1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Elists; use Elists;
30 with Einfo; use Einfo;
31 with Errout; use Errout;
32 with Eval_Fat; use Eval_Fat;
33 with Exp_Ch3; use Exp_Ch3;
34 with Exp_Dist; use Exp_Dist;
35 with Exp_Tss; use Exp_Tss;
36 with Exp_Util; use Exp_Util;
37 with Fname; use Fname;
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.
240 -- A related mechanism is used during expansion, for itypes created in
241 -- branches of conditionals. See Ensure_Defined in exp_util.
242 -- Could both mechanisms be merged ???
244 procedure Build_Underlying_Full_View
248 -- If the completion of a private type is itself derived from a private
249 -- type, or if the full view of a private subtype is itself private, the
250 -- back-end has no way to compute the actual size of this type. We build
251 -- an internal subtype declaration of the proper parent type to convey
252 -- this information. This extra mechanism is needed because a full
253 -- view cannot itself have a full view (it would get clobbered during
256 procedure Check_Abstract_Interfaces (N : Node_Id; Def : Node_Id);
257 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
259 procedure Check_Access_Discriminant_Requires_Limited
262 -- Check the restriction that the type to which an access discriminant
263 -- belongs must be a concurrent type or a descendant of a type with
264 -- the reserved word 'limited' in its declaration.
266 procedure Check_Anonymous_Access_Components
270 Comp_List : Node_Id);
271 -- Ada 2005 AI-382: an access component in a record definition can refer to
272 -- the enclosing record, in which case it denotes the type itself, and not
273 -- the current instance of the type. We create an anonymous access type for
274 -- the component, and flag it as an access to a component, so accessibility
275 -- checks are properly performed on it. The declaration of the access type
276 -- is placed ahead of that of the record to prevent order-of-elaboration
277 -- circularity issues in Gigi. We create an incomplete type for the record
278 -- declaration, which is the designated type of the anonymous access.
280 procedure Check_Delta_Expression (E : Node_Id);
281 -- Check that the expression represented by E is suitable for use as a
282 -- delta expression, i.e. it is of real type and is static.
284 procedure Check_Digits_Expression (E : Node_Id);
285 -- Check that the expression represented by E is suitable for use as a
286 -- digits expression, i.e. it is of integer type, positive and static.
288 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id);
289 -- Validate the initialization of an object declaration. T is the required
290 -- type, and Exp is the initialization expression.
292 procedure Check_Or_Process_Discriminants
295 Prev : Entity_Id := Empty);
296 -- If T is the full declaration of an incomplete or private type, check the
297 -- conformance of the discriminants, otherwise process them. Prev is the
298 -- entity of the partial declaration, if any.
300 procedure Check_Real_Bound (Bound : Node_Id);
301 -- Check given bound for being of real type and static. If not, post an
302 -- appropriate message, and rewrite the bound with the real literal zero.
304 procedure Constant_Redeclaration
308 -- Various checks on legality of full declaration of deferred constant.
309 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
310 -- node. The caller has not yet set any attributes of this entity.
312 function Contain_Interface
314 Ifaces : Elist_Id) return Boolean;
315 -- Ada 2005: Determine whether Iface is present in the list Ifaces
317 procedure Convert_Scalar_Bounds
319 Parent_Type : Entity_Id;
320 Derived_Type : Entity_Id;
322 -- For derived scalar types, convert the bounds in the type definition to
323 -- the derived type, and complete their analysis. Given a constraint of the
324 -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with
325 -- T'Base, the parent_type. The bounds of the derived type (the anonymous
326 -- base) are copies of Lo and Hi. Finally, the bounds of the derived
327 -- subtype are conversions of those bounds to the derived_type, so that
328 -- their typing is consistent.
330 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id);
331 -- Copies attributes from array base type T2 to array base type T1. Copies
332 -- only attributes that apply to base types, but not subtypes.
334 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id);
335 -- Copies attributes from array subtype T2 to array subtype T1. Copies
336 -- attributes that apply to both subtypes and base types.
338 procedure Create_Constrained_Components
342 Constraints : Elist_Id);
343 -- Build the list of entities for a constrained discriminated record
344 -- subtype. If a component depends on a discriminant, replace its subtype
345 -- using the discriminant values in the discriminant constraint. Subt
346 -- is the defining identifier for the subtype whose list of constrained
347 -- entities we will create. Decl_Node is the type declaration node where
348 -- we will attach all the itypes created. Typ is the base discriminated
349 -- type for the subtype Subt. Constraints is the list of discriminant
350 -- constraints for Typ.
352 function Constrain_Component_Type
354 Constrained_Typ : Entity_Id;
355 Related_Node : Node_Id;
357 Constraints : Elist_Id) return Entity_Id;
358 -- Given a discriminated base type Typ, a list of discriminant constraint
359 -- Constraints for Typ and a component of Typ, with type Compon_Type,
360 -- create and return the type corresponding to Compon_type where all
361 -- discriminant references are replaced with the corresponding constraint.
362 -- If no discriminant references occur in Compon_Typ then return it as is.
363 -- Constrained_Typ is the final constrained subtype to which the
364 -- constrained Compon_Type belongs. Related_Node is the node where we will
365 -- attach all the itypes created.
367 -- Above description is confused, what is Compon_Type???
369 procedure Constrain_Access
370 (Def_Id : in out Entity_Id;
372 Related_Nod : Node_Id);
373 -- Apply a list of constraints to an access type. If Def_Id is empty, it is
374 -- an anonymous type created for a subtype indication. In that case it is
375 -- created in the procedure and attached to Related_Nod.
377 procedure Constrain_Array
378 (Def_Id : in out Entity_Id;
380 Related_Nod : Node_Id;
381 Related_Id : Entity_Id;
383 -- Apply a list of index constraints to an unconstrained array type. The
384 -- first parameter is the entity for the resulting subtype. A value of
385 -- Empty for Def_Id indicates that an implicit type must be created, but
386 -- creation is delayed (and must be done by this procedure) because other
387 -- subsidiary implicit types must be created first (which is why Def_Id
388 -- is an in/out parameter). The second parameter is a subtype indication
389 -- node for the constrained array to be created (e.g. something of the
390 -- form string (1 .. 10)). Related_Nod gives the place where this type
391 -- has to be inserted in the tree. The Related_Id and Suffix parameters
392 -- are used to build the associated Implicit type name.
394 procedure Constrain_Concurrent
395 (Def_Id : in out Entity_Id;
397 Related_Nod : Node_Id;
398 Related_Id : Entity_Id;
400 -- Apply list of discriminant constraints to an unconstrained concurrent
403 -- SI is the N_Subtype_Indication node containing the constraint and
404 -- the unconstrained type to constrain.
406 -- Def_Id is the entity for the resulting constrained subtype. A value
407 -- of Empty for Def_Id indicates that an implicit type must be created,
408 -- but creation is delayed (and must be done by this procedure) because
409 -- other subsidiary implicit types must be created first (which is why
410 -- Def_Id is an in/out parameter).
412 -- Related_Nod gives the place where this type has to be inserted
415 -- The last two arguments are used to create its external name if needed.
417 function Constrain_Corresponding_Record
418 (Prot_Subt : Entity_Id;
419 Corr_Rec : Entity_Id;
420 Related_Nod : Node_Id;
421 Related_Id : Entity_Id) return Entity_Id;
422 -- When constraining a protected type or task type with discriminants,
423 -- constrain the corresponding record with the same discriminant values.
425 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id);
426 -- Constrain a decimal fixed point type with a digits constraint and/or a
427 -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
429 procedure Constrain_Discriminated_Type
432 Related_Nod : Node_Id;
433 For_Access : Boolean := False);
434 -- Process discriminant constraints of composite type. Verify that values
435 -- have been provided for all discriminants, that the original type is
436 -- unconstrained, and that the types of the supplied expressions match
437 -- the discriminant types. The first three parameters are like in routine
438 -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
441 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id);
442 -- Constrain an enumeration type with a range constraint. This is identical
443 -- to Constrain_Integer, but for the Ekind of the resulting subtype.
445 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id);
446 -- Constrain a floating point type with either a digits constraint
447 -- and/or a range constraint, building a E_Floating_Point_Subtype.
449 procedure Constrain_Index
452 Related_Nod : Node_Id;
453 Related_Id : Entity_Id;
456 -- Process an index constraint in a constrained array declaration. The
457 -- constraint can be a subtype name, or a range with or without an explicit
458 -- subtype mark. The index is the corresponding index of the unconstrained
459 -- array. The Related_Id and Suffix parameters are used to build the
460 -- associated Implicit type name.
462 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id);
463 -- Build subtype of a signed or modular integer type
465 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id);
466 -- Constrain an ordinary fixed point type with a range constraint, and
467 -- build an E_Ordinary_Fixed_Point_Subtype entity.
469 procedure Copy_And_Swap (Priv, Full : Entity_Id);
470 -- Copy the Priv entity into the entity of its full declaration then swap
471 -- the two entities in such a manner that the former private type is now
472 -- seen as a full type.
474 procedure Decimal_Fixed_Point_Type_Declaration
477 -- Create a new decimal fixed point type, and apply the constraint to
478 -- obtain a subtype of this new type.
480 procedure Complete_Private_Subtype
483 Full_Base : Entity_Id;
484 Related_Nod : Node_Id);
485 -- Complete the implicit full view of a private subtype by setting the
486 -- appropriate semantic fields. If the full view of the parent is a record
487 -- type, build constrained components of subtype.
489 procedure Derive_Interface_Subprograms
490 (Parent_Type : Entity_Id;
491 Tagged_Type : Entity_Id;
492 Ifaces_List : Elist_Id);
493 -- Ada 2005 (AI-251): Derive primitives of abstract interface types that
494 -- are not immediate ancestors of Tagged type and associate them their
495 -- aliased primitive. Ifaces_List contains the abstract interface
496 -- primitives that have been derived from Parent_Type.
498 procedure Derived_Standard_Character
500 Parent_Type : Entity_Id;
501 Derived_Type : Entity_Id);
502 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
503 -- derivations from types Standard.Character and Standard.Wide_Character.
505 procedure Derived_Type_Declaration
508 Is_Completion : Boolean);
509 -- Process a derived type declaration. Build_Derived_Type is invoked
510 -- to process the actual derived type definition. Parameters N and
511 -- Is_Completion have the same meaning as in Build_Derived_Type.
512 -- T is the N_Defining_Identifier for the entity defined in the
513 -- N_Full_Type_Declaration node N, that is T is the derived type.
515 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id);
516 -- Insert each literal in symbol table, as an overloadable identifier. Each
517 -- enumeration type is mapped into a sequence of integers, and each literal
518 -- is defined as a constant with integer value. If any of the literals are
519 -- character literals, the type is a character type, which means that
520 -- strings are legal aggregates for arrays of components of the type.
522 function Expand_To_Stored_Constraint
524 Constraint : Elist_Id) return Elist_Id;
525 -- Given a constraint (i.e. a list of expressions) on the discriminants of
526 -- Typ, expand it into a constraint on the stored discriminants and return
527 -- the new list of expressions constraining the stored discriminants.
529 function Find_Type_Of_Object
531 Related_Nod : Node_Id) return Entity_Id;
532 -- Get type entity for object referenced by Obj_Def, attaching the
533 -- implicit types generated to Related_Nod
535 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id);
536 -- Create a new float and apply the constraint to obtain subtype of it
538 function Has_Range_Constraint (N : Node_Id) return Boolean;
539 -- Given an N_Subtype_Indication node N, return True if a range constraint
540 -- is present, either directly, or as part of a digits or delta constraint.
541 -- In addition, a digits constraint in the decimal case returns True, since
542 -- it establishes a default range if no explicit range is present.
544 function Inherit_Components
546 Parent_Base : Entity_Id;
547 Derived_Base : Entity_Id;
549 Inherit_Discr : Boolean;
550 Discs : Elist_Id) return Elist_Id;
551 -- Called from Build_Derived_Record_Type to inherit the components of
552 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
553 -- For more information on derived types and component inheritance please
554 -- consult the comment above the body of Build_Derived_Record_Type.
556 -- N is the original derived type declaration
558 -- Is_Tagged is set if we are dealing with tagged types
560 -- If Inherit_Discr is set, Derived_Base inherits its discriminants from
561 -- Parent_Base, otherwise no discriminants are inherited.
563 -- Discs gives the list of constraints that apply to Parent_Base in the
564 -- derived type declaration. If Discs is set to No_Elist, then we have
565 -- the following situation:
567 -- type Parent (D1..Dn : ..) is [tagged] record ...;
568 -- type Derived is new Parent [with ...];
570 -- which gets treated as
572 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
574 -- For untagged types the returned value is an association list. The list
575 -- starts from the association (Parent_Base => Derived_Base), and then it
576 -- contains a sequence of the associations of the form
578 -- (Old_Component => New_Component),
580 -- where Old_Component is the Entity_Id of a component in Parent_Base and
581 -- New_Component is the Entity_Id of the corresponding component in
582 -- Derived_Base. For untagged records, this association list is needed when
583 -- copying the record declaration for the derived base. In the tagged case
584 -- the value returned is irrelevant.
586 function Is_Progenitor
588 Typ : Entity_Id) return Boolean;
589 -- Determine whether type Typ implements interface Iface. This requires
590 -- traversing the list of abstract interfaces of the type, as well as that
591 -- of the ancestor types. The predicate is used to determine when a formal
592 -- in the signature of an inherited operation must carry the derived type.
594 function Is_Valid_Constraint_Kind
596 Constraint_Kind : Node_Kind) return Boolean;
597 -- Returns True if it is legal to apply the given kind of constraint to the
598 -- given kind of type (index constraint to an array type, for example).
600 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id);
601 -- Create new modular type. Verify that modulus is in bounds and is
602 -- a power of two (implementation restriction).
604 procedure New_Concatenation_Op (Typ : Entity_Id);
605 -- Create an abbreviated declaration for an operator in order to
606 -- materialize concatenation on array types.
608 procedure Ordinary_Fixed_Point_Type_Declaration
611 -- Create a new ordinary fixed point type, and apply the constraint to
612 -- obtain subtype of it.
614 procedure Prepare_Private_Subtype_Completion
616 Related_Nod : Node_Id);
617 -- Id is a subtype of some private type. Creates the full declaration
618 -- associated with Id whenever possible, i.e. when the full declaration
619 -- of the base type is already known. Records each subtype into
620 -- Private_Dependents of the base type.
622 procedure Process_Incomplete_Dependents
626 -- Process all entities that depend on an incomplete type. There include
627 -- subtypes, subprogram types that mention the incomplete type in their
628 -- profiles, and subprogram with access parameters that designate the
631 -- Inc_T is the defining identifier of an incomplete type declaration, its
632 -- Ekind is E_Incomplete_Type.
634 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
636 -- Full_T is N's defining identifier.
638 -- Subtypes of incomplete types with discriminants are completed when the
639 -- parent type is. This is simpler than private subtypes, because they can
640 -- only appear in the same scope, and there is no need to exchange views.
641 -- Similarly, access_to_subprogram types may have a parameter or a return
642 -- type that is an incomplete type, and that must be replaced with the
645 -- If the full type is tagged, subprogram with access parameters that
646 -- designated the incomplete may be primitive operations of the full type,
647 -- and have to be processed accordingly.
649 procedure Process_Real_Range_Specification (Def : Node_Id);
650 -- Given the type definition for a real type, this procedure processes and
651 -- checks the real range specification of this type definition if one is
652 -- present. If errors are found, error messages are posted, and the
653 -- Real_Range_Specification of Def is reset to Empty.
655 procedure Record_Type_Declaration
659 -- Process a record type declaration (for both untagged and tagged
660 -- records). Parameters T and N are exactly like in procedure
661 -- Derived_Type_Declaration, except that no flag Is_Completion is needed
662 -- for this routine. If this is the completion of an incomplete type
663 -- declaration, Prev is the entity of the incomplete declaration, used for
664 -- cross-referencing. Otherwise Prev = T.
666 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id);
667 -- This routine is used to process the actual record type definition (both
668 -- for untagged and tagged records). Def is a record type definition node.
669 -- This procedure analyzes the components in this record type definition.
670 -- Prev_T is the entity for the enclosing record type. It is provided so
671 -- that its Has_Task flag can be set if any of the component have Has_Task
672 -- set. If the declaration is the completion of an incomplete type
673 -- declaration, Prev_T is the original incomplete type, whose full view is
676 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id);
677 -- Subsidiary to Build_Derived_Record_Type. For untagged records, we
678 -- build a copy of the declaration tree of the parent, and we create
679 -- independently the list of components for the derived type. Semantic
680 -- information uses the component entities, but record representation
681 -- clauses are validated on the declaration tree. This procedure replaces
682 -- discriminants and components in the declaration with those that have
683 -- been created by Inherit_Components.
685 procedure Set_Fixed_Range
690 -- Build a range node with the given bounds and set it as the Scalar_Range
691 -- of the given fixed-point type entity. Loc is the source location used
692 -- for the constructed range. See body for further details.
694 procedure Set_Scalar_Range_For_Subtype
698 -- This routine is used to set the scalar range field for a subtype given
699 -- Def_Id, the entity for the subtype, and R, the range expression for the
700 -- scalar range. Subt provides the parent subtype to be used to analyze,
701 -- resolve, and check the given range.
703 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id);
704 -- Create a new signed integer entity, and apply the constraint to obtain
705 -- the required first named subtype of this type.
707 procedure Set_Stored_Constraint_From_Discriminant_Constraint
709 -- E is some record type. This routine computes E's Stored_Constraint
710 -- from its Discriminant_Constraint.
712 -----------------------
713 -- Access_Definition --
714 -----------------------
716 function Access_Definition
717 (Related_Nod : Node_Id;
718 N : Node_Id) return Entity_Id
720 Loc : constant Source_Ptr := Sloc (Related_Nod);
721 Anon_Type : Entity_Id;
722 Anon_Scope : Entity_Id;
723 Desig_Type : Entity_Id;
727 if Is_Entry (Current_Scope)
728 and then Is_Task_Type (Etype (Scope (Current_Scope)))
730 Error_Msg_N ("task entries cannot have access parameters", N);
734 -- Ada 2005: for an object declaration the corresponding anonymous
735 -- type is declared in the current scope.
737 -- If the access definition is the return type of another access to
738 -- function, scope is the current one, because it is the one of the
739 -- current type declaration.
741 if Nkind_In (Related_Nod, N_Object_Declaration,
742 N_Access_Function_Definition)
744 Anon_Scope := Current_Scope;
746 -- For the anonymous function result case, retrieve the scope of the
747 -- function specification's associated entity rather than using the
748 -- current scope. The current scope will be the function itself if the
749 -- formal part is currently being analyzed, but will be the parent scope
750 -- in the case of a parameterless function, and we always want to use
751 -- the function's parent scope. Finally, if the function is a child
752 -- unit, we must traverse the the tree to retrieve the proper entity.
754 elsif Nkind (Related_Nod) = N_Function_Specification
755 and then Nkind (Parent (N)) /= N_Parameter_Specification
757 -- If the current scope is a protected type, the anonymous access
758 -- is associated with one of the protected operations, and must
759 -- be available in the scope that encloses the protected declaration.
760 -- Otherwise the type is is in the scope enclosing the subprogram.
762 if Ekind (Current_Scope) = E_Protected_Type then
763 Anon_Scope := Scope (Scope (Defining_Entity (Related_Nod)));
765 Anon_Scope := Scope (Defining_Entity (Related_Nod));
769 -- For access formals, access components, and access discriminants,
770 -- the scope is that of the enclosing declaration,
772 Anon_Scope := Scope (Current_Scope);
777 (E_Anonymous_Access_Type, Related_Nod, Scope_Id => Anon_Scope);
780 and then Ada_Version >= Ada_05
782 Error_Msg_N ("ALL is not permitted for anonymous access types", N);
785 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
786 -- the corresponding semantic routine
788 if Present (Access_To_Subprogram_Definition (N)) then
789 Access_Subprogram_Declaration
790 (T_Name => Anon_Type,
791 T_Def => Access_To_Subprogram_Definition (N));
793 if Ekind (Anon_Type) = E_Access_Protected_Subprogram_Type then
795 (Anon_Type, E_Anonymous_Access_Protected_Subprogram_Type);
798 (Anon_Type, E_Anonymous_Access_Subprogram_Type);
801 Set_Can_Use_Internal_Rep
802 (Anon_Type, not Always_Compatible_Rep_On_Target);
804 -- If the anonymous access is associated with a protected operation
805 -- create a reference to it after the enclosing protected definition
806 -- because the itype will be used in the subsequent bodies.
808 if Ekind (Current_Scope) = E_Protected_Type then
809 Build_Itype_Reference (Anon_Type, Parent (Current_Scope));
815 Find_Type (Subtype_Mark (N));
816 Desig_Type := Entity (Subtype_Mark (N));
818 Set_Directly_Designated_Type
819 (Anon_Type, Desig_Type);
820 Set_Etype (Anon_Type, Anon_Type);
822 -- Make sure the anonymous access type has size and alignment fields
823 -- set, as required by gigi. This is necessary in the case of the
824 -- Task_Body_Procedure.
826 if not Has_Private_Component (Desig_Type) then
827 Layout_Type (Anon_Type);
830 -- ???The following makes no sense, because Anon_Type is an access type
831 -- and therefore cannot have components, private or otherwise. Hence
832 -- the assertion. Not sure what was meant, here.
833 Set_Depends_On_Private (Anon_Type, Has_Private_Component (Anon_Type));
834 pragma Assert (not Depends_On_Private (Anon_Type));
836 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
837 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
838 -- the null value is allowed. In Ada 95 the null value is never allowed.
840 if Ada_Version >= Ada_05 then
841 Set_Can_Never_Be_Null (Anon_Type, Null_Exclusion_Present (N));
843 Set_Can_Never_Be_Null (Anon_Type, True);
846 -- The anonymous access type is as public as the discriminated type or
847 -- subprogram that defines it. It is imported (for back-end purposes)
848 -- if the designated type is.
850 Set_Is_Public (Anon_Type, Is_Public (Scope (Anon_Type)));
852 -- Ada 2005 (AI-50217): Propagate the attribute that indicates that the
853 -- designated type comes from the limited view.
855 Set_From_With_Type (Anon_Type, From_With_Type (Desig_Type));
857 -- Ada 2005 (AI-231): Propagate the access-constant attribute
859 Set_Is_Access_Constant (Anon_Type, Constant_Present (N));
861 -- The context is either a subprogram declaration, object declaration,
862 -- or an access discriminant, in a private or a full type declaration.
863 -- In the case of a subprogram, if the designated type is incomplete,
864 -- the operation will be a primitive operation of the full type, to be
865 -- updated subsequently. If the type is imported through a limited_with
866 -- clause, the subprogram is not a primitive operation of the type
867 -- (which is declared elsewhere in some other scope).
869 if Ekind (Desig_Type) = E_Incomplete_Type
870 and then not From_With_Type (Desig_Type)
871 and then Is_Overloadable (Current_Scope)
873 Append_Elmt (Current_Scope, Private_Dependents (Desig_Type));
874 Set_Has_Delayed_Freeze (Current_Scope);
877 -- Ada 2005: if the designated type is an interface that may contain
878 -- tasks, create a Master entity for the declaration. This must be done
879 -- before expansion of the full declaration, because the declaration may
880 -- include an expression that is an allocator, whose expansion needs the
881 -- proper Master for the created tasks.
883 if Nkind (Related_Nod) = N_Object_Declaration
884 and then Expander_Active
886 if Is_Interface (Desig_Type)
887 and then Is_Limited_Record (Desig_Type)
889 Build_Class_Wide_Master (Anon_Type);
891 -- Similarly, if the type is an anonymous access that designates
892 -- tasks, create a master entity for it in the current context.
894 elsif Has_Task (Desig_Type)
895 and then Comes_From_Source (Related_Nod)
897 if not Has_Master_Entity (Current_Scope) then
899 Make_Object_Declaration (Loc,
900 Defining_Identifier =>
901 Make_Defining_Identifier (Loc, Name_uMaster),
902 Constant_Present => True,
904 New_Reference_To (RTE (RE_Master_Id), Loc),
906 Make_Explicit_Dereference (Loc,
907 New_Reference_To (RTE (RE_Current_Master), Loc)));
909 Insert_Before (Related_Nod, Decl);
912 Set_Master_Id (Anon_Type, Defining_Identifier (Decl));
913 Set_Has_Master_Entity (Current_Scope);
915 Build_Master_Renaming (Related_Nod, Anon_Type);
920 -- For a private component of a protected type, it is imperative that
921 -- the back-end elaborate the type immediately after the protected
922 -- declaration, because this type will be used in the declarations
923 -- created for the component within each protected body, so we must
924 -- create an itype reference for it now.
926 if Nkind (Parent (Related_Nod)) = N_Protected_Definition then
927 Build_Itype_Reference (Anon_Type, Parent (Parent (Related_Nod)));
929 -- Similarly, if the access definition is the return result of a
930 -- protected function, create an itype reference for it because it
931 -- will be used within the function body.
933 elsif Nkind (Related_Nod) = N_Function_Specification
934 and then Ekind (Current_Scope) = E_Protected_Type
936 Build_Itype_Reference (Anon_Type, Parent (Current_Scope));
938 -- Finally, create an itype reference for an object declaration of
939 -- an anonymous access type. This is strictly necessary only for
940 -- deferred constants, but in any case will avoid out-of-scope
941 -- problems in the back-end.
943 elsif Nkind (Related_Nod) = N_Object_Declaration then
944 Build_Itype_Reference (Anon_Type, Related_Nod);
948 end Access_Definition;
950 -----------------------------------
951 -- Access_Subprogram_Declaration --
952 -----------------------------------
954 procedure Access_Subprogram_Declaration
959 procedure Check_For_Premature_Usage (Def : Node_Id);
960 -- Check that type T_Name is not used, directly or recursively,
961 -- as a parameter or a return type in Def. Def is either a subtype,
962 -- an access_definition, or an access_to_subprogram_definition.
964 -------------------------------
965 -- Check_For_Premature_Usage --
966 -------------------------------
968 procedure Check_For_Premature_Usage (Def : Node_Id) is
972 -- Check for a subtype mark
974 if Nkind (Def) in N_Has_Etype then
975 if Etype (Def) = T_Name then
977 ("type& cannot be used before end of its declaration", Def);
980 -- If this is not a subtype, then this is an access_definition
982 elsif Nkind (Def) = N_Access_Definition then
983 if Present (Access_To_Subprogram_Definition (Def)) then
984 Check_For_Premature_Usage
985 (Access_To_Subprogram_Definition (Def));
987 Check_For_Premature_Usage (Subtype_Mark (Def));
990 -- The only cases left are N_Access_Function_Definition and
991 -- N_Access_Procedure_Definition.
994 if Present (Parameter_Specifications (Def)) then
995 Param := First (Parameter_Specifications (Def));
996 while Present (Param) loop
997 Check_For_Premature_Usage (Parameter_Type (Param));
998 Param := Next (Param);
1002 if Nkind (Def) = N_Access_Function_Definition then
1003 Check_For_Premature_Usage (Result_Definition (Def));
1006 end Check_For_Premature_Usage;
1010 Formals : constant List_Id := Parameter_Specifications (T_Def);
1013 Desig_Type : constant Entity_Id :=
1014 Create_Itype (E_Subprogram_Type, Parent (T_Def));
1016 -- Start of processing for Access_Subprogram_Declaration
1019 -- Associate the Itype node with the inner full-type declaration or
1020 -- subprogram spec. This is required to handle nested anonymous
1021 -- declarations. For example:
1024 -- (X : access procedure
1025 -- (Y : access procedure
1028 D_Ityp := Associated_Node_For_Itype (Desig_Type);
1029 while not (Nkind_In (D_Ityp, N_Full_Type_Declaration,
1030 N_Private_Type_Declaration,
1031 N_Private_Extension_Declaration,
1032 N_Procedure_Specification,
1033 N_Function_Specification)
1035 Nkind_In (D_Ityp, N_Object_Declaration,
1036 N_Object_Renaming_Declaration,
1037 N_Formal_Type_Declaration,
1038 N_Task_Type_Declaration,
1039 N_Protected_Type_Declaration))
1041 D_Ityp := Parent (D_Ityp);
1042 pragma Assert (D_Ityp /= Empty);
1045 Set_Associated_Node_For_Itype (Desig_Type, D_Ityp);
1047 if Nkind_In (D_Ityp, N_Procedure_Specification,
1048 N_Function_Specification)
1050 Set_Scope (Desig_Type, Scope (Defining_Entity (D_Ityp)));
1052 elsif Nkind_In (D_Ityp, N_Full_Type_Declaration,
1053 N_Object_Declaration,
1054 N_Object_Renaming_Declaration,
1055 N_Formal_Type_Declaration)
1057 Set_Scope (Desig_Type, Scope (Defining_Identifier (D_Ityp)));
1060 if Nkind (T_Def) = N_Access_Function_Definition then
1061 if Nkind (Result_Definition (T_Def)) = N_Access_Definition then
1063 Acc : constant Node_Id := Result_Definition (T_Def);
1066 if Present (Access_To_Subprogram_Definition (Acc))
1068 Protected_Present (Access_To_Subprogram_Definition (Acc))
1072 Replace_Anonymous_Access_To_Protected_Subprogram
1078 Access_Definition (T_Def, Result_Definition (T_Def)));
1083 Analyze (Result_Definition (T_Def));
1084 Set_Etype (Desig_Type, Entity (Result_Definition (T_Def)));
1087 if not (Is_Type (Etype (Desig_Type))) then
1089 ("expect type in function specification",
1090 Result_Definition (T_Def));
1094 Set_Etype (Desig_Type, Standard_Void_Type);
1097 if Present (Formals) then
1098 Push_Scope (Desig_Type);
1099 Process_Formals (Formals, Parent (T_Def));
1101 -- A bit of a kludge here, End_Scope requires that the parent
1102 -- pointer be set to something reasonable, but Itypes don't have
1103 -- parent pointers. So we set it and then unset it ??? If and when
1104 -- Itypes have proper parent pointers to their declarations, this
1105 -- kludge can be removed.
1107 Set_Parent (Desig_Type, T_Name);
1109 Set_Parent (Desig_Type, Empty);
1112 -- Check for premature usage of the type being defined
1114 Check_For_Premature_Usage (T_Def);
1116 -- The return type and/or any parameter type may be incomplete. Mark
1117 -- the subprogram_type as depending on the incomplete type, so that
1118 -- it can be updated when the full type declaration is seen. This
1119 -- only applies to incomplete types declared in some enclosing scope,
1120 -- not to limited views from other packages.
1122 if Present (Formals) then
1123 Formal := First_Formal (Desig_Type);
1124 while Present (Formal) loop
1125 if Ekind (Formal) /= E_In_Parameter
1126 and then Nkind (T_Def) = N_Access_Function_Definition
1128 Error_Msg_N ("functions can only have IN parameters", Formal);
1131 if Ekind (Etype (Formal)) = E_Incomplete_Type
1132 and then In_Open_Scopes (Scope (Etype (Formal)))
1134 Append_Elmt (Desig_Type, Private_Dependents (Etype (Formal)));
1135 Set_Has_Delayed_Freeze (Desig_Type);
1138 Next_Formal (Formal);
1142 if Ekind (Etype (Desig_Type)) = E_Incomplete_Type
1143 and then not Has_Delayed_Freeze (Desig_Type)
1145 Append_Elmt (Desig_Type, Private_Dependents (Etype (Desig_Type)));
1146 Set_Has_Delayed_Freeze (Desig_Type);
1149 Check_Delayed_Subprogram (Desig_Type);
1151 if Protected_Present (T_Def) then
1152 Set_Ekind (T_Name, E_Access_Protected_Subprogram_Type);
1153 Set_Convention (Desig_Type, Convention_Protected);
1155 Set_Ekind (T_Name, E_Access_Subprogram_Type);
1158 Set_Can_Use_Internal_Rep (T_Name, not Always_Compatible_Rep_On_Target);
1160 Set_Etype (T_Name, T_Name);
1161 Init_Size_Align (T_Name);
1162 Set_Directly_Designated_Type (T_Name, Desig_Type);
1164 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1166 Set_Can_Never_Be_Null (T_Name, Null_Exclusion_Present (T_Def));
1168 Check_Restriction (No_Access_Subprograms, T_Def);
1169 end Access_Subprogram_Declaration;
1171 ----------------------------
1172 -- Access_Type_Declaration --
1173 ----------------------------
1175 procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id) is
1176 S : constant Node_Id := Subtype_Indication (Def);
1177 P : constant Node_Id := Parent (Def);
1183 -- Check for permissible use of incomplete type
1185 if Nkind (S) /= N_Subtype_Indication then
1188 if Ekind (Root_Type (Entity (S))) = E_Incomplete_Type then
1189 Set_Directly_Designated_Type (T, Entity (S));
1191 Set_Directly_Designated_Type (T,
1192 Process_Subtype (S, P, T, 'P'));
1196 Set_Directly_Designated_Type (T,
1197 Process_Subtype (S, P, T, 'P'));
1200 if All_Present (Def) or Constant_Present (Def) then
1201 Set_Ekind (T, E_General_Access_Type);
1203 Set_Ekind (T, E_Access_Type);
1206 if Base_Type (Designated_Type (T)) = T then
1207 Error_Msg_N ("access type cannot designate itself", S);
1209 -- In Ada 2005, the type may have a limited view through some unit
1210 -- in its own context, allowing the following circularity that cannot
1211 -- be detected earlier
1213 elsif Is_Class_Wide_Type (Designated_Type (T))
1214 and then Etype (Designated_Type (T)) = T
1217 ("access type cannot designate its own classwide type", S);
1219 -- Clean up indication of tagged status to prevent cascaded errors
1221 Set_Is_Tagged_Type (T, False);
1226 -- If the type has appeared already in a with_type clause, it is
1227 -- frozen and the pointer size is already set. Else, initialize.
1229 if not From_With_Type (T) then
1230 Init_Size_Align (T);
1233 Desig := Designated_Type (T);
1235 -- If designated type is an imported tagged type, indicate that the
1236 -- access type is also imported, and therefore restricted in its use.
1237 -- The access type may already be imported, so keep setting otherwise.
1239 -- Ada 2005 (AI-50217): If the non-limited view of the designated type
1240 -- is available, use it as the designated type of the access type, so
1241 -- that the back-end gets a usable entity.
1243 if From_With_Type (Desig)
1244 and then Ekind (Desig) /= E_Access_Type
1246 Set_From_With_Type (T);
1249 -- Note that Has_Task is always false, since the access type itself
1250 -- is not a task type. See Einfo for more description on this point.
1251 -- Exactly the same consideration applies to Has_Controlled_Component.
1253 Set_Has_Task (T, False);
1254 Set_Has_Controlled_Component (T, False);
1256 -- Initialize Associated_Final_Chain explicitly to Empty, to avoid
1257 -- problems where an incomplete view of this entity has been previously
1258 -- established by a limited with and an overlaid version of this field
1259 -- (Stored_Constraint) was initialized for the incomplete view.
1261 Set_Associated_Final_Chain (T, Empty);
1263 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1266 Set_Can_Never_Be_Null (T, Null_Exclusion_Present (Def));
1267 Set_Is_Access_Constant (T, Constant_Present (Def));
1268 end Access_Type_Declaration;
1270 ----------------------------------
1271 -- Add_Interface_Tag_Components --
1272 ----------------------------------
1274 procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id) is
1275 Loc : constant Source_Ptr := Sloc (N);
1282 procedure Add_Sync_Iface_Tags (T : Entity_Id);
1283 -- Local subprogram used to recursively climb through the parents
1284 -- of T to add the tags of all the progenitor interfaces.
1286 procedure Add_Tag (Iface : Entity_Id);
1287 -- Add tag for one of the progenitor interfaces
1289 -------------------------
1290 -- Add_Sync_Iface_Tags --
1291 -------------------------
1293 procedure Add_Sync_Iface_Tags (T : Entity_Id) is
1295 if Etype (T) /= T then
1296 Add_Sync_Iface_Tags (Etype (T));
1299 Elmt := First_Elmt (Abstract_Interfaces (T));
1300 while Present (Elmt) loop
1301 Add_Tag (Node (Elmt));
1304 end Add_Sync_Iface_Tags;
1310 procedure Add_Tag (Iface : Entity_Id) is
1317 pragma Assert (Is_Tagged_Type (Iface)
1318 and then Is_Interface (Iface));
1321 Make_Component_Definition (Loc,
1322 Aliased_Present => True,
1323 Subtype_Indication =>
1324 New_Occurrence_Of (RTE (RE_Interface_Tag), Loc));
1326 Tag := Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1329 Make_Component_Declaration (Loc,
1330 Defining_Identifier => Tag,
1331 Component_Definition => Def);
1333 Analyze_Component_Declaration (Decl);
1335 Set_Analyzed (Decl);
1336 Set_Ekind (Tag, E_Component);
1338 Set_Is_Aliased (Tag);
1339 Set_Related_Type (Tag, Iface);
1340 Init_Component_Location (Tag);
1342 pragma Assert (Is_Frozen (Iface));
1344 Set_DT_Entry_Count (Tag,
1345 DT_Entry_Count (First_Entity (Iface)));
1347 if No (Last_Tag) then
1350 Insert_After (Last_Tag, Decl);
1355 -- If the ancestor has discriminants we need to give special support
1356 -- to store the offset_to_top value of the secondary dispatch tables.
1357 -- For this purpose we add a supplementary component just after the
1358 -- field that contains the tag associated with each secondary DT.
1360 if Typ /= Etype (Typ)
1361 and then Has_Discriminants (Etype (Typ))
1364 Make_Component_Definition (Loc,
1365 Subtype_Indication =>
1366 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc));
1369 Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1372 Make_Component_Declaration (Loc,
1373 Defining_Identifier => Offset,
1374 Component_Definition => Def);
1376 Analyze_Component_Declaration (Decl);
1378 Set_Analyzed (Decl);
1379 Set_Ekind (Offset, E_Component);
1380 Set_Is_Aliased (Offset);
1381 Set_Related_Type (Offset, Iface);
1382 Init_Component_Location (Offset);
1383 Insert_After (Last_Tag, Decl);
1390 Iface_List : List_Id;
1392 -- Start of processing for Add_Interface_Tag_Components
1395 if not RTE_Available (RE_Interface_Tag) then
1397 ("(Ada 2005) interface types not supported by this run-time!",
1402 if Ekind (Typ) /= E_Record_Type
1403 or else (Is_Concurrent_Record_Type (Typ)
1404 and then Is_Empty_List (Abstract_Interface_List (Typ)))
1405 or else (not Is_Concurrent_Record_Type (Typ)
1406 and then No (Abstract_Interfaces (Typ))
1407 and then Is_Empty_Elmt_List (Abstract_Interfaces (Typ)))
1412 -- Find the current last tag
1414 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1415 Ext := Record_Extension_Part (Type_Definition (N));
1417 pragma Assert (Nkind (Type_Definition (N)) = N_Record_Definition);
1418 Ext := Type_Definition (N);
1423 if not (Present (Component_List (Ext))) then
1424 Set_Null_Present (Ext, False);
1426 Set_Component_List (Ext,
1427 Make_Component_List (Loc,
1428 Component_Items => L,
1429 Null_Present => False));
1431 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1432 L := Component_Items
1434 (Record_Extension_Part
1435 (Type_Definition (N))));
1437 L := Component_Items
1439 (Type_Definition (N)));
1442 -- Find the last tag component
1445 while Present (Comp) loop
1446 if Nkind (Comp) = N_Component_Declaration
1447 and then Is_Tag (Defining_Identifier (Comp))
1456 -- At this point L references the list of components and Last_Tag
1457 -- references the current last tag (if any). Now we add the tag
1458 -- corresponding with all the interfaces that are not implemented
1461 if Is_Concurrent_Record_Type (Typ) then
1462 Iface_List := Abstract_Interface_List (Typ);
1464 if Is_Non_Empty_List (Iface_List) then
1465 Add_Sync_Iface_Tags (Etype (First (Iface_List)));
1469 if Present (Abstract_Interfaces (Typ)) then
1470 Elmt := First_Elmt (Abstract_Interfaces (Typ));
1471 while Present (Elmt) loop
1472 Add_Tag (Node (Elmt));
1476 end Add_Interface_Tag_Components;
1478 -----------------------------------
1479 -- Analyze_Component_Declaration --
1480 -----------------------------------
1482 procedure Analyze_Component_Declaration (N : Node_Id) is
1483 Id : constant Entity_Id := Defining_Identifier (N);
1484 E : constant Node_Id := Expression (N);
1488 function Contains_POC (Constr : Node_Id) return Boolean;
1489 -- Determines whether a constraint uses the discriminant of a record
1490 -- type thus becoming a per-object constraint (POC).
1492 function Is_Known_Limited (Typ : Entity_Id) return Boolean;
1493 -- Typ is the type of the current component, check whether this type is
1494 -- a limited type. Used to validate declaration against that of
1495 -- enclosing record.
1501 function Contains_POC (Constr : Node_Id) return Boolean is
1503 -- Prevent cascaded errors
1505 if Error_Posted (Constr) then
1509 case Nkind (Constr) is
1510 when N_Attribute_Reference =>
1512 Attribute_Name (Constr) = Name_Access
1513 and then Prefix (Constr) = Scope (Entity (Prefix (Constr)));
1515 when N_Discriminant_Association =>
1516 return Denotes_Discriminant (Expression (Constr));
1518 when N_Identifier =>
1519 return Denotes_Discriminant (Constr);
1521 when N_Index_Or_Discriminant_Constraint =>
1526 IDC := First (Constraints (Constr));
1527 while Present (IDC) loop
1529 -- One per-object constraint is sufficient
1531 if Contains_POC (IDC) then
1542 return Denotes_Discriminant (Low_Bound (Constr))
1544 Denotes_Discriminant (High_Bound (Constr));
1546 when N_Range_Constraint =>
1547 return Denotes_Discriminant (Range_Expression (Constr));
1555 ----------------------
1556 -- Is_Known_Limited --
1557 ----------------------
1559 function Is_Known_Limited (Typ : Entity_Id) return Boolean is
1560 P : constant Entity_Id := Etype (Typ);
1561 R : constant Entity_Id := Root_Type (Typ);
1564 if Is_Limited_Record (Typ) then
1567 -- If the root type is limited (and not a limited interface)
1568 -- so is the current type
1570 elsif Is_Limited_Record (R)
1572 (not Is_Interface (R)
1573 or else not Is_Limited_Interface (R))
1577 -- Else the type may have a limited interface progenitor, but a
1578 -- limited record parent.
1581 and then Is_Limited_Record (P)
1588 end Is_Known_Limited;
1590 -- Start of processing for Analyze_Component_Declaration
1593 Generate_Definition (Id);
1596 if Present (Subtype_Indication (Component_Definition (N))) then
1597 T := Find_Type_Of_Object
1598 (Subtype_Indication (Component_Definition (N)), N);
1600 -- Ada 2005 (AI-230): Access Definition case
1603 pragma Assert (Present
1604 (Access_Definition (Component_Definition (N))));
1606 T := Access_Definition
1608 N => Access_Definition (Component_Definition (N)));
1609 Set_Is_Local_Anonymous_Access (T);
1611 -- Ada 2005 (AI-254)
1613 if Present (Access_To_Subprogram_Definition
1614 (Access_Definition (Component_Definition (N))))
1615 and then Protected_Present (Access_To_Subprogram_Definition
1617 (Component_Definition (N))))
1619 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
1623 -- If the subtype is a constrained subtype of the enclosing record,
1624 -- (which must have a partial view) the back-end does not properly
1625 -- handle the recursion. Rewrite the component declaration with an
1626 -- explicit subtype indication, which is acceptable to Gigi. We can copy
1627 -- the tree directly because side effects have already been removed from
1628 -- discriminant constraints.
1630 if Ekind (T) = E_Access_Subtype
1631 and then Is_Entity_Name (Subtype_Indication (Component_Definition (N)))
1632 and then Comes_From_Source (T)
1633 and then Nkind (Parent (T)) = N_Subtype_Declaration
1634 and then Etype (Directly_Designated_Type (T)) = Current_Scope
1637 (Subtype_Indication (Component_Definition (N)),
1638 New_Copy_Tree (Subtype_Indication (Parent (T))));
1639 T := Find_Type_Of_Object
1640 (Subtype_Indication (Component_Definition (N)), N);
1643 -- If the component declaration includes a default expression, then we
1644 -- check that the component is not of a limited type (RM 3.7(5)),
1645 -- and do the special preanalysis of the expression (see section on
1646 -- "Handling of Default and Per-Object Expressions" in the spec of
1650 Preanalyze_Spec_Expression (E, T);
1651 Check_Initialization (T, E);
1653 if Ada_Version >= Ada_05
1654 and then Ekind (T) = E_Anonymous_Access_Type
1656 -- Check RM 3.9.2(9): "if the expected type for an expression is
1657 -- an anonymous access-to-specific tagged type, then the object
1658 -- designated by the expression shall not be dynamically tagged
1659 -- unless it is a controlling operand in a call on a dispatching
1662 if Is_Tagged_Type (Directly_Designated_Type (T))
1664 Ekind (Directly_Designated_Type (T)) /= E_Class_Wide_Type
1666 Ekind (Directly_Designated_Type (Etype (E))) =
1670 ("access to specific tagged type required (RM 3.9.2(9))", E);
1673 -- (Ada 2005: AI-230): Accessibility check for anonymous
1676 if Type_Access_Level (Etype (E)) > Type_Access_Level (T) then
1678 ("expression has deeper access level than component " &
1679 "(RM 3.10.2 (12.2))", E);
1682 -- The initialization expression is a reference to an access
1683 -- discriminant. The type of the discriminant is always deeper
1684 -- than any access type.
1686 if Ekind (Etype (E)) = E_Anonymous_Access_Type
1687 and then Is_Entity_Name (E)
1688 and then Ekind (Entity (E)) = E_In_Parameter
1689 and then Present (Discriminal_Link (Entity (E)))
1692 ("discriminant has deeper accessibility level than target",
1698 -- The parent type may be a private view with unknown discriminants,
1699 -- and thus unconstrained. Regular components must be constrained.
1701 if Is_Indefinite_Subtype (T) and then Chars (Id) /= Name_uParent then
1702 if Is_Class_Wide_Type (T) then
1704 ("class-wide subtype with unknown discriminants" &
1705 " in component declaration",
1706 Subtype_Indication (Component_Definition (N)));
1709 ("unconstrained subtype in component declaration",
1710 Subtype_Indication (Component_Definition (N)));
1713 -- Components cannot be abstract, except for the special case of
1714 -- the _Parent field (case of extending an abstract tagged type)
1716 elsif Is_Abstract_Type (T) and then Chars (Id) /= Name_uParent then
1717 Error_Msg_N ("type of a component cannot be abstract", N);
1721 Set_Is_Aliased (Id, Aliased_Present (Component_Definition (N)));
1723 -- The component declaration may have a per-object constraint, set
1724 -- the appropriate flag in the defining identifier of the subtype.
1726 if Present (Subtype_Indication (Component_Definition (N))) then
1728 Sindic : constant Node_Id :=
1729 Subtype_Indication (Component_Definition (N));
1731 if Nkind (Sindic) = N_Subtype_Indication
1732 and then Present (Constraint (Sindic))
1733 and then Contains_POC (Constraint (Sindic))
1735 Set_Has_Per_Object_Constraint (Id);
1740 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
1741 -- out some static checks.
1743 if Ada_Version >= Ada_05
1744 and then Can_Never_Be_Null (T)
1746 Null_Exclusion_Static_Checks (N);
1749 -- If this component is private (or depends on a private type), flag the
1750 -- record type to indicate that some operations are not available.
1752 P := Private_Component (T);
1756 -- Check for circular definitions
1758 if P = Any_Type then
1759 Set_Etype (Id, Any_Type);
1761 -- There is a gap in the visibility of operations only if the
1762 -- component type is not defined in the scope of the record type.
1764 elsif Scope (P) = Scope (Current_Scope) then
1767 elsif Is_Limited_Type (P) then
1768 Set_Is_Limited_Composite (Current_Scope);
1771 Set_Is_Private_Composite (Current_Scope);
1776 and then Is_Limited_Type (T)
1777 and then Chars (Id) /= Name_uParent
1778 and then Is_Tagged_Type (Current_Scope)
1780 if Is_Derived_Type (Current_Scope)
1781 and then not Is_Known_Limited (Current_Scope)
1784 ("extension of nonlimited type cannot have limited components",
1787 if Is_Interface (Root_Type (Current_Scope)) then
1789 ("\limitedness is not inherited from limited interface", N);
1791 ("\add LIMITED to type indication", N);
1794 Explain_Limited_Type (T, N);
1795 Set_Etype (Id, Any_Type);
1796 Set_Is_Limited_Composite (Current_Scope, False);
1798 elsif not Is_Derived_Type (Current_Scope)
1799 and then not Is_Limited_Record (Current_Scope)
1800 and then not Is_Concurrent_Type (Current_Scope)
1803 ("nonlimited tagged type cannot have limited components", N);
1804 Explain_Limited_Type (T, N);
1805 Set_Etype (Id, Any_Type);
1806 Set_Is_Limited_Composite (Current_Scope, False);
1810 Set_Original_Record_Component (Id, Id);
1811 end Analyze_Component_Declaration;
1813 --------------------------
1814 -- Analyze_Declarations --
1815 --------------------------
1817 procedure Analyze_Declarations (L : List_Id) is
1819 Freeze_From : Entity_Id := Empty;
1820 Next_Node : Node_Id;
1823 -- Adjust D not to include implicit label declarations, since these
1824 -- have strange Sloc values that result in elaboration check problems.
1825 -- (They have the sloc of the label as found in the source, and that
1826 -- is ahead of the current declarative part).
1832 procedure Adjust_D is
1834 while Present (Prev (D))
1835 and then Nkind (D) = N_Implicit_Label_Declaration
1841 -- Start of processing for Analyze_Declarations
1845 while Present (D) loop
1847 -- Complete analysis of declaration
1850 Next_Node := Next (D);
1852 if No (Freeze_From) then
1853 Freeze_From := First_Entity (Current_Scope);
1856 -- At the end of a declarative part, freeze remaining entities
1857 -- declared in it. The end of the visible declarations of package
1858 -- specification is not the end of a declarative part if private
1859 -- declarations are present. The end of a package declaration is a
1860 -- freezing point only if it a library package. A task definition or
1861 -- protected type definition is not a freeze point either. Finally,
1862 -- we do not freeze entities in generic scopes, because there is no
1863 -- code generated for them and freeze nodes will be generated for
1866 -- The end of a package instantiation is not a freeze point, but
1867 -- for now we make it one, because the generic body is inserted
1868 -- (currently) immediately after. Generic instantiations will not
1869 -- be a freeze point once delayed freezing of bodies is implemented.
1870 -- (This is needed in any case for early instantiations ???).
1872 if No (Next_Node) then
1873 if Nkind_In (Parent (L), N_Component_List,
1875 N_Protected_Definition)
1879 elsif Nkind (Parent (L)) /= N_Package_Specification then
1880 if Nkind (Parent (L)) = N_Package_Body then
1881 Freeze_From := First_Entity (Current_Scope);
1885 Freeze_All (Freeze_From, D);
1886 Freeze_From := Last_Entity (Current_Scope);
1888 elsif Scope (Current_Scope) /= Standard_Standard
1889 and then not Is_Child_Unit (Current_Scope)
1890 and then No (Generic_Parent (Parent (L)))
1894 elsif L /= Visible_Declarations (Parent (L))
1895 or else No (Private_Declarations (Parent (L)))
1896 or else Is_Empty_List (Private_Declarations (Parent (L)))
1899 Freeze_All (Freeze_From, D);
1900 Freeze_From := Last_Entity (Current_Scope);
1903 -- If next node is a body then freeze all types before the body.
1904 -- An exception occurs for some expander-generated bodies. If these
1905 -- are generated at places where in general language rules would not
1906 -- allow a freeze point, then we assume that the expander has
1907 -- explicitly checked that all required types are properly frozen,
1908 -- and we do not cause general freezing here. This special circuit
1909 -- is used when the encountered body is marked as having already
1912 -- In all other cases (bodies that come from source, and expander
1913 -- generated bodies that have not been analyzed yet), freeze all
1914 -- types now. Note that in the latter case, the expander must take
1915 -- care to attach the bodies at a proper place in the tree so as to
1916 -- not cause unwanted freezing at that point.
1918 elsif not Analyzed (Next_Node)
1919 and then (Nkind_In (Next_Node, N_Subprogram_Body,
1925 Nkind (Next_Node) in N_Body_Stub)
1928 Freeze_All (Freeze_From, D);
1929 Freeze_From := Last_Entity (Current_Scope);
1934 end Analyze_Declarations;
1936 ----------------------------------
1937 -- Analyze_Incomplete_Type_Decl --
1938 ----------------------------------
1940 procedure Analyze_Incomplete_Type_Decl (N : Node_Id) is
1941 F : constant Boolean := Is_Pure (Current_Scope);
1945 Generate_Definition (Defining_Identifier (N));
1947 -- Process an incomplete declaration. The identifier must not have been
1948 -- declared already in the scope. However, an incomplete declaration may
1949 -- appear in the private part of a package, for a private type that has
1950 -- already been declared.
1952 -- In this case, the discriminants (if any) must match
1954 T := Find_Type_Name (N);
1956 Set_Ekind (T, E_Incomplete_Type);
1957 Init_Size_Align (T);
1958 Set_Is_First_Subtype (T, True);
1961 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
1962 -- incomplete types.
1964 if Tagged_Present (N) then
1965 Set_Is_Tagged_Type (T);
1966 Make_Class_Wide_Type (T);
1967 Set_Primitive_Operations (T, New_Elmt_List);
1972 Set_Stored_Constraint (T, No_Elist);
1974 if Present (Discriminant_Specifications (N)) then
1975 Process_Discriminants (N);
1980 -- If the type has discriminants, non-trivial subtypes may be be
1981 -- declared before the full view of the type. The full views of those
1982 -- subtypes will be built after the full view of the type.
1984 Set_Private_Dependents (T, New_Elmt_List);
1986 end Analyze_Incomplete_Type_Decl;
1988 -----------------------------------
1989 -- Analyze_Interface_Declaration --
1990 -----------------------------------
1992 procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id) is
1993 CW : constant Entity_Id := Class_Wide_Type (T);
1996 Set_Is_Tagged_Type (T);
1998 Set_Is_Limited_Record (T, Limited_Present (Def)
1999 or else Task_Present (Def)
2000 or else Protected_Present (Def)
2001 or else Synchronized_Present (Def));
2003 -- Type is abstract if full declaration carries keyword, or if previous
2004 -- partial view did.
2006 Set_Is_Abstract_Type (T);
2007 Set_Is_Interface (T);
2009 -- Type is a limited interface if it includes the keyword limited, task,
2010 -- protected, or synchronized.
2012 Set_Is_Limited_Interface
2013 (T, Limited_Present (Def)
2014 or else Protected_Present (Def)
2015 or else Synchronized_Present (Def)
2016 or else Task_Present (Def));
2018 Set_Is_Protected_Interface (T, Protected_Present (Def));
2019 Set_Is_Task_Interface (T, Task_Present (Def));
2021 -- Type is a synchronized interface if it includes the keyword task,
2022 -- protected, or synchronized.
2024 Set_Is_Synchronized_Interface
2025 (T, Synchronized_Present (Def)
2026 or else Protected_Present (Def)
2027 or else Task_Present (Def));
2029 Set_Abstract_Interfaces (T, New_Elmt_List);
2030 Set_Primitive_Operations (T, New_Elmt_List);
2032 -- Complete the decoration of the class-wide entity if it was already
2033 -- built (ie. during the creation of the limited view)
2035 if Present (CW) then
2036 Set_Is_Interface (CW);
2037 Set_Is_Limited_Interface (CW, Is_Limited_Interface (T));
2038 Set_Is_Protected_Interface (CW, Is_Protected_Interface (T));
2039 Set_Is_Synchronized_Interface (CW, Is_Synchronized_Interface (T));
2040 Set_Is_Task_Interface (CW, Is_Task_Interface (T));
2043 -- Check runtime support for synchronized interfaces
2045 if VM_Target = No_VM
2046 and then (Is_Task_Interface (T)
2047 or else Is_Protected_Interface (T)
2048 or else Is_Synchronized_Interface (T))
2049 and then not RTE_Available (RE_Select_Specific_Data)
2051 Error_Msg_CRT ("synchronized interfaces", T);
2053 end Analyze_Interface_Declaration;
2055 -----------------------------
2056 -- Analyze_Itype_Reference --
2057 -----------------------------
2059 -- Nothing to do. This node is placed in the tree only for the benefit of
2060 -- back end processing, and has no effect on the semantic processing.
2062 procedure Analyze_Itype_Reference (N : Node_Id) is
2064 pragma Assert (Is_Itype (Itype (N)));
2066 end Analyze_Itype_Reference;
2068 --------------------------------
2069 -- Analyze_Number_Declaration --
2070 --------------------------------
2072 procedure Analyze_Number_Declaration (N : Node_Id) is
2073 Id : constant Entity_Id := Defining_Identifier (N);
2074 E : constant Node_Id := Expression (N);
2076 Index : Interp_Index;
2080 Generate_Definition (Id);
2083 -- This is an optimization of a common case of an integer literal
2085 if Nkind (E) = N_Integer_Literal then
2086 Set_Is_Static_Expression (E, True);
2087 Set_Etype (E, Universal_Integer);
2089 Set_Etype (Id, Universal_Integer);
2090 Set_Ekind (Id, E_Named_Integer);
2091 Set_Is_Frozen (Id, True);
2095 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2097 -- Process expression, replacing error by integer zero, to avoid
2098 -- cascaded errors or aborts further along in the processing
2100 -- Replace Error by integer zero, which seems least likely to
2101 -- cause cascaded errors.
2104 Rewrite (E, Make_Integer_Literal (Sloc (E), Uint_0));
2105 Set_Error_Posted (E);
2110 -- Verify that the expression is static and numeric. If
2111 -- the expression is overloaded, we apply the preference
2112 -- rule that favors root numeric types.
2114 if not Is_Overloaded (E) then
2120 Get_First_Interp (E, Index, It);
2121 while Present (It.Typ) loop
2122 if (Is_Integer_Type (It.Typ)
2123 or else Is_Real_Type (It.Typ))
2124 and then (Scope (Base_Type (It.Typ))) = Standard_Standard
2126 if T = Any_Type then
2129 elsif It.Typ = Universal_Real
2130 or else It.Typ = Universal_Integer
2132 -- Choose universal interpretation over any other
2139 Get_Next_Interp (Index, It);
2143 if Is_Integer_Type (T) then
2145 Set_Etype (Id, Universal_Integer);
2146 Set_Ekind (Id, E_Named_Integer);
2148 elsif Is_Real_Type (T) then
2150 -- Because the real value is converted to universal_real, this is a
2151 -- legal context for a universal fixed expression.
2153 if T = Universal_Fixed then
2155 Loc : constant Source_Ptr := Sloc (N);
2156 Conv : constant Node_Id := Make_Type_Conversion (Loc,
2158 New_Occurrence_Of (Universal_Real, Loc),
2159 Expression => Relocate_Node (E));
2166 elsif T = Any_Fixed then
2167 Error_Msg_N ("illegal context for mixed mode operation", E);
2169 -- Expression is of the form : universal_fixed * integer. Try to
2170 -- resolve as universal_real.
2172 T := Universal_Real;
2177 Set_Etype (Id, Universal_Real);
2178 Set_Ekind (Id, E_Named_Real);
2181 Wrong_Type (E, Any_Numeric);
2185 Set_Ekind (Id, E_Constant);
2186 Set_Never_Set_In_Source (Id, True);
2187 Set_Is_True_Constant (Id, True);
2191 if Nkind_In (E, N_Integer_Literal, N_Real_Literal) then
2192 Set_Etype (E, Etype (Id));
2195 if not Is_OK_Static_Expression (E) then
2196 Flag_Non_Static_Expr
2197 ("non-static expression used in number declaration!", E);
2198 Rewrite (E, Make_Integer_Literal (Sloc (N), 1));
2199 Set_Etype (E, Any_Type);
2201 end Analyze_Number_Declaration;
2203 --------------------------------
2204 -- Analyze_Object_Declaration --
2205 --------------------------------
2207 procedure Analyze_Object_Declaration (N : Node_Id) is
2208 Loc : constant Source_Ptr := Sloc (N);
2209 Id : constant Entity_Id := Defining_Identifier (N);
2213 E : Node_Id := Expression (N);
2214 -- E is set to Expression (N) throughout this routine. When
2215 -- Expression (N) is modified, E is changed accordingly.
2217 Prev_Entity : Entity_Id := Empty;
2219 function Count_Tasks (T : Entity_Id) return Uint;
2220 -- This function is called when a non-generic library level object of a
2221 -- task type is declared. Its function is to count the static number of
2222 -- tasks declared within the type (it is only called if Has_Tasks is set
2223 -- for T). As a side effect, if an array of tasks with non-static bounds
2224 -- or a variant record type is encountered, Check_Restrictions is called
2225 -- indicating the count is unknown.
2231 function Count_Tasks (T : Entity_Id) return Uint is
2237 if Is_Task_Type (T) then
2240 elsif Is_Record_Type (T) then
2241 if Has_Discriminants (T) then
2242 Check_Restriction (Max_Tasks, N);
2247 C := First_Component (T);
2248 while Present (C) loop
2249 V := V + Count_Tasks (Etype (C));
2256 elsif Is_Array_Type (T) then
2257 X := First_Index (T);
2258 V := Count_Tasks (Component_Type (T));
2259 while Present (X) loop
2262 if not Is_Static_Subtype (C) then
2263 Check_Restriction (Max_Tasks, N);
2266 V := V * (UI_Max (Uint_0,
2267 Expr_Value (Type_High_Bound (C)) -
2268 Expr_Value (Type_Low_Bound (C)) + Uint_1));
2281 -- Start of processing for Analyze_Object_Declaration
2284 -- There are three kinds of implicit types generated by an
2285 -- object declaration:
2287 -- 1. Those for generated by the original Object Definition
2289 -- 2. Those generated by the Expression
2291 -- 3. Those used to constrained the Object Definition with the
2292 -- expression constraints when it is unconstrained
2294 -- They must be generated in this order to avoid order of elaboration
2295 -- issues. Thus the first step (after entering the name) is to analyze
2296 -- the object definition.
2298 if Constant_Present (N) then
2299 Prev_Entity := Current_Entity_In_Scope (Id);
2301 -- If the homograph is an implicit subprogram, it is overridden by
2302 -- the current declaration.
2304 if Present (Prev_Entity)
2306 ((Is_Overloadable (Prev_Entity)
2307 and then Is_Inherited_Operation (Prev_Entity))
2309 -- The current object is a discriminal generated for an entry
2310 -- family index. Even though the index is a constant, in this
2311 -- particular context there is no true contant redeclaration.
2312 -- Enter_Name will handle the visibility.
2315 (Is_Discriminal (Id)
2316 and then Ekind (Discriminal_Link (Id)) =
2317 E_Entry_Index_Parameter))
2319 Prev_Entity := Empty;
2323 if Present (Prev_Entity) then
2324 Constant_Redeclaration (Id, N, T);
2326 Generate_Reference (Prev_Entity, Id, 'c');
2327 Set_Completion_Referenced (Id);
2329 if Error_Posted (N) then
2331 -- Type mismatch or illegal redeclaration, Do not analyze
2332 -- expression to avoid cascaded errors.
2334 T := Find_Type_Of_Object (Object_Definition (N), N);
2336 Set_Ekind (Id, E_Variable);
2340 -- In the normal case, enter identifier at the start to catch premature
2341 -- usage in the initialization expression.
2344 Generate_Definition (Id);
2347 Mark_Coextensions (N, Object_Definition (N));
2349 T := Find_Type_Of_Object (Object_Definition (N), N);
2351 if Nkind (Object_Definition (N)) = N_Access_Definition
2353 (Access_To_Subprogram_Definition (Object_Definition (N)))
2354 and then Protected_Present
2355 (Access_To_Subprogram_Definition (Object_Definition (N)))
2357 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
2360 if Error_Posted (Id) then
2362 Set_Ekind (Id, E_Variable);
2367 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2368 -- out some static checks
2370 if Ada_Version >= Ada_05
2371 and then Can_Never_Be_Null (T)
2373 -- In case of aggregates we must also take care of the correct
2374 -- initialization of nested aggregates bug this is done at the
2375 -- point of the analysis of the aggregate (see sem_aggr.adb)
2377 if Present (Expression (N))
2378 and then Nkind (Expression (N)) = N_Aggregate
2384 Save_Typ : constant Entity_Id := Etype (Id);
2386 Set_Etype (Id, T); -- Temp. decoration for static checks
2387 Null_Exclusion_Static_Checks (N);
2388 Set_Etype (Id, Save_Typ);
2393 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2395 -- If deferred constant, make sure context is appropriate. We detect
2396 -- a deferred constant as a constant declaration with no expression.
2397 -- A deferred constant can appear in a package body if its completion
2398 -- is by means of an interface pragma.
2400 if Constant_Present (N)
2403 -- We exclude forward references to tags
2405 if Is_Imported (Defining_Identifier (N))
2408 or else (Present (Full_View (T))
2409 and then Full_View (T) = RTE (RE_Tag)))
2413 elsif not Is_Package_Or_Generic_Package (Current_Scope) then
2415 ("invalid context for deferred constant declaration (RM 7.4)",
2418 ("\declaration requires an initialization expression",
2420 Set_Constant_Present (N, False);
2422 -- In Ada 83, deferred constant must be of private type
2424 elsif not Is_Private_Type (T) then
2425 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2427 ("(Ada 83) deferred constant must be private type", N);
2431 -- If not a deferred constant, then object declaration freezes its type
2434 Check_Fully_Declared (T, N);
2435 Freeze_Before (N, T);
2438 -- If the object was created by a constrained array definition, then
2439 -- set the link in both the anonymous base type and anonymous subtype
2440 -- that are built to represent the array type to point to the object.
2442 if Nkind (Object_Definition (Declaration_Node (Id))) =
2443 N_Constrained_Array_Definition
2445 Set_Related_Array_Object (T, Id);
2446 Set_Related_Array_Object (Base_Type (T), Id);
2449 -- Special checks for protected objects not at library level
2451 if Is_Protected_Type (T)
2452 and then not Is_Library_Level_Entity (Id)
2454 Check_Restriction (No_Local_Protected_Objects, Id);
2456 -- Protected objects with interrupt handlers must be at library level
2458 -- Ada 2005: this test is not needed (and the corresponding clause
2459 -- in the RM is removed) because accessibility checks are sufficient
2460 -- to make handlers not at the library level illegal.
2462 if Has_Interrupt_Handler (T)
2463 and then Ada_Version < Ada_05
2466 ("interrupt object can only be declared at library level", Id);
2470 -- The actual subtype of the object is the nominal subtype, unless
2471 -- the nominal one is unconstrained and obtained from the expression.
2475 -- Process initialization expression if present and not in error
2477 if Present (E) and then E /= Error then
2479 -- Generate an error in case of CPP class-wide object initialization.
2480 -- Required because otherwise the expansion of the class-wide
2481 -- assignment would try to use 'size to initialize the object
2482 -- (primitive that is not available in CPP tagged types).
2484 if Is_Class_Wide_Type (Act_T)
2485 and then Convention (Act_T) = Convention_CPP
2488 ("predefined assignment not available in CPP tagged types", E);
2491 Mark_Coextensions (N, E);
2494 -- In case of errors detected in the analysis of the expression,
2495 -- decorate it with the expected type to avoid cascaded errors
2497 if No (Etype (E)) then
2501 -- If an initialization expression is present, then we set the
2502 -- Is_True_Constant flag. It will be reset if this is a variable
2503 -- and it is indeed modified.
2505 Set_Is_True_Constant (Id, True);
2507 -- If we are analyzing a constant declaration, set its completion
2508 -- flag after analyzing and resolving the expression.
2510 if Constant_Present (N) then
2511 Set_Has_Completion (Id);
2514 -- Set type and resolve (type may be overridden later on)
2519 -- If the object is an access to variable, the initialization
2520 -- expression cannot be an access to constant.
2522 if Is_Access_Type (T)
2523 and then not Is_Access_Constant (T)
2524 and then Is_Access_Type (Etype (E))
2525 and then Is_Access_Constant (Etype (E))
2528 ("object that is an access to variable cannot be initialized " &
2529 "with an access-to-constant expression", E);
2532 if not Assignment_OK (N) then
2533 Check_Initialization (T, E);
2536 Check_Unset_Reference (E);
2538 -- If this is a variable, then set current value
2540 if not Constant_Present (N) then
2541 if Compile_Time_Known_Value (E) then
2542 Set_Current_Value (Id, E);
2546 -- Deal with setting of null flags
2548 if Is_Access_Type (T) then
2549 if Known_Non_Null (E) then
2550 Set_Is_Known_Non_Null (Id, True);
2551 elsif Known_Null (E)
2552 and then not Can_Never_Be_Null (Id)
2554 Set_Is_Known_Null (Id, True);
2558 -- Check incorrect use of dynamically tagged expressions. Note
2559 -- the use of Is_Tagged_Type (T) which seems redundant but is in
2560 -- fact important to avoid spurious errors due to expanded code
2561 -- for dispatching functions over an anonymous access type
2563 if (Is_Class_Wide_Type (Etype (E)) or else Is_Dynamically_Tagged (E))
2564 and then Is_Tagged_Type (T)
2565 and then not Is_Class_Wide_Type (T)
2567 Error_Msg_N ("dynamically tagged expression not allowed!", E);
2570 Apply_Scalar_Range_Check (E, T);
2571 Apply_Static_Length_Check (E, T);
2574 -- If the No_Streams restriction is set, check that the type of the
2575 -- object is not, and does not contain, any subtype derived from
2576 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
2577 -- Has_Stream just for efficiency reasons. There is no point in
2578 -- spending time on a Has_Stream check if the restriction is not set.
2580 if Restrictions.Set (No_Streams) then
2581 if Has_Stream (T) then
2582 Check_Restriction (No_Streams, N);
2586 -- Abstract type is never permitted for a variable or constant.
2587 -- Note: we inhibit this check for objects that do not come from
2588 -- source because there is at least one case (the expansion of
2589 -- x'class'input where x is abstract) where we legitimately
2590 -- generate an abstract object.
2592 if Is_Abstract_Type (T) and then Comes_From_Source (N) then
2593 Error_Msg_N ("type of object cannot be abstract",
2594 Object_Definition (N));
2596 if Is_CPP_Class (T) then
2597 Error_Msg_NE ("\} may need a cpp_constructor",
2598 Object_Definition (N), T);
2601 -- Case of unconstrained type
2603 elsif Is_Indefinite_Subtype (T) then
2605 -- Nothing to do in deferred constant case
2607 if Constant_Present (N) and then No (E) then
2610 -- Case of no initialization present
2613 if No_Initialization (N) then
2616 elsif Is_Class_Wide_Type (T) then
2618 ("initialization required in class-wide declaration ", N);
2622 ("unconstrained subtype not allowed (need initialization)",
2623 Object_Definition (N));
2625 if Is_Record_Type (T) and then Has_Discriminants (T) then
2627 ("\provide initial value or explicit discriminant values",
2628 Object_Definition (N));
2631 ("\or give default discriminant values for type&",
2632 Object_Definition (N), T);
2634 elsif Is_Array_Type (T) then
2636 ("\provide initial value or explicit array bounds",
2637 Object_Definition (N));
2641 -- Case of initialization present but in error. Set initial
2642 -- expression as absent (but do not make above complaints)
2644 elsif E = Error then
2645 Set_Expression (N, Empty);
2648 -- Case of initialization present
2651 -- Not allowed in Ada 83
2653 if not Constant_Present (N) then
2654 if Ada_Version = Ada_83
2655 and then Comes_From_Source (Object_Definition (N))
2658 ("(Ada 83) unconstrained variable not allowed",
2659 Object_Definition (N));
2663 -- Now we constrain the variable from the initializing expression
2665 -- If the expression is an aggregate, it has been expanded into
2666 -- individual assignments. Retrieve the actual type from the
2667 -- expanded construct.
2669 if Is_Array_Type (T)
2670 and then No_Initialization (N)
2671 and then Nkind (Original_Node (E)) = N_Aggregate
2676 Expand_Subtype_From_Expr (N, T, Object_Definition (N), E);
2677 Act_T := Find_Type_Of_Object (Object_Definition (N), N);
2680 Set_Is_Constr_Subt_For_U_Nominal (Act_T);
2682 if Aliased_Present (N) then
2683 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2686 Freeze_Before (N, Act_T);
2687 Freeze_Before (N, T);
2690 elsif Is_Array_Type (T)
2691 and then No_Initialization (N)
2692 and then Nkind (Original_Node (E)) = N_Aggregate
2694 if not Is_Entity_Name (Object_Definition (N)) then
2696 Check_Compile_Time_Size (Act_T);
2698 if Aliased_Present (N) then
2699 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2703 -- When the given object definition and the aggregate are specified
2704 -- independently, and their lengths might differ do a length check.
2705 -- This cannot happen if the aggregate is of the form (others =>...)
2707 if not Is_Constrained (T) then
2710 elsif Nkind (E) = N_Raise_Constraint_Error then
2712 -- Aggregate is statically illegal. Place back in declaration
2714 Set_Expression (N, E);
2715 Set_No_Initialization (N, False);
2717 elsif T = Etype (E) then
2720 elsif Nkind (E) = N_Aggregate
2721 and then Present (Component_Associations (E))
2722 and then Present (Choices (First (Component_Associations (E))))
2723 and then Nkind (First
2724 (Choices (First (Component_Associations (E))))) = N_Others_Choice
2729 Apply_Length_Check (E, T);
2732 -- If the type is limited unconstrained with defaulted discriminants
2733 -- and there is no expression, then the object is constrained by the
2734 -- defaults, so it is worthwhile building the corresponding subtype.
2736 elsif (Is_Limited_Record (T)
2737 or else Is_Concurrent_Type (T))
2738 and then not Is_Constrained (T)
2739 and then Has_Discriminants (T)
2742 Act_T := Build_Default_Subtype (T, N);
2744 -- Ada 2005: a limited object may be initialized by means of an
2745 -- aggregate. If the type has default discriminants it has an
2746 -- unconstrained nominal type, Its actual subtype will be obtained
2747 -- from the aggregate, and not from the default discriminants.
2752 Rewrite (Object_Definition (N), New_Occurrence_Of (Act_T, Loc));
2754 elsif Present (Underlying_Type (T))
2755 and then not Is_Constrained (Underlying_Type (T))
2756 and then Has_Discriminants (Underlying_Type (T))
2757 and then Nkind (E) = N_Function_Call
2758 and then Constant_Present (N)
2760 -- The back-end has problems with constants of a discriminated type
2761 -- with defaults, if the initial value is a function call. We
2762 -- generate an intermediate temporary for the result of the call.
2763 -- It is unclear why this should make it acceptable to gcc. ???
2765 Remove_Side_Effects (E);
2768 -- Check No_Wide_Characters restriction
2770 if T = Standard_Wide_Character
2771 or else T = Standard_Wide_Wide_Character
2772 or else Root_Type (T) = Standard_Wide_String
2773 or else Root_Type (T) = Standard_Wide_Wide_String
2775 Check_Restriction (No_Wide_Characters, Object_Definition (N));
2778 -- Indicate this is not set in source. Certainly true for constants,
2779 -- and true for variables so far (will be reset for a variable if and
2780 -- when we encounter a modification in the source).
2782 Set_Never_Set_In_Source (Id, True);
2784 -- Now establish the proper kind and type of the object
2786 if Constant_Present (N) then
2787 Set_Ekind (Id, E_Constant);
2788 Set_Is_True_Constant (Id, True);
2791 Set_Ekind (Id, E_Variable);
2793 -- A variable is set as shared passive if it appears in a shared
2794 -- passive package, and is at the outer level. This is not done
2795 -- for entities generated during expansion, because those are
2796 -- always manipulated locally.
2798 if Is_Shared_Passive (Current_Scope)
2799 and then Is_Library_Level_Entity (Id)
2800 and then Comes_From_Source (Id)
2802 Set_Is_Shared_Passive (Id);
2803 Check_Shared_Var (Id, T, N);
2806 -- Set Has_Initial_Value if initializing expression present. Note
2807 -- that if there is no initializating expression, we leave the state
2808 -- of this flag unchanged (usually it will be False, but notably in
2809 -- the case of exception choice variables, it will already be true).
2812 Set_Has_Initial_Value (Id, True);
2816 -- Initialize alignment and size and capture alignment setting
2818 Init_Alignment (Id);
2820 Set_Optimize_Alignment_Flags (Id);
2822 -- Deal with aliased case
2824 if Aliased_Present (N) then
2825 Set_Is_Aliased (Id);
2827 -- If the object is aliased and the type is unconstrained with
2828 -- defaulted discriminants and there is no expression, then the
2829 -- object is constrained by the defaults, so it is worthwhile
2830 -- building the corresponding subtype.
2832 -- Ada 2005 (AI-363): If the aliased object is discriminated and
2833 -- unconstrained, then only establish an actual subtype if the
2834 -- nominal subtype is indefinite. In definite cases the object is
2835 -- unconstrained in Ada 2005.
2838 and then Is_Record_Type (T)
2839 and then not Is_Constrained (T)
2840 and then Has_Discriminants (T)
2841 and then (Ada_Version < Ada_05 or else Is_Indefinite_Subtype (T))
2843 Set_Actual_Subtype (Id, Build_Default_Subtype (T, N));
2847 -- Now we can set the type of the object
2849 Set_Etype (Id, Act_T);
2851 -- Deal with controlled types
2853 if Has_Controlled_Component (Etype (Id))
2854 or else Is_Controlled (Etype (Id))
2856 if not Is_Library_Level_Entity (Id) then
2857 Check_Restriction (No_Nested_Finalization, N);
2859 Validate_Controlled_Object (Id);
2862 -- Generate a warning when an initialization causes an obvious ABE
2863 -- violation. If the init expression is a simple aggregate there
2864 -- shouldn't be any initialize/adjust call generated. This will be
2865 -- true as soon as aggregates are built in place when possible.
2867 -- ??? at the moment we do not generate warnings for temporaries
2868 -- created for those aggregates although Program_Error might be
2869 -- generated if compiled with -gnato.
2871 if Is_Controlled (Etype (Id))
2872 and then Comes_From_Source (Id)
2875 BT : constant Entity_Id := Base_Type (Etype (Id));
2877 Implicit_Call : Entity_Id;
2878 pragma Warnings (Off, Implicit_Call);
2879 -- ??? what is this for (never referenced!)
2881 function Is_Aggr (N : Node_Id) return Boolean;
2882 -- Check that N is an aggregate
2888 function Is_Aggr (N : Node_Id) return Boolean is
2890 case Nkind (Original_Node (N)) is
2891 when N_Aggregate | N_Extension_Aggregate =>
2894 when N_Qualified_Expression |
2896 N_Unchecked_Type_Conversion =>
2897 return Is_Aggr (Expression (Original_Node (N)));
2905 -- If no underlying type, we already are in an error situation.
2906 -- Do not try to add a warning since we do not have access to
2909 if No (Underlying_Type (BT)) then
2910 Implicit_Call := Empty;
2912 -- A generic type does not have usable primitive operators.
2913 -- Initialization calls are built for instances.
2915 elsif Is_Generic_Type (BT) then
2916 Implicit_Call := Empty;
2918 -- If the init expression is not an aggregate, an adjust call
2919 -- will be generated
2921 elsif Present (E) and then not Is_Aggr (E) then
2922 Implicit_Call := Find_Prim_Op (BT, Name_Adjust);
2924 -- If no init expression and we are not in the deferred
2925 -- constant case, an Initialize call will be generated
2927 elsif No (E) and then not Constant_Present (N) then
2928 Implicit_Call := Find_Prim_Op (BT, Name_Initialize);
2931 Implicit_Call := Empty;
2937 if Has_Task (Etype (Id)) then
2938 Check_Restriction (No_Tasking, N);
2940 -- Deal with counting max tasks
2942 -- Nothing to do if inside a generic
2944 if Inside_A_Generic then
2947 -- If library level entity, then count tasks
2949 elsif Is_Library_Level_Entity (Id) then
2950 Check_Restriction (Max_Tasks, N, Count_Tasks (Etype (Id)));
2952 -- If not library level entity, then indicate we don't know max
2953 -- tasks and also check task hierarchy restriction and blocking
2954 -- operation (since starting a task is definitely blocking!)
2957 Check_Restriction (Max_Tasks, N);
2958 Check_Restriction (No_Task_Hierarchy, N);
2959 Check_Potentially_Blocking_Operation (N);
2962 -- A rather specialized test. If we see two tasks being declared
2963 -- of the same type in the same object declaration, and the task
2964 -- has an entry with an address clause, we know that program error
2965 -- will be raised at run-time since we can't have two tasks with
2966 -- entries at the same address.
2968 if Is_Task_Type (Etype (Id)) and then More_Ids (N) then
2973 E := First_Entity (Etype (Id));
2974 while Present (E) loop
2975 if Ekind (E) = E_Entry
2976 and then Present (Get_Attribute_Definition_Clause
2977 (E, Attribute_Address))
2980 ("?more than one task with same entry address", N);
2982 ("\?Program_Error will be raised at run time", N);
2984 Make_Raise_Program_Error (Loc,
2985 Reason => PE_Duplicated_Entry_Address));
2995 -- Some simple constant-propagation: if the expression is a constant
2996 -- string initialized with a literal, share the literal. This avoids
3000 and then Is_Entity_Name (E)
3001 and then Ekind (Entity (E)) = E_Constant
3002 and then Base_Type (Etype (E)) = Standard_String
3005 Val : constant Node_Id := Constant_Value (Entity (E));
3008 and then Nkind (Val) = N_String_Literal
3010 Rewrite (E, New_Copy (Val));
3015 -- Another optimization: if the nominal subtype is unconstrained and
3016 -- the expression is a function call that returns an unconstrained
3017 -- type, rewrite the declaration as a renaming of the result of the
3018 -- call. The exceptions below are cases where the copy is expected,
3019 -- either by the back end (Aliased case) or by the semantics, as for
3020 -- initializing controlled types or copying tags for classwide types.
3023 and then Nkind (E) = N_Explicit_Dereference
3024 and then Nkind (Original_Node (E)) = N_Function_Call
3025 and then not Is_Library_Level_Entity (Id)
3026 and then not Is_Constrained (Underlying_Type (T))
3027 and then not Is_Aliased (Id)
3028 and then not Is_Class_Wide_Type (T)
3029 and then not Is_Controlled (T)
3030 and then not Has_Controlled_Component (Base_Type (T))
3031 and then Expander_Active
3034 Make_Object_Renaming_Declaration (Loc,
3035 Defining_Identifier => Id,
3036 Access_Definition => Empty,
3037 Subtype_Mark => New_Occurrence_Of
3038 (Base_Type (Etype (Id)), Loc),
3041 Set_Renamed_Object (Id, E);
3043 -- Force generation of debugging information for the constant and for
3044 -- the renamed function call.
3046 Set_Debug_Info_Needed (Id);
3047 Set_Debug_Info_Needed (Entity (Prefix (E)));
3050 if Present (Prev_Entity)
3051 and then Is_Frozen (Prev_Entity)
3052 and then not Error_Posted (Id)
3054 Error_Msg_N ("full constant declaration appears too late", N);
3057 Check_Eliminated (Id);
3059 -- Deal with setting In_Private_Part flag if in private part
3061 if Ekind (Scope (Id)) = E_Package
3062 and then In_Private_Part (Scope (Id))
3064 Set_In_Private_Part (Id);
3066 end Analyze_Object_Declaration;
3068 ---------------------------
3069 -- Analyze_Others_Choice --
3070 ---------------------------
3072 -- Nothing to do for the others choice node itself, the semantic analysis
3073 -- of the others choice will occur as part of the processing of the parent
3075 procedure Analyze_Others_Choice (N : Node_Id) is
3076 pragma Warnings (Off, N);
3079 end Analyze_Others_Choice;
3081 -------------------------------------------
3082 -- Analyze_Private_Extension_Declaration --
3083 -------------------------------------------
3085 procedure Analyze_Private_Extension_Declaration (N : Node_Id) is
3086 T : constant Entity_Id := Defining_Identifier (N);
3087 Indic : constant Node_Id := Subtype_Indication (N);
3088 Parent_Type : Entity_Id;
3089 Parent_Base : Entity_Id;
3092 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
3094 if Is_Non_Empty_List (Interface_List (N)) then
3100 Intf := First (Interface_List (N));
3101 while Present (Intf) loop
3102 T := Find_Type_Of_Subtype_Indic (Intf);
3104 if not Is_Interface (T) then
3105 Error_Msg_NE ("(Ada 2005) & must be an interface", Intf, T);
3113 Generate_Definition (T);
3116 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
3117 Parent_Base := Base_Type (Parent_Type);
3119 if Parent_Type = Any_Type
3120 or else Etype (Parent_Type) = Any_Type
3122 Set_Ekind (T, Ekind (Parent_Type));
3123 Set_Etype (T, Any_Type);
3126 elsif not Is_Tagged_Type (Parent_Type) then
3128 ("parent of type extension must be a tagged type ", Indic);
3131 elsif Ekind (Parent_Type) = E_Void
3132 or else Ekind (Parent_Type) = E_Incomplete_Type
3134 Error_Msg_N ("premature derivation of incomplete type", Indic);
3137 elsif Is_Concurrent_Type (Parent_Type) then
3139 ("parent type of a private extension cannot be "
3140 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
3142 Set_Etype (T, Any_Type);
3143 Set_Ekind (T, E_Limited_Private_Type);
3144 Set_Private_Dependents (T, New_Elmt_List);
3145 Set_Error_Posted (T);
3149 -- Perhaps the parent type should be changed to the class-wide type's
3150 -- specific type in this case to prevent cascading errors ???
3152 if Is_Class_Wide_Type (Parent_Type) then
3154 ("parent of type extension must not be a class-wide type", Indic);
3158 if (not Is_Package_Or_Generic_Package (Current_Scope)
3159 and then Nkind (Parent (N)) /= N_Generic_Subprogram_Declaration)
3160 or else In_Private_Part (Current_Scope)
3163 Error_Msg_N ("invalid context for private extension", N);
3166 -- Set common attributes
3168 Set_Is_Pure (T, Is_Pure (Current_Scope));
3169 Set_Scope (T, Current_Scope);
3170 Set_Ekind (T, E_Record_Type_With_Private);
3171 Init_Size_Align (T);
3173 Set_Etype (T, Parent_Base);
3174 Set_Has_Task (T, Has_Task (Parent_Base));
3176 Set_Convention (T, Convention (Parent_Type));
3177 Set_First_Rep_Item (T, First_Rep_Item (Parent_Type));
3178 Set_Is_First_Subtype (T);
3179 Make_Class_Wide_Type (T);
3181 if Unknown_Discriminants_Present (N) then
3182 Set_Discriminant_Constraint (T, No_Elist);
3185 Build_Derived_Record_Type (N, Parent_Type, T);
3187 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
3188 -- synchronized formal derived type.
3190 if Ada_Version >= Ada_05
3191 and then Synchronized_Present (N)
3193 Set_Is_Limited_Record (T);
3195 -- Formal derived type case
3197 if Is_Generic_Type (T) then
3199 -- The parent must be a tagged limited type or a synchronized
3202 if (not Is_Tagged_Type (Parent_Type)
3203 or else not Is_Limited_Type (Parent_Type))
3205 (not Is_Interface (Parent_Type)
3206 or else not Is_Synchronized_Interface (Parent_Type))
3208 Error_Msg_NE ("parent type of & must be tagged limited " &
3209 "or synchronized", N, T);
3212 -- The progenitors (if any) must be limited or synchronized
3215 if Present (Abstract_Interfaces (T)) then
3218 Iface_Elmt : Elmt_Id;
3221 Iface_Elmt := First_Elmt (Abstract_Interfaces (T));
3222 while Present (Iface_Elmt) loop
3223 Iface := Node (Iface_Elmt);
3225 if not Is_Limited_Interface (Iface)
3226 and then not Is_Synchronized_Interface (Iface)
3228 Error_Msg_NE ("progenitor & must be limited " &
3229 "or synchronized", N, Iface);
3232 Next_Elmt (Iface_Elmt);
3237 -- Regular derived extension, the parent must be a limited or
3238 -- synchronized interface.
3241 if not Is_Interface (Parent_Type)
3242 or else (not Is_Limited_Interface (Parent_Type)
3244 not Is_Synchronized_Interface (Parent_Type))
3247 ("parent type of & must be limited interface", N, T);
3251 elsif Limited_Present (N) then
3252 Set_Is_Limited_Record (T);
3254 if not Is_Limited_Type (Parent_Type)
3256 (not Is_Interface (Parent_Type)
3257 or else not Is_Limited_Interface (Parent_Type))
3259 Error_Msg_NE ("parent type& of limited extension must be limited",
3263 end Analyze_Private_Extension_Declaration;
3265 ---------------------------------
3266 -- Analyze_Subtype_Declaration --
3267 ---------------------------------
3269 procedure Analyze_Subtype_Declaration
3271 Skip : Boolean := False)
3273 Id : constant Entity_Id := Defining_Identifier (N);
3275 R_Checks : Check_Result;
3278 Generate_Definition (Id);
3279 Set_Is_Pure (Id, Is_Pure (Current_Scope));
3280 Init_Size_Align (Id);
3282 -- The following guard condition on Enter_Name is to handle cases where
3283 -- the defining identifier has already been entered into the scope but
3284 -- the declaration as a whole needs to be analyzed.
3286 -- This case in particular happens for derived enumeration types. The
3287 -- derived enumeration type is processed as an inserted enumeration type
3288 -- declaration followed by a rewritten subtype declaration. The defining
3289 -- identifier, however, is entered into the name scope very early in the
3290 -- processing of the original type declaration and therefore needs to be
3291 -- avoided here, when the created subtype declaration is analyzed. (See
3292 -- Build_Derived_Types)
3294 -- This also happens when the full view of a private type is derived
3295 -- type with constraints. In this case the entity has been introduced
3296 -- in the private declaration.
3299 or else (Present (Etype (Id))
3300 and then (Is_Private_Type (Etype (Id))
3301 or else Is_Task_Type (Etype (Id))
3302 or else Is_Rewrite_Substitution (N)))
3310 T := Process_Subtype (Subtype_Indication (N), N, Id, 'P');
3312 -- Inherit common attributes
3314 Set_Is_Generic_Type (Id, Is_Generic_Type (Base_Type (T)));
3315 Set_Is_Volatile (Id, Is_Volatile (T));
3316 Set_Treat_As_Volatile (Id, Treat_As_Volatile (T));
3317 Set_Is_Atomic (Id, Is_Atomic (T));
3318 Set_Is_Ada_2005_Only (Id, Is_Ada_2005_Only (T));
3319 Set_Convention (Id, Convention (T));
3321 -- In the case where there is no constraint given in the subtype
3322 -- indication, Process_Subtype just returns the Subtype_Mark, so its
3323 -- semantic attributes must be established here.
3325 if Nkind (Subtype_Indication (N)) /= N_Subtype_Indication then
3326 Set_Etype (Id, Base_Type (T));
3330 Set_Ekind (Id, E_Array_Subtype);
3331 Copy_Array_Subtype_Attributes (Id, T);
3333 when Decimal_Fixed_Point_Kind =>
3334 Set_Ekind (Id, E_Decimal_Fixed_Point_Subtype);
3335 Set_Digits_Value (Id, Digits_Value (T));
3336 Set_Delta_Value (Id, Delta_Value (T));
3337 Set_Scale_Value (Id, Scale_Value (T));
3338 Set_Small_Value (Id, Small_Value (T));
3339 Set_Scalar_Range (Id, Scalar_Range (T));
3340 Set_Machine_Radix_10 (Id, Machine_Radix_10 (T));
3341 Set_Is_Constrained (Id, Is_Constrained (T));
3342 Set_RM_Size (Id, RM_Size (T));
3344 when Enumeration_Kind =>
3345 Set_Ekind (Id, E_Enumeration_Subtype);
3346 Set_First_Literal (Id, First_Literal (Base_Type (T)));
3347 Set_Scalar_Range (Id, Scalar_Range (T));
3348 Set_Is_Character_Type (Id, Is_Character_Type (T));
3349 Set_Is_Constrained (Id, Is_Constrained (T));
3350 Set_RM_Size (Id, RM_Size (T));
3352 when Ordinary_Fixed_Point_Kind =>
3353 Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype);
3354 Set_Scalar_Range (Id, Scalar_Range (T));
3355 Set_Small_Value (Id, Small_Value (T));
3356 Set_Delta_Value (Id, Delta_Value (T));
3357 Set_Is_Constrained (Id, Is_Constrained (T));
3358 Set_RM_Size (Id, RM_Size (T));
3361 Set_Ekind (Id, E_Floating_Point_Subtype);
3362 Set_Scalar_Range (Id, Scalar_Range (T));
3363 Set_Digits_Value (Id, Digits_Value (T));
3364 Set_Is_Constrained (Id, Is_Constrained (T));
3366 when Signed_Integer_Kind =>
3367 Set_Ekind (Id, E_Signed_Integer_Subtype);
3368 Set_Scalar_Range (Id, Scalar_Range (T));
3369 Set_Is_Constrained (Id, Is_Constrained (T));
3370 Set_RM_Size (Id, RM_Size (T));
3372 when Modular_Integer_Kind =>
3373 Set_Ekind (Id, E_Modular_Integer_Subtype);
3374 Set_Scalar_Range (Id, Scalar_Range (T));
3375 Set_Is_Constrained (Id, Is_Constrained (T));
3376 Set_RM_Size (Id, RM_Size (T));
3378 when Class_Wide_Kind =>
3379 Set_Ekind (Id, E_Class_Wide_Subtype);
3380 Set_First_Entity (Id, First_Entity (T));
3381 Set_Last_Entity (Id, Last_Entity (T));
3382 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3383 Set_Cloned_Subtype (Id, T);
3384 Set_Is_Tagged_Type (Id, True);
3385 Set_Has_Unknown_Discriminants
3388 if Ekind (T) = E_Class_Wide_Subtype then
3389 Set_Equivalent_Type (Id, Equivalent_Type (T));
3392 when E_Record_Type | E_Record_Subtype =>
3393 Set_Ekind (Id, E_Record_Subtype);
3395 if Ekind (T) = E_Record_Subtype
3396 and then Present (Cloned_Subtype (T))
3398 Set_Cloned_Subtype (Id, Cloned_Subtype (T));
3400 Set_Cloned_Subtype (Id, T);
3403 Set_First_Entity (Id, First_Entity (T));
3404 Set_Last_Entity (Id, Last_Entity (T));
3405 Set_Has_Discriminants (Id, Has_Discriminants (T));
3406 Set_Is_Constrained (Id, Is_Constrained (T));
3407 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3408 Set_Has_Unknown_Discriminants
3409 (Id, Has_Unknown_Discriminants (T));
3411 if Has_Discriminants (T) then
3412 Set_Discriminant_Constraint
3413 (Id, Discriminant_Constraint (T));
3414 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3416 elsif Has_Unknown_Discriminants (Id) then
3417 Set_Discriminant_Constraint (Id, No_Elist);
3420 if Is_Tagged_Type (T) then
3421 Set_Is_Tagged_Type (Id);
3422 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3423 Set_Primitive_Operations
3424 (Id, Primitive_Operations (T));
3425 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3427 if Is_Interface (T) then
3428 Set_Is_Interface (Id);
3429 Set_Is_Limited_Interface (Id, Is_Limited_Interface (T));
3433 when Private_Kind =>
3434 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3435 Set_Has_Discriminants (Id, Has_Discriminants (T));
3436 Set_Is_Constrained (Id, Is_Constrained (T));
3437 Set_First_Entity (Id, First_Entity (T));
3438 Set_Last_Entity (Id, Last_Entity (T));
3439 Set_Private_Dependents (Id, New_Elmt_List);
3440 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3441 Set_Has_Unknown_Discriminants
3442 (Id, Has_Unknown_Discriminants (T));
3443 Set_Known_To_Have_Preelab_Init
3444 (Id, Known_To_Have_Preelab_Init (T));
3446 if Is_Tagged_Type (T) then
3447 Set_Is_Tagged_Type (Id);
3448 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3449 Set_Primitive_Operations (Id, Primitive_Operations (T));
3450 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3453 -- In general the attributes of the subtype of a private type
3454 -- are the attributes of the partial view of parent. However,
3455 -- the full view may be a discriminated type, and the subtype
3456 -- must share the discriminant constraint to generate correct
3457 -- calls to initialization procedures.
3459 if Has_Discriminants (T) then
3460 Set_Discriminant_Constraint
3461 (Id, Discriminant_Constraint (T));
3462 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3464 elsif Present (Full_View (T))
3465 and then Has_Discriminants (Full_View (T))
3467 Set_Discriminant_Constraint
3468 (Id, Discriminant_Constraint (Full_View (T)));
3469 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3471 -- This would seem semantically correct, but apparently
3472 -- confuses the back-end. To be explained and checked with
3473 -- current version ???
3475 -- Set_Has_Discriminants (Id);
3478 Prepare_Private_Subtype_Completion (Id, N);
3481 Set_Ekind (Id, E_Access_Subtype);
3482 Set_Is_Constrained (Id, Is_Constrained (T));
3483 Set_Is_Access_Constant
3484 (Id, Is_Access_Constant (T));
3485 Set_Directly_Designated_Type
3486 (Id, Designated_Type (T));
3487 Set_Can_Never_Be_Null (Id, Can_Never_Be_Null (T));
3489 -- A Pure library_item must not contain the declaration of a
3490 -- named access type, except within a subprogram, generic
3491 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
3493 if Comes_From_Source (Id)
3494 and then In_Pure_Unit
3495 and then not In_Subprogram_Task_Protected_Unit
3498 ("named access types not allowed in pure unit", N);
3501 when Concurrent_Kind =>
3502 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3503 Set_Corresponding_Record_Type (Id,
3504 Corresponding_Record_Type (T));
3505 Set_First_Entity (Id, First_Entity (T));
3506 Set_First_Private_Entity (Id, First_Private_Entity (T));
3507 Set_Has_Discriminants (Id, Has_Discriminants (T));
3508 Set_Is_Constrained (Id, Is_Constrained (T));
3509 Set_Is_Tagged_Type (Id, Is_Tagged_Type (T));
3510 Set_Last_Entity (Id, Last_Entity (T));
3512 if Has_Discriminants (T) then
3513 Set_Discriminant_Constraint (Id,
3514 Discriminant_Constraint (T));
3515 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3518 when E_Incomplete_Type =>
3519 if Ada_Version >= Ada_05 then
3520 Set_Ekind (Id, E_Incomplete_Subtype);
3522 -- Ada 2005 (AI-412): Decorate an incomplete subtype
3523 -- of an incomplete type visible through a limited
3526 if From_With_Type (T)
3527 and then Present (Non_Limited_View (T))
3529 Set_From_With_Type (Id);
3530 Set_Non_Limited_View (Id, Non_Limited_View (T));
3532 -- Ada 2005 (AI-412): Add the regular incomplete subtype
3533 -- to the private dependents of the original incomplete
3534 -- type for future transformation.
3537 Append_Elmt (Id, Private_Dependents (T));
3540 -- If the subtype name denotes an incomplete type an error
3541 -- was already reported by Process_Subtype.
3544 Set_Etype (Id, Any_Type);
3548 raise Program_Error;
3552 if Etype (Id) = Any_Type then
3556 -- Some common processing on all types
3558 Set_Size_Info (Id, T);
3559 Set_First_Rep_Item (Id, First_Rep_Item (T));
3563 Set_Is_Immediately_Visible (Id, True);
3564 Set_Depends_On_Private (Id, Has_Private_Component (T));
3565 Set_Is_Descendent_Of_Address (Id, Is_Descendent_Of_Address (T));
3567 if Is_Interface (T) then
3568 Set_Is_Interface (Id);
3571 if Present (Generic_Parent_Type (N))
3574 (Parent (Generic_Parent_Type (N))) /= N_Formal_Type_Declaration
3576 (Formal_Type_Definition (Parent (Generic_Parent_Type (N))))
3577 /= N_Formal_Private_Type_Definition)
3579 if Is_Tagged_Type (Id) then
3581 -- If this is a generic actual subtype for a synchronized type,
3582 -- the primitive operations are those of the corresponding record
3583 -- for which there is a separate subtype declaration.
3585 if Is_Concurrent_Type (Id) then
3587 elsif Is_Class_Wide_Type (Id) then
3588 Derive_Subprograms (Generic_Parent_Type (N), Id, Etype (T));
3590 Derive_Subprograms (Generic_Parent_Type (N), Id, T);
3593 elsif Scope (Etype (Id)) /= Standard_Standard then
3594 Derive_Subprograms (Generic_Parent_Type (N), Id);
3598 if Is_Private_Type (T)
3599 and then Present (Full_View (T))
3601 Conditional_Delay (Id, Full_View (T));
3603 -- The subtypes of components or subcomponents of protected types
3604 -- do not need freeze nodes, which would otherwise appear in the
3605 -- wrong scope (before the freeze node for the protected type). The
3606 -- proper subtypes are those of the subcomponents of the corresponding
3609 elsif Ekind (Scope (Id)) /= E_Protected_Type
3610 and then Present (Scope (Scope (Id))) -- error defense!
3611 and then Ekind (Scope (Scope (Id))) /= E_Protected_Type
3613 Conditional_Delay (Id, T);
3616 -- Check that constraint_error is raised for a scalar subtype
3617 -- indication when the lower or upper bound of a non-null range
3618 -- lies outside the range of the type mark.
3620 if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then
3621 if Is_Scalar_Type (Etype (Id))
3622 and then Scalar_Range (Id) /=
3623 Scalar_Range (Etype (Subtype_Mark
3624 (Subtype_Indication (N))))
3628 Etype (Subtype_Mark (Subtype_Indication (N))));
3630 elsif Is_Array_Type (Etype (Id))
3631 and then Present (First_Index (Id))
3633 -- This really should be a subprogram that finds the indications
3636 if ((Nkind (First_Index (Id)) = N_Identifier
3637 and then Ekind (Entity (First_Index (Id))) in Scalar_Kind)
3638 or else Nkind (First_Index (Id)) = N_Subtype_Indication)
3640 Nkind (Scalar_Range (Etype (First_Index (Id)))) = N_Range
3643 Target_Typ : constant Entity_Id :=
3646 (Subtype_Mark (Subtype_Indication (N)))));
3650 (Scalar_Range (Etype (First_Index (Id))),
3652 Etype (First_Index (Id)),
3653 Defining_Identifier (N));
3659 Sloc (Defining_Identifier (N)));
3665 Set_Optimize_Alignment_Flags (Id);
3666 Check_Eliminated (Id);
3667 end Analyze_Subtype_Declaration;
3669 --------------------------------
3670 -- Analyze_Subtype_Indication --
3671 --------------------------------
3673 procedure Analyze_Subtype_Indication (N : Node_Id) is
3674 T : constant Entity_Id := Subtype_Mark (N);
3675 R : constant Node_Id := Range_Expression (Constraint (N));
3682 Set_Etype (N, Etype (R));
3683 Resolve (R, Entity (T));
3685 Set_Error_Posted (R);
3686 Set_Error_Posted (T);
3688 end Analyze_Subtype_Indication;
3690 ------------------------------
3691 -- Analyze_Type_Declaration --
3692 ------------------------------
3694 procedure Analyze_Type_Declaration (N : Node_Id) is
3695 Def : constant Node_Id := Type_Definition (N);
3696 Def_Id : constant Entity_Id := Defining_Identifier (N);
3700 Is_Remote : constant Boolean :=
3701 (Is_Remote_Types (Current_Scope)
3702 or else Is_Remote_Call_Interface (Current_Scope))
3703 and then not (In_Private_Part (Current_Scope)
3704 or else In_Package_Body (Current_Scope));
3706 procedure Check_Ops_From_Incomplete_Type;
3707 -- If there is a tagged incomplete partial view of the type, transfer
3708 -- its operations to the full view, and indicate that the type of the
3709 -- controlling parameter (s) is this full view.
3711 ------------------------------------
3712 -- Check_Ops_From_Incomplete_Type --
3713 ------------------------------------
3715 procedure Check_Ops_From_Incomplete_Type is
3722 and then Ekind (Prev) = E_Incomplete_Type
3723 and then Is_Tagged_Type (Prev)
3724 and then Is_Tagged_Type (T)
3726 Elmt := First_Elmt (Primitive_Operations (Prev));
3727 while Present (Elmt) loop
3729 Prepend_Elmt (Op, Primitive_Operations (T));
3731 Formal := First_Formal (Op);
3732 while Present (Formal) loop
3733 if Etype (Formal) = Prev then
3734 Set_Etype (Formal, T);
3737 Next_Formal (Formal);
3740 if Etype (Op) = Prev then
3747 end Check_Ops_From_Incomplete_Type;
3749 -- Start of processing for Analyze_Type_Declaration
3752 Prev := Find_Type_Name (N);
3754 -- The full view, if present, now points to the current type
3756 -- Ada 2005 (AI-50217): If the type was previously decorated when
3757 -- imported through a LIMITED WITH clause, it appears as incomplete
3758 -- but has no full view.
3759 -- If the incomplete view is tagged, a class_wide type has been
3760 -- created already. Use it for the full view as well, to prevent
3761 -- multiple incompatible class-wide types that may be created for
3762 -- self-referential anonymous access components.
3764 if Ekind (Prev) = E_Incomplete_Type
3765 and then Present (Full_View (Prev))
3767 T := Full_View (Prev);
3769 if Is_Tagged_Type (Prev)
3770 and then Present (Class_Wide_Type (Prev))
3772 Set_Ekind (T, Ekind (Prev)); -- will be reset later
3773 Set_Class_Wide_Type (T, Class_Wide_Type (Prev));
3774 Set_Etype (Class_Wide_Type (T), T);
3781 Set_Is_Pure (T, Is_Pure (Current_Scope));
3783 -- We set the flag Is_First_Subtype here. It is needed to set the
3784 -- corresponding flag for the Implicit class-wide-type created
3785 -- during tagged types processing.
3787 Set_Is_First_Subtype (T, True);
3789 -- Only composite types other than array types are allowed to have
3794 -- For derived types, the rule will be checked once we've figured
3795 -- out the parent type.
3797 when N_Derived_Type_Definition =>
3800 -- For record types, discriminants are allowed
3802 when N_Record_Definition =>
3806 if Present (Discriminant_Specifications (N)) then
3808 ("elementary or array type cannot have discriminants",
3810 (First (Discriminant_Specifications (N))));
3814 -- Elaborate the type definition according to kind, and generate
3815 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3816 -- already done (this happens during the reanalysis that follows a call
3817 -- to the high level optimizer).
3819 if not Analyzed (T) then
3824 when N_Access_To_Subprogram_Definition =>
3825 Access_Subprogram_Declaration (T, Def);
3827 -- If this is a remote access to subprogram, we must create the
3828 -- equivalent fat pointer type, and related subprograms.
3831 Process_Remote_AST_Declaration (N);
3834 -- Validate categorization rule against access type declaration
3835 -- usually a violation in Pure unit, Shared_Passive unit.
3837 Validate_Access_Type_Declaration (T, N);
3839 when N_Access_To_Object_Definition =>
3840 Access_Type_Declaration (T, Def);
3842 -- Validate categorization rule against access type declaration
3843 -- usually a violation in Pure unit, Shared_Passive unit.
3845 Validate_Access_Type_Declaration (T, N);
3847 -- If we are in a Remote_Call_Interface package and define
3848 -- a RACW, Read and Write attribute must be added.
3851 and then Is_Remote_Access_To_Class_Wide_Type (Def_Id)
3853 Add_RACW_Features (Def_Id);
3856 -- Set no strict aliasing flag if config pragma seen
3858 if Opt.No_Strict_Aliasing then
3859 Set_No_Strict_Aliasing (Base_Type (Def_Id));
3862 when N_Array_Type_Definition =>
3863 Array_Type_Declaration (T, Def);
3865 when N_Derived_Type_Definition =>
3866 Derived_Type_Declaration (T, N, T /= Def_Id);
3868 when N_Enumeration_Type_Definition =>
3869 Enumeration_Type_Declaration (T, Def);
3871 when N_Floating_Point_Definition =>
3872 Floating_Point_Type_Declaration (T, Def);
3874 when N_Decimal_Fixed_Point_Definition =>
3875 Decimal_Fixed_Point_Type_Declaration (T, Def);
3877 when N_Ordinary_Fixed_Point_Definition =>
3878 Ordinary_Fixed_Point_Type_Declaration (T, Def);
3880 when N_Signed_Integer_Type_Definition =>
3881 Signed_Integer_Type_Declaration (T, Def);
3883 when N_Modular_Type_Definition =>
3884 Modular_Type_Declaration (T, Def);
3886 when N_Record_Definition =>
3887 Record_Type_Declaration (T, N, Prev);
3890 raise Program_Error;
3895 if Etype (T) = Any_Type then
3899 -- Some common processing for all types
3901 Set_Depends_On_Private (T, Has_Private_Component (T));
3902 Check_Ops_From_Incomplete_Type;
3904 -- Both the declared entity, and its anonymous base type if one
3905 -- was created, need freeze nodes allocated.
3908 B : constant Entity_Id := Base_Type (T);
3911 -- In the case where the base type is different from the first
3912 -- subtype, we pre-allocate a freeze node, and set the proper link
3913 -- to the first subtype. Freeze_Entity will use this preallocated
3914 -- freeze node when it freezes the entity.
3917 Ensure_Freeze_Node (B);
3918 Set_First_Subtype_Link (Freeze_Node (B), T);
3921 if not From_With_Type (T) then
3922 Set_Has_Delayed_Freeze (T);
3926 -- Case of T is the full declaration of some private type which has
3927 -- been swapped in Defining_Identifier (N).
3929 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3930 Process_Full_View (N, T, Def_Id);
3932 -- Record the reference. The form of this is a little strange,
3933 -- since the full declaration has been swapped in. So the first
3934 -- parameter here represents the entity to which a reference is
3935 -- made which is the "real" entity, i.e. the one swapped in,
3936 -- and the second parameter provides the reference location.
3938 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3939 -- since we don't want a complaint about the full type being an
3940 -- unwanted reference to the private type
3943 B : constant Boolean := Has_Pragma_Unreferenced (T);
3945 Set_Has_Pragma_Unreferenced (T, False);
3946 Generate_Reference (T, T, 'c');
3947 Set_Has_Pragma_Unreferenced (T, B);
3950 Set_Completion_Referenced (Def_Id);
3952 -- For completion of incomplete type, process incomplete dependents
3953 -- and always mark the full type as referenced (it is the incomplete
3954 -- type that we get for any real reference).
3956 elsif Ekind (Prev) = E_Incomplete_Type then
3957 Process_Incomplete_Dependents (N, T, Prev);
3958 Generate_Reference (Prev, Def_Id, 'c');
3959 Set_Completion_Referenced (Def_Id);
3961 -- If not private type or incomplete type completion, this is a real
3962 -- definition of a new entity, so record it.
3965 Generate_Definition (Def_Id);
3968 if Chars (Scope (Def_Id)) = Name_System
3969 and then Chars (Def_Id) = Name_Address
3970 and then Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (N)))
3972 Set_Is_Descendent_Of_Address (Def_Id);
3973 Set_Is_Descendent_Of_Address (Base_Type (Def_Id));
3974 Set_Is_Descendent_Of_Address (Prev);
3977 Set_Optimize_Alignment_Flags (Def_Id);
3978 Check_Eliminated (Def_Id);
3979 end Analyze_Type_Declaration;
3981 --------------------------
3982 -- Analyze_Variant_Part --
3983 --------------------------
3985 procedure Analyze_Variant_Part (N : Node_Id) is
3987 procedure Non_Static_Choice_Error (Choice : Node_Id);
3988 -- Error routine invoked by the generic instantiation below when
3989 -- the variant part has a non static choice.
3991 procedure Process_Declarations (Variant : Node_Id);
3992 -- Analyzes all the declarations associated with a Variant.
3993 -- Needed by the generic instantiation below.
3995 package Variant_Choices_Processing is new
3996 Generic_Choices_Processing
3997 (Get_Alternatives => Variants,
3998 Get_Choices => Discrete_Choices,
3999 Process_Empty_Choice => No_OP,
4000 Process_Non_Static_Choice => Non_Static_Choice_Error,
4001 Process_Associated_Node => Process_Declarations);
4002 use Variant_Choices_Processing;
4003 -- Instantiation of the generic choice processing package
4005 -----------------------------
4006 -- Non_Static_Choice_Error --
4007 -----------------------------
4009 procedure Non_Static_Choice_Error (Choice : Node_Id) is
4011 Flag_Non_Static_Expr
4012 ("choice given in variant part is not static!", Choice);
4013 end Non_Static_Choice_Error;
4015 --------------------------
4016 -- Process_Declarations --
4017 --------------------------
4019 procedure Process_Declarations (Variant : Node_Id) is
4021 if not Null_Present (Component_List (Variant)) then
4022 Analyze_Declarations (Component_Items (Component_List (Variant)));
4024 if Present (Variant_Part (Component_List (Variant))) then
4025 Analyze (Variant_Part (Component_List (Variant)));
4028 end Process_Declarations;
4032 Discr_Name : Node_Id;
4033 Discr_Type : Entity_Id;
4035 Case_Table : Choice_Table_Type (1 .. Number_Of_Choices (N));
4037 Dont_Care : Boolean;
4038 Others_Present : Boolean := False;
4040 pragma Warnings (Off, Case_Table);
4041 pragma Warnings (Off, Last_Choice);
4042 pragma Warnings (Off, Dont_Care);
4043 pragma Warnings (Off, Others_Present);
4044 -- We don't care about the assigned values of any of these
4046 -- Start of processing for Analyze_Variant_Part
4049 Discr_Name := Name (N);
4050 Analyze (Discr_Name);
4052 -- If Discr_Name bad, get out (prevent cascaded errors)
4054 if Etype (Discr_Name) = Any_Type then
4058 -- Check invalid discriminant in variant part
4060 if Ekind (Entity (Discr_Name)) /= E_Discriminant then
4061 Error_Msg_N ("invalid discriminant name in variant part", Discr_Name);
4064 Discr_Type := Etype (Entity (Discr_Name));
4066 if not Is_Discrete_Type (Discr_Type) then
4068 ("discriminant in a variant part must be of a discrete type",
4073 -- Call the instantiated Analyze_Choices which does the rest of the work
4076 (N, Discr_Type, Case_Table, Last_Choice, Dont_Care, Others_Present);
4077 end Analyze_Variant_Part;
4079 ----------------------------
4080 -- Array_Type_Declaration --
4081 ----------------------------
4083 procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id) is
4084 Component_Def : constant Node_Id := Component_Definition (Def);
4085 Element_Type : Entity_Id;
4086 Implicit_Base : Entity_Id;
4088 Related_Id : Entity_Id := Empty;
4090 P : constant Node_Id := Parent (Def);
4094 if Nkind (Def) = N_Constrained_Array_Definition then
4095 Index := First (Discrete_Subtype_Definitions (Def));
4097 Index := First (Subtype_Marks (Def));
4100 -- Find proper names for the implicit types which may be public.
4101 -- in case of anonymous arrays we use the name of the first object
4102 -- of that type as prefix.
4105 Related_Id := Defining_Identifier (P);
4111 while Present (Index) loop
4114 -- Add a subtype declaration for each index of private array type
4115 -- declaration whose etype is also private. For example:
4118 -- type Index is private;
4120 -- type Table is array (Index) of ...
4123 -- This is currently required by the expander to generate the
4124 -- internally generated equality subprogram of records with variant
4125 -- parts in which the etype of some component is such private type.
4127 if Ekind (Current_Scope) = E_Package
4128 and then In_Private_Part (Current_Scope)
4129 and then Has_Private_Declaration (Etype (Index))
4132 Loc : constant Source_Ptr := Sloc (Def);
4138 Make_Defining_Identifier (Loc,
4139 Chars => New_Internal_Name ('T'));
4140 Set_Is_Internal (New_E);
4143 Make_Subtype_Declaration (Loc,
4144 Defining_Identifier => New_E,
4145 Subtype_Indication =>
4146 New_Occurrence_Of (Etype (Index), Loc));
4148 Insert_Before (Parent (Def), Decl);
4150 Set_Etype (Index, New_E);
4152 -- If the index is a range the Entity attribute is not
4153 -- available. Example:
4156 -- type T is private;
4158 -- type T is new Natural;
4159 -- Table : array (T(1) .. T(10)) of Boolean;
4162 if Nkind (Index) /= N_Range then
4163 Set_Entity (Index, New_E);
4168 Make_Index (Index, P, Related_Id, Nb_Index);
4170 Nb_Index := Nb_Index + 1;
4173 -- Process subtype indication if one is present
4175 if Present (Subtype_Indication (Component_Def)) then
4178 (Subtype_Indication (Component_Def), P, Related_Id, 'C');
4180 -- Ada 2005 (AI-230): Access Definition case
4182 else pragma Assert (Present (Access_Definition (Component_Def)));
4184 -- Indicate that the anonymous access type is created by the
4185 -- array type declaration.
4187 Element_Type := Access_Definition
4189 N => Access_Definition (Component_Def));
4190 Set_Is_Local_Anonymous_Access (Element_Type);
4192 -- Propagate the parent. This field is needed if we have to generate
4193 -- the master_id associated with an anonymous access to task type
4194 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
4196 Set_Parent (Element_Type, Parent (T));
4198 -- Ada 2005 (AI-230): In case of components that are anonymous
4199 -- access types the level of accessibility depends on the enclosing
4202 Set_Scope (Element_Type, Current_Scope); -- Ada 2005 (AI-230)
4204 -- Ada 2005 (AI-254)
4207 CD : constant Node_Id :=
4208 Access_To_Subprogram_Definition
4209 (Access_Definition (Component_Def));
4211 if Present (CD) and then Protected_Present (CD) then
4213 Replace_Anonymous_Access_To_Protected_Subprogram (Def);
4218 -- Constrained array case
4221 T := Create_Itype (E_Void, P, Related_Id, 'T');
4224 if Nkind (Def) = N_Constrained_Array_Definition then
4226 -- Establish Implicit_Base as unconstrained base type
4228 Implicit_Base := Create_Itype (E_Array_Type, P, Related_Id, 'B');
4230 Set_Etype (Implicit_Base, Implicit_Base);
4231 Set_Scope (Implicit_Base, Current_Scope);
4232 Set_Has_Delayed_Freeze (Implicit_Base);
4234 -- The constrained array type is a subtype of the unconstrained one
4236 Set_Ekind (T, E_Array_Subtype);
4237 Init_Size_Align (T);
4238 Set_Etype (T, Implicit_Base);
4239 Set_Scope (T, Current_Scope);
4240 Set_Is_Constrained (T, True);
4241 Set_First_Index (T, First (Discrete_Subtype_Definitions (Def)));
4242 Set_Has_Delayed_Freeze (T);
4244 -- Complete setup of implicit base type
4246 Set_First_Index (Implicit_Base, First_Index (T));
4247 Set_Component_Type (Implicit_Base, Element_Type);
4248 Set_Has_Task (Implicit_Base, Has_Task (Element_Type));
4249 Set_Component_Size (Implicit_Base, Uint_0);
4250 Set_Packed_Array_Type (Implicit_Base, Empty);
4251 Set_Has_Controlled_Component
4252 (Implicit_Base, Has_Controlled_Component
4254 or else Is_Controlled
4256 Set_Finalize_Storage_Only
4257 (Implicit_Base, Finalize_Storage_Only
4260 -- Unconstrained array case
4263 Set_Ekind (T, E_Array_Type);
4264 Init_Size_Align (T);
4266 Set_Scope (T, Current_Scope);
4267 Set_Component_Size (T, Uint_0);
4268 Set_Is_Constrained (T, False);
4269 Set_First_Index (T, First (Subtype_Marks (Def)));
4270 Set_Has_Delayed_Freeze (T, True);
4271 Set_Has_Task (T, Has_Task (Element_Type));
4272 Set_Has_Controlled_Component (T, Has_Controlled_Component
4275 Is_Controlled (Element_Type));
4276 Set_Finalize_Storage_Only (T, Finalize_Storage_Only
4280 -- Common attributes for both cases
4282 Set_Component_Type (Base_Type (T), Element_Type);
4283 Set_Packed_Array_Type (T, Empty);
4285 if Aliased_Present (Component_Definition (Def)) then
4286 Set_Has_Aliased_Components (Etype (T));
4289 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
4290 -- array type to ensure that objects of this type are initialized.
4292 if Ada_Version >= Ada_05
4293 and then Can_Never_Be_Null (Element_Type)
4295 Set_Can_Never_Be_Null (T);
4297 if Null_Exclusion_Present (Component_Definition (Def))
4299 -- No need to check itypes because in their case this check
4300 -- was done at their point of creation
4302 and then not Is_Itype (Element_Type)
4305 ("`NOT NULL` not allowed (null already excluded)",
4306 Subtype_Indication (Component_Definition (Def)));
4310 Priv := Private_Component (Element_Type);
4312 if Present (Priv) then
4314 -- Check for circular definitions
4316 if Priv = Any_Type then
4317 Set_Component_Type (Etype (T), Any_Type);
4319 -- There is a gap in the visibility of operations on the composite
4320 -- type only if the component type is defined in a different scope.
4322 elsif Scope (Priv) = Current_Scope then
4325 elsif Is_Limited_Type (Priv) then
4326 Set_Is_Limited_Composite (Etype (T));
4327 Set_Is_Limited_Composite (T);
4329 Set_Is_Private_Composite (Etype (T));
4330 Set_Is_Private_Composite (T);
4334 -- A syntax error in the declaration itself may lead to an empty
4335 -- index list, in which case do a minimal patch.
4337 if No (First_Index (T)) then
4338 Error_Msg_N ("missing index definition in array type declaration", T);
4341 Indices : constant List_Id :=
4342 New_List (New_Occurrence_Of (Any_Id, Sloc (T)));
4344 Set_Discrete_Subtype_Definitions (Def, Indices);
4345 Set_First_Index (T, First (Indices));
4350 -- Create a concatenation operator for the new type. Internal array
4351 -- types created for packed entities do not need such, they are
4352 -- compatible with the user-defined type.
4354 if Number_Dimensions (T) = 1
4355 and then not Is_Packed_Array_Type (T)
4357 New_Concatenation_Op (T);
4360 -- In the case of an unconstrained array the parser has already verified
4361 -- that all the indices are unconstrained but we still need to make sure
4362 -- that the element type is constrained.
4364 if Is_Indefinite_Subtype (Element_Type) then
4366 ("unconstrained element type in array declaration",
4367 Subtype_Indication (Component_Def));
4369 elsif Is_Abstract_Type (Element_Type) then
4371 ("the type of a component cannot be abstract",
4372 Subtype_Indication (Component_Def));
4374 end Array_Type_Declaration;
4376 ------------------------------------------------------
4377 -- Replace_Anonymous_Access_To_Protected_Subprogram --
4378 ------------------------------------------------------
4380 function Replace_Anonymous_Access_To_Protected_Subprogram
4381 (N : Node_Id) return Entity_Id
4383 Loc : constant Source_Ptr := Sloc (N);
4385 Curr_Scope : constant Scope_Stack_Entry :=
4386 Scope_Stack.Table (Scope_Stack.Last);
4388 Anon : constant Entity_Id :=
4389 Make_Defining_Identifier (Loc,
4390 Chars => New_Internal_Name ('S'));
4398 Set_Is_Internal (Anon);
4401 when N_Component_Declaration |
4402 N_Unconstrained_Array_Definition |
4403 N_Constrained_Array_Definition =>
4404 Comp := Component_Definition (N);
4405 Acc := Access_Definition (Comp);
4407 when N_Discriminant_Specification =>
4408 Comp := Discriminant_Type (N);
4411 when N_Parameter_Specification =>
4412 Comp := Parameter_Type (N);
4415 when N_Access_Function_Definition =>
4416 Comp := Result_Definition (N);
4419 when N_Object_Declaration =>
4420 Comp := Object_Definition (N);
4424 raise Program_Error;
4427 Decl := Make_Full_Type_Declaration (Loc,
4428 Defining_Identifier => Anon,
4430 Copy_Separate_Tree (Access_To_Subprogram_Definition (Acc)));
4432 Mark_Rewrite_Insertion (Decl);
4434 -- Insert the new declaration in the nearest enclosing scope
4437 while Present (P) and then not Has_Declarations (P) loop
4441 pragma Assert (Present (P));
4443 if Nkind (P) = N_Package_Specification then
4444 Prepend (Decl, Visible_Declarations (P));
4446 Prepend (Decl, Declarations (P));
4449 -- Replace the anonymous type with an occurrence of the new declaration.
4450 -- In all cases the rewritten node does not have the null-exclusion
4451 -- attribute because (if present) it was already inherited by the
4452 -- anonymous entity (Anon). Thus, in case of components we do not
4453 -- inherit this attribute.
4455 if Nkind (N) = N_Parameter_Specification then
4456 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4457 Set_Etype (Defining_Identifier (N), Anon);
4458 Set_Null_Exclusion_Present (N, False);
4460 elsif Nkind (N) = N_Object_Declaration then
4461 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4462 Set_Etype (Defining_Identifier (N), Anon);
4464 elsif Nkind (N) = N_Access_Function_Definition then
4465 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4469 Make_Component_Definition (Loc,
4470 Subtype_Indication => New_Occurrence_Of (Anon, Loc)));
4473 Mark_Rewrite_Insertion (Comp);
4475 -- Temporarily remove the current scope from the stack to add the new
4476 -- declarations to the enclosing scope
4478 if Nkind_In (N, N_Object_Declaration, N_Access_Function_Definition) then
4482 Scope_Stack.Decrement_Last;
4484 Set_Is_Itype (Anon);
4485 Scope_Stack.Append (Curr_Scope);
4488 Set_Ekind (Anon, E_Anonymous_Access_Protected_Subprogram_Type);
4489 Set_Can_Use_Internal_Rep (Anon, not Always_Compatible_Rep_On_Target);
4491 end Replace_Anonymous_Access_To_Protected_Subprogram;
4493 -------------------------------
4494 -- Build_Derived_Access_Type --
4495 -------------------------------
4497 procedure Build_Derived_Access_Type
4499 Parent_Type : Entity_Id;
4500 Derived_Type : Entity_Id)
4502 S : constant Node_Id := Subtype_Indication (Type_Definition (N));
4504 Desig_Type : Entity_Id;
4506 Discr_Con_Elist : Elist_Id;
4507 Discr_Con_El : Elmt_Id;
4511 -- Set the designated type so it is available in case this is an access
4512 -- to a self-referential type, e.g. a standard list type with a next
4513 -- pointer. Will be reset after subtype is built.
4515 Set_Directly_Designated_Type
4516 (Derived_Type, Designated_Type (Parent_Type));
4518 Subt := Process_Subtype (S, N);
4520 if Nkind (S) /= N_Subtype_Indication
4521 and then Subt /= Base_Type (Subt)
4523 Set_Ekind (Derived_Type, E_Access_Subtype);
4526 if Ekind (Derived_Type) = E_Access_Subtype then
4528 Pbase : constant Entity_Id := Base_Type (Parent_Type);
4529 Ibase : constant Entity_Id :=
4530 Create_Itype (Ekind (Pbase), N, Derived_Type, 'B');
4531 Svg_Chars : constant Name_Id := Chars (Ibase);
4532 Svg_Next_E : constant Entity_Id := Next_Entity (Ibase);
4535 Copy_Node (Pbase, Ibase);
4537 Set_Chars (Ibase, Svg_Chars);
4538 Set_Next_Entity (Ibase, Svg_Next_E);
4539 Set_Sloc (Ibase, Sloc (Derived_Type));
4540 Set_Scope (Ibase, Scope (Derived_Type));
4541 Set_Freeze_Node (Ibase, Empty);
4542 Set_Is_Frozen (Ibase, False);
4543 Set_Comes_From_Source (Ibase, False);
4544 Set_Is_First_Subtype (Ibase, False);
4546 Set_Etype (Ibase, Pbase);
4547 Set_Etype (Derived_Type, Ibase);
4551 Set_Directly_Designated_Type
4552 (Derived_Type, Designated_Type (Subt));
4554 Set_Is_Constrained (Derived_Type, Is_Constrained (Subt));
4555 Set_Is_Access_Constant (Derived_Type, Is_Access_Constant (Parent_Type));
4556 Set_Size_Info (Derived_Type, Parent_Type);
4557 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
4558 Set_Depends_On_Private (Derived_Type,
4559 Has_Private_Component (Derived_Type));
4560 Conditional_Delay (Derived_Type, Subt);
4562 -- Ada 2005 (AI-231). Set the null-exclusion attribute
4564 if Null_Exclusion_Present (Type_Definition (N))
4565 or else Can_Never_Be_Null (Parent_Type)
4567 Set_Can_Never_Be_Null (Derived_Type);
4570 -- Note: we do not copy the Storage_Size_Variable, since we always go to
4571 -- the root type for this information.
4573 -- Apply range checks to discriminants for derived record case
4574 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
4576 Desig_Type := Designated_Type (Derived_Type);
4577 if Is_Composite_Type (Desig_Type)
4578 and then (not Is_Array_Type (Desig_Type))
4579 and then Has_Discriminants (Desig_Type)
4580 and then Base_Type (Desig_Type) /= Desig_Type
4582 Discr_Con_Elist := Discriminant_Constraint (Desig_Type);
4583 Discr_Con_El := First_Elmt (Discr_Con_Elist);
4585 Discr := First_Discriminant (Base_Type (Desig_Type));
4586 while Present (Discr_Con_El) loop
4587 Apply_Range_Check (Node (Discr_Con_El), Etype (Discr));
4588 Next_Elmt (Discr_Con_El);
4589 Next_Discriminant (Discr);
4592 end Build_Derived_Access_Type;
4594 ------------------------------
4595 -- Build_Derived_Array_Type --
4596 ------------------------------
4598 procedure Build_Derived_Array_Type
4600 Parent_Type : Entity_Id;
4601 Derived_Type : Entity_Id)
4603 Loc : constant Source_Ptr := Sloc (N);
4604 Tdef : constant Node_Id := Type_Definition (N);
4605 Indic : constant Node_Id := Subtype_Indication (Tdef);
4606 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
4607 Implicit_Base : Entity_Id;
4608 New_Indic : Node_Id;
4610 procedure Make_Implicit_Base;
4611 -- If the parent subtype is constrained, the derived type is a subtype
4612 -- of an implicit base type derived from the parent base.
4614 ------------------------
4615 -- Make_Implicit_Base --
4616 ------------------------
4618 procedure Make_Implicit_Base is
4621 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
4623 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
4624 Set_Etype (Implicit_Base, Parent_Base);
4626 Copy_Array_Subtype_Attributes (Implicit_Base, Parent_Base);
4627 Copy_Array_Base_Type_Attributes (Implicit_Base, Parent_Base);
4629 Set_Has_Delayed_Freeze (Implicit_Base, True);
4630 end Make_Implicit_Base;
4632 -- Start of processing for Build_Derived_Array_Type
4635 if not Is_Constrained (Parent_Type) then
4636 if Nkind (Indic) /= N_Subtype_Indication then
4637 Set_Ekind (Derived_Type, E_Array_Type);
4639 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4640 Copy_Array_Base_Type_Attributes (Derived_Type, Parent_Type);
4642 Set_Has_Delayed_Freeze (Derived_Type, True);
4646 Set_Etype (Derived_Type, Implicit_Base);
4649 Make_Subtype_Declaration (Loc,
4650 Defining_Identifier => Derived_Type,
4651 Subtype_Indication =>
4652 Make_Subtype_Indication (Loc,
4653 Subtype_Mark => New_Reference_To (Implicit_Base, Loc),
4654 Constraint => Constraint (Indic)));
4656 Rewrite (N, New_Indic);
4661 if Nkind (Indic) /= N_Subtype_Indication then
4664 Set_Ekind (Derived_Type, Ekind (Parent_Type));
4665 Set_Etype (Derived_Type, Implicit_Base);
4666 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4669 Error_Msg_N ("illegal constraint on constrained type", Indic);
4673 -- If parent type is not a derived type itself, and is declared in
4674 -- closed scope (e.g. a subprogram), then we must explicitly introduce
4675 -- the new type's concatenation operator since Derive_Subprograms
4676 -- will not inherit the parent's operator. If the parent type is
4677 -- unconstrained, the operator is of the unconstrained base type.
4679 if Number_Dimensions (Parent_Type) = 1
4680 and then not Is_Limited_Type (Parent_Type)
4681 and then not Is_Derived_Type (Parent_Type)
4682 and then not Is_Package_Or_Generic_Package
4683 (Scope (Base_Type (Parent_Type)))
4685 if not Is_Constrained (Parent_Type)
4686 and then Is_Constrained (Derived_Type)
4688 New_Concatenation_Op (Implicit_Base);
4690 New_Concatenation_Op (Derived_Type);
4693 end Build_Derived_Array_Type;
4695 -----------------------------------
4696 -- Build_Derived_Concurrent_Type --
4697 -----------------------------------
4699 procedure Build_Derived_Concurrent_Type
4701 Parent_Type : Entity_Id;
4702 Derived_Type : Entity_Id)
4704 D_Constraint : Node_Id;
4705 Disc_Spec : Node_Id;
4706 Old_Disc : Entity_Id;
4707 New_Disc : Entity_Id;
4709 Constraint_Present : constant Boolean :=
4710 Nkind (Subtype_Indication (Type_Definition (N)))
4711 = N_Subtype_Indication;
4714 Set_Stored_Constraint (Derived_Type, No_Elist);
4716 -- Copy Storage_Size and Relative_Deadline variables if task case
4718 if Is_Task_Type (Parent_Type) then
4719 Set_Storage_Size_Variable (Derived_Type,
4720 Storage_Size_Variable (Parent_Type));
4721 Set_Relative_Deadline_Variable (Derived_Type,
4722 Relative_Deadline_Variable (Parent_Type));
4725 if Present (Discriminant_Specifications (N)) then
4726 Push_Scope (Derived_Type);
4727 Check_Or_Process_Discriminants (N, Derived_Type);
4730 elsif Constraint_Present then
4732 -- Build constrained subtype and derive from it
4735 Loc : constant Source_Ptr := Sloc (N);
4736 Anon : constant Entity_Id :=
4737 Make_Defining_Identifier (Loc,
4738 New_External_Name (Chars (Derived_Type), 'T'));
4743 Make_Subtype_Declaration (Loc,
4744 Defining_Identifier => Anon,
4745 Subtype_Indication =>
4746 Subtype_Indication (Type_Definition (N)));
4747 Insert_Before (N, Decl);
4750 Rewrite (Subtype_Indication (Type_Definition (N)),
4751 New_Occurrence_Of (Anon, Loc));
4752 Set_Analyzed (Derived_Type, False);
4758 -- All attributes are inherited from parent. In particular,
4759 -- entries and the corresponding record type are the same.
4760 -- Discriminants may be renamed, and must be treated separately.
4762 Set_Has_Discriminants
4763 (Derived_Type, Has_Discriminants (Parent_Type));
4764 Set_Corresponding_Record_Type
4765 (Derived_Type, Corresponding_Record_Type (Parent_Type));
4767 -- Is_Constrained is set according the parent subtype, but is set to
4768 -- False if the derived type is declared with new discriminants.
4772 (Is_Constrained (Parent_Type) or else Constraint_Present)
4773 and then not Present (Discriminant_Specifications (N)));
4775 if Constraint_Present then
4776 if not Has_Discriminants (Parent_Type) then
4777 Error_Msg_N ("untagged parent must have discriminants", N);
4779 elsif Present (Discriminant_Specifications (N)) then
4781 -- Verify that new discriminants are used to constrain old ones
4786 (Constraint (Subtype_Indication (Type_Definition (N)))));
4788 Old_Disc := First_Discriminant (Parent_Type);
4789 New_Disc := First_Discriminant (Derived_Type);
4790 Disc_Spec := First (Discriminant_Specifications (N));
4791 while Present (Old_Disc) and then Present (Disc_Spec) loop
4792 if Nkind (Discriminant_Type (Disc_Spec)) /=
4795 Analyze (Discriminant_Type (Disc_Spec));
4797 if not Subtypes_Statically_Compatible (
4798 Etype (Discriminant_Type (Disc_Spec)),
4802 ("not statically compatible with parent discriminant",
4803 Discriminant_Type (Disc_Spec));
4807 if Nkind (D_Constraint) = N_Identifier
4808 and then Chars (D_Constraint) /=
4809 Chars (Defining_Identifier (Disc_Spec))
4811 Error_Msg_N ("new discriminants must constrain old ones",
4814 Set_Corresponding_Discriminant (New_Disc, Old_Disc);
4817 Next_Discriminant (Old_Disc);
4818 Next_Discriminant (New_Disc);
4822 if Present (Old_Disc) or else Present (Disc_Spec) then
4823 Error_Msg_N ("discriminant mismatch in derivation", N);
4828 elsif Present (Discriminant_Specifications (N)) then
4830 ("missing discriminant constraint in untagged derivation",
4834 if Present (Discriminant_Specifications (N)) then
4835 Old_Disc := First_Discriminant (Parent_Type);
4836 while Present (Old_Disc) loop
4838 if No (Next_Entity (Old_Disc))
4839 or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant
4841 Set_Next_Entity (Last_Entity (Derived_Type),
4842 Next_Entity (Old_Disc));
4846 Next_Discriminant (Old_Disc);
4850 Set_First_Entity (Derived_Type, First_Entity (Parent_Type));
4851 if Has_Discriminants (Parent_Type) then
4852 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
4853 Set_Discriminant_Constraint (
4854 Derived_Type, Discriminant_Constraint (Parent_Type));
4858 Set_Last_Entity (Derived_Type, Last_Entity (Parent_Type));
4860 Set_Has_Completion (Derived_Type);
4861 end Build_Derived_Concurrent_Type;
4863 ------------------------------------
4864 -- Build_Derived_Enumeration_Type --
4865 ------------------------------------
4867 procedure Build_Derived_Enumeration_Type
4869 Parent_Type : Entity_Id;
4870 Derived_Type : Entity_Id)
4872 Loc : constant Source_Ptr := Sloc (N);
4873 Def : constant Node_Id := Type_Definition (N);
4874 Indic : constant Node_Id := Subtype_Indication (Def);
4875 Implicit_Base : Entity_Id;
4876 Literal : Entity_Id;
4877 New_Lit : Entity_Id;
4878 Literals_List : List_Id;
4879 Type_Decl : Node_Id;
4881 Rang_Expr : Node_Id;
4884 -- Since types Standard.Character and Standard.Wide_Character do
4885 -- not have explicit literals lists we need to process types derived
4886 -- from them specially. This is handled by Derived_Standard_Character.
4887 -- If the parent type is a generic type, there are no literals either,
4888 -- and we construct the same skeletal representation as for the generic
4891 if Is_Standard_Character_Type (Parent_Type) then
4892 Derived_Standard_Character (N, Parent_Type, Derived_Type);
4894 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
4901 Make_Attribute_Reference (Loc,
4902 Attribute_Name => Name_First,
4903 Prefix => New_Reference_To (Derived_Type, Loc));
4904 Set_Etype (Lo, Derived_Type);
4907 Make_Attribute_Reference (Loc,
4908 Attribute_Name => Name_Last,
4909 Prefix => New_Reference_To (Derived_Type, Loc));
4910 Set_Etype (Hi, Derived_Type);
4912 Set_Scalar_Range (Derived_Type,
4919 -- If a constraint is present, analyze the bounds to catch
4920 -- premature usage of the derived literals.
4922 if Nkind (Indic) = N_Subtype_Indication
4923 and then Nkind (Range_Expression (Constraint (Indic))) = N_Range
4925 Analyze (Low_Bound (Range_Expression (Constraint (Indic))));
4926 Analyze (High_Bound (Range_Expression (Constraint (Indic))));
4929 -- Introduce an implicit base type for the derived type even if there
4930 -- is no constraint attached to it, since this seems closer to the
4931 -- Ada semantics. Build a full type declaration tree for the derived
4932 -- type using the implicit base type as the defining identifier. The
4933 -- build a subtype declaration tree which applies the constraint (if
4934 -- any) have it replace the derived type declaration.
4936 Literal := First_Literal (Parent_Type);
4937 Literals_List := New_List;
4938 while Present (Literal)
4939 and then Ekind (Literal) = E_Enumeration_Literal
4941 -- Literals of the derived type have the same representation as
4942 -- those of the parent type, but this representation can be
4943 -- overridden by an explicit representation clause. Indicate
4944 -- that there is no explicit representation given yet. These
4945 -- derived literals are implicit operations of the new type,
4946 -- and can be overridden by explicit ones.
4948 if Nkind (Literal) = N_Defining_Character_Literal then
4950 Make_Defining_Character_Literal (Loc, Chars (Literal));
4952 New_Lit := Make_Defining_Identifier (Loc, Chars (Literal));
4955 Set_Ekind (New_Lit, E_Enumeration_Literal);
4956 Set_Enumeration_Pos (New_Lit, Enumeration_Pos (Literal));
4957 Set_Enumeration_Rep (New_Lit, Enumeration_Rep (Literal));
4958 Set_Enumeration_Rep_Expr (New_Lit, Empty);
4959 Set_Alias (New_Lit, Literal);
4960 Set_Is_Known_Valid (New_Lit, True);
4962 Append (New_Lit, Literals_List);
4963 Next_Literal (Literal);
4967 Make_Defining_Identifier (Sloc (Derived_Type),
4968 New_External_Name (Chars (Derived_Type), 'B'));
4970 -- Indicate the proper nature of the derived type. This must be done
4971 -- before analysis of the literals, to recognize cases when a literal
4972 -- may be hidden by a previous explicit function definition (cf.
4975 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
4976 Set_Etype (Derived_Type, Implicit_Base);
4979 Make_Full_Type_Declaration (Loc,
4980 Defining_Identifier => Implicit_Base,
4981 Discriminant_Specifications => No_List,
4983 Make_Enumeration_Type_Definition (Loc, Literals_List));
4985 Mark_Rewrite_Insertion (Type_Decl);
4986 Insert_Before (N, Type_Decl);
4987 Analyze (Type_Decl);
4989 -- After the implicit base is analyzed its Etype needs to be changed
4990 -- to reflect the fact that it is derived from the parent type which
4991 -- was ignored during analysis. We also set the size at this point.
4993 Set_Etype (Implicit_Base, Parent_Type);
4995 Set_Size_Info (Implicit_Base, Parent_Type);
4996 Set_RM_Size (Implicit_Base, RM_Size (Parent_Type));
4997 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Type));
4999 Set_Has_Non_Standard_Rep
5000 (Implicit_Base, Has_Non_Standard_Rep
5002 Set_Has_Delayed_Freeze (Implicit_Base);
5004 -- Process the subtype indication including a validation check on the
5005 -- constraint, if any. If a constraint is given, its bounds must be
5006 -- implicitly converted to the new type.
5008 if Nkind (Indic) = N_Subtype_Indication then
5010 R : constant Node_Id :=
5011 Range_Expression (Constraint (Indic));
5014 if Nkind (R) = N_Range then
5015 Hi := Build_Scalar_Bound
5016 (High_Bound (R), Parent_Type, Implicit_Base);
5017 Lo := Build_Scalar_Bound
5018 (Low_Bound (R), Parent_Type, Implicit_Base);
5021 -- Constraint is a Range attribute. Replace with explicit
5022 -- mention of the bounds of the prefix, which must be a
5025 Analyze (Prefix (R));
5027 Convert_To (Implicit_Base,
5028 Make_Attribute_Reference (Loc,
5029 Attribute_Name => Name_Last,
5031 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5034 Convert_To (Implicit_Base,
5035 Make_Attribute_Reference (Loc,
5036 Attribute_Name => Name_First,
5038 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5045 (Type_High_Bound (Parent_Type),
5046 Parent_Type, Implicit_Base);
5049 (Type_Low_Bound (Parent_Type),
5050 Parent_Type, Implicit_Base);
5058 -- If we constructed a default range for the case where no range
5059 -- was given, then the expressions in the range must not freeze
5060 -- since they do not correspond to expressions in the source.
5062 if Nkind (Indic) /= N_Subtype_Indication then
5063 Set_Must_Not_Freeze (Lo);
5064 Set_Must_Not_Freeze (Hi);
5065 Set_Must_Not_Freeze (Rang_Expr);
5069 Make_Subtype_Declaration (Loc,
5070 Defining_Identifier => Derived_Type,
5071 Subtype_Indication =>
5072 Make_Subtype_Indication (Loc,
5073 Subtype_Mark => New_Occurrence_Of (Implicit_Base, Loc),
5075 Make_Range_Constraint (Loc,
5076 Range_Expression => Rang_Expr))));
5080 -- If pragma Discard_Names applies on the first subtype of the parent
5081 -- type, then it must be applied on this subtype as well.
5083 if Einfo.Discard_Names (First_Subtype (Parent_Type)) then
5084 Set_Discard_Names (Derived_Type);
5087 -- Apply a range check. Since this range expression doesn't have an
5088 -- Etype, we have to specifically pass the Source_Typ parameter. Is
5091 if Nkind (Indic) = N_Subtype_Indication then
5092 Apply_Range_Check (Range_Expression (Constraint (Indic)),
5094 Source_Typ => Entity (Subtype_Mark (Indic)));
5097 end Build_Derived_Enumeration_Type;
5099 --------------------------------
5100 -- Build_Derived_Numeric_Type --
5101 --------------------------------
5103 procedure Build_Derived_Numeric_Type
5105 Parent_Type : Entity_Id;
5106 Derived_Type : Entity_Id)
5108 Loc : constant Source_Ptr := Sloc (N);
5109 Tdef : constant Node_Id := Type_Definition (N);
5110 Indic : constant Node_Id := Subtype_Indication (Tdef);
5111 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
5112 No_Constraint : constant Boolean := Nkind (Indic) /=
5113 N_Subtype_Indication;
5114 Implicit_Base : Entity_Id;
5120 -- Process the subtype indication including a validation check on
5121 -- the constraint if any.
5123 Discard_Node (Process_Subtype (Indic, N));
5125 -- Introduce an implicit base type for the derived type even if there
5126 -- is no constraint attached to it, since this seems closer to the Ada
5130 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
5132 Set_Etype (Implicit_Base, Parent_Base);
5133 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
5134 Set_Size_Info (Implicit_Base, Parent_Base);
5135 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Base));
5136 Set_Parent (Implicit_Base, Parent (Derived_Type));
5138 -- Set RM Size for discrete type or decimal fixed-point type
5139 -- Ordinary fixed-point is excluded, why???
5141 if Is_Discrete_Type (Parent_Base)
5142 or else Is_Decimal_Fixed_Point_Type (Parent_Base)
5144 Set_RM_Size (Implicit_Base, RM_Size (Parent_Base));
5147 Set_Has_Delayed_Freeze (Implicit_Base);
5149 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
5150 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
5152 Set_Scalar_Range (Implicit_Base,
5157 if Has_Infinities (Parent_Base) then
5158 Set_Includes_Infinities (Scalar_Range (Implicit_Base));
5161 -- The Derived_Type, which is the entity of the declaration, is a
5162 -- subtype of the implicit base. Its Ekind is a subtype, even in the
5163 -- absence of an explicit constraint.
5165 Set_Etype (Derived_Type, Implicit_Base);
5167 -- If we did not have a constraint, then the Ekind is set from the
5168 -- parent type (otherwise Process_Subtype has set the bounds)
5170 if No_Constraint then
5171 Set_Ekind (Derived_Type, Subtype_Kind (Ekind (Parent_Type)));
5174 -- If we did not have a range constraint, then set the range from the
5175 -- parent type. Otherwise, the call to Process_Subtype has set the
5179 or else not Has_Range_Constraint (Indic)
5181 Set_Scalar_Range (Derived_Type,
5183 Low_Bound => New_Copy_Tree (Type_Low_Bound (Parent_Type)),
5184 High_Bound => New_Copy_Tree (Type_High_Bound (Parent_Type))));
5185 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5187 if Has_Infinities (Parent_Type) then
5188 Set_Includes_Infinities (Scalar_Range (Derived_Type));
5192 Set_Is_Descendent_Of_Address (Derived_Type,
5193 Is_Descendent_Of_Address (Parent_Type));
5194 Set_Is_Descendent_Of_Address (Implicit_Base,
5195 Is_Descendent_Of_Address (Parent_Type));
5197 -- Set remaining type-specific fields, depending on numeric type
5199 if Is_Modular_Integer_Type (Parent_Type) then
5200 Set_Modulus (Implicit_Base, Modulus (Parent_Base));
5202 Set_Non_Binary_Modulus
5203 (Implicit_Base, Non_Binary_Modulus (Parent_Base));
5205 elsif Is_Floating_Point_Type (Parent_Type) then
5207 -- Digits of base type is always copied from the digits value of
5208 -- the parent base type, but the digits of the derived type will
5209 -- already have been set if there was a constraint present.
5211 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5212 Set_Vax_Float (Implicit_Base, Vax_Float (Parent_Base));
5214 if No_Constraint then
5215 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Type));
5218 elsif Is_Fixed_Point_Type (Parent_Type) then
5220 -- Small of base type and derived type are always copied from the
5221 -- parent base type, since smalls never change. The delta of the
5222 -- base type is also copied from the parent base type. However the
5223 -- delta of the derived type will have been set already if a
5224 -- constraint was present.
5226 Set_Small_Value (Derived_Type, Small_Value (Parent_Base));
5227 Set_Small_Value (Implicit_Base, Small_Value (Parent_Base));
5228 Set_Delta_Value (Implicit_Base, Delta_Value (Parent_Base));
5230 if No_Constraint then
5231 Set_Delta_Value (Derived_Type, Delta_Value (Parent_Type));
5234 -- The scale and machine radix in the decimal case are always
5235 -- copied from the parent base type.
5237 if Is_Decimal_Fixed_Point_Type (Parent_Type) then
5238 Set_Scale_Value (Derived_Type, Scale_Value (Parent_Base));
5239 Set_Scale_Value (Implicit_Base, Scale_Value (Parent_Base));
5241 Set_Machine_Radix_10
5242 (Derived_Type, Machine_Radix_10 (Parent_Base));
5243 Set_Machine_Radix_10
5244 (Implicit_Base, Machine_Radix_10 (Parent_Base));
5246 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5248 if No_Constraint then
5249 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Base));
5252 -- the analysis of the subtype_indication sets the
5253 -- digits value of the derived type.
5260 -- The type of the bounds is that of the parent type, and they
5261 -- must be converted to the derived type.
5263 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
5265 -- The implicit_base should be frozen when the derived type is frozen,
5266 -- but note that it is used in the conversions of the bounds. For fixed
5267 -- types we delay the determination of the bounds until the proper
5268 -- freezing point. For other numeric types this is rejected by GCC, for
5269 -- reasons that are currently unclear (???), so we choose to freeze the
5270 -- implicit base now. In the case of integers and floating point types
5271 -- this is harmless because subsequent representation clauses cannot
5272 -- affect anything, but it is still baffling that we cannot use the
5273 -- same mechanism for all derived numeric types.
5275 -- There is a further complication: actually *some* representation
5276 -- clauses can affect the implicit base type. Namely, attribute
5277 -- definition clauses for stream-oriented attributes need to set the
5278 -- corresponding TSS entries on the base type, and this normally cannot
5279 -- be done after the base type is frozen, so the circuitry in
5280 -- Sem_Ch13.New_Stream_Subprogram must account for this possibility and
5281 -- not use Set_TSS in this case.
5283 if Is_Fixed_Point_Type (Parent_Type) then
5284 Conditional_Delay (Implicit_Base, Parent_Type);
5286 Freeze_Before (N, Implicit_Base);
5288 end Build_Derived_Numeric_Type;
5290 --------------------------------
5291 -- Build_Derived_Private_Type --
5292 --------------------------------
5294 procedure Build_Derived_Private_Type
5296 Parent_Type : Entity_Id;
5297 Derived_Type : Entity_Id;
5298 Is_Completion : Boolean;
5299 Derive_Subps : Boolean := True)
5301 Der_Base : Entity_Id;
5303 Full_Decl : Node_Id := Empty;
5304 Full_Der : Entity_Id;
5306 Last_Discr : Entity_Id;
5307 Par_Scope : constant Entity_Id := Scope (Base_Type (Parent_Type));
5308 Swapped : Boolean := False;
5310 procedure Copy_And_Build;
5311 -- Copy derived type declaration, replace parent with its full view,
5312 -- and analyze new declaration.
5314 --------------------
5315 -- Copy_And_Build --
5316 --------------------
5318 procedure Copy_And_Build is
5322 if Ekind (Parent_Type) in Record_Kind
5324 (Ekind (Parent_Type) in Enumeration_Kind
5325 and then not Is_Standard_Character_Type (Parent_Type)
5326 and then not Is_Generic_Type (Root_Type (Parent_Type)))
5328 Full_N := New_Copy_Tree (N);
5329 Insert_After (N, Full_N);
5330 Build_Derived_Type (
5331 Full_N, Parent_Type, Full_Der, True, Derive_Subps => False);
5334 Build_Derived_Type (
5335 N, Parent_Type, Full_Der, True, Derive_Subps => False);
5339 -- Start of processing for Build_Derived_Private_Type
5342 if Is_Tagged_Type (Parent_Type) then
5343 Build_Derived_Record_Type
5344 (N, Parent_Type, Derived_Type, Derive_Subps);
5347 elsif Has_Discriminants (Parent_Type) then
5348 if Present (Full_View (Parent_Type)) then
5349 if not Is_Completion then
5351 -- Copy declaration for subsequent analysis, to provide a
5352 -- completion for what is a private declaration. Indicate that
5353 -- the full type is internally generated.
5355 Full_Decl := New_Copy_Tree (N);
5356 Full_Der := New_Copy (Derived_Type);
5357 Set_Comes_From_Source (Full_Decl, False);
5358 Set_Comes_From_Source (Full_Der, False);
5360 Insert_After (N, Full_Decl);
5363 -- If this is a completion, the full view being built is
5364 -- itself private. We build a subtype of the parent with
5365 -- the same constraints as this full view, to convey to the
5366 -- back end the constrained components and the size of this
5367 -- subtype. If the parent is constrained, its full view can
5368 -- serve as the underlying full view of the derived type.
5370 if No (Discriminant_Specifications (N)) then
5371 if Nkind (Subtype_Indication (Type_Definition (N))) =
5372 N_Subtype_Indication
5374 Build_Underlying_Full_View (N, Derived_Type, Parent_Type);
5376 elsif Is_Constrained (Full_View (Parent_Type)) then
5377 Set_Underlying_Full_View (Derived_Type,
5378 Full_View (Parent_Type));
5382 -- If there are new discriminants, the parent subtype is
5383 -- constrained by them, but it is not clear how to build
5384 -- the underlying_full_view in this case ???
5391 -- Build partial view of derived type from partial view of parent
5393 Build_Derived_Record_Type
5394 (N, Parent_Type, Derived_Type, Derive_Subps);
5396 if Present (Full_View (Parent_Type))
5397 and then not Is_Completion
5399 if not In_Open_Scopes (Par_Scope)
5400 or else not In_Same_Source_Unit (N, Parent_Type)
5402 -- Swap partial and full views temporarily
5404 Install_Private_Declarations (Par_Scope);
5405 Install_Visible_Declarations (Par_Scope);
5409 -- Build full view of derived type from full view of parent which
5410 -- is now installed. Subprograms have been derived on the partial
5411 -- view, the completion does not derive them anew.
5413 if not Is_Tagged_Type (Parent_Type) then
5415 -- If the parent is itself derived from another private type,
5416 -- installing the private declarations has not affected its
5417 -- privacy status, so use its own full view explicitly.
5419 if Is_Private_Type (Parent_Type) then
5420 Build_Derived_Record_Type
5421 (Full_Decl, Full_View (Parent_Type), Full_Der, False);
5423 Build_Derived_Record_Type
5424 (Full_Decl, Parent_Type, Full_Der, False);
5428 -- If full view of parent is tagged, the completion
5429 -- inherits the proper primitive operations.
5431 Set_Defining_Identifier (Full_Decl, Full_Der);
5432 Build_Derived_Record_Type
5433 (Full_Decl, Parent_Type, Full_Der, Derive_Subps);
5434 Set_Analyzed (Full_Decl);
5438 Uninstall_Declarations (Par_Scope);
5440 if In_Open_Scopes (Par_Scope) then
5441 Install_Visible_Declarations (Par_Scope);
5445 Der_Base := Base_Type (Derived_Type);
5446 Set_Full_View (Derived_Type, Full_Der);
5447 Set_Full_View (Der_Base, Base_Type (Full_Der));
5449 -- Copy the discriminant list from full view to the partial views
5450 -- (base type and its subtype). Gigi requires that the partial
5451 -- and full views have the same discriminants.
5453 -- Note that since the partial view is pointing to discriminants
5454 -- in the full view, their scope will be that of the full view.
5455 -- This might cause some front end problems and need
5458 Discr := First_Discriminant (Base_Type (Full_Der));
5459 Set_First_Entity (Der_Base, Discr);
5462 Last_Discr := Discr;
5463 Next_Discriminant (Discr);
5464 exit when No (Discr);
5467 Set_Last_Entity (Der_Base, Last_Discr);
5469 Set_First_Entity (Derived_Type, First_Entity (Der_Base));
5470 Set_Last_Entity (Derived_Type, Last_Entity (Der_Base));
5471 Set_Stored_Constraint (Full_Der, Stored_Constraint (Derived_Type));
5474 -- If this is a completion, the derived type stays private
5475 -- and there is no need to create a further full view, except
5476 -- in the unusual case when the derivation is nested within a
5477 -- child unit, see below.
5482 elsif Present (Full_View (Parent_Type))
5483 and then Has_Discriminants (Full_View (Parent_Type))
5485 if Has_Unknown_Discriminants (Parent_Type)
5486 and then Nkind (Subtype_Indication (Type_Definition (N))) =
5487 N_Subtype_Indication
5490 ("cannot constrain type with unknown discriminants",
5491 Subtype_Indication (Type_Definition (N)));
5495 -- If full view of parent is a record type, Build full view as
5496 -- a derivation from the parent's full view. Partial view remains
5497 -- private. For code generation and linking, the full view must
5498 -- have the same public status as the partial one. This full view
5499 -- is only needed if the parent type is in an enclosing scope, so
5500 -- that the full view may actually become visible, e.g. in a child
5501 -- unit. This is both more efficient, and avoids order of freezing
5502 -- problems with the added entities.
5504 if not Is_Private_Type (Full_View (Parent_Type))
5505 and then (In_Open_Scopes (Scope (Parent_Type)))
5507 Full_Der := Make_Defining_Identifier (Sloc (Derived_Type),
5508 Chars (Derived_Type));
5509 Set_Is_Itype (Full_Der);
5510 Set_Has_Private_Declaration (Full_Der);
5511 Set_Has_Private_Declaration (Derived_Type);
5512 Set_Associated_Node_For_Itype (Full_Der, N);
5513 Set_Parent (Full_Der, Parent (Derived_Type));
5514 Set_Full_View (Derived_Type, Full_Der);
5515 Set_Is_Public (Full_Der, Is_Public (Derived_Type));
5516 Full_P := Full_View (Parent_Type);
5517 Exchange_Declarations (Parent_Type);
5519 Exchange_Declarations (Full_P);
5522 Build_Derived_Record_Type
5523 (N, Full_View (Parent_Type), Derived_Type,
5524 Derive_Subps => False);
5527 -- In any case, the primitive operations are inherited from
5528 -- the parent type, not from the internal full view.
5530 Set_Etype (Base_Type (Derived_Type), Base_Type (Parent_Type));
5532 if Derive_Subps then
5533 Derive_Subprograms (Parent_Type, Derived_Type);
5537 -- Untagged type, No discriminants on either view
5539 if Nkind (Subtype_Indication (Type_Definition (N))) =
5540 N_Subtype_Indication
5543 ("illegal constraint on type without discriminants", N);
5546 if Present (Discriminant_Specifications (N))
5547 and then Present (Full_View (Parent_Type))
5548 and then not Is_Tagged_Type (Full_View (Parent_Type))
5551 ("cannot add discriminants to untagged type", N);
5554 Set_Stored_Constraint (Derived_Type, No_Elist);
5555 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5556 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
5557 Set_Has_Controlled_Component
5558 (Derived_Type, Has_Controlled_Component
5561 -- Direct controlled types do not inherit Finalize_Storage_Only flag
5563 if not Is_Controlled (Parent_Type) then
5564 Set_Finalize_Storage_Only
5565 (Base_Type (Derived_Type), Finalize_Storage_Only (Parent_Type));
5568 -- Construct the implicit full view by deriving from full view of
5569 -- the parent type. In order to get proper visibility, we install
5570 -- the parent scope and its declarations.
5572 -- ??? if the parent is untagged private and its completion is
5573 -- tagged, this mechanism will not work because we cannot derive
5574 -- from the tagged full view unless we have an extension
5576 if Present (Full_View (Parent_Type))
5577 and then not Is_Tagged_Type (Full_View (Parent_Type))
5578 and then not Is_Completion
5581 Make_Defining_Identifier (Sloc (Derived_Type),
5582 Chars => Chars (Derived_Type));
5583 Set_Is_Itype (Full_Der);
5584 Set_Has_Private_Declaration (Full_Der);
5585 Set_Has_Private_Declaration (Derived_Type);
5586 Set_Associated_Node_For_Itype (Full_Der, N);
5587 Set_Parent (Full_Der, Parent (Derived_Type));
5588 Set_Full_View (Derived_Type, Full_Der);
5590 if not In_Open_Scopes (Par_Scope) then
5591 Install_Private_Declarations (Par_Scope);
5592 Install_Visible_Declarations (Par_Scope);
5594 Uninstall_Declarations (Par_Scope);
5596 -- If parent scope is open and in another unit, and parent has a
5597 -- completion, then the derivation is taking place in the visible
5598 -- part of a child unit. In that case retrieve the full view of
5599 -- the parent momentarily.
5601 elsif not In_Same_Source_Unit (N, Parent_Type) then
5602 Full_P := Full_View (Parent_Type);
5603 Exchange_Declarations (Parent_Type);
5605 Exchange_Declarations (Full_P);
5607 -- Otherwise it is a local derivation
5613 Set_Scope (Full_Der, Current_Scope);
5614 Set_Is_First_Subtype (Full_Der,
5615 Is_First_Subtype (Derived_Type));
5616 Set_Has_Size_Clause (Full_Der, False);
5617 Set_Has_Alignment_Clause (Full_Der, False);
5618 Set_Next_Entity (Full_Der, Empty);
5619 Set_Has_Delayed_Freeze (Full_Der);
5620 Set_Is_Frozen (Full_Der, False);
5621 Set_Freeze_Node (Full_Der, Empty);
5622 Set_Depends_On_Private (Full_Der,
5623 Has_Private_Component (Full_Der));
5624 Set_Public_Status (Full_Der);
5628 Set_Has_Unknown_Discriminants (Derived_Type,
5629 Has_Unknown_Discriminants (Parent_Type));
5631 if Is_Private_Type (Derived_Type) then
5632 Set_Private_Dependents (Derived_Type, New_Elmt_List);
5635 if Is_Private_Type (Parent_Type)
5636 and then Base_Type (Parent_Type) = Parent_Type
5637 and then In_Open_Scopes (Scope (Parent_Type))
5639 Append_Elmt (Derived_Type, Private_Dependents (Parent_Type));
5641 if Is_Child_Unit (Scope (Current_Scope))
5642 and then Is_Completion
5643 and then In_Private_Part (Current_Scope)
5644 and then Scope (Parent_Type) /= Current_Scope
5646 -- This is the unusual case where a type completed by a private
5647 -- derivation occurs within a package nested in a child unit,
5648 -- and the parent is declared in an ancestor. In this case, the
5649 -- full view of the parent type will become visible in the body
5650 -- of the enclosing child, and only then will the current type
5651 -- be possibly non-private. We build a underlying full view that
5652 -- will be installed when the enclosing child body is compiled.
5655 Make_Defining_Identifier (Sloc (Derived_Type),
5656 Chars => Chars (Derived_Type));
5657 Set_Is_Itype (Full_Der);
5658 Build_Itype_Reference (Full_Der, N);
5660 -- The full view will be used to swap entities on entry/exit to
5661 -- the body, and must appear in the entity list for the package.
5663 Append_Entity (Full_Der, Scope (Derived_Type));
5664 Set_Has_Private_Declaration (Full_Der);
5665 Set_Has_Private_Declaration (Derived_Type);
5666 Set_Associated_Node_For_Itype (Full_Der, N);
5667 Set_Parent (Full_Der, Parent (Derived_Type));
5668 Full_P := Full_View (Parent_Type);
5669 Exchange_Declarations (Parent_Type);
5671 Exchange_Declarations (Full_P);
5672 Set_Underlying_Full_View (Derived_Type, Full_Der);
5675 end Build_Derived_Private_Type;
5677 -------------------------------
5678 -- Build_Derived_Record_Type --
5679 -------------------------------
5683 -- Ideally we would like to use the same model of type derivation for
5684 -- tagged and untagged record types. Unfortunately this is not quite
5685 -- possible because the semantics of representation clauses is different
5686 -- for tagged and untagged records under inheritance. Consider the
5689 -- type R (...) is [tagged] record ... end record;
5690 -- type T (...) is new R (...) [with ...];
5692 -- The representation clauses for T can specify a completely different
5693 -- record layout from R's. Hence the same component can be placed in two
5694 -- very different positions in objects of type T and R. If R and are tagged
5695 -- types, representation clauses for T can only specify the layout of non
5696 -- inherited components, thus components that are common in R and T have
5697 -- the same position in objects of type R and T.
5699 -- This has two implications. The first is that the entire tree for R's
5700 -- declaration needs to be copied for T in the untagged case, so that T
5701 -- can be viewed as a record type of its own with its own representation
5702 -- clauses. The second implication is the way we handle discriminants.
5703 -- Specifically, in the untagged case we need a way to communicate to Gigi
5704 -- what are the real discriminants in the record, while for the semantics
5705 -- we need to consider those introduced by the user to rename the
5706 -- discriminants in the parent type. This is handled by introducing the
5707 -- notion of stored discriminants. See below for more.
5709 -- Fortunately the way regular components are inherited can be handled in
5710 -- the same way in tagged and untagged types.
5712 -- To complicate things a bit more the private view of a private extension
5713 -- cannot be handled in the same way as the full view (for one thing the
5714 -- semantic rules are somewhat different). We will explain what differs
5717 -- 2. DISCRIMINANTS UNDER INHERITANCE
5719 -- The semantic rules governing the discriminants of derived types are
5722 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
5723 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
5725 -- If parent type has discriminants, then the discriminants that are
5726 -- declared in the derived type are [3.4 (11)]:
5728 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
5731 -- o Otherwise, each discriminant of the parent type (implicitly declared
5732 -- in the same order with the same specifications). In this case, the
5733 -- discriminants are said to be "inherited", or if unknown in the parent
5734 -- are also unknown in the derived type.
5736 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
5738 -- o The parent subtype shall be constrained;
5740 -- o If the parent type is not a tagged type, then each discriminant of
5741 -- the derived type shall be used in the constraint defining a parent
5742 -- subtype. [Implementation note: This ensures that the new discriminant
5743 -- can share storage with an existing discriminant.]
5745 -- For the derived type each discriminant of the parent type is either
5746 -- inherited, constrained to equal some new discriminant of the derived
5747 -- type, or constrained to the value of an expression.
5749 -- When inherited or constrained to equal some new discriminant, the
5750 -- parent discriminant and the discriminant of the derived type are said
5753 -- If a discriminant of the parent type is constrained to a specific value
5754 -- in the derived type definition, then the discriminant is said to be
5755 -- "specified" by that derived type definition.
5757 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
5759 -- We have spoken about stored discriminants in point 1 (introduction)
5760 -- above. There are two sort of stored discriminants: implicit and
5761 -- explicit. As long as the derived type inherits the same discriminants as
5762 -- the root record type, stored discriminants are the same as regular
5763 -- discriminants, and are said to be implicit. However, if any discriminant
5764 -- in the root type was renamed in the derived type, then the derived
5765 -- type will contain explicit stored discriminants. Explicit stored
5766 -- discriminants are discriminants in addition to the semantically visible
5767 -- discriminants defined for the derived type. Stored discriminants are
5768 -- used by Gigi to figure out what are the physical discriminants in
5769 -- objects of the derived type (see precise definition in einfo.ads).
5770 -- As an example, consider the following:
5772 -- type R (D1, D2, D3 : Int) is record ... end record;
5773 -- type T1 is new R;
5774 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
5775 -- type T3 is new T2;
5776 -- type T4 (Y : Int) is new T3 (Y, 99);
5778 -- The following table summarizes the discriminants and stored
5779 -- discriminants in R and T1 through T4.
5781 -- Type Discrim Stored Discrim Comment
5782 -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
5783 -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
5784 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
5785 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
5786 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
5788 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
5789 -- find the corresponding discriminant in the parent type, while
5790 -- Original_Record_Component (abbreviated ORC below), the actual physical
5791 -- component that is renamed. Finally the field Is_Completely_Hidden
5792 -- (abbreviated ICH below) is set for all explicit stored discriminants
5793 -- (see einfo.ads for more info). For the above example this gives:
5795 -- Discrim CD ORC ICH
5796 -- ^^^^^^^ ^^ ^^^ ^^^
5797 -- D1 in R empty itself no
5798 -- D2 in R empty itself no
5799 -- D3 in R empty itself no
5801 -- D1 in T1 D1 in R itself no
5802 -- D2 in T1 D2 in R itself no
5803 -- D3 in T1 D3 in R itself no
5805 -- X1 in T2 D3 in T1 D3 in T2 no
5806 -- X2 in T2 D1 in T1 D1 in T2 no
5807 -- D1 in T2 empty itself yes
5808 -- D2 in T2 empty itself yes
5809 -- D3 in T2 empty itself yes
5811 -- X1 in T3 X1 in T2 D3 in T3 no
5812 -- X2 in T3 X2 in T2 D1 in T3 no
5813 -- D1 in T3 empty itself yes
5814 -- D2 in T3 empty itself yes
5815 -- D3 in T3 empty itself yes
5817 -- Y in T4 X1 in T3 D3 in T3 no
5818 -- D1 in T3 empty itself yes
5819 -- D2 in T3 empty itself yes
5820 -- D3 in T3 empty itself yes
5822 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
5824 -- Type derivation for tagged types is fairly straightforward. If no
5825 -- discriminants are specified by the derived type, these are inherited
5826 -- from the parent. No explicit stored discriminants are ever necessary.
5827 -- The only manipulation that is done to the tree is that of adding a
5828 -- _parent field with parent type and constrained to the same constraint
5829 -- specified for the parent in the derived type definition. For instance:
5831 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
5832 -- type T1 is new R with null record;
5833 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
5835 -- are changed into:
5837 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
5838 -- _parent : R (D1, D2, D3);
5841 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
5842 -- _parent : T1 (X2, 88, X1);
5845 -- The discriminants actually present in R, T1 and T2 as well as their CD,
5846 -- ORC and ICH fields are:
5848 -- Discrim CD ORC ICH
5849 -- ^^^^^^^ ^^ ^^^ ^^^
5850 -- D1 in R empty itself no
5851 -- D2 in R empty itself no
5852 -- D3 in R empty itself no
5854 -- D1 in T1 D1 in R D1 in R no
5855 -- D2 in T1 D2 in R D2 in R no
5856 -- D3 in T1 D3 in R D3 in R no
5858 -- X1 in T2 D3 in T1 D3 in R no
5859 -- X2 in T2 D1 in T1 D1 in R no
5861 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
5863 -- Regardless of whether we dealing with a tagged or untagged type
5864 -- we will transform all derived type declarations of the form
5866 -- type T is new R (...) [with ...];
5868 -- subtype S is R (...);
5869 -- type T is new S [with ...];
5871 -- type BT is new R [with ...];
5872 -- subtype T is BT (...);
5874 -- That is, the base derived type is constrained only if it has no
5875 -- discriminants. The reason for doing this is that GNAT's semantic model
5876 -- assumes that a base type with discriminants is unconstrained.
5878 -- Note that, strictly speaking, the above transformation is not always
5879 -- correct. Consider for instance the following excerpt from ACVC b34011a:
5881 -- procedure B34011A is
5882 -- type REC (D : integer := 0) is record
5887 -- type T6 is new Rec;
5888 -- function F return T6;
5893 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
5896 -- The definition of Q6.U is illegal. However transforming Q6.U into
5898 -- type BaseU is new T6;
5899 -- subtype U is BaseU (Q6.F.I)
5901 -- turns U into a legal subtype, which is incorrect. To avoid this problem
5902 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
5903 -- the transformation described above.
5905 -- There is another instance where the above transformation is incorrect.
5909 -- type Base (D : Integer) is tagged null record;
5910 -- procedure P (X : Base);
5912 -- type Der is new Base (2) with null record;
5913 -- procedure P (X : Der);
5916 -- Then the above transformation turns this into
5918 -- type Der_Base is new Base with null record;
5919 -- -- procedure P (X : Base) is implicitly inherited here
5920 -- -- as procedure P (X : Der_Base).
5922 -- subtype Der is Der_Base (2);
5923 -- procedure P (X : Der);
5924 -- -- The overriding of P (X : Der_Base) is illegal since we
5925 -- -- have a parameter conformance problem.
5927 -- To get around this problem, after having semantically processed Der_Base
5928 -- and the rewritten subtype declaration for Der, we copy Der_Base field
5929 -- Discriminant_Constraint from Der so that when parameter conformance is
5930 -- checked when P is overridden, no semantic errors are flagged.
5932 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
5934 -- Regardless of whether we are dealing with a tagged or untagged type
5935 -- we will transform all derived type declarations of the form
5937 -- type R (D1, .., Dn : ...) is [tagged] record ...;
5938 -- type T is new R [with ...];
5940 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
5942 -- The reason for such transformation is that it allows us to implement a
5943 -- very clean form of component inheritance as explained below.
5945 -- Note that this transformation is not achieved by direct tree rewriting
5946 -- and manipulation, but rather by redoing the semantic actions that the
5947 -- above transformation will entail. This is done directly in routine
5948 -- Inherit_Components.
5950 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
5952 -- In both tagged and untagged derived types, regular non discriminant
5953 -- components are inherited in the derived type from the parent type. In
5954 -- the absence of discriminants component, inheritance is straightforward
5955 -- as components can simply be copied from the parent.
5957 -- If the parent has discriminants, inheriting components constrained with
5958 -- these discriminants requires caution. Consider the following example:
5960 -- type R (D1, D2 : Positive) is [tagged] record
5961 -- S : String (D1 .. D2);
5964 -- type T1 is new R [with null record];
5965 -- type T2 (X : positive) is new R (1, X) [with null record];
5967 -- As explained in 6. above, T1 is rewritten as
5968 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
5969 -- which makes the treatment for T1 and T2 identical.
5971 -- What we want when inheriting S, is that references to D1 and D2 in R are
5972 -- replaced with references to their correct constraints, ie D1 and D2 in
5973 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
5974 -- with either discriminant references in the derived type or expressions.
5975 -- This replacement is achieved as follows: before inheriting R's
5976 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
5977 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
5978 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
5979 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
5980 -- by String (1 .. X).
5982 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
5984 -- We explain here the rules governing private type extensions relevant to
5985 -- type derivation. These rules are explained on the following example:
5987 -- type D [(...)] is new A [(...)] with private; <-- partial view
5988 -- type D [(...)] is new P [(...)] with null record; <-- full view
5990 -- Type A is called the ancestor subtype of the private extension.
5991 -- Type P is the parent type of the full view of the private extension. It
5992 -- must be A or a type derived from A.
5994 -- The rules concerning the discriminants of private type extensions are
5997 -- o If a private extension inherits known discriminants from the ancestor
5998 -- subtype, then the full view shall also inherit its discriminants from
5999 -- the ancestor subtype and the parent subtype of the full view shall be
6000 -- constrained if and only if the ancestor subtype is constrained.
6002 -- o If a partial view has unknown discriminants, then the full view may
6003 -- define a definite or an indefinite subtype, with or without
6006 -- o If a partial view has neither known nor unknown discriminants, then
6007 -- the full view shall define a definite subtype.
6009 -- o If the ancestor subtype of a private extension has constrained
6010 -- discriminants, then the parent subtype of the full view shall impose a
6011 -- statically matching constraint on those discriminants.
6013 -- This means that only the following forms of private extensions are
6016 -- type D is new A with private; <-- partial view
6017 -- type D is new P with null record; <-- full view
6019 -- If A has no discriminants than P has no discriminants, otherwise P must
6020 -- inherit A's discriminants.
6022 -- type D is new A (...) with private; <-- partial view
6023 -- type D is new P (:::) with null record; <-- full view
6025 -- P must inherit A's discriminants and (...) and (:::) must statically
6028 -- subtype A is R (...);
6029 -- type D is new A with private; <-- partial view
6030 -- type D is new P with null record; <-- full view
6032 -- P must have inherited R's discriminants and must be derived from A or
6033 -- any of its subtypes.
6035 -- type D (..) is new A with private; <-- partial view
6036 -- type D (..) is new P [(:::)] with null record; <-- full view
6038 -- No specific constraints on P's discriminants or constraint (:::).
6039 -- Note that A can be unconstrained, but the parent subtype P must either
6040 -- be constrained or (:::) must be present.
6042 -- type D (..) is new A [(...)] with private; <-- partial view
6043 -- type D (..) is new P [(:::)] with null record; <-- full view
6045 -- P's constraints on A's discriminants must statically match those
6046 -- imposed by (...).
6048 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
6050 -- The full view of a private extension is handled exactly as described
6051 -- above. The model chose for the private view of a private extension is
6052 -- the same for what concerns discriminants (ie they receive the same
6053 -- treatment as in the tagged case). However, the private view of the
6054 -- private extension always inherits the components of the parent base,
6055 -- without replacing any discriminant reference. Strictly speaking this is
6056 -- incorrect. However, Gigi never uses this view to generate code so this
6057 -- is a purely semantic issue. In theory, a set of transformations similar
6058 -- to those given in 5. and 6. above could be applied to private views of
6059 -- private extensions to have the same model of component inheritance as
6060 -- for non private extensions. However, this is not done because it would
6061 -- further complicate private type processing. Semantically speaking, this
6062 -- leaves us in an uncomfortable situation. As an example consider:
6065 -- type R (D : integer) is tagged record
6066 -- S : String (1 .. D);
6068 -- procedure P (X : R);
6069 -- type T is new R (1) with private;
6071 -- type T is new R (1) with null record;
6074 -- This is transformed into:
6077 -- type R (D : integer) is tagged record
6078 -- S : String (1 .. D);
6080 -- procedure P (X : R);
6081 -- type T is new R (1) with private;
6083 -- type BaseT is new R with null record;
6084 -- subtype T is BaseT (1);
6087 -- (strictly speaking the above is incorrect Ada)
6089 -- From the semantic standpoint the private view of private extension T
6090 -- should be flagged as constrained since one can clearly have
6094 -- in a unit withing Pack. However, when deriving subprograms for the
6095 -- private view of private extension T, T must be seen as unconstrained
6096 -- since T has discriminants (this is a constraint of the current
6097 -- subprogram derivation model). Thus, when processing the private view of
6098 -- a private extension such as T, we first mark T as unconstrained, we
6099 -- process it, we perform program derivation and just before returning from
6100 -- Build_Derived_Record_Type we mark T as constrained.
6102 -- ??? Are there are other uncomfortable cases that we will have to
6105 -- 10. RECORD_TYPE_WITH_PRIVATE complications
6107 -- Types that are derived from a visible record type and have a private
6108 -- extension present other peculiarities. They behave mostly like private
6109 -- types, but if they have primitive operations defined, these will not
6110 -- have the proper signatures for further inheritance, because other
6111 -- primitive operations will use the implicit base that we define for
6112 -- private derivations below. This affect subprogram inheritance (see
6113 -- Derive_Subprograms for details). We also derive the implicit base from
6114 -- the base type of the full view, so that the implicit base is a record
6115 -- type and not another private type, This avoids infinite loops.
6117 procedure Build_Derived_Record_Type
6119 Parent_Type : Entity_Id;
6120 Derived_Type : Entity_Id;
6121 Derive_Subps : Boolean := True)
6123 Loc : constant Source_Ptr := Sloc (N);
6124 Parent_Base : Entity_Id;
6127 Discrim : Entity_Id;
6128 Last_Discrim : Entity_Id;
6131 Discs : Elist_Id := New_Elmt_List;
6132 -- An empty Discs list means that there were no constraints in the
6133 -- subtype indication or that there was an error processing it.
6135 Assoc_List : Elist_Id;
6136 New_Discrs : Elist_Id;
6137 New_Base : Entity_Id;
6139 New_Indic : Node_Id;
6141 Is_Tagged : constant Boolean := Is_Tagged_Type (Parent_Type);
6142 Discriminant_Specs : constant Boolean :=
6143 Present (Discriminant_Specifications (N));
6144 Private_Extension : constant Boolean :=
6145 Nkind (N) = N_Private_Extension_Declaration;
6147 Constraint_Present : Boolean;
6148 Inherit_Discrims : Boolean := False;
6149 Save_Etype : Entity_Id;
6150 Save_Discr_Constr : Elist_Id;
6151 Save_Next_Entity : Entity_Id;
6154 if Ekind (Parent_Type) = E_Record_Type_With_Private
6155 and then Present (Full_View (Parent_Type))
6156 and then Has_Discriminants (Parent_Type)
6158 Parent_Base := Base_Type (Full_View (Parent_Type));
6160 Parent_Base := Base_Type (Parent_Type);
6163 -- Before we start the previously documented transformations, here is
6164 -- little fix for size and alignment of tagged types. Normally when we
6165 -- derive type D from type P, we copy the size and alignment of P as the
6166 -- default for D, and in the absence of explicit representation clauses
6167 -- for D, the size and alignment are indeed the same as the parent.
6169 -- But this is wrong for tagged types, since fields may be added, and
6170 -- the default size may need to be larger, and the default alignment may
6171 -- need to be larger.
6173 -- We therefore reset the size and alignment fields in the tagged case.
6174 -- Note that the size and alignment will in any case be at least as
6175 -- large as the parent type (since the derived type has a copy of the
6176 -- parent type in the _parent field)
6178 -- The type is also marked as being tagged here, which is needed when
6179 -- processing components with a self-referential anonymous access type
6180 -- in the call to Check_Anonymous_Access_Components below. Note that
6181 -- this flag is also set later on for completeness.
6184 Set_Is_Tagged_Type (Derived_Type);
6185 Init_Size_Align (Derived_Type);
6188 -- STEP 0a: figure out what kind of derived type declaration we have
6190 if Private_Extension then
6192 Set_Ekind (Derived_Type, E_Record_Type_With_Private);
6195 Type_Def := Type_Definition (N);
6197 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
6198 -- Parent_Base can be a private type or private extension. However,
6199 -- for tagged types with an extension the newly added fields are
6200 -- visible and hence the Derived_Type is always an E_Record_Type.
6201 -- (except that the parent may have its own private fields).
6202 -- For untagged types we preserve the Ekind of the Parent_Base.
6204 if Present (Record_Extension_Part (Type_Def)) then
6205 Set_Ekind (Derived_Type, E_Record_Type);
6207 -- Create internal access types for components with anonymous
6210 if Ada_Version >= Ada_05 then
6211 Check_Anonymous_Access_Components
6212 (N, Derived_Type, Derived_Type,
6213 Component_List (Record_Extension_Part (Type_Def)));
6217 Set_Ekind (Derived_Type, Ekind (Parent_Base));
6221 -- Indic can either be an N_Identifier if the subtype indication
6222 -- contains no constraint or an N_Subtype_Indication if the subtype
6223 -- indication has a constraint.
6225 Indic := Subtype_Indication (Type_Def);
6226 Constraint_Present := (Nkind (Indic) = N_Subtype_Indication);
6228 -- Check that the type has visible discriminants. The type may be
6229 -- a private type with unknown discriminants whose full view has
6230 -- discriminants which are invisible.
6232 if Constraint_Present then
6233 if not Has_Discriminants (Parent_Base)
6235 (Has_Unknown_Discriminants (Parent_Base)
6236 and then Is_Private_Type (Parent_Base))
6239 ("invalid constraint: type has no discriminant",
6240 Constraint (Indic));
6242 Constraint_Present := False;
6243 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6245 elsif Is_Constrained (Parent_Type) then
6247 ("invalid constraint: parent type is already constrained",
6248 Constraint (Indic));
6250 Constraint_Present := False;
6251 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6255 -- STEP 0b: If needed, apply transformation given in point 5. above
6257 if not Private_Extension
6258 and then Has_Discriminants (Parent_Type)
6259 and then not Discriminant_Specs
6260 and then (Is_Constrained (Parent_Type) or else Constraint_Present)
6262 -- First, we must analyze the constraint (see comment in point 5.)
6264 if Constraint_Present then
6265 New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic);
6267 if Has_Discriminants (Derived_Type)
6268 and then Has_Private_Declaration (Derived_Type)
6269 and then Present (Discriminant_Constraint (Derived_Type))
6271 -- Verify that constraints of the full view conform to those
6272 -- given in partial view.
6278 C1 := First_Elmt (New_Discrs);
6279 C2 := First_Elmt (Discriminant_Constraint (Derived_Type));
6280 while Present (C1) and then Present (C2) loop
6282 Fully_Conformant_Expressions (Node (C1), Node (C2))
6285 "constraint not conformant to previous declaration",
6296 -- Insert and analyze the declaration for the unconstrained base type
6298 New_Base := Create_Itype (Ekind (Derived_Type), N, Derived_Type, 'B');
6301 Make_Full_Type_Declaration (Loc,
6302 Defining_Identifier => New_Base,
6304 Make_Derived_Type_Definition (Loc,
6305 Abstract_Present => Abstract_Present (Type_Def),
6306 Subtype_Indication =>
6307 New_Occurrence_Of (Parent_Base, Loc),
6308 Record_Extension_Part =>
6309 Relocate_Node (Record_Extension_Part (Type_Def))));
6311 Set_Parent (New_Decl, Parent (N));
6312 Mark_Rewrite_Insertion (New_Decl);
6313 Insert_Before (N, New_Decl);
6315 -- Note that this call passes False for the Derive_Subps parameter
6316 -- because subprogram derivation is deferred until after creating
6317 -- the subtype (see below).
6320 (New_Decl, Parent_Base, New_Base,
6321 Is_Completion => True, Derive_Subps => False);
6323 -- ??? This needs re-examination to determine whether the
6324 -- above call can simply be replaced by a call to Analyze.
6326 Set_Analyzed (New_Decl);
6328 -- Insert and analyze the declaration for the constrained subtype
6330 if Constraint_Present then
6332 Make_Subtype_Indication (Loc,
6333 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6334 Constraint => Relocate_Node (Constraint (Indic)));
6338 Constr_List : constant List_Id := New_List;
6343 C := First_Elmt (Discriminant_Constraint (Parent_Type));
6344 while Present (C) loop
6347 -- It is safe here to call New_Copy_Tree since
6348 -- Force_Evaluation was called on each constraint in
6349 -- Build_Discriminant_Constraints.
6351 Append (New_Copy_Tree (Expr), To => Constr_List);
6357 Make_Subtype_Indication (Loc,
6358 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6360 Make_Index_Or_Discriminant_Constraint (Loc, Constr_List));
6365 Make_Subtype_Declaration (Loc,
6366 Defining_Identifier => Derived_Type,
6367 Subtype_Indication => New_Indic));
6371 -- Derivation of subprograms must be delayed until the full subtype
6372 -- has been established to ensure proper overriding of subprograms
6373 -- inherited by full types. If the derivations occurred as part of
6374 -- the call to Build_Derived_Type above, then the check for type
6375 -- conformance would fail because earlier primitive subprograms
6376 -- could still refer to the full type prior the change to the new
6377 -- subtype and hence would not match the new base type created here.
6379 Derive_Subprograms (Parent_Type, Derived_Type);
6381 -- For tagged types the Discriminant_Constraint of the new base itype
6382 -- is inherited from the first subtype so that no subtype conformance
6383 -- problem arise when the first subtype overrides primitive
6384 -- operations inherited by the implicit base type.
6387 Set_Discriminant_Constraint
6388 (New_Base, Discriminant_Constraint (Derived_Type));
6394 -- If we get here Derived_Type will have no discriminants or it will be
6395 -- a discriminated unconstrained base type.
6397 -- STEP 1a: perform preliminary actions/checks for derived tagged types
6401 -- The parent type is frozen for non-private extensions (RM 13.14(7))
6402 -- The declaration of a specific descendant of an interface type
6403 -- freezes the interface type (RM 13.14).
6405 if not Private_Extension
6406 or else Is_Interface (Parent_Base)
6408 Freeze_Before (N, Parent_Type);
6411 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
6412 -- cannot be declared at a deeper level than its parent type is
6413 -- removed. The check on derivation within a generic body is also
6414 -- relaxed, but there's a restriction that a derived tagged type
6415 -- cannot be declared in a generic body if it's derived directly
6416 -- or indirectly from a formal type of that generic.
6418 if Ada_Version >= Ada_05 then
6419 if Present (Enclosing_Generic_Body (Derived_Type)) then
6421 Ancestor_Type : Entity_Id;
6424 -- Check to see if any ancestor of the derived type is a
6427 Ancestor_Type := Parent_Type;
6428 while not Is_Generic_Type (Ancestor_Type)
6429 and then Etype (Ancestor_Type) /= Ancestor_Type
6431 Ancestor_Type := Etype (Ancestor_Type);
6434 -- If the derived type does have a formal type as an
6435 -- ancestor, then it's an error if the derived type is
6436 -- declared within the body of the generic unit that
6437 -- declares the formal type in its generic formal part. It's
6438 -- sufficient to check whether the ancestor type is declared
6439 -- inside the same generic body as the derived type (such as
6440 -- within a nested generic spec), in which case the
6441 -- derivation is legal. If the formal type is declared
6442 -- outside of that generic body, then it's guaranteed that
6443 -- the derived type is declared within the generic body of
6444 -- the generic unit declaring the formal type.
6446 if Is_Generic_Type (Ancestor_Type)
6447 and then Enclosing_Generic_Body (Ancestor_Type) /=
6448 Enclosing_Generic_Body (Derived_Type)
6451 ("parent type of& must not be descendant of formal type"
6452 & " of an enclosing generic body",
6453 Indic, Derived_Type);
6458 elsif Type_Access_Level (Derived_Type) /=
6459 Type_Access_Level (Parent_Type)
6460 and then not Is_Generic_Type (Derived_Type)
6462 if Is_Controlled (Parent_Type) then
6464 ("controlled type must be declared at the library level",
6468 ("type extension at deeper accessibility level than parent",
6474 GB : constant Node_Id := Enclosing_Generic_Body (Derived_Type);
6478 and then GB /= Enclosing_Generic_Body (Parent_Base)
6481 ("parent type of& must not be outside generic body"
6483 Indic, Derived_Type);
6489 -- Ada 2005 (AI-251)
6491 if Ada_Version = Ada_05
6494 -- "The declaration of a specific descendant of an interface type
6495 -- freezes the interface type" (RM 13.14).
6500 if Is_Non_Empty_List (Interface_List (Type_Def)) then
6501 Iface := First (Interface_List (Type_Def));
6502 while Present (Iface) loop
6503 Freeze_Before (N, Etype (Iface));
6510 -- STEP 1b : preliminary cleanup of the full view of private types
6512 -- If the type is already marked as having discriminants, then it's the
6513 -- completion of a private type or private extension and we need to
6514 -- retain the discriminants from the partial view if the current
6515 -- declaration has Discriminant_Specifications so that we can verify
6516 -- conformance. However, we must remove any existing components that
6517 -- were inherited from the parent (and attached in Copy_And_Swap)
6518 -- because the full type inherits all appropriate components anyway, and
6519 -- we do not want the partial view's components interfering.
6521 if Has_Discriminants (Derived_Type) and then Discriminant_Specs then
6522 Discrim := First_Discriminant (Derived_Type);
6524 Last_Discrim := Discrim;
6525 Next_Discriminant (Discrim);
6526 exit when No (Discrim);
6529 Set_Last_Entity (Derived_Type, Last_Discrim);
6531 -- In all other cases wipe out the list of inherited components (even
6532 -- inherited discriminants), it will be properly rebuilt here.
6535 Set_First_Entity (Derived_Type, Empty);
6536 Set_Last_Entity (Derived_Type, Empty);
6539 -- STEP 1c: Initialize some flags for the Derived_Type
6541 -- The following flags must be initialized here so that
6542 -- Process_Discriminants can check that discriminants of tagged types do
6543 -- not have a default initial value and that access discriminants are
6544 -- only specified for limited records. For completeness, these flags are
6545 -- also initialized along with all the other flags below.
6547 -- AI-419: Limitedness is not inherited from an interface parent, so to
6548 -- be limited in that case the type must be explicitly declared as
6549 -- limited. However, task and protected interfaces are always limited.
6551 if Limited_Present (Type_Def) then
6552 Set_Is_Limited_Record (Derived_Type);
6554 elsif Is_Limited_Record (Parent_Type)
6555 or else (Present (Full_View (Parent_Type))
6556 and then Is_Limited_Record (Full_View (Parent_Type)))
6558 if not Is_Interface (Parent_Type)
6559 or else Is_Synchronized_Interface (Parent_Type)
6560 or else Is_Protected_Interface (Parent_Type)
6561 or else Is_Task_Interface (Parent_Type)
6563 Set_Is_Limited_Record (Derived_Type);
6567 -- STEP 2a: process discriminants of derived type if any
6569 Push_Scope (Derived_Type);
6571 if Discriminant_Specs then
6572 Set_Has_Unknown_Discriminants (Derived_Type, False);
6574 -- The following call initializes fields Has_Discriminants and
6575 -- Discriminant_Constraint, unless we are processing the completion
6576 -- of a private type declaration.
6578 Check_Or_Process_Discriminants (N, Derived_Type);
6580 -- For non-tagged types the constraint on the Parent_Type must be
6581 -- present and is used to rename the discriminants.
6583 if not Is_Tagged and then not Has_Discriminants (Parent_Type) then
6584 Error_Msg_N ("untagged parent must have discriminants", Indic);
6586 elsif not Is_Tagged and then not Constraint_Present then
6588 ("discriminant constraint needed for derived untagged records",
6591 -- Otherwise the parent subtype must be constrained unless we have a
6592 -- private extension.
6594 elsif not Constraint_Present
6595 and then not Private_Extension
6596 and then not Is_Constrained (Parent_Type)
6599 ("unconstrained type not allowed in this context", Indic);
6601 elsif Constraint_Present then
6602 -- The following call sets the field Corresponding_Discriminant
6603 -- for the discriminants in the Derived_Type.
6605 Discs := Build_Discriminant_Constraints (Parent_Type, Indic, True);
6607 -- For untagged types all new discriminants must rename
6608 -- discriminants in the parent. For private extensions new
6609 -- discriminants cannot rename old ones (implied by [7.3(13)]).
6611 Discrim := First_Discriminant (Derived_Type);
6612 while Present (Discrim) loop
6614 and then No (Corresponding_Discriminant (Discrim))
6617 ("new discriminants must constrain old ones", Discrim);
6619 elsif Private_Extension
6620 and then Present (Corresponding_Discriminant (Discrim))
6623 ("only static constraints allowed for parent"
6624 & " discriminants in the partial view", Indic);
6628 -- If a new discriminant is used in the constraint, then its
6629 -- subtype must be statically compatible with the parent
6630 -- discriminant's subtype (3.7(15)).
6632 if Present (Corresponding_Discriminant (Discrim))
6634 not Subtypes_Statically_Compatible
6636 Etype (Corresponding_Discriminant (Discrim)))
6639 ("subtype must be compatible with parent discriminant",
6643 Next_Discriminant (Discrim);
6646 -- Check whether the constraints of the full view statically
6647 -- match those imposed by the parent subtype [7.3(13)].
6649 if Present (Stored_Constraint (Derived_Type)) then
6654 C1 := First_Elmt (Discs);
6655 C2 := First_Elmt (Stored_Constraint (Derived_Type));
6656 while Present (C1) and then Present (C2) loop
6658 Fully_Conformant_Expressions (Node (C1), Node (C2))
6661 ("not conformant with previous declaration",
6672 -- STEP 2b: No new discriminants, inherit discriminants if any
6675 if Private_Extension then
6676 Set_Has_Unknown_Discriminants
6678 Has_Unknown_Discriminants (Parent_Type)
6679 or else Unknown_Discriminants_Present (N));
6681 -- The partial view of the parent may have unknown discriminants,
6682 -- but if the full view has discriminants and the parent type is
6683 -- in scope they must be inherited.
6685 elsif Has_Unknown_Discriminants (Parent_Type)
6687 (not Has_Discriminants (Parent_Type)
6688 or else not In_Open_Scopes (Scope (Parent_Type)))
6690 Set_Has_Unknown_Discriminants (Derived_Type);
6693 if not Has_Unknown_Discriminants (Derived_Type)
6694 and then not Has_Unknown_Discriminants (Parent_Base)
6695 and then Has_Discriminants (Parent_Type)
6697 Inherit_Discrims := True;
6698 Set_Has_Discriminants
6699 (Derived_Type, True);
6700 Set_Discriminant_Constraint
6701 (Derived_Type, Discriminant_Constraint (Parent_Base));
6704 -- The following test is true for private types (remember
6705 -- transformation 5. is not applied to those) and in an error
6708 if Constraint_Present then
6709 Discs := Build_Discriminant_Constraints (Parent_Type, Indic);
6712 -- For now mark a new derived type as constrained only if it has no
6713 -- discriminants. At the end of Build_Derived_Record_Type we properly
6714 -- set this flag in the case of private extensions. See comments in
6715 -- point 9. just before body of Build_Derived_Record_Type.
6719 not (Inherit_Discrims
6720 or else Has_Unknown_Discriminants (Derived_Type)));
6723 -- STEP 3: initialize fields of derived type
6725 Set_Is_Tagged_Type (Derived_Type, Is_Tagged);
6726 Set_Stored_Constraint (Derived_Type, No_Elist);
6728 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
6729 -- but cannot be interfaces
6731 if not Private_Extension
6732 and then Ekind (Derived_Type) /= E_Private_Type
6733 and then Ekind (Derived_Type) /= E_Limited_Private_Type
6735 if Interface_Present (Type_Def) then
6736 Analyze_Interface_Declaration (Derived_Type, Type_Def);
6739 Set_Abstract_Interfaces (Derived_Type, No_Elist);
6742 -- Fields inherited from the Parent_Type
6745 (Derived_Type, Einfo.Discard_Names (Parent_Type));
6746 Set_Has_Specified_Layout
6747 (Derived_Type, Has_Specified_Layout (Parent_Type));
6748 Set_Is_Limited_Composite
6749 (Derived_Type, Is_Limited_Composite (Parent_Type));
6750 Set_Is_Private_Composite
6751 (Derived_Type, Is_Private_Composite (Parent_Type));
6753 -- Fields inherited from the Parent_Base
6755 Set_Has_Controlled_Component
6756 (Derived_Type, Has_Controlled_Component (Parent_Base));
6757 Set_Has_Non_Standard_Rep
6758 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6759 Set_Has_Primitive_Operations
6760 (Derived_Type, Has_Primitive_Operations (Parent_Base));
6762 -- Fields inherited from the Parent_Base in the non-private case
6764 if Ekind (Derived_Type) = E_Record_Type then
6765 Set_Has_Complex_Representation
6766 (Derived_Type, Has_Complex_Representation (Parent_Base));
6769 -- Fields inherited from the Parent_Base for record types
6771 if Is_Record_Type (Derived_Type) then
6772 Set_OK_To_Reorder_Components
6773 (Derived_Type, OK_To_Reorder_Components (Parent_Base));
6774 Set_Reverse_Bit_Order
6775 (Derived_Type, Reverse_Bit_Order (Parent_Base));
6778 -- Direct controlled types do not inherit Finalize_Storage_Only flag
6780 if not Is_Controlled (Parent_Type) then
6781 Set_Finalize_Storage_Only
6782 (Derived_Type, Finalize_Storage_Only (Parent_Type));
6785 -- Set fields for private derived types
6787 if Is_Private_Type (Derived_Type) then
6788 Set_Depends_On_Private (Derived_Type, True);
6789 Set_Private_Dependents (Derived_Type, New_Elmt_List);
6791 -- Inherit fields from non private record types. If this is the
6792 -- completion of a derivation from a private type, the parent itself
6793 -- is private, and the attributes come from its full view, which must
6797 if Is_Private_Type (Parent_Base)
6798 and then not Is_Record_Type (Parent_Base)
6800 Set_Component_Alignment
6801 (Derived_Type, Component_Alignment (Full_View (Parent_Base)));
6803 (Derived_Type, C_Pass_By_Copy (Full_View (Parent_Base)));
6805 Set_Component_Alignment
6806 (Derived_Type, Component_Alignment (Parent_Base));
6809 (Derived_Type, C_Pass_By_Copy (Parent_Base));
6813 -- Set fields for tagged types
6816 Set_Primitive_Operations (Derived_Type, New_Elmt_List);
6818 -- All tagged types defined in Ada.Finalization are controlled
6820 if Chars (Scope (Derived_Type)) = Name_Finalization
6821 and then Chars (Scope (Scope (Derived_Type))) = Name_Ada
6822 and then Scope (Scope (Scope (Derived_Type))) = Standard_Standard
6824 Set_Is_Controlled (Derived_Type);
6826 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Base));
6829 Make_Class_Wide_Type (Derived_Type);
6830 Set_Is_Abstract_Type (Derived_Type, Abstract_Present (Type_Def));
6832 if Has_Discriminants (Derived_Type)
6833 and then Constraint_Present
6835 Set_Stored_Constraint
6836 (Derived_Type, Expand_To_Stored_Constraint (Parent_Base, Discs));
6839 if Ada_Version >= Ada_05 then
6841 Ifaces_List : Elist_Id;
6844 -- Checks rules 3.9.4 (13/2 and 14/2)
6846 if Comes_From_Source (Derived_Type)
6847 and then not Is_Private_Type (Derived_Type)
6848 and then Is_Interface (Parent_Type)
6849 and then not Is_Interface (Derived_Type)
6851 if Is_Task_Interface (Parent_Type) then
6853 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
6856 elsif Is_Protected_Interface (Parent_Type) then
6858 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
6863 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
6865 Check_Abstract_Interfaces (N, Type_Def);
6867 -- Ada 2005 (AI-251): Collect the list of progenitors that are
6868 -- not already in the parents.
6870 Collect_Abstract_Interfaces
6872 Ifaces_List => Ifaces_List,
6873 Exclude_Parent_Interfaces => True);
6874 Set_Abstract_Interfaces (Derived_Type, Ifaces_List);
6879 Set_Is_Packed (Derived_Type, Is_Packed (Parent_Base));
6880 Set_Has_Non_Standard_Rep
6881 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6884 -- STEP 4: Inherit components from the parent base and constrain them.
6885 -- Apply the second transformation described in point 6. above.
6887 if (not Is_Empty_Elmt_List (Discs) or else Inherit_Discrims)
6888 or else not Has_Discriminants (Parent_Type)
6889 or else not Is_Constrained (Parent_Type)
6893 Constrs := Discriminant_Constraint (Parent_Type);
6898 (N, Parent_Base, Derived_Type, Is_Tagged, Inherit_Discrims, Constrs);
6900 -- STEP 5a: Copy the parent record declaration for untagged types
6902 if not Is_Tagged then
6904 -- Discriminant_Constraint (Derived_Type) has been properly
6905 -- constructed. Save it and temporarily set it to Empty because we
6906 -- do not want the call to New_Copy_Tree below to mess this list.
6908 if Has_Discriminants (Derived_Type) then
6909 Save_Discr_Constr := Discriminant_Constraint (Derived_Type);
6910 Set_Discriminant_Constraint (Derived_Type, No_Elist);
6912 Save_Discr_Constr := No_Elist;
6915 -- Save the Etype field of Derived_Type. It is correctly set now,
6916 -- but the call to New_Copy tree may remap it to point to itself,
6917 -- which is not what we want. Ditto for the Next_Entity field.
6919 Save_Etype := Etype (Derived_Type);
6920 Save_Next_Entity := Next_Entity (Derived_Type);
6922 -- Assoc_List maps all stored discriminants in the Parent_Base to
6923 -- stored discriminants in the Derived_Type. It is fundamental that
6924 -- no types or itypes with discriminants other than the stored
6925 -- discriminants appear in the entities declared inside
6926 -- Derived_Type, since the back end cannot deal with it.
6930 (Parent (Parent_Base), Map => Assoc_List, New_Sloc => Loc);
6932 -- Restore the fields saved prior to the New_Copy_Tree call
6933 -- and compute the stored constraint.
6935 Set_Etype (Derived_Type, Save_Etype);
6936 Set_Next_Entity (Derived_Type, Save_Next_Entity);
6938 if Has_Discriminants (Derived_Type) then
6939 Set_Discriminant_Constraint
6940 (Derived_Type, Save_Discr_Constr);
6941 Set_Stored_Constraint
6942 (Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs));
6943 Replace_Components (Derived_Type, New_Decl);
6946 -- Insert the new derived type declaration
6948 Rewrite (N, New_Decl);
6950 -- STEP 5b: Complete the processing for record extensions in generics
6952 -- There is no completion for record extensions declared in the
6953 -- parameter part of a generic, so we need to complete processing for
6954 -- these generic record extensions here. The Record_Type_Definition call
6955 -- will change the Ekind of the components from E_Void to E_Component.
6957 elsif Private_Extension and then Is_Generic_Type (Derived_Type) then
6958 Record_Type_Definition (Empty, Derived_Type);
6960 -- STEP 5c: Process the record extension for non private tagged types
6962 elsif not Private_Extension then
6964 -- Add the _parent field in the derived type
6966 Expand_Record_Extension (Derived_Type, Type_Def);
6968 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
6969 -- implemented interfaces if we are in expansion mode
6972 and then Has_Abstract_Interfaces (Derived_Type)
6974 Add_Interface_Tag_Components (N, Derived_Type);
6977 -- Analyze the record extension
6979 Record_Type_Definition
6980 (Record_Extension_Part (Type_Def), Derived_Type);
6985 -- Nothing else to do if there is an error in the derivation.
6986 -- An unusual case: the full view may be derived from a type in an
6987 -- instance, when the partial view was used illegally as an actual
6988 -- in that instance, leading to a circular definition.
6990 if Etype (Derived_Type) = Any_Type
6991 or else Etype (Parent_Type) = Derived_Type
6996 -- Set delayed freeze and then derive subprograms, we need to do
6997 -- this in this order so that derived subprograms inherit the
6998 -- derived freeze if necessary.
7000 Set_Has_Delayed_Freeze (Derived_Type);
7002 if Derive_Subps then
7003 Derive_Subprograms (Parent_Type, Derived_Type);
7006 -- If we have a private extension which defines a constrained derived
7007 -- type mark as constrained here after we have derived subprograms. See
7008 -- comment on point 9. just above the body of Build_Derived_Record_Type.
7010 if Private_Extension and then Inherit_Discrims then
7011 if Constraint_Present and then not Is_Empty_Elmt_List (Discs) then
7012 Set_Is_Constrained (Derived_Type, True);
7013 Set_Discriminant_Constraint (Derived_Type, Discs);
7015 elsif Is_Constrained (Parent_Type) then
7017 (Derived_Type, True);
7018 Set_Discriminant_Constraint
7019 (Derived_Type, Discriminant_Constraint (Parent_Type));
7023 -- Update the class_wide type, which shares the now-completed
7024 -- entity list with its specific type.
7028 (Class_Wide_Type (Derived_Type), First_Entity (Derived_Type));
7030 (Class_Wide_Type (Derived_Type), Last_Entity (Derived_Type));
7033 -- Update the scope of anonymous access types of discriminants and other
7034 -- components, to prevent scope anomalies in gigi, when the derivation
7035 -- appears in a scope nested within that of the parent.
7041 D := First_Entity (Derived_Type);
7042 while Present (D) loop
7043 if Ekind (D) = E_Discriminant
7044 or else Ekind (D) = E_Component
7046 if Is_Itype (Etype (D))
7047 and then Ekind (Etype (D)) = E_Anonymous_Access_Type
7049 Set_Scope (Etype (D), Current_Scope);
7056 end Build_Derived_Record_Type;
7058 ------------------------
7059 -- Build_Derived_Type --
7060 ------------------------
7062 procedure Build_Derived_Type
7064 Parent_Type : Entity_Id;
7065 Derived_Type : Entity_Id;
7066 Is_Completion : Boolean;
7067 Derive_Subps : Boolean := True)
7069 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
7072 -- Set common attributes
7074 Set_Scope (Derived_Type, Current_Scope);
7076 Set_Ekind (Derived_Type, Ekind (Parent_Base));
7077 Set_Etype (Derived_Type, Parent_Base);
7078 Set_Has_Task (Derived_Type, Has_Task (Parent_Base));
7080 Set_Size_Info (Derived_Type, Parent_Type);
7081 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
7082 Set_Convention (Derived_Type, Convention (Parent_Type));
7083 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
7085 -- The derived type inherits the representation clauses of the parent.
7086 -- However, for a private type that is completed by a derivation, there
7087 -- may be operation attributes that have been specified already (stream
7088 -- attributes and External_Tag) and those must be provided. Finally,
7089 -- if the partial view is a private extension, the representation items
7090 -- of the parent have been inherited already, and should not be chained
7091 -- twice to the derived type.
7093 if Is_Tagged_Type (Parent_Type)
7094 and then Present (First_Rep_Item (Derived_Type))
7096 -- The existing items are either operational items or items inherited
7097 -- from a private extension declaration.
7101 -- Used to iterate over representation items of the derived type
7104 -- Last representation item of the (non-empty) representation
7105 -- item list of the derived type.
7107 Found : Boolean := False;
7110 Rep := First_Rep_Item (Derived_Type);
7112 while Present (Rep) loop
7113 if Rep = First_Rep_Item (Parent_Type) then
7118 Rep := Next_Rep_Item (Rep);
7120 if Present (Rep) then
7126 -- Here if we either encountered the parent type's first rep
7127 -- item on the derived type's rep item list (in which case
7128 -- Found is True, and we have nothing else to do), or if we
7129 -- reached the last rep item of the derived type, which is
7130 -- Last_Rep, in which case we further chain the parent type's
7131 -- rep items to those of the derived type.
7134 Set_Next_Rep_Item (Last_Rep, First_Rep_Item (Parent_Type));
7139 Set_First_Rep_Item (Derived_Type, First_Rep_Item (Parent_Type));
7142 case Ekind (Parent_Type) is
7143 when Numeric_Kind =>
7144 Build_Derived_Numeric_Type (N, Parent_Type, Derived_Type);
7147 Build_Derived_Array_Type (N, Parent_Type, Derived_Type);
7151 | Class_Wide_Kind =>
7152 Build_Derived_Record_Type
7153 (N, Parent_Type, Derived_Type, Derive_Subps);
7156 when Enumeration_Kind =>
7157 Build_Derived_Enumeration_Type (N, Parent_Type, Derived_Type);
7160 Build_Derived_Access_Type (N, Parent_Type, Derived_Type);
7162 when Incomplete_Or_Private_Kind =>
7163 Build_Derived_Private_Type
7164 (N, Parent_Type, Derived_Type, Is_Completion, Derive_Subps);
7166 -- For discriminated types, the derivation includes deriving
7167 -- primitive operations. For others it is done below.
7169 if Is_Tagged_Type (Parent_Type)
7170 or else Has_Discriminants (Parent_Type)
7171 or else (Present (Full_View (Parent_Type))
7172 and then Has_Discriminants (Full_View (Parent_Type)))
7177 when Concurrent_Kind =>
7178 Build_Derived_Concurrent_Type (N, Parent_Type, Derived_Type);
7181 raise Program_Error;
7184 if Etype (Derived_Type) = Any_Type then
7188 -- Set delayed freeze and then derive subprograms, we need to do this
7189 -- in this order so that derived subprograms inherit the derived freeze
7192 Set_Has_Delayed_Freeze (Derived_Type);
7193 if Derive_Subps then
7194 Derive_Subprograms (Parent_Type, Derived_Type);
7197 Set_Has_Primitive_Operations
7198 (Base_Type (Derived_Type), Has_Primitive_Operations (Parent_Type));
7199 end Build_Derived_Type;
7201 -----------------------
7202 -- Build_Discriminal --
7203 -----------------------
7205 procedure Build_Discriminal (Discrim : Entity_Id) is
7206 D_Minal : Entity_Id;
7207 CR_Disc : Entity_Id;
7210 -- A discriminal has the same name as the discriminant
7213 Make_Defining_Identifier (Sloc (Discrim),
7214 Chars => Chars (Discrim));
7216 Set_Ekind (D_Minal, E_In_Parameter);
7217 Set_Mechanism (D_Minal, Default_Mechanism);
7218 Set_Etype (D_Minal, Etype (Discrim));
7220 Set_Discriminal (Discrim, D_Minal);
7221 Set_Discriminal_Link (D_Minal, Discrim);
7223 -- For task types, build at once the discriminants of the corresponding
7224 -- record, which are needed if discriminants are used in entry defaults
7225 -- and in family bounds.
7227 if Is_Concurrent_Type (Current_Scope)
7228 or else Is_Limited_Type (Current_Scope)
7230 CR_Disc := Make_Defining_Identifier (Sloc (Discrim), Chars (Discrim));
7232 Set_Ekind (CR_Disc, E_In_Parameter);
7233 Set_Mechanism (CR_Disc, Default_Mechanism);
7234 Set_Etype (CR_Disc, Etype (Discrim));
7235 Set_Discriminal_Link (CR_Disc, Discrim);
7236 Set_CR_Discriminant (Discrim, CR_Disc);
7238 end Build_Discriminal;
7240 ------------------------------------
7241 -- Build_Discriminant_Constraints --
7242 ------------------------------------
7244 function Build_Discriminant_Constraints
7247 Derived_Def : Boolean := False) return Elist_Id
7249 C : constant Node_Id := Constraint (Def);
7250 Nb_Discr : constant Nat := Number_Discriminants (T);
7252 Discr_Expr : array (1 .. Nb_Discr) of Node_Id := (others => Empty);
7253 -- Saves the expression corresponding to a given discriminant in T
7255 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat;
7256 -- Return the Position number within array Discr_Expr of a discriminant
7257 -- D within the discriminant list of the discriminated type T.
7263 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat is
7267 Disc := First_Discriminant (T);
7268 for J in Discr_Expr'Range loop
7273 Next_Discriminant (Disc);
7276 -- Note: Since this function is called on discriminants that are
7277 -- known to belong to the discriminated type, falling through the
7278 -- loop with no match signals an internal compiler error.
7280 raise Program_Error;
7283 -- Declarations local to Build_Discriminant_Constraints
7287 Elist : constant Elist_Id := New_Elmt_List;
7295 Discrim_Present : Boolean := False;
7297 -- Start of processing for Build_Discriminant_Constraints
7300 -- The following loop will process positional associations only.
7301 -- For a positional association, the (single) discriminant is
7302 -- implicitly specified by position, in textual order (RM 3.7.2).
7304 Discr := First_Discriminant (T);
7305 Constr := First (Constraints (C));
7306 for D in Discr_Expr'Range loop
7307 exit when Nkind (Constr) = N_Discriminant_Association;
7310 Error_Msg_N ("too few discriminants given in constraint", C);
7311 return New_Elmt_List;
7313 elsif Nkind (Constr) = N_Range
7314 or else (Nkind (Constr) = N_Attribute_Reference
7316 Attribute_Name (Constr) = Name_Range)
7319 ("a range is not a valid discriminant constraint", Constr);
7320 Discr_Expr (D) := Error;
7323 Analyze_And_Resolve (Constr, Base_Type (Etype (Discr)));
7324 Discr_Expr (D) := Constr;
7327 Next_Discriminant (Discr);
7331 if No (Discr) and then Present (Constr) then
7332 Error_Msg_N ("too many discriminants given in constraint", Constr);
7333 return New_Elmt_List;
7336 -- Named associations can be given in any order, but if both positional
7337 -- and named associations are used in the same discriminant constraint,
7338 -- then positional associations must occur first, at their normal
7339 -- position. Hence once a named association is used, the rest of the
7340 -- discriminant constraint must use only named associations.
7342 while Present (Constr) loop
7344 -- Positional association forbidden after a named association
7346 if Nkind (Constr) /= N_Discriminant_Association then
7347 Error_Msg_N ("positional association follows named one", Constr);
7348 return New_Elmt_List;
7350 -- Otherwise it is a named association
7353 -- E records the type of the discriminants in the named
7354 -- association. All the discriminants specified in the same name
7355 -- association must have the same type.
7359 -- Search the list of discriminants in T to see if the simple name
7360 -- given in the constraint matches any of them.
7362 Id := First (Selector_Names (Constr));
7363 while Present (Id) loop
7366 -- If Original_Discriminant is present, we are processing a
7367 -- generic instantiation and this is an instance node. We need
7368 -- to find the name of the corresponding discriminant in the
7369 -- actual record type T and not the name of the discriminant in
7370 -- the generic formal. Example:
7373 -- type G (D : int) is private;
7375 -- subtype W is G (D => 1);
7377 -- type Rec (X : int) is record ... end record;
7378 -- package Q is new P (G => Rec);
7380 -- At the point of the instantiation, formal type G is Rec
7381 -- and therefore when reanalyzing "subtype W is G (D => 1);"
7382 -- which really looks like "subtype W is Rec (D => 1);" at
7383 -- the point of instantiation, we want to find the discriminant
7384 -- that corresponds to D in Rec, ie X.
7386 if Present (Original_Discriminant (Id)) then
7387 Discr := Find_Corresponding_Discriminant (Id, T);
7391 Discr := First_Discriminant (T);
7392 while Present (Discr) loop
7393 if Chars (Discr) = Chars (Id) then
7398 Next_Discriminant (Discr);
7402 Error_Msg_N ("& does not match any discriminant", Id);
7403 return New_Elmt_List;
7405 -- The following is only useful for the benefit of generic
7406 -- instances but it does not interfere with other
7407 -- processing for the non-generic case so we do it in all
7408 -- cases (for generics this statement is executed when
7409 -- processing the generic definition, see comment at the
7410 -- beginning of this if statement).
7413 Set_Original_Discriminant (Id, Discr);
7417 Position := Pos_Of_Discr (T, Discr);
7419 if Present (Discr_Expr (Position)) then
7420 Error_Msg_N ("duplicate constraint for discriminant&", Id);
7423 -- Each discriminant specified in the same named association
7424 -- must be associated with a separate copy of the
7425 -- corresponding expression.
7427 if Present (Next (Id)) then
7428 Expr := New_Copy_Tree (Expression (Constr));
7429 Set_Parent (Expr, Parent (Expression (Constr)));
7431 Expr := Expression (Constr);
7434 Discr_Expr (Position) := Expr;
7435 Analyze_And_Resolve (Expr, Base_Type (Etype (Discr)));
7438 -- A discriminant association with more than one discriminant
7439 -- name is only allowed if the named discriminants are all of
7440 -- the same type (RM 3.7.1(8)).
7443 E := Base_Type (Etype (Discr));
7445 elsif Base_Type (Etype (Discr)) /= E then
7447 ("all discriminants in an association " &
7448 "must have the same type", Id);
7458 -- A discriminant constraint must provide exactly one value for each
7459 -- discriminant of the type (RM 3.7.1(8)).
7461 for J in Discr_Expr'Range loop
7462 if No (Discr_Expr (J)) then
7463 Error_Msg_N ("too few discriminants given in constraint", C);
7464 return New_Elmt_List;
7468 -- Determine if there are discriminant expressions in the constraint
7470 for J in Discr_Expr'Range loop
7471 if Denotes_Discriminant
7472 (Discr_Expr (J), Check_Concurrent => True)
7474 Discrim_Present := True;
7478 -- Build an element list consisting of the expressions given in the
7479 -- discriminant constraint and apply the appropriate checks. The list
7480 -- is constructed after resolving any named discriminant associations
7481 -- and therefore the expressions appear in the textual order of the
7484 Discr := First_Discriminant (T);
7485 for J in Discr_Expr'Range loop
7486 if Discr_Expr (J) /= Error then
7487 Append_Elmt (Discr_Expr (J), Elist);
7489 -- If any of the discriminant constraints is given by a
7490 -- discriminant and we are in a derived type declaration we
7491 -- have a discriminant renaming. Establish link between new
7492 -- and old discriminant.
7494 if Denotes_Discriminant (Discr_Expr (J)) then
7496 Set_Corresponding_Discriminant
7497 (Entity (Discr_Expr (J)), Discr);
7500 -- Force the evaluation of non-discriminant expressions.
7501 -- If we have found a discriminant in the constraint 3.4(26)
7502 -- and 3.8(18) demand that no range checks are performed are
7503 -- after evaluation. If the constraint is for a component
7504 -- definition that has a per-object constraint, expressions are
7505 -- evaluated but not checked either. In all other cases perform
7509 if Discrim_Present then
7512 elsif Nkind (Parent (Parent (Def))) = N_Component_Declaration
7514 Has_Per_Object_Constraint
7515 (Defining_Identifier (Parent (Parent (Def))))
7519 elsif Is_Access_Type (Etype (Discr)) then
7520 Apply_Constraint_Check (Discr_Expr (J), Etype (Discr));
7523 Apply_Range_Check (Discr_Expr (J), Etype (Discr));
7526 Force_Evaluation (Discr_Expr (J));
7529 -- Check that the designated type of an access discriminant's
7530 -- expression is not a class-wide type unless the discriminant's
7531 -- designated type is also class-wide.
7533 if Ekind (Etype (Discr)) = E_Anonymous_Access_Type
7534 and then not Is_Class_Wide_Type
7535 (Designated_Type (Etype (Discr)))
7536 and then Etype (Discr_Expr (J)) /= Any_Type
7537 and then Is_Class_Wide_Type
7538 (Designated_Type (Etype (Discr_Expr (J))))
7540 Wrong_Type (Discr_Expr (J), Etype (Discr));
7544 Next_Discriminant (Discr);
7548 end Build_Discriminant_Constraints;
7550 ---------------------------------
7551 -- Build_Discriminated_Subtype --
7552 ---------------------------------
7554 procedure Build_Discriminated_Subtype
7558 Related_Nod : Node_Id;
7559 For_Access : Boolean := False)
7561 Has_Discrs : constant Boolean := Has_Discriminants (T);
7562 Constrained : constant Boolean :=
7564 and then not Is_Empty_Elmt_List (Elist)
7565 and then not Is_Class_Wide_Type (T))
7566 or else Is_Constrained (T);
7569 if Ekind (T) = E_Record_Type then
7571 Set_Ekind (Def_Id, E_Private_Subtype);
7572 Set_Is_For_Access_Subtype (Def_Id, True);
7574 Set_Ekind (Def_Id, E_Record_Subtype);
7577 -- Inherit preelaboration flag from base, for types for which it
7578 -- may have been set: records, private types, protected types.
7580 Set_Known_To_Have_Preelab_Init
7581 (Def_Id, Known_To_Have_Preelab_Init (T));
7583 elsif Ekind (T) = E_Task_Type then
7584 Set_Ekind (Def_Id, E_Task_Subtype);
7586 elsif Ekind (T) = E_Protected_Type then
7587 Set_Ekind (Def_Id, E_Protected_Subtype);
7588 Set_Known_To_Have_Preelab_Init
7589 (Def_Id, Known_To_Have_Preelab_Init (T));
7591 elsif Is_Private_Type (T) then
7592 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
7593 Set_Known_To_Have_Preelab_Init
7594 (Def_Id, Known_To_Have_Preelab_Init (T));
7596 elsif Is_Class_Wide_Type (T) then
7597 Set_Ekind (Def_Id, E_Class_Wide_Subtype);
7600 -- Incomplete type. Attach subtype to list of dependents, to be
7601 -- completed with full view of parent type, unless is it the
7602 -- designated subtype of a record component within an init_proc.
7603 -- This last case arises for a component of an access type whose
7604 -- designated type is incomplete (e.g. a Taft Amendment type).
7605 -- The designated subtype is within an inner scope, and needs no
7606 -- elaboration, because only the access type is needed in the
7607 -- initialization procedure.
7609 Set_Ekind (Def_Id, Ekind (T));
7611 if For_Access and then Within_Init_Proc then
7614 Append_Elmt (Def_Id, Private_Dependents (T));
7618 Set_Etype (Def_Id, T);
7619 Init_Size_Align (Def_Id);
7620 Set_Has_Discriminants (Def_Id, Has_Discrs);
7621 Set_Is_Constrained (Def_Id, Constrained);
7623 Set_First_Entity (Def_Id, First_Entity (T));
7624 Set_Last_Entity (Def_Id, Last_Entity (T));
7625 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
7627 if Is_Tagged_Type (T) then
7628 Set_Is_Tagged_Type (Def_Id);
7629 Make_Class_Wide_Type (Def_Id);
7632 Set_Stored_Constraint (Def_Id, No_Elist);
7635 Set_Discriminant_Constraint (Def_Id, Elist);
7636 Set_Stored_Constraint_From_Discriminant_Constraint (Def_Id);
7639 if Is_Tagged_Type (T) then
7641 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
7642 -- concurrent record type (which has the list of primitive
7645 if Ada_Version >= Ada_05
7646 and then Is_Concurrent_Type (T)
7648 Set_Corresponding_Record_Type (Def_Id,
7649 Corresponding_Record_Type (T));
7651 Set_Primitive_Operations (Def_Id, Primitive_Operations (T));
7654 Set_Is_Abstract_Type (Def_Id, Is_Abstract_Type (T));
7657 -- Subtypes introduced by component declarations do not need to be
7658 -- marked as delayed, and do not get freeze nodes, because the semantics
7659 -- verifies that the parents of the subtypes are frozen before the
7660 -- enclosing record is frozen.
7662 if not Is_Type (Scope (Def_Id)) then
7663 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
7665 if Is_Private_Type (T)
7666 and then Present (Full_View (T))
7668 Conditional_Delay (Def_Id, Full_View (T));
7670 Conditional_Delay (Def_Id, T);
7674 if Is_Record_Type (T) then
7675 Set_Is_Limited_Record (Def_Id, Is_Limited_Record (T));
7678 and then not Is_Empty_Elmt_List (Elist)
7679 and then not For_Access
7681 Create_Constrained_Components (Def_Id, Related_Nod, T, Elist);
7682 elsif not For_Access then
7683 Set_Cloned_Subtype (Def_Id, T);
7686 end Build_Discriminated_Subtype;
7688 ---------------------------
7689 -- Build_Itype_Reference --
7690 ---------------------------
7692 procedure Build_Itype_Reference
7696 IR : constant Node_Id := Make_Itype_Reference (Sloc (Nod));
7698 Set_Itype (IR, Ityp);
7699 Insert_After (Nod, IR);
7700 end Build_Itype_Reference;
7702 ------------------------
7703 -- Build_Scalar_Bound --
7704 ------------------------
7706 function Build_Scalar_Bound
7709 Der_T : Entity_Id) return Node_Id
7711 New_Bound : Entity_Id;
7714 -- Note: not clear why this is needed, how can the original bound
7715 -- be unanalyzed at this point? and if it is, what business do we
7716 -- have messing around with it? and why is the base type of the
7717 -- parent type the right type for the resolution. It probably is
7718 -- not! It is OK for the new bound we are creating, but not for
7719 -- the old one??? Still if it never happens, no problem!
7721 Analyze_And_Resolve (Bound, Base_Type (Par_T));
7723 if Nkind_In (Bound, N_Integer_Literal, N_Real_Literal) then
7724 New_Bound := New_Copy (Bound);
7725 Set_Etype (New_Bound, Der_T);
7726 Set_Analyzed (New_Bound);
7728 elsif Is_Entity_Name (Bound) then
7729 New_Bound := OK_Convert_To (Der_T, New_Copy (Bound));
7731 -- The following is almost certainly wrong. What business do we have
7732 -- relocating a node (Bound) that is presumably still attached to
7733 -- the tree elsewhere???
7736 New_Bound := OK_Convert_To (Der_T, Relocate_Node (Bound));
7739 Set_Etype (New_Bound, Der_T);
7741 end Build_Scalar_Bound;
7743 --------------------------------
7744 -- Build_Underlying_Full_View --
7745 --------------------------------
7747 procedure Build_Underlying_Full_View
7752 Loc : constant Source_Ptr := Sloc (N);
7753 Subt : constant Entity_Id :=
7754 Make_Defining_Identifier
7755 (Loc, New_External_Name (Chars (Typ), 'S'));
7762 procedure Set_Discriminant_Name (Id : Node_Id);
7763 -- If the derived type has discriminants, they may rename discriminants
7764 -- of the parent. When building the full view of the parent, we need to
7765 -- recover the names of the original discriminants if the constraint is
7766 -- given by named associations.
7768 ---------------------------
7769 -- Set_Discriminant_Name --
7770 ---------------------------
7772 procedure Set_Discriminant_Name (Id : Node_Id) is
7776 Set_Original_Discriminant (Id, Empty);
7778 if Has_Discriminants (Typ) then
7779 Disc := First_Discriminant (Typ);
7780 while Present (Disc) loop
7781 if Chars (Disc) = Chars (Id)
7782 and then Present (Corresponding_Discriminant (Disc))
7784 Set_Chars (Id, Chars (Corresponding_Discriminant (Disc)));
7786 Next_Discriminant (Disc);
7789 end Set_Discriminant_Name;
7791 -- Start of processing for Build_Underlying_Full_View
7794 if Nkind (N) = N_Full_Type_Declaration then
7795 Constr := Constraint (Subtype_Indication (Type_Definition (N)));
7797 elsif Nkind (N) = N_Subtype_Declaration then
7798 Constr := New_Copy_Tree (Constraint (Subtype_Indication (N)));
7800 elsif Nkind (N) = N_Component_Declaration then
7803 (Constraint (Subtype_Indication (Component_Definition (N))));
7806 raise Program_Error;
7809 C := First (Constraints (Constr));
7810 while Present (C) loop
7811 if Nkind (C) = N_Discriminant_Association then
7812 Id := First (Selector_Names (C));
7813 while Present (Id) loop
7814 Set_Discriminant_Name (Id);
7823 Make_Subtype_Declaration (Loc,
7824 Defining_Identifier => Subt,
7825 Subtype_Indication =>
7826 Make_Subtype_Indication (Loc,
7827 Subtype_Mark => New_Reference_To (Par, Loc),
7828 Constraint => New_Copy_Tree (Constr)));
7830 -- If this is a component subtype for an outer itype, it is not
7831 -- a list member, so simply set the parent link for analysis: if
7832 -- the enclosing type does not need to be in a declarative list,
7833 -- neither do the components.
7835 if Is_List_Member (N)
7836 and then Nkind (N) /= N_Component_Declaration
7838 Insert_Before (N, Indic);
7840 Set_Parent (Indic, Parent (N));
7844 Set_Underlying_Full_View (Typ, Full_View (Subt));
7845 end Build_Underlying_Full_View;
7847 -------------------------------
7848 -- Check_Abstract_Interfaces --
7849 -------------------------------
7851 procedure Check_Abstract_Interfaces (N : Node_Id; Def : Node_Id) is
7852 Parent_Type : constant Entity_Id := Etype (Defining_Identifier (N));
7855 Iface_Def : Node_Id;
7856 Iface_Typ : Entity_Id;
7857 Parent_Node : Node_Id;
7859 Is_Task : Boolean := False;
7860 -- Set True if parent type or any progenitor is a task interface
7862 Is_Protected : Boolean := False;
7863 -- Set True if parent type or any progenitor is a protected interface
7865 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id);
7866 -- Check that a progenitor is compatible with declaration.
7867 -- Error is posted on Error_Node.
7873 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id) is
7874 Iface_Id : constant Entity_Id :=
7875 Defining_Identifier (Parent (Iface_Def));
7879 if Nkind (N) = N_Private_Extension_Declaration then
7882 Type_Def := Type_Definition (N);
7885 if Is_Task_Interface (Iface_Id) then
7888 elsif Is_Protected_Interface (Iface_Id) then
7889 Is_Protected := True;
7892 -- Check that the characteristics of the progenitor are compatible
7893 -- with the explicit qualifier in the declaration.
7894 -- The check only applies to qualifiers that come from source.
7895 -- Limited_Present also appears in the declaration of corresponding
7896 -- records, and the check does not apply to them.
7898 if Limited_Present (Type_Def)
7900 Is_Concurrent_Record_Type (Defining_Identifier (N))
7902 if Is_Limited_Interface (Parent_Type)
7903 and then not Is_Limited_Interface (Iface_Id)
7906 ("progenitor& must be limited interface",
7907 Error_Node, Iface_Id);
7910 (Task_Present (Iface_Def)
7911 or else Protected_Present (Iface_Def)
7912 or else Synchronized_Present (Iface_Def))
7913 and then Nkind (N) /= N_Private_Extension_Declaration
7916 ("progenitor& must be limited interface",
7917 Error_Node, Iface_Id);
7920 -- Protected interfaces can only inherit from limited, synchronized
7921 -- or protected interfaces.
7923 elsif Nkind (N) = N_Full_Type_Declaration
7924 and then Protected_Present (Type_Def)
7926 if Limited_Present (Iface_Def)
7927 or else Synchronized_Present (Iface_Def)
7928 or else Protected_Present (Iface_Def)
7932 elsif Task_Present (Iface_Def) then
7933 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
7934 & " from task interface", Error_Node);
7937 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
7938 & " from non-limited interface", Error_Node);
7941 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
7942 -- limited and synchronized.
7944 elsif Synchronized_Present (Type_Def) then
7945 if Limited_Present (Iface_Def)
7946 or else Synchronized_Present (Iface_Def)
7950 elsif Protected_Present (Iface_Def)
7951 and then Nkind (N) /= N_Private_Extension_Declaration
7953 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
7954 & " from protected interface", Error_Node);
7956 elsif Task_Present (Iface_Def)
7957 and then Nkind (N) /= N_Private_Extension_Declaration
7959 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
7960 & " from task interface", Error_Node);
7962 elsif not Is_Limited_Interface (Iface_Id) then
7963 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
7964 & " from non-limited interface", Error_Node);
7967 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
7968 -- synchronized or task interfaces.
7970 elsif Nkind (N) = N_Full_Type_Declaration
7971 and then Task_Present (Type_Def)
7973 if Limited_Present (Iface_Def)
7974 or else Synchronized_Present (Iface_Def)
7975 or else Task_Present (Iface_Def)
7979 elsif Protected_Present (Iface_Def) then
7980 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
7981 & " protected interface", Error_Node);
7984 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
7985 & " non-limited interface", Error_Node);
7990 -- Start of processing for Check_Abstract_Interfaces
7993 if Is_Interface (Parent_Type) then
7994 if Is_Task_Interface (Parent_Type) then
7997 elsif Is_Protected_Interface (Parent_Type) then
7998 Is_Protected := True;
8002 if Nkind (N) = N_Private_Extension_Declaration then
8004 -- Check that progenitors are compatible with declaration
8006 Iface := First (Interface_List (Def));
8007 while Present (Iface) loop
8008 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8010 Parent_Node := Parent (Base_Type (Iface_Typ));
8011 Iface_Def := Type_Definition (Parent_Node);
8013 if not Is_Interface (Iface_Typ) then
8014 Error_Msg_NE ("(Ada 2005) & must be an interface",
8018 Check_Ifaces (Iface_Def, Iface);
8024 if Is_Task and Is_Protected then
8026 ("type cannot derive from task and protected interface", N);
8032 -- Full type declaration of derived type.
8033 -- Check compatibility with parent if it is interface type
8035 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition
8036 and then Is_Interface (Parent_Type)
8038 Parent_Node := Parent (Parent_Type);
8040 -- More detailed checks for interface varieties
8043 (Iface_Def => Type_Definition (Parent_Node),
8044 Error_Node => Subtype_Indication (Type_Definition (N)));
8047 Iface := First (Interface_List (Def));
8049 while Present (Iface) loop
8050 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8052 Parent_Node := Parent (Base_Type (Iface_Typ));
8053 Iface_Def := Type_Definition (Parent_Node);
8055 if not Is_Interface (Iface_Typ) then
8056 Error_Msg_NE ("(Ada 2005) & must be an interface",
8060 -- "The declaration of a specific descendant of an interface
8061 -- type freezes the interface type" RM 13.14
8063 Freeze_Before (N, Iface_Typ);
8064 Check_Ifaces (Iface_Def, Error_Node => Iface);
8070 if Is_Task and Is_Protected then
8072 ("type cannot derive from task and protected interface", N);
8075 end Check_Abstract_Interfaces;
8077 -------------------------------
8078 -- Check_Abstract_Overriding --
8079 -------------------------------
8081 procedure Check_Abstract_Overriding (T : Entity_Id) is
8082 Alias_Subp : Entity_Id;
8089 Op_List := Primitive_Operations (T);
8091 -- Loop to check primitive operations
8093 Elmt := First_Elmt (Op_List);
8094 while Present (Elmt) loop
8095 Subp := Node (Elmt);
8096 Alias_Subp := Alias (Subp);
8098 -- Inherited subprograms are identified by the fact that they do not
8099 -- come from source, and the associated source location is the
8100 -- location of the first subtype of the derived type.
8102 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
8103 -- subprograms that "require overriding".
8105 -- Special exception, do not complain about failure to override the
8106 -- stream routines _Input and _Output, as well as the primitive
8107 -- operations used in dispatching selects since we always provide
8108 -- automatic overridings for these subprograms.
8110 -- Also ignore this rule for convention CIL since .NET libraries
8111 -- do bizarre things with interfaces???
8113 -- The partial view of T may have been a private extension, for
8114 -- which inherited functions dispatching on result are abstract.
8115 -- If the full view is a null extension, there is no need for
8116 -- overriding in Ada2005, but wrappers need to be built for them
8117 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
8119 if Is_Null_Extension (T)
8120 and then Has_Controlling_Result (Subp)
8121 and then Ada_Version >= Ada_05
8122 and then Present (Alias (Subp))
8123 and then not Comes_From_Source (Subp)
8124 and then not Is_Abstract_Subprogram (Alias (Subp))
8125 and then not Is_Access_Type (Etype (Subp))
8129 elsif (Is_Abstract_Subprogram (Subp)
8130 or else Requires_Overriding (Subp)
8132 (Has_Controlling_Result (Subp)
8133 and then Present (Alias_Subp)
8134 and then not Comes_From_Source (Subp)
8135 and then Sloc (Subp) = Sloc (First_Subtype (T))))
8136 and then not Is_TSS (Subp, TSS_Stream_Input)
8137 and then not Is_TSS (Subp, TSS_Stream_Output)
8138 and then not Is_Abstract_Type (T)
8139 and then Convention (T) /= Convention_CIL
8140 and then Chars (Subp) /= Name_uDisp_Asynchronous_Select
8141 and then Chars (Subp) /= Name_uDisp_Conditional_Select
8142 and then Chars (Subp) /= Name_uDisp_Get_Prim_Op_Kind
8143 and then Chars (Subp) /= Name_uDisp_Requeue
8144 and then Chars (Subp) /= Name_uDisp_Timed_Select
8146 -- Ada 2005 (AI-251): Do not consider hidden entities associated
8147 -- with abstract interface types because the check will be done
8148 -- with the aliased entity (otherwise we generate a duplicated
8151 and then not Present (Abstract_Interface_Alias (Subp))
8153 if Present (Alias_Subp) then
8155 -- Only perform the check for a derived subprogram when the
8156 -- type has an explicit record extension. This avoids incorect
8157 -- flagging of abstract subprograms for the case of a type
8158 -- without an extension that is derived from a formal type
8159 -- with a tagged actual (can occur within a private part).
8161 -- Ada 2005 (AI-391): In the case of an inherited function with
8162 -- a controlling result of the type, the rule does not apply if
8163 -- the type is a null extension (unless the parent function
8164 -- itself is abstract, in which case the function must still be
8165 -- be overridden). The expander will generate an overriding
8166 -- wrapper function calling the parent subprogram (see
8167 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
8169 Type_Def := Type_Definition (Parent (T));
8171 if Nkind (Type_Def) = N_Derived_Type_Definition
8172 and then Present (Record_Extension_Part (Type_Def))
8174 (Ada_Version < Ada_05
8175 or else not Is_Null_Extension (T)
8176 or else Ekind (Subp) = E_Procedure
8177 or else not Has_Controlling_Result (Subp)
8178 or else Is_Abstract_Subprogram (Alias_Subp)
8179 or else Requires_Overriding (Subp)
8180 or else Is_Access_Type (Etype (Subp)))
8182 -- The body of predefined primitives of tagged types derived
8183 -- from interface types are generated later by Freeze_Type.
8185 if Is_Predefined_Dispatching_Operation (Subp)
8186 and then Is_Abstract_Subprogram (Alias_Subp)
8187 and then Is_Interface
8188 (Root_Type (Find_Dispatching_Type (Subp)))
8194 ("type must be declared abstract or & overridden",
8197 -- Traverse the whole chain of aliased subprograms to
8198 -- complete the error notification. This is especially
8199 -- useful for traceability of the chain of entities when
8200 -- the subprogram corresponds with an interface
8201 -- subprogram (which may be defined in another package).
8203 if Present (Alias_Subp) then
8209 while Present (Alias (E)) loop
8210 Error_Msg_Sloc := Sloc (E);
8212 ("\& has been inherited #", T, Subp);
8216 Error_Msg_Sloc := Sloc (E);
8218 ("\& has been inherited from subprogram #",
8224 -- Ada 2005 (AI-345): Protected or task type implementing
8225 -- abstract interfaces.
8227 elsif Is_Concurrent_Record_Type (T)
8228 and then Present (Abstract_Interfaces (T))
8230 -- The controlling formal of Subp must be of mode "out",
8231 -- "in out" or an access-to-variable to be overridden.
8233 -- Error message below needs rewording (remember comma
8234 -- in -gnatj mode) ???
8236 if Ekind (First_Formal (Subp)) = E_In_Parameter then
8238 ("first formal of & must be of mode `OUT`, `IN OUT` " &
8239 "or access-to-variable", T, Subp);
8241 ("\to be overridden by protected procedure or " &
8242 "entry (RM 9.4(11.9/2))", T);
8244 -- Some other kind of overriding failure
8248 ("interface subprogram & must be overridden",
8254 Error_Msg_Node_2 := T;
8256 ("abstract subprogram& not allowed for type&", Subp);
8258 -- Also post unconditional warning on the type (unconditional
8259 -- so that if there are more than one of these cases, we get
8260 -- them all, and not just the first one).
8262 Error_Msg_Node_2 := Subp;
8264 ("nonabstract type& has abstract subprogram&!", T);
8268 -- Ada 2005 (AI05-0030): Inspect hidden subprograms which provide
8269 -- the mapping between interface and implementing type primitives.
8270 -- If the interface alias is marked as Implemented_By_Entry, the
8271 -- alias must be an entry wrapper.
8273 if Ada_Version >= Ada_05
8274 and then Is_Hidden (Subp)
8275 and then Present (Abstract_Interface_Alias (Subp))
8276 and then Implemented_By_Entry (Abstract_Interface_Alias (Subp))
8277 and then Present (Alias_Subp)
8279 (not Is_Primitive_Wrapper (Alias_Subp)
8280 or else Ekind (Wrapped_Entity (Alias_Subp)) /= E_Entry)
8283 Error_Ent : Entity_Id := T;
8286 if Is_Concurrent_Record_Type (Error_Ent) then
8287 Error_Ent := Corresponding_Concurrent_Type (Error_Ent);
8290 Error_Msg_Node_2 := Abstract_Interface_Alias (Subp);
8292 ("type & must implement abstract subprogram & with an entry",
8293 Error_Ent, Error_Ent);
8299 end Check_Abstract_Overriding;
8301 ------------------------------------------------
8302 -- Check_Access_Discriminant_Requires_Limited --
8303 ------------------------------------------------
8305 procedure Check_Access_Discriminant_Requires_Limited
8310 -- A discriminant_specification for an access discriminant shall appear
8311 -- only in the declaration for a task or protected type, or for a type
8312 -- with the reserved word 'limited' in its definition or in one of its
8313 -- ancestors. (RM 3.7(10))
8315 if Nkind (Discriminant_Type (D)) = N_Access_Definition
8316 and then not Is_Concurrent_Type (Current_Scope)
8317 and then not Is_Concurrent_Record_Type (Current_Scope)
8318 and then not Is_Limited_Record (Current_Scope)
8319 and then Ekind (Current_Scope) /= E_Limited_Private_Type
8322 ("access discriminants allowed only for limited types", Loc);
8324 end Check_Access_Discriminant_Requires_Limited;
8326 -----------------------------------
8327 -- Check_Aliased_Component_Types --
8328 -----------------------------------
8330 procedure Check_Aliased_Component_Types (T : Entity_Id) is
8334 -- ??? Also need to check components of record extensions, but not
8335 -- components of protected types (which are always limited).
8337 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
8338 -- types to be unconstrained. This is safe because it is illegal to
8339 -- create access subtypes to such types with explicit discriminant
8342 if not Is_Limited_Type (T) then
8343 if Ekind (T) = E_Record_Type then
8344 C := First_Component (T);
8345 while Present (C) loop
8347 and then Has_Discriminants (Etype (C))
8348 and then not Is_Constrained (Etype (C))
8349 and then not In_Instance_Body
8350 and then Ada_Version < Ada_05
8353 ("aliased component must be constrained (RM 3.6(11))",
8360 elsif Ekind (T) = E_Array_Type then
8361 if Has_Aliased_Components (T)
8362 and then Has_Discriminants (Component_Type (T))
8363 and then not Is_Constrained (Component_Type (T))
8364 and then not In_Instance_Body
8365 and then Ada_Version < Ada_05
8368 ("aliased component type must be constrained (RM 3.6(11))",
8373 end Check_Aliased_Component_Types;
8375 ----------------------
8376 -- Check_Completion --
8377 ----------------------
8379 procedure Check_Completion (Body_Id : Node_Id := Empty) is
8382 procedure Post_Error;
8383 -- Post error message for lack of completion for entity E
8389 procedure Post_Error is
8391 if not Comes_From_Source (E) then
8393 if Ekind (E) = E_Task_Type
8394 or else Ekind (E) = E_Protected_Type
8396 -- It may be an anonymous protected type created for a
8397 -- single variable. Post error on variable, if present.
8403 Var := First_Entity (Current_Scope);
8404 while Present (Var) loop
8405 exit when Etype (Var) = E
8406 and then Comes_From_Source (Var);
8411 if Present (Var) then
8418 -- If a generated entity has no completion, then either previous
8419 -- semantic errors have disabled the expansion phase, or else we had
8420 -- missing subunits, or else we are compiling without expansion,
8421 -- or else something is very wrong.
8423 if not Comes_From_Source (E) then
8425 (Serious_Errors_Detected > 0
8426 or else Configurable_Run_Time_Violations > 0
8427 or else Subunits_Missing
8428 or else not Expander_Active);
8431 -- Here for source entity
8434 -- Here if no body to post the error message, so we post the error
8435 -- on the declaration that has no completion. This is not really
8436 -- the right place to post it, think about this later ???
8438 if No (Body_Id) then
8441 ("missing full declaration for }", Parent (E), E);
8444 ("missing body for &", Parent (E), E);
8447 -- Package body has no completion for a declaration that appears
8448 -- in the corresponding spec. Post error on the body, with a
8449 -- reference to the non-completed declaration.
8452 Error_Msg_Sloc := Sloc (E);
8456 ("missing full declaration for }!", Body_Id, E);
8458 elsif Is_Overloadable (E)
8459 and then Current_Entity_In_Scope (E) /= E
8461 -- It may be that the completion is mistyped and appears as
8462 -- a distinct overloading of the entity.
8465 Candidate : constant Entity_Id :=
8466 Current_Entity_In_Scope (E);
8467 Decl : constant Node_Id :=
8468 Unit_Declaration_Node (Candidate);
8471 if Is_Overloadable (Candidate)
8472 and then Ekind (Candidate) = Ekind (E)
8473 and then Nkind (Decl) = N_Subprogram_Body
8474 and then Acts_As_Spec (Decl)
8476 Check_Type_Conformant (Candidate, E);
8479 Error_Msg_NE ("missing body for & declared#!",
8484 Error_Msg_NE ("missing body for & declared#!",
8491 -- Start processing for Check_Completion
8494 E := First_Entity (Current_Scope);
8495 while Present (E) loop
8496 if Is_Intrinsic_Subprogram (E) then
8499 -- The following situation requires special handling: a child unit
8500 -- that appears in the context clause of the body of its parent:
8502 -- procedure Parent.Child (...);
8504 -- with Parent.Child;
8505 -- package body Parent is
8507 -- Here Parent.Child appears as a local entity, but should not be
8508 -- flagged as requiring completion, because it is a compilation
8511 -- Ignore missing completion for a subprogram that does not come from
8512 -- source (including the _Call primitive operation of RAS types,
8513 -- which has to have the flag Comes_From_Source for other purposes):
8514 -- we assume that the expander will provide the missing completion.
8516 elsif Ekind (E) = E_Function
8517 or else Ekind (E) = E_Procedure
8518 or else Ekind (E) = E_Generic_Function
8519 or else Ekind (E) = E_Generic_Procedure
8521 if not Has_Completion (E)
8522 and then not (Is_Subprogram (E)
8523 and then Is_Abstract_Subprogram (E))
8524 and then not (Is_Subprogram (E)
8526 (not Comes_From_Source (E)
8527 or else Chars (E) = Name_uCall))
8528 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8530 and then Chars (E) /= Name_uSize
8535 elsif Is_Entry (E) then
8536 if not Has_Completion (E) and then
8537 (Ekind (Scope (E)) = E_Protected_Object
8538 or else Ekind (Scope (E)) = E_Protected_Type)
8543 elsif Is_Package_Or_Generic_Package (E) then
8544 if Unit_Requires_Body (E) then
8545 if not Has_Completion (E)
8546 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8552 elsif not Is_Child_Unit (E) then
8553 May_Need_Implicit_Body (E);
8556 elsif Ekind (E) = E_Incomplete_Type
8557 and then No (Underlying_Type (E))
8561 elsif (Ekind (E) = E_Task_Type or else
8562 Ekind (E) = E_Protected_Type)
8563 and then not Has_Completion (E)
8567 -- A single task declared in the current scope is a constant, verify
8568 -- that the body of its anonymous type is in the same scope. If the
8569 -- task is defined elsewhere, this may be a renaming declaration for
8570 -- which no completion is needed.
8572 elsif Ekind (E) = E_Constant
8573 and then Ekind (Etype (E)) = E_Task_Type
8574 and then not Has_Completion (Etype (E))
8575 and then Scope (Etype (E)) = Current_Scope
8579 elsif Ekind (E) = E_Protected_Object
8580 and then not Has_Completion (Etype (E))
8584 elsif Ekind (E) = E_Record_Type then
8585 if Is_Tagged_Type (E) then
8586 Check_Abstract_Overriding (E);
8587 Check_Conventions (E);
8590 Check_Aliased_Component_Types (E);
8592 elsif Ekind (E) = E_Array_Type then
8593 Check_Aliased_Component_Types (E);
8599 end Check_Completion;
8601 ----------------------------
8602 -- Check_Delta_Expression --
8603 ----------------------------
8605 procedure Check_Delta_Expression (E : Node_Id) is
8607 if not (Is_Real_Type (Etype (E))) then
8608 Wrong_Type (E, Any_Real);
8610 elsif not Is_OK_Static_Expression (E) then
8611 Flag_Non_Static_Expr
8612 ("non-static expression used for delta value!", E);
8614 elsif not UR_Is_Positive (Expr_Value_R (E)) then
8615 Error_Msg_N ("delta expression must be positive", E);
8621 -- If any of above errors occurred, then replace the incorrect
8622 -- expression by the real 0.1, which should prevent further errors.
8625 Make_Real_Literal (Sloc (E), Ureal_Tenth));
8626 Analyze_And_Resolve (E, Standard_Float);
8627 end Check_Delta_Expression;
8629 -----------------------------
8630 -- Check_Digits_Expression --
8631 -----------------------------
8633 procedure Check_Digits_Expression (E : Node_Id) is
8635 if not (Is_Integer_Type (Etype (E))) then
8636 Wrong_Type (E, Any_Integer);
8638 elsif not Is_OK_Static_Expression (E) then
8639 Flag_Non_Static_Expr
8640 ("non-static expression used for digits value!", E);
8642 elsif Expr_Value (E) <= 0 then
8643 Error_Msg_N ("digits value must be greater than zero", E);
8649 -- If any of above errors occurred, then replace the incorrect
8650 -- expression by the integer 1, which should prevent further errors.
8652 Rewrite (E, Make_Integer_Literal (Sloc (E), 1));
8653 Analyze_And_Resolve (E, Standard_Integer);
8655 end Check_Digits_Expression;
8657 --------------------------
8658 -- Check_Initialization --
8659 --------------------------
8661 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id) is
8663 if Is_Limited_Type (T)
8664 and then not In_Instance
8665 and then not In_Inlined_Body
8667 if not OK_For_Limited_Init (Exp) then
8669 -- In GNAT mode, this is just a warning, to allow it to be evilly
8670 -- turned off. Otherwise it is a real error.
8674 ("?cannot initialize entities of limited type!", Exp);
8676 elsif Ada_Version < Ada_05 then
8678 ("cannot initialize entities of limited type", Exp);
8679 Explain_Limited_Type (T, Exp);
8682 -- Specialize error message according to kind of illegal
8683 -- initial expression.
8685 if Nkind (Exp) = N_Type_Conversion
8686 and then Nkind (Expression (Exp)) = N_Function_Call
8689 ("illegal context for call"
8690 & " to function with limited result", Exp);
8694 ("initialization of limited object requires aggregate "
8695 & "or function call", Exp);
8700 end Check_Initialization;
8702 ------------------------------------
8703 -- Check_Or_Process_Discriminants --
8704 ------------------------------------
8706 -- If an incomplete or private type declaration was already given for the
8707 -- type, the discriminants may have already been processed if they were
8708 -- present on the incomplete declaration. In this case a full conformance
8709 -- check is performed otherwise just process them.
8711 procedure Check_Or_Process_Discriminants
8714 Prev : Entity_Id := Empty)
8717 if Has_Discriminants (T) then
8719 -- Make the discriminants visible to component declarations
8726 D := First_Discriminant (T);
8727 while Present (D) loop
8728 Prev := Current_Entity (D);
8729 Set_Current_Entity (D);
8730 Set_Is_Immediately_Visible (D);
8731 Set_Homonym (D, Prev);
8733 -- Ada 2005 (AI-230): Access discriminant allowed in
8734 -- non-limited record types.
8736 if Ada_Version < Ada_05 then
8738 -- This restriction gets applied to the full type here. It
8739 -- has already been applied earlier to the partial view.
8741 Check_Access_Discriminant_Requires_Limited (Parent (D), N);
8744 Next_Discriminant (D);
8748 elsif Present (Discriminant_Specifications (N)) then
8749 Process_Discriminants (N, Prev);
8751 end Check_Or_Process_Discriminants;
8753 ----------------------
8754 -- Check_Real_Bound --
8755 ----------------------
8757 procedure Check_Real_Bound (Bound : Node_Id) is
8759 if not Is_Real_Type (Etype (Bound)) then
8761 ("bound in real type definition must be of real type", Bound);
8763 elsif not Is_OK_Static_Expression (Bound) then
8764 Flag_Non_Static_Expr
8765 ("non-static expression used for real type bound!", Bound);
8772 (Bound, Make_Real_Literal (Sloc (Bound), Ureal_0));
8774 Resolve (Bound, Standard_Float);
8775 end Check_Real_Bound;
8777 ------------------------------
8778 -- Complete_Private_Subtype --
8779 ------------------------------
8781 procedure Complete_Private_Subtype
8784 Full_Base : Entity_Id;
8785 Related_Nod : Node_Id)
8787 Save_Next_Entity : Entity_Id;
8788 Save_Homonym : Entity_Id;
8791 -- Set semantic attributes for (implicit) private subtype completion.
8792 -- If the full type has no discriminants, then it is a copy of the full
8793 -- view of the base. Otherwise, it is a subtype of the base with a
8794 -- possible discriminant constraint. Save and restore the original
8795 -- Next_Entity field of full to ensure that the calls to Copy_Node
8796 -- do not corrupt the entity chain.
8798 -- Note that the type of the full view is the same entity as the type of
8799 -- the partial view. In this fashion, the subtype has access to the
8800 -- correct view of the parent.
8802 Save_Next_Entity := Next_Entity (Full);
8803 Save_Homonym := Homonym (Priv);
8805 case Ekind (Full_Base) is
8806 when E_Record_Type |
8812 Copy_Node (Priv, Full);
8814 Set_Has_Discriminants (Full, Has_Discriminants (Full_Base));
8815 Set_First_Entity (Full, First_Entity (Full_Base));
8816 Set_Last_Entity (Full, Last_Entity (Full_Base));
8819 Copy_Node (Full_Base, Full);
8820 Set_Chars (Full, Chars (Priv));
8821 Conditional_Delay (Full, Priv);
8822 Set_Sloc (Full, Sloc (Priv));
8825 Set_Next_Entity (Full, Save_Next_Entity);
8826 Set_Homonym (Full, Save_Homonym);
8827 Set_Associated_Node_For_Itype (Full, Related_Nod);
8829 -- Set common attributes for all subtypes
8831 Set_Ekind (Full, Subtype_Kind (Ekind (Full_Base)));
8833 -- The Etype of the full view is inconsistent. Gigi needs to see the
8834 -- structural full view, which is what the current scheme gives:
8835 -- the Etype of the full view is the etype of the full base. However,
8836 -- if the full base is a derived type, the full view then looks like
8837 -- a subtype of the parent, not a subtype of the full base. If instead
8840 -- Set_Etype (Full, Full_Base);
8842 -- then we get inconsistencies in the front-end (confusion between
8843 -- views). Several outstanding bugs are related to this ???
8845 Set_Is_First_Subtype (Full, False);
8846 Set_Scope (Full, Scope (Priv));
8847 Set_Size_Info (Full, Full_Base);
8848 Set_RM_Size (Full, RM_Size (Full_Base));
8849 Set_Is_Itype (Full);
8851 -- A subtype of a private-type-without-discriminants, whose full-view
8852 -- has discriminants with default expressions, is not constrained!
8854 if not Has_Discriminants (Priv) then
8855 Set_Is_Constrained (Full, Is_Constrained (Full_Base));
8857 if Has_Discriminants (Full_Base) then
8858 Set_Discriminant_Constraint
8859 (Full, Discriminant_Constraint (Full_Base));
8861 -- The partial view may have been indefinite, the full view
8864 Set_Has_Unknown_Discriminants
8865 (Full, Has_Unknown_Discriminants (Full_Base));
8869 Set_First_Rep_Item (Full, First_Rep_Item (Full_Base));
8870 Set_Depends_On_Private (Full, Has_Private_Component (Full));
8872 -- Freeze the private subtype entity if its parent is delayed, and not
8873 -- already frozen. We skip this processing if the type is an anonymous
8874 -- subtype of a record component, or is the corresponding record of a
8875 -- protected type, since ???
8877 if not Is_Type (Scope (Full)) then
8878 Set_Has_Delayed_Freeze (Full,
8879 Has_Delayed_Freeze (Full_Base)
8880 and then (not Is_Frozen (Full_Base)));
8883 Set_Freeze_Node (Full, Empty);
8884 Set_Is_Frozen (Full, False);
8885 Set_Full_View (Priv, Full);
8887 if Has_Discriminants (Full) then
8888 Set_Stored_Constraint_From_Discriminant_Constraint (Full);
8889 Set_Stored_Constraint (Priv, Stored_Constraint (Full));
8891 if Has_Unknown_Discriminants (Full) then
8892 Set_Discriminant_Constraint (Full, No_Elist);
8896 if Ekind (Full_Base) = E_Record_Type
8897 and then Has_Discriminants (Full_Base)
8898 and then Has_Discriminants (Priv) -- might not, if errors
8899 and then not Has_Unknown_Discriminants (Priv)
8900 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Priv))
8902 Create_Constrained_Components
8903 (Full, Related_Nod, Full_Base, Discriminant_Constraint (Priv));
8905 -- If the full base is itself derived from private, build a congruent
8906 -- subtype of its underlying type, for use by the back end. For a
8907 -- constrained record component, the declaration cannot be placed on
8908 -- the component list, but it must nevertheless be built an analyzed, to
8909 -- supply enough information for Gigi to compute the size of component.
8911 elsif Ekind (Full_Base) in Private_Kind
8912 and then Is_Derived_Type (Full_Base)
8913 and then Has_Discriminants (Full_Base)
8914 and then (Ekind (Current_Scope) /= E_Record_Subtype)
8916 if not Is_Itype (Priv)
8918 Nkind (Subtype_Indication (Parent (Priv))) = N_Subtype_Indication
8920 Build_Underlying_Full_View
8921 (Parent (Priv), Full, Etype (Full_Base));
8923 elsif Nkind (Related_Nod) = N_Component_Declaration then
8924 Build_Underlying_Full_View (Related_Nod, Full, Etype (Full_Base));
8927 elsif Is_Record_Type (Full_Base) then
8929 -- Show Full is simply a renaming of Full_Base
8931 Set_Cloned_Subtype (Full, Full_Base);
8934 -- It is unsafe to share to bounds of a scalar type, because the Itype
8935 -- is elaborated on demand, and if a bound is non-static then different
8936 -- orders of elaboration in different units will lead to different
8937 -- external symbols.
8939 if Is_Scalar_Type (Full_Base) then
8940 Set_Scalar_Range (Full,
8941 Make_Range (Sloc (Related_Nod),
8943 Duplicate_Subexpr_No_Checks (Type_Low_Bound (Full_Base)),
8945 Duplicate_Subexpr_No_Checks (Type_High_Bound (Full_Base))));
8947 -- This completion inherits the bounds of the full parent, but if
8948 -- the parent is an unconstrained floating point type, so is the
8951 if Is_Floating_Point_Type (Full_Base) then
8952 Set_Includes_Infinities
8953 (Scalar_Range (Full), Has_Infinities (Full_Base));
8957 -- ??? It seems that a lot of fields are missing that should be copied
8958 -- from Full_Base to Full. Here are some that are introduced in a
8959 -- non-disruptive way but a cleanup is necessary.
8961 if Is_Tagged_Type (Full_Base) then
8962 Set_Is_Tagged_Type (Full);
8963 Set_Primitive_Operations (Full, Primitive_Operations (Full_Base));
8964 Set_Class_Wide_Type (Full, Class_Wide_Type (Full_Base));
8966 -- If this is a subtype of a protected or task type, constrain its
8967 -- corresponding record, unless this is a subtype without constraints,
8968 -- i.e. a simple renaming as with an actual subtype in an instance.
8970 elsif Is_Concurrent_Type (Full_Base) then
8971 if Has_Discriminants (Full)
8972 and then Present (Corresponding_Record_Type (Full_Base))
8974 not Is_Empty_Elmt_List (Discriminant_Constraint (Full))
8976 Set_Corresponding_Record_Type (Full,
8977 Constrain_Corresponding_Record
8978 (Full, Corresponding_Record_Type (Full_Base),
8979 Related_Nod, Full_Base));
8982 Set_Corresponding_Record_Type (Full,
8983 Corresponding_Record_Type (Full_Base));
8986 end Complete_Private_Subtype;
8988 ----------------------------
8989 -- Constant_Redeclaration --
8990 ----------------------------
8992 procedure Constant_Redeclaration
8997 Prev : constant Entity_Id := Current_Entity_In_Scope (Id);
8998 Obj_Def : constant Node_Id := Object_Definition (N);
9001 procedure Check_Possible_Deferred_Completion
9002 (Prev_Id : Entity_Id;
9003 Prev_Obj_Def : Node_Id;
9004 Curr_Obj_Def : Node_Id);
9005 -- Determine whether the two object definitions describe the partial
9006 -- and the full view of a constrained deferred constant. Generate
9007 -- a subtype for the full view and verify that it statically matches
9008 -- the subtype of the partial view.
9010 procedure Check_Recursive_Declaration (Typ : Entity_Id);
9011 -- If deferred constant is an access type initialized with an allocator,
9012 -- check whether there is an illegal recursion in the definition,
9013 -- through a default value of some record subcomponent. This is normally
9014 -- detected when generating init procs, but requires this additional
9015 -- mechanism when expansion is disabled.
9017 ----------------------------------------
9018 -- Check_Possible_Deferred_Completion --
9019 ----------------------------------------
9021 procedure Check_Possible_Deferred_Completion
9022 (Prev_Id : Entity_Id;
9023 Prev_Obj_Def : Node_Id;
9024 Curr_Obj_Def : Node_Id)
9027 if Nkind (Prev_Obj_Def) = N_Subtype_Indication
9028 and then Present (Constraint (Prev_Obj_Def))
9029 and then Nkind (Curr_Obj_Def) = N_Subtype_Indication
9030 and then Present (Constraint (Curr_Obj_Def))
9033 Loc : constant Source_Ptr := Sloc (N);
9034 Def_Id : constant Entity_Id :=
9035 Make_Defining_Identifier (Loc,
9036 New_Internal_Name ('S'));
9037 Decl : constant Node_Id :=
9038 Make_Subtype_Declaration (Loc,
9039 Defining_Identifier =>
9041 Subtype_Indication =>
9042 Relocate_Node (Curr_Obj_Def));
9045 Insert_Before_And_Analyze (N, Decl);
9046 Set_Etype (Id, Def_Id);
9048 if not Subtypes_Statically_Match (Etype (Prev_Id), Def_Id) then
9049 Error_Msg_Sloc := Sloc (Prev_Id);
9050 Error_Msg_N ("subtype does not statically match deferred " &
9055 end Check_Possible_Deferred_Completion;
9057 ---------------------------------
9058 -- Check_Recursive_Declaration --
9059 ---------------------------------
9061 procedure Check_Recursive_Declaration (Typ : Entity_Id) is
9065 if Is_Record_Type (Typ) then
9066 Comp := First_Component (Typ);
9067 while Present (Comp) loop
9068 if Comes_From_Source (Comp) then
9069 if Present (Expression (Parent (Comp)))
9070 and then Is_Entity_Name (Expression (Parent (Comp)))
9071 and then Entity (Expression (Parent (Comp))) = Prev
9073 Error_Msg_Sloc := Sloc (Parent (Comp));
9075 ("illegal circularity with declaration for&#",
9079 elsif Is_Record_Type (Etype (Comp)) then
9080 Check_Recursive_Declaration (Etype (Comp));
9084 Next_Component (Comp);
9087 end Check_Recursive_Declaration;
9089 -- Start of processing for Constant_Redeclaration
9092 if Nkind (Parent (Prev)) = N_Object_Declaration then
9093 if Nkind (Object_Definition
9094 (Parent (Prev))) = N_Subtype_Indication
9096 -- Find type of new declaration. The constraints of the two
9097 -- views must match statically, but there is no point in
9098 -- creating an itype for the full view.
9100 if Nkind (Obj_Def) = N_Subtype_Indication then
9101 Find_Type (Subtype_Mark (Obj_Def));
9102 New_T := Entity (Subtype_Mark (Obj_Def));
9105 Find_Type (Obj_Def);
9106 New_T := Entity (Obj_Def);
9112 -- The full view may impose a constraint, even if the partial
9113 -- view does not, so construct the subtype.
9115 New_T := Find_Type_Of_Object (Obj_Def, N);
9120 -- Current declaration is illegal, diagnosed below in Enter_Name
9126 -- If previous full declaration exists, or if a homograph is present,
9127 -- let Enter_Name handle it, either with an error, or with the removal
9128 -- of an overridden implicit subprogram.
9130 if Ekind (Prev) /= E_Constant
9131 or else Present (Expression (Parent (Prev)))
9132 or else Present (Full_View (Prev))
9136 -- Verify that types of both declarations match, or else that both types
9137 -- are anonymous access types whose designated subtypes statically match
9138 -- (as allowed in Ada 2005 by AI-385).
9140 elsif Base_Type (Etype (Prev)) /= Base_Type (New_T)
9142 (Ekind (Etype (Prev)) /= E_Anonymous_Access_Type
9143 or else Ekind (Etype (New_T)) /= E_Anonymous_Access_Type
9144 or else Is_Access_Constant (Etype (New_T)) /=
9145 Is_Access_Constant (Etype (Prev))
9146 or else Can_Never_Be_Null (Etype (New_T)) /=
9147 Can_Never_Be_Null (Etype (Prev))
9148 or else Null_Exclusion_Present (Parent (Prev)) /=
9149 Null_Exclusion_Present (Parent (Id))
9150 or else not Subtypes_Statically_Match
9151 (Designated_Type (Etype (Prev)),
9152 Designated_Type (Etype (New_T))))
9154 Error_Msg_Sloc := Sloc (Prev);
9155 Error_Msg_N ("type does not match declaration#", N);
9156 Set_Full_View (Prev, Id);
9157 Set_Etype (Id, Any_Type);
9160 Null_Exclusion_Present (Parent (Prev))
9161 and then not Null_Exclusion_Present (N)
9163 Error_Msg_Sloc := Sloc (Prev);
9164 Error_Msg_N ("null-exclusion does not match declaration#", N);
9165 Set_Full_View (Prev, Id);
9166 Set_Etype (Id, Any_Type);
9168 -- If so, process the full constant declaration
9171 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
9172 -- the deferred declaration is constrained, then the subtype defined
9173 -- by the subtype_indication in the full declaration shall match it
9176 Check_Possible_Deferred_Completion
9178 Prev_Obj_Def => Object_Definition (Parent (Prev)),
9179 Curr_Obj_Def => Obj_Def);
9181 Set_Full_View (Prev, Id);
9182 Set_Is_Public (Id, Is_Public (Prev));
9183 Set_Is_Internal (Id);
9184 Append_Entity (Id, Current_Scope);
9186 -- Check ALIASED present if present before (RM 7.4(7))
9188 if Is_Aliased (Prev)
9189 and then not Aliased_Present (N)
9191 Error_Msg_Sloc := Sloc (Prev);
9192 Error_Msg_N ("ALIASED required (see declaration#)", N);
9195 -- Allow incomplete declaration of tags (used to handle forward
9196 -- references to tags). The check on Ada_Tags avoids cicularities
9197 -- when rebuilding the compiler.
9199 if RTU_Loaded (Ada_Tags)
9200 and then T = RTE (RE_Tag)
9204 -- Check that placement is in private part and that the incomplete
9205 -- declaration appeared in the visible part.
9207 elsif Ekind (Current_Scope) = E_Package
9208 and then not In_Private_Part (Current_Scope)
9210 Error_Msg_Sloc := Sloc (Prev);
9211 Error_Msg_N ("full constant for declaration#"
9212 & " must be in private part", N);
9214 elsif Ekind (Current_Scope) = E_Package
9215 and then List_Containing (Parent (Prev))
9216 /= Visible_Declarations
9217 (Specification (Unit_Declaration_Node (Current_Scope)))
9220 ("deferred constant must be declared in visible part",
9224 if Is_Access_Type (T)
9225 and then Nkind (Expression (N)) = N_Allocator
9227 Check_Recursive_Declaration (Designated_Type (T));
9230 end Constant_Redeclaration;
9232 ----------------------
9233 -- Constrain_Access --
9234 ----------------------
9236 procedure Constrain_Access
9237 (Def_Id : in out Entity_Id;
9239 Related_Nod : Node_Id)
9241 T : constant Entity_Id := Entity (Subtype_Mark (S));
9242 Desig_Type : constant Entity_Id := Designated_Type (T);
9243 Desig_Subtype : Entity_Id := Create_Itype (E_Void, Related_Nod);
9244 Constraint_OK : Boolean := True;
9246 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean;
9247 -- Simple predicate to test for defaulted discriminants
9248 -- Shouldn't this be in sem_util???
9250 ---------------------------------
9251 -- Has_Defaulted_Discriminants --
9252 ---------------------------------
9254 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
9256 return Has_Discriminants (Typ)
9257 and then Present (First_Discriminant (Typ))
9259 (Discriminant_Default_Value (First_Discriminant (Typ)));
9260 end Has_Defaulted_Discriminants;
9262 -- Start of processing for Constrain_Access
9265 if Is_Array_Type (Desig_Type) then
9266 Constrain_Array (Desig_Subtype, S, Related_Nod, Def_Id, 'P');
9268 elsif (Is_Record_Type (Desig_Type)
9269 or else Is_Incomplete_Or_Private_Type (Desig_Type))
9270 and then not Is_Constrained (Desig_Type)
9272 -- ??? The following code is a temporary kludge to ignore a
9273 -- discriminant constraint on access type if it is constraining
9274 -- the current record. Avoid creating the implicit subtype of the
9275 -- record we are currently compiling since right now, we cannot
9276 -- handle these. For now, just return the access type itself.
9278 if Desig_Type = Current_Scope
9279 and then No (Def_Id)
9281 Set_Ekind (Desig_Subtype, E_Record_Subtype);
9282 Def_Id := Entity (Subtype_Mark (S));
9284 -- This call added to ensure that the constraint is analyzed
9285 -- (needed for a B test). Note that we still return early from
9286 -- this procedure to avoid recursive processing. ???
9288 Constrain_Discriminated_Type
9289 (Desig_Subtype, S, Related_Nod, For_Access => True);
9293 if (Ekind (T) = E_General_Access_Type
9294 or else Ada_Version >= Ada_05)
9295 and then Has_Private_Declaration (Desig_Type)
9296 and then In_Open_Scopes (Scope (Desig_Type))
9297 and then Has_Discriminants (Desig_Type)
9299 -- Enforce rule that the constraint is illegal if there is
9300 -- an unconstrained view of the designated type. This means
9301 -- that the partial view (either a private type declaration or
9302 -- a derivation from a private type) has no discriminants.
9303 -- (Defect Report 8652/0008, Technical Corrigendum 1, checked
9304 -- by ACATS B371001).
9306 -- Rule updated for Ada 2005: the private type is said to have
9307 -- a constrained partial view, given that objects of the type
9308 -- can be declared. Furthermore, the rule applies to all access
9309 -- types, unlike the rule concerning default discriminants.
9312 Pack : constant Node_Id :=
9313 Unit_Declaration_Node (Scope (Desig_Type));
9318 if Nkind (Pack) = N_Package_Declaration then
9319 Decls := Visible_Declarations (Specification (Pack));
9320 Decl := First (Decls);
9321 while Present (Decl) loop
9322 if (Nkind (Decl) = N_Private_Type_Declaration
9324 Chars (Defining_Identifier (Decl)) =
9328 (Nkind (Decl) = N_Full_Type_Declaration
9330 Chars (Defining_Identifier (Decl)) =
9332 and then Is_Derived_Type (Desig_Type)
9334 Has_Private_Declaration (Etype (Desig_Type)))
9336 if No (Discriminant_Specifications (Decl)) then
9338 ("cannot constrain general access type if " &
9339 "designated type has constrained partial view",
9352 Constrain_Discriminated_Type (Desig_Subtype, S, Related_Nod,
9353 For_Access => True);
9355 elsif (Is_Task_Type (Desig_Type)
9356 or else Is_Protected_Type (Desig_Type))
9357 and then not Is_Constrained (Desig_Type)
9359 Constrain_Concurrent
9360 (Desig_Subtype, S, Related_Nod, Desig_Type, ' ');
9363 Error_Msg_N ("invalid constraint on access type", S);
9364 Desig_Subtype := Desig_Type; -- Ignore invalid constraint.
9365 Constraint_OK := False;
9369 Def_Id := Create_Itype (E_Access_Subtype, Related_Nod);
9371 Set_Ekind (Def_Id, E_Access_Subtype);
9374 if Constraint_OK then
9375 Set_Etype (Def_Id, Base_Type (T));
9377 if Is_Private_Type (Desig_Type) then
9378 Prepare_Private_Subtype_Completion (Desig_Subtype, Related_Nod);
9381 Set_Etype (Def_Id, Any_Type);
9384 Set_Size_Info (Def_Id, T);
9385 Set_Is_Constrained (Def_Id, Constraint_OK);
9386 Set_Directly_Designated_Type (Def_Id, Desig_Subtype);
9387 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9388 Set_Is_Access_Constant (Def_Id, Is_Access_Constant (T));
9390 Conditional_Delay (Def_Id, T);
9392 -- AI-363 : Subtypes of general access types whose designated types have
9393 -- default discriminants are disallowed. In instances, the rule has to
9394 -- be checked against the actual, of which T is the subtype. In a
9395 -- generic body, the rule is checked assuming that the actual type has
9396 -- defaulted discriminants.
9398 if Ada_Version >= Ada_05 or else Warn_On_Ada_2005_Compatibility then
9399 if Ekind (Base_Type (T)) = E_General_Access_Type
9400 and then Has_Defaulted_Discriminants (Desig_Type)
9402 if Ada_Version < Ada_05 then
9404 ("access subtype of general access type would not " &
9405 "be allowed in Ada 2005?", S);
9408 ("access subype of general access type not allowed", S);
9411 Error_Msg_N ("\discriminants have defaults", S);
9413 elsif Is_Access_Type (T)
9414 and then Is_Generic_Type (Desig_Type)
9415 and then Has_Discriminants (Desig_Type)
9416 and then In_Package_Body (Current_Scope)
9418 if Ada_Version < Ada_05 then
9420 ("access subtype would not be allowed in generic body " &
9424 ("access subtype not allowed in generic body", S);
9428 ("\designated type is a discriminated formal", S);
9431 end Constrain_Access;
9433 ---------------------
9434 -- Constrain_Array --
9435 ---------------------
9437 procedure Constrain_Array
9438 (Def_Id : in out Entity_Id;
9440 Related_Nod : Node_Id;
9441 Related_Id : Entity_Id;
9444 C : constant Node_Id := Constraint (SI);
9445 Number_Of_Constraints : Nat := 0;
9448 Constraint_OK : Boolean := True;
9451 T := Entity (Subtype_Mark (SI));
9453 if Ekind (T) in Access_Kind then
9454 T := Designated_Type (T);
9457 -- If an index constraint follows a subtype mark in a subtype indication
9458 -- then the type or subtype denoted by the subtype mark must not already
9459 -- impose an index constraint. The subtype mark must denote either an
9460 -- unconstrained array type or an access type whose designated type
9461 -- is such an array type... (RM 3.6.1)
9463 if Is_Constrained (T) then
9465 ("array type is already constrained", Subtype_Mark (SI));
9466 Constraint_OK := False;
9469 S := First (Constraints (C));
9470 while Present (S) loop
9471 Number_Of_Constraints := Number_Of_Constraints + 1;
9475 -- In either case, the index constraint must provide a discrete
9476 -- range for each index of the array type and the type of each
9477 -- discrete range must be the same as that of the corresponding
9478 -- index. (RM 3.6.1)
9480 if Number_Of_Constraints /= Number_Dimensions (T) then
9481 Error_Msg_NE ("incorrect number of index constraints for }", C, T);
9482 Constraint_OK := False;
9485 S := First (Constraints (C));
9486 Index := First_Index (T);
9489 -- Apply constraints to each index type
9491 for J in 1 .. Number_Of_Constraints loop
9492 Constrain_Index (Index, S, Related_Nod, Related_Id, Suffix, J);
9502 Create_Itype (E_Array_Subtype, Related_Nod, Related_Id, Suffix);
9503 Set_Parent (Def_Id, Related_Nod);
9506 Set_Ekind (Def_Id, E_Array_Subtype);
9509 Set_Size_Info (Def_Id, (T));
9510 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
9511 Set_Etype (Def_Id, Base_Type (T));
9513 if Constraint_OK then
9514 Set_First_Index (Def_Id, First (Constraints (C)));
9516 Set_First_Index (Def_Id, First_Index (T));
9519 Set_Is_Constrained (Def_Id, True);
9520 Set_Is_Aliased (Def_Id, Is_Aliased (T));
9521 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9523 Set_Is_Private_Composite (Def_Id, Is_Private_Composite (T));
9524 Set_Is_Limited_Composite (Def_Id, Is_Limited_Composite (T));
9526 -- A subtype does not inherit the packed_array_type of is parent. We
9527 -- need to initialize the attribute because if Def_Id is previously
9528 -- analyzed through a limited_with clause, it will have the attributes
9529 -- of an incomplete type, one of which is an Elist that overlaps the
9530 -- Packed_Array_Type field.
9532 Set_Packed_Array_Type (Def_Id, Empty);
9534 -- Build a freeze node if parent still needs one. Also make sure that
9535 -- the Depends_On_Private status is set because the subtype will need
9536 -- reprocessing at the time the base type does, and also we must set a
9537 -- conditional delay.
9539 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
9540 Conditional_Delay (Def_Id, T);
9541 end Constrain_Array;
9543 ------------------------------
9544 -- Constrain_Component_Type --
9545 ------------------------------
9547 function Constrain_Component_Type
9549 Constrained_Typ : Entity_Id;
9550 Related_Node : Node_Id;
9552 Constraints : Elist_Id) return Entity_Id
9554 Loc : constant Source_Ptr := Sloc (Constrained_Typ);
9555 Compon_Type : constant Entity_Id := Etype (Comp);
9557 function Build_Constrained_Array_Type
9558 (Old_Type : Entity_Id) return Entity_Id;
9559 -- If Old_Type is an array type, one of whose indices is constrained
9560 -- by a discriminant, build an Itype whose constraint replaces the
9561 -- discriminant with its value in the constraint.
9563 function Build_Constrained_Discriminated_Type
9564 (Old_Type : Entity_Id) return Entity_Id;
9565 -- Ditto for record components
9567 function Build_Constrained_Access_Type
9568 (Old_Type : Entity_Id) return Entity_Id;
9569 -- Ditto for access types. Makes use of previous two functions, to
9570 -- constrain designated type.
9572 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id;
9573 -- T is an array or discriminated type, C is a list of constraints
9574 -- that apply to T. This routine builds the constrained subtype.
9576 function Is_Discriminant (Expr : Node_Id) return Boolean;
9577 -- Returns True if Expr is a discriminant
9579 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id;
9580 -- Find the value of discriminant Discrim in Constraint
9582 -----------------------------------
9583 -- Build_Constrained_Access_Type --
9584 -----------------------------------
9586 function Build_Constrained_Access_Type
9587 (Old_Type : Entity_Id) return Entity_Id
9589 Desig_Type : constant Entity_Id := Designated_Type (Old_Type);
9591 Desig_Subtype : Entity_Id;
9595 -- if the original access type was not embedded in the enclosing
9596 -- type definition, there is no need to produce a new access
9597 -- subtype. In fact every access type with an explicit constraint
9598 -- generates an itype whose scope is the enclosing record.
9600 if not Is_Type (Scope (Old_Type)) then
9603 elsif Is_Array_Type (Desig_Type) then
9604 Desig_Subtype := Build_Constrained_Array_Type (Desig_Type);
9606 elsif Has_Discriminants (Desig_Type) then
9608 -- This may be an access type to an enclosing record type for
9609 -- which we are constructing the constrained components. Return
9610 -- the enclosing record subtype. This is not always correct,
9611 -- but avoids infinite recursion. ???
9613 Desig_Subtype := Any_Type;
9615 for J in reverse 0 .. Scope_Stack.Last loop
9616 Scop := Scope_Stack.Table (J).Entity;
9619 and then Base_Type (Scop) = Base_Type (Desig_Type)
9621 Desig_Subtype := Scop;
9624 exit when not Is_Type (Scop);
9627 if Desig_Subtype = Any_Type then
9629 Build_Constrained_Discriminated_Type (Desig_Type);
9636 if Desig_Subtype /= Desig_Type then
9638 -- The Related_Node better be here or else we won't be able
9639 -- to attach new itypes to a node in the tree.
9641 pragma Assert (Present (Related_Node));
9643 Itype := Create_Itype (E_Access_Subtype, Related_Node);
9645 Set_Etype (Itype, Base_Type (Old_Type));
9646 Set_Size_Info (Itype, (Old_Type));
9647 Set_Directly_Designated_Type (Itype, Desig_Subtype);
9648 Set_Depends_On_Private (Itype, Has_Private_Component
9650 Set_Is_Access_Constant (Itype, Is_Access_Constant
9653 -- The new itype needs freezing when it depends on a not frozen
9654 -- type and the enclosing subtype needs freezing.
9656 if Has_Delayed_Freeze (Constrained_Typ)
9657 and then not Is_Frozen (Constrained_Typ)
9659 Conditional_Delay (Itype, Base_Type (Old_Type));
9667 end Build_Constrained_Access_Type;
9669 ----------------------------------
9670 -- Build_Constrained_Array_Type --
9671 ----------------------------------
9673 function Build_Constrained_Array_Type
9674 (Old_Type : Entity_Id) return Entity_Id
9678 Old_Index : Node_Id;
9679 Range_Node : Node_Id;
9680 Constr_List : List_Id;
9682 Need_To_Create_Itype : Boolean := False;
9685 Old_Index := First_Index (Old_Type);
9686 while Present (Old_Index) loop
9687 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9689 if Is_Discriminant (Lo_Expr)
9690 or else Is_Discriminant (Hi_Expr)
9692 Need_To_Create_Itype := True;
9695 Next_Index (Old_Index);
9698 if Need_To_Create_Itype then
9699 Constr_List := New_List;
9701 Old_Index := First_Index (Old_Type);
9702 while Present (Old_Index) loop
9703 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9705 if Is_Discriminant (Lo_Expr) then
9706 Lo_Expr := Get_Discr_Value (Lo_Expr);
9709 if Is_Discriminant (Hi_Expr) then
9710 Hi_Expr := Get_Discr_Value (Hi_Expr);
9715 (Loc, New_Copy_Tree (Lo_Expr), New_Copy_Tree (Hi_Expr));
9717 Append (Range_Node, To => Constr_List);
9719 Next_Index (Old_Index);
9722 return Build_Subtype (Old_Type, Constr_List);
9727 end Build_Constrained_Array_Type;
9729 ------------------------------------------
9730 -- Build_Constrained_Discriminated_Type --
9731 ------------------------------------------
9733 function Build_Constrained_Discriminated_Type
9734 (Old_Type : Entity_Id) return Entity_Id
9737 Constr_List : List_Id;
9738 Old_Constraint : Elmt_Id;
9740 Need_To_Create_Itype : Boolean := False;
9743 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9744 while Present (Old_Constraint) loop
9745 Expr := Node (Old_Constraint);
9747 if Is_Discriminant (Expr) then
9748 Need_To_Create_Itype := True;
9751 Next_Elmt (Old_Constraint);
9754 if Need_To_Create_Itype then
9755 Constr_List := New_List;
9757 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9758 while Present (Old_Constraint) loop
9759 Expr := Node (Old_Constraint);
9761 if Is_Discriminant (Expr) then
9762 Expr := Get_Discr_Value (Expr);
9765 Append (New_Copy_Tree (Expr), To => Constr_List);
9767 Next_Elmt (Old_Constraint);
9770 return Build_Subtype (Old_Type, Constr_List);
9775 end Build_Constrained_Discriminated_Type;
9781 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id is
9783 Subtyp_Decl : Node_Id;
9785 Btyp : Entity_Id := Base_Type (T);
9788 -- The Related_Node better be here or else we won't be able to
9789 -- attach new itypes to a node in the tree.
9791 pragma Assert (Present (Related_Node));
9793 -- If the view of the component's type is incomplete or private
9794 -- with unknown discriminants, then the constraint must be applied
9795 -- to the full type.
9797 if Has_Unknown_Discriminants (Btyp)
9798 and then Present (Underlying_Type (Btyp))
9800 Btyp := Underlying_Type (Btyp);
9804 Make_Subtype_Indication (Loc,
9805 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
9806 Constraint => Make_Index_Or_Discriminant_Constraint (Loc, C));
9808 Def_Id := Create_Itype (Ekind (T), Related_Node);
9811 Make_Subtype_Declaration (Loc,
9812 Defining_Identifier => Def_Id,
9813 Subtype_Indication => Indic);
9815 Set_Parent (Subtyp_Decl, Parent (Related_Node));
9817 -- Itypes must be analyzed with checks off (see package Itypes)
9819 Analyze (Subtyp_Decl, Suppress => All_Checks);
9824 ---------------------
9825 -- Get_Discr_Value --
9826 ---------------------
9828 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id is
9834 -- The discriminant may be declared for the type, in which case we
9835 -- find it by iterating over the list of discriminants. If the
9836 -- discriminant is inherited from a parent type, it appears as the
9837 -- corresponding discriminant of the current type. This will be the
9838 -- case when constraining an inherited component whose constraint is
9839 -- given by a discriminant of the parent.
9841 D := First_Discriminant (Typ);
9842 E := First_Elmt (Constraints);
9844 while Present (D) loop
9845 if D = Entity (Discrim)
9846 or else D = CR_Discriminant (Entity (Discrim))
9847 or else Corresponding_Discriminant (D) = Entity (Discrim)
9852 Next_Discriminant (D);
9856 -- The corresponding_Discriminant mechanism is incomplete, because
9857 -- the correspondence between new and old discriminants is not one
9858 -- to one: one new discriminant can constrain several old ones. In
9859 -- that case, scan sequentially the stored_constraint, the list of
9860 -- discriminants of the parents, and the constraints.
9862 if Is_Derived_Type (Typ)
9863 and then Present (Stored_Constraint (Typ))
9864 and then Scope (Entity (Discrim)) = Etype (Typ)
9866 D := First_Discriminant (Etype (Typ));
9867 E := First_Elmt (Constraints);
9868 G := First_Elmt (Stored_Constraint (Typ));
9869 while Present (D) loop
9870 if D = Entity (Discrim) then
9874 Next_Discriminant (D);
9880 -- Something is wrong if we did not find the value
9882 raise Program_Error;
9883 end Get_Discr_Value;
9885 ---------------------
9886 -- Is_Discriminant --
9887 ---------------------
9889 function Is_Discriminant (Expr : Node_Id) return Boolean is
9890 Discrim_Scope : Entity_Id;
9893 if Denotes_Discriminant (Expr) then
9894 Discrim_Scope := Scope (Entity (Expr));
9896 -- Either we have a reference to one of Typ's discriminants,
9898 pragma Assert (Discrim_Scope = Typ
9900 -- or to the discriminants of the parent type, in the case
9901 -- of a derivation of a tagged type with variants.
9903 or else Discrim_Scope = Etype (Typ)
9904 or else Full_View (Discrim_Scope) = Etype (Typ)
9906 -- or same as above for the case where the discriminants
9907 -- were declared in Typ's private view.
9909 or else (Is_Private_Type (Discrim_Scope)
9910 and then Chars (Discrim_Scope) = Chars (Typ))
9912 -- or else we are deriving from the full view and the
9913 -- discriminant is declared in the private entity.
9915 or else (Is_Private_Type (Typ)
9916 and then Chars (Discrim_Scope) = Chars (Typ))
9918 -- Or we are constrained the corresponding record of a
9919 -- synchronized type that completes a private declaration.
9921 or else (Is_Concurrent_Record_Type (Typ)
9923 Corresponding_Concurrent_Type (Typ) = Discrim_Scope)
9925 -- or we have a class-wide type, in which case make sure the
9926 -- discriminant found belongs to the root type.
9928 or else (Is_Class_Wide_Type (Typ)
9929 and then Etype (Typ) = Discrim_Scope));
9934 -- In all other cases we have something wrong
9937 end Is_Discriminant;
9939 -- Start of processing for Constrain_Component_Type
9942 if Nkind (Parent (Comp)) = N_Component_Declaration
9943 and then Comes_From_Source (Parent (Comp))
9944 and then Comes_From_Source
9945 (Subtype_Indication (Component_Definition (Parent (Comp))))
9948 (Subtype_Indication (Component_Definition (Parent (Comp))))
9952 elsif Is_Array_Type (Compon_Type) then
9953 return Build_Constrained_Array_Type (Compon_Type);
9955 elsif Has_Discriminants (Compon_Type) then
9956 return Build_Constrained_Discriminated_Type (Compon_Type);
9958 elsif Is_Access_Type (Compon_Type) then
9959 return Build_Constrained_Access_Type (Compon_Type);
9964 end Constrain_Component_Type;
9966 --------------------------
9967 -- Constrain_Concurrent --
9968 --------------------------
9970 -- For concurrent types, the associated record value type carries the same
9971 -- discriminants, so when we constrain a concurrent type, we must constrain
9972 -- the corresponding record type as well.
9974 procedure Constrain_Concurrent
9975 (Def_Id : in out Entity_Id;
9977 Related_Nod : Node_Id;
9978 Related_Id : Entity_Id;
9981 T_Ent : Entity_Id := Entity (Subtype_Mark (SI));
9985 if Ekind (T_Ent) in Access_Kind then
9986 T_Ent := Designated_Type (T_Ent);
9989 T_Val := Corresponding_Record_Type (T_Ent);
9991 if Present (T_Val) then
9994 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
9997 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
9999 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
10000 Set_Corresponding_Record_Type (Def_Id,
10001 Constrain_Corresponding_Record
10002 (Def_Id, T_Val, Related_Nod, Related_Id));
10005 -- If there is no associated record, expansion is disabled and this
10006 -- is a generic context. Create a subtype in any case, so that
10007 -- semantic analysis can proceed.
10009 if No (Def_Id) then
10010 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
10013 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
10015 end Constrain_Concurrent;
10017 ------------------------------------
10018 -- Constrain_Corresponding_Record --
10019 ------------------------------------
10021 function Constrain_Corresponding_Record
10022 (Prot_Subt : Entity_Id;
10023 Corr_Rec : Entity_Id;
10024 Related_Nod : Node_Id;
10025 Related_Id : Entity_Id) return Entity_Id
10027 T_Sub : constant Entity_Id :=
10028 Create_Itype (E_Record_Subtype, Related_Nod, Related_Id, 'V');
10031 Set_Etype (T_Sub, Corr_Rec);
10032 Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt));
10033 Set_Is_Constrained (T_Sub, True);
10034 Set_First_Entity (T_Sub, First_Entity (Corr_Rec));
10035 Set_Last_Entity (T_Sub, Last_Entity (Corr_Rec));
10037 -- As elsewhere, we do not want to create a freeze node for this itype
10038 -- if it is created for a constrained component of an enclosing record
10039 -- because references to outer discriminants will appear out of scope.
10041 if Ekind (Scope (Prot_Subt)) /= E_Record_Type then
10042 Conditional_Delay (T_Sub, Corr_Rec);
10044 Set_Is_Frozen (T_Sub);
10047 if Has_Discriminants (Prot_Subt) then -- False only if errors.
10048 Set_Discriminant_Constraint
10049 (T_Sub, Discriminant_Constraint (Prot_Subt));
10050 Set_Stored_Constraint_From_Discriminant_Constraint (T_Sub);
10051 Create_Constrained_Components
10052 (T_Sub, Related_Nod, Corr_Rec, Discriminant_Constraint (T_Sub));
10055 Set_Depends_On_Private (T_Sub, Has_Private_Component (T_Sub));
10058 end Constrain_Corresponding_Record;
10060 -----------------------
10061 -- Constrain_Decimal --
10062 -----------------------
10064 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id) is
10065 T : constant Entity_Id := Entity (Subtype_Mark (S));
10066 C : constant Node_Id := Constraint (S);
10067 Loc : constant Source_Ptr := Sloc (C);
10068 Range_Expr : Node_Id;
10069 Digits_Expr : Node_Id;
10074 Set_Ekind (Def_Id, E_Decimal_Fixed_Point_Subtype);
10076 if Nkind (C) = N_Range_Constraint then
10077 Range_Expr := Range_Expression (C);
10078 Digits_Val := Digits_Value (T);
10081 pragma Assert (Nkind (C) = N_Digits_Constraint);
10082 Digits_Expr := Digits_Expression (C);
10083 Analyze_And_Resolve (Digits_Expr, Any_Integer);
10085 Check_Digits_Expression (Digits_Expr);
10086 Digits_Val := Expr_Value (Digits_Expr);
10088 if Digits_Val > Digits_Value (T) then
10090 ("digits expression is incompatible with subtype", C);
10091 Digits_Val := Digits_Value (T);
10094 if Present (Range_Constraint (C)) then
10095 Range_Expr := Range_Expression (Range_Constraint (C));
10097 Range_Expr := Empty;
10101 Set_Etype (Def_Id, Base_Type (T));
10102 Set_Size_Info (Def_Id, (T));
10103 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10104 Set_Delta_Value (Def_Id, Delta_Value (T));
10105 Set_Scale_Value (Def_Id, Scale_Value (T));
10106 Set_Small_Value (Def_Id, Small_Value (T));
10107 Set_Machine_Radix_10 (Def_Id, Machine_Radix_10 (T));
10108 Set_Digits_Value (Def_Id, Digits_Val);
10110 -- Manufacture range from given digits value if no range present
10112 if No (Range_Expr) then
10113 Bound_Val := (Ureal_10 ** Digits_Val - Ureal_1) * Small_Value (T);
10117 Convert_To (T, Make_Real_Literal (Loc, (-Bound_Val))),
10119 Convert_To (T, Make_Real_Literal (Loc, Bound_Val)));
10122 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expr, T);
10123 Set_Discrete_RM_Size (Def_Id);
10125 -- Unconditionally delay the freeze, since we cannot set size
10126 -- information in all cases correctly until the freeze point.
10128 Set_Has_Delayed_Freeze (Def_Id);
10129 end Constrain_Decimal;
10131 ----------------------------------
10132 -- Constrain_Discriminated_Type --
10133 ----------------------------------
10135 procedure Constrain_Discriminated_Type
10136 (Def_Id : Entity_Id;
10138 Related_Nod : Node_Id;
10139 For_Access : Boolean := False)
10141 E : constant Entity_Id := Entity (Subtype_Mark (S));
10144 Elist : Elist_Id := New_Elmt_List;
10146 procedure Fixup_Bad_Constraint;
10147 -- This is called after finding a bad constraint, and after having
10148 -- posted an appropriate error message. The mission is to leave the
10149 -- entity T in as reasonable state as possible!
10151 --------------------------
10152 -- Fixup_Bad_Constraint --
10153 --------------------------
10155 procedure Fixup_Bad_Constraint is
10157 -- Set a reasonable Ekind for the entity. For an incomplete type,
10158 -- we can't do much, but for other types, we can set the proper
10159 -- corresponding subtype kind.
10161 if Ekind (T) = E_Incomplete_Type then
10162 Set_Ekind (Def_Id, Ekind (T));
10164 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
10167 Set_Etype (Def_Id, Any_Type);
10168 Set_Error_Posted (Def_Id);
10169 end Fixup_Bad_Constraint;
10171 -- Start of processing for Constrain_Discriminated_Type
10174 C := Constraint (S);
10176 -- A discriminant constraint is only allowed in a subtype indication,
10177 -- after a subtype mark. This subtype mark must denote either a type
10178 -- with discriminants, or an access type whose designated type is a
10179 -- type with discriminants. A discriminant constraint specifies the
10180 -- values of these discriminants (RM 3.7.2(5)).
10182 T := Base_Type (Entity (Subtype_Mark (S)));
10184 if Ekind (T) in Access_Kind then
10185 T := Designated_Type (T);
10188 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal.
10189 -- Avoid generating an error for access-to-incomplete subtypes.
10191 if Ada_Version >= Ada_05
10192 and then Ekind (T) = E_Incomplete_Type
10193 and then Nkind (Parent (S)) = N_Subtype_Declaration
10194 and then not Is_Itype (Def_Id)
10196 -- A little sanity check, emit an error message if the type
10197 -- has discriminants to begin with. Type T may be a regular
10198 -- incomplete type or imported via a limited with clause.
10200 if Has_Discriminants (T)
10202 (From_With_Type (T)
10203 and then Present (Non_Limited_View (T))
10204 and then Nkind (Parent (Non_Limited_View (T))) =
10205 N_Full_Type_Declaration
10206 and then Present (Discriminant_Specifications
10207 (Parent (Non_Limited_View (T)))))
10210 ("(Ada 2005) incomplete subtype may not be constrained", C);
10213 ("invalid constraint: type has no discriminant", C);
10216 Fixup_Bad_Constraint;
10219 -- Check that the type has visible discriminants. The type may be
10220 -- a private type with unknown discriminants whose full view has
10221 -- discriminants which are invisible.
10223 elsif not Has_Discriminants (T)
10225 (Has_Unknown_Discriminants (T)
10226 and then Is_Private_Type (T))
10228 Error_Msg_N ("invalid constraint: type has no discriminant", C);
10229 Fixup_Bad_Constraint;
10232 elsif Is_Constrained (E)
10233 or else (Ekind (E) = E_Class_Wide_Subtype
10234 and then Present (Discriminant_Constraint (E)))
10236 Error_Msg_N ("type is already constrained", Subtype_Mark (S));
10237 Fixup_Bad_Constraint;
10241 -- T may be an unconstrained subtype (e.g. a generic actual).
10242 -- Constraint applies to the base type.
10244 T := Base_Type (T);
10246 Elist := Build_Discriminant_Constraints (T, S);
10248 -- If the list returned was empty we had an error in building the
10249 -- discriminant constraint. We have also already signalled an error
10250 -- in the incomplete type case
10252 if Is_Empty_Elmt_List (Elist) then
10253 Fixup_Bad_Constraint;
10257 Build_Discriminated_Subtype (T, Def_Id, Elist, Related_Nod, For_Access);
10258 end Constrain_Discriminated_Type;
10260 ---------------------------
10261 -- Constrain_Enumeration --
10262 ---------------------------
10264 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id) is
10265 T : constant Entity_Id := Entity (Subtype_Mark (S));
10266 C : constant Node_Id := Constraint (S);
10269 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10271 Set_First_Literal (Def_Id, First_Literal (Base_Type (T)));
10273 Set_Etype (Def_Id, Base_Type (T));
10274 Set_Size_Info (Def_Id, (T));
10275 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10276 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10278 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10280 Set_Discrete_RM_Size (Def_Id);
10281 end Constrain_Enumeration;
10283 ----------------------
10284 -- Constrain_Float --
10285 ----------------------
10287 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id) is
10288 T : constant Entity_Id := Entity (Subtype_Mark (S));
10294 Set_Ekind (Def_Id, E_Floating_Point_Subtype);
10296 Set_Etype (Def_Id, Base_Type (T));
10297 Set_Size_Info (Def_Id, (T));
10298 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10300 -- Process the constraint
10302 C := Constraint (S);
10304 -- Digits constraint present
10306 if Nkind (C) = N_Digits_Constraint then
10307 Check_Restriction (No_Obsolescent_Features, C);
10309 if Warn_On_Obsolescent_Feature then
10311 ("subtype digits constraint is an " &
10312 "obsolescent feature (RM J.3(8))?", C);
10315 D := Digits_Expression (C);
10316 Analyze_And_Resolve (D, Any_Integer);
10317 Check_Digits_Expression (D);
10318 Set_Digits_Value (Def_Id, Expr_Value (D));
10320 -- Check that digits value is in range. Obviously we can do this
10321 -- at compile time, but it is strictly a runtime check, and of
10322 -- course there is an ACVC test that checks this!
10324 if Digits_Value (Def_Id) > Digits_Value (T) then
10325 Error_Msg_Uint_1 := Digits_Value (T);
10326 Error_Msg_N ("?digits value is too large, maximum is ^", D);
10328 Make_Raise_Constraint_Error (Sloc (D),
10329 Reason => CE_Range_Check_Failed);
10330 Insert_Action (Declaration_Node (Def_Id), Rais);
10333 C := Range_Constraint (C);
10335 -- No digits constraint present
10338 Set_Digits_Value (Def_Id, Digits_Value (T));
10341 -- Range constraint present
10343 if Nkind (C) = N_Range_Constraint then
10344 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10346 -- No range constraint present
10349 pragma Assert (No (C));
10350 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10353 Set_Is_Constrained (Def_Id);
10354 end Constrain_Float;
10356 ---------------------
10357 -- Constrain_Index --
10358 ---------------------
10360 procedure Constrain_Index
10363 Related_Nod : Node_Id;
10364 Related_Id : Entity_Id;
10365 Suffix : Character;
10366 Suffix_Index : Nat)
10368 Def_Id : Entity_Id;
10369 R : Node_Id := Empty;
10370 T : constant Entity_Id := Etype (Index);
10373 if Nkind (S) = N_Range
10375 (Nkind (S) = N_Attribute_Reference
10376 and then Attribute_Name (S) = Name_Range)
10378 -- A Range attribute will transformed into N_Range by Resolve
10384 Process_Range_Expr_In_Decl (R, T, Empty_List);
10386 if not Error_Posted (S)
10388 (Nkind (S) /= N_Range
10389 or else not Covers (T, (Etype (Low_Bound (S))))
10390 or else not Covers (T, (Etype (High_Bound (S)))))
10392 if Base_Type (T) /= Any_Type
10393 and then Etype (Low_Bound (S)) /= Any_Type
10394 and then Etype (High_Bound (S)) /= Any_Type
10396 Error_Msg_N ("range expected", S);
10400 elsif Nkind (S) = N_Subtype_Indication then
10402 -- The parser has verified that this is a discrete indication
10404 Resolve_Discrete_Subtype_Indication (S, T);
10405 R := Range_Expression (Constraint (S));
10407 elsif Nkind (S) = N_Discriminant_Association then
10409 -- Syntactically valid in subtype indication
10411 Error_Msg_N ("invalid index constraint", S);
10412 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10415 -- Subtype_Mark case, no anonymous subtypes to construct
10420 if Is_Entity_Name (S) then
10421 if not Is_Type (Entity (S)) then
10422 Error_Msg_N ("expect subtype mark for index constraint", S);
10424 elsif Base_Type (Entity (S)) /= Base_Type (T) then
10425 Wrong_Type (S, Base_Type (T));
10431 Error_Msg_N ("invalid index constraint", S);
10432 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10438 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index);
10440 Set_Etype (Def_Id, Base_Type (T));
10442 if Is_Modular_Integer_Type (T) then
10443 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10445 elsif Is_Integer_Type (T) then
10446 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10449 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10450 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10453 Set_Size_Info (Def_Id, (T));
10454 Set_RM_Size (Def_Id, RM_Size (T));
10455 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10457 Set_Scalar_Range (Def_Id, R);
10459 Set_Etype (S, Def_Id);
10460 Set_Discrete_RM_Size (Def_Id);
10461 end Constrain_Index;
10463 -----------------------
10464 -- Constrain_Integer --
10465 -----------------------
10467 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id) is
10468 T : constant Entity_Id := Entity (Subtype_Mark (S));
10469 C : constant Node_Id := Constraint (S);
10472 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10474 if Is_Modular_Integer_Type (T) then
10475 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10477 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10480 Set_Etype (Def_Id, Base_Type (T));
10481 Set_Size_Info (Def_Id, (T));
10482 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10483 Set_Discrete_RM_Size (Def_Id);
10484 end Constrain_Integer;
10486 ------------------------------
10487 -- Constrain_Ordinary_Fixed --
10488 ------------------------------
10490 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id) is
10491 T : constant Entity_Id := Entity (Subtype_Mark (S));
10497 Set_Ekind (Def_Id, E_Ordinary_Fixed_Point_Subtype);
10498 Set_Etype (Def_Id, Base_Type (T));
10499 Set_Size_Info (Def_Id, (T));
10500 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10501 Set_Small_Value (Def_Id, Small_Value (T));
10503 -- Process the constraint
10505 C := Constraint (S);
10507 -- Delta constraint present
10509 if Nkind (C) = N_Delta_Constraint then
10510 Check_Restriction (No_Obsolescent_Features, C);
10512 if Warn_On_Obsolescent_Feature then
10514 ("subtype delta constraint is an " &
10515 "obsolescent feature (RM J.3(7))?");
10518 D := Delta_Expression (C);
10519 Analyze_And_Resolve (D, Any_Real);
10520 Check_Delta_Expression (D);
10521 Set_Delta_Value (Def_Id, Expr_Value_R (D));
10523 -- Check that delta value is in range. Obviously we can do this
10524 -- at compile time, but it is strictly a runtime check, and of
10525 -- course there is an ACVC test that checks this!
10527 if Delta_Value (Def_Id) < Delta_Value (T) then
10528 Error_Msg_N ("?delta value is too small", D);
10530 Make_Raise_Constraint_Error (Sloc (D),
10531 Reason => CE_Range_Check_Failed);
10532 Insert_Action (Declaration_Node (Def_Id), Rais);
10535 C := Range_Constraint (C);
10537 -- No delta constraint present
10540 Set_Delta_Value (Def_Id, Delta_Value (T));
10543 -- Range constraint present
10545 if Nkind (C) = N_Range_Constraint then
10546 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10548 -- No range constraint present
10551 pragma Assert (No (C));
10552 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10556 Set_Discrete_RM_Size (Def_Id);
10558 -- Unconditionally delay the freeze, since we cannot set size
10559 -- information in all cases correctly until the freeze point.
10561 Set_Has_Delayed_Freeze (Def_Id);
10562 end Constrain_Ordinary_Fixed;
10564 -----------------------
10565 -- Contain_Interface --
10566 -----------------------
10568 function Contain_Interface
10569 (Iface : Entity_Id;
10570 Ifaces : Elist_Id) return Boolean
10572 Iface_Elmt : Elmt_Id;
10575 if Present (Ifaces) then
10576 Iface_Elmt := First_Elmt (Ifaces);
10577 while Present (Iface_Elmt) loop
10578 if Node (Iface_Elmt) = Iface then
10582 Next_Elmt (Iface_Elmt);
10587 end Contain_Interface;
10589 ---------------------------
10590 -- Convert_Scalar_Bounds --
10591 ---------------------------
10593 procedure Convert_Scalar_Bounds
10595 Parent_Type : Entity_Id;
10596 Derived_Type : Entity_Id;
10599 Implicit_Base : constant Entity_Id := Base_Type (Derived_Type);
10606 Lo := Build_Scalar_Bound
10607 (Type_Low_Bound (Derived_Type),
10608 Parent_Type, Implicit_Base);
10610 Hi := Build_Scalar_Bound
10611 (Type_High_Bound (Derived_Type),
10612 Parent_Type, Implicit_Base);
10619 Set_Includes_Infinities (Rng, Has_Infinities (Derived_Type));
10621 Set_Parent (Rng, N);
10622 Set_Scalar_Range (Derived_Type, Rng);
10624 -- Analyze the bounds
10626 Analyze_And_Resolve (Lo, Implicit_Base);
10627 Analyze_And_Resolve (Hi, Implicit_Base);
10629 -- Analyze the range itself, except that we do not analyze it if
10630 -- the bounds are real literals, and we have a fixed-point type.
10631 -- The reason for this is that we delay setting the bounds in this
10632 -- case till we know the final Small and Size values (see circuit
10633 -- in Freeze.Freeze_Fixed_Point_Type for further details).
10635 if Is_Fixed_Point_Type (Parent_Type)
10636 and then Nkind (Lo) = N_Real_Literal
10637 and then Nkind (Hi) = N_Real_Literal
10641 -- Here we do the analysis of the range
10643 -- Note: we do this manually, since if we do a normal Analyze and
10644 -- Resolve call, there are problems with the conversions used for
10645 -- the derived type range.
10648 Set_Etype (Rng, Implicit_Base);
10649 Set_Analyzed (Rng, True);
10651 end Convert_Scalar_Bounds;
10653 -------------------
10654 -- Copy_And_Swap --
10655 -------------------
10657 procedure Copy_And_Swap (Priv, Full : Entity_Id) is
10659 -- Initialize new full declaration entity by copying the pertinent
10660 -- fields of the corresponding private declaration entity.
10662 -- We temporarily set Ekind to a value appropriate for a type to
10663 -- avoid assert failures in Einfo from checking for setting type
10664 -- attributes on something that is not a type. Ekind (Priv) is an
10665 -- appropriate choice, since it allowed the attributes to be set
10666 -- in the first place. This Ekind value will be modified later.
10668 Set_Ekind (Full, Ekind (Priv));
10670 -- Also set Etype temporarily to Any_Type, again, in the absence
10671 -- of errors, it will be properly reset, and if there are errors,
10672 -- then we want a value of Any_Type to remain.
10674 Set_Etype (Full, Any_Type);
10676 -- Now start copying attributes
10678 Set_Has_Discriminants (Full, Has_Discriminants (Priv));
10680 if Has_Discriminants (Full) then
10681 Set_Discriminant_Constraint (Full, Discriminant_Constraint (Priv));
10682 Set_Stored_Constraint (Full, Stored_Constraint (Priv));
10685 Set_First_Rep_Item (Full, First_Rep_Item (Priv));
10686 Set_Homonym (Full, Homonym (Priv));
10687 Set_Is_Immediately_Visible (Full, Is_Immediately_Visible (Priv));
10688 Set_Is_Public (Full, Is_Public (Priv));
10689 Set_Is_Pure (Full, Is_Pure (Priv));
10690 Set_Is_Tagged_Type (Full, Is_Tagged_Type (Priv));
10691 Set_Has_Pragma_Unreferenced (Full, Has_Pragma_Unreferenced (Priv));
10692 Set_Has_Pragma_Unreferenced_Objects
10693 (Full, Has_Pragma_Unreferenced_Objects
10696 Conditional_Delay (Full, Priv);
10698 if Is_Tagged_Type (Full) then
10699 Set_Primitive_Operations (Full, Primitive_Operations (Priv));
10701 if Priv = Base_Type (Priv) then
10702 Set_Class_Wide_Type (Full, Class_Wide_Type (Priv));
10706 Set_Is_Volatile (Full, Is_Volatile (Priv));
10707 Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv));
10708 Set_Scope (Full, Scope (Priv));
10709 Set_Next_Entity (Full, Next_Entity (Priv));
10710 Set_First_Entity (Full, First_Entity (Priv));
10711 Set_Last_Entity (Full, Last_Entity (Priv));
10713 -- If access types have been recorded for later handling, keep them in
10714 -- the full view so that they get handled when the full view freeze
10715 -- node is expanded.
10717 if Present (Freeze_Node (Priv))
10718 and then Present (Access_Types_To_Process (Freeze_Node (Priv)))
10720 Ensure_Freeze_Node (Full);
10721 Set_Access_Types_To_Process
10722 (Freeze_Node (Full),
10723 Access_Types_To_Process (Freeze_Node (Priv)));
10726 -- Swap the two entities. Now Privat is the full type entity and
10727 -- Full is the private one. They will be swapped back at the end
10728 -- of the private part. This swapping ensures that the entity that
10729 -- is visible in the private part is the full declaration.
10731 Exchange_Entities (Priv, Full);
10732 Append_Entity (Full, Scope (Full));
10735 -------------------------------------
10736 -- Copy_Array_Base_Type_Attributes --
10737 -------------------------------------
10739 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id) is
10741 Set_Component_Alignment (T1, Component_Alignment (T2));
10742 Set_Component_Type (T1, Component_Type (T2));
10743 Set_Component_Size (T1, Component_Size (T2));
10744 Set_Has_Controlled_Component (T1, Has_Controlled_Component (T2));
10745 Set_Finalize_Storage_Only (T1, Finalize_Storage_Only (T2));
10746 Set_Has_Non_Standard_Rep (T1, Has_Non_Standard_Rep (T2));
10747 Set_Has_Task (T1, Has_Task (T2));
10748 Set_Is_Packed (T1, Is_Packed (T2));
10749 Set_Has_Aliased_Components (T1, Has_Aliased_Components (T2));
10750 Set_Has_Atomic_Components (T1, Has_Atomic_Components (T2));
10751 Set_Has_Volatile_Components (T1, Has_Volatile_Components (T2));
10752 end Copy_Array_Base_Type_Attributes;
10754 -----------------------------------
10755 -- Copy_Array_Subtype_Attributes --
10756 -----------------------------------
10758 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id) is
10760 Set_Size_Info (T1, T2);
10762 Set_First_Index (T1, First_Index (T2));
10763 Set_Is_Aliased (T1, Is_Aliased (T2));
10764 Set_Is_Atomic (T1, Is_Atomic (T2));
10765 Set_Is_Volatile (T1, Is_Volatile (T2));
10766 Set_Treat_As_Volatile (T1, Treat_As_Volatile (T2));
10767 Set_Is_Constrained (T1, Is_Constrained (T2));
10768 Set_Depends_On_Private (T1, Has_Private_Component (T2));
10769 Set_First_Rep_Item (T1, First_Rep_Item (T2));
10770 Set_Convention (T1, Convention (T2));
10771 Set_Is_Limited_Composite (T1, Is_Limited_Composite (T2));
10772 Set_Is_Private_Composite (T1, Is_Private_Composite (T2));
10773 end Copy_Array_Subtype_Attributes;
10775 -----------------------------------
10776 -- Create_Constrained_Components --
10777 -----------------------------------
10779 procedure Create_Constrained_Components
10781 Decl_Node : Node_Id;
10783 Constraints : Elist_Id)
10785 Loc : constant Source_Ptr := Sloc (Subt);
10786 Comp_List : constant Elist_Id := New_Elmt_List;
10787 Parent_Type : constant Entity_Id := Etype (Typ);
10788 Assoc_List : constant List_Id := New_List;
10789 Discr_Val : Elmt_Id;
10793 Is_Static : Boolean := True;
10795 procedure Collect_Fixed_Components (Typ : Entity_Id);
10796 -- Collect parent type components that do not appear in a variant part
10798 procedure Create_All_Components;
10799 -- Iterate over Comp_List to create the components of the subtype
10801 function Create_Component (Old_Compon : Entity_Id) return Entity_Id;
10802 -- Creates a new component from Old_Compon, copying all the fields from
10803 -- it, including its Etype, inserts the new component in the Subt entity
10804 -- chain and returns the new component.
10806 function Is_Variant_Record (T : Entity_Id) return Boolean;
10807 -- If true, and discriminants are static, collect only components from
10808 -- variants selected by discriminant values.
10810 ------------------------------
10811 -- Collect_Fixed_Components --
10812 ------------------------------
10814 procedure Collect_Fixed_Components (Typ : Entity_Id) is
10816 -- Build association list for discriminants, and find components of the
10817 -- variant part selected by the values of the discriminants.
10819 Old_C := First_Discriminant (Typ);
10820 Discr_Val := First_Elmt (Constraints);
10821 while Present (Old_C) loop
10822 Append_To (Assoc_List,
10823 Make_Component_Association (Loc,
10824 Choices => New_List (New_Occurrence_Of (Old_C, Loc)),
10825 Expression => New_Copy (Node (Discr_Val))));
10827 Next_Elmt (Discr_Val);
10828 Next_Discriminant (Old_C);
10831 -- The tag, and the possible parent and controller components
10832 -- are unconditionally in the subtype.
10834 if Is_Tagged_Type (Typ)
10835 or else Has_Controlled_Component (Typ)
10837 Old_C := First_Component (Typ);
10838 while Present (Old_C) loop
10839 if Chars ((Old_C)) = Name_uTag
10840 or else Chars ((Old_C)) = Name_uParent
10841 or else Chars ((Old_C)) = Name_uController
10843 Append_Elmt (Old_C, Comp_List);
10846 Next_Component (Old_C);
10849 end Collect_Fixed_Components;
10851 ---------------------------
10852 -- Create_All_Components --
10853 ---------------------------
10855 procedure Create_All_Components is
10859 Comp := First_Elmt (Comp_List);
10860 while Present (Comp) loop
10861 Old_C := Node (Comp);
10862 New_C := Create_Component (Old_C);
10866 Constrain_Component_Type
10867 (Old_C, Subt, Decl_Node, Typ, Constraints));
10868 Set_Is_Public (New_C, Is_Public (Subt));
10872 end Create_All_Components;
10874 ----------------------
10875 -- Create_Component --
10876 ----------------------
10878 function Create_Component (Old_Compon : Entity_Id) return Entity_Id is
10879 New_Compon : constant Entity_Id := New_Copy (Old_Compon);
10882 if Ekind (Old_Compon) = E_Discriminant
10883 and then Is_Completely_Hidden (Old_Compon)
10885 -- This is a shadow discriminant created for a discriminant of
10886 -- the parent type that is one of several renamed by the same
10887 -- new discriminant. Give the shadow discriminant an internal
10888 -- name that cannot conflict with that of visible components.
10890 Set_Chars (New_Compon, New_Internal_Name ('C'));
10893 -- Set the parent so we have a proper link for freezing etc. This is
10894 -- not a real parent pointer, since of course our parent does not own
10895 -- up to us and reference us, we are an illegitimate child of the
10896 -- original parent!
10898 Set_Parent (New_Compon, Parent (Old_Compon));
10900 -- If the old component's Esize was already determined and is a
10901 -- static value, then the new component simply inherits it. Otherwise
10902 -- the old component's size may require run-time determination, but
10903 -- the new component's size still might be statically determinable
10904 -- (if, for example it has a static constraint). In that case we want
10905 -- Layout_Type to recompute the component's size, so we reset its
10906 -- size and positional fields.
10908 if Frontend_Layout_On_Target
10909 and then not Known_Static_Esize (Old_Compon)
10911 Set_Esize (New_Compon, Uint_0);
10912 Init_Normalized_First_Bit (New_Compon);
10913 Init_Normalized_Position (New_Compon);
10914 Init_Normalized_Position_Max (New_Compon);
10917 -- We do not want this node marked as Comes_From_Source, since
10918 -- otherwise it would get first class status and a separate cross-
10919 -- reference line would be generated. Illegitimate children do not
10920 -- rate such recognition.
10922 Set_Comes_From_Source (New_Compon, False);
10924 -- But it is a real entity, and a birth certificate must be properly
10925 -- registered by entering it into the entity list.
10927 Enter_Name (New_Compon);
10930 end Create_Component;
10932 -----------------------
10933 -- Is_Variant_Record --
10934 -----------------------
10936 function Is_Variant_Record (T : Entity_Id) return Boolean is
10938 return Nkind (Parent (T)) = N_Full_Type_Declaration
10939 and then Nkind (Type_Definition (Parent (T))) = N_Record_Definition
10940 and then Present (Component_List (Type_Definition (Parent (T))))
10943 (Variant_Part (Component_List (Type_Definition (Parent (T)))));
10944 end Is_Variant_Record;
10946 -- Start of processing for Create_Constrained_Components
10949 pragma Assert (Subt /= Base_Type (Subt));
10950 pragma Assert (Typ = Base_Type (Typ));
10952 Set_First_Entity (Subt, Empty);
10953 Set_Last_Entity (Subt, Empty);
10955 -- Check whether constraint is fully static, in which case we can
10956 -- optimize the list of components.
10958 Discr_Val := First_Elmt (Constraints);
10959 while Present (Discr_Val) loop
10960 if not Is_OK_Static_Expression (Node (Discr_Val)) then
10961 Is_Static := False;
10965 Next_Elmt (Discr_Val);
10968 Set_Has_Static_Discriminants (Subt, Is_Static);
10972 -- Inherit the discriminants of the parent type
10974 Add_Discriminants : declare
10980 Old_C := First_Discriminant (Typ);
10982 while Present (Old_C) loop
10983 Num_Disc := Num_Disc + 1;
10984 New_C := Create_Component (Old_C);
10985 Set_Is_Public (New_C, Is_Public (Subt));
10986 Next_Discriminant (Old_C);
10989 -- For an untagged derived subtype, the number of discriminants may
10990 -- be smaller than the number of inherited discriminants, because
10991 -- several of them may be renamed by a single new discriminant.
10992 -- In this case, add the hidden discriminants back into the subtype,
10993 -- because otherwise the size of the subtype is computed incorrectly
10998 if Is_Derived_Type (Typ)
10999 and then not Is_Tagged_Type (Typ)
11001 Old_C := First_Stored_Discriminant (Typ);
11003 while Present (Old_C) loop
11004 Num_Gird := Num_Gird + 1;
11005 Next_Stored_Discriminant (Old_C);
11009 if Num_Gird > Num_Disc then
11011 -- Find out multiple uses of new discriminants, and add hidden
11012 -- components for the extra renamed discriminants. We recognize
11013 -- multiple uses through the Corresponding_Discriminant of a
11014 -- new discriminant: if it constrains several old discriminants,
11015 -- this field points to the last one in the parent type. The
11016 -- stored discriminants of the derived type have the same name
11017 -- as those of the parent.
11021 New_Discr : Entity_Id;
11022 Old_Discr : Entity_Id;
11025 Constr := First_Elmt (Stored_Constraint (Typ));
11026 Old_Discr := First_Stored_Discriminant (Typ);
11027 while Present (Constr) loop
11028 if Is_Entity_Name (Node (Constr))
11029 and then Ekind (Entity (Node (Constr))) = E_Discriminant
11031 New_Discr := Entity (Node (Constr));
11033 if Chars (Corresponding_Discriminant (New_Discr)) /=
11036 -- The new discriminant has been used to rename a
11037 -- subsequent old discriminant. Introduce a shadow
11038 -- component for the current old discriminant.
11040 New_C := Create_Component (Old_Discr);
11041 Set_Original_Record_Component (New_C, Old_Discr);
11045 Next_Elmt (Constr);
11046 Next_Stored_Discriminant (Old_Discr);
11050 end Add_Discriminants;
11053 and then Is_Variant_Record (Typ)
11055 Collect_Fixed_Components (Typ);
11057 Gather_Components (
11059 Component_List (Type_Definition (Parent (Typ))),
11060 Governed_By => Assoc_List,
11062 Report_Errors => Errors);
11063 pragma Assert (not Errors);
11065 Create_All_Components;
11067 -- If the subtype declaration is created for a tagged type derivation
11068 -- with constraints, we retrieve the record definition of the parent
11069 -- type to select the components of the proper variant.
11072 and then Is_Tagged_Type (Typ)
11073 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11075 Nkind (Type_Definition (Parent (Typ))) = N_Derived_Type_Definition
11076 and then Is_Variant_Record (Parent_Type)
11078 Collect_Fixed_Components (Typ);
11080 Gather_Components (
11082 Component_List (Type_Definition (Parent (Parent_Type))),
11083 Governed_By => Assoc_List,
11085 Report_Errors => Errors);
11086 pragma Assert (not Errors);
11088 -- If the tagged derivation has a type extension, collect all the
11089 -- new components therein.
11092 (Record_Extension_Part (Type_Definition (Parent (Typ))))
11094 Old_C := First_Component (Typ);
11095 while Present (Old_C) loop
11096 if Original_Record_Component (Old_C) = Old_C
11097 and then Chars (Old_C) /= Name_uTag
11098 and then Chars (Old_C) /= Name_uParent
11099 and then Chars (Old_C) /= Name_uController
11101 Append_Elmt (Old_C, Comp_List);
11104 Next_Component (Old_C);
11108 Create_All_Components;
11111 -- If discriminants are not static, or if this is a multi-level type
11112 -- extension, we have to include all components of the parent type.
11114 Old_C := First_Component (Typ);
11115 while Present (Old_C) loop
11116 New_C := Create_Component (Old_C);
11120 Constrain_Component_Type
11121 (Old_C, Subt, Decl_Node, Typ, Constraints));
11122 Set_Is_Public (New_C, Is_Public (Subt));
11124 Next_Component (Old_C);
11129 end Create_Constrained_Components;
11131 ------------------------------------------
11132 -- Decimal_Fixed_Point_Type_Declaration --
11133 ------------------------------------------
11135 procedure Decimal_Fixed_Point_Type_Declaration
11139 Loc : constant Source_Ptr := Sloc (Def);
11140 Digs_Expr : constant Node_Id := Digits_Expression (Def);
11141 Delta_Expr : constant Node_Id := Delta_Expression (Def);
11142 Implicit_Base : Entity_Id;
11148 -- Start of processing for Decimal_Fixed_Point_Type_Declaration
11151 Check_Restriction (No_Fixed_Point, Def);
11153 -- Create implicit base type
11156 Create_Itype (E_Decimal_Fixed_Point_Type, Parent (Def), T, 'B');
11157 Set_Etype (Implicit_Base, Implicit_Base);
11159 -- Analyze and process delta expression
11161 Analyze_And_Resolve (Delta_Expr, Universal_Real);
11163 Check_Delta_Expression (Delta_Expr);
11164 Delta_Val := Expr_Value_R (Delta_Expr);
11166 -- Check delta is power of 10, and determine scale value from it
11172 Scale_Val := Uint_0;
11175 if Val < Ureal_1 then
11176 while Val < Ureal_1 loop
11177 Val := Val * Ureal_10;
11178 Scale_Val := Scale_Val + 1;
11181 if Scale_Val > 18 then
11182 Error_Msg_N ("scale exceeds maximum value of 18", Def);
11183 Scale_Val := UI_From_Int (+18);
11187 while Val > Ureal_1 loop
11188 Val := Val / Ureal_10;
11189 Scale_Val := Scale_Val - 1;
11192 if Scale_Val < -18 then
11193 Error_Msg_N ("scale is less than minimum value of -18", Def);
11194 Scale_Val := UI_From_Int (-18);
11198 if Val /= Ureal_1 then
11199 Error_Msg_N ("delta expression must be a power of 10", Def);
11200 Delta_Val := Ureal_10 ** (-Scale_Val);
11204 -- Set delta, scale and small (small = delta for decimal type)
11206 Set_Delta_Value (Implicit_Base, Delta_Val);
11207 Set_Scale_Value (Implicit_Base, Scale_Val);
11208 Set_Small_Value (Implicit_Base, Delta_Val);
11210 -- Analyze and process digits expression
11212 Analyze_And_Resolve (Digs_Expr, Any_Integer);
11213 Check_Digits_Expression (Digs_Expr);
11214 Digs_Val := Expr_Value (Digs_Expr);
11216 if Digs_Val > 18 then
11217 Digs_Val := UI_From_Int (+18);
11218 Error_Msg_N ("digits value out of range, maximum is 18", Digs_Expr);
11221 Set_Digits_Value (Implicit_Base, Digs_Val);
11222 Bound_Val := UR_From_Uint (10 ** Digs_Val - 1) * Delta_Val;
11224 -- Set range of base type from digits value for now. This will be
11225 -- expanded to represent the true underlying base range by Freeze.
11227 Set_Fixed_Range (Implicit_Base, Loc, -Bound_Val, Bound_Val);
11229 -- Note: We leave size as zero for now, size will be set at freeze
11230 -- time. We have to do this for ordinary fixed-point, because the size
11231 -- depends on the specified small, and we might as well do the same for
11232 -- decimal fixed-point.
11234 pragma Assert (Esize (Implicit_Base) = Uint_0);
11236 -- If there are bounds given in the declaration use them as the
11237 -- bounds of the first named subtype.
11239 if Present (Real_Range_Specification (Def)) then
11241 RRS : constant Node_Id := Real_Range_Specification (Def);
11242 Low : constant Node_Id := Low_Bound (RRS);
11243 High : constant Node_Id := High_Bound (RRS);
11248 Analyze_And_Resolve (Low, Any_Real);
11249 Analyze_And_Resolve (High, Any_Real);
11250 Check_Real_Bound (Low);
11251 Check_Real_Bound (High);
11252 Low_Val := Expr_Value_R (Low);
11253 High_Val := Expr_Value_R (High);
11255 if Low_Val < (-Bound_Val) then
11257 ("range low bound too small for digits value", Low);
11258 Low_Val := -Bound_Val;
11261 if High_Val > Bound_Val then
11263 ("range high bound too large for digits value", High);
11264 High_Val := Bound_Val;
11267 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
11270 -- If no explicit range, use range that corresponds to given
11271 -- digits value. This will end up as the final range for the
11275 Set_Fixed_Range (T, Loc, -Bound_Val, Bound_Val);
11278 -- Complete entity for first subtype
11280 Set_Ekind (T, E_Decimal_Fixed_Point_Subtype);
11281 Set_Etype (T, Implicit_Base);
11282 Set_Size_Info (T, Implicit_Base);
11283 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
11284 Set_Digits_Value (T, Digs_Val);
11285 Set_Delta_Value (T, Delta_Val);
11286 Set_Small_Value (T, Delta_Val);
11287 Set_Scale_Value (T, Scale_Val);
11288 Set_Is_Constrained (T);
11289 end Decimal_Fixed_Point_Type_Declaration;
11291 ----------------------------------
11292 -- Derive_Interface_Subprograms --
11293 ----------------------------------
11295 procedure Derive_Interface_Subprograms
11296 (Parent_Type : Entity_Id;
11297 Tagged_Type : Entity_Id;
11298 Ifaces_List : Elist_Id)
11300 function Collect_Interface_Primitives
11301 (Tagged_Type : Entity_Id) return Elist_Id;
11302 -- Ada 2005 (AI-251): Collect the primitives of all the implemented
11305 function In_List (L : Elist_Id; Subp : Entity_Id) return Boolean;
11306 -- Determine if Subp already in the list L
11308 procedure Remove_Homonym (E : Entity_Id);
11309 -- Removes E from the homonym chain
11311 ----------------------------------
11312 -- Collect_Interface_Primitives --
11313 ----------------------------------
11315 function Collect_Interface_Primitives
11316 (Tagged_Type : Entity_Id) return Elist_Id
11318 Op_List : constant Elist_Id := New_Elmt_List;
11320 Ifaces_List : Elist_Id;
11321 Iface_Elmt : Elmt_Id;
11325 pragma Assert (Is_Tagged_Type (Tagged_Type)
11326 and then Has_Abstract_Interfaces (Tagged_Type));
11328 Collect_Abstract_Interfaces (Tagged_Type, Ifaces_List);
11330 Iface_Elmt := First_Elmt (Ifaces_List);
11331 while Present (Iface_Elmt) loop
11332 Elmt := First_Elmt (Primitive_Operations (Node (Iface_Elmt)));
11333 while Present (Elmt) loop
11334 Prim := Node (Elmt);
11336 if not Is_Predefined_Dispatching_Operation (Prim) then
11337 Append_Elmt (Prim, Op_List);
11343 Next_Elmt (Iface_Elmt);
11347 end Collect_Interface_Primitives;
11353 function In_List (L : Elist_Id; Subp : Entity_Id) return Boolean is
11357 Elmt := First_Elmt (L);
11358 while Present (Elmt) loop
11359 if Node (Elmt) = Subp then
11369 --------------------
11370 -- Remove_Homonym --
11371 --------------------
11373 procedure Remove_Homonym (E : Entity_Id) is
11374 Prev : Entity_Id := Empty;
11378 if E = Current_Entity (E) then
11379 Set_Current_Entity (Homonym (E));
11381 H := Current_Entity (E);
11382 while Present (H) and then H /= E loop
11387 Set_Homonym (Prev, Homonym (E));
11389 end Remove_Homonym;
11396 Iface_Subp : Entity_Id;
11397 New_Subp : Entity_Id := Empty;
11398 Op_List : Elist_Id;
11399 Parent_Base : Entity_Id;
11402 -- Start of processing for Derive_Interface_Subprograms
11405 if Ada_Version < Ada_05
11406 or else not Is_Record_Type (Tagged_Type)
11407 or else not Is_Tagged_Type (Tagged_Type)
11408 or else not Has_Abstract_Interfaces (Tagged_Type)
11413 -- Add to the list of interface subprograms all the primitives inherited
11414 -- from abstract interfaces that are not immediate ancestors and also
11415 -- add their derivation to the list of interface primitives.
11417 Op_List := Collect_Interface_Primitives (Tagged_Type);
11419 Elmt := First_Elmt (Op_List);
11420 while Present (Elmt) loop
11421 Subp := Node (Elmt);
11422 Iface := Find_Dispatching_Type (Subp);
11424 if Is_Concurrent_Record_Type (Tagged_Type) then
11425 if not Present (Abstract_Interface_Alias (Subp)) then
11426 Derive_Subprogram (New_Subp, Subp, Tagged_Type, Iface);
11427 Append_Elmt (New_Subp, Ifaces_List);
11430 elsif not Is_Parent (Iface, Tagged_Type) then
11431 Derive_Subprogram (New_Subp, Subp, Tagged_Type, Iface);
11432 Append_Elmt (New_Subp, Ifaces_List);
11438 -- Complete the derivation of the interface subprograms. Assign to each
11439 -- entity associated with abstract interfaces their aliased entity and
11440 -- complete their decoration as hidden interface entities that will be
11441 -- used later to build the secondary dispatch tables.
11443 if not Is_Empty_Elmt_List (Ifaces_List) then
11444 if Ekind (Parent_Type) = E_Record_Type_With_Private
11445 and then Has_Discriminants (Parent_Type)
11446 and then Present (Full_View (Parent_Type))
11448 Parent_Base := Full_View (Parent_Type);
11450 Parent_Base := Parent_Type;
11453 Elmt := First_Elmt (Ifaces_List);
11454 while Present (Elmt) loop
11455 Iface_Subp := Node (Elmt);
11457 -- Look for the first overriding entity in the homonym chain.
11458 -- In this way if we are in the private part of a package spec
11459 -- we get the last overriding subprogram.
11461 E := Current_Entity_In_Scope (Iface_Subp);
11462 while Present (E) loop
11463 if Is_Dispatching_Operation (E)
11464 and then Scope (E) = Scope (Iface_Subp)
11465 and then Type_Conformant (E, Iface_Subp)
11466 and then not In_List (Ifaces_List, E)
11474 -- Create an overriding entity if not found in the homonym chain
11476 if not Present (E) then
11478 (E, Alias (Iface_Subp), Tagged_Type, Parent_Base);
11480 elsif not In_List (Primitive_Operations (Tagged_Type), E) then
11482 -- Inherit the operation from the private view
11484 Append_Elmt (E, Primitive_Operations (Tagged_Type));
11487 -- Complete the decoration of the hidden interface entity
11489 Set_Is_Hidden (Iface_Subp);
11490 Set_Abstract_Interface_Alias (Iface_Subp, Alias (Iface_Subp));
11491 Set_Alias (Iface_Subp, E);
11492 Set_Is_Abstract_Subprogram (Iface_Subp,
11493 Is_Abstract_Subprogram (E));
11494 Remove_Homonym (Iface_Subp);
11496 -- Hidden entities associated with interfaces must have set the
11497 -- Has_Delay_Freeze attribute to ensure that the corresponding
11498 -- entry of the secondary dispatch table is filled when such
11499 -- entity is frozen.
11501 Set_Has_Delayed_Freeze (Iface_Subp);
11506 end Derive_Interface_Subprograms;
11508 -----------------------
11509 -- Derive_Subprogram --
11510 -----------------------
11512 procedure Derive_Subprogram
11513 (New_Subp : in out Entity_Id;
11514 Parent_Subp : Entity_Id;
11515 Derived_Type : Entity_Id;
11516 Parent_Type : Entity_Id;
11517 Actual_Subp : Entity_Id := Empty)
11519 Formal : Entity_Id;
11520 -- Formal parameter of parent primitive operation
11522 Formal_Of_Actual : Entity_Id;
11523 -- Formal parameter of actual operation, when the derivation is to
11524 -- create a renaming for a primitive operation of an actual in an
11527 New_Formal : Entity_Id;
11528 -- Formal of inherited operation
11530 Visible_Subp : Entity_Id := Parent_Subp;
11532 function Is_Private_Overriding return Boolean;
11533 -- If Subp is a private overriding of a visible operation, the inherited
11534 -- operation derives from the overridden op (even though its body is the
11535 -- overriding one) and the inherited operation is visible now. See
11536 -- sem_disp to see the full details of the handling of the overridden
11537 -- subprogram, which is removed from the list of primitive operations of
11538 -- the type. The overridden subprogram is saved locally in Visible_Subp,
11539 -- and used to diagnose abstract operations that need overriding in the
11542 procedure Replace_Type (Id, New_Id : Entity_Id);
11543 -- When the type is an anonymous access type, create a new access type
11544 -- designating the derived type.
11546 procedure Set_Derived_Name;
11547 -- This procedure sets the appropriate Chars name for New_Subp. This
11548 -- is normally just a copy of the parent name. An exception arises for
11549 -- type support subprograms, where the name is changed to reflect the
11550 -- name of the derived type, e.g. if type foo is derived from type bar,
11551 -- then a procedure barDA is derived with a name fooDA.
11553 ---------------------------
11554 -- Is_Private_Overriding --
11555 ---------------------------
11557 function Is_Private_Overriding return Boolean is
11561 -- If the parent is not a dispatching operation there is no
11562 -- need to investigate overridings
11564 if not Is_Dispatching_Operation (Parent_Subp) then
11568 -- The visible operation that is overridden is a homonym of the
11569 -- parent subprogram. We scan the homonym chain to find the one
11570 -- whose alias is the subprogram we are deriving.
11572 Prev := Current_Entity (Parent_Subp);
11573 while Present (Prev) loop
11574 if Ekind (Prev) = Ekind (Parent_Subp)
11575 and then Alias (Prev) = Parent_Subp
11576 and then Scope (Parent_Subp) = Scope (Prev)
11577 and then not Is_Hidden (Prev)
11579 Visible_Subp := Prev;
11583 Prev := Homonym (Prev);
11587 end Is_Private_Overriding;
11593 procedure Replace_Type (Id, New_Id : Entity_Id) is
11594 Acc_Type : Entity_Id;
11595 Par : constant Node_Id := Parent (Derived_Type);
11598 -- When the type is an anonymous access type, create a new access
11599 -- type designating the derived type. This itype must be elaborated
11600 -- at the point of the derivation, not on subsequent calls that may
11601 -- be out of the proper scope for Gigi, so we insert a reference to
11602 -- it after the derivation.
11604 if Ekind (Etype (Id)) = E_Anonymous_Access_Type then
11606 Desig_Typ : Entity_Id := Designated_Type (Etype (Id));
11609 if Ekind (Desig_Typ) = E_Record_Type_With_Private
11610 and then Present (Full_View (Desig_Typ))
11611 and then not Is_Private_Type (Parent_Type)
11613 Desig_Typ := Full_View (Desig_Typ);
11616 if Base_Type (Desig_Typ) = Base_Type (Parent_Type)
11618 -- Ada 2005 (AI-251): Handle also derivations of abstract
11619 -- interface primitives.
11621 or else (Is_Interface (Desig_Typ)
11622 and then not Is_Class_Wide_Type (Desig_Typ))
11624 Acc_Type := New_Copy (Etype (Id));
11625 Set_Etype (Acc_Type, Acc_Type);
11626 Set_Scope (Acc_Type, New_Subp);
11628 -- Compute size of anonymous access type
11630 if Is_Array_Type (Desig_Typ)
11631 and then not Is_Constrained (Desig_Typ)
11633 Init_Size (Acc_Type, 2 * System_Address_Size);
11635 Init_Size (Acc_Type, System_Address_Size);
11638 Init_Alignment (Acc_Type);
11639 Set_Directly_Designated_Type (Acc_Type, Derived_Type);
11641 Set_Etype (New_Id, Acc_Type);
11642 Set_Scope (New_Id, New_Subp);
11644 -- Create a reference to it
11645 Build_Itype_Reference (Acc_Type, Parent (Derived_Type));
11648 Set_Etype (New_Id, Etype (Id));
11652 elsif Base_Type (Etype (Id)) = Base_Type (Parent_Type)
11654 (Ekind (Etype (Id)) = E_Record_Type_With_Private
11655 and then Present (Full_View (Etype (Id)))
11657 Base_Type (Full_View (Etype (Id))) = Base_Type (Parent_Type))
11659 -- Constraint checks on formals are generated during expansion,
11660 -- based on the signature of the original subprogram. The bounds
11661 -- of the derived type are not relevant, and thus we can use
11662 -- the base type for the formals. However, the return type may be
11663 -- used in a context that requires that the proper static bounds
11664 -- be used (a case statement, for example) and for those cases
11665 -- we must use the derived type (first subtype), not its base.
11667 -- If the derived_type_definition has no constraints, we know that
11668 -- the derived type has the same constraints as the first subtype
11669 -- of the parent, and we can also use it rather than its base,
11670 -- which can lead to more efficient code.
11672 if Etype (Id) = Parent_Type then
11673 if Is_Scalar_Type (Parent_Type)
11675 Subtypes_Statically_Compatible (Parent_Type, Derived_Type)
11677 Set_Etype (New_Id, Derived_Type);
11679 elsif Nkind (Par) = N_Full_Type_Declaration
11681 Nkind (Type_Definition (Par)) = N_Derived_Type_Definition
11684 (Subtype_Indication (Type_Definition (Par)))
11686 Set_Etype (New_Id, Derived_Type);
11689 Set_Etype (New_Id, Base_Type (Derived_Type));
11693 Set_Etype (New_Id, Base_Type (Derived_Type));
11696 -- Ada 2005 (AI-251): Handle derivations of abstract interface
11699 elsif Is_Interface (Etype (Id))
11700 and then not Is_Class_Wide_Type (Etype (Id))
11701 and then Is_Progenitor (Etype (Id), Derived_Type)
11703 Set_Etype (New_Id, Derived_Type);
11706 Set_Etype (New_Id, Etype (Id));
11710 ----------------------
11711 -- Set_Derived_Name --
11712 ----------------------
11714 procedure Set_Derived_Name is
11715 Nm : constant TSS_Name_Type := Get_TSS_Name (Parent_Subp);
11717 if Nm = TSS_Null then
11718 Set_Chars (New_Subp, Chars (Parent_Subp));
11720 Set_Chars (New_Subp, Make_TSS_Name (Base_Type (Derived_Type), Nm));
11722 end Set_Derived_Name;
11724 -- Start of processing for Derive_Subprogram
11728 New_Entity (Nkind (Parent_Subp), Sloc (Derived_Type));
11729 Set_Ekind (New_Subp, Ekind (Parent_Subp));
11731 -- Check whether the inherited subprogram is a private operation that
11732 -- should be inherited but not yet made visible. Such subprograms can
11733 -- become visible at a later point (e.g., the private part of a public
11734 -- child unit) via Declare_Inherited_Private_Subprograms. If the
11735 -- following predicate is true, then this is not such a private
11736 -- operation and the subprogram simply inherits the name of the parent
11737 -- subprogram. Note the special check for the names of controlled
11738 -- operations, which are currently exempted from being inherited with
11739 -- a hidden name because they must be findable for generation of
11740 -- implicit run-time calls.
11742 if not Is_Hidden (Parent_Subp)
11743 or else Is_Internal (Parent_Subp)
11744 or else Is_Private_Overriding
11745 or else Is_Internal_Name (Chars (Parent_Subp))
11746 or else Chars (Parent_Subp) = Name_Initialize
11747 or else Chars (Parent_Subp) = Name_Adjust
11748 or else Chars (Parent_Subp) = Name_Finalize
11752 -- If parent is hidden, this can be a regular derivation if the
11753 -- parent is immediately visible in a non-instantiating context,
11754 -- or if we are in the private part of an instance. This test
11755 -- should still be refined ???
11757 -- The test for In_Instance_Not_Visible avoids inheriting the derived
11758 -- operation as a non-visible operation in cases where the parent
11759 -- subprogram might not be visible now, but was visible within the
11760 -- original generic, so it would be wrong to make the inherited
11761 -- subprogram non-visible now. (Not clear if this test is fully
11762 -- correct; are there any cases where we should declare the inherited
11763 -- operation as not visible to avoid it being overridden, e.g., when
11764 -- the parent type is a generic actual with private primitives ???)
11766 -- (they should be treated the same as other private inherited
11767 -- subprograms, but it's not clear how to do this cleanly). ???
11769 elsif (In_Open_Scopes (Scope (Base_Type (Parent_Type)))
11770 and then Is_Immediately_Visible (Parent_Subp)
11771 and then not In_Instance)
11772 or else In_Instance_Not_Visible
11776 -- Ada 2005 (AI-251): Hidden entity associated with abstract interface
11779 elsif Present (Abstract_Interface_Alias (Parent_Subp)) then
11782 -- The type is inheriting a private operation, so enter
11783 -- it with a special name so it can't be overridden.
11786 Set_Chars (New_Subp, New_External_Name (Chars (Parent_Subp), 'P'));
11789 Set_Parent (New_Subp, Parent (Derived_Type));
11791 if Present (Actual_Subp) then
11792 Replace_Type (Actual_Subp, New_Subp);
11794 Replace_Type (Parent_Subp, New_Subp);
11797 Conditional_Delay (New_Subp, Parent_Subp);
11799 -- If we are creating a renaming for a primitive operation of an
11800 -- actual of a generic derived type, we must examine the signature
11801 -- of the actual primive, not that of the generic formal, which for
11802 -- example may be an interface. However the name and initial value
11803 -- of the inherited operation are those of the formal primitive.
11805 Formal := First_Formal (Parent_Subp);
11807 if Present (Actual_Subp) then
11808 Formal_Of_Actual := First_Formal (Actual_Subp);
11810 Formal_Of_Actual := Empty;
11813 while Present (Formal) loop
11814 New_Formal := New_Copy (Formal);
11816 -- Normally we do not go copying parents, but in the case of
11817 -- formals, we need to link up to the declaration (which is the
11818 -- parameter specification), and it is fine to link up to the
11819 -- original formal's parameter specification in this case.
11821 Set_Parent (New_Formal, Parent (Formal));
11822 Append_Entity (New_Formal, New_Subp);
11824 if Present (Formal_Of_Actual) then
11825 Replace_Type (Formal_Of_Actual, New_Formal);
11826 Next_Formal (Formal_Of_Actual);
11828 Replace_Type (Formal, New_Formal);
11831 Next_Formal (Formal);
11834 -- If this derivation corresponds to a tagged generic actual, then
11835 -- primitive operations rename those of the actual. Otherwise the
11836 -- primitive operations rename those of the parent type, If the parent
11837 -- renames an intrinsic operator, so does the new subprogram. We except
11838 -- concatenation, which is always properly typed, and does not get
11839 -- expanded as other intrinsic operations.
11841 if No (Actual_Subp) then
11842 if Is_Intrinsic_Subprogram (Parent_Subp) then
11843 Set_Is_Intrinsic_Subprogram (New_Subp);
11845 if Present (Alias (Parent_Subp))
11846 and then Chars (Parent_Subp) /= Name_Op_Concat
11848 Set_Alias (New_Subp, Alias (Parent_Subp));
11850 Set_Alias (New_Subp, Parent_Subp);
11854 Set_Alias (New_Subp, Parent_Subp);
11858 Set_Alias (New_Subp, Actual_Subp);
11861 -- Derived subprograms of a tagged type must inherit the convention
11862 -- of the parent subprogram (a requirement of AI-117). Derived
11863 -- subprograms of untagged types simply get convention Ada by default.
11865 if Is_Tagged_Type (Derived_Type) then
11866 Set_Convention (New_Subp, Convention (Parent_Subp));
11869 Set_Is_Imported (New_Subp, Is_Imported (Parent_Subp));
11870 Set_Is_Exported (New_Subp, Is_Exported (Parent_Subp));
11872 if Ekind (Parent_Subp) = E_Procedure then
11873 Set_Is_Valued_Procedure
11874 (New_Subp, Is_Valued_Procedure (Parent_Subp));
11877 -- No_Return must be inherited properly. If this is overridden in the
11878 -- case of a dispatching operation, then a check is made in Sem_Disp
11879 -- that the overriding operation is also No_Return (no such check is
11880 -- required for the case of non-dispatching operation.
11882 Set_No_Return (New_Subp, No_Return (Parent_Subp));
11884 -- A derived function with a controlling result is abstract. If the
11885 -- Derived_Type is a nonabstract formal generic derived type, then
11886 -- inherited operations are not abstract: the required check is done at
11887 -- instantiation time. If the derivation is for a generic actual, the
11888 -- function is not abstract unless the actual is.
11890 if Is_Generic_Type (Derived_Type)
11891 and then not Is_Abstract_Type (Derived_Type)
11895 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
11896 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2).
11898 elsif Ada_Version >= Ada_05
11899 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11900 or else (Is_Tagged_Type (Derived_Type)
11901 and then Etype (New_Subp) = Derived_Type
11902 and then not Is_Null_Extension (Derived_Type))
11903 or else (Is_Tagged_Type (Derived_Type)
11904 and then Ekind (Etype (New_Subp)) =
11905 E_Anonymous_Access_Type
11906 and then Designated_Type (Etype (New_Subp)) =
11908 and then not Is_Null_Extension (Derived_Type)))
11909 and then No (Actual_Subp)
11911 if not Is_Tagged_Type (Derived_Type)
11912 or else Is_Abstract_Type (Derived_Type)
11913 or else Is_Abstract_Subprogram (Alias (New_Subp))
11915 Set_Is_Abstract_Subprogram (New_Subp);
11917 Set_Requires_Overriding (New_Subp);
11920 elsif Ada_Version < Ada_05
11921 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11922 or else (Is_Tagged_Type (Derived_Type)
11923 and then Etype (New_Subp) = Derived_Type
11924 and then No (Actual_Subp)))
11926 Set_Is_Abstract_Subprogram (New_Subp);
11928 -- Finally, if the parent type is abstract we must verify that all
11929 -- inherited operations are either non-abstract or overridden, or that
11930 -- the derived type itself is abstract (this check is performed at the
11931 -- end of a package declaration, in Check_Abstract_Overriding). A
11932 -- private overriding in the parent type will not be visible in the
11933 -- derivation if we are not in an inner package or in a child unit of
11934 -- the parent type, in which case the abstractness of the inherited
11935 -- operation is carried to the new subprogram.
11937 elsif Is_Abstract_Type (Parent_Type)
11938 and then not In_Open_Scopes (Scope (Parent_Type))
11939 and then Is_Private_Overriding
11940 and then Is_Abstract_Subprogram (Visible_Subp)
11942 if No (Actual_Subp) then
11943 Set_Alias (New_Subp, Visible_Subp);
11944 Set_Is_Abstract_Subprogram
11947 -- If this is a derivation for an instance of a formal derived
11948 -- type, abstractness comes from the primitive operation of the
11949 -- actual, not from the operation inherited from the ancestor.
11951 Set_Is_Abstract_Subprogram
11952 (New_Subp, Is_Abstract_Subprogram (Actual_Subp));
11956 New_Overloaded_Entity (New_Subp, Derived_Type);
11958 -- Check for case of a derived subprogram for the instantiation of a
11959 -- formal derived tagged type, if so mark the subprogram as dispatching
11960 -- and inherit the dispatching attributes of the parent subprogram. The
11961 -- derived subprogram is effectively renaming of the actual subprogram,
11962 -- so it needs to have the same attributes as the actual.
11964 if Present (Actual_Subp)
11965 and then Is_Dispatching_Operation (Parent_Subp)
11967 Set_Is_Dispatching_Operation (New_Subp);
11969 if Present (DTC_Entity (Parent_Subp)) then
11970 Set_DTC_Entity (New_Subp, DTC_Entity (Parent_Subp));
11971 Set_DT_Position (New_Subp, DT_Position (Parent_Subp));
11975 -- Indicate that a derived subprogram does not require a body and that
11976 -- it does not require processing of default expressions.
11978 Set_Has_Completion (New_Subp);
11979 Set_Default_Expressions_Processed (New_Subp);
11981 if Ekind (New_Subp) = E_Function then
11982 Set_Mechanism (New_Subp, Mechanism (Parent_Subp));
11984 end Derive_Subprogram;
11986 ------------------------
11987 -- Derive_Subprograms --
11988 ------------------------
11990 procedure Derive_Subprograms
11991 (Parent_Type : Entity_Id;
11992 Derived_Type : Entity_Id;
11993 Generic_Actual : Entity_Id := Empty)
11995 Op_List : constant Elist_Id :=
11996 Collect_Primitive_Operations (Parent_Type);
11997 Ifaces_List : constant Elist_Id := New_Elmt_List;
11998 Predef_Prims : constant Elist_Id := New_Elmt_List;
11999 Act_List : Elist_Id;
12000 Act_Elmt : Elmt_Id;
12002 New_Subp : Entity_Id := Empty;
12003 Parent_Base : Entity_Id;
12007 if Ekind (Parent_Type) = E_Record_Type_With_Private
12008 and then Has_Discriminants (Parent_Type)
12009 and then Present (Full_View (Parent_Type))
12011 Parent_Base := Full_View (Parent_Type);
12013 Parent_Base := Parent_Type;
12016 -- Derive primitives inherited from the parent. Note that if the generic
12017 -- actual is present, this is not really a type derivation, it is a
12018 -- completion within an instance.
12020 if Present (Generic_Actual) then
12021 Act_List := Collect_Primitive_Operations (Generic_Actual);
12022 Act_Elmt := First_Elmt (Act_List);
12024 Act_Elmt := No_Elmt;
12027 -- Literals are derived earlier in the process of building the derived
12028 -- type, and are skipped here.
12030 Elmt := First_Elmt (Op_List);
12031 while Present (Elmt) loop
12032 Subp := Node (Elmt);
12034 if Ekind (Subp) /= E_Enumeration_Literal then
12036 if Ada_Version >= Ada_05
12037 and then Present (Abstract_Interface_Alias (Subp))
12041 -- We derive predefined primitives in a later round to ensure that
12042 -- they are always added to the list of primitives after user
12043 -- defined primitives (because predefined primitives have to be
12044 -- skipped when matching the operations of a parent interface to
12045 -- those of a concrete type). However it is unclear why those
12046 -- primitives would be needed in an instantiation???
12048 elsif Is_Predefined_Dispatching_Operation (Subp) then
12049 Append_Elmt (Subp, Predef_Prims);
12051 elsif No (Generic_Actual) then
12052 Derive_Subprogram (New_Subp, Subp, Derived_Type, Parent_Base);
12054 -- Ada 2005 (AI-251): Add derivation of an abstract interface
12055 -- primitive to the list of entities to which we have to
12056 -- associate an aliased entity.
12058 if Ada_Version >= Ada_05
12059 and then Is_Dispatching_Operation (Subp)
12060 and then Present (Find_Dispatching_Type (Subp))
12061 and then Is_Interface (Find_Dispatching_Type (Subp))
12063 Append_Elmt (New_Subp, Ifaces_List);
12067 -- If the generic parent type is present, the derived type
12068 -- is an instance of a formal derived type, and within the
12069 -- instance its operations are those of the actual. We derive
12070 -- from the formal type but make the inherited operations
12071 -- aliases of the corresponding operations of the actual.
12073 if Is_Interface (Parent_Type)
12074 and then Root_Type (Derived_Type) /= Parent_Type
12076 -- Find the corresponding operation in the generic actual.
12077 -- Given that the actual is not a direct descendant of the
12078 -- parent, as in Ada 95, the primitives are not necessarily
12079 -- in the same order, so we have to traverse the list of
12080 -- primitive operations of the actual to find the one that
12081 -- implements the interface operation.
12083 -- Note that if the parent type is the direct ancestor of
12084 -- the derived type, then even if it is an interface the
12085 -- operations are inherited from the primary dispatch table
12086 -- and are in the proper order.
12088 Act_Elmt := First_Elmt (Act_List);
12089 while Present (Act_Elmt) loop
12091 Abstract_Interface_Alias (Node (Act_Elmt)) = Subp;
12092 Next_Elmt (Act_Elmt);
12096 -- If the formal is not an interface, the actual is a direct
12097 -- descendant and the common primitive operations appear in
12101 (New_Subp, Subp, Derived_Type, Parent_Base, Node (Act_Elmt));
12103 if Present (Act_Elmt) then
12104 Next_Elmt (Act_Elmt);
12112 -- Inherit additional operations from progenitor interfaces. However,
12113 -- if the derived type is a generic actual, there are not new primitive
12114 -- operations for the type, because it has those of the actual, so
12115 -- nothing needs to be done. The renamings generated above are not
12116 -- primitive operations, and their purpose is simply to make the proper
12117 -- operations visible within an instantiation.
12119 if Ada_Version >= Ada_05
12120 and then Is_Tagged_Type (Derived_Type)
12121 and then No (Generic_Actual)
12123 Derive_Interface_Subprograms (Parent_Type, Derived_Type, Ifaces_List);
12126 -- Derive predefined primitives
12128 if not Is_Empty_Elmt_List (Predef_Prims) then
12129 Elmt := First_Elmt (Predef_Prims);
12130 while Present (Elmt) loop
12132 (New_Subp, Node (Elmt), Derived_Type, Parent_Base);
12136 end Derive_Subprograms;
12138 --------------------------------
12139 -- Derived_Standard_Character --
12140 --------------------------------
12142 procedure Derived_Standard_Character
12144 Parent_Type : Entity_Id;
12145 Derived_Type : Entity_Id)
12147 Loc : constant Source_Ptr := Sloc (N);
12148 Def : constant Node_Id := Type_Definition (N);
12149 Indic : constant Node_Id := Subtype_Indication (Def);
12150 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
12151 Implicit_Base : constant Entity_Id :=
12153 (E_Enumeration_Type, N, Derived_Type, 'B');
12159 Discard_Node (Process_Subtype (Indic, N));
12161 Set_Etype (Implicit_Base, Parent_Base);
12162 Set_Size_Info (Implicit_Base, Root_Type (Parent_Type));
12163 Set_RM_Size (Implicit_Base, RM_Size (Root_Type (Parent_Type)));
12165 Set_Is_Character_Type (Implicit_Base, True);
12166 Set_Has_Delayed_Freeze (Implicit_Base);
12168 -- The bounds of the implicit base are the bounds of the parent base.
12169 -- Note that their type is the parent base.
12171 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
12172 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
12174 Set_Scalar_Range (Implicit_Base,
12177 High_Bound => Hi));
12179 Conditional_Delay (Derived_Type, Parent_Type);
12181 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
12182 Set_Etype (Derived_Type, Implicit_Base);
12183 Set_Size_Info (Derived_Type, Parent_Type);
12185 if Unknown_RM_Size (Derived_Type) then
12186 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
12189 Set_Is_Character_Type (Derived_Type, True);
12191 if Nkind (Indic) /= N_Subtype_Indication then
12193 -- If no explicit constraint, the bounds are those
12194 -- of the parent type.
12196 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Type));
12197 Hi := New_Copy_Tree (Type_High_Bound (Parent_Type));
12198 Set_Scalar_Range (Derived_Type, Make_Range (Loc, Lo, Hi));
12201 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
12203 -- Because the implicit base is used in the conversion of the bounds, we
12204 -- have to freeze it now. This is similar to what is done for numeric
12205 -- types, and it equally suspicious, but otherwise a non-static bound
12206 -- will have a reference to an unfrozen type, which is rejected by Gigi
12207 -- (???). This requires specific care for definition of stream
12208 -- attributes. For details, see comments at the end of
12209 -- Build_Derived_Numeric_Type.
12211 Freeze_Before (N, Implicit_Base);
12212 end Derived_Standard_Character;
12214 ------------------------------
12215 -- Derived_Type_Declaration --
12216 ------------------------------
12218 procedure Derived_Type_Declaration
12221 Is_Completion : Boolean)
12223 Parent_Type : Entity_Id;
12225 function Comes_From_Generic (Typ : Entity_Id) return Boolean;
12226 -- Check whether the parent type is a generic formal, or derives
12227 -- directly or indirectly from one.
12229 ------------------------
12230 -- Comes_From_Generic --
12231 ------------------------
12233 function Comes_From_Generic (Typ : Entity_Id) return Boolean is
12235 if Is_Generic_Type (Typ) then
12238 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
12241 elsif Is_Private_Type (Typ)
12242 and then Present (Full_View (Typ))
12243 and then Is_Generic_Type (Root_Type (Full_View (Typ)))
12247 elsif Is_Generic_Actual_Type (Typ) then
12253 end Comes_From_Generic;
12257 Def : constant Node_Id := Type_Definition (N);
12258 Iface_Def : Node_Id;
12259 Indic : constant Node_Id := Subtype_Indication (Def);
12260 Extension : constant Node_Id := Record_Extension_Part (Def);
12261 Parent_Node : Node_Id;
12262 Parent_Scope : Entity_Id;
12265 -- Start of processing for Derived_Type_Declaration
12268 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
12270 -- Ada 2005 (AI-251): In case of interface derivation check that the
12271 -- parent is also an interface.
12273 if Interface_Present (Def) then
12274 if not Is_Interface (Parent_Type) then
12276 ("(Ada 2005) & must be an interface", Indic, Parent_Type);
12279 Parent_Node := Parent (Base_Type (Parent_Type));
12280 Iface_Def := Type_Definition (Parent_Node);
12282 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
12283 -- other limited interfaces.
12285 if Limited_Present (Def) then
12286 if Limited_Present (Iface_Def) then
12289 elsif Protected_Present (Iface_Def) then
12291 ("(Ada 2005) limited interface cannot "
12292 & "inherit from protected interface", Indic);
12294 elsif Synchronized_Present (Iface_Def) then
12296 ("(Ada 2005) limited interface cannot "
12297 & "inherit from synchronized interface", Indic);
12299 elsif Task_Present (Iface_Def) then
12301 ("(Ada 2005) limited interface cannot "
12302 & "inherit from task interface", Indic);
12306 ("(Ada 2005) limited interface cannot "
12307 & "inherit from non-limited interface", Indic);
12310 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
12311 -- from non-limited or limited interfaces.
12313 elsif not Protected_Present (Def)
12314 and then not Synchronized_Present (Def)
12315 and then not Task_Present (Def)
12317 if Limited_Present (Iface_Def) then
12320 elsif Protected_Present (Iface_Def) then
12322 ("(Ada 2005) non-limited interface cannot "
12323 & "inherit from protected interface", Indic);
12325 elsif Synchronized_Present (Iface_Def) then
12327 ("(Ada 2005) non-limited interface cannot "
12328 & "inherit from synchronized interface", Indic);
12330 elsif Task_Present (Iface_Def) then
12332 ("(Ada 2005) non-limited interface cannot "
12333 & "inherit from task interface", Indic);
12342 if Is_Tagged_Type (Parent_Type)
12343 and then Is_Concurrent_Type (Parent_Type)
12344 and then not Is_Interface (Parent_Type)
12347 ("parent type of a record extension cannot be "
12348 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
12349 Set_Etype (T, Any_Type);
12353 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
12356 if Is_Tagged_Type (Parent_Type)
12357 and then Is_Non_Empty_List (Interface_List (Def))
12364 Intf := First (Interface_List (Def));
12365 while Present (Intf) loop
12366 T := Find_Type_Of_Subtype_Indic (Intf);
12368 if not Is_Interface (T) then
12369 Error_Msg_NE ("(Ada 2005) & must be an interface", Intf, T);
12371 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
12372 -- a limited type from having a nonlimited progenitor.
12374 elsif (Limited_Present (Def)
12375 or else (not Is_Interface (Parent_Type)
12376 and then Is_Limited_Type (Parent_Type)))
12377 and then not Is_Limited_Interface (T)
12380 ("progenitor interface& of limited type must be limited",
12389 if Parent_Type = Any_Type
12390 or else Etype (Parent_Type) = Any_Type
12391 or else (Is_Class_Wide_Type (Parent_Type)
12392 and then Etype (Parent_Type) = T)
12394 -- If Parent_Type is undefined or illegal, make new type into a
12395 -- subtype of Any_Type, and set a few attributes to prevent cascaded
12396 -- errors. If this is a self-definition, emit error now.
12399 or else T = Etype (Parent_Type)
12401 Error_Msg_N ("type cannot be used in its own definition", Indic);
12404 Set_Ekind (T, Ekind (Parent_Type));
12405 Set_Etype (T, Any_Type);
12406 Set_Scalar_Range (T, Scalar_Range (Any_Type));
12408 if Is_Tagged_Type (T) then
12409 Set_Primitive_Operations (T, New_Elmt_List);
12415 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
12416 -- an interface is special because the list of interfaces in the full
12417 -- view can be given in any order. For example:
12419 -- type A is interface;
12420 -- type B is interface and A;
12421 -- type D is new B with private;
12423 -- type D is new A and B with null record; -- 1 --
12425 -- In this case we perform the following transformation of -1-:
12427 -- type D is new B and A with null record;
12429 -- If the parent of the full-view covers the parent of the partial-view
12430 -- we have two possible cases:
12432 -- 1) They have the same parent
12433 -- 2) The parent of the full-view implements some further interfaces
12435 -- In both cases we do not need to perform the transformation. In the
12436 -- first case the source program is correct and the transformation is
12437 -- not needed; in the second case the source program does not fulfill
12438 -- the no-hidden interfaces rule (AI-396) and the error will be reported
12441 -- This transformation not only simplifies the rest of the analysis of
12442 -- this type declaration but also simplifies the correct generation of
12443 -- the object layout to the expander.
12445 if In_Private_Part (Current_Scope)
12446 and then Is_Interface (Parent_Type)
12450 Partial_View : Entity_Id;
12451 Partial_View_Parent : Entity_Id;
12452 New_Iface : Node_Id;
12455 -- Look for the associated private type declaration
12457 Partial_View := First_Entity (Current_Scope);
12459 exit when No (Partial_View)
12460 or else (Has_Private_Declaration (Partial_View)
12461 and then Full_View (Partial_View) = T);
12463 Next_Entity (Partial_View);
12466 -- If the partial view was not found then the source code has
12467 -- errors and the transformation is not needed.
12469 if Present (Partial_View) then
12470 Partial_View_Parent := Etype (Partial_View);
12472 -- If the parent of the full-view covers the parent of the
12473 -- partial-view we have nothing else to do.
12475 if Interface_Present_In_Ancestor
12476 (Parent_Type, Partial_View_Parent)
12480 -- Traverse the list of interfaces of the full-view to look
12481 -- for the parent of the partial-view and perform the tree
12485 Iface := First (Interface_List (Def));
12486 while Present (Iface) loop
12487 if Etype (Iface) = Etype (Partial_View) then
12488 Rewrite (Subtype_Indication (Def),
12489 New_Copy (Subtype_Indication
12490 (Parent (Partial_View))));
12492 New_Iface := Make_Identifier (Sloc (N),
12493 Chars (Parent_Type));
12494 Append (New_Iface, Interface_List (Def));
12496 -- Analyze the transformed code
12498 Derived_Type_Declaration (T, N, Is_Completion);
12509 -- Only composite types other than array types are allowed to have
12512 if Present (Discriminant_Specifications (N))
12513 and then (Is_Elementary_Type (Parent_Type)
12514 or else Is_Array_Type (Parent_Type))
12515 and then not Error_Posted (N)
12518 ("elementary or array type cannot have discriminants",
12519 Defining_Identifier (First (Discriminant_Specifications (N))));
12520 Set_Has_Discriminants (T, False);
12523 -- In Ada 83, a derived type defined in a package specification cannot
12524 -- be used for further derivation until the end of its visible part.
12525 -- Note that derivation in the private part of the package is allowed.
12527 if Ada_Version = Ada_83
12528 and then Is_Derived_Type (Parent_Type)
12529 and then In_Visible_Part (Scope (Parent_Type))
12531 if Ada_Version = Ada_83 and then Comes_From_Source (Indic) then
12533 ("(Ada 83): premature use of type for derivation", Indic);
12537 -- Check for early use of incomplete or private type
12539 if Ekind (Parent_Type) = E_Void
12540 or else Ekind (Parent_Type) = E_Incomplete_Type
12542 Error_Msg_N ("premature derivation of incomplete type", Indic);
12545 elsif (Is_Incomplete_Or_Private_Type (Parent_Type)
12546 and then not Comes_From_Generic (Parent_Type))
12547 or else Has_Private_Component (Parent_Type)
12549 -- The ancestor type of a formal type can be incomplete, in which
12550 -- case only the operations of the partial view are available in
12551 -- the generic. Subsequent checks may be required when the full
12552 -- view is analyzed, to verify that derivation from a tagged type
12553 -- has an extension.
12555 if Nkind (Original_Node (N)) = N_Formal_Type_Declaration then
12558 elsif No (Underlying_Type (Parent_Type))
12559 or else Has_Private_Component (Parent_Type)
12562 ("premature derivation of derived or private type", Indic);
12564 -- Flag the type itself as being in error, this prevents some
12565 -- nasty problems with subsequent uses of the malformed type.
12567 Set_Error_Posted (T);
12569 -- Check that within the immediate scope of an untagged partial
12570 -- view it's illegal to derive from the partial view if the
12571 -- full view is tagged. (7.3(7))
12573 -- We verify that the Parent_Type is a partial view by checking
12574 -- that it is not a Full_Type_Declaration (i.e. a private type or
12575 -- private extension declaration), to distinguish a partial view
12576 -- from a derivation from a private type which also appears as
12579 elsif Present (Full_View (Parent_Type))
12580 and then Nkind (Parent (Parent_Type)) /= N_Full_Type_Declaration
12581 and then not Is_Tagged_Type (Parent_Type)
12582 and then Is_Tagged_Type (Full_View (Parent_Type))
12584 Parent_Scope := Scope (T);
12585 while Present (Parent_Scope)
12586 and then Parent_Scope /= Standard_Standard
12588 if Parent_Scope = Scope (Parent_Type) then
12590 ("premature derivation from type with tagged full view",
12594 Parent_Scope := Scope (Parent_Scope);
12599 -- Check that form of derivation is appropriate
12601 Taggd := Is_Tagged_Type (Parent_Type);
12603 -- Perhaps the parent type should be changed to the class-wide type's
12604 -- specific type in this case to prevent cascading errors ???
12606 if Present (Extension) and then Is_Class_Wide_Type (Parent_Type) then
12607 Error_Msg_N ("parent type must not be a class-wide type", Indic);
12611 if Present (Extension) and then not Taggd then
12613 ("type derived from untagged type cannot have extension", Indic);
12615 elsif No (Extension) and then Taggd then
12617 -- If this declaration is within a private part (or body) of a
12618 -- generic instantiation then the derivation is allowed (the parent
12619 -- type can only appear tagged in this case if it's a generic actual
12620 -- type, since it would otherwise have been rejected in the analysis
12621 -- of the generic template).
12623 if not Is_Generic_Actual_Type (Parent_Type)
12624 or else In_Visible_Part (Scope (Parent_Type))
12627 ("type derived from tagged type must have extension", Indic);
12631 -- AI-443: Synchronized formal derived types require a private
12632 -- extension. There is no point in checking the ancestor type or
12633 -- the progenitors since the construct is wrong to begin with.
12635 if Ada_Version >= Ada_05
12636 and then Is_Generic_Type (T)
12637 and then Present (Original_Node (N))
12640 Decl : constant Node_Id := Original_Node (N);
12643 if Nkind (Decl) = N_Formal_Type_Declaration
12644 and then Nkind (Formal_Type_Definition (Decl)) =
12645 N_Formal_Derived_Type_Definition
12646 and then Synchronized_Present (Formal_Type_Definition (Decl))
12647 and then No (Extension)
12649 -- Avoid emitting a duplicate error message
12651 and then not Error_Posted (Indic)
12654 ("synchronized derived type must have extension", N);
12659 Build_Derived_Type (N, Parent_Type, T, Is_Completion);
12661 -- AI-419: The parent type of an explicitly limited derived type must
12662 -- be a limited type or a limited interface.
12664 if Limited_Present (Def) then
12665 Set_Is_Limited_Record (T);
12667 if Is_Interface (T) then
12668 Set_Is_Limited_Interface (T);
12671 if not Is_Limited_Type (Parent_Type)
12673 (not Is_Interface (Parent_Type)
12674 or else not Is_Limited_Interface (Parent_Type))
12676 Error_Msg_NE ("parent type& of limited type must be limited",
12680 end Derived_Type_Declaration;
12682 ----------------------------------
12683 -- Enumeration_Type_Declaration --
12684 ----------------------------------
12686 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id) is
12693 -- Create identifier node representing lower bound
12695 B_Node := New_Node (N_Identifier, Sloc (Def));
12696 L := First (Literals (Def));
12697 Set_Chars (B_Node, Chars (L));
12698 Set_Entity (B_Node, L);
12699 Set_Etype (B_Node, T);
12700 Set_Is_Static_Expression (B_Node, True);
12702 R_Node := New_Node (N_Range, Sloc (Def));
12703 Set_Low_Bound (R_Node, B_Node);
12705 Set_Ekind (T, E_Enumeration_Type);
12706 Set_First_Literal (T, L);
12708 Set_Is_Constrained (T);
12712 -- Loop through literals of enumeration type setting pos and rep values
12713 -- except that if the Ekind is already set, then it means that the
12714 -- literal was already constructed (case of a derived type declaration
12715 -- and we should not disturb the Pos and Rep values.
12717 while Present (L) loop
12718 if Ekind (L) /= E_Enumeration_Literal then
12719 Set_Ekind (L, E_Enumeration_Literal);
12720 Set_Enumeration_Pos (L, Ev);
12721 Set_Enumeration_Rep (L, Ev);
12722 Set_Is_Known_Valid (L, True);
12726 New_Overloaded_Entity (L);
12727 Generate_Definition (L);
12728 Set_Convention (L, Convention_Intrinsic);
12730 if Nkind (L) = N_Defining_Character_Literal then
12731 Set_Is_Character_Type (T, True);
12738 -- Now create a node representing upper bound
12740 B_Node := New_Node (N_Identifier, Sloc (Def));
12741 Set_Chars (B_Node, Chars (Last (Literals (Def))));
12742 Set_Entity (B_Node, Last (Literals (Def)));
12743 Set_Etype (B_Node, T);
12744 Set_Is_Static_Expression (B_Node, True);
12746 Set_High_Bound (R_Node, B_Node);
12748 -- Initialize various fields of the type. Some of this information
12749 -- may be overwritten later through rep.clauses.
12751 Set_Scalar_Range (T, R_Node);
12752 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
12753 Set_Enum_Esize (T);
12754 Set_Enum_Pos_To_Rep (T, Empty);
12756 -- Set Discard_Names if configuration pragma set, or if there is
12757 -- a parameterless pragma in the current declarative region
12759 if Global_Discard_Names
12760 or else Discard_Names (Scope (T))
12762 Set_Discard_Names (T);
12765 -- Process end label if there is one
12767 if Present (Def) then
12768 Process_End_Label (Def, 'e', T);
12770 end Enumeration_Type_Declaration;
12772 ---------------------------------
12773 -- Expand_To_Stored_Constraint --
12774 ---------------------------------
12776 function Expand_To_Stored_Constraint
12778 Constraint : Elist_Id) return Elist_Id
12780 Explicitly_Discriminated_Type : Entity_Id;
12781 Expansion : Elist_Id;
12782 Discriminant : Entity_Id;
12784 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id;
12785 -- Find the nearest type that actually specifies discriminants
12787 ---------------------------------
12788 -- Type_With_Explicit_Discrims --
12789 ---------------------------------
12791 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id is
12792 Typ : constant E := Base_Type (Id);
12795 if Ekind (Typ) in Incomplete_Or_Private_Kind then
12796 if Present (Full_View (Typ)) then
12797 return Type_With_Explicit_Discrims (Full_View (Typ));
12801 if Has_Discriminants (Typ) then
12806 if Etype (Typ) = Typ then
12808 elsif Has_Discriminants (Typ) then
12811 return Type_With_Explicit_Discrims (Etype (Typ));
12814 end Type_With_Explicit_Discrims;
12816 -- Start of processing for Expand_To_Stored_Constraint
12820 or else Is_Empty_Elmt_List (Constraint)
12825 Explicitly_Discriminated_Type := Type_With_Explicit_Discrims (Typ);
12827 if No (Explicitly_Discriminated_Type) then
12831 Expansion := New_Elmt_List;
12834 First_Stored_Discriminant (Explicitly_Discriminated_Type);
12835 while Present (Discriminant) loop
12837 Get_Discriminant_Value (
12838 Discriminant, Explicitly_Discriminated_Type, Constraint),
12840 Next_Stored_Discriminant (Discriminant);
12844 end Expand_To_Stored_Constraint;
12846 ---------------------------
12847 -- Find_Hidden_Interface --
12848 ---------------------------
12850 function Find_Hidden_Interface
12852 Dest : Elist_Id) return Entity_Id
12855 Iface_Elmt : Elmt_Id;
12858 if Present (Src) and then Present (Dest) then
12859 Iface_Elmt := First_Elmt (Src);
12860 while Present (Iface_Elmt) loop
12861 Iface := Node (Iface_Elmt);
12863 if Is_Interface (Iface)
12864 and then not Contain_Interface (Iface, Dest)
12869 Next_Elmt (Iface_Elmt);
12874 end Find_Hidden_Interface;
12876 --------------------
12877 -- Find_Type_Name --
12878 --------------------
12880 function Find_Type_Name (N : Node_Id) return Entity_Id is
12881 Id : constant Entity_Id := Defining_Identifier (N);
12883 New_Id : Entity_Id;
12884 Prev_Par : Node_Id;
12887 -- Find incomplete declaration, if one was given
12889 Prev := Current_Entity_In_Scope (Id);
12891 if Present (Prev) then
12893 -- Previous declaration exists. Error if not incomplete/private case
12894 -- except if previous declaration is implicit, etc. Enter_Name will
12895 -- emit error if appropriate.
12897 Prev_Par := Parent (Prev);
12899 if not Is_Incomplete_Or_Private_Type (Prev) then
12903 elsif not Nkind_In (N, N_Full_Type_Declaration,
12904 N_Task_Type_Declaration,
12905 N_Protected_Type_Declaration)
12907 -- Completion must be a full type declarations (RM 7.3(4))
12909 Error_Msg_Sloc := Sloc (Prev);
12910 Error_Msg_NE ("invalid completion of }", Id, Prev);
12912 -- Set scope of Id to avoid cascaded errors. Entity is never
12913 -- examined again, except when saving globals in generics.
12915 Set_Scope (Id, Current_Scope);
12918 -- Case of full declaration of incomplete type
12920 elsif Ekind (Prev) = E_Incomplete_Type then
12922 -- Indicate that the incomplete declaration has a matching full
12923 -- declaration. The defining occurrence of the incomplete
12924 -- declaration remains the visible one, and the procedure
12925 -- Get_Full_View dereferences it whenever the type is used.
12927 if Present (Full_View (Prev)) then
12928 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
12931 Set_Full_View (Prev, Id);
12932 Append_Entity (Id, Current_Scope);
12933 Set_Is_Public (Id, Is_Public (Prev));
12934 Set_Is_Internal (Id);
12937 -- Case of full declaration of private type
12940 if Nkind (Parent (Prev)) /= N_Private_Extension_Declaration then
12941 if Etype (Prev) /= Prev then
12943 -- Prev is a private subtype or a derived type, and needs
12946 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
12949 elsif Ekind (Prev) = E_Private_Type
12950 and then Nkind_In (N, N_Task_Type_Declaration,
12951 N_Protected_Type_Declaration)
12954 ("completion of nonlimited type cannot be limited", N);
12956 elsif Ekind (Prev) = E_Record_Type_With_Private
12957 and then Nkind_In (N, N_Task_Type_Declaration,
12958 N_Protected_Type_Declaration)
12960 if not Is_Limited_Record (Prev) then
12962 ("completion of nonlimited type cannot be limited", N);
12964 elsif No (Interface_List (N)) then
12966 ("completion of tagged private type must be tagged",
12971 -- Ada 2005 (AI-251): Private extension declaration of a task
12972 -- type or a protected type. This case arises when covering
12973 -- interface types.
12975 elsif Nkind_In (N, N_Task_Type_Declaration,
12976 N_Protected_Type_Declaration)
12980 elsif Nkind (N) /= N_Full_Type_Declaration
12981 or else Nkind (Type_Definition (N)) /= N_Derived_Type_Definition
12984 ("full view of private extension must be an extension", N);
12986 elsif not (Abstract_Present (Parent (Prev)))
12987 and then Abstract_Present (Type_Definition (N))
12990 ("full view of non-abstract extension cannot be abstract", N);
12993 if not In_Private_Part (Current_Scope) then
12995 ("declaration of full view must appear in private part", N);
12998 Copy_And_Swap (Prev, Id);
12999 Set_Has_Private_Declaration (Prev);
13000 Set_Has_Private_Declaration (Id);
13002 -- If no error, propagate freeze_node from private to full view.
13003 -- It may have been generated for an early operational item.
13005 if Present (Freeze_Node (Id))
13006 and then Serious_Errors_Detected = 0
13007 and then No (Full_View (Id))
13009 Set_Freeze_Node (Prev, Freeze_Node (Id));
13010 Set_Freeze_Node (Id, Empty);
13011 Set_First_Rep_Item (Prev, First_Rep_Item (Id));
13014 Set_Full_View (Id, Prev);
13018 -- Verify that full declaration conforms to incomplete one
13020 if Is_Incomplete_Or_Private_Type (Prev)
13021 and then Present (Discriminant_Specifications (Prev_Par))
13023 if Present (Discriminant_Specifications (N)) then
13024 if Ekind (Prev) = E_Incomplete_Type then
13025 Check_Discriminant_Conformance (N, Prev, Prev);
13027 Check_Discriminant_Conformance (N, Prev, Id);
13032 ("missing discriminants in full type declaration", N);
13034 -- To avoid cascaded errors on subsequent use, share the
13035 -- discriminants of the partial view.
13037 Set_Discriminant_Specifications (N,
13038 Discriminant_Specifications (Prev_Par));
13042 -- A prior untagged private type can have an associated class-wide
13043 -- type due to use of the class attribute, and in this case also the
13044 -- full type is required to be tagged.
13047 and then (Is_Tagged_Type (Prev)
13048 or else Present (Class_Wide_Type (Prev)))
13049 and then not Nkind_In (N, N_Task_Type_Declaration,
13050 N_Protected_Type_Declaration)
13052 -- The full declaration is either a tagged record or an
13053 -- extension otherwise this is an error
13055 if Nkind (Type_Definition (N)) = N_Record_Definition then
13056 if not Tagged_Present (Type_Definition (N)) then
13058 ("full declaration of } must be tagged", Prev, Id);
13059 Set_Is_Tagged_Type (Id);
13060 Set_Primitive_Operations (Id, New_Elmt_List);
13063 elsif Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
13064 if No (Record_Extension_Part (Type_Definition (N))) then
13066 "full declaration of } must be a record extension",
13068 Set_Is_Tagged_Type (Id);
13069 Set_Primitive_Operations (Id, New_Elmt_List);
13074 ("full declaration of } must be a tagged type", Prev, Id);
13082 -- New type declaration
13087 end Find_Type_Name;
13089 -------------------------
13090 -- Find_Type_Of_Object --
13091 -------------------------
13093 function Find_Type_Of_Object
13094 (Obj_Def : Node_Id;
13095 Related_Nod : Node_Id) return Entity_Id
13097 Def_Kind : constant Node_Kind := Nkind (Obj_Def);
13098 P : Node_Id := Parent (Obj_Def);
13103 -- If the parent is a component_definition node we climb to the
13104 -- component_declaration node
13106 if Nkind (P) = N_Component_Definition then
13110 -- Case of an anonymous array subtype
13112 if Nkind_In (Def_Kind, N_Constrained_Array_Definition,
13113 N_Unconstrained_Array_Definition)
13116 Array_Type_Declaration (T, Obj_Def);
13118 -- Create an explicit subtype whenever possible
13120 elsif Nkind (P) /= N_Component_Declaration
13121 and then Def_Kind = N_Subtype_Indication
13123 -- Base name of subtype on object name, which will be unique in
13124 -- the current scope.
13126 -- If this is a duplicate declaration, return base type, to avoid
13127 -- generating duplicate anonymous types.
13129 if Error_Posted (P) then
13130 Analyze (Subtype_Mark (Obj_Def));
13131 return Entity (Subtype_Mark (Obj_Def));
13136 (Chars (Defining_Identifier (Related_Nod)), 'S', 0, 'T');
13138 T := Make_Defining_Identifier (Sloc (P), Nam);
13140 Insert_Action (Obj_Def,
13141 Make_Subtype_Declaration (Sloc (P),
13142 Defining_Identifier => T,
13143 Subtype_Indication => Relocate_Node (Obj_Def)));
13145 -- This subtype may need freezing, and this will not be done
13146 -- automatically if the object declaration is not in declarative
13147 -- part. Since this is an object declaration, the type cannot always
13148 -- be frozen here. Deferred constants do not freeze their type
13149 -- (which often enough will be private).
13151 if Nkind (P) = N_Object_Declaration
13152 and then Constant_Present (P)
13153 and then No (Expression (P))
13157 Insert_Actions (Obj_Def, Freeze_Entity (T, Sloc (P)));
13160 -- Ada 2005 AI-406: the object definition in an object declaration
13161 -- can be an access definition.
13163 elsif Def_Kind = N_Access_Definition then
13164 T := Access_Definition (Related_Nod, Obj_Def);
13165 Set_Is_Local_Anonymous_Access (T);
13167 -- Otherwise, the object definition is just a subtype_mark
13170 T := Process_Subtype (Obj_Def, Related_Nod);
13174 end Find_Type_Of_Object;
13176 --------------------------------
13177 -- Find_Type_Of_Subtype_Indic --
13178 --------------------------------
13180 function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id is
13184 -- Case of subtype mark with a constraint
13186 if Nkind (S) = N_Subtype_Indication then
13187 Find_Type (Subtype_Mark (S));
13188 Typ := Entity (Subtype_Mark (S));
13191 Is_Valid_Constraint_Kind (Ekind (Typ), Nkind (Constraint (S)))
13194 ("incorrect constraint for this kind of type", Constraint (S));
13195 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
13198 -- Otherwise we have a subtype mark without a constraint
13200 elsif Error_Posted (S) then
13201 Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S)));
13209 -- Check No_Wide_Characters restriction
13211 if Typ = Standard_Wide_Character
13212 or else Typ = Standard_Wide_Wide_Character
13213 or else Typ = Standard_Wide_String
13214 or else Typ = Standard_Wide_Wide_String
13216 Check_Restriction (No_Wide_Characters, S);
13220 end Find_Type_Of_Subtype_Indic;
13222 -------------------------------------
13223 -- Floating_Point_Type_Declaration --
13224 -------------------------------------
13226 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is
13227 Digs : constant Node_Id := Digits_Expression (Def);
13229 Base_Typ : Entity_Id;
13230 Implicit_Base : Entity_Id;
13233 function Can_Derive_From (E : Entity_Id) return Boolean;
13234 -- Find if given digits value allows derivation from specified type
13236 ---------------------
13237 -- Can_Derive_From --
13238 ---------------------
13240 function Can_Derive_From (E : Entity_Id) return Boolean is
13241 Spec : constant Entity_Id := Real_Range_Specification (Def);
13244 if Digs_Val > Digits_Value (E) then
13248 if Present (Spec) then
13249 if Expr_Value_R (Type_Low_Bound (E)) >
13250 Expr_Value_R (Low_Bound (Spec))
13255 if Expr_Value_R (Type_High_Bound (E)) <
13256 Expr_Value_R (High_Bound (Spec))
13263 end Can_Derive_From;
13265 -- Start of processing for Floating_Point_Type_Declaration
13268 Check_Restriction (No_Floating_Point, Def);
13270 -- Create an implicit base type
13273 Create_Itype (E_Floating_Point_Type, Parent (Def), T, 'B');
13275 -- Analyze and verify digits value
13277 Analyze_And_Resolve (Digs, Any_Integer);
13278 Check_Digits_Expression (Digs);
13279 Digs_Val := Expr_Value (Digs);
13281 -- Process possible range spec and find correct type to derive from
13283 Process_Real_Range_Specification (Def);
13285 if Can_Derive_From (Standard_Short_Float) then
13286 Base_Typ := Standard_Short_Float;
13287 elsif Can_Derive_From (Standard_Float) then
13288 Base_Typ := Standard_Float;
13289 elsif Can_Derive_From (Standard_Long_Float) then
13290 Base_Typ := Standard_Long_Float;
13291 elsif Can_Derive_From (Standard_Long_Long_Float) then
13292 Base_Typ := Standard_Long_Long_Float;
13294 -- If we can't derive from any existing type, use long_long_float
13295 -- and give appropriate message explaining the problem.
13298 Base_Typ := Standard_Long_Long_Float;
13300 if Digs_Val >= Digits_Value (Standard_Long_Long_Float) then
13301 Error_Msg_Uint_1 := Digits_Value (Standard_Long_Long_Float);
13302 Error_Msg_N ("digits value out of range, maximum is ^", Digs);
13306 ("range too large for any predefined type",
13307 Real_Range_Specification (Def));
13311 -- If there are bounds given in the declaration use them as the bounds
13312 -- of the type, otherwise use the bounds of the predefined base type
13313 -- that was chosen based on the Digits value.
13315 if Present (Real_Range_Specification (Def)) then
13316 Set_Scalar_Range (T, Real_Range_Specification (Def));
13317 Set_Is_Constrained (T);
13319 -- The bounds of this range must be converted to machine numbers
13320 -- in accordance with RM 4.9(38).
13322 Bound := Type_Low_Bound (T);
13324 if Nkind (Bound) = N_Real_Literal then
13326 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13327 Set_Is_Machine_Number (Bound);
13330 Bound := Type_High_Bound (T);
13332 if Nkind (Bound) = N_Real_Literal then
13334 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13335 Set_Is_Machine_Number (Bound);
13339 Set_Scalar_Range (T, Scalar_Range (Base_Typ));
13342 -- Complete definition of implicit base and declared first subtype
13344 Set_Etype (Implicit_Base, Base_Typ);
13346 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
13347 Set_Size_Info (Implicit_Base, (Base_Typ));
13348 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
13349 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
13350 Set_Digits_Value (Implicit_Base, Digits_Value (Base_Typ));
13351 Set_Vax_Float (Implicit_Base, Vax_Float (Base_Typ));
13353 Set_Ekind (T, E_Floating_Point_Subtype);
13354 Set_Etype (T, Implicit_Base);
13356 Set_Size_Info (T, (Implicit_Base));
13357 Set_RM_Size (T, RM_Size (Implicit_Base));
13358 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
13359 Set_Digits_Value (T, Digs_Val);
13360 end Floating_Point_Type_Declaration;
13362 ----------------------------
13363 -- Get_Discriminant_Value --
13364 ----------------------------
13366 -- This is the situation:
13368 -- There is a non-derived type
13370 -- type T0 (Dx, Dy, Dz...)
13372 -- There are zero or more levels of derivation, with each derivation
13373 -- either purely inheriting the discriminants, or defining its own.
13375 -- type Ti is new Ti-1
13377 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
13379 -- subtype Ti is ...
13381 -- The subtype issue is avoided by the use of Original_Record_Component,
13382 -- and the fact that derived subtypes also derive the constraints.
13384 -- This chain leads back from
13386 -- Typ_For_Constraint
13388 -- Typ_For_Constraint has discriminants, and the value for each
13389 -- discriminant is given by its corresponding Elmt of Constraints.
13391 -- Discriminant is some discriminant in this hierarchy
13393 -- We need to return its value
13395 -- We do this by recursively searching each level, and looking for
13396 -- Discriminant. Once we get to the bottom, we start backing up
13397 -- returning the value for it which may in turn be a discriminant
13398 -- further up, so on the backup we continue the substitution.
13400 function Get_Discriminant_Value
13401 (Discriminant : Entity_Id;
13402 Typ_For_Constraint : Entity_Id;
13403 Constraint : Elist_Id) return Node_Id
13405 function Search_Derivation_Levels
13407 Discrim_Values : Elist_Id;
13408 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id;
13409 -- This is the routine that performs the recursive search of levels
13410 -- as described above.
13412 ------------------------------
13413 -- Search_Derivation_Levels --
13414 ------------------------------
13416 function Search_Derivation_Levels
13418 Discrim_Values : Elist_Id;
13419 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id
13423 Result : Node_Or_Entity_Id;
13424 Result_Entity : Node_Id;
13427 -- If inappropriate type, return Error, this happens only in
13428 -- cascaded error situations, and we want to avoid a blow up.
13430 if not Is_Composite_Type (Ti) or else Is_Array_Type (Ti) then
13434 -- Look deeper if possible. Use Stored_Constraints only for
13435 -- untagged types. For tagged types use the given constraint.
13436 -- This asymmetry needs explanation???
13438 if not Stored_Discrim_Values
13439 and then Present (Stored_Constraint (Ti))
13440 and then not Is_Tagged_Type (Ti)
13443 Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True);
13446 Td : constant Entity_Id := Etype (Ti);
13450 Result := Discriminant;
13453 if Present (Stored_Constraint (Ti)) then
13455 Search_Derivation_Levels
13456 (Td, Stored_Constraint (Ti), True);
13459 Search_Derivation_Levels
13460 (Td, Discrim_Values, Stored_Discrim_Values);
13466 -- Extra underlying places to search, if not found above. For
13467 -- concurrent types, the relevant discriminant appears in the
13468 -- corresponding record. For a type derived from a private type
13469 -- without discriminant, the full view inherits the discriminants
13470 -- of the full view of the parent.
13472 if Result = Discriminant then
13473 if Is_Concurrent_Type (Ti)
13474 and then Present (Corresponding_Record_Type (Ti))
13477 Search_Derivation_Levels (
13478 Corresponding_Record_Type (Ti),
13480 Stored_Discrim_Values);
13482 elsif Is_Private_Type (Ti)
13483 and then not Has_Discriminants (Ti)
13484 and then Present (Full_View (Ti))
13485 and then Etype (Full_View (Ti)) /= Ti
13488 Search_Derivation_Levels (
13491 Stored_Discrim_Values);
13495 -- If Result is not a (reference to a) discriminant, return it,
13496 -- otherwise set Result_Entity to the discriminant.
13498 if Nkind (Result) = N_Defining_Identifier then
13499 pragma Assert (Result = Discriminant);
13500 Result_Entity := Result;
13503 if not Denotes_Discriminant (Result) then
13507 Result_Entity := Entity (Result);
13510 -- See if this level of derivation actually has discriminants
13511 -- because tagged derivations can add them, hence the lower
13512 -- levels need not have any.
13514 if not Has_Discriminants (Ti) then
13518 -- Scan Ti's discriminants for Result_Entity,
13519 -- and return its corresponding value, if any.
13521 Result_Entity := Original_Record_Component (Result_Entity);
13523 Assoc := First_Elmt (Discrim_Values);
13525 if Stored_Discrim_Values then
13526 Disc := First_Stored_Discriminant (Ti);
13528 Disc := First_Discriminant (Ti);
13531 while Present (Disc) loop
13532 pragma Assert (Present (Assoc));
13534 if Original_Record_Component (Disc) = Result_Entity then
13535 return Node (Assoc);
13540 if Stored_Discrim_Values then
13541 Next_Stored_Discriminant (Disc);
13543 Next_Discriminant (Disc);
13547 -- Could not find it
13550 end Search_Derivation_Levels;
13554 Result : Node_Or_Entity_Id;
13556 -- Start of processing for Get_Discriminant_Value
13559 -- ??? This routine is a gigantic mess and will be deleted. For the
13560 -- time being just test for the trivial case before calling recurse.
13562 if Base_Type (Scope (Discriminant)) = Base_Type (Typ_For_Constraint) then
13568 D := First_Discriminant (Typ_For_Constraint);
13569 E := First_Elmt (Constraint);
13570 while Present (D) loop
13571 if Chars (D) = Chars (Discriminant) then
13575 Next_Discriminant (D);
13581 Result := Search_Derivation_Levels
13582 (Typ_For_Constraint, Constraint, False);
13584 -- ??? hack to disappear when this routine is gone
13586 if Nkind (Result) = N_Defining_Identifier then
13592 D := First_Discriminant (Typ_For_Constraint);
13593 E := First_Elmt (Constraint);
13594 while Present (D) loop
13595 if Corresponding_Discriminant (D) = Discriminant then
13599 Next_Discriminant (D);
13605 pragma Assert (Nkind (Result) /= N_Defining_Identifier);
13607 end Get_Discriminant_Value;
13609 --------------------------
13610 -- Has_Range_Constraint --
13611 --------------------------
13613 function Has_Range_Constraint (N : Node_Id) return Boolean is
13614 C : constant Node_Id := Constraint (N);
13617 if Nkind (C) = N_Range_Constraint then
13620 elsif Nkind (C) = N_Digits_Constraint then
13622 Is_Decimal_Fixed_Point_Type (Entity (Subtype_Mark (N)))
13624 Present (Range_Constraint (C));
13626 elsif Nkind (C) = N_Delta_Constraint then
13627 return Present (Range_Constraint (C));
13632 end Has_Range_Constraint;
13634 ------------------------
13635 -- Inherit_Components --
13636 ------------------------
13638 function Inherit_Components
13640 Parent_Base : Entity_Id;
13641 Derived_Base : Entity_Id;
13642 Is_Tagged : Boolean;
13643 Inherit_Discr : Boolean;
13644 Discs : Elist_Id) return Elist_Id
13646 Assoc_List : constant Elist_Id := New_Elmt_List;
13648 procedure Inherit_Component
13649 (Old_C : Entity_Id;
13650 Plain_Discrim : Boolean := False;
13651 Stored_Discrim : Boolean := False);
13652 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
13653 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
13654 -- True, Old_C is a stored discriminant. If they are both false then
13655 -- Old_C is a regular component.
13657 -----------------------
13658 -- Inherit_Component --
13659 -----------------------
13661 procedure Inherit_Component
13662 (Old_C : Entity_Id;
13663 Plain_Discrim : Boolean := False;
13664 Stored_Discrim : Boolean := False)
13666 New_C : constant Entity_Id := New_Copy (Old_C);
13668 Discrim : Entity_Id;
13669 Corr_Discrim : Entity_Id;
13672 pragma Assert (not Is_Tagged or else not Stored_Discrim);
13674 Set_Parent (New_C, Parent (Old_C));
13676 -- Regular discriminants and components must be inserted in the scope
13677 -- of the Derived_Base. Do it here.
13679 if not Stored_Discrim then
13680 Enter_Name (New_C);
13683 -- For tagged types the Original_Record_Component must point to
13684 -- whatever this field was pointing to in the parent type. This has
13685 -- already been achieved by the call to New_Copy above.
13687 if not Is_Tagged then
13688 Set_Original_Record_Component (New_C, New_C);
13691 -- If we have inherited a component then see if its Etype contains
13692 -- references to Parent_Base discriminants. In this case, replace
13693 -- these references with the constraints given in Discs. We do not
13694 -- do this for the partial view of private types because this is
13695 -- not needed (only the components of the full view will be used
13696 -- for code generation) and cause problem. We also avoid this
13697 -- transformation in some error situations.
13699 if Ekind (New_C) = E_Component then
13700 if (Is_Private_Type (Derived_Base)
13701 and then not Is_Generic_Type (Derived_Base))
13702 or else (Is_Empty_Elmt_List (Discs)
13703 and then not Expander_Active)
13705 Set_Etype (New_C, Etype (Old_C));
13708 -- The current component introduces a circularity of the
13711 -- limited with Pack_2;
13712 -- package Pack_1 is
13713 -- type T_1 is tagged record
13714 -- Comp : access Pack_2.T_2;
13720 -- package Pack_2 is
13721 -- type T_2 is new Pack_1.T_1 with ...;
13726 Constrain_Component_Type
13727 (Old_C, Derived_Base, N, Parent_Base, Discs));
13731 -- In derived tagged types it is illegal to reference a non
13732 -- discriminant component in the parent type. To catch this, mark
13733 -- these components with an Ekind of E_Void. This will be reset in
13734 -- Record_Type_Definition after processing the record extension of
13735 -- the derived type.
13737 -- If the declaration is a private extension, there is no further
13738 -- record extension to process, and the components retain their
13739 -- current kind, because they are visible at this point.
13741 if Is_Tagged and then Ekind (New_C) = E_Component
13742 and then Nkind (N) /= N_Private_Extension_Declaration
13744 Set_Ekind (New_C, E_Void);
13747 if Plain_Discrim then
13748 Set_Corresponding_Discriminant (New_C, Old_C);
13749 Build_Discriminal (New_C);
13751 -- If we are explicitly inheriting a stored discriminant it will be
13752 -- completely hidden.
13754 elsif Stored_Discrim then
13755 Set_Corresponding_Discriminant (New_C, Empty);
13756 Set_Discriminal (New_C, Empty);
13757 Set_Is_Completely_Hidden (New_C);
13759 -- Set the Original_Record_Component of each discriminant in the
13760 -- derived base to point to the corresponding stored that we just
13763 Discrim := First_Discriminant (Derived_Base);
13764 while Present (Discrim) loop
13765 Corr_Discrim := Corresponding_Discriminant (Discrim);
13767 -- Corr_Discrim could be missing in an error situation
13769 if Present (Corr_Discrim)
13770 and then Original_Record_Component (Corr_Discrim) = Old_C
13772 Set_Original_Record_Component (Discrim, New_C);
13775 Next_Discriminant (Discrim);
13778 Append_Entity (New_C, Derived_Base);
13781 if not Is_Tagged then
13782 Append_Elmt (Old_C, Assoc_List);
13783 Append_Elmt (New_C, Assoc_List);
13785 end Inherit_Component;
13787 -- Variables local to Inherit_Component
13789 Loc : constant Source_Ptr := Sloc (N);
13791 Parent_Discrim : Entity_Id;
13792 Stored_Discrim : Entity_Id;
13794 Component : Entity_Id;
13796 -- Start of processing for Inherit_Components
13799 if not Is_Tagged then
13800 Append_Elmt (Parent_Base, Assoc_List);
13801 Append_Elmt (Derived_Base, Assoc_List);
13804 -- Inherit parent discriminants if needed
13806 if Inherit_Discr then
13807 Parent_Discrim := First_Discriminant (Parent_Base);
13808 while Present (Parent_Discrim) loop
13809 Inherit_Component (Parent_Discrim, Plain_Discrim => True);
13810 Next_Discriminant (Parent_Discrim);
13814 -- Create explicit stored discrims for untagged types when necessary
13816 if not Has_Unknown_Discriminants (Derived_Base)
13817 and then Has_Discriminants (Parent_Base)
13818 and then not Is_Tagged
13821 or else First_Discriminant (Parent_Base) /=
13822 First_Stored_Discriminant (Parent_Base))
13824 Stored_Discrim := First_Stored_Discriminant (Parent_Base);
13825 while Present (Stored_Discrim) loop
13826 Inherit_Component (Stored_Discrim, Stored_Discrim => True);
13827 Next_Stored_Discriminant (Stored_Discrim);
13831 -- See if we can apply the second transformation for derived types, as
13832 -- explained in point 6. in the comments above Build_Derived_Record_Type
13833 -- This is achieved by appending Derived_Base discriminants into Discs,
13834 -- which has the side effect of returning a non empty Discs list to the
13835 -- caller of Inherit_Components, which is what we want. This must be
13836 -- done for private derived types if there are explicit stored
13837 -- discriminants, to ensure that we can retrieve the values of the
13838 -- constraints provided in the ancestors.
13841 and then Is_Empty_Elmt_List (Discs)
13842 and then Present (First_Discriminant (Derived_Base))
13844 (not Is_Private_Type (Derived_Base)
13845 or else Is_Completely_Hidden
13846 (First_Stored_Discriminant (Derived_Base))
13847 or else Is_Generic_Type (Derived_Base))
13849 D := First_Discriminant (Derived_Base);
13850 while Present (D) loop
13851 Append_Elmt (New_Reference_To (D, Loc), Discs);
13852 Next_Discriminant (D);
13856 -- Finally, inherit non-discriminant components unless they are not
13857 -- visible because defined or inherited from the full view of the
13858 -- parent. Don't inherit the _parent field of the parent type.
13860 Component := First_Entity (Parent_Base);
13861 while Present (Component) loop
13863 -- Ada 2005 (AI-251): Do not inherit components associated with
13864 -- secondary tags of the parent.
13866 if Ekind (Component) = E_Component
13867 and then Present (Related_Type (Component))
13871 elsif Ekind (Component) /= E_Component
13872 or else Chars (Component) = Name_uParent
13876 -- If the derived type is within the parent type's declarative
13877 -- region, then the components can still be inherited even though
13878 -- they aren't visible at this point. This can occur for cases
13879 -- such as within public child units where the components must
13880 -- become visible upon entering the child unit's private part.
13882 elsif not Is_Visible_Component (Component)
13883 and then not In_Open_Scopes (Scope (Parent_Base))
13887 elsif Ekind (Derived_Base) = E_Private_Type
13888 or else Ekind (Derived_Base) = E_Limited_Private_Type
13893 Inherit_Component (Component);
13896 Next_Entity (Component);
13899 -- For tagged derived types, inherited discriminants cannot be used in
13900 -- component declarations of the record extension part. To achieve this
13901 -- we mark the inherited discriminants as not visible.
13903 if Is_Tagged and then Inherit_Discr then
13904 D := First_Discriminant (Derived_Base);
13905 while Present (D) loop
13906 Set_Is_Immediately_Visible (D, False);
13907 Next_Discriminant (D);
13912 end Inherit_Components;
13914 -----------------------
13915 -- Is_Null_Extension --
13916 -----------------------
13918 function Is_Null_Extension (T : Entity_Id) return Boolean is
13919 Type_Decl : constant Node_Id := Parent (T);
13920 Comp_List : Node_Id;
13924 if Nkind (Type_Decl) /= N_Full_Type_Declaration
13925 or else not Is_Tagged_Type (T)
13926 or else Nkind (Type_Definition (Type_Decl)) /=
13927 N_Derived_Type_Definition
13928 or else No (Record_Extension_Part (Type_Definition (Type_Decl)))
13934 Component_List (Record_Extension_Part (Type_Definition (Type_Decl)));
13936 if Present (Discriminant_Specifications (Type_Decl)) then
13939 elsif Present (Comp_List)
13940 and then Is_Non_Empty_List (Component_Items (Comp_List))
13942 Comp := First (Component_Items (Comp_List));
13944 -- Only user-defined components are relevant. The component list
13945 -- may also contain a parent component and internal components
13946 -- corresponding to secondary tags, but these do not determine
13947 -- whether this is a null extension.
13949 while Present (Comp) loop
13950 if Comes_From_Source (Comp) then
13961 end Is_Null_Extension;
13963 --------------------
13964 -- Is_Progenitor --
13965 --------------------
13967 function Is_Progenitor
13968 (Iface : Entity_Id;
13969 Typ : Entity_Id) return Boolean
13971 Iface_Elmt : Elmt_Id;
13972 I_Name : Entity_Id;
13975 if No (Abstract_Interfaces (Typ)) then
13979 Iface_Elmt := First_Elmt (Abstract_Interfaces (Typ));
13980 while Present (Iface_Elmt) loop
13981 I_Name := Node (Iface_Elmt);
13982 if Base_Type (I_Name) = Base_Type (Iface) then
13985 elsif Is_Derived_Type (I_Name)
13986 and then Is_Ancestor (Iface, I_Name)
13991 Next_Elmt (Iface_Elmt);
13995 -- For concurrent record types, they have the interfaces of the
13996 -- parent synchronized type. However these have no ancestors that
13997 -- implement anything, so assume it is a progenitor.
13998 -- Should be cleaned up in Collect_Abstract_Interfaces???
14000 if Is_Concurrent_Record_Type (Typ) then
14001 return Present (Abstract_Interfaces (Typ));
14004 -- If type is a derived type, check recursively its ancestors
14006 if Is_Derived_Type (Typ) then
14007 return Etype (Typ) = Iface
14008 or else Is_Progenitor (Iface, Etype (Typ));
14015 ------------------------------
14016 -- Is_Valid_Constraint_Kind --
14017 ------------------------------
14019 function Is_Valid_Constraint_Kind
14020 (T_Kind : Type_Kind;
14021 Constraint_Kind : Node_Kind) return Boolean
14025 when Enumeration_Kind |
14027 return Constraint_Kind = N_Range_Constraint;
14029 when Decimal_Fixed_Point_Kind =>
14030 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14031 N_Range_Constraint);
14033 when Ordinary_Fixed_Point_Kind =>
14034 return Nkind_In (Constraint_Kind, N_Delta_Constraint,
14035 N_Range_Constraint);
14038 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14039 N_Range_Constraint);
14046 E_Incomplete_Type |
14049 return Constraint_Kind = N_Index_Or_Discriminant_Constraint;
14052 return True; -- Error will be detected later
14054 end Is_Valid_Constraint_Kind;
14056 --------------------------
14057 -- Is_Visible_Component --
14058 --------------------------
14060 function Is_Visible_Component (C : Entity_Id) return Boolean is
14061 Original_Comp : Entity_Id := Empty;
14062 Original_Scope : Entity_Id;
14063 Type_Scope : Entity_Id;
14065 function Is_Local_Type (Typ : Entity_Id) return Boolean;
14066 -- Check whether parent type of inherited component is declared locally,
14067 -- possibly within a nested package or instance. The current scope is
14068 -- the derived record itself.
14070 -------------------
14071 -- Is_Local_Type --
14072 -------------------
14074 function Is_Local_Type (Typ : Entity_Id) return Boolean is
14078 Scop := Scope (Typ);
14079 while Present (Scop)
14080 and then Scop /= Standard_Standard
14082 if Scop = Scope (Current_Scope) then
14086 Scop := Scope (Scop);
14092 -- Start of processing for Is_Visible_Component
14095 if Ekind (C) = E_Component
14096 or else Ekind (C) = E_Discriminant
14098 Original_Comp := Original_Record_Component (C);
14101 if No (Original_Comp) then
14103 -- Premature usage, or previous error
14108 Original_Scope := Scope (Original_Comp);
14109 Type_Scope := Scope (Base_Type (Scope (C)));
14112 -- This test only concerns tagged types
14114 if not Is_Tagged_Type (Original_Scope) then
14117 -- If it is _Parent or _Tag, there is no visibility issue
14119 elsif not Comes_From_Source (Original_Comp) then
14122 -- If we are in the body of an instantiation, the component is visible
14123 -- even when the parent type (possibly defined in an enclosing unit or
14124 -- in a parent unit) might not.
14126 elsif In_Instance_Body then
14129 -- Discriminants are always visible
14131 elsif Ekind (Original_Comp) = E_Discriminant
14132 and then not Has_Unknown_Discriminants (Original_Scope)
14136 -- If the component has been declared in an ancestor which is currently
14137 -- a private type, then it is not visible. The same applies if the
14138 -- component's containing type is not in an open scope and the original
14139 -- component's enclosing type is a visible full view of a private type
14140 -- (which can occur in cases where an attempt is being made to reference
14141 -- a component in a sibling package that is inherited from a visible
14142 -- component of a type in an ancestor package; the component in the
14143 -- sibling package should not be visible even though the component it
14144 -- inherited from is visible). This does not apply however in the case
14145 -- where the scope of the type is a private child unit, or when the
14146 -- parent comes from a local package in which the ancestor is currently
14147 -- visible. The latter suppression of visibility is needed for cases
14148 -- that are tested in B730006.
14150 elsif Is_Private_Type (Original_Scope)
14152 (not Is_Private_Descendant (Type_Scope)
14153 and then not In_Open_Scopes (Type_Scope)
14154 and then Has_Private_Declaration (Original_Scope))
14156 -- If the type derives from an entity in a formal package, there
14157 -- are no additional visible components.
14159 if Nkind (Original_Node (Unit_Declaration_Node (Type_Scope))) =
14160 N_Formal_Package_Declaration
14164 -- if we are not in the private part of the current package, there
14165 -- are no additional visible components.
14167 elsif Ekind (Scope (Current_Scope)) = E_Package
14168 and then not In_Private_Part (Scope (Current_Scope))
14173 Is_Child_Unit (Cunit_Entity (Current_Sem_Unit))
14174 and then In_Open_Scopes (Scope (Original_Scope))
14175 and then Is_Local_Type (Type_Scope);
14178 -- There is another weird way in which a component may be invisible
14179 -- when the private and the full view are not derived from the same
14180 -- ancestor. Here is an example :
14182 -- type A1 is tagged record F1 : integer; end record;
14183 -- type A2 is new A1 with record F2 : integer; end record;
14184 -- type T is new A1 with private;
14186 -- type T is new A2 with null record;
14188 -- In this case, the full view of T inherits F1 and F2 but the private
14189 -- view inherits only F1
14193 Ancestor : Entity_Id := Scope (C);
14197 if Ancestor = Original_Scope then
14199 elsif Ancestor = Etype (Ancestor) then
14203 Ancestor := Etype (Ancestor);
14207 end Is_Visible_Component;
14209 --------------------------
14210 -- Make_Class_Wide_Type --
14211 --------------------------
14213 procedure Make_Class_Wide_Type (T : Entity_Id) is
14214 CW_Type : Entity_Id;
14216 Next_E : Entity_Id;
14219 -- The class wide type can have been defined by the partial view, in
14220 -- which case everything is already done.
14222 if Present (Class_Wide_Type (T)) then
14227 New_External_Entity (E_Void, Scope (T), Sloc (T), T, 'C', 0, 'T');
14229 -- Inherit root type characteristics
14231 CW_Name := Chars (CW_Type);
14232 Next_E := Next_Entity (CW_Type);
14233 Copy_Node (T, CW_Type);
14234 Set_Comes_From_Source (CW_Type, False);
14235 Set_Chars (CW_Type, CW_Name);
14236 Set_Parent (CW_Type, Parent (T));
14237 Set_Next_Entity (CW_Type, Next_E);
14239 -- Ensure we have a new freeze node for the class-wide type. The partial
14240 -- view may have freeze action of its own, requiring a proper freeze
14241 -- node, and the same freeze node cannot be shared between the two
14244 Set_Has_Delayed_Freeze (CW_Type);
14245 Set_Freeze_Node (CW_Type, Empty);
14247 -- Customize the class-wide type: It has no prim. op., it cannot be
14248 -- abstract and its Etype points back to the specific root type.
14250 Set_Ekind (CW_Type, E_Class_Wide_Type);
14251 Set_Is_Tagged_Type (CW_Type, True);
14252 Set_Primitive_Operations (CW_Type, New_Elmt_List);
14253 Set_Is_Abstract_Type (CW_Type, False);
14254 Set_Is_Constrained (CW_Type, False);
14255 Set_Is_First_Subtype (CW_Type, Is_First_Subtype (T));
14257 if Ekind (T) = E_Class_Wide_Subtype then
14258 Set_Etype (CW_Type, Etype (Base_Type (T)));
14260 Set_Etype (CW_Type, T);
14263 -- If this is the class_wide type of a constrained subtype, it does
14264 -- not have discriminants.
14266 Set_Has_Discriminants (CW_Type,
14267 Has_Discriminants (T) and then not Is_Constrained (T));
14269 Set_Has_Unknown_Discriminants (CW_Type, True);
14270 Set_Class_Wide_Type (T, CW_Type);
14271 Set_Equivalent_Type (CW_Type, Empty);
14273 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
14275 Set_Class_Wide_Type (CW_Type, CW_Type);
14276 end Make_Class_Wide_Type;
14282 procedure Make_Index
14284 Related_Nod : Node_Id;
14285 Related_Id : Entity_Id := Empty;
14286 Suffix_Index : Nat := 1)
14290 Def_Id : Entity_Id := Empty;
14291 Found : Boolean := False;
14294 -- For a discrete range used in a constrained array definition and
14295 -- defined by a range, an implicit conversion to the predefined type
14296 -- INTEGER is assumed if each bound is either a numeric literal, a named
14297 -- number, or an attribute, and the type of both bounds (prior to the
14298 -- implicit conversion) is the type universal_integer. Otherwise, both
14299 -- bounds must be of the same discrete type, other than universal
14300 -- integer; this type must be determinable independently of the
14301 -- context, but using the fact that the type must be discrete and that
14302 -- both bounds must have the same type.
14304 -- Character literals also have a universal type in the absence of
14305 -- of additional context, and are resolved to Standard_Character.
14307 if Nkind (I) = N_Range then
14309 -- The index is given by a range constraint. The bounds are known
14310 -- to be of a consistent type.
14312 if not Is_Overloaded (I) then
14315 -- For universal bounds, choose the specific predefined type
14317 if T = Universal_Integer then
14318 T := Standard_Integer;
14320 elsif T = Any_Character then
14321 Ambiguous_Character (Low_Bound (I));
14323 T := Standard_Character;
14326 -- The node may be overloaded because some user-defined operators
14327 -- are available, but if a universal interpretation exists it is
14328 -- also the selected one.
14330 elsif Universal_Interpretation (I) = Universal_Integer then
14331 T := Standard_Integer;
14337 Ind : Interp_Index;
14341 Get_First_Interp (I, Ind, It);
14342 while Present (It.Typ) loop
14343 if Is_Discrete_Type (It.Typ) then
14346 and then not Covers (It.Typ, T)
14347 and then not Covers (T, It.Typ)
14349 Error_Msg_N ("ambiguous bounds in discrete range", I);
14357 Get_Next_Interp (Ind, It);
14360 if T = Any_Type then
14361 Error_Msg_N ("discrete type required for range", I);
14362 Set_Etype (I, Any_Type);
14365 elsif T = Universal_Integer then
14366 T := Standard_Integer;
14371 if not Is_Discrete_Type (T) then
14372 Error_Msg_N ("discrete type required for range", I);
14373 Set_Etype (I, Any_Type);
14377 if Nkind (Low_Bound (I)) = N_Attribute_Reference
14378 and then Attribute_Name (Low_Bound (I)) = Name_First
14379 and then Is_Entity_Name (Prefix (Low_Bound (I)))
14380 and then Is_Type (Entity (Prefix (Low_Bound (I))))
14381 and then Is_Discrete_Type (Entity (Prefix (Low_Bound (I))))
14383 -- The type of the index will be the type of the prefix, as long
14384 -- as the upper bound is 'Last of the same type.
14386 Def_Id := Entity (Prefix (Low_Bound (I)));
14388 if Nkind (High_Bound (I)) /= N_Attribute_Reference
14389 or else Attribute_Name (High_Bound (I)) /= Name_Last
14390 or else not Is_Entity_Name (Prefix (High_Bound (I)))
14391 or else Entity (Prefix (High_Bound (I))) /= Def_Id
14398 Process_Range_Expr_In_Decl (R, T);
14400 elsif Nkind (I) = N_Subtype_Indication then
14402 -- The index is given by a subtype with a range constraint
14404 T := Base_Type (Entity (Subtype_Mark (I)));
14406 if not Is_Discrete_Type (T) then
14407 Error_Msg_N ("discrete type required for range", I);
14408 Set_Etype (I, Any_Type);
14412 R := Range_Expression (Constraint (I));
14415 Process_Range_Expr_In_Decl (R, Entity (Subtype_Mark (I)));
14417 elsif Nkind (I) = N_Attribute_Reference then
14419 -- The parser guarantees that the attribute is a RANGE attribute
14421 -- If the node denotes the range of a type mark, that is also the
14422 -- resulting type, and we do no need to create an Itype for it.
14424 if Is_Entity_Name (Prefix (I))
14425 and then Comes_From_Source (I)
14426 and then Is_Type (Entity (Prefix (I)))
14427 and then Is_Discrete_Type (Entity (Prefix (I)))
14429 Def_Id := Entity (Prefix (I));
14432 Analyze_And_Resolve (I);
14436 -- If none of the above, must be a subtype. We convert this to a
14437 -- range attribute reference because in the case of declared first
14438 -- named subtypes, the types in the range reference can be different
14439 -- from the type of the entity. A range attribute normalizes the
14440 -- reference and obtains the correct types for the bounds.
14442 -- This transformation is in the nature of an expansion, is only
14443 -- done if expansion is active. In particular, it is not done on
14444 -- formal generic types, because we need to retain the name of the
14445 -- original index for instantiation purposes.
14448 if not Is_Entity_Name (I) or else not Is_Type (Entity (I)) then
14449 Error_Msg_N ("invalid subtype mark in discrete range ", I);
14450 Set_Etype (I, Any_Integer);
14454 -- The type mark may be that of an incomplete type. It is only
14455 -- now that we can get the full view, previous analysis does
14456 -- not look specifically for a type mark.
14458 Set_Entity (I, Get_Full_View (Entity (I)));
14459 Set_Etype (I, Entity (I));
14460 Def_Id := Entity (I);
14462 if not Is_Discrete_Type (Def_Id) then
14463 Error_Msg_N ("discrete type required for index", I);
14464 Set_Etype (I, Any_Type);
14469 if Expander_Active then
14471 Make_Attribute_Reference (Sloc (I),
14472 Attribute_Name => Name_Range,
14473 Prefix => Relocate_Node (I)));
14475 -- The original was a subtype mark that does not freeze. This
14476 -- means that the rewritten version must not freeze either.
14478 Set_Must_Not_Freeze (I);
14479 Set_Must_Not_Freeze (Prefix (I));
14481 -- Is order critical??? if so, document why, if not
14482 -- use Analyze_And_Resolve
14484 Analyze_And_Resolve (I);
14488 -- If expander is inactive, type is legal, nothing else to construct
14495 if not Is_Discrete_Type (T) then
14496 Error_Msg_N ("discrete type required for range", I);
14497 Set_Etype (I, Any_Type);
14500 elsif T = Any_Type then
14501 Set_Etype (I, Any_Type);
14505 -- We will now create the appropriate Itype to describe the range, but
14506 -- first a check. If we originally had a subtype, then we just label
14507 -- the range with this subtype. Not only is there no need to construct
14508 -- a new subtype, but it is wrong to do so for two reasons:
14510 -- 1. A legality concern, if we have a subtype, it must not freeze,
14511 -- and the Itype would cause freezing incorrectly
14513 -- 2. An efficiency concern, if we created an Itype, it would not be
14514 -- recognized as the same type for the purposes of eliminating
14515 -- checks in some circumstances.
14517 -- We signal this case by setting the subtype entity in Def_Id
14519 if No (Def_Id) then
14521 Create_Itype (E_Void, Related_Nod, Related_Id, 'D', Suffix_Index);
14522 Set_Etype (Def_Id, Base_Type (T));
14524 if Is_Signed_Integer_Type (T) then
14525 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
14527 elsif Is_Modular_Integer_Type (T) then
14528 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
14531 Set_Ekind (Def_Id, E_Enumeration_Subtype);
14532 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
14533 Set_First_Literal (Def_Id, First_Literal (T));
14536 Set_Size_Info (Def_Id, (T));
14537 Set_RM_Size (Def_Id, RM_Size (T));
14538 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
14540 Set_Scalar_Range (Def_Id, R);
14541 Conditional_Delay (Def_Id, T);
14543 -- In the subtype indication case, if the immediate parent of the
14544 -- new subtype is non-static, then the subtype we create is non-
14545 -- static, even if its bounds are static.
14547 if Nkind (I) = N_Subtype_Indication
14548 and then not Is_Static_Subtype (Entity (Subtype_Mark (I)))
14550 Set_Is_Non_Static_Subtype (Def_Id);
14554 -- Final step is to label the index with this constructed type
14556 Set_Etype (I, Def_Id);
14559 ------------------------------
14560 -- Modular_Type_Declaration --
14561 ------------------------------
14563 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id) is
14564 Mod_Expr : constant Node_Id := Expression (Def);
14567 procedure Set_Modular_Size (Bits : Int);
14568 -- Sets RM_Size to Bits, and Esize to normal word size above this
14570 ----------------------
14571 -- Set_Modular_Size --
14572 ----------------------
14574 procedure Set_Modular_Size (Bits : Int) is
14576 Set_RM_Size (T, UI_From_Int (Bits));
14581 elsif Bits <= 16 then
14582 Init_Esize (T, 16);
14584 elsif Bits <= 32 then
14585 Init_Esize (T, 32);
14588 Init_Esize (T, System_Max_Binary_Modulus_Power);
14590 end Set_Modular_Size;
14592 -- Start of processing for Modular_Type_Declaration
14595 Analyze_And_Resolve (Mod_Expr, Any_Integer);
14597 Set_Ekind (T, E_Modular_Integer_Type);
14598 Init_Alignment (T);
14599 Set_Is_Constrained (T);
14601 if not Is_OK_Static_Expression (Mod_Expr) then
14602 Flag_Non_Static_Expr
14603 ("non-static expression used for modular type bound!", Mod_Expr);
14604 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14606 M_Val := Expr_Value (Mod_Expr);
14610 Error_Msg_N ("modulus value must be positive", Mod_Expr);
14611 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14614 Set_Modulus (T, M_Val);
14616 -- Create bounds for the modular type based on the modulus given in
14617 -- the type declaration and then analyze and resolve those bounds.
14619 Set_Scalar_Range (T,
14620 Make_Range (Sloc (Mod_Expr),
14622 Make_Integer_Literal (Sloc (Mod_Expr), 0),
14624 Make_Integer_Literal (Sloc (Mod_Expr), M_Val - 1)));
14626 -- Properly analyze the literals for the range. We do this manually
14627 -- because we can't go calling Resolve, since we are resolving these
14628 -- bounds with the type, and this type is certainly not complete yet!
14630 Set_Etype (Low_Bound (Scalar_Range (T)), T);
14631 Set_Etype (High_Bound (Scalar_Range (T)), T);
14632 Set_Is_Static_Expression (Low_Bound (Scalar_Range (T)));
14633 Set_Is_Static_Expression (High_Bound (Scalar_Range (T)));
14635 -- Loop through powers of two to find number of bits required
14637 for Bits in Int range 0 .. System_Max_Binary_Modulus_Power loop
14641 if M_Val = 2 ** Bits then
14642 Set_Modular_Size (Bits);
14647 elsif M_Val < 2 ** Bits then
14648 Set_Non_Binary_Modulus (T);
14650 if Bits > System_Max_Nonbinary_Modulus_Power then
14651 Error_Msg_Uint_1 :=
14652 UI_From_Int (System_Max_Nonbinary_Modulus_Power);
14654 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr);
14655 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14659 -- In the non-binary case, set size as per RM 13.3(55)
14661 Set_Modular_Size (Bits);
14668 -- If we fall through, then the size exceed System.Max_Binary_Modulus
14669 -- so we just signal an error and set the maximum size.
14671 Error_Msg_Uint_1 := UI_From_Int (System_Max_Binary_Modulus_Power);
14672 Error_Msg_F ("modulus exceeds limit (2 '*'*^)", Mod_Expr);
14674 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14675 Init_Alignment (T);
14677 end Modular_Type_Declaration;
14679 --------------------------
14680 -- New_Concatenation_Op --
14681 --------------------------
14683 procedure New_Concatenation_Op (Typ : Entity_Id) is
14684 Loc : constant Source_Ptr := Sloc (Typ);
14687 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id;
14688 -- Create abbreviated declaration for the formal of a predefined
14689 -- Operator 'Op' of type 'Typ'
14691 --------------------
14692 -- Make_Op_Formal --
14693 --------------------
14695 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id is
14696 Formal : Entity_Id;
14698 Formal := New_Internal_Entity (E_In_Parameter, Op, Loc, 'P');
14699 Set_Etype (Formal, Typ);
14700 Set_Mechanism (Formal, Default_Mechanism);
14702 end Make_Op_Formal;
14704 -- Start of processing for New_Concatenation_Op
14707 Op := Make_Defining_Operator_Symbol (Loc, Name_Op_Concat);
14709 Set_Ekind (Op, E_Operator);
14710 Set_Scope (Op, Current_Scope);
14711 Set_Etype (Op, Typ);
14712 Set_Homonym (Op, Get_Name_Entity_Id (Name_Op_Concat));
14713 Set_Is_Immediately_Visible (Op);
14714 Set_Is_Intrinsic_Subprogram (Op);
14715 Set_Has_Completion (Op);
14716 Append_Entity (Op, Current_Scope);
14718 Set_Name_Entity_Id (Name_Op_Concat, Op);
14720 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14721 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14722 end New_Concatenation_Op;
14724 -------------------------
14725 -- OK_For_Limited_Init --
14726 -------------------------
14728 -- ???Check all calls of this, and compare the conditions under which it's
14731 function OK_For_Limited_Init (Exp : Node_Id) return Boolean is
14733 return Ada_Version >= Ada_05
14734 and then not Debug_Flag_Dot_L
14735 and then OK_For_Limited_Init_In_05 (Exp);
14736 end OK_For_Limited_Init;
14738 -------------------------------
14739 -- OK_For_Limited_Init_In_05 --
14740 -------------------------------
14742 function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean is
14744 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
14745 -- case of limited aggregates (including extension aggregates), and
14746 -- function calls. The function call may have been give in prefixed
14747 -- notation, in which case the original node is an indexed component.
14749 case Nkind (Original_Node (Exp)) is
14750 when N_Aggregate | N_Extension_Aggregate | N_Function_Call | N_Op =>
14753 when N_Qualified_Expression =>
14755 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
14757 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
14758 -- with a function call, the expander has rewritten the call into an
14759 -- N_Type_Conversion node to force displacement of the pointer to
14760 -- reference the component containing the secondary dispatch table.
14761 -- Otherwise a type conversion is not a legal context.
14763 when N_Type_Conversion =>
14764 return not Comes_From_Source (Exp)
14766 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
14768 when N_Indexed_Component | N_Selected_Component =>
14769 return Nkind (Exp) = N_Function_Call;
14771 -- A use of 'Input is a function call, hence allowed. Normally the
14772 -- attribute will be changed to a call, but the attribute by itself
14773 -- can occur with -gnatc.
14775 when N_Attribute_Reference =>
14776 return Attribute_Name (Original_Node (Exp)) = Name_Input;
14781 end OK_For_Limited_Init_In_05;
14783 -------------------------------------------
14784 -- Ordinary_Fixed_Point_Type_Declaration --
14785 -------------------------------------------
14787 procedure Ordinary_Fixed_Point_Type_Declaration
14791 Loc : constant Source_Ptr := Sloc (Def);
14792 Delta_Expr : constant Node_Id := Delta_Expression (Def);
14793 RRS : constant Node_Id := Real_Range_Specification (Def);
14794 Implicit_Base : Entity_Id;
14801 Check_Restriction (No_Fixed_Point, Def);
14803 -- Create implicit base type
14806 Create_Itype (E_Ordinary_Fixed_Point_Type, Parent (Def), T, 'B');
14807 Set_Etype (Implicit_Base, Implicit_Base);
14809 -- Analyze and process delta expression
14811 Analyze_And_Resolve (Delta_Expr, Any_Real);
14813 Check_Delta_Expression (Delta_Expr);
14814 Delta_Val := Expr_Value_R (Delta_Expr);
14816 Set_Delta_Value (Implicit_Base, Delta_Val);
14818 -- Compute default small from given delta, which is the largest power
14819 -- of two that does not exceed the given delta value.
14829 if Delta_Val < Ureal_1 then
14830 while Delta_Val < Tmp loop
14831 Tmp := Tmp / Ureal_2;
14832 Scale := Scale + 1;
14837 Tmp := Tmp * Ureal_2;
14838 exit when Tmp > Delta_Val;
14839 Scale := Scale - 1;
14843 Small_Val := UR_From_Components (Uint_1, UI_From_Int (Scale), 2);
14846 Set_Small_Value (Implicit_Base, Small_Val);
14848 -- If no range was given, set a dummy range
14850 if RRS <= Empty_Or_Error then
14851 Low_Val := -Small_Val;
14852 High_Val := Small_Val;
14854 -- Otherwise analyze and process given range
14858 Low : constant Node_Id := Low_Bound (RRS);
14859 High : constant Node_Id := High_Bound (RRS);
14862 Analyze_And_Resolve (Low, Any_Real);
14863 Analyze_And_Resolve (High, Any_Real);
14864 Check_Real_Bound (Low);
14865 Check_Real_Bound (High);
14867 -- Obtain and set the range
14869 Low_Val := Expr_Value_R (Low);
14870 High_Val := Expr_Value_R (High);
14872 if Low_Val > High_Val then
14873 Error_Msg_NE ("?fixed point type& has null range", Def, T);
14878 -- The range for both the implicit base and the declared first subtype
14879 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
14880 -- set a temporary range in place. Note that the bounds of the base
14881 -- type will be widened to be symmetrical and to fill the available
14882 -- bits when the type is frozen.
14884 -- We could do this with all discrete types, and probably should, but
14885 -- we absolutely have to do it for fixed-point, since the end-points
14886 -- of the range and the size are determined by the small value, which
14887 -- could be reset before the freeze point.
14889 Set_Fixed_Range (Implicit_Base, Loc, Low_Val, High_Val);
14890 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
14892 -- Complete definition of first subtype
14894 Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype);
14895 Set_Etype (T, Implicit_Base);
14896 Init_Size_Align (T);
14897 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
14898 Set_Small_Value (T, Small_Val);
14899 Set_Delta_Value (T, Delta_Val);
14900 Set_Is_Constrained (T);
14902 end Ordinary_Fixed_Point_Type_Declaration;
14904 ----------------------------------------
14905 -- Prepare_Private_Subtype_Completion --
14906 ----------------------------------------
14908 procedure Prepare_Private_Subtype_Completion
14910 Related_Nod : Node_Id)
14912 Id_B : constant Entity_Id := Base_Type (Id);
14913 Full_B : constant Entity_Id := Full_View (Id_B);
14917 if Present (Full_B) then
14919 -- The Base_Type is already completed, we can complete the subtype
14920 -- now. We have to create a new entity with the same name, Thus we
14921 -- can't use Create_Itype.
14923 -- This is messy, should be fixed ???
14925 Full := Make_Defining_Identifier (Sloc (Id), Chars (Id));
14926 Set_Is_Itype (Full);
14927 Set_Associated_Node_For_Itype (Full, Related_Nod);
14928 Complete_Private_Subtype (Id, Full, Full_B, Related_Nod);
14931 -- The parent subtype may be private, but the base might not, in some
14932 -- nested instances. In that case, the subtype does not need to be
14933 -- exchanged. It would still be nice to make private subtypes and their
14934 -- bases consistent at all times ???
14936 if Is_Private_Type (Id_B) then
14937 Append_Elmt (Id, Private_Dependents (Id_B));
14940 end Prepare_Private_Subtype_Completion;
14942 ---------------------------
14943 -- Process_Discriminants --
14944 ---------------------------
14946 procedure Process_Discriminants
14948 Prev : Entity_Id := Empty)
14950 Elist : constant Elist_Id := New_Elmt_List;
14953 Discr_Number : Uint;
14954 Discr_Type : Entity_Id;
14955 Default_Present : Boolean := False;
14956 Default_Not_Present : Boolean := False;
14959 -- A composite type other than an array type can have discriminants.
14960 -- On entry, the current scope is the composite type.
14962 -- The discriminants are initially entered into the scope of the type
14963 -- via Enter_Name with the default Ekind of E_Void to prevent premature
14964 -- use, as explained at the end of this procedure.
14966 Discr := First (Discriminant_Specifications (N));
14967 while Present (Discr) loop
14968 Enter_Name (Defining_Identifier (Discr));
14970 -- For navigation purposes we add a reference to the discriminant
14971 -- in the entity for the type. If the current declaration is a
14972 -- completion, place references on the partial view. Otherwise the
14973 -- type is the current scope.
14975 if Present (Prev) then
14977 -- The references go on the partial view, if present. If the
14978 -- partial view has discriminants, the references have been
14979 -- generated already.
14981 if not Has_Discriminants (Prev) then
14982 Generate_Reference (Prev, Defining_Identifier (Discr), 'd');
14986 (Current_Scope, Defining_Identifier (Discr), 'd');
14989 if Nkind (Discriminant_Type (Discr)) = N_Access_Definition then
14990 Discr_Type := Access_Definition (Discr, Discriminant_Type (Discr));
14992 -- Ada 2005 (AI-254)
14994 if Present (Access_To_Subprogram_Definition
14995 (Discriminant_Type (Discr)))
14996 and then Protected_Present (Access_To_Subprogram_Definition
14997 (Discriminant_Type (Discr)))
15000 Replace_Anonymous_Access_To_Protected_Subprogram (Discr);
15004 Find_Type (Discriminant_Type (Discr));
15005 Discr_Type := Etype (Discriminant_Type (Discr));
15007 if Error_Posted (Discriminant_Type (Discr)) then
15008 Discr_Type := Any_Type;
15012 if Is_Access_Type (Discr_Type) then
15014 -- Ada 2005 (AI-230): Access discriminant allowed in non-limited
15017 if Ada_Version < Ada_05 then
15018 Check_Access_Discriminant_Requires_Limited
15019 (Discr, Discriminant_Type (Discr));
15022 if Ada_Version = Ada_83 and then Comes_From_Source (Discr) then
15024 ("(Ada 83) access discriminant not allowed", Discr);
15027 elsif not Is_Discrete_Type (Discr_Type) then
15028 Error_Msg_N ("discriminants must have a discrete or access type",
15029 Discriminant_Type (Discr));
15032 Set_Etype (Defining_Identifier (Discr), Discr_Type);
15034 -- If a discriminant specification includes the assignment compound
15035 -- delimiter followed by an expression, the expression is the default
15036 -- expression of the discriminant; the default expression must be of
15037 -- the type of the discriminant. (RM 3.7.1) Since this expression is
15038 -- a default expression, we do the special preanalysis, since this
15039 -- expression does not freeze (see "Handling of Default and Per-
15040 -- Object Expressions" in spec of package Sem).
15042 if Present (Expression (Discr)) then
15043 Preanalyze_Spec_Expression (Expression (Discr), Discr_Type);
15045 if Nkind (N) = N_Formal_Type_Declaration then
15047 ("discriminant defaults not allowed for formal type",
15048 Expression (Discr));
15050 -- Tagged types cannot have defaulted discriminants, but a
15051 -- non-tagged private type with defaulted discriminants
15052 -- can have a tagged completion.
15054 elsif Is_Tagged_Type (Current_Scope)
15055 and then Comes_From_Source (N)
15058 ("discriminants of tagged type cannot have defaults",
15059 Expression (Discr));
15062 Default_Present := True;
15063 Append_Elmt (Expression (Discr), Elist);
15065 -- Tag the defining identifiers for the discriminants with
15066 -- their corresponding default expressions from the tree.
15068 Set_Discriminant_Default_Value
15069 (Defining_Identifier (Discr), Expression (Discr));
15073 Default_Not_Present := True;
15076 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
15077 -- Discr_Type but with the null-exclusion attribute
15079 if Ada_Version >= Ada_05 then
15081 -- Ada 2005 (AI-231): Static checks
15083 if Can_Never_Be_Null (Discr_Type) then
15084 Null_Exclusion_Static_Checks (Discr);
15086 elsif Is_Access_Type (Discr_Type)
15087 and then Null_Exclusion_Present (Discr)
15089 -- No need to check itypes because in their case this check
15090 -- was done at their point of creation
15092 and then not Is_Itype (Discr_Type)
15094 if Can_Never_Be_Null (Discr_Type) then
15096 ("`NOT NULL` not allowed (& already excludes null)",
15101 Set_Etype (Defining_Identifier (Discr),
15102 Create_Null_Excluding_Itype
15104 Related_Nod => Discr));
15107 -- Ada 2005 (AI-402): access discriminants of nonlimited types
15108 -- can't have defaults. Synchronized types, or types that are
15109 -- explicitly limited are fine, but special tests apply to derived
15110 -- types in generics: in a generic body we have to assume the
15111 -- worst, and therefore defaults are not allowed if the parent is
15112 -- a generic formal private type (see ACATS B370001).
15114 if Is_Access_Type (Discr_Type) then
15115 if Ekind (Discr_Type) /= E_Anonymous_Access_Type
15116 or else not Default_Present
15117 or else Is_Limited_Record (Current_Scope)
15118 or else Is_Concurrent_Type (Current_Scope)
15119 or else Is_Concurrent_Record_Type (Current_Scope)
15120 or else Ekind (Current_Scope) = E_Limited_Private_Type
15122 if not Is_Derived_Type (Current_Scope)
15123 or else not Is_Generic_Type (Etype (Current_Scope))
15124 or else not In_Package_Body (Scope (Etype (Current_Scope)))
15125 or else Limited_Present
15126 (Type_Definition (Parent (Current_Scope)))
15131 Error_Msg_N ("access discriminants of nonlimited types",
15132 Expression (Discr));
15133 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15136 elsif Present (Expression (Discr)) then
15138 ("(Ada 2005) access discriminants of nonlimited types",
15139 Expression (Discr));
15140 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15148 -- An element list consisting of the default expressions of the
15149 -- discriminants is constructed in the above loop and used to set
15150 -- the Discriminant_Constraint attribute for the type. If an object
15151 -- is declared of this (record or task) type without any explicit
15152 -- discriminant constraint given, this element list will form the
15153 -- actual parameters for the corresponding initialization procedure
15156 Set_Discriminant_Constraint (Current_Scope, Elist);
15157 Set_Stored_Constraint (Current_Scope, No_Elist);
15159 -- Default expressions must be provided either for all or for none
15160 -- of the discriminants of a discriminant part. (RM 3.7.1)
15162 if Default_Present and then Default_Not_Present then
15164 ("incomplete specification of defaults for discriminants", N);
15167 -- The use of the name of a discriminant is not allowed in default
15168 -- expressions of a discriminant part if the specification of the
15169 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
15171 -- To detect this, the discriminant names are entered initially with an
15172 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
15173 -- attempt to use a void entity (for example in an expression that is
15174 -- type-checked) produces the error message: premature usage. Now after
15175 -- completing the semantic analysis of the discriminant part, we can set
15176 -- the Ekind of all the discriminants appropriately.
15178 Discr := First (Discriminant_Specifications (N));
15179 Discr_Number := Uint_1;
15180 while Present (Discr) loop
15181 Id := Defining_Identifier (Discr);
15182 Set_Ekind (Id, E_Discriminant);
15183 Init_Component_Location (Id);
15185 Set_Discriminant_Number (Id, Discr_Number);
15187 -- Make sure this is always set, even in illegal programs
15189 Set_Corresponding_Discriminant (Id, Empty);
15191 -- Initialize the Original_Record_Component to the entity itself.
15192 -- Inherit_Components will propagate the right value to
15193 -- discriminants in derived record types.
15195 Set_Original_Record_Component (Id, Id);
15197 -- Create the discriminal for the discriminant
15199 Build_Discriminal (Id);
15202 Discr_Number := Discr_Number + 1;
15205 Set_Has_Discriminants (Current_Scope);
15206 end Process_Discriminants;
15208 -----------------------
15209 -- Process_Full_View --
15210 -----------------------
15212 procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id) is
15213 Priv_Parent : Entity_Id;
15214 Full_Parent : Entity_Id;
15215 Full_Indic : Node_Id;
15217 procedure Collect_Implemented_Interfaces
15219 Ifaces : Elist_Id);
15220 -- Ada 2005: Gather all the interfaces that Typ directly or
15221 -- inherently implements. Duplicate entries are not added to
15222 -- the list Ifaces.
15224 ------------------------------------
15225 -- Collect_Implemented_Interfaces --
15226 ------------------------------------
15228 procedure Collect_Implemented_Interfaces
15233 Iface_Elmt : Elmt_Id;
15236 -- Abstract interfaces are only associated with tagged record types
15238 if not Is_Tagged_Type (Typ)
15239 or else not Is_Record_Type (Typ)
15244 -- Recursively climb to the ancestors
15246 if Etype (Typ) /= Typ
15248 -- Protect the frontend against wrong cyclic declarations like:
15250 -- type B is new A with private;
15251 -- type C is new A with private;
15253 -- type B is new C with null record;
15254 -- type C is new B with null record;
15256 and then Etype (Typ) /= Priv_T
15257 and then Etype (Typ) /= Full_T
15259 -- Keep separate the management of private type declarations
15261 if Ekind (Typ) = E_Record_Type_With_Private then
15263 -- Handle the following erronous case:
15264 -- type Private_Type is tagged private;
15266 -- type Private_Type is new Type_Implementing_Iface;
15268 if Present (Full_View (Typ))
15269 and then Etype (Typ) /= Full_View (Typ)
15271 if Is_Interface (Etype (Typ)) then
15272 Append_Unique_Elmt (Etype (Typ), Ifaces);
15275 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15278 -- Non-private types
15281 if Is_Interface (Etype (Typ)) then
15282 Append_Unique_Elmt (Etype (Typ), Ifaces);
15285 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15289 -- Handle entities in the list of abstract interfaces
15291 if Present (Abstract_Interfaces (Typ)) then
15292 Iface_Elmt := First_Elmt (Abstract_Interfaces (Typ));
15293 while Present (Iface_Elmt) loop
15294 Iface := Node (Iface_Elmt);
15296 pragma Assert (Is_Interface (Iface));
15298 if not Contain_Interface (Iface, Ifaces) then
15299 Append_Elmt (Iface, Ifaces);
15300 Collect_Implemented_Interfaces (Iface, Ifaces);
15303 Next_Elmt (Iface_Elmt);
15306 end Collect_Implemented_Interfaces;
15308 -- Start of processing for Process_Full_View
15311 -- First some sanity checks that must be done after semantic
15312 -- decoration of the full view and thus cannot be placed with other
15313 -- similar checks in Find_Type_Name
15315 if not Is_Limited_Type (Priv_T)
15316 and then (Is_Limited_Type (Full_T)
15317 or else Is_Limited_Composite (Full_T))
15320 ("completion of nonlimited type cannot be limited", Full_T);
15321 Explain_Limited_Type (Full_T, Full_T);
15323 elsif Is_Abstract_Type (Full_T)
15324 and then not Is_Abstract_Type (Priv_T)
15327 ("completion of nonabstract type cannot be abstract", Full_T);
15329 elsif Is_Tagged_Type (Priv_T)
15330 and then Is_Limited_Type (Priv_T)
15331 and then not Is_Limited_Type (Full_T)
15333 -- If pragma CPP_Class was applied to the private declaration
15334 -- propagate the limitedness to the full-view
15336 if Is_CPP_Class (Priv_T) then
15337 Set_Is_Limited_Record (Full_T);
15339 -- GNAT allow its own definition of Limited_Controlled to disobey
15340 -- this rule in order in ease the implementation. The next test is
15341 -- safe because Root_Controlled is defined in a private system child
15343 elsif Etype (Full_T) = Full_View (RTE (RE_Root_Controlled)) then
15344 Set_Is_Limited_Composite (Full_T);
15347 ("completion of limited tagged type must be limited", Full_T);
15350 elsif Is_Generic_Type (Priv_T) then
15351 Error_Msg_N ("generic type cannot have a completion", Full_T);
15354 -- Check that ancestor interfaces of private and full views are
15355 -- consistent. We omit this check for synchronized types because
15356 -- they are performed on the corresponding record type when frozen.
15358 if Ada_Version >= Ada_05
15359 and then Is_Tagged_Type (Priv_T)
15360 and then Is_Tagged_Type (Full_T)
15361 and then not Is_Concurrent_Type (Full_T)
15365 Priv_T_Ifaces : constant Elist_Id := New_Elmt_List;
15366 Full_T_Ifaces : constant Elist_Id := New_Elmt_List;
15369 Collect_Implemented_Interfaces (Priv_T, Priv_T_Ifaces);
15370 Collect_Implemented_Interfaces (Full_T, Full_T_Ifaces);
15372 -- Ada 2005 (AI-251): The partial view shall be a descendant of
15373 -- an interface type if and only if the full type is descendant
15374 -- of the interface type (AARM 7.3 (7.3/2).
15376 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
15378 if Present (Iface) then
15379 Error_Msg_NE ("interface & not implemented by full type " &
15380 "(RM-2005 7.3 (7.3/2))", Priv_T, Iface);
15383 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
15385 if Present (Iface) then
15386 Error_Msg_NE ("interface & not implemented by partial view " &
15387 "(RM-2005 7.3 (7.3/2))", Full_T, Iface);
15392 if Is_Tagged_Type (Priv_T)
15393 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15394 and then Is_Derived_Type (Full_T)
15396 Priv_Parent := Etype (Priv_T);
15398 -- The full view of a private extension may have been transformed
15399 -- into an unconstrained derived type declaration and a subtype
15400 -- declaration (see build_derived_record_type for details).
15402 if Nkind (N) = N_Subtype_Declaration then
15403 Full_Indic := Subtype_Indication (N);
15404 Full_Parent := Etype (Base_Type (Full_T));
15406 Full_Indic := Subtype_Indication (Type_Definition (N));
15407 Full_Parent := Etype (Full_T);
15410 -- Check that the parent type of the full type is a descendant of
15411 -- the ancestor subtype given in the private extension. If either
15412 -- entity has an Etype equal to Any_Type then we had some previous
15413 -- error situation [7.3(8)].
15415 if Priv_Parent = Any_Type or else Full_Parent = Any_Type then
15418 -- Ada 2005 (AI-251): Interfaces in the full-typ can be given in
15419 -- any order. Therefore we don't have to check that its parent must
15420 -- be a descendant of the parent of the private type declaration.
15422 elsif Is_Interface (Priv_Parent)
15423 and then Is_Interface (Full_Parent)
15427 -- Ada 2005 (AI-251): If the parent of the private type declaration
15428 -- is an interface there is no need to check that it is an ancestor
15429 -- of the associated full type declaration. The required tests for
15430 -- this case case are performed by Build_Derived_Record_Type.
15432 elsif not Is_Interface (Base_Type (Priv_Parent))
15433 and then not Is_Ancestor (Base_Type (Priv_Parent), Full_Parent)
15436 ("parent of full type must descend from parent"
15437 & " of private extension", Full_Indic);
15439 -- Check the rules of 7.3(10): if the private extension inherits
15440 -- known discriminants, then the full type must also inherit those
15441 -- discriminants from the same (ancestor) type, and the parent
15442 -- subtype of the full type must be constrained if and only if
15443 -- the ancestor subtype of the private extension is constrained.
15445 elsif No (Discriminant_Specifications (Parent (Priv_T)))
15446 and then not Has_Unknown_Discriminants (Priv_T)
15447 and then Has_Discriminants (Base_Type (Priv_Parent))
15450 Priv_Indic : constant Node_Id :=
15451 Subtype_Indication (Parent (Priv_T));
15453 Priv_Constr : constant Boolean :=
15454 Is_Constrained (Priv_Parent)
15456 Nkind (Priv_Indic) = N_Subtype_Indication
15457 or else Is_Constrained (Entity (Priv_Indic));
15459 Full_Constr : constant Boolean :=
15460 Is_Constrained (Full_Parent)
15462 Nkind (Full_Indic) = N_Subtype_Indication
15463 or else Is_Constrained (Entity (Full_Indic));
15465 Priv_Discr : Entity_Id;
15466 Full_Discr : Entity_Id;
15469 Priv_Discr := First_Discriminant (Priv_Parent);
15470 Full_Discr := First_Discriminant (Full_Parent);
15471 while Present (Priv_Discr) and then Present (Full_Discr) loop
15472 if Original_Record_Component (Priv_Discr) =
15473 Original_Record_Component (Full_Discr)
15475 Corresponding_Discriminant (Priv_Discr) =
15476 Corresponding_Discriminant (Full_Discr)
15483 Next_Discriminant (Priv_Discr);
15484 Next_Discriminant (Full_Discr);
15487 if Present (Priv_Discr) or else Present (Full_Discr) then
15489 ("full view must inherit discriminants of the parent type"
15490 & " used in the private extension", Full_Indic);
15492 elsif Priv_Constr and then not Full_Constr then
15494 ("parent subtype of full type must be constrained",
15497 elsif Full_Constr and then not Priv_Constr then
15499 ("parent subtype of full type must be unconstrained",
15504 -- Check the rules of 7.3(12): if a partial view has neither known
15505 -- or unknown discriminants, then the full type declaration shall
15506 -- define a definite subtype.
15508 elsif not Has_Unknown_Discriminants (Priv_T)
15509 and then not Has_Discriminants (Priv_T)
15510 and then not Is_Constrained (Full_T)
15513 ("full view must define a constrained type if partial view"
15514 & " has no discriminants", Full_T);
15517 -- ??????? Do we implement the following properly ?????
15518 -- If the ancestor subtype of a private extension has constrained
15519 -- discriminants, then the parent subtype of the full view shall
15520 -- impose a statically matching constraint on those discriminants
15524 -- For untagged types, verify that a type without discriminants
15525 -- is not completed with an unconstrained type.
15527 if not Is_Indefinite_Subtype (Priv_T)
15528 and then Is_Indefinite_Subtype (Full_T)
15530 Error_Msg_N ("full view of type must be definite subtype", Full_T);
15534 -- AI-419: verify that the use of "limited" is consistent
15537 Orig_Decl : constant Node_Id := Original_Node (N);
15540 if Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15541 and then not Limited_Present (Parent (Priv_T))
15542 and then not Synchronized_Present (Parent (Priv_T))
15543 and then Nkind (Orig_Decl) = N_Full_Type_Declaration
15545 (Type_Definition (Orig_Decl)) = N_Derived_Type_Definition
15546 and then Limited_Present (Type_Definition (Orig_Decl))
15549 ("full view of non-limited extension cannot be limited", N);
15553 -- Ada 2005 (AI-443): A synchronized private extension must be
15554 -- completed by a task or protected type.
15556 if Ada_Version >= Ada_05
15557 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15558 and then Synchronized_Present (Parent (Priv_T))
15559 and then not Is_Concurrent_Type (Full_T)
15561 Error_Msg_N ("full view of synchronized extension must " &
15562 "be synchronized type", N);
15565 -- Ada 2005 AI-363: if the full view has discriminants with
15566 -- defaults, it is illegal to declare constrained access subtypes
15567 -- whose designated type is the current type. This allows objects
15568 -- of the type that are declared in the heap to be unconstrained.
15570 if not Has_Unknown_Discriminants (Priv_T)
15571 and then not Has_Discriminants (Priv_T)
15572 and then Has_Discriminants (Full_T)
15574 Present (Discriminant_Default_Value (First_Discriminant (Full_T)))
15576 Set_Has_Constrained_Partial_View (Full_T);
15577 Set_Has_Constrained_Partial_View (Priv_T);
15580 -- Create a full declaration for all its subtypes recorded in
15581 -- Private_Dependents and swap them similarly to the base type. These
15582 -- are subtypes that have been define before the full declaration of
15583 -- the private type. We also swap the entry in Private_Dependents list
15584 -- so we can properly restore the private view on exit from the scope.
15587 Priv_Elmt : Elmt_Id;
15592 Priv_Elmt := First_Elmt (Private_Dependents (Priv_T));
15593 while Present (Priv_Elmt) loop
15594 Priv := Node (Priv_Elmt);
15596 if Ekind (Priv) = E_Private_Subtype
15597 or else Ekind (Priv) = E_Limited_Private_Subtype
15598 or else Ekind (Priv) = E_Record_Subtype_With_Private
15600 Full := Make_Defining_Identifier (Sloc (Priv), Chars (Priv));
15601 Set_Is_Itype (Full);
15602 Set_Parent (Full, Parent (Priv));
15603 Set_Associated_Node_For_Itype (Full, N);
15605 -- Now we need to complete the private subtype, but since the
15606 -- base type has already been swapped, we must also swap the
15607 -- subtypes (and thus, reverse the arguments in the call to
15608 -- Complete_Private_Subtype).
15610 Copy_And_Swap (Priv, Full);
15611 Complete_Private_Subtype (Full, Priv, Full_T, N);
15612 Replace_Elmt (Priv_Elmt, Full);
15615 Next_Elmt (Priv_Elmt);
15619 -- If the private view was tagged, copy the new primitive operations
15620 -- from the private view to the full view.
15622 if Is_Tagged_Type (Full_T)
15623 and then not Is_Concurrent_Type (Full_T)
15626 Priv_List : Elist_Id;
15627 Full_List : constant Elist_Id := Primitive_Operations (Full_T);
15630 D_Type : Entity_Id;
15633 if Is_Tagged_Type (Priv_T) then
15634 Priv_List := Primitive_Operations (Priv_T);
15636 P1 := First_Elmt (Priv_List);
15637 while Present (P1) loop
15640 -- Transfer explicit primitives, not those inherited from
15641 -- parent of partial view, which will be re-inherited on
15644 if Comes_From_Source (Prim) then
15645 P2 := First_Elmt (Full_List);
15646 while Present (P2) and then Node (P2) /= Prim loop
15650 -- If not found, that is a new one
15653 Append_Elmt (Prim, Full_List);
15661 -- In this case the partial view is untagged, so here we locate
15662 -- all of the earlier primitives that need to be treated as
15663 -- dispatching (those that appear between the two views). Note
15664 -- that these additional operations must all be new operations
15665 -- (any earlier operations that override inherited operations
15666 -- of the full view will already have been inserted in the
15667 -- primitives list, marked by Check_Operation_From_Private_View
15668 -- as dispatching. Note that implicit "/=" operators are
15669 -- excluded from being added to the primitives list since they
15670 -- shouldn't be treated as dispatching (tagged "/=" is handled
15673 Prim := Next_Entity (Full_T);
15674 while Present (Prim) and then Prim /= Priv_T loop
15675 if Ekind (Prim) = E_Procedure
15677 Ekind (Prim) = E_Function
15680 D_Type := Find_Dispatching_Type (Prim);
15683 and then (Chars (Prim) /= Name_Op_Ne
15684 or else Comes_From_Source (Prim))
15686 Check_Controlling_Formals (Full_T, Prim);
15688 if not Is_Dispatching_Operation (Prim) then
15689 Append_Elmt (Prim, Full_List);
15690 Set_Is_Dispatching_Operation (Prim, True);
15691 Set_DT_Position (Prim, No_Uint);
15694 elsif Is_Dispatching_Operation (Prim)
15695 and then D_Type /= Full_T
15698 -- Verify that it is not otherwise controlled by a
15699 -- formal or a return value of type T.
15701 Check_Controlling_Formals (D_Type, Prim);
15705 Next_Entity (Prim);
15709 -- For the tagged case, the two views can share the same
15710 -- Primitive Operation list and the same class wide type.
15711 -- Update attributes of the class-wide type which depend on
15712 -- the full declaration.
15714 if Is_Tagged_Type (Priv_T) then
15715 Set_Primitive_Operations (Priv_T, Full_List);
15716 Set_Class_Wide_Type
15717 (Base_Type (Full_T), Class_Wide_Type (Priv_T));
15719 Set_Has_Task (Class_Wide_Type (Priv_T), Has_Task (Full_T));
15724 -- Ada 2005 AI 161: Check preelaboratable initialization consistency
15726 if Known_To_Have_Preelab_Init (Priv_T) then
15728 -- Case where there is a pragma Preelaborable_Initialization. We
15729 -- always allow this in predefined units, which is a bit of a kludge,
15730 -- but it means we don't have to struggle to meet the requirements in
15731 -- the RM for having Preelaborable Initialization. Otherwise we
15732 -- require that the type meets the RM rules. But we can't check that
15733 -- yet, because of the rule about overriding Ininitialize, so we
15734 -- simply set a flag that will be checked at freeze time.
15736 if not In_Predefined_Unit (Full_T) then
15737 Set_Must_Have_Preelab_Init (Full_T);
15741 -- If pragma CPP_Class was applied to the private type declaration,
15742 -- propagate it now to the full type declaration.
15744 if Is_CPP_Class (Priv_T) then
15745 Set_Is_CPP_Class (Full_T);
15746 Set_Convention (Full_T, Convention_CPP);
15748 end Process_Full_View;
15750 -----------------------------------
15751 -- Process_Incomplete_Dependents --
15752 -----------------------------------
15754 procedure Process_Incomplete_Dependents
15756 Full_T : Entity_Id;
15759 Inc_Elmt : Elmt_Id;
15760 Priv_Dep : Entity_Id;
15761 New_Subt : Entity_Id;
15763 Disc_Constraint : Elist_Id;
15766 if No (Private_Dependents (Inc_T)) then
15770 -- Itypes that may be generated by the completion of an incomplete
15771 -- subtype are not used by the back-end and not attached to the tree.
15772 -- They are created only for constraint-checking purposes.
15774 Inc_Elmt := First_Elmt (Private_Dependents (Inc_T));
15775 while Present (Inc_Elmt) loop
15776 Priv_Dep := Node (Inc_Elmt);
15778 if Ekind (Priv_Dep) = E_Subprogram_Type then
15780 -- An Access_To_Subprogram type may have a return type or a
15781 -- parameter type that is incomplete. Replace with the full view.
15783 if Etype (Priv_Dep) = Inc_T then
15784 Set_Etype (Priv_Dep, Full_T);
15788 Formal : Entity_Id;
15791 Formal := First_Formal (Priv_Dep);
15792 while Present (Formal) loop
15793 if Etype (Formal) = Inc_T then
15794 Set_Etype (Formal, Full_T);
15797 Next_Formal (Formal);
15801 elsif Is_Overloadable (Priv_Dep) then
15803 -- A protected operation is never dispatching: only its
15804 -- wrapper operation (which has convention Ada) is.
15806 if Is_Tagged_Type (Full_T)
15807 and then Convention (Priv_Dep) /= Convention_Protected
15810 -- Subprogram has an access parameter whose designated type
15811 -- was incomplete. Reexamine declaration now, because it may
15812 -- be a primitive operation of the full type.
15814 Check_Operation_From_Incomplete_Type (Priv_Dep, Inc_T);
15815 Set_Is_Dispatching_Operation (Priv_Dep);
15816 Check_Controlling_Formals (Full_T, Priv_Dep);
15819 elsif Ekind (Priv_Dep) = E_Subprogram_Body then
15821 -- Can happen during processing of a body before the completion
15822 -- of a TA type. Ignore, because spec is also on dependent list.
15826 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
15827 -- corresponding subtype of the full view.
15829 elsif Ekind (Priv_Dep) = E_Incomplete_Subtype then
15830 Set_Subtype_Indication
15831 (Parent (Priv_Dep), New_Reference_To (Full_T, Sloc (Priv_Dep)));
15832 Set_Etype (Priv_Dep, Full_T);
15833 Set_Ekind (Priv_Dep, Subtype_Kind (Ekind (Full_T)));
15834 Set_Analyzed (Parent (Priv_Dep), False);
15836 -- Reanalyze the declaration, suppressing the call to
15837 -- Enter_Name to avoid duplicate names.
15839 Analyze_Subtype_Declaration
15840 (N => Parent (Priv_Dep),
15843 -- Dependent is a subtype
15846 -- We build a new subtype indication using the full view of the
15847 -- incomplete parent. The discriminant constraints have been
15848 -- elaborated already at the point of the subtype declaration.
15850 New_Subt := Create_Itype (E_Void, N);
15852 if Has_Discriminants (Full_T) then
15853 Disc_Constraint := Discriminant_Constraint (Priv_Dep);
15855 Disc_Constraint := No_Elist;
15858 Build_Discriminated_Subtype (Full_T, New_Subt, Disc_Constraint, N);
15859 Set_Full_View (Priv_Dep, New_Subt);
15862 Next_Elmt (Inc_Elmt);
15864 end Process_Incomplete_Dependents;
15866 --------------------------------
15867 -- Process_Range_Expr_In_Decl --
15868 --------------------------------
15870 procedure Process_Range_Expr_In_Decl
15873 Check_List : List_Id := Empty_List;
15874 R_Check_Off : Boolean := False)
15877 R_Checks : Check_Result;
15878 Type_Decl : Node_Id;
15879 Def_Id : Entity_Id;
15882 Analyze_And_Resolve (R, Base_Type (T));
15884 if Nkind (R) = N_Range then
15885 Lo := Low_Bound (R);
15886 Hi := High_Bound (R);
15888 -- We need to ensure validity of the bounds here, because if we
15889 -- go ahead and do the expansion, then the expanded code will get
15890 -- analyzed with range checks suppressed and we miss the check.
15892 Validity_Check_Range (R);
15894 -- If there were errors in the declaration, try and patch up some
15895 -- common mistakes in the bounds. The cases handled are literals
15896 -- which are Integer where the expected type is Real and vice versa.
15897 -- These corrections allow the compilation process to proceed further
15898 -- along since some basic assumptions of the format of the bounds
15901 if Etype (R) = Any_Type then
15903 if Nkind (Lo) = N_Integer_Literal and then Is_Real_Type (T) then
15905 Make_Real_Literal (Sloc (Lo), UR_From_Uint (Intval (Lo))));
15907 elsif Nkind (Hi) = N_Integer_Literal and then Is_Real_Type (T) then
15909 Make_Real_Literal (Sloc (Hi), UR_From_Uint (Intval (Hi))));
15911 elsif Nkind (Lo) = N_Real_Literal and then Is_Integer_Type (T) then
15913 Make_Integer_Literal (Sloc (Lo), UR_To_Uint (Realval (Lo))));
15915 elsif Nkind (Hi) = N_Real_Literal and then Is_Integer_Type (T) then
15917 Make_Integer_Literal (Sloc (Hi), UR_To_Uint (Realval (Hi))));
15924 -- If the bounds of the range have been mistakenly given as string
15925 -- literals (perhaps in place of character literals), then an error
15926 -- has already been reported, but we rewrite the string literal as a
15927 -- bound of the range's type to avoid blowups in later processing
15928 -- that looks at static values.
15930 if Nkind (Lo) = N_String_Literal then
15932 Make_Attribute_Reference (Sloc (Lo),
15933 Attribute_Name => Name_First,
15934 Prefix => New_Reference_To (T, Sloc (Lo))));
15935 Analyze_And_Resolve (Lo);
15938 if Nkind (Hi) = N_String_Literal then
15940 Make_Attribute_Reference (Sloc (Hi),
15941 Attribute_Name => Name_First,
15942 Prefix => New_Reference_To (T, Sloc (Hi))));
15943 Analyze_And_Resolve (Hi);
15946 -- If bounds aren't scalar at this point then exit, avoiding
15947 -- problems with further processing of the range in this procedure.
15949 if not Is_Scalar_Type (Etype (Lo)) then
15953 -- Resolve (actually Sem_Eval) has checked that the bounds are in
15954 -- then range of the base type. Here we check whether the bounds
15955 -- are in the range of the subtype itself. Note that if the bounds
15956 -- represent the null range the Constraint_Error exception should
15959 -- ??? The following code should be cleaned up as follows
15961 -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
15962 -- is done in the call to Range_Check (R, T); below
15964 -- 2. The use of R_Check_Off should be investigated and possibly
15965 -- removed, this would clean up things a bit.
15967 if Is_Null_Range (Lo, Hi) then
15971 -- Capture values of bounds and generate temporaries for them
15972 -- if needed, before applying checks, since checks may cause
15973 -- duplication of the expression without forcing evaluation.
15975 if Expander_Active then
15976 Force_Evaluation (Lo);
15977 Force_Evaluation (Hi);
15980 -- We use a flag here instead of suppressing checks on the
15981 -- type because the type we check against isn't necessarily
15982 -- the place where we put the check.
15984 if not R_Check_Off then
15985 R_Checks := Get_Range_Checks (R, T);
15987 -- Look up tree to find an appropriate insertion point.
15988 -- This seems really junk code, and very brittle, couldn't
15989 -- we just use an insert actions call of some kind ???
15991 Type_Decl := Parent (R);
15992 while Present (Type_Decl) and then not
15993 (Nkind_In (Type_Decl, N_Full_Type_Declaration,
15994 N_Subtype_Declaration,
15996 N_Task_Type_Declaration)
15998 Nkind_In (Type_Decl, N_Single_Task_Declaration,
15999 N_Protected_Type_Declaration,
16000 N_Single_Protected_Declaration))
16002 Type_Decl := Parent (Type_Decl);
16005 -- Why would Type_Decl not be present??? Without this test,
16006 -- short regression tests fail.
16008 if Present (Type_Decl) then
16010 -- Case of loop statement (more comments ???)
16012 if Nkind (Type_Decl) = N_Loop_Statement then
16017 Indic := Parent (R);
16018 while Present (Indic)
16019 and then Nkind (Indic) /= N_Subtype_Indication
16021 Indic := Parent (Indic);
16024 if Present (Indic) then
16025 Def_Id := Etype (Subtype_Mark (Indic));
16027 Insert_Range_Checks
16033 Do_Before => True);
16037 -- All other cases (more comments ???)
16040 Def_Id := Defining_Identifier (Type_Decl);
16042 if (Ekind (Def_Id) = E_Record_Type
16043 and then Depends_On_Discriminant (R))
16045 (Ekind (Def_Id) = E_Protected_Type
16046 and then Has_Discriminants (Def_Id))
16048 Append_Range_Checks
16049 (R_Checks, Check_List, Def_Id, Sloc (Type_Decl), R);
16052 Insert_Range_Checks
16053 (R_Checks, Type_Decl, Def_Id, Sloc (Type_Decl), R);
16061 elsif Expander_Active then
16062 Get_Index_Bounds (R, Lo, Hi);
16063 Force_Evaluation (Lo);
16064 Force_Evaluation (Hi);
16066 end Process_Range_Expr_In_Decl;
16068 --------------------------------------
16069 -- Process_Real_Range_Specification --
16070 --------------------------------------
16072 procedure Process_Real_Range_Specification (Def : Node_Id) is
16073 Spec : constant Node_Id := Real_Range_Specification (Def);
16076 Err : Boolean := False;
16078 procedure Analyze_Bound (N : Node_Id);
16079 -- Analyze and check one bound
16081 -------------------
16082 -- Analyze_Bound --
16083 -------------------
16085 procedure Analyze_Bound (N : Node_Id) is
16087 Analyze_And_Resolve (N, Any_Real);
16089 if not Is_OK_Static_Expression (N) then
16090 Flag_Non_Static_Expr
16091 ("bound in real type definition is not static!", N);
16096 -- Start of processing for Process_Real_Range_Specification
16099 if Present (Spec) then
16100 Lo := Low_Bound (Spec);
16101 Hi := High_Bound (Spec);
16102 Analyze_Bound (Lo);
16103 Analyze_Bound (Hi);
16105 -- If error, clear away junk range specification
16108 Set_Real_Range_Specification (Def, Empty);
16111 end Process_Real_Range_Specification;
16113 ---------------------
16114 -- Process_Subtype --
16115 ---------------------
16117 function Process_Subtype
16119 Related_Nod : Node_Id;
16120 Related_Id : Entity_Id := Empty;
16121 Suffix : Character := ' ') return Entity_Id
16124 Def_Id : Entity_Id;
16125 Error_Node : Node_Id;
16126 Full_View_Id : Entity_Id;
16127 Subtype_Mark_Id : Entity_Id;
16129 May_Have_Null_Exclusion : Boolean;
16131 procedure Check_Incomplete (T : Entity_Id);
16132 -- Called to verify that an incomplete type is not used prematurely
16134 ----------------------
16135 -- Check_Incomplete --
16136 ----------------------
16138 procedure Check_Incomplete (T : Entity_Id) is
16140 -- Ada 2005 (AI-412): Incomplete subtypes are legal
16142 if Ekind (Root_Type (Entity (T))) = E_Incomplete_Type
16144 not (Ada_Version >= Ada_05
16146 (Nkind (Parent (T)) = N_Subtype_Declaration
16148 (Nkind (Parent (T)) = N_Subtype_Indication
16149 and then Nkind (Parent (Parent (T))) =
16150 N_Subtype_Declaration)))
16152 Error_Msg_N ("invalid use of type before its full declaration", T);
16154 end Check_Incomplete;
16156 -- Start of processing for Process_Subtype
16159 -- Case of no constraints present
16161 if Nkind (S) /= N_Subtype_Indication then
16163 Check_Incomplete (S);
16166 -- Ada 2005 (AI-231): Static check
16168 if Ada_Version >= Ada_05
16169 and then Present (P)
16170 and then Null_Exclusion_Present (P)
16171 and then Nkind (P) /= N_Access_To_Object_Definition
16172 and then not Is_Access_Type (Entity (S))
16174 Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
16177 -- The following is ugly, can't we have a range or even a flag???
16179 May_Have_Null_Exclusion :=
16180 Nkind_In (P, N_Access_Definition,
16181 N_Access_Function_Definition,
16182 N_Access_Procedure_Definition,
16183 N_Access_To_Object_Definition,
16185 N_Component_Definition)
16187 Nkind_In (P, N_Derived_Type_Definition,
16188 N_Discriminant_Specification,
16189 N_Object_Declaration,
16190 N_Parameter_Specification,
16191 N_Subtype_Declaration);
16193 -- Create an Itype that is a duplicate of Entity (S) but with the
16194 -- null-exclusion attribute
16196 if May_Have_Null_Exclusion
16197 and then Is_Access_Type (Entity (S))
16198 and then Null_Exclusion_Present (P)
16200 -- No need to check the case of an access to object definition.
16201 -- It is correct to define double not-null pointers.
16204 -- type Not_Null_Int_Ptr is not null access Integer;
16205 -- type Acc is not null access Not_Null_Int_Ptr;
16207 and then Nkind (P) /= N_Access_To_Object_Definition
16209 if Can_Never_Be_Null (Entity (S)) then
16210 case Nkind (Related_Nod) is
16211 when N_Full_Type_Declaration =>
16212 if Nkind (Type_Definition (Related_Nod))
16213 in N_Array_Type_Definition
16217 (Component_Definition
16218 (Type_Definition (Related_Nod)));
16221 Subtype_Indication (Type_Definition (Related_Nod));
16224 when N_Subtype_Declaration =>
16225 Error_Node := Subtype_Indication (Related_Nod);
16227 when N_Object_Declaration =>
16228 Error_Node := Object_Definition (Related_Nod);
16230 when N_Component_Declaration =>
16232 Subtype_Indication (Component_Definition (Related_Nod));
16235 pragma Assert (False);
16236 Error_Node := Related_Nod;
16240 ("`NOT NULL` not allowed (& already excludes null)",
16246 Create_Null_Excluding_Itype
16248 Related_Nod => P));
16249 Set_Entity (S, Etype (S));
16254 -- Case of constraint present, so that we have an N_Subtype_Indication
16255 -- node (this node is created only if constraints are present).
16258 Find_Type (Subtype_Mark (S));
16260 if Nkind (Parent (S)) /= N_Access_To_Object_Definition
16262 (Nkind (Parent (S)) = N_Subtype_Declaration
16263 and then Is_Itype (Defining_Identifier (Parent (S))))
16265 Check_Incomplete (Subtype_Mark (S));
16269 Subtype_Mark_Id := Entity (Subtype_Mark (S));
16271 -- Explicit subtype declaration case
16273 if Nkind (P) = N_Subtype_Declaration then
16274 Def_Id := Defining_Identifier (P);
16276 -- Explicit derived type definition case
16278 elsif Nkind (P) = N_Derived_Type_Definition then
16279 Def_Id := Defining_Identifier (Parent (P));
16281 -- Implicit case, the Def_Id must be created as an implicit type.
16282 -- The one exception arises in the case of concurrent types, array
16283 -- and access types, where other subsidiary implicit types may be
16284 -- created and must appear before the main implicit type. In these
16285 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
16286 -- has not yet been called to create Def_Id.
16289 if Is_Array_Type (Subtype_Mark_Id)
16290 or else Is_Concurrent_Type (Subtype_Mark_Id)
16291 or else Is_Access_Type (Subtype_Mark_Id)
16295 -- For the other cases, we create a new unattached Itype,
16296 -- and set the indication to ensure it gets attached later.
16300 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16304 -- If the kind of constraint is invalid for this kind of type,
16305 -- then give an error, and then pretend no constraint was given.
16307 if not Is_Valid_Constraint_Kind
16308 (Ekind (Subtype_Mark_Id), Nkind (Constraint (S)))
16311 ("incorrect constraint for this kind of type", Constraint (S));
16313 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
16315 -- Set Ekind of orphan itype, to prevent cascaded errors
16317 if Present (Def_Id) then
16318 Set_Ekind (Def_Id, Ekind (Any_Type));
16321 -- Make recursive call, having got rid of the bogus constraint
16323 return Process_Subtype (S, Related_Nod, Related_Id, Suffix);
16326 -- Remaining processing depends on type
16328 case Ekind (Subtype_Mark_Id) is
16329 when Access_Kind =>
16330 Constrain_Access (Def_Id, S, Related_Nod);
16333 and then Is_Itype (Designated_Type (Def_Id))
16334 and then Nkind (Related_Nod) = N_Subtype_Declaration
16335 and then not Is_Incomplete_Type (Designated_Type (Def_Id))
16337 Build_Itype_Reference
16338 (Designated_Type (Def_Id), Related_Nod);
16342 Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix);
16344 when Decimal_Fixed_Point_Kind =>
16345 Constrain_Decimal (Def_Id, S);
16347 when Enumeration_Kind =>
16348 Constrain_Enumeration (Def_Id, S);
16350 when Ordinary_Fixed_Point_Kind =>
16351 Constrain_Ordinary_Fixed (Def_Id, S);
16354 Constrain_Float (Def_Id, S);
16356 when Integer_Kind =>
16357 Constrain_Integer (Def_Id, S);
16359 when E_Record_Type |
16362 E_Incomplete_Type =>
16363 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16365 when Private_Kind =>
16366 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16367 Set_Private_Dependents (Def_Id, New_Elmt_List);
16369 -- In case of an invalid constraint prevent further processing
16370 -- since the type constructed is missing expected fields.
16372 if Etype (Def_Id) = Any_Type then
16376 -- If the full view is that of a task with discriminants,
16377 -- we must constrain both the concurrent type and its
16378 -- corresponding record type. Otherwise we will just propagate
16379 -- the constraint to the full view, if available.
16381 if Present (Full_View (Subtype_Mark_Id))
16382 and then Has_Discriminants (Subtype_Mark_Id)
16383 and then Is_Concurrent_Type (Full_View (Subtype_Mark_Id))
16386 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16388 Set_Entity (Subtype_Mark (S), Full_View (Subtype_Mark_Id));
16389 Constrain_Concurrent (Full_View_Id, S,
16390 Related_Nod, Related_Id, Suffix);
16391 Set_Entity (Subtype_Mark (S), Subtype_Mark_Id);
16392 Set_Full_View (Def_Id, Full_View_Id);
16394 -- Introduce an explicit reference to the private subtype,
16395 -- to prevent scope anomalies in gigi if first use appears
16396 -- in a nested context, e.g. a later function body.
16397 -- Should this be generated in other contexts than a full
16398 -- type declaration?
16400 if Is_Itype (Def_Id)
16402 Nkind (Parent (P)) = N_Full_Type_Declaration
16404 Build_Itype_Reference (Def_Id, Parent (P));
16408 Prepare_Private_Subtype_Completion (Def_Id, Related_Nod);
16411 when Concurrent_Kind =>
16412 Constrain_Concurrent (Def_Id, S,
16413 Related_Nod, Related_Id, Suffix);
16416 Error_Msg_N ("invalid subtype mark in subtype indication", S);
16419 -- Size and Convention are always inherited from the base type
16421 Set_Size_Info (Def_Id, (Subtype_Mark_Id));
16422 Set_Convention (Def_Id, Convention (Subtype_Mark_Id));
16426 end Process_Subtype;
16428 ---------------------------------------
16429 -- Check_Anonymous_Access_Components --
16430 ---------------------------------------
16432 procedure Check_Anonymous_Access_Components
16433 (Typ_Decl : Node_Id;
16436 Comp_List : Node_Id)
16438 Loc : constant Source_Ptr := Sloc (Typ_Decl);
16439 Anon_Access : Entity_Id;
16442 Comp_Def : Node_Id;
16444 Type_Def : Node_Id;
16446 procedure Build_Incomplete_Type_Declaration;
16447 -- If the record type contains components that include an access to the
16448 -- current record, then create an incomplete type declaration for the
16449 -- record, to be used as the designated type of the anonymous access.
16450 -- This is done only once, and only if there is no previous partial
16451 -- view of the type.
16453 function Designates_T (Subt : Node_Id) return Boolean;
16454 -- Check whether a node designates the enclosing record type
16456 function Mentions_T (Acc_Def : Node_Id) return Boolean;
16457 -- Check whether an access definition includes a reference to
16458 -- the enclosing record type. The reference can be a subtype mark
16459 -- in the access definition itself, a 'Class attribute reference, or
16460 -- recursively a reference appearing in a parameter specification
16461 -- or result definition of an access_to_subprogram definition.
16463 --------------------------------------
16464 -- Build_Incomplete_Type_Declaration --
16465 --------------------------------------
16467 procedure Build_Incomplete_Type_Declaration is
16473 -- If there is a previous partial view, no need to create a new one
16474 -- If the partial view, given by Prev, is incomplete, If Prev is
16475 -- a private declaration, full declaration is flagged accordingly.
16477 if Prev /= Typ then
16478 if Tagged_Present (Type_Definition (Typ_Decl)) then
16479 Make_Class_Wide_Type (Prev);
16480 Set_Class_Wide_Type (Typ, Class_Wide_Type (Prev));
16481 Set_Etype (Class_Wide_Type (Typ), Typ);
16486 elsif Has_Private_Declaration (Typ) then
16489 -- If there was a previous anonymous access type, the incomplete
16490 -- type declaration will have been created already.
16492 elsif Present (Current_Entity (Typ))
16493 and then Ekind (Current_Entity (Typ)) = E_Incomplete_Type
16494 and then Full_View (Current_Entity (Typ)) = Typ
16499 Inc_T := Make_Defining_Identifier (Loc, Chars (Typ));
16500 Decl := Make_Incomplete_Type_Declaration (Loc, Inc_T);
16502 -- Type has already been inserted into the current scope.
16503 -- Remove it, and add incomplete declaration for type, so
16504 -- that subsequent anonymous access types can use it.
16505 -- The entity is unchained from the homonym list and from
16506 -- immediate visibility. After analysis, the entity in the
16507 -- incomplete declaration becomes immediately visible in the
16508 -- record declaration that follows.
16510 H := Current_Entity (Typ);
16513 Set_Name_Entity_Id (Chars (Typ), Homonym (Typ));
16516 and then Homonym (H) /= Typ
16518 H := Homonym (Typ);
16521 Set_Homonym (H, Homonym (Typ));
16524 Insert_Before (Typ_Decl, Decl);
16526 Set_Full_View (Inc_T, Typ);
16528 if (Nkind (Type_Definition (Typ_Decl)) = N_Derived_Type_Definition
16531 (Record_Extension_Part (Type_Definition (Typ_Decl))))
16532 or else Tagged_Present (Type_Definition (Typ_Decl))
16534 -- Create a common class-wide type for both views, and set
16535 -- the etype of the class-wide type to the full view.
16537 Make_Class_Wide_Type (Inc_T);
16538 Set_Class_Wide_Type (Typ, Class_Wide_Type (Inc_T));
16539 Set_Etype (Class_Wide_Type (Typ), Typ);
16542 end Build_Incomplete_Type_Declaration;
16548 function Designates_T (Subt : Node_Id) return Boolean is
16549 Type_Id : constant Name_Id := Chars (Typ);
16551 function Names_T (Nam : Node_Id) return Boolean;
16552 -- The record type has not been introduced in the current scope
16553 -- yet, so we must examine the name of the type itself, either
16554 -- an identifier T, or an expanded name of the form P.T, where
16555 -- P denotes the current scope.
16561 function Names_T (Nam : Node_Id) return Boolean is
16563 if Nkind (Nam) = N_Identifier then
16564 return Chars (Nam) = Type_Id;
16566 elsif Nkind (Nam) = N_Selected_Component then
16567 if Chars (Selector_Name (Nam)) = Type_Id then
16568 if Nkind (Prefix (Nam)) = N_Identifier then
16569 return Chars (Prefix (Nam)) = Chars (Current_Scope);
16571 elsif Nkind (Prefix (Nam)) = N_Selected_Component then
16572 return Chars (Selector_Name (Prefix (Nam))) =
16573 Chars (Current_Scope);
16587 -- Start of processing for Designates_T
16590 if Nkind (Subt) = N_Identifier then
16591 return Chars (Subt) = Type_Id;
16593 -- Reference can be through an expanded name which has not been
16594 -- analyzed yet, and which designates enclosing scopes.
16596 elsif Nkind (Subt) = N_Selected_Component then
16597 if Names_T (Subt) then
16600 -- Otherwise it must denote an entity that is already visible.
16601 -- The access definition may name a subtype of the enclosing
16602 -- type, if there is a previous incomplete declaration for it.
16605 Find_Selected_Component (Subt);
16607 Is_Entity_Name (Subt)
16608 and then Scope (Entity (Subt)) = Current_Scope
16610 (Chars (Base_Type (Entity (Subt))) = Type_Id
16612 (Is_Class_Wide_Type (Entity (Subt))
16614 Chars (Etype (Base_Type (Entity (Subt)))) =
16618 -- A reference to the current type may appear as the prefix of
16619 -- a 'Class attribute.
16621 elsif Nkind (Subt) = N_Attribute_Reference
16622 and then Attribute_Name (Subt) = Name_Class
16624 return Names_T (Prefix (Subt));
16635 function Mentions_T (Acc_Def : Node_Id) return Boolean is
16636 Param_Spec : Node_Id;
16638 Acc_Subprg : constant Node_Id :=
16639 Access_To_Subprogram_Definition (Acc_Def);
16642 if No (Acc_Subprg) then
16643 return Designates_T (Subtype_Mark (Acc_Def));
16646 -- Component is an access_to_subprogram: examine its formals,
16647 -- and result definition in the case of an access_to_function.
16649 Param_Spec := First (Parameter_Specifications (Acc_Subprg));
16650 while Present (Param_Spec) loop
16651 if Nkind (Parameter_Type (Param_Spec)) = N_Access_Definition
16652 and then Mentions_T (Parameter_Type (Param_Spec))
16656 elsif Designates_T (Parameter_Type (Param_Spec)) then
16663 if Nkind (Acc_Subprg) = N_Access_Function_Definition then
16664 if Nkind (Result_Definition (Acc_Subprg)) =
16665 N_Access_Definition
16667 return Mentions_T (Result_Definition (Acc_Subprg));
16669 return Designates_T (Result_Definition (Acc_Subprg));
16676 -- Start of processing for Check_Anonymous_Access_Components
16679 if No (Comp_List) then
16683 Comp := First (Component_Items (Comp_List));
16684 while Present (Comp) loop
16685 if Nkind (Comp) = N_Component_Declaration
16687 (Access_Definition (Component_Definition (Comp)))
16689 Mentions_T (Access_Definition (Component_Definition (Comp)))
16691 Comp_Def := Component_Definition (Comp);
16693 Access_To_Subprogram_Definition
16694 (Access_Definition (Comp_Def));
16696 Build_Incomplete_Type_Declaration;
16698 Make_Defining_Identifier (Loc,
16699 Chars => New_Internal_Name ('S'));
16701 -- Create a declaration for the anonymous access type: either
16702 -- an access_to_object or an access_to_subprogram.
16704 if Present (Acc_Def) then
16705 if Nkind (Acc_Def) = N_Access_Function_Definition then
16707 Make_Access_Function_Definition (Loc,
16708 Parameter_Specifications =>
16709 Parameter_Specifications (Acc_Def),
16710 Result_Definition => Result_Definition (Acc_Def));
16713 Make_Access_Procedure_Definition (Loc,
16714 Parameter_Specifications =>
16715 Parameter_Specifications (Acc_Def));
16720 Make_Access_To_Object_Definition (Loc,
16721 Subtype_Indication =>
16724 (Access_Definition (Comp_Def))));
16726 Set_Constant_Present
16727 (Type_Def, Constant_Present (Access_Definition (Comp_Def)));
16729 (Type_Def, All_Present (Access_Definition (Comp_Def)));
16732 Set_Null_Exclusion_Present
16734 Null_Exclusion_Present (Access_Definition (Comp_Def)));
16737 Make_Full_Type_Declaration (Loc,
16738 Defining_Identifier => Anon_Access,
16739 Type_Definition => Type_Def);
16741 Insert_Before (Typ_Decl, Decl);
16744 -- If an access to object, Preserve entity of designated type,
16745 -- for ASIS use, before rewriting the component definition.
16747 if No (Acc_Def) then
16752 Desig := Entity (Subtype_Indication (Type_Def));
16754 -- If the access definition is to the current record,
16755 -- the visible entity at this point is an incomplete
16756 -- type. Retrieve the full view to simplify ASIS queries
16758 if Ekind (Desig) = E_Incomplete_Type then
16759 Desig := Full_View (Desig);
16763 (Subtype_Mark (Access_Definition (Comp_Def)), Desig);
16768 Make_Component_Definition (Loc,
16769 Subtype_Indication =>
16770 New_Occurrence_Of (Anon_Access, Loc)));
16772 if Ekind (Designated_Type (Anon_Access)) = E_Subprogram_Type then
16773 Set_Ekind (Anon_Access, E_Anonymous_Access_Subprogram_Type);
16775 Set_Ekind (Anon_Access, E_Anonymous_Access_Type);
16778 Set_Is_Local_Anonymous_Access (Anon_Access);
16784 if Present (Variant_Part (Comp_List)) then
16788 V := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
16789 while Present (V) loop
16790 Check_Anonymous_Access_Components
16791 (Typ_Decl, Typ, Prev, Component_List (V));
16792 Next_Non_Pragma (V);
16796 end Check_Anonymous_Access_Components;
16798 --------------------------------
16799 -- Preanalyze_Spec_Expression --
16800 --------------------------------
16802 procedure Preanalyze_Spec_Expression (N : Node_Id; T : Entity_Id) is
16803 Save_In_Spec_Expression : constant Boolean := In_Spec_Expression;
16805 In_Spec_Expression := True;
16806 Preanalyze_And_Resolve (N, T);
16807 In_Spec_Expression := Save_In_Spec_Expression;
16808 end Preanalyze_Spec_Expression;
16810 -----------------------------
16811 -- Record_Type_Declaration --
16812 -----------------------------
16814 procedure Record_Type_Declaration
16819 Def : constant Node_Id := Type_Definition (N);
16820 Is_Tagged : Boolean;
16821 Tag_Comp : Entity_Id;
16824 -- These flags must be initialized before calling Process_Discriminants
16825 -- because this routine makes use of them.
16827 Set_Ekind (T, E_Record_Type);
16829 Init_Size_Align (T);
16830 Set_Abstract_Interfaces (T, No_Elist);
16831 Set_Stored_Constraint (T, No_Elist);
16835 if Ada_Version < Ada_05
16836 or else not Interface_Present (Def)
16838 -- The flag Is_Tagged_Type might have already been set by
16839 -- Find_Type_Name if it detected an error for declaration T. This
16840 -- arises in the case of private tagged types where the full view
16841 -- omits the word tagged.
16844 Tagged_Present (Def)
16845 or else (Serious_Errors_Detected > 0 and then Is_Tagged_Type (T));
16847 Set_Is_Tagged_Type (T, Is_Tagged);
16848 Set_Is_Limited_Record (T, Limited_Present (Def));
16850 -- Type is abstract if full declaration carries keyword, or if
16851 -- previous partial view did.
16853 Set_Is_Abstract_Type (T, Is_Abstract_Type (T)
16854 or else Abstract_Present (Def));
16858 Analyze_Interface_Declaration (T, Def);
16860 if Present (Discriminant_Specifications (N)) then
16862 ("interface types cannot have discriminants",
16863 Defining_Identifier
16864 (First (Discriminant_Specifications (N))));
16868 -- First pass: if there are self-referential access components,
16869 -- create the required anonymous access type declarations, and if
16870 -- need be an incomplete type declaration for T itself.
16872 Check_Anonymous_Access_Components (N, T, Prev, Component_List (Def));
16874 if Ada_Version >= Ada_05
16875 and then Present (Interface_List (Def))
16877 Check_Abstract_Interfaces (N, Def);
16880 Ifaces_List : Elist_Id;
16883 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
16884 -- already in the parents.
16886 Collect_Abstract_Interfaces
16888 Ifaces_List => Ifaces_List,
16889 Exclude_Parent_Interfaces => True);
16891 Set_Abstract_Interfaces (T, Ifaces_List);
16895 -- Records constitute a scope for the component declarations within.
16896 -- The scope is created prior to the processing of these declarations.
16897 -- Discriminants are processed first, so that they are visible when
16898 -- processing the other components. The Ekind of the record type itself
16899 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
16901 -- Enter record scope
16905 -- If an incomplete or private type declaration was already given for
16906 -- the type, then this scope already exists, and the discriminants have
16907 -- been declared within. We must verify that the full declaration
16908 -- matches the incomplete one.
16910 Check_Or_Process_Discriminants (N, T, Prev);
16912 Set_Is_Constrained (T, not Has_Discriminants (T));
16913 Set_Has_Delayed_Freeze (T, True);
16915 -- For tagged types add a manually analyzed component corresponding
16916 -- to the component _tag, the corresponding piece of tree will be
16917 -- expanded as part of the freezing actions if it is not a CPP_Class.
16921 -- Do not add the tag unless we are in expansion mode
16923 if Expander_Active then
16924 Tag_Comp := Make_Defining_Identifier (Sloc (Def), Name_uTag);
16925 Enter_Name (Tag_Comp);
16927 Set_Ekind (Tag_Comp, E_Component);
16928 Set_Is_Tag (Tag_Comp);
16929 Set_Is_Aliased (Tag_Comp);
16930 Set_Etype (Tag_Comp, RTE (RE_Tag));
16931 Set_DT_Entry_Count (Tag_Comp, No_Uint);
16932 Set_Original_Record_Component (Tag_Comp, Tag_Comp);
16933 Init_Component_Location (Tag_Comp);
16935 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
16936 -- implemented interfaces.
16938 if Has_Abstract_Interfaces (T) then
16939 Add_Interface_Tag_Components (N, T);
16943 Make_Class_Wide_Type (T);
16944 Set_Primitive_Operations (T, New_Elmt_List);
16947 -- We must suppress range checks when processing the components
16948 -- of a record in the presence of discriminants, since we don't
16949 -- want spurious checks to be generated during their analysis, but
16950 -- must reset the Suppress_Range_Checks flags after having processed
16951 -- the record definition.
16953 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
16954 -- couldn't we just use the normal range check suppression method here.
16955 -- That would seem cleaner ???
16957 if Has_Discriminants (T) and then not Range_Checks_Suppressed (T) then
16958 Set_Kill_Range_Checks (T, True);
16959 Record_Type_Definition (Def, Prev);
16960 Set_Kill_Range_Checks (T, False);
16962 Record_Type_Definition (Def, Prev);
16965 -- Exit from record scope
16969 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
16970 -- the implemented interfaces and associate them an aliased entity.
16973 and then not Is_Empty_List (Interface_List (Def))
16976 Ifaces_List : constant Elist_Id := New_Elmt_List;
16978 Derive_Interface_Subprograms (T, T, Ifaces_List);
16981 end Record_Type_Declaration;
16983 ----------------------------
16984 -- Record_Type_Definition --
16985 ----------------------------
16987 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id) is
16988 Component : Entity_Id;
16989 Ctrl_Components : Boolean := False;
16990 Final_Storage_Only : Boolean;
16994 if Ekind (Prev_T) = E_Incomplete_Type then
16995 T := Full_View (Prev_T);
17000 Final_Storage_Only := not Is_Controlled (T);
17002 -- Ada 2005: check whether an explicit Limited is present in a derived
17003 -- type declaration.
17005 if Nkind (Parent (Def)) = N_Derived_Type_Definition
17006 and then Limited_Present (Parent (Def))
17008 Set_Is_Limited_Record (T);
17011 -- If the component list of a record type is defined by the reserved
17012 -- word null and there is no discriminant part, then the record type has
17013 -- no components and all records of the type are null records (RM 3.7)
17014 -- This procedure is also called to process the extension part of a
17015 -- record extension, in which case the current scope may have inherited
17019 or else No (Component_List (Def))
17020 or else Null_Present (Component_List (Def))
17025 Analyze_Declarations (Component_Items (Component_List (Def)));
17027 if Present (Variant_Part (Component_List (Def))) then
17028 Analyze (Variant_Part (Component_List (Def)));
17032 -- After completing the semantic analysis of the record definition,
17033 -- record components, both new and inherited, are accessible. Set their
17034 -- kind accordingly. Exclude malformed itypes from illegal declarations,
17035 -- whose Ekind may be void.
17037 Component := First_Entity (Current_Scope);
17038 while Present (Component) loop
17039 if Ekind (Component) = E_Void
17040 and then not Is_Itype (Component)
17042 Set_Ekind (Component, E_Component);
17043 Init_Component_Location (Component);
17046 if Has_Task (Etype (Component)) then
17050 if Ekind (Component) /= E_Component then
17053 elsif Has_Controlled_Component (Etype (Component))
17054 or else (Chars (Component) /= Name_uParent
17055 and then Is_Controlled (Etype (Component)))
17057 Set_Has_Controlled_Component (T, True);
17058 Final_Storage_Only := Final_Storage_Only
17059 and then Finalize_Storage_Only (Etype (Component));
17060 Ctrl_Components := True;
17063 Next_Entity (Component);
17066 -- A Type is Finalize_Storage_Only only if all its controlled components
17069 if Ctrl_Components then
17070 Set_Finalize_Storage_Only (T, Final_Storage_Only);
17073 -- Place reference to end record on the proper entity, which may
17074 -- be a partial view.
17076 if Present (Def) then
17077 Process_End_Label (Def, 'e', Prev_T);
17079 end Record_Type_Definition;
17081 ------------------------
17082 -- Replace_Components --
17083 ------------------------
17085 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id) is
17086 function Process (N : Node_Id) return Traverse_Result;
17092 function Process (N : Node_Id) return Traverse_Result is
17096 if Nkind (N) = N_Discriminant_Specification then
17097 Comp := First_Discriminant (Typ);
17098 while Present (Comp) loop
17099 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17100 Set_Defining_Identifier (N, Comp);
17104 Next_Discriminant (Comp);
17107 elsif Nkind (N) = N_Component_Declaration then
17108 Comp := First_Component (Typ);
17109 while Present (Comp) loop
17110 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17111 Set_Defining_Identifier (N, Comp);
17115 Next_Component (Comp);
17122 procedure Replace is new Traverse_Proc (Process);
17124 -- Start of processing for Replace_Components
17128 end Replace_Components;
17130 -------------------------------
17131 -- Set_Completion_Referenced --
17132 -------------------------------
17134 procedure Set_Completion_Referenced (E : Entity_Id) is
17136 -- If in main unit, mark entity that is a completion as referenced,
17137 -- warnings go on the partial view when needed.
17139 if In_Extended_Main_Source_Unit (E) then
17140 Set_Referenced (E);
17142 end Set_Completion_Referenced;
17144 ---------------------
17145 -- Set_Fixed_Range --
17146 ---------------------
17148 -- The range for fixed-point types is complicated by the fact that we
17149 -- do not know the exact end points at the time of the declaration. This
17150 -- is true for three reasons:
17152 -- A size clause may affect the fudging of the end-points
17153 -- A small clause may affect the values of the end-points
17154 -- We try to include the end-points if it does not affect the size
17156 -- This means that the actual end-points must be established at the point
17157 -- when the type is frozen. Meanwhile, we first narrow the range as
17158 -- permitted (so that it will fit if necessary in a small specified size),
17159 -- and then build a range subtree with these narrowed bounds.
17161 -- Set_Fixed_Range constructs the range from real literal values, and sets
17162 -- the range as the Scalar_Range of the given fixed-point type entity.
17164 -- The parent of this range is set to point to the entity so that it is
17165 -- properly hooked into the tree (unlike normal Scalar_Range entries for
17166 -- other scalar types, which are just pointers to the range in the
17167 -- original tree, this would otherwise be an orphan).
17169 -- The tree is left unanalyzed. When the type is frozen, the processing
17170 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
17171 -- analyzed, and uses this as an indication that it should complete
17172 -- work on the range (it will know the final small and size values).
17174 procedure Set_Fixed_Range
17180 S : constant Node_Id :=
17182 Low_Bound => Make_Real_Literal (Loc, Lo),
17183 High_Bound => Make_Real_Literal (Loc, Hi));
17185 Set_Scalar_Range (E, S);
17187 end Set_Fixed_Range;
17189 ----------------------------------
17190 -- Set_Scalar_Range_For_Subtype --
17191 ----------------------------------
17193 procedure Set_Scalar_Range_For_Subtype
17194 (Def_Id : Entity_Id;
17198 Kind : constant Entity_Kind := Ekind (Def_Id);
17201 Set_Scalar_Range (Def_Id, R);
17203 -- We need to link the range into the tree before resolving it so
17204 -- that types that are referenced, including importantly the subtype
17205 -- itself, are properly frozen (Freeze_Expression requires that the
17206 -- expression be properly linked into the tree). Of course if it is
17207 -- already linked in, then we do not disturb the current link.
17209 if No (Parent (R)) then
17210 Set_Parent (R, Def_Id);
17213 -- Reset the kind of the subtype during analysis of the range, to
17214 -- catch possible premature use in the bounds themselves.
17216 Set_Ekind (Def_Id, E_Void);
17217 Process_Range_Expr_In_Decl (R, Subt);
17218 Set_Ekind (Def_Id, Kind);
17219 end Set_Scalar_Range_For_Subtype;
17221 --------------------------------------------------------
17222 -- Set_Stored_Constraint_From_Discriminant_Constraint --
17223 --------------------------------------------------------
17225 procedure Set_Stored_Constraint_From_Discriminant_Constraint
17229 -- Make sure set if encountered during Expand_To_Stored_Constraint
17231 Set_Stored_Constraint (E, No_Elist);
17233 -- Give it the right value
17235 if Is_Constrained (E) and then Has_Discriminants (E) then
17236 Set_Stored_Constraint (E,
17237 Expand_To_Stored_Constraint (E, Discriminant_Constraint (E)));
17239 end Set_Stored_Constraint_From_Discriminant_Constraint;
17241 -------------------------------------
17242 -- Signed_Integer_Type_Declaration --
17243 -------------------------------------
17245 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id) is
17246 Implicit_Base : Entity_Id;
17247 Base_Typ : Entity_Id;
17250 Errs : Boolean := False;
17254 function Can_Derive_From (E : Entity_Id) return Boolean;
17255 -- Determine whether given bounds allow derivation from specified type
17257 procedure Check_Bound (Expr : Node_Id);
17258 -- Check bound to make sure it is integral and static. If not, post
17259 -- appropriate error message and set Errs flag
17261 ---------------------
17262 -- Can_Derive_From --
17263 ---------------------
17265 -- Note we check both bounds against both end values, to deal with
17266 -- strange types like ones with a range of 0 .. -12341234.
17268 function Can_Derive_From (E : Entity_Id) return Boolean is
17269 Lo : constant Uint := Expr_Value (Type_Low_Bound (E));
17270 Hi : constant Uint := Expr_Value (Type_High_Bound (E));
17272 return Lo <= Lo_Val and then Lo_Val <= Hi
17274 Lo <= Hi_Val and then Hi_Val <= Hi;
17275 end Can_Derive_From;
17281 procedure Check_Bound (Expr : Node_Id) is
17283 -- If a range constraint is used as an integer type definition, each
17284 -- bound of the range must be defined by a static expression of some
17285 -- integer type, but the two bounds need not have the same integer
17286 -- type (Negative bounds are allowed.) (RM 3.5.4)
17288 if not Is_Integer_Type (Etype (Expr)) then
17290 ("integer type definition bounds must be of integer type", Expr);
17293 elsif not Is_OK_Static_Expression (Expr) then
17294 Flag_Non_Static_Expr
17295 ("non-static expression used for integer type bound!", Expr);
17298 -- The bounds are folded into literals, and we set their type to be
17299 -- universal, to avoid typing difficulties: we cannot set the type
17300 -- of the literal to the new type, because this would be a forward
17301 -- reference for the back end, and if the original type is user-
17302 -- defined this can lead to spurious semantic errors (e.g. 2928-003).
17305 if Is_Entity_Name (Expr) then
17306 Fold_Uint (Expr, Expr_Value (Expr), True);
17309 Set_Etype (Expr, Universal_Integer);
17313 -- Start of processing for Signed_Integer_Type_Declaration
17316 -- Create an anonymous base type
17319 Create_Itype (E_Signed_Integer_Type, Parent (Def), T, 'B');
17321 -- Analyze and check the bounds, they can be of any integer type
17323 Lo := Low_Bound (Def);
17324 Hi := High_Bound (Def);
17326 -- Arbitrarily use Integer as the type if either bound had an error
17328 if Hi = Error or else Lo = Error then
17329 Base_Typ := Any_Integer;
17330 Set_Error_Posted (T, True);
17332 -- Here both bounds are OK expressions
17335 Analyze_And_Resolve (Lo, Any_Integer);
17336 Analyze_And_Resolve (Hi, Any_Integer);
17342 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17343 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17346 -- Find type to derive from
17348 Lo_Val := Expr_Value (Lo);
17349 Hi_Val := Expr_Value (Hi);
17351 if Can_Derive_From (Standard_Short_Short_Integer) then
17352 Base_Typ := Base_Type (Standard_Short_Short_Integer);
17354 elsif Can_Derive_From (Standard_Short_Integer) then
17355 Base_Typ := Base_Type (Standard_Short_Integer);
17357 elsif Can_Derive_From (Standard_Integer) then
17358 Base_Typ := Base_Type (Standard_Integer);
17360 elsif Can_Derive_From (Standard_Long_Integer) then
17361 Base_Typ := Base_Type (Standard_Long_Integer);
17363 elsif Can_Derive_From (Standard_Long_Long_Integer) then
17364 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17367 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17368 Error_Msg_N ("integer type definition bounds out of range", Def);
17369 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17370 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17374 -- Complete both implicit base and declared first subtype entities
17376 Set_Etype (Implicit_Base, Base_Typ);
17377 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
17378 Set_Size_Info (Implicit_Base, (Base_Typ));
17379 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
17380 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
17382 Set_Ekind (T, E_Signed_Integer_Subtype);
17383 Set_Etype (T, Implicit_Base);
17385 Set_Size_Info (T, (Implicit_Base));
17386 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
17387 Set_Scalar_Range (T, Def);
17388 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
17389 Set_Is_Constrained (T);
17390 end Signed_Integer_Type_Declaration;