1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, 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);
1447 -- If the type has appeared already in a with_type clause, it is frozen
1448 -- and the pointer size is already set. Else, initialize.
1450 if not From_Limited_With
(T
) then
1451 Reinit_Size_Align
(T
);
1454 -- Note that Has_Task is always false, since the access type itself
1455 -- is not a task type. See Einfo for more description on this point.
1456 -- Exactly the same consideration applies to Has_Controlled_Component
1457 -- and to Has_Protected.
1459 Set_Has_Task
(T
, False);
1460 Set_Has_Protected
(T
, False);
1461 Set_Has_Timing_Event
(T
, False);
1462 Set_Has_Controlled_Component
(T
, False);
1464 -- Initialize field Finalization_Collection explicitly to Empty to avoid
1465 -- problems where an incomplete view of this entity has been previously
1466 -- established by a limited with and an overlaid version of this field
1467 -- (Stored_Constraint) was initialized for the incomplete view.
1469 -- This reset is performed in most cases except where the access type
1470 -- has been created for the purposes of allocating or deallocating a
1471 -- build-in-place object. Such access types have explicitly set pools
1472 -- and finalization collections.
1474 if No
(Associated_Storage_Pool
(T
)) then
1475 Set_Finalization_Collection
(T
, Empty
);
1478 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1481 Set_Can_Never_Be_Null
(T
, Null_Exclusion_Present
(Def
));
1482 Set_Is_Access_Constant
(T
, Constant_Present
(Def
));
1483 end Access_Type_Declaration
;
1485 ----------------------------------
1486 -- Add_Interface_Tag_Components --
1487 ----------------------------------
1489 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
) is
1490 Loc
: constant Source_Ptr
:= Sloc
(N
);
1494 procedure Add_Tag
(Iface
: Entity_Id
);
1495 -- Add tag for one of the progenitor interfaces
1501 procedure Add_Tag
(Iface
: Entity_Id
) is
1508 pragma Assert
(Is_Tagged_Type
(Iface
) and then Is_Interface
(Iface
));
1510 -- This is a reasonable place to propagate predicates
1512 if Has_Predicates
(Iface
) then
1513 Set_Has_Predicates
(Typ
);
1517 Make_Component_Definition
(Loc
,
1518 Aliased_Present
=> True,
1519 Subtype_Indication
=>
1520 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
));
1522 Tag
:= Make_Temporary
(Loc
, 'V');
1525 Make_Component_Declaration
(Loc
,
1526 Defining_Identifier
=> Tag
,
1527 Component_Definition
=> Def
);
1529 Analyze_Component_Declaration
(Decl
);
1531 Set_Analyzed
(Decl
);
1532 Mutate_Ekind
(Tag
, E_Component
);
1534 Set_Is_Aliased
(Tag
);
1535 Set_Is_Independent
(Tag
);
1536 Set_Related_Type
(Tag
, Iface
);
1537 Reinit_Component_Location
(Tag
);
1539 pragma Assert
(Is_Frozen
(Iface
));
1541 Set_DT_Entry_Count
(Tag
,
1542 DT_Entry_Count
(First_Entity
(Iface
)));
1544 if No
(Last_Tag
) then
1547 Insert_After
(Last_Tag
, Decl
);
1552 -- If the ancestor has discriminants we need to give special support
1553 -- to store the offset_to_top value of the secondary dispatch tables.
1554 -- For this purpose we add a supplementary component just after the
1555 -- field that contains the tag associated with each secondary DT.
1557 if Typ
/= Etype
(Typ
) and then Has_Discriminants
(Etype
(Typ
)) then
1559 Make_Component_Definition
(Loc
,
1560 Subtype_Indication
=>
1561 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
1563 Offset
:= Make_Temporary
(Loc
, 'V');
1566 Make_Component_Declaration
(Loc
,
1567 Defining_Identifier
=> Offset
,
1568 Component_Definition
=> Def
);
1570 Analyze_Component_Declaration
(Decl
);
1572 Set_Analyzed
(Decl
);
1573 Mutate_Ekind
(Offset
, E_Component
);
1574 Set_Is_Aliased
(Offset
);
1575 Set_Is_Independent
(Offset
);
1576 Set_Related_Type
(Offset
, Iface
);
1577 Reinit_Component_Location
(Offset
);
1578 Insert_After
(Last_Tag
, Decl
);
1589 -- Start of processing for Add_Interface_Tag_Components
1592 if not RTE_Available
(RE_Interface_Tag
) then
1594 ("(Ada 2005) interface types not supported by this run-time!", N
);
1598 if Ekind
(Typ
) /= E_Record_Type
1599 or else (Is_Concurrent_Record_Type
(Typ
)
1600 and then Is_Empty_List
(Abstract_Interface_List
(Typ
)))
1601 or else (not Is_Concurrent_Record_Type
(Typ
)
1602 and then No
(Interfaces
(Typ
))
1603 and then Is_Empty_Elmt_List
(Interfaces
(Typ
)))
1608 -- Find the current last tag
1610 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1611 Ext
:= Record_Extension_Part
(Type_Definition
(N
));
1613 pragma Assert
(Nkind
(Type_Definition
(N
)) = N_Record_Definition
);
1614 Ext
:= Type_Definition
(N
);
1619 if not Present
(Component_List
(Ext
)) then
1620 Set_Null_Present
(Ext
, False);
1622 Set_Component_List
(Ext
,
1623 Make_Component_List
(Loc
,
1624 Component_Items
=> L
,
1625 Null_Present
=> False));
1627 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1628 L
:= Component_Items
1630 (Record_Extension_Part
1631 (Type_Definition
(N
))));
1633 L
:= Component_Items
1635 (Type_Definition
(N
)));
1638 -- Find the last tag component
1641 while Present
(Comp
) loop
1642 if Nkind
(Comp
) = N_Component_Declaration
1643 and then Is_Tag
(Defining_Identifier
(Comp
))
1652 -- At this point L references the list of components and Last_Tag
1653 -- references the current last tag (if any). Now we add the tag
1654 -- corresponding with all the interfaces that are not implemented
1657 if Present
(Interfaces
(Typ
)) then
1658 Elmt
:= First_Elmt
(Interfaces
(Typ
));
1659 while Present
(Elmt
) loop
1660 Add_Tag
(Node
(Elmt
));
1664 end Add_Interface_Tag_Components
;
1666 -------------------------------------
1667 -- Add_Internal_Interface_Entities --
1668 -------------------------------------
1670 procedure Add_Internal_Interface_Entities
(Tagged_Type
: Entity_Id
) is
1672 function Error_Posted_In_Formals
(Subp
: Entity_Id
) return Boolean;
1673 -- Determine if an error has been posted in some formal of Subp.
1675 -----------------------------
1676 -- Error_Posted_In_Formals --
1677 -----------------------------
1679 function Error_Posted_In_Formals
(Subp
: Entity_Id
) return Boolean is
1680 Formal
: Entity_Id
:= First_Formal
(Subp
);
1683 while Present
(Formal
) loop
1684 if Error_Posted
(Formal
) then
1688 Next_Formal
(Formal
);
1692 end Error_Posted_In_Formals
;
1698 Iface_Elmt
: Elmt_Id
;
1699 Iface_Prim
: Entity_Id
;
1700 Ifaces_List
: Elist_Id
;
1701 New_Subp
: Entity_Id
:= Empty
;
1703 Restore_Scope
: Boolean := False;
1706 pragma Assert
(Ada_Version
>= Ada_2005
1707 and then Is_Record_Type
(Tagged_Type
)
1708 and then Is_Tagged_Type
(Tagged_Type
)
1709 and then Has_Interfaces
(Tagged_Type
)
1710 and then not Is_Interface
(Tagged_Type
));
1712 -- Ensure that the internal entities are added to the scope of the type
1714 if Scope
(Tagged_Type
) /= Current_Scope
then
1715 Push_Scope
(Scope
(Tagged_Type
));
1716 Restore_Scope
:= True;
1719 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
1721 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1722 while Present
(Iface_Elmt
) loop
1723 Iface
:= Node
(Iface_Elmt
);
1725 -- Originally we excluded here from this processing interfaces that
1726 -- are parents of Tagged_Type because their primitives are located
1727 -- in the primary dispatch table (and hence no auxiliary internal
1728 -- entities are required to handle secondary dispatch tables in such
1729 -- case). However, these auxiliary entities are also required to
1730 -- handle derivations of interfaces in formals of generics (see
1731 -- Derive_Subprograms).
1733 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1734 while Present
(Elmt
) loop
1735 Iface_Prim
:= Node
(Elmt
);
1737 if not Is_Predefined_Dispatching_Operation
(Iface_Prim
) then
1739 Find_Primitive_Covering_Interface
1740 (Tagged_Type
=> Tagged_Type
,
1741 Iface_Prim
=> Iface_Prim
);
1743 if No
(Prim
) and then Serious_Errors_Detected
> 0 then
1747 pragma Assert
(Present
(Prim
));
1749 -- Check subtype conformance; we skip this check if errors have
1750 -- been reported in the primitive (or in the formals of the
1751 -- primitive) because Find_Primitive_Covering_Interface relies
1752 -- on the subprogram Type_Conformant to locate the primitive,
1753 -- and reports errors if the formals don't match.
1755 if not Error_Posted
(Prim
)
1756 and then not Error_Posted_In_Formals
(Prim
)
1759 Alias_Prim
: Entity_Id
;
1760 Alias_Typ
: Entity_Id
;
1761 Err_Loc
: Node_Id
:= Empty
;
1762 Ret_Type
: Entity_Id
;
1765 -- For inherited primitives, in case of reporting an
1766 -- error, the error must be reported on this primitive
1767 -- (i.e. in the name of its type declaration); otherwise
1768 -- the error would be reported in the formal of the
1769 -- alias primitive defined on its parent type.
1771 if Nkind
(Parent
(Prim
)) = N_Full_Type_Declaration
then
1775 -- Check subtype conformance of procedures, functions
1776 -- with matching return type, or functions not returning
1779 if Ekind
(Prim
) = E_Procedure
1780 or else Etype
(Iface_Prim
) = Etype
(Prim
)
1781 or else not Is_Interface
(Etype
(Iface_Prim
))
1783 Check_Subtype_Conformant
1785 Old_Id
=> Iface_Prim
,
1787 Skip_Controlling_Formals
=> True);
1789 -- Check subtype conformance of functions returning an
1790 -- interface type; temporarily force both entities to
1791 -- return the same type. Required because subprogram
1792 -- Subtype_Conformant does not handle this case.
1795 Ret_Type
:= Etype
(Iface_Prim
);
1796 Set_Etype
(Iface_Prim
, Etype
(Prim
));
1798 Check_Subtype_Conformant
1800 Old_Id
=> Iface_Prim
,
1802 Skip_Controlling_Formals
=> True);
1804 Set_Etype
(Iface_Prim
, Ret_Type
);
1807 -- Complete the error when reported on inherited
1810 if Nkind
(Parent
(Prim
)) = N_Full_Type_Declaration
1811 and then (Error_Posted
(Prim
)
1812 or else Error_Posted_In_Formals
(Prim
))
1813 and then Present
(Alias
(Prim
))
1815 Alias_Prim
:= Ultimate_Alias
(Prim
);
1816 Alias_Typ
:= Find_Dispatching_Type
(Alias_Prim
);
1818 if Alias_Typ
/= Tagged_Type
1819 and then Is_Ancestor
(Alias_Typ
, Tagged_Type
)
1821 Error_Msg_Sloc
:= Sloc
(Alias_Prim
);
1823 ("in primitive inherited from #!", Prim
);
1829 -- Ada 2012 (AI05-0197): If the name of the covering primitive
1830 -- differs from the name of the interface primitive then it is
1831 -- a private primitive inherited from a parent type. In such
1832 -- case, given that Tagged_Type covers the interface, the
1833 -- inherited private primitive becomes visible. For such
1834 -- purpose we add a new entity that renames the inherited
1835 -- private primitive.
1837 if Chars
(Prim
) /= Chars
(Iface_Prim
) then
1838 pragma Assert
(Has_Suffix
(Prim
, 'P'));
1840 (New_Subp
=> New_Subp
,
1841 Parent_Subp
=> Iface_Prim
,
1842 Derived_Type
=> Tagged_Type
,
1843 Parent_Type
=> Iface
);
1844 Set_Alias
(New_Subp
, Prim
);
1845 Set_Is_Abstract_Subprogram
1846 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1850 (New_Subp
=> New_Subp
,
1851 Parent_Subp
=> Iface_Prim
,
1852 Derived_Type
=> Tagged_Type
,
1853 Parent_Type
=> Iface
);
1858 if Is_Inherited_Operation
(Prim
)
1859 and then Present
(Alias
(Prim
))
1861 Anc
:= Alias
(Prim
);
1863 Anc
:= Overridden_Operation
(Prim
);
1866 -- Apply legality checks in RM 6.1.1 (10-13) concerning
1867 -- nonconforming preconditions in both an ancestor and
1868 -- a progenitor operation.
1870 -- If the operation is a primitive wrapper it is an explicit
1871 -- (overriding) operqtion and all is fine.
1874 and then Has_Non_Trivial_Precondition
(Anc
)
1875 and then Has_Non_Trivial_Precondition
(Iface_Prim
)
1877 if Is_Abstract_Subprogram
(Prim
)
1879 (Ekind
(Prim
) = E_Procedure
1880 and then Nkind
(Parent
(Prim
)) =
1881 N_Procedure_Specification
1882 and then Null_Present
(Parent
(Prim
)))
1883 or else Is_Primitive_Wrapper
(Prim
)
1887 -- The operation is inherited and must be overridden
1889 elsif not Comes_From_Source
(Prim
) then
1891 ("&inherits non-conforming preconditions and must "
1892 & "be overridden (RM 6.1.1 (10-16))",
1893 Parent
(Tagged_Type
), Prim
);
1898 -- Ada 2005 (AI-251): Decorate internal entity Iface_Subp
1899 -- associated with interface types. These entities are
1900 -- only registered in the list of primitives of its
1901 -- corresponding tagged type because they are only used
1902 -- to fill the contents of the secondary dispatch tables.
1903 -- Therefore they are removed from the homonym chains.
1905 Set_Is_Hidden
(New_Subp
);
1906 Set_Is_Internal
(New_Subp
);
1907 Set_Alias
(New_Subp
, Prim
);
1908 Set_Is_Abstract_Subprogram
1909 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1910 Set_Interface_Alias
(New_Subp
, Iface_Prim
);
1912 -- If the returned type is an interface then propagate it to
1913 -- the returned type. Needed by the thunk to generate the code
1914 -- which displaces "this" to reference the corresponding
1915 -- secondary dispatch table in the returned object.
1917 if Is_Interface
(Etype
(Iface_Prim
)) then
1918 Set_Etype
(New_Subp
, Etype
(Iface_Prim
));
1921 -- Internal entities associated with interface types are only
1922 -- registered in the list of primitives of the tagged type.
1923 -- They are only used to fill the contents of the secondary
1924 -- dispatch tables. Therefore they are not needed in the
1927 Remove_Homonym
(New_Subp
);
1929 -- Hidden entities associated with interfaces must have set
1930 -- the Has_Delay_Freeze attribute to ensure that, in case
1931 -- of locally defined tagged types (or compiling with static
1932 -- dispatch tables generation disabled) the corresponding
1933 -- entry of the secondary dispatch table is filled when such
1934 -- an entity is frozen.
1936 Set_Has_Delayed_Freeze
(New_Subp
);
1943 Next_Elmt
(Iface_Elmt
);
1946 if Restore_Scope
then
1949 end Add_Internal_Interface_Entities
;
1951 -----------------------------------
1952 -- Analyze_Component_Declaration --
1953 -----------------------------------
1955 procedure Analyze_Component_Declaration
(N
: Node_Id
) is
1956 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1957 E
: constant Node_Id
:= Expression
(N
);
1958 Typ
: constant Node_Id
:=
1959 Subtype_Indication
(Component_Definition
(N
));
1963 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean;
1964 -- Typ is the type of the current component, check whether this type is
1965 -- a limited type. Used to validate declaration against that of
1966 -- enclosing record.
1968 procedure Add_Range_Checks
(Subt_Indic
: Node_Id
);
1969 -- Adds range constraint checks for a subtype indication
1971 ----------------------
1972 -- Is_Known_Limited --
1973 ----------------------
1975 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean is
1976 P
: constant Entity_Id
:= Etype
(Typ
);
1977 R
: constant Entity_Id
:= Root_Type
(Typ
);
1980 if Is_Limited_Record
(Typ
) then
1983 -- If the root type is limited (and not a limited interface) so is
1984 -- the current type.
1986 elsif Is_Limited_Record
(R
)
1987 and then (not Is_Interface
(R
) or else not Is_Limited_Interface
(R
))
1991 -- Else the type may have a limited interface progenitor, but a
1992 -- limited record parent that is not an interface.
1995 and then Is_Limited_Record
(P
)
1996 and then not Is_Interface
(P
)
2003 end Is_Known_Limited
;
2005 ----------------------
2006 -- Add_Range_Checks --
2007 ----------------------
2009 procedure Add_Range_Checks
(Subt_Indic
: Node_Id
)
2013 if Present
(Subt_Indic
) and then
2014 Nkind
(Subt_Indic
) = N_Subtype_Indication
and then
2015 Nkind
(Constraint
(Subt_Indic
)) = N_Index_Or_Discriminant_Constraint
2019 Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(Subt_Indic
));
2020 Indic_Typ
: constant Entity_Id
:= Underlying_Type
(Typ
);
2021 Subt_Index
: Node_Id
;
2022 Target_Index
: Node_Id
;
2025 if Present
(Indic_Typ
) and then Is_Array_Type
(Indic_Typ
) then
2027 Target_Index
:= First_Index
(Indic_Typ
);
2028 Subt_Index
:= First
(Constraints
(Constraint
(Subt_Indic
)));
2030 while Present
(Target_Index
) loop
2031 if Nkind
(Subt_Index
) in N_Expanded_Name | N_Identifier
2032 and then Is_Scalar_Type
(Entity
(Subt_Index
))
2034 Nkind
(Scalar_Range
(Entity
(Subt_Index
))) = N_Range
2037 (Expr
=> Scalar_Range
(Entity
(Subt_Index
)),
2038 Target_Typ
=> Etype
(Target_Index
),
2039 Insert_Node
=> Subt_Indic
);
2043 Next_Index
(Target_Index
);
2048 end Add_Range_Checks
;
2050 -- Start of processing for Analyze_Component_Declaration
2053 Generate_Definition
(Id
);
2056 if Present
(Typ
) then
2057 T
:= Find_Type_Of_Object
2058 (Subtype_Indication
(Component_Definition
(N
)), N
);
2060 -- Ada 2005 (AI-230): Access Definition case
2063 pragma Assert
(Present
2064 (Access_Definition
(Component_Definition
(N
))));
2066 T
:= Access_Definition
2068 N
=> Access_Definition
(Component_Definition
(N
)));
2069 Set_Is_Local_Anonymous_Access
(T
);
2071 -- Ada 2005 (AI-254)
2073 if Present
(Access_To_Subprogram_Definition
2074 (Access_Definition
(Component_Definition
(N
))))
2075 and then Protected_Present
(Access_To_Subprogram_Definition
2077 (Component_Definition
(N
))))
2079 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
2083 -- If the subtype is a constrained subtype of the enclosing record,
2084 -- (which must have a partial view) the back-end does not properly
2085 -- handle the recursion. Rewrite the component declaration with an
2086 -- explicit subtype indication, which is acceptable to Gigi. We can copy
2087 -- the tree directly because side effects have already been removed from
2088 -- discriminant constraints.
2090 if Ekind
(T
) = E_Access_Subtype
2091 and then Is_Entity_Name
(Subtype_Indication
(Component_Definition
(N
)))
2092 and then Comes_From_Source
(T
)
2093 and then Nkind
(Parent
(T
)) = N_Subtype_Declaration
2094 and then Etype
(Directly_Designated_Type
(T
)) = Current_Scope
2097 (Subtype_Indication
(Component_Definition
(N
)),
2098 New_Copy_Tree
(Subtype_Indication
(Parent
(T
))));
2099 T
:= Find_Type_Of_Object
2100 (Subtype_Indication
(Component_Definition
(N
)), N
);
2103 -- If the component declaration includes a default expression, then we
2104 -- check that the component is not of a limited type (RM 3.7(5)),
2105 -- and do the special preanalysis of the expression (see section on
2106 -- "Handling of Default and Per-Object Expressions" in the spec of
2110 Preanalyze_Default_Expression
(E
, T
);
2111 Check_Initialization
(T
, E
);
2113 if Ada_Version
>= Ada_2005
2114 and then Ekind
(T
) = E_Anonymous_Access_Type
2115 and then Etype
(E
) /= Any_Type
2117 -- Check RM 3.9.2(9): "if the expected type for an expression is
2118 -- an anonymous access-to-specific tagged type, then the object
2119 -- designated by the expression shall not be dynamically tagged
2120 -- unless it is a controlling operand in a call on a dispatching
2123 if Is_Tagged_Type
(Directly_Designated_Type
(T
))
2125 Ekind
(Directly_Designated_Type
(T
)) /= E_Class_Wide_Type
2127 Ekind
(Directly_Designated_Type
(Etype
(E
))) =
2131 ("access to specific tagged type required (RM 3.9.2(9))", E
);
2134 -- (Ada 2005: AI-230): Accessibility check for anonymous
2137 if Type_Access_Level
(Etype
(E
)) >
2138 Deepest_Type_Access_Level
(T
)
2141 ("expression has deeper access level than component " &
2142 "(RM 3.10.2 (12.2))", E
);
2145 -- The initialization expression is a reference to an access
2146 -- discriminant. The type of the discriminant is always deeper
2147 -- than any access type.
2149 if Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
2150 and then Is_Entity_Name
(E
)
2151 and then Ekind
(Entity
(E
)) = E_In_Parameter
2152 and then Present
(Discriminal_Link
(Entity
(E
)))
2155 ("discriminant has deeper accessibility level than target",
2161 -- The parent type may be a private view with unknown discriminants,
2162 -- and thus unconstrained. Regular components must be constrained.
2164 if not Is_Definite_Subtype
(T
)
2165 and then Chars
(Id
) /= Name_uParent
2167 if Is_Class_Wide_Type
(T
) then
2169 ("class-wide subtype with unknown discriminants" &
2170 " in component declaration",
2171 Subtype_Indication
(Component_Definition
(N
)));
2174 ("unconstrained subtype in component declaration",
2175 Subtype_Indication
(Component_Definition
(N
)));
2178 -- Components cannot be abstract, except for the special case of
2179 -- the _Parent field (case of extending an abstract tagged type)
2181 elsif Is_Abstract_Type
(T
) and then Chars
(Id
) /= Name_uParent
then
2182 Error_Msg_N
("type of a component cannot be abstract", N
);
2187 if Aliased_Present
(Component_Definition
(N
)) then
2188 Set_Is_Aliased
(Id
);
2190 -- AI12-001: All aliased objects are considered to be specified as
2191 -- independently addressable (RM C.6(8.1/4)).
2193 Set_Is_Independent
(Id
);
2196 -- The component declaration may have a per-object constraint, set
2197 -- the appropriate flag in the defining identifier of the subtype.
2199 if Has_Discriminant_Dependent_Constraint
(Id
) then
2200 Set_Has_Per_Object_Constraint
(Id
);
2203 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2204 -- out some static checks.
2206 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(T
) then
2207 Null_Exclusion_Static_Checks
(N
);
2210 -- If this component is private (or depends on a private type), flag the
2211 -- record type to indicate that some operations are not available.
2213 P
:= Private_Component
(T
);
2217 -- Check for circular definitions
2219 if P
= Any_Type
then
2220 Set_Etype
(Id
, Any_Type
);
2222 -- There is a gap in the visibility of operations only if the
2223 -- component type is not defined in the scope of the record type.
2225 elsif Scope
(P
) = Scope
(Current_Scope
) then
2228 elsif Is_Limited_Type
(P
) then
2229 Set_Is_Limited_Composite
(Current_Scope
);
2232 Set_Is_Private_Composite
(Current_Scope
);
2237 and then Is_Limited_Type
(T
)
2238 and then Chars
(Id
) /= Name_uParent
2239 and then Is_Tagged_Type
(Current_Scope
)
2241 if Is_Derived_Type
(Current_Scope
)
2242 and then not Is_Known_Limited
(Current_Scope
)
2245 ("extension of nonlimited type cannot have limited components",
2248 if Is_Interface
(Root_Type
(Current_Scope
)) then
2250 ("\limitedness is not inherited from limited interface", N
);
2251 Error_Msg_N
("\add LIMITED to type indication", N
);
2254 Explain_Limited_Type
(T
, N
);
2255 Set_Etype
(Id
, Any_Type
);
2256 Set_Is_Limited_Composite
(Current_Scope
, False);
2258 elsif not Is_Derived_Type
(Current_Scope
)
2259 and then not Is_Limited_Record
(Current_Scope
)
2260 and then not Is_Concurrent_Type
(Current_Scope
)
2263 ("nonlimited tagged type cannot have limited components", N
);
2264 Explain_Limited_Type
(T
, N
);
2265 Set_Etype
(Id
, Any_Type
);
2266 Set_Is_Limited_Composite
(Current_Scope
, False);
2270 Set_Original_Record_Component
(Id
, Id
);
2272 Analyze_Aspect_Specifications
(N
, Id
);
2274 Analyze_Dimension
(N
);
2276 Add_Range_Checks
(Subtype_Indication
(Component_Definition
(N
)));
2278 end Analyze_Component_Declaration
;
2280 --------------------------
2281 -- Analyze_Declarations --
2282 --------------------------
2284 procedure Analyze_Declarations
(L
: List_Id
) is
2287 procedure Adjust_Decl
;
2288 -- Adjust Decl not to include implicit label declarations, since these
2289 -- have strange Sloc values that result in elaboration check problems.
2290 -- (They have the sloc of the label as found in the source, and that
2291 -- is ahead of the current declarative part).
2293 procedure Build_Assertion_Bodies
(Decls
: List_Id
; Context
: Node_Id
);
2294 -- Create the subprogram bodies which verify the run-time semantics of
2295 -- the pragmas listed below for each elibigle type found in declarative
2296 -- list Decls. The pragmas are:
2298 -- Default_Initial_Condition
2302 -- Context denotes the owner of the declarative list.
2304 procedure Check_Entry_Contracts
;
2305 -- Perform a preanalysis of the pre- and postconditions of an entry
2306 -- declaration. This must be done before full resolution and creation
2307 -- of the parameter block, etc. to catch illegal uses within the
2308 -- contract expression. Full analysis of the expression is done when
2309 -- the contract is processed.
2311 function Contains_Lib_Incomplete_Type
(Pkg
: Entity_Id
) return Boolean;
2312 -- Check if a nested package has entities within it that rely on library
2313 -- level private types where the full view has not been completed for
2314 -- the purposes of checking if it is acceptable to freeze an expression
2315 -- function at the point of declaration.
2317 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
);
2318 -- Determine whether Body_Decl denotes the body of a late controlled
2319 -- primitive (either Initialize, Adjust or Finalize). If this is the
2320 -- case, add a proper spec if the body lacks one. The spec is inserted
2321 -- before Body_Decl and immediately analyzed.
2323 procedure Remove_Partial_Visible_Refinements
(Spec_Id
: Entity_Id
);
2324 -- Spec_Id is the entity of a package that may define abstract states,
2325 -- and in the case of a child unit, whose ancestors may define abstract
2326 -- states. If the states have partial visible refinement, remove the
2327 -- partial visibility of each constituent at the end of the package
2328 -- spec and body declarations.
2330 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
);
2331 -- Spec_Id is the entity of a package that may define abstract states.
2332 -- If the states have visible refinement, remove the visibility of each
2333 -- constituent at the end of the package body declaration.
2335 procedure Resolve_Aspects
;
2336 -- Utility to resolve the expressions of aspects at the end of a list of
2337 -- declarations, or before a declaration that freezes previous entities,
2338 -- such as in a subprogram body.
2344 procedure Adjust_Decl
is
2346 while Present
(Prev
(Decl
))
2347 and then Nkind
(Decl
) = N_Implicit_Label_Declaration
2353 ----------------------------
2354 -- Build_Assertion_Bodies --
2355 ----------------------------
2357 procedure Build_Assertion_Bodies
(Decls
: List_Id
; Context
: Node_Id
) is
2358 procedure Build_Assertion_Bodies_For_Type
(Typ
: Entity_Id
);
2359 -- Create the subprogram bodies which verify the run-time semantics
2360 -- of the pragmas listed below for type Typ. The pragmas are:
2362 -- Default_Initial_Condition
2366 -------------------------------------
2367 -- Build_Assertion_Bodies_For_Type --
2368 -------------------------------------
2370 procedure Build_Assertion_Bodies_For_Type
(Typ
: Entity_Id
) is
2372 if Nkind
(Context
) = N_Package_Specification
then
2374 -- Preanalyze and resolve the class-wide invariants of an
2375 -- interface at the end of whichever declarative part has the
2376 -- interface type. Note that an interface may be declared in
2377 -- any non-package declarative part, but reaching the end of
2378 -- such a declarative part will always freeze the type and
2379 -- generate the invariant procedure (see Freeze_Type).
2381 if Is_Interface
(Typ
) then
2383 -- Interfaces are treated as the partial view of a private
2384 -- type, in order to achieve uniformity with the general
2385 -- case. As a result, an interface receives only a "partial"
2386 -- invariant procedure, which is never called.
2388 if Has_Own_Invariants
(Typ
) then
2389 Build_Invariant_Procedure_Body
2391 Partial_Invariant
=> True);
2394 elsif Decls
= Visible_Declarations
(Context
) then
2395 -- Preanalyze and resolve the invariants of a private type
2396 -- at the end of the visible declarations to catch potential
2397 -- errors. Inherited class-wide invariants are not included
2398 -- because they have already been resolved.
2400 if Ekind
(Typ
) in E_Limited_Private_Type
2402 | E_Record_Type_With_Private
2403 and then Has_Own_Invariants
(Typ
)
2405 Build_Invariant_Procedure_Body
2407 Partial_Invariant
=> True);
2410 -- Preanalyze and resolve the Default_Initial_Condition
2411 -- assertion expression at the end of the declarations to
2412 -- catch any errors.
2414 if Ekind
(Typ
) in E_Limited_Private_Type
2416 | E_Record_Type_With_Private
2417 and then Has_Own_DIC
(Typ
)
2419 Build_DIC_Procedure_Body
2421 Partial_DIC
=> True);
2424 elsif Decls
= Private_Declarations
(Context
) then
2426 -- Preanalyze and resolve the invariants of a private type's
2427 -- full view at the end of the private declarations to catch
2428 -- potential errors.
2430 if (not Is_Private_Type
(Typ
)
2431 or else Present
(Underlying_Full_View
(Typ
)))
2432 and then Has_Private_Declaration
(Typ
)
2433 and then Has_Invariants
(Typ
)
2435 Build_Invariant_Procedure_Body
(Typ
);
2438 if (not Is_Private_Type
(Typ
)
2439 or else Present
(Underlying_Full_View
(Typ
)))
2440 and then Has_Private_Declaration
(Typ
)
2441 and then Has_DIC
(Typ
)
2443 Build_DIC_Procedure_Body
(Typ
);
2447 end Build_Assertion_Bodies_For_Type
;
2452 Decl_Id
: Entity_Id
;
2454 -- Start of processing for Build_Assertion_Bodies
2457 Decl
:= First
(Decls
);
2458 while Present
(Decl
) loop
2459 if Is_Declaration
(Decl
) then
2460 Decl_Id
:= Defining_Entity
(Decl
);
2462 if Is_Type
(Decl_Id
) then
2463 Build_Assertion_Bodies_For_Type
(Decl_Id
);
2469 end Build_Assertion_Bodies
;
2471 ---------------------------
2472 -- Check_Entry_Contracts --
2473 ---------------------------
2475 procedure Check_Entry_Contracts
is
2481 Ent
:= First_Entity
(Current_Scope
);
2482 while Present
(Ent
) loop
2484 -- This only concerns entries with pre/postconditions
2486 if Ekind
(Ent
) = E_Entry
2487 and then Present
(Contract
(Ent
))
2488 and then Present
(Pre_Post_Conditions
(Contract
(Ent
)))
2490 ASN
:= Pre_Post_Conditions
(Contract
(Ent
));
2492 Install_Formals
(Ent
);
2494 -- Pre/postconditions are rewritten as Check pragmas. Analysis
2495 -- is performed on a copy of the pragma expression, to prevent
2496 -- modifying the original expression.
2498 while Present
(ASN
) loop
2499 if Nkind
(ASN
) = N_Pragma
then
2503 (First
(Pragma_Argument_Associations
(ASN
))));
2504 Set_Parent
(Exp
, ASN
);
2506 Preanalyze_Assert_Expression
(Exp
, Standard_Boolean
);
2509 ASN
:= Next_Pragma
(ASN
);
2517 end Check_Entry_Contracts
;
2519 ----------------------------------
2520 -- Contains_Lib_Incomplete_Type --
2521 ----------------------------------
2523 function Contains_Lib_Incomplete_Type
(Pkg
: Entity_Id
) return Boolean is
2527 -- Avoid looking through scopes that do not meet the precondition of
2528 -- Pkg not being within a library unit spec.
2530 if not Is_Compilation_Unit
(Pkg
)
2531 and then not Is_Generic_Instance
(Pkg
)
2532 and then not In_Package_Body
(Enclosing_Lib_Unit_Entity
(Pkg
))
2534 -- Loop through all entities in the current scope to identify
2535 -- an entity that depends on a private type.
2537 Curr
:= First_Entity
(Pkg
);
2539 if Nkind
(Curr
) in N_Entity
2540 and then Depends_On_Private
(Curr
)
2545 exit when Last_Entity
(Current_Scope
) = Curr
;
2551 end Contains_Lib_Incomplete_Type
;
2553 --------------------------------------
2554 -- Handle_Late_Controlled_Primitive --
2555 --------------------------------------
2557 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
) is
2558 Body_Spec
: constant Node_Id
:= Specification
(Body_Decl
);
2559 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2560 Loc
: constant Source_Ptr
:= Sloc
(Body_Id
);
2561 Params
: constant List_Id
:=
2562 Parameter_Specifications
(Body_Spec
);
2564 Spec_Id
: Entity_Id
;
2568 -- Consider only procedure bodies whose name matches one of the three
2569 -- controlled primitives.
2571 if Nkind
(Body_Spec
) /= N_Procedure_Specification
2572 or else Chars
(Body_Id
) not in Name_Adjust
2578 -- A controlled primitive must have exactly one formal which is not
2579 -- an anonymous access type.
2581 elsif List_Length
(Params
) /= 1 then
2585 Typ
:= Parameter_Type
(First
(Params
));
2587 if Nkind
(Typ
) = N_Access_Definition
then
2593 -- The type of the formal must be derived from [Limited_]Controlled
2595 if not Is_Controlled
(Entity
(Typ
)) then
2599 -- Check whether a specification exists for this body. We do not
2600 -- analyze the spec of the body in full, because it will be analyzed
2601 -- again when the body is properly analyzed, and we cannot create
2602 -- duplicate entries in the formals chain. We look for an explicit
2603 -- specification because the body may be an overriding operation and
2604 -- an inherited spec may be present.
2606 Spec_Id
:= Current_Entity
(Body_Id
);
2608 while Present
(Spec_Id
) loop
2609 if Ekind
(Spec_Id
) in E_Procedure | E_Generic_Procedure
2610 and then Scope
(Spec_Id
) = Current_Scope
2611 and then Present
(First_Formal
(Spec_Id
))
2612 and then No
(Next_Formal
(First_Formal
(Spec_Id
)))
2613 and then Etype
(First_Formal
(Spec_Id
)) = Entity
(Typ
)
2614 and then Comes_From_Source
(Spec_Id
)
2619 Spec_Id
:= Homonym
(Spec_Id
);
2622 -- At this point the body is known to be a late controlled primitive.
2623 -- Generate a matching spec and insert it before the body. Note the
2624 -- use of Copy_Separate_Tree - we want an entirely separate semantic
2625 -- tree in this case.
2627 Spec
:= Copy_Separate_Tree
(Body_Spec
);
2629 -- Ensure that the subprogram declaration does not inherit the null
2630 -- indicator from the body as we now have a proper spec/body pair.
2632 Set_Null_Present
(Spec
, False);
2634 -- Ensure that the freeze node is inserted after the declaration of
2635 -- the primitive since its expansion will freeze the primitive.
2637 Decl
:= Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
2639 Insert_Before_And_Analyze
(Body_Decl
, Decl
);
2640 end Handle_Late_Controlled_Primitive
;
2642 ----------------------------------------
2643 -- Remove_Partial_Visible_Refinements --
2644 ----------------------------------------
2646 procedure Remove_Partial_Visible_Refinements
(Spec_Id
: Entity_Id
) is
2647 State_Elmt
: Elmt_Id
;
2649 if Present
(Abstract_States
(Spec_Id
)) then
2650 State_Elmt
:= First_Elmt
(Abstract_States
(Spec_Id
));
2651 while Present
(State_Elmt
) loop
2652 Set_Has_Partial_Visible_Refinement
(Node
(State_Elmt
), False);
2653 Next_Elmt
(State_Elmt
);
2657 -- For a child unit, also hide the partial state refinement from
2658 -- ancestor packages.
2660 if Is_Child_Unit
(Spec_Id
) then
2661 Remove_Partial_Visible_Refinements
(Scope
(Spec_Id
));
2663 end Remove_Partial_Visible_Refinements
;
2665 --------------------------------
2666 -- Remove_Visible_Refinements --
2667 --------------------------------
2669 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
) is
2670 State_Elmt
: Elmt_Id
;
2672 if Present
(Abstract_States
(Spec_Id
)) then
2673 State_Elmt
:= First_Elmt
(Abstract_States
(Spec_Id
));
2674 while Present
(State_Elmt
) loop
2675 Set_Has_Visible_Refinement
(Node
(State_Elmt
), False);
2676 Next_Elmt
(State_Elmt
);
2679 end Remove_Visible_Refinements
;
2681 ---------------------
2682 -- Resolve_Aspects --
2683 ---------------------
2685 procedure Resolve_Aspects
is
2689 E
:= First_Entity
(Current_Scope
);
2690 while Present
(E
) loop
2691 Resolve_Aspect_Expressions
(E
);
2693 -- Now that the aspect expressions have been resolved, if this is
2694 -- at the end of the visible declarations, we can set the flag
2695 -- Known_To_Have_Preelab_Init properly on types declared in the
2696 -- visible part, which is needed for checking whether full types
2697 -- in the private part satisfy the Preelaborable_Initialization
2698 -- aspect of the partial view. We can't wait for the creation of
2699 -- the pragma by Analyze_Aspects_At_Freeze_Point, because the
2700 -- freeze point may occur after the end of the package declaration
2701 -- (in the case of nested packages).
2704 and then L
= Visible_Declarations
(Parent
(L
))
2705 and then Has_Aspect
(E
, Aspect_Preelaborable_Initialization
)
2708 ASN
: constant Node_Id
:=
2709 Find_Aspect
(E
, Aspect_Preelaborable_Initialization
);
2710 Expr
: constant Node_Id
:= Expression
(ASN
);
2712 -- Set Known_To_Have_Preelab_Init to True if aspect has no
2713 -- expression, or if the expression is True (or was folded
2714 -- to True), or if the expression is a conjunction of one or
2715 -- more Preelaborable_Initialization attributes applied to
2716 -- formal types and wasn't folded to False. (Note that
2717 -- Is_Conjunction_Of_Formal_Preelab_Init_Attributes goes to
2718 -- Original_Node if needed, hence test for Standard_False.)
2721 or else (Is_Entity_Name
(Expr
)
2722 and then Entity
(Expr
) = Standard_True
)
2724 (Is_Conjunction_Of_Formal_Preelab_Init_Attributes
(Expr
)
2726 not (Is_Entity_Name
(Expr
)
2727 and then Entity
(Expr
) = Standard_False
))
2729 Set_Known_To_Have_Preelab_Init
(E
);
2736 end Resolve_Aspects
;
2740 Context
: Node_Id
:= Empty
;
2741 Ctrl_Typ
: Entity_Id
:= Empty
;
2742 Freeze_From
: Entity_Id
:= Empty
;
2743 Next_Decl
: Node_Id
;
2745 -- Start of processing for Analyze_Declarations
2749 while Present
(Decl
) loop
2751 -- Complete analysis of declaration
2754 Next_Decl
:= Next
(Decl
);
2756 if No
(Freeze_From
) then
2757 Freeze_From
:= First_Entity
(Current_Scope
);
2760 -- Remember if the declaration we just processed is the full type
2761 -- declaration of a controlled type (to handle late overriding of
2762 -- initialize, adjust or finalize).
2764 if Nkind
(Decl
) = N_Full_Type_Declaration
2765 and then Is_Controlled
(Defining_Identifier
(Decl
))
2767 Ctrl_Typ
:= Defining_Identifier
(Decl
);
2770 -- At the end of a declarative part, freeze remaining entities
2771 -- declared in it. The end of the visible declarations of package
2772 -- specification is not the end of a declarative part if private
2773 -- declarations are present. The end of a package declaration is a
2774 -- freezing point only if it a library package. A task definition or
2775 -- protected type definition is not a freeze point either. Finally,
2776 -- we do not freeze entities in generic scopes, because there is no
2777 -- code generated for them and freeze nodes will be generated for
2780 -- The end of a package instantiation is not a freeze point, but
2781 -- for now we make it one, because the generic body is inserted
2782 -- (currently) immediately after. Generic instantiations will not
2783 -- be a freeze point once delayed freezing of bodies is implemented.
2784 -- (This is needed in any case for early instantiations ???).
2786 if No
(Next_Decl
) then
2787 if Nkind
(Parent
(L
)) = N_Component_List
then
2790 elsif Nkind
(Parent
(L
)) in
2791 N_Protected_Definition | N_Task_Definition
2793 Check_Entry_Contracts
;
2795 elsif Nkind
(Parent
(L
)) /= N_Package_Specification
then
2796 if Nkind
(Parent
(L
)) = N_Package_Body
then
2797 Freeze_From
:= First_Entity
(Current_Scope
);
2800 -- There may have been several freezing points previously,
2801 -- for example object declarations or subprogram bodies, but
2802 -- at the end of a declarative part we check freezing from
2803 -- the beginning, even though entities may already be frozen,
2804 -- in order to perform visibility checks on delayed aspects.
2808 -- If the current scope is a generic subprogram body. Skip the
2809 -- generic formal parameters that are not frozen here.
2811 if Is_Subprogram
(Current_Scope
)
2812 and then Nkind
(Unit_Declaration_Node
(Current_Scope
)) =
2813 N_Generic_Subprogram_Declaration
2814 and then Present
(First_Entity
(Current_Scope
))
2816 while Is_Generic_Formal
(Freeze_From
) loop
2817 Next_Entity
(Freeze_From
);
2820 Freeze_All
(Freeze_From
, Decl
);
2821 Freeze_From
:= Last_Entity
(Current_Scope
);
2824 -- For declarations in a subprogram body there is no issue
2825 -- with name resolution in aspect specifications.
2827 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2828 Freeze_From
:= Last_Entity
(Current_Scope
);
2831 -- Current scope is a package specification
2833 elsif Scope
(Current_Scope
) /= Standard_Standard
2834 and then not Is_Child_Unit
(Current_Scope
)
2835 and then No
(Generic_Parent
(Parent
(L
)))
2837 -- ARM rule 13.1.1(11/3): usage names in aspect definitions are
2838 -- resolved at the end of the immediately enclosing declaration
2839 -- list (AI05-0183-1).
2843 elsif L
/= Visible_Declarations
(Parent
(L
))
2844 or else Is_Empty_List
(Private_Declarations
(Parent
(L
)))
2848 -- End of a package declaration
2850 -- This is a freeze point because it is the end of a
2851 -- compilation unit.
2853 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2854 Freeze_From
:= Last_Entity
(Current_Scope
);
2856 -- At the end of the visible declarations the expressions in
2857 -- aspects of all entities declared so far must be resolved.
2858 -- The entities themselves might be frozen later, and the
2859 -- generated pragmas and attribute definition clauses analyzed
2860 -- in full at that point, but name resolution must take place
2862 -- In addition to being the proper semantics, this is mandatory
2863 -- within generic units, because global name capture requires
2864 -- those expressions to be analyzed, given that the generated
2865 -- pragmas do not appear in the original generic tree.
2867 elsif Serious_Errors_Detected
= 0 then
2871 -- If next node is a body then freeze all types before the body.
2872 -- An exception occurs for some expander-generated bodies. If these
2873 -- are generated at places where in general language rules would not
2874 -- allow a freeze point, then we assume that the expander has
2875 -- explicitly checked that all required types are properly frozen,
2876 -- and we do not cause general freezing here. This special circuit
2877 -- is used when the encountered body is marked as having already
2880 -- In all other cases (bodies that come from source, and expander
2881 -- generated bodies that have not been analyzed yet), freeze all
2882 -- types now. Note that in the latter case, the expander must take
2883 -- care to attach the bodies at a proper place in the tree so as to
2884 -- not cause unwanted freezing at that point.
2886 -- It is also necessary to check for a case where both an expression
2887 -- function is used and the current scope depends on an incomplete
2888 -- private type from a library unit, otherwise premature freezing of
2889 -- the private type will occur.
2891 elsif not Analyzed
(Next_Decl
) and then Is_Body
(Next_Decl
)
2892 and then ((Nkind
(Next_Decl
) /= N_Subprogram_Body
2893 or else not Was_Expression_Function
(Next_Decl
))
2894 or else (not Is_Ignored_Ghost_Entity
(Current_Scope
)
2895 and then not Contains_Lib_Incomplete_Type
2898 -- When a controlled type is frozen, the expander generates stream
2899 -- and controlled-type support routines. If the freeze is caused
2900 -- by the stand-alone body of Initialize, Adjust, or Finalize, the
2901 -- expander will end up using the wrong version of these routines,
2902 -- as the body has not been processed yet. To remedy this, detect
2903 -- a late controlled primitive and create a proper spec for it.
2904 -- This ensures that the primitive will override its inherited
2905 -- counterpart before the freeze takes place.
2907 -- If the declaration we just processed is a body, do not attempt
2908 -- to examine Next_Decl as the late primitive idiom can only apply
2909 -- to the first encountered body.
2911 -- ??? A cleaner approach may be possible and/or this solution
2912 -- could be extended to general-purpose late primitives.
2914 if Present
(Ctrl_Typ
) then
2916 -- No need to continue searching for late body overriding if
2917 -- the controlled type is already frozen.
2919 if Is_Frozen
(Ctrl_Typ
) then
2922 elsif Nkind
(Next_Decl
) = N_Subprogram_Body
then
2923 Handle_Late_Controlled_Primitive
(Next_Decl
);
2929 -- The generated body of an expression function does not freeze,
2930 -- unless it is a completion, in which case only the expression
2931 -- itself freezes. This is handled when the body itself is
2932 -- analyzed (see Freeze_Expr_Types, sem_ch6.adb).
2934 Freeze_All
(Freeze_From
, Decl
);
2935 Freeze_From
:= Last_Entity
(Current_Scope
);
2941 -- Post-freezing actions
2944 Context
:= Parent
(L
);
2946 -- Certain contract annotations have forward visibility semantics and
2947 -- must be analyzed after all declarative items have been processed.
2948 -- This timing ensures that entities referenced by such contracts are
2951 -- Analyze the contract of an immediately enclosing package spec or
2952 -- body first because other contracts may depend on its information.
2954 if Nkind
(Context
) = N_Package_Body
then
2955 Analyze_Package_Body_Contract
(Defining_Entity
(Context
));
2957 elsif Nkind
(Context
) = N_Package_Specification
then
2958 Analyze_Package_Contract
(Defining_Entity
(Context
));
2961 -- Analyze the contracts of various constructs in the declarative
2964 Analyze_Contracts
(L
);
2966 if Nkind
(Context
) = N_Package_Body
then
2968 -- Ensure that all abstract states and objects declared in the
2969 -- state space of a package body are utilized as constituents.
2971 Check_Unused_Body_States
(Defining_Entity
(Context
));
2973 -- State refinements are visible up to the end of the package body
2974 -- declarations. Hide the state refinements from visibility to
2975 -- restore the original state conditions.
2977 Remove_Visible_Refinements
(Corresponding_Spec
(Context
));
2978 Remove_Partial_Visible_Refinements
(Corresponding_Spec
(Context
));
2980 elsif Nkind
(Context
) = N_Package_Specification
then
2982 -- Partial state refinements are visible up to the end of the
2983 -- package spec declarations. Hide the partial state refinements
2984 -- from visibility to restore the original state conditions.
2986 Remove_Partial_Visible_Refinements
(Defining_Entity
(Context
));
2989 -- Verify that all abstract states found in any package declared in
2990 -- the input declarative list have proper refinements. The check is
2991 -- performed only when the context denotes a block, entry, package,
2992 -- protected, subprogram, or task body (SPARK RM 7.1.4(4) and SPARK
2995 Check_State_Refinements
(Context
);
2997 -- Create the subprogram bodies which verify the run-time semantics
2998 -- of pragmas Default_Initial_Condition and [Type_]Invariant for all
2999 -- types within the current declarative list. This ensures that all
3000 -- assertion expressions are preanalyzed and resolved at the end of
3001 -- the declarative part. Note that the resolution happens even when
3002 -- freezing does not take place.
3004 Build_Assertion_Bodies
(L
, Context
);
3006 end Analyze_Declarations
;
3008 -----------------------------------
3009 -- Analyze_Full_Type_Declaration --
3010 -----------------------------------
3012 procedure Analyze_Full_Type_Declaration
(N
: Node_Id
) is
3013 Def
: constant Node_Id
:= Type_Definition
(N
);
3014 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3018 Is_Remote
: constant Boolean :=
3019 (Is_Remote_Types
(Current_Scope
)
3020 or else Is_Remote_Call_Interface
(Current_Scope
))
3021 and then not (In_Private_Part
(Current_Scope
)
3022 or else In_Package_Body
(Current_Scope
));
3024 procedure Check_Nonoverridable_Aspects
;
3025 -- Apply the rule in RM 13.1.1(18.4/4) on iterator aspects that cannot
3026 -- be overridden, and can only be confirmed on derivation.
3028 procedure Check_Ops_From_Incomplete_Type
;
3029 -- If there is a tagged incomplete partial view of the type, traverse
3030 -- the primitives of the incomplete view and change the type of any
3031 -- controlling formals and result to indicate the full view. The
3032 -- primitives will be added to the full type's primitive operations
3033 -- list later in Sem_Disp.Check_Operation_From_Incomplete_Type (which
3034 -- is called from Process_Incomplete_Dependents).
3036 ----------------------------------
3037 -- Check_Nonoverridable_Aspects --
3038 ----------------------------------
3040 procedure Check_Nonoverridable_Aspects
is
3041 function Get_Aspect_Spec
3043 Aspect_Name
: Name_Id
) return Node_Id
;
3044 -- Check whether a list of aspect specifications includes an entry
3045 -- for a specific aspect. The list is either that of a partial or
3048 ---------------------
3049 -- Get_Aspect_Spec --
3050 ---------------------
3052 function Get_Aspect_Spec
3054 Aspect_Name
: Name_Id
) return Node_Id
3059 Spec
:= First
(Specs
);
3060 while Present
(Spec
) loop
3061 if Chars
(Identifier
(Spec
)) = Aspect_Name
then
3068 end Get_Aspect_Spec
;
3072 Prev_Aspects
: constant List_Id
:=
3073 Aspect_Specifications
(Parent
(Def_Id
));
3074 Par_Type
: Entity_Id
;
3075 Prev_Aspect
: Node_Id
;
3077 -- Start of processing for Check_Nonoverridable_Aspects
3080 -- Get parent type of derived type. Note that Prev is the entity in
3081 -- the partial declaration, but its contents are now those of full
3082 -- view, while Def_Id reflects the partial view.
3084 if Is_Private_Type
(Def_Id
) then
3085 Par_Type
:= Etype
(Full_View
(Def_Id
));
3087 Par_Type
:= Etype
(Def_Id
);
3090 -- If there is an inherited Implicit_Dereference, verify that it is
3091 -- made explicit in the partial view.
3093 if Has_Discriminants
(Base_Type
(Par_Type
))
3094 and then Nkind
(Parent
(Prev
)) = N_Full_Type_Declaration
3095 and then Present
(Discriminant_Specifications
(Parent
(Prev
)))
3096 and then Present
(Get_Reference_Discriminant
(Par_Type
))
3099 Get_Aspect_Spec
(Prev_Aspects
, Name_Implicit_Dereference
);
3103 (Discriminant_Specifications
3104 (Original_Node
(Parent
(Prev
))))
3107 ("type does not inherit implicit dereference", Prev
);
3110 -- If one of the views has the aspect specified, verify that it
3111 -- is consistent with that of the parent.
3114 Cur_Discr
: constant Entity_Id
:=
3115 Get_Reference_Discriminant
(Prev
);
3116 Par_Discr
: constant Entity_Id
:=
3117 Get_Reference_Discriminant
(Par_Type
);
3120 if Corresponding_Discriminant
(Cur_Discr
) /= Par_Discr
then
3122 ("aspect inconsistent with that of parent", N
);
3125 -- Check that specification in partial view matches the
3126 -- inherited aspect. Compare names directly because aspect
3127 -- expression may not be analyzed.
3129 if Present
(Prev_Aspect
)
3130 and then Nkind
(Expression
(Prev_Aspect
)) = N_Identifier
3131 and then Chars
(Expression
(Prev_Aspect
)) /=
3135 ("aspect inconsistent with that of parent", N
);
3141 -- What about other nonoverridable aspects???
3142 end Check_Nonoverridable_Aspects
;
3144 ------------------------------------
3145 -- Check_Ops_From_Incomplete_Type --
3146 ------------------------------------
3148 procedure Check_Ops_From_Incomplete_Type
is
3155 and then Ekind
(Prev
) = E_Incomplete_Type
3156 and then Is_Tagged_Type
(Prev
)
3157 and then Is_Tagged_Type
(T
)
3158 and then Present
(Primitive_Operations
(Prev
))
3160 Elmt
:= First_Elmt
(Primitive_Operations
(Prev
));
3161 while Present
(Elmt
) loop
3164 Formal
:= First_Formal
(Op
);
3165 while Present
(Formal
) loop
3166 if Etype
(Formal
) = Prev
then
3167 Set_Etype
(Formal
, T
);
3170 Next_Formal
(Formal
);
3173 if Etype
(Op
) = Prev
then
3180 end Check_Ops_From_Incomplete_Type
;
3182 -- Start of processing for Analyze_Full_Type_Declaration
3185 Prev
:= Find_Type_Name
(N
);
3187 -- The full view, if present, now points to the current type. If there
3188 -- is an incomplete partial view, set a link to it, to simplify the
3189 -- retrieval of primitive operations of the type.
3191 -- Ada 2005 (AI-50217): If the type was previously decorated when
3192 -- imported through a LIMITED WITH clause, it appears as incomplete
3193 -- but has no full view.
3195 if Ekind
(Prev
) = E_Incomplete_Type
3196 and then Present
(Full_View
(Prev
))
3198 T
:= Full_View
(Prev
);
3199 Set_Incomplete_View
(N
, Prev
);
3204 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
3206 -- We set the flag Is_First_Subtype here. It is needed to set the
3207 -- corresponding flag for the Implicit class-wide-type created
3208 -- during tagged types processing.
3210 Set_Is_First_Subtype
(T
, True);
3212 -- Only composite types other than array types are allowed to have
3217 -- For derived types, the rule will be checked once we've figured
3218 -- out the parent type.
3220 when N_Derived_Type_Definition
=>
3223 -- For record types, discriminants are allowed.
3225 when N_Record_Definition
=>
3229 if Present
(Discriminant_Specifications
(N
)) then
3231 ("elementary or array type cannot have discriminants",
3233 (First
(Discriminant_Specifications
(N
))));
3237 -- Elaborate the type definition according to kind, and generate
3238 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3239 -- already done (this happens during the reanalysis that follows a call
3240 -- to the high level optimizer).
3242 if not Analyzed
(T
) then
3245 -- Set the SPARK mode from the current context
3247 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
3248 Set_SPARK_Pragma_Inherited
(T
);
3251 when N_Access_To_Subprogram_Definition
=>
3252 Access_Subprogram_Declaration
(T
, Def
);
3254 -- If this is a remote access to subprogram, we must create the
3255 -- equivalent fat pointer type, and related subprograms.
3258 Process_Remote_AST_Declaration
(N
);
3261 -- Validate categorization rule against access type declaration
3262 -- usually a violation in Pure unit, Shared_Passive unit.
3264 Validate_Access_Type_Declaration
(T
, N
);
3266 -- If the type has contracts, we create the corresponding
3267 -- wrapper at once, before analyzing the aspect specifications,
3268 -- so that pre/postconditions can be handled directly on the
3269 -- generated wrapper.
3271 if Ada_Version
>= Ada_2022
3272 and then Present
(Aspect_Specifications
(N
))
3273 and then Expander_Active
3275 Build_Access_Subprogram_Wrapper
(N
);
3278 when N_Access_To_Object_Definition
=>
3279 Access_Type_Declaration
(T
, Def
);
3281 -- Validate categorization rule against access type declaration
3282 -- usually a violation in Pure unit, Shared_Passive unit.
3284 Validate_Access_Type_Declaration
(T
, N
);
3286 -- If we are in a Remote_Call_Interface package and define a
3287 -- RACW, then calling stubs and specific stream attributes
3291 and then Is_Remote_Access_To_Class_Wide_Type
(Def_Id
)
3293 Add_RACW_Features
(Def_Id
);
3296 when N_Array_Type_Definition
=>
3297 Array_Type_Declaration
(T
, Def
);
3299 when N_Derived_Type_Definition
=>
3300 Derived_Type_Declaration
(T
, N
, T
/= Def_Id
);
3302 -- Save the scenario for examination by the ABE Processing
3305 Record_Elaboration_Scenario
(N
);
3307 when N_Enumeration_Type_Definition
=>
3308 Enumeration_Type_Declaration
(T
, Def
);
3310 when N_Floating_Point_Definition
=>
3311 Floating_Point_Type_Declaration
(T
, Def
);
3313 when N_Decimal_Fixed_Point_Definition
=>
3314 Decimal_Fixed_Point_Type_Declaration
(T
, Def
);
3316 when N_Ordinary_Fixed_Point_Definition
=>
3317 Ordinary_Fixed_Point_Type_Declaration
(T
, Def
);
3319 when N_Signed_Integer_Type_Definition
=>
3320 Signed_Integer_Type_Declaration
(T
, Def
);
3322 when N_Modular_Type_Definition
=>
3323 Modular_Type_Declaration
(T
, Def
);
3325 when N_Record_Definition
=>
3326 Record_Type_Declaration
(T
, N
, Prev
);
3328 -- If declaration has a parse error, nothing to elaborate.
3334 raise Program_Error
;
3338 if Etype
(T
) = Any_Type
then
3342 -- Set the primitives list of the full type and its base type when
3343 -- needed. T may be E_Void in cases of earlier errors, and in that
3344 -- case we bypass this.
3346 if Ekind
(T
) /= E_Void
then
3347 if No
(Direct_Primitive_Operations
(T
)) then
3348 if Etype
(T
) = T
then
3349 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3351 -- If Etype of T is the base type (as opposed to a parent type)
3352 -- and already has an associated list of primitive operations,
3353 -- then set T's primitive list to the base type's list. Otherwise,
3354 -- create a new empty primitives list and share the list between
3355 -- T and its base type. The lists need to be shared in common.
3357 elsif Etype
(T
) = Base_Type
(T
) then
3359 if No
(Direct_Primitive_Operations
(Base_Type
(T
))) then
3360 Set_Direct_Primitive_Operations
3361 (Base_Type
(T
), New_Elmt_List
);
3364 Set_Direct_Primitive_Operations
3365 (T
, Direct_Primitive_Operations
(Base_Type
(T
)));
3367 -- Case where the Etype is a parent type, so we need a new
3368 -- primitives list for T.
3371 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3374 -- If T already has a Direct_Primitive_Operations list but its
3375 -- base type doesn't then set the base type's list to T's list.
3377 elsif No
(Direct_Primitive_Operations
(Base_Type
(T
))) then
3378 Set_Direct_Primitive_Operations
3379 (Base_Type
(T
), Direct_Primitive_Operations
(T
));
3383 -- Some common processing for all types
3385 Set_Depends_On_Private
(T
, Has_Private_Component
(T
));
3386 Check_Ops_From_Incomplete_Type
;
3388 -- Both the declared entity, and its anonymous base type if one was
3389 -- created, need freeze nodes allocated.
3392 B
: constant Entity_Id
:= Base_Type
(T
);
3395 -- In the case where the base type differs from the first subtype, we
3396 -- pre-allocate a freeze node, and set the proper link to the first
3397 -- subtype. Freeze_Entity will use this preallocated freeze node when
3398 -- it freezes the entity.
3400 -- This does not apply if the base type is a generic type, whose
3401 -- declaration is independent of the current derived definition.
3403 if B
/= T
and then not Is_Generic_Type
(B
) then
3404 Ensure_Freeze_Node
(B
);
3405 Set_First_Subtype_Link
(Freeze_Node
(B
), T
);
3408 -- A type that is imported through a limited_with clause cannot
3409 -- generate any code, and thus need not be frozen. However, an access
3410 -- type with an imported designated type needs a finalization list,
3411 -- which may be referenced in some other package that has non-limited
3412 -- visibility on the designated type. Thus we must create the
3413 -- finalization list at the point the access type is frozen, to
3414 -- prevent unsatisfied references at link time.
3416 if not From_Limited_With
(T
) or else Is_Access_Type
(T
) then
3417 Set_Has_Delayed_Freeze
(T
);
3421 -- Case where T is the full declaration of some private type which has
3422 -- been swapped in Defining_Identifier (N).
3424 if T
/= Def_Id
and then Is_Private_Type
(Def_Id
) then
3425 Process_Full_View
(N
, T
, Def_Id
);
3427 -- Record the reference. The form of this is a little strange, since
3428 -- the full declaration has been swapped in. So the first parameter
3429 -- here represents the entity to which a reference is made which is
3430 -- the "real" entity, i.e. the one swapped in, and the second
3431 -- parameter provides the reference location.
3433 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3434 -- since we don't want a complaint about the full type being an
3435 -- unwanted reference to the private type
3438 B
: constant Boolean := Has_Pragma_Unreferenced
(T
);
3440 Set_Has_Pragma_Unreferenced
(T
, False);
3441 Generate_Reference
(T
, T
, 'c');
3442 Set_Has_Pragma_Unreferenced
(T
, B
);
3445 Set_Completion_Referenced
(Def_Id
);
3447 -- For completion of incomplete type, process incomplete dependents
3448 -- and always mark the full type as referenced (it is the incomplete
3449 -- type that we get for any real reference).
3451 elsif Ekind
(Prev
) = E_Incomplete_Type
then
3452 Process_Incomplete_Dependents
(N
, T
, Prev
);
3453 Generate_Reference
(Prev
, Def_Id
, 'c');
3454 Set_Completion_Referenced
(Def_Id
);
3456 -- If not private type or incomplete type completion, this is a real
3457 -- definition of a new entity, so record it.
3460 Generate_Definition
(Def_Id
);
3463 if Chars
(Scope
(Def_Id
)) = Name_System
3464 and then Chars
(Def_Id
) = Name_Address
3465 and then In_Predefined_Unit
(N
)
3467 Set_Is_Descendant_Of_Address
(Def_Id
);
3468 Set_Is_Descendant_Of_Address
(Base_Type
(Def_Id
));
3469 Set_Is_Descendant_Of_Address
(Prev
);
3472 Set_Optimize_Alignment_Flags
(Def_Id
);
3473 Check_Eliminated
(Def_Id
);
3475 -- If the declaration is a completion and aspects are present, apply
3476 -- them to the entity for the type which is currently the partial
3477 -- view, but which is the one that will be frozen.
3479 -- In most cases the partial view is a private type, and both views
3480 -- appear in different declarative parts. In the unusual case where
3481 -- the partial view is incomplete, perform the analysis on the
3482 -- full view, to prevent freezing anomalies with the corresponding
3483 -- class-wide type, which otherwise might be frozen before the
3484 -- dispatch table is built.
3487 and then Ekind
(Prev
) /= E_Incomplete_Type
3489 Analyze_Aspect_Specifications
(N
, Prev
);
3494 Analyze_Aspect_Specifications
(N
, Def_Id
);
3497 if Is_Derived_Type
(Prev
)
3498 and then Def_Id
/= Prev
3500 Check_Nonoverridable_Aspects
;
3503 -- Check for tagged type declaration at library level
3505 if Is_Tagged_Type
(T
)
3506 and then not Is_Library_Level_Entity
(T
)
3508 Check_Restriction
(No_Local_Tagged_Types
, T
);
3510 end Analyze_Full_Type_Declaration
;
3512 ----------------------------------
3513 -- Analyze_Incomplete_Type_Decl --
3514 ----------------------------------
3516 procedure Analyze_Incomplete_Type_Decl
(N
: Node_Id
) is
3517 F
: constant Boolean := Is_Pure
(Current_Scope
);
3521 Generate_Definition
(Defining_Identifier
(N
));
3523 -- Process an incomplete declaration. The identifier must not have been
3524 -- declared already in the scope. However, an incomplete declaration may
3525 -- appear in the private part of a package, for a private type that has
3526 -- already been declared.
3528 -- In this case, the discriminants (if any) must match
3530 T
:= Find_Type_Name
(N
);
3532 Mutate_Ekind
(T
, E_Incomplete_Type
);
3534 Set_Is_First_Subtype
(T
);
3535 Reinit_Size_Align
(T
);
3537 -- Set the SPARK mode from the current context
3539 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
3540 Set_SPARK_Pragma_Inherited
(T
);
3542 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
3543 -- incomplete types.
3545 if Tagged_Present
(N
) then
3546 Set_Is_Tagged_Type
(T
, True);
3547 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
3548 Make_Class_Wide_Type
(T
);
3551 -- Initialize the list of primitive operations to an empty list,
3552 -- to cover tagged types as well as untagged types. For untagged
3553 -- types this is used either to analyze the call as legal when
3554 -- Core_Extensions_Allowed is True, or to issue a better error message
3557 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3559 Set_Stored_Constraint
(T
, No_Elist
);
3561 if Present
(Discriminant_Specifications
(N
)) then
3563 Process_Discriminants
(N
);
3567 -- If the type has discriminants, nontrivial subtypes may be declared
3568 -- before the full view of the type. The full views of those subtypes
3569 -- will be built after the full view of the type.
3571 Set_Private_Dependents
(T
, New_Elmt_List
);
3573 end Analyze_Incomplete_Type_Decl
;
3575 -----------------------------------
3576 -- Analyze_Interface_Declaration --
3577 -----------------------------------
3579 procedure Analyze_Interface_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
3580 CW
: constant Entity_Id
:= Class_Wide_Type
(T
);
3583 Set_Is_Tagged_Type
(T
);
3584 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
3586 Set_Is_Limited_Record
(T
, Limited_Present
(Def
)
3587 or else Task_Present
(Def
)
3588 or else Protected_Present
(Def
)
3589 or else Synchronized_Present
(Def
));
3591 -- Type is abstract if full declaration carries keyword, or if previous
3592 -- partial view did.
3594 Set_Is_Abstract_Type
(T
);
3595 Set_Is_Interface
(T
);
3597 -- Type is a limited interface if it includes the keyword limited, task,
3598 -- protected, or synchronized.
3600 Set_Is_Limited_Interface
3601 (T
, Limited_Present
(Def
)
3602 or else Protected_Present
(Def
)
3603 or else Synchronized_Present
(Def
)
3604 or else Task_Present
(Def
));
3606 Set_Interfaces
(T
, New_Elmt_List
);
3607 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3609 -- Complete the decoration of the class-wide entity if it was already
3610 -- built (i.e. during the creation of the limited view)
3612 if Present
(CW
) then
3613 Set_Is_Interface
(CW
);
3614 Set_Is_Limited_Interface
(CW
, Is_Limited_Interface
(T
));
3617 -- Check runtime support for synchronized interfaces
3619 if Is_Concurrent_Interface
(T
)
3620 and then not RTE_Available
(RE_Select_Specific_Data
)
3622 Error_Msg_CRT
("synchronized interfaces", T
);
3624 end Analyze_Interface_Declaration
;
3626 -----------------------------
3627 -- Analyze_Itype_Reference --
3628 -----------------------------
3630 -- Nothing to do. This node is placed in the tree only for the benefit of
3631 -- back end processing, and has no effect on the semantic processing.
3633 procedure Analyze_Itype_Reference
(N
: Node_Id
) is
3635 pragma Assert
(Is_Itype
(Itype
(N
)));
3637 end Analyze_Itype_Reference
;
3639 --------------------------------
3640 -- Analyze_Number_Declaration --
3641 --------------------------------
3643 procedure Analyze_Number_Declaration
(N
: Node_Id
) is
3644 E
: Node_Id
:= Expression
(N
);
3645 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3646 Index
: Interp_Index
;
3651 Generate_Definition
(Id
);
3654 -- This is an optimization of a common case of an integer literal
3656 if Nkind
(E
) = N_Integer_Literal
then
3657 Set_Is_Static_Expression
(E
, True);
3658 Set_Etype
(E
, Universal_Integer
);
3660 Set_Etype
(Id
, Universal_Integer
);
3661 Mutate_Ekind
(Id
, E_Named_Integer
);
3662 Set_Is_Frozen
(Id
, True);
3664 Set_Debug_Info_Needed
(Id
);
3668 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
3670 -- Replace Error by integer zero, which seems least likely to cause
3674 pragma Assert
(Serious_Errors_Detected
> 0);
3675 E
:= Make_Integer_Literal
(Sloc
(N
), Uint_0
);
3676 Set_Expression
(N
, E
);
3677 Set_Error_Posted
(E
);
3682 -- Verify that the expression is static and numeric. If
3683 -- the expression is overloaded, we apply the preference
3684 -- rule that favors root numeric types.
3686 if not Is_Overloaded
(E
) then
3688 if Has_Dynamic_Predicate_Aspect
(T
)
3689 or else Has_Ghost_Predicate_Aspect
(T
)
3692 ("subtype has non-static predicate, "
3693 & "not allowed in number declaration", N
);
3699 Get_First_Interp
(E
, Index
, It
);
3700 while Present
(It
.Typ
) loop
3701 if (Is_Integer_Type
(It
.Typ
) or else Is_Real_Type
(It
.Typ
))
3702 and then (Scope
(Base_Type
(It
.Typ
))) = Standard_Standard
3704 if T
= Any_Type
then
3707 elsif Is_Universal_Numeric_Type
(It
.Typ
) then
3708 -- Choose universal interpretation over any other
3715 Get_Next_Interp
(Index
, It
);
3719 if Is_Integer_Type
(T
) then
3721 Set_Etype
(Id
, Universal_Integer
);
3722 Mutate_Ekind
(Id
, E_Named_Integer
);
3724 elsif Is_Real_Type
(T
) then
3726 -- Because the real value is converted to universal_real, this is a
3727 -- legal context for a universal fixed expression.
3729 if T
= Universal_Fixed
then
3731 Loc
: constant Source_Ptr
:= Sloc
(N
);
3732 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3734 New_Occurrence_Of
(Universal_Real
, Loc
),
3735 Expression
=> Relocate_Node
(E
));
3742 elsif T
= Any_Fixed
then
3743 Error_Msg_N
("illegal context for mixed mode operation", E
);
3745 -- Expression is of the form : universal_fixed * integer. Try to
3746 -- resolve as universal_real.
3748 T
:= Universal_Real
;
3753 Set_Etype
(Id
, Universal_Real
);
3754 Mutate_Ekind
(Id
, E_Named_Real
);
3757 Wrong_Type
(E
, Any_Numeric
);
3761 Mutate_Ekind
(Id
, E_Constant
);
3762 Set_Never_Set_In_Source
(Id
, True);
3763 Set_Is_True_Constant
(Id
, True);
3767 if Nkind
(E
) in N_Integer_Literal | N_Real_Literal
then
3768 Set_Etype
(E
, Etype
(Id
));
3771 if not Is_OK_Static_Expression
(E
) then
3772 Flag_Non_Static_Expr
3773 ("non-static expression used in number declaration!", E
);
3774 Rewrite
(E
, Make_Integer_Literal
(Sloc
(N
), 1));
3775 Set_Etype
(E
, Any_Type
);
3778 Analyze_Dimension
(N
);
3779 end Analyze_Number_Declaration
;
3781 --------------------------------
3782 -- Analyze_Object_Declaration --
3783 --------------------------------
3785 -- WARNING: This routine manages Ghost regions. Return statements must be
3786 -- replaced by gotos which jump to the end of the routine and restore the
3789 procedure Analyze_Object_Declaration
(N
: Node_Id
) is
3790 Loc
: constant Source_Ptr
:= Sloc
(N
);
3791 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3792 Next_Decl
: constant Node_Id
:= Next
(N
);
3797 E
: Node_Id
:= Expression
(N
);
3798 -- E is set to Expression (N) throughout this routine. When Expression
3799 -- (N) is modified, E is changed accordingly.
3801 procedure Check_Dynamic_Object
(Typ
: Entity_Id
);
3802 -- A library-level object with nonstatic discriminant constraints may
3803 -- require dynamic allocation. The declaration is illegal if the
3804 -- profile includes the restriction No_Implicit_Heap_Allocations.
3806 procedure Check_For_Null_Excluding_Components
3807 (Obj_Typ
: Entity_Id
;
3808 Obj_Decl
: Node_Id
);
3809 -- Verify that each null-excluding component of object declaration
3810 -- Obj_Decl carrying type Obj_Typ has explicit initialization. Emit
3811 -- a compile-time warning if this is not the case.
3813 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
3814 -- Check that the return subtype indication properly matches the result
3815 -- subtype of the function in an extended return object declaration, as
3816 -- required by RM 6.5(5.1/2-5.3/2).
3818 function Count_Tasks
(T
: Entity_Id
) return Uint
;
3819 -- This function is called when a non-generic library level object of a
3820 -- task type is declared. Its function is to count the static number of
3821 -- tasks declared within the type (it is only called if Has_Task is set
3822 -- for T). As a side effect, if an array of tasks with nonstatic bounds
3823 -- or a variant record type is encountered, Check_Restriction is called
3824 -- indicating the count is unknown.
3826 function Delayed_Aspect_Present
return Boolean;
3827 -- If the declaration has an expression that is an aggregate, and it
3828 -- has aspects that require delayed analysis, the resolution of the
3829 -- aggregate must be deferred to the freeze point of the object. This
3830 -- special processing was created for address clauses, but it must
3831 -- also apply to address aspects. This must be done before the aspect
3832 -- specifications are analyzed because we must handle the aggregate
3833 -- before the analysis of the object declaration is complete.
3835 -- Any other relevant delayed aspects on object declarations ???
3837 --------------------------
3838 -- Check_Dynamic_Object --
3839 --------------------------
3841 procedure Check_Dynamic_Object
(Typ
: Entity_Id
) is
3843 Obj_Type
: Entity_Id
;
3848 if Is_Private_Type
(Obj_Type
)
3849 and then Present
(Full_View
(Obj_Type
))
3851 Obj_Type
:= Full_View
(Obj_Type
);
3854 if Known_Static_Esize
(Obj_Type
) then
3858 if Restriction_Active
(No_Implicit_Heap_Allocations
)
3859 and then Expander_Active
3860 and then Has_Discriminants
(Obj_Type
)
3862 Comp
:= First_Component
(Obj_Type
);
3863 while Present
(Comp
) loop
3864 if Known_Static_Esize
(Etype
(Comp
))
3865 or else Size_Known_At_Compile_Time
(Etype
(Comp
))
3869 elsif Is_Record_Type
(Etype
(Comp
)) then
3870 Check_Dynamic_Object
(Etype
(Comp
));
3872 elsif not Discriminated_Size
(Comp
)
3873 and then Comes_From_Source
(Comp
)
3876 ("component& of non-static size will violate restriction "
3877 & "No_Implicit_Heap_Allocation?", N
, Comp
);
3881 Next_Component
(Comp
);
3884 end Check_Dynamic_Object
;
3886 -----------------------------------------
3887 -- Check_For_Null_Excluding_Components --
3888 -----------------------------------------
3890 procedure Check_For_Null_Excluding_Components
3891 (Obj_Typ
: Entity_Id
;
3894 procedure Check_Component
3895 (Comp_Typ
: Entity_Id
;
3896 Comp_Decl
: Node_Id
:= Empty
;
3897 Array_Comp
: Boolean := False);
3898 -- Apply a compile-time null-exclusion check on a component denoted
3899 -- by its declaration Comp_Decl and type Comp_Typ, and all of its
3900 -- subcomponents (if any).
3902 ---------------------
3903 -- Check_Component --
3904 ---------------------
3906 procedure Check_Component
3907 (Comp_Typ
: Entity_Id
;
3908 Comp_Decl
: Node_Id
:= Empty
;
3909 Array_Comp
: Boolean := False)
3915 -- Do not consider internally-generated components or those that
3916 -- are already initialized.
3918 if Present
(Comp_Decl
)
3919 and then (not Comes_From_Source
(Comp_Decl
)
3920 or else Present
(Expression
(Comp_Decl
)))
3925 if Is_Incomplete_Or_Private_Type
(Comp_Typ
)
3926 and then Present
(Full_View
(Comp_Typ
))
3928 T
:= Full_View
(Comp_Typ
);
3933 -- Verify a component of a null-excluding access type
3935 if Is_Access_Type
(T
)
3936 and then Can_Never_Be_Null
(T
)
3938 if Comp_Decl
= Obj_Decl
then
3939 Null_Exclusion_Static_Checks
3942 Array_Comp
=> Array_Comp
);
3945 Null_Exclusion_Static_Checks
3948 Array_Comp
=> Array_Comp
);
3951 -- Check array components
3953 elsif Is_Array_Type
(T
) then
3955 -- There is no suitable component when the object is of an
3956 -- array type. However, a namable component may appear at some
3957 -- point during the recursive inspection, but not at the top
3958 -- level. At the top level just indicate array component case.
3960 if Comp_Decl
= Obj_Decl
then
3961 Check_Component
(Component_Type
(T
), Array_Comp
=> True);
3963 Check_Component
(Component_Type
(T
), Comp_Decl
);
3966 -- Verify all components of type T
3968 -- Note: No checks are performed on types with discriminants due
3969 -- to complexities involving variants. ???
3971 elsif (Is_Concurrent_Type
(T
)
3972 or else Is_Incomplete_Or_Private_Type
(T
)
3973 or else Is_Record_Type
(T
))
3974 and then not Has_Discriminants
(T
)
3976 Comp
:= First_Component
(T
);
3977 while Present
(Comp
) loop
3978 Check_Component
(Etype
(Comp
), Parent
(Comp
));
3980 Next_Component
(Comp
);
3983 end Check_Component
;
3985 -- Start processing for Check_For_Null_Excluding_Components
3988 Check_Component
(Obj_Typ
, Obj_Decl
);
3989 end Check_For_Null_Excluding_Components
;
3991 -------------------------------------
3992 -- Check_Return_Subtype_Indication --
3993 -------------------------------------
3995 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
3996 Obj_Id
: constant Entity_Id
:= Defining_Identifier
(Obj_Decl
);
3997 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
3998 Func_Id
: constant Entity_Id
:= Return_Applies_To
(Scope
(Obj_Id
));
3999 R_Typ
: constant Entity_Id
:= Etype
(Func_Id
);
4000 Indic
: constant Node_Id
:=
4001 Object_Definition
(Original_Node
(Obj_Decl
));
4003 procedure Error_No_Match
(N
: Node_Id
);
4004 -- Output error messages for case where types do not statically
4005 -- match. N is the location for the messages.
4007 --------------------
4008 -- Error_No_Match --
4009 --------------------
4011 procedure Error_No_Match
(N
: Node_Id
) is
4014 ("subtype must statically match function result subtype", N
);
4016 if not Predicates_Match
(Obj_Typ
, R_Typ
) then
4017 Error_Msg_Node_2
:= R_Typ
;
4019 ("\predicate of& does not match predicate of&",
4024 -- Start of processing for Check_Return_Subtype_Indication
4027 -- First, avoid cascaded errors
4029 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Indic
) then
4033 -- "return access T" case; check that the return statement also has
4034 -- "access T", and that the subtypes statically match:
4035 -- if this is an access to subprogram the signatures must match.
4037 if Is_Anonymous_Access_Type
(R_Typ
) then
4038 if Is_Anonymous_Access_Type
(Obj_Typ
) then
4039 if Ekind
(Designated_Type
(Obj_Typ
)) /= E_Subprogram_Type
4041 if Base_Type
(Designated_Type
(Obj_Typ
)) /=
4042 Base_Type
(Designated_Type
(R_Typ
))
4043 or else not Subtypes_Statically_Match
(Obj_Typ
, R_Typ
)
4045 Error_No_Match
(Subtype_Mark
(Indic
));
4049 -- For two anonymous access to subprogram types, the types
4050 -- themselves must be type conformant.
4052 if not Conforming_Types
4053 (Obj_Typ
, R_Typ
, Fully_Conformant
)
4055 Error_No_Match
(Indic
);
4060 Error_Msg_N
("must use anonymous access type", Indic
);
4063 -- If the return object is of an anonymous access type, then report
4064 -- an error if the function's result type is not also anonymous.
4066 elsif Is_Anonymous_Access_Type
(Obj_Typ
) then
4067 pragma Assert
(not Is_Anonymous_Access_Type
(R_Typ
));
4069 ("anonymous access not allowed for function with named access "
4072 -- Subtype indication case: check that the return object's type is
4073 -- covered by the result type, and that the subtypes statically match
4074 -- when the result subtype is constrained. Also handle record types
4075 -- with unknown discriminants for which we have built the underlying
4076 -- record view. Coverage is needed to allow specific-type return
4077 -- objects when the result type is class-wide (see AI05-32).
4079 elsif Covers
(Base_Type
(R_Typ
), Base_Type
(Obj_Typ
))
4080 or else (Is_Underlying_Record_View
(Base_Type
(Obj_Typ
))
4084 Underlying_Record_View
(Base_Type
(Obj_Typ
))))
4086 -- A null exclusion may be present on the return type, on the
4087 -- function specification, on the object declaration or on the
4090 if Is_Access_Type
(R_Typ
)
4092 (Can_Never_Be_Null
(R_Typ
)
4093 or else Null_Exclusion_Present
(Parent
(Func_Id
))) /=
4094 Can_Never_Be_Null
(Obj_Typ
)
4096 Error_No_Match
(Indic
);
4099 -- AI05-103: for elementary types, subtypes must statically match
4101 if Is_Constrained
(R_Typ
) or else Is_Access_Type
(R_Typ
) then
4102 if not Subtypes_Statically_Match
(Obj_Typ
, R_Typ
) then
4103 Error_No_Match
(Indic
);
4106 -- If the result subtype of the function is defined by a
4107 -- subtype_mark, the return_subtype_indication shall be a
4108 -- subtype_indication. The subtype defined by the subtype_
4109 -- indication shall be statically compatible with the result
4110 -- subtype of the function (RM 6.5(5.3/5)).
4112 -- We exclude the extended return statement of the predefined
4113 -- stream input to avoid reporting spurious errors, because its
4114 -- code is expanded on the basis of the base type (see subprogram
4115 -- Stream_Base_Type).
4117 elsif Nkind
(Indic
) = N_Subtype_Indication
4118 and then not Subtypes_Statically_Compatible
(Obj_Typ
, R_Typ
)
4119 and then not Is_TSS
(Func_Id
, TSS_Stream_Input
)
4122 ("result subtype must be statically compatible with the " &
4123 "function result type", Indic
);
4125 if not Predicates_Compatible
(Obj_Typ
, R_Typ
) then
4127 ("\predicate on result subtype is not compatible with &",
4132 -- All remaining cases are illegal
4134 -- Note: previous versions of this subprogram allowed the return
4135 -- value to be the ancestor of the return type if the return type
4136 -- was a null extension. This was plainly incorrect.
4140 ("wrong type for return_subtype_indication", Indic
);
4142 end Check_Return_Subtype_Indication
;
4148 function Count_Tasks
(T
: Entity_Id
) return Uint
is
4154 if Is_Task_Type
(T
) then
4157 elsif Is_Record_Type
(T
) then
4158 if Has_Discriminants
(T
) then
4159 Check_Restriction
(Max_Tasks
, N
);
4164 C
:= First_Component
(T
);
4165 while Present
(C
) loop
4166 V
:= V
+ Count_Tasks
(Etype
(C
));
4173 elsif Is_Array_Type
(T
) then
4174 X
:= First_Index
(T
);
4175 V
:= Count_Tasks
(Component_Type
(T
));
4176 while Present
(X
) loop
4179 if not Is_OK_Static_Subtype
(C
) then
4180 Check_Restriction
(Max_Tasks
, N
);
4183 V
:= V
* (UI_Max
(Uint_0
,
4184 Expr_Value
(Type_High_Bound
(C
)) -
4185 Expr_Value
(Type_Low_Bound
(C
)) + Uint_1
));
4198 ----------------------------
4199 -- Delayed_Aspect_Present --
4200 ----------------------------
4202 function Delayed_Aspect_Present
return Boolean is
4207 A
:= First
(Aspect_Specifications
(N
));
4209 while Present
(A
) loop
4210 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(A
)));
4212 if A_Id
= Aspect_Address
then
4214 -- Set flag on object entity, for later processing at the
4217 Set_Has_Delayed_Aspects
(Id
);
4225 end Delayed_Aspect_Present
;
4229 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4230 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
4231 -- Save the Ghost-related attributes to restore on exit
4233 Prev_Entity
: Entity_Id
:= Empty
;
4234 Related_Id
: Entity_Id
;
4236 -- Start of processing for Analyze_Object_Declaration
4239 -- There are three kinds of implicit types generated by an
4240 -- object declaration:
4242 -- 1. Those generated by the original Object Definition
4244 -- 2. Those generated by the Expression
4246 -- 3. Those used to constrain the Object Definition with the
4247 -- expression constraints when the definition is unconstrained.
4249 -- They must be generated in this order to avoid order of elaboration
4250 -- issues. Thus the first step (after entering the name) is to analyze
4251 -- the object definition.
4253 if Constant_Present
(N
) then
4254 Prev_Entity
:= Current_Entity_In_Scope
(Id
);
4256 if Present
(Prev_Entity
)
4258 -- If the homograph is an implicit subprogram, it is overridden
4259 -- by the current declaration.
4261 ((Is_Overloadable
(Prev_Entity
)
4262 and then Is_Inherited_Operation
(Prev_Entity
))
4264 -- The current object is a discriminal generated for an entry
4265 -- family index. Even though the index is a constant, in this
4266 -- particular context there is no true constant redeclaration.
4267 -- Enter_Name will handle the visibility.
4270 (Is_Discriminal
(Id
)
4271 and then Ekind
(Discriminal_Link
(Id
)) =
4272 E_Entry_Index_Parameter
)
4274 -- The current object is the renaming for a generic declared
4275 -- within the instance.
4278 (Ekind
(Prev_Entity
) = E_Package
4279 and then Nkind
(Parent
(Prev_Entity
)) =
4280 N_Package_Renaming_Declaration
4281 and then not Comes_From_Source
(Prev_Entity
)
4283 Is_Generic_Instance
(Renamed_Entity
(Prev_Entity
)))
4285 -- The entity may be a homonym of a private component of the
4286 -- enclosing protected object, for which we create a local
4287 -- renaming declaration. The declaration is legal, even if
4288 -- useless when it just captures that component.
4291 (Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
4292 and then Nkind
(Parent
(Prev_Entity
)) =
4293 N_Object_Renaming_Declaration
))
4295 Prev_Entity
:= Empty
;
4299 if Present
(Prev_Entity
) then
4301 -- The object declaration is Ghost when it completes a deferred Ghost
4304 Mark_And_Set_Ghost_Completion
(N
, Prev_Entity
);
4306 Constant_Redeclaration
(Id
, N
, T
);
4308 Generate_Reference
(Prev_Entity
, Id
, 'c');
4309 Set_Completion_Referenced
(Id
);
4311 if Error_Posted
(N
) then
4313 -- Type mismatch or illegal redeclaration; do not analyze
4314 -- expression to avoid cascaded errors.
4316 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4318 Mutate_Ekind
(Id
, E_Variable
);
4322 -- In the normal case, enter identifier at the start to catch premature
4323 -- usage in the initialization expression.
4326 Generate_Definition
(Id
);
4329 Mark_Coextensions
(N
, Object_Definition
(N
));
4331 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4333 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
4335 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
4336 and then Protected_Present
4337 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
4339 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
4342 if Error_Posted
(Id
) then
4344 Mutate_Ekind
(Id
, E_Variable
);
4349 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
4350 -- out some static checks.
4352 if Ada_Version
>= Ada_2005
then
4354 -- In case of aggregates we must also take care of the correct
4355 -- initialization of nested aggregates bug this is done at the
4356 -- point of the analysis of the aggregate (see sem_aggr.adb) ???
4358 if Can_Never_Be_Null
(T
) then
4359 if Present
(Expression
(N
))
4360 and then Nkind
(Expression
(N
)) = N_Aggregate
4364 elsif Comes_From_Source
(Id
) then
4366 Save_Typ
: constant Entity_Id
:= Etype
(Id
);
4368 Set_Etype
(Id
, T
); -- Temp. decoration for static checks
4369 Null_Exclusion_Static_Checks
(N
);
4370 Set_Etype
(Id
, Save_Typ
);
4374 -- We might be dealing with an object of a composite type containing
4375 -- null-excluding components without an aggregate, so we must verify
4376 -- that such components have default initialization.
4379 Check_For_Null_Excluding_Components
(T
, N
);
4383 -- Object is marked pure if it is in a pure scope
4385 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
4387 -- If deferred constant, make sure context is appropriate. We detect
4388 -- a deferred constant as a constant declaration with no expression.
4389 -- A deferred constant can appear in a package body if its completion
4390 -- is by means of an interface pragma.
4392 if Constant_Present
(N
) and then No
(E
) then
4394 -- A deferred constant may appear in the declarative part of the
4395 -- following constructs:
4399 -- extended return statements
4402 -- subprogram bodies
4405 -- When declared inside a package spec, a deferred constant must be
4406 -- completed by a full constant declaration or pragma Import. In all
4407 -- other cases, the only proper completion is pragma Import. Extended
4408 -- return statements are flagged as invalid contexts because they do
4409 -- not have a declarative part and so cannot accommodate the pragma.
4411 if Ekind
(Current_Scope
) = E_Return_Statement
then
4413 ("invalid context for deferred constant declaration (RM 7.4)",
4416 ("\declaration requires an initialization expression",
4418 Set_Constant_Present
(N
, False);
4420 -- In Ada 83, deferred constant must be of private type
4422 elsif not Is_Private_Type
(T
) then
4423 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4425 ("(Ada 83) deferred constant must be private type", N
);
4429 -- If not a deferred constant, then the object declaration freezes
4430 -- its type, unless the object is of an anonymous type and has delayed
4431 -- aspects (in that case the type is frozen when the object itself is)
4432 -- or the context is a spec expression.
4435 Check_Fully_Declared
(T
, N
);
4437 if Has_Delayed_Aspects
(Id
)
4438 and then Is_Array_Type
(T
)
4439 and then Is_Itype
(T
)
4441 Set_Has_Delayed_Freeze
(T
);
4442 elsif not In_Spec_Expression
then
4443 Freeze_Before
(N
, T
);
4447 -- If the object was created by a constrained array definition, then
4448 -- set the link in both the anonymous base type and anonymous subtype
4449 -- that are built to represent the array type to point to the object.
4451 if Nkind
(Object_Definition
(Declaration_Node
(Id
))) =
4452 N_Constrained_Array_Definition
4454 Set_Related_Array_Object
(T
, Id
);
4455 Set_Related_Array_Object
(Base_Type
(T
), Id
);
4458 -- Check for protected objects not at library level
4460 if Has_Protected
(T
) and then not Is_Library_Level_Entity
(Id
) then
4461 Check_Restriction
(No_Local_Protected_Objects
, Id
);
4464 -- Check for violation of No_Local_Timing_Events
4466 if Has_Timing_Event
(T
) and then not Is_Library_Level_Entity
(Id
) then
4467 Check_Restriction
(No_Local_Timing_Events
, Id
);
4470 -- The actual subtype of the object is the nominal subtype, unless
4471 -- the nominal one is unconstrained and obtained from the expression.
4475 if Is_Library_Level_Entity
(Id
) then
4476 Check_Dynamic_Object
(T
);
4479 -- Process initialization expression if present and not in error
4481 if Present
(E
) and then E
/= Error
then
4483 -- Generate an error in case of CPP class-wide object initialization.
4484 -- Required because otherwise the expansion of the class-wide
4485 -- assignment would try to use 'size to initialize the object
4486 -- (primitive that is not available in CPP tagged types).
4488 if Is_Class_Wide_Type
(Act_T
)
4490 (Is_CPP_Class
(Root_Type
(Etype
(Act_T
)))
4492 (Present
(Full_View
(Root_Type
(Etype
(Act_T
))))
4494 Is_CPP_Class
(Full_View
(Root_Type
(Etype
(Act_T
))))))
4497 ("predefined assignment not available for 'C'P'P tagged types",
4501 Mark_Coextensions
(N
, E
);
4504 -- In case of errors detected in the analysis of the expression,
4505 -- decorate it with the expected type to avoid cascaded errors.
4507 if No
(Etype
(E
)) then
4511 -- If an initialization expression is present, then we set the
4512 -- Is_True_Constant flag. It will be reset if this is a variable
4513 -- and it is indeed modified.
4515 Set_Is_True_Constant
(Id
, True);
4517 -- If we are analyzing a constant declaration, set its completion
4518 -- flag after analyzing and resolving the expression.
4520 if Constant_Present
(N
) then
4521 Set_Has_Completion
(Id
);
4524 -- Set type and resolve (type may be overridden later on). Note:
4525 -- Ekind (Id) must still be E_Void at this point so that incorrect
4526 -- early usage within E is properly diagnosed.
4530 -- If the expression is an aggregate we must look ahead to detect
4531 -- the possible presence of an address clause, and defer resolution
4532 -- and expansion of the aggregate to the freeze point of the entity.
4534 -- This is not always legal because the aggregate may contain other
4535 -- references that need freezing, e.g. references to other entities
4536 -- with address clauses. In any case, when compiling with -gnatI the
4537 -- presence of the address clause must be ignored.
4539 if Comes_From_Source
(N
)
4540 and then Expander_Active
4541 and then Nkind
(E
) = N_Aggregate
4543 ((Present
(Following_Address_Clause
(N
))
4544 and then not Ignore_Rep_Clauses
)
4545 or else Delayed_Aspect_Present
)
4549 -- If the aggregate is limited it will be built in place, and its
4550 -- expansion is deferred until the object declaration is expanded.
4552 -- This is also required when generating C code to ensure that an
4553 -- object with an alignment or address clause can be initialized
4554 -- by means of component by component assignments.
4556 if Is_Limited_Type
(T
) or else Modify_Tree_For_C
then
4557 Set_Expansion_Delayed
(E
);
4561 -- If the expression is a formal that is a "subprogram pointer"
4562 -- this is illegal in accessibility terms (see RM 3.10.2 (13.1/2)
4563 -- and AARM 3.10.2 (13.b/2)). Add an explicit conversion to force
4564 -- the corresponding check, as is done for assignments.
4566 if Is_Entity_Name
(E
)
4567 and then Present
(Entity
(E
))
4568 and then Is_Formal
(Entity
(E
))
4570 Ekind
(Etype
(Entity
(E
))) = E_Anonymous_Access_Subprogram_Type
4571 and then Ekind
(T
) /= E_Anonymous_Access_Subprogram_Type
4573 Rewrite
(E
, Convert_To
(T
, Relocate_Node
(E
)));
4579 -- No further action needed if E is a call to an inlined function
4580 -- which returns an unconstrained type and it has been expanded into
4581 -- a procedure call. In that case N has been replaced by an object
4582 -- declaration without initializing expression and it has been
4583 -- analyzed (see Expand_Inlined_Call).
4585 if Back_End_Inlining
4586 and then Expander_Active
4587 and then Nkind
(E
) = N_Function_Call
4588 and then Nkind
(Name
(E
)) in N_Has_Entity
4589 and then Is_Inlined
(Entity
(Name
(E
)))
4590 and then not Is_Constrained
(Etype
(E
))
4591 and then Analyzed
(N
)
4592 and then No
(Expression
(N
))
4597 -- If E is null and has been replaced by an N_Raise_Constraint_Error
4598 -- node (which was marked already-analyzed), we need to set the type
4599 -- to something else than Universal_Access to keep gigi happy.
4601 if Etype
(E
) = Universal_Access
then
4605 -- If the object is an access to variable, the initialization
4606 -- expression cannot be an access to constant.
4608 if Is_Access_Type
(T
)
4609 and then not Is_Access_Constant
(T
)
4610 and then Is_Access_Type
(Etype
(E
))
4611 and then Is_Access_Constant
(Etype
(E
))
4614 ("access to variable cannot be initialized with an "
4615 & "access-to-constant expression", E
);
4618 if not Assignment_OK
(N
) then
4619 Check_Initialization
(T
, E
);
4622 Check_Unset_Reference
(E
);
4624 -- If this is a variable, then set current value. If this is a
4625 -- declared constant of a scalar type with a static expression,
4626 -- indicate that it is always valid.
4628 if not Constant_Present
(N
) then
4629 if Compile_Time_Known_Value
(E
) then
4630 Set_Current_Value
(Id
, E
);
4633 elsif Is_Scalar_Type
(T
) and then Is_OK_Static_Expression
(E
) then
4634 Set_Is_Known_Valid
(Id
);
4636 -- If it is a constant initialized with a valid nonstatic entity,
4637 -- the constant is known valid as well, and can inherit the subtype
4638 -- of the entity if it is a subtype of the given type. This info
4639 -- is preserved on the actual subtype of the constant.
4641 elsif Is_Scalar_Type
(T
)
4642 and then Is_Entity_Name
(E
)
4643 and then Is_Known_Valid
(Entity
(E
))
4644 and then In_Subrange_Of
(Etype
(Entity
(E
)), T
)
4646 Set_Is_Known_Valid
(Id
);
4647 Mutate_Ekind
(Id
, E_Constant
);
4648 Set_Actual_Subtype
(Id
, Etype
(Entity
(E
)));
4651 -- Deal with setting of null flags
4653 if Is_Access_Type
(T
) then
4654 if Known_Non_Null
(E
) then
4655 Set_Is_Known_Non_Null
(Id
, True);
4656 elsif Known_Null
(E
) and then not Can_Never_Be_Null
(Id
) then
4657 Set_Is_Known_Null
(Id
, True);
4661 -- Check incorrect use of dynamically tagged expressions
4663 if Is_Tagged_Type
(T
) then
4664 Check_Dynamically_Tagged_Expression
4670 Apply_Scalar_Range_Check
(E
, T
);
4671 Apply_Static_Length_Check
(E
, T
);
4673 -- A formal parameter of a specific tagged type whose related
4674 -- subprogram is subject to pragma Extensions_Visible with value
4675 -- "False" cannot be implicitly converted to a class-wide type by
4676 -- means of an initialization expression (SPARK RM 6.1.7(3)). Do
4677 -- not consider internally generated expressions.
4679 if Is_Class_Wide_Type
(T
)
4680 and then Comes_From_Source
(E
)
4681 and then Is_EVF_Expression
(E
)
4684 ("formal parameter cannot be implicitly converted to "
4685 & "class-wide type when Extensions_Visible is False", E
);
4689 -- If the No_Streams restriction is set, check that the type of the
4690 -- object is not, and does not contain, any subtype derived from
4691 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
4692 -- Has_Stream just for efficiency reasons. There is no point in
4693 -- spending time on a Has_Stream check if the restriction is not set.
4695 if Restriction_Check_Required
(No_Streams
) then
4696 if Has_Stream
(T
) then
4697 Check_Restriction
(No_Streams
, N
);
4701 -- Deal with predicate check before we start to do major rewriting. It
4702 -- is OK to initialize and then check the initialized value, since the
4703 -- object goes out of scope if we get a predicate failure. Note that we
4704 -- do this in the analyzer and not the expander because the analyzer
4705 -- does some substantial rewriting in some cases.
4707 -- We need a predicate check if the type has predicates that are not
4708 -- ignored, and if either there is an initializing expression, or for
4709 -- default initialization when we have at least one case of an explicit
4710 -- default initial value (including via a Default_Value or
4711 -- Default_Component_Value aspect, see AI12-0301) and then this is not
4712 -- an internal declaration whose initialization comes later (as for an
4713 -- aggregate expansion) or a deferred constant.
4714 -- If expression is an aggregate it may be expanded into assignments
4715 -- and the declaration itself is marked with No_Initialization, but
4716 -- the predicate still applies.
4718 if not Suppress_Assignment_Checks
(N
)
4719 and then (Predicate_Enabled
(T
) or else Has_Static_Predicate
(T
))
4721 (not No_Initialization
(N
)
4722 or else (Present
(E
) and then Nkind
(E
) = N_Aggregate
))
4726 Is_Partially_Initialized_Type
(T
, Include_Implicit
=> False))
4727 and then not (Constant_Present
(N
) and then No
(E
))
4729 -- If the type has a static predicate and the expression is known at
4730 -- compile time, see if the expression satisfies the predicate.
4731 -- In the case of a static expression, this must be done even if
4732 -- the predicate is not enabled (as per static expression rules).
4735 Check_Expression_Against_Static_Predicate
(E
, T
);
4738 -- Do not perform further predicate-related checks unless
4739 -- predicates are enabled for the subtype.
4741 if not Predicate_Enabled
(T
) then
4744 -- If the type is a null record and there is no explicit initial
4745 -- expression, no predicate check applies.
4747 elsif No
(E
) and then Is_Null_Record_Type
(T
) then
4750 -- If there is an address clause for this object, do not generate a
4751 -- predicate check here. It will be generated later, at the freezng
4752 -- point. It would be wrong to generate references to the object
4753 -- here, before the address has been determined.
4755 elsif Has_Aspect
(Id
, Aspect_Address
)
4756 or else Present
(Following_Address_Clause
(N
))
4760 -- Do not generate a predicate check if the initialization expression
4761 -- is a type conversion whose target subtype statically matches the
4762 -- object's subtype because the conversion has been subjected to the
4763 -- same check. This is a small optimization which avoids redundant
4767 and then Nkind
(E
) in N_Type_Conversion
4768 and then Subtypes_Statically_Match
(Etype
(Subtype_Mark
(E
)), T
)
4773 -- The check must be inserted after the expanded aggregate
4774 -- expansion code, if any.
4777 Check
: constant Node_Id
:=
4778 Make_Predicate_Check
(T
, New_Occurrence_Of
(Id
, Loc
));
4780 if No
(Next_Decl
) then
4781 Append_To
(List_Containing
(N
), Check
);
4783 Insert_Before
(Next_Decl
, Check
);
4789 -- Case of unconstrained type
4791 if not Is_Definite_Subtype
(T
) then
4793 -- Nothing to do in deferred constant case
4795 if Constant_Present
(N
) and then No
(E
) then
4798 -- Case of no initialization present
4801 if No_Initialization
(N
) then
4804 elsif Is_Class_Wide_Type
(T
) then
4806 ("initialization required in class-wide declaration", N
);
4810 ("unconstrained subtype not allowed (need initialization)",
4811 Object_Definition
(N
));
4813 if Is_Record_Type
(T
) and then Has_Discriminants
(T
) then
4815 ("\provide initial value or explicit discriminant values",
4816 Object_Definition
(N
));
4819 ("\or give default discriminant values for type&",
4820 Object_Definition
(N
), T
);
4822 elsif Is_Array_Type
(T
) then
4824 ("\provide initial value or explicit array bounds",
4825 Object_Definition
(N
));
4829 -- Case of initialization present but in error. Set initial
4830 -- expression as absent (but do not make above complaints).
4832 elsif E
= Error
then
4833 Set_Expression
(N
, Empty
);
4836 -- Case of initialization present
4839 -- Unconstrained variables not allowed in Ada 83
4841 if Ada_Version
= Ada_83
4842 and then not Constant_Present
(N
)
4843 and then Comes_From_Source
(Object_Definition
(N
))
4846 ("(Ada 83) unconstrained variable not allowed",
4847 Object_Definition
(N
));
4850 -- Now we constrain the variable from the initializing expression
4852 -- If the expression is an aggregate, it has been expanded into
4853 -- individual assignments. Retrieve the actual type from the
4854 -- expanded construct.
4856 if Is_Array_Type
(T
)
4857 and then No_Initialization
(N
)
4858 and then Nkind
(Original_Node
(E
)) = N_Aggregate
4862 -- In case of class-wide interface object declarations we delay
4863 -- the generation of the equivalent record type declarations until
4864 -- its expansion because there are cases in they are not required.
4866 elsif Is_Interface
(T
) then
4869 -- If the type is an unchecked union, no subtype can be built from
4870 -- the expression. Rewrite declaration as a renaming, which the
4871 -- back-end can handle properly. This is a rather unusual case,
4872 -- because most unchecked_union declarations have default values
4873 -- for discriminants and are thus not indefinite.
4875 elsif Is_Unchecked_Union
(T
) then
4876 if Constant_Present
(N
) or else Nkind
(E
) = N_Function_Call
then
4877 Mutate_Ekind
(Id
, E_Constant
);
4879 Mutate_Ekind
(Id
, E_Variable
);
4882 -- If the expression is an aggregate it contains the required
4883 -- discriminant values but it has not been resolved yet, so do
4884 -- it now, and treat it as the initial expression of an object
4885 -- declaration, rather than a renaming.
4887 if Nkind
(E
) = N_Aggregate
then
4888 Analyze_And_Resolve
(E
, T
);
4892 Make_Object_Renaming_Declaration
(Loc
,
4893 Defining_Identifier
=> Id
,
4894 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
4897 Set_Renamed_Object
(Id
, E
);
4898 Freeze_Before
(N
, T
);
4904 -- Ensure that the generated subtype has a unique external name
4905 -- when the related object is public. This guarantees that the
4906 -- subtype and its bounds will not be affected by switches or
4907 -- pragmas that may offset the internal counter due to extra
4910 if Is_Public
(Id
) then
4913 Related_Id
:= Empty
;
4916 -- If the object has an unconstrained array subtype with fixed
4917 -- lower bound, then sliding to that bound may be needed.
4919 if Is_Fixed_Lower_Bound_Array_Subtype
(T
) then
4920 Expand_Sliding_Conversion
(E
, T
);
4923 if In_Spec_Expression
and then In_Declare_Expr
> 0 then
4924 -- It is too early to be doing expansion-ish things,
4925 -- so exit early. But we have to set Ekind (Id) now so
4926 -- that subsequent uses of this entity are not rejected
4927 -- via the same mechanism that (correctly) rejects
4928 -- "X : Integer := X;".
4930 if Constant_Present
(N
) then
4931 Mutate_Ekind
(Id
, E_Constant
);
4932 Set_Is_True_Constant
(Id
);
4934 Mutate_Ekind
(Id
, E_Variable
);
4936 Set_Has_Initial_Value
(Id
);
4943 Expand_Subtype_From_Expr
4946 Subtype_Indic
=> Object_Definition
(N
),
4948 Related_Id
=> Related_Id
);
4950 Act_T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4955 Full_Act_T
: constant Entity_Id
:=
4956 (if Is_Private_Type
(Act_T
)
4957 then Full_View
(Act_T
)
4959 -- Propagate attributes to full view when needed
4962 Set_Is_Constr_Subt_For_U_Nominal
(Act_T
);
4964 if Present
(Full_Act_T
) then
4965 Set_Is_Constr_Subt_For_U_Nominal
(Full_Act_T
);
4968 -- If the object is aliased, then it may be pointed to by an
4969 -- access-to-unconstrained-array value, which means that it
4970 -- must be allocated with its bounds.
4972 if Aliased_Present
(N
)
4973 and then (Is_Array_Type
(Act_T
)
4974 or else (Present
(Full_Act_T
)
4975 and then Is_Array_Type
(Full_Act_T
)))
4977 Set_Is_Constr_Array_Subt_With_Bounds
(Act_T
);
4979 if Present
(Full_Act_T
) then
4980 Set_Is_Constr_Array_Subt_With_Bounds
(Full_Act_T
);
4984 Freeze_Before
(N
, Act_T
);
4988 Freeze_Before
(N
, T
);
4991 elsif Is_Array_Type
(T
)
4992 and then No_Initialization
(N
)
4993 and then (Nkind
(Original_Node
(E
)) = N_Aggregate
4994 or else (Nkind
(Original_Node
(E
)) = N_Qualified_Expression
4995 and then Nkind
(Original_Node
(Expression
4996 (Original_Node
(E
)))) = N_Aggregate
))
4998 if not Is_Entity_Name
(Object_Definition
(N
)) then
5000 Check_Compile_Time_Size
(Act_T
);
5003 -- When the given object definition and the aggregate are specified
5004 -- independently, and their lengths might differ do a length check.
5005 -- This cannot happen if the aggregate is of the form (others =>...)
5007 if Nkind
(E
) = N_Raise_Constraint_Error
then
5009 -- Aggregate is statically illegal. Place back in declaration
5011 Set_Expression
(N
, E
);
5012 Set_No_Initialization
(N
, False);
5014 elsif T
= Etype
(E
) then
5017 elsif Nkind
(E
) = N_Aggregate
5018 and then Present
(Component_Associations
(E
))
5019 and then Present
(Choice_List
(First
(Component_Associations
(E
))))
5021 Nkind
(First
(Choice_List
(First
(Component_Associations
(E
))))) =
5027 Apply_Length_Check
(E
, T
);
5030 -- When possible, and not a deferred constant, build the default subtype
5032 elsif Build_Default_Subtype_OK
(T
)
5033 and then (not Constant_Present
(N
) or else Present
(E
))
5036 Act_T
:= Build_Default_Subtype
(T
, N
);
5038 -- Ada 2005: A limited object may be initialized by means of an
5039 -- aggregate. If the type has default discriminants it has an
5040 -- unconstrained nominal type, Its actual subtype will be obtained
5041 -- from the aggregate, and not from the default discriminants.
5046 Rewrite
(Object_Definition
(N
), New_Occurrence_Of
(Act_T
, Loc
));
5047 Freeze_Before
(N
, Act_T
);
5049 elsif Nkind
(E
) = N_Function_Call
5050 and then Constant_Present
(N
)
5051 and then Has_Unconstrained_Elements
(Etype
(E
))
5053 -- The back-end has problems with constants of a discriminated type
5054 -- with defaults, if the initial value is a function call. We
5055 -- generate an intermediate temporary that will receive a reference
5056 -- to the result of the call. The initialization expression then
5057 -- becomes a dereference of that temporary.
5059 Remove_Side_Effects
(E
);
5061 -- If this is a constant declaration of an unconstrained type and
5062 -- the initialization is an aggregate, we can use the subtype of the
5063 -- aggregate for the declared entity because it is immutable.
5065 elsif not Is_Constrained
(T
)
5066 and then Has_Discriminants
(T
)
5067 and then Constant_Present
(N
)
5068 and then not Has_Unchecked_Union
(T
)
5069 and then Nkind
(E
) = N_Aggregate
5074 -- Check No_Wide_Characters restriction
5076 Check_Wide_Character_Restriction
(T
, Object_Definition
(N
));
5078 -- Indicate this is not set in source. Certainly true for constants, and
5079 -- true for variables so far (will be reset for a variable if and when
5080 -- we encounter a modification in the source).
5082 Set_Never_Set_In_Source
(Id
);
5084 -- Now establish the proper kind and type of the object
5086 if Ekind
(Id
) = E_Void
then
5087 Reinit_Field_To_Zero
(Id
, F_Next_Inlined_Subprogram
);
5090 if Constant_Present
(N
) then
5091 Mutate_Ekind
(Id
, E_Constant
);
5092 Set_Is_True_Constant
(Id
);
5095 Mutate_Ekind
(Id
, E_Variable
);
5097 -- A variable is set as shared passive if it appears in a shared
5098 -- passive package, and is at the outer level. This is not done for
5099 -- entities generated during expansion, because those are always
5100 -- manipulated locally.
5102 if Is_Shared_Passive
(Current_Scope
)
5103 and then Is_Library_Level_Entity
(Id
)
5104 and then Comes_From_Source
(Id
)
5106 Set_Is_Shared_Passive
(Id
);
5107 Check_Shared_Var
(Id
, T
, N
);
5110 -- Set Has_Initial_Value if initializing expression present. Note
5111 -- that if there is no initializing expression, we leave the state
5112 -- of this flag unchanged (usually it will be False, but notably in
5113 -- the case of exception choice variables, it will already be true).
5116 Set_Has_Initial_Value
(Id
);
5120 -- Set the SPARK mode from the current context (may be overwritten later
5121 -- with explicit pragma).
5123 Set_SPARK_Pragma
(Id
, SPARK_Mode_Pragma
);
5124 Set_SPARK_Pragma_Inherited
(Id
);
5126 -- Preserve relevant elaboration-related attributes of the context which
5127 -- are no longer available or very expensive to recompute once analysis,
5128 -- resolution, and expansion are over.
5130 Mark_Elaboration_Attributes
5135 -- Initialize alignment and size and capture alignment setting
5137 Reinit_Alignment
(Id
);
5139 Set_Optimize_Alignment_Flags
(Id
);
5141 -- Deal with aliased case
5143 if Aliased_Present
(N
) then
5144 Set_Is_Aliased
(Id
);
5146 -- AI12-001: All aliased objects are considered to be specified as
5147 -- independently addressable (RM C.6(8.1/4)).
5149 Set_Is_Independent
(Id
);
5151 -- If the object is aliased and the type is unconstrained with
5152 -- defaulted discriminants and there is no expression, then the
5153 -- object is constrained by the defaults, so it is worthwhile
5154 -- building the corresponding subtype.
5156 -- Ada 2005 (AI-363): If the aliased object is discriminated and
5157 -- unconstrained, then only establish an actual subtype if the
5158 -- nominal subtype is indefinite. In definite cases the object is
5159 -- unconstrained in Ada 2005.
5162 and then Is_Record_Type
(T
)
5163 and then not Is_Constrained
(T
)
5164 and then Has_Discriminants
(T
)
5165 and then (Ada_Version
< Ada_2005
5166 or else not Is_Definite_Subtype
(T
))
5168 Set_Actual_Subtype
(Id
, Build_Default_Subtype
(T
, N
));
5172 -- Now we can set the type of the object
5174 Set_Etype
(Id
, Act_T
);
5176 -- Non-constant object is marked to be treated as volatile if type is
5177 -- volatile and we clear the Current_Value setting that may have been
5178 -- set above. Doing so for constants isn't required and might interfere
5179 -- with possible uses of the object as a static expression in contexts
5180 -- incompatible with volatility (e.g. as a case-statement alternative).
5182 if Ekind
(Id
) /= E_Constant
and then Treat_As_Volatile
(Etype
(Id
)) then
5183 Set_Treat_As_Volatile
(Id
);
5184 Set_Current_Value
(Id
, Empty
);
5187 -- Deal with controlled types
5189 if Has_Controlled_Component
(Etype
(Id
))
5190 or else Is_Controlled
(Etype
(Id
))
5192 if not Is_Library_Level_Entity
(Id
) then
5193 Check_Restriction
(No_Nested_Finalization
, N
);
5195 Validate_Controlled_Object
(Id
);
5198 -- If the type of a constrained array has an unconstrained first
5199 -- subtype, its Finalize_Address primitive expects the address of
5200 -- an object with a dope vector (see Make_Finalize_Address_Stmts).
5202 if Is_Array_Type
(Etype
(Id
))
5203 and then Is_Constrained
(Etype
(Id
))
5204 and then not Is_Constrained
(First_Subtype
(Etype
(Id
)))
5206 Set_Is_Constr_Array_Subt_With_Bounds
(Etype
(Id
));
5210 if Has_Task
(Etype
(Id
)) then
5211 Check_Restriction
(No_Tasking
, N
);
5213 -- Deal with counting max tasks
5215 -- Nothing to do if inside a generic
5217 if Inside_A_Generic
then
5220 -- If library level entity, then count tasks
5222 elsif Is_Library_Level_Entity
(Id
) then
5223 Check_Restriction
(Max_Tasks
, N
, Count_Tasks
(Etype
(Id
)));
5225 -- If not library level entity, then indicate we don't know max
5226 -- tasks and also check task hierarchy restriction and blocking
5227 -- operation (since starting a task is definitely blocking).
5230 Check_Restriction
(Max_Tasks
, N
);
5231 Check_Restriction
(No_Task_Hierarchy
, N
);
5232 Check_Potentially_Blocking_Operation
(N
);
5235 -- A rather specialized test. If we see two tasks being declared
5236 -- of the same type in the same object declaration, and the task
5237 -- has an entry with an address clause, we know that program error
5238 -- will be raised at run time since we can't have two tasks with
5239 -- entries at the same address.
5241 if Is_Task_Type
(Etype
(Id
)) and then More_Ids
(N
) then
5246 E
:= First_Entity
(Etype
(Id
));
5247 while Present
(E
) loop
5248 if Ekind
(E
) = E_Entry
5249 and then Present
(Get_Attribute_Definition_Clause
5250 (E
, Attribute_Address
))
5252 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5254 ("more than one task with same entry address<<", N
);
5255 Error_Msg_N
("\Program_Error [<<", N
);
5257 Make_Raise_Program_Error
(Loc
,
5258 Reason
=> PE_Duplicated_Entry_Address
));
5268 -- Check specific legality rules for a return object
5270 if Is_Return_Object
(Id
) then
5271 Check_Return_Subtype_Indication
(N
);
5274 -- Some simple constant-propagation: if the expression is a constant
5275 -- string initialized with a literal, share the literal. This avoids
5279 and then Is_Entity_Name
(E
)
5280 and then Ekind
(Entity
(E
)) = E_Constant
5281 and then Base_Type
(Etype
(E
)) = Standard_String
5284 Val
: constant Node_Id
:= Constant_Value
(Entity
(E
));
5286 if Present
(Val
) and then Nkind
(Val
) = N_String_Literal
then
5287 Rewrite
(E
, New_Copy
(Val
));
5292 if Present
(Prev_Entity
)
5293 and then Is_Frozen
(Prev_Entity
)
5294 and then not Error_Posted
(Id
)
5296 Error_Msg_N
("full constant declaration appears too late", N
);
5299 Check_Eliminated
(Id
);
5301 -- Deal with setting In_Private_Part flag if in private part
5303 if Ekind
(Scope
(Id
)) = E_Package
5304 and then In_Private_Part
(Scope
(Id
))
5306 Set_In_Private_Part
(Id
);
5310 -- Initialize the refined state of a variable here because this is a
5311 -- common destination for legal and illegal object declarations.
5313 if Ekind
(Id
) = E_Variable
then
5314 Set_Encapsulating_State
(Id
, Empty
);
5317 Analyze_Aspect_Specifications
(N
, Id
);
5319 Analyze_Dimension
(N
);
5321 -- Verify whether the object declaration introduces an illegal hidden
5322 -- state within a package subject to a null abstract state.
5324 if Ekind
(Id
) = E_Variable
then
5325 Check_No_Hidden_State
(Id
);
5328 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
5329 end Analyze_Object_Declaration
;
5331 ---------------------------
5332 -- Analyze_Others_Choice --
5333 ---------------------------
5335 -- Nothing to do for the others choice node itself, the semantic analysis
5336 -- of the others choice will occur as part of the processing of the parent
5338 procedure Analyze_Others_Choice
(N
: Node_Id
) is
5339 pragma Warnings
(Off
, N
);
5342 end Analyze_Others_Choice
;
5344 -------------------------------------------
5345 -- Analyze_Private_Extension_Declaration --
5346 -------------------------------------------
5348 procedure Analyze_Private_Extension_Declaration
(N
: Node_Id
) is
5349 Indic
: constant Node_Id
:= Subtype_Indication
(N
);
5350 T
: constant Entity_Id
:= Defining_Identifier
(N
);
5352 Iface_Elmt
: Elmt_Id
;
5353 Parent_Base
: Entity_Id
;
5354 Parent_Type
: Entity_Id
;
5357 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
5359 if Is_Non_Empty_List
(Interface_List
(N
)) then
5365 Intf
:= First
(Interface_List
(N
));
5366 while Present
(Intf
) loop
5367 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
5369 Diagnose_Interface
(Intf
, T
);
5375 Generate_Definition
(T
);
5377 -- For other than Ada 2012, just enter the name in the current scope
5379 if Ada_Version
< Ada_2012
then
5382 -- Ada 2012 (AI05-0162): Enter the name in the current scope handling
5383 -- case of private type that completes an incomplete type.
5390 Prev
:= Find_Type_Name
(N
);
5392 pragma Assert
(Prev
= T
5393 or else (Ekind
(Prev
) = E_Incomplete_Type
5394 and then Present
(Full_View
(Prev
))
5395 and then Full_View
(Prev
) = T
));
5399 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
5400 Parent_Base
:= Base_Type
(Parent_Type
);
5402 if Parent_Type
= Any_Type
or else Etype
(Parent_Type
) = Any_Type
then
5403 Mutate_Ekind
(T
, Ekind
(Parent_Type
));
5404 Set_Etype
(T
, Any_Type
);
5407 elsif not Is_Tagged_Type
(Parent_Type
) then
5409 ("parent of type extension must be a tagged type", Indic
);
5412 elsif Ekind
(Parent_Type
) in E_Void | E_Incomplete_Type
then
5413 Error_Msg_N
("premature derivation of incomplete type", Indic
);
5416 elsif Is_Concurrent_Type
(Parent_Type
) then
5418 ("parent type of a private extension cannot be a synchronized "
5419 & "tagged type (RM 3.9.1 (3/1))", N
);
5421 Set_Etype
(T
, Any_Type
);
5422 Mutate_Ekind
(T
, E_Limited_Private_Type
);
5423 Set_Private_Dependents
(T
, New_Elmt_List
);
5424 Set_Error_Posted
(T
);
5428 Check_Wide_Character_Restriction
(Parent_Type
, Indic
);
5430 -- Perhaps the parent type should be changed to the class-wide type's
5431 -- specific type in this case to prevent cascading errors ???
5433 if Is_Class_Wide_Type
(Parent_Type
) then
5435 ("parent of type extension must not be a class-wide type", Indic
);
5439 if (not Is_Package_Or_Generic_Package
(Current_Scope
)
5440 and then Nkind
(Parent
(N
)) /= N_Generic_Subprogram_Declaration
)
5441 or else In_Private_Part
(Current_Scope
)
5443 Error_Msg_N
("invalid context for private extension", N
);
5446 -- Set common attributes
5448 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
5449 Set_Scope
(T
, Current_Scope
);
5450 Mutate_Ekind
(T
, E_Record_Type_With_Private
);
5451 Reinit_Size_Align
(T
);
5452 Set_Default_SSO
(T
);
5453 Set_No_Reordering
(T
, No_Component_Reordering
);
5455 Set_Etype
(T
, Parent_Base
);
5456 Propagate_Concurrent_Flags
(T
, Parent_Base
);
5458 Set_Convention
(T
, Convention
(Parent_Type
));
5459 Set_First_Rep_Item
(T
, First_Rep_Item
(Parent_Type
));
5460 Set_Is_First_Subtype
(T
);
5462 -- Set the SPARK mode from the current context
5464 Set_SPARK_Pragma
(T
, SPARK_Mode_Pragma
);
5465 Set_SPARK_Pragma_Inherited
(T
);
5467 if Unknown_Discriminants_Present
(N
) then
5468 Set_Discriminant_Constraint
(T
, No_Elist
);
5471 Build_Derived_Record_Type
(N
, Parent_Type
, T
);
5473 -- A private extension inherits the Default_Initial_Condition pragma
5474 -- coming from any parent type within the derivation chain.
5476 if Has_DIC
(Parent_Type
) then
5477 Set_Has_Inherited_DIC
(T
);
5480 -- A private extension inherits any class-wide invariants coming from a
5481 -- parent type or an interface. Note that the invariant procedure of the
5482 -- parent type should not be inherited because the private extension may
5483 -- define invariants of its own.
5485 if Has_Inherited_Invariants
(Parent_Type
)
5486 or else Has_Inheritable_Invariants
(Parent_Type
)
5488 Set_Has_Inherited_Invariants
(T
);
5490 elsif Present
(Interfaces
(T
)) then
5491 Iface_Elmt
:= First_Elmt
(Interfaces
(T
));
5492 while Present
(Iface_Elmt
) loop
5493 Iface
:= Node
(Iface_Elmt
);
5495 if Has_Inheritable_Invariants
(Iface
) then
5496 Set_Has_Inherited_Invariants
(T
);
5500 Next_Elmt
(Iface_Elmt
);
5504 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
5505 -- synchronized formal derived type.
5507 if Ada_Version
>= Ada_2005
and then Synchronized_Present
(N
) then
5508 Set_Is_Limited_Record
(T
);
5510 -- Formal derived type case
5512 if Is_Generic_Type
(T
) then
5514 -- The parent must be a tagged limited type or a synchronized
5517 if (not Is_Tagged_Type
(Parent_Type
)
5518 or else not Is_Limited_Type
(Parent_Type
))
5520 (not Is_Interface
(Parent_Type
)
5521 or else not Is_Synchronized_Interface
(Parent_Type
))
5524 ("parent type of & must be tagged limited or synchronized",
5528 -- The progenitors (if any) must be limited or synchronized
5531 if Present
(Interfaces
(T
)) then
5532 Iface_Elmt
:= First_Elmt
(Interfaces
(T
));
5533 while Present
(Iface_Elmt
) loop
5534 Iface
:= Node
(Iface_Elmt
);
5536 if not Is_Limited_Interface
(Iface
)
5537 and then not Is_Synchronized_Interface
(Iface
)
5540 ("progenitor & must be limited or synchronized",
5544 Next_Elmt
(Iface_Elmt
);
5548 -- Regular derived extension, the parent must be a limited or
5549 -- synchronized interface.
5552 if not Is_Interface
(Parent_Type
)
5553 or else (not Is_Limited_Interface
(Parent_Type
)
5554 and then not Is_Synchronized_Interface
(Parent_Type
))
5557 ("parent type of & must be limited interface", N
, T
);
5561 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
5562 -- extension with a synchronized parent must be explicitly declared
5563 -- synchronized, because the full view will be a synchronized type.
5564 -- This must be checked before the check for limited types below,
5565 -- to ensure that types declared limited are not allowed to extend
5566 -- synchronized interfaces.
5568 elsif Is_Interface
(Parent_Type
)
5569 and then Is_Synchronized_Interface
(Parent_Type
)
5570 and then not Synchronized_Present
(N
)
5573 ("private extension of& must be explicitly synchronized",
5576 elsif Limited_Present
(N
) then
5577 Set_Is_Limited_Record
(T
);
5579 if not Is_Limited_Type
(Parent_Type
)
5581 (not Is_Interface
(Parent_Type
)
5582 or else not Is_Limited_Interface
(Parent_Type
))
5584 Error_Msg_NE
("parent type& of limited extension must be limited",
5589 -- Remember that its parent type has a private extension. Used to warn
5590 -- on public primitives of the parent type defined after its private
5591 -- extensions (see Check_Dispatching_Operation).
5593 Set_Has_Private_Extension
(Parent_Type
);
5596 Analyze_Aspect_Specifications
(N
, T
);
5597 end Analyze_Private_Extension_Declaration
;
5599 ---------------------------------
5600 -- Analyze_Subtype_Declaration --
5601 ---------------------------------
5603 procedure Analyze_Subtype_Declaration
5605 Skip
: Boolean := False)
5607 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
5611 Generate_Definition
(Id
);
5612 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
5613 Reinit_Size_Align
(Id
);
5615 -- The following guard condition on Enter_Name is to handle cases where
5616 -- the defining identifier has already been entered into the scope but
5617 -- the declaration as a whole needs to be analyzed.
5619 -- This case in particular happens for derived enumeration types. The
5620 -- derived enumeration type is processed as an inserted enumeration type
5621 -- declaration followed by a rewritten subtype declaration. The defining
5622 -- identifier, however, is entered into the name scope very early in the
5623 -- processing of the original type declaration and therefore needs to be
5624 -- avoided here, when the created subtype declaration is analyzed. (See
5625 -- Build_Derived_Types)
5627 -- This also happens when the full view of a private type is a derived
5628 -- type with constraints. In this case the entity has been introduced
5629 -- in the private declaration.
5631 -- Finally this happens in some complex cases when validity checks are
5632 -- enabled, where the same subtype declaration may be analyzed twice.
5633 -- This can happen if the subtype is created by the preanalysis of
5634 -- an attribute that gives the range of a loop statement, and the loop
5635 -- itself appears within an if_statement that will be rewritten during
5639 or else (Present
(Etype
(Id
))
5640 and then (Is_Private_Type
(Etype
(Id
))
5641 or else Is_Task_Type
(Etype
(Id
))
5642 or else Is_Rewrite_Substitution
(N
)))
5646 elsif Current_Entity
(Id
) = Id
then
5653 T
:= Process_Subtype
(Subtype_Indication
(N
), N
, Id
, 'P');
5655 -- Class-wide equivalent types of records with unknown discriminants
5656 -- involve the generation of an itype which serves as the private view
5657 -- of a constrained record subtype. In such cases the base type of the
5658 -- current subtype we are processing is the private itype. Use the full
5659 -- of the private itype when decorating various attributes.
5662 and then Is_Private_Type
(T
)
5663 and then Present
(Full_View
(T
))
5668 -- Inherit common attributes
5670 Set_Is_Volatile
(Id
, Is_Volatile
(T
));
5671 Set_Treat_As_Volatile
(Id
, Treat_As_Volatile
(T
));
5672 Set_Is_Generic_Type
(Id
, Is_Generic_Type
(Base_Type
(T
)));
5673 Set_Convention
(Id
, Convention
(T
));
5675 -- If ancestor has predicates then so does the subtype, and in addition
5676 -- we must delay the freeze to properly arrange predicate inheritance.
5678 -- The Ancestor_Type test is really unpleasant, there seem to be cases
5679 -- in which T = ID, so the above tests and assignments do nothing???
5681 if Has_Predicates
(T
)
5682 or else (Present
(Ancestor_Subtype
(T
))
5683 and then Has_Predicates
(Ancestor_Subtype
(T
)))
5685 Set_Has_Predicates
(Id
);
5686 Set_Has_Delayed_Freeze
(Id
);
5688 -- Generated subtypes inherit the predicate function from the parent
5689 -- (no aspects to examine on the generated declaration).
5691 if not Comes_From_Source
(N
) then
5692 Mutate_Ekind
(Id
, Ekind
(T
));
5694 if Present
(Predicate_Function
(Id
)) then
5697 elsif Present
(Predicate_Function
(T
)) then
5698 Set_Predicate_Function
(Id
, Predicate_Function
(T
));
5700 elsif Present
(Ancestor_Subtype
(T
))
5701 and then Present
(Predicate_Function
(Ancestor_Subtype
(T
)))
5703 Set_Predicate_Function
(Id
,
5704 Predicate_Function
(Ancestor_Subtype
(T
)));
5709 -- In the case where there is no constraint given in the subtype
5710 -- indication, Process_Subtype just returns the Subtype_Mark, so its
5711 -- semantic attributes must be established here.
5713 if Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
then
5714 Set_Etype
(Id
, Base_Type
(T
));
5718 Mutate_Ekind
(Id
, E_Array_Subtype
);
5719 Copy_Array_Subtype_Attributes
(Id
, T
);
5720 Set_Packed_Array_Impl_Type
(Id
, Packed_Array_Impl_Type
(T
));
5722 when Decimal_Fixed_Point_Kind
=>
5723 Mutate_Ekind
(Id
, E_Decimal_Fixed_Point_Subtype
);
5724 Set_Digits_Value
(Id
, Digits_Value
(T
));
5725 Set_Delta_Value
(Id
, Delta_Value
(T
));
5726 Set_Scale_Value
(Id
, Scale_Value
(T
));
5727 Set_Small_Value
(Id
, Small_Value
(T
));
5728 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5729 Set_Machine_Radix_10
(Id
, Machine_Radix_10
(T
));
5730 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5731 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5732 Copy_RM_Size
(To
=> Id
, From
=> T
);
5734 when Enumeration_Kind
=>
5735 Mutate_Ekind
(Id
, E_Enumeration_Subtype
);
5736 Set_First_Literal
(Id
, First_Literal
(Base_Type
(T
)));
5737 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5738 Set_Is_Character_Type
(Id
, Is_Character_Type
(T
));
5739 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5740 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5741 Copy_RM_Size
(To
=> Id
, From
=> T
);
5743 when Ordinary_Fixed_Point_Kind
=>
5744 Mutate_Ekind
(Id
, E_Ordinary_Fixed_Point_Subtype
);
5745 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5746 Set_Small_Value
(Id
, Small_Value
(T
));
5747 Set_Delta_Value
(Id
, Delta_Value
(T
));
5748 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5749 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5750 Copy_RM_Size
(To
=> Id
, From
=> T
);
5753 Mutate_Ekind
(Id
, E_Floating_Point_Subtype
);
5754 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5755 Set_Digits_Value
(Id
, Digits_Value
(T
));
5756 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5758 -- If the floating point type has dimensions, these will be
5759 -- inherited subsequently when Analyze_Dimensions is called.
5761 when Signed_Integer_Kind
=>
5762 Mutate_Ekind
(Id
, E_Signed_Integer_Subtype
);
5763 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5764 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5765 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5766 Copy_RM_Size
(To
=> Id
, From
=> T
);
5768 when Modular_Integer_Kind
=>
5769 Mutate_Ekind
(Id
, E_Modular_Integer_Subtype
);
5770 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
5771 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5772 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
5773 Copy_RM_Size
(To
=> Id
, From
=> T
);
5775 when Class_Wide_Kind
=>
5776 Mutate_Ekind
(Id
, E_Class_Wide_Subtype
);
5777 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5778 Set_Cloned_Subtype
(Id
, T
);
5779 Set_Is_Tagged_Type
(Id
, True);
5780 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5781 Set_Has_Unknown_Discriminants
5783 Set_No_Tagged_Streams_Pragma
5784 (Id
, No_Tagged_Streams_Pragma
(T
));
5786 if Ekind
(T
) = E_Class_Wide_Subtype
then
5787 Set_Equivalent_Type
(Id
, Equivalent_Type
(T
));
5790 when E_Record_Subtype
5793 Mutate_Ekind
(Id
, E_Record_Subtype
);
5795 -- Subtype declarations introduced for formal type parameters
5796 -- in generic instantiations should inherit the Size value of
5797 -- the type they rename.
5799 if Present
(Generic_Parent_Type
(N
)) then
5800 Copy_RM_Size
(To
=> Id
, From
=> T
);
5803 if Ekind
(T
) = E_Record_Subtype
5804 and then Present
(Cloned_Subtype
(T
))
5806 Set_Cloned_Subtype
(Id
, Cloned_Subtype
(T
));
5808 Set_Cloned_Subtype
(Id
, T
);
5811 Set_First_Entity
(Id
, First_Entity
(T
));
5812 Set_Last_Entity
(Id
, Last_Entity
(T
));
5813 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5814 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5815 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5816 Set_Has_Implicit_Dereference
5817 (Id
, Has_Implicit_Dereference
(T
));
5818 Set_Has_Unknown_Discriminants
5819 (Id
, Has_Unknown_Discriminants
(T
));
5821 if Has_Discriminants
(T
) then
5822 Set_Discriminant_Constraint
5823 (Id
, Discriminant_Constraint
(T
));
5824 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5826 elsif Has_Unknown_Discriminants
(Id
) then
5827 Set_Discriminant_Constraint
(Id
, No_Elist
);
5830 if Is_Tagged_Type
(T
) then
5831 Set_Is_Tagged_Type
(Id
, True);
5832 Set_No_Tagged_Streams_Pragma
5833 (Id
, No_Tagged_Streams_Pragma
(T
));
5834 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
5835 Set_Direct_Primitive_Operations
5836 (Id
, Direct_Primitive_Operations
(T
));
5837 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5839 if Is_Interface
(T
) then
5840 Set_Is_Interface
(Id
);
5841 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
5845 when Private_Kind
=>
5846 Mutate_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
5847 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5848 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5849 Set_First_Entity
(Id
, First_Entity
(T
));
5850 Set_Last_Entity
(Id
, Last_Entity
(T
));
5851 Set_Private_Dependents
(Id
, New_Elmt_List
);
5852 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
5853 Set_Has_Implicit_Dereference
5854 (Id
, Has_Implicit_Dereference
(T
));
5855 Set_Has_Unknown_Discriminants
5856 (Id
, Has_Unknown_Discriminants
(T
));
5857 Set_Known_To_Have_Preelab_Init
5858 (Id
, Known_To_Have_Preelab_Init
(T
));
5860 if Is_Tagged_Type
(T
) then
5861 Set_Is_Tagged_Type
(Id
);
5862 Set_No_Tagged_Streams_Pragma
(Id
,
5863 No_Tagged_Streams_Pragma
(T
));
5864 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
5865 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5866 Set_Direct_Primitive_Operations
(Id
,
5867 Direct_Primitive_Operations
(T
));
5870 -- In general the attributes of the subtype of a private type
5871 -- are the attributes of the partial view of parent. However,
5872 -- the full view may be a discriminated type, and the subtype
5873 -- must share the discriminant constraint to generate correct
5874 -- calls to initialization procedures.
5876 if Has_Discriminants
(T
) then
5877 Set_Discriminant_Constraint
5878 (Id
, Discriminant_Constraint
(T
));
5879 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5881 elsif Present
(Full_View
(T
))
5882 and then Has_Discriminants
(Full_View
(T
))
5884 Set_Discriminant_Constraint
5885 (Id
, Discriminant_Constraint
(Full_View
(T
)));
5886 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5888 -- This would seem semantically correct, but apparently
5889 -- generates spurious errors about missing components ???
5891 -- Set_Has_Discriminants (Id);
5894 Prepare_Private_Subtype_Completion
(Id
, N
);
5896 -- If this is the subtype of a constrained private type with
5897 -- discriminants that has got a full view and we also have
5898 -- built a completion just above, show that the completion
5899 -- is a clone of the full view to the back-end.
5901 if Has_Discriminants
(T
)
5902 and then not Has_Unknown_Discriminants
(T
)
5903 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(T
))
5904 and then Present
(Full_View
(T
))
5905 and then Present
(Full_View
(Id
))
5907 Set_Cloned_Subtype
(Full_View
(Id
), Full_View
(T
));
5911 Mutate_Ekind
(Id
, E_Access_Subtype
);
5912 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5913 Set_Is_Access_Constant
5914 (Id
, Is_Access_Constant
(T
));
5915 Set_Directly_Designated_Type
5916 (Id
, Designated_Type
(T
));
5917 Set_Can_Never_Be_Null
(Id
, Can_Never_Be_Null
(T
));
5919 -- A Pure library_item must not contain the declaration of a
5920 -- named access type, except within a subprogram, generic
5921 -- subprogram, task unit, or protected unit, or if it has
5922 -- a specified Storage_Size of zero (RM05-10.2.1(15.4-15.5)).
5924 if Comes_From_Source
(Id
)
5925 and then In_Pure_Unit
5926 and then not In_Subprogram_Task_Protected_Unit
5927 and then not No_Pool_Assigned
(Id
)
5930 ("named access types not allowed in pure unit", N
);
5933 when Concurrent_Kind
=>
5934 Mutate_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
5935 Set_Corresponding_Record_Type
(Id
,
5936 Corresponding_Record_Type
(T
));
5937 Set_First_Entity
(Id
, First_Entity
(T
));
5938 Set_First_Private_Entity
(Id
, First_Private_Entity
(T
));
5939 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5940 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5941 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5942 Set_Last_Entity
(Id
, Last_Entity
(T
));
5944 if Is_Tagged_Type
(T
) then
5945 Set_No_Tagged_Streams_Pragma
5946 (Id
, No_Tagged_Streams_Pragma
(T
));
5949 if Has_Discriminants
(T
) then
5950 Set_Discriminant_Constraint
5951 (Id
, Discriminant_Constraint
(T
));
5952 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5955 when Incomplete_Kind
=>
5956 if Ada_Version
>= Ada_2005
then
5958 -- In Ada 2005 an incomplete type can be explicitly tagged:
5959 -- propagate indication. Note that we also have to include
5960 -- subtypes for Ada 2012 extended use of incomplete types.
5962 Mutate_Ekind
(Id
, E_Incomplete_Subtype
);
5963 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5964 Set_Private_Dependents
(Id
, New_Elmt_List
);
5966 if Is_Tagged_Type
(Id
) then
5967 Set_No_Tagged_Streams_Pragma
5968 (Id
, No_Tagged_Streams_Pragma
(T
));
5971 -- For tagged types, or when prefixed-call syntax is allowed
5972 -- for untagged types, initialize the list of primitive
5973 -- operations to an empty list.
5975 if Is_Tagged_Type
(Id
)
5976 or else Core_Extensions_Allowed
5978 Set_Direct_Primitive_Operations
(Id
, New_Elmt_List
);
5981 -- Ada 2005 (AI-412): Decorate an incomplete subtype of an
5982 -- incomplete type visible through a limited with clause.
5984 if From_Limited_With
(T
)
5985 and then Present
(Non_Limited_View
(T
))
5987 Set_From_Limited_With
(Id
);
5988 Set_Non_Limited_View
(Id
, Non_Limited_View
(T
));
5990 -- Ada 2005 (AI-412): Add the regular incomplete subtype
5991 -- to the private dependents of the original incomplete
5992 -- type for future transformation.
5995 Append_Elmt
(Id
, Private_Dependents
(T
));
5998 -- If the subtype name denotes an incomplete type an error
5999 -- was already reported by Process_Subtype.
6002 Set_Etype
(Id
, Any_Type
);
6006 raise Program_Error
;
6009 -- If there is no constraint in the subtype indication, the
6010 -- declared entity inherits predicates from the parent.
6012 Inherit_Predicate_Flags
(Id
, T
);
6015 if Etype
(Id
) = Any_Type
then
6019 -- When prefixed calls are enabled for untagged types, the subtype
6020 -- shares the primitive operations of its base type. Do this even
6021 -- when Extensions_Allowed is False to issue better error messages.
6023 Set_Direct_Primitive_Operations
6024 (Id
, Direct_Primitive_Operations
(Base_Type
(T
)));
6026 -- Some common processing on all types
6028 Set_Size_Info
(Id
, T
);
6029 Set_First_Rep_Item
(Id
, First_Rep_Item
(T
));
6031 -- If the parent type is a generic actual, so is the subtype. This may
6032 -- happen in a nested instance. Why Comes_From_Source test???
6034 if not Comes_From_Source
(N
) then
6035 Set_Is_Generic_Actual_Type
(Id
, Is_Generic_Actual_Type
(T
));
6038 -- If this is a subtype declaration for an actual in an instance,
6039 -- inherit static and dynamic predicates if any.
6041 if Has_Predicates
(T
)
6042 and then Present
(Predicate_Function
(T
))
6043 and then In_Instance
6044 and then not Comes_From_Source
(N
)
6046 -- Inherit Subprograms_For_Type from the full view, if present
6048 if Present
(Full_View
(T
))
6049 and then Present
(Subprograms_For_Type
(Full_View
(T
)))
6051 Set_Subprograms_For_Type
6052 (Id
, Subprograms_For_Type
(Full_View
(T
)));
6054 Set_Subprograms_For_Type
(Id
, Subprograms_For_Type
(T
));
6057 -- If the current declaration created both a private and a full view,
6058 -- then propagate Predicate_Function to the latter as well.
6060 if Present
(Full_View
(Id
))
6061 and then No
(Predicate_Function
(Full_View
(Id
)))
6063 Set_Subprograms_For_Type
6064 (Full_View
(Id
), Subprograms_For_Type
(Id
));
6067 if Has_Static_Predicate
(T
) then
6068 Set_Has_Static_Predicate
(Id
);
6069 Set_Static_Discrete_Predicate
(Id
, Static_Discrete_Predicate
(T
));
6073 -- If the base type is a scalar type, or else if there is no
6074 -- constraint, the atomic flag is inherited by the subtype.
6075 -- Ditto for the Independent aspect.
6077 if Is_Scalar_Type
(Id
)
6078 or else Is_Entity_Name
(Subtype_Indication
(N
))
6080 Set_Is_Atomic
(Id
, Is_Atomic
(T
));
6081 Set_Is_Independent
(Id
, Is_Independent
(T
));
6084 -- Remaining processing depends on characteristics of base type
6088 Set_Is_Immediately_Visible
(Id
, True);
6089 Set_Depends_On_Private
(Id
, Has_Private_Component
(T
));
6090 Set_Is_Descendant_Of_Address
(Id
, Is_Descendant_Of_Address
(T
));
6092 if Is_Interface
(T
) then
6093 Set_Is_Interface
(Id
);
6094 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
6097 if Present
(Generic_Parent_Type
(N
))
6099 (Nkind
(Parent
(Generic_Parent_Type
(N
))) /=
6100 N_Formal_Type_Declaration
6101 or else Nkind
(Formal_Type_Definition
6102 (Parent
(Generic_Parent_Type
(N
)))) /=
6103 N_Formal_Private_Type_Definition
)
6105 if Is_Tagged_Type
(Id
) then
6107 -- If this is a generic actual subtype for a synchronized type,
6108 -- the primitive operations are those of the corresponding record
6109 -- for which there is a separate subtype declaration.
6111 if Is_Concurrent_Type
(Id
) then
6113 elsif Is_Class_Wide_Type
(Id
) then
6114 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, Etype
(T
));
6116 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, T
);
6119 elsif Scope
(Etype
(Id
)) /= Standard_Standard
then
6120 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
);
6124 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
6125 Conditional_Delay
(Id
, Full_View
(T
));
6127 -- The subtypes of components or subcomponents of protected types
6128 -- do not need freeze nodes, which would otherwise appear in the
6129 -- wrong scope (before the freeze node for the protected type). The
6130 -- proper subtypes are those of the subcomponents of the corresponding
6133 elsif Ekind
(Scope
(Id
)) /= E_Protected_Type
6134 and then Present
(Scope
(Scope
(Id
))) -- error defense
6135 and then Ekind
(Scope
(Scope
(Id
))) /= E_Protected_Type
6137 Conditional_Delay
(Id
, T
);
6140 -- If we have a subtype of an incomplete type whose full type is a
6141 -- derived numeric type, we need to have a freeze node for the subtype.
6142 -- Otherwise gigi will complain while computing the (static) bounds of
6146 and then Is_Elementary_Type
(Id
)
6147 and then Etype
(Id
) /= Id
6150 Partial
: constant Entity_Id
:=
6151 Incomplete_Or_Partial_View
(First_Subtype
(Id
));
6153 if Present
(Partial
)
6154 and then Ekind
(Partial
) = E_Incomplete_Type
6156 Set_Has_Delayed_Freeze
(Id
);
6161 -- Check that Constraint_Error is raised for a scalar subtype indication
6162 -- when the lower or upper bound of a non-null range lies outside the
6163 -- range of the type mark. Likewise for an array subtype, but check the
6164 -- compatibility for each index.
6166 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
6168 Indic_Typ
: constant Entity_Id
:=
6169 Underlying_Type
(Etype
(Subtype_Mark
(Subtype_Indication
(N
))));
6170 Subt_Index
: Node_Id
;
6171 Target_Index
: Node_Id
;
6174 if Is_Scalar_Type
(Etype
(Id
))
6175 and then Scalar_Range
(Id
) /= Scalar_Range
(Indic_Typ
)
6177 Apply_Range_Check
(Scalar_Range
(Id
), Indic_Typ
);
6179 elsif Is_Array_Type
(Etype
(Id
))
6180 and then Present
(First_Index
(Id
))
6182 Subt_Index
:= First_Index
(Id
);
6183 Target_Index
:= First_Index
(Indic_Typ
);
6185 while Present
(Subt_Index
) loop
6186 if ((Nkind
(Subt_Index
) in N_Expanded_Name | N_Identifier
6187 and then Is_Scalar_Type
(Entity
(Subt_Index
)))
6188 or else Nkind
(Subt_Index
) = N_Subtype_Indication
)
6190 Nkind
(Scalar_Range
(Etype
(Subt_Index
))) = N_Range
6193 (Scalar_Range
(Etype
(Subt_Index
)),
6194 Etype
(Target_Index
),
6198 Next_Index
(Subt_Index
);
6199 Next_Index
(Target_Index
);
6205 Set_Optimize_Alignment_Flags
(Id
);
6206 Check_Eliminated
(Id
);
6209 Analyze_Aspect_Specifications
(N
, Id
);
6211 Analyze_Dimension
(N
);
6213 -- Check No_Dynamic_Sized_Objects restriction, which disallows subtype
6214 -- indications on composite types where the constraints are dynamic.
6215 -- Note that object declarations and aggregates generate implicit
6216 -- subtype declarations, which this covers. One special case is that the
6217 -- implicitly generated "=" for discriminated types includes an
6218 -- offending subtype declaration, which is harmless, so we ignore it
6221 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
6223 Cstr
: constant Node_Id
:= Constraint
(Subtype_Indication
(N
));
6225 if Nkind
(Cstr
) = N_Index_Or_Discriminant_Constraint
6226 and then not (Is_Internal
(Id
)
6227 and then Is_TSS
(Scope
(Id
),
6228 TSS_Composite_Equality
))
6229 and then not Within_Init_Proc
6230 and then not All_Composite_Constraints_Static
(Cstr
)
6232 Check_Restriction
(No_Dynamic_Sized_Objects
, Cstr
);
6236 end Analyze_Subtype_Declaration
;
6238 --------------------------------
6239 -- Analyze_Subtype_Indication --
6240 --------------------------------
6242 procedure Analyze_Subtype_Indication
(N
: Node_Id
) is
6243 T
: constant Entity_Id
:= Subtype_Mark
(N
);
6244 R
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
6250 Set_Error_Posted
(R
);
6251 Set_Error_Posted
(T
);
6254 Set_Etype
(N
, Etype
(R
));
6255 Resolve
(R
, Entity
(T
));
6257 end Analyze_Subtype_Indication
;
6259 --------------------------
6260 -- Analyze_Variant_Part --
6261 --------------------------
6263 procedure Analyze_Variant_Part
(N
: Node_Id
) is
6264 Discr_Name
: Node_Id
;
6265 Discr_Type
: Entity_Id
;
6267 procedure Process_Variant
(A
: Node_Id
);
6268 -- Analyze declarations for a single variant
6270 package Analyze_Variant_Choices
is
6271 new Generic_Analyze_Choices
(Process_Variant
);
6272 use Analyze_Variant_Choices
;
6274 ---------------------
6275 -- Process_Variant --
6276 ---------------------
6278 procedure Process_Variant
(A
: Node_Id
) is
6279 CL
: constant Node_Id
:= Component_List
(A
);
6281 if not Null_Present
(CL
) then
6282 Analyze_Declarations
(Component_Items
(CL
));
6284 if Present
(Variant_Part
(CL
)) then
6285 Analyze
(Variant_Part
(CL
));
6288 end Process_Variant
;
6290 -- Start of processing for Analyze_Variant_Part
6293 Discr_Name
:= Name
(N
);
6294 Analyze
(Discr_Name
);
6296 -- If Discr_Name bad, get out (prevent cascaded errors)
6298 if Etype
(Discr_Name
) = Any_Type
then
6302 -- Check invalid discriminant in variant part
6304 if Ekind
(Entity
(Discr_Name
)) /= E_Discriminant
then
6305 Error_Msg_N
("invalid discriminant name in variant part", Discr_Name
);
6308 Discr_Type
:= Etype
(Entity
(Discr_Name
));
6310 if not Is_Discrete_Type
(Discr_Type
) then
6312 ("discriminant in a variant part must be of a discrete type",
6317 -- Now analyze the choices, which also analyzes the declarations that
6318 -- are associated with each choice.
6320 Analyze_Choices
(Variants
(N
), Discr_Type
);
6322 -- Note: we used to instantiate and call Check_Choices here to check
6323 -- that the choices covered the discriminant, but it's too early to do
6324 -- that because of statically predicated subtypes, whose analysis may
6325 -- be deferred to their freeze point which may be as late as the freeze
6326 -- point of the containing record. So this call is now to be found in
6327 -- Freeze_Record_Declaration.
6329 end Analyze_Variant_Part
;
6331 ----------------------------
6332 -- Array_Type_Declaration --
6333 ----------------------------
6335 procedure Array_Type_Declaration
(T
: in out Entity_Id
; Def
: Node_Id
) is
6336 Component_Def
: constant Node_Id
:= Component_Definition
(Def
);
6337 Component_Typ
: constant Node_Id
:= Subtype_Indication
(Component_Def
);
6338 P
: constant Node_Id
:= Parent
(Def
);
6339 Element_Type
: Entity_Id
;
6340 Implicit_Base
: Entity_Id
;
6344 Related_Id
: Entity_Id
;
6345 Has_FLB_Index
: Boolean := False;
6348 if Nkind
(Def
) = N_Constrained_Array_Definition
then
6349 Index
:= First
(Discrete_Subtype_Definitions
(Def
));
6351 Index
:= First
(Subtype_Marks
(Def
));
6354 -- Find proper names for the implicit types which may be public. In case
6355 -- of anonymous arrays we use the name of the first object of that type
6359 Related_Id
:= Defining_Identifier
(P
);
6365 while Present
(Index
) loop
6368 -- Test for odd case of trying to index a type by the type itself
6370 if Is_Entity_Name
(Index
) and then Entity
(Index
) = T
then
6371 Error_Msg_N
("type& cannot be indexed by itself", Index
);
6372 Set_Entity
(Index
, Standard_Boolean
);
6373 Set_Etype
(Index
, Standard_Boolean
);
6376 -- Add a subtype declaration for each index of private array type
6377 -- declaration whose type is also private. For example:
6380 -- type Index is private;
6382 -- type Table is array (Index) of ...
6385 -- This is currently required by the expander for the internally
6386 -- generated equality subprogram of records with variant parts in
6387 -- which the type of some component is such a private type. And it
6388 -- also helps semantic analysis in peculiar cases where the array
6389 -- type is referenced from an instance but not the index directly.
6391 if Is_Package_Or_Generic_Package
(Current_Scope
)
6392 and then In_Private_Part
(Current_Scope
)
6393 and then Has_Private_Declaration
(Etype
(Index
))
6394 and then Scope
(Etype
(Index
)) = Current_Scope
6397 Loc
: constant Source_Ptr
:= Sloc
(Def
);
6402 New_E
:= Make_Temporary
(Loc
, 'T');
6403 Set_Is_Internal
(New_E
);
6406 Make_Subtype_Declaration
(Loc
,
6407 Defining_Identifier
=> New_E
,
6408 Subtype_Indication
=>
6409 New_Occurrence_Of
(Etype
(Index
), Loc
));
6411 Insert_Before
(Parent
(Def
), Decl
);
6413 Set_Etype
(Index
, New_E
);
6415 -- If the index is a range or a subtype indication it carries
6416 -- no entity. Example:
6419 -- type T is private;
6421 -- type T is new Natural;
6422 -- Table : array (T(1) .. T(10)) of Boolean;
6425 -- Otherwise the type of the reference is its entity.
6427 if Is_Entity_Name
(Index
) then
6428 Set_Entity
(Index
, New_E
);
6433 Make_Index
(Index
, P
, Related_Id
, Nb_Index
);
6435 -- In the case where we have an unconstrained array with an index
6436 -- given by a subtype_indication, this is necessarily a "fixed lower
6437 -- bound" index. We change the upper bound of that index to the upper
6438 -- bound of the index's subtype (denoted by the subtype_mark), since
6439 -- that upper bound was originally set by the parser to be the same
6440 -- as the lower bound. In truth, that upper bound corresponds to
6441 -- a box ("<>"), and could be set to Empty, but it's convenient to
6442 -- set it to the upper bound to avoid needing to add special tests
6443 -- in various places for an Empty upper bound, and in any case that
6444 -- accurately characterizes the index's range of values.
6446 if Nkind
(Def
) = N_Unconstrained_Array_Definition
6447 and then Nkind
(Index
) = N_Subtype_Indication
6450 Index_Subtype_High_Bound
: constant Entity_Id
:=
6451 Type_High_Bound
(Entity
(Subtype_Mark
(Index
)));
6453 Set_High_Bound
(Range_Expression
(Constraint
(Index
)),
6454 Index_Subtype_High_Bound
);
6456 -- Record that the array type has one or more indexes with
6457 -- a fixed lower bound.
6459 Has_FLB_Index
:= True;
6461 -- Mark the index as belonging to an array type with a fixed
6464 Set_Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(Index
));
6468 -- Check error of subtype with predicate for index type
6470 Bad_Predicated_Subtype_Use
6471 ("subtype& has predicate, not allowed as index subtype",
6472 Index
, Etype
(Index
));
6474 -- Move to next index
6477 Nb_Index
:= Nb_Index
+ 1;
6480 -- Process subtype indication if one is present
6482 if Present
(Component_Typ
) then
6483 Element_Type
:= Process_Subtype
(Component_Typ
, P
, Related_Id
, 'C');
6484 Set_Etype
(Component_Typ
, Element_Type
);
6486 -- Ada 2005 (AI-230): Access Definition case
6488 else pragma Assert
(Present
(Access_Definition
(Component_Def
)));
6490 -- Indicate that the anonymous access type is created by the
6491 -- array type declaration.
6493 Element_Type
:= Access_Definition
6495 N
=> Access_Definition
(Component_Def
));
6496 Set_Is_Local_Anonymous_Access
(Element_Type
);
6498 -- Propagate the parent. This field is needed if we have to generate
6499 -- the master_id associated with an anonymous access to task type
6500 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
6502 Copy_Parent
(To
=> Element_Type
, From
=> T
);
6504 -- Ada 2005 (AI-230): In case of components that are anonymous access
6505 -- types the level of accessibility depends on the enclosing type
6508 Set_Scope
(Element_Type
, Current_Scope
); -- Ada 2005 (AI-230)
6510 -- Ada 2005 (AI-254)
6513 CD
: constant Node_Id
:=
6514 Access_To_Subprogram_Definition
6515 (Access_Definition
(Component_Def
));
6517 if Present
(CD
) and then Protected_Present
(CD
) then
6519 Replace_Anonymous_Access_To_Protected_Subprogram
(Def
);
6524 -- Constrained array case
6527 -- We might be creating more than one itype with the same Related_Id,
6528 -- e.g. for an array object definition and its initial value. Give
6529 -- them unique suffixes, because GNATprove require distinct types to
6530 -- have different names.
6532 T
:= Create_Itype
(E_Void
, P
, Related_Id
, 'T', Suffix_Index
=> -1);
6535 if Nkind
(Def
) = N_Constrained_Array_Definition
then
6536 -- Establish Implicit_Base as unconstrained base type
6538 Implicit_Base
:= Create_Itype
(E_Array_Type
, P
, Related_Id
, 'B');
6540 Set_Etype
(Implicit_Base
, Implicit_Base
);
6541 Set_Scope
(Implicit_Base
, Current_Scope
);
6542 Set_Has_Delayed_Freeze
(Implicit_Base
);
6543 Set_Default_SSO
(Implicit_Base
);
6545 -- The constrained array type is a subtype of the unconstrained one
6547 Mutate_Ekind
(T
, E_Array_Subtype
);
6548 Reinit_Size_Align
(T
);
6549 Set_Etype
(T
, Implicit_Base
);
6550 Set_Scope
(T
, Current_Scope
);
6551 Set_Is_Constrained
(T
);
6553 First
(Discrete_Subtype_Definitions
(Def
)));
6554 Set_Has_Delayed_Freeze
(T
);
6556 -- Complete setup of implicit base type
6558 pragma Assert
(not Known_Component_Size
(Implicit_Base
));
6559 Set_Component_Type
(Implicit_Base
, Element_Type
);
6560 Set_Finalize_Storage_Only
6562 Finalize_Storage_Only
(Element_Type
));
6563 Set_First_Index
(Implicit_Base
, First_Index
(T
));
6564 Set_Has_Controlled_Component
6566 Has_Controlled_Component
(Element_Type
)
6567 or else Is_Controlled
(Element_Type
));
6568 Set_Packed_Array_Impl_Type
6569 (Implicit_Base
, Empty
);
6571 Propagate_Concurrent_Flags
(Implicit_Base
, Element_Type
);
6573 -- Unconstrained array case
6575 else pragma Assert
(Nkind
(Def
) = N_Unconstrained_Array_Definition
);
6576 Mutate_Ekind
(T
, E_Array_Type
);
6577 Reinit_Size_Align
(T
);
6579 Set_Scope
(T
, Current_Scope
);
6580 pragma Assert
(not Known_Component_Size
(T
));
6581 Set_Is_Constrained
(T
, False);
6582 Set_Is_Fixed_Lower_Bound_Array_Subtype
6584 Set_First_Index
(T
, First
(Subtype_Marks
(Def
)));
6585 Set_Has_Delayed_Freeze
(T
, True);
6586 Propagate_Concurrent_Flags
(T
, Element_Type
);
6587 Set_Has_Controlled_Component
(T
, Has_Controlled_Component
6590 Is_Controlled
(Element_Type
));
6591 Set_Finalize_Storage_Only
(T
, Finalize_Storage_Only
6593 Set_Default_SSO
(T
);
6596 -- Common attributes for both cases
6598 Set_Component_Type
(Base_Type
(T
), Element_Type
);
6599 Set_Packed_Array_Impl_Type
(T
, Empty
);
6601 if Aliased_Present
(Component_Definition
(Def
)) then
6602 Set_Has_Aliased_Components
(Etype
(T
));
6604 -- AI12-001: All aliased objects are considered to be specified as
6605 -- independently addressable (RM C.6(8.1/4)).
6607 Set_Has_Independent_Components
(Etype
(T
));
6610 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
6611 -- array type to ensure that objects of this type are initialized.
6613 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(Element_Type
) then
6614 Set_Can_Never_Be_Null
(T
);
6616 if Null_Exclusion_Present
(Component_Definition
(Def
))
6618 -- No need to check itypes because in their case this check was
6619 -- done at their point of creation
6621 and then not Is_Itype
(Element_Type
)
6624 ("`NOT NULL` not allowed (null already excluded)",
6625 Subtype_Indication
(Component_Definition
(Def
)));
6629 Priv
:= Private_Component
(Element_Type
);
6631 if Present
(Priv
) then
6633 -- Check for circular definitions
6635 if Priv
= Any_Type
then
6636 Set_Component_Type
(Etype
(T
), Any_Type
);
6638 -- There is a gap in the visibility of operations on the composite
6639 -- type only if the component type is defined in a different scope.
6641 elsif Scope
(Priv
) = Current_Scope
then
6644 elsif Is_Limited_Type
(Priv
) then
6645 Set_Is_Limited_Composite
(Etype
(T
));
6646 Set_Is_Limited_Composite
(T
);
6648 Set_Is_Private_Composite
(Etype
(T
));
6649 Set_Is_Private_Composite
(T
);
6653 -- A syntax error in the declaration itself may lead to an empty index
6654 -- list, in which case do a minimal patch.
6656 if No
(First_Index
(T
)) then
6657 Error_Msg_N
("missing index definition in array type declaration", T
);
6660 Indexes
: constant List_Id
:=
6661 New_List
(New_Occurrence_Of
(Any_Id
, Sloc
(T
)));
6663 Set_Discrete_Subtype_Definitions
(Def
, Indexes
);
6664 Set_First_Index
(T
, First
(Indexes
));
6669 -- Create a concatenation operator for the new type. Internal array
6670 -- types created for packed entities do not need such, they are
6671 -- compatible with the user-defined type.
6673 if Number_Dimensions
(T
) = 1
6674 and then not Is_Packed_Array_Impl_Type
(T
)
6676 New_Concatenation_Op
(T
);
6679 -- In the case of an unconstrained array the parser has already verified
6680 -- that all the indexes are unconstrained but we still need to make sure
6681 -- that the element type is constrained.
6683 if not Is_Definite_Subtype
(Element_Type
) then
6685 ("unconstrained element type in array declaration",
6686 Subtype_Indication
(Component_Def
));
6688 elsif Is_Abstract_Type
(Element_Type
) then
6690 ("the type of a component cannot be abstract",
6691 Subtype_Indication
(Component_Def
));
6694 -- There may be an invariant declared for the component type, but
6695 -- the construction of the component invariant checking procedure
6696 -- takes place during expansion.
6697 end Array_Type_Declaration
;
6699 ------------------------------------------------------
6700 -- Replace_Anonymous_Access_To_Protected_Subprogram --
6701 ------------------------------------------------------
6703 function Replace_Anonymous_Access_To_Protected_Subprogram
6704 (N
: Node_Id
) return Entity_Id
6706 Loc
: constant Source_Ptr
:= Sloc
(N
);
6708 Curr_Scope
: constant Scope_Stack_Entry
:=
6709 Scope_Stack
.Table
(Scope_Stack
.Last
);
6711 Anon
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
6714 -- Access definition in declaration
6717 -- Object definition or formal definition with an access definition
6720 -- Declaration of anonymous access to subprogram type
6723 -- Original specification in access to subprogram
6728 Set_Is_Internal
(Anon
);
6731 when N_Constrained_Array_Definition
6732 | N_Component_Declaration
6733 | N_Unconstrained_Array_Definition
6735 Comp
:= Component_Definition
(N
);
6736 Acc
:= Access_Definition
(Comp
);
6738 when N_Discriminant_Specification
=>
6739 Comp
:= Discriminant_Type
(N
);
6742 when N_Parameter_Specification
=>
6743 Comp
:= Parameter_Type
(N
);
6746 when N_Access_Function_Definition
=>
6747 Comp
:= Result_Definition
(N
);
6750 when N_Object_Declaration
=>
6751 Comp
:= Object_Definition
(N
);
6754 when N_Function_Specification
=>
6755 Comp
:= Result_Definition
(N
);
6759 raise Program_Error
;
6762 Spec
:= Access_To_Subprogram_Definition
(Acc
);
6765 Make_Full_Type_Declaration
(Loc
,
6766 Defining_Identifier
=> Anon
,
6767 Type_Definition
=> Copy_Separate_Tree
(Spec
));
6769 Mark_Rewrite_Insertion
(Decl
);
6771 -- Insert the new declaration in the nearest enclosing scope. If the
6772 -- parent is a body and N is its return type, the declaration belongs
6773 -- in the enclosing scope. Likewise if N is the type of a parameter.
6777 if Nkind
(N
) = N_Function_Specification
6778 and then Nkind
(P
) = N_Subprogram_Body
6781 elsif Nkind
(N
) = N_Parameter_Specification
6782 and then Nkind
(P
) in N_Subprogram_Specification
6783 and then Nkind
(Parent
(P
)) = N_Subprogram_Body
6785 P
:= Parent
(Parent
(P
));
6788 while Present
(P
) and then not Has_Declarations
(P
) loop
6792 pragma Assert
(Present
(P
));
6794 if Nkind
(P
) = N_Package_Specification
then
6795 Prepend
(Decl
, Visible_Declarations
(P
));
6797 Prepend
(Decl
, Declarations
(P
));
6800 -- Replace the anonymous type with an occurrence of the new declaration.
6801 -- In all cases the rewritten node does not have the null-exclusion
6802 -- attribute because (if present) it was already inherited by the
6803 -- anonymous entity (Anon). Thus, in case of components we do not
6804 -- inherit this attribute.
6806 if Nkind
(N
) = N_Parameter_Specification
then
6807 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6808 Set_Etype
(Defining_Identifier
(N
), Anon
);
6809 Set_Null_Exclusion_Present
(N
, False);
6811 elsif Nkind
(N
) = N_Object_Declaration
then
6812 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6813 Set_Etype
(Defining_Identifier
(N
), Anon
);
6815 elsif Nkind
(N
) = N_Access_Function_Definition
then
6816 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6818 elsif Nkind
(N
) = N_Function_Specification
then
6819 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
6820 Set_Etype
(Defining_Unit_Name
(N
), Anon
);
6824 Make_Component_Definition
(Loc
,
6825 Subtype_Indication
=> New_Occurrence_Of
(Anon
, Loc
)));
6828 Mark_Rewrite_Insertion
(Comp
);
6830 if Nkind
(N
) in N_Object_Declaration | N_Access_Function_Definition
6831 or else (Nkind
(Parent
(N
)) = N_Full_Type_Declaration
6832 and then not Is_Type
(Current_Scope
))
6835 -- Declaration can be analyzed in the current scope.
6840 -- Temporarily remove the current scope (record or subprogram) from
6841 -- the stack to add the new declarations to the enclosing scope.
6842 -- The anonymous entity is an Itype with the proper attributes.
6844 Scope_Stack
.Decrement_Last
;
6846 Set_Is_Itype
(Anon
);
6847 Set_Associated_Node_For_Itype
(Anon
, N
);
6848 Scope_Stack
.Append
(Curr_Scope
);
6851 Mutate_Ekind
(Anon
, E_Anonymous_Access_Protected_Subprogram_Type
);
6852 Set_Can_Use_Internal_Rep
(Anon
, not Always_Compatible_Rep_On_Target
);
6854 end Replace_Anonymous_Access_To_Protected_Subprogram
;
6856 -------------------------------------
6857 -- Build_Access_Subprogram_Wrapper --
6858 -------------------------------------
6860 procedure Build_Access_Subprogram_Wrapper
(Decl
: Node_Id
) is
6861 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
6862 Id
: constant Entity_Id
:= Defining_Identifier
(Decl
);
6863 Type_Def
: constant Node_Id
:= Type_Definition
(Decl
);
6864 Specs
: constant List_Id
:=
6865 Parameter_Specifications
(Type_Def
);
6866 Profile
: constant List_Id
:= New_List
;
6867 Subp
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
6869 Contracts
: constant List_Id
:= New_List
;
6875 procedure Replace_Type_Name
(Expr
: Node_Id
);
6876 -- In the expressions for contract aspects, replace occurrences of the
6877 -- access type with the name of the subprogram entity, as needed, e.g.
6878 -- for 'Result. Aspects that are not contracts, e.g. Size or Alignment)
6879 -- remain on the original access type declaration. What about expanded
6880 -- names denoting formals, whose prefix in source is the type name ???
6882 -----------------------
6883 -- Replace_Type_Name --
6884 -----------------------
6886 procedure Replace_Type_Name
(Expr
: Node_Id
) is
6887 function Process
(N
: Node_Id
) return Traverse_Result
;
6888 function Process
(N
: Node_Id
) return Traverse_Result
is
6890 if Nkind
(N
) = N_Attribute_Reference
6891 and then Is_Entity_Name
(Prefix
(N
))
6892 and then Chars
(Prefix
(N
)) = Chars
(Id
)
6894 Set_Prefix
(N
, Make_Identifier
(Sloc
(N
), Chars
(Subp
)));
6900 procedure Traverse
is new Traverse_Proc
(Process
);
6903 end Replace_Type_Name
;
6906 if Ekind
(Id
) in E_Access_Subprogram_Type
6907 | E_Access_Protected_Subprogram_Type
6908 | E_Anonymous_Access_Protected_Subprogram_Type
6909 | E_Anonymous_Access_Subprogram_Type
6915 ("illegal pre/postcondition on access type", Decl
);
6924 Asp
:= First
(Aspect_Specifications
(Decl
));
6925 while Present
(Asp
) loop
6926 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(Asp
)));
6927 if A_Id
= Aspect_Pre
or else A_Id
= Aspect_Post
then
6928 Append
(New_Copy_Tree
(Asp
), Contracts
);
6929 Replace_Type_Name
(Expression
(Last
(Contracts
)));
6935 -- If there are no contract aspects, no need for a wrapper.
6937 if Is_Empty_List
(Contracts
) then
6941 Form_P
:= First
(Specs
);
6943 while Present
(Form_P
) loop
6944 New_P
:= New_Copy_Tree
(Form_P
);
6945 Set_Defining_Identifier
(New_P
,
6946 Make_Defining_Identifier
6947 (Loc
, Chars
(Defining_Identifier
(Form_P
))));
6948 Append
(New_P
, Profile
);
6952 -- Add to parameter specifications the access parameter that is passed
6953 -- in from an indirect call.
6956 Make_Parameter_Specification
(Loc
,
6957 Defining_Identifier
=> Make_Temporary
(Loc
, 'P'),
6958 Parameter_Type
=> New_Occurrence_Of
(Id
, Loc
)),
6961 if Nkind
(Type_Def
) = N_Access_Procedure_Definition
then
6963 Make_Procedure_Specification
(Loc
,
6964 Defining_Unit_Name
=> Subp
,
6965 Parameter_Specifications
=> Profile
);
6966 Mutate_Ekind
(Subp
, E_Procedure
);
6969 Make_Function_Specification
(Loc
,
6970 Defining_Unit_Name
=> Subp
,
6971 Parameter_Specifications
=> Profile
,
6972 Result_Definition
=>
6974 (Result_Definition
(Type_Definition
(Decl
))));
6975 Mutate_Ekind
(Subp
, E_Function
);
6979 Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
);
6980 Set_Aspect_Specifications
(New_Decl
, Contracts
);
6981 Set_Is_Wrapper
(Subp
);
6983 -- The wrapper is declared in the freezing actions to facilitate its
6984 -- identification and thus avoid handling it as a primitive operation
6985 -- of a tagged type (see Is_Access_To_Subprogram_Wrapper); otherwise it
6986 -- may be handled as a dispatching operation and erroneously registered
6987 -- in a dispatch table.
6989 Append_Freeze_Action
(Id
, New_Decl
);
6991 Set_Access_Subprogram_Wrapper
(Designated_Type
(Id
), Subp
);
6992 Build_Access_Subprogram_Wrapper_Body
(Decl
, New_Decl
);
6993 end Build_Access_Subprogram_Wrapper
;
6995 -------------------------------
6996 -- Build_Derived_Access_Type --
6997 -------------------------------
6999 procedure Build_Derived_Access_Type
7001 Parent_Type
: Entity_Id
;
7002 Derived_Type
: Entity_Id
)
7004 S
: constant Node_Id
:= Subtype_Indication
(Type_Definition
(N
));
7006 Desig_Type
: Entity_Id
;
7008 Discr_Con_Elist
: Elist_Id
;
7009 Discr_Con_El
: Elmt_Id
;
7013 -- Set the designated type so it is available in case this is an access
7014 -- to a self-referential type, e.g. a standard list type with a next
7015 -- pointer. Will be reset after subtype is built.
7017 Set_Directly_Designated_Type
7018 (Derived_Type
, Designated_Type
(Parent_Type
));
7020 Subt
:= Process_Subtype
(S
, N
);
7022 if Nkind
(S
) /= N_Subtype_Indication
7023 and then Subt
/= Base_Type
(Subt
)
7025 Mutate_Ekind
(Derived_Type
, E_Access_Subtype
);
7028 if Ekind
(Derived_Type
) = E_Access_Subtype
then
7030 Pbase
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7031 Ibase
: constant Entity_Id
:=
7032 Create_Itype
(Ekind
(Pbase
), N
, Derived_Type
, 'B');
7033 Svg_Chars
: constant Name_Id
:= Chars
(Ibase
);
7034 Svg_Next_E
: constant Entity_Id
:= Next_Entity
(Ibase
);
7035 Svg_Prev_E
: constant Entity_Id
:= Prev_Entity
(Ibase
);
7038 Copy_Node
(Pbase
, Ibase
);
7040 -- Restore Itype status after Copy_Node
7042 Set_Is_Itype
(Ibase
);
7043 Set_Associated_Node_For_Itype
(Ibase
, N
);
7045 Set_Chars
(Ibase
, Svg_Chars
);
7046 Set_Prev_Entity
(Ibase
, Svg_Prev_E
);
7047 Set_Next_Entity
(Ibase
, Svg_Next_E
);
7048 Set_Sloc
(Ibase
, Sloc
(Derived_Type
));
7049 Set_Scope
(Ibase
, Scope
(Derived_Type
));
7050 Set_Freeze_Node
(Ibase
, Empty
);
7051 Set_Is_Frozen
(Ibase
, False);
7052 Set_Comes_From_Source
(Ibase
, False);
7053 Set_Is_First_Subtype
(Ibase
, False);
7055 Set_Etype
(Ibase
, Pbase
);
7056 Set_Etype
(Derived_Type
, Ibase
);
7060 Set_Directly_Designated_Type
7061 (Derived_Type
, Designated_Type
(Subt
));
7063 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Subt
));
7064 Set_Is_Access_Constant
(Derived_Type
, Is_Access_Constant
(Parent_Type
));
7065 Set_Size_Info
(Derived_Type
, Parent_Type
);
7066 Copy_RM_Size
(To
=> Derived_Type
, From
=> Parent_Type
);
7067 Set_Depends_On_Private
(Derived_Type
,
7068 Has_Private_Component
(Derived_Type
));
7069 Conditional_Delay
(Derived_Type
, Subt
);
7071 if Is_Access_Subprogram_Type
(Derived_Type
)
7072 and then Is_Base_Type
(Derived_Type
)
7074 Set_Can_Use_Internal_Rep
7075 (Derived_Type
, Can_Use_Internal_Rep
(Parent_Type
));
7078 -- Ada 2005 (AI-231): Set the null-exclusion attribute, and verify
7079 -- that it is not redundant.
7081 if Null_Exclusion_Present
(Type_Definition
(N
)) then
7082 Set_Can_Never_Be_Null
(Derived_Type
);
7084 elsif Can_Never_Be_Null
(Parent_Type
) then
7085 Set_Can_Never_Be_Null
(Derived_Type
);
7088 -- Note: we do not copy the Storage_Size_Variable, since we always go to
7089 -- the root type for this information.
7091 -- Apply range checks to discriminants for derived record case
7092 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
7094 Desig_Type
:= Designated_Type
(Derived_Type
);
7096 if Is_Composite_Type
(Desig_Type
)
7097 and then not Is_Array_Type
(Desig_Type
)
7098 and then Has_Discriminants
(Desig_Type
)
7099 and then Base_Type
(Desig_Type
) /= Desig_Type
7101 Discr_Con_Elist
:= Discriminant_Constraint
(Desig_Type
);
7102 Discr_Con_El
:= First_Elmt
(Discr_Con_Elist
);
7104 Discr
:= First_Discriminant
(Base_Type
(Desig_Type
));
7105 while Present
(Discr_Con_El
) loop
7106 Apply_Range_Check
(Node
(Discr_Con_El
), Etype
(Discr
));
7107 Next_Elmt
(Discr_Con_El
);
7108 Next_Discriminant
(Discr
);
7111 end Build_Derived_Access_Type
;
7113 ------------------------------
7114 -- Build_Derived_Array_Type --
7115 ------------------------------
7117 procedure Build_Derived_Array_Type
7119 Parent_Type
: Entity_Id
;
7120 Derived_Type
: Entity_Id
)
7122 Loc
: constant Source_Ptr
:= Sloc
(N
);
7123 Tdef
: constant Node_Id
:= Type_Definition
(N
);
7124 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
7125 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7126 Implicit_Base
: Entity_Id
:= Empty
;
7127 New_Indic
: Node_Id
;
7129 procedure Make_Implicit_Base
;
7130 -- If the parent subtype is constrained, the derived type is a subtype
7131 -- of an implicit base type derived from the parent base.
7133 ------------------------
7134 -- Make_Implicit_Base --
7135 ------------------------
7137 procedure Make_Implicit_Base
is
7140 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
7142 Mutate_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
7143 Set_Etype
(Implicit_Base
, Parent_Base
);
7145 Copy_Array_Subtype_Attributes
(Implicit_Base
, Parent_Base
);
7146 Copy_Array_Base_Type_Attributes
(Implicit_Base
, Parent_Base
);
7148 Set_Has_Delayed_Freeze
(Implicit_Base
, True);
7149 end Make_Implicit_Base
;
7151 -- Start of processing for Build_Derived_Array_Type
7154 if not Is_Constrained
(Parent_Type
) then
7155 if Nkind
(Indic
) /= N_Subtype_Indication
then
7156 Mutate_Ekind
(Derived_Type
, E_Array_Type
);
7158 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
7159 Copy_Array_Base_Type_Attributes
(Derived_Type
, Parent_Type
);
7161 Set_Has_Delayed_Freeze
(Derived_Type
, True);
7165 Set_Etype
(Derived_Type
, Implicit_Base
);
7168 Make_Subtype_Declaration
(Loc
,
7169 Defining_Identifier
=> Derived_Type
,
7170 Subtype_Indication
=>
7171 Make_Subtype_Indication
(Loc
,
7172 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
7173 Constraint
=> Constraint
(Indic
)));
7175 Rewrite
(N
, New_Indic
);
7177 -- Keep the aspects from the original node
7179 Move_Aspects
(Original_Node
(N
), N
);
7185 if Nkind
(Indic
) /= N_Subtype_Indication
then
7188 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Type
));
7189 Set_Etype
(Derived_Type
, Implicit_Base
);
7190 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
7193 Error_Msg_N
("illegal constraint on constrained type", Indic
);
7197 -- If parent type is not a derived type itself, and is declared in
7198 -- closed scope (e.g. a subprogram), then we must explicitly introduce
7199 -- the new type's concatenation operator since Derive_Subprograms
7200 -- will not inherit the parent's operator. If the parent type is
7201 -- unconstrained, the operator is of the unconstrained base type.
7203 if Number_Dimensions
(Parent_Type
) = 1
7204 and then not Is_Limited_Type
(Parent_Type
)
7205 and then not Is_Derived_Type
(Parent_Type
)
7206 and then not Is_Package_Or_Generic_Package
7207 (Scope
(Base_Type
(Parent_Type
)))
7209 if not Is_Constrained
(Parent_Type
)
7210 and then Is_Constrained
(Derived_Type
)
7212 New_Concatenation_Op
(Implicit_Base
);
7214 New_Concatenation_Op
(Derived_Type
);
7217 end Build_Derived_Array_Type
;
7219 -----------------------------------
7220 -- Build_Derived_Concurrent_Type --
7221 -----------------------------------
7223 procedure Build_Derived_Concurrent_Type
7225 Parent_Type
: Entity_Id
;
7226 Derived_Type
: Entity_Id
)
7228 Loc
: constant Source_Ptr
:= Sloc
(N
);
7229 Def
: constant Node_Id
:= Type_Definition
(N
);
7230 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7232 Corr_Record
: constant Entity_Id
:= Make_Temporary
(Loc
, 'C');
7233 Corr_Decl
: Node_Id
:= Empty
;
7234 Corr_Decl_Needed
: Boolean;
7235 -- If the derived type has fewer discriminants than its parent, the
7236 -- corresponding record is also a derived type, in order to account for
7237 -- the bound discriminants. We create a full type declaration for it in
7240 Constraint_Present
: constant Boolean :=
7241 Nkind
(Indic
) = N_Subtype_Indication
;
7243 D_Constraint
: Node_Id
;
7244 New_Constraint
: Elist_Id
:= No_Elist
;
7245 Old_Disc
: Entity_Id
;
7246 New_Disc
: Entity_Id
;
7250 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
7251 Corr_Decl_Needed
:= False;
7254 if Present
(Discriminant_Specifications
(N
))
7255 and then Constraint_Present
7257 Old_Disc
:= First_Discriminant
(Parent_Type
);
7258 New_Disc
:= First
(Discriminant_Specifications
(N
));
7259 while Present
(New_Disc
) and then Present
(Old_Disc
) loop
7260 Next_Discriminant
(Old_Disc
);
7265 if Present
(Old_Disc
) and then Expander_Active
then
7267 -- The new type has fewer discriminants, so we need to create a new
7268 -- corresponding record, which is derived from the corresponding
7269 -- record of the parent, and has a stored constraint that captures
7270 -- the values of the discriminant constraints. The corresponding
7271 -- record is needed only if expander is active and code generation is
7274 -- The type declaration for the derived corresponding record has the
7275 -- same discriminant part and constraints as the current declaration.
7276 -- Copy the unanalyzed tree to build declaration.
7278 Corr_Decl_Needed
:= True;
7279 New_N
:= Copy_Separate_Tree
(N
);
7282 Make_Full_Type_Declaration
(Loc
,
7283 Defining_Identifier
=> Corr_Record
,
7284 Discriminant_Specifications
=>
7285 Discriminant_Specifications
(New_N
),
7287 Make_Derived_Type_Definition
(Loc
,
7288 Subtype_Indication
=>
7289 Make_Subtype_Indication
(Loc
,
7292 (Corresponding_Record_Type
(Parent_Type
), Loc
),
7295 (Subtype_Indication
(Type_Definition
(New_N
))))));
7298 -- Copy Storage_Size and Relative_Deadline variables if task case
7300 if Is_Task_Type
(Parent_Type
) then
7301 Set_Storage_Size_Variable
(Derived_Type
,
7302 Storage_Size_Variable
(Parent_Type
));
7303 Set_Relative_Deadline_Variable
(Derived_Type
,
7304 Relative_Deadline_Variable
(Parent_Type
));
7307 if Present
(Discriminant_Specifications
(N
)) then
7308 Push_Scope
(Derived_Type
);
7309 Check_Or_Process_Discriminants
(N
, Derived_Type
);
7311 if Constraint_Present
then
7313 Expand_To_Stored_Constraint
7315 Build_Discriminant_Constraints
7316 (Parent_Type
, Indic
, True));
7321 elsif Constraint_Present
then
7323 -- Build an unconstrained derived type and rewrite the derived type
7324 -- as a subtype of this new base type.
7327 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7328 New_Base
: Entity_Id
;
7330 New_Indic
: Node_Id
;
7334 Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
7337 Make_Full_Type_Declaration
(Loc
,
7338 Defining_Identifier
=> New_Base
,
7340 Make_Derived_Type_Definition
(Loc
,
7341 Abstract_Present
=> Abstract_Present
(Def
),
7342 Limited_Present
=> Limited_Present
(Def
),
7343 Subtype_Indication
=>
7344 New_Occurrence_Of
(Parent_Base
, Loc
)));
7346 Mark_Rewrite_Insertion
(New_Decl
);
7347 Insert_Before
(N
, New_Decl
);
7351 Make_Subtype_Indication
(Loc
,
7352 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
7353 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
7356 Make_Subtype_Declaration
(Loc
,
7357 Defining_Identifier
=> Derived_Type
,
7358 Subtype_Indication
=> New_Indic
));
7360 -- Keep the aspects from the original node
7362 Move_Aspects
(Original_Node
(N
), N
);
7369 -- By default, operations and private data are inherited from parent.
7370 -- However, in the presence of bound discriminants, a new corresponding
7371 -- record will be created, see below.
7373 Set_Has_Discriminants
7374 (Derived_Type
, Has_Discriminants
(Parent_Type
));
7375 Set_Corresponding_Record_Type
7376 (Derived_Type
, Corresponding_Record_Type
(Parent_Type
));
7378 -- Is_Constrained is set according the parent subtype, but is set to
7379 -- False if the derived type is declared with new discriminants.
7383 (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
7384 and then No
(Discriminant_Specifications
(N
)));
7386 if Constraint_Present
then
7387 if not Has_Discriminants
(Parent_Type
) then
7388 Error_Msg_N
("untagged parent must have discriminants", N
);
7390 elsif Present
(Discriminant_Specifications
(N
)) then
7392 -- Verify that new discriminants are used to constrain old ones
7394 D_Constraint
:= First
(Constraints
(Constraint
(Indic
)));
7396 Old_Disc
:= First_Discriminant
(Parent_Type
);
7398 while Present
(D_Constraint
) loop
7399 if Nkind
(D_Constraint
) /= N_Discriminant_Association
then
7401 -- Positional constraint. If it is a reference to a new
7402 -- discriminant, it constrains the corresponding old one.
7404 if Nkind
(D_Constraint
) = N_Identifier
then
7405 New_Disc
:= First_Discriminant
(Derived_Type
);
7406 while Present
(New_Disc
) loop
7407 exit when Chars
(New_Disc
) = Chars
(D_Constraint
);
7408 Next_Discriminant
(New_Disc
);
7411 if Present
(New_Disc
) then
7412 Set_Corresponding_Discriminant
(New_Disc
, Old_Disc
);
7416 Next_Discriminant
(Old_Disc
);
7418 -- if this is a named constraint, search by name for the old
7419 -- discriminants constrained by the new one.
7421 elsif Nkind
(Expression
(D_Constraint
)) = N_Identifier
then
7423 -- Find new discriminant with that name
7425 New_Disc
:= First_Discriminant
(Derived_Type
);
7426 while Present
(New_Disc
) loop
7428 Chars
(New_Disc
) = Chars
(Expression
(D_Constraint
));
7429 Next_Discriminant
(New_Disc
);
7432 if Present
(New_Disc
) then
7434 -- Verify that new discriminant renames some discriminant
7435 -- of the parent type, and associate the new discriminant
7436 -- with one or more old ones that it renames.
7442 Selector
:= First
(Selector_Names
(D_Constraint
));
7443 while Present
(Selector
) loop
7444 Old_Disc
:= First_Discriminant
(Parent_Type
);
7445 while Present
(Old_Disc
) loop
7446 exit when Chars
(Old_Disc
) = Chars
(Selector
);
7447 Next_Discriminant
(Old_Disc
);
7450 if Present
(Old_Disc
) then
7451 Set_Corresponding_Discriminant
7452 (New_Disc
, Old_Disc
);
7461 Next
(D_Constraint
);
7464 New_Disc
:= First_Discriminant
(Derived_Type
);
7465 while Present
(New_Disc
) loop
7466 if No
(Corresponding_Discriminant
(New_Disc
)) then
7468 ("new discriminant& must constrain old one", N
, New_Disc
);
7470 -- If a new discriminant is used in the constraint, then its
7471 -- subtype must be statically compatible with the subtype of
7472 -- the parent discriminant (RM 3.7(15)).
7475 Check_Constraining_Discriminant
7476 (New_Disc
, Corresponding_Discriminant
(New_Disc
));
7479 Next_Discriminant
(New_Disc
);
7483 elsif Present
(Discriminant_Specifications
(N
)) then
7485 ("missing discriminant constraint in untagged derivation", N
);
7488 -- The entity chain of the derived type includes the new discriminants
7489 -- but shares operations with the parent.
7491 if Present
(Discriminant_Specifications
(N
)) then
7492 Old_Disc
:= First_Discriminant
(Parent_Type
);
7493 while Present
(Old_Disc
) loop
7494 if No
(Next_Entity
(Old_Disc
))
7495 or else Ekind
(Next_Entity
(Old_Disc
)) /= E_Discriminant
7498 (Last_Entity
(Derived_Type
), Next_Entity
(Old_Disc
));
7502 Next_Discriminant
(Old_Disc
);
7506 Set_First_Entity
(Derived_Type
, First_Entity
(Parent_Type
));
7507 if Has_Discriminants
(Parent_Type
) then
7508 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
7509 Set_Discriminant_Constraint
(
7510 Derived_Type
, Discriminant_Constraint
(Parent_Type
));
7514 Set_Last_Entity
(Derived_Type
, Last_Entity
(Parent_Type
));
7516 Set_Has_Completion
(Derived_Type
);
7518 if Corr_Decl_Needed
then
7519 Set_Stored_Constraint
(Derived_Type
, New_Constraint
);
7520 Insert_After
(N
, Corr_Decl
);
7521 Analyze
(Corr_Decl
);
7522 Set_Corresponding_Record_Type
(Derived_Type
, Corr_Record
);
7524 end Build_Derived_Concurrent_Type
;
7526 ------------------------------------
7527 -- Build_Derived_Enumeration_Type --
7528 ------------------------------------
7530 procedure Build_Derived_Enumeration_Type
7532 Parent_Type
: Entity_Id
;
7533 Derived_Type
: Entity_Id
)
7535 function Bound_Belongs_To_Type
(B
: Node_Id
) return Boolean;
7536 -- When the type declaration includes a constraint, we generate
7537 -- a subtype declaration of an anonymous base type, with the constraint
7538 -- given in the original type declaration. Conceptually, the bounds
7539 -- are converted to the new base type, and this conversion freezes
7540 -- (prematurely) that base type, when the bounds are simply literals.
7541 -- As a result, a representation clause for the derived type is then
7542 -- rejected or ignored. This procedure recognizes the simple case of
7543 -- literal bounds, which allows us to indicate that the conversions
7544 -- are not freeze points, and the subsequent representation clause
7546 -- A similar approach might be used to resolve the long-standing
7547 -- problem of premature freezing of derived numeric types ???
7549 function Bound_Belongs_To_Type
(B
: Node_Id
) return Boolean is
7551 return Nkind
(B
) = N_Type_Conversion
7552 and then Is_Entity_Name
(Expression
(B
))
7553 and then Ekind
(Entity
(Expression
(B
))) = E_Enumeration_Literal
;
7554 end Bound_Belongs_To_Type
;
7556 Loc
: constant Source_Ptr
:= Sloc
(N
);
7557 Def
: constant Node_Id
:= Type_Definition
(N
);
7558 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
7559 Implicit_Base
: Entity_Id
;
7560 Literal
: Entity_Id
;
7561 New_Lit
: Entity_Id
;
7562 Literals_List
: List_Id
;
7563 Type_Decl
: Node_Id
;
7565 Rang_Expr
: Node_Id
;
7568 -- Since types Standard.Character and Standard.[Wide_]Wide_Character do
7569 -- not have explicit literals lists we need to process types derived
7570 -- from them specially. This is handled by Derived_Standard_Character.
7571 -- If the parent type is a generic type, there are no literals either,
7572 -- and we construct the same skeletal representation as for the generic
7575 if Is_Standard_Character_Type
(Parent_Type
) then
7576 Derived_Standard_Character
(N
, Parent_Type
, Derived_Type
);
7578 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
7584 if Nkind
(Indic
) /= N_Subtype_Indication
then
7586 Make_Attribute_Reference
(Loc
,
7587 Attribute_Name
=> Name_First
,
7588 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
7589 Set_Etype
(Lo
, Derived_Type
);
7592 Make_Attribute_Reference
(Loc
,
7593 Attribute_Name
=> Name_Last
,
7594 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
7595 Set_Etype
(Hi
, Derived_Type
);
7597 Set_Scalar_Range
(Derived_Type
,
7603 -- Analyze subtype indication and verify compatibility
7604 -- with parent type.
7606 if Base_Type
(Process_Subtype
(Indic
, N
)) /=
7607 Base_Type
(Parent_Type
)
7610 ("illegal constraint for formal discrete type", N
);
7616 -- If a constraint is present, analyze the bounds to catch
7617 -- premature usage of the derived literals.
7619 if Nkind
(Indic
) = N_Subtype_Indication
7620 and then Nkind
(Range_Expression
(Constraint
(Indic
))) = N_Range
7622 Analyze
(Low_Bound
(Range_Expression
(Constraint
(Indic
))));
7623 Analyze
(High_Bound
(Range_Expression
(Constraint
(Indic
))));
7626 -- Create an implicit base type for the derived type even if there
7627 -- is no constraint attached to it, since this seems closer to the
7628 -- Ada semantics. Use an Itype like for the implicit base type of
7629 -- other kinds of derived type, but build a full type declaration
7630 -- for it so as to analyze the new literals properly. Then build a
7631 -- subtype declaration tree which applies the constraint (if any)
7632 -- and have it replace the derived type declaration.
7634 Literal
:= First_Literal
(Parent_Type
);
7635 Literals_List
:= New_List
;
7636 while Present
(Literal
)
7637 and then Ekind
(Literal
) = E_Enumeration_Literal
7639 -- Literals of the derived type have the same representation as
7640 -- those of the parent type, but this representation can be
7641 -- overridden by an explicit representation clause. Indicate
7642 -- that there is no explicit representation given yet. These
7643 -- derived literals are implicit operations of the new type,
7644 -- and can be overridden by explicit ones.
7646 if Nkind
(Literal
) = N_Defining_Character_Literal
then
7648 Make_Defining_Character_Literal
(Loc
, Chars
(Literal
));
7650 New_Lit
:= Make_Defining_Identifier
(Loc
, Chars
(Literal
));
7653 Mutate_Ekind
(New_Lit
, E_Enumeration_Literal
);
7654 Set_Is_Not_Self_Hidden
(New_Lit
);
7655 Set_Enumeration_Pos
(New_Lit
, Enumeration_Pos
(Literal
));
7656 Set_Enumeration_Rep
(New_Lit
, Enumeration_Rep
(Literal
));
7657 Set_Enumeration_Rep_Expr
(New_Lit
, Empty
);
7658 Set_Alias
(New_Lit
, Literal
);
7659 Set_Is_Known_Valid
(New_Lit
, True);
7661 Append
(New_Lit
, Literals_List
);
7662 Next_Literal
(Literal
);
7666 Create_Itype
(E_Enumeration_Type
, N
, Derived_Type
, 'B');
7668 -- Indicate the proper nature of the derived type. This must be done
7669 -- before analysis of the literals, to recognize cases when a literal
7670 -- may be hidden by a previous explicit function definition (cf.
7673 Mutate_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
7674 Set_Etype
(Derived_Type
, Implicit_Base
);
7677 Make_Full_Type_Declaration
(Loc
,
7678 Defining_Identifier
=> Implicit_Base
,
7680 Make_Enumeration_Type_Definition
(Loc
, Literals_List
));
7682 -- Do not insert the declarationn, just analyze it in the context
7684 Set_Parent
(Type_Decl
, Parent
(N
));
7685 Analyze
(Type_Decl
);
7687 -- The anonymous base now has a full declaration, but this base
7688 -- is not a first subtype.
7690 Set_Is_First_Subtype
(Implicit_Base
, False);
7692 -- After the implicit base is analyzed its Etype needs to be changed
7693 -- to reflect the fact that it is derived from the parent type which
7694 -- was ignored during analysis. We also set the size at this point.
7696 Set_Etype
(Implicit_Base
, Parent_Type
);
7698 Set_Size_Info
(Implicit_Base
, Parent_Type
);
7699 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Type
));
7700 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Type
));
7702 -- Copy other flags from parent type
7704 Set_Has_Non_Standard_Rep
7705 (Implicit_Base
, Has_Non_Standard_Rep
7707 Set_Has_Pragma_Ordered
7708 (Implicit_Base
, Has_Pragma_Ordered
7710 Set_Has_Delayed_Freeze
(Implicit_Base
);
7712 -- Process the subtype indication including a validation check on the
7713 -- constraint, if any. If a constraint is given, its bounds must be
7714 -- implicitly converted to the new type.
7716 if Nkind
(Indic
) = N_Subtype_Indication
then
7718 R
: constant Node_Id
:=
7719 Range_Expression
(Constraint
(Indic
));
7722 if Nkind
(R
) = N_Range
then
7723 Hi
:= Build_Scalar_Bound
7724 (High_Bound
(R
), Parent_Type
, Implicit_Base
);
7725 Lo
:= Build_Scalar_Bound
7726 (Low_Bound
(R
), Parent_Type
, Implicit_Base
);
7729 -- Constraint is a Range attribute. Replace with explicit
7730 -- mention of the bounds of the prefix, which must be a
7733 Analyze
(Prefix
(R
));
7735 Convert_To
(Implicit_Base
,
7736 Make_Attribute_Reference
(Loc
,
7737 Attribute_Name
=> Name_Last
,
7739 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
7742 Convert_To
(Implicit_Base
,
7743 Make_Attribute_Reference
(Loc
,
7744 Attribute_Name
=> Name_First
,
7746 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
7753 (Type_High_Bound
(Parent_Type
),
7754 Parent_Type
, Implicit_Base
);
7757 (Type_Low_Bound
(Parent_Type
),
7758 Parent_Type
, Implicit_Base
);
7766 -- If we constructed a default range for the case where no range
7767 -- was given, then the expressions in the range must not freeze
7768 -- since they do not correspond to expressions in the source.
7769 -- However, if the type inherits predicates the expressions will
7770 -- be elaborated earlier and must freeze.
7772 if (Nkind
(Indic
) /= N_Subtype_Indication
7774 (Bound_Belongs_To_Type
(Lo
) and then Bound_Belongs_To_Type
(Hi
)))
7775 and then not Has_Predicates
(Derived_Type
)
7777 Set_Must_Not_Freeze
(Lo
);
7778 Set_Must_Not_Freeze
(Hi
);
7779 Set_Must_Not_Freeze
(Rang_Expr
);
7783 Make_Subtype_Declaration
(Loc
,
7784 Defining_Identifier
=> Derived_Type
,
7785 Subtype_Indication
=>
7786 Make_Subtype_Indication
(Loc
,
7787 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
7789 Make_Range_Constraint
(Loc
,
7790 Range_Expression
=> Rang_Expr
))));
7792 -- Keep the aspects from the orignal node
7794 Move_Aspects
(Original_Node
(N
), N
);
7798 -- Propagate the aspects from the original type declaration to the
7799 -- declaration of the implicit base.
7801 Copy_Aspects
(From
=> N
, To
=> Type_Decl
);
7803 -- Apply a range check. Since this range expression doesn't have an
7804 -- Etype, we have to specifically pass the Source_Typ parameter. Is
7807 if Nkind
(Indic
) = N_Subtype_Indication
then
7809 (Range_Expression
(Constraint
(Indic
)), Parent_Type
,
7810 Source_Typ
=> Entity
(Subtype_Mark
(Indic
)));
7813 end Build_Derived_Enumeration_Type
;
7815 --------------------------------
7816 -- Build_Derived_Numeric_Type --
7817 --------------------------------
7819 procedure Build_Derived_Numeric_Type
7821 Parent_Type
: Entity_Id
;
7822 Derived_Type
: Entity_Id
)
7824 Loc
: constant Source_Ptr
:= Sloc
(N
);
7825 Tdef
: constant Node_Id
:= Type_Definition
(N
);
7826 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
7827 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
7828 No_Constraint
: constant Boolean := Nkind
(Indic
) /=
7829 N_Subtype_Indication
;
7830 Implicit_Base
: Entity_Id
;
7836 -- Process the subtype indication including a validation check on
7837 -- the constraint if any.
7839 Discard_Node
(Process_Subtype
(Indic
, N
));
7841 -- Introduce an implicit base type for the derived type even if there
7842 -- is no constraint attached to it, since this seems closer to the Ada
7846 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
7848 Set_Etype
(Implicit_Base
, Parent_Base
);
7849 Mutate_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
7850 Set_Size_Info
(Implicit_Base
, Parent_Base
);
7851 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Base
));
7852 Set_Parent
(Implicit_Base
, Parent
(Derived_Type
));
7853 Set_Is_Known_Valid
(Implicit_Base
, Is_Known_Valid
(Parent_Base
));
7854 Set_Is_Volatile
(Implicit_Base
, Is_Volatile
(Parent_Base
));
7856 -- Set RM Size for discrete type or decimal fixed-point type
7857 -- Ordinary fixed-point is excluded, why???
7859 if Is_Discrete_Type
(Parent_Base
)
7860 or else Is_Decimal_Fixed_Point_Type
(Parent_Base
)
7862 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Base
));
7865 Set_Has_Delayed_Freeze
(Implicit_Base
);
7867 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
7868 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
7870 Set_Scalar_Range
(Implicit_Base
,
7875 if Has_Infinities
(Parent_Base
) then
7876 Set_Includes_Infinities
(Scalar_Range
(Implicit_Base
));
7879 -- The Derived_Type, which is the entity of the declaration, is a
7880 -- subtype of the implicit base. Its Ekind is a subtype, even in the
7881 -- absence of an explicit constraint.
7883 Set_Etype
(Derived_Type
, Implicit_Base
);
7885 -- If we did not have a constraint, then the Ekind is set from the
7886 -- parent type (otherwise Process_Subtype has set the bounds)
7888 if No_Constraint
then
7889 Mutate_Ekind
(Derived_Type
, Subtype_Kind
(Ekind
(Parent_Type
)));
7892 -- If we did not have a range constraint, then set the range from the
7893 -- parent type. Otherwise, the Process_Subtype call has set the bounds.
7895 if No_Constraint
or else not Has_Range_Constraint
(Indic
) then
7896 Set_Scalar_Range
(Derived_Type
,
7898 Low_Bound
=> New_Copy_Tree
(Type_Low_Bound
(Parent_Type
)),
7899 High_Bound
=> New_Copy_Tree
(Type_High_Bound
(Parent_Type
))));
7900 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
7902 if Has_Infinities
(Parent_Type
) then
7903 Set_Includes_Infinities
(Scalar_Range
(Derived_Type
));
7906 Set_Is_Known_Valid
(Derived_Type
, Is_Known_Valid
(Parent_Type
));
7909 Set_Is_Descendant_Of_Address
(Derived_Type
,
7910 Is_Descendant_Of_Address
(Parent_Type
));
7911 Set_Is_Descendant_Of_Address
(Implicit_Base
,
7912 Is_Descendant_Of_Address
(Parent_Type
));
7914 -- Set remaining type-specific fields, depending on numeric type
7916 if Is_Modular_Integer_Type
(Parent_Type
) then
7917 Set_Modulus
(Implicit_Base
, Modulus
(Parent_Base
));
7919 Set_Non_Binary_Modulus
7920 (Implicit_Base
, Non_Binary_Modulus
(Parent_Base
));
7923 (Implicit_Base
, Is_Known_Valid
(Parent_Base
));
7925 elsif Is_Floating_Point_Type
(Parent_Type
) then
7927 -- Digits of base type is always copied from the digits value of
7928 -- the parent base type, but the digits of the derived type will
7929 -- already have been set if there was a constraint present.
7931 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
7932 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Parent_Base
));
7934 if No_Constraint
then
7935 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Type
));
7938 elsif Is_Fixed_Point_Type
(Parent_Type
) then
7940 -- Small of base type and derived type are always copied from the
7941 -- parent base type, since smalls never change. The delta of the
7942 -- base type is also copied from the parent base type. However the
7943 -- delta of the derived type will have been set already if a
7944 -- constraint was present.
7946 Set_Small_Value
(Derived_Type
, Small_Value
(Parent_Base
));
7947 Set_Small_Value
(Implicit_Base
, Small_Value
(Parent_Base
));
7948 Set_Delta_Value
(Implicit_Base
, Delta_Value
(Parent_Base
));
7950 if No_Constraint
then
7951 Set_Delta_Value
(Derived_Type
, Delta_Value
(Parent_Type
));
7954 -- The scale and machine radix in the decimal case are always
7955 -- copied from the parent base type.
7957 if Is_Decimal_Fixed_Point_Type
(Parent_Type
) then
7958 Set_Scale_Value
(Derived_Type
, Scale_Value
(Parent_Base
));
7959 Set_Scale_Value
(Implicit_Base
, Scale_Value
(Parent_Base
));
7961 Set_Machine_Radix_10
7962 (Derived_Type
, Machine_Radix_10
(Parent_Base
));
7963 Set_Machine_Radix_10
7964 (Implicit_Base
, Machine_Radix_10
(Parent_Base
));
7966 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
7968 if No_Constraint
then
7969 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Base
));
7972 -- the analysis of the subtype_indication sets the
7973 -- digits value of the derived type.
7980 if Is_Integer_Type
(Parent_Type
) then
7981 Set_Has_Shift_Operator
7982 (Implicit_Base
, Has_Shift_Operator
(Parent_Type
));
7985 -- The type of the bounds is that of the parent type, and they
7986 -- must be converted to the derived type.
7988 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
7989 end Build_Derived_Numeric_Type
;
7991 --------------------------------
7992 -- Build_Derived_Private_Type --
7993 --------------------------------
7995 procedure Build_Derived_Private_Type
7997 Parent_Type
: Entity_Id
;
7998 Derived_Type
: Entity_Id
;
7999 Is_Completion
: Boolean;
8000 Derive_Subps
: Boolean := True)
8002 Loc
: constant Source_Ptr
:= Sloc
(N
);
8003 Par_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
8004 Par_Scope
: constant Entity_Id
:= Scope
(Par_Base
);
8005 Full_N
: constant Node_Id
:= New_Copy_Tree
(N
);
8006 Full_Der
: Entity_Id
:= New_Copy
(Derived_Type
);
8009 function Available_Full_View
(Typ
: Entity_Id
) return Entity_Id
;
8010 -- Return the Full_View or Underlying_Full_View of Typ, whichever is
8011 -- present (they cannot be both present for the same type), or Empty.
8013 procedure Build_Full_Derivation
;
8014 -- Build full derivation, i.e. derive from the full view
8016 procedure Copy_And_Build
;
8017 -- Copy derived type declaration, replace parent with its full view,
8018 -- and build derivation
8020 -------------------------
8021 -- Available_Full_View --
8022 -------------------------
8024 function Available_Full_View
(Typ
: Entity_Id
) return Entity_Id
is
8026 if Present
(Full_View
(Typ
)) then
8027 return Full_View
(Typ
);
8029 elsif Present
(Underlying_Full_View
(Typ
)) then
8031 -- We should be called on a type with an underlying full view
8032 -- only by means of the recursive call made in Copy_And_Build
8033 -- through the first call to Build_Derived_Type, or else if
8034 -- the parent scope is being analyzed because we are deriving
8037 pragma Assert
(Is_Completion
or else In_Private_Part
(Par_Scope
));
8039 return Underlying_Full_View
(Typ
);
8044 end Available_Full_View
;
8046 ---------------------------
8047 -- Build_Full_Derivation --
8048 ---------------------------
8050 procedure Build_Full_Derivation
is
8052 -- If parent scope is not open, install the declarations
8054 if not In_Open_Scopes
(Par_Scope
) then
8055 Install_Private_Declarations
(Par_Scope
);
8056 Install_Visible_Declarations
(Par_Scope
);
8058 Uninstall_Declarations
(Par_Scope
);
8060 -- If parent scope is open and in another unit, and parent has a
8061 -- completion, then the derivation is taking place in the visible
8062 -- part of a child unit. In that case retrieve the full view of
8063 -- the parent momentarily.
8065 elsif not In_Same_Source_Unit
(N
, Parent_Type
)
8066 and then Present
(Full_View
(Parent_Type
))
8068 Full_P
:= Full_View
(Parent_Type
);
8069 Exchange_Declarations
(Parent_Type
);
8071 Exchange_Declarations
(Full_P
);
8073 -- Otherwise it is a local derivation
8078 end Build_Full_Derivation
;
8080 --------------------
8081 -- Copy_And_Build --
8082 --------------------
8084 procedure Copy_And_Build
is
8085 Full_Parent
: Entity_Id
:= Parent_Type
;
8088 -- If the parent is itself derived from another private type,
8089 -- installing the private declarations has not affected its
8090 -- privacy status, so use its own full view explicitly.
8092 if Is_Private_Type
(Full_Parent
)
8093 and then Present
(Full_View
(Full_Parent
))
8095 Full_Parent
:= Full_View
(Full_Parent
);
8098 -- If the full view is itself derived from another private type
8099 -- and has got an underlying full view, and this is done for a
8100 -- completion, i.e. to build the underlying full view of the type,
8101 -- then use this underlying full view. We cannot do that if this
8102 -- is not a completion, i.e. to build the full view of the type,
8103 -- because this would break the privacy of the parent type, except
8104 -- if the parent scope is being analyzed because we are deriving a
8107 if Is_Private_Type
(Full_Parent
)
8108 and then Present
(Underlying_Full_View
(Full_Parent
))
8109 and then (Is_Completion
or else In_Private_Part
(Par_Scope
))
8111 Full_Parent
:= Underlying_Full_View
(Full_Parent
);
8114 -- For private, record, concurrent, access and almost all enumeration
8115 -- types, the derivation from the full view requires a fully-fledged
8116 -- declaration. In the other cases, just use an itype.
8118 if Is_Private_Type
(Full_Parent
)
8119 or else Is_Record_Type
(Full_Parent
)
8120 or else Is_Concurrent_Type
(Full_Parent
)
8121 or else Is_Access_Type
(Full_Parent
)
8123 (Is_Enumeration_Type
(Full_Parent
)
8124 and then not Is_Standard_Character_Type
(Full_Parent
)
8125 and then not Is_Generic_Type
(Root_Type
(Full_Parent
)))
8127 -- Copy and adjust declaration to provide a completion for what
8128 -- is originally a private declaration. Indicate that full view
8129 -- is internally generated.
8131 Set_Comes_From_Source
(Full_N
, False);
8132 Set_Comes_From_Source
(Full_Der
, False);
8133 Set_Parent
(Full_Der
, Full_N
);
8134 Set_Defining_Identifier
(Full_N
, Full_Der
);
8136 -- If there are no constraints, adjust the subtype mark
8138 if Nkind
(Subtype_Indication
(Type_Definition
(Full_N
))) /=
8139 N_Subtype_Indication
8141 Set_Subtype_Indication
8142 (Type_Definition
(Full_N
),
8143 New_Occurrence_Of
(Full_Parent
, Sloc
(Full_N
)));
8146 Insert_After
(N
, Full_N
);
8148 -- Build full view of derived type from full view of parent which
8149 -- is now installed. Subprograms have been derived on the partial
8150 -- view, the completion does not derive them anew.
8152 if Is_Record_Type
(Full_Parent
) then
8154 -- If parent type is tagged, the completion inherits the proper
8155 -- primitive operations.
8157 if Is_Tagged_Type
(Parent_Type
) then
8158 Build_Derived_Record_Type
8159 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
);
8161 Build_Derived_Record_Type
8162 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
=> False);
8166 -- If the parent type is private, this is not a completion and
8167 -- we build the full derivation recursively as a completion.
8170 (Full_N
, Full_Parent
, Full_Der
,
8171 Is_Completion
=> Is_Private_Type
(Full_Parent
),
8172 Derive_Subps
=> False);
8175 -- The full declaration has been introduced into the tree and
8176 -- processed in the step above. It should not be analyzed again
8177 -- (when encountered later in the current list of declarations)
8178 -- to prevent spurious name conflicts. The full entity remains
8181 Set_Analyzed
(Full_N
);
8185 Make_Defining_Identifier
(Sloc
(Derived_Type
),
8186 Chars
=> Chars
(Derived_Type
));
8187 Set_Is_Itype
(Full_Der
);
8188 Set_Associated_Node_For_Itype
(Full_Der
, N
);
8189 Set_Parent
(Full_Der
, N
);
8191 (N
, Full_Parent
, Full_Der
,
8192 Is_Completion
=> False, Derive_Subps
=> False);
8193 Set_Is_Not_Self_Hidden
(Full_Der
);
8196 Set_Has_Private_Declaration
(Full_Der
);
8197 Set_Has_Private_Declaration
(Derived_Type
);
8199 Set_Scope
(Full_Der
, Scope
(Derived_Type
));
8200 Set_Is_First_Subtype
(Full_Der
, Is_First_Subtype
(Derived_Type
));
8201 Set_Has_Size_Clause
(Full_Der
, False);
8202 Set_Has_Alignment_Clause
(Full_Der
, False);
8203 Set_Has_Delayed_Freeze
(Full_Der
);
8204 Set_Is_Frozen
(Full_Der
, False);
8205 Set_Freeze_Node
(Full_Der
, Empty
);
8206 Set_Depends_On_Private
(Full_Der
, Has_Private_Component
(Full_Der
));
8207 Set_Is_Public
(Full_Der
, Is_Public
(Derived_Type
));
8209 -- The convention on the base type may be set in the private part
8210 -- and not propagated to the subtype until later, so we obtain the
8211 -- convention from the base type of the parent.
8213 Set_Convention
(Full_Der
, Convention
(Base_Type
(Full_Parent
)));
8216 -- Start of processing for Build_Derived_Private_Type
8219 if Is_Tagged_Type
(Parent_Type
) then
8220 Full_P
:= Full_View
(Parent_Type
);
8222 -- A type extension of a type with unknown discriminants is an
8223 -- indefinite type that the back-end cannot handle directly.
8224 -- We treat it as a private type, and build a completion that is
8225 -- derived from the full view of the parent, and hopefully has
8226 -- known discriminants.
8228 -- If the full view of the parent type has an underlying record view,
8229 -- use it to generate the underlying record view of this derived type
8230 -- (required for chains of derivations with unknown discriminants).
8232 -- Minor optimization: we avoid the generation of useless underlying
8233 -- record view entities if the private type declaration has unknown
8234 -- discriminants but its corresponding full view has no
8237 if Has_Unknown_Discriminants
(Parent_Type
)
8238 and then Present
(Full_P
)
8239 and then (Has_Discriminants
(Full_P
)
8240 or else Present
(Underlying_Record_View
(Full_P
)))
8241 and then not In_Open_Scopes
(Par_Scope
)
8242 and then Expander_Active
8245 Full_Der
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
8246 New_Ext
: constant Node_Id
:=
8248 (Record_Extension_Part
(Type_Definition
(N
)));
8252 Build_Derived_Record_Type
8253 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8255 -- Build anonymous completion, as a derivation from the full
8256 -- view of the parent. This is not a completion in the usual
8257 -- sense, because the current type is not private.
8260 Make_Full_Type_Declaration
(Loc
,
8261 Defining_Identifier
=> Full_Der
,
8263 Make_Derived_Type_Definition
(Loc
,
8264 Subtype_Indication
=>
8266 (Subtype_Indication
(Type_Definition
(N
))),
8267 Record_Extension_Part
=> New_Ext
));
8269 -- If the parent type has an underlying record view, use it
8270 -- here to build the new underlying record view.
8272 if Present
(Underlying_Record_View
(Full_P
)) then
8274 (Nkind
(Subtype_Indication
(Type_Definition
(Decl
)))
8276 Set_Entity
(Subtype_Indication
(Type_Definition
(Decl
)),
8277 Underlying_Record_View
(Full_P
));
8280 Install_Private_Declarations
(Par_Scope
);
8281 Install_Visible_Declarations
(Par_Scope
);
8282 Insert_Before
(N
, Decl
);
8284 -- Mark entity as an underlying record view before analysis,
8285 -- to avoid generating the list of its primitive operations
8286 -- (which is not really required for this entity) and thus
8287 -- prevent spurious errors associated with missing overriding
8288 -- of abstract primitives (overridden only for Derived_Type).
8290 Mutate_Ekind
(Full_Der
, E_Record_Type
);
8291 Set_Is_Underlying_Record_View
(Full_Der
);
8292 Set_Default_SSO
(Full_Der
);
8293 Set_No_Reordering
(Full_Der
, No_Component_Reordering
);
8297 pragma Assert
(Has_Discriminants
(Full_Der
)
8298 and then not Has_Unknown_Discriminants
(Full_Der
));
8300 Uninstall_Declarations
(Par_Scope
);
8302 -- Freeze the underlying record view, to prevent generation of
8303 -- useless dispatching information, which is simply shared with
8304 -- the real derived type.
8306 Set_Is_Frozen
(Full_Der
);
8308 -- If the derived type has access discriminants, create
8309 -- references to their anonymous types now, to prevent
8310 -- back-end problems when their first use is in generated
8311 -- bodies of primitives.
8317 E
:= First_Entity
(Full_Der
);
8319 while Present
(E
) loop
8320 if Ekind
(E
) = E_Discriminant
8321 and then Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
8323 Build_Itype_Reference
(Etype
(E
), Decl
);
8330 -- Set up links between real entity and underlying record view
8332 Set_Underlying_Record_View
(Derived_Type
, Base_Type
(Full_Der
));
8333 Set_Underlying_Record_View
(Base_Type
(Full_Der
), Derived_Type
);
8336 -- If discriminants are known, build derived record
8339 Build_Derived_Record_Type
8340 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8345 elsif Has_Discriminants
(Parent_Type
) then
8347 -- Build partial view of derived type from partial view of parent.
8348 -- This must be done before building the full derivation because the
8349 -- second derivation will modify the discriminants of the first and
8350 -- the discriminants are chained with the rest of the components in
8351 -- the full derivation.
8353 Build_Derived_Record_Type
8354 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
8356 -- Build the full derivation if this is not the anonymous derived
8357 -- base type created by Build_Derived_Record_Type in the constrained
8358 -- case (see point 5. of its head comment) since we build it for the
8361 if Present
(Available_Full_View
(Parent_Type
))
8362 and then not Is_Itype
(Derived_Type
)
8365 Der_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
8367 Last_Discr
: Entity_Id
;
8370 -- If this is not a completion, construct the implicit full
8371 -- view by deriving from the full view of the parent type.
8372 -- But if this is a completion, the derived private type
8373 -- being built is a full view and the full derivation can
8374 -- only be its underlying full view.
8376 Build_Full_Derivation
;
8378 if not Is_Completion
then
8379 Set_Full_View
(Derived_Type
, Full_Der
);
8381 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8382 Set_Is_Underlying_Full_View
(Full_Der
);
8385 if not Is_Base_Type
(Derived_Type
) then
8386 Set_Full_View
(Der_Base
, Base_Type
(Full_Der
));
8389 -- Copy the discriminant list from full view to the partial
8390 -- view (base type and its subtype). Gigi requires that the
8391 -- partial and full views have the same discriminants.
8393 -- Note that since the partial view points to discriminants
8394 -- in the full view, their scope will be that of the full
8395 -- view. This might cause some front end problems and need
8398 Discr
:= First_Discriminant
(Base_Type
(Full_Der
));
8399 Set_First_Entity
(Der_Base
, Discr
);
8402 Last_Discr
:= Discr
;
8403 Next_Discriminant
(Discr
);
8404 exit when No
(Discr
);
8407 Set_Last_Entity
(Der_Base
, Last_Discr
);
8408 Set_First_Entity
(Derived_Type
, First_Entity
(Der_Base
));
8409 Set_Last_Entity
(Derived_Type
, Last_Entity
(Der_Base
));
8413 elsif Present
(Available_Full_View
(Parent_Type
))
8414 and then Has_Discriminants
(Available_Full_View
(Parent_Type
))
8416 if Has_Unknown_Discriminants
(Parent_Type
)
8417 and then Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
8418 N_Subtype_Indication
8421 ("cannot constrain type with unknown discriminants",
8422 Subtype_Indication
(Type_Definition
(N
)));
8426 -- If this is not a completion, construct the implicit full view by
8427 -- deriving from the full view of the parent type. But if this is a
8428 -- completion, the derived private type being built is a full view
8429 -- and the full derivation can only be its underlying full view.
8431 Build_Full_Derivation
;
8433 if not Is_Completion
then
8434 Set_Full_View
(Derived_Type
, Full_Der
);
8436 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8437 Set_Is_Underlying_Full_View
(Full_Der
);
8440 -- In any case, the primitive operations are inherited from the
8441 -- parent type, not from the internal full view.
8443 Set_Etype
(Base_Type
(Derived_Type
), Base_Type
(Parent_Type
));
8445 if Derive_Subps
then
8446 -- Initialize the list of primitive operations to an empty list,
8447 -- to cover tagged types as well as untagged types. For untagged
8448 -- types this is used either to analyze the call as legal when
8449 -- Extensions_Allowed is True, or to issue a better error message
8452 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
8454 Derive_Subprograms
(Parent_Type
, Derived_Type
);
8457 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
8459 (Derived_Type
, Is_Constrained
(Available_Full_View
(Parent_Type
)));
8462 -- Untagged type, No discriminants on either view
8464 if Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
8465 N_Subtype_Indication
8468 ("illegal constraint on type without discriminants", N
);
8471 if Present
(Discriminant_Specifications
(N
))
8472 and then Present
(Available_Full_View
(Parent_Type
))
8473 and then not Is_Tagged_Type
(Available_Full_View
(Parent_Type
))
8475 Error_Msg_N
("cannot add discriminants to untagged type", N
);
8478 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
8479 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
8481 Set_Is_Controlled_Active
8482 (Derived_Type
, Is_Controlled_Active
(Parent_Type
));
8484 Set_Disable_Controlled
8485 (Derived_Type
, Disable_Controlled
(Parent_Type
));
8487 Set_Has_Controlled_Component
8488 (Derived_Type
, Has_Controlled_Component
(Parent_Type
));
8490 -- Direct controlled types do not inherit Finalize_Storage_Only flag
8492 if not Is_Controlled
(Parent_Type
) then
8493 Set_Finalize_Storage_Only
8494 (Base_Type
(Derived_Type
), Finalize_Storage_Only
(Parent_Type
));
8497 -- If this is not a completion, construct the implicit full view by
8498 -- deriving from the full view of the parent type. But if this is a
8499 -- completion, the derived private type being built is a full view
8500 -- and the full derivation can only be its underlying full view.
8502 -- ??? If the parent type is untagged private and its completion is
8503 -- tagged, this mechanism will not work because we cannot derive from
8504 -- the tagged full view unless we have an extension.
8506 if Present
(Available_Full_View
(Parent_Type
))
8507 and then not Is_Tagged_Type
(Available_Full_View
(Parent_Type
))
8508 and then not Error_Posted
(N
)
8510 Build_Full_Derivation
;
8512 if not Is_Completion
then
8513 Set_Full_View
(Derived_Type
, Full_Der
);
8515 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8516 Set_Is_Underlying_Full_View
(Full_Der
);
8521 Set_Has_Unknown_Discriminants
(Derived_Type
,
8522 Has_Unknown_Discriminants
(Parent_Type
));
8524 if Is_Private_Type
(Derived_Type
) then
8525 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
8528 -- If the parent base type is in scope, add the derived type to its
8529 -- list of private dependents, because its full view may become
8530 -- visible subsequently (in a nested private part, a body, or in a
8531 -- further child unit).
8533 if Is_Private_Type
(Par_Base
) and then In_Open_Scopes
(Par_Scope
) then
8534 Append_Elmt
(Derived_Type
, Private_Dependents
(Parent_Type
));
8536 -- Check for unusual case where a type completed by a private
8537 -- derivation occurs within a package nested in a child unit, and
8538 -- the parent is declared in an ancestor.
8540 if Is_Child_Unit
(Scope
(Current_Scope
))
8541 and then Is_Completion
8542 and then In_Private_Part
(Current_Scope
)
8543 and then Scope
(Parent_Type
) /= Current_Scope
8545 -- Note that if the parent has a completion in the private part,
8546 -- (which is itself a derivation from some other private type)
8547 -- it is that completion that is visible, there is no full view
8548 -- available, and no special processing is needed.
8550 and then Present
(Full_View
(Parent_Type
))
8552 -- In this case, the full view of the parent type will become
8553 -- visible in the body of the enclosing child, and only then will
8554 -- the current type be possibly non-private. Build an underlying
8555 -- full view that will be installed when the enclosing child body
8558 if Present
(Underlying_Full_View
(Derived_Type
)) then
8559 Full_Der
:= Underlying_Full_View
(Derived_Type
);
8561 Build_Full_Derivation
;
8562 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
8563 Set_Is_Underlying_Full_View
(Full_Der
);
8566 -- The full view will be used to swap entities on entry/exit to
8567 -- the body, and must appear in the entity list for the package.
8569 Append_Entity
(Full_Der
, Scope
(Derived_Type
));
8572 end Build_Derived_Private_Type
;
8574 -------------------------------
8575 -- Build_Derived_Record_Type --
8576 -------------------------------
8580 -- Ideally we would like to use the same model of type derivation for
8581 -- tagged and untagged record types. Unfortunately this is not quite
8582 -- possible because the semantics of representation clauses is different
8583 -- for tagged and untagged records under inheritance. Consider the
8586 -- type R (...) is [tagged] record ... end record;
8587 -- type T (...) is new R (...) [with ...];
8589 -- The representation clauses for T can specify a completely different
8590 -- record layout from R's. Hence the same component can be placed in two
8591 -- very different positions in objects of type T and R. If R and T are
8592 -- tagged types, representation clauses for T can only specify the layout
8593 -- of non inherited components, thus components that are common in R and T
8594 -- have the same position in objects of type R and T.
8596 -- This has two implications. The first is that the entire tree for R's
8597 -- declaration needs to be copied for T in the untagged case, so that T
8598 -- can be viewed as a record type of its own with its own representation
8599 -- clauses. The second implication is the way we handle discriminants.
8600 -- Specifically, in the untagged case we need a way to communicate to Gigi
8601 -- what are the real discriminants in the record, while for the semantics
8602 -- we need to consider those introduced by the user to rename the
8603 -- discriminants in the parent type. This is handled by introducing the
8604 -- notion of stored discriminants. See below for more.
8606 -- Fortunately the way regular components are inherited can be handled in
8607 -- the same way in tagged and untagged types.
8609 -- To complicate things a bit more the private view of a private extension
8610 -- cannot be handled in the same way as the full view (for one thing the
8611 -- semantic rules are somewhat different). We will explain what differs
8614 -- 2. DISCRIMINANTS UNDER INHERITANCE
8616 -- The semantic rules governing the discriminants of derived types are
8619 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
8620 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
8622 -- If parent type has discriminants, then the discriminants that are
8623 -- declared in the derived type are [3.4 (11)]:
8625 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
8628 -- o Otherwise, each discriminant of the parent type (implicitly declared
8629 -- in the same order with the same specifications). In this case, the
8630 -- discriminants are said to be "inherited", or if unknown in the parent
8631 -- are also unknown in the derived type.
8633 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
8635 -- o The parent subtype must be constrained;
8637 -- o If the parent type is not a tagged type, then each discriminant of
8638 -- the derived type must be used in the constraint defining a parent
8639 -- subtype. [Implementation note: This ensures that the new discriminant
8640 -- can share storage with an existing discriminant.]
8642 -- For the derived type each discriminant of the parent type is either
8643 -- inherited, constrained to equal some new discriminant of the derived
8644 -- type, or constrained to the value of an expression.
8646 -- When inherited or constrained to equal some new discriminant, the
8647 -- parent discriminant and the discriminant of the derived type are said
8650 -- If a discriminant of the parent type is constrained to a specific value
8651 -- in the derived type definition, then the discriminant is said to be
8652 -- "specified" by that derived type definition.
8654 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
8656 -- We have spoken about stored discriminants in point 1 (introduction)
8657 -- above. There are two sorts of stored discriminants: implicit and
8658 -- explicit. As long as the derived type inherits the same discriminants as
8659 -- the root record type, stored discriminants are the same as regular
8660 -- discriminants, and are said to be implicit. However, if any discriminant
8661 -- in the root type was renamed in the derived type, then the derived
8662 -- type will contain explicit stored discriminants. Explicit stored
8663 -- discriminants are discriminants in addition to the semantically visible
8664 -- discriminants defined for the derived type. Stored discriminants are
8665 -- used by Gigi to figure out what are the physical discriminants in
8666 -- objects of the derived type (see precise definition in einfo.ads).
8667 -- As an example, consider the following:
8669 -- type R (D1, D2, D3 : Int) is record ... end record;
8670 -- type T1 is new R;
8671 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
8672 -- type T3 is new T2;
8673 -- type T4 (Y : Int) is new T3 (Y, 99);
8675 -- The following table summarizes the discriminants and stored
8676 -- discriminants in R and T1 through T4:
8678 -- Type Discrim Stored Discrim Comment
8679 -- R (D1, D2, D3) (D1, D2, D3) Stored discrims implicit in R
8680 -- T1 (D1, D2, D3) (D1, D2, D3) Stored discrims implicit in T1
8681 -- T2 (X1, X2) (D1, D2, D3) Stored discrims EXPLICIT in T2
8682 -- T3 (X1, X2) (D1, D2, D3) Stored discrims EXPLICIT in T3
8683 -- T4 (Y) (D1, D2, D3) Stored discrims EXPLICIT in T4
8685 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
8686 -- find the corresponding discriminant in the parent type, while
8687 -- Original_Record_Component (abbreviated ORC below) the actual physical
8688 -- component that is renamed. Finally the field Is_Completely_Hidden
8689 -- (abbreviated ICH below) is set for all explicit stored discriminants
8690 -- (see einfo.ads for more info). For the above example this gives:
8692 -- Discrim CD ORC ICH
8693 -- ^^^^^^^ ^^ ^^^ ^^^
8694 -- D1 in R empty itself no
8695 -- D2 in R empty itself no
8696 -- D3 in R empty itself no
8698 -- D1 in T1 D1 in R itself no
8699 -- D2 in T1 D2 in R itself no
8700 -- D3 in T1 D3 in R itself no
8702 -- X1 in T2 D3 in T1 D3 in T2 no
8703 -- X2 in T2 D1 in T1 D1 in T2 no
8704 -- D1 in T2 empty itself yes
8705 -- D2 in T2 empty itself yes
8706 -- D3 in T2 empty itself yes
8708 -- X1 in T3 X1 in T2 D3 in T3 no
8709 -- X2 in T3 X2 in T2 D1 in T3 no
8710 -- D1 in T3 empty itself yes
8711 -- D2 in T3 empty itself yes
8712 -- D3 in T3 empty itself yes
8714 -- Y in T4 X1 in T3 D3 in T4 no
8715 -- D1 in T4 empty itself yes
8716 -- D2 in T4 empty itself yes
8717 -- D3 in T4 empty itself yes
8719 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
8721 -- Type derivation for tagged types is fairly straightforward. If no
8722 -- discriminants are specified by the derived type, these are inherited
8723 -- from the parent. No explicit stored discriminants are ever necessary.
8724 -- The only manipulation that is done to the tree is that of adding a
8725 -- _parent field with parent type and constrained to the same constraint
8726 -- specified for the parent in the derived type definition. For instance:
8728 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
8729 -- type T1 is new R with null record;
8730 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
8732 -- are changed into:
8734 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
8735 -- _parent : R (D1, D2, D3);
8738 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
8739 -- _parent : T1 (X2, 88, X1);
8742 -- The discriminants actually present in R, T1 and T2 as well as their CD,
8743 -- ORC and ICH fields are:
8745 -- Discrim CD ORC ICH
8746 -- ^^^^^^^ ^^ ^^^ ^^^
8747 -- D1 in R empty itself no
8748 -- D2 in R empty itself no
8749 -- D3 in R empty itself no
8751 -- D1 in T1 D1 in R D1 in R no
8752 -- D2 in T1 D2 in R D2 in R no
8753 -- D3 in T1 D3 in R D3 in R no
8755 -- X1 in T2 D3 in T1 D3 in R no
8756 -- X2 in T2 D1 in T1 D1 in R no
8758 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
8760 -- Regardless of whether we are dealing with a tagged or untagged type
8761 -- we will transform all derived type declarations of the form
8763 -- type T is new R (...) [with ...];
8765 -- subtype S is R (...);
8766 -- type T is new S [with ...];
8768 -- type BT is new R [with ...];
8769 -- subtype T is BT (...);
8771 -- That is, the base derived type is constrained only if it has no
8772 -- discriminants. The reason for doing this is that GNAT's semantic model
8773 -- assumes that a base type with discriminants is unconstrained.
8775 -- Note that, strictly speaking, the above transformation is not always
8776 -- correct. Consider for instance the following excerpt from ACVC b34011a:
8778 -- procedure B34011A is
8779 -- type REC (D : integer := 0) is record
8784 -- type T6 is new Rec;
8785 -- function F return T6;
8790 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
8793 -- The definition of Q6.U is illegal. However transforming Q6.U into
8795 -- type BaseU is new T6;
8796 -- subtype U is BaseU (Q6.F.I)
8798 -- turns U into a legal subtype, which is incorrect. To avoid this problem
8799 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
8800 -- the transformation described above.
8802 -- There is another instance where the above transformation is incorrect.
8806 -- type Base (D : Integer) is tagged null record;
8807 -- procedure P (X : Base);
8809 -- type Der is new Base (2) with null record;
8810 -- procedure P (X : Der);
8813 -- Then the above transformation turns this into
8815 -- type Der_Base is new Base with null record;
8816 -- -- procedure P (X : Base) is implicitly inherited here
8817 -- -- as procedure P (X : Der_Base).
8819 -- subtype Der is Der_Base (2);
8820 -- procedure P (X : Der);
8821 -- -- The overriding of P (X : Der_Base) is illegal since we
8822 -- -- have a parameter conformance problem.
8824 -- To get around this problem, after having semantically processed Der_Base
8825 -- and the rewritten subtype declaration for Der, we copy Der_Base field
8826 -- Discriminant_Constraint from Der so that when parameter conformance is
8827 -- checked when P is overridden, no semantic errors are flagged.
8829 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
8831 -- Regardless of whether we are dealing with a tagged or untagged type
8832 -- we will transform all derived type declarations of the form
8834 -- type R (D1, .., Dn : ...) is [tagged] record ...;
8835 -- type T is new R [with ...];
8837 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
8839 -- The reason for such transformation is that it allows us to implement a
8840 -- very clean form of component inheritance as explained below.
8842 -- Note that this transformation is not achieved by direct tree rewriting
8843 -- and manipulation, but rather by redoing the semantic actions that the
8844 -- above transformation will entail. This is done directly in routine
8845 -- Inherit_Components.
8847 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
8849 -- In both tagged and untagged derived types, regular non discriminant
8850 -- components are inherited in the derived type from the parent type. In
8851 -- the absence of discriminants component, inheritance is straightforward
8852 -- as components can simply be copied from the parent.
8854 -- If the parent has discriminants, inheriting components constrained with
8855 -- these discriminants requires caution. Consider the following example:
8857 -- type R (D1, D2 : Positive) is [tagged] record
8858 -- S : String (D1 .. D2);
8861 -- type T1 is new R [with null record];
8862 -- type T2 (X : positive) is new R (1, X) [with null record];
8864 -- As explained in 6. above, T1 is rewritten as
8865 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
8866 -- which makes the treatment for T1 and T2 identical.
8868 -- What we want when inheriting S, is that references to D1 and D2 in R are
8869 -- replaced with references to their correct constraints, i.e. D1 and D2 in
8870 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
8871 -- with either discriminant references in the derived type or expressions.
8872 -- This replacement is achieved as follows: before inheriting R's
8873 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
8874 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
8875 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
8876 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
8877 -- by String (1 .. X).
8879 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
8881 -- We explain here the rules governing private type extensions relevant to
8882 -- type derivation. These rules are explained on the following example:
8884 -- type D [(...)] is new A [(...)] with private; <-- partial view
8885 -- type D [(...)] is new P [(...)] with null record; <-- full view
8887 -- Type A is called the ancestor subtype of the private extension.
8888 -- Type P is the parent type of the full view of the private extension. It
8889 -- must be A or a type derived from A.
8891 -- The rules concerning the discriminants of private type extensions are
8894 -- o If a private extension inherits known discriminants from the ancestor
8895 -- subtype, then the full view must also inherit its discriminants from
8896 -- the ancestor subtype and the parent subtype of the full view must be
8897 -- constrained if and only if the ancestor subtype is constrained.
8899 -- o If a partial view has unknown discriminants, then the full view may
8900 -- define a definite or an indefinite subtype, with or without
8903 -- o If a partial view has neither known nor unknown discriminants, then
8904 -- the full view must define a definite subtype.
8906 -- o If the ancestor subtype of a private extension has constrained
8907 -- discriminants, then the parent subtype of the full view must impose a
8908 -- statically matching constraint on those discriminants.
8910 -- This means that only the following forms of private extensions are
8913 -- type D is new A with private; <-- partial view
8914 -- type D is new P with null record; <-- full view
8916 -- If A has no discriminants than P has no discriminants, otherwise P must
8917 -- inherit A's discriminants.
8919 -- type D is new A (...) with private; <-- partial view
8920 -- type D is new P (:::) with null record; <-- full view
8922 -- P must inherit A's discriminants and (...) and (:::) must statically
8925 -- subtype A is R (...);
8926 -- type D is new A with private; <-- partial view
8927 -- type D is new P with null record; <-- full view
8929 -- P must have inherited R's discriminants and must be derived from A or
8930 -- any of its subtypes.
8932 -- type D (..) is new A with private; <-- partial view
8933 -- type D (..) is new P [(:::)] with null record; <-- full view
8935 -- No specific constraints on P's discriminants or constraint (:::).
8936 -- Note that A can be unconstrained, but the parent subtype P must either
8937 -- be constrained or (:::) must be present.
8939 -- type D (..) is new A [(...)] with private; <-- partial view
8940 -- type D (..) is new P [(:::)] with null record; <-- full view
8942 -- P's constraints on A's discriminants must statically match those
8943 -- imposed by (...).
8945 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
8947 -- The full view of a private extension is handled exactly as described
8948 -- above. The model chose for the private view of a private extension is
8949 -- the same for what concerns discriminants (i.e. they receive the same
8950 -- treatment as in the tagged case). However, the private view of the
8951 -- private extension always inherits the components of the parent base,
8952 -- without replacing any discriminant reference. Strictly speaking this is
8953 -- incorrect. However, Gigi never uses this view to generate code so this
8954 -- is a purely semantic issue. In theory, a set of transformations similar
8955 -- to those given in 5. and 6. above could be applied to private views of
8956 -- private extensions to have the same model of component inheritance as
8957 -- for non private extensions. However, this is not done because it would
8958 -- further complicate private type processing. Semantically speaking, this
8959 -- leaves us in an uncomfortable situation. As an example consider:
8962 -- type R (D : integer) is tagged record
8963 -- S : String (1 .. D);
8965 -- procedure P (X : R);
8966 -- type T is new R (1) with private;
8968 -- type T is new R (1) with null record;
8971 -- This is transformed into:
8974 -- type R (D : integer) is tagged record
8975 -- S : String (1 .. D);
8977 -- procedure P (X : R);
8978 -- type T is new R (1) with private;
8980 -- type BaseT is new R with null record;
8981 -- subtype T is BaseT (1);
8984 -- (strictly speaking the above is incorrect Ada)
8986 -- From the semantic standpoint the private view of private extension T
8987 -- should be flagged as constrained since one can clearly have
8991 -- in a unit withing Pack. However, when deriving subprograms for the
8992 -- private view of private extension T, T must be seen as unconstrained
8993 -- since T has discriminants (this is a constraint of the current
8994 -- subprogram derivation model). Thus, when processing the private view of
8995 -- a private extension such as T, we first mark T as unconstrained, we
8996 -- process it, we perform program derivation and just before returning from
8997 -- Build_Derived_Record_Type we mark T as constrained.
8999 -- ??? Are there are other uncomfortable cases that we will have to
9002 -- 10. RECORD_TYPE_WITH_PRIVATE complications
9004 -- Types that are derived from a visible record type and have a private
9005 -- extension present other peculiarities. They behave mostly like private
9006 -- types, but if they have primitive operations defined, these will not
9007 -- have the proper signatures for further inheritance, because other
9008 -- primitive operations will use the implicit base that we define for
9009 -- private derivations below. This affect subprogram inheritance (see
9010 -- Derive_Subprograms for details). We also derive the implicit base from
9011 -- the base type of the full view, so that the implicit base is a record
9012 -- type and not another private type, This avoids infinite loops.
9014 procedure Build_Derived_Record_Type
9016 Parent_Type
: Entity_Id
;
9017 Derived_Type
: Entity_Id
;
9018 Derive_Subps
: Boolean := True)
9020 Discriminant_Specs
: constant Boolean :=
9021 Present
(Discriminant_Specifications
(N
));
9022 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Parent_Type
);
9023 Loc
: constant Source_Ptr
:= Sloc
(N
);
9024 Private_Extension
: constant Boolean :=
9025 Nkind
(N
) = N_Private_Extension_Declaration
;
9026 Assoc_List
: Elist_Id
;
9027 Constraint_Present
: Boolean;
9029 Discrim
: Entity_Id
;
9031 Inherit_Discrims
: Boolean := False;
9032 Last_Discrim
: Entity_Id
;
9033 New_Base
: Entity_Id
;
9035 New_Discrs
: Elist_Id
;
9036 New_Indic
: Node_Id
;
9037 Parent_Base
: Entity_Id
;
9038 Save_Etype
: Entity_Id
;
9039 Save_Discr_Constr
: Elist_Id
;
9040 Save_Next_Entity
: Entity_Id
;
9043 Discs
: Elist_Id
:= New_Elmt_List
;
9044 -- An empty Discs list means that there were no constraints in the
9045 -- subtype indication or that there was an error processing it.
9047 procedure Check_Generic_Ancestors
;
9048 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
9049 -- cannot be declared at a deeper level than its parent type is
9050 -- removed. The check on derivation within a generic body is also
9051 -- relaxed, but there's a restriction that a derived tagged type
9052 -- cannot be declared in a generic body if it's derived directly
9053 -- or indirectly from a formal type of that generic. This applies
9054 -- to progenitors as well.
9056 -----------------------------
9057 -- Check_Generic_Ancestors --
9058 -----------------------------
9060 procedure Check_Generic_Ancestors
is
9061 Ancestor_Type
: Entity_Id
;
9062 Intf_List
: List_Id
;
9063 Intf_Name
: Node_Id
;
9065 procedure Check_Ancestor
;
9066 -- For parent and progenitors.
9068 --------------------
9069 -- Check_Ancestor --
9070 --------------------
9072 procedure Check_Ancestor
is
9074 -- If the derived type does have a formal type as an ancestor
9075 -- then it's an error if the derived type is declared within
9076 -- the body of the generic unit that declares the formal type
9077 -- in its generic formal part. It's sufficient to check whether
9078 -- the ancestor type is declared inside the same generic body
9079 -- as the derived type (such as within a nested generic spec),
9080 -- in which case the derivation is legal. If the formal type is
9081 -- declared outside of that generic body, then it's certain
9082 -- that the derived type is declared within the generic body
9083 -- of the generic unit declaring the formal type.
9085 if Is_Generic_Type
(Ancestor_Type
)
9086 and then Enclosing_Generic_Body
(Ancestor_Type
) /=
9087 Enclosing_Generic_Body
(Derived_Type
)
9090 ("ancestor type& is formal type of enclosing"
9091 & " generic unit (RM 3.9.1 (4/2))",
9092 Indic
, Ancestor_Type
);
9097 if Nkind
(N
) = N_Private_Extension_Declaration
then
9098 Intf_List
:= Interface_List
(N
);
9100 Intf_List
:= Interface_List
(Type_Definition
(N
));
9103 if Present
(Enclosing_Generic_Body
(Derived_Type
)) then
9104 Ancestor_Type
:= Parent_Type
;
9106 while not Is_Generic_Type
(Ancestor_Type
)
9107 and then Etype
(Ancestor_Type
) /= Ancestor_Type
9109 Ancestor_Type
:= Etype
(Ancestor_Type
);
9114 if Present
(Intf_List
) then
9115 Intf_Name
:= First
(Intf_List
);
9116 while Present
(Intf_Name
) loop
9117 Ancestor_Type
:= Entity
(Intf_Name
);
9123 end Check_Generic_Ancestors
;
9125 -- Start of processing for Build_Derived_Record_Type
9128 -- If the parent type is a private extension with discriminants, we
9129 -- need to have an unconstrained type on which to apply the inherited
9130 -- constraint, so we get to the full view. However, this means that the
9131 -- derived type and its implicit base type created below will not point
9132 -- to the same view of their respective parent type and, thus, special
9133 -- glue code like Exp_Ch7.Convert_View is needed to bridge this gap.
9135 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
9136 and then Has_Discriminants
(Parent_Type
)
9137 and then Present
(Full_View
(Parent_Type
))
9139 Parent_Base
:= Base_Type
(Full_View
(Parent_Type
));
9141 Parent_Base
:= Base_Type
(Parent_Type
);
9144 -- If the parent type is declared as a subtype of another private
9145 -- type with inherited discriminants, its generated base type is
9146 -- itself a record subtype. To further inherit the constraint we
9147 -- need to use its own base to have an unconstrained type on which
9148 -- to apply the inherited constraint.
9150 if Ekind
(Parent_Base
) = E_Record_Subtype
then
9151 Parent_Base
:= Base_Type
(Parent_Base
);
9154 -- If the parent base is a private type and only its full view has
9155 -- discriminants, use the full view's base type.
9157 -- This can happen when we are deriving from a subtype of a derived type
9158 -- of a private type derived from a discriminated type with known
9162 -- type Root_Type(I: Positive) is record
9165 -- type Bounded_Root_Type is private;
9167 -- type Bounded_Root_Type is new Root_Type(10);
9171 -- type Constrained_Root_Type is new Pkg.Bounded_Root_Type;
9173 -- subtype Sub_Base is Pkg2.Constrained_Root_Type;
9174 -- type New_Der_Type is new Sub_Base;
9176 if Is_Private_Type
(Parent_Base
)
9177 and then Present
(Full_View
(Parent_Base
))
9178 and then not Has_Discriminants
(Parent_Base
)
9179 and then Has_Discriminants
(Full_View
(Parent_Base
))
9181 Parent_Base
:= Base_Type
(Full_View
(Parent_Base
));
9184 -- AI05-0115: if this is a derivation from a private type in some
9185 -- other scope that may lead to invisible components for the derived
9186 -- type, mark it accordingly.
9188 if Is_Private_Type
(Parent_Type
) then
9189 if Scope
(Parent_Base
) = Scope
(Derived_Type
) then
9192 elsif In_Open_Scopes
(Scope
(Parent_Base
))
9193 and then In_Private_Part
(Scope
(Parent_Base
))
9198 Set_Has_Private_Ancestor
(Derived_Type
);
9202 Set_Has_Private_Ancestor
9203 (Derived_Type
, Has_Private_Ancestor
(Parent_Type
));
9206 -- Before we start the previously documented transformations, here is
9207 -- little fix for size and alignment of tagged types. Normally when we
9208 -- derive type D from type P, we copy the size and alignment of P as the
9209 -- default for D, and in the absence of explicit representation clauses
9210 -- for D, the size and alignment are indeed the same as the parent.
9212 -- But this is wrong for tagged types, since fields may be added, and
9213 -- the default size may need to be larger, and the default alignment may
9214 -- need to be larger.
9216 -- We therefore reset the size and alignment fields in the tagged case.
9217 -- Note that the size and alignment will in any case be at least as
9218 -- large as the parent type (since the derived type has a copy of the
9219 -- parent type in the _parent field)
9221 -- The type is also marked as being tagged here, which is needed when
9222 -- processing components with a self-referential anonymous access type
9223 -- in the call to Check_Anonymous_Access_Components below. Note that
9224 -- this flag is also set later on for completeness.
9227 Set_Is_Tagged_Type
(Derived_Type
);
9228 Reinit_Size_Align
(Derived_Type
);
9231 -- STEP 0a: figure out what kind of derived type declaration we have
9233 if Private_Extension
then
9235 Mutate_Ekind
(Derived_Type
, E_Record_Type_With_Private
);
9236 Set_Default_SSO
(Derived_Type
);
9237 Set_No_Reordering
(Derived_Type
, No_Component_Reordering
);
9240 Type_Def
:= Type_Definition
(N
);
9242 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
9243 -- Parent_Base can be a private type or private extension. However,
9244 -- for tagged types with an extension the newly added fields are
9245 -- visible and hence the Derived_Type is always an E_Record_Type.
9246 -- (except that the parent may have its own private fields).
9247 -- For untagged types we preserve the Ekind of the Parent_Base.
9249 if Present
(Record_Extension_Part
(Type_Def
)) then
9250 Mutate_Ekind
(Derived_Type
, E_Record_Type
);
9251 Set_Default_SSO
(Derived_Type
);
9252 Set_No_Reordering
(Derived_Type
, No_Component_Reordering
);
9254 -- Create internal access types for components with anonymous
9257 if Ada_Version
>= Ada_2005
then
9258 Check_Anonymous_Access_Components
9259 (N
, Derived_Type
, Derived_Type
,
9260 Component_List
(Record_Extension_Part
(Type_Def
)));
9264 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
9268 -- Indic can either be an N_Identifier if the subtype indication
9269 -- contains no constraint or an N_Subtype_Indication if the subtype
9270 -- indication has a constraint. In either case it can include an
9273 Indic
:= Subtype_Indication
(Type_Def
);
9274 Constraint_Present
:= (Nkind
(Indic
) = N_Subtype_Indication
);
9276 -- Check that the type has visible discriminants. The type may be
9277 -- a private type with unknown discriminants whose full view has
9278 -- discriminants which are invisible.
9280 if Constraint_Present
then
9281 if not Has_Discriminants
(Parent_Base
)
9283 (Has_Unknown_Discriminants
(Parent_Base
)
9284 and then Is_Private_Type
(Parent_Base
))
9287 ("invalid constraint: type has no discriminant",
9288 Constraint
(Indic
));
9290 Constraint_Present
:= False;
9291 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
9293 elsif Is_Constrained
(Parent_Type
) then
9295 ("invalid constraint: parent type is already constrained",
9296 Constraint
(Indic
));
9298 Constraint_Present
:= False;
9299 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
9303 -- STEP 0b: If needed, apply transformation given in point 5. above
9305 if not Private_Extension
9306 and then Has_Discriminants
(Parent_Type
)
9307 and then not Discriminant_Specs
9308 and then (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
9310 -- First, we must analyze the constraint (see comment in point 5.)
9311 -- The constraint may come from the subtype indication of the full
9312 -- declaration. Temporarily set the state of the Derived_Type to
9313 -- "self-hidden" (see RM-8.3(17)).
9315 if Constraint_Present
then
9316 pragma Assert
(Is_Not_Self_Hidden
(Derived_Type
));
9317 Set_Is_Not_Self_Hidden
(Derived_Type
, False);
9318 New_Discrs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
9319 Set_Is_Not_Self_Hidden
(Derived_Type
);
9321 -- If there is no explicit constraint, there might be one that is
9322 -- inherited from a constrained parent type. In that case verify that
9323 -- it conforms to the constraint in the partial view. In perverse
9324 -- cases the parent subtypes of the partial and full view can have
9325 -- different constraints.
9327 elsif Present
(Stored_Constraint
(Parent_Type
)) then
9328 New_Discrs
:= Stored_Constraint
(Parent_Type
);
9331 New_Discrs
:= No_Elist
;
9334 if Has_Discriminants
(Derived_Type
)
9335 and then Has_Private_Declaration
(Derived_Type
)
9336 and then Present
(Discriminant_Constraint
(Derived_Type
))
9337 and then Present
(New_Discrs
)
9339 -- Verify that constraints of the full view statically match
9340 -- those given in the partial view.
9346 C1
:= First_Elmt
(New_Discrs
);
9347 C2
:= First_Elmt
(Discriminant_Constraint
(Derived_Type
));
9348 while Present
(C1
) and then Present
(C2
) loop
9349 if Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
9351 (Is_OK_Static_Expression
(Node
(C1
))
9352 and then Is_OK_Static_Expression
(Node
(C2
))
9354 Expr_Value
(Node
(C1
)) = Expr_Value
(Node
(C2
)))
9359 if Constraint_Present
then
9361 ("constraint not conformant to previous declaration",
9365 ("constraint of full view is incompatible "
9366 & "with partial view", N
);
9376 -- Insert and analyze the declaration for the unconstrained base type
9378 New_Base
:= Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
9381 Make_Full_Type_Declaration
(Loc
,
9382 Defining_Identifier
=> New_Base
,
9384 Make_Derived_Type_Definition
(Loc
,
9385 Abstract_Present
=> Abstract_Present
(Type_Def
),
9386 Limited_Present
=> Limited_Present
(Type_Def
),
9387 Subtype_Indication
=>
9388 New_Occurrence_Of
(Parent_Base
, Loc
),
9389 Record_Extension_Part
=>
9390 Relocate_Node
(Record_Extension_Part
(Type_Def
)),
9391 Interface_List
=> Interface_List
(Type_Def
)));
9393 Set_Parent
(New_Decl
, Parent
(N
));
9394 Mark_Rewrite_Insertion
(New_Decl
);
9395 Insert_Before
(N
, New_Decl
);
9397 -- In the extension case, make sure ancestor is frozen appropriately
9398 -- (see also non-discriminated case below).
9400 if Present
(Record_Extension_Part
(Type_Def
))
9401 or else Is_Interface
(Parent_Base
)
9403 Freeze_Before
(New_Decl
, Parent_Type
);
9406 -- Note that this call passes False for the Derive_Subps parameter
9407 -- because subprogram derivation is deferred until after creating
9408 -- the subtype (see below).
9411 (New_Decl
, Parent_Base
, New_Base
,
9412 Is_Completion
=> False, Derive_Subps
=> False);
9414 -- ??? This needs re-examination to determine whether the
9415 -- following call can simply be replaced by a call to Analyze.
9417 Set_Analyzed
(New_Decl
);
9419 -- Insert and analyze the declaration for the constrained subtype
9421 if Constraint_Present
then
9423 Make_Subtype_Indication
(Loc
,
9424 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
9425 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
9429 Constr_List
: constant List_Id
:= New_List
;
9434 C
:= First_Elmt
(Discriminant_Constraint
(Parent_Type
));
9435 while Present
(C
) loop
9438 -- It is safe here to call New_Copy_Tree since we called
9439 -- Force_Evaluation on each constraint previously
9440 -- in Build_Discriminant_Constraints.
9442 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
9448 Make_Subtype_Indication
(Loc
,
9449 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
9451 Make_Index_Or_Discriminant_Constraint
(Loc
, Constr_List
));
9456 Make_Subtype_Declaration
(Loc
,
9457 Defining_Identifier
=> Derived_Type
,
9458 Subtype_Indication
=> New_Indic
));
9460 -- Keep the aspects from the original node
9462 Move_Aspects
(Original_Node
(N
), N
);
9466 -- Derivation of subprograms must be delayed until the full subtype
9467 -- has been established, to ensure proper overriding of subprograms
9468 -- inherited by full types. If the derivations occurred as part of
9469 -- the call to Build_Derived_Type above, then the check for type
9470 -- conformance would fail because earlier primitive subprograms
9471 -- could still refer to the full type prior the change to the new
9472 -- subtype and hence would not match the new base type created here.
9473 -- Subprograms are not derived, however, when Derive_Subps is False
9474 -- (since otherwise there could be redundant derivations).
9476 if Derive_Subps
then
9477 Derive_Subprograms
(Parent_Type
, Derived_Type
);
9480 -- For tagged types the Discriminant_Constraint of the new base itype
9481 -- is inherited from the first subtype so that no subtype conformance
9482 -- problem arise when the first subtype overrides primitive
9483 -- operations inherited by the implicit base type.
9486 Set_Discriminant_Constraint
9487 (New_Base
, Discriminant_Constraint
(Derived_Type
));
9493 -- If we get here Derived_Type will have no discriminants or it will be
9494 -- a discriminated unconstrained base type.
9496 -- STEP 1a: perform preliminary actions/checks for derived tagged types
9500 -- The parent type is frozen for non-private extensions (RM 13.14(7))
9501 -- The declaration of a specific descendant of an interface type
9502 -- freezes the interface type (RM 13.14).
9504 if not Private_Extension
or else Is_Interface
(Parent_Base
) then
9505 Freeze_Before
(N
, Parent_Type
);
9508 if Ada_Version
>= Ada_2005
then
9509 Check_Generic_Ancestors
;
9511 elsif Type_Access_Level
(Derived_Type
) /=
9512 Type_Access_Level
(Parent_Type
)
9513 and then not Is_Generic_Type
(Derived_Type
)
9515 if Is_Controlled
(Parent_Type
) then
9517 ("controlled type must be declared at the library level",
9521 ("type extension at deeper accessibility level than parent",
9527 GB
: constant Node_Id
:= Enclosing_Generic_Body
(Derived_Type
);
9530 and then GB
/= Enclosing_Generic_Body
(Parent_Base
)
9533 ("parent type of& must not be outside generic body"
9535 Indic
, Derived_Type
);
9541 -- Ada 2005 (AI-251)
9543 if Ada_Version
>= Ada_2005
and then Is_Tagged
then
9545 -- "The declaration of a specific descendant of an interface type
9546 -- freezes the interface type" (RM 13.14).
9551 Iface
:= First
(Interface_List
(Type_Def
));
9552 while Present
(Iface
) loop
9553 Freeze_Before
(N
, Etype
(Iface
));
9559 -- STEP 1b : preliminary cleanup of the full view of private types
9561 -- If the type is already marked as having discriminants, then it's the
9562 -- completion of a private type or private extension and we need to
9563 -- retain the discriminants from the partial view if the current
9564 -- declaration has Discriminant_Specifications so that we can verify
9565 -- conformance. However, we must remove any existing components that
9566 -- were inherited from the parent (and attached in Copy_And_Swap)
9567 -- because the full type inherits all appropriate components anyway, and
9568 -- we do not want the partial view's components interfering.
9570 if Has_Discriminants
(Derived_Type
) and then Discriminant_Specs
then
9571 Discrim
:= First_Discriminant
(Derived_Type
);
9573 Last_Discrim
:= Discrim
;
9574 Next_Discriminant
(Discrim
);
9575 exit when No
(Discrim
);
9578 Set_Last_Entity
(Derived_Type
, Last_Discrim
);
9580 -- In all other cases wipe out the list of inherited components (even
9581 -- inherited discriminants), it will be properly rebuilt here.
9584 Set_First_Entity
(Derived_Type
, Empty
);
9585 Set_Last_Entity
(Derived_Type
, Empty
);
9588 -- STEP 1c: Initialize some flags for the Derived_Type
9590 -- The following flags must be initialized here so that
9591 -- Process_Discriminants can check that discriminants of tagged types do
9592 -- not have a default initial value and that access discriminants are
9593 -- only specified for limited records. For completeness, these flags are
9594 -- also initialized along with all the other flags below.
9596 -- AI-419: Limitedness is not inherited from an interface parent, so to
9597 -- be limited in that case the type must be explicitly declared as
9598 -- limited, or synchronized. While task and protected interfaces are
9599 -- always limited, a synchronized private extension might not inherit
9600 -- from such interfaces, and so we also need to recognize the
9601 -- explicit limitedness implied by a synchronized private extension
9602 -- that does not derive from a synchronized interface (see RM-7.3(6/2)).
9604 if Limited_Present
(Type_Def
)
9605 or else Synchronized_Present
(Type_Def
)
9607 Set_Is_Limited_Record
(Derived_Type
);
9609 elsif Is_Limited_Record
(Parent_Type
)
9610 or else (Present
(Full_View
(Parent_Type
))
9611 and then Is_Limited_Record
(Full_View
(Parent_Type
)))
9613 if not Is_Interface
(Parent_Type
)
9614 or else Is_Concurrent_Interface
(Parent_Type
)
9616 Set_Is_Limited_Record
(Derived_Type
);
9620 -- STEP 2a: process discriminants of derived type if any
9622 Push_Scope
(Derived_Type
);
9624 if Discriminant_Specs
then
9625 Set_Has_Unknown_Discriminants
(Derived_Type
, False);
9627 -- The following call to Check_Or_Process_Discriminants initializes
9628 -- fields Has_Discriminants and Discriminant_Constraint, unless we
9629 -- are processing the completion of a private type declaration.
9630 -- Temporarily set the state of the Derived_Type to "self-hidden"
9631 -- (see RM-8.3(17)), unless it is already the case.
9633 if Is_Not_Self_Hidden
(Derived_Type
) then
9634 Set_Is_Not_Self_Hidden
(Derived_Type
, False);
9635 Check_Or_Process_Discriminants
(N
, Derived_Type
);
9636 Set_Is_Not_Self_Hidden
(Derived_Type
);
9638 Check_Or_Process_Discriminants
(N
, Derived_Type
);
9641 -- For untagged types, the constraint on the Parent_Type must be
9642 -- present and is used to rename the discriminants.
9644 if not Is_Tagged
and then not Has_Discriminants
(Parent_Type
) then
9645 Error_Msg_N
("untagged parent must have discriminants", Indic
);
9647 elsif not Is_Tagged
and then not Constraint_Present
then
9649 ("discriminant constraint needed for derived untagged records",
9652 -- Otherwise the parent subtype must be constrained unless we have a
9653 -- private extension.
9655 elsif not Constraint_Present
9656 and then not Private_Extension
9657 and then not Is_Constrained
(Parent_Type
)
9660 ("unconstrained type not allowed in this context", Indic
);
9662 elsif Constraint_Present
then
9663 -- The following call sets the field Corresponding_Discriminant
9664 -- for the discriminants in the Derived_Type.
9666 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
, True);
9668 -- For untagged types all new discriminants must rename
9669 -- discriminants in the parent. For private extensions new
9670 -- discriminants cannot rename old ones (implied by [7.3(13)]).
9672 Discrim
:= First_Discriminant
(Derived_Type
);
9673 while Present
(Discrim
) loop
9675 and then No
(Corresponding_Discriminant
(Discrim
))
9678 ("new discriminants must constrain old ones", Discrim
);
9680 elsif Private_Extension
9681 and then Present
(Corresponding_Discriminant
(Discrim
))
9684 ("only static constraints allowed for parent"
9685 & " discriminants in the partial view", Indic
);
9689 -- If a new discriminant is used in the constraint, then its
9690 -- subtype must be statically compatible with the subtype of
9691 -- the parent discriminant (RM 3.7(15)).
9693 if Present
(Corresponding_Discriminant
(Discrim
)) then
9694 Check_Constraining_Discriminant
9695 (Discrim
, Corresponding_Discriminant
(Discrim
));
9698 Next_Discriminant
(Discrim
);
9701 -- Check whether the constraints of the full view statically
9702 -- match those imposed by the parent subtype [7.3(13)].
9704 if Present
(Stored_Constraint
(Derived_Type
)) then
9709 C1
:= First_Elmt
(Discs
);
9710 C2
:= First_Elmt
(Stored_Constraint
(Derived_Type
));
9711 while Present
(C1
) and then Present
(C2
) loop
9713 Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
9716 ("not conformant with previous declaration",
9727 -- STEP 2b: No new discriminants, inherit discriminants if any
9730 if Private_Extension
then
9731 Set_Has_Unknown_Discriminants
9733 Has_Unknown_Discriminants
(Parent_Type
)
9734 or else Unknown_Discriminants_Present
(N
));
9736 -- The partial view of the parent may have unknown discriminants,
9737 -- but if the full view has discriminants and the parent type is
9738 -- in scope they must be inherited.
9740 elsif Has_Unknown_Discriminants
(Parent_Type
)
9742 (not Has_Discriminants
(Parent_Type
)
9743 or else not In_Open_Scopes
(Scope
(Parent_Base
)))
9745 Set_Has_Unknown_Discriminants
(Derived_Type
);
9748 if not Has_Unknown_Discriminants
(Derived_Type
)
9749 and then not Has_Unknown_Discriminants
(Parent_Base
)
9750 and then Has_Discriminants
(Parent_Type
)
9752 Inherit_Discrims
:= True;
9753 Set_Has_Discriminants
9754 (Derived_Type
, True);
9755 Set_Discriminant_Constraint
9756 (Derived_Type
, Discriminant_Constraint
(Parent_Base
));
9759 -- The following test is true for private types (remember
9760 -- transformation 5. is not applied to those) and in an error
9763 if Constraint_Present
then
9764 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
9767 -- For now mark a new derived type as constrained only if it has no
9768 -- discriminants. At the end of Build_Derived_Record_Type we properly
9769 -- set this flag in the case of private extensions. See comments in
9770 -- point 9. just before body of Build_Derived_Record_Type.
9774 not (Inherit_Discrims
9775 or else Has_Unknown_Discriminants
(Derived_Type
)));
9778 -- STEP 3: initialize fields of derived type
9780 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged
);
9781 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
9783 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
9784 -- but cannot be interfaces
9786 if not Private_Extension
9787 and then Ekind
(Derived_Type
) /= E_Private_Type
9788 and then Ekind
(Derived_Type
) /= E_Limited_Private_Type
9790 if Interface_Present
(Type_Def
) then
9791 Analyze_Interface_Declaration
(Derived_Type
, Type_Def
);
9794 Set_Interfaces
(Derived_Type
, No_Elist
);
9797 -- Fields inherited from the Parent_Type
9799 Set_Has_Specified_Layout
9800 (Derived_Type
, Has_Specified_Layout
(Parent_Type
));
9801 Set_Is_Limited_Composite
9802 (Derived_Type
, Is_Limited_Composite
(Parent_Type
));
9803 Set_Is_Private_Composite
9804 (Derived_Type
, Is_Private_Composite
(Parent_Type
));
9806 if Is_Tagged_Type
(Parent_Type
) then
9807 Set_No_Tagged_Streams_Pragma
9808 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
9811 -- Fields inherited from the Parent_Base
9813 Set_Has_Controlled_Component
9814 (Derived_Type
, Has_Controlled_Component
(Parent_Base
));
9815 Set_Has_Non_Standard_Rep
9816 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
9817 Set_Has_Primitive_Operations
9818 (Derived_Type
, Has_Primitive_Operations
(Parent_Base
));
9820 -- Set fields for private derived types
9822 if Is_Private_Type
(Derived_Type
) then
9823 Set_Depends_On_Private
(Derived_Type
, True);
9824 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
9827 -- Inherit fields for non-private types. If this is the completion of a
9828 -- derivation from a private type, the parent itself is private and the
9829 -- attributes come from its full view, which must be present.
9831 if Is_Record_Type
(Derived_Type
) then
9833 Parent_Full
: Entity_Id
;
9836 if Is_Private_Type
(Parent_Base
)
9837 and then not Is_Record_Type
(Parent_Base
)
9839 Parent_Full
:= Full_View
(Parent_Base
);
9841 Parent_Full
:= Parent_Base
;
9844 Set_Component_Alignment
9845 (Derived_Type
, Component_Alignment
(Parent_Full
));
9847 (Derived_Type
, C_Pass_By_Copy
(Parent_Full
));
9848 Set_Has_Complex_Representation
9849 (Derived_Type
, Has_Complex_Representation
(Parent_Full
));
9851 -- For untagged types, inherit the layout by default to avoid
9852 -- costly changes of representation for type conversions.
9854 if not Is_Tagged
then
9855 Set_Is_Packed
(Derived_Type
, Is_Packed
(Parent_Full
));
9856 Set_No_Reordering
(Derived_Type
, No_Reordering
(Parent_Full
));
9861 -- Initialize the list of primitive operations to an empty list,
9862 -- to cover tagged types as well as untagged types. For untagged
9863 -- types this is used either to analyze the call as legal when
9864 -- Extensions_Allowed is True, or to issue a better error message
9867 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
9869 -- Set fields for tagged types
9872 -- All tagged types defined in Ada.Finalization are controlled
9874 if Chars
(Scope
(Derived_Type
)) = Name_Finalization
9875 and then Chars
(Scope
(Scope
(Derived_Type
))) = Name_Ada
9876 and then Scope
(Scope
(Scope
(Derived_Type
))) = Standard_Standard
9878 Set_Is_Controlled_Active
(Derived_Type
);
9880 Set_Is_Controlled_Active
9881 (Derived_Type
, Is_Controlled_Active
(Parent_Base
));
9884 -- Minor optimization: there is no need to generate the class-wide
9885 -- entity associated with an underlying record view.
9887 if not Is_Underlying_Record_View
(Derived_Type
) then
9888 Make_Class_Wide_Type
(Derived_Type
);
9891 Set_Is_Abstract_Type
(Derived_Type
, Abstract_Present
(Type_Def
));
9893 if Has_Discriminants
(Derived_Type
)
9894 and then Constraint_Present
9896 Set_Stored_Constraint
9897 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Base
, Discs
));
9900 if Ada_Version
>= Ada_2005
then
9902 Ifaces_List
: Elist_Id
;
9905 -- Checks rules 3.9.4 (13/2 and 14/2)
9907 if Comes_From_Source
(Derived_Type
)
9908 and then not Is_Private_Type
(Derived_Type
)
9909 and then Is_Interface
(Parent_Type
)
9910 and then not Is_Interface
(Derived_Type
)
9912 if Is_Task_Interface
(Parent_Type
) then
9914 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
9917 elsif Is_Protected_Interface
(Parent_Type
) then
9919 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
9924 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
9926 Check_Interfaces
(N
, Type_Def
);
9928 -- Ada 2005 (AI-251): Collect the list of progenitors that are
9929 -- not already in the parents.
9933 Ifaces_List
=> Ifaces_List
,
9934 Exclude_Parents
=> True);
9936 Set_Interfaces
(Derived_Type
, Ifaces_List
);
9938 -- If the derived type is the anonymous type created for
9939 -- a declaration whose parent has a constraint, propagate
9940 -- the interface list to the source type. This must be done
9941 -- prior to the completion of the analysis of the source type
9942 -- because the components in the extension may contain current
9943 -- instances whose legality depends on some ancestor.
9945 if Is_Itype
(Derived_Type
) then
9947 Def
: constant Node_Id
:=
9948 Associated_Node_For_Itype
(Derived_Type
);
9951 and then Nkind
(Def
) = N_Full_Type_Declaration
9954 (Defining_Identifier
(Def
), Ifaces_List
);
9959 -- A type extension is automatically Ghost when one of its
9960 -- progenitors is Ghost (SPARK RM 6.9(9)). This property is
9961 -- also inherited when the parent type is Ghost, but this is
9962 -- done in Build_Derived_Type as the mechanism also handles
9963 -- untagged derivations.
9965 if Implements_Ghost_Interface
(Derived_Type
) then
9966 Set_Is_Ghost_Entity
(Derived_Type
);
9972 -- STEP 4: Inherit components from the parent base and constrain them.
9973 -- Apply the second transformation described in point 6. above.
9975 if (not Is_Empty_Elmt_List
(Discs
) or else Inherit_Discrims
)
9976 or else not Has_Discriminants
(Parent_Type
)
9977 or else not Is_Constrained
(Parent_Type
)
9981 Constrs
:= Discriminant_Constraint
(Parent_Type
);
9986 (N
, Parent_Base
, Derived_Type
, Is_Tagged
, Inherit_Discrims
, Constrs
);
9988 -- STEP 5a: Copy the parent record declaration for untagged types
9990 Set_Has_Implicit_Dereference
9991 (Derived_Type
, Has_Implicit_Dereference
(Parent_Type
));
9993 if not Is_Tagged
then
9995 -- Discriminant_Constraint (Derived_Type) has been properly
9996 -- constructed. Save it and temporarily set it to Empty because we
9997 -- do not want the call to New_Copy_Tree below to mess this list.
9999 if Has_Discriminants
(Derived_Type
) then
10000 Save_Discr_Constr
:= Discriminant_Constraint
(Derived_Type
);
10001 Set_Discriminant_Constraint
(Derived_Type
, No_Elist
);
10003 Save_Discr_Constr
:= No_Elist
;
10006 -- Save the Etype field of Derived_Type. It is correctly set now,
10007 -- but the call to New_Copy tree may remap it to point to itself,
10008 -- which is not what we want. Ditto for the Next_Entity field.
10010 Save_Etype
:= Etype
(Derived_Type
);
10011 Save_Next_Entity
:= Next_Entity
(Derived_Type
);
10013 -- Assoc_List maps all stored discriminants in the Parent_Base to
10014 -- stored discriminants in the Derived_Type. It is fundamental that
10015 -- no types or itypes with discriminants other than the stored
10016 -- discriminants appear in the entities declared inside
10017 -- Derived_Type, since the back end cannot deal with it.
10021 (Parent
(Parent_Base
), Map
=> Assoc_List
, New_Sloc
=> Loc
);
10022 Copy_Dimensions_Of_Components
(Derived_Type
);
10024 -- Restore the fields saved prior to the New_Copy_Tree call
10025 -- and compute the stored constraint.
10027 Set_Etype
(Derived_Type
, Save_Etype
);
10028 Link_Entities
(Derived_Type
, Save_Next_Entity
);
10030 if Has_Discriminants
(Derived_Type
) then
10031 Set_Discriminant_Constraint
10032 (Derived_Type
, Save_Discr_Constr
);
10033 Set_Stored_Constraint
10034 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Type
, Discs
));
10036 Replace_Discriminants
(Derived_Type
, New_Decl
);
10039 -- Relocate the aspects from the original type
10041 Remove_Aspects
(New_Decl
);
10042 Move_Aspects
(N
, New_Decl
);
10044 -- Insert the new derived type declaration
10046 Rewrite
(N
, New_Decl
);
10048 -- STEP 5b: Complete the processing for record extensions in generics
10050 -- There is no completion for record extensions declared in the
10051 -- parameter part of a generic, so we need to complete processing for
10052 -- these generic record extensions here. Record_Type_Definition will
10053 -- set the Is_Not_Self_Hidden flag.
10055 elsif Private_Extension
and then Is_Generic_Type
(Derived_Type
) then
10056 Record_Type_Definition
(Empty
, Derived_Type
);
10058 -- STEP 5c: Process the record extension for non private tagged types
10060 elsif not Private_Extension
then
10061 Expand_Record_Extension
(Derived_Type
, Type_Def
);
10063 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
10064 -- implemented interfaces if we are in expansion mode
10067 and then Has_Interfaces
(Derived_Type
)
10069 Add_Interface_Tag_Components
(N
, Derived_Type
);
10072 -- Analyze the record extension
10074 Record_Type_Definition
10075 (Record_Extension_Part
(Type_Def
), Derived_Type
);
10080 -- Nothing else to do if there is an error in the derivation.
10081 -- An unusual case: the full view may be derived from a type in an
10082 -- instance, when the partial view was used illegally as an actual
10083 -- in that instance, leading to a circular definition.
10085 if Etype
(Derived_Type
) = Any_Type
10086 or else Etype
(Parent_Type
) = Derived_Type
10091 -- Set delayed freeze and then derive subprograms, we need to do
10092 -- this in this order so that derived subprograms inherit the
10093 -- derived freeze if necessary.
10095 Set_Has_Delayed_Freeze
(Derived_Type
);
10097 if Derive_Subps
then
10098 Derive_Subprograms
(Parent_Type
, Derived_Type
);
10101 -- If we have a private extension which defines a constrained derived
10102 -- type mark as constrained here after we have derived subprograms. See
10103 -- comment on point 9. just above the body of Build_Derived_Record_Type.
10105 if Private_Extension
and then Inherit_Discrims
then
10106 if Constraint_Present
and then not Is_Empty_Elmt_List
(Discs
) then
10107 Set_Is_Constrained
(Derived_Type
, True);
10108 Set_Discriminant_Constraint
(Derived_Type
, Discs
);
10110 elsif Is_Constrained
(Parent_Type
) then
10112 (Derived_Type
, True);
10113 Set_Discriminant_Constraint
10114 (Derived_Type
, Discriminant_Constraint
(Parent_Type
));
10118 -- Update the class-wide type, which shares the now-completed entity
10119 -- list with its specific type. In case of underlying record views,
10120 -- we do not generate the corresponding class wide entity.
10123 and then not Is_Underlying_Record_View
(Derived_Type
)
10126 (Class_Wide_Type
(Derived_Type
), First_Entity
(Derived_Type
));
10128 (Class_Wide_Type
(Derived_Type
), Last_Entity
(Derived_Type
));
10131 Check_Function_Writable_Actuals
(N
);
10132 end Build_Derived_Record_Type
;
10134 ------------------------
10135 -- Build_Derived_Type --
10136 ------------------------
10138 procedure Build_Derived_Type
10140 Parent_Type
: Entity_Id
;
10141 Derived_Type
: Entity_Id
;
10142 Is_Completion
: Boolean;
10143 Derive_Subps
: Boolean := True)
10145 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
10148 -- Set common attributes
10150 if Ekind
(Derived_Type
) in Incomplete_Or_Private_Kind
10151 and then Ekind
(Parent_Base
) in Elementary_Kind
10153 Reinit_Field_To_Zero
(Derived_Type
, F_Discriminant_Constraint
);
10156 Set_Scope
(Derived_Type
, Current_Scope
);
10157 Set_Etype
(Derived_Type
, Parent_Base
);
10158 Mutate_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
10159 Propagate_Concurrent_Flags
(Derived_Type
, Parent_Base
);
10161 Set_Size_Info
(Derived_Type
, Parent_Type
);
10162 Copy_RM_Size
(To
=> Derived_Type
, From
=> Parent_Type
);
10164 Set_Is_Controlled_Active
10165 (Derived_Type
, Is_Controlled_Active
(Parent_Type
));
10167 Set_Disable_Controlled
(Derived_Type
, Disable_Controlled
(Parent_Type
));
10168 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged_Type
(Parent_Type
));
10169 Set_Is_Volatile
(Derived_Type
, Is_Volatile
(Parent_Type
));
10171 if Is_Tagged_Type
(Derived_Type
) then
10172 Set_No_Tagged_Streams_Pragma
10173 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
10176 -- If the parent has primitive routines and may have not-seen-yet aspect
10177 -- specifications (e.g., a Pack pragma), then set the derived type link
10178 -- in order to later diagnose "early derivation" issues. If in different
10179 -- compilation units, then "early derivation" cannot be an issue (and we
10180 -- don't like interunit references that go in the opposite direction of
10181 -- semantic dependencies).
10183 if Has_Primitive_Operations
(Parent_Type
)
10184 and then Enclosing_Comp_Unit_Node
(Parent_Type
) =
10185 Enclosing_Comp_Unit_Node
(Derived_Type
)
10187 Set_Derived_Type_Link
(Parent_Base
, Derived_Type
);
10190 -- If the parent type is a private subtype, the convention on the base
10191 -- type may be set in the private part, and not propagated to the
10192 -- subtype until later, so we obtain the convention from the base type.
10194 Set_Convention
(Derived_Type
, Convention
(Parent_Base
));
10196 if Is_Tagged_Type
(Derived_Type
)
10197 and then Present
(Class_Wide_Type
(Derived_Type
))
10199 Set_Convention
(Class_Wide_Type
(Derived_Type
),
10200 Convention
(Class_Wide_Type
(Parent_Base
)));
10203 -- Set SSO default for record or array type
10205 if (Is_Array_Type
(Derived_Type
) or else Is_Record_Type
(Derived_Type
))
10206 and then Is_Base_Type
(Derived_Type
)
10208 Set_Default_SSO
(Derived_Type
);
10211 -- A derived type inherits the Default_Initial_Condition pragma coming
10212 -- from any parent type within the derivation chain.
10214 if Has_DIC
(Parent_Type
) then
10215 Set_Has_Inherited_DIC
(Derived_Type
);
10218 -- A derived type inherits any class-wide invariants coming from a
10219 -- parent type or an interface. Note that the invariant procedure of
10220 -- the parent type should not be inherited because the derived type may
10221 -- define invariants of its own.
10223 if not Is_Interface
(Derived_Type
) then
10224 if Has_Inherited_Invariants
(Parent_Type
)
10225 or else Has_Inheritable_Invariants
(Parent_Type
)
10227 Set_Has_Inherited_Invariants
(Derived_Type
);
10229 elsif Is_Concurrent_Type
(Derived_Type
)
10230 or else Is_Tagged_Type
(Derived_Type
)
10235 Iface_Elmt
: Elmt_Id
;
10239 (T
=> Derived_Type
,
10240 Ifaces_List
=> Ifaces
,
10241 Exclude_Parents
=> True);
10243 if Present
(Ifaces
) then
10244 Iface_Elmt
:= First_Elmt
(Ifaces
);
10245 while Present
(Iface_Elmt
) loop
10246 Iface
:= Node
(Iface_Elmt
);
10248 if Has_Inheritable_Invariants
(Iface
) then
10249 Set_Has_Inherited_Invariants
(Derived_Type
);
10253 Next_Elmt
(Iface_Elmt
);
10260 -- We similarly inherit predicates
10262 Inherit_Predicate_Flags
(Derived_Type
, Parent_Type
, Only_Flags
=> True);
10264 -- The derived type inherits representation clauses from the parent
10265 -- type, and from any interfaces.
10267 Inherit_Rep_Item_Chain
(Derived_Type
, Parent_Type
);
10270 Iface
: Node_Id
:= First
(Abstract_Interface_List
(Derived_Type
));
10272 while Present
(Iface
) loop
10273 Inherit_Rep_Item_Chain
(Derived_Type
, Entity
(Iface
));
10278 -- If the parent type has delayed rep aspects, then mark the derived
10279 -- type as possibly inheriting a delayed rep aspect.
10281 if Has_Delayed_Rep_Aspects
(Parent_Type
) then
10282 Set_May_Inherit_Delayed_Rep_Aspects
(Derived_Type
);
10285 -- A derived type becomes Ghost when its parent type is also Ghost
10286 -- (SPARK RM 6.9(9)). Note that the Ghost-related attributes are not
10287 -- directly inherited because the Ghost policy in effect may differ.
10289 if Is_Ghost_Entity
(Parent_Type
) then
10290 Set_Is_Ghost_Entity
(Derived_Type
);
10293 -- Type dependent processing
10295 case Ekind
(Parent_Type
) is
10296 when Numeric_Kind
=>
10297 Build_Derived_Numeric_Type
(N
, Parent_Type
, Derived_Type
);
10300 Build_Derived_Array_Type
(N
, Parent_Type
, Derived_Type
);
10302 when Class_Wide_Kind
10306 Build_Derived_Record_Type
10307 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
10310 when Enumeration_Kind
=>
10311 Build_Derived_Enumeration_Type
(N
, Parent_Type
, Derived_Type
);
10313 when Access_Kind
=>
10314 Build_Derived_Access_Type
(N
, Parent_Type
, Derived_Type
);
10316 when Incomplete_Or_Private_Kind
=>
10317 Build_Derived_Private_Type
10318 (N
, Parent_Type
, Derived_Type
, Is_Completion
, Derive_Subps
);
10320 -- For discriminated types, the derivation includes deriving
10321 -- primitive operations. For others it is done below.
10323 if Is_Tagged_Type
(Parent_Type
)
10324 or else Has_Discriminants
(Parent_Type
)
10325 or else (Present
(Full_View
(Parent_Type
))
10326 and then Has_Discriminants
(Full_View
(Parent_Type
)))
10331 when Concurrent_Kind
=>
10332 Build_Derived_Concurrent_Type
(N
, Parent_Type
, Derived_Type
);
10335 raise Program_Error
;
10338 -- Nothing more to do if some error occurred
10340 if Etype
(Derived_Type
) = Any_Type
then
10344 -- If not already set, initialize the derived type's list of primitive
10345 -- operations to an empty element list.
10347 if No
(Direct_Primitive_Operations
(Derived_Type
)) then
10348 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
10350 -- If Etype of the derived type is the base type (as opposed to
10351 -- a parent type) and doesn't have an associated list of primitive
10352 -- operations, then set the base type's primitive list to the
10353 -- derived type's list. The lists need to be shared in common
10354 -- between the two.
10356 if Etype
(Derived_Type
) = Base_Type
(Derived_Type
)
10357 and then No
(Direct_Primitive_Operations
(Etype
(Derived_Type
)))
10359 Set_Direct_Primitive_Operations
10360 (Etype
(Derived_Type
),
10361 Direct_Primitive_Operations
(Derived_Type
));
10365 -- Set delayed freeze and then derive subprograms, we need to do this
10366 -- in this order so that derived subprograms inherit the derived freeze
10369 Set_Has_Delayed_Freeze
(Derived_Type
);
10371 if Derive_Subps
then
10372 Derive_Subprograms
(Parent_Type
, Derived_Type
);
10375 Set_Has_Primitive_Operations
10376 (Base_Type
(Derived_Type
), Has_Primitive_Operations
(Parent_Type
));
10377 end Build_Derived_Type
;
10379 -----------------------
10380 -- Build_Discriminal --
10381 -----------------------
10383 procedure Build_Discriminal
(Discrim
: Entity_Id
) is
10384 D_Minal
: Entity_Id
;
10385 CR_Disc
: Entity_Id
;
10388 -- A discriminal has the same name as the discriminant
10390 D_Minal
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
10392 Mutate_Ekind
(D_Minal
, E_In_Parameter
);
10393 Set_Mechanism
(D_Minal
, Default_Mechanism
);
10394 Set_Etype
(D_Minal
, Etype
(Discrim
));
10395 Set_Scope
(D_Minal
, Current_Scope
);
10396 Set_Parent
(D_Minal
, Parent
(Discrim
));
10398 Set_Discriminal
(Discrim
, D_Minal
);
10399 Set_Discriminal_Link
(D_Minal
, Discrim
);
10401 -- For task types, build at once the discriminants of the corresponding
10402 -- record, which are needed if discriminants are used in entry defaults
10403 -- and in family bounds.
10405 if Is_Concurrent_Type
(Current_Scope
)
10407 Is_Limited_Type
(Current_Scope
)
10409 CR_Disc
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
10411 Mutate_Ekind
(CR_Disc
, E_In_Parameter
);
10412 Set_Mechanism
(CR_Disc
, Default_Mechanism
);
10413 Set_Etype
(CR_Disc
, Etype
(Discrim
));
10414 Set_Scope
(CR_Disc
, Current_Scope
);
10415 Set_Discriminal_Link
(CR_Disc
, Discrim
);
10416 Set_CR_Discriminant
(Discrim
, CR_Disc
);
10418 end Build_Discriminal
;
10420 ------------------------------------
10421 -- Build_Discriminant_Constraints --
10422 ------------------------------------
10424 function Build_Discriminant_Constraints
10427 Derived_Def
: Boolean := False) return Elist_Id
10429 C
: constant Node_Id
:= Constraint
(Def
);
10430 Nb_Discr
: constant Nat
:= Number_Discriminants
(T
);
10432 Discr_Expr
: array (1 .. Nb_Discr
) of Node_Id
:= (others => Empty
);
10433 -- Saves the expression corresponding to a given discriminant in T
10435 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
;
10436 -- Return the Position number within array Discr_Expr of a discriminant
10437 -- D within the discriminant list of the discriminated type T.
10439 procedure Process_Discriminant_Expression
10442 -- If this is a discriminant constraint on a partial view, do not
10443 -- generate an overflow check on the discriminant expression. The check
10444 -- will be generated when constraining the full view. Otherwise the
10445 -- backend creates duplicate symbols for the temporaries corresponding
10446 -- to the expressions to be checked, causing spurious assembler errors.
10452 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
is
10456 Disc
:= First_Discriminant
(T
);
10457 for J
in Discr_Expr
'Range loop
10462 Next_Discriminant
(Disc
);
10465 -- Note: Since this function is called on discriminants that are
10466 -- known to belong to the discriminated type, falling through the
10467 -- loop with no match signals an internal compiler error.
10469 raise Program_Error
;
10472 -------------------------------------
10473 -- Process_Discriminant_Expression --
10474 -------------------------------------
10476 procedure Process_Discriminant_Expression
10480 BDT
: constant Entity_Id
:= Base_Type
(Etype
(D
));
10483 -- If this is a discriminant constraint on a partial view, do
10484 -- not generate an overflow on the discriminant expression. The
10485 -- check will be generated when constraining the full view.
10487 if Is_Private_Type
(T
)
10488 and then Present
(Full_View
(T
))
10490 Analyze_And_Resolve
(Expr
, BDT
, Suppress
=> Overflow_Check
);
10492 Analyze_And_Resolve
(Expr
, BDT
);
10494 end Process_Discriminant_Expression
;
10496 -- Declarations local to Build_Discriminant_Constraints
10500 Elist
: constant Elist_Id
:= New_Elmt_List
;
10508 Discrim_Present
: Boolean := False;
10510 -- Start of processing for Build_Discriminant_Constraints
10513 -- The following loop will process positional associations only.
10514 -- For a positional association, the (single) discriminant is
10515 -- implicitly specified by position, in textual order (RM 3.7.2).
10517 Discr
:= First_Discriminant
(T
);
10518 Constr
:= First
(Constraints
(C
));
10519 for D
in Discr_Expr
'Range loop
10520 exit when Nkind
(Constr
) = N_Discriminant_Association
;
10522 if No
(Constr
) then
10523 Error_Msg_N
("too few discriminants given in constraint", C
);
10524 return New_Elmt_List
;
10526 elsif Nkind
(Constr
) = N_Range
10527 or else (Nkind
(Constr
) = N_Attribute_Reference
10528 and then Attribute_Name
(Constr
) = Name_Range
)
10531 ("a range is not a valid discriminant constraint", Constr
);
10532 Discr_Expr
(D
) := Error
;
10534 elsif Nkind
(Constr
) = N_Subtype_Indication
then
10536 ("a subtype indication is not a valid discriminant constraint",
10538 Discr_Expr
(D
) := Error
;
10541 Process_Discriminant_Expression
(Constr
, Discr
);
10542 Discr_Expr
(D
) := Constr
;
10545 Next_Discriminant
(Discr
);
10549 if No
(Discr
) and then Present
(Constr
) then
10550 Error_Msg_N
("too many discriminants given in constraint", Constr
);
10551 return New_Elmt_List
;
10554 -- Named associations can be given in any order, but if both positional
10555 -- and named associations are used in the same discriminant constraint,
10556 -- then positional associations must occur first, at their normal
10557 -- position. Hence once a named association is used, the rest of the
10558 -- discriminant constraint must use only named associations.
10560 while Present
(Constr
) loop
10562 -- Positional association forbidden after a named association
10564 if Nkind
(Constr
) /= N_Discriminant_Association
then
10565 Error_Msg_N
("positional association follows named one", Constr
);
10566 return New_Elmt_List
;
10568 -- Otherwise it is a named association
10571 -- E records the type of the discriminants in the named
10572 -- association. All the discriminants specified in the same name
10573 -- association must have the same type.
10577 -- Search the list of discriminants in T to see if the simple name
10578 -- given in the constraint matches any of them.
10580 Id
:= First
(Selector_Names
(Constr
));
10581 while Present
(Id
) loop
10584 -- If Original_Discriminant is present, we are processing a
10585 -- generic instantiation and this is an instance node. We need
10586 -- to find the name of the corresponding discriminant in the
10587 -- actual record type T and not the name of the discriminant in
10588 -- the generic formal. Example:
10591 -- type G (D : int) is private;
10593 -- subtype W is G (D => 1);
10595 -- type Rec (X : int) is record ... end record;
10596 -- package Q is new P (G => Rec);
10598 -- At the point of the instantiation, formal type G is Rec
10599 -- and therefore when reanalyzing "subtype W is G (D => 1);"
10600 -- which really looks like "subtype W is Rec (D => 1);" at
10601 -- the point of instantiation, we want to find the discriminant
10602 -- that corresponds to D in Rec, i.e. X.
10604 if Present
(Original_Discriminant
(Id
))
10605 and then In_Instance
10607 Discr
:= Find_Corresponding_Discriminant
(Id
, T
);
10611 Discr
:= First_Discriminant
(T
);
10612 while Present
(Discr
) loop
10613 if Chars
(Discr
) = Chars
(Id
) then
10618 Next_Discriminant
(Discr
);
10622 Error_Msg_N
("& does not match any discriminant", Id
);
10623 return New_Elmt_List
;
10625 -- If the parent type is a generic formal, preserve the
10626 -- name of the discriminant for subsequent instances.
10627 -- see comment at the beginning of this if statement.
10629 elsif Is_Generic_Type
(Root_Type
(T
)) then
10630 Set_Original_Discriminant
(Id
, Discr
);
10634 Position
:= Pos_Of_Discr
(T
, Discr
);
10636 if Present
(Discr_Expr
(Position
)) then
10637 Error_Msg_N
("duplicate constraint for discriminant&", Id
);
10640 -- Each discriminant specified in the same named association
10641 -- must be associated with a separate copy of the
10642 -- corresponding expression.
10644 if Present
(Next
(Id
)) then
10645 Expr
:= New_Copy_Tree
(Expression
(Constr
));
10646 Set_Parent
(Expr
, Parent
(Expression
(Constr
)));
10648 Expr
:= Expression
(Constr
);
10651 Discr_Expr
(Position
) := Expr
;
10652 Process_Discriminant_Expression
(Expr
, Discr
);
10655 -- A discriminant association with more than one discriminant
10656 -- name is only allowed if the named discriminants are all of
10657 -- the same type (RM 3.7.1(8)).
10660 E
:= Base_Type
(Etype
(Discr
));
10662 elsif Base_Type
(Etype
(Discr
)) /= E
then
10664 ("all discriminants in an association " &
10665 "must have the same type", Id
);
10675 -- A discriminant constraint must provide exactly one value for each
10676 -- discriminant of the type (RM 3.7.1(8)).
10678 for J
in Discr_Expr
'Range loop
10679 if No
(Discr_Expr
(J
)) then
10680 Error_Msg_N
("too few discriminants given in constraint", C
);
10681 return New_Elmt_List
;
10685 -- Determine if there are discriminant expressions in the constraint
10687 for J
in Discr_Expr
'Range loop
10688 if Denotes_Discriminant
10689 (Discr_Expr
(J
), Check_Concurrent
=> True)
10691 Discrim_Present
:= True;
10696 -- Build an element list consisting of the expressions given in the
10697 -- discriminant constraint and apply the appropriate checks. The list
10698 -- is constructed after resolving any named discriminant associations
10699 -- and therefore the expressions appear in the textual order of the
10702 Discr
:= First_Discriminant
(T
);
10703 for J
in Discr_Expr
'Range loop
10704 if Discr_Expr
(J
) /= Error
then
10705 Append_Elmt
(Discr_Expr
(J
), Elist
);
10707 -- If any of the discriminant constraints is given by a
10708 -- discriminant and we are in a derived type declaration we
10709 -- have a discriminant renaming. Establish link between new
10710 -- and old discriminant. The new discriminant has an implicit
10711 -- dereference if the old one does.
10713 if Denotes_Discriminant
(Discr_Expr
(J
)) then
10714 if Derived_Def
then
10716 New_Discr
: constant Entity_Id
:= Entity
(Discr_Expr
(J
));
10719 Set_Corresponding_Discriminant
(New_Discr
, Discr
);
10720 Set_Has_Implicit_Dereference
(New_Discr
,
10721 Has_Implicit_Dereference
(Discr
));
10725 -- Force the evaluation of non-discriminant expressions.
10726 -- If we have found a discriminant in the constraint 3.4(26)
10727 -- and 3.8(18) demand that no range checks are performed are
10728 -- after evaluation. If the constraint is for a component
10729 -- definition that has a per-object constraint, expressions are
10730 -- evaluated but not checked either. In all other cases perform
10734 if Discrim_Present
then
10737 elsif Parent_Kind
(Parent
(Def
)) = N_Component_Declaration
10738 and then Has_Per_Object_Constraint
10739 (Defining_Identifier
(Parent
(Parent
(Def
))))
10743 elsif Is_Access_Type
(Etype
(Discr
)) then
10744 Apply_Constraint_Check
(Discr_Expr
(J
), Etype
(Discr
));
10747 Apply_Range_Check
(Discr_Expr
(J
), Etype
(Discr
));
10750 -- If the value of the discriminant may be visible in
10751 -- another unit or child unit, create an external name
10752 -- for it. We use the name of the object or component
10753 -- that carries the discriminated subtype. The code
10754 -- below may generate external symbols for the discriminant
10755 -- expression when not strictly needed, which is harmless.
10758 and then Comes_From_Source
(Def
)
10759 and then not Is_Subprogram
(Current_Scope
)
10762 Id
: Entity_Id
:= Empty
;
10764 if Nkind
(Parent
(Def
)) = N_Object_Declaration
then
10765 Id
:= Defining_Identifier
(Parent
(Def
));
10767 elsif Nkind
(Parent
(Def
)) = N_Component_Definition
10769 Nkind
(Parent
(Parent
(Def
)))
10770 = N_Component_Declaration
10772 Id
:= Defining_Identifier
(Parent
(Parent
(Def
)));
10775 if Present
(Id
) then
10779 Discr_Number
=> J
);
10781 Force_Evaluation
(Discr_Expr
(J
));
10785 Force_Evaluation
(Discr_Expr
(J
));
10789 -- Check that the designated type of an access discriminant's
10790 -- expression is not a class-wide type unless the discriminant's
10791 -- designated type is also class-wide.
10793 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
10794 and then not Is_Class_Wide_Type
10795 (Designated_Type
(Etype
(Discr
)))
10796 and then Etype
(Discr_Expr
(J
)) /= Any_Type
10797 and then Is_Class_Wide_Type
10798 (Designated_Type
(Etype
(Discr_Expr
(J
))))
10800 Wrong_Type
(Discr_Expr
(J
), Etype
(Discr
));
10802 elsif Is_Access_Type
(Etype
(Discr
))
10803 and then not Is_Access_Constant
(Etype
(Discr
))
10804 and then Is_Access_Type
(Etype
(Discr_Expr
(J
)))
10805 and then Is_Access_Constant
(Etype
(Discr_Expr
(J
)))
10808 ("constraint for discriminant& must be access to variable",
10813 Next_Discriminant
(Discr
);
10817 end Build_Discriminant_Constraints
;
10819 ---------------------------------
10820 -- Build_Discriminated_Subtype --
10821 ---------------------------------
10823 procedure Build_Discriminated_Subtype
10825 Def_Id
: Entity_Id
;
10827 Related_Nod
: Node_Id
;
10828 For_Access
: Boolean := False)
10830 Has_Discrs
: constant Boolean := Has_Discriminants
(T
);
10831 Constrained
: constant Boolean :=
10833 and then not Is_Empty_Elmt_List
(Elist
)
10834 and then not Is_Class_Wide_Type
(T
))
10835 or else Is_Constrained
(T
);
10838 if Ekind
(T
) = E_Record_Type
then
10839 Mutate_Ekind
(Def_Id
, E_Record_Subtype
);
10841 -- Inherit preelaboration flag from base, for types for which it
10842 -- may have been set: records, private types, protected types.
10844 Set_Known_To_Have_Preelab_Init
10845 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10847 elsif Ekind
(T
) = E_Task_Type
then
10848 Mutate_Ekind
(Def_Id
, E_Task_Subtype
);
10850 elsif Ekind
(T
) = E_Protected_Type
then
10851 Mutate_Ekind
(Def_Id
, E_Protected_Subtype
);
10852 Set_Known_To_Have_Preelab_Init
10853 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10855 elsif Is_Private_Type
(T
) then
10856 Mutate_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
10857 Set_Known_To_Have_Preelab_Init
10858 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
10860 -- Private subtypes may have private dependents
10862 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
10864 elsif Is_Class_Wide_Type
(T
) then
10865 Mutate_Ekind
(Def_Id
, E_Class_Wide_Subtype
);
10868 -- Incomplete type. Attach subtype to list of dependents, to be
10869 -- completed with full view of parent type, unless is it the
10870 -- designated subtype of a record component within an init_proc.
10871 -- This last case arises for a component of an access type whose
10872 -- designated type is incomplete (e.g. a Taft Amendment type).
10873 -- The designated subtype is within an inner scope, and needs no
10874 -- elaboration, because only the access type is needed in the
10875 -- initialization procedure.
10877 if Ekind
(T
) = E_Incomplete_Type
then
10878 Mutate_Ekind
(Def_Id
, E_Incomplete_Subtype
);
10880 Mutate_Ekind
(Def_Id
, Ekind
(T
));
10883 if For_Access
and then Within_Init_Proc
then
10886 Append_Elmt
(Def_Id
, Private_Dependents
(T
));
10890 Set_Etype
(Def_Id
, T
);
10891 Reinit_Size_Align
(Def_Id
);
10892 Set_Has_Discriminants
(Def_Id
, Has_Discrs
);
10893 Set_Is_Constrained
(Def_Id
, Constrained
);
10895 Set_First_Entity
(Def_Id
, First_Entity
(T
));
10896 Set_Last_Entity
(Def_Id
, Last_Entity
(T
));
10897 Set_Has_Implicit_Dereference
10898 (Def_Id
, Has_Implicit_Dereference
(T
));
10899 Set_Has_Pragma_Unreferenced_Objects
10900 (Def_Id
, Has_Pragma_Unreferenced_Objects
(T
));
10902 -- If the subtype is the completion of a private declaration, there may
10903 -- have been representation clauses for the partial view, and they must
10904 -- be preserved. Build_Derived_Type chains the inherited clauses with
10905 -- the ones appearing on the extension. If this comes from a subtype
10906 -- declaration, all clauses are inherited.
10908 if No
(First_Rep_Item
(Def_Id
)) then
10909 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
10912 if Is_Tagged_Type
(T
) then
10913 Set_Is_Tagged_Type
(Def_Id
);
10914 Set_No_Tagged_Streams_Pragma
(Def_Id
, No_Tagged_Streams_Pragma
(T
));
10915 Make_Class_Wide_Type
(Def_Id
);
10918 Set_Stored_Constraint
(Def_Id
, No_Elist
);
10921 Set_Discriminant_Constraint
(Def_Id
, Elist
);
10922 Set_Stored_Constraint_From_Discriminant_Constraint
(Def_Id
);
10925 if Is_Tagged_Type
(T
) then
10927 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
10928 -- concurrent record type (which has the list of primitive
10931 if Ada_Version
>= Ada_2005
10932 and then Is_Concurrent_Type
(T
)
10934 Set_Corresponding_Record_Type
(Def_Id
,
10935 Corresponding_Record_Type
(T
));
10937 Set_Direct_Primitive_Operations
(Def_Id
,
10938 Direct_Primitive_Operations
(T
));
10941 Set_Is_Abstract_Type
(Def_Id
, Is_Abstract_Type
(T
));
10944 -- Subtypes introduced by component declarations do not need to be
10945 -- marked as delayed, and do not get freeze nodes, because the semantics
10946 -- verifies that the parents of the subtypes are frozen before the
10947 -- enclosing record is frozen.
10949 if not Is_Type
(Scope
(Def_Id
)) then
10950 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
10952 if Is_Private_Type
(T
)
10953 and then Present
(Full_View
(T
))
10955 Conditional_Delay
(Def_Id
, Full_View
(T
));
10957 Conditional_Delay
(Def_Id
, T
);
10961 if Is_Record_Type
(T
) then
10962 Set_Is_Limited_Record
(Def_Id
, Is_Limited_Record
(T
));
10965 and then not Is_Empty_Elmt_List
(Elist
)
10966 and then not For_Access
10968 Create_Constrained_Components
(Def_Id
, Related_Nod
, T
, Elist
);
10970 elsif not Is_Private_Type
(T
) then
10971 Set_Cloned_Subtype
(Def_Id
, T
);
10974 end Build_Discriminated_Subtype
;
10976 ---------------------------
10977 -- Build_Itype_Reference --
10978 ---------------------------
10980 procedure Build_Itype_Reference
10984 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(Nod
));
10987 -- Itype references are only created for use by the back-end
10989 if Inside_A_Generic
then
10992 Set_Itype
(IR
, Ityp
);
10994 -- If Nod is a library unit entity, then Insert_After won't work,
10995 -- because Nod is not a member of any list. Therefore, we use
10996 -- Add_Global_Declaration in this case. This can happen if we have a
10997 -- build-in-place library function, child unit or not.
10999 if (Nkind
(Nod
) in N_Entity
and then Is_Compilation_Unit
(Nod
))
11000 or else (Nkind
(Nod
) in
11001 N_Defining_Program_Unit_Name | N_Subprogram_Declaration
11002 and then Is_Compilation_Unit
(Defining_Entity
(Nod
)))
11004 Add_Global_Declaration
(IR
);
11006 Insert_After
(Nod
, IR
);
11009 end Build_Itype_Reference
;
11011 ------------------------
11012 -- Build_Scalar_Bound --
11013 ------------------------
11015 function Build_Scalar_Bound
11018 Der_T
: Entity_Id
) return Node_Id
11020 New_Bound
: Entity_Id
;
11023 -- Note: not clear why this is needed, how can the original bound
11024 -- be unanalyzed at this point? and if it is, what business do we
11025 -- have messing around with it? and why is the base type of the
11026 -- parent type the right type for the resolution. It probably is
11027 -- not. It is OK for the new bound we are creating, but not for
11028 -- the old one??? Still if it never happens, no problem.
11030 Analyze_And_Resolve
(Bound
, Base_Type
(Par_T
));
11032 if Nkind
(Bound
) in N_Integer_Literal | N_Real_Literal
then
11033 New_Bound
:= New_Copy
(Bound
);
11034 Set_Etype
(New_Bound
, Der_T
);
11035 Set_Analyzed
(New_Bound
);
11037 elsif Is_Entity_Name
(Bound
) then
11038 New_Bound
:= OK_Convert_To
(Der_T
, New_Copy
(Bound
));
11040 -- The following is almost certainly wrong. What business do we have
11041 -- relocating a node (Bound) that is presumably still attached to
11042 -- the tree elsewhere???
11045 New_Bound
:= OK_Convert_To
(Der_T
, Relocate_Node
(Bound
));
11048 Set_Etype
(New_Bound
, Der_T
);
11050 end Build_Scalar_Bound
;
11052 -------------------------------
11053 -- Check_Abstract_Overriding --
11054 -------------------------------
11056 procedure Check_Abstract_Overriding
(T
: Entity_Id
) is
11057 Alias_Subp
: Entity_Id
;
11059 Op_List
: Elist_Id
;
11061 Type_Def
: Node_Id
;
11063 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
);
11064 -- Ada 2012 (AI05-0030): Subprogram Subp overrides an interface routine
11065 -- which has pragma Implemented already set. Check whether Subp's entity
11066 -- kind conforms to the implementation kind of the overridden routine.
11068 procedure Check_Pragma_Implemented
11070 Iface_Subp
: Entity_Id
);
11071 -- Ada 2012 (AI05-0030): Subprogram Subp overrides interface routine
11072 -- Iface_Subp and both entities have pragma Implemented already set on
11073 -- them. Check whether the two implementation kinds are conforming.
11075 procedure Inherit_Pragma_Implemented
11077 Iface_Subp
: Entity_Id
);
11078 -- Ada 2012 (AI05-0030): Interface primitive Subp overrides interface
11079 -- subprogram Iface_Subp which has been marked by pragma Implemented.
11080 -- Propagate the implementation kind of Iface_Subp to Subp.
11082 ------------------------------
11083 -- Check_Pragma_Implemented --
11084 ------------------------------
11086 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
) is
11087 Iface_Alias
: constant Entity_Id
:= Interface_Alias
(Subp
);
11088 Impl_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Alias
);
11089 Subp_Alias
: constant Entity_Id
:= Alias
(Subp
);
11090 Contr_Typ
: Entity_Id
;
11091 Impl_Subp
: Entity_Id
;
11094 -- Subp must have an alias since it is a hidden entity used to link
11095 -- an interface subprogram to its overriding counterpart.
11097 pragma Assert
(Present
(Subp_Alias
));
11099 -- Handle aliases to synchronized wrappers
11101 Impl_Subp
:= Subp_Alias
;
11103 if Is_Primitive_Wrapper
(Impl_Subp
) then
11104 Impl_Subp
:= Wrapped_Entity
(Impl_Subp
);
11107 -- Extract the type of the controlling formal
11109 Contr_Typ
:= Etype
(First_Formal
(Subp_Alias
));
11111 if Is_Concurrent_Record_Type
(Contr_Typ
) then
11112 Contr_Typ
:= Corresponding_Concurrent_Type
(Contr_Typ
);
11115 -- An interface subprogram whose implementation kind is By_Entry must
11116 -- be implemented by an entry.
11118 if Impl_Kind
= Name_By_Entry
11119 and then Ekind
(Impl_Subp
) /= E_Entry
11121 Error_Msg_Node_2
:= Iface_Alias
;
11123 ("type & must implement abstract subprogram & with an entry",
11124 Subp_Alias
, Contr_Typ
);
11126 elsif Impl_Kind
= Name_By_Protected_Procedure
then
11128 -- An interface subprogram whose implementation kind is By_
11129 -- Protected_Procedure cannot be implemented by a primitive
11130 -- procedure of a task type.
11132 if Ekind
(Contr_Typ
) /= E_Protected_Type
then
11133 Error_Msg_Node_2
:= Contr_Typ
;
11135 ("interface subprogram & cannot be implemented by a "
11136 & "primitive procedure of task type &",
11137 Subp_Alias
, Iface_Alias
);
11139 -- An interface subprogram whose implementation kind is By_
11140 -- Protected_Procedure must be implemented by a procedure.
11142 elsif Ekind
(Impl_Subp
) /= E_Procedure
then
11143 Error_Msg_Node_2
:= Iface_Alias
;
11145 ("type & must implement abstract subprogram & with a "
11146 & "procedure", Subp_Alias
, Contr_Typ
);
11148 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
11149 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
11151 Error_Msg_Name_1
:= Impl_Kind
;
11153 ("overriding operation& must have synchronization%",
11157 -- If primitive has Optional synchronization, overriding operation
11158 -- must match if it has an explicit synchronization.
11160 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
11161 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
11163 Error_Msg_Name_1
:= Impl_Kind
;
11165 ("overriding operation& must have synchronization%", Subp_Alias
);
11167 end Check_Pragma_Implemented
;
11169 ------------------------------
11170 -- Check_Pragma_Implemented --
11171 ------------------------------
11173 procedure Check_Pragma_Implemented
11175 Iface_Subp
: Entity_Id
)
11177 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
11178 Subp_Kind
: constant Name_Id
:= Implementation_Kind
(Subp
);
11181 -- Ada 2012 (AI05-0030): The implementation kinds of an overridden
11182 -- and overriding subprogram are different. In general this is an
11183 -- error except when the implementation kind of the overridden
11184 -- subprograms is By_Any or Optional.
11186 if Iface_Kind
/= Subp_Kind
11187 and then Iface_Kind
/= Name_By_Any
11188 and then Iface_Kind
/= Name_Optional
11190 if Iface_Kind
= Name_By_Entry
then
11192 ("incompatible implementation kind, overridden subprogram " &
11193 "is marked By_Entry", Subp
);
11196 ("incompatible implementation kind, overridden subprogram " &
11197 "is marked By_Protected_Procedure", Subp
);
11200 end Check_Pragma_Implemented
;
11202 --------------------------------
11203 -- Inherit_Pragma_Implemented --
11204 --------------------------------
11206 procedure Inherit_Pragma_Implemented
11208 Iface_Subp
: Entity_Id
)
11210 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
11211 Loc
: constant Source_Ptr
:= Sloc
(Subp
);
11212 Impl_Prag
: Node_Id
;
11215 -- Since the implementation kind is stored as a representation item
11216 -- rather than a flag, create a pragma node.
11220 Chars
=> Name_Implemented
,
11221 Pragma_Argument_Associations
=> New_List
(
11222 Make_Pragma_Argument_Association
(Loc
,
11223 Expression
=> New_Occurrence_Of
(Subp
, Loc
)),
11225 Make_Pragma_Argument_Association
(Loc
,
11226 Expression
=> Make_Identifier
(Loc
, Iface_Kind
))));
11228 -- The pragma doesn't need to be analyzed because it is internally
11229 -- built. It is safe to directly register it as a rep item since we
11230 -- are only interested in the characters of the implementation kind.
11232 Record_Rep_Item
(Subp
, Impl_Prag
);
11233 end Inherit_Pragma_Implemented
;
11235 -- Start of processing for Check_Abstract_Overriding
11238 Op_List
:= Primitive_Operations
(T
);
11240 -- Loop to check primitive operations
11242 Elmt
:= First_Elmt
(Op_List
);
11243 while Present
(Elmt
) loop
11244 Subp
:= Node
(Elmt
);
11245 Alias_Subp
:= Alias
(Subp
);
11247 -- If the parent type is untagged, then no overriding error checks
11248 -- are needed (such as in the case of an implicit full type for
11249 -- a derived type whose parent is an untagged private type with
11250 -- a tagged full type).
11252 if not Is_Tagged_Type
(Etype
(T
)) then
11255 -- Inherited subprograms are identified by the fact that they do not
11256 -- come from source, and the associated source location is the
11257 -- location of the first subtype of the derived type.
11259 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
11260 -- subprograms that "require overriding".
11262 -- Special exception, do not complain about failure to override the
11263 -- stream routines _Input and _Output, as well as the primitive
11264 -- operations used in dispatching selects since we always provide
11265 -- automatic overridings for these subprograms.
11267 -- The partial view of T may have been a private extension, for
11268 -- which inherited functions dispatching on result are abstract.
11269 -- If the full view is a null extension, there is no need for
11270 -- overriding in Ada 2005, but wrappers need to be built for them
11271 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
11273 elsif Is_Null_Extension
(T
)
11274 and then Has_Controlling_Result
(Subp
)
11275 and then Ada_Version
>= Ada_2005
11276 and then Present
(Alias_Subp
)
11277 and then not Comes_From_Source
(Subp
)
11278 and then not Is_Abstract_Subprogram
(Alias_Subp
)
11279 and then not Is_Access_Type
(Etype
(Subp
))
11283 -- Ada 2005 (AI-251): Internal entities of interfaces need no
11284 -- processing because this check is done with the aliased
11287 elsif Present
(Interface_Alias
(Subp
)) then
11290 -- AI12-0042: Test for rule in 7.3.2(6.1/4), that requires overriding
11291 -- of a visible private primitive inherited from an ancestor with
11292 -- the aspect Type_Invariant'Class, unless the inherited primitive
11295 elsif not Is_Abstract_Subprogram
(Subp
)
11296 and then not Comes_From_Source
(Subp
) -- An inherited subprogram
11297 and then Requires_Overriding
(Subp
)
11298 and then Present
(Alias_Subp
)
11299 and then Has_Invariants
(Etype
(T
))
11300 and then Present
(Get_Pragma
(Etype
(T
), Pragma_Invariant
))
11301 and then Class_Present
(Get_Pragma
(Etype
(T
), Pragma_Invariant
))
11302 and then Is_Private_Primitive
(Alias_Subp
)
11305 ("inherited private primitive & must be overridden", T
, Subp
);
11307 ("\because ancestor type has 'Type_'Invariant''Class " &
11308 "(RM 7.3.2(6.1))", T
);
11310 elsif (Is_Abstract_Subprogram
(Subp
)
11311 or else Requires_Overriding
(Subp
)
11313 (Has_Controlling_Result
(Subp
)
11314 and then Present
(Alias_Subp
)
11315 and then not Comes_From_Source
(Subp
)
11316 and then Sloc
(Subp
) = Sloc
(First_Subtype
(T
))))
11317 and then not Is_TSS
(Subp
, TSS_Stream_Input
)
11318 and then not Is_TSS
(Subp
, TSS_Stream_Output
)
11319 and then not Is_Abstract_Type
(T
)
11320 and then not Is_Predefined_Interface_Primitive
(Subp
)
11322 -- Ada 2005 (AI-251): Do not consider hidden entities associated
11323 -- with abstract interface types because the check will be done
11324 -- with the aliased entity (otherwise we generate a duplicated
11327 and then No
(Interface_Alias
(Subp
))
11329 if Present
(Alias_Subp
) then
11331 -- Only perform the check for a derived subprogram when the
11332 -- type has an explicit record extension. This avoids incorrect
11333 -- flagging of abstract subprograms for the case of a type
11334 -- without an extension that is derived from a formal type
11335 -- with a tagged actual (can occur within a private part).
11337 -- Ada 2005 (AI-391): In the case of an inherited function with
11338 -- a controlling result of the type, the rule does not apply if
11339 -- the type is a null extension (unless the parent function
11340 -- itself is abstract, in which case the function must still be
11341 -- be overridden). The expander will generate an overriding
11342 -- wrapper function calling the parent subprogram (see
11343 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
11345 Type_Def
:= Type_Definition
(Parent
(T
));
11347 if Nkind
(Type_Def
) = N_Derived_Type_Definition
11348 and then Present
(Record_Extension_Part
(Type_Def
))
11350 (Ada_Version
< Ada_2005
11351 or else not Is_Null_Extension
(T
)
11352 or else Ekind
(Subp
) = E_Procedure
11353 or else not Has_Controlling_Result
(Subp
)
11354 or else Is_Abstract_Subprogram
(Alias_Subp
)
11355 or else Requires_Overriding
(Subp
)
11356 or else Is_Access_Type
(Etype
(Subp
)))
11358 -- Avoid reporting error in case of abstract predefined
11359 -- primitive inherited from interface type because the
11360 -- body of internally generated predefined primitives
11361 -- of tagged types are generated later by Freeze_Type
11363 if Is_Interface
(Root_Type
(T
))
11364 and then Is_Abstract_Subprogram
(Subp
)
11365 and then Is_Predefined_Dispatching_Operation
(Subp
)
11366 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
11370 -- A null extension is not obliged to override an inherited
11371 -- procedure subject to pragma Extensions_Visible with value
11372 -- False and at least one controlling OUT parameter
11373 -- (SPARK RM 6.1.7(6)).
11375 elsif Is_Null_Extension
(T
)
11376 and then Is_EVF_Procedure
(Subp
)
11380 -- Subprogram renamings cannot be overridden
11382 elsif Comes_From_Source
(Subp
)
11383 and then Present
(Alias
(Subp
))
11387 -- Skip reporting the error on Ada 2022 only subprograms
11388 -- that require overriding if we are not in Ada 2022 mode.
11390 elsif Ada_Version
< Ada_2022
11391 and then Requires_Overriding
(Subp
)
11392 and then Is_Ada_2022_Only
(Ultimate_Alias
(Subp
))
11398 ("type must be declared abstract or & overridden",
11401 -- Traverse the whole chain of aliased subprograms to
11402 -- complete the error notification. This is especially
11403 -- useful for traceability of the chain of entities when
11404 -- the subprogram corresponds with an interface
11405 -- subprogram (which may be defined in another package).
11407 if Present
(Alias_Subp
) then
11413 while Present
(Alias
(E
)) loop
11415 -- Avoid reporting redundant errors on entities
11416 -- inherited from interfaces
11418 if Sloc
(E
) /= Sloc
(T
) then
11419 Error_Msg_Sloc
:= Sloc
(E
);
11421 ("\& has been inherited #", T
, Subp
);
11427 Error_Msg_Sloc
:= Sloc
(E
);
11429 -- AI05-0068: report if there is an overriding
11430 -- non-abstract subprogram that is invisible.
11433 and then not Is_Abstract_Subprogram
(E
)
11436 ("\& subprogram# is not visible",
11439 -- Clarify the case where a non-null extension must
11440 -- override inherited procedure subject to pragma
11441 -- Extensions_Visible with value False and at least
11442 -- one controlling OUT param.
11444 elsif Is_EVF_Procedure
(E
) then
11446 ("\& # is subject to Extensions_Visible False",
11451 ("\& has been inherited from subprogram #",
11458 -- Ada 2005 (AI-345): Protected or task type implementing
11459 -- abstract interfaces.
11461 elsif Is_Concurrent_Record_Type
(T
)
11462 and then Present
(Interfaces
(T
))
11464 -- There is no need to check here RM 9.4(11.9/3) since we
11465 -- are processing the corresponding record type and the
11466 -- mode of the overriding subprograms was verified by
11467 -- Check_Conformance when the corresponding concurrent
11468 -- type declaration was analyzed.
11471 ("interface subprogram & must be overridden", T
, Subp
);
11473 -- Examine primitive operations of synchronized type to find
11474 -- homonyms that have the wrong profile.
11480 Prim
:= First_Entity
(Corresponding_Concurrent_Type
(T
));
11481 while Present
(Prim
) loop
11482 if Chars
(Prim
) = Chars
(Subp
) then
11484 ("profile is not type conformant with prefixed "
11485 & "view profile of inherited operation&",
11489 Next_Entity
(Prim
);
11495 Error_Msg_Node_2
:= T
;
11497 ("abstract subprogram& not allowed for type&", Subp
);
11499 -- Also post unconditional warning on the type (unconditional
11500 -- so that if there are more than one of these cases, we get
11501 -- them all, and not just the first one).
11503 Error_Msg_Node_2
:= Subp
;
11504 Error_Msg_N
("nonabstract type& has abstract subprogram&!", T
);
11507 -- A subprogram subject to pragma Extensions_Visible with value
11508 -- "True" cannot override a subprogram subject to the same pragma
11509 -- with value "False" (SPARK RM 6.1.7(5)).
11511 elsif Extensions_Visible_Status
(Subp
) = Extensions_Visible_True
11512 and then Present
(Overridden_Operation
(Subp
))
11513 and then Extensions_Visible_Status
(Overridden_Operation
(Subp
)) =
11514 Extensions_Visible_False
11516 Error_Msg_Sloc
:= Sloc
(Overridden_Operation
(Subp
));
11518 ("subprogram & with Extensions_Visible True cannot override "
11519 & "subprogram # with Extensions_Visible False", Subp
);
11522 -- Ada 2012 (AI05-0030): Perform checks related to pragma Implemented
11524 -- Subp is an expander-generated procedure which maps an interface
11525 -- alias to a protected wrapper. The interface alias is flagged by
11526 -- pragma Implemented. Ensure that Subp is a procedure when the
11527 -- implementation kind is By_Protected_Procedure or an entry when
11530 if Ada_Version
>= Ada_2012
11531 and then Is_Hidden
(Subp
)
11532 and then Present
(Interface_Alias
(Subp
))
11533 and then Has_Rep_Pragma
(Interface_Alias
(Subp
), Name_Implemented
)
11535 Check_Pragma_Implemented
(Subp
);
11538 -- Subp is an interface primitive which overrides another interface
11539 -- primitive marked with pragma Implemented.
11541 if Ada_Version
>= Ada_2012
11542 and then Present
(Overridden_Operation
(Subp
))
11543 and then Has_Rep_Pragma
11544 (Overridden_Operation
(Subp
), Name_Implemented
)
11546 -- If the overriding routine is also marked by Implemented, check
11547 -- that the two implementation kinds are conforming.
11549 if Has_Rep_Pragma
(Subp
, Name_Implemented
) then
11550 Check_Pragma_Implemented
11552 Iface_Subp
=> Overridden_Operation
(Subp
));
11554 -- Otherwise the overriding routine inherits the implementation
11555 -- kind from the overridden subprogram.
11558 Inherit_Pragma_Implemented
11560 Iface_Subp
=> Overridden_Operation
(Subp
));
11564 -- Ada 2005 (AI95-0414) and Ada 2022 (AI12-0269): Diagnose failure to
11565 -- match No_Return in parent, but do it unconditionally in Ada 95 too
11566 -- for procedures, since this is our pragma.
11568 if Present
(Overridden_Operation
(Subp
))
11569 and then No_Return
(Overridden_Operation
(Subp
))
11572 -- If the subprogram is a renaming, check that the renamed
11573 -- subprogram is No_Return.
11575 if Present
(Renamed_Or_Alias
(Subp
)) then
11576 if not No_Return
(Renamed_Or_Alias
(Subp
)) then
11577 Error_Msg_NE
("subprogram & must be No_Return",
11579 Renamed_Or_Alias
(Subp
));
11580 Error_Msg_N
("\since renaming & overrides No_Return "
11581 & "subprogram (RM 6.5.1(6/2))",
11585 -- Make sure that the subprogram itself is No_Return.
11587 elsif not No_Return
(Subp
) then
11588 Error_Msg_N
("overriding subprogram & must be No_Return", Subp
);
11590 ("\since overridden subprogram is No_Return (RM 6.5.1(6/2))",
11595 -- If the operation is a wrapper for a synchronized primitive, it
11596 -- may be called indirectly through a dispatching select. We assume
11597 -- that it will be referenced elsewhere indirectly, and suppress
11598 -- warnings about an unused entity.
11600 if Is_Primitive_Wrapper
(Subp
)
11601 and then Present
(Wrapped_Entity
(Subp
))
11603 Set_Referenced
(Wrapped_Entity
(Subp
));
11608 end Check_Abstract_Overriding
;
11610 ------------------------------------------------
11611 -- Check_Access_Discriminant_Requires_Limited --
11612 ------------------------------------------------
11614 procedure Check_Access_Discriminant_Requires_Limited
11619 -- A discriminant_specification for an access discriminant shall appear
11620 -- only in the declaration for a task or protected type, or for a type
11621 -- with the reserved word 'limited' in its definition or in one of its
11622 -- ancestors (RM 3.7(10)).
11624 -- AI-0063: The proper condition is that type must be immutably limited,
11625 -- or else be a partial view.
11627 if Nkind
(Discriminant_Type
(D
)) = N_Access_Definition
then
11628 if Is_Inherently_Limited_Type
(Current_Scope
)
11630 (Nkind
(Parent
(Current_Scope
)) = N_Private_Type_Declaration
11631 and then Limited_Present
(Parent
(Current_Scope
)))
11637 ("access discriminants allowed only for limited types", Loc
);
11640 end Check_Access_Discriminant_Requires_Limited
;
11642 -----------------------------------
11643 -- Check_Aliased_Component_Types --
11644 -----------------------------------
11646 procedure Check_Aliased_Component_Types
(T
: Entity_Id
) is
11650 -- ??? Also need to check components of record extensions, but not
11651 -- components of protected types (which are always limited).
11653 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
11654 -- types to be unconstrained. This is safe because it is illegal to
11655 -- create access subtypes to such types with explicit discriminant
11658 if not Is_Limited_Type
(T
) then
11659 if Ekind
(T
) = E_Record_Type
then
11660 C
:= First_Component
(T
);
11661 while Present
(C
) loop
11663 and then Has_Discriminants
(Etype
(C
))
11664 and then not Is_Constrained
(Etype
(C
))
11665 and then not In_Instance_Body
11666 and then Ada_Version
< Ada_2005
11669 ("aliased component must be constrained (RM 3.6(11))",
11673 Next_Component
(C
);
11676 elsif Ekind
(T
) = E_Array_Type
then
11677 if Has_Aliased_Components
(T
)
11678 and then Has_Discriminants
(Component_Type
(T
))
11679 and then not Is_Constrained
(Component_Type
(T
))
11680 and then not In_Instance_Body
11681 and then Ada_Version
< Ada_2005
11684 ("aliased component type must be constrained (RM 3.6(11))",
11689 end Check_Aliased_Component_Types
;
11691 --------------------------------------
11692 -- Check_Anonymous_Access_Component --
11693 --------------------------------------
11695 procedure Check_Anonymous_Access_Component
11696 (Typ_Decl
: Node_Id
;
11699 Comp_Def
: Node_Id
;
11700 Access_Def
: Node_Id
)
11702 Loc
: constant Source_Ptr
:= Sloc
(Comp_Def
);
11703 Anon_Access
: Entity_Id
;
11706 Type_Def
: Node_Id
;
11708 procedure Build_Incomplete_Type_Declaration
;
11709 -- If the record type contains components that include an access to the
11710 -- current record, then create an incomplete type declaration for the
11711 -- record, to be used as the designated type of the anonymous access.
11712 -- This is done only once, and only if there is no previous partial
11713 -- view of the type.
11715 function Designates_T
(Subt
: Node_Id
) return Boolean;
11716 -- Check whether a node designates the enclosing record type, or 'Class
11719 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean;
11720 -- Check whether an access definition includes a reference to
11721 -- the enclosing record type. The reference can be a subtype mark
11722 -- in the access definition itself, a 'Class attribute reference, or
11723 -- recursively a reference appearing in a parameter specification
11724 -- or result definition of an access_to_subprogram definition.
11726 --------------------------------------
11727 -- Build_Incomplete_Type_Declaration --
11728 --------------------------------------
11730 procedure Build_Incomplete_Type_Declaration
is
11735 -- Is_Tagged indicates whether the type is tagged. It is tagged if
11736 -- it's "is new ... with record" or else "is tagged record ...".
11738 Typ_Def
: constant Node_Id
:=
11739 (if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
11740 then Type_Definition
(Typ_Decl
) else Empty
);
11741 Is_Tagged
: constant Boolean :=
11744 ((Nkind
(Typ_Def
) = N_Derived_Type_Definition
11746 Present
(Record_Extension_Part
(Typ_Def
)))
11748 (Nkind
(Typ_Def
) = N_Record_Definition
11749 and then Tagged_Present
(Typ_Def
)));
11752 -- If there is a previous partial view, no need to create a new one
11753 -- If the partial view, given by Prev, is incomplete, If Prev is
11754 -- a private declaration, full declaration is flagged accordingly.
11756 if Prev
/= Typ
then
11758 Make_Class_Wide_Type
(Prev
);
11759 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Prev
));
11760 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
11765 elsif Has_Private_Declaration
(Typ
) then
11767 -- If we refer to T'Class inside T, and T is the completion of a
11768 -- private type, then make sure the class-wide type exists.
11771 Make_Class_Wide_Type
(Typ
);
11776 -- If there was a previous anonymous access type, the incomplete
11777 -- type declaration will have been created already.
11779 elsif Present
(Current_Entity
(Typ
))
11780 and then Ekind
(Current_Entity
(Typ
)) = E_Incomplete_Type
11781 and then Full_View
(Current_Entity
(Typ
)) = Typ
11784 and then Comes_From_Source
(Current_Entity
(Typ
))
11785 and then not Is_Tagged_Type
(Current_Entity
(Typ
))
11787 Make_Class_Wide_Type
(Typ
);
11789 ("incomplete view of tagged type should be declared tagged??",
11790 Parent
(Current_Entity
(Typ
)));
11795 Inc_T
:= Make_Defining_Identifier
(Loc
, Chars
(Typ
));
11796 Decl
:= Make_Incomplete_Type_Declaration
(Loc
, Inc_T
);
11798 -- Type has already been inserted into the current scope. Remove
11799 -- it, and add incomplete declaration for type, so that subsequent
11800 -- anonymous access types can use it. The entity is unchained from
11801 -- the homonym list and from immediate visibility. After analysis,
11802 -- the entity in the incomplete declaration becomes immediately
11803 -- visible in the record declaration that follows.
11805 H
:= Current_Entity
(Typ
);
11808 Set_Name_Entity_Id
(Chars
(Typ
), Homonym
(Typ
));
11811 while Present
(Homonym
(H
)) and then Homonym
(H
) /= Typ
loop
11812 H
:= Homonym
(Typ
);
11815 Set_Homonym
(H
, Homonym
(Typ
));
11818 Insert_Before
(Typ_Decl
, Decl
);
11820 Set_Full_View
(Inc_T
, Typ
);
11821 Set_Incomplete_View
(Typ_Decl
, Inc_T
);
11823 -- If the type is tagged, create a common class-wide type for
11824 -- both views, and set the Etype of the class-wide type to the
11828 Make_Class_Wide_Type
(Inc_T
);
11829 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Inc_T
));
11830 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
11833 -- If the scope is a package with a limited view, create a shadow
11834 -- entity for the incomplete type like Build_Limited_Views, so as
11835 -- to make it possible for Remove_Limited_With_Unit to reinstall
11836 -- this incomplete type as the visible entity.
11838 if Ekind
(Scope
(Inc_T
)) = E_Package
11839 and then Present
(Limited_View
(Scope
(Inc_T
)))
11842 Shadow
: constant Entity_Id
:= Make_Temporary
(Loc
, 'Z');
11845 -- This is modeled on Build_Shadow_Entity
11847 Set_Chars
(Shadow
, Chars
(Inc_T
));
11848 Set_Parent
(Shadow
, Decl
);
11849 Decorate_Type
(Shadow
, Scope
(Inc_T
), Is_Tagged
);
11850 Set_Is_Internal
(Shadow
);
11851 Set_From_Limited_With
(Shadow
);
11852 Set_Non_Limited_View
(Shadow
, Inc_T
);
11853 Set_Private_Dependents
(Shadow
, New_Elmt_List
);
11856 Set_Non_Limited_View
11857 (Class_Wide_Type
(Shadow
), Class_Wide_Type
(Inc_T
));
11860 Append_Entity
(Shadow
, Limited_View
(Scope
(Inc_T
)));
11864 end Build_Incomplete_Type_Declaration
;
11870 function Designates_T
(Subt
: Node_Id
) return Boolean is
11871 Type_Id
: constant Name_Id
:= Chars
(Typ
);
11873 function Names_T
(Nam
: Node_Id
) return Boolean;
11874 -- The record type has not been introduced in the current scope
11875 -- yet, so we must examine the name of the type itself, either
11876 -- an identifier T, or an expanded name of the form P.T, where
11877 -- P denotes the current scope.
11883 function Names_T
(Nam
: Node_Id
) return Boolean is
11885 if Nkind
(Nam
) = N_Identifier
then
11886 return Chars
(Nam
) = Type_Id
;
11888 elsif Nkind
(Nam
) = N_Selected_Component
then
11889 if Chars
(Selector_Name
(Nam
)) = Type_Id
then
11890 if Nkind
(Prefix
(Nam
)) = N_Identifier
then
11891 return Chars
(Prefix
(Nam
)) = Chars
(Current_Scope
);
11893 elsif Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
11894 return Chars
(Selector_Name
(Prefix
(Nam
))) =
11895 Chars
(Current_Scope
);
11909 -- Start of processing for Designates_T
11912 if Nkind
(Subt
) = N_Identifier
then
11913 return Chars
(Subt
) = Type_Id
;
11915 -- Reference can be through an expanded name which has not been
11916 -- analyzed yet, and which designates enclosing scopes.
11918 elsif Nkind
(Subt
) = N_Selected_Component
then
11919 if Names_T
(Subt
) then
11922 -- Otherwise it must denote an entity that is already visible.
11923 -- The access definition may name a subtype of the enclosing
11924 -- type, if there is a previous incomplete declaration for it.
11927 Find_Selected_Component
(Subt
);
11929 Is_Entity_Name
(Subt
)
11930 and then Scope
(Entity
(Subt
)) = Current_Scope
11932 (Chars
(Base_Type
(Entity
(Subt
))) = Type_Id
11934 (Is_Class_Wide_Type
(Entity
(Subt
))
11936 Chars
(Etype
(Base_Type
(Entity
(Subt
)))) =
11940 -- A reference to the current type may appear as the prefix of
11941 -- a 'Class attribute.
11943 elsif Nkind
(Subt
) = N_Attribute_Reference
11944 and then Attribute_Name
(Subt
) = Name_Class
11946 return Names_T
(Prefix
(Subt
));
11957 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean is
11958 Param_Spec
: Node_Id
;
11960 Acc_Subprg
: constant Node_Id
:=
11961 Access_To_Subprogram_Definition
(Acc_Def
);
11964 if No
(Acc_Subprg
) then
11965 return Designates_T
(Subtype_Mark
(Acc_Def
));
11968 -- Component is an access_to_subprogram: examine its formals,
11969 -- and result definition in the case of an access_to_function.
11971 Param_Spec
:= First
(Parameter_Specifications
(Acc_Subprg
));
11972 while Present
(Param_Spec
) loop
11973 if Nkind
(Parameter_Type
(Param_Spec
)) = N_Access_Definition
11974 and then Mentions_T
(Parameter_Type
(Param_Spec
))
11978 elsif Designates_T
(Parameter_Type
(Param_Spec
)) then
11985 if Nkind
(Acc_Subprg
) = N_Access_Function_Definition
then
11986 if Nkind
(Result_Definition
(Acc_Subprg
)) =
11987 N_Access_Definition
11989 return Mentions_T
(Result_Definition
(Acc_Subprg
));
11991 return Designates_T
(Result_Definition
(Acc_Subprg
));
11998 -- Start of processing for Check_Anonymous_Access_Component
12001 if Present
(Access_Def
) and then Mentions_T
(Access_Def
) then
12002 Acc_Def
:= Access_To_Subprogram_Definition
(Access_Def
);
12004 Build_Incomplete_Type_Declaration
;
12005 Anon_Access
:= Make_Temporary
(Loc
, 'S');
12007 -- Create a declaration for the anonymous access type: either
12008 -- an access_to_object or an access_to_subprogram.
12010 if Present
(Acc_Def
) then
12011 if Nkind
(Acc_Def
) = N_Access_Function_Definition
then
12013 Make_Access_Function_Definition
(Loc
,
12014 Parameter_Specifications
=>
12015 Parameter_Specifications
(Acc_Def
),
12016 Result_Definition
=> Result_Definition
(Acc_Def
));
12019 Make_Access_Procedure_Definition
(Loc
,
12020 Parameter_Specifications
=>
12021 Parameter_Specifications
(Acc_Def
));
12026 Make_Access_To_Object_Definition
(Loc
,
12027 Subtype_Indication
=>
12028 Relocate_Node
(Subtype_Mark
(Access_Def
)));
12030 Set_Constant_Present
(Type_Def
, Constant_Present
(Access_Def
));
12031 Set_All_Present
(Type_Def
, All_Present
(Access_Def
));
12034 Set_Null_Exclusion_Present
12035 (Type_Def
, Null_Exclusion_Present
(Access_Def
));
12038 Make_Full_Type_Declaration
(Loc
,
12039 Defining_Identifier
=> Anon_Access
,
12040 Type_Definition
=> Type_Def
);
12042 Insert_Before
(Typ_Decl
, Decl
);
12045 -- At first sight we could add here the extra formals of an access to
12046 -- subprogram; however, it must delayed till the freeze point so that
12047 -- we know the convention.
12049 if Nkind
(Comp_Def
) = N_Component_Definition
then
12051 Make_Component_Definition
(Loc
,
12052 Subtype_Indication
=> New_Occurrence_Of
(Anon_Access
, Loc
)));
12054 pragma Assert
(Nkind
(Comp_Def
) = N_Discriminant_Specification
);
12056 Make_Discriminant_Specification
(Loc
,
12057 Defining_Identifier
=> Defining_Identifier
(Comp_Def
),
12058 Discriminant_Type
=> New_Occurrence_Of
(Anon_Access
, Loc
)));
12061 if Ekind
(Designated_Type
(Anon_Access
)) = E_Subprogram_Type
then
12062 Mutate_Ekind
(Anon_Access
, E_Anonymous_Access_Subprogram_Type
);
12064 Mutate_Ekind
(Anon_Access
, E_Anonymous_Access_Type
);
12067 Set_Is_Local_Anonymous_Access
(Anon_Access
);
12069 end Check_Anonymous_Access_Component
;
12071 ---------------------------------------
12072 -- Check_Anonymous_Access_Components --
12073 ---------------------------------------
12075 procedure Check_Anonymous_Access_Components
12076 (Typ_Decl
: Node_Id
;
12079 Comp_List
: Node_Id
)
12083 if No
(Comp_List
) then
12087 Set_Is_Not_Self_Hidden
(Typ
);
12089 Comp
:= First
(Component_Items
(Comp_List
));
12090 while Present
(Comp
) loop
12091 if Nkind
(Comp
) = N_Component_Declaration
then
12092 Check_Anonymous_Access_Component
12093 (Typ_Decl
, Typ
, Prev
,
12094 Component_Definition
(Comp
),
12095 Access_Definition
(Component_Definition
(Comp
)));
12101 if Present
(Variant_Part
(Comp_List
)) then
12105 V
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
12106 while Present
(V
) loop
12107 Check_Anonymous_Access_Components
12108 (Typ_Decl
, Typ
, Prev
, Component_List
(V
));
12109 Next_Non_Pragma
(V
);
12113 end Check_Anonymous_Access_Components
;
12115 ----------------------
12116 -- Check_Completion --
12117 ----------------------
12119 procedure Check_Completion
(Body_Id
: Node_Id
:= Empty
) is
12122 procedure Post_Error
;
12123 -- Post error message for lack of completion for entity E
12129 procedure Post_Error
is
12130 procedure Missing_Body
;
12131 -- Output missing body message
12137 procedure Missing_Body
is
12139 -- Spec is in same unit, so we can post on spec
12141 if In_Same_Source_Unit
(Body_Id
, E
) then
12142 Error_Msg_N
("missing body for &", E
);
12144 -- Spec is in a separate unit, so we have to post on the body
12147 Error_Msg_NE
("missing body for & declared#!", Body_Id
, E
);
12151 -- Start of processing for Post_Error
12154 if not Comes_From_Source
(E
) then
12155 if Ekind
(E
) in E_Task_Type | E_Protected_Type
then
12157 -- It may be an anonymous protected type created for a
12158 -- single variable. Post error on variable, if present.
12164 Var
:= First_Entity
(Current_Scope
);
12165 while Present
(Var
) loop
12166 exit when Etype
(Var
) = E
12167 and then Comes_From_Source
(Var
);
12172 if Present
(Var
) then
12179 -- If a generated entity has no completion, then either previous
12180 -- semantic errors have disabled the expansion phase, or else we had
12181 -- missing subunits, or else we are compiling without expansion,
12182 -- or else something is very wrong.
12184 if not Comes_From_Source
(E
) then
12186 (Serious_Errors_Detected
> 0
12187 or else Configurable_Run_Time_Violations
> 0
12188 or else Subunits_Missing
12189 or else not Expander_Active
);
12192 -- Here for source entity
12195 -- Here if no body to post the error message, so we post the error
12196 -- on the declaration that has no completion. This is not really
12197 -- the right place to post it, think about this later ???
12199 if No
(Body_Id
) then
12200 if Is_Type
(E
) then
12202 ("missing full declaration for }", Parent
(E
), E
);
12204 Error_Msg_NE
("missing body for &", Parent
(E
), E
);
12207 -- Package body has no completion for a declaration that appears
12208 -- in the corresponding spec. Post error on the body, with a
12209 -- reference to the non-completed declaration.
12212 Error_Msg_Sloc
:= Sloc
(E
);
12214 if Is_Type
(E
) then
12215 Error_Msg_NE
("missing full declaration for }!", Body_Id
, E
);
12217 elsif Is_Overloadable
(E
)
12218 and then Current_Entity_In_Scope
(E
) /= E
12220 -- It may be that the completion is mistyped and appears as
12221 -- a distinct overloading of the entity.
12224 Candidate
: constant Entity_Id
:=
12225 Current_Entity_In_Scope
(E
);
12226 Decl
: constant Node_Id
:=
12227 Unit_Declaration_Node
(Candidate
);
12230 if Is_Overloadable
(Candidate
)
12231 and then Ekind
(Candidate
) = Ekind
(E
)
12232 and then Nkind
(Decl
) = N_Subprogram_Body
12233 and then Acts_As_Spec
(Decl
)
12235 Check_Type_Conformant
(Candidate
, E
);
12251 Pack_Id
: constant Entity_Id
:= Current_Scope
;
12253 -- Start of processing for Check_Completion
12256 E
:= First_Entity
(Pack_Id
);
12257 while Present
(E
) loop
12258 if Is_Intrinsic_Subprogram
(E
) then
12261 -- The following situation requires special handling: a child unit
12262 -- that appears in the context clause of the body of its parent:
12264 -- procedure Parent.Child (...);
12266 -- with Parent.Child;
12267 -- package body Parent is
12269 -- Here Parent.Child appears as a local entity, but should not be
12270 -- flagged as requiring completion, because it is a compilation
12273 -- Ignore missing completion for a subprogram that does not come from
12274 -- source (including the _Call primitive operation of RAS types,
12275 -- which has to have the flag Comes_From_Source for other purposes):
12276 -- we assume that the expander will provide the missing completion.
12277 -- In case of previous errors, other expansion actions that provide
12278 -- bodies for null procedures with not be invoked, so inhibit message
12281 -- Note that E_Operator is not in the list that follows, because
12282 -- this kind is reserved for predefined operators, that are
12283 -- intrinsic and do not need completion.
12285 elsif Ekind
(E
) in E_Function
12287 | E_Generic_Function
12288 | E_Generic_Procedure
12290 if Has_Completion
(E
) then
12293 elsif Is_Subprogram
(E
) and then Is_Abstract_Subprogram
(E
) then
12296 elsif Is_Subprogram
(E
)
12297 and then (not Comes_From_Source
(E
)
12298 or else Chars
(E
) = Name_uCall
)
12303 Nkind
(Parent
(Unit_Declaration_Node
(E
))) = N_Compilation_Unit
12307 elsif Nkind
(Parent
(E
)) = N_Procedure_Specification
12308 and then Null_Present
(Parent
(E
))
12309 and then Serious_Errors_Detected
> 0
12317 elsif Is_Entry
(E
) then
12318 if not Has_Completion
(E
)
12319 and then Ekind
(Scope
(E
)) = E_Protected_Type
12324 elsif Is_Package_Or_Generic_Package
(E
) then
12325 if Unit_Requires_Body
(E
) then
12326 if not Has_Completion
(E
)
12327 and then Nkind
(Parent
(Unit_Declaration_Node
(E
))) /=
12333 elsif not Is_Child_Unit
(E
) then
12334 May_Need_Implicit_Body
(E
);
12337 -- A formal incomplete type (Ada 2012) does not require a completion;
12338 -- other incomplete type declarations do.
12340 elsif Ekind
(E
) = E_Incomplete_Type
then
12341 if No
(Underlying_Type
(E
))
12342 and then not Is_Generic_Type
(E
)
12347 elsif Ekind
(E
) in E_Task_Type | E_Protected_Type
then
12348 if not Has_Completion
(E
) then
12352 -- A single task declared in the current scope is a constant, verify
12353 -- that the body of its anonymous type is in the same scope. If the
12354 -- task is defined elsewhere, this may be a renaming declaration for
12355 -- which no completion is needed.
12357 elsif Ekind
(E
) = E_Constant
then
12358 if Ekind
(Etype
(E
)) = E_Task_Type
12359 and then not Has_Completion
(Etype
(E
))
12360 and then Scope
(Etype
(E
)) = Current_Scope
12365 elsif Ekind
(E
) = E_Record_Type
then
12366 if Is_Tagged_Type
(E
) then
12367 Check_Abstract_Overriding
(E
);
12368 Check_Conventions
(E
);
12371 Check_Aliased_Component_Types
(E
);
12373 elsif Ekind
(E
) = E_Array_Type
then
12374 Check_Aliased_Component_Types
(E
);
12380 end Check_Completion
;
12382 -------------------------------------
12383 -- Check_Constraining_Discriminant --
12384 -------------------------------------
12386 procedure Check_Constraining_Discriminant
(New_Disc
, Old_Disc
: Entity_Id
)
12388 New_Type
: constant Entity_Id
:= Etype
(New_Disc
);
12389 Old_Type
: Entity_Id
;
12392 -- If the record type contains an array constrained by the discriminant
12393 -- but with some different bound, the compiler tries to create a smaller
12394 -- range for the discriminant type (see exp_ch3.Adjust_Discriminants).
12395 -- In this case, where the discriminant type is a scalar type, the check
12396 -- must use the original discriminant type in the parent declaration.
12398 if Is_Scalar_Type
(New_Type
) then
12399 Old_Type
:= Entity
(Discriminant_Type
(Parent
(Old_Disc
)));
12401 Old_Type
:= Etype
(Old_Disc
);
12404 if not Subtypes_Statically_Compatible
(New_Type
, Old_Type
) then
12406 ("subtype must be statically compatible with parent discriminant",
12409 if not Predicates_Compatible
(New_Type
, Old_Type
) then
12411 ("\subtype predicate is not compatible with parent discriminant",
12415 end Check_Constraining_Discriminant
;
12417 ------------------------------------
12418 -- Check_CPP_Type_Has_No_Defaults --
12419 ------------------------------------
12421 procedure Check_CPP_Type_Has_No_Defaults
(T
: Entity_Id
) is
12422 Tdef
: constant Node_Id
:= Type_Definition
(Declaration_Node
(T
));
12427 -- Obtain the component list
12429 if Nkind
(Tdef
) = N_Record_Definition
then
12430 Clist
:= Component_List
(Tdef
);
12431 else pragma Assert
(Nkind
(Tdef
) = N_Derived_Type_Definition
);
12432 Clist
:= Component_List
(Record_Extension_Part
(Tdef
));
12435 -- Check all components to ensure no default expressions
12437 if Present
(Clist
) then
12438 Comp
:= First_Non_Pragma
(Component_Items
(Clist
));
12439 while Present
(Comp
) loop
12440 if Present
(Expression
(Comp
)) then
12442 ("component of imported 'C'P'P type cannot have "
12443 & "default expression", Expression
(Comp
));
12446 Next_Non_Pragma
(Comp
);
12449 end Check_CPP_Type_Has_No_Defaults
;
12451 ----------------------------
12452 -- Check_Delta_Expression --
12453 ----------------------------
12455 procedure Check_Delta_Expression
(E
: Node_Id
) is
12457 if not Is_Real_Type
(Etype
(E
)) then
12458 Wrong_Type
(E
, Any_Real
);
12460 elsif not Is_OK_Static_Expression
(E
) then
12461 Flag_Non_Static_Expr
12462 ("non-static expression used for delta value!", E
);
12464 elsif not UR_Is_Positive
(Expr_Value_R
(E
)) then
12465 Error_Msg_N
("delta expression must be positive", E
);
12471 -- If any of above errors occurred, then replace the incorrect
12472 -- expression by the real 0.1, which should prevent further errors.
12475 Make_Real_Literal
(Sloc
(E
), Ureal_Tenth
));
12476 Analyze_And_Resolve
(E
, Standard_Float
);
12477 end Check_Delta_Expression
;
12479 -----------------------------
12480 -- Check_Digits_Expression --
12481 -----------------------------
12483 procedure Check_Digits_Expression
(E
: Node_Id
) is
12485 if not Is_Integer_Type
(Etype
(E
)) then
12486 Wrong_Type
(E
, Any_Integer
);
12488 elsif not Is_OK_Static_Expression
(E
) then
12489 Flag_Non_Static_Expr
12490 ("non-static expression used for digits value!", E
);
12492 elsif Expr_Value
(E
) <= 0 then
12493 Error_Msg_N
("digits value must be greater than zero", E
);
12499 -- If any of above errors occurred, then replace the incorrect
12500 -- expression by the integer 1, which should prevent further errors.
12502 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), 1));
12503 Analyze_And_Resolve
(E
, Standard_Integer
);
12505 end Check_Digits_Expression
;
12507 --------------------------
12508 -- Check_Initialization --
12509 --------------------------
12511 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
) is
12513 -- Special processing for limited types
12515 if Is_Limited_Type
(T
)
12516 and then not In_Instance
12517 and then not In_Inlined_Body
12519 if not OK_For_Limited_Init
(T
, Exp
) then
12521 -- In GNAT mode, this is just a warning, to allow it to be evilly
12522 -- turned off. Otherwise it is a real error.
12526 ("??cannot initialize entities of limited type!", Exp
);
12528 elsif Ada_Version
< Ada_2005
then
12530 -- The side effect removal machinery may generate illegal Ada
12531 -- code to avoid the usage of access types and 'reference in
12532 -- SPARK mode. Since this is legal code with respect to theorem
12533 -- proving, do not emit the error.
12536 and then Nkind
(Exp
) = N_Function_Call
12537 and then Nkind
(Parent
(Exp
)) = N_Object_Declaration
12538 and then not Comes_From_Source
12539 (Defining_Identifier
(Parent
(Exp
)))
12545 ("cannot initialize entities of limited type", Exp
);
12546 Explain_Limited_Type
(T
, Exp
);
12550 -- Specialize error message according to kind of illegal
12551 -- initial expression. We check the Original_Node to cover
12552 -- cases where the initialization expression of an object
12553 -- declaration generated by the compiler has been rewritten
12554 -- (such as for dispatching calls).
12556 if Nkind
(Original_Node
(Exp
)) = N_Type_Conversion
12558 Nkind
(Expression
(Original_Node
(Exp
))) = N_Function_Call
12560 -- No error for internally-generated object declarations,
12561 -- which can come from build-in-place assignment statements.
12563 if Nkind
(Parent
(Exp
)) = N_Object_Declaration
12564 and then not Comes_From_Source
12565 (Defining_Identifier
(Parent
(Exp
)))
12571 ("illegal context for call to function with limited "
12577 ("initialization of limited object requires aggregate or "
12578 & "function call", Exp
);
12584 -- In gnatc or gnatprove mode, make sure set Do_Range_Check flag gets
12585 -- set unless we can be sure that no range check is required.
12587 if not Expander_Active
12588 and then Is_Scalar_Type
(T
)
12589 and then not Is_In_Range
(Exp
, T
, Assume_Valid
=> True)
12591 Set_Do_Range_Check
(Exp
);
12593 end Check_Initialization
;
12595 ----------------------
12596 -- Check_Interfaces --
12597 ----------------------
12599 procedure Check_Interfaces
(N
: Node_Id
; Def
: Node_Id
) is
12600 Parent_Type
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
12603 Iface_Def
: Node_Id
;
12604 Iface_Typ
: Entity_Id
;
12605 Parent_Node
: Node_Id
;
12607 Is_Task
: Boolean := False;
12608 -- Set True if parent type or any progenitor is a task interface
12610 Is_Protected
: Boolean := False;
12611 -- Set True if parent type or any progenitor is a protected interface
12613 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
);
12614 -- Check that a progenitor is compatible with declaration. If an error
12615 -- message is output, it is posted on Error_Node.
12621 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
) is
12622 Iface_Id
: constant Entity_Id
:=
12623 Defining_Identifier
(Parent
(Iface_Def
));
12624 Type_Def
: Node_Id
;
12627 if Nkind
(N
) = N_Private_Extension_Declaration
then
12630 Type_Def
:= Type_Definition
(N
);
12633 if Is_Task_Interface
(Iface_Id
) then
12636 elsif Is_Protected_Interface
(Iface_Id
) then
12637 Is_Protected
:= True;
12640 if Is_Synchronized_Interface
(Iface_Id
) then
12642 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
12643 -- extension derived from a synchronized interface must explicitly
12644 -- be declared synchronized, because the full view will be a
12645 -- synchronized type.
12647 if Nkind
(N
) = N_Private_Extension_Declaration
then
12648 if not Synchronized_Present
(N
) then
12650 ("private extension of& must be explicitly synchronized",
12654 -- However, by 3.9.4(16/2), a full type that is a record extension
12655 -- is never allowed to derive from a synchronized interface (note
12656 -- that interfaces must be excluded from this check, because those
12657 -- are represented by derived type definitions in some cases).
12659 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
12660 and then not Interface_Present
(Type_Definition
(N
))
12662 Error_Msg_N
("record extension cannot derive from synchronized "
12663 & "interface", Error_Node
);
12667 -- Check that the characteristics of the progenitor are compatible
12668 -- with the explicit qualifier in the declaration.
12669 -- The check only applies to qualifiers that come from source.
12670 -- Limited_Present also appears in the declaration of corresponding
12671 -- records, and the check does not apply to them.
12673 if Limited_Present
(Type_Def
)
12675 Is_Concurrent_Record_Type
(Defining_Identifier
(N
))
12677 if Is_Limited_Interface
(Parent_Type
)
12678 and then not Is_Limited_Interface
(Iface_Id
)
12681 ("progenitor & must be limited interface",
12682 Error_Node
, Iface_Id
);
12685 (Task_Present
(Iface_Def
)
12686 or else Protected_Present
(Iface_Def
)
12687 or else Synchronized_Present
(Iface_Def
))
12688 and then Nkind
(N
) /= N_Private_Extension_Declaration
12689 and then not Error_Posted
(N
)
12692 ("progenitor & must be limited interface",
12693 Error_Node
, Iface_Id
);
12696 -- Protected interfaces can only inherit from limited, synchronized
12697 -- or protected interfaces.
12699 elsif Nkind
(N
) = N_Full_Type_Declaration
12700 and then Protected_Present
(Type_Def
)
12702 if Limited_Present
(Iface_Def
)
12703 or else Synchronized_Present
(Iface_Def
)
12704 or else Protected_Present
(Iface_Def
)
12708 elsif Task_Present
(Iface_Def
) then
12709 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
12710 & "from task interface", Error_Node
);
12713 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
12714 & "from non-limited interface", Error_Node
);
12717 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
12718 -- limited and synchronized.
12720 elsif Synchronized_Present
(Type_Def
) then
12721 if Limited_Present
(Iface_Def
)
12722 or else Synchronized_Present
(Iface_Def
)
12726 elsif Protected_Present
(Iface_Def
)
12727 and then Nkind
(N
) /= N_Private_Extension_Declaration
12729 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12730 & "from protected interface", Error_Node
);
12732 elsif Task_Present
(Iface_Def
)
12733 and then Nkind
(N
) /= N_Private_Extension_Declaration
12735 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12736 & "from task interface", Error_Node
);
12738 elsif not Is_Limited_Interface
(Iface_Id
) then
12739 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
12740 & "from non-limited interface", Error_Node
);
12743 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
12744 -- synchronized or task interfaces.
12746 elsif Nkind
(N
) = N_Full_Type_Declaration
12747 and then Task_Present
(Type_Def
)
12749 if Limited_Present
(Iface_Def
)
12750 or else Synchronized_Present
(Iface_Def
)
12751 or else Task_Present
(Iface_Def
)
12755 elsif Protected_Present
(Iface_Def
) then
12756 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
12757 & "protected interface", Error_Node
);
12760 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
12761 & "non-limited interface", Error_Node
);
12766 -- Start of processing for Check_Interfaces
12769 if Is_Interface
(Parent_Type
) then
12770 if Is_Task_Interface
(Parent_Type
) then
12773 elsif Is_Protected_Interface
(Parent_Type
) then
12774 Is_Protected
:= True;
12778 if Nkind
(N
) = N_Private_Extension_Declaration
then
12780 -- Check that progenitors are compatible with declaration
12782 Iface
:= First
(Interface_List
(Def
));
12783 while Present
(Iface
) loop
12784 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
12786 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
12787 Iface_Def
:= Type_Definition
(Parent_Node
);
12789 if not Is_Interface
(Iface_Typ
) then
12790 Diagnose_Interface
(Iface
, Iface_Typ
);
12792 Check_Ifaces
(Iface_Def
, Iface
);
12798 if Is_Task
and Is_Protected
then
12800 ("type cannot derive from task and protected interface", N
);
12806 -- Full type declaration of derived type.
12807 -- Check compatibility with parent if it is interface type
12809 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
12810 and then Is_Interface
(Parent_Type
)
12812 Parent_Node
:= Parent
(Parent_Type
);
12814 -- More detailed checks for interface varieties
12817 (Iface_Def
=> Type_Definition
(Parent_Node
),
12818 Error_Node
=> Subtype_Indication
(Type_Definition
(N
)));
12821 Iface
:= First
(Interface_List
(Def
));
12822 while Present
(Iface
) loop
12823 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
12825 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
12826 Iface_Def
:= Type_Definition
(Parent_Node
);
12828 if not Is_Interface
(Iface_Typ
) then
12829 Diagnose_Interface
(Iface
, Iface_Typ
);
12832 -- "The declaration of a specific descendant of an interface
12833 -- type freezes the interface type" RM 13.14
12835 Freeze_Before
(N
, Iface_Typ
);
12836 Check_Ifaces
(Iface_Def
, Error_Node
=> Iface
);
12842 if Is_Task
and Is_Protected
then
12844 ("type cannot derive from task and protected interface", N
);
12846 end Check_Interfaces
;
12848 ------------------------------------
12849 -- Check_Or_Process_Discriminants --
12850 ------------------------------------
12852 -- If an incomplete or private type declaration was already given for the
12853 -- type, the discriminants may have already been processed if they were
12854 -- present on the incomplete declaration. In this case a full conformance
12855 -- check has been performed in Find_Type_Name, and we then recheck here
12856 -- some properties that can't be checked on the partial view alone.
12857 -- Otherwise we call Process_Discriminants.
12859 procedure Check_Or_Process_Discriminants
12862 Prev
: Entity_Id
:= Empty
)
12865 if Has_Discriminants
(T
) then
12867 -- Discriminants are already set on T if they were already present
12868 -- on the partial view. Make them visible to component declarations.
12872 -- Discriminant on T (full view) referencing expr on partial view
12874 Prev_D
: Entity_Id
;
12875 -- Entity of corresponding discriminant on partial view
12878 -- Discriminant specification for full view, expression is
12879 -- the syntactic copy on full view (which has been checked for
12880 -- conformance with partial view), only used here to post error
12884 D
:= First_Discriminant
(T
);
12885 New_D
:= First
(Discriminant_Specifications
(N
));
12886 while Present
(D
) loop
12887 Prev_D
:= Current_Entity
(D
);
12888 Set_Current_Entity
(D
);
12889 Set_Is_Immediately_Visible
(D
);
12890 Set_Homonym
(D
, Prev_D
);
12892 -- Handle the case where there is an untagged partial view and
12893 -- the full view is tagged: must disallow discriminants with
12894 -- defaults, unless compiling for Ada 2012, which allows a
12895 -- limited tagged type to have defaulted discriminants (see
12896 -- AI05-0214). However, suppress error here if it was already
12897 -- reported on the default expression of the partial view.
12899 if Is_Tagged_Type
(T
)
12900 and then Present
(Expression
(Parent
(D
)))
12901 and then (not Is_Limited_Type
(Current_Scope
)
12902 or else Ada_Version
< Ada_2012
)
12903 and then not Error_Posted
(Expression
(Parent
(D
)))
12905 if Ada_Version
>= Ada_2012
then
12907 ("discriminants of nonlimited tagged type cannot have "
12909 Expression
(New_D
));
12912 ("discriminants of tagged type cannot have defaults",
12913 Expression
(New_D
));
12917 -- Ada 2005 (AI-230): Access discriminant allowed in
12918 -- non-limited record types.
12920 if Ada_Version
< Ada_2005
then
12922 -- This restriction gets applied to the full type here. It
12923 -- has already been applied earlier to the partial view.
12925 Check_Access_Discriminant_Requires_Limited
(Parent
(D
), N
);
12928 Next_Discriminant
(D
);
12933 elsif Present
(Discriminant_Specifications
(N
)) then
12934 Process_Discriminants
(N
, Prev
);
12936 end Check_Or_Process_Discriminants
;
12938 ----------------------
12939 -- Check_Real_Bound --
12940 ----------------------
12942 procedure Check_Real_Bound
(Bound
: Node_Id
) is
12944 if not Is_Real_Type
(Etype
(Bound
)) then
12946 ("bound in real type definition must be of real type", Bound
);
12948 elsif not Is_OK_Static_Expression
(Bound
) then
12949 Flag_Non_Static_Expr
12950 ("non-static expression used for real type bound!", Bound
);
12957 (Bound
, Make_Real_Literal
(Sloc
(Bound
), Ureal_0
));
12959 Resolve
(Bound
, Standard_Float
);
12960 end Check_Real_Bound
;
12962 ------------------------------
12963 -- Complete_Private_Subtype --
12964 ------------------------------
12966 procedure Complete_Private_Subtype
12969 Full_Base
: Entity_Id
;
12970 Related_Nod
: Node_Id
)
12972 Save_Next_Entity
: Entity_Id
;
12973 Save_Homonym
: Entity_Id
;
12976 -- Set semantic attributes for (implicit) private subtype completion.
12977 -- If the full type has no discriminants, then it is a copy of the
12978 -- full view of the base. Otherwise, it is a subtype of the base with
12979 -- a possible discriminant constraint. Save and restore the original
12980 -- Next_Entity field of full to ensure that the calls to Copy_Node do
12981 -- not corrupt the entity chain.
12983 Save_Next_Entity
:= Next_Entity
(Full
);
12984 Save_Homonym
:= Homonym
(Priv
);
12986 if Is_Private_Type
(Full_Base
)
12987 or else Is_Record_Type
(Full_Base
)
12988 or else Is_Concurrent_Type
(Full_Base
)
12990 Copy_Node
(Priv
, Full
);
12992 -- Note that the Etype of the full view is the same as the Etype of
12993 -- the partial view. In this fashion, the subtype has access to the
12994 -- correct view of the parent.
12996 Set_Has_Discriminants
(Full
, Has_Discriminants
(Full_Base
));
12997 Set_Has_Unknown_Discriminants
12998 (Full
, Has_Unknown_Discriminants
(Full_Base
));
12999 Set_First_Entity
(Full
, First_Entity
(Full_Base
));
13000 Set_Last_Entity
(Full
, Last_Entity
(Full_Base
));
13002 -- If the underlying base type is constrained, we know that the
13003 -- full view of the subtype is constrained as well (the converse
13004 -- is not necessarily true).
13006 if Is_Constrained
(Full_Base
) then
13007 Set_Is_Constrained
(Full
);
13011 Copy_Node
(Full_Base
, Full
);
13013 -- The following subtlety with the Etype of the full view needs to be
13014 -- taken into account here. One could think that it must naturally be
13015 -- set to the base type of the full base:
13017 -- Set_Etype (Full, Base_Type (Full_Base));
13019 -- so that the full view becomes a subtype of the full base when the
13020 -- latter is a base type, which must for example happen when the full
13021 -- base is declared as derived type. That's also correct if the full
13022 -- base is declared as an array type, or a floating-point type, or a
13023 -- fixed-point type, or a signed integer type, as these declarations
13024 -- create an implicit base type and a first subtype so the Etype of
13025 -- the full views must be the implicit base type. But that's wrong
13026 -- if the full base is declared as an access type, or an enumeration
13027 -- type, or a modular integer type, as these declarations directly
13028 -- create a base type, i.e. with Etype pointing to itself. Moreover
13029 -- the full base being declared in the private part, i.e. when the
13030 -- views are swapped, the end result is that the Etype of the full
13031 -- base is set to its private view in this case and that we need to
13032 -- propagate this setting to the full view in order for the subtype
13033 -- to be compatible with the base type.
13035 if Is_Base_Type
(Full_Base
)
13036 and then (Is_Derived_Type
(Full_Base
)
13037 or else Ekind
(Full_Base
) in Array_Kind
13038 or else Ekind
(Full_Base
) in Fixed_Point_Kind
13039 or else Ekind
(Full_Base
) in Float_Kind
13040 or else Ekind
(Full_Base
) in Signed_Integer_Kind
)
13042 Set_Etype
(Full
, Full_Base
);
13045 Set_Chars
(Full
, Chars
(Priv
));
13046 Set_Sloc
(Full
, Sloc
(Priv
));
13047 Conditional_Delay
(Full
, Priv
);
13050 Link_Entities
(Full
, Save_Next_Entity
);
13051 Set_Homonym
(Full
, Save_Homonym
);
13052 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
13054 if Ekind
(Full
) in Incomplete_Or_Private_Kind
then
13055 Reinit_Field_To_Zero
(Full
, F_Private_Dependents
);
13058 -- Set common attributes for all subtypes: kind, convention, etc.
13060 Mutate_Ekind
(Full
, Subtype_Kind
(Ekind
(Full_Base
)));
13061 Set_Is_Not_Self_Hidden
(Full
);
13062 Set_Convention
(Full
, Convention
(Full_Base
));
13063 Set_Is_First_Subtype
(Full
, False);
13064 Set_Scope
(Full
, Scope
(Priv
));
13065 Set_Size_Info
(Full
, Full_Base
);
13066 Copy_RM_Size
(To
=> Full
, From
=> Full_Base
);
13067 Set_Is_Itype
(Full
);
13069 -- A subtype of a private-type-without-discriminants, whose full-view
13070 -- has discriminants with default expressions, is not constrained.
13072 if not Has_Discriminants
(Priv
) then
13073 Set_Is_Constrained
(Full
, Is_Constrained
(Full_Base
));
13075 if Has_Discriminants
(Full_Base
) then
13076 Set_Discriminant_Constraint
13077 (Full
, Discriminant_Constraint
(Full_Base
));
13079 -- The partial view may have been indefinite, the full view
13082 Set_Has_Unknown_Discriminants
13083 (Full
, Has_Unknown_Discriminants
(Full_Base
));
13087 Set_First_Rep_Item
(Full
, First_Rep_Item
(Full_Base
));
13088 Set_Depends_On_Private
(Full
, Has_Private_Component
(Full
));
13090 -- Freeze the private subtype entity if its parent is delayed, and not
13091 -- already frozen. We skip this processing if the type is an anonymous
13092 -- subtype of a record component, or is the corresponding record of a
13093 -- protected type, since these are processed when the enclosing type
13094 -- is frozen. If the parent type is declared in a nested package then
13095 -- the freezing of the private and full views also happens later.
13097 if not Is_Type
(Scope
(Full
)) then
13099 and then In_Same_Source_Unit
(Full
, Full_Base
)
13100 and then Scope
(Full_Base
) /= Scope
(Full
)
13102 Set_Has_Delayed_Freeze
(Full
);
13103 Set_Has_Delayed_Freeze
(Priv
);
13106 Set_Has_Delayed_Freeze
(Full
,
13107 Has_Delayed_Freeze
(Full_Base
)
13108 and then not Is_Frozen
(Full_Base
));
13112 Set_Freeze_Node
(Full
, Empty
);
13113 Set_Is_Frozen
(Full
, False);
13115 if Has_Discriminants
(Full
) then
13116 Set_Stored_Constraint_From_Discriminant_Constraint
(Full
);
13117 Set_Stored_Constraint
(Priv
, Stored_Constraint
(Full
));
13119 if Has_Unknown_Discriminants
(Full
) then
13120 Set_Discriminant_Constraint
(Full
, No_Elist
);
13124 if Ekind
(Full_Base
) = E_Record_Type
13125 and then Has_Discriminants
(Full_Base
)
13126 and then Has_Discriminants
(Priv
) -- might not, if errors
13127 and then not Has_Unknown_Discriminants
(Priv
)
13128 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(Priv
))
13130 Create_Constrained_Components
13131 (Full
, Related_Nod
, Full_Base
, Discriminant_Constraint
(Priv
));
13133 -- If the full base is itself derived from private, build a congruent
13134 -- subtype of its underlying full view, for use by the back end.
13136 elsif Is_Private_Type
(Full_Base
)
13137 and then Present
(Underlying_Full_View
(Full_Base
))
13140 Underlying_Full_Base
: constant Entity_Id
13141 := Underlying_Full_View
(Full_Base
);
13142 Underlying_Full
: constant Entity_Id
13143 := Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
13145 Set_Is_Itype
(Underlying_Full
);
13146 Set_Associated_Node_For_Itype
(Underlying_Full
, Related_Nod
);
13147 Complete_Private_Subtype
13148 (Priv
, Underlying_Full
, Underlying_Full_Base
, Related_Nod
);
13149 Set_Underlying_Full_View
(Full
, Underlying_Full
);
13150 Set_Is_Underlying_Full_View
(Underlying_Full
);
13153 elsif Is_Record_Type
(Full_Base
) then
13155 -- Show Full is simply a renaming of Full_Base
13157 Set_Cloned_Subtype
(Full
, Full_Base
);
13158 Set_Is_Limited_Record
(Full
, Is_Limited_Record
(Full_Base
));
13160 -- Propagate predicates
13162 Propagate_Predicate_Attributes
(Full
, Full_Base
);
13165 -- It is unsafe to share the bounds of a scalar type, because the Itype
13166 -- is elaborated on demand, and if a bound is nonstatic, then different
13167 -- orders of elaboration in different units will lead to different
13168 -- external symbols.
13170 if Is_Scalar_Type
(Full_Base
) then
13171 Set_Scalar_Range
(Full
,
13172 Make_Range
(Sloc
(Related_Nod
),
13174 Duplicate_Subexpr_No_Checks
(Type_Low_Bound
(Full_Base
)),
13176 Duplicate_Subexpr_No_Checks
(Type_High_Bound
(Full_Base
))));
13178 -- This completion inherits the bounds of the full parent, but if
13179 -- the parent is an unconstrained floating point type, so is the
13182 if Is_Floating_Point_Type
(Full_Base
) then
13183 Set_Includes_Infinities
13184 (Scalar_Range
(Full
), Has_Infinities
(Full_Base
));
13188 -- ??? It seems that a lot of fields are missing that should be copied
13189 -- from Full_Base to Full. Here are some that are introduced in a
13190 -- non-disruptive way but a cleanup is necessary.
13192 if Is_Tagged_Type
(Full_Base
) then
13193 Set_Is_Tagged_Type
(Full
);
13194 Set_Is_Limited_Record
(Full
, Is_Limited_Record
(Full_Base
));
13196 Set_Direct_Primitive_Operations
13197 (Full
, Direct_Primitive_Operations
(Full_Base
));
13198 Set_No_Tagged_Streams_Pragma
13199 (Full
, No_Tagged_Streams_Pragma
(Full_Base
));
13201 if Is_Interface
(Full_Base
) then
13202 Set_Is_Interface
(Full
);
13203 Set_Is_Limited_Interface
(Full
, Is_Limited_Interface
(Full_Base
));
13206 -- Inherit class_wide type of full_base in case the partial view was
13207 -- not tagged. Otherwise it has already been created when the private
13208 -- subtype was analyzed.
13210 if No
(Class_Wide_Type
(Full
)) then
13211 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Full_Base
));
13214 -- If this is a subtype of a protected or task type, constrain its
13215 -- corresponding record, unless this is a subtype without constraints,
13216 -- i.e. a simple renaming as with an actual subtype in an instance.
13218 elsif Is_Concurrent_Type
(Full_Base
) then
13219 if Has_Discriminants
(Full
)
13220 and then Present
(Corresponding_Record_Type
(Full_Base
))
13222 not Is_Empty_Elmt_List
(Discriminant_Constraint
(Full
))
13224 Set_Corresponding_Record_Type
(Full
,
13225 Constrain_Corresponding_Record
13226 (Full
, Corresponding_Record_Type
(Full_Base
), Related_Nod
));
13229 Set_Corresponding_Record_Type
(Full
,
13230 Corresponding_Record_Type
(Full_Base
));
13234 -- Link rep item chain, and also setting of Has_Predicates from private
13235 -- subtype to full subtype, since we will need these on the full subtype
13236 -- to create the predicate function. Note that the full subtype may
13237 -- already have rep items, inherited from the full view of the base
13238 -- type, so we must be sure not to overwrite these entries.
13243 Next_Item
: Node_Id
;
13244 Priv_Item
: Node_Id
;
13247 Item
:= First_Rep_Item
(Full
);
13248 Priv_Item
:= First_Rep_Item
(Priv
);
13250 -- If no existing rep items on full type, we can just link directly
13251 -- to the list of items on the private type, if any exist.. Same if
13252 -- the rep items are only those inherited from the base
13255 or else Nkind
(Item
) /= N_Aspect_Specification
13256 or else Entity
(Item
) = Full_Base
)
13257 and then Present
(First_Rep_Item
(Priv
))
13259 Set_First_Rep_Item
(Full
, Priv_Item
);
13261 -- Otherwise, search to the end of items currently linked to the full
13262 -- subtype and append the private items to the end. However, if Priv
13263 -- and Full already have the same list of rep items, then the append
13264 -- is not done, as that would create a circularity.
13266 -- The partial view may have a predicate and the rep item lists of
13267 -- both views agree when inherited from the same ancestor. In that
13268 -- case, simply propagate the list from one view to the other.
13269 -- A more complex analysis needed here ???
13271 elsif Present
(Priv_Item
)
13272 and then Item
= Next_Rep_Item
(Priv_Item
)
13274 Set_First_Rep_Item
(Full
, Priv_Item
);
13276 elsif Item
/= Priv_Item
then
13279 Next_Item
:= Next_Rep_Item
(Item
);
13280 exit when No
(Next_Item
);
13283 -- If the private view has aspect specifications, the full view
13284 -- inherits them. Since these aspects may already have been
13285 -- attached to the full view during derivation, do not append
13286 -- them if already present.
13288 if Item
= First_Rep_Item
(Priv
) then
13294 -- And link the private type items at the end of the chain
13297 Set_Next_Rep_Item
(Item
, First_Rep_Item
(Priv
));
13302 -- Make sure Has_Predicates is set on full type if it is set on the
13303 -- private type. Note that it may already be set on the full type and
13304 -- if so, we don't want to unset it. Similarly, propagate information
13305 -- about delayed aspects, because the corresponding pragmas must be
13306 -- analyzed when one of the views is frozen. This last step is needed
13307 -- in particular when the full type is a scalar type for which an
13308 -- anonymous base type is constructed.
13310 -- The predicate functions are generated either at the freeze point
13311 -- of the type or at the end of the visible part, and we must avoid
13312 -- generating them twice.
13314 Propagate_Predicate_Attributes
(Full
, Priv
);
13316 if Has_Delayed_Aspects
(Priv
) then
13317 Set_Has_Delayed_Aspects
(Full
);
13319 end Complete_Private_Subtype
;
13321 ----------------------------
13322 -- Constant_Redeclaration --
13323 ----------------------------
13325 procedure Constant_Redeclaration
13330 Prev
: constant Entity_Id
:= Current_Entity_In_Scope
(Id
);
13331 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
13334 procedure Check_Possible_Deferred_Completion
13335 (Prev_Id
: Entity_Id
;
13336 Curr_Obj_Def
: Node_Id
);
13337 -- Determine whether the two object definitions describe the partial
13338 -- and the full view of a constrained deferred constant. Generate
13339 -- a subtype for the full view and verify that it statically matches
13340 -- the subtype of the partial view.
13342 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
);
13343 -- If deferred constant is an access type initialized with an allocator,
13344 -- check whether there is an illegal recursion in the definition,
13345 -- through a default value of some record subcomponent. This is normally
13346 -- detected when generating init procs, but requires this additional
13347 -- mechanism when expansion is disabled.
13349 ----------------------------------------
13350 -- Check_Possible_Deferred_Completion --
13351 ----------------------------------------
13353 procedure Check_Possible_Deferred_Completion
13354 (Prev_Id
: Entity_Id
;
13355 Curr_Obj_Def
: Node_Id
)
13357 Curr_Typ
: Entity_Id
;
13358 Prev_Typ
: constant Entity_Id
:= Etype
(Prev_Id
);
13359 Anon_Acc
: constant Boolean := Is_Anonymous_Access_Type
(Prev_Typ
);
13360 Mismatch
: Boolean := False;
13364 elsif Nkind
(Curr_Obj_Def
) = N_Subtype_Indication
then
13366 Loc
: constant Source_Ptr
:= Sloc
(N
);
13367 Def_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
13368 Decl
: constant Node_Id
:=
13369 Make_Subtype_Declaration
(Loc
,
13370 Defining_Identifier
=> Def_Id
,
13371 Subtype_Indication
=>
13372 Relocate_Node
(Curr_Obj_Def
));
13375 Insert_Before_And_Analyze
(N
, Decl
);
13376 Set_Etype
(Id
, Def_Id
);
13377 Curr_Typ
:= Def_Id
;
13380 Curr_Typ
:= Etype
(Curr_Obj_Def
);
13384 if Nkind
(Curr_Obj_Def
) /= N_Access_Definition
then
13386 elsif Has_Null_Exclusion
(Prev_Typ
)
13387 and then not Null_Exclusion_Present
(Curr_Obj_Def
)
13391 -- ??? Another check needed: mismatch if disagreement
13392 -- between designated types/profiles .
13395 Is_Constrained
(Prev_Typ
)
13396 and then not Subtypes_Statically_Match
(Prev_Typ
, Curr_Typ
);
13400 Error_Msg_Sloc
:= Sloc
(Prev_Id
);
13401 Error_Msg_N
("subtype does not statically match deferred "
13402 & "declaration #", N
);
13404 end Check_Possible_Deferred_Completion
;
13406 ---------------------------------
13407 -- Check_Recursive_Declaration --
13408 ---------------------------------
13410 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
) is
13414 if Is_Record_Type
(Typ
) then
13415 Comp
:= First_Component
(Typ
);
13416 while Present
(Comp
) loop
13417 if Comes_From_Source
(Comp
) then
13418 if Present
(Expression
(Parent
(Comp
)))
13419 and then Is_Entity_Name
(Expression
(Parent
(Comp
)))
13420 and then Entity
(Expression
(Parent
(Comp
))) = Prev
13422 Error_Msg_Sloc
:= Sloc
(Parent
(Comp
));
13424 ("illegal circularity with declaration for & #",
13428 elsif Is_Record_Type
(Etype
(Comp
)) then
13429 Check_Recursive_Declaration
(Etype
(Comp
));
13433 Next_Component
(Comp
);
13436 end Check_Recursive_Declaration
;
13438 -- Start of processing for Constant_Redeclaration
13441 if Nkind
(Parent
(Prev
)) = N_Object_Declaration
then
13442 if Nkind
(Object_Definition
13443 (Parent
(Prev
))) = N_Subtype_Indication
13445 -- Find type of new declaration. The constraints of the two
13446 -- views must match statically, but there is no point in
13447 -- creating an itype for the full view.
13449 if Nkind
(Obj_Def
) = N_Subtype_Indication
then
13450 Find_Type
(Subtype_Mark
(Obj_Def
));
13451 New_T
:= Entity
(Subtype_Mark
(Obj_Def
));
13454 Find_Type
(Obj_Def
);
13455 New_T
:= Entity
(Obj_Def
);
13461 -- The full view may impose a constraint, even if the partial
13462 -- view does not, so construct the subtype.
13464 New_T
:= Find_Type_Of_Object
(Obj_Def
, N
);
13469 -- Current declaration is illegal, diagnosed below in Enter_Name
13475 -- If previous full declaration or a renaming declaration exists, or if
13476 -- a homograph is present, let Enter_Name handle it, either with an
13477 -- error or with the removal of an overridden implicit subprogram.
13478 -- The previous one is a full declaration if it has an expression
13479 -- (which in the case of an aggregate is indicated by the Init flag).
13481 if Ekind
(Prev
) /= E_Constant
13482 or else Nkind
(Parent
(Prev
)) = N_Object_Renaming_Declaration
13483 or else Present
(Expression
(Parent
(Prev
)))
13484 or else Has_Init_Expression
(Parent
(Prev
))
13485 or else Present
(Full_View
(Prev
))
13489 -- Verify that types of both declarations match, or else that both types
13490 -- are anonymous access types whose designated subtypes statically match
13491 -- (as allowed in Ada 2005 by AI-385).
13493 elsif Base_Type
(Etype
(Prev
)) /= Base_Type
(New_T
)
13495 (Ekind
(Etype
(Prev
)) /= E_Anonymous_Access_Type
13496 or else Ekind
(Etype
(New_T
)) /= E_Anonymous_Access_Type
13497 or else Is_Access_Constant
(Etype
(New_T
)) /=
13498 Is_Access_Constant
(Etype
(Prev
))
13499 or else Can_Never_Be_Null
(Etype
(New_T
)) /=
13500 Can_Never_Be_Null
(Etype
(Prev
))
13501 or else Null_Exclusion_Present
(Parent
(Prev
)) /=
13502 Null_Exclusion_Present
(Parent
(Id
))
13503 or else not Subtypes_Statically_Match
13504 (Designated_Type
(Etype
(Prev
)),
13505 Designated_Type
(Etype
(New_T
))))
13507 Error_Msg_Sloc
:= Sloc
(Prev
);
13508 Error_Msg_N
("type does not match declaration#", N
);
13509 Set_Full_View
(Prev
, Id
);
13510 Set_Etype
(Id
, Any_Type
);
13512 -- A deferred constant whose type is an anonymous array is always
13513 -- illegal (unless imported). A detailed error message might be
13514 -- helpful for Ada beginners.
13516 if Nkind
(Object_Definition
(Parent
(Prev
)))
13517 = N_Constrained_Array_Definition
13518 and then Nkind
(Object_Definition
(N
))
13519 = N_Constrained_Array_Definition
13521 Error_Msg_N
("\each anonymous array is a distinct type", N
);
13522 Error_Msg_N
("a deferred constant must have a named type",
13523 Object_Definition
(Parent
(Prev
)));
13527 Null_Exclusion_Present
(Parent
(Prev
))
13528 and then not Null_Exclusion_Present
(N
)
13530 Error_Msg_Sloc
:= Sloc
(Prev
);
13531 Error_Msg_N
("null-exclusion does not match declaration#", N
);
13532 Set_Full_View
(Prev
, Id
);
13533 Set_Etype
(Id
, Any_Type
);
13535 -- If so, process the full constant declaration
13538 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
13539 -- the deferred declaration is constrained, then the subtype defined
13540 -- by the subtype_indication in the full declaration shall match it
13543 Check_Possible_Deferred_Completion
13545 Curr_Obj_Def
=> Obj_Def
);
13547 Set_Full_View
(Prev
, Id
);
13548 Set_Is_Public
(Id
, Is_Public
(Prev
));
13549 Set_Is_Internal
(Id
);
13550 Append_Entity
(Id
, Current_Scope
);
13552 -- Check ALIASED present if present before (RM 7.4(7))
13554 if Is_Aliased
(Prev
)
13555 and then not Aliased_Present
(N
)
13557 Error_Msg_Sloc
:= Sloc
(Prev
);
13558 Error_Msg_N
("ALIASED required (see declaration #)", N
);
13561 -- Check that placement is in private part and that the incomplete
13562 -- declaration appeared in the visible part.
13564 if Ekind
(Current_Scope
) = E_Package
13565 and then not In_Private_Part
(Current_Scope
)
13567 Error_Msg_Sloc
:= Sloc
(Prev
);
13569 ("full constant for declaration # must be in private part", N
);
13571 elsif Ekind
(Current_Scope
) = E_Package
13573 List_Containing
(Parent
(Prev
)) /=
13574 Visible_Declarations
(Package_Specification
(Current_Scope
))
13577 ("deferred constant must be declared in visible part",
13581 if Is_Access_Type
(T
)
13582 and then Nkind
(Expression
(N
)) = N_Allocator
13584 Check_Recursive_Declaration
(Designated_Type
(T
));
13587 -- A deferred constant is a visible entity. If type has invariants,
13588 -- verify that the initial value satisfies them. This is not done in
13589 -- GNATprove mode, as GNATprove handles invariant checks itself.
13591 if Has_Invariants
(T
)
13592 and then Present
(Invariant_Procedure
(T
))
13593 and then not GNATprove_Mode
13596 Make_Invariant_Call
(New_Occurrence_Of
(Prev
, Sloc
(N
))));
13599 end Constant_Redeclaration
;
13601 ----------------------
13602 -- Constrain_Access --
13603 ----------------------
13605 procedure Constrain_Access
13606 (Def_Id
: in out Entity_Id
;
13608 Related_Nod
: Node_Id
)
13610 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
13611 Desig_Type
: constant Entity_Id
:= Designated_Type
(T
);
13612 Desig_Subtype
: Entity_Id
;
13613 Constraint_OK
: Boolean := True;
13616 if Is_Array_Type
(Desig_Type
) then
13617 Desig_Subtype
:= Create_Itype
(E_Void
, Related_Nod
);
13618 Constrain_Array
(Desig_Subtype
, S
, Related_Nod
, Def_Id
, 'P');
13620 elsif (Is_Record_Type
(Desig_Type
)
13621 or else Is_Incomplete_Or_Private_Type
(Desig_Type
))
13622 and then not Is_Constrained
(Desig_Type
)
13624 -- If this is a constrained access definition for a record
13625 -- component, we leave the type as an unconstrained access,
13626 -- and mark the component so that its actual type is built
13627 -- at a point of use (e.g., an assignment statement). This
13628 -- is handled in Sem_Util.Build_Actual_Subtype_Of_Component.
13630 if Desig_Type
= Current_Scope
13631 and then No
(Def_Id
)
13635 (E_Void
, Related_Nod
, Scope_Id
=> Scope
(Desig_Type
));
13636 Mutate_Ekind
(Desig_Subtype
, E_Record_Subtype
);
13637 Def_Id
:= Entity
(Subtype_Mark
(S
));
13639 -- We indicate that the component has a per-object constraint
13640 -- for treatment at a point of use, even though the constraint
13641 -- may be independent of discriminants of the enclosing type.
13643 if Nkind
(Related_Nod
) = N_Component_Declaration
then
13644 Set_Has_Per_Object_Constraint
13645 (Defining_Identifier
(Related_Nod
));
13648 -- This call added to ensure that the constraint is analyzed
13649 -- (needed for a B test). Note that we still return early from
13650 -- this procedure to avoid recursive processing.
13652 Constrain_Discriminated_Type
13653 (Desig_Subtype
, S
, Related_Nod
, For_Access
=> True);
13657 -- Enforce rule that the constraint is illegal if there is an
13658 -- unconstrained view of the designated type. This means that the
13659 -- partial view (either a private type declaration or a derivation
13660 -- from a private type) has no discriminants. (Defect Report
13661 -- 8652/0008, Technical Corrigendum 1, checked by ACATS B371001).
13663 -- Rule updated for Ada 2005: The private type is said to have
13664 -- a constrained partial view, given that objects of the type
13665 -- can be declared. Furthermore, the rule applies to all access
13666 -- types, unlike the rule concerning default discriminants (see
13669 if (Ekind
(T
) = E_General_Access_Type
or else Ada_Version
>= Ada_2005
)
13670 and then Has_Private_Declaration
(Desig_Type
)
13671 and then In_Open_Scopes
(Scope
(Desig_Type
))
13672 and then Has_Discriminants
(Desig_Type
)
13675 Pack
: constant Node_Id
:=
13676 Unit_Declaration_Node
(Scope
(Desig_Type
));
13681 if Nkind
(Pack
) = N_Package_Declaration
then
13682 Decls
:= Visible_Declarations
(Specification
(Pack
));
13683 Decl
:= First
(Decls
);
13684 while Present
(Decl
) loop
13685 if (Nkind
(Decl
) = N_Private_Type_Declaration
13686 and then Chars
(Defining_Identifier
(Decl
)) =
13687 Chars
(Desig_Type
))
13690 (Nkind
(Decl
) = N_Full_Type_Declaration
13692 Chars
(Defining_Identifier
(Decl
)) =
13694 and then Is_Derived_Type
(Desig_Type
)
13696 Has_Private_Declaration
(Etype
(Desig_Type
)))
13698 if No
(Discriminant_Specifications
(Decl
)) then
13700 ("cannot constrain access type if designated "
13701 & "type has constrained partial view", S
);
13713 Desig_Subtype
:= Create_Itype
(E_Void
, Related_Nod
);
13714 Constrain_Discriminated_Type
(Desig_Subtype
, S
, Related_Nod
,
13715 For_Access
=> True);
13717 elsif Is_Concurrent_Type
(Desig_Type
)
13718 and then not Is_Constrained
(Desig_Type
)
13720 Desig_Subtype
:= Create_Itype
(E_Void
, Related_Nod
);
13721 Constrain_Concurrent
(Desig_Subtype
, S
, Related_Nod
, Desig_Type
, ' ');
13724 Error_Msg_N
("invalid constraint on access type", S
);
13726 -- We simply ignore an invalid constraint
13728 Desig_Subtype
:= Desig_Type
;
13729 Constraint_OK
:= False;
13732 if No
(Def_Id
) then
13733 Def_Id
:= Create_Itype
(E_Access_Subtype
, Related_Nod
);
13735 Mutate_Ekind
(Def_Id
, E_Access_Subtype
);
13738 if Constraint_OK
then
13739 Set_Etype
(Def_Id
, Base_Type
(T
));
13741 if Is_Private_Type
(Desig_Type
) then
13742 Prepare_Private_Subtype_Completion
(Desig_Subtype
, Related_Nod
);
13745 Set_Etype
(Def_Id
, Any_Type
);
13748 Set_Size_Info
(Def_Id
, T
);
13749 Set_Is_Constrained
(Def_Id
, Constraint_OK
);
13750 Set_Directly_Designated_Type
(Def_Id
, Desig_Subtype
);
13751 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
13752 Set_Is_Access_Constant
(Def_Id
, Is_Access_Constant
(T
));
13753 Set_Can_Never_Be_Null
(Def_Id
, Can_Never_Be_Null
(T
));
13755 Conditional_Delay
(Def_Id
, T
);
13757 -- AI-363 : Subtypes of general access types whose designated types have
13758 -- default discriminants are disallowed. In instances, the rule has to
13759 -- be checked against the actual, of which T is the subtype. In a
13760 -- generic body, the rule is checked assuming that the actual type has
13761 -- defaulted discriminants.
13763 if Ada_Version
>= Ada_2005
or else Warn_On_Ada_2005_Compatibility
then
13764 if Ekind
(Base_Type
(T
)) = E_General_Access_Type
13765 and then Has_Defaulted_Discriminants
(Desig_Type
)
13767 if Ada_Version
< Ada_2005
then
13769 ("access subtype of general access type would not " &
13770 "be allowed in Ada 2005?y?", S
);
13773 ("access subtype of general access type not allowed", S
);
13776 Error_Msg_N
("\discriminants have defaults", S
);
13778 elsif Is_Access_Type
(T
)
13779 and then Is_Generic_Type
(Desig_Type
)
13780 and then Has_Discriminants
(Desig_Type
)
13781 and then In_Package_Body
(Current_Scope
)
13783 if Ada_Version
< Ada_2005
then
13785 ("access subtype would not be allowed in generic body "
13786 & "in Ada 2005?y?", S
);
13789 ("access subtype not allowed in generic body", S
);
13793 ("\designated type is a discriminated formal", S
);
13796 end Constrain_Access
;
13798 ---------------------
13799 -- Constrain_Array --
13800 ---------------------
13802 procedure Constrain_Array
13803 (Def_Id
: in out Entity_Id
;
13805 Related_Nod
: Node_Id
;
13806 Related_Id
: Entity_Id
;
13807 Suffix
: Character)
13809 C
: constant Node_Id
:= Constraint
(SI
);
13810 Number_Of_Constraints
: constant Nat
:= List_Length
(Constraints
(C
));
13813 Constraint_OK
: Boolean := True;
13814 Is_FLB_Array_Subtype
: Boolean := False;
13817 T
:= Entity
(Subtype_Mark
(SI
));
13819 if Is_Access_Type
(T
) then
13820 T
:= Designated_Type
(T
);
13823 T
:= Underlying_Type
(T
);
13825 -- If an index constraint follows a subtype mark in a subtype indication
13826 -- then the type or subtype denoted by the subtype mark must not already
13827 -- impose an index constraint. The subtype mark must denote either an
13828 -- unconstrained array type or an access type whose designated type
13829 -- is such an array type... (RM 3.6.1)
13831 if Is_Constrained
(T
) then
13832 Error_Msg_N
("array type is already constrained", Subtype_Mark
(SI
));
13833 Constraint_OK
:= False;
13836 -- In either case, the index constraint must provide a discrete
13837 -- range for each index of the array type and the type of each
13838 -- discrete range must be the same as that of the corresponding
13839 -- index. (RM 3.6.1)
13841 if Number_Of_Constraints
/= Number_Dimensions
(T
) then
13842 Error_Msg_NE
("incorrect number of index constraints for }", C
, T
);
13843 Constraint_OK
:= False;
13846 S
:= First
(Constraints
(C
));
13847 Index
:= First_Index
(T
);
13850 -- Apply constraints to each index type
13852 for J
in 1 .. Number_Of_Constraints
loop
13853 Constrain_Index
(Index
, S
, Related_Nod
, Related_Id
, Suffix
, J
);
13855 -- If the subtype of the index has been set to indicate that
13856 -- it has a fixed lower bound, then record that the subtype's
13857 -- entity will need to be marked as being a fixed-lower-bound
13860 if S
= First
(Constraints
(C
)) then
13861 Is_FLB_Array_Subtype
:=
13862 Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
));
13864 -- If the parent subtype (or should this be Etype of that?)
13865 -- is an FLB array subtype, we flag an error, because we
13866 -- don't currently allow subtypes of such subtypes to
13867 -- specify a fixed lower bound for any of their indexes,
13868 -- even if the index of the parent subtype is a "range <>"
13871 if Is_FLB_Array_Subtype
13872 and then Is_Fixed_Lower_Bound_Array_Subtype
(T
)
13875 ("index with fixed lower bound not allowed for subtype "
13876 & "of fixed-lower-bound }", S
, T
);
13878 Is_FLB_Array_Subtype
:= False;
13881 elsif Is_FLB_Array_Subtype
13882 and then not Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
))
13885 ("constrained index not allowed for fixed-lower-bound "
13886 & "subtype of}", S
, T
);
13888 elsif not Is_FLB_Array_Subtype
13889 and then Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(S
))
13892 ("index with fixed lower bound not allowed for "
13893 & "constrained subtype of}", S
, T
);
13903 if No
(Def_Id
) then
13905 Create_Itype
(E_Array_Subtype
, Related_Nod
, Related_Id
, Suffix
);
13906 Set_Parent
(Def_Id
, Related_Nod
);
13909 Mutate_Ekind
(Def_Id
, E_Array_Subtype
);
13912 Set_Size_Info
(Def_Id
, (T
));
13913 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13914 Set_Etype
(Def_Id
, Base_Type
(T
));
13916 if Constraint_OK
then
13917 Set_First_Index
(Def_Id
, First
(Constraints
(C
)));
13919 Set_First_Index
(Def_Id
, First_Index
(T
));
13922 Set_Is_Constrained
(Def_Id
, not Is_FLB_Array_Subtype
);
13923 Set_Is_Fixed_Lower_Bound_Array_Subtype
13924 (Def_Id
, Is_FLB_Array_Subtype
);
13925 Set_Is_Aliased
(Def_Id
, Is_Aliased
(T
));
13926 Set_Is_Independent
(Def_Id
, Is_Independent
(T
));
13927 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
13929 Set_Is_Private_Composite
(Def_Id
, Is_Private_Composite
(T
));
13930 Set_Is_Limited_Composite
(Def_Id
, Is_Limited_Composite
(T
));
13932 -- A subtype does not inherit the Packed_Array_Impl_Type of is parent.
13933 -- We need to initialize the attribute because if Def_Id is previously
13934 -- analyzed through a limited_with clause, it will have the attributes
13935 -- of an incomplete type, one of which is an Elist that overlaps the
13936 -- Packed_Array_Impl_Type field.
13938 Set_Packed_Array_Impl_Type
(Def_Id
, Empty
);
13940 -- Build a freeze node if parent still needs one. Also make sure that
13941 -- the Depends_On_Private status is set because the subtype will need
13942 -- reprocessing at the time the base type does, and also we must set a
13943 -- conditional delay.
13945 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
13946 Conditional_Delay
(Def_Id
, T
);
13947 end Constrain_Array
;
13949 ------------------------------
13950 -- Constrain_Component_Type --
13951 ------------------------------
13953 function Constrain_Component_Type
13955 Constrained_Typ
: Entity_Id
;
13956 Related_Node
: Node_Id
;
13958 Constraints
: Elist_Id
) return Entity_Id
13960 Loc
: constant Source_Ptr
:= Sloc
(Constrained_Typ
);
13961 Compon_Type
: constant Entity_Id
:= Etype
(Comp
);
13963 function Build_Constrained_Array_Type
13964 (Old_Type
: Entity_Id
) return Entity_Id
;
13965 -- If Old_Type is an array type, one of whose indexes is constrained
13966 -- by a discriminant, build an Itype whose constraint replaces the
13967 -- discriminant with its value in the constraint.
13969 function Build_Constrained_Discriminated_Type
13970 (Old_Type
: Entity_Id
) return Entity_Id
;
13971 -- Ditto for record components. Handle the case where the constraint
13972 -- is a conversion of the discriminant value, introduced during
13975 function Build_Constrained_Access_Type
13976 (Old_Type
: Entity_Id
) return Entity_Id
;
13977 -- Ditto for access types. Makes use of previous two functions, to
13978 -- constrain designated type.
13980 function Is_Discriminant
(Expr
: Node_Id
) return Boolean;
13981 -- Returns True if Expr is a discriminant
13983 function Get_Discr_Value
(Discr_Expr
: Node_Id
) return Node_Id
;
13984 -- Find the value of a discriminant named by Discr_Expr in Constraints
13986 -----------------------------------
13987 -- Build_Constrained_Access_Type --
13988 -----------------------------------
13990 function Build_Constrained_Access_Type
13991 (Old_Type
: Entity_Id
) return Entity_Id
13993 Desig_Type
: constant Entity_Id
:= Designated_Type
(Old_Type
);
13995 Desig_Subtype
: Entity_Id
;
13999 -- If the original access type was not embedded in the enclosing
14000 -- type definition, there is no need to produce a new access
14001 -- subtype. In fact every access type with an explicit constraint
14002 -- generates an itype whose scope is the enclosing record.
14004 if not Is_Type
(Scope
(Old_Type
)) then
14007 elsif Is_Array_Type
(Desig_Type
) then
14008 Desig_Subtype
:= Build_Constrained_Array_Type
(Desig_Type
);
14010 elsif Has_Discriminants
(Desig_Type
) then
14012 -- This may be an access type to an enclosing record type for
14013 -- which we are constructing the constrained components. Return
14014 -- the enclosing record subtype. This is not always correct,
14015 -- but avoids infinite recursion. ???
14017 Desig_Subtype
:= Any_Type
;
14019 for J
in reverse 0 .. Scope_Stack
.Last
loop
14020 Scop
:= Scope_Stack
.Table
(J
).Entity
;
14023 and then Base_Type
(Scop
) = Base_Type
(Desig_Type
)
14025 Desig_Subtype
:= Scop
;
14028 exit when not Is_Type
(Scop
);
14031 if Desig_Subtype
= Any_Type
then
14033 Build_Constrained_Discriminated_Type
(Desig_Type
);
14040 if Desig_Subtype
/= Desig_Type
then
14042 -- The Related_Node better be here or else we won't be able
14043 -- to attach new itypes to a node in the tree.
14045 pragma Assert
(Present
(Related_Node
));
14047 Itype
:= Create_Itype
(E_Access_Subtype
, Related_Node
);
14049 Set_Etype
(Itype
, Base_Type
(Old_Type
));
14050 Set_Size_Info
(Itype
, (Old_Type
));
14051 Set_Directly_Designated_Type
(Itype
, Desig_Subtype
);
14052 Set_Depends_On_Private
(Itype
, Has_Private_Component
14054 Set_Is_Access_Constant
(Itype
, Is_Access_Constant
14057 -- The new itype needs freezing when it depends on a not frozen
14058 -- type and the enclosing subtype needs freezing.
14060 if Has_Delayed_Freeze
(Constrained_Typ
)
14061 and then not Is_Frozen
(Constrained_Typ
)
14063 Conditional_Delay
(Itype
, Base_Type
(Old_Type
));
14071 end Build_Constrained_Access_Type
;
14073 ----------------------------------
14074 -- Build_Constrained_Array_Type --
14075 ----------------------------------
14077 function Build_Constrained_Array_Type
14078 (Old_Type
: Entity_Id
) return Entity_Id
14082 Old_Index
: Node_Id
;
14083 Range_Node
: Node_Id
;
14084 Constr_List
: List_Id
;
14086 Need_To_Create_Itype
: Boolean := False;
14089 Old_Index
:= First_Index
(Old_Type
);
14090 while Present
(Old_Index
) loop
14091 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
14093 if Is_Discriminant
(Lo_Expr
)
14095 Is_Discriminant
(Hi_Expr
)
14097 Need_To_Create_Itype
:= True;
14101 Next_Index
(Old_Index
);
14104 if Need_To_Create_Itype
then
14105 Constr_List
:= New_List
;
14107 Old_Index
:= First_Index
(Old_Type
);
14108 while Present
(Old_Index
) loop
14109 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
14111 if Is_Discriminant
(Lo_Expr
) then
14112 Lo_Expr
:= Get_Discr_Value
(Lo_Expr
);
14115 if Is_Discriminant
(Hi_Expr
) then
14116 Hi_Expr
:= Get_Discr_Value
(Hi_Expr
);
14121 (Loc
, New_Copy_Tree
(Lo_Expr
), New_Copy_Tree
(Hi_Expr
));
14123 Append
(Range_Node
, To
=> Constr_List
);
14125 Next_Index
(Old_Index
);
14128 return Build_Subtype
(Related_Node
, Loc
, Old_Type
, Constr_List
);
14133 end Build_Constrained_Array_Type
;
14135 ------------------------------------------
14136 -- Build_Constrained_Discriminated_Type --
14137 ------------------------------------------
14139 function Build_Constrained_Discriminated_Type
14140 (Old_Type
: Entity_Id
) return Entity_Id
14143 Constr_List
: List_Id
;
14144 Old_Constraint
: Elmt_Id
;
14146 Need_To_Create_Itype
: Boolean := False;
14149 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
14150 while Present
(Old_Constraint
) loop
14151 Expr
:= Node
(Old_Constraint
);
14153 if Is_Discriminant
(Expr
) then
14154 Need_To_Create_Itype
:= True;
14157 -- After expansion of discriminated task types, the value
14158 -- of the discriminant may be converted to a run-time type
14159 -- for restricted run-times. Propagate the value of the
14160 -- discriminant as well, so that e.g. the secondary stack
14161 -- component has a static constraint. Necessary for LLVM.
14163 elsif Nkind
(Expr
) = N_Type_Conversion
14164 and then Is_Discriminant
(Expression
(Expr
))
14166 Need_To_Create_Itype
:= True;
14170 Next_Elmt
(Old_Constraint
);
14173 if Need_To_Create_Itype
then
14174 Constr_List
:= New_List
;
14176 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
14177 while Present
(Old_Constraint
) loop
14178 Expr
:= Node
(Old_Constraint
);
14180 if Is_Discriminant
(Expr
) then
14181 Expr
:= Get_Discr_Value
(Expr
);
14183 elsif Nkind
(Expr
) = N_Type_Conversion
14184 and then Is_Discriminant
(Expression
(Expr
))
14186 Expr
:= New_Copy_Tree
(Expr
);
14187 Set_Expression
(Expr
, Get_Discr_Value
(Expression
(Expr
)));
14190 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
14192 Next_Elmt
(Old_Constraint
);
14195 return Build_Subtype
(Related_Node
, Loc
, Old_Type
, Constr_List
);
14200 end Build_Constrained_Discriminated_Type
;
14202 ---------------------
14203 -- Get_Discr_Value --
14204 ---------------------
14206 function Get_Discr_Value
(Discr_Expr
: Node_Id
) return Node_Id
is
14207 Discr_Id
: constant Entity_Id
:= Entity
(Discr_Expr
);
14208 -- Entity of a discriminant that appear as a standalone expression in
14209 -- the constraint of a component.
14215 -- The discriminant may be declared for the type, in which case we
14216 -- find it by iterating over the list of discriminants. If the
14217 -- discriminant is inherited from a parent type, it appears as the
14218 -- corresponding discriminant of the current type. This will be the
14219 -- case when constraining an inherited component whose constraint is
14220 -- given by a discriminant of the parent.
14222 D
:= First_Discriminant
(Typ
);
14223 E
:= First_Elmt
(Constraints
);
14225 while Present
(D
) loop
14227 or else D
= CR_Discriminant
(Discr_Id
)
14228 or else Corresponding_Discriminant
(D
) = Discr_Id
14230 return New_Copy_Tree
(Node
(E
));
14233 Next_Discriminant
(D
);
14237 -- The Corresponding_Discriminant mechanism is incomplete, because
14238 -- the correspondence between new and old discriminants is not one
14239 -- to one: one new discriminant can constrain several old ones. In
14240 -- that case, scan sequentially the stored_constraint, the list of
14241 -- discriminants of the parents, and the constraints.
14243 -- Previous code checked for the present of the Stored_Constraint
14244 -- list for the derived type, but did not use it at all. Should it
14245 -- be present when the component is a discriminated task type?
14247 if Is_Derived_Type
(Typ
)
14248 and then Scope
(Discr_Id
) = Etype
(Typ
)
14250 D
:= First_Discriminant
(Etype
(Typ
));
14251 E
:= First_Elmt
(Constraints
);
14252 while Present
(D
) loop
14253 if D
= Discr_Id
then
14254 return New_Copy_Tree
(Node
(E
));
14257 Next_Discriminant
(D
);
14262 -- Something is wrong if we did not find the value
14264 raise Program_Error
;
14265 end Get_Discr_Value
;
14267 ---------------------
14268 -- Is_Discriminant --
14269 ---------------------
14271 function Is_Discriminant
(Expr
: Node_Id
) return Boolean is
14272 Discrim_Scope
: Entity_Id
;
14275 if Denotes_Discriminant
(Expr
) then
14276 Discrim_Scope
:= Scope
(Entity
(Expr
));
14278 -- Either we have a reference to one of Typ's discriminants,
14280 pragma Assert
(Discrim_Scope
= Typ
14282 -- or to the discriminants of the parent type, in the case
14283 -- of a derivation of a tagged type with variants.
14285 or else Discrim_Scope
= Etype
(Typ
)
14286 or else Full_View
(Discrim_Scope
) = Etype
(Typ
)
14288 -- or same as above for the case where the discriminants
14289 -- were declared in Typ's private view.
14291 or else (Is_Private_Type
(Discrim_Scope
)
14292 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
14294 -- or else we are deriving from the full view and the
14295 -- discriminant is declared in the private entity.
14297 or else (Is_Private_Type
(Typ
)
14298 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
14300 -- Or we are constrained the corresponding record of a
14301 -- synchronized type that completes a private declaration.
14303 or else (Is_Concurrent_Record_Type
(Typ
)
14305 Corresponding_Concurrent_Type
(Typ
) = Discrim_Scope
)
14307 -- or we have a class-wide type, in which case make sure the
14308 -- discriminant found belongs to the root type.
14310 or else (Is_Class_Wide_Type
(Typ
)
14311 and then Etype
(Typ
) = Discrim_Scope
));
14316 -- In all other cases we have something wrong
14319 end Is_Discriminant
;
14321 -- Start of processing for Constrain_Component_Type
14324 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
14325 and then Comes_From_Source
(Parent
(Comp
))
14326 and then Comes_From_Source
14327 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
14330 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
14332 return Compon_Type
;
14334 elsif Is_Array_Type
(Compon_Type
) then
14335 return Build_Constrained_Array_Type
(Compon_Type
);
14337 elsif Has_Discriminants
(Compon_Type
) then
14338 return Build_Constrained_Discriminated_Type
(Compon_Type
);
14340 elsif Is_Access_Type
(Compon_Type
) then
14341 return Build_Constrained_Access_Type
(Compon_Type
);
14344 return Compon_Type
;
14346 end Constrain_Component_Type
;
14348 --------------------------
14349 -- Constrain_Concurrent --
14350 --------------------------
14352 -- For concurrent types, the associated record value type carries the same
14353 -- discriminants, so when we constrain a concurrent type, we must constrain
14354 -- the corresponding record type as well.
14356 procedure Constrain_Concurrent
14357 (Def_Id
: in out Entity_Id
;
14359 Related_Nod
: Node_Id
;
14360 Related_Id
: Entity_Id
;
14361 Suffix
: Character)
14363 -- Retrieve Base_Type to ensure getting to the concurrent type in the
14364 -- case of a private subtype (needed when only doing semantic analysis).
14366 T_Ent
: Entity_Id
:= Base_Type
(Entity
(Subtype_Mark
(SI
)));
14370 if Is_Access_Type
(T_Ent
) then
14371 T_Ent
:= Designated_Type
(T_Ent
);
14374 T_Val
:= Corresponding_Record_Type
(T_Ent
);
14376 if Present
(T_Val
) then
14378 if No
(Def_Id
) then
14379 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
14381 -- Elaborate itype now, as it may be used in a subsequent
14382 -- synchronized operation in another scope.
14384 if Nkind
(Related_Nod
) = N_Full_Type_Declaration
then
14385 Build_Itype_Reference
(Def_Id
, Related_Nod
);
14389 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
14390 Set_First_Private_Entity
(Def_Id
, First_Private_Entity
(T_Ent
));
14392 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
14393 Set_Corresponding_Record_Type
(Def_Id
,
14394 Constrain_Corresponding_Record
(Def_Id
, T_Val
, Related_Nod
));
14397 -- If there is no associated record, expansion is disabled and this
14398 -- is a generic context. Create a subtype in any case, so that
14399 -- semantic analysis can proceed.
14401 if No
(Def_Id
) then
14402 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
14405 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
14407 end Constrain_Concurrent
;
14409 ------------------------------------
14410 -- Constrain_Corresponding_Record --
14411 ------------------------------------
14413 function Constrain_Corresponding_Record
14414 (Prot_Subt
: Entity_Id
;
14415 Corr_Rec
: Entity_Id
;
14416 Related_Nod
: Node_Id
) return Entity_Id
14418 T_Sub
: constant Entity_Id
:=
14420 (Ekind
=> E_Record_Subtype
,
14421 Related_Nod
=> Related_Nod
,
14422 Related_Id
=> Corr_Rec
,
14424 Suffix_Index
=> -1);
14427 Set_Etype
(T_Sub
, Corr_Rec
);
14428 Set_Has_Discriminants
(T_Sub
, Has_Discriminants
(Prot_Subt
));
14429 Set_Is_Tagged_Type
(T_Sub
, Is_Tagged_Type
(Corr_Rec
));
14430 Set_Is_Constrained
(T_Sub
, True);
14431 Set_First_Entity
(T_Sub
, First_Entity
(Corr_Rec
));
14432 Set_Last_Entity
(T_Sub
, Last_Entity
(Corr_Rec
));
14433 Set_Direct_Primitive_Operations
14434 (T_Sub
, Direct_Primitive_Operations
(Corr_Rec
));
14436 if Has_Discriminants
(Prot_Subt
) then -- False only if errors.
14437 Set_Discriminant_Constraint
14438 (T_Sub
, Discriminant_Constraint
(Prot_Subt
));
14439 Set_Stored_Constraint_From_Discriminant_Constraint
(T_Sub
);
14440 Create_Constrained_Components
14441 (T_Sub
, Related_Nod
, Corr_Rec
, Discriminant_Constraint
(T_Sub
));
14444 Set_Depends_On_Private
(T_Sub
, Has_Private_Component
(T_Sub
));
14446 if Ekind
(Scope
(Prot_Subt
)) /= E_Record_Type
then
14447 Conditional_Delay
(T_Sub
, Corr_Rec
);
14450 -- This is a component subtype: it will be frozen in the context of
14451 -- the enclosing record's init_proc, so that discriminant references
14452 -- are resolved to discriminals. (Note: we used to skip freezing
14453 -- altogether in that case, which caused errors downstream for
14454 -- components of a bit packed array type).
14456 Set_Has_Delayed_Freeze
(T_Sub
);
14460 end Constrain_Corresponding_Record
;
14462 -----------------------
14463 -- Constrain_Decimal --
14464 -----------------------
14466 procedure Constrain_Decimal
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14467 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14468 C
: constant Node_Id
:= Constraint
(S
);
14469 Loc
: constant Source_Ptr
:= Sloc
(C
);
14470 Range_Expr
: Node_Id
;
14471 Digits_Expr
: Node_Id
;
14476 Mutate_Ekind
(Def_Id
, E_Decimal_Fixed_Point_Subtype
);
14478 if Nkind
(C
) = N_Range_Constraint
then
14479 Range_Expr
:= Range_Expression
(C
);
14480 Digits_Val
:= Digits_Value
(T
);
14483 pragma Assert
(Nkind
(C
) = N_Digits_Constraint
);
14485 Digits_Expr
:= Digits_Expression
(C
);
14486 Analyze_And_Resolve
(Digits_Expr
, Any_Integer
);
14488 Check_Digits_Expression
(Digits_Expr
);
14489 Digits_Val
:= Expr_Value
(Digits_Expr
);
14491 if Digits_Val
> Digits_Value
(T
) then
14493 ("digits expression is incompatible with subtype", C
);
14494 Digits_Val
:= Digits_Value
(T
);
14497 if Present
(Range_Constraint
(C
)) then
14498 Range_Expr
:= Range_Expression
(Range_Constraint
(C
));
14500 Range_Expr
:= Empty
;
14504 Set_Etype
(Def_Id
, Base_Type
(T
));
14505 Set_Size_Info
(Def_Id
, (T
));
14506 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14507 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
14508 Set_Scale_Value
(Def_Id
, Scale_Value
(T
));
14509 Set_Small_Value
(Def_Id
, Small_Value
(T
));
14510 Set_Machine_Radix_10
(Def_Id
, Machine_Radix_10
(T
));
14511 Set_Digits_Value
(Def_Id
, Digits_Val
);
14513 -- Manufacture range from given digits value if no range present
14515 if No
(Range_Expr
) then
14516 Bound_Val
:= (Ureal_10
** Digits_Val
- Ureal_1
) * Small_Value
(T
);
14520 Convert_To
(T
, Make_Real_Literal
(Loc
, (-Bound_Val
))),
14522 Convert_To
(T
, Make_Real_Literal
(Loc
, Bound_Val
)));
14525 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expr
, T
);
14526 Set_Discrete_RM_Size
(Def_Id
);
14528 -- Unconditionally delay the freeze, since we cannot set size
14529 -- information in all cases correctly until the freeze point.
14531 Set_Has_Delayed_Freeze
(Def_Id
);
14532 end Constrain_Decimal
;
14534 ----------------------------------
14535 -- Constrain_Discriminated_Type --
14536 ----------------------------------
14538 procedure Constrain_Discriminated_Type
14539 (Def_Id
: Entity_Id
;
14541 Related_Nod
: Node_Id
;
14542 For_Access
: Boolean := False)
14544 E
: Entity_Id
:= Entity
(Subtype_Mark
(S
));
14547 procedure Fixup_Bad_Constraint
;
14548 -- Called after finding a bad constraint, and after having posted an
14549 -- appropriate error message. The goal is to leave type Def_Id in as
14550 -- reasonable state as possible.
14552 --------------------------
14553 -- Fixup_Bad_Constraint --
14554 --------------------------
14556 procedure Fixup_Bad_Constraint
is
14558 -- Set a reasonable Ekind for the entity, including incomplete types.
14560 Mutate_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
14562 -- Set Etype to the known type, to reduce chances of cascaded errors
14564 Set_Etype
(Def_Id
, E
);
14565 Set_Error_Posted
(Def_Id
);
14566 end Fixup_Bad_Constraint
;
14571 Constr
: Elist_Id
:= New_Elmt_List
;
14573 -- Start of processing for Constrain_Discriminated_Type
14576 C
:= Constraint
(S
);
14578 -- A discriminant constraint is only allowed in a subtype indication,
14579 -- after a subtype mark. This subtype mark must denote either a type
14580 -- with discriminants, or an access type whose designated type is a
14581 -- type with discriminants. A discriminant constraint specifies the
14582 -- values of these discriminants (RM 3.7.2(5)).
14584 T
:= Base_Type
(Entity
(Subtype_Mark
(S
)));
14586 if Is_Access_Type
(T
) then
14587 T
:= Designated_Type
(T
);
14590 -- In an instance it may be necessary to retrieve the full view of a
14591 -- type with unknown discriminants, or a full view with defaulted
14592 -- discriminants. In other contexts the constraint is illegal.
14593 -- This relaxation of legality checking may also be needed in
14594 -- compiler-generated Put_Image or streaming subprograms (hence
14595 -- the Comes_From_Source test).
14597 if (In_Instance
or not Comes_From_Source
(S
))
14598 and then Is_Private_Type
(T
)
14599 and then Present
(Full_View
(T
))
14601 (Has_Unknown_Discriminants
(T
)
14603 (not Has_Discriminants
(T
)
14604 and then Has_Defaulted_Discriminants
(Full_View
(T
))))
14606 T
:= Full_View
(T
);
14607 E
:= Full_View
(E
);
14610 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal. Avoid
14611 -- generating an error for access-to-incomplete subtypes.
14613 if Ada_Version
>= Ada_2005
14614 and then Ekind
(T
) = E_Incomplete_Type
14615 and then Nkind
(Parent
(S
)) = N_Subtype_Declaration
14616 and then not Is_Itype
(Def_Id
)
14618 -- A little sanity check: emit an error message if the type has
14619 -- discriminants to begin with. Type T may be a regular incomplete
14620 -- type or imported via a limited with clause.
14622 if Has_Discriminants
(T
)
14623 or else (From_Limited_With
(T
)
14624 and then Present
(Non_Limited_View
(T
))
14625 and then Nkind
(Parent
(Non_Limited_View
(T
))) =
14626 N_Full_Type_Declaration
14627 and then Present
(Discriminant_Specifications
14628 (Parent
(Non_Limited_View
(T
)))))
14631 ("(Ada 2005) incomplete subtype may not be constrained", C
);
14633 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
14636 Fixup_Bad_Constraint
;
14639 -- Check that the type has visible discriminants. The type may be
14640 -- a private type with unknown discriminants whose full view has
14641 -- discriminants which are invisible.
14643 elsif not Has_Discriminants
(T
)
14645 (Has_Unknown_Discriminants
(T
)
14646 and then Is_Private_Type
(T
))
14648 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
14649 Fixup_Bad_Constraint
;
14652 elsif Is_Constrained
(E
)
14653 or else (Ekind
(E
) = E_Class_Wide_Subtype
14654 and then Present
(Discriminant_Constraint
(E
)))
14656 Error_Msg_N
("type is already constrained", Subtype_Mark
(S
));
14657 Fixup_Bad_Constraint
;
14661 -- T may be an unconstrained subtype (e.g. a generic actual). Constraint
14662 -- applies to the base type.
14664 T
:= Base_Type
(T
);
14666 Constr
:= Build_Discriminant_Constraints
(T
, S
);
14668 -- If the list returned was empty we had an error in building the
14669 -- discriminant constraint. We have also already signalled an error
14670 -- in the incomplete type case
14672 if Is_Empty_Elmt_List
(Constr
) then
14673 Fixup_Bad_Constraint
;
14677 Build_Discriminated_Subtype
(T
, Def_Id
, Constr
, Related_Nod
, For_Access
);
14678 end Constrain_Discriminated_Type
;
14680 ---------------------------
14681 -- Constrain_Enumeration --
14682 ---------------------------
14684 procedure Constrain_Enumeration
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14685 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14686 C
: constant Node_Id
:= Constraint
(S
);
14689 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
14691 Set_First_Literal
(Def_Id
, First_Literal
(Base_Type
(T
)));
14692 Set_Etype
(Def_Id
, Base_Type
(T
));
14693 Set_Size_Info
(Def_Id
, (T
));
14694 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
14695 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14697 -- Inherit the chain of representation items instead of replacing it
14698 -- because Build_Derived_Enumeration_Type rewrites the declaration of
14699 -- the derived type as a subtype declaration and the former needs to
14700 -- preserve existing representation items (see Build_Derived_Type).
14702 Inherit_Rep_Item_Chain
(Def_Id
, T
);
14704 Set_Discrete_RM_Size
(Def_Id
);
14705 end Constrain_Enumeration
;
14707 ----------------------
14708 -- Constrain_Float --
14709 ----------------------
14711 procedure Constrain_Float
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14712 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14718 Mutate_Ekind
(Def_Id
, E_Floating_Point_Subtype
);
14720 Set_Etype
(Def_Id
, Base_Type
(T
));
14721 Set_Size_Info
(Def_Id
, (T
));
14722 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14724 -- Process the constraint
14726 C
:= Constraint
(S
);
14728 -- Digits constraint present
14730 if Nkind
(C
) = N_Digits_Constraint
then
14731 Check_Restriction
(No_Obsolescent_Features
, C
);
14733 if Warn_On_Obsolescent_Feature
then
14735 ("subtype digits constraint is an " &
14736 "obsolescent feature (RM J.3(8))?j?", C
);
14739 D
:= Digits_Expression
(C
);
14740 Analyze_And_Resolve
(D
, Any_Integer
);
14741 Check_Digits_Expression
(D
);
14742 Set_Digits_Value
(Def_Id
, Expr_Value
(D
));
14744 -- Check that digits value is in range. Obviously we can do this
14745 -- at compile time, but it is strictly a runtime check, and of
14746 -- course there is an ACVC test that checks this.
14748 if Digits_Value
(Def_Id
) > Digits_Value
(T
) then
14749 Error_Msg_Uint_1
:= Digits_Value
(T
);
14750 Error_Msg_N
("??digits value is too large, maximum is ^", D
);
14752 Make_Raise_Constraint_Error
(Sloc
(D
),
14753 Reason
=> CE_Range_Check_Failed
);
14754 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
14757 C
:= Range_Constraint
(C
);
14759 -- No digits constraint present
14762 Set_Digits_Value
(Def_Id
, Digits_Value
(T
));
14765 -- Range constraint present
14767 if Nkind
(C
) = N_Range_Constraint
then
14768 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14770 -- No range constraint present
14773 pragma Assert
(No
(C
));
14774 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
14777 Set_Is_Constrained
(Def_Id
);
14778 end Constrain_Float
;
14780 ---------------------
14781 -- Constrain_Index --
14782 ---------------------
14784 procedure Constrain_Index
14787 Related_Nod
: Node_Id
;
14788 Related_Id
: Entity_Id
;
14789 Suffix
: Character;
14790 Suffix_Index
: Pos
)
14792 Def_Id
: Entity_Id
;
14793 R
: Node_Id
:= Empty
;
14794 T
: constant Entity_Id
:= Etype
(Index
);
14795 Is_FLB_Index
: Boolean := False;
14799 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
, Suffix_Index
);
14800 Set_Etype
(Def_Id
, Base_Type
(T
));
14802 if Nkind
(S
) = N_Range
14804 (Nkind
(S
) = N_Attribute_Reference
14805 and then Attribute_Name
(S
) = Name_Range
)
14807 -- A Range attribute will be transformed into N_Range by Resolve
14809 -- If a range has an Empty upper bound, then remember that for later
14810 -- setting of the index subtype's Is_Fixed_Lower_Bound_Index_Subtype
14811 -- flag, and also set the upper bound of the range to the index
14812 -- subtype's upper bound rather than leaving it Empty. In truth,
14813 -- that upper bound corresponds to a box ("<>"), but it's convenient
14814 -- to set it to the upper bound to avoid needing to add special tests
14815 -- in various places for an Empty upper bound, and in any case it
14816 -- accurately characterizes the index's range of values.
14818 if Nkind
(S
) = N_Range
and then No
(High_Bound
(S
)) then
14819 Is_FLB_Index
:= True;
14820 Set_High_Bound
(S
, Type_High_Bound
(T
));
14825 Process_Range_Expr_In_Decl
(R
, T
);
14827 if not Error_Posted
(S
)
14829 (Nkind
(S
) /= N_Range
14830 or else not Covers
(T
, (Etype
(Low_Bound
(S
))))
14831 or else not Covers
(T
, (Etype
(High_Bound
(S
)))))
14833 if Base_Type
(T
) /= Any_Type
14834 and then Etype
(Low_Bound
(S
)) /= Any_Type
14835 and then Etype
(High_Bound
(S
)) /= Any_Type
14837 Error_Msg_N
("range expected", S
);
14841 elsif Nkind
(S
) = N_Subtype_Indication
then
14843 -- The parser has verified that this is a discrete indication
14845 Resolve_Discrete_Subtype_Indication
(S
, T
);
14846 Bad_Predicated_Subtype_Use
14847 ("subtype& has predicate, not allowed in index constraint",
14848 S
, Entity
(Subtype_Mark
(S
)));
14850 R
:= Range_Expression
(Constraint
(S
));
14852 -- Capture values of bounds and generate temporaries for them if
14853 -- needed, since checks may cause duplication of the expressions
14854 -- which must not be reevaluated.
14856 -- The forced evaluation removes side effects from expressions, which
14857 -- should occur also in GNATprove mode. Otherwise, we end up with
14858 -- unexpected insertions of actions at places where this is not
14859 -- supposed to occur, e.g. on default parameters of a call.
14861 if Expander_Active
or GNATprove_Mode
then
14863 (Low_Bound
(R
), Related_Id
=> Def_Id
, Is_Low_Bound
=> True);
14865 (High_Bound
(R
), Related_Id
=> Def_Id
, Is_High_Bound
=> True);
14868 elsif Nkind
(S
) = N_Discriminant_Association
then
14870 -- Syntactically valid in subtype indication
14872 Error_Msg_N
("invalid index constraint", S
);
14873 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
14876 -- Subtype_Mark case, no anonymous subtypes to construct
14881 if Is_Entity_Name
(S
) then
14882 if not Is_Type
(Entity
(S
)) then
14883 Error_Msg_N
("expect subtype mark for index constraint", S
);
14885 elsif Base_Type
(Entity
(S
)) /= Base_Type
(T
) then
14886 Wrong_Type
(S
, Base_Type
(T
));
14888 -- Check error of subtype with predicate in index constraint
14891 Bad_Predicated_Subtype_Use
14892 ("subtype& has predicate, not allowed in index constraint",
14899 Error_Msg_N
("invalid index constraint", S
);
14900 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
14905 -- Complete construction of the Itype
14907 if Is_Modular_Integer_Type
(T
) then
14908 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
14910 elsif Is_Integer_Type
(T
) then
14911 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
14914 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
14915 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
14916 Set_First_Literal
(Def_Id
, First_Literal
(T
));
14919 Set_Size_Info
(Def_Id
, (T
));
14920 Copy_RM_Size
(To
=> Def_Id
, From
=> T
);
14921 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14923 -- If this is a range for a fixed-lower-bound subtype, then set the
14924 -- index itype's low bound to the FLB and the index itype's upper bound
14925 -- to the high bound of the parent array type's index subtype. Also,
14926 -- mark the itype as an FLB index subtype.
14928 if Nkind
(S
) = N_Range
and then Is_FLB_Index
then
14931 Make_Range
(Sloc
(S
),
14932 Low_Bound
=> Low_Bound
(S
),
14933 High_Bound
=> Type_High_Bound
(T
)));
14934 Set_Is_Fixed_Lower_Bound_Index_Subtype
(Def_Id
);
14937 Set_Scalar_Range
(Def_Id
, R
);
14940 Set_Etype
(S
, Def_Id
);
14941 Set_Discrete_RM_Size
(Def_Id
);
14942 end Constrain_Index
;
14944 -----------------------
14945 -- Constrain_Integer --
14946 -----------------------
14948 procedure Constrain_Integer
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14949 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14950 C
: constant Node_Id
:= Constraint
(S
);
14953 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
14955 if Is_Modular_Integer_Type
(T
) then
14956 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
14958 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
14961 Set_Etype
(Def_Id
, Base_Type
(T
));
14962 Set_Size_Info
(Def_Id
, (T
));
14963 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14964 Set_Discrete_RM_Size
(Def_Id
);
14965 end Constrain_Integer
;
14967 ------------------------------
14968 -- Constrain_Ordinary_Fixed --
14969 ------------------------------
14971 procedure Constrain_Ordinary_Fixed
(Def_Id
: Entity_Id
; S
: Node_Id
) is
14972 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
14978 Mutate_Ekind
(Def_Id
, E_Ordinary_Fixed_Point_Subtype
);
14979 Set_Etype
(Def_Id
, Base_Type
(T
));
14980 Set_Size_Info
(Def_Id
, (T
));
14981 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14982 Set_Small_Value
(Def_Id
, Small_Value
(T
));
14984 -- Process the constraint
14986 C
:= Constraint
(S
);
14988 -- Delta constraint present
14990 if Nkind
(C
) = N_Delta_Constraint
then
14991 Check_Restriction
(No_Obsolescent_Features
, C
);
14993 if Warn_On_Obsolescent_Feature
then
14995 ("subtype delta constraint is an " &
14996 "obsolescent feature (RM J.3(7))?j?");
14999 D
:= Delta_Expression
(C
);
15000 Analyze_And_Resolve
(D
, Any_Real
);
15001 Check_Delta_Expression
(D
);
15002 Set_Delta_Value
(Def_Id
, Expr_Value_R
(D
));
15004 -- Check that delta value is in range. Obviously we can do this
15005 -- at compile time, but it is strictly a runtime check, and of
15006 -- course there is an ACVC test that checks this.
15008 if Delta_Value
(Def_Id
) < Delta_Value
(T
) then
15009 Error_Msg_N
("??delta value is too small", D
);
15011 Make_Raise_Constraint_Error
(Sloc
(D
),
15012 Reason
=> CE_Range_Check_Failed
);
15013 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
15016 C
:= Range_Constraint
(C
);
15018 -- No delta constraint present
15021 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
15024 -- Range constraint present
15026 if Nkind
(C
) = N_Range_Constraint
then
15027 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
15029 -- No range constraint present
15032 pragma Assert
(No
(C
));
15033 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
15036 Set_Discrete_RM_Size
(Def_Id
);
15038 -- Unconditionally delay the freeze, since we cannot set size
15039 -- information in all cases correctly until the freeze point.
15041 Set_Has_Delayed_Freeze
(Def_Id
);
15042 end Constrain_Ordinary_Fixed
;
15044 -----------------------
15045 -- Contain_Interface --
15046 -----------------------
15048 function Contain_Interface
15049 (Iface
: Entity_Id
;
15050 Ifaces
: Elist_Id
) return Boolean
15052 Iface_Elmt
: Elmt_Id
;
15055 if Present
(Ifaces
) then
15056 Iface_Elmt
:= First_Elmt
(Ifaces
);
15057 while Present
(Iface_Elmt
) loop
15058 if Node
(Iface_Elmt
) = Iface
then
15062 Next_Elmt
(Iface_Elmt
);
15067 end Contain_Interface
;
15069 ---------------------------
15070 -- Convert_Scalar_Bounds --
15071 ---------------------------
15073 procedure Convert_Scalar_Bounds
15075 Parent_Type
: Entity_Id
;
15076 Derived_Type
: Entity_Id
;
15079 Implicit_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
15086 -- Defend against previous errors
15088 if No
(Scalar_Range
(Derived_Type
)) then
15089 Check_Error_Detected
;
15093 Lo
:= Build_Scalar_Bound
15094 (Type_Low_Bound
(Derived_Type
),
15095 Parent_Type
, Implicit_Base
);
15097 Hi
:= Build_Scalar_Bound
15098 (Type_High_Bound
(Derived_Type
),
15099 Parent_Type
, Implicit_Base
);
15106 Set_Includes_Infinities
(Rng
, Has_Infinities
(Derived_Type
));
15108 Set_Parent
(Rng
, N
);
15109 Set_Scalar_Range
(Derived_Type
, Rng
);
15111 -- Analyze the bounds
15113 Analyze_And_Resolve
(Lo
, Implicit_Base
);
15114 Analyze_And_Resolve
(Hi
, Implicit_Base
);
15116 -- Analyze the range itself, except that we do not analyze it if
15117 -- the bounds are real literals, and we have a fixed-point type.
15118 -- The reason for this is that we delay setting the bounds in this
15119 -- case till we know the final Small and Size values (see circuit
15120 -- in Freeze.Freeze_Fixed_Point_Type for further details).
15122 if Is_Fixed_Point_Type
(Parent_Type
)
15123 and then Nkind
(Lo
) = N_Real_Literal
15124 and then Nkind
(Hi
) = N_Real_Literal
15128 -- Here we do the analysis of the range
15130 -- Note: we do this manually, since if we do a normal Analyze and
15131 -- Resolve call, there are problems with the conversions used for
15132 -- the derived type range.
15135 Set_Etype
(Rng
, Implicit_Base
);
15136 Set_Analyzed
(Rng
, True);
15138 end Convert_Scalar_Bounds
;
15140 -------------------
15141 -- Copy_And_Swap --
15142 -------------------
15144 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
) is
15146 -- Initialize new full declaration entity by copying the pertinent
15147 -- fields of the corresponding private declaration entity.
15149 -- We temporarily set Ekind to a value appropriate for a type to
15150 -- avoid assert failures in Einfo from checking for setting type
15151 -- attributes on something that is not a type. Ekind (Priv) is an
15152 -- appropriate choice, since it allowed the attributes to be set
15153 -- in the first place. This Ekind value will be modified later.
15155 Mutate_Ekind
(Full
, Ekind
(Priv
));
15157 -- Also set Etype temporarily to Any_Type, again, in the absence
15158 -- of errors, it will be properly reset, and if there are errors,
15159 -- then we want a value of Any_Type to remain.
15161 Set_Etype
(Full
, Any_Type
);
15163 -- Now start copying attributes
15165 Set_Has_Discriminants
(Full
, Has_Discriminants
(Priv
));
15167 if Has_Discriminants
(Full
) then
15168 Set_Discriminant_Constraint
(Full
, Discriminant_Constraint
(Priv
));
15169 Set_Stored_Constraint
(Full
, Stored_Constraint
(Priv
));
15172 Set_First_Rep_Item
(Full
, First_Rep_Item
(Priv
));
15173 Set_Homonym
(Full
, Homonym
(Priv
));
15174 Set_Is_Immediately_Visible
(Full
, Is_Immediately_Visible
(Priv
));
15175 Set_Is_Public
(Full
, Is_Public
(Priv
));
15176 Set_Is_Pure
(Full
, Is_Pure
(Priv
));
15177 Set_Is_Tagged_Type
(Full
, Is_Tagged_Type
(Priv
));
15178 Set_Has_Pragma_Unmodified
(Full
, Has_Pragma_Unmodified
(Priv
));
15179 Set_Has_Pragma_Unreferenced
(Full
, Has_Pragma_Unreferenced
(Priv
));
15180 Set_Has_Pragma_Unreferenced_Objects
15181 (Full
, Has_Pragma_Unreferenced_Objects
15184 Conditional_Delay
(Full
, Priv
);
15186 if Is_Tagged_Type
(Full
) then
15187 Set_Direct_Primitive_Operations
15188 (Full
, Direct_Primitive_Operations
(Priv
));
15189 Set_No_Tagged_Streams_Pragma
15190 (Full
, No_Tagged_Streams_Pragma
(Priv
));
15192 if Is_Base_Type
(Priv
) then
15193 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Priv
));
15197 Set_Is_Volatile
(Full
, Is_Volatile
(Priv
));
15198 Set_Treat_As_Volatile
(Full
, Treat_As_Volatile
(Priv
));
15199 Set_Scope
(Full
, Scope
(Priv
));
15200 Set_Prev_Entity
(Full
, Prev_Entity
(Priv
));
15201 Set_Next_Entity
(Full
, Next_Entity
(Priv
));
15202 Set_First_Entity
(Full
, First_Entity
(Priv
));
15203 Set_Last_Entity
(Full
, Last_Entity
(Priv
));
15205 -- If access types have been recorded for later handling, keep them in
15206 -- the full view so that they get handled when the full view freeze
15207 -- node is expanded.
15209 if Present
(Freeze_Node
(Priv
))
15210 and then Present
(Access_Types_To_Process
(Freeze_Node
(Priv
)))
15212 Ensure_Freeze_Node
(Full
);
15213 Set_Access_Types_To_Process
15214 (Freeze_Node
(Full
),
15215 Access_Types_To_Process
(Freeze_Node
(Priv
)));
15218 -- Swap the two entities. Now Private is the full type entity and Full
15219 -- is the private one. They will be swapped back at the end of the
15220 -- private part. This swapping ensures that the entity that is visible
15221 -- in the private part is the full declaration.
15223 Exchange_Entities
(Priv
, Full
);
15224 Set_Is_Not_Self_Hidden
(Priv
);
15225 Append_Entity
(Full
, Scope
(Full
));
15228 -------------------------------------
15229 -- Copy_Array_Base_Type_Attributes --
15230 -------------------------------------
15232 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
) is
15234 Set_Component_Alignment
(T1
, Component_Alignment
(T2
));
15235 Set_Component_Type
(T1
, Component_Type
(T2
));
15236 Set_Component_Size
(T1
, Component_Size
(T2
));
15237 Set_Has_Controlled_Component
(T1
, Has_Controlled_Component
(T2
));
15238 Set_Has_Non_Standard_Rep
(T1
, Has_Non_Standard_Rep
(T2
));
15239 Propagate_Concurrent_Flags
(T1
, T2
);
15240 Set_Is_Packed
(T1
, Is_Packed
(T2
));
15241 Set_Has_Aliased_Components
(T1
, Has_Aliased_Components
(T2
));
15242 Set_Has_Atomic_Components
(T1
, Has_Atomic_Components
(T2
));
15243 Set_Has_Independent_Components
(T1
, Has_Independent_Components
(T2
));
15244 Set_Has_Volatile_Components
(T1
, Has_Volatile_Components
(T2
));
15245 end Copy_Array_Base_Type_Attributes
;
15247 -----------------------------------
15248 -- Copy_Array_Subtype_Attributes --
15249 -----------------------------------
15251 -- Note that we used to copy Packed_Array_Impl_Type too here, but we now
15252 -- let it be recreated during freezing for the sake of better debug info.
15254 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
) is
15256 Set_Size_Info
(T1
, T2
);
15258 Set_First_Index
(T1
, First_Index
(T2
));
15259 Set_Is_Aliased
(T1
, Is_Aliased
(T2
));
15260 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
15261 Set_Is_Independent
(T1
, Is_Independent
(T2
));
15262 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
15263 Set_Is_Volatile_Full_Access
(T1
, Is_Volatile_Full_Access
(T2
));
15264 Set_Treat_As_Volatile
(T1
, Treat_As_Volatile
(T2
));
15265 Set_Is_Constrained
(T1
, Is_Constrained
(T2
));
15266 Set_Depends_On_Private
(T1
, Has_Private_Component
(T2
));
15267 Inherit_Rep_Item_Chain
(T1
, T2
);
15268 Set_Convention
(T1
, Convention
(T2
));
15269 Set_Is_Limited_Composite
(T1
, Is_Limited_Composite
(T2
));
15270 Set_Is_Private_Composite
(T1
, Is_Private_Composite
(T2
));
15271 end Copy_Array_Subtype_Attributes
;
15273 -----------------------------------
15274 -- Create_Constrained_Components --
15275 -----------------------------------
15277 procedure Create_Constrained_Components
15279 Decl_Node
: Node_Id
;
15281 Constraints
: Elist_Id
)
15283 Loc
: constant Source_Ptr
:= Sloc
(Subt
);
15284 Comp_List
: constant Elist_Id
:= New_Elmt_List
;
15285 Parent_Type
: constant Entity_Id
:= Etype
(Typ
);
15287 Assoc_List
: List_Id
;
15288 Discr_Val
: Elmt_Id
;
15292 Is_Static
: Boolean := True;
15293 Is_Compile_Time_Known
: Boolean := True;
15295 procedure Collect_Fixed_Components
(Typ
: Entity_Id
);
15296 -- Collect parent type components that do not appear in a variant part
15298 procedure Create_All_Components
;
15299 -- Iterate over Comp_List to create the components of the subtype
15301 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
;
15302 -- Creates a new component from Old_Compon, copying all the fields from
15303 -- it, including its Etype, inserts the new component in the Subt entity
15304 -- chain and returns the new component.
15306 function Is_Variant_Record
(T
: Entity_Id
) return Boolean;
15307 -- If true, and discriminants are static, collect only components from
15308 -- variants selected by discriminant values.
15310 ------------------------------
15311 -- Collect_Fixed_Components --
15312 ------------------------------
15314 procedure Collect_Fixed_Components
(Typ
: Entity_Id
) is
15316 -- Build association list for discriminants, and find components of
15317 -- the variant part selected by the values of the discriminants.
15319 Assoc_List
:= New_List
;
15321 Old_C
:= First_Discriminant
(Typ
);
15322 Discr_Val
:= First_Elmt
(Constraints
);
15323 while Present
(Old_C
) loop
15324 Append_To
(Assoc_List
,
15325 Make_Component_Association
(Loc
,
15326 Choices
=> New_List
(New_Occurrence_Of
(Old_C
, Loc
)),
15327 Expression
=> New_Copy
(Node
(Discr_Val
))));
15329 Next_Elmt
(Discr_Val
);
15330 Next_Discriminant
(Old_C
);
15333 -- The tag and the possible parent component are unconditionally in
15336 if Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
15337 Old_C
:= First_Component
(Typ
);
15338 while Present
(Old_C
) loop
15339 if Chars
(Old_C
) in Name_uTag | Name_uParent
then
15340 Append_Elmt
(Old_C
, Comp_List
);
15343 Next_Component
(Old_C
);
15346 end Collect_Fixed_Components
;
15348 ---------------------------
15349 -- Create_All_Components --
15350 ---------------------------
15352 procedure Create_All_Components
is
15356 Comp
:= First_Elmt
(Comp_List
);
15357 while Present
(Comp
) loop
15358 Old_C
:= Node
(Comp
);
15359 New_C
:= Create_Component
(Old_C
);
15363 Constrain_Component_Type
15364 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
15365 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15369 end Create_All_Components
;
15371 ----------------------
15372 -- Create_Component --
15373 ----------------------
15375 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
is
15376 New_Compon
: constant Entity_Id
:= New_Copy
(Old_Compon
);
15379 if Ekind
(Old_Compon
) = E_Discriminant
15380 and then Is_Completely_Hidden
(Old_Compon
)
15382 -- This is a shadow discriminant created for a discriminant of
15383 -- the parent type, which needs to be present in the subtype.
15384 -- Give the shadow discriminant an internal name that cannot
15385 -- conflict with that of visible components.
15387 Set_Chars
(New_Compon
, New_Internal_Name
('C'));
15390 -- Set the parent so we have a proper link for freezing etc. This is
15391 -- not a real parent pointer, since of course our parent does not own
15392 -- up to us and reference us, we are an illegitimate child of the
15393 -- original parent.
15395 Set_Parent
(New_Compon
, Parent
(Old_Compon
));
15397 -- We do not want this node marked as Comes_From_Source, since
15398 -- otherwise it would get first class status and a separate cross-
15399 -- reference line would be generated. Illegitimate children do not
15400 -- rate such recognition.
15402 Set_Comes_From_Source
(New_Compon
, False);
15404 -- But it is a real entity, and a birth certificate must be properly
15405 -- registered by entering it into the entity list, and setting its
15406 -- scope to the given subtype. This turns out to be useful for the
15407 -- LLVM code generator, but that scope is not used otherwise.
15409 Enter_Name
(New_Compon
);
15410 Set_Scope
(New_Compon
, Subt
);
15413 end Create_Component
;
15415 -----------------------
15416 -- Is_Variant_Record --
15417 -----------------------
15419 function Is_Variant_Record
(T
: Entity_Id
) return Boolean is
15420 Decl
: constant Node_Id
:= Parent
(T
);
15422 return Nkind
(Decl
) = N_Full_Type_Declaration
15423 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
15424 and then Present
(Component_List
(Type_Definition
(Decl
)))
15426 Present
(Variant_Part
(Component_List
(Type_Definition
(Decl
))));
15427 end Is_Variant_Record
;
15429 -- Start of processing for Create_Constrained_Components
15432 pragma Assert
(Subt
/= Base_Type
(Subt
));
15433 pragma Assert
(Typ
= Base_Type
(Typ
));
15435 Set_First_Entity
(Subt
, Empty
);
15436 Set_Last_Entity
(Subt
, Empty
);
15438 -- Check whether constraint is fully static, in which case we can
15439 -- optimize the list of components.
15441 Discr_Val
:= First_Elmt
(Constraints
);
15442 while Present
(Discr_Val
) loop
15443 if not Is_OK_Static_Expression
(Node
(Discr_Val
)) then
15444 Is_Static
:= False;
15446 if not Compile_Time_Known_Value
(Node
(Discr_Val
)) then
15447 Is_Compile_Time_Known
:= False;
15452 Next_Elmt
(Discr_Val
);
15455 Set_Has_Static_Discriminants
(Subt
, Is_Static
);
15459 -- Inherit the discriminants of the parent type
15461 Add_Discriminants
: declare
15467 Old_C
:= First_Discriminant
(Typ
);
15469 while Present
(Old_C
) loop
15470 Num_Disc
:= Num_Disc
+ 1;
15471 New_C
:= Create_Component
(Old_C
);
15472 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15473 Next_Discriminant
(Old_C
);
15476 -- For an untagged derived subtype, the number of discriminants may
15477 -- be smaller than the number of inherited discriminants, because
15478 -- several of them may be renamed by a single new discriminant or
15479 -- constrained. In this case, add the hidden discriminants back into
15480 -- the subtype, because they need to be present if the optimizer of
15481 -- the GCC 4.x back-end decides to break apart assignments between
15482 -- objects using the parent view into member-wise assignments.
15486 if Is_Derived_Type
(Typ
)
15487 and then not Is_Tagged_Type
(Typ
)
15489 Old_C
:= First_Stored_Discriminant
(Typ
);
15491 while Present
(Old_C
) loop
15492 Num_Stor
:= Num_Stor
+ 1;
15493 Next_Stored_Discriminant
(Old_C
);
15497 if Num_Stor
> Num_Disc
then
15499 -- Find out multiple uses of new discriminants, and add hidden
15500 -- components for the extra renamed discriminants. We recognize
15501 -- multiple uses through the Corresponding_Discriminant of a
15502 -- new discriminant: if it constrains several old discriminants,
15503 -- this field points to the last one in the parent type. The
15504 -- stored discriminants of the derived type have the same name
15505 -- as those of the parent.
15509 New_Discr
: Entity_Id
;
15510 Old_Discr
: Entity_Id
;
15513 Constr
:= First_Elmt
(Stored_Constraint
(Typ
));
15514 Old_Discr
:= First_Stored_Discriminant
(Typ
);
15515 while Present
(Constr
) loop
15516 if Is_Entity_Name
(Node
(Constr
))
15517 and then Ekind
(Entity
(Node
(Constr
))) = E_Discriminant
15519 New_Discr
:= Entity
(Node
(Constr
));
15521 if Chars
(Corresponding_Discriminant
(New_Discr
)) /=
15524 -- The new discriminant has been used to rename a
15525 -- subsequent old discriminant. Introduce a shadow
15526 -- component for the current old discriminant.
15528 New_C
:= Create_Component
(Old_Discr
);
15529 Set_Original_Record_Component
(New_C
, Old_Discr
);
15533 -- The constraint has eliminated the old discriminant.
15534 -- Introduce a shadow component.
15536 New_C
:= Create_Component
(Old_Discr
);
15537 Set_Original_Record_Component
(New_C
, Old_Discr
);
15540 Next_Elmt
(Constr
);
15541 Next_Stored_Discriminant
(Old_Discr
);
15545 end Add_Discriminants
;
15547 if Is_Compile_Time_Known
15548 and then Is_Variant_Record
(Typ
)
15550 Collect_Fixed_Components
(Typ
);
15553 Component_List
(Type_Definition
(Parent
(Typ
))),
15554 Governed_By
=> Assoc_List
,
15556 Report_Errors
=> Errors
,
15557 Allow_Compile_Time
=> True);
15558 pragma Assert
(not Errors
or else Serious_Errors_Detected
> 0);
15560 Create_All_Components
;
15562 -- If the subtype declaration is created for a tagged type derivation
15563 -- with constraints, we retrieve the record definition of the parent
15564 -- type to select the components of the proper variant.
15566 elsif Is_Compile_Time_Known
15567 and then Is_Tagged_Type
(Typ
)
15568 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
15570 Nkind
(Type_Definition
(Parent
(Typ
))) = N_Derived_Type_Definition
15571 and then Is_Variant_Record
(Parent_Type
)
15573 Collect_Fixed_Components
(Typ
);
15576 Component_List
(Type_Definition
(Parent
(Parent_Type
))),
15577 Governed_By
=> Assoc_List
,
15579 Report_Errors
=> Errors
,
15580 Allow_Compile_Time
=> True);
15582 -- Note: previously there was a check at this point that no errors
15583 -- were detected. As a consequence of AI05-220 there may be an error
15584 -- if an inherited discriminant that controls a variant has a non-
15585 -- static constraint.
15587 -- If the tagged derivation has a type extension, collect all the
15588 -- new relevant components therein via Gather_Components.
15590 if Present
(Record_Extension_Part
(Type_Definition
(Parent
(Typ
))))
15595 (Record_Extension_Part
(Type_Definition
(Parent
(Typ
)))),
15596 Governed_By
=> Assoc_List
,
15598 Report_Errors
=> Errors
,
15599 Allow_Compile_Time
=> True,
15600 Include_Interface_Tag
=> True);
15603 Create_All_Components
;
15606 -- If discriminants are not static, or if this is a multi-level type
15607 -- extension, we have to include all components of the parent type.
15609 Old_C
:= First_Component
(Typ
);
15610 while Present
(Old_C
) loop
15611 New_C
:= Create_Component
(Old_C
);
15615 Constrain_Component_Type
15616 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
15617 Set_Is_Public
(New_C
, Is_Public
(Subt
));
15619 Next_Component
(Old_C
);
15624 end Create_Constrained_Components
;
15626 ------------------------------------------
15627 -- Decimal_Fixed_Point_Type_Declaration --
15628 ------------------------------------------
15630 procedure Decimal_Fixed_Point_Type_Declaration
15634 Loc
: constant Source_Ptr
:= Sloc
(Def
);
15635 Digs_Expr
: constant Node_Id
:= Digits_Expression
(Def
);
15636 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
15637 Max_Digits
: constant Nat
:=
15638 (if System_Max_Integer_Size
= 128 then 38 else 18);
15639 -- Maximum number of digits that can be represented in an integer
15641 Implicit_Base
: Entity_Id
;
15648 Check_Restriction
(No_Fixed_Point
, Def
);
15650 -- Create implicit base type
15653 Create_Itype
(E_Decimal_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
15654 Set_Etype
(Implicit_Base
, Implicit_Base
);
15656 -- Analyze and process delta expression
15658 Analyze_And_Resolve
(Delta_Expr
, Universal_Real
);
15660 Check_Delta_Expression
(Delta_Expr
);
15661 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
15663 -- Check delta is power of 10, and determine scale value from it
15669 Scale_Val
:= Uint_0
;
15672 if Val
< Ureal_1
then
15673 while Val
< Ureal_1
loop
15674 Val
:= Val
* Ureal_10
;
15675 Scale_Val
:= Scale_Val
+ 1;
15678 if Scale_Val
> Max_Digits
then
15679 Error_Msg_Uint_1
:= UI_From_Int
(Max_Digits
);
15680 Error_Msg_N
("scale exceeds maximum value of ^", Def
);
15681 Scale_Val
:= UI_From_Int
(Max_Digits
);
15685 while Val
> Ureal_1
loop
15686 Val
:= Val
/ Ureal_10
;
15687 Scale_Val
:= Scale_Val
- 1;
15690 if Scale_Val
< -Max_Digits
then
15691 Error_Msg_Uint_1
:= UI_From_Int
(-Max_Digits
);
15692 Error_Msg_N
("scale is less than minimum value of ^", Def
);
15693 Scale_Val
:= UI_From_Int
(-Max_Digits
);
15697 if Val
/= Ureal_1
then
15698 Error_Msg_N
("delta expression must be a power of 10", Def
);
15699 Delta_Val
:= Ureal_10
** (-Scale_Val
);
15703 -- Set delta, scale and small (small = delta for decimal type)
15705 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
15706 Set_Scale_Value
(Implicit_Base
, Scale_Val
);
15707 Set_Small_Value
(Implicit_Base
, Delta_Val
);
15709 -- Analyze and process digits expression
15711 Analyze_And_Resolve
(Digs_Expr
, Any_Integer
);
15712 Check_Digits_Expression
(Digs_Expr
);
15713 Digs_Val
:= Expr_Value
(Digs_Expr
);
15715 if Digs_Val
> Max_Digits
then
15716 Error_Msg_Uint_1
:= UI_From_Int
(Max_Digits
);
15717 Error_Msg_N
("digits value out of range, maximum is ^", Digs_Expr
);
15718 Digs_Val
:= UI_From_Int
(Max_Digits
);
15721 Set_Digits_Value
(Implicit_Base
, Digs_Val
);
15722 Bound_Val
:= UR_From_Uint
(10 ** Digs_Val
- 1) * Delta_Val
;
15724 -- Set range of base type from digits value for now. This will be
15725 -- expanded to represent the true underlying base range by Freeze.
15727 Set_Fixed_Range
(Implicit_Base
, Loc
, -Bound_Val
, Bound_Val
);
15729 -- Note: We leave Esize unset for now, size will be set at freeze
15730 -- time. We have to do this for ordinary fixed-point, because the size
15731 -- depends on the specified small, and we might as well do the same for
15732 -- decimal fixed-point.
15734 pragma Assert
(not Known_Esize
(Implicit_Base
));
15736 -- If there are bounds given in the declaration use them as the
15737 -- bounds of the first named subtype.
15739 if Present
(Real_Range_Specification
(Def
)) then
15741 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
15742 Low
: constant Node_Id
:= Low_Bound
(RRS
);
15743 High
: constant Node_Id
:= High_Bound
(RRS
);
15748 Analyze_And_Resolve
(Low
, Any_Real
);
15749 Analyze_And_Resolve
(High
, Any_Real
);
15750 Check_Real_Bound
(Low
);
15751 Check_Real_Bound
(High
);
15752 Low_Val
:= Expr_Value_R
(Low
);
15753 High_Val
:= Expr_Value_R
(High
);
15755 if Low_Val
< (-Bound_Val
) then
15757 ("range low bound too small for digits value", Low
);
15758 Low_Val
:= -Bound_Val
;
15761 if High_Val
> Bound_Val
then
15763 ("range high bound too large for digits value", High
);
15764 High_Val
:= Bound_Val
;
15767 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
15770 -- If no explicit range, use range that corresponds to given
15771 -- digits value. This will end up as the final range for the
15775 Set_Fixed_Range
(T
, Loc
, -Bound_Val
, Bound_Val
);
15778 -- Complete entity for first subtype. The inheritance of the rep item
15779 -- chain ensures that SPARK-related pragmas are not clobbered when the
15780 -- decimal fixed point type acts as a full view of a private type.
15782 Mutate_Ekind
(T
, E_Decimal_Fixed_Point_Subtype
);
15783 Set_Etype
(T
, Implicit_Base
);
15784 Set_Size_Info
(T
, Implicit_Base
);
15785 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
15786 Set_Digits_Value
(T
, Digs_Val
);
15787 Set_Delta_Value
(T
, Delta_Val
);
15788 Set_Small_Value
(T
, Delta_Val
);
15789 Set_Scale_Value
(T
, Scale_Val
);
15790 Set_Is_Constrained
(T
);
15791 end Decimal_Fixed_Point_Type_Declaration
;
15793 -----------------------------------
15794 -- Derive_Progenitor_Subprograms --
15795 -----------------------------------
15797 procedure Derive_Progenitor_Subprograms
15798 (Parent_Type
: Entity_Id
;
15799 Tagged_Type
: Entity_Id
)
15804 Iface_Alias
: Entity_Id
;
15805 Iface_Elmt
: Elmt_Id
;
15806 Iface_Subp
: Entity_Id
;
15807 New_Subp
: Entity_Id
:= Empty
;
15808 Prim_Elmt
: Elmt_Id
;
15813 pragma Assert
(Ada_Version
>= Ada_2005
15814 and then Is_Record_Type
(Tagged_Type
)
15815 and then Is_Tagged_Type
(Tagged_Type
)
15816 and then Has_Interfaces
(Tagged_Type
));
15818 -- Step 1: Transfer to the full-view primitives associated with the
15819 -- partial-view that cover interface primitives. Conceptually this
15820 -- work should be done later by Process_Full_View; done here to
15821 -- simplify its implementation at later stages. It can be safely
15822 -- done here because interfaces must be visible in the partial and
15823 -- private view (RM 7.3(7.3/2)).
15825 -- Small optimization: This work is only required if the parent may
15826 -- have entities whose Alias attribute reference an interface primitive.
15827 -- Such a situation may occur if the parent is an abstract type and the
15828 -- primitive has not been yet overridden or if the parent is a generic
15829 -- formal type covering interfaces.
15831 -- If the tagged type is not abstract, it cannot have abstract
15832 -- primitives (the only entities in the list of primitives of
15833 -- non-abstract tagged types that can reference abstract primitives
15834 -- through its Alias attribute are the internal entities that have
15835 -- attribute Interface_Alias, and these entities are generated later
15836 -- by Add_Internal_Interface_Entities).
15838 if In_Private_Part
(Current_Scope
)
15839 and then (Is_Abstract_Type
(Parent_Type
)
15841 Is_Generic_Type
(Parent_Type
))
15843 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
15844 while Present
(Elmt
) loop
15845 Subp
:= Node
(Elmt
);
15847 -- At this stage it is not possible to have entities in the list
15848 -- of primitives that have attribute Interface_Alias.
15850 pragma Assert
(No
(Interface_Alias
(Subp
)));
15852 Typ
:= Find_Dispatching_Type
(Ultimate_Alias
(Subp
));
15854 if Is_Interface
(Typ
) then
15855 E
:= Find_Primitive_Covering_Interface
15856 (Tagged_Type
=> Tagged_Type
,
15857 Iface_Prim
=> Subp
);
15860 and then Find_Dispatching_Type
(Ultimate_Alias
(E
)) /= Typ
15862 Replace_Elmt
(Elmt
, E
);
15863 Remove_Homonym
(Subp
);
15871 -- Step 2: Add primitives of progenitors that are not implemented by
15872 -- parents of Tagged_Type.
15874 if Present
(Interfaces
(Base_Type
(Tagged_Type
))) then
15875 Iface_Elmt
:= First_Elmt
(Interfaces
(Base_Type
(Tagged_Type
)));
15876 while Present
(Iface_Elmt
) loop
15877 Iface
:= Node
(Iface_Elmt
);
15879 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
15880 while Present
(Prim_Elmt
) loop
15881 Iface_Subp
:= Node
(Prim_Elmt
);
15882 Iface_Alias
:= Ultimate_Alias
(Iface_Subp
);
15884 -- Exclude derivation of predefined primitives except those
15885 -- that come from source, or are inherited from one that comes
15886 -- from source. Required to catch declarations of equality
15887 -- operators of interfaces. For example:
15889 -- type Iface is interface;
15890 -- function "=" (Left, Right : Iface) return Boolean;
15892 if not Is_Predefined_Dispatching_Operation
(Iface_Subp
)
15893 or else Comes_From_Source
(Iface_Alias
)
15896 Find_Primitive_Covering_Interface
15897 (Tagged_Type
=> Tagged_Type
,
15898 Iface_Prim
=> Iface_Subp
);
15900 -- If not found we derive a new primitive leaving its alias
15901 -- attribute referencing the interface primitive.
15905 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
15907 -- Ada 2012 (AI05-0197): If the covering primitive's name
15908 -- differs from the name of the interface primitive then it
15909 -- is a private primitive inherited from a parent type. In
15910 -- such case, given that Tagged_Type covers the interface,
15911 -- the inherited private primitive becomes visible. For such
15912 -- purpose we add a new entity that renames the inherited
15913 -- private primitive.
15915 elsif Chars
(E
) /= Chars
(Iface_Subp
) then
15916 pragma Assert
(Has_Suffix
(E
, 'P'));
15918 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
15919 Set_Alias
(New_Subp
, E
);
15920 Set_Is_Abstract_Subprogram
(New_Subp
,
15921 Is_Abstract_Subprogram
(E
));
15923 -- Propagate to the full view interface entities associated
15924 -- with the partial view.
15926 elsif In_Private_Part
(Current_Scope
)
15927 and then Present
(Alias
(E
))
15928 and then Alias
(E
) = Iface_Subp
15930 List_Containing
(Parent
(E
)) /=
15931 Private_Declarations
15933 (Unit_Declaration_Node
(Current_Scope
)))
15935 Append_Elmt
(E
, Primitive_Operations
(Tagged_Type
));
15939 Next_Elmt
(Prim_Elmt
);
15942 Next_Elmt
(Iface_Elmt
);
15945 end Derive_Progenitor_Subprograms
;
15947 -----------------------
15948 -- Derive_Subprogram --
15949 -----------------------
15951 procedure Derive_Subprogram
15952 (New_Subp
: out Entity_Id
;
15953 Parent_Subp
: Entity_Id
;
15954 Derived_Type
: Entity_Id
;
15955 Parent_Type
: Entity_Id
;
15956 Actual_Subp
: Entity_Id
:= Empty
)
15958 Formal
: Entity_Id
;
15959 -- Formal parameter of parent primitive operation
15961 Formal_Of_Actual
: Entity_Id
;
15962 -- Formal parameter of actual operation, when the derivation is to
15963 -- create a renaming for a primitive operation of an actual in an
15966 New_Formal
: Entity_Id
;
15967 -- Formal of inherited operation
15969 Visible_Subp
: Entity_Id
:= Parent_Subp
;
15971 function Is_Private_Overriding
return Boolean;
15972 -- If Subp is a private overriding of a visible operation, the inherited
15973 -- operation derives from the overridden op (even though its body is the
15974 -- overriding one) and the inherited operation is visible now. See
15975 -- sem_disp to see the full details of the handling of the overridden
15976 -- subprogram, which is removed from the list of primitive operations of
15977 -- the type. The overridden subprogram is saved locally in Visible_Subp,
15978 -- and used to diagnose abstract operations that need overriding in the
15981 procedure Replace_Type
(Id
, New_Id
: Entity_Id
);
15982 -- Set the Etype of New_Id to the appropriate subtype determined from
15983 -- the Etype of Id, following (RM 3.4 (18, 19, 20, 21)). Id is either
15984 -- the parent type's primitive subprogram or one of its formals, and
15985 -- New_Id is the corresponding entity for the derived type. When the
15986 -- Etype of Id is an anonymous access type, create a new access type
15987 -- designating the derived type.
15989 procedure Set_Derived_Name
;
15990 -- This procedure sets the appropriate Chars name for New_Subp. This
15991 -- is normally just a copy of the parent name. An exception arises for
15992 -- type support subprograms, where the name is changed to reflect the
15993 -- name of the derived type, e.g. if type foo is derived from type bar,
15994 -- then a procedure barDA is derived with a name fooDA.
15996 ---------------------------
15997 -- Is_Private_Overriding --
15998 ---------------------------
16000 function Is_Private_Overriding
return Boolean is
16004 -- If the parent is not a dispatching operation there is no
16005 -- need to investigate overridings
16007 if not Is_Dispatching_Operation
(Parent_Subp
) then
16011 -- The visible operation that is overridden is a homonym of the
16012 -- parent subprogram. We scan the homonym chain to find the one
16013 -- whose alias is the subprogram we are deriving.
16015 Prev
:= Current_Entity
(Parent_Subp
);
16016 while Present
(Prev
) loop
16017 if Ekind
(Prev
) = Ekind
(Parent_Subp
)
16018 and then Alias
(Prev
) = Parent_Subp
16019 and then Scope
(Parent_Subp
) = Scope
(Prev
)
16020 and then not Is_Hidden
(Prev
)
16022 Visible_Subp
:= Prev
;
16026 Prev
:= Homonym
(Prev
);
16030 end Is_Private_Overriding
;
16036 procedure Replace_Type
(Id
, New_Id
: Entity_Id
) is
16037 Id_Type
: constant Entity_Id
:= Etype
(Id
);
16038 Par
: constant Node_Id
:= Parent
(Derived_Type
);
16041 -- When the type is an anonymous access type, create a new access
16042 -- type designating the derived type. This itype must be elaborated
16043 -- at the point of the derivation, not on subsequent calls that may
16044 -- be out of the proper scope for Gigi, so we insert a reference to
16045 -- it after the derivation.
16047 if Ekind
(Id_Type
) = E_Anonymous_Access_Type
then
16049 Acc_Type
: Entity_Id
;
16050 Desig_Typ
: Entity_Id
:= Designated_Type
(Id_Type
);
16053 if Ekind
(Desig_Typ
) = E_Record_Type_With_Private
16054 and then Present
(Full_View
(Desig_Typ
))
16055 and then not Is_Private_Type
(Parent_Type
)
16057 Desig_Typ
:= Full_View
(Desig_Typ
);
16060 if Base_Type
(Desig_Typ
) = Base_Type
(Parent_Type
)
16062 -- Ada 2005 (AI-251): Handle also derivations of abstract
16063 -- interface primitives.
16065 or else (Is_Interface
(Desig_Typ
)
16066 and then not Is_Class_Wide_Type
(Desig_Typ
))
16068 Acc_Type
:= New_Copy
(Id_Type
);
16069 Set_Etype
(Acc_Type
, Acc_Type
);
16070 Set_Scope
(Acc_Type
, New_Subp
);
16072 -- Set size of anonymous access type. If we have an access
16073 -- to an unconstrained array, this is a fat pointer, so it
16074 -- is sizes at twice addtress size.
16076 if Is_Array_Type
(Desig_Typ
)
16077 and then not Is_Constrained
(Desig_Typ
)
16079 Init_Size
(Acc_Type
, 2 * System_Address_Size
);
16081 -- Other cases use a thin pointer
16084 Init_Size
(Acc_Type
, System_Address_Size
);
16087 -- Set remaining characterstics of anonymous access type
16089 Reinit_Alignment
(Acc_Type
);
16090 Set_Directly_Designated_Type
(Acc_Type
, Derived_Type
);
16092 Set_Etype
(New_Id
, Acc_Type
);
16093 Set_Scope
(New_Id
, New_Subp
);
16095 -- Create a reference to it
16097 Build_Itype_Reference
(Acc_Type
, Parent
(Derived_Type
));
16100 Set_Etype
(New_Id
, Id_Type
);
16104 -- In Ada2012, a formal may have an incomplete type but the type
16105 -- derivation that inherits the primitive follows the full view.
16107 elsif Base_Type
(Id_Type
) = Base_Type
(Parent_Type
)
16109 (Ekind
(Id_Type
) = E_Record_Type_With_Private
16110 and then Present
(Full_View
(Id_Type
))
16112 Base_Type
(Full_View
(Id_Type
)) = Base_Type
(Parent_Type
))
16114 (Ada_Version
>= Ada_2012
16115 and then Ekind
(Id_Type
) = E_Incomplete_Type
16116 and then Full_View
(Id_Type
) = Parent_Type
)
16118 -- Constraint checks on formals are generated during expansion,
16119 -- based on the signature of the original subprogram. The bounds
16120 -- of the derived type are not relevant, and thus we can use
16121 -- the base type for the formals. However, the return type may be
16122 -- used in a context that requires that the proper static bounds
16123 -- be used (a case statement, for example) and for those cases
16124 -- we must use the derived type (first subtype), not its base.
16126 -- If the derived_type_definition has no constraints, we know that
16127 -- the derived type has the same constraints as the first subtype
16128 -- of the parent, and we can also use it rather than its base,
16129 -- which can lead to more efficient code.
16131 if Id_Type
= Parent_Type
then
16132 if Is_Scalar_Type
(Parent_Type
)
16134 Subtypes_Statically_Compatible
(Parent_Type
, Derived_Type
)
16136 Set_Etype
(New_Id
, Derived_Type
);
16138 elsif Nkind
(Par
) = N_Full_Type_Declaration
16140 Nkind
(Type_Definition
(Par
)) = N_Derived_Type_Definition
16143 (Subtype_Indication
(Type_Definition
(Par
)))
16145 Set_Etype
(New_Id
, Derived_Type
);
16148 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
16152 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
16156 Set_Etype
(New_Id
, Id_Type
);
16160 ----------------------
16161 -- Set_Derived_Name --
16162 ----------------------
16164 procedure Set_Derived_Name
is
16165 Nm
: constant TSS_Name_Type
:= Get_TSS_Name
(Parent_Subp
);
16167 if Nm
= TSS_Null
then
16168 Set_Chars
(New_Subp
, Chars
(Parent_Subp
));
16170 Set_Chars
(New_Subp
, Make_TSS_Name
(Base_Type
(Derived_Type
), Nm
));
16172 end Set_Derived_Name
;
16174 -- Start of processing for Derive_Subprogram
16177 New_Subp
:= New_Entity
(Nkind
(Parent_Subp
), Sloc
(Derived_Type
));
16178 Mutate_Ekind
(New_Subp
, Ekind
(Parent_Subp
));
16179 Set_Is_Not_Self_Hidden
(New_Subp
);
16181 -- Check whether the inherited subprogram is a private operation that
16182 -- should be inherited but not yet made visible. Such subprograms can
16183 -- become visible at a later point (e.g., the private part of a public
16184 -- child unit) via Declare_Inherited_Private_Subprograms. If the
16185 -- following predicate is true, then this is not such a private
16186 -- operation and the subprogram simply inherits the name of the parent
16187 -- subprogram. Note the special check for the names of controlled
16188 -- operations, which are currently exempted from being inherited with
16189 -- a hidden name because they must be findable for generation of
16190 -- implicit run-time calls.
16192 if not Is_Hidden
(Parent_Subp
)
16193 or else Is_Internal
(Parent_Subp
)
16194 or else Is_Private_Overriding
16195 or else Is_Internal_Name
(Chars
(Parent_Subp
))
16196 or else (Is_Controlled
(Parent_Type
)
16197 and then Chars
(Parent_Subp
) in Name_Adjust
16203 -- An inherited dispatching equality will be overridden by an internally
16204 -- generated one, or by an explicit one, so preserve its name and thus
16205 -- its entry in the dispatch table. Otherwise, if Parent_Subp is a
16206 -- private operation it may become invisible if the full view has
16207 -- progenitors, and the dispatch table will be malformed.
16208 -- We check that the type is limited to handle the anomalous declaration
16209 -- of Limited_Controlled, which is derived from a non-limited type, and
16210 -- which is handled specially elsewhere as well.
16212 elsif Chars
(Parent_Subp
) = Name_Op_Eq
16213 and then Is_Dispatching_Operation
(Parent_Subp
)
16214 and then Etype
(Parent_Subp
) = Standard_Boolean
16215 and then not Is_Limited_Type
(Etype
(First_Formal
(Parent_Subp
)))
16217 Etype
(First_Formal
(Parent_Subp
)) =
16218 Etype
(Next_Formal
(First_Formal
(Parent_Subp
)))
16222 -- If parent is hidden, this can be a regular derivation if the
16223 -- parent is immediately visible in a non-instantiating context,
16224 -- or if we are in the private part of an instance. This test
16225 -- should still be refined ???
16227 -- The test for In_Instance_Not_Visible avoids inheriting the derived
16228 -- operation as a non-visible operation in cases where the parent
16229 -- subprogram might not be visible now, but was visible within the
16230 -- original generic, so it would be wrong to make the inherited
16231 -- subprogram non-visible now. (Not clear if this test is fully
16232 -- correct; are there any cases where we should declare the inherited
16233 -- operation as not visible to avoid it being overridden, e.g., when
16234 -- the parent type is a generic actual with private primitives ???)
16236 -- (they should be treated the same as other private inherited
16237 -- subprograms, but it's not clear how to do this cleanly). ???
16239 elsif (In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
16240 and then Is_Immediately_Visible
(Parent_Subp
)
16241 and then not In_Instance
)
16242 or else In_Instance_Not_Visible
16246 -- Ada 2005 (AI-251): Regular derivation if the parent subprogram
16247 -- overrides an interface primitive because interface primitives
16248 -- must be visible in the partial view of the parent (RM 7.3 (7.3/2))
16250 elsif Ada_Version
>= Ada_2005
16251 and then Is_Dispatching_Operation
(Parent_Subp
)
16252 and then Present
(Covered_Interface_Op
(Parent_Subp
))
16256 -- Otherwise, the type is inheriting a private operation, so enter it
16257 -- with a special name so it can't be overridden. See also below, where
16258 -- we check for this case, and if so avoid setting Requires_Overriding.
16261 Set_Chars
(New_Subp
, New_External_Name
(Chars
(Parent_Subp
), 'P'));
16264 Set_Parent
(New_Subp
, Parent
(Derived_Type
));
16266 if Present
(Actual_Subp
) then
16267 Replace_Type
(Actual_Subp
, New_Subp
);
16269 Replace_Type
(Parent_Subp
, New_Subp
);
16272 Conditional_Delay
(New_Subp
, Parent_Subp
);
16274 -- If we are creating a renaming for a primitive operation of an
16275 -- actual of a generic derived type, we must examine the signature
16276 -- of the actual primitive, not that of the generic formal, which for
16277 -- example may be an interface. However the name and initial value
16278 -- of the inherited operation are those of the formal primitive.
16280 Formal
:= First_Formal
(Parent_Subp
);
16282 if Present
(Actual_Subp
) then
16283 Formal_Of_Actual
:= First_Formal
(Actual_Subp
);
16285 Formal_Of_Actual
:= Empty
;
16288 while Present
(Formal
) loop
16289 New_Formal
:= New_Copy
(Formal
);
16291 -- Extra formals are not inherited from a limited interface parent
16292 -- since limitedness is not inherited in such case (AI-419) and this
16293 -- affects the extra formals.
16295 if Is_Limited_Interface
(Parent_Type
) then
16296 Set_Extra_Formal
(New_Formal
, Empty
);
16297 Set_Extra_Accessibility
(New_Formal
, Empty
);
16300 -- Normally we do not go copying parents, but in the case of
16301 -- formals, we need to link up to the declaration (which is the
16302 -- parameter specification), and it is fine to link up to the
16303 -- original formal's parameter specification in this case.
16305 Set_Parent
(New_Formal
, Parent
(Formal
));
16306 Append_Entity
(New_Formal
, New_Subp
);
16308 if Present
(Formal_Of_Actual
) then
16309 Replace_Type
(Formal_Of_Actual
, New_Formal
);
16310 Next_Formal
(Formal_Of_Actual
);
16312 Replace_Type
(Formal
, New_Formal
);
16315 Next_Formal
(Formal
);
16318 -- Extra formals are shared between the parent subprogram and this
16319 -- internal entity built by Derive_Subprogram (implicit in the above
16320 -- copy of formals), unless the parent type is a limited interface type;
16321 -- hence we must inherit also the reference to the first extra formal.
16322 -- When the parent type is an interface, the extra formals will be added
16323 -- when the tagged type is frozen (see Expand_Freeze_Record_Type).
16325 if not Is_Limited_Interface
(Parent_Type
) then
16326 Set_Extra_Formals
(New_Subp
, Extra_Formals
(Parent_Subp
));
16328 if Ekind
(New_Subp
) = E_Function
then
16329 Set_Extra_Accessibility_Of_Result
(New_Subp
,
16330 Extra_Accessibility_Of_Result
(Parent_Subp
));
16334 -- If this derivation corresponds to a tagged generic actual, then
16335 -- primitive operations rename those of the actual. Otherwise the
16336 -- primitive operations rename those of the parent type, If the parent
16337 -- renames an intrinsic operator, so does the new subprogram. We except
16338 -- concatenation, which is always properly typed, and does not get
16339 -- expanded as other intrinsic operations.
16341 if No
(Actual_Subp
) then
16342 if Is_Intrinsic_Subprogram
(Parent_Subp
) then
16343 Set_Convention
(New_Subp
, Convention_Intrinsic
);
16344 Set_Is_Intrinsic_Subprogram
(New_Subp
);
16346 if Present
(Alias
(Parent_Subp
))
16347 and then Chars
(Parent_Subp
) /= Name_Op_Concat
16349 Set_Alias
(New_Subp
, Alias
(Parent_Subp
));
16351 Set_Alias
(New_Subp
, Parent_Subp
);
16355 Set_Alias
(New_Subp
, Parent_Subp
);
16359 Set_Alias
(New_Subp
, Actual_Subp
);
16362 Copy_Strub_Mode
(New_Subp
, Alias
(New_Subp
));
16364 -- Derived subprograms of a tagged type must inherit the convention
16365 -- of the parent subprogram (a requirement of AI95-117). Derived
16366 -- subprograms of untagged types simply get convention Ada by default.
16368 -- If the derived type is a tagged generic formal type with unknown
16369 -- discriminants, its convention is intrinsic (RM 6.3.1 (8)).
16371 -- However, if the type is derived from a generic formal, the further
16372 -- inherited subprogram has the convention of the non-generic ancestor.
16373 -- Otherwise there would be no way to override the operation.
16374 -- (This is subject to forthcoming ARG discussions).
16376 if Is_Tagged_Type
(Derived_Type
) then
16377 if Is_Generic_Type
(Derived_Type
)
16378 and then Has_Unknown_Discriminants
(Derived_Type
)
16380 Set_Convention
(New_Subp
, Convention_Intrinsic
);
16383 if Is_Generic_Type
(Parent_Type
)
16384 and then Has_Unknown_Discriminants
(Parent_Type
)
16386 Set_Convention
(New_Subp
, Convention
(Alias
(Parent_Subp
)));
16388 Set_Convention
(New_Subp
, Convention
(Parent_Subp
));
16393 -- Predefined controlled operations retain their name even if the parent
16394 -- is hidden (see above), but they are not primitive operations if the
16395 -- ancestor is not visible, for example if the parent is a private
16396 -- extension completed with a controlled extension. Note that a full
16397 -- type that is controlled can break privacy: the flag Is_Controlled is
16398 -- set on both views of the type.
16400 if Is_Controlled
(Parent_Type
)
16401 and then Chars
(Parent_Subp
) in Name_Initialize
16404 and then Is_Hidden
(Parent_Subp
)
16405 and then not Is_Visibly_Controlled
(Parent_Type
)
16407 Set_Is_Hidden
(New_Subp
);
16410 Set_Is_Imported
(New_Subp
, Is_Imported
(Parent_Subp
));
16411 Set_Is_Exported
(New_Subp
, Is_Exported
(Parent_Subp
));
16413 if Ekind
(Parent_Subp
) = E_Procedure
then
16414 Set_Is_Valued_Procedure
16415 (New_Subp
, Is_Valued_Procedure
(Parent_Subp
));
16417 Set_Has_Controlling_Result
16418 (New_Subp
, Has_Controlling_Result
(Parent_Subp
));
16421 -- No_Return must be inherited properly. If this is overridden in the
16422 -- case of a dispatching operation, then the check is made later in
16423 -- Check_Abstract_Overriding that the overriding operation is also
16424 -- No_Return (no such check is required for the nondispatching case).
16426 Set_No_Return
(New_Subp
, No_Return
(Parent_Subp
));
16428 -- If the parent subprogram is marked as Ghost, then so is the derived
16429 -- subprogram. The ghost policy for the derived subprogram is set from
16430 -- the effective ghost policy at the point of derived type declaration.
16432 if Is_Ghost_Entity
(Parent_Subp
) then
16433 Set_Is_Ghost_Entity
(New_Subp
);
16436 -- A derived function with a controlling result is abstract. If the
16437 -- Derived_Type is a nonabstract formal generic derived type, then
16438 -- inherited operations are not abstract: the required check is done at
16439 -- instantiation time. If the derivation is for a generic actual, the
16440 -- function is not abstract unless the actual is.
16442 if Is_Generic_Type
(Derived_Type
)
16443 and then not Is_Abstract_Type
(Derived_Type
)
16447 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
16448 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2). Note
16449 -- that functions with controlling access results of record extensions
16450 -- with a null extension part require overriding (AI95-00391/06).
16452 -- Ada 2022 (AI12-0042): Similarly, set those properties for
16453 -- implementing the rule of RM 7.3.2(6.1/4).
16455 -- A subprogram subject to pragma Extensions_Visible with value False
16456 -- requires overriding if the subprogram has at least one controlling
16457 -- OUT parameter (SPARK RM 6.1.7(6)).
16459 elsif Ada_Version
>= Ada_2005
16460 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
16461 or else (Is_Tagged_Type
(Derived_Type
)
16462 and then Etype
(New_Subp
) = Derived_Type
16463 and then not Is_Null_Extension
(Derived_Type
))
16464 or else (Is_Tagged_Type
(Derived_Type
)
16465 and then Ekind
(Etype
(New_Subp
)) =
16466 E_Anonymous_Access_Type
16467 and then Designated_Type
(Etype
(New_Subp
)) =
16469 or else (Comes_From_Source
(Alias
(New_Subp
))
16470 and then Is_EVF_Procedure
(Alias
(New_Subp
)))
16472 -- AI12-0042: Set Requires_Overriding when a type extension
16473 -- inherits a private operation that is visible at the
16474 -- point of extension (Has_Private_Ancestor is False) from
16475 -- an ancestor that has Type_Invariant'Class, and when the
16476 -- type extension is in a visible part (the latter as
16477 -- clarified by AI12-0382).
16480 (not Has_Private_Ancestor
(Derived_Type
)
16481 and then Has_Invariants
(Parent_Type
)
16483 Present
(Get_Pragma
(Parent_Type
, Pragma_Invariant
))
16486 (Get_Pragma
(Parent_Type
, Pragma_Invariant
))
16487 and then Is_Private_Primitive
(Parent_Subp
)
16488 and then In_Visible_Part
(Scope
(Derived_Type
))))
16490 and then No
(Actual_Subp
)
16492 if not Is_Tagged_Type
(Derived_Type
)
16493 or else Is_Abstract_Type
(Derived_Type
)
16494 or else Is_Abstract_Subprogram
(Alias
(New_Subp
))
16496 Set_Is_Abstract_Subprogram
(New_Subp
);
16498 -- If the Chars of the new subprogram is different from that of the
16499 -- parent's one, it means that we entered it with a special name so
16500 -- it can't be overridden (see above). In that case we had better not
16501 -- *require* it to be overridden. This is the case where the parent
16502 -- type inherited the operation privately, so there's no danger of
16503 -- dangling dispatching.
16505 elsif Chars
(New_Subp
) = Chars
(Alias
(New_Subp
)) then
16506 Set_Requires_Overriding
(New_Subp
);
16509 elsif Ada_Version
< Ada_2005
16510 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
16511 or else (Is_Tagged_Type
(Derived_Type
)
16512 and then Etype
(New_Subp
) = Derived_Type
16513 and then No
(Actual_Subp
)))
16515 Set_Is_Abstract_Subprogram
(New_Subp
);
16517 -- AI05-0097 : an inherited operation that dispatches on result is
16518 -- abstract if the derived type is abstract, even if the parent type
16519 -- is concrete and the derived type is a null extension.
16521 elsif Has_Controlling_Result
(Alias
(New_Subp
))
16522 and then Is_Abstract_Type
(Etype
(New_Subp
))
16524 Set_Is_Abstract_Subprogram
(New_Subp
);
16526 -- Finally, if the parent type is abstract we must verify that all
16527 -- inherited operations are either non-abstract or overridden, or that
16528 -- the derived type itself is abstract (this check is performed at the
16529 -- end of a package declaration, in Check_Abstract_Overriding). A
16530 -- private overriding in the parent type will not be visible in the
16531 -- derivation if we are not in an inner package or in a child unit of
16532 -- the parent type, in which case the abstractness of the inherited
16533 -- operation is carried to the new subprogram.
16535 elsif Is_Abstract_Type
(Parent_Type
)
16536 and then not In_Open_Scopes
(Scope
(Parent_Type
))
16537 and then Is_Private_Overriding
16538 and then Is_Abstract_Subprogram
(Visible_Subp
)
16540 if No
(Actual_Subp
) then
16541 Set_Alias
(New_Subp
, Visible_Subp
);
16542 Set_Is_Abstract_Subprogram
(New_Subp
, True);
16545 -- If this is a derivation for an instance of a formal derived
16546 -- type, abstractness comes from the primitive operation of the
16547 -- actual, not from the operation inherited from the ancestor.
16549 Set_Is_Abstract_Subprogram
16550 (New_Subp
, Is_Abstract_Subprogram
(Actual_Subp
));
16554 New_Overloaded_Entity
(New_Subp
, Derived_Type
);
16556 -- RM 6.1.1(15): If a subprogram inherits nonconforming class-wide
16557 -- preconditions and the derived type is abstract, the derived operation
16558 -- is abstract as well if parent subprogram is not abstract or null.
16560 if Is_Abstract_Type
(Derived_Type
)
16561 and then Has_Non_Trivial_Precondition
(Parent_Subp
)
16562 and then Present
(Interfaces
(Derived_Type
))
16565 -- Add useful attributes of subprogram before the freeze point,
16566 -- in case freezing is delayed or there are previous errors.
16568 Set_Is_Dispatching_Operation
(New_Subp
);
16571 Iface_Prim
: constant Entity_Id
:= Covered_Interface_Op
(New_Subp
);
16574 if Present
(Iface_Prim
)
16575 and then Has_Non_Trivial_Precondition
(Iface_Prim
)
16577 Set_Is_Abstract_Subprogram
(New_Subp
);
16582 -- Check for case of a derived subprogram for the instantiation of a
16583 -- formal derived tagged type, if so mark the subprogram as dispatching
16584 -- and inherit the dispatching attributes of the actual subprogram. The
16585 -- derived subprogram is effectively renaming of the actual subprogram,
16586 -- so it needs to have the same attributes as the actual.
16588 if Present
(Actual_Subp
)
16589 and then Is_Dispatching_Operation
(Actual_Subp
)
16591 Set_Is_Dispatching_Operation
(New_Subp
);
16593 if Present
(DTC_Entity
(Actual_Subp
)) then
16594 Set_DTC_Entity
(New_Subp
, DTC_Entity
(Actual_Subp
));
16595 Set_DT_Position_Value
(New_Subp
, DT_Position
(Actual_Subp
));
16599 -- Indicate that a derived subprogram does not require a body and that
16600 -- it does not require processing of default expressions.
16602 Set_Has_Completion
(New_Subp
);
16603 Set_Default_Expressions_Processed
(New_Subp
);
16605 if Ekind
(New_Subp
) = E_Function
then
16606 Set_Mechanism
(New_Subp
, Mechanism
(Parent_Subp
));
16607 Set_Returns_By_Ref
(New_Subp
, Returns_By_Ref
(Parent_Subp
));
16610 -- Ada 2022 (AI12-0279): If a Yield aspect is specified True for a
16611 -- primitive subprogram S of a type T, then the aspect is inherited
16612 -- by the corresponding primitive subprogram of each descendant of T.
16614 if Is_Tagged_Type
(Derived_Type
)
16615 and then Is_Dispatching_Operation
(New_Subp
)
16616 and then Has_Yield_Aspect
(Alias
(New_Subp
))
16618 Set_Has_Yield_Aspect
(New_Subp
, Has_Yield_Aspect
(Alias
(New_Subp
)));
16621 Set_Is_Ada_2022_Only
(New_Subp
, Is_Ada_2022_Only
(Parent_Subp
));
16622 end Derive_Subprogram
;
16624 ------------------------
16625 -- Derive_Subprograms --
16626 ------------------------
16628 procedure Derive_Subprograms
16629 (Parent_Type
: Entity_Id
;
16630 Derived_Type
: Entity_Id
;
16631 Generic_Actual
: Entity_Id
:= Empty
)
16633 Op_List
: constant Elist_Id
:=
16634 Collect_Primitive_Operations
(Parent_Type
);
16636 function Check_Derived_Type
return Boolean;
16637 -- Check that all the entities derived from Parent_Type are found in
16638 -- the list of primitives of Derived_Type exactly in the same order.
16640 procedure Derive_Interface_Subprogram
16641 (New_Subp
: out Entity_Id
;
16643 Actual_Subp
: Entity_Id
);
16644 -- Derive New_Subp from the ultimate alias of the parent subprogram Subp
16645 -- (which is an interface primitive). If Generic_Actual is present then
16646 -- Actual_Subp is the actual subprogram corresponding with the generic
16647 -- subprogram Subp.
16649 ------------------------
16650 -- Check_Derived_Type --
16651 ------------------------
16653 function Check_Derived_Type
return Boolean is
16655 Derived_Elmt
: Elmt_Id
;
16656 Derived_Op
: Entity_Id
;
16657 Derived_Ops
: Elist_Id
;
16658 Parent_Elmt
: Elmt_Id
;
16659 Parent_Op
: Entity_Id
;
16662 -- Traverse list of entities in the current scope searching for
16663 -- an incomplete type whose full-view is derived type.
16665 E
:= First_Entity
(Scope
(Derived_Type
));
16666 while Present
(E
) and then E
/= Derived_Type
loop
16667 if Ekind
(E
) = E_Incomplete_Type
16668 and then Present
(Full_View
(E
))
16669 and then Full_View
(E
) = Derived_Type
16671 -- Disable this test if Derived_Type completes an incomplete
16672 -- type because in such case more primitives can be added
16673 -- later to the list of primitives of Derived_Type by routine
16674 -- Process_Incomplete_Dependents.
16682 Derived_Ops
:= Collect_Primitive_Operations
(Derived_Type
);
16684 Derived_Elmt
:= First_Elmt
(Derived_Ops
);
16685 Parent_Elmt
:= First_Elmt
(Op_List
);
16686 while Present
(Parent_Elmt
) loop
16687 Parent_Op
:= Node
(Parent_Elmt
);
16688 Derived_Op
:= Node
(Derived_Elmt
);
16690 -- At this early stage Derived_Type has no entities with attribute
16691 -- Interface_Alias. In addition, such primitives are always
16692 -- located at the end of the list of primitives of Parent_Type.
16693 -- Therefore, if found we can safely stop processing pending
16696 exit when Present
(Interface_Alias
(Parent_Op
));
16698 -- Handle hidden entities
16700 if not Is_Predefined_Dispatching_Operation
(Parent_Op
)
16701 and then Is_Hidden
(Parent_Op
)
16703 if Present
(Derived_Op
)
16704 and then Primitive_Names_Match
(Parent_Op
, Derived_Op
)
16706 Next_Elmt
(Derived_Elmt
);
16711 or else Ekind
(Parent_Op
) /= Ekind
(Derived_Op
)
16712 or else not Primitive_Names_Match
(Parent_Op
, Derived_Op
)
16717 Next_Elmt
(Derived_Elmt
);
16720 Next_Elmt
(Parent_Elmt
);
16724 end Check_Derived_Type
;
16726 ---------------------------------
16727 -- Derive_Interface_Subprogram --
16728 ---------------------------------
16730 procedure Derive_Interface_Subprogram
16731 (New_Subp
: out Entity_Id
;
16733 Actual_Subp
: Entity_Id
)
16735 Iface_Subp
: constant Entity_Id
:= Ultimate_Alias
(Subp
);
16736 Iface_Type
: constant Entity_Id
:= Find_Dispatching_Type
(Iface_Subp
);
16739 pragma Assert
(Is_Interface
(Iface_Type
));
16742 (New_Subp
=> New_Subp
,
16743 Parent_Subp
=> Iface_Subp
,
16744 Derived_Type
=> Derived_Type
,
16745 Parent_Type
=> Iface_Type
,
16746 Actual_Subp
=> Actual_Subp
);
16748 -- Given that this new interface entity corresponds with a primitive
16749 -- of the parent that was not overridden we must leave it associated
16750 -- with its parent primitive to ensure that it will share the same
16751 -- dispatch table slot when overridden. We must set the Alias to Subp
16752 -- (instead of Iface_Subp), and we must fix Is_Abstract_Subprogram
16753 -- (in case we inherited Subp from Iface_Type via a nonabstract
16754 -- generic formal type).
16756 if No
(Actual_Subp
) then
16757 Set_Alias
(New_Subp
, Subp
);
16760 T
: Entity_Id
:= Find_Dispatching_Type
(Subp
);
16762 while Etype
(T
) /= T
loop
16763 if Is_Generic_Type
(T
) and then not Is_Abstract_Type
(T
) then
16764 Set_Is_Abstract_Subprogram
(New_Subp
, False);
16772 -- For instantiations this is not needed since the previous call to
16773 -- Derive_Subprogram leaves the entity well decorated.
16776 pragma Assert
(Alias
(New_Subp
) = Actual_Subp
);
16779 end Derive_Interface_Subprogram
;
16783 Alias_Subp
: Entity_Id
;
16784 Act_List
: Elist_Id
;
16785 Act_Elmt
: Elmt_Id
;
16786 Act_Subp
: Entity_Id
:= Empty
;
16788 Need_Search
: Boolean := False;
16789 New_Subp
: Entity_Id
;
16790 Parent_Base
: Entity_Id
;
16793 -- Start of processing for Derive_Subprograms
16796 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
16797 and then Has_Discriminants
(Parent_Type
)
16798 and then Present
(Full_View
(Parent_Type
))
16800 Parent_Base
:= Full_View
(Parent_Type
);
16802 Parent_Base
:= Parent_Type
;
16805 if Present
(Generic_Actual
) then
16806 Act_List
:= Collect_Primitive_Operations
(Generic_Actual
);
16807 Act_Elmt
:= First_Elmt
(Act_List
);
16809 Act_List
:= No_Elist
;
16810 Act_Elmt
:= No_Elmt
;
16813 -- Derive primitives inherited from the parent. Note that if the generic
16814 -- actual is present, this is not really a type derivation, it is a
16815 -- completion within an instance.
16817 -- Case 1: Derived_Type does not implement interfaces
16819 if not Is_Tagged_Type
(Derived_Type
)
16820 or else (not Has_Interfaces
(Derived_Type
)
16821 and then not (Present
(Generic_Actual
)
16822 and then Has_Interfaces
(Generic_Actual
)))
16824 Elmt
:= First_Elmt
(Op_List
);
16825 while Present
(Elmt
) loop
16826 Subp
:= Node
(Elmt
);
16828 -- Literals are derived earlier in the process of building the
16829 -- derived type, and are skipped here.
16831 if Ekind
(Subp
) = E_Enumeration_Literal
then
16834 -- The actual is a direct descendant and the common primitive
16835 -- operations appear in the same order.
16837 -- If the generic parent type is present, the derived type is an
16838 -- instance of a formal derived type, and within the instance its
16839 -- operations are those of the actual. We derive from the formal
16840 -- type but make the inherited operations aliases of the
16841 -- corresponding operations of the actual.
16844 pragma Assert
(No
(Node
(Act_Elmt
))
16845 or else (Primitive_Names_Match
(Subp
, Node
(Act_Elmt
))
16848 (Subp
, Node
(Act_Elmt
),
16849 Skip_Controlling_Formals
=> True)));
16852 (New_Subp
, Subp
, Derived_Type
, Parent_Base
, Node
(Act_Elmt
));
16854 if Present
(Act_Elmt
) then
16855 Next_Elmt
(Act_Elmt
);
16862 -- Case 2: Derived_Type implements interfaces
16865 -- If the parent type has no predefined primitives we remove
16866 -- predefined primitives from the list of primitives of generic
16867 -- actual to simplify the complexity of this algorithm.
16869 if Present
(Generic_Actual
) then
16871 Has_Predefined_Primitives
: Boolean := False;
16874 -- Check if the parent type has predefined primitives
16876 Elmt
:= First_Elmt
(Op_List
);
16877 while Present
(Elmt
) loop
16878 Subp
:= Node
(Elmt
);
16880 if Is_Predefined_Dispatching_Operation
(Subp
)
16881 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
16883 Has_Predefined_Primitives
:= True;
16890 -- Remove predefined primitives of Generic_Actual. We must use
16891 -- an auxiliary list because in case of tagged types the value
16892 -- returned by Collect_Primitive_Operations is the value stored
16893 -- in its Primitive_Operations attribute (and we don't want to
16894 -- modify its current contents).
16896 if not Has_Predefined_Primitives
then
16898 Aux_List
: constant Elist_Id
:= New_Elmt_List
;
16901 Elmt
:= First_Elmt
(Act_List
);
16902 while Present
(Elmt
) loop
16903 Subp
:= Node
(Elmt
);
16905 if not Is_Predefined_Dispatching_Operation
(Subp
)
16906 or else Comes_From_Source
(Subp
)
16908 Append_Elmt
(Subp
, Aux_List
);
16914 Act_List
:= Aux_List
;
16918 Act_Elmt
:= First_Elmt
(Act_List
);
16919 Act_Subp
:= Node
(Act_Elmt
);
16923 -- Stage 1: If the generic actual is not present we derive the
16924 -- primitives inherited from the parent type. If the generic parent
16925 -- type is present, the derived type is an instance of a formal
16926 -- derived type, and within the instance its operations are those of
16927 -- the actual. We derive from the formal type but make the inherited
16928 -- operations aliases of the corresponding operations of the actual.
16930 Elmt
:= First_Elmt
(Op_List
);
16931 while Present
(Elmt
) loop
16932 Subp
:= Node
(Elmt
);
16933 Alias_Subp
:= Ultimate_Alias
(Subp
);
16935 -- Do not derive internal entities of the parent that link
16936 -- interface primitives with their covering primitive. These
16937 -- entities will be added to this type when frozen.
16939 if Present
(Interface_Alias
(Subp
)) then
16943 -- If the generic actual is present find the corresponding
16944 -- operation in the generic actual. If the parent type is a
16945 -- direct ancestor of the derived type then, even if it is an
16946 -- interface, the operations are inherited from the primary
16947 -- dispatch table and are in the proper order. If we detect here
16948 -- that primitives are not in the same order we traverse the list
16949 -- of primitive operations of the actual to find the one that
16950 -- implements the interface primitive.
16954 (Present
(Generic_Actual
)
16955 and then Present
(Act_Subp
)
16957 (Primitive_Names_Match
(Subp
, Act_Subp
)
16959 Type_Conformant
(Subp
, Act_Subp
,
16960 Skip_Controlling_Formals
=> True)))
16962 pragma Assert
(not Is_Ancestor
(Parent_Base
, Generic_Actual
,
16963 Use_Full_View
=> True));
16965 -- Remember that we need searching for all pending primitives
16967 Need_Search
:= True;
16969 -- Handle entities associated with interface primitives
16971 if Present
(Alias_Subp
)
16972 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
16973 and then not Is_Predefined_Dispatching_Operation
(Subp
)
16975 -- Search for the primitive in the homonym chain
16978 Find_Primitive_Covering_Interface
16979 (Tagged_Type
=> Generic_Actual
,
16980 Iface_Prim
=> Alias_Subp
);
16982 -- Previous search may not locate primitives covering
16983 -- interfaces defined in generics units or instantiations.
16984 -- (it fails if the covering primitive has formals whose
16985 -- type is also defined in generics or instantiations).
16986 -- In such case we search in the list of primitives of the
16987 -- generic actual for the internal entity that links the
16988 -- interface primitive and the covering primitive.
16991 and then Is_Generic_Type
(Parent_Type
)
16993 -- This code has been designed to handle only generic
16994 -- formals that implement interfaces that are defined
16995 -- in a generic unit or instantiation. If this code is
16996 -- needed for other cases we must review it because
16997 -- (given that it relies on Original_Location to locate
16998 -- the primitive of Generic_Actual that covers the
16999 -- interface) it could leave linked through attribute
17000 -- Alias entities of unrelated instantiations).
17004 (Scope
(Find_Dispatching_Type
(Alias_Subp
)))
17006 Instantiation_Location
17007 (Sloc
(Find_Dispatching_Type
(Alias_Subp
)))
17010 Iface_Prim_Loc
: constant Source_Ptr
:=
17011 Original_Location
(Sloc
(Alias_Subp
));
17018 First_Elmt
(Primitive_Operations
(Generic_Actual
));
17020 Search
: while Present
(Elmt
) loop
17021 Prim
:= Node
(Elmt
);
17023 if Present
(Interface_Alias
(Prim
))
17024 and then Original_Location
17025 (Sloc
(Interface_Alias
(Prim
))) =
17028 Act_Subp
:= Alias
(Prim
);
17037 pragma Assert
(Present
(Act_Subp
)
17038 or else Is_Abstract_Type
(Generic_Actual
)
17039 or else Serious_Errors_Detected
> 0);
17041 -- Handle predefined primitives plus the rest of user-defined
17045 Act_Elmt
:= First_Elmt
(Act_List
);
17046 while Present
(Act_Elmt
) loop
17047 Act_Subp
:= Node
(Act_Elmt
);
17049 exit when Primitive_Names_Match
(Subp
, Act_Subp
)
17050 and then Type_Conformant
17052 Skip_Controlling_Formals
=> True)
17053 and then No
(Interface_Alias
(Act_Subp
));
17055 Next_Elmt
(Act_Elmt
);
17058 if No
(Act_Elmt
) then
17064 -- Case 1: If the parent is a limited interface then it has the
17065 -- predefined primitives of synchronized interfaces. However, the
17066 -- actual type may be a non-limited type and hence it does not
17067 -- have such primitives.
17069 if Present
(Generic_Actual
)
17070 and then No
(Act_Subp
)
17071 and then Is_Limited_Interface
(Parent_Base
)
17072 and then Is_Predefined_Interface_Primitive
(Subp
)
17076 -- Case 2: Inherit entities associated with interfaces that were
17077 -- not covered by the parent type. We exclude here null interface
17078 -- primitives because they do not need special management.
17080 -- We also exclude interface operations that are renamings. If the
17081 -- subprogram is an explicit renaming of an interface primitive,
17082 -- it is a regular primitive operation, and the presence of its
17083 -- alias is not relevant: it has to be derived like any other
17086 elsif Present
(Alias
(Subp
))
17087 and then Nkind
(Unit_Declaration_Node
(Subp
)) /=
17088 N_Subprogram_Renaming_Declaration
17089 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
17091 (Nkind
(Parent
(Alias_Subp
)) = N_Procedure_Specification
17092 and then Null_Present
(Parent
(Alias_Subp
)))
17094 -- If this is an abstract private type then we transfer the
17095 -- derivation of the interface primitive from the partial view
17096 -- to the full view. This is safe because all the interfaces
17097 -- must be visible in the partial view. Done to avoid adding
17098 -- a new interface derivation to the private part of the
17099 -- enclosing package; otherwise this new derivation would be
17100 -- decorated as hidden when the analysis of the enclosing
17101 -- package completes.
17103 if Is_Abstract_Type
(Derived_Type
)
17104 and then In_Private_Part
(Current_Scope
)
17105 and then Has_Private_Declaration
(Derived_Type
)
17108 Partial_View
: Entity_Id
;
17113 Partial_View
:= First_Entity
(Current_Scope
);
17115 exit when No
(Partial_View
)
17116 or else (Has_Private_Declaration
(Partial_View
)
17118 Full_View
(Partial_View
) = Derived_Type
);
17120 Next_Entity
(Partial_View
);
17123 -- If the partial view was not found then the source code
17124 -- has errors and the derivation is not needed.
17126 if Present
(Partial_View
) then
17128 First_Elmt
(Primitive_Operations
(Partial_View
));
17129 while Present
(Elmt
) loop
17130 Ent
:= Node
(Elmt
);
17132 if Present
(Alias
(Ent
))
17133 and then Ultimate_Alias
(Ent
) = Alias
(Subp
)
17136 (Ent
, Primitive_Operations
(Derived_Type
));
17143 -- If the interface primitive was not found in the
17144 -- partial view then this interface primitive was
17145 -- overridden. We add a derivation to activate in
17146 -- Derive_Progenitor_Subprograms the machinery to
17150 Derive_Interface_Subprogram
17151 (New_Subp
=> New_Subp
,
17153 Actual_Subp
=> Act_Subp
);
17158 Derive_Interface_Subprogram
17159 (New_Subp
=> New_Subp
,
17161 Actual_Subp
=> Act_Subp
);
17164 -- Case 3: Common derivation
17168 (New_Subp
=> New_Subp
,
17169 Parent_Subp
=> Subp
,
17170 Derived_Type
=> Derived_Type
,
17171 Parent_Type
=> Parent_Base
,
17172 Actual_Subp
=> Act_Subp
);
17175 -- No need to update Act_Elm if we must search for the
17176 -- corresponding operation in the generic actual
17179 and then Present
(Act_Elmt
)
17181 Next_Elmt
(Act_Elmt
);
17182 Act_Subp
:= Node
(Act_Elmt
);
17189 -- Inherit additional operations from progenitors. If the derived
17190 -- type is a generic actual, there are not new primitive operations
17191 -- for the type because it has those of the actual, and therefore
17192 -- nothing needs to be done. The renamings generated above are not
17193 -- primitive operations, and their purpose is simply to make the
17194 -- proper operations visible within an instantiation.
17196 if No
(Generic_Actual
) then
17197 Derive_Progenitor_Subprograms
(Parent_Base
, Derived_Type
);
17201 -- Final check: Direct descendants must have their primitives in the
17202 -- same order. We exclude from this test untagged types and instances
17203 -- of formal derived types. We skip this test if we have already
17204 -- reported serious errors in the sources.
17206 pragma Assert
(not Is_Tagged_Type
(Derived_Type
)
17207 or else Present
(Generic_Actual
)
17208 or else Serious_Errors_Detected
> 0
17209 or else Check_Derived_Type
);
17210 end Derive_Subprograms
;
17212 --------------------------------
17213 -- Derived_Standard_Character --
17214 --------------------------------
17216 procedure Derived_Standard_Character
17218 Parent_Type
: Entity_Id
;
17219 Derived_Type
: Entity_Id
)
17221 Loc
: constant Source_Ptr
:= Sloc
(N
);
17222 Def
: constant Node_Id
:= Type_Definition
(N
);
17223 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
17224 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
17225 Implicit_Base
: constant Entity_Id
:=
17227 (E_Enumeration_Type
, N
, Derived_Type
, 'B');
17233 Discard_Node
(Process_Subtype
(Indic
, N
));
17235 Set_Etype
(Implicit_Base
, Parent_Base
);
17236 Set_Size_Info
(Implicit_Base
, Root_Type
(Parent_Type
));
17237 Set_RM_Size
(Implicit_Base
, RM_Size
(Root_Type
(Parent_Type
)));
17239 Set_Is_Character_Type
(Implicit_Base
, True);
17240 Set_Has_Delayed_Freeze
(Implicit_Base
);
17242 -- The bounds of the implicit base are the bounds of the parent base.
17243 -- Note that their type is the parent base.
17245 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
17246 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
17248 Set_Scalar_Range
(Implicit_Base
,
17251 High_Bound
=> Hi
));
17253 Mutate_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
17254 Set_Etype
(Derived_Type
, Implicit_Base
);
17255 Set_Size_Info
(Derived_Type
, Parent_Type
);
17257 if not Known_RM_Size
(Derived_Type
) then
17258 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
17261 Set_Is_Character_Type
(Derived_Type
, True);
17263 if Nkind
(Indic
) /= N_Subtype_Indication
then
17265 -- If no explicit constraint, the bounds are those
17266 -- of the parent type.
17268 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Type
));
17269 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Type
));
17270 Set_Scalar_Range
(Derived_Type
, Make_Range
(Loc
, Lo
, Hi
));
17273 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
17274 end Derived_Standard_Character
;
17276 ------------------------------
17277 -- Derived_Type_Declaration --
17278 ------------------------------
17280 procedure Derived_Type_Declaration
17283 Is_Completion
: Boolean)
17285 Parent_Type
: Entity_Id
;
17287 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean;
17288 -- Check whether the parent type is a generic formal, or derives
17289 -- directly or indirectly from one.
17291 ------------------------
17292 -- Comes_From_Generic --
17293 ------------------------
17295 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean is
17297 if Is_Generic_Type
(Typ
) then
17300 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
17303 elsif Is_Private_Type
(Typ
)
17304 and then Present
(Full_View
(Typ
))
17305 and then Is_Generic_Type
(Root_Type
(Full_View
(Typ
)))
17309 elsif Is_Generic_Actual_Type
(Typ
) then
17315 end Comes_From_Generic
;
17319 Def
: constant Node_Id
:= Type_Definition
(N
);
17320 Iface_Def
: Node_Id
;
17321 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
17322 Extension
: constant Node_Id
:= Record_Extension_Part
(Def
);
17323 Parent_Node
: Node_Id
;
17326 -- Start of processing for Derived_Type_Declaration
17329 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
17331 -- Ada 2005 (AI-251): In case of interface derivation check that the
17332 -- parent is also an interface.
17334 if Interface_Present
(Def
) then
17335 if not Is_Interface
(Parent_Type
) then
17336 Diagnose_Interface
(Indic
, Parent_Type
);
17339 Parent_Node
:= Parent
(Base_Type
(Parent_Type
));
17340 Iface_Def
:= Type_Definition
(Parent_Node
);
17342 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
17343 -- other limited interfaces.
17345 if Limited_Present
(Def
) then
17346 if Limited_Present
(Iface_Def
) then
17349 elsif Protected_Present
(Iface_Def
) then
17351 ("descendant of & must be declared as a protected "
17352 & "interface", N
, Parent_Type
);
17354 elsif Synchronized_Present
(Iface_Def
) then
17356 ("descendant of & must be declared as a synchronized "
17357 & "interface", N
, Parent_Type
);
17359 elsif Task_Present
(Iface_Def
) then
17361 ("descendant of & must be declared as a task interface",
17366 ("(Ada 2005) limited interface cannot inherit from "
17367 & "non-limited interface", Indic
);
17370 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
17371 -- from non-limited or limited interfaces.
17373 elsif not Protected_Present
(Def
)
17374 and then not Synchronized_Present
(Def
)
17375 and then not Task_Present
(Def
)
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",
17401 if Is_Tagged_Type
(Parent_Type
)
17402 and then Is_Concurrent_Type
(Parent_Type
)
17403 and then not Is_Interface
(Parent_Type
)
17406 ("parent type of a record extension cannot be a synchronized "
17407 & "tagged type (RM 3.9.1 (3/1))", N
);
17408 Set_Etype
(T
, Any_Type
);
17412 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
17415 if Is_Tagged_Type
(Parent_Type
)
17416 and then Is_Non_Empty_List
(Interface_List
(Def
))
17423 Intf
:= First
(Interface_List
(Def
));
17424 while Present
(Intf
) loop
17425 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
17427 if not Is_Interface
(T
) then
17428 Diagnose_Interface
(Intf
, T
);
17430 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
17431 -- a limited type from having a nonlimited progenitor.
17433 elsif (Limited_Present
(Def
)
17434 or else (not Is_Interface
(Parent_Type
)
17435 and then Is_Limited_Type
(Parent_Type
)))
17436 and then not Is_Limited_Interface
(T
)
17439 ("progenitor interface& of limited type must be limited",
17447 -- Check consistency of any nonoverridable aspects that are
17448 -- inherited from multiple sources.
17450 Check_Inherited_Nonoverridable_Aspects
17452 Interface_List
=> Interface_List
(Def
),
17453 Parent_Type
=> Parent_Type
);
17456 if Parent_Type
= Any_Type
17457 or else Etype
(Parent_Type
) = Any_Type
17458 or else (Is_Class_Wide_Type
(Parent_Type
)
17459 and then Etype
(Parent_Type
) = T
)
17461 -- If Parent_Type is undefined or illegal, make new type into a
17462 -- subtype of Any_Type, and set a few attributes to prevent cascaded
17463 -- errors. If this is a self-definition, emit error now.
17465 if T
= Parent_Type
or else T
= Etype
(Parent_Type
) then
17466 Error_Msg_N
("type cannot be used in its own definition", Indic
);
17469 Mutate_Ekind
(T
, Ekind
(Parent_Type
));
17470 Set_Etype
(T
, Any_Type
);
17471 Set_Scalar_Range
(T
, Scalar_Range
(Any_Type
));
17473 -- Initialize the list of primitive operations to an empty list,
17474 -- to cover tagged types as well as untagged types. For untagged
17475 -- types this is used either to analyze the call as legal when
17476 -- Extensions_Allowed is True, or to issue a better error message
17479 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
17484 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
17485 -- an interface is special because the list of interfaces in the full
17486 -- view can be given in any order. For example:
17488 -- type A is interface;
17489 -- type B is interface and A;
17490 -- type D is new B with private;
17492 -- type D is new A and B with null record; -- 1 --
17494 -- In this case we perform the following transformation of -1-:
17496 -- type D is new B and A with null record;
17498 -- If the parent of the full-view covers the parent of the partial-view
17499 -- we have two possible cases:
17501 -- 1) They have the same parent
17502 -- 2) The parent of the full-view implements some further interfaces
17504 -- In both cases we do not need to perform the transformation. In the
17505 -- first case the source program is correct and the transformation is
17506 -- not needed; in the second case the source program does not fulfill
17507 -- the no-hidden interfaces rule (AI-396) and the error will be reported
17510 -- This transformation not only simplifies the rest of the analysis of
17511 -- this type declaration but also simplifies the correct generation of
17512 -- the object layout to the expander.
17514 if In_Private_Part
(Current_Scope
)
17515 and then Is_Interface
(Parent_Type
)
17518 Partial_View
: Entity_Id
;
17519 Partial_View_Parent
: Entity_Id
;
17521 function Reorder_Interfaces
return Boolean;
17522 -- Look for an interface in the full view's interface list that
17523 -- matches the parent type of the partial view, and when found,
17524 -- rewrite the full view's parent with the partial view's parent,
17525 -- append the full view's original parent to the interface list,
17526 -- recursively call Derived_Type_Definition on the full type, and
17527 -- return True. If a match is not found, return False.
17529 ------------------------
17530 -- Reorder_Interfaces --
17531 ------------------------
17533 function Reorder_Interfaces
return Boolean is
17535 New_Iface
: Node_Id
;
17538 Iface
:= First
(Interface_List
(Def
));
17539 while Present
(Iface
) loop
17540 if Etype
(Iface
) = Etype
(Partial_View
) then
17541 Rewrite
(Subtype_Indication
(Def
),
17542 New_Copy
(Subtype_Indication
(Parent
(Partial_View
))));
17545 Make_Identifier
(Sloc
(N
), Chars
(Parent_Type
));
17546 Rewrite
(Iface
, New_Iface
);
17548 -- Analyze the transformed code
17550 Derived_Type_Declaration
(T
, N
, Is_Completion
);
17557 end Reorder_Interfaces
;
17560 -- Look for the associated private type declaration
17562 Partial_View
:= Incomplete_Or_Partial_View
(T
);
17564 -- If the partial view was not found then the source code has
17565 -- errors and the transformation is not needed.
17567 if Present
(Partial_View
) then
17568 Partial_View_Parent
:= Etype
(Partial_View
);
17570 -- If the parent of the full-view covers the parent of the
17571 -- partial-view we have nothing else to do.
17573 if Interface_Present_In_Ancestor
17574 (Parent_Type
, Partial_View_Parent
)
17578 -- Traverse the list of interfaces of the full view to look
17579 -- for the parent of the partial view and reorder the
17580 -- interfaces to match the order in the partial view,
17585 if Reorder_Interfaces
then
17586 -- Having the interfaces listed in any order is legal.
17587 -- However, the compiler does not properly handle
17588 -- different orders between partial and full views in
17589 -- generic units. We give a warning about the order
17590 -- mismatch, so the user can work around this problem.
17592 Error_Msg_N
("??full declaration does not respect " &
17593 "partial declaration order", T
);
17594 Error_Msg_N
("\??consider reordering", T
);
17603 -- Only composite types other than array types are allowed to have
17606 if Present
(Discriminant_Specifications
(N
)) then
17607 if (Is_Elementary_Type
(Parent_Type
)
17609 Is_Array_Type
(Parent_Type
))
17610 and then not Error_Posted
(N
)
17613 ("elementary or array type cannot have discriminants",
17614 Defining_Identifier
(First
(Discriminant_Specifications
(N
))));
17616 -- Unset Has_Discriminants flag to prevent cascaded errors, but
17617 -- only if we are not already processing a malformed syntax tree.
17619 if Is_Type
(T
) then
17620 Set_Has_Discriminants
(T
, False);
17625 -- In Ada 83, a derived type defined in a package specification cannot
17626 -- be used for further derivation until the end of its visible part.
17627 -- Note that derivation in the private part of the package is allowed.
17629 if Ada_Version
= Ada_83
17630 and then Is_Derived_Type
(Parent_Type
)
17631 and then In_Visible_Part
(Scope
(Parent_Type
))
17633 if Ada_Version
= Ada_83
and then Comes_From_Source
(Indic
) then
17635 ("(Ada 83) premature use of type for derivation", Indic
);
17639 -- Check for early use of incomplete or private type
17641 if Ekind
(Parent_Type
) in E_Void | E_Incomplete_Type
then
17642 Error_Msg_N
("premature derivation of incomplete type", Indic
);
17645 elsif (Is_Incomplete_Or_Private_Type
(Parent_Type
)
17646 and then not Comes_From_Generic
(Parent_Type
))
17647 or else Has_Private_Component
(Parent_Type
)
17649 -- The ancestor type of a formal type can be incomplete, in which
17650 -- case only the operations of the partial view are available in the
17651 -- generic. Subsequent checks may be required when the full view is
17652 -- analyzed to verify that a derivation from a tagged type has an
17655 if Nkind
(Original_Node
(N
)) = N_Formal_Type_Declaration
then
17658 elsif No
(Underlying_Type
(Parent_Type
))
17659 or else Has_Private_Component
(Parent_Type
)
17662 ("premature derivation of derived or private type", Indic
);
17664 -- Flag the type itself as being in error, this prevents some
17665 -- nasty problems with subsequent uses of the malformed type.
17667 Set_Error_Posted
(T
);
17669 -- Check that within the immediate scope of an untagged partial
17670 -- view it's illegal to derive from the partial view if the
17671 -- full view is tagged. (7.3(7))
17673 -- We verify that the Parent_Type is a partial view by checking
17674 -- that it is not a Full_Type_Declaration (i.e. a private type or
17675 -- private extension declaration), to distinguish a partial view
17676 -- from a derivation from a private type which also appears as
17677 -- E_Private_Type. If the parent base type is not declared in an
17678 -- enclosing scope there is no need to check.
17680 elsif Present
(Full_View
(Parent_Type
))
17681 and then Nkind
(Parent
(Parent_Type
)) /= N_Full_Type_Declaration
17682 and then not Is_Tagged_Type
(Parent_Type
)
17683 and then Is_Tagged_Type
(Full_View
(Parent_Type
))
17684 and then In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
17687 ("premature derivation from type with tagged full view",
17692 -- Check that form of derivation is appropriate
17694 Taggd
:= Is_Tagged_Type
(Parent_Type
);
17696 -- Set the parent type to the class-wide type's specific type in this
17697 -- case to prevent cascading errors
17699 if Present
(Extension
) and then Is_Class_Wide_Type
(Parent_Type
) then
17700 Error_Msg_N
("parent type must not be a class-wide type", Indic
);
17701 Set_Etype
(T
, Etype
(Parent_Type
));
17705 if Present
(Extension
) and then not Taggd
then
17707 ("type derived from untagged type cannot have extension", Indic
);
17709 elsif No
(Extension
) and then Taggd
then
17711 -- If this declaration is within a private part (or body) of a
17712 -- generic instantiation then the derivation is allowed (the parent
17713 -- type can only appear tagged in this case if it's a generic actual
17714 -- type, since it would otherwise have been rejected in the analysis
17715 -- of the generic template).
17717 if not Is_Generic_Actual_Type
(Parent_Type
)
17718 or else In_Visible_Part
(Scope
(Parent_Type
))
17720 if Is_Class_Wide_Type
(Parent_Type
) then
17722 ("parent type must not be a class-wide type", Indic
);
17724 -- Use specific type to prevent cascaded errors.
17726 Parent_Type
:= Etype
(Parent_Type
);
17730 ("type derived from tagged type must have extension", Indic
);
17735 -- AI-443: Synchronized formal derived types require a private
17736 -- extension. There is no point in checking the ancestor type or
17737 -- the progenitors since the construct is wrong to begin with.
17739 if Ada_Version
>= Ada_2005
17740 and then Is_Generic_Type
(T
)
17741 and then Present
(Original_Node
(N
))
17744 Decl
: constant Node_Id
:= Original_Node
(N
);
17747 if Nkind
(Decl
) = N_Formal_Type_Declaration
17748 and then Nkind
(Formal_Type_Definition
(Decl
)) =
17749 N_Formal_Derived_Type_Definition
17750 and then Synchronized_Present
(Formal_Type_Definition
(Decl
))
17751 and then No
(Extension
)
17753 -- Avoid emitting a duplicate error message
17755 and then not Error_Posted
(Indic
)
17758 ("synchronized derived type must have extension", N
);
17763 if Null_Exclusion_Present
(Def
)
17764 and then not Is_Access_Type
(Parent_Type
)
17766 Error_Msg_N
("null exclusion can only apply to an access type", N
);
17769 Check_Wide_Character_Restriction
(Parent_Type
, Indic
);
17771 -- Avoid deriving parent primitives of underlying record views
17773 Set_Is_Not_Self_Hidden
(T
);
17775 Build_Derived_Type
(N
, Parent_Type
, T
, Is_Completion
,
17776 Derive_Subps
=> not Is_Underlying_Record_View
(T
));
17778 -- AI-419: The parent type of an explicitly limited derived type must
17779 -- be a limited type or a limited interface.
17781 if Limited_Present
(Def
) then
17782 Set_Is_Limited_Record
(T
);
17784 if Is_Interface
(T
) then
17785 Set_Is_Limited_Interface
(T
);
17788 if not Is_Limited_Type
(Parent_Type
)
17790 (not Is_Interface
(Parent_Type
)
17791 or else not Is_Limited_Interface
(Parent_Type
))
17793 -- AI05-0096: a derivation in the private part of an instance is
17794 -- legal if the generic formal is untagged limited, and the actual
17797 if Is_Generic_Actual_Type
(Parent_Type
)
17798 and then In_Private_Part
(Current_Scope
)
17801 (Generic_Parent_Type
(Parent
(Parent_Type
)))
17807 ("parent type& of limited type must be limited",
17812 end Derived_Type_Declaration
;
17814 ------------------------
17815 -- Diagnose_Interface --
17816 ------------------------
17818 procedure Diagnose_Interface
(N
: Node_Id
; E
: Entity_Id
) is
17820 if not Is_Interface
(E
) and then E
/= Any_Type
then
17821 Error_Msg_NE
("(Ada 2005) & must be an interface", N
, E
);
17823 end Diagnose_Interface
;
17825 ----------------------------------
17826 -- Enumeration_Type_Declaration --
17827 ----------------------------------
17829 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
17836 -- Create identifier node representing lower bound
17838 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
17839 L
:= First
(Literals
(Def
));
17840 Set_Chars
(B_Node
, Chars
(L
));
17841 Set_Entity
(B_Node
, L
);
17842 Set_Etype
(B_Node
, T
);
17843 Set_Is_Static_Expression
(B_Node
, True);
17845 R_Node
:= New_Node
(N_Range
, Sloc
(Def
));
17846 Set_Low_Bound
(R_Node
, B_Node
);
17848 Mutate_Ekind
(T
, E_Enumeration_Type
);
17849 Set_First_Literal
(T
, L
);
17851 Set_Is_Constrained
(T
);
17855 -- Loop through literals of enumeration type setting pos and rep values
17856 -- except that if the Ekind is already set, then it means the literal
17857 -- was already constructed (case of a derived type declaration and we
17858 -- should not disturb the Pos and Rep values.
17860 while Present
(L
) loop
17861 if Ekind
(L
) /= E_Enumeration_Literal
then
17862 Mutate_Ekind
(L
, E_Enumeration_Literal
);
17863 Set_Is_Not_Self_Hidden
(L
);
17864 Set_Enumeration_Pos
(L
, Ev
);
17865 Set_Enumeration_Rep
(L
, Ev
);
17866 Set_Is_Known_Valid
(L
, True);
17870 New_Overloaded_Entity
(L
);
17871 Generate_Definition
(L
);
17872 Set_Convention
(L
, Convention_Intrinsic
);
17874 -- Case of character literal
17876 if Nkind
(L
) = N_Defining_Character_Literal
then
17877 Set_Is_Character_Type
(T
, True);
17879 -- Check violation of No_Wide_Characters
17881 if Restriction_Check_Required
(No_Wide_Characters
) then
17882 Get_Name_String
(Chars
(L
));
17884 if Name_Len
>= 3 and then Name_Buffer
(1 .. 2) = "QW" then
17885 Check_Restriction
(No_Wide_Characters
, L
);
17894 -- Now create a node representing upper bound
17896 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
17897 Set_Chars
(B_Node
, Chars
(Last
(Literals
(Def
))));
17898 Set_Entity
(B_Node
, Last
(Literals
(Def
)));
17899 Set_Etype
(B_Node
, T
);
17900 Set_Is_Static_Expression
(B_Node
, True);
17902 Set_High_Bound
(R_Node
, B_Node
);
17904 -- Initialize various fields of the type. Some of this information
17905 -- may be overwritten later through rep. clauses.
17907 Set_Scalar_Range
(T
, R_Node
);
17908 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
17909 Set_Enum_Esize
(T
);
17910 Set_Enum_Pos_To_Rep
(T
, Empty
);
17912 -- Set Discard_Names if configuration pragma set, or if there is
17913 -- a parameterless pragma in the current declarative region
17915 if Global_Discard_Names
or else Discard_Names
(Scope
(T
)) then
17916 Set_Discard_Names
(T
);
17919 -- Process end label if there is one
17921 if Present
(Def
) then
17922 Process_End_Label
(Def
, 'e', T
);
17924 end Enumeration_Type_Declaration
;
17926 ---------------------------------
17927 -- Expand_To_Stored_Constraint --
17928 ---------------------------------
17930 function Expand_To_Stored_Constraint
17932 Constraint
: Elist_Id
) return Elist_Id
17934 Explicitly_Discriminated_Type
: Entity_Id
;
17935 Expansion
: Elist_Id
;
17936 Discriminant
: Entity_Id
;
17938 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
;
17939 -- Find the nearest type that actually specifies discriminants
17941 ---------------------------------
17942 -- Type_With_Explicit_Discrims --
17943 ---------------------------------
17945 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
is
17946 Typ
: constant E
:= Base_Type
(Id
);
17949 if Ekind
(Typ
) in Incomplete_Or_Private_Kind
then
17950 if Present
(Full_View
(Typ
)) then
17951 return Type_With_Explicit_Discrims
(Full_View
(Typ
));
17955 if Has_Discriminants
(Typ
) then
17960 if Etype
(Typ
) = Typ
then
17962 elsif Has_Discriminants
(Typ
) then
17965 return Type_With_Explicit_Discrims
(Etype
(Typ
));
17968 end Type_With_Explicit_Discrims
;
17970 -- Start of processing for Expand_To_Stored_Constraint
17973 if No
(Constraint
) or else Is_Empty_Elmt_List
(Constraint
) then
17977 Explicitly_Discriminated_Type
:= Type_With_Explicit_Discrims
(Typ
);
17979 if No
(Explicitly_Discriminated_Type
) then
17983 Expansion
:= New_Elmt_List
;
17986 First_Stored_Discriminant
(Explicitly_Discriminated_Type
);
17987 while Present
(Discriminant
) loop
17989 (Get_Discriminant_Value
17990 (Discriminant
, Explicitly_Discriminated_Type
, Constraint
),
17992 Next_Stored_Discriminant
(Discriminant
);
17996 end Expand_To_Stored_Constraint
;
17998 ---------------------------
17999 -- Find_Hidden_Interface --
18000 ---------------------------
18002 function Find_Hidden_Interface
18004 Dest
: Elist_Id
) return Entity_Id
18007 Iface_Elmt
: Elmt_Id
;
18010 if Present
(Src
) and then Present
(Dest
) then
18011 Iface_Elmt
:= First_Elmt
(Src
);
18012 while Present
(Iface_Elmt
) loop
18013 Iface
:= Node
(Iface_Elmt
);
18015 if Is_Interface
(Iface
)
18016 and then not Contain_Interface
(Iface
, Dest
)
18021 Next_Elmt
(Iface_Elmt
);
18026 end Find_Hidden_Interface
;
18028 --------------------
18029 -- Find_Type_Name --
18030 --------------------
18032 function Find_Type_Name
(N
: Node_Id
) return Entity_Id
is
18033 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
18034 New_Id
: Entity_Id
;
18036 Prev_Par
: Node_Id
;
18038 procedure Check_Duplicate_Aspects
;
18039 -- Check that aspects specified in a completion have not been specified
18040 -- already in the partial view.
18042 procedure Tag_Mismatch
;
18043 -- Diagnose a tagged partial view whose full view is untagged. We post
18044 -- the message on the full view, with a reference to the previous
18045 -- partial view. The partial view can be private or incomplete, and
18046 -- these are handled in a different manner, so we determine the position
18047 -- of the error message from the respective slocs of both.
18049 -----------------------------
18050 -- Check_Duplicate_Aspects --
18051 -----------------------------
18053 procedure Check_Duplicate_Aspects
is
18054 function Get_Partial_View_Aspect
(Asp
: Node_Id
) return Node_Id
;
18055 -- Return the corresponding aspect of the partial view which matches
18056 -- the aspect id of Asp. Return Empty is no such aspect exists.
18058 -----------------------------
18059 -- Get_Partial_View_Aspect --
18060 -----------------------------
18062 function Get_Partial_View_Aspect
(Asp
: Node_Id
) return Node_Id
is
18063 Asp_Id
: constant Aspect_Id
:= Get_Aspect_Id
(Asp
);
18064 Prev_Asps
: constant List_Id
:= Aspect_Specifications
(Prev_Par
);
18065 Prev_Asp
: Node_Id
;
18068 Prev_Asp
:= First
(Prev_Asps
);
18069 while Present
(Prev_Asp
) loop
18070 if Get_Aspect_Id
(Prev_Asp
) = Asp_Id
then
18078 end Get_Partial_View_Aspect
;
18082 Full_Asps
: constant List_Id
:= Aspect_Specifications
(N
);
18083 Full_Asp
: Node_Id
;
18084 Part_Asp
: Node_Id
;
18086 -- Start of processing for Check_Duplicate_Aspects
18089 Full_Asp
:= First
(Full_Asps
);
18090 while Present
(Full_Asp
) loop
18091 Part_Asp
:= Get_Partial_View_Aspect
(Full_Asp
);
18093 -- An aspect and its class-wide counterpart are two distinct
18094 -- aspects and may apply to both views of an entity.
18096 if Present
(Part_Asp
)
18097 and then Class_Present
(Part_Asp
) = Class_Present
(Full_Asp
)
18100 ("aspect already specified in private declaration", Full_Asp
);
18106 if Has_Discriminants
(Prev
)
18107 and then not Has_Unknown_Discriminants
(Prev
)
18108 and then Get_Aspect_Id
(Full_Asp
) =
18109 Aspect_Implicit_Dereference
18112 ("cannot specify aspect if partial view has known "
18113 & "discriminants", Full_Asp
);
18118 end Check_Duplicate_Aspects
;
18124 procedure Tag_Mismatch
is
18126 if Sloc
(Prev
) < Sloc
(Id
) then
18127 if Ada_Version
>= Ada_2012
18128 and then Nkind
(N
) = N_Private_Type_Declaration
18131 ("declaration of private } must be a tagged type", Id
, Prev
);
18134 ("full declaration of } must be a tagged type", Id
, Prev
);
18138 if Ada_Version
>= Ada_2012
18139 and then Nkind
(N
) = N_Private_Type_Declaration
18142 ("declaration of private } must be a tagged type", Prev
, Id
);
18145 ("full declaration of } must be a tagged type", Prev
, Id
);
18150 -- Start of processing for Find_Type_Name
18153 -- Find incomplete declaration, if one was given
18155 Prev
:= Current_Entity_In_Scope
(Id
);
18157 -- New type declaration
18163 -- Previous declaration exists
18166 Prev_Par
:= Parent
(Prev
);
18168 -- Error if not incomplete/private case except if previous
18169 -- declaration is implicit, etc. Enter_Name will emit error if
18172 if not Is_Incomplete_Or_Private_Type
(Prev
) then
18176 -- Check invalid completion of private or incomplete type
18178 elsif Nkind
(N
) not in N_Full_Type_Declaration
18179 | N_Task_Type_Declaration
18180 | N_Protected_Type_Declaration
18182 (Ada_Version
< Ada_2012
18183 or else not Is_Incomplete_Type
(Prev
)
18184 or else Nkind
(N
) not in N_Private_Type_Declaration
18185 | N_Private_Extension_Declaration
)
18187 -- Completion must be a full type declarations (RM 7.3(4))
18189 Error_Msg_Sloc
:= Sloc
(Prev
);
18190 Error_Msg_NE
("invalid completion of }", Id
, Prev
);
18192 -- Set scope of Id to avoid cascaded errors. Entity is never
18193 -- examined again, except when saving globals in generics.
18195 Set_Scope
(Id
, Current_Scope
);
18198 -- If this is a repeated incomplete declaration, no further
18199 -- checks are possible.
18201 if Nkind
(N
) = N_Incomplete_Type_Declaration
then
18205 -- Case of full declaration of incomplete type
18207 elsif Ekind
(Prev
) = E_Incomplete_Type
18208 and then (Ada_Version
< Ada_2012
18209 or else No
(Full_View
(Prev
))
18210 or else not Is_Private_Type
(Full_View
(Prev
)))
18212 -- Indicate that the incomplete declaration has a matching full
18213 -- declaration. The defining occurrence of the incomplete
18214 -- declaration remains the visible one, and the procedure
18215 -- Get_Full_View dereferences it whenever the type is used.
18217 if Present
(Full_View
(Prev
)) then
18218 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
18221 Set_Full_View
(Prev
, Id
);
18222 Append_Entity
(Id
, Current_Scope
);
18223 Set_Is_Public
(Id
, Is_Public
(Prev
));
18224 Set_Is_Internal
(Id
);
18227 -- If the incomplete view is tagged, a class_wide type has been
18228 -- created already. Use it for the private type as well, in order
18229 -- to prevent multiple incompatible class-wide types that may be
18230 -- created for self-referential anonymous access components.
18232 if Is_Tagged_Type
(Prev
)
18233 and then Present
(Class_Wide_Type
(Prev
))
18235 Mutate_Ekind
(Id
, Ekind
(Prev
)); -- will be reset later
18236 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(Prev
));
18238 -- Type of the class-wide type is the current Id. Previously
18239 -- this was not done for private declarations because of order-
18240 -- of-elaboration issues in the back end, but gigi now handles
18243 Set_Etype
(Class_Wide_Type
(Id
), Id
);
18246 -- Case of full declaration of private type
18249 -- If the private type was a completion of an incomplete type then
18250 -- update Prev to reference the private type
18252 if Ada_Version
>= Ada_2012
18253 and then Ekind
(Prev
) = E_Incomplete_Type
18254 and then Present
(Full_View
(Prev
))
18255 and then Is_Private_Type
(Full_View
(Prev
))
18257 Prev
:= Full_View
(Prev
);
18258 Prev_Par
:= Parent
(Prev
);
18261 if Nkind
(N
) = N_Full_Type_Declaration
18262 and then Nkind
(Type_Definition
(N
)) in
18263 N_Record_Definition | N_Derived_Type_Definition
18264 and then Interface_Present
(Type_Definition
(N
))
18267 ("completion of private type cannot be an interface", N
);
18270 if Nkind
(Parent
(Prev
)) /= N_Private_Extension_Declaration
then
18271 if Etype
(Prev
) /= Prev
then
18273 -- Prev is a private subtype or a derived type, and needs
18276 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
18279 elsif Ekind
(Prev
) = E_Private_Type
18280 and then Nkind
(N
) in N_Task_Type_Declaration
18281 | N_Protected_Type_Declaration
18284 ("completion of nonlimited type cannot be limited", N
);
18286 elsif Ekind
(Prev
) = E_Record_Type_With_Private
18287 and then Nkind
(N
) in N_Task_Type_Declaration
18288 | N_Protected_Type_Declaration
18290 if not Is_Limited_Record
(Prev
) then
18292 ("completion of nonlimited type cannot be limited", N
);
18294 elsif No
(Interface_List
(N
)) then
18296 ("completion of tagged private type must be tagged",
18301 -- Ada 2005 (AI-251): Private extension declaration of a task
18302 -- type or a protected type. This case arises when covering
18303 -- interface types.
18305 elsif Nkind
(N
) in N_Task_Type_Declaration
18306 | N_Protected_Type_Declaration
18310 elsif Nkind
(N
) /= N_Full_Type_Declaration
18311 or else Nkind
(Type_Definition
(N
)) /= N_Derived_Type_Definition
18314 ("full view of private extension must be an extension", N
);
18316 elsif not (Abstract_Present
(Parent
(Prev
)))
18317 and then Abstract_Present
(Type_Definition
(N
))
18320 ("full view of non-abstract extension cannot be abstract", N
);
18323 if not In_Private_Part
(Current_Scope
) then
18325 ("declaration of full view must appear in private part", N
);
18328 if Ada_Version
>= Ada_2012
then
18329 Check_Duplicate_Aspects
;
18332 Copy_And_Swap
(Prev
, Id
);
18333 Set_Has_Private_Declaration
(Prev
);
18334 Set_Has_Private_Declaration
(Id
);
18336 -- AI12-0133: Indicate whether we have a partial view with
18337 -- unknown discriminants, in which case initialization of objects
18338 -- of the type do not receive an invariant check.
18340 Set_Partial_View_Has_Unknown_Discr
18341 (Prev
, Has_Unknown_Discriminants
(Id
));
18343 -- Preserve aspect and iterator flags that may have been set on
18344 -- the partial view.
18346 Set_Has_Delayed_Aspects
(Prev
, Has_Delayed_Aspects
(Id
));
18347 Set_Has_Implicit_Dereference
(Prev
, Has_Implicit_Dereference
(Id
));
18349 -- If no error, propagate freeze_node from private to full view.
18350 -- It may have been generated for an early operational item.
18352 if Present
(Freeze_Node
(Id
))
18353 and then Serious_Errors_Detected
= 0
18354 and then No
(Full_View
(Id
))
18356 Set_Freeze_Node
(Prev
, Freeze_Node
(Id
));
18357 Set_Freeze_Node
(Id
, Empty
);
18358 Set_First_Rep_Item
(Prev
, First_Rep_Item
(Id
));
18361 Set_Full_View
(Id
, Prev
);
18365 -- Verify that full declaration conforms to partial one
18367 if Is_Incomplete_Or_Private_Type
(Prev
)
18368 and then Present
(Discriminant_Specifications
(Prev_Par
))
18370 if Present
(Discriminant_Specifications
(N
)) then
18371 if Ekind
(Prev
) = E_Incomplete_Type
then
18372 Check_Discriminant_Conformance
(N
, Prev
, Prev
);
18374 Check_Discriminant_Conformance
(N
, Prev
, Id
);
18379 ("missing discriminants in full type declaration", N
);
18381 -- To avoid cascaded errors on subsequent use, share the
18382 -- discriminants of the partial view.
18384 Set_Discriminant_Specifications
(N
,
18385 Discriminant_Specifications
(Prev_Par
));
18389 -- A prior untagged partial view can have an associated class-wide
18390 -- type due to use of the class attribute, and in this case the full
18391 -- type must also be tagged. This Ada 95 usage is deprecated in favor
18392 -- of incomplete tagged declarations, but we check for it.
18395 and then (Is_Tagged_Type
(Prev
)
18396 or else Present
(Class_Wide_Type
(Prev
)))
18398 -- Ada 2012 (AI05-0162): A private type may be the completion of
18399 -- an incomplete type.
18401 if Ada_Version
>= Ada_2012
18402 and then Is_Incomplete_Type
(Prev
)
18403 and then Nkind
(N
) in N_Private_Type_Declaration
18404 | N_Private_Extension_Declaration
18406 -- No need to check private extensions since they are tagged
18408 if Nkind
(N
) = N_Private_Type_Declaration
18409 and then not Tagged_Present
(N
)
18414 -- The full declaration is either a tagged type (including
18415 -- a synchronized type that implements interfaces) or a
18416 -- type extension, otherwise this is an error.
18418 elsif Nkind
(N
) in N_Task_Type_Declaration
18419 | N_Protected_Type_Declaration
18421 if No
(Interface_List
(N
)) and then not Error_Posted
(N
) then
18425 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
18427 -- Indicate that the previous declaration (tagged incomplete
18428 -- or private declaration) requires the same on the full one.
18430 if not Tagged_Present
(Type_Definition
(N
)) then
18432 Set_Is_Tagged_Type
(Id
);
18435 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
18436 if No
(Record_Extension_Part
(Type_Definition
(N
))) then
18438 ("full declaration of } must be a record extension",
18441 -- Set some attributes to produce a usable full view
18443 Set_Is_Tagged_Type
(Id
);
18452 and then Nkind
(Parent
(Prev
)) = N_Incomplete_Type_Declaration
18453 and then Present
(Premature_Use
(Parent
(Prev
)))
18455 Error_Msg_Sloc
:= Sloc
(N
);
18457 ("\full declaration #", Premature_Use
(Parent
(Prev
)));
18462 end Find_Type_Name
;
18464 -------------------------
18465 -- Find_Type_Of_Object --
18466 -------------------------
18468 function Find_Type_Of_Object
18469 (Obj_Def
: Node_Id
;
18470 Related_Nod
: Node_Id
) return Entity_Id
18472 Def_Kind
: constant Node_Kind
:= Nkind
(Obj_Def
);
18473 P
: Node_Id
:= Parent
(Obj_Def
);
18478 -- If the parent is a component_definition node we climb to the
18479 -- component_declaration node.
18481 if Nkind
(P
) = N_Component_Definition
then
18485 -- Case of an anonymous array subtype
18487 if Def_Kind
in N_Array_Type_Definition
then
18489 Array_Type_Declaration
(T
, Obj_Def
);
18491 -- Create an explicit subtype whenever possible
18493 elsif Nkind
(P
) /= N_Component_Declaration
18494 and then Def_Kind
= N_Subtype_Indication
18496 -- Base name of subtype on object name, which will be unique in
18497 -- the current scope.
18499 -- If this is a duplicate declaration, return base type, to avoid
18500 -- generating duplicate anonymous types.
18502 if Error_Posted
(P
) then
18503 Analyze
(Subtype_Mark
(Obj_Def
));
18504 return Entity
(Subtype_Mark
(Obj_Def
));
18509 (Chars
(Defining_Identifier
(Related_Nod
)), 'S', 0, 'T');
18511 T
:= Make_Defining_Identifier
(Sloc
(P
), Nam
);
18513 -- If In_Spec_Expression, for example within a pre/postcondition,
18514 -- provide enough information for use of the subtype without
18515 -- depending on full analysis and freezing, which will happen when
18516 -- building the corresponding subprogram.
18518 if In_Spec_Expression
then
18519 Analyze
(Subtype_Mark
(Obj_Def
));
18522 Base_T
: constant Entity_Id
:= Entity
(Subtype_Mark
(Obj_Def
));
18523 New_Def
: constant Node_Id
:= New_Copy_Tree
(Obj_Def
);
18524 Decl
: constant Node_Id
:=
18525 Make_Subtype_Declaration
(Sloc
(P
),
18526 Defining_Identifier
=> T
,
18527 Subtype_Indication
=> New_Def
);
18530 Set_Etype
(T
, Base_T
);
18531 Mutate_Ekind
(T
, Subtype_Kind
(Ekind
(Base_T
)));
18532 Set_Parent
(T
, Decl
);
18533 Set_Scope
(T
, Current_Scope
);
18535 if Ekind
(T
) = E_Array_Subtype
then
18536 Constrain_Array
(T
, New_Def
, Related_Nod
, T
, 'P');
18538 elsif Ekind
(T
) = E_Record_Subtype
then
18539 Set_First_Entity
(T
, First_Entity
(Base_T
));
18540 Set_Has_Discriminants
(T
, Has_Discriminants
(Base_T
));
18541 Set_Is_Constrained
(T
);
18544 Insert_Before
(Related_Nod
, Decl
);
18550 -- When generating code, insert subtype declaration ahead of
18551 -- declaration that generated it.
18553 Insert_Action
(Obj_Def
,
18554 Make_Subtype_Declaration
(Sloc
(P
),
18555 Defining_Identifier
=> T
,
18556 Subtype_Indication
=> Relocate_Node
(Obj_Def
)));
18558 -- This subtype may need freezing, and this will not be done
18559 -- automatically if the object declaration is not in declarative
18560 -- part. Since this is an object declaration, the type cannot always
18561 -- be frozen here. Deferred constants do not freeze their type
18562 -- (which often enough will be private).
18564 if Nkind
(P
) = N_Object_Declaration
18565 and then Constant_Present
(P
)
18566 and then No
(Expression
(P
))
18570 -- Here we freeze the base type of object type to catch premature use
18571 -- of discriminated private type without a full view.
18574 Insert_Actions
(Obj_Def
, Freeze_Entity
(Base_Type
(T
), P
));
18577 -- Ada 2005 AI-406: the object definition in an object declaration
18578 -- can be an access definition.
18580 elsif Def_Kind
= N_Access_Definition
then
18581 T
:= Access_Definition
(Related_Nod
, Obj_Def
);
18583 Set_Is_Local_Anonymous_Access
18584 (T
, Ada_Version
< Ada_2012
18585 or else Nkind
(P
) /= N_Object_Declaration
18586 or else Is_Library_Level_Entity
(Defining_Identifier
(P
)));
18588 -- Otherwise, the object definition is just a subtype_mark
18591 T
:= Process_Subtype
(Obj_Def
, Related_Nod
);
18595 end Find_Type_Of_Object
;
18597 --------------------------------
18598 -- Find_Type_Of_Subtype_Indic --
18599 --------------------------------
18601 function Find_Type_Of_Subtype_Indic
(S
: Node_Id
) return Entity_Id
is
18605 -- Case of subtype mark with a constraint
18607 if Nkind
(S
) = N_Subtype_Indication
then
18608 Find_Type
(Subtype_Mark
(S
));
18609 Typ
:= Entity
(Subtype_Mark
(S
));
18612 Is_Valid_Constraint_Kind
(Ekind
(Typ
), Nkind
(Constraint
(S
)))
18615 ("incorrect constraint for this kind of type", Constraint
(S
));
18616 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
18619 -- Otherwise we have a subtype mark without a constraint
18621 elsif Error_Posted
(S
) then
18622 -- Don't rewrite if S is Empty or Error
18623 if S
> Empty_Or_Error
then
18624 Rewrite
(S
, New_Occurrence_Of
(Any_Id
, Sloc
(S
)));
18634 end Find_Type_Of_Subtype_Indic
;
18636 -------------------------------------
18637 -- Floating_Point_Type_Declaration --
18638 -------------------------------------
18640 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
18641 Digs
: constant Node_Id
:= Digits_Expression
(Def
);
18642 Max_Digs_Val
: constant Uint
:= Digits_Value
(Standard_Long_Long_Float
);
18644 Base_Typ
: Entity_Id
;
18645 Implicit_Base
: Entity_Id
;
18647 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
18648 -- Find if given digits value, and possibly a specified range, allows
18649 -- derivation from specified type
18651 procedure Convert_Bound
(B
: Node_Id
);
18652 -- If specified, the bounds must be static but may be of different
18653 -- types. They must be converted into machine numbers of the base type,
18654 -- in accordance with RM 4.9(38).
18656 function Find_Base_Type
return Entity_Id
;
18657 -- Find a predefined base type that Def can derive from, or generate
18658 -- an error and substitute Long_Long_Float if none exists.
18660 ---------------------
18661 -- Can_Derive_From --
18662 ---------------------
18664 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
18665 Spec
: constant Entity_Id
:= Real_Range_Specification
(Def
);
18668 -- Check specified "digits" constraint
18670 if Digs_Val
> Digits_Value
(E
) then
18674 -- Check for matching range, if specified
18676 if Present
(Spec
) then
18677 if Expr_Value_R
(Type_Low_Bound
(E
)) >
18678 Expr_Value_R
(Low_Bound
(Spec
))
18683 if Expr_Value_R
(Type_High_Bound
(E
)) <
18684 Expr_Value_R
(High_Bound
(Spec
))
18691 end Can_Derive_From
;
18693 -------------------
18694 -- Convert_Bound --
18695 --------------------
18697 procedure Convert_Bound
(B
: Node_Id
) is
18699 -- If the bound is not a literal it can only be static if it is
18700 -- a static constant, possibly of a specified type.
18702 if Is_Entity_Name
(B
)
18703 and then Ekind
(Entity
(B
)) = E_Constant
18705 Rewrite
(B
, Constant_Value
(Entity
(B
)));
18708 if Nkind
(B
) = N_Real_Literal
then
18709 Set_Realval
(B
, Machine
(Base_Typ
, Realval
(B
), Round
, B
));
18710 Set_Is_Machine_Number
(B
);
18711 Set_Etype
(B
, Base_Typ
);
18715 --------------------
18716 -- Find_Base_Type --
18717 --------------------
18719 function Find_Base_Type
return Entity_Id
is
18720 Choice
: Elmt_Id
:= First_Elmt
(Predefined_Float_Types
);
18723 -- Iterate over the predefined types in order, returning the first
18724 -- one that Def can derive from.
18726 while Present
(Choice
) loop
18727 if Can_Derive_From
(Node
(Choice
)) then
18728 return Node
(Choice
);
18731 Next_Elmt
(Choice
);
18734 -- If we can't derive from any existing type, use Long_Long_Float
18735 -- and give appropriate message explaining the problem.
18737 if Digs_Val
> Max_Digs_Val
then
18738 -- It might be the case that there is a type with the requested
18739 -- range, just not the combination of digits and range.
18742 ("no predefined type has requested range and precision",
18743 Real_Range_Specification
(Def
));
18747 ("range too large for any predefined type",
18748 Real_Range_Specification
(Def
));
18751 return Standard_Long_Long_Float
;
18752 end Find_Base_Type
;
18754 -- Start of processing for Floating_Point_Type_Declaration
18757 Check_Restriction
(No_Floating_Point
, Def
);
18759 -- Create an implicit base type
18762 Create_Itype
(E_Floating_Point_Type
, Parent
(Def
), T
, 'B');
18764 -- Analyze and verify digits value
18766 Analyze_And_Resolve
(Digs
, Any_Integer
);
18767 Check_Digits_Expression
(Digs
);
18768 Digs_Val
:= Expr_Value
(Digs
);
18770 -- Process possible range spec and find correct type to derive from
18772 Process_Real_Range_Specification
(Def
);
18774 -- Check that requested number of digits is not too high.
18776 if Digs_Val
> Max_Digs_Val
then
18778 -- The check for Max_Base_Digits may be somewhat expensive, as it
18779 -- requires reading System, so only do it when necessary.
18782 Max_Base_Digits
: constant Uint
:=
18785 (Parent
(RTE
(RE_Max_Base_Digits
))));
18788 if Digs_Val
> Max_Base_Digits
then
18789 Error_Msg_Uint_1
:= Max_Base_Digits
;
18790 Error_Msg_N
("digits value out of range, maximum is ^", Digs
);
18792 elsif No
(Real_Range_Specification
(Def
)) then
18793 Error_Msg_Uint_1
:= Max_Digs_Val
;
18794 Error_Msg_N
("types with more than ^ digits need range spec "
18795 & "(RM 3.5.7(6))", Digs
);
18800 -- Find a suitable type to derive from or complain and use a substitute
18802 Base_Typ
:= Find_Base_Type
;
18804 -- If there are bounds given in the declaration use them as the bounds
18805 -- of the type, otherwise use the bounds of the predefined base type
18806 -- that was chosen based on the Digits value.
18808 if Present
(Real_Range_Specification
(Def
)) then
18809 Set_Scalar_Range
(T
, Real_Range_Specification
(Def
));
18810 Set_Is_Constrained
(T
);
18812 Convert_Bound
(Type_Low_Bound
(T
));
18813 Convert_Bound
(Type_High_Bound
(T
));
18816 Set_Scalar_Range
(T
, Scalar_Range
(Base_Typ
));
18819 -- Complete definition of implicit base and declared first subtype. The
18820 -- inheritance of the rep item chain ensures that SPARK-related pragmas
18821 -- are not clobbered when the floating point type acts as a full view of
18824 Set_Etype
(Implicit_Base
, Base_Typ
);
18825 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
18826 Set_Size_Info
(Implicit_Base
, Base_Typ
);
18827 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
18828 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
18829 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Base_Typ
));
18830 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Base_Typ
));
18832 Mutate_Ekind
(T
, E_Floating_Point_Subtype
);
18833 Set_Etype
(T
, Implicit_Base
);
18834 Set_Size_Info
(T
, Implicit_Base
);
18835 Set_RM_Size
(T
, RM_Size
(Implicit_Base
));
18836 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
18838 if Digs_Val
>= Uint_1
then
18839 Set_Digits_Value
(T
, Digs_Val
);
18841 pragma Assert
(Serious_Errors_Detected
> 0); null;
18843 end Floating_Point_Type_Declaration
;
18845 ----------------------------
18846 -- Get_Discriminant_Value --
18847 ----------------------------
18849 -- This is the situation:
18851 -- There is a non-derived type
18853 -- type T0 (Dx, Dy, Dz...)
18855 -- There are zero or more levels of derivation, with each derivation
18856 -- either purely inheriting the discriminants, or defining its own.
18858 -- type Ti is new Ti-1
18860 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
18862 -- subtype Ti is ...
18864 -- The subtype issue is avoided by the use of Original_Record_Component,
18865 -- and the fact that derived subtypes also derive the constraints.
18867 -- This chain leads back from
18869 -- Typ_For_Constraint
18871 -- Typ_For_Constraint has discriminants, and the value for each
18872 -- discriminant is given by its corresponding Elmt of Constraints.
18874 -- Discriminant is some discriminant in this hierarchy
18876 -- We need to return its value
18878 -- We do this by recursively searching each level, and looking for
18879 -- Discriminant. Once we get to the bottom, we start backing up
18880 -- returning the value for it which may in turn be a discriminant
18881 -- further up, so on the backup we continue the substitution.
18883 function Get_Discriminant_Value
18884 (Discriminant
: Entity_Id
;
18885 Typ_For_Constraint
: Entity_Id
;
18886 Constraint
: Elist_Id
) return Node_Id
18888 function Root_Corresponding_Discriminant
18889 (Discr
: Entity_Id
) return Entity_Id
;
18890 -- Given a discriminant, traverse the chain of inherited discriminants
18891 -- and return the topmost discriminant.
18893 function Search_Derivation_Levels
18895 Discrim_Values
: Elist_Id
;
18896 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
;
18897 -- This is the routine that performs the recursive search of levels
18898 -- as described above.
18900 -------------------------------------
18901 -- Root_Corresponding_Discriminant --
18902 -------------------------------------
18904 function Root_Corresponding_Discriminant
18905 (Discr
: Entity_Id
) return Entity_Id
18911 while Present
(Corresponding_Discriminant
(D
)) loop
18912 D
:= Corresponding_Discriminant
(D
);
18916 end Root_Corresponding_Discriminant
;
18918 ------------------------------
18919 -- Search_Derivation_Levels --
18920 ------------------------------
18922 function Search_Derivation_Levels
18924 Discrim_Values
: Elist_Id
;
18925 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
18929 Result
: Node_Or_Entity_Id
;
18930 Result_Entity
: Node_Id
;
18933 -- If inappropriate type, return Error, this happens only in
18934 -- cascaded error situations, and we want to avoid a blow up.
18936 if not Is_Composite_Type
(Ti
) or else Is_Array_Type
(Ti
) then
18940 -- Look deeper if possible. Use Stored_Constraints only for
18941 -- untagged types. For tagged types use the given constraint.
18942 -- This asymmetry needs explanation???
18944 if not Stored_Discrim_Values
18945 and then Present
(Stored_Constraint
(Ti
))
18946 and then not Is_Tagged_Type
(Ti
)
18949 Search_Derivation_Levels
(Ti
, Stored_Constraint
(Ti
), True);
18953 Td
: Entity_Id
:= Etype
(Ti
);
18956 -- If the parent type is private, the full view may include
18957 -- renamed discriminants, and it is those stored values that
18958 -- may be needed (the partial view never has more information
18959 -- than the full view).
18961 if Is_Private_Type
(Td
) and then Present
(Full_View
(Td
)) then
18962 Td
:= Full_View
(Td
);
18966 Result
:= Discriminant
;
18969 if Present
(Stored_Constraint
(Ti
)) then
18971 Search_Derivation_Levels
18972 (Td
, Stored_Constraint
(Ti
), True);
18975 Search_Derivation_Levels
18976 (Td
, Discrim_Values
, Stored_Discrim_Values
);
18982 -- Extra underlying places to search, if not found above. For
18983 -- concurrent types, the relevant discriminant appears in the
18984 -- corresponding record. For a type derived from a private type
18985 -- without discriminant, the full view inherits the discriminants
18986 -- of the full view of the parent.
18988 if Result
= Discriminant
then
18989 if Is_Concurrent_Type
(Ti
)
18990 and then Present
(Corresponding_Record_Type
(Ti
))
18993 Search_Derivation_Levels
(
18994 Corresponding_Record_Type
(Ti
),
18996 Stored_Discrim_Values
);
18998 elsif Is_Private_Type
(Ti
)
18999 and then not Has_Discriminants
(Ti
)
19000 and then Present
(Full_View
(Ti
))
19001 and then Etype
(Full_View
(Ti
)) /= Ti
19004 Search_Derivation_Levels
(
19007 Stored_Discrim_Values
);
19011 -- If Result is not a (reference to a) discriminant, return it,
19012 -- otherwise set Result_Entity to the discriminant.
19014 if Nkind
(Result
) = N_Defining_Identifier
then
19015 pragma Assert
(Result
= Discriminant
);
19016 Result_Entity
:= Result
;
19019 if not Denotes_Discriminant
(Result
) then
19023 Result_Entity
:= Entity
(Result
);
19026 -- See if this level of derivation actually has discriminants because
19027 -- tagged derivations can add them, hence the lower levels need not
19030 if not Has_Discriminants
(Ti
) then
19034 -- Scan Ti's discriminants for Result_Entity, and return its
19035 -- corresponding value, if any.
19037 Result_Entity
:= Original_Record_Component
(Result_Entity
);
19039 Assoc
:= First_Elmt
(Discrim_Values
);
19041 if Stored_Discrim_Values
then
19042 Disc
:= First_Stored_Discriminant
(Ti
);
19044 Disc
:= First_Discriminant
(Ti
);
19047 while Present
(Disc
) loop
19049 -- If no further associations return the discriminant, value will
19050 -- be found on the second pass.
19056 if Original_Record_Component
(Disc
) = Result_Entity
then
19057 return Node
(Assoc
);
19062 if Stored_Discrim_Values
then
19063 Next_Stored_Discriminant
(Disc
);
19065 Next_Discriminant
(Disc
);
19069 -- Could not find it
19072 end Search_Derivation_Levels
;
19076 Result
: Node_Or_Entity_Id
;
19078 -- Start of processing for Get_Discriminant_Value
19081 -- ??? This routine is a gigantic mess and will be deleted. For the
19082 -- time being just test for the trivial case before calling recurse.
19084 -- We are now celebrating the 20th anniversary of this comment!
19086 if Base_Type
(Scope
(Discriminant
)) = Base_Type
(Typ_For_Constraint
) then
19092 D
:= First_Discriminant
(Typ_For_Constraint
);
19093 E
:= First_Elmt
(Constraint
);
19094 while Present
(D
) loop
19095 if Chars
(D
) = Chars
(Discriminant
) then
19099 Next_Discriminant
(D
);
19105 Result
:= Search_Derivation_Levels
19106 (Typ_For_Constraint
, Constraint
, False);
19108 -- ??? hack to disappear when this routine is gone
19110 if Nkind
(Result
) = N_Defining_Identifier
then
19116 D
:= First_Discriminant
(Typ_For_Constraint
);
19117 E
:= First_Elmt
(Constraint
);
19118 while Present
(D
) loop
19119 if Root_Corresponding_Discriminant
(D
) = Discriminant
then
19123 Next_Discriminant
(D
);
19129 pragma Assert
(Nkind
(Result
) /= N_Defining_Identifier
);
19131 end Get_Discriminant_Value
;
19133 --------------------------
19134 -- Has_Range_Constraint --
19135 --------------------------
19137 function Has_Range_Constraint
(N
: Node_Id
) return Boolean is
19138 C
: constant Node_Id
:= Constraint
(N
);
19141 if Nkind
(C
) = N_Range_Constraint
then
19144 elsif Nkind
(C
) = N_Digits_Constraint
then
19146 Is_Decimal_Fixed_Point_Type
(Entity
(Subtype_Mark
(N
)))
19147 or else Present
(Range_Constraint
(C
));
19149 elsif Nkind
(C
) = N_Delta_Constraint
then
19150 return Present
(Range_Constraint
(C
));
19155 end Has_Range_Constraint
;
19157 ------------------------
19158 -- Inherit_Components --
19159 ------------------------
19161 function Inherit_Components
19163 Parent_Base
: Entity_Id
;
19164 Derived_Base
: Entity_Id
;
19165 Is_Tagged
: Boolean;
19166 Inherit_Discr
: Boolean;
19167 Discs
: Elist_Id
) return Elist_Id
19169 Assoc_List
: constant Elist_Id
:= New_Elmt_List
;
19171 procedure Inherit_Component
19172 (Old_C
: Entity_Id
;
19173 Plain_Discrim
: Boolean := False;
19174 Stored_Discrim
: Boolean := False);
19175 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
19176 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
19177 -- True, Old_C is a stored discriminant. If they are both false then
19178 -- Old_C is a regular component.
19180 -----------------------
19181 -- Inherit_Component --
19182 -----------------------
19184 procedure Inherit_Component
19185 (Old_C
: Entity_Id
;
19186 Plain_Discrim
: Boolean := False;
19187 Stored_Discrim
: Boolean := False)
19189 procedure Set_Anonymous_Type
(Id
: Entity_Id
);
19190 -- Id denotes the entity of an access discriminant or anonymous
19191 -- access component. Set the type of Id to either the same type of
19192 -- Old_C or create a new one depending on whether the parent and
19193 -- the child types are in the same scope.
19195 ------------------------
19196 -- Set_Anonymous_Type --
19197 ------------------------
19199 procedure Set_Anonymous_Type
(Id
: Entity_Id
) is
19200 Old_Typ
: constant Entity_Id
:= Etype
(Old_C
);
19203 if Scope
(Parent_Base
) = Scope
(Derived_Base
) then
19204 Set_Etype
(Id
, Old_Typ
);
19206 -- The parent and the derived type are in two different scopes.
19207 -- Reuse the type of the original discriminant / component by
19208 -- copying it in order to preserve all attributes.
19212 Typ
: constant Entity_Id
:= New_Copy
(Old_Typ
);
19215 Set_Etype
(Id
, Typ
);
19217 -- Since we do not generate component declarations for
19218 -- inherited components, associate the itype with the
19221 Set_Associated_Node_For_Itype
(Typ
, Parent
(Derived_Base
));
19222 Set_Scope
(Typ
, Derived_Base
);
19225 end Set_Anonymous_Type
;
19227 -- Local variables and constants
19229 New_C
: constant Entity_Id
:= New_Copy
(Old_C
);
19231 Corr_Discrim
: Entity_Id
;
19232 Discrim
: Entity_Id
;
19234 -- Start of processing for Inherit_Component
19237 pragma Assert
(not Is_Tagged
or not Stored_Discrim
);
19239 Set_Parent
(New_C
, Parent
(Old_C
));
19241 -- Regular discriminants and components must be inserted in the scope
19242 -- of the Derived_Base. Do it here.
19244 if not Stored_Discrim
then
19245 Enter_Name
(New_C
);
19248 -- For tagged types the Original_Record_Component must point to
19249 -- whatever this field was pointing to in the parent type. This has
19250 -- already been achieved by the call to New_Copy above.
19252 if not Is_Tagged
then
19253 Set_Original_Record_Component
(New_C
, New_C
);
19254 Set_Corresponding_Record_Component
(New_C
, Old_C
);
19257 -- Set the proper type of an access discriminant
19259 if Ekind
(New_C
) = E_Discriminant
19260 and then Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
19262 Set_Anonymous_Type
(New_C
);
19265 -- If we have inherited a component then see if its Etype contains
19266 -- references to Parent_Base discriminants. In this case, replace
19267 -- these references with the constraints given in Discs. We do not
19268 -- do this for the partial view of private types because this is
19269 -- not needed (only the components of the full view will be used
19270 -- for code generation) and cause problem. We also avoid this
19271 -- transformation in some error situations.
19273 if Ekind
(New_C
) = E_Component
then
19275 -- Set the proper type of an anonymous access component
19277 if Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
then
19278 Set_Anonymous_Type
(New_C
);
19280 elsif (Is_Private_Type
(Derived_Base
)
19281 and then not Is_Generic_Type
(Derived_Base
))
19282 or else (Is_Empty_Elmt_List
(Discs
)
19283 and then not Expander_Active
)
19285 Set_Etype
(New_C
, Etype
(Old_C
));
19288 -- The current component introduces a circularity of the
19291 -- limited with Pack_2;
19292 -- package Pack_1 is
19293 -- type T_1 is tagged record
19294 -- Comp : access Pack_2.T_2;
19300 -- package Pack_2 is
19301 -- type T_2 is new Pack_1.T_1 with ...;
19306 Constrain_Component_Type
19307 (Old_C
, Derived_Base
, N
, Parent_Base
, Discs
));
19311 if Plain_Discrim
then
19312 Set_Corresponding_Discriminant
(New_C
, Old_C
);
19313 Build_Discriminal
(New_C
);
19315 -- If we are explicitly inheriting a stored discriminant it will be
19316 -- completely hidden.
19318 elsif Stored_Discrim
then
19319 Set_Corresponding_Discriminant
(New_C
, Empty
);
19320 Set_Discriminal
(New_C
, Empty
);
19321 Set_Is_Completely_Hidden
(New_C
);
19323 -- Set the Original_Record_Component of each discriminant in the
19324 -- derived base to point to the corresponding stored that we just
19327 Discrim
:= First_Discriminant
(Derived_Base
);
19328 while Present
(Discrim
) loop
19329 Corr_Discrim
:= Corresponding_Discriminant
(Discrim
);
19331 -- Corr_Discrim could be missing in an error situation
19333 if Present
(Corr_Discrim
)
19334 and then Original_Record_Component
(Corr_Discrim
) = Old_C
19336 Set_Original_Record_Component
(Discrim
, New_C
);
19337 Set_Corresponding_Record_Component
(Discrim
, Empty
);
19340 Next_Discriminant
(Discrim
);
19343 Append_Entity
(New_C
, Derived_Base
);
19346 if not Is_Tagged
then
19347 Append_Elmt
(Old_C
, Assoc_List
);
19348 Append_Elmt
(New_C
, Assoc_List
);
19350 end Inherit_Component
;
19352 -- Variables local to Inherit_Component
19354 Loc
: constant Source_Ptr
:= Sloc
(N
);
19356 Parent_Discrim
: Entity_Id
;
19357 Stored_Discrim
: Entity_Id
;
19359 Component
: Entity_Id
;
19361 -- Start of processing for Inherit_Components
19364 if not Is_Tagged
then
19365 Append_Elmt
(Parent_Base
, Assoc_List
);
19366 Append_Elmt
(Derived_Base
, Assoc_List
);
19369 -- Inherit parent discriminants if needed
19371 if Inherit_Discr
then
19372 Parent_Discrim
:= First_Discriminant
(Parent_Base
);
19373 while Present
(Parent_Discrim
) loop
19374 Inherit_Component
(Parent_Discrim
, Plain_Discrim
=> True);
19375 Next_Discriminant
(Parent_Discrim
);
19379 -- Create explicit stored discrims for untagged types when necessary
19381 if not Has_Unknown_Discriminants
(Derived_Base
)
19382 and then Has_Discriminants
(Parent_Base
)
19383 and then not Is_Tagged
19386 or else First_Discriminant
(Parent_Base
) /=
19387 First_Stored_Discriminant
(Parent_Base
))
19389 Stored_Discrim
:= First_Stored_Discriminant
(Parent_Base
);
19390 while Present
(Stored_Discrim
) loop
19391 Inherit_Component
(Stored_Discrim
, Stored_Discrim
=> True);
19392 Next_Stored_Discriminant
(Stored_Discrim
);
19396 -- See if we can apply the second transformation for derived types, as
19397 -- explained in point 6. in the comments above Build_Derived_Record_Type
19398 -- This is achieved by appending Derived_Base discriminants into Discs,
19399 -- which has the side effect of returning a non empty Discs list to the
19400 -- caller of Inherit_Components, which is what we want. This must be
19401 -- done for private derived types if there are explicit stored
19402 -- discriminants, to ensure that we can retrieve the values of the
19403 -- constraints provided in the ancestors.
19406 and then Is_Empty_Elmt_List
(Discs
)
19407 and then Present
(First_Discriminant
(Derived_Base
))
19409 (not Is_Private_Type
(Derived_Base
)
19410 or else Is_Completely_Hidden
19411 (First_Stored_Discriminant
(Derived_Base
))
19412 or else Is_Generic_Type
(Derived_Base
))
19414 D
:= First_Discriminant
(Derived_Base
);
19415 while Present
(D
) loop
19416 Append_Elmt
(New_Occurrence_Of
(D
, Loc
), Discs
);
19417 Next_Discriminant
(D
);
19421 -- Finally, inherit non-discriminant components unless they are not
19422 -- visible because defined or inherited from the full view of the
19423 -- parent. Don't inherit the _parent field of the parent type.
19425 Component
:= First_Entity
(Parent_Base
);
19426 while Present
(Component
) loop
19428 -- Ada 2005 (AI-251): Do not inherit components associated with
19429 -- secondary tags of the parent.
19431 if Ekind
(Component
) = E_Component
19432 and then Present
(Related_Type
(Component
))
19436 elsif Ekind
(Component
) /= E_Component
19437 or else Chars
(Component
) = Name_uParent
19441 -- If the derived type is within the parent type's declarative
19442 -- region, then the components can still be inherited even though
19443 -- they aren't visible at this point. This can occur for cases
19444 -- such as within public child units where the components must
19445 -- become visible upon entering the child unit's private part.
19447 elsif not Is_Visible_Component
(Component
)
19448 and then not In_Open_Scopes
(Scope
(Parent_Base
))
19452 elsif Ekind
(Derived_Base
) in E_Private_Type | E_Limited_Private_Type
19457 Inherit_Component
(Component
);
19460 Next_Entity
(Component
);
19463 -- For tagged derived types, inherited discriminants cannot be used in
19464 -- component declarations of the record extension part. To achieve this
19465 -- we mark the inherited discriminants as not visible.
19467 if Is_Tagged
and then Inherit_Discr
then
19468 D
:= First_Discriminant
(Derived_Base
);
19469 while Present
(D
) loop
19470 Set_Is_Immediately_Visible
(D
, False);
19471 Next_Discriminant
(D
);
19476 end Inherit_Components
;
19478 ----------------------
19479 -- Is_EVF_Procedure --
19480 ----------------------
19482 function Is_EVF_Procedure
(Subp
: Entity_Id
) return Boolean is
19483 Formal
: Entity_Id
;
19486 -- Examine the formals of an Extensions_Visible False procedure looking
19487 -- for a controlling OUT parameter.
19489 if Ekind
(Subp
) = E_Procedure
19490 and then Extensions_Visible_Status
(Subp
) = Extensions_Visible_False
19492 Formal
:= First_Formal
(Subp
);
19493 while Present
(Formal
) loop
19494 if Ekind
(Formal
) = E_Out_Parameter
19495 and then Is_Controlling_Formal
(Formal
)
19500 Next_Formal
(Formal
);
19505 end Is_EVF_Procedure
;
19507 --------------------------
19508 -- Is_Private_Primitive --
19509 --------------------------
19511 function Is_Private_Primitive
(Prim
: Entity_Id
) return Boolean is
19512 Prim_Scope
: constant Entity_Id
:= Scope
(Prim
);
19513 Priv_Entity
: Entity_Id
;
19515 if Is_Package_Or_Generic_Package
(Prim_Scope
) then
19516 Priv_Entity
:= First_Private_Entity
(Prim_Scope
);
19518 while Present
(Priv_Entity
) loop
19519 if Priv_Entity
= Prim
then
19523 Next_Entity
(Priv_Entity
);
19528 end Is_Private_Primitive
;
19530 ------------------------------
19531 -- Is_Valid_Constraint_Kind --
19532 ------------------------------
19534 function Is_Valid_Constraint_Kind
19535 (T_Kind
: Type_Kind
;
19536 Constraint_Kind
: Node_Kind
) return Boolean
19540 when Enumeration_Kind
19543 return Constraint_Kind
= N_Range_Constraint
;
19545 when Decimal_Fixed_Point_Kind
=>
19546 return Constraint_Kind
in N_Digits_Constraint | N_Range_Constraint
;
19548 when Ordinary_Fixed_Point_Kind
=>
19549 return Constraint_Kind
in N_Delta_Constraint | N_Range_Constraint
;
19552 return Constraint_Kind
in N_Digits_Constraint | N_Range_Constraint
;
19559 | E_Incomplete_Type
19563 return Constraint_Kind
= N_Index_Or_Discriminant_Constraint
;
19566 return True; -- Error will be detected later
19568 end Is_Valid_Constraint_Kind
;
19570 --------------------------
19571 -- Is_Visible_Component --
19572 --------------------------
19574 function Is_Visible_Component
19576 N
: Node_Id
:= Empty
) return Boolean
19578 Original_Comp
: Entity_Id
:= Empty
;
19579 Original_Type
: Entity_Id
;
19580 Type_Scope
: Entity_Id
;
19582 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean;
19583 -- Check whether parent type of inherited component is declared locally,
19584 -- possibly within a nested package or instance. The current scope is
19585 -- the derived record itself.
19587 -------------------
19588 -- Is_Local_Type --
19589 -------------------
19591 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean is
19593 return Scope_Within
(Inner
=> Typ
, Outer
=> Scope
(Current_Scope
));
19596 -- Start of processing for Is_Visible_Component
19599 if Ekind
(C
) in E_Component | E_Discriminant
then
19600 Original_Comp
:= Original_Record_Component
(C
);
19603 if No
(Original_Comp
) then
19605 -- Premature usage, or previous error
19610 Original_Type
:= Scope
(Original_Comp
);
19611 Type_Scope
:= Scope
(Base_Type
(Scope
(C
)));
19614 -- This test only concerns tagged types
19616 if not Is_Tagged_Type
(Original_Type
) then
19618 -- Check if this is a renamed discriminant (hidden either by the
19619 -- derived type or by some ancestor), unless we are analyzing code
19620 -- generated by the expander since it may reference such components
19621 -- (for example see the expansion of Deep_Adjust).
19623 if Ekind
(C
) = E_Discriminant
and then Present
(N
) then
19625 not Comes_From_Source
(N
)
19626 or else not Is_Completely_Hidden
(C
);
19631 -- If it is _Parent or _Tag, there is no visibility issue
19633 elsif not Comes_From_Source
(Original_Comp
) then
19636 -- Discriminants are visible unless the (private) type has unknown
19637 -- discriminants. If the discriminant reference is inserted for a
19638 -- discriminant check on a full view it is also visible.
19640 elsif Ekind
(Original_Comp
) = E_Discriminant
19642 (not Has_Unknown_Discriminants
(Original_Type
)
19643 or else (Present
(N
)
19644 and then Nkind
(N
) = N_Selected_Component
19645 and then Nkind
(Prefix
(N
)) = N_Type_Conversion
19646 and then not Comes_From_Source
(Prefix
(N
))))
19650 -- If the component has been declared in an ancestor which is currently
19651 -- a private type, then it is not visible. The same applies if the
19652 -- component's containing type is not in an open scope and the original
19653 -- component's enclosing type is a visible full view of a private type
19654 -- (which can occur in cases where an attempt is being made to reference
19655 -- a component in a sibling package that is inherited from a visible
19656 -- component of a type in an ancestor package; the component in the
19657 -- sibling package should not be visible even though the component it
19658 -- inherited from is visible), but instance bodies are not subject to
19659 -- this second case since they have the Has_Private_View mechanism to
19660 -- ensure proper visibility. This does not apply however in the case
19661 -- where the scope of the type is a private child unit, or when the
19662 -- parent comes from a local package in which the ancestor is currently
19663 -- visible. The latter suppression of visibility is needed for cases
19664 -- that are tested in B730006.
19666 elsif Is_Private_Type
(Original_Type
)
19668 (not Is_Private_Descendant
(Type_Scope
)
19669 and then not In_Open_Scopes
(Type_Scope
)
19670 and then Has_Private_Declaration
(Original_Type
)
19671 and then not In_Instance_Body
)
19673 -- If the type derives from an entity in a formal package, there
19674 -- are no additional visible components.
19676 if Nkind
(Original_Node
(Unit_Declaration_Node
(Type_Scope
))) =
19677 N_Formal_Package_Declaration
19681 -- if we are not in the private part of the current package, there
19682 -- are no additional visible components.
19684 elsif Ekind
(Scope
(Current_Scope
)) = E_Package
19685 and then not In_Private_Part
(Scope
(Current_Scope
))
19690 Is_Child_Unit
(Cunit_Entity
(Current_Sem_Unit
))
19691 and then In_Open_Scopes
(Scope
(Original_Type
))
19692 and then Is_Local_Type
(Type_Scope
);
19695 -- There is another weird way in which a component may be invisible when
19696 -- the private and the full view are not derived from the same ancestor.
19697 -- Here is an example :
19699 -- type A1 is tagged record F1 : integer; end record;
19700 -- type A2 is new A1 with record F2 : integer; end record;
19701 -- type T is new A1 with private;
19703 -- type T is new A2 with null record;
19705 -- In this case, the full view of T inherits F1 and F2 but the private
19706 -- view inherits only F1
19710 Ancestor
: Entity_Id
:= Scope
(C
);
19714 if Ancestor
= Original_Type
then
19717 -- The ancestor may have a partial view of the original type,
19718 -- but if the full view is in scope, as in a child body, the
19719 -- component is visible.
19721 elsif In_Private_Part
(Scope
(Original_Type
))
19722 and then Full_View
(Ancestor
) = Original_Type
19726 elsif Ancestor
= Etype
(Ancestor
) then
19728 -- No further ancestors to examine
19733 Ancestor
:= Etype
(Ancestor
);
19737 end Is_Visible_Component
;
19739 --------------------------
19740 -- Make_Class_Wide_Type --
19741 --------------------------
19743 procedure Make_Class_Wide_Type
(T
: Entity_Id
) is
19744 CW_Type
: Entity_Id
;
19746 Next_E
: Entity_Id
;
19747 Prev_E
: Entity_Id
;
19750 if Present
(Class_Wide_Type
(T
)) then
19752 -- The class-wide type is a partially decorated entity created for a
19753 -- unanalyzed tagged type referenced through a limited with clause.
19754 -- When the tagged type is analyzed, its class-wide type needs to be
19755 -- redecorated. Note that we reuse the entity created by Decorate_
19756 -- Tagged_Type in order to preserve all links.
19758 if Materialize_Entity
(Class_Wide_Type
(T
)) then
19759 CW_Type
:= Class_Wide_Type
(T
);
19760 Set_Materialize_Entity
(CW_Type
, False);
19762 -- The class wide type can have been defined by the partial view, in
19763 -- which case everything is already done.
19769 -- Default case, we need to create a new class-wide type
19773 New_External_Entity
(E_Void
, Scope
(T
), Sloc
(T
), T
, 'C', 0, 'T');
19776 -- Inherit root type characteristics
19778 CW_Name
:= Chars
(CW_Type
);
19779 Next_E
:= Next_Entity
(CW_Type
);
19780 Prev_E
:= Prev_Entity
(CW_Type
);
19781 Copy_Node
(T
, CW_Type
);
19782 Set_Comes_From_Source
(CW_Type
, False);
19783 Set_Chars
(CW_Type
, CW_Name
);
19784 Set_Parent
(CW_Type
, Parent
(T
));
19785 Set_Prev_Entity
(CW_Type
, Prev_E
);
19786 Set_Next_Entity
(CW_Type
, Next_E
);
19788 -- Ensure we have a new freeze node for the class-wide type. The partial
19789 -- view may have freeze action of its own, requiring a proper freeze
19790 -- node, and the same freeze node cannot be shared between the two
19793 Set_Has_Delayed_Freeze
(CW_Type
);
19794 Set_Freeze_Node
(CW_Type
, Empty
);
19796 -- Customize the class-wide type: It has no prim. op., it cannot be
19797 -- abstract, its Etype points back to the specific root type, and it
19798 -- cannot have any invariants.
19800 if Ekind
(CW_Type
) in Incomplete_Or_Private_Kind
then
19801 Reinit_Field_To_Zero
(CW_Type
, F_Private_Dependents
);
19803 elsif Ekind
(CW_Type
) in Concurrent_Kind
then
19804 Reinit_Field_To_Zero
(CW_Type
, F_First_Private_Entity
);
19805 Reinit_Field_To_Zero
(CW_Type
, F_Scope_Depth_Value
);
19807 if Ekind
(CW_Type
) in Task_Kind
then
19808 Reinit_Field_To_Zero
(CW_Type
, F_Is_Elaboration_Checks_OK_Id
);
19809 Reinit_Field_To_Zero
(CW_Type
, F_Is_Elaboration_Warnings_OK_Id
);
19812 if Ekind
(CW_Type
) in E_Task_Type | E_Protected_Type
then
19813 Reinit_Field_To_Zero
(CW_Type
, F_SPARK_Aux_Pragma_Inherited
);
19816 elsif Ekind
(CW_Type
) = E_Record_Type
then
19817 Reinit_Field_To_Zero
(CW_Type
, F_Corresponding_Concurrent_Type
);
19820 Mutate_Ekind
(CW_Type
, E_Class_Wide_Type
);
19821 Set_Is_Tagged_Type
(CW_Type
, True);
19822 Set_Direct_Primitive_Operations
(CW_Type
, New_Elmt_List
);
19823 Set_Is_Abstract_Type
(CW_Type
, False);
19824 Set_Is_Constrained
(CW_Type
, False);
19825 Set_Is_First_Subtype
(CW_Type
, Is_First_Subtype
(T
));
19826 Set_Default_SSO
(CW_Type
);
19827 Set_Has_Inheritable_Invariants
(CW_Type
, False);
19828 Set_Has_Inherited_Invariants
(CW_Type
, False);
19829 Set_Has_Own_Invariants
(CW_Type
, False);
19831 if Ekind
(T
) = E_Class_Wide_Subtype
then
19832 Set_Etype
(CW_Type
, Etype
(Base_Type
(T
)));
19834 Set_Etype
(CW_Type
, T
);
19837 Set_No_Tagged_Streams_Pragma
(CW_Type
, No_Tagged_Streams
);
19839 -- If this is the class_wide type of a constrained subtype, it does
19840 -- not have discriminants.
19842 Set_Has_Discriminants
(CW_Type
,
19843 Has_Discriminants
(T
) and then not Is_Constrained
(T
));
19845 Set_Has_Unknown_Discriminants
(CW_Type
, True);
19846 Set_Class_Wide_Type
(T
, CW_Type
);
19847 Set_Equivalent_Type
(CW_Type
, Empty
);
19849 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
19851 Set_Class_Wide_Type
(CW_Type
, CW_Type
);
19852 end Make_Class_Wide_Type
;
19858 procedure Make_Index
19860 Related_Nod
: Node_Id
;
19861 Related_Id
: Entity_Id
:= Empty
;
19862 Suffix_Index
: Pos
:= 1)
19866 Def_Id
: Entity_Id
:= Empty
;
19867 Found
: Boolean := False;
19870 -- For a discrete range used in a constrained array definition and
19871 -- defined by a range, an implicit conversion to the predefined type
19872 -- INTEGER is assumed if each bound is either a numeric literal, a named
19873 -- number, or an attribute, and the type of both bounds (prior to the
19874 -- implicit conversion) is the type universal_integer. Otherwise, both
19875 -- bounds must be of the same discrete type, other than universal
19876 -- integer; this type must be determinable independently of the
19877 -- context, but using the fact that the type must be discrete and that
19878 -- both bounds must have the same type.
19880 -- Character literals also have a universal type in the absence of
19881 -- of additional context, and are resolved to Standard_Character.
19883 if Nkind
(N
) = N_Range
then
19885 -- The index is given by a range constraint. The bounds are known
19886 -- to be of a consistent type.
19888 if not Is_Overloaded
(N
) then
19891 -- For universal bounds, choose the specific predefined type
19893 if T
= Universal_Integer
then
19894 T
:= Standard_Integer
;
19896 elsif T
= Any_Character
then
19897 Ambiguous_Character
(Low_Bound
(N
));
19899 T
:= Standard_Character
;
19902 -- The node may be overloaded because some user-defined operators
19903 -- are available, but if a universal interpretation exists it is
19904 -- also the selected one.
19906 elsif Universal_Interpretation
(N
) = Universal_Integer
then
19907 T
:= Standard_Integer
;
19913 Ind
: Interp_Index
;
19917 Get_First_Interp
(N
, Ind
, It
);
19918 while Present
(It
.Typ
) loop
19919 if Is_Discrete_Type
(It
.Typ
) then
19922 and then not Covers
(It
.Typ
, T
)
19923 and then not Covers
(T
, It
.Typ
)
19925 Error_Msg_N
("ambiguous bounds in discrete range", N
);
19933 Get_Next_Interp
(Ind
, It
);
19936 if T
= Any_Type
then
19937 Error_Msg_N
("discrete type required for range", N
);
19938 Set_Etype
(N
, Any_Type
);
19941 elsif T
= Universal_Integer
then
19942 T
:= Standard_Integer
;
19947 if not Is_Discrete_Type
(T
) then
19948 Error_Msg_N
("discrete type required for range", N
);
19949 Set_Etype
(N
, Any_Type
);
19953 -- If the range bounds are "T'First .. T'Last" where T is a name of a
19954 -- discrete type, then use T as the type of the index.
19956 if Nkind
(Low_Bound
(N
)) = N_Attribute_Reference
19957 and then Attribute_Name
(Low_Bound
(N
)) = Name_First
19958 and then Is_Entity_Name
(Prefix
(Low_Bound
(N
)))
19959 and then Is_Discrete_Type
(Entity
(Prefix
(Low_Bound
(N
))))
19961 and then Nkind
(High_Bound
(N
)) = N_Attribute_Reference
19962 and then Attribute_Name
(High_Bound
(N
)) = Name_Last
19963 and then Is_Entity_Name
(Prefix
(High_Bound
(N
)))
19964 and then Entity
(Prefix
(High_Bound
(N
))) = Def_Id
19966 Def_Id
:= Entity
(Prefix
(Low_Bound
(N
)));
19970 Process_Range_Expr_In_Decl
(R
, T
);
19972 elsif Nkind
(N
) = N_Subtype_Indication
then
19974 -- The index is given by a subtype with a range constraint
19976 T
:= Base_Type
(Entity
(Subtype_Mark
(N
)));
19978 if not Is_Discrete_Type
(T
) then
19979 Error_Msg_N
("discrete type required for range", N
);
19980 Set_Etype
(N
, Any_Type
);
19984 R
:= Range_Expression
(Constraint
(N
));
19987 Process_Range_Expr_In_Decl
(R
, Entity
(Subtype_Mark
(N
)));
19989 elsif Nkind
(N
) = N_Attribute_Reference
then
19991 -- Catch beginner's error (use of attribute other than 'Range)
19993 if Attribute_Name
(N
) /= Name_Range
then
19994 Error_Msg_N
("expect attribute ''Range", N
);
19995 Set_Etype
(N
, Any_Type
);
19999 -- If the node denotes the range of a type mark, that is also the
20000 -- resulting type, and we do not need to create an Itype for it.
20002 if Is_Entity_Name
(Prefix
(N
))
20003 and then Comes_From_Source
(N
)
20004 and then Is_Discrete_Type
(Entity
(Prefix
(N
)))
20006 Def_Id
:= Entity
(Prefix
(N
));
20009 Analyze_And_Resolve
(N
);
20013 -- If none of the above, must be a subtype. We convert this to a
20014 -- range attribute reference because in the case of declared first
20015 -- named subtypes, the types in the range reference can be different
20016 -- from the type of the entity. A range attribute normalizes the
20017 -- reference and obtains the correct types for the bounds.
20019 -- This transformation is in the nature of an expansion, is only
20020 -- done if expansion is active. In particular, it is not done on
20021 -- formal generic types, because we need to retain the name of the
20022 -- original index for instantiation purposes.
20025 if not Is_Entity_Name
(N
) or else not Is_Type
(Entity
(N
)) then
20026 Error_Msg_N
("invalid subtype mark in discrete range", N
);
20027 Set_Etype
(N
, Any_Integer
);
20031 -- The type mark may be that of an incomplete type. It is only
20032 -- now that we can get the full view, previous analysis does
20033 -- not look specifically for a type mark.
20035 Set_Entity
(N
, Get_Full_View
(Entity
(N
)));
20036 Set_Etype
(N
, Entity
(N
));
20037 Def_Id
:= Entity
(N
);
20039 if not Is_Discrete_Type
(Def_Id
) then
20040 Error_Msg_N
("discrete type required for index", N
);
20041 Set_Etype
(N
, Any_Type
);
20046 if Expander_Active
then
20048 Make_Attribute_Reference
(Sloc
(N
),
20049 Attribute_Name
=> Name_Range
,
20050 Prefix
=> Relocate_Node
(N
)));
20052 -- The original was a subtype mark that does not freeze. This
20053 -- means that the rewritten version must not freeze either.
20055 Set_Must_Not_Freeze
(N
);
20056 Set_Must_Not_Freeze
(Prefix
(N
));
20057 Analyze_And_Resolve
(N
);
20061 -- If expander is inactive, type is legal, nothing else to construct
20068 if not Is_Discrete_Type
(T
) then
20069 Error_Msg_N
("discrete type required for range", N
);
20070 Set_Etype
(N
, Any_Type
);
20073 elsif T
= Any_Type
then
20074 Set_Etype
(N
, Any_Type
);
20078 -- We will now create the appropriate Itype to describe the range, but
20079 -- first a check. If we originally had a subtype, then we just label
20080 -- the range with this subtype. Not only is there no need to construct
20081 -- a new subtype, but it is wrong to do so for two reasons:
20083 -- 1. A legality concern, if we have a subtype, it must not freeze,
20084 -- and the Itype would cause freezing incorrectly
20086 -- 2. An efficiency concern, if we created an Itype, it would not be
20087 -- recognized as the same type for the purposes of eliminating
20088 -- checks in some circumstances.
20090 -- We signal this case by setting the subtype entity in Def_Id
20092 if No
(Def_Id
) then
20094 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, 'D', Suffix_Index
);
20095 Set_Etype
(Def_Id
, Base_Type
(T
));
20097 if Is_Signed_Integer_Type
(T
) then
20098 Mutate_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
20100 elsif Is_Modular_Integer_Type
(T
) then
20101 Mutate_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
20104 Mutate_Ekind
(Def_Id
, E_Enumeration_Subtype
);
20105 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
20106 Set_First_Literal
(Def_Id
, First_Literal
(T
));
20109 Set_Size_Info
(Def_Id
, (T
));
20110 Set_RM_Size
(Def_Id
, RM_Size
(T
));
20111 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
20113 Set_Scalar_Range
(Def_Id
, R
);
20114 Conditional_Delay
(Def_Id
, T
);
20116 -- In the subtype indication case inherit properties of the parent
20118 if Nkind
(N
) = N_Subtype_Indication
then
20120 -- It is enough to inherit predicate flags and not the predicate
20121 -- functions, because predicates on an index type are illegal
20122 -- anyway and the flags are enough to detect them.
20124 Inherit_Predicate_Flags
(Def_Id
, Entity
(Subtype_Mark
(N
)));
20126 -- If the immediate parent of the new subtype is nonstatic, then
20127 -- the subtype we create is nonstatic as well, even if its bounds
20130 if not Is_OK_Static_Subtype
(Entity
(Subtype_Mark
(N
))) then
20131 Set_Is_Non_Static_Subtype
(Def_Id
);
20135 Set_Parent
(Def_Id
, N
);
20138 -- Final step is to label the index with this constructed type
20140 Set_Etype
(N
, Def_Id
);
20143 ------------------------------
20144 -- Modular_Type_Declaration --
20145 ------------------------------
20147 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
20148 Mod_Expr
: constant Node_Id
:= Expression
(Def
);
20151 procedure Set_Modular_Size
(Bits
: Int
);
20152 -- Sets RM_Size to Bits, and Esize to normal word size above this
20154 ----------------------
20155 -- Set_Modular_Size --
20156 ----------------------
20158 procedure Set_Modular_Size
(Bits
: Int
) is
20162 Set_RM_Size
(T
, UI_From_Int
(Bits
));
20164 if Bits
< System_Max_Binary_Modulus_Power
then
20167 while Siz
< 128 loop
20168 exit when Bits
<= Siz
;
20172 Set_Esize
(T
, UI_From_Int
(Siz
));
20175 Set_Esize
(T
, UI_From_Int
(System_Max_Binary_Modulus_Power
));
20178 if not Non_Binary_Modulus
(T
) and then Esize
(T
) = RM_Size
(T
) then
20179 Set_Is_Known_Valid
(T
);
20181 end Set_Modular_Size
;
20183 -- Start of processing for Modular_Type_Declaration
20186 -- If the mod expression is (exactly) 2 * literal, where literal is
20187 -- 128 or less, then almost certainly the * was meant to be **. Warn.
20189 if Warn_On_Suspicious_Modulus_Value
20190 and then Nkind
(Mod_Expr
) = N_Op_Multiply
20191 and then Nkind
(Left_Opnd
(Mod_Expr
)) = N_Integer_Literal
20192 and then Intval
(Left_Opnd
(Mod_Expr
)) = Uint_2
20193 and then Nkind
(Right_Opnd
(Mod_Expr
)) = N_Integer_Literal
20194 and then Intval
(Right_Opnd
(Mod_Expr
)) <= Uint_128
20197 ("suspicious MOD value, was '*'* intended'??.m?", Mod_Expr
);
20200 -- Proceed with analysis of mod expression
20202 Analyze_And_Resolve
(Mod_Expr
, Any_Integer
);
20205 Mutate_Ekind
(T
, E_Modular_Integer_Type
);
20206 Reinit_Alignment
(T
);
20207 Set_Is_Constrained
(T
);
20209 if not Is_OK_Static_Expression
(Mod_Expr
) then
20210 Flag_Non_Static_Expr
20211 ("non-static expression used for modular type bound!", Mod_Expr
);
20212 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
20214 M_Val
:= Expr_Value
(Mod_Expr
);
20218 Error_Msg_N
("modulus value must be positive", Mod_Expr
);
20219 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
20222 if M_Val
> 2 ** Standard_Long_Integer_Size
then
20223 Check_Restriction
(No_Long_Long_Integers
, Mod_Expr
);
20226 Set_Modulus
(T
, M_Val
);
20228 -- Create bounds for the modular type based on the modulus given in
20229 -- the type declaration and then analyze and resolve those bounds.
20231 Set_Scalar_Range
(T
,
20232 Make_Range
(Sloc
(Mod_Expr
),
20233 Low_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), 0),
20234 High_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), M_Val
- 1)));
20236 -- Properly analyze the literals for the range. We do this manually
20237 -- because we can't go calling Resolve, since we are resolving these
20238 -- bounds with the type, and this type is certainly not complete yet.
20240 Set_Etype
(Low_Bound
(Scalar_Range
(T
)), T
);
20241 Set_Etype
(High_Bound
(Scalar_Range
(T
)), T
);
20242 Set_Is_Static_Expression
(Low_Bound
(Scalar_Range
(T
)));
20243 Set_Is_Static_Expression
(High_Bound
(Scalar_Range
(T
)));
20245 -- Loop through powers of two to find number of bits required
20247 for Bits
in Int
range 0 .. System_Max_Binary_Modulus_Power
loop
20251 if M_Val
= 2 ** Bits
then
20252 Set_Modular_Size
(Bits
);
20257 elsif M_Val
< 2 ** Bits
then
20258 Set_Non_Binary_Modulus
(T
);
20260 if Bits
> System_Max_Nonbinary_Modulus_Power
then
20261 Error_Msg_Uint_1
:=
20262 UI_From_Int
(System_Max_Nonbinary_Modulus_Power
);
20264 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr
);
20265 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
20269 -- In the nonbinary case, set size as per RM 13.3(55)
20271 Set_Modular_Size
(Bits
);
20278 -- If we fall through, then the size exceed System.Max_Binary_Modulus
20279 -- so we just signal an error and set the maximum size.
20281 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Binary_Modulus_Power
);
20282 Error_Msg_F
("modulus exceeds limit (2 '*'*^)", Mod_Expr
);
20284 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
20285 Reinit_Alignment
(T
);
20287 end Modular_Type_Declaration
;
20289 --------------------------
20290 -- New_Concatenation_Op --
20291 --------------------------
20293 procedure New_Concatenation_Op
(Typ
: Entity_Id
) is
20294 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
20297 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
;
20298 -- Create abbreviated declaration for the formal of a predefined
20299 -- Operator 'Op' of type 'Typ'
20301 --------------------
20302 -- Make_Op_Formal --
20303 --------------------
20305 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
is
20306 Formal
: Entity_Id
;
20308 Formal
:= New_Internal_Entity
(E_In_Parameter
, Op
, Loc
, 'P');
20309 Set_Etype
(Formal
, Typ
);
20310 Set_Mechanism
(Formal
, Default_Mechanism
);
20312 end Make_Op_Formal
;
20314 -- Start of processing for New_Concatenation_Op
20317 Op
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Concat
);
20319 Mutate_Ekind
(Op
, E_Operator
);
20320 Set_Is_Not_Self_Hidden
(Op
);
20321 Set_Scope
(Op
, Current_Scope
);
20322 Set_Etype
(Op
, Typ
);
20323 Set_Homonym
(Op
, Get_Name_Entity_Id
(Name_Op_Concat
));
20324 Set_Is_Immediately_Visible
(Op
);
20325 Set_Is_Intrinsic_Subprogram
(Op
);
20326 Set_Has_Completion
(Op
);
20327 Append_Entity
(Op
, Current_Scope
);
20329 Set_Name_Entity_Id
(Name_Op_Concat
, Op
);
20331 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
20332 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
20333 end New_Concatenation_Op
;
20335 -------------------------
20336 -- OK_For_Limited_Init --
20337 -------------------------
20339 -- ???Check all calls of this, and compare the conditions under which it's
20342 function OK_For_Limited_Init
20344 Exp
: Node_Id
) return Boolean
20347 return Is_CPP_Constructor_Call
(Exp
)
20348 or else (Ada_Version
>= Ada_2005
20349 and then not Debug_Flag_Dot_L
20350 and then OK_For_Limited_Init_In_05
(Typ
, Exp
));
20351 end OK_For_Limited_Init
;
20353 -------------------------------
20354 -- OK_For_Limited_Init_In_05 --
20355 -------------------------------
20357 function OK_For_Limited_Init_In_05
20359 Exp
: Node_Id
) return Boolean
20362 -- An object of a limited interface type can be initialized with any
20363 -- expression of a nonlimited descendant type. However this does not
20364 -- apply if this is a view conversion of some other expression. This
20365 -- is checked below.
20367 if Is_Class_Wide_Type
(Typ
)
20368 and then Is_Limited_Interface
(Typ
)
20369 and then not Is_Limited_Type
(Etype
(Exp
))
20370 and then Nkind
(Exp
) /= N_Type_Conversion
20375 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
20376 -- case of limited aggregates (including extension aggregates), and
20377 -- function calls. The function call may have been given in prefixed
20378 -- notation, in which case the original node is an indexed component.
20379 -- If the function is parameterless, the original node was an explicit
20380 -- dereference. The function may also be parameterless, in which case
20381 -- the source node is just an identifier.
20383 -- A branch of a conditional expression may have been removed if the
20384 -- condition is statically known. This happens during expansion, and
20385 -- thus will not happen if previous errors were encountered. The check
20386 -- will have been performed on the chosen branch, which replaces the
20387 -- original conditional expression.
20393 case Nkind
(Original_Node
(Exp
)) is
20395 | N_Delta_Aggregate
20396 | N_Extension_Aggregate
20402 when N_Identifier
=>
20403 return Present
(Entity
(Original_Node
(Exp
)))
20404 and then Ekind
(Entity
(Original_Node
(Exp
))) = E_Function
;
20406 when N_Qualified_Expression
=>
20408 OK_For_Limited_Init_In_05
20409 (Typ
, Expression
(Original_Node
(Exp
)));
20411 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
20412 -- with a function call, the expander has rewritten the call into an
20413 -- N_Type_Conversion node to force displacement of the pointer to
20414 -- reference the component containing the secondary dispatch table.
20415 -- Otherwise a type conversion is not a legal context.
20416 -- A return statement for a build-in-place function returning a
20417 -- synchronized type also introduces an unchecked conversion.
20419 when N_Type_Conversion
20420 | N_Unchecked_Type_Conversion
20422 return not Comes_From_Source
(Exp
)
20424 -- If the conversion has been rewritten, check Original_Node;
20425 -- otherwise, check the expression of the compiler-generated
20426 -- conversion (which is a conversion that we want to ignore
20427 -- for purposes of the limited-initialization restrictions).
20429 (if Is_Rewrite_Substitution
(Exp
)
20430 then OK_For_Limited_Init_In_05
(Typ
, Original_Node
(Exp
))
20431 else OK_For_Limited_Init_In_05
(Typ
, Expression
(Exp
)));
20433 when N_Explicit_Dereference
20434 | N_Indexed_Component
20435 | N_Selected_Component
20437 return Nkind
(Exp
) = N_Function_Call
;
20439 -- A use of 'Input is a function call, hence allowed. Normally the
20440 -- attribute will be changed to a call, but the attribute by itself
20441 -- can occur with -gnatc.
20443 when N_Attribute_Reference
=>
20444 return Attribute_Name
(Original_Node
(Exp
)) = Name_Input
;
20446 -- "return raise ..." is OK
20448 when N_Raise_Expression
=>
20451 -- For a case expression, all dependent expressions must be legal
20453 when N_Case_Expression
=>
20458 Alt
:= First
(Alternatives
(Original_Node
(Exp
)));
20459 while Present
(Alt
) loop
20460 if not OK_For_Limited_Init_In_05
(Typ
, Expression
(Alt
)) then
20470 -- For an if expression, all dependent expressions must be legal
20472 when N_If_Expression
=>
20474 Then_Expr
: constant Node_Id
:=
20475 Next
(First
(Expressions
(Original_Node
(Exp
))));
20476 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
20478 return OK_For_Limited_Init_In_05
(Typ
, Then_Expr
)
20480 OK_For_Limited_Init_In_05
(Typ
, Else_Expr
);
20486 end OK_For_Limited_Init_In_05
;
20488 -------------------------------------------
20489 -- Ordinary_Fixed_Point_Type_Declaration --
20490 -------------------------------------------
20492 procedure Ordinary_Fixed_Point_Type_Declaration
20496 Loc
: constant Source_Ptr
:= Sloc
(Def
);
20497 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
20498 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
20499 Implicit_Base
: Entity_Id
;
20506 Check_Restriction
(No_Fixed_Point
, Def
);
20508 -- Create implicit base type
20511 Create_Itype
(E_Ordinary_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
20512 Set_Etype
(Implicit_Base
, Implicit_Base
);
20514 -- Analyze and process delta expression
20516 Analyze_And_Resolve
(Delta_Expr
, Any_Real
);
20518 Check_Delta_Expression
(Delta_Expr
);
20519 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
20521 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
20523 -- Compute default small from given delta, which is the largest power
20524 -- of two that does not exceed the given delta value.
20534 if Delta_Val
< Ureal_1
then
20535 while Delta_Val
< Tmp
loop
20536 Tmp
:= Tmp
/ Ureal_2
;
20537 Scale
:= Scale
+ 1;
20542 Tmp
:= Tmp
* Ureal_2
;
20543 exit when Tmp
> Delta_Val
;
20544 Scale
:= Scale
- 1;
20548 Small_Val
:= UR_From_Components
(Uint_1
, UI_From_Int
(Scale
), 2);
20551 Set_Small_Value
(Implicit_Base
, Small_Val
);
20553 -- If no range was given, set a dummy range
20555 if RRS
<= Empty_Or_Error
then
20556 Low_Val
:= -Small_Val
;
20557 High_Val
:= Small_Val
;
20559 -- Otherwise analyze and process given range
20563 Low
: constant Node_Id
:= Low_Bound
(RRS
);
20564 High
: constant Node_Id
:= High_Bound
(RRS
);
20567 Analyze_And_Resolve
(Low
, Any_Real
);
20568 Analyze_And_Resolve
(High
, Any_Real
);
20569 Check_Real_Bound
(Low
);
20570 Check_Real_Bound
(High
);
20572 -- Obtain and set the range
20574 Low_Val
:= Expr_Value_R
(Low
);
20575 High_Val
:= Expr_Value_R
(High
);
20577 if Low_Val
> High_Val
then
20578 Error_Msg_NE
("??fixed point type& has null range", Def
, T
);
20583 -- The range for both the implicit base and the declared first subtype
20584 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
20585 -- set a temporary range in place. Note that the bounds of the base
20586 -- type will be widened to be symmetrical and to fill the available
20587 -- bits when the type is frozen.
20589 -- We could do this with all discrete types, and probably should, but
20590 -- we absolutely have to do it for fixed-point, since the end-points
20591 -- of the range and the size are determined by the small value, which
20592 -- could be reset before the freeze point.
20594 Set_Fixed_Range
(Implicit_Base
, Loc
, Low_Val
, High_Val
);
20595 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
20597 -- Complete definition of first subtype. The inheritance of the rep item
20598 -- chain ensures that SPARK-related pragmas are not clobbered when the
20599 -- ordinary fixed point type acts as a full view of a private type.
20601 Mutate_Ekind
(T
, E_Ordinary_Fixed_Point_Subtype
);
20602 Set_Etype
(T
, Implicit_Base
);
20603 Reinit_Size_Align
(T
);
20604 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
20605 Set_Small_Value
(T
, Small_Val
);
20606 Set_Delta_Value
(T
, Delta_Val
);
20607 Set_Is_Constrained
(T
);
20608 end Ordinary_Fixed_Point_Type_Declaration
;
20610 ----------------------------------
20611 -- Preanalyze_Assert_Expression --
20612 ----------------------------------
20614 procedure Preanalyze_Assert_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20616 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
20617 Preanalyze_Spec_Expression
(N
, T
);
20618 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
20619 end Preanalyze_Assert_Expression
;
20621 -- ??? The variant below explicitly saves and restores all the flags,
20622 -- because it is impossible to compose the existing variety of
20623 -- Analyze/Resolve (and their wrappers, e.g. Preanalyze_Spec_Expression)
20624 -- to achieve the desired semantics.
20626 procedure Preanalyze_Assert_Expression
(N
: Node_Id
) is
20627 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20628 Save_Must_Not_Freeze
: constant Boolean := Must_Not_Freeze
(N
);
20629 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
20632 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
20633 In_Spec_Expression
:= True;
20634 Set_Must_Not_Freeze
(N
);
20635 Inside_Preanalysis_Without_Freezing
:=
20636 Inside_Preanalysis_Without_Freezing
+ 1;
20637 Full_Analysis
:= False;
20638 Expander_Mode_Save_And_Set
(False);
20640 if GNATprove_Mode
then
20641 Analyze_And_Resolve
(N
);
20643 Analyze_And_Resolve
(N
, Suppress
=> All_Checks
);
20646 Expander_Mode_Restore
;
20647 Full_Analysis
:= Save_Full_Analysis
;
20648 Inside_Preanalysis_Without_Freezing
:=
20649 Inside_Preanalysis_Without_Freezing
- 1;
20650 Set_Must_Not_Freeze
(N
, Save_Must_Not_Freeze
);
20651 In_Spec_Expression
:= Save_In_Spec_Expression
;
20652 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
20653 end Preanalyze_Assert_Expression
;
20655 -----------------------------------
20656 -- Preanalyze_Default_Expression --
20657 -----------------------------------
20659 procedure Preanalyze_Default_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20660 Save_In_Default_Expr
: constant Boolean := In_Default_Expr
;
20661 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20664 In_Default_Expr
:= True;
20665 In_Spec_Expression
:= True;
20667 Preanalyze_With_Freezing_And_Resolve
(N
, T
);
20669 In_Default_Expr
:= Save_In_Default_Expr
;
20670 In_Spec_Expression
:= Save_In_Spec_Expression
;
20671 end Preanalyze_Default_Expression
;
20673 --------------------------------
20674 -- Preanalyze_Spec_Expression --
20675 --------------------------------
20677 procedure Preanalyze_Spec_Expression
(N
: Node_Id
; T
: Entity_Id
) is
20678 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
20680 In_Spec_Expression
:= True;
20681 Preanalyze_And_Resolve
(N
, T
);
20682 In_Spec_Expression
:= Save_In_Spec_Expression
;
20683 end Preanalyze_Spec_Expression
;
20685 ----------------------------------------
20686 -- Prepare_Private_Subtype_Completion --
20687 ----------------------------------------
20689 procedure Prepare_Private_Subtype_Completion
20691 Related_Nod
: Node_Id
)
20693 Id_B
: constant Entity_Id
:= Base_Type
(Id
);
20694 Full_B
: constant Entity_Id
:= Full_View
(Id_B
);
20698 if Present
(Full_B
) then
20700 -- The Base_Type is already completed, we can complete the subtype
20701 -- now. We have to create a new entity with the same name, Thus we
20702 -- can't use Create_Itype.
20704 Full
:= Make_Defining_Identifier
(Sloc
(Id
), Chars
(Id
));
20705 Set_Is_Itype
(Full
);
20706 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
20707 Complete_Private_Subtype
(Id
, Full
, Full_B
, Related_Nod
);
20708 Set_Full_View
(Id
, Full
);
20711 -- The parent subtype may be private, but the base might not, in some
20712 -- nested instances. In that case, the subtype does not need to be
20713 -- exchanged. It would still be nice to make private subtypes and their
20714 -- bases consistent at all times ???
20716 if Is_Private_Type
(Id_B
) then
20717 Append_Elmt
(Id
, Private_Dependents
(Id_B
));
20719 end Prepare_Private_Subtype_Completion
;
20721 ---------------------------
20722 -- Process_Discriminants --
20723 ---------------------------
20725 procedure Process_Discriminants
20727 Prev
: Entity_Id
:= Empty
)
20729 Elist
: constant Elist_Id
:= New_Elmt_List
;
20732 Discr_Number
: Uint
;
20733 Discr_Type
: Entity_Id
;
20734 Default_Present
: Boolean := False;
20735 Default_Not_Present
: Boolean := False;
20738 -- A composite type other than an array type can have discriminants.
20739 -- On entry, the current scope is the composite type.
20741 -- The discriminants are initially entered into the scope of the type
20742 -- via Enter_Name with the default Ekind of E_Void to prevent premature
20743 -- use, as explained at the end of this procedure.
20745 Discr
:= First
(Discriminant_Specifications
(N
));
20746 while Present
(Discr
) loop
20747 Enter_Name
(Defining_Identifier
(Discr
));
20749 -- For navigation purposes we add a reference to the discriminant
20750 -- in the entity for the type. If the current declaration is a
20751 -- completion, place references on the partial view. Otherwise the
20752 -- type is the current scope.
20754 if Present
(Prev
) then
20756 -- The references go on the partial view, if present. If the
20757 -- partial view has discriminants, the references have been
20758 -- generated already.
20760 if not Has_Discriminants
(Prev
) then
20761 Generate_Reference
(Prev
, Defining_Identifier
(Discr
), 'd');
20765 (Current_Scope
, Defining_Identifier
(Discr
), 'd');
20768 if Nkind
(Discriminant_Type
(Discr
)) = N_Access_Definition
then
20769 Check_Anonymous_Access_Component
20771 Typ
=> Defining_Identifier
(N
),
20774 Access_Def
=> Discriminant_Type
(Discr
));
20776 -- if Check_Anonymous_Access_Component replaced Discr then
20777 -- its Original_Node points to the old Discr and the access type
20778 -- for Discr_Type has already been created.
20780 if Is_Rewrite_Substitution
(Discr
) then
20781 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
20784 Access_Definition
(Discr
, Discriminant_Type
(Discr
));
20786 -- Ada 2005 (AI-254)
20788 if Present
(Access_To_Subprogram_Definition
20789 (Discriminant_Type
(Discr
)))
20790 and then Protected_Present
(Access_To_Subprogram_Definition
20791 (Discriminant_Type
(Discr
)))
20794 Replace_Anonymous_Access_To_Protected_Subprogram
(Discr
);
20798 Find_Type
(Discriminant_Type
(Discr
));
20799 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
20801 if Error_Posted
(Discriminant_Type
(Discr
)) then
20802 Discr_Type
:= Any_Type
;
20806 -- Handling of discriminants that are access types
20808 if Is_Access_Type
(Discr_Type
) then
20810 -- Ada 2005 (AI-230): Access discriminant allowed in non-
20811 -- limited record types
20813 if Ada_Version
< Ada_2005
then
20814 Check_Access_Discriminant_Requires_Limited
20815 (Discr
, Discriminant_Type
(Discr
));
20818 if Ada_Version
= Ada_83
and then Comes_From_Source
(Discr
) then
20820 ("(Ada 83) access discriminant not allowed", Discr
);
20823 -- If not access type, must be a discrete type
20825 elsif not Is_Discrete_Type
(Discr_Type
) then
20827 ("discriminants must have a discrete or access type",
20828 Discriminant_Type
(Discr
));
20831 Set_Etype
(Defining_Identifier
(Discr
), Discr_Type
);
20833 -- If a discriminant specification includes the assignment compound
20834 -- delimiter followed by an expression, the expression is the default
20835 -- expression of the discriminant; the default expression must be of
20836 -- the type of the discriminant. (RM 3.7.1) Since this expression is
20837 -- a default expression, we do the special preanalysis, since this
20838 -- expression does not freeze (see section "Handling of Default and
20839 -- Per-Object Expressions" in spec of package Sem).
20841 if Present
(Expression
(Discr
)) then
20842 Preanalyze_Default_Expression
(Expression
(Discr
), Discr_Type
);
20846 if Nkind
(N
) = N_Formal_Type_Declaration
then
20848 ("discriminant defaults not allowed for formal type",
20849 Expression
(Discr
));
20851 -- Flag an error for a tagged type with defaulted discriminants,
20852 -- excluding limited tagged types when compiling for Ada 2012
20853 -- (see AI05-0214).
20855 elsif Is_Tagged_Type
(Current_Scope
)
20856 and then (not Is_Limited_Type
(Current_Scope
)
20857 or else Ada_Version
< Ada_2012
)
20858 and then Comes_From_Source
(N
)
20860 -- Note: see similar test in Check_Or_Process_Discriminants, to
20861 -- handle the (illegal) case of the completion of an untagged
20862 -- view with discriminants with defaults by a tagged full view.
20863 -- We skip the check if Discr does not come from source, to
20864 -- account for the case of an untagged derived type providing
20865 -- defaults for a renamed discriminant from a private untagged
20866 -- ancestor with a tagged full view (ACATS B460006).
20868 if Ada_Version
>= Ada_2012
then
20870 ("discriminants of nonlimited tagged type cannot have"
20872 Expression
(Discr
));
20875 ("discriminants of tagged type cannot have defaults",
20876 Expression
(Discr
));
20880 Default_Present
:= True;
20881 Append_Elmt
(Expression
(Discr
), Elist
);
20883 -- Tag the defining identifiers for the discriminants with
20884 -- their corresponding default expressions from the tree.
20886 Set_Discriminant_Default_Value
20887 (Defining_Identifier
(Discr
), Expression
(Discr
));
20890 -- In gnatc or GNATprove mode, make sure set Do_Range_Check flag
20891 -- gets set unless we can be sure that no range check is required.
20893 if not Expander_Active
20896 (Expression
(Discr
), Discr_Type
, Assume_Valid
=> True)
20898 Set_Do_Range_Check
(Expression
(Discr
));
20901 -- No default discriminant value given
20904 Default_Not_Present
:= True;
20907 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
20908 -- Discr_Type but with the null-exclusion attribute
20910 if Ada_Version
>= Ada_2005
then
20912 -- Ada 2005 (AI-231): Static checks
20914 if Can_Never_Be_Null
(Discr_Type
) then
20915 Null_Exclusion_Static_Checks
(Discr
);
20917 elsif Is_Access_Type
(Discr_Type
)
20918 and then Null_Exclusion_Present
(Discr
)
20920 -- No need to check itypes because in their case this check
20921 -- was done at their point of creation
20923 and then not Is_Itype
(Discr_Type
)
20925 if Can_Never_Be_Null
(Discr_Type
) then
20927 ("`NOT NULL` not allowed (& already excludes null)",
20932 Set_Etype
(Defining_Identifier
(Discr
),
20933 Create_Null_Excluding_Itype
20935 Related_Nod
=> Discr
));
20937 -- Check for improper null exclusion if the type is otherwise
20938 -- legal for a discriminant.
20940 elsif Null_Exclusion_Present
(Discr
)
20941 and then Is_Discrete_Type
(Discr_Type
)
20944 ("null exclusion can only apply to an access type", Discr
);
20947 -- Ada 2005 (AI-402): access discriminants of nonlimited types
20948 -- can't have defaults. Synchronized types, or types that are
20949 -- explicitly limited are fine, but special tests apply to derived
20950 -- types in generics: in a generic body we have to assume the
20951 -- worst, and therefore defaults are not allowed if the parent is
20952 -- a generic formal private type (see ACATS B370001).
20954 if Is_Access_Type
(Discr_Type
) and then Default_Present
then
20955 if Ekind
(Discr_Type
) /= E_Anonymous_Access_Type
20956 or else Is_Limited_Record
(Current_Scope
)
20957 or else Is_Concurrent_Type
(Current_Scope
)
20958 or else Is_Concurrent_Record_Type
(Current_Scope
)
20959 or else Ekind
(Current_Scope
) = E_Limited_Private_Type
20961 if not Is_Derived_Type
(Current_Scope
)
20962 or else not Is_Generic_Type
(Etype
(Current_Scope
))
20963 or else not In_Package_Body
(Scope
(Etype
(Current_Scope
)))
20964 or else Limited_Present
20965 (Type_Definition
(Parent
(Current_Scope
)))
20971 ("access discriminants of nonlimited types cannot "
20972 & "have defaults", Expression
(Discr
));
20975 elsif Present
(Expression
(Discr
)) then
20977 ("(Ada 2005) access discriminants of nonlimited types "
20978 & "cannot have defaults", Expression
(Discr
));
20986 -- An element list consisting of the default expressions of the
20987 -- discriminants is constructed in the above loop and used to set
20988 -- the Discriminant_Constraint attribute for the type. If an object
20989 -- is declared of this (record or task) type without any explicit
20990 -- discriminant constraint given, this element list will form the
20991 -- actual parameters for the corresponding initialization procedure
20994 Set_Discriminant_Constraint
(Current_Scope
, Elist
);
20995 Set_Stored_Constraint
(Current_Scope
, No_Elist
);
20997 -- Default expressions must be provided either for all or for none
20998 -- of the discriminants of a discriminant part. (RM 3.7.1)
21000 if Default_Present
and then Default_Not_Present
then
21002 ("incomplete specification of defaults for discriminants", N
);
21005 -- The use of the name of a discriminant is not allowed in default
21006 -- expressions of a discriminant part if the specification of the
21007 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
21009 -- To detect this, the discriminant names are entered initially with an
21010 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
21011 -- attempt to use a void entity (for example in an expression that is
21012 -- type-checked) produces the error message: premature usage. Now after
21013 -- completing the semantic analysis of the discriminant part, we can set
21014 -- the Ekind of all the discriminants appropriately.
21016 Discr
:= First
(Discriminant_Specifications
(N
));
21017 Discr_Number
:= Uint_1
;
21018 while Present
(Discr
) loop
21019 Id
:= Defining_Identifier
(Discr
);
21021 if Ekind
(Id
) = E_In_Parameter
then
21022 Reinit_Field_To_Zero
(Id
, F_Discriminal_Link
);
21025 Mutate_Ekind
(Id
, E_Discriminant
);
21026 Set_Is_Not_Self_Hidden
(Id
);
21027 Reinit_Component_Location
(Id
);
21029 Set_Discriminant_Number
(Id
, Discr_Number
);
21031 -- Make sure this is always set, even in illegal programs
21033 Set_Corresponding_Discriminant
(Id
, Empty
);
21035 -- Initialize the Original_Record_Component to the entity itself.
21036 -- Inherit_Components will propagate the right value to
21037 -- discriminants in derived record types.
21039 Set_Original_Record_Component
(Id
, Id
);
21041 -- Create the discriminal for the discriminant
21043 Build_Discriminal
(Id
);
21046 Discr_Number
:= Discr_Number
+ 1;
21049 Set_Has_Discriminants
(Current_Scope
);
21050 end Process_Discriminants
;
21052 -----------------------
21053 -- Process_Full_View --
21054 -----------------------
21056 -- WARNING: This routine manages Ghost regions. Return statements must be
21057 -- replaced by gotos which jump to the end of the routine and restore the
21060 procedure Process_Full_View
(N
: Node_Id
; Full_T
, Priv_T
: Entity_Id
) is
21061 procedure Collect_Implemented_Interfaces
21063 Ifaces
: Elist_Id
);
21064 -- Ada 2005: Gather all the interfaces that Typ directly or
21065 -- inherently implements. Duplicate entries are not added to
21066 -- the list Ifaces.
21068 ------------------------------------
21069 -- Collect_Implemented_Interfaces --
21070 ------------------------------------
21072 procedure Collect_Implemented_Interfaces
21077 Iface_Elmt
: Elmt_Id
;
21080 -- Abstract interfaces are only associated with tagged record types
21082 if not Is_Tagged_Type
(Typ
) or else not Is_Record_Type
(Typ
) then
21086 -- Recursively climb to the ancestors
21088 if Etype
(Typ
) /= Typ
21090 -- Protect the frontend against wrong cyclic declarations like:
21092 -- type B is new A with private;
21093 -- type C is new A with private;
21095 -- type B is new C with null record;
21096 -- type C is new B with null record;
21098 and then Etype
(Typ
) /= Priv_T
21099 and then Etype
(Typ
) /= Full_T
21101 -- Keep separate the management of private type declarations
21103 if Ekind
(Typ
) = E_Record_Type_With_Private
then
21105 -- Handle the following illegal usage:
21106 -- type Private_Type is tagged private;
21108 -- type Private_Type is new Type_Implementing_Iface;
21110 if Present
(Full_View
(Typ
))
21111 and then Etype
(Typ
) /= Full_View
(Typ
)
21113 if Is_Interface
(Etype
(Typ
)) then
21114 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
21117 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
21120 -- Non-private types
21123 if Is_Interface
(Etype
(Typ
)) then
21124 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
21127 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
21131 -- Handle entities in the list of abstract interfaces
21133 if Present
(Interfaces
(Typ
)) then
21134 Iface_Elmt
:= First_Elmt
(Interfaces
(Typ
));
21135 while Present
(Iface_Elmt
) loop
21136 Iface
:= Node
(Iface_Elmt
);
21138 pragma Assert
(Is_Interface
(Iface
));
21140 if not Contain_Interface
(Iface
, Ifaces
) then
21141 Append_Elmt
(Iface
, Ifaces
);
21142 Collect_Implemented_Interfaces
(Iface
, Ifaces
);
21145 Next_Elmt
(Iface_Elmt
);
21148 end Collect_Implemented_Interfaces
;
21152 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
21153 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
21154 -- Save the Ghost-related attributes to restore on exit
21156 Full_Indic
: Node_Id
;
21157 Full_Parent
: Entity_Id
;
21158 Priv_Parent
: Entity_Id
;
21160 -- Start of processing for Process_Full_View
21163 Mark_And_Set_Ghost_Completion
(N
, Priv_T
);
21165 -- First some sanity checks that must be done after semantic
21166 -- decoration of the full view and thus cannot be placed with other
21167 -- similar checks in Find_Type_Name
21169 if not Is_Limited_Type
(Priv_T
)
21170 and then (Is_Limited_Type
(Full_T
)
21171 or else Is_Limited_Composite
(Full_T
))
21173 if In_Instance
then
21177 ("completion of nonlimited type cannot be limited", Full_T
);
21178 Explain_Limited_Type
(Full_T
, Full_T
);
21181 elsif Is_Abstract_Type
(Full_T
)
21182 and then not Is_Abstract_Type
(Priv_T
)
21185 ("completion of nonabstract type cannot be abstract", Full_T
);
21187 elsif Is_Tagged_Type
(Priv_T
)
21188 and then Is_Limited_Type
(Priv_T
)
21189 and then not Is_Limited_Type
(Full_T
)
21191 -- If pragma CPP_Class was applied to the private declaration
21192 -- propagate the limitedness to the full-view
21194 if Is_CPP_Class
(Priv_T
) then
21195 Set_Is_Limited_Record
(Full_T
);
21197 -- GNAT allow its own definition of Limited_Controlled to disobey
21198 -- this rule in order in ease the implementation. This test is safe
21199 -- because Root_Controlled is defined in a child of System that
21200 -- normal programs are not supposed to use.
21202 elsif Is_RTE
(Etype
(Full_T
), RE_Root_Controlled
) then
21203 Set_Is_Limited_Composite
(Full_T
);
21206 ("completion of limited tagged type must be limited", Full_T
);
21209 elsif Is_Generic_Type
(Priv_T
) then
21210 Error_Msg_N
("generic type cannot have a completion", Full_T
);
21213 -- Check that ancestor interfaces of private and full views are
21214 -- consistent. We omit this check for synchronized types because
21215 -- they are performed on the corresponding record type when frozen.
21217 if Ada_Version
>= Ada_2005
21218 and then Is_Tagged_Type
(Priv_T
)
21219 and then Is_Tagged_Type
(Full_T
)
21220 and then not Is_Concurrent_Type
(Full_T
)
21224 Priv_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
21225 Full_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
21228 Collect_Implemented_Interfaces
(Priv_T
, Priv_T_Ifaces
);
21229 Collect_Implemented_Interfaces
(Full_T
, Full_T_Ifaces
);
21231 -- Ada 2005 (AI-251): The partial view shall be a descendant of
21232 -- an interface type if and only if the full type is descendant
21233 -- of the interface type (AARM 7.3 (7.3/2)).
21235 Iface
:= Find_Hidden_Interface
(Priv_T_Ifaces
, Full_T_Ifaces
);
21237 if Present
(Iface
) then
21239 ("interface in partial view& not implemented by full type "
21240 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
21243 Iface
:= Find_Hidden_Interface
(Full_T_Ifaces
, Priv_T_Ifaces
);
21245 if Present
(Iface
) then
21247 ("interface & not implemented by partial view "
21248 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
21253 if Is_Tagged_Type
(Priv_T
)
21254 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21255 and then Is_Derived_Type
(Full_T
)
21257 Priv_Parent
:= Etype
(Priv_T
);
21259 -- The full view of a private extension may have been transformed
21260 -- into an unconstrained derived type declaration and a subtype
21261 -- declaration (see build_derived_record_type for details).
21263 if Nkind
(N
) = N_Subtype_Declaration
then
21264 Full_Indic
:= Subtype_Indication
(N
);
21265 Full_Parent
:= Etype
(Base_Type
(Full_T
));
21267 Full_Indic
:= Subtype_Indication
(Type_Definition
(N
));
21268 Full_Parent
:= Etype
(Full_T
);
21271 -- Check that the parent type of the full type is a descendant of
21272 -- the ancestor subtype given in the private extension. If either
21273 -- entity has an Etype equal to Any_Type then we had some previous
21274 -- error situation [7.3(8)].
21276 if Priv_Parent
= Any_Type
or else Full_Parent
= Any_Type
then
21279 -- Ada 2005 (AI-251): Interfaces in the full type can be given in
21280 -- any order. Therefore we don't have to check that its parent must
21281 -- be a descendant of the parent of the private type declaration.
21283 elsif Is_Interface
(Priv_Parent
)
21284 and then Is_Interface
(Full_Parent
)
21288 -- Ada 2005 (AI-251): If the parent of the private type declaration
21289 -- is an interface there is no need to check that it is an ancestor
21290 -- of the associated full type declaration. The required tests for
21291 -- this case are performed by Build_Derived_Record_Type.
21293 elsif not Is_Interface
(Base_Type
(Priv_Parent
))
21294 and then not Is_Ancestor
(Base_Type
(Priv_Parent
), Full_Parent
)
21297 ("parent of full type must descend from parent of private "
21298 & "extension", Full_Indic
);
21300 -- First check a formal restriction, and then proceed with checking
21301 -- Ada rules. Since the formal restriction is not a serious error, we
21302 -- don't prevent further error detection for this check, hence the
21306 -- Check the rules of 7.3(10): if the private extension inherits
21307 -- known discriminants, then the full type must also inherit those
21308 -- discriminants from the same (ancestor) type, and the parent
21309 -- subtype of the full type must be constrained if and only if
21310 -- the ancestor subtype of the private extension is constrained.
21312 if No
(Discriminant_Specifications
(Parent
(Priv_T
)))
21313 and then not Has_Unknown_Discriminants
(Priv_T
)
21314 and then Has_Discriminants
(Base_Type
(Priv_Parent
))
21317 Priv_Indic
: constant Node_Id
:=
21318 Subtype_Indication
(Parent
(Priv_T
));
21320 Priv_Constr
: constant Boolean :=
21321 Is_Constrained
(Priv_Parent
)
21323 Nkind
(Priv_Indic
) = N_Subtype_Indication
21325 Is_Constrained
(Entity
(Priv_Indic
));
21327 Full_Constr
: constant Boolean :=
21328 Is_Constrained
(Full_Parent
)
21330 Nkind
(Full_Indic
) = N_Subtype_Indication
21332 Is_Constrained
(Entity
(Full_Indic
));
21334 Priv_Discr
: Entity_Id
;
21335 Full_Discr
: Entity_Id
;
21338 Priv_Discr
:= First_Discriminant
(Priv_Parent
);
21339 Full_Discr
:= First_Discriminant
(Full_Parent
);
21340 while Present
(Priv_Discr
) and then Present
(Full_Discr
) loop
21341 if Original_Record_Component
(Priv_Discr
) =
21342 Original_Record_Component
(Full_Discr
)
21344 Corresponding_Discriminant
(Priv_Discr
) =
21345 Corresponding_Discriminant
(Full_Discr
)
21352 Next_Discriminant
(Priv_Discr
);
21353 Next_Discriminant
(Full_Discr
);
21356 if Present
(Priv_Discr
) or else Present
(Full_Discr
) then
21358 ("full view must inherit discriminants of the parent "
21359 & "type used in the private extension", Full_Indic
);
21361 elsif Priv_Constr
and then not Full_Constr
then
21363 ("parent subtype of full type must be constrained",
21366 elsif Full_Constr
and then not Priv_Constr
then
21368 ("parent subtype of full type must be unconstrained",
21373 -- Check the rules of 7.3(12): if a partial view has neither
21374 -- known or unknown discriminants, then the full type
21375 -- declaration shall define a definite subtype.
21377 elsif not Has_Unknown_Discriminants
(Priv_T
)
21378 and then not Has_Discriminants
(Priv_T
)
21379 and then not Is_Constrained
(Full_T
)
21382 ("full view must define a constrained type if partial view "
21383 & "has no discriminants", Full_T
);
21386 -- Do we implement the following properly???
21387 -- If the ancestor subtype of a private extension has constrained
21388 -- discriminants, then the parent subtype of the full view shall
21389 -- impose a statically matching constraint on those discriminants
21394 -- For untagged types, verify that a type without discriminants is
21395 -- not completed with an unconstrained type. A separate error message
21396 -- is produced if the full type has defaulted discriminants.
21398 if Is_Definite_Subtype
(Priv_T
)
21399 and then not Is_Definite_Subtype
(Full_T
)
21401 Error_Msg_Sloc
:= Sloc
(Parent
(Priv_T
));
21403 ("full view of& not compatible with declaration#",
21406 if not Is_Tagged_Type
(Full_T
) then
21408 ("\one is constrained, the other unconstrained", Full_T
);
21413 -- AI-419: verify that the use of "limited" is consistent
21416 Orig_Decl
: constant Node_Id
:= Original_Node
(N
);
21419 if Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21420 and then Nkind
(Orig_Decl
) = N_Full_Type_Declaration
21422 (Type_Definition
(Orig_Decl
)) = N_Derived_Type_Definition
21424 if not Limited_Present
(Parent
(Priv_T
))
21425 and then not Synchronized_Present
(Parent
(Priv_T
))
21426 and then Limited_Present
(Type_Definition
(Orig_Decl
))
21429 ("full view of non-limited extension cannot be limited", N
);
21431 -- Conversely, if the partial view carries the limited keyword,
21432 -- the full view must as well, even if it may be redundant.
21434 elsif Limited_Present
(Parent
(Priv_T
))
21435 and then not Limited_Present
(Type_Definition
(Orig_Decl
))
21438 ("full view of limited extension must be explicitly limited",
21444 -- Ada 2005 (AI-443): A synchronized private extension must be
21445 -- completed by a task or protected type.
21447 if Ada_Version
>= Ada_2005
21448 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
21449 and then Synchronized_Present
(Parent
(Priv_T
))
21450 and then not Is_Concurrent_Type
(Full_T
)
21452 Error_Msg_N
("full view of synchronized extension must " &
21453 "be synchronized type", N
);
21456 -- Ada 2005 AI-363: if the full view has discriminants with
21457 -- defaults, it is illegal to declare constrained access subtypes
21458 -- whose designated type is the current type. This allows objects
21459 -- of the type that are declared in the heap to be unconstrained.
21461 if not Has_Unknown_Discriminants
(Priv_T
)
21462 and then not Has_Discriminants
(Priv_T
)
21463 and then Has_Defaulted_Discriminants
(Full_T
)
21465 Set_Has_Constrained_Partial_View
(Base_Type
(Full_T
));
21466 Set_Has_Constrained_Partial_View
(Priv_T
);
21469 -- Create a full declaration for all its subtypes recorded in
21470 -- Private_Dependents and swap them similarly to the base type. These
21471 -- are subtypes that have been define before the full declaration of
21472 -- the private type. We also swap the entry in Private_Dependents list
21473 -- so we can properly restore the private view on exit from the scope.
21476 Priv_Elmt
: Elmt_Id
;
21477 Priv_Scop
: Entity_Id
;
21482 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Priv_T
));
21483 while Present
(Priv_Elmt
) loop
21484 Priv
:= Node
(Priv_Elmt
);
21485 Priv_Scop
:= Scope
(Priv
);
21487 if Ekind
(Priv
) in E_Private_Subtype
21488 | E_Limited_Private_Subtype
21489 | E_Record_Subtype_With_Private
21491 Full
:= Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
21492 Set_Is_Itype
(Full
);
21493 Set_Parent
(Full
, Parent
(Priv
));
21494 Set_Associated_Node_For_Itype
(Full
, N
);
21496 -- Now we need to complete the private subtype, but since the
21497 -- base type has already been swapped, we must also swap the
21498 -- subtypes (and thus, reverse the arguments in the call to
21499 -- Complete_Private_Subtype). Also note that we may need to
21500 -- re-establish the scope of the private subtype.
21502 Copy_And_Swap
(Priv
, Full
);
21504 if not In_Open_Scopes
(Priv_Scop
) then
21505 Push_Scope
(Priv_Scop
);
21508 -- Reset Priv_Scop to Empty to indicate no scope was pushed
21510 Priv_Scop
:= Empty
;
21513 Complete_Private_Subtype
(Full
, Priv
, Full_T
, N
);
21514 Set_Full_View
(Full
, Priv
);
21516 if Present
(Priv_Scop
) then
21520 Replace_Elmt
(Priv_Elmt
, Full
);
21523 Next_Elmt
(Priv_Elmt
);
21528 Disp_Typ
: Entity_Id
;
21529 Full_List
: Elist_Id
;
21531 Prim_Elmt
: Elmt_Id
;
21532 Priv_List
: Elist_Id
;
21536 L
: Elist_Id
) return Boolean;
21537 -- Determine whether list L contains element E
21545 L
: Elist_Id
) return Boolean
21547 List_Elmt
: Elmt_Id
;
21550 List_Elmt
:= First_Elmt
(L
);
21551 while Present
(List_Elmt
) loop
21552 if Node
(List_Elmt
) = E
then
21556 Next_Elmt
(List_Elmt
);
21562 -- Start of processing
21565 -- If the private view was tagged, copy the new primitive operations
21566 -- from the private view to the full view.
21568 if Is_Tagged_Type
(Full_T
) then
21569 if Is_Tagged_Type
(Priv_T
) then
21570 Priv_List
:= Primitive_Operations
(Priv_T
);
21571 Prim_Elmt
:= First_Elmt
(Priv_List
);
21573 -- In the case of a concurrent type completing a private tagged
21574 -- type, primitives may have been declared in between the two
21575 -- views. These subprograms need to be wrapped the same way
21576 -- entries and protected procedures are handled because they
21577 -- cannot be directly shared by the two views.
21579 if Is_Concurrent_Type
(Full_T
) then
21581 Conc_Typ
: constant Entity_Id
:=
21582 Corresponding_Record_Type
(Full_T
);
21583 Curr_Nod
: Node_Id
:= Parent
(Conc_Typ
);
21584 Wrap_Spec
: Node_Id
;
21587 while Present
(Prim_Elmt
) loop
21588 Prim
:= Node
(Prim_Elmt
);
21590 if Comes_From_Source
(Prim
)
21591 and then not Is_Abstract_Subprogram
(Prim
)
21594 Make_Subprogram_Declaration
(Sloc
(Prim
),
21598 Obj_Typ
=> Conc_Typ
,
21600 Parameter_Specifications
21603 Insert_After
(Curr_Nod
, Wrap_Spec
);
21604 Curr_Nod
:= Wrap_Spec
;
21606 Analyze
(Wrap_Spec
);
21608 -- Remove the wrapper from visibility to avoid
21609 -- spurious conflict with the wrapped entity.
21611 Set_Is_Immediately_Visible
21612 (Defining_Entity
(Specification
(Wrap_Spec
)),
21616 Next_Elmt
(Prim_Elmt
);
21622 -- For nonconcurrent types, transfer explicit primitives, but
21623 -- omit those inherited from the parent of the private view
21624 -- since they will be re-inherited later on.
21627 Full_List
:= Primitive_Operations
(Full_T
);
21628 while Present
(Prim_Elmt
) loop
21629 Prim
:= Node
(Prim_Elmt
);
21631 if Comes_From_Source
(Prim
)
21632 and then not Contains
(Prim
, Full_List
)
21634 Append_Elmt
(Prim
, Full_List
);
21637 Next_Elmt
(Prim_Elmt
);
21641 -- Untagged private view
21644 Full_List
:= Primitive_Operations
(Full_T
);
21646 -- In this case the partial view is untagged, so here we locate
21647 -- all of the earlier primitives that need to be treated as
21648 -- dispatching (those that appear between the two views). Note
21649 -- that these additional operations must all be new operations
21650 -- (any earlier operations that override inherited operations
21651 -- of the full view will already have been inserted in the
21652 -- primitives list, marked by Check_Operation_From_Private_View
21653 -- as dispatching. Note that implicit "/=" operators are
21654 -- excluded from being added to the primitives list since they
21655 -- shouldn't be treated as dispatching (tagged "/=" is handled
21658 Prim
:= Next_Entity
(Full_T
);
21659 while Present
(Prim
) and then Prim
/= Priv_T
loop
21660 if Ekind
(Prim
) in E_Procedure | E_Function
then
21661 Disp_Typ
:= Find_Dispatching_Type
(Prim
);
21663 if Disp_Typ
= Full_T
21664 and then (Chars
(Prim
) /= Name_Op_Ne
21665 or else Comes_From_Source
(Prim
))
21667 Check_Controlling_Formals
(Full_T
, Prim
);
21669 if Is_Suitable_Primitive
(Prim
)
21670 and then not Is_Dispatching_Operation
(Prim
)
21672 Append_Elmt
(Prim
, Full_List
);
21673 Set_Is_Dispatching_Operation
(Prim
);
21674 Set_DT_Position_Value
(Prim
, No_Uint
);
21677 elsif Is_Dispatching_Operation
(Prim
)
21678 and then Disp_Typ
/= Full_T
21680 -- Verify that it is not otherwise controlled by a
21681 -- formal or a return value of type T.
21683 Check_Controlling_Formals
(Disp_Typ
, Prim
);
21687 Next_Entity
(Prim
);
21691 -- For the tagged case, the two views can share the same primitive
21692 -- operations list and the same class-wide type. Update attributes
21693 -- of the class-wide type which depend on the full declaration.
21695 if Is_Tagged_Type
(Priv_T
) then
21696 Set_Direct_Primitive_Operations
(Priv_T
, Full_List
);
21697 Set_Class_Wide_Type
21698 (Base_Type
(Full_T
), Class_Wide_Type
(Priv_T
));
21700 Propagate_Concurrent_Flags
(Class_Wide_Type
(Priv_T
), Full_T
);
21703 -- For untagged types, copy the primitives across from the private
21704 -- view to the full view, for support of prefixed calls when
21705 -- extensions are enabled, and better error messages otherwise.
21708 Priv_List
:= Primitive_Operations
(Priv_T
);
21709 Prim_Elmt
:= First_Elmt
(Priv_List
);
21711 Full_List
:= Primitive_Operations
(Full_T
);
21712 while Present
(Prim_Elmt
) loop
21713 Prim
:= Node
(Prim_Elmt
);
21714 Append_Elmt
(Prim
, Full_List
);
21715 Next_Elmt
(Prim_Elmt
);
21720 -- Ada 2005 AI 161: Check preelaborable initialization consistency
21722 if Known_To_Have_Preelab_Init
(Priv_T
) then
21724 -- Case where there is a pragma Preelaborable_Initialization. We
21725 -- always allow this in predefined units, which is cheating a bit,
21726 -- but it means we don't have to struggle to meet the requirements in
21727 -- the RM for having Preelaborable Initialization. Otherwise we
21728 -- require that the type meets the RM rules. But we can't check that
21729 -- yet, because of the rule about overriding Initialize, so we simply
21730 -- set a flag that will be checked at freeze time.
21732 if not In_Predefined_Unit
(Full_T
) then
21733 Set_Must_Have_Preelab_Init
(Full_T
);
21737 -- If pragma CPP_Class was applied to the private type declaration,
21738 -- propagate it now to the full type declaration.
21740 if Is_CPP_Class
(Priv_T
) then
21741 Set_Is_CPP_Class
(Full_T
);
21742 Set_Convention
(Full_T
, Convention_CPP
);
21744 -- Check that components of imported CPP types do not have default
21747 Check_CPP_Type_Has_No_Defaults
(Full_T
);
21750 -- If the private view has user specified stream attributes, then so has
21753 -- Why the test, how could these flags be already set in Full_T ???
21755 if Has_Specified_Stream_Read
(Priv_T
) then
21756 Set_Has_Specified_Stream_Read
(Full_T
);
21759 if Has_Specified_Stream_Write
(Priv_T
) then
21760 Set_Has_Specified_Stream_Write
(Full_T
);
21763 if Has_Specified_Stream_Input
(Priv_T
) then
21764 Set_Has_Specified_Stream_Input
(Full_T
);
21767 if Has_Specified_Stream_Output
(Priv_T
) then
21768 Set_Has_Specified_Stream_Output
(Full_T
);
21771 -- Propagate Default_Initial_Condition-related attributes from the
21772 -- partial view to the full view.
21774 Propagate_DIC_Attributes
(Full_T
, From_Typ
=> Priv_T
);
21776 -- And to the underlying full view, if any
21778 if Is_Private_Type
(Full_T
)
21779 and then Present
(Underlying_Full_View
(Full_T
))
21781 Propagate_DIC_Attributes
21782 (Underlying_Full_View
(Full_T
), From_Typ
=> Priv_T
);
21785 -- Propagate invariant-related attributes from the partial view to the
21788 Propagate_Invariant_Attributes
(Full_T
, From_Typ
=> Priv_T
);
21790 -- And to the underlying full view, if any
21792 if Is_Private_Type
(Full_T
)
21793 and then Present
(Underlying_Full_View
(Full_T
))
21795 Propagate_Invariant_Attributes
21796 (Underlying_Full_View
(Full_T
), From_Typ
=> Priv_T
);
21799 -- AI12-0041: Detect an attempt to inherit a class-wide type invariant
21800 -- in the full view without advertising the inheritance in the partial
21801 -- view. This can only occur when the partial view has no parent type
21802 -- and the full view has an interface as a parent. Any other scenarios
21803 -- are illegal because implemented interfaces must match between the
21806 if Is_Tagged_Type
(Priv_T
) and then Is_Tagged_Type
(Full_T
) then
21808 Full_Par
: constant Entity_Id
:= Etype
(Full_T
);
21809 Priv_Par
: constant Entity_Id
:= Etype
(Priv_T
);
21812 if not Is_Interface
(Priv_Par
)
21813 and then Is_Interface
(Full_Par
)
21814 and then Has_Inheritable_Invariants
(Full_Par
)
21817 ("hidden inheritance of class-wide type invariants not "
21823 -- Propagate predicates to full type, and predicate function if already
21824 -- defined. It is not clear that this can actually happen? the partial
21825 -- view cannot be frozen yet, and the predicate function has not been
21826 -- built. Still it is a cheap check and seems safer to make it.
21828 Propagate_Predicate_Attributes
(Full_T
, Priv_T
);
21830 if Is_Private_Type
(Full_T
)
21831 and then Present
(Underlying_Full_View
(Full_T
))
21833 Propagate_Predicate_Attributes
21834 (Underlying_Full_View
(Full_T
), Priv_T
);
21838 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
21839 end Process_Full_View
;
21841 -----------------------------------
21842 -- Process_Incomplete_Dependents --
21843 -----------------------------------
21845 procedure Process_Incomplete_Dependents
21847 Full_T
: Entity_Id
;
21850 Inc_Elmt
: Elmt_Id
;
21851 Priv_Dep
: Entity_Id
;
21852 New_Subt
: Entity_Id
;
21854 Disc_Constraint
: Elist_Id
;
21857 if No
(Private_Dependents
(Inc_T
)) then
21861 -- Itypes that may be generated by the completion of an incomplete
21862 -- subtype are not used by the back-end and not attached to the tree.
21863 -- They are created only for constraint-checking purposes.
21865 Inc_Elmt
:= First_Elmt
(Private_Dependents
(Inc_T
));
21866 while Present
(Inc_Elmt
) loop
21867 Priv_Dep
:= Node
(Inc_Elmt
);
21869 if Ekind
(Priv_Dep
) = E_Subprogram_Type
then
21871 -- An Access_To_Subprogram type may have a return type or a
21872 -- parameter type that is incomplete. Replace with the full view.
21874 if Etype
(Priv_Dep
) = Inc_T
then
21875 Set_Etype
(Priv_Dep
, Full_T
);
21879 Formal
: Entity_Id
;
21882 Formal
:= First_Formal
(Priv_Dep
);
21883 while Present
(Formal
) loop
21884 if Etype
(Formal
) = Inc_T
then
21885 Set_Etype
(Formal
, Full_T
);
21888 Next_Formal
(Formal
);
21892 elsif Is_Overloadable
(Priv_Dep
) then
21894 -- If a subprogram in the incomplete dependents list is primitive
21895 -- for a tagged full type then mark it as a dispatching operation,
21896 -- check whether it overrides an inherited subprogram, and check
21897 -- restrictions on its controlling formals. Note that a protected
21898 -- operation is never dispatching: only its wrapper operation
21899 -- (which has convention Ada) is.
21901 if Is_Tagged_Type
(Full_T
)
21902 and then Is_Primitive
(Priv_Dep
)
21903 and then Convention
(Priv_Dep
) /= Convention_Protected
21905 Check_Operation_From_Incomplete_Type
(Priv_Dep
, Inc_T
);
21906 Set_Is_Dispatching_Operation
(Priv_Dep
);
21907 Check_Controlling_Formals
(Full_T
, Priv_Dep
);
21910 elsif Ekind
(Priv_Dep
) = E_Subprogram_Body
then
21912 -- Can happen during processing of a body before the completion
21913 -- of a TA type. Ignore, because spec is also on dependent list.
21917 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
21918 -- corresponding subtype of the full view.
21920 elsif Ekind
(Priv_Dep
) = E_Incomplete_Subtype
21921 and then Comes_From_Source
(Priv_Dep
)
21923 Set_Subtype_Indication
21924 (Parent
(Priv_Dep
), New_Occurrence_Of
(Full_T
, Sloc
(Priv_Dep
)));
21925 Reinit_Field_To_Zero
21926 (Priv_Dep
, F_Private_Dependents
,
21927 Old_Ekind
=> E_Incomplete_Subtype
);
21928 Mutate_Ekind
(Priv_Dep
, Subtype_Kind
(Ekind
(Full_T
)));
21929 Set_Etype
(Priv_Dep
, Full_T
);
21930 Set_Analyzed
(Parent
(Priv_Dep
), False);
21932 -- Reanalyze the declaration, suppressing the call to Enter_Name
21933 -- to avoid duplicate names.
21935 Analyze_Subtype_Declaration
21936 (N
=> Parent
(Priv_Dep
),
21939 -- Dependent is a subtype
21942 -- We build a new subtype indication using the full view of the
21943 -- incomplete parent. The discriminant constraints have been
21944 -- elaborated already at the point of the subtype declaration.
21946 New_Subt
:= Create_Itype
(E_Void
, N
);
21948 if Has_Discriminants
(Full_T
) then
21949 Disc_Constraint
:= Discriminant_Constraint
(Priv_Dep
);
21951 Disc_Constraint
:= No_Elist
;
21954 Build_Discriminated_Subtype
(Full_T
, New_Subt
, Disc_Constraint
, N
);
21955 Set_Full_View
(Priv_Dep
, New_Subt
);
21958 Next_Elmt
(Inc_Elmt
);
21960 end Process_Incomplete_Dependents
;
21962 --------------------------------
21963 -- Process_Range_Expr_In_Decl --
21964 --------------------------------
21966 procedure Process_Range_Expr_In_Decl
21969 Subtyp
: Entity_Id
:= Empty
;
21970 Check_List
: List_Id
:= No_List
)
21973 R_Checks
: Check_Result
;
21974 Insert_Node
: Node_Id
;
21975 Def_Id
: Entity_Id
;
21978 Analyze_And_Resolve
(R
, Base_Type
(T
));
21980 if Nkind
(R
) = N_Range
then
21981 Lo
:= Low_Bound
(R
);
21982 Hi
:= High_Bound
(R
);
21984 -- Validity checks on the range of a quantified expression are
21985 -- delayed until the construct is transformed into a loop.
21987 if Nkind
(Parent
(R
)) = N_Loop_Parameter_Specification
21988 and then Nkind
(Parent
(Parent
(R
))) = N_Quantified_Expression
21992 -- We need to ensure validity of the bounds here, because if we
21993 -- go ahead and do the expansion, then the expanded code will get
21994 -- analyzed with range checks suppressed and we miss the check.
21996 -- WARNING: The capture of the range bounds with xxx_FIRST/_LAST and
21997 -- the temporaries generated by routine Remove_Side_Effects by means
21998 -- of validity checks must use the same names. When a range appears
21999 -- in the parent of a generic, the range is processed with checks
22000 -- disabled as part of the generic context and with checks enabled
22001 -- for code generation purposes. This leads to link issues as the
22002 -- generic contains references to xxx_FIRST/_LAST, but the inlined
22003 -- template sees the temporaries generated by Remove_Side_Effects.
22006 Validity_Check_Range
(R
, Subtyp
);
22009 -- If there were errors in the declaration, try and patch up some
22010 -- common mistakes in the bounds. The cases handled are literals
22011 -- which are Integer where the expected type is Real and vice versa.
22012 -- These corrections allow the compilation process to proceed further
22013 -- along since some basic assumptions of the format of the bounds
22016 if Etype
(R
) = Any_Type
then
22017 if Nkind
(Lo
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
22019 Make_Real_Literal
(Sloc
(Lo
), UR_From_Uint
(Intval
(Lo
))));
22021 elsif Nkind
(Hi
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
22023 Make_Real_Literal
(Sloc
(Hi
), UR_From_Uint
(Intval
(Hi
))));
22025 elsif Nkind
(Lo
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
22027 Make_Integer_Literal
(Sloc
(Lo
), UR_To_Uint
(Realval
(Lo
))));
22029 elsif Nkind
(Hi
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
22031 Make_Integer_Literal
(Sloc
(Hi
), UR_To_Uint
(Realval
(Hi
))));
22038 -- If the bounds of the range have been mistakenly given as string
22039 -- literals (perhaps in place of character literals), then an error
22040 -- has already been reported, but we rewrite the string literal as a
22041 -- bound of the range's type to avoid blowups in later processing
22042 -- that looks at static values.
22044 if Nkind
(Lo
) = N_String_Literal
then
22046 Make_Attribute_Reference
(Sloc
(Lo
),
22047 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Lo
)),
22048 Attribute_Name
=> Name_First
));
22049 Analyze_And_Resolve
(Lo
);
22052 if Nkind
(Hi
) = N_String_Literal
then
22054 Make_Attribute_Reference
(Sloc
(Hi
),
22055 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Hi
)),
22056 Attribute_Name
=> Name_First
));
22057 Analyze_And_Resolve
(Hi
);
22060 -- If bounds aren't scalar at this point then exit, avoiding
22061 -- problems with further processing of the range in this procedure.
22063 if not Is_Scalar_Type
(Etype
(Lo
)) then
22067 -- Resolve (actually Sem_Eval) has checked that the bounds are in
22068 -- then range of the base type. Here we check whether the bounds
22069 -- are in the range of the subtype itself. Note that if the bounds
22070 -- represent the null range the Constraint_Error exception should
22073 -- Capture values of bounds and generate temporaries for them
22074 -- if needed, before applying checks, since checks may cause
22075 -- duplication of the expression without forcing evaluation.
22077 -- The forced evaluation removes side effects from expressions,
22078 -- which should occur also in GNATprove mode. Otherwise, we end up
22079 -- with unexpected insertions of actions at places where this is
22080 -- not supposed to occur, e.g. on default parameters of a call.
22082 if Expander_Active
or GNATprove_Mode
then
22084 -- Call Force_Evaluation to create declarations as needed
22085 -- to deal with side effects, and also create typ_FIRST/LAST
22086 -- entities for bounds if we have a subtype name.
22088 -- Note: we do this transformation even if expansion is not
22089 -- active if we are in GNATprove_Mode since the transformation
22090 -- is in general required to ensure that the resulting tree has
22091 -- proper Ada semantics.
22094 (Lo
, Related_Id
=> Subtyp
, Is_Low_Bound
=> True);
22096 (Hi
, Related_Id
=> Subtyp
, Is_High_Bound
=> True);
22099 -- We use a flag here instead of suppressing checks on the type
22100 -- because the type we check against isn't necessarily the place
22101 -- where we put the check.
22103 R_Checks
:= Get_Range_Checks
(R
, T
);
22105 -- Look up tree to find an appropriate insertion point. We can't
22106 -- just use insert_actions because later processing depends on
22107 -- the insertion node. Prior to Ada 2012 the insertion point could
22108 -- only be a declaration or a loop, but quantified expressions can
22109 -- appear within any context in an expression, and the insertion
22110 -- point can be any statement, pragma, or declaration.
22112 Insert_Node
:= Parent
(R
);
22113 while Present
(Insert_Node
) loop
22115 Nkind
(Insert_Node
) in N_Declaration
22117 Nkind
(Insert_Node
) not in N_Component_Declaration
22118 | N_Loop_Parameter_Specification
22119 | N_Function_Specification
22120 | N_Procedure_Specification
;
22122 exit when Nkind
(Insert_Node
) in
22123 N_Later_Decl_Item |
22124 N_Statement_Other_Than_Procedure_Call |
22125 N_Procedure_Call_Statement |
22128 Insert_Node
:= Parent
(Insert_Node
);
22131 if Present
(Insert_Node
) then
22133 -- Case of loop statement. Verify that the range is part of the
22134 -- subtype indication of the iteration scheme.
22136 if Nkind
(Insert_Node
) = N_Loop_Statement
then
22141 Indic
:= Parent
(R
);
22142 while Present
(Indic
)
22143 and then Nkind
(Indic
) /= N_Subtype_Indication
22145 Indic
:= Parent
(Indic
);
22148 if Present
(Indic
) then
22149 Def_Id
:= Etype
(Subtype_Mark
(Indic
));
22151 Insert_Range_Checks
22155 Sloc
(Insert_Node
),
22156 Do_Before
=> True);
22160 -- Case of declarations. If the declaration is for a type and
22161 -- involves discriminants, the checks are premature at the
22162 -- declaration point and need to wait for the expansion of the
22163 -- initialization procedure, which will pass in the list to put
22164 -- them on; otherwise, the checks are done at the declaration
22165 -- point and there is no need to do them again in the
22166 -- initialization procedure.
22168 elsif Nkind
(Insert_Node
) in N_Declaration
then
22169 Def_Id
:= Defining_Identifier
(Insert_Node
);
22171 if (Ekind
(Def_Id
) = E_Record_Type
22172 and then Depends_On_Discriminant
(R
))
22174 (Ekind
(Def_Id
) = E_Protected_Type
22175 and then Has_Discriminants
(Def_Id
))
22177 if Present
(Check_List
) then
22178 Append_Range_Checks
22180 Check_List
, Def_Id
, Sloc
(Insert_Node
));
22184 if No
(Check_List
) then
22185 Insert_Range_Checks
22187 Insert_Node
, Def_Id
, Sloc
(Insert_Node
));
22191 -- Case of statements. Drop the checks, as the range appears in
22192 -- the context of a quantified expression. Insertion will take
22193 -- place when expression is expanded.
22200 -- Case of other than an explicit N_Range node
22202 -- The forced evaluation removes side effects from expressions, which
22203 -- should occur also in GNATprove mode. Otherwise, we end up with
22204 -- unexpected insertions of actions at places where this is not
22205 -- supposed to occur, e.g. on default parameters of a call.
22207 elsif Expander_Active
or GNATprove_Mode
then
22208 Get_Index_Bounds
(R
, Lo
, Hi
);
22209 Force_Evaluation
(Lo
);
22210 Force_Evaluation
(Hi
);
22212 end Process_Range_Expr_In_Decl
;
22214 --------------------------------------
22215 -- Process_Real_Range_Specification --
22216 --------------------------------------
22218 procedure Process_Real_Range_Specification
(Def
: Node_Id
) is
22219 Spec
: constant Node_Id
:= Real_Range_Specification
(Def
);
22222 Err
: Boolean := False;
22224 procedure Analyze_Bound
(N
: Node_Id
);
22225 -- Analyze and check one bound
22227 -------------------
22228 -- Analyze_Bound --
22229 -------------------
22231 procedure Analyze_Bound
(N
: Node_Id
) is
22233 Analyze_And_Resolve
(N
, Any_Real
);
22235 if not Is_OK_Static_Expression
(N
) then
22236 Flag_Non_Static_Expr
22237 ("bound in real type definition is not static!", N
);
22242 -- Start of processing for Process_Real_Range_Specification
22245 if Present
(Spec
) then
22246 Lo
:= Low_Bound
(Spec
);
22247 Hi
:= High_Bound
(Spec
);
22248 Analyze_Bound
(Lo
);
22249 Analyze_Bound
(Hi
);
22251 -- If error, clear away junk range specification
22254 Set_Real_Range_Specification
(Def
, Empty
);
22257 end Process_Real_Range_Specification
;
22259 ---------------------
22260 -- Process_Subtype --
22261 ---------------------
22263 function Process_Subtype
22265 Related_Nod
: Node_Id
;
22266 Related_Id
: Entity_Id
:= Empty
;
22267 Suffix
: Character := ' ') return Entity_Id
22269 procedure Check_Incomplete
(T
: Node_Id
);
22270 -- Called to verify that an incomplete type is not used prematurely
22272 ----------------------
22273 -- Check_Incomplete --
22274 ----------------------
22276 procedure Check_Incomplete
(T
: Node_Id
) is
22278 -- Ada 2005 (AI-412): Incomplete subtypes are legal
22280 if Ekind
(Root_Type
(Entity
(T
))) = E_Incomplete_Type
22282 not (Ada_Version
>= Ada_2005
22284 (Nkind
(Parent
(T
)) = N_Subtype_Declaration
22285 or else (Nkind
(Parent
(T
)) = N_Subtype_Indication
22286 and then Nkind
(Parent
(Parent
(T
))) =
22287 N_Subtype_Declaration
)))
22289 Error_Msg_N
("invalid use of type before its full declaration", T
);
22291 end Check_Incomplete
;
22296 Def_Id
: Entity_Id
;
22297 Error_Node
: Node_Id
;
22298 Full_View_Id
: Entity_Id
;
22299 Subtype_Mark_Id
: Entity_Id
;
22301 May_Have_Null_Exclusion
: Boolean;
22303 -- Start of processing for Process_Subtype
22306 -- Case of no constraints present
22308 if Nkind
(S
) /= N_Subtype_Indication
then
22311 -- No way to proceed if the subtype indication is malformed. This
22312 -- will happen for example when the subtype indication in an object
22313 -- declaration is missing altogether and the expression is analyzed
22314 -- as if it were that indication.
22316 if not Is_Entity_Name
(S
) then
22320 Check_Incomplete
(S
);
22323 -- The following mirroring of assertion in Null_Exclusion_Present is
22324 -- ugly, can't we have a range, a static predicate or even a flag???
22326 May_Have_Null_Exclusion
:=
22329 Nkind
(P
) in N_Access_Definition
22330 | N_Access_Function_Definition
22331 | N_Access_Procedure_Definition
22332 | N_Access_To_Object_Definition
22334 | N_Component_Definition
22335 | N_Derived_Type_Definition
22336 | N_Discriminant_Specification
22337 | N_Formal_Object_Declaration
22338 | N_Function_Specification
22339 | N_Object_Declaration
22340 | N_Object_Renaming_Declaration
22341 | N_Parameter_Specification
22342 | N_Subtype_Declaration
;
22344 -- Ada 2005 (AI-231): Static check
22346 if Ada_Version
>= Ada_2005
22347 and then May_Have_Null_Exclusion
22348 and then Null_Exclusion_Present
(P
)
22349 and then Nkind
(P
) /= N_Access_To_Object_Definition
22350 and then not Is_Access_Type
(Entity
(S
))
22352 Error_Msg_N
("`NOT NULL` only allowed for an access type", S
);
22355 -- Create an Itype that is a duplicate of Entity (S) but with the
22356 -- null-exclusion attribute.
22358 if May_Have_Null_Exclusion
22359 and then Is_Access_Type
(Entity
(S
))
22360 and then Null_Exclusion_Present
(P
)
22362 -- No need to check the case of an access to object definition.
22363 -- It is correct to define double not-null pointers.
22366 -- type Not_Null_Int_Ptr is not null access Integer;
22367 -- type Acc is not null access Not_Null_Int_Ptr;
22369 and then Nkind
(P
) /= N_Access_To_Object_Definition
22371 if Can_Never_Be_Null
(Entity
(S
)) then
22372 case Nkind
(Related_Nod
) is
22373 when N_Full_Type_Declaration
=>
22374 if Nkind
(Type_Definition
(Related_Nod
))
22375 in N_Array_Type_Definition
22379 (Component_Definition
22380 (Type_Definition
(Related_Nod
)));
22383 Subtype_Indication
(Type_Definition
(Related_Nod
));
22386 when N_Subtype_Declaration
=>
22387 Error_Node
:= Subtype_Indication
(Related_Nod
);
22389 when N_Object_Declaration
=>
22390 Error_Node
:= Object_Definition
(Related_Nod
);
22392 when N_Component_Declaration
=>
22394 Subtype_Indication
(Component_Definition
(Related_Nod
));
22396 when N_Allocator
=>
22397 Error_Node
:= Expression
(Related_Nod
);
22400 pragma Assert
(False);
22401 Error_Node
:= Related_Nod
;
22405 ("`NOT NULL` not allowed (& already excludes null)",
22411 Create_Null_Excluding_Itype
22413 Related_Nod
=> P
));
22414 Set_Entity
(S
, Etype
(S
));
22419 -- Case of constraint present, so that we have an N_Subtype_Indication
22420 -- node (this node is created only if constraints are present).
22423 Find_Type
(Subtype_Mark
(S
));
22425 if Nkind
(Parent
(S
)) /= N_Access_To_Object_Definition
22427 (Nkind
(Parent
(S
)) = N_Subtype_Declaration
22428 and then Is_Itype
(Defining_Identifier
(Parent
(S
))))
22430 Check_Incomplete
(Subtype_Mark
(S
));
22434 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
22436 -- Explicit subtype declaration case
22438 if Nkind
(P
) = N_Subtype_Declaration
then
22439 Def_Id
:= Defining_Identifier
(P
);
22441 -- Explicit derived type definition case
22443 elsif Nkind
(P
) = N_Derived_Type_Definition
then
22444 Def_Id
:= Defining_Identifier
(Parent
(P
));
22446 -- Implicit case, the Def_Id must be created as an implicit type.
22447 -- The one exception arises in the case of concurrent types, array
22448 -- and access types, where other subsidiary implicit types may be
22449 -- created and must appear before the main implicit type. In these
22450 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
22451 -- has not yet been called to create Def_Id.
22454 if Is_Array_Type
(Subtype_Mark_Id
)
22455 or else Is_Concurrent_Type
(Subtype_Mark_Id
)
22456 or else Is_Access_Type
(Subtype_Mark_Id
)
22460 -- For the other cases, we create a new unattached Itype,
22461 -- and set the indication to ensure it gets attached later.
22465 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
22469 -- If the kind of constraint is invalid for this kind of type,
22470 -- then give an error, and then pretend no constraint was given.
22472 if not Is_Valid_Constraint_Kind
22473 (Ekind
(Subtype_Mark_Id
), Nkind
(Constraint
(S
)))
22476 ("incorrect constraint for this kind of type", Constraint
(S
));
22478 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
22480 -- Set Ekind of orphan itype, to prevent cascaded errors
22482 if Present
(Def_Id
) then
22483 Mutate_Ekind
(Def_Id
, Ekind
(Any_Type
));
22486 -- Make recursive call, having got rid of the bogus constraint
22488 return Process_Subtype
(S
, Related_Nod
, Related_Id
, Suffix
);
22491 -- Remaining processing depends on type. Select on Base_Type kind to
22492 -- ensure getting to the concrete type kind in the case of a private
22493 -- subtype (needed when only doing semantic analysis).
22495 case Ekind
(Base_Type
(Subtype_Mark_Id
)) is
22496 when Access_Kind
=>
22498 -- If this is a constraint on a class-wide type, discard it.
22499 -- There is currently no way to express a partial discriminant
22500 -- constraint on a type with unknown discriminants. This is
22501 -- a pathology that the ACATS wisely decides not to test.
22503 if Is_Class_Wide_Type
(Designated_Type
(Subtype_Mark_Id
)) then
22504 if Comes_From_Source
(S
) then
22506 ("constraint on class-wide type ignored??",
22510 if Nkind
(P
) = N_Subtype_Declaration
then
22511 Set_Subtype_Indication
(P
,
22512 New_Occurrence_Of
(Subtype_Mark_Id
, Sloc
(S
)));
22515 return Subtype_Mark_Id
;
22518 Constrain_Access
(Def_Id
, S
, Related_Nod
);
22521 and then Is_Itype
(Designated_Type
(Def_Id
))
22522 and then Nkind
(Related_Nod
) = N_Subtype_Declaration
22523 and then not Is_Incomplete_Type
(Designated_Type
(Def_Id
))
22525 Build_Itype_Reference
22526 (Designated_Type
(Def_Id
), Related_Nod
);
22530 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
22532 when Decimal_Fixed_Point_Kind
=>
22533 Constrain_Decimal
(Def_Id
, S
);
22535 when Enumeration_Kind
=>
22536 Constrain_Enumeration
(Def_Id
, S
);
22538 when Ordinary_Fixed_Point_Kind
=>
22539 Constrain_Ordinary_Fixed
(Def_Id
, S
);
22542 Constrain_Float
(Def_Id
, S
);
22544 when Integer_Kind
=>
22545 Constrain_Integer
(Def_Id
, S
);
22547 when Class_Wide_Kind
22548 | E_Incomplete_Type
22552 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
22554 if Ekind
(Def_Id
) = E_Incomplete_Type
then
22555 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
22558 when Private_Kind
=>
22560 -- A private type with unknown discriminants may be completed
22561 -- by an unconstrained array type.
22563 if Has_Unknown_Discriminants
(Subtype_Mark_Id
)
22564 and then Present
(Full_View
(Subtype_Mark_Id
))
22565 and then Is_Array_Type
(Full_View
(Subtype_Mark_Id
))
22567 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
22569 -- ... but more commonly is completed by a discriminated record
22573 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
22576 -- The base type may be private but Def_Id may be a full view
22579 if Is_Private_Type
(Def_Id
) then
22580 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
22583 -- In case of an invalid constraint prevent further processing
22584 -- since the type constructed is missing expected fields.
22586 if Etype
(Def_Id
) = Any_Type
then
22590 -- If the full view is that of a task with discriminants,
22591 -- we must constrain both the concurrent type and its
22592 -- corresponding record type. Otherwise we will just propagate
22593 -- the constraint to the full view, if available.
22595 if Present
(Full_View
(Subtype_Mark_Id
))
22596 and then Has_Discriminants
(Subtype_Mark_Id
)
22597 and then Is_Concurrent_Type
(Full_View
(Subtype_Mark_Id
))
22600 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
22602 Set_Entity
(Subtype_Mark
(S
), Full_View
(Subtype_Mark_Id
));
22603 Constrain_Concurrent
(Full_View_Id
, S
,
22604 Related_Nod
, Related_Id
, Suffix
);
22605 Set_Entity
(Subtype_Mark
(S
), Subtype_Mark_Id
);
22606 Set_Full_View
(Def_Id
, Full_View_Id
);
22608 -- Introduce an explicit reference to the private subtype,
22609 -- to prevent scope anomalies in gigi if first use appears
22610 -- in a nested context, e.g. a later function body.
22611 -- Should this be generated in other contexts than a full
22612 -- type declaration?
22614 if Is_Itype
(Def_Id
)
22616 Nkind
(Parent
(P
)) = N_Full_Type_Declaration
22618 Build_Itype_Reference
(Def_Id
, Parent
(P
));
22622 Prepare_Private_Subtype_Completion
(Def_Id
, Related_Nod
);
22625 when Concurrent_Kind
=>
22626 Constrain_Concurrent
(Def_Id
, S
,
22627 Related_Nod
, Related_Id
, Suffix
);
22630 Error_Msg_N
("invalid subtype mark in subtype indication", S
);
22633 -- Size, Alignment, Representation aspects and Convention are always
22634 -- inherited from the base type.
22636 Set_Size_Info
(Def_Id
, (Subtype_Mark_Id
));
22637 Set_Rep_Info
(Def_Id
, (Subtype_Mark_Id
));
22638 Set_Convention
(Def_Id
, Convention
(Subtype_Mark_Id
));
22640 -- The anonymous subtype created for the subtype indication
22641 -- inherits the predicates of the parent.
22643 if Has_Predicates
(Subtype_Mark_Id
) then
22644 Inherit_Predicate_Flags
(Def_Id
, Subtype_Mark_Id
);
22646 -- Indicate where the predicate function may be found
22648 if No
(Predicate_Function
(Def_Id
)) and then Is_Itype
(Def_Id
) then
22649 Set_Predicated_Parent
(Def_Id
, Subtype_Mark_Id
);
22655 end Process_Subtype
;
22657 -----------------------------
22658 -- Record_Type_Declaration --
22659 -----------------------------
22661 procedure Record_Type_Declaration
22666 Def
: constant Node_Id
:= Type_Definition
(N
);
22667 Is_Tagged
: Boolean;
22668 Tag_Comp
: Entity_Id
;
22671 -- These flags must be initialized before calling Process_Discriminants
22672 -- because this routine makes use of them.
22674 Mutate_Ekind
(T
, E_Record_Type
);
22676 Reinit_Size_Align
(T
);
22677 Set_Interfaces
(T
, No_Elist
);
22678 Set_Stored_Constraint
(T
, No_Elist
);
22679 Set_Default_SSO
(T
);
22680 Set_No_Reordering
(T
, No_Component_Reordering
);
22684 if Ada_Version
< Ada_2005
or else not Interface_Present
(Def
) then
22685 -- The flag Is_Tagged_Type might have already been set by
22686 -- Find_Type_Name if it detected an error for declaration T. This
22687 -- arises in the case of private tagged types where the full view
22688 -- omits the word tagged.
22691 Tagged_Present
(Def
)
22692 or else (Serious_Errors_Detected
> 0 and then Is_Tagged_Type
(T
));
22694 Set_Is_Limited_Record
(T
, Limited_Present
(Def
));
22697 Set_Is_Tagged_Type
(T
, True);
22698 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
22701 -- Type is abstract if full declaration carries keyword, or if
22702 -- previous partial view did.
22704 Set_Is_Abstract_Type
(T
, Is_Abstract_Type
(T
)
22705 or else Abstract_Present
(Def
));
22709 Analyze_Interface_Declaration
(T
, Def
);
22711 if Present
(Discriminant_Specifications
(N
)) then
22713 ("interface types cannot have discriminants",
22714 Defining_Identifier
22715 (First
(Discriminant_Specifications
(N
))));
22719 -- First pass: if there are self-referential access components,
22720 -- create the required anonymous access type declarations, and if
22721 -- need be an incomplete type declaration for T itself.
22723 Check_Anonymous_Access_Components
(N
, T
, Prev
, Component_List
(Def
));
22725 if Ada_Version
>= Ada_2005
22726 and then Present
(Interface_List
(Def
))
22728 Check_Interfaces
(N
, Def
);
22731 Ifaces_List
: Elist_Id
;
22734 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
22735 -- already in the parents.
22739 Ifaces_List
=> Ifaces_List
,
22740 Exclude_Parents
=> True);
22742 Set_Interfaces
(T
, Ifaces_List
);
22746 -- Records constitute a scope for the component declarations within.
22747 -- The scope is created prior to the processing of these declarations.
22748 -- Discriminants are processed first, so that they are visible when
22749 -- processing the other components. The Ekind of the record type itself
22750 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
22752 -- Enter record scope
22756 -- If an incomplete or private type declaration was already given for
22757 -- the type, then this scope already exists, and the discriminants have
22758 -- been declared within. We must verify that the full declaration
22759 -- matches the incomplete one.
22761 Check_Or_Process_Discriminants
(N
, T
, Prev
);
22763 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
22764 Set_Has_Delayed_Freeze
(T
, True);
22766 -- For tagged types add a manually analyzed component corresponding
22767 -- to the component _tag, the corresponding piece of tree will be
22768 -- expanded as part of the freezing actions if it is not a CPP_Class.
22772 -- Do not add the tag unless we are in expansion mode
22774 if Expander_Active
then
22775 Tag_Comp
:= Make_Defining_Identifier
(Sloc
(Def
), Name_uTag
);
22776 Enter_Name
(Tag_Comp
);
22778 Mutate_Ekind
(Tag_Comp
, E_Component
);
22779 Set_Is_Tag
(Tag_Comp
);
22780 Set_Is_Aliased
(Tag_Comp
);
22781 Set_Is_Independent
(Tag_Comp
);
22782 Set_Etype
(Tag_Comp
, RTE
(RE_Tag
));
22783 Set_DT_Entry_Count
(Tag_Comp
, No_Uint
);
22784 Set_Original_Record_Component
(Tag_Comp
, Tag_Comp
);
22785 Reinit_Component_Location
(Tag_Comp
);
22787 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
22788 -- implemented interfaces.
22790 if Has_Interfaces
(T
) then
22791 Add_Interface_Tag_Components
(N
, T
);
22795 Make_Class_Wide_Type
(T
);
22796 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
22799 -- We must suppress range checks when processing record components in
22800 -- the presence of discriminants, since we don't want spurious checks to
22801 -- be generated during their analysis, but Suppress_Range_Checks flags
22802 -- must be reset the after processing the record definition.
22804 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
22805 -- couldn't we just use the normal range check suppression method here.
22806 -- That would seem cleaner ???
22808 if Has_Discriminants
(T
) and then not Range_Checks_Suppressed
(T
) then
22809 Set_Kill_Range_Checks
(T
, True);
22810 Record_Type_Definition
(Def
, Prev
);
22811 Set_Kill_Range_Checks
(T
, False);
22813 Record_Type_Definition
(Def
, Prev
);
22816 -- Exit from record scope
22820 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
22821 -- the implemented interfaces and associate them an aliased entity.
22824 and then not Is_Empty_List
(Interface_List
(Def
))
22826 Derive_Progenitor_Subprograms
(T
, T
);
22829 Check_Function_Writable_Actuals
(N
);
22830 end Record_Type_Declaration
;
22832 ----------------------------
22833 -- Record_Type_Definition --
22834 ----------------------------
22836 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
) is
22837 Component
: Entity_Id
;
22838 Ctrl_Components
: Boolean := False;
22839 Final_Storage_Only
: Boolean;
22843 if Ekind
(Prev_T
) = E_Incomplete_Type
then
22844 T
:= Full_View
(Prev_T
);
22849 Set_Is_Not_Self_Hidden
(T
);
22851 Final_Storage_Only
:= not Is_Controlled
(T
);
22853 -- Ada 2005: Check whether an explicit "limited" is present in a derived
22854 -- type declaration.
22856 if Parent_Kind
(Def
) = N_Derived_Type_Definition
22857 and then Limited_Present
(Parent
(Def
))
22859 Set_Is_Limited_Record
(T
);
22862 -- If the component list of a record type is defined by the reserved
22863 -- word null and there is no discriminant part, then the record type has
22864 -- no components and all records of the type are null records (RM 3.7)
22865 -- This procedure is also called to process the extension part of a
22866 -- record extension, in which case the current scope may have inherited
22870 and then Present
(Component_List
(Def
))
22871 and then not Null_Present
(Component_List
(Def
))
22873 Analyze_Declarations
(Component_Items
(Component_List
(Def
)));
22875 if Present
(Variant_Part
(Component_List
(Def
))) then
22876 Analyze
(Variant_Part
(Component_List
(Def
)));
22880 -- After completing the semantic analysis of the record definition,
22881 -- record components, both new and inherited, are accessible. Set their
22882 -- kind accordingly. Exclude malformed itypes from illegal declarations,
22883 -- whose Ekind may be void.
22885 Component
:= First_Entity
(Current_Scope
);
22886 while Present
(Component
) loop
22887 if Ekind
(Component
) = E_Void
22888 and then not Is_Itype
(Component
)
22890 Mutate_Ekind
(Component
, E_Component
);
22891 Reinit_Component_Location
(Component
);
22892 Set_Is_Not_Self_Hidden
(Component
);
22895 Propagate_Concurrent_Flags
(T
, Etype
(Component
));
22897 if Ekind
(Component
) /= E_Component
then
22900 -- Do not set Has_Controlled_Component on a class-wide equivalent
22901 -- type. See Make_CW_Equivalent_Type.
22903 elsif not Is_Class_Wide_Equivalent_Type
(T
)
22904 and then (Has_Controlled_Component
(Etype
(Component
))
22905 or else (Chars
(Component
) /= Name_uParent
22906 and then Is_Controlled
(Etype
(Component
))))
22908 Set_Has_Controlled_Component
(T
, True);
22909 Final_Storage_Only
:=
22911 and then Finalize_Storage_Only
(Etype
(Component
));
22912 Ctrl_Components
:= True;
22915 Next_Entity
(Component
);
22918 -- A Type is Finalize_Storage_Only only if all its controlled components
22921 if Ctrl_Components
then
22922 Set_Finalize_Storage_Only
(T
, Final_Storage_Only
);
22925 -- Place reference to end record on the proper entity, which may
22926 -- be a partial view.
22928 if Present
(Def
) then
22929 Process_End_Label
(Def
, 'e', Prev_T
);
22931 end Record_Type_Definition
;
22933 ---------------------------
22934 -- Replace_Discriminants --
22935 ---------------------------
22937 procedure Replace_Discriminants
(Typ
: Entity_Id
; Decl
: Node_Id
) is
22938 function Process
(N
: Node_Id
) return Traverse_Result
;
22944 function Process
(N
: Node_Id
) return Traverse_Result
is
22948 if Nkind
(N
) = N_Discriminant_Specification
then
22949 Comp
:= First_Discriminant
(Typ
);
22950 while Present
(Comp
) loop
22951 if Original_Record_Component
(Comp
) = Defining_Identifier
(N
)
22952 or else Chars
(Comp
) = Chars
(Defining_Identifier
(N
))
22954 Set_Defining_Identifier
(N
, Comp
);
22958 Next_Discriminant
(Comp
);
22961 elsif Nkind
(N
) = N_Variant_Part
then
22962 Comp
:= First_Discriminant
(Typ
);
22963 while Present
(Comp
) loop
22964 if Original_Record_Component
(Comp
) = Entity
(Name
(N
))
22965 or else Chars
(Comp
) = Chars
(Name
(N
))
22967 -- Make sure to preserve the type coming from the parent on
22968 -- the Name, even if the subtype of the discriminant can be
22969 -- constrained, so that discrete choices inherited from the
22970 -- parent in the variant part are not flagged as violating
22971 -- the constraints of the subtype.
22974 Typ
: constant Entity_Id
:= Etype
(Name
(N
));
22976 Rewrite
(Name
(N
), New_Occurrence_Of
(Comp
, Sloc
(N
)));
22977 Set_Etype
(Name
(N
), Typ
);
22982 Next_Discriminant
(Comp
);
22989 procedure Replace
is new Traverse_Proc
(Process
);
22991 -- Start of processing for Replace_Discriminants
22995 end Replace_Discriminants
;
22997 -------------------------------
22998 -- Set_Completion_Referenced --
22999 -------------------------------
23001 procedure Set_Completion_Referenced
(E
: Entity_Id
) is
23003 -- If in main unit, mark entity that is a completion as referenced,
23004 -- warnings go on the partial view when needed.
23006 if In_Extended_Main_Source_Unit
(E
) then
23007 Set_Referenced
(E
);
23009 end Set_Completion_Referenced
;
23011 ---------------------
23012 -- Set_Default_SSO --
23013 ---------------------
23015 procedure Set_Default_SSO
(T
: Entity_Id
) is
23017 case Opt
.Default_SSO
is
23021 Set_SSO_Set_Low_By_Default
(T
, True);
23023 Set_SSO_Set_High_By_Default
(T
, True);
23025 raise Program_Error
;
23027 end Set_Default_SSO
;
23029 ---------------------
23030 -- Set_Fixed_Range --
23031 ---------------------
23033 -- The range for fixed-point types is complicated by the fact that we
23034 -- do not know the exact end points at the time of the declaration. This
23035 -- is true for three reasons:
23037 -- A size clause may affect the fudging of the end-points.
23038 -- A small clause may affect the values of the end-points.
23039 -- We try to include the end-points if it does not affect the size.
23041 -- This means that the actual end-points must be established at the
23042 -- point when the type is frozen. Meanwhile, we first narrow the range
23043 -- as permitted (so that it will fit if necessary in a small specified
23044 -- size), and then build a range subtree with these narrowed bounds.
23045 -- Set_Fixed_Range constructs the range from real literal values, and
23046 -- sets the range as the Scalar_Range of the given fixed-point type entity.
23048 -- The parent of this range is set to point to the entity so that it is
23049 -- properly hooked into the tree (unlike normal Scalar_Range entries for
23050 -- other scalar types, which are just pointers to the range in the
23051 -- original tree, this would otherwise be an orphan).
23053 -- The tree is left unanalyzed. When the type is frozen, the processing
23054 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
23055 -- analyzed, and uses this as an indication that it should complete
23056 -- work on the range (it will know the final small and size values).
23058 procedure Set_Fixed_Range
23064 S
: constant Node_Id
:=
23066 Low_Bound
=> Make_Real_Literal
(Loc
, Lo
),
23067 High_Bound
=> Make_Real_Literal
(Loc
, Hi
));
23069 Set_Scalar_Range
(E
, S
);
23072 -- Before the freeze point, the bounds of a fixed point are universal
23073 -- and carry the corresponding type.
23075 Set_Etype
(Low_Bound
(S
), Universal_Real
);
23076 Set_Etype
(High_Bound
(S
), Universal_Real
);
23077 end Set_Fixed_Range
;
23079 ----------------------------------
23080 -- Set_Scalar_Range_For_Subtype --
23081 ----------------------------------
23083 procedure Set_Scalar_Range_For_Subtype
23084 (Def_Id
: Entity_Id
;
23088 Kind
: constant Entity_Kind
:= Ekind
(Def_Id
);
23091 -- Defend against previous error
23093 if Nkind
(R
) = N_Error
then
23097 Set_Scalar_Range
(Def_Id
, R
);
23099 -- We need to link the range into the tree before resolving it so
23100 -- that types that are referenced, including importantly the subtype
23101 -- itself, are properly frozen (Freeze_Expression requires that the
23102 -- expression be properly linked into the tree). Of course if it is
23103 -- already linked in, then we do not disturb the current link.
23105 if No
(Parent
(R
)) then
23106 Set_Parent
(R
, Def_Id
);
23109 -- Reset the kind of the subtype during analysis of the range, to
23110 -- catch possible premature use in the bounds themselves.
23112 Process_Range_Expr_In_Decl
(R
, Subt
, Subtyp
=> Def_Id
);
23113 pragma Assert
(Ekind
(Def_Id
) = Kind
);
23114 end Set_Scalar_Range_For_Subtype
;
23116 --------------------------------------------------------
23117 -- Set_Stored_Constraint_From_Discriminant_Constraint --
23118 --------------------------------------------------------
23120 procedure Set_Stored_Constraint_From_Discriminant_Constraint
23124 -- Make sure set if encountered during Expand_To_Stored_Constraint
23126 Set_Stored_Constraint
(E
, No_Elist
);
23128 -- Give it the right value
23130 if Is_Constrained
(E
) and then Has_Discriminants
(E
) then
23131 Set_Stored_Constraint
(E
,
23132 Expand_To_Stored_Constraint
(E
, Discriminant_Constraint
(E
)));
23134 end Set_Stored_Constraint_From_Discriminant_Constraint
;
23136 -------------------------------------
23137 -- Signed_Integer_Type_Declaration --
23138 -------------------------------------
23140 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
23141 Implicit_Base
: Entity_Id
;
23142 Base_Typ
: Entity_Id
;
23145 Errs
: Boolean := False;
23149 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
23150 -- Determine whether given bounds allow derivation from specified type
23152 procedure Check_Bound
(Expr
: Node_Id
);
23153 -- Check bound to make sure it is integral and static. If not, post
23154 -- appropriate error message and set Errs flag
23156 ---------------------
23157 -- Can_Derive_From --
23158 ---------------------
23160 -- Note we check both bounds against both end values, to deal with
23161 -- strange types like ones with a range of 0 .. -12341234.
23163 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
23164 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(E
));
23165 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(E
));
23167 return Lo
<= Lo_Val
and then Lo_Val
<= Hi
23169 Lo
<= Hi_Val
and then Hi_Val
<= Hi
;
23170 end Can_Derive_From
;
23176 procedure Check_Bound
(Expr
: Node_Id
) is
23178 -- If a range constraint is used as an integer type definition, each
23179 -- bound of the range must be defined by a static expression of some
23180 -- integer type, but the two bounds need not have the same integer
23181 -- type (Negative bounds are allowed.) (RM 3.5.4)
23183 if not Is_Integer_Type
(Etype
(Expr
)) then
23185 ("integer type definition bounds must be of integer type", Expr
);
23188 elsif not Is_OK_Static_Expression
(Expr
) then
23189 Flag_Non_Static_Expr
23190 ("non-static expression used for integer type bound!", Expr
);
23193 -- Otherwise the bounds are folded into literals
23195 elsif Is_Entity_Name
(Expr
) then
23196 Fold_Uint
(Expr
, Expr_Value
(Expr
), True);
23200 -- Start of processing for Signed_Integer_Type_Declaration
23203 -- Create an anonymous base type
23206 Create_Itype
(E_Signed_Integer_Type
, Parent
(Def
), T
, 'B');
23208 -- Analyze and check the bounds, they can be of any integer type
23210 Lo
:= Low_Bound
(Def
);
23211 Hi
:= High_Bound
(Def
);
23213 -- Arbitrarily use Integer as the type if either bound had an error
23215 if Hi
= Error
or else Lo
= Error
then
23216 Base_Typ
:= Any_Integer
;
23217 Set_Error_Posted
(T
, True);
23220 -- Here both bounds are OK expressions
23223 Analyze_And_Resolve
(Lo
, Any_Integer
);
23224 Analyze_And_Resolve
(Hi
, Any_Integer
);
23230 Hi
:= Type_High_Bound
(Standard_Long_Long_Long_Integer
);
23231 Lo
:= Type_Low_Bound
(Standard_Long_Long_Long_Integer
);
23234 -- Find type to derive from
23236 Lo_Val
:= Expr_Value
(Lo
);
23237 Hi_Val
:= Expr_Value
(Hi
);
23239 if Can_Derive_From
(Standard_Short_Short_Integer
) then
23240 Base_Typ
:= Base_Type
(Standard_Short_Short_Integer
);
23242 elsif Can_Derive_From
(Standard_Short_Integer
) then
23243 Base_Typ
:= Base_Type
(Standard_Short_Integer
);
23245 elsif Can_Derive_From
(Standard_Integer
) then
23246 Base_Typ
:= Base_Type
(Standard_Integer
);
23248 elsif Can_Derive_From
(Standard_Long_Integer
) then
23249 Base_Typ
:= Base_Type
(Standard_Long_Integer
);
23251 elsif Can_Derive_From
(Standard_Long_Long_Integer
) then
23252 Check_Restriction
(No_Long_Long_Integers
, Def
);
23253 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
23255 elsif Can_Derive_From
(Standard_Long_Long_Long_Integer
) then
23256 Check_Restriction
(No_Long_Long_Integers
, Def
);
23257 Base_Typ
:= Base_Type
(Standard_Long_Long_Long_Integer
);
23260 Base_Typ
:= Base_Type
(Standard_Long_Long_Long_Integer
);
23261 Error_Msg_N
("integer type definition bounds out of range", Def
);
23262 Hi
:= Type_High_Bound
(Standard_Long_Long_Long_Integer
);
23263 Lo
:= Type_Low_Bound
(Standard_Long_Long_Long_Integer
);
23267 -- Set the type of the bounds to the implicit base: we cannot set it to
23268 -- the new type, because this would be a forward reference for the code
23269 -- generator and, if the original type is user-defined, this could even
23270 -- lead to spurious semantic errors. Furthermore we do not set it to be
23271 -- universal, because this could make it much larger than needed here.
23274 Set_Etype
(Lo
, Implicit_Base
);
23275 Set_Etype
(Hi
, Implicit_Base
);
23278 -- Complete both implicit base and declared first subtype entities. The
23279 -- inheritance of the rep item chain ensures that SPARK-related pragmas
23280 -- are not clobbered when the signed integer type acts as a full view of
23283 Set_Etype
(Implicit_Base
, Base_Typ
);
23284 Set_Size_Info
(Implicit_Base
, Base_Typ
);
23285 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
23286 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
23287 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
23289 Mutate_Ekind
(T
, E_Signed_Integer_Subtype
);
23290 Set_Etype
(T
, Implicit_Base
);
23291 Set_Size_Info
(T
, Implicit_Base
);
23292 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
23293 Set_Scalar_Range
(T
, Def
);
23294 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
23295 Set_Is_Constrained
(T
);
23296 end Signed_Integer_Type_Declaration
;