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_Type_Declaration,
1058 N_Task_Type_Declaration,
1059 N_Protected_Type_Declaration))
1061 D_Ityp := Parent (D_Ityp);
1062 pragma Assert (D_Ityp /= Empty);
1065 Set_Associated_Node_For_Itype (Desig_Type, D_Ityp);
1067 if Nkind_In (D_Ityp, N_Procedure_Specification,
1068 N_Function_Specification)
1070 Set_Scope (Desig_Type, Scope (Defining_Entity (D_Ityp)));
1072 elsif Nkind_In (D_Ityp, N_Full_Type_Declaration,
1073 N_Object_Declaration,
1074 N_Object_Renaming_Declaration,
1075 N_Formal_Type_Declaration)
1077 Set_Scope (Desig_Type, Scope (Defining_Identifier (D_Ityp)));
1080 if Nkind (T_Def) = N_Access_Function_Definition then
1081 if Nkind (Result_Definition (T_Def)) = N_Access_Definition then
1083 Acc : constant Node_Id := Result_Definition (T_Def);
1086 if Present (Access_To_Subprogram_Definition (Acc))
1088 Protected_Present (Access_To_Subprogram_Definition (Acc))
1092 Replace_Anonymous_Access_To_Protected_Subprogram
1098 Access_Definition (T_Def, Result_Definition (T_Def)));
1103 Analyze (Result_Definition (T_Def));
1104 Set_Etype (Desig_Type, Entity (Result_Definition (T_Def)));
1107 if not (Is_Type (Etype (Desig_Type))) then
1109 ("expect type in function specification",
1110 Result_Definition (T_Def));
1114 Set_Etype (Desig_Type, Standard_Void_Type);
1117 if Present (Formals) then
1118 Push_Scope (Desig_Type);
1119 Process_Formals (Formals, Parent (T_Def));
1121 -- A bit of a kludge here, End_Scope requires that the parent
1122 -- pointer be set to something reasonable, but Itypes don't have
1123 -- parent pointers. So we set it and then unset it ??? If and when
1124 -- Itypes have proper parent pointers to their declarations, this
1125 -- kludge can be removed.
1127 Set_Parent (Desig_Type, T_Name);
1129 Set_Parent (Desig_Type, Empty);
1132 -- Check for premature usage of the type being defined
1134 Check_For_Premature_Usage (T_Def);
1136 -- The return type and/or any parameter type may be incomplete. Mark
1137 -- the subprogram_type as depending on the incomplete type, so that
1138 -- it can be updated when the full type declaration is seen. This
1139 -- only applies to incomplete types declared in some enclosing scope,
1140 -- not to limited views from other packages.
1142 if Present (Formals) then
1143 Formal := First_Formal (Desig_Type);
1144 while Present (Formal) loop
1145 if Ekind (Formal) /= E_In_Parameter
1146 and then Nkind (T_Def) = N_Access_Function_Definition
1148 Error_Msg_N ("functions can only have IN parameters", Formal);
1151 if Ekind (Etype (Formal)) = E_Incomplete_Type
1152 and then In_Open_Scopes (Scope (Etype (Formal)))
1154 Append_Elmt (Desig_Type, Private_Dependents (Etype (Formal)));
1155 Set_Has_Delayed_Freeze (Desig_Type);
1158 Next_Formal (Formal);
1162 if Ekind (Etype (Desig_Type)) = E_Incomplete_Type
1163 and then not Has_Delayed_Freeze (Desig_Type)
1165 Append_Elmt (Desig_Type, Private_Dependents (Etype (Desig_Type)));
1166 Set_Has_Delayed_Freeze (Desig_Type);
1169 Check_Delayed_Subprogram (Desig_Type);
1171 if Protected_Present (T_Def) then
1172 Set_Ekind (T_Name, E_Access_Protected_Subprogram_Type);
1173 Set_Convention (Desig_Type, Convention_Protected);
1175 Set_Ekind (T_Name, E_Access_Subprogram_Type);
1178 Set_Can_Use_Internal_Rep (T_Name, not Always_Compatible_Rep_On_Target);
1180 Set_Etype (T_Name, T_Name);
1181 Init_Size_Align (T_Name);
1182 Set_Directly_Designated_Type (T_Name, Desig_Type);
1184 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1186 Set_Can_Never_Be_Null (T_Name, Null_Exclusion_Present (T_Def));
1188 Check_Restriction (No_Access_Subprograms, T_Def);
1189 end Access_Subprogram_Declaration;
1191 ----------------------------
1192 -- Access_Type_Declaration --
1193 ----------------------------
1195 procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id) is
1196 S : constant Node_Id := Subtype_Indication (Def);
1197 P : constant Node_Id := Parent (Def);
1203 -- Check for permissible use of incomplete type
1205 if Nkind (S) /= N_Subtype_Indication then
1208 if Ekind (Root_Type (Entity (S))) = E_Incomplete_Type then
1209 Set_Directly_Designated_Type (T, Entity (S));
1211 Set_Directly_Designated_Type (T,
1212 Process_Subtype (S, P, T, 'P'));
1216 Set_Directly_Designated_Type (T,
1217 Process_Subtype (S, P, T, 'P'));
1220 if All_Present (Def) or Constant_Present (Def) then
1221 Set_Ekind (T, E_General_Access_Type);
1223 Set_Ekind (T, E_Access_Type);
1226 if Base_Type (Designated_Type (T)) = T then
1227 Error_Msg_N ("access type cannot designate itself", S);
1229 -- In Ada 2005, the type may have a limited view through some unit
1230 -- in its own context, allowing the following circularity that cannot
1231 -- be detected earlier
1233 elsif Is_Class_Wide_Type (Designated_Type (T))
1234 and then Etype (Designated_Type (T)) = T
1237 ("access type cannot designate its own classwide type", S);
1239 -- Clean up indication of tagged status to prevent cascaded errors
1241 Set_Is_Tagged_Type (T, False);
1246 -- If the type has appeared already in a with_type clause, it is
1247 -- frozen and the pointer size is already set. Else, initialize.
1249 if not From_With_Type (T) then
1250 Init_Size_Align (T);
1253 Desig := Designated_Type (T);
1255 -- If designated type is an imported tagged type, indicate that the
1256 -- access type is also imported, and therefore restricted in its use.
1257 -- The access type may already be imported, so keep setting otherwise.
1259 -- Ada 2005 (AI-50217): If the non-limited view of the designated type
1260 -- is available, use it as the designated type of the access type, so
1261 -- that the back-end gets a usable entity.
1263 if From_With_Type (Desig)
1264 and then Ekind (Desig) /= E_Access_Type
1266 Set_From_With_Type (T);
1269 -- Note that Has_Task is always false, since the access type itself
1270 -- is not a task type. See Einfo for more description on this point.
1271 -- Exactly the same consideration applies to Has_Controlled_Component.
1273 Set_Has_Task (T, False);
1274 Set_Has_Controlled_Component (T, False);
1276 -- Initialize Associated_Final_Chain explicitly to Empty, to avoid
1277 -- problems where an incomplete view of this entity has been previously
1278 -- established by a limited with and an overlaid version of this field
1279 -- (Stored_Constraint) was initialized for the incomplete view.
1281 Set_Associated_Final_Chain (T, Empty);
1283 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1286 Set_Can_Never_Be_Null (T, Null_Exclusion_Present (Def));
1287 Set_Is_Access_Constant (T, Constant_Present (Def));
1288 end Access_Type_Declaration;
1290 ----------------------------------
1291 -- Add_Interface_Tag_Components --
1292 ----------------------------------
1294 procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id) is
1295 Loc : constant Source_Ptr := Sloc (N);
1299 procedure Add_Tag (Iface : Entity_Id);
1300 -- Add tag for one of the progenitor interfaces
1306 procedure Add_Tag (Iface : Entity_Id) is
1313 pragma Assert (Is_Tagged_Type (Iface)
1314 and then Is_Interface (Iface));
1317 Make_Component_Definition (Loc,
1318 Aliased_Present => True,
1319 Subtype_Indication =>
1320 New_Occurrence_Of (RTE (RE_Interface_Tag), Loc));
1322 Tag := Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1325 Make_Component_Declaration (Loc,
1326 Defining_Identifier => Tag,
1327 Component_Definition => Def);
1329 Analyze_Component_Declaration (Decl);
1331 Set_Analyzed (Decl);
1332 Set_Ekind (Tag, E_Component);
1334 Set_Is_Aliased (Tag);
1335 Set_Related_Type (Tag, Iface);
1336 Init_Component_Location (Tag);
1338 pragma Assert (Is_Frozen (Iface));
1340 Set_DT_Entry_Count (Tag,
1341 DT_Entry_Count (First_Entity (Iface)));
1343 if No (Last_Tag) then
1346 Insert_After (Last_Tag, Decl);
1351 -- If the ancestor has discriminants we need to give special support
1352 -- to store the offset_to_top value of the secondary dispatch tables.
1353 -- For this purpose we add a supplementary component just after the
1354 -- field that contains the tag associated with each secondary DT.
1356 if Typ /= Etype (Typ)
1357 and then Has_Discriminants (Etype (Typ))
1360 Make_Component_Definition (Loc,
1361 Subtype_Indication =>
1362 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc));
1365 Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1368 Make_Component_Declaration (Loc,
1369 Defining_Identifier => Offset,
1370 Component_Definition => Def);
1372 Analyze_Component_Declaration (Decl);
1374 Set_Analyzed (Decl);
1375 Set_Ekind (Offset, E_Component);
1376 Set_Is_Aliased (Offset);
1377 Set_Related_Type (Offset, Iface);
1378 Init_Component_Location (Offset);
1379 Insert_After (Last_Tag, Decl);
1390 -- Start of processing for Add_Interface_Tag_Components
1393 if not RTE_Available (RE_Interface_Tag) then
1395 ("(Ada 2005) interface types not supported by this run-time!",
1400 if Ekind (Typ) /= E_Record_Type
1401 or else (Is_Concurrent_Record_Type (Typ)
1402 and then Is_Empty_List (Abstract_Interface_List (Typ)))
1403 or else (not Is_Concurrent_Record_Type (Typ)
1404 and then No (Interfaces (Typ))
1405 and then Is_Empty_Elmt_List (Interfaces (Typ)))
1410 -- Find the current last tag
1412 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1413 Ext := Record_Extension_Part (Type_Definition (N));
1415 pragma Assert (Nkind (Type_Definition (N)) = N_Record_Definition);
1416 Ext := Type_Definition (N);
1421 if not (Present (Component_List (Ext))) then
1422 Set_Null_Present (Ext, False);
1424 Set_Component_List (Ext,
1425 Make_Component_List (Loc,
1426 Component_Items => L,
1427 Null_Present => False));
1429 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1430 L := Component_Items
1432 (Record_Extension_Part
1433 (Type_Definition (N))));
1435 L := Component_Items
1437 (Type_Definition (N)));
1440 -- Find the last tag component
1443 while Present (Comp) loop
1444 if Nkind (Comp) = N_Component_Declaration
1445 and then Is_Tag (Defining_Identifier (Comp))
1454 -- At this point L references the list of components and Last_Tag
1455 -- references the current last tag (if any). Now we add the tag
1456 -- corresponding with all the interfaces that are not implemented
1459 if Present (Interfaces (Typ)) then
1460 Elmt := First_Elmt (Interfaces (Typ));
1461 while Present (Elmt) loop
1462 Add_Tag (Node (Elmt));
1466 end Add_Interface_Tag_Components;
1468 -----------------------------------
1469 -- Analyze_Component_Declaration --
1470 -----------------------------------
1472 procedure Analyze_Component_Declaration (N : Node_Id) is
1473 Id : constant Entity_Id := Defining_Identifier (N);
1474 E : constant Node_Id := Expression (N);
1478 function Contains_POC (Constr : Node_Id) return Boolean;
1479 -- Determines whether a constraint uses the discriminant of a record
1480 -- type thus becoming a per-object constraint (POC).
1482 function Is_Known_Limited (Typ : Entity_Id) return Boolean;
1483 -- Typ is the type of the current component, check whether this type is
1484 -- a limited type. Used to validate declaration against that of
1485 -- enclosing record.
1491 function Contains_POC (Constr : Node_Id) return Boolean is
1493 -- Prevent cascaded errors
1495 if Error_Posted (Constr) then
1499 case Nkind (Constr) is
1500 when N_Attribute_Reference =>
1502 Attribute_Name (Constr) = Name_Access
1503 and then Prefix (Constr) = Scope (Entity (Prefix (Constr)));
1505 when N_Discriminant_Association =>
1506 return Denotes_Discriminant (Expression (Constr));
1508 when N_Identifier =>
1509 return Denotes_Discriminant (Constr);
1511 when N_Index_Or_Discriminant_Constraint =>
1516 IDC := First (Constraints (Constr));
1517 while Present (IDC) loop
1519 -- One per-object constraint is sufficient
1521 if Contains_POC (IDC) then
1532 return Denotes_Discriminant (Low_Bound (Constr))
1534 Denotes_Discriminant (High_Bound (Constr));
1536 when N_Range_Constraint =>
1537 return Denotes_Discriminant (Range_Expression (Constr));
1545 ----------------------
1546 -- Is_Known_Limited --
1547 ----------------------
1549 function Is_Known_Limited (Typ : Entity_Id) return Boolean is
1550 P : constant Entity_Id := Etype (Typ);
1551 R : constant Entity_Id := Root_Type (Typ);
1554 if Is_Limited_Record (Typ) then
1557 -- If the root type is limited (and not a limited interface)
1558 -- so is the current type
1560 elsif Is_Limited_Record (R)
1562 (not Is_Interface (R)
1563 or else not Is_Limited_Interface (R))
1567 -- Else the type may have a limited interface progenitor, but a
1568 -- limited record parent.
1571 and then Is_Limited_Record (P)
1578 end Is_Known_Limited;
1580 -- Start of processing for Analyze_Component_Declaration
1583 Generate_Definition (Id);
1586 if Present (Subtype_Indication (Component_Definition (N))) then
1587 T := Find_Type_Of_Object
1588 (Subtype_Indication (Component_Definition (N)), N);
1590 -- Ada 2005 (AI-230): Access Definition case
1593 pragma Assert (Present
1594 (Access_Definition (Component_Definition (N))));
1596 T := Access_Definition
1598 N => Access_Definition (Component_Definition (N)));
1599 Set_Is_Local_Anonymous_Access (T);
1601 -- Ada 2005 (AI-254)
1603 if Present (Access_To_Subprogram_Definition
1604 (Access_Definition (Component_Definition (N))))
1605 and then Protected_Present (Access_To_Subprogram_Definition
1607 (Component_Definition (N))))
1609 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
1613 -- If the subtype is a constrained subtype of the enclosing record,
1614 -- (which must have a partial view) the back-end does not properly
1615 -- handle the recursion. Rewrite the component declaration with an
1616 -- explicit subtype indication, which is acceptable to Gigi. We can copy
1617 -- the tree directly because side effects have already been removed from
1618 -- discriminant constraints.
1620 if Ekind (T) = E_Access_Subtype
1621 and then Is_Entity_Name (Subtype_Indication (Component_Definition (N)))
1622 and then Comes_From_Source (T)
1623 and then Nkind (Parent (T)) = N_Subtype_Declaration
1624 and then Etype (Directly_Designated_Type (T)) = Current_Scope
1627 (Subtype_Indication (Component_Definition (N)),
1628 New_Copy_Tree (Subtype_Indication (Parent (T))));
1629 T := Find_Type_Of_Object
1630 (Subtype_Indication (Component_Definition (N)), N);
1633 -- If the component declaration includes a default expression, then we
1634 -- check that the component is not of a limited type (RM 3.7(5)),
1635 -- and do the special preanalysis of the expression (see section on
1636 -- "Handling of Default and Per-Object Expressions" in the spec of
1640 Preanalyze_Spec_Expression (E, T);
1641 Check_Initialization (T, E);
1643 if Ada_Version >= Ada_05
1644 and then Ekind (T) = E_Anonymous_Access_Type
1646 -- Check RM 3.9.2(9): "if the expected type for an expression is
1647 -- an anonymous access-to-specific tagged type, then the object
1648 -- designated by the expression shall not be dynamically tagged
1649 -- unless it is a controlling operand in a call on a dispatching
1652 if Is_Tagged_Type (Directly_Designated_Type (T))
1654 Ekind (Directly_Designated_Type (T)) /= E_Class_Wide_Type
1656 Ekind (Directly_Designated_Type (Etype (E))) =
1660 ("access to specific tagged type required (RM 3.9.2(9))", E);
1663 -- (Ada 2005: AI-230): Accessibility check for anonymous
1666 if Type_Access_Level (Etype (E)) > Type_Access_Level (T) then
1668 ("expression has deeper access level than component " &
1669 "(RM 3.10.2 (12.2))", E);
1672 -- The initialization expression is a reference to an access
1673 -- discriminant. The type of the discriminant is always deeper
1674 -- than any access type.
1676 if Ekind (Etype (E)) = E_Anonymous_Access_Type
1677 and then Is_Entity_Name (E)
1678 and then Ekind (Entity (E)) = E_In_Parameter
1679 and then Present (Discriminal_Link (Entity (E)))
1682 ("discriminant has deeper accessibility level than target",
1688 -- The parent type may be a private view with unknown discriminants,
1689 -- and thus unconstrained. Regular components must be constrained.
1691 if Is_Indefinite_Subtype (T) and then Chars (Id) /= Name_uParent then
1692 if Is_Class_Wide_Type (T) then
1694 ("class-wide subtype with unknown discriminants" &
1695 " in component declaration",
1696 Subtype_Indication (Component_Definition (N)));
1699 ("unconstrained subtype in component declaration",
1700 Subtype_Indication (Component_Definition (N)));
1703 -- Components cannot be abstract, except for the special case of
1704 -- the _Parent field (case of extending an abstract tagged type)
1706 elsif Is_Abstract_Type (T) and then Chars (Id) /= Name_uParent then
1707 Error_Msg_N ("type of a component cannot be abstract", N);
1711 Set_Is_Aliased (Id, Aliased_Present (Component_Definition (N)));
1713 -- The component declaration may have a per-object constraint, set
1714 -- the appropriate flag in the defining identifier of the subtype.
1716 if Present (Subtype_Indication (Component_Definition (N))) then
1718 Sindic : constant Node_Id :=
1719 Subtype_Indication (Component_Definition (N));
1721 if Nkind (Sindic) = N_Subtype_Indication
1722 and then Present (Constraint (Sindic))
1723 and then Contains_POC (Constraint (Sindic))
1725 Set_Has_Per_Object_Constraint (Id);
1730 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
1731 -- out some static checks.
1733 if Ada_Version >= Ada_05
1734 and then Can_Never_Be_Null (T)
1736 Null_Exclusion_Static_Checks (N);
1739 -- If this component is private (or depends on a private type), flag the
1740 -- record type to indicate that some operations are not available.
1742 P := Private_Component (T);
1746 -- Check for circular definitions
1748 if P = Any_Type then
1749 Set_Etype (Id, Any_Type);
1751 -- There is a gap in the visibility of operations only if the
1752 -- component type is not defined in the scope of the record type.
1754 elsif Scope (P) = Scope (Current_Scope) then
1757 elsif Is_Limited_Type (P) then
1758 Set_Is_Limited_Composite (Current_Scope);
1761 Set_Is_Private_Composite (Current_Scope);
1766 and then Is_Limited_Type (T)
1767 and then Chars (Id) /= Name_uParent
1768 and then Is_Tagged_Type (Current_Scope)
1770 if Is_Derived_Type (Current_Scope)
1771 and then not Is_Known_Limited (Current_Scope)
1774 ("extension of nonlimited type cannot have limited components",
1777 if Is_Interface (Root_Type (Current_Scope)) then
1779 ("\limitedness is not inherited from limited interface", N);
1781 ("\add LIMITED to type indication", N);
1784 Explain_Limited_Type (T, N);
1785 Set_Etype (Id, Any_Type);
1786 Set_Is_Limited_Composite (Current_Scope, False);
1788 elsif not Is_Derived_Type (Current_Scope)
1789 and then not Is_Limited_Record (Current_Scope)
1790 and then not Is_Concurrent_Type (Current_Scope)
1793 ("nonlimited tagged type cannot have limited components", N);
1794 Explain_Limited_Type (T, N);
1795 Set_Etype (Id, Any_Type);
1796 Set_Is_Limited_Composite (Current_Scope, False);
1800 Set_Original_Record_Component (Id, Id);
1801 end Analyze_Component_Declaration;
1803 --------------------------
1804 -- Analyze_Declarations --
1805 --------------------------
1807 procedure Analyze_Declarations (L : List_Id) is
1809 Freeze_From : Entity_Id := Empty;
1810 Next_Node : Node_Id;
1813 -- Adjust D not to include implicit label declarations, since these
1814 -- have strange Sloc values that result in elaboration check problems.
1815 -- (They have the sloc of the label as found in the source, and that
1816 -- is ahead of the current declarative part).
1822 procedure Adjust_D is
1824 while Present (Prev (D))
1825 and then Nkind (D) = N_Implicit_Label_Declaration
1831 -- Start of processing for Analyze_Declarations
1835 while Present (D) loop
1837 -- Complete analysis of declaration
1840 Next_Node := Next (D);
1842 if No (Freeze_From) then
1843 Freeze_From := First_Entity (Current_Scope);
1846 -- At the end of a declarative part, freeze remaining entities
1847 -- declared in it. The end of the visible declarations of package
1848 -- specification is not the end of a declarative part if private
1849 -- declarations are present. The end of a package declaration is a
1850 -- freezing point only if it a library package. A task definition or
1851 -- protected type definition is not a freeze point either. Finally,
1852 -- we do not freeze entities in generic scopes, because there is no
1853 -- code generated for them and freeze nodes will be generated for
1856 -- The end of a package instantiation is not a freeze point, but
1857 -- for now we make it one, because the generic body is inserted
1858 -- (currently) immediately after. Generic instantiations will not
1859 -- be a freeze point once delayed freezing of bodies is implemented.
1860 -- (This is needed in any case for early instantiations ???).
1862 if No (Next_Node) then
1863 if Nkind_In (Parent (L), N_Component_List,
1865 N_Protected_Definition)
1869 elsif Nkind (Parent (L)) /= N_Package_Specification then
1870 if Nkind (Parent (L)) = N_Package_Body then
1871 Freeze_From := First_Entity (Current_Scope);
1875 Freeze_All (Freeze_From, D);
1876 Freeze_From := Last_Entity (Current_Scope);
1878 elsif Scope (Current_Scope) /= Standard_Standard
1879 and then not Is_Child_Unit (Current_Scope)
1880 and then No (Generic_Parent (Parent (L)))
1884 elsif L /= Visible_Declarations (Parent (L))
1885 or else No (Private_Declarations (Parent (L)))
1886 or else Is_Empty_List (Private_Declarations (Parent (L)))
1889 Freeze_All (Freeze_From, D);
1890 Freeze_From := Last_Entity (Current_Scope);
1893 -- If next node is a body then freeze all types before the body.
1894 -- An exception occurs for some expander-generated bodies. If these
1895 -- are generated at places where in general language rules would not
1896 -- allow a freeze point, then we assume that the expander has
1897 -- explicitly checked that all required types are properly frozen,
1898 -- and we do not cause general freezing here. This special circuit
1899 -- is used when the encountered body is marked as having already
1902 -- In all other cases (bodies that come from source, and expander
1903 -- generated bodies that have not been analyzed yet), freeze all
1904 -- types now. Note that in the latter case, the expander must take
1905 -- care to attach the bodies at a proper place in the tree so as to
1906 -- not cause unwanted freezing at that point.
1908 elsif not Analyzed (Next_Node)
1909 and then (Nkind_In (Next_Node, N_Subprogram_Body,
1915 Nkind (Next_Node) in N_Body_Stub)
1918 Freeze_All (Freeze_From, D);
1919 Freeze_From := Last_Entity (Current_Scope);
1924 end Analyze_Declarations;
1926 ----------------------------------
1927 -- Analyze_Incomplete_Type_Decl --
1928 ----------------------------------
1930 procedure Analyze_Incomplete_Type_Decl (N : Node_Id) is
1931 F : constant Boolean := Is_Pure (Current_Scope);
1935 Generate_Definition (Defining_Identifier (N));
1937 -- Process an incomplete declaration. The identifier must not have been
1938 -- declared already in the scope. However, an incomplete declaration may
1939 -- appear in the private part of a package, for a private type that has
1940 -- already been declared.
1942 -- In this case, the discriminants (if any) must match
1944 T := Find_Type_Name (N);
1946 Set_Ekind (T, E_Incomplete_Type);
1947 Init_Size_Align (T);
1948 Set_Is_First_Subtype (T, True);
1951 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
1952 -- incomplete types.
1954 if Tagged_Present (N) then
1955 Set_Is_Tagged_Type (T);
1956 Make_Class_Wide_Type (T);
1957 Set_Primitive_Operations (T, New_Elmt_List);
1962 Set_Stored_Constraint (T, No_Elist);
1964 if Present (Discriminant_Specifications (N)) then
1965 Process_Discriminants (N);
1970 -- If the type has discriminants, non-trivial subtypes may be be
1971 -- declared before the full view of the type. The full views of those
1972 -- subtypes will be built after the full view of the type.
1974 Set_Private_Dependents (T, New_Elmt_List);
1976 end Analyze_Incomplete_Type_Decl;
1978 -----------------------------------
1979 -- Analyze_Interface_Declaration --
1980 -----------------------------------
1982 procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id) is
1983 CW : constant Entity_Id := Class_Wide_Type (T);
1986 Set_Is_Tagged_Type (T);
1988 Set_Is_Limited_Record (T, Limited_Present (Def)
1989 or else Task_Present (Def)
1990 or else Protected_Present (Def)
1991 or else Synchronized_Present (Def));
1993 -- Type is abstract if full declaration carries keyword, or if previous
1994 -- partial view did.
1996 Set_Is_Abstract_Type (T);
1997 Set_Is_Interface (T);
1999 -- Type is a limited interface if it includes the keyword limited, task,
2000 -- protected, or synchronized.
2002 Set_Is_Limited_Interface
2003 (T, Limited_Present (Def)
2004 or else Protected_Present (Def)
2005 or else Synchronized_Present (Def)
2006 or else Task_Present (Def));
2008 Set_Is_Protected_Interface (T, Protected_Present (Def));
2009 Set_Is_Task_Interface (T, Task_Present (Def));
2011 -- Type is a synchronized interface if it includes the keyword task,
2012 -- protected, or synchronized.
2014 Set_Is_Synchronized_Interface
2015 (T, Synchronized_Present (Def)
2016 or else Protected_Present (Def)
2017 or else Task_Present (Def));
2019 Set_Interfaces (T, New_Elmt_List);
2020 Set_Primitive_Operations (T, New_Elmt_List);
2022 -- Complete the decoration of the class-wide entity if it was already
2023 -- built (i.e. during the creation of the limited view)
2025 if Present (CW) then
2026 Set_Is_Interface (CW);
2027 Set_Is_Limited_Interface (CW, Is_Limited_Interface (T));
2028 Set_Is_Protected_Interface (CW, Is_Protected_Interface (T));
2029 Set_Is_Synchronized_Interface (CW, Is_Synchronized_Interface (T));
2030 Set_Is_Task_Interface (CW, Is_Task_Interface (T));
2033 -- Check runtime support for synchronized interfaces
2035 if VM_Target = No_VM
2036 and then (Is_Task_Interface (T)
2037 or else Is_Protected_Interface (T)
2038 or else Is_Synchronized_Interface (T))
2039 and then not RTE_Available (RE_Select_Specific_Data)
2041 Error_Msg_CRT ("synchronized interfaces", T);
2043 end Analyze_Interface_Declaration;
2045 -----------------------------
2046 -- Analyze_Itype_Reference --
2047 -----------------------------
2049 -- Nothing to do. This node is placed in the tree only for the benefit of
2050 -- back end processing, and has no effect on the semantic processing.
2052 procedure Analyze_Itype_Reference (N : Node_Id) is
2054 pragma Assert (Is_Itype (Itype (N)));
2056 end Analyze_Itype_Reference;
2058 --------------------------------
2059 -- Analyze_Number_Declaration --
2060 --------------------------------
2062 procedure Analyze_Number_Declaration (N : Node_Id) is
2063 Id : constant Entity_Id := Defining_Identifier (N);
2064 E : constant Node_Id := Expression (N);
2066 Index : Interp_Index;
2070 Generate_Definition (Id);
2073 -- This is an optimization of a common case of an integer literal
2075 if Nkind (E) = N_Integer_Literal then
2076 Set_Is_Static_Expression (E, True);
2077 Set_Etype (E, Universal_Integer);
2079 Set_Etype (Id, Universal_Integer);
2080 Set_Ekind (Id, E_Named_Integer);
2081 Set_Is_Frozen (Id, True);
2085 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2087 -- Process expression, replacing error by integer zero, to avoid
2088 -- cascaded errors or aborts further along in the processing
2090 -- Replace Error by integer zero, which seems least likely to
2091 -- cause cascaded errors.
2094 Rewrite (E, Make_Integer_Literal (Sloc (E), Uint_0));
2095 Set_Error_Posted (E);
2100 -- Verify that the expression is static and numeric. If
2101 -- the expression is overloaded, we apply the preference
2102 -- rule that favors root numeric types.
2104 if not Is_Overloaded (E) then
2110 Get_First_Interp (E, Index, It);
2111 while Present (It.Typ) loop
2112 if (Is_Integer_Type (It.Typ)
2113 or else Is_Real_Type (It.Typ))
2114 and then (Scope (Base_Type (It.Typ))) = Standard_Standard
2116 if T = Any_Type then
2119 elsif It.Typ = Universal_Real
2120 or else It.Typ = Universal_Integer
2122 -- Choose universal interpretation over any other
2129 Get_Next_Interp (Index, It);
2133 if Is_Integer_Type (T) then
2135 Set_Etype (Id, Universal_Integer);
2136 Set_Ekind (Id, E_Named_Integer);
2138 elsif Is_Real_Type (T) then
2140 -- Because the real value is converted to universal_real, this is a
2141 -- legal context for a universal fixed expression.
2143 if T = Universal_Fixed then
2145 Loc : constant Source_Ptr := Sloc (N);
2146 Conv : constant Node_Id := Make_Type_Conversion (Loc,
2148 New_Occurrence_Of (Universal_Real, Loc),
2149 Expression => Relocate_Node (E));
2156 elsif T = Any_Fixed then
2157 Error_Msg_N ("illegal context for mixed mode operation", E);
2159 -- Expression is of the form : universal_fixed * integer. Try to
2160 -- resolve as universal_real.
2162 T := Universal_Real;
2167 Set_Etype (Id, Universal_Real);
2168 Set_Ekind (Id, E_Named_Real);
2171 Wrong_Type (E, Any_Numeric);
2175 Set_Ekind (Id, E_Constant);
2176 Set_Never_Set_In_Source (Id, True);
2177 Set_Is_True_Constant (Id, True);
2181 if Nkind_In (E, N_Integer_Literal, N_Real_Literal) then
2182 Set_Etype (E, Etype (Id));
2185 if not Is_OK_Static_Expression (E) then
2186 Flag_Non_Static_Expr
2187 ("non-static expression used in number declaration!", E);
2188 Rewrite (E, Make_Integer_Literal (Sloc (N), 1));
2189 Set_Etype (E, Any_Type);
2191 end Analyze_Number_Declaration;
2193 --------------------------------
2194 -- Analyze_Object_Declaration --
2195 --------------------------------
2197 procedure Analyze_Object_Declaration (N : Node_Id) is
2198 Loc : constant Source_Ptr := Sloc (N);
2199 Id : constant Entity_Id := Defining_Identifier (N);
2203 E : Node_Id := Expression (N);
2204 -- E is set to Expression (N) throughout this routine. When
2205 -- Expression (N) is modified, E is changed accordingly.
2207 Prev_Entity : Entity_Id := Empty;
2209 function Count_Tasks (T : Entity_Id) return Uint;
2210 -- This function is called when a non-generic library level object of a
2211 -- task type is declared. Its function is to count the static number of
2212 -- tasks declared within the type (it is only called if Has_Tasks is set
2213 -- for T). As a side effect, if an array of tasks with non-static bounds
2214 -- or a variant record type is encountered, Check_Restrictions is called
2215 -- indicating the count is unknown.
2221 function Count_Tasks (T : Entity_Id) return Uint is
2227 if Is_Task_Type (T) then
2230 elsif Is_Record_Type (T) then
2231 if Has_Discriminants (T) then
2232 Check_Restriction (Max_Tasks, N);
2237 C := First_Component (T);
2238 while Present (C) loop
2239 V := V + Count_Tasks (Etype (C));
2246 elsif Is_Array_Type (T) then
2247 X := First_Index (T);
2248 V := Count_Tasks (Component_Type (T));
2249 while Present (X) loop
2252 if not Is_Static_Subtype (C) then
2253 Check_Restriction (Max_Tasks, N);
2256 V := V * (UI_Max (Uint_0,
2257 Expr_Value (Type_High_Bound (C)) -
2258 Expr_Value (Type_Low_Bound (C)) + Uint_1));
2271 -- Start of processing for Analyze_Object_Declaration
2274 -- There are three kinds of implicit types generated by an
2275 -- object declaration:
2277 -- 1. Those for generated by the original Object Definition
2279 -- 2. Those generated by the Expression
2281 -- 3. Those used to constrained the Object Definition with the
2282 -- expression constraints when it is unconstrained
2284 -- They must be generated in this order to avoid order of elaboration
2285 -- issues. Thus the first step (after entering the name) is to analyze
2286 -- the object definition.
2288 if Constant_Present (N) then
2289 Prev_Entity := Current_Entity_In_Scope (Id);
2291 -- If the homograph is an implicit subprogram, it is overridden by
2292 -- the current declaration.
2294 if Present (Prev_Entity)
2296 ((Is_Overloadable (Prev_Entity)
2297 and then Is_Inherited_Operation (Prev_Entity))
2299 -- The current object is a discriminal generated for an entry
2300 -- family index. Even though the index is a constant, in this
2301 -- particular context there is no true constant redeclaration.
2302 -- Enter_Name will handle the visibility.
2305 (Is_Discriminal (Id)
2306 and then Ekind (Discriminal_Link (Id)) =
2307 E_Entry_Index_Parameter))
2309 Prev_Entity := Empty;
2313 if Present (Prev_Entity) then
2314 Constant_Redeclaration (Id, N, T);
2316 Generate_Reference (Prev_Entity, Id, 'c');
2317 Set_Completion_Referenced (Id);
2319 if Error_Posted (N) then
2321 -- Type mismatch or illegal redeclaration, Do not analyze
2322 -- expression to avoid cascaded errors.
2324 T := Find_Type_Of_Object (Object_Definition (N), N);
2326 Set_Ekind (Id, E_Variable);
2330 -- In the normal case, enter identifier at the start to catch premature
2331 -- usage in the initialization expression.
2334 Generate_Definition (Id);
2337 Mark_Coextensions (N, Object_Definition (N));
2339 T := Find_Type_Of_Object (Object_Definition (N), N);
2341 if Nkind (Object_Definition (N)) = N_Access_Definition
2343 (Access_To_Subprogram_Definition (Object_Definition (N)))
2344 and then Protected_Present
2345 (Access_To_Subprogram_Definition (Object_Definition (N)))
2347 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
2350 if Error_Posted (Id) then
2352 Set_Ekind (Id, E_Variable);
2357 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2358 -- out some static checks
2360 if Ada_Version >= Ada_05
2361 and then Can_Never_Be_Null (T)
2363 -- In case of aggregates we must also take care of the correct
2364 -- initialization of nested aggregates bug this is done at the
2365 -- point of the analysis of the aggregate (see sem_aggr.adb)
2367 if Present (Expression (N))
2368 and then Nkind (Expression (N)) = N_Aggregate
2374 Save_Typ : constant Entity_Id := Etype (Id);
2376 Set_Etype (Id, T); -- Temp. decoration for static checks
2377 Null_Exclusion_Static_Checks (N);
2378 Set_Etype (Id, Save_Typ);
2383 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2385 -- If deferred constant, make sure context is appropriate. We detect
2386 -- a deferred constant as a constant declaration with no expression.
2387 -- A deferred constant can appear in a package body if its completion
2388 -- is by means of an interface pragma.
2390 if Constant_Present (N)
2393 -- We exclude forward references to tags
2395 if Is_Imported (Defining_Identifier (N))
2399 (Present (Full_View (T))
2400 and then Full_View (T) = RTE (RE_Tag)))
2404 -- A deferred constant may appear in the declarative part of the
2405 -- following constructs:
2409 -- extended return statements
2412 -- subprogram bodies
2415 -- When declared inside a package spec, a deferred constant must be
2416 -- completed by a full constant declaration or pragma Import. In all
2417 -- other cases, the only proper completion is pragma Import. Extended
2418 -- return statements are flagged as invalid contexts because they do
2419 -- not have a declarative part and so cannot accommodate the pragma.
2421 elsif Ekind (Current_Scope) = E_Return_Statement then
2423 ("invalid context for deferred constant declaration (RM 7.4)",
2426 ("\declaration requires an initialization expression",
2428 Set_Constant_Present (N, False);
2430 -- In Ada 83, deferred constant must be of private type
2432 elsif not Is_Private_Type (T) then
2433 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2435 ("(Ada 83) deferred constant must be private type", N);
2439 -- If not a deferred constant, then object declaration freezes its type
2442 Check_Fully_Declared (T, N);
2443 Freeze_Before (N, T);
2446 -- If the object was created by a constrained array definition, then
2447 -- set the link in both the anonymous base type and anonymous subtype
2448 -- that are built to represent the array type to point to the object.
2450 if Nkind (Object_Definition (Declaration_Node (Id))) =
2451 N_Constrained_Array_Definition
2453 Set_Related_Array_Object (T, Id);
2454 Set_Related_Array_Object (Base_Type (T), Id);
2457 -- Special checks for protected objects not at library level
2459 if Is_Protected_Type (T)
2460 and then not Is_Library_Level_Entity (Id)
2462 Check_Restriction (No_Local_Protected_Objects, Id);
2464 -- Protected objects with interrupt handlers must be at library level
2466 -- Ada 2005: this test is not needed (and the corresponding clause
2467 -- in the RM is removed) because accessibility checks are sufficient
2468 -- to make handlers not at the library level illegal.
2470 if Has_Interrupt_Handler (T)
2471 and then Ada_Version < Ada_05
2474 ("interrupt object can only be declared at library level", Id);
2478 -- The actual subtype of the object is the nominal subtype, unless
2479 -- the nominal one is unconstrained and obtained from the expression.
2483 -- Process initialization expression if present and not in error
2485 if Present (E) and then E /= Error then
2487 -- Generate an error in case of CPP class-wide object initialization.
2488 -- Required because otherwise the expansion of the class-wide
2489 -- assignment would try to use 'size to initialize the object
2490 -- (primitive that is not available in CPP tagged types).
2492 if Is_Class_Wide_Type (Act_T)
2494 (Is_CPP_Class (Root_Type (Etype (Act_T)))
2496 (Present (Full_View (Root_Type (Etype (Act_T))))
2498 Is_CPP_Class (Full_View (Root_Type (Etype (Act_T))))))
2501 ("predefined assignment not available for 'C'P'P tagged types",
2505 Mark_Coextensions (N, E);
2508 -- In case of errors detected in the analysis of the expression,
2509 -- decorate it with the expected type to avoid cascaded errors
2511 if No (Etype (E)) then
2515 -- If an initialization expression is present, then we set the
2516 -- Is_True_Constant flag. It will be reset if this is a variable
2517 -- and it is indeed modified.
2519 Set_Is_True_Constant (Id, True);
2521 -- If we are analyzing a constant declaration, set its completion
2522 -- flag after analyzing and resolving the expression.
2524 if Constant_Present (N) then
2525 Set_Has_Completion (Id);
2528 -- Set type and resolve (type may be overridden later on)
2533 -- If the object is an access to variable, the initialization
2534 -- expression cannot be an access to constant.
2536 if Is_Access_Type (T)
2537 and then not Is_Access_Constant (T)
2538 and then Is_Access_Type (Etype (E))
2539 and then Is_Access_Constant (Etype (E))
2542 ("object that is an access to variable cannot be initialized " &
2543 "with an access-to-constant expression", E);
2546 if not Assignment_OK (N) then
2547 Check_Initialization (T, E);
2550 Check_Unset_Reference (E);
2552 -- If this is a variable, then set current value
2554 if not Constant_Present (N) then
2555 if Compile_Time_Known_Value (E) then
2556 Set_Current_Value (Id, E);
2560 -- Deal with setting of null flags
2562 if Is_Access_Type (T) then
2563 if Known_Non_Null (E) then
2564 Set_Is_Known_Non_Null (Id, True);
2565 elsif Known_Null (E)
2566 and then not Can_Never_Be_Null (Id)
2568 Set_Is_Known_Null (Id, True);
2572 -- Check incorrect use of dynamically tagged expressions. Note
2573 -- the use of Is_Tagged_Type (T) which seems redundant but is in
2574 -- fact important to avoid spurious errors due to expanded code
2575 -- for dispatching functions over an anonymous access type
2577 if (Is_Class_Wide_Type (Etype (E)) or else Is_Dynamically_Tagged (E))
2578 and then Is_Tagged_Type (T)
2579 and then not Is_Class_Wide_Type (T)
2581 Error_Msg_N ("dynamically tagged expression not allowed!", E);
2584 Apply_Scalar_Range_Check (E, T);
2585 Apply_Static_Length_Check (E, T);
2588 -- If the No_Streams restriction is set, check that the type of the
2589 -- object is not, and does not contain, any subtype derived from
2590 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
2591 -- Has_Stream just for efficiency reasons. There is no point in
2592 -- spending time on a Has_Stream check if the restriction is not set.
2594 if Restrictions.Set (No_Streams) then
2595 if Has_Stream (T) then
2596 Check_Restriction (No_Streams, N);
2600 -- Abstract type is never permitted for a variable or constant.
2601 -- Note: we inhibit this check for objects that do not come from
2602 -- source because there is at least one case (the expansion of
2603 -- x'class'input where x is abstract) where we legitimately
2604 -- generate an abstract object.
2606 if Is_Abstract_Type (T) and then Comes_From_Source (N) then
2607 Error_Msg_N ("type of object cannot be abstract",
2608 Object_Definition (N));
2610 if Is_CPP_Class (T) then
2611 Error_Msg_NE ("\} may need a cpp_constructor",
2612 Object_Definition (N), T);
2615 -- Case of unconstrained type
2617 elsif Is_Indefinite_Subtype (T) then
2619 -- Nothing to do in deferred constant case
2621 if Constant_Present (N) and then No (E) then
2624 -- Case of no initialization present
2627 if No_Initialization (N) then
2630 elsif Is_Class_Wide_Type (T) then
2632 ("initialization required in class-wide declaration ", N);
2636 ("unconstrained subtype not allowed (need initialization)",
2637 Object_Definition (N));
2639 if Is_Record_Type (T) and then Has_Discriminants (T) then
2641 ("\provide initial value or explicit discriminant values",
2642 Object_Definition (N));
2645 ("\or give default discriminant values for type&",
2646 Object_Definition (N), T);
2648 elsif Is_Array_Type (T) then
2650 ("\provide initial value or explicit array bounds",
2651 Object_Definition (N));
2655 -- Case of initialization present but in error. Set initial
2656 -- expression as absent (but do not make above complaints)
2658 elsif E = Error then
2659 Set_Expression (N, Empty);
2662 -- Case of initialization present
2665 -- Not allowed in Ada 83
2667 if not Constant_Present (N) then
2668 if Ada_Version = Ada_83
2669 and then Comes_From_Source (Object_Definition (N))
2672 ("(Ada 83) unconstrained variable not allowed",
2673 Object_Definition (N));
2677 -- Now we constrain the variable from the initializing expression
2679 -- If the expression is an aggregate, it has been expanded into
2680 -- individual assignments. Retrieve the actual type from the
2681 -- expanded construct.
2683 if Is_Array_Type (T)
2684 and then No_Initialization (N)
2685 and then Nkind (Original_Node (E)) = N_Aggregate
2690 Expand_Subtype_From_Expr (N, T, Object_Definition (N), E);
2691 Act_T := Find_Type_Of_Object (Object_Definition (N), N);
2694 Set_Is_Constr_Subt_For_U_Nominal (Act_T);
2696 if Aliased_Present (N) then
2697 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2700 Freeze_Before (N, Act_T);
2701 Freeze_Before (N, T);
2704 elsif Is_Array_Type (T)
2705 and then No_Initialization (N)
2706 and then Nkind (Original_Node (E)) = N_Aggregate
2708 if not Is_Entity_Name (Object_Definition (N)) then
2710 Check_Compile_Time_Size (Act_T);
2712 if Aliased_Present (N) then
2713 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2717 -- When the given object definition and the aggregate are specified
2718 -- independently, and their lengths might differ do a length check.
2719 -- This cannot happen if the aggregate is of the form (others =>...)
2721 if not Is_Constrained (T) then
2724 elsif Nkind (E) = N_Raise_Constraint_Error then
2726 -- Aggregate is statically illegal. Place back in declaration
2728 Set_Expression (N, E);
2729 Set_No_Initialization (N, False);
2731 elsif T = Etype (E) then
2734 elsif Nkind (E) = N_Aggregate
2735 and then Present (Component_Associations (E))
2736 and then Present (Choices (First (Component_Associations (E))))
2737 and then Nkind (First
2738 (Choices (First (Component_Associations (E))))) = N_Others_Choice
2743 Apply_Length_Check (E, T);
2746 -- If the type is limited unconstrained with defaulted discriminants
2747 -- and there is no expression, then the object is constrained by the
2748 -- defaults, so it is worthwhile building the corresponding subtype.
2750 elsif (Is_Limited_Record (T)
2751 or else Is_Concurrent_Type (T))
2752 and then not Is_Constrained (T)
2753 and then Has_Discriminants (T)
2756 Act_T := Build_Default_Subtype (T, N);
2758 -- Ada 2005: a limited object may be initialized by means of an
2759 -- aggregate. If the type has default discriminants it has an
2760 -- unconstrained nominal type, Its actual subtype will be obtained
2761 -- from the aggregate, and not from the default discriminants.
2766 Rewrite (Object_Definition (N), New_Occurrence_Of (Act_T, Loc));
2768 elsif Present (Underlying_Type (T))
2769 and then not Is_Constrained (Underlying_Type (T))
2770 and then Has_Discriminants (Underlying_Type (T))
2771 and then Nkind (E) = N_Function_Call
2772 and then Constant_Present (N)
2774 -- The back-end has problems with constants of a discriminated type
2775 -- with defaults, if the initial value is a function call. We
2776 -- generate an intermediate temporary for the result of the call.
2777 -- It is unclear why this should make it acceptable to gcc. ???
2779 Remove_Side_Effects (E);
2782 -- Check No_Wide_Characters restriction
2784 if T = Standard_Wide_Character
2785 or else T = Standard_Wide_Wide_Character
2786 or else Root_Type (T) = Standard_Wide_String
2787 or else Root_Type (T) = Standard_Wide_Wide_String
2789 Check_Restriction (No_Wide_Characters, Object_Definition (N));
2792 -- Indicate this is not set in source. Certainly true for constants,
2793 -- and true for variables so far (will be reset for a variable if and
2794 -- when we encounter a modification in the source).
2796 Set_Never_Set_In_Source (Id, True);
2798 -- Now establish the proper kind and type of the object
2800 if Constant_Present (N) then
2801 Set_Ekind (Id, E_Constant);
2802 Set_Is_True_Constant (Id, True);
2805 Set_Ekind (Id, E_Variable);
2807 -- A variable is set as shared passive if it appears in a shared
2808 -- passive package, and is at the outer level. This is not done
2809 -- for entities generated during expansion, because those are
2810 -- always manipulated locally.
2812 if Is_Shared_Passive (Current_Scope)
2813 and then Is_Library_Level_Entity (Id)
2814 and then Comes_From_Source (Id)
2816 Set_Is_Shared_Passive (Id);
2817 Check_Shared_Var (Id, T, N);
2820 -- Set Has_Initial_Value if initializing expression present. Note
2821 -- that if there is no initializing expression, we leave the state
2822 -- of this flag unchanged (usually it will be False, but notably in
2823 -- the case of exception choice variables, it will already be true).
2826 Set_Has_Initial_Value (Id, True);
2830 -- Initialize alignment and size and capture alignment setting
2832 Init_Alignment (Id);
2834 Set_Optimize_Alignment_Flags (Id);
2836 -- Deal with aliased case
2838 if Aliased_Present (N) then
2839 Set_Is_Aliased (Id);
2841 -- If the object is aliased and the type is unconstrained with
2842 -- defaulted discriminants and there is no expression, then the
2843 -- object is constrained by the defaults, so it is worthwhile
2844 -- building the corresponding subtype.
2846 -- Ada 2005 (AI-363): If the aliased object is discriminated and
2847 -- unconstrained, then only establish an actual subtype if the
2848 -- nominal subtype is indefinite. In definite cases the object is
2849 -- unconstrained in Ada 2005.
2852 and then Is_Record_Type (T)
2853 and then not Is_Constrained (T)
2854 and then Has_Discriminants (T)
2855 and then (Ada_Version < Ada_05 or else Is_Indefinite_Subtype (T))
2857 Set_Actual_Subtype (Id, Build_Default_Subtype (T, N));
2861 -- Now we can set the type of the object
2863 Set_Etype (Id, Act_T);
2865 -- Deal with controlled types
2867 if Has_Controlled_Component (Etype (Id))
2868 or else Is_Controlled (Etype (Id))
2870 if not Is_Library_Level_Entity (Id) then
2871 Check_Restriction (No_Nested_Finalization, N);
2873 Validate_Controlled_Object (Id);
2876 -- Generate a warning when an initialization causes an obvious ABE
2877 -- violation. If the init expression is a simple aggregate there
2878 -- shouldn't be any initialize/adjust call generated. This will be
2879 -- true as soon as aggregates are built in place when possible.
2881 -- ??? at the moment we do not generate warnings for temporaries
2882 -- created for those aggregates although Program_Error might be
2883 -- generated if compiled with -gnato.
2885 if Is_Controlled (Etype (Id))
2886 and then Comes_From_Source (Id)
2889 BT : constant Entity_Id := Base_Type (Etype (Id));
2891 Implicit_Call : Entity_Id;
2892 pragma Warnings (Off, Implicit_Call);
2893 -- ??? what is this for (never referenced!)
2895 function Is_Aggr (N : Node_Id) return Boolean;
2896 -- Check that N is an aggregate
2902 function Is_Aggr (N : Node_Id) return Boolean is
2904 case Nkind (Original_Node (N)) is
2905 when N_Aggregate | N_Extension_Aggregate =>
2908 when N_Qualified_Expression |
2910 N_Unchecked_Type_Conversion =>
2911 return Is_Aggr (Expression (Original_Node (N)));
2919 -- If no underlying type, we already are in an error situation.
2920 -- Do not try to add a warning since we do not have access to
2923 if No (Underlying_Type (BT)) then
2924 Implicit_Call := Empty;
2926 -- A generic type does not have usable primitive operators.
2927 -- Initialization calls are built for instances.
2929 elsif Is_Generic_Type (BT) then
2930 Implicit_Call := Empty;
2932 -- If the init expression is not an aggregate, an adjust call
2933 -- will be generated
2935 elsif Present (E) and then not Is_Aggr (E) then
2936 Implicit_Call := Find_Prim_Op (BT, Name_Adjust);
2938 -- If no init expression and we are not in the deferred
2939 -- constant case, an Initialize call will be generated
2941 elsif No (E) and then not Constant_Present (N) then
2942 Implicit_Call := Find_Prim_Op (BT, Name_Initialize);
2945 Implicit_Call := Empty;
2951 if Has_Task (Etype (Id)) then
2952 Check_Restriction (No_Tasking, N);
2954 -- Deal with counting max tasks
2956 -- Nothing to do if inside a generic
2958 if Inside_A_Generic then
2961 -- If library level entity, then count tasks
2963 elsif Is_Library_Level_Entity (Id) then
2964 Check_Restriction (Max_Tasks, N, Count_Tasks (Etype (Id)));
2966 -- If not library level entity, then indicate we don't know max
2967 -- tasks and also check task hierarchy restriction and blocking
2968 -- operation (since starting a task is definitely blocking!)
2971 Check_Restriction (Max_Tasks, N);
2972 Check_Restriction (No_Task_Hierarchy, N);
2973 Check_Potentially_Blocking_Operation (N);
2976 -- A rather specialized test. If we see two tasks being declared
2977 -- of the same type in the same object declaration, and the task
2978 -- has an entry with an address clause, we know that program error
2979 -- will be raised at run-time since we can't have two tasks with
2980 -- entries at the same address.
2982 if Is_Task_Type (Etype (Id)) and then More_Ids (N) then
2987 E := First_Entity (Etype (Id));
2988 while Present (E) loop
2989 if Ekind (E) = E_Entry
2990 and then Present (Get_Attribute_Definition_Clause
2991 (E, Attribute_Address))
2994 ("?more than one task with same entry address", N);
2996 ("\?Program_Error will be raised at run time", N);
2998 Make_Raise_Program_Error (Loc,
2999 Reason => PE_Duplicated_Entry_Address));
3009 -- Some simple constant-propagation: if the expression is a constant
3010 -- string initialized with a literal, share the literal. This avoids
3014 and then Is_Entity_Name (E)
3015 and then Ekind (Entity (E)) = E_Constant
3016 and then Base_Type (Etype (E)) = Standard_String
3019 Val : constant Node_Id := Constant_Value (Entity (E));
3022 and then Nkind (Val) = N_String_Literal
3024 Rewrite (E, New_Copy (Val));
3029 -- Another optimization: if the nominal subtype is unconstrained and
3030 -- the expression is a function call that returns an unconstrained
3031 -- type, rewrite the declaration as a renaming of the result of the
3032 -- call. The exceptions below are cases where the copy is expected,
3033 -- either by the back end (Aliased case) or by the semantics, as for
3034 -- initializing controlled types or copying tags for classwide types.
3037 and then Nkind (E) = N_Explicit_Dereference
3038 and then Nkind (Original_Node (E)) = N_Function_Call
3039 and then not Is_Library_Level_Entity (Id)
3040 and then not Is_Constrained (Underlying_Type (T))
3041 and then not Is_Aliased (Id)
3042 and then not Is_Class_Wide_Type (T)
3043 and then not Is_Controlled (T)
3044 and then not Has_Controlled_Component (Base_Type (T))
3045 and then Expander_Active
3048 Make_Object_Renaming_Declaration (Loc,
3049 Defining_Identifier => Id,
3050 Access_Definition => Empty,
3051 Subtype_Mark => New_Occurrence_Of
3052 (Base_Type (Etype (Id)), Loc),
3055 Set_Renamed_Object (Id, E);
3057 -- Force generation of debugging information for the constant and for
3058 -- the renamed function call.
3060 Set_Debug_Info_Needed (Id);
3061 Set_Debug_Info_Needed (Entity (Prefix (E)));
3064 if Present (Prev_Entity)
3065 and then Is_Frozen (Prev_Entity)
3066 and then not Error_Posted (Id)
3068 Error_Msg_N ("full constant declaration appears too late", N);
3071 Check_Eliminated (Id);
3073 -- Deal with setting In_Private_Part flag if in private part
3075 if Ekind (Scope (Id)) = E_Package
3076 and then In_Private_Part (Scope (Id))
3078 Set_In_Private_Part (Id);
3081 -- Check for violation of No_Local_Timing_Events
3083 if Is_RTE (Etype (Id), RE_Timing_Event)
3084 and then not Is_Library_Level_Entity (Id)
3086 Check_Restriction (No_Local_Timing_Events, N);
3088 end Analyze_Object_Declaration;
3090 ---------------------------
3091 -- Analyze_Others_Choice --
3092 ---------------------------
3094 -- Nothing to do for the others choice node itself, the semantic analysis
3095 -- of the others choice will occur as part of the processing of the parent
3097 procedure Analyze_Others_Choice (N : Node_Id) is
3098 pragma Warnings (Off, N);
3101 end Analyze_Others_Choice;
3103 -------------------------------------------
3104 -- Analyze_Private_Extension_Declaration --
3105 -------------------------------------------
3107 procedure Analyze_Private_Extension_Declaration (N : Node_Id) is
3108 T : constant Entity_Id := Defining_Identifier (N);
3109 Indic : constant Node_Id := Subtype_Indication (N);
3110 Parent_Type : Entity_Id;
3111 Parent_Base : Entity_Id;
3114 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
3116 if Is_Non_Empty_List (Interface_List (N)) then
3122 Intf := First (Interface_List (N));
3123 while Present (Intf) loop
3124 T := Find_Type_Of_Subtype_Indic (Intf);
3126 Diagnose_Interface (Intf, T);
3132 Generate_Definition (T);
3135 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
3136 Parent_Base := Base_Type (Parent_Type);
3138 if Parent_Type = Any_Type
3139 or else Etype (Parent_Type) = Any_Type
3141 Set_Ekind (T, Ekind (Parent_Type));
3142 Set_Etype (T, Any_Type);
3145 elsif not Is_Tagged_Type (Parent_Type) then
3147 ("parent of type extension must be a tagged type ", Indic);
3150 elsif Ekind (Parent_Type) = E_Void
3151 or else Ekind (Parent_Type) = E_Incomplete_Type
3153 Error_Msg_N ("premature derivation of incomplete type", Indic);
3156 elsif Is_Concurrent_Type (Parent_Type) then
3158 ("parent type of a private extension cannot be "
3159 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
3161 Set_Etype (T, Any_Type);
3162 Set_Ekind (T, E_Limited_Private_Type);
3163 Set_Private_Dependents (T, New_Elmt_List);
3164 Set_Error_Posted (T);
3168 -- Perhaps the parent type should be changed to the class-wide type's
3169 -- specific type in this case to prevent cascading errors ???
3171 if Is_Class_Wide_Type (Parent_Type) then
3173 ("parent of type extension must not be a class-wide type", Indic);
3177 if (not Is_Package_Or_Generic_Package (Current_Scope)
3178 and then Nkind (Parent (N)) /= N_Generic_Subprogram_Declaration)
3179 or else In_Private_Part (Current_Scope)
3182 Error_Msg_N ("invalid context for private extension", N);
3185 -- Set common attributes
3187 Set_Is_Pure (T, Is_Pure (Current_Scope));
3188 Set_Scope (T, Current_Scope);
3189 Set_Ekind (T, E_Record_Type_With_Private);
3190 Init_Size_Align (T);
3192 Set_Etype (T, Parent_Base);
3193 Set_Has_Task (T, Has_Task (Parent_Base));
3195 Set_Convention (T, Convention (Parent_Type));
3196 Set_First_Rep_Item (T, First_Rep_Item (Parent_Type));
3197 Set_Is_First_Subtype (T);
3198 Make_Class_Wide_Type (T);
3200 if Unknown_Discriminants_Present (N) then
3201 Set_Discriminant_Constraint (T, No_Elist);
3204 Build_Derived_Record_Type (N, Parent_Type, T);
3206 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
3207 -- synchronized formal derived type.
3209 if Ada_Version >= Ada_05
3210 and then Synchronized_Present (N)
3212 Set_Is_Limited_Record (T);
3214 -- Formal derived type case
3216 if Is_Generic_Type (T) then
3218 -- The parent must be a tagged limited type or a synchronized
3221 if (not Is_Tagged_Type (Parent_Type)
3222 or else not Is_Limited_Type (Parent_Type))
3224 (not Is_Interface (Parent_Type)
3225 or else not Is_Synchronized_Interface (Parent_Type))
3227 Error_Msg_NE ("parent type of & must be tagged limited " &
3228 "or synchronized", N, T);
3231 -- The progenitors (if any) must be limited or synchronized
3234 if Present (Interfaces (T)) then
3237 Iface_Elmt : Elmt_Id;
3240 Iface_Elmt := First_Elmt (Interfaces (T));
3241 while Present (Iface_Elmt) loop
3242 Iface := Node (Iface_Elmt);
3244 if not Is_Limited_Interface (Iface)
3245 and then not Is_Synchronized_Interface (Iface)
3247 Error_Msg_NE ("progenitor & must be limited " &
3248 "or synchronized", N, Iface);
3251 Next_Elmt (Iface_Elmt);
3256 -- Regular derived extension, the parent must be a limited or
3257 -- synchronized interface.
3260 if not Is_Interface (Parent_Type)
3261 or else (not Is_Limited_Interface (Parent_Type)
3263 not Is_Synchronized_Interface (Parent_Type))
3266 ("parent type of & must be limited interface", N, T);
3270 elsif Limited_Present (N) then
3271 Set_Is_Limited_Record (T);
3273 if not Is_Limited_Type (Parent_Type)
3275 (not Is_Interface (Parent_Type)
3276 or else not Is_Limited_Interface (Parent_Type))
3278 Error_Msg_NE ("parent type& of limited extension must be limited",
3282 end Analyze_Private_Extension_Declaration;
3284 ---------------------------------
3285 -- Analyze_Subtype_Declaration --
3286 ---------------------------------
3288 procedure Analyze_Subtype_Declaration
3290 Skip : Boolean := False)
3292 Id : constant Entity_Id := Defining_Identifier (N);
3294 R_Checks : Check_Result;
3297 Generate_Definition (Id);
3298 Set_Is_Pure (Id, Is_Pure (Current_Scope));
3299 Init_Size_Align (Id);
3301 -- The following guard condition on Enter_Name is to handle cases where
3302 -- the defining identifier has already been entered into the scope but
3303 -- the declaration as a whole needs to be analyzed.
3305 -- This case in particular happens for derived enumeration types. The
3306 -- derived enumeration type is processed as an inserted enumeration type
3307 -- declaration followed by a rewritten subtype declaration. The defining
3308 -- identifier, however, is entered into the name scope very early in the
3309 -- processing of the original type declaration and therefore needs to be
3310 -- avoided here, when the created subtype declaration is analyzed. (See
3311 -- Build_Derived_Types)
3313 -- This also happens when the full view of a private type is derived
3314 -- type with constraints. In this case the entity has been introduced
3315 -- in the private declaration.
3318 or else (Present (Etype (Id))
3319 and then (Is_Private_Type (Etype (Id))
3320 or else Is_Task_Type (Etype (Id))
3321 or else Is_Rewrite_Substitution (N)))
3329 T := Process_Subtype (Subtype_Indication (N), N, Id, 'P');
3331 -- Inherit common attributes
3333 Set_Is_Generic_Type (Id, Is_Generic_Type (Base_Type (T)));
3334 Set_Is_Volatile (Id, Is_Volatile (T));
3335 Set_Treat_As_Volatile (Id, Treat_As_Volatile (T));
3336 Set_Is_Atomic (Id, Is_Atomic (T));
3337 Set_Is_Ada_2005_Only (Id, Is_Ada_2005_Only (T));
3338 Set_Convention (Id, Convention (T));
3340 -- In the case where there is no constraint given in the subtype
3341 -- indication, Process_Subtype just returns the Subtype_Mark, so its
3342 -- semantic attributes must be established here.
3344 if Nkind (Subtype_Indication (N)) /= N_Subtype_Indication then
3345 Set_Etype (Id, Base_Type (T));
3349 Set_Ekind (Id, E_Array_Subtype);
3350 Copy_Array_Subtype_Attributes (Id, T);
3352 when Decimal_Fixed_Point_Kind =>
3353 Set_Ekind (Id, E_Decimal_Fixed_Point_Subtype);
3354 Set_Digits_Value (Id, Digits_Value (T));
3355 Set_Delta_Value (Id, Delta_Value (T));
3356 Set_Scale_Value (Id, Scale_Value (T));
3357 Set_Small_Value (Id, Small_Value (T));
3358 Set_Scalar_Range (Id, Scalar_Range (T));
3359 Set_Machine_Radix_10 (Id, Machine_Radix_10 (T));
3360 Set_Is_Constrained (Id, Is_Constrained (T));
3361 Set_RM_Size (Id, RM_Size (T));
3363 when Enumeration_Kind =>
3364 Set_Ekind (Id, E_Enumeration_Subtype);
3365 Set_First_Literal (Id, First_Literal (Base_Type (T)));
3366 Set_Scalar_Range (Id, Scalar_Range (T));
3367 Set_Is_Character_Type (Id, Is_Character_Type (T));
3368 Set_Is_Constrained (Id, Is_Constrained (T));
3369 Set_RM_Size (Id, RM_Size (T));
3371 when Ordinary_Fixed_Point_Kind =>
3372 Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype);
3373 Set_Scalar_Range (Id, Scalar_Range (T));
3374 Set_Small_Value (Id, Small_Value (T));
3375 Set_Delta_Value (Id, Delta_Value (T));
3376 Set_Is_Constrained (Id, Is_Constrained (T));
3377 Set_RM_Size (Id, RM_Size (T));
3380 Set_Ekind (Id, E_Floating_Point_Subtype);
3381 Set_Scalar_Range (Id, Scalar_Range (T));
3382 Set_Digits_Value (Id, Digits_Value (T));
3383 Set_Is_Constrained (Id, Is_Constrained (T));
3385 when Signed_Integer_Kind =>
3386 Set_Ekind (Id, E_Signed_Integer_Subtype);
3387 Set_Scalar_Range (Id, Scalar_Range (T));
3388 Set_Is_Constrained (Id, Is_Constrained (T));
3389 Set_RM_Size (Id, RM_Size (T));
3391 when Modular_Integer_Kind =>
3392 Set_Ekind (Id, E_Modular_Integer_Subtype);
3393 Set_Scalar_Range (Id, Scalar_Range (T));
3394 Set_Is_Constrained (Id, Is_Constrained (T));
3395 Set_RM_Size (Id, RM_Size (T));
3397 when Class_Wide_Kind =>
3398 Set_Ekind (Id, E_Class_Wide_Subtype);
3399 Set_First_Entity (Id, First_Entity (T));
3400 Set_Last_Entity (Id, Last_Entity (T));
3401 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3402 Set_Cloned_Subtype (Id, T);
3403 Set_Is_Tagged_Type (Id, True);
3404 Set_Has_Unknown_Discriminants
3407 if Ekind (T) = E_Class_Wide_Subtype then
3408 Set_Equivalent_Type (Id, Equivalent_Type (T));
3411 when E_Record_Type | E_Record_Subtype =>
3412 Set_Ekind (Id, E_Record_Subtype);
3414 if Ekind (T) = E_Record_Subtype
3415 and then Present (Cloned_Subtype (T))
3417 Set_Cloned_Subtype (Id, Cloned_Subtype (T));
3419 Set_Cloned_Subtype (Id, T);
3422 Set_First_Entity (Id, First_Entity (T));
3423 Set_Last_Entity (Id, Last_Entity (T));
3424 Set_Has_Discriminants (Id, Has_Discriminants (T));
3425 Set_Is_Constrained (Id, Is_Constrained (T));
3426 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3427 Set_Has_Unknown_Discriminants
3428 (Id, Has_Unknown_Discriminants (T));
3430 if Has_Discriminants (T) then
3431 Set_Discriminant_Constraint
3432 (Id, Discriminant_Constraint (T));
3433 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3435 elsif Has_Unknown_Discriminants (Id) then
3436 Set_Discriminant_Constraint (Id, No_Elist);
3439 if Is_Tagged_Type (T) then
3440 Set_Is_Tagged_Type (Id);
3441 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3442 Set_Primitive_Operations
3443 (Id, Primitive_Operations (T));
3444 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3446 if Is_Interface (T) then
3447 Set_Is_Interface (Id);
3448 Set_Is_Limited_Interface (Id, Is_Limited_Interface (T));
3452 when Private_Kind =>
3453 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3454 Set_Has_Discriminants (Id, Has_Discriminants (T));
3455 Set_Is_Constrained (Id, Is_Constrained (T));
3456 Set_First_Entity (Id, First_Entity (T));
3457 Set_Last_Entity (Id, Last_Entity (T));
3458 Set_Private_Dependents (Id, New_Elmt_List);
3459 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3460 Set_Has_Unknown_Discriminants
3461 (Id, Has_Unknown_Discriminants (T));
3462 Set_Known_To_Have_Preelab_Init
3463 (Id, Known_To_Have_Preelab_Init (T));
3465 if Is_Tagged_Type (T) then
3466 Set_Is_Tagged_Type (Id);
3467 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3468 Set_Primitive_Operations (Id, Primitive_Operations (T));
3469 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3472 -- In general the attributes of the subtype of a private type
3473 -- are the attributes of the partial view of parent. However,
3474 -- the full view may be a discriminated type, and the subtype
3475 -- must share the discriminant constraint to generate correct
3476 -- calls to initialization procedures.
3478 if Has_Discriminants (T) then
3479 Set_Discriminant_Constraint
3480 (Id, Discriminant_Constraint (T));
3481 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3483 elsif Present (Full_View (T))
3484 and then Has_Discriminants (Full_View (T))
3486 Set_Discriminant_Constraint
3487 (Id, Discriminant_Constraint (Full_View (T)));
3488 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3490 -- This would seem semantically correct, but apparently
3491 -- confuses the back-end. To be explained and checked with
3492 -- current version ???
3494 -- Set_Has_Discriminants (Id);
3497 Prepare_Private_Subtype_Completion (Id, N);
3500 Set_Ekind (Id, E_Access_Subtype);
3501 Set_Is_Constrained (Id, Is_Constrained (T));
3502 Set_Is_Access_Constant
3503 (Id, Is_Access_Constant (T));
3504 Set_Directly_Designated_Type
3505 (Id, Designated_Type (T));
3506 Set_Can_Never_Be_Null (Id, Can_Never_Be_Null (T));
3508 -- A Pure library_item must not contain the declaration of a
3509 -- named access type, except within a subprogram, generic
3510 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
3512 if Comes_From_Source (Id)
3513 and then In_Pure_Unit
3514 and then not In_Subprogram_Task_Protected_Unit
3517 ("named access types not allowed in pure unit", N);
3520 when Concurrent_Kind =>
3521 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3522 Set_Corresponding_Record_Type (Id,
3523 Corresponding_Record_Type (T));
3524 Set_First_Entity (Id, First_Entity (T));
3525 Set_First_Private_Entity (Id, First_Private_Entity (T));
3526 Set_Has_Discriminants (Id, Has_Discriminants (T));
3527 Set_Is_Constrained (Id, Is_Constrained (T));
3528 Set_Is_Tagged_Type (Id, Is_Tagged_Type (T));
3529 Set_Last_Entity (Id, Last_Entity (T));
3531 if Has_Discriminants (T) then
3532 Set_Discriminant_Constraint (Id,
3533 Discriminant_Constraint (T));
3534 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3537 when E_Incomplete_Type =>
3538 if Ada_Version >= Ada_05 then
3539 Set_Ekind (Id, E_Incomplete_Subtype);
3541 -- Ada 2005 (AI-412): Decorate an incomplete subtype
3542 -- of an incomplete type visible through a limited
3545 if From_With_Type (T)
3546 and then Present (Non_Limited_View (T))
3548 Set_From_With_Type (Id);
3549 Set_Non_Limited_View (Id, Non_Limited_View (T));
3551 -- Ada 2005 (AI-412): Add the regular incomplete subtype
3552 -- to the private dependents of the original incomplete
3553 -- type for future transformation.
3556 Append_Elmt (Id, Private_Dependents (T));
3559 -- If the subtype name denotes an incomplete type an error
3560 -- was already reported by Process_Subtype.
3563 Set_Etype (Id, Any_Type);
3567 raise Program_Error;
3571 if Etype (Id) = Any_Type then
3575 -- Some common processing on all types
3577 Set_Size_Info (Id, T);
3578 Set_First_Rep_Item (Id, First_Rep_Item (T));
3582 Set_Is_Immediately_Visible (Id, True);
3583 Set_Depends_On_Private (Id, Has_Private_Component (T));
3584 Set_Is_Descendent_Of_Address (Id, Is_Descendent_Of_Address (T));
3586 if Is_Interface (T) then
3587 Set_Is_Interface (Id);
3590 if Present (Generic_Parent_Type (N))
3593 (Parent (Generic_Parent_Type (N))) /= N_Formal_Type_Declaration
3595 (Formal_Type_Definition (Parent (Generic_Parent_Type (N))))
3596 /= N_Formal_Private_Type_Definition)
3598 if Is_Tagged_Type (Id) then
3600 -- If this is a generic actual subtype for a synchronized type,
3601 -- the primitive operations are those of the corresponding record
3602 -- for which there is a separate subtype declaration.
3604 if Is_Concurrent_Type (Id) then
3606 elsif Is_Class_Wide_Type (Id) then
3607 Derive_Subprograms (Generic_Parent_Type (N), Id, Etype (T));
3609 Derive_Subprograms (Generic_Parent_Type (N), Id, T);
3612 elsif Scope (Etype (Id)) /= Standard_Standard then
3613 Derive_Subprograms (Generic_Parent_Type (N), Id);
3617 if Is_Private_Type (T)
3618 and then Present (Full_View (T))
3620 Conditional_Delay (Id, Full_View (T));
3622 -- The subtypes of components or subcomponents of protected types
3623 -- do not need freeze nodes, which would otherwise appear in the
3624 -- wrong scope (before the freeze node for the protected type). The
3625 -- proper subtypes are those of the subcomponents of the corresponding
3628 elsif Ekind (Scope (Id)) /= E_Protected_Type
3629 and then Present (Scope (Scope (Id))) -- error defense!
3630 and then Ekind (Scope (Scope (Id))) /= E_Protected_Type
3632 Conditional_Delay (Id, T);
3635 -- Check that constraint_error is raised for a scalar subtype
3636 -- indication when the lower or upper bound of a non-null range
3637 -- lies outside the range of the type mark.
3639 if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then
3640 if Is_Scalar_Type (Etype (Id))
3641 and then Scalar_Range (Id) /=
3642 Scalar_Range (Etype (Subtype_Mark
3643 (Subtype_Indication (N))))
3647 Etype (Subtype_Mark (Subtype_Indication (N))));
3649 elsif Is_Array_Type (Etype (Id))
3650 and then Present (First_Index (Id))
3652 -- This really should be a subprogram that finds the indications
3655 if ((Nkind (First_Index (Id)) = N_Identifier
3656 and then Ekind (Entity (First_Index (Id))) in Scalar_Kind)
3657 or else Nkind (First_Index (Id)) = N_Subtype_Indication)
3659 Nkind (Scalar_Range (Etype (First_Index (Id)))) = N_Range
3662 Target_Typ : constant Entity_Id :=
3665 (Subtype_Mark (Subtype_Indication (N)))));
3669 (Scalar_Range (Etype (First_Index (Id))),
3671 Etype (First_Index (Id)),
3672 Defining_Identifier (N));
3678 Sloc (Defining_Identifier (N)));
3684 Set_Optimize_Alignment_Flags (Id);
3685 Check_Eliminated (Id);
3686 end Analyze_Subtype_Declaration;
3688 --------------------------------
3689 -- Analyze_Subtype_Indication --
3690 --------------------------------
3692 procedure Analyze_Subtype_Indication (N : Node_Id) is
3693 T : constant Entity_Id := Subtype_Mark (N);
3694 R : constant Node_Id := Range_Expression (Constraint (N));
3701 Set_Etype (N, Etype (R));
3702 Resolve (R, Entity (T));
3704 Set_Error_Posted (R);
3705 Set_Error_Posted (T);
3707 end Analyze_Subtype_Indication;
3709 ------------------------------
3710 -- Analyze_Type_Declaration --
3711 ------------------------------
3713 procedure Analyze_Type_Declaration (N : Node_Id) is
3714 Def : constant Node_Id := Type_Definition (N);
3715 Def_Id : constant Entity_Id := Defining_Identifier (N);
3719 Is_Remote : constant Boolean :=
3720 (Is_Remote_Types (Current_Scope)
3721 or else Is_Remote_Call_Interface (Current_Scope))
3722 and then not (In_Private_Part (Current_Scope)
3723 or else In_Package_Body (Current_Scope));
3725 procedure Check_Ops_From_Incomplete_Type;
3726 -- If there is a tagged incomplete partial view of the type, transfer
3727 -- its operations to the full view, and indicate that the type of the
3728 -- controlling parameter (s) is this full view.
3730 ------------------------------------
3731 -- Check_Ops_From_Incomplete_Type --
3732 ------------------------------------
3734 procedure Check_Ops_From_Incomplete_Type is
3741 and then Ekind (Prev) = E_Incomplete_Type
3742 and then Is_Tagged_Type (Prev)
3743 and then Is_Tagged_Type (T)
3745 Elmt := First_Elmt (Primitive_Operations (Prev));
3746 while Present (Elmt) loop
3748 Prepend_Elmt (Op, Primitive_Operations (T));
3750 Formal := First_Formal (Op);
3751 while Present (Formal) loop
3752 if Etype (Formal) = Prev then
3753 Set_Etype (Formal, T);
3756 Next_Formal (Formal);
3759 if Etype (Op) = Prev then
3766 end Check_Ops_From_Incomplete_Type;
3768 -- Start of processing for Analyze_Type_Declaration
3771 Prev := Find_Type_Name (N);
3773 -- The full view, if present, now points to the current type
3775 -- Ada 2005 (AI-50217): If the type was previously decorated when
3776 -- imported through a LIMITED WITH clause, it appears as incomplete
3777 -- but has no full view.
3778 -- If the incomplete view is tagged, a class_wide type has been
3779 -- created already. Use it for the full view as well, to prevent
3780 -- multiple incompatible class-wide types that may be created for
3781 -- self-referential anonymous access components.
3783 if Ekind (Prev) = E_Incomplete_Type
3784 and then Present (Full_View (Prev))
3786 T := Full_View (Prev);
3788 if Is_Tagged_Type (Prev)
3789 and then Present (Class_Wide_Type (Prev))
3791 Set_Ekind (T, Ekind (Prev)); -- will be reset later
3792 Set_Class_Wide_Type (T, Class_Wide_Type (Prev));
3793 Set_Etype (Class_Wide_Type (T), T);
3800 Set_Is_Pure (T, Is_Pure (Current_Scope));
3802 -- We set the flag Is_First_Subtype here. It is needed to set the
3803 -- corresponding flag for the Implicit class-wide-type created
3804 -- during tagged types processing.
3806 Set_Is_First_Subtype (T, True);
3808 -- Only composite types other than array types are allowed to have
3813 -- For derived types, the rule will be checked once we've figured
3814 -- out the parent type.
3816 when N_Derived_Type_Definition =>
3819 -- For record types, discriminants are allowed
3821 when N_Record_Definition =>
3825 if Present (Discriminant_Specifications (N)) then
3827 ("elementary or array type cannot have discriminants",
3829 (First (Discriminant_Specifications (N))));
3833 -- Elaborate the type definition according to kind, and generate
3834 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3835 -- already done (this happens during the reanalysis that follows a call
3836 -- to the high level optimizer).
3838 if not Analyzed (T) then
3843 when N_Access_To_Subprogram_Definition =>
3844 Access_Subprogram_Declaration (T, Def);
3846 -- If this is a remote access to subprogram, we must create the
3847 -- equivalent fat pointer type, and related subprograms.
3850 Process_Remote_AST_Declaration (N);
3853 -- Validate categorization rule against access type declaration
3854 -- usually a violation in Pure unit, Shared_Passive unit.
3856 Validate_Access_Type_Declaration (T, N);
3858 when N_Access_To_Object_Definition =>
3859 Access_Type_Declaration (T, Def);
3861 -- Validate categorization rule against access type declaration
3862 -- usually a violation in Pure unit, Shared_Passive unit.
3864 Validate_Access_Type_Declaration (T, N);
3866 -- If we are in a Remote_Call_Interface package and define a
3867 -- RACW, then calling stubs and specific stream attributes
3871 and then Is_Remote_Access_To_Class_Wide_Type (Def_Id)
3873 Add_RACW_Features (Def_Id);
3876 -- Set no strict aliasing flag if config pragma seen
3878 if Opt.No_Strict_Aliasing then
3879 Set_No_Strict_Aliasing (Base_Type (Def_Id));
3882 when N_Array_Type_Definition =>
3883 Array_Type_Declaration (T, Def);
3885 when N_Derived_Type_Definition =>
3886 Derived_Type_Declaration (T, N, T /= Def_Id);
3888 when N_Enumeration_Type_Definition =>
3889 Enumeration_Type_Declaration (T, Def);
3891 when N_Floating_Point_Definition =>
3892 Floating_Point_Type_Declaration (T, Def);
3894 when N_Decimal_Fixed_Point_Definition =>
3895 Decimal_Fixed_Point_Type_Declaration (T, Def);
3897 when N_Ordinary_Fixed_Point_Definition =>
3898 Ordinary_Fixed_Point_Type_Declaration (T, Def);
3900 when N_Signed_Integer_Type_Definition =>
3901 Signed_Integer_Type_Declaration (T, Def);
3903 when N_Modular_Type_Definition =>
3904 Modular_Type_Declaration (T, Def);
3906 when N_Record_Definition =>
3907 Record_Type_Declaration (T, N, Prev);
3910 raise Program_Error;
3915 if Etype (T) = Any_Type then
3919 -- Some common processing for all types
3921 Set_Depends_On_Private (T, Has_Private_Component (T));
3922 Check_Ops_From_Incomplete_Type;
3924 -- Both the declared entity, and its anonymous base type if one
3925 -- was created, need freeze nodes allocated.
3928 B : constant Entity_Id := Base_Type (T);
3931 -- In the case where the base type differs from the first subtype, we
3932 -- pre-allocate a freeze node, and set the proper link to the first
3933 -- subtype. Freeze_Entity will use this preallocated freeze node when
3934 -- it freezes the entity.
3937 Ensure_Freeze_Node (B);
3938 Set_First_Subtype_Link (Freeze_Node (B), T);
3941 if not From_With_Type (T) then
3942 Set_Has_Delayed_Freeze (T);
3946 -- Case of T is the full declaration of some private type which has
3947 -- been swapped in Defining_Identifier (N).
3949 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3950 Process_Full_View (N, T, Def_Id);
3952 -- Record the reference. The form of this is a little strange, since
3953 -- the full declaration has been swapped in. So the first parameter
3954 -- here represents the entity to which a reference is made which is
3955 -- the "real" entity, i.e. the one swapped in, and the second
3956 -- parameter provides the reference location.
3958 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3959 -- since we don't want a complaint about the full type being an
3960 -- unwanted reference to the private type
3963 B : constant Boolean := Has_Pragma_Unreferenced (T);
3965 Set_Has_Pragma_Unreferenced (T, False);
3966 Generate_Reference (T, T, 'c');
3967 Set_Has_Pragma_Unreferenced (T, B);
3970 Set_Completion_Referenced (Def_Id);
3972 -- For completion of incomplete type, process incomplete dependents
3973 -- and always mark the full type as referenced (it is the incomplete
3974 -- type that we get for any real reference).
3976 elsif Ekind (Prev) = E_Incomplete_Type then
3977 Process_Incomplete_Dependents (N, T, Prev);
3978 Generate_Reference (Prev, Def_Id, 'c');
3979 Set_Completion_Referenced (Def_Id);
3981 -- If not private type or incomplete type completion, this is a real
3982 -- definition of a new entity, so record it.
3985 Generate_Definition (Def_Id);
3988 if Chars (Scope (Def_Id)) = Name_System
3989 and then Chars (Def_Id) = Name_Address
3990 and then Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (N)))
3992 Set_Is_Descendent_Of_Address (Def_Id);
3993 Set_Is_Descendent_Of_Address (Base_Type (Def_Id));
3994 Set_Is_Descendent_Of_Address (Prev);
3997 Set_Optimize_Alignment_Flags (Def_Id);
3998 Check_Eliminated (Def_Id);
3999 end Analyze_Type_Declaration;
4001 --------------------------
4002 -- Analyze_Variant_Part --
4003 --------------------------
4005 procedure Analyze_Variant_Part (N : Node_Id) is
4007 procedure Non_Static_Choice_Error (Choice : Node_Id);
4008 -- Error routine invoked by the generic instantiation below when the
4009 -- variant part has a non static choice.
4011 procedure Process_Declarations (Variant : Node_Id);
4012 -- Analyzes all the declarations associated with a Variant. Needed by
4013 -- the generic instantiation below.
4015 package Variant_Choices_Processing is new
4016 Generic_Choices_Processing
4017 (Get_Alternatives => Variants,
4018 Get_Choices => Discrete_Choices,
4019 Process_Empty_Choice => No_OP,
4020 Process_Non_Static_Choice => Non_Static_Choice_Error,
4021 Process_Associated_Node => Process_Declarations);
4022 use Variant_Choices_Processing;
4023 -- Instantiation of the generic choice processing package
4025 -----------------------------
4026 -- Non_Static_Choice_Error --
4027 -----------------------------
4029 procedure Non_Static_Choice_Error (Choice : Node_Id) is
4031 Flag_Non_Static_Expr
4032 ("choice given in variant part is not static!", Choice);
4033 end Non_Static_Choice_Error;
4035 --------------------------
4036 -- Process_Declarations --
4037 --------------------------
4039 procedure Process_Declarations (Variant : Node_Id) is
4041 if not Null_Present (Component_List (Variant)) then
4042 Analyze_Declarations (Component_Items (Component_List (Variant)));
4044 if Present (Variant_Part (Component_List (Variant))) then
4045 Analyze (Variant_Part (Component_List (Variant)));
4048 end Process_Declarations;
4052 Discr_Name : Node_Id;
4053 Discr_Type : Entity_Id;
4055 Case_Table : Choice_Table_Type (1 .. Number_Of_Choices (N));
4057 Dont_Care : Boolean;
4058 Others_Present : Boolean := False;
4060 pragma Warnings (Off, Case_Table);
4061 pragma Warnings (Off, Last_Choice);
4062 pragma Warnings (Off, Dont_Care);
4063 pragma Warnings (Off, Others_Present);
4064 -- We don't care about the assigned values of any of these
4066 -- Start of processing for Analyze_Variant_Part
4069 Discr_Name := Name (N);
4070 Analyze (Discr_Name);
4072 -- If Discr_Name bad, get out (prevent cascaded errors)
4074 if Etype (Discr_Name) = Any_Type then
4078 -- Check invalid discriminant in variant part
4080 if Ekind (Entity (Discr_Name)) /= E_Discriminant then
4081 Error_Msg_N ("invalid discriminant name in variant part", Discr_Name);
4084 Discr_Type := Etype (Entity (Discr_Name));
4086 if not Is_Discrete_Type (Discr_Type) then
4088 ("discriminant in a variant part must be of a discrete type",
4093 -- Call the instantiated Analyze_Choices which does the rest of the work
4096 (N, Discr_Type, Case_Table, Last_Choice, Dont_Care, Others_Present);
4097 end Analyze_Variant_Part;
4099 ----------------------------
4100 -- Array_Type_Declaration --
4101 ----------------------------
4103 procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id) is
4104 Component_Def : constant Node_Id := Component_Definition (Def);
4105 Element_Type : Entity_Id;
4106 Implicit_Base : Entity_Id;
4108 Related_Id : Entity_Id := Empty;
4110 P : constant Node_Id := Parent (Def);
4114 if Nkind (Def) = N_Constrained_Array_Definition then
4115 Index := First (Discrete_Subtype_Definitions (Def));
4117 Index := First (Subtype_Marks (Def));
4120 -- Find proper names for the implicit types which may be public. In case
4121 -- of anonymous arrays we use the name of the first object of that type
4125 Related_Id := Defining_Identifier (P);
4131 while Present (Index) loop
4134 -- Add a subtype declaration for each index of private array type
4135 -- declaration whose etype is also private. For example:
4138 -- type Index is private;
4140 -- type Table is array (Index) of ...
4143 -- This is currently required by the expander for the internally
4144 -- generated equality subprogram of records with variant parts in
4145 -- which the etype of some component is such private type.
4147 if Ekind (Current_Scope) = E_Package
4148 and then In_Private_Part (Current_Scope)
4149 and then Has_Private_Declaration (Etype (Index))
4152 Loc : constant Source_Ptr := Sloc (Def);
4158 Make_Defining_Identifier (Loc,
4159 Chars => New_Internal_Name ('T'));
4160 Set_Is_Internal (New_E);
4163 Make_Subtype_Declaration (Loc,
4164 Defining_Identifier => New_E,
4165 Subtype_Indication =>
4166 New_Occurrence_Of (Etype (Index), Loc));
4168 Insert_Before (Parent (Def), Decl);
4170 Set_Etype (Index, New_E);
4172 -- If the index is a range the Entity attribute is not
4173 -- available. Example:
4176 -- type T is private;
4178 -- type T is new Natural;
4179 -- Table : array (T(1) .. T(10)) of Boolean;
4182 if Nkind (Index) /= N_Range then
4183 Set_Entity (Index, New_E);
4188 Make_Index (Index, P, Related_Id, Nb_Index);
4190 Nb_Index := Nb_Index + 1;
4193 -- Process subtype indication if one is present
4195 if Present (Subtype_Indication (Component_Def)) then
4198 (Subtype_Indication (Component_Def), P, Related_Id, 'C');
4200 -- Ada 2005 (AI-230): Access Definition case
4202 else pragma Assert (Present (Access_Definition (Component_Def)));
4204 -- Indicate that the anonymous access type is created by the
4205 -- array type declaration.
4207 Element_Type := Access_Definition
4209 N => Access_Definition (Component_Def));
4210 Set_Is_Local_Anonymous_Access (Element_Type);
4212 -- Propagate the parent. This field is needed if we have to generate
4213 -- the master_id associated with an anonymous access to task type
4214 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
4216 Set_Parent (Element_Type, Parent (T));
4218 -- Ada 2005 (AI-230): In case of components that are anonymous access
4219 -- types the level of accessibility depends on the enclosing type
4222 Set_Scope (Element_Type, Current_Scope); -- Ada 2005 (AI-230)
4224 -- Ada 2005 (AI-254)
4227 CD : constant Node_Id :=
4228 Access_To_Subprogram_Definition
4229 (Access_Definition (Component_Def));
4231 if Present (CD) and then Protected_Present (CD) then
4233 Replace_Anonymous_Access_To_Protected_Subprogram (Def);
4238 -- Constrained array case
4241 T := Create_Itype (E_Void, P, Related_Id, 'T');
4244 if Nkind (Def) = N_Constrained_Array_Definition then
4246 -- Establish Implicit_Base as unconstrained base type
4248 Implicit_Base := Create_Itype (E_Array_Type, P, Related_Id, 'B');
4250 Set_Etype (Implicit_Base, Implicit_Base);
4251 Set_Scope (Implicit_Base, Current_Scope);
4252 Set_Has_Delayed_Freeze (Implicit_Base);
4254 -- The constrained array type is a subtype of the unconstrained one
4256 Set_Ekind (T, E_Array_Subtype);
4257 Init_Size_Align (T);
4258 Set_Etype (T, Implicit_Base);
4259 Set_Scope (T, Current_Scope);
4260 Set_Is_Constrained (T, True);
4261 Set_First_Index (T, First (Discrete_Subtype_Definitions (Def)));
4262 Set_Has_Delayed_Freeze (T);
4264 -- Complete setup of implicit base type
4266 Set_First_Index (Implicit_Base, First_Index (T));
4267 Set_Component_Type (Implicit_Base, Element_Type);
4268 Set_Has_Task (Implicit_Base, Has_Task (Element_Type));
4269 Set_Component_Size (Implicit_Base, Uint_0);
4270 Set_Packed_Array_Type (Implicit_Base, Empty);
4271 Set_Has_Controlled_Component
4272 (Implicit_Base, Has_Controlled_Component
4274 or else Is_Controlled
4276 Set_Finalize_Storage_Only
4277 (Implicit_Base, Finalize_Storage_Only
4280 -- Unconstrained array case
4283 Set_Ekind (T, E_Array_Type);
4284 Init_Size_Align (T);
4286 Set_Scope (T, Current_Scope);
4287 Set_Component_Size (T, Uint_0);
4288 Set_Is_Constrained (T, False);
4289 Set_First_Index (T, First (Subtype_Marks (Def)));
4290 Set_Has_Delayed_Freeze (T, True);
4291 Set_Has_Task (T, Has_Task (Element_Type));
4292 Set_Has_Controlled_Component (T, Has_Controlled_Component
4295 Is_Controlled (Element_Type));
4296 Set_Finalize_Storage_Only (T, Finalize_Storage_Only
4300 -- Common attributes for both cases
4302 Set_Component_Type (Base_Type (T), Element_Type);
4303 Set_Packed_Array_Type (T, Empty);
4305 if Aliased_Present (Component_Definition (Def)) then
4306 Set_Has_Aliased_Components (Etype (T));
4309 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
4310 -- array type to ensure that objects of this type are initialized.
4312 if Ada_Version >= Ada_05
4313 and then Can_Never_Be_Null (Element_Type)
4315 Set_Can_Never_Be_Null (T);
4317 if Null_Exclusion_Present (Component_Definition (Def))
4319 -- No need to check itypes because in their case this check was
4320 -- done at their point of creation
4322 and then not Is_Itype (Element_Type)
4325 ("`NOT NULL` not allowed (null already excluded)",
4326 Subtype_Indication (Component_Definition (Def)));
4330 Priv := Private_Component (Element_Type);
4332 if Present (Priv) then
4334 -- Check for circular definitions
4336 if Priv = Any_Type then
4337 Set_Component_Type (Etype (T), Any_Type);
4339 -- There is a gap in the visibility of operations on the composite
4340 -- type only if the component type is defined in a different scope.
4342 elsif Scope (Priv) = Current_Scope then
4345 elsif Is_Limited_Type (Priv) then
4346 Set_Is_Limited_Composite (Etype (T));
4347 Set_Is_Limited_Composite (T);
4349 Set_Is_Private_Composite (Etype (T));
4350 Set_Is_Private_Composite (T);
4354 -- A syntax error in the declaration itself may lead to an empty index
4355 -- list, in which case do a minimal patch.
4357 if No (First_Index (T)) then
4358 Error_Msg_N ("missing index definition in array type declaration", T);
4361 Indices : constant List_Id :=
4362 New_List (New_Occurrence_Of (Any_Id, Sloc (T)));
4364 Set_Discrete_Subtype_Definitions (Def, Indices);
4365 Set_First_Index (T, First (Indices));
4370 -- Create a concatenation operator for the new type. Internal array
4371 -- types created for packed entities do not need such, they are
4372 -- compatible with the user-defined type.
4374 if Number_Dimensions (T) = 1
4375 and then not Is_Packed_Array_Type (T)
4377 New_Concatenation_Op (T);
4380 -- In the case of an unconstrained array the parser has already verified
4381 -- that all the indices are unconstrained but we still need to make sure
4382 -- that the element type is constrained.
4384 if Is_Indefinite_Subtype (Element_Type) then
4386 ("unconstrained element type in array declaration",
4387 Subtype_Indication (Component_Def));
4389 elsif Is_Abstract_Type (Element_Type) then
4391 ("the type of a component cannot be abstract",
4392 Subtype_Indication (Component_Def));
4394 end Array_Type_Declaration;
4396 ------------------------------------------------------
4397 -- Replace_Anonymous_Access_To_Protected_Subprogram --
4398 ------------------------------------------------------
4400 function Replace_Anonymous_Access_To_Protected_Subprogram
4401 (N : Node_Id) return Entity_Id
4403 Loc : constant Source_Ptr := Sloc (N);
4405 Curr_Scope : constant Scope_Stack_Entry :=
4406 Scope_Stack.Table (Scope_Stack.Last);
4408 Anon : constant Entity_Id :=
4409 Make_Defining_Identifier (Loc,
4410 Chars => New_Internal_Name ('S'));
4418 Set_Is_Internal (Anon);
4421 when N_Component_Declaration |
4422 N_Unconstrained_Array_Definition |
4423 N_Constrained_Array_Definition =>
4424 Comp := Component_Definition (N);
4425 Acc := Access_Definition (Comp);
4427 when N_Discriminant_Specification =>
4428 Comp := Discriminant_Type (N);
4431 when N_Parameter_Specification =>
4432 Comp := Parameter_Type (N);
4435 when N_Access_Function_Definition =>
4436 Comp := Result_Definition (N);
4439 when N_Object_Declaration =>
4440 Comp := Object_Definition (N);
4444 raise Program_Error;
4447 Decl := Make_Full_Type_Declaration (Loc,
4448 Defining_Identifier => Anon,
4450 Copy_Separate_Tree (Access_To_Subprogram_Definition (Acc)));
4452 Mark_Rewrite_Insertion (Decl);
4454 -- Insert the new declaration in the nearest enclosing scope
4457 while Present (P) and then not Has_Declarations (P) loop
4461 pragma Assert (Present (P));
4463 if Nkind (P) = N_Package_Specification then
4464 Prepend (Decl, Visible_Declarations (P));
4466 Prepend (Decl, Declarations (P));
4469 -- Replace the anonymous type with an occurrence of the new declaration.
4470 -- In all cases the rewritten node does not have the null-exclusion
4471 -- attribute because (if present) it was already inherited by the
4472 -- anonymous entity (Anon). Thus, in case of components we do not
4473 -- inherit this attribute.
4475 if Nkind (N) = N_Parameter_Specification then
4476 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4477 Set_Etype (Defining_Identifier (N), Anon);
4478 Set_Null_Exclusion_Present (N, False);
4480 elsif Nkind (N) = N_Object_Declaration then
4481 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4482 Set_Etype (Defining_Identifier (N), Anon);
4484 elsif Nkind (N) = N_Access_Function_Definition then
4485 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4489 Make_Component_Definition (Loc,
4490 Subtype_Indication => New_Occurrence_Of (Anon, Loc)));
4493 Mark_Rewrite_Insertion (Comp);
4495 -- Temporarily remove the current scope from the stack to add the new
4496 -- declarations to the enclosing scope
4498 if Nkind_In (N, N_Object_Declaration, N_Access_Function_Definition) then
4502 Scope_Stack.Decrement_Last;
4504 Set_Is_Itype (Anon);
4505 Scope_Stack.Append (Curr_Scope);
4508 Set_Ekind (Anon, E_Anonymous_Access_Protected_Subprogram_Type);
4509 Set_Can_Use_Internal_Rep (Anon, not Always_Compatible_Rep_On_Target);
4511 end Replace_Anonymous_Access_To_Protected_Subprogram;
4513 -------------------------------
4514 -- Build_Derived_Access_Type --
4515 -------------------------------
4517 procedure Build_Derived_Access_Type
4519 Parent_Type : Entity_Id;
4520 Derived_Type : Entity_Id)
4522 S : constant Node_Id := Subtype_Indication (Type_Definition (N));
4524 Desig_Type : Entity_Id;
4526 Discr_Con_Elist : Elist_Id;
4527 Discr_Con_El : Elmt_Id;
4531 -- Set the designated type so it is available in case this is an access
4532 -- to a self-referential type, e.g. a standard list type with a next
4533 -- pointer. Will be reset after subtype is built.
4535 Set_Directly_Designated_Type
4536 (Derived_Type, Designated_Type (Parent_Type));
4538 Subt := Process_Subtype (S, N);
4540 if Nkind (S) /= N_Subtype_Indication
4541 and then Subt /= Base_Type (Subt)
4543 Set_Ekind (Derived_Type, E_Access_Subtype);
4546 if Ekind (Derived_Type) = E_Access_Subtype then
4548 Pbase : constant Entity_Id := Base_Type (Parent_Type);
4549 Ibase : constant Entity_Id :=
4550 Create_Itype (Ekind (Pbase), N, Derived_Type, 'B');
4551 Svg_Chars : constant Name_Id := Chars (Ibase);
4552 Svg_Next_E : constant Entity_Id := Next_Entity (Ibase);
4555 Copy_Node (Pbase, Ibase);
4557 Set_Chars (Ibase, Svg_Chars);
4558 Set_Next_Entity (Ibase, Svg_Next_E);
4559 Set_Sloc (Ibase, Sloc (Derived_Type));
4560 Set_Scope (Ibase, Scope (Derived_Type));
4561 Set_Freeze_Node (Ibase, Empty);
4562 Set_Is_Frozen (Ibase, False);
4563 Set_Comes_From_Source (Ibase, False);
4564 Set_Is_First_Subtype (Ibase, False);
4566 Set_Etype (Ibase, Pbase);
4567 Set_Etype (Derived_Type, Ibase);
4571 Set_Directly_Designated_Type
4572 (Derived_Type, Designated_Type (Subt));
4574 Set_Is_Constrained (Derived_Type, Is_Constrained (Subt));
4575 Set_Is_Access_Constant (Derived_Type, Is_Access_Constant (Parent_Type));
4576 Set_Size_Info (Derived_Type, Parent_Type);
4577 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
4578 Set_Depends_On_Private (Derived_Type,
4579 Has_Private_Component (Derived_Type));
4580 Conditional_Delay (Derived_Type, Subt);
4582 -- Ada 2005 (AI-231). Set the null-exclusion attribute
4584 if Null_Exclusion_Present (Type_Definition (N))
4585 or else Can_Never_Be_Null (Parent_Type)
4587 Set_Can_Never_Be_Null (Derived_Type);
4590 -- Note: we do not copy the Storage_Size_Variable, since we always go to
4591 -- the root type for this information.
4593 -- Apply range checks to discriminants for derived record case
4594 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
4596 Desig_Type := Designated_Type (Derived_Type);
4597 if Is_Composite_Type (Desig_Type)
4598 and then (not Is_Array_Type (Desig_Type))
4599 and then Has_Discriminants (Desig_Type)
4600 and then Base_Type (Desig_Type) /= Desig_Type
4602 Discr_Con_Elist := Discriminant_Constraint (Desig_Type);
4603 Discr_Con_El := First_Elmt (Discr_Con_Elist);
4605 Discr := First_Discriminant (Base_Type (Desig_Type));
4606 while Present (Discr_Con_El) loop
4607 Apply_Range_Check (Node (Discr_Con_El), Etype (Discr));
4608 Next_Elmt (Discr_Con_El);
4609 Next_Discriminant (Discr);
4612 end Build_Derived_Access_Type;
4614 ------------------------------
4615 -- Build_Derived_Array_Type --
4616 ------------------------------
4618 procedure Build_Derived_Array_Type
4620 Parent_Type : Entity_Id;
4621 Derived_Type : Entity_Id)
4623 Loc : constant Source_Ptr := Sloc (N);
4624 Tdef : constant Node_Id := Type_Definition (N);
4625 Indic : constant Node_Id := Subtype_Indication (Tdef);
4626 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
4627 Implicit_Base : Entity_Id;
4628 New_Indic : Node_Id;
4630 procedure Make_Implicit_Base;
4631 -- If the parent subtype is constrained, the derived type is a subtype
4632 -- of an implicit base type derived from the parent base.
4634 ------------------------
4635 -- Make_Implicit_Base --
4636 ------------------------
4638 procedure Make_Implicit_Base is
4641 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
4643 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
4644 Set_Etype (Implicit_Base, Parent_Base);
4646 Copy_Array_Subtype_Attributes (Implicit_Base, Parent_Base);
4647 Copy_Array_Base_Type_Attributes (Implicit_Base, Parent_Base);
4649 Set_Has_Delayed_Freeze (Implicit_Base, True);
4650 end Make_Implicit_Base;
4652 -- Start of processing for Build_Derived_Array_Type
4655 if not Is_Constrained (Parent_Type) then
4656 if Nkind (Indic) /= N_Subtype_Indication then
4657 Set_Ekind (Derived_Type, E_Array_Type);
4659 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4660 Copy_Array_Base_Type_Attributes (Derived_Type, Parent_Type);
4662 Set_Has_Delayed_Freeze (Derived_Type, True);
4666 Set_Etype (Derived_Type, Implicit_Base);
4669 Make_Subtype_Declaration (Loc,
4670 Defining_Identifier => Derived_Type,
4671 Subtype_Indication =>
4672 Make_Subtype_Indication (Loc,
4673 Subtype_Mark => New_Reference_To (Implicit_Base, Loc),
4674 Constraint => Constraint (Indic)));
4676 Rewrite (N, New_Indic);
4681 if Nkind (Indic) /= N_Subtype_Indication then
4684 Set_Ekind (Derived_Type, Ekind (Parent_Type));
4685 Set_Etype (Derived_Type, Implicit_Base);
4686 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4689 Error_Msg_N ("illegal constraint on constrained type", Indic);
4693 -- If parent type is not a derived type itself, and is declared in
4694 -- closed scope (e.g. a subprogram), then we must explicitly introduce
4695 -- the new type's concatenation operator since Derive_Subprograms
4696 -- will not inherit the parent's operator. If the parent type is
4697 -- unconstrained, the operator is of the unconstrained base type.
4699 if Number_Dimensions (Parent_Type) = 1
4700 and then not Is_Limited_Type (Parent_Type)
4701 and then not Is_Derived_Type (Parent_Type)
4702 and then not Is_Package_Or_Generic_Package
4703 (Scope (Base_Type (Parent_Type)))
4705 if not Is_Constrained (Parent_Type)
4706 and then Is_Constrained (Derived_Type)
4708 New_Concatenation_Op (Implicit_Base);
4710 New_Concatenation_Op (Derived_Type);
4713 end Build_Derived_Array_Type;
4715 -----------------------------------
4716 -- Build_Derived_Concurrent_Type --
4717 -----------------------------------
4719 procedure Build_Derived_Concurrent_Type
4721 Parent_Type : Entity_Id;
4722 Derived_Type : Entity_Id)
4724 D_Constraint : Node_Id;
4725 Disc_Spec : Node_Id;
4726 Old_Disc : Entity_Id;
4727 New_Disc : Entity_Id;
4729 Constraint_Present : constant Boolean :=
4730 Nkind (Subtype_Indication (Type_Definition (N)))
4731 = N_Subtype_Indication;
4734 Set_Stored_Constraint (Derived_Type, No_Elist);
4736 -- Copy Storage_Size and Relative_Deadline variables if task case
4738 if Is_Task_Type (Parent_Type) then
4739 Set_Storage_Size_Variable (Derived_Type,
4740 Storage_Size_Variable (Parent_Type));
4741 Set_Relative_Deadline_Variable (Derived_Type,
4742 Relative_Deadline_Variable (Parent_Type));
4745 if Present (Discriminant_Specifications (N)) then
4746 Push_Scope (Derived_Type);
4747 Check_Or_Process_Discriminants (N, Derived_Type);
4750 elsif Constraint_Present then
4752 -- Build constrained subtype and derive from it
4755 Loc : constant Source_Ptr := Sloc (N);
4756 Anon : constant Entity_Id :=
4757 Make_Defining_Identifier (Loc,
4758 New_External_Name (Chars (Derived_Type), 'T'));
4763 Make_Subtype_Declaration (Loc,
4764 Defining_Identifier => Anon,
4765 Subtype_Indication =>
4766 Subtype_Indication (Type_Definition (N)));
4767 Insert_Before (N, Decl);
4770 Rewrite (Subtype_Indication (Type_Definition (N)),
4771 New_Occurrence_Of (Anon, Loc));
4772 Set_Analyzed (Derived_Type, False);
4778 -- All attributes are inherited from parent. In particular,
4779 -- entries and the corresponding record type are the same.
4780 -- Discriminants may be renamed, and must be treated separately.
4782 Set_Has_Discriminants
4783 (Derived_Type, Has_Discriminants (Parent_Type));
4784 Set_Corresponding_Record_Type
4785 (Derived_Type, Corresponding_Record_Type (Parent_Type));
4787 -- Is_Constrained is set according the parent subtype, but is set to
4788 -- False if the derived type is declared with new discriminants.
4792 (Is_Constrained (Parent_Type) or else Constraint_Present)
4793 and then not Present (Discriminant_Specifications (N)));
4795 if Constraint_Present then
4796 if not Has_Discriminants (Parent_Type) then
4797 Error_Msg_N ("untagged parent must have discriminants", N);
4799 elsif Present (Discriminant_Specifications (N)) then
4801 -- Verify that new discriminants are used to constrain old ones
4806 (Constraint (Subtype_Indication (Type_Definition (N)))));
4808 Old_Disc := First_Discriminant (Parent_Type);
4809 New_Disc := First_Discriminant (Derived_Type);
4810 Disc_Spec := First (Discriminant_Specifications (N));
4811 while Present (Old_Disc) and then Present (Disc_Spec) loop
4812 if Nkind (Discriminant_Type (Disc_Spec)) /=
4815 Analyze (Discriminant_Type (Disc_Spec));
4817 if not Subtypes_Statically_Compatible (
4818 Etype (Discriminant_Type (Disc_Spec)),
4822 ("not statically compatible with parent discriminant",
4823 Discriminant_Type (Disc_Spec));
4827 if Nkind (D_Constraint) = N_Identifier
4828 and then Chars (D_Constraint) /=
4829 Chars (Defining_Identifier (Disc_Spec))
4831 Error_Msg_N ("new discriminants must constrain old ones",
4834 Set_Corresponding_Discriminant (New_Disc, Old_Disc);
4837 Next_Discriminant (Old_Disc);
4838 Next_Discriminant (New_Disc);
4842 if Present (Old_Disc) or else Present (Disc_Spec) then
4843 Error_Msg_N ("discriminant mismatch in derivation", N);
4848 elsif Present (Discriminant_Specifications (N)) then
4850 ("missing discriminant constraint in untagged derivation",
4854 if Present (Discriminant_Specifications (N)) then
4855 Old_Disc := First_Discriminant (Parent_Type);
4856 while Present (Old_Disc) loop
4858 if No (Next_Entity (Old_Disc))
4859 or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant
4861 Set_Next_Entity (Last_Entity (Derived_Type),
4862 Next_Entity (Old_Disc));
4866 Next_Discriminant (Old_Disc);
4870 Set_First_Entity (Derived_Type, First_Entity (Parent_Type));
4871 if Has_Discriminants (Parent_Type) then
4872 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
4873 Set_Discriminant_Constraint (
4874 Derived_Type, Discriminant_Constraint (Parent_Type));
4878 Set_Last_Entity (Derived_Type, Last_Entity (Parent_Type));
4880 Set_Has_Completion (Derived_Type);
4881 end Build_Derived_Concurrent_Type;
4883 ------------------------------------
4884 -- Build_Derived_Enumeration_Type --
4885 ------------------------------------
4887 procedure Build_Derived_Enumeration_Type
4889 Parent_Type : Entity_Id;
4890 Derived_Type : Entity_Id)
4892 Loc : constant Source_Ptr := Sloc (N);
4893 Def : constant Node_Id := Type_Definition (N);
4894 Indic : constant Node_Id := Subtype_Indication (Def);
4895 Implicit_Base : Entity_Id;
4896 Literal : Entity_Id;
4897 New_Lit : Entity_Id;
4898 Literals_List : List_Id;
4899 Type_Decl : Node_Id;
4901 Rang_Expr : Node_Id;
4904 -- Since types Standard.Character and Standard.Wide_Character do
4905 -- not have explicit literals lists we need to process types derived
4906 -- from them specially. This is handled by Derived_Standard_Character.
4907 -- If the parent type is a generic type, there are no literals either,
4908 -- and we construct the same skeletal representation as for the generic
4911 if Is_Standard_Character_Type (Parent_Type) then
4912 Derived_Standard_Character (N, Parent_Type, Derived_Type);
4914 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
4921 Make_Attribute_Reference (Loc,
4922 Attribute_Name => Name_First,
4923 Prefix => New_Reference_To (Derived_Type, Loc));
4924 Set_Etype (Lo, Derived_Type);
4927 Make_Attribute_Reference (Loc,
4928 Attribute_Name => Name_Last,
4929 Prefix => New_Reference_To (Derived_Type, Loc));
4930 Set_Etype (Hi, Derived_Type);
4932 Set_Scalar_Range (Derived_Type,
4939 -- If a constraint is present, analyze the bounds to catch
4940 -- premature usage of the derived literals.
4942 if Nkind (Indic) = N_Subtype_Indication
4943 and then Nkind (Range_Expression (Constraint (Indic))) = N_Range
4945 Analyze (Low_Bound (Range_Expression (Constraint (Indic))));
4946 Analyze (High_Bound (Range_Expression (Constraint (Indic))));
4949 -- Introduce an implicit base type for the derived type even if there
4950 -- is no constraint attached to it, since this seems closer to the
4951 -- Ada semantics. Build a full type declaration tree for the derived
4952 -- type using the implicit base type as the defining identifier. The
4953 -- build a subtype declaration tree which applies the constraint (if
4954 -- any) have it replace the derived type declaration.
4956 Literal := First_Literal (Parent_Type);
4957 Literals_List := New_List;
4958 while Present (Literal)
4959 and then Ekind (Literal) = E_Enumeration_Literal
4961 -- Literals of the derived type have the same representation as
4962 -- those of the parent type, but this representation can be
4963 -- overridden by an explicit representation clause. Indicate
4964 -- that there is no explicit representation given yet. These
4965 -- derived literals are implicit operations of the new type,
4966 -- and can be overridden by explicit ones.
4968 if Nkind (Literal) = N_Defining_Character_Literal then
4970 Make_Defining_Character_Literal (Loc, Chars (Literal));
4972 New_Lit := Make_Defining_Identifier (Loc, Chars (Literal));
4975 Set_Ekind (New_Lit, E_Enumeration_Literal);
4976 Set_Enumeration_Pos (New_Lit, Enumeration_Pos (Literal));
4977 Set_Enumeration_Rep (New_Lit, Enumeration_Rep (Literal));
4978 Set_Enumeration_Rep_Expr (New_Lit, Empty);
4979 Set_Alias (New_Lit, Literal);
4980 Set_Is_Known_Valid (New_Lit, True);
4982 Append (New_Lit, Literals_List);
4983 Next_Literal (Literal);
4987 Make_Defining_Identifier (Sloc (Derived_Type),
4988 New_External_Name (Chars (Derived_Type), 'B'));
4990 -- Indicate the proper nature of the derived type. This must be done
4991 -- before analysis of the literals, to recognize cases when a literal
4992 -- may be hidden by a previous explicit function definition (cf.
4995 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
4996 Set_Etype (Derived_Type, Implicit_Base);
4999 Make_Full_Type_Declaration (Loc,
5000 Defining_Identifier => Implicit_Base,
5001 Discriminant_Specifications => No_List,
5003 Make_Enumeration_Type_Definition (Loc, Literals_List));
5005 Mark_Rewrite_Insertion (Type_Decl);
5006 Insert_Before (N, Type_Decl);
5007 Analyze (Type_Decl);
5009 -- After the implicit base is analyzed its Etype needs to be changed
5010 -- to reflect the fact that it is derived from the parent type which
5011 -- was ignored during analysis. We also set the size at this point.
5013 Set_Etype (Implicit_Base, Parent_Type);
5015 Set_Size_Info (Implicit_Base, Parent_Type);
5016 Set_RM_Size (Implicit_Base, RM_Size (Parent_Type));
5017 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Type));
5019 Set_Has_Non_Standard_Rep
5020 (Implicit_Base, Has_Non_Standard_Rep
5022 Set_Has_Delayed_Freeze (Implicit_Base);
5024 -- Process the subtype indication including a validation check on the
5025 -- constraint, if any. If a constraint is given, its bounds must be
5026 -- implicitly converted to the new type.
5028 if Nkind (Indic) = N_Subtype_Indication then
5030 R : constant Node_Id :=
5031 Range_Expression (Constraint (Indic));
5034 if Nkind (R) = N_Range then
5035 Hi := Build_Scalar_Bound
5036 (High_Bound (R), Parent_Type, Implicit_Base);
5037 Lo := Build_Scalar_Bound
5038 (Low_Bound (R), Parent_Type, Implicit_Base);
5041 -- Constraint is a Range attribute. Replace with explicit
5042 -- mention of the bounds of the prefix, which must be a
5045 Analyze (Prefix (R));
5047 Convert_To (Implicit_Base,
5048 Make_Attribute_Reference (Loc,
5049 Attribute_Name => Name_Last,
5051 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5054 Convert_To (Implicit_Base,
5055 Make_Attribute_Reference (Loc,
5056 Attribute_Name => Name_First,
5058 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5065 (Type_High_Bound (Parent_Type),
5066 Parent_Type, Implicit_Base);
5069 (Type_Low_Bound (Parent_Type),
5070 Parent_Type, Implicit_Base);
5078 -- If we constructed a default range for the case where no range
5079 -- was given, then the expressions in the range must not freeze
5080 -- since they do not correspond to expressions in the source.
5082 if Nkind (Indic) /= N_Subtype_Indication then
5083 Set_Must_Not_Freeze (Lo);
5084 Set_Must_Not_Freeze (Hi);
5085 Set_Must_Not_Freeze (Rang_Expr);
5089 Make_Subtype_Declaration (Loc,
5090 Defining_Identifier => Derived_Type,
5091 Subtype_Indication =>
5092 Make_Subtype_Indication (Loc,
5093 Subtype_Mark => New_Occurrence_Of (Implicit_Base, Loc),
5095 Make_Range_Constraint (Loc,
5096 Range_Expression => Rang_Expr))));
5100 -- If pragma Discard_Names applies on the first subtype of the parent
5101 -- type, then it must be applied on this subtype as well.
5103 if Einfo.Discard_Names (First_Subtype (Parent_Type)) then
5104 Set_Discard_Names (Derived_Type);
5107 -- Apply a range check. Since this range expression doesn't have an
5108 -- Etype, we have to specifically pass the Source_Typ parameter. Is
5111 if Nkind (Indic) = N_Subtype_Indication then
5112 Apply_Range_Check (Range_Expression (Constraint (Indic)),
5114 Source_Typ => Entity (Subtype_Mark (Indic)));
5117 end Build_Derived_Enumeration_Type;
5119 --------------------------------
5120 -- Build_Derived_Numeric_Type --
5121 --------------------------------
5123 procedure Build_Derived_Numeric_Type
5125 Parent_Type : Entity_Id;
5126 Derived_Type : Entity_Id)
5128 Loc : constant Source_Ptr := Sloc (N);
5129 Tdef : constant Node_Id := Type_Definition (N);
5130 Indic : constant Node_Id := Subtype_Indication (Tdef);
5131 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
5132 No_Constraint : constant Boolean := Nkind (Indic) /=
5133 N_Subtype_Indication;
5134 Implicit_Base : Entity_Id;
5140 -- Process the subtype indication including a validation check on
5141 -- the constraint if any.
5143 Discard_Node (Process_Subtype (Indic, N));
5145 -- Introduce an implicit base type for the derived type even if there
5146 -- is no constraint attached to it, since this seems closer to the Ada
5150 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
5152 Set_Etype (Implicit_Base, Parent_Base);
5153 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
5154 Set_Size_Info (Implicit_Base, Parent_Base);
5155 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Base));
5156 Set_Parent (Implicit_Base, Parent (Derived_Type));
5158 -- Set RM Size for discrete type or decimal fixed-point type
5159 -- Ordinary fixed-point is excluded, why???
5161 if Is_Discrete_Type (Parent_Base)
5162 or else Is_Decimal_Fixed_Point_Type (Parent_Base)
5164 Set_RM_Size (Implicit_Base, RM_Size (Parent_Base));
5167 Set_Has_Delayed_Freeze (Implicit_Base);
5169 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
5170 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
5172 Set_Scalar_Range (Implicit_Base,
5177 if Has_Infinities (Parent_Base) then
5178 Set_Includes_Infinities (Scalar_Range (Implicit_Base));
5181 -- The Derived_Type, which is the entity of the declaration, is a
5182 -- subtype of the implicit base. Its Ekind is a subtype, even in the
5183 -- absence of an explicit constraint.
5185 Set_Etype (Derived_Type, Implicit_Base);
5187 -- If we did not have a constraint, then the Ekind is set from the
5188 -- parent type (otherwise Process_Subtype has set the bounds)
5190 if No_Constraint then
5191 Set_Ekind (Derived_Type, Subtype_Kind (Ekind (Parent_Type)));
5194 -- If we did not have a range constraint, then set the range from the
5195 -- parent type. Otherwise, the call to Process_Subtype has set the
5199 or else not Has_Range_Constraint (Indic)
5201 Set_Scalar_Range (Derived_Type,
5203 Low_Bound => New_Copy_Tree (Type_Low_Bound (Parent_Type)),
5204 High_Bound => New_Copy_Tree (Type_High_Bound (Parent_Type))));
5205 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5207 if Has_Infinities (Parent_Type) then
5208 Set_Includes_Infinities (Scalar_Range (Derived_Type));
5212 Set_Is_Descendent_Of_Address (Derived_Type,
5213 Is_Descendent_Of_Address (Parent_Type));
5214 Set_Is_Descendent_Of_Address (Implicit_Base,
5215 Is_Descendent_Of_Address (Parent_Type));
5217 -- Set remaining type-specific fields, depending on numeric type
5219 if Is_Modular_Integer_Type (Parent_Type) then
5220 Set_Modulus (Implicit_Base, Modulus (Parent_Base));
5222 Set_Non_Binary_Modulus
5223 (Implicit_Base, Non_Binary_Modulus (Parent_Base));
5225 elsif Is_Floating_Point_Type (Parent_Type) then
5227 -- Digits of base type is always copied from the digits value of
5228 -- the parent base type, but the digits of the derived type will
5229 -- already have been set if there was a constraint present.
5231 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5232 Set_Vax_Float (Implicit_Base, Vax_Float (Parent_Base));
5234 if No_Constraint then
5235 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Type));
5238 elsif Is_Fixed_Point_Type (Parent_Type) then
5240 -- Small of base type and derived type are always copied from the
5241 -- parent base type, since smalls never change. The delta of the
5242 -- base type is also copied from the parent base type. However the
5243 -- delta of the derived type will have been set already if a
5244 -- constraint was present.
5246 Set_Small_Value (Derived_Type, Small_Value (Parent_Base));
5247 Set_Small_Value (Implicit_Base, Small_Value (Parent_Base));
5248 Set_Delta_Value (Implicit_Base, Delta_Value (Parent_Base));
5250 if No_Constraint then
5251 Set_Delta_Value (Derived_Type, Delta_Value (Parent_Type));
5254 -- The scale and machine radix in the decimal case are always
5255 -- copied from the parent base type.
5257 if Is_Decimal_Fixed_Point_Type (Parent_Type) then
5258 Set_Scale_Value (Derived_Type, Scale_Value (Parent_Base));
5259 Set_Scale_Value (Implicit_Base, Scale_Value (Parent_Base));
5261 Set_Machine_Radix_10
5262 (Derived_Type, Machine_Radix_10 (Parent_Base));
5263 Set_Machine_Radix_10
5264 (Implicit_Base, Machine_Radix_10 (Parent_Base));
5266 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5268 if No_Constraint then
5269 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Base));
5272 -- the analysis of the subtype_indication sets the
5273 -- digits value of the derived type.
5280 -- The type of the bounds is that of the parent type, and they
5281 -- must be converted to the derived type.
5283 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
5285 -- The implicit_base should be frozen when the derived type is frozen,
5286 -- but note that it is used in the conversions of the bounds. For fixed
5287 -- types we delay the determination of the bounds until the proper
5288 -- freezing point. For other numeric types this is rejected by GCC, for
5289 -- reasons that are currently unclear (???), so we choose to freeze the
5290 -- implicit base now. In the case of integers and floating point types
5291 -- this is harmless because subsequent representation clauses cannot
5292 -- affect anything, but it is still baffling that we cannot use the
5293 -- same mechanism for all derived numeric types.
5295 -- There is a further complication: actually *some* representation
5296 -- clauses can affect the implicit base type. Namely, attribute
5297 -- definition clauses for stream-oriented attributes need to set the
5298 -- corresponding TSS entries on the base type, and this normally cannot
5299 -- be done after the base type is frozen, so the circuitry in
5300 -- Sem_Ch13.New_Stream_Subprogram must account for this possibility and
5301 -- not use Set_TSS in this case.
5303 if Is_Fixed_Point_Type (Parent_Type) then
5304 Conditional_Delay (Implicit_Base, Parent_Type);
5306 Freeze_Before (N, Implicit_Base);
5308 end Build_Derived_Numeric_Type;
5310 --------------------------------
5311 -- Build_Derived_Private_Type --
5312 --------------------------------
5314 procedure Build_Derived_Private_Type
5316 Parent_Type : Entity_Id;
5317 Derived_Type : Entity_Id;
5318 Is_Completion : Boolean;
5319 Derive_Subps : Boolean := True)
5321 Der_Base : Entity_Id;
5323 Full_Decl : Node_Id := Empty;
5324 Full_Der : Entity_Id;
5326 Last_Discr : Entity_Id;
5327 Par_Scope : constant Entity_Id := Scope (Base_Type (Parent_Type));
5328 Swapped : Boolean := False;
5330 procedure Copy_And_Build;
5331 -- Copy derived type declaration, replace parent with its full view,
5332 -- and analyze new declaration.
5334 --------------------
5335 -- Copy_And_Build --
5336 --------------------
5338 procedure Copy_And_Build is
5342 if Ekind (Parent_Type) in Record_Kind
5344 (Ekind (Parent_Type) in Enumeration_Kind
5345 and then not Is_Standard_Character_Type (Parent_Type)
5346 and then not Is_Generic_Type (Root_Type (Parent_Type)))
5348 Full_N := New_Copy_Tree (N);
5349 Insert_After (N, Full_N);
5350 Build_Derived_Type (
5351 Full_N, Parent_Type, Full_Der, True, Derive_Subps => False);
5354 Build_Derived_Type (
5355 N, Parent_Type, Full_Der, True, Derive_Subps => False);
5359 -- Start of processing for Build_Derived_Private_Type
5362 if Is_Tagged_Type (Parent_Type) then
5363 Build_Derived_Record_Type
5364 (N, Parent_Type, Derived_Type, Derive_Subps);
5367 elsif Has_Discriminants (Parent_Type) then
5368 if Present (Full_View (Parent_Type)) then
5369 if not Is_Completion then
5371 -- Copy declaration for subsequent analysis, to provide a
5372 -- completion for what is a private declaration. Indicate that
5373 -- the full type is internally generated.
5375 Full_Decl := New_Copy_Tree (N);
5376 Full_Der := New_Copy (Derived_Type);
5377 Set_Comes_From_Source (Full_Decl, False);
5378 Set_Comes_From_Source (Full_Der, False);
5380 Insert_After (N, Full_Decl);
5383 -- If this is a completion, the full view being built is
5384 -- itself private. We build a subtype of the parent with
5385 -- the same constraints as this full view, to convey to the
5386 -- back end the constrained components and the size of this
5387 -- subtype. If the parent is constrained, its full view can
5388 -- serve as the underlying full view of the derived type.
5390 if No (Discriminant_Specifications (N)) then
5391 if Nkind (Subtype_Indication (Type_Definition (N))) =
5392 N_Subtype_Indication
5394 Build_Underlying_Full_View (N, Derived_Type, Parent_Type);
5396 elsif Is_Constrained (Full_View (Parent_Type)) then
5397 Set_Underlying_Full_View (Derived_Type,
5398 Full_View (Parent_Type));
5402 -- If there are new discriminants, the parent subtype is
5403 -- constrained by them, but it is not clear how to build
5404 -- the underlying_full_view in this case ???
5411 -- Build partial view of derived type from partial view of parent
5413 Build_Derived_Record_Type
5414 (N, Parent_Type, Derived_Type, Derive_Subps);
5416 if Present (Full_View (Parent_Type))
5417 and then not Is_Completion
5419 if not In_Open_Scopes (Par_Scope)
5420 or else not In_Same_Source_Unit (N, Parent_Type)
5422 -- Swap partial and full views temporarily
5424 Install_Private_Declarations (Par_Scope);
5425 Install_Visible_Declarations (Par_Scope);
5429 -- Build full view of derived type from full view of parent which
5430 -- is now installed. Subprograms have been derived on the partial
5431 -- view, the completion does not derive them anew.
5433 if not Is_Tagged_Type (Parent_Type) then
5435 -- If the parent is itself derived from another private type,
5436 -- installing the private declarations has not affected its
5437 -- privacy status, so use its own full view explicitly.
5439 if Is_Private_Type (Parent_Type) then
5440 Build_Derived_Record_Type
5441 (Full_Decl, Full_View (Parent_Type), Full_Der, False);
5443 Build_Derived_Record_Type
5444 (Full_Decl, Parent_Type, Full_Der, False);
5448 -- If full view of parent is tagged, the completion
5449 -- inherits the proper primitive operations.
5451 Set_Defining_Identifier (Full_Decl, Full_Der);
5452 Build_Derived_Record_Type
5453 (Full_Decl, Parent_Type, Full_Der, Derive_Subps);
5454 Set_Analyzed (Full_Decl);
5458 Uninstall_Declarations (Par_Scope);
5460 if In_Open_Scopes (Par_Scope) then
5461 Install_Visible_Declarations (Par_Scope);
5465 Der_Base := Base_Type (Derived_Type);
5466 Set_Full_View (Derived_Type, Full_Der);
5467 Set_Full_View (Der_Base, Base_Type (Full_Der));
5469 -- Copy the discriminant list from full view to the partial views
5470 -- (base type and its subtype). Gigi requires that the partial
5471 -- and full views have the same discriminants.
5473 -- Note that since the partial view is pointing to discriminants
5474 -- in the full view, their scope will be that of the full view.
5475 -- This might cause some front end problems and need
5478 Discr := First_Discriminant (Base_Type (Full_Der));
5479 Set_First_Entity (Der_Base, Discr);
5482 Last_Discr := Discr;
5483 Next_Discriminant (Discr);
5484 exit when No (Discr);
5487 Set_Last_Entity (Der_Base, Last_Discr);
5489 Set_First_Entity (Derived_Type, First_Entity (Der_Base));
5490 Set_Last_Entity (Derived_Type, Last_Entity (Der_Base));
5491 Set_Stored_Constraint (Full_Der, Stored_Constraint (Derived_Type));
5494 -- If this is a completion, the derived type stays private
5495 -- and there is no need to create a further full view, except
5496 -- in the unusual case when the derivation is nested within a
5497 -- child unit, see below.
5502 elsif Present (Full_View (Parent_Type))
5503 and then Has_Discriminants (Full_View (Parent_Type))
5505 if Has_Unknown_Discriminants (Parent_Type)
5506 and then Nkind (Subtype_Indication (Type_Definition (N))) =
5507 N_Subtype_Indication
5510 ("cannot constrain type with unknown discriminants",
5511 Subtype_Indication (Type_Definition (N)));
5515 -- If full view of parent is a record type, Build full view as
5516 -- a derivation from the parent's full view. Partial view remains
5517 -- private. For code generation and linking, the full view must
5518 -- have the same public status as the partial one. This full view
5519 -- is only needed if the parent type is in an enclosing scope, so
5520 -- that the full view may actually become visible, e.g. in a child
5521 -- unit. This is both more efficient, and avoids order of freezing
5522 -- problems with the added entities.
5524 if not Is_Private_Type (Full_View (Parent_Type))
5525 and then (In_Open_Scopes (Scope (Parent_Type)))
5527 Full_Der := Make_Defining_Identifier (Sloc (Derived_Type),
5528 Chars (Derived_Type));
5529 Set_Is_Itype (Full_Der);
5530 Set_Has_Private_Declaration (Full_Der);
5531 Set_Has_Private_Declaration (Derived_Type);
5532 Set_Associated_Node_For_Itype (Full_Der, N);
5533 Set_Parent (Full_Der, Parent (Derived_Type));
5534 Set_Full_View (Derived_Type, Full_Der);
5535 Set_Is_Public (Full_Der, Is_Public (Derived_Type));
5536 Full_P := Full_View (Parent_Type);
5537 Exchange_Declarations (Parent_Type);
5539 Exchange_Declarations (Full_P);
5542 Build_Derived_Record_Type
5543 (N, Full_View (Parent_Type), Derived_Type,
5544 Derive_Subps => False);
5547 -- In any case, the primitive operations are inherited from
5548 -- the parent type, not from the internal full view.
5550 Set_Etype (Base_Type (Derived_Type), Base_Type (Parent_Type));
5552 if Derive_Subps then
5553 Derive_Subprograms (Parent_Type, Derived_Type);
5557 -- Untagged type, No discriminants on either view
5559 if Nkind (Subtype_Indication (Type_Definition (N))) =
5560 N_Subtype_Indication
5563 ("illegal constraint on type without discriminants", N);
5566 if Present (Discriminant_Specifications (N))
5567 and then Present (Full_View (Parent_Type))
5568 and then not Is_Tagged_Type (Full_View (Parent_Type))
5571 ("cannot add discriminants to untagged type", N);
5574 Set_Stored_Constraint (Derived_Type, No_Elist);
5575 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5576 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
5577 Set_Has_Controlled_Component
5578 (Derived_Type, Has_Controlled_Component
5581 -- Direct controlled types do not inherit Finalize_Storage_Only flag
5583 if not Is_Controlled (Parent_Type) then
5584 Set_Finalize_Storage_Only
5585 (Base_Type (Derived_Type), Finalize_Storage_Only (Parent_Type));
5588 -- Construct the implicit full view by deriving from full view of
5589 -- the parent type. In order to get proper visibility, we install
5590 -- the parent scope and its declarations.
5592 -- ??? if the parent is untagged private and its completion is
5593 -- tagged, this mechanism will not work because we cannot derive
5594 -- from the tagged full view unless we have an extension
5596 if Present (Full_View (Parent_Type))
5597 and then not Is_Tagged_Type (Full_View (Parent_Type))
5598 and then not Is_Completion
5601 Make_Defining_Identifier (Sloc (Derived_Type),
5602 Chars => Chars (Derived_Type));
5603 Set_Is_Itype (Full_Der);
5604 Set_Has_Private_Declaration (Full_Der);
5605 Set_Has_Private_Declaration (Derived_Type);
5606 Set_Associated_Node_For_Itype (Full_Der, N);
5607 Set_Parent (Full_Der, Parent (Derived_Type));
5608 Set_Full_View (Derived_Type, Full_Der);
5610 if not In_Open_Scopes (Par_Scope) then
5611 Install_Private_Declarations (Par_Scope);
5612 Install_Visible_Declarations (Par_Scope);
5614 Uninstall_Declarations (Par_Scope);
5616 -- If parent scope is open and in another unit, and parent has a
5617 -- completion, then the derivation is taking place in the visible
5618 -- part of a child unit. In that case retrieve the full view of
5619 -- the parent momentarily.
5621 elsif not In_Same_Source_Unit (N, Parent_Type) then
5622 Full_P := Full_View (Parent_Type);
5623 Exchange_Declarations (Parent_Type);
5625 Exchange_Declarations (Full_P);
5627 -- Otherwise it is a local derivation
5633 Set_Scope (Full_Der, Current_Scope);
5634 Set_Is_First_Subtype (Full_Der,
5635 Is_First_Subtype (Derived_Type));
5636 Set_Has_Size_Clause (Full_Der, False);
5637 Set_Has_Alignment_Clause (Full_Der, False);
5638 Set_Next_Entity (Full_Der, Empty);
5639 Set_Has_Delayed_Freeze (Full_Der);
5640 Set_Is_Frozen (Full_Der, False);
5641 Set_Freeze_Node (Full_Der, Empty);
5642 Set_Depends_On_Private (Full_Der,
5643 Has_Private_Component (Full_Der));
5644 Set_Public_Status (Full_Der);
5648 Set_Has_Unknown_Discriminants (Derived_Type,
5649 Has_Unknown_Discriminants (Parent_Type));
5651 if Is_Private_Type (Derived_Type) then
5652 Set_Private_Dependents (Derived_Type, New_Elmt_List);
5655 if Is_Private_Type (Parent_Type)
5656 and then Base_Type (Parent_Type) = Parent_Type
5657 and then In_Open_Scopes (Scope (Parent_Type))
5659 Append_Elmt (Derived_Type, Private_Dependents (Parent_Type));
5661 if Is_Child_Unit (Scope (Current_Scope))
5662 and then Is_Completion
5663 and then In_Private_Part (Current_Scope)
5664 and then Scope (Parent_Type) /= Current_Scope
5666 -- This is the unusual case where a type completed by a private
5667 -- derivation occurs within a package nested in a child unit,
5668 -- and the parent is declared in an ancestor. In this case, the
5669 -- full view of the parent type will become visible in the body
5670 -- of the enclosing child, and only then will the current type
5671 -- be possibly non-private. We build a underlying full view that
5672 -- will be installed when the enclosing child body is compiled.
5675 Make_Defining_Identifier (Sloc (Derived_Type),
5676 Chars => Chars (Derived_Type));
5677 Set_Is_Itype (Full_Der);
5678 Build_Itype_Reference (Full_Der, N);
5680 -- The full view will be used to swap entities on entry/exit to
5681 -- the body, and must appear in the entity list for the package.
5683 Append_Entity (Full_Der, Scope (Derived_Type));
5684 Set_Has_Private_Declaration (Full_Der);
5685 Set_Has_Private_Declaration (Derived_Type);
5686 Set_Associated_Node_For_Itype (Full_Der, N);
5687 Set_Parent (Full_Der, Parent (Derived_Type));
5688 Full_P := Full_View (Parent_Type);
5689 Exchange_Declarations (Parent_Type);
5691 Exchange_Declarations (Full_P);
5692 Set_Underlying_Full_View (Derived_Type, Full_Der);
5695 end Build_Derived_Private_Type;
5697 -------------------------------
5698 -- Build_Derived_Record_Type --
5699 -------------------------------
5703 -- Ideally we would like to use the same model of type derivation for
5704 -- tagged and untagged record types. Unfortunately this is not quite
5705 -- possible because the semantics of representation clauses is different
5706 -- for tagged and untagged records under inheritance. Consider the
5709 -- type R (...) is [tagged] record ... end record;
5710 -- type T (...) is new R (...) [with ...];
5712 -- The representation clauses for T can specify a completely different
5713 -- record layout from R's. Hence the same component can be placed in two
5714 -- very different positions in objects of type T and R. If R and are tagged
5715 -- types, representation clauses for T can only specify the layout of non
5716 -- inherited components, thus components that are common in R and T have
5717 -- the same position in objects of type R and T.
5719 -- This has two implications. The first is that the entire tree for R's
5720 -- declaration needs to be copied for T in the untagged case, so that T
5721 -- can be viewed as a record type of its own with its own representation
5722 -- clauses. The second implication is the way we handle discriminants.
5723 -- Specifically, in the untagged case we need a way to communicate to Gigi
5724 -- what are the real discriminants in the record, while for the semantics
5725 -- we need to consider those introduced by the user to rename the
5726 -- discriminants in the parent type. This is handled by introducing the
5727 -- notion of stored discriminants. See below for more.
5729 -- Fortunately the way regular components are inherited can be handled in
5730 -- the same way in tagged and untagged types.
5732 -- To complicate things a bit more the private view of a private extension
5733 -- cannot be handled in the same way as the full view (for one thing the
5734 -- semantic rules are somewhat different). We will explain what differs
5737 -- 2. DISCRIMINANTS UNDER INHERITANCE
5739 -- The semantic rules governing the discriminants of derived types are
5742 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
5743 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
5745 -- If parent type has discriminants, then the discriminants that are
5746 -- declared in the derived type are [3.4 (11)]:
5748 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
5751 -- o Otherwise, each discriminant of the parent type (implicitly declared
5752 -- in the same order with the same specifications). In this case, the
5753 -- discriminants are said to be "inherited", or if unknown in the parent
5754 -- are also unknown in the derived type.
5756 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
5758 -- o The parent subtype shall be constrained;
5760 -- o If the parent type is not a tagged type, then each discriminant of
5761 -- the derived type shall be used in the constraint defining a parent
5762 -- subtype. [Implementation note: This ensures that the new discriminant
5763 -- can share storage with an existing discriminant.]
5765 -- For the derived type each discriminant of the parent type is either
5766 -- inherited, constrained to equal some new discriminant of the derived
5767 -- type, or constrained to the value of an expression.
5769 -- When inherited or constrained to equal some new discriminant, the
5770 -- parent discriminant and the discriminant of the derived type are said
5773 -- If a discriminant of the parent type is constrained to a specific value
5774 -- in the derived type definition, then the discriminant is said to be
5775 -- "specified" by that derived type definition.
5777 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
5779 -- We have spoken about stored discriminants in point 1 (introduction)
5780 -- above. There are two sort of stored discriminants: implicit and
5781 -- explicit. As long as the derived type inherits the same discriminants as
5782 -- the root record type, stored discriminants are the same as regular
5783 -- discriminants, and are said to be implicit. However, if any discriminant
5784 -- in the root type was renamed in the derived type, then the derived
5785 -- type will contain explicit stored discriminants. Explicit stored
5786 -- discriminants are discriminants in addition to the semantically visible
5787 -- discriminants defined for the derived type. Stored discriminants are
5788 -- used by Gigi to figure out what are the physical discriminants in
5789 -- objects of the derived type (see precise definition in einfo.ads).
5790 -- As an example, consider the following:
5792 -- type R (D1, D2, D3 : Int) is record ... end record;
5793 -- type T1 is new R;
5794 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
5795 -- type T3 is new T2;
5796 -- type T4 (Y : Int) is new T3 (Y, 99);
5798 -- The following table summarizes the discriminants and stored
5799 -- discriminants in R and T1 through T4.
5801 -- Type Discrim Stored Discrim Comment
5802 -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
5803 -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
5804 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
5805 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
5806 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
5808 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
5809 -- find the corresponding discriminant in the parent type, while
5810 -- Original_Record_Component (abbreviated ORC below), the actual physical
5811 -- component that is renamed. Finally the field Is_Completely_Hidden
5812 -- (abbreviated ICH below) is set for all explicit stored discriminants
5813 -- (see einfo.ads for more info). For the above example this gives:
5815 -- Discrim CD ORC ICH
5816 -- ^^^^^^^ ^^ ^^^ ^^^
5817 -- D1 in R empty itself no
5818 -- D2 in R empty itself no
5819 -- D3 in R empty itself no
5821 -- D1 in T1 D1 in R itself no
5822 -- D2 in T1 D2 in R itself no
5823 -- D3 in T1 D3 in R itself no
5825 -- X1 in T2 D3 in T1 D3 in T2 no
5826 -- X2 in T2 D1 in T1 D1 in T2 no
5827 -- D1 in T2 empty itself yes
5828 -- D2 in T2 empty itself yes
5829 -- D3 in T2 empty itself yes
5831 -- X1 in T3 X1 in T2 D3 in T3 no
5832 -- X2 in T3 X2 in T2 D1 in T3 no
5833 -- D1 in T3 empty itself yes
5834 -- D2 in T3 empty itself yes
5835 -- D3 in T3 empty itself yes
5837 -- Y in T4 X1 in T3 D3 in T3 no
5838 -- D1 in T3 empty itself yes
5839 -- D2 in T3 empty itself yes
5840 -- D3 in T3 empty itself yes
5842 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
5844 -- Type derivation for tagged types is fairly straightforward. If no
5845 -- discriminants are specified by the derived type, these are inherited
5846 -- from the parent. No explicit stored discriminants are ever necessary.
5847 -- The only manipulation that is done to the tree is that of adding a
5848 -- _parent field with parent type and constrained to the same constraint
5849 -- specified for the parent in the derived type definition. For instance:
5851 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
5852 -- type T1 is new R with null record;
5853 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
5855 -- are changed into:
5857 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
5858 -- _parent : R (D1, D2, D3);
5861 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
5862 -- _parent : T1 (X2, 88, X1);
5865 -- The discriminants actually present in R, T1 and T2 as well as their CD,
5866 -- ORC and ICH fields are:
5868 -- Discrim CD ORC ICH
5869 -- ^^^^^^^ ^^ ^^^ ^^^
5870 -- D1 in R empty itself no
5871 -- D2 in R empty itself no
5872 -- D3 in R empty itself no
5874 -- D1 in T1 D1 in R D1 in R no
5875 -- D2 in T1 D2 in R D2 in R no
5876 -- D3 in T1 D3 in R D3 in R no
5878 -- X1 in T2 D3 in T1 D3 in R no
5879 -- X2 in T2 D1 in T1 D1 in R no
5881 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
5883 -- Regardless of whether we dealing with a tagged or untagged type
5884 -- we will transform all derived type declarations of the form
5886 -- type T is new R (...) [with ...];
5888 -- subtype S is R (...);
5889 -- type T is new S [with ...];
5891 -- type BT is new R [with ...];
5892 -- subtype T is BT (...);
5894 -- That is, the base derived type is constrained only if it has no
5895 -- discriminants. The reason for doing this is that GNAT's semantic model
5896 -- assumes that a base type with discriminants is unconstrained.
5898 -- Note that, strictly speaking, the above transformation is not always
5899 -- correct. Consider for instance the following excerpt from ACVC b34011a:
5901 -- procedure B34011A is
5902 -- type REC (D : integer := 0) is record
5907 -- type T6 is new Rec;
5908 -- function F return T6;
5913 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
5916 -- The definition of Q6.U is illegal. However transforming Q6.U into
5918 -- type BaseU is new T6;
5919 -- subtype U is BaseU (Q6.F.I)
5921 -- turns U into a legal subtype, which is incorrect. To avoid this problem
5922 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
5923 -- the transformation described above.
5925 -- There is another instance where the above transformation is incorrect.
5929 -- type Base (D : Integer) is tagged null record;
5930 -- procedure P (X : Base);
5932 -- type Der is new Base (2) with null record;
5933 -- procedure P (X : Der);
5936 -- Then the above transformation turns this into
5938 -- type Der_Base is new Base with null record;
5939 -- -- procedure P (X : Base) is implicitly inherited here
5940 -- -- as procedure P (X : Der_Base).
5942 -- subtype Der is Der_Base (2);
5943 -- procedure P (X : Der);
5944 -- -- The overriding of P (X : Der_Base) is illegal since we
5945 -- -- have a parameter conformance problem.
5947 -- To get around this problem, after having semantically processed Der_Base
5948 -- and the rewritten subtype declaration for Der, we copy Der_Base field
5949 -- Discriminant_Constraint from Der so that when parameter conformance is
5950 -- checked when P is overridden, no semantic errors are flagged.
5952 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
5954 -- Regardless of whether we are dealing with a tagged or untagged type
5955 -- we will transform all derived type declarations of the form
5957 -- type R (D1, .., Dn : ...) is [tagged] record ...;
5958 -- type T is new R [with ...];
5960 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
5962 -- The reason for such transformation is that it allows us to implement a
5963 -- very clean form of component inheritance as explained below.
5965 -- Note that this transformation is not achieved by direct tree rewriting
5966 -- and manipulation, but rather by redoing the semantic actions that the
5967 -- above transformation will entail. This is done directly in routine
5968 -- Inherit_Components.
5970 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
5972 -- In both tagged and untagged derived types, regular non discriminant
5973 -- components are inherited in the derived type from the parent type. In
5974 -- the absence of discriminants component, inheritance is straightforward
5975 -- as components can simply be copied from the parent.
5977 -- If the parent has discriminants, inheriting components constrained with
5978 -- these discriminants requires caution. Consider the following example:
5980 -- type R (D1, D2 : Positive) is [tagged] record
5981 -- S : String (D1 .. D2);
5984 -- type T1 is new R [with null record];
5985 -- type T2 (X : positive) is new R (1, X) [with null record];
5987 -- As explained in 6. above, T1 is rewritten as
5988 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
5989 -- which makes the treatment for T1 and T2 identical.
5991 -- What we want when inheriting S, is that references to D1 and D2 in R are
5992 -- replaced with references to their correct constraints, i.e. D1 and D2 in
5993 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
5994 -- with either discriminant references in the derived type or expressions.
5995 -- This replacement is achieved as follows: before inheriting R's
5996 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
5997 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
5998 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
5999 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
6000 -- by String (1 .. X).
6002 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
6004 -- We explain here the rules governing private type extensions relevant to
6005 -- type derivation. These rules are explained on the following example:
6007 -- type D [(...)] is new A [(...)] with private; <-- partial view
6008 -- type D [(...)] is new P [(...)] with null record; <-- full view
6010 -- Type A is called the ancestor subtype of the private extension.
6011 -- Type P is the parent type of the full view of the private extension. It
6012 -- must be A or a type derived from A.
6014 -- The rules concerning the discriminants of private type extensions are
6017 -- o If a private extension inherits known discriminants from the ancestor
6018 -- subtype, then the full view shall also inherit its discriminants from
6019 -- the ancestor subtype and the parent subtype of the full view shall be
6020 -- constrained if and only if the ancestor subtype is constrained.
6022 -- o If a partial view has unknown discriminants, then the full view may
6023 -- define a definite or an indefinite subtype, with or without
6026 -- o If a partial view has neither known nor unknown discriminants, then
6027 -- the full view shall define a definite subtype.
6029 -- o If the ancestor subtype of a private extension has constrained
6030 -- discriminants, then the parent subtype of the full view shall impose a
6031 -- statically matching constraint on those discriminants.
6033 -- This means that only the following forms of private extensions are
6036 -- type D is new A with private; <-- partial view
6037 -- type D is new P with null record; <-- full view
6039 -- If A has no discriminants than P has no discriminants, otherwise P must
6040 -- inherit A's discriminants.
6042 -- type D is new A (...) with private; <-- partial view
6043 -- type D is new P (:::) with null record; <-- full view
6045 -- P must inherit A's discriminants and (...) and (:::) must statically
6048 -- subtype A is R (...);
6049 -- type D is new A with private; <-- partial view
6050 -- type D is new P with null record; <-- full view
6052 -- P must have inherited R's discriminants and must be derived from A or
6053 -- any of its subtypes.
6055 -- type D (..) is new A with private; <-- partial view
6056 -- type D (..) is new P [(:::)] with null record; <-- full view
6058 -- No specific constraints on P's discriminants or constraint (:::).
6059 -- Note that A can be unconstrained, but the parent subtype P must either
6060 -- be constrained or (:::) must be present.
6062 -- type D (..) is new A [(...)] with private; <-- partial view
6063 -- type D (..) is new P [(:::)] with null record; <-- full view
6065 -- P's constraints on A's discriminants must statically match those
6066 -- imposed by (...).
6068 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
6070 -- The full view of a private extension is handled exactly as described
6071 -- above. The model chose for the private view of a private extension is
6072 -- the same for what concerns discriminants (i.e. they receive the same
6073 -- treatment as in the tagged case). However, the private view of the
6074 -- private extension always inherits the components of the parent base,
6075 -- without replacing any discriminant reference. Strictly speaking this is
6076 -- incorrect. However, Gigi never uses this view to generate code so this
6077 -- is a purely semantic issue. In theory, a set of transformations similar
6078 -- to those given in 5. and 6. above could be applied to private views of
6079 -- private extensions to have the same model of component inheritance as
6080 -- for non private extensions. However, this is not done because it would
6081 -- further complicate private type processing. Semantically speaking, this
6082 -- leaves us in an uncomfortable situation. As an example consider:
6085 -- type R (D : integer) is tagged record
6086 -- S : String (1 .. D);
6088 -- procedure P (X : R);
6089 -- type T is new R (1) with private;
6091 -- type T is new R (1) with null record;
6094 -- This is transformed into:
6097 -- type R (D : integer) is tagged record
6098 -- S : String (1 .. D);
6100 -- procedure P (X : R);
6101 -- type T is new R (1) with private;
6103 -- type BaseT is new R with null record;
6104 -- subtype T is BaseT (1);
6107 -- (strictly speaking the above is incorrect Ada)
6109 -- From the semantic standpoint the private view of private extension T
6110 -- should be flagged as constrained since one can clearly have
6114 -- in a unit withing Pack. However, when deriving subprograms for the
6115 -- private view of private extension T, T must be seen as unconstrained
6116 -- since T has discriminants (this is a constraint of the current
6117 -- subprogram derivation model). Thus, when processing the private view of
6118 -- a private extension such as T, we first mark T as unconstrained, we
6119 -- process it, we perform program derivation and just before returning from
6120 -- Build_Derived_Record_Type we mark T as constrained.
6122 -- ??? Are there are other uncomfortable cases that we will have to
6125 -- 10. RECORD_TYPE_WITH_PRIVATE complications
6127 -- Types that are derived from a visible record type and have a private
6128 -- extension present other peculiarities. They behave mostly like private
6129 -- types, but if they have primitive operations defined, these will not
6130 -- have the proper signatures for further inheritance, because other
6131 -- primitive operations will use the implicit base that we define for
6132 -- private derivations below. This affect subprogram inheritance (see
6133 -- Derive_Subprograms for details). We also derive the implicit base from
6134 -- the base type of the full view, so that the implicit base is a record
6135 -- type and not another private type, This avoids infinite loops.
6137 procedure Build_Derived_Record_Type
6139 Parent_Type : Entity_Id;
6140 Derived_Type : Entity_Id;
6141 Derive_Subps : Boolean := True)
6143 Loc : constant Source_Ptr := Sloc (N);
6144 Parent_Base : Entity_Id;
6147 Discrim : Entity_Id;
6148 Last_Discrim : Entity_Id;
6151 Discs : Elist_Id := New_Elmt_List;
6152 -- An empty Discs list means that there were no constraints in the
6153 -- subtype indication or that there was an error processing it.
6155 Assoc_List : Elist_Id;
6156 New_Discrs : Elist_Id;
6157 New_Base : Entity_Id;
6159 New_Indic : Node_Id;
6161 Is_Tagged : constant Boolean := Is_Tagged_Type (Parent_Type);
6162 Discriminant_Specs : constant Boolean :=
6163 Present (Discriminant_Specifications (N));
6164 Private_Extension : constant Boolean :=
6165 Nkind (N) = N_Private_Extension_Declaration;
6167 Constraint_Present : Boolean;
6168 Inherit_Discrims : Boolean := False;
6169 Save_Etype : Entity_Id;
6170 Save_Discr_Constr : Elist_Id;
6171 Save_Next_Entity : Entity_Id;
6174 if Ekind (Parent_Type) = E_Record_Type_With_Private
6175 and then Present (Full_View (Parent_Type))
6176 and then Has_Discriminants (Parent_Type)
6178 Parent_Base := Base_Type (Full_View (Parent_Type));
6180 Parent_Base := Base_Type (Parent_Type);
6183 -- Before we start the previously documented transformations, here is
6184 -- little fix for size and alignment of tagged types. Normally when we
6185 -- derive type D from type P, we copy the size and alignment of P as the
6186 -- default for D, and in the absence of explicit representation clauses
6187 -- for D, the size and alignment are indeed the same as the parent.
6189 -- But this is wrong for tagged types, since fields may be added, and
6190 -- the default size may need to be larger, and the default alignment may
6191 -- need to be larger.
6193 -- We therefore reset the size and alignment fields in the tagged case.
6194 -- Note that the size and alignment will in any case be at least as
6195 -- large as the parent type (since the derived type has a copy of the
6196 -- parent type in the _parent field)
6198 -- The type is also marked as being tagged here, which is needed when
6199 -- processing components with a self-referential anonymous access type
6200 -- in the call to Check_Anonymous_Access_Components below. Note that
6201 -- this flag is also set later on for completeness.
6204 Set_Is_Tagged_Type (Derived_Type);
6205 Init_Size_Align (Derived_Type);
6208 -- STEP 0a: figure out what kind of derived type declaration we have
6210 if Private_Extension then
6212 Set_Ekind (Derived_Type, E_Record_Type_With_Private);
6215 Type_Def := Type_Definition (N);
6217 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
6218 -- Parent_Base can be a private type or private extension. However,
6219 -- for tagged types with an extension the newly added fields are
6220 -- visible and hence the Derived_Type is always an E_Record_Type.
6221 -- (except that the parent may have its own private fields).
6222 -- For untagged types we preserve the Ekind of the Parent_Base.
6224 if Present (Record_Extension_Part (Type_Def)) then
6225 Set_Ekind (Derived_Type, E_Record_Type);
6227 -- Create internal access types for components with anonymous
6230 if Ada_Version >= Ada_05 then
6231 Check_Anonymous_Access_Components
6232 (N, Derived_Type, Derived_Type,
6233 Component_List (Record_Extension_Part (Type_Def)));
6237 Set_Ekind (Derived_Type, Ekind (Parent_Base));
6241 -- Indic can either be an N_Identifier if the subtype indication
6242 -- contains no constraint or an N_Subtype_Indication if the subtype
6243 -- indication has a constraint.
6245 Indic := Subtype_Indication (Type_Def);
6246 Constraint_Present := (Nkind (Indic) = N_Subtype_Indication);
6248 -- Check that the type has visible discriminants. The type may be
6249 -- a private type with unknown discriminants whose full view has
6250 -- discriminants which are invisible.
6252 if Constraint_Present then
6253 if not Has_Discriminants (Parent_Base)
6255 (Has_Unknown_Discriminants (Parent_Base)
6256 and then Is_Private_Type (Parent_Base))
6259 ("invalid constraint: type has no discriminant",
6260 Constraint (Indic));
6262 Constraint_Present := False;
6263 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6265 elsif Is_Constrained (Parent_Type) then
6267 ("invalid constraint: parent type is already constrained",
6268 Constraint (Indic));
6270 Constraint_Present := False;
6271 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6275 -- STEP 0b: If needed, apply transformation given in point 5. above
6277 if not Private_Extension
6278 and then Has_Discriminants (Parent_Type)
6279 and then not Discriminant_Specs
6280 and then (Is_Constrained (Parent_Type) or else Constraint_Present)
6282 -- First, we must analyze the constraint (see comment in point 5.)
6284 if Constraint_Present then
6285 New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic);
6287 if Has_Discriminants (Derived_Type)
6288 and then Has_Private_Declaration (Derived_Type)
6289 and then Present (Discriminant_Constraint (Derived_Type))
6291 -- Verify that constraints of the full view statically match
6292 -- those given in the partial view.
6298 C1 := First_Elmt (New_Discrs);
6299 C2 := First_Elmt (Discriminant_Constraint (Derived_Type));
6300 while Present (C1) and then Present (C2) loop
6301 if Fully_Conformant_Expressions (Node (C1), Node (C2))
6303 (Is_OK_Static_Expression (Node (C1))
6305 Is_OK_Static_Expression (Node (C2))
6307 Expr_Value (Node (C1)) = Expr_Value (Node (C2)))
6313 "constraint not conformant to previous declaration",
6324 -- Insert and analyze the declaration for the unconstrained base type
6326 New_Base := Create_Itype (Ekind (Derived_Type), N, Derived_Type, 'B');
6329 Make_Full_Type_Declaration (Loc,
6330 Defining_Identifier => New_Base,
6332 Make_Derived_Type_Definition (Loc,
6333 Abstract_Present => Abstract_Present (Type_Def),
6334 Subtype_Indication =>
6335 New_Occurrence_Of (Parent_Base, Loc),
6336 Record_Extension_Part =>
6337 Relocate_Node (Record_Extension_Part (Type_Def))));
6339 Set_Parent (New_Decl, Parent (N));
6340 Mark_Rewrite_Insertion (New_Decl);
6341 Insert_Before (N, New_Decl);
6343 -- Note that this call passes False for the Derive_Subps parameter
6344 -- because subprogram derivation is deferred until after creating
6345 -- the subtype (see below).
6348 (New_Decl, Parent_Base, New_Base,
6349 Is_Completion => True, Derive_Subps => False);
6351 -- ??? This needs re-examination to determine whether the
6352 -- above call can simply be replaced by a call to Analyze.
6354 Set_Analyzed (New_Decl);
6356 -- Insert and analyze the declaration for the constrained subtype
6358 if Constraint_Present then
6360 Make_Subtype_Indication (Loc,
6361 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6362 Constraint => Relocate_Node (Constraint (Indic)));
6366 Constr_List : constant List_Id := New_List;
6371 C := First_Elmt (Discriminant_Constraint (Parent_Type));
6372 while Present (C) loop
6375 -- It is safe here to call New_Copy_Tree since
6376 -- Force_Evaluation was called on each constraint in
6377 -- Build_Discriminant_Constraints.
6379 Append (New_Copy_Tree (Expr), To => Constr_List);
6385 Make_Subtype_Indication (Loc,
6386 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6388 Make_Index_Or_Discriminant_Constraint (Loc, Constr_List));
6393 Make_Subtype_Declaration (Loc,
6394 Defining_Identifier => Derived_Type,
6395 Subtype_Indication => New_Indic));
6399 -- Derivation of subprograms must be delayed until the full subtype
6400 -- has been established to ensure proper overriding of subprograms
6401 -- inherited by full types. If the derivations occurred as part of
6402 -- the call to Build_Derived_Type above, then the check for type
6403 -- conformance would fail because earlier primitive subprograms
6404 -- could still refer to the full type prior the change to the new
6405 -- subtype and hence would not match the new base type created here.
6407 Derive_Subprograms (Parent_Type, Derived_Type);
6409 -- For tagged types the Discriminant_Constraint of the new base itype
6410 -- is inherited from the first subtype so that no subtype conformance
6411 -- problem arise when the first subtype overrides primitive
6412 -- operations inherited by the implicit base type.
6415 Set_Discriminant_Constraint
6416 (New_Base, Discriminant_Constraint (Derived_Type));
6422 -- If we get here Derived_Type will have no discriminants or it will be
6423 -- a discriminated unconstrained base type.
6425 -- STEP 1a: perform preliminary actions/checks for derived tagged types
6429 -- The parent type is frozen for non-private extensions (RM 13.14(7))
6430 -- The declaration of a specific descendant of an interface type
6431 -- freezes the interface type (RM 13.14).
6433 if not Private_Extension
6434 or else Is_Interface (Parent_Base)
6436 Freeze_Before (N, Parent_Type);
6439 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
6440 -- cannot be declared at a deeper level than its parent type is
6441 -- removed. The check on derivation within a generic body is also
6442 -- relaxed, but there's a restriction that a derived tagged type
6443 -- cannot be declared in a generic body if it's derived directly
6444 -- or indirectly from a formal type of that generic.
6446 if Ada_Version >= Ada_05 then
6447 if Present (Enclosing_Generic_Body (Derived_Type)) then
6449 Ancestor_Type : Entity_Id;
6452 -- Check to see if any ancestor of the derived type is a
6455 Ancestor_Type := Parent_Type;
6456 while not Is_Generic_Type (Ancestor_Type)
6457 and then Etype (Ancestor_Type) /= Ancestor_Type
6459 Ancestor_Type := Etype (Ancestor_Type);
6462 -- If the derived type does have a formal type as an
6463 -- ancestor, then it's an error if the derived type is
6464 -- declared within the body of the generic unit that
6465 -- declares the formal type in its generic formal part. It's
6466 -- sufficient to check whether the ancestor type is declared
6467 -- inside the same generic body as the derived type (such as
6468 -- within a nested generic spec), in which case the
6469 -- derivation is legal. If the formal type is declared
6470 -- outside of that generic body, then it's guaranteed that
6471 -- the derived type is declared within the generic body of
6472 -- the generic unit declaring the formal type.
6474 if Is_Generic_Type (Ancestor_Type)
6475 and then Enclosing_Generic_Body (Ancestor_Type) /=
6476 Enclosing_Generic_Body (Derived_Type)
6479 ("parent type of& must not be descendant of formal type"
6480 & " of an enclosing generic body",
6481 Indic, Derived_Type);
6486 elsif Type_Access_Level (Derived_Type) /=
6487 Type_Access_Level (Parent_Type)
6488 and then not Is_Generic_Type (Derived_Type)
6490 if Is_Controlled (Parent_Type) then
6492 ("controlled type must be declared at the library level",
6496 ("type extension at deeper accessibility level than parent",
6502 GB : constant Node_Id := Enclosing_Generic_Body (Derived_Type);
6506 and then GB /= Enclosing_Generic_Body (Parent_Base)
6509 ("parent type of& must not be outside generic body"
6511 Indic, Derived_Type);
6517 -- Ada 2005 (AI-251)
6519 if Ada_Version = Ada_05
6522 -- "The declaration of a specific descendant of an interface type
6523 -- freezes the interface type" (RM 13.14).
6528 if Is_Non_Empty_List (Interface_List (Type_Def)) then
6529 Iface := First (Interface_List (Type_Def));
6530 while Present (Iface) loop
6531 Freeze_Before (N, Etype (Iface));
6538 -- STEP 1b : preliminary cleanup of the full view of private types
6540 -- If the type is already marked as having discriminants, then it's the
6541 -- completion of a private type or private extension and we need to
6542 -- retain the discriminants from the partial view if the current
6543 -- declaration has Discriminant_Specifications so that we can verify
6544 -- conformance. However, we must remove any existing components that
6545 -- were inherited from the parent (and attached in Copy_And_Swap)
6546 -- because the full type inherits all appropriate components anyway, and
6547 -- we do not want the partial view's components interfering.
6549 if Has_Discriminants (Derived_Type) and then Discriminant_Specs then
6550 Discrim := First_Discriminant (Derived_Type);
6552 Last_Discrim := Discrim;
6553 Next_Discriminant (Discrim);
6554 exit when No (Discrim);
6557 Set_Last_Entity (Derived_Type, Last_Discrim);
6559 -- In all other cases wipe out the list of inherited components (even
6560 -- inherited discriminants), it will be properly rebuilt here.
6563 Set_First_Entity (Derived_Type, Empty);
6564 Set_Last_Entity (Derived_Type, Empty);
6567 -- STEP 1c: Initialize some flags for the Derived_Type
6569 -- The following flags must be initialized here so that
6570 -- Process_Discriminants can check that discriminants of tagged types do
6571 -- not have a default initial value and that access discriminants are
6572 -- only specified for limited records. For completeness, these flags are
6573 -- also initialized along with all the other flags below.
6575 -- AI-419: Limitedness is not inherited from an interface parent, so to
6576 -- be limited in that case the type must be explicitly declared as
6577 -- limited. However, task and protected interfaces are always limited.
6579 if Limited_Present (Type_Def) then
6580 Set_Is_Limited_Record (Derived_Type);
6582 elsif Is_Limited_Record (Parent_Type)
6583 or else (Present (Full_View (Parent_Type))
6584 and then Is_Limited_Record (Full_View (Parent_Type)))
6586 if not Is_Interface (Parent_Type)
6587 or else Is_Synchronized_Interface (Parent_Type)
6588 or else Is_Protected_Interface (Parent_Type)
6589 or else Is_Task_Interface (Parent_Type)
6591 Set_Is_Limited_Record (Derived_Type);
6595 -- STEP 2a: process discriminants of derived type if any
6597 Push_Scope (Derived_Type);
6599 if Discriminant_Specs then
6600 Set_Has_Unknown_Discriminants (Derived_Type, False);
6602 -- The following call initializes fields Has_Discriminants and
6603 -- Discriminant_Constraint, unless we are processing the completion
6604 -- of a private type declaration.
6606 Check_Or_Process_Discriminants (N, Derived_Type);
6608 -- For non-tagged types the constraint on the Parent_Type must be
6609 -- present and is used to rename the discriminants.
6611 if not Is_Tagged and then not Has_Discriminants (Parent_Type) then
6612 Error_Msg_N ("untagged parent must have discriminants", Indic);
6614 elsif not Is_Tagged and then not Constraint_Present then
6616 ("discriminant constraint needed for derived untagged records",
6619 -- Otherwise the parent subtype must be constrained unless we have a
6620 -- private extension.
6622 elsif not Constraint_Present
6623 and then not Private_Extension
6624 and then not Is_Constrained (Parent_Type)
6627 ("unconstrained type not allowed in this context", Indic);
6629 elsif Constraint_Present then
6630 -- The following call sets the field Corresponding_Discriminant
6631 -- for the discriminants in the Derived_Type.
6633 Discs := Build_Discriminant_Constraints (Parent_Type, Indic, True);
6635 -- For untagged types all new discriminants must rename
6636 -- discriminants in the parent. For private extensions new
6637 -- discriminants cannot rename old ones (implied by [7.3(13)]).
6639 Discrim := First_Discriminant (Derived_Type);
6640 while Present (Discrim) loop
6642 and then No (Corresponding_Discriminant (Discrim))
6645 ("new discriminants must constrain old ones", Discrim);
6647 elsif Private_Extension
6648 and then Present (Corresponding_Discriminant (Discrim))
6651 ("only static constraints allowed for parent"
6652 & " discriminants in the partial view", Indic);
6656 -- If a new discriminant is used in the constraint, then its
6657 -- subtype must be statically compatible with the parent
6658 -- discriminant's subtype (3.7(15)).
6660 if Present (Corresponding_Discriminant (Discrim))
6662 not Subtypes_Statically_Compatible
6664 Etype (Corresponding_Discriminant (Discrim)))
6667 ("subtype must be compatible with parent discriminant",
6671 Next_Discriminant (Discrim);
6674 -- Check whether the constraints of the full view statically
6675 -- match those imposed by the parent subtype [7.3(13)].
6677 if Present (Stored_Constraint (Derived_Type)) then
6682 C1 := First_Elmt (Discs);
6683 C2 := First_Elmt (Stored_Constraint (Derived_Type));
6684 while Present (C1) and then Present (C2) loop
6686 Fully_Conformant_Expressions (Node (C1), Node (C2))
6689 ("not conformant with previous declaration",
6700 -- STEP 2b: No new discriminants, inherit discriminants if any
6703 if Private_Extension then
6704 Set_Has_Unknown_Discriminants
6706 Has_Unknown_Discriminants (Parent_Type)
6707 or else Unknown_Discriminants_Present (N));
6709 -- The partial view of the parent may have unknown discriminants,
6710 -- but if the full view has discriminants and the parent type is
6711 -- in scope they must be inherited.
6713 elsif Has_Unknown_Discriminants (Parent_Type)
6715 (not Has_Discriminants (Parent_Type)
6716 or else not In_Open_Scopes (Scope (Parent_Type)))
6718 Set_Has_Unknown_Discriminants (Derived_Type);
6721 if not Has_Unknown_Discriminants (Derived_Type)
6722 and then not Has_Unknown_Discriminants (Parent_Base)
6723 and then Has_Discriminants (Parent_Type)
6725 Inherit_Discrims := True;
6726 Set_Has_Discriminants
6727 (Derived_Type, True);
6728 Set_Discriminant_Constraint
6729 (Derived_Type, Discriminant_Constraint (Parent_Base));
6732 -- The following test is true for private types (remember
6733 -- transformation 5. is not applied to those) and in an error
6736 if Constraint_Present then
6737 Discs := Build_Discriminant_Constraints (Parent_Type, Indic);
6740 -- For now mark a new derived type as constrained only if it has no
6741 -- discriminants. At the end of Build_Derived_Record_Type we properly
6742 -- set this flag in the case of private extensions. See comments in
6743 -- point 9. just before body of Build_Derived_Record_Type.
6747 not (Inherit_Discrims
6748 or else Has_Unknown_Discriminants (Derived_Type)));
6751 -- STEP 3: initialize fields of derived type
6753 Set_Is_Tagged_Type (Derived_Type, Is_Tagged);
6754 Set_Stored_Constraint (Derived_Type, No_Elist);
6756 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
6757 -- but cannot be interfaces
6759 if not Private_Extension
6760 and then Ekind (Derived_Type) /= E_Private_Type
6761 and then Ekind (Derived_Type) /= E_Limited_Private_Type
6763 if Interface_Present (Type_Def) then
6764 Analyze_Interface_Declaration (Derived_Type, Type_Def);
6767 Set_Interfaces (Derived_Type, No_Elist);
6770 -- Fields inherited from the Parent_Type
6773 (Derived_Type, Einfo.Discard_Names (Parent_Type));
6774 Set_Has_Specified_Layout
6775 (Derived_Type, Has_Specified_Layout (Parent_Type));
6776 Set_Is_Limited_Composite
6777 (Derived_Type, Is_Limited_Composite (Parent_Type));
6778 Set_Is_Private_Composite
6779 (Derived_Type, Is_Private_Composite (Parent_Type));
6781 -- Fields inherited from the Parent_Base
6783 Set_Has_Controlled_Component
6784 (Derived_Type, Has_Controlled_Component (Parent_Base));
6785 Set_Has_Non_Standard_Rep
6786 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6787 Set_Has_Primitive_Operations
6788 (Derived_Type, Has_Primitive_Operations (Parent_Base));
6790 -- Fields inherited from the Parent_Base in the non-private case
6792 if Ekind (Derived_Type) = E_Record_Type then
6793 Set_Has_Complex_Representation
6794 (Derived_Type, Has_Complex_Representation (Parent_Base));
6797 -- Fields inherited from the Parent_Base for record types
6799 if Is_Record_Type (Derived_Type) then
6800 Set_OK_To_Reorder_Components
6801 (Derived_Type, OK_To_Reorder_Components (Parent_Base));
6802 Set_Reverse_Bit_Order
6803 (Derived_Type, Reverse_Bit_Order (Parent_Base));
6806 -- Direct controlled types do not inherit Finalize_Storage_Only flag
6808 if not Is_Controlled (Parent_Type) then
6809 Set_Finalize_Storage_Only
6810 (Derived_Type, Finalize_Storage_Only (Parent_Type));
6813 -- Set fields for private derived types
6815 if Is_Private_Type (Derived_Type) then
6816 Set_Depends_On_Private (Derived_Type, True);
6817 Set_Private_Dependents (Derived_Type, New_Elmt_List);
6819 -- Inherit fields from non private record types. If this is the
6820 -- completion of a derivation from a private type, the parent itself
6821 -- is private, and the attributes come from its full view, which must
6825 if Is_Private_Type (Parent_Base)
6826 and then not Is_Record_Type (Parent_Base)
6828 Set_Component_Alignment
6829 (Derived_Type, Component_Alignment (Full_View (Parent_Base)));
6831 (Derived_Type, C_Pass_By_Copy (Full_View (Parent_Base)));
6833 Set_Component_Alignment
6834 (Derived_Type, Component_Alignment (Parent_Base));
6837 (Derived_Type, C_Pass_By_Copy (Parent_Base));
6841 -- Set fields for tagged types
6844 Set_Primitive_Operations (Derived_Type, New_Elmt_List);
6846 -- All tagged types defined in Ada.Finalization are controlled
6848 if Chars (Scope (Derived_Type)) = Name_Finalization
6849 and then Chars (Scope (Scope (Derived_Type))) = Name_Ada
6850 and then Scope (Scope (Scope (Derived_Type))) = Standard_Standard
6852 Set_Is_Controlled (Derived_Type);
6854 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Base));
6857 Make_Class_Wide_Type (Derived_Type);
6858 Set_Is_Abstract_Type (Derived_Type, Abstract_Present (Type_Def));
6860 if Has_Discriminants (Derived_Type)
6861 and then Constraint_Present
6863 Set_Stored_Constraint
6864 (Derived_Type, Expand_To_Stored_Constraint (Parent_Base, Discs));
6867 if Ada_Version >= Ada_05 then
6869 Ifaces_List : Elist_Id;
6872 -- Checks rules 3.9.4 (13/2 and 14/2)
6874 if Comes_From_Source (Derived_Type)
6875 and then not Is_Private_Type (Derived_Type)
6876 and then Is_Interface (Parent_Type)
6877 and then not Is_Interface (Derived_Type)
6879 if Is_Task_Interface (Parent_Type) then
6881 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
6884 elsif Is_Protected_Interface (Parent_Type) then
6886 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
6891 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
6893 Check_Interfaces (N, Type_Def);
6895 -- Ada 2005 (AI-251): Collect the list of progenitors that are
6896 -- not already in the parents.
6900 Ifaces_List => Ifaces_List,
6901 Exclude_Parents => True);
6903 Set_Interfaces (Derived_Type, Ifaces_List);
6908 Set_Is_Packed (Derived_Type, Is_Packed (Parent_Base));
6909 Set_Has_Non_Standard_Rep
6910 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6913 -- STEP 4: Inherit components from the parent base and constrain them.
6914 -- Apply the second transformation described in point 6. above.
6916 if (not Is_Empty_Elmt_List (Discs) or else Inherit_Discrims)
6917 or else not Has_Discriminants (Parent_Type)
6918 or else not Is_Constrained (Parent_Type)
6922 Constrs := Discriminant_Constraint (Parent_Type);
6927 (N, Parent_Base, Derived_Type, Is_Tagged, Inherit_Discrims, Constrs);
6929 -- STEP 5a: Copy the parent record declaration for untagged types
6931 if not Is_Tagged then
6933 -- Discriminant_Constraint (Derived_Type) has been properly
6934 -- constructed. Save it and temporarily set it to Empty because we
6935 -- do not want the call to New_Copy_Tree below to mess this list.
6937 if Has_Discriminants (Derived_Type) then
6938 Save_Discr_Constr := Discriminant_Constraint (Derived_Type);
6939 Set_Discriminant_Constraint (Derived_Type, No_Elist);
6941 Save_Discr_Constr := No_Elist;
6944 -- Save the Etype field of Derived_Type. It is correctly set now,
6945 -- but the call to New_Copy tree may remap it to point to itself,
6946 -- which is not what we want. Ditto for the Next_Entity field.
6948 Save_Etype := Etype (Derived_Type);
6949 Save_Next_Entity := Next_Entity (Derived_Type);
6951 -- Assoc_List maps all stored discriminants in the Parent_Base to
6952 -- stored discriminants in the Derived_Type. It is fundamental that
6953 -- no types or itypes with discriminants other than the stored
6954 -- discriminants appear in the entities declared inside
6955 -- Derived_Type, since the back end cannot deal with it.
6959 (Parent (Parent_Base), Map => Assoc_List, New_Sloc => Loc);
6961 -- Restore the fields saved prior to the New_Copy_Tree call
6962 -- and compute the stored constraint.
6964 Set_Etype (Derived_Type, Save_Etype);
6965 Set_Next_Entity (Derived_Type, Save_Next_Entity);
6967 if Has_Discriminants (Derived_Type) then
6968 Set_Discriminant_Constraint
6969 (Derived_Type, Save_Discr_Constr);
6970 Set_Stored_Constraint
6971 (Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs));
6972 Replace_Components (Derived_Type, New_Decl);
6975 -- Insert the new derived type declaration
6977 Rewrite (N, New_Decl);
6979 -- STEP 5b: Complete the processing for record extensions in generics
6981 -- There is no completion for record extensions declared in the
6982 -- parameter part of a generic, so we need to complete processing for
6983 -- these generic record extensions here. The Record_Type_Definition call
6984 -- will change the Ekind of the components from E_Void to E_Component.
6986 elsif Private_Extension and then Is_Generic_Type (Derived_Type) then
6987 Record_Type_Definition (Empty, Derived_Type);
6989 -- STEP 5c: Process the record extension for non private tagged types
6991 elsif not Private_Extension then
6993 -- Add the _parent field in the derived type
6995 Expand_Record_Extension (Derived_Type, Type_Def);
6997 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
6998 -- implemented interfaces if we are in expansion mode
7001 and then Has_Interfaces (Derived_Type)
7003 Add_Interface_Tag_Components (N, Derived_Type);
7006 -- Analyze the record extension
7008 Record_Type_Definition
7009 (Record_Extension_Part (Type_Def), Derived_Type);
7014 -- Nothing else to do if there is an error in the derivation.
7015 -- An unusual case: the full view may be derived from a type in an
7016 -- instance, when the partial view was used illegally as an actual
7017 -- in that instance, leading to a circular definition.
7019 if Etype (Derived_Type) = Any_Type
7020 or else Etype (Parent_Type) = Derived_Type
7025 -- Set delayed freeze and then derive subprograms, we need to do
7026 -- this in this order so that derived subprograms inherit the
7027 -- derived freeze if necessary.
7029 Set_Has_Delayed_Freeze (Derived_Type);
7031 if Derive_Subps then
7032 Derive_Subprograms (Parent_Type, Derived_Type);
7035 -- If we have a private extension which defines a constrained derived
7036 -- type mark as constrained here after we have derived subprograms. See
7037 -- comment on point 9. just above the body of Build_Derived_Record_Type.
7039 if Private_Extension and then Inherit_Discrims then
7040 if Constraint_Present and then not Is_Empty_Elmt_List (Discs) then
7041 Set_Is_Constrained (Derived_Type, True);
7042 Set_Discriminant_Constraint (Derived_Type, Discs);
7044 elsif Is_Constrained (Parent_Type) then
7046 (Derived_Type, True);
7047 Set_Discriminant_Constraint
7048 (Derived_Type, Discriminant_Constraint (Parent_Type));
7052 -- Update the class_wide type, which shares the now-completed
7053 -- entity list with its specific type.
7057 (Class_Wide_Type (Derived_Type), First_Entity (Derived_Type));
7059 (Class_Wide_Type (Derived_Type), Last_Entity (Derived_Type));
7062 -- Update the scope of anonymous access types of discriminants and other
7063 -- components, to prevent scope anomalies in gigi, when the derivation
7064 -- appears in a scope nested within that of the parent.
7070 D := First_Entity (Derived_Type);
7071 while Present (D) loop
7072 if Ekind (D) = E_Discriminant
7073 or else Ekind (D) = E_Component
7075 if Is_Itype (Etype (D))
7076 and then Ekind (Etype (D)) = E_Anonymous_Access_Type
7078 Set_Scope (Etype (D), Current_Scope);
7085 end Build_Derived_Record_Type;
7087 ------------------------
7088 -- Build_Derived_Type --
7089 ------------------------
7091 procedure Build_Derived_Type
7093 Parent_Type : Entity_Id;
7094 Derived_Type : Entity_Id;
7095 Is_Completion : Boolean;
7096 Derive_Subps : Boolean := True)
7098 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
7101 -- Set common attributes
7103 Set_Scope (Derived_Type, Current_Scope);
7105 Set_Ekind (Derived_Type, Ekind (Parent_Base));
7106 Set_Etype (Derived_Type, Parent_Base);
7107 Set_Has_Task (Derived_Type, Has_Task (Parent_Base));
7109 Set_Size_Info (Derived_Type, Parent_Type);
7110 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
7111 Set_Convention (Derived_Type, Convention (Parent_Type));
7112 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
7114 -- The derived type inherits the representation clauses of the parent.
7115 -- However, for a private type that is completed by a derivation, there
7116 -- may be operation attributes that have been specified already (stream
7117 -- attributes and External_Tag) and those must be provided. Finally,
7118 -- if the partial view is a private extension, the representation items
7119 -- of the parent have been inherited already, and should not be chained
7120 -- twice to the derived type.
7122 if Is_Tagged_Type (Parent_Type)
7123 and then Present (First_Rep_Item (Derived_Type))
7125 -- The existing items are either operational items or items inherited
7126 -- from a private extension declaration.
7130 -- Used to iterate over representation items of the derived type
7133 -- Last representation item of the (non-empty) representation
7134 -- item list of the derived type.
7136 Found : Boolean := False;
7139 Rep := First_Rep_Item (Derived_Type);
7141 while Present (Rep) loop
7142 if Rep = First_Rep_Item (Parent_Type) then
7147 Rep := Next_Rep_Item (Rep);
7149 if Present (Rep) then
7155 -- Here if we either encountered the parent type's first rep
7156 -- item on the derived type's rep item list (in which case
7157 -- Found is True, and we have nothing else to do), or if we
7158 -- reached the last rep item of the derived type, which is
7159 -- Last_Rep, in which case we further chain the parent type's
7160 -- rep items to those of the derived type.
7163 Set_Next_Rep_Item (Last_Rep, First_Rep_Item (Parent_Type));
7168 Set_First_Rep_Item (Derived_Type, First_Rep_Item (Parent_Type));
7171 case Ekind (Parent_Type) is
7172 when Numeric_Kind =>
7173 Build_Derived_Numeric_Type (N, Parent_Type, Derived_Type);
7176 Build_Derived_Array_Type (N, Parent_Type, Derived_Type);
7180 | Class_Wide_Kind =>
7181 Build_Derived_Record_Type
7182 (N, Parent_Type, Derived_Type, Derive_Subps);
7185 when Enumeration_Kind =>
7186 Build_Derived_Enumeration_Type (N, Parent_Type, Derived_Type);
7189 Build_Derived_Access_Type (N, Parent_Type, Derived_Type);
7191 when Incomplete_Or_Private_Kind =>
7192 Build_Derived_Private_Type
7193 (N, Parent_Type, Derived_Type, Is_Completion, Derive_Subps);
7195 -- For discriminated types, the derivation includes deriving
7196 -- primitive operations. For others it is done below.
7198 if Is_Tagged_Type (Parent_Type)
7199 or else Has_Discriminants (Parent_Type)
7200 or else (Present (Full_View (Parent_Type))
7201 and then Has_Discriminants (Full_View (Parent_Type)))
7206 when Concurrent_Kind =>
7207 Build_Derived_Concurrent_Type (N, Parent_Type, Derived_Type);
7210 raise Program_Error;
7213 if Etype (Derived_Type) = Any_Type then
7217 -- Set delayed freeze and then derive subprograms, we need to do this
7218 -- in this order so that derived subprograms inherit the derived freeze
7221 Set_Has_Delayed_Freeze (Derived_Type);
7222 if Derive_Subps then
7223 Derive_Subprograms (Parent_Type, Derived_Type);
7226 Set_Has_Primitive_Operations
7227 (Base_Type (Derived_Type), Has_Primitive_Operations (Parent_Type));
7228 end Build_Derived_Type;
7230 -----------------------
7231 -- Build_Discriminal --
7232 -----------------------
7234 procedure Build_Discriminal (Discrim : Entity_Id) is
7235 D_Minal : Entity_Id;
7236 CR_Disc : Entity_Id;
7239 -- A discriminal has the same name as the discriminant
7242 Make_Defining_Identifier (Sloc (Discrim),
7243 Chars => Chars (Discrim));
7245 Set_Ekind (D_Minal, E_In_Parameter);
7246 Set_Mechanism (D_Minal, Default_Mechanism);
7247 Set_Etype (D_Minal, Etype (Discrim));
7249 Set_Discriminal (Discrim, D_Minal);
7250 Set_Discriminal_Link (D_Minal, Discrim);
7252 -- For task types, build at once the discriminants of the corresponding
7253 -- record, which are needed if discriminants are used in entry defaults
7254 -- and in family bounds.
7256 if Is_Concurrent_Type (Current_Scope)
7257 or else Is_Limited_Type (Current_Scope)
7259 CR_Disc := Make_Defining_Identifier (Sloc (Discrim), Chars (Discrim));
7261 Set_Ekind (CR_Disc, E_In_Parameter);
7262 Set_Mechanism (CR_Disc, Default_Mechanism);
7263 Set_Etype (CR_Disc, Etype (Discrim));
7264 Set_Discriminal_Link (CR_Disc, Discrim);
7265 Set_CR_Discriminant (Discrim, CR_Disc);
7267 end Build_Discriminal;
7269 ------------------------------------
7270 -- Build_Discriminant_Constraints --
7271 ------------------------------------
7273 function Build_Discriminant_Constraints
7276 Derived_Def : Boolean := False) return Elist_Id
7278 C : constant Node_Id := Constraint (Def);
7279 Nb_Discr : constant Nat := Number_Discriminants (T);
7281 Discr_Expr : array (1 .. Nb_Discr) of Node_Id := (others => Empty);
7282 -- Saves the expression corresponding to a given discriminant in T
7284 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat;
7285 -- Return the Position number within array Discr_Expr of a discriminant
7286 -- D within the discriminant list of the discriminated type T.
7292 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat is
7296 Disc := First_Discriminant (T);
7297 for J in Discr_Expr'Range loop
7302 Next_Discriminant (Disc);
7305 -- Note: Since this function is called on discriminants that are
7306 -- known to belong to the discriminated type, falling through the
7307 -- loop with no match signals an internal compiler error.
7309 raise Program_Error;
7312 -- Declarations local to Build_Discriminant_Constraints
7316 Elist : constant Elist_Id := New_Elmt_List;
7324 Discrim_Present : Boolean := False;
7326 -- Start of processing for Build_Discriminant_Constraints
7329 -- The following loop will process positional associations only.
7330 -- For a positional association, the (single) discriminant is
7331 -- implicitly specified by position, in textual order (RM 3.7.2).
7333 Discr := First_Discriminant (T);
7334 Constr := First (Constraints (C));
7335 for D in Discr_Expr'Range loop
7336 exit when Nkind (Constr) = N_Discriminant_Association;
7339 Error_Msg_N ("too few discriminants given in constraint", C);
7340 return New_Elmt_List;
7342 elsif Nkind (Constr) = N_Range
7343 or else (Nkind (Constr) = N_Attribute_Reference
7345 Attribute_Name (Constr) = Name_Range)
7348 ("a range is not a valid discriminant constraint", Constr);
7349 Discr_Expr (D) := Error;
7352 Analyze_And_Resolve (Constr, Base_Type (Etype (Discr)));
7353 Discr_Expr (D) := Constr;
7356 Next_Discriminant (Discr);
7360 if No (Discr) and then Present (Constr) then
7361 Error_Msg_N ("too many discriminants given in constraint", Constr);
7362 return New_Elmt_List;
7365 -- Named associations can be given in any order, but if both positional
7366 -- and named associations are used in the same discriminant constraint,
7367 -- then positional associations must occur first, at their normal
7368 -- position. Hence once a named association is used, the rest of the
7369 -- discriminant constraint must use only named associations.
7371 while Present (Constr) loop
7373 -- Positional association forbidden after a named association
7375 if Nkind (Constr) /= N_Discriminant_Association then
7376 Error_Msg_N ("positional association follows named one", Constr);
7377 return New_Elmt_List;
7379 -- Otherwise it is a named association
7382 -- E records the type of the discriminants in the named
7383 -- association. All the discriminants specified in the same name
7384 -- association must have the same type.
7388 -- Search the list of discriminants in T to see if the simple name
7389 -- given in the constraint matches any of them.
7391 Id := First (Selector_Names (Constr));
7392 while Present (Id) loop
7395 -- If Original_Discriminant is present, we are processing a
7396 -- generic instantiation and this is an instance node. We need
7397 -- to find the name of the corresponding discriminant in the
7398 -- actual record type T and not the name of the discriminant in
7399 -- the generic formal. Example:
7402 -- type G (D : int) is private;
7404 -- subtype W is G (D => 1);
7406 -- type Rec (X : int) is record ... end record;
7407 -- package Q is new P (G => Rec);
7409 -- At the point of the instantiation, formal type G is Rec
7410 -- and therefore when reanalyzing "subtype W is G (D => 1);"
7411 -- which really looks like "subtype W is Rec (D => 1);" at
7412 -- the point of instantiation, we want to find the discriminant
7413 -- that corresponds to D in Rec, i.e. X.
7415 if Present (Original_Discriminant (Id)) then
7416 Discr := Find_Corresponding_Discriminant (Id, T);
7420 Discr := First_Discriminant (T);
7421 while Present (Discr) loop
7422 if Chars (Discr) = Chars (Id) then
7427 Next_Discriminant (Discr);
7431 Error_Msg_N ("& does not match any discriminant", Id);
7432 return New_Elmt_List;
7434 -- The following is only useful for the benefit of generic
7435 -- instances but it does not interfere with other
7436 -- processing for the non-generic case so we do it in all
7437 -- cases (for generics this statement is executed when
7438 -- processing the generic definition, see comment at the
7439 -- beginning of this if statement).
7442 Set_Original_Discriminant (Id, Discr);
7446 Position := Pos_Of_Discr (T, Discr);
7448 if Present (Discr_Expr (Position)) then
7449 Error_Msg_N ("duplicate constraint for discriminant&", Id);
7452 -- Each discriminant specified in the same named association
7453 -- must be associated with a separate copy of the
7454 -- corresponding expression.
7456 if Present (Next (Id)) then
7457 Expr := New_Copy_Tree (Expression (Constr));
7458 Set_Parent (Expr, Parent (Expression (Constr)));
7460 Expr := Expression (Constr);
7463 Discr_Expr (Position) := Expr;
7464 Analyze_And_Resolve (Expr, Base_Type (Etype (Discr)));
7467 -- A discriminant association with more than one discriminant
7468 -- name is only allowed if the named discriminants are all of
7469 -- the same type (RM 3.7.1(8)).
7472 E := Base_Type (Etype (Discr));
7474 elsif Base_Type (Etype (Discr)) /= E then
7476 ("all discriminants in an association " &
7477 "must have the same type", Id);
7487 -- A discriminant constraint must provide exactly one value for each
7488 -- discriminant of the type (RM 3.7.1(8)).
7490 for J in Discr_Expr'Range loop
7491 if No (Discr_Expr (J)) then
7492 Error_Msg_N ("too few discriminants given in constraint", C);
7493 return New_Elmt_List;
7497 -- Determine if there are discriminant expressions in the constraint
7499 for J in Discr_Expr'Range loop
7500 if Denotes_Discriminant
7501 (Discr_Expr (J), Check_Concurrent => True)
7503 Discrim_Present := True;
7507 -- Build an element list consisting of the expressions given in the
7508 -- discriminant constraint and apply the appropriate checks. The list
7509 -- is constructed after resolving any named discriminant associations
7510 -- and therefore the expressions appear in the textual order of the
7513 Discr := First_Discriminant (T);
7514 for J in Discr_Expr'Range loop
7515 if Discr_Expr (J) /= Error then
7516 Append_Elmt (Discr_Expr (J), Elist);
7518 -- If any of the discriminant constraints is given by a
7519 -- discriminant and we are in a derived type declaration we
7520 -- have a discriminant renaming. Establish link between new
7521 -- and old discriminant.
7523 if Denotes_Discriminant (Discr_Expr (J)) then
7525 Set_Corresponding_Discriminant
7526 (Entity (Discr_Expr (J)), Discr);
7529 -- Force the evaluation of non-discriminant expressions.
7530 -- If we have found a discriminant in the constraint 3.4(26)
7531 -- and 3.8(18) demand that no range checks are performed are
7532 -- after evaluation. If the constraint is for a component
7533 -- definition that has a per-object constraint, expressions are
7534 -- evaluated but not checked either. In all other cases perform
7538 if Discrim_Present then
7541 elsif Nkind (Parent (Parent (Def))) = N_Component_Declaration
7543 Has_Per_Object_Constraint
7544 (Defining_Identifier (Parent (Parent (Def))))
7548 elsif Is_Access_Type (Etype (Discr)) then
7549 Apply_Constraint_Check (Discr_Expr (J), Etype (Discr));
7552 Apply_Range_Check (Discr_Expr (J), Etype (Discr));
7555 Force_Evaluation (Discr_Expr (J));
7558 -- Check that the designated type of an access discriminant's
7559 -- expression is not a class-wide type unless the discriminant's
7560 -- designated type is also class-wide.
7562 if Ekind (Etype (Discr)) = E_Anonymous_Access_Type
7563 and then not Is_Class_Wide_Type
7564 (Designated_Type (Etype (Discr)))
7565 and then Etype (Discr_Expr (J)) /= Any_Type
7566 and then Is_Class_Wide_Type
7567 (Designated_Type (Etype (Discr_Expr (J))))
7569 Wrong_Type (Discr_Expr (J), Etype (Discr));
7573 Next_Discriminant (Discr);
7577 end Build_Discriminant_Constraints;
7579 ---------------------------------
7580 -- Build_Discriminated_Subtype --
7581 ---------------------------------
7583 procedure Build_Discriminated_Subtype
7587 Related_Nod : Node_Id;
7588 For_Access : Boolean := False)
7590 Has_Discrs : constant Boolean := Has_Discriminants (T);
7591 Constrained : constant Boolean :=
7593 and then not Is_Empty_Elmt_List (Elist)
7594 and then not Is_Class_Wide_Type (T))
7595 or else Is_Constrained (T);
7598 if Ekind (T) = E_Record_Type then
7600 Set_Ekind (Def_Id, E_Private_Subtype);
7601 Set_Is_For_Access_Subtype (Def_Id, True);
7603 Set_Ekind (Def_Id, E_Record_Subtype);
7606 -- Inherit preelaboration flag from base, for types for which it
7607 -- may have been set: records, private types, protected types.
7609 Set_Known_To_Have_Preelab_Init
7610 (Def_Id, Known_To_Have_Preelab_Init (T));
7612 elsif Ekind (T) = E_Task_Type then
7613 Set_Ekind (Def_Id, E_Task_Subtype);
7615 elsif Ekind (T) = E_Protected_Type then
7616 Set_Ekind (Def_Id, E_Protected_Subtype);
7617 Set_Known_To_Have_Preelab_Init
7618 (Def_Id, Known_To_Have_Preelab_Init (T));
7620 elsif Is_Private_Type (T) then
7621 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
7622 Set_Known_To_Have_Preelab_Init
7623 (Def_Id, Known_To_Have_Preelab_Init (T));
7625 elsif Is_Class_Wide_Type (T) then
7626 Set_Ekind (Def_Id, E_Class_Wide_Subtype);
7629 -- Incomplete type. Attach subtype to list of dependents, to be
7630 -- completed with full view of parent type, unless is it the
7631 -- designated subtype of a record component within an init_proc.
7632 -- This last case arises for a component of an access type whose
7633 -- designated type is incomplete (e.g. a Taft Amendment type).
7634 -- The designated subtype is within an inner scope, and needs no
7635 -- elaboration, because only the access type is needed in the
7636 -- initialization procedure.
7638 Set_Ekind (Def_Id, Ekind (T));
7640 if For_Access and then Within_Init_Proc then
7643 Append_Elmt (Def_Id, Private_Dependents (T));
7647 Set_Etype (Def_Id, T);
7648 Init_Size_Align (Def_Id);
7649 Set_Has_Discriminants (Def_Id, Has_Discrs);
7650 Set_Is_Constrained (Def_Id, Constrained);
7652 Set_First_Entity (Def_Id, First_Entity (T));
7653 Set_Last_Entity (Def_Id, Last_Entity (T));
7655 -- If the subtype is the completion of a private declaration, there may
7656 -- have been representation clauses for the partial view, and they must
7657 -- be preserved. Build_Derived_Type chains the inherited clauses with
7658 -- the ones appearing on the extension. If this comes from a subtype
7659 -- declaration, all clauses are inherited.
7661 if No (First_Rep_Item (Def_Id)) then
7662 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
7665 if Is_Tagged_Type (T) then
7666 Set_Is_Tagged_Type (Def_Id);
7667 Make_Class_Wide_Type (Def_Id);
7670 Set_Stored_Constraint (Def_Id, No_Elist);
7673 Set_Discriminant_Constraint (Def_Id, Elist);
7674 Set_Stored_Constraint_From_Discriminant_Constraint (Def_Id);
7677 if Is_Tagged_Type (T) then
7679 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
7680 -- concurrent record type (which has the list of primitive
7683 if Ada_Version >= Ada_05
7684 and then Is_Concurrent_Type (T)
7686 Set_Corresponding_Record_Type (Def_Id,
7687 Corresponding_Record_Type (T));
7689 Set_Primitive_Operations (Def_Id, Primitive_Operations (T));
7692 Set_Is_Abstract_Type (Def_Id, Is_Abstract_Type (T));
7695 -- Subtypes introduced by component declarations do not need to be
7696 -- marked as delayed, and do not get freeze nodes, because the semantics
7697 -- verifies that the parents of the subtypes are frozen before the
7698 -- enclosing record is frozen.
7700 if not Is_Type (Scope (Def_Id)) then
7701 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
7703 if Is_Private_Type (T)
7704 and then Present (Full_View (T))
7706 Conditional_Delay (Def_Id, Full_View (T));
7708 Conditional_Delay (Def_Id, T);
7712 if Is_Record_Type (T) then
7713 Set_Is_Limited_Record (Def_Id, Is_Limited_Record (T));
7716 and then not Is_Empty_Elmt_List (Elist)
7717 and then not For_Access
7719 Create_Constrained_Components (Def_Id, Related_Nod, T, Elist);
7720 elsif not For_Access then
7721 Set_Cloned_Subtype (Def_Id, T);
7724 end Build_Discriminated_Subtype;
7726 ---------------------------
7727 -- Build_Itype_Reference --
7728 ---------------------------
7730 procedure Build_Itype_Reference
7734 IR : constant Node_Id := Make_Itype_Reference (Sloc (Nod));
7736 Set_Itype (IR, Ityp);
7737 Insert_After (Nod, IR);
7738 end Build_Itype_Reference;
7740 ------------------------
7741 -- Build_Scalar_Bound --
7742 ------------------------
7744 function Build_Scalar_Bound
7747 Der_T : Entity_Id) return Node_Id
7749 New_Bound : Entity_Id;
7752 -- Note: not clear why this is needed, how can the original bound
7753 -- be unanalyzed at this point? and if it is, what business do we
7754 -- have messing around with it? and why is the base type of the
7755 -- parent type the right type for the resolution. It probably is
7756 -- not! It is OK for the new bound we are creating, but not for
7757 -- the old one??? Still if it never happens, no problem!
7759 Analyze_And_Resolve (Bound, Base_Type (Par_T));
7761 if Nkind_In (Bound, N_Integer_Literal, N_Real_Literal) then
7762 New_Bound := New_Copy (Bound);
7763 Set_Etype (New_Bound, Der_T);
7764 Set_Analyzed (New_Bound);
7766 elsif Is_Entity_Name (Bound) then
7767 New_Bound := OK_Convert_To (Der_T, New_Copy (Bound));
7769 -- The following is almost certainly wrong. What business do we have
7770 -- relocating a node (Bound) that is presumably still attached to
7771 -- the tree elsewhere???
7774 New_Bound := OK_Convert_To (Der_T, Relocate_Node (Bound));
7777 Set_Etype (New_Bound, Der_T);
7779 end Build_Scalar_Bound;
7781 --------------------------------
7782 -- Build_Underlying_Full_View --
7783 --------------------------------
7785 procedure Build_Underlying_Full_View
7790 Loc : constant Source_Ptr := Sloc (N);
7791 Subt : constant Entity_Id :=
7792 Make_Defining_Identifier
7793 (Loc, New_External_Name (Chars (Typ), 'S'));
7800 procedure Set_Discriminant_Name (Id : Node_Id);
7801 -- If the derived type has discriminants, they may rename discriminants
7802 -- of the parent. When building the full view of the parent, we need to
7803 -- recover the names of the original discriminants if the constraint is
7804 -- given by named associations.
7806 ---------------------------
7807 -- Set_Discriminant_Name --
7808 ---------------------------
7810 procedure Set_Discriminant_Name (Id : Node_Id) is
7814 Set_Original_Discriminant (Id, Empty);
7816 if Has_Discriminants (Typ) then
7817 Disc := First_Discriminant (Typ);
7818 while Present (Disc) loop
7819 if Chars (Disc) = Chars (Id)
7820 and then Present (Corresponding_Discriminant (Disc))
7822 Set_Chars (Id, Chars (Corresponding_Discriminant (Disc)));
7824 Next_Discriminant (Disc);
7827 end Set_Discriminant_Name;
7829 -- Start of processing for Build_Underlying_Full_View
7832 if Nkind (N) = N_Full_Type_Declaration then
7833 Constr := Constraint (Subtype_Indication (Type_Definition (N)));
7835 elsif Nkind (N) = N_Subtype_Declaration then
7836 Constr := New_Copy_Tree (Constraint (Subtype_Indication (N)));
7838 elsif Nkind (N) = N_Component_Declaration then
7841 (Constraint (Subtype_Indication (Component_Definition (N))));
7844 raise Program_Error;
7847 C := First (Constraints (Constr));
7848 while Present (C) loop
7849 if Nkind (C) = N_Discriminant_Association then
7850 Id := First (Selector_Names (C));
7851 while Present (Id) loop
7852 Set_Discriminant_Name (Id);
7861 Make_Subtype_Declaration (Loc,
7862 Defining_Identifier => Subt,
7863 Subtype_Indication =>
7864 Make_Subtype_Indication (Loc,
7865 Subtype_Mark => New_Reference_To (Par, Loc),
7866 Constraint => New_Copy_Tree (Constr)));
7868 -- If this is a component subtype for an outer itype, it is not
7869 -- a list member, so simply set the parent link for analysis: if
7870 -- the enclosing type does not need to be in a declarative list,
7871 -- neither do the components.
7873 if Is_List_Member (N)
7874 and then Nkind (N) /= N_Component_Declaration
7876 Insert_Before (N, Indic);
7878 Set_Parent (Indic, Parent (N));
7882 Set_Underlying_Full_View (Typ, Full_View (Subt));
7883 end Build_Underlying_Full_View;
7885 -------------------------------
7886 -- Check_Abstract_Overriding --
7887 -------------------------------
7889 procedure Check_Abstract_Overriding (T : Entity_Id) is
7890 Alias_Subp : Entity_Id;
7897 Op_List := Primitive_Operations (T);
7899 -- Loop to check primitive operations
7901 Elmt := First_Elmt (Op_List);
7902 while Present (Elmt) loop
7903 Subp := Node (Elmt);
7904 Alias_Subp := Alias (Subp);
7906 -- Inherited subprograms are identified by the fact that they do not
7907 -- come from source, and the associated source location is the
7908 -- location of the first subtype of the derived type.
7910 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
7911 -- subprograms that "require overriding".
7913 -- Special exception, do not complain about failure to override the
7914 -- stream routines _Input and _Output, as well as the primitive
7915 -- operations used in dispatching selects since we always provide
7916 -- automatic overridings for these subprograms.
7918 -- Also ignore this rule for convention CIL since .NET libraries
7919 -- do bizarre things with interfaces???
7921 -- The partial view of T may have been a private extension, for
7922 -- which inherited functions dispatching on result are abstract.
7923 -- If the full view is a null extension, there is no need for
7924 -- overriding in Ada2005, but wrappers need to be built for them
7925 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
7927 if Is_Null_Extension (T)
7928 and then Has_Controlling_Result (Subp)
7929 and then Ada_Version >= Ada_05
7930 and then Present (Alias_Subp)
7931 and then not Comes_From_Source (Subp)
7932 and then not Is_Abstract_Subprogram (Alias_Subp)
7933 and then not Is_Access_Type (Etype (Subp))
7937 -- Ada 2005 (AI-251): Internal entities of interfaces need no
7938 -- processing because this check is done with the aliased
7941 elsif Present (Interface_Alias (Subp)) then
7944 elsif (Is_Abstract_Subprogram (Subp)
7945 or else Requires_Overriding (Subp)
7947 (Has_Controlling_Result (Subp)
7948 and then Present (Alias_Subp)
7949 and then not Comes_From_Source (Subp)
7950 and then Sloc (Subp) = Sloc (First_Subtype (T))))
7951 and then not Is_TSS (Subp, TSS_Stream_Input)
7952 and then not Is_TSS (Subp, TSS_Stream_Output)
7953 and then not Is_Abstract_Type (T)
7954 and then Convention (T) /= Convention_CIL
7955 and then not Is_Predefined_Interface_Primitive (Subp)
7957 -- Ada 2005 (AI-251): Do not consider hidden entities associated
7958 -- with abstract interface types because the check will be done
7959 -- with the aliased entity (otherwise we generate a duplicated
7962 and then not Present (Interface_Alias (Subp))
7964 if Present (Alias_Subp) then
7966 -- Only perform the check for a derived subprogram when the
7967 -- type has an explicit record extension. This avoids incorrect
7968 -- flagging of abstract subprograms for the case of a type
7969 -- without an extension that is derived from a formal type
7970 -- with a tagged actual (can occur within a private part).
7972 -- Ada 2005 (AI-391): In the case of an inherited function with
7973 -- a controlling result of the type, the rule does not apply if
7974 -- the type is a null extension (unless the parent function
7975 -- itself is abstract, in which case the function must still be
7976 -- be overridden). The expander will generate an overriding
7977 -- wrapper function calling the parent subprogram (see
7978 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
7980 Type_Def := Type_Definition (Parent (T));
7982 if Nkind (Type_Def) = N_Derived_Type_Definition
7983 and then Present (Record_Extension_Part (Type_Def))
7985 (Ada_Version < Ada_05
7986 or else not Is_Null_Extension (T)
7987 or else Ekind (Subp) = E_Procedure
7988 or else not Has_Controlling_Result (Subp)
7989 or else Is_Abstract_Subprogram (Alias_Subp)
7990 or else Requires_Overriding (Subp)
7991 or else Is_Access_Type (Etype (Subp)))
7993 -- Avoid reporting error in case of abstract predefined
7994 -- primitive inherited from interface type because the
7995 -- body of internally generated predefined primitives
7996 -- of tagged types are generated later by Freeze_Type
7998 if Is_Interface (Root_Type (T))
7999 and then Is_Abstract_Subprogram (Subp)
8000 and then Is_Predefined_Dispatching_Operation (Subp)
8001 and then not Comes_From_Source (Ultimate_Alias (Subp))
8007 ("type must be declared abstract or & overridden",
8010 -- Traverse the whole chain of aliased subprograms to
8011 -- complete the error notification. This is especially
8012 -- useful for traceability of the chain of entities when
8013 -- the subprogram corresponds with an interface
8014 -- subprogram (which may be defined in another package).
8016 if Present (Alias_Subp) then
8022 while Present (Alias (E)) loop
8023 Error_Msg_Sloc := Sloc (E);
8025 ("\& has been inherited #", T, Subp);
8029 Error_Msg_Sloc := Sloc (E);
8031 ("\& has been inherited from subprogram #",
8037 -- Ada 2005 (AI-345): Protected or task type implementing
8038 -- abstract interfaces.
8040 elsif Is_Concurrent_Record_Type (T)
8041 and then Present (Interfaces (T))
8043 -- The controlling formal of Subp must be of mode "out",
8044 -- "in out" or an access-to-variable to be overridden.
8046 -- Error message below needs rewording (remember comma
8047 -- in -gnatj mode) ???
8049 if Ekind (First_Formal (Subp)) = E_In_Parameter then
8050 if not Is_Predefined_Dispatching_Operation (Subp) then
8052 ("first formal of & must be of mode `OUT`, " &
8053 "`IN OUT` or access-to-variable", T, Subp);
8055 ("\to be overridden by protected procedure or " &
8056 "entry (RM 9.4(11.9/2))", T);
8059 -- Some other kind of overriding failure
8063 ("interface subprogram & must be overridden",
8069 Error_Msg_Node_2 := T;
8071 ("abstract subprogram& not allowed for type&", Subp);
8073 -- Also post unconditional warning on the type (unconditional
8074 -- so that if there are more than one of these cases, we get
8075 -- them all, and not just the first one).
8077 Error_Msg_Node_2 := Subp;
8079 ("nonabstract type& has abstract subprogram&!", T);
8083 -- Ada 2005 (AI05-0030): Inspect hidden subprograms which provide
8084 -- the mapping between interface and implementing type primitives.
8085 -- If the interface alias is marked as Implemented_By_Entry, the
8086 -- alias must be an entry wrapper.
8088 if Ada_Version >= Ada_05
8089 and then Is_Hidden (Subp)
8090 and then Present (Interface_Alias (Subp))
8091 and then Implemented_By_Entry (Interface_Alias (Subp))
8092 and then Present (Alias_Subp)
8094 (not Is_Primitive_Wrapper (Alias_Subp)
8095 or else Ekind (Wrapped_Entity (Alias_Subp)) /= E_Entry)
8098 Error_Ent : Entity_Id := T;
8101 if Is_Concurrent_Record_Type (Error_Ent) then
8102 Error_Ent := Corresponding_Concurrent_Type (Error_Ent);
8105 Error_Msg_Node_2 := Interface_Alias (Subp);
8107 ("type & must implement abstract subprogram & with an entry",
8108 Error_Ent, Error_Ent);
8114 end Check_Abstract_Overriding;
8116 ------------------------------------------------
8117 -- Check_Access_Discriminant_Requires_Limited --
8118 ------------------------------------------------
8120 procedure Check_Access_Discriminant_Requires_Limited
8125 -- A discriminant_specification for an access discriminant shall appear
8126 -- only in the declaration for a task or protected type, or for a type
8127 -- with the reserved word 'limited' in its definition or in one of its
8128 -- ancestors. (RM 3.7(10))
8130 if Nkind (Discriminant_Type (D)) = N_Access_Definition
8131 and then not Is_Concurrent_Type (Current_Scope)
8132 and then not Is_Concurrent_Record_Type (Current_Scope)
8133 and then not Is_Limited_Record (Current_Scope)
8134 and then Ekind (Current_Scope) /= E_Limited_Private_Type
8137 ("access discriminants allowed only for limited types", Loc);
8139 end Check_Access_Discriminant_Requires_Limited;
8141 -----------------------------------
8142 -- Check_Aliased_Component_Types --
8143 -----------------------------------
8145 procedure Check_Aliased_Component_Types (T : Entity_Id) is
8149 -- ??? Also need to check components of record extensions, but not
8150 -- components of protected types (which are always limited).
8152 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
8153 -- types to be unconstrained. This is safe because it is illegal to
8154 -- create access subtypes to such types with explicit discriminant
8157 if not Is_Limited_Type (T) then
8158 if Ekind (T) = E_Record_Type then
8159 C := First_Component (T);
8160 while Present (C) loop
8162 and then Has_Discriminants (Etype (C))
8163 and then not Is_Constrained (Etype (C))
8164 and then not In_Instance_Body
8165 and then Ada_Version < Ada_05
8168 ("aliased component must be constrained (RM 3.6(11))",
8175 elsif Ekind (T) = E_Array_Type then
8176 if Has_Aliased_Components (T)
8177 and then Has_Discriminants (Component_Type (T))
8178 and then not Is_Constrained (Component_Type (T))
8179 and then not In_Instance_Body
8180 and then Ada_Version < Ada_05
8183 ("aliased component type must be constrained (RM 3.6(11))",
8188 end Check_Aliased_Component_Types;
8190 ----------------------
8191 -- Check_Completion --
8192 ----------------------
8194 procedure Check_Completion (Body_Id : Node_Id := Empty) is
8197 procedure Post_Error;
8198 -- Post error message for lack of completion for entity E
8204 procedure Post_Error is
8206 if not Comes_From_Source (E) then
8208 if Ekind (E) = E_Task_Type
8209 or else Ekind (E) = E_Protected_Type
8211 -- It may be an anonymous protected type created for a
8212 -- single variable. Post error on variable, if present.
8218 Var := First_Entity (Current_Scope);
8219 while Present (Var) loop
8220 exit when Etype (Var) = E
8221 and then Comes_From_Source (Var);
8226 if Present (Var) then
8233 -- If a generated entity has no completion, then either previous
8234 -- semantic errors have disabled the expansion phase, or else we had
8235 -- missing subunits, or else we are compiling without expansion,
8236 -- or else something is very wrong.
8238 if not Comes_From_Source (E) then
8240 (Serious_Errors_Detected > 0
8241 or else Configurable_Run_Time_Violations > 0
8242 or else Subunits_Missing
8243 or else not Expander_Active);
8246 -- Here for source entity
8249 -- Here if no body to post the error message, so we post the error
8250 -- on the declaration that has no completion. This is not really
8251 -- the right place to post it, think about this later ???
8253 if No (Body_Id) then
8256 ("missing full declaration for }", Parent (E), E);
8259 ("missing body for &", Parent (E), E);
8262 -- Package body has no completion for a declaration that appears
8263 -- in the corresponding spec. Post error on the body, with a
8264 -- reference to the non-completed declaration.
8267 Error_Msg_Sloc := Sloc (E);
8271 ("missing full declaration for }!", Body_Id, E);
8273 elsif Is_Overloadable (E)
8274 and then Current_Entity_In_Scope (E) /= E
8276 -- It may be that the completion is mistyped and appears as
8277 -- a distinct overloading of the entity.
8280 Candidate : constant Entity_Id :=
8281 Current_Entity_In_Scope (E);
8282 Decl : constant Node_Id :=
8283 Unit_Declaration_Node (Candidate);
8286 if Is_Overloadable (Candidate)
8287 and then Ekind (Candidate) = Ekind (E)
8288 and then Nkind (Decl) = N_Subprogram_Body
8289 and then Acts_As_Spec (Decl)
8291 Check_Type_Conformant (Candidate, E);
8294 Error_Msg_NE ("missing body for & declared#!",
8299 Error_Msg_NE ("missing body for & declared#!",
8306 -- Start processing for Check_Completion
8309 E := First_Entity (Current_Scope);
8310 while Present (E) loop
8311 if Is_Intrinsic_Subprogram (E) then
8314 -- The following situation requires special handling: a child unit
8315 -- that appears in the context clause of the body of its parent:
8317 -- procedure Parent.Child (...);
8319 -- with Parent.Child;
8320 -- package body Parent is
8322 -- Here Parent.Child appears as a local entity, but should not be
8323 -- flagged as requiring completion, because it is a compilation
8326 -- Ignore missing completion for a subprogram that does not come from
8327 -- source (including the _Call primitive operation of RAS types,
8328 -- which has to have the flag Comes_From_Source for other purposes):
8329 -- we assume that the expander will provide the missing completion.
8331 elsif Ekind (E) = E_Function
8332 or else Ekind (E) = E_Procedure
8333 or else Ekind (E) = E_Generic_Function
8334 or else Ekind (E) = E_Generic_Procedure
8336 if not Has_Completion (E)
8337 and then not (Is_Subprogram (E)
8338 and then Is_Abstract_Subprogram (E))
8339 and then not (Is_Subprogram (E)
8341 (not Comes_From_Source (E)
8342 or else Chars (E) = Name_uCall))
8343 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8345 and then Chars (E) /= Name_uSize
8350 elsif Is_Entry (E) then
8351 if not Has_Completion (E) and then
8352 (Ekind (Scope (E)) = E_Protected_Object
8353 or else Ekind (Scope (E)) = E_Protected_Type)
8358 elsif Is_Package_Or_Generic_Package (E) then
8359 if Unit_Requires_Body (E) then
8360 if not Has_Completion (E)
8361 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8367 elsif not Is_Child_Unit (E) then
8368 May_Need_Implicit_Body (E);
8371 elsif Ekind (E) = E_Incomplete_Type
8372 and then No (Underlying_Type (E))
8376 elsif (Ekind (E) = E_Task_Type or else
8377 Ekind (E) = E_Protected_Type)
8378 and then not Has_Completion (E)
8382 -- A single task declared in the current scope is a constant, verify
8383 -- that the body of its anonymous type is in the same scope. If the
8384 -- task is defined elsewhere, this may be a renaming declaration for
8385 -- which no completion is needed.
8387 elsif Ekind (E) = E_Constant
8388 and then Ekind (Etype (E)) = E_Task_Type
8389 and then not Has_Completion (Etype (E))
8390 and then Scope (Etype (E)) = Current_Scope
8394 elsif Ekind (E) = E_Protected_Object
8395 and then not Has_Completion (Etype (E))
8399 elsif Ekind (E) = E_Record_Type then
8400 if Is_Tagged_Type (E) then
8401 Check_Abstract_Overriding (E);
8402 Check_Conventions (E);
8405 Check_Aliased_Component_Types (E);
8407 elsif Ekind (E) = E_Array_Type then
8408 Check_Aliased_Component_Types (E);
8414 end Check_Completion;
8416 ----------------------------
8417 -- Check_Delta_Expression --
8418 ----------------------------
8420 procedure Check_Delta_Expression (E : Node_Id) is
8422 if not (Is_Real_Type (Etype (E))) then
8423 Wrong_Type (E, Any_Real);
8425 elsif not Is_OK_Static_Expression (E) then
8426 Flag_Non_Static_Expr
8427 ("non-static expression used for delta value!", E);
8429 elsif not UR_Is_Positive (Expr_Value_R (E)) then
8430 Error_Msg_N ("delta expression must be positive", E);
8436 -- If any of above errors occurred, then replace the incorrect
8437 -- expression by the real 0.1, which should prevent further errors.
8440 Make_Real_Literal (Sloc (E), Ureal_Tenth));
8441 Analyze_And_Resolve (E, Standard_Float);
8442 end Check_Delta_Expression;
8444 -----------------------------
8445 -- Check_Digits_Expression --
8446 -----------------------------
8448 procedure Check_Digits_Expression (E : Node_Id) is
8450 if not (Is_Integer_Type (Etype (E))) then
8451 Wrong_Type (E, Any_Integer);
8453 elsif not Is_OK_Static_Expression (E) then
8454 Flag_Non_Static_Expr
8455 ("non-static expression used for digits value!", E);
8457 elsif Expr_Value (E) <= 0 then
8458 Error_Msg_N ("digits value must be greater than zero", E);
8464 -- If any of above errors occurred, then replace the incorrect
8465 -- expression by the integer 1, which should prevent further errors.
8467 Rewrite (E, Make_Integer_Literal (Sloc (E), 1));
8468 Analyze_And_Resolve (E, Standard_Integer);
8470 end Check_Digits_Expression;
8472 --------------------------
8473 -- Check_Initialization --
8474 --------------------------
8476 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id) is
8478 if Is_Limited_Type (T)
8479 and then not In_Instance
8480 and then not In_Inlined_Body
8482 if not OK_For_Limited_Init (Exp) then
8484 -- In GNAT mode, this is just a warning, to allow it to be evilly
8485 -- turned off. Otherwise it is a real error.
8489 ("?cannot initialize entities of limited type!", Exp);
8491 elsif Ada_Version < Ada_05 then
8493 ("cannot initialize entities of limited type", Exp);
8494 Explain_Limited_Type (T, Exp);
8497 -- Specialize error message according to kind of illegal
8498 -- initial expression.
8500 if Nkind (Exp) = N_Type_Conversion
8501 and then Nkind (Expression (Exp)) = N_Function_Call
8504 ("illegal context for call"
8505 & " to function with limited result", Exp);
8509 ("initialization of limited object requires aggregate "
8510 & "or function call", Exp);
8515 end Check_Initialization;
8517 ----------------------
8518 -- Check_Interfaces --
8519 ----------------------
8521 procedure Check_Interfaces (N : Node_Id; Def : Node_Id) is
8522 Parent_Type : constant Entity_Id := Etype (Defining_Identifier (N));
8525 Iface_Def : Node_Id;
8526 Iface_Typ : Entity_Id;
8527 Parent_Node : Node_Id;
8529 Is_Task : Boolean := False;
8530 -- Set True if parent type or any progenitor is a task interface
8532 Is_Protected : Boolean := False;
8533 -- Set True if parent type or any progenitor is a protected interface
8535 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id);
8536 -- Check that a progenitor is compatible with declaration.
8537 -- Error is posted on Error_Node.
8543 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id) is
8544 Iface_Id : constant Entity_Id :=
8545 Defining_Identifier (Parent (Iface_Def));
8549 if Nkind (N) = N_Private_Extension_Declaration then
8552 Type_Def := Type_Definition (N);
8555 if Is_Task_Interface (Iface_Id) then
8558 elsif Is_Protected_Interface (Iface_Id) then
8559 Is_Protected := True;
8562 -- Check that the characteristics of the progenitor are compatible
8563 -- with the explicit qualifier in the declaration.
8564 -- The check only applies to qualifiers that come from source.
8565 -- Limited_Present also appears in the declaration of corresponding
8566 -- records, and the check does not apply to them.
8568 if Limited_Present (Type_Def)
8570 Is_Concurrent_Record_Type (Defining_Identifier (N))
8572 if Is_Limited_Interface (Parent_Type)
8573 and then not Is_Limited_Interface (Iface_Id)
8576 ("progenitor& must be limited interface",
8577 Error_Node, Iface_Id);
8580 (Task_Present (Iface_Def)
8581 or else Protected_Present (Iface_Def)
8582 or else Synchronized_Present (Iface_Def))
8583 and then Nkind (N) /= N_Private_Extension_Declaration
8586 ("progenitor& must be limited interface",
8587 Error_Node, Iface_Id);
8590 -- Protected interfaces can only inherit from limited, synchronized
8591 -- or protected interfaces.
8593 elsif Nkind (N) = N_Full_Type_Declaration
8594 and then Protected_Present (Type_Def)
8596 if Limited_Present (Iface_Def)
8597 or else Synchronized_Present (Iface_Def)
8598 or else Protected_Present (Iface_Def)
8602 elsif Task_Present (Iface_Def) then
8603 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
8604 & " from task interface", Error_Node);
8607 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
8608 & " from non-limited interface", Error_Node);
8611 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
8612 -- limited and synchronized.
8614 elsif Synchronized_Present (Type_Def) then
8615 if Limited_Present (Iface_Def)
8616 or else Synchronized_Present (Iface_Def)
8620 elsif Protected_Present (Iface_Def)
8621 and then Nkind (N) /= N_Private_Extension_Declaration
8623 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8624 & " from protected interface", Error_Node);
8626 elsif Task_Present (Iface_Def)
8627 and then Nkind (N) /= N_Private_Extension_Declaration
8629 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8630 & " from task interface", Error_Node);
8632 elsif not Is_Limited_Interface (Iface_Id) then
8633 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8634 & " from non-limited interface", Error_Node);
8637 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
8638 -- synchronized or task interfaces.
8640 elsif Nkind (N) = N_Full_Type_Declaration
8641 and then Task_Present (Type_Def)
8643 if Limited_Present (Iface_Def)
8644 or else Synchronized_Present (Iface_Def)
8645 or else Task_Present (Iface_Def)
8649 elsif Protected_Present (Iface_Def) then
8650 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
8651 & " protected interface", Error_Node);
8654 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
8655 & " non-limited interface", Error_Node);
8660 -- Start of processing for Check_Interfaces
8663 if Is_Interface (Parent_Type) then
8664 if Is_Task_Interface (Parent_Type) then
8667 elsif Is_Protected_Interface (Parent_Type) then
8668 Is_Protected := True;
8672 if Nkind (N) = N_Private_Extension_Declaration then
8674 -- Check that progenitors are compatible with declaration
8676 Iface := First (Interface_List (Def));
8677 while Present (Iface) loop
8678 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8680 Parent_Node := Parent (Base_Type (Iface_Typ));
8681 Iface_Def := Type_Definition (Parent_Node);
8683 if not Is_Interface (Iface_Typ) then
8684 Diagnose_Interface (Iface, Iface_Typ);
8687 Check_Ifaces (Iface_Def, Iface);
8693 if Is_Task and Is_Protected then
8695 ("type cannot derive from task and protected interface", N);
8701 -- Full type declaration of derived type.
8702 -- Check compatibility with parent if it is interface type
8704 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition
8705 and then Is_Interface (Parent_Type)
8707 Parent_Node := Parent (Parent_Type);
8709 -- More detailed checks for interface varieties
8712 (Iface_Def => Type_Definition (Parent_Node),
8713 Error_Node => Subtype_Indication (Type_Definition (N)));
8716 Iface := First (Interface_List (Def));
8717 while Present (Iface) loop
8718 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8720 Parent_Node := Parent (Base_Type (Iface_Typ));
8721 Iface_Def := Type_Definition (Parent_Node);
8723 if not Is_Interface (Iface_Typ) then
8724 Diagnose_Interface (Iface, Iface_Typ);
8727 -- "The declaration of a specific descendant of an interface
8728 -- type freezes the interface type" RM 13.14
8730 Freeze_Before (N, Iface_Typ);
8731 Check_Ifaces (Iface_Def, Error_Node => Iface);
8737 if Is_Task and Is_Protected then
8739 ("type cannot derive from task and protected interface", N);
8741 end Check_Interfaces;
8743 ------------------------------------
8744 -- Check_Or_Process_Discriminants --
8745 ------------------------------------
8747 -- If an incomplete or private type declaration was already given for the
8748 -- type, the discriminants may have already been processed if they were
8749 -- present on the incomplete declaration. In this case a full conformance
8750 -- check is performed otherwise just process them.
8752 procedure Check_Or_Process_Discriminants
8755 Prev : Entity_Id := Empty)
8758 if Has_Discriminants (T) then
8760 -- Make the discriminants visible to component declarations
8767 D := First_Discriminant (T);
8768 while Present (D) loop
8769 Prev := Current_Entity (D);
8770 Set_Current_Entity (D);
8771 Set_Is_Immediately_Visible (D);
8772 Set_Homonym (D, Prev);
8774 -- Ada 2005 (AI-230): Access discriminant allowed in
8775 -- non-limited record types.
8777 if Ada_Version < Ada_05 then
8779 -- This restriction gets applied to the full type here. It
8780 -- has already been applied earlier to the partial view.
8782 Check_Access_Discriminant_Requires_Limited (Parent (D), N);
8785 Next_Discriminant (D);
8789 elsif Present (Discriminant_Specifications (N)) then
8790 Process_Discriminants (N, Prev);
8792 end Check_Or_Process_Discriminants;
8794 ----------------------
8795 -- Check_Real_Bound --
8796 ----------------------
8798 procedure Check_Real_Bound (Bound : Node_Id) is
8800 if not Is_Real_Type (Etype (Bound)) then
8802 ("bound in real type definition must be of real type", Bound);
8804 elsif not Is_OK_Static_Expression (Bound) then
8805 Flag_Non_Static_Expr
8806 ("non-static expression used for real type bound!", Bound);
8813 (Bound, Make_Real_Literal (Sloc (Bound), Ureal_0));
8815 Resolve (Bound, Standard_Float);
8816 end Check_Real_Bound;
8818 ------------------------------
8819 -- Complete_Private_Subtype --
8820 ------------------------------
8822 procedure Complete_Private_Subtype
8825 Full_Base : Entity_Id;
8826 Related_Nod : Node_Id)
8828 Save_Next_Entity : Entity_Id;
8829 Save_Homonym : Entity_Id;
8832 -- Set semantic attributes for (implicit) private subtype completion.
8833 -- If the full type has no discriminants, then it is a copy of the full
8834 -- view of the base. Otherwise, it is a subtype of the base with a
8835 -- possible discriminant constraint. Save and restore the original
8836 -- Next_Entity field of full to ensure that the calls to Copy_Node
8837 -- do not corrupt the entity chain.
8839 -- Note that the type of the full view is the same entity as the type of
8840 -- the partial view. In this fashion, the subtype has access to the
8841 -- correct view of the parent.
8843 Save_Next_Entity := Next_Entity (Full);
8844 Save_Homonym := Homonym (Priv);
8846 case Ekind (Full_Base) is
8847 when E_Record_Type |
8853 Copy_Node (Priv, Full);
8855 Set_Has_Discriminants (Full, Has_Discriminants (Full_Base));
8856 Set_First_Entity (Full, First_Entity (Full_Base));
8857 Set_Last_Entity (Full, Last_Entity (Full_Base));
8860 Copy_Node (Full_Base, Full);
8861 Set_Chars (Full, Chars (Priv));
8862 Conditional_Delay (Full, Priv);
8863 Set_Sloc (Full, Sloc (Priv));
8866 Set_Next_Entity (Full, Save_Next_Entity);
8867 Set_Homonym (Full, Save_Homonym);
8868 Set_Associated_Node_For_Itype (Full, Related_Nod);
8870 -- Set common attributes for all subtypes
8872 Set_Ekind (Full, Subtype_Kind (Ekind (Full_Base)));
8874 -- The Etype of the full view is inconsistent. Gigi needs to see the
8875 -- structural full view, which is what the current scheme gives:
8876 -- the Etype of the full view is the etype of the full base. However,
8877 -- if the full base is a derived type, the full view then looks like
8878 -- a subtype of the parent, not a subtype of the full base. If instead
8881 -- Set_Etype (Full, Full_Base);
8883 -- then we get inconsistencies in the front-end (confusion between
8884 -- views). Several outstanding bugs are related to this ???
8886 Set_Is_First_Subtype (Full, False);
8887 Set_Scope (Full, Scope (Priv));
8888 Set_Size_Info (Full, Full_Base);
8889 Set_RM_Size (Full, RM_Size (Full_Base));
8890 Set_Is_Itype (Full);
8892 -- A subtype of a private-type-without-discriminants, whose full-view
8893 -- has discriminants with default expressions, is not constrained!
8895 if not Has_Discriminants (Priv) then
8896 Set_Is_Constrained (Full, Is_Constrained (Full_Base));
8898 if Has_Discriminants (Full_Base) then
8899 Set_Discriminant_Constraint
8900 (Full, Discriminant_Constraint (Full_Base));
8902 -- The partial view may have been indefinite, the full view
8905 Set_Has_Unknown_Discriminants
8906 (Full, Has_Unknown_Discriminants (Full_Base));
8910 Set_First_Rep_Item (Full, First_Rep_Item (Full_Base));
8911 Set_Depends_On_Private (Full, Has_Private_Component (Full));
8913 -- Freeze the private subtype entity if its parent is delayed, and not
8914 -- already frozen. We skip this processing if the type is an anonymous
8915 -- subtype of a record component, or is the corresponding record of a
8916 -- protected type, since ???
8918 if not Is_Type (Scope (Full)) then
8919 Set_Has_Delayed_Freeze (Full,
8920 Has_Delayed_Freeze (Full_Base)
8921 and then (not Is_Frozen (Full_Base)));
8924 Set_Freeze_Node (Full, Empty);
8925 Set_Is_Frozen (Full, False);
8926 Set_Full_View (Priv, Full);
8928 if Has_Discriminants (Full) then
8929 Set_Stored_Constraint_From_Discriminant_Constraint (Full);
8930 Set_Stored_Constraint (Priv, Stored_Constraint (Full));
8932 if Has_Unknown_Discriminants (Full) then
8933 Set_Discriminant_Constraint (Full, No_Elist);
8937 if Ekind (Full_Base) = E_Record_Type
8938 and then Has_Discriminants (Full_Base)
8939 and then Has_Discriminants (Priv) -- might not, if errors
8940 and then not Has_Unknown_Discriminants (Priv)
8941 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Priv))
8943 Create_Constrained_Components
8944 (Full, Related_Nod, Full_Base, Discriminant_Constraint (Priv));
8946 -- If the full base is itself derived from private, build a congruent
8947 -- subtype of its underlying type, for use by the back end. For a
8948 -- constrained record component, the declaration cannot be placed on
8949 -- the component list, but it must nevertheless be built an analyzed, to
8950 -- supply enough information for Gigi to compute the size of component.
8952 elsif Ekind (Full_Base) in Private_Kind
8953 and then Is_Derived_Type (Full_Base)
8954 and then Has_Discriminants (Full_Base)
8955 and then (Ekind (Current_Scope) /= E_Record_Subtype)
8957 if not Is_Itype (Priv)
8959 Nkind (Subtype_Indication (Parent (Priv))) = N_Subtype_Indication
8961 Build_Underlying_Full_View
8962 (Parent (Priv), Full, Etype (Full_Base));
8964 elsif Nkind (Related_Nod) = N_Component_Declaration then
8965 Build_Underlying_Full_View (Related_Nod, Full, Etype (Full_Base));
8968 elsif Is_Record_Type (Full_Base) then
8970 -- Show Full is simply a renaming of Full_Base
8972 Set_Cloned_Subtype (Full, Full_Base);
8975 -- It is unsafe to share to bounds of a scalar type, because the Itype
8976 -- is elaborated on demand, and if a bound is non-static then different
8977 -- orders of elaboration in different units will lead to different
8978 -- external symbols.
8980 if Is_Scalar_Type (Full_Base) then
8981 Set_Scalar_Range (Full,
8982 Make_Range (Sloc (Related_Nod),
8984 Duplicate_Subexpr_No_Checks (Type_Low_Bound (Full_Base)),
8986 Duplicate_Subexpr_No_Checks (Type_High_Bound (Full_Base))));
8988 -- This completion inherits the bounds of the full parent, but if
8989 -- the parent is an unconstrained floating point type, so is the
8992 if Is_Floating_Point_Type (Full_Base) then
8993 Set_Includes_Infinities
8994 (Scalar_Range (Full), Has_Infinities (Full_Base));
8998 -- ??? It seems that a lot of fields are missing that should be copied
8999 -- from Full_Base to Full. Here are some that are introduced in a
9000 -- non-disruptive way but a cleanup is necessary.
9002 if Is_Tagged_Type (Full_Base) then
9003 Set_Is_Tagged_Type (Full);
9004 Set_Primitive_Operations (Full, Primitive_Operations (Full_Base));
9005 Set_Class_Wide_Type (Full, Class_Wide_Type (Full_Base));
9007 -- If this is a subtype of a protected or task type, constrain its
9008 -- corresponding record, unless this is a subtype without constraints,
9009 -- i.e. a simple renaming as with an actual subtype in an instance.
9011 elsif Is_Concurrent_Type (Full_Base) then
9012 if Has_Discriminants (Full)
9013 and then Present (Corresponding_Record_Type (Full_Base))
9015 not Is_Empty_Elmt_List (Discriminant_Constraint (Full))
9017 Set_Corresponding_Record_Type (Full,
9018 Constrain_Corresponding_Record
9019 (Full, Corresponding_Record_Type (Full_Base),
9020 Related_Nod, Full_Base));
9023 Set_Corresponding_Record_Type (Full,
9024 Corresponding_Record_Type (Full_Base));
9027 end Complete_Private_Subtype;
9029 ----------------------------
9030 -- Constant_Redeclaration --
9031 ----------------------------
9033 procedure Constant_Redeclaration
9038 Prev : constant Entity_Id := Current_Entity_In_Scope (Id);
9039 Obj_Def : constant Node_Id := Object_Definition (N);
9042 procedure Check_Possible_Deferred_Completion
9043 (Prev_Id : Entity_Id;
9044 Prev_Obj_Def : Node_Id;
9045 Curr_Obj_Def : Node_Id);
9046 -- Determine whether the two object definitions describe the partial
9047 -- and the full view of a constrained deferred constant. Generate
9048 -- a subtype for the full view and verify that it statically matches
9049 -- the subtype of the partial view.
9051 procedure Check_Recursive_Declaration (Typ : Entity_Id);
9052 -- If deferred constant is an access type initialized with an allocator,
9053 -- check whether there is an illegal recursion in the definition,
9054 -- through a default value of some record subcomponent. This is normally
9055 -- detected when generating init procs, but requires this additional
9056 -- mechanism when expansion is disabled.
9058 ----------------------------------------
9059 -- Check_Possible_Deferred_Completion --
9060 ----------------------------------------
9062 procedure Check_Possible_Deferred_Completion
9063 (Prev_Id : Entity_Id;
9064 Prev_Obj_Def : Node_Id;
9065 Curr_Obj_Def : Node_Id)
9068 if Nkind (Prev_Obj_Def) = N_Subtype_Indication
9069 and then Present (Constraint (Prev_Obj_Def))
9070 and then Nkind (Curr_Obj_Def) = N_Subtype_Indication
9071 and then Present (Constraint (Curr_Obj_Def))
9074 Loc : constant Source_Ptr := Sloc (N);
9075 Def_Id : constant Entity_Id :=
9076 Make_Defining_Identifier (Loc,
9077 New_Internal_Name ('S'));
9078 Decl : constant Node_Id :=
9079 Make_Subtype_Declaration (Loc,
9080 Defining_Identifier =>
9082 Subtype_Indication =>
9083 Relocate_Node (Curr_Obj_Def));
9086 Insert_Before_And_Analyze (N, Decl);
9087 Set_Etype (Id, Def_Id);
9089 if not Subtypes_Statically_Match (Etype (Prev_Id), Def_Id) then
9090 Error_Msg_Sloc := Sloc (Prev_Id);
9091 Error_Msg_N ("subtype does not statically match deferred " &
9096 end Check_Possible_Deferred_Completion;
9098 ---------------------------------
9099 -- Check_Recursive_Declaration --
9100 ---------------------------------
9102 procedure Check_Recursive_Declaration (Typ : Entity_Id) is
9106 if Is_Record_Type (Typ) then
9107 Comp := First_Component (Typ);
9108 while Present (Comp) loop
9109 if Comes_From_Source (Comp) then
9110 if Present (Expression (Parent (Comp)))
9111 and then Is_Entity_Name (Expression (Parent (Comp)))
9112 and then Entity (Expression (Parent (Comp))) = Prev
9114 Error_Msg_Sloc := Sloc (Parent (Comp));
9116 ("illegal circularity with declaration for&#",
9120 elsif Is_Record_Type (Etype (Comp)) then
9121 Check_Recursive_Declaration (Etype (Comp));
9125 Next_Component (Comp);
9128 end Check_Recursive_Declaration;
9130 -- Start of processing for Constant_Redeclaration
9133 if Nkind (Parent (Prev)) = N_Object_Declaration then
9134 if Nkind (Object_Definition
9135 (Parent (Prev))) = N_Subtype_Indication
9137 -- Find type of new declaration. The constraints of the two
9138 -- views must match statically, but there is no point in
9139 -- creating an itype for the full view.
9141 if Nkind (Obj_Def) = N_Subtype_Indication then
9142 Find_Type (Subtype_Mark (Obj_Def));
9143 New_T := Entity (Subtype_Mark (Obj_Def));
9146 Find_Type (Obj_Def);
9147 New_T := Entity (Obj_Def);
9153 -- The full view may impose a constraint, even if the partial
9154 -- view does not, so construct the subtype.
9156 New_T := Find_Type_Of_Object (Obj_Def, N);
9161 -- Current declaration is illegal, diagnosed below in Enter_Name
9167 -- If previous full declaration exists, or if a homograph is present,
9168 -- let Enter_Name handle it, either with an error, or with the removal
9169 -- of an overridden implicit subprogram.
9171 if Ekind (Prev) /= E_Constant
9172 or else Present (Expression (Parent (Prev)))
9173 or else Present (Full_View (Prev))
9177 -- Verify that types of both declarations match, or else that both types
9178 -- are anonymous access types whose designated subtypes statically match
9179 -- (as allowed in Ada 2005 by AI-385).
9181 elsif Base_Type (Etype (Prev)) /= Base_Type (New_T)
9183 (Ekind (Etype (Prev)) /= E_Anonymous_Access_Type
9184 or else Ekind (Etype (New_T)) /= E_Anonymous_Access_Type
9185 or else Is_Access_Constant (Etype (New_T)) /=
9186 Is_Access_Constant (Etype (Prev))
9187 or else Can_Never_Be_Null (Etype (New_T)) /=
9188 Can_Never_Be_Null (Etype (Prev))
9189 or else Null_Exclusion_Present (Parent (Prev)) /=
9190 Null_Exclusion_Present (Parent (Id))
9191 or else not Subtypes_Statically_Match
9192 (Designated_Type (Etype (Prev)),
9193 Designated_Type (Etype (New_T))))
9195 Error_Msg_Sloc := Sloc (Prev);
9196 Error_Msg_N ("type does not match declaration#", N);
9197 Set_Full_View (Prev, Id);
9198 Set_Etype (Id, Any_Type);
9201 Null_Exclusion_Present (Parent (Prev))
9202 and then not Null_Exclusion_Present (N)
9204 Error_Msg_Sloc := Sloc (Prev);
9205 Error_Msg_N ("null-exclusion does not match declaration#", N);
9206 Set_Full_View (Prev, Id);
9207 Set_Etype (Id, Any_Type);
9209 -- If so, process the full constant declaration
9212 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
9213 -- the deferred declaration is constrained, then the subtype defined
9214 -- by the subtype_indication in the full declaration shall match it
9217 Check_Possible_Deferred_Completion
9219 Prev_Obj_Def => Object_Definition (Parent (Prev)),
9220 Curr_Obj_Def => Obj_Def);
9222 Set_Full_View (Prev, Id);
9223 Set_Is_Public (Id, Is_Public (Prev));
9224 Set_Is_Internal (Id);
9225 Append_Entity (Id, Current_Scope);
9227 -- Check ALIASED present if present before (RM 7.4(7))
9229 if Is_Aliased (Prev)
9230 and then not Aliased_Present (N)
9232 Error_Msg_Sloc := Sloc (Prev);
9233 Error_Msg_N ("ALIASED required (see declaration#)", N);
9236 -- Allow incomplete declaration of tags (used to handle forward
9237 -- references to tags). The check on Ada_Tags avoids circularities
9238 -- when rebuilding the compiler.
9240 if RTU_Loaded (Ada_Tags)
9241 and then T = RTE (RE_Tag)
9245 -- Check that placement is in private part and that the incomplete
9246 -- declaration appeared in the visible part.
9248 elsif Ekind (Current_Scope) = E_Package
9249 and then not In_Private_Part (Current_Scope)
9251 Error_Msg_Sloc := Sloc (Prev);
9252 Error_Msg_N ("full constant for declaration#"
9253 & " must be in private part", N);
9255 elsif Ekind (Current_Scope) = E_Package
9256 and then List_Containing (Parent (Prev))
9257 /= Visible_Declarations
9258 (Specification (Unit_Declaration_Node (Current_Scope)))
9261 ("deferred constant must be declared in visible part",
9265 if Is_Access_Type (T)
9266 and then Nkind (Expression (N)) = N_Allocator
9268 Check_Recursive_Declaration (Designated_Type (T));
9271 end Constant_Redeclaration;
9273 ----------------------
9274 -- Constrain_Access --
9275 ----------------------
9277 procedure Constrain_Access
9278 (Def_Id : in out Entity_Id;
9280 Related_Nod : Node_Id)
9282 T : constant Entity_Id := Entity (Subtype_Mark (S));
9283 Desig_Type : constant Entity_Id := Designated_Type (T);
9284 Desig_Subtype : Entity_Id := Create_Itype (E_Void, Related_Nod);
9285 Constraint_OK : Boolean := True;
9287 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean;
9288 -- Simple predicate to test for defaulted discriminants
9289 -- Shouldn't this be in sem_util???
9291 ---------------------------------
9292 -- Has_Defaulted_Discriminants --
9293 ---------------------------------
9295 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
9297 return Has_Discriminants (Typ)
9298 and then Present (First_Discriminant (Typ))
9300 (Discriminant_Default_Value (First_Discriminant (Typ)));
9301 end Has_Defaulted_Discriminants;
9303 -- Start of processing for Constrain_Access
9306 if Is_Array_Type (Desig_Type) then
9307 Constrain_Array (Desig_Subtype, S, Related_Nod, Def_Id, 'P');
9309 elsif (Is_Record_Type (Desig_Type)
9310 or else Is_Incomplete_Or_Private_Type (Desig_Type))
9311 and then not Is_Constrained (Desig_Type)
9313 -- ??? The following code is a temporary kludge to ignore a
9314 -- discriminant constraint on access type if it is constraining
9315 -- the current record. Avoid creating the implicit subtype of the
9316 -- record we are currently compiling since right now, we cannot
9317 -- handle these. For now, just return the access type itself.
9319 if Desig_Type = Current_Scope
9320 and then No (Def_Id)
9322 Set_Ekind (Desig_Subtype, E_Record_Subtype);
9323 Def_Id := Entity (Subtype_Mark (S));
9325 -- This call added to ensure that the constraint is analyzed
9326 -- (needed for a B test). Note that we still return early from
9327 -- this procedure to avoid recursive processing. ???
9329 Constrain_Discriminated_Type
9330 (Desig_Subtype, S, Related_Nod, For_Access => True);
9334 if (Ekind (T) = E_General_Access_Type
9335 or else Ada_Version >= Ada_05)
9336 and then Has_Private_Declaration (Desig_Type)
9337 and then In_Open_Scopes (Scope (Desig_Type))
9338 and then Has_Discriminants (Desig_Type)
9340 -- Enforce rule that the constraint is illegal if there is
9341 -- an unconstrained view of the designated type. This means
9342 -- that the partial view (either a private type declaration or
9343 -- a derivation from a private type) has no discriminants.
9344 -- (Defect Report 8652/0008, Technical Corrigendum 1, checked
9345 -- by ACATS B371001).
9347 -- Rule updated for Ada 2005: the private type is said to have
9348 -- a constrained partial view, given that objects of the type
9349 -- can be declared. Furthermore, the rule applies to all access
9350 -- types, unlike the rule concerning default discriminants.
9353 Pack : constant Node_Id :=
9354 Unit_Declaration_Node (Scope (Desig_Type));
9359 if Nkind (Pack) = N_Package_Declaration then
9360 Decls := Visible_Declarations (Specification (Pack));
9361 Decl := First (Decls);
9362 while Present (Decl) loop
9363 if (Nkind (Decl) = N_Private_Type_Declaration
9365 Chars (Defining_Identifier (Decl)) =
9369 (Nkind (Decl) = N_Full_Type_Declaration
9371 Chars (Defining_Identifier (Decl)) =
9373 and then Is_Derived_Type (Desig_Type)
9375 Has_Private_Declaration (Etype (Desig_Type)))
9377 if No (Discriminant_Specifications (Decl)) then
9379 ("cannot constrain general access type if " &
9380 "designated type has constrained partial view",
9393 Constrain_Discriminated_Type (Desig_Subtype, S, Related_Nod,
9394 For_Access => True);
9396 elsif (Is_Task_Type (Desig_Type)
9397 or else Is_Protected_Type (Desig_Type))
9398 and then not Is_Constrained (Desig_Type)
9400 Constrain_Concurrent
9401 (Desig_Subtype, S, Related_Nod, Desig_Type, ' ');
9404 Error_Msg_N ("invalid constraint on access type", S);
9405 Desig_Subtype := Desig_Type; -- Ignore invalid constraint.
9406 Constraint_OK := False;
9410 Def_Id := Create_Itype (E_Access_Subtype, Related_Nod);
9412 Set_Ekind (Def_Id, E_Access_Subtype);
9415 if Constraint_OK then
9416 Set_Etype (Def_Id, Base_Type (T));
9418 if Is_Private_Type (Desig_Type) then
9419 Prepare_Private_Subtype_Completion (Desig_Subtype, Related_Nod);
9422 Set_Etype (Def_Id, Any_Type);
9425 Set_Size_Info (Def_Id, T);
9426 Set_Is_Constrained (Def_Id, Constraint_OK);
9427 Set_Directly_Designated_Type (Def_Id, Desig_Subtype);
9428 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9429 Set_Is_Access_Constant (Def_Id, Is_Access_Constant (T));
9431 Conditional_Delay (Def_Id, T);
9433 -- AI-363 : Subtypes of general access types whose designated types have
9434 -- default discriminants are disallowed. In instances, the rule has to
9435 -- be checked against the actual, of which T is the subtype. In a
9436 -- generic body, the rule is checked assuming that the actual type has
9437 -- defaulted discriminants.
9439 if Ada_Version >= Ada_05 or else Warn_On_Ada_2005_Compatibility then
9440 if Ekind (Base_Type (T)) = E_General_Access_Type
9441 and then Has_Defaulted_Discriminants (Desig_Type)
9443 if Ada_Version < Ada_05 then
9445 ("access subtype of general access type would not " &
9446 "be allowed in Ada 2005?", S);
9449 ("access subype of general access type not allowed", S);
9452 Error_Msg_N ("\discriminants have defaults", S);
9454 elsif Is_Access_Type (T)
9455 and then Is_Generic_Type (Desig_Type)
9456 and then Has_Discriminants (Desig_Type)
9457 and then In_Package_Body (Current_Scope)
9459 if Ada_Version < Ada_05 then
9461 ("access subtype would not be allowed in generic body " &
9465 ("access subtype not allowed in generic body", S);
9469 ("\designated type is a discriminated formal", S);
9472 end Constrain_Access;
9474 ---------------------
9475 -- Constrain_Array --
9476 ---------------------
9478 procedure Constrain_Array
9479 (Def_Id : in out Entity_Id;
9481 Related_Nod : Node_Id;
9482 Related_Id : Entity_Id;
9485 C : constant Node_Id := Constraint (SI);
9486 Number_Of_Constraints : Nat := 0;
9489 Constraint_OK : Boolean := True;
9492 T := Entity (Subtype_Mark (SI));
9494 if Ekind (T) in Access_Kind then
9495 T := Designated_Type (T);
9498 -- If an index constraint follows a subtype mark in a subtype indication
9499 -- then the type or subtype denoted by the subtype mark must not already
9500 -- impose an index constraint. The subtype mark must denote either an
9501 -- unconstrained array type or an access type whose designated type
9502 -- is such an array type... (RM 3.6.1)
9504 if Is_Constrained (T) then
9506 ("array type is already constrained", Subtype_Mark (SI));
9507 Constraint_OK := False;
9510 S := First (Constraints (C));
9511 while Present (S) loop
9512 Number_Of_Constraints := Number_Of_Constraints + 1;
9516 -- In either case, the index constraint must provide a discrete
9517 -- range for each index of the array type and the type of each
9518 -- discrete range must be the same as that of the corresponding
9519 -- index. (RM 3.6.1)
9521 if Number_Of_Constraints /= Number_Dimensions (T) then
9522 Error_Msg_NE ("incorrect number of index constraints for }", C, T);
9523 Constraint_OK := False;
9526 S := First (Constraints (C));
9527 Index := First_Index (T);
9530 -- Apply constraints to each index type
9532 for J in 1 .. Number_Of_Constraints loop
9533 Constrain_Index (Index, S, Related_Nod, Related_Id, Suffix, J);
9543 Create_Itype (E_Array_Subtype, Related_Nod, Related_Id, Suffix);
9544 Set_Parent (Def_Id, Related_Nod);
9547 Set_Ekind (Def_Id, E_Array_Subtype);
9550 Set_Size_Info (Def_Id, (T));
9551 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
9552 Set_Etype (Def_Id, Base_Type (T));
9554 if Constraint_OK then
9555 Set_First_Index (Def_Id, First (Constraints (C)));
9557 Set_First_Index (Def_Id, First_Index (T));
9560 Set_Is_Constrained (Def_Id, True);
9561 Set_Is_Aliased (Def_Id, Is_Aliased (T));
9562 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9564 Set_Is_Private_Composite (Def_Id, Is_Private_Composite (T));
9565 Set_Is_Limited_Composite (Def_Id, Is_Limited_Composite (T));
9567 -- A subtype does not inherit the packed_array_type of is parent. We
9568 -- need to initialize the attribute because if Def_Id is previously
9569 -- analyzed through a limited_with clause, it will have the attributes
9570 -- of an incomplete type, one of which is an Elist that overlaps the
9571 -- Packed_Array_Type field.
9573 Set_Packed_Array_Type (Def_Id, Empty);
9575 -- Build a freeze node if parent still needs one. Also make sure that
9576 -- the Depends_On_Private status is set because the subtype will need
9577 -- reprocessing at the time the base type does, and also we must set a
9578 -- conditional delay.
9580 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
9581 Conditional_Delay (Def_Id, T);
9582 end Constrain_Array;
9584 ------------------------------
9585 -- Constrain_Component_Type --
9586 ------------------------------
9588 function Constrain_Component_Type
9590 Constrained_Typ : Entity_Id;
9591 Related_Node : Node_Id;
9593 Constraints : Elist_Id) return Entity_Id
9595 Loc : constant Source_Ptr := Sloc (Constrained_Typ);
9596 Compon_Type : constant Entity_Id := Etype (Comp);
9598 function Build_Constrained_Array_Type
9599 (Old_Type : Entity_Id) return Entity_Id;
9600 -- If Old_Type is an array type, one of whose indices is constrained
9601 -- by a discriminant, build an Itype whose constraint replaces the
9602 -- discriminant with its value in the constraint.
9604 function Build_Constrained_Discriminated_Type
9605 (Old_Type : Entity_Id) return Entity_Id;
9606 -- Ditto for record components
9608 function Build_Constrained_Access_Type
9609 (Old_Type : Entity_Id) return Entity_Id;
9610 -- Ditto for access types. Makes use of previous two functions, to
9611 -- constrain designated type.
9613 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id;
9614 -- T is an array or discriminated type, C is a list of constraints
9615 -- that apply to T. This routine builds the constrained subtype.
9617 function Is_Discriminant (Expr : Node_Id) return Boolean;
9618 -- Returns True if Expr is a discriminant
9620 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id;
9621 -- Find the value of discriminant Discrim in Constraint
9623 -----------------------------------
9624 -- Build_Constrained_Access_Type --
9625 -----------------------------------
9627 function Build_Constrained_Access_Type
9628 (Old_Type : Entity_Id) return Entity_Id
9630 Desig_Type : constant Entity_Id := Designated_Type (Old_Type);
9632 Desig_Subtype : Entity_Id;
9636 -- if the original access type was not embedded in the enclosing
9637 -- type definition, there is no need to produce a new access
9638 -- subtype. In fact every access type with an explicit constraint
9639 -- generates an itype whose scope is the enclosing record.
9641 if not Is_Type (Scope (Old_Type)) then
9644 elsif Is_Array_Type (Desig_Type) then
9645 Desig_Subtype := Build_Constrained_Array_Type (Desig_Type);
9647 elsif Has_Discriminants (Desig_Type) then
9649 -- This may be an access type to an enclosing record type for
9650 -- which we are constructing the constrained components. Return
9651 -- the enclosing record subtype. This is not always correct,
9652 -- but avoids infinite recursion. ???
9654 Desig_Subtype := Any_Type;
9656 for J in reverse 0 .. Scope_Stack.Last loop
9657 Scop := Scope_Stack.Table (J).Entity;
9660 and then Base_Type (Scop) = Base_Type (Desig_Type)
9662 Desig_Subtype := Scop;
9665 exit when not Is_Type (Scop);
9668 if Desig_Subtype = Any_Type then
9670 Build_Constrained_Discriminated_Type (Desig_Type);
9677 if Desig_Subtype /= Desig_Type then
9679 -- The Related_Node better be here or else we won't be able
9680 -- to attach new itypes to a node in the tree.
9682 pragma Assert (Present (Related_Node));
9684 Itype := Create_Itype (E_Access_Subtype, Related_Node);
9686 Set_Etype (Itype, Base_Type (Old_Type));
9687 Set_Size_Info (Itype, (Old_Type));
9688 Set_Directly_Designated_Type (Itype, Desig_Subtype);
9689 Set_Depends_On_Private (Itype, Has_Private_Component
9691 Set_Is_Access_Constant (Itype, Is_Access_Constant
9694 -- The new itype needs freezing when it depends on a not frozen
9695 -- type and the enclosing subtype needs freezing.
9697 if Has_Delayed_Freeze (Constrained_Typ)
9698 and then not Is_Frozen (Constrained_Typ)
9700 Conditional_Delay (Itype, Base_Type (Old_Type));
9708 end Build_Constrained_Access_Type;
9710 ----------------------------------
9711 -- Build_Constrained_Array_Type --
9712 ----------------------------------
9714 function Build_Constrained_Array_Type
9715 (Old_Type : Entity_Id) return Entity_Id
9719 Old_Index : Node_Id;
9720 Range_Node : Node_Id;
9721 Constr_List : List_Id;
9723 Need_To_Create_Itype : Boolean := False;
9726 Old_Index := First_Index (Old_Type);
9727 while Present (Old_Index) loop
9728 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9730 if Is_Discriminant (Lo_Expr)
9731 or else Is_Discriminant (Hi_Expr)
9733 Need_To_Create_Itype := True;
9736 Next_Index (Old_Index);
9739 if Need_To_Create_Itype then
9740 Constr_List := New_List;
9742 Old_Index := First_Index (Old_Type);
9743 while Present (Old_Index) loop
9744 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9746 if Is_Discriminant (Lo_Expr) then
9747 Lo_Expr := Get_Discr_Value (Lo_Expr);
9750 if Is_Discriminant (Hi_Expr) then
9751 Hi_Expr := Get_Discr_Value (Hi_Expr);
9756 (Loc, New_Copy_Tree (Lo_Expr), New_Copy_Tree (Hi_Expr));
9758 Append (Range_Node, To => Constr_List);
9760 Next_Index (Old_Index);
9763 return Build_Subtype (Old_Type, Constr_List);
9768 end Build_Constrained_Array_Type;
9770 ------------------------------------------
9771 -- Build_Constrained_Discriminated_Type --
9772 ------------------------------------------
9774 function Build_Constrained_Discriminated_Type
9775 (Old_Type : Entity_Id) return Entity_Id
9778 Constr_List : List_Id;
9779 Old_Constraint : Elmt_Id;
9781 Need_To_Create_Itype : Boolean := False;
9784 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9785 while Present (Old_Constraint) loop
9786 Expr := Node (Old_Constraint);
9788 if Is_Discriminant (Expr) then
9789 Need_To_Create_Itype := True;
9792 Next_Elmt (Old_Constraint);
9795 if Need_To_Create_Itype then
9796 Constr_List := New_List;
9798 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9799 while Present (Old_Constraint) loop
9800 Expr := Node (Old_Constraint);
9802 if Is_Discriminant (Expr) then
9803 Expr := Get_Discr_Value (Expr);
9806 Append (New_Copy_Tree (Expr), To => Constr_List);
9808 Next_Elmt (Old_Constraint);
9811 return Build_Subtype (Old_Type, Constr_List);
9816 end Build_Constrained_Discriminated_Type;
9822 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id is
9824 Subtyp_Decl : Node_Id;
9826 Btyp : Entity_Id := Base_Type (T);
9829 -- The Related_Node better be here or else we won't be able to
9830 -- attach new itypes to a node in the tree.
9832 pragma Assert (Present (Related_Node));
9834 -- If the view of the component's type is incomplete or private
9835 -- with unknown discriminants, then the constraint must be applied
9836 -- to the full type.
9838 if Has_Unknown_Discriminants (Btyp)
9839 and then Present (Underlying_Type (Btyp))
9841 Btyp := Underlying_Type (Btyp);
9845 Make_Subtype_Indication (Loc,
9846 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
9847 Constraint => Make_Index_Or_Discriminant_Constraint (Loc, C));
9849 Def_Id := Create_Itype (Ekind (T), Related_Node);
9852 Make_Subtype_Declaration (Loc,
9853 Defining_Identifier => Def_Id,
9854 Subtype_Indication => Indic);
9856 Set_Parent (Subtyp_Decl, Parent (Related_Node));
9858 -- Itypes must be analyzed with checks off (see package Itypes)
9860 Analyze (Subtyp_Decl, Suppress => All_Checks);
9865 ---------------------
9866 -- Get_Discr_Value --
9867 ---------------------
9869 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id is
9874 -- The discriminant may be declared for the type, in which case we
9875 -- find it by iterating over the list of discriminants. If the
9876 -- discriminant is inherited from a parent type, it appears as the
9877 -- corresponding discriminant of the current type. This will be the
9878 -- case when constraining an inherited component whose constraint is
9879 -- given by a discriminant of the parent.
9881 D := First_Discriminant (Typ);
9882 E := First_Elmt (Constraints);
9884 while Present (D) loop
9885 if D = Entity (Discrim)
9886 or else D = CR_Discriminant (Entity (Discrim))
9887 or else Corresponding_Discriminant (D) = Entity (Discrim)
9892 Next_Discriminant (D);
9896 -- The corresponding_Discriminant mechanism is incomplete, because
9897 -- the correspondence between new and old discriminants is not one
9898 -- to one: one new discriminant can constrain several old ones. In
9899 -- that case, scan sequentially the stored_constraint, the list of
9900 -- discriminants of the parents, and the constraints.
9901 -- Previous code checked for the present of the Stored_Constraint
9902 -- list for the derived type, but did not use it at all. Should it
9903 -- be present when the component is a discriminated task type?
9905 if Is_Derived_Type (Typ)
9906 and then Scope (Entity (Discrim)) = Etype (Typ)
9908 D := First_Discriminant (Etype (Typ));
9909 E := First_Elmt (Constraints);
9910 while Present (D) loop
9911 if D = Entity (Discrim) then
9915 Next_Discriminant (D);
9920 -- Something is wrong if we did not find the value
9922 raise Program_Error;
9923 end Get_Discr_Value;
9925 ---------------------
9926 -- Is_Discriminant --
9927 ---------------------
9929 function Is_Discriminant (Expr : Node_Id) return Boolean is
9930 Discrim_Scope : Entity_Id;
9933 if Denotes_Discriminant (Expr) then
9934 Discrim_Scope := Scope (Entity (Expr));
9936 -- Either we have a reference to one of Typ's discriminants,
9938 pragma Assert (Discrim_Scope = Typ
9940 -- or to the discriminants of the parent type, in the case
9941 -- of a derivation of a tagged type with variants.
9943 or else Discrim_Scope = Etype (Typ)
9944 or else Full_View (Discrim_Scope) = Etype (Typ)
9946 -- or same as above for the case where the discriminants
9947 -- were declared in Typ's private view.
9949 or else (Is_Private_Type (Discrim_Scope)
9950 and then Chars (Discrim_Scope) = Chars (Typ))
9952 -- or else we are deriving from the full view and the
9953 -- discriminant is declared in the private entity.
9955 or else (Is_Private_Type (Typ)
9956 and then Chars (Discrim_Scope) = Chars (Typ))
9958 -- Or we are constrained the corresponding record of a
9959 -- synchronized type that completes a private declaration.
9961 or else (Is_Concurrent_Record_Type (Typ)
9963 Corresponding_Concurrent_Type (Typ) = Discrim_Scope)
9965 -- or we have a class-wide type, in which case make sure the
9966 -- discriminant found belongs to the root type.
9968 or else (Is_Class_Wide_Type (Typ)
9969 and then Etype (Typ) = Discrim_Scope));
9974 -- In all other cases we have something wrong
9977 end Is_Discriminant;
9979 -- Start of processing for Constrain_Component_Type
9982 if Nkind (Parent (Comp)) = N_Component_Declaration
9983 and then Comes_From_Source (Parent (Comp))
9984 and then Comes_From_Source
9985 (Subtype_Indication (Component_Definition (Parent (Comp))))
9988 (Subtype_Indication (Component_Definition (Parent (Comp))))
9992 elsif Is_Array_Type (Compon_Type) then
9993 return Build_Constrained_Array_Type (Compon_Type);
9995 elsif Has_Discriminants (Compon_Type) then
9996 return Build_Constrained_Discriminated_Type (Compon_Type);
9998 elsif Is_Access_Type (Compon_Type) then
9999 return Build_Constrained_Access_Type (Compon_Type);
10002 return Compon_Type;
10004 end Constrain_Component_Type;
10006 --------------------------
10007 -- Constrain_Concurrent --
10008 --------------------------
10010 -- For concurrent types, the associated record value type carries the same
10011 -- discriminants, so when we constrain a concurrent type, we must constrain
10012 -- the corresponding record type as well.
10014 procedure Constrain_Concurrent
10015 (Def_Id : in out Entity_Id;
10017 Related_Nod : Node_Id;
10018 Related_Id : Entity_Id;
10019 Suffix : Character)
10021 T_Ent : Entity_Id := Entity (Subtype_Mark (SI));
10025 if Ekind (T_Ent) in Access_Kind then
10026 T_Ent := Designated_Type (T_Ent);
10029 T_Val := Corresponding_Record_Type (T_Ent);
10031 if Present (T_Val) then
10033 if No (Def_Id) then
10034 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
10037 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
10039 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
10040 Set_Corresponding_Record_Type (Def_Id,
10041 Constrain_Corresponding_Record
10042 (Def_Id, T_Val, Related_Nod, Related_Id));
10045 -- If there is no associated record, expansion is disabled and this
10046 -- is a generic context. Create a subtype in any case, so that
10047 -- semantic analysis can proceed.
10049 if No (Def_Id) then
10050 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
10053 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
10055 end Constrain_Concurrent;
10057 ------------------------------------
10058 -- Constrain_Corresponding_Record --
10059 ------------------------------------
10061 function Constrain_Corresponding_Record
10062 (Prot_Subt : Entity_Id;
10063 Corr_Rec : Entity_Id;
10064 Related_Nod : Node_Id;
10065 Related_Id : Entity_Id) return Entity_Id
10067 T_Sub : constant Entity_Id :=
10068 Create_Itype (E_Record_Subtype, Related_Nod, Related_Id, 'V');
10071 Set_Etype (T_Sub, Corr_Rec);
10072 Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt));
10073 Set_Is_Constrained (T_Sub, True);
10074 Set_First_Entity (T_Sub, First_Entity (Corr_Rec));
10075 Set_Last_Entity (T_Sub, Last_Entity (Corr_Rec));
10077 -- As elsewhere, we do not want to create a freeze node for this itype
10078 -- if it is created for a constrained component of an enclosing record
10079 -- because references to outer discriminants will appear out of scope.
10081 if Ekind (Scope (Prot_Subt)) /= E_Record_Type then
10082 Conditional_Delay (T_Sub, Corr_Rec);
10084 Set_Is_Frozen (T_Sub);
10087 if Has_Discriminants (Prot_Subt) then -- False only if errors.
10088 Set_Discriminant_Constraint
10089 (T_Sub, Discriminant_Constraint (Prot_Subt));
10090 Set_Stored_Constraint_From_Discriminant_Constraint (T_Sub);
10091 Create_Constrained_Components
10092 (T_Sub, Related_Nod, Corr_Rec, Discriminant_Constraint (T_Sub));
10095 Set_Depends_On_Private (T_Sub, Has_Private_Component (T_Sub));
10098 end Constrain_Corresponding_Record;
10100 -----------------------
10101 -- Constrain_Decimal --
10102 -----------------------
10104 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id) is
10105 T : constant Entity_Id := Entity (Subtype_Mark (S));
10106 C : constant Node_Id := Constraint (S);
10107 Loc : constant Source_Ptr := Sloc (C);
10108 Range_Expr : Node_Id;
10109 Digits_Expr : Node_Id;
10114 Set_Ekind (Def_Id, E_Decimal_Fixed_Point_Subtype);
10116 if Nkind (C) = N_Range_Constraint then
10117 Range_Expr := Range_Expression (C);
10118 Digits_Val := Digits_Value (T);
10121 pragma Assert (Nkind (C) = N_Digits_Constraint);
10122 Digits_Expr := Digits_Expression (C);
10123 Analyze_And_Resolve (Digits_Expr, Any_Integer);
10125 Check_Digits_Expression (Digits_Expr);
10126 Digits_Val := Expr_Value (Digits_Expr);
10128 if Digits_Val > Digits_Value (T) then
10130 ("digits expression is incompatible with subtype", C);
10131 Digits_Val := Digits_Value (T);
10134 if Present (Range_Constraint (C)) then
10135 Range_Expr := Range_Expression (Range_Constraint (C));
10137 Range_Expr := Empty;
10141 Set_Etype (Def_Id, Base_Type (T));
10142 Set_Size_Info (Def_Id, (T));
10143 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10144 Set_Delta_Value (Def_Id, Delta_Value (T));
10145 Set_Scale_Value (Def_Id, Scale_Value (T));
10146 Set_Small_Value (Def_Id, Small_Value (T));
10147 Set_Machine_Radix_10 (Def_Id, Machine_Radix_10 (T));
10148 Set_Digits_Value (Def_Id, Digits_Val);
10150 -- Manufacture range from given digits value if no range present
10152 if No (Range_Expr) then
10153 Bound_Val := (Ureal_10 ** Digits_Val - Ureal_1) * Small_Value (T);
10157 Convert_To (T, Make_Real_Literal (Loc, (-Bound_Val))),
10159 Convert_To (T, Make_Real_Literal (Loc, Bound_Val)));
10162 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expr, T);
10163 Set_Discrete_RM_Size (Def_Id);
10165 -- Unconditionally delay the freeze, since we cannot set size
10166 -- information in all cases correctly until the freeze point.
10168 Set_Has_Delayed_Freeze (Def_Id);
10169 end Constrain_Decimal;
10171 ----------------------------------
10172 -- Constrain_Discriminated_Type --
10173 ----------------------------------
10175 procedure Constrain_Discriminated_Type
10176 (Def_Id : Entity_Id;
10178 Related_Nod : Node_Id;
10179 For_Access : Boolean := False)
10181 E : constant Entity_Id := Entity (Subtype_Mark (S));
10184 Elist : Elist_Id := New_Elmt_List;
10186 procedure Fixup_Bad_Constraint;
10187 -- This is called after finding a bad constraint, and after having
10188 -- posted an appropriate error message. The mission is to leave the
10189 -- entity T in as reasonable state as possible!
10191 --------------------------
10192 -- Fixup_Bad_Constraint --
10193 --------------------------
10195 procedure Fixup_Bad_Constraint is
10197 -- Set a reasonable Ekind for the entity. For an incomplete type,
10198 -- we can't do much, but for other types, we can set the proper
10199 -- corresponding subtype kind.
10201 if Ekind (T) = E_Incomplete_Type then
10202 Set_Ekind (Def_Id, Ekind (T));
10204 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
10207 -- Set Etype to the known type, to reduce chances of cascaded errors
10209 Set_Etype (Def_Id, E);
10210 Set_Error_Posted (Def_Id);
10211 end Fixup_Bad_Constraint;
10213 -- Start of processing for Constrain_Discriminated_Type
10216 C := Constraint (S);
10218 -- A discriminant constraint is only allowed in a subtype indication,
10219 -- after a subtype mark. This subtype mark must denote either a type
10220 -- with discriminants, or an access type whose designated type is a
10221 -- type with discriminants. A discriminant constraint specifies the
10222 -- values of these discriminants (RM 3.7.2(5)).
10224 T := Base_Type (Entity (Subtype_Mark (S)));
10226 if Ekind (T) in Access_Kind then
10227 T := Designated_Type (T);
10230 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal.
10231 -- Avoid generating an error for access-to-incomplete subtypes.
10233 if Ada_Version >= Ada_05
10234 and then Ekind (T) = E_Incomplete_Type
10235 and then Nkind (Parent (S)) = N_Subtype_Declaration
10236 and then not Is_Itype (Def_Id)
10238 -- A little sanity check, emit an error message if the type
10239 -- has discriminants to begin with. Type T may be a regular
10240 -- incomplete type or imported via a limited with clause.
10242 if Has_Discriminants (T)
10244 (From_With_Type (T)
10245 and then Present (Non_Limited_View (T))
10246 and then Nkind (Parent (Non_Limited_View (T))) =
10247 N_Full_Type_Declaration
10248 and then Present (Discriminant_Specifications
10249 (Parent (Non_Limited_View (T)))))
10252 ("(Ada 2005) incomplete subtype may not be constrained", C);
10255 ("invalid constraint: type has no discriminant", C);
10258 Fixup_Bad_Constraint;
10261 -- Check that the type has visible discriminants. The type may be
10262 -- a private type with unknown discriminants whose full view has
10263 -- discriminants which are invisible.
10265 elsif not Has_Discriminants (T)
10267 (Has_Unknown_Discriminants (T)
10268 and then Is_Private_Type (T))
10270 Error_Msg_N ("invalid constraint: type has no discriminant", C);
10271 Fixup_Bad_Constraint;
10274 elsif Is_Constrained (E)
10275 or else (Ekind (E) = E_Class_Wide_Subtype
10276 and then Present (Discriminant_Constraint (E)))
10278 Error_Msg_N ("type is already constrained", Subtype_Mark (S));
10279 Fixup_Bad_Constraint;
10283 -- T may be an unconstrained subtype (e.g. a generic actual).
10284 -- Constraint applies to the base type.
10286 T := Base_Type (T);
10288 Elist := Build_Discriminant_Constraints (T, S);
10290 -- If the list returned was empty we had an error in building the
10291 -- discriminant constraint. We have also already signalled an error
10292 -- in the incomplete type case
10294 if Is_Empty_Elmt_List (Elist) then
10295 Fixup_Bad_Constraint;
10299 Build_Discriminated_Subtype (T, Def_Id, Elist, Related_Nod, For_Access);
10300 end Constrain_Discriminated_Type;
10302 ---------------------------
10303 -- Constrain_Enumeration --
10304 ---------------------------
10306 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id) is
10307 T : constant Entity_Id := Entity (Subtype_Mark (S));
10308 C : constant Node_Id := Constraint (S);
10311 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10313 Set_First_Literal (Def_Id, First_Literal (Base_Type (T)));
10315 Set_Etype (Def_Id, Base_Type (T));
10316 Set_Size_Info (Def_Id, (T));
10317 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10318 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10320 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10322 Set_Discrete_RM_Size (Def_Id);
10323 end Constrain_Enumeration;
10325 ----------------------
10326 -- Constrain_Float --
10327 ----------------------
10329 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id) is
10330 T : constant Entity_Id := Entity (Subtype_Mark (S));
10336 Set_Ekind (Def_Id, E_Floating_Point_Subtype);
10338 Set_Etype (Def_Id, Base_Type (T));
10339 Set_Size_Info (Def_Id, (T));
10340 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10342 -- Process the constraint
10344 C := Constraint (S);
10346 -- Digits constraint present
10348 if Nkind (C) = N_Digits_Constraint then
10349 Check_Restriction (No_Obsolescent_Features, C);
10351 if Warn_On_Obsolescent_Feature then
10353 ("subtype digits constraint is an " &
10354 "obsolescent feature (RM J.3(8))?", C);
10357 D := Digits_Expression (C);
10358 Analyze_And_Resolve (D, Any_Integer);
10359 Check_Digits_Expression (D);
10360 Set_Digits_Value (Def_Id, Expr_Value (D));
10362 -- Check that digits value is in range. Obviously we can do this
10363 -- at compile time, but it is strictly a runtime check, and of
10364 -- course there is an ACVC test that checks this!
10366 if Digits_Value (Def_Id) > Digits_Value (T) then
10367 Error_Msg_Uint_1 := Digits_Value (T);
10368 Error_Msg_N ("?digits value is too large, maximum is ^", D);
10370 Make_Raise_Constraint_Error (Sloc (D),
10371 Reason => CE_Range_Check_Failed);
10372 Insert_Action (Declaration_Node (Def_Id), Rais);
10375 C := Range_Constraint (C);
10377 -- No digits constraint present
10380 Set_Digits_Value (Def_Id, Digits_Value (T));
10383 -- Range constraint present
10385 if Nkind (C) = N_Range_Constraint then
10386 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10388 -- No range constraint present
10391 pragma Assert (No (C));
10392 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10395 Set_Is_Constrained (Def_Id);
10396 end Constrain_Float;
10398 ---------------------
10399 -- Constrain_Index --
10400 ---------------------
10402 procedure Constrain_Index
10405 Related_Nod : Node_Id;
10406 Related_Id : Entity_Id;
10407 Suffix : Character;
10408 Suffix_Index : Nat)
10410 Def_Id : Entity_Id;
10411 R : Node_Id := Empty;
10412 T : constant Entity_Id := Etype (Index);
10415 if Nkind (S) = N_Range
10417 (Nkind (S) = N_Attribute_Reference
10418 and then Attribute_Name (S) = Name_Range)
10420 -- A Range attribute will transformed into N_Range by Resolve
10426 Process_Range_Expr_In_Decl (R, T, Empty_List);
10428 if not Error_Posted (S)
10430 (Nkind (S) /= N_Range
10431 or else not Covers (T, (Etype (Low_Bound (S))))
10432 or else not Covers (T, (Etype (High_Bound (S)))))
10434 if Base_Type (T) /= Any_Type
10435 and then Etype (Low_Bound (S)) /= Any_Type
10436 and then Etype (High_Bound (S)) /= Any_Type
10438 Error_Msg_N ("range expected", S);
10442 elsif Nkind (S) = N_Subtype_Indication then
10444 -- The parser has verified that this is a discrete indication
10446 Resolve_Discrete_Subtype_Indication (S, T);
10447 R := Range_Expression (Constraint (S));
10449 elsif Nkind (S) = N_Discriminant_Association then
10451 -- Syntactically valid in subtype indication
10453 Error_Msg_N ("invalid index constraint", S);
10454 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10457 -- Subtype_Mark case, no anonymous subtypes to construct
10462 if Is_Entity_Name (S) then
10463 if not Is_Type (Entity (S)) then
10464 Error_Msg_N ("expect subtype mark for index constraint", S);
10466 elsif Base_Type (Entity (S)) /= Base_Type (T) then
10467 Wrong_Type (S, Base_Type (T));
10473 Error_Msg_N ("invalid index constraint", S);
10474 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10480 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index);
10482 Set_Etype (Def_Id, Base_Type (T));
10484 if Is_Modular_Integer_Type (T) then
10485 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10487 elsif Is_Integer_Type (T) then
10488 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10491 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10492 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10495 Set_Size_Info (Def_Id, (T));
10496 Set_RM_Size (Def_Id, RM_Size (T));
10497 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10499 Set_Scalar_Range (Def_Id, R);
10501 Set_Etype (S, Def_Id);
10502 Set_Discrete_RM_Size (Def_Id);
10503 end Constrain_Index;
10505 -----------------------
10506 -- Constrain_Integer --
10507 -----------------------
10509 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id) is
10510 T : constant Entity_Id := Entity (Subtype_Mark (S));
10511 C : constant Node_Id := Constraint (S);
10514 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10516 if Is_Modular_Integer_Type (T) then
10517 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10519 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10522 Set_Etype (Def_Id, Base_Type (T));
10523 Set_Size_Info (Def_Id, (T));
10524 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10525 Set_Discrete_RM_Size (Def_Id);
10526 end Constrain_Integer;
10528 ------------------------------
10529 -- Constrain_Ordinary_Fixed --
10530 ------------------------------
10532 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id) is
10533 T : constant Entity_Id := Entity (Subtype_Mark (S));
10539 Set_Ekind (Def_Id, E_Ordinary_Fixed_Point_Subtype);
10540 Set_Etype (Def_Id, Base_Type (T));
10541 Set_Size_Info (Def_Id, (T));
10542 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10543 Set_Small_Value (Def_Id, Small_Value (T));
10545 -- Process the constraint
10547 C := Constraint (S);
10549 -- Delta constraint present
10551 if Nkind (C) = N_Delta_Constraint then
10552 Check_Restriction (No_Obsolescent_Features, C);
10554 if Warn_On_Obsolescent_Feature then
10556 ("subtype delta constraint is an " &
10557 "obsolescent feature (RM J.3(7))?");
10560 D := Delta_Expression (C);
10561 Analyze_And_Resolve (D, Any_Real);
10562 Check_Delta_Expression (D);
10563 Set_Delta_Value (Def_Id, Expr_Value_R (D));
10565 -- Check that delta value is in range. Obviously we can do this
10566 -- at compile time, but it is strictly a runtime check, and of
10567 -- course there is an ACVC test that checks this!
10569 if Delta_Value (Def_Id) < Delta_Value (T) then
10570 Error_Msg_N ("?delta value is too small", D);
10572 Make_Raise_Constraint_Error (Sloc (D),
10573 Reason => CE_Range_Check_Failed);
10574 Insert_Action (Declaration_Node (Def_Id), Rais);
10577 C := Range_Constraint (C);
10579 -- No delta constraint present
10582 Set_Delta_Value (Def_Id, Delta_Value (T));
10585 -- Range constraint present
10587 if Nkind (C) = N_Range_Constraint then
10588 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10590 -- No range constraint present
10593 pragma Assert (No (C));
10594 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10598 Set_Discrete_RM_Size (Def_Id);
10600 -- Unconditionally delay the freeze, since we cannot set size
10601 -- information in all cases correctly until the freeze point.
10603 Set_Has_Delayed_Freeze (Def_Id);
10604 end Constrain_Ordinary_Fixed;
10606 -----------------------
10607 -- Contain_Interface --
10608 -----------------------
10610 function Contain_Interface
10611 (Iface : Entity_Id;
10612 Ifaces : Elist_Id) return Boolean
10614 Iface_Elmt : Elmt_Id;
10617 if Present (Ifaces) then
10618 Iface_Elmt := First_Elmt (Ifaces);
10619 while Present (Iface_Elmt) loop
10620 if Node (Iface_Elmt) = Iface then
10624 Next_Elmt (Iface_Elmt);
10629 end Contain_Interface;
10631 ---------------------------
10632 -- Convert_Scalar_Bounds --
10633 ---------------------------
10635 procedure Convert_Scalar_Bounds
10637 Parent_Type : Entity_Id;
10638 Derived_Type : Entity_Id;
10641 Implicit_Base : constant Entity_Id := Base_Type (Derived_Type);
10648 Lo := Build_Scalar_Bound
10649 (Type_Low_Bound (Derived_Type),
10650 Parent_Type, Implicit_Base);
10652 Hi := Build_Scalar_Bound
10653 (Type_High_Bound (Derived_Type),
10654 Parent_Type, Implicit_Base);
10661 Set_Includes_Infinities (Rng, Has_Infinities (Derived_Type));
10663 Set_Parent (Rng, N);
10664 Set_Scalar_Range (Derived_Type, Rng);
10666 -- Analyze the bounds
10668 Analyze_And_Resolve (Lo, Implicit_Base);
10669 Analyze_And_Resolve (Hi, Implicit_Base);
10671 -- Analyze the range itself, except that we do not analyze it if
10672 -- the bounds are real literals, and we have a fixed-point type.
10673 -- The reason for this is that we delay setting the bounds in this
10674 -- case till we know the final Small and Size values (see circuit
10675 -- in Freeze.Freeze_Fixed_Point_Type for further details).
10677 if Is_Fixed_Point_Type (Parent_Type)
10678 and then Nkind (Lo) = N_Real_Literal
10679 and then Nkind (Hi) = N_Real_Literal
10683 -- Here we do the analysis of the range
10685 -- Note: we do this manually, since if we do a normal Analyze and
10686 -- Resolve call, there are problems with the conversions used for
10687 -- the derived type range.
10690 Set_Etype (Rng, Implicit_Base);
10691 Set_Analyzed (Rng, True);
10693 end Convert_Scalar_Bounds;
10695 -------------------
10696 -- Copy_And_Swap --
10697 -------------------
10699 procedure Copy_And_Swap (Priv, Full : Entity_Id) is
10701 -- Initialize new full declaration entity by copying the pertinent
10702 -- fields of the corresponding private declaration entity.
10704 -- We temporarily set Ekind to a value appropriate for a type to
10705 -- avoid assert failures in Einfo from checking for setting type
10706 -- attributes on something that is not a type. Ekind (Priv) is an
10707 -- appropriate choice, since it allowed the attributes to be set
10708 -- in the first place. This Ekind value will be modified later.
10710 Set_Ekind (Full, Ekind (Priv));
10712 -- Also set Etype temporarily to Any_Type, again, in the absence
10713 -- of errors, it will be properly reset, and if there are errors,
10714 -- then we want a value of Any_Type to remain.
10716 Set_Etype (Full, Any_Type);
10718 -- Now start copying attributes
10720 Set_Has_Discriminants (Full, Has_Discriminants (Priv));
10722 if Has_Discriminants (Full) then
10723 Set_Discriminant_Constraint (Full, Discriminant_Constraint (Priv));
10724 Set_Stored_Constraint (Full, Stored_Constraint (Priv));
10727 Set_First_Rep_Item (Full, First_Rep_Item (Priv));
10728 Set_Homonym (Full, Homonym (Priv));
10729 Set_Is_Immediately_Visible (Full, Is_Immediately_Visible (Priv));
10730 Set_Is_Public (Full, Is_Public (Priv));
10731 Set_Is_Pure (Full, Is_Pure (Priv));
10732 Set_Is_Tagged_Type (Full, Is_Tagged_Type (Priv));
10733 Set_Has_Pragma_Unreferenced (Full, Has_Pragma_Unreferenced (Priv));
10734 Set_Has_Pragma_Unreferenced_Objects
10735 (Full, Has_Pragma_Unreferenced_Objects
10738 Conditional_Delay (Full, Priv);
10740 if Is_Tagged_Type (Full) then
10741 Set_Primitive_Operations (Full, Primitive_Operations (Priv));
10743 if Priv = Base_Type (Priv) then
10744 Set_Class_Wide_Type (Full, Class_Wide_Type (Priv));
10748 Set_Is_Volatile (Full, Is_Volatile (Priv));
10749 Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv));
10750 Set_Scope (Full, Scope (Priv));
10751 Set_Next_Entity (Full, Next_Entity (Priv));
10752 Set_First_Entity (Full, First_Entity (Priv));
10753 Set_Last_Entity (Full, Last_Entity (Priv));
10755 -- If access types have been recorded for later handling, keep them in
10756 -- the full view so that they get handled when the full view freeze
10757 -- node is expanded.
10759 if Present (Freeze_Node (Priv))
10760 and then Present (Access_Types_To_Process (Freeze_Node (Priv)))
10762 Ensure_Freeze_Node (Full);
10763 Set_Access_Types_To_Process
10764 (Freeze_Node (Full),
10765 Access_Types_To_Process (Freeze_Node (Priv)));
10768 -- Swap the two entities. Now Privat is the full type entity and
10769 -- Full is the private one. They will be swapped back at the end
10770 -- of the private part. This swapping ensures that the entity that
10771 -- is visible in the private part is the full declaration.
10773 Exchange_Entities (Priv, Full);
10774 Append_Entity (Full, Scope (Full));
10777 -------------------------------------
10778 -- Copy_Array_Base_Type_Attributes --
10779 -------------------------------------
10781 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id) is
10783 Set_Component_Alignment (T1, Component_Alignment (T2));
10784 Set_Component_Type (T1, Component_Type (T2));
10785 Set_Component_Size (T1, Component_Size (T2));
10786 Set_Has_Controlled_Component (T1, Has_Controlled_Component (T2));
10787 Set_Finalize_Storage_Only (T1, Finalize_Storage_Only (T2));
10788 Set_Has_Non_Standard_Rep (T1, Has_Non_Standard_Rep (T2));
10789 Set_Has_Task (T1, Has_Task (T2));
10790 Set_Is_Packed (T1, Is_Packed (T2));
10791 Set_Has_Aliased_Components (T1, Has_Aliased_Components (T2));
10792 Set_Has_Atomic_Components (T1, Has_Atomic_Components (T2));
10793 Set_Has_Volatile_Components (T1, Has_Volatile_Components (T2));
10794 end Copy_Array_Base_Type_Attributes;
10796 -----------------------------------
10797 -- Copy_Array_Subtype_Attributes --
10798 -----------------------------------
10800 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id) is
10802 Set_Size_Info (T1, T2);
10804 Set_First_Index (T1, First_Index (T2));
10805 Set_Is_Aliased (T1, Is_Aliased (T2));
10806 Set_Is_Atomic (T1, Is_Atomic (T2));
10807 Set_Is_Volatile (T1, Is_Volatile (T2));
10808 Set_Treat_As_Volatile (T1, Treat_As_Volatile (T2));
10809 Set_Is_Constrained (T1, Is_Constrained (T2));
10810 Set_Depends_On_Private (T1, Has_Private_Component (T2));
10811 Set_First_Rep_Item (T1, First_Rep_Item (T2));
10812 Set_Convention (T1, Convention (T2));
10813 Set_Is_Limited_Composite (T1, Is_Limited_Composite (T2));
10814 Set_Is_Private_Composite (T1, Is_Private_Composite (T2));
10815 end Copy_Array_Subtype_Attributes;
10817 -----------------------------------
10818 -- Create_Constrained_Components --
10819 -----------------------------------
10821 procedure Create_Constrained_Components
10823 Decl_Node : Node_Id;
10825 Constraints : Elist_Id)
10827 Loc : constant Source_Ptr := Sloc (Subt);
10828 Comp_List : constant Elist_Id := New_Elmt_List;
10829 Parent_Type : constant Entity_Id := Etype (Typ);
10830 Assoc_List : constant List_Id := New_List;
10831 Discr_Val : Elmt_Id;
10835 Is_Static : Boolean := True;
10837 procedure Collect_Fixed_Components (Typ : Entity_Id);
10838 -- Collect parent type components that do not appear in a variant part
10840 procedure Create_All_Components;
10841 -- Iterate over Comp_List to create the components of the subtype
10843 function Create_Component (Old_Compon : Entity_Id) return Entity_Id;
10844 -- Creates a new component from Old_Compon, copying all the fields from
10845 -- it, including its Etype, inserts the new component in the Subt entity
10846 -- chain and returns the new component.
10848 function Is_Variant_Record (T : Entity_Id) return Boolean;
10849 -- If true, and discriminants are static, collect only components from
10850 -- variants selected by discriminant values.
10852 ------------------------------
10853 -- Collect_Fixed_Components --
10854 ------------------------------
10856 procedure Collect_Fixed_Components (Typ : Entity_Id) is
10858 -- Build association list for discriminants, and find components of the
10859 -- variant part selected by the values of the discriminants.
10861 Old_C := First_Discriminant (Typ);
10862 Discr_Val := First_Elmt (Constraints);
10863 while Present (Old_C) loop
10864 Append_To (Assoc_List,
10865 Make_Component_Association (Loc,
10866 Choices => New_List (New_Occurrence_Of (Old_C, Loc)),
10867 Expression => New_Copy (Node (Discr_Val))));
10869 Next_Elmt (Discr_Val);
10870 Next_Discriminant (Old_C);
10873 -- The tag, and the possible parent and controller components
10874 -- are unconditionally in the subtype.
10876 if Is_Tagged_Type (Typ)
10877 or else Has_Controlled_Component (Typ)
10879 Old_C := First_Component (Typ);
10880 while Present (Old_C) loop
10881 if Chars ((Old_C)) = Name_uTag
10882 or else Chars ((Old_C)) = Name_uParent
10883 or else Chars ((Old_C)) = Name_uController
10885 Append_Elmt (Old_C, Comp_List);
10888 Next_Component (Old_C);
10891 end Collect_Fixed_Components;
10893 ---------------------------
10894 -- Create_All_Components --
10895 ---------------------------
10897 procedure Create_All_Components is
10901 Comp := First_Elmt (Comp_List);
10902 while Present (Comp) loop
10903 Old_C := Node (Comp);
10904 New_C := Create_Component (Old_C);
10908 Constrain_Component_Type
10909 (Old_C, Subt, Decl_Node, Typ, Constraints));
10910 Set_Is_Public (New_C, Is_Public (Subt));
10914 end Create_All_Components;
10916 ----------------------
10917 -- Create_Component --
10918 ----------------------
10920 function Create_Component (Old_Compon : Entity_Id) return Entity_Id is
10921 New_Compon : constant Entity_Id := New_Copy (Old_Compon);
10924 if Ekind (Old_Compon) = E_Discriminant
10925 and then Is_Completely_Hidden (Old_Compon)
10927 -- This is a shadow discriminant created for a discriminant of
10928 -- the parent type that is one of several renamed by the same
10929 -- new discriminant. Give the shadow discriminant an internal
10930 -- name that cannot conflict with that of visible components.
10932 Set_Chars (New_Compon, New_Internal_Name ('C'));
10935 -- Set the parent so we have a proper link for freezing etc. This is
10936 -- not a real parent pointer, since of course our parent does not own
10937 -- up to us and reference us, we are an illegitimate child of the
10938 -- original parent!
10940 Set_Parent (New_Compon, Parent (Old_Compon));
10942 -- If the old component's Esize was already determined and is a
10943 -- static value, then the new component simply inherits it. Otherwise
10944 -- the old component's size may require run-time determination, but
10945 -- the new component's size still might be statically determinable
10946 -- (if, for example it has a static constraint). In that case we want
10947 -- Layout_Type to recompute the component's size, so we reset its
10948 -- size and positional fields.
10950 if Frontend_Layout_On_Target
10951 and then not Known_Static_Esize (Old_Compon)
10953 Set_Esize (New_Compon, Uint_0);
10954 Init_Normalized_First_Bit (New_Compon);
10955 Init_Normalized_Position (New_Compon);
10956 Init_Normalized_Position_Max (New_Compon);
10959 -- We do not want this node marked as Comes_From_Source, since
10960 -- otherwise it would get first class status and a separate cross-
10961 -- reference line would be generated. Illegitimate children do not
10962 -- rate such recognition.
10964 Set_Comes_From_Source (New_Compon, False);
10966 -- But it is a real entity, and a birth certificate must be properly
10967 -- registered by entering it into the entity list.
10969 Enter_Name (New_Compon);
10972 end Create_Component;
10974 -----------------------
10975 -- Is_Variant_Record --
10976 -----------------------
10978 function Is_Variant_Record (T : Entity_Id) return Boolean is
10980 return Nkind (Parent (T)) = N_Full_Type_Declaration
10981 and then Nkind (Type_Definition (Parent (T))) = N_Record_Definition
10982 and then Present (Component_List (Type_Definition (Parent (T))))
10985 (Variant_Part (Component_List (Type_Definition (Parent (T)))));
10986 end Is_Variant_Record;
10988 -- Start of processing for Create_Constrained_Components
10991 pragma Assert (Subt /= Base_Type (Subt));
10992 pragma Assert (Typ = Base_Type (Typ));
10994 Set_First_Entity (Subt, Empty);
10995 Set_Last_Entity (Subt, Empty);
10997 -- Check whether constraint is fully static, in which case we can
10998 -- optimize the list of components.
11000 Discr_Val := First_Elmt (Constraints);
11001 while Present (Discr_Val) loop
11002 if not Is_OK_Static_Expression (Node (Discr_Val)) then
11003 Is_Static := False;
11007 Next_Elmt (Discr_Val);
11010 Set_Has_Static_Discriminants (Subt, Is_Static);
11014 -- Inherit the discriminants of the parent type
11016 Add_Discriminants : declare
11022 Old_C := First_Discriminant (Typ);
11024 while Present (Old_C) loop
11025 Num_Disc := Num_Disc + 1;
11026 New_C := Create_Component (Old_C);
11027 Set_Is_Public (New_C, Is_Public (Subt));
11028 Next_Discriminant (Old_C);
11031 -- For an untagged derived subtype, the number of discriminants may
11032 -- be smaller than the number of inherited discriminants, because
11033 -- several of them may be renamed by a single new discriminant.
11034 -- In this case, add the hidden discriminants back into the subtype,
11035 -- because otherwise the size of the subtype is computed incorrectly
11040 if Is_Derived_Type (Typ)
11041 and then not Is_Tagged_Type (Typ)
11043 Old_C := First_Stored_Discriminant (Typ);
11045 while Present (Old_C) loop
11046 Num_Gird := Num_Gird + 1;
11047 Next_Stored_Discriminant (Old_C);
11051 if Num_Gird > Num_Disc then
11053 -- Find out multiple uses of new discriminants, and add hidden
11054 -- components for the extra renamed discriminants. We recognize
11055 -- multiple uses through the Corresponding_Discriminant of a
11056 -- new discriminant: if it constrains several old discriminants,
11057 -- this field points to the last one in the parent type. The
11058 -- stored discriminants of the derived type have the same name
11059 -- as those of the parent.
11063 New_Discr : Entity_Id;
11064 Old_Discr : Entity_Id;
11067 Constr := First_Elmt (Stored_Constraint (Typ));
11068 Old_Discr := First_Stored_Discriminant (Typ);
11069 while Present (Constr) loop
11070 if Is_Entity_Name (Node (Constr))
11071 and then Ekind (Entity (Node (Constr))) = E_Discriminant
11073 New_Discr := Entity (Node (Constr));
11075 if Chars (Corresponding_Discriminant (New_Discr)) /=
11078 -- The new discriminant has been used to rename a
11079 -- subsequent old discriminant. Introduce a shadow
11080 -- component for the current old discriminant.
11082 New_C := Create_Component (Old_Discr);
11083 Set_Original_Record_Component (New_C, Old_Discr);
11087 Next_Elmt (Constr);
11088 Next_Stored_Discriminant (Old_Discr);
11092 end Add_Discriminants;
11095 and then Is_Variant_Record (Typ)
11097 Collect_Fixed_Components (Typ);
11099 Gather_Components (
11101 Component_List (Type_Definition (Parent (Typ))),
11102 Governed_By => Assoc_List,
11104 Report_Errors => Errors);
11105 pragma Assert (not Errors);
11107 Create_All_Components;
11109 -- If the subtype declaration is created for a tagged type derivation
11110 -- with constraints, we retrieve the record definition of the parent
11111 -- type to select the components of the proper variant.
11114 and then Is_Tagged_Type (Typ)
11115 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11117 Nkind (Type_Definition (Parent (Typ))) = N_Derived_Type_Definition
11118 and then Is_Variant_Record (Parent_Type)
11120 Collect_Fixed_Components (Typ);
11122 Gather_Components (
11124 Component_List (Type_Definition (Parent (Parent_Type))),
11125 Governed_By => Assoc_List,
11127 Report_Errors => Errors);
11128 pragma Assert (not Errors);
11130 -- If the tagged derivation has a type extension, collect all the
11131 -- new components therein.
11134 (Record_Extension_Part (Type_Definition (Parent (Typ))))
11136 Old_C := First_Component (Typ);
11137 while Present (Old_C) loop
11138 if Original_Record_Component (Old_C) = Old_C
11139 and then Chars (Old_C) /= Name_uTag
11140 and then Chars (Old_C) /= Name_uParent
11141 and then Chars (Old_C) /= Name_uController
11143 Append_Elmt (Old_C, Comp_List);
11146 Next_Component (Old_C);
11150 Create_All_Components;
11153 -- If discriminants are not static, or if this is a multi-level type
11154 -- extension, we have to include all components of the parent type.
11156 Old_C := First_Component (Typ);
11157 while Present (Old_C) loop
11158 New_C := Create_Component (Old_C);
11162 Constrain_Component_Type
11163 (Old_C, Subt, Decl_Node, Typ, Constraints));
11164 Set_Is_Public (New_C, Is_Public (Subt));
11166 Next_Component (Old_C);
11171 end Create_Constrained_Components;
11173 ------------------------------------------
11174 -- Decimal_Fixed_Point_Type_Declaration --
11175 ------------------------------------------
11177 procedure Decimal_Fixed_Point_Type_Declaration
11181 Loc : constant Source_Ptr := Sloc (Def);
11182 Digs_Expr : constant Node_Id := Digits_Expression (Def);
11183 Delta_Expr : constant Node_Id := Delta_Expression (Def);
11184 Implicit_Base : Entity_Id;
11191 Check_Restriction (No_Fixed_Point, Def);
11193 -- Create implicit base type
11196 Create_Itype (E_Decimal_Fixed_Point_Type, Parent (Def), T, 'B');
11197 Set_Etype (Implicit_Base, Implicit_Base);
11199 -- Analyze and process delta expression
11201 Analyze_And_Resolve (Delta_Expr, Universal_Real);
11203 Check_Delta_Expression (Delta_Expr);
11204 Delta_Val := Expr_Value_R (Delta_Expr);
11206 -- Check delta is power of 10, and determine scale value from it
11212 Scale_Val := Uint_0;
11215 if Val < Ureal_1 then
11216 while Val < Ureal_1 loop
11217 Val := Val * Ureal_10;
11218 Scale_Val := Scale_Val + 1;
11221 if Scale_Val > 18 then
11222 Error_Msg_N ("scale exceeds maximum value of 18", Def);
11223 Scale_Val := UI_From_Int (+18);
11227 while Val > Ureal_1 loop
11228 Val := Val / Ureal_10;
11229 Scale_Val := Scale_Val - 1;
11232 if Scale_Val < -18 then
11233 Error_Msg_N ("scale is less than minimum value of -18", Def);
11234 Scale_Val := UI_From_Int (-18);
11238 if Val /= Ureal_1 then
11239 Error_Msg_N ("delta expression must be a power of 10", Def);
11240 Delta_Val := Ureal_10 ** (-Scale_Val);
11244 -- Set delta, scale and small (small = delta for decimal type)
11246 Set_Delta_Value (Implicit_Base, Delta_Val);
11247 Set_Scale_Value (Implicit_Base, Scale_Val);
11248 Set_Small_Value (Implicit_Base, Delta_Val);
11250 -- Analyze and process digits expression
11252 Analyze_And_Resolve (Digs_Expr, Any_Integer);
11253 Check_Digits_Expression (Digs_Expr);
11254 Digs_Val := Expr_Value (Digs_Expr);
11256 if Digs_Val > 18 then
11257 Digs_Val := UI_From_Int (+18);
11258 Error_Msg_N ("digits value out of range, maximum is 18", Digs_Expr);
11261 Set_Digits_Value (Implicit_Base, Digs_Val);
11262 Bound_Val := UR_From_Uint (10 ** Digs_Val - 1) * Delta_Val;
11264 -- Set range of base type from digits value for now. This will be
11265 -- expanded to represent the true underlying base range by Freeze.
11267 Set_Fixed_Range (Implicit_Base, Loc, -Bound_Val, Bound_Val);
11269 -- Note: We leave size as zero for now, size will be set at freeze
11270 -- time. We have to do this for ordinary fixed-point, because the size
11271 -- depends on the specified small, and we might as well do the same for
11272 -- decimal fixed-point.
11274 pragma Assert (Esize (Implicit_Base) = Uint_0);
11276 -- If there are bounds given in the declaration use them as the
11277 -- bounds of the first named subtype.
11279 if Present (Real_Range_Specification (Def)) then
11281 RRS : constant Node_Id := Real_Range_Specification (Def);
11282 Low : constant Node_Id := Low_Bound (RRS);
11283 High : constant Node_Id := High_Bound (RRS);
11288 Analyze_And_Resolve (Low, Any_Real);
11289 Analyze_And_Resolve (High, Any_Real);
11290 Check_Real_Bound (Low);
11291 Check_Real_Bound (High);
11292 Low_Val := Expr_Value_R (Low);
11293 High_Val := Expr_Value_R (High);
11295 if Low_Val < (-Bound_Val) then
11297 ("range low bound too small for digits value", Low);
11298 Low_Val := -Bound_Val;
11301 if High_Val > Bound_Val then
11303 ("range high bound too large for digits value", High);
11304 High_Val := Bound_Val;
11307 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
11310 -- If no explicit range, use range that corresponds to given
11311 -- digits value. This will end up as the final range for the
11315 Set_Fixed_Range (T, Loc, -Bound_Val, Bound_Val);
11318 -- Complete entity for first subtype
11320 Set_Ekind (T, E_Decimal_Fixed_Point_Subtype);
11321 Set_Etype (T, Implicit_Base);
11322 Set_Size_Info (T, Implicit_Base);
11323 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
11324 Set_Digits_Value (T, Digs_Val);
11325 Set_Delta_Value (T, Delta_Val);
11326 Set_Small_Value (T, Delta_Val);
11327 Set_Scale_Value (T, Scale_Val);
11328 Set_Is_Constrained (T);
11329 end Decimal_Fixed_Point_Type_Declaration;
11331 -----------------------------------
11332 -- Derive_Progenitor_Subprograms --
11333 -----------------------------------
11335 procedure Derive_Progenitor_Subprograms
11336 (Parent_Type : Entity_Id;
11337 Tagged_Type : Entity_Id)
11342 Iface_Elmt : Elmt_Id;
11343 Iface_Subp : Entity_Id;
11344 New_Subp : Entity_Id := Empty;
11345 Prim_Elmt : Elmt_Id;
11350 pragma Assert (Ada_Version >= Ada_05
11351 and then Is_Record_Type (Tagged_Type)
11352 and then Is_Tagged_Type (Tagged_Type)
11353 and then Has_Interfaces (Tagged_Type));
11355 -- Step 1: Transfer to the full-view primitives associated with the
11356 -- partial-view that cover interface primitives. Conceptually this
11357 -- work should be done later by Process_Full_View; done here to
11358 -- simplify its implementation at later stages. It can be safely
11359 -- done here because interfaces must be visible in the partial and
11360 -- private view (RM 7.3(7.3/2)).
11362 -- Small optimization: This work is only required if the parent is
11363 -- abstract. If the tagged type is not abstract, it cannot have
11364 -- abstract primitives (the only entities in the list of primitives of
11365 -- non-abstract tagged types that can reference abstract primitives
11366 -- through its Alias attribute are the internal entities that have
11367 -- attribute Interface_Alias, and these entities are generated later
11368 -- by Freeze_Record_Type).
11370 if In_Private_Part (Current_Scope)
11371 and then Is_Abstract_Type (Parent_Type)
11373 Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
11374 while Present (Elmt) loop
11375 Subp := Node (Elmt);
11377 -- At this stage it is not possible to have entities in the list
11378 -- of primitives that have attribute Interface_Alias
11380 pragma Assert (No (Interface_Alias (Subp)));
11382 Typ := Find_Dispatching_Type (Ultimate_Alias (Subp));
11384 if Is_Interface (Typ) then
11385 E := Find_Primitive_Covering_Interface
11386 (Tagged_Type => Tagged_Type,
11387 Iface_Prim => Subp);
11390 and then Find_Dispatching_Type (Ultimate_Alias (E)) /= Typ
11392 Replace_Elmt (Elmt, E);
11393 Remove_Homonym (Subp);
11401 -- Step 2: Add primitives of progenitors that are not implemented by
11402 -- parents of Tagged_Type
11404 if Present (Interfaces (Tagged_Type)) then
11405 Iface_Elmt := First_Elmt (Interfaces (Tagged_Type));
11406 while Present (Iface_Elmt) loop
11407 Iface := Node (Iface_Elmt);
11409 Prim_Elmt := First_Elmt (Primitive_Operations (Iface));
11410 while Present (Prim_Elmt) loop
11411 Iface_Subp := Node (Prim_Elmt);
11413 -- Exclude derivation of predefined primitives except those
11414 -- that come from source. Required to catch declarations of
11415 -- equality operators of interfaces. For example:
11417 -- type Iface is interface;
11418 -- function "=" (Left, Right : Iface) return Boolean;
11420 if not Is_Predefined_Dispatching_Operation (Iface_Subp)
11421 or else Comes_From_Source (Iface_Subp)
11423 E := Find_Primitive_Covering_Interface
11424 (Tagged_Type => Tagged_Type,
11425 Iface_Prim => Iface_Subp);
11427 -- If not found we derive a new primitive leaving its alias
11428 -- attribute referencing the interface primitive
11432 (New_Subp, Iface_Subp, Tagged_Type, Iface);
11434 -- Propagate to the full view interface entities associated
11435 -- with the partial view
11437 elsif In_Private_Part (Current_Scope)
11438 and then Present (Alias (E))
11439 and then Alias (E) = Iface_Subp
11441 List_Containing (Parent (E)) /=
11442 Private_Declarations
11444 (Unit_Declaration_Node (Current_Scope)))
11446 Append_Elmt (E, Primitive_Operations (Tagged_Type));
11450 Next_Elmt (Prim_Elmt);
11453 Next_Elmt (Iface_Elmt);
11456 end Derive_Progenitor_Subprograms;
11458 -----------------------
11459 -- Derive_Subprogram --
11460 -----------------------
11462 procedure Derive_Subprogram
11463 (New_Subp : in out Entity_Id;
11464 Parent_Subp : Entity_Id;
11465 Derived_Type : Entity_Id;
11466 Parent_Type : Entity_Id;
11467 Actual_Subp : Entity_Id := Empty)
11469 Formal : Entity_Id;
11470 -- Formal parameter of parent primitive operation
11472 Formal_Of_Actual : Entity_Id;
11473 -- Formal parameter of actual operation, when the derivation is to
11474 -- create a renaming for a primitive operation of an actual in an
11477 New_Formal : Entity_Id;
11478 -- Formal of inherited operation
11480 Visible_Subp : Entity_Id := Parent_Subp;
11482 function Is_Private_Overriding return Boolean;
11483 -- If Subp is a private overriding of a visible operation, the inherited
11484 -- operation derives from the overridden op (even though its body is the
11485 -- overriding one) and the inherited operation is visible now. See
11486 -- sem_disp to see the full details of the handling of the overridden
11487 -- subprogram, which is removed from the list of primitive operations of
11488 -- the type. The overridden subprogram is saved locally in Visible_Subp,
11489 -- and used to diagnose abstract operations that need overriding in the
11492 procedure Replace_Type (Id, New_Id : Entity_Id);
11493 -- When the type is an anonymous access type, create a new access type
11494 -- designating the derived type.
11496 procedure Set_Derived_Name;
11497 -- This procedure sets the appropriate Chars name for New_Subp. This
11498 -- is normally just a copy of the parent name. An exception arises for
11499 -- type support subprograms, where the name is changed to reflect the
11500 -- name of the derived type, e.g. if type foo is derived from type bar,
11501 -- then a procedure barDA is derived with a name fooDA.
11503 ---------------------------
11504 -- Is_Private_Overriding --
11505 ---------------------------
11507 function Is_Private_Overriding return Boolean is
11511 -- If the parent is not a dispatching operation there is no
11512 -- need to investigate overridings
11514 if not Is_Dispatching_Operation (Parent_Subp) then
11518 -- The visible operation that is overridden is a homonym of the
11519 -- parent subprogram. We scan the homonym chain to find the one
11520 -- whose alias is the subprogram we are deriving.
11522 Prev := Current_Entity (Parent_Subp);
11523 while Present (Prev) loop
11524 if Ekind (Prev) = Ekind (Parent_Subp)
11525 and then Alias (Prev) = Parent_Subp
11526 and then Scope (Parent_Subp) = Scope (Prev)
11527 and then not Is_Hidden (Prev)
11529 Visible_Subp := Prev;
11533 Prev := Homonym (Prev);
11537 end Is_Private_Overriding;
11543 procedure Replace_Type (Id, New_Id : Entity_Id) is
11544 Acc_Type : Entity_Id;
11545 Par : constant Node_Id := Parent (Derived_Type);
11548 -- When the type is an anonymous access type, create a new access
11549 -- type designating the derived type. This itype must be elaborated
11550 -- at the point of the derivation, not on subsequent calls that may
11551 -- be out of the proper scope for Gigi, so we insert a reference to
11552 -- it after the derivation.
11554 if Ekind (Etype (Id)) = E_Anonymous_Access_Type then
11556 Desig_Typ : Entity_Id := Designated_Type (Etype (Id));
11559 if Ekind (Desig_Typ) = E_Record_Type_With_Private
11560 and then Present (Full_View (Desig_Typ))
11561 and then not Is_Private_Type (Parent_Type)
11563 Desig_Typ := Full_View (Desig_Typ);
11566 if Base_Type (Desig_Typ) = Base_Type (Parent_Type)
11568 -- Ada 2005 (AI-251): Handle also derivations of abstract
11569 -- interface primitives.
11571 or else (Is_Interface (Desig_Typ)
11572 and then not Is_Class_Wide_Type (Desig_Typ))
11574 Acc_Type := New_Copy (Etype (Id));
11575 Set_Etype (Acc_Type, Acc_Type);
11576 Set_Scope (Acc_Type, New_Subp);
11578 -- Compute size of anonymous access type
11580 if Is_Array_Type (Desig_Typ)
11581 and then not Is_Constrained (Desig_Typ)
11583 Init_Size (Acc_Type, 2 * System_Address_Size);
11585 Init_Size (Acc_Type, System_Address_Size);
11588 Init_Alignment (Acc_Type);
11589 Set_Directly_Designated_Type (Acc_Type, Derived_Type);
11591 Set_Etype (New_Id, Acc_Type);
11592 Set_Scope (New_Id, New_Subp);
11594 -- Create a reference to it
11595 Build_Itype_Reference (Acc_Type, Parent (Derived_Type));
11598 Set_Etype (New_Id, Etype (Id));
11602 elsif Base_Type (Etype (Id)) = Base_Type (Parent_Type)
11604 (Ekind (Etype (Id)) = E_Record_Type_With_Private
11605 and then Present (Full_View (Etype (Id)))
11607 Base_Type (Full_View (Etype (Id))) = Base_Type (Parent_Type))
11609 -- Constraint checks on formals are generated during expansion,
11610 -- based on the signature of the original subprogram. The bounds
11611 -- of the derived type are not relevant, and thus we can use
11612 -- the base type for the formals. However, the return type may be
11613 -- used in a context that requires that the proper static bounds
11614 -- be used (a case statement, for example) and for those cases
11615 -- we must use the derived type (first subtype), not its base.
11617 -- If the derived_type_definition has no constraints, we know that
11618 -- the derived type has the same constraints as the first subtype
11619 -- of the parent, and we can also use it rather than its base,
11620 -- which can lead to more efficient code.
11622 if Etype (Id) = Parent_Type then
11623 if Is_Scalar_Type (Parent_Type)
11625 Subtypes_Statically_Compatible (Parent_Type, Derived_Type)
11627 Set_Etype (New_Id, Derived_Type);
11629 elsif Nkind (Par) = N_Full_Type_Declaration
11631 Nkind (Type_Definition (Par)) = N_Derived_Type_Definition
11634 (Subtype_Indication (Type_Definition (Par)))
11636 Set_Etype (New_Id, Derived_Type);
11639 Set_Etype (New_Id, Base_Type (Derived_Type));
11643 Set_Etype (New_Id, Base_Type (Derived_Type));
11646 -- Ada 2005 (AI-251): Handle derivations of abstract interface
11649 elsif Is_Interface (Etype (Id))
11650 and then not Is_Class_Wide_Type (Etype (Id))
11651 and then Is_Progenitor (Etype (Id), Derived_Type)
11653 Set_Etype (New_Id, Derived_Type);
11656 Set_Etype (New_Id, Etype (Id));
11660 ----------------------
11661 -- Set_Derived_Name --
11662 ----------------------
11664 procedure Set_Derived_Name is
11665 Nm : constant TSS_Name_Type := Get_TSS_Name (Parent_Subp);
11667 if Nm = TSS_Null then
11668 Set_Chars (New_Subp, Chars (Parent_Subp));
11670 Set_Chars (New_Subp, Make_TSS_Name (Base_Type (Derived_Type), Nm));
11672 end Set_Derived_Name;
11676 Parent_Overrides_Interface_Primitive : Boolean := False;
11678 -- Start of processing for Derive_Subprogram
11682 New_Entity (Nkind (Parent_Subp), Sloc (Derived_Type));
11683 Set_Ekind (New_Subp, Ekind (Parent_Subp));
11685 -- Check whether the parent overrides an interface primitive
11687 if Is_Overriding_Operation (Parent_Subp) then
11689 E : Entity_Id := Parent_Subp;
11691 while Present (Overridden_Operation (E)) loop
11692 E := Ultimate_Alias (Overridden_Operation (E));
11695 Parent_Overrides_Interface_Primitive :=
11696 Is_Dispatching_Operation (E)
11697 and then Present (Find_Dispatching_Type (E))
11698 and then Is_Interface (Find_Dispatching_Type (E));
11702 -- Check whether the inherited subprogram is a private operation that
11703 -- should be inherited but not yet made visible. Such subprograms can
11704 -- become visible at a later point (e.g., the private part of a public
11705 -- child unit) via Declare_Inherited_Private_Subprograms. If the
11706 -- following predicate is true, then this is not such a private
11707 -- operation and the subprogram simply inherits the name of the parent
11708 -- subprogram. Note the special check for the names of controlled
11709 -- operations, which are currently exempted from being inherited with
11710 -- a hidden name because they must be findable for generation of
11711 -- implicit run-time calls.
11713 if not Is_Hidden (Parent_Subp)
11714 or else Is_Internal (Parent_Subp)
11715 or else Is_Private_Overriding
11716 or else Is_Internal_Name (Chars (Parent_Subp))
11717 or else Chars (Parent_Subp) = Name_Initialize
11718 or else Chars (Parent_Subp) = Name_Adjust
11719 or else Chars (Parent_Subp) = Name_Finalize
11723 -- If parent is hidden, this can be a regular derivation if the
11724 -- parent is immediately visible in a non-instantiating context,
11725 -- or if we are in the private part of an instance. This test
11726 -- should still be refined ???
11728 -- The test for In_Instance_Not_Visible avoids inheriting the derived
11729 -- operation as a non-visible operation in cases where the parent
11730 -- subprogram might not be visible now, but was visible within the
11731 -- original generic, so it would be wrong to make the inherited
11732 -- subprogram non-visible now. (Not clear if this test is fully
11733 -- correct; are there any cases where we should declare the inherited
11734 -- operation as not visible to avoid it being overridden, e.g., when
11735 -- the parent type is a generic actual with private primitives ???)
11737 -- (they should be treated the same as other private inherited
11738 -- subprograms, but it's not clear how to do this cleanly). ???
11740 elsif (In_Open_Scopes (Scope (Base_Type (Parent_Type)))
11741 and then Is_Immediately_Visible (Parent_Subp)
11742 and then not In_Instance)
11743 or else In_Instance_Not_Visible
11747 -- Ada 2005 (AI-251): Regular derivation if the parent subprogram
11748 -- overrides an interface primitive because interface primitives
11749 -- must be visible in the partial view of the parent (RM 7.3 (7.3/2))
11751 elsif Parent_Overrides_Interface_Primitive then
11754 -- The type is inheriting a private operation, so enter
11755 -- it with a special name so it can't be overridden.
11758 Set_Chars (New_Subp, New_External_Name (Chars (Parent_Subp), 'P'));
11761 Set_Parent (New_Subp, Parent (Derived_Type));
11763 if Present (Actual_Subp) then
11764 Replace_Type (Actual_Subp, New_Subp);
11766 Replace_Type (Parent_Subp, New_Subp);
11769 Conditional_Delay (New_Subp, Parent_Subp);
11771 -- If we are creating a renaming for a primitive operation of an
11772 -- actual of a generic derived type, we must examine the signature
11773 -- of the actual primitive, not that of the generic formal, which for
11774 -- example may be an interface. However the name and initial value
11775 -- of the inherited operation are those of the formal primitive.
11777 Formal := First_Formal (Parent_Subp);
11779 if Present (Actual_Subp) then
11780 Formal_Of_Actual := First_Formal (Actual_Subp);
11782 Formal_Of_Actual := Empty;
11785 while Present (Formal) loop
11786 New_Formal := New_Copy (Formal);
11788 -- Normally we do not go copying parents, but in the case of
11789 -- formals, we need to link up to the declaration (which is the
11790 -- parameter specification), and it is fine to link up to the
11791 -- original formal's parameter specification in this case.
11793 Set_Parent (New_Formal, Parent (Formal));
11794 Append_Entity (New_Formal, New_Subp);
11796 if Present (Formal_Of_Actual) then
11797 Replace_Type (Formal_Of_Actual, New_Formal);
11798 Next_Formal (Formal_Of_Actual);
11800 Replace_Type (Formal, New_Formal);
11803 Next_Formal (Formal);
11806 -- If this derivation corresponds to a tagged generic actual, then
11807 -- primitive operations rename those of the actual. Otherwise the
11808 -- primitive operations rename those of the parent type, If the parent
11809 -- renames an intrinsic operator, so does the new subprogram. We except
11810 -- concatenation, which is always properly typed, and does not get
11811 -- expanded as other intrinsic operations.
11813 if No (Actual_Subp) then
11814 if Is_Intrinsic_Subprogram (Parent_Subp) then
11815 Set_Is_Intrinsic_Subprogram (New_Subp);
11817 if Present (Alias (Parent_Subp))
11818 and then Chars (Parent_Subp) /= Name_Op_Concat
11820 Set_Alias (New_Subp, Alias (Parent_Subp));
11822 Set_Alias (New_Subp, Parent_Subp);
11826 Set_Alias (New_Subp, Parent_Subp);
11830 Set_Alias (New_Subp, Actual_Subp);
11833 -- Derived subprograms of a tagged type must inherit the convention
11834 -- of the parent subprogram (a requirement of AI-117). Derived
11835 -- subprograms of untagged types simply get convention Ada by default.
11837 if Is_Tagged_Type (Derived_Type) then
11838 Set_Convention (New_Subp, Convention (Parent_Subp));
11841 Set_Is_Imported (New_Subp, Is_Imported (Parent_Subp));
11842 Set_Is_Exported (New_Subp, Is_Exported (Parent_Subp));
11844 if Ekind (Parent_Subp) = E_Procedure then
11845 Set_Is_Valued_Procedure
11846 (New_Subp, Is_Valued_Procedure (Parent_Subp));
11849 -- No_Return must be inherited properly. If this is overridden in the
11850 -- case of a dispatching operation, then a check is made in Sem_Disp
11851 -- that the overriding operation is also No_Return (no such check is
11852 -- required for the case of non-dispatching operation.
11854 Set_No_Return (New_Subp, No_Return (Parent_Subp));
11856 -- A derived function with a controlling result is abstract. If the
11857 -- Derived_Type is a nonabstract formal generic derived type, then
11858 -- inherited operations are not abstract: the required check is done at
11859 -- instantiation time. If the derivation is for a generic actual, the
11860 -- function is not abstract unless the actual is.
11862 if Is_Generic_Type (Derived_Type)
11863 and then not Is_Abstract_Type (Derived_Type)
11867 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
11868 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2).
11870 elsif Ada_Version >= Ada_05
11871 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11872 or else (Is_Tagged_Type (Derived_Type)
11873 and then Etype (New_Subp) = Derived_Type
11874 and then not Is_Null_Extension (Derived_Type))
11875 or else (Is_Tagged_Type (Derived_Type)
11876 and then Ekind (Etype (New_Subp)) =
11877 E_Anonymous_Access_Type
11878 and then Designated_Type (Etype (New_Subp)) =
11880 and then not Is_Null_Extension (Derived_Type)))
11881 and then No (Actual_Subp)
11883 if not Is_Tagged_Type (Derived_Type)
11884 or else Is_Abstract_Type (Derived_Type)
11885 or else Is_Abstract_Subprogram (Alias (New_Subp))
11887 Set_Is_Abstract_Subprogram (New_Subp);
11889 Set_Requires_Overriding (New_Subp);
11892 elsif Ada_Version < Ada_05
11893 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11894 or else (Is_Tagged_Type (Derived_Type)
11895 and then Etype (New_Subp) = Derived_Type
11896 and then No (Actual_Subp)))
11898 Set_Is_Abstract_Subprogram (New_Subp);
11900 -- Finally, if the parent type is abstract we must verify that all
11901 -- inherited operations are either non-abstract or overridden, or that
11902 -- the derived type itself is abstract (this check is performed at the
11903 -- end of a package declaration, in Check_Abstract_Overriding). A
11904 -- private overriding in the parent type will not be visible in the
11905 -- derivation if we are not in an inner package or in a child unit of
11906 -- the parent type, in which case the abstractness of the inherited
11907 -- operation is carried to the new subprogram.
11909 elsif Is_Abstract_Type (Parent_Type)
11910 and then not In_Open_Scopes (Scope (Parent_Type))
11911 and then Is_Private_Overriding
11912 and then Is_Abstract_Subprogram (Visible_Subp)
11914 if No (Actual_Subp) then
11915 Set_Alias (New_Subp, Visible_Subp);
11916 Set_Is_Abstract_Subprogram
11919 -- If this is a derivation for an instance of a formal derived
11920 -- type, abstractness comes from the primitive operation of the
11921 -- actual, not from the operation inherited from the ancestor.
11923 Set_Is_Abstract_Subprogram
11924 (New_Subp, Is_Abstract_Subprogram (Actual_Subp));
11928 New_Overloaded_Entity (New_Subp, Derived_Type);
11930 -- Check for case of a derived subprogram for the instantiation of a
11931 -- formal derived tagged type, if so mark the subprogram as dispatching
11932 -- and inherit the dispatching attributes of the parent subprogram. The
11933 -- derived subprogram is effectively renaming of the actual subprogram,
11934 -- so it needs to have the same attributes as the actual.
11936 if Present (Actual_Subp)
11937 and then Is_Dispatching_Operation (Parent_Subp)
11939 Set_Is_Dispatching_Operation (New_Subp);
11941 if Present (DTC_Entity (Parent_Subp)) then
11942 Set_DTC_Entity (New_Subp, DTC_Entity (Parent_Subp));
11943 Set_DT_Position (New_Subp, DT_Position (Parent_Subp));
11947 -- Indicate that a derived subprogram does not require a body and that
11948 -- it does not require processing of default expressions.
11950 Set_Has_Completion (New_Subp);
11951 Set_Default_Expressions_Processed (New_Subp);
11953 if Ekind (New_Subp) = E_Function then
11954 Set_Mechanism (New_Subp, Mechanism (Parent_Subp));
11956 end Derive_Subprogram;
11958 ------------------------
11959 -- Derive_Subprograms --
11960 ------------------------
11962 procedure Derive_Subprograms
11963 (Parent_Type : Entity_Id;
11964 Derived_Type : Entity_Id;
11965 Generic_Actual : Entity_Id := Empty)
11967 Op_List : constant Elist_Id :=
11968 Collect_Primitive_Operations (Parent_Type);
11970 function Check_Derived_Type return Boolean;
11971 -- Check that all primitive inherited from Parent_Type are found in
11972 -- the list of primitives of Derived_Type exactly in the same order.
11974 function Check_Derived_Type return Boolean is
11978 New_Subp : Entity_Id;
11983 -- Traverse list of entities in the current scope searching for
11984 -- an incomplete type whose full-view is derived type
11986 E := First_Entity (Scope (Derived_Type));
11988 and then E /= Derived_Type
11990 if Ekind (E) = E_Incomplete_Type
11991 and then Present (Full_View (E))
11992 and then Full_View (E) = Derived_Type
11994 -- Disable this test if Derived_Type completes an incomplete
11995 -- type because in such case more primitives can be added
11996 -- later to the list of primitives of Derived_Type by routine
11997 -- Process_Incomplete_Dependents
12002 E := Next_Entity (E);
12005 List := Collect_Primitive_Operations (Derived_Type);
12006 Elmt := First_Elmt (List);
12008 Op_Elmt := First_Elmt (Op_List);
12009 while Present (Op_Elmt) loop
12010 Subp := Node (Op_Elmt);
12011 New_Subp := Node (Elmt);
12013 -- At this early stage Derived_Type has no entities with attribute
12014 -- Interface_Alias. In addition, such primitives are always
12015 -- located at the end of the list of primitives of Parent_Type.
12016 -- Therefore, if found we can safely stop processing pending
12019 exit when Present (Interface_Alias (Subp));
12021 -- Handle hidden entities
12023 if not Is_Predefined_Dispatching_Operation (Subp)
12024 and then Is_Hidden (Subp)
12026 if Present (New_Subp)
12027 and then Primitive_Names_Match (Subp, New_Subp)
12033 if not Present (New_Subp)
12034 or else Ekind (Subp) /= Ekind (New_Subp)
12035 or else not Primitive_Names_Match (Subp, New_Subp)
12043 Next_Elmt (Op_Elmt);
12047 end Check_Derived_Type;
12051 Alias_Subp : Entity_Id;
12052 Act_List : Elist_Id;
12053 Act_Elmt : Elmt_Id := No_Elmt;
12054 Act_Subp : Entity_Id := Empty;
12056 Need_Search : Boolean := False;
12057 New_Subp : Entity_Id := Empty;
12058 Parent_Base : Entity_Id;
12061 -- Start of processing for Derive_Subprograms
12064 if Ekind (Parent_Type) = E_Record_Type_With_Private
12065 and then Has_Discriminants (Parent_Type)
12066 and then Present (Full_View (Parent_Type))
12068 Parent_Base := Full_View (Parent_Type);
12070 Parent_Base := Parent_Type;
12073 if Present (Generic_Actual) then
12074 Act_List := Collect_Primitive_Operations (Generic_Actual);
12075 Act_Elmt := First_Elmt (Act_List);
12078 -- Derive primitives inherited from the parent. Note that if the generic
12079 -- actual is present, this is not really a type derivation, it is a
12080 -- completion within an instance.
12082 -- Case 1: Derived_Type does not implement interfaces
12084 if not Is_Tagged_Type (Derived_Type)
12085 or else (not Has_Interfaces (Derived_Type)
12086 and then not (Present (Generic_Actual)
12088 Has_Interfaces (Generic_Actual)))
12090 Elmt := First_Elmt (Op_List);
12091 while Present (Elmt) loop
12092 Subp := Node (Elmt);
12094 -- Literals are derived earlier in the process of building the
12095 -- derived type, and are skipped here.
12097 if Ekind (Subp) = E_Enumeration_Literal then
12100 -- The actual is a direct descendant and the common primitive
12101 -- operations appear in the same order.
12103 -- If the generic parent type is present, the derived type is an
12104 -- instance of a formal derived type, and within the instance its
12105 -- operations are those of the actual. We derive from the formal
12106 -- type but make the inherited operations aliases of the
12107 -- corresponding operations of the actual.
12111 (New_Subp, Subp, Derived_Type, Parent_Base, Node (Act_Elmt));
12113 if Present (Act_Elmt) then
12114 Next_Elmt (Act_Elmt);
12121 -- Case 2: Derived_Type implements interfaces
12124 -- If the parent type has no predefined primitives we remove
12125 -- predefined primitives from the list of primitives of generic
12126 -- actual to simplify the complexity of this algorithm.
12128 if Present (Generic_Actual) then
12130 Has_Predefined_Primitives : Boolean := False;
12133 -- Check if the parent type has predefined primitives
12135 Elmt := First_Elmt (Op_List);
12136 while Present (Elmt) loop
12137 Subp := Node (Elmt);
12139 if Is_Predefined_Dispatching_Operation (Subp)
12140 and then not Comes_From_Source (Ultimate_Alias (Subp))
12142 Has_Predefined_Primitives := True;
12149 -- Remove predefined primitives of Generic_Actual. We must use
12150 -- an auxiliary list because in case of tagged types the value
12151 -- returned by Collect_Primitive_Operations is the value stored
12152 -- in its Primitive_Operations attribute (and we don't want to
12153 -- modify its current contents).
12155 if not Has_Predefined_Primitives then
12157 Aux_List : constant Elist_Id := New_Elmt_List;
12160 Elmt := First_Elmt (Act_List);
12161 while Present (Elmt) loop
12162 Subp := Node (Elmt);
12164 if not Is_Predefined_Dispatching_Operation (Subp)
12165 or else Comes_From_Source (Subp)
12167 Append_Elmt (Subp, Aux_List);
12173 Act_List := Aux_List;
12177 Act_Elmt := First_Elmt (Act_List);
12178 Act_Subp := Node (Act_Elmt);
12182 -- Stage 1: If the generic actual is not present we derive the
12183 -- primitives inherited from the parent type. If the generic parent
12184 -- type is present, the derived type is an instance of a formal
12185 -- derived type, and within the instance its operations are those of
12186 -- the actual. We derive from the formal type but make the inherited
12187 -- operations aliases of the corresponding operations of the actual.
12189 Elmt := First_Elmt (Op_List);
12190 while Present (Elmt) loop
12191 Subp := Node (Elmt);
12192 Alias_Subp := Ultimate_Alias (Subp);
12194 -- At this early stage Derived_Type has no entities with attribute
12195 -- Interface_Alias. In addition, such primitives are always
12196 -- located at the end of the list of primitives of Parent_Type.
12197 -- Therefore, if found we can safely stop processing pending
12200 exit when Present (Interface_Alias (Subp));
12202 -- If the generic actual is present find the corresponding
12203 -- operation in the generic actual. If the parent type is a
12204 -- direct ancestor of the derived type then, even if it is an
12205 -- interface, the operations are inherited from the primary
12206 -- dispatch table and are in the proper order. If we detect here
12207 -- that primitives are not in the same order we traverse the list
12208 -- of primitive operations of the actual to find the one that
12209 -- implements the interface primitive.
12213 (Present (Generic_Actual)
12214 and then Present (Act_Subp)
12215 and then not Primitive_Names_Match (Subp, Act_Subp))
12217 pragma Assert (not Is_Ancestor (Parent_Base, Generic_Actual));
12218 pragma Assert (Is_Interface (Parent_Base));
12220 -- Remember that we need searching for all the pending
12223 Need_Search := True;
12225 -- Handle entities associated with interface primitives
12227 if Present (Alias (Subp))
12228 and then Is_Interface (Find_Dispatching_Type (Alias (Subp)))
12229 and then not Is_Predefined_Dispatching_Operation (Subp)
12232 Find_Primitive_Covering_Interface
12233 (Tagged_Type => Generic_Actual,
12234 Iface_Prim => Subp);
12236 -- Handle predefined primitives plus the rest of user-defined
12240 Act_Elmt := First_Elmt (Act_List);
12241 while Present (Act_Elmt) loop
12242 Act_Subp := Node (Act_Elmt);
12244 exit when Primitive_Names_Match (Subp, Act_Subp)
12245 and then Type_Conformant (Subp, Act_Subp,
12246 Skip_Controlling_Formals => True)
12247 and then No (Interface_Alias (Act_Subp));
12249 Next_Elmt (Act_Elmt);
12254 -- Case 1: If the parent is a limited interface then it has the
12255 -- predefined primitives of synchronized interfaces. However, the
12256 -- actual type may be a non-limited type and hence it does not
12257 -- have such primitives.
12259 if Present (Generic_Actual)
12260 and then not Present (Act_Subp)
12261 and then Is_Limited_Interface (Parent_Base)
12262 and then Is_Predefined_Interface_Primitive (Subp)
12266 -- Case 2: Inherit entities associated with interfaces that
12267 -- were not covered by the parent type. We exclude here null
12268 -- interface primitives because they do not need special
12271 elsif Present (Alias (Subp))
12272 and then Is_Interface (Find_Dispatching_Type (Alias_Subp))
12274 (Nkind (Parent (Alias_Subp)) = N_Procedure_Specification
12275 and then Null_Present (Parent (Alias_Subp)))
12278 (New_Subp => New_Subp,
12279 Parent_Subp => Alias_Subp,
12280 Derived_Type => Derived_Type,
12281 Parent_Type => Find_Dispatching_Type (Alias_Subp),
12282 Actual_Subp => Act_Subp);
12284 if No (Generic_Actual) then
12285 Set_Alias (New_Subp, Subp);
12288 -- Case 3: Common derivation
12292 (New_Subp => New_Subp,
12293 Parent_Subp => Subp,
12294 Derived_Type => Derived_Type,
12295 Parent_Type => Parent_Base,
12296 Actual_Subp => Act_Subp);
12299 -- No need to update Act_Elm if we must search for the
12300 -- corresponding operation in the generic actual
12303 and then Present (Act_Elmt)
12305 Next_Elmt (Act_Elmt);
12306 Act_Subp := Node (Act_Elmt);
12312 -- Inherit additional operations from progenitors. If the derived
12313 -- type is a generic actual, there are not new primitive operations
12314 -- for the type because it has those of the actual, and therefore
12315 -- nothing needs to be done. The renamings generated above are not
12316 -- primitive operations, and their purpose is simply to make the
12317 -- proper operations visible within an instantiation.
12319 if No (Generic_Actual) then
12320 Derive_Progenitor_Subprograms (Parent_Base, Derived_Type);
12324 -- Final check: Direct descendants must have their primitives in the
12325 -- same order. We exclude from this test non-tagged types and instances
12326 -- of formal derived types. We skip this test if we have already
12327 -- reported serious errors in the sources.
12329 pragma Assert (not Is_Tagged_Type (Derived_Type)
12330 or else Present (Generic_Actual)
12331 or else Serious_Errors_Detected > 0
12332 or else Check_Derived_Type);
12333 end Derive_Subprograms;
12335 --------------------------------
12336 -- Derived_Standard_Character --
12337 --------------------------------
12339 procedure Derived_Standard_Character
12341 Parent_Type : Entity_Id;
12342 Derived_Type : Entity_Id)
12344 Loc : constant Source_Ptr := Sloc (N);
12345 Def : constant Node_Id := Type_Definition (N);
12346 Indic : constant Node_Id := Subtype_Indication (Def);
12347 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
12348 Implicit_Base : constant Entity_Id :=
12350 (E_Enumeration_Type, N, Derived_Type, 'B');
12356 Discard_Node (Process_Subtype (Indic, N));
12358 Set_Etype (Implicit_Base, Parent_Base);
12359 Set_Size_Info (Implicit_Base, Root_Type (Parent_Type));
12360 Set_RM_Size (Implicit_Base, RM_Size (Root_Type (Parent_Type)));
12362 Set_Is_Character_Type (Implicit_Base, True);
12363 Set_Has_Delayed_Freeze (Implicit_Base);
12365 -- The bounds of the implicit base are the bounds of the parent base.
12366 -- Note that their type is the parent base.
12368 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
12369 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
12371 Set_Scalar_Range (Implicit_Base,
12374 High_Bound => Hi));
12376 Conditional_Delay (Derived_Type, Parent_Type);
12378 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
12379 Set_Etype (Derived_Type, Implicit_Base);
12380 Set_Size_Info (Derived_Type, Parent_Type);
12382 if Unknown_RM_Size (Derived_Type) then
12383 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
12386 Set_Is_Character_Type (Derived_Type, True);
12388 if Nkind (Indic) /= N_Subtype_Indication then
12390 -- If no explicit constraint, the bounds are those
12391 -- of the parent type.
12393 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Type));
12394 Hi := New_Copy_Tree (Type_High_Bound (Parent_Type));
12395 Set_Scalar_Range (Derived_Type, Make_Range (Loc, Lo, Hi));
12398 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
12400 -- Because the implicit base is used in the conversion of the bounds, we
12401 -- have to freeze it now. This is similar to what is done for numeric
12402 -- types, and it equally suspicious, but otherwise a non-static bound
12403 -- will have a reference to an unfrozen type, which is rejected by Gigi
12404 -- (???). This requires specific care for definition of stream
12405 -- attributes. For details, see comments at the end of
12406 -- Build_Derived_Numeric_Type.
12408 Freeze_Before (N, Implicit_Base);
12409 end Derived_Standard_Character;
12411 ------------------------------
12412 -- Derived_Type_Declaration --
12413 ------------------------------
12415 procedure Derived_Type_Declaration
12418 Is_Completion : Boolean)
12420 Parent_Type : Entity_Id;
12422 function Comes_From_Generic (Typ : Entity_Id) return Boolean;
12423 -- Check whether the parent type is a generic formal, or derives
12424 -- directly or indirectly from one.
12426 ------------------------
12427 -- Comes_From_Generic --
12428 ------------------------
12430 function Comes_From_Generic (Typ : Entity_Id) return Boolean is
12432 if Is_Generic_Type (Typ) then
12435 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
12438 elsif Is_Private_Type (Typ)
12439 and then Present (Full_View (Typ))
12440 and then Is_Generic_Type (Root_Type (Full_View (Typ)))
12444 elsif Is_Generic_Actual_Type (Typ) then
12450 end Comes_From_Generic;
12454 Def : constant Node_Id := Type_Definition (N);
12455 Iface_Def : Node_Id;
12456 Indic : constant Node_Id := Subtype_Indication (Def);
12457 Extension : constant Node_Id := Record_Extension_Part (Def);
12458 Parent_Node : Node_Id;
12459 Parent_Scope : Entity_Id;
12462 -- Start of processing for Derived_Type_Declaration
12465 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
12467 -- Ada 2005 (AI-251): In case of interface derivation check that the
12468 -- parent is also an interface.
12470 if Interface_Present (Def) then
12471 if not Is_Interface (Parent_Type) then
12472 Diagnose_Interface (Indic, Parent_Type);
12475 Parent_Node := Parent (Base_Type (Parent_Type));
12476 Iface_Def := Type_Definition (Parent_Node);
12478 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
12479 -- other limited interfaces.
12481 if Limited_Present (Def) then
12482 if Limited_Present (Iface_Def) then
12485 elsif Protected_Present (Iface_Def) then
12487 ("(Ada 2005) limited interface cannot "
12488 & "inherit from protected interface", Indic);
12490 elsif Synchronized_Present (Iface_Def) then
12492 ("(Ada 2005) limited interface cannot "
12493 & "inherit from synchronized interface", Indic);
12495 elsif Task_Present (Iface_Def) then
12497 ("(Ada 2005) limited interface cannot "
12498 & "inherit from task interface", Indic);
12502 ("(Ada 2005) limited interface cannot "
12503 & "inherit from non-limited interface", Indic);
12506 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
12507 -- from non-limited or limited interfaces.
12509 elsif not Protected_Present (Def)
12510 and then not Synchronized_Present (Def)
12511 and then not Task_Present (Def)
12513 if Limited_Present (Iface_Def) then
12516 elsif Protected_Present (Iface_Def) then
12518 ("(Ada 2005) non-limited interface cannot "
12519 & "inherit from protected interface", Indic);
12521 elsif Synchronized_Present (Iface_Def) then
12523 ("(Ada 2005) non-limited interface cannot "
12524 & "inherit from synchronized interface", Indic);
12526 elsif Task_Present (Iface_Def) then
12528 ("(Ada 2005) non-limited interface cannot "
12529 & "inherit from task interface", Indic);
12538 if Is_Tagged_Type (Parent_Type)
12539 and then Is_Concurrent_Type (Parent_Type)
12540 and then not Is_Interface (Parent_Type)
12543 ("parent type of a record extension cannot be "
12544 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
12545 Set_Etype (T, Any_Type);
12549 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
12552 if Is_Tagged_Type (Parent_Type)
12553 and then Is_Non_Empty_List (Interface_List (Def))
12560 Intf := First (Interface_List (Def));
12561 while Present (Intf) loop
12562 T := Find_Type_Of_Subtype_Indic (Intf);
12564 if not Is_Interface (T) then
12565 Diagnose_Interface (Intf, T);
12567 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
12568 -- a limited type from having a nonlimited progenitor.
12570 elsif (Limited_Present (Def)
12571 or else (not Is_Interface (Parent_Type)
12572 and then Is_Limited_Type (Parent_Type)))
12573 and then not Is_Limited_Interface (T)
12576 ("progenitor interface& of limited type must be limited",
12585 if Parent_Type = Any_Type
12586 or else Etype (Parent_Type) = Any_Type
12587 or else (Is_Class_Wide_Type (Parent_Type)
12588 and then Etype (Parent_Type) = T)
12590 -- If Parent_Type is undefined or illegal, make new type into a
12591 -- subtype of Any_Type, and set a few attributes to prevent cascaded
12592 -- errors. If this is a self-definition, emit error now.
12595 or else T = Etype (Parent_Type)
12597 Error_Msg_N ("type cannot be used in its own definition", Indic);
12600 Set_Ekind (T, Ekind (Parent_Type));
12601 Set_Etype (T, Any_Type);
12602 Set_Scalar_Range (T, Scalar_Range (Any_Type));
12604 if Is_Tagged_Type (T) then
12605 Set_Primitive_Operations (T, New_Elmt_List);
12611 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
12612 -- an interface is special because the list of interfaces in the full
12613 -- view can be given in any order. For example:
12615 -- type A is interface;
12616 -- type B is interface and A;
12617 -- type D is new B with private;
12619 -- type D is new A and B with null record; -- 1 --
12621 -- In this case we perform the following transformation of -1-:
12623 -- type D is new B and A with null record;
12625 -- If the parent of the full-view covers the parent of the partial-view
12626 -- we have two possible cases:
12628 -- 1) They have the same parent
12629 -- 2) The parent of the full-view implements some further interfaces
12631 -- In both cases we do not need to perform the transformation. In the
12632 -- first case the source program is correct and the transformation is
12633 -- not needed; in the second case the source program does not fulfill
12634 -- the no-hidden interfaces rule (AI-396) and the error will be reported
12637 -- This transformation not only simplifies the rest of the analysis of
12638 -- this type declaration but also simplifies the correct generation of
12639 -- the object layout to the expander.
12641 if In_Private_Part (Current_Scope)
12642 and then Is_Interface (Parent_Type)
12646 Partial_View : Entity_Id;
12647 Partial_View_Parent : Entity_Id;
12648 New_Iface : Node_Id;
12651 -- Look for the associated private type declaration
12653 Partial_View := First_Entity (Current_Scope);
12655 exit when No (Partial_View)
12656 or else (Has_Private_Declaration (Partial_View)
12657 and then Full_View (Partial_View) = T);
12659 Next_Entity (Partial_View);
12662 -- If the partial view was not found then the source code has
12663 -- errors and the transformation is not needed.
12665 if Present (Partial_View) then
12666 Partial_View_Parent := Etype (Partial_View);
12668 -- If the parent of the full-view covers the parent of the
12669 -- partial-view we have nothing else to do.
12671 if Interface_Present_In_Ancestor
12672 (Parent_Type, Partial_View_Parent)
12676 -- Traverse the list of interfaces of the full-view to look
12677 -- for the parent of the partial-view and perform the tree
12681 Iface := First (Interface_List (Def));
12682 while Present (Iface) loop
12683 if Etype (Iface) = Etype (Partial_View) then
12684 Rewrite (Subtype_Indication (Def),
12685 New_Copy (Subtype_Indication
12686 (Parent (Partial_View))));
12688 New_Iface := Make_Identifier (Sloc (N),
12689 Chars (Parent_Type));
12690 Append (New_Iface, Interface_List (Def));
12692 -- Analyze the transformed code
12694 Derived_Type_Declaration (T, N, Is_Completion);
12705 -- Only composite types other than array types are allowed to have
12708 if Present (Discriminant_Specifications (N))
12709 and then (Is_Elementary_Type (Parent_Type)
12710 or else Is_Array_Type (Parent_Type))
12711 and then not Error_Posted (N)
12714 ("elementary or array type cannot have discriminants",
12715 Defining_Identifier (First (Discriminant_Specifications (N))));
12716 Set_Has_Discriminants (T, False);
12719 -- In Ada 83, a derived type defined in a package specification cannot
12720 -- be used for further derivation until the end of its visible part.
12721 -- Note that derivation in the private part of the package is allowed.
12723 if Ada_Version = Ada_83
12724 and then Is_Derived_Type (Parent_Type)
12725 and then In_Visible_Part (Scope (Parent_Type))
12727 if Ada_Version = Ada_83 and then Comes_From_Source (Indic) then
12729 ("(Ada 83): premature use of type for derivation", Indic);
12733 -- Check for early use of incomplete or private type
12735 if Ekind (Parent_Type) = E_Void
12736 or else Ekind (Parent_Type) = E_Incomplete_Type
12738 Error_Msg_N ("premature derivation of incomplete type", Indic);
12741 elsif (Is_Incomplete_Or_Private_Type (Parent_Type)
12742 and then not Comes_From_Generic (Parent_Type))
12743 or else Has_Private_Component (Parent_Type)
12745 -- The ancestor type of a formal type can be incomplete, in which
12746 -- case only the operations of the partial view are available in
12747 -- the generic. Subsequent checks may be required when the full
12748 -- view is analyzed, to verify that derivation from a tagged type
12749 -- has an extension.
12751 if Nkind (Original_Node (N)) = N_Formal_Type_Declaration then
12754 elsif No (Underlying_Type (Parent_Type))
12755 or else Has_Private_Component (Parent_Type)
12758 ("premature derivation of derived or private type", Indic);
12760 -- Flag the type itself as being in error, this prevents some
12761 -- nasty problems with subsequent uses of the malformed type.
12763 Set_Error_Posted (T);
12765 -- Check that within the immediate scope of an untagged partial
12766 -- view it's illegal to derive from the partial view if the
12767 -- full view is tagged. (7.3(7))
12769 -- We verify that the Parent_Type is a partial view by checking
12770 -- that it is not a Full_Type_Declaration (i.e. a private type or
12771 -- private extension declaration), to distinguish a partial view
12772 -- from a derivation from a private type which also appears as
12775 elsif Present (Full_View (Parent_Type))
12776 and then Nkind (Parent (Parent_Type)) /= N_Full_Type_Declaration
12777 and then not Is_Tagged_Type (Parent_Type)
12778 and then Is_Tagged_Type (Full_View (Parent_Type))
12780 Parent_Scope := Scope (T);
12781 while Present (Parent_Scope)
12782 and then Parent_Scope /= Standard_Standard
12784 if Parent_Scope = Scope (Parent_Type) then
12786 ("premature derivation from type with tagged full view",
12790 Parent_Scope := Scope (Parent_Scope);
12795 -- Check that form of derivation is appropriate
12797 Taggd := Is_Tagged_Type (Parent_Type);
12799 -- Perhaps the parent type should be changed to the class-wide type's
12800 -- specific type in this case to prevent cascading errors ???
12802 if Present (Extension) and then Is_Class_Wide_Type (Parent_Type) then
12803 Error_Msg_N ("parent type must not be a class-wide type", Indic);
12807 if Present (Extension) and then not Taggd then
12809 ("type derived from untagged type cannot have extension", Indic);
12811 elsif No (Extension) and then Taggd then
12813 -- If this declaration is within a private part (or body) of a
12814 -- generic instantiation then the derivation is allowed (the parent
12815 -- type can only appear tagged in this case if it's a generic actual
12816 -- type, since it would otherwise have been rejected in the analysis
12817 -- of the generic template).
12819 if not Is_Generic_Actual_Type (Parent_Type)
12820 or else In_Visible_Part (Scope (Parent_Type))
12823 ("type derived from tagged type must have extension", Indic);
12827 -- AI-443: Synchronized formal derived types require a private
12828 -- extension. There is no point in checking the ancestor type or
12829 -- the progenitors since the construct is wrong to begin with.
12831 if Ada_Version >= Ada_05
12832 and then Is_Generic_Type (T)
12833 and then Present (Original_Node (N))
12836 Decl : constant Node_Id := Original_Node (N);
12839 if Nkind (Decl) = N_Formal_Type_Declaration
12840 and then Nkind (Formal_Type_Definition (Decl)) =
12841 N_Formal_Derived_Type_Definition
12842 and then Synchronized_Present (Formal_Type_Definition (Decl))
12843 and then No (Extension)
12845 -- Avoid emitting a duplicate error message
12847 and then not Error_Posted (Indic)
12850 ("synchronized derived type must have extension", N);
12855 Build_Derived_Type (N, Parent_Type, T, Is_Completion);
12857 -- AI-419: The parent type of an explicitly limited derived type must
12858 -- be a limited type or a limited interface.
12860 if Limited_Present (Def) then
12861 Set_Is_Limited_Record (T);
12863 if Is_Interface (T) then
12864 Set_Is_Limited_Interface (T);
12867 if not Is_Limited_Type (Parent_Type)
12869 (not Is_Interface (Parent_Type)
12870 or else not Is_Limited_Interface (Parent_Type))
12872 Error_Msg_NE ("parent type& of limited type must be limited",
12876 end Derived_Type_Declaration;
12878 ------------------------
12879 -- Diagnose_Interface --
12880 ------------------------
12882 procedure Diagnose_Interface (N : Node_Id; E : Entity_Id) is
12884 if not Is_Interface (E)
12885 and then E /= Any_Type
12887 Error_Msg_NE ("(Ada 2005) & must be an interface", N, E);
12889 end Diagnose_Interface;
12891 ----------------------------------
12892 -- Enumeration_Type_Declaration --
12893 ----------------------------------
12895 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id) is
12902 -- Create identifier node representing lower bound
12904 B_Node := New_Node (N_Identifier, Sloc (Def));
12905 L := First (Literals (Def));
12906 Set_Chars (B_Node, Chars (L));
12907 Set_Entity (B_Node, L);
12908 Set_Etype (B_Node, T);
12909 Set_Is_Static_Expression (B_Node, True);
12911 R_Node := New_Node (N_Range, Sloc (Def));
12912 Set_Low_Bound (R_Node, B_Node);
12914 Set_Ekind (T, E_Enumeration_Type);
12915 Set_First_Literal (T, L);
12917 Set_Is_Constrained (T);
12921 -- Loop through literals of enumeration type setting pos and rep values
12922 -- except that if the Ekind is already set, then it means that the
12923 -- literal was already constructed (case of a derived type declaration
12924 -- and we should not disturb the Pos and Rep values.
12926 while Present (L) loop
12927 if Ekind (L) /= E_Enumeration_Literal then
12928 Set_Ekind (L, E_Enumeration_Literal);
12929 Set_Enumeration_Pos (L, Ev);
12930 Set_Enumeration_Rep (L, Ev);
12931 Set_Is_Known_Valid (L, True);
12935 New_Overloaded_Entity (L);
12936 Generate_Definition (L);
12937 Set_Convention (L, Convention_Intrinsic);
12939 if Nkind (L) = N_Defining_Character_Literal then
12940 Set_Is_Character_Type (T, True);
12947 -- Now create a node representing upper bound
12949 B_Node := New_Node (N_Identifier, Sloc (Def));
12950 Set_Chars (B_Node, Chars (Last (Literals (Def))));
12951 Set_Entity (B_Node, Last (Literals (Def)));
12952 Set_Etype (B_Node, T);
12953 Set_Is_Static_Expression (B_Node, True);
12955 Set_High_Bound (R_Node, B_Node);
12957 -- Initialize various fields of the type. Some of this information
12958 -- may be overwritten later through rep.clauses.
12960 Set_Scalar_Range (T, R_Node);
12961 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
12962 Set_Enum_Esize (T);
12963 Set_Enum_Pos_To_Rep (T, Empty);
12965 -- Set Discard_Names if configuration pragma set, or if there is
12966 -- a parameterless pragma in the current declarative region
12968 if Global_Discard_Names
12969 or else Discard_Names (Scope (T))
12971 Set_Discard_Names (T);
12974 -- Process end label if there is one
12976 if Present (Def) then
12977 Process_End_Label (Def, 'e', T);
12979 end Enumeration_Type_Declaration;
12981 ---------------------------------
12982 -- Expand_To_Stored_Constraint --
12983 ---------------------------------
12985 function Expand_To_Stored_Constraint
12987 Constraint : Elist_Id) return Elist_Id
12989 Explicitly_Discriminated_Type : Entity_Id;
12990 Expansion : Elist_Id;
12991 Discriminant : Entity_Id;
12993 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id;
12994 -- Find the nearest type that actually specifies discriminants
12996 ---------------------------------
12997 -- Type_With_Explicit_Discrims --
12998 ---------------------------------
13000 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id is
13001 Typ : constant E := Base_Type (Id);
13004 if Ekind (Typ) in Incomplete_Or_Private_Kind then
13005 if Present (Full_View (Typ)) then
13006 return Type_With_Explicit_Discrims (Full_View (Typ));
13010 if Has_Discriminants (Typ) then
13015 if Etype (Typ) = Typ then
13017 elsif Has_Discriminants (Typ) then
13020 return Type_With_Explicit_Discrims (Etype (Typ));
13023 end Type_With_Explicit_Discrims;
13025 -- Start of processing for Expand_To_Stored_Constraint
13029 or else Is_Empty_Elmt_List (Constraint)
13034 Explicitly_Discriminated_Type := Type_With_Explicit_Discrims (Typ);
13036 if No (Explicitly_Discriminated_Type) then
13040 Expansion := New_Elmt_List;
13043 First_Stored_Discriminant (Explicitly_Discriminated_Type);
13044 while Present (Discriminant) loop
13046 Get_Discriminant_Value (
13047 Discriminant, Explicitly_Discriminated_Type, Constraint),
13049 Next_Stored_Discriminant (Discriminant);
13053 end Expand_To_Stored_Constraint;
13055 ---------------------------
13056 -- Find_Hidden_Interface --
13057 ---------------------------
13059 function Find_Hidden_Interface
13061 Dest : Elist_Id) return Entity_Id
13064 Iface_Elmt : Elmt_Id;
13067 if Present (Src) and then Present (Dest) then
13068 Iface_Elmt := First_Elmt (Src);
13069 while Present (Iface_Elmt) loop
13070 Iface := Node (Iface_Elmt);
13072 if Is_Interface (Iface)
13073 and then not Contain_Interface (Iface, Dest)
13078 Next_Elmt (Iface_Elmt);
13083 end Find_Hidden_Interface;
13085 --------------------
13086 -- Find_Type_Name --
13087 --------------------
13089 function Find_Type_Name (N : Node_Id) return Entity_Id is
13090 Id : constant Entity_Id := Defining_Identifier (N);
13092 New_Id : Entity_Id;
13093 Prev_Par : Node_Id;
13095 procedure Tag_Mismatch;
13096 -- Diagnose a tagged partial view whose full view is untagged.
13097 -- We post the message on the full view, with a reference to
13098 -- the previous partial view. The partial view can be private
13099 -- or incomplete, and these are handled in a different manner,
13100 -- so we determine the position of the error message from the
13101 -- respective slocs of both.
13107 procedure Tag_Mismatch is
13109 if Sloc (Prev) < Sloc (Id) then
13111 ("full declaration of } must be a tagged type ", Id, Prev);
13114 ("full declaration of } must be a tagged type ", Prev, Id);
13118 -- Start processing for Find_Type_Name
13121 -- Find incomplete declaration, if one was given
13123 Prev := Current_Entity_In_Scope (Id);
13125 if Present (Prev) then
13127 -- Previous declaration exists. Error if not incomplete/private case
13128 -- except if previous declaration is implicit, etc. Enter_Name will
13129 -- emit error if appropriate.
13131 Prev_Par := Parent (Prev);
13133 if not Is_Incomplete_Or_Private_Type (Prev) then
13137 elsif not Nkind_In (N, N_Full_Type_Declaration,
13138 N_Task_Type_Declaration,
13139 N_Protected_Type_Declaration)
13141 -- Completion must be a full type declarations (RM 7.3(4))
13143 Error_Msg_Sloc := Sloc (Prev);
13144 Error_Msg_NE ("invalid completion of }", Id, Prev);
13146 -- Set scope of Id to avoid cascaded errors. Entity is never
13147 -- examined again, except when saving globals in generics.
13149 Set_Scope (Id, Current_Scope);
13152 -- Case of full declaration of incomplete type
13154 elsif Ekind (Prev) = E_Incomplete_Type then
13156 -- Indicate that the incomplete declaration has a matching full
13157 -- declaration. The defining occurrence of the incomplete
13158 -- declaration remains the visible one, and the procedure
13159 -- Get_Full_View dereferences it whenever the type is used.
13161 if Present (Full_View (Prev)) then
13162 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
13165 Set_Full_View (Prev, Id);
13166 Append_Entity (Id, Current_Scope);
13167 Set_Is_Public (Id, Is_Public (Prev));
13168 Set_Is_Internal (Id);
13171 -- Case of full declaration of private type
13174 if Nkind (Parent (Prev)) /= N_Private_Extension_Declaration then
13175 if Etype (Prev) /= Prev then
13177 -- Prev is a private subtype or a derived type, and needs
13180 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
13183 elsif Ekind (Prev) = E_Private_Type
13184 and then Nkind_In (N, N_Task_Type_Declaration,
13185 N_Protected_Type_Declaration)
13188 ("completion of nonlimited type cannot be limited", N);
13190 elsif Ekind (Prev) = E_Record_Type_With_Private
13191 and then Nkind_In (N, N_Task_Type_Declaration,
13192 N_Protected_Type_Declaration)
13194 if not Is_Limited_Record (Prev) then
13196 ("completion of nonlimited type cannot be limited", N);
13198 elsif No (Interface_List (N)) then
13200 ("completion of tagged private type must be tagged",
13205 -- Ada 2005 (AI-251): Private extension declaration of a task
13206 -- type or a protected type. This case arises when covering
13207 -- interface types.
13209 elsif Nkind_In (N, N_Task_Type_Declaration,
13210 N_Protected_Type_Declaration)
13214 elsif Nkind (N) /= N_Full_Type_Declaration
13215 or else Nkind (Type_Definition (N)) /= N_Derived_Type_Definition
13218 ("full view of private extension must be an extension", N);
13220 elsif not (Abstract_Present (Parent (Prev)))
13221 and then Abstract_Present (Type_Definition (N))
13224 ("full view of non-abstract extension cannot be abstract", N);
13227 if not In_Private_Part (Current_Scope) then
13229 ("declaration of full view must appear in private part", N);
13232 Copy_And_Swap (Prev, Id);
13233 Set_Has_Private_Declaration (Prev);
13234 Set_Has_Private_Declaration (Id);
13236 -- If no error, propagate freeze_node from private to full view.
13237 -- It may have been generated for an early operational item.
13239 if Present (Freeze_Node (Id))
13240 and then Serious_Errors_Detected = 0
13241 and then No (Full_View (Id))
13243 Set_Freeze_Node (Prev, Freeze_Node (Id));
13244 Set_Freeze_Node (Id, Empty);
13245 Set_First_Rep_Item (Prev, First_Rep_Item (Id));
13248 Set_Full_View (Id, Prev);
13252 -- Verify that full declaration conforms to partial one
13254 if Is_Incomplete_Or_Private_Type (Prev)
13255 and then Present (Discriminant_Specifications (Prev_Par))
13257 if Present (Discriminant_Specifications (N)) then
13258 if Ekind (Prev) = E_Incomplete_Type then
13259 Check_Discriminant_Conformance (N, Prev, Prev);
13261 Check_Discriminant_Conformance (N, Prev, Id);
13266 ("missing discriminants in full type declaration", N);
13268 -- To avoid cascaded errors on subsequent use, share the
13269 -- discriminants of the partial view.
13271 Set_Discriminant_Specifications (N,
13272 Discriminant_Specifications (Prev_Par));
13276 -- A prior untagged partial view can have an associated class-wide
13277 -- type due to use of the class attribute, and in this case the full
13278 -- type must also be tagged. This Ada 95 usage is deprecated in favor
13279 -- of incomplete tagged declarations, but we check for it.
13282 and then (Is_Tagged_Type (Prev)
13283 or else Present (Class_Wide_Type (Prev)))
13285 -- The full declaration is either a tagged type (including
13286 -- a synchronized type that implements interfaces) or a
13287 -- type extension, otherwise this is an error.
13289 if Nkind_In (N, N_Task_Type_Declaration,
13290 N_Protected_Type_Declaration)
13292 if No (Interface_List (N))
13293 and then not Error_Posted (N)
13298 elsif Nkind (Type_Definition (N)) = N_Record_Definition then
13300 -- Indicate that the previous declaration (tagged incomplete
13301 -- or private declaration) requires the same on the full one.
13303 if not Tagged_Present (Type_Definition (N)) then
13305 Set_Is_Tagged_Type (Id);
13306 Set_Primitive_Operations (Id, New_Elmt_List);
13309 elsif Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
13310 if No (Record_Extension_Part (Type_Definition (N))) then
13312 "full declaration of } must be a record extension",
13314 Set_Is_Tagged_Type (Id);
13315 Set_Primitive_Operations (Id, New_Elmt_List);
13326 -- New type declaration
13331 end Find_Type_Name;
13333 -------------------------
13334 -- Find_Type_Of_Object --
13335 -------------------------
13337 function Find_Type_Of_Object
13338 (Obj_Def : Node_Id;
13339 Related_Nod : Node_Id) return Entity_Id
13341 Def_Kind : constant Node_Kind := Nkind (Obj_Def);
13342 P : Node_Id := Parent (Obj_Def);
13347 -- If the parent is a component_definition node we climb to the
13348 -- component_declaration node
13350 if Nkind (P) = N_Component_Definition then
13354 -- Case of an anonymous array subtype
13356 if Nkind_In (Def_Kind, N_Constrained_Array_Definition,
13357 N_Unconstrained_Array_Definition)
13360 Array_Type_Declaration (T, Obj_Def);
13362 -- Create an explicit subtype whenever possible
13364 elsif Nkind (P) /= N_Component_Declaration
13365 and then Def_Kind = N_Subtype_Indication
13367 -- Base name of subtype on object name, which will be unique in
13368 -- the current scope.
13370 -- If this is a duplicate declaration, return base type, to avoid
13371 -- generating duplicate anonymous types.
13373 if Error_Posted (P) then
13374 Analyze (Subtype_Mark (Obj_Def));
13375 return Entity (Subtype_Mark (Obj_Def));
13380 (Chars (Defining_Identifier (Related_Nod)), 'S', 0, 'T');
13382 T := Make_Defining_Identifier (Sloc (P), Nam);
13384 Insert_Action (Obj_Def,
13385 Make_Subtype_Declaration (Sloc (P),
13386 Defining_Identifier => T,
13387 Subtype_Indication => Relocate_Node (Obj_Def)));
13389 -- This subtype may need freezing, and this will not be done
13390 -- automatically if the object declaration is not in declarative
13391 -- part. Since this is an object declaration, the type cannot always
13392 -- be frozen here. Deferred constants do not freeze their type
13393 -- (which often enough will be private).
13395 if Nkind (P) = N_Object_Declaration
13396 and then Constant_Present (P)
13397 and then No (Expression (P))
13401 Insert_Actions (Obj_Def, Freeze_Entity (T, Sloc (P)));
13404 -- Ada 2005 AI-406: the object definition in an object declaration
13405 -- can be an access definition.
13407 elsif Def_Kind = N_Access_Definition then
13408 T := Access_Definition (Related_Nod, Obj_Def);
13409 Set_Is_Local_Anonymous_Access (T);
13411 -- Otherwise, the object definition is just a subtype_mark
13414 T := Process_Subtype (Obj_Def, Related_Nod);
13418 end Find_Type_Of_Object;
13420 --------------------------------
13421 -- Find_Type_Of_Subtype_Indic --
13422 --------------------------------
13424 function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id is
13428 -- Case of subtype mark with a constraint
13430 if Nkind (S) = N_Subtype_Indication then
13431 Find_Type (Subtype_Mark (S));
13432 Typ := Entity (Subtype_Mark (S));
13435 Is_Valid_Constraint_Kind (Ekind (Typ), Nkind (Constraint (S)))
13438 ("incorrect constraint for this kind of type", Constraint (S));
13439 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
13442 -- Otherwise we have a subtype mark without a constraint
13444 elsif Error_Posted (S) then
13445 Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S)));
13453 -- Check No_Wide_Characters restriction
13455 if Typ = Standard_Wide_Character
13456 or else Typ = Standard_Wide_Wide_Character
13457 or else Typ = Standard_Wide_String
13458 or else Typ = Standard_Wide_Wide_String
13460 Check_Restriction (No_Wide_Characters, S);
13464 end Find_Type_Of_Subtype_Indic;
13466 -------------------------------------
13467 -- Floating_Point_Type_Declaration --
13468 -------------------------------------
13470 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is
13471 Digs : constant Node_Id := Digits_Expression (Def);
13473 Base_Typ : Entity_Id;
13474 Implicit_Base : Entity_Id;
13477 function Can_Derive_From (E : Entity_Id) return Boolean;
13478 -- Find if given digits value allows derivation from specified type
13480 ---------------------
13481 -- Can_Derive_From --
13482 ---------------------
13484 function Can_Derive_From (E : Entity_Id) return Boolean is
13485 Spec : constant Entity_Id := Real_Range_Specification (Def);
13488 if Digs_Val > Digits_Value (E) then
13492 if Present (Spec) then
13493 if Expr_Value_R (Type_Low_Bound (E)) >
13494 Expr_Value_R (Low_Bound (Spec))
13499 if Expr_Value_R (Type_High_Bound (E)) <
13500 Expr_Value_R (High_Bound (Spec))
13507 end Can_Derive_From;
13509 -- Start of processing for Floating_Point_Type_Declaration
13512 Check_Restriction (No_Floating_Point, Def);
13514 -- Create an implicit base type
13517 Create_Itype (E_Floating_Point_Type, Parent (Def), T, 'B');
13519 -- Analyze and verify digits value
13521 Analyze_And_Resolve (Digs, Any_Integer);
13522 Check_Digits_Expression (Digs);
13523 Digs_Val := Expr_Value (Digs);
13525 -- Process possible range spec and find correct type to derive from
13527 Process_Real_Range_Specification (Def);
13529 if Can_Derive_From (Standard_Short_Float) then
13530 Base_Typ := Standard_Short_Float;
13531 elsif Can_Derive_From (Standard_Float) then
13532 Base_Typ := Standard_Float;
13533 elsif Can_Derive_From (Standard_Long_Float) then
13534 Base_Typ := Standard_Long_Float;
13535 elsif Can_Derive_From (Standard_Long_Long_Float) then
13536 Base_Typ := Standard_Long_Long_Float;
13538 -- If we can't derive from any existing type, use long_long_float
13539 -- and give appropriate message explaining the problem.
13542 Base_Typ := Standard_Long_Long_Float;
13544 if Digs_Val >= Digits_Value (Standard_Long_Long_Float) then
13545 Error_Msg_Uint_1 := Digits_Value (Standard_Long_Long_Float);
13546 Error_Msg_N ("digits value out of range, maximum is ^", Digs);
13550 ("range too large for any predefined type",
13551 Real_Range_Specification (Def));
13555 -- If there are bounds given in the declaration use them as the bounds
13556 -- of the type, otherwise use the bounds of the predefined base type
13557 -- that was chosen based on the Digits value.
13559 if Present (Real_Range_Specification (Def)) then
13560 Set_Scalar_Range (T, Real_Range_Specification (Def));
13561 Set_Is_Constrained (T);
13563 -- The bounds of this range must be converted to machine numbers
13564 -- in accordance with RM 4.9(38).
13566 Bound := Type_Low_Bound (T);
13568 if Nkind (Bound) = N_Real_Literal then
13570 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13571 Set_Is_Machine_Number (Bound);
13574 Bound := Type_High_Bound (T);
13576 if Nkind (Bound) = N_Real_Literal then
13578 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13579 Set_Is_Machine_Number (Bound);
13583 Set_Scalar_Range (T, Scalar_Range (Base_Typ));
13586 -- Complete definition of implicit base and declared first subtype
13588 Set_Etype (Implicit_Base, Base_Typ);
13590 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
13591 Set_Size_Info (Implicit_Base, (Base_Typ));
13592 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
13593 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
13594 Set_Digits_Value (Implicit_Base, Digits_Value (Base_Typ));
13595 Set_Vax_Float (Implicit_Base, Vax_Float (Base_Typ));
13597 Set_Ekind (T, E_Floating_Point_Subtype);
13598 Set_Etype (T, Implicit_Base);
13600 Set_Size_Info (T, (Implicit_Base));
13601 Set_RM_Size (T, RM_Size (Implicit_Base));
13602 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
13603 Set_Digits_Value (T, Digs_Val);
13604 end Floating_Point_Type_Declaration;
13606 ----------------------------
13607 -- Get_Discriminant_Value --
13608 ----------------------------
13610 -- This is the situation:
13612 -- There is a non-derived type
13614 -- type T0 (Dx, Dy, Dz...)
13616 -- There are zero or more levels of derivation, with each derivation
13617 -- either purely inheriting the discriminants, or defining its own.
13619 -- type Ti is new Ti-1
13621 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
13623 -- subtype Ti is ...
13625 -- The subtype issue is avoided by the use of Original_Record_Component,
13626 -- and the fact that derived subtypes also derive the constraints.
13628 -- This chain leads back from
13630 -- Typ_For_Constraint
13632 -- Typ_For_Constraint has discriminants, and the value for each
13633 -- discriminant is given by its corresponding Elmt of Constraints.
13635 -- Discriminant is some discriminant in this hierarchy
13637 -- We need to return its value
13639 -- We do this by recursively searching each level, and looking for
13640 -- Discriminant. Once we get to the bottom, we start backing up
13641 -- returning the value for it which may in turn be a discriminant
13642 -- further up, so on the backup we continue the substitution.
13644 function Get_Discriminant_Value
13645 (Discriminant : Entity_Id;
13646 Typ_For_Constraint : Entity_Id;
13647 Constraint : Elist_Id) return Node_Id
13649 function Search_Derivation_Levels
13651 Discrim_Values : Elist_Id;
13652 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id;
13653 -- This is the routine that performs the recursive search of levels
13654 -- as described above.
13656 ------------------------------
13657 -- Search_Derivation_Levels --
13658 ------------------------------
13660 function Search_Derivation_Levels
13662 Discrim_Values : Elist_Id;
13663 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id
13667 Result : Node_Or_Entity_Id;
13668 Result_Entity : Node_Id;
13671 -- If inappropriate type, return Error, this happens only in
13672 -- cascaded error situations, and we want to avoid a blow up.
13674 if not Is_Composite_Type (Ti) or else Is_Array_Type (Ti) then
13678 -- Look deeper if possible. Use Stored_Constraints only for
13679 -- untagged types. For tagged types use the given constraint.
13680 -- This asymmetry needs explanation???
13682 if not Stored_Discrim_Values
13683 and then Present (Stored_Constraint (Ti))
13684 and then not Is_Tagged_Type (Ti)
13687 Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True);
13690 Td : constant Entity_Id := Etype (Ti);
13694 Result := Discriminant;
13697 if Present (Stored_Constraint (Ti)) then
13699 Search_Derivation_Levels
13700 (Td, Stored_Constraint (Ti), True);
13703 Search_Derivation_Levels
13704 (Td, Discrim_Values, Stored_Discrim_Values);
13710 -- Extra underlying places to search, if not found above. For
13711 -- concurrent types, the relevant discriminant appears in the
13712 -- corresponding record. For a type derived from a private type
13713 -- without discriminant, the full view inherits the discriminants
13714 -- of the full view of the parent.
13716 if Result = Discriminant then
13717 if Is_Concurrent_Type (Ti)
13718 and then Present (Corresponding_Record_Type (Ti))
13721 Search_Derivation_Levels (
13722 Corresponding_Record_Type (Ti),
13724 Stored_Discrim_Values);
13726 elsif Is_Private_Type (Ti)
13727 and then not Has_Discriminants (Ti)
13728 and then Present (Full_View (Ti))
13729 and then Etype (Full_View (Ti)) /= Ti
13732 Search_Derivation_Levels (
13735 Stored_Discrim_Values);
13739 -- If Result is not a (reference to a) discriminant, return it,
13740 -- otherwise set Result_Entity to the discriminant.
13742 if Nkind (Result) = N_Defining_Identifier then
13743 pragma Assert (Result = Discriminant);
13744 Result_Entity := Result;
13747 if not Denotes_Discriminant (Result) then
13751 Result_Entity := Entity (Result);
13754 -- See if this level of derivation actually has discriminants
13755 -- because tagged derivations can add them, hence the lower
13756 -- levels need not have any.
13758 if not Has_Discriminants (Ti) then
13762 -- Scan Ti's discriminants for Result_Entity,
13763 -- and return its corresponding value, if any.
13765 Result_Entity := Original_Record_Component (Result_Entity);
13767 Assoc := First_Elmt (Discrim_Values);
13769 if Stored_Discrim_Values then
13770 Disc := First_Stored_Discriminant (Ti);
13772 Disc := First_Discriminant (Ti);
13775 while Present (Disc) loop
13776 pragma Assert (Present (Assoc));
13778 if Original_Record_Component (Disc) = Result_Entity then
13779 return Node (Assoc);
13784 if Stored_Discrim_Values then
13785 Next_Stored_Discriminant (Disc);
13787 Next_Discriminant (Disc);
13791 -- Could not find it
13794 end Search_Derivation_Levels;
13798 Result : Node_Or_Entity_Id;
13800 -- Start of processing for Get_Discriminant_Value
13803 -- ??? This routine is a gigantic mess and will be deleted. For the
13804 -- time being just test for the trivial case before calling recurse.
13806 if Base_Type (Scope (Discriminant)) = Base_Type (Typ_For_Constraint) then
13812 D := First_Discriminant (Typ_For_Constraint);
13813 E := First_Elmt (Constraint);
13814 while Present (D) loop
13815 if Chars (D) = Chars (Discriminant) then
13819 Next_Discriminant (D);
13825 Result := Search_Derivation_Levels
13826 (Typ_For_Constraint, Constraint, False);
13828 -- ??? hack to disappear when this routine is gone
13830 if Nkind (Result) = N_Defining_Identifier then
13836 D := First_Discriminant (Typ_For_Constraint);
13837 E := First_Elmt (Constraint);
13838 while Present (D) loop
13839 if Corresponding_Discriminant (D) = Discriminant then
13843 Next_Discriminant (D);
13849 pragma Assert (Nkind (Result) /= N_Defining_Identifier);
13851 end Get_Discriminant_Value;
13853 --------------------------
13854 -- Has_Range_Constraint --
13855 --------------------------
13857 function Has_Range_Constraint (N : Node_Id) return Boolean is
13858 C : constant Node_Id := Constraint (N);
13861 if Nkind (C) = N_Range_Constraint then
13864 elsif Nkind (C) = N_Digits_Constraint then
13866 Is_Decimal_Fixed_Point_Type (Entity (Subtype_Mark (N)))
13868 Present (Range_Constraint (C));
13870 elsif Nkind (C) = N_Delta_Constraint then
13871 return Present (Range_Constraint (C));
13876 end Has_Range_Constraint;
13878 ------------------------
13879 -- Inherit_Components --
13880 ------------------------
13882 function Inherit_Components
13884 Parent_Base : Entity_Id;
13885 Derived_Base : Entity_Id;
13886 Is_Tagged : Boolean;
13887 Inherit_Discr : Boolean;
13888 Discs : Elist_Id) return Elist_Id
13890 Assoc_List : constant Elist_Id := New_Elmt_List;
13892 procedure Inherit_Component
13893 (Old_C : Entity_Id;
13894 Plain_Discrim : Boolean := False;
13895 Stored_Discrim : Boolean := False);
13896 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
13897 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
13898 -- True, Old_C is a stored discriminant. If they are both false then
13899 -- Old_C is a regular component.
13901 -----------------------
13902 -- Inherit_Component --
13903 -----------------------
13905 procedure Inherit_Component
13906 (Old_C : Entity_Id;
13907 Plain_Discrim : Boolean := False;
13908 Stored_Discrim : Boolean := False)
13910 New_C : constant Entity_Id := New_Copy (Old_C);
13912 Discrim : Entity_Id;
13913 Corr_Discrim : Entity_Id;
13916 pragma Assert (not Is_Tagged or else not Stored_Discrim);
13918 Set_Parent (New_C, Parent (Old_C));
13920 -- Regular discriminants and components must be inserted in the scope
13921 -- of the Derived_Base. Do it here.
13923 if not Stored_Discrim then
13924 Enter_Name (New_C);
13927 -- For tagged types the Original_Record_Component must point to
13928 -- whatever this field was pointing to in the parent type. This has
13929 -- already been achieved by the call to New_Copy above.
13931 if not Is_Tagged then
13932 Set_Original_Record_Component (New_C, New_C);
13935 -- If we have inherited a component then see if its Etype contains
13936 -- references to Parent_Base discriminants. In this case, replace
13937 -- these references with the constraints given in Discs. We do not
13938 -- do this for the partial view of private types because this is
13939 -- not needed (only the components of the full view will be used
13940 -- for code generation) and cause problem. We also avoid this
13941 -- transformation in some error situations.
13943 if Ekind (New_C) = E_Component then
13944 if (Is_Private_Type (Derived_Base)
13945 and then not Is_Generic_Type (Derived_Base))
13946 or else (Is_Empty_Elmt_List (Discs)
13947 and then not Expander_Active)
13949 Set_Etype (New_C, Etype (Old_C));
13952 -- The current component introduces a circularity of the
13955 -- limited with Pack_2;
13956 -- package Pack_1 is
13957 -- type T_1 is tagged record
13958 -- Comp : access Pack_2.T_2;
13964 -- package Pack_2 is
13965 -- type T_2 is new Pack_1.T_1 with ...;
13970 Constrain_Component_Type
13971 (Old_C, Derived_Base, N, Parent_Base, Discs));
13975 -- In derived tagged types it is illegal to reference a non
13976 -- discriminant component in the parent type. To catch this, mark
13977 -- these components with an Ekind of E_Void. This will be reset in
13978 -- Record_Type_Definition after processing the record extension of
13979 -- the derived type.
13981 -- If the declaration is a private extension, there is no further
13982 -- record extension to process, and the components retain their
13983 -- current kind, because they are visible at this point.
13985 if Is_Tagged and then Ekind (New_C) = E_Component
13986 and then Nkind (N) /= N_Private_Extension_Declaration
13988 Set_Ekind (New_C, E_Void);
13991 if Plain_Discrim then
13992 Set_Corresponding_Discriminant (New_C, Old_C);
13993 Build_Discriminal (New_C);
13995 -- If we are explicitly inheriting a stored discriminant it will be
13996 -- completely hidden.
13998 elsif Stored_Discrim then
13999 Set_Corresponding_Discriminant (New_C, Empty);
14000 Set_Discriminal (New_C, Empty);
14001 Set_Is_Completely_Hidden (New_C);
14003 -- Set the Original_Record_Component of each discriminant in the
14004 -- derived base to point to the corresponding stored that we just
14007 Discrim := First_Discriminant (Derived_Base);
14008 while Present (Discrim) loop
14009 Corr_Discrim := Corresponding_Discriminant (Discrim);
14011 -- Corr_Discrim could be missing in an error situation
14013 if Present (Corr_Discrim)
14014 and then Original_Record_Component (Corr_Discrim) = Old_C
14016 Set_Original_Record_Component (Discrim, New_C);
14019 Next_Discriminant (Discrim);
14022 Append_Entity (New_C, Derived_Base);
14025 if not Is_Tagged then
14026 Append_Elmt (Old_C, Assoc_List);
14027 Append_Elmt (New_C, Assoc_List);
14029 end Inherit_Component;
14031 -- Variables local to Inherit_Component
14033 Loc : constant Source_Ptr := Sloc (N);
14035 Parent_Discrim : Entity_Id;
14036 Stored_Discrim : Entity_Id;
14038 Component : Entity_Id;
14040 -- Start of processing for Inherit_Components
14043 if not Is_Tagged then
14044 Append_Elmt (Parent_Base, Assoc_List);
14045 Append_Elmt (Derived_Base, Assoc_List);
14048 -- Inherit parent discriminants if needed
14050 if Inherit_Discr then
14051 Parent_Discrim := First_Discriminant (Parent_Base);
14052 while Present (Parent_Discrim) loop
14053 Inherit_Component (Parent_Discrim, Plain_Discrim => True);
14054 Next_Discriminant (Parent_Discrim);
14058 -- Create explicit stored discrims for untagged types when necessary
14060 if not Has_Unknown_Discriminants (Derived_Base)
14061 and then Has_Discriminants (Parent_Base)
14062 and then not Is_Tagged
14065 or else First_Discriminant (Parent_Base) /=
14066 First_Stored_Discriminant (Parent_Base))
14068 Stored_Discrim := First_Stored_Discriminant (Parent_Base);
14069 while Present (Stored_Discrim) loop
14070 Inherit_Component (Stored_Discrim, Stored_Discrim => True);
14071 Next_Stored_Discriminant (Stored_Discrim);
14075 -- See if we can apply the second transformation for derived types, as
14076 -- explained in point 6. in the comments above Build_Derived_Record_Type
14077 -- This is achieved by appending Derived_Base discriminants into Discs,
14078 -- which has the side effect of returning a non empty Discs list to the
14079 -- caller of Inherit_Components, which is what we want. This must be
14080 -- done for private derived types if there are explicit stored
14081 -- discriminants, to ensure that we can retrieve the values of the
14082 -- constraints provided in the ancestors.
14085 and then Is_Empty_Elmt_List (Discs)
14086 and then Present (First_Discriminant (Derived_Base))
14088 (not Is_Private_Type (Derived_Base)
14089 or else Is_Completely_Hidden
14090 (First_Stored_Discriminant (Derived_Base))
14091 or else Is_Generic_Type (Derived_Base))
14093 D := First_Discriminant (Derived_Base);
14094 while Present (D) loop
14095 Append_Elmt (New_Reference_To (D, Loc), Discs);
14096 Next_Discriminant (D);
14100 -- Finally, inherit non-discriminant components unless they are not
14101 -- visible because defined or inherited from the full view of the
14102 -- parent. Don't inherit the _parent field of the parent type.
14104 Component := First_Entity (Parent_Base);
14105 while Present (Component) loop
14107 -- Ada 2005 (AI-251): Do not inherit components associated with
14108 -- secondary tags of the parent.
14110 if Ekind (Component) = E_Component
14111 and then Present (Related_Type (Component))
14115 elsif Ekind (Component) /= E_Component
14116 or else Chars (Component) = Name_uParent
14120 -- If the derived type is within the parent type's declarative
14121 -- region, then the components can still be inherited even though
14122 -- they aren't visible at this point. This can occur for cases
14123 -- such as within public child units where the components must
14124 -- become visible upon entering the child unit's private part.
14126 elsif not Is_Visible_Component (Component)
14127 and then not In_Open_Scopes (Scope (Parent_Base))
14131 elsif Ekind (Derived_Base) = E_Private_Type
14132 or else Ekind (Derived_Base) = E_Limited_Private_Type
14137 Inherit_Component (Component);
14140 Next_Entity (Component);
14143 -- For tagged derived types, inherited discriminants cannot be used in
14144 -- component declarations of the record extension part. To achieve this
14145 -- we mark the inherited discriminants as not visible.
14147 if Is_Tagged and then Inherit_Discr then
14148 D := First_Discriminant (Derived_Base);
14149 while Present (D) loop
14150 Set_Is_Immediately_Visible (D, False);
14151 Next_Discriminant (D);
14156 end Inherit_Components;
14158 -----------------------
14159 -- Is_Null_Extension --
14160 -----------------------
14162 function Is_Null_Extension (T : Entity_Id) return Boolean is
14163 Type_Decl : constant Node_Id := Parent (T);
14164 Comp_List : Node_Id;
14168 if Nkind (Type_Decl) /= N_Full_Type_Declaration
14169 or else not Is_Tagged_Type (T)
14170 or else Nkind (Type_Definition (Type_Decl)) /=
14171 N_Derived_Type_Definition
14172 or else No (Record_Extension_Part (Type_Definition (Type_Decl)))
14178 Component_List (Record_Extension_Part (Type_Definition (Type_Decl)));
14180 if Present (Discriminant_Specifications (Type_Decl)) then
14183 elsif Present (Comp_List)
14184 and then Is_Non_Empty_List (Component_Items (Comp_List))
14186 Comp := First (Component_Items (Comp_List));
14188 -- Only user-defined components are relevant. The component list
14189 -- may also contain a parent component and internal components
14190 -- corresponding to secondary tags, but these do not determine
14191 -- whether this is a null extension.
14193 while Present (Comp) loop
14194 if Comes_From_Source (Comp) then
14205 end Is_Null_Extension;
14207 --------------------
14208 -- Is_Progenitor --
14209 --------------------
14211 function Is_Progenitor
14212 (Iface : Entity_Id;
14213 Typ : Entity_Id) return Boolean
14216 return Implements_Interface (Typ, Iface,
14217 Exclude_Parents => True);
14220 ------------------------------
14221 -- Is_Valid_Constraint_Kind --
14222 ------------------------------
14224 function Is_Valid_Constraint_Kind
14225 (T_Kind : Type_Kind;
14226 Constraint_Kind : Node_Kind) return Boolean
14230 when Enumeration_Kind |
14232 return Constraint_Kind = N_Range_Constraint;
14234 when Decimal_Fixed_Point_Kind =>
14235 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14236 N_Range_Constraint);
14238 when Ordinary_Fixed_Point_Kind =>
14239 return Nkind_In (Constraint_Kind, N_Delta_Constraint,
14240 N_Range_Constraint);
14243 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14244 N_Range_Constraint);
14251 E_Incomplete_Type |
14254 return Constraint_Kind = N_Index_Or_Discriminant_Constraint;
14257 return True; -- Error will be detected later
14259 end Is_Valid_Constraint_Kind;
14261 --------------------------
14262 -- Is_Visible_Component --
14263 --------------------------
14265 function Is_Visible_Component (C : Entity_Id) return Boolean is
14266 Original_Comp : Entity_Id := Empty;
14267 Original_Scope : Entity_Id;
14268 Type_Scope : Entity_Id;
14270 function Is_Local_Type (Typ : Entity_Id) return Boolean;
14271 -- Check whether parent type of inherited component is declared locally,
14272 -- possibly within a nested package or instance. The current scope is
14273 -- the derived record itself.
14275 -------------------
14276 -- Is_Local_Type --
14277 -------------------
14279 function Is_Local_Type (Typ : Entity_Id) return Boolean is
14283 Scop := Scope (Typ);
14284 while Present (Scop)
14285 and then Scop /= Standard_Standard
14287 if Scop = Scope (Current_Scope) then
14291 Scop := Scope (Scop);
14297 -- Start of processing for Is_Visible_Component
14300 if Ekind (C) = E_Component
14301 or else Ekind (C) = E_Discriminant
14303 Original_Comp := Original_Record_Component (C);
14306 if No (Original_Comp) then
14308 -- Premature usage, or previous error
14313 Original_Scope := Scope (Original_Comp);
14314 Type_Scope := Scope (Base_Type (Scope (C)));
14317 -- This test only concerns tagged types
14319 if not Is_Tagged_Type (Original_Scope) then
14322 -- If it is _Parent or _Tag, there is no visibility issue
14324 elsif not Comes_From_Source (Original_Comp) then
14327 -- If we are in the body of an instantiation, the component is visible
14328 -- even when the parent type (possibly defined in an enclosing unit or
14329 -- in a parent unit) might not.
14331 elsif In_Instance_Body then
14334 -- Discriminants are always visible
14336 elsif Ekind (Original_Comp) = E_Discriminant
14337 and then not Has_Unknown_Discriminants (Original_Scope)
14341 -- If the component has been declared in an ancestor which is currently
14342 -- a private type, then it is not visible. The same applies if the
14343 -- component's containing type is not in an open scope and the original
14344 -- component's enclosing type is a visible full view of a private type
14345 -- (which can occur in cases where an attempt is being made to reference
14346 -- a component in a sibling package that is inherited from a visible
14347 -- component of a type in an ancestor package; the component in the
14348 -- sibling package should not be visible even though the component it
14349 -- inherited from is visible). This does not apply however in the case
14350 -- where the scope of the type is a private child unit, or when the
14351 -- parent comes from a local package in which the ancestor is currently
14352 -- visible. The latter suppression of visibility is needed for cases
14353 -- that are tested in B730006.
14355 elsif Is_Private_Type (Original_Scope)
14357 (not Is_Private_Descendant (Type_Scope)
14358 and then not In_Open_Scopes (Type_Scope)
14359 and then Has_Private_Declaration (Original_Scope))
14361 -- If the type derives from an entity in a formal package, there
14362 -- are no additional visible components.
14364 if Nkind (Original_Node (Unit_Declaration_Node (Type_Scope))) =
14365 N_Formal_Package_Declaration
14369 -- if we are not in the private part of the current package, there
14370 -- are no additional visible components.
14372 elsif Ekind (Scope (Current_Scope)) = E_Package
14373 and then not In_Private_Part (Scope (Current_Scope))
14378 Is_Child_Unit (Cunit_Entity (Current_Sem_Unit))
14379 and then In_Open_Scopes (Scope (Original_Scope))
14380 and then Is_Local_Type (Type_Scope);
14383 -- There is another weird way in which a component may be invisible
14384 -- when the private and the full view are not derived from the same
14385 -- ancestor. Here is an example :
14387 -- type A1 is tagged record F1 : integer; end record;
14388 -- type A2 is new A1 with record F2 : integer; end record;
14389 -- type T is new A1 with private;
14391 -- type T is new A2 with null record;
14393 -- In this case, the full view of T inherits F1 and F2 but the private
14394 -- view inherits only F1
14398 Ancestor : Entity_Id := Scope (C);
14402 if Ancestor = Original_Scope then
14404 elsif Ancestor = Etype (Ancestor) then
14408 Ancestor := Etype (Ancestor);
14412 end Is_Visible_Component;
14414 --------------------------
14415 -- Make_Class_Wide_Type --
14416 --------------------------
14418 procedure Make_Class_Wide_Type (T : Entity_Id) is
14419 CW_Type : Entity_Id;
14421 Next_E : Entity_Id;
14424 -- The class wide type can have been defined by the partial view, in
14425 -- which case everything is already done.
14427 if Present (Class_Wide_Type (T)) then
14432 New_External_Entity (E_Void, Scope (T), Sloc (T), T, 'C', 0, 'T');
14434 -- Inherit root type characteristics
14436 CW_Name := Chars (CW_Type);
14437 Next_E := Next_Entity (CW_Type);
14438 Copy_Node (T, CW_Type);
14439 Set_Comes_From_Source (CW_Type, False);
14440 Set_Chars (CW_Type, CW_Name);
14441 Set_Parent (CW_Type, Parent (T));
14442 Set_Next_Entity (CW_Type, Next_E);
14444 -- Ensure we have a new freeze node for the class-wide type. The partial
14445 -- view may have freeze action of its own, requiring a proper freeze
14446 -- node, and the same freeze node cannot be shared between the two
14449 Set_Has_Delayed_Freeze (CW_Type);
14450 Set_Freeze_Node (CW_Type, Empty);
14452 -- Customize the class-wide type: It has no prim. op., it cannot be
14453 -- abstract and its Etype points back to the specific root type.
14455 Set_Ekind (CW_Type, E_Class_Wide_Type);
14456 Set_Is_Tagged_Type (CW_Type, True);
14457 Set_Primitive_Operations (CW_Type, New_Elmt_List);
14458 Set_Is_Abstract_Type (CW_Type, False);
14459 Set_Is_Constrained (CW_Type, False);
14460 Set_Is_First_Subtype (CW_Type, Is_First_Subtype (T));
14462 if Ekind (T) = E_Class_Wide_Subtype then
14463 Set_Etype (CW_Type, Etype (Base_Type (T)));
14465 Set_Etype (CW_Type, T);
14468 -- If this is the class_wide type of a constrained subtype, it does
14469 -- not have discriminants.
14471 Set_Has_Discriminants (CW_Type,
14472 Has_Discriminants (T) and then not Is_Constrained (T));
14474 Set_Has_Unknown_Discriminants (CW_Type, True);
14475 Set_Class_Wide_Type (T, CW_Type);
14476 Set_Equivalent_Type (CW_Type, Empty);
14478 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
14480 Set_Class_Wide_Type (CW_Type, CW_Type);
14481 end Make_Class_Wide_Type;
14487 procedure Make_Index
14489 Related_Nod : Node_Id;
14490 Related_Id : Entity_Id := Empty;
14491 Suffix_Index : Nat := 1)
14495 Def_Id : Entity_Id := Empty;
14496 Found : Boolean := False;
14499 -- For a discrete range used in a constrained array definition and
14500 -- defined by a range, an implicit conversion to the predefined type
14501 -- INTEGER is assumed if each bound is either a numeric literal, a named
14502 -- number, or an attribute, and the type of both bounds (prior to the
14503 -- implicit conversion) is the type universal_integer. Otherwise, both
14504 -- bounds must be of the same discrete type, other than universal
14505 -- integer; this type must be determinable independently of the
14506 -- context, but using the fact that the type must be discrete and that
14507 -- both bounds must have the same type.
14509 -- Character literals also have a universal type in the absence of
14510 -- of additional context, and are resolved to Standard_Character.
14512 if Nkind (I) = N_Range then
14514 -- The index is given by a range constraint. The bounds are known
14515 -- to be of a consistent type.
14517 if not Is_Overloaded (I) then
14520 -- For universal bounds, choose the specific predefined type
14522 if T = Universal_Integer then
14523 T := Standard_Integer;
14525 elsif T = Any_Character then
14526 Ambiguous_Character (Low_Bound (I));
14528 T := Standard_Character;
14531 -- The node may be overloaded because some user-defined operators
14532 -- are available, but if a universal interpretation exists it is
14533 -- also the selected one.
14535 elsif Universal_Interpretation (I) = Universal_Integer then
14536 T := Standard_Integer;
14542 Ind : Interp_Index;
14546 Get_First_Interp (I, Ind, It);
14547 while Present (It.Typ) loop
14548 if Is_Discrete_Type (It.Typ) then
14551 and then not Covers (It.Typ, T)
14552 and then not Covers (T, It.Typ)
14554 Error_Msg_N ("ambiguous bounds in discrete range", I);
14562 Get_Next_Interp (Ind, It);
14565 if T = Any_Type then
14566 Error_Msg_N ("discrete type required for range", I);
14567 Set_Etype (I, Any_Type);
14570 elsif T = Universal_Integer then
14571 T := Standard_Integer;
14576 if not Is_Discrete_Type (T) then
14577 Error_Msg_N ("discrete type required for range", I);
14578 Set_Etype (I, Any_Type);
14582 if Nkind (Low_Bound (I)) = N_Attribute_Reference
14583 and then Attribute_Name (Low_Bound (I)) = Name_First
14584 and then Is_Entity_Name (Prefix (Low_Bound (I)))
14585 and then Is_Type (Entity (Prefix (Low_Bound (I))))
14586 and then Is_Discrete_Type (Entity (Prefix (Low_Bound (I))))
14588 -- The type of the index will be the type of the prefix, as long
14589 -- as the upper bound is 'Last of the same type.
14591 Def_Id := Entity (Prefix (Low_Bound (I)));
14593 if Nkind (High_Bound (I)) /= N_Attribute_Reference
14594 or else Attribute_Name (High_Bound (I)) /= Name_Last
14595 or else not Is_Entity_Name (Prefix (High_Bound (I)))
14596 or else Entity (Prefix (High_Bound (I))) /= Def_Id
14603 Process_Range_Expr_In_Decl (R, T);
14605 elsif Nkind (I) = N_Subtype_Indication then
14607 -- The index is given by a subtype with a range constraint
14609 T := Base_Type (Entity (Subtype_Mark (I)));
14611 if not Is_Discrete_Type (T) then
14612 Error_Msg_N ("discrete type required for range", I);
14613 Set_Etype (I, Any_Type);
14617 R := Range_Expression (Constraint (I));
14620 Process_Range_Expr_In_Decl (R, Entity (Subtype_Mark (I)));
14622 elsif Nkind (I) = N_Attribute_Reference then
14624 -- The parser guarantees that the attribute is a RANGE attribute
14626 -- If the node denotes the range of a type mark, that is also the
14627 -- resulting type, and we do no need to create an Itype for it.
14629 if Is_Entity_Name (Prefix (I))
14630 and then Comes_From_Source (I)
14631 and then Is_Type (Entity (Prefix (I)))
14632 and then Is_Discrete_Type (Entity (Prefix (I)))
14634 Def_Id := Entity (Prefix (I));
14637 Analyze_And_Resolve (I);
14641 -- If none of the above, must be a subtype. We convert this to a
14642 -- range attribute reference because in the case of declared first
14643 -- named subtypes, the types in the range reference can be different
14644 -- from the type of the entity. A range attribute normalizes the
14645 -- reference and obtains the correct types for the bounds.
14647 -- This transformation is in the nature of an expansion, is only
14648 -- done if expansion is active. In particular, it is not done on
14649 -- formal generic types, because we need to retain the name of the
14650 -- original index for instantiation purposes.
14653 if not Is_Entity_Name (I) or else not Is_Type (Entity (I)) then
14654 Error_Msg_N ("invalid subtype mark in discrete range ", I);
14655 Set_Etype (I, Any_Integer);
14659 -- The type mark may be that of an incomplete type. It is only
14660 -- now that we can get the full view, previous analysis does
14661 -- not look specifically for a type mark.
14663 Set_Entity (I, Get_Full_View (Entity (I)));
14664 Set_Etype (I, Entity (I));
14665 Def_Id := Entity (I);
14667 if not Is_Discrete_Type (Def_Id) then
14668 Error_Msg_N ("discrete type required for index", I);
14669 Set_Etype (I, Any_Type);
14674 if Expander_Active then
14676 Make_Attribute_Reference (Sloc (I),
14677 Attribute_Name => Name_Range,
14678 Prefix => Relocate_Node (I)));
14680 -- The original was a subtype mark that does not freeze. This
14681 -- means that the rewritten version must not freeze either.
14683 Set_Must_Not_Freeze (I);
14684 Set_Must_Not_Freeze (Prefix (I));
14686 -- Is order critical??? if so, document why, if not
14687 -- use Analyze_And_Resolve
14689 Analyze_And_Resolve (I);
14693 -- If expander is inactive, type is legal, nothing else to construct
14700 if not Is_Discrete_Type (T) then
14701 Error_Msg_N ("discrete type required for range", I);
14702 Set_Etype (I, Any_Type);
14705 elsif T = Any_Type then
14706 Set_Etype (I, Any_Type);
14710 -- We will now create the appropriate Itype to describe the range, but
14711 -- first a check. If we originally had a subtype, then we just label
14712 -- the range with this subtype. Not only is there no need to construct
14713 -- a new subtype, but it is wrong to do so for two reasons:
14715 -- 1. A legality concern, if we have a subtype, it must not freeze,
14716 -- and the Itype would cause freezing incorrectly
14718 -- 2. An efficiency concern, if we created an Itype, it would not be
14719 -- recognized as the same type for the purposes of eliminating
14720 -- checks in some circumstances.
14722 -- We signal this case by setting the subtype entity in Def_Id
14724 if No (Def_Id) then
14726 Create_Itype (E_Void, Related_Nod, Related_Id, 'D', Suffix_Index);
14727 Set_Etype (Def_Id, Base_Type (T));
14729 if Is_Signed_Integer_Type (T) then
14730 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
14732 elsif Is_Modular_Integer_Type (T) then
14733 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
14736 Set_Ekind (Def_Id, E_Enumeration_Subtype);
14737 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
14738 Set_First_Literal (Def_Id, First_Literal (T));
14741 Set_Size_Info (Def_Id, (T));
14742 Set_RM_Size (Def_Id, RM_Size (T));
14743 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
14745 Set_Scalar_Range (Def_Id, R);
14746 Conditional_Delay (Def_Id, T);
14748 -- In the subtype indication case, if the immediate parent of the
14749 -- new subtype is non-static, then the subtype we create is non-
14750 -- static, even if its bounds are static.
14752 if Nkind (I) = N_Subtype_Indication
14753 and then not Is_Static_Subtype (Entity (Subtype_Mark (I)))
14755 Set_Is_Non_Static_Subtype (Def_Id);
14759 -- Final step is to label the index with this constructed type
14761 Set_Etype (I, Def_Id);
14764 ------------------------------
14765 -- Modular_Type_Declaration --
14766 ------------------------------
14768 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id) is
14769 Mod_Expr : constant Node_Id := Expression (Def);
14772 procedure Set_Modular_Size (Bits : Int);
14773 -- Sets RM_Size to Bits, and Esize to normal word size above this
14775 ----------------------
14776 -- Set_Modular_Size --
14777 ----------------------
14779 procedure Set_Modular_Size (Bits : Int) is
14781 Set_RM_Size (T, UI_From_Int (Bits));
14786 elsif Bits <= 16 then
14787 Init_Esize (T, 16);
14789 elsif Bits <= 32 then
14790 Init_Esize (T, 32);
14793 Init_Esize (T, System_Max_Binary_Modulus_Power);
14795 end Set_Modular_Size;
14797 -- Start of processing for Modular_Type_Declaration
14800 Analyze_And_Resolve (Mod_Expr, Any_Integer);
14802 Set_Ekind (T, E_Modular_Integer_Type);
14803 Init_Alignment (T);
14804 Set_Is_Constrained (T);
14806 if not Is_OK_Static_Expression (Mod_Expr) then
14807 Flag_Non_Static_Expr
14808 ("non-static expression used for modular type bound!", Mod_Expr);
14809 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14811 M_Val := Expr_Value (Mod_Expr);
14815 Error_Msg_N ("modulus value must be positive", Mod_Expr);
14816 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14819 Set_Modulus (T, M_Val);
14821 -- Create bounds for the modular type based on the modulus given in
14822 -- the type declaration and then analyze and resolve those bounds.
14824 Set_Scalar_Range (T,
14825 Make_Range (Sloc (Mod_Expr),
14827 Make_Integer_Literal (Sloc (Mod_Expr), 0),
14829 Make_Integer_Literal (Sloc (Mod_Expr), M_Val - 1)));
14831 -- Properly analyze the literals for the range. We do this manually
14832 -- because we can't go calling Resolve, since we are resolving these
14833 -- bounds with the type, and this type is certainly not complete yet!
14835 Set_Etype (Low_Bound (Scalar_Range (T)), T);
14836 Set_Etype (High_Bound (Scalar_Range (T)), T);
14837 Set_Is_Static_Expression (Low_Bound (Scalar_Range (T)));
14838 Set_Is_Static_Expression (High_Bound (Scalar_Range (T)));
14840 -- Loop through powers of two to find number of bits required
14842 for Bits in Int range 0 .. System_Max_Binary_Modulus_Power loop
14846 if M_Val = 2 ** Bits then
14847 Set_Modular_Size (Bits);
14852 elsif M_Val < 2 ** Bits then
14853 Set_Non_Binary_Modulus (T);
14855 if Bits > System_Max_Nonbinary_Modulus_Power then
14856 Error_Msg_Uint_1 :=
14857 UI_From_Int (System_Max_Nonbinary_Modulus_Power);
14859 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr);
14860 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14864 -- In the non-binary case, set size as per RM 13.3(55)
14866 Set_Modular_Size (Bits);
14873 -- If we fall through, then the size exceed System.Max_Binary_Modulus
14874 -- so we just signal an error and set the maximum size.
14876 Error_Msg_Uint_1 := UI_From_Int (System_Max_Binary_Modulus_Power);
14877 Error_Msg_F ("modulus exceeds limit (2 '*'*^)", Mod_Expr);
14879 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14880 Init_Alignment (T);
14882 end Modular_Type_Declaration;
14884 --------------------------
14885 -- New_Concatenation_Op --
14886 --------------------------
14888 procedure New_Concatenation_Op (Typ : Entity_Id) is
14889 Loc : constant Source_Ptr := Sloc (Typ);
14892 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id;
14893 -- Create abbreviated declaration for the formal of a predefined
14894 -- Operator 'Op' of type 'Typ'
14896 --------------------
14897 -- Make_Op_Formal --
14898 --------------------
14900 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id is
14901 Formal : Entity_Id;
14903 Formal := New_Internal_Entity (E_In_Parameter, Op, Loc, 'P');
14904 Set_Etype (Formal, Typ);
14905 Set_Mechanism (Formal, Default_Mechanism);
14907 end Make_Op_Formal;
14909 -- Start of processing for New_Concatenation_Op
14912 Op := Make_Defining_Operator_Symbol (Loc, Name_Op_Concat);
14914 Set_Ekind (Op, E_Operator);
14915 Set_Scope (Op, Current_Scope);
14916 Set_Etype (Op, Typ);
14917 Set_Homonym (Op, Get_Name_Entity_Id (Name_Op_Concat));
14918 Set_Is_Immediately_Visible (Op);
14919 Set_Is_Intrinsic_Subprogram (Op);
14920 Set_Has_Completion (Op);
14921 Append_Entity (Op, Current_Scope);
14923 Set_Name_Entity_Id (Name_Op_Concat, Op);
14925 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14926 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14927 end New_Concatenation_Op;
14929 -------------------------
14930 -- OK_For_Limited_Init --
14931 -------------------------
14933 -- ???Check all calls of this, and compare the conditions under which it's
14936 function OK_For_Limited_Init (Exp : Node_Id) return Boolean is
14938 return Ada_Version >= Ada_05
14939 and then not Debug_Flag_Dot_L
14940 and then OK_For_Limited_Init_In_05 (Exp);
14941 end OK_For_Limited_Init;
14943 -------------------------------
14944 -- OK_For_Limited_Init_In_05 --
14945 -------------------------------
14947 function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean is
14949 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
14950 -- case of limited aggregates (including extension aggregates), and
14951 -- function calls. The function call may have been give in prefixed
14952 -- notation, in which case the original node is an indexed component.
14954 case Nkind (Original_Node (Exp)) is
14955 when N_Aggregate | N_Extension_Aggregate | N_Function_Call | N_Op =>
14958 when N_Qualified_Expression =>
14960 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
14962 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
14963 -- with a function call, the expander has rewritten the call into an
14964 -- N_Type_Conversion node to force displacement of the pointer to
14965 -- reference the component containing the secondary dispatch table.
14966 -- Otherwise a type conversion is not a legal context.
14968 when N_Type_Conversion =>
14969 return not Comes_From_Source (Exp)
14971 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
14973 when N_Indexed_Component | N_Selected_Component =>
14974 return Nkind (Exp) = N_Function_Call;
14976 -- A use of 'Input is a function call, hence allowed. Normally the
14977 -- attribute will be changed to a call, but the attribute by itself
14978 -- can occur with -gnatc.
14980 when N_Attribute_Reference =>
14981 return Attribute_Name (Original_Node (Exp)) = Name_Input;
14986 end OK_For_Limited_Init_In_05;
14988 -------------------------------------------
14989 -- Ordinary_Fixed_Point_Type_Declaration --
14990 -------------------------------------------
14992 procedure Ordinary_Fixed_Point_Type_Declaration
14996 Loc : constant Source_Ptr := Sloc (Def);
14997 Delta_Expr : constant Node_Id := Delta_Expression (Def);
14998 RRS : constant Node_Id := Real_Range_Specification (Def);
14999 Implicit_Base : Entity_Id;
15006 Check_Restriction (No_Fixed_Point, Def);
15008 -- Create implicit base type
15011 Create_Itype (E_Ordinary_Fixed_Point_Type, Parent (Def), T, 'B');
15012 Set_Etype (Implicit_Base, Implicit_Base);
15014 -- Analyze and process delta expression
15016 Analyze_And_Resolve (Delta_Expr, Any_Real);
15018 Check_Delta_Expression (Delta_Expr);
15019 Delta_Val := Expr_Value_R (Delta_Expr);
15021 Set_Delta_Value (Implicit_Base, Delta_Val);
15023 -- Compute default small from given delta, which is the largest power
15024 -- of two that does not exceed the given delta value.
15034 if Delta_Val < Ureal_1 then
15035 while Delta_Val < Tmp loop
15036 Tmp := Tmp / Ureal_2;
15037 Scale := Scale + 1;
15042 Tmp := Tmp * Ureal_2;
15043 exit when Tmp > Delta_Val;
15044 Scale := Scale - 1;
15048 Small_Val := UR_From_Components (Uint_1, UI_From_Int (Scale), 2);
15051 Set_Small_Value (Implicit_Base, Small_Val);
15053 -- If no range was given, set a dummy range
15055 if RRS <= Empty_Or_Error then
15056 Low_Val := -Small_Val;
15057 High_Val := Small_Val;
15059 -- Otherwise analyze and process given range
15063 Low : constant Node_Id := Low_Bound (RRS);
15064 High : constant Node_Id := High_Bound (RRS);
15067 Analyze_And_Resolve (Low, Any_Real);
15068 Analyze_And_Resolve (High, Any_Real);
15069 Check_Real_Bound (Low);
15070 Check_Real_Bound (High);
15072 -- Obtain and set the range
15074 Low_Val := Expr_Value_R (Low);
15075 High_Val := Expr_Value_R (High);
15077 if Low_Val > High_Val then
15078 Error_Msg_NE ("?fixed point type& has null range", Def, T);
15083 -- The range for both the implicit base and the declared first subtype
15084 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
15085 -- set a temporary range in place. Note that the bounds of the base
15086 -- type will be widened to be symmetrical and to fill the available
15087 -- bits when the type is frozen.
15089 -- We could do this with all discrete types, and probably should, but
15090 -- we absolutely have to do it for fixed-point, since the end-points
15091 -- of the range and the size are determined by the small value, which
15092 -- could be reset before the freeze point.
15094 Set_Fixed_Range (Implicit_Base, Loc, Low_Val, High_Val);
15095 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
15097 -- Complete definition of first subtype
15099 Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype);
15100 Set_Etype (T, Implicit_Base);
15101 Init_Size_Align (T);
15102 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
15103 Set_Small_Value (T, Small_Val);
15104 Set_Delta_Value (T, Delta_Val);
15105 Set_Is_Constrained (T);
15107 end Ordinary_Fixed_Point_Type_Declaration;
15109 ----------------------------------------
15110 -- Prepare_Private_Subtype_Completion --
15111 ----------------------------------------
15113 procedure Prepare_Private_Subtype_Completion
15115 Related_Nod : Node_Id)
15117 Id_B : constant Entity_Id := Base_Type (Id);
15118 Full_B : constant Entity_Id := Full_View (Id_B);
15122 if Present (Full_B) then
15124 -- The Base_Type is already completed, we can complete the subtype
15125 -- now. We have to create a new entity with the same name, Thus we
15126 -- can't use Create_Itype.
15128 -- This is messy, should be fixed ???
15130 Full := Make_Defining_Identifier (Sloc (Id), Chars (Id));
15131 Set_Is_Itype (Full);
15132 Set_Associated_Node_For_Itype (Full, Related_Nod);
15133 Complete_Private_Subtype (Id, Full, Full_B, Related_Nod);
15136 -- The parent subtype may be private, but the base might not, in some
15137 -- nested instances. In that case, the subtype does not need to be
15138 -- exchanged. It would still be nice to make private subtypes and their
15139 -- bases consistent at all times ???
15141 if Is_Private_Type (Id_B) then
15142 Append_Elmt (Id, Private_Dependents (Id_B));
15145 end Prepare_Private_Subtype_Completion;
15147 ---------------------------
15148 -- Process_Discriminants --
15149 ---------------------------
15151 procedure Process_Discriminants
15153 Prev : Entity_Id := Empty)
15155 Elist : constant Elist_Id := New_Elmt_List;
15158 Discr_Number : Uint;
15159 Discr_Type : Entity_Id;
15160 Default_Present : Boolean := False;
15161 Default_Not_Present : Boolean := False;
15164 -- A composite type other than an array type can have discriminants.
15165 -- On entry, the current scope is the composite type.
15167 -- The discriminants are initially entered into the scope of the type
15168 -- via Enter_Name with the default Ekind of E_Void to prevent premature
15169 -- use, as explained at the end of this procedure.
15171 Discr := First (Discriminant_Specifications (N));
15172 while Present (Discr) loop
15173 Enter_Name (Defining_Identifier (Discr));
15175 -- For navigation purposes we add a reference to the discriminant
15176 -- in the entity for the type. If the current declaration is a
15177 -- completion, place references on the partial view. Otherwise the
15178 -- type is the current scope.
15180 if Present (Prev) then
15182 -- The references go on the partial view, if present. If the
15183 -- partial view has discriminants, the references have been
15184 -- generated already.
15186 if not Has_Discriminants (Prev) then
15187 Generate_Reference (Prev, Defining_Identifier (Discr), 'd');
15191 (Current_Scope, Defining_Identifier (Discr), 'd');
15194 if Nkind (Discriminant_Type (Discr)) = N_Access_Definition then
15195 Discr_Type := Access_Definition (Discr, Discriminant_Type (Discr));
15197 -- Ada 2005 (AI-254)
15199 if Present (Access_To_Subprogram_Definition
15200 (Discriminant_Type (Discr)))
15201 and then Protected_Present (Access_To_Subprogram_Definition
15202 (Discriminant_Type (Discr)))
15205 Replace_Anonymous_Access_To_Protected_Subprogram (Discr);
15209 Find_Type (Discriminant_Type (Discr));
15210 Discr_Type := Etype (Discriminant_Type (Discr));
15212 if Error_Posted (Discriminant_Type (Discr)) then
15213 Discr_Type := Any_Type;
15217 if Is_Access_Type (Discr_Type) then
15219 -- Ada 2005 (AI-230): Access discriminant allowed in non-limited
15222 if Ada_Version < Ada_05 then
15223 Check_Access_Discriminant_Requires_Limited
15224 (Discr, Discriminant_Type (Discr));
15227 if Ada_Version = Ada_83 and then Comes_From_Source (Discr) then
15229 ("(Ada 83) access discriminant not allowed", Discr);
15232 elsif not Is_Discrete_Type (Discr_Type) then
15233 Error_Msg_N ("discriminants must have a discrete or access type",
15234 Discriminant_Type (Discr));
15237 Set_Etype (Defining_Identifier (Discr), Discr_Type);
15239 -- If a discriminant specification includes the assignment compound
15240 -- delimiter followed by an expression, the expression is the default
15241 -- expression of the discriminant; the default expression must be of
15242 -- the type of the discriminant. (RM 3.7.1) Since this expression is
15243 -- a default expression, we do the special preanalysis, since this
15244 -- expression does not freeze (see "Handling of Default and Per-
15245 -- Object Expressions" in spec of package Sem).
15247 if Present (Expression (Discr)) then
15248 Preanalyze_Spec_Expression (Expression (Discr), Discr_Type);
15250 if Nkind (N) = N_Formal_Type_Declaration then
15252 ("discriminant defaults not allowed for formal type",
15253 Expression (Discr));
15255 -- Tagged types cannot have defaulted discriminants, but a
15256 -- non-tagged private type with defaulted discriminants
15257 -- can have a tagged completion.
15259 elsif Is_Tagged_Type (Current_Scope)
15260 and then Comes_From_Source (N)
15263 ("discriminants of tagged type cannot have defaults",
15264 Expression (Discr));
15267 Default_Present := True;
15268 Append_Elmt (Expression (Discr), Elist);
15270 -- Tag the defining identifiers for the discriminants with
15271 -- their corresponding default expressions from the tree.
15273 Set_Discriminant_Default_Value
15274 (Defining_Identifier (Discr), Expression (Discr));
15278 Default_Not_Present := True;
15281 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
15282 -- Discr_Type but with the null-exclusion attribute
15284 if Ada_Version >= Ada_05 then
15286 -- Ada 2005 (AI-231): Static checks
15288 if Can_Never_Be_Null (Discr_Type) then
15289 Null_Exclusion_Static_Checks (Discr);
15291 elsif Is_Access_Type (Discr_Type)
15292 and then Null_Exclusion_Present (Discr)
15294 -- No need to check itypes because in their case this check
15295 -- was done at their point of creation
15297 and then not Is_Itype (Discr_Type)
15299 if Can_Never_Be_Null (Discr_Type) then
15301 ("`NOT NULL` not allowed (& already excludes null)",
15306 Set_Etype (Defining_Identifier (Discr),
15307 Create_Null_Excluding_Itype
15309 Related_Nod => Discr));
15312 -- Ada 2005 (AI-402): access discriminants of nonlimited types
15313 -- can't have defaults. Synchronized types, or types that are
15314 -- explicitly limited are fine, but special tests apply to derived
15315 -- types in generics: in a generic body we have to assume the
15316 -- worst, and therefore defaults are not allowed if the parent is
15317 -- a generic formal private type (see ACATS B370001).
15319 if Is_Access_Type (Discr_Type) then
15320 if Ekind (Discr_Type) /= E_Anonymous_Access_Type
15321 or else not Default_Present
15322 or else Is_Limited_Record (Current_Scope)
15323 or else Is_Concurrent_Type (Current_Scope)
15324 or else Is_Concurrent_Record_Type (Current_Scope)
15325 or else Ekind (Current_Scope) = E_Limited_Private_Type
15327 if not Is_Derived_Type (Current_Scope)
15328 or else not Is_Generic_Type (Etype (Current_Scope))
15329 or else not In_Package_Body (Scope (Etype (Current_Scope)))
15330 or else Limited_Present
15331 (Type_Definition (Parent (Current_Scope)))
15336 Error_Msg_N ("access discriminants of nonlimited types",
15337 Expression (Discr));
15338 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15341 elsif Present (Expression (Discr)) then
15343 ("(Ada 2005) access discriminants of nonlimited types",
15344 Expression (Discr));
15345 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15353 -- An element list consisting of the default expressions of the
15354 -- discriminants is constructed in the above loop and used to set
15355 -- the Discriminant_Constraint attribute for the type. If an object
15356 -- is declared of this (record or task) type without any explicit
15357 -- discriminant constraint given, this element list will form the
15358 -- actual parameters for the corresponding initialization procedure
15361 Set_Discriminant_Constraint (Current_Scope, Elist);
15362 Set_Stored_Constraint (Current_Scope, No_Elist);
15364 -- Default expressions must be provided either for all or for none
15365 -- of the discriminants of a discriminant part. (RM 3.7.1)
15367 if Default_Present and then Default_Not_Present then
15369 ("incomplete specification of defaults for discriminants", N);
15372 -- The use of the name of a discriminant is not allowed in default
15373 -- expressions of a discriminant part if the specification of the
15374 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
15376 -- To detect this, the discriminant names are entered initially with an
15377 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
15378 -- attempt to use a void entity (for example in an expression that is
15379 -- type-checked) produces the error message: premature usage. Now after
15380 -- completing the semantic analysis of the discriminant part, we can set
15381 -- the Ekind of all the discriminants appropriately.
15383 Discr := First (Discriminant_Specifications (N));
15384 Discr_Number := Uint_1;
15385 while Present (Discr) loop
15386 Id := Defining_Identifier (Discr);
15387 Set_Ekind (Id, E_Discriminant);
15388 Init_Component_Location (Id);
15390 Set_Discriminant_Number (Id, Discr_Number);
15392 -- Make sure this is always set, even in illegal programs
15394 Set_Corresponding_Discriminant (Id, Empty);
15396 -- Initialize the Original_Record_Component to the entity itself.
15397 -- Inherit_Components will propagate the right value to
15398 -- discriminants in derived record types.
15400 Set_Original_Record_Component (Id, Id);
15402 -- Create the discriminal for the discriminant
15404 Build_Discriminal (Id);
15407 Discr_Number := Discr_Number + 1;
15410 Set_Has_Discriminants (Current_Scope);
15411 end Process_Discriminants;
15413 -----------------------
15414 -- Process_Full_View --
15415 -----------------------
15417 procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id) is
15418 Priv_Parent : Entity_Id;
15419 Full_Parent : Entity_Id;
15420 Full_Indic : Node_Id;
15422 procedure Collect_Implemented_Interfaces
15424 Ifaces : Elist_Id);
15425 -- Ada 2005: Gather all the interfaces that Typ directly or
15426 -- inherently implements. Duplicate entries are not added to
15427 -- the list Ifaces.
15429 ------------------------------------
15430 -- Collect_Implemented_Interfaces --
15431 ------------------------------------
15433 procedure Collect_Implemented_Interfaces
15438 Iface_Elmt : Elmt_Id;
15441 -- Abstract interfaces are only associated with tagged record types
15443 if not Is_Tagged_Type (Typ)
15444 or else not Is_Record_Type (Typ)
15449 -- Recursively climb to the ancestors
15451 if Etype (Typ) /= Typ
15453 -- Protect the frontend against wrong cyclic declarations like:
15455 -- type B is new A with private;
15456 -- type C is new A with private;
15458 -- type B is new C with null record;
15459 -- type C is new B with null record;
15461 and then Etype (Typ) /= Priv_T
15462 and then Etype (Typ) /= Full_T
15464 -- Keep separate the management of private type declarations
15466 if Ekind (Typ) = E_Record_Type_With_Private then
15468 -- Handle the following erronous case:
15469 -- type Private_Type is tagged private;
15471 -- type Private_Type is new Type_Implementing_Iface;
15473 if Present (Full_View (Typ))
15474 and then Etype (Typ) /= Full_View (Typ)
15476 if Is_Interface (Etype (Typ)) then
15477 Append_Unique_Elmt (Etype (Typ), Ifaces);
15480 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15483 -- Non-private types
15486 if Is_Interface (Etype (Typ)) then
15487 Append_Unique_Elmt (Etype (Typ), Ifaces);
15490 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15494 -- Handle entities in the list of abstract interfaces
15496 if Present (Interfaces (Typ)) then
15497 Iface_Elmt := First_Elmt (Interfaces (Typ));
15498 while Present (Iface_Elmt) loop
15499 Iface := Node (Iface_Elmt);
15501 pragma Assert (Is_Interface (Iface));
15503 if not Contain_Interface (Iface, Ifaces) then
15504 Append_Elmt (Iface, Ifaces);
15505 Collect_Implemented_Interfaces (Iface, Ifaces);
15508 Next_Elmt (Iface_Elmt);
15511 end Collect_Implemented_Interfaces;
15513 -- Start of processing for Process_Full_View
15516 -- First some sanity checks that must be done after semantic
15517 -- decoration of the full view and thus cannot be placed with other
15518 -- similar checks in Find_Type_Name
15520 if not Is_Limited_Type (Priv_T)
15521 and then (Is_Limited_Type (Full_T)
15522 or else Is_Limited_Composite (Full_T))
15525 ("completion of nonlimited type cannot be limited", Full_T);
15526 Explain_Limited_Type (Full_T, Full_T);
15528 elsif Is_Abstract_Type (Full_T)
15529 and then not Is_Abstract_Type (Priv_T)
15532 ("completion of nonabstract type cannot be abstract", Full_T);
15534 elsif Is_Tagged_Type (Priv_T)
15535 and then Is_Limited_Type (Priv_T)
15536 and then not Is_Limited_Type (Full_T)
15538 -- If pragma CPP_Class was applied to the private declaration
15539 -- propagate the limitedness to the full-view
15541 if Is_CPP_Class (Priv_T) then
15542 Set_Is_Limited_Record (Full_T);
15544 -- GNAT allow its own definition of Limited_Controlled to disobey
15545 -- this rule in order in ease the implementation. The next test is
15546 -- safe because Root_Controlled is defined in a private system child
15548 elsif Etype (Full_T) = Full_View (RTE (RE_Root_Controlled)) then
15549 Set_Is_Limited_Composite (Full_T);
15552 ("completion of limited tagged type must be limited", Full_T);
15555 elsif Is_Generic_Type (Priv_T) then
15556 Error_Msg_N ("generic type cannot have a completion", Full_T);
15559 -- Check that ancestor interfaces of private and full views are
15560 -- consistent. We omit this check for synchronized types because
15561 -- they are performed on the corresponding record type when frozen.
15563 if Ada_Version >= Ada_05
15564 and then Is_Tagged_Type (Priv_T)
15565 and then Is_Tagged_Type (Full_T)
15566 and then not Is_Concurrent_Type (Full_T)
15570 Priv_T_Ifaces : constant Elist_Id := New_Elmt_List;
15571 Full_T_Ifaces : constant Elist_Id := New_Elmt_List;
15574 Collect_Implemented_Interfaces (Priv_T, Priv_T_Ifaces);
15575 Collect_Implemented_Interfaces (Full_T, Full_T_Ifaces);
15577 -- Ada 2005 (AI-251): The partial view shall be a descendant of
15578 -- an interface type if and only if the full type is descendant
15579 -- of the interface type (AARM 7.3 (7.3/2).
15581 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
15583 if Present (Iface) then
15584 Error_Msg_NE ("interface & not implemented by full type " &
15585 "(RM-2005 7.3 (7.3/2))", Priv_T, Iface);
15588 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
15590 if Present (Iface) then
15591 Error_Msg_NE ("interface & not implemented by partial view " &
15592 "(RM-2005 7.3 (7.3/2))", Full_T, Iface);
15597 if Is_Tagged_Type (Priv_T)
15598 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15599 and then Is_Derived_Type (Full_T)
15601 Priv_Parent := Etype (Priv_T);
15603 -- The full view of a private extension may have been transformed
15604 -- into an unconstrained derived type declaration and a subtype
15605 -- declaration (see build_derived_record_type for details).
15607 if Nkind (N) = N_Subtype_Declaration then
15608 Full_Indic := Subtype_Indication (N);
15609 Full_Parent := Etype (Base_Type (Full_T));
15611 Full_Indic := Subtype_Indication (Type_Definition (N));
15612 Full_Parent := Etype (Full_T);
15615 -- Check that the parent type of the full type is a descendant of
15616 -- the ancestor subtype given in the private extension. If either
15617 -- entity has an Etype equal to Any_Type then we had some previous
15618 -- error situation [7.3(8)].
15620 if Priv_Parent = Any_Type or else Full_Parent = Any_Type then
15623 -- Ada 2005 (AI-251): Interfaces in the full-typ can be given in
15624 -- any order. Therefore we don't have to check that its parent must
15625 -- be a descendant of the parent of the private type declaration.
15627 elsif Is_Interface (Priv_Parent)
15628 and then Is_Interface (Full_Parent)
15632 -- Ada 2005 (AI-251): If the parent of the private type declaration
15633 -- is an interface there is no need to check that it is an ancestor
15634 -- of the associated full type declaration. The required tests for
15635 -- this case case are performed by Build_Derived_Record_Type.
15637 elsif not Is_Interface (Base_Type (Priv_Parent))
15638 and then not Is_Ancestor (Base_Type (Priv_Parent), Full_Parent)
15641 ("parent of full type must descend from parent"
15642 & " of private extension", Full_Indic);
15644 -- Check the rules of 7.3(10): if the private extension inherits
15645 -- known discriminants, then the full type must also inherit those
15646 -- discriminants from the same (ancestor) type, and the parent
15647 -- subtype of the full type must be constrained if and only if
15648 -- the ancestor subtype of the private extension is constrained.
15650 elsif No (Discriminant_Specifications (Parent (Priv_T)))
15651 and then not Has_Unknown_Discriminants (Priv_T)
15652 and then Has_Discriminants (Base_Type (Priv_Parent))
15655 Priv_Indic : constant Node_Id :=
15656 Subtype_Indication (Parent (Priv_T));
15658 Priv_Constr : constant Boolean :=
15659 Is_Constrained (Priv_Parent)
15661 Nkind (Priv_Indic) = N_Subtype_Indication
15662 or else Is_Constrained (Entity (Priv_Indic));
15664 Full_Constr : constant Boolean :=
15665 Is_Constrained (Full_Parent)
15667 Nkind (Full_Indic) = N_Subtype_Indication
15668 or else Is_Constrained (Entity (Full_Indic));
15670 Priv_Discr : Entity_Id;
15671 Full_Discr : Entity_Id;
15674 Priv_Discr := First_Discriminant (Priv_Parent);
15675 Full_Discr := First_Discriminant (Full_Parent);
15676 while Present (Priv_Discr) and then Present (Full_Discr) loop
15677 if Original_Record_Component (Priv_Discr) =
15678 Original_Record_Component (Full_Discr)
15680 Corresponding_Discriminant (Priv_Discr) =
15681 Corresponding_Discriminant (Full_Discr)
15688 Next_Discriminant (Priv_Discr);
15689 Next_Discriminant (Full_Discr);
15692 if Present (Priv_Discr) or else Present (Full_Discr) then
15694 ("full view must inherit discriminants of the parent type"
15695 & " used in the private extension", Full_Indic);
15697 elsif Priv_Constr and then not Full_Constr then
15699 ("parent subtype of full type must be constrained",
15702 elsif Full_Constr and then not Priv_Constr then
15704 ("parent subtype of full type must be unconstrained",
15709 -- Check the rules of 7.3(12): if a partial view has neither known
15710 -- or unknown discriminants, then the full type declaration shall
15711 -- define a definite subtype.
15713 elsif not Has_Unknown_Discriminants (Priv_T)
15714 and then not Has_Discriminants (Priv_T)
15715 and then not Is_Constrained (Full_T)
15718 ("full view must define a constrained type if partial view"
15719 & " has no discriminants", Full_T);
15722 -- ??????? Do we implement the following properly ?????
15723 -- If the ancestor subtype of a private extension has constrained
15724 -- discriminants, then the parent subtype of the full view shall
15725 -- impose a statically matching constraint on those discriminants
15729 -- For untagged types, verify that a type without discriminants
15730 -- is not completed with an unconstrained type.
15732 if not Is_Indefinite_Subtype (Priv_T)
15733 and then Is_Indefinite_Subtype (Full_T)
15735 Error_Msg_N ("full view of type must be definite subtype", Full_T);
15739 -- AI-419: verify that the use of "limited" is consistent
15742 Orig_Decl : constant Node_Id := Original_Node (N);
15745 if Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15746 and then not Limited_Present (Parent (Priv_T))
15747 and then not Synchronized_Present (Parent (Priv_T))
15748 and then Nkind (Orig_Decl) = N_Full_Type_Declaration
15750 (Type_Definition (Orig_Decl)) = N_Derived_Type_Definition
15751 and then Limited_Present (Type_Definition (Orig_Decl))
15754 ("full view of non-limited extension cannot be limited", N);
15758 -- Ada 2005 (AI-443): A synchronized private extension must be
15759 -- completed by a task or protected type.
15761 if Ada_Version >= Ada_05
15762 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15763 and then Synchronized_Present (Parent (Priv_T))
15764 and then not Is_Concurrent_Type (Full_T)
15766 Error_Msg_N ("full view of synchronized extension must " &
15767 "be synchronized type", N);
15770 -- Ada 2005 AI-363: if the full view has discriminants with
15771 -- defaults, it is illegal to declare constrained access subtypes
15772 -- whose designated type is the current type. This allows objects
15773 -- of the type that are declared in the heap to be unconstrained.
15775 if not Has_Unknown_Discriminants (Priv_T)
15776 and then not Has_Discriminants (Priv_T)
15777 and then Has_Discriminants (Full_T)
15779 Present (Discriminant_Default_Value (First_Discriminant (Full_T)))
15781 Set_Has_Constrained_Partial_View (Full_T);
15782 Set_Has_Constrained_Partial_View (Priv_T);
15785 -- Create a full declaration for all its subtypes recorded in
15786 -- Private_Dependents and swap them similarly to the base type. These
15787 -- are subtypes that have been define before the full declaration of
15788 -- the private type. We also swap the entry in Private_Dependents list
15789 -- so we can properly restore the private view on exit from the scope.
15792 Priv_Elmt : Elmt_Id;
15797 Priv_Elmt := First_Elmt (Private_Dependents (Priv_T));
15798 while Present (Priv_Elmt) loop
15799 Priv := Node (Priv_Elmt);
15801 if Ekind (Priv) = E_Private_Subtype
15802 or else Ekind (Priv) = E_Limited_Private_Subtype
15803 or else Ekind (Priv) = E_Record_Subtype_With_Private
15805 Full := Make_Defining_Identifier (Sloc (Priv), Chars (Priv));
15806 Set_Is_Itype (Full);
15807 Set_Parent (Full, Parent (Priv));
15808 Set_Associated_Node_For_Itype (Full, N);
15810 -- Now we need to complete the private subtype, but since the
15811 -- base type has already been swapped, we must also swap the
15812 -- subtypes (and thus, reverse the arguments in the call to
15813 -- Complete_Private_Subtype).
15815 Copy_And_Swap (Priv, Full);
15816 Complete_Private_Subtype (Full, Priv, Full_T, N);
15817 Replace_Elmt (Priv_Elmt, Full);
15820 Next_Elmt (Priv_Elmt);
15824 -- If the private view was tagged, copy the new primitive operations
15825 -- from the private view to the full view.
15827 if Is_Tagged_Type (Full_T) then
15829 Disp_Typ : Entity_Id;
15830 Full_List : Elist_Id;
15832 Prim_Elmt : Elmt_Id;
15833 Priv_List : Elist_Id;
15837 L : Elist_Id) return Boolean;
15838 -- Determine whether list L contains element E
15846 L : Elist_Id) return Boolean
15848 List_Elmt : Elmt_Id;
15851 List_Elmt := First_Elmt (L);
15852 while Present (List_Elmt) loop
15853 if Node (List_Elmt) = E then
15857 Next_Elmt (List_Elmt);
15863 -- Start of processing
15866 if Is_Tagged_Type (Priv_T) then
15867 Priv_List := Primitive_Operations (Priv_T);
15868 Prim_Elmt := First_Elmt (Priv_List);
15870 -- In the case of a concurrent type completing a private tagged
15871 -- type, primivies may have been declared in between the two
15872 -- views. These subprograms need to be wrapped the same way
15873 -- entries and protected procedures are handled because they
15874 -- cannot be directly shared by the two views.
15876 if Is_Concurrent_Type (Full_T) then
15878 Conc_Typ : constant Entity_Id :=
15879 Corresponding_Record_Type (Full_T);
15880 Loc : constant Source_Ptr := Sloc (Conc_Typ);
15881 Curr_Nod : Node_Id := Parent (Conc_Typ);
15882 Wrap_Spec : Node_Id;
15885 while Present (Prim_Elmt) loop
15886 Prim := Node (Prim_Elmt);
15888 if Comes_From_Source (Prim)
15889 and then not Is_Abstract_Subprogram (Prim)
15892 Make_Subprogram_Declaration (Loc,
15894 Build_Wrapper_Spec (Loc,
15896 Obj_Typ => Conc_Typ,
15898 Parameter_Specifications (
15901 Insert_After (Curr_Nod, Wrap_Spec);
15902 Curr_Nod := Wrap_Spec;
15904 Analyze (Wrap_Spec);
15907 Next_Elmt (Prim_Elmt);
15913 -- For non-concurrent types, transfer explicit primitives, but
15914 -- omit those inherited from the parent of the private view
15915 -- since they will be re-inherited later on.
15918 Full_List := Primitive_Operations (Full_T);
15920 while Present (Prim_Elmt) loop
15921 Prim := Node (Prim_Elmt);
15923 if Comes_From_Source (Prim)
15924 and then not Contains (Prim, Full_List)
15926 Append_Elmt (Prim, Full_List);
15929 Next_Elmt (Prim_Elmt);
15933 -- Untagged private view
15936 Full_List := Primitive_Operations (Full_T);
15938 -- In this case the partial view is untagged, so here we locate
15939 -- all of the earlier primitives that need to be treated as
15940 -- dispatching (those that appear between the two views). Note
15941 -- that these additional operations must all be new operations
15942 -- (any earlier operations that override inherited operations
15943 -- of the full view will already have been inserted in the
15944 -- primitives list, marked by Check_Operation_From_Private_View
15945 -- as dispatching. Note that implicit "/=" operators are
15946 -- excluded from being added to the primitives list since they
15947 -- shouldn't be treated as dispatching (tagged "/=" is handled
15950 Prim := Next_Entity (Full_T);
15951 while Present (Prim) and then Prim /= Priv_T loop
15952 if Ekind (Prim) = E_Procedure
15954 Ekind (Prim) = E_Function
15956 Disp_Typ := Find_Dispatching_Type (Prim);
15958 if Disp_Typ = Full_T
15959 and then (Chars (Prim) /= Name_Op_Ne
15960 or else Comes_From_Source (Prim))
15962 Check_Controlling_Formals (Full_T, Prim);
15964 if not Is_Dispatching_Operation (Prim) then
15965 Append_Elmt (Prim, Full_List);
15966 Set_Is_Dispatching_Operation (Prim, True);
15967 Set_DT_Position (Prim, No_Uint);
15970 elsif Is_Dispatching_Operation (Prim)
15971 and then Disp_Typ /= Full_T
15974 -- Verify that it is not otherwise controlled by a
15975 -- formal or a return value of type T.
15977 Check_Controlling_Formals (Disp_Typ, Prim);
15981 Next_Entity (Prim);
15985 -- For the tagged case, the two views can share the same
15986 -- Primitive Operation list and the same class wide type.
15987 -- Update attributes of the class-wide type which depend on
15988 -- the full declaration.
15990 if Is_Tagged_Type (Priv_T) then
15991 Set_Primitive_Operations (Priv_T, Full_List);
15992 Set_Class_Wide_Type
15993 (Base_Type (Full_T), Class_Wide_Type (Priv_T));
15995 Set_Has_Task (Class_Wide_Type (Priv_T), Has_Task (Full_T));
16000 -- Ada 2005 AI 161: Check preelaboratable initialization consistency
16002 if Known_To_Have_Preelab_Init (Priv_T) then
16004 -- Case where there is a pragma Preelaborable_Initialization. We
16005 -- always allow this in predefined units, which is a bit of a kludge,
16006 -- but it means we don't have to struggle to meet the requirements in
16007 -- the RM for having Preelaborable Initialization. Otherwise we
16008 -- require that the type meets the RM rules. But we can't check that
16009 -- yet, because of the rule about overriding Ininitialize, so we
16010 -- simply set a flag that will be checked at freeze time.
16012 if not In_Predefined_Unit (Full_T) then
16013 Set_Must_Have_Preelab_Init (Full_T);
16017 -- If pragma CPP_Class was applied to the private type declaration,
16018 -- propagate it now to the full type declaration.
16020 if Is_CPP_Class (Priv_T) then
16021 Set_Is_CPP_Class (Full_T);
16022 Set_Convention (Full_T, Convention_CPP);
16024 end Process_Full_View;
16026 -----------------------------------
16027 -- Process_Incomplete_Dependents --
16028 -----------------------------------
16030 procedure Process_Incomplete_Dependents
16032 Full_T : Entity_Id;
16035 Inc_Elmt : Elmt_Id;
16036 Priv_Dep : Entity_Id;
16037 New_Subt : Entity_Id;
16039 Disc_Constraint : Elist_Id;
16042 if No (Private_Dependents (Inc_T)) then
16046 -- Itypes that may be generated by the completion of an incomplete
16047 -- subtype are not used by the back-end and not attached to the tree.
16048 -- They are created only for constraint-checking purposes.
16050 Inc_Elmt := First_Elmt (Private_Dependents (Inc_T));
16051 while Present (Inc_Elmt) loop
16052 Priv_Dep := Node (Inc_Elmt);
16054 if Ekind (Priv_Dep) = E_Subprogram_Type then
16056 -- An Access_To_Subprogram type may have a return type or a
16057 -- parameter type that is incomplete. Replace with the full view.
16059 if Etype (Priv_Dep) = Inc_T then
16060 Set_Etype (Priv_Dep, Full_T);
16064 Formal : Entity_Id;
16067 Formal := First_Formal (Priv_Dep);
16068 while Present (Formal) loop
16069 if Etype (Formal) = Inc_T then
16070 Set_Etype (Formal, Full_T);
16073 Next_Formal (Formal);
16077 elsif Is_Overloadable (Priv_Dep) then
16079 -- A protected operation is never dispatching: only its
16080 -- wrapper operation (which has convention Ada) is.
16082 if Is_Tagged_Type (Full_T)
16083 and then Convention (Priv_Dep) /= Convention_Protected
16086 -- Subprogram has an access parameter whose designated type
16087 -- was incomplete. Reexamine declaration now, because it may
16088 -- be a primitive operation of the full type.
16090 Check_Operation_From_Incomplete_Type (Priv_Dep, Inc_T);
16091 Set_Is_Dispatching_Operation (Priv_Dep);
16092 Check_Controlling_Formals (Full_T, Priv_Dep);
16095 elsif Ekind (Priv_Dep) = E_Subprogram_Body then
16097 -- Can happen during processing of a body before the completion
16098 -- of a TA type. Ignore, because spec is also on dependent list.
16102 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
16103 -- corresponding subtype of the full view.
16105 elsif Ekind (Priv_Dep) = E_Incomplete_Subtype then
16106 Set_Subtype_Indication
16107 (Parent (Priv_Dep), New_Reference_To (Full_T, Sloc (Priv_Dep)));
16108 Set_Etype (Priv_Dep, Full_T);
16109 Set_Ekind (Priv_Dep, Subtype_Kind (Ekind (Full_T)));
16110 Set_Analyzed (Parent (Priv_Dep), False);
16112 -- Reanalyze the declaration, suppressing the call to
16113 -- Enter_Name to avoid duplicate names.
16115 Analyze_Subtype_Declaration
16116 (N => Parent (Priv_Dep),
16119 -- Dependent is a subtype
16122 -- We build a new subtype indication using the full view of the
16123 -- incomplete parent. The discriminant constraints have been
16124 -- elaborated already at the point of the subtype declaration.
16126 New_Subt := Create_Itype (E_Void, N);
16128 if Has_Discriminants (Full_T) then
16129 Disc_Constraint := Discriminant_Constraint (Priv_Dep);
16131 Disc_Constraint := No_Elist;
16134 Build_Discriminated_Subtype (Full_T, New_Subt, Disc_Constraint, N);
16135 Set_Full_View (Priv_Dep, New_Subt);
16138 Next_Elmt (Inc_Elmt);
16140 end Process_Incomplete_Dependents;
16142 --------------------------------
16143 -- Process_Range_Expr_In_Decl --
16144 --------------------------------
16146 procedure Process_Range_Expr_In_Decl
16149 Check_List : List_Id := Empty_List;
16150 R_Check_Off : Boolean := False)
16153 R_Checks : Check_Result;
16154 Type_Decl : Node_Id;
16155 Def_Id : Entity_Id;
16158 Analyze_And_Resolve (R, Base_Type (T));
16160 if Nkind (R) = N_Range then
16161 Lo := Low_Bound (R);
16162 Hi := High_Bound (R);
16164 -- We need to ensure validity of the bounds here, because if we
16165 -- go ahead and do the expansion, then the expanded code will get
16166 -- analyzed with range checks suppressed and we miss the check.
16168 Validity_Check_Range (R);
16170 -- If there were errors in the declaration, try and patch up some
16171 -- common mistakes in the bounds. The cases handled are literals
16172 -- which are Integer where the expected type is Real and vice versa.
16173 -- These corrections allow the compilation process to proceed further
16174 -- along since some basic assumptions of the format of the bounds
16177 if Etype (R) = Any_Type then
16179 if Nkind (Lo) = N_Integer_Literal and then Is_Real_Type (T) then
16181 Make_Real_Literal (Sloc (Lo), UR_From_Uint (Intval (Lo))));
16183 elsif Nkind (Hi) = N_Integer_Literal and then Is_Real_Type (T) then
16185 Make_Real_Literal (Sloc (Hi), UR_From_Uint (Intval (Hi))));
16187 elsif Nkind (Lo) = N_Real_Literal and then Is_Integer_Type (T) then
16189 Make_Integer_Literal (Sloc (Lo), UR_To_Uint (Realval (Lo))));
16191 elsif Nkind (Hi) = N_Real_Literal and then Is_Integer_Type (T) then
16193 Make_Integer_Literal (Sloc (Hi), UR_To_Uint (Realval (Hi))));
16200 -- If the bounds of the range have been mistakenly given as string
16201 -- literals (perhaps in place of character literals), then an error
16202 -- has already been reported, but we rewrite the string literal as a
16203 -- bound of the range's type to avoid blowups in later processing
16204 -- that looks at static values.
16206 if Nkind (Lo) = N_String_Literal then
16208 Make_Attribute_Reference (Sloc (Lo),
16209 Attribute_Name => Name_First,
16210 Prefix => New_Reference_To (T, Sloc (Lo))));
16211 Analyze_And_Resolve (Lo);
16214 if Nkind (Hi) = N_String_Literal then
16216 Make_Attribute_Reference (Sloc (Hi),
16217 Attribute_Name => Name_First,
16218 Prefix => New_Reference_To (T, Sloc (Hi))));
16219 Analyze_And_Resolve (Hi);
16222 -- If bounds aren't scalar at this point then exit, avoiding
16223 -- problems with further processing of the range in this procedure.
16225 if not Is_Scalar_Type (Etype (Lo)) then
16229 -- Resolve (actually Sem_Eval) has checked that the bounds are in
16230 -- then range of the base type. Here we check whether the bounds
16231 -- are in the range of the subtype itself. Note that if the bounds
16232 -- represent the null range the Constraint_Error exception should
16235 -- ??? The following code should be cleaned up as follows
16237 -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
16238 -- is done in the call to Range_Check (R, T); below
16240 -- 2. The use of R_Check_Off should be investigated and possibly
16241 -- removed, this would clean up things a bit.
16243 if Is_Null_Range (Lo, Hi) then
16247 -- Capture values of bounds and generate temporaries for them
16248 -- if needed, before applying checks, since checks may cause
16249 -- duplication of the expression without forcing evaluation.
16251 if Expander_Active then
16252 Force_Evaluation (Lo);
16253 Force_Evaluation (Hi);
16256 -- We use a flag here instead of suppressing checks on the
16257 -- type because the type we check against isn't necessarily
16258 -- the place where we put the check.
16260 if not R_Check_Off then
16261 R_Checks := Get_Range_Checks (R, T);
16263 -- Look up tree to find an appropriate insertion point.
16264 -- This seems really junk code, and very brittle, couldn't
16265 -- we just use an insert actions call of some kind ???
16267 Type_Decl := Parent (R);
16268 while Present (Type_Decl) and then not
16269 (Nkind_In (Type_Decl, N_Full_Type_Declaration,
16270 N_Subtype_Declaration,
16272 N_Task_Type_Declaration)
16274 Nkind_In (Type_Decl, N_Single_Task_Declaration,
16275 N_Protected_Type_Declaration,
16276 N_Single_Protected_Declaration))
16278 Type_Decl := Parent (Type_Decl);
16281 -- Why would Type_Decl not be present??? Without this test,
16282 -- short regression tests fail.
16284 if Present (Type_Decl) then
16286 -- Case of loop statement (more comments ???)
16288 if Nkind (Type_Decl) = N_Loop_Statement then
16293 Indic := Parent (R);
16294 while Present (Indic)
16295 and then Nkind (Indic) /= N_Subtype_Indication
16297 Indic := Parent (Indic);
16300 if Present (Indic) then
16301 Def_Id := Etype (Subtype_Mark (Indic));
16303 Insert_Range_Checks
16309 Do_Before => True);
16313 -- All other cases (more comments ???)
16316 Def_Id := Defining_Identifier (Type_Decl);
16318 if (Ekind (Def_Id) = E_Record_Type
16319 and then Depends_On_Discriminant (R))
16321 (Ekind (Def_Id) = E_Protected_Type
16322 and then Has_Discriminants (Def_Id))
16324 Append_Range_Checks
16325 (R_Checks, Check_List, Def_Id, Sloc (Type_Decl), R);
16328 Insert_Range_Checks
16329 (R_Checks, Type_Decl, Def_Id, Sloc (Type_Decl), R);
16337 elsif Expander_Active then
16338 Get_Index_Bounds (R, Lo, Hi);
16339 Force_Evaluation (Lo);
16340 Force_Evaluation (Hi);
16342 end Process_Range_Expr_In_Decl;
16344 --------------------------------------
16345 -- Process_Real_Range_Specification --
16346 --------------------------------------
16348 procedure Process_Real_Range_Specification (Def : Node_Id) is
16349 Spec : constant Node_Id := Real_Range_Specification (Def);
16352 Err : Boolean := False;
16354 procedure Analyze_Bound (N : Node_Id);
16355 -- Analyze and check one bound
16357 -------------------
16358 -- Analyze_Bound --
16359 -------------------
16361 procedure Analyze_Bound (N : Node_Id) is
16363 Analyze_And_Resolve (N, Any_Real);
16365 if not Is_OK_Static_Expression (N) then
16366 Flag_Non_Static_Expr
16367 ("bound in real type definition is not static!", N);
16372 -- Start of processing for Process_Real_Range_Specification
16375 if Present (Spec) then
16376 Lo := Low_Bound (Spec);
16377 Hi := High_Bound (Spec);
16378 Analyze_Bound (Lo);
16379 Analyze_Bound (Hi);
16381 -- If error, clear away junk range specification
16384 Set_Real_Range_Specification (Def, Empty);
16387 end Process_Real_Range_Specification;
16389 ---------------------
16390 -- Process_Subtype --
16391 ---------------------
16393 function Process_Subtype
16395 Related_Nod : Node_Id;
16396 Related_Id : Entity_Id := Empty;
16397 Suffix : Character := ' ') return Entity_Id
16400 Def_Id : Entity_Id;
16401 Error_Node : Node_Id;
16402 Full_View_Id : Entity_Id;
16403 Subtype_Mark_Id : Entity_Id;
16405 May_Have_Null_Exclusion : Boolean;
16407 procedure Check_Incomplete (T : Entity_Id);
16408 -- Called to verify that an incomplete type is not used prematurely
16410 ----------------------
16411 -- Check_Incomplete --
16412 ----------------------
16414 procedure Check_Incomplete (T : Entity_Id) is
16416 -- Ada 2005 (AI-412): Incomplete subtypes are legal
16418 if Ekind (Root_Type (Entity (T))) = E_Incomplete_Type
16420 not (Ada_Version >= Ada_05
16422 (Nkind (Parent (T)) = N_Subtype_Declaration
16424 (Nkind (Parent (T)) = N_Subtype_Indication
16425 and then Nkind (Parent (Parent (T))) =
16426 N_Subtype_Declaration)))
16428 Error_Msg_N ("invalid use of type before its full declaration", T);
16430 end Check_Incomplete;
16432 -- Start of processing for Process_Subtype
16435 -- Case of no constraints present
16437 if Nkind (S) /= N_Subtype_Indication then
16439 Check_Incomplete (S);
16442 -- Ada 2005 (AI-231): Static check
16444 if Ada_Version >= Ada_05
16445 and then Present (P)
16446 and then Null_Exclusion_Present (P)
16447 and then Nkind (P) /= N_Access_To_Object_Definition
16448 and then not Is_Access_Type (Entity (S))
16450 Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
16453 -- The following is ugly, can't we have a range or even a flag???
16455 May_Have_Null_Exclusion :=
16456 Nkind_In (P, N_Access_Definition,
16457 N_Access_Function_Definition,
16458 N_Access_Procedure_Definition,
16459 N_Access_To_Object_Definition,
16461 N_Component_Definition)
16463 Nkind_In (P, N_Derived_Type_Definition,
16464 N_Discriminant_Specification,
16465 N_Object_Declaration,
16466 N_Parameter_Specification,
16467 N_Subtype_Declaration);
16469 -- Create an Itype that is a duplicate of Entity (S) but with the
16470 -- null-exclusion attribute
16472 if May_Have_Null_Exclusion
16473 and then Is_Access_Type (Entity (S))
16474 and then Null_Exclusion_Present (P)
16476 -- No need to check the case of an access to object definition.
16477 -- It is correct to define double not-null pointers.
16480 -- type Not_Null_Int_Ptr is not null access Integer;
16481 -- type Acc is not null access Not_Null_Int_Ptr;
16483 and then Nkind (P) /= N_Access_To_Object_Definition
16485 if Can_Never_Be_Null (Entity (S)) then
16486 case Nkind (Related_Nod) is
16487 when N_Full_Type_Declaration =>
16488 if Nkind (Type_Definition (Related_Nod))
16489 in N_Array_Type_Definition
16493 (Component_Definition
16494 (Type_Definition (Related_Nod)));
16497 Subtype_Indication (Type_Definition (Related_Nod));
16500 when N_Subtype_Declaration =>
16501 Error_Node := Subtype_Indication (Related_Nod);
16503 when N_Object_Declaration =>
16504 Error_Node := Object_Definition (Related_Nod);
16506 when N_Component_Declaration =>
16508 Subtype_Indication (Component_Definition (Related_Nod));
16511 pragma Assert (False);
16512 Error_Node := Related_Nod;
16516 ("`NOT NULL` not allowed (& already excludes null)",
16522 Create_Null_Excluding_Itype
16524 Related_Nod => P));
16525 Set_Entity (S, Etype (S));
16530 -- Case of constraint present, so that we have an N_Subtype_Indication
16531 -- node (this node is created only if constraints are present).
16534 Find_Type (Subtype_Mark (S));
16536 if Nkind (Parent (S)) /= N_Access_To_Object_Definition
16538 (Nkind (Parent (S)) = N_Subtype_Declaration
16539 and then Is_Itype (Defining_Identifier (Parent (S))))
16541 Check_Incomplete (Subtype_Mark (S));
16545 Subtype_Mark_Id := Entity (Subtype_Mark (S));
16547 -- Explicit subtype declaration case
16549 if Nkind (P) = N_Subtype_Declaration then
16550 Def_Id := Defining_Identifier (P);
16552 -- Explicit derived type definition case
16554 elsif Nkind (P) = N_Derived_Type_Definition then
16555 Def_Id := Defining_Identifier (Parent (P));
16557 -- Implicit case, the Def_Id must be created as an implicit type.
16558 -- The one exception arises in the case of concurrent types, array
16559 -- and access types, where other subsidiary implicit types may be
16560 -- created and must appear before the main implicit type. In these
16561 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
16562 -- has not yet been called to create Def_Id.
16565 if Is_Array_Type (Subtype_Mark_Id)
16566 or else Is_Concurrent_Type (Subtype_Mark_Id)
16567 or else Is_Access_Type (Subtype_Mark_Id)
16571 -- For the other cases, we create a new unattached Itype,
16572 -- and set the indication to ensure it gets attached later.
16576 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16580 -- If the kind of constraint is invalid for this kind of type,
16581 -- then give an error, and then pretend no constraint was given.
16583 if not Is_Valid_Constraint_Kind
16584 (Ekind (Subtype_Mark_Id), Nkind (Constraint (S)))
16587 ("incorrect constraint for this kind of type", Constraint (S));
16589 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
16591 -- Set Ekind of orphan itype, to prevent cascaded errors
16593 if Present (Def_Id) then
16594 Set_Ekind (Def_Id, Ekind (Any_Type));
16597 -- Make recursive call, having got rid of the bogus constraint
16599 return Process_Subtype (S, Related_Nod, Related_Id, Suffix);
16602 -- Remaining processing depends on type
16604 case Ekind (Subtype_Mark_Id) is
16605 when Access_Kind =>
16606 Constrain_Access (Def_Id, S, Related_Nod);
16609 and then Is_Itype (Designated_Type (Def_Id))
16610 and then Nkind (Related_Nod) = N_Subtype_Declaration
16611 and then not Is_Incomplete_Type (Designated_Type (Def_Id))
16613 Build_Itype_Reference
16614 (Designated_Type (Def_Id), Related_Nod);
16618 Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix);
16620 when Decimal_Fixed_Point_Kind =>
16621 Constrain_Decimal (Def_Id, S);
16623 when Enumeration_Kind =>
16624 Constrain_Enumeration (Def_Id, S);
16626 when Ordinary_Fixed_Point_Kind =>
16627 Constrain_Ordinary_Fixed (Def_Id, S);
16630 Constrain_Float (Def_Id, S);
16632 when Integer_Kind =>
16633 Constrain_Integer (Def_Id, S);
16635 when E_Record_Type |
16638 E_Incomplete_Type =>
16639 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16641 when Private_Kind =>
16642 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16643 Set_Private_Dependents (Def_Id, New_Elmt_List);
16645 -- In case of an invalid constraint prevent further processing
16646 -- since the type constructed is missing expected fields.
16648 if Etype (Def_Id) = Any_Type then
16652 -- If the full view is that of a task with discriminants,
16653 -- we must constrain both the concurrent type and its
16654 -- corresponding record type. Otherwise we will just propagate
16655 -- the constraint to the full view, if available.
16657 if Present (Full_View (Subtype_Mark_Id))
16658 and then Has_Discriminants (Subtype_Mark_Id)
16659 and then Is_Concurrent_Type (Full_View (Subtype_Mark_Id))
16662 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16664 Set_Entity (Subtype_Mark (S), Full_View (Subtype_Mark_Id));
16665 Constrain_Concurrent (Full_View_Id, S,
16666 Related_Nod, Related_Id, Suffix);
16667 Set_Entity (Subtype_Mark (S), Subtype_Mark_Id);
16668 Set_Full_View (Def_Id, Full_View_Id);
16670 -- Introduce an explicit reference to the private subtype,
16671 -- to prevent scope anomalies in gigi if first use appears
16672 -- in a nested context, e.g. a later function body.
16673 -- Should this be generated in other contexts than a full
16674 -- type declaration?
16676 if Is_Itype (Def_Id)
16678 Nkind (Parent (P)) = N_Full_Type_Declaration
16680 Build_Itype_Reference (Def_Id, Parent (P));
16684 Prepare_Private_Subtype_Completion (Def_Id, Related_Nod);
16687 when Concurrent_Kind =>
16688 Constrain_Concurrent (Def_Id, S,
16689 Related_Nod, Related_Id, Suffix);
16692 Error_Msg_N ("invalid subtype mark in subtype indication", S);
16695 -- Size and Convention are always inherited from the base type
16697 Set_Size_Info (Def_Id, (Subtype_Mark_Id));
16698 Set_Convention (Def_Id, Convention (Subtype_Mark_Id));
16702 end Process_Subtype;
16704 ---------------------------------------
16705 -- Check_Anonymous_Access_Components --
16706 ---------------------------------------
16708 procedure Check_Anonymous_Access_Components
16709 (Typ_Decl : Node_Id;
16712 Comp_List : Node_Id)
16714 Loc : constant Source_Ptr := Sloc (Typ_Decl);
16715 Anon_Access : Entity_Id;
16718 Comp_Def : Node_Id;
16720 Type_Def : Node_Id;
16722 procedure Build_Incomplete_Type_Declaration;
16723 -- If the record type contains components that include an access to the
16724 -- current record, then create an incomplete type declaration for the
16725 -- record, to be used as the designated type of the anonymous access.
16726 -- This is done only once, and only if there is no previous partial
16727 -- view of the type.
16729 function Designates_T (Subt : Node_Id) return Boolean;
16730 -- Check whether a node designates the enclosing record type, or 'Class
16733 function Mentions_T (Acc_Def : Node_Id) return Boolean;
16734 -- Check whether an access definition includes a reference to
16735 -- the enclosing record type. The reference can be a subtype mark
16736 -- in the access definition itself, a 'Class attribute reference, or
16737 -- recursively a reference appearing in a parameter specification
16738 -- or result definition of an access_to_subprogram definition.
16740 --------------------------------------
16741 -- Build_Incomplete_Type_Declaration --
16742 --------------------------------------
16744 procedure Build_Incomplete_Type_Declaration is
16749 -- Is_Tagged indicates whether the type is tagged. It is tagged if
16750 -- it's "is new ... with record" or else "is tagged record ...".
16752 Is_Tagged : constant Boolean :=
16753 (Nkind (Type_Definition (Typ_Decl)) = N_Derived_Type_Definition
16756 (Record_Extension_Part (Type_Definition (Typ_Decl))))
16758 (Nkind (Type_Definition (Typ_Decl)) = N_Record_Definition
16759 and then Tagged_Present (Type_Definition (Typ_Decl)));
16762 -- If there is a previous partial view, no need to create a new one
16763 -- If the partial view, given by Prev, is incomplete, If Prev is
16764 -- a private declaration, full declaration is flagged accordingly.
16766 if Prev /= Typ then
16768 Make_Class_Wide_Type (Prev);
16769 Set_Class_Wide_Type (Typ, Class_Wide_Type (Prev));
16770 Set_Etype (Class_Wide_Type (Typ), Typ);
16775 elsif Has_Private_Declaration (Typ) then
16777 -- If we refer to T'Class inside T, and T is the completion of a
16778 -- private type, then we need to make sure the class-wide type
16782 Make_Class_Wide_Type (Typ);
16787 -- If there was a previous anonymous access type, the incomplete
16788 -- type declaration will have been created already.
16790 elsif Present (Current_Entity (Typ))
16791 and then Ekind (Current_Entity (Typ)) = E_Incomplete_Type
16792 and then Full_View (Current_Entity (Typ)) = Typ
16797 Inc_T := Make_Defining_Identifier (Loc, Chars (Typ));
16798 Decl := Make_Incomplete_Type_Declaration (Loc, Inc_T);
16800 -- Type has already been inserted into the current scope.
16801 -- Remove it, and add incomplete declaration for type, so
16802 -- that subsequent anonymous access types can use it.
16803 -- The entity is unchained from the homonym list and from
16804 -- immediate visibility. After analysis, the entity in the
16805 -- incomplete declaration becomes immediately visible in the
16806 -- record declaration that follows.
16808 H := Current_Entity (Typ);
16811 Set_Name_Entity_Id (Chars (Typ), Homonym (Typ));
16814 and then Homonym (H) /= Typ
16816 H := Homonym (Typ);
16819 Set_Homonym (H, Homonym (Typ));
16822 Insert_Before (Typ_Decl, Decl);
16824 Set_Full_View (Inc_T, Typ);
16827 -- Create a common class-wide type for both views, and set
16828 -- the Etype of the class-wide type to the full view.
16830 Make_Class_Wide_Type (Inc_T);
16831 Set_Class_Wide_Type (Typ, Class_Wide_Type (Inc_T));
16832 Set_Etype (Class_Wide_Type (Typ), Typ);
16835 end Build_Incomplete_Type_Declaration;
16841 function Designates_T (Subt : Node_Id) return Boolean is
16842 Type_Id : constant Name_Id := Chars (Typ);
16844 function Names_T (Nam : Node_Id) return Boolean;
16845 -- The record type has not been introduced in the current scope
16846 -- yet, so we must examine the name of the type itself, either
16847 -- an identifier T, or an expanded name of the form P.T, where
16848 -- P denotes the current scope.
16854 function Names_T (Nam : Node_Id) return Boolean is
16856 if Nkind (Nam) = N_Identifier then
16857 return Chars (Nam) = Type_Id;
16859 elsif Nkind (Nam) = N_Selected_Component then
16860 if Chars (Selector_Name (Nam)) = Type_Id then
16861 if Nkind (Prefix (Nam)) = N_Identifier then
16862 return Chars (Prefix (Nam)) = Chars (Current_Scope);
16864 elsif Nkind (Prefix (Nam)) = N_Selected_Component then
16865 return Chars (Selector_Name (Prefix (Nam))) =
16866 Chars (Current_Scope);
16880 -- Start of processing for Designates_T
16883 if Nkind (Subt) = N_Identifier then
16884 return Chars (Subt) = Type_Id;
16886 -- Reference can be through an expanded name which has not been
16887 -- analyzed yet, and which designates enclosing scopes.
16889 elsif Nkind (Subt) = N_Selected_Component then
16890 if Names_T (Subt) then
16893 -- Otherwise it must denote an entity that is already visible.
16894 -- The access definition may name a subtype of the enclosing
16895 -- type, if there is a previous incomplete declaration for it.
16898 Find_Selected_Component (Subt);
16900 Is_Entity_Name (Subt)
16901 and then Scope (Entity (Subt)) = Current_Scope
16903 (Chars (Base_Type (Entity (Subt))) = Type_Id
16905 (Is_Class_Wide_Type (Entity (Subt))
16907 Chars (Etype (Base_Type (Entity (Subt)))) =
16911 -- A reference to the current type may appear as the prefix of
16912 -- a 'Class attribute.
16914 elsif Nkind (Subt) = N_Attribute_Reference
16915 and then Attribute_Name (Subt) = Name_Class
16917 return Names_T (Prefix (Subt));
16928 function Mentions_T (Acc_Def : Node_Id) return Boolean is
16929 Param_Spec : Node_Id;
16931 Acc_Subprg : constant Node_Id :=
16932 Access_To_Subprogram_Definition (Acc_Def);
16935 if No (Acc_Subprg) then
16936 return Designates_T (Subtype_Mark (Acc_Def));
16939 -- Component is an access_to_subprogram: examine its formals,
16940 -- and result definition in the case of an access_to_function.
16942 Param_Spec := First (Parameter_Specifications (Acc_Subprg));
16943 while Present (Param_Spec) loop
16944 if Nkind (Parameter_Type (Param_Spec)) = N_Access_Definition
16945 and then Mentions_T (Parameter_Type (Param_Spec))
16949 elsif Designates_T (Parameter_Type (Param_Spec)) then
16956 if Nkind (Acc_Subprg) = N_Access_Function_Definition then
16957 if Nkind (Result_Definition (Acc_Subprg)) =
16958 N_Access_Definition
16960 return Mentions_T (Result_Definition (Acc_Subprg));
16962 return Designates_T (Result_Definition (Acc_Subprg));
16969 -- Start of processing for Check_Anonymous_Access_Components
16972 if No (Comp_List) then
16976 Comp := First (Component_Items (Comp_List));
16977 while Present (Comp) loop
16978 if Nkind (Comp) = N_Component_Declaration
16980 (Access_Definition (Component_Definition (Comp)))
16982 Mentions_T (Access_Definition (Component_Definition (Comp)))
16984 Comp_Def := Component_Definition (Comp);
16986 Access_To_Subprogram_Definition
16987 (Access_Definition (Comp_Def));
16989 Build_Incomplete_Type_Declaration;
16991 Make_Defining_Identifier (Loc,
16992 Chars => New_Internal_Name ('S'));
16994 -- Create a declaration for the anonymous access type: either
16995 -- an access_to_object or an access_to_subprogram.
16997 if Present (Acc_Def) then
16998 if Nkind (Acc_Def) = N_Access_Function_Definition then
17000 Make_Access_Function_Definition (Loc,
17001 Parameter_Specifications =>
17002 Parameter_Specifications (Acc_Def),
17003 Result_Definition => Result_Definition (Acc_Def));
17006 Make_Access_Procedure_Definition (Loc,
17007 Parameter_Specifications =>
17008 Parameter_Specifications (Acc_Def));
17013 Make_Access_To_Object_Definition (Loc,
17014 Subtype_Indication =>
17017 (Access_Definition (Comp_Def))));
17019 Set_Constant_Present
17020 (Type_Def, Constant_Present (Access_Definition (Comp_Def)));
17022 (Type_Def, All_Present (Access_Definition (Comp_Def)));
17025 Set_Null_Exclusion_Present
17027 Null_Exclusion_Present (Access_Definition (Comp_Def)));
17030 Make_Full_Type_Declaration (Loc,
17031 Defining_Identifier => Anon_Access,
17032 Type_Definition => Type_Def);
17034 Insert_Before (Typ_Decl, Decl);
17037 -- If an access to object, Preserve entity of designated type,
17038 -- for ASIS use, before rewriting the component definition.
17040 if No (Acc_Def) then
17045 Desig := Entity (Subtype_Indication (Type_Def));
17047 -- If the access definition is to the current record,
17048 -- the visible entity at this point is an incomplete
17049 -- type. Retrieve the full view to simplify ASIS queries
17051 if Ekind (Desig) = E_Incomplete_Type then
17052 Desig := Full_View (Desig);
17056 (Subtype_Mark (Access_Definition (Comp_Def)), Desig);
17061 Make_Component_Definition (Loc,
17062 Subtype_Indication =>
17063 New_Occurrence_Of (Anon_Access, Loc)));
17065 if Ekind (Designated_Type (Anon_Access)) = E_Subprogram_Type then
17066 Set_Ekind (Anon_Access, E_Anonymous_Access_Subprogram_Type);
17068 Set_Ekind (Anon_Access, E_Anonymous_Access_Type);
17071 Set_Is_Local_Anonymous_Access (Anon_Access);
17077 if Present (Variant_Part (Comp_List)) then
17081 V := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
17082 while Present (V) loop
17083 Check_Anonymous_Access_Components
17084 (Typ_Decl, Typ, Prev, Component_List (V));
17085 Next_Non_Pragma (V);
17089 end Check_Anonymous_Access_Components;
17091 --------------------------------
17092 -- Preanalyze_Spec_Expression --
17093 --------------------------------
17095 procedure Preanalyze_Spec_Expression (N : Node_Id; T : Entity_Id) is
17096 Save_In_Spec_Expression : constant Boolean := In_Spec_Expression;
17098 In_Spec_Expression := True;
17099 Preanalyze_And_Resolve (N, T);
17100 In_Spec_Expression := Save_In_Spec_Expression;
17101 end Preanalyze_Spec_Expression;
17103 -----------------------------
17104 -- Record_Type_Declaration --
17105 -----------------------------
17107 procedure Record_Type_Declaration
17112 Def : constant Node_Id := Type_Definition (N);
17113 Is_Tagged : Boolean;
17114 Tag_Comp : Entity_Id;
17117 -- These flags must be initialized before calling Process_Discriminants
17118 -- because this routine makes use of them.
17120 Set_Ekind (T, E_Record_Type);
17122 Init_Size_Align (T);
17123 Set_Interfaces (T, No_Elist);
17124 Set_Stored_Constraint (T, No_Elist);
17128 if Ada_Version < Ada_05
17129 or else not Interface_Present (Def)
17131 -- The flag Is_Tagged_Type might have already been set by
17132 -- Find_Type_Name if it detected an error for declaration T. This
17133 -- arises in the case of private tagged types where the full view
17134 -- omits the word tagged.
17137 Tagged_Present (Def)
17138 or else (Serious_Errors_Detected > 0 and then Is_Tagged_Type (T));
17140 Set_Is_Tagged_Type (T, Is_Tagged);
17141 Set_Is_Limited_Record (T, Limited_Present (Def));
17143 -- Type is abstract if full declaration carries keyword, or if
17144 -- previous partial view did.
17146 Set_Is_Abstract_Type (T, Is_Abstract_Type (T)
17147 or else Abstract_Present (Def));
17151 Analyze_Interface_Declaration (T, Def);
17153 if Present (Discriminant_Specifications (N)) then
17155 ("interface types cannot have discriminants",
17156 Defining_Identifier
17157 (First (Discriminant_Specifications (N))));
17161 -- First pass: if there are self-referential access components,
17162 -- create the required anonymous access type declarations, and if
17163 -- need be an incomplete type declaration for T itself.
17165 Check_Anonymous_Access_Components (N, T, Prev, Component_List (Def));
17167 if Ada_Version >= Ada_05
17168 and then Present (Interface_List (Def))
17170 Check_Interfaces (N, Def);
17173 Ifaces_List : Elist_Id;
17176 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
17177 -- already in the parents.
17181 Ifaces_List => Ifaces_List,
17182 Exclude_Parents => True);
17184 Set_Interfaces (T, Ifaces_List);
17188 -- Records constitute a scope for the component declarations within.
17189 -- The scope is created prior to the processing of these declarations.
17190 -- Discriminants are processed first, so that they are visible when
17191 -- processing the other components. The Ekind of the record type itself
17192 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
17194 -- Enter record scope
17198 -- If an incomplete or private type declaration was already given for
17199 -- the type, then this scope already exists, and the discriminants have
17200 -- been declared within. We must verify that the full declaration
17201 -- matches the incomplete one.
17203 Check_Or_Process_Discriminants (N, T, Prev);
17205 Set_Is_Constrained (T, not Has_Discriminants (T));
17206 Set_Has_Delayed_Freeze (T, True);
17208 -- For tagged types add a manually analyzed component corresponding
17209 -- to the component _tag, the corresponding piece of tree will be
17210 -- expanded as part of the freezing actions if it is not a CPP_Class.
17214 -- Do not add the tag unless we are in expansion mode
17216 if Expander_Active then
17217 Tag_Comp := Make_Defining_Identifier (Sloc (Def), Name_uTag);
17218 Enter_Name (Tag_Comp);
17220 Set_Ekind (Tag_Comp, E_Component);
17221 Set_Is_Tag (Tag_Comp);
17222 Set_Is_Aliased (Tag_Comp);
17223 Set_Etype (Tag_Comp, RTE (RE_Tag));
17224 Set_DT_Entry_Count (Tag_Comp, No_Uint);
17225 Set_Original_Record_Component (Tag_Comp, Tag_Comp);
17226 Init_Component_Location (Tag_Comp);
17228 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
17229 -- implemented interfaces.
17231 if Has_Interfaces (T) then
17232 Add_Interface_Tag_Components (N, T);
17236 Make_Class_Wide_Type (T);
17237 Set_Primitive_Operations (T, New_Elmt_List);
17240 -- We must suppress range checks when processing the components
17241 -- of a record in the presence of discriminants, since we don't
17242 -- want spurious checks to be generated during their analysis, but
17243 -- must reset the Suppress_Range_Checks flags after having processed
17244 -- the record definition.
17246 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
17247 -- couldn't we just use the normal range check suppression method here.
17248 -- That would seem cleaner ???
17250 if Has_Discriminants (T) and then not Range_Checks_Suppressed (T) then
17251 Set_Kill_Range_Checks (T, True);
17252 Record_Type_Definition (Def, Prev);
17253 Set_Kill_Range_Checks (T, False);
17255 Record_Type_Definition (Def, Prev);
17258 -- Exit from record scope
17262 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
17263 -- the implemented interfaces and associate them an aliased entity.
17266 and then not Is_Empty_List (Interface_List (Def))
17268 Derive_Progenitor_Subprograms (T, T);
17270 end Record_Type_Declaration;
17272 ----------------------------
17273 -- Record_Type_Definition --
17274 ----------------------------
17276 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id) is
17277 Component : Entity_Id;
17278 Ctrl_Components : Boolean := False;
17279 Final_Storage_Only : Boolean;
17283 if Ekind (Prev_T) = E_Incomplete_Type then
17284 T := Full_View (Prev_T);
17289 Final_Storage_Only := not Is_Controlled (T);
17291 -- Ada 2005: check whether an explicit Limited is present in a derived
17292 -- type declaration.
17294 if Nkind (Parent (Def)) = N_Derived_Type_Definition
17295 and then Limited_Present (Parent (Def))
17297 Set_Is_Limited_Record (T);
17300 -- If the component list of a record type is defined by the reserved
17301 -- word null and there is no discriminant part, then the record type has
17302 -- no components and all records of the type are null records (RM 3.7)
17303 -- This procedure is also called to process the extension part of a
17304 -- record extension, in which case the current scope may have inherited
17308 or else No (Component_List (Def))
17309 or else Null_Present (Component_List (Def))
17314 Analyze_Declarations (Component_Items (Component_List (Def)));
17316 if Present (Variant_Part (Component_List (Def))) then
17317 Analyze (Variant_Part (Component_List (Def)));
17321 -- After completing the semantic analysis of the record definition,
17322 -- record components, both new and inherited, are accessible. Set their
17323 -- kind accordingly. Exclude malformed itypes from illegal declarations,
17324 -- whose Ekind may be void.
17326 Component := First_Entity (Current_Scope);
17327 while Present (Component) loop
17328 if Ekind (Component) = E_Void
17329 and then not Is_Itype (Component)
17331 Set_Ekind (Component, E_Component);
17332 Init_Component_Location (Component);
17335 if Has_Task (Etype (Component)) then
17339 if Ekind (Component) /= E_Component then
17342 elsif Has_Controlled_Component (Etype (Component))
17343 or else (Chars (Component) /= Name_uParent
17344 and then Is_Controlled (Etype (Component)))
17346 Set_Has_Controlled_Component (T, True);
17347 Final_Storage_Only :=
17349 and then Finalize_Storage_Only (Etype (Component));
17350 Ctrl_Components := True;
17353 Next_Entity (Component);
17356 -- A Type is Finalize_Storage_Only only if all its controlled components
17359 if Ctrl_Components then
17360 Set_Finalize_Storage_Only (T, Final_Storage_Only);
17363 -- Place reference to end record on the proper entity, which may
17364 -- be a partial view.
17366 if Present (Def) then
17367 Process_End_Label (Def, 'e', Prev_T);
17369 end Record_Type_Definition;
17371 ------------------------
17372 -- Replace_Components --
17373 ------------------------
17375 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id) is
17376 function Process (N : Node_Id) return Traverse_Result;
17382 function Process (N : Node_Id) return Traverse_Result is
17386 if Nkind (N) = N_Discriminant_Specification then
17387 Comp := First_Discriminant (Typ);
17388 while Present (Comp) loop
17389 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17390 Set_Defining_Identifier (N, Comp);
17394 Next_Discriminant (Comp);
17397 elsif Nkind (N) = N_Component_Declaration then
17398 Comp := First_Component (Typ);
17399 while Present (Comp) loop
17400 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17401 Set_Defining_Identifier (N, Comp);
17405 Next_Component (Comp);
17412 procedure Replace is new Traverse_Proc (Process);
17414 -- Start of processing for Replace_Components
17418 end Replace_Components;
17420 -------------------------------
17421 -- Set_Completion_Referenced --
17422 -------------------------------
17424 procedure Set_Completion_Referenced (E : Entity_Id) is
17426 -- If in main unit, mark entity that is a completion as referenced,
17427 -- warnings go on the partial view when needed.
17429 if In_Extended_Main_Source_Unit (E) then
17430 Set_Referenced (E);
17432 end Set_Completion_Referenced;
17434 ---------------------
17435 -- Set_Fixed_Range --
17436 ---------------------
17438 -- The range for fixed-point types is complicated by the fact that we
17439 -- do not know the exact end points at the time of the declaration. This
17440 -- is true for three reasons:
17442 -- A size clause may affect the fudging of the end-points
17443 -- A small clause may affect the values of the end-points
17444 -- We try to include the end-points if it does not affect the size
17446 -- This means that the actual end-points must be established at the point
17447 -- when the type is frozen. Meanwhile, we first narrow the range as
17448 -- permitted (so that it will fit if necessary in a small specified size),
17449 -- and then build a range subtree with these narrowed bounds.
17451 -- Set_Fixed_Range constructs the range from real literal values, and sets
17452 -- the range as the Scalar_Range of the given fixed-point type entity.
17454 -- The parent of this range is set to point to the entity so that it is
17455 -- properly hooked into the tree (unlike normal Scalar_Range entries for
17456 -- other scalar types, which are just pointers to the range in the
17457 -- original tree, this would otherwise be an orphan).
17459 -- The tree is left unanalyzed. When the type is frozen, the processing
17460 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
17461 -- analyzed, and uses this as an indication that it should complete
17462 -- work on the range (it will know the final small and size values).
17464 procedure Set_Fixed_Range
17470 S : constant Node_Id :=
17472 Low_Bound => Make_Real_Literal (Loc, Lo),
17473 High_Bound => Make_Real_Literal (Loc, Hi));
17475 Set_Scalar_Range (E, S);
17477 end Set_Fixed_Range;
17479 ----------------------------------
17480 -- Set_Scalar_Range_For_Subtype --
17481 ----------------------------------
17483 procedure Set_Scalar_Range_For_Subtype
17484 (Def_Id : Entity_Id;
17488 Kind : constant Entity_Kind := Ekind (Def_Id);
17491 Set_Scalar_Range (Def_Id, R);
17493 -- We need to link the range into the tree before resolving it so
17494 -- that types that are referenced, including importantly the subtype
17495 -- itself, are properly frozen (Freeze_Expression requires that the
17496 -- expression be properly linked into the tree). Of course if it is
17497 -- already linked in, then we do not disturb the current link.
17499 if No (Parent (R)) then
17500 Set_Parent (R, Def_Id);
17503 -- Reset the kind of the subtype during analysis of the range, to
17504 -- catch possible premature use in the bounds themselves.
17506 Set_Ekind (Def_Id, E_Void);
17507 Process_Range_Expr_In_Decl (R, Subt);
17508 Set_Ekind (Def_Id, Kind);
17509 end Set_Scalar_Range_For_Subtype;
17511 --------------------------------------------------------
17512 -- Set_Stored_Constraint_From_Discriminant_Constraint --
17513 --------------------------------------------------------
17515 procedure Set_Stored_Constraint_From_Discriminant_Constraint
17519 -- Make sure set if encountered during Expand_To_Stored_Constraint
17521 Set_Stored_Constraint (E, No_Elist);
17523 -- Give it the right value
17525 if Is_Constrained (E) and then Has_Discriminants (E) then
17526 Set_Stored_Constraint (E,
17527 Expand_To_Stored_Constraint (E, Discriminant_Constraint (E)));
17529 end Set_Stored_Constraint_From_Discriminant_Constraint;
17531 -------------------------------------
17532 -- Signed_Integer_Type_Declaration --
17533 -------------------------------------
17535 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id) is
17536 Implicit_Base : Entity_Id;
17537 Base_Typ : Entity_Id;
17540 Errs : Boolean := False;
17544 function Can_Derive_From (E : Entity_Id) return Boolean;
17545 -- Determine whether given bounds allow derivation from specified type
17547 procedure Check_Bound (Expr : Node_Id);
17548 -- Check bound to make sure it is integral and static. If not, post
17549 -- appropriate error message and set Errs flag
17551 ---------------------
17552 -- Can_Derive_From --
17553 ---------------------
17555 -- Note we check both bounds against both end values, to deal with
17556 -- strange types like ones with a range of 0 .. -12341234.
17558 function Can_Derive_From (E : Entity_Id) return Boolean is
17559 Lo : constant Uint := Expr_Value (Type_Low_Bound (E));
17560 Hi : constant Uint := Expr_Value (Type_High_Bound (E));
17562 return Lo <= Lo_Val and then Lo_Val <= Hi
17564 Lo <= Hi_Val and then Hi_Val <= Hi;
17565 end Can_Derive_From;
17571 procedure Check_Bound (Expr : Node_Id) is
17573 -- If a range constraint is used as an integer type definition, each
17574 -- bound of the range must be defined by a static expression of some
17575 -- integer type, but the two bounds need not have the same integer
17576 -- type (Negative bounds are allowed.) (RM 3.5.4)
17578 if not Is_Integer_Type (Etype (Expr)) then
17580 ("integer type definition bounds must be of integer type", Expr);
17583 elsif not Is_OK_Static_Expression (Expr) then
17584 Flag_Non_Static_Expr
17585 ("non-static expression used for integer type bound!", Expr);
17588 -- The bounds are folded into literals, and we set their type to be
17589 -- universal, to avoid typing difficulties: we cannot set the type
17590 -- of the literal to the new type, because this would be a forward
17591 -- reference for the back end, and if the original type is user-
17592 -- defined this can lead to spurious semantic errors (e.g. 2928-003).
17595 if Is_Entity_Name (Expr) then
17596 Fold_Uint (Expr, Expr_Value (Expr), True);
17599 Set_Etype (Expr, Universal_Integer);
17603 -- Start of processing for Signed_Integer_Type_Declaration
17606 -- Create an anonymous base type
17609 Create_Itype (E_Signed_Integer_Type, Parent (Def), T, 'B');
17611 -- Analyze and check the bounds, they can be of any integer type
17613 Lo := Low_Bound (Def);
17614 Hi := High_Bound (Def);
17616 -- Arbitrarily use Integer as the type if either bound had an error
17618 if Hi = Error or else Lo = Error then
17619 Base_Typ := Any_Integer;
17620 Set_Error_Posted (T, True);
17622 -- Here both bounds are OK expressions
17625 Analyze_And_Resolve (Lo, Any_Integer);
17626 Analyze_And_Resolve (Hi, Any_Integer);
17632 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17633 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17636 -- Find type to derive from
17638 Lo_Val := Expr_Value (Lo);
17639 Hi_Val := Expr_Value (Hi);
17641 if Can_Derive_From (Standard_Short_Short_Integer) then
17642 Base_Typ := Base_Type (Standard_Short_Short_Integer);
17644 elsif Can_Derive_From (Standard_Short_Integer) then
17645 Base_Typ := Base_Type (Standard_Short_Integer);
17647 elsif Can_Derive_From (Standard_Integer) then
17648 Base_Typ := Base_Type (Standard_Integer);
17650 elsif Can_Derive_From (Standard_Long_Integer) then
17651 Base_Typ := Base_Type (Standard_Long_Integer);
17653 elsif Can_Derive_From (Standard_Long_Long_Integer) then
17654 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17657 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17658 Error_Msg_N ("integer type definition bounds out of range", Def);
17659 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17660 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17664 -- Complete both implicit base and declared first subtype entities
17666 Set_Etype (Implicit_Base, Base_Typ);
17667 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
17668 Set_Size_Info (Implicit_Base, (Base_Typ));
17669 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
17670 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
17672 Set_Ekind (T, E_Signed_Integer_Subtype);
17673 Set_Etype (T, Implicit_Base);
17675 Set_Size_Info (T, (Implicit_Base));
17676 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
17677 Set_Scalar_Range (T, Def);
17678 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
17679 Set_Is_Constrained (T);
17680 end Signed_Integer_Type_Declaration;