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 in the scope enclosing the subprogram.
770 if Ekind (Current_Scope) = E_Protected_Type then
771 Anon_Scope := Scope (Scope (Defining_Entity (Related_Nod)));
773 Anon_Scope := Scope (Defining_Entity (Related_Nod));
777 -- For access formals, access components, and access discriminants,
778 -- the scope is that of the enclosing declaration,
780 Anon_Scope := Scope (Current_Scope);
785 (E_Anonymous_Access_Type, Related_Nod, Scope_Id => Anon_Scope);
788 and then Ada_Version >= Ada_05
790 Error_Msg_N ("ALL is not permitted for anonymous access types", N);
793 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
794 -- the corresponding semantic routine
796 if Present (Access_To_Subprogram_Definition (N)) then
797 Access_Subprogram_Declaration
798 (T_Name => Anon_Type,
799 T_Def => Access_To_Subprogram_Definition (N));
801 if Ekind (Anon_Type) = E_Access_Protected_Subprogram_Type then
803 (Anon_Type, E_Anonymous_Access_Protected_Subprogram_Type);
806 (Anon_Type, E_Anonymous_Access_Subprogram_Type);
809 Set_Can_Use_Internal_Rep
810 (Anon_Type, not Always_Compatible_Rep_On_Target);
812 -- If the anonymous access is associated with a protected operation
813 -- create a reference to it after the enclosing protected definition
814 -- because the itype will be used in the subsequent bodies.
816 if Ekind (Current_Scope) = E_Protected_Type then
817 Build_Itype_Reference (Anon_Type, Parent (Current_Scope));
823 Find_Type (Subtype_Mark (N));
824 Desig_Type := Entity (Subtype_Mark (N));
826 Set_Directly_Designated_Type
827 (Anon_Type, Desig_Type);
828 Set_Etype (Anon_Type, Anon_Type);
830 -- Make sure the anonymous access type has size and alignment fields
831 -- set, as required by gigi. This is necessary in the case of the
832 -- Task_Body_Procedure.
834 if not Has_Private_Component (Desig_Type) then
835 Layout_Type (Anon_Type);
838 -- ???The following makes no sense, because Anon_Type is an access type
839 -- and therefore cannot have components, private or otherwise. Hence
840 -- the assertion. Not sure what was meant, here.
841 Set_Depends_On_Private (Anon_Type, Has_Private_Component (Anon_Type));
842 pragma Assert (not Depends_On_Private (Anon_Type));
844 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
845 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
846 -- the null value is allowed. In Ada 95 the null value is never allowed.
848 if Ada_Version >= Ada_05 then
849 Set_Can_Never_Be_Null (Anon_Type, Null_Exclusion_Present (N));
851 Set_Can_Never_Be_Null (Anon_Type, True);
854 -- The anonymous access type is as public as the discriminated type or
855 -- subprogram that defines it. It is imported (for back-end purposes)
856 -- if the designated type is.
858 Set_Is_Public (Anon_Type, Is_Public (Scope (Anon_Type)));
860 -- Ada 2005 (AI-50217): Propagate the attribute that indicates that the
861 -- designated type comes from the limited view.
863 Set_From_With_Type (Anon_Type, From_With_Type (Desig_Type));
865 -- Ada 2005 (AI-231): Propagate the access-constant attribute
867 Set_Is_Access_Constant (Anon_Type, Constant_Present (N));
869 -- The context is either a subprogram declaration, object declaration,
870 -- or an access discriminant, in a private or a full type declaration.
871 -- In the case of a subprogram, if the designated type is incomplete,
872 -- the operation will be a primitive operation of the full type, to be
873 -- updated subsequently. If the type is imported through a limited_with
874 -- clause, the subprogram is not a primitive operation of the type
875 -- (which is declared elsewhere in some other scope).
877 if Ekind (Desig_Type) = E_Incomplete_Type
878 and then not From_With_Type (Desig_Type)
879 and then Is_Overloadable (Current_Scope)
881 Append_Elmt (Current_Scope, Private_Dependents (Desig_Type));
882 Set_Has_Delayed_Freeze (Current_Scope);
885 -- Ada 2005: if the designated type is an interface that may contain
886 -- tasks, create a Master entity for the declaration. This must be done
887 -- before expansion of the full declaration, because the declaration may
888 -- include an expression that is an allocator, whose expansion needs the
889 -- proper Master for the created tasks.
891 if Nkind (Related_Nod) = N_Object_Declaration
892 and then Expander_Active
894 if Is_Interface (Desig_Type)
895 and then Is_Limited_Record (Desig_Type)
897 Build_Class_Wide_Master (Anon_Type);
899 -- Similarly, if the type is an anonymous access that designates
900 -- tasks, create a master entity for it in the current context.
902 elsif Has_Task (Desig_Type)
903 and then Comes_From_Source (Related_Nod)
905 if not Has_Master_Entity (Current_Scope) then
907 Make_Object_Declaration (Loc,
908 Defining_Identifier =>
909 Make_Defining_Identifier (Loc, Name_uMaster),
910 Constant_Present => True,
912 New_Reference_To (RTE (RE_Master_Id), Loc),
914 Make_Explicit_Dereference (Loc,
915 New_Reference_To (RTE (RE_Current_Master), Loc)));
917 Insert_Before (Related_Nod, Decl);
920 Set_Master_Id (Anon_Type, Defining_Identifier (Decl));
921 Set_Has_Master_Entity (Current_Scope);
923 Build_Master_Renaming (Related_Nod, Anon_Type);
928 -- For a private component of a protected type, it is imperative that
929 -- the back-end elaborate the type immediately after the protected
930 -- declaration, because this type will be used in the declarations
931 -- created for the component within each protected body, so we must
932 -- create an itype reference for it now.
934 if Nkind (Parent (Related_Nod)) = N_Protected_Definition then
935 Build_Itype_Reference (Anon_Type, Parent (Parent (Related_Nod)));
937 -- Similarly, if the access definition is the return result of a
938 -- function, create an itype reference for it because it
939 -- will be used within the function body. For a regular function that
940 -- is not a compilation unit, insert reference after the declaration.
941 -- For a protected operation, insert it after the enclosing protected
942 -- type declaration. In either case, do not create a reference for a
943 -- type obtained through a limited_with clause, because this would
944 -- introduce semantic dependencies.
946 elsif Nkind (Related_Nod) = N_Function_Specification
947 and then not From_With_Type (Anon_Type)
949 if Ekind (Current_Scope) = E_Protected_Type then
950 Build_Itype_Reference (Anon_Type, Parent (Current_Scope));
952 elsif Is_List_Member (Parent (Related_Nod))
953 and then Nkind (Parent (N)) /= N_Parameter_Specification
955 Build_Itype_Reference (Anon_Type, Parent (Related_Nod));
958 -- Finally, create an itype reference for an object declaration of
959 -- an anonymous access type. This is strictly necessary only for
960 -- deferred constants, but in any case will avoid out-of-scope
961 -- problems in the back-end.
963 elsif Nkind (Related_Nod) = N_Object_Declaration then
964 Build_Itype_Reference (Anon_Type, Related_Nod);
968 end Access_Definition;
970 -----------------------------------
971 -- Access_Subprogram_Declaration --
972 -----------------------------------
974 procedure Access_Subprogram_Declaration
979 procedure Check_For_Premature_Usage (Def : Node_Id);
980 -- Check that type T_Name is not used, directly or recursively,
981 -- as a parameter or a return type in Def. Def is either a subtype,
982 -- an access_definition, or an access_to_subprogram_definition.
984 -------------------------------
985 -- Check_For_Premature_Usage --
986 -------------------------------
988 procedure Check_For_Premature_Usage (Def : Node_Id) is
992 -- Check for a subtype mark
994 if Nkind (Def) in N_Has_Etype then
995 if Etype (Def) = T_Name then
997 ("type& cannot be used before end of its declaration", Def);
1000 -- If this is not a subtype, then this is an access_definition
1002 elsif Nkind (Def) = N_Access_Definition then
1003 if Present (Access_To_Subprogram_Definition (Def)) then
1004 Check_For_Premature_Usage
1005 (Access_To_Subprogram_Definition (Def));
1007 Check_For_Premature_Usage (Subtype_Mark (Def));
1010 -- The only cases left are N_Access_Function_Definition and
1011 -- N_Access_Procedure_Definition.
1014 if Present (Parameter_Specifications (Def)) then
1015 Param := First (Parameter_Specifications (Def));
1016 while Present (Param) loop
1017 Check_For_Premature_Usage (Parameter_Type (Param));
1018 Param := Next (Param);
1022 if Nkind (Def) = N_Access_Function_Definition then
1023 Check_For_Premature_Usage (Result_Definition (Def));
1026 end Check_For_Premature_Usage;
1030 Formals : constant List_Id := Parameter_Specifications (T_Def);
1033 Desig_Type : constant Entity_Id :=
1034 Create_Itype (E_Subprogram_Type, Parent (T_Def));
1036 -- Start of processing for Access_Subprogram_Declaration
1039 -- Associate the Itype node with the inner full-type declaration or
1040 -- subprogram spec. This is required to handle nested anonymous
1041 -- declarations. For example:
1044 -- (X : access procedure
1045 -- (Y : access procedure
1048 D_Ityp := Associated_Node_For_Itype (Desig_Type);
1049 while not (Nkind_In (D_Ityp, N_Full_Type_Declaration,
1050 N_Private_Type_Declaration,
1051 N_Private_Extension_Declaration,
1052 N_Procedure_Specification,
1053 N_Function_Specification)
1055 Nkind_In (D_Ityp, N_Object_Declaration,
1056 N_Object_Renaming_Declaration,
1057 N_Formal_Object_Declaration,
1058 N_Formal_Type_Declaration,
1059 N_Task_Type_Declaration,
1060 N_Protected_Type_Declaration))
1062 D_Ityp := Parent (D_Ityp);
1063 pragma Assert (D_Ityp /= Empty);
1066 Set_Associated_Node_For_Itype (Desig_Type, D_Ityp);
1068 if Nkind_In (D_Ityp, N_Procedure_Specification,
1069 N_Function_Specification)
1071 Set_Scope (Desig_Type, Scope (Defining_Entity (D_Ityp)));
1073 elsif Nkind_In (D_Ityp, N_Full_Type_Declaration,
1074 N_Object_Declaration,
1075 N_Object_Renaming_Declaration,
1076 N_Formal_Type_Declaration)
1078 Set_Scope (Desig_Type, Scope (Defining_Identifier (D_Ityp)));
1081 if Nkind (T_Def) = N_Access_Function_Definition then
1082 if Nkind (Result_Definition (T_Def)) = N_Access_Definition then
1084 Acc : constant Node_Id := Result_Definition (T_Def);
1087 if Present (Access_To_Subprogram_Definition (Acc))
1089 Protected_Present (Access_To_Subprogram_Definition (Acc))
1093 Replace_Anonymous_Access_To_Protected_Subprogram
1099 Access_Definition (T_Def, Result_Definition (T_Def)));
1104 Analyze (Result_Definition (T_Def));
1105 Set_Etype (Desig_Type, Entity (Result_Definition (T_Def)));
1108 if not (Is_Type (Etype (Desig_Type))) then
1110 ("expect type in function specification",
1111 Result_Definition (T_Def));
1115 Set_Etype (Desig_Type, Standard_Void_Type);
1118 if Present (Formals) then
1119 Push_Scope (Desig_Type);
1121 -- A bit of a kludge here. These kludges will be removed when Itypes
1122 -- have proper parent pointers to their declarations???
1124 -- Kludge 1) Link defining_identifier of formals. Required by
1125 -- First_Formal to provide its functionality.
1131 F := First (Formals);
1132 while Present (F) loop
1133 if No (Parent (Defining_Identifier (F))) then
1134 Set_Parent (Defining_Identifier (F), F);
1141 Process_Formals (Formals, Parent (T_Def));
1143 -- Kludge 2) End_Scope requires that the parent pointer be set to
1144 -- something reasonable, but Itypes don't have parent pointers. So
1145 -- we set it and then unset it ???
1147 Set_Parent (Desig_Type, T_Name);
1149 Set_Parent (Desig_Type, Empty);
1152 -- Check for premature usage of the type being defined
1154 Check_For_Premature_Usage (T_Def);
1156 -- The return type and/or any parameter type may be incomplete. Mark
1157 -- the subprogram_type as depending on the incomplete type, so that
1158 -- it can be updated when the full type declaration is seen. This
1159 -- only applies to incomplete types declared in some enclosing scope,
1160 -- not to limited views from other packages.
1162 if Present (Formals) then
1163 Formal := First_Formal (Desig_Type);
1164 while Present (Formal) loop
1165 if Ekind (Formal) /= E_In_Parameter
1166 and then Nkind (T_Def) = N_Access_Function_Definition
1168 Error_Msg_N ("functions can only have IN parameters", Formal);
1171 if Ekind (Etype (Formal)) = E_Incomplete_Type
1172 and then In_Open_Scopes (Scope (Etype (Formal)))
1174 Append_Elmt (Desig_Type, Private_Dependents (Etype (Formal)));
1175 Set_Has_Delayed_Freeze (Desig_Type);
1178 Next_Formal (Formal);
1182 -- If the return type is incomplete, this is legal as long as the
1183 -- type is declared in the current scope and will be completed in
1184 -- it (rather than being part of limited view).
1186 if Ekind (Etype (Desig_Type)) = E_Incomplete_Type
1187 and then not Has_Delayed_Freeze (Desig_Type)
1188 and then In_Open_Scopes (Scope (Etype (Desig_Type)))
1190 Append_Elmt (Desig_Type, Private_Dependents (Etype (Desig_Type)));
1191 Set_Has_Delayed_Freeze (Desig_Type);
1194 Check_Delayed_Subprogram (Desig_Type);
1196 if Protected_Present (T_Def) then
1197 Set_Ekind (T_Name, E_Access_Protected_Subprogram_Type);
1198 Set_Convention (Desig_Type, Convention_Protected);
1200 Set_Ekind (T_Name, E_Access_Subprogram_Type);
1203 Set_Can_Use_Internal_Rep (T_Name, not Always_Compatible_Rep_On_Target);
1205 Set_Etype (T_Name, T_Name);
1206 Init_Size_Align (T_Name);
1207 Set_Directly_Designated_Type (T_Name, Desig_Type);
1209 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1211 Set_Can_Never_Be_Null (T_Name, Null_Exclusion_Present (T_Def));
1213 Check_Restriction (No_Access_Subprograms, T_Def);
1214 end Access_Subprogram_Declaration;
1216 ----------------------------
1217 -- Access_Type_Declaration --
1218 ----------------------------
1220 procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id) is
1221 S : constant Node_Id := Subtype_Indication (Def);
1222 P : constant Node_Id := Parent (Def);
1228 -- Check for permissible use of incomplete type
1230 if Nkind (S) /= N_Subtype_Indication then
1233 if Ekind (Root_Type (Entity (S))) = E_Incomplete_Type then
1234 Set_Directly_Designated_Type (T, Entity (S));
1236 Set_Directly_Designated_Type (T,
1237 Process_Subtype (S, P, T, 'P'));
1241 Set_Directly_Designated_Type (T,
1242 Process_Subtype (S, P, T, 'P'));
1245 if All_Present (Def) or Constant_Present (Def) then
1246 Set_Ekind (T, E_General_Access_Type);
1248 Set_Ekind (T, E_Access_Type);
1251 if Base_Type (Designated_Type (T)) = T then
1252 Error_Msg_N ("access type cannot designate itself", S);
1254 -- In Ada 2005, the type may have a limited view through some unit
1255 -- in its own context, allowing the following circularity that cannot
1256 -- be detected earlier
1258 elsif Is_Class_Wide_Type (Designated_Type (T))
1259 and then Etype (Designated_Type (T)) = T
1262 ("access type cannot designate its own classwide type", S);
1264 -- Clean up indication of tagged status to prevent cascaded errors
1266 Set_Is_Tagged_Type (T, False);
1271 -- If the type has appeared already in a with_type clause, it is
1272 -- frozen and the pointer size is already set. Else, initialize.
1274 if not From_With_Type (T) then
1275 Init_Size_Align (T);
1278 Desig := Designated_Type (T);
1280 -- If designated type is an imported tagged type, indicate that the
1281 -- access type is also imported, and therefore restricted in its use.
1282 -- The access type may already be imported, so keep setting otherwise.
1284 -- Ada 2005 (AI-50217): If the non-limited view of the designated type
1285 -- is available, use it as the designated type of the access type, so
1286 -- that the back-end gets a usable entity.
1288 if From_With_Type (Desig)
1289 and then Ekind (Desig) /= E_Access_Type
1291 Set_From_With_Type (T);
1294 -- Note that Has_Task is always false, since the access type itself
1295 -- is not a task type. See Einfo for more description on this point.
1296 -- Exactly the same consideration applies to Has_Controlled_Component.
1298 Set_Has_Task (T, False);
1299 Set_Has_Controlled_Component (T, False);
1301 -- Initialize Associated_Final_Chain explicitly to Empty, to avoid
1302 -- problems where an incomplete view of this entity has been previously
1303 -- established by a limited with and an overlaid version of this field
1304 -- (Stored_Constraint) was initialized for the incomplete view.
1306 Set_Associated_Final_Chain (T, Empty);
1308 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1311 Set_Can_Never_Be_Null (T, Null_Exclusion_Present (Def));
1312 Set_Is_Access_Constant (T, Constant_Present (Def));
1313 end Access_Type_Declaration;
1315 ----------------------------------
1316 -- Add_Interface_Tag_Components --
1317 ----------------------------------
1319 procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id) is
1320 Loc : constant Source_Ptr := Sloc (N);
1324 procedure Add_Tag (Iface : Entity_Id);
1325 -- Add tag for one of the progenitor interfaces
1331 procedure Add_Tag (Iface : Entity_Id) is
1338 pragma Assert (Is_Tagged_Type (Iface)
1339 and then Is_Interface (Iface));
1342 Make_Component_Definition (Loc,
1343 Aliased_Present => True,
1344 Subtype_Indication =>
1345 New_Occurrence_Of (RTE (RE_Interface_Tag), Loc));
1347 Tag := Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1350 Make_Component_Declaration (Loc,
1351 Defining_Identifier => Tag,
1352 Component_Definition => Def);
1354 Analyze_Component_Declaration (Decl);
1356 Set_Analyzed (Decl);
1357 Set_Ekind (Tag, E_Component);
1359 Set_Is_Aliased (Tag);
1360 Set_Related_Type (Tag, Iface);
1361 Init_Component_Location (Tag);
1363 pragma Assert (Is_Frozen (Iface));
1365 Set_DT_Entry_Count (Tag,
1366 DT_Entry_Count (First_Entity (Iface)));
1368 if No (Last_Tag) then
1371 Insert_After (Last_Tag, Decl);
1376 -- If the ancestor has discriminants we need to give special support
1377 -- to store the offset_to_top value of the secondary dispatch tables.
1378 -- For this purpose we add a supplementary component just after the
1379 -- field that contains the tag associated with each secondary DT.
1381 if Typ /= Etype (Typ)
1382 and then Has_Discriminants (Etype (Typ))
1385 Make_Component_Definition (Loc,
1386 Subtype_Indication =>
1387 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc));
1390 Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1393 Make_Component_Declaration (Loc,
1394 Defining_Identifier => Offset,
1395 Component_Definition => Def);
1397 Analyze_Component_Declaration (Decl);
1399 Set_Analyzed (Decl);
1400 Set_Ekind (Offset, E_Component);
1401 Set_Is_Aliased (Offset);
1402 Set_Related_Type (Offset, Iface);
1403 Init_Component_Location (Offset);
1404 Insert_After (Last_Tag, Decl);
1415 -- Start of processing for Add_Interface_Tag_Components
1418 if not RTE_Available (RE_Interface_Tag) then
1420 ("(Ada 2005) interface types not supported by this run-time!",
1425 if Ekind (Typ) /= E_Record_Type
1426 or else (Is_Concurrent_Record_Type (Typ)
1427 and then Is_Empty_List (Abstract_Interface_List (Typ)))
1428 or else (not Is_Concurrent_Record_Type (Typ)
1429 and then No (Interfaces (Typ))
1430 and then Is_Empty_Elmt_List (Interfaces (Typ)))
1435 -- Find the current last tag
1437 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1438 Ext := Record_Extension_Part (Type_Definition (N));
1440 pragma Assert (Nkind (Type_Definition (N)) = N_Record_Definition);
1441 Ext := Type_Definition (N);
1446 if not (Present (Component_List (Ext))) then
1447 Set_Null_Present (Ext, False);
1449 Set_Component_List (Ext,
1450 Make_Component_List (Loc,
1451 Component_Items => L,
1452 Null_Present => False));
1454 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1455 L := Component_Items
1457 (Record_Extension_Part
1458 (Type_Definition (N))));
1460 L := Component_Items
1462 (Type_Definition (N)));
1465 -- Find the last tag component
1468 while Present (Comp) loop
1469 if Nkind (Comp) = N_Component_Declaration
1470 and then Is_Tag (Defining_Identifier (Comp))
1479 -- At this point L references the list of components and Last_Tag
1480 -- references the current last tag (if any). Now we add the tag
1481 -- corresponding with all the interfaces that are not implemented
1484 if Present (Interfaces (Typ)) then
1485 Elmt := First_Elmt (Interfaces (Typ));
1486 while Present (Elmt) loop
1487 Add_Tag (Node (Elmt));
1491 end Add_Interface_Tag_Components;
1493 -----------------------------------
1494 -- Analyze_Component_Declaration --
1495 -----------------------------------
1497 procedure Analyze_Component_Declaration (N : Node_Id) is
1498 Id : constant Entity_Id := Defining_Identifier (N);
1499 E : constant Node_Id := Expression (N);
1503 function Contains_POC (Constr : Node_Id) return Boolean;
1504 -- Determines whether a constraint uses the discriminant of a record
1505 -- type thus becoming a per-object constraint (POC).
1507 function Is_Known_Limited (Typ : Entity_Id) return Boolean;
1508 -- Typ is the type of the current component, check whether this type is
1509 -- a limited type. Used to validate declaration against that of
1510 -- enclosing record.
1516 function Contains_POC (Constr : Node_Id) return Boolean is
1518 -- Prevent cascaded errors
1520 if Error_Posted (Constr) then
1524 case Nkind (Constr) is
1525 when N_Attribute_Reference =>
1527 Attribute_Name (Constr) = Name_Access
1528 and then Prefix (Constr) = Scope (Entity (Prefix (Constr)));
1530 when N_Discriminant_Association =>
1531 return Denotes_Discriminant (Expression (Constr));
1533 when N_Identifier =>
1534 return Denotes_Discriminant (Constr);
1536 when N_Index_Or_Discriminant_Constraint =>
1541 IDC := First (Constraints (Constr));
1542 while Present (IDC) loop
1544 -- One per-object constraint is sufficient
1546 if Contains_POC (IDC) then
1557 return Denotes_Discriminant (Low_Bound (Constr))
1559 Denotes_Discriminant (High_Bound (Constr));
1561 when N_Range_Constraint =>
1562 return Denotes_Discriminant (Range_Expression (Constr));
1570 ----------------------
1571 -- Is_Known_Limited --
1572 ----------------------
1574 function Is_Known_Limited (Typ : Entity_Id) return Boolean is
1575 P : constant Entity_Id := Etype (Typ);
1576 R : constant Entity_Id := Root_Type (Typ);
1579 if Is_Limited_Record (Typ) then
1582 -- If the root type is limited (and not a limited interface)
1583 -- so is the current type
1585 elsif Is_Limited_Record (R)
1587 (not Is_Interface (R)
1588 or else not Is_Limited_Interface (R))
1592 -- Else the type may have a limited interface progenitor, but a
1593 -- limited record parent.
1596 and then Is_Limited_Record (P)
1603 end Is_Known_Limited;
1605 -- Start of processing for Analyze_Component_Declaration
1608 Generate_Definition (Id);
1611 if Present (Subtype_Indication (Component_Definition (N))) then
1612 T := Find_Type_Of_Object
1613 (Subtype_Indication (Component_Definition (N)), N);
1615 -- Ada 2005 (AI-230): Access Definition case
1618 pragma Assert (Present
1619 (Access_Definition (Component_Definition (N))));
1621 T := Access_Definition
1623 N => Access_Definition (Component_Definition (N)));
1624 Set_Is_Local_Anonymous_Access (T);
1626 -- Ada 2005 (AI-254)
1628 if Present (Access_To_Subprogram_Definition
1629 (Access_Definition (Component_Definition (N))))
1630 and then Protected_Present (Access_To_Subprogram_Definition
1632 (Component_Definition (N))))
1634 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
1638 -- If the subtype is a constrained subtype of the enclosing record,
1639 -- (which must have a partial view) the back-end does not properly
1640 -- handle the recursion. Rewrite the component declaration with an
1641 -- explicit subtype indication, which is acceptable to Gigi. We can copy
1642 -- the tree directly because side effects have already been removed from
1643 -- discriminant constraints.
1645 if Ekind (T) = E_Access_Subtype
1646 and then Is_Entity_Name (Subtype_Indication (Component_Definition (N)))
1647 and then Comes_From_Source (T)
1648 and then Nkind (Parent (T)) = N_Subtype_Declaration
1649 and then Etype (Directly_Designated_Type (T)) = Current_Scope
1652 (Subtype_Indication (Component_Definition (N)),
1653 New_Copy_Tree (Subtype_Indication (Parent (T))));
1654 T := Find_Type_Of_Object
1655 (Subtype_Indication (Component_Definition (N)), N);
1658 -- If the component declaration includes a default expression, then we
1659 -- check that the component is not of a limited type (RM 3.7(5)),
1660 -- and do the special preanalysis of the expression (see section on
1661 -- "Handling of Default and Per-Object Expressions" in the spec of
1665 Preanalyze_Spec_Expression (E, T);
1666 Check_Initialization (T, E);
1668 if Ada_Version >= Ada_05
1669 and then Ekind (T) = E_Anonymous_Access_Type
1670 and then Etype (E) /= Any_Type
1672 -- Check RM 3.9.2(9): "if the expected type for an expression is
1673 -- an anonymous access-to-specific tagged type, then the object
1674 -- designated by the expression shall not be dynamically tagged
1675 -- unless it is a controlling operand in a call on a dispatching
1678 if Is_Tagged_Type (Directly_Designated_Type (T))
1680 Ekind (Directly_Designated_Type (T)) /= E_Class_Wide_Type
1682 Ekind (Directly_Designated_Type (Etype (E))) =
1686 ("access to specific tagged type required (RM 3.9.2(9))", E);
1689 -- (Ada 2005: AI-230): Accessibility check for anonymous
1692 if Type_Access_Level (Etype (E)) > Type_Access_Level (T) then
1694 ("expression has deeper access level than component " &
1695 "(RM 3.10.2 (12.2))", E);
1698 -- The initialization expression is a reference to an access
1699 -- discriminant. The type of the discriminant is always deeper
1700 -- than any access type.
1702 if Ekind (Etype (E)) = E_Anonymous_Access_Type
1703 and then Is_Entity_Name (E)
1704 and then Ekind (Entity (E)) = E_In_Parameter
1705 and then Present (Discriminal_Link (Entity (E)))
1708 ("discriminant has deeper accessibility level than target",
1714 -- The parent type may be a private view with unknown discriminants,
1715 -- and thus unconstrained. Regular components must be constrained.
1717 if Is_Indefinite_Subtype (T) and then Chars (Id) /= Name_uParent then
1718 if Is_Class_Wide_Type (T) then
1720 ("class-wide subtype with unknown discriminants" &
1721 " in component declaration",
1722 Subtype_Indication (Component_Definition (N)));
1725 ("unconstrained subtype in component declaration",
1726 Subtype_Indication (Component_Definition (N)));
1729 -- Components cannot be abstract, except for the special case of
1730 -- the _Parent field (case of extending an abstract tagged type)
1732 elsif Is_Abstract_Type (T) and then Chars (Id) /= Name_uParent then
1733 Error_Msg_N ("type of a component cannot be abstract", N);
1737 Set_Is_Aliased (Id, Aliased_Present (Component_Definition (N)));
1739 -- The component declaration may have a per-object constraint, set
1740 -- the appropriate flag in the defining identifier of the subtype.
1742 if Present (Subtype_Indication (Component_Definition (N))) then
1744 Sindic : constant Node_Id :=
1745 Subtype_Indication (Component_Definition (N));
1747 if Nkind (Sindic) = N_Subtype_Indication
1748 and then Present (Constraint (Sindic))
1749 and then Contains_POC (Constraint (Sindic))
1751 Set_Has_Per_Object_Constraint (Id);
1756 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
1757 -- out some static checks.
1759 if Ada_Version >= Ada_05
1760 and then Can_Never_Be_Null (T)
1762 Null_Exclusion_Static_Checks (N);
1765 -- If this component is private (or depends on a private type), flag the
1766 -- record type to indicate that some operations are not available.
1768 P := Private_Component (T);
1772 -- Check for circular definitions
1774 if P = Any_Type then
1775 Set_Etype (Id, Any_Type);
1777 -- There is a gap in the visibility of operations only if the
1778 -- component type is not defined in the scope of the record type.
1780 elsif Scope (P) = Scope (Current_Scope) then
1783 elsif Is_Limited_Type (P) then
1784 Set_Is_Limited_Composite (Current_Scope);
1787 Set_Is_Private_Composite (Current_Scope);
1792 and then Is_Limited_Type (T)
1793 and then Chars (Id) /= Name_uParent
1794 and then Is_Tagged_Type (Current_Scope)
1796 if Is_Derived_Type (Current_Scope)
1797 and then not Is_Known_Limited (Current_Scope)
1800 ("extension of nonlimited type cannot have limited components",
1803 if Is_Interface (Root_Type (Current_Scope)) then
1805 ("\limitedness is not inherited from limited interface", N);
1807 ("\add LIMITED to type indication", N);
1810 Explain_Limited_Type (T, N);
1811 Set_Etype (Id, Any_Type);
1812 Set_Is_Limited_Composite (Current_Scope, False);
1814 elsif not Is_Derived_Type (Current_Scope)
1815 and then not Is_Limited_Record (Current_Scope)
1816 and then not Is_Concurrent_Type (Current_Scope)
1819 ("nonlimited tagged type cannot have limited components", N);
1820 Explain_Limited_Type (T, N);
1821 Set_Etype (Id, Any_Type);
1822 Set_Is_Limited_Composite (Current_Scope, False);
1826 Set_Original_Record_Component (Id, Id);
1827 end Analyze_Component_Declaration;
1829 --------------------------
1830 -- Analyze_Declarations --
1831 --------------------------
1833 procedure Analyze_Declarations (L : List_Id) is
1835 Freeze_From : Entity_Id := Empty;
1836 Next_Node : Node_Id;
1839 -- Adjust D not to include implicit label declarations, since these
1840 -- have strange Sloc values that result in elaboration check problems.
1841 -- (They have the sloc of the label as found in the source, and that
1842 -- is ahead of the current declarative part).
1848 procedure Adjust_D is
1850 while Present (Prev (D))
1851 and then Nkind (D) = N_Implicit_Label_Declaration
1857 -- Start of processing for Analyze_Declarations
1861 while Present (D) loop
1863 -- Complete analysis of declaration
1866 Next_Node := Next (D);
1868 if No (Freeze_From) then
1869 Freeze_From := First_Entity (Current_Scope);
1872 -- At the end of a declarative part, freeze remaining entities
1873 -- declared in it. The end of the visible declarations of package
1874 -- specification is not the end of a declarative part if private
1875 -- declarations are present. The end of a package declaration is a
1876 -- freezing point only if it a library package. A task definition or
1877 -- protected type definition is not a freeze point either. Finally,
1878 -- we do not freeze entities in generic scopes, because there is no
1879 -- code generated for them and freeze nodes will be generated for
1882 -- The end of a package instantiation is not a freeze point, but
1883 -- for now we make it one, because the generic body is inserted
1884 -- (currently) immediately after. Generic instantiations will not
1885 -- be a freeze point once delayed freezing of bodies is implemented.
1886 -- (This is needed in any case for early instantiations ???).
1888 if No (Next_Node) then
1889 if Nkind_In (Parent (L), N_Component_List,
1891 N_Protected_Definition)
1895 elsif Nkind (Parent (L)) /= N_Package_Specification then
1896 if Nkind (Parent (L)) = N_Package_Body then
1897 Freeze_From := First_Entity (Current_Scope);
1901 Freeze_All (Freeze_From, D);
1902 Freeze_From := Last_Entity (Current_Scope);
1904 elsif Scope (Current_Scope) /= Standard_Standard
1905 and then not Is_Child_Unit (Current_Scope)
1906 and then No (Generic_Parent (Parent (L)))
1910 elsif L /= Visible_Declarations (Parent (L))
1911 or else No (Private_Declarations (Parent (L)))
1912 or else Is_Empty_List (Private_Declarations (Parent (L)))
1915 Freeze_All (Freeze_From, D);
1916 Freeze_From := Last_Entity (Current_Scope);
1919 -- If next node is a body then freeze all types before the body.
1920 -- An exception occurs for some expander-generated bodies. If these
1921 -- are generated at places where in general language rules would not
1922 -- allow a freeze point, then we assume that the expander has
1923 -- explicitly checked that all required types are properly frozen,
1924 -- and we do not cause general freezing here. This special circuit
1925 -- is used when the encountered body is marked as having already
1928 -- In all other cases (bodies that come from source, and expander
1929 -- generated bodies that have not been analyzed yet), freeze all
1930 -- types now. Note that in the latter case, the expander must take
1931 -- care to attach the bodies at a proper place in the tree so as to
1932 -- not cause unwanted freezing at that point.
1934 elsif not Analyzed (Next_Node)
1935 and then (Nkind_In (Next_Node, N_Subprogram_Body,
1941 Nkind (Next_Node) in N_Body_Stub)
1944 Freeze_All (Freeze_From, D);
1945 Freeze_From := Last_Entity (Current_Scope);
1950 end Analyze_Declarations;
1952 ----------------------------------
1953 -- Analyze_Incomplete_Type_Decl --
1954 ----------------------------------
1956 procedure Analyze_Incomplete_Type_Decl (N : Node_Id) is
1957 F : constant Boolean := Is_Pure (Current_Scope);
1961 Generate_Definition (Defining_Identifier (N));
1963 -- Process an incomplete declaration. The identifier must not have been
1964 -- declared already in the scope. However, an incomplete declaration may
1965 -- appear in the private part of a package, for a private type that has
1966 -- already been declared.
1968 -- In this case, the discriminants (if any) must match
1970 T := Find_Type_Name (N);
1972 Set_Ekind (T, E_Incomplete_Type);
1973 Init_Size_Align (T);
1974 Set_Is_First_Subtype (T, True);
1977 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
1978 -- incomplete types.
1980 if Tagged_Present (N) then
1981 Set_Is_Tagged_Type (T);
1982 Make_Class_Wide_Type (T);
1983 Set_Primitive_Operations (T, New_Elmt_List);
1988 Set_Stored_Constraint (T, No_Elist);
1990 if Present (Discriminant_Specifications (N)) then
1991 Process_Discriminants (N);
1996 -- If the type has discriminants, non-trivial subtypes may be
1997 -- declared before the full view of the type. The full views of those
1998 -- subtypes will be built after the full view of the type.
2000 Set_Private_Dependents (T, New_Elmt_List);
2002 end Analyze_Incomplete_Type_Decl;
2004 -----------------------------------
2005 -- Analyze_Interface_Declaration --
2006 -----------------------------------
2008 procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id) is
2009 CW : constant Entity_Id := Class_Wide_Type (T);
2012 Set_Is_Tagged_Type (T);
2014 Set_Is_Limited_Record (T, Limited_Present (Def)
2015 or else Task_Present (Def)
2016 or else Protected_Present (Def)
2017 or else Synchronized_Present (Def));
2019 -- Type is abstract if full declaration carries keyword, or if previous
2020 -- partial view did.
2022 Set_Is_Abstract_Type (T);
2023 Set_Is_Interface (T);
2025 -- Type is a limited interface if it includes the keyword limited, task,
2026 -- protected, or synchronized.
2028 Set_Is_Limited_Interface
2029 (T, Limited_Present (Def)
2030 or else Protected_Present (Def)
2031 or else Synchronized_Present (Def)
2032 or else Task_Present (Def));
2034 Set_Is_Protected_Interface (T, Protected_Present (Def));
2035 Set_Is_Task_Interface (T, Task_Present (Def));
2037 -- Type is a synchronized interface if it includes the keyword task,
2038 -- protected, or synchronized.
2040 Set_Is_Synchronized_Interface
2041 (T, Synchronized_Present (Def)
2042 or else Protected_Present (Def)
2043 or else Task_Present (Def));
2045 Set_Interfaces (T, New_Elmt_List);
2046 Set_Primitive_Operations (T, New_Elmt_List);
2048 -- Complete the decoration of the class-wide entity if it was already
2049 -- built (i.e. during the creation of the limited view)
2051 if Present (CW) then
2052 Set_Is_Interface (CW);
2053 Set_Is_Limited_Interface (CW, Is_Limited_Interface (T));
2054 Set_Is_Protected_Interface (CW, Is_Protected_Interface (T));
2055 Set_Is_Synchronized_Interface (CW, Is_Synchronized_Interface (T));
2056 Set_Is_Task_Interface (CW, Is_Task_Interface (T));
2059 -- Check runtime support for synchronized interfaces
2061 if VM_Target = No_VM
2062 and then (Is_Task_Interface (T)
2063 or else Is_Protected_Interface (T)
2064 or else Is_Synchronized_Interface (T))
2065 and then not RTE_Available (RE_Select_Specific_Data)
2067 Error_Msg_CRT ("synchronized interfaces", T);
2069 end Analyze_Interface_Declaration;
2071 -----------------------------
2072 -- Analyze_Itype_Reference --
2073 -----------------------------
2075 -- Nothing to do. This node is placed in the tree only for the benefit of
2076 -- back end processing, and has no effect on the semantic processing.
2078 procedure Analyze_Itype_Reference (N : Node_Id) is
2080 pragma Assert (Is_Itype (Itype (N)));
2082 end Analyze_Itype_Reference;
2084 --------------------------------
2085 -- Analyze_Number_Declaration --
2086 --------------------------------
2088 procedure Analyze_Number_Declaration (N : Node_Id) is
2089 Id : constant Entity_Id := Defining_Identifier (N);
2090 E : constant Node_Id := Expression (N);
2092 Index : Interp_Index;
2096 Generate_Definition (Id);
2099 -- This is an optimization of a common case of an integer literal
2101 if Nkind (E) = N_Integer_Literal then
2102 Set_Is_Static_Expression (E, True);
2103 Set_Etype (E, Universal_Integer);
2105 Set_Etype (Id, Universal_Integer);
2106 Set_Ekind (Id, E_Named_Integer);
2107 Set_Is_Frozen (Id, True);
2111 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2113 -- Process expression, replacing error by integer zero, to avoid
2114 -- cascaded errors or aborts further along in the processing
2116 -- Replace Error by integer zero, which seems least likely to
2117 -- cause cascaded errors.
2120 Rewrite (E, Make_Integer_Literal (Sloc (E), Uint_0));
2121 Set_Error_Posted (E);
2126 -- Verify that the expression is static and numeric. If
2127 -- the expression is overloaded, we apply the preference
2128 -- rule that favors root numeric types.
2130 if not Is_Overloaded (E) then
2136 Get_First_Interp (E, Index, It);
2137 while Present (It.Typ) loop
2138 if (Is_Integer_Type (It.Typ)
2139 or else Is_Real_Type (It.Typ))
2140 and then (Scope (Base_Type (It.Typ))) = Standard_Standard
2142 if T = Any_Type then
2145 elsif It.Typ = Universal_Real
2146 or else It.Typ = Universal_Integer
2148 -- Choose universal interpretation over any other
2155 Get_Next_Interp (Index, It);
2159 if Is_Integer_Type (T) then
2161 Set_Etype (Id, Universal_Integer);
2162 Set_Ekind (Id, E_Named_Integer);
2164 elsif Is_Real_Type (T) then
2166 -- Because the real value is converted to universal_real, this is a
2167 -- legal context for a universal fixed expression.
2169 if T = Universal_Fixed then
2171 Loc : constant Source_Ptr := Sloc (N);
2172 Conv : constant Node_Id := Make_Type_Conversion (Loc,
2174 New_Occurrence_Of (Universal_Real, Loc),
2175 Expression => Relocate_Node (E));
2182 elsif T = Any_Fixed then
2183 Error_Msg_N ("illegal context for mixed mode operation", E);
2185 -- Expression is of the form : universal_fixed * integer. Try to
2186 -- resolve as universal_real.
2188 T := Universal_Real;
2193 Set_Etype (Id, Universal_Real);
2194 Set_Ekind (Id, E_Named_Real);
2197 Wrong_Type (E, Any_Numeric);
2201 Set_Ekind (Id, E_Constant);
2202 Set_Never_Set_In_Source (Id, True);
2203 Set_Is_True_Constant (Id, True);
2207 if Nkind_In (E, N_Integer_Literal, N_Real_Literal) then
2208 Set_Etype (E, Etype (Id));
2211 if not Is_OK_Static_Expression (E) then
2212 Flag_Non_Static_Expr
2213 ("non-static expression used in number declaration!", E);
2214 Rewrite (E, Make_Integer_Literal (Sloc (N), 1));
2215 Set_Etype (E, Any_Type);
2217 end Analyze_Number_Declaration;
2219 --------------------------------
2220 -- Analyze_Object_Declaration --
2221 --------------------------------
2223 procedure Analyze_Object_Declaration (N : Node_Id) is
2224 Loc : constant Source_Ptr := Sloc (N);
2225 Id : constant Entity_Id := Defining_Identifier (N);
2229 E : Node_Id := Expression (N);
2230 -- E is set to Expression (N) throughout this routine. When
2231 -- Expression (N) is modified, E is changed accordingly.
2233 Prev_Entity : Entity_Id := Empty;
2235 function Count_Tasks (T : Entity_Id) return Uint;
2236 -- This function is called when a non-generic library level object of a
2237 -- task type is declared. Its function is to count the static number of
2238 -- tasks declared within the type (it is only called if Has_Tasks is set
2239 -- for T). As a side effect, if an array of tasks with non-static bounds
2240 -- or a variant record type is encountered, Check_Restrictions is called
2241 -- indicating the count is unknown.
2247 function Count_Tasks (T : Entity_Id) return Uint is
2253 if Is_Task_Type (T) then
2256 elsif Is_Record_Type (T) then
2257 if Has_Discriminants (T) then
2258 Check_Restriction (Max_Tasks, N);
2263 C := First_Component (T);
2264 while Present (C) loop
2265 V := V + Count_Tasks (Etype (C));
2272 elsif Is_Array_Type (T) then
2273 X := First_Index (T);
2274 V := Count_Tasks (Component_Type (T));
2275 while Present (X) loop
2278 if not Is_Static_Subtype (C) then
2279 Check_Restriction (Max_Tasks, N);
2282 V := V * (UI_Max (Uint_0,
2283 Expr_Value (Type_High_Bound (C)) -
2284 Expr_Value (Type_Low_Bound (C)) + Uint_1));
2297 -- Start of processing for Analyze_Object_Declaration
2300 -- There are three kinds of implicit types generated by an
2301 -- object declaration:
2303 -- 1. Those for generated by the original Object Definition
2305 -- 2. Those generated by the Expression
2307 -- 3. Those used to constrained the Object Definition with the
2308 -- expression constraints when it is unconstrained
2310 -- They must be generated in this order to avoid order of elaboration
2311 -- issues. Thus the first step (after entering the name) is to analyze
2312 -- the object definition.
2314 if Constant_Present (N) then
2315 Prev_Entity := Current_Entity_In_Scope (Id);
2317 -- If the homograph is an implicit subprogram, it is overridden by
2318 -- the current declaration.
2320 if Present (Prev_Entity)
2322 ((Is_Overloadable (Prev_Entity)
2323 and then Is_Inherited_Operation (Prev_Entity))
2325 -- The current object is a discriminal generated for an entry
2326 -- family index. Even though the index is a constant, in this
2327 -- particular context there is no true constant redeclaration.
2328 -- Enter_Name will handle the visibility.
2331 (Is_Discriminal (Id)
2332 and then Ekind (Discriminal_Link (Id)) =
2333 E_Entry_Index_Parameter))
2335 Prev_Entity := Empty;
2339 if Present (Prev_Entity) then
2340 Constant_Redeclaration (Id, N, T);
2342 Generate_Reference (Prev_Entity, Id, 'c');
2343 Set_Completion_Referenced (Id);
2345 if Error_Posted (N) then
2347 -- Type mismatch or illegal redeclaration, Do not analyze
2348 -- expression to avoid cascaded errors.
2350 T := Find_Type_Of_Object (Object_Definition (N), N);
2352 Set_Ekind (Id, E_Variable);
2356 -- In the normal case, enter identifier at the start to catch premature
2357 -- usage in the initialization expression.
2360 Generate_Definition (Id);
2363 Mark_Coextensions (N, Object_Definition (N));
2365 T := Find_Type_Of_Object (Object_Definition (N), N);
2367 if Nkind (Object_Definition (N)) = N_Access_Definition
2369 (Access_To_Subprogram_Definition (Object_Definition (N)))
2370 and then Protected_Present
2371 (Access_To_Subprogram_Definition (Object_Definition (N)))
2373 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
2376 if Error_Posted (Id) then
2378 Set_Ekind (Id, E_Variable);
2383 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2384 -- out some static checks
2386 if Ada_Version >= Ada_05
2387 and then Can_Never_Be_Null (T)
2389 -- In case of aggregates we must also take care of the correct
2390 -- initialization of nested aggregates bug this is done at the
2391 -- point of the analysis of the aggregate (see sem_aggr.adb)
2393 if Present (Expression (N))
2394 and then Nkind (Expression (N)) = N_Aggregate
2400 Save_Typ : constant Entity_Id := Etype (Id);
2402 Set_Etype (Id, T); -- Temp. decoration for static checks
2403 Null_Exclusion_Static_Checks (N);
2404 Set_Etype (Id, Save_Typ);
2409 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2411 -- If deferred constant, make sure context is appropriate. We detect
2412 -- a deferred constant as a constant declaration with no expression.
2413 -- A deferred constant can appear in a package body if its completion
2414 -- is by means of an interface pragma.
2416 if Constant_Present (N)
2419 -- We exclude forward references to tags
2421 if Is_Imported (Defining_Identifier (N))
2425 (Present (Full_View (T))
2426 and then Full_View (T) = RTE (RE_Tag)))
2430 -- A deferred constant may appear in the declarative part of the
2431 -- following constructs:
2435 -- extended return statements
2438 -- subprogram bodies
2441 -- When declared inside a package spec, a deferred constant must be
2442 -- completed by a full constant declaration or pragma Import. In all
2443 -- other cases, the only proper completion is pragma Import. Extended
2444 -- return statements are flagged as invalid contexts because they do
2445 -- not have a declarative part and so cannot accommodate the pragma.
2447 elsif Ekind (Current_Scope) = E_Return_Statement then
2449 ("invalid context for deferred constant declaration (RM 7.4)",
2452 ("\declaration requires an initialization expression",
2454 Set_Constant_Present (N, False);
2456 -- In Ada 83, deferred constant must be of private type
2458 elsif not Is_Private_Type (T) then
2459 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2461 ("(Ada 83) deferred constant must be private type", N);
2465 -- If not a deferred constant, then object declaration freezes its type
2468 Check_Fully_Declared (T, N);
2469 Freeze_Before (N, T);
2472 -- If the object was created by a constrained array definition, then
2473 -- set the link in both the anonymous base type and anonymous subtype
2474 -- that are built to represent the array type to point to the object.
2476 if Nkind (Object_Definition (Declaration_Node (Id))) =
2477 N_Constrained_Array_Definition
2479 Set_Related_Array_Object (T, Id);
2480 Set_Related_Array_Object (Base_Type (T), Id);
2483 -- Special checks for protected objects not at library level
2485 if Is_Protected_Type (T)
2486 and then not Is_Library_Level_Entity (Id)
2488 Check_Restriction (No_Local_Protected_Objects, Id);
2490 -- Protected objects with interrupt handlers must be at library level
2492 -- Ada 2005: this test is not needed (and the corresponding clause
2493 -- in the RM is removed) because accessibility checks are sufficient
2494 -- to make handlers not at the library level illegal.
2496 if Has_Interrupt_Handler (T)
2497 and then Ada_Version < Ada_05
2500 ("interrupt object can only be declared at library level", Id);
2504 -- The actual subtype of the object is the nominal subtype, unless
2505 -- the nominal one is unconstrained and obtained from the expression.
2509 -- Process initialization expression if present and not in error
2511 if Present (E) and then E /= Error then
2513 -- Generate an error in case of CPP class-wide object initialization.
2514 -- Required because otherwise the expansion of the class-wide
2515 -- assignment would try to use 'size to initialize the object
2516 -- (primitive that is not available in CPP tagged types).
2518 if Is_Class_Wide_Type (Act_T)
2520 (Is_CPP_Class (Root_Type (Etype (Act_T)))
2522 (Present (Full_View (Root_Type (Etype (Act_T))))
2524 Is_CPP_Class (Full_View (Root_Type (Etype (Act_T))))))
2527 ("predefined assignment not available for 'C'P'P tagged types",
2531 Mark_Coextensions (N, E);
2534 -- In case of errors detected in the analysis of the expression,
2535 -- decorate it with the expected type to avoid cascaded errors
2537 if No (Etype (E)) then
2541 -- If an initialization expression is present, then we set the
2542 -- Is_True_Constant flag. It will be reset if this is a variable
2543 -- and it is indeed modified.
2545 Set_Is_True_Constant (Id, True);
2547 -- If we are analyzing a constant declaration, set its completion
2548 -- flag after analyzing and resolving the expression.
2550 if Constant_Present (N) then
2551 Set_Has_Completion (Id);
2554 -- Set type and resolve (type may be overridden later on)
2559 -- If E is null and has been replaced by an N_Raise_Constraint_Error
2560 -- node (which was marked already-analyzed), we need to set the type
2561 -- to something other than Any_Access in order to keep gigi happy.
2563 if Etype (E) = Any_Access then
2567 -- If the object is an access to variable, the initialization
2568 -- expression cannot be an access to constant.
2570 if Is_Access_Type (T)
2571 and then not Is_Access_Constant (T)
2572 and then Is_Access_Type (Etype (E))
2573 and then Is_Access_Constant (Etype (E))
2576 ("access to variable cannot be initialized " &
2577 "with an access-to-constant expression", E);
2580 if not Assignment_OK (N) then
2581 Check_Initialization (T, E);
2584 Check_Unset_Reference (E);
2586 -- If this is a variable, then set current value
2588 if not Constant_Present (N) then
2589 if Compile_Time_Known_Value (E) then
2590 Set_Current_Value (Id, E);
2594 -- Deal with setting of null flags
2596 if Is_Access_Type (T) then
2597 if Known_Non_Null (E) then
2598 Set_Is_Known_Non_Null (Id, True);
2599 elsif Known_Null (E)
2600 and then not Can_Never_Be_Null (Id)
2602 Set_Is_Known_Null (Id, True);
2606 -- Check incorrect use of dynamically tagged expressions. Note
2607 -- the use of Is_Tagged_Type (T) which seems redundant but is in
2608 -- fact important to avoid spurious errors due to expanded code
2609 -- for dispatching functions over an anonymous access type
2611 if (Is_Class_Wide_Type (Etype (E)) or else Is_Dynamically_Tagged (E))
2612 and then Is_Tagged_Type (T)
2613 and then not Is_Class_Wide_Type (T)
2615 Error_Msg_N ("dynamically tagged expression not allowed!", E);
2618 Apply_Scalar_Range_Check (E, T);
2619 Apply_Static_Length_Check (E, T);
2622 -- If the No_Streams restriction is set, check that the type of the
2623 -- object is not, and does not contain, any subtype derived from
2624 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
2625 -- Has_Stream just for efficiency reasons. There is no point in
2626 -- spending time on a Has_Stream check if the restriction is not set.
2628 if Restrictions.Set (No_Streams) then
2629 if Has_Stream (T) then
2630 Check_Restriction (No_Streams, N);
2634 -- Abstract type is never permitted for a variable or constant.
2635 -- Note: we inhibit this check for objects that do not come from
2636 -- source because there is at least one case (the expansion of
2637 -- x'class'input where x is abstract) where we legitimately
2638 -- generate an abstract object.
2640 if Is_Abstract_Type (T) and then Comes_From_Source (N) then
2641 Error_Msg_N ("type of object cannot be abstract",
2642 Object_Definition (N));
2644 if Is_CPP_Class (T) then
2645 Error_Msg_NE ("\} may need a cpp_constructor",
2646 Object_Definition (N), T);
2649 -- Case of unconstrained type
2651 elsif Is_Indefinite_Subtype (T) then
2653 -- Nothing to do in deferred constant case
2655 if Constant_Present (N) and then No (E) then
2658 -- Case of no initialization present
2661 if No_Initialization (N) then
2664 elsif Is_Class_Wide_Type (T) then
2666 ("initialization required in class-wide declaration ", N);
2670 ("unconstrained subtype not allowed (need initialization)",
2671 Object_Definition (N));
2673 if Is_Record_Type (T) and then Has_Discriminants (T) then
2675 ("\provide initial value or explicit discriminant values",
2676 Object_Definition (N));
2679 ("\or give default discriminant values for type&",
2680 Object_Definition (N), T);
2682 elsif Is_Array_Type (T) then
2684 ("\provide initial value or explicit array bounds",
2685 Object_Definition (N));
2689 -- Case of initialization present but in error. Set initial
2690 -- expression as absent (but do not make above complaints)
2692 elsif E = Error then
2693 Set_Expression (N, Empty);
2696 -- Case of initialization present
2699 -- Not allowed in Ada 83
2701 if not Constant_Present (N) then
2702 if Ada_Version = Ada_83
2703 and then Comes_From_Source (Object_Definition (N))
2706 ("(Ada 83) unconstrained variable not allowed",
2707 Object_Definition (N));
2711 -- Now we constrain the variable from the initializing expression
2713 -- If the expression is an aggregate, it has been expanded into
2714 -- individual assignments. Retrieve the actual type from the
2715 -- expanded construct.
2717 if Is_Array_Type (T)
2718 and then No_Initialization (N)
2719 and then Nkind (Original_Node (E)) = N_Aggregate
2724 Expand_Subtype_From_Expr (N, T, Object_Definition (N), E);
2725 Act_T := Find_Type_Of_Object (Object_Definition (N), N);
2728 Set_Is_Constr_Subt_For_U_Nominal (Act_T);
2730 if Aliased_Present (N) then
2731 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2734 Freeze_Before (N, Act_T);
2735 Freeze_Before (N, T);
2738 elsif Is_Array_Type (T)
2739 and then No_Initialization (N)
2740 and then Nkind (Original_Node (E)) = N_Aggregate
2742 if not Is_Entity_Name (Object_Definition (N)) then
2744 Check_Compile_Time_Size (Act_T);
2746 if Aliased_Present (N) then
2747 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2751 -- When the given object definition and the aggregate are specified
2752 -- independently, and their lengths might differ do a length check.
2753 -- This cannot happen if the aggregate is of the form (others =>...)
2755 if not Is_Constrained (T) then
2758 elsif Nkind (E) = N_Raise_Constraint_Error then
2760 -- Aggregate is statically illegal. Place back in declaration
2762 Set_Expression (N, E);
2763 Set_No_Initialization (N, False);
2765 elsif T = Etype (E) then
2768 elsif Nkind (E) = N_Aggregate
2769 and then Present (Component_Associations (E))
2770 and then Present (Choices (First (Component_Associations (E))))
2771 and then Nkind (First
2772 (Choices (First (Component_Associations (E))))) = N_Others_Choice
2777 Apply_Length_Check (E, T);
2780 -- If the type is limited unconstrained with defaulted discriminants
2781 -- and there is no expression, then the object is constrained by the
2782 -- defaults, so it is worthwhile building the corresponding subtype.
2784 elsif (Is_Limited_Record (T)
2785 or else Is_Concurrent_Type (T))
2786 and then not Is_Constrained (T)
2787 and then Has_Discriminants (T)
2790 Act_T := Build_Default_Subtype (T, N);
2792 -- Ada 2005: a limited object may be initialized by means of an
2793 -- aggregate. If the type has default discriminants it has an
2794 -- unconstrained nominal type, Its actual subtype will be obtained
2795 -- from the aggregate, and not from the default discriminants.
2800 Rewrite (Object_Definition (N), New_Occurrence_Of (Act_T, Loc));
2802 elsif Present (Underlying_Type (T))
2803 and then not Is_Constrained (Underlying_Type (T))
2804 and then Has_Discriminants (Underlying_Type (T))
2805 and then Nkind (E) = N_Function_Call
2806 and then Constant_Present (N)
2808 -- The back-end has problems with constants of a discriminated type
2809 -- with defaults, if the initial value is a function call. We
2810 -- generate an intermediate temporary for the result of the call.
2811 -- It is unclear why this should make it acceptable to gcc. ???
2813 Remove_Side_Effects (E);
2816 -- Check No_Wide_Characters restriction
2818 if T = Standard_Wide_Character
2819 or else T = Standard_Wide_Wide_Character
2820 or else Root_Type (T) = Standard_Wide_String
2821 or else Root_Type (T) = Standard_Wide_Wide_String
2823 Check_Restriction (No_Wide_Characters, Object_Definition (N));
2826 -- Indicate this is not set in source. Certainly true for constants,
2827 -- and true for variables so far (will be reset for a variable if and
2828 -- when we encounter a modification in the source).
2830 Set_Never_Set_In_Source (Id, True);
2832 -- Now establish the proper kind and type of the object
2834 if Constant_Present (N) then
2835 Set_Ekind (Id, E_Constant);
2836 Set_Is_True_Constant (Id, True);
2839 Set_Ekind (Id, E_Variable);
2841 -- A variable is set as shared passive if it appears in a shared
2842 -- passive package, and is at the outer level. This is not done
2843 -- for entities generated during expansion, because those are
2844 -- always manipulated locally.
2846 if Is_Shared_Passive (Current_Scope)
2847 and then Is_Library_Level_Entity (Id)
2848 and then Comes_From_Source (Id)
2850 Set_Is_Shared_Passive (Id);
2851 Check_Shared_Var (Id, T, N);
2854 -- Set Has_Initial_Value if initializing expression present. Note
2855 -- that if there is no initializing expression, we leave the state
2856 -- of this flag unchanged (usually it will be False, but notably in
2857 -- the case of exception choice variables, it will already be true).
2860 Set_Has_Initial_Value (Id, True);
2864 -- Initialize alignment and size and capture alignment setting
2866 Init_Alignment (Id);
2868 Set_Optimize_Alignment_Flags (Id);
2870 -- Deal with aliased case
2872 if Aliased_Present (N) then
2873 Set_Is_Aliased (Id);
2875 -- If the object is aliased and the type is unconstrained with
2876 -- defaulted discriminants and there is no expression, then the
2877 -- object is constrained by the defaults, so it is worthwhile
2878 -- building the corresponding subtype.
2880 -- Ada 2005 (AI-363): If the aliased object is discriminated and
2881 -- unconstrained, then only establish an actual subtype if the
2882 -- nominal subtype is indefinite. In definite cases the object is
2883 -- unconstrained in Ada 2005.
2886 and then Is_Record_Type (T)
2887 and then not Is_Constrained (T)
2888 and then Has_Discriminants (T)
2889 and then (Ada_Version < Ada_05 or else Is_Indefinite_Subtype (T))
2891 Set_Actual_Subtype (Id, Build_Default_Subtype (T, N));
2895 -- Now we can set the type of the object
2897 Set_Etype (Id, Act_T);
2899 -- Deal with controlled types
2901 if Has_Controlled_Component (Etype (Id))
2902 or else Is_Controlled (Etype (Id))
2904 if not Is_Library_Level_Entity (Id) then
2905 Check_Restriction (No_Nested_Finalization, N);
2907 Validate_Controlled_Object (Id);
2910 -- Generate a warning when an initialization causes an obvious ABE
2911 -- violation. If the init expression is a simple aggregate there
2912 -- shouldn't be any initialize/adjust call generated. This will be
2913 -- true as soon as aggregates are built in place when possible.
2915 -- ??? at the moment we do not generate warnings for temporaries
2916 -- created for those aggregates although Program_Error might be
2917 -- generated if compiled with -gnato.
2919 if Is_Controlled (Etype (Id))
2920 and then Comes_From_Source (Id)
2923 BT : constant Entity_Id := Base_Type (Etype (Id));
2925 Implicit_Call : Entity_Id;
2926 pragma Warnings (Off, Implicit_Call);
2927 -- ??? what is this for (never referenced!)
2929 function Is_Aggr (N : Node_Id) return Boolean;
2930 -- Check that N is an aggregate
2936 function Is_Aggr (N : Node_Id) return Boolean is
2938 case Nkind (Original_Node (N)) is
2939 when N_Aggregate | N_Extension_Aggregate =>
2942 when N_Qualified_Expression |
2944 N_Unchecked_Type_Conversion =>
2945 return Is_Aggr (Expression (Original_Node (N)));
2953 -- If no underlying type, we already are in an error situation.
2954 -- Do not try to add a warning since we do not have access to
2957 if No (Underlying_Type (BT)) then
2958 Implicit_Call := Empty;
2960 -- A generic type does not have usable primitive operators.
2961 -- Initialization calls are built for instances.
2963 elsif Is_Generic_Type (BT) then
2964 Implicit_Call := Empty;
2966 -- If the init expression is not an aggregate, an adjust call
2967 -- will be generated
2969 elsif Present (E) and then not Is_Aggr (E) then
2970 Implicit_Call := Find_Prim_Op (BT, Name_Adjust);
2972 -- If no init expression and we are not in the deferred
2973 -- constant case, an Initialize call will be generated
2975 elsif No (E) and then not Constant_Present (N) then
2976 Implicit_Call := Find_Prim_Op (BT, Name_Initialize);
2979 Implicit_Call := Empty;
2985 if Has_Task (Etype (Id)) then
2986 Check_Restriction (No_Tasking, N);
2988 -- Deal with counting max tasks
2990 -- Nothing to do if inside a generic
2992 if Inside_A_Generic then
2995 -- If library level entity, then count tasks
2997 elsif Is_Library_Level_Entity (Id) then
2998 Check_Restriction (Max_Tasks, N, Count_Tasks (Etype (Id)));
3000 -- If not library level entity, then indicate we don't know max
3001 -- tasks and also check task hierarchy restriction and blocking
3002 -- operation (since starting a task is definitely blocking!)
3005 Check_Restriction (Max_Tasks, N);
3006 Check_Restriction (No_Task_Hierarchy, N);
3007 Check_Potentially_Blocking_Operation (N);
3010 -- A rather specialized test. If we see two tasks being declared
3011 -- of the same type in the same object declaration, and the task
3012 -- has an entry with an address clause, we know that program error
3013 -- will be raised at run-time since we can't have two tasks with
3014 -- entries at the same address.
3016 if Is_Task_Type (Etype (Id)) and then More_Ids (N) then
3021 E := First_Entity (Etype (Id));
3022 while Present (E) loop
3023 if Ekind (E) = E_Entry
3024 and then Present (Get_Attribute_Definition_Clause
3025 (E, Attribute_Address))
3028 ("?more than one task with same entry address", N);
3030 ("\?Program_Error will be raised at run time", N);
3032 Make_Raise_Program_Error (Loc,
3033 Reason => PE_Duplicated_Entry_Address));
3043 -- Some simple constant-propagation: if the expression is a constant
3044 -- string initialized with a literal, share the literal. This avoids
3048 and then Is_Entity_Name (E)
3049 and then Ekind (Entity (E)) = E_Constant
3050 and then Base_Type (Etype (E)) = Standard_String
3053 Val : constant Node_Id := Constant_Value (Entity (E));
3056 and then Nkind (Val) = N_String_Literal
3058 Rewrite (E, New_Copy (Val));
3063 -- Another optimization: if the nominal subtype is unconstrained and
3064 -- the expression is a function call that returns an unconstrained
3065 -- type, rewrite the declaration as a renaming of the result of the
3066 -- call. The exceptions below are cases where the copy is expected,
3067 -- either by the back end (Aliased case) or by the semantics, as for
3068 -- initializing controlled types or copying tags for classwide types.
3071 and then Nkind (E) = N_Explicit_Dereference
3072 and then Nkind (Original_Node (E)) = N_Function_Call
3073 and then not Is_Library_Level_Entity (Id)
3074 and then not Is_Constrained (Underlying_Type (T))
3075 and then not Is_Aliased (Id)
3076 and then not Is_Class_Wide_Type (T)
3077 and then not Is_Controlled (T)
3078 and then not Has_Controlled_Component (Base_Type (T))
3079 and then Expander_Active
3082 Make_Object_Renaming_Declaration (Loc,
3083 Defining_Identifier => Id,
3084 Access_Definition => Empty,
3085 Subtype_Mark => New_Occurrence_Of
3086 (Base_Type (Etype (Id)), Loc),
3089 Set_Renamed_Object (Id, E);
3091 -- Force generation of debugging information for the constant and for
3092 -- the renamed function call.
3094 Set_Debug_Info_Needed (Id);
3095 Set_Debug_Info_Needed (Entity (Prefix (E)));
3098 if Present (Prev_Entity)
3099 and then Is_Frozen (Prev_Entity)
3100 and then not Error_Posted (Id)
3102 Error_Msg_N ("full constant declaration appears too late", N);
3105 Check_Eliminated (Id);
3107 -- Deal with setting In_Private_Part flag if in private part
3109 if Ekind (Scope (Id)) = E_Package
3110 and then In_Private_Part (Scope (Id))
3112 Set_In_Private_Part (Id);
3115 -- Check for violation of No_Local_Timing_Events
3117 if Is_RTE (Etype (Id), RE_Timing_Event)
3118 and then not Is_Library_Level_Entity (Id)
3120 Check_Restriction (No_Local_Timing_Events, N);
3122 end Analyze_Object_Declaration;
3124 ---------------------------
3125 -- Analyze_Others_Choice --
3126 ---------------------------
3128 -- Nothing to do for the others choice node itself, the semantic analysis
3129 -- of the others choice will occur as part of the processing of the parent
3131 procedure Analyze_Others_Choice (N : Node_Id) is
3132 pragma Warnings (Off, N);
3135 end Analyze_Others_Choice;
3137 -------------------------------------------
3138 -- Analyze_Private_Extension_Declaration --
3139 -------------------------------------------
3141 procedure Analyze_Private_Extension_Declaration (N : Node_Id) is
3142 T : constant Entity_Id := Defining_Identifier (N);
3143 Indic : constant Node_Id := Subtype_Indication (N);
3144 Parent_Type : Entity_Id;
3145 Parent_Base : Entity_Id;
3148 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
3150 if Is_Non_Empty_List (Interface_List (N)) then
3156 Intf := First (Interface_List (N));
3157 while Present (Intf) loop
3158 T := Find_Type_Of_Subtype_Indic (Intf);
3160 Diagnose_Interface (Intf, T);
3166 Generate_Definition (T);
3169 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
3170 Parent_Base := Base_Type (Parent_Type);
3172 if Parent_Type = Any_Type
3173 or else Etype (Parent_Type) = Any_Type
3175 Set_Ekind (T, Ekind (Parent_Type));
3176 Set_Etype (T, Any_Type);
3179 elsif not Is_Tagged_Type (Parent_Type) then
3181 ("parent of type extension must be a tagged type ", Indic);
3184 elsif Ekind (Parent_Type) = E_Void
3185 or else Ekind (Parent_Type) = E_Incomplete_Type
3187 Error_Msg_N ("premature derivation of incomplete type", Indic);
3190 elsif Is_Concurrent_Type (Parent_Type) then
3192 ("parent type of a private extension cannot be "
3193 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
3195 Set_Etype (T, Any_Type);
3196 Set_Ekind (T, E_Limited_Private_Type);
3197 Set_Private_Dependents (T, New_Elmt_List);
3198 Set_Error_Posted (T);
3202 -- Perhaps the parent type should be changed to the class-wide type's
3203 -- specific type in this case to prevent cascading errors ???
3205 if Is_Class_Wide_Type (Parent_Type) then
3207 ("parent of type extension must not be a class-wide type", Indic);
3211 if (not Is_Package_Or_Generic_Package (Current_Scope)
3212 and then Nkind (Parent (N)) /= N_Generic_Subprogram_Declaration)
3213 or else In_Private_Part (Current_Scope)
3216 Error_Msg_N ("invalid context for private extension", N);
3219 -- Set common attributes
3221 Set_Is_Pure (T, Is_Pure (Current_Scope));
3222 Set_Scope (T, Current_Scope);
3223 Set_Ekind (T, E_Record_Type_With_Private);
3224 Init_Size_Align (T);
3226 Set_Etype (T, Parent_Base);
3227 Set_Has_Task (T, Has_Task (Parent_Base));
3229 Set_Convention (T, Convention (Parent_Type));
3230 Set_First_Rep_Item (T, First_Rep_Item (Parent_Type));
3231 Set_Is_First_Subtype (T);
3232 Make_Class_Wide_Type (T);
3234 if Unknown_Discriminants_Present (N) then
3235 Set_Discriminant_Constraint (T, No_Elist);
3238 Build_Derived_Record_Type (N, Parent_Type, T);
3240 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
3241 -- synchronized formal derived type.
3243 if Ada_Version >= Ada_05
3244 and then Synchronized_Present (N)
3246 Set_Is_Limited_Record (T);
3248 -- Formal derived type case
3250 if Is_Generic_Type (T) then
3252 -- The parent must be a tagged limited type or a synchronized
3255 if (not Is_Tagged_Type (Parent_Type)
3256 or else not Is_Limited_Type (Parent_Type))
3258 (not Is_Interface (Parent_Type)
3259 or else not Is_Synchronized_Interface (Parent_Type))
3261 Error_Msg_NE ("parent type of & must be tagged limited " &
3262 "or synchronized", N, T);
3265 -- The progenitors (if any) must be limited or synchronized
3268 if Present (Interfaces (T)) then
3271 Iface_Elmt : Elmt_Id;
3274 Iface_Elmt := First_Elmt (Interfaces (T));
3275 while Present (Iface_Elmt) loop
3276 Iface := Node (Iface_Elmt);
3278 if not Is_Limited_Interface (Iface)
3279 and then not Is_Synchronized_Interface (Iface)
3281 Error_Msg_NE ("progenitor & must be limited " &
3282 "or synchronized", N, Iface);
3285 Next_Elmt (Iface_Elmt);
3290 -- Regular derived extension, the parent must be a limited or
3291 -- synchronized interface.
3294 if not Is_Interface (Parent_Type)
3295 or else (not Is_Limited_Interface (Parent_Type)
3297 not Is_Synchronized_Interface (Parent_Type))
3300 ("parent type of & must be limited interface", N, T);
3304 elsif Limited_Present (N) then
3305 Set_Is_Limited_Record (T);
3307 if not Is_Limited_Type (Parent_Type)
3309 (not Is_Interface (Parent_Type)
3310 or else not Is_Limited_Interface (Parent_Type))
3312 Error_Msg_NE ("parent type& of limited extension must be limited",
3316 end Analyze_Private_Extension_Declaration;
3318 ---------------------------------
3319 -- Analyze_Subtype_Declaration --
3320 ---------------------------------
3322 procedure Analyze_Subtype_Declaration
3324 Skip : Boolean := False)
3326 Id : constant Entity_Id := Defining_Identifier (N);
3328 R_Checks : Check_Result;
3331 Generate_Definition (Id);
3332 Set_Is_Pure (Id, Is_Pure (Current_Scope));
3333 Init_Size_Align (Id);
3335 -- The following guard condition on Enter_Name is to handle cases where
3336 -- the defining identifier has already been entered into the scope but
3337 -- the declaration as a whole needs to be analyzed.
3339 -- This case in particular happens for derived enumeration types. The
3340 -- derived enumeration type is processed as an inserted enumeration type
3341 -- declaration followed by a rewritten subtype declaration. The defining
3342 -- identifier, however, is entered into the name scope very early in the
3343 -- processing of the original type declaration and therefore needs to be
3344 -- avoided here, when the created subtype declaration is analyzed. (See
3345 -- Build_Derived_Types)
3347 -- This also happens when the full view of a private type is derived
3348 -- type with constraints. In this case the entity has been introduced
3349 -- in the private declaration.
3352 or else (Present (Etype (Id))
3353 and then (Is_Private_Type (Etype (Id))
3354 or else Is_Task_Type (Etype (Id))
3355 or else Is_Rewrite_Substitution (N)))
3363 T := Process_Subtype (Subtype_Indication (N), N, Id, 'P');
3365 -- Inherit common attributes
3367 Set_Is_Generic_Type (Id, Is_Generic_Type (Base_Type (T)));
3368 Set_Is_Volatile (Id, Is_Volatile (T));
3369 Set_Treat_As_Volatile (Id, Treat_As_Volatile (T));
3370 Set_Is_Atomic (Id, Is_Atomic (T));
3371 Set_Is_Ada_2005_Only (Id, Is_Ada_2005_Only (T));
3372 Set_Convention (Id, Convention (T));
3374 -- In the case where there is no constraint given in the subtype
3375 -- indication, Process_Subtype just returns the Subtype_Mark, so its
3376 -- semantic attributes must be established here.
3378 if Nkind (Subtype_Indication (N)) /= N_Subtype_Indication then
3379 Set_Etype (Id, Base_Type (T));
3383 Set_Ekind (Id, E_Array_Subtype);
3384 Copy_Array_Subtype_Attributes (Id, T);
3386 when Decimal_Fixed_Point_Kind =>
3387 Set_Ekind (Id, E_Decimal_Fixed_Point_Subtype);
3388 Set_Digits_Value (Id, Digits_Value (T));
3389 Set_Delta_Value (Id, Delta_Value (T));
3390 Set_Scale_Value (Id, Scale_Value (T));
3391 Set_Small_Value (Id, Small_Value (T));
3392 Set_Scalar_Range (Id, Scalar_Range (T));
3393 Set_Machine_Radix_10 (Id, Machine_Radix_10 (T));
3394 Set_Is_Constrained (Id, Is_Constrained (T));
3395 Set_RM_Size (Id, RM_Size (T));
3397 when Enumeration_Kind =>
3398 Set_Ekind (Id, E_Enumeration_Subtype);
3399 Set_First_Literal (Id, First_Literal (Base_Type (T)));
3400 Set_Scalar_Range (Id, Scalar_Range (T));
3401 Set_Is_Character_Type (Id, Is_Character_Type (T));
3402 Set_Is_Constrained (Id, Is_Constrained (T));
3403 Set_RM_Size (Id, RM_Size (T));
3405 when Ordinary_Fixed_Point_Kind =>
3406 Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype);
3407 Set_Scalar_Range (Id, Scalar_Range (T));
3408 Set_Small_Value (Id, Small_Value (T));
3409 Set_Delta_Value (Id, Delta_Value (T));
3410 Set_Is_Constrained (Id, Is_Constrained (T));
3411 Set_RM_Size (Id, RM_Size (T));
3414 Set_Ekind (Id, E_Floating_Point_Subtype);
3415 Set_Scalar_Range (Id, Scalar_Range (T));
3416 Set_Digits_Value (Id, Digits_Value (T));
3417 Set_Is_Constrained (Id, Is_Constrained (T));
3419 when Signed_Integer_Kind =>
3420 Set_Ekind (Id, E_Signed_Integer_Subtype);
3421 Set_Scalar_Range (Id, Scalar_Range (T));
3422 Set_Is_Constrained (Id, Is_Constrained (T));
3423 Set_RM_Size (Id, RM_Size (T));
3425 when Modular_Integer_Kind =>
3426 Set_Ekind (Id, E_Modular_Integer_Subtype);
3427 Set_Scalar_Range (Id, Scalar_Range (T));
3428 Set_Is_Constrained (Id, Is_Constrained (T));
3429 Set_RM_Size (Id, RM_Size (T));
3431 when Class_Wide_Kind =>
3432 Set_Ekind (Id, E_Class_Wide_Subtype);
3433 Set_First_Entity (Id, First_Entity (T));
3434 Set_Last_Entity (Id, Last_Entity (T));
3435 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3436 Set_Cloned_Subtype (Id, T);
3437 Set_Is_Tagged_Type (Id, True);
3438 Set_Has_Unknown_Discriminants
3441 if Ekind (T) = E_Class_Wide_Subtype then
3442 Set_Equivalent_Type (Id, Equivalent_Type (T));
3445 when E_Record_Type | E_Record_Subtype =>
3446 Set_Ekind (Id, E_Record_Subtype);
3448 if Ekind (T) = E_Record_Subtype
3449 and then Present (Cloned_Subtype (T))
3451 Set_Cloned_Subtype (Id, Cloned_Subtype (T));
3453 Set_Cloned_Subtype (Id, T);
3456 Set_First_Entity (Id, First_Entity (T));
3457 Set_Last_Entity (Id, Last_Entity (T));
3458 Set_Has_Discriminants (Id, Has_Discriminants (T));
3459 Set_Is_Constrained (Id, Is_Constrained (T));
3460 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3461 Set_Has_Unknown_Discriminants
3462 (Id, Has_Unknown_Discriminants (T));
3464 if Has_Discriminants (T) then
3465 Set_Discriminant_Constraint
3466 (Id, Discriminant_Constraint (T));
3467 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3469 elsif Has_Unknown_Discriminants (Id) then
3470 Set_Discriminant_Constraint (Id, No_Elist);
3473 if Is_Tagged_Type (T) then
3474 Set_Is_Tagged_Type (Id);
3475 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3476 Set_Primitive_Operations
3477 (Id, Primitive_Operations (T));
3478 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3480 if Is_Interface (T) then
3481 Set_Is_Interface (Id);
3482 Set_Is_Limited_Interface (Id, Is_Limited_Interface (T));
3486 when Private_Kind =>
3487 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3488 Set_Has_Discriminants (Id, Has_Discriminants (T));
3489 Set_Is_Constrained (Id, Is_Constrained (T));
3490 Set_First_Entity (Id, First_Entity (T));
3491 Set_Last_Entity (Id, Last_Entity (T));
3492 Set_Private_Dependents (Id, New_Elmt_List);
3493 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3494 Set_Has_Unknown_Discriminants
3495 (Id, Has_Unknown_Discriminants (T));
3496 Set_Known_To_Have_Preelab_Init
3497 (Id, Known_To_Have_Preelab_Init (T));
3499 if Is_Tagged_Type (T) then
3500 Set_Is_Tagged_Type (Id);
3501 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3502 Set_Primitive_Operations (Id, Primitive_Operations (T));
3503 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3506 -- In general the attributes of the subtype of a private type
3507 -- are the attributes of the partial view of parent. However,
3508 -- the full view may be a discriminated type, and the subtype
3509 -- must share the discriminant constraint to generate correct
3510 -- calls to initialization procedures.
3512 if Has_Discriminants (T) then
3513 Set_Discriminant_Constraint
3514 (Id, Discriminant_Constraint (T));
3515 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3517 elsif Present (Full_View (T))
3518 and then Has_Discriminants (Full_View (T))
3520 Set_Discriminant_Constraint
3521 (Id, Discriminant_Constraint (Full_View (T)));
3522 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3524 -- This would seem semantically correct, but apparently
3525 -- confuses the back-end. To be explained and checked with
3526 -- current version ???
3528 -- Set_Has_Discriminants (Id);
3531 Prepare_Private_Subtype_Completion (Id, N);
3534 Set_Ekind (Id, E_Access_Subtype);
3535 Set_Is_Constrained (Id, Is_Constrained (T));
3536 Set_Is_Access_Constant
3537 (Id, Is_Access_Constant (T));
3538 Set_Directly_Designated_Type
3539 (Id, Designated_Type (T));
3540 Set_Can_Never_Be_Null (Id, Can_Never_Be_Null (T));
3542 -- A Pure library_item must not contain the declaration of a
3543 -- named access type, except within a subprogram, generic
3544 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
3546 if Comes_From_Source (Id)
3547 and then In_Pure_Unit
3548 and then not In_Subprogram_Task_Protected_Unit
3551 ("named access types not allowed in pure unit", N);
3554 when Concurrent_Kind =>
3555 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3556 Set_Corresponding_Record_Type (Id,
3557 Corresponding_Record_Type (T));
3558 Set_First_Entity (Id, First_Entity (T));
3559 Set_First_Private_Entity (Id, First_Private_Entity (T));
3560 Set_Has_Discriminants (Id, Has_Discriminants (T));
3561 Set_Is_Constrained (Id, Is_Constrained (T));
3562 Set_Is_Tagged_Type (Id, Is_Tagged_Type (T));
3563 Set_Last_Entity (Id, Last_Entity (T));
3565 if Has_Discriminants (T) then
3566 Set_Discriminant_Constraint (Id,
3567 Discriminant_Constraint (T));
3568 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3571 when E_Incomplete_Type =>
3572 if Ada_Version >= Ada_05 then
3573 Set_Ekind (Id, E_Incomplete_Subtype);
3575 -- Ada 2005 (AI-412): Decorate an incomplete subtype
3576 -- of an incomplete type visible through a limited
3579 if From_With_Type (T)
3580 and then Present (Non_Limited_View (T))
3582 Set_From_With_Type (Id);
3583 Set_Non_Limited_View (Id, Non_Limited_View (T));
3585 -- Ada 2005 (AI-412): Add the regular incomplete subtype
3586 -- to the private dependents of the original incomplete
3587 -- type for future transformation.
3590 Append_Elmt (Id, Private_Dependents (T));
3593 -- If the subtype name denotes an incomplete type an error
3594 -- was already reported by Process_Subtype.
3597 Set_Etype (Id, Any_Type);
3601 raise Program_Error;
3605 if Etype (Id) = Any_Type then
3609 -- Some common processing on all types
3611 Set_Size_Info (Id, T);
3612 Set_First_Rep_Item (Id, First_Rep_Item (T));
3616 Set_Is_Immediately_Visible (Id, True);
3617 Set_Depends_On_Private (Id, Has_Private_Component (T));
3618 Set_Is_Descendent_Of_Address (Id, Is_Descendent_Of_Address (T));
3620 if Is_Interface (T) then
3621 Set_Is_Interface (Id);
3624 if Present (Generic_Parent_Type (N))
3627 (Parent (Generic_Parent_Type (N))) /= N_Formal_Type_Declaration
3629 (Formal_Type_Definition (Parent (Generic_Parent_Type (N))))
3630 /= N_Formal_Private_Type_Definition)
3632 if Is_Tagged_Type (Id) then
3634 -- If this is a generic actual subtype for a synchronized type,
3635 -- the primitive operations are those of the corresponding record
3636 -- for which there is a separate subtype declaration.
3638 if Is_Concurrent_Type (Id) then
3640 elsif Is_Class_Wide_Type (Id) then
3641 Derive_Subprograms (Generic_Parent_Type (N), Id, Etype (T));
3643 Derive_Subprograms (Generic_Parent_Type (N), Id, T);
3646 elsif Scope (Etype (Id)) /= Standard_Standard then
3647 Derive_Subprograms (Generic_Parent_Type (N), Id);
3651 if Is_Private_Type (T)
3652 and then Present (Full_View (T))
3654 Conditional_Delay (Id, Full_View (T));
3656 -- The subtypes of components or subcomponents of protected types
3657 -- do not need freeze nodes, which would otherwise appear in the
3658 -- wrong scope (before the freeze node for the protected type). The
3659 -- proper subtypes are those of the subcomponents of the corresponding
3662 elsif Ekind (Scope (Id)) /= E_Protected_Type
3663 and then Present (Scope (Scope (Id))) -- error defense!
3664 and then Ekind (Scope (Scope (Id))) /= E_Protected_Type
3666 Conditional_Delay (Id, T);
3669 -- Check that constraint_error is raised for a scalar subtype
3670 -- indication when the lower or upper bound of a non-null range
3671 -- lies outside the range of the type mark.
3673 if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then
3674 if Is_Scalar_Type (Etype (Id))
3675 and then Scalar_Range (Id) /=
3676 Scalar_Range (Etype (Subtype_Mark
3677 (Subtype_Indication (N))))
3681 Etype (Subtype_Mark (Subtype_Indication (N))));
3683 elsif Is_Array_Type (Etype (Id))
3684 and then Present (First_Index (Id))
3686 -- This really should be a subprogram that finds the indications
3689 if ((Nkind (First_Index (Id)) = N_Identifier
3690 and then Ekind (Entity (First_Index (Id))) in Scalar_Kind)
3691 or else Nkind (First_Index (Id)) = N_Subtype_Indication)
3693 Nkind (Scalar_Range (Etype (First_Index (Id)))) = N_Range
3696 Target_Typ : constant Entity_Id :=
3699 (Subtype_Mark (Subtype_Indication (N)))));
3703 (Scalar_Range (Etype (First_Index (Id))),
3705 Etype (First_Index (Id)),
3706 Defining_Identifier (N));
3712 Sloc (Defining_Identifier (N)));
3718 Set_Optimize_Alignment_Flags (Id);
3719 Check_Eliminated (Id);
3720 end Analyze_Subtype_Declaration;
3722 --------------------------------
3723 -- Analyze_Subtype_Indication --
3724 --------------------------------
3726 procedure Analyze_Subtype_Indication (N : Node_Id) is
3727 T : constant Entity_Id := Subtype_Mark (N);
3728 R : constant Node_Id := Range_Expression (Constraint (N));
3735 Set_Etype (N, Etype (R));
3736 Resolve (R, Entity (T));
3738 Set_Error_Posted (R);
3739 Set_Error_Posted (T);
3741 end Analyze_Subtype_Indication;
3743 ------------------------------
3744 -- Analyze_Type_Declaration --
3745 ------------------------------
3747 procedure Analyze_Type_Declaration (N : Node_Id) is
3748 Def : constant Node_Id := Type_Definition (N);
3749 Def_Id : constant Entity_Id := Defining_Identifier (N);
3753 Is_Remote : constant Boolean :=
3754 (Is_Remote_Types (Current_Scope)
3755 or else Is_Remote_Call_Interface (Current_Scope))
3756 and then not (In_Private_Part (Current_Scope)
3757 or else In_Package_Body (Current_Scope));
3759 procedure Check_Ops_From_Incomplete_Type;
3760 -- If there is a tagged incomplete partial view of the type, transfer
3761 -- its operations to the full view, and indicate that the type of the
3762 -- controlling parameter (s) is this full view.
3764 ------------------------------------
3765 -- Check_Ops_From_Incomplete_Type --
3766 ------------------------------------
3768 procedure Check_Ops_From_Incomplete_Type is
3775 and then Ekind (Prev) = E_Incomplete_Type
3776 and then Is_Tagged_Type (Prev)
3777 and then Is_Tagged_Type (T)
3779 Elmt := First_Elmt (Primitive_Operations (Prev));
3780 while Present (Elmt) loop
3782 Prepend_Elmt (Op, Primitive_Operations (T));
3784 Formal := First_Formal (Op);
3785 while Present (Formal) loop
3786 if Etype (Formal) = Prev then
3787 Set_Etype (Formal, T);
3790 Next_Formal (Formal);
3793 if Etype (Op) = Prev then
3800 end Check_Ops_From_Incomplete_Type;
3802 -- Start of processing for Analyze_Type_Declaration
3805 Prev := Find_Type_Name (N);
3807 -- The full view, if present, now points to the current type
3809 -- Ada 2005 (AI-50217): If the type was previously decorated when
3810 -- imported through a LIMITED WITH clause, it appears as incomplete
3811 -- but has no full view.
3812 -- If the incomplete view is tagged, a class_wide type has been
3813 -- created already. Use it for the full view as well, to prevent
3814 -- multiple incompatible class-wide types that may be created for
3815 -- self-referential anonymous access components.
3817 if Ekind (Prev) = E_Incomplete_Type
3818 and then Present (Full_View (Prev))
3820 T := Full_View (Prev);
3822 if Is_Tagged_Type (Prev)
3823 and then Present (Class_Wide_Type (Prev))
3825 Set_Ekind (T, Ekind (Prev)); -- will be reset later
3826 Set_Class_Wide_Type (T, Class_Wide_Type (Prev));
3827 Set_Etype (Class_Wide_Type (T), T);
3834 Set_Is_Pure (T, Is_Pure (Current_Scope));
3836 -- We set the flag Is_First_Subtype here. It is needed to set the
3837 -- corresponding flag for the Implicit class-wide-type created
3838 -- during tagged types processing.
3840 Set_Is_First_Subtype (T, True);
3842 -- Only composite types other than array types are allowed to have
3847 -- For derived types, the rule will be checked once we've figured
3848 -- out the parent type.
3850 when N_Derived_Type_Definition =>
3853 -- For record types, discriminants are allowed
3855 when N_Record_Definition =>
3859 if Present (Discriminant_Specifications (N)) then
3861 ("elementary or array type cannot have discriminants",
3863 (First (Discriminant_Specifications (N))));
3867 -- Elaborate the type definition according to kind, and generate
3868 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3869 -- already done (this happens during the reanalysis that follows a call
3870 -- to the high level optimizer).
3872 if not Analyzed (T) then
3877 when N_Access_To_Subprogram_Definition =>
3878 Access_Subprogram_Declaration (T, Def);
3880 -- If this is a remote access to subprogram, we must create the
3881 -- equivalent fat pointer type, and related subprograms.
3884 Process_Remote_AST_Declaration (N);
3887 -- Validate categorization rule against access type declaration
3888 -- usually a violation in Pure unit, Shared_Passive unit.
3890 Validate_Access_Type_Declaration (T, N);
3892 when N_Access_To_Object_Definition =>
3893 Access_Type_Declaration (T, Def);
3895 -- Validate categorization rule against access type declaration
3896 -- usually a violation in Pure unit, Shared_Passive unit.
3898 Validate_Access_Type_Declaration (T, N);
3900 -- If we are in a Remote_Call_Interface package and define a
3901 -- RACW, then calling stubs and specific stream attributes
3905 and then Is_Remote_Access_To_Class_Wide_Type (Def_Id)
3907 Add_RACW_Features (Def_Id);
3910 -- Set no strict aliasing flag if config pragma seen
3912 if Opt.No_Strict_Aliasing then
3913 Set_No_Strict_Aliasing (Base_Type (Def_Id));
3916 when N_Array_Type_Definition =>
3917 Array_Type_Declaration (T, Def);
3919 when N_Derived_Type_Definition =>
3920 Derived_Type_Declaration (T, N, T /= Def_Id);
3922 when N_Enumeration_Type_Definition =>
3923 Enumeration_Type_Declaration (T, Def);
3925 when N_Floating_Point_Definition =>
3926 Floating_Point_Type_Declaration (T, Def);
3928 when N_Decimal_Fixed_Point_Definition =>
3929 Decimal_Fixed_Point_Type_Declaration (T, Def);
3931 when N_Ordinary_Fixed_Point_Definition =>
3932 Ordinary_Fixed_Point_Type_Declaration (T, Def);
3934 when N_Signed_Integer_Type_Definition =>
3935 Signed_Integer_Type_Declaration (T, Def);
3937 when N_Modular_Type_Definition =>
3938 Modular_Type_Declaration (T, Def);
3940 when N_Record_Definition =>
3941 Record_Type_Declaration (T, N, Prev);
3944 raise Program_Error;
3949 if Etype (T) = Any_Type then
3953 -- Some common processing for all types
3955 Set_Depends_On_Private (T, Has_Private_Component (T));
3956 Check_Ops_From_Incomplete_Type;
3958 -- Both the declared entity, and its anonymous base type if one
3959 -- was created, need freeze nodes allocated.
3962 B : constant Entity_Id := Base_Type (T);
3965 -- In the case where the base type differs from the first subtype, we
3966 -- pre-allocate a freeze node, and set the proper link to the first
3967 -- subtype. Freeze_Entity will use this preallocated freeze node when
3968 -- it freezes the entity.
3971 Ensure_Freeze_Node (B);
3972 Set_First_Subtype_Link (Freeze_Node (B), T);
3975 if not From_With_Type (T) then
3976 Set_Has_Delayed_Freeze (T);
3980 -- Case of T is the full declaration of some private type which has
3981 -- been swapped in Defining_Identifier (N).
3983 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3984 Process_Full_View (N, T, Def_Id);
3986 -- Record the reference. The form of this is a little strange, since
3987 -- the full declaration has been swapped in. So the first parameter
3988 -- here represents the entity to which a reference is made which is
3989 -- the "real" entity, i.e. the one swapped in, and the second
3990 -- parameter provides the reference location.
3992 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3993 -- since we don't want a complaint about the full type being an
3994 -- unwanted reference to the private type
3997 B : constant Boolean := Has_Pragma_Unreferenced (T);
3999 Set_Has_Pragma_Unreferenced (T, False);
4000 Generate_Reference (T, T, 'c');
4001 Set_Has_Pragma_Unreferenced (T, B);
4004 Set_Completion_Referenced (Def_Id);
4006 -- For completion of incomplete type, process incomplete dependents
4007 -- and always mark the full type as referenced (it is the incomplete
4008 -- type that we get for any real reference).
4010 elsif Ekind (Prev) = E_Incomplete_Type then
4011 Process_Incomplete_Dependents (N, T, Prev);
4012 Generate_Reference (Prev, Def_Id, 'c');
4013 Set_Completion_Referenced (Def_Id);
4015 -- If not private type or incomplete type completion, this is a real
4016 -- definition of a new entity, so record it.
4019 Generate_Definition (Def_Id);
4022 if Chars (Scope (Def_Id)) = Name_System
4023 and then Chars (Def_Id) = Name_Address
4024 and then Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (N)))
4026 Set_Is_Descendent_Of_Address (Def_Id);
4027 Set_Is_Descendent_Of_Address (Base_Type (Def_Id));
4028 Set_Is_Descendent_Of_Address (Prev);
4031 Set_Optimize_Alignment_Flags (Def_Id);
4032 Check_Eliminated (Def_Id);
4033 end Analyze_Type_Declaration;
4035 --------------------------
4036 -- Analyze_Variant_Part --
4037 --------------------------
4039 procedure Analyze_Variant_Part (N : Node_Id) is
4041 procedure Non_Static_Choice_Error (Choice : Node_Id);
4042 -- Error routine invoked by the generic instantiation below when the
4043 -- variant part has a non static choice.
4045 procedure Process_Declarations (Variant : Node_Id);
4046 -- Analyzes all the declarations associated with a Variant. Needed by
4047 -- the generic instantiation below.
4049 package Variant_Choices_Processing is new
4050 Generic_Choices_Processing
4051 (Get_Alternatives => Variants,
4052 Get_Choices => Discrete_Choices,
4053 Process_Empty_Choice => No_OP,
4054 Process_Non_Static_Choice => Non_Static_Choice_Error,
4055 Process_Associated_Node => Process_Declarations);
4056 use Variant_Choices_Processing;
4057 -- Instantiation of the generic choice processing package
4059 -----------------------------
4060 -- Non_Static_Choice_Error --
4061 -----------------------------
4063 procedure Non_Static_Choice_Error (Choice : Node_Id) is
4065 Flag_Non_Static_Expr
4066 ("choice given in variant part is not static!", Choice);
4067 end Non_Static_Choice_Error;
4069 --------------------------
4070 -- Process_Declarations --
4071 --------------------------
4073 procedure Process_Declarations (Variant : Node_Id) is
4075 if not Null_Present (Component_List (Variant)) then
4076 Analyze_Declarations (Component_Items (Component_List (Variant)));
4078 if Present (Variant_Part (Component_List (Variant))) then
4079 Analyze (Variant_Part (Component_List (Variant)));
4082 end Process_Declarations;
4086 Discr_Name : Node_Id;
4087 Discr_Type : Entity_Id;
4089 Case_Table : Choice_Table_Type (1 .. Number_Of_Choices (N));
4091 Dont_Care : Boolean;
4092 Others_Present : Boolean := False;
4094 pragma Warnings (Off, Case_Table);
4095 pragma Warnings (Off, Last_Choice);
4096 pragma Warnings (Off, Dont_Care);
4097 pragma Warnings (Off, Others_Present);
4098 -- We don't care about the assigned values of any of these
4100 -- Start of processing for Analyze_Variant_Part
4103 Discr_Name := Name (N);
4104 Analyze (Discr_Name);
4106 -- If Discr_Name bad, get out (prevent cascaded errors)
4108 if Etype (Discr_Name) = Any_Type then
4112 -- Check invalid discriminant in variant part
4114 if Ekind (Entity (Discr_Name)) /= E_Discriminant then
4115 Error_Msg_N ("invalid discriminant name in variant part", Discr_Name);
4118 Discr_Type := Etype (Entity (Discr_Name));
4120 if not Is_Discrete_Type (Discr_Type) then
4122 ("discriminant in a variant part must be of a discrete type",
4127 -- Call the instantiated Analyze_Choices which does the rest of the work
4130 (N, Discr_Type, Case_Table, Last_Choice, Dont_Care, Others_Present);
4131 end Analyze_Variant_Part;
4133 ----------------------------
4134 -- Array_Type_Declaration --
4135 ----------------------------
4137 procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id) is
4138 Component_Def : constant Node_Id := Component_Definition (Def);
4139 Element_Type : Entity_Id;
4140 Implicit_Base : Entity_Id;
4142 Related_Id : Entity_Id := Empty;
4144 P : constant Node_Id := Parent (Def);
4148 if Nkind (Def) = N_Constrained_Array_Definition then
4149 Index := First (Discrete_Subtype_Definitions (Def));
4151 Index := First (Subtype_Marks (Def));
4154 -- Find proper names for the implicit types which may be public. In case
4155 -- of anonymous arrays we use the name of the first object of that type
4159 Related_Id := Defining_Identifier (P);
4165 while Present (Index) loop
4168 -- Add a subtype declaration for each index of private array type
4169 -- declaration whose etype is also private. For example:
4172 -- type Index is private;
4174 -- type Table is array (Index) of ...
4177 -- This is currently required by the expander for the internally
4178 -- generated equality subprogram of records with variant parts in
4179 -- which the etype of some component is such private type.
4181 if Ekind (Current_Scope) = E_Package
4182 and then In_Private_Part (Current_Scope)
4183 and then Has_Private_Declaration (Etype (Index))
4186 Loc : constant Source_Ptr := Sloc (Def);
4192 Make_Defining_Identifier (Loc,
4193 Chars => New_Internal_Name ('T'));
4194 Set_Is_Internal (New_E);
4197 Make_Subtype_Declaration (Loc,
4198 Defining_Identifier => New_E,
4199 Subtype_Indication =>
4200 New_Occurrence_Of (Etype (Index), Loc));
4202 Insert_Before (Parent (Def), Decl);
4204 Set_Etype (Index, New_E);
4206 -- If the index is a range the Entity attribute is not
4207 -- available. Example:
4210 -- type T is private;
4212 -- type T is new Natural;
4213 -- Table : array (T(1) .. T(10)) of Boolean;
4216 if Nkind (Index) /= N_Range then
4217 Set_Entity (Index, New_E);
4222 Make_Index (Index, P, Related_Id, Nb_Index);
4224 Nb_Index := Nb_Index + 1;
4227 -- Process subtype indication if one is present
4229 if Present (Subtype_Indication (Component_Def)) then
4232 (Subtype_Indication (Component_Def), P, Related_Id, 'C');
4234 -- Ada 2005 (AI-230): Access Definition case
4236 else pragma Assert (Present (Access_Definition (Component_Def)));
4238 -- Indicate that the anonymous access type is created by the
4239 -- array type declaration.
4241 Element_Type := Access_Definition
4243 N => Access_Definition (Component_Def));
4244 Set_Is_Local_Anonymous_Access (Element_Type);
4246 -- Propagate the parent. This field is needed if we have to generate
4247 -- the master_id associated with an anonymous access to task type
4248 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
4250 Set_Parent (Element_Type, Parent (T));
4252 -- Ada 2005 (AI-230): In case of components that are anonymous access
4253 -- types the level of accessibility depends on the enclosing type
4256 Set_Scope (Element_Type, Current_Scope); -- Ada 2005 (AI-230)
4258 -- Ada 2005 (AI-254)
4261 CD : constant Node_Id :=
4262 Access_To_Subprogram_Definition
4263 (Access_Definition (Component_Def));
4265 if Present (CD) and then Protected_Present (CD) then
4267 Replace_Anonymous_Access_To_Protected_Subprogram (Def);
4272 -- Constrained array case
4275 T := Create_Itype (E_Void, P, Related_Id, 'T');
4278 if Nkind (Def) = N_Constrained_Array_Definition then
4280 -- Establish Implicit_Base as unconstrained base type
4282 Implicit_Base := Create_Itype (E_Array_Type, P, Related_Id, 'B');
4284 Set_Etype (Implicit_Base, Implicit_Base);
4285 Set_Scope (Implicit_Base, Current_Scope);
4286 Set_Has_Delayed_Freeze (Implicit_Base);
4288 -- The constrained array type is a subtype of the unconstrained one
4290 Set_Ekind (T, E_Array_Subtype);
4291 Init_Size_Align (T);
4292 Set_Etype (T, Implicit_Base);
4293 Set_Scope (T, Current_Scope);
4294 Set_Is_Constrained (T, True);
4295 Set_First_Index (T, First (Discrete_Subtype_Definitions (Def)));
4296 Set_Has_Delayed_Freeze (T);
4298 -- Complete setup of implicit base type
4300 Set_First_Index (Implicit_Base, First_Index (T));
4301 Set_Component_Type (Implicit_Base, Element_Type);
4302 Set_Has_Task (Implicit_Base, Has_Task (Element_Type));
4303 Set_Component_Size (Implicit_Base, Uint_0);
4304 Set_Packed_Array_Type (Implicit_Base, Empty);
4305 Set_Has_Controlled_Component
4306 (Implicit_Base, Has_Controlled_Component
4308 or else Is_Controlled
4310 Set_Finalize_Storage_Only
4311 (Implicit_Base, Finalize_Storage_Only
4314 -- Unconstrained array case
4317 Set_Ekind (T, E_Array_Type);
4318 Init_Size_Align (T);
4320 Set_Scope (T, Current_Scope);
4321 Set_Component_Size (T, Uint_0);
4322 Set_Is_Constrained (T, False);
4323 Set_First_Index (T, First (Subtype_Marks (Def)));
4324 Set_Has_Delayed_Freeze (T, True);
4325 Set_Has_Task (T, Has_Task (Element_Type));
4326 Set_Has_Controlled_Component (T, Has_Controlled_Component
4329 Is_Controlled (Element_Type));
4330 Set_Finalize_Storage_Only (T, Finalize_Storage_Only
4334 -- Common attributes for both cases
4336 Set_Component_Type (Base_Type (T), Element_Type);
4337 Set_Packed_Array_Type (T, Empty);
4339 if Aliased_Present (Component_Definition (Def)) then
4340 Set_Has_Aliased_Components (Etype (T));
4343 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
4344 -- array type to ensure that objects of this type are initialized.
4346 if Ada_Version >= Ada_05
4347 and then Can_Never_Be_Null (Element_Type)
4349 Set_Can_Never_Be_Null (T);
4351 if Null_Exclusion_Present (Component_Definition (Def))
4353 -- No need to check itypes because in their case this check was
4354 -- done at their point of creation
4356 and then not Is_Itype (Element_Type)
4359 ("`NOT NULL` not allowed (null already excluded)",
4360 Subtype_Indication (Component_Definition (Def)));
4364 Priv := Private_Component (Element_Type);
4366 if Present (Priv) then
4368 -- Check for circular definitions
4370 if Priv = Any_Type then
4371 Set_Component_Type (Etype (T), Any_Type);
4373 -- There is a gap in the visibility of operations on the composite
4374 -- type only if the component type is defined in a different scope.
4376 elsif Scope (Priv) = Current_Scope then
4379 elsif Is_Limited_Type (Priv) then
4380 Set_Is_Limited_Composite (Etype (T));
4381 Set_Is_Limited_Composite (T);
4383 Set_Is_Private_Composite (Etype (T));
4384 Set_Is_Private_Composite (T);
4388 -- A syntax error in the declaration itself may lead to an empty index
4389 -- list, in which case do a minimal patch.
4391 if No (First_Index (T)) then
4392 Error_Msg_N ("missing index definition in array type declaration", T);
4395 Indices : constant List_Id :=
4396 New_List (New_Occurrence_Of (Any_Id, Sloc (T)));
4398 Set_Discrete_Subtype_Definitions (Def, Indices);
4399 Set_First_Index (T, First (Indices));
4404 -- Create a concatenation operator for the new type. Internal array
4405 -- types created for packed entities do not need such, they are
4406 -- compatible with the user-defined type.
4408 if Number_Dimensions (T) = 1
4409 and then not Is_Packed_Array_Type (T)
4411 New_Concatenation_Op (T);
4414 -- In the case of an unconstrained array the parser has already verified
4415 -- that all the indices are unconstrained but we still need to make sure
4416 -- that the element type is constrained.
4418 if Is_Indefinite_Subtype (Element_Type) then
4420 ("unconstrained element type in array declaration",
4421 Subtype_Indication (Component_Def));
4423 elsif Is_Abstract_Type (Element_Type) then
4425 ("the type of a component cannot be abstract",
4426 Subtype_Indication (Component_Def));
4428 end Array_Type_Declaration;
4430 ------------------------------------------------------
4431 -- Replace_Anonymous_Access_To_Protected_Subprogram --
4432 ------------------------------------------------------
4434 function Replace_Anonymous_Access_To_Protected_Subprogram
4435 (N : Node_Id) return Entity_Id
4437 Loc : constant Source_Ptr := Sloc (N);
4439 Curr_Scope : constant Scope_Stack_Entry :=
4440 Scope_Stack.Table (Scope_Stack.Last);
4442 Anon : constant Entity_Id :=
4443 Make_Defining_Identifier (Loc,
4444 Chars => New_Internal_Name ('S'));
4452 Set_Is_Internal (Anon);
4455 when N_Component_Declaration |
4456 N_Unconstrained_Array_Definition |
4457 N_Constrained_Array_Definition =>
4458 Comp := Component_Definition (N);
4459 Acc := Access_Definition (Comp);
4461 when N_Discriminant_Specification =>
4462 Comp := Discriminant_Type (N);
4465 when N_Parameter_Specification =>
4466 Comp := Parameter_Type (N);
4469 when N_Access_Function_Definition =>
4470 Comp := Result_Definition (N);
4473 when N_Object_Declaration =>
4474 Comp := Object_Definition (N);
4477 when N_Function_Specification =>
4478 Comp := Result_Definition (N);
4482 raise Program_Error;
4485 Decl := Make_Full_Type_Declaration (Loc,
4486 Defining_Identifier => Anon,
4488 Copy_Separate_Tree (Access_To_Subprogram_Definition (Acc)));
4490 Mark_Rewrite_Insertion (Decl);
4492 -- Insert the new declaration in the nearest enclosing scope. If the
4493 -- node is a body and N is its return type, the declaration belongs in
4494 -- the enclosing scope.
4498 if Nkind (P) = N_Subprogram_Body
4499 and then Nkind (N) = N_Function_Specification
4504 while Present (P) and then not Has_Declarations (P) loop
4508 pragma Assert (Present (P));
4510 if Nkind (P) = N_Package_Specification then
4511 Prepend (Decl, Visible_Declarations (P));
4513 Prepend (Decl, Declarations (P));
4516 -- Replace the anonymous type with an occurrence of the new declaration.
4517 -- In all cases the rewritten node does not have the null-exclusion
4518 -- attribute because (if present) it was already inherited by the
4519 -- anonymous entity (Anon). Thus, in case of components we do not
4520 -- inherit this attribute.
4522 if Nkind (N) = N_Parameter_Specification then
4523 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4524 Set_Etype (Defining_Identifier (N), Anon);
4525 Set_Null_Exclusion_Present (N, False);
4527 elsif Nkind (N) = N_Object_Declaration then
4528 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4529 Set_Etype (Defining_Identifier (N), Anon);
4531 elsif Nkind (N) = N_Access_Function_Definition then
4532 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4534 elsif Nkind (N) = N_Function_Specification then
4535 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4536 Set_Etype (Defining_Unit_Name (N), Anon);
4540 Make_Component_Definition (Loc,
4541 Subtype_Indication => New_Occurrence_Of (Anon, Loc)));
4544 Mark_Rewrite_Insertion (Comp);
4546 if Nkind_In (N, N_Object_Declaration, N_Access_Function_Definition) then
4550 -- Temporarily remove the current scope (record or subprogram) from
4551 -- the stack to add the new declarations to the enclosing scope.
4553 Scope_Stack.Decrement_Last;
4555 Set_Is_Itype (Anon);
4556 Scope_Stack.Append (Curr_Scope);
4559 Set_Ekind (Anon, E_Anonymous_Access_Protected_Subprogram_Type);
4560 Set_Can_Use_Internal_Rep (Anon, not Always_Compatible_Rep_On_Target);
4562 end Replace_Anonymous_Access_To_Protected_Subprogram;
4564 -------------------------------
4565 -- Build_Derived_Access_Type --
4566 -------------------------------
4568 procedure Build_Derived_Access_Type
4570 Parent_Type : Entity_Id;
4571 Derived_Type : Entity_Id)
4573 S : constant Node_Id := Subtype_Indication (Type_Definition (N));
4575 Desig_Type : Entity_Id;
4577 Discr_Con_Elist : Elist_Id;
4578 Discr_Con_El : Elmt_Id;
4582 -- Set the designated type so it is available in case this is an access
4583 -- to a self-referential type, e.g. a standard list type with a next
4584 -- pointer. Will be reset after subtype is built.
4586 Set_Directly_Designated_Type
4587 (Derived_Type, Designated_Type (Parent_Type));
4589 Subt := Process_Subtype (S, N);
4591 if Nkind (S) /= N_Subtype_Indication
4592 and then Subt /= Base_Type (Subt)
4594 Set_Ekind (Derived_Type, E_Access_Subtype);
4597 if Ekind (Derived_Type) = E_Access_Subtype then
4599 Pbase : constant Entity_Id := Base_Type (Parent_Type);
4600 Ibase : constant Entity_Id :=
4601 Create_Itype (Ekind (Pbase), N, Derived_Type, 'B');
4602 Svg_Chars : constant Name_Id := Chars (Ibase);
4603 Svg_Next_E : constant Entity_Id := Next_Entity (Ibase);
4606 Copy_Node (Pbase, Ibase);
4608 Set_Chars (Ibase, Svg_Chars);
4609 Set_Next_Entity (Ibase, Svg_Next_E);
4610 Set_Sloc (Ibase, Sloc (Derived_Type));
4611 Set_Scope (Ibase, Scope (Derived_Type));
4612 Set_Freeze_Node (Ibase, Empty);
4613 Set_Is_Frozen (Ibase, False);
4614 Set_Comes_From_Source (Ibase, False);
4615 Set_Is_First_Subtype (Ibase, False);
4617 Set_Etype (Ibase, Pbase);
4618 Set_Etype (Derived_Type, Ibase);
4622 Set_Directly_Designated_Type
4623 (Derived_Type, Designated_Type (Subt));
4625 Set_Is_Constrained (Derived_Type, Is_Constrained (Subt));
4626 Set_Is_Access_Constant (Derived_Type, Is_Access_Constant (Parent_Type));
4627 Set_Size_Info (Derived_Type, Parent_Type);
4628 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
4629 Set_Depends_On_Private (Derived_Type,
4630 Has_Private_Component (Derived_Type));
4631 Conditional_Delay (Derived_Type, Subt);
4633 -- Ada 2005 (AI-231): Set the null-exclusion attribute, and verify
4634 -- that it is not redundant.
4636 if Null_Exclusion_Present (Type_Definition (N)) then
4637 Set_Can_Never_Be_Null (Derived_Type);
4639 if Can_Never_Be_Null (Parent_Type)
4643 ("`NOT NULL` not allowed (& already excludes null)",
4647 elsif Can_Never_Be_Null (Parent_Type) then
4648 Set_Can_Never_Be_Null (Derived_Type);
4651 -- Note: we do not copy the Storage_Size_Variable, since we always go to
4652 -- the root type for this information.
4654 -- Apply range checks to discriminants for derived record case
4655 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
4657 Desig_Type := Designated_Type (Derived_Type);
4658 if Is_Composite_Type (Desig_Type)
4659 and then (not Is_Array_Type (Desig_Type))
4660 and then Has_Discriminants (Desig_Type)
4661 and then Base_Type (Desig_Type) /= Desig_Type
4663 Discr_Con_Elist := Discriminant_Constraint (Desig_Type);
4664 Discr_Con_El := First_Elmt (Discr_Con_Elist);
4666 Discr := First_Discriminant (Base_Type (Desig_Type));
4667 while Present (Discr_Con_El) loop
4668 Apply_Range_Check (Node (Discr_Con_El), Etype (Discr));
4669 Next_Elmt (Discr_Con_El);
4670 Next_Discriminant (Discr);
4673 end Build_Derived_Access_Type;
4675 ------------------------------
4676 -- Build_Derived_Array_Type --
4677 ------------------------------
4679 procedure Build_Derived_Array_Type
4681 Parent_Type : Entity_Id;
4682 Derived_Type : Entity_Id)
4684 Loc : constant Source_Ptr := Sloc (N);
4685 Tdef : constant Node_Id := Type_Definition (N);
4686 Indic : constant Node_Id := Subtype_Indication (Tdef);
4687 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
4688 Implicit_Base : Entity_Id;
4689 New_Indic : Node_Id;
4691 procedure Make_Implicit_Base;
4692 -- If the parent subtype is constrained, the derived type is a subtype
4693 -- of an implicit base type derived from the parent base.
4695 ------------------------
4696 -- Make_Implicit_Base --
4697 ------------------------
4699 procedure Make_Implicit_Base is
4702 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
4704 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
4705 Set_Etype (Implicit_Base, Parent_Base);
4707 Copy_Array_Subtype_Attributes (Implicit_Base, Parent_Base);
4708 Copy_Array_Base_Type_Attributes (Implicit_Base, Parent_Base);
4710 Set_Has_Delayed_Freeze (Implicit_Base, True);
4711 end Make_Implicit_Base;
4713 -- Start of processing for Build_Derived_Array_Type
4716 if not Is_Constrained (Parent_Type) then
4717 if Nkind (Indic) /= N_Subtype_Indication then
4718 Set_Ekind (Derived_Type, E_Array_Type);
4720 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4721 Copy_Array_Base_Type_Attributes (Derived_Type, Parent_Type);
4723 Set_Has_Delayed_Freeze (Derived_Type, True);
4727 Set_Etype (Derived_Type, Implicit_Base);
4730 Make_Subtype_Declaration (Loc,
4731 Defining_Identifier => Derived_Type,
4732 Subtype_Indication =>
4733 Make_Subtype_Indication (Loc,
4734 Subtype_Mark => New_Reference_To (Implicit_Base, Loc),
4735 Constraint => Constraint (Indic)));
4737 Rewrite (N, New_Indic);
4742 if Nkind (Indic) /= N_Subtype_Indication then
4745 Set_Ekind (Derived_Type, Ekind (Parent_Type));
4746 Set_Etype (Derived_Type, Implicit_Base);
4747 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4750 Error_Msg_N ("illegal constraint on constrained type", Indic);
4754 -- If parent type is not a derived type itself, and is declared in
4755 -- closed scope (e.g. a subprogram), then we must explicitly introduce
4756 -- the new type's concatenation operator since Derive_Subprograms
4757 -- will not inherit the parent's operator. If the parent type is
4758 -- unconstrained, the operator is of the unconstrained base type.
4760 if Number_Dimensions (Parent_Type) = 1
4761 and then not Is_Limited_Type (Parent_Type)
4762 and then not Is_Derived_Type (Parent_Type)
4763 and then not Is_Package_Or_Generic_Package
4764 (Scope (Base_Type (Parent_Type)))
4766 if not Is_Constrained (Parent_Type)
4767 and then Is_Constrained (Derived_Type)
4769 New_Concatenation_Op (Implicit_Base);
4771 New_Concatenation_Op (Derived_Type);
4774 end Build_Derived_Array_Type;
4776 -----------------------------------
4777 -- Build_Derived_Concurrent_Type --
4778 -----------------------------------
4780 procedure Build_Derived_Concurrent_Type
4782 Parent_Type : Entity_Id;
4783 Derived_Type : Entity_Id)
4785 D_Constraint : Node_Id;
4786 Disc_Spec : Node_Id;
4787 Old_Disc : Entity_Id;
4788 New_Disc : Entity_Id;
4790 Constraint_Present : constant Boolean :=
4791 Nkind (Subtype_Indication (Type_Definition (N)))
4792 = N_Subtype_Indication;
4795 Set_Stored_Constraint (Derived_Type, No_Elist);
4797 -- Copy Storage_Size and Relative_Deadline variables if task case
4799 if Is_Task_Type (Parent_Type) then
4800 Set_Storage_Size_Variable (Derived_Type,
4801 Storage_Size_Variable (Parent_Type));
4802 Set_Relative_Deadline_Variable (Derived_Type,
4803 Relative_Deadline_Variable (Parent_Type));
4806 if Present (Discriminant_Specifications (N)) then
4807 Push_Scope (Derived_Type);
4808 Check_Or_Process_Discriminants (N, Derived_Type);
4811 elsif Constraint_Present then
4813 -- Build constrained subtype and derive from it
4816 Loc : constant Source_Ptr := Sloc (N);
4817 Anon : constant Entity_Id :=
4818 Make_Defining_Identifier (Loc,
4819 New_External_Name (Chars (Derived_Type), 'T'));
4824 Make_Subtype_Declaration (Loc,
4825 Defining_Identifier => Anon,
4826 Subtype_Indication =>
4827 Subtype_Indication (Type_Definition (N)));
4828 Insert_Before (N, Decl);
4831 Rewrite (Subtype_Indication (Type_Definition (N)),
4832 New_Occurrence_Of (Anon, Loc));
4833 Set_Analyzed (Derived_Type, False);
4839 -- All attributes are inherited from parent. In particular,
4840 -- entries and the corresponding record type are the same.
4841 -- Discriminants may be renamed, and must be treated separately.
4843 Set_Has_Discriminants
4844 (Derived_Type, Has_Discriminants (Parent_Type));
4845 Set_Corresponding_Record_Type
4846 (Derived_Type, Corresponding_Record_Type (Parent_Type));
4848 -- Is_Constrained is set according the parent subtype, but is set to
4849 -- False if the derived type is declared with new discriminants.
4853 (Is_Constrained (Parent_Type) or else Constraint_Present)
4854 and then not Present (Discriminant_Specifications (N)));
4856 if Constraint_Present then
4857 if not Has_Discriminants (Parent_Type) then
4858 Error_Msg_N ("untagged parent must have discriminants", N);
4860 elsif Present (Discriminant_Specifications (N)) then
4862 -- Verify that new discriminants are used to constrain old ones
4867 (Constraint (Subtype_Indication (Type_Definition (N)))));
4869 Old_Disc := First_Discriminant (Parent_Type);
4870 New_Disc := First_Discriminant (Derived_Type);
4871 Disc_Spec := First (Discriminant_Specifications (N));
4872 while Present (Old_Disc) and then Present (Disc_Spec) loop
4873 if Nkind (Discriminant_Type (Disc_Spec)) /=
4876 Analyze (Discriminant_Type (Disc_Spec));
4878 if not Subtypes_Statically_Compatible (
4879 Etype (Discriminant_Type (Disc_Spec)),
4883 ("not statically compatible with parent discriminant",
4884 Discriminant_Type (Disc_Spec));
4888 if Nkind (D_Constraint) = N_Identifier
4889 and then Chars (D_Constraint) /=
4890 Chars (Defining_Identifier (Disc_Spec))
4892 Error_Msg_N ("new discriminants must constrain old ones",
4895 Set_Corresponding_Discriminant (New_Disc, Old_Disc);
4898 Next_Discriminant (Old_Disc);
4899 Next_Discriminant (New_Disc);
4903 if Present (Old_Disc) or else Present (Disc_Spec) then
4904 Error_Msg_N ("discriminant mismatch in derivation", N);
4909 elsif Present (Discriminant_Specifications (N)) then
4911 ("missing discriminant constraint in untagged derivation",
4915 if Present (Discriminant_Specifications (N)) then
4916 Old_Disc := First_Discriminant (Parent_Type);
4917 while Present (Old_Disc) loop
4919 if No (Next_Entity (Old_Disc))
4920 or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant
4922 Set_Next_Entity (Last_Entity (Derived_Type),
4923 Next_Entity (Old_Disc));
4927 Next_Discriminant (Old_Disc);
4931 Set_First_Entity (Derived_Type, First_Entity (Parent_Type));
4932 if Has_Discriminants (Parent_Type) then
4933 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
4934 Set_Discriminant_Constraint (
4935 Derived_Type, Discriminant_Constraint (Parent_Type));
4939 Set_Last_Entity (Derived_Type, Last_Entity (Parent_Type));
4941 Set_Has_Completion (Derived_Type);
4942 end Build_Derived_Concurrent_Type;
4944 ------------------------------------
4945 -- Build_Derived_Enumeration_Type --
4946 ------------------------------------
4948 procedure Build_Derived_Enumeration_Type
4950 Parent_Type : Entity_Id;
4951 Derived_Type : Entity_Id)
4953 Loc : constant Source_Ptr := Sloc (N);
4954 Def : constant Node_Id := Type_Definition (N);
4955 Indic : constant Node_Id := Subtype_Indication (Def);
4956 Implicit_Base : Entity_Id;
4957 Literal : Entity_Id;
4958 New_Lit : Entity_Id;
4959 Literals_List : List_Id;
4960 Type_Decl : Node_Id;
4962 Rang_Expr : Node_Id;
4965 -- Since types Standard.Character and Standard.Wide_Character do
4966 -- not have explicit literals lists we need to process types derived
4967 -- from them specially. This is handled by Derived_Standard_Character.
4968 -- If the parent type is a generic type, there are no literals either,
4969 -- and we construct the same skeletal representation as for the generic
4972 if Is_Standard_Character_Type (Parent_Type) then
4973 Derived_Standard_Character (N, Parent_Type, Derived_Type);
4975 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
4982 Make_Attribute_Reference (Loc,
4983 Attribute_Name => Name_First,
4984 Prefix => New_Reference_To (Derived_Type, Loc));
4985 Set_Etype (Lo, Derived_Type);
4988 Make_Attribute_Reference (Loc,
4989 Attribute_Name => Name_Last,
4990 Prefix => New_Reference_To (Derived_Type, Loc));
4991 Set_Etype (Hi, Derived_Type);
4993 Set_Scalar_Range (Derived_Type,
5000 -- If a constraint is present, analyze the bounds to catch
5001 -- premature usage of the derived literals.
5003 if Nkind (Indic) = N_Subtype_Indication
5004 and then Nkind (Range_Expression (Constraint (Indic))) = N_Range
5006 Analyze (Low_Bound (Range_Expression (Constraint (Indic))));
5007 Analyze (High_Bound (Range_Expression (Constraint (Indic))));
5010 -- Introduce an implicit base type for the derived type even if there
5011 -- is no constraint attached to it, since this seems closer to the
5012 -- Ada semantics. Build a full type declaration tree for the derived
5013 -- type using the implicit base type as the defining identifier. The
5014 -- build a subtype declaration tree which applies the constraint (if
5015 -- any) have it replace the derived type declaration.
5017 Literal := First_Literal (Parent_Type);
5018 Literals_List := New_List;
5019 while Present (Literal)
5020 and then Ekind (Literal) = E_Enumeration_Literal
5022 -- Literals of the derived type have the same representation as
5023 -- those of the parent type, but this representation can be
5024 -- overridden by an explicit representation clause. Indicate
5025 -- that there is no explicit representation given yet. These
5026 -- derived literals are implicit operations of the new type,
5027 -- and can be overridden by explicit ones.
5029 if Nkind (Literal) = N_Defining_Character_Literal then
5031 Make_Defining_Character_Literal (Loc, Chars (Literal));
5033 New_Lit := Make_Defining_Identifier (Loc, Chars (Literal));
5036 Set_Ekind (New_Lit, E_Enumeration_Literal);
5037 Set_Enumeration_Pos (New_Lit, Enumeration_Pos (Literal));
5038 Set_Enumeration_Rep (New_Lit, Enumeration_Rep (Literal));
5039 Set_Enumeration_Rep_Expr (New_Lit, Empty);
5040 Set_Alias (New_Lit, Literal);
5041 Set_Is_Known_Valid (New_Lit, True);
5043 Append (New_Lit, Literals_List);
5044 Next_Literal (Literal);
5048 Make_Defining_Identifier (Sloc (Derived_Type),
5049 New_External_Name (Chars (Derived_Type), 'B'));
5051 -- Indicate the proper nature of the derived type. This must be done
5052 -- before analysis of the literals, to recognize cases when a literal
5053 -- may be hidden by a previous explicit function definition (cf.
5056 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
5057 Set_Etype (Derived_Type, Implicit_Base);
5060 Make_Full_Type_Declaration (Loc,
5061 Defining_Identifier => Implicit_Base,
5062 Discriminant_Specifications => No_List,
5064 Make_Enumeration_Type_Definition (Loc, Literals_List));
5066 Mark_Rewrite_Insertion (Type_Decl);
5067 Insert_Before (N, Type_Decl);
5068 Analyze (Type_Decl);
5070 -- After the implicit base is analyzed its Etype needs to be changed
5071 -- to reflect the fact that it is derived from the parent type which
5072 -- was ignored during analysis. We also set the size at this point.
5074 Set_Etype (Implicit_Base, Parent_Type);
5076 Set_Size_Info (Implicit_Base, Parent_Type);
5077 Set_RM_Size (Implicit_Base, RM_Size (Parent_Type));
5078 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Type));
5080 Set_Has_Non_Standard_Rep
5081 (Implicit_Base, Has_Non_Standard_Rep
5083 Set_Has_Delayed_Freeze (Implicit_Base);
5085 -- Process the subtype indication including a validation check on the
5086 -- constraint, if any. If a constraint is given, its bounds must be
5087 -- implicitly converted to the new type.
5089 if Nkind (Indic) = N_Subtype_Indication then
5091 R : constant Node_Id :=
5092 Range_Expression (Constraint (Indic));
5095 if Nkind (R) = N_Range then
5096 Hi := Build_Scalar_Bound
5097 (High_Bound (R), Parent_Type, Implicit_Base);
5098 Lo := Build_Scalar_Bound
5099 (Low_Bound (R), Parent_Type, Implicit_Base);
5102 -- Constraint is a Range attribute. Replace with explicit
5103 -- mention of the bounds of the prefix, which must be a
5106 Analyze (Prefix (R));
5108 Convert_To (Implicit_Base,
5109 Make_Attribute_Reference (Loc,
5110 Attribute_Name => Name_Last,
5112 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5115 Convert_To (Implicit_Base,
5116 Make_Attribute_Reference (Loc,
5117 Attribute_Name => Name_First,
5119 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5126 (Type_High_Bound (Parent_Type),
5127 Parent_Type, Implicit_Base);
5130 (Type_Low_Bound (Parent_Type),
5131 Parent_Type, Implicit_Base);
5139 -- If we constructed a default range for the case where no range
5140 -- was given, then the expressions in the range must not freeze
5141 -- since they do not correspond to expressions in the source.
5143 if Nkind (Indic) /= N_Subtype_Indication then
5144 Set_Must_Not_Freeze (Lo);
5145 Set_Must_Not_Freeze (Hi);
5146 Set_Must_Not_Freeze (Rang_Expr);
5150 Make_Subtype_Declaration (Loc,
5151 Defining_Identifier => Derived_Type,
5152 Subtype_Indication =>
5153 Make_Subtype_Indication (Loc,
5154 Subtype_Mark => New_Occurrence_Of (Implicit_Base, Loc),
5156 Make_Range_Constraint (Loc,
5157 Range_Expression => Rang_Expr))));
5161 -- If pragma Discard_Names applies on the first subtype of the parent
5162 -- type, then it must be applied on this subtype as well.
5164 if Einfo.Discard_Names (First_Subtype (Parent_Type)) then
5165 Set_Discard_Names (Derived_Type);
5168 -- Apply a range check. Since this range expression doesn't have an
5169 -- Etype, we have to specifically pass the Source_Typ parameter. Is
5172 if Nkind (Indic) = N_Subtype_Indication then
5173 Apply_Range_Check (Range_Expression (Constraint (Indic)),
5175 Source_Typ => Entity (Subtype_Mark (Indic)));
5178 end Build_Derived_Enumeration_Type;
5180 --------------------------------
5181 -- Build_Derived_Numeric_Type --
5182 --------------------------------
5184 procedure Build_Derived_Numeric_Type
5186 Parent_Type : Entity_Id;
5187 Derived_Type : Entity_Id)
5189 Loc : constant Source_Ptr := Sloc (N);
5190 Tdef : constant Node_Id := Type_Definition (N);
5191 Indic : constant Node_Id := Subtype_Indication (Tdef);
5192 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
5193 No_Constraint : constant Boolean := Nkind (Indic) /=
5194 N_Subtype_Indication;
5195 Implicit_Base : Entity_Id;
5201 -- Process the subtype indication including a validation check on
5202 -- the constraint if any.
5204 Discard_Node (Process_Subtype (Indic, N));
5206 -- Introduce an implicit base type for the derived type even if there
5207 -- is no constraint attached to it, since this seems closer to the Ada
5211 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
5213 Set_Etype (Implicit_Base, Parent_Base);
5214 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
5215 Set_Size_Info (Implicit_Base, Parent_Base);
5216 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Base));
5217 Set_Parent (Implicit_Base, Parent (Derived_Type));
5219 -- Set RM Size for discrete type or decimal fixed-point type
5220 -- Ordinary fixed-point is excluded, why???
5222 if Is_Discrete_Type (Parent_Base)
5223 or else Is_Decimal_Fixed_Point_Type (Parent_Base)
5225 Set_RM_Size (Implicit_Base, RM_Size (Parent_Base));
5228 Set_Has_Delayed_Freeze (Implicit_Base);
5230 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
5231 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
5233 Set_Scalar_Range (Implicit_Base,
5238 if Has_Infinities (Parent_Base) then
5239 Set_Includes_Infinities (Scalar_Range (Implicit_Base));
5242 -- The Derived_Type, which is the entity of the declaration, is a
5243 -- subtype of the implicit base. Its Ekind is a subtype, even in the
5244 -- absence of an explicit constraint.
5246 Set_Etype (Derived_Type, Implicit_Base);
5248 -- If we did not have a constraint, then the Ekind is set from the
5249 -- parent type (otherwise Process_Subtype has set the bounds)
5251 if No_Constraint then
5252 Set_Ekind (Derived_Type, Subtype_Kind (Ekind (Parent_Type)));
5255 -- If we did not have a range constraint, then set the range from the
5256 -- parent type. Otherwise, the call to Process_Subtype has set the
5260 or else not Has_Range_Constraint (Indic)
5262 Set_Scalar_Range (Derived_Type,
5264 Low_Bound => New_Copy_Tree (Type_Low_Bound (Parent_Type)),
5265 High_Bound => New_Copy_Tree (Type_High_Bound (Parent_Type))));
5266 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5268 if Has_Infinities (Parent_Type) then
5269 Set_Includes_Infinities (Scalar_Range (Derived_Type));
5273 Set_Is_Descendent_Of_Address (Derived_Type,
5274 Is_Descendent_Of_Address (Parent_Type));
5275 Set_Is_Descendent_Of_Address (Implicit_Base,
5276 Is_Descendent_Of_Address (Parent_Type));
5278 -- Set remaining type-specific fields, depending on numeric type
5280 if Is_Modular_Integer_Type (Parent_Type) then
5281 Set_Modulus (Implicit_Base, Modulus (Parent_Base));
5283 Set_Non_Binary_Modulus
5284 (Implicit_Base, Non_Binary_Modulus (Parent_Base));
5286 elsif Is_Floating_Point_Type (Parent_Type) then
5288 -- Digits of base type is always copied from the digits value of
5289 -- the parent base type, but the digits of the derived type will
5290 -- already have been set if there was a constraint present.
5292 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5293 Set_Vax_Float (Implicit_Base, Vax_Float (Parent_Base));
5295 if No_Constraint then
5296 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Type));
5299 elsif Is_Fixed_Point_Type (Parent_Type) then
5301 -- Small of base type and derived type are always copied from the
5302 -- parent base type, since smalls never change. The delta of the
5303 -- base type is also copied from the parent base type. However the
5304 -- delta of the derived type will have been set already if a
5305 -- constraint was present.
5307 Set_Small_Value (Derived_Type, Small_Value (Parent_Base));
5308 Set_Small_Value (Implicit_Base, Small_Value (Parent_Base));
5309 Set_Delta_Value (Implicit_Base, Delta_Value (Parent_Base));
5311 if No_Constraint then
5312 Set_Delta_Value (Derived_Type, Delta_Value (Parent_Type));
5315 -- The scale and machine radix in the decimal case are always
5316 -- copied from the parent base type.
5318 if Is_Decimal_Fixed_Point_Type (Parent_Type) then
5319 Set_Scale_Value (Derived_Type, Scale_Value (Parent_Base));
5320 Set_Scale_Value (Implicit_Base, Scale_Value (Parent_Base));
5322 Set_Machine_Radix_10
5323 (Derived_Type, Machine_Radix_10 (Parent_Base));
5324 Set_Machine_Radix_10
5325 (Implicit_Base, Machine_Radix_10 (Parent_Base));
5327 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5329 if No_Constraint then
5330 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Base));
5333 -- the analysis of the subtype_indication sets the
5334 -- digits value of the derived type.
5341 -- The type of the bounds is that of the parent type, and they
5342 -- must be converted to the derived type.
5344 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
5346 -- The implicit_base should be frozen when the derived type is frozen,
5347 -- but note that it is used in the conversions of the bounds. For fixed
5348 -- types we delay the determination of the bounds until the proper
5349 -- freezing point. For other numeric types this is rejected by GCC, for
5350 -- reasons that are currently unclear (???), so we choose to freeze the
5351 -- implicit base now. In the case of integers and floating point types
5352 -- this is harmless because subsequent representation clauses cannot
5353 -- affect anything, but it is still baffling that we cannot use the
5354 -- same mechanism for all derived numeric types.
5356 -- There is a further complication: actually *some* representation
5357 -- clauses can affect the implicit base type. Namely, attribute
5358 -- definition clauses for stream-oriented attributes need to set the
5359 -- corresponding TSS entries on the base type, and this normally cannot
5360 -- be done after the base type is frozen, so the circuitry in
5361 -- Sem_Ch13.New_Stream_Subprogram must account for this possibility and
5362 -- not use Set_TSS in this case.
5364 if Is_Fixed_Point_Type (Parent_Type) then
5365 Conditional_Delay (Implicit_Base, Parent_Type);
5367 Freeze_Before (N, Implicit_Base);
5369 end Build_Derived_Numeric_Type;
5371 --------------------------------
5372 -- Build_Derived_Private_Type --
5373 --------------------------------
5375 procedure Build_Derived_Private_Type
5377 Parent_Type : Entity_Id;
5378 Derived_Type : Entity_Id;
5379 Is_Completion : Boolean;
5380 Derive_Subps : Boolean := True)
5382 Der_Base : Entity_Id;
5384 Full_Decl : Node_Id := Empty;
5385 Full_Der : Entity_Id;
5387 Last_Discr : Entity_Id;
5388 Par_Scope : constant Entity_Id := Scope (Base_Type (Parent_Type));
5389 Swapped : Boolean := False;
5391 procedure Copy_And_Build;
5392 -- Copy derived type declaration, replace parent with its full view,
5393 -- and analyze new declaration.
5395 --------------------
5396 -- Copy_And_Build --
5397 --------------------
5399 procedure Copy_And_Build is
5403 if Ekind (Parent_Type) in Record_Kind
5405 (Ekind (Parent_Type) in Enumeration_Kind
5406 and then not Is_Standard_Character_Type (Parent_Type)
5407 and then not Is_Generic_Type (Root_Type (Parent_Type)))
5409 Full_N := New_Copy_Tree (N);
5410 Insert_After (N, Full_N);
5411 Build_Derived_Type (
5412 Full_N, Parent_Type, Full_Der, True, Derive_Subps => False);
5415 Build_Derived_Type (
5416 N, Parent_Type, Full_Der, True, Derive_Subps => False);
5420 -- Start of processing for Build_Derived_Private_Type
5423 if Is_Tagged_Type (Parent_Type) then
5424 Build_Derived_Record_Type
5425 (N, Parent_Type, Derived_Type, Derive_Subps);
5428 elsif Has_Discriminants (Parent_Type) then
5429 if Present (Full_View (Parent_Type)) then
5430 if not Is_Completion then
5432 -- Copy declaration for subsequent analysis, to provide a
5433 -- completion for what is a private declaration. Indicate that
5434 -- the full type is internally generated.
5436 Full_Decl := New_Copy_Tree (N);
5437 Full_Der := New_Copy (Derived_Type);
5438 Set_Comes_From_Source (Full_Decl, False);
5439 Set_Comes_From_Source (Full_Der, False);
5441 Insert_After (N, Full_Decl);
5444 -- If this is a completion, the full view being built is
5445 -- itself private. We build a subtype of the parent with
5446 -- the same constraints as this full view, to convey to the
5447 -- back end the constrained components and the size of this
5448 -- subtype. If the parent is constrained, its full view can
5449 -- serve as the underlying full view of the derived type.
5451 if No (Discriminant_Specifications (N)) then
5452 if Nkind (Subtype_Indication (Type_Definition (N))) =
5453 N_Subtype_Indication
5455 Build_Underlying_Full_View (N, Derived_Type, Parent_Type);
5457 elsif Is_Constrained (Full_View (Parent_Type)) then
5458 Set_Underlying_Full_View (Derived_Type,
5459 Full_View (Parent_Type));
5463 -- If there are new discriminants, the parent subtype is
5464 -- constrained by them, but it is not clear how to build
5465 -- the underlying_full_view in this case ???
5472 -- Build partial view of derived type from partial view of parent
5474 Build_Derived_Record_Type
5475 (N, Parent_Type, Derived_Type, Derive_Subps);
5477 if Present (Full_View (Parent_Type))
5478 and then not Is_Completion
5480 if not In_Open_Scopes (Par_Scope)
5481 or else not In_Same_Source_Unit (N, Parent_Type)
5483 -- Swap partial and full views temporarily
5485 Install_Private_Declarations (Par_Scope);
5486 Install_Visible_Declarations (Par_Scope);
5490 -- Build full view of derived type from full view of parent which
5491 -- is now installed. Subprograms have been derived on the partial
5492 -- view, the completion does not derive them anew.
5494 if not Is_Tagged_Type (Parent_Type) then
5496 -- If the parent is itself derived from another private type,
5497 -- installing the private declarations has not affected its
5498 -- privacy status, so use its own full view explicitly.
5500 if Is_Private_Type (Parent_Type) then
5501 Build_Derived_Record_Type
5502 (Full_Decl, Full_View (Parent_Type), Full_Der, False);
5504 Build_Derived_Record_Type
5505 (Full_Decl, Parent_Type, Full_Der, False);
5509 -- If full view of parent is tagged, the completion
5510 -- inherits the proper primitive operations.
5512 Set_Defining_Identifier (Full_Decl, Full_Der);
5513 Build_Derived_Record_Type
5514 (Full_Decl, Parent_Type, Full_Der, Derive_Subps);
5515 Set_Analyzed (Full_Decl);
5519 Uninstall_Declarations (Par_Scope);
5521 if In_Open_Scopes (Par_Scope) then
5522 Install_Visible_Declarations (Par_Scope);
5526 Der_Base := Base_Type (Derived_Type);
5527 Set_Full_View (Derived_Type, Full_Der);
5528 Set_Full_View (Der_Base, Base_Type (Full_Der));
5530 -- Copy the discriminant list from full view to the partial views
5531 -- (base type and its subtype). Gigi requires that the partial
5532 -- and full views have the same discriminants.
5534 -- Note that since the partial view is pointing to discriminants
5535 -- in the full view, their scope will be that of the full view.
5536 -- This might cause some front end problems and need
5539 Discr := First_Discriminant (Base_Type (Full_Der));
5540 Set_First_Entity (Der_Base, Discr);
5543 Last_Discr := Discr;
5544 Next_Discriminant (Discr);
5545 exit when No (Discr);
5548 Set_Last_Entity (Der_Base, Last_Discr);
5550 Set_First_Entity (Derived_Type, First_Entity (Der_Base));
5551 Set_Last_Entity (Derived_Type, Last_Entity (Der_Base));
5552 Set_Stored_Constraint (Full_Der, Stored_Constraint (Derived_Type));
5555 -- If this is a completion, the derived type stays private
5556 -- and there is no need to create a further full view, except
5557 -- in the unusual case when the derivation is nested within a
5558 -- child unit, see below.
5563 elsif Present (Full_View (Parent_Type))
5564 and then Has_Discriminants (Full_View (Parent_Type))
5566 if Has_Unknown_Discriminants (Parent_Type)
5567 and then Nkind (Subtype_Indication (Type_Definition (N))) =
5568 N_Subtype_Indication
5571 ("cannot constrain type with unknown discriminants",
5572 Subtype_Indication (Type_Definition (N)));
5576 -- If full view of parent is a record type, Build full view as
5577 -- a derivation from the parent's full view. Partial view remains
5578 -- private. For code generation and linking, the full view must
5579 -- have the same public status as the partial one. This full view
5580 -- is only needed if the parent type is in an enclosing scope, so
5581 -- that the full view may actually become visible, e.g. in a child
5582 -- unit. This is both more efficient, and avoids order of freezing
5583 -- problems with the added entities.
5585 if not Is_Private_Type (Full_View (Parent_Type))
5586 and then (In_Open_Scopes (Scope (Parent_Type)))
5588 Full_Der := Make_Defining_Identifier (Sloc (Derived_Type),
5589 Chars (Derived_Type));
5590 Set_Is_Itype (Full_Der);
5591 Set_Has_Private_Declaration (Full_Der);
5592 Set_Has_Private_Declaration (Derived_Type);
5593 Set_Associated_Node_For_Itype (Full_Der, N);
5594 Set_Parent (Full_Der, Parent (Derived_Type));
5595 Set_Full_View (Derived_Type, Full_Der);
5596 Set_Is_Public (Full_Der, Is_Public (Derived_Type));
5597 Full_P := Full_View (Parent_Type);
5598 Exchange_Declarations (Parent_Type);
5600 Exchange_Declarations (Full_P);
5603 Build_Derived_Record_Type
5604 (N, Full_View (Parent_Type), Derived_Type,
5605 Derive_Subps => False);
5608 -- In any case, the primitive operations are inherited from
5609 -- the parent type, not from the internal full view.
5611 Set_Etype (Base_Type (Derived_Type), Base_Type (Parent_Type));
5613 if Derive_Subps then
5614 Derive_Subprograms (Parent_Type, Derived_Type);
5618 -- Untagged type, No discriminants on either view
5620 if Nkind (Subtype_Indication (Type_Definition (N))) =
5621 N_Subtype_Indication
5624 ("illegal constraint on type without discriminants", N);
5627 if Present (Discriminant_Specifications (N))
5628 and then Present (Full_View (Parent_Type))
5629 and then not Is_Tagged_Type (Full_View (Parent_Type))
5632 ("cannot add discriminants to untagged type", N);
5635 Set_Stored_Constraint (Derived_Type, No_Elist);
5636 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5637 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
5638 Set_Has_Controlled_Component
5639 (Derived_Type, Has_Controlled_Component
5642 -- Direct controlled types do not inherit Finalize_Storage_Only flag
5644 if not Is_Controlled (Parent_Type) then
5645 Set_Finalize_Storage_Only
5646 (Base_Type (Derived_Type), Finalize_Storage_Only (Parent_Type));
5649 -- Construct the implicit full view by deriving from full view of
5650 -- the parent type. In order to get proper visibility, we install
5651 -- the parent scope and its declarations.
5653 -- ??? if the parent is untagged private and its completion is
5654 -- tagged, this mechanism will not work because we cannot derive
5655 -- from the tagged full view unless we have an extension
5657 if Present (Full_View (Parent_Type))
5658 and then not Is_Tagged_Type (Full_View (Parent_Type))
5659 and then not Is_Completion
5662 Make_Defining_Identifier (Sloc (Derived_Type),
5663 Chars => Chars (Derived_Type));
5664 Set_Is_Itype (Full_Der);
5665 Set_Has_Private_Declaration (Full_Der);
5666 Set_Has_Private_Declaration (Derived_Type);
5667 Set_Associated_Node_For_Itype (Full_Der, N);
5668 Set_Parent (Full_Der, Parent (Derived_Type));
5669 Set_Full_View (Derived_Type, Full_Der);
5671 if not In_Open_Scopes (Par_Scope) then
5672 Install_Private_Declarations (Par_Scope);
5673 Install_Visible_Declarations (Par_Scope);
5675 Uninstall_Declarations (Par_Scope);
5677 -- If parent scope is open and in another unit, and parent has a
5678 -- completion, then the derivation is taking place in the visible
5679 -- part of a child unit. In that case retrieve the full view of
5680 -- the parent momentarily.
5682 elsif not In_Same_Source_Unit (N, Parent_Type) then
5683 Full_P := Full_View (Parent_Type);
5684 Exchange_Declarations (Parent_Type);
5686 Exchange_Declarations (Full_P);
5688 -- Otherwise it is a local derivation
5694 Set_Scope (Full_Der, Current_Scope);
5695 Set_Is_First_Subtype (Full_Der,
5696 Is_First_Subtype (Derived_Type));
5697 Set_Has_Size_Clause (Full_Der, False);
5698 Set_Has_Alignment_Clause (Full_Der, False);
5699 Set_Next_Entity (Full_Der, Empty);
5700 Set_Has_Delayed_Freeze (Full_Der);
5701 Set_Is_Frozen (Full_Der, False);
5702 Set_Freeze_Node (Full_Der, Empty);
5703 Set_Depends_On_Private (Full_Der,
5704 Has_Private_Component (Full_Der));
5705 Set_Public_Status (Full_Der);
5709 Set_Has_Unknown_Discriminants (Derived_Type,
5710 Has_Unknown_Discriminants (Parent_Type));
5712 if Is_Private_Type (Derived_Type) then
5713 Set_Private_Dependents (Derived_Type, New_Elmt_List);
5716 if Is_Private_Type (Parent_Type)
5717 and then Base_Type (Parent_Type) = Parent_Type
5718 and then In_Open_Scopes (Scope (Parent_Type))
5720 Append_Elmt (Derived_Type, Private_Dependents (Parent_Type));
5722 if Is_Child_Unit (Scope (Current_Scope))
5723 and then Is_Completion
5724 and then In_Private_Part (Current_Scope)
5725 and then Scope (Parent_Type) /= Current_Scope
5727 -- This is the unusual case where a type completed by a private
5728 -- derivation occurs within a package nested in a child unit,
5729 -- and the parent is declared in an ancestor. In this case, the
5730 -- full view of the parent type will become visible in the body
5731 -- of the enclosing child, and only then will the current type
5732 -- be possibly non-private. We build a underlying full view that
5733 -- will be installed when the enclosing child body is compiled.
5736 Make_Defining_Identifier (Sloc (Derived_Type),
5737 Chars => Chars (Derived_Type));
5738 Set_Is_Itype (Full_Der);
5739 Build_Itype_Reference (Full_Der, N);
5741 -- The full view will be used to swap entities on entry/exit to
5742 -- the body, and must appear in the entity list for the package.
5744 Append_Entity (Full_Der, Scope (Derived_Type));
5745 Set_Has_Private_Declaration (Full_Der);
5746 Set_Has_Private_Declaration (Derived_Type);
5747 Set_Associated_Node_For_Itype (Full_Der, N);
5748 Set_Parent (Full_Der, Parent (Derived_Type));
5749 Full_P := Full_View (Parent_Type);
5750 Exchange_Declarations (Parent_Type);
5752 Exchange_Declarations (Full_P);
5753 Set_Underlying_Full_View (Derived_Type, Full_Der);
5756 end Build_Derived_Private_Type;
5758 -------------------------------
5759 -- Build_Derived_Record_Type --
5760 -------------------------------
5764 -- Ideally we would like to use the same model of type derivation for
5765 -- tagged and untagged record types. Unfortunately this is not quite
5766 -- possible because the semantics of representation clauses is different
5767 -- for tagged and untagged records under inheritance. Consider the
5770 -- type R (...) is [tagged] record ... end record;
5771 -- type T (...) is new R (...) [with ...];
5773 -- The representation clauses for T can specify a completely different
5774 -- record layout from R's. Hence the same component can be placed in two
5775 -- very different positions in objects of type T and R. If R and are tagged
5776 -- types, representation clauses for T can only specify the layout of non
5777 -- inherited components, thus components that are common in R and T have
5778 -- the same position in objects of type R and T.
5780 -- This has two implications. The first is that the entire tree for R's
5781 -- declaration needs to be copied for T in the untagged case, so that T
5782 -- can be viewed as a record type of its own with its own representation
5783 -- clauses. The second implication is the way we handle discriminants.
5784 -- Specifically, in the untagged case we need a way to communicate to Gigi
5785 -- what are the real discriminants in the record, while for the semantics
5786 -- we need to consider those introduced by the user to rename the
5787 -- discriminants in the parent type. This is handled by introducing the
5788 -- notion of stored discriminants. See below for more.
5790 -- Fortunately the way regular components are inherited can be handled in
5791 -- the same way in tagged and untagged types.
5793 -- To complicate things a bit more the private view of a private extension
5794 -- cannot be handled in the same way as the full view (for one thing the
5795 -- semantic rules are somewhat different). We will explain what differs
5798 -- 2. DISCRIMINANTS UNDER INHERITANCE
5800 -- The semantic rules governing the discriminants of derived types are
5803 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
5804 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
5806 -- If parent type has discriminants, then the discriminants that are
5807 -- declared in the derived type are [3.4 (11)]:
5809 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
5812 -- o Otherwise, each discriminant of the parent type (implicitly declared
5813 -- in the same order with the same specifications). In this case, the
5814 -- discriminants are said to be "inherited", or if unknown in the parent
5815 -- are also unknown in the derived type.
5817 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
5819 -- o The parent subtype shall be constrained;
5821 -- o If the parent type is not a tagged type, then each discriminant of
5822 -- the derived type shall be used in the constraint defining a parent
5823 -- subtype. [Implementation note: This ensures that the new discriminant
5824 -- can share storage with an existing discriminant.]
5826 -- For the derived type each discriminant of the parent type is either
5827 -- inherited, constrained to equal some new discriminant of the derived
5828 -- type, or constrained to the value of an expression.
5830 -- When inherited or constrained to equal some new discriminant, the
5831 -- parent discriminant and the discriminant of the derived type are said
5834 -- If a discriminant of the parent type is constrained to a specific value
5835 -- in the derived type definition, then the discriminant is said to be
5836 -- "specified" by that derived type definition.
5838 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
5840 -- We have spoken about stored discriminants in point 1 (introduction)
5841 -- above. There are two sort of stored discriminants: implicit and
5842 -- explicit. As long as the derived type inherits the same discriminants as
5843 -- the root record type, stored discriminants are the same as regular
5844 -- discriminants, and are said to be implicit. However, if any discriminant
5845 -- in the root type was renamed in the derived type, then the derived
5846 -- type will contain explicit stored discriminants. Explicit stored
5847 -- discriminants are discriminants in addition to the semantically visible
5848 -- discriminants defined for the derived type. Stored discriminants are
5849 -- used by Gigi to figure out what are the physical discriminants in
5850 -- objects of the derived type (see precise definition in einfo.ads).
5851 -- As an example, consider the following:
5853 -- type R (D1, D2, D3 : Int) is record ... end record;
5854 -- type T1 is new R;
5855 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
5856 -- type T3 is new T2;
5857 -- type T4 (Y : Int) is new T3 (Y, 99);
5859 -- The following table summarizes the discriminants and stored
5860 -- discriminants in R and T1 through T4.
5862 -- Type Discrim Stored Discrim Comment
5863 -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
5864 -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
5865 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
5866 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
5867 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
5869 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
5870 -- find the corresponding discriminant in the parent type, while
5871 -- Original_Record_Component (abbreviated ORC below), the actual physical
5872 -- component that is renamed. Finally the field Is_Completely_Hidden
5873 -- (abbreviated ICH below) is set for all explicit stored discriminants
5874 -- (see einfo.ads for more info). For the above example this gives:
5876 -- Discrim CD ORC ICH
5877 -- ^^^^^^^ ^^ ^^^ ^^^
5878 -- D1 in R empty itself no
5879 -- D2 in R empty itself no
5880 -- D3 in R empty itself no
5882 -- D1 in T1 D1 in R itself no
5883 -- D2 in T1 D2 in R itself no
5884 -- D3 in T1 D3 in R itself no
5886 -- X1 in T2 D3 in T1 D3 in T2 no
5887 -- X2 in T2 D1 in T1 D1 in T2 no
5888 -- D1 in T2 empty itself yes
5889 -- D2 in T2 empty itself yes
5890 -- D3 in T2 empty itself yes
5892 -- X1 in T3 X1 in T2 D3 in T3 no
5893 -- X2 in T3 X2 in T2 D1 in T3 no
5894 -- D1 in T3 empty itself yes
5895 -- D2 in T3 empty itself yes
5896 -- D3 in T3 empty itself yes
5898 -- Y in T4 X1 in T3 D3 in T3 no
5899 -- D1 in T3 empty itself yes
5900 -- D2 in T3 empty itself yes
5901 -- D3 in T3 empty itself yes
5903 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
5905 -- Type derivation for tagged types is fairly straightforward. If no
5906 -- discriminants are specified by the derived type, these are inherited
5907 -- from the parent. No explicit stored discriminants are ever necessary.
5908 -- The only manipulation that is done to the tree is that of adding a
5909 -- _parent field with parent type and constrained to the same constraint
5910 -- specified for the parent in the derived type definition. For instance:
5912 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
5913 -- type T1 is new R with null record;
5914 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
5916 -- are changed into:
5918 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
5919 -- _parent : R (D1, D2, D3);
5922 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
5923 -- _parent : T1 (X2, 88, X1);
5926 -- The discriminants actually present in R, T1 and T2 as well as their CD,
5927 -- ORC and ICH fields are:
5929 -- Discrim CD ORC ICH
5930 -- ^^^^^^^ ^^ ^^^ ^^^
5931 -- D1 in R empty itself no
5932 -- D2 in R empty itself no
5933 -- D3 in R empty itself no
5935 -- D1 in T1 D1 in R D1 in R no
5936 -- D2 in T1 D2 in R D2 in R no
5937 -- D3 in T1 D3 in R D3 in R no
5939 -- X1 in T2 D3 in T1 D3 in R no
5940 -- X2 in T2 D1 in T1 D1 in R no
5942 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
5944 -- Regardless of whether we dealing with a tagged or untagged type
5945 -- we will transform all derived type declarations of the form
5947 -- type T is new R (...) [with ...];
5949 -- subtype S is R (...);
5950 -- type T is new S [with ...];
5952 -- type BT is new R [with ...];
5953 -- subtype T is BT (...);
5955 -- That is, the base derived type is constrained only if it has no
5956 -- discriminants. The reason for doing this is that GNAT's semantic model
5957 -- assumes that a base type with discriminants is unconstrained.
5959 -- Note that, strictly speaking, the above transformation is not always
5960 -- correct. Consider for instance the following excerpt from ACVC b34011a:
5962 -- procedure B34011A is
5963 -- type REC (D : integer := 0) is record
5968 -- type T6 is new Rec;
5969 -- function F return T6;
5974 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
5977 -- The definition of Q6.U is illegal. However transforming Q6.U into
5979 -- type BaseU is new T6;
5980 -- subtype U is BaseU (Q6.F.I)
5982 -- turns U into a legal subtype, which is incorrect. To avoid this problem
5983 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
5984 -- the transformation described above.
5986 -- There is another instance where the above transformation is incorrect.
5990 -- type Base (D : Integer) is tagged null record;
5991 -- procedure P (X : Base);
5993 -- type Der is new Base (2) with null record;
5994 -- procedure P (X : Der);
5997 -- Then the above transformation turns this into
5999 -- type Der_Base is new Base with null record;
6000 -- -- procedure P (X : Base) is implicitly inherited here
6001 -- -- as procedure P (X : Der_Base).
6003 -- subtype Der is Der_Base (2);
6004 -- procedure P (X : Der);
6005 -- -- The overriding of P (X : Der_Base) is illegal since we
6006 -- -- have a parameter conformance problem.
6008 -- To get around this problem, after having semantically processed Der_Base
6009 -- and the rewritten subtype declaration for Der, we copy Der_Base field
6010 -- Discriminant_Constraint from Der so that when parameter conformance is
6011 -- checked when P is overridden, no semantic errors are flagged.
6013 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
6015 -- Regardless of whether we are dealing with a tagged or untagged type
6016 -- we will transform all derived type declarations of the form
6018 -- type R (D1, .., Dn : ...) is [tagged] record ...;
6019 -- type T is new R [with ...];
6021 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
6023 -- The reason for such transformation is that it allows us to implement a
6024 -- very clean form of component inheritance as explained below.
6026 -- Note that this transformation is not achieved by direct tree rewriting
6027 -- and manipulation, but rather by redoing the semantic actions that the
6028 -- above transformation will entail. This is done directly in routine
6029 -- Inherit_Components.
6031 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
6033 -- In both tagged and untagged derived types, regular non discriminant
6034 -- components are inherited in the derived type from the parent type. In
6035 -- the absence of discriminants component, inheritance is straightforward
6036 -- as components can simply be copied from the parent.
6038 -- If the parent has discriminants, inheriting components constrained with
6039 -- these discriminants requires caution. Consider the following example:
6041 -- type R (D1, D2 : Positive) is [tagged] record
6042 -- S : String (D1 .. D2);
6045 -- type T1 is new R [with null record];
6046 -- type T2 (X : positive) is new R (1, X) [with null record];
6048 -- As explained in 6. above, T1 is rewritten as
6049 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
6050 -- which makes the treatment for T1 and T2 identical.
6052 -- What we want when inheriting S, is that references to D1 and D2 in R are
6053 -- replaced with references to their correct constraints, i.e. D1 and D2 in
6054 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
6055 -- with either discriminant references in the derived type or expressions.
6056 -- This replacement is achieved as follows: before inheriting R's
6057 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
6058 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
6059 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
6060 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
6061 -- by String (1 .. X).
6063 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
6065 -- We explain here the rules governing private type extensions relevant to
6066 -- type derivation. These rules are explained on the following example:
6068 -- type D [(...)] is new A [(...)] with private; <-- partial view
6069 -- type D [(...)] is new P [(...)] with null record; <-- full view
6071 -- Type A is called the ancestor subtype of the private extension.
6072 -- Type P is the parent type of the full view of the private extension. It
6073 -- must be A or a type derived from A.
6075 -- The rules concerning the discriminants of private type extensions are
6078 -- o If a private extension inherits known discriminants from the ancestor
6079 -- subtype, then the full view shall also inherit its discriminants from
6080 -- the ancestor subtype and the parent subtype of the full view shall be
6081 -- constrained if and only if the ancestor subtype is constrained.
6083 -- o If a partial view has unknown discriminants, then the full view may
6084 -- define a definite or an indefinite subtype, with or without
6087 -- o If a partial view has neither known nor unknown discriminants, then
6088 -- the full view shall define a definite subtype.
6090 -- o If the ancestor subtype of a private extension has constrained
6091 -- discriminants, then the parent subtype of the full view shall impose a
6092 -- statically matching constraint on those discriminants.
6094 -- This means that only the following forms of private extensions are
6097 -- type D is new A with private; <-- partial view
6098 -- type D is new P with null record; <-- full view
6100 -- If A has no discriminants than P has no discriminants, otherwise P must
6101 -- inherit A's discriminants.
6103 -- type D is new A (...) with private; <-- partial view
6104 -- type D is new P (:::) with null record; <-- full view
6106 -- P must inherit A's discriminants and (...) and (:::) must statically
6109 -- subtype A is R (...);
6110 -- type D is new A with private; <-- partial view
6111 -- type D is new P with null record; <-- full view
6113 -- P must have inherited R's discriminants and must be derived from A or
6114 -- any of its subtypes.
6116 -- type D (..) is new A with private; <-- partial view
6117 -- type D (..) is new P [(:::)] with null record; <-- full view
6119 -- No specific constraints on P's discriminants or constraint (:::).
6120 -- Note that A can be unconstrained, but the parent subtype P must either
6121 -- be constrained or (:::) must be present.
6123 -- type D (..) is new A [(...)] with private; <-- partial view
6124 -- type D (..) is new P [(:::)] with null record; <-- full view
6126 -- P's constraints on A's discriminants must statically match those
6127 -- imposed by (...).
6129 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
6131 -- The full view of a private extension is handled exactly as described
6132 -- above. The model chose for the private view of a private extension is
6133 -- the same for what concerns discriminants (i.e. they receive the same
6134 -- treatment as in the tagged case). However, the private view of the
6135 -- private extension always inherits the components of the parent base,
6136 -- without replacing any discriminant reference. Strictly speaking this is
6137 -- incorrect. However, Gigi never uses this view to generate code so this
6138 -- is a purely semantic issue. In theory, a set of transformations similar
6139 -- to those given in 5. and 6. above could be applied to private views of
6140 -- private extensions to have the same model of component inheritance as
6141 -- for non private extensions. However, this is not done because it would
6142 -- further complicate private type processing. Semantically speaking, this
6143 -- leaves us in an uncomfortable situation. As an example consider:
6146 -- type R (D : integer) is tagged record
6147 -- S : String (1 .. D);
6149 -- procedure P (X : R);
6150 -- type T is new R (1) with private;
6152 -- type T is new R (1) with null record;
6155 -- This is transformed into:
6158 -- type R (D : integer) is tagged record
6159 -- S : String (1 .. D);
6161 -- procedure P (X : R);
6162 -- type T is new R (1) with private;
6164 -- type BaseT is new R with null record;
6165 -- subtype T is BaseT (1);
6168 -- (strictly speaking the above is incorrect Ada)
6170 -- From the semantic standpoint the private view of private extension T
6171 -- should be flagged as constrained since one can clearly have
6175 -- in a unit withing Pack. However, when deriving subprograms for the
6176 -- private view of private extension T, T must be seen as unconstrained
6177 -- since T has discriminants (this is a constraint of the current
6178 -- subprogram derivation model). Thus, when processing the private view of
6179 -- a private extension such as T, we first mark T as unconstrained, we
6180 -- process it, we perform program derivation and just before returning from
6181 -- Build_Derived_Record_Type we mark T as constrained.
6183 -- ??? Are there are other uncomfortable cases that we will have to
6186 -- 10. RECORD_TYPE_WITH_PRIVATE complications
6188 -- Types that are derived from a visible record type and have a private
6189 -- extension present other peculiarities. They behave mostly like private
6190 -- types, but if they have primitive operations defined, these will not
6191 -- have the proper signatures for further inheritance, because other
6192 -- primitive operations will use the implicit base that we define for
6193 -- private derivations below. This affect subprogram inheritance (see
6194 -- Derive_Subprograms for details). We also derive the implicit base from
6195 -- the base type of the full view, so that the implicit base is a record
6196 -- type and not another private type, This avoids infinite loops.
6198 procedure Build_Derived_Record_Type
6200 Parent_Type : Entity_Id;
6201 Derived_Type : Entity_Id;
6202 Derive_Subps : Boolean := True)
6204 Loc : constant Source_Ptr := Sloc (N);
6205 Parent_Base : Entity_Id;
6208 Discrim : Entity_Id;
6209 Last_Discrim : Entity_Id;
6212 Discs : Elist_Id := New_Elmt_List;
6213 -- An empty Discs list means that there were no constraints in the
6214 -- subtype indication or that there was an error processing it.
6216 Assoc_List : Elist_Id;
6217 New_Discrs : Elist_Id;
6218 New_Base : Entity_Id;
6220 New_Indic : Node_Id;
6222 Is_Tagged : constant Boolean := Is_Tagged_Type (Parent_Type);
6223 Discriminant_Specs : constant Boolean :=
6224 Present (Discriminant_Specifications (N));
6225 Private_Extension : constant Boolean :=
6226 Nkind (N) = N_Private_Extension_Declaration;
6228 Constraint_Present : Boolean;
6229 Inherit_Discrims : Boolean := False;
6230 Save_Etype : Entity_Id;
6231 Save_Discr_Constr : Elist_Id;
6232 Save_Next_Entity : Entity_Id;
6235 if Ekind (Parent_Type) = E_Record_Type_With_Private
6236 and then Present (Full_View (Parent_Type))
6237 and then Has_Discriminants (Parent_Type)
6239 Parent_Base := Base_Type (Full_View (Parent_Type));
6241 Parent_Base := Base_Type (Parent_Type);
6244 -- Before we start the previously documented transformations, here is
6245 -- little fix for size and alignment of tagged types. Normally when we
6246 -- derive type D from type P, we copy the size and alignment of P as the
6247 -- default for D, and in the absence of explicit representation clauses
6248 -- for D, the size and alignment are indeed the same as the parent.
6250 -- But this is wrong for tagged types, since fields may be added, and
6251 -- the default size may need to be larger, and the default alignment may
6252 -- need to be larger.
6254 -- We therefore reset the size and alignment fields in the tagged case.
6255 -- Note that the size and alignment will in any case be at least as
6256 -- large as the parent type (since the derived type has a copy of the
6257 -- parent type in the _parent field)
6259 -- The type is also marked as being tagged here, which is needed when
6260 -- processing components with a self-referential anonymous access type
6261 -- in the call to Check_Anonymous_Access_Components below. Note that
6262 -- this flag is also set later on for completeness.
6265 Set_Is_Tagged_Type (Derived_Type);
6266 Init_Size_Align (Derived_Type);
6269 -- STEP 0a: figure out what kind of derived type declaration we have
6271 if Private_Extension then
6273 Set_Ekind (Derived_Type, E_Record_Type_With_Private);
6276 Type_Def := Type_Definition (N);
6278 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
6279 -- Parent_Base can be a private type or private extension. However,
6280 -- for tagged types with an extension the newly added fields are
6281 -- visible and hence the Derived_Type is always an E_Record_Type.
6282 -- (except that the parent may have its own private fields).
6283 -- For untagged types we preserve the Ekind of the Parent_Base.
6285 if Present (Record_Extension_Part (Type_Def)) then
6286 Set_Ekind (Derived_Type, E_Record_Type);
6288 -- Create internal access types for components with anonymous
6291 if Ada_Version >= Ada_05 then
6292 Check_Anonymous_Access_Components
6293 (N, Derived_Type, Derived_Type,
6294 Component_List (Record_Extension_Part (Type_Def)));
6298 Set_Ekind (Derived_Type, Ekind (Parent_Base));
6302 -- Indic can either be an N_Identifier if the subtype indication
6303 -- contains no constraint or an N_Subtype_Indication if the subtype
6304 -- indication has a constraint.
6306 Indic := Subtype_Indication (Type_Def);
6307 Constraint_Present := (Nkind (Indic) = N_Subtype_Indication);
6309 -- Check that the type has visible discriminants. The type may be
6310 -- a private type with unknown discriminants whose full view has
6311 -- discriminants which are invisible.
6313 if Constraint_Present then
6314 if not Has_Discriminants (Parent_Base)
6316 (Has_Unknown_Discriminants (Parent_Base)
6317 and then Is_Private_Type (Parent_Base))
6320 ("invalid constraint: type has no discriminant",
6321 Constraint (Indic));
6323 Constraint_Present := False;
6324 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6326 elsif Is_Constrained (Parent_Type) then
6328 ("invalid constraint: parent type is already constrained",
6329 Constraint (Indic));
6331 Constraint_Present := False;
6332 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6336 -- STEP 0b: If needed, apply transformation given in point 5. above
6338 if not Private_Extension
6339 and then Has_Discriminants (Parent_Type)
6340 and then not Discriminant_Specs
6341 and then (Is_Constrained (Parent_Type) or else Constraint_Present)
6343 -- First, we must analyze the constraint (see comment in point 5.)
6345 if Constraint_Present then
6346 New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic);
6348 if Has_Discriminants (Derived_Type)
6349 and then Has_Private_Declaration (Derived_Type)
6350 and then Present (Discriminant_Constraint (Derived_Type))
6352 -- Verify that constraints of the full view statically match
6353 -- those given in the partial view.
6359 C1 := First_Elmt (New_Discrs);
6360 C2 := First_Elmt (Discriminant_Constraint (Derived_Type));
6361 while Present (C1) and then Present (C2) loop
6362 if Fully_Conformant_Expressions (Node (C1), Node (C2))
6364 (Is_OK_Static_Expression (Node (C1))
6366 Is_OK_Static_Expression (Node (C2))
6368 Expr_Value (Node (C1)) = Expr_Value (Node (C2)))
6374 "constraint not conformant to previous declaration",
6385 -- Insert and analyze the declaration for the unconstrained base type
6387 New_Base := Create_Itype (Ekind (Derived_Type), N, Derived_Type, 'B');
6390 Make_Full_Type_Declaration (Loc,
6391 Defining_Identifier => New_Base,
6393 Make_Derived_Type_Definition (Loc,
6394 Abstract_Present => Abstract_Present (Type_Def),
6395 Subtype_Indication =>
6396 New_Occurrence_Of (Parent_Base, Loc),
6397 Record_Extension_Part =>
6398 Relocate_Node (Record_Extension_Part (Type_Def))));
6400 Set_Parent (New_Decl, Parent (N));
6401 Mark_Rewrite_Insertion (New_Decl);
6402 Insert_Before (N, New_Decl);
6404 -- Note that this call passes False for the Derive_Subps parameter
6405 -- because subprogram derivation is deferred until after creating
6406 -- the subtype (see below).
6409 (New_Decl, Parent_Base, New_Base,
6410 Is_Completion => True, Derive_Subps => False);
6412 -- ??? This needs re-examination to determine whether the
6413 -- above call can simply be replaced by a call to Analyze.
6415 Set_Analyzed (New_Decl);
6417 -- Insert and analyze the declaration for the constrained subtype
6419 if Constraint_Present then
6421 Make_Subtype_Indication (Loc,
6422 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6423 Constraint => Relocate_Node (Constraint (Indic)));
6427 Constr_List : constant List_Id := New_List;
6432 C := First_Elmt (Discriminant_Constraint (Parent_Type));
6433 while Present (C) loop
6436 -- It is safe here to call New_Copy_Tree since
6437 -- Force_Evaluation was called on each constraint in
6438 -- Build_Discriminant_Constraints.
6440 Append (New_Copy_Tree (Expr), To => Constr_List);
6446 Make_Subtype_Indication (Loc,
6447 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6449 Make_Index_Or_Discriminant_Constraint (Loc, Constr_List));
6454 Make_Subtype_Declaration (Loc,
6455 Defining_Identifier => Derived_Type,
6456 Subtype_Indication => New_Indic));
6460 -- Derivation of subprograms must be delayed until the full subtype
6461 -- has been established to ensure proper overriding of subprograms
6462 -- inherited by full types. If the derivations occurred as part of
6463 -- the call to Build_Derived_Type above, then the check for type
6464 -- conformance would fail because earlier primitive subprograms
6465 -- could still refer to the full type prior the change to the new
6466 -- subtype and hence would not match the new base type created here.
6468 Derive_Subprograms (Parent_Type, Derived_Type);
6470 -- For tagged types the Discriminant_Constraint of the new base itype
6471 -- is inherited from the first subtype so that no subtype conformance
6472 -- problem arise when the first subtype overrides primitive
6473 -- operations inherited by the implicit base type.
6476 Set_Discriminant_Constraint
6477 (New_Base, Discriminant_Constraint (Derived_Type));
6483 -- If we get here Derived_Type will have no discriminants or it will be
6484 -- a discriminated unconstrained base type.
6486 -- STEP 1a: perform preliminary actions/checks for derived tagged types
6490 -- The parent type is frozen for non-private extensions (RM 13.14(7))
6491 -- The declaration of a specific descendant of an interface type
6492 -- freezes the interface type (RM 13.14).
6494 if not Private_Extension
6495 or else Is_Interface (Parent_Base)
6497 Freeze_Before (N, Parent_Type);
6500 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
6501 -- cannot be declared at a deeper level than its parent type is
6502 -- removed. The check on derivation within a generic body is also
6503 -- relaxed, but there's a restriction that a derived tagged type
6504 -- cannot be declared in a generic body if it's derived directly
6505 -- or indirectly from a formal type of that generic.
6507 if Ada_Version >= Ada_05 then
6508 if Present (Enclosing_Generic_Body (Derived_Type)) then
6510 Ancestor_Type : Entity_Id;
6513 -- Check to see if any ancestor of the derived type is a
6516 Ancestor_Type := Parent_Type;
6517 while not Is_Generic_Type (Ancestor_Type)
6518 and then Etype (Ancestor_Type) /= Ancestor_Type
6520 Ancestor_Type := Etype (Ancestor_Type);
6523 -- If the derived type does have a formal type as an
6524 -- ancestor, then it's an error if the derived type is
6525 -- declared within the body of the generic unit that
6526 -- declares the formal type in its generic formal part. It's
6527 -- sufficient to check whether the ancestor type is declared
6528 -- inside the same generic body as the derived type (such as
6529 -- within a nested generic spec), in which case the
6530 -- derivation is legal. If the formal type is declared
6531 -- outside of that generic body, then it's guaranteed that
6532 -- the derived type is declared within the generic body of
6533 -- the generic unit declaring the formal type.
6535 if Is_Generic_Type (Ancestor_Type)
6536 and then Enclosing_Generic_Body (Ancestor_Type) /=
6537 Enclosing_Generic_Body (Derived_Type)
6540 ("parent type of& must not be descendant of formal type"
6541 & " of an enclosing generic body",
6542 Indic, Derived_Type);
6547 elsif Type_Access_Level (Derived_Type) /=
6548 Type_Access_Level (Parent_Type)
6549 and then not Is_Generic_Type (Derived_Type)
6551 if Is_Controlled (Parent_Type) then
6553 ("controlled type must be declared at the library level",
6557 ("type extension at deeper accessibility level than parent",
6563 GB : constant Node_Id := Enclosing_Generic_Body (Derived_Type);
6567 and then GB /= Enclosing_Generic_Body (Parent_Base)
6570 ("parent type of& must not be outside generic body"
6572 Indic, Derived_Type);
6578 -- Ada 2005 (AI-251)
6580 if Ada_Version = Ada_05
6583 -- "The declaration of a specific descendant of an interface type
6584 -- freezes the interface type" (RM 13.14).
6589 if Is_Non_Empty_List (Interface_List (Type_Def)) then
6590 Iface := First (Interface_List (Type_Def));
6591 while Present (Iface) loop
6592 Freeze_Before (N, Etype (Iface));
6599 -- STEP 1b : preliminary cleanup of the full view of private types
6601 -- If the type is already marked as having discriminants, then it's the
6602 -- completion of a private type or private extension and we need to
6603 -- retain the discriminants from the partial view if the current
6604 -- declaration has Discriminant_Specifications so that we can verify
6605 -- conformance. However, we must remove any existing components that
6606 -- were inherited from the parent (and attached in Copy_And_Swap)
6607 -- because the full type inherits all appropriate components anyway, and
6608 -- we do not want the partial view's components interfering.
6610 if Has_Discriminants (Derived_Type) and then Discriminant_Specs then
6611 Discrim := First_Discriminant (Derived_Type);
6613 Last_Discrim := Discrim;
6614 Next_Discriminant (Discrim);
6615 exit when No (Discrim);
6618 Set_Last_Entity (Derived_Type, Last_Discrim);
6620 -- In all other cases wipe out the list of inherited components (even
6621 -- inherited discriminants), it will be properly rebuilt here.
6624 Set_First_Entity (Derived_Type, Empty);
6625 Set_Last_Entity (Derived_Type, Empty);
6628 -- STEP 1c: Initialize some flags for the Derived_Type
6630 -- The following flags must be initialized here so that
6631 -- Process_Discriminants can check that discriminants of tagged types do
6632 -- not have a default initial value and that access discriminants are
6633 -- only specified for limited records. For completeness, these flags are
6634 -- also initialized along with all the other flags below.
6636 -- AI-419: Limitedness is not inherited from an interface parent, so to
6637 -- be limited in that case the type must be explicitly declared as
6638 -- limited. However, task and protected interfaces are always limited.
6640 if Limited_Present (Type_Def) then
6641 Set_Is_Limited_Record (Derived_Type);
6643 elsif Is_Limited_Record (Parent_Type)
6644 or else (Present (Full_View (Parent_Type))
6645 and then Is_Limited_Record (Full_View (Parent_Type)))
6647 if not Is_Interface (Parent_Type)
6648 or else Is_Synchronized_Interface (Parent_Type)
6649 or else Is_Protected_Interface (Parent_Type)
6650 or else Is_Task_Interface (Parent_Type)
6652 Set_Is_Limited_Record (Derived_Type);
6656 -- STEP 2a: process discriminants of derived type if any
6658 Push_Scope (Derived_Type);
6660 if Discriminant_Specs then
6661 Set_Has_Unknown_Discriminants (Derived_Type, False);
6663 -- The following call initializes fields Has_Discriminants and
6664 -- Discriminant_Constraint, unless we are processing the completion
6665 -- of a private type declaration.
6667 Check_Or_Process_Discriminants (N, Derived_Type);
6669 -- For non-tagged types the constraint on the Parent_Type must be
6670 -- present and is used to rename the discriminants.
6672 if not Is_Tagged and then not Has_Discriminants (Parent_Type) then
6673 Error_Msg_N ("untagged parent must have discriminants", Indic);
6675 elsif not Is_Tagged and then not Constraint_Present then
6677 ("discriminant constraint needed for derived untagged records",
6680 -- Otherwise the parent subtype must be constrained unless we have a
6681 -- private extension.
6683 elsif not Constraint_Present
6684 and then not Private_Extension
6685 and then not Is_Constrained (Parent_Type)
6688 ("unconstrained type not allowed in this context", Indic);
6690 elsif Constraint_Present then
6691 -- The following call sets the field Corresponding_Discriminant
6692 -- for the discriminants in the Derived_Type.
6694 Discs := Build_Discriminant_Constraints (Parent_Type, Indic, True);
6696 -- For untagged types all new discriminants must rename
6697 -- discriminants in the parent. For private extensions new
6698 -- discriminants cannot rename old ones (implied by [7.3(13)]).
6700 Discrim := First_Discriminant (Derived_Type);
6701 while Present (Discrim) loop
6703 and then No (Corresponding_Discriminant (Discrim))
6706 ("new discriminants must constrain old ones", Discrim);
6708 elsif Private_Extension
6709 and then Present (Corresponding_Discriminant (Discrim))
6712 ("only static constraints allowed for parent"
6713 & " discriminants in the partial view", Indic);
6717 -- If a new discriminant is used in the constraint, then its
6718 -- subtype must be statically compatible with the parent
6719 -- discriminant's subtype (3.7(15)).
6721 if Present (Corresponding_Discriminant (Discrim))
6723 not Subtypes_Statically_Compatible
6725 Etype (Corresponding_Discriminant (Discrim)))
6728 ("subtype must be compatible with parent discriminant",
6732 Next_Discriminant (Discrim);
6735 -- Check whether the constraints of the full view statically
6736 -- match those imposed by the parent subtype [7.3(13)].
6738 if Present (Stored_Constraint (Derived_Type)) then
6743 C1 := First_Elmt (Discs);
6744 C2 := First_Elmt (Stored_Constraint (Derived_Type));
6745 while Present (C1) and then Present (C2) loop
6747 Fully_Conformant_Expressions (Node (C1), Node (C2))
6750 ("not conformant with previous declaration",
6761 -- STEP 2b: No new discriminants, inherit discriminants if any
6764 if Private_Extension then
6765 Set_Has_Unknown_Discriminants
6767 Has_Unknown_Discriminants (Parent_Type)
6768 or else Unknown_Discriminants_Present (N));
6770 -- The partial view of the parent may have unknown discriminants,
6771 -- but if the full view has discriminants and the parent type is
6772 -- in scope they must be inherited.
6774 elsif Has_Unknown_Discriminants (Parent_Type)
6776 (not Has_Discriminants (Parent_Type)
6777 or else not In_Open_Scopes (Scope (Parent_Type)))
6779 Set_Has_Unknown_Discriminants (Derived_Type);
6782 if not Has_Unknown_Discriminants (Derived_Type)
6783 and then not Has_Unknown_Discriminants (Parent_Base)
6784 and then Has_Discriminants (Parent_Type)
6786 Inherit_Discrims := True;
6787 Set_Has_Discriminants
6788 (Derived_Type, True);
6789 Set_Discriminant_Constraint
6790 (Derived_Type, Discriminant_Constraint (Parent_Base));
6793 -- The following test is true for private types (remember
6794 -- transformation 5. is not applied to those) and in an error
6797 if Constraint_Present then
6798 Discs := Build_Discriminant_Constraints (Parent_Type, Indic);
6801 -- For now mark a new derived type as constrained only if it has no
6802 -- discriminants. At the end of Build_Derived_Record_Type we properly
6803 -- set this flag in the case of private extensions. See comments in
6804 -- point 9. just before body of Build_Derived_Record_Type.
6808 not (Inherit_Discrims
6809 or else Has_Unknown_Discriminants (Derived_Type)));
6812 -- STEP 3: initialize fields of derived type
6814 Set_Is_Tagged_Type (Derived_Type, Is_Tagged);
6815 Set_Stored_Constraint (Derived_Type, No_Elist);
6817 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
6818 -- but cannot be interfaces
6820 if not Private_Extension
6821 and then Ekind (Derived_Type) /= E_Private_Type
6822 and then Ekind (Derived_Type) /= E_Limited_Private_Type
6824 if Interface_Present (Type_Def) then
6825 Analyze_Interface_Declaration (Derived_Type, Type_Def);
6828 Set_Interfaces (Derived_Type, No_Elist);
6831 -- Fields inherited from the Parent_Type
6834 (Derived_Type, Einfo.Discard_Names (Parent_Type));
6835 Set_Has_Specified_Layout
6836 (Derived_Type, Has_Specified_Layout (Parent_Type));
6837 Set_Is_Limited_Composite
6838 (Derived_Type, Is_Limited_Composite (Parent_Type));
6839 Set_Is_Private_Composite
6840 (Derived_Type, Is_Private_Composite (Parent_Type));
6842 -- Fields inherited from the Parent_Base
6844 Set_Has_Controlled_Component
6845 (Derived_Type, Has_Controlled_Component (Parent_Base));
6846 Set_Has_Non_Standard_Rep
6847 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6848 Set_Has_Primitive_Operations
6849 (Derived_Type, Has_Primitive_Operations (Parent_Base));
6851 -- Fields inherited from the Parent_Base in the non-private case
6853 if Ekind (Derived_Type) = E_Record_Type then
6854 Set_Has_Complex_Representation
6855 (Derived_Type, Has_Complex_Representation (Parent_Base));
6858 -- Fields inherited from the Parent_Base for record types
6860 if Is_Record_Type (Derived_Type) then
6861 Set_OK_To_Reorder_Components
6862 (Derived_Type, OK_To_Reorder_Components (Parent_Base));
6863 Set_Reverse_Bit_Order
6864 (Derived_Type, Reverse_Bit_Order (Parent_Base));
6867 -- Direct controlled types do not inherit Finalize_Storage_Only flag
6869 if not Is_Controlled (Parent_Type) then
6870 Set_Finalize_Storage_Only
6871 (Derived_Type, Finalize_Storage_Only (Parent_Type));
6874 -- Set fields for private derived types
6876 if Is_Private_Type (Derived_Type) then
6877 Set_Depends_On_Private (Derived_Type, True);
6878 Set_Private_Dependents (Derived_Type, New_Elmt_List);
6880 -- Inherit fields from non private record types. If this is the
6881 -- completion of a derivation from a private type, the parent itself
6882 -- is private, and the attributes come from its full view, which must
6886 if Is_Private_Type (Parent_Base)
6887 and then not Is_Record_Type (Parent_Base)
6889 Set_Component_Alignment
6890 (Derived_Type, Component_Alignment (Full_View (Parent_Base)));
6892 (Derived_Type, C_Pass_By_Copy (Full_View (Parent_Base)));
6894 Set_Component_Alignment
6895 (Derived_Type, Component_Alignment (Parent_Base));
6898 (Derived_Type, C_Pass_By_Copy (Parent_Base));
6902 -- Set fields for tagged types
6905 Set_Primitive_Operations (Derived_Type, New_Elmt_List);
6907 -- All tagged types defined in Ada.Finalization are controlled
6909 if Chars (Scope (Derived_Type)) = Name_Finalization
6910 and then Chars (Scope (Scope (Derived_Type))) = Name_Ada
6911 and then Scope (Scope (Scope (Derived_Type))) = Standard_Standard
6913 Set_Is_Controlled (Derived_Type);
6915 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Base));
6918 Make_Class_Wide_Type (Derived_Type);
6919 Set_Is_Abstract_Type (Derived_Type, Abstract_Present (Type_Def));
6921 if Has_Discriminants (Derived_Type)
6922 and then Constraint_Present
6924 Set_Stored_Constraint
6925 (Derived_Type, Expand_To_Stored_Constraint (Parent_Base, Discs));
6928 if Ada_Version >= Ada_05 then
6930 Ifaces_List : Elist_Id;
6933 -- Checks rules 3.9.4 (13/2 and 14/2)
6935 if Comes_From_Source (Derived_Type)
6936 and then not Is_Private_Type (Derived_Type)
6937 and then Is_Interface (Parent_Type)
6938 and then not Is_Interface (Derived_Type)
6940 if Is_Task_Interface (Parent_Type) then
6942 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
6945 elsif Is_Protected_Interface (Parent_Type) then
6947 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
6952 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
6954 Check_Interfaces (N, Type_Def);
6956 -- Ada 2005 (AI-251): Collect the list of progenitors that are
6957 -- not already in the parents.
6961 Ifaces_List => Ifaces_List,
6962 Exclude_Parents => True);
6964 Set_Interfaces (Derived_Type, Ifaces_List);
6969 Set_Is_Packed (Derived_Type, Is_Packed (Parent_Base));
6970 Set_Has_Non_Standard_Rep
6971 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6974 -- STEP 4: Inherit components from the parent base and constrain them.
6975 -- Apply the second transformation described in point 6. above.
6977 if (not Is_Empty_Elmt_List (Discs) or else Inherit_Discrims)
6978 or else not Has_Discriminants (Parent_Type)
6979 or else not Is_Constrained (Parent_Type)
6983 Constrs := Discriminant_Constraint (Parent_Type);
6988 (N, Parent_Base, Derived_Type, Is_Tagged, Inherit_Discrims, Constrs);
6990 -- STEP 5a: Copy the parent record declaration for untagged types
6992 if not Is_Tagged then
6994 -- Discriminant_Constraint (Derived_Type) has been properly
6995 -- constructed. Save it and temporarily set it to Empty because we
6996 -- do not want the call to New_Copy_Tree below to mess this list.
6998 if Has_Discriminants (Derived_Type) then
6999 Save_Discr_Constr := Discriminant_Constraint (Derived_Type);
7000 Set_Discriminant_Constraint (Derived_Type, No_Elist);
7002 Save_Discr_Constr := No_Elist;
7005 -- Save the Etype field of Derived_Type. It is correctly set now,
7006 -- but the call to New_Copy tree may remap it to point to itself,
7007 -- which is not what we want. Ditto for the Next_Entity field.
7009 Save_Etype := Etype (Derived_Type);
7010 Save_Next_Entity := Next_Entity (Derived_Type);
7012 -- Assoc_List maps all stored discriminants in the Parent_Base to
7013 -- stored discriminants in the Derived_Type. It is fundamental that
7014 -- no types or itypes with discriminants other than the stored
7015 -- discriminants appear in the entities declared inside
7016 -- Derived_Type, since the back end cannot deal with it.
7020 (Parent (Parent_Base), Map => Assoc_List, New_Sloc => Loc);
7022 -- Restore the fields saved prior to the New_Copy_Tree call
7023 -- and compute the stored constraint.
7025 Set_Etype (Derived_Type, Save_Etype);
7026 Set_Next_Entity (Derived_Type, Save_Next_Entity);
7028 if Has_Discriminants (Derived_Type) then
7029 Set_Discriminant_Constraint
7030 (Derived_Type, Save_Discr_Constr);
7031 Set_Stored_Constraint
7032 (Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs));
7033 Replace_Components (Derived_Type, New_Decl);
7036 -- Insert the new derived type declaration
7038 Rewrite (N, New_Decl);
7040 -- STEP 5b: Complete the processing for record extensions in generics
7042 -- There is no completion for record extensions declared in the
7043 -- parameter part of a generic, so we need to complete processing for
7044 -- these generic record extensions here. The Record_Type_Definition call
7045 -- will change the Ekind of the components from E_Void to E_Component.
7047 elsif Private_Extension and then Is_Generic_Type (Derived_Type) then
7048 Record_Type_Definition (Empty, Derived_Type);
7050 -- STEP 5c: Process the record extension for non private tagged types
7052 elsif not Private_Extension then
7054 -- Add the _parent field in the derived type
7056 Expand_Record_Extension (Derived_Type, Type_Def);
7058 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
7059 -- implemented interfaces if we are in expansion mode
7062 and then Has_Interfaces (Derived_Type)
7064 Add_Interface_Tag_Components (N, Derived_Type);
7067 -- Analyze the record extension
7069 Record_Type_Definition
7070 (Record_Extension_Part (Type_Def), Derived_Type);
7075 -- Nothing else to do if there is an error in the derivation.
7076 -- An unusual case: the full view may be derived from a type in an
7077 -- instance, when the partial view was used illegally as an actual
7078 -- in that instance, leading to a circular definition.
7080 if Etype (Derived_Type) = Any_Type
7081 or else Etype (Parent_Type) = Derived_Type
7086 -- Set delayed freeze and then derive subprograms, we need to do
7087 -- this in this order so that derived subprograms inherit the
7088 -- derived freeze if necessary.
7090 Set_Has_Delayed_Freeze (Derived_Type);
7092 if Derive_Subps then
7093 Derive_Subprograms (Parent_Type, Derived_Type);
7096 -- If we have a private extension which defines a constrained derived
7097 -- type mark as constrained here after we have derived subprograms. See
7098 -- comment on point 9. just above the body of Build_Derived_Record_Type.
7100 if Private_Extension and then Inherit_Discrims then
7101 if Constraint_Present and then not Is_Empty_Elmt_List (Discs) then
7102 Set_Is_Constrained (Derived_Type, True);
7103 Set_Discriminant_Constraint (Derived_Type, Discs);
7105 elsif Is_Constrained (Parent_Type) then
7107 (Derived_Type, True);
7108 Set_Discriminant_Constraint
7109 (Derived_Type, Discriminant_Constraint (Parent_Type));
7113 -- Update the class_wide type, which shares the now-completed
7114 -- entity list with its specific type.
7118 (Class_Wide_Type (Derived_Type), First_Entity (Derived_Type));
7120 (Class_Wide_Type (Derived_Type), Last_Entity (Derived_Type));
7123 -- Update the scope of anonymous access types of discriminants and other
7124 -- components, to prevent scope anomalies in gigi, when the derivation
7125 -- appears in a scope nested within that of the parent.
7131 D := First_Entity (Derived_Type);
7132 while Present (D) loop
7133 if Ekind (D) = E_Discriminant
7134 or else Ekind (D) = E_Component
7136 if Is_Itype (Etype (D))
7137 and then Ekind (Etype (D)) = E_Anonymous_Access_Type
7139 Set_Scope (Etype (D), Current_Scope);
7146 end Build_Derived_Record_Type;
7148 ------------------------
7149 -- Build_Derived_Type --
7150 ------------------------
7152 procedure Build_Derived_Type
7154 Parent_Type : Entity_Id;
7155 Derived_Type : Entity_Id;
7156 Is_Completion : Boolean;
7157 Derive_Subps : Boolean := True)
7159 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
7162 -- Set common attributes
7164 Set_Scope (Derived_Type, Current_Scope);
7166 Set_Ekind (Derived_Type, Ekind (Parent_Base));
7167 Set_Etype (Derived_Type, Parent_Base);
7168 Set_Has_Task (Derived_Type, Has_Task (Parent_Base));
7170 Set_Size_Info (Derived_Type, Parent_Type);
7171 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
7172 Set_Convention (Derived_Type, Convention (Parent_Type));
7173 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
7175 -- The derived type inherits the representation clauses of the parent.
7176 -- However, for a private type that is completed by a derivation, there
7177 -- may be operation attributes that have been specified already (stream
7178 -- attributes and External_Tag) and those must be provided. Finally,
7179 -- if the partial view is a private extension, the representation items
7180 -- of the parent have been inherited already, and should not be chained
7181 -- twice to the derived type.
7183 if Is_Tagged_Type (Parent_Type)
7184 and then Present (First_Rep_Item (Derived_Type))
7186 -- The existing items are either operational items or items inherited
7187 -- from a private extension declaration.
7191 -- Used to iterate over representation items of the derived type
7194 -- Last representation item of the (non-empty) representation
7195 -- item list of the derived type.
7197 Found : Boolean := False;
7200 Rep := First_Rep_Item (Derived_Type);
7202 while Present (Rep) loop
7203 if Rep = First_Rep_Item (Parent_Type) then
7208 Rep := Next_Rep_Item (Rep);
7210 if Present (Rep) then
7216 -- Here if we either encountered the parent type's first rep
7217 -- item on the derived type's rep item list (in which case
7218 -- Found is True, and we have nothing else to do), or if we
7219 -- reached the last rep item of the derived type, which is
7220 -- Last_Rep, in which case we further chain the parent type's
7221 -- rep items to those of the derived type.
7224 Set_Next_Rep_Item (Last_Rep, First_Rep_Item (Parent_Type));
7229 Set_First_Rep_Item (Derived_Type, First_Rep_Item (Parent_Type));
7232 case Ekind (Parent_Type) is
7233 when Numeric_Kind =>
7234 Build_Derived_Numeric_Type (N, Parent_Type, Derived_Type);
7237 Build_Derived_Array_Type (N, Parent_Type, Derived_Type);
7241 | Class_Wide_Kind =>
7242 Build_Derived_Record_Type
7243 (N, Parent_Type, Derived_Type, Derive_Subps);
7246 when Enumeration_Kind =>
7247 Build_Derived_Enumeration_Type (N, Parent_Type, Derived_Type);
7250 Build_Derived_Access_Type (N, Parent_Type, Derived_Type);
7252 when Incomplete_Or_Private_Kind =>
7253 Build_Derived_Private_Type
7254 (N, Parent_Type, Derived_Type, Is_Completion, Derive_Subps);
7256 -- For discriminated types, the derivation includes deriving
7257 -- primitive operations. For others it is done below.
7259 if Is_Tagged_Type (Parent_Type)
7260 or else Has_Discriminants (Parent_Type)
7261 or else (Present (Full_View (Parent_Type))
7262 and then Has_Discriminants (Full_View (Parent_Type)))
7267 when Concurrent_Kind =>
7268 Build_Derived_Concurrent_Type (N, Parent_Type, Derived_Type);
7271 raise Program_Error;
7274 if Etype (Derived_Type) = Any_Type then
7278 -- Set delayed freeze and then derive subprograms, we need to do this
7279 -- in this order so that derived subprograms inherit the derived freeze
7282 Set_Has_Delayed_Freeze (Derived_Type);
7283 if Derive_Subps then
7284 Derive_Subprograms (Parent_Type, Derived_Type);
7287 Set_Has_Primitive_Operations
7288 (Base_Type (Derived_Type), Has_Primitive_Operations (Parent_Type));
7289 end Build_Derived_Type;
7291 -----------------------
7292 -- Build_Discriminal --
7293 -----------------------
7295 procedure Build_Discriminal (Discrim : Entity_Id) is
7296 D_Minal : Entity_Id;
7297 CR_Disc : Entity_Id;
7300 -- A discriminal has the same name as the discriminant
7303 Make_Defining_Identifier (Sloc (Discrim),
7304 Chars => Chars (Discrim));
7306 Set_Ekind (D_Minal, E_In_Parameter);
7307 Set_Mechanism (D_Minal, Default_Mechanism);
7308 Set_Etype (D_Minal, Etype (Discrim));
7310 Set_Discriminal (Discrim, D_Minal);
7311 Set_Discriminal_Link (D_Minal, Discrim);
7313 -- For task types, build at once the discriminants of the corresponding
7314 -- record, which are needed if discriminants are used in entry defaults
7315 -- and in family bounds.
7317 if Is_Concurrent_Type (Current_Scope)
7318 or else Is_Limited_Type (Current_Scope)
7320 CR_Disc := Make_Defining_Identifier (Sloc (Discrim), Chars (Discrim));
7322 Set_Ekind (CR_Disc, E_In_Parameter);
7323 Set_Mechanism (CR_Disc, Default_Mechanism);
7324 Set_Etype (CR_Disc, Etype (Discrim));
7325 Set_Discriminal_Link (CR_Disc, Discrim);
7326 Set_CR_Discriminant (Discrim, CR_Disc);
7328 end Build_Discriminal;
7330 ------------------------------------
7331 -- Build_Discriminant_Constraints --
7332 ------------------------------------
7334 function Build_Discriminant_Constraints
7337 Derived_Def : Boolean := False) return Elist_Id
7339 C : constant Node_Id := Constraint (Def);
7340 Nb_Discr : constant Nat := Number_Discriminants (T);
7342 Discr_Expr : array (1 .. Nb_Discr) of Node_Id := (others => Empty);
7343 -- Saves the expression corresponding to a given discriminant in T
7345 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat;
7346 -- Return the Position number within array Discr_Expr of a discriminant
7347 -- D within the discriminant list of the discriminated type T.
7353 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat is
7357 Disc := First_Discriminant (T);
7358 for J in Discr_Expr'Range loop
7363 Next_Discriminant (Disc);
7366 -- Note: Since this function is called on discriminants that are
7367 -- known to belong to the discriminated type, falling through the
7368 -- loop with no match signals an internal compiler error.
7370 raise Program_Error;
7373 -- Declarations local to Build_Discriminant_Constraints
7377 Elist : constant Elist_Id := New_Elmt_List;
7385 Discrim_Present : Boolean := False;
7387 -- Start of processing for Build_Discriminant_Constraints
7390 -- The following loop will process positional associations only.
7391 -- For a positional association, the (single) discriminant is
7392 -- implicitly specified by position, in textual order (RM 3.7.2).
7394 Discr := First_Discriminant (T);
7395 Constr := First (Constraints (C));
7396 for D in Discr_Expr'Range loop
7397 exit when Nkind (Constr) = N_Discriminant_Association;
7400 Error_Msg_N ("too few discriminants given in constraint", C);
7401 return New_Elmt_List;
7403 elsif Nkind (Constr) = N_Range
7404 or else (Nkind (Constr) = N_Attribute_Reference
7406 Attribute_Name (Constr) = Name_Range)
7409 ("a range is not a valid discriminant constraint", Constr);
7410 Discr_Expr (D) := Error;
7413 Analyze_And_Resolve (Constr, Base_Type (Etype (Discr)));
7414 Discr_Expr (D) := Constr;
7417 Next_Discriminant (Discr);
7421 if No (Discr) and then Present (Constr) then
7422 Error_Msg_N ("too many discriminants given in constraint", Constr);
7423 return New_Elmt_List;
7426 -- Named associations can be given in any order, but if both positional
7427 -- and named associations are used in the same discriminant constraint,
7428 -- then positional associations must occur first, at their normal
7429 -- position. Hence once a named association is used, the rest of the
7430 -- discriminant constraint must use only named associations.
7432 while Present (Constr) loop
7434 -- Positional association forbidden after a named association
7436 if Nkind (Constr) /= N_Discriminant_Association then
7437 Error_Msg_N ("positional association follows named one", Constr);
7438 return New_Elmt_List;
7440 -- Otherwise it is a named association
7443 -- E records the type of the discriminants in the named
7444 -- association. All the discriminants specified in the same name
7445 -- association must have the same type.
7449 -- Search the list of discriminants in T to see if the simple name
7450 -- given in the constraint matches any of them.
7452 Id := First (Selector_Names (Constr));
7453 while Present (Id) loop
7456 -- If Original_Discriminant is present, we are processing a
7457 -- generic instantiation and this is an instance node. We need
7458 -- to find the name of the corresponding discriminant in the
7459 -- actual record type T and not the name of the discriminant in
7460 -- the generic formal. Example:
7463 -- type G (D : int) is private;
7465 -- subtype W is G (D => 1);
7467 -- type Rec (X : int) is record ... end record;
7468 -- package Q is new P (G => Rec);
7470 -- At the point of the instantiation, formal type G is Rec
7471 -- and therefore when reanalyzing "subtype W is G (D => 1);"
7472 -- which really looks like "subtype W is Rec (D => 1);" at
7473 -- the point of instantiation, we want to find the discriminant
7474 -- that corresponds to D in Rec, i.e. X.
7476 if Present (Original_Discriminant (Id)) then
7477 Discr := Find_Corresponding_Discriminant (Id, T);
7481 Discr := First_Discriminant (T);
7482 while Present (Discr) loop
7483 if Chars (Discr) = Chars (Id) then
7488 Next_Discriminant (Discr);
7492 Error_Msg_N ("& does not match any discriminant", Id);
7493 return New_Elmt_List;
7495 -- The following is only useful for the benefit of generic
7496 -- instances but it does not interfere with other
7497 -- processing for the non-generic case so we do it in all
7498 -- cases (for generics this statement is executed when
7499 -- processing the generic definition, see comment at the
7500 -- beginning of this if statement).
7503 Set_Original_Discriminant (Id, Discr);
7507 Position := Pos_Of_Discr (T, Discr);
7509 if Present (Discr_Expr (Position)) then
7510 Error_Msg_N ("duplicate constraint for discriminant&", Id);
7513 -- Each discriminant specified in the same named association
7514 -- must be associated with a separate copy of the
7515 -- corresponding expression.
7517 if Present (Next (Id)) then
7518 Expr := New_Copy_Tree (Expression (Constr));
7519 Set_Parent (Expr, Parent (Expression (Constr)));
7521 Expr := Expression (Constr);
7524 Discr_Expr (Position) := Expr;
7525 Analyze_And_Resolve (Expr, Base_Type (Etype (Discr)));
7528 -- A discriminant association with more than one discriminant
7529 -- name is only allowed if the named discriminants are all of
7530 -- the same type (RM 3.7.1(8)).
7533 E := Base_Type (Etype (Discr));
7535 elsif Base_Type (Etype (Discr)) /= E then
7537 ("all discriminants in an association " &
7538 "must have the same type", Id);
7548 -- A discriminant constraint must provide exactly one value for each
7549 -- discriminant of the type (RM 3.7.1(8)).
7551 for J in Discr_Expr'Range loop
7552 if No (Discr_Expr (J)) then
7553 Error_Msg_N ("too few discriminants given in constraint", C);
7554 return New_Elmt_List;
7558 -- Determine if there are discriminant expressions in the constraint
7560 for J in Discr_Expr'Range loop
7561 if Denotes_Discriminant
7562 (Discr_Expr (J), Check_Concurrent => True)
7564 Discrim_Present := True;
7568 -- Build an element list consisting of the expressions given in the
7569 -- discriminant constraint and apply the appropriate checks. The list
7570 -- is constructed after resolving any named discriminant associations
7571 -- and therefore the expressions appear in the textual order of the
7574 Discr := First_Discriminant (T);
7575 for J in Discr_Expr'Range loop
7576 if Discr_Expr (J) /= Error then
7577 Append_Elmt (Discr_Expr (J), Elist);
7579 -- If any of the discriminant constraints is given by a
7580 -- discriminant and we are in a derived type declaration we
7581 -- have a discriminant renaming. Establish link between new
7582 -- and old discriminant.
7584 if Denotes_Discriminant (Discr_Expr (J)) then
7586 Set_Corresponding_Discriminant
7587 (Entity (Discr_Expr (J)), Discr);
7590 -- Force the evaluation of non-discriminant expressions.
7591 -- If we have found a discriminant in the constraint 3.4(26)
7592 -- and 3.8(18) demand that no range checks are performed are
7593 -- after evaluation. If the constraint is for a component
7594 -- definition that has a per-object constraint, expressions are
7595 -- evaluated but not checked either. In all other cases perform
7599 if Discrim_Present then
7602 elsif Nkind (Parent (Parent (Def))) = N_Component_Declaration
7604 Has_Per_Object_Constraint
7605 (Defining_Identifier (Parent (Parent (Def))))
7609 elsif Is_Access_Type (Etype (Discr)) then
7610 Apply_Constraint_Check (Discr_Expr (J), Etype (Discr));
7613 Apply_Range_Check (Discr_Expr (J), Etype (Discr));
7616 Force_Evaluation (Discr_Expr (J));
7619 -- Check that the designated type of an access discriminant's
7620 -- expression is not a class-wide type unless the discriminant's
7621 -- designated type is also class-wide.
7623 if Ekind (Etype (Discr)) = E_Anonymous_Access_Type
7624 and then not Is_Class_Wide_Type
7625 (Designated_Type (Etype (Discr)))
7626 and then Etype (Discr_Expr (J)) /= Any_Type
7627 and then Is_Class_Wide_Type
7628 (Designated_Type (Etype (Discr_Expr (J))))
7630 Wrong_Type (Discr_Expr (J), Etype (Discr));
7632 elsif Is_Access_Type (Etype (Discr))
7633 and then not Is_Access_Constant (Etype (Discr))
7634 and then Is_Access_Type (Etype (Discr_Expr (J)))
7635 and then Is_Access_Constant (Etype (Discr_Expr (J)))
7638 ("constraint for discriminant& must be access to variable",
7643 Next_Discriminant (Discr);
7647 end Build_Discriminant_Constraints;
7649 ---------------------------------
7650 -- Build_Discriminated_Subtype --
7651 ---------------------------------
7653 procedure Build_Discriminated_Subtype
7657 Related_Nod : Node_Id;
7658 For_Access : Boolean := False)
7660 Has_Discrs : constant Boolean := Has_Discriminants (T);
7661 Constrained : constant Boolean :=
7663 and then not Is_Empty_Elmt_List (Elist)
7664 and then not Is_Class_Wide_Type (T))
7665 or else Is_Constrained (T);
7668 if Ekind (T) = E_Record_Type then
7670 Set_Ekind (Def_Id, E_Private_Subtype);
7671 Set_Is_For_Access_Subtype (Def_Id, True);
7673 Set_Ekind (Def_Id, E_Record_Subtype);
7676 -- Inherit preelaboration flag from base, for types for which it
7677 -- may have been set: records, private types, protected types.
7679 Set_Known_To_Have_Preelab_Init
7680 (Def_Id, Known_To_Have_Preelab_Init (T));
7682 elsif Ekind (T) = E_Task_Type then
7683 Set_Ekind (Def_Id, E_Task_Subtype);
7685 elsif Ekind (T) = E_Protected_Type then
7686 Set_Ekind (Def_Id, E_Protected_Subtype);
7687 Set_Known_To_Have_Preelab_Init
7688 (Def_Id, Known_To_Have_Preelab_Init (T));
7690 elsif Is_Private_Type (T) then
7691 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
7692 Set_Known_To_Have_Preelab_Init
7693 (Def_Id, Known_To_Have_Preelab_Init (T));
7695 elsif Is_Class_Wide_Type (T) then
7696 Set_Ekind (Def_Id, E_Class_Wide_Subtype);
7699 -- Incomplete type. Attach subtype to list of dependents, to be
7700 -- completed with full view of parent type, unless is it the
7701 -- designated subtype of a record component within an init_proc.
7702 -- This last case arises for a component of an access type whose
7703 -- designated type is incomplete (e.g. a Taft Amendment type).
7704 -- The designated subtype is within an inner scope, and needs no
7705 -- elaboration, because only the access type is needed in the
7706 -- initialization procedure.
7708 Set_Ekind (Def_Id, Ekind (T));
7710 if For_Access and then Within_Init_Proc then
7713 Append_Elmt (Def_Id, Private_Dependents (T));
7717 Set_Etype (Def_Id, T);
7718 Init_Size_Align (Def_Id);
7719 Set_Has_Discriminants (Def_Id, Has_Discrs);
7720 Set_Is_Constrained (Def_Id, Constrained);
7722 Set_First_Entity (Def_Id, First_Entity (T));
7723 Set_Last_Entity (Def_Id, Last_Entity (T));
7725 -- If the subtype is the completion of a private declaration, there may
7726 -- have been representation clauses for the partial view, and they must
7727 -- be preserved. Build_Derived_Type chains the inherited clauses with
7728 -- the ones appearing on the extension. If this comes from a subtype
7729 -- declaration, all clauses are inherited.
7731 if No (First_Rep_Item (Def_Id)) then
7732 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
7735 if Is_Tagged_Type (T) then
7736 Set_Is_Tagged_Type (Def_Id);
7737 Make_Class_Wide_Type (Def_Id);
7740 Set_Stored_Constraint (Def_Id, No_Elist);
7743 Set_Discriminant_Constraint (Def_Id, Elist);
7744 Set_Stored_Constraint_From_Discriminant_Constraint (Def_Id);
7747 if Is_Tagged_Type (T) then
7749 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
7750 -- concurrent record type (which has the list of primitive
7753 if Ada_Version >= Ada_05
7754 and then Is_Concurrent_Type (T)
7756 Set_Corresponding_Record_Type (Def_Id,
7757 Corresponding_Record_Type (T));
7759 Set_Primitive_Operations (Def_Id, Primitive_Operations (T));
7762 Set_Is_Abstract_Type (Def_Id, Is_Abstract_Type (T));
7765 -- Subtypes introduced by component declarations do not need to be
7766 -- marked as delayed, and do not get freeze nodes, because the semantics
7767 -- verifies that the parents of the subtypes are frozen before the
7768 -- enclosing record is frozen.
7770 if not Is_Type (Scope (Def_Id)) then
7771 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
7773 if Is_Private_Type (T)
7774 and then Present (Full_View (T))
7776 Conditional_Delay (Def_Id, Full_View (T));
7778 Conditional_Delay (Def_Id, T);
7782 if Is_Record_Type (T) then
7783 Set_Is_Limited_Record (Def_Id, Is_Limited_Record (T));
7786 and then not Is_Empty_Elmt_List (Elist)
7787 and then not For_Access
7789 Create_Constrained_Components (Def_Id, Related_Nod, T, Elist);
7790 elsif not For_Access then
7791 Set_Cloned_Subtype (Def_Id, T);
7794 end Build_Discriminated_Subtype;
7796 ---------------------------
7797 -- Build_Itype_Reference --
7798 ---------------------------
7800 procedure Build_Itype_Reference
7804 IR : constant Node_Id := Make_Itype_Reference (Sloc (Nod));
7806 Set_Itype (IR, Ityp);
7807 Insert_After (Nod, IR);
7808 end Build_Itype_Reference;
7810 ------------------------
7811 -- Build_Scalar_Bound --
7812 ------------------------
7814 function Build_Scalar_Bound
7817 Der_T : Entity_Id) return Node_Id
7819 New_Bound : Entity_Id;
7822 -- Note: not clear why this is needed, how can the original bound
7823 -- be unanalyzed at this point? and if it is, what business do we
7824 -- have messing around with it? and why is the base type of the
7825 -- parent type the right type for the resolution. It probably is
7826 -- not! It is OK for the new bound we are creating, but not for
7827 -- the old one??? Still if it never happens, no problem!
7829 Analyze_And_Resolve (Bound, Base_Type (Par_T));
7831 if Nkind_In (Bound, N_Integer_Literal, N_Real_Literal) then
7832 New_Bound := New_Copy (Bound);
7833 Set_Etype (New_Bound, Der_T);
7834 Set_Analyzed (New_Bound);
7836 elsif Is_Entity_Name (Bound) then
7837 New_Bound := OK_Convert_To (Der_T, New_Copy (Bound));
7839 -- The following is almost certainly wrong. What business do we have
7840 -- relocating a node (Bound) that is presumably still attached to
7841 -- the tree elsewhere???
7844 New_Bound := OK_Convert_To (Der_T, Relocate_Node (Bound));
7847 Set_Etype (New_Bound, Der_T);
7849 end Build_Scalar_Bound;
7851 --------------------------------
7852 -- Build_Underlying_Full_View --
7853 --------------------------------
7855 procedure Build_Underlying_Full_View
7860 Loc : constant Source_Ptr := Sloc (N);
7861 Subt : constant Entity_Id :=
7862 Make_Defining_Identifier
7863 (Loc, New_External_Name (Chars (Typ), 'S'));
7870 procedure Set_Discriminant_Name (Id : Node_Id);
7871 -- If the derived type has discriminants, they may rename discriminants
7872 -- of the parent. When building the full view of the parent, we need to
7873 -- recover the names of the original discriminants if the constraint is
7874 -- given by named associations.
7876 ---------------------------
7877 -- Set_Discriminant_Name --
7878 ---------------------------
7880 procedure Set_Discriminant_Name (Id : Node_Id) is
7884 Set_Original_Discriminant (Id, Empty);
7886 if Has_Discriminants (Typ) then
7887 Disc := First_Discriminant (Typ);
7888 while Present (Disc) loop
7889 if Chars (Disc) = Chars (Id)
7890 and then Present (Corresponding_Discriminant (Disc))
7892 Set_Chars (Id, Chars (Corresponding_Discriminant (Disc)));
7894 Next_Discriminant (Disc);
7897 end Set_Discriminant_Name;
7899 -- Start of processing for Build_Underlying_Full_View
7902 if Nkind (N) = N_Full_Type_Declaration then
7903 Constr := Constraint (Subtype_Indication (Type_Definition (N)));
7905 elsif Nkind (N) = N_Subtype_Declaration then
7906 Constr := New_Copy_Tree (Constraint (Subtype_Indication (N)));
7908 elsif Nkind (N) = N_Component_Declaration then
7911 (Constraint (Subtype_Indication (Component_Definition (N))));
7914 raise Program_Error;
7917 C := First (Constraints (Constr));
7918 while Present (C) loop
7919 if Nkind (C) = N_Discriminant_Association then
7920 Id := First (Selector_Names (C));
7921 while Present (Id) loop
7922 Set_Discriminant_Name (Id);
7931 Make_Subtype_Declaration (Loc,
7932 Defining_Identifier => Subt,
7933 Subtype_Indication =>
7934 Make_Subtype_Indication (Loc,
7935 Subtype_Mark => New_Reference_To (Par, Loc),
7936 Constraint => New_Copy_Tree (Constr)));
7938 -- If this is a component subtype for an outer itype, it is not
7939 -- a list member, so simply set the parent link for analysis: if
7940 -- the enclosing type does not need to be in a declarative list,
7941 -- neither do the components.
7943 if Is_List_Member (N)
7944 and then Nkind (N) /= N_Component_Declaration
7946 Insert_Before (N, Indic);
7948 Set_Parent (Indic, Parent (N));
7952 Set_Underlying_Full_View (Typ, Full_View (Subt));
7953 end Build_Underlying_Full_View;
7955 -------------------------------
7956 -- Check_Abstract_Overriding --
7957 -------------------------------
7959 procedure Check_Abstract_Overriding (T : Entity_Id) is
7960 Alias_Subp : Entity_Id;
7967 Op_List := Primitive_Operations (T);
7969 -- Loop to check primitive operations
7971 Elmt := First_Elmt (Op_List);
7972 while Present (Elmt) loop
7973 Subp := Node (Elmt);
7974 Alias_Subp := Alias (Subp);
7976 -- Inherited subprograms are identified by the fact that they do not
7977 -- come from source, and the associated source location is the
7978 -- location of the first subtype of the derived type.
7980 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
7981 -- subprograms that "require overriding".
7983 -- Special exception, do not complain about failure to override the
7984 -- stream routines _Input and _Output, as well as the primitive
7985 -- operations used in dispatching selects since we always provide
7986 -- automatic overridings for these subprograms.
7988 -- Also ignore this rule for convention CIL since .NET libraries
7989 -- do bizarre things with interfaces???
7991 -- The partial view of T may have been a private extension, for
7992 -- which inherited functions dispatching on result are abstract.
7993 -- If the full view is a null extension, there is no need for
7994 -- overriding in Ada2005, but wrappers need to be built for them
7995 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
7997 if Is_Null_Extension (T)
7998 and then Has_Controlling_Result (Subp)
7999 and then Ada_Version >= Ada_05
8000 and then Present (Alias_Subp)
8001 and then not Comes_From_Source (Subp)
8002 and then not Is_Abstract_Subprogram (Alias_Subp)
8003 and then not Is_Access_Type (Etype (Subp))
8007 -- Ada 2005 (AI-251): Internal entities of interfaces need no
8008 -- processing because this check is done with the aliased
8011 elsif Present (Interface_Alias (Subp)) then
8014 elsif (Is_Abstract_Subprogram (Subp)
8015 or else Requires_Overriding (Subp)
8017 (Has_Controlling_Result (Subp)
8018 and then Present (Alias_Subp)
8019 and then not Comes_From_Source (Subp)
8020 and then Sloc (Subp) = Sloc (First_Subtype (T))))
8021 and then not Is_TSS (Subp, TSS_Stream_Input)
8022 and then not Is_TSS (Subp, TSS_Stream_Output)
8023 and then not Is_Abstract_Type (T)
8024 and then Convention (T) /= Convention_CIL
8025 and then not Is_Predefined_Interface_Primitive (Subp)
8027 -- Ada 2005 (AI-251): Do not consider hidden entities associated
8028 -- with abstract interface types because the check will be done
8029 -- with the aliased entity (otherwise we generate a duplicated
8032 and then not Present (Interface_Alias (Subp))
8034 if Present (Alias_Subp) then
8036 -- Only perform the check for a derived subprogram when the
8037 -- type has an explicit record extension. This avoids incorrect
8038 -- flagging of abstract subprograms for the case of a type
8039 -- without an extension that is derived from a formal type
8040 -- with a tagged actual (can occur within a private part).
8042 -- Ada 2005 (AI-391): In the case of an inherited function with
8043 -- a controlling result of the type, the rule does not apply if
8044 -- the type is a null extension (unless the parent function
8045 -- itself is abstract, in which case the function must still be
8046 -- be overridden). The expander will generate an overriding
8047 -- wrapper function calling the parent subprogram (see
8048 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
8050 Type_Def := Type_Definition (Parent (T));
8052 if Nkind (Type_Def) = N_Derived_Type_Definition
8053 and then Present (Record_Extension_Part (Type_Def))
8055 (Ada_Version < Ada_05
8056 or else not Is_Null_Extension (T)
8057 or else Ekind (Subp) = E_Procedure
8058 or else not Has_Controlling_Result (Subp)
8059 or else Is_Abstract_Subprogram (Alias_Subp)
8060 or else Requires_Overriding (Subp)
8061 or else Is_Access_Type (Etype (Subp)))
8063 -- Avoid reporting error in case of abstract predefined
8064 -- primitive inherited from interface type because the
8065 -- body of internally generated predefined primitives
8066 -- of tagged types are generated later by Freeze_Type
8068 if Is_Interface (Root_Type (T))
8069 and then Is_Abstract_Subprogram (Subp)
8070 and then Is_Predefined_Dispatching_Operation (Subp)
8071 and then not Comes_From_Source (Ultimate_Alias (Subp))
8077 ("type must be declared abstract or & overridden",
8080 -- Traverse the whole chain of aliased subprograms to
8081 -- complete the error notification. This is especially
8082 -- useful for traceability of the chain of entities when
8083 -- the subprogram corresponds with an interface
8084 -- subprogram (which may be defined in another package).
8086 if Present (Alias_Subp) then
8092 while Present (Alias (E)) loop
8093 Error_Msg_Sloc := Sloc (E);
8095 ("\& has been inherited #", T, Subp);
8099 Error_Msg_Sloc := Sloc (E);
8101 ("\& has been inherited from subprogram #",
8107 -- Ada 2005 (AI-345): Protected or task type implementing
8108 -- abstract interfaces.
8110 elsif Is_Concurrent_Record_Type (T)
8111 and then Present (Interfaces (T))
8113 -- The controlling formal of Subp must be of mode "out",
8114 -- "in out" or an access-to-variable to be overridden.
8116 -- Error message below needs rewording (remember comma
8117 -- in -gnatj mode) ???
8119 if Ekind (First_Formal (Subp)) = E_In_Parameter then
8120 if not Is_Predefined_Dispatching_Operation (Subp) then
8122 ("first formal of & must be of mode `OUT`, " &
8123 "`IN OUT` or access-to-variable", T, Subp);
8125 ("\to be overridden by protected procedure or " &
8126 "entry (RM 9.4(11.9/2))", T);
8129 -- Some other kind of overriding failure
8133 ("interface subprogram & must be overridden",
8139 Error_Msg_Node_2 := T;
8141 ("abstract subprogram& not allowed for type&", Subp);
8143 -- Also post unconditional warning on the type (unconditional
8144 -- so that if there are more than one of these cases, we get
8145 -- them all, and not just the first one).
8147 Error_Msg_Node_2 := Subp;
8149 ("nonabstract type& has abstract subprogram&!", T);
8153 -- Ada 2005 (AI05-0030): Inspect hidden subprograms which provide
8154 -- the mapping between interface and implementing type primitives.
8155 -- If the interface alias is marked as Implemented_By_Entry, the
8156 -- alias must be an entry wrapper.
8158 if Ada_Version >= Ada_05
8159 and then Is_Hidden (Subp)
8160 and then Present (Interface_Alias (Subp))
8161 and then Implemented_By_Entry (Interface_Alias (Subp))
8162 and then Present (Alias_Subp)
8164 (not Is_Primitive_Wrapper (Alias_Subp)
8165 or else Ekind (Wrapped_Entity (Alias_Subp)) /= E_Entry)
8168 Error_Ent : Entity_Id := T;
8171 if Is_Concurrent_Record_Type (Error_Ent) then
8172 Error_Ent := Corresponding_Concurrent_Type (Error_Ent);
8175 Error_Msg_Node_2 := Interface_Alias (Subp);
8177 ("type & must implement abstract subprogram & with an entry",
8178 Error_Ent, Error_Ent);
8184 end Check_Abstract_Overriding;
8186 ------------------------------------------------
8187 -- Check_Access_Discriminant_Requires_Limited --
8188 ------------------------------------------------
8190 procedure Check_Access_Discriminant_Requires_Limited
8195 -- A discriminant_specification for an access discriminant shall appear
8196 -- only in the declaration for a task or protected type, or for a type
8197 -- with the reserved word 'limited' in its definition or in one of its
8198 -- ancestors. (RM 3.7(10))
8200 if Nkind (Discriminant_Type (D)) = N_Access_Definition
8201 and then not Is_Concurrent_Type (Current_Scope)
8202 and then not Is_Concurrent_Record_Type (Current_Scope)
8203 and then not Is_Limited_Record (Current_Scope)
8204 and then Ekind (Current_Scope) /= E_Limited_Private_Type
8207 ("access discriminants allowed only for limited types", Loc);
8209 end Check_Access_Discriminant_Requires_Limited;
8211 -----------------------------------
8212 -- Check_Aliased_Component_Types --
8213 -----------------------------------
8215 procedure Check_Aliased_Component_Types (T : Entity_Id) is
8219 -- ??? Also need to check components of record extensions, but not
8220 -- components of protected types (which are always limited).
8222 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
8223 -- types to be unconstrained. This is safe because it is illegal to
8224 -- create access subtypes to such types with explicit discriminant
8227 if not Is_Limited_Type (T) then
8228 if Ekind (T) = E_Record_Type then
8229 C := First_Component (T);
8230 while Present (C) loop
8232 and then Has_Discriminants (Etype (C))
8233 and then not Is_Constrained (Etype (C))
8234 and then not In_Instance_Body
8235 and then Ada_Version < Ada_05
8238 ("aliased component must be constrained (RM 3.6(11))",
8245 elsif Ekind (T) = E_Array_Type then
8246 if Has_Aliased_Components (T)
8247 and then Has_Discriminants (Component_Type (T))
8248 and then not Is_Constrained (Component_Type (T))
8249 and then not In_Instance_Body
8250 and then Ada_Version < Ada_05
8253 ("aliased component type must be constrained (RM 3.6(11))",
8258 end Check_Aliased_Component_Types;
8260 ----------------------
8261 -- Check_Completion --
8262 ----------------------
8264 procedure Check_Completion (Body_Id : Node_Id := Empty) is
8267 procedure Post_Error;
8268 -- Post error message for lack of completion for entity E
8274 procedure Post_Error is
8276 if not Comes_From_Source (E) then
8278 if Ekind (E) = E_Task_Type
8279 or else Ekind (E) = E_Protected_Type
8281 -- It may be an anonymous protected type created for a
8282 -- single variable. Post error on variable, if present.
8288 Var := First_Entity (Current_Scope);
8289 while Present (Var) loop
8290 exit when Etype (Var) = E
8291 and then Comes_From_Source (Var);
8296 if Present (Var) then
8303 -- If a generated entity has no completion, then either previous
8304 -- semantic errors have disabled the expansion phase, or else we had
8305 -- missing subunits, or else we are compiling without expansion,
8306 -- or else something is very wrong.
8308 if not Comes_From_Source (E) then
8310 (Serious_Errors_Detected > 0
8311 or else Configurable_Run_Time_Violations > 0
8312 or else Subunits_Missing
8313 or else not Expander_Active);
8316 -- Here for source entity
8319 -- Here if no body to post the error message, so we post the error
8320 -- on the declaration that has no completion. This is not really
8321 -- the right place to post it, think about this later ???
8323 if No (Body_Id) then
8326 ("missing full declaration for }", Parent (E), E);
8329 ("missing body for &", Parent (E), E);
8332 -- Package body has no completion for a declaration that appears
8333 -- in the corresponding spec. Post error on the body, with a
8334 -- reference to the non-completed declaration.
8337 Error_Msg_Sloc := Sloc (E);
8341 ("missing full declaration for }!", Body_Id, E);
8343 elsif Is_Overloadable (E)
8344 and then Current_Entity_In_Scope (E) /= E
8346 -- It may be that the completion is mistyped and appears as
8347 -- a distinct overloading of the entity.
8350 Candidate : constant Entity_Id :=
8351 Current_Entity_In_Scope (E);
8352 Decl : constant Node_Id :=
8353 Unit_Declaration_Node (Candidate);
8356 if Is_Overloadable (Candidate)
8357 and then Ekind (Candidate) = Ekind (E)
8358 and then Nkind (Decl) = N_Subprogram_Body
8359 and then Acts_As_Spec (Decl)
8361 Check_Type_Conformant (Candidate, E);
8364 Error_Msg_NE ("missing body for & declared#!",
8369 Error_Msg_NE ("missing body for & declared#!",
8376 -- Start processing for Check_Completion
8379 E := First_Entity (Current_Scope);
8380 while Present (E) loop
8381 if Is_Intrinsic_Subprogram (E) then
8384 -- The following situation requires special handling: a child unit
8385 -- that appears in the context clause of the body of its parent:
8387 -- procedure Parent.Child (...);
8389 -- with Parent.Child;
8390 -- package body Parent is
8392 -- Here Parent.Child appears as a local entity, but should not be
8393 -- flagged as requiring completion, because it is a compilation
8396 -- Ignore missing completion for a subprogram that does not come from
8397 -- source (including the _Call primitive operation of RAS types,
8398 -- which has to have the flag Comes_From_Source for other purposes):
8399 -- we assume that the expander will provide the missing completion.
8401 elsif Ekind (E) = E_Function
8402 or else Ekind (E) = E_Procedure
8403 or else Ekind (E) = E_Generic_Function
8404 or else Ekind (E) = E_Generic_Procedure
8406 if not Has_Completion (E)
8407 and then not (Is_Subprogram (E)
8408 and then Is_Abstract_Subprogram (E))
8409 and then not (Is_Subprogram (E)
8411 (not Comes_From_Source (E)
8412 or else Chars (E) = Name_uCall))
8413 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8415 and then Chars (E) /= Name_uSize
8420 elsif Is_Entry (E) then
8421 if not Has_Completion (E) and then
8422 (Ekind (Scope (E)) = E_Protected_Object
8423 or else Ekind (Scope (E)) = E_Protected_Type)
8428 elsif Is_Package_Or_Generic_Package (E) then
8429 if Unit_Requires_Body (E) then
8430 if not Has_Completion (E)
8431 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8437 elsif not Is_Child_Unit (E) then
8438 May_Need_Implicit_Body (E);
8441 elsif Ekind (E) = E_Incomplete_Type
8442 and then No (Underlying_Type (E))
8446 elsif (Ekind (E) = E_Task_Type or else
8447 Ekind (E) = E_Protected_Type)
8448 and then not Has_Completion (E)
8452 -- A single task declared in the current scope is a constant, verify
8453 -- that the body of its anonymous type is in the same scope. If the
8454 -- task is defined elsewhere, this may be a renaming declaration for
8455 -- which no completion is needed.
8457 elsif Ekind (E) = E_Constant
8458 and then Ekind (Etype (E)) = E_Task_Type
8459 and then not Has_Completion (Etype (E))
8460 and then Scope (Etype (E)) = Current_Scope
8464 elsif Ekind (E) = E_Protected_Object
8465 and then not Has_Completion (Etype (E))
8469 elsif Ekind (E) = E_Record_Type then
8470 if Is_Tagged_Type (E) then
8471 Check_Abstract_Overriding (E);
8472 Check_Conventions (E);
8475 Check_Aliased_Component_Types (E);
8477 elsif Ekind (E) = E_Array_Type then
8478 Check_Aliased_Component_Types (E);
8484 end Check_Completion;
8486 ----------------------------
8487 -- Check_Delta_Expression --
8488 ----------------------------
8490 procedure Check_Delta_Expression (E : Node_Id) is
8492 if not (Is_Real_Type (Etype (E))) then
8493 Wrong_Type (E, Any_Real);
8495 elsif not Is_OK_Static_Expression (E) then
8496 Flag_Non_Static_Expr
8497 ("non-static expression used for delta value!", E);
8499 elsif not UR_Is_Positive (Expr_Value_R (E)) then
8500 Error_Msg_N ("delta expression must be positive", E);
8506 -- If any of above errors occurred, then replace the incorrect
8507 -- expression by the real 0.1, which should prevent further errors.
8510 Make_Real_Literal (Sloc (E), Ureal_Tenth));
8511 Analyze_And_Resolve (E, Standard_Float);
8512 end Check_Delta_Expression;
8514 -----------------------------
8515 -- Check_Digits_Expression --
8516 -----------------------------
8518 procedure Check_Digits_Expression (E : Node_Id) is
8520 if not (Is_Integer_Type (Etype (E))) then
8521 Wrong_Type (E, Any_Integer);
8523 elsif not Is_OK_Static_Expression (E) then
8524 Flag_Non_Static_Expr
8525 ("non-static expression used for digits value!", E);
8527 elsif Expr_Value (E) <= 0 then
8528 Error_Msg_N ("digits value must be greater than zero", E);
8534 -- If any of above errors occurred, then replace the incorrect
8535 -- expression by the integer 1, which should prevent further errors.
8537 Rewrite (E, Make_Integer_Literal (Sloc (E), 1));
8538 Analyze_And_Resolve (E, Standard_Integer);
8540 end Check_Digits_Expression;
8542 --------------------------
8543 -- Check_Initialization --
8544 --------------------------
8546 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id) is
8548 if Is_Limited_Type (T)
8549 and then not In_Instance
8550 and then not In_Inlined_Body
8552 if not OK_For_Limited_Init (Exp) then
8554 -- In GNAT mode, this is just a warning, to allow it to be evilly
8555 -- turned off. Otherwise it is a real error.
8559 ("?cannot initialize entities of limited type!", Exp);
8561 elsif Ada_Version < Ada_05 then
8563 ("cannot initialize entities of limited type", Exp);
8564 Explain_Limited_Type (T, Exp);
8567 -- Specialize error message according to kind of illegal
8568 -- initial expression.
8570 if Nkind (Exp) = N_Type_Conversion
8571 and then Nkind (Expression (Exp)) = N_Function_Call
8574 ("illegal context for call"
8575 & " to function with limited result", Exp);
8579 ("initialization of limited object requires aggregate "
8580 & "or function call", Exp);
8585 end Check_Initialization;
8587 ----------------------
8588 -- Check_Interfaces --
8589 ----------------------
8591 procedure Check_Interfaces (N : Node_Id; Def : Node_Id) is
8592 Parent_Type : constant Entity_Id := Etype (Defining_Identifier (N));
8595 Iface_Def : Node_Id;
8596 Iface_Typ : Entity_Id;
8597 Parent_Node : Node_Id;
8599 Is_Task : Boolean := False;
8600 -- Set True if parent type or any progenitor is a task interface
8602 Is_Protected : Boolean := False;
8603 -- Set True if parent type or any progenitor is a protected interface
8605 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id);
8606 -- Check that a progenitor is compatible with declaration.
8607 -- Error is posted on Error_Node.
8613 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id) is
8614 Iface_Id : constant Entity_Id :=
8615 Defining_Identifier (Parent (Iface_Def));
8619 if Nkind (N) = N_Private_Extension_Declaration then
8622 Type_Def := Type_Definition (N);
8625 if Is_Task_Interface (Iface_Id) then
8628 elsif Is_Protected_Interface (Iface_Id) then
8629 Is_Protected := True;
8632 -- Check that the characteristics of the progenitor are compatible
8633 -- with the explicit qualifier in the declaration.
8634 -- The check only applies to qualifiers that come from source.
8635 -- Limited_Present also appears in the declaration of corresponding
8636 -- records, and the check does not apply to them.
8638 if Limited_Present (Type_Def)
8640 Is_Concurrent_Record_Type (Defining_Identifier (N))
8642 if Is_Limited_Interface (Parent_Type)
8643 and then not Is_Limited_Interface (Iface_Id)
8646 ("progenitor& must be limited interface",
8647 Error_Node, Iface_Id);
8650 (Task_Present (Iface_Def)
8651 or else Protected_Present (Iface_Def)
8652 or else Synchronized_Present (Iface_Def))
8653 and then Nkind (N) /= N_Private_Extension_Declaration
8656 ("progenitor& must be limited interface",
8657 Error_Node, Iface_Id);
8660 -- Protected interfaces can only inherit from limited, synchronized
8661 -- or protected interfaces.
8663 elsif Nkind (N) = N_Full_Type_Declaration
8664 and then Protected_Present (Type_Def)
8666 if Limited_Present (Iface_Def)
8667 or else Synchronized_Present (Iface_Def)
8668 or else Protected_Present (Iface_Def)
8672 elsif Task_Present (Iface_Def) then
8673 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
8674 & " from task interface", Error_Node);
8677 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
8678 & " from non-limited interface", Error_Node);
8681 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
8682 -- limited and synchronized.
8684 elsif Synchronized_Present (Type_Def) then
8685 if Limited_Present (Iface_Def)
8686 or else Synchronized_Present (Iface_Def)
8690 elsif Protected_Present (Iface_Def)
8691 and then Nkind (N) /= N_Private_Extension_Declaration
8693 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8694 & " from protected interface", Error_Node);
8696 elsif Task_Present (Iface_Def)
8697 and then Nkind (N) /= N_Private_Extension_Declaration
8699 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8700 & " from task interface", Error_Node);
8702 elsif not Is_Limited_Interface (Iface_Id) then
8703 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8704 & " from non-limited interface", Error_Node);
8707 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
8708 -- synchronized or task interfaces.
8710 elsif Nkind (N) = N_Full_Type_Declaration
8711 and then Task_Present (Type_Def)
8713 if Limited_Present (Iface_Def)
8714 or else Synchronized_Present (Iface_Def)
8715 or else Task_Present (Iface_Def)
8719 elsif Protected_Present (Iface_Def) then
8720 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
8721 & " protected interface", Error_Node);
8724 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
8725 & " non-limited interface", Error_Node);
8730 -- Start of processing for Check_Interfaces
8733 if Is_Interface (Parent_Type) then
8734 if Is_Task_Interface (Parent_Type) then
8737 elsif Is_Protected_Interface (Parent_Type) then
8738 Is_Protected := True;
8742 if Nkind (N) = N_Private_Extension_Declaration then
8744 -- Check that progenitors are compatible with declaration
8746 Iface := First (Interface_List (Def));
8747 while Present (Iface) loop
8748 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8750 Parent_Node := Parent (Base_Type (Iface_Typ));
8751 Iface_Def := Type_Definition (Parent_Node);
8753 if not Is_Interface (Iface_Typ) then
8754 Diagnose_Interface (Iface, Iface_Typ);
8757 Check_Ifaces (Iface_Def, Iface);
8763 if Is_Task and Is_Protected then
8765 ("type cannot derive from task and protected interface", N);
8771 -- Full type declaration of derived type.
8772 -- Check compatibility with parent if it is interface type
8774 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition
8775 and then Is_Interface (Parent_Type)
8777 Parent_Node := Parent (Parent_Type);
8779 -- More detailed checks for interface varieties
8782 (Iface_Def => Type_Definition (Parent_Node),
8783 Error_Node => Subtype_Indication (Type_Definition (N)));
8786 Iface := First (Interface_List (Def));
8787 while Present (Iface) loop
8788 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8790 Parent_Node := Parent (Base_Type (Iface_Typ));
8791 Iface_Def := Type_Definition (Parent_Node);
8793 if not Is_Interface (Iface_Typ) then
8794 Diagnose_Interface (Iface, Iface_Typ);
8797 -- "The declaration of a specific descendant of an interface
8798 -- type freezes the interface type" RM 13.14
8800 Freeze_Before (N, Iface_Typ);
8801 Check_Ifaces (Iface_Def, Error_Node => Iface);
8807 if Is_Task and Is_Protected then
8809 ("type cannot derive from task and protected interface", N);
8811 end Check_Interfaces;
8813 ------------------------------------
8814 -- Check_Or_Process_Discriminants --
8815 ------------------------------------
8817 -- If an incomplete or private type declaration was already given for the
8818 -- type, the discriminants may have already been processed if they were
8819 -- present on the incomplete declaration. In this case a full conformance
8820 -- check is performed otherwise just process them.
8822 procedure Check_Or_Process_Discriminants
8825 Prev : Entity_Id := Empty)
8828 if Has_Discriminants (T) then
8830 -- Make the discriminants visible to component declarations
8837 D := First_Discriminant (T);
8838 while Present (D) loop
8839 Prev := Current_Entity (D);
8840 Set_Current_Entity (D);
8841 Set_Is_Immediately_Visible (D);
8842 Set_Homonym (D, Prev);
8844 -- Ada 2005 (AI-230): Access discriminant allowed in
8845 -- non-limited record types.
8847 if Ada_Version < Ada_05 then
8849 -- This restriction gets applied to the full type here. It
8850 -- has already been applied earlier to the partial view.
8852 Check_Access_Discriminant_Requires_Limited (Parent (D), N);
8855 Next_Discriminant (D);
8859 elsif Present (Discriminant_Specifications (N)) then
8860 Process_Discriminants (N, Prev);
8862 end Check_Or_Process_Discriminants;
8864 ----------------------
8865 -- Check_Real_Bound --
8866 ----------------------
8868 procedure Check_Real_Bound (Bound : Node_Id) is
8870 if not Is_Real_Type (Etype (Bound)) then
8872 ("bound in real type definition must be of real type", Bound);
8874 elsif not Is_OK_Static_Expression (Bound) then
8875 Flag_Non_Static_Expr
8876 ("non-static expression used for real type bound!", Bound);
8883 (Bound, Make_Real_Literal (Sloc (Bound), Ureal_0));
8885 Resolve (Bound, Standard_Float);
8886 end Check_Real_Bound;
8888 ------------------------------
8889 -- Complete_Private_Subtype --
8890 ------------------------------
8892 procedure Complete_Private_Subtype
8895 Full_Base : Entity_Id;
8896 Related_Nod : Node_Id)
8898 Save_Next_Entity : Entity_Id;
8899 Save_Homonym : Entity_Id;
8902 -- Set semantic attributes for (implicit) private subtype completion.
8903 -- If the full type has no discriminants, then it is a copy of the full
8904 -- view of the base. Otherwise, it is a subtype of the base with a
8905 -- possible discriminant constraint. Save and restore the original
8906 -- Next_Entity field of full to ensure that the calls to Copy_Node
8907 -- do not corrupt the entity chain.
8909 -- Note that the type of the full view is the same entity as the type of
8910 -- the partial view. In this fashion, the subtype has access to the
8911 -- correct view of the parent.
8913 Save_Next_Entity := Next_Entity (Full);
8914 Save_Homonym := Homonym (Priv);
8916 case Ekind (Full_Base) is
8917 when E_Record_Type |
8923 Copy_Node (Priv, Full);
8925 Set_Has_Discriminants (Full, Has_Discriminants (Full_Base));
8926 Set_First_Entity (Full, First_Entity (Full_Base));
8927 Set_Last_Entity (Full, Last_Entity (Full_Base));
8930 Copy_Node (Full_Base, Full);
8931 Set_Chars (Full, Chars (Priv));
8932 Conditional_Delay (Full, Priv);
8933 Set_Sloc (Full, Sloc (Priv));
8936 Set_Next_Entity (Full, Save_Next_Entity);
8937 Set_Homonym (Full, Save_Homonym);
8938 Set_Associated_Node_For_Itype (Full, Related_Nod);
8940 -- Set common attributes for all subtypes
8942 Set_Ekind (Full, Subtype_Kind (Ekind (Full_Base)));
8944 -- The Etype of the full view is inconsistent. Gigi needs to see the
8945 -- structural full view, which is what the current scheme gives:
8946 -- the Etype of the full view is the etype of the full base. However,
8947 -- if the full base is a derived type, the full view then looks like
8948 -- a subtype of the parent, not a subtype of the full base. If instead
8951 -- Set_Etype (Full, Full_Base);
8953 -- then we get inconsistencies in the front-end (confusion between
8954 -- views). Several outstanding bugs are related to this ???
8956 Set_Is_First_Subtype (Full, False);
8957 Set_Scope (Full, Scope (Priv));
8958 Set_Size_Info (Full, Full_Base);
8959 Set_RM_Size (Full, RM_Size (Full_Base));
8960 Set_Is_Itype (Full);
8962 -- A subtype of a private-type-without-discriminants, whose full-view
8963 -- has discriminants with default expressions, is not constrained!
8965 if not Has_Discriminants (Priv) then
8966 Set_Is_Constrained (Full, Is_Constrained (Full_Base));
8968 if Has_Discriminants (Full_Base) then
8969 Set_Discriminant_Constraint
8970 (Full, Discriminant_Constraint (Full_Base));
8972 -- The partial view may have been indefinite, the full view
8975 Set_Has_Unknown_Discriminants
8976 (Full, Has_Unknown_Discriminants (Full_Base));
8980 Set_First_Rep_Item (Full, First_Rep_Item (Full_Base));
8981 Set_Depends_On_Private (Full, Has_Private_Component (Full));
8983 -- Freeze the private subtype entity if its parent is delayed, and not
8984 -- already frozen. We skip this processing if the type is an anonymous
8985 -- subtype of a record component, or is the corresponding record of a
8986 -- protected type, since ???
8988 if not Is_Type (Scope (Full)) then
8989 Set_Has_Delayed_Freeze (Full,
8990 Has_Delayed_Freeze (Full_Base)
8991 and then (not Is_Frozen (Full_Base)));
8994 Set_Freeze_Node (Full, Empty);
8995 Set_Is_Frozen (Full, False);
8996 Set_Full_View (Priv, Full);
8998 if Has_Discriminants (Full) then
8999 Set_Stored_Constraint_From_Discriminant_Constraint (Full);
9000 Set_Stored_Constraint (Priv, Stored_Constraint (Full));
9002 if Has_Unknown_Discriminants (Full) then
9003 Set_Discriminant_Constraint (Full, No_Elist);
9007 if Ekind (Full_Base) = E_Record_Type
9008 and then Has_Discriminants (Full_Base)
9009 and then Has_Discriminants (Priv) -- might not, if errors
9010 and then not Has_Unknown_Discriminants (Priv)
9011 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Priv))
9013 Create_Constrained_Components
9014 (Full, Related_Nod, Full_Base, Discriminant_Constraint (Priv));
9016 -- If the full base is itself derived from private, build a congruent
9017 -- subtype of its underlying type, for use by the back end. For a
9018 -- constrained record component, the declaration cannot be placed on
9019 -- the component list, but it must nevertheless be built an analyzed, to
9020 -- supply enough information for Gigi to compute the size of component.
9022 elsif Ekind (Full_Base) in Private_Kind
9023 and then Is_Derived_Type (Full_Base)
9024 and then Has_Discriminants (Full_Base)
9025 and then (Ekind (Current_Scope) /= E_Record_Subtype)
9027 if not Is_Itype (Priv)
9029 Nkind (Subtype_Indication (Parent (Priv))) = N_Subtype_Indication
9031 Build_Underlying_Full_View
9032 (Parent (Priv), Full, Etype (Full_Base));
9034 elsif Nkind (Related_Nod) = N_Component_Declaration then
9035 Build_Underlying_Full_View (Related_Nod, Full, Etype (Full_Base));
9038 elsif Is_Record_Type (Full_Base) then
9040 -- Show Full is simply a renaming of Full_Base
9042 Set_Cloned_Subtype (Full, Full_Base);
9045 -- It is unsafe to share to bounds of a scalar type, because the Itype
9046 -- is elaborated on demand, and if a bound is non-static then different
9047 -- orders of elaboration in different units will lead to different
9048 -- external symbols.
9050 if Is_Scalar_Type (Full_Base) then
9051 Set_Scalar_Range (Full,
9052 Make_Range (Sloc (Related_Nod),
9054 Duplicate_Subexpr_No_Checks (Type_Low_Bound (Full_Base)),
9056 Duplicate_Subexpr_No_Checks (Type_High_Bound (Full_Base))));
9058 -- This completion inherits the bounds of the full parent, but if
9059 -- the parent is an unconstrained floating point type, so is the
9062 if Is_Floating_Point_Type (Full_Base) then
9063 Set_Includes_Infinities
9064 (Scalar_Range (Full), Has_Infinities (Full_Base));
9068 -- ??? It seems that a lot of fields are missing that should be copied
9069 -- from Full_Base to Full. Here are some that are introduced in a
9070 -- non-disruptive way but a cleanup is necessary.
9072 if Is_Tagged_Type (Full_Base) then
9073 Set_Is_Tagged_Type (Full);
9074 Set_Primitive_Operations (Full, Primitive_Operations (Full_Base));
9075 Set_Class_Wide_Type (Full, Class_Wide_Type (Full_Base));
9077 -- If this is a subtype of a protected or task type, constrain its
9078 -- corresponding record, unless this is a subtype without constraints,
9079 -- i.e. a simple renaming as with an actual subtype in an instance.
9081 elsif Is_Concurrent_Type (Full_Base) then
9082 if Has_Discriminants (Full)
9083 and then Present (Corresponding_Record_Type (Full_Base))
9085 not Is_Empty_Elmt_List (Discriminant_Constraint (Full))
9087 Set_Corresponding_Record_Type (Full,
9088 Constrain_Corresponding_Record
9089 (Full, Corresponding_Record_Type (Full_Base),
9090 Related_Nod, Full_Base));
9093 Set_Corresponding_Record_Type (Full,
9094 Corresponding_Record_Type (Full_Base));
9097 end Complete_Private_Subtype;
9099 ----------------------------
9100 -- Constant_Redeclaration --
9101 ----------------------------
9103 procedure Constant_Redeclaration
9108 Prev : constant Entity_Id := Current_Entity_In_Scope (Id);
9109 Obj_Def : constant Node_Id := Object_Definition (N);
9112 procedure Check_Possible_Deferred_Completion
9113 (Prev_Id : Entity_Id;
9114 Prev_Obj_Def : Node_Id;
9115 Curr_Obj_Def : Node_Id);
9116 -- Determine whether the two object definitions describe the partial
9117 -- and the full view of a constrained deferred constant. Generate
9118 -- a subtype for the full view and verify that it statically matches
9119 -- the subtype of the partial view.
9121 procedure Check_Recursive_Declaration (Typ : Entity_Id);
9122 -- If deferred constant is an access type initialized with an allocator,
9123 -- check whether there is an illegal recursion in the definition,
9124 -- through a default value of some record subcomponent. This is normally
9125 -- detected when generating init procs, but requires this additional
9126 -- mechanism when expansion is disabled.
9128 ----------------------------------------
9129 -- Check_Possible_Deferred_Completion --
9130 ----------------------------------------
9132 procedure Check_Possible_Deferred_Completion
9133 (Prev_Id : Entity_Id;
9134 Prev_Obj_Def : Node_Id;
9135 Curr_Obj_Def : Node_Id)
9138 if Nkind (Prev_Obj_Def) = N_Subtype_Indication
9139 and then Present (Constraint (Prev_Obj_Def))
9140 and then Nkind (Curr_Obj_Def) = N_Subtype_Indication
9141 and then Present (Constraint (Curr_Obj_Def))
9144 Loc : constant Source_Ptr := Sloc (N);
9145 Def_Id : constant Entity_Id :=
9146 Make_Defining_Identifier (Loc,
9147 New_Internal_Name ('S'));
9148 Decl : constant Node_Id :=
9149 Make_Subtype_Declaration (Loc,
9150 Defining_Identifier =>
9152 Subtype_Indication =>
9153 Relocate_Node (Curr_Obj_Def));
9156 Insert_Before_And_Analyze (N, Decl);
9157 Set_Etype (Id, Def_Id);
9159 if not Subtypes_Statically_Match (Etype (Prev_Id), Def_Id) then
9160 Error_Msg_Sloc := Sloc (Prev_Id);
9161 Error_Msg_N ("subtype does not statically match deferred " &
9166 end Check_Possible_Deferred_Completion;
9168 ---------------------------------
9169 -- Check_Recursive_Declaration --
9170 ---------------------------------
9172 procedure Check_Recursive_Declaration (Typ : Entity_Id) is
9176 if Is_Record_Type (Typ) then
9177 Comp := First_Component (Typ);
9178 while Present (Comp) loop
9179 if Comes_From_Source (Comp) then
9180 if Present (Expression (Parent (Comp)))
9181 and then Is_Entity_Name (Expression (Parent (Comp)))
9182 and then Entity (Expression (Parent (Comp))) = Prev
9184 Error_Msg_Sloc := Sloc (Parent (Comp));
9186 ("illegal circularity with declaration for&#",
9190 elsif Is_Record_Type (Etype (Comp)) then
9191 Check_Recursive_Declaration (Etype (Comp));
9195 Next_Component (Comp);
9198 end Check_Recursive_Declaration;
9200 -- Start of processing for Constant_Redeclaration
9203 if Nkind (Parent (Prev)) = N_Object_Declaration then
9204 if Nkind (Object_Definition
9205 (Parent (Prev))) = N_Subtype_Indication
9207 -- Find type of new declaration. The constraints of the two
9208 -- views must match statically, but there is no point in
9209 -- creating an itype for the full view.
9211 if Nkind (Obj_Def) = N_Subtype_Indication then
9212 Find_Type (Subtype_Mark (Obj_Def));
9213 New_T := Entity (Subtype_Mark (Obj_Def));
9216 Find_Type (Obj_Def);
9217 New_T := Entity (Obj_Def);
9223 -- The full view may impose a constraint, even if the partial
9224 -- view does not, so construct the subtype.
9226 New_T := Find_Type_Of_Object (Obj_Def, N);
9231 -- Current declaration is illegal, diagnosed below in Enter_Name
9237 -- If previous full declaration exists, or if a homograph is present,
9238 -- let Enter_Name handle it, either with an error, or with the removal
9239 -- of an overridden implicit subprogram.
9241 if Ekind (Prev) /= E_Constant
9242 or else Present (Expression (Parent (Prev)))
9243 or else Present (Full_View (Prev))
9247 -- Verify that types of both declarations match, or else that both types
9248 -- are anonymous access types whose designated subtypes statically match
9249 -- (as allowed in Ada 2005 by AI-385).
9251 elsif Base_Type (Etype (Prev)) /= Base_Type (New_T)
9253 (Ekind (Etype (Prev)) /= E_Anonymous_Access_Type
9254 or else Ekind (Etype (New_T)) /= E_Anonymous_Access_Type
9255 or else Is_Access_Constant (Etype (New_T)) /=
9256 Is_Access_Constant (Etype (Prev))
9257 or else Can_Never_Be_Null (Etype (New_T)) /=
9258 Can_Never_Be_Null (Etype (Prev))
9259 or else Null_Exclusion_Present (Parent (Prev)) /=
9260 Null_Exclusion_Present (Parent (Id))
9261 or else not Subtypes_Statically_Match
9262 (Designated_Type (Etype (Prev)),
9263 Designated_Type (Etype (New_T))))
9265 Error_Msg_Sloc := Sloc (Prev);
9266 Error_Msg_N ("type does not match declaration#", N);
9267 Set_Full_View (Prev, Id);
9268 Set_Etype (Id, Any_Type);
9271 Null_Exclusion_Present (Parent (Prev))
9272 and then not Null_Exclusion_Present (N)
9274 Error_Msg_Sloc := Sloc (Prev);
9275 Error_Msg_N ("null-exclusion does not match declaration#", N);
9276 Set_Full_View (Prev, Id);
9277 Set_Etype (Id, Any_Type);
9279 -- If so, process the full constant declaration
9282 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
9283 -- the deferred declaration is constrained, then the subtype defined
9284 -- by the subtype_indication in the full declaration shall match it
9287 Check_Possible_Deferred_Completion
9289 Prev_Obj_Def => Object_Definition (Parent (Prev)),
9290 Curr_Obj_Def => Obj_Def);
9292 Set_Full_View (Prev, Id);
9293 Set_Is_Public (Id, Is_Public (Prev));
9294 Set_Is_Internal (Id);
9295 Append_Entity (Id, Current_Scope);
9297 -- Check ALIASED present if present before (RM 7.4(7))
9299 if Is_Aliased (Prev)
9300 and then not Aliased_Present (N)
9302 Error_Msg_Sloc := Sloc (Prev);
9303 Error_Msg_N ("ALIASED required (see declaration#)", N);
9306 -- Allow incomplete declaration of tags (used to handle forward
9307 -- references to tags). The check on Ada_Tags avoids circularities
9308 -- when rebuilding the compiler.
9310 if RTU_Loaded (Ada_Tags)
9311 and then T = RTE (RE_Tag)
9315 -- Check that placement is in private part and that the incomplete
9316 -- declaration appeared in the visible part.
9318 elsif Ekind (Current_Scope) = E_Package
9319 and then not In_Private_Part (Current_Scope)
9321 Error_Msg_Sloc := Sloc (Prev);
9322 Error_Msg_N ("full constant for declaration#"
9323 & " must be in private part", N);
9325 elsif Ekind (Current_Scope) = E_Package
9326 and then List_Containing (Parent (Prev))
9327 /= Visible_Declarations
9328 (Specification (Unit_Declaration_Node (Current_Scope)))
9331 ("deferred constant must be declared in visible part",
9335 if Is_Access_Type (T)
9336 and then Nkind (Expression (N)) = N_Allocator
9338 Check_Recursive_Declaration (Designated_Type (T));
9341 end Constant_Redeclaration;
9343 ----------------------
9344 -- Constrain_Access --
9345 ----------------------
9347 procedure Constrain_Access
9348 (Def_Id : in out Entity_Id;
9350 Related_Nod : Node_Id)
9352 T : constant Entity_Id := Entity (Subtype_Mark (S));
9353 Desig_Type : constant Entity_Id := Designated_Type (T);
9354 Desig_Subtype : Entity_Id := Create_Itype (E_Void, Related_Nod);
9355 Constraint_OK : Boolean := True;
9357 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean;
9358 -- Simple predicate to test for defaulted discriminants
9359 -- Shouldn't this be in sem_util???
9361 ---------------------------------
9362 -- Has_Defaulted_Discriminants --
9363 ---------------------------------
9365 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
9367 return Has_Discriminants (Typ)
9368 and then Present (First_Discriminant (Typ))
9370 (Discriminant_Default_Value (First_Discriminant (Typ)));
9371 end Has_Defaulted_Discriminants;
9373 -- Start of processing for Constrain_Access
9376 if Is_Array_Type (Desig_Type) then
9377 Constrain_Array (Desig_Subtype, S, Related_Nod, Def_Id, 'P');
9379 elsif (Is_Record_Type (Desig_Type)
9380 or else Is_Incomplete_Or_Private_Type (Desig_Type))
9381 and then not Is_Constrained (Desig_Type)
9383 -- ??? The following code is a temporary kludge to ignore a
9384 -- discriminant constraint on access type if it is constraining
9385 -- the current record. Avoid creating the implicit subtype of the
9386 -- record we are currently compiling since right now, we cannot
9387 -- handle these. For now, just return the access type itself.
9389 if Desig_Type = Current_Scope
9390 and then No (Def_Id)
9392 Set_Ekind (Desig_Subtype, E_Record_Subtype);
9393 Def_Id := Entity (Subtype_Mark (S));
9395 -- This call added to ensure that the constraint is analyzed
9396 -- (needed for a B test). Note that we still return early from
9397 -- this procedure to avoid recursive processing. ???
9399 Constrain_Discriminated_Type
9400 (Desig_Subtype, S, Related_Nod, For_Access => True);
9404 if (Ekind (T) = E_General_Access_Type
9405 or else Ada_Version >= Ada_05)
9406 and then Has_Private_Declaration (Desig_Type)
9407 and then In_Open_Scopes (Scope (Desig_Type))
9408 and then Has_Discriminants (Desig_Type)
9410 -- Enforce rule that the constraint is illegal if there is
9411 -- an unconstrained view of the designated type. This means
9412 -- that the partial view (either a private type declaration or
9413 -- a derivation from a private type) has no discriminants.
9414 -- (Defect Report 8652/0008, Technical Corrigendum 1, checked
9415 -- by ACATS B371001).
9417 -- Rule updated for Ada 2005: the private type is said to have
9418 -- a constrained partial view, given that objects of the type
9419 -- can be declared. Furthermore, the rule applies to all access
9420 -- types, unlike the rule concerning default discriminants.
9423 Pack : constant Node_Id :=
9424 Unit_Declaration_Node (Scope (Desig_Type));
9429 if Nkind (Pack) = N_Package_Declaration then
9430 Decls := Visible_Declarations (Specification (Pack));
9431 Decl := First (Decls);
9432 while Present (Decl) loop
9433 if (Nkind (Decl) = N_Private_Type_Declaration
9435 Chars (Defining_Identifier (Decl)) =
9439 (Nkind (Decl) = N_Full_Type_Declaration
9441 Chars (Defining_Identifier (Decl)) =
9443 and then Is_Derived_Type (Desig_Type)
9445 Has_Private_Declaration (Etype (Desig_Type)))
9447 if No (Discriminant_Specifications (Decl)) then
9449 ("cannot constrain general access type if " &
9450 "designated type has constrained partial view",
9463 Constrain_Discriminated_Type (Desig_Subtype, S, Related_Nod,
9464 For_Access => True);
9466 elsif (Is_Task_Type (Desig_Type)
9467 or else Is_Protected_Type (Desig_Type))
9468 and then not Is_Constrained (Desig_Type)
9470 Constrain_Concurrent
9471 (Desig_Subtype, S, Related_Nod, Desig_Type, ' ');
9474 Error_Msg_N ("invalid constraint on access type", S);
9475 Desig_Subtype := Desig_Type; -- Ignore invalid constraint.
9476 Constraint_OK := False;
9480 Def_Id := Create_Itype (E_Access_Subtype, Related_Nod);
9482 Set_Ekind (Def_Id, E_Access_Subtype);
9485 if Constraint_OK then
9486 Set_Etype (Def_Id, Base_Type (T));
9488 if Is_Private_Type (Desig_Type) then
9489 Prepare_Private_Subtype_Completion (Desig_Subtype, Related_Nod);
9492 Set_Etype (Def_Id, Any_Type);
9495 Set_Size_Info (Def_Id, T);
9496 Set_Is_Constrained (Def_Id, Constraint_OK);
9497 Set_Directly_Designated_Type (Def_Id, Desig_Subtype);
9498 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9499 Set_Is_Access_Constant (Def_Id, Is_Access_Constant (T));
9501 Conditional_Delay (Def_Id, T);
9503 -- AI-363 : Subtypes of general access types whose designated types have
9504 -- default discriminants are disallowed. In instances, the rule has to
9505 -- be checked against the actual, of which T is the subtype. In a
9506 -- generic body, the rule is checked assuming that the actual type has
9507 -- defaulted discriminants.
9509 if Ada_Version >= Ada_05 or else Warn_On_Ada_2005_Compatibility then
9510 if Ekind (Base_Type (T)) = E_General_Access_Type
9511 and then Has_Defaulted_Discriminants (Desig_Type)
9513 if Ada_Version < Ada_05 then
9515 ("access subtype of general access type would not " &
9516 "be allowed in Ada 2005?", S);
9519 ("access subype of general access type not allowed", S);
9522 Error_Msg_N ("\discriminants have defaults", S);
9524 elsif Is_Access_Type (T)
9525 and then Is_Generic_Type (Desig_Type)
9526 and then Has_Discriminants (Desig_Type)
9527 and then In_Package_Body (Current_Scope)
9529 if Ada_Version < Ada_05 then
9531 ("access subtype would not be allowed in generic body " &
9535 ("access subtype not allowed in generic body", S);
9539 ("\designated type is a discriminated formal", S);
9542 end Constrain_Access;
9544 ---------------------
9545 -- Constrain_Array --
9546 ---------------------
9548 procedure Constrain_Array
9549 (Def_Id : in out Entity_Id;
9551 Related_Nod : Node_Id;
9552 Related_Id : Entity_Id;
9555 C : constant Node_Id := Constraint (SI);
9556 Number_Of_Constraints : Nat := 0;
9559 Constraint_OK : Boolean := True;
9562 T := Entity (Subtype_Mark (SI));
9564 if Ekind (T) in Access_Kind then
9565 T := Designated_Type (T);
9568 -- If an index constraint follows a subtype mark in a subtype indication
9569 -- then the type or subtype denoted by the subtype mark must not already
9570 -- impose an index constraint. The subtype mark must denote either an
9571 -- unconstrained array type or an access type whose designated type
9572 -- is such an array type... (RM 3.6.1)
9574 if Is_Constrained (T) then
9576 ("array type is already constrained", Subtype_Mark (SI));
9577 Constraint_OK := False;
9580 S := First (Constraints (C));
9581 while Present (S) loop
9582 Number_Of_Constraints := Number_Of_Constraints + 1;
9586 -- In either case, the index constraint must provide a discrete
9587 -- range for each index of the array type and the type of each
9588 -- discrete range must be the same as that of the corresponding
9589 -- index. (RM 3.6.1)
9591 if Number_Of_Constraints /= Number_Dimensions (T) then
9592 Error_Msg_NE ("incorrect number of index constraints for }", C, T);
9593 Constraint_OK := False;
9596 S := First (Constraints (C));
9597 Index := First_Index (T);
9600 -- Apply constraints to each index type
9602 for J in 1 .. Number_Of_Constraints loop
9603 Constrain_Index (Index, S, Related_Nod, Related_Id, Suffix, J);
9613 Create_Itype (E_Array_Subtype, Related_Nod, Related_Id, Suffix);
9614 Set_Parent (Def_Id, Related_Nod);
9617 Set_Ekind (Def_Id, E_Array_Subtype);
9620 Set_Size_Info (Def_Id, (T));
9621 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
9622 Set_Etype (Def_Id, Base_Type (T));
9624 if Constraint_OK then
9625 Set_First_Index (Def_Id, First (Constraints (C)));
9627 Set_First_Index (Def_Id, First_Index (T));
9630 Set_Is_Constrained (Def_Id, True);
9631 Set_Is_Aliased (Def_Id, Is_Aliased (T));
9632 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9634 Set_Is_Private_Composite (Def_Id, Is_Private_Composite (T));
9635 Set_Is_Limited_Composite (Def_Id, Is_Limited_Composite (T));
9637 -- A subtype does not inherit the packed_array_type of is parent. We
9638 -- need to initialize the attribute because if Def_Id is previously
9639 -- analyzed through a limited_with clause, it will have the attributes
9640 -- of an incomplete type, one of which is an Elist that overlaps the
9641 -- Packed_Array_Type field.
9643 Set_Packed_Array_Type (Def_Id, Empty);
9645 -- Build a freeze node if parent still needs one. Also make sure that
9646 -- the Depends_On_Private status is set because the subtype will need
9647 -- reprocessing at the time the base type does, and also we must set a
9648 -- conditional delay.
9650 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
9651 Conditional_Delay (Def_Id, T);
9652 end Constrain_Array;
9654 ------------------------------
9655 -- Constrain_Component_Type --
9656 ------------------------------
9658 function Constrain_Component_Type
9660 Constrained_Typ : Entity_Id;
9661 Related_Node : Node_Id;
9663 Constraints : Elist_Id) return Entity_Id
9665 Loc : constant Source_Ptr := Sloc (Constrained_Typ);
9666 Compon_Type : constant Entity_Id := Etype (Comp);
9668 function Build_Constrained_Array_Type
9669 (Old_Type : Entity_Id) return Entity_Id;
9670 -- If Old_Type is an array type, one of whose indices is constrained
9671 -- by a discriminant, build an Itype whose constraint replaces the
9672 -- discriminant with its value in the constraint.
9674 function Build_Constrained_Discriminated_Type
9675 (Old_Type : Entity_Id) return Entity_Id;
9676 -- Ditto for record components
9678 function Build_Constrained_Access_Type
9679 (Old_Type : Entity_Id) return Entity_Id;
9680 -- Ditto for access types. Makes use of previous two functions, to
9681 -- constrain designated type.
9683 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id;
9684 -- T is an array or discriminated type, C is a list of constraints
9685 -- that apply to T. This routine builds the constrained subtype.
9687 function Is_Discriminant (Expr : Node_Id) return Boolean;
9688 -- Returns True if Expr is a discriminant
9690 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id;
9691 -- Find the value of discriminant Discrim in Constraint
9693 -----------------------------------
9694 -- Build_Constrained_Access_Type --
9695 -----------------------------------
9697 function Build_Constrained_Access_Type
9698 (Old_Type : Entity_Id) return Entity_Id
9700 Desig_Type : constant Entity_Id := Designated_Type (Old_Type);
9702 Desig_Subtype : Entity_Id;
9706 -- if the original access type was not embedded in the enclosing
9707 -- type definition, there is no need to produce a new access
9708 -- subtype. In fact every access type with an explicit constraint
9709 -- generates an itype whose scope is the enclosing record.
9711 if not Is_Type (Scope (Old_Type)) then
9714 elsif Is_Array_Type (Desig_Type) then
9715 Desig_Subtype := Build_Constrained_Array_Type (Desig_Type);
9717 elsif Has_Discriminants (Desig_Type) then
9719 -- This may be an access type to an enclosing record type for
9720 -- which we are constructing the constrained components. Return
9721 -- the enclosing record subtype. This is not always correct,
9722 -- but avoids infinite recursion. ???
9724 Desig_Subtype := Any_Type;
9726 for J in reverse 0 .. Scope_Stack.Last loop
9727 Scop := Scope_Stack.Table (J).Entity;
9730 and then Base_Type (Scop) = Base_Type (Desig_Type)
9732 Desig_Subtype := Scop;
9735 exit when not Is_Type (Scop);
9738 if Desig_Subtype = Any_Type then
9740 Build_Constrained_Discriminated_Type (Desig_Type);
9747 if Desig_Subtype /= Desig_Type then
9749 -- The Related_Node better be here or else we won't be able
9750 -- to attach new itypes to a node in the tree.
9752 pragma Assert (Present (Related_Node));
9754 Itype := Create_Itype (E_Access_Subtype, Related_Node);
9756 Set_Etype (Itype, Base_Type (Old_Type));
9757 Set_Size_Info (Itype, (Old_Type));
9758 Set_Directly_Designated_Type (Itype, Desig_Subtype);
9759 Set_Depends_On_Private (Itype, Has_Private_Component
9761 Set_Is_Access_Constant (Itype, Is_Access_Constant
9764 -- The new itype needs freezing when it depends on a not frozen
9765 -- type and the enclosing subtype needs freezing.
9767 if Has_Delayed_Freeze (Constrained_Typ)
9768 and then not Is_Frozen (Constrained_Typ)
9770 Conditional_Delay (Itype, Base_Type (Old_Type));
9778 end Build_Constrained_Access_Type;
9780 ----------------------------------
9781 -- Build_Constrained_Array_Type --
9782 ----------------------------------
9784 function Build_Constrained_Array_Type
9785 (Old_Type : Entity_Id) return Entity_Id
9789 Old_Index : Node_Id;
9790 Range_Node : Node_Id;
9791 Constr_List : List_Id;
9793 Need_To_Create_Itype : Boolean := False;
9796 Old_Index := First_Index (Old_Type);
9797 while Present (Old_Index) loop
9798 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9800 if Is_Discriminant (Lo_Expr)
9801 or else Is_Discriminant (Hi_Expr)
9803 Need_To_Create_Itype := True;
9806 Next_Index (Old_Index);
9809 if Need_To_Create_Itype then
9810 Constr_List := New_List;
9812 Old_Index := First_Index (Old_Type);
9813 while Present (Old_Index) loop
9814 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9816 if Is_Discriminant (Lo_Expr) then
9817 Lo_Expr := Get_Discr_Value (Lo_Expr);
9820 if Is_Discriminant (Hi_Expr) then
9821 Hi_Expr := Get_Discr_Value (Hi_Expr);
9826 (Loc, New_Copy_Tree (Lo_Expr), New_Copy_Tree (Hi_Expr));
9828 Append (Range_Node, To => Constr_List);
9830 Next_Index (Old_Index);
9833 return Build_Subtype (Old_Type, Constr_List);
9838 end Build_Constrained_Array_Type;
9840 ------------------------------------------
9841 -- Build_Constrained_Discriminated_Type --
9842 ------------------------------------------
9844 function Build_Constrained_Discriminated_Type
9845 (Old_Type : Entity_Id) return Entity_Id
9848 Constr_List : List_Id;
9849 Old_Constraint : Elmt_Id;
9851 Need_To_Create_Itype : Boolean := False;
9854 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9855 while Present (Old_Constraint) loop
9856 Expr := Node (Old_Constraint);
9858 if Is_Discriminant (Expr) then
9859 Need_To_Create_Itype := True;
9862 Next_Elmt (Old_Constraint);
9865 if Need_To_Create_Itype then
9866 Constr_List := New_List;
9868 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9869 while Present (Old_Constraint) loop
9870 Expr := Node (Old_Constraint);
9872 if Is_Discriminant (Expr) then
9873 Expr := Get_Discr_Value (Expr);
9876 Append (New_Copy_Tree (Expr), To => Constr_List);
9878 Next_Elmt (Old_Constraint);
9881 return Build_Subtype (Old_Type, Constr_List);
9886 end Build_Constrained_Discriminated_Type;
9892 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id is
9894 Subtyp_Decl : Node_Id;
9896 Btyp : Entity_Id := Base_Type (T);
9899 -- The Related_Node better be here or else we won't be able to
9900 -- attach new itypes to a node in the tree.
9902 pragma Assert (Present (Related_Node));
9904 -- If the view of the component's type is incomplete or private
9905 -- with unknown discriminants, then the constraint must be applied
9906 -- to the full type.
9908 if Has_Unknown_Discriminants (Btyp)
9909 and then Present (Underlying_Type (Btyp))
9911 Btyp := Underlying_Type (Btyp);
9915 Make_Subtype_Indication (Loc,
9916 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
9917 Constraint => Make_Index_Or_Discriminant_Constraint (Loc, C));
9919 Def_Id := Create_Itype (Ekind (T), Related_Node);
9922 Make_Subtype_Declaration (Loc,
9923 Defining_Identifier => Def_Id,
9924 Subtype_Indication => Indic);
9926 Set_Parent (Subtyp_Decl, Parent (Related_Node));
9928 -- Itypes must be analyzed with checks off (see package Itypes)
9930 Analyze (Subtyp_Decl, Suppress => All_Checks);
9935 ---------------------
9936 -- Get_Discr_Value --
9937 ---------------------
9939 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id is
9944 -- The discriminant may be declared for the type, in which case we
9945 -- find it by iterating over the list of discriminants. If the
9946 -- discriminant is inherited from a parent type, it appears as the
9947 -- corresponding discriminant of the current type. This will be the
9948 -- case when constraining an inherited component whose constraint is
9949 -- given by a discriminant of the parent.
9951 D := First_Discriminant (Typ);
9952 E := First_Elmt (Constraints);
9954 while Present (D) loop
9955 if D = Entity (Discrim)
9956 or else D = CR_Discriminant (Entity (Discrim))
9957 or else Corresponding_Discriminant (D) = Entity (Discrim)
9962 Next_Discriminant (D);
9966 -- The corresponding_Discriminant mechanism is incomplete, because
9967 -- the correspondence between new and old discriminants is not one
9968 -- to one: one new discriminant can constrain several old ones. In
9969 -- that case, scan sequentially the stored_constraint, the list of
9970 -- discriminants of the parents, and the constraints.
9971 -- Previous code checked for the present of the Stored_Constraint
9972 -- list for the derived type, but did not use it at all. Should it
9973 -- be present when the component is a discriminated task type?
9975 if Is_Derived_Type (Typ)
9976 and then Scope (Entity (Discrim)) = Etype (Typ)
9978 D := First_Discriminant (Etype (Typ));
9979 E := First_Elmt (Constraints);
9980 while Present (D) loop
9981 if D = Entity (Discrim) then
9985 Next_Discriminant (D);
9990 -- Something is wrong if we did not find the value
9992 raise Program_Error;
9993 end Get_Discr_Value;
9995 ---------------------
9996 -- Is_Discriminant --
9997 ---------------------
9999 function Is_Discriminant (Expr : Node_Id) return Boolean is
10000 Discrim_Scope : Entity_Id;
10003 if Denotes_Discriminant (Expr) then
10004 Discrim_Scope := Scope (Entity (Expr));
10006 -- Either we have a reference to one of Typ's discriminants,
10008 pragma Assert (Discrim_Scope = Typ
10010 -- or to the discriminants of the parent type, in the case
10011 -- of a derivation of a tagged type with variants.
10013 or else Discrim_Scope = Etype (Typ)
10014 or else Full_View (Discrim_Scope) = Etype (Typ)
10016 -- or same as above for the case where the discriminants
10017 -- were declared in Typ's private view.
10019 or else (Is_Private_Type (Discrim_Scope)
10020 and then Chars (Discrim_Scope) = Chars (Typ))
10022 -- or else we are deriving from the full view and the
10023 -- discriminant is declared in the private entity.
10025 or else (Is_Private_Type (Typ)
10026 and then Chars (Discrim_Scope) = Chars (Typ))
10028 -- Or we are constrained the corresponding record of a
10029 -- synchronized type that completes a private declaration.
10031 or else (Is_Concurrent_Record_Type (Typ)
10033 Corresponding_Concurrent_Type (Typ) = Discrim_Scope)
10035 -- or we have a class-wide type, in which case make sure the
10036 -- discriminant found belongs to the root type.
10038 or else (Is_Class_Wide_Type (Typ)
10039 and then Etype (Typ) = Discrim_Scope));
10044 -- In all other cases we have something wrong
10047 end Is_Discriminant;
10049 -- Start of processing for Constrain_Component_Type
10052 if Nkind (Parent (Comp)) = N_Component_Declaration
10053 and then Comes_From_Source (Parent (Comp))
10054 and then Comes_From_Source
10055 (Subtype_Indication (Component_Definition (Parent (Comp))))
10058 (Subtype_Indication (Component_Definition (Parent (Comp))))
10060 return Compon_Type;
10062 elsif Is_Array_Type (Compon_Type) then
10063 return Build_Constrained_Array_Type (Compon_Type);
10065 elsif Has_Discriminants (Compon_Type) then
10066 return Build_Constrained_Discriminated_Type (Compon_Type);
10068 elsif Is_Access_Type (Compon_Type) then
10069 return Build_Constrained_Access_Type (Compon_Type);
10072 return Compon_Type;
10074 end Constrain_Component_Type;
10076 --------------------------
10077 -- Constrain_Concurrent --
10078 --------------------------
10080 -- For concurrent types, the associated record value type carries the same
10081 -- discriminants, so when we constrain a concurrent type, we must constrain
10082 -- the corresponding record type as well.
10084 procedure Constrain_Concurrent
10085 (Def_Id : in out Entity_Id;
10087 Related_Nod : Node_Id;
10088 Related_Id : Entity_Id;
10089 Suffix : Character)
10091 T_Ent : Entity_Id := Entity (Subtype_Mark (SI));
10095 if Ekind (T_Ent) in Access_Kind then
10096 T_Ent := Designated_Type (T_Ent);
10099 T_Val := Corresponding_Record_Type (T_Ent);
10101 if Present (T_Val) then
10103 if No (Def_Id) then
10104 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
10107 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
10109 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
10110 Set_Corresponding_Record_Type (Def_Id,
10111 Constrain_Corresponding_Record
10112 (Def_Id, T_Val, Related_Nod, Related_Id));
10115 -- If there is no associated record, expansion is disabled and this
10116 -- is a generic context. Create a subtype in any case, so that
10117 -- semantic analysis can proceed.
10119 if No (Def_Id) then
10120 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
10123 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
10125 end Constrain_Concurrent;
10127 ------------------------------------
10128 -- Constrain_Corresponding_Record --
10129 ------------------------------------
10131 function Constrain_Corresponding_Record
10132 (Prot_Subt : Entity_Id;
10133 Corr_Rec : Entity_Id;
10134 Related_Nod : Node_Id;
10135 Related_Id : Entity_Id) return Entity_Id
10137 T_Sub : constant Entity_Id :=
10138 Create_Itype (E_Record_Subtype, Related_Nod, Related_Id, 'V');
10141 Set_Etype (T_Sub, Corr_Rec);
10142 Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt));
10143 Set_Is_Constrained (T_Sub, True);
10144 Set_First_Entity (T_Sub, First_Entity (Corr_Rec));
10145 Set_Last_Entity (T_Sub, Last_Entity (Corr_Rec));
10147 -- As elsewhere, we do not want to create a freeze node for this itype
10148 -- if it is created for a constrained component of an enclosing record
10149 -- because references to outer discriminants will appear out of scope.
10151 if Ekind (Scope (Prot_Subt)) /= E_Record_Type then
10152 Conditional_Delay (T_Sub, Corr_Rec);
10154 Set_Is_Frozen (T_Sub);
10157 if Has_Discriminants (Prot_Subt) then -- False only if errors.
10158 Set_Discriminant_Constraint
10159 (T_Sub, Discriminant_Constraint (Prot_Subt));
10160 Set_Stored_Constraint_From_Discriminant_Constraint (T_Sub);
10161 Create_Constrained_Components
10162 (T_Sub, Related_Nod, Corr_Rec, Discriminant_Constraint (T_Sub));
10165 Set_Depends_On_Private (T_Sub, Has_Private_Component (T_Sub));
10168 end Constrain_Corresponding_Record;
10170 -----------------------
10171 -- Constrain_Decimal --
10172 -----------------------
10174 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id) is
10175 T : constant Entity_Id := Entity (Subtype_Mark (S));
10176 C : constant Node_Id := Constraint (S);
10177 Loc : constant Source_Ptr := Sloc (C);
10178 Range_Expr : Node_Id;
10179 Digits_Expr : Node_Id;
10184 Set_Ekind (Def_Id, E_Decimal_Fixed_Point_Subtype);
10186 if Nkind (C) = N_Range_Constraint then
10187 Range_Expr := Range_Expression (C);
10188 Digits_Val := Digits_Value (T);
10191 pragma Assert (Nkind (C) = N_Digits_Constraint);
10192 Digits_Expr := Digits_Expression (C);
10193 Analyze_And_Resolve (Digits_Expr, Any_Integer);
10195 Check_Digits_Expression (Digits_Expr);
10196 Digits_Val := Expr_Value (Digits_Expr);
10198 if Digits_Val > Digits_Value (T) then
10200 ("digits expression is incompatible with subtype", C);
10201 Digits_Val := Digits_Value (T);
10204 if Present (Range_Constraint (C)) then
10205 Range_Expr := Range_Expression (Range_Constraint (C));
10207 Range_Expr := Empty;
10211 Set_Etype (Def_Id, Base_Type (T));
10212 Set_Size_Info (Def_Id, (T));
10213 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10214 Set_Delta_Value (Def_Id, Delta_Value (T));
10215 Set_Scale_Value (Def_Id, Scale_Value (T));
10216 Set_Small_Value (Def_Id, Small_Value (T));
10217 Set_Machine_Radix_10 (Def_Id, Machine_Radix_10 (T));
10218 Set_Digits_Value (Def_Id, Digits_Val);
10220 -- Manufacture range from given digits value if no range present
10222 if No (Range_Expr) then
10223 Bound_Val := (Ureal_10 ** Digits_Val - Ureal_1) * Small_Value (T);
10227 Convert_To (T, Make_Real_Literal (Loc, (-Bound_Val))),
10229 Convert_To (T, Make_Real_Literal (Loc, Bound_Val)));
10232 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expr, T);
10233 Set_Discrete_RM_Size (Def_Id);
10235 -- Unconditionally delay the freeze, since we cannot set size
10236 -- information in all cases correctly until the freeze point.
10238 Set_Has_Delayed_Freeze (Def_Id);
10239 end Constrain_Decimal;
10241 ----------------------------------
10242 -- Constrain_Discriminated_Type --
10243 ----------------------------------
10245 procedure Constrain_Discriminated_Type
10246 (Def_Id : Entity_Id;
10248 Related_Nod : Node_Id;
10249 For_Access : Boolean := False)
10251 E : constant Entity_Id := Entity (Subtype_Mark (S));
10254 Elist : Elist_Id := New_Elmt_List;
10256 procedure Fixup_Bad_Constraint;
10257 -- This is called after finding a bad constraint, and after having
10258 -- posted an appropriate error message. The mission is to leave the
10259 -- entity T in as reasonable state as possible!
10261 --------------------------
10262 -- Fixup_Bad_Constraint --
10263 --------------------------
10265 procedure Fixup_Bad_Constraint is
10267 -- Set a reasonable Ekind for the entity. For an incomplete type,
10268 -- we can't do much, but for other types, we can set the proper
10269 -- corresponding subtype kind.
10271 if Ekind (T) = E_Incomplete_Type then
10272 Set_Ekind (Def_Id, Ekind (T));
10274 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
10277 -- Set Etype to the known type, to reduce chances of cascaded errors
10279 Set_Etype (Def_Id, E);
10280 Set_Error_Posted (Def_Id);
10281 end Fixup_Bad_Constraint;
10283 -- Start of processing for Constrain_Discriminated_Type
10286 C := Constraint (S);
10288 -- A discriminant constraint is only allowed in a subtype indication,
10289 -- after a subtype mark. This subtype mark must denote either a type
10290 -- with discriminants, or an access type whose designated type is a
10291 -- type with discriminants. A discriminant constraint specifies the
10292 -- values of these discriminants (RM 3.7.2(5)).
10294 T := Base_Type (Entity (Subtype_Mark (S)));
10296 if Ekind (T) in Access_Kind then
10297 T := Designated_Type (T);
10300 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal.
10301 -- Avoid generating an error for access-to-incomplete subtypes.
10303 if Ada_Version >= Ada_05
10304 and then Ekind (T) = E_Incomplete_Type
10305 and then Nkind (Parent (S)) = N_Subtype_Declaration
10306 and then not Is_Itype (Def_Id)
10308 -- A little sanity check, emit an error message if the type
10309 -- has discriminants to begin with. Type T may be a regular
10310 -- incomplete type or imported via a limited with clause.
10312 if Has_Discriminants (T)
10314 (From_With_Type (T)
10315 and then Present (Non_Limited_View (T))
10316 and then Nkind (Parent (Non_Limited_View (T))) =
10317 N_Full_Type_Declaration
10318 and then Present (Discriminant_Specifications
10319 (Parent (Non_Limited_View (T)))))
10322 ("(Ada 2005) incomplete subtype may not be constrained", C);
10325 ("invalid constraint: type has no discriminant", C);
10328 Fixup_Bad_Constraint;
10331 -- Check that the type has visible discriminants. The type may be
10332 -- a private type with unknown discriminants whose full view has
10333 -- discriminants which are invisible.
10335 elsif not Has_Discriminants (T)
10337 (Has_Unknown_Discriminants (T)
10338 and then Is_Private_Type (T))
10340 Error_Msg_N ("invalid constraint: type has no discriminant", C);
10341 Fixup_Bad_Constraint;
10344 elsif Is_Constrained (E)
10345 or else (Ekind (E) = E_Class_Wide_Subtype
10346 and then Present (Discriminant_Constraint (E)))
10348 Error_Msg_N ("type is already constrained", Subtype_Mark (S));
10349 Fixup_Bad_Constraint;
10353 -- T may be an unconstrained subtype (e.g. a generic actual).
10354 -- Constraint applies to the base type.
10356 T := Base_Type (T);
10358 Elist := Build_Discriminant_Constraints (T, S);
10360 -- If the list returned was empty we had an error in building the
10361 -- discriminant constraint. We have also already signalled an error
10362 -- in the incomplete type case
10364 if Is_Empty_Elmt_List (Elist) then
10365 Fixup_Bad_Constraint;
10369 Build_Discriminated_Subtype (T, Def_Id, Elist, Related_Nod, For_Access);
10370 end Constrain_Discriminated_Type;
10372 ---------------------------
10373 -- Constrain_Enumeration --
10374 ---------------------------
10376 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id) is
10377 T : constant Entity_Id := Entity (Subtype_Mark (S));
10378 C : constant Node_Id := Constraint (S);
10381 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10383 Set_First_Literal (Def_Id, First_Literal (Base_Type (T)));
10385 Set_Etype (Def_Id, Base_Type (T));
10386 Set_Size_Info (Def_Id, (T));
10387 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10388 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10390 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10392 Set_Discrete_RM_Size (Def_Id);
10393 end Constrain_Enumeration;
10395 ----------------------
10396 -- Constrain_Float --
10397 ----------------------
10399 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id) is
10400 T : constant Entity_Id := Entity (Subtype_Mark (S));
10406 Set_Ekind (Def_Id, E_Floating_Point_Subtype);
10408 Set_Etype (Def_Id, Base_Type (T));
10409 Set_Size_Info (Def_Id, (T));
10410 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10412 -- Process the constraint
10414 C := Constraint (S);
10416 -- Digits constraint present
10418 if Nkind (C) = N_Digits_Constraint then
10419 Check_Restriction (No_Obsolescent_Features, C);
10421 if Warn_On_Obsolescent_Feature then
10423 ("subtype digits constraint is an " &
10424 "obsolescent feature (RM J.3(8))?", C);
10427 D := Digits_Expression (C);
10428 Analyze_And_Resolve (D, Any_Integer);
10429 Check_Digits_Expression (D);
10430 Set_Digits_Value (Def_Id, Expr_Value (D));
10432 -- Check that digits value is in range. Obviously we can do this
10433 -- at compile time, but it is strictly a runtime check, and of
10434 -- course there is an ACVC test that checks this!
10436 if Digits_Value (Def_Id) > Digits_Value (T) then
10437 Error_Msg_Uint_1 := Digits_Value (T);
10438 Error_Msg_N ("?digits value is too large, maximum is ^", D);
10440 Make_Raise_Constraint_Error (Sloc (D),
10441 Reason => CE_Range_Check_Failed);
10442 Insert_Action (Declaration_Node (Def_Id), Rais);
10445 C := Range_Constraint (C);
10447 -- No digits constraint present
10450 Set_Digits_Value (Def_Id, Digits_Value (T));
10453 -- Range constraint present
10455 if Nkind (C) = N_Range_Constraint then
10456 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10458 -- No range constraint present
10461 pragma Assert (No (C));
10462 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10465 Set_Is_Constrained (Def_Id);
10466 end Constrain_Float;
10468 ---------------------
10469 -- Constrain_Index --
10470 ---------------------
10472 procedure Constrain_Index
10475 Related_Nod : Node_Id;
10476 Related_Id : Entity_Id;
10477 Suffix : Character;
10478 Suffix_Index : Nat)
10480 Def_Id : Entity_Id;
10481 R : Node_Id := Empty;
10482 T : constant Entity_Id := Etype (Index);
10485 if Nkind (S) = N_Range
10487 (Nkind (S) = N_Attribute_Reference
10488 and then Attribute_Name (S) = Name_Range)
10490 -- A Range attribute will transformed into N_Range by Resolve
10496 Process_Range_Expr_In_Decl (R, T, Empty_List);
10498 if not Error_Posted (S)
10500 (Nkind (S) /= N_Range
10501 or else not Covers (T, (Etype (Low_Bound (S))))
10502 or else not Covers (T, (Etype (High_Bound (S)))))
10504 if Base_Type (T) /= Any_Type
10505 and then Etype (Low_Bound (S)) /= Any_Type
10506 and then Etype (High_Bound (S)) /= Any_Type
10508 Error_Msg_N ("range expected", S);
10512 elsif Nkind (S) = N_Subtype_Indication then
10514 -- The parser has verified that this is a discrete indication
10516 Resolve_Discrete_Subtype_Indication (S, T);
10517 R := Range_Expression (Constraint (S));
10519 elsif Nkind (S) = N_Discriminant_Association then
10521 -- Syntactically valid in subtype indication
10523 Error_Msg_N ("invalid index constraint", S);
10524 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10527 -- Subtype_Mark case, no anonymous subtypes to construct
10532 if Is_Entity_Name (S) then
10533 if not Is_Type (Entity (S)) then
10534 Error_Msg_N ("expect subtype mark for index constraint", S);
10536 elsif Base_Type (Entity (S)) /= Base_Type (T) then
10537 Wrong_Type (S, Base_Type (T));
10543 Error_Msg_N ("invalid index constraint", S);
10544 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10550 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index);
10552 Set_Etype (Def_Id, Base_Type (T));
10554 if Is_Modular_Integer_Type (T) then
10555 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10557 elsif Is_Integer_Type (T) then
10558 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10561 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10562 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10565 Set_Size_Info (Def_Id, (T));
10566 Set_RM_Size (Def_Id, RM_Size (T));
10567 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10569 Set_Scalar_Range (Def_Id, R);
10571 Set_Etype (S, Def_Id);
10572 Set_Discrete_RM_Size (Def_Id);
10573 end Constrain_Index;
10575 -----------------------
10576 -- Constrain_Integer --
10577 -----------------------
10579 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id) is
10580 T : constant Entity_Id := Entity (Subtype_Mark (S));
10581 C : constant Node_Id := Constraint (S);
10584 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10586 if Is_Modular_Integer_Type (T) then
10587 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10589 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10592 Set_Etype (Def_Id, Base_Type (T));
10593 Set_Size_Info (Def_Id, (T));
10594 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10595 Set_Discrete_RM_Size (Def_Id);
10596 end Constrain_Integer;
10598 ------------------------------
10599 -- Constrain_Ordinary_Fixed --
10600 ------------------------------
10602 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id) is
10603 T : constant Entity_Id := Entity (Subtype_Mark (S));
10609 Set_Ekind (Def_Id, E_Ordinary_Fixed_Point_Subtype);
10610 Set_Etype (Def_Id, Base_Type (T));
10611 Set_Size_Info (Def_Id, (T));
10612 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10613 Set_Small_Value (Def_Id, Small_Value (T));
10615 -- Process the constraint
10617 C := Constraint (S);
10619 -- Delta constraint present
10621 if Nkind (C) = N_Delta_Constraint then
10622 Check_Restriction (No_Obsolescent_Features, C);
10624 if Warn_On_Obsolescent_Feature then
10626 ("subtype delta constraint is an " &
10627 "obsolescent feature (RM J.3(7))?");
10630 D := Delta_Expression (C);
10631 Analyze_And_Resolve (D, Any_Real);
10632 Check_Delta_Expression (D);
10633 Set_Delta_Value (Def_Id, Expr_Value_R (D));
10635 -- Check that delta value is in range. Obviously we can do this
10636 -- at compile time, but it is strictly a runtime check, and of
10637 -- course there is an ACVC test that checks this!
10639 if Delta_Value (Def_Id) < Delta_Value (T) then
10640 Error_Msg_N ("?delta value is too small", D);
10642 Make_Raise_Constraint_Error (Sloc (D),
10643 Reason => CE_Range_Check_Failed);
10644 Insert_Action (Declaration_Node (Def_Id), Rais);
10647 C := Range_Constraint (C);
10649 -- No delta constraint present
10652 Set_Delta_Value (Def_Id, Delta_Value (T));
10655 -- Range constraint present
10657 if Nkind (C) = N_Range_Constraint then
10658 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10660 -- No range constraint present
10663 pragma Assert (No (C));
10664 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10668 Set_Discrete_RM_Size (Def_Id);
10670 -- Unconditionally delay the freeze, since we cannot set size
10671 -- information in all cases correctly until the freeze point.
10673 Set_Has_Delayed_Freeze (Def_Id);
10674 end Constrain_Ordinary_Fixed;
10676 -----------------------
10677 -- Contain_Interface --
10678 -----------------------
10680 function Contain_Interface
10681 (Iface : Entity_Id;
10682 Ifaces : Elist_Id) return Boolean
10684 Iface_Elmt : Elmt_Id;
10687 if Present (Ifaces) then
10688 Iface_Elmt := First_Elmt (Ifaces);
10689 while Present (Iface_Elmt) loop
10690 if Node (Iface_Elmt) = Iface then
10694 Next_Elmt (Iface_Elmt);
10699 end Contain_Interface;
10701 ---------------------------
10702 -- Convert_Scalar_Bounds --
10703 ---------------------------
10705 procedure Convert_Scalar_Bounds
10707 Parent_Type : Entity_Id;
10708 Derived_Type : Entity_Id;
10711 Implicit_Base : constant Entity_Id := Base_Type (Derived_Type);
10718 Lo := Build_Scalar_Bound
10719 (Type_Low_Bound (Derived_Type),
10720 Parent_Type, Implicit_Base);
10722 Hi := Build_Scalar_Bound
10723 (Type_High_Bound (Derived_Type),
10724 Parent_Type, Implicit_Base);
10731 Set_Includes_Infinities (Rng, Has_Infinities (Derived_Type));
10733 Set_Parent (Rng, N);
10734 Set_Scalar_Range (Derived_Type, Rng);
10736 -- Analyze the bounds
10738 Analyze_And_Resolve (Lo, Implicit_Base);
10739 Analyze_And_Resolve (Hi, Implicit_Base);
10741 -- Analyze the range itself, except that we do not analyze it if
10742 -- the bounds are real literals, and we have a fixed-point type.
10743 -- The reason for this is that we delay setting the bounds in this
10744 -- case till we know the final Small and Size values (see circuit
10745 -- in Freeze.Freeze_Fixed_Point_Type for further details).
10747 if Is_Fixed_Point_Type (Parent_Type)
10748 and then Nkind (Lo) = N_Real_Literal
10749 and then Nkind (Hi) = N_Real_Literal
10753 -- Here we do the analysis of the range
10755 -- Note: we do this manually, since if we do a normal Analyze and
10756 -- Resolve call, there are problems with the conversions used for
10757 -- the derived type range.
10760 Set_Etype (Rng, Implicit_Base);
10761 Set_Analyzed (Rng, True);
10763 end Convert_Scalar_Bounds;
10765 -------------------
10766 -- Copy_And_Swap --
10767 -------------------
10769 procedure Copy_And_Swap (Priv, Full : Entity_Id) is
10771 -- Initialize new full declaration entity by copying the pertinent
10772 -- fields of the corresponding private declaration entity.
10774 -- We temporarily set Ekind to a value appropriate for a type to
10775 -- avoid assert failures in Einfo from checking for setting type
10776 -- attributes on something that is not a type. Ekind (Priv) is an
10777 -- appropriate choice, since it allowed the attributes to be set
10778 -- in the first place. This Ekind value will be modified later.
10780 Set_Ekind (Full, Ekind (Priv));
10782 -- Also set Etype temporarily to Any_Type, again, in the absence
10783 -- of errors, it will be properly reset, and if there are errors,
10784 -- then we want a value of Any_Type to remain.
10786 Set_Etype (Full, Any_Type);
10788 -- Now start copying attributes
10790 Set_Has_Discriminants (Full, Has_Discriminants (Priv));
10792 if Has_Discriminants (Full) then
10793 Set_Discriminant_Constraint (Full, Discriminant_Constraint (Priv));
10794 Set_Stored_Constraint (Full, Stored_Constraint (Priv));
10797 Set_First_Rep_Item (Full, First_Rep_Item (Priv));
10798 Set_Homonym (Full, Homonym (Priv));
10799 Set_Is_Immediately_Visible (Full, Is_Immediately_Visible (Priv));
10800 Set_Is_Public (Full, Is_Public (Priv));
10801 Set_Is_Pure (Full, Is_Pure (Priv));
10802 Set_Is_Tagged_Type (Full, Is_Tagged_Type (Priv));
10803 Set_Has_Pragma_Unreferenced (Full, Has_Pragma_Unreferenced (Priv));
10804 Set_Has_Pragma_Unreferenced_Objects
10805 (Full, Has_Pragma_Unreferenced_Objects
10808 Conditional_Delay (Full, Priv);
10810 if Is_Tagged_Type (Full) then
10811 Set_Primitive_Operations (Full, Primitive_Operations (Priv));
10813 if Priv = Base_Type (Priv) then
10814 Set_Class_Wide_Type (Full, Class_Wide_Type (Priv));
10818 Set_Is_Volatile (Full, Is_Volatile (Priv));
10819 Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv));
10820 Set_Scope (Full, Scope (Priv));
10821 Set_Next_Entity (Full, Next_Entity (Priv));
10822 Set_First_Entity (Full, First_Entity (Priv));
10823 Set_Last_Entity (Full, Last_Entity (Priv));
10825 -- If access types have been recorded for later handling, keep them in
10826 -- the full view so that they get handled when the full view freeze
10827 -- node is expanded.
10829 if Present (Freeze_Node (Priv))
10830 and then Present (Access_Types_To_Process (Freeze_Node (Priv)))
10832 Ensure_Freeze_Node (Full);
10833 Set_Access_Types_To_Process
10834 (Freeze_Node (Full),
10835 Access_Types_To_Process (Freeze_Node (Priv)));
10838 -- Swap the two entities. Now Privat is the full type entity and
10839 -- Full is the private one. They will be swapped back at the end
10840 -- of the private part. This swapping ensures that the entity that
10841 -- is visible in the private part is the full declaration.
10843 Exchange_Entities (Priv, Full);
10844 Append_Entity (Full, Scope (Full));
10847 -------------------------------------
10848 -- Copy_Array_Base_Type_Attributes --
10849 -------------------------------------
10851 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id) is
10853 Set_Component_Alignment (T1, Component_Alignment (T2));
10854 Set_Component_Type (T1, Component_Type (T2));
10855 Set_Component_Size (T1, Component_Size (T2));
10856 Set_Has_Controlled_Component (T1, Has_Controlled_Component (T2));
10857 Set_Finalize_Storage_Only (T1, Finalize_Storage_Only (T2));
10858 Set_Has_Non_Standard_Rep (T1, Has_Non_Standard_Rep (T2));
10859 Set_Has_Task (T1, Has_Task (T2));
10860 Set_Is_Packed (T1, Is_Packed (T2));
10861 Set_Has_Aliased_Components (T1, Has_Aliased_Components (T2));
10862 Set_Has_Atomic_Components (T1, Has_Atomic_Components (T2));
10863 Set_Has_Volatile_Components (T1, Has_Volatile_Components (T2));
10864 end Copy_Array_Base_Type_Attributes;
10866 -----------------------------------
10867 -- Copy_Array_Subtype_Attributes --
10868 -----------------------------------
10870 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id) is
10872 Set_Size_Info (T1, T2);
10874 Set_First_Index (T1, First_Index (T2));
10875 Set_Is_Aliased (T1, Is_Aliased (T2));
10876 Set_Is_Atomic (T1, Is_Atomic (T2));
10877 Set_Is_Volatile (T1, Is_Volatile (T2));
10878 Set_Treat_As_Volatile (T1, Treat_As_Volatile (T2));
10879 Set_Is_Constrained (T1, Is_Constrained (T2));
10880 Set_Depends_On_Private (T1, Has_Private_Component (T2));
10881 Set_First_Rep_Item (T1, First_Rep_Item (T2));
10882 Set_Convention (T1, Convention (T2));
10883 Set_Is_Limited_Composite (T1, Is_Limited_Composite (T2));
10884 Set_Is_Private_Composite (T1, Is_Private_Composite (T2));
10885 end Copy_Array_Subtype_Attributes;
10887 -----------------------------------
10888 -- Create_Constrained_Components --
10889 -----------------------------------
10891 procedure Create_Constrained_Components
10893 Decl_Node : Node_Id;
10895 Constraints : Elist_Id)
10897 Loc : constant Source_Ptr := Sloc (Subt);
10898 Comp_List : constant Elist_Id := New_Elmt_List;
10899 Parent_Type : constant Entity_Id := Etype (Typ);
10900 Assoc_List : constant List_Id := New_List;
10901 Discr_Val : Elmt_Id;
10905 Is_Static : Boolean := True;
10907 procedure Collect_Fixed_Components (Typ : Entity_Id);
10908 -- Collect parent type components that do not appear in a variant part
10910 procedure Create_All_Components;
10911 -- Iterate over Comp_List to create the components of the subtype
10913 function Create_Component (Old_Compon : Entity_Id) return Entity_Id;
10914 -- Creates a new component from Old_Compon, copying all the fields from
10915 -- it, including its Etype, inserts the new component in the Subt entity
10916 -- chain and returns the new component.
10918 function Is_Variant_Record (T : Entity_Id) return Boolean;
10919 -- If true, and discriminants are static, collect only components from
10920 -- variants selected by discriminant values.
10922 ------------------------------
10923 -- Collect_Fixed_Components --
10924 ------------------------------
10926 procedure Collect_Fixed_Components (Typ : Entity_Id) is
10928 -- Build association list for discriminants, and find components of the
10929 -- variant part selected by the values of the discriminants.
10931 Old_C := First_Discriminant (Typ);
10932 Discr_Val := First_Elmt (Constraints);
10933 while Present (Old_C) loop
10934 Append_To (Assoc_List,
10935 Make_Component_Association (Loc,
10936 Choices => New_List (New_Occurrence_Of (Old_C, Loc)),
10937 Expression => New_Copy (Node (Discr_Val))));
10939 Next_Elmt (Discr_Val);
10940 Next_Discriminant (Old_C);
10943 -- The tag, and the possible parent and controller components
10944 -- are unconditionally in the subtype.
10946 if Is_Tagged_Type (Typ)
10947 or else Has_Controlled_Component (Typ)
10949 Old_C := First_Component (Typ);
10950 while Present (Old_C) loop
10951 if Chars ((Old_C)) = Name_uTag
10952 or else Chars ((Old_C)) = Name_uParent
10953 or else Chars ((Old_C)) = Name_uController
10955 Append_Elmt (Old_C, Comp_List);
10958 Next_Component (Old_C);
10961 end Collect_Fixed_Components;
10963 ---------------------------
10964 -- Create_All_Components --
10965 ---------------------------
10967 procedure Create_All_Components is
10971 Comp := First_Elmt (Comp_List);
10972 while Present (Comp) loop
10973 Old_C := Node (Comp);
10974 New_C := Create_Component (Old_C);
10978 Constrain_Component_Type
10979 (Old_C, Subt, Decl_Node, Typ, Constraints));
10980 Set_Is_Public (New_C, Is_Public (Subt));
10984 end Create_All_Components;
10986 ----------------------
10987 -- Create_Component --
10988 ----------------------
10990 function Create_Component (Old_Compon : Entity_Id) return Entity_Id is
10991 New_Compon : constant Entity_Id := New_Copy (Old_Compon);
10994 if Ekind (Old_Compon) = E_Discriminant
10995 and then Is_Completely_Hidden (Old_Compon)
10997 -- This is a shadow discriminant created for a discriminant of
10998 -- the parent type that is one of several renamed by the same
10999 -- new discriminant. Give the shadow discriminant an internal
11000 -- name that cannot conflict with that of visible components.
11002 Set_Chars (New_Compon, New_Internal_Name ('C'));
11005 -- Set the parent so we have a proper link for freezing etc. This is
11006 -- not a real parent pointer, since of course our parent does not own
11007 -- up to us and reference us, we are an illegitimate child of the
11008 -- original parent!
11010 Set_Parent (New_Compon, Parent (Old_Compon));
11012 -- If the old component's Esize was already determined and is a
11013 -- static value, then the new component simply inherits it. Otherwise
11014 -- the old component's size may require run-time determination, but
11015 -- the new component's size still might be statically determinable
11016 -- (if, for example it has a static constraint). In that case we want
11017 -- Layout_Type to recompute the component's size, so we reset its
11018 -- size and positional fields.
11020 if Frontend_Layout_On_Target
11021 and then not Known_Static_Esize (Old_Compon)
11023 Set_Esize (New_Compon, Uint_0);
11024 Init_Normalized_First_Bit (New_Compon);
11025 Init_Normalized_Position (New_Compon);
11026 Init_Normalized_Position_Max (New_Compon);
11029 -- We do not want this node marked as Comes_From_Source, since
11030 -- otherwise it would get first class status and a separate cross-
11031 -- reference line would be generated. Illegitimate children do not
11032 -- rate such recognition.
11034 Set_Comes_From_Source (New_Compon, False);
11036 -- But it is a real entity, and a birth certificate must be properly
11037 -- registered by entering it into the entity list.
11039 Enter_Name (New_Compon);
11042 end Create_Component;
11044 -----------------------
11045 -- Is_Variant_Record --
11046 -----------------------
11048 function Is_Variant_Record (T : Entity_Id) return Boolean is
11050 return Nkind (Parent (T)) = N_Full_Type_Declaration
11051 and then Nkind (Type_Definition (Parent (T))) = N_Record_Definition
11052 and then Present (Component_List (Type_Definition (Parent (T))))
11055 (Variant_Part (Component_List (Type_Definition (Parent (T)))));
11056 end Is_Variant_Record;
11058 -- Start of processing for Create_Constrained_Components
11061 pragma Assert (Subt /= Base_Type (Subt));
11062 pragma Assert (Typ = Base_Type (Typ));
11064 Set_First_Entity (Subt, Empty);
11065 Set_Last_Entity (Subt, Empty);
11067 -- Check whether constraint is fully static, in which case we can
11068 -- optimize the list of components.
11070 Discr_Val := First_Elmt (Constraints);
11071 while Present (Discr_Val) loop
11072 if not Is_OK_Static_Expression (Node (Discr_Val)) then
11073 Is_Static := False;
11077 Next_Elmt (Discr_Val);
11080 Set_Has_Static_Discriminants (Subt, Is_Static);
11084 -- Inherit the discriminants of the parent type
11086 Add_Discriminants : declare
11092 Old_C := First_Discriminant (Typ);
11094 while Present (Old_C) loop
11095 Num_Disc := Num_Disc + 1;
11096 New_C := Create_Component (Old_C);
11097 Set_Is_Public (New_C, Is_Public (Subt));
11098 Next_Discriminant (Old_C);
11101 -- For an untagged derived subtype, the number of discriminants may
11102 -- be smaller than the number of inherited discriminants, because
11103 -- several of them may be renamed by a single new discriminant.
11104 -- In this case, add the hidden discriminants back into the subtype,
11105 -- because otherwise the size of the subtype is computed incorrectly
11110 if Is_Derived_Type (Typ)
11111 and then not Is_Tagged_Type (Typ)
11113 Old_C := First_Stored_Discriminant (Typ);
11115 while Present (Old_C) loop
11116 Num_Gird := Num_Gird + 1;
11117 Next_Stored_Discriminant (Old_C);
11121 if Num_Gird > Num_Disc then
11123 -- Find out multiple uses of new discriminants, and add hidden
11124 -- components for the extra renamed discriminants. We recognize
11125 -- multiple uses through the Corresponding_Discriminant of a
11126 -- new discriminant: if it constrains several old discriminants,
11127 -- this field points to the last one in the parent type. The
11128 -- stored discriminants of the derived type have the same name
11129 -- as those of the parent.
11133 New_Discr : Entity_Id;
11134 Old_Discr : Entity_Id;
11137 Constr := First_Elmt (Stored_Constraint (Typ));
11138 Old_Discr := First_Stored_Discriminant (Typ);
11139 while Present (Constr) loop
11140 if Is_Entity_Name (Node (Constr))
11141 and then Ekind (Entity (Node (Constr))) = E_Discriminant
11143 New_Discr := Entity (Node (Constr));
11145 if Chars (Corresponding_Discriminant (New_Discr)) /=
11148 -- The new discriminant has been used to rename a
11149 -- subsequent old discriminant. Introduce a shadow
11150 -- component for the current old discriminant.
11152 New_C := Create_Component (Old_Discr);
11153 Set_Original_Record_Component (New_C, Old_Discr);
11157 Next_Elmt (Constr);
11158 Next_Stored_Discriminant (Old_Discr);
11162 end Add_Discriminants;
11165 and then Is_Variant_Record (Typ)
11167 Collect_Fixed_Components (Typ);
11169 Gather_Components (
11171 Component_List (Type_Definition (Parent (Typ))),
11172 Governed_By => Assoc_List,
11174 Report_Errors => Errors);
11175 pragma Assert (not Errors);
11177 Create_All_Components;
11179 -- If the subtype declaration is created for a tagged type derivation
11180 -- with constraints, we retrieve the record definition of the parent
11181 -- type to select the components of the proper variant.
11184 and then Is_Tagged_Type (Typ)
11185 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11187 Nkind (Type_Definition (Parent (Typ))) = N_Derived_Type_Definition
11188 and then Is_Variant_Record (Parent_Type)
11190 Collect_Fixed_Components (Typ);
11192 Gather_Components (
11194 Component_List (Type_Definition (Parent (Parent_Type))),
11195 Governed_By => Assoc_List,
11197 Report_Errors => Errors);
11198 pragma Assert (not Errors);
11200 -- If the tagged derivation has a type extension, collect all the
11201 -- new components therein.
11204 (Record_Extension_Part (Type_Definition (Parent (Typ))))
11206 Old_C := First_Component (Typ);
11207 while Present (Old_C) loop
11208 if Original_Record_Component (Old_C) = Old_C
11209 and then Chars (Old_C) /= Name_uTag
11210 and then Chars (Old_C) /= Name_uParent
11211 and then Chars (Old_C) /= Name_uController
11213 Append_Elmt (Old_C, Comp_List);
11216 Next_Component (Old_C);
11220 Create_All_Components;
11223 -- If discriminants are not static, or if this is a multi-level type
11224 -- extension, we have to include all components of the parent type.
11226 Old_C := First_Component (Typ);
11227 while Present (Old_C) loop
11228 New_C := Create_Component (Old_C);
11232 Constrain_Component_Type
11233 (Old_C, Subt, Decl_Node, Typ, Constraints));
11234 Set_Is_Public (New_C, Is_Public (Subt));
11236 Next_Component (Old_C);
11241 end Create_Constrained_Components;
11243 ------------------------------------------
11244 -- Decimal_Fixed_Point_Type_Declaration --
11245 ------------------------------------------
11247 procedure Decimal_Fixed_Point_Type_Declaration
11251 Loc : constant Source_Ptr := Sloc (Def);
11252 Digs_Expr : constant Node_Id := Digits_Expression (Def);
11253 Delta_Expr : constant Node_Id := Delta_Expression (Def);
11254 Implicit_Base : Entity_Id;
11261 Check_Restriction (No_Fixed_Point, Def);
11263 -- Create implicit base type
11266 Create_Itype (E_Decimal_Fixed_Point_Type, Parent (Def), T, 'B');
11267 Set_Etype (Implicit_Base, Implicit_Base);
11269 -- Analyze and process delta expression
11271 Analyze_And_Resolve (Delta_Expr, Universal_Real);
11273 Check_Delta_Expression (Delta_Expr);
11274 Delta_Val := Expr_Value_R (Delta_Expr);
11276 -- Check delta is power of 10, and determine scale value from it
11282 Scale_Val := Uint_0;
11285 if Val < Ureal_1 then
11286 while Val < Ureal_1 loop
11287 Val := Val * Ureal_10;
11288 Scale_Val := Scale_Val + 1;
11291 if Scale_Val > 18 then
11292 Error_Msg_N ("scale exceeds maximum value of 18", Def);
11293 Scale_Val := UI_From_Int (+18);
11297 while Val > Ureal_1 loop
11298 Val := Val / Ureal_10;
11299 Scale_Val := Scale_Val - 1;
11302 if Scale_Val < -18 then
11303 Error_Msg_N ("scale is less than minimum value of -18", Def);
11304 Scale_Val := UI_From_Int (-18);
11308 if Val /= Ureal_1 then
11309 Error_Msg_N ("delta expression must be a power of 10", Def);
11310 Delta_Val := Ureal_10 ** (-Scale_Val);
11314 -- Set delta, scale and small (small = delta for decimal type)
11316 Set_Delta_Value (Implicit_Base, Delta_Val);
11317 Set_Scale_Value (Implicit_Base, Scale_Val);
11318 Set_Small_Value (Implicit_Base, Delta_Val);
11320 -- Analyze and process digits expression
11322 Analyze_And_Resolve (Digs_Expr, Any_Integer);
11323 Check_Digits_Expression (Digs_Expr);
11324 Digs_Val := Expr_Value (Digs_Expr);
11326 if Digs_Val > 18 then
11327 Digs_Val := UI_From_Int (+18);
11328 Error_Msg_N ("digits value out of range, maximum is 18", Digs_Expr);
11331 Set_Digits_Value (Implicit_Base, Digs_Val);
11332 Bound_Val := UR_From_Uint (10 ** Digs_Val - 1) * Delta_Val;
11334 -- Set range of base type from digits value for now. This will be
11335 -- expanded to represent the true underlying base range by Freeze.
11337 Set_Fixed_Range (Implicit_Base, Loc, -Bound_Val, Bound_Val);
11339 -- Note: We leave size as zero for now, size will be set at freeze
11340 -- time. We have to do this for ordinary fixed-point, because the size
11341 -- depends on the specified small, and we might as well do the same for
11342 -- decimal fixed-point.
11344 pragma Assert (Esize (Implicit_Base) = Uint_0);
11346 -- If there are bounds given in the declaration use them as the
11347 -- bounds of the first named subtype.
11349 if Present (Real_Range_Specification (Def)) then
11351 RRS : constant Node_Id := Real_Range_Specification (Def);
11352 Low : constant Node_Id := Low_Bound (RRS);
11353 High : constant Node_Id := High_Bound (RRS);
11358 Analyze_And_Resolve (Low, Any_Real);
11359 Analyze_And_Resolve (High, Any_Real);
11360 Check_Real_Bound (Low);
11361 Check_Real_Bound (High);
11362 Low_Val := Expr_Value_R (Low);
11363 High_Val := Expr_Value_R (High);
11365 if Low_Val < (-Bound_Val) then
11367 ("range low bound too small for digits value", Low);
11368 Low_Val := -Bound_Val;
11371 if High_Val > Bound_Val then
11373 ("range high bound too large for digits value", High);
11374 High_Val := Bound_Val;
11377 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
11380 -- If no explicit range, use range that corresponds to given
11381 -- digits value. This will end up as the final range for the
11385 Set_Fixed_Range (T, Loc, -Bound_Val, Bound_Val);
11388 -- Complete entity for first subtype
11390 Set_Ekind (T, E_Decimal_Fixed_Point_Subtype);
11391 Set_Etype (T, Implicit_Base);
11392 Set_Size_Info (T, Implicit_Base);
11393 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
11394 Set_Digits_Value (T, Digs_Val);
11395 Set_Delta_Value (T, Delta_Val);
11396 Set_Small_Value (T, Delta_Val);
11397 Set_Scale_Value (T, Scale_Val);
11398 Set_Is_Constrained (T);
11399 end Decimal_Fixed_Point_Type_Declaration;
11401 -----------------------------------
11402 -- Derive_Progenitor_Subprograms --
11403 -----------------------------------
11405 procedure Derive_Progenitor_Subprograms
11406 (Parent_Type : Entity_Id;
11407 Tagged_Type : Entity_Id)
11412 Iface_Elmt : Elmt_Id;
11413 Iface_Subp : Entity_Id;
11414 New_Subp : Entity_Id := Empty;
11415 Prim_Elmt : Elmt_Id;
11420 pragma Assert (Ada_Version >= Ada_05
11421 and then Is_Record_Type (Tagged_Type)
11422 and then Is_Tagged_Type (Tagged_Type)
11423 and then Has_Interfaces (Tagged_Type));
11425 -- Step 1: Transfer to the full-view primitives associated with the
11426 -- partial-view that cover interface primitives. Conceptually this
11427 -- work should be done later by Process_Full_View; done here to
11428 -- simplify its implementation at later stages. It can be safely
11429 -- done here because interfaces must be visible in the partial and
11430 -- private view (RM 7.3(7.3/2)).
11432 -- Small optimization: This work is only required if the parent is
11433 -- abstract. If the tagged type is not abstract, it cannot have
11434 -- abstract primitives (the only entities in the list of primitives of
11435 -- non-abstract tagged types that can reference abstract primitives
11436 -- through its Alias attribute are the internal entities that have
11437 -- attribute Interface_Alias, and these entities are generated later
11438 -- by Freeze_Record_Type).
11440 if In_Private_Part (Current_Scope)
11441 and then Is_Abstract_Type (Parent_Type)
11443 Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
11444 while Present (Elmt) loop
11445 Subp := Node (Elmt);
11447 -- At this stage it is not possible to have entities in the list
11448 -- of primitives that have attribute Interface_Alias
11450 pragma Assert (No (Interface_Alias (Subp)));
11452 Typ := Find_Dispatching_Type (Ultimate_Alias (Subp));
11454 if Is_Interface (Typ) then
11455 E := Find_Primitive_Covering_Interface
11456 (Tagged_Type => Tagged_Type,
11457 Iface_Prim => Subp);
11460 and then Find_Dispatching_Type (Ultimate_Alias (E)) /= Typ
11462 Replace_Elmt (Elmt, E);
11463 Remove_Homonym (Subp);
11471 -- Step 2: Add primitives of progenitors that are not implemented by
11472 -- parents of Tagged_Type
11474 if Present (Interfaces (Tagged_Type)) then
11475 Iface_Elmt := First_Elmt (Interfaces (Tagged_Type));
11476 while Present (Iface_Elmt) loop
11477 Iface := Node (Iface_Elmt);
11479 Prim_Elmt := First_Elmt (Primitive_Operations (Iface));
11480 while Present (Prim_Elmt) loop
11481 Iface_Subp := Node (Prim_Elmt);
11483 -- Exclude derivation of predefined primitives except those
11484 -- that come from source. Required to catch declarations of
11485 -- equality operators of interfaces. For example:
11487 -- type Iface is interface;
11488 -- function "=" (Left, Right : Iface) return Boolean;
11490 if not Is_Predefined_Dispatching_Operation (Iface_Subp)
11491 or else Comes_From_Source (Iface_Subp)
11493 E := Find_Primitive_Covering_Interface
11494 (Tagged_Type => Tagged_Type,
11495 Iface_Prim => Iface_Subp);
11497 -- If not found we derive a new primitive leaving its alias
11498 -- attribute referencing the interface primitive
11502 (New_Subp, Iface_Subp, Tagged_Type, Iface);
11504 -- Propagate to the full view interface entities associated
11505 -- with the partial view
11507 elsif In_Private_Part (Current_Scope)
11508 and then Present (Alias (E))
11509 and then Alias (E) = Iface_Subp
11511 List_Containing (Parent (E)) /=
11512 Private_Declarations
11514 (Unit_Declaration_Node (Current_Scope)))
11516 Append_Elmt (E, Primitive_Operations (Tagged_Type));
11520 Next_Elmt (Prim_Elmt);
11523 Next_Elmt (Iface_Elmt);
11526 end Derive_Progenitor_Subprograms;
11528 -----------------------
11529 -- Derive_Subprogram --
11530 -----------------------
11532 procedure Derive_Subprogram
11533 (New_Subp : in out Entity_Id;
11534 Parent_Subp : Entity_Id;
11535 Derived_Type : Entity_Id;
11536 Parent_Type : Entity_Id;
11537 Actual_Subp : Entity_Id := Empty)
11539 Formal : Entity_Id;
11540 -- Formal parameter of parent primitive operation
11542 Formal_Of_Actual : Entity_Id;
11543 -- Formal parameter of actual operation, when the derivation is to
11544 -- create a renaming for a primitive operation of an actual in an
11547 New_Formal : Entity_Id;
11548 -- Formal of inherited operation
11550 Visible_Subp : Entity_Id := Parent_Subp;
11552 function Is_Private_Overriding return Boolean;
11553 -- If Subp is a private overriding of a visible operation, the inherited
11554 -- operation derives from the overridden op (even though its body is the
11555 -- overriding one) and the inherited operation is visible now. See
11556 -- sem_disp to see the full details of the handling of the overridden
11557 -- subprogram, which is removed from the list of primitive operations of
11558 -- the type. The overridden subprogram is saved locally in Visible_Subp,
11559 -- and used to diagnose abstract operations that need overriding in the
11562 procedure Replace_Type (Id, New_Id : Entity_Id);
11563 -- When the type is an anonymous access type, create a new access type
11564 -- designating the derived type.
11566 procedure Set_Derived_Name;
11567 -- This procedure sets the appropriate Chars name for New_Subp. This
11568 -- is normally just a copy of the parent name. An exception arises for
11569 -- type support subprograms, where the name is changed to reflect the
11570 -- name of the derived type, e.g. if type foo is derived from type bar,
11571 -- then a procedure barDA is derived with a name fooDA.
11573 ---------------------------
11574 -- Is_Private_Overriding --
11575 ---------------------------
11577 function Is_Private_Overriding return Boolean is
11581 -- If the parent is not a dispatching operation there is no
11582 -- need to investigate overridings
11584 if not Is_Dispatching_Operation (Parent_Subp) then
11588 -- The visible operation that is overridden is a homonym of the
11589 -- parent subprogram. We scan the homonym chain to find the one
11590 -- whose alias is the subprogram we are deriving.
11592 Prev := Current_Entity (Parent_Subp);
11593 while Present (Prev) loop
11594 if Ekind (Prev) = Ekind (Parent_Subp)
11595 and then Alias (Prev) = Parent_Subp
11596 and then Scope (Parent_Subp) = Scope (Prev)
11597 and then not Is_Hidden (Prev)
11599 Visible_Subp := Prev;
11603 Prev := Homonym (Prev);
11607 end Is_Private_Overriding;
11613 procedure Replace_Type (Id, New_Id : Entity_Id) is
11614 Acc_Type : Entity_Id;
11615 Par : constant Node_Id := Parent (Derived_Type);
11618 -- When the type is an anonymous access type, create a new access
11619 -- type designating the derived type. This itype must be elaborated
11620 -- at the point of the derivation, not on subsequent calls that may
11621 -- be out of the proper scope for Gigi, so we insert a reference to
11622 -- it after the derivation.
11624 if Ekind (Etype (Id)) = E_Anonymous_Access_Type then
11626 Desig_Typ : Entity_Id := Designated_Type (Etype (Id));
11629 if Ekind (Desig_Typ) = E_Record_Type_With_Private
11630 and then Present (Full_View (Desig_Typ))
11631 and then not Is_Private_Type (Parent_Type)
11633 Desig_Typ := Full_View (Desig_Typ);
11636 if Base_Type (Desig_Typ) = Base_Type (Parent_Type)
11638 -- Ada 2005 (AI-251): Handle also derivations of abstract
11639 -- interface primitives.
11641 or else (Is_Interface (Desig_Typ)
11642 and then not Is_Class_Wide_Type (Desig_Typ))
11644 Acc_Type := New_Copy (Etype (Id));
11645 Set_Etype (Acc_Type, Acc_Type);
11646 Set_Scope (Acc_Type, New_Subp);
11648 -- Compute size of anonymous access type
11650 if Is_Array_Type (Desig_Typ)
11651 and then not Is_Constrained (Desig_Typ)
11653 Init_Size (Acc_Type, 2 * System_Address_Size);
11655 Init_Size (Acc_Type, System_Address_Size);
11658 Init_Alignment (Acc_Type);
11659 Set_Directly_Designated_Type (Acc_Type, Derived_Type);
11661 Set_Etype (New_Id, Acc_Type);
11662 Set_Scope (New_Id, New_Subp);
11664 -- Create a reference to it
11665 Build_Itype_Reference (Acc_Type, Parent (Derived_Type));
11668 Set_Etype (New_Id, Etype (Id));
11672 elsif Base_Type (Etype (Id)) = Base_Type (Parent_Type)
11674 (Ekind (Etype (Id)) = E_Record_Type_With_Private
11675 and then Present (Full_View (Etype (Id)))
11677 Base_Type (Full_View (Etype (Id))) = Base_Type (Parent_Type))
11679 -- Constraint checks on formals are generated during expansion,
11680 -- based on the signature of the original subprogram. The bounds
11681 -- of the derived type are not relevant, and thus we can use
11682 -- the base type for the formals. However, the return type may be
11683 -- used in a context that requires that the proper static bounds
11684 -- be used (a case statement, for example) and for those cases
11685 -- we must use the derived type (first subtype), not its base.
11687 -- If the derived_type_definition has no constraints, we know that
11688 -- the derived type has the same constraints as the first subtype
11689 -- of the parent, and we can also use it rather than its base,
11690 -- which can lead to more efficient code.
11692 if Etype (Id) = Parent_Type then
11693 if Is_Scalar_Type (Parent_Type)
11695 Subtypes_Statically_Compatible (Parent_Type, Derived_Type)
11697 Set_Etype (New_Id, Derived_Type);
11699 elsif Nkind (Par) = N_Full_Type_Declaration
11701 Nkind (Type_Definition (Par)) = N_Derived_Type_Definition
11704 (Subtype_Indication (Type_Definition (Par)))
11706 Set_Etype (New_Id, Derived_Type);
11709 Set_Etype (New_Id, Base_Type (Derived_Type));
11713 Set_Etype (New_Id, Base_Type (Derived_Type));
11716 -- Ada 2005 (AI-251): Handle derivations of abstract interface
11719 elsif Is_Interface (Etype (Id))
11720 and then not Is_Class_Wide_Type (Etype (Id))
11721 and then Is_Progenitor (Etype (Id), Derived_Type)
11723 Set_Etype (New_Id, Derived_Type);
11726 Set_Etype (New_Id, Etype (Id));
11730 ----------------------
11731 -- Set_Derived_Name --
11732 ----------------------
11734 procedure Set_Derived_Name is
11735 Nm : constant TSS_Name_Type := Get_TSS_Name (Parent_Subp);
11737 if Nm = TSS_Null then
11738 Set_Chars (New_Subp, Chars (Parent_Subp));
11740 Set_Chars (New_Subp, Make_TSS_Name (Base_Type (Derived_Type), Nm));
11742 end Set_Derived_Name;
11746 Parent_Overrides_Interface_Primitive : Boolean := False;
11748 -- Start of processing for Derive_Subprogram
11752 New_Entity (Nkind (Parent_Subp), Sloc (Derived_Type));
11753 Set_Ekind (New_Subp, Ekind (Parent_Subp));
11755 -- Check whether the parent overrides an interface primitive
11757 if Is_Overriding_Operation (Parent_Subp) then
11759 E : Entity_Id := Parent_Subp;
11761 while Present (Overridden_Operation (E)) loop
11762 E := Ultimate_Alias (Overridden_Operation (E));
11765 Parent_Overrides_Interface_Primitive :=
11766 Is_Dispatching_Operation (E)
11767 and then Present (Find_Dispatching_Type (E))
11768 and then Is_Interface (Find_Dispatching_Type (E));
11772 -- Check whether the inherited subprogram is a private operation that
11773 -- should be inherited but not yet made visible. Such subprograms can
11774 -- become visible at a later point (e.g., the private part of a public
11775 -- child unit) via Declare_Inherited_Private_Subprograms. If the
11776 -- following predicate is true, then this is not such a private
11777 -- operation and the subprogram simply inherits the name of the parent
11778 -- subprogram. Note the special check for the names of controlled
11779 -- operations, which are currently exempted from being inherited with
11780 -- a hidden name because they must be findable for generation of
11781 -- implicit run-time calls.
11783 if not Is_Hidden (Parent_Subp)
11784 or else Is_Internal (Parent_Subp)
11785 or else Is_Private_Overriding
11786 or else Is_Internal_Name (Chars (Parent_Subp))
11787 or else Chars (Parent_Subp) = Name_Initialize
11788 or else Chars (Parent_Subp) = Name_Adjust
11789 or else Chars (Parent_Subp) = Name_Finalize
11793 -- If parent is hidden, this can be a regular derivation if the
11794 -- parent is immediately visible in a non-instantiating context,
11795 -- or if we are in the private part of an instance. This test
11796 -- should still be refined ???
11798 -- The test for In_Instance_Not_Visible avoids inheriting the derived
11799 -- operation as a non-visible operation in cases where the parent
11800 -- subprogram might not be visible now, but was visible within the
11801 -- original generic, so it would be wrong to make the inherited
11802 -- subprogram non-visible now. (Not clear if this test is fully
11803 -- correct; are there any cases where we should declare the inherited
11804 -- operation as not visible to avoid it being overridden, e.g., when
11805 -- the parent type is a generic actual with private primitives ???)
11807 -- (they should be treated the same as other private inherited
11808 -- subprograms, but it's not clear how to do this cleanly). ???
11810 elsif (In_Open_Scopes (Scope (Base_Type (Parent_Type)))
11811 and then Is_Immediately_Visible (Parent_Subp)
11812 and then not In_Instance)
11813 or else In_Instance_Not_Visible
11817 -- Ada 2005 (AI-251): Regular derivation if the parent subprogram
11818 -- overrides an interface primitive because interface primitives
11819 -- must be visible in the partial view of the parent (RM 7.3 (7.3/2))
11821 elsif Parent_Overrides_Interface_Primitive then
11824 -- The type is inheriting a private operation, so enter
11825 -- it with a special name so it can't be overridden.
11828 Set_Chars (New_Subp, New_External_Name (Chars (Parent_Subp), 'P'));
11831 Set_Parent (New_Subp, Parent (Derived_Type));
11833 if Present (Actual_Subp) then
11834 Replace_Type (Actual_Subp, New_Subp);
11836 Replace_Type (Parent_Subp, New_Subp);
11839 Conditional_Delay (New_Subp, Parent_Subp);
11841 -- If we are creating a renaming for a primitive operation of an
11842 -- actual of a generic derived type, we must examine the signature
11843 -- of the actual primitive, not that of the generic formal, which for
11844 -- example may be an interface. However the name and initial value
11845 -- of the inherited operation are those of the formal primitive.
11847 Formal := First_Formal (Parent_Subp);
11849 if Present (Actual_Subp) then
11850 Formal_Of_Actual := First_Formal (Actual_Subp);
11852 Formal_Of_Actual := Empty;
11855 while Present (Formal) loop
11856 New_Formal := New_Copy (Formal);
11858 -- Normally we do not go copying parents, but in the case of
11859 -- formals, we need to link up to the declaration (which is the
11860 -- parameter specification), and it is fine to link up to the
11861 -- original formal's parameter specification in this case.
11863 Set_Parent (New_Formal, Parent (Formal));
11864 Append_Entity (New_Formal, New_Subp);
11866 if Present (Formal_Of_Actual) then
11867 Replace_Type (Formal_Of_Actual, New_Formal);
11868 Next_Formal (Formal_Of_Actual);
11870 Replace_Type (Formal, New_Formal);
11873 Next_Formal (Formal);
11876 -- If this derivation corresponds to a tagged generic actual, then
11877 -- primitive operations rename those of the actual. Otherwise the
11878 -- primitive operations rename those of the parent type, If the parent
11879 -- renames an intrinsic operator, so does the new subprogram. We except
11880 -- concatenation, which is always properly typed, and does not get
11881 -- expanded as other intrinsic operations.
11883 if No (Actual_Subp) then
11884 if Is_Intrinsic_Subprogram (Parent_Subp) then
11885 Set_Is_Intrinsic_Subprogram (New_Subp);
11887 if Present (Alias (Parent_Subp))
11888 and then Chars (Parent_Subp) /= Name_Op_Concat
11890 Set_Alias (New_Subp, Alias (Parent_Subp));
11892 Set_Alias (New_Subp, Parent_Subp);
11896 Set_Alias (New_Subp, Parent_Subp);
11900 Set_Alias (New_Subp, Actual_Subp);
11903 -- Derived subprograms of a tagged type must inherit the convention
11904 -- of the parent subprogram (a requirement of AI-117). Derived
11905 -- subprograms of untagged types simply get convention Ada by default.
11907 if Is_Tagged_Type (Derived_Type) then
11908 Set_Convention (New_Subp, Convention (Parent_Subp));
11911 Set_Is_Imported (New_Subp, Is_Imported (Parent_Subp));
11912 Set_Is_Exported (New_Subp, Is_Exported (Parent_Subp));
11914 if Ekind (Parent_Subp) = E_Procedure then
11915 Set_Is_Valued_Procedure
11916 (New_Subp, Is_Valued_Procedure (Parent_Subp));
11919 -- No_Return must be inherited properly. If this is overridden in the
11920 -- case of a dispatching operation, then a check is made in Sem_Disp
11921 -- that the overriding operation is also No_Return (no such check is
11922 -- required for the case of non-dispatching operation.
11924 Set_No_Return (New_Subp, No_Return (Parent_Subp));
11926 -- A derived function with a controlling result is abstract. If the
11927 -- Derived_Type is a nonabstract formal generic derived type, then
11928 -- inherited operations are not abstract: the required check is done at
11929 -- instantiation time. If the derivation is for a generic actual, the
11930 -- function is not abstract unless the actual is.
11932 if Is_Generic_Type (Derived_Type)
11933 and then not Is_Abstract_Type (Derived_Type)
11937 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
11938 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2).
11940 elsif Ada_Version >= Ada_05
11941 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11942 or else (Is_Tagged_Type (Derived_Type)
11943 and then Etype (New_Subp) = Derived_Type
11944 and then not Is_Null_Extension (Derived_Type))
11945 or else (Is_Tagged_Type (Derived_Type)
11946 and then Ekind (Etype (New_Subp)) =
11947 E_Anonymous_Access_Type
11948 and then Designated_Type (Etype (New_Subp)) =
11950 and then not Is_Null_Extension (Derived_Type)))
11951 and then No (Actual_Subp)
11953 if not Is_Tagged_Type (Derived_Type)
11954 or else Is_Abstract_Type (Derived_Type)
11955 or else Is_Abstract_Subprogram (Alias (New_Subp))
11957 Set_Is_Abstract_Subprogram (New_Subp);
11959 Set_Requires_Overriding (New_Subp);
11962 elsif Ada_Version < Ada_05
11963 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11964 or else (Is_Tagged_Type (Derived_Type)
11965 and then Etype (New_Subp) = Derived_Type
11966 and then No (Actual_Subp)))
11968 Set_Is_Abstract_Subprogram (New_Subp);
11970 -- Finally, if the parent type is abstract we must verify that all
11971 -- inherited operations are either non-abstract or overridden, or that
11972 -- the derived type itself is abstract (this check is performed at the
11973 -- end of a package declaration, in Check_Abstract_Overriding). A
11974 -- private overriding in the parent type will not be visible in the
11975 -- derivation if we are not in an inner package or in a child unit of
11976 -- the parent type, in which case the abstractness of the inherited
11977 -- operation is carried to the new subprogram.
11979 elsif Is_Abstract_Type (Parent_Type)
11980 and then not In_Open_Scopes (Scope (Parent_Type))
11981 and then Is_Private_Overriding
11982 and then Is_Abstract_Subprogram (Visible_Subp)
11984 if No (Actual_Subp) then
11985 Set_Alias (New_Subp, Visible_Subp);
11986 Set_Is_Abstract_Subprogram
11989 -- If this is a derivation for an instance of a formal derived
11990 -- type, abstractness comes from the primitive operation of the
11991 -- actual, not from the operation inherited from the ancestor.
11993 Set_Is_Abstract_Subprogram
11994 (New_Subp, Is_Abstract_Subprogram (Actual_Subp));
11998 New_Overloaded_Entity (New_Subp, Derived_Type);
12000 -- Check for case of a derived subprogram for the instantiation of a
12001 -- formal derived tagged type, if so mark the subprogram as dispatching
12002 -- and inherit the dispatching attributes of the parent subprogram. The
12003 -- derived subprogram is effectively renaming of the actual subprogram,
12004 -- so it needs to have the same attributes as the actual.
12006 if Present (Actual_Subp)
12007 and then Is_Dispatching_Operation (Parent_Subp)
12009 Set_Is_Dispatching_Operation (New_Subp);
12011 if Present (DTC_Entity (Parent_Subp)) then
12012 Set_DTC_Entity (New_Subp, DTC_Entity (Parent_Subp));
12013 Set_DT_Position (New_Subp, DT_Position (Parent_Subp));
12017 -- Indicate that a derived subprogram does not require a body and that
12018 -- it does not require processing of default expressions.
12020 Set_Has_Completion (New_Subp);
12021 Set_Default_Expressions_Processed (New_Subp);
12023 if Ekind (New_Subp) = E_Function then
12024 Set_Mechanism (New_Subp, Mechanism (Parent_Subp));
12026 end Derive_Subprogram;
12028 ------------------------
12029 -- Derive_Subprograms --
12030 ------------------------
12032 procedure Derive_Subprograms
12033 (Parent_Type : Entity_Id;
12034 Derived_Type : Entity_Id;
12035 Generic_Actual : Entity_Id := Empty)
12037 Op_List : constant Elist_Id :=
12038 Collect_Primitive_Operations (Parent_Type);
12040 function Check_Derived_Type return Boolean;
12041 -- Check that all primitive inherited from Parent_Type are found in
12042 -- the list of primitives of Derived_Type exactly in the same order.
12044 function Check_Derived_Type return Boolean is
12048 New_Subp : Entity_Id;
12053 -- Traverse list of entities in the current scope searching for
12054 -- an incomplete type whose full-view is derived type
12056 E := First_Entity (Scope (Derived_Type));
12058 and then E /= Derived_Type
12060 if Ekind (E) = E_Incomplete_Type
12061 and then Present (Full_View (E))
12062 and then Full_View (E) = Derived_Type
12064 -- Disable this test if Derived_Type completes an incomplete
12065 -- type because in such case more primitives can be added
12066 -- later to the list of primitives of Derived_Type by routine
12067 -- Process_Incomplete_Dependents
12072 E := Next_Entity (E);
12075 List := Collect_Primitive_Operations (Derived_Type);
12076 Elmt := First_Elmt (List);
12078 Op_Elmt := First_Elmt (Op_List);
12079 while Present (Op_Elmt) loop
12080 Subp := Node (Op_Elmt);
12081 New_Subp := Node (Elmt);
12083 -- At this early stage Derived_Type has no entities with attribute
12084 -- Interface_Alias. In addition, such primitives are always
12085 -- located at the end of the list of primitives of Parent_Type.
12086 -- Therefore, if found we can safely stop processing pending
12089 exit when Present (Interface_Alias (Subp));
12091 -- Handle hidden entities
12093 if not Is_Predefined_Dispatching_Operation (Subp)
12094 and then Is_Hidden (Subp)
12096 if Present (New_Subp)
12097 and then Primitive_Names_Match (Subp, New_Subp)
12103 if not Present (New_Subp)
12104 or else Ekind (Subp) /= Ekind (New_Subp)
12105 or else not Primitive_Names_Match (Subp, New_Subp)
12113 Next_Elmt (Op_Elmt);
12117 end Check_Derived_Type;
12121 Alias_Subp : Entity_Id;
12122 Act_List : Elist_Id;
12123 Act_Elmt : Elmt_Id := No_Elmt;
12124 Act_Subp : Entity_Id := Empty;
12126 Need_Search : Boolean := False;
12127 New_Subp : Entity_Id := Empty;
12128 Parent_Base : Entity_Id;
12131 -- Start of processing for Derive_Subprograms
12134 if Ekind (Parent_Type) = E_Record_Type_With_Private
12135 and then Has_Discriminants (Parent_Type)
12136 and then Present (Full_View (Parent_Type))
12138 Parent_Base := Full_View (Parent_Type);
12140 Parent_Base := Parent_Type;
12143 if Present (Generic_Actual) then
12144 Act_List := Collect_Primitive_Operations (Generic_Actual);
12145 Act_Elmt := First_Elmt (Act_List);
12148 -- Derive primitives inherited from the parent. Note that if the generic
12149 -- actual is present, this is not really a type derivation, it is a
12150 -- completion within an instance.
12152 -- Case 1: Derived_Type does not implement interfaces
12154 if not Is_Tagged_Type (Derived_Type)
12155 or else (not Has_Interfaces (Derived_Type)
12156 and then not (Present (Generic_Actual)
12158 Has_Interfaces (Generic_Actual)))
12160 Elmt := First_Elmt (Op_List);
12161 while Present (Elmt) loop
12162 Subp := Node (Elmt);
12164 -- Literals are derived earlier in the process of building the
12165 -- derived type, and are skipped here.
12167 if Ekind (Subp) = E_Enumeration_Literal then
12170 -- The actual is a direct descendant and the common primitive
12171 -- operations appear in the same order.
12173 -- If the generic parent type is present, the derived type is an
12174 -- instance of a formal derived type, and within the instance its
12175 -- operations are those of the actual. We derive from the formal
12176 -- type but make the inherited operations aliases of the
12177 -- corresponding operations of the actual.
12181 (New_Subp, Subp, Derived_Type, Parent_Base, Node (Act_Elmt));
12183 if Present (Act_Elmt) then
12184 Next_Elmt (Act_Elmt);
12191 -- Case 2: Derived_Type implements interfaces
12194 -- If the parent type has no predefined primitives we remove
12195 -- predefined primitives from the list of primitives of generic
12196 -- actual to simplify the complexity of this algorithm.
12198 if Present (Generic_Actual) then
12200 Has_Predefined_Primitives : Boolean := False;
12203 -- Check if the parent type has predefined primitives
12205 Elmt := First_Elmt (Op_List);
12206 while Present (Elmt) loop
12207 Subp := Node (Elmt);
12209 if Is_Predefined_Dispatching_Operation (Subp)
12210 and then not Comes_From_Source (Ultimate_Alias (Subp))
12212 Has_Predefined_Primitives := True;
12219 -- Remove predefined primitives of Generic_Actual. We must use
12220 -- an auxiliary list because in case of tagged types the value
12221 -- returned by Collect_Primitive_Operations is the value stored
12222 -- in its Primitive_Operations attribute (and we don't want to
12223 -- modify its current contents).
12225 if not Has_Predefined_Primitives then
12227 Aux_List : constant Elist_Id := New_Elmt_List;
12230 Elmt := First_Elmt (Act_List);
12231 while Present (Elmt) loop
12232 Subp := Node (Elmt);
12234 if not Is_Predefined_Dispatching_Operation (Subp)
12235 or else Comes_From_Source (Subp)
12237 Append_Elmt (Subp, Aux_List);
12243 Act_List := Aux_List;
12247 Act_Elmt := First_Elmt (Act_List);
12248 Act_Subp := Node (Act_Elmt);
12252 -- Stage 1: If the generic actual is not present we derive the
12253 -- primitives inherited from the parent type. If the generic parent
12254 -- type is present, the derived type is an instance of a formal
12255 -- derived type, and within the instance its operations are those of
12256 -- the actual. We derive from the formal type but make the inherited
12257 -- operations aliases of the corresponding operations of the actual.
12259 Elmt := First_Elmt (Op_List);
12260 while Present (Elmt) loop
12261 Subp := Node (Elmt);
12262 Alias_Subp := Ultimate_Alias (Subp);
12264 -- At this early stage Derived_Type has no entities with attribute
12265 -- Interface_Alias. In addition, such primitives are always
12266 -- located at the end of the list of primitives of Parent_Type.
12267 -- Therefore, if found we can safely stop processing pending
12270 exit when Present (Interface_Alias (Subp));
12272 -- If the generic actual is present find the corresponding
12273 -- operation in the generic actual. If the parent type is a
12274 -- direct ancestor of the derived type then, even if it is an
12275 -- interface, the operations are inherited from the primary
12276 -- dispatch table and are in the proper order. If we detect here
12277 -- that primitives are not in the same order we traverse the list
12278 -- of primitive operations of the actual to find the one that
12279 -- implements the interface primitive.
12283 (Present (Generic_Actual)
12284 and then Present (Act_Subp)
12285 and then not Primitive_Names_Match (Subp, Act_Subp))
12287 pragma Assert (not Is_Ancestor (Parent_Base, Generic_Actual));
12288 pragma Assert (Is_Interface (Parent_Base));
12290 -- Remember that we need searching for all the pending
12293 Need_Search := True;
12295 -- Handle entities associated with interface primitives
12297 if Present (Alias (Subp))
12298 and then Is_Interface (Find_Dispatching_Type (Alias (Subp)))
12299 and then not Is_Predefined_Dispatching_Operation (Subp)
12302 Find_Primitive_Covering_Interface
12303 (Tagged_Type => Generic_Actual,
12304 Iface_Prim => Subp);
12306 -- Handle predefined primitives plus the rest of user-defined
12310 Act_Elmt := First_Elmt (Act_List);
12311 while Present (Act_Elmt) loop
12312 Act_Subp := Node (Act_Elmt);
12314 exit when Primitive_Names_Match (Subp, Act_Subp)
12315 and then Type_Conformant (Subp, Act_Subp,
12316 Skip_Controlling_Formals => True)
12317 and then No (Interface_Alias (Act_Subp));
12319 Next_Elmt (Act_Elmt);
12324 -- Case 1: If the parent is a limited interface then it has the
12325 -- predefined primitives of synchronized interfaces. However, the
12326 -- actual type may be a non-limited type and hence it does not
12327 -- have such primitives.
12329 if Present (Generic_Actual)
12330 and then not Present (Act_Subp)
12331 and then Is_Limited_Interface (Parent_Base)
12332 and then Is_Predefined_Interface_Primitive (Subp)
12336 -- Case 2: Inherit entities associated with interfaces that
12337 -- were not covered by the parent type. We exclude here null
12338 -- interface primitives because they do not need special
12341 elsif Present (Alias (Subp))
12342 and then Is_Interface (Find_Dispatching_Type (Alias_Subp))
12344 (Nkind (Parent (Alias_Subp)) = N_Procedure_Specification
12345 and then Null_Present (Parent (Alias_Subp)))
12348 (New_Subp => New_Subp,
12349 Parent_Subp => Alias_Subp,
12350 Derived_Type => Derived_Type,
12351 Parent_Type => Find_Dispatching_Type (Alias_Subp),
12352 Actual_Subp => Act_Subp);
12354 if No (Generic_Actual) then
12355 Set_Alias (New_Subp, Subp);
12358 -- Case 3: Common derivation
12362 (New_Subp => New_Subp,
12363 Parent_Subp => Subp,
12364 Derived_Type => Derived_Type,
12365 Parent_Type => Parent_Base,
12366 Actual_Subp => Act_Subp);
12369 -- No need to update Act_Elm if we must search for the
12370 -- corresponding operation in the generic actual
12373 and then Present (Act_Elmt)
12375 Next_Elmt (Act_Elmt);
12376 Act_Subp := Node (Act_Elmt);
12382 -- Inherit additional operations from progenitors. If the derived
12383 -- type is a generic actual, there are not new primitive operations
12384 -- for the type because it has those of the actual, and therefore
12385 -- nothing needs to be done. The renamings generated above are not
12386 -- primitive operations, and their purpose is simply to make the
12387 -- proper operations visible within an instantiation.
12389 if No (Generic_Actual) then
12390 Derive_Progenitor_Subprograms (Parent_Base, Derived_Type);
12394 -- Final check: Direct descendants must have their primitives in the
12395 -- same order. We exclude from this test non-tagged types and instances
12396 -- of formal derived types. We skip this test if we have already
12397 -- reported serious errors in the sources.
12399 pragma Assert (not Is_Tagged_Type (Derived_Type)
12400 or else Present (Generic_Actual)
12401 or else Serious_Errors_Detected > 0
12402 or else Check_Derived_Type);
12403 end Derive_Subprograms;
12405 --------------------------------
12406 -- Derived_Standard_Character --
12407 --------------------------------
12409 procedure Derived_Standard_Character
12411 Parent_Type : Entity_Id;
12412 Derived_Type : Entity_Id)
12414 Loc : constant Source_Ptr := Sloc (N);
12415 Def : constant Node_Id := Type_Definition (N);
12416 Indic : constant Node_Id := Subtype_Indication (Def);
12417 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
12418 Implicit_Base : constant Entity_Id :=
12420 (E_Enumeration_Type, N, Derived_Type, 'B');
12426 Discard_Node (Process_Subtype (Indic, N));
12428 Set_Etype (Implicit_Base, Parent_Base);
12429 Set_Size_Info (Implicit_Base, Root_Type (Parent_Type));
12430 Set_RM_Size (Implicit_Base, RM_Size (Root_Type (Parent_Type)));
12432 Set_Is_Character_Type (Implicit_Base, True);
12433 Set_Has_Delayed_Freeze (Implicit_Base);
12435 -- The bounds of the implicit base are the bounds of the parent base.
12436 -- Note that their type is the parent base.
12438 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
12439 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
12441 Set_Scalar_Range (Implicit_Base,
12444 High_Bound => Hi));
12446 Conditional_Delay (Derived_Type, Parent_Type);
12448 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
12449 Set_Etype (Derived_Type, Implicit_Base);
12450 Set_Size_Info (Derived_Type, Parent_Type);
12452 if Unknown_RM_Size (Derived_Type) then
12453 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
12456 Set_Is_Character_Type (Derived_Type, True);
12458 if Nkind (Indic) /= N_Subtype_Indication then
12460 -- If no explicit constraint, the bounds are those
12461 -- of the parent type.
12463 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Type));
12464 Hi := New_Copy_Tree (Type_High_Bound (Parent_Type));
12465 Set_Scalar_Range (Derived_Type, Make_Range (Loc, Lo, Hi));
12468 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
12470 -- Because the implicit base is used in the conversion of the bounds, we
12471 -- have to freeze it now. This is similar to what is done for numeric
12472 -- types, and it equally suspicious, but otherwise a non-static bound
12473 -- will have a reference to an unfrozen type, which is rejected by Gigi
12474 -- (???). This requires specific care for definition of stream
12475 -- attributes. For details, see comments at the end of
12476 -- Build_Derived_Numeric_Type.
12478 Freeze_Before (N, Implicit_Base);
12479 end Derived_Standard_Character;
12481 ------------------------------
12482 -- Derived_Type_Declaration --
12483 ------------------------------
12485 procedure Derived_Type_Declaration
12488 Is_Completion : Boolean)
12490 Parent_Type : Entity_Id;
12492 function Comes_From_Generic (Typ : Entity_Id) return Boolean;
12493 -- Check whether the parent type is a generic formal, or derives
12494 -- directly or indirectly from one.
12496 ------------------------
12497 -- Comes_From_Generic --
12498 ------------------------
12500 function Comes_From_Generic (Typ : Entity_Id) return Boolean is
12502 if Is_Generic_Type (Typ) then
12505 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
12508 elsif Is_Private_Type (Typ)
12509 and then Present (Full_View (Typ))
12510 and then Is_Generic_Type (Root_Type (Full_View (Typ)))
12514 elsif Is_Generic_Actual_Type (Typ) then
12520 end Comes_From_Generic;
12524 Def : constant Node_Id := Type_Definition (N);
12525 Iface_Def : Node_Id;
12526 Indic : constant Node_Id := Subtype_Indication (Def);
12527 Extension : constant Node_Id := Record_Extension_Part (Def);
12528 Parent_Node : Node_Id;
12529 Parent_Scope : Entity_Id;
12532 -- Start of processing for Derived_Type_Declaration
12535 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
12537 -- Ada 2005 (AI-251): In case of interface derivation check that the
12538 -- parent is also an interface.
12540 if Interface_Present (Def) then
12541 if not Is_Interface (Parent_Type) then
12542 Diagnose_Interface (Indic, Parent_Type);
12545 Parent_Node := Parent (Base_Type (Parent_Type));
12546 Iface_Def := Type_Definition (Parent_Node);
12548 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
12549 -- other limited interfaces.
12551 if Limited_Present (Def) then
12552 if Limited_Present (Iface_Def) then
12555 elsif Protected_Present (Iface_Def) then
12557 ("(Ada 2005) limited interface cannot "
12558 & "inherit from protected interface", Indic);
12560 elsif Synchronized_Present (Iface_Def) then
12562 ("(Ada 2005) limited interface cannot "
12563 & "inherit from synchronized interface", Indic);
12565 elsif Task_Present (Iface_Def) then
12567 ("(Ada 2005) limited interface cannot "
12568 & "inherit from task interface", Indic);
12572 ("(Ada 2005) limited interface cannot "
12573 & "inherit from non-limited interface", Indic);
12576 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
12577 -- from non-limited or limited interfaces.
12579 elsif not Protected_Present (Def)
12580 and then not Synchronized_Present (Def)
12581 and then not Task_Present (Def)
12583 if Limited_Present (Iface_Def) then
12586 elsif Protected_Present (Iface_Def) then
12588 ("(Ada 2005) non-limited interface cannot "
12589 & "inherit from protected interface", Indic);
12591 elsif Synchronized_Present (Iface_Def) then
12593 ("(Ada 2005) non-limited interface cannot "
12594 & "inherit from synchronized interface", Indic);
12596 elsif Task_Present (Iface_Def) then
12598 ("(Ada 2005) non-limited interface cannot "
12599 & "inherit from task interface", Indic);
12608 if Is_Tagged_Type (Parent_Type)
12609 and then Is_Concurrent_Type (Parent_Type)
12610 and then not Is_Interface (Parent_Type)
12613 ("parent type of a record extension cannot be "
12614 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
12615 Set_Etype (T, Any_Type);
12619 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
12622 if Is_Tagged_Type (Parent_Type)
12623 and then Is_Non_Empty_List (Interface_List (Def))
12630 Intf := First (Interface_List (Def));
12631 while Present (Intf) loop
12632 T := Find_Type_Of_Subtype_Indic (Intf);
12634 if not Is_Interface (T) then
12635 Diagnose_Interface (Intf, T);
12637 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
12638 -- a limited type from having a nonlimited progenitor.
12640 elsif (Limited_Present (Def)
12641 or else (not Is_Interface (Parent_Type)
12642 and then Is_Limited_Type (Parent_Type)))
12643 and then not Is_Limited_Interface (T)
12646 ("progenitor interface& of limited type must be limited",
12655 if Parent_Type = Any_Type
12656 or else Etype (Parent_Type) = Any_Type
12657 or else (Is_Class_Wide_Type (Parent_Type)
12658 and then Etype (Parent_Type) = T)
12660 -- If Parent_Type is undefined or illegal, make new type into a
12661 -- subtype of Any_Type, and set a few attributes to prevent cascaded
12662 -- errors. If this is a self-definition, emit error now.
12665 or else T = Etype (Parent_Type)
12667 Error_Msg_N ("type cannot be used in its own definition", Indic);
12670 Set_Ekind (T, Ekind (Parent_Type));
12671 Set_Etype (T, Any_Type);
12672 Set_Scalar_Range (T, Scalar_Range (Any_Type));
12674 if Is_Tagged_Type (T) then
12675 Set_Primitive_Operations (T, New_Elmt_List);
12681 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
12682 -- an interface is special because the list of interfaces in the full
12683 -- view can be given in any order. For example:
12685 -- type A is interface;
12686 -- type B is interface and A;
12687 -- type D is new B with private;
12689 -- type D is new A and B with null record; -- 1 --
12691 -- In this case we perform the following transformation of -1-:
12693 -- type D is new B and A with null record;
12695 -- If the parent of the full-view covers the parent of the partial-view
12696 -- we have two possible cases:
12698 -- 1) They have the same parent
12699 -- 2) The parent of the full-view implements some further interfaces
12701 -- In both cases we do not need to perform the transformation. In the
12702 -- first case the source program is correct and the transformation is
12703 -- not needed; in the second case the source program does not fulfill
12704 -- the no-hidden interfaces rule (AI-396) and the error will be reported
12707 -- This transformation not only simplifies the rest of the analysis of
12708 -- this type declaration but also simplifies the correct generation of
12709 -- the object layout to the expander.
12711 if In_Private_Part (Current_Scope)
12712 and then Is_Interface (Parent_Type)
12716 Partial_View : Entity_Id;
12717 Partial_View_Parent : Entity_Id;
12718 New_Iface : Node_Id;
12721 -- Look for the associated private type declaration
12723 Partial_View := First_Entity (Current_Scope);
12725 exit when No (Partial_View)
12726 or else (Has_Private_Declaration (Partial_View)
12727 and then Full_View (Partial_View) = T);
12729 Next_Entity (Partial_View);
12732 -- If the partial view was not found then the source code has
12733 -- errors and the transformation is not needed.
12735 if Present (Partial_View) then
12736 Partial_View_Parent := Etype (Partial_View);
12738 -- If the parent of the full-view covers the parent of the
12739 -- partial-view we have nothing else to do.
12741 if Interface_Present_In_Ancestor
12742 (Parent_Type, Partial_View_Parent)
12746 -- Traverse the list of interfaces of the full-view to look
12747 -- for the parent of the partial-view and perform the tree
12751 Iface := First (Interface_List (Def));
12752 while Present (Iface) loop
12753 if Etype (Iface) = Etype (Partial_View) then
12754 Rewrite (Subtype_Indication (Def),
12755 New_Copy (Subtype_Indication
12756 (Parent (Partial_View))));
12758 New_Iface := Make_Identifier (Sloc (N),
12759 Chars (Parent_Type));
12760 Append (New_Iface, Interface_List (Def));
12762 -- Analyze the transformed code
12764 Derived_Type_Declaration (T, N, Is_Completion);
12775 -- Only composite types other than array types are allowed to have
12778 if Present (Discriminant_Specifications (N))
12779 and then (Is_Elementary_Type (Parent_Type)
12780 or else Is_Array_Type (Parent_Type))
12781 and then not Error_Posted (N)
12784 ("elementary or array type cannot have discriminants",
12785 Defining_Identifier (First (Discriminant_Specifications (N))));
12786 Set_Has_Discriminants (T, False);
12789 -- In Ada 83, a derived type defined in a package specification cannot
12790 -- be used for further derivation until the end of its visible part.
12791 -- Note that derivation in the private part of the package is allowed.
12793 if Ada_Version = Ada_83
12794 and then Is_Derived_Type (Parent_Type)
12795 and then In_Visible_Part (Scope (Parent_Type))
12797 if Ada_Version = Ada_83 and then Comes_From_Source (Indic) then
12799 ("(Ada 83): premature use of type for derivation", Indic);
12803 -- Check for early use of incomplete or private type
12805 if Ekind (Parent_Type) = E_Void
12806 or else Ekind (Parent_Type) = E_Incomplete_Type
12808 Error_Msg_N ("premature derivation of incomplete type", Indic);
12811 elsif (Is_Incomplete_Or_Private_Type (Parent_Type)
12812 and then not Comes_From_Generic (Parent_Type))
12813 or else Has_Private_Component (Parent_Type)
12815 -- The ancestor type of a formal type can be incomplete, in which
12816 -- case only the operations of the partial view are available in
12817 -- the generic. Subsequent checks may be required when the full
12818 -- view is analyzed, to verify that derivation from a tagged type
12819 -- has an extension.
12821 if Nkind (Original_Node (N)) = N_Formal_Type_Declaration then
12824 elsif No (Underlying_Type (Parent_Type))
12825 or else Has_Private_Component (Parent_Type)
12828 ("premature derivation of derived or private type", Indic);
12830 -- Flag the type itself as being in error, this prevents some
12831 -- nasty problems with subsequent uses of the malformed type.
12833 Set_Error_Posted (T);
12835 -- Check that within the immediate scope of an untagged partial
12836 -- view it's illegal to derive from the partial view if the
12837 -- full view is tagged. (7.3(7))
12839 -- We verify that the Parent_Type is a partial view by checking
12840 -- that it is not a Full_Type_Declaration (i.e. a private type or
12841 -- private extension declaration), to distinguish a partial view
12842 -- from a derivation from a private type which also appears as
12845 elsif Present (Full_View (Parent_Type))
12846 and then Nkind (Parent (Parent_Type)) /= N_Full_Type_Declaration
12847 and then not Is_Tagged_Type (Parent_Type)
12848 and then Is_Tagged_Type (Full_View (Parent_Type))
12850 Parent_Scope := Scope (T);
12851 while Present (Parent_Scope)
12852 and then Parent_Scope /= Standard_Standard
12854 if Parent_Scope = Scope (Parent_Type) then
12856 ("premature derivation from type with tagged full view",
12860 Parent_Scope := Scope (Parent_Scope);
12865 -- Check that form of derivation is appropriate
12867 Taggd := Is_Tagged_Type (Parent_Type);
12869 -- Perhaps the parent type should be changed to the class-wide type's
12870 -- specific type in this case to prevent cascading errors ???
12872 if Present (Extension) and then Is_Class_Wide_Type (Parent_Type) then
12873 Error_Msg_N ("parent type must not be a class-wide type", Indic);
12877 if Present (Extension) and then not Taggd then
12879 ("type derived from untagged type cannot have extension", Indic);
12881 elsif No (Extension) and then Taggd then
12883 -- If this declaration is within a private part (or body) of a
12884 -- generic instantiation then the derivation is allowed (the parent
12885 -- type can only appear tagged in this case if it's a generic actual
12886 -- type, since it would otherwise have been rejected in the analysis
12887 -- of the generic template).
12889 if not Is_Generic_Actual_Type (Parent_Type)
12890 or else In_Visible_Part (Scope (Parent_Type))
12893 ("type derived from tagged type must have extension", Indic);
12897 -- AI-443: Synchronized formal derived types require a private
12898 -- extension. There is no point in checking the ancestor type or
12899 -- the progenitors since the construct is wrong to begin with.
12901 if Ada_Version >= Ada_05
12902 and then Is_Generic_Type (T)
12903 and then Present (Original_Node (N))
12906 Decl : constant Node_Id := Original_Node (N);
12909 if Nkind (Decl) = N_Formal_Type_Declaration
12910 and then Nkind (Formal_Type_Definition (Decl)) =
12911 N_Formal_Derived_Type_Definition
12912 and then Synchronized_Present (Formal_Type_Definition (Decl))
12913 and then No (Extension)
12915 -- Avoid emitting a duplicate error message
12917 and then not Error_Posted (Indic)
12920 ("synchronized derived type must have extension", N);
12925 if Null_Exclusion_Present (Def)
12926 and then not Is_Access_Type (Parent_Type)
12928 Error_Msg_N ("null exclusion can only apply to an access type", N);
12931 Build_Derived_Type (N, Parent_Type, T, Is_Completion);
12933 -- AI-419: The parent type of an explicitly limited derived type must
12934 -- be a limited type or a limited interface.
12936 if Limited_Present (Def) then
12937 Set_Is_Limited_Record (T);
12939 if Is_Interface (T) then
12940 Set_Is_Limited_Interface (T);
12943 if not Is_Limited_Type (Parent_Type)
12945 (not Is_Interface (Parent_Type)
12946 or else not Is_Limited_Interface (Parent_Type))
12948 Error_Msg_NE ("parent type& of limited type must be limited",
12952 end Derived_Type_Declaration;
12954 ------------------------
12955 -- Diagnose_Interface --
12956 ------------------------
12958 procedure Diagnose_Interface (N : Node_Id; E : Entity_Id) is
12960 if not Is_Interface (E)
12961 and then E /= Any_Type
12963 Error_Msg_NE ("(Ada 2005) & must be an interface", N, E);
12965 end Diagnose_Interface;
12967 ----------------------------------
12968 -- Enumeration_Type_Declaration --
12969 ----------------------------------
12971 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id) is
12978 -- Create identifier node representing lower bound
12980 B_Node := New_Node (N_Identifier, Sloc (Def));
12981 L := First (Literals (Def));
12982 Set_Chars (B_Node, Chars (L));
12983 Set_Entity (B_Node, L);
12984 Set_Etype (B_Node, T);
12985 Set_Is_Static_Expression (B_Node, True);
12987 R_Node := New_Node (N_Range, Sloc (Def));
12988 Set_Low_Bound (R_Node, B_Node);
12990 Set_Ekind (T, E_Enumeration_Type);
12991 Set_First_Literal (T, L);
12993 Set_Is_Constrained (T);
12997 -- Loop through literals of enumeration type setting pos and rep values
12998 -- except that if the Ekind is already set, then it means that the
12999 -- literal was already constructed (case of a derived type declaration
13000 -- and we should not disturb the Pos and Rep values.
13002 while Present (L) loop
13003 if Ekind (L) /= E_Enumeration_Literal then
13004 Set_Ekind (L, E_Enumeration_Literal);
13005 Set_Enumeration_Pos (L, Ev);
13006 Set_Enumeration_Rep (L, Ev);
13007 Set_Is_Known_Valid (L, True);
13011 New_Overloaded_Entity (L);
13012 Generate_Definition (L);
13013 Set_Convention (L, Convention_Intrinsic);
13015 if Nkind (L) = N_Defining_Character_Literal then
13016 Set_Is_Character_Type (T, True);
13023 -- Now create a node representing upper bound
13025 B_Node := New_Node (N_Identifier, Sloc (Def));
13026 Set_Chars (B_Node, Chars (Last (Literals (Def))));
13027 Set_Entity (B_Node, Last (Literals (Def)));
13028 Set_Etype (B_Node, T);
13029 Set_Is_Static_Expression (B_Node, True);
13031 Set_High_Bound (R_Node, B_Node);
13033 -- Initialize various fields of the type. Some of this information
13034 -- may be overwritten later through rep.clauses.
13036 Set_Scalar_Range (T, R_Node);
13037 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
13038 Set_Enum_Esize (T);
13039 Set_Enum_Pos_To_Rep (T, Empty);
13041 -- Set Discard_Names if configuration pragma set, or if there is
13042 -- a parameterless pragma in the current declarative region
13044 if Global_Discard_Names
13045 or else Discard_Names (Scope (T))
13047 Set_Discard_Names (T);
13050 -- Process end label if there is one
13052 if Present (Def) then
13053 Process_End_Label (Def, 'e', T);
13055 end Enumeration_Type_Declaration;
13057 ---------------------------------
13058 -- Expand_To_Stored_Constraint --
13059 ---------------------------------
13061 function Expand_To_Stored_Constraint
13063 Constraint : Elist_Id) return Elist_Id
13065 Explicitly_Discriminated_Type : Entity_Id;
13066 Expansion : Elist_Id;
13067 Discriminant : Entity_Id;
13069 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id;
13070 -- Find the nearest type that actually specifies discriminants
13072 ---------------------------------
13073 -- Type_With_Explicit_Discrims --
13074 ---------------------------------
13076 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id is
13077 Typ : constant E := Base_Type (Id);
13080 if Ekind (Typ) in Incomplete_Or_Private_Kind then
13081 if Present (Full_View (Typ)) then
13082 return Type_With_Explicit_Discrims (Full_View (Typ));
13086 if Has_Discriminants (Typ) then
13091 if Etype (Typ) = Typ then
13093 elsif Has_Discriminants (Typ) then
13096 return Type_With_Explicit_Discrims (Etype (Typ));
13099 end Type_With_Explicit_Discrims;
13101 -- Start of processing for Expand_To_Stored_Constraint
13105 or else Is_Empty_Elmt_List (Constraint)
13110 Explicitly_Discriminated_Type := Type_With_Explicit_Discrims (Typ);
13112 if No (Explicitly_Discriminated_Type) then
13116 Expansion := New_Elmt_List;
13119 First_Stored_Discriminant (Explicitly_Discriminated_Type);
13120 while Present (Discriminant) loop
13122 Get_Discriminant_Value (
13123 Discriminant, Explicitly_Discriminated_Type, Constraint),
13125 Next_Stored_Discriminant (Discriminant);
13129 end Expand_To_Stored_Constraint;
13131 ---------------------------
13132 -- Find_Hidden_Interface --
13133 ---------------------------
13135 function Find_Hidden_Interface
13137 Dest : Elist_Id) return Entity_Id
13140 Iface_Elmt : Elmt_Id;
13143 if Present (Src) and then Present (Dest) then
13144 Iface_Elmt := First_Elmt (Src);
13145 while Present (Iface_Elmt) loop
13146 Iface := Node (Iface_Elmt);
13148 if Is_Interface (Iface)
13149 and then not Contain_Interface (Iface, Dest)
13154 Next_Elmt (Iface_Elmt);
13159 end Find_Hidden_Interface;
13161 --------------------
13162 -- Find_Type_Name --
13163 --------------------
13165 function Find_Type_Name (N : Node_Id) return Entity_Id is
13166 Id : constant Entity_Id := Defining_Identifier (N);
13168 New_Id : Entity_Id;
13169 Prev_Par : Node_Id;
13171 procedure Tag_Mismatch;
13172 -- Diagnose a tagged partial view whose full view is untagged.
13173 -- We post the message on the full view, with a reference to
13174 -- the previous partial view. The partial view can be private
13175 -- or incomplete, and these are handled in a different manner,
13176 -- so we determine the position of the error message from the
13177 -- respective slocs of both.
13183 procedure Tag_Mismatch is
13185 if Sloc (Prev) < Sloc (Id) then
13187 ("full declaration of } must be a tagged type ", Id, Prev);
13190 ("full declaration of } must be a tagged type ", Prev, Id);
13194 -- Start processing for Find_Type_Name
13197 -- Find incomplete declaration, if one was given
13199 Prev := Current_Entity_In_Scope (Id);
13201 if Present (Prev) then
13203 -- Previous declaration exists. Error if not incomplete/private case
13204 -- except if previous declaration is implicit, etc. Enter_Name will
13205 -- emit error if appropriate.
13207 Prev_Par := Parent (Prev);
13209 if not Is_Incomplete_Or_Private_Type (Prev) then
13213 elsif not Nkind_In (N, N_Full_Type_Declaration,
13214 N_Task_Type_Declaration,
13215 N_Protected_Type_Declaration)
13217 -- Completion must be a full type declarations (RM 7.3(4))
13219 Error_Msg_Sloc := Sloc (Prev);
13220 Error_Msg_NE ("invalid completion of }", Id, Prev);
13222 -- Set scope of Id to avoid cascaded errors. Entity is never
13223 -- examined again, except when saving globals in generics.
13225 Set_Scope (Id, Current_Scope);
13228 -- If this is a repeated incomplete declaration, no further
13229 -- checks are possible.
13231 if Nkind (N) = N_Incomplete_Type_Declaration then
13235 -- Case of full declaration of incomplete type
13237 elsif Ekind (Prev) = E_Incomplete_Type then
13239 -- Indicate that the incomplete declaration has a matching full
13240 -- declaration. The defining occurrence of the incomplete
13241 -- declaration remains the visible one, and the procedure
13242 -- Get_Full_View dereferences it whenever the type is used.
13244 if Present (Full_View (Prev)) then
13245 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
13248 Set_Full_View (Prev, Id);
13249 Append_Entity (Id, Current_Scope);
13250 Set_Is_Public (Id, Is_Public (Prev));
13251 Set_Is_Internal (Id);
13254 -- Case of full declaration of private type
13257 if Nkind (Parent (Prev)) /= N_Private_Extension_Declaration then
13258 if Etype (Prev) /= Prev then
13260 -- Prev is a private subtype or a derived type, and needs
13263 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
13266 elsif Ekind (Prev) = E_Private_Type
13267 and then Nkind_In (N, N_Task_Type_Declaration,
13268 N_Protected_Type_Declaration)
13271 ("completion of nonlimited type cannot be limited", N);
13273 elsif Ekind (Prev) = E_Record_Type_With_Private
13274 and then Nkind_In (N, N_Task_Type_Declaration,
13275 N_Protected_Type_Declaration)
13277 if not Is_Limited_Record (Prev) then
13279 ("completion of nonlimited type cannot be limited", N);
13281 elsif No (Interface_List (N)) then
13283 ("completion of tagged private type must be tagged",
13288 -- Ada 2005 (AI-251): Private extension declaration of a task
13289 -- type or a protected type. This case arises when covering
13290 -- interface types.
13292 elsif Nkind_In (N, N_Task_Type_Declaration,
13293 N_Protected_Type_Declaration)
13297 elsif Nkind (N) /= N_Full_Type_Declaration
13298 or else Nkind (Type_Definition (N)) /= N_Derived_Type_Definition
13301 ("full view of private extension must be an extension", N);
13303 elsif not (Abstract_Present (Parent (Prev)))
13304 and then Abstract_Present (Type_Definition (N))
13307 ("full view of non-abstract extension cannot be abstract", N);
13310 if not In_Private_Part (Current_Scope) then
13312 ("declaration of full view must appear in private part", N);
13315 Copy_And_Swap (Prev, Id);
13316 Set_Has_Private_Declaration (Prev);
13317 Set_Has_Private_Declaration (Id);
13319 -- If no error, propagate freeze_node from private to full view.
13320 -- It may have been generated for an early operational item.
13322 if Present (Freeze_Node (Id))
13323 and then Serious_Errors_Detected = 0
13324 and then No (Full_View (Id))
13326 Set_Freeze_Node (Prev, Freeze_Node (Id));
13327 Set_Freeze_Node (Id, Empty);
13328 Set_First_Rep_Item (Prev, First_Rep_Item (Id));
13331 Set_Full_View (Id, Prev);
13335 -- Verify that full declaration conforms to partial one
13337 if Is_Incomplete_Or_Private_Type (Prev)
13338 and then Present (Discriminant_Specifications (Prev_Par))
13340 if Present (Discriminant_Specifications (N)) then
13341 if Ekind (Prev) = E_Incomplete_Type then
13342 Check_Discriminant_Conformance (N, Prev, Prev);
13344 Check_Discriminant_Conformance (N, Prev, Id);
13349 ("missing discriminants in full type declaration", N);
13351 -- To avoid cascaded errors on subsequent use, share the
13352 -- discriminants of the partial view.
13354 Set_Discriminant_Specifications (N,
13355 Discriminant_Specifications (Prev_Par));
13359 -- A prior untagged partial view can have an associated class-wide
13360 -- type due to use of the class attribute, and in this case the full
13361 -- type must also be tagged. This Ada 95 usage is deprecated in favor
13362 -- of incomplete tagged declarations, but we check for it.
13365 and then (Is_Tagged_Type (Prev)
13366 or else Present (Class_Wide_Type (Prev)))
13368 -- The full declaration is either a tagged type (including
13369 -- a synchronized type that implements interfaces) or a
13370 -- type extension, otherwise this is an error.
13372 if Nkind_In (N, N_Task_Type_Declaration,
13373 N_Protected_Type_Declaration)
13375 if No (Interface_List (N))
13376 and then not Error_Posted (N)
13381 elsif Nkind (Type_Definition (N)) = N_Record_Definition then
13383 -- Indicate that the previous declaration (tagged incomplete
13384 -- or private declaration) requires the same on the full one.
13386 if not Tagged_Present (Type_Definition (N)) then
13388 Set_Is_Tagged_Type (Id);
13389 Set_Primitive_Operations (Id, New_Elmt_List);
13392 elsif Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
13393 if No (Record_Extension_Part (Type_Definition (N))) then
13395 "full declaration of } must be a record extension",
13397 Set_Is_Tagged_Type (Id);
13398 Set_Primitive_Operations (Id, New_Elmt_List);
13409 -- New type declaration
13414 end Find_Type_Name;
13416 -------------------------
13417 -- Find_Type_Of_Object --
13418 -------------------------
13420 function Find_Type_Of_Object
13421 (Obj_Def : Node_Id;
13422 Related_Nod : Node_Id) return Entity_Id
13424 Def_Kind : constant Node_Kind := Nkind (Obj_Def);
13425 P : Node_Id := Parent (Obj_Def);
13430 -- If the parent is a component_definition node we climb to the
13431 -- component_declaration node
13433 if Nkind (P) = N_Component_Definition then
13437 -- Case of an anonymous array subtype
13439 if Nkind_In (Def_Kind, N_Constrained_Array_Definition,
13440 N_Unconstrained_Array_Definition)
13443 Array_Type_Declaration (T, Obj_Def);
13445 -- Create an explicit subtype whenever possible
13447 elsif Nkind (P) /= N_Component_Declaration
13448 and then Def_Kind = N_Subtype_Indication
13450 -- Base name of subtype on object name, which will be unique in
13451 -- the current scope.
13453 -- If this is a duplicate declaration, return base type, to avoid
13454 -- generating duplicate anonymous types.
13456 if Error_Posted (P) then
13457 Analyze (Subtype_Mark (Obj_Def));
13458 return Entity (Subtype_Mark (Obj_Def));
13463 (Chars (Defining_Identifier (Related_Nod)), 'S', 0, 'T');
13465 T := Make_Defining_Identifier (Sloc (P), Nam);
13467 Insert_Action (Obj_Def,
13468 Make_Subtype_Declaration (Sloc (P),
13469 Defining_Identifier => T,
13470 Subtype_Indication => Relocate_Node (Obj_Def)));
13472 -- This subtype may need freezing, and this will not be done
13473 -- automatically if the object declaration is not in declarative
13474 -- part. Since this is an object declaration, the type cannot always
13475 -- be frozen here. Deferred constants do not freeze their type
13476 -- (which often enough will be private).
13478 if Nkind (P) = N_Object_Declaration
13479 and then Constant_Present (P)
13480 and then No (Expression (P))
13484 Insert_Actions (Obj_Def, Freeze_Entity (T, Sloc (P)));
13487 -- Ada 2005 AI-406: the object definition in an object declaration
13488 -- can be an access definition.
13490 elsif Def_Kind = N_Access_Definition then
13491 T := Access_Definition (Related_Nod, Obj_Def);
13492 Set_Is_Local_Anonymous_Access (T);
13494 -- Otherwise, the object definition is just a subtype_mark
13497 T := Process_Subtype (Obj_Def, Related_Nod);
13501 end Find_Type_Of_Object;
13503 --------------------------------
13504 -- Find_Type_Of_Subtype_Indic --
13505 --------------------------------
13507 function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id is
13511 -- Case of subtype mark with a constraint
13513 if Nkind (S) = N_Subtype_Indication then
13514 Find_Type (Subtype_Mark (S));
13515 Typ := Entity (Subtype_Mark (S));
13518 Is_Valid_Constraint_Kind (Ekind (Typ), Nkind (Constraint (S)))
13521 ("incorrect constraint for this kind of type", Constraint (S));
13522 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
13525 -- Otherwise we have a subtype mark without a constraint
13527 elsif Error_Posted (S) then
13528 Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S)));
13536 -- Check No_Wide_Characters restriction
13538 if Typ = Standard_Wide_Character
13539 or else Typ = Standard_Wide_Wide_Character
13540 or else Typ = Standard_Wide_String
13541 or else Typ = Standard_Wide_Wide_String
13543 Check_Restriction (No_Wide_Characters, S);
13547 end Find_Type_Of_Subtype_Indic;
13549 -------------------------------------
13550 -- Floating_Point_Type_Declaration --
13551 -------------------------------------
13553 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is
13554 Digs : constant Node_Id := Digits_Expression (Def);
13556 Base_Typ : Entity_Id;
13557 Implicit_Base : Entity_Id;
13560 function Can_Derive_From (E : Entity_Id) return Boolean;
13561 -- Find if given digits value allows derivation from specified type
13563 ---------------------
13564 -- Can_Derive_From --
13565 ---------------------
13567 function Can_Derive_From (E : Entity_Id) return Boolean is
13568 Spec : constant Entity_Id := Real_Range_Specification (Def);
13571 if Digs_Val > Digits_Value (E) then
13575 if Present (Spec) then
13576 if Expr_Value_R (Type_Low_Bound (E)) >
13577 Expr_Value_R (Low_Bound (Spec))
13582 if Expr_Value_R (Type_High_Bound (E)) <
13583 Expr_Value_R (High_Bound (Spec))
13590 end Can_Derive_From;
13592 -- Start of processing for Floating_Point_Type_Declaration
13595 Check_Restriction (No_Floating_Point, Def);
13597 -- Create an implicit base type
13600 Create_Itype (E_Floating_Point_Type, Parent (Def), T, 'B');
13602 -- Analyze and verify digits value
13604 Analyze_And_Resolve (Digs, Any_Integer);
13605 Check_Digits_Expression (Digs);
13606 Digs_Val := Expr_Value (Digs);
13608 -- Process possible range spec and find correct type to derive from
13610 Process_Real_Range_Specification (Def);
13612 if Can_Derive_From (Standard_Short_Float) then
13613 Base_Typ := Standard_Short_Float;
13614 elsif Can_Derive_From (Standard_Float) then
13615 Base_Typ := Standard_Float;
13616 elsif Can_Derive_From (Standard_Long_Float) then
13617 Base_Typ := Standard_Long_Float;
13618 elsif Can_Derive_From (Standard_Long_Long_Float) then
13619 Base_Typ := Standard_Long_Long_Float;
13621 -- If we can't derive from any existing type, use long_long_float
13622 -- and give appropriate message explaining the problem.
13625 Base_Typ := Standard_Long_Long_Float;
13627 if Digs_Val >= Digits_Value (Standard_Long_Long_Float) then
13628 Error_Msg_Uint_1 := Digits_Value (Standard_Long_Long_Float);
13629 Error_Msg_N ("digits value out of range, maximum is ^", Digs);
13633 ("range too large for any predefined type",
13634 Real_Range_Specification (Def));
13638 -- If there are bounds given in the declaration use them as the bounds
13639 -- of the type, otherwise use the bounds of the predefined base type
13640 -- that was chosen based on the Digits value.
13642 if Present (Real_Range_Specification (Def)) then
13643 Set_Scalar_Range (T, Real_Range_Specification (Def));
13644 Set_Is_Constrained (T);
13646 -- The bounds of this range must be converted to machine numbers
13647 -- in accordance with RM 4.9(38).
13649 Bound := Type_Low_Bound (T);
13651 if Nkind (Bound) = N_Real_Literal then
13653 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13654 Set_Is_Machine_Number (Bound);
13657 Bound := Type_High_Bound (T);
13659 if Nkind (Bound) = N_Real_Literal then
13661 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13662 Set_Is_Machine_Number (Bound);
13666 Set_Scalar_Range (T, Scalar_Range (Base_Typ));
13669 -- Complete definition of implicit base and declared first subtype
13671 Set_Etype (Implicit_Base, Base_Typ);
13673 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
13674 Set_Size_Info (Implicit_Base, (Base_Typ));
13675 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
13676 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
13677 Set_Digits_Value (Implicit_Base, Digits_Value (Base_Typ));
13678 Set_Vax_Float (Implicit_Base, Vax_Float (Base_Typ));
13680 Set_Ekind (T, E_Floating_Point_Subtype);
13681 Set_Etype (T, Implicit_Base);
13683 Set_Size_Info (T, (Implicit_Base));
13684 Set_RM_Size (T, RM_Size (Implicit_Base));
13685 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
13686 Set_Digits_Value (T, Digs_Val);
13687 end Floating_Point_Type_Declaration;
13689 ----------------------------
13690 -- Get_Discriminant_Value --
13691 ----------------------------
13693 -- This is the situation:
13695 -- There is a non-derived type
13697 -- type T0 (Dx, Dy, Dz...)
13699 -- There are zero or more levels of derivation, with each derivation
13700 -- either purely inheriting the discriminants, or defining its own.
13702 -- type Ti is new Ti-1
13704 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
13706 -- subtype Ti is ...
13708 -- The subtype issue is avoided by the use of Original_Record_Component,
13709 -- and the fact that derived subtypes also derive the constraints.
13711 -- This chain leads back from
13713 -- Typ_For_Constraint
13715 -- Typ_For_Constraint has discriminants, and the value for each
13716 -- discriminant is given by its corresponding Elmt of Constraints.
13718 -- Discriminant is some discriminant in this hierarchy
13720 -- We need to return its value
13722 -- We do this by recursively searching each level, and looking for
13723 -- Discriminant. Once we get to the bottom, we start backing up
13724 -- returning the value for it which may in turn be a discriminant
13725 -- further up, so on the backup we continue the substitution.
13727 function Get_Discriminant_Value
13728 (Discriminant : Entity_Id;
13729 Typ_For_Constraint : Entity_Id;
13730 Constraint : Elist_Id) return Node_Id
13732 function Search_Derivation_Levels
13734 Discrim_Values : Elist_Id;
13735 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id;
13736 -- This is the routine that performs the recursive search of levels
13737 -- as described above.
13739 ------------------------------
13740 -- Search_Derivation_Levels --
13741 ------------------------------
13743 function Search_Derivation_Levels
13745 Discrim_Values : Elist_Id;
13746 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id
13750 Result : Node_Or_Entity_Id;
13751 Result_Entity : Node_Id;
13754 -- If inappropriate type, return Error, this happens only in
13755 -- cascaded error situations, and we want to avoid a blow up.
13757 if not Is_Composite_Type (Ti) or else Is_Array_Type (Ti) then
13761 -- Look deeper if possible. Use Stored_Constraints only for
13762 -- untagged types. For tagged types use the given constraint.
13763 -- This asymmetry needs explanation???
13765 if not Stored_Discrim_Values
13766 and then Present (Stored_Constraint (Ti))
13767 and then not Is_Tagged_Type (Ti)
13770 Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True);
13773 Td : constant Entity_Id := Etype (Ti);
13777 Result := Discriminant;
13780 if Present (Stored_Constraint (Ti)) then
13782 Search_Derivation_Levels
13783 (Td, Stored_Constraint (Ti), True);
13786 Search_Derivation_Levels
13787 (Td, Discrim_Values, Stored_Discrim_Values);
13793 -- Extra underlying places to search, if not found above. For
13794 -- concurrent types, the relevant discriminant appears in the
13795 -- corresponding record. For a type derived from a private type
13796 -- without discriminant, the full view inherits the discriminants
13797 -- of the full view of the parent.
13799 if Result = Discriminant then
13800 if Is_Concurrent_Type (Ti)
13801 and then Present (Corresponding_Record_Type (Ti))
13804 Search_Derivation_Levels (
13805 Corresponding_Record_Type (Ti),
13807 Stored_Discrim_Values);
13809 elsif Is_Private_Type (Ti)
13810 and then not Has_Discriminants (Ti)
13811 and then Present (Full_View (Ti))
13812 and then Etype (Full_View (Ti)) /= Ti
13815 Search_Derivation_Levels (
13818 Stored_Discrim_Values);
13822 -- If Result is not a (reference to a) discriminant, return it,
13823 -- otherwise set Result_Entity to the discriminant.
13825 if Nkind (Result) = N_Defining_Identifier then
13826 pragma Assert (Result = Discriminant);
13827 Result_Entity := Result;
13830 if not Denotes_Discriminant (Result) then
13834 Result_Entity := Entity (Result);
13837 -- See if this level of derivation actually has discriminants
13838 -- because tagged derivations can add them, hence the lower
13839 -- levels need not have any.
13841 if not Has_Discriminants (Ti) then
13845 -- Scan Ti's discriminants for Result_Entity,
13846 -- and return its corresponding value, if any.
13848 Result_Entity := Original_Record_Component (Result_Entity);
13850 Assoc := First_Elmt (Discrim_Values);
13852 if Stored_Discrim_Values then
13853 Disc := First_Stored_Discriminant (Ti);
13855 Disc := First_Discriminant (Ti);
13858 while Present (Disc) loop
13859 pragma Assert (Present (Assoc));
13861 if Original_Record_Component (Disc) = Result_Entity then
13862 return Node (Assoc);
13867 if Stored_Discrim_Values then
13868 Next_Stored_Discriminant (Disc);
13870 Next_Discriminant (Disc);
13874 -- Could not find it
13877 end Search_Derivation_Levels;
13881 Result : Node_Or_Entity_Id;
13883 -- Start of processing for Get_Discriminant_Value
13886 -- ??? This routine is a gigantic mess and will be deleted. For the
13887 -- time being just test for the trivial case before calling recurse.
13889 if Base_Type (Scope (Discriminant)) = Base_Type (Typ_For_Constraint) then
13895 D := First_Discriminant (Typ_For_Constraint);
13896 E := First_Elmt (Constraint);
13897 while Present (D) loop
13898 if Chars (D) = Chars (Discriminant) then
13902 Next_Discriminant (D);
13908 Result := Search_Derivation_Levels
13909 (Typ_For_Constraint, Constraint, False);
13911 -- ??? hack to disappear when this routine is gone
13913 if Nkind (Result) = N_Defining_Identifier then
13919 D := First_Discriminant (Typ_For_Constraint);
13920 E := First_Elmt (Constraint);
13921 while Present (D) loop
13922 if Corresponding_Discriminant (D) = Discriminant then
13926 Next_Discriminant (D);
13932 pragma Assert (Nkind (Result) /= N_Defining_Identifier);
13934 end Get_Discriminant_Value;
13936 --------------------------
13937 -- Has_Range_Constraint --
13938 --------------------------
13940 function Has_Range_Constraint (N : Node_Id) return Boolean is
13941 C : constant Node_Id := Constraint (N);
13944 if Nkind (C) = N_Range_Constraint then
13947 elsif Nkind (C) = N_Digits_Constraint then
13949 Is_Decimal_Fixed_Point_Type (Entity (Subtype_Mark (N)))
13951 Present (Range_Constraint (C));
13953 elsif Nkind (C) = N_Delta_Constraint then
13954 return Present (Range_Constraint (C));
13959 end Has_Range_Constraint;
13961 ------------------------
13962 -- Inherit_Components --
13963 ------------------------
13965 function Inherit_Components
13967 Parent_Base : Entity_Id;
13968 Derived_Base : Entity_Id;
13969 Is_Tagged : Boolean;
13970 Inherit_Discr : Boolean;
13971 Discs : Elist_Id) return Elist_Id
13973 Assoc_List : constant Elist_Id := New_Elmt_List;
13975 procedure Inherit_Component
13976 (Old_C : Entity_Id;
13977 Plain_Discrim : Boolean := False;
13978 Stored_Discrim : Boolean := False);
13979 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
13980 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
13981 -- True, Old_C is a stored discriminant. If they are both false then
13982 -- Old_C is a regular component.
13984 -----------------------
13985 -- Inherit_Component --
13986 -----------------------
13988 procedure Inherit_Component
13989 (Old_C : Entity_Id;
13990 Plain_Discrim : Boolean := False;
13991 Stored_Discrim : Boolean := False)
13993 New_C : constant Entity_Id := New_Copy (Old_C);
13995 Discrim : Entity_Id;
13996 Corr_Discrim : Entity_Id;
13999 pragma Assert (not Is_Tagged or else not Stored_Discrim);
14001 Set_Parent (New_C, Parent (Old_C));
14003 -- Regular discriminants and components must be inserted in the scope
14004 -- of the Derived_Base. Do it here.
14006 if not Stored_Discrim then
14007 Enter_Name (New_C);
14010 -- For tagged types the Original_Record_Component must point to
14011 -- whatever this field was pointing to in the parent type. This has
14012 -- already been achieved by the call to New_Copy above.
14014 if not Is_Tagged then
14015 Set_Original_Record_Component (New_C, New_C);
14018 -- If we have inherited a component then see if its Etype contains
14019 -- references to Parent_Base discriminants. In this case, replace
14020 -- these references with the constraints given in Discs. We do not
14021 -- do this for the partial view of private types because this is
14022 -- not needed (only the components of the full view will be used
14023 -- for code generation) and cause problem. We also avoid this
14024 -- transformation in some error situations.
14026 if Ekind (New_C) = E_Component then
14027 if (Is_Private_Type (Derived_Base)
14028 and then not Is_Generic_Type (Derived_Base))
14029 or else (Is_Empty_Elmt_List (Discs)
14030 and then not Expander_Active)
14032 Set_Etype (New_C, Etype (Old_C));
14035 -- The current component introduces a circularity of the
14038 -- limited with Pack_2;
14039 -- package Pack_1 is
14040 -- type T_1 is tagged record
14041 -- Comp : access Pack_2.T_2;
14047 -- package Pack_2 is
14048 -- type T_2 is new Pack_1.T_1 with ...;
14053 Constrain_Component_Type
14054 (Old_C, Derived_Base, N, Parent_Base, Discs));
14058 -- In derived tagged types it is illegal to reference a non
14059 -- discriminant component in the parent type. To catch this, mark
14060 -- these components with an Ekind of E_Void. This will be reset in
14061 -- Record_Type_Definition after processing the record extension of
14062 -- the derived type.
14064 -- If the declaration is a private extension, there is no further
14065 -- record extension to process, and the components retain their
14066 -- current kind, because they are visible at this point.
14068 if Is_Tagged and then Ekind (New_C) = E_Component
14069 and then Nkind (N) /= N_Private_Extension_Declaration
14071 Set_Ekind (New_C, E_Void);
14074 if Plain_Discrim then
14075 Set_Corresponding_Discriminant (New_C, Old_C);
14076 Build_Discriminal (New_C);
14078 -- If we are explicitly inheriting a stored discriminant it will be
14079 -- completely hidden.
14081 elsif Stored_Discrim then
14082 Set_Corresponding_Discriminant (New_C, Empty);
14083 Set_Discriminal (New_C, Empty);
14084 Set_Is_Completely_Hidden (New_C);
14086 -- Set the Original_Record_Component of each discriminant in the
14087 -- derived base to point to the corresponding stored that we just
14090 Discrim := First_Discriminant (Derived_Base);
14091 while Present (Discrim) loop
14092 Corr_Discrim := Corresponding_Discriminant (Discrim);
14094 -- Corr_Discrim could be missing in an error situation
14096 if Present (Corr_Discrim)
14097 and then Original_Record_Component (Corr_Discrim) = Old_C
14099 Set_Original_Record_Component (Discrim, New_C);
14102 Next_Discriminant (Discrim);
14105 Append_Entity (New_C, Derived_Base);
14108 if not Is_Tagged then
14109 Append_Elmt (Old_C, Assoc_List);
14110 Append_Elmt (New_C, Assoc_List);
14112 end Inherit_Component;
14114 -- Variables local to Inherit_Component
14116 Loc : constant Source_Ptr := Sloc (N);
14118 Parent_Discrim : Entity_Id;
14119 Stored_Discrim : Entity_Id;
14121 Component : Entity_Id;
14123 -- Start of processing for Inherit_Components
14126 if not Is_Tagged then
14127 Append_Elmt (Parent_Base, Assoc_List);
14128 Append_Elmt (Derived_Base, Assoc_List);
14131 -- Inherit parent discriminants if needed
14133 if Inherit_Discr then
14134 Parent_Discrim := First_Discriminant (Parent_Base);
14135 while Present (Parent_Discrim) loop
14136 Inherit_Component (Parent_Discrim, Plain_Discrim => True);
14137 Next_Discriminant (Parent_Discrim);
14141 -- Create explicit stored discrims for untagged types when necessary
14143 if not Has_Unknown_Discriminants (Derived_Base)
14144 and then Has_Discriminants (Parent_Base)
14145 and then not Is_Tagged
14148 or else First_Discriminant (Parent_Base) /=
14149 First_Stored_Discriminant (Parent_Base))
14151 Stored_Discrim := First_Stored_Discriminant (Parent_Base);
14152 while Present (Stored_Discrim) loop
14153 Inherit_Component (Stored_Discrim, Stored_Discrim => True);
14154 Next_Stored_Discriminant (Stored_Discrim);
14158 -- See if we can apply the second transformation for derived types, as
14159 -- explained in point 6. in the comments above Build_Derived_Record_Type
14160 -- This is achieved by appending Derived_Base discriminants into Discs,
14161 -- which has the side effect of returning a non empty Discs list to the
14162 -- caller of Inherit_Components, which is what we want. This must be
14163 -- done for private derived types if there are explicit stored
14164 -- discriminants, to ensure that we can retrieve the values of the
14165 -- constraints provided in the ancestors.
14168 and then Is_Empty_Elmt_List (Discs)
14169 and then Present (First_Discriminant (Derived_Base))
14171 (not Is_Private_Type (Derived_Base)
14172 or else Is_Completely_Hidden
14173 (First_Stored_Discriminant (Derived_Base))
14174 or else Is_Generic_Type (Derived_Base))
14176 D := First_Discriminant (Derived_Base);
14177 while Present (D) loop
14178 Append_Elmt (New_Reference_To (D, Loc), Discs);
14179 Next_Discriminant (D);
14183 -- Finally, inherit non-discriminant components unless they are not
14184 -- visible because defined or inherited from the full view of the
14185 -- parent. Don't inherit the _parent field of the parent type.
14187 Component := First_Entity (Parent_Base);
14188 while Present (Component) loop
14190 -- Ada 2005 (AI-251): Do not inherit components associated with
14191 -- secondary tags of the parent.
14193 if Ekind (Component) = E_Component
14194 and then Present (Related_Type (Component))
14198 elsif Ekind (Component) /= E_Component
14199 or else Chars (Component) = Name_uParent
14203 -- If the derived type is within the parent type's declarative
14204 -- region, then the components can still be inherited even though
14205 -- they aren't visible at this point. This can occur for cases
14206 -- such as within public child units where the components must
14207 -- become visible upon entering the child unit's private part.
14209 elsif not Is_Visible_Component (Component)
14210 and then not In_Open_Scopes (Scope (Parent_Base))
14214 elsif Ekind (Derived_Base) = E_Private_Type
14215 or else Ekind (Derived_Base) = E_Limited_Private_Type
14220 Inherit_Component (Component);
14223 Next_Entity (Component);
14226 -- For tagged derived types, inherited discriminants cannot be used in
14227 -- component declarations of the record extension part. To achieve this
14228 -- we mark the inherited discriminants as not visible.
14230 if Is_Tagged and then Inherit_Discr then
14231 D := First_Discriminant (Derived_Base);
14232 while Present (D) loop
14233 Set_Is_Immediately_Visible (D, False);
14234 Next_Discriminant (D);
14239 end Inherit_Components;
14241 -----------------------
14242 -- Is_Null_Extension --
14243 -----------------------
14245 function Is_Null_Extension (T : Entity_Id) return Boolean is
14246 Type_Decl : constant Node_Id := Parent (T);
14247 Comp_List : Node_Id;
14251 if Nkind (Type_Decl) /= N_Full_Type_Declaration
14252 or else not Is_Tagged_Type (T)
14253 or else Nkind (Type_Definition (Type_Decl)) /=
14254 N_Derived_Type_Definition
14255 or else No (Record_Extension_Part (Type_Definition (Type_Decl)))
14261 Component_List (Record_Extension_Part (Type_Definition (Type_Decl)));
14263 if Present (Discriminant_Specifications (Type_Decl)) then
14266 elsif Present (Comp_List)
14267 and then Is_Non_Empty_List (Component_Items (Comp_List))
14269 Comp := First (Component_Items (Comp_List));
14271 -- Only user-defined components are relevant. The component list
14272 -- may also contain a parent component and internal components
14273 -- corresponding to secondary tags, but these do not determine
14274 -- whether this is a null extension.
14276 while Present (Comp) loop
14277 if Comes_From_Source (Comp) then
14288 end Is_Null_Extension;
14290 --------------------
14291 -- Is_Progenitor --
14292 --------------------
14294 function Is_Progenitor
14295 (Iface : Entity_Id;
14296 Typ : Entity_Id) return Boolean
14299 return Implements_Interface (Typ, Iface,
14300 Exclude_Parents => True);
14303 ------------------------------
14304 -- Is_Valid_Constraint_Kind --
14305 ------------------------------
14307 function Is_Valid_Constraint_Kind
14308 (T_Kind : Type_Kind;
14309 Constraint_Kind : Node_Kind) return Boolean
14313 when Enumeration_Kind |
14315 return Constraint_Kind = N_Range_Constraint;
14317 when Decimal_Fixed_Point_Kind =>
14318 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14319 N_Range_Constraint);
14321 when Ordinary_Fixed_Point_Kind =>
14322 return Nkind_In (Constraint_Kind, N_Delta_Constraint,
14323 N_Range_Constraint);
14326 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14327 N_Range_Constraint);
14334 E_Incomplete_Type |
14337 return Constraint_Kind = N_Index_Or_Discriminant_Constraint;
14340 return True; -- Error will be detected later
14342 end Is_Valid_Constraint_Kind;
14344 --------------------------
14345 -- Is_Visible_Component --
14346 --------------------------
14348 function Is_Visible_Component (C : Entity_Id) return Boolean is
14349 Original_Comp : Entity_Id := Empty;
14350 Original_Scope : Entity_Id;
14351 Type_Scope : Entity_Id;
14353 function Is_Local_Type (Typ : Entity_Id) return Boolean;
14354 -- Check whether parent type of inherited component is declared locally,
14355 -- possibly within a nested package or instance. The current scope is
14356 -- the derived record itself.
14358 -------------------
14359 -- Is_Local_Type --
14360 -------------------
14362 function Is_Local_Type (Typ : Entity_Id) return Boolean is
14366 Scop := Scope (Typ);
14367 while Present (Scop)
14368 and then Scop /= Standard_Standard
14370 if Scop = Scope (Current_Scope) then
14374 Scop := Scope (Scop);
14380 -- Start of processing for Is_Visible_Component
14383 if Ekind (C) = E_Component
14384 or else Ekind (C) = E_Discriminant
14386 Original_Comp := Original_Record_Component (C);
14389 if No (Original_Comp) then
14391 -- Premature usage, or previous error
14396 Original_Scope := Scope (Original_Comp);
14397 Type_Scope := Scope (Base_Type (Scope (C)));
14400 -- This test only concerns tagged types
14402 if not Is_Tagged_Type (Original_Scope) then
14405 -- If it is _Parent or _Tag, there is no visibility issue
14407 elsif not Comes_From_Source (Original_Comp) then
14410 -- If we are in the body of an instantiation, the component is visible
14411 -- even when the parent type (possibly defined in an enclosing unit or
14412 -- in a parent unit) might not.
14414 elsif In_Instance_Body then
14417 -- Discriminants are always visible
14419 elsif Ekind (Original_Comp) = E_Discriminant
14420 and then not Has_Unknown_Discriminants (Original_Scope)
14424 -- If the component has been declared in an ancestor which is currently
14425 -- a private type, then it is not visible. The same applies if the
14426 -- component's containing type is not in an open scope and the original
14427 -- component's enclosing type is a visible full view of a private type
14428 -- (which can occur in cases where an attempt is being made to reference
14429 -- a component in a sibling package that is inherited from a visible
14430 -- component of a type in an ancestor package; the component in the
14431 -- sibling package should not be visible even though the component it
14432 -- inherited from is visible). This does not apply however in the case
14433 -- where the scope of the type is a private child unit, or when the
14434 -- parent comes from a local package in which the ancestor is currently
14435 -- visible. The latter suppression of visibility is needed for cases
14436 -- that are tested in B730006.
14438 elsif Is_Private_Type (Original_Scope)
14440 (not Is_Private_Descendant (Type_Scope)
14441 and then not In_Open_Scopes (Type_Scope)
14442 and then Has_Private_Declaration (Original_Scope))
14444 -- If the type derives from an entity in a formal package, there
14445 -- are no additional visible components.
14447 if Nkind (Original_Node (Unit_Declaration_Node (Type_Scope))) =
14448 N_Formal_Package_Declaration
14452 -- if we are not in the private part of the current package, there
14453 -- are no additional visible components.
14455 elsif Ekind (Scope (Current_Scope)) = E_Package
14456 and then not In_Private_Part (Scope (Current_Scope))
14461 Is_Child_Unit (Cunit_Entity (Current_Sem_Unit))
14462 and then In_Open_Scopes (Scope (Original_Scope))
14463 and then Is_Local_Type (Type_Scope);
14466 -- There is another weird way in which a component may be invisible
14467 -- when the private and the full view are not derived from the same
14468 -- ancestor. Here is an example :
14470 -- type A1 is tagged record F1 : integer; end record;
14471 -- type A2 is new A1 with record F2 : integer; end record;
14472 -- type T is new A1 with private;
14474 -- type T is new A2 with null record;
14476 -- In this case, the full view of T inherits F1 and F2 but the private
14477 -- view inherits only F1
14481 Ancestor : Entity_Id := Scope (C);
14485 if Ancestor = Original_Scope then
14487 elsif Ancestor = Etype (Ancestor) then
14491 Ancestor := Etype (Ancestor);
14495 end Is_Visible_Component;
14497 --------------------------
14498 -- Make_Class_Wide_Type --
14499 --------------------------
14501 procedure Make_Class_Wide_Type (T : Entity_Id) is
14502 CW_Type : Entity_Id;
14504 Next_E : Entity_Id;
14507 -- The class wide type can have been defined by the partial view, in
14508 -- which case everything is already done.
14510 if Present (Class_Wide_Type (T)) then
14515 New_External_Entity (E_Void, Scope (T), Sloc (T), T, 'C', 0, 'T');
14517 -- Inherit root type characteristics
14519 CW_Name := Chars (CW_Type);
14520 Next_E := Next_Entity (CW_Type);
14521 Copy_Node (T, CW_Type);
14522 Set_Comes_From_Source (CW_Type, False);
14523 Set_Chars (CW_Type, CW_Name);
14524 Set_Parent (CW_Type, Parent (T));
14525 Set_Next_Entity (CW_Type, Next_E);
14527 -- Ensure we have a new freeze node for the class-wide type. The partial
14528 -- view may have freeze action of its own, requiring a proper freeze
14529 -- node, and the same freeze node cannot be shared between the two
14532 Set_Has_Delayed_Freeze (CW_Type);
14533 Set_Freeze_Node (CW_Type, Empty);
14535 -- Customize the class-wide type: It has no prim. op., it cannot be
14536 -- abstract and its Etype points back to the specific root type.
14538 Set_Ekind (CW_Type, E_Class_Wide_Type);
14539 Set_Is_Tagged_Type (CW_Type, True);
14540 Set_Primitive_Operations (CW_Type, New_Elmt_List);
14541 Set_Is_Abstract_Type (CW_Type, False);
14542 Set_Is_Constrained (CW_Type, False);
14543 Set_Is_First_Subtype (CW_Type, Is_First_Subtype (T));
14545 if Ekind (T) = E_Class_Wide_Subtype then
14546 Set_Etype (CW_Type, Etype (Base_Type (T)));
14548 Set_Etype (CW_Type, T);
14551 -- If this is the class_wide type of a constrained subtype, it does
14552 -- not have discriminants.
14554 Set_Has_Discriminants (CW_Type,
14555 Has_Discriminants (T) and then not Is_Constrained (T));
14557 Set_Has_Unknown_Discriminants (CW_Type, True);
14558 Set_Class_Wide_Type (T, CW_Type);
14559 Set_Equivalent_Type (CW_Type, Empty);
14561 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
14563 Set_Class_Wide_Type (CW_Type, CW_Type);
14564 end Make_Class_Wide_Type;
14570 procedure Make_Index
14572 Related_Nod : Node_Id;
14573 Related_Id : Entity_Id := Empty;
14574 Suffix_Index : Nat := 1)
14578 Def_Id : Entity_Id := Empty;
14579 Found : Boolean := False;
14582 -- For a discrete range used in a constrained array definition and
14583 -- defined by a range, an implicit conversion to the predefined type
14584 -- INTEGER is assumed if each bound is either a numeric literal, a named
14585 -- number, or an attribute, and the type of both bounds (prior to the
14586 -- implicit conversion) is the type universal_integer. Otherwise, both
14587 -- bounds must be of the same discrete type, other than universal
14588 -- integer; this type must be determinable independently of the
14589 -- context, but using the fact that the type must be discrete and that
14590 -- both bounds must have the same type.
14592 -- Character literals also have a universal type in the absence of
14593 -- of additional context, and are resolved to Standard_Character.
14595 if Nkind (I) = N_Range then
14597 -- The index is given by a range constraint. The bounds are known
14598 -- to be of a consistent type.
14600 if not Is_Overloaded (I) then
14603 -- For universal bounds, choose the specific predefined type
14605 if T = Universal_Integer then
14606 T := Standard_Integer;
14608 elsif T = Any_Character then
14609 Ambiguous_Character (Low_Bound (I));
14611 T := Standard_Character;
14614 -- The node may be overloaded because some user-defined operators
14615 -- are available, but if a universal interpretation exists it is
14616 -- also the selected one.
14618 elsif Universal_Interpretation (I) = Universal_Integer then
14619 T := Standard_Integer;
14625 Ind : Interp_Index;
14629 Get_First_Interp (I, Ind, It);
14630 while Present (It.Typ) loop
14631 if Is_Discrete_Type (It.Typ) then
14634 and then not Covers (It.Typ, T)
14635 and then not Covers (T, It.Typ)
14637 Error_Msg_N ("ambiguous bounds in discrete range", I);
14645 Get_Next_Interp (Ind, It);
14648 if T = Any_Type then
14649 Error_Msg_N ("discrete type required for range", I);
14650 Set_Etype (I, Any_Type);
14653 elsif T = Universal_Integer then
14654 T := Standard_Integer;
14659 if not Is_Discrete_Type (T) then
14660 Error_Msg_N ("discrete type required for range", I);
14661 Set_Etype (I, Any_Type);
14665 if Nkind (Low_Bound (I)) = N_Attribute_Reference
14666 and then Attribute_Name (Low_Bound (I)) = Name_First
14667 and then Is_Entity_Name (Prefix (Low_Bound (I)))
14668 and then Is_Type (Entity (Prefix (Low_Bound (I))))
14669 and then Is_Discrete_Type (Entity (Prefix (Low_Bound (I))))
14671 -- The type of the index will be the type of the prefix, as long
14672 -- as the upper bound is 'Last of the same type.
14674 Def_Id := Entity (Prefix (Low_Bound (I)));
14676 if Nkind (High_Bound (I)) /= N_Attribute_Reference
14677 or else Attribute_Name (High_Bound (I)) /= Name_Last
14678 or else not Is_Entity_Name (Prefix (High_Bound (I)))
14679 or else Entity (Prefix (High_Bound (I))) /= Def_Id
14686 Process_Range_Expr_In_Decl (R, T);
14688 elsif Nkind (I) = N_Subtype_Indication then
14690 -- The index is given by a subtype with a range constraint
14692 T := Base_Type (Entity (Subtype_Mark (I)));
14694 if not Is_Discrete_Type (T) then
14695 Error_Msg_N ("discrete type required for range", I);
14696 Set_Etype (I, Any_Type);
14700 R := Range_Expression (Constraint (I));
14703 Process_Range_Expr_In_Decl (R, Entity (Subtype_Mark (I)));
14705 elsif Nkind (I) = N_Attribute_Reference then
14707 -- The parser guarantees that the attribute is a RANGE attribute
14709 -- If the node denotes the range of a type mark, that is also the
14710 -- resulting type, and we do no need to create an Itype for it.
14712 if Is_Entity_Name (Prefix (I))
14713 and then Comes_From_Source (I)
14714 and then Is_Type (Entity (Prefix (I)))
14715 and then Is_Discrete_Type (Entity (Prefix (I)))
14717 Def_Id := Entity (Prefix (I));
14720 Analyze_And_Resolve (I);
14724 -- If none of the above, must be a subtype. We convert this to a
14725 -- range attribute reference because in the case of declared first
14726 -- named subtypes, the types in the range reference can be different
14727 -- from the type of the entity. A range attribute normalizes the
14728 -- reference and obtains the correct types for the bounds.
14730 -- This transformation is in the nature of an expansion, is only
14731 -- done if expansion is active. In particular, it is not done on
14732 -- formal generic types, because we need to retain the name of the
14733 -- original index for instantiation purposes.
14736 if not Is_Entity_Name (I) or else not Is_Type (Entity (I)) then
14737 Error_Msg_N ("invalid subtype mark in discrete range ", I);
14738 Set_Etype (I, Any_Integer);
14742 -- The type mark may be that of an incomplete type. It is only
14743 -- now that we can get the full view, previous analysis does
14744 -- not look specifically for a type mark.
14746 Set_Entity (I, Get_Full_View (Entity (I)));
14747 Set_Etype (I, Entity (I));
14748 Def_Id := Entity (I);
14750 if not Is_Discrete_Type (Def_Id) then
14751 Error_Msg_N ("discrete type required for index", I);
14752 Set_Etype (I, Any_Type);
14757 if Expander_Active then
14759 Make_Attribute_Reference (Sloc (I),
14760 Attribute_Name => Name_Range,
14761 Prefix => Relocate_Node (I)));
14763 -- The original was a subtype mark that does not freeze. This
14764 -- means that the rewritten version must not freeze either.
14766 Set_Must_Not_Freeze (I);
14767 Set_Must_Not_Freeze (Prefix (I));
14769 -- Is order critical??? if so, document why, if not
14770 -- use Analyze_And_Resolve
14772 Analyze_And_Resolve (I);
14776 -- If expander is inactive, type is legal, nothing else to construct
14783 if not Is_Discrete_Type (T) then
14784 Error_Msg_N ("discrete type required for range", I);
14785 Set_Etype (I, Any_Type);
14788 elsif T = Any_Type then
14789 Set_Etype (I, Any_Type);
14793 -- We will now create the appropriate Itype to describe the range, but
14794 -- first a check. If we originally had a subtype, then we just label
14795 -- the range with this subtype. Not only is there no need to construct
14796 -- a new subtype, but it is wrong to do so for two reasons:
14798 -- 1. A legality concern, if we have a subtype, it must not freeze,
14799 -- and the Itype would cause freezing incorrectly
14801 -- 2. An efficiency concern, if we created an Itype, it would not be
14802 -- recognized as the same type for the purposes of eliminating
14803 -- checks in some circumstances.
14805 -- We signal this case by setting the subtype entity in Def_Id
14807 if No (Def_Id) then
14809 Create_Itype (E_Void, Related_Nod, Related_Id, 'D', Suffix_Index);
14810 Set_Etype (Def_Id, Base_Type (T));
14812 if Is_Signed_Integer_Type (T) then
14813 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
14815 elsif Is_Modular_Integer_Type (T) then
14816 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
14819 Set_Ekind (Def_Id, E_Enumeration_Subtype);
14820 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
14821 Set_First_Literal (Def_Id, First_Literal (T));
14824 Set_Size_Info (Def_Id, (T));
14825 Set_RM_Size (Def_Id, RM_Size (T));
14826 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
14828 Set_Scalar_Range (Def_Id, R);
14829 Conditional_Delay (Def_Id, T);
14831 -- In the subtype indication case, if the immediate parent of the
14832 -- new subtype is non-static, then the subtype we create is non-
14833 -- static, even if its bounds are static.
14835 if Nkind (I) = N_Subtype_Indication
14836 and then not Is_Static_Subtype (Entity (Subtype_Mark (I)))
14838 Set_Is_Non_Static_Subtype (Def_Id);
14842 -- Final step is to label the index with this constructed type
14844 Set_Etype (I, Def_Id);
14847 ------------------------------
14848 -- Modular_Type_Declaration --
14849 ------------------------------
14851 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id) is
14852 Mod_Expr : constant Node_Id := Expression (Def);
14855 procedure Set_Modular_Size (Bits : Int);
14856 -- Sets RM_Size to Bits, and Esize to normal word size above this
14858 ----------------------
14859 -- Set_Modular_Size --
14860 ----------------------
14862 procedure Set_Modular_Size (Bits : Int) is
14864 Set_RM_Size (T, UI_From_Int (Bits));
14869 elsif Bits <= 16 then
14870 Init_Esize (T, 16);
14872 elsif Bits <= 32 then
14873 Init_Esize (T, 32);
14876 Init_Esize (T, System_Max_Binary_Modulus_Power);
14878 end Set_Modular_Size;
14880 -- Start of processing for Modular_Type_Declaration
14883 Analyze_And_Resolve (Mod_Expr, Any_Integer);
14885 Set_Ekind (T, E_Modular_Integer_Type);
14886 Init_Alignment (T);
14887 Set_Is_Constrained (T);
14889 if not Is_OK_Static_Expression (Mod_Expr) then
14890 Flag_Non_Static_Expr
14891 ("non-static expression used for modular type bound!", Mod_Expr);
14892 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14894 M_Val := Expr_Value (Mod_Expr);
14898 Error_Msg_N ("modulus value must be positive", Mod_Expr);
14899 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14902 Set_Modulus (T, M_Val);
14904 -- Create bounds for the modular type based on the modulus given in
14905 -- the type declaration and then analyze and resolve those bounds.
14907 Set_Scalar_Range (T,
14908 Make_Range (Sloc (Mod_Expr),
14910 Make_Integer_Literal (Sloc (Mod_Expr), 0),
14912 Make_Integer_Literal (Sloc (Mod_Expr), M_Val - 1)));
14914 -- Properly analyze the literals for the range. We do this manually
14915 -- because we can't go calling Resolve, since we are resolving these
14916 -- bounds with the type, and this type is certainly not complete yet!
14918 Set_Etype (Low_Bound (Scalar_Range (T)), T);
14919 Set_Etype (High_Bound (Scalar_Range (T)), T);
14920 Set_Is_Static_Expression (Low_Bound (Scalar_Range (T)));
14921 Set_Is_Static_Expression (High_Bound (Scalar_Range (T)));
14923 -- Loop through powers of two to find number of bits required
14925 for Bits in Int range 0 .. System_Max_Binary_Modulus_Power loop
14929 if M_Val = 2 ** Bits then
14930 Set_Modular_Size (Bits);
14935 elsif M_Val < 2 ** Bits then
14936 Set_Non_Binary_Modulus (T);
14938 if Bits > System_Max_Nonbinary_Modulus_Power then
14939 Error_Msg_Uint_1 :=
14940 UI_From_Int (System_Max_Nonbinary_Modulus_Power);
14942 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr);
14943 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14947 -- In the non-binary case, set size as per RM 13.3(55)
14949 Set_Modular_Size (Bits);
14956 -- If we fall through, then the size exceed System.Max_Binary_Modulus
14957 -- so we just signal an error and set the maximum size.
14959 Error_Msg_Uint_1 := UI_From_Int (System_Max_Binary_Modulus_Power);
14960 Error_Msg_F ("modulus exceeds limit (2 '*'*^)", Mod_Expr);
14962 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14963 Init_Alignment (T);
14965 end Modular_Type_Declaration;
14967 --------------------------
14968 -- New_Concatenation_Op --
14969 --------------------------
14971 procedure New_Concatenation_Op (Typ : Entity_Id) is
14972 Loc : constant Source_Ptr := Sloc (Typ);
14975 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id;
14976 -- Create abbreviated declaration for the formal of a predefined
14977 -- Operator 'Op' of type 'Typ'
14979 --------------------
14980 -- Make_Op_Formal --
14981 --------------------
14983 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id is
14984 Formal : Entity_Id;
14986 Formal := New_Internal_Entity (E_In_Parameter, Op, Loc, 'P');
14987 Set_Etype (Formal, Typ);
14988 Set_Mechanism (Formal, Default_Mechanism);
14990 end Make_Op_Formal;
14992 -- Start of processing for New_Concatenation_Op
14995 Op := Make_Defining_Operator_Symbol (Loc, Name_Op_Concat);
14997 Set_Ekind (Op, E_Operator);
14998 Set_Scope (Op, Current_Scope);
14999 Set_Etype (Op, Typ);
15000 Set_Homonym (Op, Get_Name_Entity_Id (Name_Op_Concat));
15001 Set_Is_Immediately_Visible (Op);
15002 Set_Is_Intrinsic_Subprogram (Op);
15003 Set_Has_Completion (Op);
15004 Append_Entity (Op, Current_Scope);
15006 Set_Name_Entity_Id (Name_Op_Concat, Op);
15008 Append_Entity (Make_Op_Formal (Typ, Op), Op);
15009 Append_Entity (Make_Op_Formal (Typ, Op), Op);
15010 end New_Concatenation_Op;
15012 -------------------------
15013 -- OK_For_Limited_Init --
15014 -------------------------
15016 -- ???Check all calls of this, and compare the conditions under which it's
15019 function OK_For_Limited_Init (Exp : Node_Id) return Boolean is
15021 return Ada_Version >= Ada_05
15022 and then not Debug_Flag_Dot_L
15023 and then OK_For_Limited_Init_In_05 (Exp);
15024 end OK_For_Limited_Init;
15026 -------------------------------
15027 -- OK_For_Limited_Init_In_05 --
15028 -------------------------------
15030 function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean is
15032 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
15033 -- case of limited aggregates (including extension aggregates), and
15034 -- function calls. The function call may have been give in prefixed
15035 -- notation, in which case the original node is an indexed component.
15037 case Nkind (Original_Node (Exp)) is
15038 when N_Aggregate | N_Extension_Aggregate | N_Function_Call | N_Op =>
15041 when N_Qualified_Expression =>
15043 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
15045 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
15046 -- with a function call, the expander has rewritten the call into an
15047 -- N_Type_Conversion node to force displacement of the pointer to
15048 -- reference the component containing the secondary dispatch table.
15049 -- Otherwise a type conversion is not a legal context.
15051 when N_Type_Conversion =>
15052 return not Comes_From_Source (Exp)
15054 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
15056 when N_Indexed_Component | N_Selected_Component =>
15057 return Nkind (Exp) = N_Function_Call;
15059 -- A use of 'Input is a function call, hence allowed. Normally the
15060 -- attribute will be changed to a call, but the attribute by itself
15061 -- can occur with -gnatc.
15063 when N_Attribute_Reference =>
15064 return Attribute_Name (Original_Node (Exp)) = Name_Input;
15069 end OK_For_Limited_Init_In_05;
15071 -------------------------------------------
15072 -- Ordinary_Fixed_Point_Type_Declaration --
15073 -------------------------------------------
15075 procedure Ordinary_Fixed_Point_Type_Declaration
15079 Loc : constant Source_Ptr := Sloc (Def);
15080 Delta_Expr : constant Node_Id := Delta_Expression (Def);
15081 RRS : constant Node_Id := Real_Range_Specification (Def);
15082 Implicit_Base : Entity_Id;
15089 Check_Restriction (No_Fixed_Point, Def);
15091 -- Create implicit base type
15094 Create_Itype (E_Ordinary_Fixed_Point_Type, Parent (Def), T, 'B');
15095 Set_Etype (Implicit_Base, Implicit_Base);
15097 -- Analyze and process delta expression
15099 Analyze_And_Resolve (Delta_Expr, Any_Real);
15101 Check_Delta_Expression (Delta_Expr);
15102 Delta_Val := Expr_Value_R (Delta_Expr);
15104 Set_Delta_Value (Implicit_Base, Delta_Val);
15106 -- Compute default small from given delta, which is the largest power
15107 -- of two that does not exceed the given delta value.
15117 if Delta_Val < Ureal_1 then
15118 while Delta_Val < Tmp loop
15119 Tmp := Tmp / Ureal_2;
15120 Scale := Scale + 1;
15125 Tmp := Tmp * Ureal_2;
15126 exit when Tmp > Delta_Val;
15127 Scale := Scale - 1;
15131 Small_Val := UR_From_Components (Uint_1, UI_From_Int (Scale), 2);
15134 Set_Small_Value (Implicit_Base, Small_Val);
15136 -- If no range was given, set a dummy range
15138 if RRS <= Empty_Or_Error then
15139 Low_Val := -Small_Val;
15140 High_Val := Small_Val;
15142 -- Otherwise analyze and process given range
15146 Low : constant Node_Id := Low_Bound (RRS);
15147 High : constant Node_Id := High_Bound (RRS);
15150 Analyze_And_Resolve (Low, Any_Real);
15151 Analyze_And_Resolve (High, Any_Real);
15152 Check_Real_Bound (Low);
15153 Check_Real_Bound (High);
15155 -- Obtain and set the range
15157 Low_Val := Expr_Value_R (Low);
15158 High_Val := Expr_Value_R (High);
15160 if Low_Val > High_Val then
15161 Error_Msg_NE ("?fixed point type& has null range", Def, T);
15166 -- The range for both the implicit base and the declared first subtype
15167 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
15168 -- set a temporary range in place. Note that the bounds of the base
15169 -- type will be widened to be symmetrical and to fill the available
15170 -- bits when the type is frozen.
15172 -- We could do this with all discrete types, and probably should, but
15173 -- we absolutely have to do it for fixed-point, since the end-points
15174 -- of the range and the size are determined by the small value, which
15175 -- could be reset before the freeze point.
15177 Set_Fixed_Range (Implicit_Base, Loc, Low_Val, High_Val);
15178 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
15180 -- Complete definition of first subtype
15182 Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype);
15183 Set_Etype (T, Implicit_Base);
15184 Init_Size_Align (T);
15185 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
15186 Set_Small_Value (T, Small_Val);
15187 Set_Delta_Value (T, Delta_Val);
15188 Set_Is_Constrained (T);
15190 end Ordinary_Fixed_Point_Type_Declaration;
15192 ----------------------------------------
15193 -- Prepare_Private_Subtype_Completion --
15194 ----------------------------------------
15196 procedure Prepare_Private_Subtype_Completion
15198 Related_Nod : Node_Id)
15200 Id_B : constant Entity_Id := Base_Type (Id);
15201 Full_B : constant Entity_Id := Full_View (Id_B);
15205 if Present (Full_B) then
15207 -- The Base_Type is already completed, we can complete the subtype
15208 -- now. We have to create a new entity with the same name, Thus we
15209 -- can't use Create_Itype.
15211 -- This is messy, should be fixed ???
15213 Full := Make_Defining_Identifier (Sloc (Id), Chars (Id));
15214 Set_Is_Itype (Full);
15215 Set_Associated_Node_For_Itype (Full, Related_Nod);
15216 Complete_Private_Subtype (Id, Full, Full_B, Related_Nod);
15219 -- The parent subtype may be private, but the base might not, in some
15220 -- nested instances. In that case, the subtype does not need to be
15221 -- exchanged. It would still be nice to make private subtypes and their
15222 -- bases consistent at all times ???
15224 if Is_Private_Type (Id_B) then
15225 Append_Elmt (Id, Private_Dependents (Id_B));
15228 end Prepare_Private_Subtype_Completion;
15230 ---------------------------
15231 -- Process_Discriminants --
15232 ---------------------------
15234 procedure Process_Discriminants
15236 Prev : Entity_Id := Empty)
15238 Elist : constant Elist_Id := New_Elmt_List;
15241 Discr_Number : Uint;
15242 Discr_Type : Entity_Id;
15243 Default_Present : Boolean := False;
15244 Default_Not_Present : Boolean := False;
15247 -- A composite type other than an array type can have discriminants.
15248 -- On entry, the current scope is the composite type.
15250 -- The discriminants are initially entered into the scope of the type
15251 -- via Enter_Name with the default Ekind of E_Void to prevent premature
15252 -- use, as explained at the end of this procedure.
15254 Discr := First (Discriminant_Specifications (N));
15255 while Present (Discr) loop
15256 Enter_Name (Defining_Identifier (Discr));
15258 -- For navigation purposes we add a reference to the discriminant
15259 -- in the entity for the type. If the current declaration is a
15260 -- completion, place references on the partial view. Otherwise the
15261 -- type is the current scope.
15263 if Present (Prev) then
15265 -- The references go on the partial view, if present. If the
15266 -- partial view has discriminants, the references have been
15267 -- generated already.
15269 if not Has_Discriminants (Prev) then
15270 Generate_Reference (Prev, Defining_Identifier (Discr), 'd');
15274 (Current_Scope, Defining_Identifier (Discr), 'd');
15277 if Nkind (Discriminant_Type (Discr)) = N_Access_Definition then
15278 Discr_Type := Access_Definition (Discr, Discriminant_Type (Discr));
15280 -- Ada 2005 (AI-254)
15282 if Present (Access_To_Subprogram_Definition
15283 (Discriminant_Type (Discr)))
15284 and then Protected_Present (Access_To_Subprogram_Definition
15285 (Discriminant_Type (Discr)))
15288 Replace_Anonymous_Access_To_Protected_Subprogram (Discr);
15292 Find_Type (Discriminant_Type (Discr));
15293 Discr_Type := Etype (Discriminant_Type (Discr));
15295 if Error_Posted (Discriminant_Type (Discr)) then
15296 Discr_Type := Any_Type;
15300 if Is_Access_Type (Discr_Type) then
15302 -- Ada 2005 (AI-230): Access discriminant allowed in non-limited
15305 if Ada_Version < Ada_05 then
15306 Check_Access_Discriminant_Requires_Limited
15307 (Discr, Discriminant_Type (Discr));
15310 if Ada_Version = Ada_83 and then Comes_From_Source (Discr) then
15312 ("(Ada 83) access discriminant not allowed", Discr);
15315 elsif not Is_Discrete_Type (Discr_Type) then
15316 Error_Msg_N ("discriminants must have a discrete or access type",
15317 Discriminant_Type (Discr));
15320 Set_Etype (Defining_Identifier (Discr), Discr_Type);
15322 -- If a discriminant specification includes the assignment compound
15323 -- delimiter followed by an expression, the expression is the default
15324 -- expression of the discriminant; the default expression must be of
15325 -- the type of the discriminant. (RM 3.7.1) Since this expression is
15326 -- a default expression, we do the special preanalysis, since this
15327 -- expression does not freeze (see "Handling of Default and Per-
15328 -- Object Expressions" in spec of package Sem).
15330 if Present (Expression (Discr)) then
15331 Preanalyze_Spec_Expression (Expression (Discr), Discr_Type);
15333 if Nkind (N) = N_Formal_Type_Declaration then
15335 ("discriminant defaults not allowed for formal type",
15336 Expression (Discr));
15338 -- Tagged types cannot have defaulted discriminants, but a
15339 -- non-tagged private type with defaulted discriminants
15340 -- can have a tagged completion.
15342 elsif Is_Tagged_Type (Current_Scope)
15343 and then Comes_From_Source (N)
15346 ("discriminants of tagged type cannot have defaults",
15347 Expression (Discr));
15350 Default_Present := True;
15351 Append_Elmt (Expression (Discr), Elist);
15353 -- Tag the defining identifiers for the discriminants with
15354 -- their corresponding default expressions from the tree.
15356 Set_Discriminant_Default_Value
15357 (Defining_Identifier (Discr), Expression (Discr));
15361 Default_Not_Present := True;
15364 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
15365 -- Discr_Type but with the null-exclusion attribute
15367 if Ada_Version >= Ada_05 then
15369 -- Ada 2005 (AI-231): Static checks
15371 if Can_Never_Be_Null (Discr_Type) then
15372 Null_Exclusion_Static_Checks (Discr);
15374 elsif Is_Access_Type (Discr_Type)
15375 and then Null_Exclusion_Present (Discr)
15377 -- No need to check itypes because in their case this check
15378 -- was done at their point of creation
15380 and then not Is_Itype (Discr_Type)
15382 if Can_Never_Be_Null (Discr_Type) then
15384 ("`NOT NULL` not allowed (& already excludes null)",
15389 Set_Etype (Defining_Identifier (Discr),
15390 Create_Null_Excluding_Itype
15392 Related_Nod => Discr));
15394 -- Check for improper null exclusion if the type is otherwise
15395 -- legal for a discriminant.
15397 elsif Null_Exclusion_Present (Discr)
15398 and then Is_Discrete_Type (Discr_Type)
15401 ("null exclusion can only apply to an access type", Discr);
15404 -- Ada 2005 (AI-402): access discriminants of nonlimited types
15405 -- can't have defaults. Synchronized types, or types that are
15406 -- explicitly limited are fine, but special tests apply to derived
15407 -- types in generics: in a generic body we have to assume the
15408 -- worst, and therefore defaults are not allowed if the parent is
15409 -- a generic formal private type (see ACATS B370001).
15411 if Is_Access_Type (Discr_Type) then
15412 if Ekind (Discr_Type) /= E_Anonymous_Access_Type
15413 or else not Default_Present
15414 or else Is_Limited_Record (Current_Scope)
15415 or else Is_Concurrent_Type (Current_Scope)
15416 or else Is_Concurrent_Record_Type (Current_Scope)
15417 or else Ekind (Current_Scope) = E_Limited_Private_Type
15419 if not Is_Derived_Type (Current_Scope)
15420 or else not Is_Generic_Type (Etype (Current_Scope))
15421 or else not In_Package_Body (Scope (Etype (Current_Scope)))
15422 or else Limited_Present
15423 (Type_Definition (Parent (Current_Scope)))
15428 Error_Msg_N ("access discriminants of nonlimited types",
15429 Expression (Discr));
15430 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15433 elsif Present (Expression (Discr)) then
15435 ("(Ada 2005) access discriminants of nonlimited types",
15436 Expression (Discr));
15437 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15445 -- An element list consisting of the default expressions of the
15446 -- discriminants is constructed in the above loop and used to set
15447 -- the Discriminant_Constraint attribute for the type. If an object
15448 -- is declared of this (record or task) type without any explicit
15449 -- discriminant constraint given, this element list will form the
15450 -- actual parameters for the corresponding initialization procedure
15453 Set_Discriminant_Constraint (Current_Scope, Elist);
15454 Set_Stored_Constraint (Current_Scope, No_Elist);
15456 -- Default expressions must be provided either for all or for none
15457 -- of the discriminants of a discriminant part. (RM 3.7.1)
15459 if Default_Present and then Default_Not_Present then
15461 ("incomplete specification of defaults for discriminants", N);
15464 -- The use of the name of a discriminant is not allowed in default
15465 -- expressions of a discriminant part if the specification of the
15466 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
15468 -- To detect this, the discriminant names are entered initially with an
15469 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
15470 -- attempt to use a void entity (for example in an expression that is
15471 -- type-checked) produces the error message: premature usage. Now after
15472 -- completing the semantic analysis of the discriminant part, we can set
15473 -- the Ekind of all the discriminants appropriately.
15475 Discr := First (Discriminant_Specifications (N));
15476 Discr_Number := Uint_1;
15477 while Present (Discr) loop
15478 Id := Defining_Identifier (Discr);
15479 Set_Ekind (Id, E_Discriminant);
15480 Init_Component_Location (Id);
15482 Set_Discriminant_Number (Id, Discr_Number);
15484 -- Make sure this is always set, even in illegal programs
15486 Set_Corresponding_Discriminant (Id, Empty);
15488 -- Initialize the Original_Record_Component to the entity itself.
15489 -- Inherit_Components will propagate the right value to
15490 -- discriminants in derived record types.
15492 Set_Original_Record_Component (Id, Id);
15494 -- Create the discriminal for the discriminant
15496 Build_Discriminal (Id);
15499 Discr_Number := Discr_Number + 1;
15502 Set_Has_Discriminants (Current_Scope);
15503 end Process_Discriminants;
15505 -----------------------
15506 -- Process_Full_View --
15507 -----------------------
15509 procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id) is
15510 Priv_Parent : Entity_Id;
15511 Full_Parent : Entity_Id;
15512 Full_Indic : Node_Id;
15514 procedure Collect_Implemented_Interfaces
15516 Ifaces : Elist_Id);
15517 -- Ada 2005: Gather all the interfaces that Typ directly or
15518 -- inherently implements. Duplicate entries are not added to
15519 -- the list Ifaces.
15521 ------------------------------------
15522 -- Collect_Implemented_Interfaces --
15523 ------------------------------------
15525 procedure Collect_Implemented_Interfaces
15530 Iface_Elmt : Elmt_Id;
15533 -- Abstract interfaces are only associated with tagged record types
15535 if not Is_Tagged_Type (Typ)
15536 or else not Is_Record_Type (Typ)
15541 -- Recursively climb to the ancestors
15543 if Etype (Typ) /= Typ
15545 -- Protect the frontend against wrong cyclic declarations like:
15547 -- type B is new A with private;
15548 -- type C is new A with private;
15550 -- type B is new C with null record;
15551 -- type C is new B with null record;
15553 and then Etype (Typ) /= Priv_T
15554 and then Etype (Typ) /= Full_T
15556 -- Keep separate the management of private type declarations
15558 if Ekind (Typ) = E_Record_Type_With_Private then
15560 -- Handle the following erronous case:
15561 -- type Private_Type is tagged private;
15563 -- type Private_Type is new Type_Implementing_Iface;
15565 if Present (Full_View (Typ))
15566 and then Etype (Typ) /= Full_View (Typ)
15568 if Is_Interface (Etype (Typ)) then
15569 Append_Unique_Elmt (Etype (Typ), Ifaces);
15572 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15575 -- Non-private types
15578 if Is_Interface (Etype (Typ)) then
15579 Append_Unique_Elmt (Etype (Typ), Ifaces);
15582 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15586 -- Handle entities in the list of abstract interfaces
15588 if Present (Interfaces (Typ)) then
15589 Iface_Elmt := First_Elmt (Interfaces (Typ));
15590 while Present (Iface_Elmt) loop
15591 Iface := Node (Iface_Elmt);
15593 pragma Assert (Is_Interface (Iface));
15595 if not Contain_Interface (Iface, Ifaces) then
15596 Append_Elmt (Iface, Ifaces);
15597 Collect_Implemented_Interfaces (Iface, Ifaces);
15600 Next_Elmt (Iface_Elmt);
15603 end Collect_Implemented_Interfaces;
15605 -- Start of processing for Process_Full_View
15608 -- First some sanity checks that must be done after semantic
15609 -- decoration of the full view and thus cannot be placed with other
15610 -- similar checks in Find_Type_Name
15612 if not Is_Limited_Type (Priv_T)
15613 and then (Is_Limited_Type (Full_T)
15614 or else Is_Limited_Composite (Full_T))
15617 ("completion of nonlimited type cannot be limited", Full_T);
15618 Explain_Limited_Type (Full_T, Full_T);
15620 elsif Is_Abstract_Type (Full_T)
15621 and then not Is_Abstract_Type (Priv_T)
15624 ("completion of nonabstract type cannot be abstract", Full_T);
15626 elsif Is_Tagged_Type (Priv_T)
15627 and then Is_Limited_Type (Priv_T)
15628 and then not Is_Limited_Type (Full_T)
15630 -- If pragma CPP_Class was applied to the private declaration
15631 -- propagate the limitedness to the full-view
15633 if Is_CPP_Class (Priv_T) then
15634 Set_Is_Limited_Record (Full_T);
15636 -- GNAT allow its own definition of Limited_Controlled to disobey
15637 -- this rule in order in ease the implementation. The next test is
15638 -- safe because Root_Controlled is defined in a private system child
15640 elsif Etype (Full_T) = Full_View (RTE (RE_Root_Controlled)) then
15641 Set_Is_Limited_Composite (Full_T);
15644 ("completion of limited tagged type must be limited", Full_T);
15647 elsif Is_Generic_Type (Priv_T) then
15648 Error_Msg_N ("generic type cannot have a completion", Full_T);
15651 -- Check that ancestor interfaces of private and full views are
15652 -- consistent. We omit this check for synchronized types because
15653 -- they are performed on the corresponding record type when frozen.
15655 if Ada_Version >= Ada_05
15656 and then Is_Tagged_Type (Priv_T)
15657 and then Is_Tagged_Type (Full_T)
15658 and then not Is_Concurrent_Type (Full_T)
15662 Priv_T_Ifaces : constant Elist_Id := New_Elmt_List;
15663 Full_T_Ifaces : constant Elist_Id := New_Elmt_List;
15666 Collect_Implemented_Interfaces (Priv_T, Priv_T_Ifaces);
15667 Collect_Implemented_Interfaces (Full_T, Full_T_Ifaces);
15669 -- Ada 2005 (AI-251): The partial view shall be a descendant of
15670 -- an interface type if and only if the full type is descendant
15671 -- of the interface type (AARM 7.3 (7.3/2).
15673 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
15675 if Present (Iface) then
15676 Error_Msg_NE ("interface & not implemented by full type " &
15677 "(RM-2005 7.3 (7.3/2))", Priv_T, Iface);
15680 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
15682 if Present (Iface) then
15683 Error_Msg_NE ("interface & not implemented by partial view " &
15684 "(RM-2005 7.3 (7.3/2))", Full_T, Iface);
15689 if Is_Tagged_Type (Priv_T)
15690 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15691 and then Is_Derived_Type (Full_T)
15693 Priv_Parent := Etype (Priv_T);
15695 -- The full view of a private extension may have been transformed
15696 -- into an unconstrained derived type declaration and a subtype
15697 -- declaration (see build_derived_record_type for details).
15699 if Nkind (N) = N_Subtype_Declaration then
15700 Full_Indic := Subtype_Indication (N);
15701 Full_Parent := Etype (Base_Type (Full_T));
15703 Full_Indic := Subtype_Indication (Type_Definition (N));
15704 Full_Parent := Etype (Full_T);
15707 -- Check that the parent type of the full type is a descendant of
15708 -- the ancestor subtype given in the private extension. If either
15709 -- entity has an Etype equal to Any_Type then we had some previous
15710 -- error situation [7.3(8)].
15712 if Priv_Parent = Any_Type or else Full_Parent = Any_Type then
15715 -- Ada 2005 (AI-251): Interfaces in the full-typ can be given in
15716 -- any order. Therefore we don't have to check that its parent must
15717 -- be a descendant of the parent of the private type declaration.
15719 elsif Is_Interface (Priv_Parent)
15720 and then Is_Interface (Full_Parent)
15724 -- Ada 2005 (AI-251): If the parent of the private type declaration
15725 -- is an interface there is no need to check that it is an ancestor
15726 -- of the associated full type declaration. The required tests for
15727 -- this case are performed by Build_Derived_Record_Type.
15729 elsif not Is_Interface (Base_Type (Priv_Parent))
15730 and then not Is_Ancestor (Base_Type (Priv_Parent), Full_Parent)
15733 ("parent of full type must descend from parent"
15734 & " of private extension", Full_Indic);
15736 -- Check the rules of 7.3(10): if the private extension inherits
15737 -- known discriminants, then the full type must also inherit those
15738 -- discriminants from the same (ancestor) type, and the parent
15739 -- subtype of the full type must be constrained if and only if
15740 -- the ancestor subtype of the private extension is constrained.
15742 elsif No (Discriminant_Specifications (Parent (Priv_T)))
15743 and then not Has_Unknown_Discriminants (Priv_T)
15744 and then Has_Discriminants (Base_Type (Priv_Parent))
15747 Priv_Indic : constant Node_Id :=
15748 Subtype_Indication (Parent (Priv_T));
15750 Priv_Constr : constant Boolean :=
15751 Is_Constrained (Priv_Parent)
15753 Nkind (Priv_Indic) = N_Subtype_Indication
15754 or else Is_Constrained (Entity (Priv_Indic));
15756 Full_Constr : constant Boolean :=
15757 Is_Constrained (Full_Parent)
15759 Nkind (Full_Indic) = N_Subtype_Indication
15760 or else Is_Constrained (Entity (Full_Indic));
15762 Priv_Discr : Entity_Id;
15763 Full_Discr : Entity_Id;
15766 Priv_Discr := First_Discriminant (Priv_Parent);
15767 Full_Discr := First_Discriminant (Full_Parent);
15768 while Present (Priv_Discr) and then Present (Full_Discr) loop
15769 if Original_Record_Component (Priv_Discr) =
15770 Original_Record_Component (Full_Discr)
15772 Corresponding_Discriminant (Priv_Discr) =
15773 Corresponding_Discriminant (Full_Discr)
15780 Next_Discriminant (Priv_Discr);
15781 Next_Discriminant (Full_Discr);
15784 if Present (Priv_Discr) or else Present (Full_Discr) then
15786 ("full view must inherit discriminants of the parent type"
15787 & " used in the private extension", Full_Indic);
15789 elsif Priv_Constr and then not Full_Constr then
15791 ("parent subtype of full type must be constrained",
15794 elsif Full_Constr and then not Priv_Constr then
15796 ("parent subtype of full type must be unconstrained",
15801 -- Check the rules of 7.3(12): if a partial view has neither known
15802 -- or unknown discriminants, then the full type declaration shall
15803 -- define a definite subtype.
15805 elsif not Has_Unknown_Discriminants (Priv_T)
15806 and then not Has_Discriminants (Priv_T)
15807 and then not Is_Constrained (Full_T)
15810 ("full view must define a constrained type if partial view"
15811 & " has no discriminants", Full_T);
15814 -- ??????? Do we implement the following properly ?????
15815 -- If the ancestor subtype of a private extension has constrained
15816 -- discriminants, then the parent subtype of the full view shall
15817 -- impose a statically matching constraint on those discriminants
15821 -- For untagged types, verify that a type without discriminants
15822 -- is not completed with an unconstrained type.
15824 if not Is_Indefinite_Subtype (Priv_T)
15825 and then Is_Indefinite_Subtype (Full_T)
15827 Error_Msg_N ("full view of type must be definite subtype", Full_T);
15831 -- AI-419: verify that the use of "limited" is consistent
15834 Orig_Decl : constant Node_Id := Original_Node (N);
15837 if Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15838 and then not Limited_Present (Parent (Priv_T))
15839 and then not Synchronized_Present (Parent (Priv_T))
15840 and then Nkind (Orig_Decl) = N_Full_Type_Declaration
15842 (Type_Definition (Orig_Decl)) = N_Derived_Type_Definition
15843 and then Limited_Present (Type_Definition (Orig_Decl))
15846 ("full view of non-limited extension cannot be limited", N);
15850 -- Ada 2005 (AI-443): A synchronized private extension must be
15851 -- completed by a task or protected type.
15853 if Ada_Version >= Ada_05
15854 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15855 and then Synchronized_Present (Parent (Priv_T))
15856 and then not Is_Concurrent_Type (Full_T)
15858 Error_Msg_N ("full view of synchronized extension must " &
15859 "be synchronized type", N);
15862 -- Ada 2005 AI-363: if the full view has discriminants with
15863 -- defaults, it is illegal to declare constrained access subtypes
15864 -- whose designated type is the current type. This allows objects
15865 -- of the type that are declared in the heap to be unconstrained.
15867 if not Has_Unknown_Discriminants (Priv_T)
15868 and then not Has_Discriminants (Priv_T)
15869 and then Has_Discriminants (Full_T)
15871 Present (Discriminant_Default_Value (First_Discriminant (Full_T)))
15873 Set_Has_Constrained_Partial_View (Full_T);
15874 Set_Has_Constrained_Partial_View (Priv_T);
15877 -- Create a full declaration for all its subtypes recorded in
15878 -- Private_Dependents and swap them similarly to the base type. These
15879 -- are subtypes that have been define before the full declaration of
15880 -- the private type. We also swap the entry in Private_Dependents list
15881 -- so we can properly restore the private view on exit from the scope.
15884 Priv_Elmt : Elmt_Id;
15889 Priv_Elmt := First_Elmt (Private_Dependents (Priv_T));
15890 while Present (Priv_Elmt) loop
15891 Priv := Node (Priv_Elmt);
15893 if Ekind (Priv) = E_Private_Subtype
15894 or else Ekind (Priv) = E_Limited_Private_Subtype
15895 or else Ekind (Priv) = E_Record_Subtype_With_Private
15897 Full := Make_Defining_Identifier (Sloc (Priv), Chars (Priv));
15898 Set_Is_Itype (Full);
15899 Set_Parent (Full, Parent (Priv));
15900 Set_Associated_Node_For_Itype (Full, N);
15902 -- Now we need to complete the private subtype, but since the
15903 -- base type has already been swapped, we must also swap the
15904 -- subtypes (and thus, reverse the arguments in the call to
15905 -- Complete_Private_Subtype).
15907 Copy_And_Swap (Priv, Full);
15908 Complete_Private_Subtype (Full, Priv, Full_T, N);
15909 Replace_Elmt (Priv_Elmt, Full);
15912 Next_Elmt (Priv_Elmt);
15916 -- If the private view was tagged, copy the new primitive operations
15917 -- from the private view to the full view.
15919 if Is_Tagged_Type (Full_T) then
15921 Disp_Typ : Entity_Id;
15922 Full_List : Elist_Id;
15924 Prim_Elmt : Elmt_Id;
15925 Priv_List : Elist_Id;
15929 L : Elist_Id) return Boolean;
15930 -- Determine whether list L contains element E
15938 L : Elist_Id) return Boolean
15940 List_Elmt : Elmt_Id;
15943 List_Elmt := First_Elmt (L);
15944 while Present (List_Elmt) loop
15945 if Node (List_Elmt) = E then
15949 Next_Elmt (List_Elmt);
15955 -- Start of processing
15958 if Is_Tagged_Type (Priv_T) then
15959 Priv_List := Primitive_Operations (Priv_T);
15960 Prim_Elmt := First_Elmt (Priv_List);
15962 -- In the case of a concurrent type completing a private tagged
15963 -- type, primitives may have been declared in between the two
15964 -- views. These subprograms need to be wrapped the same way
15965 -- entries and protected procedures are handled because they
15966 -- cannot be directly shared by the two views.
15968 if Is_Concurrent_Type (Full_T) then
15970 Conc_Typ : constant Entity_Id :=
15971 Corresponding_Record_Type (Full_T);
15972 Loc : constant Source_Ptr := Sloc (Conc_Typ);
15973 Curr_Nod : Node_Id := Parent (Conc_Typ);
15974 Wrap_Spec : Node_Id;
15977 while Present (Prim_Elmt) loop
15978 Prim := Node (Prim_Elmt);
15980 if Comes_From_Source (Prim)
15981 and then not Is_Abstract_Subprogram (Prim)
15984 Make_Subprogram_Declaration (Loc,
15986 Build_Wrapper_Spec (Loc,
15988 Obj_Typ => Conc_Typ,
15990 Parameter_Specifications (
15993 Insert_After (Curr_Nod, Wrap_Spec);
15994 Curr_Nod := Wrap_Spec;
15996 Analyze (Wrap_Spec);
15999 Next_Elmt (Prim_Elmt);
16005 -- For non-concurrent types, transfer explicit primitives, but
16006 -- omit those inherited from the parent of the private view
16007 -- since they will be re-inherited later on.
16010 Full_List := Primitive_Operations (Full_T);
16012 while Present (Prim_Elmt) loop
16013 Prim := Node (Prim_Elmt);
16015 if Comes_From_Source (Prim)
16016 and then not Contains (Prim, Full_List)
16018 Append_Elmt (Prim, Full_List);
16021 Next_Elmt (Prim_Elmt);
16025 -- Untagged private view
16028 Full_List := Primitive_Operations (Full_T);
16030 -- In this case the partial view is untagged, so here we locate
16031 -- all of the earlier primitives that need to be treated as
16032 -- dispatching (those that appear between the two views). Note
16033 -- that these additional operations must all be new operations
16034 -- (any earlier operations that override inherited operations
16035 -- of the full view will already have been inserted in the
16036 -- primitives list, marked by Check_Operation_From_Private_View
16037 -- as dispatching. Note that implicit "/=" operators are
16038 -- excluded from being added to the primitives list since they
16039 -- shouldn't be treated as dispatching (tagged "/=" is handled
16042 Prim := Next_Entity (Full_T);
16043 while Present (Prim) and then Prim /= Priv_T loop
16044 if Ekind (Prim) = E_Procedure
16046 Ekind (Prim) = E_Function
16048 Disp_Typ := Find_Dispatching_Type (Prim);
16050 if Disp_Typ = Full_T
16051 and then (Chars (Prim) /= Name_Op_Ne
16052 or else Comes_From_Source (Prim))
16054 Check_Controlling_Formals (Full_T, Prim);
16056 if not Is_Dispatching_Operation (Prim) then
16057 Append_Elmt (Prim, Full_List);
16058 Set_Is_Dispatching_Operation (Prim, True);
16059 Set_DT_Position (Prim, No_Uint);
16062 elsif Is_Dispatching_Operation (Prim)
16063 and then Disp_Typ /= Full_T
16066 -- Verify that it is not otherwise controlled by a
16067 -- formal or a return value of type T.
16069 Check_Controlling_Formals (Disp_Typ, Prim);
16073 Next_Entity (Prim);
16077 -- For the tagged case, the two views can share the same
16078 -- Primitive Operation list and the same class wide type.
16079 -- Update attributes of the class-wide type which depend on
16080 -- the full declaration.
16082 if Is_Tagged_Type (Priv_T) then
16083 Set_Primitive_Operations (Priv_T, Full_List);
16084 Set_Class_Wide_Type
16085 (Base_Type (Full_T), Class_Wide_Type (Priv_T));
16087 Set_Has_Task (Class_Wide_Type (Priv_T), Has_Task (Full_T));
16092 -- Ada 2005 AI 161: Check preelaboratable initialization consistency
16094 if Known_To_Have_Preelab_Init (Priv_T) then
16096 -- Case where there is a pragma Preelaborable_Initialization. We
16097 -- always allow this in predefined units, which is a bit of a kludge,
16098 -- but it means we don't have to struggle to meet the requirements in
16099 -- the RM for having Preelaborable Initialization. Otherwise we
16100 -- require that the type meets the RM rules. But we can't check that
16101 -- yet, because of the rule about overriding Ininitialize, so we
16102 -- simply set a flag that will be checked at freeze time.
16104 if not In_Predefined_Unit (Full_T) then
16105 Set_Must_Have_Preelab_Init (Full_T);
16109 -- If pragma CPP_Class was applied to the private type declaration,
16110 -- propagate it now to the full type declaration.
16112 if Is_CPP_Class (Priv_T) then
16113 Set_Is_CPP_Class (Full_T);
16114 Set_Convention (Full_T, Convention_CPP);
16116 end Process_Full_View;
16118 -----------------------------------
16119 -- Process_Incomplete_Dependents --
16120 -----------------------------------
16122 procedure Process_Incomplete_Dependents
16124 Full_T : Entity_Id;
16127 Inc_Elmt : Elmt_Id;
16128 Priv_Dep : Entity_Id;
16129 New_Subt : Entity_Id;
16131 Disc_Constraint : Elist_Id;
16134 if No (Private_Dependents (Inc_T)) then
16138 -- Itypes that may be generated by the completion of an incomplete
16139 -- subtype are not used by the back-end and not attached to the tree.
16140 -- They are created only for constraint-checking purposes.
16142 Inc_Elmt := First_Elmt (Private_Dependents (Inc_T));
16143 while Present (Inc_Elmt) loop
16144 Priv_Dep := Node (Inc_Elmt);
16146 if Ekind (Priv_Dep) = E_Subprogram_Type then
16148 -- An Access_To_Subprogram type may have a return type or a
16149 -- parameter type that is incomplete. Replace with the full view.
16151 if Etype (Priv_Dep) = Inc_T then
16152 Set_Etype (Priv_Dep, Full_T);
16156 Formal : Entity_Id;
16159 Formal := First_Formal (Priv_Dep);
16160 while Present (Formal) loop
16161 if Etype (Formal) = Inc_T then
16162 Set_Etype (Formal, Full_T);
16165 Next_Formal (Formal);
16169 elsif Is_Overloadable (Priv_Dep) then
16171 -- A protected operation is never dispatching: only its
16172 -- wrapper operation (which has convention Ada) is.
16174 if Is_Tagged_Type (Full_T)
16175 and then Convention (Priv_Dep) /= Convention_Protected
16178 -- Subprogram has an access parameter whose designated type
16179 -- was incomplete. Reexamine declaration now, because it may
16180 -- be a primitive operation of the full type.
16182 Check_Operation_From_Incomplete_Type (Priv_Dep, Inc_T);
16183 Set_Is_Dispatching_Operation (Priv_Dep);
16184 Check_Controlling_Formals (Full_T, Priv_Dep);
16187 elsif Ekind (Priv_Dep) = E_Subprogram_Body then
16189 -- Can happen during processing of a body before the completion
16190 -- of a TA type. Ignore, because spec is also on dependent list.
16194 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
16195 -- corresponding subtype of the full view.
16197 elsif Ekind (Priv_Dep) = E_Incomplete_Subtype then
16198 Set_Subtype_Indication
16199 (Parent (Priv_Dep), New_Reference_To (Full_T, Sloc (Priv_Dep)));
16200 Set_Etype (Priv_Dep, Full_T);
16201 Set_Ekind (Priv_Dep, Subtype_Kind (Ekind (Full_T)));
16202 Set_Analyzed (Parent (Priv_Dep), False);
16204 -- Reanalyze the declaration, suppressing the call to
16205 -- Enter_Name to avoid duplicate names.
16207 Analyze_Subtype_Declaration
16208 (N => Parent (Priv_Dep),
16211 -- Dependent is a subtype
16214 -- We build a new subtype indication using the full view of the
16215 -- incomplete parent. The discriminant constraints have been
16216 -- elaborated already at the point of the subtype declaration.
16218 New_Subt := Create_Itype (E_Void, N);
16220 if Has_Discriminants (Full_T) then
16221 Disc_Constraint := Discriminant_Constraint (Priv_Dep);
16223 Disc_Constraint := No_Elist;
16226 Build_Discriminated_Subtype (Full_T, New_Subt, Disc_Constraint, N);
16227 Set_Full_View (Priv_Dep, New_Subt);
16230 Next_Elmt (Inc_Elmt);
16232 end Process_Incomplete_Dependents;
16234 --------------------------------
16235 -- Process_Range_Expr_In_Decl --
16236 --------------------------------
16238 procedure Process_Range_Expr_In_Decl
16241 Check_List : List_Id := Empty_List;
16242 R_Check_Off : Boolean := False)
16245 R_Checks : Check_Result;
16246 Type_Decl : Node_Id;
16247 Def_Id : Entity_Id;
16250 Analyze_And_Resolve (R, Base_Type (T));
16252 if Nkind (R) = N_Range then
16253 Lo := Low_Bound (R);
16254 Hi := High_Bound (R);
16256 -- We need to ensure validity of the bounds here, because if we
16257 -- go ahead and do the expansion, then the expanded code will get
16258 -- analyzed with range checks suppressed and we miss the check.
16260 Validity_Check_Range (R);
16262 -- If there were errors in the declaration, try and patch up some
16263 -- common mistakes in the bounds. The cases handled are literals
16264 -- which are Integer where the expected type is Real and vice versa.
16265 -- These corrections allow the compilation process to proceed further
16266 -- along since some basic assumptions of the format of the bounds
16269 if Etype (R) = Any_Type then
16271 if Nkind (Lo) = N_Integer_Literal and then Is_Real_Type (T) then
16273 Make_Real_Literal (Sloc (Lo), UR_From_Uint (Intval (Lo))));
16275 elsif Nkind (Hi) = N_Integer_Literal and then Is_Real_Type (T) then
16277 Make_Real_Literal (Sloc (Hi), UR_From_Uint (Intval (Hi))));
16279 elsif Nkind (Lo) = N_Real_Literal and then Is_Integer_Type (T) then
16281 Make_Integer_Literal (Sloc (Lo), UR_To_Uint (Realval (Lo))));
16283 elsif Nkind (Hi) = N_Real_Literal and then Is_Integer_Type (T) then
16285 Make_Integer_Literal (Sloc (Hi), UR_To_Uint (Realval (Hi))));
16292 -- If the bounds of the range have been mistakenly given as string
16293 -- literals (perhaps in place of character literals), then an error
16294 -- has already been reported, but we rewrite the string literal as a
16295 -- bound of the range's type to avoid blowups in later processing
16296 -- that looks at static values.
16298 if Nkind (Lo) = N_String_Literal then
16300 Make_Attribute_Reference (Sloc (Lo),
16301 Attribute_Name => Name_First,
16302 Prefix => New_Reference_To (T, Sloc (Lo))));
16303 Analyze_And_Resolve (Lo);
16306 if Nkind (Hi) = N_String_Literal then
16308 Make_Attribute_Reference (Sloc (Hi),
16309 Attribute_Name => Name_First,
16310 Prefix => New_Reference_To (T, Sloc (Hi))));
16311 Analyze_And_Resolve (Hi);
16314 -- If bounds aren't scalar at this point then exit, avoiding
16315 -- problems with further processing of the range in this procedure.
16317 if not Is_Scalar_Type (Etype (Lo)) then
16321 -- Resolve (actually Sem_Eval) has checked that the bounds are in
16322 -- then range of the base type. Here we check whether the bounds
16323 -- are in the range of the subtype itself. Note that if the bounds
16324 -- represent the null range the Constraint_Error exception should
16327 -- ??? The following code should be cleaned up as follows
16329 -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
16330 -- is done in the call to Range_Check (R, T); below
16332 -- 2. The use of R_Check_Off should be investigated and possibly
16333 -- removed, this would clean up things a bit.
16335 if Is_Null_Range (Lo, Hi) then
16339 -- Capture values of bounds and generate temporaries for them
16340 -- if needed, before applying checks, since checks may cause
16341 -- duplication of the expression without forcing evaluation.
16343 if Expander_Active then
16344 Force_Evaluation (Lo);
16345 Force_Evaluation (Hi);
16348 -- We use a flag here instead of suppressing checks on the
16349 -- type because the type we check against isn't necessarily
16350 -- the place where we put the check.
16352 if not R_Check_Off then
16353 R_Checks := Get_Range_Checks (R, T);
16355 -- Look up tree to find an appropriate insertion point.
16356 -- This seems really junk code, and very brittle, couldn't
16357 -- we just use an insert actions call of some kind ???
16359 Type_Decl := Parent (R);
16360 while Present (Type_Decl) and then not
16361 (Nkind_In (Type_Decl, N_Full_Type_Declaration,
16362 N_Subtype_Declaration,
16364 N_Task_Type_Declaration)
16366 Nkind_In (Type_Decl, N_Single_Task_Declaration,
16367 N_Protected_Type_Declaration,
16368 N_Single_Protected_Declaration))
16370 Type_Decl := Parent (Type_Decl);
16373 -- Why would Type_Decl not be present??? Without this test,
16374 -- short regression tests fail.
16376 if Present (Type_Decl) then
16378 -- Case of loop statement (more comments ???)
16380 if Nkind (Type_Decl) = N_Loop_Statement then
16385 Indic := Parent (R);
16386 while Present (Indic)
16387 and then Nkind (Indic) /= N_Subtype_Indication
16389 Indic := Parent (Indic);
16392 if Present (Indic) then
16393 Def_Id := Etype (Subtype_Mark (Indic));
16395 Insert_Range_Checks
16401 Do_Before => True);
16405 -- All other cases (more comments ???)
16408 Def_Id := Defining_Identifier (Type_Decl);
16410 if (Ekind (Def_Id) = E_Record_Type
16411 and then Depends_On_Discriminant (R))
16413 (Ekind (Def_Id) = E_Protected_Type
16414 and then Has_Discriminants (Def_Id))
16416 Append_Range_Checks
16417 (R_Checks, Check_List, Def_Id, Sloc (Type_Decl), R);
16420 Insert_Range_Checks
16421 (R_Checks, Type_Decl, Def_Id, Sloc (Type_Decl), R);
16429 elsif Expander_Active then
16430 Get_Index_Bounds (R, Lo, Hi);
16431 Force_Evaluation (Lo);
16432 Force_Evaluation (Hi);
16434 end Process_Range_Expr_In_Decl;
16436 --------------------------------------
16437 -- Process_Real_Range_Specification --
16438 --------------------------------------
16440 procedure Process_Real_Range_Specification (Def : Node_Id) is
16441 Spec : constant Node_Id := Real_Range_Specification (Def);
16444 Err : Boolean := False;
16446 procedure Analyze_Bound (N : Node_Id);
16447 -- Analyze and check one bound
16449 -------------------
16450 -- Analyze_Bound --
16451 -------------------
16453 procedure Analyze_Bound (N : Node_Id) is
16455 Analyze_And_Resolve (N, Any_Real);
16457 if not Is_OK_Static_Expression (N) then
16458 Flag_Non_Static_Expr
16459 ("bound in real type definition is not static!", N);
16464 -- Start of processing for Process_Real_Range_Specification
16467 if Present (Spec) then
16468 Lo := Low_Bound (Spec);
16469 Hi := High_Bound (Spec);
16470 Analyze_Bound (Lo);
16471 Analyze_Bound (Hi);
16473 -- If error, clear away junk range specification
16476 Set_Real_Range_Specification (Def, Empty);
16479 end Process_Real_Range_Specification;
16481 ---------------------
16482 -- Process_Subtype --
16483 ---------------------
16485 function Process_Subtype
16487 Related_Nod : Node_Id;
16488 Related_Id : Entity_Id := Empty;
16489 Suffix : Character := ' ') return Entity_Id
16492 Def_Id : Entity_Id;
16493 Error_Node : Node_Id;
16494 Full_View_Id : Entity_Id;
16495 Subtype_Mark_Id : Entity_Id;
16497 May_Have_Null_Exclusion : Boolean;
16499 procedure Check_Incomplete (T : Entity_Id);
16500 -- Called to verify that an incomplete type is not used prematurely
16502 ----------------------
16503 -- Check_Incomplete --
16504 ----------------------
16506 procedure Check_Incomplete (T : Entity_Id) is
16508 -- Ada 2005 (AI-412): Incomplete subtypes are legal
16510 if Ekind (Root_Type (Entity (T))) = E_Incomplete_Type
16512 not (Ada_Version >= Ada_05
16514 (Nkind (Parent (T)) = N_Subtype_Declaration
16516 (Nkind (Parent (T)) = N_Subtype_Indication
16517 and then Nkind (Parent (Parent (T))) =
16518 N_Subtype_Declaration)))
16520 Error_Msg_N ("invalid use of type before its full declaration", T);
16522 end Check_Incomplete;
16524 -- Start of processing for Process_Subtype
16527 -- Case of no constraints present
16529 if Nkind (S) /= N_Subtype_Indication then
16531 Check_Incomplete (S);
16534 -- Ada 2005 (AI-231): Static check
16536 if Ada_Version >= Ada_05
16537 and then Present (P)
16538 and then Null_Exclusion_Present (P)
16539 and then Nkind (P) /= N_Access_To_Object_Definition
16540 and then not Is_Access_Type (Entity (S))
16542 Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
16545 -- The following is ugly, can't we have a range or even a flag???
16547 May_Have_Null_Exclusion :=
16548 Nkind_In (P, N_Access_Definition,
16549 N_Access_Function_Definition,
16550 N_Access_Procedure_Definition,
16551 N_Access_To_Object_Definition,
16553 N_Component_Definition)
16555 Nkind_In (P, N_Derived_Type_Definition,
16556 N_Discriminant_Specification,
16557 N_Formal_Object_Declaration,
16558 N_Object_Declaration,
16559 N_Object_Renaming_Declaration,
16560 N_Parameter_Specification,
16561 N_Subtype_Declaration);
16563 -- Create an Itype that is a duplicate of Entity (S) but with the
16564 -- null-exclusion attribute
16566 if May_Have_Null_Exclusion
16567 and then Is_Access_Type (Entity (S))
16568 and then Null_Exclusion_Present (P)
16570 -- No need to check the case of an access to object definition.
16571 -- It is correct to define double not-null pointers.
16574 -- type Not_Null_Int_Ptr is not null access Integer;
16575 -- type Acc is not null access Not_Null_Int_Ptr;
16577 and then Nkind (P) /= N_Access_To_Object_Definition
16579 if Can_Never_Be_Null (Entity (S)) then
16580 case Nkind (Related_Nod) is
16581 when N_Full_Type_Declaration =>
16582 if Nkind (Type_Definition (Related_Nod))
16583 in N_Array_Type_Definition
16587 (Component_Definition
16588 (Type_Definition (Related_Nod)));
16591 Subtype_Indication (Type_Definition (Related_Nod));
16594 when N_Subtype_Declaration =>
16595 Error_Node := Subtype_Indication (Related_Nod);
16597 when N_Object_Declaration =>
16598 Error_Node := Object_Definition (Related_Nod);
16600 when N_Component_Declaration =>
16602 Subtype_Indication (Component_Definition (Related_Nod));
16604 when N_Allocator =>
16605 Error_Node := Expression (Related_Nod);
16608 pragma Assert (False);
16609 Error_Node := Related_Nod;
16613 ("`NOT NULL` not allowed (& already excludes null)",
16619 Create_Null_Excluding_Itype
16621 Related_Nod => P));
16622 Set_Entity (S, Etype (S));
16627 -- Case of constraint present, so that we have an N_Subtype_Indication
16628 -- node (this node is created only if constraints are present).
16631 Find_Type (Subtype_Mark (S));
16633 if Nkind (Parent (S)) /= N_Access_To_Object_Definition
16635 (Nkind (Parent (S)) = N_Subtype_Declaration
16636 and then Is_Itype (Defining_Identifier (Parent (S))))
16638 Check_Incomplete (Subtype_Mark (S));
16642 Subtype_Mark_Id := Entity (Subtype_Mark (S));
16644 -- Explicit subtype declaration case
16646 if Nkind (P) = N_Subtype_Declaration then
16647 Def_Id := Defining_Identifier (P);
16649 -- Explicit derived type definition case
16651 elsif Nkind (P) = N_Derived_Type_Definition then
16652 Def_Id := Defining_Identifier (Parent (P));
16654 -- Implicit case, the Def_Id must be created as an implicit type.
16655 -- The one exception arises in the case of concurrent types, array
16656 -- and access types, where other subsidiary implicit types may be
16657 -- created and must appear before the main implicit type. In these
16658 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
16659 -- has not yet been called to create Def_Id.
16662 if Is_Array_Type (Subtype_Mark_Id)
16663 or else Is_Concurrent_Type (Subtype_Mark_Id)
16664 or else Is_Access_Type (Subtype_Mark_Id)
16668 -- For the other cases, we create a new unattached Itype,
16669 -- and set the indication to ensure it gets attached later.
16673 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16677 -- If the kind of constraint is invalid for this kind of type,
16678 -- then give an error, and then pretend no constraint was given.
16680 if not Is_Valid_Constraint_Kind
16681 (Ekind (Subtype_Mark_Id), Nkind (Constraint (S)))
16684 ("incorrect constraint for this kind of type", Constraint (S));
16686 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
16688 -- Set Ekind of orphan itype, to prevent cascaded errors
16690 if Present (Def_Id) then
16691 Set_Ekind (Def_Id, Ekind (Any_Type));
16694 -- Make recursive call, having got rid of the bogus constraint
16696 return Process_Subtype (S, Related_Nod, Related_Id, Suffix);
16699 -- Remaining processing depends on type
16701 case Ekind (Subtype_Mark_Id) is
16702 when Access_Kind =>
16703 Constrain_Access (Def_Id, S, Related_Nod);
16706 and then Is_Itype (Designated_Type (Def_Id))
16707 and then Nkind (Related_Nod) = N_Subtype_Declaration
16708 and then not Is_Incomplete_Type (Designated_Type (Def_Id))
16710 Build_Itype_Reference
16711 (Designated_Type (Def_Id), Related_Nod);
16715 Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix);
16717 when Decimal_Fixed_Point_Kind =>
16718 Constrain_Decimal (Def_Id, S);
16720 when Enumeration_Kind =>
16721 Constrain_Enumeration (Def_Id, S);
16723 when Ordinary_Fixed_Point_Kind =>
16724 Constrain_Ordinary_Fixed (Def_Id, S);
16727 Constrain_Float (Def_Id, S);
16729 when Integer_Kind =>
16730 Constrain_Integer (Def_Id, S);
16732 when E_Record_Type |
16735 E_Incomplete_Type =>
16736 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16738 when Private_Kind =>
16739 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16740 Set_Private_Dependents (Def_Id, New_Elmt_List);
16742 -- In case of an invalid constraint prevent further processing
16743 -- since the type constructed is missing expected fields.
16745 if Etype (Def_Id) = Any_Type then
16749 -- If the full view is that of a task with discriminants,
16750 -- we must constrain both the concurrent type and its
16751 -- corresponding record type. Otherwise we will just propagate
16752 -- the constraint to the full view, if available.
16754 if Present (Full_View (Subtype_Mark_Id))
16755 and then Has_Discriminants (Subtype_Mark_Id)
16756 and then Is_Concurrent_Type (Full_View (Subtype_Mark_Id))
16759 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16761 Set_Entity (Subtype_Mark (S), Full_View (Subtype_Mark_Id));
16762 Constrain_Concurrent (Full_View_Id, S,
16763 Related_Nod, Related_Id, Suffix);
16764 Set_Entity (Subtype_Mark (S), Subtype_Mark_Id);
16765 Set_Full_View (Def_Id, Full_View_Id);
16767 -- Introduce an explicit reference to the private subtype,
16768 -- to prevent scope anomalies in gigi if first use appears
16769 -- in a nested context, e.g. a later function body.
16770 -- Should this be generated in other contexts than a full
16771 -- type declaration?
16773 if Is_Itype (Def_Id)
16775 Nkind (Parent (P)) = N_Full_Type_Declaration
16777 Build_Itype_Reference (Def_Id, Parent (P));
16781 Prepare_Private_Subtype_Completion (Def_Id, Related_Nod);
16784 when Concurrent_Kind =>
16785 Constrain_Concurrent (Def_Id, S,
16786 Related_Nod, Related_Id, Suffix);
16789 Error_Msg_N ("invalid subtype mark in subtype indication", S);
16792 -- Size and Convention are always inherited from the base type
16794 Set_Size_Info (Def_Id, (Subtype_Mark_Id));
16795 Set_Convention (Def_Id, Convention (Subtype_Mark_Id));
16799 end Process_Subtype;
16801 ---------------------------------------
16802 -- Check_Anonymous_Access_Components --
16803 ---------------------------------------
16805 procedure Check_Anonymous_Access_Components
16806 (Typ_Decl : Node_Id;
16809 Comp_List : Node_Id)
16811 Loc : constant Source_Ptr := Sloc (Typ_Decl);
16812 Anon_Access : Entity_Id;
16815 Comp_Def : Node_Id;
16817 Type_Def : Node_Id;
16819 procedure Build_Incomplete_Type_Declaration;
16820 -- If the record type contains components that include an access to the
16821 -- current record, then create an incomplete type declaration for the
16822 -- record, to be used as the designated type of the anonymous access.
16823 -- This is done only once, and only if there is no previous partial
16824 -- view of the type.
16826 function Designates_T (Subt : Node_Id) return Boolean;
16827 -- Check whether a node designates the enclosing record type, or 'Class
16830 function Mentions_T (Acc_Def : Node_Id) return Boolean;
16831 -- Check whether an access definition includes a reference to
16832 -- the enclosing record type. The reference can be a subtype mark
16833 -- in the access definition itself, a 'Class attribute reference, or
16834 -- recursively a reference appearing in a parameter specification
16835 -- or result definition of an access_to_subprogram definition.
16837 --------------------------------------
16838 -- Build_Incomplete_Type_Declaration --
16839 --------------------------------------
16841 procedure Build_Incomplete_Type_Declaration is
16846 -- Is_Tagged indicates whether the type is tagged. It is tagged if
16847 -- it's "is new ... with record" or else "is tagged record ...".
16849 Is_Tagged : constant Boolean :=
16850 (Nkind (Type_Definition (Typ_Decl)) = N_Derived_Type_Definition
16853 (Record_Extension_Part (Type_Definition (Typ_Decl))))
16855 (Nkind (Type_Definition (Typ_Decl)) = N_Record_Definition
16856 and then Tagged_Present (Type_Definition (Typ_Decl)));
16859 -- If there is a previous partial view, no need to create a new one
16860 -- If the partial view, given by Prev, is incomplete, If Prev is
16861 -- a private declaration, full declaration is flagged accordingly.
16863 if Prev /= Typ then
16865 Make_Class_Wide_Type (Prev);
16866 Set_Class_Wide_Type (Typ, Class_Wide_Type (Prev));
16867 Set_Etype (Class_Wide_Type (Typ), Typ);
16872 elsif Has_Private_Declaration (Typ) then
16874 -- If we refer to T'Class inside T, and T is the completion of a
16875 -- private type, then we need to make sure the class-wide type
16879 Make_Class_Wide_Type (Typ);
16884 -- If there was a previous anonymous access type, the incomplete
16885 -- type declaration will have been created already.
16887 elsif Present (Current_Entity (Typ))
16888 and then Ekind (Current_Entity (Typ)) = E_Incomplete_Type
16889 and then Full_View (Current_Entity (Typ)) = Typ
16894 Inc_T := Make_Defining_Identifier (Loc, Chars (Typ));
16895 Decl := Make_Incomplete_Type_Declaration (Loc, Inc_T);
16897 -- Type has already been inserted into the current scope.
16898 -- Remove it, and add incomplete declaration for type, so
16899 -- that subsequent anonymous access types can use it.
16900 -- The entity is unchained from the homonym list and from
16901 -- immediate visibility. After analysis, the entity in the
16902 -- incomplete declaration becomes immediately visible in the
16903 -- record declaration that follows.
16905 H := Current_Entity (Typ);
16908 Set_Name_Entity_Id (Chars (Typ), Homonym (Typ));
16911 and then Homonym (H) /= Typ
16913 H := Homonym (Typ);
16916 Set_Homonym (H, Homonym (Typ));
16919 Insert_Before (Typ_Decl, Decl);
16921 Set_Full_View (Inc_T, Typ);
16924 -- Create a common class-wide type for both views, and set
16925 -- the Etype of the class-wide type to the full view.
16927 Make_Class_Wide_Type (Inc_T);
16928 Set_Class_Wide_Type (Typ, Class_Wide_Type (Inc_T));
16929 Set_Etype (Class_Wide_Type (Typ), Typ);
16932 end Build_Incomplete_Type_Declaration;
16938 function Designates_T (Subt : Node_Id) return Boolean is
16939 Type_Id : constant Name_Id := Chars (Typ);
16941 function Names_T (Nam : Node_Id) return Boolean;
16942 -- The record type has not been introduced in the current scope
16943 -- yet, so we must examine the name of the type itself, either
16944 -- an identifier T, or an expanded name of the form P.T, where
16945 -- P denotes the current scope.
16951 function Names_T (Nam : Node_Id) return Boolean is
16953 if Nkind (Nam) = N_Identifier then
16954 return Chars (Nam) = Type_Id;
16956 elsif Nkind (Nam) = N_Selected_Component then
16957 if Chars (Selector_Name (Nam)) = Type_Id then
16958 if Nkind (Prefix (Nam)) = N_Identifier then
16959 return Chars (Prefix (Nam)) = Chars (Current_Scope);
16961 elsif Nkind (Prefix (Nam)) = N_Selected_Component then
16962 return Chars (Selector_Name (Prefix (Nam))) =
16963 Chars (Current_Scope);
16977 -- Start of processing for Designates_T
16980 if Nkind (Subt) = N_Identifier then
16981 return Chars (Subt) = Type_Id;
16983 -- Reference can be through an expanded name which has not been
16984 -- analyzed yet, and which designates enclosing scopes.
16986 elsif Nkind (Subt) = N_Selected_Component then
16987 if Names_T (Subt) then
16990 -- Otherwise it must denote an entity that is already visible.
16991 -- The access definition may name a subtype of the enclosing
16992 -- type, if there is a previous incomplete declaration for it.
16995 Find_Selected_Component (Subt);
16997 Is_Entity_Name (Subt)
16998 and then Scope (Entity (Subt)) = Current_Scope
17000 (Chars (Base_Type (Entity (Subt))) = Type_Id
17002 (Is_Class_Wide_Type (Entity (Subt))
17004 Chars (Etype (Base_Type (Entity (Subt)))) =
17008 -- A reference to the current type may appear as the prefix of
17009 -- a 'Class attribute.
17011 elsif Nkind (Subt) = N_Attribute_Reference
17012 and then Attribute_Name (Subt) = Name_Class
17014 return Names_T (Prefix (Subt));
17025 function Mentions_T (Acc_Def : Node_Id) return Boolean is
17026 Param_Spec : Node_Id;
17028 Acc_Subprg : constant Node_Id :=
17029 Access_To_Subprogram_Definition (Acc_Def);
17032 if No (Acc_Subprg) then
17033 return Designates_T (Subtype_Mark (Acc_Def));
17036 -- Component is an access_to_subprogram: examine its formals,
17037 -- and result definition in the case of an access_to_function.
17039 Param_Spec := First (Parameter_Specifications (Acc_Subprg));
17040 while Present (Param_Spec) loop
17041 if Nkind (Parameter_Type (Param_Spec)) = N_Access_Definition
17042 and then Mentions_T (Parameter_Type (Param_Spec))
17046 elsif Designates_T (Parameter_Type (Param_Spec)) then
17053 if Nkind (Acc_Subprg) = N_Access_Function_Definition then
17054 if Nkind (Result_Definition (Acc_Subprg)) =
17055 N_Access_Definition
17057 return Mentions_T (Result_Definition (Acc_Subprg));
17059 return Designates_T (Result_Definition (Acc_Subprg));
17066 -- Start of processing for Check_Anonymous_Access_Components
17069 if No (Comp_List) then
17073 Comp := First (Component_Items (Comp_List));
17074 while Present (Comp) loop
17075 if Nkind (Comp) = N_Component_Declaration
17077 (Access_Definition (Component_Definition (Comp)))
17079 Mentions_T (Access_Definition (Component_Definition (Comp)))
17081 Comp_Def := Component_Definition (Comp);
17083 Access_To_Subprogram_Definition
17084 (Access_Definition (Comp_Def));
17086 Build_Incomplete_Type_Declaration;
17088 Make_Defining_Identifier (Loc,
17089 Chars => New_Internal_Name ('S'));
17091 -- Create a declaration for the anonymous access type: either
17092 -- an access_to_object or an access_to_subprogram.
17094 if Present (Acc_Def) then
17095 if Nkind (Acc_Def) = N_Access_Function_Definition then
17097 Make_Access_Function_Definition (Loc,
17098 Parameter_Specifications =>
17099 Parameter_Specifications (Acc_Def),
17100 Result_Definition => Result_Definition (Acc_Def));
17103 Make_Access_Procedure_Definition (Loc,
17104 Parameter_Specifications =>
17105 Parameter_Specifications (Acc_Def));
17110 Make_Access_To_Object_Definition (Loc,
17111 Subtype_Indication =>
17114 (Access_Definition (Comp_Def))));
17116 Set_Constant_Present
17117 (Type_Def, Constant_Present (Access_Definition (Comp_Def)));
17119 (Type_Def, All_Present (Access_Definition (Comp_Def)));
17122 Set_Null_Exclusion_Present
17124 Null_Exclusion_Present (Access_Definition (Comp_Def)));
17127 Make_Full_Type_Declaration (Loc,
17128 Defining_Identifier => Anon_Access,
17129 Type_Definition => Type_Def);
17131 Insert_Before (Typ_Decl, Decl);
17134 -- If an access to object, Preserve entity of designated type,
17135 -- for ASIS use, before rewriting the component definition.
17137 if No (Acc_Def) then
17142 Desig := Entity (Subtype_Indication (Type_Def));
17144 -- If the access definition is to the current record,
17145 -- the visible entity at this point is an incomplete
17146 -- type. Retrieve the full view to simplify ASIS queries
17148 if Ekind (Desig) = E_Incomplete_Type then
17149 Desig := Full_View (Desig);
17153 (Subtype_Mark (Access_Definition (Comp_Def)), Desig);
17158 Make_Component_Definition (Loc,
17159 Subtype_Indication =>
17160 New_Occurrence_Of (Anon_Access, Loc)));
17162 if Ekind (Designated_Type (Anon_Access)) = E_Subprogram_Type then
17163 Set_Ekind (Anon_Access, E_Anonymous_Access_Subprogram_Type);
17165 Set_Ekind (Anon_Access, E_Anonymous_Access_Type);
17168 Set_Is_Local_Anonymous_Access (Anon_Access);
17174 if Present (Variant_Part (Comp_List)) then
17178 V := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
17179 while Present (V) loop
17180 Check_Anonymous_Access_Components
17181 (Typ_Decl, Typ, Prev, Component_List (V));
17182 Next_Non_Pragma (V);
17186 end Check_Anonymous_Access_Components;
17188 --------------------------------
17189 -- Preanalyze_Spec_Expression --
17190 --------------------------------
17192 procedure Preanalyze_Spec_Expression (N : Node_Id; T : Entity_Id) is
17193 Save_In_Spec_Expression : constant Boolean := In_Spec_Expression;
17195 In_Spec_Expression := True;
17196 Preanalyze_And_Resolve (N, T);
17197 In_Spec_Expression := Save_In_Spec_Expression;
17198 end Preanalyze_Spec_Expression;
17200 -----------------------------
17201 -- Record_Type_Declaration --
17202 -----------------------------
17204 procedure Record_Type_Declaration
17209 Def : constant Node_Id := Type_Definition (N);
17210 Is_Tagged : Boolean;
17211 Tag_Comp : Entity_Id;
17214 -- These flags must be initialized before calling Process_Discriminants
17215 -- because this routine makes use of them.
17217 Set_Ekind (T, E_Record_Type);
17219 Init_Size_Align (T);
17220 Set_Interfaces (T, No_Elist);
17221 Set_Stored_Constraint (T, No_Elist);
17225 if Ada_Version < Ada_05
17226 or else not Interface_Present (Def)
17228 -- The flag Is_Tagged_Type might have already been set by
17229 -- Find_Type_Name if it detected an error for declaration T. This
17230 -- arises in the case of private tagged types where the full view
17231 -- omits the word tagged.
17234 Tagged_Present (Def)
17235 or else (Serious_Errors_Detected > 0 and then Is_Tagged_Type (T));
17237 Set_Is_Tagged_Type (T, Is_Tagged);
17238 Set_Is_Limited_Record (T, Limited_Present (Def));
17240 -- Type is abstract if full declaration carries keyword, or if
17241 -- previous partial view did.
17243 Set_Is_Abstract_Type (T, Is_Abstract_Type (T)
17244 or else Abstract_Present (Def));
17248 Analyze_Interface_Declaration (T, Def);
17250 if Present (Discriminant_Specifications (N)) then
17252 ("interface types cannot have discriminants",
17253 Defining_Identifier
17254 (First (Discriminant_Specifications (N))));
17258 -- First pass: if there are self-referential access components,
17259 -- create the required anonymous access type declarations, and if
17260 -- need be an incomplete type declaration for T itself.
17262 Check_Anonymous_Access_Components (N, T, Prev, Component_List (Def));
17264 if Ada_Version >= Ada_05
17265 and then Present (Interface_List (Def))
17267 Check_Interfaces (N, Def);
17270 Ifaces_List : Elist_Id;
17273 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
17274 -- already in the parents.
17278 Ifaces_List => Ifaces_List,
17279 Exclude_Parents => True);
17281 Set_Interfaces (T, Ifaces_List);
17285 -- Records constitute a scope for the component declarations within.
17286 -- The scope is created prior to the processing of these declarations.
17287 -- Discriminants are processed first, so that they are visible when
17288 -- processing the other components. The Ekind of the record type itself
17289 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
17291 -- Enter record scope
17295 -- If an incomplete or private type declaration was already given for
17296 -- the type, then this scope already exists, and the discriminants have
17297 -- been declared within. We must verify that the full declaration
17298 -- matches the incomplete one.
17300 Check_Or_Process_Discriminants (N, T, Prev);
17302 Set_Is_Constrained (T, not Has_Discriminants (T));
17303 Set_Has_Delayed_Freeze (T, True);
17305 -- For tagged types add a manually analyzed component corresponding
17306 -- to the component _tag, the corresponding piece of tree will be
17307 -- expanded as part of the freezing actions if it is not a CPP_Class.
17311 -- Do not add the tag unless we are in expansion mode
17313 if Expander_Active then
17314 Tag_Comp := Make_Defining_Identifier (Sloc (Def), Name_uTag);
17315 Enter_Name (Tag_Comp);
17317 Set_Ekind (Tag_Comp, E_Component);
17318 Set_Is_Tag (Tag_Comp);
17319 Set_Is_Aliased (Tag_Comp);
17320 Set_Etype (Tag_Comp, RTE (RE_Tag));
17321 Set_DT_Entry_Count (Tag_Comp, No_Uint);
17322 Set_Original_Record_Component (Tag_Comp, Tag_Comp);
17323 Init_Component_Location (Tag_Comp);
17325 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
17326 -- implemented interfaces.
17328 if Has_Interfaces (T) then
17329 Add_Interface_Tag_Components (N, T);
17333 Make_Class_Wide_Type (T);
17334 Set_Primitive_Operations (T, New_Elmt_List);
17337 -- We must suppress range checks when processing the components
17338 -- of a record in the presence of discriminants, since we don't
17339 -- want spurious checks to be generated during their analysis, but
17340 -- must reset the Suppress_Range_Checks flags after having processed
17341 -- the record definition.
17343 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
17344 -- couldn't we just use the normal range check suppression method here.
17345 -- That would seem cleaner ???
17347 if Has_Discriminants (T) and then not Range_Checks_Suppressed (T) then
17348 Set_Kill_Range_Checks (T, True);
17349 Record_Type_Definition (Def, Prev);
17350 Set_Kill_Range_Checks (T, False);
17352 Record_Type_Definition (Def, Prev);
17355 -- Exit from record scope
17359 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
17360 -- the implemented interfaces and associate them an aliased entity.
17363 and then not Is_Empty_List (Interface_List (Def))
17365 Derive_Progenitor_Subprograms (T, T);
17367 end Record_Type_Declaration;
17369 ----------------------------
17370 -- Record_Type_Definition --
17371 ----------------------------
17373 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id) is
17374 Component : Entity_Id;
17375 Ctrl_Components : Boolean := False;
17376 Final_Storage_Only : Boolean;
17380 if Ekind (Prev_T) = E_Incomplete_Type then
17381 T := Full_View (Prev_T);
17386 Final_Storage_Only := not Is_Controlled (T);
17388 -- Ada 2005: check whether an explicit Limited is present in a derived
17389 -- type declaration.
17391 if Nkind (Parent (Def)) = N_Derived_Type_Definition
17392 and then Limited_Present (Parent (Def))
17394 Set_Is_Limited_Record (T);
17397 -- If the component list of a record type is defined by the reserved
17398 -- word null and there is no discriminant part, then the record type has
17399 -- no components and all records of the type are null records (RM 3.7)
17400 -- This procedure is also called to process the extension part of a
17401 -- record extension, in which case the current scope may have inherited
17405 or else No (Component_List (Def))
17406 or else Null_Present (Component_List (Def))
17411 Analyze_Declarations (Component_Items (Component_List (Def)));
17413 if Present (Variant_Part (Component_List (Def))) then
17414 Analyze (Variant_Part (Component_List (Def)));
17418 -- After completing the semantic analysis of the record definition,
17419 -- record components, both new and inherited, are accessible. Set their
17420 -- kind accordingly. Exclude malformed itypes from illegal declarations,
17421 -- whose Ekind may be void.
17423 Component := First_Entity (Current_Scope);
17424 while Present (Component) loop
17425 if Ekind (Component) = E_Void
17426 and then not Is_Itype (Component)
17428 Set_Ekind (Component, E_Component);
17429 Init_Component_Location (Component);
17432 if Has_Task (Etype (Component)) then
17436 if Ekind (Component) /= E_Component then
17439 elsif Has_Controlled_Component (Etype (Component))
17440 or else (Chars (Component) /= Name_uParent
17441 and then Is_Controlled (Etype (Component)))
17443 Set_Has_Controlled_Component (T, True);
17444 Final_Storage_Only :=
17446 and then Finalize_Storage_Only (Etype (Component));
17447 Ctrl_Components := True;
17450 Next_Entity (Component);
17453 -- A Type is Finalize_Storage_Only only if all its controlled components
17456 if Ctrl_Components then
17457 Set_Finalize_Storage_Only (T, Final_Storage_Only);
17460 -- Place reference to end record on the proper entity, which may
17461 -- be a partial view.
17463 if Present (Def) then
17464 Process_End_Label (Def, 'e', Prev_T);
17466 end Record_Type_Definition;
17468 ------------------------
17469 -- Replace_Components --
17470 ------------------------
17472 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id) is
17473 function Process (N : Node_Id) return Traverse_Result;
17479 function Process (N : Node_Id) return Traverse_Result is
17483 if Nkind (N) = N_Discriminant_Specification then
17484 Comp := First_Discriminant (Typ);
17485 while Present (Comp) loop
17486 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17487 Set_Defining_Identifier (N, Comp);
17491 Next_Discriminant (Comp);
17494 elsif Nkind (N) = N_Component_Declaration then
17495 Comp := First_Component (Typ);
17496 while Present (Comp) loop
17497 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17498 Set_Defining_Identifier (N, Comp);
17502 Next_Component (Comp);
17509 procedure Replace is new Traverse_Proc (Process);
17511 -- Start of processing for Replace_Components
17515 end Replace_Components;
17517 -------------------------------
17518 -- Set_Completion_Referenced --
17519 -------------------------------
17521 procedure Set_Completion_Referenced (E : Entity_Id) is
17523 -- If in main unit, mark entity that is a completion as referenced,
17524 -- warnings go on the partial view when needed.
17526 if In_Extended_Main_Source_Unit (E) then
17527 Set_Referenced (E);
17529 end Set_Completion_Referenced;
17531 ---------------------
17532 -- Set_Fixed_Range --
17533 ---------------------
17535 -- The range for fixed-point types is complicated by the fact that we
17536 -- do not know the exact end points at the time of the declaration. This
17537 -- is true for three reasons:
17539 -- A size clause may affect the fudging of the end-points
17540 -- A small clause may affect the values of the end-points
17541 -- We try to include the end-points if it does not affect the size
17543 -- This means that the actual end-points must be established at the point
17544 -- when the type is frozen. Meanwhile, we first narrow the range as
17545 -- permitted (so that it will fit if necessary in a small specified size),
17546 -- and then build a range subtree with these narrowed bounds.
17548 -- Set_Fixed_Range constructs the range from real literal values, and sets
17549 -- the range as the Scalar_Range of the given fixed-point type entity.
17551 -- The parent of this range is set to point to the entity so that it is
17552 -- properly hooked into the tree (unlike normal Scalar_Range entries for
17553 -- other scalar types, which are just pointers to the range in the
17554 -- original tree, this would otherwise be an orphan).
17556 -- The tree is left unanalyzed. When the type is frozen, the processing
17557 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
17558 -- analyzed, and uses this as an indication that it should complete
17559 -- work on the range (it will know the final small and size values).
17561 procedure Set_Fixed_Range
17567 S : constant Node_Id :=
17569 Low_Bound => Make_Real_Literal (Loc, Lo),
17570 High_Bound => Make_Real_Literal (Loc, Hi));
17572 Set_Scalar_Range (E, S);
17574 end Set_Fixed_Range;
17576 ----------------------------------
17577 -- Set_Scalar_Range_For_Subtype --
17578 ----------------------------------
17580 procedure Set_Scalar_Range_For_Subtype
17581 (Def_Id : Entity_Id;
17585 Kind : constant Entity_Kind := Ekind (Def_Id);
17588 Set_Scalar_Range (Def_Id, R);
17590 -- We need to link the range into the tree before resolving it so
17591 -- that types that are referenced, including importantly the subtype
17592 -- itself, are properly frozen (Freeze_Expression requires that the
17593 -- expression be properly linked into the tree). Of course if it is
17594 -- already linked in, then we do not disturb the current link.
17596 if No (Parent (R)) then
17597 Set_Parent (R, Def_Id);
17600 -- Reset the kind of the subtype during analysis of the range, to
17601 -- catch possible premature use in the bounds themselves.
17603 Set_Ekind (Def_Id, E_Void);
17604 Process_Range_Expr_In_Decl (R, Subt);
17605 Set_Ekind (Def_Id, Kind);
17606 end Set_Scalar_Range_For_Subtype;
17608 --------------------------------------------------------
17609 -- Set_Stored_Constraint_From_Discriminant_Constraint --
17610 --------------------------------------------------------
17612 procedure Set_Stored_Constraint_From_Discriminant_Constraint
17616 -- Make sure set if encountered during Expand_To_Stored_Constraint
17618 Set_Stored_Constraint (E, No_Elist);
17620 -- Give it the right value
17622 if Is_Constrained (E) and then Has_Discriminants (E) then
17623 Set_Stored_Constraint (E,
17624 Expand_To_Stored_Constraint (E, Discriminant_Constraint (E)));
17626 end Set_Stored_Constraint_From_Discriminant_Constraint;
17628 -------------------------------------
17629 -- Signed_Integer_Type_Declaration --
17630 -------------------------------------
17632 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id) is
17633 Implicit_Base : Entity_Id;
17634 Base_Typ : Entity_Id;
17637 Errs : Boolean := False;
17641 function Can_Derive_From (E : Entity_Id) return Boolean;
17642 -- Determine whether given bounds allow derivation from specified type
17644 procedure Check_Bound (Expr : Node_Id);
17645 -- Check bound to make sure it is integral and static. If not, post
17646 -- appropriate error message and set Errs flag
17648 ---------------------
17649 -- Can_Derive_From --
17650 ---------------------
17652 -- Note we check both bounds against both end values, to deal with
17653 -- strange types like ones with a range of 0 .. -12341234.
17655 function Can_Derive_From (E : Entity_Id) return Boolean is
17656 Lo : constant Uint := Expr_Value (Type_Low_Bound (E));
17657 Hi : constant Uint := Expr_Value (Type_High_Bound (E));
17659 return Lo <= Lo_Val and then Lo_Val <= Hi
17661 Lo <= Hi_Val and then Hi_Val <= Hi;
17662 end Can_Derive_From;
17668 procedure Check_Bound (Expr : Node_Id) is
17670 -- If a range constraint is used as an integer type definition, each
17671 -- bound of the range must be defined by a static expression of some
17672 -- integer type, but the two bounds need not have the same integer
17673 -- type (Negative bounds are allowed.) (RM 3.5.4)
17675 if not Is_Integer_Type (Etype (Expr)) then
17677 ("integer type definition bounds must be of integer type", Expr);
17680 elsif not Is_OK_Static_Expression (Expr) then
17681 Flag_Non_Static_Expr
17682 ("non-static expression used for integer type bound!", Expr);
17685 -- The bounds are folded into literals, and we set their type to be
17686 -- universal, to avoid typing difficulties: we cannot set the type
17687 -- of the literal to the new type, because this would be a forward
17688 -- reference for the back end, and if the original type is user-
17689 -- defined this can lead to spurious semantic errors (e.g. 2928-003).
17692 if Is_Entity_Name (Expr) then
17693 Fold_Uint (Expr, Expr_Value (Expr), True);
17696 Set_Etype (Expr, Universal_Integer);
17700 -- Start of processing for Signed_Integer_Type_Declaration
17703 -- Create an anonymous base type
17706 Create_Itype (E_Signed_Integer_Type, Parent (Def), T, 'B');
17708 -- Analyze and check the bounds, they can be of any integer type
17710 Lo := Low_Bound (Def);
17711 Hi := High_Bound (Def);
17713 -- Arbitrarily use Integer as the type if either bound had an error
17715 if Hi = Error or else Lo = Error then
17716 Base_Typ := Any_Integer;
17717 Set_Error_Posted (T, True);
17719 -- Here both bounds are OK expressions
17722 Analyze_And_Resolve (Lo, Any_Integer);
17723 Analyze_And_Resolve (Hi, Any_Integer);
17729 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17730 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17733 -- Find type to derive from
17735 Lo_Val := Expr_Value (Lo);
17736 Hi_Val := Expr_Value (Hi);
17738 if Can_Derive_From (Standard_Short_Short_Integer) then
17739 Base_Typ := Base_Type (Standard_Short_Short_Integer);
17741 elsif Can_Derive_From (Standard_Short_Integer) then
17742 Base_Typ := Base_Type (Standard_Short_Integer);
17744 elsif Can_Derive_From (Standard_Integer) then
17745 Base_Typ := Base_Type (Standard_Integer);
17747 elsif Can_Derive_From (Standard_Long_Integer) then
17748 Base_Typ := Base_Type (Standard_Long_Integer);
17750 elsif Can_Derive_From (Standard_Long_Long_Integer) then
17751 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17754 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17755 Error_Msg_N ("integer type definition bounds out of range", Def);
17756 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17757 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17761 -- Complete both implicit base and declared first subtype entities
17763 Set_Etype (Implicit_Base, Base_Typ);
17764 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
17765 Set_Size_Info (Implicit_Base, (Base_Typ));
17766 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
17767 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
17769 Set_Ekind (T, E_Signed_Integer_Subtype);
17770 Set_Etype (T, Implicit_Base);
17772 Set_Size_Info (T, (Implicit_Base));
17773 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
17774 Set_Scalar_Range (T, Def);
17775 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
17776 Set_Is_Constrained (T);
17777 end Signed_Integer_Type_Declaration;