1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Elists; use Elists;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
33 with Eval_Fat; use Eval_Fat;
34 with Exp_Ch3; use Exp_Ch3;
35 with Exp_Dist; use Exp_Dist;
36 with Exp_Tss; use Exp_Tss;
37 with Exp_Util; use Exp_Util;
38 with Freeze; use Freeze;
39 with Itypes; use Itypes;
40 with Layout; use Layout;
42 with Lib.Xref; use Lib.Xref;
43 with Namet; use Namet;
44 with Nmake; use Nmake;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
50 with Sem_Case; use Sem_Case;
51 with Sem_Cat; use Sem_Cat;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch7; use Sem_Ch7;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Ch13; use Sem_Ch13;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Dist; use Sem_Dist;
58 with Sem_Elim; use Sem_Elim;
59 with Sem_Eval; use Sem_Eval;
60 with Sem_Mech; use Sem_Mech;
61 with Sem_Res; use Sem_Res;
62 with Sem_Smem; use Sem_Smem;
63 with Sem_Type; use Sem_Type;
64 with Sem_Util; use Sem_Util;
65 with Sem_Warn; use Sem_Warn;
66 with Stand; use Stand;
67 with Sinfo; use Sinfo;
68 with Snames; use Snames;
69 with Targparm; use Targparm;
70 with Tbuild; use Tbuild;
71 with Ttypes; use Ttypes;
72 with Uintp; use Uintp;
73 with Urealp; use Urealp;
75 package body Sem_Ch3 is
77 -----------------------
78 -- Local Subprograms --
79 -----------------------
81 procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id);
82 -- Ada 2005 (AI-251): Add the tag components corresponding to all the
83 -- abstract interface types implemented by a record type or a derived
86 procedure Build_Derived_Type
88 Parent_Type : Entity_Id;
89 Derived_Type : Entity_Id;
90 Is_Completion : Boolean;
91 Derive_Subps : Boolean := True);
92 -- Create and decorate a Derived_Type given the Parent_Type entity. N is
93 -- the N_Full_Type_Declaration node containing the derived type definition.
94 -- Parent_Type is the entity for the parent type in the derived type
95 -- definition and Derived_Type the actual derived type. Is_Completion must
96 -- be set to False if Derived_Type is the N_Defining_Identifier node in N
97 -- (ie Derived_Type = Defining_Identifier (N)). In this case N is not the
98 -- completion of a private type declaration. If Is_Completion is set to
99 -- True, N is the completion of a private type declaration and Derived_Type
100 -- is different from the defining identifier inside N (i.e. Derived_Type /=
101 -- Defining_Identifier (N)). Derive_Subps indicates whether the parent
102 -- subprograms should be derived. The only case where this parameter is
103 -- False is when Build_Derived_Type is recursively called to process an
104 -- implicit derived full type for a type derived from a private type (in
105 -- that case the subprograms must only be derived for the private view of
108 -- ??? These flags need a bit of re-examination and re-documentation:
109 -- ??? are they both necessary (both seem related to the recursion)?
111 procedure Build_Derived_Access_Type
113 Parent_Type : Entity_Id;
114 Derived_Type : Entity_Id);
115 -- Subsidiary procedure to Build_Derived_Type. For a derived access type,
116 -- create an implicit base if the parent type is constrained or if the
117 -- subtype indication has a constraint.
119 procedure Build_Derived_Array_Type
121 Parent_Type : Entity_Id;
122 Derived_Type : Entity_Id);
123 -- Subsidiary procedure to Build_Derived_Type. For a derived array type,
124 -- create an implicit base if the parent type is constrained or if the
125 -- subtype indication has a constraint.
127 procedure Build_Derived_Concurrent_Type
129 Parent_Type : Entity_Id;
130 Derived_Type : Entity_Id);
131 -- Subsidiary procedure to Build_Derived_Type. For a derived task or
132 -- protected type, inherit entries and protected subprograms, check
133 -- legality of discriminant constraints if any.
135 procedure Build_Derived_Enumeration_Type
137 Parent_Type : Entity_Id;
138 Derived_Type : Entity_Id);
139 -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
140 -- type, we must create a new list of literals. Types derived from
141 -- Character and Wide_Character are special-cased.
143 procedure Build_Derived_Numeric_Type
145 Parent_Type : Entity_Id;
146 Derived_Type : Entity_Id);
147 -- Subsidiary procedure to Build_Derived_Type. For numeric types, create
148 -- an anonymous base type, and propagate constraint to subtype if needed.
150 procedure Build_Derived_Private_Type
152 Parent_Type : Entity_Id;
153 Derived_Type : Entity_Id;
154 Is_Completion : Boolean;
155 Derive_Subps : Boolean := True);
156 -- Subsidiary procedure to Build_Derived_Type. This procedure is complex
157 -- because the parent may or may not have a completion, and the derivation
158 -- may itself be a completion.
160 procedure Build_Derived_Record_Type
162 Parent_Type : Entity_Id;
163 Derived_Type : Entity_Id;
164 Derive_Subps : Boolean := True);
165 -- Subsidiary procedure for Build_Derived_Type and
166 -- Analyze_Private_Extension_Declaration used for tagged and untagged
167 -- record types. All parameters are as in Build_Derived_Type except that
168 -- N, in addition to being an N_Full_Type_Declaration node, can also be an
169 -- N_Private_Extension_Declaration node. See the definition of this routine
170 -- for much more info. Derive_Subps indicates whether subprograms should
171 -- be derived from the parent type. The only case where Derive_Subps is
172 -- False is for an implicit derived full type for a type derived from a
173 -- private type (see Build_Derived_Type).
175 procedure Build_Discriminal (Discrim : Entity_Id);
176 -- Create the discriminal corresponding to discriminant Discrim, that is
177 -- the parameter corresponding to Discrim to be used in initialization
178 -- procedures for the type where Discrim is a discriminant. Discriminals
179 -- are not used during semantic analysis, and are not fully defined
180 -- entities until expansion. Thus they are not given a scope until
181 -- initialization procedures are built.
183 function Build_Discriminant_Constraints
186 Derived_Def : Boolean := False) return Elist_Id;
187 -- Validate discriminant constraints and return the list of the constraints
188 -- in order of discriminant declarations, where T is the discriminated
189 -- unconstrained type. Def is the N_Subtype_Indication node where the
190 -- discriminants constraints for T are specified. Derived_Def is True
191 -- when building the discriminant constraints in a derived type definition
192 -- of the form "type D (...) is new T (xxx)". In this case T is the parent
193 -- type and Def is the constraint "(xxx)" on T and this routine sets the
194 -- Corresponding_Discriminant field of the discriminants in the derived
195 -- type D to point to the corresponding discriminants in the parent type T.
197 procedure Build_Discriminated_Subtype
201 Related_Nod : Node_Id;
202 For_Access : Boolean := False);
203 -- Subsidiary procedure to Constrain_Discriminated_Type and to
204 -- Process_Incomplete_Dependents. Given
206 -- T (a possibly discriminated base type)
207 -- Def_Id (a very partially built subtype for T),
209 -- the call completes Def_Id to be the appropriate E_*_Subtype.
211 -- The Elist is the list of discriminant constraints if any (it is set
212 -- to No_Elist if T is not a discriminated type, and to an empty list if
213 -- T has discriminants but there are no discriminant constraints). The
214 -- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
215 -- The For_Access says whether or not this subtype is really constraining
216 -- an access type. That is its sole purpose is the designated type of an
217 -- access type -- in which case a Private_Subtype Is_For_Access_Subtype
218 -- is built to avoid freezing T when the access subtype is frozen.
220 function Build_Scalar_Bound
223 Der_T : Entity_Id) return Node_Id;
224 -- The bounds of a derived scalar type are conversions of the bounds of
225 -- the parent type. Optimize the representation if the bounds are literals.
226 -- Needs a more complete spec--what are the parameters exactly, and what
227 -- exactly is the returned value, and how is Bound affected???
229 procedure Build_Itype_Reference
232 -- Create a reference to an internal type, for use by Gigi. The back-end
233 -- elaborates itypes on demand, i.e. when their first use is seen. This
234 -- can lead to scope anomalies if the first use is within a scope that is
235 -- nested within the scope that contains the point of definition of the
236 -- itype. The Itype_Reference node forces the elaboration of the itype
237 -- in the proper scope. The node is inserted after Nod, which is the
238 -- enclosing declaration that generated Ityp.
239 -- A related mechanism is used during expansion, for itypes created in
240 -- branches of conditionals. See Ensure_Defined in exp_util.
241 -- Could both mechanisms be merged ???
243 procedure Build_Underlying_Full_View
247 -- If the completion of a private type is itself derived from a private
248 -- type, or if the full view of a private subtype is itself private, the
249 -- back-end has no way to compute the actual size of this type. We build
250 -- an internal subtype declaration of the proper parent type to convey
251 -- this information. This extra mechanism is needed because a full
252 -- view cannot itself have a full view (it would get clobbered during
255 procedure Check_Abstract_Interfaces (N : Node_Id; Def : Node_Id);
256 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
258 procedure Check_Access_Discriminant_Requires_Limited
261 -- Check the restriction that the type to which an access discriminant
262 -- belongs must be a concurrent type or a descendant of a type with
263 -- the reserved word 'limited' in its declaration.
265 procedure Check_Anonymous_Access_Components
269 Comp_List : Node_Id);
270 -- Ada 2005 AI-382: an access component in a record definition can refer to
271 -- the enclosing record, in which case it denotes the type itself, and not
272 -- the current instance of the type. We create an anonymous access type for
273 -- the component, and flag it as an access to a component, so accessibility
274 -- checks are properly performed on it. The declaration of the access type
275 -- is placed ahead of that of the record to prevent order-of-elaboration
276 -- circularity issues in Gigi. We create an incomplete type for the record
277 -- declaration, which is the designated type of the anonymous access.
279 procedure Check_Delta_Expression (E : Node_Id);
280 -- Check that the expression represented by E is suitable for use as a
281 -- delta expression, i.e. it is of real type and is static.
283 procedure Check_Digits_Expression (E : Node_Id);
284 -- Check that the expression represented by E is suitable for use as a
285 -- digits expression, i.e. it is of integer type, positive and static.
287 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id);
288 -- Validate the initialization of an object declaration. T is the required
289 -- type, and Exp is the initialization expression.
291 procedure Check_Or_Process_Discriminants
294 Prev : Entity_Id := Empty);
295 -- If T is the full declaration of an incomplete or private type, check the
296 -- conformance of the discriminants, otherwise process them. Prev is the
297 -- entity of the partial declaration, if any.
299 procedure Check_Real_Bound (Bound : Node_Id);
300 -- Check given bound for being of real type and static. If not, post an
301 -- appropriate message, and rewrite the bound with the real literal zero.
303 procedure Constant_Redeclaration
307 -- Various checks on legality of full declaration of deferred constant.
308 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
309 -- node. The caller has not yet set any attributes of this entity.
311 function Contain_Interface
313 Ifaces : Elist_Id) return Boolean;
314 -- Ada 2005: Determine whether Iface is present in the list Ifaces
316 procedure Convert_Scalar_Bounds
318 Parent_Type : Entity_Id;
319 Derived_Type : Entity_Id;
321 -- For derived scalar types, convert the bounds in the type definition to
322 -- the derived type, and complete their analysis. Given a constraint of the
323 -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with
324 -- T'Base, the parent_type. The bounds of the derived type (the anonymous
325 -- base) are copies of Lo and Hi. Finally, the bounds of the derived
326 -- subtype are conversions of those bounds to the derived_type, so that
327 -- their typing is consistent.
329 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id);
330 -- Copies attributes from array base type T2 to array base type T1. Copies
331 -- only attributes that apply to base types, but not subtypes.
333 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id);
334 -- Copies attributes from array subtype T2 to array subtype T1. Copies
335 -- attributes that apply to both subtypes and base types.
337 procedure Create_Constrained_Components
341 Constraints : Elist_Id);
342 -- Build the list of entities for a constrained discriminated record
343 -- subtype. If a component depends on a discriminant, replace its subtype
344 -- using the discriminant values in the discriminant constraint. Subt is
345 -- the defining identifier for the subtype whose list of constrained
346 -- entities we will create. Decl_Node is the type declaration node where we
347 -- will attach all the itypes created. Typ is the base discriminated type
348 -- for the subtype Subt. Constraints is the list of discriminant
349 -- constraints for Typ.
351 function Constrain_Component_Type
353 Constrained_Typ : Entity_Id;
354 Related_Node : Node_Id;
356 Constraints : Elist_Id) return Entity_Id;
357 -- Given a discriminated base type Typ, a list of discriminant constraint
358 -- Constraints for Typ and a component of Typ, with type Compon_Type,
359 -- create and return the type corresponding to Compon_type where all
360 -- discriminant references are replaced with the corresponding constraint.
361 -- If no discriminant references occur in Compon_Typ then return it as is.
362 -- Constrained_Typ is the final constrained subtype to which the
363 -- constrained Compon_Type belongs. Related_Node is the node where we will
364 -- attach all the itypes created.
365 -- Above description is confused, what is Compon_Type???
367 procedure Constrain_Access
368 (Def_Id : in out Entity_Id;
370 Related_Nod : Node_Id);
371 -- Apply a list of constraints to an access type. If Def_Id is empty, it is
372 -- an anonymous type created for a subtype indication. In that case it is
373 -- created in the procedure and attached to Related_Nod.
375 procedure Constrain_Array
376 (Def_Id : in out Entity_Id;
378 Related_Nod : Node_Id;
379 Related_Id : Entity_Id;
381 -- Apply a list of index constraints to an unconstrained array type. The
382 -- first parameter is the entity for the resulting subtype. A value of
383 -- Empty for Def_Id indicates that an implicit type must be created, but
384 -- creation is delayed (and must be done by this procedure) because other
385 -- subsidiary implicit types must be created first (which is why Def_Id
386 -- is an in/out parameter). The second parameter is a subtype indication
387 -- node for the constrained array to be created (e.g. something of the
388 -- form string (1 .. 10)). Related_Nod gives the place where this type
389 -- has to be inserted in the tree. The Related_Id and Suffix parameters
390 -- are used to build the associated Implicit type name.
392 procedure Constrain_Concurrent
393 (Def_Id : in out Entity_Id;
395 Related_Nod : Node_Id;
396 Related_Id : Entity_Id;
398 -- Apply list of discriminant constraints to an unconstrained concurrent
401 -- SI is the N_Subtype_Indication node containing the constraint and
402 -- the unconstrained type to constrain.
404 -- Def_Id is the entity for the resulting constrained subtype. A value
405 -- of Empty for Def_Id indicates that an implicit type must be created,
406 -- but creation is delayed (and must be done by this procedure) because
407 -- other subsidiary implicit types must be created first (which is why
408 -- Def_Id is an in/out parameter).
410 -- Related_Nod gives the place where this type has to be inserted
413 -- The last two arguments are used to create its external name if needed.
415 function Constrain_Corresponding_Record
416 (Prot_Subt : Entity_Id;
417 Corr_Rec : Entity_Id;
418 Related_Nod : Node_Id;
419 Related_Id : Entity_Id) return Entity_Id;
420 -- When constraining a protected type or task type with discriminants,
421 -- constrain the corresponding record with the same discriminant values.
423 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id);
424 -- Constrain a decimal fixed point type with a digits constraint and/or a
425 -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
427 procedure Constrain_Discriminated_Type
430 Related_Nod : Node_Id;
431 For_Access : Boolean := False);
432 -- Process discriminant constraints of composite type. Verify that values
433 -- have been provided for all discriminants, that the original type is
434 -- unconstrained, and that the types of the supplied expressions match
435 -- the discriminant types. The first three parameters are like in routine
436 -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
439 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id);
440 -- Constrain an enumeration type with a range constraint. This is identical
441 -- to Constrain_Integer, but for the Ekind of the resulting subtype.
443 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id);
444 -- Constrain a floating point type with either a digits constraint
445 -- and/or a range constraint, building a E_Floating_Point_Subtype.
447 procedure Constrain_Index
450 Related_Nod : Node_Id;
451 Related_Id : Entity_Id;
454 -- Process an index constraint in a constrained array declaration. The
455 -- constraint can be a subtype name, or a range with or without an explicit
456 -- subtype mark. The index is the corresponding index of the unconstrained
457 -- array. The Related_Id and Suffix parameters are used to build the
458 -- associated Implicit type name.
460 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id);
461 -- Build subtype of a signed or modular integer type
463 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id);
464 -- Constrain an ordinary fixed point type with a range constraint, and
465 -- build an E_Ordinary_Fixed_Point_Subtype entity.
467 procedure Copy_And_Swap (Priv, Full : Entity_Id);
468 -- Copy the Priv entity into the entity of its full declaration then swap
469 -- the two entities in such a manner that the former private type is now
470 -- seen as a full type.
472 procedure Decimal_Fixed_Point_Type_Declaration
475 -- Create a new decimal fixed point type, and apply the constraint to
476 -- obtain a subtype of this new type.
478 procedure Complete_Private_Subtype
481 Full_Base : Entity_Id;
482 Related_Nod : Node_Id);
483 -- Complete the implicit full view of a private subtype by setting the
484 -- appropriate semantic fields. If the full view of the parent is a record
485 -- type, build constrained components of subtype.
487 procedure Derive_Interface_Subprograms
488 (Parent_Type : Entity_Id;
489 Tagged_Type : Entity_Id;
490 Ifaces_List : Elist_Id);
491 -- Ada 2005 (AI-251): Derive primitives of abstract interface types that
492 -- are not immediate ancestors of Tagged type and associate them their
493 -- aliased primitive. Ifaces_List contains the abstract interface
494 -- primitives that have been derived from Parent_Type.
496 procedure Derived_Standard_Character
498 Parent_Type : Entity_Id;
499 Derived_Type : Entity_Id);
500 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
501 -- derivations from types Standard.Character and Standard.Wide_Character.
503 procedure Derived_Type_Declaration
506 Is_Completion : Boolean);
507 -- Process a derived type declaration. This routine will invoke
508 -- Build_Derived_Type to process the actual derived type definition.
509 -- Parameters N and Is_Completion have the same meaning as in
510 -- Build_Derived_Type. T is the N_Defining_Identifier for the entity
511 -- defined in the N_Full_Type_Declaration node N, that is T is the derived
514 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id);
515 -- Insert each literal in symbol table, as an overloadable identifier. Each
516 -- enumeration type is mapped into a sequence of integers, and each literal
517 -- is defined as a constant with integer value. If any of the literals are
518 -- character literals, the type is a character type, which means that
519 -- strings are legal aggregates for arrays of components of the type.
521 function Expand_To_Stored_Constraint
523 Constraint : Elist_Id) return Elist_Id;
524 -- Given a Constraint (i.e. a list of expressions) on the discriminants of
525 -- Typ, expand it into a constraint on the stored discriminants and return
526 -- the new list of expressions constraining the stored discriminants.
528 function Find_Type_Of_Object
530 Related_Nod : Node_Id) return Entity_Id;
531 -- Get type entity for object referenced by Obj_Def, attaching the
532 -- implicit types generated to Related_Nod
534 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id);
535 -- Create a new float, and apply the constraint to obtain subtype of it
537 function Has_Range_Constraint (N : Node_Id) return Boolean;
538 -- Given an N_Subtype_Indication node N, return True if a range constraint
539 -- is present, either directly, or as part of a digits or delta constraint.
540 -- In addition, a digits constraint in the decimal case returns True, since
541 -- it establishes a default range if no explicit range is present.
543 function Inherit_Components
545 Parent_Base : Entity_Id;
546 Derived_Base : Entity_Id;
548 Inherit_Discr : Boolean;
549 Discs : Elist_Id) return Elist_Id;
550 -- Called from Build_Derived_Record_Type to inherit the components of
551 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
552 -- For more information on derived types and component inheritance please
553 -- consult the comment above the body of Build_Derived_Record_Type.
555 -- N is the original derived type declaration
557 -- Is_Tagged is set if we are dealing with tagged types
559 -- If Inherit_Discr is set, Derived_Base inherits its discriminants from
560 -- Parent_Base, otherwise no discriminants are inherited.
562 -- Discs gives the list of constraints that apply to Parent_Base in the
563 -- derived type declaration. If Discs is set to No_Elist, then we have
564 -- the following situation:
566 -- type Parent (D1..Dn : ..) is [tagged] record ...;
567 -- type Derived is new Parent [with ...];
569 -- which gets treated as
571 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
573 -- For untagged types the returned value is an association list. The list
574 -- starts from the association (Parent_Base => Derived_Base), and then it
575 -- contains a sequence of the associations of the form
577 -- (Old_Component => New_Component),
579 -- where Old_Component is the Entity_Id of a component in Parent_Base and
580 -- New_Component is the Entity_Id of the corresponding component in
581 -- Derived_Base. For untagged records, this association list is needed when
582 -- copying the record declaration for the derived base. In the tagged case
583 -- the value returned is irrelevant.
585 function Is_Valid_Constraint_Kind
587 Constraint_Kind : Node_Kind) return Boolean;
588 -- Returns True if it is legal to apply the given kind of constraint to the
589 -- given kind of type (index constraint to an array type, for example).
591 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id);
592 -- Create new modular type. Verify that modulus is in bounds and is
593 -- a power of two (implementation restriction).
595 procedure New_Concatenation_Op (Typ : Entity_Id);
596 -- Create an abbreviated declaration for an operator in order to
597 -- materialize concatenation on array types.
599 procedure Ordinary_Fixed_Point_Type_Declaration
602 -- Create a new ordinary fixed point type, and apply the constraint to
603 -- obtain subtype of it.
605 procedure Prepare_Private_Subtype_Completion
607 Related_Nod : Node_Id);
608 -- Id is a subtype of some private type. Creates the full declaration
609 -- associated with Id whenever possible, i.e. when the full declaration
610 -- of the base type is already known. Records each subtype into
611 -- Private_Dependents of the base type.
613 procedure Process_Incomplete_Dependents
617 -- Process all entities that depend on an incomplete type. There include
618 -- subtypes, subprogram types that mention the incomplete type in their
619 -- profiles, and subprogram with access parameters that designate the
622 -- Inc_T is the defining identifier of an incomplete type declaration, its
623 -- Ekind is E_Incomplete_Type.
625 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
627 -- Full_T is N's defining identifier.
629 -- Subtypes of incomplete types with discriminants are completed when the
630 -- parent type is. This is simpler than private subtypes, because they can
631 -- only appear in the same scope, and there is no need to exchange views.
632 -- Similarly, access_to_subprogram types may have a parameter or a return
633 -- type that is an incomplete type, and that must be replaced with the
636 -- If the full type is tagged, subprogram with access parameters that
637 -- designated the incomplete may be primitive operations of the full type,
638 -- and have to be processed accordingly.
640 procedure Process_Real_Range_Specification (Def : Node_Id);
641 -- Given the type definition for a real type, this procedure processes
642 -- and checks the real range specification of this type definition if
643 -- one is present. If errors are found, error messages are posted, and
644 -- the Real_Range_Specification of Def is reset to Empty.
646 procedure Record_Type_Declaration
650 -- Process a record type declaration (for both untagged and tagged
651 -- records). Parameters T and N are exactly like in procedure
652 -- Derived_Type_Declaration, except that no flag Is_Completion is needed
653 -- for this routine. If this is the completion of an incomplete type
654 -- declaration, Prev is the entity of the incomplete declaration, used for
655 -- cross-referencing. Otherwise Prev = T.
657 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id);
658 -- This routine is used to process the actual record type definition
659 -- (both for untagged and tagged records). Def is a record type
660 -- definition node. This procedure analyzes the components in this
661 -- record type definition. Prev_T is the entity for the enclosing record
662 -- type. It is provided so that its Has_Task flag can be set if any of
663 -- the component have Has_Task set. If the declaration is the completion
664 -- of an incomplete type declaration, Prev_T is the original incomplete
665 -- type, whose full view is the record type.
667 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id);
668 -- Subsidiary to Build_Derived_Record_Type. For untagged records, we
669 -- build a copy of the declaration tree of the parent, and we create
670 -- independently the list of components for the derived type. Semantic
671 -- information uses the component entities, but record representation
672 -- clauses are validated on the declaration tree. This procedure replaces
673 -- discriminants and components in the declaration with those that have
674 -- been created by Inherit_Components.
676 procedure Set_Fixed_Range
681 -- Build a range node with the given bounds and set it as the Scalar_Range
682 -- of the given fixed-point type entity. Loc is the source location used
683 -- for the constructed range. See body for further details.
685 procedure Set_Scalar_Range_For_Subtype
689 -- This routine is used to set the scalar range field for a subtype given
690 -- Def_Id, the entity for the subtype, and R, the range expression for the
691 -- scalar range. Subt provides the parent subtype to be used to analyze,
692 -- resolve, and check the given range.
694 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id);
695 -- Create a new signed integer entity, and apply the constraint to obtain
696 -- the required first named subtype of this type.
698 procedure Set_Stored_Constraint_From_Discriminant_Constraint
700 -- E is some record type. This routine computes E's Stored_Constraint
701 -- from its Discriminant_Constraint.
703 -----------------------
704 -- Access_Definition --
705 -----------------------
707 function Access_Definition
708 (Related_Nod : Node_Id;
709 N : Node_Id) return Entity_Id
711 Loc : constant Source_Ptr := Sloc (Related_Nod);
712 Anon_Type : Entity_Id;
713 Anon_Scope : Entity_Id;
714 Desig_Type : Entity_Id;
718 if Is_Entry (Current_Scope)
719 and then Is_Task_Type (Etype (Scope (Current_Scope)))
721 Error_Msg_N ("task entries cannot have access parameters", N);
725 -- Ada 2005: for an object declaration the corresponding anonymous
726 -- type is declared in the current scope.
728 -- If the access definition is the return type of another access to
729 -- function, scope is the current one, because it is the one of the
730 -- current type declaration.
732 if Nkind (Related_Nod) = N_Object_Declaration
733 or else Nkind (Related_Nod) = N_Access_Function_Definition
735 Anon_Scope := Current_Scope;
737 -- For the anonymous function result case, retrieve the scope of the
738 -- function specification's associated entity rather than using the
739 -- current scope. The current scope will be the function itself if the
740 -- formal part is currently being analyzed, but will be the parent scope
741 -- in the case of a parameterless function, and we always want to use
742 -- the function's parent scope. Finally, if the function is a child
743 -- unit, we must traverse the the tree to retrieve the proper entity.
745 elsif Nkind (Related_Nod) = N_Function_Specification
746 and then Nkind (Parent (N)) /= N_Parameter_Specification
748 -- If the current scope is a protected type, the anonymous access
749 -- is associated with one of the protected operations, and must
750 -- be available in the scope that encloses the protected declaration.
751 -- Otherwise the type is is in the scope enclosing the subprogram.
753 if Ekind (Current_Scope) = E_Protected_Type then
754 Anon_Scope := Scope (Scope (Defining_Entity (Related_Nod)));
756 Anon_Scope := Scope (Defining_Entity (Related_Nod));
760 -- For access formals, access components, and access discriminants,
761 -- the scope is that of the enclosing declaration,
763 Anon_Scope := Scope (Current_Scope);
768 (E_Anonymous_Access_Type, Related_Nod, Scope_Id => Anon_Scope);
771 and then Ada_Version >= Ada_05
773 Error_Msg_N ("ALL is not permitted for anonymous access types", N);
776 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
777 -- the corresponding semantic routine
779 if Present (Access_To_Subprogram_Definition (N)) then
780 Access_Subprogram_Declaration
781 (T_Name => Anon_Type,
782 T_Def => Access_To_Subprogram_Definition (N));
784 if Ekind (Anon_Type) = E_Access_Protected_Subprogram_Type then
786 (Anon_Type, E_Anonymous_Access_Protected_Subprogram_Type);
789 (Anon_Type, E_Anonymous_Access_Subprogram_Type);
792 -- If the anonymous access is associated with a protected operation
793 -- create a reference to it after the enclosing protected definition
794 -- because the itype will be used in the subsequent bodies.
796 if Ekind (Current_Scope) = E_Protected_Type then
797 Build_Itype_Reference (Anon_Type, Parent (Current_Scope));
803 Find_Type (Subtype_Mark (N));
804 Desig_Type := Entity (Subtype_Mark (N));
806 Set_Directly_Designated_Type
807 (Anon_Type, Desig_Type);
808 Set_Etype (Anon_Type, Anon_Type);
809 Init_Size_Align (Anon_Type);
810 Set_Depends_On_Private (Anon_Type, Has_Private_Component (Anon_Type));
812 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
813 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
814 -- the null value is allowed. In Ada 95 the null value is never allowed.
816 if Ada_Version >= Ada_05 then
817 Set_Can_Never_Be_Null (Anon_Type, Null_Exclusion_Present (N));
819 Set_Can_Never_Be_Null (Anon_Type, True);
822 -- The anonymous access type is as public as the discriminated type or
823 -- subprogram that defines it. It is imported (for back-end purposes)
824 -- if the designated type is.
826 Set_Is_Public (Anon_Type, Is_Public (Scope (Anon_Type)));
828 -- Ada 2005 (AI-50217): Propagate the attribute that indicates that the
829 -- designated type comes from the limited view.
831 Set_From_With_Type (Anon_Type, From_With_Type (Desig_Type));
833 -- Ada 2005 (AI-231): Propagate the access-constant attribute
835 Set_Is_Access_Constant (Anon_Type, Constant_Present (N));
837 -- The context is either a subprogram declaration, object declaration,
838 -- or an access discriminant, in a private or a full type declaration.
839 -- In the case of a subprogram, if the designated type is incomplete,
840 -- the operation will be a primitive operation of the full type, to be
841 -- updated subsequently. If the type is imported through a limited_with
842 -- clause, the subprogram is not a primitive operation of the type
843 -- (which is declared elsewhere in some other scope).
845 if Ekind (Desig_Type) = E_Incomplete_Type
846 and then not From_With_Type (Desig_Type)
847 and then Is_Overloadable (Current_Scope)
849 Append_Elmt (Current_Scope, Private_Dependents (Desig_Type));
850 Set_Has_Delayed_Freeze (Current_Scope);
853 -- Ada 2005: if the designated type is an interface that may contain
854 -- tasks, create a Master entity for the declaration. This must be done
855 -- before expansion of the full declaration, because the declaration may
856 -- include an expression that is an allocator, whose expansion needs the
857 -- proper Master for the created tasks.
859 if Nkind (Related_Nod) = N_Object_Declaration
860 and then Expander_Active
862 if Is_Interface (Desig_Type)
863 and then Is_Limited_Record (Desig_Type)
865 Build_Class_Wide_Master (Anon_Type);
867 -- Similarly, if the type is an anonymous access that designates
868 -- tasks, create a master entity for it in the current context.
870 elsif Has_Task (Desig_Type)
871 and then Comes_From_Source (Related_Nod)
873 if not Has_Master_Entity (Current_Scope) then
875 Make_Object_Declaration (Loc,
876 Defining_Identifier =>
877 Make_Defining_Identifier (Loc, Name_uMaster),
878 Constant_Present => True,
880 New_Reference_To (RTE (RE_Master_Id), Loc),
882 Make_Explicit_Dereference (Loc,
883 New_Reference_To (RTE (RE_Current_Master), Loc)));
885 Insert_Before (Related_Nod, Decl);
888 Set_Master_Id (Anon_Type, Defining_Identifier (Decl));
889 Set_Has_Master_Entity (Current_Scope);
891 Build_Master_Renaming (Related_Nod, Anon_Type);
896 -- For a private component of a protected type, it is imperative that
897 -- the back-end elaborate the type immediately after the protected
898 -- declaration, because this type will be used in the declarations
899 -- created for the component within each protected body, so we must
900 -- create an itype reference for it now.
902 if Nkind (Parent (Related_Nod)) = N_Protected_Definition then
903 Build_Itype_Reference (Anon_Type, Parent (Parent (Related_Nod)));
907 end Access_Definition;
909 -----------------------------------
910 -- Access_Subprogram_Declaration --
911 -----------------------------------
913 procedure Access_Subprogram_Declaration
917 Formals : constant List_Id := Parameter_Specifications (T_Def);
921 Desig_Type : constant Entity_Id :=
922 Create_Itype (E_Subprogram_Type, Parent (T_Def));
925 -- Associate the Itype node with the inner full-type declaration or
926 -- subprogram spec. This is required to handle nested anonymous
927 -- declarations. For example:
930 -- (X : access procedure
931 -- (Y : access procedure
934 D_Ityp := Associated_Node_For_Itype (Desig_Type);
935 while Nkind (D_Ityp) /= N_Full_Type_Declaration
936 and then Nkind (D_Ityp) /= N_Private_Type_Declaration
937 and then Nkind (D_Ityp) /= N_Private_Extension_Declaration
938 and then Nkind (D_Ityp) /= N_Procedure_Specification
939 and then Nkind (D_Ityp) /= N_Function_Specification
940 and then Nkind (D_Ityp) /= N_Object_Declaration
941 and then Nkind (D_Ityp) /= N_Object_Renaming_Declaration
942 and then Nkind (D_Ityp) /= N_Formal_Type_Declaration
943 and then Nkind (D_Ityp) /= N_Task_Type_Declaration
944 and then Nkind (D_Ityp) /= N_Protected_Type_Declaration
946 D_Ityp := Parent (D_Ityp);
947 pragma Assert (D_Ityp /= Empty);
950 Set_Associated_Node_For_Itype (Desig_Type, D_Ityp);
952 if Nkind (D_Ityp) = N_Procedure_Specification
953 or else Nkind (D_Ityp) = N_Function_Specification
955 Set_Scope (Desig_Type, Scope (Defining_Entity (D_Ityp)));
957 elsif Nkind (D_Ityp) = N_Full_Type_Declaration
958 or else Nkind (D_Ityp) = N_Object_Declaration
959 or else Nkind (D_Ityp) = N_Object_Renaming_Declaration
960 or else Nkind (D_Ityp) = N_Formal_Type_Declaration
962 Set_Scope (Desig_Type, Scope (Defining_Identifier (D_Ityp)));
965 if Nkind (T_Def) = N_Access_Function_Definition then
966 if Nkind (Result_Definition (T_Def)) = N_Access_Definition then
969 Acc : constant Node_Id := Result_Definition (T_Def);
972 if Present (Access_To_Subprogram_Definition (Acc))
974 Protected_Present (Access_To_Subprogram_Definition (Acc))
978 Replace_Anonymous_Access_To_Protected_Subprogram
984 Access_Definition (T_Def, Result_Definition (T_Def)));
989 Analyze (Result_Definition (T_Def));
990 Set_Etype (Desig_Type, Entity (Result_Definition (T_Def)));
993 if not (Is_Type (Etype (Desig_Type))) then
995 ("expect type in function specification",
996 Result_Definition (T_Def));
1000 Set_Etype (Desig_Type, Standard_Void_Type);
1003 if Present (Formals) then
1004 Push_Scope (Desig_Type);
1005 Process_Formals (Formals, Parent (T_Def));
1007 -- A bit of a kludge here, End_Scope requires that the parent
1008 -- pointer be set to something reasonable, but Itypes don't have
1009 -- parent pointers. So we set it and then unset it ??? If and when
1010 -- Itypes have proper parent pointers to their declarations, this
1011 -- kludge can be removed.
1013 Set_Parent (Desig_Type, T_Name);
1015 Set_Parent (Desig_Type, Empty);
1018 -- The return type and/or any parameter type may be incomplete. Mark
1019 -- the subprogram_type as depending on the incomplete type, so that
1020 -- it can be updated when the full type declaration is seen. This
1021 -- only applies to incomplete types declared in some enclosing scope,
1022 -- not to limited views from other packages.
1024 if Present (Formals) then
1025 Formal := First_Formal (Desig_Type);
1026 while Present (Formal) loop
1027 if Ekind (Formal) /= E_In_Parameter
1028 and then Nkind (T_Def) = N_Access_Function_Definition
1030 Error_Msg_N ("functions can only have IN parameters", Formal);
1033 if Ekind (Etype (Formal)) = E_Incomplete_Type
1034 and then In_Open_Scopes (Scope (Etype (Formal)))
1036 Append_Elmt (Desig_Type, Private_Dependents (Etype (Formal)));
1037 Set_Has_Delayed_Freeze (Desig_Type);
1040 Next_Formal (Formal);
1044 if Ekind (Etype (Desig_Type)) = E_Incomplete_Type
1045 and then not Has_Delayed_Freeze (Desig_Type)
1047 Append_Elmt (Desig_Type, Private_Dependents (Etype (Desig_Type)));
1048 Set_Has_Delayed_Freeze (Desig_Type);
1051 Check_Delayed_Subprogram (Desig_Type);
1053 if Protected_Present (T_Def) then
1054 Set_Ekind (T_Name, E_Access_Protected_Subprogram_Type);
1055 Set_Convention (Desig_Type, Convention_Protected);
1057 Set_Ekind (T_Name, E_Access_Subprogram_Type);
1060 Set_Etype (T_Name, T_Name);
1061 Init_Size_Align (T_Name);
1062 Set_Directly_Designated_Type (T_Name, Desig_Type);
1064 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1066 Set_Can_Never_Be_Null (T_Name, Null_Exclusion_Present (T_Def));
1068 Check_Restriction (No_Access_Subprograms, T_Def);
1069 end Access_Subprogram_Declaration;
1071 ----------------------------
1072 -- Access_Type_Declaration --
1073 ----------------------------
1075 procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id) is
1076 S : constant Node_Id := Subtype_Indication (Def);
1077 P : constant Node_Id := Parent (Def);
1083 -- Check for permissible use of incomplete type
1085 if Nkind (S) /= N_Subtype_Indication then
1088 if Ekind (Root_Type (Entity (S))) = E_Incomplete_Type then
1089 Set_Directly_Designated_Type (T, Entity (S));
1091 Set_Directly_Designated_Type (T,
1092 Process_Subtype (S, P, T, 'P'));
1096 Set_Directly_Designated_Type (T,
1097 Process_Subtype (S, P, T, 'P'));
1100 if All_Present (Def) or Constant_Present (Def) then
1101 Set_Ekind (T, E_General_Access_Type);
1103 Set_Ekind (T, E_Access_Type);
1106 if Base_Type (Designated_Type (T)) = T then
1107 Error_Msg_N ("access type cannot designate itself", S);
1109 -- In Ada 2005, the type may have a limited view through some unit
1110 -- in its own context, allowing the following circularity that cannot
1111 -- be detected earlier
1113 elsif Is_Class_Wide_Type (Designated_Type (T))
1114 and then Etype (Designated_Type (T)) = T
1117 ("access type cannot designate its own classwide type", S);
1119 -- Clean up indication of tagged status to prevent cascaded errors
1121 Set_Is_Tagged_Type (T, False);
1126 -- If the type has appeared already in a with_type clause, it is
1127 -- frozen and the pointer size is already set. Else, initialize.
1129 if not From_With_Type (T) then
1130 Init_Size_Align (T);
1133 Desig := Designated_Type (T);
1135 -- If designated type is an imported tagged type, indicate that the
1136 -- access type is also imported, and therefore restricted in its use.
1137 -- The access type may already be imported, so keep setting otherwise.
1139 -- Ada 2005 (AI-50217): If the non-limited view of the designated type
1140 -- is available, use it as the designated type of the access type, so
1141 -- that the back-end gets a usable entity.
1143 if From_With_Type (Desig)
1144 and then Ekind (Desig) /= E_Access_Type
1146 Set_From_With_Type (T);
1149 -- Note that Has_Task is always false, since the access type itself
1150 -- is not a task type. See Einfo for more description on this point.
1151 -- Exactly the same consideration applies to Has_Controlled_Component.
1153 Set_Has_Task (T, False);
1154 Set_Has_Controlled_Component (T, False);
1156 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1159 Set_Can_Never_Be_Null (T, Null_Exclusion_Present (Def));
1160 Set_Is_Access_Constant (T, Constant_Present (Def));
1161 end Access_Type_Declaration;
1163 ----------------------------------
1164 -- Add_Interface_Tag_Components --
1165 ----------------------------------
1167 procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id) is
1168 Loc : constant Source_Ptr := Sloc (N);
1175 procedure Add_Sync_Iface_Tags (T : Entity_Id);
1176 -- Local subprogram used to recursively climb through the parents
1177 -- of T to add the tags of all the progenitor interfaces.
1179 procedure Add_Tag (Iface : Entity_Id);
1180 -- Add tag for one of the progenitor interfaces
1182 -------------------------
1183 -- Add_Sync_Iface_Tags --
1184 -------------------------
1186 procedure Add_Sync_Iface_Tags (T : Entity_Id) is
1188 if Etype (T) /= T then
1189 Add_Sync_Iface_Tags (Etype (T));
1192 Elmt := First_Elmt (Abstract_Interfaces (T));
1193 while Present (Elmt) loop
1194 Add_Tag (Node (Elmt));
1197 end Add_Sync_Iface_Tags;
1203 procedure Add_Tag (Iface : Entity_Id) is
1210 pragma Assert (Is_Tagged_Type (Iface)
1211 and then Is_Interface (Iface));
1214 Make_Component_Definition (Loc,
1215 Aliased_Present => True,
1216 Subtype_Indication =>
1217 New_Occurrence_Of (RTE (RE_Interface_Tag), Loc));
1219 Tag := Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1222 Make_Component_Declaration (Loc,
1223 Defining_Identifier => Tag,
1224 Component_Definition => Def);
1226 Analyze_Component_Declaration (Decl);
1228 Set_Analyzed (Decl);
1229 Set_Ekind (Tag, E_Component);
1231 Set_Is_Aliased (Tag);
1232 Set_Related_Interface (Tag, Iface);
1233 Init_Component_Location (Tag);
1235 pragma Assert (Is_Frozen (Iface));
1237 Set_DT_Entry_Count (Tag,
1238 DT_Entry_Count (First_Entity (Iface)));
1240 if No (Last_Tag) then
1243 Insert_After (Last_Tag, Decl);
1248 -- If the ancestor has discriminants we need to give special support
1249 -- to store the offset_to_top value of the secondary dispatch tables.
1250 -- For this purpose we add a supplementary component just after the
1251 -- field that contains the tag associated with each secondary DT.
1253 if Typ /= Etype (Typ)
1254 and then Has_Discriminants (Etype (Typ))
1257 Make_Component_Definition (Loc,
1258 Subtype_Indication =>
1259 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc));
1262 Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1265 Make_Component_Declaration (Loc,
1266 Defining_Identifier => Offset,
1267 Component_Definition => Def);
1269 Analyze_Component_Declaration (Decl);
1271 Set_Analyzed (Decl);
1272 Set_Ekind (Offset, E_Component);
1273 Set_Is_Aliased (Offset);
1274 Set_Related_Interface (Offset, Iface);
1275 Init_Component_Location (Offset);
1276 Insert_After (Last_Tag, Decl);
1283 Iface_List : List_Id;
1285 -- Start of processing for Add_Interface_Tag_Components
1288 if not RTE_Available (RE_Interface_Tag) then
1290 ("(Ada 2005) interface types not supported by this run-time!",
1295 if Ekind (Typ) /= E_Record_Type
1296 or else (Is_Concurrent_Record_Type (Typ)
1297 and then Is_Empty_List (Abstract_Interface_List (Typ)))
1298 or else (not Is_Concurrent_Record_Type (Typ)
1299 and then No (Abstract_Interfaces (Typ))
1300 and then Is_Empty_Elmt_List (Abstract_Interfaces (Typ)))
1305 -- Find the current last tag
1307 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1308 Ext := Record_Extension_Part (Type_Definition (N));
1310 pragma Assert (Nkind (Type_Definition (N)) = N_Record_Definition);
1311 Ext := Type_Definition (N);
1316 if not (Present (Component_List (Ext))) then
1317 Set_Null_Present (Ext, False);
1319 Set_Component_List (Ext,
1320 Make_Component_List (Loc,
1321 Component_Items => L,
1322 Null_Present => False));
1324 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1325 L := Component_Items
1327 (Record_Extension_Part
1328 (Type_Definition (N))));
1330 L := Component_Items
1332 (Type_Definition (N)));
1335 -- Find the last tag component
1338 while Present (Comp) loop
1339 if Nkind (Comp) = N_Component_Declaration
1340 and then Is_Tag (Defining_Identifier (Comp))
1349 -- At this point L references the list of components and Last_Tag
1350 -- references the current last tag (if any). Now we add the tag
1351 -- corresponding with all the interfaces that are not implemented
1354 if Is_Concurrent_Record_Type (Typ) then
1355 Iface_List := Abstract_Interface_List (Typ);
1357 if Is_Non_Empty_List (Iface_List) then
1358 Add_Sync_Iface_Tags (Etype (First (Iface_List)));
1362 if Present (Abstract_Interfaces (Typ)) then
1363 Elmt := First_Elmt (Abstract_Interfaces (Typ));
1364 while Present (Elmt) loop
1365 Add_Tag (Node (Elmt));
1369 end Add_Interface_Tag_Components;
1371 -----------------------------------
1372 -- Analyze_Component_Declaration --
1373 -----------------------------------
1375 procedure Analyze_Component_Declaration (N : Node_Id) is
1376 Id : constant Entity_Id := Defining_Identifier (N);
1377 E : constant Node_Id := Expression (N);
1381 function Contains_POC (Constr : Node_Id) return Boolean;
1382 -- Determines whether a constraint uses the discriminant of a record
1383 -- type thus becoming a per-object constraint (POC).
1385 function Is_Known_Limited (Typ : Entity_Id) return Boolean;
1386 -- Typ is the type of the current component, check whether this type is
1387 -- a limited type. Used to validate declaration against that of
1388 -- enclosing record.
1394 function Contains_POC (Constr : Node_Id) return Boolean is
1396 -- Prevent cascaded errors
1398 if Error_Posted (Constr) then
1402 case Nkind (Constr) is
1403 when N_Attribute_Reference =>
1405 Attribute_Name (Constr) = Name_Access
1406 and then Prefix (Constr) = Scope (Entity (Prefix (Constr)));
1408 when N_Discriminant_Association =>
1409 return Denotes_Discriminant (Expression (Constr));
1411 when N_Identifier =>
1412 return Denotes_Discriminant (Constr);
1414 when N_Index_Or_Discriminant_Constraint =>
1419 IDC := First (Constraints (Constr));
1420 while Present (IDC) loop
1422 -- One per-object constraint is sufficient
1424 if Contains_POC (IDC) then
1435 return Denotes_Discriminant (Low_Bound (Constr))
1437 Denotes_Discriminant (High_Bound (Constr));
1439 when N_Range_Constraint =>
1440 return Denotes_Discriminant (Range_Expression (Constr));
1448 ----------------------
1449 -- Is_Known_Limited --
1450 ----------------------
1452 function Is_Known_Limited (Typ : Entity_Id) return Boolean is
1453 P : constant Entity_Id := Etype (Typ);
1454 R : constant Entity_Id := Root_Type (Typ);
1457 if Is_Limited_Record (Typ) then
1460 -- If the root type is limited (and not a limited interface)
1461 -- so is the current type
1463 elsif Is_Limited_Record (R)
1465 (not Is_Interface (R)
1466 or else not Is_Limited_Interface (R))
1470 -- Else the type may have a limited interface progenitor, but a
1471 -- limited record parent.
1474 and then Is_Limited_Record (P)
1481 end Is_Known_Limited;
1483 -- Start of processing for Analyze_Component_Declaration
1486 Generate_Definition (Id);
1489 if Present (Subtype_Indication (Component_Definition (N))) then
1490 T := Find_Type_Of_Object
1491 (Subtype_Indication (Component_Definition (N)), N);
1493 -- Ada 2005 (AI-230): Access Definition case
1496 pragma Assert (Present
1497 (Access_Definition (Component_Definition (N))));
1499 T := Access_Definition
1501 N => Access_Definition (Component_Definition (N)));
1502 Set_Is_Local_Anonymous_Access (T);
1504 -- Ada 2005 (AI-254)
1506 if Present (Access_To_Subprogram_Definition
1507 (Access_Definition (Component_Definition (N))))
1508 and then Protected_Present (Access_To_Subprogram_Definition
1510 (Component_Definition (N))))
1512 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
1516 -- If the subtype is a constrained subtype of the enclosing record,
1517 -- (which must have a partial view) the back-end does not properly
1518 -- handle the recursion. Rewrite the component declaration with an
1519 -- explicit subtype indication, which is acceptable to Gigi. We can copy
1520 -- the tree directly because side effects have already been removed from
1521 -- discriminant constraints.
1523 if Ekind (T) = E_Access_Subtype
1524 and then Is_Entity_Name (Subtype_Indication (Component_Definition (N)))
1525 and then Comes_From_Source (T)
1526 and then Nkind (Parent (T)) = N_Subtype_Declaration
1527 and then Etype (Directly_Designated_Type (T)) = Current_Scope
1530 (Subtype_Indication (Component_Definition (N)),
1531 New_Copy_Tree (Subtype_Indication (Parent (T))));
1532 T := Find_Type_Of_Object
1533 (Subtype_Indication (Component_Definition (N)), N);
1536 -- If the component declaration includes a default expression, then we
1537 -- check that the component is not of a limited type (RM 3.7(5)),
1538 -- and do the special preanalysis of the expression (see section on
1539 -- "Handling of Default and Per-Object Expressions" in the spec of
1543 Analyze_Per_Use_Expression (E, T);
1544 Check_Initialization (T, E);
1546 if Ada_Version >= Ada_05
1547 and then Ekind (T) = E_Anonymous_Access_Type
1549 -- Check RM 3.9.2(9): "if the expected type for an expression is
1550 -- an anonymous access-to-specific tagged type, then the object
1551 -- designated by the expression shall not be dynamically tagged
1552 -- unless it is a controlling operand in a call on a dispatching
1555 if Is_Tagged_Type (Directly_Designated_Type (T))
1557 Ekind (Directly_Designated_Type (T)) /= E_Class_Wide_Type
1559 Ekind (Directly_Designated_Type (Etype (E))) =
1563 ("access to specific tagged type required (RM 3.9.2(9))", E);
1566 -- (Ada 2005: AI-230): Accessibility check for anonymous
1569 if Type_Access_Level (Etype (E)) > Type_Access_Level (T) then
1571 ("expression has deeper access level than component " &
1572 "(RM 3.10.2 (12.2))", E);
1575 -- The initialization expression is a reference to an access
1576 -- discriminant. The type of the discriminant is always deeper
1577 -- than any access type.
1579 if Ekind (Etype (E)) = E_Anonymous_Access_Type
1580 and then Is_Entity_Name (E)
1581 and then Ekind (Entity (E)) = E_In_Parameter
1582 and then Present (Discriminal_Link (Entity (E)))
1585 ("discriminant has deeper accessibility level than target",
1591 -- The parent type may be a private view with unknown discriminants,
1592 -- and thus unconstrained. Regular components must be constrained.
1594 if Is_Indefinite_Subtype (T) and then Chars (Id) /= Name_uParent then
1595 if Is_Class_Wide_Type (T) then
1597 ("class-wide subtype with unknown discriminants" &
1598 " in component declaration",
1599 Subtype_Indication (Component_Definition (N)));
1602 ("unconstrained subtype in component declaration",
1603 Subtype_Indication (Component_Definition (N)));
1606 -- Components cannot be abstract, except for the special case of
1607 -- the _Parent field (case of extending an abstract tagged type)
1609 elsif Is_Abstract_Type (T) and then Chars (Id) /= Name_uParent then
1610 Error_Msg_N ("type of a component cannot be abstract", N);
1614 Set_Is_Aliased (Id, Aliased_Present (Component_Definition (N)));
1616 -- The component declaration may have a per-object constraint, set
1617 -- the appropriate flag in the defining identifier of the subtype.
1619 if Present (Subtype_Indication (Component_Definition (N))) then
1621 Sindic : constant Node_Id :=
1622 Subtype_Indication (Component_Definition (N));
1625 if Nkind (Sindic) = N_Subtype_Indication
1626 and then Present (Constraint (Sindic))
1627 and then Contains_POC (Constraint (Sindic))
1629 Set_Has_Per_Object_Constraint (Id);
1634 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
1635 -- out some static checks.
1637 if Ada_Version >= Ada_05
1638 and then Can_Never_Be_Null (T)
1640 Null_Exclusion_Static_Checks (N);
1643 -- If this component is private (or depends on a private type), flag the
1644 -- record type to indicate that some operations are not available.
1646 P := Private_Component (T);
1650 -- Check for circular definitions
1652 if P = Any_Type then
1653 Set_Etype (Id, Any_Type);
1655 -- There is a gap in the visibility of operations only if the
1656 -- component type is not defined in the scope of the record type.
1658 elsif Scope (P) = Scope (Current_Scope) then
1661 elsif Is_Limited_Type (P) then
1662 Set_Is_Limited_Composite (Current_Scope);
1665 Set_Is_Private_Composite (Current_Scope);
1670 and then Is_Limited_Type (T)
1671 and then Chars (Id) /= Name_uParent
1672 and then Is_Tagged_Type (Current_Scope)
1674 if Is_Derived_Type (Current_Scope)
1675 and then not Is_Known_Limited (Current_Scope)
1678 ("extension of nonlimited type cannot have limited components",
1681 if Is_Interface (Root_Type (Current_Scope)) then
1683 ("\limitedness is not inherited from limited interface", N);
1685 ("\add LIMITED to type indication", N);
1688 Explain_Limited_Type (T, N);
1689 Set_Etype (Id, Any_Type);
1690 Set_Is_Limited_Composite (Current_Scope, False);
1692 elsif not Is_Derived_Type (Current_Scope)
1693 and then not Is_Limited_Record (Current_Scope)
1694 and then not Is_Concurrent_Type (Current_Scope)
1697 ("nonlimited tagged type cannot have limited components", N);
1698 Explain_Limited_Type (T, N);
1699 Set_Etype (Id, Any_Type);
1700 Set_Is_Limited_Composite (Current_Scope, False);
1704 Set_Original_Record_Component (Id, Id);
1705 end Analyze_Component_Declaration;
1707 --------------------------
1708 -- Analyze_Declarations --
1709 --------------------------
1711 procedure Analyze_Declarations (L : List_Id) is
1713 Freeze_From : Entity_Id := Empty;
1714 Next_Node : Node_Id;
1717 -- Adjust D not to include implicit label declarations, since these
1718 -- have strange Sloc values that result in elaboration check problems.
1719 -- (They have the sloc of the label as found in the source, and that
1720 -- is ahead of the current declarative part).
1726 procedure Adjust_D is
1728 while Present (Prev (D))
1729 and then Nkind (D) = N_Implicit_Label_Declaration
1735 -- Start of processing for Analyze_Declarations
1739 while Present (D) loop
1741 -- Complete analysis of declaration
1744 Next_Node := Next (D);
1746 if No (Freeze_From) then
1747 Freeze_From := First_Entity (Current_Scope);
1750 -- At the end of a declarative part, freeze remaining entities
1751 -- declared in it. The end of the visible declarations of package
1752 -- specification is not the end of a declarative part if private
1753 -- declarations are present. The end of a package declaration is a
1754 -- freezing point only if it a library package. A task definition or
1755 -- protected type definition is not a freeze point either. Finally,
1756 -- we do not freeze entities in generic scopes, because there is no
1757 -- code generated for them and freeze nodes will be generated for
1760 -- The end of a package instantiation is not a freeze point, but
1761 -- for now we make it one, because the generic body is inserted
1762 -- (currently) immediately after. Generic instantiations will not
1763 -- be a freeze point once delayed freezing of bodies is implemented.
1764 -- (This is needed in any case for early instantiations ???).
1766 if No (Next_Node) then
1767 if Nkind (Parent (L)) = N_Component_List
1768 or else Nkind (Parent (L)) = N_Task_Definition
1769 or else Nkind (Parent (L)) = N_Protected_Definition
1773 elsif Nkind (Parent (L)) /= N_Package_Specification then
1774 if Nkind (Parent (L)) = N_Package_Body then
1775 Freeze_From := First_Entity (Current_Scope);
1779 Freeze_All (Freeze_From, D);
1780 Freeze_From := Last_Entity (Current_Scope);
1782 elsif Scope (Current_Scope) /= Standard_Standard
1783 and then not Is_Child_Unit (Current_Scope)
1784 and then No (Generic_Parent (Parent (L)))
1788 elsif L /= Visible_Declarations (Parent (L))
1789 or else No (Private_Declarations (Parent (L)))
1790 or else Is_Empty_List (Private_Declarations (Parent (L)))
1793 Freeze_All (Freeze_From, D);
1794 Freeze_From := Last_Entity (Current_Scope);
1797 -- If next node is a body then freeze all types before the body.
1798 -- An exception occurs for some expander-generated bodies. If these
1799 -- are generated at places where in general language rules would not
1800 -- allow a freeze point, then we assume that the expander has
1801 -- explicitly checked that all required types are properly frozen,
1802 -- and we do not cause general freezing here. This special circuit
1803 -- is used when the encountered body is marked as having already
1806 -- In all other cases (bodies that come from source, and expander
1807 -- generated bodies that have not been analyzed yet), freeze all
1808 -- types now. Note that in the latter case, the expander must take
1809 -- care to attach the bodies at a proper place in the tree so as to
1810 -- not cause unwanted freezing at that point.
1812 elsif not Analyzed (Next_Node)
1813 and then (Nkind (Next_Node) = N_Subprogram_Body
1814 or else Nkind (Next_Node) = N_Entry_Body
1815 or else Nkind (Next_Node) = N_Package_Body
1816 or else Nkind (Next_Node) = N_Protected_Body
1817 or else Nkind (Next_Node) = N_Task_Body
1818 or else Nkind (Next_Node) in N_Body_Stub)
1821 Freeze_All (Freeze_From, D);
1822 Freeze_From := Last_Entity (Current_Scope);
1827 end Analyze_Declarations;
1829 ----------------------------------
1830 -- Analyze_Incomplete_Type_Decl --
1831 ----------------------------------
1833 procedure Analyze_Incomplete_Type_Decl (N : Node_Id) is
1834 F : constant Boolean := Is_Pure (Current_Scope);
1838 Generate_Definition (Defining_Identifier (N));
1840 -- Process an incomplete declaration. The identifier must not have been
1841 -- declared already in the scope. However, an incomplete declaration may
1842 -- appear in the private part of a package, for a private type that has
1843 -- already been declared.
1845 -- In this case, the discriminants (if any) must match
1847 T := Find_Type_Name (N);
1849 Set_Ekind (T, E_Incomplete_Type);
1850 Init_Size_Align (T);
1851 Set_Is_First_Subtype (T, True);
1854 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
1855 -- incomplete types.
1857 if Tagged_Present (N) then
1858 Set_Is_Tagged_Type (T);
1859 Make_Class_Wide_Type (T);
1860 Set_Primitive_Operations (T, New_Elmt_List);
1865 Set_Stored_Constraint (T, No_Elist);
1867 if Present (Discriminant_Specifications (N)) then
1868 Process_Discriminants (N);
1873 -- If the type has discriminants, non-trivial subtypes may be be
1874 -- declared before the full view of the type. The full views of those
1875 -- subtypes will be built after the full view of the type.
1877 Set_Private_Dependents (T, New_Elmt_List);
1879 end Analyze_Incomplete_Type_Decl;
1881 -----------------------------------
1882 -- Analyze_Interface_Declaration --
1883 -----------------------------------
1885 procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id) is
1886 CW : constant Entity_Id := Class_Wide_Type (T);
1889 Set_Is_Tagged_Type (T);
1891 Set_Is_Limited_Record (T, Limited_Present (Def)
1892 or else Task_Present (Def)
1893 or else Protected_Present (Def)
1894 or else Synchronized_Present (Def));
1896 -- Type is abstract if full declaration carries keyword, or if previous
1897 -- partial view did.
1899 Set_Is_Abstract_Type (T);
1900 Set_Is_Interface (T);
1902 -- Type is a limited interface if it includes the keyword limited, task,
1903 -- protected, or synchronized.
1905 Set_Is_Limited_Interface
1906 (T, Limited_Present (Def)
1907 or else Protected_Present (Def)
1908 or else Synchronized_Present (Def)
1909 or else Task_Present (Def));
1911 Set_Is_Protected_Interface (T, Protected_Present (Def));
1912 Set_Is_Task_Interface (T, Task_Present (Def));
1914 -- Type is a synchronized interface if it includes the keyword task,
1915 -- protected, or synchronized.
1917 Set_Is_Synchronized_Interface
1918 (T, Synchronized_Present (Def)
1919 or else Protected_Present (Def)
1920 or else Task_Present (Def));
1922 Set_Abstract_Interfaces (T, New_Elmt_List);
1923 Set_Primitive_Operations (T, New_Elmt_List);
1925 -- Complete the decoration of the class-wide entity if it was already
1926 -- built (ie. during the creation of the limited view)
1928 if Present (CW) then
1929 Set_Is_Interface (CW);
1930 Set_Is_Limited_Interface (CW, Is_Limited_Interface (T));
1931 Set_Is_Protected_Interface (CW, Is_Protected_Interface (T));
1932 Set_Is_Synchronized_Interface (CW, Is_Synchronized_Interface (T));
1933 Set_Is_Task_Interface (CW, Is_Task_Interface (T));
1935 end Analyze_Interface_Declaration;
1937 -----------------------------
1938 -- Analyze_Itype_Reference --
1939 -----------------------------
1941 -- Nothing to do. This node is placed in the tree only for the benefit of
1942 -- back end processing, and has no effect on the semantic processing.
1944 procedure Analyze_Itype_Reference (N : Node_Id) is
1946 pragma Assert (Is_Itype (Itype (N)));
1948 end Analyze_Itype_Reference;
1950 --------------------------------
1951 -- Analyze_Number_Declaration --
1952 --------------------------------
1954 procedure Analyze_Number_Declaration (N : Node_Id) is
1955 Id : constant Entity_Id := Defining_Identifier (N);
1956 E : constant Node_Id := Expression (N);
1958 Index : Interp_Index;
1962 Generate_Definition (Id);
1965 -- This is an optimization of a common case of an integer literal
1967 if Nkind (E) = N_Integer_Literal then
1968 Set_Is_Static_Expression (E, True);
1969 Set_Etype (E, Universal_Integer);
1971 Set_Etype (Id, Universal_Integer);
1972 Set_Ekind (Id, E_Named_Integer);
1973 Set_Is_Frozen (Id, True);
1977 Set_Is_Pure (Id, Is_Pure (Current_Scope));
1979 -- Process expression, replacing error by integer zero, to avoid
1980 -- cascaded errors or aborts further along in the processing
1982 -- Replace Error by integer zero, which seems least likely to
1983 -- cause cascaded errors.
1986 Rewrite (E, Make_Integer_Literal (Sloc (E), Uint_0));
1987 Set_Error_Posted (E);
1992 -- Verify that the expression is static and numeric. If
1993 -- the expression is overloaded, we apply the preference
1994 -- rule that favors root numeric types.
1996 if not Is_Overloaded (E) then
2002 Get_First_Interp (E, Index, It);
2003 while Present (It.Typ) loop
2004 if (Is_Integer_Type (It.Typ)
2005 or else Is_Real_Type (It.Typ))
2006 and then (Scope (Base_Type (It.Typ))) = Standard_Standard
2008 if T = Any_Type then
2011 elsif It.Typ = Universal_Real
2012 or else It.Typ = Universal_Integer
2014 -- Choose universal interpretation over any other
2021 Get_Next_Interp (Index, It);
2025 if Is_Integer_Type (T) then
2027 Set_Etype (Id, Universal_Integer);
2028 Set_Ekind (Id, E_Named_Integer);
2030 elsif Is_Real_Type (T) then
2032 -- Because the real value is converted to universal_real, this is a
2033 -- legal context for a universal fixed expression.
2035 if T = Universal_Fixed then
2037 Loc : constant Source_Ptr := Sloc (N);
2038 Conv : constant Node_Id := Make_Type_Conversion (Loc,
2040 New_Occurrence_Of (Universal_Real, Loc),
2041 Expression => Relocate_Node (E));
2048 elsif T = Any_Fixed then
2049 Error_Msg_N ("illegal context for mixed mode operation", E);
2051 -- Expression is of the form : universal_fixed * integer. Try to
2052 -- resolve as universal_real.
2054 T := Universal_Real;
2059 Set_Etype (Id, Universal_Real);
2060 Set_Ekind (Id, E_Named_Real);
2063 Wrong_Type (E, Any_Numeric);
2067 Set_Ekind (Id, E_Constant);
2068 Set_Never_Set_In_Source (Id, True);
2069 Set_Is_True_Constant (Id, True);
2073 if Nkind (E) = N_Integer_Literal
2074 or else Nkind (E) = N_Real_Literal
2076 Set_Etype (E, Etype (Id));
2079 if not Is_OK_Static_Expression (E) then
2080 Flag_Non_Static_Expr
2081 ("non-static expression used in number declaration!", E);
2082 Rewrite (E, Make_Integer_Literal (Sloc (N), 1));
2083 Set_Etype (E, Any_Type);
2085 end Analyze_Number_Declaration;
2087 --------------------------------
2088 -- Analyze_Object_Declaration --
2089 --------------------------------
2091 procedure Analyze_Object_Declaration (N : Node_Id) is
2092 Loc : constant Source_Ptr := Sloc (N);
2093 Id : constant Entity_Id := Defining_Identifier (N);
2097 E : Node_Id := Expression (N);
2098 -- E is set to Expression (N) throughout this routine. When
2099 -- Expression (N) is modified, E is changed accordingly.
2101 Prev_Entity : Entity_Id := Empty;
2103 function Count_Tasks (T : Entity_Id) return Uint;
2104 -- This function is called when a library level object of type is
2105 -- declared. It's function is to count the static number of tasks
2106 -- declared within the type (it is only called if Has_Tasks is set for
2107 -- T). As a side effect, if an array of tasks with non-static bounds or
2108 -- a variant record type is encountered, Check_Restrictions is called
2109 -- indicating the count is unknown.
2115 function Count_Tasks (T : Entity_Id) return Uint is
2121 if Is_Task_Type (T) then
2124 elsif Is_Record_Type (T) then
2125 if Has_Discriminants (T) then
2126 Check_Restriction (Max_Tasks, N);
2131 C := First_Component (T);
2132 while Present (C) loop
2133 V := V + Count_Tasks (Etype (C));
2140 elsif Is_Array_Type (T) then
2141 X := First_Index (T);
2142 V := Count_Tasks (Component_Type (T));
2143 while Present (X) loop
2146 if not Is_Static_Subtype (C) then
2147 Check_Restriction (Max_Tasks, N);
2150 V := V * (UI_Max (Uint_0,
2151 Expr_Value (Type_High_Bound (C)) -
2152 Expr_Value (Type_Low_Bound (C)) + Uint_1));
2165 -- Start of processing for Analyze_Object_Declaration
2168 -- There are three kinds of implicit types generated by an
2169 -- object declaration:
2171 -- 1. Those for generated by the original Object Definition
2173 -- 2. Those generated by the Expression
2175 -- 3. Those used to constrained the Object Definition with the
2176 -- expression constraints when it is unconstrained
2178 -- They must be generated in this order to avoid order of elaboration
2179 -- issues. Thus the first step (after entering the name) is to analyze
2180 -- the object definition.
2182 if Constant_Present (N) then
2183 Prev_Entity := Current_Entity_In_Scope (Id);
2185 -- If homograph is an implicit subprogram, it is overridden by the
2186 -- current declaration.
2188 if Present (Prev_Entity)
2189 and then Is_Overloadable (Prev_Entity)
2190 and then Is_Inherited_Operation (Prev_Entity)
2192 Prev_Entity := Empty;
2196 if Present (Prev_Entity) then
2197 Constant_Redeclaration (Id, N, T);
2199 Generate_Reference (Prev_Entity, Id, 'c');
2200 Set_Completion_Referenced (Id);
2202 if Error_Posted (N) then
2204 -- Type mismatch or illegal redeclaration, Do not analyze
2205 -- expression to avoid cascaded errors.
2207 T := Find_Type_Of_Object (Object_Definition (N), N);
2209 Set_Ekind (Id, E_Variable);
2213 -- In the normal case, enter identifier at the start to catch premature
2214 -- usage in the initialization expression.
2217 Generate_Definition (Id);
2220 Mark_Coextensions (N, Object_Definition (N));
2222 T := Find_Type_Of_Object (Object_Definition (N), N);
2224 if Nkind (Object_Definition (N)) = N_Access_Definition
2226 (Access_To_Subprogram_Definition (Object_Definition (N)))
2227 and then Protected_Present
2228 (Access_To_Subprogram_Definition (Object_Definition (N)))
2230 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
2233 if Error_Posted (Id) then
2235 Set_Ekind (Id, E_Variable);
2240 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2241 -- out some static checks
2243 if Ada_Version >= Ada_05
2244 and then Can_Never_Be_Null (T)
2246 -- In case of aggregates we must also take care of the correct
2247 -- initialization of nested aggregates bug this is done at the
2248 -- point of the analysis of the aggregate (see sem_aggr.adb)
2250 if Present (Expression (N))
2251 and then Nkind (Expression (N)) = N_Aggregate
2257 Save_Typ : constant Entity_Id := Etype (Id);
2259 Set_Etype (Id, T); -- Temp. decoration for static checks
2260 Null_Exclusion_Static_Checks (N);
2261 Set_Etype (Id, Save_Typ);
2266 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2268 -- If deferred constant, make sure context is appropriate. We detect
2269 -- a deferred constant as a constant declaration with no expression.
2270 -- A deferred constant can appear in a package body if its completion
2271 -- is by means of an interface pragma.
2273 if Constant_Present (N)
2276 -- We exclude forward references to tags
2278 if Is_Imported (Defining_Identifier (N))
2281 or else (Present (Full_View (T))
2282 and then Full_View (T) = RTE (RE_Tag)))
2286 elsif not Is_Package_Or_Generic_Package (Current_Scope) then
2288 ("invalid context for deferred constant declaration (RM 7.4)",
2291 ("\declaration requires an initialization expression",
2293 Set_Constant_Present (N, False);
2295 -- In Ada 83, deferred constant must be of private type
2297 elsif not Is_Private_Type (T) then
2298 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2300 ("(Ada 83) deferred constant must be private type", N);
2304 -- If not a deferred constant, then object declaration freezes its type
2307 Check_Fully_Declared (T, N);
2308 Freeze_Before (N, T);
2311 -- If the object was created by a constrained array definition, then
2312 -- set the link in both the anonymous base type and anonymous subtype
2313 -- that are built to represent the array type to point to the object.
2315 if Nkind (Object_Definition (Declaration_Node (Id))) =
2316 N_Constrained_Array_Definition
2318 Set_Related_Array_Object (T, Id);
2319 Set_Related_Array_Object (Base_Type (T), Id);
2322 -- Special checks for protected objects not at library level
2324 if Is_Protected_Type (T)
2325 and then not Is_Library_Level_Entity (Id)
2327 Check_Restriction (No_Local_Protected_Objects, Id);
2329 -- Protected objects with interrupt handlers must be at library level
2331 -- Ada 2005: this test is not needed (and the corresponding clause
2332 -- in the RM is removed) because accessibility checks are sufficient
2333 -- to make handlers not at the library level illegal.
2335 if Has_Interrupt_Handler (T)
2336 and then Ada_Version < Ada_05
2339 ("interrupt object can only be declared at library level", Id);
2343 -- The actual subtype of the object is the nominal subtype, unless
2344 -- the nominal one is unconstrained and obtained from the expression.
2348 -- Process initialization expression if present and not in error
2350 if Present (E) and then E /= Error then
2351 Mark_Coextensions (N, E);
2354 -- In case of errors detected in the analysis of the expression,
2355 -- decorate it with the expected type to avoid cascade errors
2357 if No (Etype (E)) then
2361 -- If an initialization expression is present, then we set the
2362 -- Is_True_Constant flag. It will be reset if this is a variable
2363 -- and it is indeed modified.
2365 Set_Is_True_Constant (Id, True);
2367 -- If we are analyzing a constant declaration, set its completion
2368 -- flag after analyzing the expression.
2370 if Constant_Present (N) then
2371 Set_Has_Completion (Id);
2374 Set_Etype (Id, T); -- may be overridden later on
2377 if not Assignment_OK (N) then
2378 Check_Initialization (T, E);
2381 Check_Unset_Reference (E);
2383 -- If this is a variable, then set current value
2385 if not Constant_Present (N) then
2386 if Compile_Time_Known_Value (E) then
2387 Set_Current_Value (Id, E);
2391 -- Deal with setting of null flags
2393 if Is_Access_Type (T) then
2394 if Known_Non_Null (E) then
2395 Set_Is_Known_Non_Null (Id, True);
2396 elsif Known_Null (E)
2397 and then not Can_Never_Be_Null (Id)
2399 Set_Is_Known_Null (Id, True);
2403 -- Check incorrect use of dynamically tagged expressions. Note
2404 -- the use of Is_Tagged_Type (T) which seems redundant but is in
2405 -- fact important to avoid spurious errors due to expanded code
2406 -- for dispatching functions over an anonymous access type
2408 if (Is_Class_Wide_Type (Etype (E)) or else Is_Dynamically_Tagged (E))
2409 and then Is_Tagged_Type (T)
2410 and then not Is_Class_Wide_Type (T)
2412 Error_Msg_N ("dynamically tagged expression not allowed!", E);
2415 Apply_Scalar_Range_Check (E, T);
2416 Apply_Static_Length_Check (E, T);
2419 -- If the No_Streams restriction is set, check that the type of the
2420 -- object is not, and does not contain, any subtype derived from
2421 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
2422 -- Has_Stream just for efficiency reasons. There is no point in
2423 -- spending time on a Has_Stream check if the restriction is not set.
2425 if Restrictions.Set (No_Streams) then
2426 if Has_Stream (T) then
2427 Check_Restriction (No_Streams, N);
2431 -- Abstract type is never permitted for a variable or constant.
2432 -- Note: we inhibit this check for objects that do not come from
2433 -- source because there is at least one case (the expansion of
2434 -- x'class'input where x is abstract) where we legitimately
2435 -- generate an abstract object.
2437 if Is_Abstract_Type (T) and then Comes_From_Source (N) then
2438 Error_Msg_N ("type of object cannot be abstract",
2439 Object_Definition (N));
2441 if Is_CPP_Class (T) then
2442 Error_Msg_NE ("\} may need a cpp_constructor",
2443 Object_Definition (N), T);
2446 -- Case of unconstrained type
2448 elsif Is_Indefinite_Subtype (T) then
2450 -- Nothing to do in deferred constant case
2452 if Constant_Present (N) and then No (E) then
2455 -- Case of no initialization present
2458 if No_Initialization (N) then
2461 elsif Is_Class_Wide_Type (T) then
2463 ("initialization required in class-wide declaration ", N);
2467 ("unconstrained subtype not allowed (need initialization)",
2468 Object_Definition (N));
2471 -- Case of initialization present but in error. Set initial
2472 -- expression as absent (but do not make above complaints)
2474 elsif E = Error then
2475 Set_Expression (N, Empty);
2478 -- Case of initialization present
2481 -- Not allowed in Ada 83
2483 if not Constant_Present (N) then
2484 if Ada_Version = Ada_83
2485 and then Comes_From_Source (Object_Definition (N))
2488 ("(Ada 83) unconstrained variable not allowed",
2489 Object_Definition (N));
2493 -- Now we constrain the variable from the initializing expression
2495 -- If the expression is an aggregate, it has been expanded into
2496 -- individual assignments. Retrieve the actual type from the
2497 -- expanded construct.
2499 if Is_Array_Type (T)
2500 and then No_Initialization (N)
2501 and then Nkind (Original_Node (E)) = N_Aggregate
2506 Expand_Subtype_From_Expr (N, T, Object_Definition (N), E);
2507 Act_T := Find_Type_Of_Object (Object_Definition (N), N);
2510 Set_Is_Constr_Subt_For_U_Nominal (Act_T);
2512 if Aliased_Present (N) then
2513 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2516 Freeze_Before (N, Act_T);
2517 Freeze_Before (N, T);
2520 elsif Is_Array_Type (T)
2521 and then No_Initialization (N)
2522 and then Nkind (Original_Node (E)) = N_Aggregate
2524 if not Is_Entity_Name (Object_Definition (N)) then
2526 Check_Compile_Time_Size (Act_T);
2528 if Aliased_Present (N) then
2529 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2533 -- When the given object definition and the aggregate are specified
2534 -- independently, and their lengths might differ do a length check.
2535 -- This cannot happen if the aggregate is of the form (others =>...)
2537 if not Is_Constrained (T) then
2540 elsif Nkind (E) = N_Raise_Constraint_Error then
2542 -- Aggregate is statically illegal. Place back in declaration
2544 Set_Expression (N, E);
2545 Set_No_Initialization (N, False);
2547 elsif T = Etype (E) then
2550 elsif Nkind (E) = N_Aggregate
2551 and then Present (Component_Associations (E))
2552 and then Present (Choices (First (Component_Associations (E))))
2553 and then Nkind (First
2554 (Choices (First (Component_Associations (E))))) = N_Others_Choice
2559 Apply_Length_Check (E, T);
2562 -- If the type is limited unconstrained with defaulted discriminants
2563 -- and there is no expression, then the object is constrained by the
2564 -- defaults, so it is worthwhile building the corresponding subtype.
2566 elsif (Is_Limited_Record (T)
2567 or else Is_Concurrent_Type (T))
2568 and then not Is_Constrained (T)
2569 and then Has_Discriminants (T)
2572 Act_T := Build_Default_Subtype (T, N);
2574 -- Ada 2005: a limited object may be initialized by means of an
2575 -- aggregate. If the type has default discriminants it has an
2576 -- unconstrained nominal type, Its actual subtype will be obtained
2577 -- from the aggregate, and not from the default discriminants.
2582 Rewrite (Object_Definition (N), New_Occurrence_Of (Act_T, Loc));
2584 elsif Present (Underlying_Type (T))
2585 and then not Is_Constrained (Underlying_Type (T))
2586 and then Has_Discriminants (Underlying_Type (T))
2587 and then Nkind (E) = N_Function_Call
2588 and then Constant_Present (N)
2590 -- The back-end has problems with constants of a discriminated type
2591 -- with defaults, if the initial value is a function call. We
2592 -- generate an intermediate temporary for the result of the call.
2593 -- It is unclear why this should make it acceptable to gcc. ???
2595 Remove_Side_Effects (E);
2598 if T = Standard_Wide_Character or else T = Standard_Wide_Wide_Character
2599 or else Root_Type (T) = Standard_Wide_String
2600 or else Root_Type (T) = Standard_Wide_Wide_String
2602 Check_Restriction (No_Wide_Characters, Object_Definition (N));
2605 -- Indicate this is not set in source. Certainly true for constants,
2606 -- and true for variables so far (will be reset for a variable if and
2607 -- when we encounter a modification in the source).
2609 Set_Never_Set_In_Source (Id, True);
2611 -- Now establish the proper kind and type of the object
2613 if Constant_Present (N) then
2614 Set_Ekind (Id, E_Constant);
2615 Set_Is_True_Constant (Id, True);
2618 Set_Ekind (Id, E_Variable);
2620 -- A variable is set as shared passive if it appears in a shared
2621 -- passive package, and is at the outer level. This is not done
2622 -- for entities generated during expansion, because those are
2623 -- always manipulated locally.
2625 if Is_Shared_Passive (Current_Scope)
2626 and then Is_Library_Level_Entity (Id)
2627 and then Comes_From_Source (Id)
2629 Set_Is_Shared_Passive (Id);
2630 Check_Shared_Var (Id, T, N);
2633 -- Set Has_Initial_Value if initializing expression present. Note
2634 -- that if there is no initializating expression, we leave the state
2635 -- of this flag unchanged (usually it will be False, but notably in
2636 -- the case of exception choice variables, it will already be true).
2639 Set_Has_Initial_Value (Id, True);
2643 -- Initialize alignment and size
2645 Init_Alignment (Id);
2648 -- Deal with aliased case
2650 if Aliased_Present (N) then
2651 Set_Is_Aliased (Id);
2653 -- If the object is aliased and the type is unconstrained with
2654 -- defaulted discriminants and there is no expression, then the
2655 -- object is constrained by the defaults, so it is worthwhile
2656 -- building the corresponding subtype.
2658 -- Ada 2005 (AI-363): If the aliased object is discriminated and
2659 -- unconstrained, then only establish an actual subtype if the
2660 -- nominal subtype is indefinite. In definite cases the object is
2661 -- unconstrained in Ada 2005.
2664 and then Is_Record_Type (T)
2665 and then not Is_Constrained (T)
2666 and then Has_Discriminants (T)
2667 and then (Ada_Version < Ada_05 or else Is_Indefinite_Subtype (T))
2669 Set_Actual_Subtype (Id, Build_Default_Subtype (T, N));
2673 -- Now we can set the type of the object
2675 Set_Etype (Id, Act_T);
2677 -- Deal with controlled types
2679 if Has_Controlled_Component (Etype (Id))
2680 or else Is_Controlled (Etype (Id))
2682 if not Is_Library_Level_Entity (Id) then
2683 Check_Restriction (No_Nested_Finalization, N);
2685 Validate_Controlled_Object (Id);
2688 -- Generate a warning when an initialization causes an obvious ABE
2689 -- violation. If the init expression is a simple aggregate there
2690 -- shouldn't be any initialize/adjust call generated. This will be
2691 -- true as soon as aggregates are built in place when possible.
2693 -- ??? at the moment we do not generate warnings for temporaries
2694 -- created for those aggregates although Program_Error might be
2695 -- generated if compiled with -gnato.
2697 if Is_Controlled (Etype (Id))
2698 and then Comes_From_Source (Id)
2701 BT : constant Entity_Id := Base_Type (Etype (Id));
2703 Implicit_Call : Entity_Id;
2704 pragma Warnings (Off, Implicit_Call);
2705 -- ??? what is this for (never referenced!)
2707 function Is_Aggr (N : Node_Id) return Boolean;
2708 -- Check that N is an aggregate
2714 function Is_Aggr (N : Node_Id) return Boolean is
2716 case Nkind (Original_Node (N)) is
2717 when N_Aggregate | N_Extension_Aggregate =>
2720 when N_Qualified_Expression |
2722 N_Unchecked_Type_Conversion =>
2723 return Is_Aggr (Expression (Original_Node (N)));
2731 -- If no underlying type, we already are in an error situation.
2732 -- Do not try to add a warning since we do not have access to
2735 if No (Underlying_Type (BT)) then
2736 Implicit_Call := Empty;
2738 -- A generic type does not have usable primitive operators.
2739 -- Initialization calls are built for instances.
2741 elsif Is_Generic_Type (BT) then
2742 Implicit_Call := Empty;
2744 -- If the init expression is not an aggregate, an adjust call
2745 -- will be generated
2747 elsif Present (E) and then not Is_Aggr (E) then
2748 Implicit_Call := Find_Prim_Op (BT, Name_Adjust);
2750 -- If no init expression and we are not in the deferred
2751 -- constant case, an Initialize call will be generated
2753 elsif No (E) and then not Constant_Present (N) then
2754 Implicit_Call := Find_Prim_Op (BT, Name_Initialize);
2757 Implicit_Call := Empty;
2763 if Has_Task (Etype (Id)) then
2764 Check_Restriction (No_Tasking, N);
2766 if Is_Library_Level_Entity (Id) then
2767 Check_Restriction (Max_Tasks, N, Count_Tasks (Etype (Id)));
2769 Check_Restriction (Max_Tasks, N);
2770 Check_Restriction (No_Task_Hierarchy, N);
2771 Check_Potentially_Blocking_Operation (N);
2774 -- A rather specialized test. If we see two tasks being declared
2775 -- of the same type in the same object declaration, and the task
2776 -- has an entry with an address clause, we know that program error
2777 -- will be raised at run-time since we can't have two tasks with
2778 -- entries at the same address.
2780 if Is_Task_Type (Etype (Id)) and then More_Ids (N) then
2785 E := First_Entity (Etype (Id));
2786 while Present (E) loop
2787 if Ekind (E) = E_Entry
2788 and then Present (Get_Attribute_Definition_Clause
2789 (E, Attribute_Address))
2792 ("?more than one task with same entry address", N);
2794 ("\?Program_Error will be raised at run time", N);
2796 Make_Raise_Program_Error (Loc,
2797 Reason => PE_Duplicated_Entry_Address));
2807 -- Some simple constant-propagation: if the expression is a constant
2808 -- string initialized with a literal, share the literal. This avoids
2812 and then Is_Entity_Name (E)
2813 and then Ekind (Entity (E)) = E_Constant
2814 and then Base_Type (Etype (E)) = Standard_String
2817 Val : constant Node_Id := Constant_Value (Entity (E));
2820 and then Nkind (Val) = N_String_Literal
2822 Rewrite (E, New_Copy (Val));
2827 -- Another optimization: if the nominal subtype is unconstrained and
2828 -- the expression is a function call that returns an unconstrained
2829 -- type, rewrite the declaration as a renaming of the result of the
2830 -- call. The exceptions below are cases where the copy is expected,
2831 -- either by the back end (Aliased case) or by the semantics, as for
2832 -- initializing controlled types or copying tags for classwide types.
2835 and then Nkind (E) = N_Explicit_Dereference
2836 and then Nkind (Original_Node (E)) = N_Function_Call
2837 and then not Is_Library_Level_Entity (Id)
2838 and then not Is_Constrained (Underlying_Type (T))
2839 and then not Is_Aliased (Id)
2840 and then not Is_Class_Wide_Type (T)
2841 and then not Is_Controlled (T)
2842 and then not Has_Controlled_Component (Base_Type (T))
2843 and then Expander_Active
2846 Make_Object_Renaming_Declaration (Loc,
2847 Defining_Identifier => Id,
2848 Access_Definition => Empty,
2849 Subtype_Mark => New_Occurrence_Of
2850 (Base_Type (Etype (Id)), Loc),
2853 Set_Renamed_Object (Id, E);
2855 -- Force generation of debugging information for the constant and for
2856 -- the renamed function call.
2858 Set_Needs_Debug_Info (Id);
2859 Set_Needs_Debug_Info (Entity (Prefix (E)));
2862 if Present (Prev_Entity)
2863 and then Is_Frozen (Prev_Entity)
2864 and then not Error_Posted (Id)
2866 Error_Msg_N ("full constant declaration appears too late", N);
2869 Check_Eliminated (Id);
2871 -- Deal with setting In_Private_Part flag if in private part
2873 if Ekind (Scope (Id)) = E_Package
2874 and then In_Private_Part (Scope (Id))
2876 Set_In_Private_Part (Id);
2878 end Analyze_Object_Declaration;
2880 ---------------------------
2881 -- Analyze_Others_Choice --
2882 ---------------------------
2884 -- Nothing to do for the others choice node itself, the semantic analysis
2885 -- of the others choice will occur as part of the processing of the parent
2887 procedure Analyze_Others_Choice (N : Node_Id) is
2888 pragma Warnings (Off, N);
2891 end Analyze_Others_Choice;
2893 --------------------------------
2894 -- Analyze_Per_Use_Expression --
2895 --------------------------------
2897 procedure Analyze_Per_Use_Expression (N : Node_Id; T : Entity_Id) is
2898 Save_In_Default_Expression : constant Boolean := In_Default_Expression;
2900 In_Default_Expression := True;
2901 Pre_Analyze_And_Resolve (N, T);
2902 In_Default_Expression := Save_In_Default_Expression;
2903 end Analyze_Per_Use_Expression;
2905 -------------------------------------------
2906 -- Analyze_Private_Extension_Declaration --
2907 -------------------------------------------
2909 procedure Analyze_Private_Extension_Declaration (N : Node_Id) is
2910 T : constant Entity_Id := Defining_Identifier (N);
2911 Indic : constant Node_Id := Subtype_Indication (N);
2912 Parent_Type : Entity_Id;
2913 Parent_Base : Entity_Id;
2916 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
2918 if Is_Non_Empty_List (Interface_List (N)) then
2924 Intf := First (Interface_List (N));
2925 while Present (Intf) loop
2926 T := Find_Type_Of_Subtype_Indic (Intf);
2928 if not Is_Interface (T) then
2929 Error_Msg_NE ("(Ada 2005) & must be an interface", Intf, T);
2937 Generate_Definition (T);
2940 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
2941 Parent_Base := Base_Type (Parent_Type);
2943 if Parent_Type = Any_Type
2944 or else Etype (Parent_Type) = Any_Type
2946 Set_Ekind (T, Ekind (Parent_Type));
2947 Set_Etype (T, Any_Type);
2950 elsif not Is_Tagged_Type (Parent_Type) then
2952 ("parent of type extension must be a tagged type ", Indic);
2955 elsif Ekind (Parent_Type) = E_Void
2956 or else Ekind (Parent_Type) = E_Incomplete_Type
2958 Error_Msg_N ("premature derivation of incomplete type", Indic);
2961 elsif Is_Concurrent_Type (Parent_Type) then
2963 ("parent type of a private extension cannot be "
2964 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
2966 Set_Etype (T, Any_Type);
2967 Set_Ekind (T, E_Limited_Private_Type);
2968 Set_Private_Dependents (T, New_Elmt_List);
2969 Set_Error_Posted (T);
2973 -- Perhaps the parent type should be changed to the class-wide type's
2974 -- specific type in this case to prevent cascading errors ???
2976 if Is_Class_Wide_Type (Parent_Type) then
2978 ("parent of type extension must not be a class-wide type", Indic);
2982 if (not Is_Package_Or_Generic_Package (Current_Scope)
2983 and then Nkind (Parent (N)) /= N_Generic_Subprogram_Declaration)
2984 or else In_Private_Part (Current_Scope)
2987 Error_Msg_N ("invalid context for private extension", N);
2990 -- Set common attributes
2992 Set_Is_Pure (T, Is_Pure (Current_Scope));
2993 Set_Scope (T, Current_Scope);
2994 Set_Ekind (T, E_Record_Type_With_Private);
2995 Init_Size_Align (T);
2997 Set_Etype (T, Parent_Base);
2998 Set_Has_Task (T, Has_Task (Parent_Base));
3000 Set_Convention (T, Convention (Parent_Type));
3001 Set_First_Rep_Item (T, First_Rep_Item (Parent_Type));
3002 Set_Is_First_Subtype (T);
3003 Make_Class_Wide_Type (T);
3005 if Unknown_Discriminants_Present (N) then
3006 Set_Discriminant_Constraint (T, No_Elist);
3009 Build_Derived_Record_Type (N, Parent_Type, T);
3011 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
3012 -- synchronized formal derived type.
3014 if Ada_Version >= Ada_05
3015 and then Synchronized_Present (N)
3017 Set_Is_Limited_Record (T);
3019 -- Formal derived type case
3021 if Is_Generic_Type (T) then
3023 -- The parent must be a tagged limited type or a synchronized
3026 if (not Is_Tagged_Type (Parent_Type)
3027 or else not Is_Limited_Type (Parent_Type))
3029 (not Is_Interface (Parent_Type)
3030 or else not Is_Synchronized_Interface (Parent_Type))
3032 Error_Msg_NE ("parent type of & must be tagged limited " &
3033 "or synchronized", N, T);
3036 -- The progenitors (if any) must be limited or synchronized
3039 if Present (Abstract_Interfaces (T)) then
3042 Iface_Elmt : Elmt_Id;
3045 Iface_Elmt := First_Elmt (Abstract_Interfaces (T));
3046 while Present (Iface_Elmt) loop
3047 Iface := Node (Iface_Elmt);
3049 if not Is_Limited_Interface (Iface)
3050 and then not Is_Synchronized_Interface (Iface)
3052 Error_Msg_NE ("progenitor & must be limited " &
3053 "or synchronized", N, Iface);
3056 Next_Elmt (Iface_Elmt);
3061 -- Regular derived extension, the parent must be a limited or
3062 -- synchronized interface.
3065 if not Is_Interface (Parent_Type)
3066 or else (not Is_Limited_Interface (Parent_Type)
3068 not Is_Synchronized_Interface (Parent_Type))
3071 ("parent type of & must be limited interface", N, T);
3075 elsif Limited_Present (N) then
3076 Set_Is_Limited_Record (T);
3078 if not Is_Limited_Type (Parent_Type)
3080 (not Is_Interface (Parent_Type)
3081 or else not Is_Limited_Interface (Parent_Type))
3083 Error_Msg_NE ("parent type& of limited extension must be limited",
3087 end Analyze_Private_Extension_Declaration;
3089 ---------------------------------
3090 -- Analyze_Subtype_Declaration --
3091 ---------------------------------
3093 procedure Analyze_Subtype_Declaration
3095 Skip : Boolean := False)
3097 Id : constant Entity_Id := Defining_Identifier (N);
3099 R_Checks : Check_Result;
3102 Generate_Definition (Id);
3103 Set_Is_Pure (Id, Is_Pure (Current_Scope));
3104 Init_Size_Align (Id);
3106 -- The following guard condition on Enter_Name is to handle cases where
3107 -- the defining identifier has already been entered into the scope but
3108 -- the declaration as a whole needs to be analyzed.
3110 -- This case in particular happens for derived enumeration types. The
3111 -- derived enumeration type is processed as an inserted enumeration type
3112 -- declaration followed by a rewritten subtype declaration. The defining
3113 -- identifier, however, is entered into the name scope very early in the
3114 -- processing of the original type declaration and therefore needs to be
3115 -- avoided here, when the created subtype declaration is analyzed. (See
3116 -- Build_Derived_Types)
3118 -- This also happens when the full view of a private type is derived
3119 -- type with constraints. In this case the entity has been introduced
3120 -- in the private declaration.
3123 or else (Present (Etype (Id))
3124 and then (Is_Private_Type (Etype (Id))
3125 or else Is_Task_Type (Etype (Id))
3126 or else Is_Rewrite_Substitution (N)))
3134 T := Process_Subtype (Subtype_Indication (N), N, Id, 'P');
3136 -- Inherit common attributes
3138 Set_Is_Generic_Type (Id, Is_Generic_Type (Base_Type (T)));
3139 Set_Is_Volatile (Id, Is_Volatile (T));
3140 Set_Treat_As_Volatile (Id, Treat_As_Volatile (T));
3141 Set_Is_Atomic (Id, Is_Atomic (T));
3142 Set_Is_Ada_2005_Only (Id, Is_Ada_2005_Only (T));
3144 -- In the case where there is no constraint given in the subtype
3145 -- indication, Process_Subtype just returns the Subtype_Mark, so its
3146 -- semantic attributes must be established here.
3148 if Nkind (Subtype_Indication (N)) /= N_Subtype_Indication then
3149 Set_Etype (Id, Base_Type (T));
3153 Set_Ekind (Id, E_Array_Subtype);
3154 Copy_Array_Subtype_Attributes (Id, T);
3156 when Decimal_Fixed_Point_Kind =>
3157 Set_Ekind (Id, E_Decimal_Fixed_Point_Subtype);
3158 Set_Digits_Value (Id, Digits_Value (T));
3159 Set_Delta_Value (Id, Delta_Value (T));
3160 Set_Scale_Value (Id, Scale_Value (T));
3161 Set_Small_Value (Id, Small_Value (T));
3162 Set_Scalar_Range (Id, Scalar_Range (T));
3163 Set_Machine_Radix_10 (Id, Machine_Radix_10 (T));
3164 Set_Is_Constrained (Id, Is_Constrained (T));
3165 Set_RM_Size (Id, RM_Size (T));
3167 when Enumeration_Kind =>
3168 Set_Ekind (Id, E_Enumeration_Subtype);
3169 Set_First_Literal (Id, First_Literal (Base_Type (T)));
3170 Set_Scalar_Range (Id, Scalar_Range (T));
3171 Set_Is_Character_Type (Id, Is_Character_Type (T));
3172 Set_Is_Constrained (Id, Is_Constrained (T));
3173 Set_RM_Size (Id, RM_Size (T));
3175 when Ordinary_Fixed_Point_Kind =>
3176 Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype);
3177 Set_Scalar_Range (Id, Scalar_Range (T));
3178 Set_Small_Value (Id, Small_Value (T));
3179 Set_Delta_Value (Id, Delta_Value (T));
3180 Set_Is_Constrained (Id, Is_Constrained (T));
3181 Set_RM_Size (Id, RM_Size (T));
3184 Set_Ekind (Id, E_Floating_Point_Subtype);
3185 Set_Scalar_Range (Id, Scalar_Range (T));
3186 Set_Digits_Value (Id, Digits_Value (T));
3187 Set_Is_Constrained (Id, Is_Constrained (T));
3189 when Signed_Integer_Kind =>
3190 Set_Ekind (Id, E_Signed_Integer_Subtype);
3191 Set_Scalar_Range (Id, Scalar_Range (T));
3192 Set_Is_Constrained (Id, Is_Constrained (T));
3193 Set_RM_Size (Id, RM_Size (T));
3195 when Modular_Integer_Kind =>
3196 Set_Ekind (Id, E_Modular_Integer_Subtype);
3197 Set_Scalar_Range (Id, Scalar_Range (T));
3198 Set_Is_Constrained (Id, Is_Constrained (T));
3199 Set_RM_Size (Id, RM_Size (T));
3201 when Class_Wide_Kind =>
3202 Set_Ekind (Id, E_Class_Wide_Subtype);
3203 Set_First_Entity (Id, First_Entity (T));
3204 Set_Last_Entity (Id, Last_Entity (T));
3205 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3206 Set_Cloned_Subtype (Id, T);
3207 Set_Is_Tagged_Type (Id, True);
3208 Set_Has_Unknown_Discriminants
3211 if Ekind (T) = E_Class_Wide_Subtype then
3212 Set_Equivalent_Type (Id, Equivalent_Type (T));
3215 when E_Record_Type | E_Record_Subtype =>
3216 Set_Ekind (Id, E_Record_Subtype);
3218 if Ekind (T) = E_Record_Subtype
3219 and then Present (Cloned_Subtype (T))
3221 Set_Cloned_Subtype (Id, Cloned_Subtype (T));
3223 Set_Cloned_Subtype (Id, T);
3226 Set_First_Entity (Id, First_Entity (T));
3227 Set_Last_Entity (Id, Last_Entity (T));
3228 Set_Has_Discriminants (Id, Has_Discriminants (T));
3229 Set_Is_Constrained (Id, Is_Constrained (T));
3230 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3231 Set_Has_Unknown_Discriminants
3232 (Id, Has_Unknown_Discriminants (T));
3234 if Has_Discriminants (T) then
3235 Set_Discriminant_Constraint
3236 (Id, Discriminant_Constraint (T));
3237 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3239 elsif Has_Unknown_Discriminants (Id) then
3240 Set_Discriminant_Constraint (Id, No_Elist);
3243 if Is_Tagged_Type (T) then
3244 Set_Is_Tagged_Type (Id);
3245 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3246 Set_Primitive_Operations
3247 (Id, Primitive_Operations (T));
3248 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3250 if Is_Interface (T) then
3251 Set_Is_Interface (Id);
3252 Set_Is_Limited_Interface (Id, Is_Limited_Interface (T));
3256 when Private_Kind =>
3257 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3258 Set_Has_Discriminants (Id, Has_Discriminants (T));
3259 Set_Is_Constrained (Id, Is_Constrained (T));
3260 Set_First_Entity (Id, First_Entity (T));
3261 Set_Last_Entity (Id, Last_Entity (T));
3262 Set_Private_Dependents (Id, New_Elmt_List);
3263 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3264 Set_Has_Unknown_Discriminants
3265 (Id, Has_Unknown_Discriminants (T));
3267 if Is_Tagged_Type (T) then
3268 Set_Is_Tagged_Type (Id);
3269 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3270 Set_Primitive_Operations (Id, Primitive_Operations (T));
3271 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3274 -- In general the attributes of the subtype of a private type
3275 -- are the attributes of the partial view of parent. However,
3276 -- the full view may be a discriminated type, and the subtype
3277 -- must share the discriminant constraint to generate correct
3278 -- calls to initialization procedures.
3280 if Has_Discriminants (T) then
3281 Set_Discriminant_Constraint
3282 (Id, Discriminant_Constraint (T));
3283 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3285 elsif Present (Full_View (T))
3286 and then Has_Discriminants (Full_View (T))
3288 Set_Discriminant_Constraint
3289 (Id, Discriminant_Constraint (Full_View (T)));
3290 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3292 -- This would seem semantically correct, but apparently
3293 -- confuses the back-end (4412-009). To be explained ???
3295 -- Set_Has_Discriminants (Id);
3298 Prepare_Private_Subtype_Completion (Id, N);
3301 Set_Ekind (Id, E_Access_Subtype);
3302 Set_Is_Constrained (Id, Is_Constrained (T));
3303 Set_Is_Access_Constant
3304 (Id, Is_Access_Constant (T));
3305 Set_Directly_Designated_Type
3306 (Id, Designated_Type (T));
3307 Set_Can_Never_Be_Null (Id, Can_Never_Be_Null (T));
3309 -- A Pure library_item must not contain the declaration of a
3310 -- named access type, except within a subprogram, generic
3311 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
3313 if Comes_From_Source (Id)
3314 and then In_Pure_Unit
3315 and then not In_Subprogram_Task_Protected_Unit
3318 ("named access types not allowed in pure unit", N);
3321 when Concurrent_Kind =>
3322 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3323 Set_Corresponding_Record_Type (Id,
3324 Corresponding_Record_Type (T));
3325 Set_First_Entity (Id, First_Entity (T));
3326 Set_First_Private_Entity (Id, First_Private_Entity (T));
3327 Set_Has_Discriminants (Id, Has_Discriminants (T));
3328 Set_Is_Constrained (Id, Is_Constrained (T));
3329 Set_Is_Tagged_Type (Id, Is_Tagged_Type (T));
3330 Set_Last_Entity (Id, Last_Entity (T));
3332 if Has_Discriminants (T) then
3333 Set_Discriminant_Constraint (Id,
3334 Discriminant_Constraint (T));
3335 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3338 when E_Incomplete_Type =>
3339 if Ada_Version >= Ada_05 then
3340 Set_Ekind (Id, E_Incomplete_Subtype);
3342 -- Ada 2005 (AI-412): Decorate an incomplete subtype
3343 -- of an incomplete type visible through a limited
3346 if From_With_Type (T)
3347 and then Present (Non_Limited_View (T))
3349 Set_From_With_Type (Id);
3350 Set_Non_Limited_View (Id, Non_Limited_View (T));
3352 -- Ada 2005 (AI-412): Add the regular incomplete subtype
3353 -- to the private dependents of the original incomplete
3354 -- type for future transformation.
3357 Append_Elmt (Id, Private_Dependents (T));
3360 -- If the subtype name denotes an incomplete type an error
3361 -- was already reported by Process_Subtype.
3364 Set_Etype (Id, Any_Type);
3368 raise Program_Error;
3372 if Etype (Id) = Any_Type then
3376 -- Some common processing on all types
3378 Set_Size_Info (Id, T);
3379 Set_First_Rep_Item (Id, First_Rep_Item (T));
3383 Set_Is_Immediately_Visible (Id, True);
3384 Set_Depends_On_Private (Id, Has_Private_Component (T));
3386 if Is_Interface (T) then
3387 Set_Is_Interface (Id);
3390 if Present (Generic_Parent_Type (N))
3393 (Parent (Generic_Parent_Type (N))) /= N_Formal_Type_Declaration
3395 (Formal_Type_Definition (Parent (Generic_Parent_Type (N))))
3396 /= N_Formal_Private_Type_Definition)
3398 if Is_Tagged_Type (Id) then
3400 -- If this is a generic actual subtype for a synchronized type,
3401 -- the primitive operations are those of the corresponding record
3402 -- for which there is a separate subtype declaration.
3404 if Is_Concurrent_Type (Id) then
3406 elsif Is_Class_Wide_Type (Id) then
3407 Derive_Subprograms (Generic_Parent_Type (N), Id, Etype (T));
3409 Derive_Subprograms (Generic_Parent_Type (N), Id, T);
3412 elsif Scope (Etype (Id)) /= Standard_Standard then
3413 Derive_Subprograms (Generic_Parent_Type (N), Id);
3417 if Is_Private_Type (T)
3418 and then Present (Full_View (T))
3420 Conditional_Delay (Id, Full_View (T));
3422 -- The subtypes of components or subcomponents of protected types
3423 -- do not need freeze nodes, which would otherwise appear in the
3424 -- wrong scope (before the freeze node for the protected type). The
3425 -- proper subtypes are those of the subcomponents of the corresponding
3428 elsif Ekind (Scope (Id)) /= E_Protected_Type
3429 and then Present (Scope (Scope (Id))) -- error defense!
3430 and then Ekind (Scope (Scope (Id))) /= E_Protected_Type
3432 Conditional_Delay (Id, T);
3435 -- Check that constraint_error is raised for a scalar subtype
3436 -- indication when the lower or upper bound of a non-null range
3437 -- lies outside the range of the type mark.
3439 if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then
3440 if Is_Scalar_Type (Etype (Id))
3441 and then Scalar_Range (Id) /=
3442 Scalar_Range (Etype (Subtype_Mark
3443 (Subtype_Indication (N))))
3447 Etype (Subtype_Mark (Subtype_Indication (N))));
3449 elsif Is_Array_Type (Etype (Id))
3450 and then Present (First_Index (Id))
3452 -- This really should be a subprogram that finds the indications
3455 if ((Nkind (First_Index (Id)) = N_Identifier
3456 and then Ekind (Entity (First_Index (Id))) in Scalar_Kind)
3457 or else Nkind (First_Index (Id)) = N_Subtype_Indication)
3459 Nkind (Scalar_Range (Etype (First_Index (Id)))) = N_Range
3462 Target_Typ : constant Entity_Id :=
3465 (Subtype_Mark (Subtype_Indication (N)))));
3469 (Scalar_Range (Etype (First_Index (Id))),
3471 Etype (First_Index (Id)),
3472 Defining_Identifier (N));
3478 Sloc (Defining_Identifier (N)));
3484 Check_Eliminated (Id);
3485 end Analyze_Subtype_Declaration;
3487 --------------------------------
3488 -- Analyze_Subtype_Indication --
3489 --------------------------------
3491 procedure Analyze_Subtype_Indication (N : Node_Id) is
3492 T : constant Entity_Id := Subtype_Mark (N);
3493 R : constant Node_Id := Range_Expression (Constraint (N));
3500 Set_Etype (N, Etype (R));
3501 Resolve (R, Entity (T));
3503 Set_Error_Posted (R);
3504 Set_Error_Posted (T);
3506 end Analyze_Subtype_Indication;
3508 ------------------------------
3509 -- Analyze_Type_Declaration --
3510 ------------------------------
3512 procedure Analyze_Type_Declaration (N : Node_Id) is
3513 Def : constant Node_Id := Type_Definition (N);
3514 Def_Id : constant Entity_Id := Defining_Identifier (N);
3518 Is_Remote : constant Boolean :=
3519 (Is_Remote_Types (Current_Scope)
3520 or else Is_Remote_Call_Interface (Current_Scope))
3521 and then not (In_Private_Part (Current_Scope)
3522 or else In_Package_Body (Current_Scope));
3524 procedure Check_Ops_From_Incomplete_Type;
3525 -- If there is a tagged incomplete partial view of the type, transfer
3526 -- its operations to the full view, and indicate that the type of the
3527 -- controlling parameter (s) is this full view.
3529 ------------------------------------
3530 -- Check_Ops_From_Incomplete_Type --
3531 ------------------------------------
3533 procedure Check_Ops_From_Incomplete_Type is
3540 and then Ekind (Prev) = E_Incomplete_Type
3541 and then Is_Tagged_Type (Prev)
3542 and then Is_Tagged_Type (T)
3544 Elmt := First_Elmt (Primitive_Operations (Prev));
3545 while Present (Elmt) loop
3547 Prepend_Elmt (Op, Primitive_Operations (T));
3549 Formal := First_Formal (Op);
3550 while Present (Formal) loop
3551 if Etype (Formal) = Prev then
3552 Set_Etype (Formal, T);
3555 Next_Formal (Formal);
3558 if Etype (Op) = Prev then
3565 end Check_Ops_From_Incomplete_Type;
3567 -- Start of processing for Analyze_Type_Declaration
3570 Prev := Find_Type_Name (N);
3572 -- The full view, if present, now points to the current type
3574 -- Ada 2005 (AI-50217): If the type was previously decorated when
3575 -- imported through a LIMITED WITH clause, it appears as incomplete
3576 -- but has no full view.
3577 -- If the incomplete view is tagged, a class_wide type has been
3578 -- created already. Use it for the full view as well, to prevent
3579 -- multiple incompatible class-wide types that may be created for
3580 -- self-referential anonymous access components.
3582 if Ekind (Prev) = E_Incomplete_Type
3583 and then Present (Full_View (Prev))
3585 T := Full_View (Prev);
3587 if Is_Tagged_Type (Prev)
3588 and then Present (Class_Wide_Type (Prev))
3590 Set_Ekind (T, Ekind (Prev)); -- will be reset later
3591 Set_Class_Wide_Type (T, Class_Wide_Type (Prev));
3592 Set_Etype (Class_Wide_Type (T), T);
3599 Set_Is_Pure (T, Is_Pure (Current_Scope));
3601 -- We set the flag Is_First_Subtype here. It is needed to set the
3602 -- corresponding flag for the Implicit class-wide-type created
3603 -- during tagged types processing.
3605 Set_Is_First_Subtype (T, True);
3607 -- Only composite types other than array types are allowed to have
3612 -- For derived types, the rule will be checked once we've figured
3613 -- out the parent type.
3615 when N_Derived_Type_Definition =>
3618 -- For record types, discriminants are allowed
3620 when N_Record_Definition =>
3624 if Present (Discriminant_Specifications (N)) then
3626 ("elementary or array type cannot have discriminants",
3628 (First (Discriminant_Specifications (N))));
3632 -- Elaborate the type definition according to kind, and generate
3633 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3634 -- already done (this happens during the reanalysis that follows a call
3635 -- to the high level optimizer).
3637 if not Analyzed (T) then
3642 when N_Access_To_Subprogram_Definition =>
3643 Access_Subprogram_Declaration (T, Def);
3645 -- If this is a remote access to subprogram, we must create the
3646 -- equivalent fat pointer type, and related subprograms.
3649 Process_Remote_AST_Declaration (N);
3652 -- Validate categorization rule against access type declaration
3653 -- usually a violation in Pure unit, Shared_Passive unit.
3655 Validate_Access_Type_Declaration (T, N);
3657 when N_Access_To_Object_Definition =>
3658 Access_Type_Declaration (T, Def);
3660 -- Validate categorization rule against access type declaration
3661 -- usually a violation in Pure unit, Shared_Passive unit.
3663 Validate_Access_Type_Declaration (T, N);
3665 -- If we are in a Remote_Call_Interface package and define
3666 -- a RACW, Read and Write attribute must be added.
3669 and then Is_Remote_Access_To_Class_Wide_Type (Def_Id)
3671 Add_RACW_Features (Def_Id);
3674 -- Set no strict aliasing flag if config pragma seen
3676 if Opt.No_Strict_Aliasing then
3677 Set_No_Strict_Aliasing (Base_Type (Def_Id));
3680 when N_Array_Type_Definition =>
3681 Array_Type_Declaration (T, Def);
3683 when N_Derived_Type_Definition =>
3684 Derived_Type_Declaration (T, N, T /= Def_Id);
3686 when N_Enumeration_Type_Definition =>
3687 Enumeration_Type_Declaration (T, Def);
3689 when N_Floating_Point_Definition =>
3690 Floating_Point_Type_Declaration (T, Def);
3692 when N_Decimal_Fixed_Point_Definition =>
3693 Decimal_Fixed_Point_Type_Declaration (T, Def);
3695 when N_Ordinary_Fixed_Point_Definition =>
3696 Ordinary_Fixed_Point_Type_Declaration (T, Def);
3698 when N_Signed_Integer_Type_Definition =>
3699 Signed_Integer_Type_Declaration (T, Def);
3701 when N_Modular_Type_Definition =>
3702 Modular_Type_Declaration (T, Def);
3704 when N_Record_Definition =>
3705 Record_Type_Declaration (T, N, Prev);
3708 raise Program_Error;
3713 if Etype (T) = Any_Type then
3717 -- Some common processing for all types
3719 Set_Depends_On_Private (T, Has_Private_Component (T));
3720 Check_Ops_From_Incomplete_Type;
3722 -- Both the declared entity, and its anonymous base type if one
3723 -- was created, need freeze nodes allocated.
3726 B : constant Entity_Id := Base_Type (T);
3729 -- In the case where the base type is different from the first
3730 -- subtype, we pre-allocate a freeze node, and set the proper link
3731 -- to the first subtype. Freeze_Entity will use this preallocated
3732 -- freeze node when it freezes the entity.
3735 Ensure_Freeze_Node (B);
3736 Set_First_Subtype_Link (Freeze_Node (B), T);
3739 if not From_With_Type (T) then
3740 Set_Has_Delayed_Freeze (T);
3744 -- Case of T is the full declaration of some private type which has
3745 -- been swapped in Defining_Identifier (N).
3747 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3748 Process_Full_View (N, T, Def_Id);
3750 -- Record the reference. The form of this is a little strange,
3751 -- since the full declaration has been swapped in. So the first
3752 -- parameter here represents the entity to which a reference is
3753 -- made which is the "real" entity, i.e. the one swapped in,
3754 -- and the second parameter provides the reference location.
3756 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3757 -- since we don't want a complaint about the full type being an
3758 -- unwanted reference to the private type
3761 B : constant Boolean := Has_Pragma_Unreferenced (T);
3763 Set_Has_Pragma_Unreferenced (T, False);
3764 Generate_Reference (T, T, 'c');
3765 Set_Has_Pragma_Unreferenced (T, B);
3768 Set_Completion_Referenced (Def_Id);
3770 -- For completion of incomplete type, process incomplete dependents
3771 -- and always mark the full type as referenced (it is the incomplete
3772 -- type that we get for any real reference).
3774 elsif Ekind (Prev) = E_Incomplete_Type then
3775 Process_Incomplete_Dependents (N, T, Prev);
3776 Generate_Reference (Prev, Def_Id, 'c');
3777 Set_Completion_Referenced (Def_Id);
3779 -- If not private type or incomplete type completion, this is a real
3780 -- definition of a new entity, so record it.
3783 Generate_Definition (Def_Id);
3786 Check_Eliminated (Def_Id);
3787 end Analyze_Type_Declaration;
3789 --------------------------
3790 -- Analyze_Variant_Part --
3791 --------------------------
3793 procedure Analyze_Variant_Part (N : Node_Id) is
3795 procedure Non_Static_Choice_Error (Choice : Node_Id);
3796 -- Error routine invoked by the generic instantiation below when
3797 -- the variant part has a non static choice.
3799 procedure Process_Declarations (Variant : Node_Id);
3800 -- Analyzes all the declarations associated with a Variant.
3801 -- Needed by the generic instantiation below.
3803 package Variant_Choices_Processing is new
3804 Generic_Choices_Processing
3805 (Get_Alternatives => Variants,
3806 Get_Choices => Discrete_Choices,
3807 Process_Empty_Choice => No_OP,
3808 Process_Non_Static_Choice => Non_Static_Choice_Error,
3809 Process_Associated_Node => Process_Declarations);
3810 use Variant_Choices_Processing;
3811 -- Instantiation of the generic choice processing package
3813 -----------------------------
3814 -- Non_Static_Choice_Error --
3815 -----------------------------
3817 procedure Non_Static_Choice_Error (Choice : Node_Id) is
3819 Flag_Non_Static_Expr
3820 ("choice given in variant part is not static!", Choice);
3821 end Non_Static_Choice_Error;
3823 --------------------------
3824 -- Process_Declarations --
3825 --------------------------
3827 procedure Process_Declarations (Variant : Node_Id) is
3829 if not Null_Present (Component_List (Variant)) then
3830 Analyze_Declarations (Component_Items (Component_List (Variant)));
3832 if Present (Variant_Part (Component_List (Variant))) then
3833 Analyze (Variant_Part (Component_List (Variant)));
3836 end Process_Declarations;
3838 -- Variables local to Analyze_Case_Statement
3840 Discr_Name : Node_Id;
3841 Discr_Type : Entity_Id;
3843 Case_Table : Choice_Table_Type (1 .. Number_Of_Choices (N));
3845 Dont_Care : Boolean;
3846 Others_Present : Boolean := False;
3848 -- Start of processing for Analyze_Variant_Part
3851 Discr_Name := Name (N);
3852 Analyze (Discr_Name);
3854 if Etype (Discr_Name) = Any_Type then
3856 -- Prevent cascaded errors
3860 elsif Ekind (Entity (Discr_Name)) /= E_Discriminant then
3861 Error_Msg_N ("invalid discriminant name in variant part", Discr_Name);
3864 Discr_Type := Etype (Entity (Discr_Name));
3866 if not Is_Discrete_Type (Discr_Type) then
3868 ("discriminant in a variant part must be of a discrete type",
3873 -- Call the instantiated Analyze_Choices which does the rest of the work
3876 (N, Discr_Type, Case_Table, Last_Choice, Dont_Care, Others_Present);
3877 end Analyze_Variant_Part;
3879 ----------------------------
3880 -- Array_Type_Declaration --
3881 ----------------------------
3883 procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id) is
3884 Component_Def : constant Node_Id := Component_Definition (Def);
3885 Element_Type : Entity_Id;
3886 Implicit_Base : Entity_Id;
3888 Related_Id : Entity_Id := Empty;
3890 P : constant Node_Id := Parent (Def);
3894 if Nkind (Def) = N_Constrained_Array_Definition then
3895 Index := First (Discrete_Subtype_Definitions (Def));
3897 Index := First (Subtype_Marks (Def));
3900 -- Find proper names for the implicit types which may be public.
3901 -- in case of anonymous arrays we use the name of the first object
3902 -- of that type as prefix.
3905 Related_Id := Defining_Identifier (P);
3911 while Present (Index) loop
3914 -- Add a subtype declaration for each index of private array type
3915 -- declaration whose etype is also private. For example:
3918 -- type Index is private;
3920 -- type Table is array (Index) of ...
3923 -- This is currently required by the expander to generate the
3924 -- internally generated equality subprogram of records with variant
3925 -- parts in which the etype of some component is such private type.
3927 if Ekind (Current_Scope) = E_Package
3928 and then In_Private_Part (Current_Scope)
3929 and then Has_Private_Declaration (Etype (Index))
3932 Loc : constant Source_Ptr := Sloc (Def);
3938 Make_Defining_Identifier (Loc,
3939 Chars => New_Internal_Name ('T'));
3940 Set_Is_Internal (New_E);
3943 Make_Subtype_Declaration (Loc,
3944 Defining_Identifier => New_E,
3945 Subtype_Indication =>
3946 New_Occurrence_Of (Etype (Index), Loc));
3948 Insert_Before (Parent (Def), Decl);
3950 Set_Etype (Index, New_E);
3952 -- If the index is a range the Entity attribute is not
3953 -- available. Example:
3956 -- type T is private;
3958 -- type T is new Natural;
3959 -- Table : array (T(1) .. T(10)) of Boolean;
3962 if Nkind (Index) /= N_Range then
3963 Set_Entity (Index, New_E);
3968 Make_Index (Index, P, Related_Id, Nb_Index);
3970 Nb_Index := Nb_Index + 1;
3973 -- Process subtype indication if one is present
3975 if Present (Subtype_Indication (Component_Def)) then
3978 (Subtype_Indication (Component_Def), P, Related_Id, 'C');
3980 -- Ada 2005 (AI-230): Access Definition case
3982 else pragma Assert (Present (Access_Definition (Component_Def)));
3984 -- Indicate that the anonymous access type is created by the
3985 -- array type declaration.
3987 Element_Type := Access_Definition
3989 N => Access_Definition (Component_Def));
3990 Set_Is_Local_Anonymous_Access (Element_Type);
3992 -- Propagate the parent. This field is needed if we have to generate
3993 -- the master_id associated with an anonymous access to task type
3994 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
3996 Set_Parent (Element_Type, Parent (T));
3998 -- Ada 2005 (AI-230): In case of components that are anonymous
3999 -- access types the level of accessibility depends on the enclosing
4002 Set_Scope (Element_Type, Current_Scope); -- Ada 2005 (AI-230)
4004 -- Ada 2005 (AI-254)
4007 CD : constant Node_Id :=
4008 Access_To_Subprogram_Definition
4009 (Access_Definition (Component_Def));
4011 if Present (CD) and then Protected_Present (CD) then
4013 Replace_Anonymous_Access_To_Protected_Subprogram (Def);
4018 -- Constrained array case
4021 T := Create_Itype (E_Void, P, Related_Id, 'T');
4024 if Nkind (Def) = N_Constrained_Array_Definition then
4026 -- Establish Implicit_Base as unconstrained base type
4028 Implicit_Base := Create_Itype (E_Array_Type, P, Related_Id, 'B');
4030 Init_Size_Align (Implicit_Base);
4031 Set_Etype (Implicit_Base, Implicit_Base);
4032 Set_Scope (Implicit_Base, Current_Scope);
4033 Set_Has_Delayed_Freeze (Implicit_Base);
4035 -- The constrained array type is a subtype of the unconstrained one
4037 Set_Ekind (T, E_Array_Subtype);
4038 Init_Size_Align (T);
4039 Set_Etype (T, Implicit_Base);
4040 Set_Scope (T, Current_Scope);
4041 Set_Is_Constrained (T, True);
4042 Set_First_Index (T, First (Discrete_Subtype_Definitions (Def)));
4043 Set_Has_Delayed_Freeze (T);
4045 -- Complete setup of implicit base type
4047 Set_First_Index (Implicit_Base, First_Index (T));
4048 Set_Component_Type (Implicit_Base, Element_Type);
4049 Set_Has_Task (Implicit_Base, Has_Task (Element_Type));
4050 Set_Component_Size (Implicit_Base, Uint_0);
4051 Set_Packed_Array_Type (Implicit_Base, Empty);
4052 Set_Has_Controlled_Component
4053 (Implicit_Base, Has_Controlled_Component
4055 or else Is_Controlled
4057 Set_Finalize_Storage_Only
4058 (Implicit_Base, Finalize_Storage_Only
4061 -- Unconstrained array case
4064 Set_Ekind (T, E_Array_Type);
4065 Init_Size_Align (T);
4067 Set_Scope (T, Current_Scope);
4068 Set_Component_Size (T, Uint_0);
4069 Set_Is_Constrained (T, False);
4070 Set_First_Index (T, First (Subtype_Marks (Def)));
4071 Set_Has_Delayed_Freeze (T, True);
4072 Set_Has_Task (T, Has_Task (Element_Type));
4073 Set_Has_Controlled_Component (T, Has_Controlled_Component
4076 Is_Controlled (Element_Type));
4077 Set_Finalize_Storage_Only (T, Finalize_Storage_Only
4081 -- Common attributes for both cases
4083 Set_Component_Type (Base_Type (T), Element_Type);
4084 Set_Packed_Array_Type (T, Empty);
4086 if Aliased_Present (Component_Definition (Def)) then
4087 Set_Has_Aliased_Components (Etype (T));
4090 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
4091 -- array type to ensure that objects of this type are initialized.
4093 if Ada_Version >= Ada_05
4094 and then Can_Never_Be_Null (Element_Type)
4096 Set_Can_Never_Be_Null (T);
4098 if Null_Exclusion_Present (Component_Definition (Def))
4100 -- No need to check itypes because in their case this check
4101 -- was done at their point of creation
4103 and then not Is_Itype (Element_Type)
4106 ("`NOT NULL` not allowed (null already excluded)",
4107 Subtype_Indication (Component_Definition (Def)));
4111 Priv := Private_Component (Element_Type);
4113 if Present (Priv) then
4115 -- Check for circular definitions
4117 if Priv = Any_Type then
4118 Set_Component_Type (Etype (T), Any_Type);
4120 -- There is a gap in the visibility of operations on the composite
4121 -- type only if the component type is defined in a different scope.
4123 elsif Scope (Priv) = Current_Scope then
4126 elsif Is_Limited_Type (Priv) then
4127 Set_Is_Limited_Composite (Etype (T));
4128 Set_Is_Limited_Composite (T);
4130 Set_Is_Private_Composite (Etype (T));
4131 Set_Is_Private_Composite (T);
4135 -- A syntax error in the declaration itself may lead to an empty
4136 -- index list, in which case do a minimal patch.
4138 if No (First_Index (T)) then
4139 Error_Msg_N ("missing index definition in array type declaration", T);
4142 Indices : constant List_Id :=
4143 New_List (New_Occurrence_Of (Any_Id, Sloc (T)));
4145 Set_Discrete_Subtype_Definitions (Def, Indices);
4146 Set_First_Index (T, First (Indices));
4151 -- Create a concatenation operator for the new type. Internal array
4152 -- types created for packed entities do not need such, they are
4153 -- compatible with the user-defined type.
4155 if Number_Dimensions (T) = 1
4156 and then not Is_Packed_Array_Type (T)
4158 New_Concatenation_Op (T);
4161 -- In the case of an unconstrained array the parser has already verified
4162 -- that all the indices are unconstrained but we still need to make sure
4163 -- that the element type is constrained.
4165 if Is_Indefinite_Subtype (Element_Type) then
4167 ("unconstrained element type in array declaration",
4168 Subtype_Indication (Component_Def));
4170 elsif Is_Abstract_Type (Element_Type) then
4172 ("the type of a component cannot be abstract",
4173 Subtype_Indication (Component_Def));
4176 end Array_Type_Declaration;
4178 ------------------------------------------------------
4179 -- Replace_Anonymous_Access_To_Protected_Subprogram --
4180 ------------------------------------------------------
4182 function Replace_Anonymous_Access_To_Protected_Subprogram
4183 (N : Node_Id) return Entity_Id
4185 Loc : constant Source_Ptr := Sloc (N);
4187 Curr_Scope : constant Scope_Stack_Entry :=
4188 Scope_Stack.Table (Scope_Stack.Last);
4190 Anon : constant Entity_Id :=
4191 Make_Defining_Identifier (Loc,
4192 Chars => New_Internal_Name ('S'));
4200 Set_Is_Internal (Anon);
4203 when N_Component_Declaration |
4204 N_Unconstrained_Array_Definition |
4205 N_Constrained_Array_Definition =>
4206 Comp := Component_Definition (N);
4207 Acc := Access_Definition (Comp);
4209 when N_Discriminant_Specification =>
4210 Comp := Discriminant_Type (N);
4213 when N_Parameter_Specification =>
4214 Comp := Parameter_Type (N);
4217 when N_Access_Function_Definition =>
4218 Comp := Result_Definition (N);
4221 when N_Object_Declaration =>
4222 Comp := Object_Definition (N);
4226 raise Program_Error;
4229 Decl := Make_Full_Type_Declaration (Loc,
4230 Defining_Identifier => Anon,
4232 Copy_Separate_Tree (Access_To_Subprogram_Definition (Acc)));
4234 Mark_Rewrite_Insertion (Decl);
4236 -- Insert the new declaration in the nearest enclosing scope
4239 while Present (P) and then not Has_Declarations (P) loop
4243 pragma Assert (Present (P));
4245 if Nkind (P) = N_Package_Specification then
4246 Prepend (Decl, Visible_Declarations (P));
4248 Prepend (Decl, Declarations (P));
4251 -- Replace the anonymous type with an occurrence of the new declaration.
4252 -- In all cases the rewritten node does not have the null-exclusion
4253 -- attribute because (if present) it was already inherited by the
4254 -- anonymous entity (Anon). Thus, in case of components we do not
4255 -- inherit this attribute.
4257 if Nkind (N) = N_Parameter_Specification then
4258 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4259 Set_Etype (Defining_Identifier (N), Anon);
4260 Set_Null_Exclusion_Present (N, False);
4262 elsif Nkind (N) = N_Object_Declaration then
4263 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4264 Set_Etype (Defining_Identifier (N), Anon);
4266 elsif Nkind (N) = N_Access_Function_Definition then
4267 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4271 Make_Component_Definition (Loc,
4272 Subtype_Indication => New_Occurrence_Of (Anon, Loc)));
4275 Mark_Rewrite_Insertion (Comp);
4277 -- Temporarily remove the current scope from the stack to add the new
4278 -- declarations to the enclosing scope
4280 if Nkind (N) = N_Object_Declaration
4281 or else Nkind (N) = N_Access_Function_Definition
4286 Scope_Stack.Decrement_Last;
4288 Set_Is_Itype (Anon);
4289 Scope_Stack.Append (Curr_Scope);
4292 Set_Ekind (Anon, E_Anonymous_Access_Protected_Subprogram_Type);
4294 end Replace_Anonymous_Access_To_Protected_Subprogram;
4296 -------------------------------
4297 -- Build_Derived_Access_Type --
4298 -------------------------------
4300 procedure Build_Derived_Access_Type
4302 Parent_Type : Entity_Id;
4303 Derived_Type : Entity_Id)
4305 S : constant Node_Id := Subtype_Indication (Type_Definition (N));
4307 Desig_Type : Entity_Id;
4309 Discr_Con_Elist : Elist_Id;
4310 Discr_Con_El : Elmt_Id;
4314 -- Set the designated type so it is available in case this is an access
4315 -- to a self-referential type, e.g. a standard list type with a next
4316 -- pointer. Will be reset after subtype is built.
4318 Set_Directly_Designated_Type
4319 (Derived_Type, Designated_Type (Parent_Type));
4321 Subt := Process_Subtype (S, N);
4323 if Nkind (S) /= N_Subtype_Indication
4324 and then Subt /= Base_Type (Subt)
4326 Set_Ekind (Derived_Type, E_Access_Subtype);
4329 if Ekind (Derived_Type) = E_Access_Subtype then
4331 Pbase : constant Entity_Id := Base_Type (Parent_Type);
4332 Ibase : constant Entity_Id :=
4333 Create_Itype (Ekind (Pbase), N, Derived_Type, 'B');
4334 Svg_Chars : constant Name_Id := Chars (Ibase);
4335 Svg_Next_E : constant Entity_Id := Next_Entity (Ibase);
4338 Copy_Node (Pbase, Ibase);
4340 Set_Chars (Ibase, Svg_Chars);
4341 Set_Next_Entity (Ibase, Svg_Next_E);
4342 Set_Sloc (Ibase, Sloc (Derived_Type));
4343 Set_Scope (Ibase, Scope (Derived_Type));
4344 Set_Freeze_Node (Ibase, Empty);
4345 Set_Is_Frozen (Ibase, False);
4346 Set_Comes_From_Source (Ibase, False);
4347 Set_Is_First_Subtype (Ibase, False);
4349 Set_Etype (Ibase, Pbase);
4350 Set_Etype (Derived_Type, Ibase);
4354 Set_Directly_Designated_Type
4355 (Derived_Type, Designated_Type (Subt));
4357 Set_Is_Constrained (Derived_Type, Is_Constrained (Subt));
4358 Set_Is_Access_Constant (Derived_Type, Is_Access_Constant (Parent_Type));
4359 Set_Size_Info (Derived_Type, Parent_Type);
4360 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
4361 Set_Depends_On_Private (Derived_Type,
4362 Has_Private_Component (Derived_Type));
4363 Conditional_Delay (Derived_Type, Subt);
4365 -- Ada 2005 (AI-231). Set the null-exclusion attribute
4367 if Null_Exclusion_Present (Type_Definition (N))
4368 or else Can_Never_Be_Null (Parent_Type)
4370 Set_Can_Never_Be_Null (Derived_Type);
4373 -- Note: we do not copy the Storage_Size_Variable, since we always go to
4374 -- the root type for this information.
4376 -- Apply range checks to discriminants for derived record case
4377 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
4379 Desig_Type := Designated_Type (Derived_Type);
4380 if Is_Composite_Type (Desig_Type)
4381 and then (not Is_Array_Type (Desig_Type))
4382 and then Has_Discriminants (Desig_Type)
4383 and then Base_Type (Desig_Type) /= Desig_Type
4385 Discr_Con_Elist := Discriminant_Constraint (Desig_Type);
4386 Discr_Con_El := First_Elmt (Discr_Con_Elist);
4388 Discr := First_Discriminant (Base_Type (Desig_Type));
4389 while Present (Discr_Con_El) loop
4390 Apply_Range_Check (Node (Discr_Con_El), Etype (Discr));
4391 Next_Elmt (Discr_Con_El);
4392 Next_Discriminant (Discr);
4395 end Build_Derived_Access_Type;
4397 ------------------------------
4398 -- Build_Derived_Array_Type --
4399 ------------------------------
4401 procedure Build_Derived_Array_Type
4403 Parent_Type : Entity_Id;
4404 Derived_Type : Entity_Id)
4406 Loc : constant Source_Ptr := Sloc (N);
4407 Tdef : constant Node_Id := Type_Definition (N);
4408 Indic : constant Node_Id := Subtype_Indication (Tdef);
4409 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
4410 Implicit_Base : Entity_Id;
4411 New_Indic : Node_Id;
4413 procedure Make_Implicit_Base;
4414 -- If the parent subtype is constrained, the derived type is a subtype
4415 -- of an implicit base type derived from the parent base.
4417 ------------------------
4418 -- Make_Implicit_Base --
4419 ------------------------
4421 procedure Make_Implicit_Base is
4424 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
4426 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
4427 Set_Etype (Implicit_Base, Parent_Base);
4429 Copy_Array_Subtype_Attributes (Implicit_Base, Parent_Base);
4430 Copy_Array_Base_Type_Attributes (Implicit_Base, Parent_Base);
4432 Set_Has_Delayed_Freeze (Implicit_Base, True);
4433 end Make_Implicit_Base;
4435 -- Start of processing for Build_Derived_Array_Type
4438 if not Is_Constrained (Parent_Type) then
4439 if Nkind (Indic) /= N_Subtype_Indication then
4440 Set_Ekind (Derived_Type, E_Array_Type);
4442 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4443 Copy_Array_Base_Type_Attributes (Derived_Type, Parent_Type);
4445 Set_Has_Delayed_Freeze (Derived_Type, True);
4449 Set_Etype (Derived_Type, Implicit_Base);
4452 Make_Subtype_Declaration (Loc,
4453 Defining_Identifier => Derived_Type,
4454 Subtype_Indication =>
4455 Make_Subtype_Indication (Loc,
4456 Subtype_Mark => New_Reference_To (Implicit_Base, Loc),
4457 Constraint => Constraint (Indic)));
4459 Rewrite (N, New_Indic);
4464 if Nkind (Indic) /= N_Subtype_Indication then
4467 Set_Ekind (Derived_Type, Ekind (Parent_Type));
4468 Set_Etype (Derived_Type, Implicit_Base);
4469 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4472 Error_Msg_N ("illegal constraint on constrained type", Indic);
4476 -- If parent type is not a derived type itself, and is declared in
4477 -- closed scope (e.g. a subprogram), then we must explicitly introduce
4478 -- the new type's concatenation operator since Derive_Subprograms
4479 -- will not inherit the parent's operator. If the parent type is
4480 -- unconstrained, the operator is of the unconstrained base type.
4482 if Number_Dimensions (Parent_Type) = 1
4483 and then not Is_Limited_Type (Parent_Type)
4484 and then not Is_Derived_Type (Parent_Type)
4485 and then not Is_Package_Or_Generic_Package
4486 (Scope (Base_Type (Parent_Type)))
4488 if not Is_Constrained (Parent_Type)
4489 and then Is_Constrained (Derived_Type)
4491 New_Concatenation_Op (Implicit_Base);
4493 New_Concatenation_Op (Derived_Type);
4496 end Build_Derived_Array_Type;
4498 -----------------------------------
4499 -- Build_Derived_Concurrent_Type --
4500 -----------------------------------
4502 procedure Build_Derived_Concurrent_Type
4504 Parent_Type : Entity_Id;
4505 Derived_Type : Entity_Id)
4507 D_Constraint : Node_Id;
4508 Disc_Spec : Node_Id;
4509 Old_Disc : Entity_Id;
4510 New_Disc : Entity_Id;
4512 Constraint_Present : constant Boolean :=
4513 Nkind (Subtype_Indication (Type_Definition (N)))
4514 = N_Subtype_Indication;
4517 Set_Stored_Constraint (Derived_Type, No_Elist);
4519 if Is_Task_Type (Parent_Type) then
4520 Set_Storage_Size_Variable (Derived_Type,
4521 Storage_Size_Variable (Parent_Type));
4524 if Present (Discriminant_Specifications (N)) then
4525 Push_Scope (Derived_Type);
4526 Check_Or_Process_Discriminants (N, Derived_Type);
4529 elsif Constraint_Present then
4531 -- Build constrained subtype and derive from it
4534 Loc : constant Source_Ptr := Sloc (N);
4535 Anon : constant Entity_Id :=
4536 Make_Defining_Identifier (Loc,
4537 New_External_Name (Chars (Derived_Type), 'T'));
4542 Make_Subtype_Declaration (Loc,
4543 Defining_Identifier => Anon,
4544 Subtype_Indication =>
4545 Subtype_Indication (Type_Definition (N)));
4546 Insert_Before (N, Decl);
4549 Rewrite (Subtype_Indication (Type_Definition (N)),
4550 New_Occurrence_Of (Anon, Loc));
4551 Set_Analyzed (Derived_Type, False);
4557 -- All attributes are inherited from parent. In particular,
4558 -- entries and the corresponding record type are the same.
4559 -- Discriminants may be renamed, and must be treated separately.
4561 Set_Has_Discriminants
4562 (Derived_Type, Has_Discriminants (Parent_Type));
4563 Set_Corresponding_Record_Type
4564 (Derived_Type, Corresponding_Record_Type (Parent_Type));
4566 if Constraint_Present then
4567 if not Has_Discriminants (Parent_Type) then
4568 Error_Msg_N ("untagged parent must have discriminants", N);
4570 elsif Present (Discriminant_Specifications (N)) then
4572 -- Verify that new discriminants are used to constrain old ones
4577 (Constraint (Subtype_Indication (Type_Definition (N)))));
4579 Old_Disc := First_Discriminant (Parent_Type);
4580 New_Disc := First_Discriminant (Derived_Type);
4581 Disc_Spec := First (Discriminant_Specifications (N));
4582 while Present (Old_Disc) and then Present (Disc_Spec) loop
4583 if Nkind (Discriminant_Type (Disc_Spec)) /=
4586 Analyze (Discriminant_Type (Disc_Spec));
4588 if not Subtypes_Statically_Compatible (
4589 Etype (Discriminant_Type (Disc_Spec)),
4593 ("not statically compatible with parent discriminant",
4594 Discriminant_Type (Disc_Spec));
4598 if Nkind (D_Constraint) = N_Identifier
4599 and then Chars (D_Constraint) /=
4600 Chars (Defining_Identifier (Disc_Spec))
4602 Error_Msg_N ("new discriminants must constrain old ones",
4605 Set_Corresponding_Discriminant (New_Disc, Old_Disc);
4608 Next_Discriminant (Old_Disc);
4609 Next_Discriminant (New_Disc);
4613 if Present (Old_Disc) or else Present (Disc_Spec) then
4614 Error_Msg_N ("discriminant mismatch in derivation", N);
4619 elsif Present (Discriminant_Specifications (N)) then
4621 ("missing discriminant constraint in untagged derivation",
4625 if Present (Discriminant_Specifications (N)) then
4626 Old_Disc := First_Discriminant (Parent_Type);
4627 while Present (Old_Disc) loop
4629 if No (Next_Entity (Old_Disc))
4630 or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant
4632 Set_Next_Entity (Last_Entity (Derived_Type),
4633 Next_Entity (Old_Disc));
4637 Next_Discriminant (Old_Disc);
4641 Set_First_Entity (Derived_Type, First_Entity (Parent_Type));
4642 if Has_Discriminants (Parent_Type) then
4643 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
4644 Set_Discriminant_Constraint (
4645 Derived_Type, Discriminant_Constraint (Parent_Type));
4649 Set_Last_Entity (Derived_Type, Last_Entity (Parent_Type));
4651 Set_Has_Completion (Derived_Type);
4652 end Build_Derived_Concurrent_Type;
4654 ------------------------------------
4655 -- Build_Derived_Enumeration_Type --
4656 ------------------------------------
4658 procedure Build_Derived_Enumeration_Type
4660 Parent_Type : Entity_Id;
4661 Derived_Type : Entity_Id)
4663 Loc : constant Source_Ptr := Sloc (N);
4664 Def : constant Node_Id := Type_Definition (N);
4665 Indic : constant Node_Id := Subtype_Indication (Def);
4666 Implicit_Base : Entity_Id;
4667 Literal : Entity_Id;
4668 New_Lit : Entity_Id;
4669 Literals_List : List_Id;
4670 Type_Decl : Node_Id;
4672 Rang_Expr : Node_Id;
4675 -- Since types Standard.Character and Standard.Wide_Character do
4676 -- not have explicit literals lists we need to process types derived
4677 -- from them specially. This is handled by Derived_Standard_Character.
4678 -- If the parent type is a generic type, there are no literals either,
4679 -- and we construct the same skeletal representation as for the generic
4682 if Root_Type (Parent_Type) = Standard_Character
4683 or else Root_Type (Parent_Type) = Standard_Wide_Character
4684 or else Root_Type (Parent_Type) = Standard_Wide_Wide_Character
4686 Derived_Standard_Character (N, Parent_Type, Derived_Type);
4688 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
4695 Make_Attribute_Reference (Loc,
4696 Attribute_Name => Name_First,
4697 Prefix => New_Reference_To (Derived_Type, Loc));
4698 Set_Etype (Lo, Derived_Type);
4701 Make_Attribute_Reference (Loc,
4702 Attribute_Name => Name_Last,
4703 Prefix => New_Reference_To (Derived_Type, Loc));
4704 Set_Etype (Hi, Derived_Type);
4706 Set_Scalar_Range (Derived_Type,
4713 -- If a constraint is present, analyze the bounds to catch
4714 -- premature usage of the derived literals.
4716 if Nkind (Indic) = N_Subtype_Indication
4717 and then Nkind (Range_Expression (Constraint (Indic))) = N_Range
4719 Analyze (Low_Bound (Range_Expression (Constraint (Indic))));
4720 Analyze (High_Bound (Range_Expression (Constraint (Indic))));
4723 -- Introduce an implicit base type for the derived type even if there
4724 -- is no constraint attached to it, since this seems closer to the
4725 -- Ada semantics. Build a full type declaration tree for the derived
4726 -- type using the implicit base type as the defining identifier. The
4727 -- build a subtype declaration tree which applies the constraint (if
4728 -- any) have it replace the derived type declaration.
4730 Literal := First_Literal (Parent_Type);
4731 Literals_List := New_List;
4732 while Present (Literal)
4733 and then Ekind (Literal) = E_Enumeration_Literal
4735 -- Literals of the derived type have the same representation as
4736 -- those of the parent type, but this representation can be
4737 -- overridden by an explicit representation clause. Indicate
4738 -- that there is no explicit representation given yet. These
4739 -- derived literals are implicit operations of the new type,
4740 -- and can be overridden by explicit ones.
4742 if Nkind (Literal) = N_Defining_Character_Literal then
4744 Make_Defining_Character_Literal (Loc, Chars (Literal));
4746 New_Lit := Make_Defining_Identifier (Loc, Chars (Literal));
4749 Set_Ekind (New_Lit, E_Enumeration_Literal);
4750 Set_Enumeration_Pos (New_Lit, Enumeration_Pos (Literal));
4751 Set_Enumeration_Rep (New_Lit, Enumeration_Rep (Literal));
4752 Set_Enumeration_Rep_Expr (New_Lit, Empty);
4753 Set_Alias (New_Lit, Literal);
4754 Set_Is_Known_Valid (New_Lit, True);
4756 Append (New_Lit, Literals_List);
4757 Next_Literal (Literal);
4761 Make_Defining_Identifier (Sloc (Derived_Type),
4762 New_External_Name (Chars (Derived_Type), 'B'));
4764 -- Indicate the proper nature of the derived type. This must be done
4765 -- before analysis of the literals, to recognize cases when a literal
4766 -- may be hidden by a previous explicit function definition (cf.
4769 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
4770 Set_Etype (Derived_Type, Implicit_Base);
4773 Make_Full_Type_Declaration (Loc,
4774 Defining_Identifier => Implicit_Base,
4775 Discriminant_Specifications => No_List,
4777 Make_Enumeration_Type_Definition (Loc, Literals_List));
4779 Mark_Rewrite_Insertion (Type_Decl);
4780 Insert_Before (N, Type_Decl);
4781 Analyze (Type_Decl);
4783 -- After the implicit base is analyzed its Etype needs to be changed
4784 -- to reflect the fact that it is derived from the parent type which
4785 -- was ignored during analysis. We also set the size at this point.
4787 Set_Etype (Implicit_Base, Parent_Type);
4789 Set_Size_Info (Implicit_Base, Parent_Type);
4790 Set_RM_Size (Implicit_Base, RM_Size (Parent_Type));
4791 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Type));
4793 Set_Has_Non_Standard_Rep
4794 (Implicit_Base, Has_Non_Standard_Rep
4796 Set_Has_Delayed_Freeze (Implicit_Base);
4798 -- Process the subtype indication including a validation check on the
4799 -- constraint, if any. If a constraint is given, its bounds must be
4800 -- implicitly converted to the new type.
4802 if Nkind (Indic) = N_Subtype_Indication then
4804 R : constant Node_Id :=
4805 Range_Expression (Constraint (Indic));
4808 if Nkind (R) = N_Range then
4809 Hi := Build_Scalar_Bound
4810 (High_Bound (R), Parent_Type, Implicit_Base);
4811 Lo := Build_Scalar_Bound
4812 (Low_Bound (R), Parent_Type, Implicit_Base);
4815 -- Constraint is a Range attribute. Replace with explicit
4816 -- mention of the bounds of the prefix, which must be a
4819 Analyze (Prefix (R));
4821 Convert_To (Implicit_Base,
4822 Make_Attribute_Reference (Loc,
4823 Attribute_Name => Name_Last,
4825 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
4828 Convert_To (Implicit_Base,
4829 Make_Attribute_Reference (Loc,
4830 Attribute_Name => Name_First,
4832 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
4839 (Type_High_Bound (Parent_Type),
4840 Parent_Type, Implicit_Base);
4843 (Type_Low_Bound (Parent_Type),
4844 Parent_Type, Implicit_Base);
4852 -- If we constructed a default range for the case where no range
4853 -- was given, then the expressions in the range must not freeze
4854 -- since they do not correspond to expressions in the source.
4856 if Nkind (Indic) /= N_Subtype_Indication then
4857 Set_Must_Not_Freeze (Lo);
4858 Set_Must_Not_Freeze (Hi);
4859 Set_Must_Not_Freeze (Rang_Expr);
4863 Make_Subtype_Declaration (Loc,
4864 Defining_Identifier => Derived_Type,
4865 Subtype_Indication =>
4866 Make_Subtype_Indication (Loc,
4867 Subtype_Mark => New_Occurrence_Of (Implicit_Base, Loc),
4869 Make_Range_Constraint (Loc,
4870 Range_Expression => Rang_Expr))));
4874 -- If pragma Discard_Names applies on the first subtype of the parent
4875 -- type, then it must be applied on this subtype as well.
4877 if Einfo.Discard_Names (First_Subtype (Parent_Type)) then
4878 Set_Discard_Names (Derived_Type);
4881 -- Apply a range check. Since this range expression doesn't have an
4882 -- Etype, we have to specifically pass the Source_Typ parameter. Is
4885 if Nkind (Indic) = N_Subtype_Indication then
4886 Apply_Range_Check (Range_Expression (Constraint (Indic)),
4888 Source_Typ => Entity (Subtype_Mark (Indic)));
4891 end Build_Derived_Enumeration_Type;
4893 --------------------------------
4894 -- Build_Derived_Numeric_Type --
4895 --------------------------------
4897 procedure Build_Derived_Numeric_Type
4899 Parent_Type : Entity_Id;
4900 Derived_Type : Entity_Id)
4902 Loc : constant Source_Ptr := Sloc (N);
4903 Tdef : constant Node_Id := Type_Definition (N);
4904 Indic : constant Node_Id := Subtype_Indication (Tdef);
4905 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
4906 No_Constraint : constant Boolean := Nkind (Indic) /=
4907 N_Subtype_Indication;
4908 Implicit_Base : Entity_Id;
4914 -- Process the subtype indication including a validation check on
4915 -- the constraint if any.
4917 Discard_Node (Process_Subtype (Indic, N));
4919 -- Introduce an implicit base type for the derived type even if there
4920 -- is no constraint attached to it, since this seems closer to the Ada
4924 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
4926 Set_Etype (Implicit_Base, Parent_Base);
4927 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
4928 Set_Size_Info (Implicit_Base, Parent_Base);
4929 Set_RM_Size (Implicit_Base, RM_Size (Parent_Base));
4930 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Base));
4931 Set_Parent (Implicit_Base, Parent (Derived_Type));
4933 if Is_Discrete_Or_Fixed_Point_Type (Parent_Base) then
4934 Set_RM_Size (Implicit_Base, RM_Size (Parent_Base));
4937 Set_Has_Delayed_Freeze (Implicit_Base);
4939 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
4940 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
4942 Set_Scalar_Range (Implicit_Base,
4947 if Has_Infinities (Parent_Base) then
4948 Set_Includes_Infinities (Scalar_Range (Implicit_Base));
4951 -- The Derived_Type, which is the entity of the declaration, is a
4952 -- subtype of the implicit base. Its Ekind is a subtype, even in the
4953 -- absence of an explicit constraint.
4955 Set_Etype (Derived_Type, Implicit_Base);
4957 -- If we did not have a constraint, then the Ekind is set from the
4958 -- parent type (otherwise Process_Subtype has set the bounds)
4960 if No_Constraint then
4961 Set_Ekind (Derived_Type, Subtype_Kind (Ekind (Parent_Type)));
4964 -- If we did not have a range constraint, then set the range from the
4965 -- parent type. Otherwise, the call to Process_Subtype has set the
4969 or else not Has_Range_Constraint (Indic)
4971 Set_Scalar_Range (Derived_Type,
4973 Low_Bound => New_Copy_Tree (Type_Low_Bound (Parent_Type)),
4974 High_Bound => New_Copy_Tree (Type_High_Bound (Parent_Type))));
4975 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
4977 if Has_Infinities (Parent_Type) then
4978 Set_Includes_Infinities (Scalar_Range (Derived_Type));
4982 -- Set remaining type-specific fields, depending on numeric type
4984 if Is_Modular_Integer_Type (Parent_Type) then
4985 Set_Modulus (Implicit_Base, Modulus (Parent_Base));
4987 Set_Non_Binary_Modulus
4988 (Implicit_Base, Non_Binary_Modulus (Parent_Base));
4990 elsif Is_Floating_Point_Type (Parent_Type) then
4992 -- Digits of base type is always copied from the digits value of
4993 -- the parent base type, but the digits of the derived type will
4994 -- already have been set if there was a constraint present.
4996 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
4997 Set_Vax_Float (Implicit_Base, Vax_Float (Parent_Base));
4999 if No_Constraint then
5000 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Type));
5003 elsif Is_Fixed_Point_Type (Parent_Type) then
5005 -- Small of base type and derived type are always copied from the
5006 -- parent base type, since smalls never change. The delta of the
5007 -- base type is also copied from the parent base type. However the
5008 -- delta of the derived type will have been set already if a
5009 -- constraint was present.
5011 Set_Small_Value (Derived_Type, Small_Value (Parent_Base));
5012 Set_Small_Value (Implicit_Base, Small_Value (Parent_Base));
5013 Set_Delta_Value (Implicit_Base, Delta_Value (Parent_Base));
5015 if No_Constraint then
5016 Set_Delta_Value (Derived_Type, Delta_Value (Parent_Type));
5019 -- The scale and machine radix in the decimal case are always
5020 -- copied from the parent base type.
5022 if Is_Decimal_Fixed_Point_Type (Parent_Type) then
5023 Set_Scale_Value (Derived_Type, Scale_Value (Parent_Base));
5024 Set_Scale_Value (Implicit_Base, Scale_Value (Parent_Base));
5026 Set_Machine_Radix_10
5027 (Derived_Type, Machine_Radix_10 (Parent_Base));
5028 Set_Machine_Radix_10
5029 (Implicit_Base, Machine_Radix_10 (Parent_Base));
5031 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5033 if No_Constraint then
5034 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Base));
5037 -- the analysis of the subtype_indication sets the
5038 -- digits value of the derived type.
5045 -- The type of the bounds is that of the parent type, and they
5046 -- must be converted to the derived type.
5048 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
5050 -- The implicit_base should be frozen when the derived type is frozen,
5051 -- but note that it is used in the conversions of the bounds. For fixed
5052 -- types we delay the determination of the bounds until the proper
5053 -- freezing point. For other numeric types this is rejected by GCC, for
5054 -- reasons that are currently unclear (???), so we choose to freeze the
5055 -- implicit base now. In the case of integers and floating point types
5056 -- this is harmless because subsequent representation clauses cannot
5057 -- affect anything, but it is still baffling that we cannot use the
5058 -- same mechanism for all derived numeric types.
5060 -- There is a further complication: actually *some* representation
5061 -- clauses can affect the implicit base type. Namely, attribute
5062 -- definition clauses for stream-oriented attributes need to set the
5063 -- corresponding TSS entries on the base type, and this normally cannot
5064 -- be done after the base type is frozen, so the circuitry in
5065 -- Sem_Ch13.New_Stream_Subprogram must account for this possibility and
5066 -- not use Set_TSS in this case.
5068 if Is_Fixed_Point_Type (Parent_Type) then
5069 Conditional_Delay (Implicit_Base, Parent_Type);
5071 Freeze_Before (N, Implicit_Base);
5073 end Build_Derived_Numeric_Type;
5075 --------------------------------
5076 -- Build_Derived_Private_Type --
5077 --------------------------------
5079 procedure Build_Derived_Private_Type
5081 Parent_Type : Entity_Id;
5082 Derived_Type : Entity_Id;
5083 Is_Completion : Boolean;
5084 Derive_Subps : Boolean := True)
5086 Der_Base : Entity_Id;
5088 Full_Decl : Node_Id := Empty;
5089 Full_Der : Entity_Id;
5091 Last_Discr : Entity_Id;
5092 Par_Scope : constant Entity_Id := Scope (Base_Type (Parent_Type));
5093 Swapped : Boolean := False;
5095 procedure Copy_And_Build;
5096 -- Copy derived type declaration, replace parent with its full view,
5097 -- and analyze new declaration.
5099 --------------------
5100 -- Copy_And_Build --
5101 --------------------
5103 procedure Copy_And_Build is
5107 if Ekind (Parent_Type) in Record_Kind
5109 (Ekind (Parent_Type) in Enumeration_Kind
5110 and then Root_Type (Parent_Type) /= Standard_Character
5111 and then Root_Type (Parent_Type) /= Standard_Wide_Character
5112 and then Root_Type (Parent_Type) /= Standard_Wide_Wide_Character
5113 and then not Is_Generic_Type (Root_Type (Parent_Type)))
5115 Full_N := New_Copy_Tree (N);
5116 Insert_After (N, Full_N);
5117 Build_Derived_Type (
5118 Full_N, Parent_Type, Full_Der, True, Derive_Subps => False);
5121 Build_Derived_Type (
5122 N, Parent_Type, Full_Der, True, Derive_Subps => False);
5126 -- Start of processing for Build_Derived_Private_Type
5129 if Is_Tagged_Type (Parent_Type) then
5130 Build_Derived_Record_Type
5131 (N, Parent_Type, Derived_Type, Derive_Subps);
5134 elsif Has_Discriminants (Parent_Type) then
5135 if Present (Full_View (Parent_Type)) then
5136 if not Is_Completion then
5138 -- Copy declaration for subsequent analysis, to provide a
5139 -- completion for what is a private declaration. Indicate that
5140 -- the full type is internally generated.
5142 Full_Decl := New_Copy_Tree (N);
5143 Full_Der := New_Copy (Derived_Type);
5144 Set_Comes_From_Source (Full_Decl, False);
5145 Set_Comes_From_Source (Full_Der, False);
5147 Insert_After (N, Full_Decl);
5150 -- If this is a completion, the full view being built is
5151 -- itself private. We build a subtype of the parent with
5152 -- the same constraints as this full view, to convey to the
5153 -- back end the constrained components and the size of this
5154 -- subtype. If the parent is constrained, its full view can
5155 -- serve as the underlying full view of the derived type.
5157 if No (Discriminant_Specifications (N)) then
5158 if Nkind (Subtype_Indication (Type_Definition (N))) =
5159 N_Subtype_Indication
5161 Build_Underlying_Full_View (N, Derived_Type, Parent_Type);
5163 elsif Is_Constrained (Full_View (Parent_Type)) then
5164 Set_Underlying_Full_View (Derived_Type,
5165 Full_View (Parent_Type));
5169 -- If there are new discriminants, the parent subtype is
5170 -- constrained by them, but it is not clear how to build
5171 -- the underlying_full_view in this case ???
5178 -- Build partial view of derived type from partial view of parent
5180 Build_Derived_Record_Type
5181 (N, Parent_Type, Derived_Type, Derive_Subps);
5183 if Present (Full_View (Parent_Type))
5184 and then not Is_Completion
5186 if not In_Open_Scopes (Par_Scope)
5187 or else not In_Same_Source_Unit (N, Parent_Type)
5189 -- Swap partial and full views temporarily
5191 Install_Private_Declarations (Par_Scope);
5192 Install_Visible_Declarations (Par_Scope);
5196 -- Build full view of derived type from full view of parent which
5197 -- is now installed. Subprograms have been derived on the partial
5198 -- view, the completion does not derive them anew.
5200 if not Is_Tagged_Type (Parent_Type) then
5202 -- If the parent is itself derived from another private type,
5203 -- installing the private declarations has not affected its
5204 -- privacy status, so use its own full view explicitly.
5206 if Is_Private_Type (Parent_Type) then
5207 Build_Derived_Record_Type
5208 (Full_Decl, Full_View (Parent_Type), Full_Der, False);
5210 Build_Derived_Record_Type
5211 (Full_Decl, Parent_Type, Full_Der, False);
5215 -- If full view of parent is tagged, the completion
5216 -- inherits the proper primitive operations.
5218 Set_Defining_Identifier (Full_Decl, Full_Der);
5219 Build_Derived_Record_Type
5220 (Full_Decl, Parent_Type, Full_Der, Derive_Subps);
5221 Set_Analyzed (Full_Decl);
5225 Uninstall_Declarations (Par_Scope);
5227 if In_Open_Scopes (Par_Scope) then
5228 Install_Visible_Declarations (Par_Scope);
5232 Der_Base := Base_Type (Derived_Type);
5233 Set_Full_View (Derived_Type, Full_Der);
5234 Set_Full_View (Der_Base, Base_Type (Full_Der));
5236 -- Copy the discriminant list from full view to the partial views
5237 -- (base type and its subtype). Gigi requires that the partial
5238 -- and full views have the same discriminants.
5240 -- Note that since the partial view is pointing to discriminants
5241 -- in the full view, their scope will be that of the full view.
5242 -- This might cause some front end problems and need
5245 Discr := First_Discriminant (Base_Type (Full_Der));
5246 Set_First_Entity (Der_Base, Discr);
5249 Last_Discr := Discr;
5250 Next_Discriminant (Discr);
5251 exit when No (Discr);
5254 Set_Last_Entity (Der_Base, Last_Discr);
5256 Set_First_Entity (Derived_Type, First_Entity (Der_Base));
5257 Set_Last_Entity (Derived_Type, Last_Entity (Der_Base));
5258 Set_Stored_Constraint (Full_Der, Stored_Constraint (Derived_Type));
5261 -- If this is a completion, the derived type stays private
5262 -- and there is no need to create a further full view, except
5263 -- in the unusual case when the derivation is nested within a
5264 -- child unit, see below.
5269 elsif Present (Full_View (Parent_Type))
5270 and then Has_Discriminants (Full_View (Parent_Type))
5272 if Has_Unknown_Discriminants (Parent_Type)
5273 and then Nkind (Subtype_Indication (Type_Definition (N)))
5274 = N_Subtype_Indication
5277 ("cannot constrain type with unknown discriminants",
5278 Subtype_Indication (Type_Definition (N)));
5282 -- If full view of parent is a record type, Build full view as
5283 -- a derivation from the parent's full view. Partial view remains
5284 -- private. For code generation and linking, the full view must
5285 -- have the same public status as the partial one. This full view
5286 -- is only needed if the parent type is in an enclosing scope, so
5287 -- that the full view may actually become visible, e.g. in a child
5288 -- unit. This is both more efficient, and avoids order of freezing
5289 -- problems with the added entities.
5291 if not Is_Private_Type (Full_View (Parent_Type))
5292 and then (In_Open_Scopes (Scope (Parent_Type)))
5294 Full_Der := Make_Defining_Identifier (Sloc (Derived_Type),
5295 Chars (Derived_Type));
5296 Set_Is_Itype (Full_Der);
5297 Set_Has_Private_Declaration (Full_Der);
5298 Set_Has_Private_Declaration (Derived_Type);
5299 Set_Associated_Node_For_Itype (Full_Der, N);
5300 Set_Parent (Full_Der, Parent (Derived_Type));
5301 Set_Full_View (Derived_Type, Full_Der);
5302 Set_Is_Public (Full_Der, Is_Public (Derived_Type));
5303 Full_P := Full_View (Parent_Type);
5304 Exchange_Declarations (Parent_Type);
5306 Exchange_Declarations (Full_P);
5309 Build_Derived_Record_Type
5310 (N, Full_View (Parent_Type), Derived_Type,
5311 Derive_Subps => False);
5314 -- In any case, the primitive operations are inherited from
5315 -- the parent type, not from the internal full view.
5317 Set_Etype (Base_Type (Derived_Type), Base_Type (Parent_Type));
5319 if Derive_Subps then
5320 Derive_Subprograms (Parent_Type, Derived_Type);
5324 -- Untagged type, No discriminants on either view
5326 if Nkind (Subtype_Indication (Type_Definition (N))) =
5327 N_Subtype_Indication
5330 ("illegal constraint on type without discriminants", N);
5333 if Present (Discriminant_Specifications (N))
5334 and then Present (Full_View (Parent_Type))
5335 and then not Is_Tagged_Type (Full_View (Parent_Type))
5338 ("cannot add discriminants to untagged type", N);
5341 Set_Stored_Constraint (Derived_Type, No_Elist);
5342 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5343 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
5344 Set_Has_Controlled_Component
5345 (Derived_Type, Has_Controlled_Component
5348 -- Direct controlled types do not inherit Finalize_Storage_Only flag
5350 if not Is_Controlled (Parent_Type) then
5351 Set_Finalize_Storage_Only
5352 (Base_Type (Derived_Type), Finalize_Storage_Only (Parent_Type));
5355 -- Construct the implicit full view by deriving from full view of
5356 -- the parent type. In order to get proper visibility, we install
5357 -- the parent scope and its declarations.
5359 -- ??? if the parent is untagged private and its completion is
5360 -- tagged, this mechanism will not work because we cannot derive
5361 -- from the tagged full view unless we have an extension
5363 if Present (Full_View (Parent_Type))
5364 and then not Is_Tagged_Type (Full_View (Parent_Type))
5365 and then not Is_Completion
5368 Make_Defining_Identifier (Sloc (Derived_Type),
5369 Chars => Chars (Derived_Type));
5370 Set_Is_Itype (Full_Der);
5371 Set_Has_Private_Declaration (Full_Der);
5372 Set_Has_Private_Declaration (Derived_Type);
5373 Set_Associated_Node_For_Itype (Full_Der, N);
5374 Set_Parent (Full_Der, Parent (Derived_Type));
5375 Set_Full_View (Derived_Type, Full_Der);
5377 if not In_Open_Scopes (Par_Scope) then
5378 Install_Private_Declarations (Par_Scope);
5379 Install_Visible_Declarations (Par_Scope);
5381 Uninstall_Declarations (Par_Scope);
5383 -- If parent scope is open and in another unit, and parent has a
5384 -- completion, then the derivation is taking place in the visible
5385 -- part of a child unit. In that case retrieve the full view of
5386 -- the parent momentarily.
5388 elsif not In_Same_Source_Unit (N, Parent_Type) then
5389 Full_P := Full_View (Parent_Type);
5390 Exchange_Declarations (Parent_Type);
5392 Exchange_Declarations (Full_P);
5394 -- Otherwise it is a local derivation
5400 Set_Scope (Full_Der, Current_Scope);
5401 Set_Is_First_Subtype (Full_Der,
5402 Is_First_Subtype (Derived_Type));
5403 Set_Has_Size_Clause (Full_Der, False);
5404 Set_Has_Alignment_Clause (Full_Der, False);
5405 Set_Next_Entity (Full_Der, Empty);
5406 Set_Has_Delayed_Freeze (Full_Der);
5407 Set_Is_Frozen (Full_Der, False);
5408 Set_Freeze_Node (Full_Der, Empty);
5409 Set_Depends_On_Private (Full_Der,
5410 Has_Private_Component (Full_Der));
5411 Set_Public_Status (Full_Der);
5415 Set_Has_Unknown_Discriminants (Derived_Type,
5416 Has_Unknown_Discriminants (Parent_Type));
5418 if Is_Private_Type (Derived_Type) then
5419 Set_Private_Dependents (Derived_Type, New_Elmt_List);
5422 if Is_Private_Type (Parent_Type)
5423 and then Base_Type (Parent_Type) = Parent_Type
5424 and then In_Open_Scopes (Scope (Parent_Type))
5426 Append_Elmt (Derived_Type, Private_Dependents (Parent_Type));
5428 if Is_Child_Unit (Scope (Current_Scope))
5429 and then Is_Completion
5430 and then In_Private_Part (Current_Scope)
5431 and then Scope (Parent_Type) /= Current_Scope
5433 -- This is the unusual case where a type completed by a private
5434 -- derivation occurs within a package nested in a child unit,
5435 -- and the parent is declared in an ancestor. In this case, the
5436 -- full view of the parent type will become visible in the body
5437 -- of the enclosing child, and only then will the current type
5438 -- be possibly non-private. We build a underlying full view that
5439 -- will be installed when the enclosing child body is compiled.
5442 Make_Defining_Identifier (Sloc (Derived_Type),
5443 Chars => Chars (Derived_Type));
5444 Set_Is_Itype (Full_Der);
5445 Build_Itype_Reference (Full_Der, N);
5447 -- The full view will be used to swap entities on entry/exit to
5448 -- the body, and must appear in the entity list for the package.
5450 Append_Entity (Full_Der, Scope (Derived_Type));
5451 Set_Has_Private_Declaration (Full_Der);
5452 Set_Has_Private_Declaration (Derived_Type);
5453 Set_Associated_Node_For_Itype (Full_Der, N);
5454 Set_Parent (Full_Der, Parent (Derived_Type));
5455 Full_P := Full_View (Parent_Type);
5456 Exchange_Declarations (Parent_Type);
5458 Exchange_Declarations (Full_P);
5459 Set_Underlying_Full_View (Derived_Type, Full_Der);
5462 end Build_Derived_Private_Type;
5464 -------------------------------
5465 -- Build_Derived_Record_Type --
5466 -------------------------------
5470 -- Ideally we would like to use the same model of type derivation for
5471 -- tagged and untagged record types. Unfortunately this is not quite
5472 -- possible because the semantics of representation clauses is different
5473 -- for tagged and untagged records under inheritance. Consider the
5476 -- type R (...) is [tagged] record ... end record;
5477 -- type T (...) is new R (...) [with ...];
5479 -- The representation clauses for T can specify a completely different
5480 -- record layout from R's. Hence the same component can be placed in two
5481 -- very different positions in objects of type T and R. If R and are tagged
5482 -- types, representation clauses for T can only specify the layout of non
5483 -- inherited components, thus components that are common in R and T have
5484 -- the same position in objects of type R and T.
5486 -- This has two implications. The first is that the entire tree for R's
5487 -- declaration needs to be copied for T in the untagged case, so that T
5488 -- can be viewed as a record type of its own with its own representation
5489 -- clauses. The second implication is the way we handle discriminants.
5490 -- Specifically, in the untagged case we need a way to communicate to Gigi
5491 -- what are the real discriminants in the record, while for the semantics
5492 -- we need to consider those introduced by the user to rename the
5493 -- discriminants in the parent type. This is handled by introducing the
5494 -- notion of stored discriminants. See below for more.
5496 -- Fortunately the way regular components are inherited can be handled in
5497 -- the same way in tagged and untagged types.
5499 -- To complicate things a bit more the private view of a private extension
5500 -- cannot be handled in the same way as the full view (for one thing the
5501 -- semantic rules are somewhat different). We will explain what differs
5504 -- 2. DISCRIMINANTS UNDER INHERITANCE
5506 -- The semantic rules governing the discriminants of derived types are
5509 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
5510 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
5512 -- If parent type has discriminants, then the discriminants that are
5513 -- declared in the derived type are [3.4 (11)]:
5515 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
5518 -- o Otherwise, each discriminant of the parent type (implicitly declared
5519 -- in the same order with the same specifications). In this case, the
5520 -- discriminants are said to be "inherited", or if unknown in the parent
5521 -- are also unknown in the derived type.
5523 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
5525 -- o The parent subtype shall be constrained;
5527 -- o If the parent type is not a tagged type, then each discriminant of
5528 -- the derived type shall be used in the constraint defining a parent
5529 -- subtype. [Implementation note: This ensures that the new discriminant
5530 -- can share storage with an existing discriminant.]
5532 -- For the derived type each discriminant of the parent type is either
5533 -- inherited, constrained to equal some new discriminant of the derived
5534 -- type, or constrained to the value of an expression.
5536 -- When inherited or constrained to equal some new discriminant, the
5537 -- parent discriminant and the discriminant of the derived type are said
5540 -- If a discriminant of the parent type is constrained to a specific value
5541 -- in the derived type definition, then the discriminant is said to be
5542 -- "specified" by that derived type definition.
5544 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
5546 -- We have spoken about stored discriminants in point 1 (introduction)
5547 -- above. There are two sort of stored discriminants: implicit and
5548 -- explicit. As long as the derived type inherits the same discriminants as
5549 -- the root record type, stored discriminants are the same as regular
5550 -- discriminants, and are said to be implicit. However, if any discriminant
5551 -- in the root type was renamed in the derived type, then the derived
5552 -- type will contain explicit stored discriminants. Explicit stored
5553 -- discriminants are discriminants in addition to the semantically visible
5554 -- discriminants defined for the derived type. Stored discriminants are
5555 -- used by Gigi to figure out what are the physical discriminants in
5556 -- objects of the derived type (see precise definition in einfo.ads).
5557 -- As an example, consider the following:
5559 -- type R (D1, D2, D3 : Int) is record ... end record;
5560 -- type T1 is new R;
5561 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
5562 -- type T3 is new T2;
5563 -- type T4 (Y : Int) is new T3 (Y, 99);
5565 -- The following table summarizes the discriminants and stored
5566 -- discriminants in R and T1 through T4.
5568 -- Type Discrim Stored Discrim Comment
5569 -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
5570 -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
5571 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
5572 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
5573 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
5575 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
5576 -- find the corresponding discriminant in the parent type, while
5577 -- Original_Record_Component (abbreviated ORC below), the actual physical
5578 -- component that is renamed. Finally the field Is_Completely_Hidden
5579 -- (abbreviated ICH below) is set for all explicit stored discriminants
5580 -- (see einfo.ads for more info). For the above example this gives:
5582 -- Discrim CD ORC ICH
5583 -- ^^^^^^^ ^^ ^^^ ^^^
5584 -- D1 in R empty itself no
5585 -- D2 in R empty itself no
5586 -- D3 in R empty itself no
5588 -- D1 in T1 D1 in R itself no
5589 -- D2 in T1 D2 in R itself no
5590 -- D3 in T1 D3 in R itself no
5592 -- X1 in T2 D3 in T1 D3 in T2 no
5593 -- X2 in T2 D1 in T1 D1 in T2 no
5594 -- D1 in T2 empty itself yes
5595 -- D2 in T2 empty itself yes
5596 -- D3 in T2 empty itself yes
5598 -- X1 in T3 X1 in T2 D3 in T3 no
5599 -- X2 in T3 X2 in T2 D1 in T3 no
5600 -- D1 in T3 empty itself yes
5601 -- D2 in T3 empty itself yes
5602 -- D3 in T3 empty itself yes
5604 -- Y in T4 X1 in T3 D3 in T3 no
5605 -- D1 in T3 empty itself yes
5606 -- D2 in T3 empty itself yes
5607 -- D3 in T3 empty itself yes
5609 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
5611 -- Type derivation for tagged types is fairly straightforward. If no
5612 -- discriminants are specified by the derived type, these are inherited
5613 -- from the parent. No explicit stored discriminants are ever necessary.
5614 -- The only manipulation that is done to the tree is that of adding a
5615 -- _parent field with parent type and constrained to the same constraint
5616 -- specified for the parent in the derived type definition. For instance:
5618 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
5619 -- type T1 is new R with null record;
5620 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
5622 -- are changed into:
5624 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
5625 -- _parent : R (D1, D2, D3);
5628 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
5629 -- _parent : T1 (X2, 88, X1);
5632 -- The discriminants actually present in R, T1 and T2 as well as their CD,
5633 -- ORC and ICH fields are:
5635 -- Discrim CD ORC ICH
5636 -- ^^^^^^^ ^^ ^^^ ^^^
5637 -- D1 in R empty itself no
5638 -- D2 in R empty itself no
5639 -- D3 in R empty itself no
5641 -- D1 in T1 D1 in R D1 in R no
5642 -- D2 in T1 D2 in R D2 in R no
5643 -- D3 in T1 D3 in R D3 in R no
5645 -- X1 in T2 D3 in T1 D3 in R no
5646 -- X2 in T2 D1 in T1 D1 in R no
5648 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
5650 -- Regardless of whether we dealing with a tagged or untagged type
5651 -- we will transform all derived type declarations of the form
5653 -- type T is new R (...) [with ...];
5655 -- subtype S is R (...);
5656 -- type T is new S [with ...];
5658 -- type BT is new R [with ...];
5659 -- subtype T is BT (...);
5661 -- That is, the base derived type is constrained only if it has no
5662 -- discriminants. The reason for doing this is that GNAT's semantic model
5663 -- assumes that a base type with discriminants is unconstrained.
5665 -- Note that, strictly speaking, the above transformation is not always
5666 -- correct. Consider for instance the following excerpt from ACVC b34011a:
5668 -- procedure B34011A is
5669 -- type REC (D : integer := 0) is record
5674 -- type T6 is new Rec;
5675 -- function F return T6;
5680 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
5683 -- The definition of Q6.U is illegal. However transforming Q6.U into
5685 -- type BaseU is new T6;
5686 -- subtype U is BaseU (Q6.F.I)
5688 -- turns U into a legal subtype, which is incorrect. To avoid this problem
5689 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
5690 -- the transformation described above.
5692 -- There is another instance where the above transformation is incorrect.
5696 -- type Base (D : Integer) is tagged null record;
5697 -- procedure P (X : Base);
5699 -- type Der is new Base (2) with null record;
5700 -- procedure P (X : Der);
5703 -- Then the above transformation turns this into
5705 -- type Der_Base is new Base with null record;
5706 -- -- procedure P (X : Base) is implicitly inherited here
5707 -- -- as procedure P (X : Der_Base).
5709 -- subtype Der is Der_Base (2);
5710 -- procedure P (X : Der);
5711 -- -- The overriding of P (X : Der_Base) is illegal since we
5712 -- -- have a parameter conformance problem.
5714 -- To get around this problem, after having semantically processed Der_Base
5715 -- and the rewritten subtype declaration for Der, we copy Der_Base field
5716 -- Discriminant_Constraint from Der so that when parameter conformance is
5717 -- checked when P is overridden, no semantic errors are flagged.
5719 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
5721 -- Regardless of whether we are dealing with a tagged or untagged type
5722 -- we will transform all derived type declarations of the form
5724 -- type R (D1, .., Dn : ...) is [tagged] record ...;
5725 -- type T is new R [with ...];
5727 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
5729 -- The reason for such transformation is that it allows us to implement a
5730 -- very clean form of component inheritance as explained below.
5732 -- Note that this transformation is not achieved by direct tree rewriting
5733 -- and manipulation, but rather by redoing the semantic actions that the
5734 -- above transformation will entail. This is done directly in routine
5735 -- Inherit_Components.
5737 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
5739 -- In both tagged and untagged derived types, regular non discriminant
5740 -- components are inherited in the derived type from the parent type. In
5741 -- the absence of discriminants component, inheritance is straightforward
5742 -- as components can simply be copied from the parent.
5744 -- If the parent has discriminants, inheriting components constrained with
5745 -- these discriminants requires caution. Consider the following example:
5747 -- type R (D1, D2 : Positive) is [tagged] record
5748 -- S : String (D1 .. D2);
5751 -- type T1 is new R [with null record];
5752 -- type T2 (X : positive) is new R (1, X) [with null record];
5754 -- As explained in 6. above, T1 is rewritten as
5755 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
5756 -- which makes the treatment for T1 and T2 identical.
5758 -- What we want when inheriting S, is that references to D1 and D2 in R are
5759 -- replaced with references to their correct constraints, ie D1 and D2 in
5760 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
5761 -- with either discriminant references in the derived type or expressions.
5762 -- This replacement is achieved as follows: before inheriting R's
5763 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
5764 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
5765 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
5766 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
5767 -- by String (1 .. X).
5769 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
5771 -- We explain here the rules governing private type extensions relevant to
5772 -- type derivation. These rules are explained on the following example:
5774 -- type D [(...)] is new A [(...)] with private; <-- partial view
5775 -- type D [(...)] is new P [(...)] with null record; <-- full view
5777 -- Type A is called the ancestor subtype of the private extension.
5778 -- Type P is the parent type of the full view of the private extension. It
5779 -- must be A or a type derived from A.
5781 -- The rules concerning the discriminants of private type extensions are
5784 -- o If a private extension inherits known discriminants from the ancestor
5785 -- subtype, then the full view shall also inherit its discriminants from
5786 -- the ancestor subtype and the parent subtype of the full view shall be
5787 -- constrained if and only if the ancestor subtype is constrained.
5789 -- o If a partial view has unknown discriminants, then the full view may
5790 -- define a definite or an indefinite subtype, with or without
5793 -- o If a partial view has neither known nor unknown discriminants, then
5794 -- the full view shall define a definite subtype.
5796 -- o If the ancestor subtype of a private extension has constrained
5797 -- discriminants, then the parent subtype of the full view shall impose a
5798 -- statically matching constraint on those discriminants.
5800 -- This means that only the following forms of private extensions are
5803 -- type D is new A with private; <-- partial view
5804 -- type D is new P with null record; <-- full view
5806 -- If A has no discriminants than P has no discriminants, otherwise P must
5807 -- inherit A's discriminants.
5809 -- type D is new A (...) with private; <-- partial view
5810 -- type D is new P (:::) with null record; <-- full view
5812 -- P must inherit A's discriminants and (...) and (:::) must statically
5815 -- subtype A is R (...);
5816 -- type D is new A with private; <-- partial view
5817 -- type D is new P with null record; <-- full view
5819 -- P must have inherited R's discriminants and must be derived from A or
5820 -- any of its subtypes.
5822 -- type D (..) is new A with private; <-- partial view
5823 -- type D (..) is new P [(:::)] with null record; <-- full view
5825 -- No specific constraints on P's discriminants or constraint (:::).
5826 -- Note that A can be unconstrained, but the parent subtype P must either
5827 -- be constrained or (:::) must be present.
5829 -- type D (..) is new A [(...)] with private; <-- partial view
5830 -- type D (..) is new P [(:::)] with null record; <-- full view
5832 -- P's constraints on A's discriminants must statically match those
5833 -- imposed by (...).
5835 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
5837 -- The full view of a private extension is handled exactly as described
5838 -- above. The model chose for the private view of a private extension is
5839 -- the same for what concerns discriminants (ie they receive the same
5840 -- treatment as in the tagged case). However, the private view of the
5841 -- private extension always inherits the components of the parent base,
5842 -- without replacing any discriminant reference. Strictly speaking this is
5843 -- incorrect. However, Gigi never uses this view to generate code so this
5844 -- is a purely semantic issue. In theory, a set of transformations similar
5845 -- to those given in 5. and 6. above could be applied to private views of
5846 -- private extensions to have the same model of component inheritance as
5847 -- for non private extensions. However, this is not done because it would
5848 -- further complicate private type processing. Semantically speaking, this
5849 -- leaves us in an uncomfortable situation. As an example consider:
5852 -- type R (D : integer) is tagged record
5853 -- S : String (1 .. D);
5855 -- procedure P (X : R);
5856 -- type T is new R (1) with private;
5858 -- type T is new R (1) with null record;
5861 -- This is transformed into:
5864 -- type R (D : integer) is tagged record
5865 -- S : String (1 .. D);
5867 -- procedure P (X : R);
5868 -- type T is new R (1) with private;
5870 -- type BaseT is new R with null record;
5871 -- subtype T is BaseT (1);
5874 -- (strictly speaking the above is incorrect Ada)
5876 -- From the semantic standpoint the private view of private extension T
5877 -- should be flagged as constrained since one can clearly have
5881 -- in a unit withing Pack. However, when deriving subprograms for the
5882 -- private view of private extension T, T must be seen as unconstrained
5883 -- since T has discriminants (this is a constraint of the current
5884 -- subprogram derivation model). Thus, when processing the private view of
5885 -- a private extension such as T, we first mark T as unconstrained, we
5886 -- process it, we perform program derivation and just before returning from
5887 -- Build_Derived_Record_Type we mark T as constrained.
5889 -- ??? Are there are other uncomfortable cases that we will have to
5892 -- 10. RECORD_TYPE_WITH_PRIVATE complications
5894 -- Types that are derived from a visible record type and have a private
5895 -- extension present other peculiarities. They behave mostly like private
5896 -- types, but if they have primitive operations defined, these will not
5897 -- have the proper signatures for further inheritance, because other
5898 -- primitive operations will use the implicit base that we define for
5899 -- private derivations below. This affect subprogram inheritance (see
5900 -- Derive_Subprograms for details). We also derive the implicit base from
5901 -- the base type of the full view, so that the implicit base is a record
5902 -- type and not another private type, This avoids infinite loops.
5904 procedure Build_Derived_Record_Type
5906 Parent_Type : Entity_Id;
5907 Derived_Type : Entity_Id;
5908 Derive_Subps : Boolean := True)
5910 Loc : constant Source_Ptr := Sloc (N);
5911 Parent_Base : Entity_Id;
5914 Discrim : Entity_Id;
5915 Last_Discrim : Entity_Id;
5918 Discs : Elist_Id := New_Elmt_List;
5919 -- An empty Discs list means that there were no constraints in the
5920 -- subtype indication or that there was an error processing it.
5922 Assoc_List : Elist_Id;
5923 New_Discrs : Elist_Id;
5924 New_Base : Entity_Id;
5926 New_Indic : Node_Id;
5928 Is_Tagged : constant Boolean := Is_Tagged_Type (Parent_Type);
5929 Discriminant_Specs : constant Boolean :=
5930 Present (Discriminant_Specifications (N));
5931 Private_Extension : constant Boolean :=
5932 (Nkind (N) = N_Private_Extension_Declaration);
5934 Constraint_Present : Boolean;
5935 Inherit_Discrims : Boolean := False;
5936 Save_Etype : Entity_Id;
5937 Save_Discr_Constr : Elist_Id;
5938 Save_Next_Entity : Entity_Id;
5941 if Ekind (Parent_Type) = E_Record_Type_With_Private
5942 and then Present (Full_View (Parent_Type))
5943 and then Has_Discriminants (Parent_Type)
5945 Parent_Base := Base_Type (Full_View (Parent_Type));
5947 Parent_Base := Base_Type (Parent_Type);
5950 -- Before we start the previously documented transformations, here is
5951 -- little fix for size and alignment of tagged types. Normally when we
5952 -- derive type D from type P, we copy the size and alignment of P as the
5953 -- default for D, and in the absence of explicit representation clauses
5954 -- for D, the size and alignment are indeed the same as the parent.
5956 -- But this is wrong for tagged types, since fields may be added, and
5957 -- the default size may need to be larger, and the default alignment may
5958 -- need to be larger.
5960 -- We therefore reset the size and alignment fields in the tagged case.
5961 -- Note that the size and alignment will in any case be at least as
5962 -- large as the parent type (since the derived type has a copy of the
5963 -- parent type in the _parent field)
5965 -- The type is also marked as being tagged here, which is needed when
5966 -- processing components with a self-referential anonymous access type
5967 -- in the call to Check_Anonymous_Access_Components below. Note that
5968 -- this flag is also set later on for completeness.
5971 Set_Is_Tagged_Type (Derived_Type);
5972 Init_Size_Align (Derived_Type);
5975 -- STEP 0a: figure out what kind of derived type declaration we have
5977 if Private_Extension then
5979 Set_Ekind (Derived_Type, E_Record_Type_With_Private);
5982 Type_Def := Type_Definition (N);
5984 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
5985 -- Parent_Base can be a private type or private extension. However,
5986 -- for tagged types with an extension the newly added fields are
5987 -- visible and hence the Derived_Type is always an E_Record_Type.
5988 -- (except that the parent may have its own private fields).
5989 -- For untagged types we preserve the Ekind of the Parent_Base.
5991 if Present (Record_Extension_Part (Type_Def)) then
5992 Set_Ekind (Derived_Type, E_Record_Type);
5994 -- Create internal access types for components with anonymous
5997 if Ada_Version >= Ada_05 then
5998 Check_Anonymous_Access_Components
5999 (N, Derived_Type, Derived_Type,
6000 Component_List (Record_Extension_Part (Type_Def)));
6004 Set_Ekind (Derived_Type, Ekind (Parent_Base));
6008 -- Indic can either be an N_Identifier if the subtype indication
6009 -- contains no constraint or an N_Subtype_Indication if the subtype
6010 -- indication has a constraint.
6012 Indic := Subtype_Indication (Type_Def);
6013 Constraint_Present := (Nkind (Indic) = N_Subtype_Indication);
6015 -- Check that the type has visible discriminants. The type may be
6016 -- a private type with unknown discriminants whose full view has
6017 -- discriminants which are invisible.
6019 if Constraint_Present then
6020 if not Has_Discriminants (Parent_Base)
6022 (Has_Unknown_Discriminants (Parent_Base)
6023 and then Is_Private_Type (Parent_Base))
6026 ("invalid constraint: type has no discriminant",
6027 Constraint (Indic));
6029 Constraint_Present := False;
6030 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6032 elsif Is_Constrained (Parent_Type) then
6034 ("invalid constraint: parent type is already constrained",
6035 Constraint (Indic));
6037 Constraint_Present := False;
6038 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6042 -- STEP 0b: If needed, apply transformation given in point 5. above
6044 if not Private_Extension
6045 and then Has_Discriminants (Parent_Type)
6046 and then not Discriminant_Specs
6047 and then (Is_Constrained (Parent_Type) or else Constraint_Present)
6049 -- First, we must analyze the constraint (see comment in point 5.)
6051 if Constraint_Present then
6052 New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic);
6054 if Has_Discriminants (Derived_Type)
6055 and then Has_Private_Declaration (Derived_Type)
6056 and then Present (Discriminant_Constraint (Derived_Type))
6058 -- Verify that constraints of the full view conform to those
6059 -- given in partial view.
6065 C1 := First_Elmt (New_Discrs);
6066 C2 := First_Elmt (Discriminant_Constraint (Derived_Type));
6067 while Present (C1) and then Present (C2) loop
6069 Fully_Conformant_Expressions (Node (C1), Node (C2))
6072 "constraint not conformant to previous declaration",
6083 -- Insert and analyze the declaration for the unconstrained base type
6085 New_Base := Create_Itype (Ekind (Derived_Type), N, Derived_Type, 'B');
6088 Make_Full_Type_Declaration (Loc,
6089 Defining_Identifier => New_Base,
6091 Make_Derived_Type_Definition (Loc,
6092 Abstract_Present => Abstract_Present (Type_Def),
6093 Subtype_Indication =>
6094 New_Occurrence_Of (Parent_Base, Loc),
6095 Record_Extension_Part =>
6096 Relocate_Node (Record_Extension_Part (Type_Def))));
6098 Set_Parent (New_Decl, Parent (N));
6099 Mark_Rewrite_Insertion (New_Decl);
6100 Insert_Before (N, New_Decl);
6102 -- Note that this call passes False for the Derive_Subps parameter
6103 -- because subprogram derivation is deferred until after creating
6104 -- the subtype (see below).
6107 (New_Decl, Parent_Base, New_Base,
6108 Is_Completion => True, Derive_Subps => False);
6110 -- ??? This needs re-examination to determine whether the
6111 -- above call can simply be replaced by a call to Analyze.
6113 Set_Analyzed (New_Decl);
6115 -- Insert and analyze the declaration for the constrained subtype
6117 if Constraint_Present then
6119 Make_Subtype_Indication (Loc,
6120 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6121 Constraint => Relocate_Node (Constraint (Indic)));
6125 Constr_List : constant List_Id := New_List;
6130 C := First_Elmt (Discriminant_Constraint (Parent_Type));
6131 while Present (C) loop
6134 -- It is safe here to call New_Copy_Tree since
6135 -- Force_Evaluation was called on each constraint in
6136 -- Build_Discriminant_Constraints.
6138 Append (New_Copy_Tree (Expr), To => Constr_List);
6144 Make_Subtype_Indication (Loc,
6145 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6147 Make_Index_Or_Discriminant_Constraint (Loc, Constr_List));
6152 Make_Subtype_Declaration (Loc,
6153 Defining_Identifier => Derived_Type,
6154 Subtype_Indication => New_Indic));
6158 -- Derivation of subprograms must be delayed until the full subtype
6159 -- has been established to ensure proper overriding of subprograms
6160 -- inherited by full types. If the derivations occurred as part of
6161 -- the call to Build_Derived_Type above, then the check for type
6162 -- conformance would fail because earlier primitive subprograms
6163 -- could still refer to the full type prior the change to the new
6164 -- subtype and hence would not match the new base type created here.
6166 Derive_Subprograms (Parent_Type, Derived_Type);
6168 -- For tagged types the Discriminant_Constraint of the new base itype
6169 -- is inherited from the first subtype so that no subtype conformance
6170 -- problem arise when the first subtype overrides primitive
6171 -- operations inherited by the implicit base type.
6174 Set_Discriminant_Constraint
6175 (New_Base, Discriminant_Constraint (Derived_Type));
6181 -- If we get here Derived_Type will have no discriminants or it will be
6182 -- a discriminated unconstrained base type.
6184 -- STEP 1a: perform preliminary actions/checks for derived tagged types
6188 -- The parent type is frozen for non-private extensions (RM 13.14(7))
6189 -- The declaration of a specific descendant of an interface type
6190 -- freezes the interface type (RM 13.14).
6192 if not Private_Extension
6193 or else Is_Interface (Parent_Base)
6195 Freeze_Before (N, Parent_Type);
6198 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
6199 -- cannot be declared at a deeper level than its parent type is
6200 -- removed. The check on derivation within a generic body is also
6201 -- relaxed, but there's a restriction that a derived tagged type
6202 -- cannot be declared in a generic body if it's derived directly
6203 -- or indirectly from a formal type of that generic.
6205 if Ada_Version >= Ada_05 then
6206 if Present (Enclosing_Generic_Body (Derived_Type)) then
6208 Ancestor_Type : Entity_Id;
6211 -- Check to see if any ancestor of the derived type is a
6214 Ancestor_Type := Parent_Type;
6215 while not Is_Generic_Type (Ancestor_Type)
6216 and then Etype (Ancestor_Type) /= Ancestor_Type
6218 Ancestor_Type := Etype (Ancestor_Type);
6221 -- If the derived type does have a formal type as an
6222 -- ancestor, then it's an error if the derived type is
6223 -- declared within the body of the generic unit that
6224 -- declares the formal type in its generic formal part. It's
6225 -- sufficient to check whether the ancestor type is declared
6226 -- inside the same generic body as the derived type (such as
6227 -- within a nested generic spec), in which case the
6228 -- derivation is legal. If the formal type is declared
6229 -- outside of that generic body, then it's guaranteed that
6230 -- the derived type is declared within the generic body of
6231 -- the generic unit declaring the formal type.
6233 if Is_Generic_Type (Ancestor_Type)
6234 and then Enclosing_Generic_Body (Ancestor_Type) /=
6235 Enclosing_Generic_Body (Derived_Type)
6238 ("parent type of& must not be descendant of formal type"
6239 & " of an enclosing generic body",
6240 Indic, Derived_Type);
6245 elsif Type_Access_Level (Derived_Type) /=
6246 Type_Access_Level (Parent_Type)
6247 and then not Is_Generic_Type (Derived_Type)
6249 if Is_Controlled (Parent_Type) then
6251 ("controlled type must be declared at the library level",
6255 ("type extension at deeper accessibility level than parent",
6261 GB : constant Node_Id := Enclosing_Generic_Body (Derived_Type);
6265 and then GB /= Enclosing_Generic_Body (Parent_Base)
6268 ("parent type of& must not be outside generic body"
6270 Indic, Derived_Type);
6276 -- Ada 2005 (AI-251)
6278 if Ada_Version = Ada_05
6281 -- "The declaration of a specific descendant of an interface type
6282 -- freezes the interface type" (RM 13.14).
6287 if Is_Non_Empty_List (Interface_List (Type_Def)) then
6288 Iface := First (Interface_List (Type_Def));
6289 while Present (Iface) loop
6290 Freeze_Before (N, Etype (Iface));
6297 -- STEP 1b : preliminary cleanup of the full view of private types
6299 -- If the type is already marked as having discriminants, then it's the
6300 -- completion of a private type or private extension and we need to
6301 -- retain the discriminants from the partial view if the current
6302 -- declaration has Discriminant_Specifications so that we can verify
6303 -- conformance. However, we must remove any existing components that
6304 -- were inherited from the parent (and attached in Copy_And_Swap)
6305 -- because the full type inherits all appropriate components anyway, and
6306 -- we do not want the partial view's components interfering.
6308 if Has_Discriminants (Derived_Type) and then Discriminant_Specs then
6309 Discrim := First_Discriminant (Derived_Type);
6311 Last_Discrim := Discrim;
6312 Next_Discriminant (Discrim);
6313 exit when No (Discrim);
6316 Set_Last_Entity (Derived_Type, Last_Discrim);
6318 -- In all other cases wipe out the list of inherited components (even
6319 -- inherited discriminants), it will be properly rebuilt here.
6322 Set_First_Entity (Derived_Type, Empty);
6323 Set_Last_Entity (Derived_Type, Empty);
6326 -- STEP 1c: Initialize some flags for the Derived_Type
6328 -- The following flags must be initialized here so that
6329 -- Process_Discriminants can check that discriminants of tagged types do
6330 -- not have a default initial value and that access discriminants are
6331 -- only specified for limited records. For completeness, these flags are
6332 -- also initialized along with all the other flags below.
6334 -- AI-419: Limitedness is not inherited from an interface parent, so to
6335 -- be limited in that case the type must be explicitly declared as
6336 -- limited. However, task and protected interfaces are always limited.
6338 if Limited_Present (Type_Def) then
6339 Set_Is_Limited_Record (Derived_Type);
6341 elsif Is_Limited_Record (Parent_Type) then
6342 if not Is_Interface (Parent_Type)
6343 or else Is_Synchronized_Interface (Parent_Type)
6344 or else Is_Protected_Interface (Parent_Type)
6345 or else Is_Task_Interface (Parent_Type)
6347 Set_Is_Limited_Record (Derived_Type);
6351 -- STEP 2a: process discriminants of derived type if any
6353 Push_Scope (Derived_Type);
6355 if Discriminant_Specs then
6356 Set_Has_Unknown_Discriminants (Derived_Type, False);
6358 -- The following call initializes fields Has_Discriminants and
6359 -- Discriminant_Constraint, unless we are processing the completion
6360 -- of a private type declaration.
6362 Check_Or_Process_Discriminants (N, Derived_Type);
6364 -- For non-tagged types the constraint on the Parent_Type must be
6365 -- present and is used to rename the discriminants.
6367 if not Is_Tagged and then not Has_Discriminants (Parent_Type) then
6368 Error_Msg_N ("untagged parent must have discriminants", Indic);
6370 elsif not Is_Tagged and then not Constraint_Present then
6372 ("discriminant constraint needed for derived untagged records",
6375 -- Otherwise the parent subtype must be constrained unless we have a
6376 -- private extension.
6378 elsif not Constraint_Present
6379 and then not Private_Extension
6380 and then not Is_Constrained (Parent_Type)
6383 ("unconstrained type not allowed in this context", Indic);
6385 elsif Constraint_Present then
6386 -- The following call sets the field Corresponding_Discriminant
6387 -- for the discriminants in the Derived_Type.
6389 Discs := Build_Discriminant_Constraints (Parent_Type, Indic, True);
6391 -- For untagged types all new discriminants must rename
6392 -- discriminants in the parent. For private extensions new
6393 -- discriminants cannot rename old ones (implied by [7.3(13)]).
6395 Discrim := First_Discriminant (Derived_Type);
6396 while Present (Discrim) loop
6398 and then No (Corresponding_Discriminant (Discrim))
6401 ("new discriminants must constrain old ones", Discrim);
6403 elsif Private_Extension
6404 and then Present (Corresponding_Discriminant (Discrim))
6407 ("only static constraints allowed for parent"
6408 & " discriminants in the partial view", Indic);
6412 -- If a new discriminant is used in the constraint, then its
6413 -- subtype must be statically compatible with the parent
6414 -- discriminant's subtype (3.7(15)).
6416 if Present (Corresponding_Discriminant (Discrim))
6418 not Subtypes_Statically_Compatible
6420 Etype (Corresponding_Discriminant (Discrim)))
6423 ("subtype must be compatible with parent discriminant",
6427 Next_Discriminant (Discrim);
6430 -- Check whether the constraints of the full view statically
6431 -- match those imposed by the parent subtype [7.3(13)].
6433 if Present (Stored_Constraint (Derived_Type)) then
6438 C1 := First_Elmt (Discs);
6439 C2 := First_Elmt (Stored_Constraint (Derived_Type));
6440 while Present (C1) and then Present (C2) loop
6442 Fully_Conformant_Expressions (Node (C1), Node (C2))
6445 ("not conformant with previous declaration",
6456 -- STEP 2b: No new discriminants, inherit discriminants if any
6459 if Private_Extension then
6460 Set_Has_Unknown_Discriminants
6462 Has_Unknown_Discriminants (Parent_Type)
6463 or else Unknown_Discriminants_Present (N));
6465 -- The partial view of the parent may have unknown discriminants,
6466 -- but if the full view has discriminants and the parent type is
6467 -- in scope they must be inherited.
6469 elsif Has_Unknown_Discriminants (Parent_Type)
6471 (not Has_Discriminants (Parent_Type)
6472 or else not In_Open_Scopes (Scope (Parent_Type)))
6474 Set_Has_Unknown_Discriminants (Derived_Type);
6477 if not Has_Unknown_Discriminants (Derived_Type)
6478 and then not Has_Unknown_Discriminants (Parent_Base)
6479 and then Has_Discriminants (Parent_Type)
6481 Inherit_Discrims := True;
6482 Set_Has_Discriminants
6483 (Derived_Type, True);
6484 Set_Discriminant_Constraint
6485 (Derived_Type, Discriminant_Constraint (Parent_Base));
6488 -- The following test is true for private types (remember
6489 -- transformation 5. is not applied to those) and in an error
6492 if Constraint_Present then
6493 Discs := Build_Discriminant_Constraints (Parent_Type, Indic);
6496 -- For now mark a new derived type as constrained only if it has no
6497 -- discriminants. At the end of Build_Derived_Record_Type we properly
6498 -- set this flag in the case of private extensions. See comments in
6499 -- point 9. just before body of Build_Derived_Record_Type.
6503 not (Inherit_Discrims
6504 or else Has_Unknown_Discriminants (Derived_Type)));
6507 -- STEP 3: initialize fields of derived type
6509 Set_Is_Tagged_Type (Derived_Type, Is_Tagged);
6510 Set_Stored_Constraint (Derived_Type, No_Elist);
6512 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
6513 -- but cannot be interfaces
6515 if not Private_Extension
6516 and then Ekind (Derived_Type) /= E_Private_Type
6517 and then Ekind (Derived_Type) /= E_Limited_Private_Type
6519 if Interface_Present (Type_Def) then
6520 Analyze_Interface_Declaration (Derived_Type, Type_Def);
6523 Set_Abstract_Interfaces (Derived_Type, No_Elist);
6526 -- Fields inherited from the Parent_Type
6529 (Derived_Type, Einfo.Discard_Names (Parent_Type));
6530 Set_Has_Specified_Layout
6531 (Derived_Type, Has_Specified_Layout (Parent_Type));
6532 Set_Is_Limited_Composite
6533 (Derived_Type, Is_Limited_Composite (Parent_Type));
6534 Set_Is_Private_Composite
6535 (Derived_Type, Is_Private_Composite (Parent_Type));
6537 -- Fields inherited from the Parent_Base
6539 Set_Has_Controlled_Component
6540 (Derived_Type, Has_Controlled_Component (Parent_Base));
6541 Set_Has_Non_Standard_Rep
6542 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6543 Set_Has_Primitive_Operations
6544 (Derived_Type, Has_Primitive_Operations (Parent_Base));
6546 -- For non-private case, we also inherit Has_Complex_Representation
6548 if Ekind (Derived_Type) = E_Record_Type then
6549 Set_Has_Complex_Representation
6550 (Derived_Type, Has_Complex_Representation (Parent_Base));
6553 -- Direct controlled types do not inherit Finalize_Storage_Only flag
6555 if not Is_Controlled (Parent_Type) then
6556 Set_Finalize_Storage_Only
6557 (Derived_Type, Finalize_Storage_Only (Parent_Type));
6560 -- Set fields for private derived types
6562 if Is_Private_Type (Derived_Type) then
6563 Set_Depends_On_Private (Derived_Type, True);
6564 Set_Private_Dependents (Derived_Type, New_Elmt_List);
6566 -- Inherit fields from non private record types. If this is the
6567 -- completion of a derivation from a private type, the parent itself
6568 -- is private, and the attributes come from its full view, which must
6572 if Is_Private_Type (Parent_Base)
6573 and then not Is_Record_Type (Parent_Base)
6575 Set_Component_Alignment
6576 (Derived_Type, Component_Alignment (Full_View (Parent_Base)));
6578 (Derived_Type, C_Pass_By_Copy (Full_View (Parent_Base)));
6580 Set_Component_Alignment
6581 (Derived_Type, Component_Alignment (Parent_Base));
6584 (Derived_Type, C_Pass_By_Copy (Parent_Base));
6588 -- Set fields for tagged types
6591 Set_Primitive_Operations (Derived_Type, New_Elmt_List);
6593 -- All tagged types defined in Ada.Finalization are controlled
6595 if Chars (Scope (Derived_Type)) = Name_Finalization
6596 and then Chars (Scope (Scope (Derived_Type))) = Name_Ada
6597 and then Scope (Scope (Scope (Derived_Type))) = Standard_Standard
6599 Set_Is_Controlled (Derived_Type);
6601 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Base));
6604 Make_Class_Wide_Type (Derived_Type);
6605 Set_Is_Abstract_Type (Derived_Type, Abstract_Present (Type_Def));
6607 if Has_Discriminants (Derived_Type)
6608 and then Constraint_Present
6610 Set_Stored_Constraint
6611 (Derived_Type, Expand_To_Stored_Constraint (Parent_Base, Discs));
6614 if Ada_Version >= Ada_05 then
6616 Ifaces_List : Elist_Id;
6619 -- Checks rules 3.9.4 (13/2 and 14/2)
6621 if Comes_From_Source (Derived_Type)
6622 and then not Is_Private_Type (Derived_Type)
6623 and then Is_Interface (Parent_Type)
6624 and then not Is_Interface (Derived_Type)
6626 if Is_Task_Interface (Parent_Type) then
6628 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
6631 elsif Is_Protected_Interface (Parent_Type) then
6633 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
6638 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
6640 Check_Abstract_Interfaces (N, Type_Def);
6642 -- Ada 2005 (AI-251): Collect the list of progenitors that are
6643 -- not already in the parents.
6645 Collect_Abstract_Interfaces
6647 Ifaces_List => Ifaces_List,
6648 Exclude_Parent_Interfaces => True);
6649 Set_Abstract_Interfaces (Derived_Type, Ifaces_List);
6654 Set_Is_Packed (Derived_Type, Is_Packed (Parent_Base));
6655 Set_Has_Non_Standard_Rep
6656 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6659 -- STEP 4: Inherit components from the parent base and constrain them.
6660 -- Apply the second transformation described in point 6. above.
6662 if (not Is_Empty_Elmt_List (Discs) or else Inherit_Discrims)
6663 or else not Has_Discriminants (Parent_Type)
6664 or else not Is_Constrained (Parent_Type)
6668 Constrs := Discriminant_Constraint (Parent_Type);
6673 (N, Parent_Base, Derived_Type, Is_Tagged, Inherit_Discrims, Constrs);
6675 -- STEP 5a: Copy the parent record declaration for untagged types
6677 if not Is_Tagged then
6679 -- Discriminant_Constraint (Derived_Type) has been properly
6680 -- constructed. Save it and temporarily set it to Empty because we
6681 -- do not want the call to New_Copy_Tree below to mess this list.
6683 if Has_Discriminants (Derived_Type) then
6684 Save_Discr_Constr := Discriminant_Constraint (Derived_Type);
6685 Set_Discriminant_Constraint (Derived_Type, No_Elist);
6687 Save_Discr_Constr := No_Elist;
6690 -- Save the Etype field of Derived_Type. It is correctly set now,
6691 -- but the call to New_Copy tree may remap it to point to itself,
6692 -- which is not what we want. Ditto for the Next_Entity field.
6694 Save_Etype := Etype (Derived_Type);
6695 Save_Next_Entity := Next_Entity (Derived_Type);
6697 -- Assoc_List maps all stored discriminants in the Parent_Base to
6698 -- stored discriminants in the Derived_Type. It is fundamental that
6699 -- no types or itypes with discriminants other than the stored
6700 -- discriminants appear in the entities declared inside
6701 -- Derived_Type, since the back end cannot deal with it.
6705 (Parent (Parent_Base), Map => Assoc_List, New_Sloc => Loc);
6707 -- Restore the fields saved prior to the New_Copy_Tree call
6708 -- and compute the stored constraint.
6710 Set_Etype (Derived_Type, Save_Etype);
6711 Set_Next_Entity (Derived_Type, Save_Next_Entity);
6713 if Has_Discriminants (Derived_Type) then
6714 Set_Discriminant_Constraint
6715 (Derived_Type, Save_Discr_Constr);
6716 Set_Stored_Constraint
6717 (Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs));
6718 Replace_Components (Derived_Type, New_Decl);
6721 -- Insert the new derived type declaration
6723 Rewrite (N, New_Decl);
6725 -- STEP 5b: Complete the processing for record extensions in generics
6727 -- There is no completion for record extensions declared in the
6728 -- parameter part of a generic, so we need to complete processing for
6729 -- these generic record extensions here. The Record_Type_Definition call
6730 -- will change the Ekind of the components from E_Void to E_Component.
6732 elsif Private_Extension and then Is_Generic_Type (Derived_Type) then
6733 Record_Type_Definition (Empty, Derived_Type);
6735 -- STEP 5c: Process the record extension for non private tagged types
6737 elsif not Private_Extension then
6739 -- Add the _parent field in the derived type
6741 Expand_Record_Extension (Derived_Type, Type_Def);
6743 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
6744 -- implemented interfaces if we are in expansion mode
6747 and then Has_Abstract_Interfaces (Derived_Type)
6749 Add_Interface_Tag_Components (N, Derived_Type);
6752 -- Analyze the record extension
6754 Record_Type_Definition
6755 (Record_Extension_Part (Type_Def), Derived_Type);
6760 -- Nothing else to do if there is an error in the derivation.
6761 -- An unusual case: the full view may be derived from a type in an
6762 -- instance, when the partial view was used illegally as an actual
6763 -- in that instance, leading to a circular definition.
6765 if Etype (Derived_Type) = Any_Type
6766 or else Etype (Parent_Type) = Derived_Type
6771 -- Set delayed freeze and then derive subprograms, we need to do
6772 -- this in this order so that derived subprograms inherit the
6773 -- derived freeze if necessary.
6775 Set_Has_Delayed_Freeze (Derived_Type);
6777 if Derive_Subps then
6778 Derive_Subprograms (Parent_Type, Derived_Type);
6781 -- If we have a private extension which defines a constrained derived
6782 -- type mark as constrained here after we have derived subprograms. See
6783 -- comment on point 9. just above the body of Build_Derived_Record_Type.
6785 if Private_Extension and then Inherit_Discrims then
6786 if Constraint_Present and then not Is_Empty_Elmt_List (Discs) then
6787 Set_Is_Constrained (Derived_Type, True);
6788 Set_Discriminant_Constraint (Derived_Type, Discs);
6790 elsif Is_Constrained (Parent_Type) then
6792 (Derived_Type, True);
6793 Set_Discriminant_Constraint
6794 (Derived_Type, Discriminant_Constraint (Parent_Type));
6798 -- Update the class_wide type, which shares the now-completed
6799 -- entity list with its specific type.
6803 (Class_Wide_Type (Derived_Type), First_Entity (Derived_Type));
6805 (Class_Wide_Type (Derived_Type), Last_Entity (Derived_Type));
6808 -- Update the scope of anonymous access types of discriminants and other
6809 -- components, to prevent scope anomalies in gigi, when the derivation
6810 -- appears in a scope nested within that of the parent.
6816 D := First_Entity (Derived_Type);
6817 while Present (D) loop
6818 if Ekind (D) = E_Discriminant
6819 or else Ekind (D) = E_Component
6821 if Is_Itype (Etype (D))
6822 and then Ekind (Etype (D)) = E_Anonymous_Access_Type
6824 Set_Scope (Etype (D), Current_Scope);
6831 end Build_Derived_Record_Type;
6833 ------------------------
6834 -- Build_Derived_Type --
6835 ------------------------
6837 procedure Build_Derived_Type
6839 Parent_Type : Entity_Id;
6840 Derived_Type : Entity_Id;
6841 Is_Completion : Boolean;
6842 Derive_Subps : Boolean := True)
6844 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
6847 -- Set common attributes
6849 Set_Scope (Derived_Type, Current_Scope);
6851 Set_Ekind (Derived_Type, Ekind (Parent_Base));
6852 Set_Etype (Derived_Type, Parent_Base);
6853 Set_Has_Task (Derived_Type, Has_Task (Parent_Base));
6855 Set_Size_Info (Derived_Type, Parent_Type);
6856 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
6857 Set_Convention (Derived_Type, Convention (Parent_Type));
6858 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
6860 -- The derived type inherits the representation clauses of the parent.
6861 -- However, for a private type that is completed by a derivation, there
6862 -- may be operation attributes that have been specified already (stream
6863 -- attributes and External_Tag) and those must be provided. Finally,
6864 -- if the partial view is a private extension, the representation items
6865 -- of the parent have been inherited already, and should not be chained
6866 -- twice to the derived type.
6868 if Is_Tagged_Type (Parent_Type)
6869 and then Present (First_Rep_Item (Derived_Type))
6871 -- The existing items are either operational items or items inherited
6872 -- from a private extension declaration.
6876 -- Used to iterate over representation items of the derived type
6879 -- Last representation item of the (non-empty) representation
6880 -- item list of the derived type.
6882 Found : Boolean := False;
6885 Rep := First_Rep_Item (Derived_Type);
6887 while Present (Rep) loop
6888 if Rep = First_Rep_Item (Parent_Type) then
6893 Rep := Next_Rep_Item (Rep);
6895 if Present (Rep) then
6901 -- Here if we either encountered the parent type's first rep
6902 -- item on the derived type's rep item list (in which case
6903 -- Found is True, and we have nothing else to do), or if we
6904 -- reached the last rep item of the derived type, which is
6905 -- Last_Rep, in which case we further chain the parent type's
6906 -- rep items to those of the derived type.
6909 Set_Next_Rep_Item (Last_Rep, First_Rep_Item (Parent_Type));
6914 Set_First_Rep_Item (Derived_Type, First_Rep_Item (Parent_Type));
6917 case Ekind (Parent_Type) is
6918 when Numeric_Kind =>
6919 Build_Derived_Numeric_Type (N, Parent_Type, Derived_Type);
6922 Build_Derived_Array_Type (N, Parent_Type, Derived_Type);
6926 | Class_Wide_Kind =>
6927 Build_Derived_Record_Type
6928 (N, Parent_Type, Derived_Type, Derive_Subps);
6931 when Enumeration_Kind =>
6932 Build_Derived_Enumeration_Type (N, Parent_Type, Derived_Type);
6935 Build_Derived_Access_Type (N, Parent_Type, Derived_Type);
6937 when Incomplete_Or_Private_Kind =>
6938 Build_Derived_Private_Type
6939 (N, Parent_Type, Derived_Type, Is_Completion, Derive_Subps);
6941 -- For discriminated types, the derivation includes deriving
6942 -- primitive operations. For others it is done below.
6944 if Is_Tagged_Type (Parent_Type)
6945 or else Has_Discriminants (Parent_Type)
6946 or else (Present (Full_View (Parent_Type))
6947 and then Has_Discriminants (Full_View (Parent_Type)))
6952 when Concurrent_Kind =>
6953 Build_Derived_Concurrent_Type (N, Parent_Type, Derived_Type);
6956 raise Program_Error;
6959 if Etype (Derived_Type) = Any_Type then
6963 -- Set delayed freeze and then derive subprograms, we need to do this
6964 -- in this order so that derived subprograms inherit the derived freeze
6967 Set_Has_Delayed_Freeze (Derived_Type);
6968 if Derive_Subps then
6969 Derive_Subprograms (Parent_Type, Derived_Type);
6972 Set_Has_Primitive_Operations
6973 (Base_Type (Derived_Type), Has_Primitive_Operations (Parent_Type));
6974 end Build_Derived_Type;
6976 -----------------------
6977 -- Build_Discriminal --
6978 -----------------------
6980 procedure Build_Discriminal (Discrim : Entity_Id) is
6981 D_Minal : Entity_Id;
6982 CR_Disc : Entity_Id;
6985 -- A discriminal has the same name as the discriminant
6988 Make_Defining_Identifier (Sloc (Discrim),
6989 Chars => Chars (Discrim));
6991 Set_Ekind (D_Minal, E_In_Parameter);
6992 Set_Mechanism (D_Minal, Default_Mechanism);
6993 Set_Etype (D_Minal, Etype (Discrim));
6995 Set_Discriminal (Discrim, D_Minal);
6996 Set_Discriminal_Link (D_Minal, Discrim);
6998 -- For task types, build at once the discriminants of the corresponding
6999 -- record, which are needed if discriminants are used in entry defaults
7000 -- and in family bounds.
7002 if Is_Concurrent_Type (Current_Scope)
7003 or else Is_Limited_Type (Current_Scope)
7005 CR_Disc := Make_Defining_Identifier (Sloc (Discrim), Chars (Discrim));
7007 Set_Ekind (CR_Disc, E_In_Parameter);
7008 Set_Mechanism (CR_Disc, Default_Mechanism);
7009 Set_Etype (CR_Disc, Etype (Discrim));
7010 Set_Discriminal_Link (CR_Disc, Discrim);
7011 Set_CR_Discriminant (Discrim, CR_Disc);
7013 end Build_Discriminal;
7015 ------------------------------------
7016 -- Build_Discriminant_Constraints --
7017 ------------------------------------
7019 function Build_Discriminant_Constraints
7022 Derived_Def : Boolean := False) return Elist_Id
7024 C : constant Node_Id := Constraint (Def);
7025 Nb_Discr : constant Nat := Number_Discriminants (T);
7027 Discr_Expr : array (1 .. Nb_Discr) of Node_Id := (others => Empty);
7028 -- Saves the expression corresponding to a given discriminant in T
7030 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat;
7031 -- Return the Position number within array Discr_Expr of a discriminant
7032 -- D within the discriminant list of the discriminated type T.
7038 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat is
7042 Disc := First_Discriminant (T);
7043 for J in Discr_Expr'Range loop
7048 Next_Discriminant (Disc);
7051 -- Note: Since this function is called on discriminants that are
7052 -- known to belong to the discriminated type, falling through the
7053 -- loop with no match signals an internal compiler error.
7055 raise Program_Error;
7058 -- Declarations local to Build_Discriminant_Constraints
7062 Elist : constant Elist_Id := New_Elmt_List;
7070 Discrim_Present : Boolean := False;
7072 -- Start of processing for Build_Discriminant_Constraints
7075 -- The following loop will process positional associations only.
7076 -- For a positional association, the (single) discriminant is
7077 -- implicitly specified by position, in textual order (RM 3.7.2).
7079 Discr := First_Discriminant (T);
7080 Constr := First (Constraints (C));
7081 for D in Discr_Expr'Range loop
7082 exit when Nkind (Constr) = N_Discriminant_Association;
7085 Error_Msg_N ("too few discriminants given in constraint", C);
7086 return New_Elmt_List;
7088 elsif Nkind (Constr) = N_Range
7089 or else (Nkind (Constr) = N_Attribute_Reference
7091 Attribute_Name (Constr) = Name_Range)
7094 ("a range is not a valid discriminant constraint", Constr);
7095 Discr_Expr (D) := Error;
7098 Analyze_And_Resolve (Constr, Base_Type (Etype (Discr)));
7099 Discr_Expr (D) := Constr;
7102 Next_Discriminant (Discr);
7106 if No (Discr) and then Present (Constr) then
7107 Error_Msg_N ("too many discriminants given in constraint", Constr);
7108 return New_Elmt_List;
7111 -- Named associations can be given in any order, but if both positional
7112 -- and named associations are used in the same discriminant constraint,
7113 -- then positional associations must occur first, at their normal
7114 -- position. Hence once a named association is used, the rest of the
7115 -- discriminant constraint must use only named associations.
7117 while Present (Constr) loop
7119 -- Positional association forbidden after a named association
7121 if Nkind (Constr) /= N_Discriminant_Association then
7122 Error_Msg_N ("positional association follows named one", Constr);
7123 return New_Elmt_List;
7125 -- Otherwise it is a named association
7128 -- E records the type of the discriminants in the named
7129 -- association. All the discriminants specified in the same name
7130 -- association must have the same type.
7134 -- Search the list of discriminants in T to see if the simple name
7135 -- given in the constraint matches any of them.
7137 Id := First (Selector_Names (Constr));
7138 while Present (Id) loop
7141 -- If Original_Discriminant is present, we are processing a
7142 -- generic instantiation and this is an instance node. We need
7143 -- to find the name of the corresponding discriminant in the
7144 -- actual record type T and not the name of the discriminant in
7145 -- the generic formal. Example:
7148 -- type G (D : int) is private;
7150 -- subtype W is G (D => 1);
7152 -- type Rec (X : int) is record ... end record;
7153 -- package Q is new P (G => Rec);
7155 -- At the point of the instantiation, formal type G is Rec
7156 -- and therefore when reanalyzing "subtype W is G (D => 1);"
7157 -- which really looks like "subtype W is Rec (D => 1);" at
7158 -- the point of instantiation, we want to find the discriminant
7159 -- that corresponds to D in Rec, ie X.
7161 if Present (Original_Discriminant (Id)) then
7162 Discr := Find_Corresponding_Discriminant (Id, T);
7166 Discr := First_Discriminant (T);
7167 while Present (Discr) loop
7168 if Chars (Discr) = Chars (Id) then
7173 Next_Discriminant (Discr);
7177 Error_Msg_N ("& does not match any discriminant", Id);
7178 return New_Elmt_List;
7180 -- The following is only useful for the benefit of generic
7181 -- instances but it does not interfere with other
7182 -- processing for the non-generic case so we do it in all
7183 -- cases (for generics this statement is executed when
7184 -- processing the generic definition, see comment at the
7185 -- beginning of this if statement).
7188 Set_Original_Discriminant (Id, Discr);
7192 Position := Pos_Of_Discr (T, Discr);
7194 if Present (Discr_Expr (Position)) then
7195 Error_Msg_N ("duplicate constraint for discriminant&", Id);
7198 -- Each discriminant specified in the same named association
7199 -- must be associated with a separate copy of the
7200 -- corresponding expression.
7202 if Present (Next (Id)) then
7203 Expr := New_Copy_Tree (Expression (Constr));
7204 Set_Parent (Expr, Parent (Expression (Constr)));
7206 Expr := Expression (Constr);
7209 Discr_Expr (Position) := Expr;
7210 Analyze_And_Resolve (Expr, Base_Type (Etype (Discr)));
7213 -- A discriminant association with more than one discriminant
7214 -- name is only allowed if the named discriminants are all of
7215 -- the same type (RM 3.7.1(8)).
7218 E := Base_Type (Etype (Discr));
7220 elsif Base_Type (Etype (Discr)) /= E then
7222 ("all discriminants in an association " &
7223 "must have the same type", Id);
7233 -- A discriminant constraint must provide exactly one value for each
7234 -- discriminant of the type (RM 3.7.1(8)).
7236 for J in Discr_Expr'Range loop
7237 if No (Discr_Expr (J)) then
7238 Error_Msg_N ("too few discriminants given in constraint", C);
7239 return New_Elmt_List;
7243 -- Determine if there are discriminant expressions in the constraint
7245 for J in Discr_Expr'Range loop
7246 if Denotes_Discriminant
7247 (Discr_Expr (J), Check_Concurrent => True)
7249 Discrim_Present := True;
7253 -- Build an element list consisting of the expressions given in the
7254 -- discriminant constraint and apply the appropriate checks. The list
7255 -- is constructed after resolving any named discriminant associations
7256 -- and therefore the expressions appear in the textual order of the
7259 Discr := First_Discriminant (T);
7260 for J in Discr_Expr'Range loop
7261 if Discr_Expr (J) /= Error then
7262 Append_Elmt (Discr_Expr (J), Elist);
7264 -- If any of the discriminant constraints is given by a
7265 -- discriminant and we are in a derived type declaration we
7266 -- have a discriminant renaming. Establish link between new
7267 -- and old discriminant.
7269 if Denotes_Discriminant (Discr_Expr (J)) then
7271 Set_Corresponding_Discriminant
7272 (Entity (Discr_Expr (J)), Discr);
7275 -- Force the evaluation of non-discriminant expressions.
7276 -- If we have found a discriminant in the constraint 3.4(26)
7277 -- and 3.8(18) demand that no range checks are performed are
7278 -- after evaluation. If the constraint is for a component
7279 -- definition that has a per-object constraint, expressions are
7280 -- evaluated but not checked either. In all other cases perform
7284 if Discrim_Present then
7287 elsif Nkind (Parent (Parent (Def))) = N_Component_Declaration
7289 Has_Per_Object_Constraint
7290 (Defining_Identifier (Parent (Parent (Def))))
7294 elsif Is_Access_Type (Etype (Discr)) then
7295 Apply_Constraint_Check (Discr_Expr (J), Etype (Discr));
7298 Apply_Range_Check (Discr_Expr (J), Etype (Discr));
7301 Force_Evaluation (Discr_Expr (J));
7304 -- Check that the designated type of an access discriminant's
7305 -- expression is not a class-wide type unless the discriminant's
7306 -- designated type is also class-wide.
7308 if Ekind (Etype (Discr)) = E_Anonymous_Access_Type
7309 and then not Is_Class_Wide_Type
7310 (Designated_Type (Etype (Discr)))
7311 and then Etype (Discr_Expr (J)) /= Any_Type
7312 and then Is_Class_Wide_Type
7313 (Designated_Type (Etype (Discr_Expr (J))))
7315 Wrong_Type (Discr_Expr (J), Etype (Discr));
7319 Next_Discriminant (Discr);
7323 end Build_Discriminant_Constraints;
7325 ---------------------------------
7326 -- Build_Discriminated_Subtype --
7327 ---------------------------------
7329 procedure Build_Discriminated_Subtype
7333 Related_Nod : Node_Id;
7334 For_Access : Boolean := False)
7336 Has_Discrs : constant Boolean := Has_Discriminants (T);
7337 Constrained : constant Boolean :=
7339 and then not Is_Empty_Elmt_List (Elist)
7340 and then not Is_Class_Wide_Type (T))
7341 or else Is_Constrained (T);
7344 if Ekind (T) = E_Record_Type then
7346 Set_Ekind (Def_Id, E_Private_Subtype);
7347 Set_Is_For_Access_Subtype (Def_Id, True);
7349 Set_Ekind (Def_Id, E_Record_Subtype);
7352 elsif Ekind (T) = E_Task_Type then
7353 Set_Ekind (Def_Id, E_Task_Subtype);
7355 elsif Ekind (T) = E_Protected_Type then
7356 Set_Ekind (Def_Id, E_Protected_Subtype);
7358 elsif Is_Private_Type (T) then
7359 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
7361 elsif Is_Class_Wide_Type (T) then
7362 Set_Ekind (Def_Id, E_Class_Wide_Subtype);
7365 -- Incomplete type. Attach subtype to list of dependents, to be
7366 -- completed with full view of parent type, unless is it the
7367 -- designated subtype of a record component within an init_proc.
7368 -- This last case arises for a component of an access type whose
7369 -- designated type is incomplete (e.g. a Taft Amendment type).
7370 -- The designated subtype is within an inner scope, and needs no
7371 -- elaboration, because only the access type is needed in the
7372 -- initialization procedure.
7374 Set_Ekind (Def_Id, Ekind (T));
7376 if For_Access and then Within_Init_Proc then
7379 Append_Elmt (Def_Id, Private_Dependents (T));
7383 Set_Etype (Def_Id, T);
7384 Init_Size_Align (Def_Id);
7385 Set_Has_Discriminants (Def_Id, Has_Discrs);
7386 Set_Is_Constrained (Def_Id, Constrained);
7388 Set_First_Entity (Def_Id, First_Entity (T));
7389 Set_Last_Entity (Def_Id, Last_Entity (T));
7390 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
7392 if Is_Tagged_Type (T) then
7393 Set_Is_Tagged_Type (Def_Id);
7394 Make_Class_Wide_Type (Def_Id);
7397 Set_Stored_Constraint (Def_Id, No_Elist);
7400 Set_Discriminant_Constraint (Def_Id, Elist);
7401 Set_Stored_Constraint_From_Discriminant_Constraint (Def_Id);
7404 if Is_Tagged_Type (T) then
7406 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
7407 -- concurrent record type (which has the list of primitive
7410 if Ada_Version >= Ada_05
7411 and then Is_Concurrent_Type (T)
7413 Set_Corresponding_Record_Type (Def_Id,
7414 Corresponding_Record_Type (T));
7416 Set_Primitive_Operations (Def_Id, Primitive_Operations (T));
7419 Set_Is_Abstract_Type (Def_Id, Is_Abstract_Type (T));
7422 -- Subtypes introduced by component declarations do not need to be
7423 -- marked as delayed, and do not get freeze nodes, because the semantics
7424 -- verifies that the parents of the subtypes are frozen before the
7425 -- enclosing record is frozen.
7427 if not Is_Type (Scope (Def_Id)) then
7428 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
7430 if Is_Private_Type (T)
7431 and then Present (Full_View (T))
7433 Conditional_Delay (Def_Id, Full_View (T));
7435 Conditional_Delay (Def_Id, T);
7439 if Is_Record_Type (T) then
7440 Set_Is_Limited_Record (Def_Id, Is_Limited_Record (T));
7443 and then not Is_Empty_Elmt_List (Elist)
7444 and then not For_Access
7446 Create_Constrained_Components (Def_Id, Related_Nod, T, Elist);
7447 elsif not For_Access then
7448 Set_Cloned_Subtype (Def_Id, T);
7451 end Build_Discriminated_Subtype;
7453 ---------------------------
7454 -- Build_Itype_Reference --
7455 ---------------------------
7457 procedure Build_Itype_Reference
7461 IR : constant Node_Id := Make_Itype_Reference (Sloc (Nod));
7463 Set_Itype (IR, Ityp);
7464 Insert_After (Nod, IR);
7465 end Build_Itype_Reference;
7467 ------------------------
7468 -- Build_Scalar_Bound --
7469 ------------------------
7471 function Build_Scalar_Bound
7474 Der_T : Entity_Id) return Node_Id
7476 New_Bound : Entity_Id;
7479 -- Note: not clear why this is needed, how can the original bound
7480 -- be unanalyzed at this point? and if it is, what business do we
7481 -- have messing around with it? and why is the base type of the
7482 -- parent type the right type for the resolution. It probably is
7483 -- not! It is OK for the new bound we are creating, but not for
7484 -- the old one??? Still if it never happens, no problem!
7486 Analyze_And_Resolve (Bound, Base_Type (Par_T));
7488 if Nkind (Bound) = N_Integer_Literal
7489 or else Nkind (Bound) = N_Real_Literal
7491 New_Bound := New_Copy (Bound);
7492 Set_Etype (New_Bound, Der_T);
7493 Set_Analyzed (New_Bound);
7495 elsif Is_Entity_Name (Bound) then
7496 New_Bound := OK_Convert_To (Der_T, New_Copy (Bound));
7498 -- The following is almost certainly wrong. What business do we have
7499 -- relocating a node (Bound) that is presumably still attached to
7500 -- the tree elsewhere???
7503 New_Bound := OK_Convert_To (Der_T, Relocate_Node (Bound));
7506 Set_Etype (New_Bound, Der_T);
7508 end Build_Scalar_Bound;
7510 --------------------------------
7511 -- Build_Underlying_Full_View --
7512 --------------------------------
7514 procedure Build_Underlying_Full_View
7519 Loc : constant Source_Ptr := Sloc (N);
7520 Subt : constant Entity_Id :=
7521 Make_Defining_Identifier
7522 (Loc, New_External_Name (Chars (Typ), 'S'));
7529 procedure Set_Discriminant_Name (Id : Node_Id);
7530 -- If the derived type has discriminants, they may rename discriminants
7531 -- of the parent. When building the full view of the parent, we need to
7532 -- recover the names of the original discriminants if the constraint is
7533 -- given by named associations.
7535 ---------------------------
7536 -- Set_Discriminant_Name --
7537 ---------------------------
7539 procedure Set_Discriminant_Name (Id : Node_Id) is
7543 Set_Original_Discriminant (Id, Empty);
7545 if Has_Discriminants (Typ) then
7546 Disc := First_Discriminant (Typ);
7547 while Present (Disc) loop
7548 if Chars (Disc) = Chars (Id)
7549 and then Present (Corresponding_Discriminant (Disc))
7551 Set_Chars (Id, Chars (Corresponding_Discriminant (Disc)));
7553 Next_Discriminant (Disc);
7556 end Set_Discriminant_Name;
7558 -- Start of processing for Build_Underlying_Full_View
7561 if Nkind (N) = N_Full_Type_Declaration then
7562 Constr := Constraint (Subtype_Indication (Type_Definition (N)));
7564 elsif Nkind (N) = N_Subtype_Declaration then
7565 Constr := New_Copy_Tree (Constraint (Subtype_Indication (N)));
7567 elsif Nkind (N) = N_Component_Declaration then
7570 (Constraint (Subtype_Indication (Component_Definition (N))));
7573 raise Program_Error;
7576 C := First (Constraints (Constr));
7577 while Present (C) loop
7578 if Nkind (C) = N_Discriminant_Association then
7579 Id := First (Selector_Names (C));
7580 while Present (Id) loop
7581 Set_Discriminant_Name (Id);
7590 Make_Subtype_Declaration (Loc,
7591 Defining_Identifier => Subt,
7592 Subtype_Indication =>
7593 Make_Subtype_Indication (Loc,
7594 Subtype_Mark => New_Reference_To (Par, Loc),
7595 Constraint => New_Copy_Tree (Constr)));
7597 -- If this is a component subtype for an outer itype, it is not
7598 -- a list member, so simply set the parent link for analysis: if
7599 -- the enclosing type does not need to be in a declarative list,
7600 -- neither do the components.
7602 if Is_List_Member (N)
7603 and then Nkind (N) /= N_Component_Declaration
7605 Insert_Before (N, Indic);
7607 Set_Parent (Indic, Parent (N));
7611 Set_Underlying_Full_View (Typ, Full_View (Subt));
7612 end Build_Underlying_Full_View;
7614 -------------------------------
7615 -- Check_Abstract_Interfaces --
7616 -------------------------------
7618 procedure Check_Abstract_Interfaces (N : Node_Id; Def : Node_Id) is
7620 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id);
7621 -- Local subprogram used to avoid code duplication. In case of error
7622 -- the message will be associated to Error_Node.
7628 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id) is
7630 -- Ada 2005 (AI-345): Protected interfaces can only inherit from
7631 -- limited, synchronized or protected interfaces.
7633 if Protected_Present (Def) then
7634 if Limited_Present (Iface_Def)
7635 or else Synchronized_Present (Iface_Def)
7636 or else Protected_Present (Iface_Def)
7640 elsif Task_Present (Iface_Def) then
7641 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
7642 & " from task interface", Error_Node);
7645 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
7646 & " from non-limited interface", Error_Node);
7649 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
7650 -- limited and synchronized.
7652 elsif Synchronized_Present (Def) then
7653 if Limited_Present (Iface_Def)
7654 or else Synchronized_Present (Iface_Def)
7658 elsif Protected_Present (Iface_Def) then
7659 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
7660 & " from protected interface", Error_Node);
7662 elsif Task_Present (Iface_Def) then
7663 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
7664 & " from task interface", Error_Node);
7667 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
7668 & " from non-limited interface", Error_Node);
7671 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
7672 -- synchronized or task interfaces.
7674 elsif Task_Present (Def) then
7675 if Limited_Present (Iface_Def)
7676 or else Synchronized_Present (Iface_Def)
7677 or else Task_Present (Iface_Def)
7681 elsif Protected_Present (Iface_Def) then
7682 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
7683 & " protected interface", Error_Node);
7686 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
7687 & " non-limited interface", Error_Node);
7695 Iface_Def : Node_Id;
7696 Iface_Typ : Entity_Id;
7697 Parent_Node : Node_Id;
7699 -- Start of processing for Check_Abstract_Interfaces
7702 -- Why is this still unsupported???
7704 if Nkind (N) = N_Private_Extension_Declaration then
7708 -- Check the parent in case of derivation of interface type
7710 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition
7711 and then Is_Interface (Etype (Defining_Identifier (N)))
7713 Parent_Node := Parent (Etype (Defining_Identifier (N)));
7716 (Iface_Def => Type_Definition (Parent_Node),
7717 Error_Node => Subtype_Indication (Type_Definition (N)));
7720 Iface := First (Interface_List (Def));
7721 while Present (Iface) loop
7722 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
7724 Parent_Node := Parent (Base_Type (Iface_Typ));
7725 Iface_Def := Type_Definition (Parent_Node);
7727 if not Is_Interface (Iface_Typ) then
7728 Error_Msg_NE ("(Ada 2005) & must be an interface",
7732 -- "The declaration of a specific descendant of an interface
7733 -- type freezes the interface type" RM 13.14
7735 Freeze_Before (N, Iface_Typ);
7736 Check_Ifaces (Iface_Def, Error_Node => Iface);
7741 end Check_Abstract_Interfaces;
7743 -------------------------------
7744 -- Check_Abstract_Overriding --
7745 -------------------------------
7747 procedure Check_Abstract_Overriding (T : Entity_Id) is
7748 Alias_Subp : Entity_Id;
7755 Op_List := Primitive_Operations (T);
7757 -- Loop to check primitive operations
7759 Elmt := First_Elmt (Op_List);
7760 while Present (Elmt) loop
7761 Subp := Node (Elmt);
7762 Alias_Subp := Alias (Subp);
7764 -- Inherited subprograms are identified by the fact that they do not
7765 -- come from source, and the associated source location is the
7766 -- location of the first subtype of the derived type.
7768 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
7769 -- subprograms that "require overriding".
7771 -- Special exception, do not complain about failure to override the
7772 -- stream routines _Input and _Output, as well as the primitive
7773 -- operations used in dispatching selects since we always provide
7774 -- automatic overridings for these subprograms.
7776 -- Also ignore this rule for convention CIL since .NET libraries
7777 -- do bizarre things with interfaces???
7779 -- The partial view of T may have been a private extension, for
7780 -- which inherited functions dispatching on result are abstract.
7781 -- If the full view is a null extension, there is no need for
7782 -- overriding in Ada2005, but wrappers need to be built for them
7783 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
7785 -- Use elseif here and avoid above goto???
7787 if Is_Null_Extension (T)
7788 and then Has_Controlling_Result (Subp)
7789 and then Ada_Version >= Ada_05
7790 and then Present (Alias (Subp))
7791 and then not Comes_From_Source (Subp)
7792 and then not Is_Abstract_Subprogram (Alias (Subp))
7797 if (Is_Abstract_Subprogram (Subp)
7798 or else Requires_Overriding (Subp)
7799 or else (Has_Controlling_Result (Subp)
7800 and then Present (Alias_Subp)
7801 and then not Comes_From_Source (Subp)
7802 and then Sloc (Subp) = Sloc (First_Subtype (T))))
7803 and then not Is_TSS (Subp, TSS_Stream_Input)
7804 and then not Is_TSS (Subp, TSS_Stream_Output)
7805 and then not Is_Abstract_Type (T)
7806 and then Convention (T) /= Convention_CIL
7807 and then Chars (Subp) /= Name_uDisp_Asynchronous_Select
7808 and then Chars (Subp) /= Name_uDisp_Conditional_Select
7809 and then Chars (Subp) /= Name_uDisp_Get_Prim_Op_Kind
7810 and then Chars (Subp) /= Name_uDisp_Timed_Select
7812 -- Ada 2005 (AI-251): Do not consider hidden entities associated
7813 -- with abstract interface types because the check will be done
7814 -- with the aliased entity (otherwise we generate a duplicated
7817 and then not Present (Abstract_Interface_Alias (Subp))
7819 if Present (Alias_Subp) then
7821 -- Only perform the check for a derived subprogram when the
7822 -- type has an explicit record extension. This avoids
7823 -- incorrectly flagging abstract subprograms for the case of a
7824 -- type without an extension derived from a formal type with a
7825 -- tagged actual (can occur within a private part).
7827 -- Ada 2005 (AI-391): In the case of an inherited function with
7828 -- a controlling result of the type, the rule does not apply if
7829 -- the type is a null extension (unless the parent function
7830 -- itself is abstract, in which case the function must still be
7831 -- be overridden). The expander will generate an overriding
7832 -- wrapper function calling the parent subprogram (see
7833 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
7835 Type_Def := Type_Definition (Parent (T));
7836 if Nkind (Type_Def) = N_Derived_Type_Definition
7837 and then Present (Record_Extension_Part (Type_Def))
7839 (Ada_Version < Ada_05
7840 or else not Is_Null_Extension (T)
7841 or else Ekind (Subp) = E_Procedure
7842 or else not Has_Controlling_Result (Subp)
7843 or else Is_Abstract_Subprogram (Alias_Subp)
7844 or else Requires_Overriding (Subp)
7845 or else Is_Access_Type (Etype (Subp)))
7848 ("type must be declared abstract or & overridden",
7851 -- Traverse the whole chain of aliased subprograms to
7852 -- complete the error notification. This is especially
7853 -- useful for traceability of the chain of entities when the
7854 -- subprogram corresponds with an interface subprogram
7855 -- (which might be defined in another package)
7857 if Present (Alias_Subp) then
7863 while Present (Alias (E)) loop
7864 Error_Msg_Sloc := Sloc (E);
7865 Error_Msg_NE ("\& has been inherited #", T, Subp);
7869 Error_Msg_Sloc := Sloc (E);
7871 ("\& has been inherited from subprogram #", T, Subp);
7875 -- Ada 2005 (AI-345): Protected or task type implementing
7876 -- abstract interfaces.
7878 elsif Is_Concurrent_Record_Type (T)
7879 and then Present (Abstract_Interfaces (T))
7881 -- The controlling formal of Subp must be of mode "out",
7882 -- "in out" or an access-to-variable to be overridden.
7884 -- Error message below needs rewording (remember comma
7885 -- in -gnatj mode) ???
7887 if Ekind (First_Formal (Subp)) = E_In_Parameter then
7889 ("first formal of & must be of mode `OUT`, `IN OUT` " &
7890 "or access-to-variable", T, Subp);
7892 ("\to be overridden by protected procedure or " &
7893 "entry (RM 9.4(11.9/2))", T);
7895 -- Some other kind of overriding failure
7899 ("interface subprogram & must be overridden",
7905 Error_Msg_Node_2 := T;
7907 ("abstract subprogram& not allowed for type&", Subp);
7909 -- Also post unconditional warning on the type (unconditional
7910 -- so that if there are more than one of these cases, we get
7911 -- them all, and not just the first one).
7913 Error_Msg_Node_2 := Subp;
7915 ("nonabstract type& has abstract subprogram&!", T);
7922 end Check_Abstract_Overriding;
7924 ------------------------------------------------
7925 -- Check_Access_Discriminant_Requires_Limited --
7926 ------------------------------------------------
7928 procedure Check_Access_Discriminant_Requires_Limited
7933 -- A discriminant_specification for an access discriminant shall appear
7934 -- only in the declaration for a task or protected type, or for a type
7935 -- with the reserved word 'limited' in its definition or in one of its
7936 -- ancestors. (RM 3.7(10))
7938 if Nkind (Discriminant_Type (D)) = N_Access_Definition
7939 and then not Is_Concurrent_Type (Current_Scope)
7940 and then not Is_Concurrent_Record_Type (Current_Scope)
7941 and then not Is_Limited_Record (Current_Scope)
7942 and then Ekind (Current_Scope) /= E_Limited_Private_Type
7945 ("access discriminants allowed only for limited types", Loc);
7947 end Check_Access_Discriminant_Requires_Limited;
7949 -----------------------------------
7950 -- Check_Aliased_Component_Types --
7951 -----------------------------------
7953 procedure Check_Aliased_Component_Types (T : Entity_Id) is
7957 -- ??? Also need to check components of record extensions, but not
7958 -- components of protected types (which are always limited).
7960 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
7961 -- types to be unconstrained. This is safe because it is illegal to
7962 -- create access subtypes to such types with explicit discriminant
7965 if not Is_Limited_Type (T) then
7966 if Ekind (T) = E_Record_Type then
7967 C := First_Component (T);
7968 while Present (C) loop
7970 and then Has_Discriminants (Etype (C))
7971 and then not Is_Constrained (Etype (C))
7972 and then not In_Instance_Body
7973 and then Ada_Version < Ada_05
7976 ("aliased component must be constrained (RM 3.6(11))",
7983 elsif Ekind (T) = E_Array_Type then
7984 if Has_Aliased_Components (T)
7985 and then Has_Discriminants (Component_Type (T))
7986 and then not Is_Constrained (Component_Type (T))
7987 and then not In_Instance_Body
7988 and then Ada_Version < Ada_05
7991 ("aliased component type must be constrained (RM 3.6(11))",
7996 end Check_Aliased_Component_Types;
7998 ----------------------
7999 -- Check_Completion --
8000 ----------------------
8002 procedure Check_Completion (Body_Id : Node_Id := Empty) is
8005 procedure Post_Error;
8006 -- Post error message for lack of completion for entity E
8012 procedure Post_Error is
8014 if not Comes_From_Source (E) then
8016 if Ekind (E) = E_Task_Type
8017 or else Ekind (E) = E_Protected_Type
8019 -- It may be an anonymous protected type created for a
8020 -- single variable. Post error on variable, if present.
8026 Var := First_Entity (Current_Scope);
8027 while Present (Var) loop
8028 exit when Etype (Var) = E
8029 and then Comes_From_Source (Var);
8034 if Present (Var) then
8041 -- If a generated entity has no completion, then either previous
8042 -- semantic errors have disabled the expansion phase, or else we had
8043 -- missing subunits, or else we are compiling without expansion,
8044 -- or else something is very wrong.
8046 if not Comes_From_Source (E) then
8048 (Serious_Errors_Detected > 0
8049 or else Configurable_Run_Time_Violations > 0
8050 or else Subunits_Missing
8051 or else not Expander_Active);
8054 -- Here for source entity
8057 -- Here if no body to post the error message, so we post the error
8058 -- on the declaration that has no completion. This is not really
8059 -- the right place to post it, think about this later ???
8061 if No (Body_Id) then
8064 ("missing full declaration for }", Parent (E), E);
8067 ("missing body for &", Parent (E), E);
8070 -- Package body has no completion for a declaration that appears
8071 -- in the corresponding spec. Post error on the body, with a
8072 -- reference to the non-completed declaration.
8075 Error_Msg_Sloc := Sloc (E);
8079 ("missing full declaration for }!", Body_Id, E);
8081 elsif Is_Overloadable (E)
8082 and then Current_Entity_In_Scope (E) /= E
8084 -- It may be that the completion is mistyped and appears
8085 -- as a distinct overloading of the entity.
8088 Candidate : constant Entity_Id :=
8089 Current_Entity_In_Scope (E);
8090 Decl : constant Node_Id :=
8091 Unit_Declaration_Node (Candidate);
8094 if Is_Overloadable (Candidate)
8095 and then Ekind (Candidate) = Ekind (E)
8096 and then Nkind (Decl) = N_Subprogram_Body
8097 and then Acts_As_Spec (Decl)
8099 Check_Type_Conformant (Candidate, E);
8102 Error_Msg_NE ("missing body for & declared#!",
8107 Error_Msg_NE ("missing body for & declared#!",
8114 -- Start processing for Check_Completion
8117 E := First_Entity (Current_Scope);
8118 while Present (E) loop
8119 if Is_Intrinsic_Subprogram (E) then
8122 -- The following situation requires special handling: a child
8123 -- unit that appears in the context clause of the body of its
8126 -- procedure Parent.Child (...);
8128 -- with Parent.Child;
8129 -- package body Parent is
8131 -- Here Parent.Child appears as a local entity, but should not
8132 -- be flagged as requiring completion, because it is a
8133 -- compilation unit.
8135 -- Ignore missing completion for a subprogram that does not come from
8136 -- source (including the _Call primitive operation of RAS types,
8137 -- which has to have the flag Comes_From_Source for other purposes):
8138 -- we assume that the expander will provide the missing completion.
8140 elsif Ekind (E) = E_Function
8141 or else Ekind (E) = E_Procedure
8142 or else Ekind (E) = E_Generic_Function
8143 or else Ekind (E) = E_Generic_Procedure
8145 if not Has_Completion (E)
8146 and then not (Is_Subprogram (E)
8147 and then Is_Abstract_Subprogram (E))
8148 and then not (Is_Subprogram (E)
8150 (not Comes_From_Source (E)
8151 or else Chars (E) = Name_uCall))
8152 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8154 and then Chars (E) /= Name_uSize
8159 elsif Is_Entry (E) then
8160 if not Has_Completion (E) and then
8161 (Ekind (Scope (E)) = E_Protected_Object
8162 or else Ekind (Scope (E)) = E_Protected_Type)
8167 elsif Is_Package_Or_Generic_Package (E) then
8168 if Unit_Requires_Body (E) then
8169 if not Has_Completion (E)
8170 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8176 elsif not Is_Child_Unit (E) then
8177 May_Need_Implicit_Body (E);
8180 elsif Ekind (E) = E_Incomplete_Type
8181 and then No (Underlying_Type (E))
8185 elsif (Ekind (E) = E_Task_Type or else
8186 Ekind (E) = E_Protected_Type)
8187 and then not Has_Completion (E)
8191 -- A single task declared in the current scope is a constant, verify
8192 -- that the body of its anonymous type is in the same scope. If the
8193 -- task is defined elsewhere, this may be a renaming declaration for
8194 -- which no completion is needed.
8196 elsif Ekind (E) = E_Constant
8197 and then Ekind (Etype (E)) = E_Task_Type
8198 and then not Has_Completion (Etype (E))
8199 and then Scope (Etype (E)) = Current_Scope
8203 elsif Ekind (E) = E_Protected_Object
8204 and then not Has_Completion (Etype (E))
8208 elsif Ekind (E) = E_Record_Type then
8209 if Is_Tagged_Type (E) then
8210 Check_Abstract_Overriding (E);
8211 Check_Conventions (E);
8214 Check_Aliased_Component_Types (E);
8216 elsif Ekind (E) = E_Array_Type then
8217 Check_Aliased_Component_Types (E);
8223 end Check_Completion;
8225 ----------------------------
8226 -- Check_Delta_Expression --
8227 ----------------------------
8229 procedure Check_Delta_Expression (E : Node_Id) is
8231 if not (Is_Real_Type (Etype (E))) then
8232 Wrong_Type (E, Any_Real);
8234 elsif not Is_OK_Static_Expression (E) then
8235 Flag_Non_Static_Expr
8236 ("non-static expression used for delta value!", E);
8238 elsif not UR_Is_Positive (Expr_Value_R (E)) then
8239 Error_Msg_N ("delta expression must be positive", E);
8245 -- If any of above errors occurred, then replace the incorrect
8246 -- expression by the real 0.1, which should prevent further errors.
8249 Make_Real_Literal (Sloc (E), Ureal_Tenth));
8250 Analyze_And_Resolve (E, Standard_Float);
8251 end Check_Delta_Expression;
8253 -----------------------------
8254 -- Check_Digits_Expression --
8255 -----------------------------
8257 procedure Check_Digits_Expression (E : Node_Id) is
8259 if not (Is_Integer_Type (Etype (E))) then
8260 Wrong_Type (E, Any_Integer);
8262 elsif not Is_OK_Static_Expression (E) then
8263 Flag_Non_Static_Expr
8264 ("non-static expression used for digits value!", E);
8266 elsif Expr_Value (E) <= 0 then
8267 Error_Msg_N ("digits value must be greater than zero", E);
8273 -- If any of above errors occurred, then replace the incorrect
8274 -- expression by the integer 1, which should prevent further errors.
8276 Rewrite (E, Make_Integer_Literal (Sloc (E), 1));
8277 Analyze_And_Resolve (E, Standard_Integer);
8279 end Check_Digits_Expression;
8281 --------------------------
8282 -- Check_Initialization --
8283 --------------------------
8285 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id) is
8287 if Is_Limited_Type (T)
8288 and then not In_Instance
8289 and then not In_Inlined_Body
8291 if not OK_For_Limited_Init (Exp) then
8292 -- In GNAT mode, this is just a warning, to allow it to be
8293 -- evilly turned off. Otherwise it is a real error.
8297 ("cannot initialize entities of limited type?", Exp);
8300 ("cannot initialize entities of limited type", Exp);
8301 Explain_Limited_Type (T, Exp);
8305 end Check_Initialization;
8307 ------------------------------------
8308 -- Check_Or_Process_Discriminants --
8309 ------------------------------------
8311 -- If an incomplete or private type declaration was already given for the
8312 -- type, the discriminants may have already been processed if they were
8313 -- present on the incomplete declaration. In this case a full conformance
8314 -- check is performed otherwise just process them.
8316 procedure Check_Or_Process_Discriminants
8319 Prev : Entity_Id := Empty)
8322 if Has_Discriminants (T) then
8324 -- Make the discriminants visible to component declarations
8331 D := First_Discriminant (T);
8332 while Present (D) loop
8333 Prev := Current_Entity (D);
8334 Set_Current_Entity (D);
8335 Set_Is_Immediately_Visible (D);
8336 Set_Homonym (D, Prev);
8338 -- Ada 2005 (AI-230): Access discriminant allowed in
8339 -- non-limited record types.
8341 if Ada_Version < Ada_05 then
8343 -- This restriction gets applied to the full type here. It
8344 -- has already been applied earlier to the partial view.
8346 Check_Access_Discriminant_Requires_Limited (Parent (D), N);
8349 Next_Discriminant (D);
8353 elsif Present (Discriminant_Specifications (N)) then
8354 Process_Discriminants (N, Prev);
8356 end Check_Or_Process_Discriminants;
8358 ----------------------
8359 -- Check_Real_Bound --
8360 ----------------------
8362 procedure Check_Real_Bound (Bound : Node_Id) is
8364 if not Is_Real_Type (Etype (Bound)) then
8366 ("bound in real type definition must be of real type", Bound);
8368 elsif not Is_OK_Static_Expression (Bound) then
8369 Flag_Non_Static_Expr
8370 ("non-static expression used for real type bound!", Bound);
8377 (Bound, Make_Real_Literal (Sloc (Bound), Ureal_0));
8379 Resolve (Bound, Standard_Float);
8380 end Check_Real_Bound;
8382 ------------------------------
8383 -- Complete_Private_Subtype --
8384 ------------------------------
8386 procedure Complete_Private_Subtype
8389 Full_Base : Entity_Id;
8390 Related_Nod : Node_Id)
8392 Save_Next_Entity : Entity_Id;
8393 Save_Homonym : Entity_Id;
8396 -- Set semantic attributes for (implicit) private subtype completion.
8397 -- If the full type has no discriminants, then it is a copy of the full
8398 -- view of the base. Otherwise, it is a subtype of the base with a
8399 -- possible discriminant constraint. Save and restore the original
8400 -- Next_Entity field of full to ensure that the calls to Copy_Node
8401 -- do not corrupt the entity chain.
8403 -- Note that the type of the full view is the same entity as the type of
8404 -- the partial view. In this fashion, the subtype has access to the
8405 -- correct view of the parent.
8407 Save_Next_Entity := Next_Entity (Full);
8408 Save_Homonym := Homonym (Priv);
8410 case Ekind (Full_Base) is
8411 when E_Record_Type |
8417 Copy_Node (Priv, Full);
8419 Set_Has_Discriminants (Full, Has_Discriminants (Full_Base));
8420 Set_First_Entity (Full, First_Entity (Full_Base));
8421 Set_Last_Entity (Full, Last_Entity (Full_Base));
8424 Copy_Node (Full_Base, Full);
8425 Set_Chars (Full, Chars (Priv));
8426 Conditional_Delay (Full, Priv);
8427 Set_Sloc (Full, Sloc (Priv));
8430 Set_Next_Entity (Full, Save_Next_Entity);
8431 Set_Homonym (Full, Save_Homonym);
8432 Set_Associated_Node_For_Itype (Full, Related_Nod);
8434 -- Set common attributes for all subtypes
8436 Set_Ekind (Full, Subtype_Kind (Ekind (Full_Base)));
8438 -- The Etype of the full view is inconsistent. Gigi needs to see the
8439 -- structural full view, which is what the current scheme gives:
8440 -- the Etype of the full view is the etype of the full base. However,
8441 -- if the full base is a derived type, the full view then looks like
8442 -- a subtype of the parent, not a subtype of the full base. If instead
8445 -- Set_Etype (Full, Full_Base);
8447 -- then we get inconsistencies in the front-end (confusion between
8448 -- views). Several outstanding bugs are related to this ???
8450 Set_Is_First_Subtype (Full, False);
8451 Set_Scope (Full, Scope (Priv));
8452 Set_Size_Info (Full, Full_Base);
8453 Set_RM_Size (Full, RM_Size (Full_Base));
8454 Set_Is_Itype (Full);
8456 -- A subtype of a private-type-without-discriminants, whose full-view
8457 -- has discriminants with default expressions, is not constrained!
8459 if not Has_Discriminants (Priv) then
8460 Set_Is_Constrained (Full, Is_Constrained (Full_Base));
8462 if Has_Discriminants (Full_Base) then
8463 Set_Discriminant_Constraint
8464 (Full, Discriminant_Constraint (Full_Base));
8466 -- The partial view may have been indefinite, the full view
8469 Set_Has_Unknown_Discriminants
8470 (Full, Has_Unknown_Discriminants (Full_Base));
8474 Set_First_Rep_Item (Full, First_Rep_Item (Full_Base));
8475 Set_Depends_On_Private (Full, Has_Private_Component (Full));
8477 -- Freeze the private subtype entity if its parent is delayed, and not
8478 -- already frozen. We skip this processing if the type is an anonymous
8479 -- subtype of a record component, or is the corresponding record of a
8480 -- protected type, since ???
8482 if not Is_Type (Scope (Full)) then
8483 Set_Has_Delayed_Freeze (Full,
8484 Has_Delayed_Freeze (Full_Base)
8485 and then (not Is_Frozen (Full_Base)));
8488 Set_Freeze_Node (Full, Empty);
8489 Set_Is_Frozen (Full, False);
8490 Set_Full_View (Priv, Full);
8492 if Has_Discriminants (Full) then
8493 Set_Stored_Constraint_From_Discriminant_Constraint (Full);
8494 Set_Stored_Constraint (Priv, Stored_Constraint (Full));
8496 if Has_Unknown_Discriminants (Full) then
8497 Set_Discriminant_Constraint (Full, No_Elist);
8501 if Ekind (Full_Base) = E_Record_Type
8502 and then Has_Discriminants (Full_Base)
8503 and then Has_Discriminants (Priv) -- might not, if errors
8504 and then not Has_Unknown_Discriminants (Priv)
8505 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Priv))
8507 Create_Constrained_Components
8508 (Full, Related_Nod, Full_Base, Discriminant_Constraint (Priv));
8510 -- If the full base is itself derived from private, build a congruent
8511 -- subtype of its underlying type, for use by the back end. For a
8512 -- constrained record component, the declaration cannot be placed on
8513 -- the component list, but it must nevertheless be built an analyzed, to
8514 -- supply enough information for Gigi to compute the size of component.
8516 elsif Ekind (Full_Base) in Private_Kind
8517 and then Is_Derived_Type (Full_Base)
8518 and then Has_Discriminants (Full_Base)
8519 and then (Ekind (Current_Scope) /= E_Record_Subtype)
8521 if not Is_Itype (Priv)
8523 Nkind (Subtype_Indication (Parent (Priv))) = N_Subtype_Indication
8525 Build_Underlying_Full_View
8526 (Parent (Priv), Full, Etype (Full_Base));
8528 elsif Nkind (Related_Nod) = N_Component_Declaration then
8529 Build_Underlying_Full_View (Related_Nod, Full, Etype (Full_Base));
8532 elsif Is_Record_Type (Full_Base) then
8534 -- Show Full is simply a renaming of Full_Base
8536 Set_Cloned_Subtype (Full, Full_Base);
8539 -- It is unsafe to share to bounds of a scalar type, because the Itype
8540 -- is elaborated on demand, and if a bound is non-static then different
8541 -- orders of elaboration in different units will lead to different
8542 -- external symbols.
8544 if Is_Scalar_Type (Full_Base) then
8545 Set_Scalar_Range (Full,
8546 Make_Range (Sloc (Related_Nod),
8548 Duplicate_Subexpr_No_Checks (Type_Low_Bound (Full_Base)),
8550 Duplicate_Subexpr_No_Checks (Type_High_Bound (Full_Base))));
8552 -- This completion inherits the bounds of the full parent, but if
8553 -- the parent is an unconstrained floating point type, so is the
8556 if Is_Floating_Point_Type (Full_Base) then
8557 Set_Includes_Infinities
8558 (Scalar_Range (Full), Has_Infinities (Full_Base));
8562 -- ??? It seems that a lot of fields are missing that should be copied
8563 -- from Full_Base to Full. Here are some that are introduced in a
8564 -- non-disruptive way but a cleanup is necessary.
8566 if Is_Tagged_Type (Full_Base) then
8567 Set_Is_Tagged_Type (Full);
8568 Set_Primitive_Operations (Full, Primitive_Operations (Full_Base));
8569 Set_Class_Wide_Type (Full, Class_Wide_Type (Full_Base));
8571 -- If this is a subtype of a protected or task type, constrain its
8572 -- corresponding record, unless this is a subtype without constraints,
8573 -- i.e. a simple renaming as with an actual subtype in an instance.
8575 elsif Is_Concurrent_Type (Full_Base) then
8576 if Has_Discriminants (Full)
8577 and then Present (Corresponding_Record_Type (Full_Base))
8579 not Is_Empty_Elmt_List (Discriminant_Constraint (Full))
8581 Set_Corresponding_Record_Type (Full,
8582 Constrain_Corresponding_Record
8583 (Full, Corresponding_Record_Type (Full_Base),
8584 Related_Nod, Full_Base));
8587 Set_Corresponding_Record_Type (Full,
8588 Corresponding_Record_Type (Full_Base));
8591 end Complete_Private_Subtype;
8593 ----------------------------
8594 -- Constant_Redeclaration --
8595 ----------------------------
8597 procedure Constant_Redeclaration
8602 Prev : constant Entity_Id := Current_Entity_In_Scope (Id);
8603 Obj_Def : constant Node_Id := Object_Definition (N);
8606 procedure Check_Possible_Deferred_Completion
8607 (Prev_Id : Entity_Id;
8608 Prev_Obj_Def : Node_Id;
8609 Curr_Obj_Def : Node_Id);
8610 -- Determine whether the two object definitions describe the partial
8611 -- and the full view of a constrained deferred constant. Generate
8612 -- a subtype for the full view and verify that it statically matches
8613 -- the subtype of the partial view.
8615 procedure Check_Recursive_Declaration (Typ : Entity_Id);
8616 -- If deferred constant is an access type initialized with an allocator,
8617 -- check whether there is an illegal recursion in the definition,
8618 -- through a default value of some record subcomponent. This is normally
8619 -- detected when generating init procs, but requires this additional
8620 -- mechanism when expansion is disabled.
8622 ----------------------------------------
8623 -- Check_Possible_Deferred_Completion --
8624 ----------------------------------------
8626 procedure Check_Possible_Deferred_Completion
8627 (Prev_Id : Entity_Id;
8628 Prev_Obj_Def : Node_Id;
8629 Curr_Obj_Def : Node_Id)
8632 if Nkind (Prev_Obj_Def) = N_Subtype_Indication
8633 and then Present (Constraint (Prev_Obj_Def))
8634 and then Nkind (Curr_Obj_Def) = N_Subtype_Indication
8635 and then Present (Constraint (Curr_Obj_Def))
8638 Loc : constant Source_Ptr := Sloc (N);
8639 Def_Id : constant Entity_Id :=
8640 Make_Defining_Identifier (Loc,
8641 New_Internal_Name ('S'));
8642 Decl : constant Node_Id :=
8643 Make_Subtype_Declaration (Loc,
8644 Defining_Identifier =>
8646 Subtype_Indication =>
8647 Relocate_Node (Curr_Obj_Def));
8650 Insert_Before_And_Analyze (N, Decl);
8651 Set_Etype (Id, Def_Id);
8653 if not Subtypes_Statically_Match (Etype (Prev_Id), Def_Id) then
8654 Error_Msg_Sloc := Sloc (Prev_Id);
8655 Error_Msg_N ("subtype does not statically match deferred " &
8660 end Check_Possible_Deferred_Completion;
8662 ---------------------------------
8663 -- Check_Recursive_Declaration --
8664 ---------------------------------
8666 procedure Check_Recursive_Declaration (Typ : Entity_Id) is
8670 if Is_Record_Type (Typ) then
8671 Comp := First_Component (Typ);
8672 while Present (Comp) loop
8673 if Comes_From_Source (Comp) then
8674 if Present (Expression (Parent (Comp)))
8675 and then Is_Entity_Name (Expression (Parent (Comp)))
8676 and then Entity (Expression (Parent (Comp))) = Prev
8678 Error_Msg_Sloc := Sloc (Parent (Comp));
8680 ("illegal circularity with declaration for&#",
8684 elsif Is_Record_Type (Etype (Comp)) then
8685 Check_Recursive_Declaration (Etype (Comp));
8689 Next_Component (Comp);
8692 end Check_Recursive_Declaration;
8694 -- Start of processing for Constant_Redeclaration
8697 if Nkind (Parent (Prev)) = N_Object_Declaration then
8698 if Nkind (Object_Definition
8699 (Parent (Prev))) = N_Subtype_Indication
8701 -- Find type of new declaration. The constraints of the two
8702 -- views must match statically, but there is no point in
8703 -- creating an itype for the full view.
8705 if Nkind (Obj_Def) = N_Subtype_Indication then
8706 Find_Type (Subtype_Mark (Obj_Def));
8707 New_T := Entity (Subtype_Mark (Obj_Def));
8710 Find_Type (Obj_Def);
8711 New_T := Entity (Obj_Def);
8717 -- The full view may impose a constraint, even if the partial
8718 -- view does not, so construct the subtype.
8720 New_T := Find_Type_Of_Object (Obj_Def, N);
8725 -- Current declaration is illegal, diagnosed below in Enter_Name
8731 -- If previous full declaration exists, or if a homograph is present,
8732 -- let Enter_Name handle it, either with an error, or with the removal
8733 -- of an overridden implicit subprogram.
8735 if Ekind (Prev) /= E_Constant
8736 or else Present (Expression (Parent (Prev)))
8737 or else Present (Full_View (Prev))
8741 -- Verify that types of both declarations match, or else that both types
8742 -- are anonymous access types whose designated subtypes statically match
8743 -- (as allowed in Ada 2005 by AI-385).
8745 elsif Base_Type (Etype (Prev)) /= Base_Type (New_T)
8747 (Ekind (Etype (Prev)) /= E_Anonymous_Access_Type
8748 or else Ekind (Etype (New_T)) /= E_Anonymous_Access_Type
8749 or else not Subtypes_Statically_Match
8750 (Designated_Type (Etype (Prev)),
8751 Designated_Type (Etype (New_T))))
8753 Error_Msg_Sloc := Sloc (Prev);
8754 Error_Msg_N ("type does not match declaration#", N);
8755 Set_Full_View (Prev, Id);
8756 Set_Etype (Id, Any_Type);
8758 -- If so, process the full constant declaration
8761 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
8762 -- the deferred declaration is constrained, then the subtype defined
8763 -- by the subtype_indication in the full declaration shall match it
8766 Check_Possible_Deferred_Completion
8768 Prev_Obj_Def => Object_Definition (Parent (Prev)),
8769 Curr_Obj_Def => Obj_Def);
8771 Set_Full_View (Prev, Id);
8772 Set_Is_Public (Id, Is_Public (Prev));
8773 Set_Is_Internal (Id);
8774 Append_Entity (Id, Current_Scope);
8776 -- Check ALIASED present if present before (RM 7.4(7))
8778 if Is_Aliased (Prev)
8779 and then not Aliased_Present (N)
8781 Error_Msg_Sloc := Sloc (Prev);
8782 Error_Msg_N ("ALIASED required (see declaration#)", N);
8785 -- Allow incomplete declaration of tags (used to handle forward
8786 -- references to tags). The check on Ada_Tags avoids cicularities
8787 -- when rebuilding the compiler.
8789 if RTU_Loaded (Ada_Tags)
8790 and then T = RTE (RE_Tag)
8794 -- Check that placement is in private part and that the incomplete
8795 -- declaration appeared in the visible part.
8797 elsif Ekind (Current_Scope) = E_Package
8798 and then not In_Private_Part (Current_Scope)
8800 Error_Msg_Sloc := Sloc (Prev);
8801 Error_Msg_N ("full constant for declaration#"
8802 & " must be in private part", N);
8804 elsif Ekind (Current_Scope) = E_Package
8805 and then List_Containing (Parent (Prev))
8806 /= Visible_Declarations
8807 (Specification (Unit_Declaration_Node (Current_Scope)))
8810 ("deferred constant must be declared in visible part",
8814 if Is_Access_Type (T)
8815 and then Nkind (Expression (N)) = N_Allocator
8817 Check_Recursive_Declaration (Designated_Type (T));
8820 end Constant_Redeclaration;
8822 ----------------------
8823 -- Constrain_Access --
8824 ----------------------
8826 procedure Constrain_Access
8827 (Def_Id : in out Entity_Id;
8829 Related_Nod : Node_Id)
8831 T : constant Entity_Id := Entity (Subtype_Mark (S));
8832 Desig_Type : constant Entity_Id := Designated_Type (T);
8833 Desig_Subtype : Entity_Id := Create_Itype (E_Void, Related_Nod);
8834 Constraint_OK : Boolean := True;
8836 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean;
8837 -- Simple predicate to test for defaulted discriminants
8838 -- Shouldn't this be in sem_util???
8840 ---------------------------------
8841 -- Has_Defaulted_Discriminants --
8842 ---------------------------------
8844 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8846 return Has_Discriminants (Typ)
8847 and then Present (First_Discriminant (Typ))
8849 (Discriminant_Default_Value (First_Discriminant (Typ)));
8850 end Has_Defaulted_Discriminants;
8852 -- Start of processing for Constrain_Access
8855 if Is_Array_Type (Desig_Type) then
8856 Constrain_Array (Desig_Subtype, S, Related_Nod, Def_Id, 'P');
8858 elsif (Is_Record_Type (Desig_Type)
8859 or else Is_Incomplete_Or_Private_Type (Desig_Type))
8860 and then not Is_Constrained (Desig_Type)
8862 -- ??? The following code is a temporary kludge to ignore a
8863 -- discriminant constraint on access type if it is constraining
8864 -- the current record. Avoid creating the implicit subtype of the
8865 -- record we are currently compiling since right now, we cannot
8866 -- handle these. For now, just return the access type itself.
8868 if Desig_Type = Current_Scope
8869 and then No (Def_Id)
8871 Set_Ekind (Desig_Subtype, E_Record_Subtype);
8872 Def_Id := Entity (Subtype_Mark (S));
8874 -- This call added to ensure that the constraint is analyzed
8875 -- (needed for a B test). Note that we still return early from
8876 -- this procedure to avoid recursive processing. ???
8878 Constrain_Discriminated_Type
8879 (Desig_Subtype, S, Related_Nod, For_Access => True);
8883 if Ekind (T) = E_General_Access_Type
8884 and then Has_Private_Declaration (Desig_Type)
8885 and then In_Open_Scopes (Scope (Desig_Type))
8887 -- Enforce rule that the constraint is illegal if there is
8888 -- an unconstrained view of the designated type. This means
8889 -- that the partial view (either a private type declaration or
8890 -- a derivation from a private type) has no discriminants.
8891 -- (Defect Report 8652/0008, Technical Corrigendum 1, checked
8892 -- by ACATS B371001).
8894 -- Rule updated for Ada 2005: the private type is said to have
8895 -- a constrained partial view, given that objects of the type
8899 Pack : constant Node_Id :=
8900 Unit_Declaration_Node (Scope (Desig_Type));
8905 if Nkind (Pack) = N_Package_Declaration then
8906 Decls := Visible_Declarations (Specification (Pack));
8907 Decl := First (Decls);
8908 while Present (Decl) loop
8909 if (Nkind (Decl) = N_Private_Type_Declaration
8911 Chars (Defining_Identifier (Decl)) =
8915 (Nkind (Decl) = N_Full_Type_Declaration
8917 Chars (Defining_Identifier (Decl)) =
8919 and then Is_Derived_Type (Desig_Type)
8921 Has_Private_Declaration (Etype (Desig_Type)))
8923 if No (Discriminant_Specifications (Decl)) then
8925 ("cannot constrain general access type if " &
8926 "designated type has constrained partial view",
8939 Constrain_Discriminated_Type (Desig_Subtype, S, Related_Nod,
8940 For_Access => True);
8942 elsif (Is_Task_Type (Desig_Type)
8943 or else Is_Protected_Type (Desig_Type))
8944 and then not Is_Constrained (Desig_Type)
8946 Constrain_Concurrent
8947 (Desig_Subtype, S, Related_Nod, Desig_Type, ' ');
8950 Error_Msg_N ("invalid constraint on access type", S);
8951 Desig_Subtype := Desig_Type; -- Ignore invalid constraint.
8952 Constraint_OK := False;
8956 Def_Id := Create_Itype (E_Access_Subtype, Related_Nod);
8958 Set_Ekind (Def_Id, E_Access_Subtype);
8961 if Constraint_OK then
8962 Set_Etype (Def_Id, Base_Type (T));
8964 if Is_Private_Type (Desig_Type) then
8965 Prepare_Private_Subtype_Completion (Desig_Subtype, Related_Nod);
8968 Set_Etype (Def_Id, Any_Type);
8971 Set_Size_Info (Def_Id, T);
8972 Set_Is_Constrained (Def_Id, Constraint_OK);
8973 Set_Directly_Designated_Type (Def_Id, Desig_Subtype);
8974 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
8975 Set_Is_Access_Constant (Def_Id, Is_Access_Constant (T));
8977 Conditional_Delay (Def_Id, T);
8979 -- AI-363 : Subtypes of general access types whose designated types have
8980 -- default discriminants are disallowed. In instances, the rule has to
8981 -- be checked against the actual, of which T is the subtype. In a
8982 -- generic body, the rule is checked assuming that the actual type has
8983 -- defaulted discriminants.
8985 if Ada_Version >= Ada_05 or else Warn_On_Ada_2005_Compatibility then
8986 if Ekind (Base_Type (T)) = E_General_Access_Type
8987 and then Has_Defaulted_Discriminants (Desig_Type)
8989 if Ada_Version < Ada_05 then
8991 ("access subtype of general access type would not " &
8992 "be allowed in Ada 2005?", S);
8995 ("access subype of general access type not allowed", S);
8998 Error_Msg_N ("\discriminants have defaults", S);
9000 elsif Is_Access_Type (T)
9001 and then Is_Generic_Type (Desig_Type)
9002 and then Has_Discriminants (Desig_Type)
9003 and then In_Package_Body (Current_Scope)
9005 if Ada_Version < Ada_05 then
9007 ("access subtype would not be allowed in generic body " &
9011 ("access subtype not allowed in generic body", S);
9015 ("\designated type is a discriminated formal", S);
9018 end Constrain_Access;
9020 ---------------------
9021 -- Constrain_Array --
9022 ---------------------
9024 procedure Constrain_Array
9025 (Def_Id : in out Entity_Id;
9027 Related_Nod : Node_Id;
9028 Related_Id : Entity_Id;
9031 C : constant Node_Id := Constraint (SI);
9032 Number_Of_Constraints : Nat := 0;
9035 Constraint_OK : Boolean := True;
9038 T := Entity (Subtype_Mark (SI));
9040 if Ekind (T) in Access_Kind then
9041 T := Designated_Type (T);
9044 -- If an index constraint follows a subtype mark in a subtype indication
9045 -- then the type or subtype denoted by the subtype mark must not already
9046 -- impose an index constraint. The subtype mark must denote either an
9047 -- unconstrained array type or an access type whose designated type
9048 -- is such an array type... (RM 3.6.1)
9050 if Is_Constrained (T) then
9052 ("array type is already constrained", Subtype_Mark (SI));
9053 Constraint_OK := False;
9056 S := First (Constraints (C));
9057 while Present (S) loop
9058 Number_Of_Constraints := Number_Of_Constraints + 1;
9062 -- In either case, the index constraint must provide a discrete
9063 -- range for each index of the array type and the type of each
9064 -- discrete range must be the same as that of the corresponding
9065 -- index. (RM 3.6.1)
9067 if Number_Of_Constraints /= Number_Dimensions (T) then
9068 Error_Msg_NE ("incorrect number of index constraints for }", C, T);
9069 Constraint_OK := False;
9072 S := First (Constraints (C));
9073 Index := First_Index (T);
9076 -- Apply constraints to each index type
9078 for J in 1 .. Number_Of_Constraints loop
9079 Constrain_Index (Index, S, Related_Nod, Related_Id, Suffix, J);
9089 Create_Itype (E_Array_Subtype, Related_Nod, Related_Id, Suffix);
9090 Set_Parent (Def_Id, Related_Nod);
9093 Set_Ekind (Def_Id, E_Array_Subtype);
9096 Set_Size_Info (Def_Id, (T));
9097 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
9098 Set_Etype (Def_Id, Base_Type (T));
9100 if Constraint_OK then
9101 Set_First_Index (Def_Id, First (Constraints (C)));
9103 Set_First_Index (Def_Id, First_Index (T));
9106 Set_Is_Constrained (Def_Id, True);
9107 Set_Is_Aliased (Def_Id, Is_Aliased (T));
9108 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9110 Set_Is_Private_Composite (Def_Id, Is_Private_Composite (T));
9111 Set_Is_Limited_Composite (Def_Id, Is_Limited_Composite (T));
9113 -- A subtype does not inherit the packed_array_type of is parent. We
9114 -- need to initialize the attribute because if Def_Id is previously
9115 -- analyzed through a limited_with clause, it will have the attributes
9116 -- of an incomplete type, one of which is an Elist that overlaps the
9117 -- Packed_Array_Type field.
9119 Set_Packed_Array_Type (Def_Id, Empty);
9121 -- Build a freeze node if parent still needs one. Also make sure that
9122 -- the Depends_On_Private status is set because the subtype will need
9123 -- reprocessing at the time the base type does, and also we must set a
9124 -- conditional delay.
9126 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
9127 Conditional_Delay (Def_Id, T);
9128 end Constrain_Array;
9130 ------------------------------
9131 -- Constrain_Component_Type --
9132 ------------------------------
9134 function Constrain_Component_Type
9136 Constrained_Typ : Entity_Id;
9137 Related_Node : Node_Id;
9139 Constraints : Elist_Id) return Entity_Id
9141 Loc : constant Source_Ptr := Sloc (Constrained_Typ);
9142 Compon_Type : constant Entity_Id := Etype (Comp);
9144 function Build_Constrained_Array_Type
9145 (Old_Type : Entity_Id) return Entity_Id;
9146 -- If Old_Type is an array type, one of whose indices is constrained
9147 -- by a discriminant, build an Itype whose constraint replaces the
9148 -- discriminant with its value in the constraint.
9150 function Build_Constrained_Discriminated_Type
9151 (Old_Type : Entity_Id) return Entity_Id;
9152 -- Ditto for record components
9154 function Build_Constrained_Access_Type
9155 (Old_Type : Entity_Id) return Entity_Id;
9156 -- Ditto for access types. Makes use of previous two functions, to
9157 -- constrain designated type.
9159 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id;
9160 -- T is an array or discriminated type, C is a list of constraints
9161 -- that apply to T. This routine builds the constrained subtype.
9163 function Is_Discriminant (Expr : Node_Id) return Boolean;
9164 -- Returns True if Expr is a discriminant
9166 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id;
9167 -- Find the value of discriminant Discrim in Constraint
9169 -----------------------------------
9170 -- Build_Constrained_Access_Type --
9171 -----------------------------------
9173 function Build_Constrained_Access_Type
9174 (Old_Type : Entity_Id) return Entity_Id
9176 Desig_Type : constant Entity_Id := Designated_Type (Old_Type);
9178 Desig_Subtype : Entity_Id;
9182 -- if the original access type was not embedded in the enclosing
9183 -- type definition, there is no need to produce a new access
9184 -- subtype. In fact every access type with an explicit constraint
9185 -- generates an itype whose scope is the enclosing record.
9187 if not Is_Type (Scope (Old_Type)) then
9190 elsif Is_Array_Type (Desig_Type) then
9191 Desig_Subtype := Build_Constrained_Array_Type (Desig_Type);
9193 elsif Has_Discriminants (Desig_Type) then
9195 -- This may be an access type to an enclosing record type for
9196 -- which we are constructing the constrained components. Return
9197 -- the enclosing record subtype. This is not always correct,
9198 -- but avoids infinite recursion. ???
9200 Desig_Subtype := Any_Type;
9202 for J in reverse 0 .. Scope_Stack.Last loop
9203 Scop := Scope_Stack.Table (J).Entity;
9206 and then Base_Type (Scop) = Base_Type (Desig_Type)
9208 Desig_Subtype := Scop;
9211 exit when not Is_Type (Scop);
9214 if Desig_Subtype = Any_Type then
9216 Build_Constrained_Discriminated_Type (Desig_Type);
9223 if Desig_Subtype /= Desig_Type then
9225 -- The Related_Node better be here or else we won't be able
9226 -- to attach new itypes to a node in the tree.
9228 pragma Assert (Present (Related_Node));
9230 Itype := Create_Itype (E_Access_Subtype, Related_Node);
9232 Set_Etype (Itype, Base_Type (Old_Type));
9233 Set_Size_Info (Itype, (Old_Type));
9234 Set_Directly_Designated_Type (Itype, Desig_Subtype);
9235 Set_Depends_On_Private (Itype, Has_Private_Component
9237 Set_Is_Access_Constant (Itype, Is_Access_Constant
9240 -- The new itype needs freezing when it depends on a not frozen
9241 -- type and the enclosing subtype needs freezing.
9243 if Has_Delayed_Freeze (Constrained_Typ)
9244 and then not Is_Frozen (Constrained_Typ)
9246 Conditional_Delay (Itype, Base_Type (Old_Type));
9254 end Build_Constrained_Access_Type;
9256 ----------------------------------
9257 -- Build_Constrained_Array_Type --
9258 ----------------------------------
9260 function Build_Constrained_Array_Type
9261 (Old_Type : Entity_Id) return Entity_Id
9265 Old_Index : Node_Id;
9266 Range_Node : Node_Id;
9267 Constr_List : List_Id;
9269 Need_To_Create_Itype : Boolean := False;
9272 Old_Index := First_Index (Old_Type);
9273 while Present (Old_Index) loop
9274 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9276 if Is_Discriminant (Lo_Expr)
9277 or else Is_Discriminant (Hi_Expr)
9279 Need_To_Create_Itype := True;
9282 Next_Index (Old_Index);
9285 if Need_To_Create_Itype then
9286 Constr_List := New_List;
9288 Old_Index := First_Index (Old_Type);
9289 while Present (Old_Index) loop
9290 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9292 if Is_Discriminant (Lo_Expr) then
9293 Lo_Expr := Get_Discr_Value (Lo_Expr);
9296 if Is_Discriminant (Hi_Expr) then
9297 Hi_Expr := Get_Discr_Value (Hi_Expr);
9302 (Loc, New_Copy_Tree (Lo_Expr), New_Copy_Tree (Hi_Expr));
9304 Append (Range_Node, To => Constr_List);
9306 Next_Index (Old_Index);
9309 return Build_Subtype (Old_Type, Constr_List);
9314 end Build_Constrained_Array_Type;
9316 ------------------------------------------
9317 -- Build_Constrained_Discriminated_Type --
9318 ------------------------------------------
9320 function Build_Constrained_Discriminated_Type
9321 (Old_Type : Entity_Id) return Entity_Id
9324 Constr_List : List_Id;
9325 Old_Constraint : Elmt_Id;
9327 Need_To_Create_Itype : Boolean := False;
9330 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9331 while Present (Old_Constraint) loop
9332 Expr := Node (Old_Constraint);
9334 if Is_Discriminant (Expr) then
9335 Need_To_Create_Itype := True;
9338 Next_Elmt (Old_Constraint);
9341 if Need_To_Create_Itype then
9342 Constr_List := New_List;
9344 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9345 while Present (Old_Constraint) loop
9346 Expr := Node (Old_Constraint);
9348 if Is_Discriminant (Expr) then
9349 Expr := Get_Discr_Value (Expr);
9352 Append (New_Copy_Tree (Expr), To => Constr_List);
9354 Next_Elmt (Old_Constraint);
9357 return Build_Subtype (Old_Type, Constr_List);
9362 end Build_Constrained_Discriminated_Type;
9368 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id is
9370 Subtyp_Decl : Node_Id;
9372 Btyp : Entity_Id := Base_Type (T);
9375 -- The Related_Node better be here or else we won't be able to
9376 -- attach new itypes to a node in the tree.
9378 pragma Assert (Present (Related_Node));
9380 -- If the view of the component's type is incomplete or private
9381 -- with unknown discriminants, then the constraint must be applied
9382 -- to the full type.
9384 if Has_Unknown_Discriminants (Btyp)
9385 and then Present (Underlying_Type (Btyp))
9387 Btyp := Underlying_Type (Btyp);
9391 Make_Subtype_Indication (Loc,
9392 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
9393 Constraint => Make_Index_Or_Discriminant_Constraint (Loc, C));
9395 Def_Id := Create_Itype (Ekind (T), Related_Node);
9398 Make_Subtype_Declaration (Loc,
9399 Defining_Identifier => Def_Id,
9400 Subtype_Indication => Indic);
9402 Set_Parent (Subtyp_Decl, Parent (Related_Node));
9404 -- Itypes must be analyzed with checks off (see package Itypes)
9406 Analyze (Subtyp_Decl, Suppress => All_Checks);
9411 ---------------------
9412 -- Get_Discr_Value --
9413 ---------------------
9415 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id is
9421 -- The discriminant may be declared for the type, in which case we
9422 -- find it by iterating over the list of discriminants. If the
9423 -- discriminant is inherited from a parent type, it appears as the
9424 -- corresponding discriminant of the current type. This will be the
9425 -- case when constraining an inherited component whose constraint is
9426 -- given by a discriminant of the parent.
9428 D := First_Discriminant (Typ);
9429 E := First_Elmt (Constraints);
9431 while Present (D) loop
9432 if D = Entity (Discrim)
9433 or else D = CR_Discriminant (Entity (Discrim))
9434 or else Corresponding_Discriminant (D) = Entity (Discrim)
9439 Next_Discriminant (D);
9443 -- The corresponding_Discriminant mechanism is incomplete, because
9444 -- the correspondence between new and old discriminants is not one
9445 -- to one: one new discriminant can constrain several old ones. In
9446 -- that case, scan sequentially the stored_constraint, the list of
9447 -- discriminants of the parents, and the constraints.
9449 if Is_Derived_Type (Typ)
9450 and then Present (Stored_Constraint (Typ))
9451 and then Scope (Entity (Discrim)) = Etype (Typ)
9453 D := First_Discriminant (Etype (Typ));
9454 E := First_Elmt (Constraints);
9455 G := First_Elmt (Stored_Constraint (Typ));
9456 while Present (D) loop
9457 if D = Entity (Discrim) then
9461 Next_Discriminant (D);
9467 -- Something is wrong if we did not find the value
9469 raise Program_Error;
9470 end Get_Discr_Value;
9472 ---------------------
9473 -- Is_Discriminant --
9474 ---------------------
9476 function Is_Discriminant (Expr : Node_Id) return Boolean is
9477 Discrim_Scope : Entity_Id;
9480 if Denotes_Discriminant (Expr) then
9481 Discrim_Scope := Scope (Entity (Expr));
9483 -- Either we have a reference to one of Typ's discriminants,
9485 pragma Assert (Discrim_Scope = Typ
9487 -- or to the discriminants of the parent type, in the case
9488 -- of a derivation of a tagged type with variants.
9490 or else Discrim_Scope = Etype (Typ)
9491 or else Full_View (Discrim_Scope) = Etype (Typ)
9493 -- or same as above for the case where the discriminants
9494 -- were declared in Typ's private view.
9496 or else (Is_Private_Type (Discrim_Scope)
9497 and then Chars (Discrim_Scope) = Chars (Typ))
9499 -- or else we are deriving from the full view and the
9500 -- discriminant is declared in the private entity.
9502 or else (Is_Private_Type (Typ)
9503 and then Chars (Discrim_Scope) = Chars (Typ))
9505 -- Or we are constrained the corresponding record of a
9506 -- synchronized type that completes a private declaration.
9508 or else (Is_Concurrent_Record_Type (Typ)
9510 Corresponding_Concurrent_Type (Typ) = Discrim_Scope)
9512 -- or we have a class-wide type, in which case make sure the
9513 -- discriminant found belongs to the root type.
9515 or else (Is_Class_Wide_Type (Typ)
9516 and then Etype (Typ) = Discrim_Scope));
9521 -- In all other cases we have something wrong
9524 end Is_Discriminant;
9526 -- Start of processing for Constrain_Component_Type
9529 if Nkind (Parent (Comp)) = N_Component_Declaration
9530 and then Comes_From_Source (Parent (Comp))
9531 and then Comes_From_Source
9532 (Subtype_Indication (Component_Definition (Parent (Comp))))
9535 (Subtype_Indication (Component_Definition (Parent (Comp))))
9539 elsif Is_Array_Type (Compon_Type) then
9540 return Build_Constrained_Array_Type (Compon_Type);
9542 elsif Has_Discriminants (Compon_Type) then
9543 return Build_Constrained_Discriminated_Type (Compon_Type);
9545 elsif Is_Access_Type (Compon_Type) then
9546 return Build_Constrained_Access_Type (Compon_Type);
9551 end Constrain_Component_Type;
9553 --------------------------
9554 -- Constrain_Concurrent --
9555 --------------------------
9557 -- For concurrent types, the associated record value type carries the same
9558 -- discriminants, so when we constrain a concurrent type, we must constrain
9559 -- the corresponding record type as well.
9561 procedure Constrain_Concurrent
9562 (Def_Id : in out Entity_Id;
9564 Related_Nod : Node_Id;
9565 Related_Id : Entity_Id;
9568 T_Ent : Entity_Id := Entity (Subtype_Mark (SI));
9572 if Ekind (T_Ent) in Access_Kind then
9573 T_Ent := Designated_Type (T_Ent);
9576 T_Val := Corresponding_Record_Type (T_Ent);
9578 if Present (T_Val) then
9581 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
9584 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
9586 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9587 Set_Corresponding_Record_Type (Def_Id,
9588 Constrain_Corresponding_Record
9589 (Def_Id, T_Val, Related_Nod, Related_Id));
9592 -- If there is no associated record, expansion is disabled and this
9593 -- is a generic context. Create a subtype in any case, so that
9594 -- semantic analysis can proceed.
9597 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
9600 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
9602 end Constrain_Concurrent;
9604 ------------------------------------
9605 -- Constrain_Corresponding_Record --
9606 ------------------------------------
9608 function Constrain_Corresponding_Record
9609 (Prot_Subt : Entity_Id;
9610 Corr_Rec : Entity_Id;
9611 Related_Nod : Node_Id;
9612 Related_Id : Entity_Id) return Entity_Id
9614 T_Sub : constant Entity_Id :=
9615 Create_Itype (E_Record_Subtype, Related_Nod, Related_Id, 'V');
9618 Set_Etype (T_Sub, Corr_Rec);
9619 Init_Size_Align (T_Sub);
9620 Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt));
9621 Set_Is_Constrained (T_Sub, True);
9622 Set_First_Entity (T_Sub, First_Entity (Corr_Rec));
9623 Set_Last_Entity (T_Sub, Last_Entity (Corr_Rec));
9625 -- As elsewhere, we do not want to create a freeze node for this itype
9626 -- if it is created for a constrained component of an enclosing record
9627 -- because references to outer discriminants will appear out of scope.
9629 if Ekind (Scope (Prot_Subt)) /= E_Record_Type then
9630 Conditional_Delay (T_Sub, Corr_Rec);
9632 Set_Is_Frozen (T_Sub);
9635 if Has_Discriminants (Prot_Subt) then -- False only if errors.
9636 Set_Discriminant_Constraint
9637 (T_Sub, Discriminant_Constraint (Prot_Subt));
9638 Set_Stored_Constraint_From_Discriminant_Constraint (T_Sub);
9639 Create_Constrained_Components
9640 (T_Sub, Related_Nod, Corr_Rec, Discriminant_Constraint (T_Sub));
9643 Set_Depends_On_Private (T_Sub, Has_Private_Component (T_Sub));
9646 end Constrain_Corresponding_Record;
9648 -----------------------
9649 -- Constrain_Decimal --
9650 -----------------------
9652 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id) is
9653 T : constant Entity_Id := Entity (Subtype_Mark (S));
9654 C : constant Node_Id := Constraint (S);
9655 Loc : constant Source_Ptr := Sloc (C);
9656 Range_Expr : Node_Id;
9657 Digits_Expr : Node_Id;
9662 Set_Ekind (Def_Id, E_Decimal_Fixed_Point_Subtype);
9664 if Nkind (C) = N_Range_Constraint then
9665 Range_Expr := Range_Expression (C);
9666 Digits_Val := Digits_Value (T);
9669 pragma Assert (Nkind (C) = N_Digits_Constraint);
9670 Digits_Expr := Digits_Expression (C);
9671 Analyze_And_Resolve (Digits_Expr, Any_Integer);
9673 Check_Digits_Expression (Digits_Expr);
9674 Digits_Val := Expr_Value (Digits_Expr);
9676 if Digits_Val > Digits_Value (T) then
9678 ("digits expression is incompatible with subtype", C);
9679 Digits_Val := Digits_Value (T);
9682 if Present (Range_Constraint (C)) then
9683 Range_Expr := Range_Expression (Range_Constraint (C));
9685 Range_Expr := Empty;
9689 Set_Etype (Def_Id, Base_Type (T));
9690 Set_Size_Info (Def_Id, (T));
9691 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
9692 Set_Delta_Value (Def_Id, Delta_Value (T));
9693 Set_Scale_Value (Def_Id, Scale_Value (T));
9694 Set_Small_Value (Def_Id, Small_Value (T));
9695 Set_Machine_Radix_10 (Def_Id, Machine_Radix_10 (T));
9696 Set_Digits_Value (Def_Id, Digits_Val);
9698 -- Manufacture range from given digits value if no range present
9700 if No (Range_Expr) then
9701 Bound_Val := (Ureal_10 ** Digits_Val - Ureal_1) * Small_Value (T);
9705 Convert_To (T, Make_Real_Literal (Loc, (-Bound_Val))),
9707 Convert_To (T, Make_Real_Literal (Loc, Bound_Val)));
9710 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expr, T);
9711 Set_Discrete_RM_Size (Def_Id);
9713 -- Unconditionally delay the freeze, since we cannot set size
9714 -- information in all cases correctly until the freeze point.
9716 Set_Has_Delayed_Freeze (Def_Id);
9717 end Constrain_Decimal;
9719 ----------------------------------
9720 -- Constrain_Discriminated_Type --
9721 ----------------------------------
9723 procedure Constrain_Discriminated_Type
9724 (Def_Id : Entity_Id;
9726 Related_Nod : Node_Id;
9727 For_Access : Boolean := False)
9729 E : constant Entity_Id := Entity (Subtype_Mark (S));
9732 Elist : Elist_Id := New_Elmt_List;
9734 procedure Fixup_Bad_Constraint;
9735 -- This is called after finding a bad constraint, and after having
9736 -- posted an appropriate error message. The mission is to leave the
9737 -- entity T in as reasonable state as possible!
9739 --------------------------
9740 -- Fixup_Bad_Constraint --
9741 --------------------------
9743 procedure Fixup_Bad_Constraint is
9745 -- Set a reasonable Ekind for the entity. For an incomplete type,
9746 -- we can't do much, but for other types, we can set the proper
9747 -- corresponding subtype kind.
9749 if Ekind (T) = E_Incomplete_Type then
9750 Set_Ekind (Def_Id, Ekind (T));
9752 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
9755 Set_Etype (Def_Id, Any_Type);
9756 Set_Error_Posted (Def_Id);
9757 end Fixup_Bad_Constraint;
9759 -- Start of processing for Constrain_Discriminated_Type
9762 C := Constraint (S);
9764 -- A discriminant constraint is only allowed in a subtype indication,
9765 -- after a subtype mark. This subtype mark must denote either a type
9766 -- with discriminants, or an access type whose designated type is a
9767 -- type with discriminants. A discriminant constraint specifies the
9768 -- values of these discriminants (RM 3.7.2(5)).
9770 T := Base_Type (Entity (Subtype_Mark (S)));
9772 if Ekind (T) in Access_Kind then
9773 T := Designated_Type (T);
9776 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal.
9777 -- Avoid generating an error for access-to-incomplete subtypes.
9779 if Ada_Version >= Ada_05
9780 and then Ekind (T) = E_Incomplete_Type
9781 and then Nkind (Parent (S)) = N_Subtype_Declaration
9782 and then not Is_Itype (Def_Id)
9784 -- A little sanity check, emit an error message if the type
9785 -- has discriminants to begin with. Type T may be a regular
9786 -- incomplete type or imported via a limited with clause.
9788 if Has_Discriminants (T)
9791 and then Present (Non_Limited_View (T))
9792 and then Nkind (Parent (Non_Limited_View (T))) =
9793 N_Full_Type_Declaration
9794 and then Present (Discriminant_Specifications
9795 (Parent (Non_Limited_View (T)))))
9798 ("(Ada 2005) incomplete subtype may not be constrained", C);
9801 ("invalid constraint: type has no discriminant", C);
9804 Fixup_Bad_Constraint;
9807 -- Check that the type has visible discriminants. The type may be
9808 -- a private type with unknown discriminants whose full view has
9809 -- discriminants which are invisible.
9811 elsif not Has_Discriminants (T)
9813 (Has_Unknown_Discriminants (T)
9814 and then Is_Private_Type (T))
9816 Error_Msg_N ("invalid constraint: type has no discriminant", C);
9817 Fixup_Bad_Constraint;
9820 elsif Is_Constrained (E)
9821 or else (Ekind (E) = E_Class_Wide_Subtype
9822 and then Present (Discriminant_Constraint (E)))
9824 Error_Msg_N ("type is already constrained", Subtype_Mark (S));
9825 Fixup_Bad_Constraint;
9829 -- T may be an unconstrained subtype (e.g. a generic actual).
9830 -- Constraint applies to the base type.
9834 Elist := Build_Discriminant_Constraints (T, S);
9836 -- If the list returned was empty we had an error in building the
9837 -- discriminant constraint. We have also already signalled an error
9838 -- in the incomplete type case
9840 if Is_Empty_Elmt_List (Elist) then
9841 Fixup_Bad_Constraint;
9845 Build_Discriminated_Subtype (T, Def_Id, Elist, Related_Nod, For_Access);
9846 end Constrain_Discriminated_Type;
9848 ---------------------------
9849 -- Constrain_Enumeration --
9850 ---------------------------
9852 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id) is
9853 T : constant Entity_Id := Entity (Subtype_Mark (S));
9854 C : constant Node_Id := Constraint (S);
9857 Set_Ekind (Def_Id, E_Enumeration_Subtype);
9859 Set_First_Literal (Def_Id, First_Literal (Base_Type (T)));
9861 Set_Etype (Def_Id, Base_Type (T));
9862 Set_Size_Info (Def_Id, (T));
9863 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
9864 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
9866 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
9868 Set_Discrete_RM_Size (Def_Id);
9869 end Constrain_Enumeration;
9871 ----------------------
9872 -- Constrain_Float --
9873 ----------------------
9875 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id) is
9876 T : constant Entity_Id := Entity (Subtype_Mark (S));
9882 Set_Ekind (Def_Id, E_Floating_Point_Subtype);
9884 Set_Etype (Def_Id, Base_Type (T));
9885 Set_Size_Info (Def_Id, (T));
9886 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
9888 -- Process the constraint
9890 C := Constraint (S);
9892 -- Digits constraint present
9894 if Nkind (C) = N_Digits_Constraint then
9895 Check_Restriction (No_Obsolescent_Features, C);
9897 if Warn_On_Obsolescent_Feature then
9899 ("subtype digits constraint is an " &
9900 "obsolescent feature (RM J.3(8))?", C);
9903 D := Digits_Expression (C);
9904 Analyze_And_Resolve (D, Any_Integer);
9905 Check_Digits_Expression (D);
9906 Set_Digits_Value (Def_Id, Expr_Value (D));
9908 -- Check that digits value is in range. Obviously we can do this
9909 -- at compile time, but it is strictly a runtime check, and of
9910 -- course there is an ACVC test that checks this!
9912 if Digits_Value (Def_Id) > Digits_Value (T) then
9913 Error_Msg_Uint_1 := Digits_Value (T);
9914 Error_Msg_N ("?digits value is too large, maximum is ^", D);
9916 Make_Raise_Constraint_Error (Sloc (D),
9917 Reason => CE_Range_Check_Failed);
9918 Insert_Action (Declaration_Node (Def_Id), Rais);
9921 C := Range_Constraint (C);
9923 -- No digits constraint present
9926 Set_Digits_Value (Def_Id, Digits_Value (T));
9929 -- Range constraint present
9931 if Nkind (C) = N_Range_Constraint then
9932 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
9934 -- No range constraint present
9937 pragma Assert (No (C));
9938 Set_Scalar_Range (Def_Id, Scalar_Range (T));
9941 Set_Is_Constrained (Def_Id);
9942 end Constrain_Float;
9944 ---------------------
9945 -- Constrain_Index --
9946 ---------------------
9948 procedure Constrain_Index
9951 Related_Nod : Node_Id;
9952 Related_Id : Entity_Id;
9957 R : Node_Id := Empty;
9958 T : constant Entity_Id := Etype (Index);
9961 if Nkind (S) = N_Range
9963 (Nkind (S) = N_Attribute_Reference
9964 and then Attribute_Name (S) = Name_Range)
9966 -- A Range attribute will transformed into N_Range by Resolve
9972 Process_Range_Expr_In_Decl (R, T, Empty_List);
9974 if not Error_Posted (S)
9976 (Nkind (S) /= N_Range
9977 or else not Covers (T, (Etype (Low_Bound (S))))
9978 or else not Covers (T, (Etype (High_Bound (S)))))
9980 if Base_Type (T) /= Any_Type
9981 and then Etype (Low_Bound (S)) /= Any_Type
9982 and then Etype (High_Bound (S)) /= Any_Type
9984 Error_Msg_N ("range expected", S);
9988 elsif Nkind (S) = N_Subtype_Indication then
9990 -- The parser has verified that this is a discrete indication
9992 Resolve_Discrete_Subtype_Indication (S, T);
9993 R := Range_Expression (Constraint (S));
9995 elsif Nkind (S) = N_Discriminant_Association then
9997 -- Syntactically valid in subtype indication
9999 Error_Msg_N ("invalid index constraint", S);
10000 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10003 -- Subtype_Mark case, no anonymous subtypes to construct
10008 if Is_Entity_Name (S) then
10009 if not Is_Type (Entity (S)) then
10010 Error_Msg_N ("expect subtype mark for index constraint", S);
10012 elsif Base_Type (Entity (S)) /= Base_Type (T) then
10013 Wrong_Type (S, Base_Type (T));
10019 Error_Msg_N ("invalid index constraint", S);
10020 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10026 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index);
10028 Set_Etype (Def_Id, Base_Type (T));
10030 if Is_Modular_Integer_Type (T) then
10031 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10033 elsif Is_Integer_Type (T) then
10034 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10037 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10038 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10041 Set_Size_Info (Def_Id, (T));
10042 Set_RM_Size (Def_Id, RM_Size (T));
10043 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10045 Set_Scalar_Range (Def_Id, R);
10047 Set_Etype (S, Def_Id);
10048 Set_Discrete_RM_Size (Def_Id);
10049 end Constrain_Index;
10051 -----------------------
10052 -- Constrain_Integer --
10053 -----------------------
10055 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id) is
10056 T : constant Entity_Id := Entity (Subtype_Mark (S));
10057 C : constant Node_Id := Constraint (S);
10060 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10062 if Is_Modular_Integer_Type (T) then
10063 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10065 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10068 Set_Etype (Def_Id, Base_Type (T));
10069 Set_Size_Info (Def_Id, (T));
10070 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10071 Set_Discrete_RM_Size (Def_Id);
10072 end Constrain_Integer;
10074 ------------------------------
10075 -- Constrain_Ordinary_Fixed --
10076 ------------------------------
10078 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id) is
10079 T : constant Entity_Id := Entity (Subtype_Mark (S));
10085 Set_Ekind (Def_Id, E_Ordinary_Fixed_Point_Subtype);
10086 Set_Etype (Def_Id, Base_Type (T));
10087 Set_Size_Info (Def_Id, (T));
10088 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10089 Set_Small_Value (Def_Id, Small_Value (T));
10091 -- Process the constraint
10093 C := Constraint (S);
10095 -- Delta constraint present
10097 if Nkind (C) = N_Delta_Constraint then
10098 Check_Restriction (No_Obsolescent_Features, C);
10100 if Warn_On_Obsolescent_Feature then
10102 ("subtype delta constraint is an " &
10103 "obsolescent feature (RM J.3(7))?");
10106 D := Delta_Expression (C);
10107 Analyze_And_Resolve (D, Any_Real);
10108 Check_Delta_Expression (D);
10109 Set_Delta_Value (Def_Id, Expr_Value_R (D));
10111 -- Check that delta value is in range. Obviously we can do this
10112 -- at compile time, but it is strictly a runtime check, and of
10113 -- course there is an ACVC test that checks this!
10115 if Delta_Value (Def_Id) < Delta_Value (T) then
10116 Error_Msg_N ("?delta value is too small", D);
10118 Make_Raise_Constraint_Error (Sloc (D),
10119 Reason => CE_Range_Check_Failed);
10120 Insert_Action (Declaration_Node (Def_Id), Rais);
10123 C := Range_Constraint (C);
10125 -- No delta constraint present
10128 Set_Delta_Value (Def_Id, Delta_Value (T));
10131 -- Range constraint present
10133 if Nkind (C) = N_Range_Constraint then
10134 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10136 -- No range constraint present
10139 pragma Assert (No (C));
10140 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10144 Set_Discrete_RM_Size (Def_Id);
10146 -- Unconditionally delay the freeze, since we cannot set size
10147 -- information in all cases correctly until the freeze point.
10149 Set_Has_Delayed_Freeze (Def_Id);
10150 end Constrain_Ordinary_Fixed;
10152 -----------------------
10153 -- Contain_Interface --
10154 -----------------------
10156 function Contain_Interface
10157 (Iface : Entity_Id;
10158 Ifaces : Elist_Id) return Boolean
10160 Iface_Elmt : Elmt_Id;
10163 if Present (Ifaces) then
10164 Iface_Elmt := First_Elmt (Ifaces);
10165 while Present (Iface_Elmt) loop
10166 if Node (Iface_Elmt) = Iface then
10170 Next_Elmt (Iface_Elmt);
10175 end Contain_Interface;
10177 ---------------------------
10178 -- Convert_Scalar_Bounds --
10179 ---------------------------
10181 procedure Convert_Scalar_Bounds
10183 Parent_Type : Entity_Id;
10184 Derived_Type : Entity_Id;
10187 Implicit_Base : constant Entity_Id := Base_Type (Derived_Type);
10194 Lo := Build_Scalar_Bound
10195 (Type_Low_Bound (Derived_Type),
10196 Parent_Type, Implicit_Base);
10198 Hi := Build_Scalar_Bound
10199 (Type_High_Bound (Derived_Type),
10200 Parent_Type, Implicit_Base);
10207 Set_Includes_Infinities (Rng, Has_Infinities (Derived_Type));
10209 Set_Parent (Rng, N);
10210 Set_Scalar_Range (Derived_Type, Rng);
10212 -- Analyze the bounds
10214 Analyze_And_Resolve (Lo, Implicit_Base);
10215 Analyze_And_Resolve (Hi, Implicit_Base);
10217 -- Analyze the range itself, except that we do not analyze it if
10218 -- the bounds are real literals, and we have a fixed-point type.
10219 -- The reason for this is that we delay setting the bounds in this
10220 -- case till we know the final Small and Size values (see circuit
10221 -- in Freeze.Freeze_Fixed_Point_Type for further details).
10223 if Is_Fixed_Point_Type (Parent_Type)
10224 and then Nkind (Lo) = N_Real_Literal
10225 and then Nkind (Hi) = N_Real_Literal
10229 -- Here we do the analysis of the range
10231 -- Note: we do this manually, since if we do a normal Analyze and
10232 -- Resolve call, there are problems with the conversions used for
10233 -- the derived type range.
10236 Set_Etype (Rng, Implicit_Base);
10237 Set_Analyzed (Rng, True);
10239 end Convert_Scalar_Bounds;
10241 -------------------
10242 -- Copy_And_Swap --
10243 -------------------
10245 procedure Copy_And_Swap (Priv, Full : Entity_Id) is
10247 -- Initialize new full declaration entity by copying the pertinent
10248 -- fields of the corresponding private declaration entity.
10250 -- We temporarily set Ekind to a value appropriate for a type to
10251 -- avoid assert failures in Einfo from checking for setting type
10252 -- attributes on something that is not a type. Ekind (Priv) is an
10253 -- appropriate choice, since it allowed the attributes to be set
10254 -- in the first place. This Ekind value will be modified later.
10256 Set_Ekind (Full, Ekind (Priv));
10258 -- Also set Etype temporarily to Any_Type, again, in the absence
10259 -- of errors, it will be properly reset, and if there are errors,
10260 -- then we want a value of Any_Type to remain.
10262 Set_Etype (Full, Any_Type);
10264 -- Now start copying attributes
10266 Set_Has_Discriminants (Full, Has_Discriminants (Priv));
10268 if Has_Discriminants (Full) then
10269 Set_Discriminant_Constraint (Full, Discriminant_Constraint (Priv));
10270 Set_Stored_Constraint (Full, Stored_Constraint (Priv));
10273 Set_First_Rep_Item (Full, First_Rep_Item (Priv));
10274 Set_Homonym (Full, Homonym (Priv));
10275 Set_Is_Immediately_Visible (Full, Is_Immediately_Visible (Priv));
10276 Set_Is_Public (Full, Is_Public (Priv));
10277 Set_Is_Pure (Full, Is_Pure (Priv));
10278 Set_Is_Tagged_Type (Full, Is_Tagged_Type (Priv));
10279 Set_Has_Pragma_Unreferenced (Full, Has_Pragma_Unreferenced (Priv));
10280 Set_Has_Pragma_Unreferenced_Objects
10281 (Full, Has_Pragma_Unreferenced_Objects
10284 Conditional_Delay (Full, Priv);
10286 if Is_Tagged_Type (Full) then
10287 Set_Primitive_Operations (Full, Primitive_Operations (Priv));
10289 if Priv = Base_Type (Priv) then
10290 Set_Class_Wide_Type (Full, Class_Wide_Type (Priv));
10294 Set_Is_Volatile (Full, Is_Volatile (Priv));
10295 Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv));
10296 Set_Scope (Full, Scope (Priv));
10297 Set_Next_Entity (Full, Next_Entity (Priv));
10298 Set_First_Entity (Full, First_Entity (Priv));
10299 Set_Last_Entity (Full, Last_Entity (Priv));
10301 -- If access types have been recorded for later handling, keep them in
10302 -- the full view so that they get handled when the full view freeze
10303 -- node is expanded.
10305 if Present (Freeze_Node (Priv))
10306 and then Present (Access_Types_To_Process (Freeze_Node (Priv)))
10308 Ensure_Freeze_Node (Full);
10309 Set_Access_Types_To_Process
10310 (Freeze_Node (Full),
10311 Access_Types_To_Process (Freeze_Node (Priv)));
10314 -- Swap the two entities. Now Privat is the full type entity and
10315 -- Full is the private one. They will be swapped back at the end
10316 -- of the private part. This swapping ensures that the entity that
10317 -- is visible in the private part is the full declaration.
10319 Exchange_Entities (Priv, Full);
10320 Append_Entity (Full, Scope (Full));
10323 -------------------------------------
10324 -- Copy_Array_Base_Type_Attributes --
10325 -------------------------------------
10327 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id) is
10329 Set_Component_Alignment (T1, Component_Alignment (T2));
10330 Set_Component_Type (T1, Component_Type (T2));
10331 Set_Component_Size (T1, Component_Size (T2));
10332 Set_Has_Controlled_Component (T1, Has_Controlled_Component (T2));
10333 Set_Finalize_Storage_Only (T1, Finalize_Storage_Only (T2));
10334 Set_Has_Non_Standard_Rep (T1, Has_Non_Standard_Rep (T2));
10335 Set_Has_Task (T1, Has_Task (T2));
10336 Set_Is_Packed (T1, Is_Packed (T2));
10337 Set_Has_Aliased_Components (T1, Has_Aliased_Components (T2));
10338 Set_Has_Atomic_Components (T1, Has_Atomic_Components (T2));
10339 Set_Has_Volatile_Components (T1, Has_Volatile_Components (T2));
10340 end Copy_Array_Base_Type_Attributes;
10342 -----------------------------------
10343 -- Copy_Array_Subtype_Attributes --
10344 -----------------------------------
10346 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id) is
10348 Set_Size_Info (T1, T2);
10350 Set_First_Index (T1, First_Index (T2));
10351 Set_Is_Aliased (T1, Is_Aliased (T2));
10352 Set_Is_Atomic (T1, Is_Atomic (T2));
10353 Set_Is_Volatile (T1, Is_Volatile (T2));
10354 Set_Treat_As_Volatile (T1, Treat_As_Volatile (T2));
10355 Set_Is_Constrained (T1, Is_Constrained (T2));
10356 Set_Depends_On_Private (T1, Has_Private_Component (T2));
10357 Set_First_Rep_Item (T1, First_Rep_Item (T2));
10358 Set_Convention (T1, Convention (T2));
10359 Set_Is_Limited_Composite (T1, Is_Limited_Composite (T2));
10360 Set_Is_Private_Composite (T1, Is_Private_Composite (T2));
10361 end Copy_Array_Subtype_Attributes;
10363 -----------------------------------
10364 -- Create_Constrained_Components --
10365 -----------------------------------
10367 procedure Create_Constrained_Components
10369 Decl_Node : Node_Id;
10371 Constraints : Elist_Id)
10373 Loc : constant Source_Ptr := Sloc (Subt);
10374 Comp_List : constant Elist_Id := New_Elmt_List;
10375 Parent_Type : constant Entity_Id := Etype (Typ);
10376 Assoc_List : constant List_Id := New_List;
10377 Discr_Val : Elmt_Id;
10381 Is_Static : Boolean := True;
10383 procedure Collect_Fixed_Components (Typ : Entity_Id);
10384 -- Collect parent type components that do not appear in a variant part
10386 procedure Create_All_Components;
10387 -- Iterate over Comp_List to create the components of the subtype
10389 function Create_Component (Old_Compon : Entity_Id) return Entity_Id;
10390 -- Creates a new component from Old_Compon, copying all the fields from
10391 -- it, including its Etype, inserts the new component in the Subt entity
10392 -- chain and returns the new component.
10394 function Is_Variant_Record (T : Entity_Id) return Boolean;
10395 -- If true, and discriminants are static, collect only components from
10396 -- variants selected by discriminant values.
10398 ------------------------------
10399 -- Collect_Fixed_Components --
10400 ------------------------------
10402 procedure Collect_Fixed_Components (Typ : Entity_Id) is
10404 -- Build association list for discriminants, and find components of the
10405 -- variant part selected by the values of the discriminants.
10407 Old_C := First_Discriminant (Typ);
10408 Discr_Val := First_Elmt (Constraints);
10409 while Present (Old_C) loop
10410 Append_To (Assoc_List,
10411 Make_Component_Association (Loc,
10412 Choices => New_List (New_Occurrence_Of (Old_C, Loc)),
10413 Expression => New_Copy (Node (Discr_Val))));
10415 Next_Elmt (Discr_Val);
10416 Next_Discriminant (Old_C);
10419 -- The tag, and the possible parent and controller components
10420 -- are unconditionally in the subtype.
10422 if Is_Tagged_Type (Typ)
10423 or else Has_Controlled_Component (Typ)
10425 Old_C := First_Component (Typ);
10426 while Present (Old_C) loop
10427 if Chars ((Old_C)) = Name_uTag
10428 or else Chars ((Old_C)) = Name_uParent
10429 or else Chars ((Old_C)) = Name_uController
10431 Append_Elmt (Old_C, Comp_List);
10434 Next_Component (Old_C);
10437 end Collect_Fixed_Components;
10439 ---------------------------
10440 -- Create_All_Components --
10441 ---------------------------
10443 procedure Create_All_Components is
10447 Comp := First_Elmt (Comp_List);
10448 while Present (Comp) loop
10449 Old_C := Node (Comp);
10450 New_C := Create_Component (Old_C);
10454 Constrain_Component_Type
10455 (Old_C, Subt, Decl_Node, Typ, Constraints));
10456 Set_Is_Public (New_C, Is_Public (Subt));
10460 end Create_All_Components;
10462 ----------------------
10463 -- Create_Component --
10464 ----------------------
10466 function Create_Component (Old_Compon : Entity_Id) return Entity_Id is
10467 New_Compon : constant Entity_Id := New_Copy (Old_Compon);
10470 if Ekind (Old_Compon) = E_Discriminant
10471 and then Is_Completely_Hidden (Old_Compon)
10473 -- This is a shadow discriminant created for a discriminant of
10474 -- the parent type that is one of several renamed by the same
10475 -- new discriminant. Give the shadow discriminant an internal
10476 -- name that cannot conflict with that of visible components.
10478 Set_Chars (New_Compon, New_Internal_Name ('C'));
10481 -- Set the parent so we have a proper link for freezing etc. This is
10482 -- not a real parent pointer, since of course our parent does not own
10483 -- up to us and reference us, we are an illegitimate child of the
10484 -- original parent!
10486 Set_Parent (New_Compon, Parent (Old_Compon));
10488 -- If the old component's Esize was already determined and is a
10489 -- static value, then the new component simply inherits it. Otherwise
10490 -- the old component's size may require run-time determination, but
10491 -- the new component's size still might be statically determinable
10492 -- (if, for example it has a static constraint). In that case we want
10493 -- Layout_Type to recompute the component's size, so we reset its
10494 -- size and positional fields.
10496 if Frontend_Layout_On_Target
10497 and then not Known_Static_Esize (Old_Compon)
10499 Set_Esize (New_Compon, Uint_0);
10500 Init_Normalized_First_Bit (New_Compon);
10501 Init_Normalized_Position (New_Compon);
10502 Init_Normalized_Position_Max (New_Compon);
10505 -- We do not want this node marked as Comes_From_Source, since
10506 -- otherwise it would get first class status and a separate cross-
10507 -- reference line would be generated. Illegitimate children do not
10508 -- rate such recognition.
10510 Set_Comes_From_Source (New_Compon, False);
10512 -- But it is a real entity, and a birth certificate must be properly
10513 -- registered by entering it into the entity list.
10515 Enter_Name (New_Compon);
10518 end Create_Component;
10520 -----------------------
10521 -- Is_Variant_Record --
10522 -----------------------
10524 function Is_Variant_Record (T : Entity_Id) return Boolean is
10526 return Nkind (Parent (T)) = N_Full_Type_Declaration
10527 and then Nkind (Type_Definition (Parent (T))) = N_Record_Definition
10528 and then Present (Component_List (Type_Definition (Parent (T))))
10531 (Variant_Part (Component_List (Type_Definition (Parent (T)))));
10532 end Is_Variant_Record;
10534 -- Start of processing for Create_Constrained_Components
10537 pragma Assert (Subt /= Base_Type (Subt));
10538 pragma Assert (Typ = Base_Type (Typ));
10540 Set_First_Entity (Subt, Empty);
10541 Set_Last_Entity (Subt, Empty);
10543 -- Check whether constraint is fully static, in which case we can
10544 -- optimize the list of components.
10546 Discr_Val := First_Elmt (Constraints);
10547 while Present (Discr_Val) loop
10548 if not Is_OK_Static_Expression (Node (Discr_Val)) then
10549 Is_Static := False;
10553 Next_Elmt (Discr_Val);
10556 Set_Has_Static_Discriminants (Subt, Is_Static);
10560 -- Inherit the discriminants of the parent type
10562 Add_Discriminants : declare
10568 Old_C := First_Discriminant (Typ);
10570 while Present (Old_C) loop
10571 Num_Disc := Num_Disc + 1;
10572 New_C := Create_Component (Old_C);
10573 Set_Is_Public (New_C, Is_Public (Subt));
10574 Next_Discriminant (Old_C);
10577 -- For an untagged derived subtype, the number of discriminants may
10578 -- be smaller than the number of inherited discriminants, because
10579 -- several of them may be renamed by a single new discriminant.
10580 -- In this case, add the hidden discriminants back into the subtype,
10581 -- because otherwise the size of the subtype is computed incorrectly
10586 if Is_Derived_Type (Typ)
10587 and then not Is_Tagged_Type (Typ)
10589 Old_C := First_Stored_Discriminant (Typ);
10591 while Present (Old_C) loop
10592 Num_Gird := Num_Gird + 1;
10593 Next_Stored_Discriminant (Old_C);
10597 if Num_Gird > Num_Disc then
10599 -- Find out multiple uses of new discriminants, and add hidden
10600 -- components for the extra renamed discriminants. We recognize
10601 -- multiple uses through the Corresponding_Discriminant of a
10602 -- new discriminant: if it constrains several old discriminants,
10603 -- this field points to the last one in the parent type. The
10604 -- stored discriminants of the derived type have the same name
10605 -- as those of the parent.
10609 New_Discr : Entity_Id;
10610 Old_Discr : Entity_Id;
10613 Constr := First_Elmt (Stored_Constraint (Typ));
10614 Old_Discr := First_Stored_Discriminant (Typ);
10615 while Present (Constr) loop
10616 if Is_Entity_Name (Node (Constr))
10617 and then Ekind (Entity (Node (Constr))) = E_Discriminant
10619 New_Discr := Entity (Node (Constr));
10621 if Chars (Corresponding_Discriminant (New_Discr)) /=
10624 -- The new discriminant has been used to rename a
10625 -- subsequent old discriminant. Introduce a shadow
10626 -- component for the current old discriminant.
10628 New_C := Create_Component (Old_Discr);
10629 Set_Original_Record_Component (New_C, Old_Discr);
10633 Next_Elmt (Constr);
10634 Next_Stored_Discriminant (Old_Discr);
10638 end Add_Discriminants;
10641 and then Is_Variant_Record (Typ)
10643 Collect_Fixed_Components (Typ);
10645 Gather_Components (
10647 Component_List (Type_Definition (Parent (Typ))),
10648 Governed_By => Assoc_List,
10650 Report_Errors => Errors);
10651 pragma Assert (not Errors);
10653 Create_All_Components;
10655 -- If the subtype declaration is created for a tagged type derivation
10656 -- with constraints, we retrieve the record definition of the parent
10657 -- type to select the components of the proper variant.
10660 and then Is_Tagged_Type (Typ)
10661 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
10663 Nkind (Type_Definition (Parent (Typ))) = N_Derived_Type_Definition
10664 and then Is_Variant_Record (Parent_Type)
10666 Collect_Fixed_Components (Typ);
10668 Gather_Components (
10670 Component_List (Type_Definition (Parent (Parent_Type))),
10671 Governed_By => Assoc_List,
10673 Report_Errors => Errors);
10674 pragma Assert (not Errors);
10676 -- If the tagged derivation has a type extension, collect all the
10677 -- new components therein.
10680 (Record_Extension_Part (Type_Definition (Parent (Typ))))
10682 Old_C := First_Component (Typ);
10683 while Present (Old_C) loop
10684 if Original_Record_Component (Old_C) = Old_C
10685 and then Chars (Old_C) /= Name_uTag
10686 and then Chars (Old_C) /= Name_uParent
10687 and then Chars (Old_C) /= Name_uController
10689 Append_Elmt (Old_C, Comp_List);
10692 Next_Component (Old_C);
10696 Create_All_Components;
10699 -- If discriminants are not static, or if this is a multi-level type
10700 -- extension, we have to include all components of the parent type.
10702 Old_C := First_Component (Typ);
10703 while Present (Old_C) loop
10704 New_C := Create_Component (Old_C);
10708 Constrain_Component_Type
10709 (Old_C, Subt, Decl_Node, Typ, Constraints));
10710 Set_Is_Public (New_C, Is_Public (Subt));
10712 Next_Component (Old_C);
10717 end Create_Constrained_Components;
10719 ------------------------------------------
10720 -- Decimal_Fixed_Point_Type_Declaration --
10721 ------------------------------------------
10723 procedure Decimal_Fixed_Point_Type_Declaration
10727 Loc : constant Source_Ptr := Sloc (Def);
10728 Digs_Expr : constant Node_Id := Digits_Expression (Def);
10729 Delta_Expr : constant Node_Id := Delta_Expression (Def);
10730 Implicit_Base : Entity_Id;
10736 -- Start of processing for Decimal_Fixed_Point_Type_Declaration
10739 Check_Restriction (No_Fixed_Point, Def);
10741 -- Create implicit base type
10744 Create_Itype (E_Decimal_Fixed_Point_Type, Parent (Def), T, 'B');
10745 Set_Etype (Implicit_Base, Implicit_Base);
10747 -- Analyze and process delta expression
10749 Analyze_And_Resolve (Delta_Expr, Universal_Real);
10751 Check_Delta_Expression (Delta_Expr);
10752 Delta_Val := Expr_Value_R (Delta_Expr);
10754 -- Check delta is power of 10, and determine scale value from it
10760 Scale_Val := Uint_0;
10763 if Val < Ureal_1 then
10764 while Val < Ureal_1 loop
10765 Val := Val * Ureal_10;
10766 Scale_Val := Scale_Val + 1;
10769 if Scale_Val > 18 then
10770 Error_Msg_N ("scale exceeds maximum value of 18", Def);
10771 Scale_Val := UI_From_Int (+18);
10775 while Val > Ureal_1 loop
10776 Val := Val / Ureal_10;
10777 Scale_Val := Scale_Val - 1;
10780 if Scale_Val < -18 then
10781 Error_Msg_N ("scale is less than minimum value of -18", Def);
10782 Scale_Val := UI_From_Int (-18);
10786 if Val /= Ureal_1 then
10787 Error_Msg_N ("delta expression must be a power of 10", Def);
10788 Delta_Val := Ureal_10 ** (-Scale_Val);
10792 -- Set delta, scale and small (small = delta for decimal type)
10794 Set_Delta_Value (Implicit_Base, Delta_Val);
10795 Set_Scale_Value (Implicit_Base, Scale_Val);
10796 Set_Small_Value (Implicit_Base, Delta_Val);
10798 -- Analyze and process digits expression
10800 Analyze_And_Resolve (Digs_Expr, Any_Integer);
10801 Check_Digits_Expression (Digs_Expr);
10802 Digs_Val := Expr_Value (Digs_Expr);
10804 if Digs_Val > 18 then
10805 Digs_Val := UI_From_Int (+18);
10806 Error_Msg_N ("digits value out of range, maximum is 18", Digs_Expr);
10809 Set_Digits_Value (Implicit_Base, Digs_Val);
10810 Bound_Val := UR_From_Uint (10 ** Digs_Val - 1) * Delta_Val;
10812 -- Set range of base type from digits value for now. This will be
10813 -- expanded to represent the true underlying base range by Freeze.
10815 Set_Fixed_Range (Implicit_Base, Loc, -Bound_Val, Bound_Val);
10817 -- Set size to zero for now, size will be set at freeze time. We have
10818 -- to do this for ordinary fixed-point, because the size depends on
10819 -- the specified small, and we might as well do the same for decimal
10822 Init_Size_Align (Implicit_Base);
10824 -- If there are bounds given in the declaration use them as the
10825 -- bounds of the first named subtype.
10827 if Present (Real_Range_Specification (Def)) then
10829 RRS : constant Node_Id := Real_Range_Specification (Def);
10830 Low : constant Node_Id := Low_Bound (RRS);
10831 High : constant Node_Id := High_Bound (RRS);
10836 Analyze_And_Resolve (Low, Any_Real);
10837 Analyze_And_Resolve (High, Any_Real);
10838 Check_Real_Bound (Low);
10839 Check_Real_Bound (High);
10840 Low_Val := Expr_Value_R (Low);
10841 High_Val := Expr_Value_R (High);
10843 if Low_Val < (-Bound_Val) then
10845 ("range low bound too small for digits value", Low);
10846 Low_Val := -Bound_Val;
10849 if High_Val > Bound_Val then
10851 ("range high bound too large for digits value", High);
10852 High_Val := Bound_Val;
10855 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
10858 -- If no explicit range, use range that corresponds to given
10859 -- digits value. This will end up as the final range for the
10863 Set_Fixed_Range (T, Loc, -Bound_Val, Bound_Val);
10866 -- Complete entity for first subtype
10868 Set_Ekind (T, E_Decimal_Fixed_Point_Subtype);
10869 Set_Etype (T, Implicit_Base);
10870 Set_Size_Info (T, Implicit_Base);
10871 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
10872 Set_Digits_Value (T, Digs_Val);
10873 Set_Delta_Value (T, Delta_Val);
10874 Set_Small_Value (T, Delta_Val);
10875 Set_Scale_Value (T, Scale_Val);
10876 Set_Is_Constrained (T);
10877 end Decimal_Fixed_Point_Type_Declaration;
10879 ----------------------------------
10880 -- Derive_Interface_Subprograms --
10881 ----------------------------------
10883 procedure Derive_Interface_Subprograms
10884 (Parent_Type : Entity_Id;
10885 Tagged_Type : Entity_Id;
10886 Ifaces_List : Elist_Id)
10888 function Collect_Interface_Primitives
10889 (Tagged_Type : Entity_Id) return Elist_Id;
10890 -- Ada 2005 (AI-251): Collect the primitives of all the implemented
10893 function In_List (L : Elist_Id; Subp : Entity_Id) return Boolean;
10894 -- Determine if Subp already in the list L
10896 procedure Remove_Homonym (E : Entity_Id);
10897 -- Removes E from the homonym chain
10899 ----------------------------------
10900 -- Collect_Interface_Primitives --
10901 ----------------------------------
10903 function Collect_Interface_Primitives
10904 (Tagged_Type : Entity_Id) return Elist_Id
10906 Op_List : constant Elist_Id := New_Elmt_List;
10908 Ifaces_List : Elist_Id;
10909 Iface_Elmt : Elmt_Id;
10913 pragma Assert (Is_Tagged_Type (Tagged_Type)
10914 and then Has_Abstract_Interfaces (Tagged_Type));
10916 Collect_Abstract_Interfaces (Tagged_Type, Ifaces_List);
10918 Iface_Elmt := First_Elmt (Ifaces_List);
10919 while Present (Iface_Elmt) loop
10920 Elmt := First_Elmt (Primitive_Operations (Node (Iface_Elmt)));
10922 while Present (Elmt) loop
10923 Prim := Node (Elmt);
10925 if not Is_Predefined_Dispatching_Operation (Prim) then
10926 Append_Elmt (Prim, Op_List);
10932 Next_Elmt (Iface_Elmt);
10936 end Collect_Interface_Primitives;
10942 function In_List (L : Elist_Id; Subp : Entity_Id) return Boolean is
10945 Elmt := First_Elmt (L);
10946 while Present (Elmt) loop
10947 if Node (Elmt) = Subp then
10957 --------------------
10958 -- Remove_Homonym --
10959 --------------------
10961 procedure Remove_Homonym (E : Entity_Id) is
10962 Prev : Entity_Id := Empty;
10966 if E = Current_Entity (E) then
10967 Set_Current_Entity (Homonym (E));
10969 H := Current_Entity (E);
10970 while Present (H) and then H /= E loop
10975 Set_Homonym (Prev, Homonym (E));
10977 end Remove_Homonym;
10984 Iface_Subp : Entity_Id;
10985 New_Subp : Entity_Id := Empty;
10986 Op_List : Elist_Id;
10987 Parent_Base : Entity_Id;
10990 -- Start of processing for Derive_Interface_Subprograms
10993 if Ada_Version < Ada_05
10994 or else not Is_Record_Type (Tagged_Type)
10995 or else not Is_Tagged_Type (Tagged_Type)
10996 or else not Has_Abstract_Interfaces (Tagged_Type)
11001 -- Add to the list of interface subprograms all the primitives inherited
11002 -- from abstract interfaces that are not immediate ancestors and also
11003 -- add their derivation to the list of interface primitives.
11005 Op_List := Collect_Interface_Primitives (Tagged_Type);
11007 Elmt := First_Elmt (Op_List);
11008 while Present (Elmt) loop
11009 Subp := Node (Elmt);
11010 Iface := Find_Dispatching_Type (Subp);
11012 if Is_Concurrent_Record_Type (Tagged_Type) then
11013 if not Present (Abstract_Interface_Alias (Subp)) then
11014 Derive_Subprogram (New_Subp, Subp, Tagged_Type, Iface);
11015 Append_Elmt (New_Subp, Ifaces_List);
11018 elsif not Is_Parent (Iface, Tagged_Type) then
11019 Derive_Subprogram (New_Subp, Subp, Tagged_Type, Iface);
11020 Append_Elmt (New_Subp, Ifaces_List);
11026 -- Complete the derivation of the interface subprograms. Assignate to
11027 -- each entity associated with abstract interfaces their aliased entity
11028 -- and complete their decoration as hidden interface entities that will
11029 -- be used later to build the secondary dispatch tables.
11031 if not Is_Empty_Elmt_List (Ifaces_List) then
11032 if Ekind (Parent_Type) = E_Record_Type_With_Private
11033 and then Has_Discriminants (Parent_Type)
11034 and then Present (Full_View (Parent_Type))
11036 Parent_Base := Full_View (Parent_Type);
11038 Parent_Base := Parent_Type;
11041 Elmt := First_Elmt (Ifaces_List);
11042 while Present (Elmt) loop
11043 Iface_Subp := Node (Elmt);
11045 -- Look for the first overriding entity in the homonym chain.
11046 -- In this way if we are in the private part of a package spec
11047 -- we get the last overriding subprogram.
11049 E := Current_Entity_In_Scope (Iface_Subp);
11050 while Present (E) loop
11051 if Is_Dispatching_Operation (E)
11052 and then Scope (E) = Scope (Iface_Subp)
11053 and then Type_Conformant (E, Iface_Subp)
11054 and then not In_List (Ifaces_List, E)
11062 -- Create an overriding entity if not found in the homonym chain
11064 if not Present (E) then
11066 (E, Alias (Iface_Subp), Tagged_Type, Parent_Base);
11068 elsif not In_List (Primitive_Operations (Tagged_Type), E) then
11070 -- Inherit the operation from the private view
11072 Append_Elmt (E, Primitive_Operations (Tagged_Type));
11075 -- Complete the decoration of the hidden interface entity
11077 Set_Is_Hidden (Iface_Subp);
11078 Set_Abstract_Interface_Alias (Iface_Subp, Alias (Iface_Subp));
11079 Set_Alias (Iface_Subp, E);
11080 Set_Is_Abstract_Subprogram (Iface_Subp,
11081 Is_Abstract_Subprogram (E));
11082 Remove_Homonym (Iface_Subp);
11084 -- Hidden entities associated with interfaces must have set the
11085 -- Has_Delay_Freeze attribute to ensure that the corresponding
11086 -- entry of the secondary dispatch table is filled when such
11087 -- entity is frozen.
11089 Set_Has_Delayed_Freeze (Iface_Subp);
11094 end Derive_Interface_Subprograms;
11096 -----------------------
11097 -- Derive_Subprogram --
11098 -----------------------
11100 procedure Derive_Subprogram
11101 (New_Subp : in out Entity_Id;
11102 Parent_Subp : Entity_Id;
11103 Derived_Type : Entity_Id;
11104 Parent_Type : Entity_Id;
11105 Actual_Subp : Entity_Id := Empty)
11107 Formal : Entity_Id;
11108 New_Formal : Entity_Id;
11109 Visible_Subp : Entity_Id := Parent_Subp;
11111 function Is_Private_Overriding return Boolean;
11112 -- If Subp is a private overriding of a visible operation, the in-
11113 -- herited operation derives from the overridden op (even though
11114 -- its body is the overriding one) and the inherited operation is
11115 -- visible now. See sem_disp to see the details of the handling of
11116 -- the overridden subprogram, which is removed from the list of
11117 -- primitive operations of the type. The overridden subprogram is
11118 -- saved locally in Visible_Subp, and used to diagnose abstract
11119 -- operations that need overriding in the derived type.
11121 procedure Replace_Type (Id, New_Id : Entity_Id);
11122 -- When the type is an anonymous access type, create a new access type
11123 -- designating the derived type.
11125 procedure Set_Derived_Name;
11126 -- This procedure sets the appropriate Chars name for New_Subp. This
11127 -- is normally just a copy of the parent name. An exception arises for
11128 -- type support subprograms, where the name is changed to reflect the
11129 -- name of the derived type, e.g. if type foo is derived from type bar,
11130 -- then a procedure barDA is derived with a name fooDA.
11132 ---------------------------
11133 -- Is_Private_Overriding --
11134 ---------------------------
11136 function Is_Private_Overriding return Boolean is
11140 -- If the parent is not a dispatching operation there is no
11141 -- need to investigate overridings
11143 if not Is_Dispatching_Operation (Parent_Subp) then
11147 -- The visible operation that is overridden is a homonym of the
11148 -- parent subprogram. We scan the homonym chain to find the one
11149 -- whose alias is the subprogram we are deriving.
11151 Prev := Current_Entity (Parent_Subp);
11152 while Present (Prev) loop
11153 if Ekind (Prev) = Ekind (Parent_Subp)
11154 and then Alias (Prev) = Parent_Subp
11155 and then Scope (Parent_Subp) = Scope (Prev)
11156 and then not Is_Hidden (Prev)
11158 Visible_Subp := Prev;
11162 Prev := Homonym (Prev);
11166 end Is_Private_Overriding;
11172 procedure Replace_Type (Id, New_Id : Entity_Id) is
11173 Acc_Type : Entity_Id;
11174 Par : constant Node_Id := Parent (Derived_Type);
11177 -- When the type is an anonymous access type, create a new access
11178 -- type designating the derived type. This itype must be elaborated
11179 -- at the point of the derivation, not on subsequent calls that may
11180 -- be out of the proper scope for Gigi, so we insert a reference to
11181 -- it after the derivation.
11183 if Ekind (Etype (Id)) = E_Anonymous_Access_Type then
11185 Desig_Typ : Entity_Id := Designated_Type (Etype (Id));
11188 if Ekind (Desig_Typ) = E_Record_Type_With_Private
11189 and then Present (Full_View (Desig_Typ))
11190 and then not Is_Private_Type (Parent_Type)
11192 Desig_Typ := Full_View (Desig_Typ);
11195 if Base_Type (Desig_Typ) = Base_Type (Parent_Type)
11197 -- Ada 2005 (AI-251): Handle also derivations of abstract
11198 -- interface primitives.
11200 or else (Is_Interface (Desig_Typ)
11201 and then not Is_Class_Wide_Type (Desig_Typ))
11203 Acc_Type := New_Copy (Etype (Id));
11204 Set_Etype (Acc_Type, Acc_Type);
11205 Set_Scope (Acc_Type, New_Subp);
11207 -- Compute size of anonymous access type
11209 if Is_Array_Type (Desig_Typ)
11210 and then not Is_Constrained (Desig_Typ)
11212 Init_Size (Acc_Type, 2 * System_Address_Size);
11214 Init_Size (Acc_Type, System_Address_Size);
11217 Init_Alignment (Acc_Type);
11218 Set_Directly_Designated_Type (Acc_Type, Derived_Type);
11220 Set_Etype (New_Id, Acc_Type);
11221 Set_Scope (New_Id, New_Subp);
11223 -- Create a reference to it
11224 Build_Itype_Reference (Acc_Type, Parent (Derived_Type));
11227 Set_Etype (New_Id, Etype (Id));
11231 elsif Base_Type (Etype (Id)) = Base_Type (Parent_Type)
11233 (Ekind (Etype (Id)) = E_Record_Type_With_Private
11234 and then Present (Full_View (Etype (Id)))
11236 Base_Type (Full_View (Etype (Id))) = Base_Type (Parent_Type))
11238 -- Constraint checks on formals are generated during expansion,
11239 -- based on the signature of the original subprogram. The bounds
11240 -- of the derived type are not relevant, and thus we can use
11241 -- the base type for the formals. However, the return type may be
11242 -- used in a context that requires that the proper static bounds
11243 -- be used (a case statement, for example) and for those cases
11244 -- we must use the derived type (first subtype), not its base.
11246 -- If the derived_type_definition has no constraints, we know that
11247 -- the derived type has the same constraints as the first subtype
11248 -- of the parent, and we can also use it rather than its base,
11249 -- which can lead to more efficient code.
11251 if Etype (Id) = Parent_Type then
11252 if Is_Scalar_Type (Parent_Type)
11254 Subtypes_Statically_Compatible (Parent_Type, Derived_Type)
11256 Set_Etype (New_Id, Derived_Type);
11258 elsif Nkind (Par) = N_Full_Type_Declaration
11260 Nkind (Type_Definition (Par)) = N_Derived_Type_Definition
11263 (Subtype_Indication (Type_Definition (Par)))
11265 Set_Etype (New_Id, Derived_Type);
11268 Set_Etype (New_Id, Base_Type (Derived_Type));
11272 Set_Etype (New_Id, Base_Type (Derived_Type));
11275 -- Ada 2005 (AI-251): Handle derivations of abstract interface
11278 elsif Is_Interface (Etype (Id))
11279 and then not Is_Class_Wide_Type (Etype (Id))
11281 Set_Etype (New_Id, Derived_Type);
11284 Set_Etype (New_Id, Etype (Id));
11288 ----------------------
11289 -- Set_Derived_Name --
11290 ----------------------
11292 procedure Set_Derived_Name is
11293 Nm : constant TSS_Name_Type := Get_TSS_Name (Parent_Subp);
11295 if Nm = TSS_Null then
11296 Set_Chars (New_Subp, Chars (Parent_Subp));
11298 Set_Chars (New_Subp, Make_TSS_Name (Base_Type (Derived_Type), Nm));
11300 end Set_Derived_Name;
11302 -- Start of processing for Derive_Subprogram
11306 New_Entity (Nkind (Parent_Subp), Sloc (Derived_Type));
11307 Set_Ekind (New_Subp, Ekind (Parent_Subp));
11309 -- Check whether the inherited subprogram is a private operation that
11310 -- should be inherited but not yet made visible. Such subprograms can
11311 -- become visible at a later point (e.g., the private part of a public
11312 -- child unit) via Declare_Inherited_Private_Subprograms. If the
11313 -- following predicate is true, then this is not such a private
11314 -- operation and the subprogram simply inherits the name of the parent
11315 -- subprogram. Note the special check for the names of controlled
11316 -- operations, which are currently exempted from being inherited with
11317 -- a hidden name because they must be findable for generation of
11318 -- implicit run-time calls.
11320 if not Is_Hidden (Parent_Subp)
11321 or else Is_Internal (Parent_Subp)
11322 or else Is_Private_Overriding
11323 or else Is_Internal_Name (Chars (Parent_Subp))
11324 or else Chars (Parent_Subp) = Name_Initialize
11325 or else Chars (Parent_Subp) = Name_Adjust
11326 or else Chars (Parent_Subp) = Name_Finalize
11330 -- If parent is hidden, this can be a regular derivation if the
11331 -- parent is immediately visible in a non-instantiating context,
11332 -- or if we are in the private part of an instance. This test
11333 -- should still be refined ???
11335 -- The test for In_Instance_Not_Visible avoids inheriting the derived
11336 -- operation as a non-visible operation in cases where the parent
11337 -- subprogram might not be visible now, but was visible within the
11338 -- original generic, so it would be wrong to make the inherited
11339 -- subprogram non-visible now. (Not clear if this test is fully
11340 -- correct; are there any cases where we should declare the inherited
11341 -- operation as not visible to avoid it being overridden, e.g., when
11342 -- the parent type is a generic actual with private primitives ???)
11344 -- (they should be treated the same as other private inherited
11345 -- subprograms, but it's not clear how to do this cleanly). ???
11347 elsif (In_Open_Scopes (Scope (Base_Type (Parent_Type)))
11348 and then Is_Immediately_Visible (Parent_Subp)
11349 and then not In_Instance)
11350 or else In_Instance_Not_Visible
11354 -- Ada 2005 (AI-251): Hidden entity associated with abstract interface
11357 elsif Present (Abstract_Interface_Alias (Parent_Subp)) then
11360 -- The type is inheriting a private operation, so enter
11361 -- it with a special name so it can't be overridden.
11364 Set_Chars (New_Subp, New_External_Name (Chars (Parent_Subp), 'P'));
11367 Set_Parent (New_Subp, Parent (Derived_Type));
11368 Replace_Type (Parent_Subp, New_Subp);
11369 Conditional_Delay (New_Subp, Parent_Subp);
11371 Formal := First_Formal (Parent_Subp);
11372 while Present (Formal) loop
11373 New_Formal := New_Copy (Formal);
11375 -- Normally we do not go copying parents, but in the case of
11376 -- formals, we need to link up to the declaration (which is the
11377 -- parameter specification), and it is fine to link up to the
11378 -- original formal's parameter specification in this case.
11380 Set_Parent (New_Formal, Parent (Formal));
11382 Append_Entity (New_Formal, New_Subp);
11384 Replace_Type (Formal, New_Formal);
11385 Next_Formal (Formal);
11388 -- If this derivation corresponds to a tagged generic actual, then
11389 -- primitive operations rename those of the actual. Otherwise the
11390 -- primitive operations rename those of the parent type, If the
11391 -- parent renames an intrinsic operator, so does the new subprogram.
11392 -- We except concatenation, which is always properly typed, and does
11393 -- not get expanded as other intrinsic operations.
11395 if No (Actual_Subp) then
11396 if Is_Intrinsic_Subprogram (Parent_Subp) then
11397 Set_Is_Intrinsic_Subprogram (New_Subp);
11399 if Present (Alias (Parent_Subp))
11400 and then Chars (Parent_Subp) /= Name_Op_Concat
11402 Set_Alias (New_Subp, Alias (Parent_Subp));
11404 Set_Alias (New_Subp, Parent_Subp);
11408 Set_Alias (New_Subp, Parent_Subp);
11412 Set_Alias (New_Subp, Actual_Subp);
11415 -- Derived subprograms of a tagged type must inherit the convention
11416 -- of the parent subprogram (a requirement of AI-117). Derived
11417 -- subprograms of untagged types simply get convention Ada by default.
11419 if Is_Tagged_Type (Derived_Type) then
11420 Set_Convention (New_Subp, Convention (Parent_Subp));
11423 Set_Is_Imported (New_Subp, Is_Imported (Parent_Subp));
11424 Set_Is_Exported (New_Subp, Is_Exported (Parent_Subp));
11426 if Ekind (Parent_Subp) = E_Procedure then
11427 Set_Is_Valued_Procedure
11428 (New_Subp, Is_Valued_Procedure (Parent_Subp));
11431 -- No_Return must be inherited properly. If this is overridden in the
11432 -- case of a dispatching operation, then a check is made in Sem_Disp
11433 -- that the overriding operation is also No_Return (no such check is
11434 -- required for the case of non-dispatching operation.
11436 Set_No_Return (New_Subp, No_Return (Parent_Subp));
11438 -- A derived function with a controlling result is abstract. If the
11439 -- Derived_Type is a nonabstract formal generic derived type, then
11440 -- inherited operations are not abstract: the required check is done at
11441 -- instantiation time. If the derivation is for a generic actual, the
11442 -- function is not abstract unless the actual is.
11444 if Is_Generic_Type (Derived_Type)
11445 and then not Is_Abstract_Type (Derived_Type)
11449 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
11450 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2).
11452 elsif Ada_Version >= Ada_05
11453 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11454 or else (Is_Tagged_Type (Derived_Type)
11455 and then Etype (New_Subp) = Derived_Type
11456 and then not Is_Null_Extension (Derived_Type))
11457 or else (Is_Tagged_Type (Derived_Type)
11458 and then Ekind (Etype (New_Subp)) =
11459 E_Anonymous_Access_Type
11460 and then Designated_Type (Etype (New_Subp)) =
11462 and then not Is_Null_Extension (Derived_Type)))
11463 and then No (Actual_Subp)
11465 if not Is_Tagged_Type (Derived_Type)
11466 or else Is_Abstract_Type (Derived_Type)
11467 or else Is_Abstract_Subprogram (Alias (New_Subp))
11469 Set_Is_Abstract_Subprogram (New_Subp);
11471 Set_Requires_Overriding (New_Subp);
11474 elsif Ada_Version < Ada_05
11475 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11476 or else (Is_Tagged_Type (Derived_Type)
11477 and then Etype (New_Subp) = Derived_Type
11478 and then No (Actual_Subp)))
11480 Set_Is_Abstract_Subprogram (New_Subp);
11482 -- Finally, if the parent type is abstract we must verify that all
11483 -- inherited operations are either non-abstract or overridden, or
11484 -- that the derived type itself is abstract (this check is performed
11485 -- at the end of a package declaration, in Check_Abstract_Overriding).
11486 -- A private overriding in the parent type will not be visible in the
11487 -- derivation if we are not in an inner package or in a child unit of
11488 -- the parent type, in which case the abstractness of the inherited
11489 -- operation is carried to the new subprogram.
11491 elsif Is_Abstract_Type (Parent_Type)
11492 and then not In_Open_Scopes (Scope (Parent_Type))
11493 and then Is_Private_Overriding
11494 and then Is_Abstract_Subprogram (Visible_Subp)
11496 if No (Actual_Subp) then
11497 Set_Alias (New_Subp, Visible_Subp);
11498 Set_Is_Abstract_Subprogram
11501 -- If this is a derivation for an instance of a formal derived
11502 -- type, abstractness comes from the primitive operation of the
11503 -- actual, not from the operation inherited from the ancestor.
11505 Set_Is_Abstract_Subprogram
11506 (New_Subp, Is_Abstract_Subprogram (Actual_Subp));
11510 New_Overloaded_Entity (New_Subp, Derived_Type);
11512 -- Check for case of a derived subprogram for the instantiation of a
11513 -- formal derived tagged type, if so mark the subprogram as dispatching
11514 -- and inherit the dispatching attributes of the parent subprogram. The
11515 -- derived subprogram is effectively renaming of the actual subprogram,
11516 -- so it needs to have the same attributes as the actual.
11518 if Present (Actual_Subp)
11519 and then Is_Dispatching_Operation (Parent_Subp)
11521 Set_Is_Dispatching_Operation (New_Subp);
11523 if Present (DTC_Entity (Parent_Subp)) then
11524 Set_DTC_Entity (New_Subp, DTC_Entity (Parent_Subp));
11525 Set_DT_Position (New_Subp, DT_Position (Parent_Subp));
11529 -- Indicate that a derived subprogram does not require a body and that
11530 -- it does not require processing of default expressions.
11532 Set_Has_Completion (New_Subp);
11533 Set_Default_Expressions_Processed (New_Subp);
11535 if Ekind (New_Subp) = E_Function then
11536 Set_Mechanism (New_Subp, Mechanism (Parent_Subp));
11538 end Derive_Subprogram;
11540 ------------------------
11541 -- Derive_Subprograms --
11542 ------------------------
11544 procedure Derive_Subprograms
11545 (Parent_Type : Entity_Id;
11546 Derived_Type : Entity_Id;
11547 Generic_Actual : Entity_Id := Empty)
11549 Op_List : constant Elist_Id :=
11550 Collect_Primitive_Operations (Parent_Type);
11551 Ifaces_List : constant Elist_Id := New_Elmt_List;
11552 Act_List : Elist_Id;
11553 Act_Elmt : Elmt_Id;
11555 New_Subp : Entity_Id := Empty;
11556 Parent_Base : Entity_Id;
11560 if Ekind (Parent_Type) = E_Record_Type_With_Private
11561 and then Has_Discriminants (Parent_Type)
11562 and then Present (Full_View (Parent_Type))
11564 Parent_Base := Full_View (Parent_Type);
11566 Parent_Base := Parent_Type;
11569 -- Derive primitives inherited from the parent
11571 if Present (Generic_Actual) then
11572 Act_List := Collect_Primitive_Operations (Generic_Actual);
11573 Act_Elmt := First_Elmt (Act_List);
11575 Act_Elmt := No_Elmt;
11578 -- Literals are derived earlier in the process of building the derived
11579 -- type, and are skipped here.
11581 Elmt := First_Elmt (Op_List);
11582 while Present (Elmt) loop
11583 Subp := Node (Elmt);
11585 if Ekind (Subp) /= E_Enumeration_Literal then
11587 if Ada_Version >= Ada_05
11588 and then Present (Abstract_Interface_Alias (Subp))
11592 elsif No (Generic_Actual) then
11593 Derive_Subprogram (New_Subp, Subp, Derived_Type, Parent_Base);
11595 -- Ada 2005 (AI-251): Add the derivation of an abstract
11596 -- interface primitive to the list of entities to which
11597 -- we have to associate an aliased entity.
11599 if Ada_Version >= Ada_05
11600 and then Is_Dispatching_Operation (Subp)
11601 and then Present (Find_Dispatching_Type (Subp))
11602 and then Is_Interface (Find_Dispatching_Type (Subp))
11603 and then not Is_Predefined_Dispatching_Operation (Subp)
11605 Append_Elmt (New_Subp, Ifaces_List);
11610 -- If the generic parent type is present, the derived type
11611 -- is an instance of a formal derived type, and within the
11612 -- instance its operations are those of the actual. We derive
11613 -- from the formal type but make the inherited operations
11614 -- aliases of the corresponding operations of the actual.
11616 if Is_Interface (Parent_Type) then
11618 -- Find the corresponding operation in the generic actual.
11619 -- Given that the actual is not a direct descendant of the
11620 -- parent, as in Ada 95, the primitives are not necessarily
11621 -- in the same order, so we have to traverse the list of
11622 -- primitive operations of the actual to find the one that
11623 -- implements the interface operation.
11625 Act_Elmt := First_Elmt (Act_List);
11627 while Present (Act_Elmt) loop
11629 Abstract_Interface_Alias (Node (Act_Elmt)) = Subp;
11630 Next_Elmt (Act_Elmt);
11634 -- If the formal is not an interface, the actual is a direct
11635 -- descendant and the common primitive operations appear in
11639 (New_Subp, Subp, Derived_Type, Parent_Base, Node (Act_Elmt));
11641 if Present (Act_Elmt) then
11642 Next_Elmt (Act_Elmt);
11650 -- Inherit additional operations from progenitor interfaces.
11651 -- However, if the derived type is a generic actual, there
11652 -- are not new primitive operations for the type, because
11653 -- it has those of the actual, so nothing needs to be done.
11654 -- The renamings generated above are not primitive operations,
11655 -- and their purpose is simply to make the proper operations
11656 -- visible within an instantiation.
11658 if Ada_Version >= Ada_05
11659 and then Is_Tagged_Type (Derived_Type)
11660 and then No (Generic_Actual)
11662 Derive_Interface_Subprograms (Parent_Type, Derived_Type, Ifaces_List);
11664 end Derive_Subprograms;
11666 --------------------------------
11667 -- Derived_Standard_Character --
11668 --------------------------------
11670 procedure Derived_Standard_Character
11672 Parent_Type : Entity_Id;
11673 Derived_Type : Entity_Id)
11675 Loc : constant Source_Ptr := Sloc (N);
11676 Def : constant Node_Id := Type_Definition (N);
11677 Indic : constant Node_Id := Subtype_Indication (Def);
11678 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
11679 Implicit_Base : constant Entity_Id :=
11681 (E_Enumeration_Type, N, Derived_Type, 'B');
11687 Discard_Node (Process_Subtype (Indic, N));
11689 Set_Etype (Implicit_Base, Parent_Base);
11690 Set_Size_Info (Implicit_Base, Root_Type (Parent_Type));
11691 Set_RM_Size (Implicit_Base, RM_Size (Root_Type (Parent_Type)));
11693 Set_Is_Character_Type (Implicit_Base, True);
11694 Set_Has_Delayed_Freeze (Implicit_Base);
11696 -- The bounds of the implicit base are the bounds of the parent base.
11697 -- Note that their type is the parent base.
11699 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
11700 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
11702 Set_Scalar_Range (Implicit_Base,
11705 High_Bound => Hi));
11707 Conditional_Delay (Derived_Type, Parent_Type);
11709 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
11710 Set_Etype (Derived_Type, Implicit_Base);
11711 Set_Size_Info (Derived_Type, Parent_Type);
11713 if Unknown_RM_Size (Derived_Type) then
11714 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
11717 Set_Is_Character_Type (Derived_Type, True);
11719 if Nkind (Indic) /= N_Subtype_Indication then
11721 -- If no explicit constraint, the bounds are those
11722 -- of the parent type.
11724 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Type));
11725 Hi := New_Copy_Tree (Type_High_Bound (Parent_Type));
11726 Set_Scalar_Range (Derived_Type, Make_Range (Loc, Lo, Hi));
11729 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
11731 -- Because the implicit base is used in the conversion of the bounds,
11732 -- we have to freeze it now. This is similar to what is done for
11733 -- numeric types, and it equally suspicious, but otherwise a non-
11734 -- static bound will have a reference to an unfrozen type, which is
11735 -- rejected by Gigi (???). This requires specific care for definition
11736 -- of stream attributes. For details, see comments at the end of
11737 -- Build_Derived_Numeric_Type.
11739 Freeze_Before (N, Implicit_Base);
11740 end Derived_Standard_Character;
11742 ------------------------------
11743 -- Derived_Type_Declaration --
11744 ------------------------------
11746 procedure Derived_Type_Declaration
11749 Is_Completion : Boolean)
11751 Parent_Type : Entity_Id;
11753 function Comes_From_Generic (Typ : Entity_Id) return Boolean;
11754 -- Check whether the parent type is a generic formal, or derives
11755 -- directly or indirectly from one.
11757 ------------------------
11758 -- Comes_From_Generic --
11759 ------------------------
11761 function Comes_From_Generic (Typ : Entity_Id) return Boolean is
11763 if Is_Generic_Type (Typ) then
11766 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
11769 elsif Is_Private_Type (Typ)
11770 and then Present (Full_View (Typ))
11771 and then Is_Generic_Type (Root_Type (Full_View (Typ)))
11775 elsif Is_Generic_Actual_Type (Typ) then
11781 end Comes_From_Generic;
11785 Def : constant Node_Id := Type_Definition (N);
11786 Iface_Def : Node_Id;
11787 Indic : constant Node_Id := Subtype_Indication (Def);
11788 Extension : constant Node_Id := Record_Extension_Part (Def);
11789 Parent_Node : Node_Id;
11790 Parent_Scope : Entity_Id;
11793 -- Start of processing for Derived_Type_Declaration
11796 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
11798 -- Ada 2005 (AI-251): In case of interface derivation check that the
11799 -- parent is also an interface.
11801 if Interface_Present (Def) then
11802 if not Is_Interface (Parent_Type) then
11804 ("(Ada 2005) & must be an interface", Indic, Parent_Type);
11807 Parent_Node := Parent (Base_Type (Parent_Type));
11808 Iface_Def := Type_Definition (Parent_Node);
11810 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
11811 -- other limited interfaces.
11813 if Limited_Present (Def) then
11814 if Limited_Present (Iface_Def) then
11817 elsif Protected_Present (Iface_Def) then
11819 ("(Ada 2005) limited interface cannot "
11820 & "inherit from protected interface", Indic);
11822 elsif Synchronized_Present (Iface_Def) then
11824 ("(Ada 2005) limited interface cannot "
11825 & "inherit from synchronized interface", Indic);
11827 elsif Task_Present (Iface_Def) then
11829 ("(Ada 2005) limited interface cannot "
11830 & "inherit from task interface", Indic);
11834 ("(Ada 2005) limited interface cannot "
11835 & "inherit from non-limited interface", Indic);
11838 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
11839 -- from non-limited or limited interfaces.
11841 elsif not Protected_Present (Def)
11842 and then not Synchronized_Present (Def)
11843 and then not Task_Present (Def)
11845 if Limited_Present (Iface_Def) then
11848 elsif Protected_Present (Iface_Def) then
11850 ("(Ada 2005) non-limited interface cannot "
11851 & "inherit from protected interface", Indic);
11853 elsif Synchronized_Present (Iface_Def) then
11855 ("(Ada 2005) non-limited interface cannot "
11856 & "inherit from synchronized interface", Indic);
11858 elsif Task_Present (Iface_Def) then
11860 ("(Ada 2005) non-limited interface cannot "
11861 & "inherit from task interface", Indic);
11870 if Is_Tagged_Type (Parent_Type)
11871 and then Is_Concurrent_Type (Parent_Type)
11872 and then not Is_Interface (Parent_Type)
11875 ("parent type of a record extension cannot be "
11876 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
11877 Set_Etype (T, Any_Type);
11881 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
11884 if Is_Tagged_Type (Parent_Type)
11885 and then Is_Non_Empty_List (Interface_List (Def))
11892 Intf := First (Interface_List (Def));
11893 while Present (Intf) loop
11894 T := Find_Type_Of_Subtype_Indic (Intf);
11896 if not Is_Interface (T) then
11897 Error_Msg_NE ("(Ada 2005) & must be an interface", Intf, T);
11899 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
11900 -- a limited type from having a nonlimited progenitor.
11902 elsif (Limited_Present (Def)
11903 or else (not Is_Interface (Parent_Type)
11904 and then Is_Limited_Type (Parent_Type)))
11905 and then not Is_Limited_Interface (T)
11908 ("progenitor interface& of limited type must be limited",
11917 if Parent_Type = Any_Type
11918 or else Etype (Parent_Type) = Any_Type
11919 or else (Is_Class_Wide_Type (Parent_Type)
11920 and then Etype (Parent_Type) = T)
11922 -- If Parent_Type is undefined or illegal, make new type into a
11923 -- subtype of Any_Type, and set a few attributes to prevent cascaded
11924 -- errors. If this is a self-definition, emit error now.
11927 or else T = Etype (Parent_Type)
11929 Error_Msg_N ("type cannot be used in its own definition", Indic);
11932 Set_Ekind (T, Ekind (Parent_Type));
11933 Set_Etype (T, Any_Type);
11934 Set_Scalar_Range (T, Scalar_Range (Any_Type));
11936 if Is_Tagged_Type (T) then
11937 Set_Primitive_Operations (T, New_Elmt_List);
11943 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
11944 -- an interface is special because the list of interfaces in the full
11945 -- view can be given in any order. For example:
11947 -- type A is interface;
11948 -- type B is interface and A;
11949 -- type D is new B with private;
11951 -- type D is new A and B with null record; -- 1 --
11953 -- In this case we perform the following transformation of -1-:
11955 -- type D is new B and A with null record;
11957 -- If the parent of the full-view covers the parent of the partial-view
11958 -- we have two possible cases:
11960 -- 1) They have the same parent
11961 -- 2) The parent of the full-view implements some further interfaces
11963 -- In both cases we do not need to perform the transformation. In the
11964 -- first case the source program is correct and the transformation is
11965 -- not needed; in the second case the source program does not fulfill
11966 -- the no-hidden interfaces rule (AI-396) and the error will be reported
11969 -- This transformation not only simplifies the rest of the analysis of
11970 -- this type declaration but also simplifies the correct generation of
11971 -- the object layout to the expander.
11973 if In_Private_Part (Current_Scope)
11974 and then Is_Interface (Parent_Type)
11978 Partial_View : Entity_Id;
11979 Partial_View_Parent : Entity_Id;
11980 New_Iface : Node_Id;
11983 -- Look for the associated private type declaration
11985 Partial_View := First_Entity (Current_Scope);
11987 exit when No (Partial_View)
11988 or else (Has_Private_Declaration (Partial_View)
11989 and then Full_View (Partial_View) = T);
11991 Next_Entity (Partial_View);
11994 -- If the partial view was not found then the source code has
11995 -- errors and the transformation is not needed.
11997 if Present (Partial_View) then
11998 Partial_View_Parent := Etype (Partial_View);
12000 -- If the parent of the full-view covers the parent of the
12001 -- partial-view we have nothing else to do.
12003 if Interface_Present_In_Ancestor
12004 (Parent_Type, Partial_View_Parent)
12008 -- Traverse the list of interfaces of the full-view to look
12009 -- for the parent of the partial-view and perform the tree
12013 Iface := First (Interface_List (Def));
12014 while Present (Iface) loop
12015 if Etype (Iface) = Etype (Partial_View) then
12016 Rewrite (Subtype_Indication (Def),
12017 New_Copy (Subtype_Indication
12018 (Parent (Partial_View))));
12020 New_Iface := Make_Identifier (Sloc (N),
12021 Chars (Parent_Type));
12022 Append (New_Iface, Interface_List (Def));
12024 -- Analyze the transformed code
12026 Derived_Type_Declaration (T, N, Is_Completion);
12037 -- Only composite types other than array types are allowed to have
12040 if Present (Discriminant_Specifications (N))
12041 and then (Is_Elementary_Type (Parent_Type)
12042 or else Is_Array_Type (Parent_Type))
12043 and then not Error_Posted (N)
12046 ("elementary or array type cannot have discriminants",
12047 Defining_Identifier (First (Discriminant_Specifications (N))));
12048 Set_Has_Discriminants (T, False);
12051 -- In Ada 83, a derived type defined in a package specification cannot
12052 -- be used for further derivation until the end of its visible part.
12053 -- Note that derivation in the private part of the package is allowed.
12055 if Ada_Version = Ada_83
12056 and then Is_Derived_Type (Parent_Type)
12057 and then In_Visible_Part (Scope (Parent_Type))
12059 if Ada_Version = Ada_83 and then Comes_From_Source (Indic) then
12061 ("(Ada 83): premature use of type for derivation", Indic);
12065 -- Check for early use of incomplete or private type
12067 if Ekind (Parent_Type) = E_Void
12068 or else Ekind (Parent_Type) = E_Incomplete_Type
12070 Error_Msg_N ("premature derivation of incomplete type", Indic);
12073 elsif (Is_Incomplete_Or_Private_Type (Parent_Type)
12074 and then not Comes_From_Generic (Parent_Type))
12075 or else Has_Private_Component (Parent_Type)
12077 -- The ancestor type of a formal type can be incomplete, in which
12078 -- case only the operations of the partial view are available in
12079 -- the generic. Subsequent checks may be required when the full
12080 -- view is analyzed, to verify that derivation from a tagged type
12081 -- has an extension.
12083 if Nkind (Original_Node (N)) = N_Formal_Type_Declaration then
12086 elsif No (Underlying_Type (Parent_Type))
12087 or else Has_Private_Component (Parent_Type)
12090 ("premature derivation of derived or private type", Indic);
12092 -- Flag the type itself as being in error, this prevents some
12093 -- nasty problems with subsequent uses of the malformed type.
12095 Set_Error_Posted (T);
12097 -- Check that within the immediate scope of an untagged partial
12098 -- view it's illegal to derive from the partial view if the
12099 -- full view is tagged. (7.3(7))
12101 -- We verify that the Parent_Type is a partial view by checking
12102 -- that it is not a Full_Type_Declaration (i.e. a private type or
12103 -- private extension declaration), to distinguish a partial view
12104 -- from a derivation from a private type which also appears as
12107 elsif Present (Full_View (Parent_Type))
12108 and then Nkind (Parent (Parent_Type)) /= N_Full_Type_Declaration
12109 and then not Is_Tagged_Type (Parent_Type)
12110 and then Is_Tagged_Type (Full_View (Parent_Type))
12112 Parent_Scope := Scope (T);
12113 while Present (Parent_Scope)
12114 and then Parent_Scope /= Standard_Standard
12116 if Parent_Scope = Scope (Parent_Type) then
12118 ("premature derivation from type with tagged full view",
12122 Parent_Scope := Scope (Parent_Scope);
12127 -- Check that form of derivation is appropriate
12129 Taggd := Is_Tagged_Type (Parent_Type);
12131 -- Perhaps the parent type should be changed to the class-wide type's
12132 -- specific type in this case to prevent cascading errors ???
12134 if Present (Extension) and then Is_Class_Wide_Type (Parent_Type) then
12135 Error_Msg_N ("parent type must not be a class-wide type", Indic);
12139 if Present (Extension) and then not Taggd then
12141 ("type derived from untagged type cannot have extension", Indic);
12143 elsif No (Extension) and then Taggd then
12145 -- If this declaration is within a private part (or body) of a
12146 -- generic instantiation then the derivation is allowed (the parent
12147 -- type can only appear tagged in this case if it's a generic actual
12148 -- type, since it would otherwise have been rejected in the analysis
12149 -- of the generic template).
12151 if not Is_Generic_Actual_Type (Parent_Type)
12152 or else In_Visible_Part (Scope (Parent_Type))
12155 ("type derived from tagged type must have extension", Indic);
12159 -- AI-443: Synchronized formal derived types require a private
12160 -- extension. There is no point in checking the ancestor type or
12161 -- the progenitors since the construct is wrong to begin with.
12163 if Ada_Version >= Ada_05
12164 and then Is_Generic_Type (T)
12165 and then Present (Original_Node (N))
12168 Decl : constant Node_Id := Original_Node (N);
12171 if Nkind (Decl) = N_Formal_Type_Declaration
12172 and then Nkind (Formal_Type_Definition (Decl)) =
12173 N_Formal_Derived_Type_Definition
12174 and then Synchronized_Present (Formal_Type_Definition (Decl))
12175 and then No (Extension)
12177 -- Avoid emitting a duplicate error message
12179 and then not Error_Posted (Indic)
12182 ("synchronized derived type must have extension", N);
12187 Build_Derived_Type (N, Parent_Type, T, Is_Completion);
12189 -- AI-419: The parent type of an explicitly limited derived type must
12190 -- be a limited type or a limited interface.
12192 if Limited_Present (Def) then
12193 Set_Is_Limited_Record (T);
12195 if Is_Interface (T) then
12196 Set_Is_Limited_Interface (T);
12199 if not Is_Limited_Type (Parent_Type)
12201 (not Is_Interface (Parent_Type)
12202 or else not Is_Limited_Interface (Parent_Type))
12204 Error_Msg_NE ("parent type& of limited type must be limited",
12208 end Derived_Type_Declaration;
12210 ----------------------------------
12211 -- Enumeration_Type_Declaration --
12212 ----------------------------------
12214 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id) is
12221 -- Create identifier node representing lower bound
12223 B_Node := New_Node (N_Identifier, Sloc (Def));
12224 L := First (Literals (Def));
12225 Set_Chars (B_Node, Chars (L));
12226 Set_Entity (B_Node, L);
12227 Set_Etype (B_Node, T);
12228 Set_Is_Static_Expression (B_Node, True);
12230 R_Node := New_Node (N_Range, Sloc (Def));
12231 Set_Low_Bound (R_Node, B_Node);
12233 Set_Ekind (T, E_Enumeration_Type);
12234 Set_First_Literal (T, L);
12236 Set_Is_Constrained (T);
12240 -- Loop through literals of enumeration type setting pos and rep values
12241 -- except that if the Ekind is already set, then it means that the
12242 -- literal was already constructed (case of a derived type declaration
12243 -- and we should not disturb the Pos and Rep values.
12245 while Present (L) loop
12246 if Ekind (L) /= E_Enumeration_Literal then
12247 Set_Ekind (L, E_Enumeration_Literal);
12248 Set_Enumeration_Pos (L, Ev);
12249 Set_Enumeration_Rep (L, Ev);
12250 Set_Is_Known_Valid (L, True);
12254 New_Overloaded_Entity (L);
12255 Generate_Definition (L);
12256 Set_Convention (L, Convention_Intrinsic);
12258 if Nkind (L) = N_Defining_Character_Literal then
12259 Set_Is_Character_Type (T, True);
12266 -- Now create a node representing upper bound
12268 B_Node := New_Node (N_Identifier, Sloc (Def));
12269 Set_Chars (B_Node, Chars (Last (Literals (Def))));
12270 Set_Entity (B_Node, Last (Literals (Def)));
12271 Set_Etype (B_Node, T);
12272 Set_Is_Static_Expression (B_Node, True);
12274 Set_High_Bound (R_Node, B_Node);
12276 -- Initialize various fields of the type. Some of this information
12277 -- may be overwritten later through rep.clauses.
12279 Set_Scalar_Range (T, R_Node);
12280 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
12281 Set_Enum_Esize (T);
12282 Set_Enum_Pos_To_Rep (T, Empty);
12284 -- Set Discard_Names if configuration pragma set, or if there is
12285 -- a parameterless pragma in the current declarative region
12287 if Global_Discard_Names
12288 or else Discard_Names (Scope (T))
12290 Set_Discard_Names (T);
12293 -- Process end label if there is one
12295 if Present (Def) then
12296 Process_End_Label (Def, 'e', T);
12298 end Enumeration_Type_Declaration;
12300 ---------------------------------
12301 -- Expand_To_Stored_Constraint --
12302 ---------------------------------
12304 function Expand_To_Stored_Constraint
12306 Constraint : Elist_Id) return Elist_Id
12308 Explicitly_Discriminated_Type : Entity_Id;
12309 Expansion : Elist_Id;
12310 Discriminant : Entity_Id;
12312 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id;
12313 -- Find the nearest type that actually specifies discriminants
12315 ---------------------------------
12316 -- Type_With_Explicit_Discrims --
12317 ---------------------------------
12319 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id is
12320 Typ : constant E := Base_Type (Id);
12323 if Ekind (Typ) in Incomplete_Or_Private_Kind then
12324 if Present (Full_View (Typ)) then
12325 return Type_With_Explicit_Discrims (Full_View (Typ));
12329 if Has_Discriminants (Typ) then
12334 if Etype (Typ) = Typ then
12336 elsif Has_Discriminants (Typ) then
12339 return Type_With_Explicit_Discrims (Etype (Typ));
12342 end Type_With_Explicit_Discrims;
12344 -- Start of processing for Expand_To_Stored_Constraint
12348 or else Is_Empty_Elmt_List (Constraint)
12353 Explicitly_Discriminated_Type := Type_With_Explicit_Discrims (Typ);
12355 if No (Explicitly_Discriminated_Type) then
12359 Expansion := New_Elmt_List;
12362 First_Stored_Discriminant (Explicitly_Discriminated_Type);
12363 while Present (Discriminant) loop
12365 Get_Discriminant_Value (
12366 Discriminant, Explicitly_Discriminated_Type, Constraint),
12368 Next_Stored_Discriminant (Discriminant);
12372 end Expand_To_Stored_Constraint;
12374 ---------------------------
12375 -- Find_Hidden_Interface --
12376 ---------------------------
12378 function Find_Hidden_Interface
12380 Dest : Elist_Id) return Entity_Id
12383 Iface_Elmt : Elmt_Id;
12386 if Present (Src) and then Present (Dest) then
12387 Iface_Elmt := First_Elmt (Src);
12388 while Present (Iface_Elmt) loop
12389 Iface := Node (Iface_Elmt);
12391 if Is_Interface (Iface)
12392 and then not Contain_Interface (Iface, Dest)
12397 Next_Elmt (Iface_Elmt);
12402 end Find_Hidden_Interface;
12404 --------------------
12405 -- Find_Type_Name --
12406 --------------------
12408 function Find_Type_Name (N : Node_Id) return Entity_Id is
12409 Id : constant Entity_Id := Defining_Identifier (N);
12411 New_Id : Entity_Id;
12412 Prev_Par : Node_Id;
12415 -- Find incomplete declaration, if one was given
12417 Prev := Current_Entity_In_Scope (Id);
12419 if Present (Prev) then
12421 -- Previous declaration exists. Error if not incomplete/private case
12422 -- except if previous declaration is implicit, etc. Enter_Name will
12423 -- emit error if appropriate.
12425 Prev_Par := Parent (Prev);
12427 if not Is_Incomplete_Or_Private_Type (Prev) then
12431 elsif Nkind (N) /= N_Full_Type_Declaration
12432 and then Nkind (N) /= N_Task_Type_Declaration
12433 and then Nkind (N) /= N_Protected_Type_Declaration
12435 -- Completion must be a full type declarations (RM 7.3(4))
12437 Error_Msg_Sloc := Sloc (Prev);
12438 Error_Msg_NE ("invalid completion of }", Id, Prev);
12440 -- Set scope of Id to avoid cascaded errors. Entity is never
12441 -- examined again, except when saving globals in generics.
12443 Set_Scope (Id, Current_Scope);
12446 -- Case of full declaration of incomplete type
12448 elsif Ekind (Prev) = E_Incomplete_Type then
12450 -- Indicate that the incomplete declaration has a matching full
12451 -- declaration. The defining occurrence of the incomplete
12452 -- declaration remains the visible one, and the procedure
12453 -- Get_Full_View dereferences it whenever the type is used.
12455 if Present (Full_View (Prev)) then
12456 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
12459 Set_Full_View (Prev, Id);
12460 Append_Entity (Id, Current_Scope);
12461 Set_Is_Public (Id, Is_Public (Prev));
12462 Set_Is_Internal (Id);
12465 -- Case of full declaration of private type
12468 if Nkind (Parent (Prev)) /= N_Private_Extension_Declaration then
12469 if Etype (Prev) /= Prev then
12471 -- Prev is a private subtype or a derived type, and needs
12474 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
12477 elsif Ekind (Prev) = E_Private_Type
12479 (Nkind (N) = N_Task_Type_Declaration
12480 or else Nkind (N) = N_Protected_Type_Declaration)
12483 ("completion of nonlimited type cannot be limited", N);
12485 elsif Ekind (Prev) = E_Record_Type_With_Private
12487 (Nkind (N) = N_Task_Type_Declaration
12488 or else Nkind (N) = N_Protected_Type_Declaration)
12490 if not Is_Limited_Record (Prev) then
12492 ("completion of nonlimited type cannot be limited", N);
12494 elsif No (Interface_List (N)) then
12496 ("completion of tagged private type must be tagged",
12501 -- Ada 2005 (AI-251): Private extension declaration of a task
12502 -- type or a protected type. This case arises when covering
12503 -- interface types.
12505 elsif Nkind (N) = N_Task_Type_Declaration
12506 or else Nkind (N) = N_Protected_Type_Declaration
12510 elsif Nkind (N) /= N_Full_Type_Declaration
12511 or else Nkind (Type_Definition (N)) /= N_Derived_Type_Definition
12514 ("full view of private extension must be an extension", N);
12516 elsif not (Abstract_Present (Parent (Prev)))
12517 and then Abstract_Present (Type_Definition (N))
12520 ("full view of non-abstract extension cannot be abstract", N);
12523 if not In_Private_Part (Current_Scope) then
12525 ("declaration of full view must appear in private part", N);
12528 Copy_And_Swap (Prev, Id);
12529 Set_Has_Private_Declaration (Prev);
12530 Set_Has_Private_Declaration (Id);
12532 -- If no error, propagate freeze_node from private to full view.
12533 -- It may have been generated for an early operational item.
12535 if Present (Freeze_Node (Id))
12536 and then Serious_Errors_Detected = 0
12537 and then No (Full_View (Id))
12539 Set_Freeze_Node (Prev, Freeze_Node (Id));
12540 Set_Freeze_Node (Id, Empty);
12541 Set_First_Rep_Item (Prev, First_Rep_Item (Id));
12544 Set_Full_View (Id, Prev);
12548 -- Verify that full declaration conforms to incomplete one
12550 if Is_Incomplete_Or_Private_Type (Prev)
12551 and then Present (Discriminant_Specifications (Prev_Par))
12553 if Present (Discriminant_Specifications (N)) then
12554 if Ekind (Prev) = E_Incomplete_Type then
12555 Check_Discriminant_Conformance (N, Prev, Prev);
12557 Check_Discriminant_Conformance (N, Prev, Id);
12562 ("missing discriminants in full type declaration", N);
12564 -- To avoid cascaded errors on subsequent use, share the
12565 -- discriminants of the partial view.
12567 Set_Discriminant_Specifications (N,
12568 Discriminant_Specifications (Prev_Par));
12572 -- A prior untagged private type can have an associated class-wide
12573 -- type due to use of the class attribute, and in this case also the
12574 -- full type is required to be tagged.
12577 and then (Is_Tagged_Type (Prev)
12578 or else Present (Class_Wide_Type (Prev)))
12579 and then (Nkind (N) /= N_Task_Type_Declaration
12580 and then Nkind (N) /= N_Protected_Type_Declaration)
12582 -- The full declaration is either a tagged record or an
12583 -- extension otherwise this is an error
12585 if Nkind (Type_Definition (N)) = N_Record_Definition then
12586 if not Tagged_Present (Type_Definition (N)) then
12588 ("full declaration of } must be tagged", Prev, Id);
12589 Set_Is_Tagged_Type (Id);
12590 Set_Primitive_Operations (Id, New_Elmt_List);
12593 elsif Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
12594 if No (Record_Extension_Part (Type_Definition (N))) then
12596 "full declaration of } must be a record extension",
12598 Set_Is_Tagged_Type (Id);
12599 Set_Primitive_Operations (Id, New_Elmt_List);
12604 ("full declaration of } must be a tagged type", Prev, Id);
12612 -- New type declaration
12617 end Find_Type_Name;
12619 -------------------------
12620 -- Find_Type_Of_Object --
12621 -------------------------
12623 function Find_Type_Of_Object
12624 (Obj_Def : Node_Id;
12625 Related_Nod : Node_Id) return Entity_Id
12627 Def_Kind : constant Node_Kind := Nkind (Obj_Def);
12628 P : Node_Id := Parent (Obj_Def);
12633 -- If the parent is a component_definition node we climb to the
12634 -- component_declaration node
12636 if Nkind (P) = N_Component_Definition then
12640 -- Case of an anonymous array subtype
12642 if Def_Kind = N_Constrained_Array_Definition
12643 or else Def_Kind = N_Unconstrained_Array_Definition
12646 Array_Type_Declaration (T, Obj_Def);
12648 -- Create an explicit subtype whenever possible
12650 elsif Nkind (P) /= N_Component_Declaration
12651 and then Def_Kind = N_Subtype_Indication
12653 -- Base name of subtype on object name, which will be unique in
12654 -- the current scope.
12656 -- If this is a duplicate declaration, return base type, to avoid
12657 -- generating duplicate anonymous types.
12659 if Error_Posted (P) then
12660 Analyze (Subtype_Mark (Obj_Def));
12661 return Entity (Subtype_Mark (Obj_Def));
12666 (Chars (Defining_Identifier (Related_Nod)), 'S', 0, 'T');
12668 T := Make_Defining_Identifier (Sloc (P), Nam);
12670 Insert_Action (Obj_Def,
12671 Make_Subtype_Declaration (Sloc (P),
12672 Defining_Identifier => T,
12673 Subtype_Indication => Relocate_Node (Obj_Def)));
12675 -- This subtype may need freezing, and this will not be done
12676 -- automatically if the object declaration is not in declarative
12677 -- part. Since this is an object declaration, the type cannot always
12678 -- be frozen here. Deferred constants do not freeze their type
12679 -- (which often enough will be private).
12681 if Nkind (P) = N_Object_Declaration
12682 and then Constant_Present (P)
12683 and then No (Expression (P))
12687 Insert_Actions (Obj_Def, Freeze_Entity (T, Sloc (P)));
12690 -- Ada 2005 AI-406: the object definition in an object declaration
12691 -- can be an access definition.
12693 elsif Def_Kind = N_Access_Definition then
12694 T := Access_Definition (Related_Nod, Obj_Def);
12695 Set_Is_Local_Anonymous_Access (T);
12697 -- Otherwise, the object definition is just a subtype_mark
12700 T := Process_Subtype (Obj_Def, Related_Nod);
12704 end Find_Type_Of_Object;
12706 --------------------------------
12707 -- Find_Type_Of_Subtype_Indic --
12708 --------------------------------
12710 function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id is
12714 -- Case of subtype mark with a constraint
12716 if Nkind (S) = N_Subtype_Indication then
12717 Find_Type (Subtype_Mark (S));
12718 Typ := Entity (Subtype_Mark (S));
12721 Is_Valid_Constraint_Kind (Ekind (Typ), Nkind (Constraint (S)))
12724 ("incorrect constraint for this kind of type", Constraint (S));
12725 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
12728 -- Otherwise we have a subtype mark without a constraint
12730 elsif Error_Posted (S) then
12731 Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S)));
12739 if Typ = Standard_Wide_Character
12740 or else Typ = Standard_Wide_Wide_Character
12741 or else Typ = Standard_Wide_String
12742 or else Typ = Standard_Wide_Wide_String
12744 Check_Restriction (No_Wide_Characters, S);
12748 end Find_Type_Of_Subtype_Indic;
12750 -------------------------------------
12751 -- Floating_Point_Type_Declaration --
12752 -------------------------------------
12754 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is
12755 Digs : constant Node_Id := Digits_Expression (Def);
12757 Base_Typ : Entity_Id;
12758 Implicit_Base : Entity_Id;
12761 function Can_Derive_From (E : Entity_Id) return Boolean;
12762 -- Find if given digits value allows derivation from specified type
12764 ---------------------
12765 -- Can_Derive_From --
12766 ---------------------
12768 function Can_Derive_From (E : Entity_Id) return Boolean is
12769 Spec : constant Entity_Id := Real_Range_Specification (Def);
12772 if Digs_Val > Digits_Value (E) then
12776 if Present (Spec) then
12777 if Expr_Value_R (Type_Low_Bound (E)) >
12778 Expr_Value_R (Low_Bound (Spec))
12783 if Expr_Value_R (Type_High_Bound (E)) <
12784 Expr_Value_R (High_Bound (Spec))
12791 end Can_Derive_From;
12793 -- Start of processing for Floating_Point_Type_Declaration
12796 Check_Restriction (No_Floating_Point, Def);
12798 -- Create an implicit base type
12801 Create_Itype (E_Floating_Point_Type, Parent (Def), T, 'B');
12803 -- Analyze and verify digits value
12805 Analyze_And_Resolve (Digs, Any_Integer);
12806 Check_Digits_Expression (Digs);
12807 Digs_Val := Expr_Value (Digs);
12809 -- Process possible range spec and find correct type to derive from
12811 Process_Real_Range_Specification (Def);
12813 if Can_Derive_From (Standard_Short_Float) then
12814 Base_Typ := Standard_Short_Float;
12815 elsif Can_Derive_From (Standard_Float) then
12816 Base_Typ := Standard_Float;
12817 elsif Can_Derive_From (Standard_Long_Float) then
12818 Base_Typ := Standard_Long_Float;
12819 elsif Can_Derive_From (Standard_Long_Long_Float) then
12820 Base_Typ := Standard_Long_Long_Float;
12822 -- If we can't derive from any existing type, use long_long_float
12823 -- and give appropriate message explaining the problem.
12826 Base_Typ := Standard_Long_Long_Float;
12828 if Digs_Val >= Digits_Value (Standard_Long_Long_Float) then
12829 Error_Msg_Uint_1 := Digits_Value (Standard_Long_Long_Float);
12830 Error_Msg_N ("digits value out of range, maximum is ^", Digs);
12834 ("range too large for any predefined type",
12835 Real_Range_Specification (Def));
12839 -- If there are bounds given in the declaration use them as the bounds
12840 -- of the type, otherwise use the bounds of the predefined base type
12841 -- that was chosen based on the Digits value.
12843 if Present (Real_Range_Specification (Def)) then
12844 Set_Scalar_Range (T, Real_Range_Specification (Def));
12845 Set_Is_Constrained (T);
12847 -- The bounds of this range must be converted to machine numbers
12848 -- in accordance with RM 4.9(38).
12850 Bound := Type_Low_Bound (T);
12852 if Nkind (Bound) = N_Real_Literal then
12854 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
12855 Set_Is_Machine_Number (Bound);
12858 Bound := Type_High_Bound (T);
12860 if Nkind (Bound) = N_Real_Literal then
12862 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
12863 Set_Is_Machine_Number (Bound);
12867 Set_Scalar_Range (T, Scalar_Range (Base_Typ));
12870 -- Complete definition of implicit base and declared first subtype
12872 Set_Etype (Implicit_Base, Base_Typ);
12874 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
12875 Set_Size_Info (Implicit_Base, (Base_Typ));
12876 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
12877 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
12878 Set_Digits_Value (Implicit_Base, Digits_Value (Base_Typ));
12879 Set_Vax_Float (Implicit_Base, Vax_Float (Base_Typ));
12881 Set_Ekind (T, E_Floating_Point_Subtype);
12882 Set_Etype (T, Implicit_Base);
12884 Set_Size_Info (T, (Implicit_Base));
12885 Set_RM_Size (T, RM_Size (Implicit_Base));
12886 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
12887 Set_Digits_Value (T, Digs_Val);
12888 end Floating_Point_Type_Declaration;
12890 ----------------------------
12891 -- Get_Discriminant_Value --
12892 ----------------------------
12894 -- This is the situation:
12896 -- There is a non-derived type
12898 -- type T0 (Dx, Dy, Dz...)
12900 -- There are zero or more levels of derivation, with each derivation
12901 -- either purely inheriting the discriminants, or defining its own.
12903 -- type Ti is new Ti-1
12905 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
12907 -- subtype Ti is ...
12909 -- The subtype issue is avoided by the use of Original_Record_Component,
12910 -- and the fact that derived subtypes also derive the constraints.
12912 -- This chain leads back from
12914 -- Typ_For_Constraint
12916 -- Typ_For_Constraint has discriminants, and the value for each
12917 -- discriminant is given by its corresponding Elmt of Constraints.
12919 -- Discriminant is some discriminant in this hierarchy
12921 -- We need to return its value
12923 -- We do this by recursively searching each level, and looking for
12924 -- Discriminant. Once we get to the bottom, we start backing up
12925 -- returning the value for it which may in turn be a discriminant
12926 -- further up, so on the backup we continue the substitution.
12928 function Get_Discriminant_Value
12929 (Discriminant : Entity_Id;
12930 Typ_For_Constraint : Entity_Id;
12931 Constraint : Elist_Id) return Node_Id
12933 function Search_Derivation_Levels
12935 Discrim_Values : Elist_Id;
12936 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id;
12937 -- This is the routine that performs the recursive search of levels
12938 -- as described above.
12940 ------------------------------
12941 -- Search_Derivation_Levels --
12942 ------------------------------
12944 function Search_Derivation_Levels
12946 Discrim_Values : Elist_Id;
12947 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id
12951 Result : Node_Or_Entity_Id;
12952 Result_Entity : Node_Id;
12955 -- If inappropriate type, return Error, this happens only in
12956 -- cascaded error situations, and we want to avoid a blow up.
12958 if not Is_Composite_Type (Ti) or else Is_Array_Type (Ti) then
12962 -- Look deeper if possible. Use Stored_Constraints only for
12963 -- untagged types. For tagged types use the given constraint.
12964 -- This asymmetry needs explanation???
12966 if not Stored_Discrim_Values
12967 and then Present (Stored_Constraint (Ti))
12968 and then not Is_Tagged_Type (Ti)
12971 Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True);
12974 Td : constant Entity_Id := Etype (Ti);
12978 Result := Discriminant;
12981 if Present (Stored_Constraint (Ti)) then
12983 Search_Derivation_Levels
12984 (Td, Stored_Constraint (Ti), True);
12987 Search_Derivation_Levels
12988 (Td, Discrim_Values, Stored_Discrim_Values);
12994 -- Extra underlying places to search, if not found above. For
12995 -- concurrent types, the relevant discriminant appears in the
12996 -- corresponding record. For a type derived from a private type
12997 -- without discriminant, the full view inherits the discriminants
12998 -- of the full view of the parent.
13000 if Result = Discriminant then
13001 if Is_Concurrent_Type (Ti)
13002 and then Present (Corresponding_Record_Type (Ti))
13005 Search_Derivation_Levels (
13006 Corresponding_Record_Type (Ti),
13008 Stored_Discrim_Values);
13010 elsif Is_Private_Type (Ti)
13011 and then not Has_Discriminants (Ti)
13012 and then Present (Full_View (Ti))
13013 and then Etype (Full_View (Ti)) /= Ti
13016 Search_Derivation_Levels (
13019 Stored_Discrim_Values);
13023 -- If Result is not a (reference to a) discriminant, return it,
13024 -- otherwise set Result_Entity to the discriminant.
13026 if Nkind (Result) = N_Defining_Identifier then
13027 pragma Assert (Result = Discriminant);
13028 Result_Entity := Result;
13031 if not Denotes_Discriminant (Result) then
13035 Result_Entity := Entity (Result);
13038 -- See if this level of derivation actually has discriminants
13039 -- because tagged derivations can add them, hence the lower
13040 -- levels need not have any.
13042 if not Has_Discriminants (Ti) then
13046 -- Scan Ti's discriminants for Result_Entity,
13047 -- and return its corresponding value, if any.
13049 Result_Entity := Original_Record_Component (Result_Entity);
13051 Assoc := First_Elmt (Discrim_Values);
13053 if Stored_Discrim_Values then
13054 Disc := First_Stored_Discriminant (Ti);
13056 Disc := First_Discriminant (Ti);
13059 while Present (Disc) loop
13060 pragma Assert (Present (Assoc));
13062 if Original_Record_Component (Disc) = Result_Entity then
13063 return Node (Assoc);
13068 if Stored_Discrim_Values then
13069 Next_Stored_Discriminant (Disc);
13071 Next_Discriminant (Disc);
13075 -- Could not find it
13078 end Search_Derivation_Levels;
13080 Result : Node_Or_Entity_Id;
13082 -- Start of processing for Get_Discriminant_Value
13085 -- ??? This routine is a gigantic mess and will be deleted. For the
13086 -- time being just test for the trivial case before calling recurse.
13088 if Base_Type (Scope (Discriminant)) = Base_Type (Typ_For_Constraint) then
13094 D := First_Discriminant (Typ_For_Constraint);
13095 E := First_Elmt (Constraint);
13096 while Present (D) loop
13097 if Chars (D) = Chars (Discriminant) then
13101 Next_Discriminant (D);
13107 Result := Search_Derivation_Levels
13108 (Typ_For_Constraint, Constraint, False);
13110 -- ??? hack to disappear when this routine is gone
13112 if Nkind (Result) = N_Defining_Identifier then
13118 D := First_Discriminant (Typ_For_Constraint);
13119 E := First_Elmt (Constraint);
13120 while Present (D) loop
13121 if Corresponding_Discriminant (D) = Discriminant then
13125 Next_Discriminant (D);
13131 pragma Assert (Nkind (Result) /= N_Defining_Identifier);
13133 end Get_Discriminant_Value;
13135 --------------------------
13136 -- Has_Range_Constraint --
13137 --------------------------
13139 function Has_Range_Constraint (N : Node_Id) return Boolean is
13140 C : constant Node_Id := Constraint (N);
13143 if Nkind (C) = N_Range_Constraint then
13146 elsif Nkind (C) = N_Digits_Constraint then
13148 Is_Decimal_Fixed_Point_Type (Entity (Subtype_Mark (N)))
13150 Present (Range_Constraint (C));
13152 elsif Nkind (C) = N_Delta_Constraint then
13153 return Present (Range_Constraint (C));
13158 end Has_Range_Constraint;
13160 ------------------------
13161 -- Inherit_Components --
13162 ------------------------
13164 function Inherit_Components
13166 Parent_Base : Entity_Id;
13167 Derived_Base : Entity_Id;
13168 Is_Tagged : Boolean;
13169 Inherit_Discr : Boolean;
13170 Discs : Elist_Id) return Elist_Id
13172 Assoc_List : constant Elist_Id := New_Elmt_List;
13174 procedure Inherit_Component
13175 (Old_C : Entity_Id;
13176 Plain_Discrim : Boolean := False;
13177 Stored_Discrim : Boolean := False);
13178 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
13179 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
13180 -- True, Old_C is a stored discriminant. If they are both false then
13181 -- Old_C is a regular component.
13183 -----------------------
13184 -- Inherit_Component --
13185 -----------------------
13187 procedure Inherit_Component
13188 (Old_C : Entity_Id;
13189 Plain_Discrim : Boolean := False;
13190 Stored_Discrim : Boolean := False)
13192 New_C : constant Entity_Id := New_Copy (Old_C);
13194 Discrim : Entity_Id;
13195 Corr_Discrim : Entity_Id;
13198 pragma Assert (not Is_Tagged or else not Stored_Discrim);
13200 Set_Parent (New_C, Parent (Old_C));
13202 -- Regular discriminants and components must be inserted in the scope
13203 -- of the Derived_Base. Do it here.
13205 if not Stored_Discrim then
13206 Enter_Name (New_C);
13209 -- For tagged types the Original_Record_Component must point to
13210 -- whatever this field was pointing to in the parent type. This has
13211 -- already been achieved by the call to New_Copy above.
13213 if not Is_Tagged then
13214 Set_Original_Record_Component (New_C, New_C);
13217 -- If we have inherited a component then see if its Etype contains
13218 -- references to Parent_Base discriminants. In this case, replace
13219 -- these references with the constraints given in Discs. We do not
13220 -- do this for the partial view of private types because this is
13221 -- not needed (only the components of the full view will be used
13222 -- for code generation) and cause problem. We also avoid this
13223 -- transformation in some error situations.
13225 if Ekind (New_C) = E_Component then
13226 if (Is_Private_Type (Derived_Base)
13227 and then not Is_Generic_Type (Derived_Base))
13228 or else (Is_Empty_Elmt_List (Discs)
13229 and then not Expander_Active)
13231 Set_Etype (New_C, Etype (Old_C));
13234 -- The current component introduces a circularity of the
13237 -- limited with Pack_2;
13238 -- package Pack_1 is
13239 -- type T_1 is tagged record
13240 -- Comp : access Pack_2.T_2;
13246 -- package Pack_2 is
13247 -- type T_2 is new Pack_1.T_1 with ...;
13252 Constrain_Component_Type
13253 (Old_C, Derived_Base, N, Parent_Base, Discs));
13257 -- In derived tagged types it is illegal to reference a non
13258 -- discriminant component in the parent type. To catch this, mark
13259 -- these components with an Ekind of E_Void. This will be reset in
13260 -- Record_Type_Definition after processing the record extension of
13261 -- the derived type.
13263 -- If the declaration is a private extension, there is no further
13264 -- record extension to process, and the components retain their
13265 -- current kind, because they are visible at this point.
13267 if Is_Tagged and then Ekind (New_C) = E_Component
13268 and then Nkind (N) /= N_Private_Extension_Declaration
13270 Set_Ekind (New_C, E_Void);
13273 if Plain_Discrim then
13274 Set_Corresponding_Discriminant (New_C, Old_C);
13275 Build_Discriminal (New_C);
13277 -- If we are explicitly inheriting a stored discriminant it will be
13278 -- completely hidden.
13280 elsif Stored_Discrim then
13281 Set_Corresponding_Discriminant (New_C, Empty);
13282 Set_Discriminal (New_C, Empty);
13283 Set_Is_Completely_Hidden (New_C);
13285 -- Set the Original_Record_Component of each discriminant in the
13286 -- derived base to point to the corresponding stored that we just
13289 Discrim := First_Discriminant (Derived_Base);
13290 while Present (Discrim) loop
13291 Corr_Discrim := Corresponding_Discriminant (Discrim);
13293 -- Corr_Discrim could be missing in an error situation
13295 if Present (Corr_Discrim)
13296 and then Original_Record_Component (Corr_Discrim) = Old_C
13298 Set_Original_Record_Component (Discrim, New_C);
13301 Next_Discriminant (Discrim);
13304 Append_Entity (New_C, Derived_Base);
13307 if not Is_Tagged then
13308 Append_Elmt (Old_C, Assoc_List);
13309 Append_Elmt (New_C, Assoc_List);
13311 end Inherit_Component;
13313 -- Variables local to Inherit_Component
13315 Loc : constant Source_Ptr := Sloc (N);
13317 Parent_Discrim : Entity_Id;
13318 Stored_Discrim : Entity_Id;
13320 Component : Entity_Id;
13322 -- Start of processing for Inherit_Components
13325 if not Is_Tagged then
13326 Append_Elmt (Parent_Base, Assoc_List);
13327 Append_Elmt (Derived_Base, Assoc_List);
13330 -- Inherit parent discriminants if needed
13332 if Inherit_Discr then
13333 Parent_Discrim := First_Discriminant (Parent_Base);
13334 while Present (Parent_Discrim) loop
13335 Inherit_Component (Parent_Discrim, Plain_Discrim => True);
13336 Next_Discriminant (Parent_Discrim);
13340 -- Create explicit stored discrims for untagged types when necessary
13342 if not Has_Unknown_Discriminants (Derived_Base)
13343 and then Has_Discriminants (Parent_Base)
13344 and then not Is_Tagged
13347 or else First_Discriminant (Parent_Base) /=
13348 First_Stored_Discriminant (Parent_Base))
13350 Stored_Discrim := First_Stored_Discriminant (Parent_Base);
13351 while Present (Stored_Discrim) loop
13352 Inherit_Component (Stored_Discrim, Stored_Discrim => True);
13353 Next_Stored_Discriminant (Stored_Discrim);
13357 -- See if we can apply the second transformation for derived types, as
13358 -- explained in point 6. in the comments above Build_Derived_Record_Type
13359 -- This is achieved by appending Derived_Base discriminants into Discs,
13360 -- which has the side effect of returning a non empty Discs list to the
13361 -- caller of Inherit_Components, which is what we want. This must be
13362 -- done for private derived types if there are explicit stored
13363 -- discriminants, to ensure that we can retrieve the values of the
13364 -- constraints provided in the ancestors.
13367 and then Is_Empty_Elmt_List (Discs)
13368 and then Present (First_Discriminant (Derived_Base))
13370 (not Is_Private_Type (Derived_Base)
13371 or else Is_Completely_Hidden
13372 (First_Stored_Discriminant (Derived_Base))
13373 or else Is_Generic_Type (Derived_Base))
13375 D := First_Discriminant (Derived_Base);
13376 while Present (D) loop
13377 Append_Elmt (New_Reference_To (D, Loc), Discs);
13378 Next_Discriminant (D);
13382 -- Finally, inherit non-discriminant components unless they are not
13383 -- visible because defined or inherited from the full view of the
13384 -- parent. Don't inherit the _parent field of the parent type.
13386 Component := First_Entity (Parent_Base);
13387 while Present (Component) loop
13389 -- Ada 2005 (AI-251): Do not inherit components associated with
13390 -- secondary tags of the parent.
13392 if Ekind (Component) = E_Component
13393 and then Present (Related_Interface (Component))
13397 elsif Ekind (Component) /= E_Component
13398 or else Chars (Component) = Name_uParent
13402 -- If the derived type is within the parent type's declarative
13403 -- region, then the components can still be inherited even though
13404 -- they aren't visible at this point. This can occur for cases
13405 -- such as within public child units where the components must
13406 -- become visible upon entering the child unit's private part.
13408 elsif not Is_Visible_Component (Component)
13409 and then not In_Open_Scopes (Scope (Parent_Base))
13413 elsif Ekind (Derived_Base) = E_Private_Type
13414 or else Ekind (Derived_Base) = E_Limited_Private_Type
13419 Inherit_Component (Component);
13422 Next_Entity (Component);
13425 -- For tagged derived types, inherited discriminants cannot be used in
13426 -- component declarations of the record extension part. To achieve this
13427 -- we mark the inherited discriminants as not visible.
13429 if Is_Tagged and then Inherit_Discr then
13430 D := First_Discriminant (Derived_Base);
13431 while Present (D) loop
13432 Set_Is_Immediately_Visible (D, False);
13433 Next_Discriminant (D);
13438 end Inherit_Components;
13440 -----------------------
13441 -- Is_Null_Extension --
13442 -----------------------
13444 function Is_Null_Extension (T : Entity_Id) return Boolean is
13445 Type_Decl : constant Node_Id := Parent (T);
13446 Comp_List : Node_Id;
13450 if Nkind (Type_Decl) /= N_Full_Type_Declaration
13451 or else not Is_Tagged_Type (T)
13452 or else Nkind (Type_Definition (Type_Decl)) /=
13453 N_Derived_Type_Definition
13454 or else No (Record_Extension_Part (Type_Definition (Type_Decl)))
13460 Component_List (Record_Extension_Part (Type_Definition (Type_Decl)));
13462 if Present (Discriminant_Specifications (Type_Decl)) then
13465 elsif Present (Comp_List)
13466 and then Is_Non_Empty_List (Component_Items (Comp_List))
13468 Comp := First (Component_Items (Comp_List));
13470 -- Only user-defined components are relevant. The component list
13471 -- may also contain a parent component and internal components
13472 -- corresponding to secondary tags, but these do not determine
13473 -- whether this is a null extension.
13475 while Present (Comp) loop
13476 if Comes_From_Source (Comp) then
13487 end Is_Null_Extension;
13489 ------------------------------
13490 -- Is_Valid_Constraint_Kind --
13491 ------------------------------
13493 function Is_Valid_Constraint_Kind
13494 (T_Kind : Type_Kind;
13495 Constraint_Kind : Node_Kind) return Boolean
13499 when Enumeration_Kind |
13501 return Constraint_Kind = N_Range_Constraint;
13503 when Decimal_Fixed_Point_Kind =>
13505 Constraint_Kind = N_Digits_Constraint
13507 Constraint_Kind = N_Range_Constraint;
13509 when Ordinary_Fixed_Point_Kind =>
13511 Constraint_Kind = N_Delta_Constraint
13513 Constraint_Kind = N_Range_Constraint;
13517 Constraint_Kind = N_Digits_Constraint
13519 Constraint_Kind = N_Range_Constraint;
13526 E_Incomplete_Type |
13529 return Constraint_Kind = N_Index_Or_Discriminant_Constraint;
13532 return True; -- Error will be detected later
13534 end Is_Valid_Constraint_Kind;
13536 --------------------------
13537 -- Is_Visible_Component --
13538 --------------------------
13540 function Is_Visible_Component (C : Entity_Id) return Boolean is
13541 Original_Comp : Entity_Id := Empty;
13542 Original_Scope : Entity_Id;
13543 Type_Scope : Entity_Id;
13545 function Is_Local_Type (Typ : Entity_Id) return Boolean;
13546 -- Check whether parent type of inherited component is declared locally,
13547 -- possibly within a nested package or instance. The current scope is
13548 -- the derived record itself.
13550 -------------------
13551 -- Is_Local_Type --
13552 -------------------
13554 function Is_Local_Type (Typ : Entity_Id) return Boolean is
13558 Scop := Scope (Typ);
13559 while Present (Scop)
13560 and then Scop /= Standard_Standard
13562 if Scop = Scope (Current_Scope) then
13566 Scop := Scope (Scop);
13572 -- Start of processing for Is_Visible_Component
13575 if Ekind (C) = E_Component
13576 or else Ekind (C) = E_Discriminant
13578 Original_Comp := Original_Record_Component (C);
13581 if No (Original_Comp) then
13583 -- Premature usage, or previous error
13588 Original_Scope := Scope (Original_Comp);
13589 Type_Scope := Scope (Base_Type (Scope (C)));
13592 -- This test only concerns tagged types
13594 if not Is_Tagged_Type (Original_Scope) then
13597 -- If it is _Parent or _Tag, there is no visibility issue
13599 elsif not Comes_From_Source (Original_Comp) then
13602 -- If we are in the body of an instantiation, the component is visible
13603 -- even when the parent type (possibly defined in an enclosing unit or
13604 -- in a parent unit) might not.
13606 elsif In_Instance_Body then
13609 -- Discriminants are always visible
13611 elsif Ekind (Original_Comp) = E_Discriminant
13612 and then not Has_Unknown_Discriminants (Original_Scope)
13616 -- If the component has been declared in an ancestor which is currently
13617 -- a private type, then it is not visible. The same applies if the
13618 -- component's containing type is not in an open scope and the original
13619 -- component's enclosing type is a visible full view of a private type
13620 -- (which can occur in cases where an attempt is being made to reference
13621 -- a component in a sibling package that is inherited from a visible
13622 -- component of a type in an ancestor package; the component in the
13623 -- sibling package should not be visible even though the component it
13624 -- inherited from is visible). This does not apply however in the case
13625 -- where the scope of the type is a private child unit, or when the
13626 -- parent comes from a local package in which the ancestor is currently
13627 -- visible. The latter suppression of visibility is needed for cases
13628 -- that are tested in B730006.
13630 elsif Is_Private_Type (Original_Scope)
13632 (not Is_Private_Descendant (Type_Scope)
13633 and then not In_Open_Scopes (Type_Scope)
13634 and then Has_Private_Declaration (Original_Scope))
13636 -- If the type derives from an entity in a formal package, there
13637 -- are no additional visible components.
13639 if Nkind (Original_Node (Unit_Declaration_Node (Type_Scope))) =
13640 N_Formal_Package_Declaration
13644 -- if we are not in the private part of the current package, there
13645 -- are no additional visible components.
13647 elsif Ekind (Scope (Current_Scope)) = E_Package
13648 and then not In_Private_Part (Scope (Current_Scope))
13653 Is_Child_Unit (Cunit_Entity (Current_Sem_Unit))
13654 and then In_Open_Scopes (Scope (Original_Scope))
13655 and then Is_Local_Type (Type_Scope);
13658 -- There is another weird way in which a component may be invisible
13659 -- when the private and the full view are not derived from the same
13660 -- ancestor. Here is an example :
13662 -- type A1 is tagged record F1 : integer; end record;
13663 -- type A2 is new A1 with record F2 : integer; end record;
13664 -- type T is new A1 with private;
13666 -- type T is new A2 with null record;
13668 -- In this case, the full view of T inherits F1 and F2 but the private
13669 -- view inherits only F1
13673 Ancestor : Entity_Id := Scope (C);
13677 if Ancestor = Original_Scope then
13679 elsif Ancestor = Etype (Ancestor) then
13683 Ancestor := Etype (Ancestor);
13689 end Is_Visible_Component;
13691 --------------------------
13692 -- Make_Class_Wide_Type --
13693 --------------------------
13695 procedure Make_Class_Wide_Type (T : Entity_Id) is
13696 CW_Type : Entity_Id;
13698 Next_E : Entity_Id;
13701 -- The class wide type can have been defined by the partial view, in
13702 -- which case everything is already done.
13704 if Present (Class_Wide_Type (T)) then
13709 New_External_Entity (E_Void, Scope (T), Sloc (T), T, 'C', 0, 'T');
13711 -- Inherit root type characteristics
13713 CW_Name := Chars (CW_Type);
13714 Next_E := Next_Entity (CW_Type);
13715 Copy_Node (T, CW_Type);
13716 Set_Comes_From_Source (CW_Type, False);
13717 Set_Chars (CW_Type, CW_Name);
13718 Set_Parent (CW_Type, Parent (T));
13719 Set_Next_Entity (CW_Type, Next_E);
13721 -- Ensure we have a new freeze node for the class-wide type. The partial
13722 -- view may have freeze action of its own, requiring a proper freeze
13723 -- node, and the same freeze node cannot be shared between the two
13726 Set_Has_Delayed_Freeze (CW_Type);
13727 Set_Freeze_Node (CW_Type, Empty);
13729 -- Customize the class-wide type: It has no prim. op., it cannot be
13730 -- abstract and its Etype points back to the specific root type.
13732 Set_Ekind (CW_Type, E_Class_Wide_Type);
13733 Set_Is_Tagged_Type (CW_Type, True);
13734 Set_Primitive_Operations (CW_Type, New_Elmt_List);
13735 Set_Is_Abstract_Type (CW_Type, False);
13736 Set_Is_Constrained (CW_Type, False);
13737 Set_Is_First_Subtype (CW_Type, Is_First_Subtype (T));
13738 Init_Size_Align (CW_Type);
13740 if Ekind (T) = E_Class_Wide_Subtype then
13741 Set_Etype (CW_Type, Etype (Base_Type (T)));
13743 Set_Etype (CW_Type, T);
13746 -- If this is the class_wide type of a constrained subtype, it does
13747 -- not have discriminants.
13749 Set_Has_Discriminants (CW_Type,
13750 Has_Discriminants (T) and then not Is_Constrained (T));
13752 Set_Has_Unknown_Discriminants (CW_Type, True);
13753 Set_Class_Wide_Type (T, CW_Type);
13754 Set_Equivalent_Type (CW_Type, Empty);
13756 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
13758 Set_Class_Wide_Type (CW_Type, CW_Type);
13759 end Make_Class_Wide_Type;
13765 procedure Make_Index
13767 Related_Nod : Node_Id;
13768 Related_Id : Entity_Id := Empty;
13769 Suffix_Index : Nat := 1)
13773 Def_Id : Entity_Id := Empty;
13774 Found : Boolean := False;
13777 -- For a discrete range used in a constrained array definition and
13778 -- defined by a range, an implicit conversion to the predefined type
13779 -- INTEGER is assumed if each bound is either a numeric literal, a named
13780 -- number, or an attribute, and the type of both bounds (prior to the
13781 -- implicit conversion) is the type universal_integer. Otherwise, both
13782 -- bounds must be of the same discrete type, other than universal
13783 -- integer; this type must be determinable independently of the
13784 -- context, but using the fact that the type must be discrete and that
13785 -- both bounds must have the same type.
13787 -- Character literals also have a universal type in the absence of
13788 -- of additional context, and are resolved to Standard_Character.
13790 if Nkind (I) = N_Range then
13792 -- The index is given by a range constraint. The bounds are known
13793 -- to be of a consistent type.
13795 if not Is_Overloaded (I) then
13798 -- For universal bounds, choose the specific predefined type
13800 if T = Universal_Integer then
13801 T := Standard_Integer;
13803 elsif T = Any_Character then
13804 Ambiguous_Character (Low_Bound (I));
13806 T := Standard_Character;
13813 Ind : Interp_Index;
13817 Get_First_Interp (I, Ind, It);
13818 while Present (It.Typ) loop
13819 if Is_Discrete_Type (It.Typ) then
13822 and then not Covers (It.Typ, T)
13823 and then not Covers (T, It.Typ)
13825 Error_Msg_N ("ambiguous bounds in discrete range", I);
13833 Get_Next_Interp (Ind, It);
13836 if T = Any_Type then
13837 Error_Msg_N ("discrete type required for range", I);
13838 Set_Etype (I, Any_Type);
13841 elsif T = Universal_Integer then
13842 T := Standard_Integer;
13847 if not Is_Discrete_Type (T) then
13848 Error_Msg_N ("discrete type required for range", I);
13849 Set_Etype (I, Any_Type);
13853 if Nkind (Low_Bound (I)) = N_Attribute_Reference
13854 and then Attribute_Name (Low_Bound (I)) = Name_First
13855 and then Is_Entity_Name (Prefix (Low_Bound (I)))
13856 and then Is_Type (Entity (Prefix (Low_Bound (I))))
13857 and then Is_Discrete_Type (Entity (Prefix (Low_Bound (I))))
13859 -- The type of the index will be the type of the prefix, as long
13860 -- as the upper bound is 'Last of the same type.
13862 Def_Id := Entity (Prefix (Low_Bound (I)));
13864 if Nkind (High_Bound (I)) /= N_Attribute_Reference
13865 or else Attribute_Name (High_Bound (I)) /= Name_Last
13866 or else not Is_Entity_Name (Prefix (High_Bound (I)))
13867 or else Entity (Prefix (High_Bound (I))) /= Def_Id
13874 Process_Range_Expr_In_Decl (R, T);
13876 elsif Nkind (I) = N_Subtype_Indication then
13878 -- The index is given by a subtype with a range constraint
13880 T := Base_Type (Entity (Subtype_Mark (I)));
13882 if not Is_Discrete_Type (T) then
13883 Error_Msg_N ("discrete type required for range", I);
13884 Set_Etype (I, Any_Type);
13888 R := Range_Expression (Constraint (I));
13891 Process_Range_Expr_In_Decl (R, Entity (Subtype_Mark (I)));
13893 elsif Nkind (I) = N_Attribute_Reference then
13895 -- The parser guarantees that the attribute is a RANGE attribute
13897 -- If the node denotes the range of a type mark, that is also the
13898 -- resulting type, and we do no need to create an Itype for it.
13900 if Is_Entity_Name (Prefix (I))
13901 and then Comes_From_Source (I)
13902 and then Is_Type (Entity (Prefix (I)))
13903 and then Is_Discrete_Type (Entity (Prefix (I)))
13905 Def_Id := Entity (Prefix (I));
13908 Analyze_And_Resolve (I);
13912 -- If none of the above, must be a subtype. We convert this to a
13913 -- range attribute reference because in the case of declared first
13914 -- named subtypes, the types in the range reference can be different
13915 -- from the type of the entity. A range attribute normalizes the
13916 -- reference and obtains the correct types for the bounds.
13918 -- This transformation is in the nature of an expansion, is only
13919 -- done if expansion is active. In particular, it is not done on
13920 -- formal generic types, because we need to retain the name of the
13921 -- original index for instantiation purposes.
13924 if not Is_Entity_Name (I) or else not Is_Type (Entity (I)) then
13925 Error_Msg_N ("invalid subtype mark in discrete range ", I);
13926 Set_Etype (I, Any_Integer);
13930 -- The type mark may be that of an incomplete type. It is only
13931 -- now that we can get the full view, previous analysis does
13932 -- not look specifically for a type mark.
13934 Set_Entity (I, Get_Full_View (Entity (I)));
13935 Set_Etype (I, Entity (I));
13936 Def_Id := Entity (I);
13938 if not Is_Discrete_Type (Def_Id) then
13939 Error_Msg_N ("discrete type required for index", I);
13940 Set_Etype (I, Any_Type);
13945 if Expander_Active then
13947 Make_Attribute_Reference (Sloc (I),
13948 Attribute_Name => Name_Range,
13949 Prefix => Relocate_Node (I)));
13951 -- The original was a subtype mark that does not freeze. This
13952 -- means that the rewritten version must not freeze either.
13954 Set_Must_Not_Freeze (I);
13955 Set_Must_Not_Freeze (Prefix (I));
13957 -- Is order critical??? if so, document why, if not
13958 -- use Analyze_And_Resolve
13960 Analyze_And_Resolve (I);
13964 -- If expander is inactive, type is legal, nothing else to construct
13971 if not Is_Discrete_Type (T) then
13972 Error_Msg_N ("discrete type required for range", I);
13973 Set_Etype (I, Any_Type);
13976 elsif T = Any_Type then
13977 Set_Etype (I, Any_Type);
13981 -- We will now create the appropriate Itype to describe the range, but
13982 -- first a check. If we originally had a subtype, then we just label
13983 -- the range with this subtype. Not only is there no need to construct
13984 -- a new subtype, but it is wrong to do so for two reasons:
13986 -- 1. A legality concern, if we have a subtype, it must not freeze,
13987 -- and the Itype would cause freezing incorrectly
13989 -- 2. An efficiency concern, if we created an Itype, it would not be
13990 -- recognized as the same type for the purposes of eliminating
13991 -- checks in some circumstances.
13993 -- We signal this case by setting the subtype entity in Def_Id
13995 if No (Def_Id) then
13997 Create_Itype (E_Void, Related_Nod, Related_Id, 'D', Suffix_Index);
13998 Set_Etype (Def_Id, Base_Type (T));
14000 if Is_Signed_Integer_Type (T) then
14001 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
14003 elsif Is_Modular_Integer_Type (T) then
14004 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
14007 Set_Ekind (Def_Id, E_Enumeration_Subtype);
14008 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
14009 Set_First_Literal (Def_Id, First_Literal (T));
14012 Set_Size_Info (Def_Id, (T));
14013 Set_RM_Size (Def_Id, RM_Size (T));
14014 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
14016 Set_Scalar_Range (Def_Id, R);
14017 Conditional_Delay (Def_Id, T);
14019 -- In the subtype indication case, if the immediate parent of the
14020 -- new subtype is non-static, then the subtype we create is non-
14021 -- static, even if its bounds are static.
14023 if Nkind (I) = N_Subtype_Indication
14024 and then not Is_Static_Subtype (Entity (Subtype_Mark (I)))
14026 Set_Is_Non_Static_Subtype (Def_Id);
14030 -- Final step is to label the index with this constructed type
14032 Set_Etype (I, Def_Id);
14035 ------------------------------
14036 -- Modular_Type_Declaration --
14037 ------------------------------
14039 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id) is
14040 Mod_Expr : constant Node_Id := Expression (Def);
14043 procedure Set_Modular_Size (Bits : Int);
14044 -- Sets RM_Size to Bits, and Esize to normal word size above this
14046 ----------------------
14047 -- Set_Modular_Size --
14048 ----------------------
14050 procedure Set_Modular_Size (Bits : Int) is
14052 Set_RM_Size (T, UI_From_Int (Bits));
14057 elsif Bits <= 16 then
14058 Init_Esize (T, 16);
14060 elsif Bits <= 32 then
14061 Init_Esize (T, 32);
14064 Init_Esize (T, System_Max_Binary_Modulus_Power);
14066 end Set_Modular_Size;
14068 -- Start of processing for Modular_Type_Declaration
14071 Analyze_And_Resolve (Mod_Expr, Any_Integer);
14073 Set_Ekind (T, E_Modular_Integer_Type);
14074 Init_Alignment (T);
14075 Set_Is_Constrained (T);
14077 if not Is_OK_Static_Expression (Mod_Expr) then
14078 Flag_Non_Static_Expr
14079 ("non-static expression used for modular type bound!", Mod_Expr);
14080 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14082 M_Val := Expr_Value (Mod_Expr);
14086 Error_Msg_N ("modulus value must be positive", Mod_Expr);
14087 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14090 Set_Modulus (T, M_Val);
14092 -- Create bounds for the modular type based on the modulus given in
14093 -- the type declaration and then analyze and resolve those bounds.
14095 Set_Scalar_Range (T,
14096 Make_Range (Sloc (Mod_Expr),
14098 Make_Integer_Literal (Sloc (Mod_Expr), 0),
14100 Make_Integer_Literal (Sloc (Mod_Expr), M_Val - 1)));
14102 -- Properly analyze the literals for the range. We do this manually
14103 -- because we can't go calling Resolve, since we are resolving these
14104 -- bounds with the type, and this type is certainly not complete yet!
14106 Set_Etype (Low_Bound (Scalar_Range (T)), T);
14107 Set_Etype (High_Bound (Scalar_Range (T)), T);
14108 Set_Is_Static_Expression (Low_Bound (Scalar_Range (T)));
14109 Set_Is_Static_Expression (High_Bound (Scalar_Range (T)));
14111 -- Loop through powers of two to find number of bits required
14113 for Bits in Int range 0 .. System_Max_Binary_Modulus_Power loop
14117 if M_Val = 2 ** Bits then
14118 Set_Modular_Size (Bits);
14123 elsif M_Val < 2 ** Bits then
14124 Set_Non_Binary_Modulus (T);
14126 if Bits > System_Max_Nonbinary_Modulus_Power then
14127 Error_Msg_Uint_1 :=
14128 UI_From_Int (System_Max_Nonbinary_Modulus_Power);
14130 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr);
14131 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14135 -- In the non-binary case, set size as per RM 13.3(55)
14137 Set_Modular_Size (Bits);
14144 -- If we fall through, then the size exceed System.Max_Binary_Modulus
14145 -- so we just signal an error and set the maximum size.
14147 Error_Msg_Uint_1 := UI_From_Int (System_Max_Binary_Modulus_Power);
14148 Error_Msg_F ("modulus exceeds limit (2 '*'*^)", Mod_Expr);
14150 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14151 Init_Alignment (T);
14153 end Modular_Type_Declaration;
14155 --------------------------
14156 -- New_Concatenation_Op --
14157 --------------------------
14159 procedure New_Concatenation_Op (Typ : Entity_Id) is
14160 Loc : constant Source_Ptr := Sloc (Typ);
14163 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id;
14164 -- Create abbreviated declaration for the formal of a predefined
14165 -- Operator 'Op' of type 'Typ'
14167 --------------------
14168 -- Make_Op_Formal --
14169 --------------------
14171 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id is
14172 Formal : Entity_Id;
14174 Formal := New_Internal_Entity (E_In_Parameter, Op, Loc, 'P');
14175 Set_Etype (Formal, Typ);
14176 Set_Mechanism (Formal, Default_Mechanism);
14178 end Make_Op_Formal;
14180 -- Start of processing for New_Concatenation_Op
14183 Op := Make_Defining_Operator_Symbol (Loc, Name_Op_Concat);
14185 Set_Ekind (Op, E_Operator);
14186 Set_Scope (Op, Current_Scope);
14187 Set_Etype (Op, Typ);
14188 Set_Homonym (Op, Get_Name_Entity_Id (Name_Op_Concat));
14189 Set_Is_Immediately_Visible (Op);
14190 Set_Is_Intrinsic_Subprogram (Op);
14191 Set_Has_Completion (Op);
14192 Append_Entity (Op, Current_Scope);
14194 Set_Name_Entity_Id (Name_Op_Concat, Op);
14196 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14197 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14198 end New_Concatenation_Op;
14200 -------------------------
14201 -- OK_For_Limited_Init --
14202 -------------------------
14204 -- ???Check all calls of this, and compare the conditions under which it's
14207 function OK_For_Limited_Init (Exp : Node_Id) return Boolean is
14209 return Ada_Version >= Ada_05
14210 and then not Debug_Flag_Dot_L
14211 and then OK_For_Limited_Init_In_05 (Exp);
14212 end OK_For_Limited_Init;
14214 -------------------------------
14215 -- OK_For_Limited_Init_In_05 --
14216 -------------------------------
14218 function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean is
14220 -- ???Expand_N_Extended_Return_Statement generates code that would
14221 -- violate the rules in some cases. Once we have build-in-place
14222 -- function returns working, we can probably remove the following
14225 if not Comes_From_Source (Exp) then
14229 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
14230 -- case of limited aggregates (including extension aggregates), and
14231 -- function calls. The function call may have been give in prefixed
14232 -- notation, in which case the original node is an indexed component.
14234 case Nkind (Original_Node (Exp)) is
14235 when N_Aggregate | N_Extension_Aggregate | N_Function_Call | N_Op =>
14238 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
14239 -- with a function call, the expander has rewritten the call into an
14240 -- N_Type_Conversion node to force displacement of the pointer to
14241 -- reference the component containing the secondary dispatch table.
14243 when N_Qualified_Expression | N_Type_Conversion =>
14244 return OK_For_Limited_Init_In_05
14245 (Expression (Original_Node (Exp)));
14247 when N_Indexed_Component | N_Selected_Component =>
14248 return Nkind (Exp) = N_Function_Call;
14250 -- A use of 'Input is a function call, hence allowed. Normally the
14251 -- attribute will be changed to a call, but the attribute by itself
14252 -- can occur with -gnatc.
14254 when N_Attribute_Reference =>
14255 return Attribute_Name (Original_Node (Exp)) = Name_Input;
14260 end OK_For_Limited_Init_In_05;
14262 -------------------------------------------
14263 -- Ordinary_Fixed_Point_Type_Declaration --
14264 -------------------------------------------
14266 procedure Ordinary_Fixed_Point_Type_Declaration
14270 Loc : constant Source_Ptr := Sloc (Def);
14271 Delta_Expr : constant Node_Id := Delta_Expression (Def);
14272 RRS : constant Node_Id := Real_Range_Specification (Def);
14273 Implicit_Base : Entity_Id;
14280 Check_Restriction (No_Fixed_Point, Def);
14282 -- Create implicit base type
14285 Create_Itype (E_Ordinary_Fixed_Point_Type, Parent (Def), T, 'B');
14286 Set_Etype (Implicit_Base, Implicit_Base);
14288 -- Analyze and process delta expression
14290 Analyze_And_Resolve (Delta_Expr, Any_Real);
14292 Check_Delta_Expression (Delta_Expr);
14293 Delta_Val := Expr_Value_R (Delta_Expr);
14295 Set_Delta_Value (Implicit_Base, Delta_Val);
14297 -- Compute default small from given delta, which is the largest power
14298 -- of two that does not exceed the given delta value.
14308 if Delta_Val < Ureal_1 then
14309 while Delta_Val < Tmp loop
14310 Tmp := Tmp / Ureal_2;
14311 Scale := Scale + 1;
14316 Tmp := Tmp * Ureal_2;
14317 exit when Tmp > Delta_Val;
14318 Scale := Scale - 1;
14322 Small_Val := UR_From_Components (Uint_1, UI_From_Int (Scale), 2);
14325 Set_Small_Value (Implicit_Base, Small_Val);
14327 -- If no range was given, set a dummy range
14329 if RRS <= Empty_Or_Error then
14330 Low_Val := -Small_Val;
14331 High_Val := Small_Val;
14333 -- Otherwise analyze and process given range
14337 Low : constant Node_Id := Low_Bound (RRS);
14338 High : constant Node_Id := High_Bound (RRS);
14341 Analyze_And_Resolve (Low, Any_Real);
14342 Analyze_And_Resolve (High, Any_Real);
14343 Check_Real_Bound (Low);
14344 Check_Real_Bound (High);
14346 -- Obtain and set the range
14348 Low_Val := Expr_Value_R (Low);
14349 High_Val := Expr_Value_R (High);
14351 if Low_Val > High_Val then
14352 Error_Msg_NE ("?fixed point type& has null range", Def, T);
14357 -- The range for both the implicit base and the declared first subtype
14358 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
14359 -- set a temporary range in place. Note that the bounds of the base
14360 -- type will be widened to be symmetrical and to fill the available
14361 -- bits when the type is frozen.
14363 -- We could do this with all discrete types, and probably should, but
14364 -- we absolutely have to do it for fixed-point, since the end-points
14365 -- of the range and the size are determined by the small value, which
14366 -- could be reset before the freeze point.
14368 Set_Fixed_Range (Implicit_Base, Loc, Low_Val, High_Val);
14369 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
14371 Init_Size_Align (Implicit_Base);
14373 -- Complete definition of first subtype
14375 Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype);
14376 Set_Etype (T, Implicit_Base);
14377 Init_Size_Align (T);
14378 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
14379 Set_Small_Value (T, Small_Val);
14380 Set_Delta_Value (T, Delta_Val);
14381 Set_Is_Constrained (T);
14383 end Ordinary_Fixed_Point_Type_Declaration;
14385 ----------------------------------------
14386 -- Prepare_Private_Subtype_Completion --
14387 ----------------------------------------
14389 procedure Prepare_Private_Subtype_Completion
14391 Related_Nod : Node_Id)
14393 Id_B : constant Entity_Id := Base_Type (Id);
14394 Full_B : constant Entity_Id := Full_View (Id_B);
14398 if Present (Full_B) then
14400 -- The Base_Type is already completed, we can complete the subtype
14401 -- now. We have to create a new entity with the same name, Thus we
14402 -- can't use Create_Itype.
14404 -- This is messy, should be fixed ???
14406 Full := Make_Defining_Identifier (Sloc (Id), Chars (Id));
14407 Set_Is_Itype (Full);
14408 Set_Associated_Node_For_Itype (Full, Related_Nod);
14409 Complete_Private_Subtype (Id, Full, Full_B, Related_Nod);
14412 -- The parent subtype may be private, but the base might not, in some
14413 -- nested instances. In that case, the subtype does not need to be
14414 -- exchanged. It would still be nice to make private subtypes and their
14415 -- bases consistent at all times ???
14417 if Is_Private_Type (Id_B) then
14418 Append_Elmt (Id, Private_Dependents (Id_B));
14421 end Prepare_Private_Subtype_Completion;
14423 ---------------------------
14424 -- Process_Discriminants --
14425 ---------------------------
14427 procedure Process_Discriminants
14429 Prev : Entity_Id := Empty)
14431 Elist : constant Elist_Id := New_Elmt_List;
14434 Discr_Number : Uint;
14435 Discr_Type : Entity_Id;
14436 Default_Present : Boolean := False;
14437 Default_Not_Present : Boolean := False;
14440 -- A composite type other than an array type can have discriminants.
14441 -- On entry, the current scope is the composite type.
14443 -- The discriminants are initially entered into the scope of the type
14444 -- via Enter_Name with the default Ekind of E_Void to prevent premature
14445 -- use, as explained at the end of this procedure.
14447 Discr := First (Discriminant_Specifications (N));
14448 while Present (Discr) loop
14449 Enter_Name (Defining_Identifier (Discr));
14451 -- For navigation purposes we add a reference to the discriminant
14452 -- in the entity for the type. If the current declaration is a
14453 -- completion, place references on the partial view. Otherwise the
14454 -- type is the current scope.
14456 if Present (Prev) then
14458 -- The references go on the partial view, if present. If the
14459 -- partial view has discriminants, the references have been
14460 -- generated already.
14462 if not Has_Discriminants (Prev) then
14463 Generate_Reference (Prev, Defining_Identifier (Discr), 'd');
14467 (Current_Scope, Defining_Identifier (Discr), 'd');
14470 if Nkind (Discriminant_Type (Discr)) = N_Access_Definition then
14471 Discr_Type := Access_Definition (Discr, Discriminant_Type (Discr));
14473 -- Ada 2005 (AI-254)
14475 if Present (Access_To_Subprogram_Definition
14476 (Discriminant_Type (Discr)))
14477 and then Protected_Present (Access_To_Subprogram_Definition
14478 (Discriminant_Type (Discr)))
14481 Replace_Anonymous_Access_To_Protected_Subprogram (Discr);
14485 Find_Type (Discriminant_Type (Discr));
14486 Discr_Type := Etype (Discriminant_Type (Discr));
14488 if Error_Posted (Discriminant_Type (Discr)) then
14489 Discr_Type := Any_Type;
14493 if Is_Access_Type (Discr_Type) then
14495 -- Ada 2005 (AI-230): Access discriminant allowed in non-limited
14498 if Ada_Version < Ada_05 then
14499 Check_Access_Discriminant_Requires_Limited
14500 (Discr, Discriminant_Type (Discr));
14503 if Ada_Version = Ada_83 and then Comes_From_Source (Discr) then
14505 ("(Ada 83) access discriminant not allowed", Discr);
14508 elsif not Is_Discrete_Type (Discr_Type) then
14509 Error_Msg_N ("discriminants must have a discrete or access type",
14510 Discriminant_Type (Discr));
14513 Set_Etype (Defining_Identifier (Discr), Discr_Type);
14515 -- If a discriminant specification includes the assignment compound
14516 -- delimiter followed by an expression, the expression is the default
14517 -- expression of the discriminant; the default expression must be of
14518 -- the type of the discriminant. (RM 3.7.1) Since this expression is
14519 -- a default expression, we do the special preanalysis, since this
14520 -- expression does not freeze (see "Handling of Default and Per-
14521 -- Object Expressions" in spec of package Sem).
14523 if Present (Expression (Discr)) then
14524 Analyze_Per_Use_Expression (Expression (Discr), Discr_Type);
14526 if Nkind (N) = N_Formal_Type_Declaration then
14528 ("discriminant defaults not allowed for formal type",
14529 Expression (Discr));
14531 -- Tagged types cannot have defaulted discriminants, but a
14532 -- non-tagged private type with defaulted discriminants
14533 -- can have a tagged completion.
14535 elsif Is_Tagged_Type (Current_Scope)
14536 and then Comes_From_Source (N)
14539 ("discriminants of tagged type cannot have defaults",
14540 Expression (Discr));
14543 Default_Present := True;
14544 Append_Elmt (Expression (Discr), Elist);
14546 -- Tag the defining identifiers for the discriminants with
14547 -- their corresponding default expressions from the tree.
14549 Set_Discriminant_Default_Value
14550 (Defining_Identifier (Discr), Expression (Discr));
14554 Default_Not_Present := True;
14557 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
14558 -- Discr_Type but with the null-exclusion attribute
14560 if Ada_Version >= Ada_05 then
14562 -- Ada 2005 (AI-231): Static checks
14564 if Can_Never_Be_Null (Discr_Type) then
14565 Null_Exclusion_Static_Checks (Discr);
14567 elsif Is_Access_Type (Discr_Type)
14568 and then Null_Exclusion_Present (Discr)
14570 -- No need to check itypes because in their case this check
14571 -- was done at their point of creation
14573 and then not Is_Itype (Discr_Type)
14575 if Can_Never_Be_Null (Discr_Type) then
14577 ("`NOT NULL` not allowed (& already excludes null)",
14582 Set_Etype (Defining_Identifier (Discr),
14583 Create_Null_Excluding_Itype
14585 Related_Nod => Discr));
14588 -- Ada 2005 (AI-402): access discriminants of nonlimited types
14589 -- can't have defaults
14591 if Is_Access_Type (Discr_Type) then
14592 if Ekind (Discr_Type) /= E_Anonymous_Access_Type
14593 or else not Default_Present
14594 or else Is_Limited_Record (Current_Scope)
14595 or else Is_Concurrent_Type (Current_Scope)
14596 or else Is_Concurrent_Record_Type (Current_Scope)
14597 or else Ekind (Current_Scope) = E_Limited_Private_Type
14601 elsif Present (Expression (Discr)) then
14603 ("(Ada 2005) access discriminants of nonlimited types",
14604 Expression (Discr));
14605 Error_Msg_N ("\cannot have defaults", Expression (Discr));
14613 -- An element list consisting of the default expressions of the
14614 -- discriminants is constructed in the above loop and used to set
14615 -- the Discriminant_Constraint attribute for the type. If an object
14616 -- is declared of this (record or task) type without any explicit
14617 -- discriminant constraint given, this element list will form the
14618 -- actual parameters for the corresponding initialization procedure
14621 Set_Discriminant_Constraint (Current_Scope, Elist);
14622 Set_Stored_Constraint (Current_Scope, No_Elist);
14624 -- Default expressions must be provided either for all or for none
14625 -- of the discriminants of a discriminant part. (RM 3.7.1)
14627 if Default_Present and then Default_Not_Present then
14629 ("incomplete specification of defaults for discriminants", N);
14632 -- The use of the name of a discriminant is not allowed in default
14633 -- expressions of a discriminant part if the specification of the
14634 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
14636 -- To detect this, the discriminant names are entered initially with an
14637 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
14638 -- attempt to use a void entity (for example in an expression that is
14639 -- type-checked) produces the error message: premature usage. Now after
14640 -- completing the semantic analysis of the discriminant part, we can set
14641 -- the Ekind of all the discriminants appropriately.
14643 Discr := First (Discriminant_Specifications (N));
14644 Discr_Number := Uint_1;
14645 while Present (Discr) loop
14646 Id := Defining_Identifier (Discr);
14647 Set_Ekind (Id, E_Discriminant);
14648 Init_Component_Location (Id);
14650 Set_Discriminant_Number (Id, Discr_Number);
14652 -- Make sure this is always set, even in illegal programs
14654 Set_Corresponding_Discriminant (Id, Empty);
14656 -- Initialize the Original_Record_Component to the entity itself.
14657 -- Inherit_Components will propagate the right value to
14658 -- discriminants in derived record types.
14660 Set_Original_Record_Component (Id, Id);
14662 -- Create the discriminal for the discriminant
14664 Build_Discriminal (Id);
14667 Discr_Number := Discr_Number + 1;
14670 Set_Has_Discriminants (Current_Scope);
14671 end Process_Discriminants;
14673 -----------------------
14674 -- Process_Full_View --
14675 -----------------------
14677 procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id) is
14678 Priv_Parent : Entity_Id;
14679 Full_Parent : Entity_Id;
14680 Full_Indic : Node_Id;
14682 procedure Collect_Implemented_Interfaces
14684 Ifaces : Elist_Id);
14685 -- Ada 2005: Gather all the interfaces that Typ directly or
14686 -- inherently implements. Duplicate entries are not added to
14687 -- the list Ifaces.
14689 ------------------------------------
14690 -- Collect_Implemented_Interfaces --
14691 ------------------------------------
14693 procedure Collect_Implemented_Interfaces
14698 Iface_Elmt : Elmt_Id;
14701 -- Abstract interfaces are only associated with tagged record types
14703 if not Is_Tagged_Type (Typ)
14704 or else not Is_Record_Type (Typ)
14709 -- Recursively climb to the ancestors
14711 if Etype (Typ) /= Typ
14713 -- Protect the frontend against wrong cyclic declarations like:
14715 -- type B is new A with private;
14716 -- type C is new A with private;
14718 -- type B is new C with null record;
14719 -- type C is new B with null record;
14721 and then Etype (Typ) /= Priv_T
14722 and then Etype (Typ) /= Full_T
14724 -- Keep separate the management of private type declarations
14726 if Ekind (Typ) = E_Record_Type_With_Private then
14728 -- Handle the following erronous case:
14729 -- type Private_Type is tagged private;
14731 -- type Private_Type is new Type_Implementing_Iface;
14733 if Present (Full_View (Typ))
14734 and then Etype (Typ) /= Full_View (Typ)
14736 if Is_Interface (Etype (Typ)) then
14737 Append_Unique_Elmt (Etype (Typ), Ifaces);
14740 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
14743 -- Non-private types
14746 if Is_Interface (Etype (Typ)) then
14747 Append_Unique_Elmt (Etype (Typ), Ifaces);
14750 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
14754 -- Handle entities in the list of abstract interfaces
14756 if Present (Abstract_Interfaces (Typ)) then
14757 Iface_Elmt := First_Elmt (Abstract_Interfaces (Typ));
14758 while Present (Iface_Elmt) loop
14759 Iface := Node (Iface_Elmt);
14761 pragma Assert (Is_Interface (Iface));
14763 if not Contain_Interface (Iface, Ifaces) then
14764 Append_Elmt (Iface, Ifaces);
14765 Collect_Implemented_Interfaces (Iface, Ifaces);
14768 Next_Elmt (Iface_Elmt);
14771 end Collect_Implemented_Interfaces;
14773 -- Start of processing for Process_Full_View
14776 -- First some sanity checks that must be done after semantic
14777 -- decoration of the full view and thus cannot be placed with other
14778 -- similar checks in Find_Type_Name
14780 if not Is_Limited_Type (Priv_T)
14781 and then (Is_Limited_Type (Full_T)
14782 or else Is_Limited_Composite (Full_T))
14785 ("completion of nonlimited type cannot be limited", Full_T);
14786 Explain_Limited_Type (Full_T, Full_T);
14788 elsif Is_Abstract_Type (Full_T)
14789 and then not Is_Abstract_Type (Priv_T)
14792 ("completion of nonabstract type cannot be abstract", Full_T);
14794 elsif Is_Tagged_Type (Priv_T)
14795 and then Is_Limited_Type (Priv_T)
14796 and then not Is_Limited_Type (Full_T)
14798 -- If pragma CPP_Class was applied to the private declaration
14799 -- propagate the limitedness to the full-view
14801 if Is_CPP_Class (Priv_T) then
14802 Set_Is_Limited_Record (Full_T);
14804 -- GNAT allow its own definition of Limited_Controlled to disobey
14805 -- this rule in order in ease the implementation. The next test is
14806 -- safe because Root_Controlled is defined in a private system child
14808 elsif Etype (Full_T) = Full_View (RTE (RE_Root_Controlled)) then
14809 Set_Is_Limited_Composite (Full_T);
14812 ("completion of limited tagged type must be limited", Full_T);
14815 elsif Is_Generic_Type (Priv_T) then
14816 Error_Msg_N ("generic type cannot have a completion", Full_T);
14819 -- Check that ancestor interfaces of private and full views are
14820 -- consistent. We omit this check for synchronized types because
14821 -- they are performed on the corresponding record type when frozen.
14823 if Ada_Version >= Ada_05
14824 and then Is_Tagged_Type (Priv_T)
14825 and then Is_Tagged_Type (Full_T)
14826 and then not Is_Concurrent_Type (Full_T)
14830 Priv_T_Ifaces : constant Elist_Id := New_Elmt_List;
14831 Full_T_Ifaces : constant Elist_Id := New_Elmt_List;
14834 Collect_Implemented_Interfaces (Priv_T, Priv_T_Ifaces);
14835 Collect_Implemented_Interfaces (Full_T, Full_T_Ifaces);
14837 -- Ada 2005 (AI-251): The partial view shall be a descendant of
14838 -- an interface type if and only if the full type is descendant
14839 -- of the interface type (AARM 7.3 (7.3/2).
14841 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
14843 if Present (Iface) then
14844 Error_Msg_NE ("interface & not implemented by full type " &
14845 "(RM-2005 7.3 (7.3/2))", Priv_T, Iface);
14848 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
14850 if Present (Iface) then
14851 Error_Msg_NE ("interface & not implemented by partial view " &
14852 "(RM-2005 7.3 (7.3/2))", Full_T, Iface);
14857 if Is_Tagged_Type (Priv_T)
14858 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
14859 and then Is_Derived_Type (Full_T)
14861 Priv_Parent := Etype (Priv_T);
14863 -- The full view of a private extension may have been transformed
14864 -- into an unconstrained derived type declaration and a subtype
14865 -- declaration (see build_derived_record_type for details).
14867 if Nkind (N) = N_Subtype_Declaration then
14868 Full_Indic := Subtype_Indication (N);
14869 Full_Parent := Etype (Base_Type (Full_T));
14871 Full_Indic := Subtype_Indication (Type_Definition (N));
14872 Full_Parent := Etype (Full_T);
14875 -- Check that the parent type of the full type is a descendant of
14876 -- the ancestor subtype given in the private extension. If either
14877 -- entity has an Etype equal to Any_Type then we had some previous
14878 -- error situation [7.3(8)].
14880 if Priv_Parent = Any_Type or else Full_Parent = Any_Type then
14883 -- Ada 2005 (AI-251): Interfaces in the full-typ can be given in
14884 -- any order. Therefore we don't have to check that its parent must
14885 -- be a descendant of the parent of the private type declaration.
14887 elsif Is_Interface (Priv_Parent)
14888 and then Is_Interface (Full_Parent)
14892 -- Ada 2005 (AI-251): If the parent of the private type declaration
14893 -- is an interface there is no need to check that it is an ancestor
14894 -- of the associated full type declaration. The required tests for
14895 -- this case case are performed by Build_Derived_Record_Type.
14897 elsif not Is_Interface (Base_Type (Priv_Parent))
14898 and then not Is_Ancestor (Base_Type (Priv_Parent), Full_Parent)
14901 ("parent of full type must descend from parent"
14902 & " of private extension", Full_Indic);
14904 -- Check the rules of 7.3(10): if the private extension inherits
14905 -- known discriminants, then the full type must also inherit those
14906 -- discriminants from the same (ancestor) type, and the parent
14907 -- subtype of the full type must be constrained if and only if
14908 -- the ancestor subtype of the private extension is constrained.
14910 elsif No (Discriminant_Specifications (Parent (Priv_T)))
14911 and then not Has_Unknown_Discriminants (Priv_T)
14912 and then Has_Discriminants (Base_Type (Priv_Parent))
14915 Priv_Indic : constant Node_Id :=
14916 Subtype_Indication (Parent (Priv_T));
14918 Priv_Constr : constant Boolean :=
14919 Is_Constrained (Priv_Parent)
14921 Nkind (Priv_Indic) = N_Subtype_Indication
14922 or else Is_Constrained (Entity (Priv_Indic));
14924 Full_Constr : constant Boolean :=
14925 Is_Constrained (Full_Parent)
14927 Nkind (Full_Indic) = N_Subtype_Indication
14928 or else Is_Constrained (Entity (Full_Indic));
14930 Priv_Discr : Entity_Id;
14931 Full_Discr : Entity_Id;
14934 Priv_Discr := First_Discriminant (Priv_Parent);
14935 Full_Discr := First_Discriminant (Full_Parent);
14936 while Present (Priv_Discr) and then Present (Full_Discr) loop
14937 if Original_Record_Component (Priv_Discr) =
14938 Original_Record_Component (Full_Discr)
14940 Corresponding_Discriminant (Priv_Discr) =
14941 Corresponding_Discriminant (Full_Discr)
14948 Next_Discriminant (Priv_Discr);
14949 Next_Discriminant (Full_Discr);
14952 if Present (Priv_Discr) or else Present (Full_Discr) then
14954 ("full view must inherit discriminants of the parent type"
14955 & " used in the private extension", Full_Indic);
14957 elsif Priv_Constr and then not Full_Constr then
14959 ("parent subtype of full type must be constrained",
14962 elsif Full_Constr and then not Priv_Constr then
14964 ("parent subtype of full type must be unconstrained",
14969 -- Check the rules of 7.3(12): if a partial view has neither known
14970 -- or unknown discriminants, then the full type declaration shall
14971 -- define a definite subtype.
14973 elsif not Has_Unknown_Discriminants (Priv_T)
14974 and then not Has_Discriminants (Priv_T)
14975 and then not Is_Constrained (Full_T)
14978 ("full view must define a constrained type if partial view"
14979 & " has no discriminants", Full_T);
14982 -- ??????? Do we implement the following properly ?????
14983 -- If the ancestor subtype of a private extension has constrained
14984 -- discriminants, then the parent subtype of the full view shall
14985 -- impose a statically matching constraint on those discriminants
14989 -- For untagged types, verify that a type without discriminants
14990 -- is not completed with an unconstrained type.
14992 if not Is_Indefinite_Subtype (Priv_T)
14993 and then Is_Indefinite_Subtype (Full_T)
14995 Error_Msg_N ("full view of type must be definite subtype", Full_T);
14999 -- AI-419: verify that the use of "limited" is consistent
15002 Orig_Decl : constant Node_Id := Original_Node (N);
15005 if Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15006 and then not Limited_Present (Parent (Priv_T))
15007 and then not Synchronized_Present (Parent (Priv_T))
15008 and then Nkind (Orig_Decl) = N_Full_Type_Declaration
15010 (Type_Definition (Orig_Decl)) = N_Derived_Type_Definition
15011 and then Limited_Present (Type_Definition (Orig_Decl))
15014 ("full view of non-limited extension cannot be limited", N);
15018 -- Ada 2005 (AI-443): A synchronized private extension must be
15019 -- completed by a task or protected type.
15021 if Ada_Version >= Ada_05
15022 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15023 and then Synchronized_Present (Parent (Priv_T))
15024 and then not Is_Concurrent_Type (Full_T)
15026 Error_Msg_N ("full view of synchronized extension must " &
15027 "be synchronized type", N);
15030 -- Ada 2005 AI-363: if the full view has discriminants with
15031 -- defaults, it is illegal to declare constrained access subtypes
15032 -- whose designated type is the current type. This allows objects
15033 -- of the type that are declared in the heap to be unconstrained.
15035 if not Has_Unknown_Discriminants (Priv_T)
15036 and then not Has_Discriminants (Priv_T)
15037 and then Has_Discriminants (Full_T)
15039 Present (Discriminant_Default_Value (First_Discriminant (Full_T)))
15041 Set_Has_Constrained_Partial_View (Full_T);
15042 Set_Has_Constrained_Partial_View (Priv_T);
15045 -- Create a full declaration for all its subtypes recorded in
15046 -- Private_Dependents and swap them similarly to the base type. These
15047 -- are subtypes that have been define before the full declaration of
15048 -- the private type. We also swap the entry in Private_Dependents list
15049 -- so we can properly restore the private view on exit from the scope.
15052 Priv_Elmt : Elmt_Id;
15057 Priv_Elmt := First_Elmt (Private_Dependents (Priv_T));
15058 while Present (Priv_Elmt) loop
15059 Priv := Node (Priv_Elmt);
15061 if Ekind (Priv) = E_Private_Subtype
15062 or else Ekind (Priv) = E_Limited_Private_Subtype
15063 or else Ekind (Priv) = E_Record_Subtype_With_Private
15065 Full := Make_Defining_Identifier (Sloc (Priv), Chars (Priv));
15066 Set_Is_Itype (Full);
15067 Set_Parent (Full, Parent (Priv));
15068 Set_Associated_Node_For_Itype (Full, N);
15070 -- Now we need to complete the private subtype, but since the
15071 -- base type has already been swapped, we must also swap the
15072 -- subtypes (and thus, reverse the arguments in the call to
15073 -- Complete_Private_Subtype).
15075 Copy_And_Swap (Priv, Full);
15076 Complete_Private_Subtype (Full, Priv, Full_T, N);
15077 Replace_Elmt (Priv_Elmt, Full);
15080 Next_Elmt (Priv_Elmt);
15084 -- If the private view was tagged, copy the new primitive operations
15085 -- from the private view to the full view.
15087 if Is_Tagged_Type (Full_T)
15088 and then not Is_Concurrent_Type (Full_T)
15091 Priv_List : Elist_Id;
15092 Full_List : constant Elist_Id := Primitive_Operations (Full_T);
15095 D_Type : Entity_Id;
15098 if Is_Tagged_Type (Priv_T) then
15099 Priv_List := Primitive_Operations (Priv_T);
15101 P1 := First_Elmt (Priv_List);
15102 while Present (P1) loop
15105 -- Transfer explicit primitives, not those inherited from
15106 -- parent of partial view, which will be re-inherited on
15109 if Comes_From_Source (Prim) then
15110 P2 := First_Elmt (Full_List);
15111 while Present (P2) and then Node (P2) /= Prim loop
15115 -- If not found, that is a new one
15118 Append_Elmt (Prim, Full_List);
15126 -- In this case the partial view is untagged, so here we locate
15127 -- all of the earlier primitives that need to be treated as
15128 -- dispatching (those that appear between the two views). Note
15129 -- that these additional operations must all be new operations
15130 -- (any earlier operations that override inherited operations
15131 -- of the full view will already have been inserted in the
15132 -- primitives list, marked by Check_Operation_From_Private_View
15133 -- as dispatching. Note that implicit "/=" operators are
15134 -- excluded from being added to the primitives list since they
15135 -- shouldn't be treated as dispatching (tagged "/=" is handled
15138 Prim := Next_Entity (Full_T);
15139 while Present (Prim) and then Prim /= Priv_T loop
15140 if Ekind (Prim) = E_Procedure
15142 Ekind (Prim) = E_Function
15145 D_Type := Find_Dispatching_Type (Prim);
15148 and then (Chars (Prim) /= Name_Op_Ne
15149 or else Comes_From_Source (Prim))
15151 Check_Controlling_Formals (Full_T, Prim);
15153 if not Is_Dispatching_Operation (Prim) then
15154 Append_Elmt (Prim, Full_List);
15155 Set_Is_Dispatching_Operation (Prim, True);
15156 Set_DT_Position (Prim, No_Uint);
15159 elsif Is_Dispatching_Operation (Prim)
15160 and then D_Type /= Full_T
15163 -- Verify that it is not otherwise controlled by a
15164 -- formal or a return value of type T.
15166 Check_Controlling_Formals (D_Type, Prim);
15170 Next_Entity (Prim);
15174 -- For the tagged case, the two views can share the same
15175 -- Primitive Operation list and the same class wide type.
15176 -- Update attributes of the class-wide type which depend on
15177 -- the full declaration.
15179 if Is_Tagged_Type (Priv_T) then
15180 Set_Primitive_Operations (Priv_T, Full_List);
15181 Set_Class_Wide_Type
15182 (Base_Type (Full_T), Class_Wide_Type (Priv_T));
15184 Set_Has_Task (Class_Wide_Type (Priv_T), Has_Task (Full_T));
15189 -- Ada 2005 AI 161: Check preelaboratable initialization consistency
15191 if Known_To_Have_Preelab_Init (Priv_T) then
15193 -- Case where there is a pragma Preelaborable_Initialization. We
15194 -- always allow this in predefined units, which is a bit of a kludge,
15195 -- but it means we don't have to struggle to meet the requirements in
15196 -- the RM for having Preelaborable Initialization. Otherwise we
15197 -- require that the type meets the RM rules. But we can't check that
15198 -- yet, because of the rule about overriding Ininitialize, so we
15199 -- simply set a flag that will be checked at freeze time.
15201 if not In_Predefined_Unit (Full_T) then
15202 Set_Must_Have_Preelab_Init (Full_T);
15206 -- If pragma CPP_Class was applied to the private type declaration,
15207 -- propagate it now to the full type declaration.
15209 if Is_CPP_Class (Priv_T) then
15210 Set_Is_CPP_Class (Full_T);
15211 Set_Convention (Full_T, Convention_CPP);
15213 end Process_Full_View;
15215 -----------------------------------
15216 -- Process_Incomplete_Dependents --
15217 -----------------------------------
15219 procedure Process_Incomplete_Dependents
15221 Full_T : Entity_Id;
15224 Inc_Elmt : Elmt_Id;
15225 Priv_Dep : Entity_Id;
15226 New_Subt : Entity_Id;
15228 Disc_Constraint : Elist_Id;
15231 if No (Private_Dependents (Inc_T)) then
15235 -- Itypes that may be generated by the completion of an incomplete
15236 -- subtype are not used by the back-end and not attached to the tree.
15237 -- They are created only for constraint-checking purposes.
15239 Inc_Elmt := First_Elmt (Private_Dependents (Inc_T));
15240 while Present (Inc_Elmt) loop
15241 Priv_Dep := Node (Inc_Elmt);
15243 if Ekind (Priv_Dep) = E_Subprogram_Type then
15245 -- An Access_To_Subprogram type may have a return type or a
15246 -- parameter type that is incomplete. Replace with the full view.
15248 if Etype (Priv_Dep) = Inc_T then
15249 Set_Etype (Priv_Dep, Full_T);
15253 Formal : Entity_Id;
15256 Formal := First_Formal (Priv_Dep);
15257 while Present (Formal) loop
15258 if Etype (Formal) = Inc_T then
15259 Set_Etype (Formal, Full_T);
15262 Next_Formal (Formal);
15266 elsif Is_Overloadable (Priv_Dep) then
15268 -- A protected operation is never dispatching: only its
15269 -- wrapper operation (which has convention Ada) is.
15271 if Is_Tagged_Type (Full_T)
15272 and then Convention (Priv_Dep) /= Convention_Protected
15275 -- Subprogram has an access parameter whose designated type
15276 -- was incomplete. Reexamine declaration now, because it may
15277 -- be a primitive operation of the full type.
15279 Check_Operation_From_Incomplete_Type (Priv_Dep, Inc_T);
15280 Set_Is_Dispatching_Operation (Priv_Dep);
15281 Check_Controlling_Formals (Full_T, Priv_Dep);
15284 elsif Ekind (Priv_Dep) = E_Subprogram_Body then
15286 -- Can happen during processing of a body before the completion
15287 -- of a TA type. Ignore, because spec is also on dependent list.
15291 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
15292 -- corresponding subtype of the full view.
15294 elsif Ekind (Priv_Dep) = E_Incomplete_Subtype then
15295 Set_Subtype_Indication
15296 (Parent (Priv_Dep), New_Reference_To (Full_T, Sloc (Priv_Dep)));
15297 Set_Etype (Priv_Dep, Full_T);
15298 Set_Ekind (Priv_Dep, Subtype_Kind (Ekind (Full_T)));
15299 Set_Analyzed (Parent (Priv_Dep), False);
15301 -- Reanalyze the declaration, suppressing the call to
15302 -- Enter_Name to avoid duplicate names.
15304 Analyze_Subtype_Declaration
15305 (N => Parent (Priv_Dep),
15308 -- Dependent is a subtype
15311 -- We build a new subtype indication using the full view of the
15312 -- incomplete parent. The discriminant constraints have been
15313 -- elaborated already at the point of the subtype declaration.
15315 New_Subt := Create_Itype (E_Void, N);
15317 if Has_Discriminants (Full_T) then
15318 Disc_Constraint := Discriminant_Constraint (Priv_Dep);
15320 Disc_Constraint := No_Elist;
15323 Build_Discriminated_Subtype (Full_T, New_Subt, Disc_Constraint, N);
15324 Set_Full_View (Priv_Dep, New_Subt);
15327 Next_Elmt (Inc_Elmt);
15329 end Process_Incomplete_Dependents;
15331 --------------------------------
15332 -- Process_Range_Expr_In_Decl --
15333 --------------------------------
15335 procedure Process_Range_Expr_In_Decl
15338 Check_List : List_Id := Empty_List;
15339 R_Check_Off : Boolean := False)
15342 R_Checks : Check_Result;
15343 Type_Decl : Node_Id;
15344 Def_Id : Entity_Id;
15347 Analyze_And_Resolve (R, Base_Type (T));
15349 if Nkind (R) = N_Range then
15350 Lo := Low_Bound (R);
15351 Hi := High_Bound (R);
15353 -- We need to ensure validity of the bounds here, because if we
15354 -- go ahead and do the expansion, then the expanded code will get
15355 -- analyzed with range checks suppressed and we miss the check.
15357 Validity_Check_Range (R);
15359 -- If there were errors in the declaration, try and patch up some
15360 -- common mistakes in the bounds. The cases handled are literals
15361 -- which are Integer where the expected type is Real and vice versa.
15362 -- These corrections allow the compilation process to proceed further
15363 -- along since some basic assumptions of the format of the bounds
15366 if Etype (R) = Any_Type then
15368 if Nkind (Lo) = N_Integer_Literal and then Is_Real_Type (T) then
15370 Make_Real_Literal (Sloc (Lo), UR_From_Uint (Intval (Lo))));
15372 elsif Nkind (Hi) = N_Integer_Literal and then Is_Real_Type (T) then
15374 Make_Real_Literal (Sloc (Hi), UR_From_Uint (Intval (Hi))));
15376 elsif Nkind (Lo) = N_Real_Literal and then Is_Integer_Type (T) then
15378 Make_Integer_Literal (Sloc (Lo), UR_To_Uint (Realval (Lo))));
15380 elsif Nkind (Hi) = N_Real_Literal and then Is_Integer_Type (T) then
15382 Make_Integer_Literal (Sloc (Hi), UR_To_Uint (Realval (Hi))));
15389 -- If the bounds of the range have been mistakenly given as string
15390 -- literals (perhaps in place of character literals), then an error
15391 -- has already been reported, but we rewrite the string literal as a
15392 -- bound of the range's type to avoid blowups in later processing
15393 -- that looks at static values.
15395 if Nkind (Lo) = N_String_Literal then
15397 Make_Attribute_Reference (Sloc (Lo),
15398 Attribute_Name => Name_First,
15399 Prefix => New_Reference_To (T, Sloc (Lo))));
15400 Analyze_And_Resolve (Lo);
15403 if Nkind (Hi) = N_String_Literal then
15405 Make_Attribute_Reference (Sloc (Hi),
15406 Attribute_Name => Name_First,
15407 Prefix => New_Reference_To (T, Sloc (Hi))));
15408 Analyze_And_Resolve (Hi);
15411 -- If bounds aren't scalar at this point then exit, avoiding
15412 -- problems with further processing of the range in this procedure.
15414 if not Is_Scalar_Type (Etype (Lo)) then
15418 -- Resolve (actually Sem_Eval) has checked that the bounds are in
15419 -- then range of the base type. Here we check whether the bounds
15420 -- are in the range of the subtype itself. Note that if the bounds
15421 -- represent the null range the Constraint_Error exception should
15424 -- ??? The following code should be cleaned up as follows
15426 -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
15427 -- is done in the call to Range_Check (R, T); below
15429 -- 2. The use of R_Check_Off should be investigated and possibly
15430 -- removed, this would clean up things a bit.
15432 if Is_Null_Range (Lo, Hi) then
15436 -- Capture values of bounds and generate temporaries for them
15437 -- if needed, before applying checks, since checks may cause
15438 -- duplication of the expression without forcing evaluation.
15440 if Expander_Active then
15441 Force_Evaluation (Lo);
15442 Force_Evaluation (Hi);
15445 -- We use a flag here instead of suppressing checks on the
15446 -- type because the type we check against isn't necessarily
15447 -- the place where we put the check.
15449 if not R_Check_Off then
15450 R_Checks := Get_Range_Checks (R, T);
15452 -- Look up tree to find an appropriate insertion point.
15453 -- This seems really junk code, and very brittle, couldn't
15454 -- we just use an insert actions call of some kind ???
15456 Type_Decl := Parent (R);
15457 while Present (Type_Decl) and then not
15458 (Nkind (Type_Decl) = N_Full_Type_Declaration
15460 Nkind (Type_Decl) = N_Subtype_Declaration
15462 Nkind (Type_Decl) = N_Loop_Statement
15464 Nkind (Type_Decl) = N_Task_Type_Declaration
15466 Nkind (Type_Decl) = N_Single_Task_Declaration
15468 Nkind (Type_Decl) = N_Protected_Type_Declaration
15470 Nkind (Type_Decl) = N_Single_Protected_Declaration)
15472 Type_Decl := Parent (Type_Decl);
15475 -- Why would Type_Decl not be present??? Without this test,
15476 -- short regression tests fail.
15478 if Present (Type_Decl) then
15480 -- Case of loop statement (more comments ???)
15482 if Nkind (Type_Decl) = N_Loop_Statement then
15487 Indic := Parent (R);
15488 while Present (Indic) and then not
15489 (Nkind (Indic) = N_Subtype_Indication)
15491 Indic := Parent (Indic);
15494 if Present (Indic) then
15495 Def_Id := Etype (Subtype_Mark (Indic));
15497 Insert_Range_Checks
15503 Do_Before => True);
15507 -- All other cases (more comments ???)
15510 Def_Id := Defining_Identifier (Type_Decl);
15512 if (Ekind (Def_Id) = E_Record_Type
15513 and then Depends_On_Discriminant (R))
15515 (Ekind (Def_Id) = E_Protected_Type
15516 and then Has_Discriminants (Def_Id))
15518 Append_Range_Checks
15519 (R_Checks, Check_List, Def_Id, Sloc (Type_Decl), R);
15522 Insert_Range_Checks
15523 (R_Checks, Type_Decl, Def_Id, Sloc (Type_Decl), R);
15531 elsif Expander_Active then
15532 Get_Index_Bounds (R, Lo, Hi);
15533 Force_Evaluation (Lo);
15534 Force_Evaluation (Hi);
15536 end Process_Range_Expr_In_Decl;
15538 --------------------------------------
15539 -- Process_Real_Range_Specification --
15540 --------------------------------------
15542 procedure Process_Real_Range_Specification (Def : Node_Id) is
15543 Spec : constant Node_Id := Real_Range_Specification (Def);
15546 Err : Boolean := False;
15548 procedure Analyze_Bound (N : Node_Id);
15549 -- Analyze and check one bound
15551 -------------------
15552 -- Analyze_Bound --
15553 -------------------
15555 procedure Analyze_Bound (N : Node_Id) is
15557 Analyze_And_Resolve (N, Any_Real);
15559 if not Is_OK_Static_Expression (N) then
15560 Flag_Non_Static_Expr
15561 ("bound in real type definition is not static!", N);
15566 -- Start of processing for Process_Real_Range_Specification
15569 if Present (Spec) then
15570 Lo := Low_Bound (Spec);
15571 Hi := High_Bound (Spec);
15572 Analyze_Bound (Lo);
15573 Analyze_Bound (Hi);
15575 -- If error, clear away junk range specification
15578 Set_Real_Range_Specification (Def, Empty);
15581 end Process_Real_Range_Specification;
15583 ---------------------
15584 -- Process_Subtype --
15585 ---------------------
15587 function Process_Subtype
15589 Related_Nod : Node_Id;
15590 Related_Id : Entity_Id := Empty;
15591 Suffix : Character := ' ') return Entity_Id
15594 Def_Id : Entity_Id;
15595 Error_Node : Node_Id;
15596 Full_View_Id : Entity_Id;
15597 Subtype_Mark_Id : Entity_Id;
15599 May_Have_Null_Exclusion : Boolean;
15601 procedure Check_Incomplete (T : Entity_Id);
15602 -- Called to verify that an incomplete type is not used prematurely
15604 ----------------------
15605 -- Check_Incomplete --
15606 ----------------------
15608 procedure Check_Incomplete (T : Entity_Id) is
15610 -- Ada 2005 (AI-412): Incomplete subtypes are legal
15612 if Ekind (Root_Type (Entity (T))) = E_Incomplete_Type
15614 not (Ada_Version >= Ada_05
15616 (Nkind (Parent (T)) = N_Subtype_Declaration
15618 (Nkind (Parent (T)) = N_Subtype_Indication
15619 and then Nkind (Parent (Parent (T))) =
15620 N_Subtype_Declaration)))
15622 Error_Msg_N ("invalid use of type before its full declaration", T);
15624 end Check_Incomplete;
15626 -- Start of processing for Process_Subtype
15629 -- Case of no constraints present
15631 if Nkind (S) /= N_Subtype_Indication then
15634 Check_Incomplete (S);
15637 -- Ada 2005 (AI-231): Static check
15639 if Ada_Version >= Ada_05
15640 and then Present (P)
15641 and then Null_Exclusion_Present (P)
15642 and then Nkind (P) /= N_Access_To_Object_Definition
15643 and then not Is_Access_Type (Entity (S))
15645 Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
15648 May_Have_Null_Exclusion :=
15649 Nkind (P) = N_Access_Definition
15650 or else Nkind (P) = N_Access_Function_Definition
15651 or else Nkind (P) = N_Access_Procedure_Definition
15652 or else Nkind (P) = N_Access_To_Object_Definition
15653 or else Nkind (P) = N_Allocator
15654 or else Nkind (P) = N_Component_Definition
15655 or else Nkind (P) = N_Derived_Type_Definition
15656 or else Nkind (P) = N_Discriminant_Specification
15657 or else Nkind (P) = N_Object_Declaration
15658 or else Nkind (P) = N_Parameter_Specification
15659 or else Nkind (P) = N_Subtype_Declaration;
15661 -- Create an Itype that is a duplicate of Entity (S) but with the
15662 -- null-exclusion attribute
15664 if May_Have_Null_Exclusion
15665 and then Is_Access_Type (Entity (S))
15666 and then Null_Exclusion_Present (P)
15668 -- No need to check the case of an access to object definition.
15669 -- It is correct to define double not-null pointers.
15672 -- type Not_Null_Int_Ptr is not null access Integer;
15673 -- type Acc is not null access Not_Null_Int_Ptr;
15675 and then Nkind (P) /= N_Access_To_Object_Definition
15677 if Can_Never_Be_Null (Entity (S)) then
15678 case Nkind (Related_Nod) is
15679 when N_Full_Type_Declaration =>
15680 if Nkind (Type_Definition (Related_Nod))
15681 in N_Array_Type_Definition
15685 (Component_Definition
15686 (Type_Definition (Related_Nod)));
15689 Subtype_Indication (Type_Definition (Related_Nod));
15692 when N_Subtype_Declaration =>
15693 Error_Node := Subtype_Indication (Related_Nod);
15695 when N_Object_Declaration =>
15696 Error_Node := Object_Definition (Related_Nod);
15698 when N_Component_Declaration =>
15700 Subtype_Indication (Component_Definition (Related_Nod));
15703 pragma Assert (False);
15704 Error_Node := Related_Nod;
15708 ("`NOT NULL` not allowed (& already excludes null)",
15714 Create_Null_Excluding_Itype
15716 Related_Nod => P));
15717 Set_Entity (S, Etype (S));
15722 -- Case of constraint present, so that we have an N_Subtype_Indication
15723 -- node (this node is created only if constraints are present).
15726 Find_Type (Subtype_Mark (S));
15728 if Nkind (Parent (S)) /= N_Access_To_Object_Definition
15730 (Nkind (Parent (S)) = N_Subtype_Declaration
15731 and then Is_Itype (Defining_Identifier (Parent (S))))
15733 Check_Incomplete (Subtype_Mark (S));
15737 Subtype_Mark_Id := Entity (Subtype_Mark (S));
15739 -- Explicit subtype declaration case
15741 if Nkind (P) = N_Subtype_Declaration then
15742 Def_Id := Defining_Identifier (P);
15744 -- Explicit derived type definition case
15746 elsif Nkind (P) = N_Derived_Type_Definition then
15747 Def_Id := Defining_Identifier (Parent (P));
15749 -- Implicit case, the Def_Id must be created as an implicit type.
15750 -- The one exception arises in the case of concurrent types, array
15751 -- and access types, where other subsidiary implicit types may be
15752 -- created and must appear before the main implicit type. In these
15753 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
15754 -- has not yet been called to create Def_Id.
15757 if Is_Array_Type (Subtype_Mark_Id)
15758 or else Is_Concurrent_Type (Subtype_Mark_Id)
15759 or else Is_Access_Type (Subtype_Mark_Id)
15763 -- For the other cases, we create a new unattached Itype,
15764 -- and set the indication to ensure it gets attached later.
15768 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
15772 -- If the kind of constraint is invalid for this kind of type,
15773 -- then give an error, and then pretend no constraint was given.
15775 if not Is_Valid_Constraint_Kind
15776 (Ekind (Subtype_Mark_Id), Nkind (Constraint (S)))
15779 ("incorrect constraint for this kind of type", Constraint (S));
15781 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
15783 -- Set Ekind of orphan itype, to prevent cascaded errors
15785 if Present (Def_Id) then
15786 Set_Ekind (Def_Id, Ekind (Any_Type));
15789 -- Make recursive call, having got rid of the bogus constraint
15791 return Process_Subtype (S, Related_Nod, Related_Id, Suffix);
15794 -- Remaining processing depends on type
15796 case Ekind (Subtype_Mark_Id) is
15797 when Access_Kind =>
15798 Constrain_Access (Def_Id, S, Related_Nod);
15801 and then Is_Itype (Designated_Type (Def_Id))
15802 and then Nkind (Related_Nod) = N_Subtype_Declaration
15803 and then not Is_Incomplete_Type (Designated_Type (Def_Id))
15805 Build_Itype_Reference
15806 (Designated_Type (Def_Id), Related_Nod);
15810 Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix);
15812 when Decimal_Fixed_Point_Kind =>
15813 Constrain_Decimal (Def_Id, S);
15815 when Enumeration_Kind =>
15816 Constrain_Enumeration (Def_Id, S);
15818 when Ordinary_Fixed_Point_Kind =>
15819 Constrain_Ordinary_Fixed (Def_Id, S);
15822 Constrain_Float (Def_Id, S);
15824 when Integer_Kind =>
15825 Constrain_Integer (Def_Id, S);
15827 when E_Record_Type |
15830 E_Incomplete_Type =>
15831 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
15833 when Private_Kind =>
15834 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
15835 Set_Private_Dependents (Def_Id, New_Elmt_List);
15837 -- In case of an invalid constraint prevent further processing
15838 -- since the type constructed is missing expected fields.
15840 if Etype (Def_Id) = Any_Type then
15844 -- If the full view is that of a task with discriminants,
15845 -- we must constrain both the concurrent type and its
15846 -- corresponding record type. Otherwise we will just propagate
15847 -- the constraint to the full view, if available.
15849 if Present (Full_View (Subtype_Mark_Id))
15850 and then Has_Discriminants (Subtype_Mark_Id)
15851 and then Is_Concurrent_Type (Full_View (Subtype_Mark_Id))
15854 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
15856 Set_Entity (Subtype_Mark (S), Full_View (Subtype_Mark_Id));
15857 Constrain_Concurrent (Full_View_Id, S,
15858 Related_Nod, Related_Id, Suffix);
15859 Set_Entity (Subtype_Mark (S), Subtype_Mark_Id);
15860 Set_Full_View (Def_Id, Full_View_Id);
15862 -- Introduce an explicit reference to the private subtype,
15863 -- to prevent scope anomalies in gigi if first use appears
15864 -- in a nested context, e.g. a later function body.
15865 -- Should this be generated in other contexts than a full
15866 -- type declaration?
15868 if Is_Itype (Def_Id)
15870 Nkind (Parent (P)) = N_Full_Type_Declaration
15872 Build_Itype_Reference (Def_Id, Parent (P));
15876 Prepare_Private_Subtype_Completion (Def_Id, Related_Nod);
15879 when Concurrent_Kind =>
15880 Constrain_Concurrent (Def_Id, S,
15881 Related_Nod, Related_Id, Suffix);
15884 Error_Msg_N ("invalid subtype mark in subtype indication", S);
15887 -- Size and Convention are always inherited from the base type
15889 Set_Size_Info (Def_Id, (Subtype_Mark_Id));
15890 Set_Convention (Def_Id, Convention (Subtype_Mark_Id));
15894 end Process_Subtype;
15896 ---------------------------------------
15897 -- Check_Anonymous_Access_Components --
15898 ---------------------------------------
15900 procedure Check_Anonymous_Access_Components
15901 (Typ_Decl : Node_Id;
15904 Comp_List : Node_Id)
15906 Loc : constant Source_Ptr := Sloc (Typ_Decl);
15907 Anon_Access : Entity_Id;
15910 Comp_Def : Node_Id;
15912 Type_Def : Node_Id;
15914 procedure Build_Incomplete_Type_Declaration;
15915 -- If the record type contains components that include an access to the
15916 -- current record, then create an incomplete type declaration for the
15917 -- record, to be used as the designated type of the anonymous access.
15918 -- This is done only once, and only if there is no previous partial
15919 -- view of the type.
15921 function Mentions_T (Acc_Def : Node_Id) return Boolean;
15922 -- Check whether an access definition includes a reference to
15923 -- the enclosing record type. The reference can be a subtype
15924 -- mark in the access definition itself, or a 'Class attribute
15925 -- reference, or recursively a reference appearing in a parameter
15926 -- type in an access_to_subprogram definition.
15928 --------------------------------------
15929 -- Build_Incomplete_Type_Declaration --
15930 --------------------------------------
15932 procedure Build_Incomplete_Type_Declaration is
15938 -- If there is a previous partial view, no need to create a new one
15939 -- If the partial view, given by Prev, is incomplete, If Prev is
15940 -- a private declaration, full declaration is flagged accordingly.
15942 if Prev /= Typ then
15943 if Tagged_Present (Type_Definition (Typ_Decl)) then
15944 Make_Class_Wide_Type (Prev);
15945 Set_Class_Wide_Type (Typ, Class_Wide_Type (Prev));
15946 Set_Etype (Class_Wide_Type (Typ), Typ);
15951 elsif Has_Private_Declaration (Typ) then
15954 -- If there was a previous anonymous access type, the incomplete
15955 -- type declaration will have been created already.
15957 elsif Present (Current_Entity (Typ))
15958 and then Ekind (Current_Entity (Typ)) = E_Incomplete_Type
15959 and then Full_View (Current_Entity (Typ)) = Typ
15964 Inc_T := Make_Defining_Identifier (Loc, Chars (Typ));
15965 Decl := Make_Incomplete_Type_Declaration (Loc, Inc_T);
15967 -- Type has already been inserted into the current scope.
15968 -- Remove it, and add incomplete declaration for type, so
15969 -- that subsequent anonymous access types can use it.
15970 -- The entity is unchained from the homonym list and from
15971 -- immediate visibility. After analysis, the entity in the
15972 -- incomplete declaration becomes immediately visible in the
15973 -- record declaration that follows.
15975 H := Current_Entity (Typ);
15978 Set_Name_Entity_Id (Chars (Typ), Homonym (Typ));
15981 and then Homonym (H) /= Typ
15983 H := Homonym (Typ);
15986 Set_Homonym (H, Homonym (Typ));
15989 Insert_Before (Typ_Decl, Decl);
15991 Set_Full_View (Inc_T, Typ);
15993 if (Nkind (Type_Definition (Typ_Decl)) = N_Derived_Type_Definition
15996 (Record_Extension_Part (Type_Definition (Typ_Decl))))
15997 or else Tagged_Present (Type_Definition (Typ_Decl))
15999 -- Create a common class-wide type for both views, and set
16000 -- the etype of the class-wide type to the full view.
16002 Make_Class_Wide_Type (Inc_T);
16003 Set_Class_Wide_Type (Typ, Class_Wide_Type (Inc_T));
16004 Set_Etype (Class_Wide_Type (Typ), Typ);
16007 end Build_Incomplete_Type_Declaration;
16013 function Mentions_T (Acc_Def : Node_Id) return Boolean is
16015 Type_Id : constant Name_Id := Chars (Typ);
16017 function Names_T (Nam : Node_Id) return Boolean;
16018 -- The record type has not been introduced in the current scope
16019 -- yet, so we must examine the name of the type itself, either
16020 -- an identifier T, or an expanded name of the form P.T, where
16021 -- P denotes the current scope.
16027 function Names_T (Nam : Node_Id) return Boolean is
16029 if Nkind (Nam) = N_Identifier then
16030 return Chars (Nam) = Type_Id;
16032 elsif Nkind (Nam) = N_Selected_Component then
16033 if Chars (Selector_Name (Nam)) = Type_Id then
16034 if Nkind (Prefix (Nam)) = N_Identifier then
16035 return Chars (Prefix (Nam)) = Chars (Current_Scope);
16037 elsif Nkind (Prefix (Nam)) = N_Selected_Component then
16038 return Chars (Selector_Name (Prefix (Nam))) =
16039 Chars (Current_Scope);
16051 -- Start of processing for Mentions_T
16054 if No (Access_To_Subprogram_Definition (Acc_Def)) then
16055 Subt := Subtype_Mark (Acc_Def);
16057 if Nkind (Subt) = N_Identifier then
16058 return Chars (Subt) = Type_Id;
16060 -- Reference can be through an expanded name which has not been
16061 -- analyzed yet, and which designates enclosing scopes.
16063 elsif Nkind (Subt) = N_Selected_Component then
16064 if Names_T (Subt) then
16067 -- Otherwise it must denote an entity that is already visible.
16068 -- The access definition may name a subtype of the enclosing
16069 -- type, if there is a previous incomplete declaration for it.
16072 Find_Selected_Component (Subt);
16074 Is_Entity_Name (Subt)
16075 and then Scope (Entity (Subt)) = Current_Scope
16076 and then (Chars (Base_Type (Entity (Subt))) = Type_Id
16078 (Is_Class_Wide_Type (Entity (Subt))
16080 Chars (Etype (Base_Type (Entity (Subt))))
16084 -- A reference to the current type may appear as the prefix of
16085 -- a 'Class attribute.
16087 elsif Nkind (Subt) = N_Attribute_Reference
16088 and then Attribute_Name (Subt) = Name_Class
16090 return Names_T (Prefix (Subt));
16096 -- Component is an access_to_subprogram: examine its formals
16099 Param_Spec : Node_Id;
16104 (Parameter_Specifications
16105 (Access_To_Subprogram_Definition (Acc_Def)));
16106 while Present (Param_Spec) loop
16107 if Nkind (Parameter_Type (Param_Spec))
16108 = N_Access_Definition
16109 and then Mentions_T (Parameter_Type (Param_Spec))
16122 -- Start of processing for Check_Anonymous_Access_Components
16125 if No (Comp_List) then
16129 Comp := First (Component_Items (Comp_List));
16130 while Present (Comp) loop
16131 if Nkind (Comp) = N_Component_Declaration
16133 (Access_Definition (Component_Definition (Comp)))
16135 Mentions_T (Access_Definition (Component_Definition (Comp)))
16137 Comp_Def := Component_Definition (Comp);
16139 Access_To_Subprogram_Definition
16140 (Access_Definition (Comp_Def));
16142 Build_Incomplete_Type_Declaration;
16144 Make_Defining_Identifier (Loc,
16145 Chars => New_Internal_Name ('S'));
16147 -- Create a declaration for the anonymous access type: either
16148 -- an access_to_object or an access_to_subprogram.
16150 if Present (Acc_Def) then
16151 if Nkind (Acc_Def) = N_Access_Function_Definition then
16153 Make_Access_Function_Definition (Loc,
16154 Parameter_Specifications =>
16155 Parameter_Specifications (Acc_Def),
16156 Result_Definition => Result_Definition (Acc_Def));
16159 Make_Access_Procedure_Definition (Loc,
16160 Parameter_Specifications =>
16161 Parameter_Specifications (Acc_Def));
16166 Make_Access_To_Object_Definition (Loc,
16167 Subtype_Indication =>
16170 (Access_Definition (Comp_Def))));
16172 Set_Constant_Present
16173 (Type_Def, Constant_Present (Access_Definition (Comp_Def)));
16175 (Type_Def, All_Present (Access_Definition (Comp_Def)));
16178 Set_Null_Exclusion_Present
16180 Null_Exclusion_Present (Access_Definition (Comp_Def)));
16183 Make_Full_Type_Declaration (Loc,
16184 Defining_Identifier => Anon_Access,
16185 Type_Definition => Type_Def);
16187 Insert_Before (Typ_Decl, Decl);
16190 -- If an access to object, Preserve entity of designated type,
16191 -- for ASIS use, before rewriting the component definition.
16193 if No (Acc_Def) then
16198 Desig := Entity (Subtype_Indication (Type_Def));
16200 -- If the access definition is to the current record,
16201 -- the visible entity at this point is an incomplete
16202 -- type. Retrieve the full view to simplify ASIS queries
16204 if Ekind (Desig) = E_Incomplete_Type then
16205 Desig := Full_View (Desig);
16209 (Subtype_Mark (Access_Definition (Comp_Def)), Desig);
16214 Make_Component_Definition (Loc,
16215 Subtype_Indication =>
16216 New_Occurrence_Of (Anon_Access, Loc)));
16217 Set_Ekind (Anon_Access, E_Anonymous_Access_Type);
16218 Set_Is_Local_Anonymous_Access (Anon_Access);
16224 if Present (Variant_Part (Comp_List)) then
16228 V := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
16229 while Present (V) loop
16230 Check_Anonymous_Access_Components
16231 (Typ_Decl, Typ, Prev, Component_List (V));
16232 Next_Non_Pragma (V);
16236 end Check_Anonymous_Access_Components;
16238 -----------------------------
16239 -- Record_Type_Declaration --
16240 -----------------------------
16242 procedure Record_Type_Declaration
16247 Def : constant Node_Id := Type_Definition (N);
16248 Is_Tagged : Boolean;
16249 Tag_Comp : Entity_Id;
16252 -- These flags must be initialized before calling Process_Discriminants
16253 -- because this routine makes use of them.
16255 Set_Ekind (T, E_Record_Type);
16257 Init_Size_Align (T);
16258 Set_Abstract_Interfaces (T, No_Elist);
16259 Set_Stored_Constraint (T, No_Elist);
16263 if Ada_Version < Ada_05
16264 or else not Interface_Present (Def)
16266 -- The flag Is_Tagged_Type might have already been set by
16267 -- Find_Type_Name if it detected an error for declaration T. This
16268 -- arises in the case of private tagged types where the full view
16269 -- omits the word tagged.
16272 Tagged_Present (Def)
16273 or else (Serious_Errors_Detected > 0 and then Is_Tagged_Type (T));
16275 Set_Is_Tagged_Type (T, Is_Tagged);
16276 Set_Is_Limited_Record (T, Limited_Present (Def));
16278 -- Type is abstract if full declaration carries keyword, or if
16279 -- previous partial view did.
16281 Set_Is_Abstract_Type (T, Is_Abstract_Type (T)
16282 or else Abstract_Present (Def));
16286 Analyze_Interface_Declaration (T, Def);
16288 if Present (Discriminant_Specifications (N)) then
16290 ("interface types cannot have discriminants",
16291 Defining_Identifier
16292 (First (Discriminant_Specifications (N))));
16296 -- First pass: if there are self-referential access components,
16297 -- create the required anonymous access type declarations, and if
16298 -- need be an incomplete type declaration for T itself.
16300 Check_Anonymous_Access_Components (N, T, Prev, Component_List (Def));
16302 if Ada_Version >= Ada_05
16303 and then Present (Interface_List (Def))
16305 Check_Abstract_Interfaces (N, Def);
16308 Ifaces_List : Elist_Id;
16311 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
16312 -- already in the parents.
16314 Collect_Abstract_Interfaces
16316 Ifaces_List => Ifaces_List,
16317 Exclude_Parent_Interfaces => True);
16319 Set_Abstract_Interfaces (T, Ifaces_List);
16323 -- Records constitute a scope for the component declarations within.
16324 -- The scope is created prior to the processing of these declarations.
16325 -- Discriminants are processed first, so that they are visible when
16326 -- processing the other components. The Ekind of the record type itself
16327 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
16329 -- Enter record scope
16333 -- If an incomplete or private type declaration was already given for
16334 -- the type, then this scope already exists, and the discriminants have
16335 -- been declared within. We must verify that the full declaration
16336 -- matches the incomplete one.
16338 Check_Or_Process_Discriminants (N, T, Prev);
16340 Set_Is_Constrained (T, not Has_Discriminants (T));
16341 Set_Has_Delayed_Freeze (T, True);
16343 -- For tagged types add a manually analyzed component corresponding
16344 -- to the component _tag, the corresponding piece of tree will be
16345 -- expanded as part of the freezing actions if it is not a CPP_Class.
16349 -- Do not add the tag unless we are in expansion mode
16351 if Expander_Active then
16352 Tag_Comp := Make_Defining_Identifier (Sloc (Def), Name_uTag);
16353 Enter_Name (Tag_Comp);
16355 Set_Is_Tag (Tag_Comp);
16356 Set_Is_Aliased (Tag_Comp);
16357 Set_Ekind (Tag_Comp, E_Component);
16358 Set_Etype (Tag_Comp, RTE (RE_Tag));
16359 Set_DT_Entry_Count (Tag_Comp, No_Uint);
16360 Set_Original_Record_Component (Tag_Comp, Tag_Comp);
16361 Init_Component_Location (Tag_Comp);
16363 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
16364 -- implemented interfaces.
16366 if Has_Abstract_Interfaces (T) then
16367 Add_Interface_Tag_Components (N, T);
16371 Make_Class_Wide_Type (T);
16372 Set_Primitive_Operations (T, New_Elmt_List);
16375 -- We must suppress range checks when processing the components
16376 -- of a record in the presence of discriminants, since we don't
16377 -- want spurious checks to be generated during their analysis, but
16378 -- must reset the Suppress_Range_Checks flags after having processed
16379 -- the record definition.
16381 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
16382 -- couldn't we just use the normal range check suppression method here.
16383 -- That would seem cleaner ???
16385 if Has_Discriminants (T) and then not Range_Checks_Suppressed (T) then
16386 Set_Kill_Range_Checks (T, True);
16387 Record_Type_Definition (Def, Prev);
16388 Set_Kill_Range_Checks (T, False);
16390 Record_Type_Definition (Def, Prev);
16393 -- Exit from record scope
16397 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
16398 -- the implemented interfaces and associate them an aliased entity.
16401 and then not Is_Empty_List (Interface_List (Def))
16404 Ifaces_List : constant Elist_Id := New_Elmt_List;
16406 Derive_Interface_Subprograms (T, T, Ifaces_List);
16409 end Record_Type_Declaration;
16411 ----------------------------
16412 -- Record_Type_Definition --
16413 ----------------------------
16415 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id) is
16416 Component : Entity_Id;
16417 Ctrl_Components : Boolean := False;
16418 Final_Storage_Only : Boolean;
16422 if Ekind (Prev_T) = E_Incomplete_Type then
16423 T := Full_View (Prev_T);
16428 Final_Storage_Only := not Is_Controlled (T);
16430 -- Ada 2005: check whether an explicit Limited is present in a derived
16431 -- type declaration.
16433 if Nkind (Parent (Def)) = N_Derived_Type_Definition
16434 and then Limited_Present (Parent (Def))
16436 Set_Is_Limited_Record (T);
16439 -- If the component list of a record type is defined by the reserved
16440 -- word null and there is no discriminant part, then the record type has
16441 -- no components and all records of the type are null records (RM 3.7)
16442 -- This procedure is also called to process the extension part of a
16443 -- record extension, in which case the current scope may have inherited
16447 or else No (Component_List (Def))
16448 or else Null_Present (Component_List (Def))
16453 Analyze_Declarations (Component_Items (Component_List (Def)));
16455 if Present (Variant_Part (Component_List (Def))) then
16456 Analyze (Variant_Part (Component_List (Def)));
16460 -- After completing the semantic analysis of the record definition,
16461 -- record components, both new and inherited, are accessible. Set their
16462 -- kind accordingly. Exclude malformed itypes from illegal declarations,
16463 -- whose Ekind may be void.
16465 Component := First_Entity (Current_Scope);
16466 while Present (Component) loop
16467 if Ekind (Component) = E_Void
16468 and then not Is_Itype (Component)
16470 Set_Ekind (Component, E_Component);
16471 Init_Component_Location (Component);
16474 if Has_Task (Etype (Component)) then
16478 if Ekind (Component) /= E_Component then
16481 elsif Has_Controlled_Component (Etype (Component))
16482 or else (Chars (Component) /= Name_uParent
16483 and then Is_Controlled (Etype (Component)))
16485 Set_Has_Controlled_Component (T, True);
16486 Final_Storage_Only := Final_Storage_Only
16487 and then Finalize_Storage_Only (Etype (Component));
16488 Ctrl_Components := True;
16491 Next_Entity (Component);
16494 -- A Type is Finalize_Storage_Only only if all its controlled components
16497 if Ctrl_Components then
16498 Set_Finalize_Storage_Only (T, Final_Storage_Only);
16501 -- Place reference to end record on the proper entity, which may
16502 -- be a partial view.
16504 if Present (Def) then
16505 Process_End_Label (Def, 'e', Prev_T);
16507 end Record_Type_Definition;
16509 ------------------------
16510 -- Replace_Components --
16511 ------------------------
16513 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id) is
16514 function Process (N : Node_Id) return Traverse_Result;
16520 function Process (N : Node_Id) return Traverse_Result is
16524 if Nkind (N) = N_Discriminant_Specification then
16525 Comp := First_Discriminant (Typ);
16526 while Present (Comp) loop
16527 if Chars (Comp) = Chars (Defining_Identifier (N)) then
16528 Set_Defining_Identifier (N, Comp);
16532 Next_Discriminant (Comp);
16535 elsif Nkind (N) = N_Component_Declaration then
16536 Comp := First_Component (Typ);
16537 while Present (Comp) loop
16538 if Chars (Comp) = Chars (Defining_Identifier (N)) then
16539 Set_Defining_Identifier (N, Comp);
16543 Next_Component (Comp);
16550 procedure Replace is new Traverse_Proc (Process);
16552 -- Start of processing for Replace_Components
16556 end Replace_Components;
16558 -------------------------------
16559 -- Set_Completion_Referenced --
16560 -------------------------------
16562 procedure Set_Completion_Referenced (E : Entity_Id) is
16564 -- If in main unit, mark entity that is a completion as referenced,
16565 -- warnings go on the partial view when needed.
16567 if In_Extended_Main_Source_Unit (E) then
16568 Set_Referenced (E);
16570 end Set_Completion_Referenced;
16572 ---------------------
16573 -- Set_Fixed_Range --
16574 ---------------------
16576 -- The range for fixed-point types is complicated by the fact that we
16577 -- do not know the exact end points at the time of the declaration. This
16578 -- is true for three reasons:
16580 -- A size clause may affect the fudging of the end-points
16581 -- A small clause may affect the values of the end-points
16582 -- We try to include the end-points if it does not affect the size
16584 -- This means that the actual end-points must be established at the point
16585 -- when the type is frozen. Meanwhile, we first narrow the range as
16586 -- permitted (so that it will fit if necessary in a small specified size),
16587 -- and then build a range subtree with these narrowed bounds.
16589 -- Set_Fixed_Range constructs the range from real literal values, and sets
16590 -- the range as the Scalar_Range of the given fixed-point type entity.
16592 -- The parent of this range is set to point to the entity so that it is
16593 -- properly hooked into the tree (unlike normal Scalar_Range entries for
16594 -- other scalar types, which are just pointers to the range in the
16595 -- original tree, this would otherwise be an orphan).
16597 -- The tree is left unanalyzed. When the type is frozen, the processing
16598 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
16599 -- analyzed, and uses this as an indication that it should complete
16600 -- work on the range (it will know the final small and size values).
16602 procedure Set_Fixed_Range
16608 S : constant Node_Id :=
16610 Low_Bound => Make_Real_Literal (Loc, Lo),
16611 High_Bound => Make_Real_Literal (Loc, Hi));
16613 Set_Scalar_Range (E, S);
16615 end Set_Fixed_Range;
16617 ----------------------------------
16618 -- Set_Scalar_Range_For_Subtype --
16619 ----------------------------------
16621 procedure Set_Scalar_Range_For_Subtype
16622 (Def_Id : Entity_Id;
16626 Kind : constant Entity_Kind := Ekind (Def_Id);
16629 Set_Scalar_Range (Def_Id, R);
16631 -- We need to link the range into the tree before resolving it so
16632 -- that types that are referenced, including importantly the subtype
16633 -- itself, are properly frozen (Freeze_Expression requires that the
16634 -- expression be properly linked into the tree). Of course if it is
16635 -- already linked in, then we do not disturb the current link.
16637 if No (Parent (R)) then
16638 Set_Parent (R, Def_Id);
16641 -- Reset the kind of the subtype during analysis of the range, to
16642 -- catch possible premature use in the bounds themselves.
16644 Set_Ekind (Def_Id, E_Void);
16645 Process_Range_Expr_In_Decl (R, Subt);
16646 Set_Ekind (Def_Id, Kind);
16647 end Set_Scalar_Range_For_Subtype;
16649 --------------------------------------------------------
16650 -- Set_Stored_Constraint_From_Discriminant_Constraint --
16651 --------------------------------------------------------
16653 procedure Set_Stored_Constraint_From_Discriminant_Constraint
16657 -- Make sure set if encountered during Expand_To_Stored_Constraint
16659 Set_Stored_Constraint (E, No_Elist);
16661 -- Give it the right value
16663 if Is_Constrained (E) and then Has_Discriminants (E) then
16664 Set_Stored_Constraint (E,
16665 Expand_To_Stored_Constraint (E, Discriminant_Constraint (E)));
16667 end Set_Stored_Constraint_From_Discriminant_Constraint;
16669 -------------------------------------
16670 -- Signed_Integer_Type_Declaration --
16671 -------------------------------------
16673 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id) is
16674 Implicit_Base : Entity_Id;
16675 Base_Typ : Entity_Id;
16678 Errs : Boolean := False;
16682 function Can_Derive_From (E : Entity_Id) return Boolean;
16683 -- Determine whether given bounds allow derivation from specified type
16685 procedure Check_Bound (Expr : Node_Id);
16686 -- Check bound to make sure it is integral and static. If not, post
16687 -- appropriate error message and set Errs flag
16689 ---------------------
16690 -- Can_Derive_From --
16691 ---------------------
16693 -- Note we check both bounds against both end values, to deal with
16694 -- strange types like ones with a range of 0 .. -12341234.
16696 function Can_Derive_From (E : Entity_Id) return Boolean is
16697 Lo : constant Uint := Expr_Value (Type_Low_Bound (E));
16698 Hi : constant Uint := Expr_Value (Type_High_Bound (E));
16700 return Lo <= Lo_Val and then Lo_Val <= Hi
16702 Lo <= Hi_Val and then Hi_Val <= Hi;
16703 end Can_Derive_From;
16709 procedure Check_Bound (Expr : Node_Id) is
16711 -- If a range constraint is used as an integer type definition, each
16712 -- bound of the range must be defined by a static expression of some
16713 -- integer type, but the two bounds need not have the same integer
16714 -- type (Negative bounds are allowed.) (RM 3.5.4)
16716 if not Is_Integer_Type (Etype (Expr)) then
16718 ("integer type definition bounds must be of integer type", Expr);
16721 elsif not Is_OK_Static_Expression (Expr) then
16722 Flag_Non_Static_Expr
16723 ("non-static expression used for integer type bound!", Expr);
16726 -- The bounds are folded into literals, and we set their type to be
16727 -- universal, to avoid typing difficulties: we cannot set the type
16728 -- of the literal to the new type, because this would be a forward
16729 -- reference for the back end, and if the original type is user-
16730 -- defined this can lead to spurious semantic errors (e.g. 2928-003).
16733 if Is_Entity_Name (Expr) then
16734 Fold_Uint (Expr, Expr_Value (Expr), True);
16737 Set_Etype (Expr, Universal_Integer);
16741 -- Start of processing for Signed_Integer_Type_Declaration
16744 -- Create an anonymous base type
16747 Create_Itype (E_Signed_Integer_Type, Parent (Def), T, 'B');
16749 -- Analyze and check the bounds, they can be of any integer type
16751 Lo := Low_Bound (Def);
16752 Hi := High_Bound (Def);
16754 -- Arbitrarily use Integer as the type if either bound had an error
16756 if Hi = Error or else Lo = Error then
16757 Base_Typ := Any_Integer;
16758 Set_Error_Posted (T, True);
16760 -- Here both bounds are OK expressions
16763 Analyze_And_Resolve (Lo, Any_Integer);
16764 Analyze_And_Resolve (Hi, Any_Integer);
16770 Hi := Type_High_Bound (Standard_Long_Long_Integer);
16771 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
16774 -- Find type to derive from
16776 Lo_Val := Expr_Value (Lo);
16777 Hi_Val := Expr_Value (Hi);
16779 if Can_Derive_From (Standard_Short_Short_Integer) then
16780 Base_Typ := Base_Type (Standard_Short_Short_Integer);
16782 elsif Can_Derive_From (Standard_Short_Integer) then
16783 Base_Typ := Base_Type (Standard_Short_Integer);
16785 elsif Can_Derive_From (Standard_Integer) then
16786 Base_Typ := Base_Type (Standard_Integer);
16788 elsif Can_Derive_From (Standard_Long_Integer) then
16789 Base_Typ := Base_Type (Standard_Long_Integer);
16791 elsif Can_Derive_From (Standard_Long_Long_Integer) then
16792 Base_Typ := Base_Type (Standard_Long_Long_Integer);
16795 Base_Typ := Base_Type (Standard_Long_Long_Integer);
16796 Error_Msg_N ("integer type definition bounds out of range", Def);
16797 Hi := Type_High_Bound (Standard_Long_Long_Integer);
16798 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
16802 -- Complete both implicit base and declared first subtype entities
16804 Set_Etype (Implicit_Base, Base_Typ);
16805 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
16806 Set_Size_Info (Implicit_Base, (Base_Typ));
16807 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
16808 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
16810 Set_Ekind (T, E_Signed_Integer_Subtype);
16811 Set_Etype (T, Implicit_Base);
16813 Set_Size_Info (T, (Implicit_Base));
16814 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
16815 Set_Scalar_Range (T, Def);
16816 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
16817 Set_Is_Constrained (T);
16818 end Signed_Integer_Type_Declaration;