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_Ch9; use Exp_Ch9;
35 with Exp_Disp; use Exp_Disp;
36 with Exp_Dist; use Exp_Dist;
37 with Exp_Tss; use Exp_Tss;
38 with Exp_Util; use Exp_Util;
39 with Fname; use Fname;
40 with Freeze; use Freeze;
41 with Itypes; use Itypes;
42 with Layout; use Layout;
44 with Lib.Xref; use Lib.Xref;
45 with Namet; use Namet;
46 with Nmake; use Nmake;
48 with Restrict; use Restrict;
49 with Rident; use Rident;
50 with Rtsfind; use Rtsfind;
52 with Sem_Case; use Sem_Case;
53 with Sem_Cat; use Sem_Cat;
54 with Sem_Ch6; use Sem_Ch6;
55 with Sem_Ch7; use Sem_Ch7;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_Ch13; use Sem_Ch13;
58 with Sem_Disp; use Sem_Disp;
59 with Sem_Dist; use Sem_Dist;
60 with Sem_Elim; use Sem_Elim;
61 with Sem_Eval; use Sem_Eval;
62 with Sem_Mech; use Sem_Mech;
63 with Sem_Res; use Sem_Res;
64 with Sem_Smem; use Sem_Smem;
65 with Sem_Type; use Sem_Type;
66 with Sem_Util; use Sem_Util;
67 with Sem_Warn; use Sem_Warn;
68 with Stand; use Stand;
69 with Sinfo; use Sinfo;
70 with Snames; use Snames;
71 with Targparm; use Targparm;
72 with Tbuild; use Tbuild;
73 with Ttypes; use Ttypes;
74 with Uintp; use Uintp;
75 with Urealp; use Urealp;
77 package body Sem_Ch3 is
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id);
84 -- Ada 2005 (AI-251): Add the tag components corresponding to all the
85 -- abstract interface types implemented by a record type or a derived
88 procedure Build_Derived_Type
90 Parent_Type : Entity_Id;
91 Derived_Type : Entity_Id;
92 Is_Completion : Boolean;
93 Derive_Subps : Boolean := True);
94 -- Create and decorate a Derived_Type given the Parent_Type entity. N is
95 -- the N_Full_Type_Declaration node containing the derived type definition.
96 -- Parent_Type is the entity for the parent type in the derived type
97 -- definition and Derived_Type the actual derived type. Is_Completion must
98 -- be set to False if Derived_Type is the N_Defining_Identifier node in N
99 -- (i.e. Derived_Type = Defining_Identifier (N)). In this case N is not the
100 -- completion of a private type declaration. If Is_Completion is set to
101 -- True, N is the completion of a private type declaration and Derived_Type
102 -- is different from the defining identifier inside N (i.e. Derived_Type /=
103 -- Defining_Identifier (N)). Derive_Subps indicates whether the parent
104 -- subprograms should be derived. The only case where this parameter is
105 -- False is when Build_Derived_Type is recursively called to process an
106 -- implicit derived full type for a type derived from a private type (in
107 -- that case the subprograms must only be derived for the private view of
110 -- ??? These flags need a bit of re-examination and re-documentation:
111 -- ??? are they both necessary (both seem related to the recursion)?
113 procedure Build_Derived_Access_Type
115 Parent_Type : Entity_Id;
116 Derived_Type : Entity_Id);
117 -- Subsidiary procedure to Build_Derived_Type. For a derived access type,
118 -- create an implicit base if the parent type is constrained or if the
119 -- subtype indication has a constraint.
121 procedure Build_Derived_Array_Type
123 Parent_Type : Entity_Id;
124 Derived_Type : Entity_Id);
125 -- Subsidiary procedure to Build_Derived_Type. For a derived array type,
126 -- create an implicit base if the parent type is constrained or if the
127 -- subtype indication has a constraint.
129 procedure Build_Derived_Concurrent_Type
131 Parent_Type : Entity_Id;
132 Derived_Type : Entity_Id);
133 -- Subsidiary procedure to Build_Derived_Type. For a derived task or
134 -- protected type, inherit entries and protected subprograms, check
135 -- legality of discriminant constraints if any.
137 procedure Build_Derived_Enumeration_Type
139 Parent_Type : Entity_Id;
140 Derived_Type : Entity_Id);
141 -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
142 -- type, we must create a new list of literals. Types derived from
143 -- Character and Wide_Character are special-cased.
145 procedure Build_Derived_Numeric_Type
147 Parent_Type : Entity_Id;
148 Derived_Type : Entity_Id);
149 -- Subsidiary procedure to Build_Derived_Type. For numeric types, create
150 -- an anonymous base type, and propagate constraint to subtype if needed.
152 procedure Build_Derived_Private_Type
154 Parent_Type : Entity_Id;
155 Derived_Type : Entity_Id;
156 Is_Completion : Boolean;
157 Derive_Subps : Boolean := True);
158 -- Subsidiary procedure to Build_Derived_Type. This procedure is complex
159 -- because the parent may or may not have a completion, and the derivation
160 -- may itself be a completion.
162 procedure Build_Derived_Record_Type
164 Parent_Type : Entity_Id;
165 Derived_Type : Entity_Id;
166 Derive_Subps : Boolean := True);
167 -- Subsidiary procedure for Build_Derived_Type and
168 -- Analyze_Private_Extension_Declaration used for tagged and untagged
169 -- record types. All parameters are as in Build_Derived_Type except that
170 -- N, in addition to being an N_Full_Type_Declaration node, can also be an
171 -- N_Private_Extension_Declaration node. See the definition of this routine
172 -- for much more info. Derive_Subps indicates whether subprograms should
173 -- be derived from the parent type. The only case where Derive_Subps is
174 -- False is for an implicit derived full type for a type derived from a
175 -- private type (see Build_Derived_Type).
177 procedure Build_Discriminal (Discrim : Entity_Id);
178 -- Create the discriminal corresponding to discriminant Discrim, that is
179 -- the parameter corresponding to Discrim to be used in initialization
180 -- procedures for the type where Discrim is a discriminant. Discriminals
181 -- are not used during semantic analysis, and are not fully defined
182 -- entities until expansion. Thus they are not given a scope until
183 -- initialization procedures are built.
185 function Build_Discriminant_Constraints
188 Derived_Def : Boolean := False) return Elist_Id;
189 -- Validate discriminant constraints and return the list of the constraints
190 -- in order of discriminant declarations, where T is the discriminated
191 -- unconstrained type. Def is the N_Subtype_Indication node where the
192 -- discriminants constraints for T are specified. Derived_Def is True
193 -- when building the discriminant constraints in a derived type definition
194 -- of the form "type D (...) is new T (xxx)". In this case T is the parent
195 -- type and Def is the constraint "(xxx)" on T and this routine sets the
196 -- Corresponding_Discriminant field of the discriminants in the derived
197 -- type D to point to the corresponding discriminants in the parent type T.
199 procedure Build_Discriminated_Subtype
203 Related_Nod : Node_Id;
204 For_Access : Boolean := False);
205 -- Subsidiary procedure to Constrain_Discriminated_Type and to
206 -- Process_Incomplete_Dependents. Given
208 -- T (a possibly discriminated base type)
209 -- Def_Id (a very partially built subtype for T),
211 -- the call completes Def_Id to be the appropriate E_*_Subtype.
213 -- The Elist is the list of discriminant constraints if any (it is set
214 -- to No_Elist if T is not a discriminated type, and to an empty list if
215 -- T has discriminants but there are no discriminant constraints). The
216 -- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
217 -- The For_Access says whether or not this subtype is really constraining
218 -- an access type. That is its sole purpose is the designated type of an
219 -- access type -- in which case a Private_Subtype Is_For_Access_Subtype
220 -- is built to avoid freezing T when the access subtype is frozen.
222 function Build_Scalar_Bound
225 Der_T : Entity_Id) return Node_Id;
226 -- The bounds of a derived scalar type are conversions of the bounds of
227 -- the parent type. Optimize the representation if the bounds are literals.
228 -- Needs a more complete spec--what are the parameters exactly, and what
229 -- exactly is the returned value, and how is Bound affected???
231 procedure Build_Itype_Reference
234 -- Create a reference to an internal type, for use by Gigi. The back-end
235 -- elaborates itypes on demand, i.e. when their first use is seen. This
236 -- can lead to scope anomalies if the first use is within a scope that is
237 -- nested within the scope that contains the point of definition of the
238 -- itype. The Itype_Reference node forces the elaboration of the itype
239 -- in the proper scope. The node is inserted after Nod, which is the
240 -- enclosing declaration that generated Ityp.
242 -- A related mechanism is used during expansion, for itypes created in
243 -- branches of conditionals. See Ensure_Defined in exp_util.
244 -- Could both mechanisms be merged ???
246 procedure Build_Underlying_Full_View
250 -- If the completion of a private type is itself derived from a private
251 -- type, or if the full view of a private subtype is itself private, the
252 -- back-end has no way to compute the actual size of this type. We build
253 -- an internal subtype declaration of the proper parent type to convey
254 -- this information. This extra mechanism is needed because a full
255 -- view cannot itself have a full view (it would get clobbered during
258 procedure Check_Access_Discriminant_Requires_Limited
261 -- Check the restriction that the type to which an access discriminant
262 -- belongs must be a concurrent type or a descendant of a type with
263 -- the reserved word 'limited' in its declaration.
265 procedure Check_Anonymous_Access_Components
269 Comp_List : Node_Id);
270 -- Ada 2005 AI-382: an access component in a record definition can refer to
271 -- the enclosing record, in which case it denotes the type itself, and not
272 -- the current instance of the type. We create an anonymous access type for
273 -- the component, and flag it as an access to a component, so accessibility
274 -- checks are properly performed on it. The declaration of the access type
275 -- is placed ahead of that of the record to prevent order-of-elaboration
276 -- circularity issues in Gigi. We create an incomplete type for the record
277 -- declaration, which is the designated type of the anonymous access.
279 procedure Check_Delta_Expression (E : Node_Id);
280 -- Check that the expression represented by E is suitable for use as a
281 -- delta expression, i.e. it is of real type and is static.
283 procedure Check_Digits_Expression (E : Node_Id);
284 -- Check that the expression represented by E is suitable for use as a
285 -- digits expression, i.e. it is of integer type, positive and static.
287 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id);
288 -- Validate the initialization of an object declaration. T is the required
289 -- type, and Exp is the initialization expression.
291 procedure Check_Interfaces (N : Node_Id; Def : Node_Id);
292 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
294 procedure Check_Or_Process_Discriminants
297 Prev : Entity_Id := Empty);
298 -- If T is the full declaration of an incomplete or private type, check the
299 -- conformance of the discriminants, otherwise process them. Prev is the
300 -- entity of the partial declaration, if any.
302 procedure Check_Real_Bound (Bound : Node_Id);
303 -- Check given bound for being of real type and static. If not, post an
304 -- appropriate message, and rewrite the bound with the real literal zero.
306 procedure Constant_Redeclaration
310 -- Various checks on legality of full declaration of deferred constant.
311 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
312 -- node. The caller has not yet set any attributes of this entity.
314 function Contain_Interface
316 Ifaces : Elist_Id) return Boolean;
317 -- Ada 2005: Determine whether Iface is present in the list Ifaces
319 procedure Convert_Scalar_Bounds
321 Parent_Type : Entity_Id;
322 Derived_Type : Entity_Id;
324 -- For derived scalar types, convert the bounds in the type definition to
325 -- the derived type, and complete their analysis. Given a constraint of the
326 -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with
327 -- T'Base, the parent_type. The bounds of the derived type (the anonymous
328 -- base) are copies of Lo and Hi. Finally, the bounds of the derived
329 -- subtype are conversions of those bounds to the derived_type, so that
330 -- their typing is consistent.
332 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id);
333 -- Copies attributes from array base type T2 to array base type T1. Copies
334 -- only attributes that apply to base types, but not subtypes.
336 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id);
337 -- Copies attributes from array subtype T2 to array subtype T1. Copies
338 -- attributes that apply to both subtypes and base types.
340 procedure Create_Constrained_Components
344 Constraints : Elist_Id);
345 -- Build the list of entities for a constrained discriminated record
346 -- subtype. If a component depends on a discriminant, replace its subtype
347 -- using the discriminant values in the discriminant constraint. Subt
348 -- is the defining identifier for the subtype whose list of constrained
349 -- entities we will create. Decl_Node is the type declaration node where
350 -- we will attach all the itypes created. Typ is the base discriminated
351 -- type for the subtype Subt. Constraints is the list of discriminant
352 -- constraints for Typ.
354 function Constrain_Component_Type
356 Constrained_Typ : Entity_Id;
357 Related_Node : Node_Id;
359 Constraints : Elist_Id) return Entity_Id;
360 -- Given a discriminated base type Typ, a list of discriminant constraint
361 -- Constraints for Typ and a component of Typ, with type Compon_Type,
362 -- create and return the type corresponding to Compon_type where all
363 -- discriminant references are replaced with the corresponding constraint.
364 -- If no discriminant references occur in Compon_Typ then return it as is.
365 -- Constrained_Typ is the final constrained subtype to which the
366 -- constrained Compon_Type belongs. Related_Node is the node where we will
367 -- attach all the itypes created.
369 -- Above description is confused, what is Compon_Type???
371 procedure Constrain_Access
372 (Def_Id : in out Entity_Id;
374 Related_Nod : Node_Id);
375 -- Apply a list of constraints to an access type. If Def_Id is empty, it is
376 -- an anonymous type created for a subtype indication. In that case it is
377 -- created in the procedure and attached to Related_Nod.
379 procedure Constrain_Array
380 (Def_Id : in out Entity_Id;
382 Related_Nod : Node_Id;
383 Related_Id : Entity_Id;
385 -- Apply a list of index constraints to an unconstrained array type. The
386 -- first parameter is the entity for the resulting subtype. A value of
387 -- Empty for Def_Id indicates that an implicit type must be created, but
388 -- creation is delayed (and must be done by this procedure) because other
389 -- subsidiary implicit types must be created first (which is why Def_Id
390 -- is an in/out parameter). The second parameter is a subtype indication
391 -- node for the constrained array to be created (e.g. something of the
392 -- form string (1 .. 10)). Related_Nod gives the place where this type
393 -- has to be inserted in the tree. The Related_Id and Suffix parameters
394 -- are used to build the associated Implicit type name.
396 procedure Constrain_Concurrent
397 (Def_Id : in out Entity_Id;
399 Related_Nod : Node_Id;
400 Related_Id : Entity_Id;
402 -- Apply list of discriminant constraints to an unconstrained concurrent
405 -- SI is the N_Subtype_Indication node containing the constraint and
406 -- the unconstrained type to constrain.
408 -- Def_Id is the entity for the resulting constrained subtype. A value
409 -- of Empty for Def_Id indicates that an implicit type must be created,
410 -- but creation is delayed (and must be done by this procedure) because
411 -- other subsidiary implicit types must be created first (which is why
412 -- Def_Id is an in/out parameter).
414 -- Related_Nod gives the place where this type has to be inserted
417 -- The last two arguments are used to create its external name if needed.
419 function Constrain_Corresponding_Record
420 (Prot_Subt : Entity_Id;
421 Corr_Rec : Entity_Id;
422 Related_Nod : Node_Id;
423 Related_Id : Entity_Id) return Entity_Id;
424 -- When constraining a protected type or task type with discriminants,
425 -- constrain the corresponding record with the same discriminant values.
427 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id);
428 -- Constrain a decimal fixed point type with a digits constraint and/or a
429 -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
431 procedure Constrain_Discriminated_Type
434 Related_Nod : Node_Id;
435 For_Access : Boolean := False);
436 -- Process discriminant constraints of composite type. Verify that values
437 -- have been provided for all discriminants, that the original type is
438 -- unconstrained, and that the types of the supplied expressions match
439 -- the discriminant types. The first three parameters are like in routine
440 -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
443 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id);
444 -- Constrain an enumeration type with a range constraint. This is identical
445 -- to Constrain_Integer, but for the Ekind of the resulting subtype.
447 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id);
448 -- Constrain a floating point type with either a digits constraint
449 -- and/or a range constraint, building a E_Floating_Point_Subtype.
451 procedure Constrain_Index
454 Related_Nod : Node_Id;
455 Related_Id : Entity_Id;
458 -- Process an index constraint in a constrained array declaration. The
459 -- constraint can be a subtype name, or a range with or without an explicit
460 -- subtype mark. The index is the corresponding index of the unconstrained
461 -- array. The Related_Id and Suffix parameters are used to build the
462 -- associated Implicit type name.
464 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id);
465 -- Build subtype of a signed or modular integer type
467 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id);
468 -- Constrain an ordinary fixed point type with a range constraint, and
469 -- build an E_Ordinary_Fixed_Point_Subtype entity.
471 procedure Copy_And_Swap (Priv, Full : Entity_Id);
472 -- Copy the Priv entity into the entity of its full declaration then swap
473 -- the two entities in such a manner that the former private type is now
474 -- seen as a full type.
476 procedure Decimal_Fixed_Point_Type_Declaration
479 -- Create a new decimal fixed point type, and apply the constraint to
480 -- obtain a subtype of this new type.
482 procedure Complete_Private_Subtype
485 Full_Base : Entity_Id;
486 Related_Nod : Node_Id);
487 -- Complete the implicit full view of a private subtype by setting the
488 -- appropriate semantic fields. If the full view of the parent is a record
489 -- type, build constrained components of subtype.
491 procedure Derive_Progenitor_Subprograms
492 (Parent_Type : Entity_Id;
493 Tagged_Type : Entity_Id);
494 -- Ada 2005 (AI-251): To complete type derivation, collect the primitive
495 -- operations of progenitors of Tagged_Type, and replace the subsidiary
496 -- subtypes with Tagged_Type, to build the specs of the inherited interface
497 -- primitives. The derived primitives are aliased to those of the
498 -- interface. This routine takes care also of transferring to the full-view
499 -- subprograms associated with the partial-view of Tagged_Type that cover
500 -- interface primitives.
502 procedure Derived_Standard_Character
504 Parent_Type : Entity_Id;
505 Derived_Type : Entity_Id);
506 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
507 -- derivations from types Standard.Character and Standard.Wide_Character.
509 procedure Derived_Type_Declaration
512 Is_Completion : Boolean);
513 -- Process a derived type declaration. Build_Derived_Type is invoked
514 -- to process the actual derived type definition. Parameters N and
515 -- Is_Completion have the same meaning as in Build_Derived_Type.
516 -- T is the N_Defining_Identifier for the entity defined in the
517 -- N_Full_Type_Declaration node N, that is T is the derived type.
519 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id);
520 -- Insert each literal in symbol table, as an overloadable identifier. Each
521 -- enumeration type is mapped into a sequence of integers, and each literal
522 -- is defined as a constant with integer value. If any of the literals are
523 -- character literals, the type is a character type, which means that
524 -- strings are legal aggregates for arrays of components of the type.
526 function Expand_To_Stored_Constraint
528 Constraint : Elist_Id) return Elist_Id;
529 -- Given a constraint (i.e. a list of expressions) on the discriminants of
530 -- Typ, expand it into a constraint on the stored discriminants and return
531 -- the new list of expressions constraining the stored discriminants.
533 function Find_Type_Of_Object
535 Related_Nod : Node_Id) return Entity_Id;
536 -- Get type entity for object referenced by Obj_Def, attaching the
537 -- implicit types generated to Related_Nod
539 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id);
540 -- Create a new float and apply the constraint to obtain subtype of it
542 function Has_Range_Constraint (N : Node_Id) return Boolean;
543 -- Given an N_Subtype_Indication node N, return True if a range constraint
544 -- is present, either directly, or as part of a digits or delta constraint.
545 -- In addition, a digits constraint in the decimal case returns True, since
546 -- it establishes a default range if no explicit range is present.
548 function Inherit_Components
550 Parent_Base : Entity_Id;
551 Derived_Base : Entity_Id;
553 Inherit_Discr : Boolean;
554 Discs : Elist_Id) return Elist_Id;
555 -- Called from Build_Derived_Record_Type to inherit the components of
556 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
557 -- For more information on derived types and component inheritance please
558 -- consult the comment above the body of Build_Derived_Record_Type.
560 -- N is the original derived type declaration
562 -- Is_Tagged is set if we are dealing with tagged types
564 -- If Inherit_Discr is set, Derived_Base inherits its discriminants from
565 -- Parent_Base, otherwise no discriminants are inherited.
567 -- Discs gives the list of constraints that apply to Parent_Base in the
568 -- derived type declaration. If Discs is set to No_Elist, then we have
569 -- the following situation:
571 -- type Parent (D1..Dn : ..) is [tagged] record ...;
572 -- type Derived is new Parent [with ...];
574 -- which gets treated as
576 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
578 -- For untagged types the returned value is an association list. The list
579 -- starts from the association (Parent_Base => Derived_Base), and then it
580 -- contains a sequence of the associations of the form
582 -- (Old_Component => New_Component),
584 -- where Old_Component is the Entity_Id of a component in Parent_Base and
585 -- New_Component is the Entity_Id of the corresponding component in
586 -- Derived_Base. For untagged records, this association list is needed when
587 -- copying the record declaration for the derived base. In the tagged case
588 -- the value returned is irrelevant.
590 function Is_Progenitor
592 Typ : Entity_Id) return Boolean;
593 -- Determine whether type Typ implements interface Iface. This requires
594 -- traversing the list of abstract interfaces of the type, as well as that
595 -- of the ancestor types. The predicate is used to determine when a formal
596 -- in the signature of an inherited operation must carry the derived type.
598 function Is_Valid_Constraint_Kind
600 Constraint_Kind : Node_Kind) return Boolean;
601 -- Returns True if it is legal to apply the given kind of constraint to the
602 -- given kind of type (index constraint to an array type, for example).
604 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id);
605 -- Create new modular type. Verify that modulus is in bounds and is
606 -- a power of two (implementation restriction).
608 procedure New_Concatenation_Op (Typ : Entity_Id);
609 -- Create an abbreviated declaration for an operator in order to
610 -- materialize concatenation on array types.
612 procedure Ordinary_Fixed_Point_Type_Declaration
615 -- Create a new ordinary fixed point type, and apply the constraint to
616 -- obtain subtype of it.
618 procedure Prepare_Private_Subtype_Completion
620 Related_Nod : Node_Id);
621 -- Id is a subtype of some private type. Creates the full declaration
622 -- associated with Id whenever possible, i.e. when the full declaration
623 -- of the base type is already known. Records each subtype into
624 -- Private_Dependents of the base type.
626 procedure Process_Incomplete_Dependents
630 -- Process all entities that depend on an incomplete type. There include
631 -- subtypes, subprogram types that mention the incomplete type in their
632 -- profiles, and subprogram with access parameters that designate the
635 -- Inc_T is the defining identifier of an incomplete type declaration, its
636 -- Ekind is E_Incomplete_Type.
638 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
640 -- Full_T is N's defining identifier.
642 -- Subtypes of incomplete types with discriminants are completed when the
643 -- parent type is. This is simpler than private subtypes, because they can
644 -- only appear in the same scope, and there is no need to exchange views.
645 -- Similarly, access_to_subprogram types may have a parameter or a return
646 -- type that is an incomplete type, and that must be replaced with the
649 -- If the full type is tagged, subprogram with access parameters that
650 -- designated the incomplete may be primitive operations of the full type,
651 -- and have to be processed accordingly.
653 procedure Process_Real_Range_Specification (Def : Node_Id);
654 -- Given the type definition for a real type, this procedure processes and
655 -- checks the real range specification of this type definition if one is
656 -- present. If errors are found, error messages are posted, and the
657 -- Real_Range_Specification of Def is reset to Empty.
659 procedure Record_Type_Declaration
663 -- Process a record type declaration (for both untagged and tagged
664 -- records). Parameters T and N are exactly like in procedure
665 -- Derived_Type_Declaration, except that no flag Is_Completion is needed
666 -- for this routine. If this is the completion of an incomplete type
667 -- declaration, Prev is the entity of the incomplete declaration, used for
668 -- cross-referencing. Otherwise Prev = T.
670 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id);
671 -- This routine is used to process the actual record type definition (both
672 -- for untagged and tagged records). Def is a record type definition node.
673 -- This procedure analyzes the components in this record type definition.
674 -- Prev_T is the entity for the enclosing record type. It is provided so
675 -- that its Has_Task flag can be set if any of the component have Has_Task
676 -- set. If the declaration is the completion of an incomplete type
677 -- declaration, Prev_T is the original incomplete type, whose full view is
680 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id);
681 -- Subsidiary to Build_Derived_Record_Type. For untagged records, we
682 -- build a copy of the declaration tree of the parent, and we create
683 -- independently the list of components for the derived type. Semantic
684 -- information uses the component entities, but record representation
685 -- clauses are validated on the declaration tree. This procedure replaces
686 -- discriminants and components in the declaration with those that have
687 -- been created by Inherit_Components.
689 procedure Set_Fixed_Range
694 -- Build a range node with the given bounds and set it as the Scalar_Range
695 -- of the given fixed-point type entity. Loc is the source location used
696 -- for the constructed range. See body for further details.
698 procedure Set_Scalar_Range_For_Subtype
702 -- This routine is used to set the scalar range field for a subtype given
703 -- Def_Id, the entity for the subtype, and R, the range expression for the
704 -- scalar range. Subt provides the parent subtype to be used to analyze,
705 -- resolve, and check the given range.
707 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id);
708 -- Create a new signed integer entity, and apply the constraint to obtain
709 -- the required first named subtype of this type.
711 procedure Set_Stored_Constraint_From_Discriminant_Constraint
713 -- E is some record type. This routine computes E's Stored_Constraint
714 -- from its Discriminant_Constraint.
716 procedure Diagnose_Interface (N : Node_Id; E : Entity_Id);
717 -- Check that an entity in a list of progenitors is an interface,
718 -- emit error otherwise.
720 -----------------------
721 -- Access_Definition --
722 -----------------------
724 function Access_Definition
725 (Related_Nod : Node_Id;
726 N : Node_Id) return Entity_Id
728 Loc : constant Source_Ptr := Sloc (Related_Nod);
729 Anon_Type : Entity_Id;
730 Anon_Scope : Entity_Id;
731 Desig_Type : Entity_Id;
735 if Is_Entry (Current_Scope)
736 and then Is_Task_Type (Etype (Scope (Current_Scope)))
738 Error_Msg_N ("task entries cannot have access parameters", N);
742 -- Ada 2005: for an object declaration the corresponding anonymous
743 -- type is declared in the current scope.
745 -- If the access definition is the return type of another access to
746 -- function, scope is the current one, because it is the one of the
747 -- current type declaration.
749 if Nkind_In (Related_Nod, N_Object_Declaration,
750 N_Access_Function_Definition)
752 Anon_Scope := Current_Scope;
754 -- For the anonymous function result case, retrieve the scope of the
755 -- function specification's associated entity rather than using the
756 -- current scope. The current scope will be the function itself if the
757 -- formal part is currently being analyzed, but will be the parent scope
758 -- in the case of a parameterless function, and we always want to use
759 -- the function's parent scope. Finally, if the function is a child
760 -- unit, we must traverse the tree to retrieve the proper entity.
762 elsif Nkind (Related_Nod) = N_Function_Specification
763 and then Nkind (Parent (N)) /= N_Parameter_Specification
765 -- If the current scope is a protected type, the anonymous access
766 -- is associated with one of the protected operations, and must
767 -- be available in the scope that encloses the protected declaration.
768 -- Otherwise the type is is in the scope enclosing the subprogram.
770 if Ekind (Current_Scope) = E_Protected_Type then
771 Anon_Scope := Scope (Scope (Defining_Entity (Related_Nod)));
773 Anon_Scope := Scope (Defining_Entity (Related_Nod));
777 -- For access formals, access components, and access discriminants,
778 -- the scope is that of the enclosing declaration,
780 Anon_Scope := Scope (Current_Scope);
785 (E_Anonymous_Access_Type, Related_Nod, Scope_Id => Anon_Scope);
788 and then Ada_Version >= Ada_05
790 Error_Msg_N ("ALL is not permitted for anonymous access types", N);
793 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
794 -- the corresponding semantic routine
796 if Present (Access_To_Subprogram_Definition (N)) then
797 Access_Subprogram_Declaration
798 (T_Name => Anon_Type,
799 T_Def => Access_To_Subprogram_Definition (N));
801 if Ekind (Anon_Type) = E_Access_Protected_Subprogram_Type then
803 (Anon_Type, E_Anonymous_Access_Protected_Subprogram_Type);
806 (Anon_Type, E_Anonymous_Access_Subprogram_Type);
809 Set_Can_Use_Internal_Rep
810 (Anon_Type, not Always_Compatible_Rep_On_Target);
812 -- If the anonymous access is associated with a protected operation
813 -- create a reference to it after the enclosing protected definition
814 -- because the itype will be used in the subsequent bodies.
816 if Ekind (Current_Scope) = E_Protected_Type then
817 Build_Itype_Reference (Anon_Type, Parent (Current_Scope));
823 Find_Type (Subtype_Mark (N));
824 Desig_Type := Entity (Subtype_Mark (N));
826 Set_Directly_Designated_Type
827 (Anon_Type, Desig_Type);
828 Set_Etype (Anon_Type, Anon_Type);
830 -- Make sure the anonymous access type has size and alignment fields
831 -- set, as required by gigi. This is necessary in the case of the
832 -- Task_Body_Procedure.
834 if not Has_Private_Component (Desig_Type) then
835 Layout_Type (Anon_Type);
838 -- ???The following makes no sense, because Anon_Type is an access type
839 -- and therefore cannot have components, private or otherwise. Hence
840 -- the assertion. Not sure what was meant, here.
841 Set_Depends_On_Private (Anon_Type, Has_Private_Component (Anon_Type));
842 pragma Assert (not Depends_On_Private (Anon_Type));
844 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
845 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
846 -- the null value is allowed. In Ada 95 the null value is never allowed.
848 if Ada_Version >= Ada_05 then
849 Set_Can_Never_Be_Null (Anon_Type, Null_Exclusion_Present (N));
851 Set_Can_Never_Be_Null (Anon_Type, True);
854 -- The anonymous access type is as public as the discriminated type or
855 -- subprogram that defines it. It is imported (for back-end purposes)
856 -- if the designated type is.
858 Set_Is_Public (Anon_Type, Is_Public (Scope (Anon_Type)));
860 -- Ada 2005 (AI-50217): Propagate the attribute that indicates that the
861 -- designated type comes from the limited view.
863 Set_From_With_Type (Anon_Type, From_With_Type (Desig_Type));
865 -- Ada 2005 (AI-231): Propagate the access-constant attribute
867 Set_Is_Access_Constant (Anon_Type, Constant_Present (N));
869 -- The context is either a subprogram declaration, object declaration,
870 -- or an access discriminant, in a private or a full type declaration.
871 -- In the case of a subprogram, if the designated type is incomplete,
872 -- the operation will be a primitive operation of the full type, to be
873 -- updated subsequently. If the type is imported through a limited_with
874 -- clause, the subprogram is not a primitive operation of the type
875 -- (which is declared elsewhere in some other scope).
877 if Ekind (Desig_Type) = E_Incomplete_Type
878 and then not From_With_Type (Desig_Type)
879 and then Is_Overloadable (Current_Scope)
881 Append_Elmt (Current_Scope, Private_Dependents (Desig_Type));
882 Set_Has_Delayed_Freeze (Current_Scope);
885 -- Ada 2005: if the designated type is an interface that may contain
886 -- tasks, create a Master entity for the declaration. This must be done
887 -- before expansion of the full declaration, because the declaration may
888 -- include an expression that is an allocator, whose expansion needs the
889 -- proper Master for the created tasks.
891 if Nkind (Related_Nod) = N_Object_Declaration
892 and then Expander_Active
894 if Is_Interface (Desig_Type)
895 and then Is_Limited_Record (Desig_Type)
897 Build_Class_Wide_Master (Anon_Type);
899 -- Similarly, if the type is an anonymous access that designates
900 -- tasks, create a master entity for it in the current context.
902 elsif Has_Task (Desig_Type)
903 and then Comes_From_Source (Related_Nod)
905 if not Has_Master_Entity (Current_Scope) then
907 Make_Object_Declaration (Loc,
908 Defining_Identifier =>
909 Make_Defining_Identifier (Loc, Name_uMaster),
910 Constant_Present => True,
912 New_Reference_To (RTE (RE_Master_Id), Loc),
914 Make_Explicit_Dereference (Loc,
915 New_Reference_To (RTE (RE_Current_Master), Loc)));
917 Insert_Before (Related_Nod, Decl);
920 Set_Master_Id (Anon_Type, Defining_Identifier (Decl));
921 Set_Has_Master_Entity (Current_Scope);
923 Build_Master_Renaming (Related_Nod, Anon_Type);
928 -- For a private component of a protected type, it is imperative that
929 -- the back-end elaborate the type immediately after the protected
930 -- declaration, because this type will be used in the declarations
931 -- created for the component within each protected body, so we must
932 -- create an itype reference for it now.
934 if Nkind (Parent (Related_Nod)) = N_Protected_Definition then
935 Build_Itype_Reference (Anon_Type, Parent (Parent (Related_Nod)));
937 -- Similarly, if the access definition is the return result of a
938 -- function, create an itype reference for it because it
939 -- will be used within the function body. For a regular function that
940 -- is not a compilation unit, insert reference after the declaration.
941 -- For a protected operation, insert it after the enclosing protected
942 -- type declaration. In either case, do not create a reference for a
943 -- type obtained through a limited_with clause, because this would
944 -- introduce semantic dependencies.
946 elsif Nkind (Related_Nod) = N_Function_Specification
947 and then not From_With_Type (Anon_Type)
949 if Ekind (Current_Scope) = E_Protected_Type then
950 Build_Itype_Reference (Anon_Type, Parent (Current_Scope));
952 elsif Is_List_Member (Parent (Related_Nod))
953 and then Nkind (Parent (N)) /= N_Parameter_Specification
955 Build_Itype_Reference (Anon_Type, Parent (Related_Nod));
958 -- Finally, create an itype reference for an object declaration of
959 -- an anonymous access type. This is strictly necessary only for
960 -- deferred constants, but in any case will avoid out-of-scope
961 -- problems in the back-end.
963 elsif Nkind (Related_Nod) = N_Object_Declaration then
964 Build_Itype_Reference (Anon_Type, Related_Nod);
968 end Access_Definition;
970 -----------------------------------
971 -- Access_Subprogram_Declaration --
972 -----------------------------------
974 procedure Access_Subprogram_Declaration
979 procedure Check_For_Premature_Usage (Def : Node_Id);
980 -- Check that type T_Name is not used, directly or recursively,
981 -- as a parameter or a return type in Def. Def is either a subtype,
982 -- an access_definition, or an access_to_subprogram_definition.
984 -------------------------------
985 -- Check_For_Premature_Usage --
986 -------------------------------
988 procedure Check_For_Premature_Usage (Def : Node_Id) is
992 -- Check for a subtype mark
994 if Nkind (Def) in N_Has_Etype then
995 if Etype (Def) = T_Name then
997 ("type& cannot be used before end of its declaration", Def);
1000 -- If this is not a subtype, then this is an access_definition
1002 elsif Nkind (Def) = N_Access_Definition then
1003 if Present (Access_To_Subprogram_Definition (Def)) then
1004 Check_For_Premature_Usage
1005 (Access_To_Subprogram_Definition (Def));
1007 Check_For_Premature_Usage (Subtype_Mark (Def));
1010 -- The only cases left are N_Access_Function_Definition and
1011 -- N_Access_Procedure_Definition.
1014 if Present (Parameter_Specifications (Def)) then
1015 Param := First (Parameter_Specifications (Def));
1016 while Present (Param) loop
1017 Check_For_Premature_Usage (Parameter_Type (Param));
1018 Param := Next (Param);
1022 if Nkind (Def) = N_Access_Function_Definition then
1023 Check_For_Premature_Usage (Result_Definition (Def));
1026 end Check_For_Premature_Usage;
1030 Formals : constant List_Id := Parameter_Specifications (T_Def);
1033 Desig_Type : constant Entity_Id :=
1034 Create_Itype (E_Subprogram_Type, Parent (T_Def));
1036 -- Start of processing for Access_Subprogram_Declaration
1039 -- Associate the Itype node with the inner full-type declaration or
1040 -- subprogram spec. This is required to handle nested anonymous
1041 -- declarations. For example:
1044 -- (X : access procedure
1045 -- (Y : access procedure
1048 D_Ityp := Associated_Node_For_Itype (Desig_Type);
1049 while not (Nkind_In (D_Ityp, N_Full_Type_Declaration,
1050 N_Private_Type_Declaration,
1051 N_Private_Extension_Declaration,
1052 N_Procedure_Specification,
1053 N_Function_Specification)
1055 Nkind_In (D_Ityp, N_Object_Declaration,
1056 N_Object_Renaming_Declaration,
1057 N_Formal_Object_Declaration,
1058 N_Formal_Type_Declaration,
1059 N_Formal_Object_Declaration,
1060 N_Task_Type_Declaration,
1061 N_Protected_Type_Declaration))
1063 D_Ityp := Parent (D_Ityp);
1064 pragma Assert (D_Ityp /= Empty);
1067 Set_Associated_Node_For_Itype (Desig_Type, D_Ityp);
1069 if Nkind_In (D_Ityp, N_Procedure_Specification,
1070 N_Function_Specification)
1072 Set_Scope (Desig_Type, Scope (Defining_Entity (D_Ityp)));
1074 elsif Nkind_In (D_Ityp, N_Full_Type_Declaration,
1075 N_Object_Declaration,
1076 N_Object_Renaming_Declaration,
1077 N_Formal_Type_Declaration)
1079 Set_Scope (Desig_Type, Scope (Defining_Identifier (D_Ityp)));
1082 if Nkind (T_Def) = N_Access_Function_Definition then
1083 if Nkind (Result_Definition (T_Def)) = N_Access_Definition then
1085 Acc : constant Node_Id := Result_Definition (T_Def);
1088 if Present (Access_To_Subprogram_Definition (Acc))
1090 Protected_Present (Access_To_Subprogram_Definition (Acc))
1094 Replace_Anonymous_Access_To_Protected_Subprogram
1100 Access_Definition (T_Def, Result_Definition (T_Def)));
1105 Analyze (Result_Definition (T_Def));
1106 Set_Etype (Desig_Type, Entity (Result_Definition (T_Def)));
1109 if not (Is_Type (Etype (Desig_Type))) then
1111 ("expect type in function specification",
1112 Result_Definition (T_Def));
1116 Set_Etype (Desig_Type, Standard_Void_Type);
1119 if Present (Formals) then
1120 Push_Scope (Desig_Type);
1122 -- A bit of a kludge here. These kludges will be removed when Itypes
1123 -- have proper parent pointers to their declarations???
1125 -- Kludge 1) Link definining_identifier of formals. Required by
1126 -- First_Formal to provide its functionality.
1132 F := First (Formals);
1133 while Present (F) loop
1134 if No (Parent (Defining_Identifier (F))) then
1135 Set_Parent (Defining_Identifier (F), F);
1142 Process_Formals (Formals, Parent (T_Def));
1144 -- Kludge 2) End_Scope requires that the parent pointer be set to
1145 -- something reasonable, but Itypes don't have parent pointers. So
1146 -- we set it and then unset it ???
1148 Set_Parent (Desig_Type, T_Name);
1150 Set_Parent (Desig_Type, Empty);
1153 -- Check for premature usage of the type being defined
1155 Check_For_Premature_Usage (T_Def);
1157 -- The return type and/or any parameter type may be incomplete. Mark
1158 -- the subprogram_type as depending on the incomplete type, so that
1159 -- it can be updated when the full type declaration is seen. This
1160 -- only applies to incomplete types declared in some enclosing scope,
1161 -- not to limited views from other packages.
1163 if Present (Formals) then
1164 Formal := First_Formal (Desig_Type);
1165 while Present (Formal) loop
1166 if Ekind (Formal) /= E_In_Parameter
1167 and then Nkind (T_Def) = N_Access_Function_Definition
1169 Error_Msg_N ("functions can only have IN parameters", Formal);
1172 if Ekind (Etype (Formal)) = E_Incomplete_Type
1173 and then In_Open_Scopes (Scope (Etype (Formal)))
1175 Append_Elmt (Desig_Type, Private_Dependents (Etype (Formal)));
1176 Set_Has_Delayed_Freeze (Desig_Type);
1179 Next_Formal (Formal);
1183 if Ekind (Etype (Desig_Type)) = E_Incomplete_Type
1184 and then not Has_Delayed_Freeze (Desig_Type)
1186 Append_Elmt (Desig_Type, Private_Dependents (Etype (Desig_Type)));
1187 Set_Has_Delayed_Freeze (Desig_Type);
1190 Check_Delayed_Subprogram (Desig_Type);
1192 if Protected_Present (T_Def) then
1193 Set_Ekind (T_Name, E_Access_Protected_Subprogram_Type);
1194 Set_Convention (Desig_Type, Convention_Protected);
1196 Set_Ekind (T_Name, E_Access_Subprogram_Type);
1199 Set_Can_Use_Internal_Rep (T_Name, not Always_Compatible_Rep_On_Target);
1201 Set_Etype (T_Name, T_Name);
1202 Init_Size_Align (T_Name);
1203 Set_Directly_Designated_Type (T_Name, Desig_Type);
1205 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1207 Set_Can_Never_Be_Null (T_Name, Null_Exclusion_Present (T_Def));
1209 Check_Restriction (No_Access_Subprograms, T_Def);
1210 end Access_Subprogram_Declaration;
1212 ----------------------------
1213 -- Access_Type_Declaration --
1214 ----------------------------
1216 procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id) is
1217 S : constant Node_Id := Subtype_Indication (Def);
1218 P : constant Node_Id := Parent (Def);
1224 -- Check for permissible use of incomplete type
1226 if Nkind (S) /= N_Subtype_Indication then
1229 if Ekind (Root_Type (Entity (S))) = E_Incomplete_Type then
1230 Set_Directly_Designated_Type (T, Entity (S));
1232 Set_Directly_Designated_Type (T,
1233 Process_Subtype (S, P, T, 'P'));
1237 Set_Directly_Designated_Type (T,
1238 Process_Subtype (S, P, T, 'P'));
1241 if All_Present (Def) or Constant_Present (Def) then
1242 Set_Ekind (T, E_General_Access_Type);
1244 Set_Ekind (T, E_Access_Type);
1247 if Base_Type (Designated_Type (T)) = T then
1248 Error_Msg_N ("access type cannot designate itself", S);
1250 -- In Ada 2005, the type may have a limited view through some unit
1251 -- in its own context, allowing the following circularity that cannot
1252 -- be detected earlier
1254 elsif Is_Class_Wide_Type (Designated_Type (T))
1255 and then Etype (Designated_Type (T)) = T
1258 ("access type cannot designate its own classwide type", S);
1260 -- Clean up indication of tagged status to prevent cascaded errors
1262 Set_Is_Tagged_Type (T, False);
1267 -- If the type has appeared already in a with_type clause, it is
1268 -- frozen and the pointer size is already set. Else, initialize.
1270 if not From_With_Type (T) then
1271 Init_Size_Align (T);
1274 Desig := Designated_Type (T);
1276 -- If designated type is an imported tagged type, indicate that the
1277 -- access type is also imported, and therefore restricted in its use.
1278 -- The access type may already be imported, so keep setting otherwise.
1280 -- Ada 2005 (AI-50217): If the non-limited view of the designated type
1281 -- is available, use it as the designated type of the access type, so
1282 -- that the back-end gets a usable entity.
1284 if From_With_Type (Desig)
1285 and then Ekind (Desig) /= E_Access_Type
1287 Set_From_With_Type (T);
1290 -- Note that Has_Task is always false, since the access type itself
1291 -- is not a task type. See Einfo for more description on this point.
1292 -- Exactly the same consideration applies to Has_Controlled_Component.
1294 Set_Has_Task (T, False);
1295 Set_Has_Controlled_Component (T, False);
1297 -- Initialize Associated_Final_Chain explicitly to Empty, to avoid
1298 -- problems where an incomplete view of this entity has been previously
1299 -- established by a limited with and an overlaid version of this field
1300 -- (Stored_Constraint) was initialized for the incomplete view.
1302 Set_Associated_Final_Chain (T, Empty);
1304 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1307 Set_Can_Never_Be_Null (T, Null_Exclusion_Present (Def));
1308 Set_Is_Access_Constant (T, Constant_Present (Def));
1309 end Access_Type_Declaration;
1311 ----------------------------------
1312 -- Add_Interface_Tag_Components --
1313 ----------------------------------
1315 procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id) is
1316 Loc : constant Source_Ptr := Sloc (N);
1320 procedure Add_Tag (Iface : Entity_Id);
1321 -- Add tag for one of the progenitor interfaces
1327 procedure Add_Tag (Iface : Entity_Id) is
1334 pragma Assert (Is_Tagged_Type (Iface)
1335 and then Is_Interface (Iface));
1338 Make_Component_Definition (Loc,
1339 Aliased_Present => True,
1340 Subtype_Indication =>
1341 New_Occurrence_Of (RTE (RE_Interface_Tag), Loc));
1343 Tag := Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1346 Make_Component_Declaration (Loc,
1347 Defining_Identifier => Tag,
1348 Component_Definition => Def);
1350 Analyze_Component_Declaration (Decl);
1352 Set_Analyzed (Decl);
1353 Set_Ekind (Tag, E_Component);
1355 Set_Is_Aliased (Tag);
1356 Set_Related_Type (Tag, Iface);
1357 Init_Component_Location (Tag);
1359 pragma Assert (Is_Frozen (Iface));
1361 Set_DT_Entry_Count (Tag,
1362 DT_Entry_Count (First_Entity (Iface)));
1364 if No (Last_Tag) then
1367 Insert_After (Last_Tag, Decl);
1372 -- If the ancestor has discriminants we need to give special support
1373 -- to store the offset_to_top value of the secondary dispatch tables.
1374 -- For this purpose we add a supplementary component just after the
1375 -- field that contains the tag associated with each secondary DT.
1377 if Typ /= Etype (Typ)
1378 and then Has_Discriminants (Etype (Typ))
1381 Make_Component_Definition (Loc,
1382 Subtype_Indication =>
1383 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc));
1386 Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1389 Make_Component_Declaration (Loc,
1390 Defining_Identifier => Offset,
1391 Component_Definition => Def);
1393 Analyze_Component_Declaration (Decl);
1395 Set_Analyzed (Decl);
1396 Set_Ekind (Offset, E_Component);
1397 Set_Is_Aliased (Offset);
1398 Set_Related_Type (Offset, Iface);
1399 Init_Component_Location (Offset);
1400 Insert_After (Last_Tag, Decl);
1411 -- Start of processing for Add_Interface_Tag_Components
1414 if not RTE_Available (RE_Interface_Tag) then
1416 ("(Ada 2005) interface types not supported by this run-time!",
1421 if Ekind (Typ) /= E_Record_Type
1422 or else (Is_Concurrent_Record_Type (Typ)
1423 and then Is_Empty_List (Abstract_Interface_List (Typ)))
1424 or else (not Is_Concurrent_Record_Type (Typ)
1425 and then No (Interfaces (Typ))
1426 and then Is_Empty_Elmt_List (Interfaces (Typ)))
1431 -- Find the current last tag
1433 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1434 Ext := Record_Extension_Part (Type_Definition (N));
1436 pragma Assert (Nkind (Type_Definition (N)) = N_Record_Definition);
1437 Ext := Type_Definition (N);
1442 if not (Present (Component_List (Ext))) then
1443 Set_Null_Present (Ext, False);
1445 Set_Component_List (Ext,
1446 Make_Component_List (Loc,
1447 Component_Items => L,
1448 Null_Present => False));
1450 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1451 L := Component_Items
1453 (Record_Extension_Part
1454 (Type_Definition (N))));
1456 L := Component_Items
1458 (Type_Definition (N)));
1461 -- Find the last tag component
1464 while Present (Comp) loop
1465 if Nkind (Comp) = N_Component_Declaration
1466 and then Is_Tag (Defining_Identifier (Comp))
1475 -- At this point L references the list of components and Last_Tag
1476 -- references the current last tag (if any). Now we add the tag
1477 -- corresponding with all the interfaces that are not implemented
1480 if Present (Interfaces (Typ)) then
1481 Elmt := First_Elmt (Interfaces (Typ));
1482 while Present (Elmt) loop
1483 Add_Tag (Node (Elmt));
1487 end Add_Interface_Tag_Components;
1489 -----------------------------------
1490 -- Analyze_Component_Declaration --
1491 -----------------------------------
1493 procedure Analyze_Component_Declaration (N : Node_Id) is
1494 Id : constant Entity_Id := Defining_Identifier (N);
1495 E : constant Node_Id := Expression (N);
1499 function Contains_POC (Constr : Node_Id) return Boolean;
1500 -- Determines whether a constraint uses the discriminant of a record
1501 -- type thus becoming a per-object constraint (POC).
1503 function Is_Known_Limited (Typ : Entity_Id) return Boolean;
1504 -- Typ is the type of the current component, check whether this type is
1505 -- a limited type. Used to validate declaration against that of
1506 -- enclosing record.
1512 function Contains_POC (Constr : Node_Id) return Boolean is
1514 -- Prevent cascaded errors
1516 if Error_Posted (Constr) then
1520 case Nkind (Constr) is
1521 when N_Attribute_Reference =>
1523 Attribute_Name (Constr) = Name_Access
1524 and then Prefix (Constr) = Scope (Entity (Prefix (Constr)));
1526 when N_Discriminant_Association =>
1527 return Denotes_Discriminant (Expression (Constr));
1529 when N_Identifier =>
1530 return Denotes_Discriminant (Constr);
1532 when N_Index_Or_Discriminant_Constraint =>
1537 IDC := First (Constraints (Constr));
1538 while Present (IDC) loop
1540 -- One per-object constraint is sufficient
1542 if Contains_POC (IDC) then
1553 return Denotes_Discriminant (Low_Bound (Constr))
1555 Denotes_Discriminant (High_Bound (Constr));
1557 when N_Range_Constraint =>
1558 return Denotes_Discriminant (Range_Expression (Constr));
1566 ----------------------
1567 -- Is_Known_Limited --
1568 ----------------------
1570 function Is_Known_Limited (Typ : Entity_Id) return Boolean is
1571 P : constant Entity_Id := Etype (Typ);
1572 R : constant Entity_Id := Root_Type (Typ);
1575 if Is_Limited_Record (Typ) then
1578 -- If the root type is limited (and not a limited interface)
1579 -- so is the current type
1581 elsif Is_Limited_Record (R)
1583 (not Is_Interface (R)
1584 or else not Is_Limited_Interface (R))
1588 -- Else the type may have a limited interface progenitor, but a
1589 -- limited record parent.
1592 and then Is_Limited_Record (P)
1599 end Is_Known_Limited;
1601 -- Start of processing for Analyze_Component_Declaration
1604 Generate_Definition (Id);
1607 if Present (Subtype_Indication (Component_Definition (N))) then
1608 T := Find_Type_Of_Object
1609 (Subtype_Indication (Component_Definition (N)), N);
1611 -- Ada 2005 (AI-230): Access Definition case
1614 pragma Assert (Present
1615 (Access_Definition (Component_Definition (N))));
1617 T := Access_Definition
1619 N => Access_Definition (Component_Definition (N)));
1620 Set_Is_Local_Anonymous_Access (T);
1622 -- Ada 2005 (AI-254)
1624 if Present (Access_To_Subprogram_Definition
1625 (Access_Definition (Component_Definition (N))))
1626 and then Protected_Present (Access_To_Subprogram_Definition
1628 (Component_Definition (N))))
1630 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
1634 -- If the subtype is a constrained subtype of the enclosing record,
1635 -- (which must have a partial view) the back-end does not properly
1636 -- handle the recursion. Rewrite the component declaration with an
1637 -- explicit subtype indication, which is acceptable to Gigi. We can copy
1638 -- the tree directly because side effects have already been removed from
1639 -- discriminant constraints.
1641 if Ekind (T) = E_Access_Subtype
1642 and then Is_Entity_Name (Subtype_Indication (Component_Definition (N)))
1643 and then Comes_From_Source (T)
1644 and then Nkind (Parent (T)) = N_Subtype_Declaration
1645 and then Etype (Directly_Designated_Type (T)) = Current_Scope
1648 (Subtype_Indication (Component_Definition (N)),
1649 New_Copy_Tree (Subtype_Indication (Parent (T))));
1650 T := Find_Type_Of_Object
1651 (Subtype_Indication (Component_Definition (N)), N);
1654 -- If the component declaration includes a default expression, then we
1655 -- check that the component is not of a limited type (RM 3.7(5)),
1656 -- and do the special preanalysis of the expression (see section on
1657 -- "Handling of Default and Per-Object Expressions" in the spec of
1661 Preanalyze_Spec_Expression (E, T);
1662 Check_Initialization (T, E);
1664 if Ada_Version >= Ada_05
1665 and then Ekind (T) = E_Anonymous_Access_Type
1667 -- Check RM 3.9.2(9): "if the expected type for an expression is
1668 -- an anonymous access-to-specific tagged type, then the object
1669 -- designated by the expression shall not be dynamically tagged
1670 -- unless it is a controlling operand in a call on a dispatching
1673 if Is_Tagged_Type (Directly_Designated_Type (T))
1675 Ekind (Directly_Designated_Type (T)) /= E_Class_Wide_Type
1677 Ekind (Directly_Designated_Type (Etype (E))) =
1681 ("access to specific tagged type required (RM 3.9.2(9))", E);
1684 -- (Ada 2005: AI-230): Accessibility check for anonymous
1687 if Type_Access_Level (Etype (E)) > Type_Access_Level (T) then
1689 ("expression has deeper access level than component " &
1690 "(RM 3.10.2 (12.2))", E);
1693 -- The initialization expression is a reference to an access
1694 -- discriminant. The type of the discriminant is always deeper
1695 -- than any access type.
1697 if Ekind (Etype (E)) = E_Anonymous_Access_Type
1698 and then Is_Entity_Name (E)
1699 and then Ekind (Entity (E)) = E_In_Parameter
1700 and then Present (Discriminal_Link (Entity (E)))
1703 ("discriminant has deeper accessibility level than target",
1709 -- The parent type may be a private view with unknown discriminants,
1710 -- and thus unconstrained. Regular components must be constrained.
1712 if Is_Indefinite_Subtype (T) and then Chars (Id) /= Name_uParent then
1713 if Is_Class_Wide_Type (T) then
1715 ("class-wide subtype with unknown discriminants" &
1716 " in component declaration",
1717 Subtype_Indication (Component_Definition (N)));
1720 ("unconstrained subtype in component declaration",
1721 Subtype_Indication (Component_Definition (N)));
1724 -- Components cannot be abstract, except for the special case of
1725 -- the _Parent field (case of extending an abstract tagged type)
1727 elsif Is_Abstract_Type (T) and then Chars (Id) /= Name_uParent then
1728 Error_Msg_N ("type of a component cannot be abstract", N);
1732 Set_Is_Aliased (Id, Aliased_Present (Component_Definition (N)));
1734 -- The component declaration may have a per-object constraint, set
1735 -- the appropriate flag in the defining identifier of the subtype.
1737 if Present (Subtype_Indication (Component_Definition (N))) then
1739 Sindic : constant Node_Id :=
1740 Subtype_Indication (Component_Definition (N));
1742 if Nkind (Sindic) = N_Subtype_Indication
1743 and then Present (Constraint (Sindic))
1744 and then Contains_POC (Constraint (Sindic))
1746 Set_Has_Per_Object_Constraint (Id);
1751 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
1752 -- out some static checks.
1754 if Ada_Version >= Ada_05
1755 and then Can_Never_Be_Null (T)
1757 Null_Exclusion_Static_Checks (N);
1760 -- If this component is private (or depends on a private type), flag the
1761 -- record type to indicate that some operations are not available.
1763 P := Private_Component (T);
1767 -- Check for circular definitions
1769 if P = Any_Type then
1770 Set_Etype (Id, Any_Type);
1772 -- There is a gap in the visibility of operations only if the
1773 -- component type is not defined in the scope of the record type.
1775 elsif Scope (P) = Scope (Current_Scope) then
1778 elsif Is_Limited_Type (P) then
1779 Set_Is_Limited_Composite (Current_Scope);
1782 Set_Is_Private_Composite (Current_Scope);
1787 and then Is_Limited_Type (T)
1788 and then Chars (Id) /= Name_uParent
1789 and then Is_Tagged_Type (Current_Scope)
1791 if Is_Derived_Type (Current_Scope)
1792 and then not Is_Known_Limited (Current_Scope)
1795 ("extension of nonlimited type cannot have limited components",
1798 if Is_Interface (Root_Type (Current_Scope)) then
1800 ("\limitedness is not inherited from limited interface", N);
1802 ("\add LIMITED to type indication", N);
1805 Explain_Limited_Type (T, N);
1806 Set_Etype (Id, Any_Type);
1807 Set_Is_Limited_Composite (Current_Scope, False);
1809 elsif not Is_Derived_Type (Current_Scope)
1810 and then not Is_Limited_Record (Current_Scope)
1811 and then not Is_Concurrent_Type (Current_Scope)
1814 ("nonlimited tagged type cannot have limited components", N);
1815 Explain_Limited_Type (T, N);
1816 Set_Etype (Id, Any_Type);
1817 Set_Is_Limited_Composite (Current_Scope, False);
1821 Set_Original_Record_Component (Id, Id);
1822 end Analyze_Component_Declaration;
1824 --------------------------
1825 -- Analyze_Declarations --
1826 --------------------------
1828 procedure Analyze_Declarations (L : List_Id) is
1830 Freeze_From : Entity_Id := Empty;
1831 Next_Node : Node_Id;
1834 -- Adjust D not to include implicit label declarations, since these
1835 -- have strange Sloc values that result in elaboration check problems.
1836 -- (They have the sloc of the label as found in the source, and that
1837 -- is ahead of the current declarative part).
1843 procedure Adjust_D is
1845 while Present (Prev (D))
1846 and then Nkind (D) = N_Implicit_Label_Declaration
1852 -- Start of processing for Analyze_Declarations
1856 while Present (D) loop
1858 -- Complete analysis of declaration
1861 Next_Node := Next (D);
1863 if No (Freeze_From) then
1864 Freeze_From := First_Entity (Current_Scope);
1867 -- At the end of a declarative part, freeze remaining entities
1868 -- declared in it. The end of the visible declarations of package
1869 -- specification is not the end of a declarative part if private
1870 -- declarations are present. The end of a package declaration is a
1871 -- freezing point only if it a library package. A task definition or
1872 -- protected type definition is not a freeze point either. Finally,
1873 -- we do not freeze entities in generic scopes, because there is no
1874 -- code generated for them and freeze nodes will be generated for
1877 -- The end of a package instantiation is not a freeze point, but
1878 -- for now we make it one, because the generic body is inserted
1879 -- (currently) immediately after. Generic instantiations will not
1880 -- be a freeze point once delayed freezing of bodies is implemented.
1881 -- (This is needed in any case for early instantiations ???).
1883 if No (Next_Node) then
1884 if Nkind_In (Parent (L), N_Component_List,
1886 N_Protected_Definition)
1890 elsif Nkind (Parent (L)) /= N_Package_Specification then
1891 if Nkind (Parent (L)) = N_Package_Body then
1892 Freeze_From := First_Entity (Current_Scope);
1896 Freeze_All (Freeze_From, D);
1897 Freeze_From := Last_Entity (Current_Scope);
1899 elsif Scope (Current_Scope) /= Standard_Standard
1900 and then not Is_Child_Unit (Current_Scope)
1901 and then No (Generic_Parent (Parent (L)))
1905 elsif L /= Visible_Declarations (Parent (L))
1906 or else No (Private_Declarations (Parent (L)))
1907 or else Is_Empty_List (Private_Declarations (Parent (L)))
1910 Freeze_All (Freeze_From, D);
1911 Freeze_From := Last_Entity (Current_Scope);
1914 -- If next node is a body then freeze all types before the body.
1915 -- An exception occurs for some expander-generated bodies. If these
1916 -- are generated at places where in general language rules would not
1917 -- allow a freeze point, then we assume that the expander has
1918 -- explicitly checked that all required types are properly frozen,
1919 -- and we do not cause general freezing here. This special circuit
1920 -- is used when the encountered body is marked as having already
1923 -- In all other cases (bodies that come from source, and expander
1924 -- generated bodies that have not been analyzed yet), freeze all
1925 -- types now. Note that in the latter case, the expander must take
1926 -- care to attach the bodies at a proper place in the tree so as to
1927 -- not cause unwanted freezing at that point.
1929 elsif not Analyzed (Next_Node)
1930 and then (Nkind_In (Next_Node, N_Subprogram_Body,
1936 Nkind (Next_Node) in N_Body_Stub)
1939 Freeze_All (Freeze_From, D);
1940 Freeze_From := Last_Entity (Current_Scope);
1945 end Analyze_Declarations;
1947 ----------------------------------
1948 -- Analyze_Incomplete_Type_Decl --
1949 ----------------------------------
1951 procedure Analyze_Incomplete_Type_Decl (N : Node_Id) is
1952 F : constant Boolean := Is_Pure (Current_Scope);
1956 Generate_Definition (Defining_Identifier (N));
1958 -- Process an incomplete declaration. The identifier must not have been
1959 -- declared already in the scope. However, an incomplete declaration may
1960 -- appear in the private part of a package, for a private type that has
1961 -- already been declared.
1963 -- In this case, the discriminants (if any) must match
1965 T := Find_Type_Name (N);
1967 Set_Ekind (T, E_Incomplete_Type);
1968 Init_Size_Align (T);
1969 Set_Is_First_Subtype (T, True);
1972 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
1973 -- incomplete types.
1975 if Tagged_Present (N) then
1976 Set_Is_Tagged_Type (T);
1977 Make_Class_Wide_Type (T);
1978 Set_Primitive_Operations (T, New_Elmt_List);
1983 Set_Stored_Constraint (T, No_Elist);
1985 if Present (Discriminant_Specifications (N)) then
1986 Process_Discriminants (N);
1991 -- If the type has discriminants, non-trivial subtypes may be be
1992 -- declared before the full view of the type. The full views of those
1993 -- subtypes will be built after the full view of the type.
1995 Set_Private_Dependents (T, New_Elmt_List);
1997 end Analyze_Incomplete_Type_Decl;
1999 -----------------------------------
2000 -- Analyze_Interface_Declaration --
2001 -----------------------------------
2003 procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id) is
2004 CW : constant Entity_Id := Class_Wide_Type (T);
2007 Set_Is_Tagged_Type (T);
2009 Set_Is_Limited_Record (T, Limited_Present (Def)
2010 or else Task_Present (Def)
2011 or else Protected_Present (Def)
2012 or else Synchronized_Present (Def));
2014 -- Type is abstract if full declaration carries keyword, or if previous
2015 -- partial view did.
2017 Set_Is_Abstract_Type (T);
2018 Set_Is_Interface (T);
2020 -- Type is a limited interface if it includes the keyword limited, task,
2021 -- protected, or synchronized.
2023 Set_Is_Limited_Interface
2024 (T, Limited_Present (Def)
2025 or else Protected_Present (Def)
2026 or else Synchronized_Present (Def)
2027 or else Task_Present (Def));
2029 Set_Is_Protected_Interface (T, Protected_Present (Def));
2030 Set_Is_Task_Interface (T, Task_Present (Def));
2032 -- Type is a synchronized interface if it includes the keyword task,
2033 -- protected, or synchronized.
2035 Set_Is_Synchronized_Interface
2036 (T, Synchronized_Present (Def)
2037 or else Protected_Present (Def)
2038 or else Task_Present (Def));
2040 Set_Interfaces (T, New_Elmt_List);
2041 Set_Primitive_Operations (T, New_Elmt_List);
2043 -- Complete the decoration of the class-wide entity if it was already
2044 -- built (i.e. during the creation of the limited view)
2046 if Present (CW) then
2047 Set_Is_Interface (CW);
2048 Set_Is_Limited_Interface (CW, Is_Limited_Interface (T));
2049 Set_Is_Protected_Interface (CW, Is_Protected_Interface (T));
2050 Set_Is_Synchronized_Interface (CW, Is_Synchronized_Interface (T));
2051 Set_Is_Task_Interface (CW, Is_Task_Interface (T));
2054 -- Check runtime support for synchronized interfaces
2056 if VM_Target = No_VM
2057 and then (Is_Task_Interface (T)
2058 or else Is_Protected_Interface (T)
2059 or else Is_Synchronized_Interface (T))
2060 and then not RTE_Available (RE_Select_Specific_Data)
2062 Error_Msg_CRT ("synchronized interfaces", T);
2064 end Analyze_Interface_Declaration;
2066 -----------------------------
2067 -- Analyze_Itype_Reference --
2068 -----------------------------
2070 -- Nothing to do. This node is placed in the tree only for the benefit of
2071 -- back end processing, and has no effect on the semantic processing.
2073 procedure Analyze_Itype_Reference (N : Node_Id) is
2075 pragma Assert (Is_Itype (Itype (N)));
2077 end Analyze_Itype_Reference;
2079 --------------------------------
2080 -- Analyze_Number_Declaration --
2081 --------------------------------
2083 procedure Analyze_Number_Declaration (N : Node_Id) is
2084 Id : constant Entity_Id := Defining_Identifier (N);
2085 E : constant Node_Id := Expression (N);
2087 Index : Interp_Index;
2091 Generate_Definition (Id);
2094 -- This is an optimization of a common case of an integer literal
2096 if Nkind (E) = N_Integer_Literal then
2097 Set_Is_Static_Expression (E, True);
2098 Set_Etype (E, Universal_Integer);
2100 Set_Etype (Id, Universal_Integer);
2101 Set_Ekind (Id, E_Named_Integer);
2102 Set_Is_Frozen (Id, True);
2106 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2108 -- Process expression, replacing error by integer zero, to avoid
2109 -- cascaded errors or aborts further along in the processing
2111 -- Replace Error by integer zero, which seems least likely to
2112 -- cause cascaded errors.
2115 Rewrite (E, Make_Integer_Literal (Sloc (E), Uint_0));
2116 Set_Error_Posted (E);
2121 -- Verify that the expression is static and numeric. If
2122 -- the expression is overloaded, we apply the preference
2123 -- rule that favors root numeric types.
2125 if not Is_Overloaded (E) then
2131 Get_First_Interp (E, Index, It);
2132 while Present (It.Typ) loop
2133 if (Is_Integer_Type (It.Typ)
2134 or else Is_Real_Type (It.Typ))
2135 and then (Scope (Base_Type (It.Typ))) = Standard_Standard
2137 if T = Any_Type then
2140 elsif It.Typ = Universal_Real
2141 or else It.Typ = Universal_Integer
2143 -- Choose universal interpretation over any other
2150 Get_Next_Interp (Index, It);
2154 if Is_Integer_Type (T) then
2156 Set_Etype (Id, Universal_Integer);
2157 Set_Ekind (Id, E_Named_Integer);
2159 elsif Is_Real_Type (T) then
2161 -- Because the real value is converted to universal_real, this is a
2162 -- legal context for a universal fixed expression.
2164 if T = Universal_Fixed then
2166 Loc : constant Source_Ptr := Sloc (N);
2167 Conv : constant Node_Id := Make_Type_Conversion (Loc,
2169 New_Occurrence_Of (Universal_Real, Loc),
2170 Expression => Relocate_Node (E));
2177 elsif T = Any_Fixed then
2178 Error_Msg_N ("illegal context for mixed mode operation", E);
2180 -- Expression is of the form : universal_fixed * integer. Try to
2181 -- resolve as universal_real.
2183 T := Universal_Real;
2188 Set_Etype (Id, Universal_Real);
2189 Set_Ekind (Id, E_Named_Real);
2192 Wrong_Type (E, Any_Numeric);
2196 Set_Ekind (Id, E_Constant);
2197 Set_Never_Set_In_Source (Id, True);
2198 Set_Is_True_Constant (Id, True);
2202 if Nkind_In (E, N_Integer_Literal, N_Real_Literal) then
2203 Set_Etype (E, Etype (Id));
2206 if not Is_OK_Static_Expression (E) then
2207 Flag_Non_Static_Expr
2208 ("non-static expression used in number declaration!", E);
2209 Rewrite (E, Make_Integer_Literal (Sloc (N), 1));
2210 Set_Etype (E, Any_Type);
2212 end Analyze_Number_Declaration;
2214 --------------------------------
2215 -- Analyze_Object_Declaration --
2216 --------------------------------
2218 procedure Analyze_Object_Declaration (N : Node_Id) is
2219 Loc : constant Source_Ptr := Sloc (N);
2220 Id : constant Entity_Id := Defining_Identifier (N);
2224 E : Node_Id := Expression (N);
2225 -- E is set to Expression (N) throughout this routine. When
2226 -- Expression (N) is modified, E is changed accordingly.
2228 Prev_Entity : Entity_Id := Empty;
2230 function Count_Tasks (T : Entity_Id) return Uint;
2231 -- This function is called when a non-generic library level object of a
2232 -- task type is declared. Its function is to count the static number of
2233 -- tasks declared within the type (it is only called if Has_Tasks is set
2234 -- for T). As a side effect, if an array of tasks with non-static bounds
2235 -- or a variant record type is encountered, Check_Restrictions is called
2236 -- indicating the count is unknown.
2242 function Count_Tasks (T : Entity_Id) return Uint is
2248 if Is_Task_Type (T) then
2251 elsif Is_Record_Type (T) then
2252 if Has_Discriminants (T) then
2253 Check_Restriction (Max_Tasks, N);
2258 C := First_Component (T);
2259 while Present (C) loop
2260 V := V + Count_Tasks (Etype (C));
2267 elsif Is_Array_Type (T) then
2268 X := First_Index (T);
2269 V := Count_Tasks (Component_Type (T));
2270 while Present (X) loop
2273 if not Is_Static_Subtype (C) then
2274 Check_Restriction (Max_Tasks, N);
2277 V := V * (UI_Max (Uint_0,
2278 Expr_Value (Type_High_Bound (C)) -
2279 Expr_Value (Type_Low_Bound (C)) + Uint_1));
2292 -- Start of processing for Analyze_Object_Declaration
2295 -- There are three kinds of implicit types generated by an
2296 -- object declaration:
2298 -- 1. Those for generated by the original Object Definition
2300 -- 2. Those generated by the Expression
2302 -- 3. Those used to constrained the Object Definition with the
2303 -- expression constraints when it is unconstrained
2305 -- They must be generated in this order to avoid order of elaboration
2306 -- issues. Thus the first step (after entering the name) is to analyze
2307 -- the object definition.
2309 if Constant_Present (N) then
2310 Prev_Entity := Current_Entity_In_Scope (Id);
2312 -- If the homograph is an implicit subprogram, it is overridden by
2313 -- the current declaration.
2315 if Present (Prev_Entity)
2317 ((Is_Overloadable (Prev_Entity)
2318 and then Is_Inherited_Operation (Prev_Entity))
2320 -- The current object is a discriminal generated for an entry
2321 -- family index. Even though the index is a constant, in this
2322 -- particular context there is no true constant redeclaration.
2323 -- Enter_Name will handle the visibility.
2326 (Is_Discriminal (Id)
2327 and then Ekind (Discriminal_Link (Id)) =
2328 E_Entry_Index_Parameter))
2330 Prev_Entity := Empty;
2334 if Present (Prev_Entity) then
2335 Constant_Redeclaration (Id, N, T);
2337 Generate_Reference (Prev_Entity, Id, 'c');
2338 Set_Completion_Referenced (Id);
2340 if Error_Posted (N) then
2342 -- Type mismatch or illegal redeclaration, Do not analyze
2343 -- expression to avoid cascaded errors.
2345 T := Find_Type_Of_Object (Object_Definition (N), N);
2347 Set_Ekind (Id, E_Variable);
2351 -- In the normal case, enter identifier at the start to catch premature
2352 -- usage in the initialization expression.
2355 Generate_Definition (Id);
2358 Mark_Coextensions (N, Object_Definition (N));
2360 T := Find_Type_Of_Object (Object_Definition (N), N);
2362 if Nkind (Object_Definition (N)) = N_Access_Definition
2364 (Access_To_Subprogram_Definition (Object_Definition (N)))
2365 and then Protected_Present
2366 (Access_To_Subprogram_Definition (Object_Definition (N)))
2368 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
2371 if Error_Posted (Id) then
2373 Set_Ekind (Id, E_Variable);
2378 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2379 -- out some static checks
2381 if Ada_Version >= Ada_05
2382 and then Can_Never_Be_Null (T)
2384 -- In case of aggregates we must also take care of the correct
2385 -- initialization of nested aggregates bug this is done at the
2386 -- point of the analysis of the aggregate (see sem_aggr.adb)
2388 if Present (Expression (N))
2389 and then Nkind (Expression (N)) = N_Aggregate
2395 Save_Typ : constant Entity_Id := Etype (Id);
2397 Set_Etype (Id, T); -- Temp. decoration for static checks
2398 Null_Exclusion_Static_Checks (N);
2399 Set_Etype (Id, Save_Typ);
2404 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2406 -- If deferred constant, make sure context is appropriate. We detect
2407 -- a deferred constant as a constant declaration with no expression.
2408 -- A deferred constant can appear in a package body if its completion
2409 -- is by means of an interface pragma.
2411 if Constant_Present (N)
2414 -- We exclude forward references to tags
2416 if Is_Imported (Defining_Identifier (N))
2420 (Present (Full_View (T))
2421 and then Full_View (T) = RTE (RE_Tag)))
2425 -- A deferred constant may appear in the declarative part of the
2426 -- following constructs:
2430 -- extended return statements
2433 -- subprogram bodies
2436 -- When declared inside a package spec, a deferred constant must be
2437 -- completed by a full constant declaration or pragma Import. In all
2438 -- other cases, the only proper completion is pragma Import. Extended
2439 -- return statements are flagged as invalid contexts because they do
2440 -- not have a declarative part and so cannot accommodate the pragma.
2442 elsif Ekind (Current_Scope) = E_Return_Statement then
2444 ("invalid context for deferred constant declaration (RM 7.4)",
2447 ("\declaration requires an initialization expression",
2449 Set_Constant_Present (N, False);
2451 -- In Ada 83, deferred constant must be of private type
2453 elsif not Is_Private_Type (T) then
2454 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2456 ("(Ada 83) deferred constant must be private type", N);
2460 -- If not a deferred constant, then object declaration freezes its type
2463 Check_Fully_Declared (T, N);
2464 Freeze_Before (N, T);
2467 -- If the object was created by a constrained array definition, then
2468 -- set the link in both the anonymous base type and anonymous subtype
2469 -- that are built to represent the array type to point to the object.
2471 if Nkind (Object_Definition (Declaration_Node (Id))) =
2472 N_Constrained_Array_Definition
2474 Set_Related_Array_Object (T, Id);
2475 Set_Related_Array_Object (Base_Type (T), Id);
2478 -- Special checks for protected objects not at library level
2480 if Is_Protected_Type (T)
2481 and then not Is_Library_Level_Entity (Id)
2483 Check_Restriction (No_Local_Protected_Objects, Id);
2485 -- Protected objects with interrupt handlers must be at library level
2487 -- Ada 2005: this test is not needed (and the corresponding clause
2488 -- in the RM is removed) because accessibility checks are sufficient
2489 -- to make handlers not at the library level illegal.
2491 if Has_Interrupt_Handler (T)
2492 and then Ada_Version < Ada_05
2495 ("interrupt object can only be declared at library level", Id);
2499 -- The actual subtype of the object is the nominal subtype, unless
2500 -- the nominal one is unconstrained and obtained from the expression.
2504 -- Process initialization expression if present and not in error
2506 if Present (E) and then E /= Error then
2508 -- Generate an error in case of CPP class-wide object initialization.
2509 -- Required because otherwise the expansion of the class-wide
2510 -- assignment would try to use 'size to initialize the object
2511 -- (primitive that is not available in CPP tagged types).
2513 if Is_Class_Wide_Type (Act_T)
2515 (Is_CPP_Class (Root_Type (Etype (Act_T)))
2517 (Present (Full_View (Root_Type (Etype (Act_T))))
2519 Is_CPP_Class (Full_View (Root_Type (Etype (Act_T))))))
2522 ("predefined assignment not available for 'C'P'P tagged types",
2526 Mark_Coextensions (N, E);
2529 -- In case of errors detected in the analysis of the expression,
2530 -- decorate it with the expected type to avoid cascaded errors
2532 if No (Etype (E)) then
2536 -- If an initialization expression is present, then we set the
2537 -- Is_True_Constant flag. It will be reset if this is a variable
2538 -- and it is indeed modified.
2540 Set_Is_True_Constant (Id, True);
2542 -- If we are analyzing a constant declaration, set its completion
2543 -- flag after analyzing and resolving the expression.
2545 if Constant_Present (N) then
2546 Set_Has_Completion (Id);
2549 -- Set type and resolve (type may be overridden later on)
2554 -- If the object is an access to variable, the initialization
2555 -- expression cannot be an access to constant.
2557 if Is_Access_Type (T)
2558 and then not Is_Access_Constant (T)
2559 and then Is_Access_Type (Etype (E))
2560 and then Is_Access_Constant (Etype (E))
2563 ("object that is an access to variable cannot be initialized " &
2564 "with an access-to-constant expression", E);
2567 if not Assignment_OK (N) then
2568 Check_Initialization (T, E);
2571 Check_Unset_Reference (E);
2573 -- If this is a variable, then set current value
2575 if not Constant_Present (N) then
2576 if Compile_Time_Known_Value (E) then
2577 Set_Current_Value (Id, E);
2581 -- Deal with setting of null flags
2583 if Is_Access_Type (T) then
2584 if Known_Non_Null (E) then
2585 Set_Is_Known_Non_Null (Id, True);
2586 elsif Known_Null (E)
2587 and then not Can_Never_Be_Null (Id)
2589 Set_Is_Known_Null (Id, True);
2593 -- Check incorrect use of dynamically tagged expressions. Note
2594 -- the use of Is_Tagged_Type (T) which seems redundant but is in
2595 -- fact important to avoid spurious errors due to expanded code
2596 -- for dispatching functions over an anonymous access type
2598 if (Is_Class_Wide_Type (Etype (E)) or else Is_Dynamically_Tagged (E))
2599 and then Is_Tagged_Type (T)
2600 and then not Is_Class_Wide_Type (T)
2602 Error_Msg_N ("dynamically tagged expression not allowed!", E);
2605 Apply_Scalar_Range_Check (E, T);
2606 Apply_Static_Length_Check (E, T);
2609 -- If the No_Streams restriction is set, check that the type of the
2610 -- object is not, and does not contain, any subtype derived from
2611 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
2612 -- Has_Stream just for efficiency reasons. There is no point in
2613 -- spending time on a Has_Stream check if the restriction is not set.
2615 if Restrictions.Set (No_Streams) then
2616 if Has_Stream (T) then
2617 Check_Restriction (No_Streams, N);
2621 -- Abstract type is never permitted for a variable or constant.
2622 -- Note: we inhibit this check for objects that do not come from
2623 -- source because there is at least one case (the expansion of
2624 -- x'class'input where x is abstract) where we legitimately
2625 -- generate an abstract object.
2627 if Is_Abstract_Type (T) and then Comes_From_Source (N) then
2628 Error_Msg_N ("type of object cannot be abstract",
2629 Object_Definition (N));
2631 if Is_CPP_Class (T) then
2632 Error_Msg_NE ("\} may need a cpp_constructor",
2633 Object_Definition (N), T);
2636 -- Case of unconstrained type
2638 elsif Is_Indefinite_Subtype (T) then
2640 -- Nothing to do in deferred constant case
2642 if Constant_Present (N) and then No (E) then
2645 -- Case of no initialization present
2648 if No_Initialization (N) then
2651 elsif Is_Class_Wide_Type (T) then
2653 ("initialization required in class-wide declaration ", N);
2657 ("unconstrained subtype not allowed (need initialization)",
2658 Object_Definition (N));
2660 if Is_Record_Type (T) and then Has_Discriminants (T) then
2662 ("\provide initial value or explicit discriminant values",
2663 Object_Definition (N));
2666 ("\or give default discriminant values for type&",
2667 Object_Definition (N), T);
2669 elsif Is_Array_Type (T) then
2671 ("\provide initial value or explicit array bounds",
2672 Object_Definition (N));
2676 -- Case of initialization present but in error. Set initial
2677 -- expression as absent (but do not make above complaints)
2679 elsif E = Error then
2680 Set_Expression (N, Empty);
2683 -- Case of initialization present
2686 -- Not allowed in Ada 83
2688 if not Constant_Present (N) then
2689 if Ada_Version = Ada_83
2690 and then Comes_From_Source (Object_Definition (N))
2693 ("(Ada 83) unconstrained variable not allowed",
2694 Object_Definition (N));
2698 -- Now we constrain the variable from the initializing expression
2700 -- If the expression is an aggregate, it has been expanded into
2701 -- individual assignments. Retrieve the actual type from the
2702 -- expanded construct.
2704 if Is_Array_Type (T)
2705 and then No_Initialization (N)
2706 and then Nkind (Original_Node (E)) = N_Aggregate
2711 Expand_Subtype_From_Expr (N, T, Object_Definition (N), E);
2712 Act_T := Find_Type_Of_Object (Object_Definition (N), N);
2715 Set_Is_Constr_Subt_For_U_Nominal (Act_T);
2717 if Aliased_Present (N) then
2718 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2721 Freeze_Before (N, Act_T);
2722 Freeze_Before (N, T);
2725 elsif Is_Array_Type (T)
2726 and then No_Initialization (N)
2727 and then Nkind (Original_Node (E)) = N_Aggregate
2729 if not Is_Entity_Name (Object_Definition (N)) then
2731 Check_Compile_Time_Size (Act_T);
2733 if Aliased_Present (N) then
2734 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2738 -- When the given object definition and the aggregate are specified
2739 -- independently, and their lengths might differ do a length check.
2740 -- This cannot happen if the aggregate is of the form (others =>...)
2742 if not Is_Constrained (T) then
2745 elsif Nkind (E) = N_Raise_Constraint_Error then
2747 -- Aggregate is statically illegal. Place back in declaration
2749 Set_Expression (N, E);
2750 Set_No_Initialization (N, False);
2752 elsif T = Etype (E) then
2755 elsif Nkind (E) = N_Aggregate
2756 and then Present (Component_Associations (E))
2757 and then Present (Choices (First (Component_Associations (E))))
2758 and then Nkind (First
2759 (Choices (First (Component_Associations (E))))) = N_Others_Choice
2764 Apply_Length_Check (E, T);
2767 -- If the type is limited unconstrained with defaulted discriminants
2768 -- and there is no expression, then the object is constrained by the
2769 -- defaults, so it is worthwhile building the corresponding subtype.
2771 elsif (Is_Limited_Record (T)
2772 or else Is_Concurrent_Type (T))
2773 and then not Is_Constrained (T)
2774 and then Has_Discriminants (T)
2777 Act_T := Build_Default_Subtype (T, N);
2779 -- Ada 2005: a limited object may be initialized by means of an
2780 -- aggregate. If the type has default discriminants it has an
2781 -- unconstrained nominal type, Its actual subtype will be obtained
2782 -- from the aggregate, and not from the default discriminants.
2787 Rewrite (Object_Definition (N), New_Occurrence_Of (Act_T, Loc));
2789 elsif Present (Underlying_Type (T))
2790 and then not Is_Constrained (Underlying_Type (T))
2791 and then Has_Discriminants (Underlying_Type (T))
2792 and then Nkind (E) = N_Function_Call
2793 and then Constant_Present (N)
2795 -- The back-end has problems with constants of a discriminated type
2796 -- with defaults, if the initial value is a function call. We
2797 -- generate an intermediate temporary for the result of the call.
2798 -- It is unclear why this should make it acceptable to gcc. ???
2800 Remove_Side_Effects (E);
2803 -- Check No_Wide_Characters restriction
2805 if T = Standard_Wide_Character
2806 or else T = Standard_Wide_Wide_Character
2807 or else Root_Type (T) = Standard_Wide_String
2808 or else Root_Type (T) = Standard_Wide_Wide_String
2810 Check_Restriction (No_Wide_Characters, Object_Definition (N));
2813 -- Indicate this is not set in source. Certainly true for constants,
2814 -- and true for variables so far (will be reset for a variable if and
2815 -- when we encounter a modification in the source).
2817 Set_Never_Set_In_Source (Id, True);
2819 -- Now establish the proper kind and type of the object
2821 if Constant_Present (N) then
2822 Set_Ekind (Id, E_Constant);
2823 Set_Is_True_Constant (Id, True);
2826 Set_Ekind (Id, E_Variable);
2828 -- A variable is set as shared passive if it appears in a shared
2829 -- passive package, and is at the outer level. This is not done
2830 -- for entities generated during expansion, because those are
2831 -- always manipulated locally.
2833 if Is_Shared_Passive (Current_Scope)
2834 and then Is_Library_Level_Entity (Id)
2835 and then Comes_From_Source (Id)
2837 Set_Is_Shared_Passive (Id);
2838 Check_Shared_Var (Id, T, N);
2841 -- Set Has_Initial_Value if initializing expression present. Note
2842 -- that if there is no initializing expression, we leave the state
2843 -- of this flag unchanged (usually it will be False, but notably in
2844 -- the case of exception choice variables, it will already be true).
2847 Set_Has_Initial_Value (Id, True);
2851 -- Initialize alignment and size and capture alignment setting
2853 Init_Alignment (Id);
2855 Set_Optimize_Alignment_Flags (Id);
2857 -- Deal with aliased case
2859 if Aliased_Present (N) then
2860 Set_Is_Aliased (Id);
2862 -- If the object is aliased and the type is unconstrained with
2863 -- defaulted discriminants and there is no expression, then the
2864 -- object is constrained by the defaults, so it is worthwhile
2865 -- building the corresponding subtype.
2867 -- Ada 2005 (AI-363): If the aliased object is discriminated and
2868 -- unconstrained, then only establish an actual subtype if the
2869 -- nominal subtype is indefinite. In definite cases the object is
2870 -- unconstrained in Ada 2005.
2873 and then Is_Record_Type (T)
2874 and then not Is_Constrained (T)
2875 and then Has_Discriminants (T)
2876 and then (Ada_Version < Ada_05 or else Is_Indefinite_Subtype (T))
2878 Set_Actual_Subtype (Id, Build_Default_Subtype (T, N));
2882 -- Now we can set the type of the object
2884 Set_Etype (Id, Act_T);
2886 -- Deal with controlled types
2888 if Has_Controlled_Component (Etype (Id))
2889 or else Is_Controlled (Etype (Id))
2891 if not Is_Library_Level_Entity (Id) then
2892 Check_Restriction (No_Nested_Finalization, N);
2894 Validate_Controlled_Object (Id);
2897 -- Generate a warning when an initialization causes an obvious ABE
2898 -- violation. If the init expression is a simple aggregate there
2899 -- shouldn't be any initialize/adjust call generated. This will be
2900 -- true as soon as aggregates are built in place when possible.
2902 -- ??? at the moment we do not generate warnings for temporaries
2903 -- created for those aggregates although Program_Error might be
2904 -- generated if compiled with -gnato.
2906 if Is_Controlled (Etype (Id))
2907 and then Comes_From_Source (Id)
2910 BT : constant Entity_Id := Base_Type (Etype (Id));
2912 Implicit_Call : Entity_Id;
2913 pragma Warnings (Off, Implicit_Call);
2914 -- ??? what is this for (never referenced!)
2916 function Is_Aggr (N : Node_Id) return Boolean;
2917 -- Check that N is an aggregate
2923 function Is_Aggr (N : Node_Id) return Boolean is
2925 case Nkind (Original_Node (N)) is
2926 when N_Aggregate | N_Extension_Aggregate =>
2929 when N_Qualified_Expression |
2931 N_Unchecked_Type_Conversion =>
2932 return Is_Aggr (Expression (Original_Node (N)));
2940 -- If no underlying type, we already are in an error situation.
2941 -- Do not try to add a warning since we do not have access to
2944 if No (Underlying_Type (BT)) then
2945 Implicit_Call := Empty;
2947 -- A generic type does not have usable primitive operators.
2948 -- Initialization calls are built for instances.
2950 elsif Is_Generic_Type (BT) then
2951 Implicit_Call := Empty;
2953 -- If the init expression is not an aggregate, an adjust call
2954 -- will be generated
2956 elsif Present (E) and then not Is_Aggr (E) then
2957 Implicit_Call := Find_Prim_Op (BT, Name_Adjust);
2959 -- If no init expression and we are not in the deferred
2960 -- constant case, an Initialize call will be generated
2962 elsif No (E) and then not Constant_Present (N) then
2963 Implicit_Call := Find_Prim_Op (BT, Name_Initialize);
2966 Implicit_Call := Empty;
2972 if Has_Task (Etype (Id)) then
2973 Check_Restriction (No_Tasking, N);
2975 -- Deal with counting max tasks
2977 -- Nothing to do if inside a generic
2979 if Inside_A_Generic then
2982 -- If library level entity, then count tasks
2984 elsif Is_Library_Level_Entity (Id) then
2985 Check_Restriction (Max_Tasks, N, Count_Tasks (Etype (Id)));
2987 -- If not library level entity, then indicate we don't know max
2988 -- tasks and also check task hierarchy restriction and blocking
2989 -- operation (since starting a task is definitely blocking!)
2992 Check_Restriction (Max_Tasks, N);
2993 Check_Restriction (No_Task_Hierarchy, N);
2994 Check_Potentially_Blocking_Operation (N);
2997 -- A rather specialized test. If we see two tasks being declared
2998 -- of the same type in the same object declaration, and the task
2999 -- has an entry with an address clause, we know that program error
3000 -- will be raised at run-time since we can't have two tasks with
3001 -- entries at the same address.
3003 if Is_Task_Type (Etype (Id)) and then More_Ids (N) then
3008 E := First_Entity (Etype (Id));
3009 while Present (E) loop
3010 if Ekind (E) = E_Entry
3011 and then Present (Get_Attribute_Definition_Clause
3012 (E, Attribute_Address))
3015 ("?more than one task with same entry address", N);
3017 ("\?Program_Error will be raised at run time", N);
3019 Make_Raise_Program_Error (Loc,
3020 Reason => PE_Duplicated_Entry_Address));
3030 -- Some simple constant-propagation: if the expression is a constant
3031 -- string initialized with a literal, share the literal. This avoids
3035 and then Is_Entity_Name (E)
3036 and then Ekind (Entity (E)) = E_Constant
3037 and then Base_Type (Etype (E)) = Standard_String
3040 Val : constant Node_Id := Constant_Value (Entity (E));
3043 and then Nkind (Val) = N_String_Literal
3045 Rewrite (E, New_Copy (Val));
3050 -- Another optimization: if the nominal subtype is unconstrained and
3051 -- the expression is a function call that returns an unconstrained
3052 -- type, rewrite the declaration as a renaming of the result of the
3053 -- call. The exceptions below are cases where the copy is expected,
3054 -- either by the back end (Aliased case) or by the semantics, as for
3055 -- initializing controlled types or copying tags for classwide types.
3058 and then Nkind (E) = N_Explicit_Dereference
3059 and then Nkind (Original_Node (E)) = N_Function_Call
3060 and then not Is_Library_Level_Entity (Id)
3061 and then not Is_Constrained (Underlying_Type (T))
3062 and then not Is_Aliased (Id)
3063 and then not Is_Class_Wide_Type (T)
3064 and then not Is_Controlled (T)
3065 and then not Has_Controlled_Component (Base_Type (T))
3066 and then Expander_Active
3069 Make_Object_Renaming_Declaration (Loc,
3070 Defining_Identifier => Id,
3071 Access_Definition => Empty,
3072 Subtype_Mark => New_Occurrence_Of
3073 (Base_Type (Etype (Id)), Loc),
3076 Set_Renamed_Object (Id, E);
3078 -- Force generation of debugging information for the constant and for
3079 -- the renamed function call.
3081 Set_Debug_Info_Needed (Id);
3082 Set_Debug_Info_Needed (Entity (Prefix (E)));
3085 if Present (Prev_Entity)
3086 and then Is_Frozen (Prev_Entity)
3087 and then not Error_Posted (Id)
3089 Error_Msg_N ("full constant declaration appears too late", N);
3092 Check_Eliminated (Id);
3094 -- Deal with setting In_Private_Part flag if in private part
3096 if Ekind (Scope (Id)) = E_Package
3097 and then In_Private_Part (Scope (Id))
3099 Set_In_Private_Part (Id);
3102 -- Check for violation of No_Local_Timing_Events
3104 if Is_RTE (Etype (Id), RE_Timing_Event)
3105 and then not Is_Library_Level_Entity (Id)
3107 Check_Restriction (No_Local_Timing_Events, N);
3109 end Analyze_Object_Declaration;
3111 ---------------------------
3112 -- Analyze_Others_Choice --
3113 ---------------------------
3115 -- Nothing to do for the others choice node itself, the semantic analysis
3116 -- of the others choice will occur as part of the processing of the parent
3118 procedure Analyze_Others_Choice (N : Node_Id) is
3119 pragma Warnings (Off, N);
3122 end Analyze_Others_Choice;
3124 -------------------------------------------
3125 -- Analyze_Private_Extension_Declaration --
3126 -------------------------------------------
3128 procedure Analyze_Private_Extension_Declaration (N : Node_Id) is
3129 T : constant Entity_Id := Defining_Identifier (N);
3130 Indic : constant Node_Id := Subtype_Indication (N);
3131 Parent_Type : Entity_Id;
3132 Parent_Base : Entity_Id;
3135 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
3137 if Is_Non_Empty_List (Interface_List (N)) then
3143 Intf := First (Interface_List (N));
3144 while Present (Intf) loop
3145 T := Find_Type_Of_Subtype_Indic (Intf);
3147 Diagnose_Interface (Intf, T);
3153 Generate_Definition (T);
3156 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
3157 Parent_Base := Base_Type (Parent_Type);
3159 if Parent_Type = Any_Type
3160 or else Etype (Parent_Type) = Any_Type
3162 Set_Ekind (T, Ekind (Parent_Type));
3163 Set_Etype (T, Any_Type);
3166 elsif not Is_Tagged_Type (Parent_Type) then
3168 ("parent of type extension must be a tagged type ", Indic);
3171 elsif Ekind (Parent_Type) = E_Void
3172 or else Ekind (Parent_Type) = E_Incomplete_Type
3174 Error_Msg_N ("premature derivation of incomplete type", Indic);
3177 elsif Is_Concurrent_Type (Parent_Type) then
3179 ("parent type of a private extension cannot be "
3180 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
3182 Set_Etype (T, Any_Type);
3183 Set_Ekind (T, E_Limited_Private_Type);
3184 Set_Private_Dependents (T, New_Elmt_List);
3185 Set_Error_Posted (T);
3189 -- Perhaps the parent type should be changed to the class-wide type's
3190 -- specific type in this case to prevent cascading errors ???
3192 if Is_Class_Wide_Type (Parent_Type) then
3194 ("parent of type extension must not be a class-wide type", Indic);
3198 if (not Is_Package_Or_Generic_Package (Current_Scope)
3199 and then Nkind (Parent (N)) /= N_Generic_Subprogram_Declaration)
3200 or else In_Private_Part (Current_Scope)
3203 Error_Msg_N ("invalid context for private extension", N);
3206 -- Set common attributes
3208 Set_Is_Pure (T, Is_Pure (Current_Scope));
3209 Set_Scope (T, Current_Scope);
3210 Set_Ekind (T, E_Record_Type_With_Private);
3211 Init_Size_Align (T);
3213 Set_Etype (T, Parent_Base);
3214 Set_Has_Task (T, Has_Task (Parent_Base));
3216 Set_Convention (T, Convention (Parent_Type));
3217 Set_First_Rep_Item (T, First_Rep_Item (Parent_Type));
3218 Set_Is_First_Subtype (T);
3219 Make_Class_Wide_Type (T);
3221 if Unknown_Discriminants_Present (N) then
3222 Set_Discriminant_Constraint (T, No_Elist);
3225 Build_Derived_Record_Type (N, Parent_Type, T);
3227 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
3228 -- synchronized formal derived type.
3230 if Ada_Version >= Ada_05
3231 and then Synchronized_Present (N)
3233 Set_Is_Limited_Record (T);
3235 -- Formal derived type case
3237 if Is_Generic_Type (T) then
3239 -- The parent must be a tagged limited type or a synchronized
3242 if (not Is_Tagged_Type (Parent_Type)
3243 or else not Is_Limited_Type (Parent_Type))
3245 (not Is_Interface (Parent_Type)
3246 or else not Is_Synchronized_Interface (Parent_Type))
3248 Error_Msg_NE ("parent type of & must be tagged limited " &
3249 "or synchronized", N, T);
3252 -- The progenitors (if any) must be limited or synchronized
3255 if Present (Interfaces (T)) then
3258 Iface_Elmt : Elmt_Id;
3261 Iface_Elmt := First_Elmt (Interfaces (T));
3262 while Present (Iface_Elmt) loop
3263 Iface := Node (Iface_Elmt);
3265 if not Is_Limited_Interface (Iface)
3266 and then not Is_Synchronized_Interface (Iface)
3268 Error_Msg_NE ("progenitor & must be limited " &
3269 "or synchronized", N, Iface);
3272 Next_Elmt (Iface_Elmt);
3277 -- Regular derived extension, the parent must be a limited or
3278 -- synchronized interface.
3281 if not Is_Interface (Parent_Type)
3282 or else (not Is_Limited_Interface (Parent_Type)
3284 not Is_Synchronized_Interface (Parent_Type))
3287 ("parent type of & must be limited interface", N, T);
3291 elsif Limited_Present (N) then
3292 Set_Is_Limited_Record (T);
3294 if not Is_Limited_Type (Parent_Type)
3296 (not Is_Interface (Parent_Type)
3297 or else not Is_Limited_Interface (Parent_Type))
3299 Error_Msg_NE ("parent type& of limited extension must be limited",
3303 end Analyze_Private_Extension_Declaration;
3305 ---------------------------------
3306 -- Analyze_Subtype_Declaration --
3307 ---------------------------------
3309 procedure Analyze_Subtype_Declaration
3311 Skip : Boolean := False)
3313 Id : constant Entity_Id := Defining_Identifier (N);
3315 R_Checks : Check_Result;
3318 Generate_Definition (Id);
3319 Set_Is_Pure (Id, Is_Pure (Current_Scope));
3320 Init_Size_Align (Id);
3322 -- The following guard condition on Enter_Name is to handle cases where
3323 -- the defining identifier has already been entered into the scope but
3324 -- the declaration as a whole needs to be analyzed.
3326 -- This case in particular happens for derived enumeration types. The
3327 -- derived enumeration type is processed as an inserted enumeration type
3328 -- declaration followed by a rewritten subtype declaration. The defining
3329 -- identifier, however, is entered into the name scope very early in the
3330 -- processing of the original type declaration and therefore needs to be
3331 -- avoided here, when the created subtype declaration is analyzed. (See
3332 -- Build_Derived_Types)
3334 -- This also happens when the full view of a private type is derived
3335 -- type with constraints. In this case the entity has been introduced
3336 -- in the private declaration.
3339 or else (Present (Etype (Id))
3340 and then (Is_Private_Type (Etype (Id))
3341 or else Is_Task_Type (Etype (Id))
3342 or else Is_Rewrite_Substitution (N)))
3350 T := Process_Subtype (Subtype_Indication (N), N, Id, 'P');
3352 -- Inherit common attributes
3354 Set_Is_Generic_Type (Id, Is_Generic_Type (Base_Type (T)));
3355 Set_Is_Volatile (Id, Is_Volatile (T));
3356 Set_Treat_As_Volatile (Id, Treat_As_Volatile (T));
3357 Set_Is_Atomic (Id, Is_Atomic (T));
3358 Set_Is_Ada_2005_Only (Id, Is_Ada_2005_Only (T));
3359 Set_Convention (Id, Convention (T));
3361 -- In the case where there is no constraint given in the subtype
3362 -- indication, Process_Subtype just returns the Subtype_Mark, so its
3363 -- semantic attributes must be established here.
3365 if Nkind (Subtype_Indication (N)) /= N_Subtype_Indication then
3366 Set_Etype (Id, Base_Type (T));
3370 Set_Ekind (Id, E_Array_Subtype);
3371 Copy_Array_Subtype_Attributes (Id, T);
3373 when Decimal_Fixed_Point_Kind =>
3374 Set_Ekind (Id, E_Decimal_Fixed_Point_Subtype);
3375 Set_Digits_Value (Id, Digits_Value (T));
3376 Set_Delta_Value (Id, Delta_Value (T));
3377 Set_Scale_Value (Id, Scale_Value (T));
3378 Set_Small_Value (Id, Small_Value (T));
3379 Set_Scalar_Range (Id, Scalar_Range (T));
3380 Set_Machine_Radix_10 (Id, Machine_Radix_10 (T));
3381 Set_Is_Constrained (Id, Is_Constrained (T));
3382 Set_RM_Size (Id, RM_Size (T));
3384 when Enumeration_Kind =>
3385 Set_Ekind (Id, E_Enumeration_Subtype);
3386 Set_First_Literal (Id, First_Literal (Base_Type (T)));
3387 Set_Scalar_Range (Id, Scalar_Range (T));
3388 Set_Is_Character_Type (Id, Is_Character_Type (T));
3389 Set_Is_Constrained (Id, Is_Constrained (T));
3390 Set_RM_Size (Id, RM_Size (T));
3392 when Ordinary_Fixed_Point_Kind =>
3393 Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype);
3394 Set_Scalar_Range (Id, Scalar_Range (T));
3395 Set_Small_Value (Id, Small_Value (T));
3396 Set_Delta_Value (Id, Delta_Value (T));
3397 Set_Is_Constrained (Id, Is_Constrained (T));
3398 Set_RM_Size (Id, RM_Size (T));
3401 Set_Ekind (Id, E_Floating_Point_Subtype);
3402 Set_Scalar_Range (Id, Scalar_Range (T));
3403 Set_Digits_Value (Id, Digits_Value (T));
3404 Set_Is_Constrained (Id, Is_Constrained (T));
3406 when Signed_Integer_Kind =>
3407 Set_Ekind (Id, E_Signed_Integer_Subtype);
3408 Set_Scalar_Range (Id, Scalar_Range (T));
3409 Set_Is_Constrained (Id, Is_Constrained (T));
3410 Set_RM_Size (Id, RM_Size (T));
3412 when Modular_Integer_Kind =>
3413 Set_Ekind (Id, E_Modular_Integer_Subtype);
3414 Set_Scalar_Range (Id, Scalar_Range (T));
3415 Set_Is_Constrained (Id, Is_Constrained (T));
3416 Set_RM_Size (Id, RM_Size (T));
3418 when Class_Wide_Kind =>
3419 Set_Ekind (Id, E_Class_Wide_Subtype);
3420 Set_First_Entity (Id, First_Entity (T));
3421 Set_Last_Entity (Id, Last_Entity (T));
3422 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3423 Set_Cloned_Subtype (Id, T);
3424 Set_Is_Tagged_Type (Id, True);
3425 Set_Has_Unknown_Discriminants
3428 if Ekind (T) = E_Class_Wide_Subtype then
3429 Set_Equivalent_Type (Id, Equivalent_Type (T));
3432 when E_Record_Type | E_Record_Subtype =>
3433 Set_Ekind (Id, E_Record_Subtype);
3435 if Ekind (T) = E_Record_Subtype
3436 and then Present (Cloned_Subtype (T))
3438 Set_Cloned_Subtype (Id, Cloned_Subtype (T));
3440 Set_Cloned_Subtype (Id, T);
3443 Set_First_Entity (Id, First_Entity (T));
3444 Set_Last_Entity (Id, Last_Entity (T));
3445 Set_Has_Discriminants (Id, Has_Discriminants (T));
3446 Set_Is_Constrained (Id, Is_Constrained (T));
3447 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3448 Set_Has_Unknown_Discriminants
3449 (Id, Has_Unknown_Discriminants (T));
3451 if Has_Discriminants (T) then
3452 Set_Discriminant_Constraint
3453 (Id, Discriminant_Constraint (T));
3454 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3456 elsif Has_Unknown_Discriminants (Id) then
3457 Set_Discriminant_Constraint (Id, No_Elist);
3460 if Is_Tagged_Type (T) then
3461 Set_Is_Tagged_Type (Id);
3462 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3463 Set_Primitive_Operations
3464 (Id, Primitive_Operations (T));
3465 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3467 if Is_Interface (T) then
3468 Set_Is_Interface (Id);
3469 Set_Is_Limited_Interface (Id, Is_Limited_Interface (T));
3473 when Private_Kind =>
3474 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3475 Set_Has_Discriminants (Id, Has_Discriminants (T));
3476 Set_Is_Constrained (Id, Is_Constrained (T));
3477 Set_First_Entity (Id, First_Entity (T));
3478 Set_Last_Entity (Id, Last_Entity (T));
3479 Set_Private_Dependents (Id, New_Elmt_List);
3480 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3481 Set_Has_Unknown_Discriminants
3482 (Id, Has_Unknown_Discriminants (T));
3483 Set_Known_To_Have_Preelab_Init
3484 (Id, Known_To_Have_Preelab_Init (T));
3486 if Is_Tagged_Type (T) then
3487 Set_Is_Tagged_Type (Id);
3488 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3489 Set_Primitive_Operations (Id, Primitive_Operations (T));
3490 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3493 -- In general the attributes of the subtype of a private type
3494 -- are the attributes of the partial view of parent. However,
3495 -- the full view may be a discriminated type, and the subtype
3496 -- must share the discriminant constraint to generate correct
3497 -- calls to initialization procedures.
3499 if Has_Discriminants (T) then
3500 Set_Discriminant_Constraint
3501 (Id, Discriminant_Constraint (T));
3502 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3504 elsif Present (Full_View (T))
3505 and then Has_Discriminants (Full_View (T))
3507 Set_Discriminant_Constraint
3508 (Id, Discriminant_Constraint (Full_View (T)));
3509 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3511 -- This would seem semantically correct, but apparently
3512 -- confuses the back-end. To be explained and checked with
3513 -- current version ???
3515 -- Set_Has_Discriminants (Id);
3518 Prepare_Private_Subtype_Completion (Id, N);
3521 Set_Ekind (Id, E_Access_Subtype);
3522 Set_Is_Constrained (Id, Is_Constrained (T));
3523 Set_Is_Access_Constant
3524 (Id, Is_Access_Constant (T));
3525 Set_Directly_Designated_Type
3526 (Id, Designated_Type (T));
3527 Set_Can_Never_Be_Null (Id, Can_Never_Be_Null (T));
3529 -- A Pure library_item must not contain the declaration of a
3530 -- named access type, except within a subprogram, generic
3531 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
3533 if Comes_From_Source (Id)
3534 and then In_Pure_Unit
3535 and then not In_Subprogram_Task_Protected_Unit
3538 ("named access types not allowed in pure unit", N);
3541 when Concurrent_Kind =>
3542 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3543 Set_Corresponding_Record_Type (Id,
3544 Corresponding_Record_Type (T));
3545 Set_First_Entity (Id, First_Entity (T));
3546 Set_First_Private_Entity (Id, First_Private_Entity (T));
3547 Set_Has_Discriminants (Id, Has_Discriminants (T));
3548 Set_Is_Constrained (Id, Is_Constrained (T));
3549 Set_Is_Tagged_Type (Id, Is_Tagged_Type (T));
3550 Set_Last_Entity (Id, Last_Entity (T));
3552 if Has_Discriminants (T) then
3553 Set_Discriminant_Constraint (Id,
3554 Discriminant_Constraint (T));
3555 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3558 when E_Incomplete_Type =>
3559 if Ada_Version >= Ada_05 then
3560 Set_Ekind (Id, E_Incomplete_Subtype);
3562 -- Ada 2005 (AI-412): Decorate an incomplete subtype
3563 -- of an incomplete type visible through a limited
3566 if From_With_Type (T)
3567 and then Present (Non_Limited_View (T))
3569 Set_From_With_Type (Id);
3570 Set_Non_Limited_View (Id, Non_Limited_View (T));
3572 -- Ada 2005 (AI-412): Add the regular incomplete subtype
3573 -- to the private dependents of the original incomplete
3574 -- type for future transformation.
3577 Append_Elmt (Id, Private_Dependents (T));
3580 -- If the subtype name denotes an incomplete type an error
3581 -- was already reported by Process_Subtype.
3584 Set_Etype (Id, Any_Type);
3588 raise Program_Error;
3592 if Etype (Id) = Any_Type then
3596 -- Some common processing on all types
3598 Set_Size_Info (Id, T);
3599 Set_First_Rep_Item (Id, First_Rep_Item (T));
3603 Set_Is_Immediately_Visible (Id, True);
3604 Set_Depends_On_Private (Id, Has_Private_Component (T));
3605 Set_Is_Descendent_Of_Address (Id, Is_Descendent_Of_Address (T));
3607 if Is_Interface (T) then
3608 Set_Is_Interface (Id);
3611 if Present (Generic_Parent_Type (N))
3614 (Parent (Generic_Parent_Type (N))) /= N_Formal_Type_Declaration
3616 (Formal_Type_Definition (Parent (Generic_Parent_Type (N))))
3617 /= N_Formal_Private_Type_Definition)
3619 if Is_Tagged_Type (Id) then
3621 -- If this is a generic actual subtype for a synchronized type,
3622 -- the primitive operations are those of the corresponding record
3623 -- for which there is a separate subtype declaration.
3625 if Is_Concurrent_Type (Id) then
3627 elsif Is_Class_Wide_Type (Id) then
3628 Derive_Subprograms (Generic_Parent_Type (N), Id, Etype (T));
3630 Derive_Subprograms (Generic_Parent_Type (N), Id, T);
3633 elsif Scope (Etype (Id)) /= Standard_Standard then
3634 Derive_Subprograms (Generic_Parent_Type (N), Id);
3638 if Is_Private_Type (T)
3639 and then Present (Full_View (T))
3641 Conditional_Delay (Id, Full_View (T));
3643 -- The subtypes of components or subcomponents of protected types
3644 -- do not need freeze nodes, which would otherwise appear in the
3645 -- wrong scope (before the freeze node for the protected type). The
3646 -- proper subtypes are those of the subcomponents of the corresponding
3649 elsif Ekind (Scope (Id)) /= E_Protected_Type
3650 and then Present (Scope (Scope (Id))) -- error defense!
3651 and then Ekind (Scope (Scope (Id))) /= E_Protected_Type
3653 Conditional_Delay (Id, T);
3656 -- Check that constraint_error is raised for a scalar subtype
3657 -- indication when the lower or upper bound of a non-null range
3658 -- lies outside the range of the type mark.
3660 if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then
3661 if Is_Scalar_Type (Etype (Id))
3662 and then Scalar_Range (Id) /=
3663 Scalar_Range (Etype (Subtype_Mark
3664 (Subtype_Indication (N))))
3668 Etype (Subtype_Mark (Subtype_Indication (N))));
3670 elsif Is_Array_Type (Etype (Id))
3671 and then Present (First_Index (Id))
3673 -- This really should be a subprogram that finds the indications
3676 if ((Nkind (First_Index (Id)) = N_Identifier
3677 and then Ekind (Entity (First_Index (Id))) in Scalar_Kind)
3678 or else Nkind (First_Index (Id)) = N_Subtype_Indication)
3680 Nkind (Scalar_Range (Etype (First_Index (Id)))) = N_Range
3683 Target_Typ : constant Entity_Id :=
3686 (Subtype_Mark (Subtype_Indication (N)))));
3690 (Scalar_Range (Etype (First_Index (Id))),
3692 Etype (First_Index (Id)),
3693 Defining_Identifier (N));
3699 Sloc (Defining_Identifier (N)));
3705 Set_Optimize_Alignment_Flags (Id);
3706 Check_Eliminated (Id);
3707 end Analyze_Subtype_Declaration;
3709 --------------------------------
3710 -- Analyze_Subtype_Indication --
3711 --------------------------------
3713 procedure Analyze_Subtype_Indication (N : Node_Id) is
3714 T : constant Entity_Id := Subtype_Mark (N);
3715 R : constant Node_Id := Range_Expression (Constraint (N));
3722 Set_Etype (N, Etype (R));
3723 Resolve (R, Entity (T));
3725 Set_Error_Posted (R);
3726 Set_Error_Posted (T);
3728 end Analyze_Subtype_Indication;
3730 ------------------------------
3731 -- Analyze_Type_Declaration --
3732 ------------------------------
3734 procedure Analyze_Type_Declaration (N : Node_Id) is
3735 Def : constant Node_Id := Type_Definition (N);
3736 Def_Id : constant Entity_Id := Defining_Identifier (N);
3740 Is_Remote : constant Boolean :=
3741 (Is_Remote_Types (Current_Scope)
3742 or else Is_Remote_Call_Interface (Current_Scope))
3743 and then not (In_Private_Part (Current_Scope)
3744 or else In_Package_Body (Current_Scope));
3746 procedure Check_Ops_From_Incomplete_Type;
3747 -- If there is a tagged incomplete partial view of the type, transfer
3748 -- its operations to the full view, and indicate that the type of the
3749 -- controlling parameter (s) is this full view.
3751 ------------------------------------
3752 -- Check_Ops_From_Incomplete_Type --
3753 ------------------------------------
3755 procedure Check_Ops_From_Incomplete_Type is
3762 and then Ekind (Prev) = E_Incomplete_Type
3763 and then Is_Tagged_Type (Prev)
3764 and then Is_Tagged_Type (T)
3766 Elmt := First_Elmt (Primitive_Operations (Prev));
3767 while Present (Elmt) loop
3769 Prepend_Elmt (Op, Primitive_Operations (T));
3771 Formal := First_Formal (Op);
3772 while Present (Formal) loop
3773 if Etype (Formal) = Prev then
3774 Set_Etype (Formal, T);
3777 Next_Formal (Formal);
3780 if Etype (Op) = Prev then
3787 end Check_Ops_From_Incomplete_Type;
3789 -- Start of processing for Analyze_Type_Declaration
3792 Prev := Find_Type_Name (N);
3794 -- The full view, if present, now points to the current type
3796 -- Ada 2005 (AI-50217): If the type was previously decorated when
3797 -- imported through a LIMITED WITH clause, it appears as incomplete
3798 -- but has no full view.
3799 -- If the incomplete view is tagged, a class_wide type has been
3800 -- created already. Use it for the full view as well, to prevent
3801 -- multiple incompatible class-wide types that may be created for
3802 -- self-referential anonymous access components.
3804 if Ekind (Prev) = E_Incomplete_Type
3805 and then Present (Full_View (Prev))
3807 T := Full_View (Prev);
3809 if Is_Tagged_Type (Prev)
3810 and then Present (Class_Wide_Type (Prev))
3812 Set_Ekind (T, Ekind (Prev)); -- will be reset later
3813 Set_Class_Wide_Type (T, Class_Wide_Type (Prev));
3814 Set_Etype (Class_Wide_Type (T), T);
3821 Set_Is_Pure (T, Is_Pure (Current_Scope));
3823 -- We set the flag Is_First_Subtype here. It is needed to set the
3824 -- corresponding flag for the Implicit class-wide-type created
3825 -- during tagged types processing.
3827 Set_Is_First_Subtype (T, True);
3829 -- Only composite types other than array types are allowed to have
3834 -- For derived types, the rule will be checked once we've figured
3835 -- out the parent type.
3837 when N_Derived_Type_Definition =>
3840 -- For record types, discriminants are allowed
3842 when N_Record_Definition =>
3846 if Present (Discriminant_Specifications (N)) then
3848 ("elementary or array type cannot have discriminants",
3850 (First (Discriminant_Specifications (N))));
3854 -- Elaborate the type definition according to kind, and generate
3855 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3856 -- already done (this happens during the reanalysis that follows a call
3857 -- to the high level optimizer).
3859 if not Analyzed (T) then
3864 when N_Access_To_Subprogram_Definition =>
3865 Access_Subprogram_Declaration (T, Def);
3867 -- If this is a remote access to subprogram, we must create the
3868 -- equivalent fat pointer type, and related subprograms.
3871 Process_Remote_AST_Declaration (N);
3874 -- Validate categorization rule against access type declaration
3875 -- usually a violation in Pure unit, Shared_Passive unit.
3877 Validate_Access_Type_Declaration (T, N);
3879 when N_Access_To_Object_Definition =>
3880 Access_Type_Declaration (T, Def);
3882 -- Validate categorization rule against access type declaration
3883 -- usually a violation in Pure unit, Shared_Passive unit.
3885 Validate_Access_Type_Declaration (T, N);
3887 -- If we are in a Remote_Call_Interface package and define a
3888 -- RACW, then calling stubs and specific stream attributes
3892 and then Is_Remote_Access_To_Class_Wide_Type (Def_Id)
3894 Add_RACW_Features (Def_Id);
3897 -- Set no strict aliasing flag if config pragma seen
3899 if Opt.No_Strict_Aliasing then
3900 Set_No_Strict_Aliasing (Base_Type (Def_Id));
3903 when N_Array_Type_Definition =>
3904 Array_Type_Declaration (T, Def);
3906 when N_Derived_Type_Definition =>
3907 Derived_Type_Declaration (T, N, T /= Def_Id);
3909 when N_Enumeration_Type_Definition =>
3910 Enumeration_Type_Declaration (T, Def);
3912 when N_Floating_Point_Definition =>
3913 Floating_Point_Type_Declaration (T, Def);
3915 when N_Decimal_Fixed_Point_Definition =>
3916 Decimal_Fixed_Point_Type_Declaration (T, Def);
3918 when N_Ordinary_Fixed_Point_Definition =>
3919 Ordinary_Fixed_Point_Type_Declaration (T, Def);
3921 when N_Signed_Integer_Type_Definition =>
3922 Signed_Integer_Type_Declaration (T, Def);
3924 when N_Modular_Type_Definition =>
3925 Modular_Type_Declaration (T, Def);
3927 when N_Record_Definition =>
3928 Record_Type_Declaration (T, N, Prev);
3931 raise Program_Error;
3936 if Etype (T) = Any_Type then
3940 -- Some common processing for all types
3942 Set_Depends_On_Private (T, Has_Private_Component (T));
3943 Check_Ops_From_Incomplete_Type;
3945 -- Both the declared entity, and its anonymous base type if one
3946 -- was created, need freeze nodes allocated.
3949 B : constant Entity_Id := Base_Type (T);
3952 -- In the case where the base type differs from the first subtype, we
3953 -- pre-allocate a freeze node, and set the proper link to the first
3954 -- subtype. Freeze_Entity will use this preallocated freeze node when
3955 -- it freezes the entity.
3958 Ensure_Freeze_Node (B);
3959 Set_First_Subtype_Link (Freeze_Node (B), T);
3962 if not From_With_Type (T) then
3963 Set_Has_Delayed_Freeze (T);
3967 -- Case of T is the full declaration of some private type which has
3968 -- been swapped in Defining_Identifier (N).
3970 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3971 Process_Full_View (N, T, Def_Id);
3973 -- Record the reference. The form of this is a little strange, since
3974 -- the full declaration has been swapped in. So the first parameter
3975 -- here represents the entity to which a reference is made which is
3976 -- the "real" entity, i.e. the one swapped in, and the second
3977 -- parameter provides the reference location.
3979 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3980 -- since we don't want a complaint about the full type being an
3981 -- unwanted reference to the private type
3984 B : constant Boolean := Has_Pragma_Unreferenced (T);
3986 Set_Has_Pragma_Unreferenced (T, False);
3987 Generate_Reference (T, T, 'c');
3988 Set_Has_Pragma_Unreferenced (T, B);
3991 Set_Completion_Referenced (Def_Id);
3993 -- For completion of incomplete type, process incomplete dependents
3994 -- and always mark the full type as referenced (it is the incomplete
3995 -- type that we get for any real reference).
3997 elsif Ekind (Prev) = E_Incomplete_Type then
3998 Process_Incomplete_Dependents (N, T, Prev);
3999 Generate_Reference (Prev, Def_Id, 'c');
4000 Set_Completion_Referenced (Def_Id);
4002 -- If not private type or incomplete type completion, this is a real
4003 -- definition of a new entity, so record it.
4006 Generate_Definition (Def_Id);
4009 if Chars (Scope (Def_Id)) = Name_System
4010 and then Chars (Def_Id) = Name_Address
4011 and then Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (N)))
4013 Set_Is_Descendent_Of_Address (Def_Id);
4014 Set_Is_Descendent_Of_Address (Base_Type (Def_Id));
4015 Set_Is_Descendent_Of_Address (Prev);
4018 Set_Optimize_Alignment_Flags (Def_Id);
4019 Check_Eliminated (Def_Id);
4020 end Analyze_Type_Declaration;
4022 --------------------------
4023 -- Analyze_Variant_Part --
4024 --------------------------
4026 procedure Analyze_Variant_Part (N : Node_Id) is
4028 procedure Non_Static_Choice_Error (Choice : Node_Id);
4029 -- Error routine invoked by the generic instantiation below when the
4030 -- variant part has a non static choice.
4032 procedure Process_Declarations (Variant : Node_Id);
4033 -- Analyzes all the declarations associated with a Variant. Needed by
4034 -- the generic instantiation below.
4036 package Variant_Choices_Processing is new
4037 Generic_Choices_Processing
4038 (Get_Alternatives => Variants,
4039 Get_Choices => Discrete_Choices,
4040 Process_Empty_Choice => No_OP,
4041 Process_Non_Static_Choice => Non_Static_Choice_Error,
4042 Process_Associated_Node => Process_Declarations);
4043 use Variant_Choices_Processing;
4044 -- Instantiation of the generic choice processing package
4046 -----------------------------
4047 -- Non_Static_Choice_Error --
4048 -----------------------------
4050 procedure Non_Static_Choice_Error (Choice : Node_Id) is
4052 Flag_Non_Static_Expr
4053 ("choice given in variant part is not static!", Choice);
4054 end Non_Static_Choice_Error;
4056 --------------------------
4057 -- Process_Declarations --
4058 --------------------------
4060 procedure Process_Declarations (Variant : Node_Id) is
4062 if not Null_Present (Component_List (Variant)) then
4063 Analyze_Declarations (Component_Items (Component_List (Variant)));
4065 if Present (Variant_Part (Component_List (Variant))) then
4066 Analyze (Variant_Part (Component_List (Variant)));
4069 end Process_Declarations;
4073 Discr_Name : Node_Id;
4074 Discr_Type : Entity_Id;
4076 Case_Table : Choice_Table_Type (1 .. Number_Of_Choices (N));
4078 Dont_Care : Boolean;
4079 Others_Present : Boolean := False;
4081 pragma Warnings (Off, Case_Table);
4082 pragma Warnings (Off, Last_Choice);
4083 pragma Warnings (Off, Dont_Care);
4084 pragma Warnings (Off, Others_Present);
4085 -- We don't care about the assigned values of any of these
4087 -- Start of processing for Analyze_Variant_Part
4090 Discr_Name := Name (N);
4091 Analyze (Discr_Name);
4093 -- If Discr_Name bad, get out (prevent cascaded errors)
4095 if Etype (Discr_Name) = Any_Type then
4099 -- Check invalid discriminant in variant part
4101 if Ekind (Entity (Discr_Name)) /= E_Discriminant then
4102 Error_Msg_N ("invalid discriminant name in variant part", Discr_Name);
4105 Discr_Type := Etype (Entity (Discr_Name));
4107 if not Is_Discrete_Type (Discr_Type) then
4109 ("discriminant in a variant part must be of a discrete type",
4114 -- Call the instantiated Analyze_Choices which does the rest of the work
4117 (N, Discr_Type, Case_Table, Last_Choice, Dont_Care, Others_Present);
4118 end Analyze_Variant_Part;
4120 ----------------------------
4121 -- Array_Type_Declaration --
4122 ----------------------------
4124 procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id) is
4125 Component_Def : constant Node_Id := Component_Definition (Def);
4126 Element_Type : Entity_Id;
4127 Implicit_Base : Entity_Id;
4129 Related_Id : Entity_Id := Empty;
4131 P : constant Node_Id := Parent (Def);
4135 if Nkind (Def) = N_Constrained_Array_Definition then
4136 Index := First (Discrete_Subtype_Definitions (Def));
4138 Index := First (Subtype_Marks (Def));
4141 -- Find proper names for the implicit types which may be public. In case
4142 -- of anonymous arrays we use the name of the first object of that type
4146 Related_Id := Defining_Identifier (P);
4152 while Present (Index) loop
4155 -- Add a subtype declaration for each index of private array type
4156 -- declaration whose etype is also private. For example:
4159 -- type Index is private;
4161 -- type Table is array (Index) of ...
4164 -- This is currently required by the expander for the internally
4165 -- generated equality subprogram of records with variant parts in
4166 -- which the etype of some component is such private type.
4168 if Ekind (Current_Scope) = E_Package
4169 and then In_Private_Part (Current_Scope)
4170 and then Has_Private_Declaration (Etype (Index))
4173 Loc : constant Source_Ptr := Sloc (Def);
4179 Make_Defining_Identifier (Loc,
4180 Chars => New_Internal_Name ('T'));
4181 Set_Is_Internal (New_E);
4184 Make_Subtype_Declaration (Loc,
4185 Defining_Identifier => New_E,
4186 Subtype_Indication =>
4187 New_Occurrence_Of (Etype (Index), Loc));
4189 Insert_Before (Parent (Def), Decl);
4191 Set_Etype (Index, New_E);
4193 -- If the index is a range the Entity attribute is not
4194 -- available. Example:
4197 -- type T is private;
4199 -- type T is new Natural;
4200 -- Table : array (T(1) .. T(10)) of Boolean;
4203 if Nkind (Index) /= N_Range then
4204 Set_Entity (Index, New_E);
4209 Make_Index (Index, P, Related_Id, Nb_Index);
4211 Nb_Index := Nb_Index + 1;
4214 -- Process subtype indication if one is present
4216 if Present (Subtype_Indication (Component_Def)) then
4219 (Subtype_Indication (Component_Def), P, Related_Id, 'C');
4221 -- Ada 2005 (AI-230): Access Definition case
4223 else pragma Assert (Present (Access_Definition (Component_Def)));
4225 -- Indicate that the anonymous access type is created by the
4226 -- array type declaration.
4228 Element_Type := Access_Definition
4230 N => Access_Definition (Component_Def));
4231 Set_Is_Local_Anonymous_Access (Element_Type);
4233 -- Propagate the parent. This field is needed if we have to generate
4234 -- the master_id associated with an anonymous access to task type
4235 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
4237 Set_Parent (Element_Type, Parent (T));
4239 -- Ada 2005 (AI-230): In case of components that are anonymous access
4240 -- types the level of accessibility depends on the enclosing type
4243 Set_Scope (Element_Type, Current_Scope); -- Ada 2005 (AI-230)
4245 -- Ada 2005 (AI-254)
4248 CD : constant Node_Id :=
4249 Access_To_Subprogram_Definition
4250 (Access_Definition (Component_Def));
4252 if Present (CD) and then Protected_Present (CD) then
4254 Replace_Anonymous_Access_To_Protected_Subprogram (Def);
4259 -- Constrained array case
4262 T := Create_Itype (E_Void, P, Related_Id, 'T');
4265 if Nkind (Def) = N_Constrained_Array_Definition then
4267 -- Establish Implicit_Base as unconstrained base type
4269 Implicit_Base := Create_Itype (E_Array_Type, P, Related_Id, 'B');
4271 Set_Etype (Implicit_Base, Implicit_Base);
4272 Set_Scope (Implicit_Base, Current_Scope);
4273 Set_Has_Delayed_Freeze (Implicit_Base);
4275 -- The constrained array type is a subtype of the unconstrained one
4277 Set_Ekind (T, E_Array_Subtype);
4278 Init_Size_Align (T);
4279 Set_Etype (T, Implicit_Base);
4280 Set_Scope (T, Current_Scope);
4281 Set_Is_Constrained (T, True);
4282 Set_First_Index (T, First (Discrete_Subtype_Definitions (Def)));
4283 Set_Has_Delayed_Freeze (T);
4285 -- Complete setup of implicit base type
4287 Set_First_Index (Implicit_Base, First_Index (T));
4288 Set_Component_Type (Implicit_Base, Element_Type);
4289 Set_Has_Task (Implicit_Base, Has_Task (Element_Type));
4290 Set_Component_Size (Implicit_Base, Uint_0);
4291 Set_Packed_Array_Type (Implicit_Base, Empty);
4292 Set_Has_Controlled_Component
4293 (Implicit_Base, Has_Controlled_Component
4295 or else Is_Controlled
4297 Set_Finalize_Storage_Only
4298 (Implicit_Base, Finalize_Storage_Only
4301 -- Unconstrained array case
4304 Set_Ekind (T, E_Array_Type);
4305 Init_Size_Align (T);
4307 Set_Scope (T, Current_Scope);
4308 Set_Component_Size (T, Uint_0);
4309 Set_Is_Constrained (T, False);
4310 Set_First_Index (T, First (Subtype_Marks (Def)));
4311 Set_Has_Delayed_Freeze (T, True);
4312 Set_Has_Task (T, Has_Task (Element_Type));
4313 Set_Has_Controlled_Component (T, Has_Controlled_Component
4316 Is_Controlled (Element_Type));
4317 Set_Finalize_Storage_Only (T, Finalize_Storage_Only
4321 -- Common attributes for both cases
4323 Set_Component_Type (Base_Type (T), Element_Type);
4324 Set_Packed_Array_Type (T, Empty);
4326 if Aliased_Present (Component_Definition (Def)) then
4327 Set_Has_Aliased_Components (Etype (T));
4330 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
4331 -- array type to ensure that objects of this type are initialized.
4333 if Ada_Version >= Ada_05
4334 and then Can_Never_Be_Null (Element_Type)
4336 Set_Can_Never_Be_Null (T);
4338 if Null_Exclusion_Present (Component_Definition (Def))
4340 -- No need to check itypes because in their case this check was
4341 -- done at their point of creation
4343 and then not Is_Itype (Element_Type)
4346 ("`NOT NULL` not allowed (null already excluded)",
4347 Subtype_Indication (Component_Definition (Def)));
4351 Priv := Private_Component (Element_Type);
4353 if Present (Priv) then
4355 -- Check for circular definitions
4357 if Priv = Any_Type then
4358 Set_Component_Type (Etype (T), Any_Type);
4360 -- There is a gap in the visibility of operations on the composite
4361 -- type only if the component type is defined in a different scope.
4363 elsif Scope (Priv) = Current_Scope then
4366 elsif Is_Limited_Type (Priv) then
4367 Set_Is_Limited_Composite (Etype (T));
4368 Set_Is_Limited_Composite (T);
4370 Set_Is_Private_Composite (Etype (T));
4371 Set_Is_Private_Composite (T);
4375 -- A syntax error in the declaration itself may lead to an empty index
4376 -- list, in which case do a minimal patch.
4378 if No (First_Index (T)) then
4379 Error_Msg_N ("missing index definition in array type declaration", T);
4382 Indices : constant List_Id :=
4383 New_List (New_Occurrence_Of (Any_Id, Sloc (T)));
4385 Set_Discrete_Subtype_Definitions (Def, Indices);
4386 Set_First_Index (T, First (Indices));
4391 -- Create a concatenation operator for the new type. Internal array
4392 -- types created for packed entities do not need such, they are
4393 -- compatible with the user-defined type.
4395 if Number_Dimensions (T) = 1
4396 and then not Is_Packed_Array_Type (T)
4398 New_Concatenation_Op (T);
4401 -- In the case of an unconstrained array the parser has already verified
4402 -- that all the indices are unconstrained but we still need to make sure
4403 -- that the element type is constrained.
4405 if Is_Indefinite_Subtype (Element_Type) then
4407 ("unconstrained element type in array declaration",
4408 Subtype_Indication (Component_Def));
4410 elsif Is_Abstract_Type (Element_Type) then
4412 ("the type of a component cannot be abstract",
4413 Subtype_Indication (Component_Def));
4415 end Array_Type_Declaration;
4417 ------------------------------------------------------
4418 -- Replace_Anonymous_Access_To_Protected_Subprogram --
4419 ------------------------------------------------------
4421 function Replace_Anonymous_Access_To_Protected_Subprogram
4422 (N : Node_Id) return Entity_Id
4424 Loc : constant Source_Ptr := Sloc (N);
4426 Curr_Scope : constant Scope_Stack_Entry :=
4427 Scope_Stack.Table (Scope_Stack.Last);
4429 Anon : constant Entity_Id :=
4430 Make_Defining_Identifier (Loc,
4431 Chars => New_Internal_Name ('S'));
4439 Set_Is_Internal (Anon);
4442 when N_Component_Declaration |
4443 N_Unconstrained_Array_Definition |
4444 N_Constrained_Array_Definition =>
4445 Comp := Component_Definition (N);
4446 Acc := Access_Definition (Comp);
4448 when N_Discriminant_Specification =>
4449 Comp := Discriminant_Type (N);
4452 when N_Parameter_Specification =>
4453 Comp := Parameter_Type (N);
4456 when N_Access_Function_Definition =>
4457 Comp := Result_Definition (N);
4460 when N_Object_Declaration =>
4461 Comp := Object_Definition (N);
4464 when N_Function_Specification =>
4465 Comp := Result_Definition (N);
4469 raise Program_Error;
4472 Decl := Make_Full_Type_Declaration (Loc,
4473 Defining_Identifier => Anon,
4475 Copy_Separate_Tree (Access_To_Subprogram_Definition (Acc)));
4477 Mark_Rewrite_Insertion (Decl);
4479 -- Insert the new declaration in the nearest enclosing scope
4482 while Present (P) and then not Has_Declarations (P) loop
4486 pragma Assert (Present (P));
4488 if Nkind (P) = N_Package_Specification then
4489 Prepend (Decl, Visible_Declarations (P));
4491 Prepend (Decl, Declarations (P));
4494 -- Replace the anonymous type with an occurrence of the new declaration.
4495 -- In all cases the rewritten node does not have the null-exclusion
4496 -- attribute because (if present) it was already inherited by the
4497 -- anonymous entity (Anon). Thus, in case of components we do not
4498 -- inherit this attribute.
4500 if Nkind (N) = N_Parameter_Specification then
4501 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4502 Set_Etype (Defining_Identifier (N), Anon);
4503 Set_Null_Exclusion_Present (N, False);
4505 elsif Nkind (N) = N_Object_Declaration then
4506 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4507 Set_Etype (Defining_Identifier (N), Anon);
4509 elsif Nkind (N) = N_Access_Function_Definition then
4510 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4512 elsif Nkind (N) = N_Function_Specification then
4513 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4514 Set_Etype (Defining_Unit_Name (N), Anon);
4518 Make_Component_Definition (Loc,
4519 Subtype_Indication => New_Occurrence_Of (Anon, Loc)));
4522 Mark_Rewrite_Insertion (Comp);
4524 -- Temporarily remove the current scope from the stack to add the new
4525 -- declarations to the enclosing scope
4527 if Nkind_In (N, N_Object_Declaration, N_Access_Function_Definition) then
4531 Scope_Stack.Decrement_Last;
4533 Set_Is_Itype (Anon);
4534 Scope_Stack.Append (Curr_Scope);
4537 Set_Ekind (Anon, E_Anonymous_Access_Protected_Subprogram_Type);
4538 Set_Can_Use_Internal_Rep (Anon, not Always_Compatible_Rep_On_Target);
4540 end Replace_Anonymous_Access_To_Protected_Subprogram;
4542 -------------------------------
4543 -- Build_Derived_Access_Type --
4544 -------------------------------
4546 procedure Build_Derived_Access_Type
4548 Parent_Type : Entity_Id;
4549 Derived_Type : Entity_Id)
4551 S : constant Node_Id := Subtype_Indication (Type_Definition (N));
4553 Desig_Type : Entity_Id;
4555 Discr_Con_Elist : Elist_Id;
4556 Discr_Con_El : Elmt_Id;
4560 -- Set the designated type so it is available in case this is an access
4561 -- to a self-referential type, e.g. a standard list type with a next
4562 -- pointer. Will be reset after subtype is built.
4564 Set_Directly_Designated_Type
4565 (Derived_Type, Designated_Type (Parent_Type));
4567 Subt := Process_Subtype (S, N);
4569 if Nkind (S) /= N_Subtype_Indication
4570 and then Subt /= Base_Type (Subt)
4572 Set_Ekind (Derived_Type, E_Access_Subtype);
4575 if Ekind (Derived_Type) = E_Access_Subtype then
4577 Pbase : constant Entity_Id := Base_Type (Parent_Type);
4578 Ibase : constant Entity_Id :=
4579 Create_Itype (Ekind (Pbase), N, Derived_Type, 'B');
4580 Svg_Chars : constant Name_Id := Chars (Ibase);
4581 Svg_Next_E : constant Entity_Id := Next_Entity (Ibase);
4584 Copy_Node (Pbase, Ibase);
4586 Set_Chars (Ibase, Svg_Chars);
4587 Set_Next_Entity (Ibase, Svg_Next_E);
4588 Set_Sloc (Ibase, Sloc (Derived_Type));
4589 Set_Scope (Ibase, Scope (Derived_Type));
4590 Set_Freeze_Node (Ibase, Empty);
4591 Set_Is_Frozen (Ibase, False);
4592 Set_Comes_From_Source (Ibase, False);
4593 Set_Is_First_Subtype (Ibase, False);
4595 Set_Etype (Ibase, Pbase);
4596 Set_Etype (Derived_Type, Ibase);
4600 Set_Directly_Designated_Type
4601 (Derived_Type, Designated_Type (Subt));
4603 Set_Is_Constrained (Derived_Type, Is_Constrained (Subt));
4604 Set_Is_Access_Constant (Derived_Type, Is_Access_Constant (Parent_Type));
4605 Set_Size_Info (Derived_Type, Parent_Type);
4606 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
4607 Set_Depends_On_Private (Derived_Type,
4608 Has_Private_Component (Derived_Type));
4609 Conditional_Delay (Derived_Type, Subt);
4611 -- Ada 2005 (AI-231). Set the null-exclusion attribute
4613 if Null_Exclusion_Present (Type_Definition (N))
4614 or else Can_Never_Be_Null (Parent_Type)
4616 Set_Can_Never_Be_Null (Derived_Type);
4619 -- Note: we do not copy the Storage_Size_Variable, since we always go to
4620 -- the root type for this information.
4622 -- Apply range checks to discriminants for derived record case
4623 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
4625 Desig_Type := Designated_Type (Derived_Type);
4626 if Is_Composite_Type (Desig_Type)
4627 and then (not Is_Array_Type (Desig_Type))
4628 and then Has_Discriminants (Desig_Type)
4629 and then Base_Type (Desig_Type) /= Desig_Type
4631 Discr_Con_Elist := Discriminant_Constraint (Desig_Type);
4632 Discr_Con_El := First_Elmt (Discr_Con_Elist);
4634 Discr := First_Discriminant (Base_Type (Desig_Type));
4635 while Present (Discr_Con_El) loop
4636 Apply_Range_Check (Node (Discr_Con_El), Etype (Discr));
4637 Next_Elmt (Discr_Con_El);
4638 Next_Discriminant (Discr);
4641 end Build_Derived_Access_Type;
4643 ------------------------------
4644 -- Build_Derived_Array_Type --
4645 ------------------------------
4647 procedure Build_Derived_Array_Type
4649 Parent_Type : Entity_Id;
4650 Derived_Type : Entity_Id)
4652 Loc : constant Source_Ptr := Sloc (N);
4653 Tdef : constant Node_Id := Type_Definition (N);
4654 Indic : constant Node_Id := Subtype_Indication (Tdef);
4655 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
4656 Implicit_Base : Entity_Id;
4657 New_Indic : Node_Id;
4659 procedure Make_Implicit_Base;
4660 -- If the parent subtype is constrained, the derived type is a subtype
4661 -- of an implicit base type derived from the parent base.
4663 ------------------------
4664 -- Make_Implicit_Base --
4665 ------------------------
4667 procedure Make_Implicit_Base is
4670 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
4672 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
4673 Set_Etype (Implicit_Base, Parent_Base);
4675 Copy_Array_Subtype_Attributes (Implicit_Base, Parent_Base);
4676 Copy_Array_Base_Type_Attributes (Implicit_Base, Parent_Base);
4678 Set_Has_Delayed_Freeze (Implicit_Base, True);
4679 end Make_Implicit_Base;
4681 -- Start of processing for Build_Derived_Array_Type
4684 if not Is_Constrained (Parent_Type) then
4685 if Nkind (Indic) /= N_Subtype_Indication then
4686 Set_Ekind (Derived_Type, E_Array_Type);
4688 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4689 Copy_Array_Base_Type_Attributes (Derived_Type, Parent_Type);
4691 Set_Has_Delayed_Freeze (Derived_Type, True);
4695 Set_Etype (Derived_Type, Implicit_Base);
4698 Make_Subtype_Declaration (Loc,
4699 Defining_Identifier => Derived_Type,
4700 Subtype_Indication =>
4701 Make_Subtype_Indication (Loc,
4702 Subtype_Mark => New_Reference_To (Implicit_Base, Loc),
4703 Constraint => Constraint (Indic)));
4705 Rewrite (N, New_Indic);
4710 if Nkind (Indic) /= N_Subtype_Indication then
4713 Set_Ekind (Derived_Type, Ekind (Parent_Type));
4714 Set_Etype (Derived_Type, Implicit_Base);
4715 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4718 Error_Msg_N ("illegal constraint on constrained type", Indic);
4722 -- If parent type is not a derived type itself, and is declared in
4723 -- closed scope (e.g. a subprogram), then we must explicitly introduce
4724 -- the new type's concatenation operator since Derive_Subprograms
4725 -- will not inherit the parent's operator. If the parent type is
4726 -- unconstrained, the operator is of the unconstrained base type.
4728 if Number_Dimensions (Parent_Type) = 1
4729 and then not Is_Limited_Type (Parent_Type)
4730 and then not Is_Derived_Type (Parent_Type)
4731 and then not Is_Package_Or_Generic_Package
4732 (Scope (Base_Type (Parent_Type)))
4734 if not Is_Constrained (Parent_Type)
4735 and then Is_Constrained (Derived_Type)
4737 New_Concatenation_Op (Implicit_Base);
4739 New_Concatenation_Op (Derived_Type);
4742 end Build_Derived_Array_Type;
4744 -----------------------------------
4745 -- Build_Derived_Concurrent_Type --
4746 -----------------------------------
4748 procedure Build_Derived_Concurrent_Type
4750 Parent_Type : Entity_Id;
4751 Derived_Type : Entity_Id)
4753 D_Constraint : Node_Id;
4754 Disc_Spec : Node_Id;
4755 Old_Disc : Entity_Id;
4756 New_Disc : Entity_Id;
4758 Constraint_Present : constant Boolean :=
4759 Nkind (Subtype_Indication (Type_Definition (N)))
4760 = N_Subtype_Indication;
4763 Set_Stored_Constraint (Derived_Type, No_Elist);
4765 -- Copy Storage_Size and Relative_Deadline variables if task case
4767 if Is_Task_Type (Parent_Type) then
4768 Set_Storage_Size_Variable (Derived_Type,
4769 Storage_Size_Variable (Parent_Type));
4770 Set_Relative_Deadline_Variable (Derived_Type,
4771 Relative_Deadline_Variable (Parent_Type));
4774 if Present (Discriminant_Specifications (N)) then
4775 Push_Scope (Derived_Type);
4776 Check_Or_Process_Discriminants (N, Derived_Type);
4779 elsif Constraint_Present then
4781 -- Build constrained subtype and derive from it
4784 Loc : constant Source_Ptr := Sloc (N);
4785 Anon : constant Entity_Id :=
4786 Make_Defining_Identifier (Loc,
4787 New_External_Name (Chars (Derived_Type), 'T'));
4792 Make_Subtype_Declaration (Loc,
4793 Defining_Identifier => Anon,
4794 Subtype_Indication =>
4795 Subtype_Indication (Type_Definition (N)));
4796 Insert_Before (N, Decl);
4799 Rewrite (Subtype_Indication (Type_Definition (N)),
4800 New_Occurrence_Of (Anon, Loc));
4801 Set_Analyzed (Derived_Type, False);
4807 -- All attributes are inherited from parent. In particular,
4808 -- entries and the corresponding record type are the same.
4809 -- Discriminants may be renamed, and must be treated separately.
4811 Set_Has_Discriminants
4812 (Derived_Type, Has_Discriminants (Parent_Type));
4813 Set_Corresponding_Record_Type
4814 (Derived_Type, Corresponding_Record_Type (Parent_Type));
4816 -- Is_Constrained is set according the parent subtype, but is set to
4817 -- False if the derived type is declared with new discriminants.
4821 (Is_Constrained (Parent_Type) or else Constraint_Present)
4822 and then not Present (Discriminant_Specifications (N)));
4824 if Constraint_Present then
4825 if not Has_Discriminants (Parent_Type) then
4826 Error_Msg_N ("untagged parent must have discriminants", N);
4828 elsif Present (Discriminant_Specifications (N)) then
4830 -- Verify that new discriminants are used to constrain old ones
4835 (Constraint (Subtype_Indication (Type_Definition (N)))));
4837 Old_Disc := First_Discriminant (Parent_Type);
4838 New_Disc := First_Discriminant (Derived_Type);
4839 Disc_Spec := First (Discriminant_Specifications (N));
4840 while Present (Old_Disc) and then Present (Disc_Spec) loop
4841 if Nkind (Discriminant_Type (Disc_Spec)) /=
4844 Analyze (Discriminant_Type (Disc_Spec));
4846 if not Subtypes_Statically_Compatible (
4847 Etype (Discriminant_Type (Disc_Spec)),
4851 ("not statically compatible with parent discriminant",
4852 Discriminant_Type (Disc_Spec));
4856 if Nkind (D_Constraint) = N_Identifier
4857 and then Chars (D_Constraint) /=
4858 Chars (Defining_Identifier (Disc_Spec))
4860 Error_Msg_N ("new discriminants must constrain old ones",
4863 Set_Corresponding_Discriminant (New_Disc, Old_Disc);
4866 Next_Discriminant (Old_Disc);
4867 Next_Discriminant (New_Disc);
4871 if Present (Old_Disc) or else Present (Disc_Spec) then
4872 Error_Msg_N ("discriminant mismatch in derivation", N);
4877 elsif Present (Discriminant_Specifications (N)) then
4879 ("missing discriminant constraint in untagged derivation",
4883 if Present (Discriminant_Specifications (N)) then
4884 Old_Disc := First_Discriminant (Parent_Type);
4885 while Present (Old_Disc) loop
4887 if No (Next_Entity (Old_Disc))
4888 or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant
4890 Set_Next_Entity (Last_Entity (Derived_Type),
4891 Next_Entity (Old_Disc));
4895 Next_Discriminant (Old_Disc);
4899 Set_First_Entity (Derived_Type, First_Entity (Parent_Type));
4900 if Has_Discriminants (Parent_Type) then
4901 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
4902 Set_Discriminant_Constraint (
4903 Derived_Type, Discriminant_Constraint (Parent_Type));
4907 Set_Last_Entity (Derived_Type, Last_Entity (Parent_Type));
4909 Set_Has_Completion (Derived_Type);
4910 end Build_Derived_Concurrent_Type;
4912 ------------------------------------
4913 -- Build_Derived_Enumeration_Type --
4914 ------------------------------------
4916 procedure Build_Derived_Enumeration_Type
4918 Parent_Type : Entity_Id;
4919 Derived_Type : Entity_Id)
4921 Loc : constant Source_Ptr := Sloc (N);
4922 Def : constant Node_Id := Type_Definition (N);
4923 Indic : constant Node_Id := Subtype_Indication (Def);
4924 Implicit_Base : Entity_Id;
4925 Literal : Entity_Id;
4926 New_Lit : Entity_Id;
4927 Literals_List : List_Id;
4928 Type_Decl : Node_Id;
4930 Rang_Expr : Node_Id;
4933 -- Since types Standard.Character and Standard.Wide_Character do
4934 -- not have explicit literals lists we need to process types derived
4935 -- from them specially. This is handled by Derived_Standard_Character.
4936 -- If the parent type is a generic type, there are no literals either,
4937 -- and we construct the same skeletal representation as for the generic
4940 if Is_Standard_Character_Type (Parent_Type) then
4941 Derived_Standard_Character (N, Parent_Type, Derived_Type);
4943 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
4950 Make_Attribute_Reference (Loc,
4951 Attribute_Name => Name_First,
4952 Prefix => New_Reference_To (Derived_Type, Loc));
4953 Set_Etype (Lo, Derived_Type);
4956 Make_Attribute_Reference (Loc,
4957 Attribute_Name => Name_Last,
4958 Prefix => New_Reference_To (Derived_Type, Loc));
4959 Set_Etype (Hi, Derived_Type);
4961 Set_Scalar_Range (Derived_Type,
4968 -- If a constraint is present, analyze the bounds to catch
4969 -- premature usage of the derived literals.
4971 if Nkind (Indic) = N_Subtype_Indication
4972 and then Nkind (Range_Expression (Constraint (Indic))) = N_Range
4974 Analyze (Low_Bound (Range_Expression (Constraint (Indic))));
4975 Analyze (High_Bound (Range_Expression (Constraint (Indic))));
4978 -- Introduce an implicit base type for the derived type even if there
4979 -- is no constraint attached to it, since this seems closer to the
4980 -- Ada semantics. Build a full type declaration tree for the derived
4981 -- type using the implicit base type as the defining identifier. The
4982 -- build a subtype declaration tree which applies the constraint (if
4983 -- any) have it replace the derived type declaration.
4985 Literal := First_Literal (Parent_Type);
4986 Literals_List := New_List;
4987 while Present (Literal)
4988 and then Ekind (Literal) = E_Enumeration_Literal
4990 -- Literals of the derived type have the same representation as
4991 -- those of the parent type, but this representation can be
4992 -- overridden by an explicit representation clause. Indicate
4993 -- that there is no explicit representation given yet. These
4994 -- derived literals are implicit operations of the new type,
4995 -- and can be overridden by explicit ones.
4997 if Nkind (Literal) = N_Defining_Character_Literal then
4999 Make_Defining_Character_Literal (Loc, Chars (Literal));
5001 New_Lit := Make_Defining_Identifier (Loc, Chars (Literal));
5004 Set_Ekind (New_Lit, E_Enumeration_Literal);
5005 Set_Enumeration_Pos (New_Lit, Enumeration_Pos (Literal));
5006 Set_Enumeration_Rep (New_Lit, Enumeration_Rep (Literal));
5007 Set_Enumeration_Rep_Expr (New_Lit, Empty);
5008 Set_Alias (New_Lit, Literal);
5009 Set_Is_Known_Valid (New_Lit, True);
5011 Append (New_Lit, Literals_List);
5012 Next_Literal (Literal);
5016 Make_Defining_Identifier (Sloc (Derived_Type),
5017 New_External_Name (Chars (Derived_Type), 'B'));
5019 -- Indicate the proper nature of the derived type. This must be done
5020 -- before analysis of the literals, to recognize cases when a literal
5021 -- may be hidden by a previous explicit function definition (cf.
5024 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
5025 Set_Etype (Derived_Type, Implicit_Base);
5028 Make_Full_Type_Declaration (Loc,
5029 Defining_Identifier => Implicit_Base,
5030 Discriminant_Specifications => No_List,
5032 Make_Enumeration_Type_Definition (Loc, Literals_List));
5034 Mark_Rewrite_Insertion (Type_Decl);
5035 Insert_Before (N, Type_Decl);
5036 Analyze (Type_Decl);
5038 -- After the implicit base is analyzed its Etype needs to be changed
5039 -- to reflect the fact that it is derived from the parent type which
5040 -- was ignored during analysis. We also set the size at this point.
5042 Set_Etype (Implicit_Base, Parent_Type);
5044 Set_Size_Info (Implicit_Base, Parent_Type);
5045 Set_RM_Size (Implicit_Base, RM_Size (Parent_Type));
5046 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Type));
5048 Set_Has_Non_Standard_Rep
5049 (Implicit_Base, Has_Non_Standard_Rep
5051 Set_Has_Delayed_Freeze (Implicit_Base);
5053 -- Process the subtype indication including a validation check on the
5054 -- constraint, if any. If a constraint is given, its bounds must be
5055 -- implicitly converted to the new type.
5057 if Nkind (Indic) = N_Subtype_Indication then
5059 R : constant Node_Id :=
5060 Range_Expression (Constraint (Indic));
5063 if Nkind (R) = N_Range then
5064 Hi := Build_Scalar_Bound
5065 (High_Bound (R), Parent_Type, Implicit_Base);
5066 Lo := Build_Scalar_Bound
5067 (Low_Bound (R), Parent_Type, Implicit_Base);
5070 -- Constraint is a Range attribute. Replace with explicit
5071 -- mention of the bounds of the prefix, which must be a
5074 Analyze (Prefix (R));
5076 Convert_To (Implicit_Base,
5077 Make_Attribute_Reference (Loc,
5078 Attribute_Name => Name_Last,
5080 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5083 Convert_To (Implicit_Base,
5084 Make_Attribute_Reference (Loc,
5085 Attribute_Name => Name_First,
5087 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5094 (Type_High_Bound (Parent_Type),
5095 Parent_Type, Implicit_Base);
5098 (Type_Low_Bound (Parent_Type),
5099 Parent_Type, Implicit_Base);
5107 -- If we constructed a default range for the case where no range
5108 -- was given, then the expressions in the range must not freeze
5109 -- since they do not correspond to expressions in the source.
5111 if Nkind (Indic) /= N_Subtype_Indication then
5112 Set_Must_Not_Freeze (Lo);
5113 Set_Must_Not_Freeze (Hi);
5114 Set_Must_Not_Freeze (Rang_Expr);
5118 Make_Subtype_Declaration (Loc,
5119 Defining_Identifier => Derived_Type,
5120 Subtype_Indication =>
5121 Make_Subtype_Indication (Loc,
5122 Subtype_Mark => New_Occurrence_Of (Implicit_Base, Loc),
5124 Make_Range_Constraint (Loc,
5125 Range_Expression => Rang_Expr))));
5129 -- If pragma Discard_Names applies on the first subtype of the parent
5130 -- type, then it must be applied on this subtype as well.
5132 if Einfo.Discard_Names (First_Subtype (Parent_Type)) then
5133 Set_Discard_Names (Derived_Type);
5136 -- Apply a range check. Since this range expression doesn't have an
5137 -- Etype, we have to specifically pass the Source_Typ parameter. Is
5140 if Nkind (Indic) = N_Subtype_Indication then
5141 Apply_Range_Check (Range_Expression (Constraint (Indic)),
5143 Source_Typ => Entity (Subtype_Mark (Indic)));
5146 end Build_Derived_Enumeration_Type;
5148 --------------------------------
5149 -- Build_Derived_Numeric_Type --
5150 --------------------------------
5152 procedure Build_Derived_Numeric_Type
5154 Parent_Type : Entity_Id;
5155 Derived_Type : Entity_Id)
5157 Loc : constant Source_Ptr := Sloc (N);
5158 Tdef : constant Node_Id := Type_Definition (N);
5159 Indic : constant Node_Id := Subtype_Indication (Tdef);
5160 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
5161 No_Constraint : constant Boolean := Nkind (Indic) /=
5162 N_Subtype_Indication;
5163 Implicit_Base : Entity_Id;
5169 -- Process the subtype indication including a validation check on
5170 -- the constraint if any.
5172 Discard_Node (Process_Subtype (Indic, N));
5174 -- Introduce an implicit base type for the derived type even if there
5175 -- is no constraint attached to it, since this seems closer to the Ada
5179 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
5181 Set_Etype (Implicit_Base, Parent_Base);
5182 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
5183 Set_Size_Info (Implicit_Base, Parent_Base);
5184 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Base));
5185 Set_Parent (Implicit_Base, Parent (Derived_Type));
5187 -- Set RM Size for discrete type or decimal fixed-point type
5188 -- Ordinary fixed-point is excluded, why???
5190 if Is_Discrete_Type (Parent_Base)
5191 or else Is_Decimal_Fixed_Point_Type (Parent_Base)
5193 Set_RM_Size (Implicit_Base, RM_Size (Parent_Base));
5196 Set_Has_Delayed_Freeze (Implicit_Base);
5198 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
5199 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
5201 Set_Scalar_Range (Implicit_Base,
5206 if Has_Infinities (Parent_Base) then
5207 Set_Includes_Infinities (Scalar_Range (Implicit_Base));
5210 -- The Derived_Type, which is the entity of the declaration, is a
5211 -- subtype of the implicit base. Its Ekind is a subtype, even in the
5212 -- absence of an explicit constraint.
5214 Set_Etype (Derived_Type, Implicit_Base);
5216 -- If we did not have a constraint, then the Ekind is set from the
5217 -- parent type (otherwise Process_Subtype has set the bounds)
5219 if No_Constraint then
5220 Set_Ekind (Derived_Type, Subtype_Kind (Ekind (Parent_Type)));
5223 -- If we did not have a range constraint, then set the range from the
5224 -- parent type. Otherwise, the call to Process_Subtype has set the
5228 or else not Has_Range_Constraint (Indic)
5230 Set_Scalar_Range (Derived_Type,
5232 Low_Bound => New_Copy_Tree (Type_Low_Bound (Parent_Type)),
5233 High_Bound => New_Copy_Tree (Type_High_Bound (Parent_Type))));
5234 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5236 if Has_Infinities (Parent_Type) then
5237 Set_Includes_Infinities (Scalar_Range (Derived_Type));
5241 Set_Is_Descendent_Of_Address (Derived_Type,
5242 Is_Descendent_Of_Address (Parent_Type));
5243 Set_Is_Descendent_Of_Address (Implicit_Base,
5244 Is_Descendent_Of_Address (Parent_Type));
5246 -- Set remaining type-specific fields, depending on numeric type
5248 if Is_Modular_Integer_Type (Parent_Type) then
5249 Set_Modulus (Implicit_Base, Modulus (Parent_Base));
5251 Set_Non_Binary_Modulus
5252 (Implicit_Base, Non_Binary_Modulus (Parent_Base));
5254 elsif Is_Floating_Point_Type (Parent_Type) then
5256 -- Digits of base type is always copied from the digits value of
5257 -- the parent base type, but the digits of the derived type will
5258 -- already have been set if there was a constraint present.
5260 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5261 Set_Vax_Float (Implicit_Base, Vax_Float (Parent_Base));
5263 if No_Constraint then
5264 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Type));
5267 elsif Is_Fixed_Point_Type (Parent_Type) then
5269 -- Small of base type and derived type are always copied from the
5270 -- parent base type, since smalls never change. The delta of the
5271 -- base type is also copied from the parent base type. However the
5272 -- delta of the derived type will have been set already if a
5273 -- constraint was present.
5275 Set_Small_Value (Derived_Type, Small_Value (Parent_Base));
5276 Set_Small_Value (Implicit_Base, Small_Value (Parent_Base));
5277 Set_Delta_Value (Implicit_Base, Delta_Value (Parent_Base));
5279 if No_Constraint then
5280 Set_Delta_Value (Derived_Type, Delta_Value (Parent_Type));
5283 -- The scale and machine radix in the decimal case are always
5284 -- copied from the parent base type.
5286 if Is_Decimal_Fixed_Point_Type (Parent_Type) then
5287 Set_Scale_Value (Derived_Type, Scale_Value (Parent_Base));
5288 Set_Scale_Value (Implicit_Base, Scale_Value (Parent_Base));
5290 Set_Machine_Radix_10
5291 (Derived_Type, Machine_Radix_10 (Parent_Base));
5292 Set_Machine_Radix_10
5293 (Implicit_Base, Machine_Radix_10 (Parent_Base));
5295 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5297 if No_Constraint then
5298 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Base));
5301 -- the analysis of the subtype_indication sets the
5302 -- digits value of the derived type.
5309 -- The type of the bounds is that of the parent type, and they
5310 -- must be converted to the derived type.
5312 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
5314 -- The implicit_base should be frozen when the derived type is frozen,
5315 -- but note that it is used in the conversions of the bounds. For fixed
5316 -- types we delay the determination of the bounds until the proper
5317 -- freezing point. For other numeric types this is rejected by GCC, for
5318 -- reasons that are currently unclear (???), so we choose to freeze the
5319 -- implicit base now. In the case of integers and floating point types
5320 -- this is harmless because subsequent representation clauses cannot
5321 -- affect anything, but it is still baffling that we cannot use the
5322 -- same mechanism for all derived numeric types.
5324 -- There is a further complication: actually *some* representation
5325 -- clauses can affect the implicit base type. Namely, attribute
5326 -- definition clauses for stream-oriented attributes need to set the
5327 -- corresponding TSS entries on the base type, and this normally cannot
5328 -- be done after the base type is frozen, so the circuitry in
5329 -- Sem_Ch13.New_Stream_Subprogram must account for this possibility and
5330 -- not use Set_TSS in this case.
5332 if Is_Fixed_Point_Type (Parent_Type) then
5333 Conditional_Delay (Implicit_Base, Parent_Type);
5335 Freeze_Before (N, Implicit_Base);
5337 end Build_Derived_Numeric_Type;
5339 --------------------------------
5340 -- Build_Derived_Private_Type --
5341 --------------------------------
5343 procedure Build_Derived_Private_Type
5345 Parent_Type : Entity_Id;
5346 Derived_Type : Entity_Id;
5347 Is_Completion : Boolean;
5348 Derive_Subps : Boolean := True)
5350 Der_Base : Entity_Id;
5352 Full_Decl : Node_Id := Empty;
5353 Full_Der : Entity_Id;
5355 Last_Discr : Entity_Id;
5356 Par_Scope : constant Entity_Id := Scope (Base_Type (Parent_Type));
5357 Swapped : Boolean := False;
5359 procedure Copy_And_Build;
5360 -- Copy derived type declaration, replace parent with its full view,
5361 -- and analyze new declaration.
5363 --------------------
5364 -- Copy_And_Build --
5365 --------------------
5367 procedure Copy_And_Build is
5371 if Ekind (Parent_Type) in Record_Kind
5373 (Ekind (Parent_Type) in Enumeration_Kind
5374 and then not Is_Standard_Character_Type (Parent_Type)
5375 and then not Is_Generic_Type (Root_Type (Parent_Type)))
5377 Full_N := New_Copy_Tree (N);
5378 Insert_After (N, Full_N);
5379 Build_Derived_Type (
5380 Full_N, Parent_Type, Full_Der, True, Derive_Subps => False);
5383 Build_Derived_Type (
5384 N, Parent_Type, Full_Der, True, Derive_Subps => False);
5388 -- Start of processing for Build_Derived_Private_Type
5391 if Is_Tagged_Type (Parent_Type) then
5392 Build_Derived_Record_Type
5393 (N, Parent_Type, Derived_Type, Derive_Subps);
5396 elsif Has_Discriminants (Parent_Type) then
5397 if Present (Full_View (Parent_Type)) then
5398 if not Is_Completion then
5400 -- Copy declaration for subsequent analysis, to provide a
5401 -- completion for what is a private declaration. Indicate that
5402 -- the full type is internally generated.
5404 Full_Decl := New_Copy_Tree (N);
5405 Full_Der := New_Copy (Derived_Type);
5406 Set_Comes_From_Source (Full_Decl, False);
5407 Set_Comes_From_Source (Full_Der, False);
5409 Insert_After (N, Full_Decl);
5412 -- If this is a completion, the full view being built is
5413 -- itself private. We build a subtype of the parent with
5414 -- the same constraints as this full view, to convey to the
5415 -- back end the constrained components and the size of this
5416 -- subtype. If the parent is constrained, its full view can
5417 -- serve as the underlying full view of the derived type.
5419 if No (Discriminant_Specifications (N)) then
5420 if Nkind (Subtype_Indication (Type_Definition (N))) =
5421 N_Subtype_Indication
5423 Build_Underlying_Full_View (N, Derived_Type, Parent_Type);
5425 elsif Is_Constrained (Full_View (Parent_Type)) then
5426 Set_Underlying_Full_View (Derived_Type,
5427 Full_View (Parent_Type));
5431 -- If there are new discriminants, the parent subtype is
5432 -- constrained by them, but it is not clear how to build
5433 -- the underlying_full_view in this case ???
5440 -- Build partial view of derived type from partial view of parent
5442 Build_Derived_Record_Type
5443 (N, Parent_Type, Derived_Type, Derive_Subps);
5445 if Present (Full_View (Parent_Type))
5446 and then not Is_Completion
5448 if not In_Open_Scopes (Par_Scope)
5449 or else not In_Same_Source_Unit (N, Parent_Type)
5451 -- Swap partial and full views temporarily
5453 Install_Private_Declarations (Par_Scope);
5454 Install_Visible_Declarations (Par_Scope);
5458 -- Build full view of derived type from full view of parent which
5459 -- is now installed. Subprograms have been derived on the partial
5460 -- view, the completion does not derive them anew.
5462 if not Is_Tagged_Type (Parent_Type) then
5464 -- If the parent is itself derived from another private type,
5465 -- installing the private declarations has not affected its
5466 -- privacy status, so use its own full view explicitly.
5468 if Is_Private_Type (Parent_Type) then
5469 Build_Derived_Record_Type
5470 (Full_Decl, Full_View (Parent_Type), Full_Der, False);
5472 Build_Derived_Record_Type
5473 (Full_Decl, Parent_Type, Full_Der, False);
5477 -- If full view of parent is tagged, the completion
5478 -- inherits the proper primitive operations.
5480 Set_Defining_Identifier (Full_Decl, Full_Der);
5481 Build_Derived_Record_Type
5482 (Full_Decl, Parent_Type, Full_Der, Derive_Subps);
5483 Set_Analyzed (Full_Decl);
5487 Uninstall_Declarations (Par_Scope);
5489 if In_Open_Scopes (Par_Scope) then
5490 Install_Visible_Declarations (Par_Scope);
5494 Der_Base := Base_Type (Derived_Type);
5495 Set_Full_View (Derived_Type, Full_Der);
5496 Set_Full_View (Der_Base, Base_Type (Full_Der));
5498 -- Copy the discriminant list from full view to the partial views
5499 -- (base type and its subtype). Gigi requires that the partial
5500 -- and full views have the same discriminants.
5502 -- Note that since the partial view is pointing to discriminants
5503 -- in the full view, their scope will be that of the full view.
5504 -- This might cause some front end problems and need
5507 Discr := First_Discriminant (Base_Type (Full_Der));
5508 Set_First_Entity (Der_Base, Discr);
5511 Last_Discr := Discr;
5512 Next_Discriminant (Discr);
5513 exit when No (Discr);
5516 Set_Last_Entity (Der_Base, Last_Discr);
5518 Set_First_Entity (Derived_Type, First_Entity (Der_Base));
5519 Set_Last_Entity (Derived_Type, Last_Entity (Der_Base));
5520 Set_Stored_Constraint (Full_Der, Stored_Constraint (Derived_Type));
5523 -- If this is a completion, the derived type stays private
5524 -- and there is no need to create a further full view, except
5525 -- in the unusual case when the derivation is nested within a
5526 -- child unit, see below.
5531 elsif Present (Full_View (Parent_Type))
5532 and then Has_Discriminants (Full_View (Parent_Type))
5534 if Has_Unknown_Discriminants (Parent_Type)
5535 and then Nkind (Subtype_Indication (Type_Definition (N))) =
5536 N_Subtype_Indication
5539 ("cannot constrain type with unknown discriminants",
5540 Subtype_Indication (Type_Definition (N)));
5544 -- If full view of parent is a record type, Build full view as
5545 -- a derivation from the parent's full view. Partial view remains
5546 -- private. For code generation and linking, the full view must
5547 -- have the same public status as the partial one. This full view
5548 -- is only needed if the parent type is in an enclosing scope, so
5549 -- that the full view may actually become visible, e.g. in a child
5550 -- unit. This is both more efficient, and avoids order of freezing
5551 -- problems with the added entities.
5553 if not Is_Private_Type (Full_View (Parent_Type))
5554 and then (In_Open_Scopes (Scope (Parent_Type)))
5556 Full_Der := Make_Defining_Identifier (Sloc (Derived_Type),
5557 Chars (Derived_Type));
5558 Set_Is_Itype (Full_Der);
5559 Set_Has_Private_Declaration (Full_Der);
5560 Set_Has_Private_Declaration (Derived_Type);
5561 Set_Associated_Node_For_Itype (Full_Der, N);
5562 Set_Parent (Full_Der, Parent (Derived_Type));
5563 Set_Full_View (Derived_Type, Full_Der);
5564 Set_Is_Public (Full_Der, Is_Public (Derived_Type));
5565 Full_P := Full_View (Parent_Type);
5566 Exchange_Declarations (Parent_Type);
5568 Exchange_Declarations (Full_P);
5571 Build_Derived_Record_Type
5572 (N, Full_View (Parent_Type), Derived_Type,
5573 Derive_Subps => False);
5576 -- In any case, the primitive operations are inherited from
5577 -- the parent type, not from the internal full view.
5579 Set_Etype (Base_Type (Derived_Type), Base_Type (Parent_Type));
5581 if Derive_Subps then
5582 Derive_Subprograms (Parent_Type, Derived_Type);
5586 -- Untagged type, No discriminants on either view
5588 if Nkind (Subtype_Indication (Type_Definition (N))) =
5589 N_Subtype_Indication
5592 ("illegal constraint on type without discriminants", N);
5595 if Present (Discriminant_Specifications (N))
5596 and then Present (Full_View (Parent_Type))
5597 and then not Is_Tagged_Type (Full_View (Parent_Type))
5600 ("cannot add discriminants to untagged type", N);
5603 Set_Stored_Constraint (Derived_Type, No_Elist);
5604 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5605 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
5606 Set_Has_Controlled_Component
5607 (Derived_Type, Has_Controlled_Component
5610 -- Direct controlled types do not inherit Finalize_Storage_Only flag
5612 if not Is_Controlled (Parent_Type) then
5613 Set_Finalize_Storage_Only
5614 (Base_Type (Derived_Type), Finalize_Storage_Only (Parent_Type));
5617 -- Construct the implicit full view by deriving from full view of
5618 -- the parent type. In order to get proper visibility, we install
5619 -- the parent scope and its declarations.
5621 -- ??? if the parent is untagged private and its completion is
5622 -- tagged, this mechanism will not work because we cannot derive
5623 -- from the tagged full view unless we have an extension
5625 if Present (Full_View (Parent_Type))
5626 and then not Is_Tagged_Type (Full_View (Parent_Type))
5627 and then not Is_Completion
5630 Make_Defining_Identifier (Sloc (Derived_Type),
5631 Chars => Chars (Derived_Type));
5632 Set_Is_Itype (Full_Der);
5633 Set_Has_Private_Declaration (Full_Der);
5634 Set_Has_Private_Declaration (Derived_Type);
5635 Set_Associated_Node_For_Itype (Full_Der, N);
5636 Set_Parent (Full_Der, Parent (Derived_Type));
5637 Set_Full_View (Derived_Type, Full_Der);
5639 if not In_Open_Scopes (Par_Scope) then
5640 Install_Private_Declarations (Par_Scope);
5641 Install_Visible_Declarations (Par_Scope);
5643 Uninstall_Declarations (Par_Scope);
5645 -- If parent scope is open and in another unit, and parent has a
5646 -- completion, then the derivation is taking place in the visible
5647 -- part of a child unit. In that case retrieve the full view of
5648 -- the parent momentarily.
5650 elsif not In_Same_Source_Unit (N, Parent_Type) then
5651 Full_P := Full_View (Parent_Type);
5652 Exchange_Declarations (Parent_Type);
5654 Exchange_Declarations (Full_P);
5656 -- Otherwise it is a local derivation
5662 Set_Scope (Full_Der, Current_Scope);
5663 Set_Is_First_Subtype (Full_Der,
5664 Is_First_Subtype (Derived_Type));
5665 Set_Has_Size_Clause (Full_Der, False);
5666 Set_Has_Alignment_Clause (Full_Der, False);
5667 Set_Next_Entity (Full_Der, Empty);
5668 Set_Has_Delayed_Freeze (Full_Der);
5669 Set_Is_Frozen (Full_Der, False);
5670 Set_Freeze_Node (Full_Der, Empty);
5671 Set_Depends_On_Private (Full_Der,
5672 Has_Private_Component (Full_Der));
5673 Set_Public_Status (Full_Der);
5677 Set_Has_Unknown_Discriminants (Derived_Type,
5678 Has_Unknown_Discriminants (Parent_Type));
5680 if Is_Private_Type (Derived_Type) then
5681 Set_Private_Dependents (Derived_Type, New_Elmt_List);
5684 if Is_Private_Type (Parent_Type)
5685 and then Base_Type (Parent_Type) = Parent_Type
5686 and then In_Open_Scopes (Scope (Parent_Type))
5688 Append_Elmt (Derived_Type, Private_Dependents (Parent_Type));
5690 if Is_Child_Unit (Scope (Current_Scope))
5691 and then Is_Completion
5692 and then In_Private_Part (Current_Scope)
5693 and then Scope (Parent_Type) /= Current_Scope
5695 -- This is the unusual case where a type completed by a private
5696 -- derivation occurs within a package nested in a child unit,
5697 -- and the parent is declared in an ancestor. In this case, the
5698 -- full view of the parent type will become visible in the body
5699 -- of the enclosing child, and only then will the current type
5700 -- be possibly non-private. We build a underlying full view that
5701 -- will be installed when the enclosing child body is compiled.
5704 Make_Defining_Identifier (Sloc (Derived_Type),
5705 Chars => Chars (Derived_Type));
5706 Set_Is_Itype (Full_Der);
5707 Build_Itype_Reference (Full_Der, N);
5709 -- The full view will be used to swap entities on entry/exit to
5710 -- the body, and must appear in the entity list for the package.
5712 Append_Entity (Full_Der, Scope (Derived_Type));
5713 Set_Has_Private_Declaration (Full_Der);
5714 Set_Has_Private_Declaration (Derived_Type);
5715 Set_Associated_Node_For_Itype (Full_Der, N);
5716 Set_Parent (Full_Der, Parent (Derived_Type));
5717 Full_P := Full_View (Parent_Type);
5718 Exchange_Declarations (Parent_Type);
5720 Exchange_Declarations (Full_P);
5721 Set_Underlying_Full_View (Derived_Type, Full_Der);
5724 end Build_Derived_Private_Type;
5726 -------------------------------
5727 -- Build_Derived_Record_Type --
5728 -------------------------------
5732 -- Ideally we would like to use the same model of type derivation for
5733 -- tagged and untagged record types. Unfortunately this is not quite
5734 -- possible because the semantics of representation clauses is different
5735 -- for tagged and untagged records under inheritance. Consider the
5738 -- type R (...) is [tagged] record ... end record;
5739 -- type T (...) is new R (...) [with ...];
5741 -- The representation clauses for T can specify a completely different
5742 -- record layout from R's. Hence the same component can be placed in two
5743 -- very different positions in objects of type T and R. If R and are tagged
5744 -- types, representation clauses for T can only specify the layout of non
5745 -- inherited components, thus components that are common in R and T have
5746 -- the same position in objects of type R and T.
5748 -- This has two implications. The first is that the entire tree for R's
5749 -- declaration needs to be copied for T in the untagged case, so that T
5750 -- can be viewed as a record type of its own with its own representation
5751 -- clauses. The second implication is the way we handle discriminants.
5752 -- Specifically, in the untagged case we need a way to communicate to Gigi
5753 -- what are the real discriminants in the record, while for the semantics
5754 -- we need to consider those introduced by the user to rename the
5755 -- discriminants in the parent type. This is handled by introducing the
5756 -- notion of stored discriminants. See below for more.
5758 -- Fortunately the way regular components are inherited can be handled in
5759 -- the same way in tagged and untagged types.
5761 -- To complicate things a bit more the private view of a private extension
5762 -- cannot be handled in the same way as the full view (for one thing the
5763 -- semantic rules are somewhat different). We will explain what differs
5766 -- 2. DISCRIMINANTS UNDER INHERITANCE
5768 -- The semantic rules governing the discriminants of derived types are
5771 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
5772 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
5774 -- If parent type has discriminants, then the discriminants that are
5775 -- declared in the derived type are [3.4 (11)]:
5777 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
5780 -- o Otherwise, each discriminant of the parent type (implicitly declared
5781 -- in the same order with the same specifications). In this case, the
5782 -- discriminants are said to be "inherited", or if unknown in the parent
5783 -- are also unknown in the derived type.
5785 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
5787 -- o The parent subtype shall be constrained;
5789 -- o If the parent type is not a tagged type, then each discriminant of
5790 -- the derived type shall be used in the constraint defining a parent
5791 -- subtype. [Implementation note: This ensures that the new discriminant
5792 -- can share storage with an existing discriminant.]
5794 -- For the derived type each discriminant of the parent type is either
5795 -- inherited, constrained to equal some new discriminant of the derived
5796 -- type, or constrained to the value of an expression.
5798 -- When inherited or constrained to equal some new discriminant, the
5799 -- parent discriminant and the discriminant of the derived type are said
5802 -- If a discriminant of the parent type is constrained to a specific value
5803 -- in the derived type definition, then the discriminant is said to be
5804 -- "specified" by that derived type definition.
5806 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
5808 -- We have spoken about stored discriminants in point 1 (introduction)
5809 -- above. There are two sort of stored discriminants: implicit and
5810 -- explicit. As long as the derived type inherits the same discriminants as
5811 -- the root record type, stored discriminants are the same as regular
5812 -- discriminants, and are said to be implicit. However, if any discriminant
5813 -- in the root type was renamed in the derived type, then the derived
5814 -- type will contain explicit stored discriminants. Explicit stored
5815 -- discriminants are discriminants in addition to the semantically visible
5816 -- discriminants defined for the derived type. Stored discriminants are
5817 -- used by Gigi to figure out what are the physical discriminants in
5818 -- objects of the derived type (see precise definition in einfo.ads).
5819 -- As an example, consider the following:
5821 -- type R (D1, D2, D3 : Int) is record ... end record;
5822 -- type T1 is new R;
5823 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
5824 -- type T3 is new T2;
5825 -- type T4 (Y : Int) is new T3 (Y, 99);
5827 -- The following table summarizes the discriminants and stored
5828 -- discriminants in R and T1 through T4.
5830 -- Type Discrim Stored Discrim Comment
5831 -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
5832 -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
5833 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
5834 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
5835 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
5837 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
5838 -- find the corresponding discriminant in the parent type, while
5839 -- Original_Record_Component (abbreviated ORC below), the actual physical
5840 -- component that is renamed. Finally the field Is_Completely_Hidden
5841 -- (abbreviated ICH below) is set for all explicit stored discriminants
5842 -- (see einfo.ads for more info). For the above example this gives:
5844 -- Discrim CD ORC ICH
5845 -- ^^^^^^^ ^^ ^^^ ^^^
5846 -- D1 in R empty itself no
5847 -- D2 in R empty itself no
5848 -- D3 in R empty itself no
5850 -- D1 in T1 D1 in R itself no
5851 -- D2 in T1 D2 in R itself no
5852 -- D3 in T1 D3 in R itself no
5854 -- X1 in T2 D3 in T1 D3 in T2 no
5855 -- X2 in T2 D1 in T1 D1 in T2 no
5856 -- D1 in T2 empty itself yes
5857 -- D2 in T2 empty itself yes
5858 -- D3 in T2 empty itself yes
5860 -- X1 in T3 X1 in T2 D3 in T3 no
5861 -- X2 in T3 X2 in T2 D1 in T3 no
5862 -- D1 in T3 empty itself yes
5863 -- D2 in T3 empty itself yes
5864 -- D3 in T3 empty itself yes
5866 -- Y in T4 X1 in T3 D3 in T3 no
5867 -- D1 in T3 empty itself yes
5868 -- D2 in T3 empty itself yes
5869 -- D3 in T3 empty itself yes
5871 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
5873 -- Type derivation for tagged types is fairly straightforward. If no
5874 -- discriminants are specified by the derived type, these are inherited
5875 -- from the parent. No explicit stored discriminants are ever necessary.
5876 -- The only manipulation that is done to the tree is that of adding a
5877 -- _parent field with parent type and constrained to the same constraint
5878 -- specified for the parent in the derived type definition. For instance:
5880 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
5881 -- type T1 is new R with null record;
5882 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
5884 -- are changed into:
5886 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
5887 -- _parent : R (D1, D2, D3);
5890 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
5891 -- _parent : T1 (X2, 88, X1);
5894 -- The discriminants actually present in R, T1 and T2 as well as their CD,
5895 -- ORC and ICH fields are:
5897 -- Discrim CD ORC ICH
5898 -- ^^^^^^^ ^^ ^^^ ^^^
5899 -- D1 in R empty itself no
5900 -- D2 in R empty itself no
5901 -- D3 in R empty itself no
5903 -- D1 in T1 D1 in R D1 in R no
5904 -- D2 in T1 D2 in R D2 in R no
5905 -- D3 in T1 D3 in R D3 in R no
5907 -- X1 in T2 D3 in T1 D3 in R no
5908 -- X2 in T2 D1 in T1 D1 in R no
5910 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
5912 -- Regardless of whether we dealing with a tagged or untagged type
5913 -- we will transform all derived type declarations of the form
5915 -- type T is new R (...) [with ...];
5917 -- subtype S is R (...);
5918 -- type T is new S [with ...];
5920 -- type BT is new R [with ...];
5921 -- subtype T is BT (...);
5923 -- That is, the base derived type is constrained only if it has no
5924 -- discriminants. The reason for doing this is that GNAT's semantic model
5925 -- assumes that a base type with discriminants is unconstrained.
5927 -- Note that, strictly speaking, the above transformation is not always
5928 -- correct. Consider for instance the following excerpt from ACVC b34011a:
5930 -- procedure B34011A is
5931 -- type REC (D : integer := 0) is record
5936 -- type T6 is new Rec;
5937 -- function F return T6;
5942 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
5945 -- The definition of Q6.U is illegal. However transforming Q6.U into
5947 -- type BaseU is new T6;
5948 -- subtype U is BaseU (Q6.F.I)
5950 -- turns U into a legal subtype, which is incorrect. To avoid this problem
5951 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
5952 -- the transformation described above.
5954 -- There is another instance where the above transformation is incorrect.
5958 -- type Base (D : Integer) is tagged null record;
5959 -- procedure P (X : Base);
5961 -- type Der is new Base (2) with null record;
5962 -- procedure P (X : Der);
5965 -- Then the above transformation turns this into
5967 -- type Der_Base is new Base with null record;
5968 -- -- procedure P (X : Base) is implicitly inherited here
5969 -- -- as procedure P (X : Der_Base).
5971 -- subtype Der is Der_Base (2);
5972 -- procedure P (X : Der);
5973 -- -- The overriding of P (X : Der_Base) is illegal since we
5974 -- -- have a parameter conformance problem.
5976 -- To get around this problem, after having semantically processed Der_Base
5977 -- and the rewritten subtype declaration for Der, we copy Der_Base field
5978 -- Discriminant_Constraint from Der so that when parameter conformance is
5979 -- checked when P is overridden, no semantic errors are flagged.
5981 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
5983 -- Regardless of whether we are dealing with a tagged or untagged type
5984 -- we will transform all derived type declarations of the form
5986 -- type R (D1, .., Dn : ...) is [tagged] record ...;
5987 -- type T is new R [with ...];
5989 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
5991 -- The reason for such transformation is that it allows us to implement a
5992 -- very clean form of component inheritance as explained below.
5994 -- Note that this transformation is not achieved by direct tree rewriting
5995 -- and manipulation, but rather by redoing the semantic actions that the
5996 -- above transformation will entail. This is done directly in routine
5997 -- Inherit_Components.
5999 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
6001 -- In both tagged and untagged derived types, regular non discriminant
6002 -- components are inherited in the derived type from the parent type. In
6003 -- the absence of discriminants component, inheritance is straightforward
6004 -- as components can simply be copied from the parent.
6006 -- If the parent has discriminants, inheriting components constrained with
6007 -- these discriminants requires caution. Consider the following example:
6009 -- type R (D1, D2 : Positive) is [tagged] record
6010 -- S : String (D1 .. D2);
6013 -- type T1 is new R [with null record];
6014 -- type T2 (X : positive) is new R (1, X) [with null record];
6016 -- As explained in 6. above, T1 is rewritten as
6017 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
6018 -- which makes the treatment for T1 and T2 identical.
6020 -- What we want when inheriting S, is that references to D1 and D2 in R are
6021 -- replaced with references to their correct constraints, i.e. D1 and D2 in
6022 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
6023 -- with either discriminant references in the derived type or expressions.
6024 -- This replacement is achieved as follows: before inheriting R's
6025 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
6026 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
6027 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
6028 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
6029 -- by String (1 .. X).
6031 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
6033 -- We explain here the rules governing private type extensions relevant to
6034 -- type derivation. These rules are explained on the following example:
6036 -- type D [(...)] is new A [(...)] with private; <-- partial view
6037 -- type D [(...)] is new P [(...)] with null record; <-- full view
6039 -- Type A is called the ancestor subtype of the private extension.
6040 -- Type P is the parent type of the full view of the private extension. It
6041 -- must be A or a type derived from A.
6043 -- The rules concerning the discriminants of private type extensions are
6046 -- o If a private extension inherits known discriminants from the ancestor
6047 -- subtype, then the full view shall also inherit its discriminants from
6048 -- the ancestor subtype and the parent subtype of the full view shall be
6049 -- constrained if and only if the ancestor subtype is constrained.
6051 -- o If a partial view has unknown discriminants, then the full view may
6052 -- define a definite or an indefinite subtype, with or without
6055 -- o If a partial view has neither known nor unknown discriminants, then
6056 -- the full view shall define a definite subtype.
6058 -- o If the ancestor subtype of a private extension has constrained
6059 -- discriminants, then the parent subtype of the full view shall impose a
6060 -- statically matching constraint on those discriminants.
6062 -- This means that only the following forms of private extensions are
6065 -- type D is new A with private; <-- partial view
6066 -- type D is new P with null record; <-- full view
6068 -- If A has no discriminants than P has no discriminants, otherwise P must
6069 -- inherit A's discriminants.
6071 -- type D is new A (...) with private; <-- partial view
6072 -- type D is new P (:::) with null record; <-- full view
6074 -- P must inherit A's discriminants and (...) and (:::) must statically
6077 -- subtype A is R (...);
6078 -- type D is new A with private; <-- partial view
6079 -- type D is new P with null record; <-- full view
6081 -- P must have inherited R's discriminants and must be derived from A or
6082 -- any of its subtypes.
6084 -- type D (..) is new A with private; <-- partial view
6085 -- type D (..) is new P [(:::)] with null record; <-- full view
6087 -- No specific constraints on P's discriminants or constraint (:::).
6088 -- Note that A can be unconstrained, but the parent subtype P must either
6089 -- be constrained or (:::) must be present.
6091 -- type D (..) is new A [(...)] with private; <-- partial view
6092 -- type D (..) is new P [(:::)] with null record; <-- full view
6094 -- P's constraints on A's discriminants must statically match those
6095 -- imposed by (...).
6097 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
6099 -- The full view of a private extension is handled exactly as described
6100 -- above. The model chose for the private view of a private extension is
6101 -- the same for what concerns discriminants (i.e. they receive the same
6102 -- treatment as in the tagged case). However, the private view of the
6103 -- private extension always inherits the components of the parent base,
6104 -- without replacing any discriminant reference. Strictly speaking this is
6105 -- incorrect. However, Gigi never uses this view to generate code so this
6106 -- is a purely semantic issue. In theory, a set of transformations similar
6107 -- to those given in 5. and 6. above could be applied to private views of
6108 -- private extensions to have the same model of component inheritance as
6109 -- for non private extensions. However, this is not done because it would
6110 -- further complicate private type processing. Semantically speaking, this
6111 -- leaves us in an uncomfortable situation. As an example consider:
6114 -- type R (D : integer) is tagged record
6115 -- S : String (1 .. D);
6117 -- procedure P (X : R);
6118 -- type T is new R (1) with private;
6120 -- type T is new R (1) with null record;
6123 -- This is transformed into:
6126 -- type R (D : integer) is tagged record
6127 -- S : String (1 .. D);
6129 -- procedure P (X : R);
6130 -- type T is new R (1) with private;
6132 -- type BaseT is new R with null record;
6133 -- subtype T is BaseT (1);
6136 -- (strictly speaking the above is incorrect Ada)
6138 -- From the semantic standpoint the private view of private extension T
6139 -- should be flagged as constrained since one can clearly have
6143 -- in a unit withing Pack. However, when deriving subprograms for the
6144 -- private view of private extension T, T must be seen as unconstrained
6145 -- since T has discriminants (this is a constraint of the current
6146 -- subprogram derivation model). Thus, when processing the private view of
6147 -- a private extension such as T, we first mark T as unconstrained, we
6148 -- process it, we perform program derivation and just before returning from
6149 -- Build_Derived_Record_Type we mark T as constrained.
6151 -- ??? Are there are other uncomfortable cases that we will have to
6154 -- 10. RECORD_TYPE_WITH_PRIVATE complications
6156 -- Types that are derived from a visible record type and have a private
6157 -- extension present other peculiarities. They behave mostly like private
6158 -- types, but if they have primitive operations defined, these will not
6159 -- have the proper signatures for further inheritance, because other
6160 -- primitive operations will use the implicit base that we define for
6161 -- private derivations below. This affect subprogram inheritance (see
6162 -- Derive_Subprograms for details). We also derive the implicit base from
6163 -- the base type of the full view, so that the implicit base is a record
6164 -- type and not another private type, This avoids infinite loops.
6166 procedure Build_Derived_Record_Type
6168 Parent_Type : Entity_Id;
6169 Derived_Type : Entity_Id;
6170 Derive_Subps : Boolean := True)
6172 Loc : constant Source_Ptr := Sloc (N);
6173 Parent_Base : Entity_Id;
6176 Discrim : Entity_Id;
6177 Last_Discrim : Entity_Id;
6180 Discs : Elist_Id := New_Elmt_List;
6181 -- An empty Discs list means that there were no constraints in the
6182 -- subtype indication or that there was an error processing it.
6184 Assoc_List : Elist_Id;
6185 New_Discrs : Elist_Id;
6186 New_Base : Entity_Id;
6188 New_Indic : Node_Id;
6190 Is_Tagged : constant Boolean := Is_Tagged_Type (Parent_Type);
6191 Discriminant_Specs : constant Boolean :=
6192 Present (Discriminant_Specifications (N));
6193 Private_Extension : constant Boolean :=
6194 Nkind (N) = N_Private_Extension_Declaration;
6196 Constraint_Present : Boolean;
6197 Inherit_Discrims : Boolean := False;
6198 Save_Etype : Entity_Id;
6199 Save_Discr_Constr : Elist_Id;
6200 Save_Next_Entity : Entity_Id;
6203 if Ekind (Parent_Type) = E_Record_Type_With_Private
6204 and then Present (Full_View (Parent_Type))
6205 and then Has_Discriminants (Parent_Type)
6207 Parent_Base := Base_Type (Full_View (Parent_Type));
6209 Parent_Base := Base_Type (Parent_Type);
6212 -- Before we start the previously documented transformations, here is
6213 -- little fix for size and alignment of tagged types. Normally when we
6214 -- derive type D from type P, we copy the size and alignment of P as the
6215 -- default for D, and in the absence of explicit representation clauses
6216 -- for D, the size and alignment are indeed the same as the parent.
6218 -- But this is wrong for tagged types, since fields may be added, and
6219 -- the default size may need to be larger, and the default alignment may
6220 -- need to be larger.
6222 -- We therefore reset the size and alignment fields in the tagged case.
6223 -- Note that the size and alignment will in any case be at least as
6224 -- large as the parent type (since the derived type has a copy of the
6225 -- parent type in the _parent field)
6227 -- The type is also marked as being tagged here, which is needed when
6228 -- processing components with a self-referential anonymous access type
6229 -- in the call to Check_Anonymous_Access_Components below. Note that
6230 -- this flag is also set later on for completeness.
6233 Set_Is_Tagged_Type (Derived_Type);
6234 Init_Size_Align (Derived_Type);
6237 -- STEP 0a: figure out what kind of derived type declaration we have
6239 if Private_Extension then
6241 Set_Ekind (Derived_Type, E_Record_Type_With_Private);
6244 Type_Def := Type_Definition (N);
6246 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
6247 -- Parent_Base can be a private type or private extension. However,
6248 -- for tagged types with an extension the newly added fields are
6249 -- visible and hence the Derived_Type is always an E_Record_Type.
6250 -- (except that the parent may have its own private fields).
6251 -- For untagged types we preserve the Ekind of the Parent_Base.
6253 if Present (Record_Extension_Part (Type_Def)) then
6254 Set_Ekind (Derived_Type, E_Record_Type);
6256 -- Create internal access types for components with anonymous
6259 if Ada_Version >= Ada_05 then
6260 Check_Anonymous_Access_Components
6261 (N, Derived_Type, Derived_Type,
6262 Component_List (Record_Extension_Part (Type_Def)));
6266 Set_Ekind (Derived_Type, Ekind (Parent_Base));
6270 -- Indic can either be an N_Identifier if the subtype indication
6271 -- contains no constraint or an N_Subtype_Indication if the subtype
6272 -- indication has a constraint.
6274 Indic := Subtype_Indication (Type_Def);
6275 Constraint_Present := (Nkind (Indic) = N_Subtype_Indication);
6277 -- Check that the type has visible discriminants. The type may be
6278 -- a private type with unknown discriminants whose full view has
6279 -- discriminants which are invisible.
6281 if Constraint_Present then
6282 if not Has_Discriminants (Parent_Base)
6284 (Has_Unknown_Discriminants (Parent_Base)
6285 and then Is_Private_Type (Parent_Base))
6288 ("invalid constraint: type has no discriminant",
6289 Constraint (Indic));
6291 Constraint_Present := False;
6292 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6294 elsif Is_Constrained (Parent_Type) then
6296 ("invalid constraint: parent type is already constrained",
6297 Constraint (Indic));
6299 Constraint_Present := False;
6300 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6304 -- STEP 0b: If needed, apply transformation given in point 5. above
6306 if not Private_Extension
6307 and then Has_Discriminants (Parent_Type)
6308 and then not Discriminant_Specs
6309 and then (Is_Constrained (Parent_Type) or else Constraint_Present)
6311 -- First, we must analyze the constraint (see comment in point 5.)
6313 if Constraint_Present then
6314 New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic);
6316 if Has_Discriminants (Derived_Type)
6317 and then Has_Private_Declaration (Derived_Type)
6318 and then Present (Discriminant_Constraint (Derived_Type))
6320 -- Verify that constraints of the full view statically match
6321 -- those given in the partial view.
6327 C1 := First_Elmt (New_Discrs);
6328 C2 := First_Elmt (Discriminant_Constraint (Derived_Type));
6329 while Present (C1) and then Present (C2) loop
6330 if Fully_Conformant_Expressions (Node (C1), Node (C2))
6332 (Is_OK_Static_Expression (Node (C1))
6334 Is_OK_Static_Expression (Node (C2))
6336 Expr_Value (Node (C1)) = Expr_Value (Node (C2)))
6342 "constraint not conformant to previous declaration",
6353 -- Insert and analyze the declaration for the unconstrained base type
6355 New_Base := Create_Itype (Ekind (Derived_Type), N, Derived_Type, 'B');
6358 Make_Full_Type_Declaration (Loc,
6359 Defining_Identifier => New_Base,
6361 Make_Derived_Type_Definition (Loc,
6362 Abstract_Present => Abstract_Present (Type_Def),
6363 Subtype_Indication =>
6364 New_Occurrence_Of (Parent_Base, Loc),
6365 Record_Extension_Part =>
6366 Relocate_Node (Record_Extension_Part (Type_Def))));
6368 Set_Parent (New_Decl, Parent (N));
6369 Mark_Rewrite_Insertion (New_Decl);
6370 Insert_Before (N, New_Decl);
6372 -- Note that this call passes False for the Derive_Subps parameter
6373 -- because subprogram derivation is deferred until after creating
6374 -- the subtype (see below).
6377 (New_Decl, Parent_Base, New_Base,
6378 Is_Completion => True, Derive_Subps => False);
6380 -- ??? This needs re-examination to determine whether the
6381 -- above call can simply be replaced by a call to Analyze.
6383 Set_Analyzed (New_Decl);
6385 -- Insert and analyze the declaration for the constrained subtype
6387 if Constraint_Present then
6389 Make_Subtype_Indication (Loc,
6390 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6391 Constraint => Relocate_Node (Constraint (Indic)));
6395 Constr_List : constant List_Id := New_List;
6400 C := First_Elmt (Discriminant_Constraint (Parent_Type));
6401 while Present (C) loop
6404 -- It is safe here to call New_Copy_Tree since
6405 -- Force_Evaluation was called on each constraint in
6406 -- Build_Discriminant_Constraints.
6408 Append (New_Copy_Tree (Expr), To => Constr_List);
6414 Make_Subtype_Indication (Loc,
6415 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6417 Make_Index_Or_Discriminant_Constraint (Loc, Constr_List));
6422 Make_Subtype_Declaration (Loc,
6423 Defining_Identifier => Derived_Type,
6424 Subtype_Indication => New_Indic));
6428 -- Derivation of subprograms must be delayed until the full subtype
6429 -- has been established to ensure proper overriding of subprograms
6430 -- inherited by full types. If the derivations occurred as part of
6431 -- the call to Build_Derived_Type above, then the check for type
6432 -- conformance would fail because earlier primitive subprograms
6433 -- could still refer to the full type prior the change to the new
6434 -- subtype and hence would not match the new base type created here.
6436 Derive_Subprograms (Parent_Type, Derived_Type);
6438 -- For tagged types the Discriminant_Constraint of the new base itype
6439 -- is inherited from the first subtype so that no subtype conformance
6440 -- problem arise when the first subtype overrides primitive
6441 -- operations inherited by the implicit base type.
6444 Set_Discriminant_Constraint
6445 (New_Base, Discriminant_Constraint (Derived_Type));
6451 -- If we get here Derived_Type will have no discriminants or it will be
6452 -- a discriminated unconstrained base type.
6454 -- STEP 1a: perform preliminary actions/checks for derived tagged types
6458 -- The parent type is frozen for non-private extensions (RM 13.14(7))
6459 -- The declaration of a specific descendant of an interface type
6460 -- freezes the interface type (RM 13.14).
6462 if not Private_Extension
6463 or else Is_Interface (Parent_Base)
6465 Freeze_Before (N, Parent_Type);
6468 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
6469 -- cannot be declared at a deeper level than its parent type is
6470 -- removed. The check on derivation within a generic body is also
6471 -- relaxed, but there's a restriction that a derived tagged type
6472 -- cannot be declared in a generic body if it's derived directly
6473 -- or indirectly from a formal type of that generic.
6475 if Ada_Version >= Ada_05 then
6476 if Present (Enclosing_Generic_Body (Derived_Type)) then
6478 Ancestor_Type : Entity_Id;
6481 -- Check to see if any ancestor of the derived type is a
6484 Ancestor_Type := Parent_Type;
6485 while not Is_Generic_Type (Ancestor_Type)
6486 and then Etype (Ancestor_Type) /= Ancestor_Type
6488 Ancestor_Type := Etype (Ancestor_Type);
6491 -- If the derived type does have a formal type as an
6492 -- ancestor, then it's an error if the derived type is
6493 -- declared within the body of the generic unit that
6494 -- declares the formal type in its generic formal part. It's
6495 -- sufficient to check whether the ancestor type is declared
6496 -- inside the same generic body as the derived type (such as
6497 -- within a nested generic spec), in which case the
6498 -- derivation is legal. If the formal type is declared
6499 -- outside of that generic body, then it's guaranteed that
6500 -- the derived type is declared within the generic body of
6501 -- the generic unit declaring the formal type.
6503 if Is_Generic_Type (Ancestor_Type)
6504 and then Enclosing_Generic_Body (Ancestor_Type) /=
6505 Enclosing_Generic_Body (Derived_Type)
6508 ("parent type of& must not be descendant of formal type"
6509 & " of an enclosing generic body",
6510 Indic, Derived_Type);
6515 elsif Type_Access_Level (Derived_Type) /=
6516 Type_Access_Level (Parent_Type)
6517 and then not Is_Generic_Type (Derived_Type)
6519 if Is_Controlled (Parent_Type) then
6521 ("controlled type must be declared at the library level",
6525 ("type extension at deeper accessibility level than parent",
6531 GB : constant Node_Id := Enclosing_Generic_Body (Derived_Type);
6535 and then GB /= Enclosing_Generic_Body (Parent_Base)
6538 ("parent type of& must not be outside generic body"
6540 Indic, Derived_Type);
6546 -- Ada 2005 (AI-251)
6548 if Ada_Version = Ada_05
6551 -- "The declaration of a specific descendant of an interface type
6552 -- freezes the interface type" (RM 13.14).
6557 if Is_Non_Empty_List (Interface_List (Type_Def)) then
6558 Iface := First (Interface_List (Type_Def));
6559 while Present (Iface) loop
6560 Freeze_Before (N, Etype (Iface));
6567 -- STEP 1b : preliminary cleanup of the full view of private types
6569 -- If the type is already marked as having discriminants, then it's the
6570 -- completion of a private type or private extension and we need to
6571 -- retain the discriminants from the partial view if the current
6572 -- declaration has Discriminant_Specifications so that we can verify
6573 -- conformance. However, we must remove any existing components that
6574 -- were inherited from the parent (and attached in Copy_And_Swap)
6575 -- because the full type inherits all appropriate components anyway, and
6576 -- we do not want the partial view's components interfering.
6578 if Has_Discriminants (Derived_Type) and then Discriminant_Specs then
6579 Discrim := First_Discriminant (Derived_Type);
6581 Last_Discrim := Discrim;
6582 Next_Discriminant (Discrim);
6583 exit when No (Discrim);
6586 Set_Last_Entity (Derived_Type, Last_Discrim);
6588 -- In all other cases wipe out the list of inherited components (even
6589 -- inherited discriminants), it will be properly rebuilt here.
6592 Set_First_Entity (Derived_Type, Empty);
6593 Set_Last_Entity (Derived_Type, Empty);
6596 -- STEP 1c: Initialize some flags for the Derived_Type
6598 -- The following flags must be initialized here so that
6599 -- Process_Discriminants can check that discriminants of tagged types do
6600 -- not have a default initial value and that access discriminants are
6601 -- only specified for limited records. For completeness, these flags are
6602 -- also initialized along with all the other flags below.
6604 -- AI-419: Limitedness is not inherited from an interface parent, so to
6605 -- be limited in that case the type must be explicitly declared as
6606 -- limited. However, task and protected interfaces are always limited.
6608 if Limited_Present (Type_Def) then
6609 Set_Is_Limited_Record (Derived_Type);
6611 elsif Is_Limited_Record (Parent_Type)
6612 or else (Present (Full_View (Parent_Type))
6613 and then Is_Limited_Record (Full_View (Parent_Type)))
6615 if not Is_Interface (Parent_Type)
6616 or else Is_Synchronized_Interface (Parent_Type)
6617 or else Is_Protected_Interface (Parent_Type)
6618 or else Is_Task_Interface (Parent_Type)
6620 Set_Is_Limited_Record (Derived_Type);
6624 -- STEP 2a: process discriminants of derived type if any
6626 Push_Scope (Derived_Type);
6628 if Discriminant_Specs then
6629 Set_Has_Unknown_Discriminants (Derived_Type, False);
6631 -- The following call initializes fields Has_Discriminants and
6632 -- Discriminant_Constraint, unless we are processing the completion
6633 -- of a private type declaration.
6635 Check_Or_Process_Discriminants (N, Derived_Type);
6637 -- For non-tagged types the constraint on the Parent_Type must be
6638 -- present and is used to rename the discriminants.
6640 if not Is_Tagged and then not Has_Discriminants (Parent_Type) then
6641 Error_Msg_N ("untagged parent must have discriminants", Indic);
6643 elsif not Is_Tagged and then not Constraint_Present then
6645 ("discriminant constraint needed for derived untagged records",
6648 -- Otherwise the parent subtype must be constrained unless we have a
6649 -- private extension.
6651 elsif not Constraint_Present
6652 and then not Private_Extension
6653 and then not Is_Constrained (Parent_Type)
6656 ("unconstrained type not allowed in this context", Indic);
6658 elsif Constraint_Present then
6659 -- The following call sets the field Corresponding_Discriminant
6660 -- for the discriminants in the Derived_Type.
6662 Discs := Build_Discriminant_Constraints (Parent_Type, Indic, True);
6664 -- For untagged types all new discriminants must rename
6665 -- discriminants in the parent. For private extensions new
6666 -- discriminants cannot rename old ones (implied by [7.3(13)]).
6668 Discrim := First_Discriminant (Derived_Type);
6669 while Present (Discrim) loop
6671 and then No (Corresponding_Discriminant (Discrim))
6674 ("new discriminants must constrain old ones", Discrim);
6676 elsif Private_Extension
6677 and then Present (Corresponding_Discriminant (Discrim))
6680 ("only static constraints allowed for parent"
6681 & " discriminants in the partial view", Indic);
6685 -- If a new discriminant is used in the constraint, then its
6686 -- subtype must be statically compatible with the parent
6687 -- discriminant's subtype (3.7(15)).
6689 if Present (Corresponding_Discriminant (Discrim))
6691 not Subtypes_Statically_Compatible
6693 Etype (Corresponding_Discriminant (Discrim)))
6696 ("subtype must be compatible with parent discriminant",
6700 Next_Discriminant (Discrim);
6703 -- Check whether the constraints of the full view statically
6704 -- match those imposed by the parent subtype [7.3(13)].
6706 if Present (Stored_Constraint (Derived_Type)) then
6711 C1 := First_Elmt (Discs);
6712 C2 := First_Elmt (Stored_Constraint (Derived_Type));
6713 while Present (C1) and then Present (C2) loop
6715 Fully_Conformant_Expressions (Node (C1), Node (C2))
6718 ("not conformant with previous declaration",
6729 -- STEP 2b: No new discriminants, inherit discriminants if any
6732 if Private_Extension then
6733 Set_Has_Unknown_Discriminants
6735 Has_Unknown_Discriminants (Parent_Type)
6736 or else Unknown_Discriminants_Present (N));
6738 -- The partial view of the parent may have unknown discriminants,
6739 -- but if the full view has discriminants and the parent type is
6740 -- in scope they must be inherited.
6742 elsif Has_Unknown_Discriminants (Parent_Type)
6744 (not Has_Discriminants (Parent_Type)
6745 or else not In_Open_Scopes (Scope (Parent_Type)))
6747 Set_Has_Unknown_Discriminants (Derived_Type);
6750 if not Has_Unknown_Discriminants (Derived_Type)
6751 and then not Has_Unknown_Discriminants (Parent_Base)
6752 and then Has_Discriminants (Parent_Type)
6754 Inherit_Discrims := True;
6755 Set_Has_Discriminants
6756 (Derived_Type, True);
6757 Set_Discriminant_Constraint
6758 (Derived_Type, Discriminant_Constraint (Parent_Base));
6761 -- The following test is true for private types (remember
6762 -- transformation 5. is not applied to those) and in an error
6765 if Constraint_Present then
6766 Discs := Build_Discriminant_Constraints (Parent_Type, Indic);
6769 -- For now mark a new derived type as constrained only if it has no
6770 -- discriminants. At the end of Build_Derived_Record_Type we properly
6771 -- set this flag in the case of private extensions. See comments in
6772 -- point 9. just before body of Build_Derived_Record_Type.
6776 not (Inherit_Discrims
6777 or else Has_Unknown_Discriminants (Derived_Type)));
6780 -- STEP 3: initialize fields of derived type
6782 Set_Is_Tagged_Type (Derived_Type, Is_Tagged);
6783 Set_Stored_Constraint (Derived_Type, No_Elist);
6785 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
6786 -- but cannot be interfaces
6788 if not Private_Extension
6789 and then Ekind (Derived_Type) /= E_Private_Type
6790 and then Ekind (Derived_Type) /= E_Limited_Private_Type
6792 if Interface_Present (Type_Def) then
6793 Analyze_Interface_Declaration (Derived_Type, Type_Def);
6796 Set_Interfaces (Derived_Type, No_Elist);
6799 -- Fields inherited from the Parent_Type
6802 (Derived_Type, Einfo.Discard_Names (Parent_Type));
6803 Set_Has_Specified_Layout
6804 (Derived_Type, Has_Specified_Layout (Parent_Type));
6805 Set_Is_Limited_Composite
6806 (Derived_Type, Is_Limited_Composite (Parent_Type));
6807 Set_Is_Private_Composite
6808 (Derived_Type, Is_Private_Composite (Parent_Type));
6810 -- Fields inherited from the Parent_Base
6812 Set_Has_Controlled_Component
6813 (Derived_Type, Has_Controlled_Component (Parent_Base));
6814 Set_Has_Non_Standard_Rep
6815 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6816 Set_Has_Primitive_Operations
6817 (Derived_Type, Has_Primitive_Operations (Parent_Base));
6819 -- Fields inherited from the Parent_Base in the non-private case
6821 if Ekind (Derived_Type) = E_Record_Type then
6822 Set_Has_Complex_Representation
6823 (Derived_Type, Has_Complex_Representation (Parent_Base));
6826 -- Fields inherited from the Parent_Base for record types
6828 if Is_Record_Type (Derived_Type) then
6829 Set_OK_To_Reorder_Components
6830 (Derived_Type, OK_To_Reorder_Components (Parent_Base));
6831 Set_Reverse_Bit_Order
6832 (Derived_Type, Reverse_Bit_Order (Parent_Base));
6835 -- Direct controlled types do not inherit Finalize_Storage_Only flag
6837 if not Is_Controlled (Parent_Type) then
6838 Set_Finalize_Storage_Only
6839 (Derived_Type, Finalize_Storage_Only (Parent_Type));
6842 -- Set fields for private derived types
6844 if Is_Private_Type (Derived_Type) then
6845 Set_Depends_On_Private (Derived_Type, True);
6846 Set_Private_Dependents (Derived_Type, New_Elmt_List);
6848 -- Inherit fields from non private record types. If this is the
6849 -- completion of a derivation from a private type, the parent itself
6850 -- is private, and the attributes come from its full view, which must
6854 if Is_Private_Type (Parent_Base)
6855 and then not Is_Record_Type (Parent_Base)
6857 Set_Component_Alignment
6858 (Derived_Type, Component_Alignment (Full_View (Parent_Base)));
6860 (Derived_Type, C_Pass_By_Copy (Full_View (Parent_Base)));
6862 Set_Component_Alignment
6863 (Derived_Type, Component_Alignment (Parent_Base));
6866 (Derived_Type, C_Pass_By_Copy (Parent_Base));
6870 -- Set fields for tagged types
6873 Set_Primitive_Operations (Derived_Type, New_Elmt_List);
6875 -- All tagged types defined in Ada.Finalization are controlled
6877 if Chars (Scope (Derived_Type)) = Name_Finalization
6878 and then Chars (Scope (Scope (Derived_Type))) = Name_Ada
6879 and then Scope (Scope (Scope (Derived_Type))) = Standard_Standard
6881 Set_Is_Controlled (Derived_Type);
6883 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Base));
6886 Make_Class_Wide_Type (Derived_Type);
6887 Set_Is_Abstract_Type (Derived_Type, Abstract_Present (Type_Def));
6889 if Has_Discriminants (Derived_Type)
6890 and then Constraint_Present
6892 Set_Stored_Constraint
6893 (Derived_Type, Expand_To_Stored_Constraint (Parent_Base, Discs));
6896 if Ada_Version >= Ada_05 then
6898 Ifaces_List : Elist_Id;
6901 -- Checks rules 3.9.4 (13/2 and 14/2)
6903 if Comes_From_Source (Derived_Type)
6904 and then not Is_Private_Type (Derived_Type)
6905 and then Is_Interface (Parent_Type)
6906 and then not Is_Interface (Derived_Type)
6908 if Is_Task_Interface (Parent_Type) then
6910 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
6913 elsif Is_Protected_Interface (Parent_Type) then
6915 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
6920 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
6922 Check_Interfaces (N, Type_Def);
6924 -- Ada 2005 (AI-251): Collect the list of progenitors that are
6925 -- not already in the parents.
6929 Ifaces_List => Ifaces_List,
6930 Exclude_Parents => True);
6932 Set_Interfaces (Derived_Type, Ifaces_List);
6937 Set_Is_Packed (Derived_Type, Is_Packed (Parent_Base));
6938 Set_Has_Non_Standard_Rep
6939 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6942 -- STEP 4: Inherit components from the parent base and constrain them.
6943 -- Apply the second transformation described in point 6. above.
6945 if (not Is_Empty_Elmt_List (Discs) or else Inherit_Discrims)
6946 or else not Has_Discriminants (Parent_Type)
6947 or else not Is_Constrained (Parent_Type)
6951 Constrs := Discriminant_Constraint (Parent_Type);
6956 (N, Parent_Base, Derived_Type, Is_Tagged, Inherit_Discrims, Constrs);
6958 -- STEP 5a: Copy the parent record declaration for untagged types
6960 if not Is_Tagged then
6962 -- Discriminant_Constraint (Derived_Type) has been properly
6963 -- constructed. Save it and temporarily set it to Empty because we
6964 -- do not want the call to New_Copy_Tree below to mess this list.
6966 if Has_Discriminants (Derived_Type) then
6967 Save_Discr_Constr := Discriminant_Constraint (Derived_Type);
6968 Set_Discriminant_Constraint (Derived_Type, No_Elist);
6970 Save_Discr_Constr := No_Elist;
6973 -- Save the Etype field of Derived_Type. It is correctly set now,
6974 -- but the call to New_Copy tree may remap it to point to itself,
6975 -- which is not what we want. Ditto for the Next_Entity field.
6977 Save_Etype := Etype (Derived_Type);
6978 Save_Next_Entity := Next_Entity (Derived_Type);
6980 -- Assoc_List maps all stored discriminants in the Parent_Base to
6981 -- stored discriminants in the Derived_Type. It is fundamental that
6982 -- no types or itypes with discriminants other than the stored
6983 -- discriminants appear in the entities declared inside
6984 -- Derived_Type, since the back end cannot deal with it.
6988 (Parent (Parent_Base), Map => Assoc_List, New_Sloc => Loc);
6990 -- Restore the fields saved prior to the New_Copy_Tree call
6991 -- and compute the stored constraint.
6993 Set_Etype (Derived_Type, Save_Etype);
6994 Set_Next_Entity (Derived_Type, Save_Next_Entity);
6996 if Has_Discriminants (Derived_Type) then
6997 Set_Discriminant_Constraint
6998 (Derived_Type, Save_Discr_Constr);
6999 Set_Stored_Constraint
7000 (Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs));
7001 Replace_Components (Derived_Type, New_Decl);
7004 -- Insert the new derived type declaration
7006 Rewrite (N, New_Decl);
7008 -- STEP 5b: Complete the processing for record extensions in generics
7010 -- There is no completion for record extensions declared in the
7011 -- parameter part of a generic, so we need to complete processing for
7012 -- these generic record extensions here. The Record_Type_Definition call
7013 -- will change the Ekind of the components from E_Void to E_Component.
7015 elsif Private_Extension and then Is_Generic_Type (Derived_Type) then
7016 Record_Type_Definition (Empty, Derived_Type);
7018 -- STEP 5c: Process the record extension for non private tagged types
7020 elsif not Private_Extension then
7022 -- Add the _parent field in the derived type
7024 Expand_Record_Extension (Derived_Type, Type_Def);
7026 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
7027 -- implemented interfaces if we are in expansion mode
7030 and then Has_Interfaces (Derived_Type)
7032 Add_Interface_Tag_Components (N, Derived_Type);
7035 -- Analyze the record extension
7037 Record_Type_Definition
7038 (Record_Extension_Part (Type_Def), Derived_Type);
7043 -- Nothing else to do if there is an error in the derivation.
7044 -- An unusual case: the full view may be derived from a type in an
7045 -- instance, when the partial view was used illegally as an actual
7046 -- in that instance, leading to a circular definition.
7048 if Etype (Derived_Type) = Any_Type
7049 or else Etype (Parent_Type) = Derived_Type
7054 -- Set delayed freeze and then derive subprograms, we need to do
7055 -- this in this order so that derived subprograms inherit the
7056 -- derived freeze if necessary.
7058 Set_Has_Delayed_Freeze (Derived_Type);
7060 if Derive_Subps then
7061 Derive_Subprograms (Parent_Type, Derived_Type);
7064 -- If we have a private extension which defines a constrained derived
7065 -- type mark as constrained here after we have derived subprograms. See
7066 -- comment on point 9. just above the body of Build_Derived_Record_Type.
7068 if Private_Extension and then Inherit_Discrims then
7069 if Constraint_Present and then not Is_Empty_Elmt_List (Discs) then
7070 Set_Is_Constrained (Derived_Type, True);
7071 Set_Discriminant_Constraint (Derived_Type, Discs);
7073 elsif Is_Constrained (Parent_Type) then
7075 (Derived_Type, True);
7076 Set_Discriminant_Constraint
7077 (Derived_Type, Discriminant_Constraint (Parent_Type));
7081 -- Update the class_wide type, which shares the now-completed
7082 -- entity list with its specific type.
7086 (Class_Wide_Type (Derived_Type), First_Entity (Derived_Type));
7088 (Class_Wide_Type (Derived_Type), Last_Entity (Derived_Type));
7091 -- Update the scope of anonymous access types of discriminants and other
7092 -- components, to prevent scope anomalies in gigi, when the derivation
7093 -- appears in a scope nested within that of the parent.
7099 D := First_Entity (Derived_Type);
7100 while Present (D) loop
7101 if Ekind (D) = E_Discriminant
7102 or else Ekind (D) = E_Component
7104 if Is_Itype (Etype (D))
7105 and then Ekind (Etype (D)) = E_Anonymous_Access_Type
7107 Set_Scope (Etype (D), Current_Scope);
7114 end Build_Derived_Record_Type;
7116 ------------------------
7117 -- Build_Derived_Type --
7118 ------------------------
7120 procedure Build_Derived_Type
7122 Parent_Type : Entity_Id;
7123 Derived_Type : Entity_Id;
7124 Is_Completion : Boolean;
7125 Derive_Subps : Boolean := True)
7127 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
7130 -- Set common attributes
7132 Set_Scope (Derived_Type, Current_Scope);
7134 Set_Ekind (Derived_Type, Ekind (Parent_Base));
7135 Set_Etype (Derived_Type, Parent_Base);
7136 Set_Has_Task (Derived_Type, Has_Task (Parent_Base));
7138 Set_Size_Info (Derived_Type, Parent_Type);
7139 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
7140 Set_Convention (Derived_Type, Convention (Parent_Type));
7141 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
7143 -- The derived type inherits the representation clauses of the parent.
7144 -- However, for a private type that is completed by a derivation, there
7145 -- may be operation attributes that have been specified already (stream
7146 -- attributes and External_Tag) and those must be provided. Finally,
7147 -- if the partial view is a private extension, the representation items
7148 -- of the parent have been inherited already, and should not be chained
7149 -- twice to the derived type.
7151 if Is_Tagged_Type (Parent_Type)
7152 and then Present (First_Rep_Item (Derived_Type))
7154 -- The existing items are either operational items or items inherited
7155 -- from a private extension declaration.
7159 -- Used to iterate over representation items of the derived type
7162 -- Last representation item of the (non-empty) representation
7163 -- item list of the derived type.
7165 Found : Boolean := False;
7168 Rep := First_Rep_Item (Derived_Type);
7170 while Present (Rep) loop
7171 if Rep = First_Rep_Item (Parent_Type) then
7176 Rep := Next_Rep_Item (Rep);
7178 if Present (Rep) then
7184 -- Here if we either encountered the parent type's first rep
7185 -- item on the derived type's rep item list (in which case
7186 -- Found is True, and we have nothing else to do), or if we
7187 -- reached the last rep item of the derived type, which is
7188 -- Last_Rep, in which case we further chain the parent type's
7189 -- rep items to those of the derived type.
7192 Set_Next_Rep_Item (Last_Rep, First_Rep_Item (Parent_Type));
7197 Set_First_Rep_Item (Derived_Type, First_Rep_Item (Parent_Type));
7200 case Ekind (Parent_Type) is
7201 when Numeric_Kind =>
7202 Build_Derived_Numeric_Type (N, Parent_Type, Derived_Type);
7205 Build_Derived_Array_Type (N, Parent_Type, Derived_Type);
7209 | Class_Wide_Kind =>
7210 Build_Derived_Record_Type
7211 (N, Parent_Type, Derived_Type, Derive_Subps);
7214 when Enumeration_Kind =>
7215 Build_Derived_Enumeration_Type (N, Parent_Type, Derived_Type);
7218 Build_Derived_Access_Type (N, Parent_Type, Derived_Type);
7220 when Incomplete_Or_Private_Kind =>
7221 Build_Derived_Private_Type
7222 (N, Parent_Type, Derived_Type, Is_Completion, Derive_Subps);
7224 -- For discriminated types, the derivation includes deriving
7225 -- primitive operations. For others it is done below.
7227 if Is_Tagged_Type (Parent_Type)
7228 or else Has_Discriminants (Parent_Type)
7229 or else (Present (Full_View (Parent_Type))
7230 and then Has_Discriminants (Full_View (Parent_Type)))
7235 when Concurrent_Kind =>
7236 Build_Derived_Concurrent_Type (N, Parent_Type, Derived_Type);
7239 raise Program_Error;
7242 if Etype (Derived_Type) = Any_Type then
7246 -- Set delayed freeze and then derive subprograms, we need to do this
7247 -- in this order so that derived subprograms inherit the derived freeze
7250 Set_Has_Delayed_Freeze (Derived_Type);
7251 if Derive_Subps then
7252 Derive_Subprograms (Parent_Type, Derived_Type);
7255 Set_Has_Primitive_Operations
7256 (Base_Type (Derived_Type), Has_Primitive_Operations (Parent_Type));
7257 end Build_Derived_Type;
7259 -----------------------
7260 -- Build_Discriminal --
7261 -----------------------
7263 procedure Build_Discriminal (Discrim : Entity_Id) is
7264 D_Minal : Entity_Id;
7265 CR_Disc : Entity_Id;
7268 -- A discriminal has the same name as the discriminant
7271 Make_Defining_Identifier (Sloc (Discrim),
7272 Chars => Chars (Discrim));
7274 Set_Ekind (D_Minal, E_In_Parameter);
7275 Set_Mechanism (D_Minal, Default_Mechanism);
7276 Set_Etype (D_Minal, Etype (Discrim));
7278 Set_Discriminal (Discrim, D_Minal);
7279 Set_Discriminal_Link (D_Minal, Discrim);
7281 -- For task types, build at once the discriminants of the corresponding
7282 -- record, which are needed if discriminants are used in entry defaults
7283 -- and in family bounds.
7285 if Is_Concurrent_Type (Current_Scope)
7286 or else Is_Limited_Type (Current_Scope)
7288 CR_Disc := Make_Defining_Identifier (Sloc (Discrim), Chars (Discrim));
7290 Set_Ekind (CR_Disc, E_In_Parameter);
7291 Set_Mechanism (CR_Disc, Default_Mechanism);
7292 Set_Etype (CR_Disc, Etype (Discrim));
7293 Set_Discriminal_Link (CR_Disc, Discrim);
7294 Set_CR_Discriminant (Discrim, CR_Disc);
7296 end Build_Discriminal;
7298 ------------------------------------
7299 -- Build_Discriminant_Constraints --
7300 ------------------------------------
7302 function Build_Discriminant_Constraints
7305 Derived_Def : Boolean := False) return Elist_Id
7307 C : constant Node_Id := Constraint (Def);
7308 Nb_Discr : constant Nat := Number_Discriminants (T);
7310 Discr_Expr : array (1 .. Nb_Discr) of Node_Id := (others => Empty);
7311 -- Saves the expression corresponding to a given discriminant in T
7313 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat;
7314 -- Return the Position number within array Discr_Expr of a discriminant
7315 -- D within the discriminant list of the discriminated type T.
7321 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat is
7325 Disc := First_Discriminant (T);
7326 for J in Discr_Expr'Range loop
7331 Next_Discriminant (Disc);
7334 -- Note: Since this function is called on discriminants that are
7335 -- known to belong to the discriminated type, falling through the
7336 -- loop with no match signals an internal compiler error.
7338 raise Program_Error;
7341 -- Declarations local to Build_Discriminant_Constraints
7345 Elist : constant Elist_Id := New_Elmt_List;
7353 Discrim_Present : Boolean := False;
7355 -- Start of processing for Build_Discriminant_Constraints
7358 -- The following loop will process positional associations only.
7359 -- For a positional association, the (single) discriminant is
7360 -- implicitly specified by position, in textual order (RM 3.7.2).
7362 Discr := First_Discriminant (T);
7363 Constr := First (Constraints (C));
7364 for D in Discr_Expr'Range loop
7365 exit when Nkind (Constr) = N_Discriminant_Association;
7368 Error_Msg_N ("too few discriminants given in constraint", C);
7369 return New_Elmt_List;
7371 elsif Nkind (Constr) = N_Range
7372 or else (Nkind (Constr) = N_Attribute_Reference
7374 Attribute_Name (Constr) = Name_Range)
7377 ("a range is not a valid discriminant constraint", Constr);
7378 Discr_Expr (D) := Error;
7381 Analyze_And_Resolve (Constr, Base_Type (Etype (Discr)));
7382 Discr_Expr (D) := Constr;
7385 Next_Discriminant (Discr);
7389 if No (Discr) and then Present (Constr) then
7390 Error_Msg_N ("too many discriminants given in constraint", Constr);
7391 return New_Elmt_List;
7394 -- Named associations can be given in any order, but if both positional
7395 -- and named associations are used in the same discriminant constraint,
7396 -- then positional associations must occur first, at their normal
7397 -- position. Hence once a named association is used, the rest of the
7398 -- discriminant constraint must use only named associations.
7400 while Present (Constr) loop
7402 -- Positional association forbidden after a named association
7404 if Nkind (Constr) /= N_Discriminant_Association then
7405 Error_Msg_N ("positional association follows named one", Constr);
7406 return New_Elmt_List;
7408 -- Otherwise it is a named association
7411 -- E records the type of the discriminants in the named
7412 -- association. All the discriminants specified in the same name
7413 -- association must have the same type.
7417 -- Search the list of discriminants in T to see if the simple name
7418 -- given in the constraint matches any of them.
7420 Id := First (Selector_Names (Constr));
7421 while Present (Id) loop
7424 -- If Original_Discriminant is present, we are processing a
7425 -- generic instantiation and this is an instance node. We need
7426 -- to find the name of the corresponding discriminant in the
7427 -- actual record type T and not the name of the discriminant in
7428 -- the generic formal. Example:
7431 -- type G (D : int) is private;
7433 -- subtype W is G (D => 1);
7435 -- type Rec (X : int) is record ... end record;
7436 -- package Q is new P (G => Rec);
7438 -- At the point of the instantiation, formal type G is Rec
7439 -- and therefore when reanalyzing "subtype W is G (D => 1);"
7440 -- which really looks like "subtype W is Rec (D => 1);" at
7441 -- the point of instantiation, we want to find the discriminant
7442 -- that corresponds to D in Rec, i.e. X.
7444 if Present (Original_Discriminant (Id)) then
7445 Discr := Find_Corresponding_Discriminant (Id, T);
7449 Discr := First_Discriminant (T);
7450 while Present (Discr) loop
7451 if Chars (Discr) = Chars (Id) then
7456 Next_Discriminant (Discr);
7460 Error_Msg_N ("& does not match any discriminant", Id);
7461 return New_Elmt_List;
7463 -- The following is only useful for the benefit of generic
7464 -- instances but it does not interfere with other
7465 -- processing for the non-generic case so we do it in all
7466 -- cases (for generics this statement is executed when
7467 -- processing the generic definition, see comment at the
7468 -- beginning of this if statement).
7471 Set_Original_Discriminant (Id, Discr);
7475 Position := Pos_Of_Discr (T, Discr);
7477 if Present (Discr_Expr (Position)) then
7478 Error_Msg_N ("duplicate constraint for discriminant&", Id);
7481 -- Each discriminant specified in the same named association
7482 -- must be associated with a separate copy of the
7483 -- corresponding expression.
7485 if Present (Next (Id)) then
7486 Expr := New_Copy_Tree (Expression (Constr));
7487 Set_Parent (Expr, Parent (Expression (Constr)));
7489 Expr := Expression (Constr);
7492 Discr_Expr (Position) := Expr;
7493 Analyze_And_Resolve (Expr, Base_Type (Etype (Discr)));
7496 -- A discriminant association with more than one discriminant
7497 -- name is only allowed if the named discriminants are all of
7498 -- the same type (RM 3.7.1(8)).
7501 E := Base_Type (Etype (Discr));
7503 elsif Base_Type (Etype (Discr)) /= E then
7505 ("all discriminants in an association " &
7506 "must have the same type", Id);
7516 -- A discriminant constraint must provide exactly one value for each
7517 -- discriminant of the type (RM 3.7.1(8)).
7519 for J in Discr_Expr'Range loop
7520 if No (Discr_Expr (J)) then
7521 Error_Msg_N ("too few discriminants given in constraint", C);
7522 return New_Elmt_List;
7526 -- Determine if there are discriminant expressions in the constraint
7528 for J in Discr_Expr'Range loop
7529 if Denotes_Discriminant
7530 (Discr_Expr (J), Check_Concurrent => True)
7532 Discrim_Present := True;
7536 -- Build an element list consisting of the expressions given in the
7537 -- discriminant constraint and apply the appropriate checks. The list
7538 -- is constructed after resolving any named discriminant associations
7539 -- and therefore the expressions appear in the textual order of the
7542 Discr := First_Discriminant (T);
7543 for J in Discr_Expr'Range loop
7544 if Discr_Expr (J) /= Error then
7545 Append_Elmt (Discr_Expr (J), Elist);
7547 -- If any of the discriminant constraints is given by a
7548 -- discriminant and we are in a derived type declaration we
7549 -- have a discriminant renaming. Establish link between new
7550 -- and old discriminant.
7552 if Denotes_Discriminant (Discr_Expr (J)) then
7554 Set_Corresponding_Discriminant
7555 (Entity (Discr_Expr (J)), Discr);
7558 -- Force the evaluation of non-discriminant expressions.
7559 -- If we have found a discriminant in the constraint 3.4(26)
7560 -- and 3.8(18) demand that no range checks are performed are
7561 -- after evaluation. If the constraint is for a component
7562 -- definition that has a per-object constraint, expressions are
7563 -- evaluated but not checked either. In all other cases perform
7567 if Discrim_Present then
7570 elsif Nkind (Parent (Parent (Def))) = N_Component_Declaration
7572 Has_Per_Object_Constraint
7573 (Defining_Identifier (Parent (Parent (Def))))
7577 elsif Is_Access_Type (Etype (Discr)) then
7578 Apply_Constraint_Check (Discr_Expr (J), Etype (Discr));
7581 Apply_Range_Check (Discr_Expr (J), Etype (Discr));
7584 Force_Evaluation (Discr_Expr (J));
7587 -- Check that the designated type of an access discriminant's
7588 -- expression is not a class-wide type unless the discriminant's
7589 -- designated type is also class-wide.
7591 if Ekind (Etype (Discr)) = E_Anonymous_Access_Type
7592 and then not Is_Class_Wide_Type
7593 (Designated_Type (Etype (Discr)))
7594 and then Etype (Discr_Expr (J)) /= Any_Type
7595 and then Is_Class_Wide_Type
7596 (Designated_Type (Etype (Discr_Expr (J))))
7598 Wrong_Type (Discr_Expr (J), Etype (Discr));
7602 Next_Discriminant (Discr);
7606 end Build_Discriminant_Constraints;
7608 ---------------------------------
7609 -- Build_Discriminated_Subtype --
7610 ---------------------------------
7612 procedure Build_Discriminated_Subtype
7616 Related_Nod : Node_Id;
7617 For_Access : Boolean := False)
7619 Has_Discrs : constant Boolean := Has_Discriminants (T);
7620 Constrained : constant Boolean :=
7622 and then not Is_Empty_Elmt_List (Elist)
7623 and then not Is_Class_Wide_Type (T))
7624 or else Is_Constrained (T);
7627 if Ekind (T) = E_Record_Type then
7629 Set_Ekind (Def_Id, E_Private_Subtype);
7630 Set_Is_For_Access_Subtype (Def_Id, True);
7632 Set_Ekind (Def_Id, E_Record_Subtype);
7635 -- Inherit preelaboration flag from base, for types for which it
7636 -- may have been set: records, private types, protected types.
7638 Set_Known_To_Have_Preelab_Init
7639 (Def_Id, Known_To_Have_Preelab_Init (T));
7641 elsif Ekind (T) = E_Task_Type then
7642 Set_Ekind (Def_Id, E_Task_Subtype);
7644 elsif Ekind (T) = E_Protected_Type then
7645 Set_Ekind (Def_Id, E_Protected_Subtype);
7646 Set_Known_To_Have_Preelab_Init
7647 (Def_Id, Known_To_Have_Preelab_Init (T));
7649 elsif Is_Private_Type (T) then
7650 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
7651 Set_Known_To_Have_Preelab_Init
7652 (Def_Id, Known_To_Have_Preelab_Init (T));
7654 elsif Is_Class_Wide_Type (T) then
7655 Set_Ekind (Def_Id, E_Class_Wide_Subtype);
7658 -- Incomplete type. Attach subtype to list of dependents, to be
7659 -- completed with full view of parent type, unless is it the
7660 -- designated subtype of a record component within an init_proc.
7661 -- This last case arises for a component of an access type whose
7662 -- designated type is incomplete (e.g. a Taft Amendment type).
7663 -- The designated subtype is within an inner scope, and needs no
7664 -- elaboration, because only the access type is needed in the
7665 -- initialization procedure.
7667 Set_Ekind (Def_Id, Ekind (T));
7669 if For_Access and then Within_Init_Proc then
7672 Append_Elmt (Def_Id, Private_Dependents (T));
7676 Set_Etype (Def_Id, T);
7677 Init_Size_Align (Def_Id);
7678 Set_Has_Discriminants (Def_Id, Has_Discrs);
7679 Set_Is_Constrained (Def_Id, Constrained);
7681 Set_First_Entity (Def_Id, First_Entity (T));
7682 Set_Last_Entity (Def_Id, Last_Entity (T));
7684 -- If the subtype is the completion of a private declaration, there may
7685 -- have been representation clauses for the partial view, and they must
7686 -- be preserved. Build_Derived_Type chains the inherited clauses with
7687 -- the ones appearing on the extension. If this comes from a subtype
7688 -- declaration, all clauses are inherited.
7690 if No (First_Rep_Item (Def_Id)) then
7691 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
7694 if Is_Tagged_Type (T) then
7695 Set_Is_Tagged_Type (Def_Id);
7696 Make_Class_Wide_Type (Def_Id);
7699 Set_Stored_Constraint (Def_Id, No_Elist);
7702 Set_Discriminant_Constraint (Def_Id, Elist);
7703 Set_Stored_Constraint_From_Discriminant_Constraint (Def_Id);
7706 if Is_Tagged_Type (T) then
7708 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
7709 -- concurrent record type (which has the list of primitive
7712 if Ada_Version >= Ada_05
7713 and then Is_Concurrent_Type (T)
7715 Set_Corresponding_Record_Type (Def_Id,
7716 Corresponding_Record_Type (T));
7718 Set_Primitive_Operations (Def_Id, Primitive_Operations (T));
7721 Set_Is_Abstract_Type (Def_Id, Is_Abstract_Type (T));
7724 -- Subtypes introduced by component declarations do not need to be
7725 -- marked as delayed, and do not get freeze nodes, because the semantics
7726 -- verifies that the parents of the subtypes are frozen before the
7727 -- enclosing record is frozen.
7729 if not Is_Type (Scope (Def_Id)) then
7730 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
7732 if Is_Private_Type (T)
7733 and then Present (Full_View (T))
7735 Conditional_Delay (Def_Id, Full_View (T));
7737 Conditional_Delay (Def_Id, T);
7741 if Is_Record_Type (T) then
7742 Set_Is_Limited_Record (Def_Id, Is_Limited_Record (T));
7745 and then not Is_Empty_Elmt_List (Elist)
7746 and then not For_Access
7748 Create_Constrained_Components (Def_Id, Related_Nod, T, Elist);
7749 elsif not For_Access then
7750 Set_Cloned_Subtype (Def_Id, T);
7753 end Build_Discriminated_Subtype;
7755 ---------------------------
7756 -- Build_Itype_Reference --
7757 ---------------------------
7759 procedure Build_Itype_Reference
7763 IR : constant Node_Id := Make_Itype_Reference (Sloc (Nod));
7765 Set_Itype (IR, Ityp);
7766 Insert_After (Nod, IR);
7767 end Build_Itype_Reference;
7769 ------------------------
7770 -- Build_Scalar_Bound --
7771 ------------------------
7773 function Build_Scalar_Bound
7776 Der_T : Entity_Id) return Node_Id
7778 New_Bound : Entity_Id;
7781 -- Note: not clear why this is needed, how can the original bound
7782 -- be unanalyzed at this point? and if it is, what business do we
7783 -- have messing around with it? and why is the base type of the
7784 -- parent type the right type for the resolution. It probably is
7785 -- not! It is OK for the new bound we are creating, but not for
7786 -- the old one??? Still if it never happens, no problem!
7788 Analyze_And_Resolve (Bound, Base_Type (Par_T));
7790 if Nkind_In (Bound, N_Integer_Literal, N_Real_Literal) then
7791 New_Bound := New_Copy (Bound);
7792 Set_Etype (New_Bound, Der_T);
7793 Set_Analyzed (New_Bound);
7795 elsif Is_Entity_Name (Bound) then
7796 New_Bound := OK_Convert_To (Der_T, New_Copy (Bound));
7798 -- The following is almost certainly wrong. What business do we have
7799 -- relocating a node (Bound) that is presumably still attached to
7800 -- the tree elsewhere???
7803 New_Bound := OK_Convert_To (Der_T, Relocate_Node (Bound));
7806 Set_Etype (New_Bound, Der_T);
7808 end Build_Scalar_Bound;
7810 --------------------------------
7811 -- Build_Underlying_Full_View --
7812 --------------------------------
7814 procedure Build_Underlying_Full_View
7819 Loc : constant Source_Ptr := Sloc (N);
7820 Subt : constant Entity_Id :=
7821 Make_Defining_Identifier
7822 (Loc, New_External_Name (Chars (Typ), 'S'));
7829 procedure Set_Discriminant_Name (Id : Node_Id);
7830 -- If the derived type has discriminants, they may rename discriminants
7831 -- of the parent. When building the full view of the parent, we need to
7832 -- recover the names of the original discriminants if the constraint is
7833 -- given by named associations.
7835 ---------------------------
7836 -- Set_Discriminant_Name --
7837 ---------------------------
7839 procedure Set_Discriminant_Name (Id : Node_Id) is
7843 Set_Original_Discriminant (Id, Empty);
7845 if Has_Discriminants (Typ) then
7846 Disc := First_Discriminant (Typ);
7847 while Present (Disc) loop
7848 if Chars (Disc) = Chars (Id)
7849 and then Present (Corresponding_Discriminant (Disc))
7851 Set_Chars (Id, Chars (Corresponding_Discriminant (Disc)));
7853 Next_Discriminant (Disc);
7856 end Set_Discriminant_Name;
7858 -- Start of processing for Build_Underlying_Full_View
7861 if Nkind (N) = N_Full_Type_Declaration then
7862 Constr := Constraint (Subtype_Indication (Type_Definition (N)));
7864 elsif Nkind (N) = N_Subtype_Declaration then
7865 Constr := New_Copy_Tree (Constraint (Subtype_Indication (N)));
7867 elsif Nkind (N) = N_Component_Declaration then
7870 (Constraint (Subtype_Indication (Component_Definition (N))));
7873 raise Program_Error;
7876 C := First (Constraints (Constr));
7877 while Present (C) loop
7878 if Nkind (C) = N_Discriminant_Association then
7879 Id := First (Selector_Names (C));
7880 while Present (Id) loop
7881 Set_Discriminant_Name (Id);
7890 Make_Subtype_Declaration (Loc,
7891 Defining_Identifier => Subt,
7892 Subtype_Indication =>
7893 Make_Subtype_Indication (Loc,
7894 Subtype_Mark => New_Reference_To (Par, Loc),
7895 Constraint => New_Copy_Tree (Constr)));
7897 -- If this is a component subtype for an outer itype, it is not
7898 -- a list member, so simply set the parent link for analysis: if
7899 -- the enclosing type does not need to be in a declarative list,
7900 -- neither do the components.
7902 if Is_List_Member (N)
7903 and then Nkind (N) /= N_Component_Declaration
7905 Insert_Before (N, Indic);
7907 Set_Parent (Indic, Parent (N));
7911 Set_Underlying_Full_View (Typ, Full_View (Subt));
7912 end Build_Underlying_Full_View;
7914 -------------------------------
7915 -- Check_Abstract_Overriding --
7916 -------------------------------
7918 procedure Check_Abstract_Overriding (T : Entity_Id) is
7919 Alias_Subp : Entity_Id;
7926 Op_List := Primitive_Operations (T);
7928 -- Loop to check primitive operations
7930 Elmt := First_Elmt (Op_List);
7931 while Present (Elmt) loop
7932 Subp := Node (Elmt);
7933 Alias_Subp := Alias (Subp);
7935 -- Inherited subprograms are identified by the fact that they do not
7936 -- come from source, and the associated source location is the
7937 -- location of the first subtype of the derived type.
7939 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
7940 -- subprograms that "require overriding".
7942 -- Special exception, do not complain about failure to override the
7943 -- stream routines _Input and _Output, as well as the primitive
7944 -- operations used in dispatching selects since we always provide
7945 -- automatic overridings for these subprograms.
7947 -- Also ignore this rule for convention CIL since .NET libraries
7948 -- do bizarre things with interfaces???
7950 -- The partial view of T may have been a private extension, for
7951 -- which inherited functions dispatching on result are abstract.
7952 -- If the full view is a null extension, there is no need for
7953 -- overriding in Ada2005, but wrappers need to be built for them
7954 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
7956 if Is_Null_Extension (T)
7957 and then Has_Controlling_Result (Subp)
7958 and then Ada_Version >= Ada_05
7959 and then Present (Alias_Subp)
7960 and then not Comes_From_Source (Subp)
7961 and then not Is_Abstract_Subprogram (Alias_Subp)
7962 and then not Is_Access_Type (Etype (Subp))
7966 -- Ada 2005 (AI-251): Internal entities of interfaces need no
7967 -- processing because this check is done with the aliased
7970 elsif Present (Interface_Alias (Subp)) then
7973 elsif (Is_Abstract_Subprogram (Subp)
7974 or else Requires_Overriding (Subp)
7976 (Has_Controlling_Result (Subp)
7977 and then Present (Alias_Subp)
7978 and then not Comes_From_Source (Subp)
7979 and then Sloc (Subp) = Sloc (First_Subtype (T))))
7980 and then not Is_TSS (Subp, TSS_Stream_Input)
7981 and then not Is_TSS (Subp, TSS_Stream_Output)
7982 and then not Is_Abstract_Type (T)
7983 and then Convention (T) /= Convention_CIL
7984 and then not Is_Predefined_Interface_Primitive (Subp)
7986 -- Ada 2005 (AI-251): Do not consider hidden entities associated
7987 -- with abstract interface types because the check will be done
7988 -- with the aliased entity (otherwise we generate a duplicated
7991 and then not Present (Interface_Alias (Subp))
7993 if Present (Alias_Subp) then
7995 -- Only perform the check for a derived subprogram when the
7996 -- type has an explicit record extension. This avoids incorrect
7997 -- flagging of abstract subprograms for the case of a type
7998 -- without an extension that is derived from a formal type
7999 -- with a tagged actual (can occur within a private part).
8001 -- Ada 2005 (AI-391): In the case of an inherited function with
8002 -- a controlling result of the type, the rule does not apply if
8003 -- the type is a null extension (unless the parent function
8004 -- itself is abstract, in which case the function must still be
8005 -- be overridden). The expander will generate an overriding
8006 -- wrapper function calling the parent subprogram (see
8007 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
8009 Type_Def := Type_Definition (Parent (T));
8011 if Nkind (Type_Def) = N_Derived_Type_Definition
8012 and then Present (Record_Extension_Part (Type_Def))
8014 (Ada_Version < Ada_05
8015 or else not Is_Null_Extension (T)
8016 or else Ekind (Subp) = E_Procedure
8017 or else not Has_Controlling_Result (Subp)
8018 or else Is_Abstract_Subprogram (Alias_Subp)
8019 or else Requires_Overriding (Subp)
8020 or else Is_Access_Type (Etype (Subp)))
8022 -- Avoid reporting error in case of abstract predefined
8023 -- primitive inherited from interface type because the
8024 -- body of internally generated predefined primitives
8025 -- of tagged types are generated later by Freeze_Type
8027 if Is_Interface (Root_Type (T))
8028 and then Is_Abstract_Subprogram (Subp)
8029 and then Is_Predefined_Dispatching_Operation (Subp)
8030 and then not Comes_From_Source (Ultimate_Alias (Subp))
8036 ("type must be declared abstract or & overridden",
8039 -- Traverse the whole chain of aliased subprograms to
8040 -- complete the error notification. This is especially
8041 -- useful for traceability of the chain of entities when
8042 -- the subprogram corresponds with an interface
8043 -- subprogram (which may be defined in another package).
8045 if Present (Alias_Subp) then
8051 while Present (Alias (E)) loop
8052 Error_Msg_Sloc := Sloc (E);
8054 ("\& has been inherited #", T, Subp);
8058 Error_Msg_Sloc := Sloc (E);
8060 ("\& has been inherited from subprogram #",
8066 -- Ada 2005 (AI-345): Protected or task type implementing
8067 -- abstract interfaces.
8069 elsif Is_Concurrent_Record_Type (T)
8070 and then Present (Interfaces (T))
8072 -- The controlling formal of Subp must be of mode "out",
8073 -- "in out" or an access-to-variable to be overridden.
8075 -- Error message below needs rewording (remember comma
8076 -- in -gnatj mode) ???
8078 if Ekind (First_Formal (Subp)) = E_In_Parameter then
8079 if not Is_Predefined_Dispatching_Operation (Subp) then
8081 ("first formal of & must be of mode `OUT`, " &
8082 "`IN OUT` or access-to-variable", T, Subp);
8084 ("\to be overridden by protected procedure or " &
8085 "entry (RM 9.4(11.9/2))", T);
8088 -- Some other kind of overriding failure
8092 ("interface subprogram & must be overridden",
8098 Error_Msg_Node_2 := T;
8100 ("abstract subprogram& not allowed for type&", Subp);
8102 -- Also post unconditional warning on the type (unconditional
8103 -- so that if there are more than one of these cases, we get
8104 -- them all, and not just the first one).
8106 Error_Msg_Node_2 := Subp;
8108 ("nonabstract type& has abstract subprogram&!", T);
8112 -- Ada 2005 (AI05-0030): Inspect hidden subprograms which provide
8113 -- the mapping between interface and implementing type primitives.
8114 -- If the interface alias is marked as Implemented_By_Entry, the
8115 -- alias must be an entry wrapper.
8117 if Ada_Version >= Ada_05
8118 and then Is_Hidden (Subp)
8119 and then Present (Interface_Alias (Subp))
8120 and then Implemented_By_Entry (Interface_Alias (Subp))
8121 and then Present (Alias_Subp)
8123 (not Is_Primitive_Wrapper (Alias_Subp)
8124 or else Ekind (Wrapped_Entity (Alias_Subp)) /= E_Entry)
8127 Error_Ent : Entity_Id := T;
8130 if Is_Concurrent_Record_Type (Error_Ent) then
8131 Error_Ent := Corresponding_Concurrent_Type (Error_Ent);
8134 Error_Msg_Node_2 := Interface_Alias (Subp);
8136 ("type & must implement abstract subprogram & with an entry",
8137 Error_Ent, Error_Ent);
8143 end Check_Abstract_Overriding;
8145 ------------------------------------------------
8146 -- Check_Access_Discriminant_Requires_Limited --
8147 ------------------------------------------------
8149 procedure Check_Access_Discriminant_Requires_Limited
8154 -- A discriminant_specification for an access discriminant shall appear
8155 -- only in the declaration for a task or protected type, or for a type
8156 -- with the reserved word 'limited' in its definition or in one of its
8157 -- ancestors. (RM 3.7(10))
8159 if Nkind (Discriminant_Type (D)) = N_Access_Definition
8160 and then not Is_Concurrent_Type (Current_Scope)
8161 and then not Is_Concurrent_Record_Type (Current_Scope)
8162 and then not Is_Limited_Record (Current_Scope)
8163 and then Ekind (Current_Scope) /= E_Limited_Private_Type
8166 ("access discriminants allowed only for limited types", Loc);
8168 end Check_Access_Discriminant_Requires_Limited;
8170 -----------------------------------
8171 -- Check_Aliased_Component_Types --
8172 -----------------------------------
8174 procedure Check_Aliased_Component_Types (T : Entity_Id) is
8178 -- ??? Also need to check components of record extensions, but not
8179 -- components of protected types (which are always limited).
8181 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
8182 -- types to be unconstrained. This is safe because it is illegal to
8183 -- create access subtypes to such types with explicit discriminant
8186 if not Is_Limited_Type (T) then
8187 if Ekind (T) = E_Record_Type then
8188 C := First_Component (T);
8189 while Present (C) loop
8191 and then Has_Discriminants (Etype (C))
8192 and then not Is_Constrained (Etype (C))
8193 and then not In_Instance_Body
8194 and then Ada_Version < Ada_05
8197 ("aliased component must be constrained (RM 3.6(11))",
8204 elsif Ekind (T) = E_Array_Type then
8205 if Has_Aliased_Components (T)
8206 and then Has_Discriminants (Component_Type (T))
8207 and then not Is_Constrained (Component_Type (T))
8208 and then not In_Instance_Body
8209 and then Ada_Version < Ada_05
8212 ("aliased component type must be constrained (RM 3.6(11))",
8217 end Check_Aliased_Component_Types;
8219 ----------------------
8220 -- Check_Completion --
8221 ----------------------
8223 procedure Check_Completion (Body_Id : Node_Id := Empty) is
8226 procedure Post_Error;
8227 -- Post error message for lack of completion for entity E
8233 procedure Post_Error is
8235 if not Comes_From_Source (E) then
8237 if Ekind (E) = E_Task_Type
8238 or else Ekind (E) = E_Protected_Type
8240 -- It may be an anonymous protected type created for a
8241 -- single variable. Post error on variable, if present.
8247 Var := First_Entity (Current_Scope);
8248 while Present (Var) loop
8249 exit when Etype (Var) = E
8250 and then Comes_From_Source (Var);
8255 if Present (Var) then
8262 -- If a generated entity has no completion, then either previous
8263 -- semantic errors have disabled the expansion phase, or else we had
8264 -- missing subunits, or else we are compiling without expansion,
8265 -- or else something is very wrong.
8267 if not Comes_From_Source (E) then
8269 (Serious_Errors_Detected > 0
8270 or else Configurable_Run_Time_Violations > 0
8271 or else Subunits_Missing
8272 or else not Expander_Active);
8275 -- Here for source entity
8278 -- Here if no body to post the error message, so we post the error
8279 -- on the declaration that has no completion. This is not really
8280 -- the right place to post it, think about this later ???
8282 if No (Body_Id) then
8285 ("missing full declaration for }", Parent (E), E);
8288 ("missing body for &", Parent (E), E);
8291 -- Package body has no completion for a declaration that appears
8292 -- in the corresponding spec. Post error on the body, with a
8293 -- reference to the non-completed declaration.
8296 Error_Msg_Sloc := Sloc (E);
8300 ("missing full declaration for }!", Body_Id, E);
8302 elsif Is_Overloadable (E)
8303 and then Current_Entity_In_Scope (E) /= E
8305 -- It may be that the completion is mistyped and appears as
8306 -- a distinct overloading of the entity.
8309 Candidate : constant Entity_Id :=
8310 Current_Entity_In_Scope (E);
8311 Decl : constant Node_Id :=
8312 Unit_Declaration_Node (Candidate);
8315 if Is_Overloadable (Candidate)
8316 and then Ekind (Candidate) = Ekind (E)
8317 and then Nkind (Decl) = N_Subprogram_Body
8318 and then Acts_As_Spec (Decl)
8320 Check_Type_Conformant (Candidate, E);
8323 Error_Msg_NE ("missing body for & declared#!",
8328 Error_Msg_NE ("missing body for & declared#!",
8335 -- Start processing for Check_Completion
8338 E := First_Entity (Current_Scope);
8339 while Present (E) loop
8340 if Is_Intrinsic_Subprogram (E) then
8343 -- The following situation requires special handling: a child unit
8344 -- that appears in the context clause of the body of its parent:
8346 -- procedure Parent.Child (...);
8348 -- with Parent.Child;
8349 -- package body Parent is
8351 -- Here Parent.Child appears as a local entity, but should not be
8352 -- flagged as requiring completion, because it is a compilation
8355 -- Ignore missing completion for a subprogram that does not come from
8356 -- source (including the _Call primitive operation of RAS types,
8357 -- which has to have the flag Comes_From_Source for other purposes):
8358 -- we assume that the expander will provide the missing completion.
8360 elsif Ekind (E) = E_Function
8361 or else Ekind (E) = E_Procedure
8362 or else Ekind (E) = E_Generic_Function
8363 or else Ekind (E) = E_Generic_Procedure
8365 if not Has_Completion (E)
8366 and then not (Is_Subprogram (E)
8367 and then Is_Abstract_Subprogram (E))
8368 and then not (Is_Subprogram (E)
8370 (not Comes_From_Source (E)
8371 or else Chars (E) = Name_uCall))
8372 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8374 and then Chars (E) /= Name_uSize
8379 elsif Is_Entry (E) then
8380 if not Has_Completion (E) and then
8381 (Ekind (Scope (E)) = E_Protected_Object
8382 or else Ekind (Scope (E)) = E_Protected_Type)
8387 elsif Is_Package_Or_Generic_Package (E) then
8388 if Unit_Requires_Body (E) then
8389 if not Has_Completion (E)
8390 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8396 elsif not Is_Child_Unit (E) then
8397 May_Need_Implicit_Body (E);
8400 elsif Ekind (E) = E_Incomplete_Type
8401 and then No (Underlying_Type (E))
8405 elsif (Ekind (E) = E_Task_Type or else
8406 Ekind (E) = E_Protected_Type)
8407 and then not Has_Completion (E)
8411 -- A single task declared in the current scope is a constant, verify
8412 -- that the body of its anonymous type is in the same scope. If the
8413 -- task is defined elsewhere, this may be a renaming declaration for
8414 -- which no completion is needed.
8416 elsif Ekind (E) = E_Constant
8417 and then Ekind (Etype (E)) = E_Task_Type
8418 and then not Has_Completion (Etype (E))
8419 and then Scope (Etype (E)) = Current_Scope
8423 elsif Ekind (E) = E_Protected_Object
8424 and then not Has_Completion (Etype (E))
8428 elsif Ekind (E) = E_Record_Type then
8429 if Is_Tagged_Type (E) then
8430 Check_Abstract_Overriding (E);
8431 Check_Conventions (E);
8434 Check_Aliased_Component_Types (E);
8436 elsif Ekind (E) = E_Array_Type then
8437 Check_Aliased_Component_Types (E);
8443 end Check_Completion;
8445 ----------------------------
8446 -- Check_Delta_Expression --
8447 ----------------------------
8449 procedure Check_Delta_Expression (E : Node_Id) is
8451 if not (Is_Real_Type (Etype (E))) then
8452 Wrong_Type (E, Any_Real);
8454 elsif not Is_OK_Static_Expression (E) then
8455 Flag_Non_Static_Expr
8456 ("non-static expression used for delta value!", E);
8458 elsif not UR_Is_Positive (Expr_Value_R (E)) then
8459 Error_Msg_N ("delta expression must be positive", E);
8465 -- If any of above errors occurred, then replace the incorrect
8466 -- expression by the real 0.1, which should prevent further errors.
8469 Make_Real_Literal (Sloc (E), Ureal_Tenth));
8470 Analyze_And_Resolve (E, Standard_Float);
8471 end Check_Delta_Expression;
8473 -----------------------------
8474 -- Check_Digits_Expression --
8475 -----------------------------
8477 procedure Check_Digits_Expression (E : Node_Id) is
8479 if not (Is_Integer_Type (Etype (E))) then
8480 Wrong_Type (E, Any_Integer);
8482 elsif not Is_OK_Static_Expression (E) then
8483 Flag_Non_Static_Expr
8484 ("non-static expression used for digits value!", E);
8486 elsif Expr_Value (E) <= 0 then
8487 Error_Msg_N ("digits value must be greater than zero", E);
8493 -- If any of above errors occurred, then replace the incorrect
8494 -- expression by the integer 1, which should prevent further errors.
8496 Rewrite (E, Make_Integer_Literal (Sloc (E), 1));
8497 Analyze_And_Resolve (E, Standard_Integer);
8499 end Check_Digits_Expression;
8501 --------------------------
8502 -- Check_Initialization --
8503 --------------------------
8505 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id) is
8507 if Is_Limited_Type (T)
8508 and then not In_Instance
8509 and then not In_Inlined_Body
8511 if not OK_For_Limited_Init (Exp) then
8513 -- In GNAT mode, this is just a warning, to allow it to be evilly
8514 -- turned off. Otherwise it is a real error.
8518 ("?cannot initialize entities of limited type!", Exp);
8520 elsif Ada_Version < Ada_05 then
8522 ("cannot initialize entities of limited type", Exp);
8523 Explain_Limited_Type (T, Exp);
8526 -- Specialize error message according to kind of illegal
8527 -- initial expression.
8529 if Nkind (Exp) = N_Type_Conversion
8530 and then Nkind (Expression (Exp)) = N_Function_Call
8533 ("illegal context for call"
8534 & " to function with limited result", Exp);
8538 ("initialization of limited object requires aggregate "
8539 & "or function call", Exp);
8544 end Check_Initialization;
8546 ----------------------
8547 -- Check_Interfaces --
8548 ----------------------
8550 procedure Check_Interfaces (N : Node_Id; Def : Node_Id) is
8551 Parent_Type : constant Entity_Id := Etype (Defining_Identifier (N));
8554 Iface_Def : Node_Id;
8555 Iface_Typ : Entity_Id;
8556 Parent_Node : Node_Id;
8558 Is_Task : Boolean := False;
8559 -- Set True if parent type or any progenitor is a task interface
8561 Is_Protected : Boolean := False;
8562 -- Set True if parent type or any progenitor is a protected interface
8564 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id);
8565 -- Check that a progenitor is compatible with declaration.
8566 -- Error is posted on Error_Node.
8572 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id) is
8573 Iface_Id : constant Entity_Id :=
8574 Defining_Identifier (Parent (Iface_Def));
8578 if Nkind (N) = N_Private_Extension_Declaration then
8581 Type_Def := Type_Definition (N);
8584 if Is_Task_Interface (Iface_Id) then
8587 elsif Is_Protected_Interface (Iface_Id) then
8588 Is_Protected := True;
8591 -- Check that the characteristics of the progenitor are compatible
8592 -- with the explicit qualifier in the declaration.
8593 -- The check only applies to qualifiers that come from source.
8594 -- Limited_Present also appears in the declaration of corresponding
8595 -- records, and the check does not apply to them.
8597 if Limited_Present (Type_Def)
8599 Is_Concurrent_Record_Type (Defining_Identifier (N))
8601 if Is_Limited_Interface (Parent_Type)
8602 and then not Is_Limited_Interface (Iface_Id)
8605 ("progenitor& must be limited interface",
8606 Error_Node, Iface_Id);
8609 (Task_Present (Iface_Def)
8610 or else Protected_Present (Iface_Def)
8611 or else Synchronized_Present (Iface_Def))
8612 and then Nkind (N) /= N_Private_Extension_Declaration
8615 ("progenitor& must be limited interface",
8616 Error_Node, Iface_Id);
8619 -- Protected interfaces can only inherit from limited, synchronized
8620 -- or protected interfaces.
8622 elsif Nkind (N) = N_Full_Type_Declaration
8623 and then Protected_Present (Type_Def)
8625 if Limited_Present (Iface_Def)
8626 or else Synchronized_Present (Iface_Def)
8627 or else Protected_Present (Iface_Def)
8631 elsif Task_Present (Iface_Def) then
8632 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
8633 & " from task interface", Error_Node);
8636 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
8637 & " from non-limited interface", Error_Node);
8640 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
8641 -- limited and synchronized.
8643 elsif Synchronized_Present (Type_Def) then
8644 if Limited_Present (Iface_Def)
8645 or else Synchronized_Present (Iface_Def)
8649 elsif Protected_Present (Iface_Def)
8650 and then Nkind (N) /= N_Private_Extension_Declaration
8652 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8653 & " from protected interface", Error_Node);
8655 elsif Task_Present (Iface_Def)
8656 and then Nkind (N) /= N_Private_Extension_Declaration
8658 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8659 & " from task interface", Error_Node);
8661 elsif not Is_Limited_Interface (Iface_Id) then
8662 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8663 & " from non-limited interface", Error_Node);
8666 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
8667 -- synchronized or task interfaces.
8669 elsif Nkind (N) = N_Full_Type_Declaration
8670 and then Task_Present (Type_Def)
8672 if Limited_Present (Iface_Def)
8673 or else Synchronized_Present (Iface_Def)
8674 or else Task_Present (Iface_Def)
8678 elsif Protected_Present (Iface_Def) then
8679 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
8680 & " protected interface", Error_Node);
8683 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
8684 & " non-limited interface", Error_Node);
8689 -- Start of processing for Check_Interfaces
8692 if Is_Interface (Parent_Type) then
8693 if Is_Task_Interface (Parent_Type) then
8696 elsif Is_Protected_Interface (Parent_Type) then
8697 Is_Protected := True;
8701 if Nkind (N) = N_Private_Extension_Declaration then
8703 -- Check that progenitors are compatible with declaration
8705 Iface := First (Interface_List (Def));
8706 while Present (Iface) loop
8707 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8709 Parent_Node := Parent (Base_Type (Iface_Typ));
8710 Iface_Def := Type_Definition (Parent_Node);
8712 if not Is_Interface (Iface_Typ) then
8713 Diagnose_Interface (Iface, Iface_Typ);
8716 Check_Ifaces (Iface_Def, Iface);
8722 if Is_Task and Is_Protected then
8724 ("type cannot derive from task and protected interface", N);
8730 -- Full type declaration of derived type.
8731 -- Check compatibility with parent if it is interface type
8733 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition
8734 and then Is_Interface (Parent_Type)
8736 Parent_Node := Parent (Parent_Type);
8738 -- More detailed checks for interface varieties
8741 (Iface_Def => Type_Definition (Parent_Node),
8742 Error_Node => Subtype_Indication (Type_Definition (N)));
8745 Iface := First (Interface_List (Def));
8746 while Present (Iface) loop
8747 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8749 Parent_Node := Parent (Base_Type (Iface_Typ));
8750 Iface_Def := Type_Definition (Parent_Node);
8752 if not Is_Interface (Iface_Typ) then
8753 Diagnose_Interface (Iface, Iface_Typ);
8756 -- "The declaration of a specific descendant of an interface
8757 -- type freezes the interface type" RM 13.14
8759 Freeze_Before (N, Iface_Typ);
8760 Check_Ifaces (Iface_Def, Error_Node => Iface);
8766 if Is_Task and Is_Protected then
8768 ("type cannot derive from task and protected interface", N);
8770 end Check_Interfaces;
8772 ------------------------------------
8773 -- Check_Or_Process_Discriminants --
8774 ------------------------------------
8776 -- If an incomplete or private type declaration was already given for the
8777 -- type, the discriminants may have already been processed if they were
8778 -- present on the incomplete declaration. In this case a full conformance
8779 -- check is performed otherwise just process them.
8781 procedure Check_Or_Process_Discriminants
8784 Prev : Entity_Id := Empty)
8787 if Has_Discriminants (T) then
8789 -- Make the discriminants visible to component declarations
8796 D := First_Discriminant (T);
8797 while Present (D) loop
8798 Prev := Current_Entity (D);
8799 Set_Current_Entity (D);
8800 Set_Is_Immediately_Visible (D);
8801 Set_Homonym (D, Prev);
8803 -- Ada 2005 (AI-230): Access discriminant allowed in
8804 -- non-limited record types.
8806 if Ada_Version < Ada_05 then
8808 -- This restriction gets applied to the full type here. It
8809 -- has already been applied earlier to the partial view.
8811 Check_Access_Discriminant_Requires_Limited (Parent (D), N);
8814 Next_Discriminant (D);
8818 elsif Present (Discriminant_Specifications (N)) then
8819 Process_Discriminants (N, Prev);
8821 end Check_Or_Process_Discriminants;
8823 ----------------------
8824 -- Check_Real_Bound --
8825 ----------------------
8827 procedure Check_Real_Bound (Bound : Node_Id) is
8829 if not Is_Real_Type (Etype (Bound)) then
8831 ("bound in real type definition must be of real type", Bound);
8833 elsif not Is_OK_Static_Expression (Bound) then
8834 Flag_Non_Static_Expr
8835 ("non-static expression used for real type bound!", Bound);
8842 (Bound, Make_Real_Literal (Sloc (Bound), Ureal_0));
8844 Resolve (Bound, Standard_Float);
8845 end Check_Real_Bound;
8847 ------------------------------
8848 -- Complete_Private_Subtype --
8849 ------------------------------
8851 procedure Complete_Private_Subtype
8854 Full_Base : Entity_Id;
8855 Related_Nod : Node_Id)
8857 Save_Next_Entity : Entity_Id;
8858 Save_Homonym : Entity_Id;
8861 -- Set semantic attributes for (implicit) private subtype completion.
8862 -- If the full type has no discriminants, then it is a copy of the full
8863 -- view of the base. Otherwise, it is a subtype of the base with a
8864 -- possible discriminant constraint. Save and restore the original
8865 -- Next_Entity field of full to ensure that the calls to Copy_Node
8866 -- do not corrupt the entity chain.
8868 -- Note that the type of the full view is the same entity as the type of
8869 -- the partial view. In this fashion, the subtype has access to the
8870 -- correct view of the parent.
8872 Save_Next_Entity := Next_Entity (Full);
8873 Save_Homonym := Homonym (Priv);
8875 case Ekind (Full_Base) is
8876 when E_Record_Type |
8882 Copy_Node (Priv, Full);
8884 Set_Has_Discriminants (Full, Has_Discriminants (Full_Base));
8885 Set_First_Entity (Full, First_Entity (Full_Base));
8886 Set_Last_Entity (Full, Last_Entity (Full_Base));
8889 Copy_Node (Full_Base, Full);
8890 Set_Chars (Full, Chars (Priv));
8891 Conditional_Delay (Full, Priv);
8892 Set_Sloc (Full, Sloc (Priv));
8895 Set_Next_Entity (Full, Save_Next_Entity);
8896 Set_Homonym (Full, Save_Homonym);
8897 Set_Associated_Node_For_Itype (Full, Related_Nod);
8899 -- Set common attributes for all subtypes
8901 Set_Ekind (Full, Subtype_Kind (Ekind (Full_Base)));
8903 -- The Etype of the full view is inconsistent. Gigi needs to see the
8904 -- structural full view, which is what the current scheme gives:
8905 -- the Etype of the full view is the etype of the full base. However,
8906 -- if the full base is a derived type, the full view then looks like
8907 -- a subtype of the parent, not a subtype of the full base. If instead
8910 -- Set_Etype (Full, Full_Base);
8912 -- then we get inconsistencies in the front-end (confusion between
8913 -- views). Several outstanding bugs are related to this ???
8915 Set_Is_First_Subtype (Full, False);
8916 Set_Scope (Full, Scope (Priv));
8917 Set_Size_Info (Full, Full_Base);
8918 Set_RM_Size (Full, RM_Size (Full_Base));
8919 Set_Is_Itype (Full);
8921 -- A subtype of a private-type-without-discriminants, whose full-view
8922 -- has discriminants with default expressions, is not constrained!
8924 if not Has_Discriminants (Priv) then
8925 Set_Is_Constrained (Full, Is_Constrained (Full_Base));
8927 if Has_Discriminants (Full_Base) then
8928 Set_Discriminant_Constraint
8929 (Full, Discriminant_Constraint (Full_Base));
8931 -- The partial view may have been indefinite, the full view
8934 Set_Has_Unknown_Discriminants
8935 (Full, Has_Unknown_Discriminants (Full_Base));
8939 Set_First_Rep_Item (Full, First_Rep_Item (Full_Base));
8940 Set_Depends_On_Private (Full, Has_Private_Component (Full));
8942 -- Freeze the private subtype entity if its parent is delayed, and not
8943 -- already frozen. We skip this processing if the type is an anonymous
8944 -- subtype of a record component, or is the corresponding record of a
8945 -- protected type, since ???
8947 if not Is_Type (Scope (Full)) then
8948 Set_Has_Delayed_Freeze (Full,
8949 Has_Delayed_Freeze (Full_Base)
8950 and then (not Is_Frozen (Full_Base)));
8953 Set_Freeze_Node (Full, Empty);
8954 Set_Is_Frozen (Full, False);
8955 Set_Full_View (Priv, Full);
8957 if Has_Discriminants (Full) then
8958 Set_Stored_Constraint_From_Discriminant_Constraint (Full);
8959 Set_Stored_Constraint (Priv, Stored_Constraint (Full));
8961 if Has_Unknown_Discriminants (Full) then
8962 Set_Discriminant_Constraint (Full, No_Elist);
8966 if Ekind (Full_Base) = E_Record_Type
8967 and then Has_Discriminants (Full_Base)
8968 and then Has_Discriminants (Priv) -- might not, if errors
8969 and then not Has_Unknown_Discriminants (Priv)
8970 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Priv))
8972 Create_Constrained_Components
8973 (Full, Related_Nod, Full_Base, Discriminant_Constraint (Priv));
8975 -- If the full base is itself derived from private, build a congruent
8976 -- subtype of its underlying type, for use by the back end. For a
8977 -- constrained record component, the declaration cannot be placed on
8978 -- the component list, but it must nevertheless be built an analyzed, to
8979 -- supply enough information for Gigi to compute the size of component.
8981 elsif Ekind (Full_Base) in Private_Kind
8982 and then Is_Derived_Type (Full_Base)
8983 and then Has_Discriminants (Full_Base)
8984 and then (Ekind (Current_Scope) /= E_Record_Subtype)
8986 if not Is_Itype (Priv)
8988 Nkind (Subtype_Indication (Parent (Priv))) = N_Subtype_Indication
8990 Build_Underlying_Full_View
8991 (Parent (Priv), Full, Etype (Full_Base));
8993 elsif Nkind (Related_Nod) = N_Component_Declaration then
8994 Build_Underlying_Full_View (Related_Nod, Full, Etype (Full_Base));
8997 elsif Is_Record_Type (Full_Base) then
8999 -- Show Full is simply a renaming of Full_Base
9001 Set_Cloned_Subtype (Full, Full_Base);
9004 -- It is unsafe to share to bounds of a scalar type, because the Itype
9005 -- is elaborated on demand, and if a bound is non-static then different
9006 -- orders of elaboration in different units will lead to different
9007 -- external symbols.
9009 if Is_Scalar_Type (Full_Base) then
9010 Set_Scalar_Range (Full,
9011 Make_Range (Sloc (Related_Nod),
9013 Duplicate_Subexpr_No_Checks (Type_Low_Bound (Full_Base)),
9015 Duplicate_Subexpr_No_Checks (Type_High_Bound (Full_Base))));
9017 -- This completion inherits the bounds of the full parent, but if
9018 -- the parent is an unconstrained floating point type, so is the
9021 if Is_Floating_Point_Type (Full_Base) then
9022 Set_Includes_Infinities
9023 (Scalar_Range (Full), Has_Infinities (Full_Base));
9027 -- ??? It seems that a lot of fields are missing that should be copied
9028 -- from Full_Base to Full. Here are some that are introduced in a
9029 -- non-disruptive way but a cleanup is necessary.
9031 if Is_Tagged_Type (Full_Base) then
9032 Set_Is_Tagged_Type (Full);
9033 Set_Primitive_Operations (Full, Primitive_Operations (Full_Base));
9034 Set_Class_Wide_Type (Full, Class_Wide_Type (Full_Base));
9036 -- If this is a subtype of a protected or task type, constrain its
9037 -- corresponding record, unless this is a subtype without constraints,
9038 -- i.e. a simple renaming as with an actual subtype in an instance.
9040 elsif Is_Concurrent_Type (Full_Base) then
9041 if Has_Discriminants (Full)
9042 and then Present (Corresponding_Record_Type (Full_Base))
9044 not Is_Empty_Elmt_List (Discriminant_Constraint (Full))
9046 Set_Corresponding_Record_Type (Full,
9047 Constrain_Corresponding_Record
9048 (Full, Corresponding_Record_Type (Full_Base),
9049 Related_Nod, Full_Base));
9052 Set_Corresponding_Record_Type (Full,
9053 Corresponding_Record_Type (Full_Base));
9056 end Complete_Private_Subtype;
9058 ----------------------------
9059 -- Constant_Redeclaration --
9060 ----------------------------
9062 procedure Constant_Redeclaration
9067 Prev : constant Entity_Id := Current_Entity_In_Scope (Id);
9068 Obj_Def : constant Node_Id := Object_Definition (N);
9071 procedure Check_Possible_Deferred_Completion
9072 (Prev_Id : Entity_Id;
9073 Prev_Obj_Def : Node_Id;
9074 Curr_Obj_Def : Node_Id);
9075 -- Determine whether the two object definitions describe the partial
9076 -- and the full view of a constrained deferred constant. Generate
9077 -- a subtype for the full view and verify that it statically matches
9078 -- the subtype of the partial view.
9080 procedure Check_Recursive_Declaration (Typ : Entity_Id);
9081 -- If deferred constant is an access type initialized with an allocator,
9082 -- check whether there is an illegal recursion in the definition,
9083 -- through a default value of some record subcomponent. This is normally
9084 -- detected when generating init procs, but requires this additional
9085 -- mechanism when expansion is disabled.
9087 ----------------------------------------
9088 -- Check_Possible_Deferred_Completion --
9089 ----------------------------------------
9091 procedure Check_Possible_Deferred_Completion
9092 (Prev_Id : Entity_Id;
9093 Prev_Obj_Def : Node_Id;
9094 Curr_Obj_Def : Node_Id)
9097 if Nkind (Prev_Obj_Def) = N_Subtype_Indication
9098 and then Present (Constraint (Prev_Obj_Def))
9099 and then Nkind (Curr_Obj_Def) = N_Subtype_Indication
9100 and then Present (Constraint (Curr_Obj_Def))
9103 Loc : constant Source_Ptr := Sloc (N);
9104 Def_Id : constant Entity_Id :=
9105 Make_Defining_Identifier (Loc,
9106 New_Internal_Name ('S'));
9107 Decl : constant Node_Id :=
9108 Make_Subtype_Declaration (Loc,
9109 Defining_Identifier =>
9111 Subtype_Indication =>
9112 Relocate_Node (Curr_Obj_Def));
9115 Insert_Before_And_Analyze (N, Decl);
9116 Set_Etype (Id, Def_Id);
9118 if not Subtypes_Statically_Match (Etype (Prev_Id), Def_Id) then
9119 Error_Msg_Sloc := Sloc (Prev_Id);
9120 Error_Msg_N ("subtype does not statically match deferred " &
9125 end Check_Possible_Deferred_Completion;
9127 ---------------------------------
9128 -- Check_Recursive_Declaration --
9129 ---------------------------------
9131 procedure Check_Recursive_Declaration (Typ : Entity_Id) is
9135 if Is_Record_Type (Typ) then
9136 Comp := First_Component (Typ);
9137 while Present (Comp) loop
9138 if Comes_From_Source (Comp) then
9139 if Present (Expression (Parent (Comp)))
9140 and then Is_Entity_Name (Expression (Parent (Comp)))
9141 and then Entity (Expression (Parent (Comp))) = Prev
9143 Error_Msg_Sloc := Sloc (Parent (Comp));
9145 ("illegal circularity with declaration for&#",
9149 elsif Is_Record_Type (Etype (Comp)) then
9150 Check_Recursive_Declaration (Etype (Comp));
9154 Next_Component (Comp);
9157 end Check_Recursive_Declaration;
9159 -- Start of processing for Constant_Redeclaration
9162 if Nkind (Parent (Prev)) = N_Object_Declaration then
9163 if Nkind (Object_Definition
9164 (Parent (Prev))) = N_Subtype_Indication
9166 -- Find type of new declaration. The constraints of the two
9167 -- views must match statically, but there is no point in
9168 -- creating an itype for the full view.
9170 if Nkind (Obj_Def) = N_Subtype_Indication then
9171 Find_Type (Subtype_Mark (Obj_Def));
9172 New_T := Entity (Subtype_Mark (Obj_Def));
9175 Find_Type (Obj_Def);
9176 New_T := Entity (Obj_Def);
9182 -- The full view may impose a constraint, even if the partial
9183 -- view does not, so construct the subtype.
9185 New_T := Find_Type_Of_Object (Obj_Def, N);
9190 -- Current declaration is illegal, diagnosed below in Enter_Name
9196 -- If previous full declaration exists, or if a homograph is present,
9197 -- let Enter_Name handle it, either with an error, or with the removal
9198 -- of an overridden implicit subprogram.
9200 if Ekind (Prev) /= E_Constant
9201 or else Present (Expression (Parent (Prev)))
9202 or else Present (Full_View (Prev))
9206 -- Verify that types of both declarations match, or else that both types
9207 -- are anonymous access types whose designated subtypes statically match
9208 -- (as allowed in Ada 2005 by AI-385).
9210 elsif Base_Type (Etype (Prev)) /= Base_Type (New_T)
9212 (Ekind (Etype (Prev)) /= E_Anonymous_Access_Type
9213 or else Ekind (Etype (New_T)) /= E_Anonymous_Access_Type
9214 or else Is_Access_Constant (Etype (New_T)) /=
9215 Is_Access_Constant (Etype (Prev))
9216 or else Can_Never_Be_Null (Etype (New_T)) /=
9217 Can_Never_Be_Null (Etype (Prev))
9218 or else Null_Exclusion_Present (Parent (Prev)) /=
9219 Null_Exclusion_Present (Parent (Id))
9220 or else not Subtypes_Statically_Match
9221 (Designated_Type (Etype (Prev)),
9222 Designated_Type (Etype (New_T))))
9224 Error_Msg_Sloc := Sloc (Prev);
9225 Error_Msg_N ("type does not match declaration#", N);
9226 Set_Full_View (Prev, Id);
9227 Set_Etype (Id, Any_Type);
9230 Null_Exclusion_Present (Parent (Prev))
9231 and then not Null_Exclusion_Present (N)
9233 Error_Msg_Sloc := Sloc (Prev);
9234 Error_Msg_N ("null-exclusion does not match declaration#", N);
9235 Set_Full_View (Prev, Id);
9236 Set_Etype (Id, Any_Type);
9238 -- If so, process the full constant declaration
9241 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
9242 -- the deferred declaration is constrained, then the subtype defined
9243 -- by the subtype_indication in the full declaration shall match it
9246 Check_Possible_Deferred_Completion
9248 Prev_Obj_Def => Object_Definition (Parent (Prev)),
9249 Curr_Obj_Def => Obj_Def);
9251 Set_Full_View (Prev, Id);
9252 Set_Is_Public (Id, Is_Public (Prev));
9253 Set_Is_Internal (Id);
9254 Append_Entity (Id, Current_Scope);
9256 -- Check ALIASED present if present before (RM 7.4(7))
9258 if Is_Aliased (Prev)
9259 and then not Aliased_Present (N)
9261 Error_Msg_Sloc := Sloc (Prev);
9262 Error_Msg_N ("ALIASED required (see declaration#)", N);
9265 -- Allow incomplete declaration of tags (used to handle forward
9266 -- references to tags). The check on Ada_Tags avoids circularities
9267 -- when rebuilding the compiler.
9269 if RTU_Loaded (Ada_Tags)
9270 and then T = RTE (RE_Tag)
9274 -- Check that placement is in private part and that the incomplete
9275 -- declaration appeared in the visible part.
9277 elsif Ekind (Current_Scope) = E_Package
9278 and then not In_Private_Part (Current_Scope)
9280 Error_Msg_Sloc := Sloc (Prev);
9281 Error_Msg_N ("full constant for declaration#"
9282 & " must be in private part", N);
9284 elsif Ekind (Current_Scope) = E_Package
9285 and then List_Containing (Parent (Prev))
9286 /= Visible_Declarations
9287 (Specification (Unit_Declaration_Node (Current_Scope)))
9290 ("deferred constant must be declared in visible part",
9294 if Is_Access_Type (T)
9295 and then Nkind (Expression (N)) = N_Allocator
9297 Check_Recursive_Declaration (Designated_Type (T));
9300 end Constant_Redeclaration;
9302 ----------------------
9303 -- Constrain_Access --
9304 ----------------------
9306 procedure Constrain_Access
9307 (Def_Id : in out Entity_Id;
9309 Related_Nod : Node_Id)
9311 T : constant Entity_Id := Entity (Subtype_Mark (S));
9312 Desig_Type : constant Entity_Id := Designated_Type (T);
9313 Desig_Subtype : Entity_Id := Create_Itype (E_Void, Related_Nod);
9314 Constraint_OK : Boolean := True;
9316 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean;
9317 -- Simple predicate to test for defaulted discriminants
9318 -- Shouldn't this be in sem_util???
9320 ---------------------------------
9321 -- Has_Defaulted_Discriminants --
9322 ---------------------------------
9324 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
9326 return Has_Discriminants (Typ)
9327 and then Present (First_Discriminant (Typ))
9329 (Discriminant_Default_Value (First_Discriminant (Typ)));
9330 end Has_Defaulted_Discriminants;
9332 -- Start of processing for Constrain_Access
9335 if Is_Array_Type (Desig_Type) then
9336 Constrain_Array (Desig_Subtype, S, Related_Nod, Def_Id, 'P');
9338 elsif (Is_Record_Type (Desig_Type)
9339 or else Is_Incomplete_Or_Private_Type (Desig_Type))
9340 and then not Is_Constrained (Desig_Type)
9342 -- ??? The following code is a temporary kludge to ignore a
9343 -- discriminant constraint on access type if it is constraining
9344 -- the current record. Avoid creating the implicit subtype of the
9345 -- record we are currently compiling since right now, we cannot
9346 -- handle these. For now, just return the access type itself.
9348 if Desig_Type = Current_Scope
9349 and then No (Def_Id)
9351 Set_Ekind (Desig_Subtype, E_Record_Subtype);
9352 Def_Id := Entity (Subtype_Mark (S));
9354 -- This call added to ensure that the constraint is analyzed
9355 -- (needed for a B test). Note that we still return early from
9356 -- this procedure to avoid recursive processing. ???
9358 Constrain_Discriminated_Type
9359 (Desig_Subtype, S, Related_Nod, For_Access => True);
9363 if (Ekind (T) = E_General_Access_Type
9364 or else Ada_Version >= Ada_05)
9365 and then Has_Private_Declaration (Desig_Type)
9366 and then In_Open_Scopes (Scope (Desig_Type))
9367 and then Has_Discriminants (Desig_Type)
9369 -- Enforce rule that the constraint is illegal if there is
9370 -- an unconstrained view of the designated type. This means
9371 -- that the partial view (either a private type declaration or
9372 -- a derivation from a private type) has no discriminants.
9373 -- (Defect Report 8652/0008, Technical Corrigendum 1, checked
9374 -- by ACATS B371001).
9376 -- Rule updated for Ada 2005: the private type is said to have
9377 -- a constrained partial view, given that objects of the type
9378 -- can be declared. Furthermore, the rule applies to all access
9379 -- types, unlike the rule concerning default discriminants.
9382 Pack : constant Node_Id :=
9383 Unit_Declaration_Node (Scope (Desig_Type));
9388 if Nkind (Pack) = N_Package_Declaration then
9389 Decls := Visible_Declarations (Specification (Pack));
9390 Decl := First (Decls);
9391 while Present (Decl) loop
9392 if (Nkind (Decl) = N_Private_Type_Declaration
9394 Chars (Defining_Identifier (Decl)) =
9398 (Nkind (Decl) = N_Full_Type_Declaration
9400 Chars (Defining_Identifier (Decl)) =
9402 and then Is_Derived_Type (Desig_Type)
9404 Has_Private_Declaration (Etype (Desig_Type)))
9406 if No (Discriminant_Specifications (Decl)) then
9408 ("cannot constrain general access type if " &
9409 "designated type has constrained partial view",
9422 Constrain_Discriminated_Type (Desig_Subtype, S, Related_Nod,
9423 For_Access => True);
9425 elsif (Is_Task_Type (Desig_Type)
9426 or else Is_Protected_Type (Desig_Type))
9427 and then not Is_Constrained (Desig_Type)
9429 Constrain_Concurrent
9430 (Desig_Subtype, S, Related_Nod, Desig_Type, ' ');
9433 Error_Msg_N ("invalid constraint on access type", S);
9434 Desig_Subtype := Desig_Type; -- Ignore invalid constraint.
9435 Constraint_OK := False;
9439 Def_Id := Create_Itype (E_Access_Subtype, Related_Nod);
9441 Set_Ekind (Def_Id, E_Access_Subtype);
9444 if Constraint_OK then
9445 Set_Etype (Def_Id, Base_Type (T));
9447 if Is_Private_Type (Desig_Type) then
9448 Prepare_Private_Subtype_Completion (Desig_Subtype, Related_Nod);
9451 Set_Etype (Def_Id, Any_Type);
9454 Set_Size_Info (Def_Id, T);
9455 Set_Is_Constrained (Def_Id, Constraint_OK);
9456 Set_Directly_Designated_Type (Def_Id, Desig_Subtype);
9457 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9458 Set_Is_Access_Constant (Def_Id, Is_Access_Constant (T));
9460 Conditional_Delay (Def_Id, T);
9462 -- AI-363 : Subtypes of general access types whose designated types have
9463 -- default discriminants are disallowed. In instances, the rule has to
9464 -- be checked against the actual, of which T is the subtype. In a
9465 -- generic body, the rule is checked assuming that the actual type has
9466 -- defaulted discriminants.
9468 if Ada_Version >= Ada_05 or else Warn_On_Ada_2005_Compatibility then
9469 if Ekind (Base_Type (T)) = E_General_Access_Type
9470 and then Has_Defaulted_Discriminants (Desig_Type)
9472 if Ada_Version < Ada_05 then
9474 ("access subtype of general access type would not " &
9475 "be allowed in Ada 2005?", S);
9478 ("access subype of general access type not allowed", S);
9481 Error_Msg_N ("\discriminants have defaults", S);
9483 elsif Is_Access_Type (T)
9484 and then Is_Generic_Type (Desig_Type)
9485 and then Has_Discriminants (Desig_Type)
9486 and then In_Package_Body (Current_Scope)
9488 if Ada_Version < Ada_05 then
9490 ("access subtype would not be allowed in generic body " &
9494 ("access subtype not allowed in generic body", S);
9498 ("\designated type is a discriminated formal", S);
9501 end Constrain_Access;
9503 ---------------------
9504 -- Constrain_Array --
9505 ---------------------
9507 procedure Constrain_Array
9508 (Def_Id : in out Entity_Id;
9510 Related_Nod : Node_Id;
9511 Related_Id : Entity_Id;
9514 C : constant Node_Id := Constraint (SI);
9515 Number_Of_Constraints : Nat := 0;
9518 Constraint_OK : Boolean := True;
9521 T := Entity (Subtype_Mark (SI));
9523 if Ekind (T) in Access_Kind then
9524 T := Designated_Type (T);
9527 -- If an index constraint follows a subtype mark in a subtype indication
9528 -- then the type or subtype denoted by the subtype mark must not already
9529 -- impose an index constraint. The subtype mark must denote either an
9530 -- unconstrained array type or an access type whose designated type
9531 -- is such an array type... (RM 3.6.1)
9533 if Is_Constrained (T) then
9535 ("array type is already constrained", Subtype_Mark (SI));
9536 Constraint_OK := False;
9539 S := First (Constraints (C));
9540 while Present (S) loop
9541 Number_Of_Constraints := Number_Of_Constraints + 1;
9545 -- In either case, the index constraint must provide a discrete
9546 -- range for each index of the array type and the type of each
9547 -- discrete range must be the same as that of the corresponding
9548 -- index. (RM 3.6.1)
9550 if Number_Of_Constraints /= Number_Dimensions (T) then
9551 Error_Msg_NE ("incorrect number of index constraints for }", C, T);
9552 Constraint_OK := False;
9555 S := First (Constraints (C));
9556 Index := First_Index (T);
9559 -- Apply constraints to each index type
9561 for J in 1 .. Number_Of_Constraints loop
9562 Constrain_Index (Index, S, Related_Nod, Related_Id, Suffix, J);
9572 Create_Itype (E_Array_Subtype, Related_Nod, Related_Id, Suffix);
9573 Set_Parent (Def_Id, Related_Nod);
9576 Set_Ekind (Def_Id, E_Array_Subtype);
9579 Set_Size_Info (Def_Id, (T));
9580 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
9581 Set_Etype (Def_Id, Base_Type (T));
9583 if Constraint_OK then
9584 Set_First_Index (Def_Id, First (Constraints (C)));
9586 Set_First_Index (Def_Id, First_Index (T));
9589 Set_Is_Constrained (Def_Id, True);
9590 Set_Is_Aliased (Def_Id, Is_Aliased (T));
9591 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9593 Set_Is_Private_Composite (Def_Id, Is_Private_Composite (T));
9594 Set_Is_Limited_Composite (Def_Id, Is_Limited_Composite (T));
9596 -- A subtype does not inherit the packed_array_type of is parent. We
9597 -- need to initialize the attribute because if Def_Id is previously
9598 -- analyzed through a limited_with clause, it will have the attributes
9599 -- of an incomplete type, one of which is an Elist that overlaps the
9600 -- Packed_Array_Type field.
9602 Set_Packed_Array_Type (Def_Id, Empty);
9604 -- Build a freeze node if parent still needs one. Also make sure that
9605 -- the Depends_On_Private status is set because the subtype will need
9606 -- reprocessing at the time the base type does, and also we must set a
9607 -- conditional delay.
9609 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
9610 Conditional_Delay (Def_Id, T);
9611 end Constrain_Array;
9613 ------------------------------
9614 -- Constrain_Component_Type --
9615 ------------------------------
9617 function Constrain_Component_Type
9619 Constrained_Typ : Entity_Id;
9620 Related_Node : Node_Id;
9622 Constraints : Elist_Id) return Entity_Id
9624 Loc : constant Source_Ptr := Sloc (Constrained_Typ);
9625 Compon_Type : constant Entity_Id := Etype (Comp);
9627 function Build_Constrained_Array_Type
9628 (Old_Type : Entity_Id) return Entity_Id;
9629 -- If Old_Type is an array type, one of whose indices is constrained
9630 -- by a discriminant, build an Itype whose constraint replaces the
9631 -- discriminant with its value in the constraint.
9633 function Build_Constrained_Discriminated_Type
9634 (Old_Type : Entity_Id) return Entity_Id;
9635 -- Ditto for record components
9637 function Build_Constrained_Access_Type
9638 (Old_Type : Entity_Id) return Entity_Id;
9639 -- Ditto for access types. Makes use of previous two functions, to
9640 -- constrain designated type.
9642 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id;
9643 -- T is an array or discriminated type, C is a list of constraints
9644 -- that apply to T. This routine builds the constrained subtype.
9646 function Is_Discriminant (Expr : Node_Id) return Boolean;
9647 -- Returns True if Expr is a discriminant
9649 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id;
9650 -- Find the value of discriminant Discrim in Constraint
9652 -----------------------------------
9653 -- Build_Constrained_Access_Type --
9654 -----------------------------------
9656 function Build_Constrained_Access_Type
9657 (Old_Type : Entity_Id) return Entity_Id
9659 Desig_Type : constant Entity_Id := Designated_Type (Old_Type);
9661 Desig_Subtype : Entity_Id;
9665 -- if the original access type was not embedded in the enclosing
9666 -- type definition, there is no need to produce a new access
9667 -- subtype. In fact every access type with an explicit constraint
9668 -- generates an itype whose scope is the enclosing record.
9670 if not Is_Type (Scope (Old_Type)) then
9673 elsif Is_Array_Type (Desig_Type) then
9674 Desig_Subtype := Build_Constrained_Array_Type (Desig_Type);
9676 elsif Has_Discriminants (Desig_Type) then
9678 -- This may be an access type to an enclosing record type for
9679 -- which we are constructing the constrained components. Return
9680 -- the enclosing record subtype. This is not always correct,
9681 -- but avoids infinite recursion. ???
9683 Desig_Subtype := Any_Type;
9685 for J in reverse 0 .. Scope_Stack.Last loop
9686 Scop := Scope_Stack.Table (J).Entity;
9689 and then Base_Type (Scop) = Base_Type (Desig_Type)
9691 Desig_Subtype := Scop;
9694 exit when not Is_Type (Scop);
9697 if Desig_Subtype = Any_Type then
9699 Build_Constrained_Discriminated_Type (Desig_Type);
9706 if Desig_Subtype /= Desig_Type then
9708 -- The Related_Node better be here or else we won't be able
9709 -- to attach new itypes to a node in the tree.
9711 pragma Assert (Present (Related_Node));
9713 Itype := Create_Itype (E_Access_Subtype, Related_Node);
9715 Set_Etype (Itype, Base_Type (Old_Type));
9716 Set_Size_Info (Itype, (Old_Type));
9717 Set_Directly_Designated_Type (Itype, Desig_Subtype);
9718 Set_Depends_On_Private (Itype, Has_Private_Component
9720 Set_Is_Access_Constant (Itype, Is_Access_Constant
9723 -- The new itype needs freezing when it depends on a not frozen
9724 -- type and the enclosing subtype needs freezing.
9726 if Has_Delayed_Freeze (Constrained_Typ)
9727 and then not Is_Frozen (Constrained_Typ)
9729 Conditional_Delay (Itype, Base_Type (Old_Type));
9737 end Build_Constrained_Access_Type;
9739 ----------------------------------
9740 -- Build_Constrained_Array_Type --
9741 ----------------------------------
9743 function Build_Constrained_Array_Type
9744 (Old_Type : Entity_Id) return Entity_Id
9748 Old_Index : Node_Id;
9749 Range_Node : Node_Id;
9750 Constr_List : List_Id;
9752 Need_To_Create_Itype : Boolean := False;
9755 Old_Index := First_Index (Old_Type);
9756 while Present (Old_Index) loop
9757 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9759 if Is_Discriminant (Lo_Expr)
9760 or else Is_Discriminant (Hi_Expr)
9762 Need_To_Create_Itype := True;
9765 Next_Index (Old_Index);
9768 if Need_To_Create_Itype then
9769 Constr_List := New_List;
9771 Old_Index := First_Index (Old_Type);
9772 while Present (Old_Index) loop
9773 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9775 if Is_Discriminant (Lo_Expr) then
9776 Lo_Expr := Get_Discr_Value (Lo_Expr);
9779 if Is_Discriminant (Hi_Expr) then
9780 Hi_Expr := Get_Discr_Value (Hi_Expr);
9785 (Loc, New_Copy_Tree (Lo_Expr), New_Copy_Tree (Hi_Expr));
9787 Append (Range_Node, To => Constr_List);
9789 Next_Index (Old_Index);
9792 return Build_Subtype (Old_Type, Constr_List);
9797 end Build_Constrained_Array_Type;
9799 ------------------------------------------
9800 -- Build_Constrained_Discriminated_Type --
9801 ------------------------------------------
9803 function Build_Constrained_Discriminated_Type
9804 (Old_Type : Entity_Id) return Entity_Id
9807 Constr_List : List_Id;
9808 Old_Constraint : Elmt_Id;
9810 Need_To_Create_Itype : Boolean := False;
9813 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9814 while Present (Old_Constraint) loop
9815 Expr := Node (Old_Constraint);
9817 if Is_Discriminant (Expr) then
9818 Need_To_Create_Itype := True;
9821 Next_Elmt (Old_Constraint);
9824 if Need_To_Create_Itype then
9825 Constr_List := New_List;
9827 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9828 while Present (Old_Constraint) loop
9829 Expr := Node (Old_Constraint);
9831 if Is_Discriminant (Expr) then
9832 Expr := Get_Discr_Value (Expr);
9835 Append (New_Copy_Tree (Expr), To => Constr_List);
9837 Next_Elmt (Old_Constraint);
9840 return Build_Subtype (Old_Type, Constr_List);
9845 end Build_Constrained_Discriminated_Type;
9851 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id is
9853 Subtyp_Decl : Node_Id;
9855 Btyp : Entity_Id := Base_Type (T);
9858 -- The Related_Node better be here or else we won't be able to
9859 -- attach new itypes to a node in the tree.
9861 pragma Assert (Present (Related_Node));
9863 -- If the view of the component's type is incomplete or private
9864 -- with unknown discriminants, then the constraint must be applied
9865 -- to the full type.
9867 if Has_Unknown_Discriminants (Btyp)
9868 and then Present (Underlying_Type (Btyp))
9870 Btyp := Underlying_Type (Btyp);
9874 Make_Subtype_Indication (Loc,
9875 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
9876 Constraint => Make_Index_Or_Discriminant_Constraint (Loc, C));
9878 Def_Id := Create_Itype (Ekind (T), Related_Node);
9881 Make_Subtype_Declaration (Loc,
9882 Defining_Identifier => Def_Id,
9883 Subtype_Indication => Indic);
9885 Set_Parent (Subtyp_Decl, Parent (Related_Node));
9887 -- Itypes must be analyzed with checks off (see package Itypes)
9889 Analyze (Subtyp_Decl, Suppress => All_Checks);
9894 ---------------------
9895 -- Get_Discr_Value --
9896 ---------------------
9898 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id is
9903 -- The discriminant may be declared for the type, in which case we
9904 -- find it by iterating over the list of discriminants. If the
9905 -- discriminant is inherited from a parent type, it appears as the
9906 -- corresponding discriminant of the current type. This will be the
9907 -- case when constraining an inherited component whose constraint is
9908 -- given by a discriminant of the parent.
9910 D := First_Discriminant (Typ);
9911 E := First_Elmt (Constraints);
9913 while Present (D) loop
9914 if D = Entity (Discrim)
9915 or else D = CR_Discriminant (Entity (Discrim))
9916 or else Corresponding_Discriminant (D) = Entity (Discrim)
9921 Next_Discriminant (D);
9925 -- The corresponding_Discriminant mechanism is incomplete, because
9926 -- the correspondence between new and old discriminants is not one
9927 -- to one: one new discriminant can constrain several old ones. In
9928 -- that case, scan sequentially the stored_constraint, the list of
9929 -- discriminants of the parents, and the constraints.
9930 -- Previous code checked for the present of the Stored_Constraint
9931 -- list for the derived type, but did not use it at all. Should it
9932 -- be present when the component is a discriminated task type?
9934 if Is_Derived_Type (Typ)
9935 and then Scope (Entity (Discrim)) = Etype (Typ)
9937 D := First_Discriminant (Etype (Typ));
9938 E := First_Elmt (Constraints);
9939 while Present (D) loop
9940 if D = Entity (Discrim) then
9944 Next_Discriminant (D);
9949 -- Something is wrong if we did not find the value
9951 raise Program_Error;
9952 end Get_Discr_Value;
9954 ---------------------
9955 -- Is_Discriminant --
9956 ---------------------
9958 function Is_Discriminant (Expr : Node_Id) return Boolean is
9959 Discrim_Scope : Entity_Id;
9962 if Denotes_Discriminant (Expr) then
9963 Discrim_Scope := Scope (Entity (Expr));
9965 -- Either we have a reference to one of Typ's discriminants,
9967 pragma Assert (Discrim_Scope = Typ
9969 -- or to the discriminants of the parent type, in the case
9970 -- of a derivation of a tagged type with variants.
9972 or else Discrim_Scope = Etype (Typ)
9973 or else Full_View (Discrim_Scope) = Etype (Typ)
9975 -- or same as above for the case where the discriminants
9976 -- were declared in Typ's private view.
9978 or else (Is_Private_Type (Discrim_Scope)
9979 and then Chars (Discrim_Scope) = Chars (Typ))
9981 -- or else we are deriving from the full view and the
9982 -- discriminant is declared in the private entity.
9984 or else (Is_Private_Type (Typ)
9985 and then Chars (Discrim_Scope) = Chars (Typ))
9987 -- Or we are constrained the corresponding record of a
9988 -- synchronized type that completes a private declaration.
9990 or else (Is_Concurrent_Record_Type (Typ)
9992 Corresponding_Concurrent_Type (Typ) = Discrim_Scope)
9994 -- or we have a class-wide type, in which case make sure the
9995 -- discriminant found belongs to the root type.
9997 or else (Is_Class_Wide_Type (Typ)
9998 and then Etype (Typ) = Discrim_Scope));
10003 -- In all other cases we have something wrong
10006 end Is_Discriminant;
10008 -- Start of processing for Constrain_Component_Type
10011 if Nkind (Parent (Comp)) = N_Component_Declaration
10012 and then Comes_From_Source (Parent (Comp))
10013 and then Comes_From_Source
10014 (Subtype_Indication (Component_Definition (Parent (Comp))))
10017 (Subtype_Indication (Component_Definition (Parent (Comp))))
10019 return Compon_Type;
10021 elsif Is_Array_Type (Compon_Type) then
10022 return Build_Constrained_Array_Type (Compon_Type);
10024 elsif Has_Discriminants (Compon_Type) then
10025 return Build_Constrained_Discriminated_Type (Compon_Type);
10027 elsif Is_Access_Type (Compon_Type) then
10028 return Build_Constrained_Access_Type (Compon_Type);
10031 return Compon_Type;
10033 end Constrain_Component_Type;
10035 --------------------------
10036 -- Constrain_Concurrent --
10037 --------------------------
10039 -- For concurrent types, the associated record value type carries the same
10040 -- discriminants, so when we constrain a concurrent type, we must constrain
10041 -- the corresponding record type as well.
10043 procedure Constrain_Concurrent
10044 (Def_Id : in out Entity_Id;
10046 Related_Nod : Node_Id;
10047 Related_Id : Entity_Id;
10048 Suffix : Character)
10050 T_Ent : Entity_Id := Entity (Subtype_Mark (SI));
10054 if Ekind (T_Ent) in Access_Kind then
10055 T_Ent := Designated_Type (T_Ent);
10058 T_Val := Corresponding_Record_Type (T_Ent);
10060 if Present (T_Val) then
10062 if No (Def_Id) then
10063 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
10066 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
10068 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
10069 Set_Corresponding_Record_Type (Def_Id,
10070 Constrain_Corresponding_Record
10071 (Def_Id, T_Val, Related_Nod, Related_Id));
10074 -- If there is no associated record, expansion is disabled and this
10075 -- is a generic context. Create a subtype in any case, so that
10076 -- semantic analysis can proceed.
10078 if No (Def_Id) then
10079 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
10082 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
10084 end Constrain_Concurrent;
10086 ------------------------------------
10087 -- Constrain_Corresponding_Record --
10088 ------------------------------------
10090 function Constrain_Corresponding_Record
10091 (Prot_Subt : Entity_Id;
10092 Corr_Rec : Entity_Id;
10093 Related_Nod : Node_Id;
10094 Related_Id : Entity_Id) return Entity_Id
10096 T_Sub : constant Entity_Id :=
10097 Create_Itype (E_Record_Subtype, Related_Nod, Related_Id, 'V');
10100 Set_Etype (T_Sub, Corr_Rec);
10101 Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt));
10102 Set_Is_Constrained (T_Sub, True);
10103 Set_First_Entity (T_Sub, First_Entity (Corr_Rec));
10104 Set_Last_Entity (T_Sub, Last_Entity (Corr_Rec));
10106 -- As elsewhere, we do not want to create a freeze node for this itype
10107 -- if it is created for a constrained component of an enclosing record
10108 -- because references to outer discriminants will appear out of scope.
10110 if Ekind (Scope (Prot_Subt)) /= E_Record_Type then
10111 Conditional_Delay (T_Sub, Corr_Rec);
10113 Set_Is_Frozen (T_Sub);
10116 if Has_Discriminants (Prot_Subt) then -- False only if errors.
10117 Set_Discriminant_Constraint
10118 (T_Sub, Discriminant_Constraint (Prot_Subt));
10119 Set_Stored_Constraint_From_Discriminant_Constraint (T_Sub);
10120 Create_Constrained_Components
10121 (T_Sub, Related_Nod, Corr_Rec, Discriminant_Constraint (T_Sub));
10124 Set_Depends_On_Private (T_Sub, Has_Private_Component (T_Sub));
10127 end Constrain_Corresponding_Record;
10129 -----------------------
10130 -- Constrain_Decimal --
10131 -----------------------
10133 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id) is
10134 T : constant Entity_Id := Entity (Subtype_Mark (S));
10135 C : constant Node_Id := Constraint (S);
10136 Loc : constant Source_Ptr := Sloc (C);
10137 Range_Expr : Node_Id;
10138 Digits_Expr : Node_Id;
10143 Set_Ekind (Def_Id, E_Decimal_Fixed_Point_Subtype);
10145 if Nkind (C) = N_Range_Constraint then
10146 Range_Expr := Range_Expression (C);
10147 Digits_Val := Digits_Value (T);
10150 pragma Assert (Nkind (C) = N_Digits_Constraint);
10151 Digits_Expr := Digits_Expression (C);
10152 Analyze_And_Resolve (Digits_Expr, Any_Integer);
10154 Check_Digits_Expression (Digits_Expr);
10155 Digits_Val := Expr_Value (Digits_Expr);
10157 if Digits_Val > Digits_Value (T) then
10159 ("digits expression is incompatible with subtype", C);
10160 Digits_Val := Digits_Value (T);
10163 if Present (Range_Constraint (C)) then
10164 Range_Expr := Range_Expression (Range_Constraint (C));
10166 Range_Expr := Empty;
10170 Set_Etype (Def_Id, Base_Type (T));
10171 Set_Size_Info (Def_Id, (T));
10172 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10173 Set_Delta_Value (Def_Id, Delta_Value (T));
10174 Set_Scale_Value (Def_Id, Scale_Value (T));
10175 Set_Small_Value (Def_Id, Small_Value (T));
10176 Set_Machine_Radix_10 (Def_Id, Machine_Radix_10 (T));
10177 Set_Digits_Value (Def_Id, Digits_Val);
10179 -- Manufacture range from given digits value if no range present
10181 if No (Range_Expr) then
10182 Bound_Val := (Ureal_10 ** Digits_Val - Ureal_1) * Small_Value (T);
10186 Convert_To (T, Make_Real_Literal (Loc, (-Bound_Val))),
10188 Convert_To (T, Make_Real_Literal (Loc, Bound_Val)));
10191 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expr, T);
10192 Set_Discrete_RM_Size (Def_Id);
10194 -- Unconditionally delay the freeze, since we cannot set size
10195 -- information in all cases correctly until the freeze point.
10197 Set_Has_Delayed_Freeze (Def_Id);
10198 end Constrain_Decimal;
10200 ----------------------------------
10201 -- Constrain_Discriminated_Type --
10202 ----------------------------------
10204 procedure Constrain_Discriminated_Type
10205 (Def_Id : Entity_Id;
10207 Related_Nod : Node_Id;
10208 For_Access : Boolean := False)
10210 E : constant Entity_Id := Entity (Subtype_Mark (S));
10213 Elist : Elist_Id := New_Elmt_List;
10215 procedure Fixup_Bad_Constraint;
10216 -- This is called after finding a bad constraint, and after having
10217 -- posted an appropriate error message. The mission is to leave the
10218 -- entity T in as reasonable state as possible!
10220 --------------------------
10221 -- Fixup_Bad_Constraint --
10222 --------------------------
10224 procedure Fixup_Bad_Constraint is
10226 -- Set a reasonable Ekind for the entity. For an incomplete type,
10227 -- we can't do much, but for other types, we can set the proper
10228 -- corresponding subtype kind.
10230 if Ekind (T) = E_Incomplete_Type then
10231 Set_Ekind (Def_Id, Ekind (T));
10233 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
10236 -- Set Etype to the known type, to reduce chances of cascaded errors
10238 Set_Etype (Def_Id, E);
10239 Set_Error_Posted (Def_Id);
10240 end Fixup_Bad_Constraint;
10242 -- Start of processing for Constrain_Discriminated_Type
10245 C := Constraint (S);
10247 -- A discriminant constraint is only allowed in a subtype indication,
10248 -- after a subtype mark. This subtype mark must denote either a type
10249 -- with discriminants, or an access type whose designated type is a
10250 -- type with discriminants. A discriminant constraint specifies the
10251 -- values of these discriminants (RM 3.7.2(5)).
10253 T := Base_Type (Entity (Subtype_Mark (S)));
10255 if Ekind (T) in Access_Kind then
10256 T := Designated_Type (T);
10259 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal.
10260 -- Avoid generating an error for access-to-incomplete subtypes.
10262 if Ada_Version >= Ada_05
10263 and then Ekind (T) = E_Incomplete_Type
10264 and then Nkind (Parent (S)) = N_Subtype_Declaration
10265 and then not Is_Itype (Def_Id)
10267 -- A little sanity check, emit an error message if the type
10268 -- has discriminants to begin with. Type T may be a regular
10269 -- incomplete type or imported via a limited with clause.
10271 if Has_Discriminants (T)
10273 (From_With_Type (T)
10274 and then Present (Non_Limited_View (T))
10275 and then Nkind (Parent (Non_Limited_View (T))) =
10276 N_Full_Type_Declaration
10277 and then Present (Discriminant_Specifications
10278 (Parent (Non_Limited_View (T)))))
10281 ("(Ada 2005) incomplete subtype may not be constrained", C);
10284 ("invalid constraint: type has no discriminant", C);
10287 Fixup_Bad_Constraint;
10290 -- Check that the type has visible discriminants. The type may be
10291 -- a private type with unknown discriminants whose full view has
10292 -- discriminants which are invisible.
10294 elsif not Has_Discriminants (T)
10296 (Has_Unknown_Discriminants (T)
10297 and then Is_Private_Type (T))
10299 Error_Msg_N ("invalid constraint: type has no discriminant", C);
10300 Fixup_Bad_Constraint;
10303 elsif Is_Constrained (E)
10304 or else (Ekind (E) = E_Class_Wide_Subtype
10305 and then Present (Discriminant_Constraint (E)))
10307 Error_Msg_N ("type is already constrained", Subtype_Mark (S));
10308 Fixup_Bad_Constraint;
10312 -- T may be an unconstrained subtype (e.g. a generic actual).
10313 -- Constraint applies to the base type.
10315 T := Base_Type (T);
10317 Elist := Build_Discriminant_Constraints (T, S);
10319 -- If the list returned was empty we had an error in building the
10320 -- discriminant constraint. We have also already signalled an error
10321 -- in the incomplete type case
10323 if Is_Empty_Elmt_List (Elist) then
10324 Fixup_Bad_Constraint;
10328 Build_Discriminated_Subtype (T, Def_Id, Elist, Related_Nod, For_Access);
10329 end Constrain_Discriminated_Type;
10331 ---------------------------
10332 -- Constrain_Enumeration --
10333 ---------------------------
10335 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id) is
10336 T : constant Entity_Id := Entity (Subtype_Mark (S));
10337 C : constant Node_Id := Constraint (S);
10340 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10342 Set_First_Literal (Def_Id, First_Literal (Base_Type (T)));
10344 Set_Etype (Def_Id, Base_Type (T));
10345 Set_Size_Info (Def_Id, (T));
10346 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10347 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10349 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10351 Set_Discrete_RM_Size (Def_Id);
10352 end Constrain_Enumeration;
10354 ----------------------
10355 -- Constrain_Float --
10356 ----------------------
10358 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id) is
10359 T : constant Entity_Id := Entity (Subtype_Mark (S));
10365 Set_Ekind (Def_Id, E_Floating_Point_Subtype);
10367 Set_Etype (Def_Id, Base_Type (T));
10368 Set_Size_Info (Def_Id, (T));
10369 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10371 -- Process the constraint
10373 C := Constraint (S);
10375 -- Digits constraint present
10377 if Nkind (C) = N_Digits_Constraint then
10378 Check_Restriction (No_Obsolescent_Features, C);
10380 if Warn_On_Obsolescent_Feature then
10382 ("subtype digits constraint is an " &
10383 "obsolescent feature (RM J.3(8))?", C);
10386 D := Digits_Expression (C);
10387 Analyze_And_Resolve (D, Any_Integer);
10388 Check_Digits_Expression (D);
10389 Set_Digits_Value (Def_Id, Expr_Value (D));
10391 -- Check that digits value is in range. Obviously we can do this
10392 -- at compile time, but it is strictly a runtime check, and of
10393 -- course there is an ACVC test that checks this!
10395 if Digits_Value (Def_Id) > Digits_Value (T) then
10396 Error_Msg_Uint_1 := Digits_Value (T);
10397 Error_Msg_N ("?digits value is too large, maximum is ^", D);
10399 Make_Raise_Constraint_Error (Sloc (D),
10400 Reason => CE_Range_Check_Failed);
10401 Insert_Action (Declaration_Node (Def_Id), Rais);
10404 C := Range_Constraint (C);
10406 -- No digits constraint present
10409 Set_Digits_Value (Def_Id, Digits_Value (T));
10412 -- Range constraint present
10414 if Nkind (C) = N_Range_Constraint then
10415 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10417 -- No range constraint present
10420 pragma Assert (No (C));
10421 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10424 Set_Is_Constrained (Def_Id);
10425 end Constrain_Float;
10427 ---------------------
10428 -- Constrain_Index --
10429 ---------------------
10431 procedure Constrain_Index
10434 Related_Nod : Node_Id;
10435 Related_Id : Entity_Id;
10436 Suffix : Character;
10437 Suffix_Index : Nat)
10439 Def_Id : Entity_Id;
10440 R : Node_Id := Empty;
10441 T : constant Entity_Id := Etype (Index);
10444 if Nkind (S) = N_Range
10446 (Nkind (S) = N_Attribute_Reference
10447 and then Attribute_Name (S) = Name_Range)
10449 -- A Range attribute will transformed into N_Range by Resolve
10455 Process_Range_Expr_In_Decl (R, T, Empty_List);
10457 if not Error_Posted (S)
10459 (Nkind (S) /= N_Range
10460 or else not Covers (T, (Etype (Low_Bound (S))))
10461 or else not Covers (T, (Etype (High_Bound (S)))))
10463 if Base_Type (T) /= Any_Type
10464 and then Etype (Low_Bound (S)) /= Any_Type
10465 and then Etype (High_Bound (S)) /= Any_Type
10467 Error_Msg_N ("range expected", S);
10471 elsif Nkind (S) = N_Subtype_Indication then
10473 -- The parser has verified that this is a discrete indication
10475 Resolve_Discrete_Subtype_Indication (S, T);
10476 R := Range_Expression (Constraint (S));
10478 elsif Nkind (S) = N_Discriminant_Association then
10480 -- Syntactically valid in subtype indication
10482 Error_Msg_N ("invalid index constraint", S);
10483 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10486 -- Subtype_Mark case, no anonymous subtypes to construct
10491 if Is_Entity_Name (S) then
10492 if not Is_Type (Entity (S)) then
10493 Error_Msg_N ("expect subtype mark for index constraint", S);
10495 elsif Base_Type (Entity (S)) /= Base_Type (T) then
10496 Wrong_Type (S, Base_Type (T));
10502 Error_Msg_N ("invalid index constraint", S);
10503 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10509 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index);
10511 Set_Etype (Def_Id, Base_Type (T));
10513 if Is_Modular_Integer_Type (T) then
10514 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10516 elsif Is_Integer_Type (T) then
10517 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10520 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10521 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10524 Set_Size_Info (Def_Id, (T));
10525 Set_RM_Size (Def_Id, RM_Size (T));
10526 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10528 Set_Scalar_Range (Def_Id, R);
10530 Set_Etype (S, Def_Id);
10531 Set_Discrete_RM_Size (Def_Id);
10532 end Constrain_Index;
10534 -----------------------
10535 -- Constrain_Integer --
10536 -----------------------
10538 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id) is
10539 T : constant Entity_Id := Entity (Subtype_Mark (S));
10540 C : constant Node_Id := Constraint (S);
10543 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10545 if Is_Modular_Integer_Type (T) then
10546 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10548 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10551 Set_Etype (Def_Id, Base_Type (T));
10552 Set_Size_Info (Def_Id, (T));
10553 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10554 Set_Discrete_RM_Size (Def_Id);
10555 end Constrain_Integer;
10557 ------------------------------
10558 -- Constrain_Ordinary_Fixed --
10559 ------------------------------
10561 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id) is
10562 T : constant Entity_Id := Entity (Subtype_Mark (S));
10568 Set_Ekind (Def_Id, E_Ordinary_Fixed_Point_Subtype);
10569 Set_Etype (Def_Id, Base_Type (T));
10570 Set_Size_Info (Def_Id, (T));
10571 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10572 Set_Small_Value (Def_Id, Small_Value (T));
10574 -- Process the constraint
10576 C := Constraint (S);
10578 -- Delta constraint present
10580 if Nkind (C) = N_Delta_Constraint then
10581 Check_Restriction (No_Obsolescent_Features, C);
10583 if Warn_On_Obsolescent_Feature then
10585 ("subtype delta constraint is an " &
10586 "obsolescent feature (RM J.3(7))?");
10589 D := Delta_Expression (C);
10590 Analyze_And_Resolve (D, Any_Real);
10591 Check_Delta_Expression (D);
10592 Set_Delta_Value (Def_Id, Expr_Value_R (D));
10594 -- Check that delta value is in range. Obviously we can do this
10595 -- at compile time, but it is strictly a runtime check, and of
10596 -- course there is an ACVC test that checks this!
10598 if Delta_Value (Def_Id) < Delta_Value (T) then
10599 Error_Msg_N ("?delta value is too small", D);
10601 Make_Raise_Constraint_Error (Sloc (D),
10602 Reason => CE_Range_Check_Failed);
10603 Insert_Action (Declaration_Node (Def_Id), Rais);
10606 C := Range_Constraint (C);
10608 -- No delta constraint present
10611 Set_Delta_Value (Def_Id, Delta_Value (T));
10614 -- Range constraint present
10616 if Nkind (C) = N_Range_Constraint then
10617 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10619 -- No range constraint present
10622 pragma Assert (No (C));
10623 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10627 Set_Discrete_RM_Size (Def_Id);
10629 -- Unconditionally delay the freeze, since we cannot set size
10630 -- information in all cases correctly until the freeze point.
10632 Set_Has_Delayed_Freeze (Def_Id);
10633 end Constrain_Ordinary_Fixed;
10635 -----------------------
10636 -- Contain_Interface --
10637 -----------------------
10639 function Contain_Interface
10640 (Iface : Entity_Id;
10641 Ifaces : Elist_Id) return Boolean
10643 Iface_Elmt : Elmt_Id;
10646 if Present (Ifaces) then
10647 Iface_Elmt := First_Elmt (Ifaces);
10648 while Present (Iface_Elmt) loop
10649 if Node (Iface_Elmt) = Iface then
10653 Next_Elmt (Iface_Elmt);
10658 end Contain_Interface;
10660 ---------------------------
10661 -- Convert_Scalar_Bounds --
10662 ---------------------------
10664 procedure Convert_Scalar_Bounds
10666 Parent_Type : Entity_Id;
10667 Derived_Type : Entity_Id;
10670 Implicit_Base : constant Entity_Id := Base_Type (Derived_Type);
10677 Lo := Build_Scalar_Bound
10678 (Type_Low_Bound (Derived_Type),
10679 Parent_Type, Implicit_Base);
10681 Hi := Build_Scalar_Bound
10682 (Type_High_Bound (Derived_Type),
10683 Parent_Type, Implicit_Base);
10690 Set_Includes_Infinities (Rng, Has_Infinities (Derived_Type));
10692 Set_Parent (Rng, N);
10693 Set_Scalar_Range (Derived_Type, Rng);
10695 -- Analyze the bounds
10697 Analyze_And_Resolve (Lo, Implicit_Base);
10698 Analyze_And_Resolve (Hi, Implicit_Base);
10700 -- Analyze the range itself, except that we do not analyze it if
10701 -- the bounds are real literals, and we have a fixed-point type.
10702 -- The reason for this is that we delay setting the bounds in this
10703 -- case till we know the final Small and Size values (see circuit
10704 -- in Freeze.Freeze_Fixed_Point_Type for further details).
10706 if Is_Fixed_Point_Type (Parent_Type)
10707 and then Nkind (Lo) = N_Real_Literal
10708 and then Nkind (Hi) = N_Real_Literal
10712 -- Here we do the analysis of the range
10714 -- Note: we do this manually, since if we do a normal Analyze and
10715 -- Resolve call, there are problems with the conversions used for
10716 -- the derived type range.
10719 Set_Etype (Rng, Implicit_Base);
10720 Set_Analyzed (Rng, True);
10722 end Convert_Scalar_Bounds;
10724 -------------------
10725 -- Copy_And_Swap --
10726 -------------------
10728 procedure Copy_And_Swap (Priv, Full : Entity_Id) is
10730 -- Initialize new full declaration entity by copying the pertinent
10731 -- fields of the corresponding private declaration entity.
10733 -- We temporarily set Ekind to a value appropriate for a type to
10734 -- avoid assert failures in Einfo from checking for setting type
10735 -- attributes on something that is not a type. Ekind (Priv) is an
10736 -- appropriate choice, since it allowed the attributes to be set
10737 -- in the first place. This Ekind value will be modified later.
10739 Set_Ekind (Full, Ekind (Priv));
10741 -- Also set Etype temporarily to Any_Type, again, in the absence
10742 -- of errors, it will be properly reset, and if there are errors,
10743 -- then we want a value of Any_Type to remain.
10745 Set_Etype (Full, Any_Type);
10747 -- Now start copying attributes
10749 Set_Has_Discriminants (Full, Has_Discriminants (Priv));
10751 if Has_Discriminants (Full) then
10752 Set_Discriminant_Constraint (Full, Discriminant_Constraint (Priv));
10753 Set_Stored_Constraint (Full, Stored_Constraint (Priv));
10756 Set_First_Rep_Item (Full, First_Rep_Item (Priv));
10757 Set_Homonym (Full, Homonym (Priv));
10758 Set_Is_Immediately_Visible (Full, Is_Immediately_Visible (Priv));
10759 Set_Is_Public (Full, Is_Public (Priv));
10760 Set_Is_Pure (Full, Is_Pure (Priv));
10761 Set_Is_Tagged_Type (Full, Is_Tagged_Type (Priv));
10762 Set_Has_Pragma_Unreferenced (Full, Has_Pragma_Unreferenced (Priv));
10763 Set_Has_Pragma_Unreferenced_Objects
10764 (Full, Has_Pragma_Unreferenced_Objects
10767 Conditional_Delay (Full, Priv);
10769 if Is_Tagged_Type (Full) then
10770 Set_Primitive_Operations (Full, Primitive_Operations (Priv));
10772 if Priv = Base_Type (Priv) then
10773 Set_Class_Wide_Type (Full, Class_Wide_Type (Priv));
10777 Set_Is_Volatile (Full, Is_Volatile (Priv));
10778 Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv));
10779 Set_Scope (Full, Scope (Priv));
10780 Set_Next_Entity (Full, Next_Entity (Priv));
10781 Set_First_Entity (Full, First_Entity (Priv));
10782 Set_Last_Entity (Full, Last_Entity (Priv));
10784 -- If access types have been recorded for later handling, keep them in
10785 -- the full view so that they get handled when the full view freeze
10786 -- node is expanded.
10788 if Present (Freeze_Node (Priv))
10789 and then Present (Access_Types_To_Process (Freeze_Node (Priv)))
10791 Ensure_Freeze_Node (Full);
10792 Set_Access_Types_To_Process
10793 (Freeze_Node (Full),
10794 Access_Types_To_Process (Freeze_Node (Priv)));
10797 -- Swap the two entities. Now Privat is the full type entity and
10798 -- Full is the private one. They will be swapped back at the end
10799 -- of the private part. This swapping ensures that the entity that
10800 -- is visible in the private part is the full declaration.
10802 Exchange_Entities (Priv, Full);
10803 Append_Entity (Full, Scope (Full));
10806 -------------------------------------
10807 -- Copy_Array_Base_Type_Attributes --
10808 -------------------------------------
10810 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id) is
10812 Set_Component_Alignment (T1, Component_Alignment (T2));
10813 Set_Component_Type (T1, Component_Type (T2));
10814 Set_Component_Size (T1, Component_Size (T2));
10815 Set_Has_Controlled_Component (T1, Has_Controlled_Component (T2));
10816 Set_Finalize_Storage_Only (T1, Finalize_Storage_Only (T2));
10817 Set_Has_Non_Standard_Rep (T1, Has_Non_Standard_Rep (T2));
10818 Set_Has_Task (T1, Has_Task (T2));
10819 Set_Is_Packed (T1, Is_Packed (T2));
10820 Set_Has_Aliased_Components (T1, Has_Aliased_Components (T2));
10821 Set_Has_Atomic_Components (T1, Has_Atomic_Components (T2));
10822 Set_Has_Volatile_Components (T1, Has_Volatile_Components (T2));
10823 end Copy_Array_Base_Type_Attributes;
10825 -----------------------------------
10826 -- Copy_Array_Subtype_Attributes --
10827 -----------------------------------
10829 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id) is
10831 Set_Size_Info (T1, T2);
10833 Set_First_Index (T1, First_Index (T2));
10834 Set_Is_Aliased (T1, Is_Aliased (T2));
10835 Set_Is_Atomic (T1, Is_Atomic (T2));
10836 Set_Is_Volatile (T1, Is_Volatile (T2));
10837 Set_Treat_As_Volatile (T1, Treat_As_Volatile (T2));
10838 Set_Is_Constrained (T1, Is_Constrained (T2));
10839 Set_Depends_On_Private (T1, Has_Private_Component (T2));
10840 Set_First_Rep_Item (T1, First_Rep_Item (T2));
10841 Set_Convention (T1, Convention (T2));
10842 Set_Is_Limited_Composite (T1, Is_Limited_Composite (T2));
10843 Set_Is_Private_Composite (T1, Is_Private_Composite (T2));
10844 end Copy_Array_Subtype_Attributes;
10846 -----------------------------------
10847 -- Create_Constrained_Components --
10848 -----------------------------------
10850 procedure Create_Constrained_Components
10852 Decl_Node : Node_Id;
10854 Constraints : Elist_Id)
10856 Loc : constant Source_Ptr := Sloc (Subt);
10857 Comp_List : constant Elist_Id := New_Elmt_List;
10858 Parent_Type : constant Entity_Id := Etype (Typ);
10859 Assoc_List : constant List_Id := New_List;
10860 Discr_Val : Elmt_Id;
10864 Is_Static : Boolean := True;
10866 procedure Collect_Fixed_Components (Typ : Entity_Id);
10867 -- Collect parent type components that do not appear in a variant part
10869 procedure Create_All_Components;
10870 -- Iterate over Comp_List to create the components of the subtype
10872 function Create_Component (Old_Compon : Entity_Id) return Entity_Id;
10873 -- Creates a new component from Old_Compon, copying all the fields from
10874 -- it, including its Etype, inserts the new component in the Subt entity
10875 -- chain and returns the new component.
10877 function Is_Variant_Record (T : Entity_Id) return Boolean;
10878 -- If true, and discriminants are static, collect only components from
10879 -- variants selected by discriminant values.
10881 ------------------------------
10882 -- Collect_Fixed_Components --
10883 ------------------------------
10885 procedure Collect_Fixed_Components (Typ : Entity_Id) is
10887 -- Build association list for discriminants, and find components of the
10888 -- variant part selected by the values of the discriminants.
10890 Old_C := First_Discriminant (Typ);
10891 Discr_Val := First_Elmt (Constraints);
10892 while Present (Old_C) loop
10893 Append_To (Assoc_List,
10894 Make_Component_Association (Loc,
10895 Choices => New_List (New_Occurrence_Of (Old_C, Loc)),
10896 Expression => New_Copy (Node (Discr_Val))));
10898 Next_Elmt (Discr_Val);
10899 Next_Discriminant (Old_C);
10902 -- The tag, and the possible parent and controller components
10903 -- are unconditionally in the subtype.
10905 if Is_Tagged_Type (Typ)
10906 or else Has_Controlled_Component (Typ)
10908 Old_C := First_Component (Typ);
10909 while Present (Old_C) loop
10910 if Chars ((Old_C)) = Name_uTag
10911 or else Chars ((Old_C)) = Name_uParent
10912 or else Chars ((Old_C)) = Name_uController
10914 Append_Elmt (Old_C, Comp_List);
10917 Next_Component (Old_C);
10920 end Collect_Fixed_Components;
10922 ---------------------------
10923 -- Create_All_Components --
10924 ---------------------------
10926 procedure Create_All_Components is
10930 Comp := First_Elmt (Comp_List);
10931 while Present (Comp) loop
10932 Old_C := Node (Comp);
10933 New_C := Create_Component (Old_C);
10937 Constrain_Component_Type
10938 (Old_C, Subt, Decl_Node, Typ, Constraints));
10939 Set_Is_Public (New_C, Is_Public (Subt));
10943 end Create_All_Components;
10945 ----------------------
10946 -- Create_Component --
10947 ----------------------
10949 function Create_Component (Old_Compon : Entity_Id) return Entity_Id is
10950 New_Compon : constant Entity_Id := New_Copy (Old_Compon);
10953 if Ekind (Old_Compon) = E_Discriminant
10954 and then Is_Completely_Hidden (Old_Compon)
10956 -- This is a shadow discriminant created for a discriminant of
10957 -- the parent type that is one of several renamed by the same
10958 -- new discriminant. Give the shadow discriminant an internal
10959 -- name that cannot conflict with that of visible components.
10961 Set_Chars (New_Compon, New_Internal_Name ('C'));
10964 -- Set the parent so we have a proper link for freezing etc. This is
10965 -- not a real parent pointer, since of course our parent does not own
10966 -- up to us and reference us, we are an illegitimate child of the
10967 -- original parent!
10969 Set_Parent (New_Compon, Parent (Old_Compon));
10971 -- If the old component's Esize was already determined and is a
10972 -- static value, then the new component simply inherits it. Otherwise
10973 -- the old component's size may require run-time determination, but
10974 -- the new component's size still might be statically determinable
10975 -- (if, for example it has a static constraint). In that case we want
10976 -- Layout_Type to recompute the component's size, so we reset its
10977 -- size and positional fields.
10979 if Frontend_Layout_On_Target
10980 and then not Known_Static_Esize (Old_Compon)
10982 Set_Esize (New_Compon, Uint_0);
10983 Init_Normalized_First_Bit (New_Compon);
10984 Init_Normalized_Position (New_Compon);
10985 Init_Normalized_Position_Max (New_Compon);
10988 -- We do not want this node marked as Comes_From_Source, since
10989 -- otherwise it would get first class status and a separate cross-
10990 -- reference line would be generated. Illegitimate children do not
10991 -- rate such recognition.
10993 Set_Comes_From_Source (New_Compon, False);
10995 -- But it is a real entity, and a birth certificate must be properly
10996 -- registered by entering it into the entity list.
10998 Enter_Name (New_Compon);
11001 end Create_Component;
11003 -----------------------
11004 -- Is_Variant_Record --
11005 -----------------------
11007 function Is_Variant_Record (T : Entity_Id) return Boolean is
11009 return Nkind (Parent (T)) = N_Full_Type_Declaration
11010 and then Nkind (Type_Definition (Parent (T))) = N_Record_Definition
11011 and then Present (Component_List (Type_Definition (Parent (T))))
11014 (Variant_Part (Component_List (Type_Definition (Parent (T)))));
11015 end Is_Variant_Record;
11017 -- Start of processing for Create_Constrained_Components
11020 pragma Assert (Subt /= Base_Type (Subt));
11021 pragma Assert (Typ = Base_Type (Typ));
11023 Set_First_Entity (Subt, Empty);
11024 Set_Last_Entity (Subt, Empty);
11026 -- Check whether constraint is fully static, in which case we can
11027 -- optimize the list of components.
11029 Discr_Val := First_Elmt (Constraints);
11030 while Present (Discr_Val) loop
11031 if not Is_OK_Static_Expression (Node (Discr_Val)) then
11032 Is_Static := False;
11036 Next_Elmt (Discr_Val);
11039 Set_Has_Static_Discriminants (Subt, Is_Static);
11043 -- Inherit the discriminants of the parent type
11045 Add_Discriminants : declare
11051 Old_C := First_Discriminant (Typ);
11053 while Present (Old_C) loop
11054 Num_Disc := Num_Disc + 1;
11055 New_C := Create_Component (Old_C);
11056 Set_Is_Public (New_C, Is_Public (Subt));
11057 Next_Discriminant (Old_C);
11060 -- For an untagged derived subtype, the number of discriminants may
11061 -- be smaller than the number of inherited discriminants, because
11062 -- several of them may be renamed by a single new discriminant.
11063 -- In this case, add the hidden discriminants back into the subtype,
11064 -- because otherwise the size of the subtype is computed incorrectly
11069 if Is_Derived_Type (Typ)
11070 and then not Is_Tagged_Type (Typ)
11072 Old_C := First_Stored_Discriminant (Typ);
11074 while Present (Old_C) loop
11075 Num_Gird := Num_Gird + 1;
11076 Next_Stored_Discriminant (Old_C);
11080 if Num_Gird > Num_Disc then
11082 -- Find out multiple uses of new discriminants, and add hidden
11083 -- components for the extra renamed discriminants. We recognize
11084 -- multiple uses through the Corresponding_Discriminant of a
11085 -- new discriminant: if it constrains several old discriminants,
11086 -- this field points to the last one in the parent type. The
11087 -- stored discriminants of the derived type have the same name
11088 -- as those of the parent.
11092 New_Discr : Entity_Id;
11093 Old_Discr : Entity_Id;
11096 Constr := First_Elmt (Stored_Constraint (Typ));
11097 Old_Discr := First_Stored_Discriminant (Typ);
11098 while Present (Constr) loop
11099 if Is_Entity_Name (Node (Constr))
11100 and then Ekind (Entity (Node (Constr))) = E_Discriminant
11102 New_Discr := Entity (Node (Constr));
11104 if Chars (Corresponding_Discriminant (New_Discr)) /=
11107 -- The new discriminant has been used to rename a
11108 -- subsequent old discriminant. Introduce a shadow
11109 -- component for the current old discriminant.
11111 New_C := Create_Component (Old_Discr);
11112 Set_Original_Record_Component (New_C, Old_Discr);
11116 Next_Elmt (Constr);
11117 Next_Stored_Discriminant (Old_Discr);
11121 end Add_Discriminants;
11124 and then Is_Variant_Record (Typ)
11126 Collect_Fixed_Components (Typ);
11128 Gather_Components (
11130 Component_List (Type_Definition (Parent (Typ))),
11131 Governed_By => Assoc_List,
11133 Report_Errors => Errors);
11134 pragma Assert (not Errors);
11136 Create_All_Components;
11138 -- If the subtype declaration is created for a tagged type derivation
11139 -- with constraints, we retrieve the record definition of the parent
11140 -- type to select the components of the proper variant.
11143 and then Is_Tagged_Type (Typ)
11144 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11146 Nkind (Type_Definition (Parent (Typ))) = N_Derived_Type_Definition
11147 and then Is_Variant_Record (Parent_Type)
11149 Collect_Fixed_Components (Typ);
11151 Gather_Components (
11153 Component_List (Type_Definition (Parent (Parent_Type))),
11154 Governed_By => Assoc_List,
11156 Report_Errors => Errors);
11157 pragma Assert (not Errors);
11159 -- If the tagged derivation has a type extension, collect all the
11160 -- new components therein.
11163 (Record_Extension_Part (Type_Definition (Parent (Typ))))
11165 Old_C := First_Component (Typ);
11166 while Present (Old_C) loop
11167 if Original_Record_Component (Old_C) = Old_C
11168 and then Chars (Old_C) /= Name_uTag
11169 and then Chars (Old_C) /= Name_uParent
11170 and then Chars (Old_C) /= Name_uController
11172 Append_Elmt (Old_C, Comp_List);
11175 Next_Component (Old_C);
11179 Create_All_Components;
11182 -- If discriminants are not static, or if this is a multi-level type
11183 -- extension, we have to include all components of the parent type.
11185 Old_C := First_Component (Typ);
11186 while Present (Old_C) loop
11187 New_C := Create_Component (Old_C);
11191 Constrain_Component_Type
11192 (Old_C, Subt, Decl_Node, Typ, Constraints));
11193 Set_Is_Public (New_C, Is_Public (Subt));
11195 Next_Component (Old_C);
11200 end Create_Constrained_Components;
11202 ------------------------------------------
11203 -- Decimal_Fixed_Point_Type_Declaration --
11204 ------------------------------------------
11206 procedure Decimal_Fixed_Point_Type_Declaration
11210 Loc : constant Source_Ptr := Sloc (Def);
11211 Digs_Expr : constant Node_Id := Digits_Expression (Def);
11212 Delta_Expr : constant Node_Id := Delta_Expression (Def);
11213 Implicit_Base : Entity_Id;
11220 Check_Restriction (No_Fixed_Point, Def);
11222 -- Create implicit base type
11225 Create_Itype (E_Decimal_Fixed_Point_Type, Parent (Def), T, 'B');
11226 Set_Etype (Implicit_Base, Implicit_Base);
11228 -- Analyze and process delta expression
11230 Analyze_And_Resolve (Delta_Expr, Universal_Real);
11232 Check_Delta_Expression (Delta_Expr);
11233 Delta_Val := Expr_Value_R (Delta_Expr);
11235 -- Check delta is power of 10, and determine scale value from it
11241 Scale_Val := Uint_0;
11244 if Val < Ureal_1 then
11245 while Val < Ureal_1 loop
11246 Val := Val * Ureal_10;
11247 Scale_Val := Scale_Val + 1;
11250 if Scale_Val > 18 then
11251 Error_Msg_N ("scale exceeds maximum value of 18", Def);
11252 Scale_Val := UI_From_Int (+18);
11256 while Val > Ureal_1 loop
11257 Val := Val / Ureal_10;
11258 Scale_Val := Scale_Val - 1;
11261 if Scale_Val < -18 then
11262 Error_Msg_N ("scale is less than minimum value of -18", Def);
11263 Scale_Val := UI_From_Int (-18);
11267 if Val /= Ureal_1 then
11268 Error_Msg_N ("delta expression must be a power of 10", Def);
11269 Delta_Val := Ureal_10 ** (-Scale_Val);
11273 -- Set delta, scale and small (small = delta for decimal type)
11275 Set_Delta_Value (Implicit_Base, Delta_Val);
11276 Set_Scale_Value (Implicit_Base, Scale_Val);
11277 Set_Small_Value (Implicit_Base, Delta_Val);
11279 -- Analyze and process digits expression
11281 Analyze_And_Resolve (Digs_Expr, Any_Integer);
11282 Check_Digits_Expression (Digs_Expr);
11283 Digs_Val := Expr_Value (Digs_Expr);
11285 if Digs_Val > 18 then
11286 Digs_Val := UI_From_Int (+18);
11287 Error_Msg_N ("digits value out of range, maximum is 18", Digs_Expr);
11290 Set_Digits_Value (Implicit_Base, Digs_Val);
11291 Bound_Val := UR_From_Uint (10 ** Digs_Val - 1) * Delta_Val;
11293 -- Set range of base type from digits value for now. This will be
11294 -- expanded to represent the true underlying base range by Freeze.
11296 Set_Fixed_Range (Implicit_Base, Loc, -Bound_Val, Bound_Val);
11298 -- Note: We leave size as zero for now, size will be set at freeze
11299 -- time. We have to do this for ordinary fixed-point, because the size
11300 -- depends on the specified small, and we might as well do the same for
11301 -- decimal fixed-point.
11303 pragma Assert (Esize (Implicit_Base) = Uint_0);
11305 -- If there are bounds given in the declaration use them as the
11306 -- bounds of the first named subtype.
11308 if Present (Real_Range_Specification (Def)) then
11310 RRS : constant Node_Id := Real_Range_Specification (Def);
11311 Low : constant Node_Id := Low_Bound (RRS);
11312 High : constant Node_Id := High_Bound (RRS);
11317 Analyze_And_Resolve (Low, Any_Real);
11318 Analyze_And_Resolve (High, Any_Real);
11319 Check_Real_Bound (Low);
11320 Check_Real_Bound (High);
11321 Low_Val := Expr_Value_R (Low);
11322 High_Val := Expr_Value_R (High);
11324 if Low_Val < (-Bound_Val) then
11326 ("range low bound too small for digits value", Low);
11327 Low_Val := -Bound_Val;
11330 if High_Val > Bound_Val then
11332 ("range high bound too large for digits value", High);
11333 High_Val := Bound_Val;
11336 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
11339 -- If no explicit range, use range that corresponds to given
11340 -- digits value. This will end up as the final range for the
11344 Set_Fixed_Range (T, Loc, -Bound_Val, Bound_Val);
11347 -- Complete entity for first subtype
11349 Set_Ekind (T, E_Decimal_Fixed_Point_Subtype);
11350 Set_Etype (T, Implicit_Base);
11351 Set_Size_Info (T, Implicit_Base);
11352 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
11353 Set_Digits_Value (T, Digs_Val);
11354 Set_Delta_Value (T, Delta_Val);
11355 Set_Small_Value (T, Delta_Val);
11356 Set_Scale_Value (T, Scale_Val);
11357 Set_Is_Constrained (T);
11358 end Decimal_Fixed_Point_Type_Declaration;
11360 -----------------------------------
11361 -- Derive_Progenitor_Subprograms --
11362 -----------------------------------
11364 procedure Derive_Progenitor_Subprograms
11365 (Parent_Type : Entity_Id;
11366 Tagged_Type : Entity_Id)
11371 Iface_Elmt : Elmt_Id;
11372 Iface_Subp : Entity_Id;
11373 New_Subp : Entity_Id := Empty;
11374 Prim_Elmt : Elmt_Id;
11379 pragma Assert (Ada_Version >= Ada_05
11380 and then Is_Record_Type (Tagged_Type)
11381 and then Is_Tagged_Type (Tagged_Type)
11382 and then Has_Interfaces (Tagged_Type));
11384 -- Step 1: Transfer to the full-view primitives associated with the
11385 -- partial-view that cover interface primitives. Conceptually this
11386 -- work should be done later by Process_Full_View; done here to
11387 -- simplify its implementation at later stages. It can be safely
11388 -- done here because interfaces must be visible in the partial and
11389 -- private view (RM 7.3(7.3/2)).
11391 -- Small optimization: This work is only required if the parent is
11392 -- abstract. If the tagged type is not abstract, it cannot have
11393 -- abstract primitives (the only entities in the list of primitives of
11394 -- non-abstract tagged types that can reference abstract primitives
11395 -- through its Alias attribute are the internal entities that have
11396 -- attribute Interface_Alias, and these entities are generated later
11397 -- by Freeze_Record_Type).
11399 if In_Private_Part (Current_Scope)
11400 and then Is_Abstract_Type (Parent_Type)
11402 Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
11403 while Present (Elmt) loop
11404 Subp := Node (Elmt);
11406 -- At this stage it is not possible to have entities in the list
11407 -- of primitives that have attribute Interface_Alias
11409 pragma Assert (No (Interface_Alias (Subp)));
11411 Typ := Find_Dispatching_Type (Ultimate_Alias (Subp));
11413 if Is_Interface (Typ) then
11414 E := Find_Primitive_Covering_Interface
11415 (Tagged_Type => Tagged_Type,
11416 Iface_Prim => Subp);
11419 and then Find_Dispatching_Type (Ultimate_Alias (E)) /= Typ
11421 Replace_Elmt (Elmt, E);
11422 Remove_Homonym (Subp);
11430 -- Step 2: Add primitives of progenitors that are not implemented by
11431 -- parents of Tagged_Type
11433 if Present (Interfaces (Tagged_Type)) then
11434 Iface_Elmt := First_Elmt (Interfaces (Tagged_Type));
11435 while Present (Iface_Elmt) loop
11436 Iface := Node (Iface_Elmt);
11438 Prim_Elmt := First_Elmt (Primitive_Operations (Iface));
11439 while Present (Prim_Elmt) loop
11440 Iface_Subp := Node (Prim_Elmt);
11442 -- Exclude derivation of predefined primitives except those
11443 -- that come from source. Required to catch declarations of
11444 -- equality operators of interfaces. For example:
11446 -- type Iface is interface;
11447 -- function "=" (Left, Right : Iface) return Boolean;
11449 if not Is_Predefined_Dispatching_Operation (Iface_Subp)
11450 or else Comes_From_Source (Iface_Subp)
11452 E := Find_Primitive_Covering_Interface
11453 (Tagged_Type => Tagged_Type,
11454 Iface_Prim => Iface_Subp);
11456 -- If not found we derive a new primitive leaving its alias
11457 -- attribute referencing the interface primitive
11461 (New_Subp, Iface_Subp, Tagged_Type, Iface);
11463 -- Propagate to the full view interface entities associated
11464 -- with the partial view
11466 elsif In_Private_Part (Current_Scope)
11467 and then Present (Alias (E))
11468 and then Alias (E) = Iface_Subp
11470 List_Containing (Parent (E)) /=
11471 Private_Declarations
11473 (Unit_Declaration_Node (Current_Scope)))
11475 Append_Elmt (E, Primitive_Operations (Tagged_Type));
11479 Next_Elmt (Prim_Elmt);
11482 Next_Elmt (Iface_Elmt);
11485 end Derive_Progenitor_Subprograms;
11487 -----------------------
11488 -- Derive_Subprogram --
11489 -----------------------
11491 procedure Derive_Subprogram
11492 (New_Subp : in out Entity_Id;
11493 Parent_Subp : Entity_Id;
11494 Derived_Type : Entity_Id;
11495 Parent_Type : Entity_Id;
11496 Actual_Subp : Entity_Id := Empty)
11498 Formal : Entity_Id;
11499 -- Formal parameter of parent primitive operation
11501 Formal_Of_Actual : Entity_Id;
11502 -- Formal parameter of actual operation, when the derivation is to
11503 -- create a renaming for a primitive operation of an actual in an
11506 New_Formal : Entity_Id;
11507 -- Formal of inherited operation
11509 Visible_Subp : Entity_Id := Parent_Subp;
11511 function Is_Private_Overriding return Boolean;
11512 -- If Subp is a private overriding of a visible operation, the inherited
11513 -- operation derives from the overridden op (even though its body is the
11514 -- overriding one) and the inherited operation is visible now. See
11515 -- sem_disp to see the full details of the handling of the overridden
11516 -- subprogram, which is removed from the list of primitive operations of
11517 -- the type. The overridden subprogram is saved locally in Visible_Subp,
11518 -- and used to diagnose abstract operations that need overriding in the
11521 procedure Replace_Type (Id, New_Id : Entity_Id);
11522 -- When the type is an anonymous access type, create a new access type
11523 -- designating the derived type.
11525 procedure Set_Derived_Name;
11526 -- This procedure sets the appropriate Chars name for New_Subp. This
11527 -- is normally just a copy of the parent name. An exception arises for
11528 -- type support subprograms, where the name is changed to reflect the
11529 -- name of the derived type, e.g. if type foo is derived from type bar,
11530 -- then a procedure barDA is derived with a name fooDA.
11532 ---------------------------
11533 -- Is_Private_Overriding --
11534 ---------------------------
11536 function Is_Private_Overriding return Boolean is
11540 -- If the parent is not a dispatching operation there is no
11541 -- need to investigate overridings
11543 if not Is_Dispatching_Operation (Parent_Subp) then
11547 -- The visible operation that is overridden is a homonym of the
11548 -- parent subprogram. We scan the homonym chain to find the one
11549 -- whose alias is the subprogram we are deriving.
11551 Prev := Current_Entity (Parent_Subp);
11552 while Present (Prev) loop
11553 if Ekind (Prev) = Ekind (Parent_Subp)
11554 and then Alias (Prev) = Parent_Subp
11555 and then Scope (Parent_Subp) = Scope (Prev)
11556 and then not Is_Hidden (Prev)
11558 Visible_Subp := Prev;
11562 Prev := Homonym (Prev);
11566 end Is_Private_Overriding;
11572 procedure Replace_Type (Id, New_Id : Entity_Id) is
11573 Acc_Type : Entity_Id;
11574 Par : constant Node_Id := Parent (Derived_Type);
11577 -- When the type is an anonymous access type, create a new access
11578 -- type designating the derived type. This itype must be elaborated
11579 -- at the point of the derivation, not on subsequent calls that may
11580 -- be out of the proper scope for Gigi, so we insert a reference to
11581 -- it after the derivation.
11583 if Ekind (Etype (Id)) = E_Anonymous_Access_Type then
11585 Desig_Typ : Entity_Id := Designated_Type (Etype (Id));
11588 if Ekind (Desig_Typ) = E_Record_Type_With_Private
11589 and then Present (Full_View (Desig_Typ))
11590 and then not Is_Private_Type (Parent_Type)
11592 Desig_Typ := Full_View (Desig_Typ);
11595 if Base_Type (Desig_Typ) = Base_Type (Parent_Type)
11597 -- Ada 2005 (AI-251): Handle also derivations of abstract
11598 -- interface primitives.
11600 or else (Is_Interface (Desig_Typ)
11601 and then not Is_Class_Wide_Type (Desig_Typ))
11603 Acc_Type := New_Copy (Etype (Id));
11604 Set_Etype (Acc_Type, Acc_Type);
11605 Set_Scope (Acc_Type, New_Subp);
11607 -- Compute size of anonymous access type
11609 if Is_Array_Type (Desig_Typ)
11610 and then not Is_Constrained (Desig_Typ)
11612 Init_Size (Acc_Type, 2 * System_Address_Size);
11614 Init_Size (Acc_Type, System_Address_Size);
11617 Init_Alignment (Acc_Type);
11618 Set_Directly_Designated_Type (Acc_Type, Derived_Type);
11620 Set_Etype (New_Id, Acc_Type);
11621 Set_Scope (New_Id, New_Subp);
11623 -- Create a reference to it
11624 Build_Itype_Reference (Acc_Type, Parent (Derived_Type));
11627 Set_Etype (New_Id, Etype (Id));
11631 elsif Base_Type (Etype (Id)) = Base_Type (Parent_Type)
11633 (Ekind (Etype (Id)) = E_Record_Type_With_Private
11634 and then Present (Full_View (Etype (Id)))
11636 Base_Type (Full_View (Etype (Id))) = Base_Type (Parent_Type))
11638 -- Constraint checks on formals are generated during expansion,
11639 -- based on the signature of the original subprogram. The bounds
11640 -- of the derived type are not relevant, and thus we can use
11641 -- the base type for the formals. However, the return type may be
11642 -- used in a context that requires that the proper static bounds
11643 -- be used (a case statement, for example) and for those cases
11644 -- we must use the derived type (first subtype), not its base.
11646 -- If the derived_type_definition has no constraints, we know that
11647 -- the derived type has the same constraints as the first subtype
11648 -- of the parent, and we can also use it rather than its base,
11649 -- which can lead to more efficient code.
11651 if Etype (Id) = Parent_Type then
11652 if Is_Scalar_Type (Parent_Type)
11654 Subtypes_Statically_Compatible (Parent_Type, Derived_Type)
11656 Set_Etype (New_Id, Derived_Type);
11658 elsif Nkind (Par) = N_Full_Type_Declaration
11660 Nkind (Type_Definition (Par)) = N_Derived_Type_Definition
11663 (Subtype_Indication (Type_Definition (Par)))
11665 Set_Etype (New_Id, Derived_Type);
11668 Set_Etype (New_Id, Base_Type (Derived_Type));
11672 Set_Etype (New_Id, Base_Type (Derived_Type));
11675 -- Ada 2005 (AI-251): Handle derivations of abstract interface
11678 elsif Is_Interface (Etype (Id))
11679 and then not Is_Class_Wide_Type (Etype (Id))
11680 and then Is_Progenitor (Etype (Id), Derived_Type)
11682 Set_Etype (New_Id, Derived_Type);
11685 Set_Etype (New_Id, Etype (Id));
11689 ----------------------
11690 -- Set_Derived_Name --
11691 ----------------------
11693 procedure Set_Derived_Name is
11694 Nm : constant TSS_Name_Type := Get_TSS_Name (Parent_Subp);
11696 if Nm = TSS_Null then
11697 Set_Chars (New_Subp, Chars (Parent_Subp));
11699 Set_Chars (New_Subp, Make_TSS_Name (Base_Type (Derived_Type), Nm));
11701 end Set_Derived_Name;
11705 Parent_Overrides_Interface_Primitive : Boolean := False;
11707 -- Start of processing for Derive_Subprogram
11711 New_Entity (Nkind (Parent_Subp), Sloc (Derived_Type));
11712 Set_Ekind (New_Subp, Ekind (Parent_Subp));
11714 -- Check whether the parent overrides an interface primitive
11716 if Is_Overriding_Operation (Parent_Subp) then
11718 E : Entity_Id := Parent_Subp;
11720 while Present (Overridden_Operation (E)) loop
11721 E := Ultimate_Alias (Overridden_Operation (E));
11724 Parent_Overrides_Interface_Primitive :=
11725 Is_Dispatching_Operation (E)
11726 and then Present (Find_Dispatching_Type (E))
11727 and then Is_Interface (Find_Dispatching_Type (E));
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): Regular derivation if the parent subprogram
11777 -- overrides an interface primitive because interface primitives
11778 -- must be visible in the partial view of the parent (RM 7.3 (7.3/2))
11780 elsif Parent_Overrides_Interface_Primitive then
11783 -- The type is inheriting a private operation, so enter
11784 -- it with a special name so it can't be overridden.
11787 Set_Chars (New_Subp, New_External_Name (Chars (Parent_Subp), 'P'));
11790 Set_Parent (New_Subp, Parent (Derived_Type));
11792 if Present (Actual_Subp) then
11793 Replace_Type (Actual_Subp, New_Subp);
11795 Replace_Type (Parent_Subp, New_Subp);
11798 Conditional_Delay (New_Subp, Parent_Subp);
11800 -- If we are creating a renaming for a primitive operation of an
11801 -- actual of a generic derived type, we must examine the signature
11802 -- of the actual primitive, not that of the generic formal, which for
11803 -- example may be an interface. However the name and initial value
11804 -- of the inherited operation are those of the formal primitive.
11806 Formal := First_Formal (Parent_Subp);
11808 if Present (Actual_Subp) then
11809 Formal_Of_Actual := First_Formal (Actual_Subp);
11811 Formal_Of_Actual := Empty;
11814 while Present (Formal) loop
11815 New_Formal := New_Copy (Formal);
11817 -- Normally we do not go copying parents, but in the case of
11818 -- formals, we need to link up to the declaration (which is the
11819 -- parameter specification), and it is fine to link up to the
11820 -- original formal's parameter specification in this case.
11822 Set_Parent (New_Formal, Parent (Formal));
11823 Append_Entity (New_Formal, New_Subp);
11825 if Present (Formal_Of_Actual) then
11826 Replace_Type (Formal_Of_Actual, New_Formal);
11827 Next_Formal (Formal_Of_Actual);
11829 Replace_Type (Formal, New_Formal);
11832 Next_Formal (Formal);
11835 -- If this derivation corresponds to a tagged generic actual, then
11836 -- primitive operations rename those of the actual. Otherwise the
11837 -- primitive operations rename those of the parent type, If the parent
11838 -- renames an intrinsic operator, so does the new subprogram. We except
11839 -- concatenation, which is always properly typed, and does not get
11840 -- expanded as other intrinsic operations.
11842 if No (Actual_Subp) then
11843 if Is_Intrinsic_Subprogram (Parent_Subp) then
11844 Set_Is_Intrinsic_Subprogram (New_Subp);
11846 if Present (Alias (Parent_Subp))
11847 and then Chars (Parent_Subp) /= Name_Op_Concat
11849 Set_Alias (New_Subp, Alias (Parent_Subp));
11851 Set_Alias (New_Subp, Parent_Subp);
11855 Set_Alias (New_Subp, Parent_Subp);
11859 Set_Alias (New_Subp, Actual_Subp);
11862 -- Derived subprograms of a tagged type must inherit the convention
11863 -- of the parent subprogram (a requirement of AI-117). Derived
11864 -- subprograms of untagged types simply get convention Ada by default.
11866 if Is_Tagged_Type (Derived_Type) then
11867 Set_Convention (New_Subp, Convention (Parent_Subp));
11870 Set_Is_Imported (New_Subp, Is_Imported (Parent_Subp));
11871 Set_Is_Exported (New_Subp, Is_Exported (Parent_Subp));
11873 if Ekind (Parent_Subp) = E_Procedure then
11874 Set_Is_Valued_Procedure
11875 (New_Subp, Is_Valued_Procedure (Parent_Subp));
11878 -- No_Return must be inherited properly. If this is overridden in the
11879 -- case of a dispatching operation, then a check is made in Sem_Disp
11880 -- that the overriding operation is also No_Return (no such check is
11881 -- required for the case of non-dispatching operation.
11883 Set_No_Return (New_Subp, No_Return (Parent_Subp));
11885 -- A derived function with a controlling result is abstract. If the
11886 -- Derived_Type is a nonabstract formal generic derived type, then
11887 -- inherited operations are not abstract: the required check is done at
11888 -- instantiation time. If the derivation is for a generic actual, the
11889 -- function is not abstract unless the actual is.
11891 if Is_Generic_Type (Derived_Type)
11892 and then not Is_Abstract_Type (Derived_Type)
11896 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
11897 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2).
11899 elsif Ada_Version >= Ada_05
11900 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11901 or else (Is_Tagged_Type (Derived_Type)
11902 and then Etype (New_Subp) = Derived_Type
11903 and then not Is_Null_Extension (Derived_Type))
11904 or else (Is_Tagged_Type (Derived_Type)
11905 and then Ekind (Etype (New_Subp)) =
11906 E_Anonymous_Access_Type
11907 and then Designated_Type (Etype (New_Subp)) =
11909 and then not Is_Null_Extension (Derived_Type)))
11910 and then No (Actual_Subp)
11912 if not Is_Tagged_Type (Derived_Type)
11913 or else Is_Abstract_Type (Derived_Type)
11914 or else Is_Abstract_Subprogram (Alias (New_Subp))
11916 Set_Is_Abstract_Subprogram (New_Subp);
11918 Set_Requires_Overriding (New_Subp);
11921 elsif Ada_Version < Ada_05
11922 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11923 or else (Is_Tagged_Type (Derived_Type)
11924 and then Etype (New_Subp) = Derived_Type
11925 and then No (Actual_Subp)))
11927 Set_Is_Abstract_Subprogram (New_Subp);
11929 -- Finally, if the parent type is abstract we must verify that all
11930 -- inherited operations are either non-abstract or overridden, or that
11931 -- the derived type itself is abstract (this check is performed at the
11932 -- end of a package declaration, in Check_Abstract_Overriding). A
11933 -- private overriding in the parent type will not be visible in the
11934 -- derivation if we are not in an inner package or in a child unit of
11935 -- the parent type, in which case the abstractness of the inherited
11936 -- operation is carried to the new subprogram.
11938 elsif Is_Abstract_Type (Parent_Type)
11939 and then not In_Open_Scopes (Scope (Parent_Type))
11940 and then Is_Private_Overriding
11941 and then Is_Abstract_Subprogram (Visible_Subp)
11943 if No (Actual_Subp) then
11944 Set_Alias (New_Subp, Visible_Subp);
11945 Set_Is_Abstract_Subprogram
11948 -- If this is a derivation for an instance of a formal derived
11949 -- type, abstractness comes from the primitive operation of the
11950 -- actual, not from the operation inherited from the ancestor.
11952 Set_Is_Abstract_Subprogram
11953 (New_Subp, Is_Abstract_Subprogram (Actual_Subp));
11957 New_Overloaded_Entity (New_Subp, Derived_Type);
11959 -- Check for case of a derived subprogram for the instantiation of a
11960 -- formal derived tagged type, if so mark the subprogram as dispatching
11961 -- and inherit the dispatching attributes of the parent subprogram. The
11962 -- derived subprogram is effectively renaming of the actual subprogram,
11963 -- so it needs to have the same attributes as the actual.
11965 if Present (Actual_Subp)
11966 and then Is_Dispatching_Operation (Parent_Subp)
11968 Set_Is_Dispatching_Operation (New_Subp);
11970 if Present (DTC_Entity (Parent_Subp)) then
11971 Set_DTC_Entity (New_Subp, DTC_Entity (Parent_Subp));
11972 Set_DT_Position (New_Subp, DT_Position (Parent_Subp));
11976 -- Indicate that a derived subprogram does not require a body and that
11977 -- it does not require processing of default expressions.
11979 Set_Has_Completion (New_Subp);
11980 Set_Default_Expressions_Processed (New_Subp);
11982 if Ekind (New_Subp) = E_Function then
11983 Set_Mechanism (New_Subp, Mechanism (Parent_Subp));
11985 end Derive_Subprogram;
11987 ------------------------
11988 -- Derive_Subprograms --
11989 ------------------------
11991 procedure Derive_Subprograms
11992 (Parent_Type : Entity_Id;
11993 Derived_Type : Entity_Id;
11994 Generic_Actual : Entity_Id := Empty)
11996 Op_List : constant Elist_Id :=
11997 Collect_Primitive_Operations (Parent_Type);
11999 function Check_Derived_Type return Boolean;
12000 -- Check that all primitive inherited from Parent_Type are found in
12001 -- the list of primitives of Derived_Type exactly in the same order.
12003 function Check_Derived_Type return Boolean is
12007 New_Subp : Entity_Id;
12012 -- Traverse list of entities in the current scope searching for
12013 -- an incomplete type whose full-view is derived type
12015 E := First_Entity (Scope (Derived_Type));
12017 and then E /= Derived_Type
12019 if Ekind (E) = E_Incomplete_Type
12020 and then Present (Full_View (E))
12021 and then Full_View (E) = Derived_Type
12023 -- Disable this test if Derived_Type completes an incomplete
12024 -- type because in such case more primitives can be added
12025 -- later to the list of primitives of Derived_Type by routine
12026 -- Process_Incomplete_Dependents
12031 E := Next_Entity (E);
12034 List := Collect_Primitive_Operations (Derived_Type);
12035 Elmt := First_Elmt (List);
12037 Op_Elmt := First_Elmt (Op_List);
12038 while Present (Op_Elmt) loop
12039 Subp := Node (Op_Elmt);
12040 New_Subp := Node (Elmt);
12042 -- At this early stage Derived_Type has no entities with attribute
12043 -- Interface_Alias. In addition, such primitives are always
12044 -- located at the end of the list of primitives of Parent_Type.
12045 -- Therefore, if found we can safely stop processing pending
12048 exit when Present (Interface_Alias (Subp));
12050 -- Handle hidden entities
12052 if not Is_Predefined_Dispatching_Operation (Subp)
12053 and then Is_Hidden (Subp)
12055 if Present (New_Subp)
12056 and then Primitive_Names_Match (Subp, New_Subp)
12062 if not Present (New_Subp)
12063 or else Ekind (Subp) /= Ekind (New_Subp)
12064 or else not Primitive_Names_Match (Subp, New_Subp)
12072 Next_Elmt (Op_Elmt);
12076 end Check_Derived_Type;
12080 Alias_Subp : Entity_Id;
12081 Act_List : Elist_Id;
12082 Act_Elmt : Elmt_Id := No_Elmt;
12083 Act_Subp : Entity_Id := Empty;
12085 Need_Search : Boolean := False;
12086 New_Subp : Entity_Id := Empty;
12087 Parent_Base : Entity_Id;
12090 -- Start of processing for Derive_Subprograms
12093 if Ekind (Parent_Type) = E_Record_Type_With_Private
12094 and then Has_Discriminants (Parent_Type)
12095 and then Present (Full_View (Parent_Type))
12097 Parent_Base := Full_View (Parent_Type);
12099 Parent_Base := Parent_Type;
12102 if Present (Generic_Actual) then
12103 Act_List := Collect_Primitive_Operations (Generic_Actual);
12104 Act_Elmt := First_Elmt (Act_List);
12107 -- Derive primitives inherited from the parent. Note that if the generic
12108 -- actual is present, this is not really a type derivation, it is a
12109 -- completion within an instance.
12111 -- Case 1: Derived_Type does not implement interfaces
12113 if not Is_Tagged_Type (Derived_Type)
12114 or else (not Has_Interfaces (Derived_Type)
12115 and then not (Present (Generic_Actual)
12117 Has_Interfaces (Generic_Actual)))
12119 Elmt := First_Elmt (Op_List);
12120 while Present (Elmt) loop
12121 Subp := Node (Elmt);
12123 -- Literals are derived earlier in the process of building the
12124 -- derived type, and are skipped here.
12126 if Ekind (Subp) = E_Enumeration_Literal then
12129 -- The actual is a direct descendant and the common primitive
12130 -- operations appear in the same order.
12132 -- If the generic parent type is present, the derived type is an
12133 -- instance of a formal derived type, and within the instance its
12134 -- operations are those of the actual. We derive from the formal
12135 -- type but make the inherited operations aliases of the
12136 -- corresponding operations of the actual.
12140 (New_Subp, Subp, Derived_Type, Parent_Base, Node (Act_Elmt));
12142 if Present (Act_Elmt) then
12143 Next_Elmt (Act_Elmt);
12150 -- Case 2: Derived_Type implements interfaces
12153 -- If the parent type has no predefined primitives we remove
12154 -- predefined primitives from the list of primitives of generic
12155 -- actual to simplify the complexity of this algorithm.
12157 if Present (Generic_Actual) then
12159 Has_Predefined_Primitives : Boolean := False;
12162 -- Check if the parent type has predefined primitives
12164 Elmt := First_Elmt (Op_List);
12165 while Present (Elmt) loop
12166 Subp := Node (Elmt);
12168 if Is_Predefined_Dispatching_Operation (Subp)
12169 and then not Comes_From_Source (Ultimate_Alias (Subp))
12171 Has_Predefined_Primitives := True;
12178 -- Remove predefined primitives of Generic_Actual. We must use
12179 -- an auxiliary list because in case of tagged types the value
12180 -- returned by Collect_Primitive_Operations is the value stored
12181 -- in its Primitive_Operations attribute (and we don't want to
12182 -- modify its current contents).
12184 if not Has_Predefined_Primitives then
12186 Aux_List : constant Elist_Id := New_Elmt_List;
12189 Elmt := First_Elmt (Act_List);
12190 while Present (Elmt) loop
12191 Subp := Node (Elmt);
12193 if not Is_Predefined_Dispatching_Operation (Subp)
12194 or else Comes_From_Source (Subp)
12196 Append_Elmt (Subp, Aux_List);
12202 Act_List := Aux_List;
12206 Act_Elmt := First_Elmt (Act_List);
12207 Act_Subp := Node (Act_Elmt);
12211 -- Stage 1: If the generic actual is not present we derive the
12212 -- primitives inherited from the parent type. If the generic parent
12213 -- type is present, the derived type is an instance of a formal
12214 -- derived type, and within the instance its operations are those of
12215 -- the actual. We derive from the formal type but make the inherited
12216 -- operations aliases of the corresponding operations of the actual.
12218 Elmt := First_Elmt (Op_List);
12219 while Present (Elmt) loop
12220 Subp := Node (Elmt);
12221 Alias_Subp := Ultimate_Alias (Subp);
12223 -- At this early stage Derived_Type has no entities with attribute
12224 -- Interface_Alias. In addition, such primitives are always
12225 -- located at the end of the list of primitives of Parent_Type.
12226 -- Therefore, if found we can safely stop processing pending
12229 exit when Present (Interface_Alias (Subp));
12231 -- If the generic actual is present find the corresponding
12232 -- operation in the generic actual. If the parent type is a
12233 -- direct ancestor of the derived type then, even if it is an
12234 -- interface, the operations are inherited from the primary
12235 -- dispatch table and are in the proper order. If we detect here
12236 -- that primitives are not in the same order we traverse the list
12237 -- of primitive operations of the actual to find the one that
12238 -- implements the interface primitive.
12242 (Present (Generic_Actual)
12243 and then Present (Act_Subp)
12244 and then not Primitive_Names_Match (Subp, Act_Subp))
12246 pragma Assert (not Is_Ancestor (Parent_Base, Generic_Actual));
12247 pragma Assert (Is_Interface (Parent_Base));
12249 -- Remember that we need searching for all the pending
12252 Need_Search := True;
12254 -- Handle entities associated with interface primitives
12256 if Present (Alias (Subp))
12257 and then Is_Interface (Find_Dispatching_Type (Alias (Subp)))
12258 and then not Is_Predefined_Dispatching_Operation (Subp)
12261 Find_Primitive_Covering_Interface
12262 (Tagged_Type => Generic_Actual,
12263 Iface_Prim => Subp);
12265 -- Handle predefined primitives plus the rest of user-defined
12269 Act_Elmt := First_Elmt (Act_List);
12270 while Present (Act_Elmt) loop
12271 Act_Subp := Node (Act_Elmt);
12273 exit when Primitive_Names_Match (Subp, Act_Subp)
12274 and then Type_Conformant (Subp, Act_Subp,
12275 Skip_Controlling_Formals => True)
12276 and then No (Interface_Alias (Act_Subp));
12278 Next_Elmt (Act_Elmt);
12283 -- Case 1: If the parent is a limited interface then it has the
12284 -- predefined primitives of synchronized interfaces. However, the
12285 -- actual type may be a non-limited type and hence it does not
12286 -- have such primitives.
12288 if Present (Generic_Actual)
12289 and then not Present (Act_Subp)
12290 and then Is_Limited_Interface (Parent_Base)
12291 and then Is_Predefined_Interface_Primitive (Subp)
12295 -- Case 2: Inherit entities associated with interfaces that
12296 -- were not covered by the parent type. We exclude here null
12297 -- interface primitives because they do not need special
12300 elsif Present (Alias (Subp))
12301 and then Is_Interface (Find_Dispatching_Type (Alias_Subp))
12303 (Nkind (Parent (Alias_Subp)) = N_Procedure_Specification
12304 and then Null_Present (Parent (Alias_Subp)))
12307 (New_Subp => New_Subp,
12308 Parent_Subp => Alias_Subp,
12309 Derived_Type => Derived_Type,
12310 Parent_Type => Find_Dispatching_Type (Alias_Subp),
12311 Actual_Subp => Act_Subp);
12313 if No (Generic_Actual) then
12314 Set_Alias (New_Subp, Subp);
12317 -- Case 3: Common derivation
12321 (New_Subp => New_Subp,
12322 Parent_Subp => Subp,
12323 Derived_Type => Derived_Type,
12324 Parent_Type => Parent_Base,
12325 Actual_Subp => Act_Subp);
12328 -- No need to update Act_Elm if we must search for the
12329 -- corresponding operation in the generic actual
12332 and then Present (Act_Elmt)
12334 Next_Elmt (Act_Elmt);
12335 Act_Subp := Node (Act_Elmt);
12341 -- Inherit additional operations from progenitors. If the derived
12342 -- type is a generic actual, there are not new primitive operations
12343 -- for the type because it has those of the actual, and therefore
12344 -- nothing needs to be done. The renamings generated above are not
12345 -- primitive operations, and their purpose is simply to make the
12346 -- proper operations visible within an instantiation.
12348 if No (Generic_Actual) then
12349 Derive_Progenitor_Subprograms (Parent_Base, Derived_Type);
12353 -- Final check: Direct descendants must have their primitives in the
12354 -- same order. We exclude from this test non-tagged types and instances
12355 -- of formal derived types. We skip this test if we have already
12356 -- reported serious errors in the sources.
12358 pragma Assert (not Is_Tagged_Type (Derived_Type)
12359 or else Present (Generic_Actual)
12360 or else Serious_Errors_Detected > 0
12361 or else Check_Derived_Type);
12362 end Derive_Subprograms;
12364 --------------------------------
12365 -- Derived_Standard_Character --
12366 --------------------------------
12368 procedure Derived_Standard_Character
12370 Parent_Type : Entity_Id;
12371 Derived_Type : Entity_Id)
12373 Loc : constant Source_Ptr := Sloc (N);
12374 Def : constant Node_Id := Type_Definition (N);
12375 Indic : constant Node_Id := Subtype_Indication (Def);
12376 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
12377 Implicit_Base : constant Entity_Id :=
12379 (E_Enumeration_Type, N, Derived_Type, 'B');
12385 Discard_Node (Process_Subtype (Indic, N));
12387 Set_Etype (Implicit_Base, Parent_Base);
12388 Set_Size_Info (Implicit_Base, Root_Type (Parent_Type));
12389 Set_RM_Size (Implicit_Base, RM_Size (Root_Type (Parent_Type)));
12391 Set_Is_Character_Type (Implicit_Base, True);
12392 Set_Has_Delayed_Freeze (Implicit_Base);
12394 -- The bounds of the implicit base are the bounds of the parent base.
12395 -- Note that their type is the parent base.
12397 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
12398 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
12400 Set_Scalar_Range (Implicit_Base,
12403 High_Bound => Hi));
12405 Conditional_Delay (Derived_Type, Parent_Type);
12407 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
12408 Set_Etype (Derived_Type, Implicit_Base);
12409 Set_Size_Info (Derived_Type, Parent_Type);
12411 if Unknown_RM_Size (Derived_Type) then
12412 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
12415 Set_Is_Character_Type (Derived_Type, True);
12417 if Nkind (Indic) /= N_Subtype_Indication then
12419 -- If no explicit constraint, the bounds are those
12420 -- of the parent type.
12422 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Type));
12423 Hi := New_Copy_Tree (Type_High_Bound (Parent_Type));
12424 Set_Scalar_Range (Derived_Type, Make_Range (Loc, Lo, Hi));
12427 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
12429 -- Because the implicit base is used in the conversion of the bounds, we
12430 -- have to freeze it now. This is similar to what is done for numeric
12431 -- types, and it equally suspicious, but otherwise a non-static bound
12432 -- will have a reference to an unfrozen type, which is rejected by Gigi
12433 -- (???). This requires specific care for definition of stream
12434 -- attributes. For details, see comments at the end of
12435 -- Build_Derived_Numeric_Type.
12437 Freeze_Before (N, Implicit_Base);
12438 end Derived_Standard_Character;
12440 ------------------------------
12441 -- Derived_Type_Declaration --
12442 ------------------------------
12444 procedure Derived_Type_Declaration
12447 Is_Completion : Boolean)
12449 Parent_Type : Entity_Id;
12451 function Comes_From_Generic (Typ : Entity_Id) return Boolean;
12452 -- Check whether the parent type is a generic formal, or derives
12453 -- directly or indirectly from one.
12455 ------------------------
12456 -- Comes_From_Generic --
12457 ------------------------
12459 function Comes_From_Generic (Typ : Entity_Id) return Boolean is
12461 if Is_Generic_Type (Typ) then
12464 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
12467 elsif Is_Private_Type (Typ)
12468 and then Present (Full_View (Typ))
12469 and then Is_Generic_Type (Root_Type (Full_View (Typ)))
12473 elsif Is_Generic_Actual_Type (Typ) then
12479 end Comes_From_Generic;
12483 Def : constant Node_Id := Type_Definition (N);
12484 Iface_Def : Node_Id;
12485 Indic : constant Node_Id := Subtype_Indication (Def);
12486 Extension : constant Node_Id := Record_Extension_Part (Def);
12487 Parent_Node : Node_Id;
12488 Parent_Scope : Entity_Id;
12491 -- Start of processing for Derived_Type_Declaration
12494 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
12496 -- Ada 2005 (AI-251): In case of interface derivation check that the
12497 -- parent is also an interface.
12499 if Interface_Present (Def) then
12500 if not Is_Interface (Parent_Type) then
12501 Diagnose_Interface (Indic, Parent_Type);
12504 Parent_Node := Parent (Base_Type (Parent_Type));
12505 Iface_Def := Type_Definition (Parent_Node);
12507 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
12508 -- other limited interfaces.
12510 if Limited_Present (Def) then
12511 if Limited_Present (Iface_Def) then
12514 elsif Protected_Present (Iface_Def) then
12516 ("(Ada 2005) limited interface cannot "
12517 & "inherit from protected interface", Indic);
12519 elsif Synchronized_Present (Iface_Def) then
12521 ("(Ada 2005) limited interface cannot "
12522 & "inherit from synchronized interface", Indic);
12524 elsif Task_Present (Iface_Def) then
12526 ("(Ada 2005) limited interface cannot "
12527 & "inherit from task interface", Indic);
12531 ("(Ada 2005) limited interface cannot "
12532 & "inherit from non-limited interface", Indic);
12535 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
12536 -- from non-limited or limited interfaces.
12538 elsif not Protected_Present (Def)
12539 and then not Synchronized_Present (Def)
12540 and then not Task_Present (Def)
12542 if Limited_Present (Iface_Def) then
12545 elsif Protected_Present (Iface_Def) then
12547 ("(Ada 2005) non-limited interface cannot "
12548 & "inherit from protected interface", Indic);
12550 elsif Synchronized_Present (Iface_Def) then
12552 ("(Ada 2005) non-limited interface cannot "
12553 & "inherit from synchronized interface", Indic);
12555 elsif Task_Present (Iface_Def) then
12557 ("(Ada 2005) non-limited interface cannot "
12558 & "inherit from task interface", Indic);
12567 if Is_Tagged_Type (Parent_Type)
12568 and then Is_Concurrent_Type (Parent_Type)
12569 and then not Is_Interface (Parent_Type)
12572 ("parent type of a record extension cannot be "
12573 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
12574 Set_Etype (T, Any_Type);
12578 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
12581 if Is_Tagged_Type (Parent_Type)
12582 and then Is_Non_Empty_List (Interface_List (Def))
12589 Intf := First (Interface_List (Def));
12590 while Present (Intf) loop
12591 T := Find_Type_Of_Subtype_Indic (Intf);
12593 if not Is_Interface (T) then
12594 Diagnose_Interface (Intf, T);
12596 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
12597 -- a limited type from having a nonlimited progenitor.
12599 elsif (Limited_Present (Def)
12600 or else (not Is_Interface (Parent_Type)
12601 and then Is_Limited_Type (Parent_Type)))
12602 and then not Is_Limited_Interface (T)
12605 ("progenitor interface& of limited type must be limited",
12614 if Parent_Type = Any_Type
12615 or else Etype (Parent_Type) = Any_Type
12616 or else (Is_Class_Wide_Type (Parent_Type)
12617 and then Etype (Parent_Type) = T)
12619 -- If Parent_Type is undefined or illegal, make new type into a
12620 -- subtype of Any_Type, and set a few attributes to prevent cascaded
12621 -- errors. If this is a self-definition, emit error now.
12624 or else T = Etype (Parent_Type)
12626 Error_Msg_N ("type cannot be used in its own definition", Indic);
12629 Set_Ekind (T, Ekind (Parent_Type));
12630 Set_Etype (T, Any_Type);
12631 Set_Scalar_Range (T, Scalar_Range (Any_Type));
12633 if Is_Tagged_Type (T) then
12634 Set_Primitive_Operations (T, New_Elmt_List);
12640 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
12641 -- an interface is special because the list of interfaces in the full
12642 -- view can be given in any order. For example:
12644 -- type A is interface;
12645 -- type B is interface and A;
12646 -- type D is new B with private;
12648 -- type D is new A and B with null record; -- 1 --
12650 -- In this case we perform the following transformation of -1-:
12652 -- type D is new B and A with null record;
12654 -- If the parent of the full-view covers the parent of the partial-view
12655 -- we have two possible cases:
12657 -- 1) They have the same parent
12658 -- 2) The parent of the full-view implements some further interfaces
12660 -- In both cases we do not need to perform the transformation. In the
12661 -- first case the source program is correct and the transformation is
12662 -- not needed; in the second case the source program does not fulfill
12663 -- the no-hidden interfaces rule (AI-396) and the error will be reported
12666 -- This transformation not only simplifies the rest of the analysis of
12667 -- this type declaration but also simplifies the correct generation of
12668 -- the object layout to the expander.
12670 if In_Private_Part (Current_Scope)
12671 and then Is_Interface (Parent_Type)
12675 Partial_View : Entity_Id;
12676 Partial_View_Parent : Entity_Id;
12677 New_Iface : Node_Id;
12680 -- Look for the associated private type declaration
12682 Partial_View := First_Entity (Current_Scope);
12684 exit when No (Partial_View)
12685 or else (Has_Private_Declaration (Partial_View)
12686 and then Full_View (Partial_View) = T);
12688 Next_Entity (Partial_View);
12691 -- If the partial view was not found then the source code has
12692 -- errors and the transformation is not needed.
12694 if Present (Partial_View) then
12695 Partial_View_Parent := Etype (Partial_View);
12697 -- If the parent of the full-view covers the parent of the
12698 -- partial-view we have nothing else to do.
12700 if Interface_Present_In_Ancestor
12701 (Parent_Type, Partial_View_Parent)
12705 -- Traverse the list of interfaces of the full-view to look
12706 -- for the parent of the partial-view and perform the tree
12710 Iface := First (Interface_List (Def));
12711 while Present (Iface) loop
12712 if Etype (Iface) = Etype (Partial_View) then
12713 Rewrite (Subtype_Indication (Def),
12714 New_Copy (Subtype_Indication
12715 (Parent (Partial_View))));
12717 New_Iface := Make_Identifier (Sloc (N),
12718 Chars (Parent_Type));
12719 Append (New_Iface, Interface_List (Def));
12721 -- Analyze the transformed code
12723 Derived_Type_Declaration (T, N, Is_Completion);
12734 -- Only composite types other than array types are allowed to have
12737 if Present (Discriminant_Specifications (N))
12738 and then (Is_Elementary_Type (Parent_Type)
12739 or else Is_Array_Type (Parent_Type))
12740 and then not Error_Posted (N)
12743 ("elementary or array type cannot have discriminants",
12744 Defining_Identifier (First (Discriminant_Specifications (N))));
12745 Set_Has_Discriminants (T, False);
12748 -- In Ada 83, a derived type defined in a package specification cannot
12749 -- be used for further derivation until the end of its visible part.
12750 -- Note that derivation in the private part of the package is allowed.
12752 if Ada_Version = Ada_83
12753 and then Is_Derived_Type (Parent_Type)
12754 and then In_Visible_Part (Scope (Parent_Type))
12756 if Ada_Version = Ada_83 and then Comes_From_Source (Indic) then
12758 ("(Ada 83): premature use of type for derivation", Indic);
12762 -- Check for early use of incomplete or private type
12764 if Ekind (Parent_Type) = E_Void
12765 or else Ekind (Parent_Type) = E_Incomplete_Type
12767 Error_Msg_N ("premature derivation of incomplete type", Indic);
12770 elsif (Is_Incomplete_Or_Private_Type (Parent_Type)
12771 and then not Comes_From_Generic (Parent_Type))
12772 or else Has_Private_Component (Parent_Type)
12774 -- The ancestor type of a formal type can be incomplete, in which
12775 -- case only the operations of the partial view are available in
12776 -- the generic. Subsequent checks may be required when the full
12777 -- view is analyzed, to verify that derivation from a tagged type
12778 -- has an extension.
12780 if Nkind (Original_Node (N)) = N_Formal_Type_Declaration then
12783 elsif No (Underlying_Type (Parent_Type))
12784 or else Has_Private_Component (Parent_Type)
12787 ("premature derivation of derived or private type", Indic);
12789 -- Flag the type itself as being in error, this prevents some
12790 -- nasty problems with subsequent uses of the malformed type.
12792 Set_Error_Posted (T);
12794 -- Check that within the immediate scope of an untagged partial
12795 -- view it's illegal to derive from the partial view if the
12796 -- full view is tagged. (7.3(7))
12798 -- We verify that the Parent_Type is a partial view by checking
12799 -- that it is not a Full_Type_Declaration (i.e. a private type or
12800 -- private extension declaration), to distinguish a partial view
12801 -- from a derivation from a private type which also appears as
12804 elsif Present (Full_View (Parent_Type))
12805 and then Nkind (Parent (Parent_Type)) /= N_Full_Type_Declaration
12806 and then not Is_Tagged_Type (Parent_Type)
12807 and then Is_Tagged_Type (Full_View (Parent_Type))
12809 Parent_Scope := Scope (T);
12810 while Present (Parent_Scope)
12811 and then Parent_Scope /= Standard_Standard
12813 if Parent_Scope = Scope (Parent_Type) then
12815 ("premature derivation from type with tagged full view",
12819 Parent_Scope := Scope (Parent_Scope);
12824 -- Check that form of derivation is appropriate
12826 Taggd := Is_Tagged_Type (Parent_Type);
12828 -- Perhaps the parent type should be changed to the class-wide type's
12829 -- specific type in this case to prevent cascading errors ???
12831 if Present (Extension) and then Is_Class_Wide_Type (Parent_Type) then
12832 Error_Msg_N ("parent type must not be a class-wide type", Indic);
12836 if Present (Extension) and then not Taggd then
12838 ("type derived from untagged type cannot have extension", Indic);
12840 elsif No (Extension) and then Taggd then
12842 -- If this declaration is within a private part (or body) of a
12843 -- generic instantiation then the derivation is allowed (the parent
12844 -- type can only appear tagged in this case if it's a generic actual
12845 -- type, since it would otherwise have been rejected in the analysis
12846 -- of the generic template).
12848 if not Is_Generic_Actual_Type (Parent_Type)
12849 or else In_Visible_Part (Scope (Parent_Type))
12852 ("type derived from tagged type must have extension", Indic);
12856 -- AI-443: Synchronized formal derived types require a private
12857 -- extension. There is no point in checking the ancestor type or
12858 -- the progenitors since the construct is wrong to begin with.
12860 if Ada_Version >= Ada_05
12861 and then Is_Generic_Type (T)
12862 and then Present (Original_Node (N))
12865 Decl : constant Node_Id := Original_Node (N);
12868 if Nkind (Decl) = N_Formal_Type_Declaration
12869 and then Nkind (Formal_Type_Definition (Decl)) =
12870 N_Formal_Derived_Type_Definition
12871 and then Synchronized_Present (Formal_Type_Definition (Decl))
12872 and then No (Extension)
12874 -- Avoid emitting a duplicate error message
12876 and then not Error_Posted (Indic)
12879 ("synchronized derived type must have extension", N);
12884 Build_Derived_Type (N, Parent_Type, T, Is_Completion);
12886 -- AI-419: The parent type of an explicitly limited derived type must
12887 -- be a limited type or a limited interface.
12889 if Limited_Present (Def) then
12890 Set_Is_Limited_Record (T);
12892 if Is_Interface (T) then
12893 Set_Is_Limited_Interface (T);
12896 if not Is_Limited_Type (Parent_Type)
12898 (not Is_Interface (Parent_Type)
12899 or else not Is_Limited_Interface (Parent_Type))
12901 Error_Msg_NE ("parent type& of limited type must be limited",
12905 end Derived_Type_Declaration;
12907 ------------------------
12908 -- Diagnose_Interface --
12909 ------------------------
12911 procedure Diagnose_Interface (N : Node_Id; E : Entity_Id) is
12913 if not Is_Interface (E)
12914 and then E /= Any_Type
12916 Error_Msg_NE ("(Ada 2005) & must be an interface", N, E);
12918 end Diagnose_Interface;
12920 ----------------------------------
12921 -- Enumeration_Type_Declaration --
12922 ----------------------------------
12924 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id) is
12931 -- Create identifier node representing lower bound
12933 B_Node := New_Node (N_Identifier, Sloc (Def));
12934 L := First (Literals (Def));
12935 Set_Chars (B_Node, Chars (L));
12936 Set_Entity (B_Node, L);
12937 Set_Etype (B_Node, T);
12938 Set_Is_Static_Expression (B_Node, True);
12940 R_Node := New_Node (N_Range, Sloc (Def));
12941 Set_Low_Bound (R_Node, B_Node);
12943 Set_Ekind (T, E_Enumeration_Type);
12944 Set_First_Literal (T, L);
12946 Set_Is_Constrained (T);
12950 -- Loop through literals of enumeration type setting pos and rep values
12951 -- except that if the Ekind is already set, then it means that the
12952 -- literal was already constructed (case of a derived type declaration
12953 -- and we should not disturb the Pos and Rep values.
12955 while Present (L) loop
12956 if Ekind (L) /= E_Enumeration_Literal then
12957 Set_Ekind (L, E_Enumeration_Literal);
12958 Set_Enumeration_Pos (L, Ev);
12959 Set_Enumeration_Rep (L, Ev);
12960 Set_Is_Known_Valid (L, True);
12964 New_Overloaded_Entity (L);
12965 Generate_Definition (L);
12966 Set_Convention (L, Convention_Intrinsic);
12968 if Nkind (L) = N_Defining_Character_Literal then
12969 Set_Is_Character_Type (T, True);
12976 -- Now create a node representing upper bound
12978 B_Node := New_Node (N_Identifier, Sloc (Def));
12979 Set_Chars (B_Node, Chars (Last (Literals (Def))));
12980 Set_Entity (B_Node, Last (Literals (Def)));
12981 Set_Etype (B_Node, T);
12982 Set_Is_Static_Expression (B_Node, True);
12984 Set_High_Bound (R_Node, B_Node);
12986 -- Initialize various fields of the type. Some of this information
12987 -- may be overwritten later through rep.clauses.
12989 Set_Scalar_Range (T, R_Node);
12990 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
12991 Set_Enum_Esize (T);
12992 Set_Enum_Pos_To_Rep (T, Empty);
12994 -- Set Discard_Names if configuration pragma set, or if there is
12995 -- a parameterless pragma in the current declarative region
12997 if Global_Discard_Names
12998 or else Discard_Names (Scope (T))
13000 Set_Discard_Names (T);
13003 -- Process end label if there is one
13005 if Present (Def) then
13006 Process_End_Label (Def, 'e', T);
13008 end Enumeration_Type_Declaration;
13010 ---------------------------------
13011 -- Expand_To_Stored_Constraint --
13012 ---------------------------------
13014 function Expand_To_Stored_Constraint
13016 Constraint : Elist_Id) return Elist_Id
13018 Explicitly_Discriminated_Type : Entity_Id;
13019 Expansion : Elist_Id;
13020 Discriminant : Entity_Id;
13022 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id;
13023 -- Find the nearest type that actually specifies discriminants
13025 ---------------------------------
13026 -- Type_With_Explicit_Discrims --
13027 ---------------------------------
13029 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id is
13030 Typ : constant E := Base_Type (Id);
13033 if Ekind (Typ) in Incomplete_Or_Private_Kind then
13034 if Present (Full_View (Typ)) then
13035 return Type_With_Explicit_Discrims (Full_View (Typ));
13039 if Has_Discriminants (Typ) then
13044 if Etype (Typ) = Typ then
13046 elsif Has_Discriminants (Typ) then
13049 return Type_With_Explicit_Discrims (Etype (Typ));
13052 end Type_With_Explicit_Discrims;
13054 -- Start of processing for Expand_To_Stored_Constraint
13058 or else Is_Empty_Elmt_List (Constraint)
13063 Explicitly_Discriminated_Type := Type_With_Explicit_Discrims (Typ);
13065 if No (Explicitly_Discriminated_Type) then
13069 Expansion := New_Elmt_List;
13072 First_Stored_Discriminant (Explicitly_Discriminated_Type);
13073 while Present (Discriminant) loop
13075 Get_Discriminant_Value (
13076 Discriminant, Explicitly_Discriminated_Type, Constraint),
13078 Next_Stored_Discriminant (Discriminant);
13082 end Expand_To_Stored_Constraint;
13084 ---------------------------
13085 -- Find_Hidden_Interface --
13086 ---------------------------
13088 function Find_Hidden_Interface
13090 Dest : Elist_Id) return Entity_Id
13093 Iface_Elmt : Elmt_Id;
13096 if Present (Src) and then Present (Dest) then
13097 Iface_Elmt := First_Elmt (Src);
13098 while Present (Iface_Elmt) loop
13099 Iface := Node (Iface_Elmt);
13101 if Is_Interface (Iface)
13102 and then not Contain_Interface (Iface, Dest)
13107 Next_Elmt (Iface_Elmt);
13112 end Find_Hidden_Interface;
13114 --------------------
13115 -- Find_Type_Name --
13116 --------------------
13118 function Find_Type_Name (N : Node_Id) return Entity_Id is
13119 Id : constant Entity_Id := Defining_Identifier (N);
13121 New_Id : Entity_Id;
13122 Prev_Par : Node_Id;
13124 procedure Tag_Mismatch;
13125 -- Diagnose a tagged partial view whose full view is untagged.
13126 -- We post the message on the full view, with a reference to
13127 -- the previous partial view. The partial view can be private
13128 -- or incomplete, and these are handled in a different manner,
13129 -- so we determine the position of the error message from the
13130 -- respective slocs of both.
13136 procedure Tag_Mismatch is
13138 if Sloc (Prev) < Sloc (Id) then
13140 ("full declaration of } must be a tagged type ", Id, Prev);
13143 ("full declaration of } must be a tagged type ", Prev, Id);
13147 -- Start processing for Find_Type_Name
13150 -- Find incomplete declaration, if one was given
13152 Prev := Current_Entity_In_Scope (Id);
13154 if Present (Prev) then
13156 -- Previous declaration exists. Error if not incomplete/private case
13157 -- except if previous declaration is implicit, etc. Enter_Name will
13158 -- emit error if appropriate.
13160 Prev_Par := Parent (Prev);
13162 if not Is_Incomplete_Or_Private_Type (Prev) then
13166 elsif not Nkind_In (N, N_Full_Type_Declaration,
13167 N_Task_Type_Declaration,
13168 N_Protected_Type_Declaration)
13170 -- Completion must be a full type declarations (RM 7.3(4))
13172 Error_Msg_Sloc := Sloc (Prev);
13173 Error_Msg_NE ("invalid completion of }", Id, Prev);
13175 -- Set scope of Id to avoid cascaded errors. Entity is never
13176 -- examined again, except when saving globals in generics.
13178 Set_Scope (Id, Current_Scope);
13181 -- Case of full declaration of incomplete type
13183 elsif Ekind (Prev) = E_Incomplete_Type then
13185 -- Indicate that the incomplete declaration has a matching full
13186 -- declaration. The defining occurrence of the incomplete
13187 -- declaration remains the visible one, and the procedure
13188 -- Get_Full_View dereferences it whenever the type is used.
13190 if Present (Full_View (Prev)) then
13191 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
13194 Set_Full_View (Prev, Id);
13195 Append_Entity (Id, Current_Scope);
13196 Set_Is_Public (Id, Is_Public (Prev));
13197 Set_Is_Internal (Id);
13200 -- Case of full declaration of private type
13203 if Nkind (Parent (Prev)) /= N_Private_Extension_Declaration then
13204 if Etype (Prev) /= Prev then
13206 -- Prev is a private subtype or a derived type, and needs
13209 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
13212 elsif Ekind (Prev) = E_Private_Type
13213 and then Nkind_In (N, N_Task_Type_Declaration,
13214 N_Protected_Type_Declaration)
13217 ("completion of nonlimited type cannot be limited", N);
13219 elsif Ekind (Prev) = E_Record_Type_With_Private
13220 and then Nkind_In (N, N_Task_Type_Declaration,
13221 N_Protected_Type_Declaration)
13223 if not Is_Limited_Record (Prev) then
13225 ("completion of nonlimited type cannot be limited", N);
13227 elsif No (Interface_List (N)) then
13229 ("completion of tagged private type must be tagged",
13234 -- Ada 2005 (AI-251): Private extension declaration of a task
13235 -- type or a protected type. This case arises when covering
13236 -- interface types.
13238 elsif Nkind_In (N, N_Task_Type_Declaration,
13239 N_Protected_Type_Declaration)
13243 elsif Nkind (N) /= N_Full_Type_Declaration
13244 or else Nkind (Type_Definition (N)) /= N_Derived_Type_Definition
13247 ("full view of private extension must be an extension", N);
13249 elsif not (Abstract_Present (Parent (Prev)))
13250 and then Abstract_Present (Type_Definition (N))
13253 ("full view of non-abstract extension cannot be abstract", N);
13256 if not In_Private_Part (Current_Scope) then
13258 ("declaration of full view must appear in private part", N);
13261 Copy_And_Swap (Prev, Id);
13262 Set_Has_Private_Declaration (Prev);
13263 Set_Has_Private_Declaration (Id);
13265 -- If no error, propagate freeze_node from private to full view.
13266 -- It may have been generated for an early operational item.
13268 if Present (Freeze_Node (Id))
13269 and then Serious_Errors_Detected = 0
13270 and then No (Full_View (Id))
13272 Set_Freeze_Node (Prev, Freeze_Node (Id));
13273 Set_Freeze_Node (Id, Empty);
13274 Set_First_Rep_Item (Prev, First_Rep_Item (Id));
13277 Set_Full_View (Id, Prev);
13281 -- Verify that full declaration conforms to partial one
13283 if Is_Incomplete_Or_Private_Type (Prev)
13284 and then Present (Discriminant_Specifications (Prev_Par))
13286 if Present (Discriminant_Specifications (N)) then
13287 if Ekind (Prev) = E_Incomplete_Type then
13288 Check_Discriminant_Conformance (N, Prev, Prev);
13290 Check_Discriminant_Conformance (N, Prev, Id);
13295 ("missing discriminants in full type declaration", N);
13297 -- To avoid cascaded errors on subsequent use, share the
13298 -- discriminants of the partial view.
13300 Set_Discriminant_Specifications (N,
13301 Discriminant_Specifications (Prev_Par));
13305 -- A prior untagged partial view can have an associated class-wide
13306 -- type due to use of the class attribute, and in this case the full
13307 -- type must also be tagged. This Ada 95 usage is deprecated in favor
13308 -- of incomplete tagged declarations, but we check for it.
13311 and then (Is_Tagged_Type (Prev)
13312 or else Present (Class_Wide_Type (Prev)))
13314 -- The full declaration is either a tagged type (including
13315 -- a synchronized type that implements interfaces) or a
13316 -- type extension, otherwise this is an error.
13318 if Nkind_In (N, N_Task_Type_Declaration,
13319 N_Protected_Type_Declaration)
13321 if No (Interface_List (N))
13322 and then not Error_Posted (N)
13327 elsif Nkind (Type_Definition (N)) = N_Record_Definition then
13329 -- Indicate that the previous declaration (tagged incomplete
13330 -- or private declaration) requires the same on the full one.
13332 if not Tagged_Present (Type_Definition (N)) then
13334 Set_Is_Tagged_Type (Id);
13335 Set_Primitive_Operations (Id, New_Elmt_List);
13338 elsif Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
13339 if No (Record_Extension_Part (Type_Definition (N))) then
13341 "full declaration of } must be a record extension",
13343 Set_Is_Tagged_Type (Id);
13344 Set_Primitive_Operations (Id, New_Elmt_List);
13355 -- New type declaration
13360 end Find_Type_Name;
13362 -------------------------
13363 -- Find_Type_Of_Object --
13364 -------------------------
13366 function Find_Type_Of_Object
13367 (Obj_Def : Node_Id;
13368 Related_Nod : Node_Id) return Entity_Id
13370 Def_Kind : constant Node_Kind := Nkind (Obj_Def);
13371 P : Node_Id := Parent (Obj_Def);
13376 -- If the parent is a component_definition node we climb to the
13377 -- component_declaration node
13379 if Nkind (P) = N_Component_Definition then
13383 -- Case of an anonymous array subtype
13385 if Nkind_In (Def_Kind, N_Constrained_Array_Definition,
13386 N_Unconstrained_Array_Definition)
13389 Array_Type_Declaration (T, Obj_Def);
13391 -- Create an explicit subtype whenever possible
13393 elsif Nkind (P) /= N_Component_Declaration
13394 and then Def_Kind = N_Subtype_Indication
13396 -- Base name of subtype on object name, which will be unique in
13397 -- the current scope.
13399 -- If this is a duplicate declaration, return base type, to avoid
13400 -- generating duplicate anonymous types.
13402 if Error_Posted (P) then
13403 Analyze (Subtype_Mark (Obj_Def));
13404 return Entity (Subtype_Mark (Obj_Def));
13409 (Chars (Defining_Identifier (Related_Nod)), 'S', 0, 'T');
13411 T := Make_Defining_Identifier (Sloc (P), Nam);
13413 Insert_Action (Obj_Def,
13414 Make_Subtype_Declaration (Sloc (P),
13415 Defining_Identifier => T,
13416 Subtype_Indication => Relocate_Node (Obj_Def)));
13418 -- This subtype may need freezing, and this will not be done
13419 -- automatically if the object declaration is not in declarative
13420 -- part. Since this is an object declaration, the type cannot always
13421 -- be frozen here. Deferred constants do not freeze their type
13422 -- (which often enough will be private).
13424 if Nkind (P) = N_Object_Declaration
13425 and then Constant_Present (P)
13426 and then No (Expression (P))
13430 Insert_Actions (Obj_Def, Freeze_Entity (T, Sloc (P)));
13433 -- Ada 2005 AI-406: the object definition in an object declaration
13434 -- can be an access definition.
13436 elsif Def_Kind = N_Access_Definition then
13437 T := Access_Definition (Related_Nod, Obj_Def);
13438 Set_Is_Local_Anonymous_Access (T);
13440 -- Otherwise, the object definition is just a subtype_mark
13443 T := Process_Subtype (Obj_Def, Related_Nod);
13447 end Find_Type_Of_Object;
13449 --------------------------------
13450 -- Find_Type_Of_Subtype_Indic --
13451 --------------------------------
13453 function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id is
13457 -- Case of subtype mark with a constraint
13459 if Nkind (S) = N_Subtype_Indication then
13460 Find_Type (Subtype_Mark (S));
13461 Typ := Entity (Subtype_Mark (S));
13464 Is_Valid_Constraint_Kind (Ekind (Typ), Nkind (Constraint (S)))
13467 ("incorrect constraint for this kind of type", Constraint (S));
13468 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
13471 -- Otherwise we have a subtype mark without a constraint
13473 elsif Error_Posted (S) then
13474 Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S)));
13482 -- Check No_Wide_Characters restriction
13484 if Typ = Standard_Wide_Character
13485 or else Typ = Standard_Wide_Wide_Character
13486 or else Typ = Standard_Wide_String
13487 or else Typ = Standard_Wide_Wide_String
13489 Check_Restriction (No_Wide_Characters, S);
13493 end Find_Type_Of_Subtype_Indic;
13495 -------------------------------------
13496 -- Floating_Point_Type_Declaration --
13497 -------------------------------------
13499 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is
13500 Digs : constant Node_Id := Digits_Expression (Def);
13502 Base_Typ : Entity_Id;
13503 Implicit_Base : Entity_Id;
13506 function Can_Derive_From (E : Entity_Id) return Boolean;
13507 -- Find if given digits value allows derivation from specified type
13509 ---------------------
13510 -- Can_Derive_From --
13511 ---------------------
13513 function Can_Derive_From (E : Entity_Id) return Boolean is
13514 Spec : constant Entity_Id := Real_Range_Specification (Def);
13517 if Digs_Val > Digits_Value (E) then
13521 if Present (Spec) then
13522 if Expr_Value_R (Type_Low_Bound (E)) >
13523 Expr_Value_R (Low_Bound (Spec))
13528 if Expr_Value_R (Type_High_Bound (E)) <
13529 Expr_Value_R (High_Bound (Spec))
13536 end Can_Derive_From;
13538 -- Start of processing for Floating_Point_Type_Declaration
13541 Check_Restriction (No_Floating_Point, Def);
13543 -- Create an implicit base type
13546 Create_Itype (E_Floating_Point_Type, Parent (Def), T, 'B');
13548 -- Analyze and verify digits value
13550 Analyze_And_Resolve (Digs, Any_Integer);
13551 Check_Digits_Expression (Digs);
13552 Digs_Val := Expr_Value (Digs);
13554 -- Process possible range spec and find correct type to derive from
13556 Process_Real_Range_Specification (Def);
13558 if Can_Derive_From (Standard_Short_Float) then
13559 Base_Typ := Standard_Short_Float;
13560 elsif Can_Derive_From (Standard_Float) then
13561 Base_Typ := Standard_Float;
13562 elsif Can_Derive_From (Standard_Long_Float) then
13563 Base_Typ := Standard_Long_Float;
13564 elsif Can_Derive_From (Standard_Long_Long_Float) then
13565 Base_Typ := Standard_Long_Long_Float;
13567 -- If we can't derive from any existing type, use long_long_float
13568 -- and give appropriate message explaining the problem.
13571 Base_Typ := Standard_Long_Long_Float;
13573 if Digs_Val >= Digits_Value (Standard_Long_Long_Float) then
13574 Error_Msg_Uint_1 := Digits_Value (Standard_Long_Long_Float);
13575 Error_Msg_N ("digits value out of range, maximum is ^", Digs);
13579 ("range too large for any predefined type",
13580 Real_Range_Specification (Def));
13584 -- If there are bounds given in the declaration use them as the bounds
13585 -- of the type, otherwise use the bounds of the predefined base type
13586 -- that was chosen based on the Digits value.
13588 if Present (Real_Range_Specification (Def)) then
13589 Set_Scalar_Range (T, Real_Range_Specification (Def));
13590 Set_Is_Constrained (T);
13592 -- The bounds of this range must be converted to machine numbers
13593 -- in accordance with RM 4.9(38).
13595 Bound := Type_Low_Bound (T);
13597 if Nkind (Bound) = N_Real_Literal then
13599 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13600 Set_Is_Machine_Number (Bound);
13603 Bound := Type_High_Bound (T);
13605 if Nkind (Bound) = N_Real_Literal then
13607 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13608 Set_Is_Machine_Number (Bound);
13612 Set_Scalar_Range (T, Scalar_Range (Base_Typ));
13615 -- Complete definition of implicit base and declared first subtype
13617 Set_Etype (Implicit_Base, Base_Typ);
13619 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
13620 Set_Size_Info (Implicit_Base, (Base_Typ));
13621 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
13622 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
13623 Set_Digits_Value (Implicit_Base, Digits_Value (Base_Typ));
13624 Set_Vax_Float (Implicit_Base, Vax_Float (Base_Typ));
13626 Set_Ekind (T, E_Floating_Point_Subtype);
13627 Set_Etype (T, Implicit_Base);
13629 Set_Size_Info (T, (Implicit_Base));
13630 Set_RM_Size (T, RM_Size (Implicit_Base));
13631 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
13632 Set_Digits_Value (T, Digs_Val);
13633 end Floating_Point_Type_Declaration;
13635 ----------------------------
13636 -- Get_Discriminant_Value --
13637 ----------------------------
13639 -- This is the situation:
13641 -- There is a non-derived type
13643 -- type T0 (Dx, Dy, Dz...)
13645 -- There are zero or more levels of derivation, with each derivation
13646 -- either purely inheriting the discriminants, or defining its own.
13648 -- type Ti is new Ti-1
13650 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
13652 -- subtype Ti is ...
13654 -- The subtype issue is avoided by the use of Original_Record_Component,
13655 -- and the fact that derived subtypes also derive the constraints.
13657 -- This chain leads back from
13659 -- Typ_For_Constraint
13661 -- Typ_For_Constraint has discriminants, and the value for each
13662 -- discriminant is given by its corresponding Elmt of Constraints.
13664 -- Discriminant is some discriminant in this hierarchy
13666 -- We need to return its value
13668 -- We do this by recursively searching each level, and looking for
13669 -- Discriminant. Once we get to the bottom, we start backing up
13670 -- returning the value for it which may in turn be a discriminant
13671 -- further up, so on the backup we continue the substitution.
13673 function Get_Discriminant_Value
13674 (Discriminant : Entity_Id;
13675 Typ_For_Constraint : Entity_Id;
13676 Constraint : Elist_Id) return Node_Id
13678 function Search_Derivation_Levels
13680 Discrim_Values : Elist_Id;
13681 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id;
13682 -- This is the routine that performs the recursive search of levels
13683 -- as described above.
13685 ------------------------------
13686 -- Search_Derivation_Levels --
13687 ------------------------------
13689 function Search_Derivation_Levels
13691 Discrim_Values : Elist_Id;
13692 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id
13696 Result : Node_Or_Entity_Id;
13697 Result_Entity : Node_Id;
13700 -- If inappropriate type, return Error, this happens only in
13701 -- cascaded error situations, and we want to avoid a blow up.
13703 if not Is_Composite_Type (Ti) or else Is_Array_Type (Ti) then
13707 -- Look deeper if possible. Use Stored_Constraints only for
13708 -- untagged types. For tagged types use the given constraint.
13709 -- This asymmetry needs explanation???
13711 if not Stored_Discrim_Values
13712 and then Present (Stored_Constraint (Ti))
13713 and then not Is_Tagged_Type (Ti)
13716 Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True);
13719 Td : constant Entity_Id := Etype (Ti);
13723 Result := Discriminant;
13726 if Present (Stored_Constraint (Ti)) then
13728 Search_Derivation_Levels
13729 (Td, Stored_Constraint (Ti), True);
13732 Search_Derivation_Levels
13733 (Td, Discrim_Values, Stored_Discrim_Values);
13739 -- Extra underlying places to search, if not found above. For
13740 -- concurrent types, the relevant discriminant appears in the
13741 -- corresponding record. For a type derived from a private type
13742 -- without discriminant, the full view inherits the discriminants
13743 -- of the full view of the parent.
13745 if Result = Discriminant then
13746 if Is_Concurrent_Type (Ti)
13747 and then Present (Corresponding_Record_Type (Ti))
13750 Search_Derivation_Levels (
13751 Corresponding_Record_Type (Ti),
13753 Stored_Discrim_Values);
13755 elsif Is_Private_Type (Ti)
13756 and then not Has_Discriminants (Ti)
13757 and then Present (Full_View (Ti))
13758 and then Etype (Full_View (Ti)) /= Ti
13761 Search_Derivation_Levels (
13764 Stored_Discrim_Values);
13768 -- If Result is not a (reference to a) discriminant, return it,
13769 -- otherwise set Result_Entity to the discriminant.
13771 if Nkind (Result) = N_Defining_Identifier then
13772 pragma Assert (Result = Discriminant);
13773 Result_Entity := Result;
13776 if not Denotes_Discriminant (Result) then
13780 Result_Entity := Entity (Result);
13783 -- See if this level of derivation actually has discriminants
13784 -- because tagged derivations can add them, hence the lower
13785 -- levels need not have any.
13787 if not Has_Discriminants (Ti) then
13791 -- Scan Ti's discriminants for Result_Entity,
13792 -- and return its corresponding value, if any.
13794 Result_Entity := Original_Record_Component (Result_Entity);
13796 Assoc := First_Elmt (Discrim_Values);
13798 if Stored_Discrim_Values then
13799 Disc := First_Stored_Discriminant (Ti);
13801 Disc := First_Discriminant (Ti);
13804 while Present (Disc) loop
13805 pragma Assert (Present (Assoc));
13807 if Original_Record_Component (Disc) = Result_Entity then
13808 return Node (Assoc);
13813 if Stored_Discrim_Values then
13814 Next_Stored_Discriminant (Disc);
13816 Next_Discriminant (Disc);
13820 -- Could not find it
13823 end Search_Derivation_Levels;
13827 Result : Node_Or_Entity_Id;
13829 -- Start of processing for Get_Discriminant_Value
13832 -- ??? This routine is a gigantic mess and will be deleted. For the
13833 -- time being just test for the trivial case before calling recurse.
13835 if Base_Type (Scope (Discriminant)) = Base_Type (Typ_For_Constraint) then
13841 D := First_Discriminant (Typ_For_Constraint);
13842 E := First_Elmt (Constraint);
13843 while Present (D) loop
13844 if Chars (D) = Chars (Discriminant) then
13848 Next_Discriminant (D);
13854 Result := Search_Derivation_Levels
13855 (Typ_For_Constraint, Constraint, False);
13857 -- ??? hack to disappear when this routine is gone
13859 if Nkind (Result) = N_Defining_Identifier then
13865 D := First_Discriminant (Typ_For_Constraint);
13866 E := First_Elmt (Constraint);
13867 while Present (D) loop
13868 if Corresponding_Discriminant (D) = Discriminant then
13872 Next_Discriminant (D);
13878 pragma Assert (Nkind (Result) /= N_Defining_Identifier);
13880 end Get_Discriminant_Value;
13882 --------------------------
13883 -- Has_Range_Constraint --
13884 --------------------------
13886 function Has_Range_Constraint (N : Node_Id) return Boolean is
13887 C : constant Node_Id := Constraint (N);
13890 if Nkind (C) = N_Range_Constraint then
13893 elsif Nkind (C) = N_Digits_Constraint then
13895 Is_Decimal_Fixed_Point_Type (Entity (Subtype_Mark (N)))
13897 Present (Range_Constraint (C));
13899 elsif Nkind (C) = N_Delta_Constraint then
13900 return Present (Range_Constraint (C));
13905 end Has_Range_Constraint;
13907 ------------------------
13908 -- Inherit_Components --
13909 ------------------------
13911 function Inherit_Components
13913 Parent_Base : Entity_Id;
13914 Derived_Base : Entity_Id;
13915 Is_Tagged : Boolean;
13916 Inherit_Discr : Boolean;
13917 Discs : Elist_Id) return Elist_Id
13919 Assoc_List : constant Elist_Id := New_Elmt_List;
13921 procedure Inherit_Component
13922 (Old_C : Entity_Id;
13923 Plain_Discrim : Boolean := False;
13924 Stored_Discrim : Boolean := False);
13925 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
13926 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
13927 -- True, Old_C is a stored discriminant. If they are both false then
13928 -- Old_C is a regular component.
13930 -----------------------
13931 -- Inherit_Component --
13932 -----------------------
13934 procedure Inherit_Component
13935 (Old_C : Entity_Id;
13936 Plain_Discrim : Boolean := False;
13937 Stored_Discrim : Boolean := False)
13939 New_C : constant Entity_Id := New_Copy (Old_C);
13941 Discrim : Entity_Id;
13942 Corr_Discrim : Entity_Id;
13945 pragma Assert (not Is_Tagged or else not Stored_Discrim);
13947 Set_Parent (New_C, Parent (Old_C));
13949 -- Regular discriminants and components must be inserted in the scope
13950 -- of the Derived_Base. Do it here.
13952 if not Stored_Discrim then
13953 Enter_Name (New_C);
13956 -- For tagged types the Original_Record_Component must point to
13957 -- whatever this field was pointing to in the parent type. This has
13958 -- already been achieved by the call to New_Copy above.
13960 if not Is_Tagged then
13961 Set_Original_Record_Component (New_C, New_C);
13964 -- If we have inherited a component then see if its Etype contains
13965 -- references to Parent_Base discriminants. In this case, replace
13966 -- these references with the constraints given in Discs. We do not
13967 -- do this for the partial view of private types because this is
13968 -- not needed (only the components of the full view will be used
13969 -- for code generation) and cause problem. We also avoid this
13970 -- transformation in some error situations.
13972 if Ekind (New_C) = E_Component then
13973 if (Is_Private_Type (Derived_Base)
13974 and then not Is_Generic_Type (Derived_Base))
13975 or else (Is_Empty_Elmt_List (Discs)
13976 and then not Expander_Active)
13978 Set_Etype (New_C, Etype (Old_C));
13981 -- The current component introduces a circularity of the
13984 -- limited with Pack_2;
13985 -- package Pack_1 is
13986 -- type T_1 is tagged record
13987 -- Comp : access Pack_2.T_2;
13993 -- package Pack_2 is
13994 -- type T_2 is new Pack_1.T_1 with ...;
13999 Constrain_Component_Type
14000 (Old_C, Derived_Base, N, Parent_Base, Discs));
14004 -- In derived tagged types it is illegal to reference a non
14005 -- discriminant component in the parent type. To catch this, mark
14006 -- these components with an Ekind of E_Void. This will be reset in
14007 -- Record_Type_Definition after processing the record extension of
14008 -- the derived type.
14010 -- If the declaration is a private extension, there is no further
14011 -- record extension to process, and the components retain their
14012 -- current kind, because they are visible at this point.
14014 if Is_Tagged and then Ekind (New_C) = E_Component
14015 and then Nkind (N) /= N_Private_Extension_Declaration
14017 Set_Ekind (New_C, E_Void);
14020 if Plain_Discrim then
14021 Set_Corresponding_Discriminant (New_C, Old_C);
14022 Build_Discriminal (New_C);
14024 -- If we are explicitly inheriting a stored discriminant it will be
14025 -- completely hidden.
14027 elsif Stored_Discrim then
14028 Set_Corresponding_Discriminant (New_C, Empty);
14029 Set_Discriminal (New_C, Empty);
14030 Set_Is_Completely_Hidden (New_C);
14032 -- Set the Original_Record_Component of each discriminant in the
14033 -- derived base to point to the corresponding stored that we just
14036 Discrim := First_Discriminant (Derived_Base);
14037 while Present (Discrim) loop
14038 Corr_Discrim := Corresponding_Discriminant (Discrim);
14040 -- Corr_Discrim could be missing in an error situation
14042 if Present (Corr_Discrim)
14043 and then Original_Record_Component (Corr_Discrim) = Old_C
14045 Set_Original_Record_Component (Discrim, New_C);
14048 Next_Discriminant (Discrim);
14051 Append_Entity (New_C, Derived_Base);
14054 if not Is_Tagged then
14055 Append_Elmt (Old_C, Assoc_List);
14056 Append_Elmt (New_C, Assoc_List);
14058 end Inherit_Component;
14060 -- Variables local to Inherit_Component
14062 Loc : constant Source_Ptr := Sloc (N);
14064 Parent_Discrim : Entity_Id;
14065 Stored_Discrim : Entity_Id;
14067 Component : Entity_Id;
14069 -- Start of processing for Inherit_Components
14072 if not Is_Tagged then
14073 Append_Elmt (Parent_Base, Assoc_List);
14074 Append_Elmt (Derived_Base, Assoc_List);
14077 -- Inherit parent discriminants if needed
14079 if Inherit_Discr then
14080 Parent_Discrim := First_Discriminant (Parent_Base);
14081 while Present (Parent_Discrim) loop
14082 Inherit_Component (Parent_Discrim, Plain_Discrim => True);
14083 Next_Discriminant (Parent_Discrim);
14087 -- Create explicit stored discrims for untagged types when necessary
14089 if not Has_Unknown_Discriminants (Derived_Base)
14090 and then Has_Discriminants (Parent_Base)
14091 and then not Is_Tagged
14094 or else First_Discriminant (Parent_Base) /=
14095 First_Stored_Discriminant (Parent_Base))
14097 Stored_Discrim := First_Stored_Discriminant (Parent_Base);
14098 while Present (Stored_Discrim) loop
14099 Inherit_Component (Stored_Discrim, Stored_Discrim => True);
14100 Next_Stored_Discriminant (Stored_Discrim);
14104 -- See if we can apply the second transformation for derived types, as
14105 -- explained in point 6. in the comments above Build_Derived_Record_Type
14106 -- This is achieved by appending Derived_Base discriminants into Discs,
14107 -- which has the side effect of returning a non empty Discs list to the
14108 -- caller of Inherit_Components, which is what we want. This must be
14109 -- done for private derived types if there are explicit stored
14110 -- discriminants, to ensure that we can retrieve the values of the
14111 -- constraints provided in the ancestors.
14114 and then Is_Empty_Elmt_List (Discs)
14115 and then Present (First_Discriminant (Derived_Base))
14117 (not Is_Private_Type (Derived_Base)
14118 or else Is_Completely_Hidden
14119 (First_Stored_Discriminant (Derived_Base))
14120 or else Is_Generic_Type (Derived_Base))
14122 D := First_Discriminant (Derived_Base);
14123 while Present (D) loop
14124 Append_Elmt (New_Reference_To (D, Loc), Discs);
14125 Next_Discriminant (D);
14129 -- Finally, inherit non-discriminant components unless they are not
14130 -- visible because defined or inherited from the full view of the
14131 -- parent. Don't inherit the _parent field of the parent type.
14133 Component := First_Entity (Parent_Base);
14134 while Present (Component) loop
14136 -- Ada 2005 (AI-251): Do not inherit components associated with
14137 -- secondary tags of the parent.
14139 if Ekind (Component) = E_Component
14140 and then Present (Related_Type (Component))
14144 elsif Ekind (Component) /= E_Component
14145 or else Chars (Component) = Name_uParent
14149 -- If the derived type is within the parent type's declarative
14150 -- region, then the components can still be inherited even though
14151 -- they aren't visible at this point. This can occur for cases
14152 -- such as within public child units where the components must
14153 -- become visible upon entering the child unit's private part.
14155 elsif not Is_Visible_Component (Component)
14156 and then not In_Open_Scopes (Scope (Parent_Base))
14160 elsif Ekind (Derived_Base) = E_Private_Type
14161 or else Ekind (Derived_Base) = E_Limited_Private_Type
14166 Inherit_Component (Component);
14169 Next_Entity (Component);
14172 -- For tagged derived types, inherited discriminants cannot be used in
14173 -- component declarations of the record extension part. To achieve this
14174 -- we mark the inherited discriminants as not visible.
14176 if Is_Tagged and then Inherit_Discr then
14177 D := First_Discriminant (Derived_Base);
14178 while Present (D) loop
14179 Set_Is_Immediately_Visible (D, False);
14180 Next_Discriminant (D);
14185 end Inherit_Components;
14187 -----------------------
14188 -- Is_Null_Extension --
14189 -----------------------
14191 function Is_Null_Extension (T : Entity_Id) return Boolean is
14192 Type_Decl : constant Node_Id := Parent (T);
14193 Comp_List : Node_Id;
14197 if Nkind (Type_Decl) /= N_Full_Type_Declaration
14198 or else not Is_Tagged_Type (T)
14199 or else Nkind (Type_Definition (Type_Decl)) /=
14200 N_Derived_Type_Definition
14201 or else No (Record_Extension_Part (Type_Definition (Type_Decl)))
14207 Component_List (Record_Extension_Part (Type_Definition (Type_Decl)));
14209 if Present (Discriminant_Specifications (Type_Decl)) then
14212 elsif Present (Comp_List)
14213 and then Is_Non_Empty_List (Component_Items (Comp_List))
14215 Comp := First (Component_Items (Comp_List));
14217 -- Only user-defined components are relevant. The component list
14218 -- may also contain a parent component and internal components
14219 -- corresponding to secondary tags, but these do not determine
14220 -- whether this is a null extension.
14222 while Present (Comp) loop
14223 if Comes_From_Source (Comp) then
14234 end Is_Null_Extension;
14236 --------------------
14237 -- Is_Progenitor --
14238 --------------------
14240 function Is_Progenitor
14241 (Iface : Entity_Id;
14242 Typ : Entity_Id) return Boolean
14245 return Implements_Interface (Typ, Iface,
14246 Exclude_Parents => True);
14249 ------------------------------
14250 -- Is_Valid_Constraint_Kind --
14251 ------------------------------
14253 function Is_Valid_Constraint_Kind
14254 (T_Kind : Type_Kind;
14255 Constraint_Kind : Node_Kind) return Boolean
14259 when Enumeration_Kind |
14261 return Constraint_Kind = N_Range_Constraint;
14263 when Decimal_Fixed_Point_Kind =>
14264 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14265 N_Range_Constraint);
14267 when Ordinary_Fixed_Point_Kind =>
14268 return Nkind_In (Constraint_Kind, N_Delta_Constraint,
14269 N_Range_Constraint);
14272 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14273 N_Range_Constraint);
14280 E_Incomplete_Type |
14283 return Constraint_Kind = N_Index_Or_Discriminant_Constraint;
14286 return True; -- Error will be detected later
14288 end Is_Valid_Constraint_Kind;
14290 --------------------------
14291 -- Is_Visible_Component --
14292 --------------------------
14294 function Is_Visible_Component (C : Entity_Id) return Boolean is
14295 Original_Comp : Entity_Id := Empty;
14296 Original_Scope : Entity_Id;
14297 Type_Scope : Entity_Id;
14299 function Is_Local_Type (Typ : Entity_Id) return Boolean;
14300 -- Check whether parent type of inherited component is declared locally,
14301 -- possibly within a nested package or instance. The current scope is
14302 -- the derived record itself.
14304 -------------------
14305 -- Is_Local_Type --
14306 -------------------
14308 function Is_Local_Type (Typ : Entity_Id) return Boolean is
14312 Scop := Scope (Typ);
14313 while Present (Scop)
14314 and then Scop /= Standard_Standard
14316 if Scop = Scope (Current_Scope) then
14320 Scop := Scope (Scop);
14326 -- Start of processing for Is_Visible_Component
14329 if Ekind (C) = E_Component
14330 or else Ekind (C) = E_Discriminant
14332 Original_Comp := Original_Record_Component (C);
14335 if No (Original_Comp) then
14337 -- Premature usage, or previous error
14342 Original_Scope := Scope (Original_Comp);
14343 Type_Scope := Scope (Base_Type (Scope (C)));
14346 -- This test only concerns tagged types
14348 if not Is_Tagged_Type (Original_Scope) then
14351 -- If it is _Parent or _Tag, there is no visibility issue
14353 elsif not Comes_From_Source (Original_Comp) then
14356 -- If we are in the body of an instantiation, the component is visible
14357 -- even when the parent type (possibly defined in an enclosing unit or
14358 -- in a parent unit) might not.
14360 elsif In_Instance_Body then
14363 -- Discriminants are always visible
14365 elsif Ekind (Original_Comp) = E_Discriminant
14366 and then not Has_Unknown_Discriminants (Original_Scope)
14370 -- If the component has been declared in an ancestor which is currently
14371 -- a private type, then it is not visible. The same applies if the
14372 -- component's containing type is not in an open scope and the original
14373 -- component's enclosing type is a visible full view of a private type
14374 -- (which can occur in cases where an attempt is being made to reference
14375 -- a component in a sibling package that is inherited from a visible
14376 -- component of a type in an ancestor package; the component in the
14377 -- sibling package should not be visible even though the component it
14378 -- inherited from is visible). This does not apply however in the case
14379 -- where the scope of the type is a private child unit, or when the
14380 -- parent comes from a local package in which the ancestor is currently
14381 -- visible. The latter suppression of visibility is needed for cases
14382 -- that are tested in B730006.
14384 elsif Is_Private_Type (Original_Scope)
14386 (not Is_Private_Descendant (Type_Scope)
14387 and then not In_Open_Scopes (Type_Scope)
14388 and then Has_Private_Declaration (Original_Scope))
14390 -- If the type derives from an entity in a formal package, there
14391 -- are no additional visible components.
14393 if Nkind (Original_Node (Unit_Declaration_Node (Type_Scope))) =
14394 N_Formal_Package_Declaration
14398 -- if we are not in the private part of the current package, there
14399 -- are no additional visible components.
14401 elsif Ekind (Scope (Current_Scope)) = E_Package
14402 and then not In_Private_Part (Scope (Current_Scope))
14407 Is_Child_Unit (Cunit_Entity (Current_Sem_Unit))
14408 and then In_Open_Scopes (Scope (Original_Scope))
14409 and then Is_Local_Type (Type_Scope);
14412 -- There is another weird way in which a component may be invisible
14413 -- when the private and the full view are not derived from the same
14414 -- ancestor. Here is an example :
14416 -- type A1 is tagged record F1 : integer; end record;
14417 -- type A2 is new A1 with record F2 : integer; end record;
14418 -- type T is new A1 with private;
14420 -- type T is new A2 with null record;
14422 -- In this case, the full view of T inherits F1 and F2 but the private
14423 -- view inherits only F1
14427 Ancestor : Entity_Id := Scope (C);
14431 if Ancestor = Original_Scope then
14433 elsif Ancestor = Etype (Ancestor) then
14437 Ancestor := Etype (Ancestor);
14441 end Is_Visible_Component;
14443 --------------------------
14444 -- Make_Class_Wide_Type --
14445 --------------------------
14447 procedure Make_Class_Wide_Type (T : Entity_Id) is
14448 CW_Type : Entity_Id;
14450 Next_E : Entity_Id;
14453 -- The class wide type can have been defined by the partial view, in
14454 -- which case everything is already done.
14456 if Present (Class_Wide_Type (T)) then
14461 New_External_Entity (E_Void, Scope (T), Sloc (T), T, 'C', 0, 'T');
14463 -- Inherit root type characteristics
14465 CW_Name := Chars (CW_Type);
14466 Next_E := Next_Entity (CW_Type);
14467 Copy_Node (T, CW_Type);
14468 Set_Comes_From_Source (CW_Type, False);
14469 Set_Chars (CW_Type, CW_Name);
14470 Set_Parent (CW_Type, Parent (T));
14471 Set_Next_Entity (CW_Type, Next_E);
14473 -- Ensure we have a new freeze node for the class-wide type. The partial
14474 -- view may have freeze action of its own, requiring a proper freeze
14475 -- node, and the same freeze node cannot be shared between the two
14478 Set_Has_Delayed_Freeze (CW_Type);
14479 Set_Freeze_Node (CW_Type, Empty);
14481 -- Customize the class-wide type: It has no prim. op., it cannot be
14482 -- abstract and its Etype points back to the specific root type.
14484 Set_Ekind (CW_Type, E_Class_Wide_Type);
14485 Set_Is_Tagged_Type (CW_Type, True);
14486 Set_Primitive_Operations (CW_Type, New_Elmt_List);
14487 Set_Is_Abstract_Type (CW_Type, False);
14488 Set_Is_Constrained (CW_Type, False);
14489 Set_Is_First_Subtype (CW_Type, Is_First_Subtype (T));
14491 if Ekind (T) = E_Class_Wide_Subtype then
14492 Set_Etype (CW_Type, Etype (Base_Type (T)));
14494 Set_Etype (CW_Type, T);
14497 -- If this is the class_wide type of a constrained subtype, it does
14498 -- not have discriminants.
14500 Set_Has_Discriminants (CW_Type,
14501 Has_Discriminants (T) and then not Is_Constrained (T));
14503 Set_Has_Unknown_Discriminants (CW_Type, True);
14504 Set_Class_Wide_Type (T, CW_Type);
14505 Set_Equivalent_Type (CW_Type, Empty);
14507 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
14509 Set_Class_Wide_Type (CW_Type, CW_Type);
14510 end Make_Class_Wide_Type;
14516 procedure Make_Index
14518 Related_Nod : Node_Id;
14519 Related_Id : Entity_Id := Empty;
14520 Suffix_Index : Nat := 1)
14524 Def_Id : Entity_Id := Empty;
14525 Found : Boolean := False;
14528 -- For a discrete range used in a constrained array definition and
14529 -- defined by a range, an implicit conversion to the predefined type
14530 -- INTEGER is assumed if each bound is either a numeric literal, a named
14531 -- number, or an attribute, and the type of both bounds (prior to the
14532 -- implicit conversion) is the type universal_integer. Otherwise, both
14533 -- bounds must be of the same discrete type, other than universal
14534 -- integer; this type must be determinable independently of the
14535 -- context, but using the fact that the type must be discrete and that
14536 -- both bounds must have the same type.
14538 -- Character literals also have a universal type in the absence of
14539 -- of additional context, and are resolved to Standard_Character.
14541 if Nkind (I) = N_Range then
14543 -- The index is given by a range constraint. The bounds are known
14544 -- to be of a consistent type.
14546 if not Is_Overloaded (I) then
14549 -- For universal bounds, choose the specific predefined type
14551 if T = Universal_Integer then
14552 T := Standard_Integer;
14554 elsif T = Any_Character then
14555 Ambiguous_Character (Low_Bound (I));
14557 T := Standard_Character;
14560 -- The node may be overloaded because some user-defined operators
14561 -- are available, but if a universal interpretation exists it is
14562 -- also the selected one.
14564 elsif Universal_Interpretation (I) = Universal_Integer then
14565 T := Standard_Integer;
14571 Ind : Interp_Index;
14575 Get_First_Interp (I, Ind, It);
14576 while Present (It.Typ) loop
14577 if Is_Discrete_Type (It.Typ) then
14580 and then not Covers (It.Typ, T)
14581 and then not Covers (T, It.Typ)
14583 Error_Msg_N ("ambiguous bounds in discrete range", I);
14591 Get_Next_Interp (Ind, It);
14594 if T = Any_Type then
14595 Error_Msg_N ("discrete type required for range", I);
14596 Set_Etype (I, Any_Type);
14599 elsif T = Universal_Integer then
14600 T := Standard_Integer;
14605 if not Is_Discrete_Type (T) then
14606 Error_Msg_N ("discrete type required for range", I);
14607 Set_Etype (I, Any_Type);
14611 if Nkind (Low_Bound (I)) = N_Attribute_Reference
14612 and then Attribute_Name (Low_Bound (I)) = Name_First
14613 and then Is_Entity_Name (Prefix (Low_Bound (I)))
14614 and then Is_Type (Entity (Prefix (Low_Bound (I))))
14615 and then Is_Discrete_Type (Entity (Prefix (Low_Bound (I))))
14617 -- The type of the index will be the type of the prefix, as long
14618 -- as the upper bound is 'Last of the same type.
14620 Def_Id := Entity (Prefix (Low_Bound (I)));
14622 if Nkind (High_Bound (I)) /= N_Attribute_Reference
14623 or else Attribute_Name (High_Bound (I)) /= Name_Last
14624 or else not Is_Entity_Name (Prefix (High_Bound (I)))
14625 or else Entity (Prefix (High_Bound (I))) /= Def_Id
14632 Process_Range_Expr_In_Decl (R, T);
14634 elsif Nkind (I) = N_Subtype_Indication then
14636 -- The index is given by a subtype with a range constraint
14638 T := Base_Type (Entity (Subtype_Mark (I)));
14640 if not Is_Discrete_Type (T) then
14641 Error_Msg_N ("discrete type required for range", I);
14642 Set_Etype (I, Any_Type);
14646 R := Range_Expression (Constraint (I));
14649 Process_Range_Expr_In_Decl (R, Entity (Subtype_Mark (I)));
14651 elsif Nkind (I) = N_Attribute_Reference then
14653 -- The parser guarantees that the attribute is a RANGE attribute
14655 -- If the node denotes the range of a type mark, that is also the
14656 -- resulting type, and we do no need to create an Itype for it.
14658 if Is_Entity_Name (Prefix (I))
14659 and then Comes_From_Source (I)
14660 and then Is_Type (Entity (Prefix (I)))
14661 and then Is_Discrete_Type (Entity (Prefix (I)))
14663 Def_Id := Entity (Prefix (I));
14666 Analyze_And_Resolve (I);
14670 -- If none of the above, must be a subtype. We convert this to a
14671 -- range attribute reference because in the case of declared first
14672 -- named subtypes, the types in the range reference can be different
14673 -- from the type of the entity. A range attribute normalizes the
14674 -- reference and obtains the correct types for the bounds.
14676 -- This transformation is in the nature of an expansion, is only
14677 -- done if expansion is active. In particular, it is not done on
14678 -- formal generic types, because we need to retain the name of the
14679 -- original index for instantiation purposes.
14682 if not Is_Entity_Name (I) or else not Is_Type (Entity (I)) then
14683 Error_Msg_N ("invalid subtype mark in discrete range ", I);
14684 Set_Etype (I, Any_Integer);
14688 -- The type mark may be that of an incomplete type. It is only
14689 -- now that we can get the full view, previous analysis does
14690 -- not look specifically for a type mark.
14692 Set_Entity (I, Get_Full_View (Entity (I)));
14693 Set_Etype (I, Entity (I));
14694 Def_Id := Entity (I);
14696 if not Is_Discrete_Type (Def_Id) then
14697 Error_Msg_N ("discrete type required for index", I);
14698 Set_Etype (I, Any_Type);
14703 if Expander_Active then
14705 Make_Attribute_Reference (Sloc (I),
14706 Attribute_Name => Name_Range,
14707 Prefix => Relocate_Node (I)));
14709 -- The original was a subtype mark that does not freeze. This
14710 -- means that the rewritten version must not freeze either.
14712 Set_Must_Not_Freeze (I);
14713 Set_Must_Not_Freeze (Prefix (I));
14715 -- Is order critical??? if so, document why, if not
14716 -- use Analyze_And_Resolve
14718 Analyze_And_Resolve (I);
14722 -- If expander is inactive, type is legal, nothing else to construct
14729 if not Is_Discrete_Type (T) then
14730 Error_Msg_N ("discrete type required for range", I);
14731 Set_Etype (I, Any_Type);
14734 elsif T = Any_Type then
14735 Set_Etype (I, Any_Type);
14739 -- We will now create the appropriate Itype to describe the range, but
14740 -- first a check. If we originally had a subtype, then we just label
14741 -- the range with this subtype. Not only is there no need to construct
14742 -- a new subtype, but it is wrong to do so for two reasons:
14744 -- 1. A legality concern, if we have a subtype, it must not freeze,
14745 -- and the Itype would cause freezing incorrectly
14747 -- 2. An efficiency concern, if we created an Itype, it would not be
14748 -- recognized as the same type for the purposes of eliminating
14749 -- checks in some circumstances.
14751 -- We signal this case by setting the subtype entity in Def_Id
14753 if No (Def_Id) then
14755 Create_Itype (E_Void, Related_Nod, Related_Id, 'D', Suffix_Index);
14756 Set_Etype (Def_Id, Base_Type (T));
14758 if Is_Signed_Integer_Type (T) then
14759 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
14761 elsif Is_Modular_Integer_Type (T) then
14762 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
14765 Set_Ekind (Def_Id, E_Enumeration_Subtype);
14766 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
14767 Set_First_Literal (Def_Id, First_Literal (T));
14770 Set_Size_Info (Def_Id, (T));
14771 Set_RM_Size (Def_Id, RM_Size (T));
14772 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
14774 Set_Scalar_Range (Def_Id, R);
14775 Conditional_Delay (Def_Id, T);
14777 -- In the subtype indication case, if the immediate parent of the
14778 -- new subtype is non-static, then the subtype we create is non-
14779 -- static, even if its bounds are static.
14781 if Nkind (I) = N_Subtype_Indication
14782 and then not Is_Static_Subtype (Entity (Subtype_Mark (I)))
14784 Set_Is_Non_Static_Subtype (Def_Id);
14788 -- Final step is to label the index with this constructed type
14790 Set_Etype (I, Def_Id);
14793 ------------------------------
14794 -- Modular_Type_Declaration --
14795 ------------------------------
14797 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id) is
14798 Mod_Expr : constant Node_Id := Expression (Def);
14801 procedure Set_Modular_Size (Bits : Int);
14802 -- Sets RM_Size to Bits, and Esize to normal word size above this
14804 ----------------------
14805 -- Set_Modular_Size --
14806 ----------------------
14808 procedure Set_Modular_Size (Bits : Int) is
14810 Set_RM_Size (T, UI_From_Int (Bits));
14815 elsif Bits <= 16 then
14816 Init_Esize (T, 16);
14818 elsif Bits <= 32 then
14819 Init_Esize (T, 32);
14822 Init_Esize (T, System_Max_Binary_Modulus_Power);
14824 end Set_Modular_Size;
14826 -- Start of processing for Modular_Type_Declaration
14829 Analyze_And_Resolve (Mod_Expr, Any_Integer);
14831 Set_Ekind (T, E_Modular_Integer_Type);
14832 Init_Alignment (T);
14833 Set_Is_Constrained (T);
14835 if not Is_OK_Static_Expression (Mod_Expr) then
14836 Flag_Non_Static_Expr
14837 ("non-static expression used for modular type bound!", Mod_Expr);
14838 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14840 M_Val := Expr_Value (Mod_Expr);
14844 Error_Msg_N ("modulus value must be positive", Mod_Expr);
14845 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14848 Set_Modulus (T, M_Val);
14850 -- Create bounds for the modular type based on the modulus given in
14851 -- the type declaration and then analyze and resolve those bounds.
14853 Set_Scalar_Range (T,
14854 Make_Range (Sloc (Mod_Expr),
14856 Make_Integer_Literal (Sloc (Mod_Expr), 0),
14858 Make_Integer_Literal (Sloc (Mod_Expr), M_Val - 1)));
14860 -- Properly analyze the literals for the range. We do this manually
14861 -- because we can't go calling Resolve, since we are resolving these
14862 -- bounds with the type, and this type is certainly not complete yet!
14864 Set_Etype (Low_Bound (Scalar_Range (T)), T);
14865 Set_Etype (High_Bound (Scalar_Range (T)), T);
14866 Set_Is_Static_Expression (Low_Bound (Scalar_Range (T)));
14867 Set_Is_Static_Expression (High_Bound (Scalar_Range (T)));
14869 -- Loop through powers of two to find number of bits required
14871 for Bits in Int range 0 .. System_Max_Binary_Modulus_Power loop
14875 if M_Val = 2 ** Bits then
14876 Set_Modular_Size (Bits);
14881 elsif M_Val < 2 ** Bits then
14882 Set_Non_Binary_Modulus (T);
14884 if Bits > System_Max_Nonbinary_Modulus_Power then
14885 Error_Msg_Uint_1 :=
14886 UI_From_Int (System_Max_Nonbinary_Modulus_Power);
14888 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr);
14889 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14893 -- In the non-binary case, set size as per RM 13.3(55)
14895 Set_Modular_Size (Bits);
14902 -- If we fall through, then the size exceed System.Max_Binary_Modulus
14903 -- so we just signal an error and set the maximum size.
14905 Error_Msg_Uint_1 := UI_From_Int (System_Max_Binary_Modulus_Power);
14906 Error_Msg_F ("modulus exceeds limit (2 '*'*^)", Mod_Expr);
14908 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14909 Init_Alignment (T);
14911 end Modular_Type_Declaration;
14913 --------------------------
14914 -- New_Concatenation_Op --
14915 --------------------------
14917 procedure New_Concatenation_Op (Typ : Entity_Id) is
14918 Loc : constant Source_Ptr := Sloc (Typ);
14921 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id;
14922 -- Create abbreviated declaration for the formal of a predefined
14923 -- Operator 'Op' of type 'Typ'
14925 --------------------
14926 -- Make_Op_Formal --
14927 --------------------
14929 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id is
14930 Formal : Entity_Id;
14932 Formal := New_Internal_Entity (E_In_Parameter, Op, Loc, 'P');
14933 Set_Etype (Formal, Typ);
14934 Set_Mechanism (Formal, Default_Mechanism);
14936 end Make_Op_Formal;
14938 -- Start of processing for New_Concatenation_Op
14941 Op := Make_Defining_Operator_Symbol (Loc, Name_Op_Concat);
14943 Set_Ekind (Op, E_Operator);
14944 Set_Scope (Op, Current_Scope);
14945 Set_Etype (Op, Typ);
14946 Set_Homonym (Op, Get_Name_Entity_Id (Name_Op_Concat));
14947 Set_Is_Immediately_Visible (Op);
14948 Set_Is_Intrinsic_Subprogram (Op);
14949 Set_Has_Completion (Op);
14950 Append_Entity (Op, Current_Scope);
14952 Set_Name_Entity_Id (Name_Op_Concat, Op);
14954 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14955 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14956 end New_Concatenation_Op;
14958 -------------------------
14959 -- OK_For_Limited_Init --
14960 -------------------------
14962 -- ???Check all calls of this, and compare the conditions under which it's
14965 function OK_For_Limited_Init (Exp : Node_Id) return Boolean is
14967 return Ada_Version >= Ada_05
14968 and then not Debug_Flag_Dot_L
14969 and then OK_For_Limited_Init_In_05 (Exp);
14970 end OK_For_Limited_Init;
14972 -------------------------------
14973 -- OK_For_Limited_Init_In_05 --
14974 -------------------------------
14976 function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean is
14978 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
14979 -- case of limited aggregates (including extension aggregates), and
14980 -- function calls. The function call may have been give in prefixed
14981 -- notation, in which case the original node is an indexed component.
14983 case Nkind (Original_Node (Exp)) is
14984 when N_Aggregate | N_Extension_Aggregate | N_Function_Call | N_Op =>
14987 when N_Qualified_Expression =>
14989 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
14991 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
14992 -- with a function call, the expander has rewritten the call into an
14993 -- N_Type_Conversion node to force displacement of the pointer to
14994 -- reference the component containing the secondary dispatch table.
14995 -- Otherwise a type conversion is not a legal context.
14997 when N_Type_Conversion =>
14998 return not Comes_From_Source (Exp)
15000 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
15002 when N_Indexed_Component | N_Selected_Component =>
15003 return Nkind (Exp) = N_Function_Call;
15005 -- A use of 'Input is a function call, hence allowed. Normally the
15006 -- attribute will be changed to a call, but the attribute by itself
15007 -- can occur with -gnatc.
15009 when N_Attribute_Reference =>
15010 return Attribute_Name (Original_Node (Exp)) = Name_Input;
15015 end OK_For_Limited_Init_In_05;
15017 -------------------------------------------
15018 -- Ordinary_Fixed_Point_Type_Declaration --
15019 -------------------------------------------
15021 procedure Ordinary_Fixed_Point_Type_Declaration
15025 Loc : constant Source_Ptr := Sloc (Def);
15026 Delta_Expr : constant Node_Id := Delta_Expression (Def);
15027 RRS : constant Node_Id := Real_Range_Specification (Def);
15028 Implicit_Base : Entity_Id;
15035 Check_Restriction (No_Fixed_Point, Def);
15037 -- Create implicit base type
15040 Create_Itype (E_Ordinary_Fixed_Point_Type, Parent (Def), T, 'B');
15041 Set_Etype (Implicit_Base, Implicit_Base);
15043 -- Analyze and process delta expression
15045 Analyze_And_Resolve (Delta_Expr, Any_Real);
15047 Check_Delta_Expression (Delta_Expr);
15048 Delta_Val := Expr_Value_R (Delta_Expr);
15050 Set_Delta_Value (Implicit_Base, Delta_Val);
15052 -- Compute default small from given delta, which is the largest power
15053 -- of two that does not exceed the given delta value.
15063 if Delta_Val < Ureal_1 then
15064 while Delta_Val < Tmp loop
15065 Tmp := Tmp / Ureal_2;
15066 Scale := Scale + 1;
15071 Tmp := Tmp * Ureal_2;
15072 exit when Tmp > Delta_Val;
15073 Scale := Scale - 1;
15077 Small_Val := UR_From_Components (Uint_1, UI_From_Int (Scale), 2);
15080 Set_Small_Value (Implicit_Base, Small_Val);
15082 -- If no range was given, set a dummy range
15084 if RRS <= Empty_Or_Error then
15085 Low_Val := -Small_Val;
15086 High_Val := Small_Val;
15088 -- Otherwise analyze and process given range
15092 Low : constant Node_Id := Low_Bound (RRS);
15093 High : constant Node_Id := High_Bound (RRS);
15096 Analyze_And_Resolve (Low, Any_Real);
15097 Analyze_And_Resolve (High, Any_Real);
15098 Check_Real_Bound (Low);
15099 Check_Real_Bound (High);
15101 -- Obtain and set the range
15103 Low_Val := Expr_Value_R (Low);
15104 High_Val := Expr_Value_R (High);
15106 if Low_Val > High_Val then
15107 Error_Msg_NE ("?fixed point type& has null range", Def, T);
15112 -- The range for both the implicit base and the declared first subtype
15113 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
15114 -- set a temporary range in place. Note that the bounds of the base
15115 -- type will be widened to be symmetrical and to fill the available
15116 -- bits when the type is frozen.
15118 -- We could do this with all discrete types, and probably should, but
15119 -- we absolutely have to do it for fixed-point, since the end-points
15120 -- of the range and the size are determined by the small value, which
15121 -- could be reset before the freeze point.
15123 Set_Fixed_Range (Implicit_Base, Loc, Low_Val, High_Val);
15124 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
15126 -- Complete definition of first subtype
15128 Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype);
15129 Set_Etype (T, Implicit_Base);
15130 Init_Size_Align (T);
15131 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
15132 Set_Small_Value (T, Small_Val);
15133 Set_Delta_Value (T, Delta_Val);
15134 Set_Is_Constrained (T);
15136 end Ordinary_Fixed_Point_Type_Declaration;
15138 ----------------------------------------
15139 -- Prepare_Private_Subtype_Completion --
15140 ----------------------------------------
15142 procedure Prepare_Private_Subtype_Completion
15144 Related_Nod : Node_Id)
15146 Id_B : constant Entity_Id := Base_Type (Id);
15147 Full_B : constant Entity_Id := Full_View (Id_B);
15151 if Present (Full_B) then
15153 -- The Base_Type is already completed, we can complete the subtype
15154 -- now. We have to create a new entity with the same name, Thus we
15155 -- can't use Create_Itype.
15157 -- This is messy, should be fixed ???
15159 Full := Make_Defining_Identifier (Sloc (Id), Chars (Id));
15160 Set_Is_Itype (Full);
15161 Set_Associated_Node_For_Itype (Full, Related_Nod);
15162 Complete_Private_Subtype (Id, Full, Full_B, Related_Nod);
15165 -- The parent subtype may be private, but the base might not, in some
15166 -- nested instances. In that case, the subtype does not need to be
15167 -- exchanged. It would still be nice to make private subtypes and their
15168 -- bases consistent at all times ???
15170 if Is_Private_Type (Id_B) then
15171 Append_Elmt (Id, Private_Dependents (Id_B));
15174 end Prepare_Private_Subtype_Completion;
15176 ---------------------------
15177 -- Process_Discriminants --
15178 ---------------------------
15180 procedure Process_Discriminants
15182 Prev : Entity_Id := Empty)
15184 Elist : constant Elist_Id := New_Elmt_List;
15187 Discr_Number : Uint;
15188 Discr_Type : Entity_Id;
15189 Default_Present : Boolean := False;
15190 Default_Not_Present : Boolean := False;
15193 -- A composite type other than an array type can have discriminants.
15194 -- On entry, the current scope is the composite type.
15196 -- The discriminants are initially entered into the scope of the type
15197 -- via Enter_Name with the default Ekind of E_Void to prevent premature
15198 -- use, as explained at the end of this procedure.
15200 Discr := First (Discriminant_Specifications (N));
15201 while Present (Discr) loop
15202 Enter_Name (Defining_Identifier (Discr));
15204 -- For navigation purposes we add a reference to the discriminant
15205 -- in the entity for the type. If the current declaration is a
15206 -- completion, place references on the partial view. Otherwise the
15207 -- type is the current scope.
15209 if Present (Prev) then
15211 -- The references go on the partial view, if present. If the
15212 -- partial view has discriminants, the references have been
15213 -- generated already.
15215 if not Has_Discriminants (Prev) then
15216 Generate_Reference (Prev, Defining_Identifier (Discr), 'd');
15220 (Current_Scope, Defining_Identifier (Discr), 'd');
15223 if Nkind (Discriminant_Type (Discr)) = N_Access_Definition then
15224 Discr_Type := Access_Definition (Discr, Discriminant_Type (Discr));
15226 -- Ada 2005 (AI-254)
15228 if Present (Access_To_Subprogram_Definition
15229 (Discriminant_Type (Discr)))
15230 and then Protected_Present (Access_To_Subprogram_Definition
15231 (Discriminant_Type (Discr)))
15234 Replace_Anonymous_Access_To_Protected_Subprogram (Discr);
15238 Find_Type (Discriminant_Type (Discr));
15239 Discr_Type := Etype (Discriminant_Type (Discr));
15241 if Error_Posted (Discriminant_Type (Discr)) then
15242 Discr_Type := Any_Type;
15246 if Is_Access_Type (Discr_Type) then
15248 -- Ada 2005 (AI-230): Access discriminant allowed in non-limited
15251 if Ada_Version < Ada_05 then
15252 Check_Access_Discriminant_Requires_Limited
15253 (Discr, Discriminant_Type (Discr));
15256 if Ada_Version = Ada_83 and then Comes_From_Source (Discr) then
15258 ("(Ada 83) access discriminant not allowed", Discr);
15261 elsif not Is_Discrete_Type (Discr_Type) then
15262 Error_Msg_N ("discriminants must have a discrete or access type",
15263 Discriminant_Type (Discr));
15266 Set_Etype (Defining_Identifier (Discr), Discr_Type);
15268 -- If a discriminant specification includes the assignment compound
15269 -- delimiter followed by an expression, the expression is the default
15270 -- expression of the discriminant; the default expression must be of
15271 -- the type of the discriminant. (RM 3.7.1) Since this expression is
15272 -- a default expression, we do the special preanalysis, since this
15273 -- expression does not freeze (see "Handling of Default and Per-
15274 -- Object Expressions" in spec of package Sem).
15276 if Present (Expression (Discr)) then
15277 Preanalyze_Spec_Expression (Expression (Discr), Discr_Type);
15279 if Nkind (N) = N_Formal_Type_Declaration then
15281 ("discriminant defaults not allowed for formal type",
15282 Expression (Discr));
15284 -- Tagged types cannot have defaulted discriminants, but a
15285 -- non-tagged private type with defaulted discriminants
15286 -- can have a tagged completion.
15288 elsif Is_Tagged_Type (Current_Scope)
15289 and then Comes_From_Source (N)
15292 ("discriminants of tagged type cannot have defaults",
15293 Expression (Discr));
15296 Default_Present := True;
15297 Append_Elmt (Expression (Discr), Elist);
15299 -- Tag the defining identifiers for the discriminants with
15300 -- their corresponding default expressions from the tree.
15302 Set_Discriminant_Default_Value
15303 (Defining_Identifier (Discr), Expression (Discr));
15307 Default_Not_Present := True;
15310 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
15311 -- Discr_Type but with the null-exclusion attribute
15313 if Ada_Version >= Ada_05 then
15315 -- Ada 2005 (AI-231): Static checks
15317 if Can_Never_Be_Null (Discr_Type) then
15318 Null_Exclusion_Static_Checks (Discr);
15320 elsif Is_Access_Type (Discr_Type)
15321 and then Null_Exclusion_Present (Discr)
15323 -- No need to check itypes because in their case this check
15324 -- was done at their point of creation
15326 and then not Is_Itype (Discr_Type)
15328 if Can_Never_Be_Null (Discr_Type) then
15330 ("`NOT NULL` not allowed (& already excludes null)",
15335 Set_Etype (Defining_Identifier (Discr),
15336 Create_Null_Excluding_Itype
15338 Related_Nod => Discr));
15341 -- Ada 2005 (AI-402): access discriminants of nonlimited types
15342 -- can't have defaults. Synchronized types, or types that are
15343 -- explicitly limited are fine, but special tests apply to derived
15344 -- types in generics: in a generic body we have to assume the
15345 -- worst, and therefore defaults are not allowed if the parent is
15346 -- a generic formal private type (see ACATS B370001).
15348 if Is_Access_Type (Discr_Type) then
15349 if Ekind (Discr_Type) /= E_Anonymous_Access_Type
15350 or else not Default_Present
15351 or else Is_Limited_Record (Current_Scope)
15352 or else Is_Concurrent_Type (Current_Scope)
15353 or else Is_Concurrent_Record_Type (Current_Scope)
15354 or else Ekind (Current_Scope) = E_Limited_Private_Type
15356 if not Is_Derived_Type (Current_Scope)
15357 or else not Is_Generic_Type (Etype (Current_Scope))
15358 or else not In_Package_Body (Scope (Etype (Current_Scope)))
15359 or else Limited_Present
15360 (Type_Definition (Parent (Current_Scope)))
15365 Error_Msg_N ("access discriminants of nonlimited types",
15366 Expression (Discr));
15367 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15370 elsif Present (Expression (Discr)) then
15372 ("(Ada 2005) access discriminants of nonlimited types",
15373 Expression (Discr));
15374 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15382 -- An element list consisting of the default expressions of the
15383 -- discriminants is constructed in the above loop and used to set
15384 -- the Discriminant_Constraint attribute for the type. If an object
15385 -- is declared of this (record or task) type without any explicit
15386 -- discriminant constraint given, this element list will form the
15387 -- actual parameters for the corresponding initialization procedure
15390 Set_Discriminant_Constraint (Current_Scope, Elist);
15391 Set_Stored_Constraint (Current_Scope, No_Elist);
15393 -- Default expressions must be provided either for all or for none
15394 -- of the discriminants of a discriminant part. (RM 3.7.1)
15396 if Default_Present and then Default_Not_Present then
15398 ("incomplete specification of defaults for discriminants", N);
15401 -- The use of the name of a discriminant is not allowed in default
15402 -- expressions of a discriminant part if the specification of the
15403 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
15405 -- To detect this, the discriminant names are entered initially with an
15406 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
15407 -- attempt to use a void entity (for example in an expression that is
15408 -- type-checked) produces the error message: premature usage. Now after
15409 -- completing the semantic analysis of the discriminant part, we can set
15410 -- the Ekind of all the discriminants appropriately.
15412 Discr := First (Discriminant_Specifications (N));
15413 Discr_Number := Uint_1;
15414 while Present (Discr) loop
15415 Id := Defining_Identifier (Discr);
15416 Set_Ekind (Id, E_Discriminant);
15417 Init_Component_Location (Id);
15419 Set_Discriminant_Number (Id, Discr_Number);
15421 -- Make sure this is always set, even in illegal programs
15423 Set_Corresponding_Discriminant (Id, Empty);
15425 -- Initialize the Original_Record_Component to the entity itself.
15426 -- Inherit_Components will propagate the right value to
15427 -- discriminants in derived record types.
15429 Set_Original_Record_Component (Id, Id);
15431 -- Create the discriminal for the discriminant
15433 Build_Discriminal (Id);
15436 Discr_Number := Discr_Number + 1;
15439 Set_Has_Discriminants (Current_Scope);
15440 end Process_Discriminants;
15442 -----------------------
15443 -- Process_Full_View --
15444 -----------------------
15446 procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id) is
15447 Priv_Parent : Entity_Id;
15448 Full_Parent : Entity_Id;
15449 Full_Indic : Node_Id;
15451 procedure Collect_Implemented_Interfaces
15453 Ifaces : Elist_Id);
15454 -- Ada 2005: Gather all the interfaces that Typ directly or
15455 -- inherently implements. Duplicate entries are not added to
15456 -- the list Ifaces.
15458 ------------------------------------
15459 -- Collect_Implemented_Interfaces --
15460 ------------------------------------
15462 procedure Collect_Implemented_Interfaces
15467 Iface_Elmt : Elmt_Id;
15470 -- Abstract interfaces are only associated with tagged record types
15472 if not Is_Tagged_Type (Typ)
15473 or else not Is_Record_Type (Typ)
15478 -- Recursively climb to the ancestors
15480 if Etype (Typ) /= Typ
15482 -- Protect the frontend against wrong cyclic declarations like:
15484 -- type B is new A with private;
15485 -- type C is new A with private;
15487 -- type B is new C with null record;
15488 -- type C is new B with null record;
15490 and then Etype (Typ) /= Priv_T
15491 and then Etype (Typ) /= Full_T
15493 -- Keep separate the management of private type declarations
15495 if Ekind (Typ) = E_Record_Type_With_Private then
15497 -- Handle the following erronous case:
15498 -- type Private_Type is tagged private;
15500 -- type Private_Type is new Type_Implementing_Iface;
15502 if Present (Full_View (Typ))
15503 and then Etype (Typ) /= Full_View (Typ)
15505 if Is_Interface (Etype (Typ)) then
15506 Append_Unique_Elmt (Etype (Typ), Ifaces);
15509 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15512 -- Non-private types
15515 if Is_Interface (Etype (Typ)) then
15516 Append_Unique_Elmt (Etype (Typ), Ifaces);
15519 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15523 -- Handle entities in the list of abstract interfaces
15525 if Present (Interfaces (Typ)) then
15526 Iface_Elmt := First_Elmt (Interfaces (Typ));
15527 while Present (Iface_Elmt) loop
15528 Iface := Node (Iface_Elmt);
15530 pragma Assert (Is_Interface (Iface));
15532 if not Contain_Interface (Iface, Ifaces) then
15533 Append_Elmt (Iface, Ifaces);
15534 Collect_Implemented_Interfaces (Iface, Ifaces);
15537 Next_Elmt (Iface_Elmt);
15540 end Collect_Implemented_Interfaces;
15542 -- Start of processing for Process_Full_View
15545 -- First some sanity checks that must be done after semantic
15546 -- decoration of the full view and thus cannot be placed with other
15547 -- similar checks in Find_Type_Name
15549 if not Is_Limited_Type (Priv_T)
15550 and then (Is_Limited_Type (Full_T)
15551 or else Is_Limited_Composite (Full_T))
15554 ("completion of nonlimited type cannot be limited", Full_T);
15555 Explain_Limited_Type (Full_T, Full_T);
15557 elsif Is_Abstract_Type (Full_T)
15558 and then not Is_Abstract_Type (Priv_T)
15561 ("completion of nonabstract type cannot be abstract", Full_T);
15563 elsif Is_Tagged_Type (Priv_T)
15564 and then Is_Limited_Type (Priv_T)
15565 and then not Is_Limited_Type (Full_T)
15567 -- If pragma CPP_Class was applied to the private declaration
15568 -- propagate the limitedness to the full-view
15570 if Is_CPP_Class (Priv_T) then
15571 Set_Is_Limited_Record (Full_T);
15573 -- GNAT allow its own definition of Limited_Controlled to disobey
15574 -- this rule in order in ease the implementation. The next test is
15575 -- safe because Root_Controlled is defined in a private system child
15577 elsif Etype (Full_T) = Full_View (RTE (RE_Root_Controlled)) then
15578 Set_Is_Limited_Composite (Full_T);
15581 ("completion of limited tagged type must be limited", Full_T);
15584 elsif Is_Generic_Type (Priv_T) then
15585 Error_Msg_N ("generic type cannot have a completion", Full_T);
15588 -- Check that ancestor interfaces of private and full views are
15589 -- consistent. We omit this check for synchronized types because
15590 -- they are performed on the corresponding record type when frozen.
15592 if Ada_Version >= Ada_05
15593 and then Is_Tagged_Type (Priv_T)
15594 and then Is_Tagged_Type (Full_T)
15595 and then not Is_Concurrent_Type (Full_T)
15599 Priv_T_Ifaces : constant Elist_Id := New_Elmt_List;
15600 Full_T_Ifaces : constant Elist_Id := New_Elmt_List;
15603 Collect_Implemented_Interfaces (Priv_T, Priv_T_Ifaces);
15604 Collect_Implemented_Interfaces (Full_T, Full_T_Ifaces);
15606 -- Ada 2005 (AI-251): The partial view shall be a descendant of
15607 -- an interface type if and only if the full type is descendant
15608 -- of the interface type (AARM 7.3 (7.3/2).
15610 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
15612 if Present (Iface) then
15613 Error_Msg_NE ("interface & not implemented by full type " &
15614 "(RM-2005 7.3 (7.3/2))", Priv_T, Iface);
15617 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
15619 if Present (Iface) then
15620 Error_Msg_NE ("interface & not implemented by partial view " &
15621 "(RM-2005 7.3 (7.3/2))", Full_T, Iface);
15626 if Is_Tagged_Type (Priv_T)
15627 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15628 and then Is_Derived_Type (Full_T)
15630 Priv_Parent := Etype (Priv_T);
15632 -- The full view of a private extension may have been transformed
15633 -- into an unconstrained derived type declaration and a subtype
15634 -- declaration (see build_derived_record_type for details).
15636 if Nkind (N) = N_Subtype_Declaration then
15637 Full_Indic := Subtype_Indication (N);
15638 Full_Parent := Etype (Base_Type (Full_T));
15640 Full_Indic := Subtype_Indication (Type_Definition (N));
15641 Full_Parent := Etype (Full_T);
15644 -- Check that the parent type of the full type is a descendant of
15645 -- the ancestor subtype given in the private extension. If either
15646 -- entity has an Etype equal to Any_Type then we had some previous
15647 -- error situation [7.3(8)].
15649 if Priv_Parent = Any_Type or else Full_Parent = Any_Type then
15652 -- Ada 2005 (AI-251): Interfaces in the full-typ can be given in
15653 -- any order. Therefore we don't have to check that its parent must
15654 -- be a descendant of the parent of the private type declaration.
15656 elsif Is_Interface (Priv_Parent)
15657 and then Is_Interface (Full_Parent)
15661 -- Ada 2005 (AI-251): If the parent of the private type declaration
15662 -- is an interface there is no need to check that it is an ancestor
15663 -- of the associated full type declaration. The required tests for
15664 -- this case case are performed by Build_Derived_Record_Type.
15666 elsif not Is_Interface (Base_Type (Priv_Parent))
15667 and then not Is_Ancestor (Base_Type (Priv_Parent), Full_Parent)
15670 ("parent of full type must descend from parent"
15671 & " of private extension", Full_Indic);
15673 -- Check the rules of 7.3(10): if the private extension inherits
15674 -- known discriminants, then the full type must also inherit those
15675 -- discriminants from the same (ancestor) type, and the parent
15676 -- subtype of the full type must be constrained if and only if
15677 -- the ancestor subtype of the private extension is constrained.
15679 elsif No (Discriminant_Specifications (Parent (Priv_T)))
15680 and then not Has_Unknown_Discriminants (Priv_T)
15681 and then Has_Discriminants (Base_Type (Priv_Parent))
15684 Priv_Indic : constant Node_Id :=
15685 Subtype_Indication (Parent (Priv_T));
15687 Priv_Constr : constant Boolean :=
15688 Is_Constrained (Priv_Parent)
15690 Nkind (Priv_Indic) = N_Subtype_Indication
15691 or else Is_Constrained (Entity (Priv_Indic));
15693 Full_Constr : constant Boolean :=
15694 Is_Constrained (Full_Parent)
15696 Nkind (Full_Indic) = N_Subtype_Indication
15697 or else Is_Constrained (Entity (Full_Indic));
15699 Priv_Discr : Entity_Id;
15700 Full_Discr : Entity_Id;
15703 Priv_Discr := First_Discriminant (Priv_Parent);
15704 Full_Discr := First_Discriminant (Full_Parent);
15705 while Present (Priv_Discr) and then Present (Full_Discr) loop
15706 if Original_Record_Component (Priv_Discr) =
15707 Original_Record_Component (Full_Discr)
15709 Corresponding_Discriminant (Priv_Discr) =
15710 Corresponding_Discriminant (Full_Discr)
15717 Next_Discriminant (Priv_Discr);
15718 Next_Discriminant (Full_Discr);
15721 if Present (Priv_Discr) or else Present (Full_Discr) then
15723 ("full view must inherit discriminants of the parent type"
15724 & " used in the private extension", Full_Indic);
15726 elsif Priv_Constr and then not Full_Constr then
15728 ("parent subtype of full type must be constrained",
15731 elsif Full_Constr and then not Priv_Constr then
15733 ("parent subtype of full type must be unconstrained",
15738 -- Check the rules of 7.3(12): if a partial view has neither known
15739 -- or unknown discriminants, then the full type declaration shall
15740 -- define a definite subtype.
15742 elsif not Has_Unknown_Discriminants (Priv_T)
15743 and then not Has_Discriminants (Priv_T)
15744 and then not Is_Constrained (Full_T)
15747 ("full view must define a constrained type if partial view"
15748 & " has no discriminants", Full_T);
15751 -- ??????? Do we implement the following properly ?????
15752 -- If the ancestor subtype of a private extension has constrained
15753 -- discriminants, then the parent subtype of the full view shall
15754 -- impose a statically matching constraint on those discriminants
15758 -- For untagged types, verify that a type without discriminants
15759 -- is not completed with an unconstrained type.
15761 if not Is_Indefinite_Subtype (Priv_T)
15762 and then Is_Indefinite_Subtype (Full_T)
15764 Error_Msg_N ("full view of type must be definite subtype", Full_T);
15768 -- AI-419: verify that the use of "limited" is consistent
15771 Orig_Decl : constant Node_Id := Original_Node (N);
15774 if Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15775 and then not Limited_Present (Parent (Priv_T))
15776 and then not Synchronized_Present (Parent (Priv_T))
15777 and then Nkind (Orig_Decl) = N_Full_Type_Declaration
15779 (Type_Definition (Orig_Decl)) = N_Derived_Type_Definition
15780 and then Limited_Present (Type_Definition (Orig_Decl))
15783 ("full view of non-limited extension cannot be limited", N);
15787 -- Ada 2005 (AI-443): A synchronized private extension must be
15788 -- completed by a task or protected type.
15790 if Ada_Version >= Ada_05
15791 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15792 and then Synchronized_Present (Parent (Priv_T))
15793 and then not Is_Concurrent_Type (Full_T)
15795 Error_Msg_N ("full view of synchronized extension must " &
15796 "be synchronized type", N);
15799 -- Ada 2005 AI-363: if the full view has discriminants with
15800 -- defaults, it is illegal to declare constrained access subtypes
15801 -- whose designated type is the current type. This allows objects
15802 -- of the type that are declared in the heap to be unconstrained.
15804 if not Has_Unknown_Discriminants (Priv_T)
15805 and then not Has_Discriminants (Priv_T)
15806 and then Has_Discriminants (Full_T)
15808 Present (Discriminant_Default_Value (First_Discriminant (Full_T)))
15810 Set_Has_Constrained_Partial_View (Full_T);
15811 Set_Has_Constrained_Partial_View (Priv_T);
15814 -- Create a full declaration for all its subtypes recorded in
15815 -- Private_Dependents and swap them similarly to the base type. These
15816 -- are subtypes that have been define before the full declaration of
15817 -- the private type. We also swap the entry in Private_Dependents list
15818 -- so we can properly restore the private view on exit from the scope.
15821 Priv_Elmt : Elmt_Id;
15826 Priv_Elmt := First_Elmt (Private_Dependents (Priv_T));
15827 while Present (Priv_Elmt) loop
15828 Priv := Node (Priv_Elmt);
15830 if Ekind (Priv) = E_Private_Subtype
15831 or else Ekind (Priv) = E_Limited_Private_Subtype
15832 or else Ekind (Priv) = E_Record_Subtype_With_Private
15834 Full := Make_Defining_Identifier (Sloc (Priv), Chars (Priv));
15835 Set_Is_Itype (Full);
15836 Set_Parent (Full, Parent (Priv));
15837 Set_Associated_Node_For_Itype (Full, N);
15839 -- Now we need to complete the private subtype, but since the
15840 -- base type has already been swapped, we must also swap the
15841 -- subtypes (and thus, reverse the arguments in the call to
15842 -- Complete_Private_Subtype).
15844 Copy_And_Swap (Priv, Full);
15845 Complete_Private_Subtype (Full, Priv, Full_T, N);
15846 Replace_Elmt (Priv_Elmt, Full);
15849 Next_Elmt (Priv_Elmt);
15853 -- If the private view was tagged, copy the new primitive operations
15854 -- from the private view to the full view.
15856 if Is_Tagged_Type (Full_T) then
15858 Disp_Typ : Entity_Id;
15859 Full_List : Elist_Id;
15861 Prim_Elmt : Elmt_Id;
15862 Priv_List : Elist_Id;
15866 L : Elist_Id) return Boolean;
15867 -- Determine whether list L contains element E
15875 L : Elist_Id) return Boolean
15877 List_Elmt : Elmt_Id;
15880 List_Elmt := First_Elmt (L);
15881 while Present (List_Elmt) loop
15882 if Node (List_Elmt) = E then
15886 Next_Elmt (List_Elmt);
15892 -- Start of processing
15895 if Is_Tagged_Type (Priv_T) then
15896 Priv_List := Primitive_Operations (Priv_T);
15897 Prim_Elmt := First_Elmt (Priv_List);
15899 -- In the case of a concurrent type completing a private tagged
15900 -- type, primivies may have been declared in between the two
15901 -- views. These subprograms need to be wrapped the same way
15902 -- entries and protected procedures are handled because they
15903 -- cannot be directly shared by the two views.
15905 if Is_Concurrent_Type (Full_T) then
15907 Conc_Typ : constant Entity_Id :=
15908 Corresponding_Record_Type (Full_T);
15909 Loc : constant Source_Ptr := Sloc (Conc_Typ);
15910 Curr_Nod : Node_Id := Parent (Conc_Typ);
15911 Wrap_Spec : Node_Id;
15914 while Present (Prim_Elmt) loop
15915 Prim := Node (Prim_Elmt);
15917 if Comes_From_Source (Prim)
15918 and then not Is_Abstract_Subprogram (Prim)
15921 Make_Subprogram_Declaration (Loc,
15923 Build_Wrapper_Spec (Loc,
15925 Obj_Typ => Conc_Typ,
15927 Parameter_Specifications (
15930 Insert_After (Curr_Nod, Wrap_Spec);
15931 Curr_Nod := Wrap_Spec;
15933 Analyze (Wrap_Spec);
15936 Next_Elmt (Prim_Elmt);
15942 -- For non-concurrent types, transfer explicit primitives, but
15943 -- omit those inherited from the parent of the private view
15944 -- since they will be re-inherited later on.
15947 Full_List := Primitive_Operations (Full_T);
15949 while Present (Prim_Elmt) loop
15950 Prim := Node (Prim_Elmt);
15952 if Comes_From_Source (Prim)
15953 and then not Contains (Prim, Full_List)
15955 Append_Elmt (Prim, Full_List);
15958 Next_Elmt (Prim_Elmt);
15962 -- Untagged private view
15965 Full_List := Primitive_Operations (Full_T);
15967 -- In this case the partial view is untagged, so here we locate
15968 -- all of the earlier primitives that need to be treated as
15969 -- dispatching (those that appear between the two views). Note
15970 -- that these additional operations must all be new operations
15971 -- (any earlier operations that override inherited operations
15972 -- of the full view will already have been inserted in the
15973 -- primitives list, marked by Check_Operation_From_Private_View
15974 -- as dispatching. Note that implicit "/=" operators are
15975 -- excluded from being added to the primitives list since they
15976 -- shouldn't be treated as dispatching (tagged "/=" is handled
15979 Prim := Next_Entity (Full_T);
15980 while Present (Prim) and then Prim /= Priv_T loop
15981 if Ekind (Prim) = E_Procedure
15983 Ekind (Prim) = E_Function
15985 Disp_Typ := Find_Dispatching_Type (Prim);
15987 if Disp_Typ = Full_T
15988 and then (Chars (Prim) /= Name_Op_Ne
15989 or else Comes_From_Source (Prim))
15991 Check_Controlling_Formals (Full_T, Prim);
15993 if not Is_Dispatching_Operation (Prim) then
15994 Append_Elmt (Prim, Full_List);
15995 Set_Is_Dispatching_Operation (Prim, True);
15996 Set_DT_Position (Prim, No_Uint);
15999 elsif Is_Dispatching_Operation (Prim)
16000 and then Disp_Typ /= Full_T
16003 -- Verify that it is not otherwise controlled by a
16004 -- formal or a return value of type T.
16006 Check_Controlling_Formals (Disp_Typ, Prim);
16010 Next_Entity (Prim);
16014 -- For the tagged case, the two views can share the same
16015 -- Primitive Operation list and the same class wide type.
16016 -- Update attributes of the class-wide type which depend on
16017 -- the full declaration.
16019 if Is_Tagged_Type (Priv_T) then
16020 Set_Primitive_Operations (Priv_T, Full_List);
16021 Set_Class_Wide_Type
16022 (Base_Type (Full_T), Class_Wide_Type (Priv_T));
16024 Set_Has_Task (Class_Wide_Type (Priv_T), Has_Task (Full_T));
16029 -- Ada 2005 AI 161: Check preelaboratable initialization consistency
16031 if Known_To_Have_Preelab_Init (Priv_T) then
16033 -- Case where there is a pragma Preelaborable_Initialization. We
16034 -- always allow this in predefined units, which is a bit of a kludge,
16035 -- but it means we don't have to struggle to meet the requirements in
16036 -- the RM for having Preelaborable Initialization. Otherwise we
16037 -- require that the type meets the RM rules. But we can't check that
16038 -- yet, because of the rule about overriding Ininitialize, so we
16039 -- simply set a flag that will be checked at freeze time.
16041 if not In_Predefined_Unit (Full_T) then
16042 Set_Must_Have_Preelab_Init (Full_T);
16046 -- If pragma CPP_Class was applied to the private type declaration,
16047 -- propagate it now to the full type declaration.
16049 if Is_CPP_Class (Priv_T) then
16050 Set_Is_CPP_Class (Full_T);
16051 Set_Convention (Full_T, Convention_CPP);
16053 end Process_Full_View;
16055 -----------------------------------
16056 -- Process_Incomplete_Dependents --
16057 -----------------------------------
16059 procedure Process_Incomplete_Dependents
16061 Full_T : Entity_Id;
16064 Inc_Elmt : Elmt_Id;
16065 Priv_Dep : Entity_Id;
16066 New_Subt : Entity_Id;
16068 Disc_Constraint : Elist_Id;
16071 if No (Private_Dependents (Inc_T)) then
16075 -- Itypes that may be generated by the completion of an incomplete
16076 -- subtype are not used by the back-end and not attached to the tree.
16077 -- They are created only for constraint-checking purposes.
16079 Inc_Elmt := First_Elmt (Private_Dependents (Inc_T));
16080 while Present (Inc_Elmt) loop
16081 Priv_Dep := Node (Inc_Elmt);
16083 if Ekind (Priv_Dep) = E_Subprogram_Type then
16085 -- An Access_To_Subprogram type may have a return type or a
16086 -- parameter type that is incomplete. Replace with the full view.
16088 if Etype (Priv_Dep) = Inc_T then
16089 Set_Etype (Priv_Dep, Full_T);
16093 Formal : Entity_Id;
16096 Formal := First_Formal (Priv_Dep);
16097 while Present (Formal) loop
16098 if Etype (Formal) = Inc_T then
16099 Set_Etype (Formal, Full_T);
16102 Next_Formal (Formal);
16106 elsif Is_Overloadable (Priv_Dep) then
16108 -- A protected operation is never dispatching: only its
16109 -- wrapper operation (which has convention Ada) is.
16111 if Is_Tagged_Type (Full_T)
16112 and then Convention (Priv_Dep) /= Convention_Protected
16115 -- Subprogram has an access parameter whose designated type
16116 -- was incomplete. Reexamine declaration now, because it may
16117 -- be a primitive operation of the full type.
16119 Check_Operation_From_Incomplete_Type (Priv_Dep, Inc_T);
16120 Set_Is_Dispatching_Operation (Priv_Dep);
16121 Check_Controlling_Formals (Full_T, Priv_Dep);
16124 elsif Ekind (Priv_Dep) = E_Subprogram_Body then
16126 -- Can happen during processing of a body before the completion
16127 -- of a TA type. Ignore, because spec is also on dependent list.
16131 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
16132 -- corresponding subtype of the full view.
16134 elsif Ekind (Priv_Dep) = E_Incomplete_Subtype then
16135 Set_Subtype_Indication
16136 (Parent (Priv_Dep), New_Reference_To (Full_T, Sloc (Priv_Dep)));
16137 Set_Etype (Priv_Dep, Full_T);
16138 Set_Ekind (Priv_Dep, Subtype_Kind (Ekind (Full_T)));
16139 Set_Analyzed (Parent (Priv_Dep), False);
16141 -- Reanalyze the declaration, suppressing the call to
16142 -- Enter_Name to avoid duplicate names.
16144 Analyze_Subtype_Declaration
16145 (N => Parent (Priv_Dep),
16148 -- Dependent is a subtype
16151 -- We build a new subtype indication using the full view of the
16152 -- incomplete parent. The discriminant constraints have been
16153 -- elaborated already at the point of the subtype declaration.
16155 New_Subt := Create_Itype (E_Void, N);
16157 if Has_Discriminants (Full_T) then
16158 Disc_Constraint := Discriminant_Constraint (Priv_Dep);
16160 Disc_Constraint := No_Elist;
16163 Build_Discriminated_Subtype (Full_T, New_Subt, Disc_Constraint, N);
16164 Set_Full_View (Priv_Dep, New_Subt);
16167 Next_Elmt (Inc_Elmt);
16169 end Process_Incomplete_Dependents;
16171 --------------------------------
16172 -- Process_Range_Expr_In_Decl --
16173 --------------------------------
16175 procedure Process_Range_Expr_In_Decl
16178 Check_List : List_Id := Empty_List;
16179 R_Check_Off : Boolean := False)
16182 R_Checks : Check_Result;
16183 Type_Decl : Node_Id;
16184 Def_Id : Entity_Id;
16187 Analyze_And_Resolve (R, Base_Type (T));
16189 if Nkind (R) = N_Range then
16190 Lo := Low_Bound (R);
16191 Hi := High_Bound (R);
16193 -- We need to ensure validity of the bounds here, because if we
16194 -- go ahead and do the expansion, then the expanded code will get
16195 -- analyzed with range checks suppressed and we miss the check.
16197 Validity_Check_Range (R);
16199 -- If there were errors in the declaration, try and patch up some
16200 -- common mistakes in the bounds. The cases handled are literals
16201 -- which are Integer where the expected type is Real and vice versa.
16202 -- These corrections allow the compilation process to proceed further
16203 -- along since some basic assumptions of the format of the bounds
16206 if Etype (R) = Any_Type then
16208 if Nkind (Lo) = N_Integer_Literal and then Is_Real_Type (T) then
16210 Make_Real_Literal (Sloc (Lo), UR_From_Uint (Intval (Lo))));
16212 elsif Nkind (Hi) = N_Integer_Literal and then Is_Real_Type (T) then
16214 Make_Real_Literal (Sloc (Hi), UR_From_Uint (Intval (Hi))));
16216 elsif Nkind (Lo) = N_Real_Literal and then Is_Integer_Type (T) then
16218 Make_Integer_Literal (Sloc (Lo), UR_To_Uint (Realval (Lo))));
16220 elsif Nkind (Hi) = N_Real_Literal and then Is_Integer_Type (T) then
16222 Make_Integer_Literal (Sloc (Hi), UR_To_Uint (Realval (Hi))));
16229 -- If the bounds of the range have been mistakenly given as string
16230 -- literals (perhaps in place of character literals), then an error
16231 -- has already been reported, but we rewrite the string literal as a
16232 -- bound of the range's type to avoid blowups in later processing
16233 -- that looks at static values.
16235 if Nkind (Lo) = N_String_Literal then
16237 Make_Attribute_Reference (Sloc (Lo),
16238 Attribute_Name => Name_First,
16239 Prefix => New_Reference_To (T, Sloc (Lo))));
16240 Analyze_And_Resolve (Lo);
16243 if Nkind (Hi) = N_String_Literal then
16245 Make_Attribute_Reference (Sloc (Hi),
16246 Attribute_Name => Name_First,
16247 Prefix => New_Reference_To (T, Sloc (Hi))));
16248 Analyze_And_Resolve (Hi);
16251 -- If bounds aren't scalar at this point then exit, avoiding
16252 -- problems with further processing of the range in this procedure.
16254 if not Is_Scalar_Type (Etype (Lo)) then
16258 -- Resolve (actually Sem_Eval) has checked that the bounds are in
16259 -- then range of the base type. Here we check whether the bounds
16260 -- are in the range of the subtype itself. Note that if the bounds
16261 -- represent the null range the Constraint_Error exception should
16264 -- ??? The following code should be cleaned up as follows
16266 -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
16267 -- is done in the call to Range_Check (R, T); below
16269 -- 2. The use of R_Check_Off should be investigated and possibly
16270 -- removed, this would clean up things a bit.
16272 if Is_Null_Range (Lo, Hi) then
16276 -- Capture values of bounds and generate temporaries for them
16277 -- if needed, before applying checks, since checks may cause
16278 -- duplication of the expression without forcing evaluation.
16280 if Expander_Active then
16281 Force_Evaluation (Lo);
16282 Force_Evaluation (Hi);
16285 -- We use a flag here instead of suppressing checks on the
16286 -- type because the type we check against isn't necessarily
16287 -- the place where we put the check.
16289 if not R_Check_Off then
16290 R_Checks := Get_Range_Checks (R, T);
16292 -- Look up tree to find an appropriate insertion point.
16293 -- This seems really junk code, and very brittle, couldn't
16294 -- we just use an insert actions call of some kind ???
16296 Type_Decl := Parent (R);
16297 while Present (Type_Decl) and then not
16298 (Nkind_In (Type_Decl, N_Full_Type_Declaration,
16299 N_Subtype_Declaration,
16301 N_Task_Type_Declaration)
16303 Nkind_In (Type_Decl, N_Single_Task_Declaration,
16304 N_Protected_Type_Declaration,
16305 N_Single_Protected_Declaration))
16307 Type_Decl := Parent (Type_Decl);
16310 -- Why would Type_Decl not be present??? Without this test,
16311 -- short regression tests fail.
16313 if Present (Type_Decl) then
16315 -- Case of loop statement (more comments ???)
16317 if Nkind (Type_Decl) = N_Loop_Statement then
16322 Indic := Parent (R);
16323 while Present (Indic)
16324 and then Nkind (Indic) /= N_Subtype_Indication
16326 Indic := Parent (Indic);
16329 if Present (Indic) then
16330 Def_Id := Etype (Subtype_Mark (Indic));
16332 Insert_Range_Checks
16338 Do_Before => True);
16342 -- All other cases (more comments ???)
16345 Def_Id := Defining_Identifier (Type_Decl);
16347 if (Ekind (Def_Id) = E_Record_Type
16348 and then Depends_On_Discriminant (R))
16350 (Ekind (Def_Id) = E_Protected_Type
16351 and then Has_Discriminants (Def_Id))
16353 Append_Range_Checks
16354 (R_Checks, Check_List, Def_Id, Sloc (Type_Decl), R);
16357 Insert_Range_Checks
16358 (R_Checks, Type_Decl, Def_Id, Sloc (Type_Decl), R);
16366 elsif Expander_Active then
16367 Get_Index_Bounds (R, Lo, Hi);
16368 Force_Evaluation (Lo);
16369 Force_Evaluation (Hi);
16371 end Process_Range_Expr_In_Decl;
16373 --------------------------------------
16374 -- Process_Real_Range_Specification --
16375 --------------------------------------
16377 procedure Process_Real_Range_Specification (Def : Node_Id) is
16378 Spec : constant Node_Id := Real_Range_Specification (Def);
16381 Err : Boolean := False;
16383 procedure Analyze_Bound (N : Node_Id);
16384 -- Analyze and check one bound
16386 -------------------
16387 -- Analyze_Bound --
16388 -------------------
16390 procedure Analyze_Bound (N : Node_Id) is
16392 Analyze_And_Resolve (N, Any_Real);
16394 if not Is_OK_Static_Expression (N) then
16395 Flag_Non_Static_Expr
16396 ("bound in real type definition is not static!", N);
16401 -- Start of processing for Process_Real_Range_Specification
16404 if Present (Spec) then
16405 Lo := Low_Bound (Spec);
16406 Hi := High_Bound (Spec);
16407 Analyze_Bound (Lo);
16408 Analyze_Bound (Hi);
16410 -- If error, clear away junk range specification
16413 Set_Real_Range_Specification (Def, Empty);
16416 end Process_Real_Range_Specification;
16418 ---------------------
16419 -- Process_Subtype --
16420 ---------------------
16422 function Process_Subtype
16424 Related_Nod : Node_Id;
16425 Related_Id : Entity_Id := Empty;
16426 Suffix : Character := ' ') return Entity_Id
16429 Def_Id : Entity_Id;
16430 Error_Node : Node_Id;
16431 Full_View_Id : Entity_Id;
16432 Subtype_Mark_Id : Entity_Id;
16434 May_Have_Null_Exclusion : Boolean;
16436 procedure Check_Incomplete (T : Entity_Id);
16437 -- Called to verify that an incomplete type is not used prematurely
16439 ----------------------
16440 -- Check_Incomplete --
16441 ----------------------
16443 procedure Check_Incomplete (T : Entity_Id) is
16445 -- Ada 2005 (AI-412): Incomplete subtypes are legal
16447 if Ekind (Root_Type (Entity (T))) = E_Incomplete_Type
16449 not (Ada_Version >= Ada_05
16451 (Nkind (Parent (T)) = N_Subtype_Declaration
16453 (Nkind (Parent (T)) = N_Subtype_Indication
16454 and then Nkind (Parent (Parent (T))) =
16455 N_Subtype_Declaration)))
16457 Error_Msg_N ("invalid use of type before its full declaration", T);
16459 end Check_Incomplete;
16461 -- Start of processing for Process_Subtype
16464 -- Case of no constraints present
16466 if Nkind (S) /= N_Subtype_Indication then
16468 Check_Incomplete (S);
16471 -- Ada 2005 (AI-231): Static check
16473 if Ada_Version >= Ada_05
16474 and then Present (P)
16475 and then Null_Exclusion_Present (P)
16476 and then Nkind (P) /= N_Access_To_Object_Definition
16477 and then not Is_Access_Type (Entity (S))
16479 Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
16482 -- The following is ugly, can't we have a range or even a flag???
16484 May_Have_Null_Exclusion :=
16485 Nkind_In (P, N_Access_Definition,
16486 N_Access_Function_Definition,
16487 N_Access_Procedure_Definition,
16488 N_Access_To_Object_Definition,
16490 N_Component_Definition)
16492 Nkind_In (P, N_Derived_Type_Definition,
16493 N_Discriminant_Specification,
16494 N_Object_Declaration,
16495 N_Parameter_Specification,
16496 N_Subtype_Declaration);
16498 -- Create an Itype that is a duplicate of Entity (S) but with the
16499 -- null-exclusion attribute
16501 if May_Have_Null_Exclusion
16502 and then Is_Access_Type (Entity (S))
16503 and then Null_Exclusion_Present (P)
16505 -- No need to check the case of an access to object definition.
16506 -- It is correct to define double not-null pointers.
16509 -- type Not_Null_Int_Ptr is not null access Integer;
16510 -- type Acc is not null access Not_Null_Int_Ptr;
16512 and then Nkind (P) /= N_Access_To_Object_Definition
16514 if Can_Never_Be_Null (Entity (S)) then
16515 case Nkind (Related_Nod) is
16516 when N_Full_Type_Declaration =>
16517 if Nkind (Type_Definition (Related_Nod))
16518 in N_Array_Type_Definition
16522 (Component_Definition
16523 (Type_Definition (Related_Nod)));
16526 Subtype_Indication (Type_Definition (Related_Nod));
16529 when N_Subtype_Declaration =>
16530 Error_Node := Subtype_Indication (Related_Nod);
16532 when N_Object_Declaration =>
16533 Error_Node := Object_Definition (Related_Nod);
16535 when N_Component_Declaration =>
16537 Subtype_Indication (Component_Definition (Related_Nod));
16540 pragma Assert (False);
16541 Error_Node := Related_Nod;
16545 ("`NOT NULL` not allowed (& already excludes null)",
16551 Create_Null_Excluding_Itype
16553 Related_Nod => P));
16554 Set_Entity (S, Etype (S));
16559 -- Case of constraint present, so that we have an N_Subtype_Indication
16560 -- node (this node is created only if constraints are present).
16563 Find_Type (Subtype_Mark (S));
16565 if Nkind (Parent (S)) /= N_Access_To_Object_Definition
16567 (Nkind (Parent (S)) = N_Subtype_Declaration
16568 and then Is_Itype (Defining_Identifier (Parent (S))))
16570 Check_Incomplete (Subtype_Mark (S));
16574 Subtype_Mark_Id := Entity (Subtype_Mark (S));
16576 -- Explicit subtype declaration case
16578 if Nkind (P) = N_Subtype_Declaration then
16579 Def_Id := Defining_Identifier (P);
16581 -- Explicit derived type definition case
16583 elsif Nkind (P) = N_Derived_Type_Definition then
16584 Def_Id := Defining_Identifier (Parent (P));
16586 -- Implicit case, the Def_Id must be created as an implicit type.
16587 -- The one exception arises in the case of concurrent types, array
16588 -- and access types, where other subsidiary implicit types may be
16589 -- created and must appear before the main implicit type. In these
16590 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
16591 -- has not yet been called to create Def_Id.
16594 if Is_Array_Type (Subtype_Mark_Id)
16595 or else Is_Concurrent_Type (Subtype_Mark_Id)
16596 or else Is_Access_Type (Subtype_Mark_Id)
16600 -- For the other cases, we create a new unattached Itype,
16601 -- and set the indication to ensure it gets attached later.
16605 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16609 -- If the kind of constraint is invalid for this kind of type,
16610 -- then give an error, and then pretend no constraint was given.
16612 if not Is_Valid_Constraint_Kind
16613 (Ekind (Subtype_Mark_Id), Nkind (Constraint (S)))
16616 ("incorrect constraint for this kind of type", Constraint (S));
16618 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
16620 -- Set Ekind of orphan itype, to prevent cascaded errors
16622 if Present (Def_Id) then
16623 Set_Ekind (Def_Id, Ekind (Any_Type));
16626 -- Make recursive call, having got rid of the bogus constraint
16628 return Process_Subtype (S, Related_Nod, Related_Id, Suffix);
16631 -- Remaining processing depends on type
16633 case Ekind (Subtype_Mark_Id) is
16634 when Access_Kind =>
16635 Constrain_Access (Def_Id, S, Related_Nod);
16638 and then Is_Itype (Designated_Type (Def_Id))
16639 and then Nkind (Related_Nod) = N_Subtype_Declaration
16640 and then not Is_Incomplete_Type (Designated_Type (Def_Id))
16642 Build_Itype_Reference
16643 (Designated_Type (Def_Id), Related_Nod);
16647 Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix);
16649 when Decimal_Fixed_Point_Kind =>
16650 Constrain_Decimal (Def_Id, S);
16652 when Enumeration_Kind =>
16653 Constrain_Enumeration (Def_Id, S);
16655 when Ordinary_Fixed_Point_Kind =>
16656 Constrain_Ordinary_Fixed (Def_Id, S);
16659 Constrain_Float (Def_Id, S);
16661 when Integer_Kind =>
16662 Constrain_Integer (Def_Id, S);
16664 when E_Record_Type |
16667 E_Incomplete_Type =>
16668 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16670 when Private_Kind =>
16671 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16672 Set_Private_Dependents (Def_Id, New_Elmt_List);
16674 -- In case of an invalid constraint prevent further processing
16675 -- since the type constructed is missing expected fields.
16677 if Etype (Def_Id) = Any_Type then
16681 -- If the full view is that of a task with discriminants,
16682 -- we must constrain both the concurrent type and its
16683 -- corresponding record type. Otherwise we will just propagate
16684 -- the constraint to the full view, if available.
16686 if Present (Full_View (Subtype_Mark_Id))
16687 and then Has_Discriminants (Subtype_Mark_Id)
16688 and then Is_Concurrent_Type (Full_View (Subtype_Mark_Id))
16691 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16693 Set_Entity (Subtype_Mark (S), Full_View (Subtype_Mark_Id));
16694 Constrain_Concurrent (Full_View_Id, S,
16695 Related_Nod, Related_Id, Suffix);
16696 Set_Entity (Subtype_Mark (S), Subtype_Mark_Id);
16697 Set_Full_View (Def_Id, Full_View_Id);
16699 -- Introduce an explicit reference to the private subtype,
16700 -- to prevent scope anomalies in gigi if first use appears
16701 -- in a nested context, e.g. a later function body.
16702 -- Should this be generated in other contexts than a full
16703 -- type declaration?
16705 if Is_Itype (Def_Id)
16707 Nkind (Parent (P)) = N_Full_Type_Declaration
16709 Build_Itype_Reference (Def_Id, Parent (P));
16713 Prepare_Private_Subtype_Completion (Def_Id, Related_Nod);
16716 when Concurrent_Kind =>
16717 Constrain_Concurrent (Def_Id, S,
16718 Related_Nod, Related_Id, Suffix);
16721 Error_Msg_N ("invalid subtype mark in subtype indication", S);
16724 -- Size and Convention are always inherited from the base type
16726 Set_Size_Info (Def_Id, (Subtype_Mark_Id));
16727 Set_Convention (Def_Id, Convention (Subtype_Mark_Id));
16731 end Process_Subtype;
16733 ---------------------------------------
16734 -- Check_Anonymous_Access_Components --
16735 ---------------------------------------
16737 procedure Check_Anonymous_Access_Components
16738 (Typ_Decl : Node_Id;
16741 Comp_List : Node_Id)
16743 Loc : constant Source_Ptr := Sloc (Typ_Decl);
16744 Anon_Access : Entity_Id;
16747 Comp_Def : Node_Id;
16749 Type_Def : Node_Id;
16751 procedure Build_Incomplete_Type_Declaration;
16752 -- If the record type contains components that include an access to the
16753 -- current record, then create an incomplete type declaration for the
16754 -- record, to be used as the designated type of the anonymous access.
16755 -- This is done only once, and only if there is no previous partial
16756 -- view of the type.
16758 function Designates_T (Subt : Node_Id) return Boolean;
16759 -- Check whether a node designates the enclosing record type, or 'Class
16762 function Mentions_T (Acc_Def : Node_Id) return Boolean;
16763 -- Check whether an access definition includes a reference to
16764 -- the enclosing record type. The reference can be a subtype mark
16765 -- in the access definition itself, a 'Class attribute reference, or
16766 -- recursively a reference appearing in a parameter specification
16767 -- or result definition of an access_to_subprogram definition.
16769 --------------------------------------
16770 -- Build_Incomplete_Type_Declaration --
16771 --------------------------------------
16773 procedure Build_Incomplete_Type_Declaration is
16778 -- Is_Tagged indicates whether the type is tagged. It is tagged if
16779 -- it's "is new ... with record" or else "is tagged record ...".
16781 Is_Tagged : constant Boolean :=
16782 (Nkind (Type_Definition (Typ_Decl)) = N_Derived_Type_Definition
16785 (Record_Extension_Part (Type_Definition (Typ_Decl))))
16787 (Nkind (Type_Definition (Typ_Decl)) = N_Record_Definition
16788 and then Tagged_Present (Type_Definition (Typ_Decl)));
16791 -- If there is a previous partial view, no need to create a new one
16792 -- If the partial view, given by Prev, is incomplete, If Prev is
16793 -- a private declaration, full declaration is flagged accordingly.
16795 if Prev /= Typ then
16797 Make_Class_Wide_Type (Prev);
16798 Set_Class_Wide_Type (Typ, Class_Wide_Type (Prev));
16799 Set_Etype (Class_Wide_Type (Typ), Typ);
16804 elsif Has_Private_Declaration (Typ) then
16806 -- If we refer to T'Class inside T, and T is the completion of a
16807 -- private type, then we need to make sure the class-wide type
16811 Make_Class_Wide_Type (Typ);
16816 -- If there was a previous anonymous access type, the incomplete
16817 -- type declaration will have been created already.
16819 elsif Present (Current_Entity (Typ))
16820 and then Ekind (Current_Entity (Typ)) = E_Incomplete_Type
16821 and then Full_View (Current_Entity (Typ)) = Typ
16826 Inc_T := Make_Defining_Identifier (Loc, Chars (Typ));
16827 Decl := Make_Incomplete_Type_Declaration (Loc, Inc_T);
16829 -- Type has already been inserted into the current scope.
16830 -- Remove it, and add incomplete declaration for type, so
16831 -- that subsequent anonymous access types can use it.
16832 -- The entity is unchained from the homonym list and from
16833 -- immediate visibility. After analysis, the entity in the
16834 -- incomplete declaration becomes immediately visible in the
16835 -- record declaration that follows.
16837 H := Current_Entity (Typ);
16840 Set_Name_Entity_Id (Chars (Typ), Homonym (Typ));
16843 and then Homonym (H) /= Typ
16845 H := Homonym (Typ);
16848 Set_Homonym (H, Homonym (Typ));
16851 Insert_Before (Typ_Decl, Decl);
16853 Set_Full_View (Inc_T, Typ);
16856 -- Create a common class-wide type for both views, and set
16857 -- the Etype of the class-wide type to the full view.
16859 Make_Class_Wide_Type (Inc_T);
16860 Set_Class_Wide_Type (Typ, Class_Wide_Type (Inc_T));
16861 Set_Etype (Class_Wide_Type (Typ), Typ);
16864 end Build_Incomplete_Type_Declaration;
16870 function Designates_T (Subt : Node_Id) return Boolean is
16871 Type_Id : constant Name_Id := Chars (Typ);
16873 function Names_T (Nam : Node_Id) return Boolean;
16874 -- The record type has not been introduced in the current scope
16875 -- yet, so we must examine the name of the type itself, either
16876 -- an identifier T, or an expanded name of the form P.T, where
16877 -- P denotes the current scope.
16883 function Names_T (Nam : Node_Id) return Boolean is
16885 if Nkind (Nam) = N_Identifier then
16886 return Chars (Nam) = Type_Id;
16888 elsif Nkind (Nam) = N_Selected_Component then
16889 if Chars (Selector_Name (Nam)) = Type_Id then
16890 if Nkind (Prefix (Nam)) = N_Identifier then
16891 return Chars (Prefix (Nam)) = Chars (Current_Scope);
16893 elsif Nkind (Prefix (Nam)) = N_Selected_Component then
16894 return Chars (Selector_Name (Prefix (Nam))) =
16895 Chars (Current_Scope);
16909 -- Start of processing for Designates_T
16912 if Nkind (Subt) = N_Identifier then
16913 return Chars (Subt) = Type_Id;
16915 -- Reference can be through an expanded name which has not been
16916 -- analyzed yet, and which designates enclosing scopes.
16918 elsif Nkind (Subt) = N_Selected_Component then
16919 if Names_T (Subt) then
16922 -- Otherwise it must denote an entity that is already visible.
16923 -- The access definition may name a subtype of the enclosing
16924 -- type, if there is a previous incomplete declaration for it.
16927 Find_Selected_Component (Subt);
16929 Is_Entity_Name (Subt)
16930 and then Scope (Entity (Subt)) = Current_Scope
16932 (Chars (Base_Type (Entity (Subt))) = Type_Id
16934 (Is_Class_Wide_Type (Entity (Subt))
16936 Chars (Etype (Base_Type (Entity (Subt)))) =
16940 -- A reference to the current type may appear as the prefix of
16941 -- a 'Class attribute.
16943 elsif Nkind (Subt) = N_Attribute_Reference
16944 and then Attribute_Name (Subt) = Name_Class
16946 return Names_T (Prefix (Subt));
16957 function Mentions_T (Acc_Def : Node_Id) return Boolean is
16958 Param_Spec : Node_Id;
16960 Acc_Subprg : constant Node_Id :=
16961 Access_To_Subprogram_Definition (Acc_Def);
16964 if No (Acc_Subprg) then
16965 return Designates_T (Subtype_Mark (Acc_Def));
16968 -- Component is an access_to_subprogram: examine its formals,
16969 -- and result definition in the case of an access_to_function.
16971 Param_Spec := First (Parameter_Specifications (Acc_Subprg));
16972 while Present (Param_Spec) loop
16973 if Nkind (Parameter_Type (Param_Spec)) = N_Access_Definition
16974 and then Mentions_T (Parameter_Type (Param_Spec))
16978 elsif Designates_T (Parameter_Type (Param_Spec)) then
16985 if Nkind (Acc_Subprg) = N_Access_Function_Definition then
16986 if Nkind (Result_Definition (Acc_Subprg)) =
16987 N_Access_Definition
16989 return Mentions_T (Result_Definition (Acc_Subprg));
16991 return Designates_T (Result_Definition (Acc_Subprg));
16998 -- Start of processing for Check_Anonymous_Access_Components
17001 if No (Comp_List) then
17005 Comp := First (Component_Items (Comp_List));
17006 while Present (Comp) loop
17007 if Nkind (Comp) = N_Component_Declaration
17009 (Access_Definition (Component_Definition (Comp)))
17011 Mentions_T (Access_Definition (Component_Definition (Comp)))
17013 Comp_Def := Component_Definition (Comp);
17015 Access_To_Subprogram_Definition
17016 (Access_Definition (Comp_Def));
17018 Build_Incomplete_Type_Declaration;
17020 Make_Defining_Identifier (Loc,
17021 Chars => New_Internal_Name ('S'));
17023 -- Create a declaration for the anonymous access type: either
17024 -- an access_to_object or an access_to_subprogram.
17026 if Present (Acc_Def) then
17027 if Nkind (Acc_Def) = N_Access_Function_Definition then
17029 Make_Access_Function_Definition (Loc,
17030 Parameter_Specifications =>
17031 Parameter_Specifications (Acc_Def),
17032 Result_Definition => Result_Definition (Acc_Def));
17035 Make_Access_Procedure_Definition (Loc,
17036 Parameter_Specifications =>
17037 Parameter_Specifications (Acc_Def));
17042 Make_Access_To_Object_Definition (Loc,
17043 Subtype_Indication =>
17046 (Access_Definition (Comp_Def))));
17048 Set_Constant_Present
17049 (Type_Def, Constant_Present (Access_Definition (Comp_Def)));
17051 (Type_Def, All_Present (Access_Definition (Comp_Def)));
17054 Set_Null_Exclusion_Present
17056 Null_Exclusion_Present (Access_Definition (Comp_Def)));
17059 Make_Full_Type_Declaration (Loc,
17060 Defining_Identifier => Anon_Access,
17061 Type_Definition => Type_Def);
17063 Insert_Before (Typ_Decl, Decl);
17066 -- If an access to object, Preserve entity of designated type,
17067 -- for ASIS use, before rewriting the component definition.
17069 if No (Acc_Def) then
17074 Desig := Entity (Subtype_Indication (Type_Def));
17076 -- If the access definition is to the current record,
17077 -- the visible entity at this point is an incomplete
17078 -- type. Retrieve the full view to simplify ASIS queries
17080 if Ekind (Desig) = E_Incomplete_Type then
17081 Desig := Full_View (Desig);
17085 (Subtype_Mark (Access_Definition (Comp_Def)), Desig);
17090 Make_Component_Definition (Loc,
17091 Subtype_Indication =>
17092 New_Occurrence_Of (Anon_Access, Loc)));
17094 if Ekind (Designated_Type (Anon_Access)) = E_Subprogram_Type then
17095 Set_Ekind (Anon_Access, E_Anonymous_Access_Subprogram_Type);
17097 Set_Ekind (Anon_Access, E_Anonymous_Access_Type);
17100 Set_Is_Local_Anonymous_Access (Anon_Access);
17106 if Present (Variant_Part (Comp_List)) then
17110 V := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
17111 while Present (V) loop
17112 Check_Anonymous_Access_Components
17113 (Typ_Decl, Typ, Prev, Component_List (V));
17114 Next_Non_Pragma (V);
17118 end Check_Anonymous_Access_Components;
17120 --------------------------------
17121 -- Preanalyze_Spec_Expression --
17122 --------------------------------
17124 procedure Preanalyze_Spec_Expression (N : Node_Id; T : Entity_Id) is
17125 Save_In_Spec_Expression : constant Boolean := In_Spec_Expression;
17127 In_Spec_Expression := True;
17128 Preanalyze_And_Resolve (N, T);
17129 In_Spec_Expression := Save_In_Spec_Expression;
17130 end Preanalyze_Spec_Expression;
17132 -----------------------------
17133 -- Record_Type_Declaration --
17134 -----------------------------
17136 procedure Record_Type_Declaration
17141 Def : constant Node_Id := Type_Definition (N);
17142 Is_Tagged : Boolean;
17143 Tag_Comp : Entity_Id;
17146 -- These flags must be initialized before calling Process_Discriminants
17147 -- because this routine makes use of them.
17149 Set_Ekind (T, E_Record_Type);
17151 Init_Size_Align (T);
17152 Set_Interfaces (T, No_Elist);
17153 Set_Stored_Constraint (T, No_Elist);
17157 if Ada_Version < Ada_05
17158 or else not Interface_Present (Def)
17160 -- The flag Is_Tagged_Type might have already been set by
17161 -- Find_Type_Name if it detected an error for declaration T. This
17162 -- arises in the case of private tagged types where the full view
17163 -- omits the word tagged.
17166 Tagged_Present (Def)
17167 or else (Serious_Errors_Detected > 0 and then Is_Tagged_Type (T));
17169 Set_Is_Tagged_Type (T, Is_Tagged);
17170 Set_Is_Limited_Record (T, Limited_Present (Def));
17172 -- Type is abstract if full declaration carries keyword, or if
17173 -- previous partial view did.
17175 Set_Is_Abstract_Type (T, Is_Abstract_Type (T)
17176 or else Abstract_Present (Def));
17180 Analyze_Interface_Declaration (T, Def);
17182 if Present (Discriminant_Specifications (N)) then
17184 ("interface types cannot have discriminants",
17185 Defining_Identifier
17186 (First (Discriminant_Specifications (N))));
17190 -- First pass: if there are self-referential access components,
17191 -- create the required anonymous access type declarations, and if
17192 -- need be an incomplete type declaration for T itself.
17194 Check_Anonymous_Access_Components (N, T, Prev, Component_List (Def));
17196 if Ada_Version >= Ada_05
17197 and then Present (Interface_List (Def))
17199 Check_Interfaces (N, Def);
17202 Ifaces_List : Elist_Id;
17205 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
17206 -- already in the parents.
17210 Ifaces_List => Ifaces_List,
17211 Exclude_Parents => True);
17213 Set_Interfaces (T, Ifaces_List);
17217 -- Records constitute a scope for the component declarations within.
17218 -- The scope is created prior to the processing of these declarations.
17219 -- Discriminants are processed first, so that they are visible when
17220 -- processing the other components. The Ekind of the record type itself
17221 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
17223 -- Enter record scope
17227 -- If an incomplete or private type declaration was already given for
17228 -- the type, then this scope already exists, and the discriminants have
17229 -- been declared within. We must verify that the full declaration
17230 -- matches the incomplete one.
17232 Check_Or_Process_Discriminants (N, T, Prev);
17234 Set_Is_Constrained (T, not Has_Discriminants (T));
17235 Set_Has_Delayed_Freeze (T, True);
17237 -- For tagged types add a manually analyzed component corresponding
17238 -- to the component _tag, the corresponding piece of tree will be
17239 -- expanded as part of the freezing actions if it is not a CPP_Class.
17243 -- Do not add the tag unless we are in expansion mode
17245 if Expander_Active then
17246 Tag_Comp := Make_Defining_Identifier (Sloc (Def), Name_uTag);
17247 Enter_Name (Tag_Comp);
17249 Set_Ekind (Tag_Comp, E_Component);
17250 Set_Is_Tag (Tag_Comp);
17251 Set_Is_Aliased (Tag_Comp);
17252 Set_Etype (Tag_Comp, RTE (RE_Tag));
17253 Set_DT_Entry_Count (Tag_Comp, No_Uint);
17254 Set_Original_Record_Component (Tag_Comp, Tag_Comp);
17255 Init_Component_Location (Tag_Comp);
17257 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
17258 -- implemented interfaces.
17260 if Has_Interfaces (T) then
17261 Add_Interface_Tag_Components (N, T);
17265 Make_Class_Wide_Type (T);
17266 Set_Primitive_Operations (T, New_Elmt_List);
17269 -- We must suppress range checks when processing the components
17270 -- of a record in the presence of discriminants, since we don't
17271 -- want spurious checks to be generated during their analysis, but
17272 -- must reset the Suppress_Range_Checks flags after having processed
17273 -- the record definition.
17275 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
17276 -- couldn't we just use the normal range check suppression method here.
17277 -- That would seem cleaner ???
17279 if Has_Discriminants (T) and then not Range_Checks_Suppressed (T) then
17280 Set_Kill_Range_Checks (T, True);
17281 Record_Type_Definition (Def, Prev);
17282 Set_Kill_Range_Checks (T, False);
17284 Record_Type_Definition (Def, Prev);
17287 -- Exit from record scope
17291 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
17292 -- the implemented interfaces and associate them an aliased entity.
17295 and then not Is_Empty_List (Interface_List (Def))
17297 Derive_Progenitor_Subprograms (T, T);
17299 end Record_Type_Declaration;
17301 ----------------------------
17302 -- Record_Type_Definition --
17303 ----------------------------
17305 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id) is
17306 Component : Entity_Id;
17307 Ctrl_Components : Boolean := False;
17308 Final_Storage_Only : Boolean;
17312 if Ekind (Prev_T) = E_Incomplete_Type then
17313 T := Full_View (Prev_T);
17318 Final_Storage_Only := not Is_Controlled (T);
17320 -- Ada 2005: check whether an explicit Limited is present in a derived
17321 -- type declaration.
17323 if Nkind (Parent (Def)) = N_Derived_Type_Definition
17324 and then Limited_Present (Parent (Def))
17326 Set_Is_Limited_Record (T);
17329 -- If the component list of a record type is defined by the reserved
17330 -- word null and there is no discriminant part, then the record type has
17331 -- no components and all records of the type are null records (RM 3.7)
17332 -- This procedure is also called to process the extension part of a
17333 -- record extension, in which case the current scope may have inherited
17337 or else No (Component_List (Def))
17338 or else Null_Present (Component_List (Def))
17343 Analyze_Declarations (Component_Items (Component_List (Def)));
17345 if Present (Variant_Part (Component_List (Def))) then
17346 Analyze (Variant_Part (Component_List (Def)));
17350 -- After completing the semantic analysis of the record definition,
17351 -- record components, both new and inherited, are accessible. Set their
17352 -- kind accordingly. Exclude malformed itypes from illegal declarations,
17353 -- whose Ekind may be void.
17355 Component := First_Entity (Current_Scope);
17356 while Present (Component) loop
17357 if Ekind (Component) = E_Void
17358 and then not Is_Itype (Component)
17360 Set_Ekind (Component, E_Component);
17361 Init_Component_Location (Component);
17364 if Has_Task (Etype (Component)) then
17368 if Ekind (Component) /= E_Component then
17371 elsif Has_Controlled_Component (Etype (Component))
17372 or else (Chars (Component) /= Name_uParent
17373 and then Is_Controlled (Etype (Component)))
17375 Set_Has_Controlled_Component (T, True);
17376 Final_Storage_Only :=
17378 and then Finalize_Storage_Only (Etype (Component));
17379 Ctrl_Components := True;
17382 Next_Entity (Component);
17385 -- A Type is Finalize_Storage_Only only if all its controlled components
17388 if Ctrl_Components then
17389 Set_Finalize_Storage_Only (T, Final_Storage_Only);
17392 -- Place reference to end record on the proper entity, which may
17393 -- be a partial view.
17395 if Present (Def) then
17396 Process_End_Label (Def, 'e', Prev_T);
17398 end Record_Type_Definition;
17400 ------------------------
17401 -- Replace_Components --
17402 ------------------------
17404 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id) is
17405 function Process (N : Node_Id) return Traverse_Result;
17411 function Process (N : Node_Id) return Traverse_Result is
17415 if Nkind (N) = N_Discriminant_Specification then
17416 Comp := First_Discriminant (Typ);
17417 while Present (Comp) loop
17418 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17419 Set_Defining_Identifier (N, Comp);
17423 Next_Discriminant (Comp);
17426 elsif Nkind (N) = N_Component_Declaration then
17427 Comp := First_Component (Typ);
17428 while Present (Comp) loop
17429 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17430 Set_Defining_Identifier (N, Comp);
17434 Next_Component (Comp);
17441 procedure Replace is new Traverse_Proc (Process);
17443 -- Start of processing for Replace_Components
17447 end Replace_Components;
17449 -------------------------------
17450 -- Set_Completion_Referenced --
17451 -------------------------------
17453 procedure Set_Completion_Referenced (E : Entity_Id) is
17455 -- If in main unit, mark entity that is a completion as referenced,
17456 -- warnings go on the partial view when needed.
17458 if In_Extended_Main_Source_Unit (E) then
17459 Set_Referenced (E);
17461 end Set_Completion_Referenced;
17463 ---------------------
17464 -- Set_Fixed_Range --
17465 ---------------------
17467 -- The range for fixed-point types is complicated by the fact that we
17468 -- do not know the exact end points at the time of the declaration. This
17469 -- is true for three reasons:
17471 -- A size clause may affect the fudging of the end-points
17472 -- A small clause may affect the values of the end-points
17473 -- We try to include the end-points if it does not affect the size
17475 -- This means that the actual end-points must be established at the point
17476 -- when the type is frozen. Meanwhile, we first narrow the range as
17477 -- permitted (so that it will fit if necessary in a small specified size),
17478 -- and then build a range subtree with these narrowed bounds.
17480 -- Set_Fixed_Range constructs the range from real literal values, and sets
17481 -- the range as the Scalar_Range of the given fixed-point type entity.
17483 -- The parent of this range is set to point to the entity so that it is
17484 -- properly hooked into the tree (unlike normal Scalar_Range entries for
17485 -- other scalar types, which are just pointers to the range in the
17486 -- original tree, this would otherwise be an orphan).
17488 -- The tree is left unanalyzed. When the type is frozen, the processing
17489 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
17490 -- analyzed, and uses this as an indication that it should complete
17491 -- work on the range (it will know the final small and size values).
17493 procedure Set_Fixed_Range
17499 S : constant Node_Id :=
17501 Low_Bound => Make_Real_Literal (Loc, Lo),
17502 High_Bound => Make_Real_Literal (Loc, Hi));
17504 Set_Scalar_Range (E, S);
17506 end Set_Fixed_Range;
17508 ----------------------------------
17509 -- Set_Scalar_Range_For_Subtype --
17510 ----------------------------------
17512 procedure Set_Scalar_Range_For_Subtype
17513 (Def_Id : Entity_Id;
17517 Kind : constant Entity_Kind := Ekind (Def_Id);
17520 Set_Scalar_Range (Def_Id, R);
17522 -- We need to link the range into the tree before resolving it so
17523 -- that types that are referenced, including importantly the subtype
17524 -- itself, are properly frozen (Freeze_Expression requires that the
17525 -- expression be properly linked into the tree). Of course if it is
17526 -- already linked in, then we do not disturb the current link.
17528 if No (Parent (R)) then
17529 Set_Parent (R, Def_Id);
17532 -- Reset the kind of the subtype during analysis of the range, to
17533 -- catch possible premature use in the bounds themselves.
17535 Set_Ekind (Def_Id, E_Void);
17536 Process_Range_Expr_In_Decl (R, Subt);
17537 Set_Ekind (Def_Id, Kind);
17538 end Set_Scalar_Range_For_Subtype;
17540 --------------------------------------------------------
17541 -- Set_Stored_Constraint_From_Discriminant_Constraint --
17542 --------------------------------------------------------
17544 procedure Set_Stored_Constraint_From_Discriminant_Constraint
17548 -- Make sure set if encountered during Expand_To_Stored_Constraint
17550 Set_Stored_Constraint (E, No_Elist);
17552 -- Give it the right value
17554 if Is_Constrained (E) and then Has_Discriminants (E) then
17555 Set_Stored_Constraint (E,
17556 Expand_To_Stored_Constraint (E, Discriminant_Constraint (E)));
17558 end Set_Stored_Constraint_From_Discriminant_Constraint;
17560 -------------------------------------
17561 -- Signed_Integer_Type_Declaration --
17562 -------------------------------------
17564 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id) is
17565 Implicit_Base : Entity_Id;
17566 Base_Typ : Entity_Id;
17569 Errs : Boolean := False;
17573 function Can_Derive_From (E : Entity_Id) return Boolean;
17574 -- Determine whether given bounds allow derivation from specified type
17576 procedure Check_Bound (Expr : Node_Id);
17577 -- Check bound to make sure it is integral and static. If not, post
17578 -- appropriate error message and set Errs flag
17580 ---------------------
17581 -- Can_Derive_From --
17582 ---------------------
17584 -- Note we check both bounds against both end values, to deal with
17585 -- strange types like ones with a range of 0 .. -12341234.
17587 function Can_Derive_From (E : Entity_Id) return Boolean is
17588 Lo : constant Uint := Expr_Value (Type_Low_Bound (E));
17589 Hi : constant Uint := Expr_Value (Type_High_Bound (E));
17591 return Lo <= Lo_Val and then Lo_Val <= Hi
17593 Lo <= Hi_Val and then Hi_Val <= Hi;
17594 end Can_Derive_From;
17600 procedure Check_Bound (Expr : Node_Id) is
17602 -- If a range constraint is used as an integer type definition, each
17603 -- bound of the range must be defined by a static expression of some
17604 -- integer type, but the two bounds need not have the same integer
17605 -- type (Negative bounds are allowed.) (RM 3.5.4)
17607 if not Is_Integer_Type (Etype (Expr)) then
17609 ("integer type definition bounds must be of integer type", Expr);
17612 elsif not Is_OK_Static_Expression (Expr) then
17613 Flag_Non_Static_Expr
17614 ("non-static expression used for integer type bound!", Expr);
17617 -- The bounds are folded into literals, and we set their type to be
17618 -- universal, to avoid typing difficulties: we cannot set the type
17619 -- of the literal to the new type, because this would be a forward
17620 -- reference for the back end, and if the original type is user-
17621 -- defined this can lead to spurious semantic errors (e.g. 2928-003).
17624 if Is_Entity_Name (Expr) then
17625 Fold_Uint (Expr, Expr_Value (Expr), True);
17628 Set_Etype (Expr, Universal_Integer);
17632 -- Start of processing for Signed_Integer_Type_Declaration
17635 -- Create an anonymous base type
17638 Create_Itype (E_Signed_Integer_Type, Parent (Def), T, 'B');
17640 -- Analyze and check the bounds, they can be of any integer type
17642 Lo := Low_Bound (Def);
17643 Hi := High_Bound (Def);
17645 -- Arbitrarily use Integer as the type if either bound had an error
17647 if Hi = Error or else Lo = Error then
17648 Base_Typ := Any_Integer;
17649 Set_Error_Posted (T, True);
17651 -- Here both bounds are OK expressions
17654 Analyze_And_Resolve (Lo, Any_Integer);
17655 Analyze_And_Resolve (Hi, Any_Integer);
17661 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17662 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17665 -- Find type to derive from
17667 Lo_Val := Expr_Value (Lo);
17668 Hi_Val := Expr_Value (Hi);
17670 if Can_Derive_From (Standard_Short_Short_Integer) then
17671 Base_Typ := Base_Type (Standard_Short_Short_Integer);
17673 elsif Can_Derive_From (Standard_Short_Integer) then
17674 Base_Typ := Base_Type (Standard_Short_Integer);
17676 elsif Can_Derive_From (Standard_Integer) then
17677 Base_Typ := Base_Type (Standard_Integer);
17679 elsif Can_Derive_From (Standard_Long_Integer) then
17680 Base_Typ := Base_Type (Standard_Long_Integer);
17682 elsif Can_Derive_From (Standard_Long_Long_Integer) then
17683 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17686 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17687 Error_Msg_N ("integer type definition bounds out of range", Def);
17688 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17689 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17693 -- Complete both implicit base and declared first subtype entities
17695 Set_Etype (Implicit_Base, Base_Typ);
17696 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
17697 Set_Size_Info (Implicit_Base, (Base_Typ));
17698 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
17699 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
17701 Set_Ekind (T, E_Signed_Integer_Subtype);
17702 Set_Etype (T, Implicit_Base);
17704 Set_Size_Info (T, (Implicit_Base));
17705 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
17706 Set_Scalar_Range (T, Def);
17707 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
17708 Set_Is_Constrained (T);
17709 end Signed_Integer_Type_Declaration;