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_Disp; use Exp_Disp;
35 with Exp_Dist; use Exp_Dist;
36 with Exp_Tss; use Exp_Tss;
37 with Exp_Util; use Exp_Util;
38 with Fname; use Fname;
39 with Freeze; use Freeze;
40 with Itypes; use Itypes;
41 with Layout; use Layout;
43 with Lib.Xref; use Lib.Xref;
44 with Namet; use Namet;
45 with Nmake; use Nmake;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Case; use Sem_Case;
52 with Sem_Cat; use Sem_Cat;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch7; use Sem_Ch7;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Ch13; use Sem_Ch13;
57 with Sem_Disp; use Sem_Disp;
58 with Sem_Dist; use Sem_Dist;
59 with Sem_Elim; use Sem_Elim;
60 with Sem_Eval; use Sem_Eval;
61 with Sem_Mech; use Sem_Mech;
62 with Sem_Res; use Sem_Res;
63 with Sem_Smem; use Sem_Smem;
64 with Sem_Type; use Sem_Type;
65 with Sem_Util; use Sem_Util;
66 with Sem_Warn; use Sem_Warn;
67 with Stand; use Stand;
68 with Sinfo; use Sinfo;
69 with Snames; use Snames;
70 with Targparm; use Targparm;
71 with Tbuild; use Tbuild;
72 with Ttypes; use Ttypes;
73 with Uintp; use Uintp;
74 with Urealp; use Urealp;
76 package body Sem_Ch3 is
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id);
83 -- Ada 2005 (AI-251): Add the tag components corresponding to all the
84 -- abstract interface types implemented by a record type or a derived
87 procedure Build_Derived_Type
89 Parent_Type : Entity_Id;
90 Derived_Type : Entity_Id;
91 Is_Completion : Boolean;
92 Derive_Subps : Boolean := True);
93 -- Create and decorate a Derived_Type given the Parent_Type entity. N is
94 -- the N_Full_Type_Declaration node containing the derived type definition.
95 -- Parent_Type is the entity for the parent type in the derived type
96 -- definition and Derived_Type the actual derived type. Is_Completion must
97 -- be set to False if Derived_Type is the N_Defining_Identifier node in N
98 -- (i.e. Derived_Type = Defining_Identifier (N)). In this case N is not the
99 -- completion of a private type declaration. If Is_Completion is set to
100 -- True, N is the completion of a private type declaration and Derived_Type
101 -- is different from the defining identifier inside N (i.e. Derived_Type /=
102 -- Defining_Identifier (N)). Derive_Subps indicates whether the parent
103 -- subprograms should be derived. The only case where this parameter is
104 -- False is when Build_Derived_Type is recursively called to process an
105 -- implicit derived full type for a type derived from a private type (in
106 -- that case the subprograms must only be derived for the private view of
109 -- ??? These flags need a bit of re-examination and re-documentation:
110 -- ??? are they both necessary (both seem related to the recursion)?
112 procedure Build_Derived_Access_Type
114 Parent_Type : Entity_Id;
115 Derived_Type : Entity_Id);
116 -- Subsidiary procedure to Build_Derived_Type. For a derived access type,
117 -- create an implicit base if the parent type is constrained or if the
118 -- subtype indication has a constraint.
120 procedure Build_Derived_Array_Type
122 Parent_Type : Entity_Id;
123 Derived_Type : Entity_Id);
124 -- Subsidiary procedure to Build_Derived_Type. For a derived array type,
125 -- create an implicit base if the parent type is constrained or if the
126 -- subtype indication has a constraint.
128 procedure Build_Derived_Concurrent_Type
130 Parent_Type : Entity_Id;
131 Derived_Type : Entity_Id);
132 -- Subsidiary procedure to Build_Derived_Type. For a derived task or
133 -- protected type, inherit entries and protected subprograms, check
134 -- legality of discriminant constraints if any.
136 procedure Build_Derived_Enumeration_Type
138 Parent_Type : Entity_Id;
139 Derived_Type : Entity_Id);
140 -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
141 -- type, we must create a new list of literals. Types derived from
142 -- Character and Wide_Character are special-cased.
144 procedure Build_Derived_Numeric_Type
146 Parent_Type : Entity_Id;
147 Derived_Type : Entity_Id);
148 -- Subsidiary procedure to Build_Derived_Type. For numeric types, create
149 -- an anonymous base type, and propagate constraint to subtype if needed.
151 procedure Build_Derived_Private_Type
153 Parent_Type : Entity_Id;
154 Derived_Type : Entity_Id;
155 Is_Completion : Boolean;
156 Derive_Subps : Boolean := True);
157 -- Subsidiary procedure to Build_Derived_Type. This procedure is complex
158 -- because the parent may or may not have a completion, and the derivation
159 -- may itself be a completion.
161 procedure Build_Derived_Record_Type
163 Parent_Type : Entity_Id;
164 Derived_Type : Entity_Id;
165 Derive_Subps : Boolean := True);
166 -- Subsidiary procedure for Build_Derived_Type and
167 -- Analyze_Private_Extension_Declaration used for tagged and untagged
168 -- record types. All parameters are as in Build_Derived_Type except that
169 -- N, in addition to being an N_Full_Type_Declaration node, can also be an
170 -- N_Private_Extension_Declaration node. See the definition of this routine
171 -- for much more info. Derive_Subps indicates whether subprograms should
172 -- be derived from the parent type. The only case where Derive_Subps is
173 -- False is for an implicit derived full type for a type derived from a
174 -- private type (see Build_Derived_Type).
176 procedure Build_Discriminal (Discrim : Entity_Id);
177 -- Create the discriminal corresponding to discriminant Discrim, that is
178 -- the parameter corresponding to Discrim to be used in initialization
179 -- procedures for the type where Discrim is a discriminant. Discriminals
180 -- are not used during semantic analysis, and are not fully defined
181 -- entities until expansion. Thus they are not given a scope until
182 -- initialization procedures are built.
184 function Build_Discriminant_Constraints
187 Derived_Def : Boolean := False) return Elist_Id;
188 -- Validate discriminant constraints and return the list of the constraints
189 -- in order of discriminant declarations, where T is the discriminated
190 -- unconstrained type. Def is the N_Subtype_Indication node where the
191 -- discriminants constraints for T are specified. Derived_Def is True
192 -- when building the discriminant constraints in a derived type definition
193 -- of the form "type D (...) is new T (xxx)". In this case T is the parent
194 -- type and Def is the constraint "(xxx)" on T and this routine sets the
195 -- Corresponding_Discriminant field of the discriminants in the derived
196 -- type D to point to the corresponding discriminants in the parent type T.
198 procedure Build_Discriminated_Subtype
202 Related_Nod : Node_Id;
203 For_Access : Boolean := False);
204 -- Subsidiary procedure to Constrain_Discriminated_Type and to
205 -- Process_Incomplete_Dependents. Given
207 -- T (a possibly discriminated base type)
208 -- Def_Id (a very partially built subtype for T),
210 -- the call completes Def_Id to be the appropriate E_*_Subtype.
212 -- The Elist is the list of discriminant constraints if any (it is set
213 -- to No_Elist if T is not a discriminated type, and to an empty list if
214 -- T has discriminants but there are no discriminant constraints). The
215 -- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
216 -- The For_Access says whether or not this subtype is really constraining
217 -- an access type. That is its sole purpose is the designated type of an
218 -- access type -- in which case a Private_Subtype Is_For_Access_Subtype
219 -- is built to avoid freezing T when the access subtype is frozen.
221 function Build_Scalar_Bound
224 Der_T : Entity_Id) return Node_Id;
225 -- The bounds of a derived scalar type are conversions of the bounds of
226 -- the parent type. Optimize the representation if the bounds are literals.
227 -- Needs a more complete spec--what are the parameters exactly, and what
228 -- exactly is the returned value, and how is Bound affected???
230 procedure Build_Itype_Reference
233 -- Create a reference to an internal type, for use by Gigi. The back-end
234 -- elaborates itypes on demand, i.e. when their first use is seen. This
235 -- can lead to scope anomalies if the first use is within a scope that is
236 -- nested within the scope that contains the point of definition of the
237 -- itype. The Itype_Reference node forces the elaboration of the itype
238 -- in the proper scope. The node is inserted after Nod, which is the
239 -- enclosing declaration that generated Ityp.
241 -- A related mechanism is used during expansion, for itypes created in
242 -- branches of conditionals. See Ensure_Defined in exp_util.
243 -- Could both mechanisms be merged ???
245 procedure Build_Underlying_Full_View
249 -- If the completion of a private type is itself derived from a private
250 -- type, or if the full view of a private subtype is itself private, the
251 -- back-end has no way to compute the actual size of this type. We build
252 -- an internal subtype declaration of the proper parent type to convey
253 -- this information. This extra mechanism is needed because a full
254 -- view cannot itself have a full view (it would get clobbered during
257 procedure Check_Access_Discriminant_Requires_Limited
260 -- Check the restriction that the type to which an access discriminant
261 -- belongs must be a concurrent type or a descendant of a type with
262 -- the reserved word 'limited' in its declaration.
264 procedure Check_Anonymous_Access_Components
268 Comp_List : Node_Id);
269 -- Ada 2005 AI-382: an access component in a record definition can refer to
270 -- the enclosing record, in which case it denotes the type itself, and not
271 -- the current instance of the type. We create an anonymous access type for
272 -- the component, and flag it as an access to a component, so accessibility
273 -- checks are properly performed on it. The declaration of the access type
274 -- is placed ahead of that of the record to prevent order-of-elaboration
275 -- circularity issues in Gigi. We create an incomplete type for the record
276 -- declaration, which is the designated type of the anonymous access.
278 procedure Check_Delta_Expression (E : Node_Id);
279 -- Check that the expression represented by E is suitable for use as a
280 -- delta expression, i.e. it is of real type and is static.
282 procedure Check_Digits_Expression (E : Node_Id);
283 -- Check that the expression represented by E is suitable for use as a
284 -- digits expression, i.e. it is of integer type, positive and static.
286 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id);
287 -- Validate the initialization of an object declaration. T is the required
288 -- type, and Exp is the initialization expression.
290 procedure Check_Interfaces (N : Node_Id; Def : Node_Id);
291 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
293 procedure Check_Or_Process_Discriminants
296 Prev : Entity_Id := Empty);
297 -- If T is the full declaration of an incomplete or private type, check the
298 -- conformance of the discriminants, otherwise process them. Prev is the
299 -- entity of the partial declaration, if any.
301 procedure Check_Real_Bound (Bound : Node_Id);
302 -- Check given bound for being of real type and static. If not, post an
303 -- appropriate message, and rewrite the bound with the real literal zero.
305 procedure Constant_Redeclaration
309 -- Various checks on legality of full declaration of deferred constant.
310 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
311 -- node. The caller has not yet set any attributes of this entity.
313 function Contain_Interface
315 Ifaces : Elist_Id) return Boolean;
316 -- Ada 2005: Determine whether Iface is present in the list Ifaces
318 procedure Convert_Scalar_Bounds
320 Parent_Type : Entity_Id;
321 Derived_Type : Entity_Id;
323 -- For derived scalar types, convert the bounds in the type definition to
324 -- the derived type, and complete their analysis. Given a constraint of the
325 -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with
326 -- T'Base, the parent_type. The bounds of the derived type (the anonymous
327 -- base) are copies of Lo and Hi. Finally, the bounds of the derived
328 -- subtype are conversions of those bounds to the derived_type, so that
329 -- their typing is consistent.
331 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id);
332 -- Copies attributes from array base type T2 to array base type T1. Copies
333 -- only attributes that apply to base types, but not subtypes.
335 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id);
336 -- Copies attributes from array subtype T2 to array subtype T1. Copies
337 -- attributes that apply to both subtypes and base types.
339 procedure Create_Constrained_Components
343 Constraints : Elist_Id);
344 -- Build the list of entities for a constrained discriminated record
345 -- subtype. If a component depends on a discriminant, replace its subtype
346 -- using the discriminant values in the discriminant constraint. Subt
347 -- is the defining identifier for the subtype whose list of constrained
348 -- entities we will create. Decl_Node is the type declaration node where
349 -- we will attach all the itypes created. Typ is the base discriminated
350 -- type for the subtype Subt. Constraints is the list of discriminant
351 -- constraints for Typ.
353 function Constrain_Component_Type
355 Constrained_Typ : Entity_Id;
356 Related_Node : Node_Id;
358 Constraints : Elist_Id) return Entity_Id;
359 -- Given a discriminated base type Typ, a list of discriminant constraint
360 -- Constraints for Typ and a component of Typ, with type Compon_Type,
361 -- create and return the type corresponding to Compon_type where all
362 -- discriminant references are replaced with the corresponding constraint.
363 -- If no discriminant references occur in Compon_Typ then return it as is.
364 -- Constrained_Typ is the final constrained subtype to which the
365 -- constrained Compon_Type belongs. Related_Node is the node where we will
366 -- attach all the itypes created.
368 -- Above description is confused, what is Compon_Type???
370 procedure Constrain_Access
371 (Def_Id : in out Entity_Id;
373 Related_Nod : Node_Id);
374 -- Apply a list of constraints to an access type. If Def_Id is empty, it is
375 -- an anonymous type created for a subtype indication. In that case it is
376 -- created in the procedure and attached to Related_Nod.
378 procedure Constrain_Array
379 (Def_Id : in out Entity_Id;
381 Related_Nod : Node_Id;
382 Related_Id : Entity_Id;
384 -- Apply a list of index constraints to an unconstrained array type. The
385 -- first parameter is the entity for the resulting subtype. A value of
386 -- Empty for Def_Id indicates that an implicit type must be created, but
387 -- creation is delayed (and must be done by this procedure) because other
388 -- subsidiary implicit types must be created first (which is why Def_Id
389 -- is an in/out parameter). The second parameter is a subtype indication
390 -- node for the constrained array to be created (e.g. something of the
391 -- form string (1 .. 10)). Related_Nod gives the place where this type
392 -- has to be inserted in the tree. The Related_Id and Suffix parameters
393 -- are used to build the associated Implicit type name.
395 procedure Constrain_Concurrent
396 (Def_Id : in out Entity_Id;
398 Related_Nod : Node_Id;
399 Related_Id : Entity_Id;
401 -- Apply list of discriminant constraints to an unconstrained concurrent
404 -- SI is the N_Subtype_Indication node containing the constraint and
405 -- the unconstrained type to constrain.
407 -- Def_Id is the entity for the resulting constrained subtype. A value
408 -- of Empty for Def_Id indicates that an implicit type must be created,
409 -- but creation is delayed (and must be done by this procedure) because
410 -- other subsidiary implicit types must be created first (which is why
411 -- Def_Id is an in/out parameter).
413 -- Related_Nod gives the place where this type has to be inserted
416 -- The last two arguments are used to create its external name if needed.
418 function Constrain_Corresponding_Record
419 (Prot_Subt : Entity_Id;
420 Corr_Rec : Entity_Id;
421 Related_Nod : Node_Id;
422 Related_Id : Entity_Id) return Entity_Id;
423 -- When constraining a protected type or task type with discriminants,
424 -- constrain the corresponding record with the same discriminant values.
426 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id);
427 -- Constrain a decimal fixed point type with a digits constraint and/or a
428 -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
430 procedure Constrain_Discriminated_Type
433 Related_Nod : Node_Id;
434 For_Access : Boolean := False);
435 -- Process discriminant constraints of composite type. Verify that values
436 -- have been provided for all discriminants, that the original type is
437 -- unconstrained, and that the types of the supplied expressions match
438 -- the discriminant types. The first three parameters are like in routine
439 -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
442 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id);
443 -- Constrain an enumeration type with a range constraint. This is identical
444 -- to Constrain_Integer, but for the Ekind of the resulting subtype.
446 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id);
447 -- Constrain a floating point type with either a digits constraint
448 -- and/or a range constraint, building a E_Floating_Point_Subtype.
450 procedure Constrain_Index
453 Related_Nod : Node_Id;
454 Related_Id : Entity_Id;
457 -- Process an index constraint in a constrained array declaration. The
458 -- constraint can be a subtype name, or a range with or without an explicit
459 -- subtype mark. The index is the corresponding index of the unconstrained
460 -- array. The Related_Id and Suffix parameters are used to build the
461 -- associated Implicit type name.
463 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id);
464 -- Build subtype of a signed or modular integer type
466 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id);
467 -- Constrain an ordinary fixed point type with a range constraint, and
468 -- build an E_Ordinary_Fixed_Point_Subtype entity.
470 procedure Copy_And_Swap (Priv, Full : Entity_Id);
471 -- Copy the Priv entity into the entity of its full declaration then swap
472 -- the two entities in such a manner that the former private type is now
473 -- seen as a full type.
475 procedure Decimal_Fixed_Point_Type_Declaration
478 -- Create a new decimal fixed point type, and apply the constraint to
479 -- obtain a subtype of this new type.
481 procedure Complete_Private_Subtype
484 Full_Base : Entity_Id;
485 Related_Nod : Node_Id);
486 -- Complete the implicit full view of a private subtype by setting the
487 -- appropriate semantic fields. If the full view of the parent is a record
488 -- type, build constrained components of subtype.
490 procedure Derive_Progenitor_Subprograms
491 (Parent_Type : Entity_Id;
492 Tagged_Type : Entity_Id);
493 -- Ada 2005 (AI-251): To complete type derivation, collect the primitive
494 -- operations of progenitors of Tagged_Type, and replace the subsidiary
495 -- subtypes with Tagged_Type, to build the specs of the inherited interface
496 -- primitives. The derived primitives are aliased to those of the
497 -- interface. This routine takes care also of transferring to the full-view
498 -- subprograms associated with the partial-view of Tagged_Type that cover
499 -- interface primitives.
501 procedure Derived_Standard_Character
503 Parent_Type : Entity_Id;
504 Derived_Type : Entity_Id);
505 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
506 -- derivations from types Standard.Character and Standard.Wide_Character.
508 procedure Derived_Type_Declaration
511 Is_Completion : Boolean);
512 -- Process a derived type declaration. Build_Derived_Type is invoked
513 -- to process the actual derived type definition. Parameters N and
514 -- Is_Completion have the same meaning as in Build_Derived_Type.
515 -- T is the N_Defining_Identifier for the entity defined in the
516 -- N_Full_Type_Declaration node N, that is T is the derived type.
518 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id);
519 -- Insert each literal in symbol table, as an overloadable identifier. Each
520 -- enumeration type is mapped into a sequence of integers, and each literal
521 -- is defined as a constant with integer value. If any of the literals are
522 -- character literals, the type is a character type, which means that
523 -- strings are legal aggregates for arrays of components of the type.
525 function Expand_To_Stored_Constraint
527 Constraint : Elist_Id) return Elist_Id;
528 -- Given a constraint (i.e. a list of expressions) on the discriminants of
529 -- Typ, expand it into a constraint on the stored discriminants and return
530 -- the new list of expressions constraining the stored discriminants.
532 function Find_Type_Of_Object
534 Related_Nod : Node_Id) return Entity_Id;
535 -- Get type entity for object referenced by Obj_Def, attaching the
536 -- implicit types generated to Related_Nod
538 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id);
539 -- Create a new float and apply the constraint to obtain subtype of it
541 function Has_Range_Constraint (N : Node_Id) return Boolean;
542 -- Given an N_Subtype_Indication node N, return True if a range constraint
543 -- is present, either directly, or as part of a digits or delta constraint.
544 -- In addition, a digits constraint in the decimal case returns True, since
545 -- it establishes a default range if no explicit range is present.
547 function Inherit_Components
549 Parent_Base : Entity_Id;
550 Derived_Base : Entity_Id;
552 Inherit_Discr : Boolean;
553 Discs : Elist_Id) return Elist_Id;
554 -- Called from Build_Derived_Record_Type to inherit the components of
555 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
556 -- For more information on derived types and component inheritance please
557 -- consult the comment above the body of Build_Derived_Record_Type.
559 -- N is the original derived type declaration
561 -- Is_Tagged is set if we are dealing with tagged types
563 -- If Inherit_Discr is set, Derived_Base inherits its discriminants from
564 -- Parent_Base, otherwise no discriminants are inherited.
566 -- Discs gives the list of constraints that apply to Parent_Base in the
567 -- derived type declaration. If Discs is set to No_Elist, then we have
568 -- the following situation:
570 -- type Parent (D1..Dn : ..) is [tagged] record ...;
571 -- type Derived is new Parent [with ...];
573 -- which gets treated as
575 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
577 -- For untagged types the returned value is an association list. The list
578 -- starts from the association (Parent_Base => Derived_Base), and then it
579 -- contains a sequence of the associations of the form
581 -- (Old_Component => New_Component),
583 -- where Old_Component is the Entity_Id of a component in Parent_Base and
584 -- New_Component is the Entity_Id of the corresponding component in
585 -- Derived_Base. For untagged records, this association list is needed when
586 -- copying the record declaration for the derived base. In the tagged case
587 -- the value returned is irrelevant.
589 function Is_Progenitor
591 Typ : Entity_Id) return Boolean;
592 -- Determine whether type Typ implements interface Iface. This requires
593 -- traversing the list of abstract interfaces of the type, as well as that
594 -- of the ancestor types. The predicate is used to determine when a formal
595 -- in the signature of an inherited operation must carry the derived type.
597 function Is_Valid_Constraint_Kind
599 Constraint_Kind : Node_Kind) return Boolean;
600 -- Returns True if it is legal to apply the given kind of constraint to the
601 -- given kind of type (index constraint to an array type, for example).
603 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id);
604 -- Create new modular type. Verify that modulus is in bounds and is
605 -- a power of two (implementation restriction).
607 procedure New_Concatenation_Op (Typ : Entity_Id);
608 -- Create an abbreviated declaration for an operator in order to
609 -- materialize concatenation on array types.
611 procedure Ordinary_Fixed_Point_Type_Declaration
614 -- Create a new ordinary fixed point type, and apply the constraint to
615 -- obtain subtype of it.
617 procedure Prepare_Private_Subtype_Completion
619 Related_Nod : Node_Id);
620 -- Id is a subtype of some private type. Creates the full declaration
621 -- associated with Id whenever possible, i.e. when the full declaration
622 -- of the base type is already known. Records each subtype into
623 -- Private_Dependents of the base type.
625 procedure Process_Incomplete_Dependents
629 -- Process all entities that depend on an incomplete type. There include
630 -- subtypes, subprogram types that mention the incomplete type in their
631 -- profiles, and subprogram with access parameters that designate the
634 -- Inc_T is the defining identifier of an incomplete type declaration, its
635 -- Ekind is E_Incomplete_Type.
637 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
639 -- Full_T is N's defining identifier.
641 -- Subtypes of incomplete types with discriminants are completed when the
642 -- parent type is. This is simpler than private subtypes, because they can
643 -- only appear in the same scope, and there is no need to exchange views.
644 -- Similarly, access_to_subprogram types may have a parameter or a return
645 -- type that is an incomplete type, and that must be replaced with the
648 -- If the full type is tagged, subprogram with access parameters that
649 -- designated the incomplete may be primitive operations of the full type,
650 -- and have to be processed accordingly.
652 procedure Process_Real_Range_Specification (Def : Node_Id);
653 -- Given the type definition for a real type, this procedure processes and
654 -- checks the real range specification of this type definition if one is
655 -- present. If errors are found, error messages are posted, and the
656 -- Real_Range_Specification of Def is reset to Empty.
658 procedure Record_Type_Declaration
662 -- Process a record type declaration (for both untagged and tagged
663 -- records). Parameters T and N are exactly like in procedure
664 -- Derived_Type_Declaration, except that no flag Is_Completion is needed
665 -- for this routine. If this is the completion of an incomplete type
666 -- declaration, Prev is the entity of the incomplete declaration, used for
667 -- cross-referencing. Otherwise Prev = T.
669 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id);
670 -- This routine is used to process the actual record type definition (both
671 -- for untagged and tagged records). Def is a record type definition node.
672 -- This procedure analyzes the components in this record type definition.
673 -- Prev_T is the entity for the enclosing record type. It is provided so
674 -- that its Has_Task flag can be set if any of the component have Has_Task
675 -- set. If the declaration is the completion of an incomplete type
676 -- declaration, Prev_T is the original incomplete type, whose full view is
679 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id);
680 -- Subsidiary to Build_Derived_Record_Type. For untagged records, we
681 -- build a copy of the declaration tree of the parent, and we create
682 -- independently the list of components for the derived type. Semantic
683 -- information uses the component entities, but record representation
684 -- clauses are validated on the declaration tree. This procedure replaces
685 -- discriminants and components in the declaration with those that have
686 -- been created by Inherit_Components.
688 procedure Set_Fixed_Range
693 -- Build a range node with the given bounds and set it as the Scalar_Range
694 -- of the given fixed-point type entity. Loc is the source location used
695 -- for the constructed range. See body for further details.
697 procedure Set_Scalar_Range_For_Subtype
701 -- This routine is used to set the scalar range field for a subtype given
702 -- Def_Id, the entity for the subtype, and R, the range expression for the
703 -- scalar range. Subt provides the parent subtype to be used to analyze,
704 -- resolve, and check the given range.
706 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id);
707 -- Create a new signed integer entity, and apply the constraint to obtain
708 -- the required first named subtype of this type.
710 procedure Set_Stored_Constraint_From_Discriminant_Constraint
712 -- E is some record type. This routine computes E's Stored_Constraint
713 -- from its Discriminant_Constraint.
715 procedure Diagnose_Interface (N : Node_Id; E : Entity_Id);
716 -- Check that an entity in a list of progenitors is an interface,
717 -- emit error otherwise.
719 -----------------------
720 -- Access_Definition --
721 -----------------------
723 function Access_Definition
724 (Related_Nod : Node_Id;
725 N : Node_Id) return Entity_Id
727 Loc : constant Source_Ptr := Sloc (Related_Nod);
728 Anon_Type : Entity_Id;
729 Anon_Scope : Entity_Id;
730 Desig_Type : Entity_Id;
734 if Is_Entry (Current_Scope)
735 and then Is_Task_Type (Etype (Scope (Current_Scope)))
737 Error_Msg_N ("task entries cannot have access parameters", N);
741 -- Ada 2005: for an object declaration the corresponding anonymous
742 -- type is declared in the current scope.
744 -- If the access definition is the return type of another access to
745 -- function, scope is the current one, because it is the one of the
746 -- current type declaration.
748 if Nkind_In (Related_Nod, N_Object_Declaration,
749 N_Access_Function_Definition)
751 Anon_Scope := Current_Scope;
753 -- For the anonymous function result case, retrieve the scope of the
754 -- function specification's associated entity rather than using the
755 -- current scope. The current scope will be the function itself if the
756 -- formal part is currently being analyzed, but will be the parent scope
757 -- in the case of a parameterless function, and we always want to use
758 -- the function's parent scope. Finally, if the function is a child
759 -- unit, we must traverse the tree to retrieve the proper entity.
761 elsif Nkind (Related_Nod) = N_Function_Specification
762 and then Nkind (Parent (N)) /= N_Parameter_Specification
764 -- If the current scope is a protected type, the anonymous access
765 -- is associated with one of the protected operations, and must
766 -- be available in the scope that encloses the protected declaration.
767 -- Otherwise the type is is in the scope enclosing the subprogram.
769 if Ekind (Current_Scope) = E_Protected_Type then
770 Anon_Scope := Scope (Scope (Defining_Entity (Related_Nod)));
772 Anon_Scope := Scope (Defining_Entity (Related_Nod));
776 -- For access formals, access components, and access discriminants,
777 -- the scope is that of the enclosing declaration,
779 Anon_Scope := Scope (Current_Scope);
784 (E_Anonymous_Access_Type, Related_Nod, Scope_Id => Anon_Scope);
787 and then Ada_Version >= Ada_05
789 Error_Msg_N ("ALL is not permitted for anonymous access types", N);
792 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
793 -- the corresponding semantic routine
795 if Present (Access_To_Subprogram_Definition (N)) then
796 Access_Subprogram_Declaration
797 (T_Name => Anon_Type,
798 T_Def => Access_To_Subprogram_Definition (N));
800 if Ekind (Anon_Type) = E_Access_Protected_Subprogram_Type then
802 (Anon_Type, E_Anonymous_Access_Protected_Subprogram_Type);
805 (Anon_Type, E_Anonymous_Access_Subprogram_Type);
808 Set_Can_Use_Internal_Rep
809 (Anon_Type, not Always_Compatible_Rep_On_Target);
811 -- If the anonymous access is associated with a protected operation
812 -- create a reference to it after the enclosing protected definition
813 -- because the itype will be used in the subsequent bodies.
815 if Ekind (Current_Scope) = E_Protected_Type then
816 Build_Itype_Reference (Anon_Type, Parent (Current_Scope));
822 Find_Type (Subtype_Mark (N));
823 Desig_Type := Entity (Subtype_Mark (N));
825 Set_Directly_Designated_Type
826 (Anon_Type, Desig_Type);
827 Set_Etype (Anon_Type, Anon_Type);
829 -- Make sure the anonymous access type has size and alignment fields
830 -- set, as required by gigi. This is necessary in the case of the
831 -- Task_Body_Procedure.
833 if not Has_Private_Component (Desig_Type) then
834 Layout_Type (Anon_Type);
837 -- ???The following makes no sense, because Anon_Type is an access type
838 -- and therefore cannot have components, private or otherwise. Hence
839 -- the assertion. Not sure what was meant, here.
840 Set_Depends_On_Private (Anon_Type, Has_Private_Component (Anon_Type));
841 pragma Assert (not Depends_On_Private (Anon_Type));
843 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
844 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
845 -- the null value is allowed. In Ada 95 the null value is never allowed.
847 if Ada_Version >= Ada_05 then
848 Set_Can_Never_Be_Null (Anon_Type, Null_Exclusion_Present (N));
850 Set_Can_Never_Be_Null (Anon_Type, True);
853 -- The anonymous access type is as public as the discriminated type or
854 -- subprogram that defines it. It is imported (for back-end purposes)
855 -- if the designated type is.
857 Set_Is_Public (Anon_Type, Is_Public (Scope (Anon_Type)));
859 -- Ada 2005 (AI-50217): Propagate the attribute that indicates that the
860 -- designated type comes from the limited view.
862 Set_From_With_Type (Anon_Type, From_With_Type (Desig_Type));
864 -- Ada 2005 (AI-231): Propagate the access-constant attribute
866 Set_Is_Access_Constant (Anon_Type, Constant_Present (N));
868 -- The context is either a subprogram declaration, object declaration,
869 -- or an access discriminant, in a private or a full type declaration.
870 -- In the case of a subprogram, if the designated type is incomplete,
871 -- the operation will be a primitive operation of the full type, to be
872 -- updated subsequently. If the type is imported through a limited_with
873 -- clause, the subprogram is not a primitive operation of the type
874 -- (which is declared elsewhere in some other scope).
876 if Ekind (Desig_Type) = E_Incomplete_Type
877 and then not From_With_Type (Desig_Type)
878 and then Is_Overloadable (Current_Scope)
880 Append_Elmt (Current_Scope, Private_Dependents (Desig_Type));
881 Set_Has_Delayed_Freeze (Current_Scope);
884 -- Ada 2005: if the designated type is an interface that may contain
885 -- tasks, create a Master entity for the declaration. This must be done
886 -- before expansion of the full declaration, because the declaration may
887 -- include an expression that is an allocator, whose expansion needs the
888 -- proper Master for the created tasks.
890 if Nkind (Related_Nod) = N_Object_Declaration
891 and then Expander_Active
893 if Is_Interface (Desig_Type)
894 and then Is_Limited_Record (Desig_Type)
896 Build_Class_Wide_Master (Anon_Type);
898 -- Similarly, if the type is an anonymous access that designates
899 -- tasks, create a master entity for it in the current context.
901 elsif Has_Task (Desig_Type)
902 and then Comes_From_Source (Related_Nod)
904 if not Has_Master_Entity (Current_Scope) then
906 Make_Object_Declaration (Loc,
907 Defining_Identifier =>
908 Make_Defining_Identifier (Loc, Name_uMaster),
909 Constant_Present => True,
911 New_Reference_To (RTE (RE_Master_Id), Loc),
913 Make_Explicit_Dereference (Loc,
914 New_Reference_To (RTE (RE_Current_Master), Loc)));
916 Insert_Before (Related_Nod, Decl);
919 Set_Master_Id (Anon_Type, Defining_Identifier (Decl));
920 Set_Has_Master_Entity (Current_Scope);
922 Build_Master_Renaming (Related_Nod, Anon_Type);
927 -- For a private component of a protected type, it is imperative that
928 -- the back-end elaborate the type immediately after the protected
929 -- declaration, because this type will be used in the declarations
930 -- created for the component within each protected body, so we must
931 -- create an itype reference for it now.
933 if Nkind (Parent (Related_Nod)) = N_Protected_Definition then
934 Build_Itype_Reference (Anon_Type, Parent (Parent (Related_Nod)));
936 -- Similarly, if the access definition is the return result of a
937 -- protected function, create an itype reference for it because it
938 -- will be used within the function body.
940 elsif Nkind (Related_Nod) = N_Function_Specification
941 and then Ekind (Current_Scope) = E_Protected_Type
943 Build_Itype_Reference (Anon_Type, Parent (Current_Scope));
945 -- Finally, create an itype reference for an object declaration of
946 -- an anonymous access type. This is strictly necessary only for
947 -- deferred constants, but in any case will avoid out-of-scope
948 -- problems in the back-end.
950 elsif Nkind (Related_Nod) = N_Object_Declaration then
951 Build_Itype_Reference (Anon_Type, Related_Nod);
955 end Access_Definition;
957 -----------------------------------
958 -- Access_Subprogram_Declaration --
959 -----------------------------------
961 procedure Access_Subprogram_Declaration
966 procedure Check_For_Premature_Usage (Def : Node_Id);
967 -- Check that type T_Name is not used, directly or recursively,
968 -- as a parameter or a return type in Def. Def is either a subtype,
969 -- an access_definition, or an access_to_subprogram_definition.
971 -------------------------------
972 -- Check_For_Premature_Usage --
973 -------------------------------
975 procedure Check_For_Premature_Usage (Def : Node_Id) is
979 -- Check for a subtype mark
981 if Nkind (Def) in N_Has_Etype then
982 if Etype (Def) = T_Name then
984 ("type& cannot be used before end of its declaration", Def);
987 -- If this is not a subtype, then this is an access_definition
989 elsif Nkind (Def) = N_Access_Definition then
990 if Present (Access_To_Subprogram_Definition (Def)) then
991 Check_For_Premature_Usage
992 (Access_To_Subprogram_Definition (Def));
994 Check_For_Premature_Usage (Subtype_Mark (Def));
997 -- The only cases left are N_Access_Function_Definition and
998 -- N_Access_Procedure_Definition.
1001 if Present (Parameter_Specifications (Def)) then
1002 Param := First (Parameter_Specifications (Def));
1003 while Present (Param) loop
1004 Check_For_Premature_Usage (Parameter_Type (Param));
1005 Param := Next (Param);
1009 if Nkind (Def) = N_Access_Function_Definition then
1010 Check_For_Premature_Usage (Result_Definition (Def));
1013 end Check_For_Premature_Usage;
1017 Formals : constant List_Id := Parameter_Specifications (T_Def);
1020 Desig_Type : constant Entity_Id :=
1021 Create_Itype (E_Subprogram_Type, Parent (T_Def));
1023 -- Start of processing for Access_Subprogram_Declaration
1026 -- Associate the Itype node with the inner full-type declaration or
1027 -- subprogram spec. This is required to handle nested anonymous
1028 -- declarations. For example:
1031 -- (X : access procedure
1032 -- (Y : access procedure
1035 D_Ityp := Associated_Node_For_Itype (Desig_Type);
1036 while not (Nkind_In (D_Ityp, N_Full_Type_Declaration,
1037 N_Private_Type_Declaration,
1038 N_Private_Extension_Declaration,
1039 N_Procedure_Specification,
1040 N_Function_Specification)
1042 Nkind_In (D_Ityp, N_Object_Declaration,
1043 N_Object_Renaming_Declaration,
1044 N_Formal_Type_Declaration,
1045 N_Task_Type_Declaration,
1046 N_Protected_Type_Declaration))
1048 D_Ityp := Parent (D_Ityp);
1049 pragma Assert (D_Ityp /= Empty);
1052 Set_Associated_Node_For_Itype (Desig_Type, D_Ityp);
1054 if Nkind_In (D_Ityp, N_Procedure_Specification,
1055 N_Function_Specification)
1057 Set_Scope (Desig_Type, Scope (Defining_Entity (D_Ityp)));
1059 elsif Nkind_In (D_Ityp, N_Full_Type_Declaration,
1060 N_Object_Declaration,
1061 N_Object_Renaming_Declaration,
1062 N_Formal_Type_Declaration)
1064 Set_Scope (Desig_Type, Scope (Defining_Identifier (D_Ityp)));
1067 if Nkind (T_Def) = N_Access_Function_Definition then
1068 if Nkind (Result_Definition (T_Def)) = N_Access_Definition then
1070 Acc : constant Node_Id := Result_Definition (T_Def);
1073 if Present (Access_To_Subprogram_Definition (Acc))
1075 Protected_Present (Access_To_Subprogram_Definition (Acc))
1079 Replace_Anonymous_Access_To_Protected_Subprogram
1085 Access_Definition (T_Def, Result_Definition (T_Def)));
1090 Analyze (Result_Definition (T_Def));
1091 Set_Etype (Desig_Type, Entity (Result_Definition (T_Def)));
1094 if not (Is_Type (Etype (Desig_Type))) then
1096 ("expect type in function specification",
1097 Result_Definition (T_Def));
1101 Set_Etype (Desig_Type, Standard_Void_Type);
1104 if Present (Formals) then
1105 Push_Scope (Desig_Type);
1106 Process_Formals (Formals, Parent (T_Def));
1108 -- A bit of a kludge here, End_Scope requires that the parent
1109 -- pointer be set to something reasonable, but Itypes don't have
1110 -- parent pointers. So we set it and then unset it ??? If and when
1111 -- Itypes have proper parent pointers to their declarations, this
1112 -- kludge can be removed.
1114 Set_Parent (Desig_Type, T_Name);
1116 Set_Parent (Desig_Type, Empty);
1119 -- Check for premature usage of the type being defined
1121 Check_For_Premature_Usage (T_Def);
1123 -- The return type and/or any parameter type may be incomplete. Mark
1124 -- the subprogram_type as depending on the incomplete type, so that
1125 -- it can be updated when the full type declaration is seen. This
1126 -- only applies to incomplete types declared in some enclosing scope,
1127 -- not to limited views from other packages.
1129 if Present (Formals) then
1130 Formal := First_Formal (Desig_Type);
1131 while Present (Formal) loop
1132 if Ekind (Formal) /= E_In_Parameter
1133 and then Nkind (T_Def) = N_Access_Function_Definition
1135 Error_Msg_N ("functions can only have IN parameters", Formal);
1138 if Ekind (Etype (Formal)) = E_Incomplete_Type
1139 and then In_Open_Scopes (Scope (Etype (Formal)))
1141 Append_Elmt (Desig_Type, Private_Dependents (Etype (Formal)));
1142 Set_Has_Delayed_Freeze (Desig_Type);
1145 Next_Formal (Formal);
1149 if Ekind (Etype (Desig_Type)) = E_Incomplete_Type
1150 and then not Has_Delayed_Freeze (Desig_Type)
1152 Append_Elmt (Desig_Type, Private_Dependents (Etype (Desig_Type)));
1153 Set_Has_Delayed_Freeze (Desig_Type);
1156 Check_Delayed_Subprogram (Desig_Type);
1158 if Protected_Present (T_Def) then
1159 Set_Ekind (T_Name, E_Access_Protected_Subprogram_Type);
1160 Set_Convention (Desig_Type, Convention_Protected);
1162 Set_Ekind (T_Name, E_Access_Subprogram_Type);
1165 Set_Can_Use_Internal_Rep (T_Name, not Always_Compatible_Rep_On_Target);
1167 Set_Etype (T_Name, T_Name);
1168 Init_Size_Align (T_Name);
1169 Set_Directly_Designated_Type (T_Name, Desig_Type);
1171 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1173 Set_Can_Never_Be_Null (T_Name, Null_Exclusion_Present (T_Def));
1175 Check_Restriction (No_Access_Subprograms, T_Def);
1176 end Access_Subprogram_Declaration;
1178 ----------------------------
1179 -- Access_Type_Declaration --
1180 ----------------------------
1182 procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id) is
1183 S : constant Node_Id := Subtype_Indication (Def);
1184 P : constant Node_Id := Parent (Def);
1190 -- Check for permissible use of incomplete type
1192 if Nkind (S) /= N_Subtype_Indication then
1195 if Ekind (Root_Type (Entity (S))) = E_Incomplete_Type then
1196 Set_Directly_Designated_Type (T, Entity (S));
1198 Set_Directly_Designated_Type (T,
1199 Process_Subtype (S, P, T, 'P'));
1203 Set_Directly_Designated_Type (T,
1204 Process_Subtype (S, P, T, 'P'));
1207 if All_Present (Def) or Constant_Present (Def) then
1208 Set_Ekind (T, E_General_Access_Type);
1210 Set_Ekind (T, E_Access_Type);
1213 if Base_Type (Designated_Type (T)) = T then
1214 Error_Msg_N ("access type cannot designate itself", S);
1216 -- In Ada 2005, the type may have a limited view through some unit
1217 -- in its own context, allowing the following circularity that cannot
1218 -- be detected earlier
1220 elsif Is_Class_Wide_Type (Designated_Type (T))
1221 and then Etype (Designated_Type (T)) = T
1224 ("access type cannot designate its own classwide type", S);
1226 -- Clean up indication of tagged status to prevent cascaded errors
1228 Set_Is_Tagged_Type (T, False);
1233 -- If the type has appeared already in a with_type clause, it is
1234 -- frozen and the pointer size is already set. Else, initialize.
1236 if not From_With_Type (T) then
1237 Init_Size_Align (T);
1240 Desig := Designated_Type (T);
1242 -- If designated type is an imported tagged type, indicate that the
1243 -- access type is also imported, and therefore restricted in its use.
1244 -- The access type may already be imported, so keep setting otherwise.
1246 -- Ada 2005 (AI-50217): If the non-limited view of the designated type
1247 -- is available, use it as the designated type of the access type, so
1248 -- that the back-end gets a usable entity.
1250 if From_With_Type (Desig)
1251 and then Ekind (Desig) /= E_Access_Type
1253 Set_From_With_Type (T);
1256 -- Note that Has_Task is always false, since the access type itself
1257 -- is not a task type. See Einfo for more description on this point.
1258 -- Exactly the same consideration applies to Has_Controlled_Component.
1260 Set_Has_Task (T, False);
1261 Set_Has_Controlled_Component (T, False);
1263 -- Initialize Associated_Final_Chain explicitly to Empty, to avoid
1264 -- problems where an incomplete view of this entity has been previously
1265 -- established by a limited with and an overlaid version of this field
1266 -- (Stored_Constraint) was initialized for the incomplete view.
1268 Set_Associated_Final_Chain (T, Empty);
1270 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1273 Set_Can_Never_Be_Null (T, Null_Exclusion_Present (Def));
1274 Set_Is_Access_Constant (T, Constant_Present (Def));
1275 end Access_Type_Declaration;
1277 ----------------------------------
1278 -- Add_Interface_Tag_Components --
1279 ----------------------------------
1281 procedure Add_Interface_Tag_Components (N : Node_Id; Typ : Entity_Id) is
1282 Loc : constant Source_Ptr := Sloc (N);
1286 procedure Add_Tag (Iface : Entity_Id);
1287 -- Add tag for one of the progenitor interfaces
1293 procedure Add_Tag (Iface : Entity_Id) is
1300 pragma Assert (Is_Tagged_Type (Iface)
1301 and then Is_Interface (Iface));
1304 Make_Component_Definition (Loc,
1305 Aliased_Present => True,
1306 Subtype_Indication =>
1307 New_Occurrence_Of (RTE (RE_Interface_Tag), Loc));
1309 Tag := Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1312 Make_Component_Declaration (Loc,
1313 Defining_Identifier => Tag,
1314 Component_Definition => Def);
1316 Analyze_Component_Declaration (Decl);
1318 Set_Analyzed (Decl);
1319 Set_Ekind (Tag, E_Component);
1321 Set_Is_Aliased (Tag);
1322 Set_Related_Type (Tag, Iface);
1323 Init_Component_Location (Tag);
1325 pragma Assert (Is_Frozen (Iface));
1327 Set_DT_Entry_Count (Tag,
1328 DT_Entry_Count (First_Entity (Iface)));
1330 if No (Last_Tag) then
1333 Insert_After (Last_Tag, Decl);
1338 -- If the ancestor has discriminants we need to give special support
1339 -- to store the offset_to_top value of the secondary dispatch tables.
1340 -- For this purpose we add a supplementary component just after the
1341 -- field that contains the tag associated with each secondary DT.
1343 if Typ /= Etype (Typ)
1344 and then Has_Discriminants (Etype (Typ))
1347 Make_Component_Definition (Loc,
1348 Subtype_Indication =>
1349 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc));
1352 Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1355 Make_Component_Declaration (Loc,
1356 Defining_Identifier => Offset,
1357 Component_Definition => Def);
1359 Analyze_Component_Declaration (Decl);
1361 Set_Analyzed (Decl);
1362 Set_Ekind (Offset, E_Component);
1363 Set_Is_Aliased (Offset);
1364 Set_Related_Type (Offset, Iface);
1365 Init_Component_Location (Offset);
1366 Insert_After (Last_Tag, Decl);
1377 -- Start of processing for Add_Interface_Tag_Components
1380 if not RTE_Available (RE_Interface_Tag) then
1382 ("(Ada 2005) interface types not supported by this run-time!",
1387 if Ekind (Typ) /= E_Record_Type
1388 or else (Is_Concurrent_Record_Type (Typ)
1389 and then Is_Empty_List (Abstract_Interface_List (Typ)))
1390 or else (not Is_Concurrent_Record_Type (Typ)
1391 and then No (Interfaces (Typ))
1392 and then Is_Empty_Elmt_List (Interfaces (Typ)))
1397 -- Find the current last tag
1399 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1400 Ext := Record_Extension_Part (Type_Definition (N));
1402 pragma Assert (Nkind (Type_Definition (N)) = N_Record_Definition);
1403 Ext := Type_Definition (N);
1408 if not (Present (Component_List (Ext))) then
1409 Set_Null_Present (Ext, False);
1411 Set_Component_List (Ext,
1412 Make_Component_List (Loc,
1413 Component_Items => L,
1414 Null_Present => False));
1416 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
1417 L := Component_Items
1419 (Record_Extension_Part
1420 (Type_Definition (N))));
1422 L := Component_Items
1424 (Type_Definition (N)));
1427 -- Find the last tag component
1430 while Present (Comp) loop
1431 if Nkind (Comp) = N_Component_Declaration
1432 and then Is_Tag (Defining_Identifier (Comp))
1441 -- At this point L references the list of components and Last_Tag
1442 -- references the current last tag (if any). Now we add the tag
1443 -- corresponding with all the interfaces that are not implemented
1446 if Present (Interfaces (Typ)) then
1447 Elmt := First_Elmt (Interfaces (Typ));
1448 while Present (Elmt) loop
1449 Add_Tag (Node (Elmt));
1453 end Add_Interface_Tag_Components;
1455 -----------------------------------
1456 -- Analyze_Component_Declaration --
1457 -----------------------------------
1459 procedure Analyze_Component_Declaration (N : Node_Id) is
1460 Id : constant Entity_Id := Defining_Identifier (N);
1461 E : constant Node_Id := Expression (N);
1465 function Contains_POC (Constr : Node_Id) return Boolean;
1466 -- Determines whether a constraint uses the discriminant of a record
1467 -- type thus becoming a per-object constraint (POC).
1469 function Is_Known_Limited (Typ : Entity_Id) return Boolean;
1470 -- Typ is the type of the current component, check whether this type is
1471 -- a limited type. Used to validate declaration against that of
1472 -- enclosing record.
1478 function Contains_POC (Constr : Node_Id) return Boolean is
1480 -- Prevent cascaded errors
1482 if Error_Posted (Constr) then
1486 case Nkind (Constr) is
1487 when N_Attribute_Reference =>
1489 Attribute_Name (Constr) = Name_Access
1490 and then Prefix (Constr) = Scope (Entity (Prefix (Constr)));
1492 when N_Discriminant_Association =>
1493 return Denotes_Discriminant (Expression (Constr));
1495 when N_Identifier =>
1496 return Denotes_Discriminant (Constr);
1498 when N_Index_Or_Discriminant_Constraint =>
1503 IDC := First (Constraints (Constr));
1504 while Present (IDC) loop
1506 -- One per-object constraint is sufficient
1508 if Contains_POC (IDC) then
1519 return Denotes_Discriminant (Low_Bound (Constr))
1521 Denotes_Discriminant (High_Bound (Constr));
1523 when N_Range_Constraint =>
1524 return Denotes_Discriminant (Range_Expression (Constr));
1532 ----------------------
1533 -- Is_Known_Limited --
1534 ----------------------
1536 function Is_Known_Limited (Typ : Entity_Id) return Boolean is
1537 P : constant Entity_Id := Etype (Typ);
1538 R : constant Entity_Id := Root_Type (Typ);
1541 if Is_Limited_Record (Typ) then
1544 -- If the root type is limited (and not a limited interface)
1545 -- so is the current type
1547 elsif Is_Limited_Record (R)
1549 (not Is_Interface (R)
1550 or else not Is_Limited_Interface (R))
1554 -- Else the type may have a limited interface progenitor, but a
1555 -- limited record parent.
1558 and then Is_Limited_Record (P)
1565 end Is_Known_Limited;
1567 -- Start of processing for Analyze_Component_Declaration
1570 Generate_Definition (Id);
1573 if Present (Subtype_Indication (Component_Definition (N))) then
1574 T := Find_Type_Of_Object
1575 (Subtype_Indication (Component_Definition (N)), N);
1577 -- Ada 2005 (AI-230): Access Definition case
1580 pragma Assert (Present
1581 (Access_Definition (Component_Definition (N))));
1583 T := Access_Definition
1585 N => Access_Definition (Component_Definition (N)));
1586 Set_Is_Local_Anonymous_Access (T);
1588 -- Ada 2005 (AI-254)
1590 if Present (Access_To_Subprogram_Definition
1591 (Access_Definition (Component_Definition (N))))
1592 and then Protected_Present (Access_To_Subprogram_Definition
1594 (Component_Definition (N))))
1596 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
1600 -- If the subtype is a constrained subtype of the enclosing record,
1601 -- (which must have a partial view) the back-end does not properly
1602 -- handle the recursion. Rewrite the component declaration with an
1603 -- explicit subtype indication, which is acceptable to Gigi. We can copy
1604 -- the tree directly because side effects have already been removed from
1605 -- discriminant constraints.
1607 if Ekind (T) = E_Access_Subtype
1608 and then Is_Entity_Name (Subtype_Indication (Component_Definition (N)))
1609 and then Comes_From_Source (T)
1610 and then Nkind (Parent (T)) = N_Subtype_Declaration
1611 and then Etype (Directly_Designated_Type (T)) = Current_Scope
1614 (Subtype_Indication (Component_Definition (N)),
1615 New_Copy_Tree (Subtype_Indication (Parent (T))));
1616 T := Find_Type_Of_Object
1617 (Subtype_Indication (Component_Definition (N)), N);
1620 -- If the component declaration includes a default expression, then we
1621 -- check that the component is not of a limited type (RM 3.7(5)),
1622 -- and do the special preanalysis of the expression (see section on
1623 -- "Handling of Default and Per-Object Expressions" in the spec of
1627 Preanalyze_Spec_Expression (E, T);
1628 Check_Initialization (T, E);
1630 if Ada_Version >= Ada_05
1631 and then Ekind (T) = E_Anonymous_Access_Type
1633 -- Check RM 3.9.2(9): "if the expected type for an expression is
1634 -- an anonymous access-to-specific tagged type, then the object
1635 -- designated by the expression shall not be dynamically tagged
1636 -- unless it is a controlling operand in a call on a dispatching
1639 if Is_Tagged_Type (Directly_Designated_Type (T))
1641 Ekind (Directly_Designated_Type (T)) /= E_Class_Wide_Type
1643 Ekind (Directly_Designated_Type (Etype (E))) =
1647 ("access to specific tagged type required (RM 3.9.2(9))", E);
1650 -- (Ada 2005: AI-230): Accessibility check for anonymous
1653 if Type_Access_Level (Etype (E)) > Type_Access_Level (T) then
1655 ("expression has deeper access level than component " &
1656 "(RM 3.10.2 (12.2))", E);
1659 -- The initialization expression is a reference to an access
1660 -- discriminant. The type of the discriminant is always deeper
1661 -- than any access type.
1663 if Ekind (Etype (E)) = E_Anonymous_Access_Type
1664 and then Is_Entity_Name (E)
1665 and then Ekind (Entity (E)) = E_In_Parameter
1666 and then Present (Discriminal_Link (Entity (E)))
1669 ("discriminant has deeper accessibility level than target",
1675 -- The parent type may be a private view with unknown discriminants,
1676 -- and thus unconstrained. Regular components must be constrained.
1678 if Is_Indefinite_Subtype (T) and then Chars (Id) /= Name_uParent then
1679 if Is_Class_Wide_Type (T) then
1681 ("class-wide subtype with unknown discriminants" &
1682 " in component declaration",
1683 Subtype_Indication (Component_Definition (N)));
1686 ("unconstrained subtype in component declaration",
1687 Subtype_Indication (Component_Definition (N)));
1690 -- Components cannot be abstract, except for the special case of
1691 -- the _Parent field (case of extending an abstract tagged type)
1693 elsif Is_Abstract_Type (T) and then Chars (Id) /= Name_uParent then
1694 Error_Msg_N ("type of a component cannot be abstract", N);
1698 Set_Is_Aliased (Id, Aliased_Present (Component_Definition (N)));
1700 -- The component declaration may have a per-object constraint, set
1701 -- the appropriate flag in the defining identifier of the subtype.
1703 if Present (Subtype_Indication (Component_Definition (N))) then
1705 Sindic : constant Node_Id :=
1706 Subtype_Indication (Component_Definition (N));
1708 if Nkind (Sindic) = N_Subtype_Indication
1709 and then Present (Constraint (Sindic))
1710 and then Contains_POC (Constraint (Sindic))
1712 Set_Has_Per_Object_Constraint (Id);
1717 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
1718 -- out some static checks.
1720 if Ada_Version >= Ada_05
1721 and then Can_Never_Be_Null (T)
1723 Null_Exclusion_Static_Checks (N);
1726 -- If this component is private (or depends on a private type), flag the
1727 -- record type to indicate that some operations are not available.
1729 P := Private_Component (T);
1733 -- Check for circular definitions
1735 if P = Any_Type then
1736 Set_Etype (Id, Any_Type);
1738 -- There is a gap in the visibility of operations only if the
1739 -- component type is not defined in the scope of the record type.
1741 elsif Scope (P) = Scope (Current_Scope) then
1744 elsif Is_Limited_Type (P) then
1745 Set_Is_Limited_Composite (Current_Scope);
1748 Set_Is_Private_Composite (Current_Scope);
1753 and then Is_Limited_Type (T)
1754 and then Chars (Id) /= Name_uParent
1755 and then Is_Tagged_Type (Current_Scope)
1757 if Is_Derived_Type (Current_Scope)
1758 and then not Is_Known_Limited (Current_Scope)
1761 ("extension of nonlimited type cannot have limited components",
1764 if Is_Interface (Root_Type (Current_Scope)) then
1766 ("\limitedness is not inherited from limited interface", N);
1768 ("\add LIMITED to type indication", N);
1771 Explain_Limited_Type (T, N);
1772 Set_Etype (Id, Any_Type);
1773 Set_Is_Limited_Composite (Current_Scope, False);
1775 elsif not Is_Derived_Type (Current_Scope)
1776 and then not Is_Limited_Record (Current_Scope)
1777 and then not Is_Concurrent_Type (Current_Scope)
1780 ("nonlimited tagged type cannot have limited components", N);
1781 Explain_Limited_Type (T, N);
1782 Set_Etype (Id, Any_Type);
1783 Set_Is_Limited_Composite (Current_Scope, False);
1787 Set_Original_Record_Component (Id, Id);
1788 end Analyze_Component_Declaration;
1790 --------------------------
1791 -- Analyze_Declarations --
1792 --------------------------
1794 procedure Analyze_Declarations (L : List_Id) is
1796 Freeze_From : Entity_Id := Empty;
1797 Next_Node : Node_Id;
1800 -- Adjust D not to include implicit label declarations, since these
1801 -- have strange Sloc values that result in elaboration check problems.
1802 -- (They have the sloc of the label as found in the source, and that
1803 -- is ahead of the current declarative part).
1809 procedure Adjust_D is
1811 while Present (Prev (D))
1812 and then Nkind (D) = N_Implicit_Label_Declaration
1818 -- Start of processing for Analyze_Declarations
1822 while Present (D) loop
1824 -- Complete analysis of declaration
1827 Next_Node := Next (D);
1829 if No (Freeze_From) then
1830 Freeze_From := First_Entity (Current_Scope);
1833 -- At the end of a declarative part, freeze remaining entities
1834 -- declared in it. The end of the visible declarations of package
1835 -- specification is not the end of a declarative part if private
1836 -- declarations are present. The end of a package declaration is a
1837 -- freezing point only if it a library package. A task definition or
1838 -- protected type definition is not a freeze point either. Finally,
1839 -- we do not freeze entities in generic scopes, because there is no
1840 -- code generated for them and freeze nodes will be generated for
1843 -- The end of a package instantiation is not a freeze point, but
1844 -- for now we make it one, because the generic body is inserted
1845 -- (currently) immediately after. Generic instantiations will not
1846 -- be a freeze point once delayed freezing of bodies is implemented.
1847 -- (This is needed in any case for early instantiations ???).
1849 if No (Next_Node) then
1850 if Nkind_In (Parent (L), N_Component_List,
1852 N_Protected_Definition)
1856 elsif Nkind (Parent (L)) /= N_Package_Specification then
1857 if Nkind (Parent (L)) = N_Package_Body then
1858 Freeze_From := First_Entity (Current_Scope);
1862 Freeze_All (Freeze_From, D);
1863 Freeze_From := Last_Entity (Current_Scope);
1865 elsif Scope (Current_Scope) /= Standard_Standard
1866 and then not Is_Child_Unit (Current_Scope)
1867 and then No (Generic_Parent (Parent (L)))
1871 elsif L /= Visible_Declarations (Parent (L))
1872 or else No (Private_Declarations (Parent (L)))
1873 or else Is_Empty_List (Private_Declarations (Parent (L)))
1876 Freeze_All (Freeze_From, D);
1877 Freeze_From := Last_Entity (Current_Scope);
1880 -- If next node is a body then freeze all types before the body.
1881 -- An exception occurs for some expander-generated bodies. If these
1882 -- are generated at places where in general language rules would not
1883 -- allow a freeze point, then we assume that the expander has
1884 -- explicitly checked that all required types are properly frozen,
1885 -- and we do not cause general freezing here. This special circuit
1886 -- is used when the encountered body is marked as having already
1889 -- In all other cases (bodies that come from source, and expander
1890 -- generated bodies that have not been analyzed yet), freeze all
1891 -- types now. Note that in the latter case, the expander must take
1892 -- care to attach the bodies at a proper place in the tree so as to
1893 -- not cause unwanted freezing at that point.
1895 elsif not Analyzed (Next_Node)
1896 and then (Nkind_In (Next_Node, N_Subprogram_Body,
1902 Nkind (Next_Node) in N_Body_Stub)
1905 Freeze_All (Freeze_From, D);
1906 Freeze_From := Last_Entity (Current_Scope);
1911 end Analyze_Declarations;
1913 ----------------------------------
1914 -- Analyze_Incomplete_Type_Decl --
1915 ----------------------------------
1917 procedure Analyze_Incomplete_Type_Decl (N : Node_Id) is
1918 F : constant Boolean := Is_Pure (Current_Scope);
1922 Generate_Definition (Defining_Identifier (N));
1924 -- Process an incomplete declaration. The identifier must not have been
1925 -- declared already in the scope. However, an incomplete declaration may
1926 -- appear in the private part of a package, for a private type that has
1927 -- already been declared.
1929 -- In this case, the discriminants (if any) must match
1931 T := Find_Type_Name (N);
1933 Set_Ekind (T, E_Incomplete_Type);
1934 Init_Size_Align (T);
1935 Set_Is_First_Subtype (T, True);
1938 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
1939 -- incomplete types.
1941 if Tagged_Present (N) then
1942 Set_Is_Tagged_Type (T);
1943 Make_Class_Wide_Type (T);
1944 Set_Primitive_Operations (T, New_Elmt_List);
1949 Set_Stored_Constraint (T, No_Elist);
1951 if Present (Discriminant_Specifications (N)) then
1952 Process_Discriminants (N);
1957 -- If the type has discriminants, non-trivial subtypes may be be
1958 -- declared before the full view of the type. The full views of those
1959 -- subtypes will be built after the full view of the type.
1961 Set_Private_Dependents (T, New_Elmt_List);
1963 end Analyze_Incomplete_Type_Decl;
1965 -----------------------------------
1966 -- Analyze_Interface_Declaration --
1967 -----------------------------------
1969 procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id) is
1970 CW : constant Entity_Id := Class_Wide_Type (T);
1973 Set_Is_Tagged_Type (T);
1975 Set_Is_Limited_Record (T, Limited_Present (Def)
1976 or else Task_Present (Def)
1977 or else Protected_Present (Def)
1978 or else Synchronized_Present (Def));
1980 -- Type is abstract if full declaration carries keyword, or if previous
1981 -- partial view did.
1983 Set_Is_Abstract_Type (T);
1984 Set_Is_Interface (T);
1986 -- Type is a limited interface if it includes the keyword limited, task,
1987 -- protected, or synchronized.
1989 Set_Is_Limited_Interface
1990 (T, Limited_Present (Def)
1991 or else Protected_Present (Def)
1992 or else Synchronized_Present (Def)
1993 or else Task_Present (Def));
1995 Set_Is_Protected_Interface (T, Protected_Present (Def));
1996 Set_Is_Task_Interface (T, Task_Present (Def));
1998 -- Type is a synchronized interface if it includes the keyword task,
1999 -- protected, or synchronized.
2001 Set_Is_Synchronized_Interface
2002 (T, Synchronized_Present (Def)
2003 or else Protected_Present (Def)
2004 or else Task_Present (Def));
2006 Set_Interfaces (T, New_Elmt_List);
2007 Set_Primitive_Operations (T, New_Elmt_List);
2009 -- Complete the decoration of the class-wide entity if it was already
2010 -- built (i.e. during the creation of the limited view)
2012 if Present (CW) then
2013 Set_Is_Interface (CW);
2014 Set_Is_Limited_Interface (CW, Is_Limited_Interface (T));
2015 Set_Is_Protected_Interface (CW, Is_Protected_Interface (T));
2016 Set_Is_Synchronized_Interface (CW, Is_Synchronized_Interface (T));
2017 Set_Is_Task_Interface (CW, Is_Task_Interface (T));
2020 -- Check runtime support for synchronized interfaces
2022 if VM_Target = No_VM
2023 and then (Is_Task_Interface (T)
2024 or else Is_Protected_Interface (T)
2025 or else Is_Synchronized_Interface (T))
2026 and then not RTE_Available (RE_Select_Specific_Data)
2028 Error_Msg_CRT ("synchronized interfaces", T);
2030 end Analyze_Interface_Declaration;
2032 -----------------------------
2033 -- Analyze_Itype_Reference --
2034 -----------------------------
2036 -- Nothing to do. This node is placed in the tree only for the benefit of
2037 -- back end processing, and has no effect on the semantic processing.
2039 procedure Analyze_Itype_Reference (N : Node_Id) is
2041 pragma Assert (Is_Itype (Itype (N)));
2043 end Analyze_Itype_Reference;
2045 --------------------------------
2046 -- Analyze_Number_Declaration --
2047 --------------------------------
2049 procedure Analyze_Number_Declaration (N : Node_Id) is
2050 Id : constant Entity_Id := Defining_Identifier (N);
2051 E : constant Node_Id := Expression (N);
2053 Index : Interp_Index;
2057 Generate_Definition (Id);
2060 -- This is an optimization of a common case of an integer literal
2062 if Nkind (E) = N_Integer_Literal then
2063 Set_Is_Static_Expression (E, True);
2064 Set_Etype (E, Universal_Integer);
2066 Set_Etype (Id, Universal_Integer);
2067 Set_Ekind (Id, E_Named_Integer);
2068 Set_Is_Frozen (Id, True);
2072 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2074 -- Process expression, replacing error by integer zero, to avoid
2075 -- cascaded errors or aborts further along in the processing
2077 -- Replace Error by integer zero, which seems least likely to
2078 -- cause cascaded errors.
2081 Rewrite (E, Make_Integer_Literal (Sloc (E), Uint_0));
2082 Set_Error_Posted (E);
2087 -- Verify that the expression is static and numeric. If
2088 -- the expression is overloaded, we apply the preference
2089 -- rule that favors root numeric types.
2091 if not Is_Overloaded (E) then
2097 Get_First_Interp (E, Index, It);
2098 while Present (It.Typ) loop
2099 if (Is_Integer_Type (It.Typ)
2100 or else Is_Real_Type (It.Typ))
2101 and then (Scope (Base_Type (It.Typ))) = Standard_Standard
2103 if T = Any_Type then
2106 elsif It.Typ = Universal_Real
2107 or else It.Typ = Universal_Integer
2109 -- Choose universal interpretation over any other
2116 Get_Next_Interp (Index, It);
2120 if Is_Integer_Type (T) then
2122 Set_Etype (Id, Universal_Integer);
2123 Set_Ekind (Id, E_Named_Integer);
2125 elsif Is_Real_Type (T) then
2127 -- Because the real value is converted to universal_real, this is a
2128 -- legal context for a universal fixed expression.
2130 if T = Universal_Fixed then
2132 Loc : constant Source_Ptr := Sloc (N);
2133 Conv : constant Node_Id := Make_Type_Conversion (Loc,
2135 New_Occurrence_Of (Universal_Real, Loc),
2136 Expression => Relocate_Node (E));
2143 elsif T = Any_Fixed then
2144 Error_Msg_N ("illegal context for mixed mode operation", E);
2146 -- Expression is of the form : universal_fixed * integer. Try to
2147 -- resolve as universal_real.
2149 T := Universal_Real;
2154 Set_Etype (Id, Universal_Real);
2155 Set_Ekind (Id, E_Named_Real);
2158 Wrong_Type (E, Any_Numeric);
2162 Set_Ekind (Id, E_Constant);
2163 Set_Never_Set_In_Source (Id, True);
2164 Set_Is_True_Constant (Id, True);
2168 if Nkind_In (E, N_Integer_Literal, N_Real_Literal) then
2169 Set_Etype (E, Etype (Id));
2172 if not Is_OK_Static_Expression (E) then
2173 Flag_Non_Static_Expr
2174 ("non-static expression used in number declaration!", E);
2175 Rewrite (E, Make_Integer_Literal (Sloc (N), 1));
2176 Set_Etype (E, Any_Type);
2178 end Analyze_Number_Declaration;
2180 --------------------------------
2181 -- Analyze_Object_Declaration --
2182 --------------------------------
2184 procedure Analyze_Object_Declaration (N : Node_Id) is
2185 Loc : constant Source_Ptr := Sloc (N);
2186 Id : constant Entity_Id := Defining_Identifier (N);
2190 E : Node_Id := Expression (N);
2191 -- E is set to Expression (N) throughout this routine. When
2192 -- Expression (N) is modified, E is changed accordingly.
2194 Prev_Entity : Entity_Id := Empty;
2196 function Count_Tasks (T : Entity_Id) return Uint;
2197 -- This function is called when a non-generic library level object of a
2198 -- task type is declared. Its function is to count the static number of
2199 -- tasks declared within the type (it is only called if Has_Tasks is set
2200 -- for T). As a side effect, if an array of tasks with non-static bounds
2201 -- or a variant record type is encountered, Check_Restrictions is called
2202 -- indicating the count is unknown.
2208 function Count_Tasks (T : Entity_Id) return Uint is
2214 if Is_Task_Type (T) then
2217 elsif Is_Record_Type (T) then
2218 if Has_Discriminants (T) then
2219 Check_Restriction (Max_Tasks, N);
2224 C := First_Component (T);
2225 while Present (C) loop
2226 V := V + Count_Tasks (Etype (C));
2233 elsif Is_Array_Type (T) then
2234 X := First_Index (T);
2235 V := Count_Tasks (Component_Type (T));
2236 while Present (X) loop
2239 if not Is_Static_Subtype (C) then
2240 Check_Restriction (Max_Tasks, N);
2243 V := V * (UI_Max (Uint_0,
2244 Expr_Value (Type_High_Bound (C)) -
2245 Expr_Value (Type_Low_Bound (C)) + Uint_1));
2258 -- Start of processing for Analyze_Object_Declaration
2261 -- There are three kinds of implicit types generated by an
2262 -- object declaration:
2264 -- 1. Those for generated by the original Object Definition
2266 -- 2. Those generated by the Expression
2268 -- 3. Those used to constrained the Object Definition with the
2269 -- expression constraints when it is unconstrained
2271 -- They must be generated in this order to avoid order of elaboration
2272 -- issues. Thus the first step (after entering the name) is to analyze
2273 -- the object definition.
2275 if Constant_Present (N) then
2276 Prev_Entity := Current_Entity_In_Scope (Id);
2278 -- If the homograph is an implicit subprogram, it is overridden by
2279 -- the current declaration.
2281 if Present (Prev_Entity)
2283 ((Is_Overloadable (Prev_Entity)
2284 and then Is_Inherited_Operation (Prev_Entity))
2286 -- The current object is a discriminal generated for an entry
2287 -- family index. Even though the index is a constant, in this
2288 -- particular context there is no true constant redeclaration.
2289 -- Enter_Name will handle the visibility.
2292 (Is_Discriminal (Id)
2293 and then Ekind (Discriminal_Link (Id)) =
2294 E_Entry_Index_Parameter))
2296 Prev_Entity := Empty;
2300 if Present (Prev_Entity) then
2301 Constant_Redeclaration (Id, N, T);
2303 Generate_Reference (Prev_Entity, Id, 'c');
2304 Set_Completion_Referenced (Id);
2306 if Error_Posted (N) then
2308 -- Type mismatch or illegal redeclaration, Do not analyze
2309 -- expression to avoid cascaded errors.
2311 T := Find_Type_Of_Object (Object_Definition (N), N);
2313 Set_Ekind (Id, E_Variable);
2317 -- In the normal case, enter identifier at the start to catch premature
2318 -- usage in the initialization expression.
2321 Generate_Definition (Id);
2324 Mark_Coextensions (N, Object_Definition (N));
2326 T := Find_Type_Of_Object (Object_Definition (N), N);
2328 if Nkind (Object_Definition (N)) = N_Access_Definition
2330 (Access_To_Subprogram_Definition (Object_Definition (N)))
2331 and then Protected_Present
2332 (Access_To_Subprogram_Definition (Object_Definition (N)))
2334 T := Replace_Anonymous_Access_To_Protected_Subprogram (N);
2337 if Error_Posted (Id) then
2339 Set_Ekind (Id, E_Variable);
2344 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2345 -- out some static checks
2347 if Ada_Version >= Ada_05
2348 and then Can_Never_Be_Null (T)
2350 -- In case of aggregates we must also take care of the correct
2351 -- initialization of nested aggregates bug this is done at the
2352 -- point of the analysis of the aggregate (see sem_aggr.adb)
2354 if Present (Expression (N))
2355 and then Nkind (Expression (N)) = N_Aggregate
2361 Save_Typ : constant Entity_Id := Etype (Id);
2363 Set_Etype (Id, T); -- Temp. decoration for static checks
2364 Null_Exclusion_Static_Checks (N);
2365 Set_Etype (Id, Save_Typ);
2370 Set_Is_Pure (Id, Is_Pure (Current_Scope));
2372 -- If deferred constant, make sure context is appropriate. We detect
2373 -- a deferred constant as a constant declaration with no expression.
2374 -- A deferred constant can appear in a package body if its completion
2375 -- is by means of an interface pragma.
2377 if Constant_Present (N)
2380 -- We exclude forward references to tags
2382 if Is_Imported (Defining_Identifier (N))
2386 (Present (Full_View (T))
2387 and then Full_View (T) = RTE (RE_Tag)))
2391 -- A deferred constant may appear in the declarative part of the
2392 -- following constructs:
2396 -- extended return statements
2399 -- subprogram bodies
2402 -- When declared inside a package spec, a deferred constant must be
2403 -- completed by a full constant declaration or pragma Import. In all
2404 -- other cases, the only proper completion is pragma Import. Extended
2405 -- return statements are flagged as invalid contexts because they do
2406 -- not have a declarative part and so cannot accommodate the pragma.
2408 elsif Ekind (Current_Scope) = E_Return_Statement then
2410 ("invalid context for deferred constant declaration (RM 7.4)",
2413 ("\declaration requires an initialization expression",
2415 Set_Constant_Present (N, False);
2417 -- In Ada 83, deferred constant must be of private type
2419 elsif not Is_Private_Type (T) then
2420 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2422 ("(Ada 83) deferred constant must be private type", N);
2426 -- If not a deferred constant, then object declaration freezes its type
2429 Check_Fully_Declared (T, N);
2430 Freeze_Before (N, T);
2433 -- If the object was created by a constrained array definition, then
2434 -- set the link in both the anonymous base type and anonymous subtype
2435 -- that are built to represent the array type to point to the object.
2437 if Nkind (Object_Definition (Declaration_Node (Id))) =
2438 N_Constrained_Array_Definition
2440 Set_Related_Array_Object (T, Id);
2441 Set_Related_Array_Object (Base_Type (T), Id);
2444 -- Special checks for protected objects not at library level
2446 if Is_Protected_Type (T)
2447 and then not Is_Library_Level_Entity (Id)
2449 Check_Restriction (No_Local_Protected_Objects, Id);
2451 -- Protected objects with interrupt handlers must be at library level
2453 -- Ada 2005: this test is not needed (and the corresponding clause
2454 -- in the RM is removed) because accessibility checks are sufficient
2455 -- to make handlers not at the library level illegal.
2457 if Has_Interrupt_Handler (T)
2458 and then Ada_Version < Ada_05
2461 ("interrupt object can only be declared at library level", Id);
2465 -- The actual subtype of the object is the nominal subtype, unless
2466 -- the nominal one is unconstrained and obtained from the expression.
2470 -- Process initialization expression if present and not in error
2472 if Present (E) and then E /= Error then
2474 -- Generate an error in case of CPP class-wide object initialization.
2475 -- Required because otherwise the expansion of the class-wide
2476 -- assignment would try to use 'size to initialize the object
2477 -- (primitive that is not available in CPP tagged types).
2479 if Is_Class_Wide_Type (Act_T)
2481 (Is_CPP_Class (Root_Type (Etype (Act_T)))
2483 (Present (Full_View (Root_Type (Etype (Act_T))))
2485 Is_CPP_Class (Full_View (Root_Type (Etype (Act_T))))))
2488 ("predefined assignment not available for 'C'P'P tagged types",
2492 Mark_Coextensions (N, E);
2495 -- In case of errors detected in the analysis of the expression,
2496 -- decorate it with the expected type to avoid cascaded errors
2498 if No (Etype (E)) then
2502 -- If an initialization expression is present, then we set the
2503 -- Is_True_Constant flag. It will be reset if this is a variable
2504 -- and it is indeed modified.
2506 Set_Is_True_Constant (Id, True);
2508 -- If we are analyzing a constant declaration, set its completion
2509 -- flag after analyzing and resolving the expression.
2511 if Constant_Present (N) then
2512 Set_Has_Completion (Id);
2515 -- Set type and resolve (type may be overridden later on)
2520 -- If the object is an access to variable, the initialization
2521 -- expression cannot be an access to constant.
2523 if Is_Access_Type (T)
2524 and then not Is_Access_Constant (T)
2525 and then Is_Access_Type (Etype (E))
2526 and then Is_Access_Constant (Etype (E))
2529 ("object that is an access to variable cannot be initialized " &
2530 "with an access-to-constant expression", E);
2533 if not Assignment_OK (N) then
2534 Check_Initialization (T, E);
2537 Check_Unset_Reference (E);
2539 -- If this is a variable, then set current value
2541 if not Constant_Present (N) then
2542 if Compile_Time_Known_Value (E) then
2543 Set_Current_Value (Id, E);
2547 -- Deal with setting of null flags
2549 if Is_Access_Type (T) then
2550 if Known_Non_Null (E) then
2551 Set_Is_Known_Non_Null (Id, True);
2552 elsif Known_Null (E)
2553 and then not Can_Never_Be_Null (Id)
2555 Set_Is_Known_Null (Id, True);
2559 -- Check incorrect use of dynamically tagged expressions. Note
2560 -- the use of Is_Tagged_Type (T) which seems redundant but is in
2561 -- fact important to avoid spurious errors due to expanded code
2562 -- for dispatching functions over an anonymous access type
2564 if (Is_Class_Wide_Type (Etype (E)) or else Is_Dynamically_Tagged (E))
2565 and then Is_Tagged_Type (T)
2566 and then not Is_Class_Wide_Type (T)
2568 Error_Msg_N ("dynamically tagged expression not allowed!", E);
2571 Apply_Scalar_Range_Check (E, T);
2572 Apply_Static_Length_Check (E, T);
2575 -- If the No_Streams restriction is set, check that the type of the
2576 -- object is not, and does not contain, any subtype derived from
2577 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
2578 -- Has_Stream just for efficiency reasons. There is no point in
2579 -- spending time on a Has_Stream check if the restriction is not set.
2581 if Restrictions.Set (No_Streams) then
2582 if Has_Stream (T) then
2583 Check_Restriction (No_Streams, N);
2587 -- Abstract type is never permitted for a variable or constant.
2588 -- Note: we inhibit this check for objects that do not come from
2589 -- source because there is at least one case (the expansion of
2590 -- x'class'input where x is abstract) where we legitimately
2591 -- generate an abstract object.
2593 if Is_Abstract_Type (T) and then Comes_From_Source (N) then
2594 Error_Msg_N ("type of object cannot be abstract",
2595 Object_Definition (N));
2597 if Is_CPP_Class (T) then
2598 Error_Msg_NE ("\} may need a cpp_constructor",
2599 Object_Definition (N), T);
2602 -- Case of unconstrained type
2604 elsif Is_Indefinite_Subtype (T) then
2606 -- Nothing to do in deferred constant case
2608 if Constant_Present (N) and then No (E) then
2611 -- Case of no initialization present
2614 if No_Initialization (N) then
2617 elsif Is_Class_Wide_Type (T) then
2619 ("initialization required in class-wide declaration ", N);
2623 ("unconstrained subtype not allowed (need initialization)",
2624 Object_Definition (N));
2626 if Is_Record_Type (T) and then Has_Discriminants (T) then
2628 ("\provide initial value or explicit discriminant values",
2629 Object_Definition (N));
2632 ("\or give default discriminant values for type&",
2633 Object_Definition (N), T);
2635 elsif Is_Array_Type (T) then
2637 ("\provide initial value or explicit array bounds",
2638 Object_Definition (N));
2642 -- Case of initialization present but in error. Set initial
2643 -- expression as absent (but do not make above complaints)
2645 elsif E = Error then
2646 Set_Expression (N, Empty);
2649 -- Case of initialization present
2652 -- Not allowed in Ada 83
2654 if not Constant_Present (N) then
2655 if Ada_Version = Ada_83
2656 and then Comes_From_Source (Object_Definition (N))
2659 ("(Ada 83) unconstrained variable not allowed",
2660 Object_Definition (N));
2664 -- Now we constrain the variable from the initializing expression
2666 -- If the expression is an aggregate, it has been expanded into
2667 -- individual assignments. Retrieve the actual type from the
2668 -- expanded construct.
2670 if Is_Array_Type (T)
2671 and then No_Initialization (N)
2672 and then Nkind (Original_Node (E)) = N_Aggregate
2677 Expand_Subtype_From_Expr (N, T, Object_Definition (N), E);
2678 Act_T := Find_Type_Of_Object (Object_Definition (N), N);
2681 Set_Is_Constr_Subt_For_U_Nominal (Act_T);
2683 if Aliased_Present (N) then
2684 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2687 Freeze_Before (N, Act_T);
2688 Freeze_Before (N, T);
2691 elsif Is_Array_Type (T)
2692 and then No_Initialization (N)
2693 and then Nkind (Original_Node (E)) = N_Aggregate
2695 if not Is_Entity_Name (Object_Definition (N)) then
2697 Check_Compile_Time_Size (Act_T);
2699 if Aliased_Present (N) then
2700 Set_Is_Constr_Subt_For_UN_Aliased (Act_T);
2704 -- When the given object definition and the aggregate are specified
2705 -- independently, and their lengths might differ do a length check.
2706 -- This cannot happen if the aggregate is of the form (others =>...)
2708 if not Is_Constrained (T) then
2711 elsif Nkind (E) = N_Raise_Constraint_Error then
2713 -- Aggregate is statically illegal. Place back in declaration
2715 Set_Expression (N, E);
2716 Set_No_Initialization (N, False);
2718 elsif T = Etype (E) then
2721 elsif Nkind (E) = N_Aggregate
2722 and then Present (Component_Associations (E))
2723 and then Present (Choices (First (Component_Associations (E))))
2724 and then Nkind (First
2725 (Choices (First (Component_Associations (E))))) = N_Others_Choice
2730 Apply_Length_Check (E, T);
2733 -- If the type is limited unconstrained with defaulted discriminants
2734 -- and there is no expression, then the object is constrained by the
2735 -- defaults, so it is worthwhile building the corresponding subtype.
2737 elsif (Is_Limited_Record (T)
2738 or else Is_Concurrent_Type (T))
2739 and then not Is_Constrained (T)
2740 and then Has_Discriminants (T)
2743 Act_T := Build_Default_Subtype (T, N);
2745 -- Ada 2005: a limited object may be initialized by means of an
2746 -- aggregate. If the type has default discriminants it has an
2747 -- unconstrained nominal type, Its actual subtype will be obtained
2748 -- from the aggregate, and not from the default discriminants.
2753 Rewrite (Object_Definition (N), New_Occurrence_Of (Act_T, Loc));
2755 elsif Present (Underlying_Type (T))
2756 and then not Is_Constrained (Underlying_Type (T))
2757 and then Has_Discriminants (Underlying_Type (T))
2758 and then Nkind (E) = N_Function_Call
2759 and then Constant_Present (N)
2761 -- The back-end has problems with constants of a discriminated type
2762 -- with defaults, if the initial value is a function call. We
2763 -- generate an intermediate temporary for the result of the call.
2764 -- It is unclear why this should make it acceptable to gcc. ???
2766 Remove_Side_Effects (E);
2769 -- Check No_Wide_Characters restriction
2771 if T = Standard_Wide_Character
2772 or else T = Standard_Wide_Wide_Character
2773 or else Root_Type (T) = Standard_Wide_String
2774 or else Root_Type (T) = Standard_Wide_Wide_String
2776 Check_Restriction (No_Wide_Characters, Object_Definition (N));
2779 -- Indicate this is not set in source. Certainly true for constants,
2780 -- and true for variables so far (will be reset for a variable if and
2781 -- when we encounter a modification in the source).
2783 Set_Never_Set_In_Source (Id, True);
2785 -- Now establish the proper kind and type of the object
2787 if Constant_Present (N) then
2788 Set_Ekind (Id, E_Constant);
2789 Set_Is_True_Constant (Id, True);
2792 Set_Ekind (Id, E_Variable);
2794 -- A variable is set as shared passive if it appears in a shared
2795 -- passive package, and is at the outer level. This is not done
2796 -- for entities generated during expansion, because those are
2797 -- always manipulated locally.
2799 if Is_Shared_Passive (Current_Scope)
2800 and then Is_Library_Level_Entity (Id)
2801 and then Comes_From_Source (Id)
2803 Set_Is_Shared_Passive (Id);
2804 Check_Shared_Var (Id, T, N);
2807 -- Set Has_Initial_Value if initializing expression present. Note
2808 -- that if there is no initializing expression, we leave the state
2809 -- of this flag unchanged (usually it will be False, but notably in
2810 -- the case of exception choice variables, it will already be true).
2813 Set_Has_Initial_Value (Id, True);
2817 -- Initialize alignment and size and capture alignment setting
2819 Init_Alignment (Id);
2821 Set_Optimize_Alignment_Flags (Id);
2823 -- Deal with aliased case
2825 if Aliased_Present (N) then
2826 Set_Is_Aliased (Id);
2828 -- If the object is aliased and the type is unconstrained with
2829 -- defaulted discriminants and there is no expression, then the
2830 -- object is constrained by the defaults, so it is worthwhile
2831 -- building the corresponding subtype.
2833 -- Ada 2005 (AI-363): If the aliased object is discriminated and
2834 -- unconstrained, then only establish an actual subtype if the
2835 -- nominal subtype is indefinite. In definite cases the object is
2836 -- unconstrained in Ada 2005.
2839 and then Is_Record_Type (T)
2840 and then not Is_Constrained (T)
2841 and then Has_Discriminants (T)
2842 and then (Ada_Version < Ada_05 or else Is_Indefinite_Subtype (T))
2844 Set_Actual_Subtype (Id, Build_Default_Subtype (T, N));
2848 -- Now we can set the type of the object
2850 Set_Etype (Id, Act_T);
2852 -- Deal with controlled types
2854 if Has_Controlled_Component (Etype (Id))
2855 or else Is_Controlled (Etype (Id))
2857 if not Is_Library_Level_Entity (Id) then
2858 Check_Restriction (No_Nested_Finalization, N);
2860 Validate_Controlled_Object (Id);
2863 -- Generate a warning when an initialization causes an obvious ABE
2864 -- violation. If the init expression is a simple aggregate there
2865 -- shouldn't be any initialize/adjust call generated. This will be
2866 -- true as soon as aggregates are built in place when possible.
2868 -- ??? at the moment we do not generate warnings for temporaries
2869 -- created for those aggregates although Program_Error might be
2870 -- generated if compiled with -gnato.
2872 if Is_Controlled (Etype (Id))
2873 and then Comes_From_Source (Id)
2876 BT : constant Entity_Id := Base_Type (Etype (Id));
2878 Implicit_Call : Entity_Id;
2879 pragma Warnings (Off, Implicit_Call);
2880 -- ??? what is this for (never referenced!)
2882 function Is_Aggr (N : Node_Id) return Boolean;
2883 -- Check that N is an aggregate
2889 function Is_Aggr (N : Node_Id) return Boolean is
2891 case Nkind (Original_Node (N)) is
2892 when N_Aggregate | N_Extension_Aggregate =>
2895 when N_Qualified_Expression |
2897 N_Unchecked_Type_Conversion =>
2898 return Is_Aggr (Expression (Original_Node (N)));
2906 -- If no underlying type, we already are in an error situation.
2907 -- Do not try to add a warning since we do not have access to
2910 if No (Underlying_Type (BT)) then
2911 Implicit_Call := Empty;
2913 -- A generic type does not have usable primitive operators.
2914 -- Initialization calls are built for instances.
2916 elsif Is_Generic_Type (BT) then
2917 Implicit_Call := Empty;
2919 -- If the init expression is not an aggregate, an adjust call
2920 -- will be generated
2922 elsif Present (E) and then not Is_Aggr (E) then
2923 Implicit_Call := Find_Prim_Op (BT, Name_Adjust);
2925 -- If no init expression and we are not in the deferred
2926 -- constant case, an Initialize call will be generated
2928 elsif No (E) and then not Constant_Present (N) then
2929 Implicit_Call := Find_Prim_Op (BT, Name_Initialize);
2932 Implicit_Call := Empty;
2938 if Has_Task (Etype (Id)) then
2939 Check_Restriction (No_Tasking, N);
2941 -- Deal with counting max tasks
2943 -- Nothing to do if inside a generic
2945 if Inside_A_Generic then
2948 -- If library level entity, then count tasks
2950 elsif Is_Library_Level_Entity (Id) then
2951 Check_Restriction (Max_Tasks, N, Count_Tasks (Etype (Id)));
2953 -- If not library level entity, then indicate we don't know max
2954 -- tasks and also check task hierarchy restriction and blocking
2955 -- operation (since starting a task is definitely blocking!)
2958 Check_Restriction (Max_Tasks, N);
2959 Check_Restriction (No_Task_Hierarchy, N);
2960 Check_Potentially_Blocking_Operation (N);
2963 -- A rather specialized test. If we see two tasks being declared
2964 -- of the same type in the same object declaration, and the task
2965 -- has an entry with an address clause, we know that program error
2966 -- will be raised at run-time since we can't have two tasks with
2967 -- entries at the same address.
2969 if Is_Task_Type (Etype (Id)) and then More_Ids (N) then
2974 E := First_Entity (Etype (Id));
2975 while Present (E) loop
2976 if Ekind (E) = E_Entry
2977 and then Present (Get_Attribute_Definition_Clause
2978 (E, Attribute_Address))
2981 ("?more than one task with same entry address", N);
2983 ("\?Program_Error will be raised at run time", N);
2985 Make_Raise_Program_Error (Loc,
2986 Reason => PE_Duplicated_Entry_Address));
2996 -- Some simple constant-propagation: if the expression is a constant
2997 -- string initialized with a literal, share the literal. This avoids
3001 and then Is_Entity_Name (E)
3002 and then Ekind (Entity (E)) = E_Constant
3003 and then Base_Type (Etype (E)) = Standard_String
3006 Val : constant Node_Id := Constant_Value (Entity (E));
3009 and then Nkind (Val) = N_String_Literal
3011 Rewrite (E, New_Copy (Val));
3016 -- Another optimization: if the nominal subtype is unconstrained and
3017 -- the expression is a function call that returns an unconstrained
3018 -- type, rewrite the declaration as a renaming of the result of the
3019 -- call. The exceptions below are cases where the copy is expected,
3020 -- either by the back end (Aliased case) or by the semantics, as for
3021 -- initializing controlled types or copying tags for classwide types.
3024 and then Nkind (E) = N_Explicit_Dereference
3025 and then Nkind (Original_Node (E)) = N_Function_Call
3026 and then not Is_Library_Level_Entity (Id)
3027 and then not Is_Constrained (Underlying_Type (T))
3028 and then not Is_Aliased (Id)
3029 and then not Is_Class_Wide_Type (T)
3030 and then not Is_Controlled (T)
3031 and then not Has_Controlled_Component (Base_Type (T))
3032 and then Expander_Active
3035 Make_Object_Renaming_Declaration (Loc,
3036 Defining_Identifier => Id,
3037 Access_Definition => Empty,
3038 Subtype_Mark => New_Occurrence_Of
3039 (Base_Type (Etype (Id)), Loc),
3042 Set_Renamed_Object (Id, E);
3044 -- Force generation of debugging information for the constant and for
3045 -- the renamed function call.
3047 Set_Debug_Info_Needed (Id);
3048 Set_Debug_Info_Needed (Entity (Prefix (E)));
3051 if Present (Prev_Entity)
3052 and then Is_Frozen (Prev_Entity)
3053 and then not Error_Posted (Id)
3055 Error_Msg_N ("full constant declaration appears too late", N);
3058 Check_Eliminated (Id);
3060 -- Deal with setting In_Private_Part flag if in private part
3062 if Ekind (Scope (Id)) = E_Package
3063 and then In_Private_Part (Scope (Id))
3065 Set_In_Private_Part (Id);
3068 -- Check for violation of No_Local_Timing_Events
3070 if Is_RTE (Etype (Id), RE_Timing_Event)
3071 and then not Is_Library_Level_Entity (Id)
3073 Check_Restriction (No_Local_Timing_Events, N);
3075 end Analyze_Object_Declaration;
3077 ---------------------------
3078 -- Analyze_Others_Choice --
3079 ---------------------------
3081 -- Nothing to do for the others choice node itself, the semantic analysis
3082 -- of the others choice will occur as part of the processing of the parent
3084 procedure Analyze_Others_Choice (N : Node_Id) is
3085 pragma Warnings (Off, N);
3088 end Analyze_Others_Choice;
3090 -------------------------------------------
3091 -- Analyze_Private_Extension_Declaration --
3092 -------------------------------------------
3094 procedure Analyze_Private_Extension_Declaration (N : Node_Id) is
3095 T : constant Entity_Id := Defining_Identifier (N);
3096 Indic : constant Node_Id := Subtype_Indication (N);
3097 Parent_Type : Entity_Id;
3098 Parent_Base : Entity_Id;
3101 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
3103 if Is_Non_Empty_List (Interface_List (N)) then
3109 Intf := First (Interface_List (N));
3110 while Present (Intf) loop
3111 T := Find_Type_Of_Subtype_Indic (Intf);
3113 Diagnose_Interface (Intf, T);
3119 Generate_Definition (T);
3122 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
3123 Parent_Base := Base_Type (Parent_Type);
3125 if Parent_Type = Any_Type
3126 or else Etype (Parent_Type) = Any_Type
3128 Set_Ekind (T, Ekind (Parent_Type));
3129 Set_Etype (T, Any_Type);
3132 elsif not Is_Tagged_Type (Parent_Type) then
3134 ("parent of type extension must be a tagged type ", Indic);
3137 elsif Ekind (Parent_Type) = E_Void
3138 or else Ekind (Parent_Type) = E_Incomplete_Type
3140 Error_Msg_N ("premature derivation of incomplete type", Indic);
3143 elsif Is_Concurrent_Type (Parent_Type) then
3145 ("parent type of a private extension cannot be "
3146 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
3148 Set_Etype (T, Any_Type);
3149 Set_Ekind (T, E_Limited_Private_Type);
3150 Set_Private_Dependents (T, New_Elmt_List);
3151 Set_Error_Posted (T);
3155 -- Perhaps the parent type should be changed to the class-wide type's
3156 -- specific type in this case to prevent cascading errors ???
3158 if Is_Class_Wide_Type (Parent_Type) then
3160 ("parent of type extension must not be a class-wide type", Indic);
3164 if (not Is_Package_Or_Generic_Package (Current_Scope)
3165 and then Nkind (Parent (N)) /= N_Generic_Subprogram_Declaration)
3166 or else In_Private_Part (Current_Scope)
3169 Error_Msg_N ("invalid context for private extension", N);
3172 -- Set common attributes
3174 Set_Is_Pure (T, Is_Pure (Current_Scope));
3175 Set_Scope (T, Current_Scope);
3176 Set_Ekind (T, E_Record_Type_With_Private);
3177 Init_Size_Align (T);
3179 Set_Etype (T, Parent_Base);
3180 Set_Has_Task (T, Has_Task (Parent_Base));
3182 Set_Convention (T, Convention (Parent_Type));
3183 Set_First_Rep_Item (T, First_Rep_Item (Parent_Type));
3184 Set_Is_First_Subtype (T);
3185 Make_Class_Wide_Type (T);
3187 if Unknown_Discriminants_Present (N) then
3188 Set_Discriminant_Constraint (T, No_Elist);
3191 Build_Derived_Record_Type (N, Parent_Type, T);
3193 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
3194 -- synchronized formal derived type.
3196 if Ada_Version >= Ada_05
3197 and then Synchronized_Present (N)
3199 Set_Is_Limited_Record (T);
3201 -- Formal derived type case
3203 if Is_Generic_Type (T) then
3205 -- The parent must be a tagged limited type or a synchronized
3208 if (not Is_Tagged_Type (Parent_Type)
3209 or else not Is_Limited_Type (Parent_Type))
3211 (not Is_Interface (Parent_Type)
3212 or else not Is_Synchronized_Interface (Parent_Type))
3214 Error_Msg_NE ("parent type of & must be tagged limited " &
3215 "or synchronized", N, T);
3218 -- The progenitors (if any) must be limited or synchronized
3221 if Present (Interfaces (T)) then
3224 Iface_Elmt : Elmt_Id;
3227 Iface_Elmt := First_Elmt (Interfaces (T));
3228 while Present (Iface_Elmt) loop
3229 Iface := Node (Iface_Elmt);
3231 if not Is_Limited_Interface (Iface)
3232 and then not Is_Synchronized_Interface (Iface)
3234 Error_Msg_NE ("progenitor & must be limited " &
3235 "or synchronized", N, Iface);
3238 Next_Elmt (Iface_Elmt);
3243 -- Regular derived extension, the parent must be a limited or
3244 -- synchronized interface.
3247 if not Is_Interface (Parent_Type)
3248 or else (not Is_Limited_Interface (Parent_Type)
3250 not Is_Synchronized_Interface (Parent_Type))
3253 ("parent type of & must be limited interface", N, T);
3257 elsif Limited_Present (N) then
3258 Set_Is_Limited_Record (T);
3260 if not Is_Limited_Type (Parent_Type)
3262 (not Is_Interface (Parent_Type)
3263 or else not Is_Limited_Interface (Parent_Type))
3265 Error_Msg_NE ("parent type& of limited extension must be limited",
3269 end Analyze_Private_Extension_Declaration;
3271 ---------------------------------
3272 -- Analyze_Subtype_Declaration --
3273 ---------------------------------
3275 procedure Analyze_Subtype_Declaration
3277 Skip : Boolean := False)
3279 Id : constant Entity_Id := Defining_Identifier (N);
3281 R_Checks : Check_Result;
3284 Generate_Definition (Id);
3285 Set_Is_Pure (Id, Is_Pure (Current_Scope));
3286 Init_Size_Align (Id);
3288 -- The following guard condition on Enter_Name is to handle cases where
3289 -- the defining identifier has already been entered into the scope but
3290 -- the declaration as a whole needs to be analyzed.
3292 -- This case in particular happens for derived enumeration types. The
3293 -- derived enumeration type is processed as an inserted enumeration type
3294 -- declaration followed by a rewritten subtype declaration. The defining
3295 -- identifier, however, is entered into the name scope very early in the
3296 -- processing of the original type declaration and therefore needs to be
3297 -- avoided here, when the created subtype declaration is analyzed. (See
3298 -- Build_Derived_Types)
3300 -- This also happens when the full view of a private type is derived
3301 -- type with constraints. In this case the entity has been introduced
3302 -- in the private declaration.
3305 or else (Present (Etype (Id))
3306 and then (Is_Private_Type (Etype (Id))
3307 or else Is_Task_Type (Etype (Id))
3308 or else Is_Rewrite_Substitution (N)))
3316 T := Process_Subtype (Subtype_Indication (N), N, Id, 'P');
3318 -- Inherit common attributes
3320 Set_Is_Generic_Type (Id, Is_Generic_Type (Base_Type (T)));
3321 Set_Is_Volatile (Id, Is_Volatile (T));
3322 Set_Treat_As_Volatile (Id, Treat_As_Volatile (T));
3323 Set_Is_Atomic (Id, Is_Atomic (T));
3324 Set_Is_Ada_2005_Only (Id, Is_Ada_2005_Only (T));
3325 Set_Convention (Id, Convention (T));
3327 -- In the case where there is no constraint given in the subtype
3328 -- indication, Process_Subtype just returns the Subtype_Mark, so its
3329 -- semantic attributes must be established here.
3331 if Nkind (Subtype_Indication (N)) /= N_Subtype_Indication then
3332 Set_Etype (Id, Base_Type (T));
3336 Set_Ekind (Id, E_Array_Subtype);
3337 Copy_Array_Subtype_Attributes (Id, T);
3339 when Decimal_Fixed_Point_Kind =>
3340 Set_Ekind (Id, E_Decimal_Fixed_Point_Subtype);
3341 Set_Digits_Value (Id, Digits_Value (T));
3342 Set_Delta_Value (Id, Delta_Value (T));
3343 Set_Scale_Value (Id, Scale_Value (T));
3344 Set_Small_Value (Id, Small_Value (T));
3345 Set_Scalar_Range (Id, Scalar_Range (T));
3346 Set_Machine_Radix_10 (Id, Machine_Radix_10 (T));
3347 Set_Is_Constrained (Id, Is_Constrained (T));
3348 Set_RM_Size (Id, RM_Size (T));
3350 when Enumeration_Kind =>
3351 Set_Ekind (Id, E_Enumeration_Subtype);
3352 Set_First_Literal (Id, First_Literal (Base_Type (T)));
3353 Set_Scalar_Range (Id, Scalar_Range (T));
3354 Set_Is_Character_Type (Id, Is_Character_Type (T));
3355 Set_Is_Constrained (Id, Is_Constrained (T));
3356 Set_RM_Size (Id, RM_Size (T));
3358 when Ordinary_Fixed_Point_Kind =>
3359 Set_Ekind (Id, E_Ordinary_Fixed_Point_Subtype);
3360 Set_Scalar_Range (Id, Scalar_Range (T));
3361 Set_Small_Value (Id, Small_Value (T));
3362 Set_Delta_Value (Id, Delta_Value (T));
3363 Set_Is_Constrained (Id, Is_Constrained (T));
3364 Set_RM_Size (Id, RM_Size (T));
3367 Set_Ekind (Id, E_Floating_Point_Subtype);
3368 Set_Scalar_Range (Id, Scalar_Range (T));
3369 Set_Digits_Value (Id, Digits_Value (T));
3370 Set_Is_Constrained (Id, Is_Constrained (T));
3372 when Signed_Integer_Kind =>
3373 Set_Ekind (Id, E_Signed_Integer_Subtype);
3374 Set_Scalar_Range (Id, Scalar_Range (T));
3375 Set_Is_Constrained (Id, Is_Constrained (T));
3376 Set_RM_Size (Id, RM_Size (T));
3378 when Modular_Integer_Kind =>
3379 Set_Ekind (Id, E_Modular_Integer_Subtype);
3380 Set_Scalar_Range (Id, Scalar_Range (T));
3381 Set_Is_Constrained (Id, Is_Constrained (T));
3382 Set_RM_Size (Id, RM_Size (T));
3384 when Class_Wide_Kind =>
3385 Set_Ekind (Id, E_Class_Wide_Subtype);
3386 Set_First_Entity (Id, First_Entity (T));
3387 Set_Last_Entity (Id, Last_Entity (T));
3388 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3389 Set_Cloned_Subtype (Id, T);
3390 Set_Is_Tagged_Type (Id, True);
3391 Set_Has_Unknown_Discriminants
3394 if Ekind (T) = E_Class_Wide_Subtype then
3395 Set_Equivalent_Type (Id, Equivalent_Type (T));
3398 when E_Record_Type | E_Record_Subtype =>
3399 Set_Ekind (Id, E_Record_Subtype);
3401 if Ekind (T) = E_Record_Subtype
3402 and then Present (Cloned_Subtype (T))
3404 Set_Cloned_Subtype (Id, Cloned_Subtype (T));
3406 Set_Cloned_Subtype (Id, T);
3409 Set_First_Entity (Id, First_Entity (T));
3410 Set_Last_Entity (Id, Last_Entity (T));
3411 Set_Has_Discriminants (Id, Has_Discriminants (T));
3412 Set_Is_Constrained (Id, Is_Constrained (T));
3413 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3414 Set_Has_Unknown_Discriminants
3415 (Id, Has_Unknown_Discriminants (T));
3417 if Has_Discriminants (T) then
3418 Set_Discriminant_Constraint
3419 (Id, Discriminant_Constraint (T));
3420 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3422 elsif Has_Unknown_Discriminants (Id) then
3423 Set_Discriminant_Constraint (Id, No_Elist);
3426 if Is_Tagged_Type (T) then
3427 Set_Is_Tagged_Type (Id);
3428 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3429 Set_Primitive_Operations
3430 (Id, Primitive_Operations (T));
3431 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3433 if Is_Interface (T) then
3434 Set_Is_Interface (Id);
3435 Set_Is_Limited_Interface (Id, Is_Limited_Interface (T));
3439 when Private_Kind =>
3440 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3441 Set_Has_Discriminants (Id, Has_Discriminants (T));
3442 Set_Is_Constrained (Id, Is_Constrained (T));
3443 Set_First_Entity (Id, First_Entity (T));
3444 Set_Last_Entity (Id, Last_Entity (T));
3445 Set_Private_Dependents (Id, New_Elmt_List);
3446 Set_Is_Limited_Record (Id, Is_Limited_Record (T));
3447 Set_Has_Unknown_Discriminants
3448 (Id, Has_Unknown_Discriminants (T));
3449 Set_Known_To_Have_Preelab_Init
3450 (Id, Known_To_Have_Preelab_Init (T));
3452 if Is_Tagged_Type (T) then
3453 Set_Is_Tagged_Type (Id);
3454 Set_Is_Abstract_Type (Id, Is_Abstract_Type (T));
3455 Set_Primitive_Operations (Id, Primitive_Operations (T));
3456 Set_Class_Wide_Type (Id, Class_Wide_Type (T));
3459 -- In general the attributes of the subtype of a private type
3460 -- are the attributes of the partial view of parent. However,
3461 -- the full view may be a discriminated type, and the subtype
3462 -- must share the discriminant constraint to generate correct
3463 -- calls to initialization procedures.
3465 if Has_Discriminants (T) then
3466 Set_Discriminant_Constraint
3467 (Id, Discriminant_Constraint (T));
3468 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3470 elsif Present (Full_View (T))
3471 and then Has_Discriminants (Full_View (T))
3473 Set_Discriminant_Constraint
3474 (Id, Discriminant_Constraint (Full_View (T)));
3475 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3477 -- This would seem semantically correct, but apparently
3478 -- confuses the back-end. To be explained and checked with
3479 -- current version ???
3481 -- Set_Has_Discriminants (Id);
3484 Prepare_Private_Subtype_Completion (Id, N);
3487 Set_Ekind (Id, E_Access_Subtype);
3488 Set_Is_Constrained (Id, Is_Constrained (T));
3489 Set_Is_Access_Constant
3490 (Id, Is_Access_Constant (T));
3491 Set_Directly_Designated_Type
3492 (Id, Designated_Type (T));
3493 Set_Can_Never_Be_Null (Id, Can_Never_Be_Null (T));
3495 -- A Pure library_item must not contain the declaration of a
3496 -- named access type, except within a subprogram, generic
3497 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
3499 if Comes_From_Source (Id)
3500 and then In_Pure_Unit
3501 and then not In_Subprogram_Task_Protected_Unit
3504 ("named access types not allowed in pure unit", N);
3507 when Concurrent_Kind =>
3508 Set_Ekind (Id, Subtype_Kind (Ekind (T)));
3509 Set_Corresponding_Record_Type (Id,
3510 Corresponding_Record_Type (T));
3511 Set_First_Entity (Id, First_Entity (T));
3512 Set_First_Private_Entity (Id, First_Private_Entity (T));
3513 Set_Has_Discriminants (Id, Has_Discriminants (T));
3514 Set_Is_Constrained (Id, Is_Constrained (T));
3515 Set_Is_Tagged_Type (Id, Is_Tagged_Type (T));
3516 Set_Last_Entity (Id, Last_Entity (T));
3518 if Has_Discriminants (T) then
3519 Set_Discriminant_Constraint (Id,
3520 Discriminant_Constraint (T));
3521 Set_Stored_Constraint_From_Discriminant_Constraint (Id);
3524 when E_Incomplete_Type =>
3525 if Ada_Version >= Ada_05 then
3526 Set_Ekind (Id, E_Incomplete_Subtype);
3528 -- Ada 2005 (AI-412): Decorate an incomplete subtype
3529 -- of an incomplete type visible through a limited
3532 if From_With_Type (T)
3533 and then Present (Non_Limited_View (T))
3535 Set_From_With_Type (Id);
3536 Set_Non_Limited_View (Id, Non_Limited_View (T));
3538 -- Ada 2005 (AI-412): Add the regular incomplete subtype
3539 -- to the private dependents of the original incomplete
3540 -- type for future transformation.
3543 Append_Elmt (Id, Private_Dependents (T));
3546 -- If the subtype name denotes an incomplete type an error
3547 -- was already reported by Process_Subtype.
3550 Set_Etype (Id, Any_Type);
3554 raise Program_Error;
3558 if Etype (Id) = Any_Type then
3562 -- Some common processing on all types
3564 Set_Size_Info (Id, T);
3565 Set_First_Rep_Item (Id, First_Rep_Item (T));
3569 Set_Is_Immediately_Visible (Id, True);
3570 Set_Depends_On_Private (Id, Has_Private_Component (T));
3571 Set_Is_Descendent_Of_Address (Id, Is_Descendent_Of_Address (T));
3573 if Is_Interface (T) then
3574 Set_Is_Interface (Id);
3577 if Present (Generic_Parent_Type (N))
3580 (Parent (Generic_Parent_Type (N))) /= N_Formal_Type_Declaration
3582 (Formal_Type_Definition (Parent (Generic_Parent_Type (N))))
3583 /= N_Formal_Private_Type_Definition)
3585 if Is_Tagged_Type (Id) then
3587 -- If this is a generic actual subtype for a synchronized type,
3588 -- the primitive operations are those of the corresponding record
3589 -- for which there is a separate subtype declaration.
3591 if Is_Concurrent_Type (Id) then
3593 elsif Is_Class_Wide_Type (Id) then
3594 Derive_Subprograms (Generic_Parent_Type (N), Id, Etype (T));
3596 Derive_Subprograms (Generic_Parent_Type (N), Id, T);
3599 elsif Scope (Etype (Id)) /= Standard_Standard then
3600 Derive_Subprograms (Generic_Parent_Type (N), Id);
3604 if Is_Private_Type (T)
3605 and then Present (Full_View (T))
3607 Conditional_Delay (Id, Full_View (T));
3609 -- The subtypes of components or subcomponents of protected types
3610 -- do not need freeze nodes, which would otherwise appear in the
3611 -- wrong scope (before the freeze node for the protected type). The
3612 -- proper subtypes are those of the subcomponents of the corresponding
3615 elsif Ekind (Scope (Id)) /= E_Protected_Type
3616 and then Present (Scope (Scope (Id))) -- error defense!
3617 and then Ekind (Scope (Scope (Id))) /= E_Protected_Type
3619 Conditional_Delay (Id, T);
3622 -- Check that constraint_error is raised for a scalar subtype
3623 -- indication when the lower or upper bound of a non-null range
3624 -- lies outside the range of the type mark.
3626 if Nkind (Subtype_Indication (N)) = N_Subtype_Indication then
3627 if Is_Scalar_Type (Etype (Id))
3628 and then Scalar_Range (Id) /=
3629 Scalar_Range (Etype (Subtype_Mark
3630 (Subtype_Indication (N))))
3634 Etype (Subtype_Mark (Subtype_Indication (N))));
3636 elsif Is_Array_Type (Etype (Id))
3637 and then Present (First_Index (Id))
3639 -- This really should be a subprogram that finds the indications
3642 if ((Nkind (First_Index (Id)) = N_Identifier
3643 and then Ekind (Entity (First_Index (Id))) in Scalar_Kind)
3644 or else Nkind (First_Index (Id)) = N_Subtype_Indication)
3646 Nkind (Scalar_Range (Etype (First_Index (Id)))) = N_Range
3649 Target_Typ : constant Entity_Id :=
3652 (Subtype_Mark (Subtype_Indication (N)))));
3656 (Scalar_Range (Etype (First_Index (Id))),
3658 Etype (First_Index (Id)),
3659 Defining_Identifier (N));
3665 Sloc (Defining_Identifier (N)));
3671 Set_Optimize_Alignment_Flags (Id);
3672 Check_Eliminated (Id);
3673 end Analyze_Subtype_Declaration;
3675 --------------------------------
3676 -- Analyze_Subtype_Indication --
3677 --------------------------------
3679 procedure Analyze_Subtype_Indication (N : Node_Id) is
3680 T : constant Entity_Id := Subtype_Mark (N);
3681 R : constant Node_Id := Range_Expression (Constraint (N));
3688 Set_Etype (N, Etype (R));
3689 Resolve (R, Entity (T));
3691 Set_Error_Posted (R);
3692 Set_Error_Posted (T);
3694 end Analyze_Subtype_Indication;
3696 ------------------------------
3697 -- Analyze_Type_Declaration --
3698 ------------------------------
3700 procedure Analyze_Type_Declaration (N : Node_Id) is
3701 Def : constant Node_Id := Type_Definition (N);
3702 Def_Id : constant Entity_Id := Defining_Identifier (N);
3706 Is_Remote : constant Boolean :=
3707 (Is_Remote_Types (Current_Scope)
3708 or else Is_Remote_Call_Interface (Current_Scope))
3709 and then not (In_Private_Part (Current_Scope)
3710 or else In_Package_Body (Current_Scope));
3712 procedure Check_Ops_From_Incomplete_Type;
3713 -- If there is a tagged incomplete partial view of the type, transfer
3714 -- its operations to the full view, and indicate that the type of the
3715 -- controlling parameter (s) is this full view.
3717 ------------------------------------
3718 -- Check_Ops_From_Incomplete_Type --
3719 ------------------------------------
3721 procedure Check_Ops_From_Incomplete_Type is
3728 and then Ekind (Prev) = E_Incomplete_Type
3729 and then Is_Tagged_Type (Prev)
3730 and then Is_Tagged_Type (T)
3732 Elmt := First_Elmt (Primitive_Operations (Prev));
3733 while Present (Elmt) loop
3735 Prepend_Elmt (Op, Primitive_Operations (T));
3737 Formal := First_Formal (Op);
3738 while Present (Formal) loop
3739 if Etype (Formal) = Prev then
3740 Set_Etype (Formal, T);
3743 Next_Formal (Formal);
3746 if Etype (Op) = Prev then
3753 end Check_Ops_From_Incomplete_Type;
3755 -- Start of processing for Analyze_Type_Declaration
3758 Prev := Find_Type_Name (N);
3760 -- The full view, if present, now points to the current type
3762 -- Ada 2005 (AI-50217): If the type was previously decorated when
3763 -- imported through a LIMITED WITH clause, it appears as incomplete
3764 -- but has no full view.
3765 -- If the incomplete view is tagged, a class_wide type has been
3766 -- created already. Use it for the full view as well, to prevent
3767 -- multiple incompatible class-wide types that may be created for
3768 -- self-referential anonymous access components.
3770 if Ekind (Prev) = E_Incomplete_Type
3771 and then Present (Full_View (Prev))
3773 T := Full_View (Prev);
3775 if Is_Tagged_Type (Prev)
3776 and then Present (Class_Wide_Type (Prev))
3778 Set_Ekind (T, Ekind (Prev)); -- will be reset later
3779 Set_Class_Wide_Type (T, Class_Wide_Type (Prev));
3780 Set_Etype (Class_Wide_Type (T), T);
3787 Set_Is_Pure (T, Is_Pure (Current_Scope));
3789 -- We set the flag Is_First_Subtype here. It is needed to set the
3790 -- corresponding flag for the Implicit class-wide-type created
3791 -- during tagged types processing.
3793 Set_Is_First_Subtype (T, True);
3795 -- Only composite types other than array types are allowed to have
3800 -- For derived types, the rule will be checked once we've figured
3801 -- out the parent type.
3803 when N_Derived_Type_Definition =>
3806 -- For record types, discriminants are allowed
3808 when N_Record_Definition =>
3812 if Present (Discriminant_Specifications (N)) then
3814 ("elementary or array type cannot have discriminants",
3816 (First (Discriminant_Specifications (N))));
3820 -- Elaborate the type definition according to kind, and generate
3821 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3822 -- already done (this happens during the reanalysis that follows a call
3823 -- to the high level optimizer).
3825 if not Analyzed (T) then
3830 when N_Access_To_Subprogram_Definition =>
3831 Access_Subprogram_Declaration (T, Def);
3833 -- If this is a remote access to subprogram, we must create the
3834 -- equivalent fat pointer type, and related subprograms.
3837 Process_Remote_AST_Declaration (N);
3840 -- Validate categorization rule against access type declaration
3841 -- usually a violation in Pure unit, Shared_Passive unit.
3843 Validate_Access_Type_Declaration (T, N);
3845 when N_Access_To_Object_Definition =>
3846 Access_Type_Declaration (T, Def);
3848 -- Validate categorization rule against access type declaration
3849 -- usually a violation in Pure unit, Shared_Passive unit.
3851 Validate_Access_Type_Declaration (T, N);
3853 -- If we are in a Remote_Call_Interface package and define a
3854 -- RACW, then calling stubs and specific stream attributes
3858 and then Is_Remote_Access_To_Class_Wide_Type (Def_Id)
3860 Add_RACW_Features (Def_Id);
3863 -- Set no strict aliasing flag if config pragma seen
3865 if Opt.No_Strict_Aliasing then
3866 Set_No_Strict_Aliasing (Base_Type (Def_Id));
3869 when N_Array_Type_Definition =>
3870 Array_Type_Declaration (T, Def);
3872 when N_Derived_Type_Definition =>
3873 Derived_Type_Declaration (T, N, T /= Def_Id);
3875 when N_Enumeration_Type_Definition =>
3876 Enumeration_Type_Declaration (T, Def);
3878 when N_Floating_Point_Definition =>
3879 Floating_Point_Type_Declaration (T, Def);
3881 when N_Decimal_Fixed_Point_Definition =>
3882 Decimal_Fixed_Point_Type_Declaration (T, Def);
3884 when N_Ordinary_Fixed_Point_Definition =>
3885 Ordinary_Fixed_Point_Type_Declaration (T, Def);
3887 when N_Signed_Integer_Type_Definition =>
3888 Signed_Integer_Type_Declaration (T, Def);
3890 when N_Modular_Type_Definition =>
3891 Modular_Type_Declaration (T, Def);
3893 when N_Record_Definition =>
3894 Record_Type_Declaration (T, N, Prev);
3897 raise Program_Error;
3902 if Etype (T) = Any_Type then
3906 -- Some common processing for all types
3908 Set_Depends_On_Private (T, Has_Private_Component (T));
3909 Check_Ops_From_Incomplete_Type;
3911 -- Both the declared entity, and its anonymous base type if one
3912 -- was created, need freeze nodes allocated.
3915 B : constant Entity_Id := Base_Type (T);
3918 -- In the case where the base type differs from the first subtype, we
3919 -- pre-allocate a freeze node, and set the proper link to the first
3920 -- subtype. Freeze_Entity will use this preallocated freeze node when
3921 -- it freezes the entity.
3924 Ensure_Freeze_Node (B);
3925 Set_First_Subtype_Link (Freeze_Node (B), T);
3928 if not From_With_Type (T) then
3929 Set_Has_Delayed_Freeze (T);
3933 -- Case of T is the full declaration of some private type which has
3934 -- been swapped in Defining_Identifier (N).
3936 if T /= Def_Id and then Is_Private_Type (Def_Id) then
3937 Process_Full_View (N, T, Def_Id);
3939 -- Record the reference. The form of this is a little strange, since
3940 -- the full declaration has been swapped in. So the first parameter
3941 -- here represents the entity to which a reference is made which is
3942 -- the "real" entity, i.e. the one swapped in, and the second
3943 -- parameter provides the reference location.
3945 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3946 -- since we don't want a complaint about the full type being an
3947 -- unwanted reference to the private type
3950 B : constant Boolean := Has_Pragma_Unreferenced (T);
3952 Set_Has_Pragma_Unreferenced (T, False);
3953 Generate_Reference (T, T, 'c');
3954 Set_Has_Pragma_Unreferenced (T, B);
3957 Set_Completion_Referenced (Def_Id);
3959 -- For completion of incomplete type, process incomplete dependents
3960 -- and always mark the full type as referenced (it is the incomplete
3961 -- type that we get for any real reference).
3963 elsif Ekind (Prev) = E_Incomplete_Type then
3964 Process_Incomplete_Dependents (N, T, Prev);
3965 Generate_Reference (Prev, Def_Id, 'c');
3966 Set_Completion_Referenced (Def_Id);
3968 -- If not private type or incomplete type completion, this is a real
3969 -- definition of a new entity, so record it.
3972 Generate_Definition (Def_Id);
3975 if Chars (Scope (Def_Id)) = Name_System
3976 and then Chars (Def_Id) = Name_Address
3977 and then Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (N)))
3979 Set_Is_Descendent_Of_Address (Def_Id);
3980 Set_Is_Descendent_Of_Address (Base_Type (Def_Id));
3981 Set_Is_Descendent_Of_Address (Prev);
3984 Set_Optimize_Alignment_Flags (Def_Id);
3985 Check_Eliminated (Def_Id);
3986 end Analyze_Type_Declaration;
3988 --------------------------
3989 -- Analyze_Variant_Part --
3990 --------------------------
3992 procedure Analyze_Variant_Part (N : Node_Id) is
3994 procedure Non_Static_Choice_Error (Choice : Node_Id);
3995 -- Error routine invoked by the generic instantiation below when the
3996 -- variant part has a non static choice.
3998 procedure Process_Declarations (Variant : Node_Id);
3999 -- Analyzes all the declarations associated with a Variant. Needed by
4000 -- the generic instantiation below.
4002 package Variant_Choices_Processing is new
4003 Generic_Choices_Processing
4004 (Get_Alternatives => Variants,
4005 Get_Choices => Discrete_Choices,
4006 Process_Empty_Choice => No_OP,
4007 Process_Non_Static_Choice => Non_Static_Choice_Error,
4008 Process_Associated_Node => Process_Declarations);
4009 use Variant_Choices_Processing;
4010 -- Instantiation of the generic choice processing package
4012 -----------------------------
4013 -- Non_Static_Choice_Error --
4014 -----------------------------
4016 procedure Non_Static_Choice_Error (Choice : Node_Id) is
4018 Flag_Non_Static_Expr
4019 ("choice given in variant part is not static!", Choice);
4020 end Non_Static_Choice_Error;
4022 --------------------------
4023 -- Process_Declarations --
4024 --------------------------
4026 procedure Process_Declarations (Variant : Node_Id) is
4028 if not Null_Present (Component_List (Variant)) then
4029 Analyze_Declarations (Component_Items (Component_List (Variant)));
4031 if Present (Variant_Part (Component_List (Variant))) then
4032 Analyze (Variant_Part (Component_List (Variant)));
4035 end Process_Declarations;
4039 Discr_Name : Node_Id;
4040 Discr_Type : Entity_Id;
4042 Case_Table : Choice_Table_Type (1 .. Number_Of_Choices (N));
4044 Dont_Care : Boolean;
4045 Others_Present : Boolean := False;
4047 pragma Warnings (Off, Case_Table);
4048 pragma Warnings (Off, Last_Choice);
4049 pragma Warnings (Off, Dont_Care);
4050 pragma Warnings (Off, Others_Present);
4051 -- We don't care about the assigned values of any of these
4053 -- Start of processing for Analyze_Variant_Part
4056 Discr_Name := Name (N);
4057 Analyze (Discr_Name);
4059 -- If Discr_Name bad, get out (prevent cascaded errors)
4061 if Etype (Discr_Name) = Any_Type then
4065 -- Check invalid discriminant in variant part
4067 if Ekind (Entity (Discr_Name)) /= E_Discriminant then
4068 Error_Msg_N ("invalid discriminant name in variant part", Discr_Name);
4071 Discr_Type := Etype (Entity (Discr_Name));
4073 if not Is_Discrete_Type (Discr_Type) then
4075 ("discriminant in a variant part must be of a discrete type",
4080 -- Call the instantiated Analyze_Choices which does the rest of the work
4083 (N, Discr_Type, Case_Table, Last_Choice, Dont_Care, Others_Present);
4084 end Analyze_Variant_Part;
4086 ----------------------------
4087 -- Array_Type_Declaration --
4088 ----------------------------
4090 procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id) is
4091 Component_Def : constant Node_Id := Component_Definition (Def);
4092 Element_Type : Entity_Id;
4093 Implicit_Base : Entity_Id;
4095 Related_Id : Entity_Id := Empty;
4097 P : constant Node_Id := Parent (Def);
4101 if Nkind (Def) = N_Constrained_Array_Definition then
4102 Index := First (Discrete_Subtype_Definitions (Def));
4104 Index := First (Subtype_Marks (Def));
4107 -- Find proper names for the implicit types which may be public. In case
4108 -- of anonymous arrays we use the name of the first object of that type
4112 Related_Id := Defining_Identifier (P);
4118 while Present (Index) loop
4121 -- Add a subtype declaration for each index of private array type
4122 -- declaration whose etype is also private. For example:
4125 -- type Index is private;
4127 -- type Table is array (Index) of ...
4130 -- This is currently required by the expander for the internally
4131 -- generated equality subprogram of records with variant parts in
4132 -- which the etype of some component is such private type.
4134 if Ekind (Current_Scope) = E_Package
4135 and then In_Private_Part (Current_Scope)
4136 and then Has_Private_Declaration (Etype (Index))
4139 Loc : constant Source_Ptr := Sloc (Def);
4145 Make_Defining_Identifier (Loc,
4146 Chars => New_Internal_Name ('T'));
4147 Set_Is_Internal (New_E);
4150 Make_Subtype_Declaration (Loc,
4151 Defining_Identifier => New_E,
4152 Subtype_Indication =>
4153 New_Occurrence_Of (Etype (Index), Loc));
4155 Insert_Before (Parent (Def), Decl);
4157 Set_Etype (Index, New_E);
4159 -- If the index is a range the Entity attribute is not
4160 -- available. Example:
4163 -- type T is private;
4165 -- type T is new Natural;
4166 -- Table : array (T(1) .. T(10)) of Boolean;
4169 if Nkind (Index) /= N_Range then
4170 Set_Entity (Index, New_E);
4175 Make_Index (Index, P, Related_Id, Nb_Index);
4177 Nb_Index := Nb_Index + 1;
4180 -- Process subtype indication if one is present
4182 if Present (Subtype_Indication (Component_Def)) then
4185 (Subtype_Indication (Component_Def), P, Related_Id, 'C');
4187 -- Ada 2005 (AI-230): Access Definition case
4189 else pragma Assert (Present (Access_Definition (Component_Def)));
4191 -- Indicate that the anonymous access type is created by the
4192 -- array type declaration.
4194 Element_Type := Access_Definition
4196 N => Access_Definition (Component_Def));
4197 Set_Is_Local_Anonymous_Access (Element_Type);
4199 -- Propagate the parent. This field is needed if we have to generate
4200 -- the master_id associated with an anonymous access to task type
4201 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
4203 Set_Parent (Element_Type, Parent (T));
4205 -- Ada 2005 (AI-230): In case of components that are anonymous access
4206 -- types the level of accessibility depends on the enclosing type
4209 Set_Scope (Element_Type, Current_Scope); -- Ada 2005 (AI-230)
4211 -- Ada 2005 (AI-254)
4214 CD : constant Node_Id :=
4215 Access_To_Subprogram_Definition
4216 (Access_Definition (Component_Def));
4218 if Present (CD) and then Protected_Present (CD) then
4220 Replace_Anonymous_Access_To_Protected_Subprogram (Def);
4225 -- Constrained array case
4228 T := Create_Itype (E_Void, P, Related_Id, 'T');
4231 if Nkind (Def) = N_Constrained_Array_Definition then
4233 -- Establish Implicit_Base as unconstrained base type
4235 Implicit_Base := Create_Itype (E_Array_Type, P, Related_Id, 'B');
4237 Set_Etype (Implicit_Base, Implicit_Base);
4238 Set_Scope (Implicit_Base, Current_Scope);
4239 Set_Has_Delayed_Freeze (Implicit_Base);
4241 -- The constrained array type is a subtype of the unconstrained one
4243 Set_Ekind (T, E_Array_Subtype);
4244 Init_Size_Align (T);
4245 Set_Etype (T, Implicit_Base);
4246 Set_Scope (T, Current_Scope);
4247 Set_Is_Constrained (T, True);
4248 Set_First_Index (T, First (Discrete_Subtype_Definitions (Def)));
4249 Set_Has_Delayed_Freeze (T);
4251 -- Complete setup of implicit base type
4253 Set_First_Index (Implicit_Base, First_Index (T));
4254 Set_Component_Type (Implicit_Base, Element_Type);
4255 Set_Has_Task (Implicit_Base, Has_Task (Element_Type));
4256 Set_Component_Size (Implicit_Base, Uint_0);
4257 Set_Packed_Array_Type (Implicit_Base, Empty);
4258 Set_Has_Controlled_Component
4259 (Implicit_Base, Has_Controlled_Component
4261 or else Is_Controlled
4263 Set_Finalize_Storage_Only
4264 (Implicit_Base, Finalize_Storage_Only
4267 -- Unconstrained array case
4270 Set_Ekind (T, E_Array_Type);
4271 Init_Size_Align (T);
4273 Set_Scope (T, Current_Scope);
4274 Set_Component_Size (T, Uint_0);
4275 Set_Is_Constrained (T, False);
4276 Set_First_Index (T, First (Subtype_Marks (Def)));
4277 Set_Has_Delayed_Freeze (T, True);
4278 Set_Has_Task (T, Has_Task (Element_Type));
4279 Set_Has_Controlled_Component (T, Has_Controlled_Component
4282 Is_Controlled (Element_Type));
4283 Set_Finalize_Storage_Only (T, Finalize_Storage_Only
4287 -- Common attributes for both cases
4289 Set_Component_Type (Base_Type (T), Element_Type);
4290 Set_Packed_Array_Type (T, Empty);
4292 if Aliased_Present (Component_Definition (Def)) then
4293 Set_Has_Aliased_Components (Etype (T));
4296 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
4297 -- array type to ensure that objects of this type are initialized.
4299 if Ada_Version >= Ada_05
4300 and then Can_Never_Be_Null (Element_Type)
4302 Set_Can_Never_Be_Null (T);
4304 if Null_Exclusion_Present (Component_Definition (Def))
4306 -- No need to check itypes because in their case this check was
4307 -- done at their point of creation
4309 and then not Is_Itype (Element_Type)
4312 ("`NOT NULL` not allowed (null already excluded)",
4313 Subtype_Indication (Component_Definition (Def)));
4317 Priv := Private_Component (Element_Type);
4319 if Present (Priv) then
4321 -- Check for circular definitions
4323 if Priv = Any_Type then
4324 Set_Component_Type (Etype (T), Any_Type);
4326 -- There is a gap in the visibility of operations on the composite
4327 -- type only if the component type is defined in a different scope.
4329 elsif Scope (Priv) = Current_Scope then
4332 elsif Is_Limited_Type (Priv) then
4333 Set_Is_Limited_Composite (Etype (T));
4334 Set_Is_Limited_Composite (T);
4336 Set_Is_Private_Composite (Etype (T));
4337 Set_Is_Private_Composite (T);
4341 -- A syntax error in the declaration itself may lead to an empty index
4342 -- list, in which case do a minimal patch.
4344 if No (First_Index (T)) then
4345 Error_Msg_N ("missing index definition in array type declaration", T);
4348 Indices : constant List_Id :=
4349 New_List (New_Occurrence_Of (Any_Id, Sloc (T)));
4351 Set_Discrete_Subtype_Definitions (Def, Indices);
4352 Set_First_Index (T, First (Indices));
4357 -- Create a concatenation operator for the new type. Internal array
4358 -- types created for packed entities do not need such, they are
4359 -- compatible with the user-defined type.
4361 if Number_Dimensions (T) = 1
4362 and then not Is_Packed_Array_Type (T)
4364 New_Concatenation_Op (T);
4367 -- In the case of an unconstrained array the parser has already verified
4368 -- that all the indices are unconstrained but we still need to make sure
4369 -- that the element type is constrained.
4371 if Is_Indefinite_Subtype (Element_Type) then
4373 ("unconstrained element type in array declaration",
4374 Subtype_Indication (Component_Def));
4376 elsif Is_Abstract_Type (Element_Type) then
4378 ("the type of a component cannot be abstract",
4379 Subtype_Indication (Component_Def));
4381 end Array_Type_Declaration;
4383 ------------------------------------------------------
4384 -- Replace_Anonymous_Access_To_Protected_Subprogram --
4385 ------------------------------------------------------
4387 function Replace_Anonymous_Access_To_Protected_Subprogram
4388 (N : Node_Id) return Entity_Id
4390 Loc : constant Source_Ptr := Sloc (N);
4392 Curr_Scope : constant Scope_Stack_Entry :=
4393 Scope_Stack.Table (Scope_Stack.Last);
4395 Anon : constant Entity_Id :=
4396 Make_Defining_Identifier (Loc,
4397 Chars => New_Internal_Name ('S'));
4405 Set_Is_Internal (Anon);
4408 when N_Component_Declaration |
4409 N_Unconstrained_Array_Definition |
4410 N_Constrained_Array_Definition =>
4411 Comp := Component_Definition (N);
4412 Acc := Access_Definition (Comp);
4414 when N_Discriminant_Specification =>
4415 Comp := Discriminant_Type (N);
4418 when N_Parameter_Specification =>
4419 Comp := Parameter_Type (N);
4422 when N_Access_Function_Definition =>
4423 Comp := Result_Definition (N);
4426 when N_Object_Declaration =>
4427 Comp := Object_Definition (N);
4431 raise Program_Error;
4434 Decl := Make_Full_Type_Declaration (Loc,
4435 Defining_Identifier => Anon,
4437 Copy_Separate_Tree (Access_To_Subprogram_Definition (Acc)));
4439 Mark_Rewrite_Insertion (Decl);
4441 -- Insert the new declaration in the nearest enclosing scope
4444 while Present (P) and then not Has_Declarations (P) loop
4448 pragma Assert (Present (P));
4450 if Nkind (P) = N_Package_Specification then
4451 Prepend (Decl, Visible_Declarations (P));
4453 Prepend (Decl, Declarations (P));
4456 -- Replace the anonymous type with an occurrence of the new declaration.
4457 -- In all cases the rewritten node does not have the null-exclusion
4458 -- attribute because (if present) it was already inherited by the
4459 -- anonymous entity (Anon). Thus, in case of components we do not
4460 -- inherit this attribute.
4462 if Nkind (N) = N_Parameter_Specification then
4463 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4464 Set_Etype (Defining_Identifier (N), Anon);
4465 Set_Null_Exclusion_Present (N, False);
4467 elsif Nkind (N) = N_Object_Declaration then
4468 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4469 Set_Etype (Defining_Identifier (N), Anon);
4471 elsif Nkind (N) = N_Access_Function_Definition then
4472 Rewrite (Comp, New_Occurrence_Of (Anon, Loc));
4476 Make_Component_Definition (Loc,
4477 Subtype_Indication => New_Occurrence_Of (Anon, Loc)));
4480 Mark_Rewrite_Insertion (Comp);
4482 -- Temporarily remove the current scope from the stack to add the new
4483 -- declarations to the enclosing scope
4485 if Nkind_In (N, N_Object_Declaration, N_Access_Function_Definition) then
4489 Scope_Stack.Decrement_Last;
4491 Set_Is_Itype (Anon);
4492 Scope_Stack.Append (Curr_Scope);
4495 Set_Ekind (Anon, E_Anonymous_Access_Protected_Subprogram_Type);
4496 Set_Can_Use_Internal_Rep (Anon, not Always_Compatible_Rep_On_Target);
4498 end Replace_Anonymous_Access_To_Protected_Subprogram;
4500 -------------------------------
4501 -- Build_Derived_Access_Type --
4502 -------------------------------
4504 procedure Build_Derived_Access_Type
4506 Parent_Type : Entity_Id;
4507 Derived_Type : Entity_Id)
4509 S : constant Node_Id := Subtype_Indication (Type_Definition (N));
4511 Desig_Type : Entity_Id;
4513 Discr_Con_Elist : Elist_Id;
4514 Discr_Con_El : Elmt_Id;
4518 -- Set the designated type so it is available in case this is an access
4519 -- to a self-referential type, e.g. a standard list type with a next
4520 -- pointer. Will be reset after subtype is built.
4522 Set_Directly_Designated_Type
4523 (Derived_Type, Designated_Type (Parent_Type));
4525 Subt := Process_Subtype (S, N);
4527 if Nkind (S) /= N_Subtype_Indication
4528 and then Subt /= Base_Type (Subt)
4530 Set_Ekind (Derived_Type, E_Access_Subtype);
4533 if Ekind (Derived_Type) = E_Access_Subtype then
4535 Pbase : constant Entity_Id := Base_Type (Parent_Type);
4536 Ibase : constant Entity_Id :=
4537 Create_Itype (Ekind (Pbase), N, Derived_Type, 'B');
4538 Svg_Chars : constant Name_Id := Chars (Ibase);
4539 Svg_Next_E : constant Entity_Id := Next_Entity (Ibase);
4542 Copy_Node (Pbase, Ibase);
4544 Set_Chars (Ibase, Svg_Chars);
4545 Set_Next_Entity (Ibase, Svg_Next_E);
4546 Set_Sloc (Ibase, Sloc (Derived_Type));
4547 Set_Scope (Ibase, Scope (Derived_Type));
4548 Set_Freeze_Node (Ibase, Empty);
4549 Set_Is_Frozen (Ibase, False);
4550 Set_Comes_From_Source (Ibase, False);
4551 Set_Is_First_Subtype (Ibase, False);
4553 Set_Etype (Ibase, Pbase);
4554 Set_Etype (Derived_Type, Ibase);
4558 Set_Directly_Designated_Type
4559 (Derived_Type, Designated_Type (Subt));
4561 Set_Is_Constrained (Derived_Type, Is_Constrained (Subt));
4562 Set_Is_Access_Constant (Derived_Type, Is_Access_Constant (Parent_Type));
4563 Set_Size_Info (Derived_Type, Parent_Type);
4564 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
4565 Set_Depends_On_Private (Derived_Type,
4566 Has_Private_Component (Derived_Type));
4567 Conditional_Delay (Derived_Type, Subt);
4569 -- Ada 2005 (AI-231). Set the null-exclusion attribute
4571 if Null_Exclusion_Present (Type_Definition (N))
4572 or else Can_Never_Be_Null (Parent_Type)
4574 Set_Can_Never_Be_Null (Derived_Type);
4577 -- Note: we do not copy the Storage_Size_Variable, since we always go to
4578 -- the root type for this information.
4580 -- Apply range checks to discriminants for derived record case
4581 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
4583 Desig_Type := Designated_Type (Derived_Type);
4584 if Is_Composite_Type (Desig_Type)
4585 and then (not Is_Array_Type (Desig_Type))
4586 and then Has_Discriminants (Desig_Type)
4587 and then Base_Type (Desig_Type) /= Desig_Type
4589 Discr_Con_Elist := Discriminant_Constraint (Desig_Type);
4590 Discr_Con_El := First_Elmt (Discr_Con_Elist);
4592 Discr := First_Discriminant (Base_Type (Desig_Type));
4593 while Present (Discr_Con_El) loop
4594 Apply_Range_Check (Node (Discr_Con_El), Etype (Discr));
4595 Next_Elmt (Discr_Con_El);
4596 Next_Discriminant (Discr);
4599 end Build_Derived_Access_Type;
4601 ------------------------------
4602 -- Build_Derived_Array_Type --
4603 ------------------------------
4605 procedure Build_Derived_Array_Type
4607 Parent_Type : Entity_Id;
4608 Derived_Type : Entity_Id)
4610 Loc : constant Source_Ptr := Sloc (N);
4611 Tdef : constant Node_Id := Type_Definition (N);
4612 Indic : constant Node_Id := Subtype_Indication (Tdef);
4613 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
4614 Implicit_Base : Entity_Id;
4615 New_Indic : Node_Id;
4617 procedure Make_Implicit_Base;
4618 -- If the parent subtype is constrained, the derived type is a subtype
4619 -- of an implicit base type derived from the parent base.
4621 ------------------------
4622 -- Make_Implicit_Base --
4623 ------------------------
4625 procedure Make_Implicit_Base is
4628 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
4630 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
4631 Set_Etype (Implicit_Base, Parent_Base);
4633 Copy_Array_Subtype_Attributes (Implicit_Base, Parent_Base);
4634 Copy_Array_Base_Type_Attributes (Implicit_Base, Parent_Base);
4636 Set_Has_Delayed_Freeze (Implicit_Base, True);
4637 end Make_Implicit_Base;
4639 -- Start of processing for Build_Derived_Array_Type
4642 if not Is_Constrained (Parent_Type) then
4643 if Nkind (Indic) /= N_Subtype_Indication then
4644 Set_Ekind (Derived_Type, E_Array_Type);
4646 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4647 Copy_Array_Base_Type_Attributes (Derived_Type, Parent_Type);
4649 Set_Has_Delayed_Freeze (Derived_Type, True);
4653 Set_Etype (Derived_Type, Implicit_Base);
4656 Make_Subtype_Declaration (Loc,
4657 Defining_Identifier => Derived_Type,
4658 Subtype_Indication =>
4659 Make_Subtype_Indication (Loc,
4660 Subtype_Mark => New_Reference_To (Implicit_Base, Loc),
4661 Constraint => Constraint (Indic)));
4663 Rewrite (N, New_Indic);
4668 if Nkind (Indic) /= N_Subtype_Indication then
4671 Set_Ekind (Derived_Type, Ekind (Parent_Type));
4672 Set_Etype (Derived_Type, Implicit_Base);
4673 Copy_Array_Subtype_Attributes (Derived_Type, Parent_Type);
4676 Error_Msg_N ("illegal constraint on constrained type", Indic);
4680 -- If parent type is not a derived type itself, and is declared in
4681 -- closed scope (e.g. a subprogram), then we must explicitly introduce
4682 -- the new type's concatenation operator since Derive_Subprograms
4683 -- will not inherit the parent's operator. If the parent type is
4684 -- unconstrained, the operator is of the unconstrained base type.
4686 if Number_Dimensions (Parent_Type) = 1
4687 and then not Is_Limited_Type (Parent_Type)
4688 and then not Is_Derived_Type (Parent_Type)
4689 and then not Is_Package_Or_Generic_Package
4690 (Scope (Base_Type (Parent_Type)))
4692 if not Is_Constrained (Parent_Type)
4693 and then Is_Constrained (Derived_Type)
4695 New_Concatenation_Op (Implicit_Base);
4697 New_Concatenation_Op (Derived_Type);
4700 end Build_Derived_Array_Type;
4702 -----------------------------------
4703 -- Build_Derived_Concurrent_Type --
4704 -----------------------------------
4706 procedure Build_Derived_Concurrent_Type
4708 Parent_Type : Entity_Id;
4709 Derived_Type : Entity_Id)
4711 D_Constraint : Node_Id;
4712 Disc_Spec : Node_Id;
4713 Old_Disc : Entity_Id;
4714 New_Disc : Entity_Id;
4716 Constraint_Present : constant Boolean :=
4717 Nkind (Subtype_Indication (Type_Definition (N)))
4718 = N_Subtype_Indication;
4721 Set_Stored_Constraint (Derived_Type, No_Elist);
4723 -- Copy Storage_Size and Relative_Deadline variables if task case
4725 if Is_Task_Type (Parent_Type) then
4726 Set_Storage_Size_Variable (Derived_Type,
4727 Storage_Size_Variable (Parent_Type));
4728 Set_Relative_Deadline_Variable (Derived_Type,
4729 Relative_Deadline_Variable (Parent_Type));
4732 if Present (Discriminant_Specifications (N)) then
4733 Push_Scope (Derived_Type);
4734 Check_Or_Process_Discriminants (N, Derived_Type);
4737 elsif Constraint_Present then
4739 -- Build constrained subtype and derive from it
4742 Loc : constant Source_Ptr := Sloc (N);
4743 Anon : constant Entity_Id :=
4744 Make_Defining_Identifier (Loc,
4745 New_External_Name (Chars (Derived_Type), 'T'));
4750 Make_Subtype_Declaration (Loc,
4751 Defining_Identifier => Anon,
4752 Subtype_Indication =>
4753 Subtype_Indication (Type_Definition (N)));
4754 Insert_Before (N, Decl);
4757 Rewrite (Subtype_Indication (Type_Definition (N)),
4758 New_Occurrence_Of (Anon, Loc));
4759 Set_Analyzed (Derived_Type, False);
4765 -- All attributes are inherited from parent. In particular,
4766 -- entries and the corresponding record type are the same.
4767 -- Discriminants may be renamed, and must be treated separately.
4769 Set_Has_Discriminants
4770 (Derived_Type, Has_Discriminants (Parent_Type));
4771 Set_Corresponding_Record_Type
4772 (Derived_Type, Corresponding_Record_Type (Parent_Type));
4774 -- Is_Constrained is set according the parent subtype, but is set to
4775 -- False if the derived type is declared with new discriminants.
4779 (Is_Constrained (Parent_Type) or else Constraint_Present)
4780 and then not Present (Discriminant_Specifications (N)));
4782 if Constraint_Present then
4783 if not Has_Discriminants (Parent_Type) then
4784 Error_Msg_N ("untagged parent must have discriminants", N);
4786 elsif Present (Discriminant_Specifications (N)) then
4788 -- Verify that new discriminants are used to constrain old ones
4793 (Constraint (Subtype_Indication (Type_Definition (N)))));
4795 Old_Disc := First_Discriminant (Parent_Type);
4796 New_Disc := First_Discriminant (Derived_Type);
4797 Disc_Spec := First (Discriminant_Specifications (N));
4798 while Present (Old_Disc) and then Present (Disc_Spec) loop
4799 if Nkind (Discriminant_Type (Disc_Spec)) /=
4802 Analyze (Discriminant_Type (Disc_Spec));
4804 if not Subtypes_Statically_Compatible (
4805 Etype (Discriminant_Type (Disc_Spec)),
4809 ("not statically compatible with parent discriminant",
4810 Discriminant_Type (Disc_Spec));
4814 if Nkind (D_Constraint) = N_Identifier
4815 and then Chars (D_Constraint) /=
4816 Chars (Defining_Identifier (Disc_Spec))
4818 Error_Msg_N ("new discriminants must constrain old ones",
4821 Set_Corresponding_Discriminant (New_Disc, Old_Disc);
4824 Next_Discriminant (Old_Disc);
4825 Next_Discriminant (New_Disc);
4829 if Present (Old_Disc) or else Present (Disc_Spec) then
4830 Error_Msg_N ("discriminant mismatch in derivation", N);
4835 elsif Present (Discriminant_Specifications (N)) then
4837 ("missing discriminant constraint in untagged derivation",
4841 if Present (Discriminant_Specifications (N)) then
4842 Old_Disc := First_Discriminant (Parent_Type);
4843 while Present (Old_Disc) loop
4845 if No (Next_Entity (Old_Disc))
4846 or else Ekind (Next_Entity (Old_Disc)) /= E_Discriminant
4848 Set_Next_Entity (Last_Entity (Derived_Type),
4849 Next_Entity (Old_Disc));
4853 Next_Discriminant (Old_Disc);
4857 Set_First_Entity (Derived_Type, First_Entity (Parent_Type));
4858 if Has_Discriminants (Parent_Type) then
4859 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
4860 Set_Discriminant_Constraint (
4861 Derived_Type, Discriminant_Constraint (Parent_Type));
4865 Set_Last_Entity (Derived_Type, Last_Entity (Parent_Type));
4867 Set_Has_Completion (Derived_Type);
4868 end Build_Derived_Concurrent_Type;
4870 ------------------------------------
4871 -- Build_Derived_Enumeration_Type --
4872 ------------------------------------
4874 procedure Build_Derived_Enumeration_Type
4876 Parent_Type : Entity_Id;
4877 Derived_Type : Entity_Id)
4879 Loc : constant Source_Ptr := Sloc (N);
4880 Def : constant Node_Id := Type_Definition (N);
4881 Indic : constant Node_Id := Subtype_Indication (Def);
4882 Implicit_Base : Entity_Id;
4883 Literal : Entity_Id;
4884 New_Lit : Entity_Id;
4885 Literals_List : List_Id;
4886 Type_Decl : Node_Id;
4888 Rang_Expr : Node_Id;
4891 -- Since types Standard.Character and Standard.Wide_Character do
4892 -- not have explicit literals lists we need to process types derived
4893 -- from them specially. This is handled by Derived_Standard_Character.
4894 -- If the parent type is a generic type, there are no literals either,
4895 -- and we construct the same skeletal representation as for the generic
4898 if Is_Standard_Character_Type (Parent_Type) then
4899 Derived_Standard_Character (N, Parent_Type, Derived_Type);
4901 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
4908 Make_Attribute_Reference (Loc,
4909 Attribute_Name => Name_First,
4910 Prefix => New_Reference_To (Derived_Type, Loc));
4911 Set_Etype (Lo, Derived_Type);
4914 Make_Attribute_Reference (Loc,
4915 Attribute_Name => Name_Last,
4916 Prefix => New_Reference_To (Derived_Type, Loc));
4917 Set_Etype (Hi, Derived_Type);
4919 Set_Scalar_Range (Derived_Type,
4926 -- If a constraint is present, analyze the bounds to catch
4927 -- premature usage of the derived literals.
4929 if Nkind (Indic) = N_Subtype_Indication
4930 and then Nkind (Range_Expression (Constraint (Indic))) = N_Range
4932 Analyze (Low_Bound (Range_Expression (Constraint (Indic))));
4933 Analyze (High_Bound (Range_Expression (Constraint (Indic))));
4936 -- Introduce an implicit base type for the derived type even if there
4937 -- is no constraint attached to it, since this seems closer to the
4938 -- Ada semantics. Build a full type declaration tree for the derived
4939 -- type using the implicit base type as the defining identifier. The
4940 -- build a subtype declaration tree which applies the constraint (if
4941 -- any) have it replace the derived type declaration.
4943 Literal := First_Literal (Parent_Type);
4944 Literals_List := New_List;
4945 while Present (Literal)
4946 and then Ekind (Literal) = E_Enumeration_Literal
4948 -- Literals of the derived type have the same representation as
4949 -- those of the parent type, but this representation can be
4950 -- overridden by an explicit representation clause. Indicate
4951 -- that there is no explicit representation given yet. These
4952 -- derived literals are implicit operations of the new type,
4953 -- and can be overridden by explicit ones.
4955 if Nkind (Literal) = N_Defining_Character_Literal then
4957 Make_Defining_Character_Literal (Loc, Chars (Literal));
4959 New_Lit := Make_Defining_Identifier (Loc, Chars (Literal));
4962 Set_Ekind (New_Lit, E_Enumeration_Literal);
4963 Set_Enumeration_Pos (New_Lit, Enumeration_Pos (Literal));
4964 Set_Enumeration_Rep (New_Lit, Enumeration_Rep (Literal));
4965 Set_Enumeration_Rep_Expr (New_Lit, Empty);
4966 Set_Alias (New_Lit, Literal);
4967 Set_Is_Known_Valid (New_Lit, True);
4969 Append (New_Lit, Literals_List);
4970 Next_Literal (Literal);
4974 Make_Defining_Identifier (Sloc (Derived_Type),
4975 New_External_Name (Chars (Derived_Type), 'B'));
4977 -- Indicate the proper nature of the derived type. This must be done
4978 -- before analysis of the literals, to recognize cases when a literal
4979 -- may be hidden by a previous explicit function definition (cf.
4982 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
4983 Set_Etype (Derived_Type, Implicit_Base);
4986 Make_Full_Type_Declaration (Loc,
4987 Defining_Identifier => Implicit_Base,
4988 Discriminant_Specifications => No_List,
4990 Make_Enumeration_Type_Definition (Loc, Literals_List));
4992 Mark_Rewrite_Insertion (Type_Decl);
4993 Insert_Before (N, Type_Decl);
4994 Analyze (Type_Decl);
4996 -- After the implicit base is analyzed its Etype needs to be changed
4997 -- to reflect the fact that it is derived from the parent type which
4998 -- was ignored during analysis. We also set the size at this point.
5000 Set_Etype (Implicit_Base, Parent_Type);
5002 Set_Size_Info (Implicit_Base, Parent_Type);
5003 Set_RM_Size (Implicit_Base, RM_Size (Parent_Type));
5004 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Type));
5006 Set_Has_Non_Standard_Rep
5007 (Implicit_Base, Has_Non_Standard_Rep
5009 Set_Has_Delayed_Freeze (Implicit_Base);
5011 -- Process the subtype indication including a validation check on the
5012 -- constraint, if any. If a constraint is given, its bounds must be
5013 -- implicitly converted to the new type.
5015 if Nkind (Indic) = N_Subtype_Indication then
5017 R : constant Node_Id :=
5018 Range_Expression (Constraint (Indic));
5021 if Nkind (R) = N_Range then
5022 Hi := Build_Scalar_Bound
5023 (High_Bound (R), Parent_Type, Implicit_Base);
5024 Lo := Build_Scalar_Bound
5025 (Low_Bound (R), Parent_Type, Implicit_Base);
5028 -- Constraint is a Range attribute. Replace with explicit
5029 -- mention of the bounds of the prefix, which must be a
5032 Analyze (Prefix (R));
5034 Convert_To (Implicit_Base,
5035 Make_Attribute_Reference (Loc,
5036 Attribute_Name => Name_Last,
5038 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5041 Convert_To (Implicit_Base,
5042 Make_Attribute_Reference (Loc,
5043 Attribute_Name => Name_First,
5045 New_Occurrence_Of (Entity (Prefix (R)), Loc)));
5052 (Type_High_Bound (Parent_Type),
5053 Parent_Type, Implicit_Base);
5056 (Type_Low_Bound (Parent_Type),
5057 Parent_Type, Implicit_Base);
5065 -- If we constructed a default range for the case where no range
5066 -- was given, then the expressions in the range must not freeze
5067 -- since they do not correspond to expressions in the source.
5069 if Nkind (Indic) /= N_Subtype_Indication then
5070 Set_Must_Not_Freeze (Lo);
5071 Set_Must_Not_Freeze (Hi);
5072 Set_Must_Not_Freeze (Rang_Expr);
5076 Make_Subtype_Declaration (Loc,
5077 Defining_Identifier => Derived_Type,
5078 Subtype_Indication =>
5079 Make_Subtype_Indication (Loc,
5080 Subtype_Mark => New_Occurrence_Of (Implicit_Base, Loc),
5082 Make_Range_Constraint (Loc,
5083 Range_Expression => Rang_Expr))));
5087 -- If pragma Discard_Names applies on the first subtype of the parent
5088 -- type, then it must be applied on this subtype as well.
5090 if Einfo.Discard_Names (First_Subtype (Parent_Type)) then
5091 Set_Discard_Names (Derived_Type);
5094 -- Apply a range check. Since this range expression doesn't have an
5095 -- Etype, we have to specifically pass the Source_Typ parameter. Is
5098 if Nkind (Indic) = N_Subtype_Indication then
5099 Apply_Range_Check (Range_Expression (Constraint (Indic)),
5101 Source_Typ => Entity (Subtype_Mark (Indic)));
5104 end Build_Derived_Enumeration_Type;
5106 --------------------------------
5107 -- Build_Derived_Numeric_Type --
5108 --------------------------------
5110 procedure Build_Derived_Numeric_Type
5112 Parent_Type : Entity_Id;
5113 Derived_Type : Entity_Id)
5115 Loc : constant Source_Ptr := Sloc (N);
5116 Tdef : constant Node_Id := Type_Definition (N);
5117 Indic : constant Node_Id := Subtype_Indication (Tdef);
5118 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
5119 No_Constraint : constant Boolean := Nkind (Indic) /=
5120 N_Subtype_Indication;
5121 Implicit_Base : Entity_Id;
5127 -- Process the subtype indication including a validation check on
5128 -- the constraint if any.
5130 Discard_Node (Process_Subtype (Indic, N));
5132 -- Introduce an implicit base type for the derived type even if there
5133 -- is no constraint attached to it, since this seems closer to the Ada
5137 Create_Itype (Ekind (Parent_Base), N, Derived_Type, 'B');
5139 Set_Etype (Implicit_Base, Parent_Base);
5140 Set_Ekind (Implicit_Base, Ekind (Parent_Base));
5141 Set_Size_Info (Implicit_Base, Parent_Base);
5142 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Parent_Base));
5143 Set_Parent (Implicit_Base, Parent (Derived_Type));
5145 -- Set RM Size for discrete type or decimal fixed-point type
5146 -- Ordinary fixed-point is excluded, why???
5148 if Is_Discrete_Type (Parent_Base)
5149 or else Is_Decimal_Fixed_Point_Type (Parent_Base)
5151 Set_RM_Size (Implicit_Base, RM_Size (Parent_Base));
5154 Set_Has_Delayed_Freeze (Implicit_Base);
5156 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
5157 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
5159 Set_Scalar_Range (Implicit_Base,
5164 if Has_Infinities (Parent_Base) then
5165 Set_Includes_Infinities (Scalar_Range (Implicit_Base));
5168 -- The Derived_Type, which is the entity of the declaration, is a
5169 -- subtype of the implicit base. Its Ekind is a subtype, even in the
5170 -- absence of an explicit constraint.
5172 Set_Etype (Derived_Type, Implicit_Base);
5174 -- If we did not have a constraint, then the Ekind is set from the
5175 -- parent type (otherwise Process_Subtype has set the bounds)
5177 if No_Constraint then
5178 Set_Ekind (Derived_Type, Subtype_Kind (Ekind (Parent_Type)));
5181 -- If we did not have a range constraint, then set the range from the
5182 -- parent type. Otherwise, the call to Process_Subtype has set the
5186 or else not Has_Range_Constraint (Indic)
5188 Set_Scalar_Range (Derived_Type,
5190 Low_Bound => New_Copy_Tree (Type_Low_Bound (Parent_Type)),
5191 High_Bound => New_Copy_Tree (Type_High_Bound (Parent_Type))));
5192 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5194 if Has_Infinities (Parent_Type) then
5195 Set_Includes_Infinities (Scalar_Range (Derived_Type));
5199 Set_Is_Descendent_Of_Address (Derived_Type,
5200 Is_Descendent_Of_Address (Parent_Type));
5201 Set_Is_Descendent_Of_Address (Implicit_Base,
5202 Is_Descendent_Of_Address (Parent_Type));
5204 -- Set remaining type-specific fields, depending on numeric type
5206 if Is_Modular_Integer_Type (Parent_Type) then
5207 Set_Modulus (Implicit_Base, Modulus (Parent_Base));
5209 Set_Non_Binary_Modulus
5210 (Implicit_Base, Non_Binary_Modulus (Parent_Base));
5212 elsif Is_Floating_Point_Type (Parent_Type) then
5214 -- Digits of base type is always copied from the digits value of
5215 -- the parent base type, but the digits of the derived type will
5216 -- already have been set if there was a constraint present.
5218 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5219 Set_Vax_Float (Implicit_Base, Vax_Float (Parent_Base));
5221 if No_Constraint then
5222 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Type));
5225 elsif Is_Fixed_Point_Type (Parent_Type) then
5227 -- Small of base type and derived type are always copied from the
5228 -- parent base type, since smalls never change. The delta of the
5229 -- base type is also copied from the parent base type. However the
5230 -- delta of the derived type will have been set already if a
5231 -- constraint was present.
5233 Set_Small_Value (Derived_Type, Small_Value (Parent_Base));
5234 Set_Small_Value (Implicit_Base, Small_Value (Parent_Base));
5235 Set_Delta_Value (Implicit_Base, Delta_Value (Parent_Base));
5237 if No_Constraint then
5238 Set_Delta_Value (Derived_Type, Delta_Value (Parent_Type));
5241 -- The scale and machine radix in the decimal case are always
5242 -- copied from the parent base type.
5244 if Is_Decimal_Fixed_Point_Type (Parent_Type) then
5245 Set_Scale_Value (Derived_Type, Scale_Value (Parent_Base));
5246 Set_Scale_Value (Implicit_Base, Scale_Value (Parent_Base));
5248 Set_Machine_Radix_10
5249 (Derived_Type, Machine_Radix_10 (Parent_Base));
5250 Set_Machine_Radix_10
5251 (Implicit_Base, Machine_Radix_10 (Parent_Base));
5253 Set_Digits_Value (Implicit_Base, Digits_Value (Parent_Base));
5255 if No_Constraint then
5256 Set_Digits_Value (Derived_Type, Digits_Value (Parent_Base));
5259 -- the analysis of the subtype_indication sets the
5260 -- digits value of the derived type.
5267 -- The type of the bounds is that of the parent type, and they
5268 -- must be converted to the derived type.
5270 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
5272 -- The implicit_base should be frozen when the derived type is frozen,
5273 -- but note that it is used in the conversions of the bounds. For fixed
5274 -- types we delay the determination of the bounds until the proper
5275 -- freezing point. For other numeric types this is rejected by GCC, for
5276 -- reasons that are currently unclear (???), so we choose to freeze the
5277 -- implicit base now. In the case of integers and floating point types
5278 -- this is harmless because subsequent representation clauses cannot
5279 -- affect anything, but it is still baffling that we cannot use the
5280 -- same mechanism for all derived numeric types.
5282 -- There is a further complication: actually *some* representation
5283 -- clauses can affect the implicit base type. Namely, attribute
5284 -- definition clauses for stream-oriented attributes need to set the
5285 -- corresponding TSS entries on the base type, and this normally cannot
5286 -- be done after the base type is frozen, so the circuitry in
5287 -- Sem_Ch13.New_Stream_Subprogram must account for this possibility and
5288 -- not use Set_TSS in this case.
5290 if Is_Fixed_Point_Type (Parent_Type) then
5291 Conditional_Delay (Implicit_Base, Parent_Type);
5293 Freeze_Before (N, Implicit_Base);
5295 end Build_Derived_Numeric_Type;
5297 --------------------------------
5298 -- Build_Derived_Private_Type --
5299 --------------------------------
5301 procedure Build_Derived_Private_Type
5303 Parent_Type : Entity_Id;
5304 Derived_Type : Entity_Id;
5305 Is_Completion : Boolean;
5306 Derive_Subps : Boolean := True)
5308 Der_Base : Entity_Id;
5310 Full_Decl : Node_Id := Empty;
5311 Full_Der : Entity_Id;
5313 Last_Discr : Entity_Id;
5314 Par_Scope : constant Entity_Id := Scope (Base_Type (Parent_Type));
5315 Swapped : Boolean := False;
5317 procedure Copy_And_Build;
5318 -- Copy derived type declaration, replace parent with its full view,
5319 -- and analyze new declaration.
5321 --------------------
5322 -- Copy_And_Build --
5323 --------------------
5325 procedure Copy_And_Build is
5329 if Ekind (Parent_Type) in Record_Kind
5331 (Ekind (Parent_Type) in Enumeration_Kind
5332 and then not Is_Standard_Character_Type (Parent_Type)
5333 and then not Is_Generic_Type (Root_Type (Parent_Type)))
5335 Full_N := New_Copy_Tree (N);
5336 Insert_After (N, Full_N);
5337 Build_Derived_Type (
5338 Full_N, Parent_Type, Full_Der, True, Derive_Subps => False);
5341 Build_Derived_Type (
5342 N, Parent_Type, Full_Der, True, Derive_Subps => False);
5346 -- Start of processing for Build_Derived_Private_Type
5349 if Is_Tagged_Type (Parent_Type) then
5350 Build_Derived_Record_Type
5351 (N, Parent_Type, Derived_Type, Derive_Subps);
5354 elsif Has_Discriminants (Parent_Type) then
5355 if Present (Full_View (Parent_Type)) then
5356 if not Is_Completion then
5358 -- Copy declaration for subsequent analysis, to provide a
5359 -- completion for what is a private declaration. Indicate that
5360 -- the full type is internally generated.
5362 Full_Decl := New_Copy_Tree (N);
5363 Full_Der := New_Copy (Derived_Type);
5364 Set_Comes_From_Source (Full_Decl, False);
5365 Set_Comes_From_Source (Full_Der, False);
5367 Insert_After (N, Full_Decl);
5370 -- If this is a completion, the full view being built is
5371 -- itself private. We build a subtype of the parent with
5372 -- the same constraints as this full view, to convey to the
5373 -- back end the constrained components and the size of this
5374 -- subtype. If the parent is constrained, its full view can
5375 -- serve as the underlying full view of the derived type.
5377 if No (Discriminant_Specifications (N)) then
5378 if Nkind (Subtype_Indication (Type_Definition (N))) =
5379 N_Subtype_Indication
5381 Build_Underlying_Full_View (N, Derived_Type, Parent_Type);
5383 elsif Is_Constrained (Full_View (Parent_Type)) then
5384 Set_Underlying_Full_View (Derived_Type,
5385 Full_View (Parent_Type));
5389 -- If there are new discriminants, the parent subtype is
5390 -- constrained by them, but it is not clear how to build
5391 -- the underlying_full_view in this case ???
5398 -- Build partial view of derived type from partial view of parent
5400 Build_Derived_Record_Type
5401 (N, Parent_Type, Derived_Type, Derive_Subps);
5403 if Present (Full_View (Parent_Type))
5404 and then not Is_Completion
5406 if not In_Open_Scopes (Par_Scope)
5407 or else not In_Same_Source_Unit (N, Parent_Type)
5409 -- Swap partial and full views temporarily
5411 Install_Private_Declarations (Par_Scope);
5412 Install_Visible_Declarations (Par_Scope);
5416 -- Build full view of derived type from full view of parent which
5417 -- is now installed. Subprograms have been derived on the partial
5418 -- view, the completion does not derive them anew.
5420 if not Is_Tagged_Type (Parent_Type) then
5422 -- If the parent is itself derived from another private type,
5423 -- installing the private declarations has not affected its
5424 -- privacy status, so use its own full view explicitly.
5426 if Is_Private_Type (Parent_Type) then
5427 Build_Derived_Record_Type
5428 (Full_Decl, Full_View (Parent_Type), Full_Der, False);
5430 Build_Derived_Record_Type
5431 (Full_Decl, Parent_Type, Full_Der, False);
5435 -- If full view of parent is tagged, the completion
5436 -- inherits the proper primitive operations.
5438 Set_Defining_Identifier (Full_Decl, Full_Der);
5439 Build_Derived_Record_Type
5440 (Full_Decl, Parent_Type, Full_Der, Derive_Subps);
5441 Set_Analyzed (Full_Decl);
5445 Uninstall_Declarations (Par_Scope);
5447 if In_Open_Scopes (Par_Scope) then
5448 Install_Visible_Declarations (Par_Scope);
5452 Der_Base := Base_Type (Derived_Type);
5453 Set_Full_View (Derived_Type, Full_Der);
5454 Set_Full_View (Der_Base, Base_Type (Full_Der));
5456 -- Copy the discriminant list from full view to the partial views
5457 -- (base type and its subtype). Gigi requires that the partial
5458 -- and full views have the same discriminants.
5460 -- Note that since the partial view is pointing to discriminants
5461 -- in the full view, their scope will be that of the full view.
5462 -- This might cause some front end problems and need
5465 Discr := First_Discriminant (Base_Type (Full_Der));
5466 Set_First_Entity (Der_Base, Discr);
5469 Last_Discr := Discr;
5470 Next_Discriminant (Discr);
5471 exit when No (Discr);
5474 Set_Last_Entity (Der_Base, Last_Discr);
5476 Set_First_Entity (Derived_Type, First_Entity (Der_Base));
5477 Set_Last_Entity (Derived_Type, Last_Entity (Der_Base));
5478 Set_Stored_Constraint (Full_Der, Stored_Constraint (Derived_Type));
5481 -- If this is a completion, the derived type stays private
5482 -- and there is no need to create a further full view, except
5483 -- in the unusual case when the derivation is nested within a
5484 -- child unit, see below.
5489 elsif Present (Full_View (Parent_Type))
5490 and then Has_Discriminants (Full_View (Parent_Type))
5492 if Has_Unknown_Discriminants (Parent_Type)
5493 and then Nkind (Subtype_Indication (Type_Definition (N))) =
5494 N_Subtype_Indication
5497 ("cannot constrain type with unknown discriminants",
5498 Subtype_Indication (Type_Definition (N)));
5502 -- If full view of parent is a record type, Build full view as
5503 -- a derivation from the parent's full view. Partial view remains
5504 -- private. For code generation and linking, the full view must
5505 -- have the same public status as the partial one. This full view
5506 -- is only needed if the parent type is in an enclosing scope, so
5507 -- that the full view may actually become visible, e.g. in a child
5508 -- unit. This is both more efficient, and avoids order of freezing
5509 -- problems with the added entities.
5511 if not Is_Private_Type (Full_View (Parent_Type))
5512 and then (In_Open_Scopes (Scope (Parent_Type)))
5514 Full_Der := Make_Defining_Identifier (Sloc (Derived_Type),
5515 Chars (Derived_Type));
5516 Set_Is_Itype (Full_Der);
5517 Set_Has_Private_Declaration (Full_Der);
5518 Set_Has_Private_Declaration (Derived_Type);
5519 Set_Associated_Node_For_Itype (Full_Der, N);
5520 Set_Parent (Full_Der, Parent (Derived_Type));
5521 Set_Full_View (Derived_Type, Full_Der);
5522 Set_Is_Public (Full_Der, Is_Public (Derived_Type));
5523 Full_P := Full_View (Parent_Type);
5524 Exchange_Declarations (Parent_Type);
5526 Exchange_Declarations (Full_P);
5529 Build_Derived_Record_Type
5530 (N, Full_View (Parent_Type), Derived_Type,
5531 Derive_Subps => False);
5534 -- In any case, the primitive operations are inherited from
5535 -- the parent type, not from the internal full view.
5537 Set_Etype (Base_Type (Derived_Type), Base_Type (Parent_Type));
5539 if Derive_Subps then
5540 Derive_Subprograms (Parent_Type, Derived_Type);
5544 -- Untagged type, No discriminants on either view
5546 if Nkind (Subtype_Indication (Type_Definition (N))) =
5547 N_Subtype_Indication
5550 ("illegal constraint on type without discriminants", N);
5553 if Present (Discriminant_Specifications (N))
5554 and then Present (Full_View (Parent_Type))
5555 and then not Is_Tagged_Type (Full_View (Parent_Type))
5558 ("cannot add discriminants to untagged type", N);
5561 Set_Stored_Constraint (Derived_Type, No_Elist);
5562 Set_Is_Constrained (Derived_Type, Is_Constrained (Parent_Type));
5563 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
5564 Set_Has_Controlled_Component
5565 (Derived_Type, Has_Controlled_Component
5568 -- Direct controlled types do not inherit Finalize_Storage_Only flag
5570 if not Is_Controlled (Parent_Type) then
5571 Set_Finalize_Storage_Only
5572 (Base_Type (Derived_Type), Finalize_Storage_Only (Parent_Type));
5575 -- Construct the implicit full view by deriving from full view of
5576 -- the parent type. In order to get proper visibility, we install
5577 -- the parent scope and its declarations.
5579 -- ??? if the parent is untagged private and its completion is
5580 -- tagged, this mechanism will not work because we cannot derive
5581 -- from the tagged full view unless we have an extension
5583 if Present (Full_View (Parent_Type))
5584 and then not Is_Tagged_Type (Full_View (Parent_Type))
5585 and then not Is_Completion
5588 Make_Defining_Identifier (Sloc (Derived_Type),
5589 Chars => 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);
5597 if not In_Open_Scopes (Par_Scope) then
5598 Install_Private_Declarations (Par_Scope);
5599 Install_Visible_Declarations (Par_Scope);
5601 Uninstall_Declarations (Par_Scope);
5603 -- If parent scope is open and in another unit, and parent has a
5604 -- completion, then the derivation is taking place in the visible
5605 -- part of a child unit. In that case retrieve the full view of
5606 -- the parent momentarily.
5608 elsif not In_Same_Source_Unit (N, Parent_Type) then
5609 Full_P := Full_View (Parent_Type);
5610 Exchange_Declarations (Parent_Type);
5612 Exchange_Declarations (Full_P);
5614 -- Otherwise it is a local derivation
5620 Set_Scope (Full_Der, Current_Scope);
5621 Set_Is_First_Subtype (Full_Der,
5622 Is_First_Subtype (Derived_Type));
5623 Set_Has_Size_Clause (Full_Der, False);
5624 Set_Has_Alignment_Clause (Full_Der, False);
5625 Set_Next_Entity (Full_Der, Empty);
5626 Set_Has_Delayed_Freeze (Full_Der);
5627 Set_Is_Frozen (Full_Der, False);
5628 Set_Freeze_Node (Full_Der, Empty);
5629 Set_Depends_On_Private (Full_Der,
5630 Has_Private_Component (Full_Der));
5631 Set_Public_Status (Full_Der);
5635 Set_Has_Unknown_Discriminants (Derived_Type,
5636 Has_Unknown_Discriminants (Parent_Type));
5638 if Is_Private_Type (Derived_Type) then
5639 Set_Private_Dependents (Derived_Type, New_Elmt_List);
5642 if Is_Private_Type (Parent_Type)
5643 and then Base_Type (Parent_Type) = Parent_Type
5644 and then In_Open_Scopes (Scope (Parent_Type))
5646 Append_Elmt (Derived_Type, Private_Dependents (Parent_Type));
5648 if Is_Child_Unit (Scope (Current_Scope))
5649 and then Is_Completion
5650 and then In_Private_Part (Current_Scope)
5651 and then Scope (Parent_Type) /= Current_Scope
5653 -- This is the unusual case where a type completed by a private
5654 -- derivation occurs within a package nested in a child unit,
5655 -- and the parent is declared in an ancestor. In this case, the
5656 -- full view of the parent type will become visible in the body
5657 -- of the enclosing child, and only then will the current type
5658 -- be possibly non-private. We build a underlying full view that
5659 -- will be installed when the enclosing child body is compiled.
5662 Make_Defining_Identifier (Sloc (Derived_Type),
5663 Chars => Chars (Derived_Type));
5664 Set_Is_Itype (Full_Der);
5665 Build_Itype_Reference (Full_Der, N);
5667 -- The full view will be used to swap entities on entry/exit to
5668 -- the body, and must appear in the entity list for the package.
5670 Append_Entity (Full_Der, Scope (Derived_Type));
5671 Set_Has_Private_Declaration (Full_Der);
5672 Set_Has_Private_Declaration (Derived_Type);
5673 Set_Associated_Node_For_Itype (Full_Der, N);
5674 Set_Parent (Full_Der, Parent (Derived_Type));
5675 Full_P := Full_View (Parent_Type);
5676 Exchange_Declarations (Parent_Type);
5678 Exchange_Declarations (Full_P);
5679 Set_Underlying_Full_View (Derived_Type, Full_Der);
5682 end Build_Derived_Private_Type;
5684 -------------------------------
5685 -- Build_Derived_Record_Type --
5686 -------------------------------
5690 -- Ideally we would like to use the same model of type derivation for
5691 -- tagged and untagged record types. Unfortunately this is not quite
5692 -- possible because the semantics of representation clauses is different
5693 -- for tagged and untagged records under inheritance. Consider the
5696 -- type R (...) is [tagged] record ... end record;
5697 -- type T (...) is new R (...) [with ...];
5699 -- The representation clauses for T can specify a completely different
5700 -- record layout from R's. Hence the same component can be placed in two
5701 -- very different positions in objects of type T and R. If R and are tagged
5702 -- types, representation clauses for T can only specify the layout of non
5703 -- inherited components, thus components that are common in R and T have
5704 -- the same position in objects of type R and T.
5706 -- This has two implications. The first is that the entire tree for R's
5707 -- declaration needs to be copied for T in the untagged case, so that T
5708 -- can be viewed as a record type of its own with its own representation
5709 -- clauses. The second implication is the way we handle discriminants.
5710 -- Specifically, in the untagged case we need a way to communicate to Gigi
5711 -- what are the real discriminants in the record, while for the semantics
5712 -- we need to consider those introduced by the user to rename the
5713 -- discriminants in the parent type. This is handled by introducing the
5714 -- notion of stored discriminants. See below for more.
5716 -- Fortunately the way regular components are inherited can be handled in
5717 -- the same way in tagged and untagged types.
5719 -- To complicate things a bit more the private view of a private extension
5720 -- cannot be handled in the same way as the full view (for one thing the
5721 -- semantic rules are somewhat different). We will explain what differs
5724 -- 2. DISCRIMINANTS UNDER INHERITANCE
5726 -- The semantic rules governing the discriminants of derived types are
5729 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
5730 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
5732 -- If parent type has discriminants, then the discriminants that are
5733 -- declared in the derived type are [3.4 (11)]:
5735 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
5738 -- o Otherwise, each discriminant of the parent type (implicitly declared
5739 -- in the same order with the same specifications). In this case, the
5740 -- discriminants are said to be "inherited", or if unknown in the parent
5741 -- are also unknown in the derived type.
5743 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
5745 -- o The parent subtype shall be constrained;
5747 -- o If the parent type is not a tagged type, then each discriminant of
5748 -- the derived type shall be used in the constraint defining a parent
5749 -- subtype. [Implementation note: This ensures that the new discriminant
5750 -- can share storage with an existing discriminant.]
5752 -- For the derived type each discriminant of the parent type is either
5753 -- inherited, constrained to equal some new discriminant of the derived
5754 -- type, or constrained to the value of an expression.
5756 -- When inherited or constrained to equal some new discriminant, the
5757 -- parent discriminant and the discriminant of the derived type are said
5760 -- If a discriminant of the parent type is constrained to a specific value
5761 -- in the derived type definition, then the discriminant is said to be
5762 -- "specified" by that derived type definition.
5764 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
5766 -- We have spoken about stored discriminants in point 1 (introduction)
5767 -- above. There are two sort of stored discriminants: implicit and
5768 -- explicit. As long as the derived type inherits the same discriminants as
5769 -- the root record type, stored discriminants are the same as regular
5770 -- discriminants, and are said to be implicit. However, if any discriminant
5771 -- in the root type was renamed in the derived type, then the derived
5772 -- type will contain explicit stored discriminants. Explicit stored
5773 -- discriminants are discriminants in addition to the semantically visible
5774 -- discriminants defined for the derived type. Stored discriminants are
5775 -- used by Gigi to figure out what are the physical discriminants in
5776 -- objects of the derived type (see precise definition in einfo.ads).
5777 -- As an example, consider the following:
5779 -- type R (D1, D2, D3 : Int) is record ... end record;
5780 -- type T1 is new R;
5781 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
5782 -- type T3 is new T2;
5783 -- type T4 (Y : Int) is new T3 (Y, 99);
5785 -- The following table summarizes the discriminants and stored
5786 -- discriminants in R and T1 through T4.
5788 -- Type Discrim Stored Discrim Comment
5789 -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
5790 -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
5791 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
5792 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
5793 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
5795 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
5796 -- find the corresponding discriminant in the parent type, while
5797 -- Original_Record_Component (abbreviated ORC below), the actual physical
5798 -- component that is renamed. Finally the field Is_Completely_Hidden
5799 -- (abbreviated ICH below) is set for all explicit stored discriminants
5800 -- (see einfo.ads for more info). For the above example this gives:
5802 -- Discrim CD ORC ICH
5803 -- ^^^^^^^ ^^ ^^^ ^^^
5804 -- D1 in R empty itself no
5805 -- D2 in R empty itself no
5806 -- D3 in R empty itself no
5808 -- D1 in T1 D1 in R itself no
5809 -- D2 in T1 D2 in R itself no
5810 -- D3 in T1 D3 in R itself no
5812 -- X1 in T2 D3 in T1 D3 in T2 no
5813 -- X2 in T2 D1 in T1 D1 in T2 no
5814 -- D1 in T2 empty itself yes
5815 -- D2 in T2 empty itself yes
5816 -- D3 in T2 empty itself yes
5818 -- X1 in T3 X1 in T2 D3 in T3 no
5819 -- X2 in T3 X2 in T2 D1 in T3 no
5820 -- D1 in T3 empty itself yes
5821 -- D2 in T3 empty itself yes
5822 -- D3 in T3 empty itself yes
5824 -- Y in T4 X1 in T3 D3 in T3 no
5825 -- D1 in T3 empty itself yes
5826 -- D2 in T3 empty itself yes
5827 -- D3 in T3 empty itself yes
5829 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
5831 -- Type derivation for tagged types is fairly straightforward. If no
5832 -- discriminants are specified by the derived type, these are inherited
5833 -- from the parent. No explicit stored discriminants are ever necessary.
5834 -- The only manipulation that is done to the tree is that of adding a
5835 -- _parent field with parent type and constrained to the same constraint
5836 -- specified for the parent in the derived type definition. For instance:
5838 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
5839 -- type T1 is new R with null record;
5840 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
5842 -- are changed into:
5844 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
5845 -- _parent : R (D1, D2, D3);
5848 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
5849 -- _parent : T1 (X2, 88, X1);
5852 -- The discriminants actually present in R, T1 and T2 as well as their CD,
5853 -- ORC and ICH fields are:
5855 -- Discrim CD ORC ICH
5856 -- ^^^^^^^ ^^ ^^^ ^^^
5857 -- D1 in R empty itself no
5858 -- D2 in R empty itself no
5859 -- D3 in R empty itself no
5861 -- D1 in T1 D1 in R D1 in R no
5862 -- D2 in T1 D2 in R D2 in R no
5863 -- D3 in T1 D3 in R D3 in R no
5865 -- X1 in T2 D3 in T1 D3 in R no
5866 -- X2 in T2 D1 in T1 D1 in R no
5868 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
5870 -- Regardless of whether we dealing with a tagged or untagged type
5871 -- we will transform all derived type declarations of the form
5873 -- type T is new R (...) [with ...];
5875 -- subtype S is R (...);
5876 -- type T is new S [with ...];
5878 -- type BT is new R [with ...];
5879 -- subtype T is BT (...);
5881 -- That is, the base derived type is constrained only if it has no
5882 -- discriminants. The reason for doing this is that GNAT's semantic model
5883 -- assumes that a base type with discriminants is unconstrained.
5885 -- Note that, strictly speaking, the above transformation is not always
5886 -- correct. Consider for instance the following excerpt from ACVC b34011a:
5888 -- procedure B34011A is
5889 -- type REC (D : integer := 0) is record
5894 -- type T6 is new Rec;
5895 -- function F return T6;
5900 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
5903 -- The definition of Q6.U is illegal. However transforming Q6.U into
5905 -- type BaseU is new T6;
5906 -- subtype U is BaseU (Q6.F.I)
5908 -- turns U into a legal subtype, which is incorrect. To avoid this problem
5909 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
5910 -- the transformation described above.
5912 -- There is another instance where the above transformation is incorrect.
5916 -- type Base (D : Integer) is tagged null record;
5917 -- procedure P (X : Base);
5919 -- type Der is new Base (2) with null record;
5920 -- procedure P (X : Der);
5923 -- Then the above transformation turns this into
5925 -- type Der_Base is new Base with null record;
5926 -- -- procedure P (X : Base) is implicitly inherited here
5927 -- -- as procedure P (X : Der_Base).
5929 -- subtype Der is Der_Base (2);
5930 -- procedure P (X : Der);
5931 -- -- The overriding of P (X : Der_Base) is illegal since we
5932 -- -- have a parameter conformance problem.
5934 -- To get around this problem, after having semantically processed Der_Base
5935 -- and the rewritten subtype declaration for Der, we copy Der_Base field
5936 -- Discriminant_Constraint from Der so that when parameter conformance is
5937 -- checked when P is overridden, no semantic errors are flagged.
5939 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
5941 -- Regardless of whether we are dealing with a tagged or untagged type
5942 -- we will transform all derived type declarations of the form
5944 -- type R (D1, .., Dn : ...) is [tagged] record ...;
5945 -- type T is new R [with ...];
5947 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
5949 -- The reason for such transformation is that it allows us to implement a
5950 -- very clean form of component inheritance as explained below.
5952 -- Note that this transformation is not achieved by direct tree rewriting
5953 -- and manipulation, but rather by redoing the semantic actions that the
5954 -- above transformation will entail. This is done directly in routine
5955 -- Inherit_Components.
5957 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
5959 -- In both tagged and untagged derived types, regular non discriminant
5960 -- components are inherited in the derived type from the parent type. In
5961 -- the absence of discriminants component, inheritance is straightforward
5962 -- as components can simply be copied from the parent.
5964 -- If the parent has discriminants, inheriting components constrained with
5965 -- these discriminants requires caution. Consider the following example:
5967 -- type R (D1, D2 : Positive) is [tagged] record
5968 -- S : String (D1 .. D2);
5971 -- type T1 is new R [with null record];
5972 -- type T2 (X : positive) is new R (1, X) [with null record];
5974 -- As explained in 6. above, T1 is rewritten as
5975 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
5976 -- which makes the treatment for T1 and T2 identical.
5978 -- What we want when inheriting S, is that references to D1 and D2 in R are
5979 -- replaced with references to their correct constraints, i.e. D1 and D2 in
5980 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
5981 -- with either discriminant references in the derived type or expressions.
5982 -- This replacement is achieved as follows: before inheriting R's
5983 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
5984 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
5985 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
5986 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
5987 -- by String (1 .. X).
5989 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
5991 -- We explain here the rules governing private type extensions relevant to
5992 -- type derivation. These rules are explained on the following example:
5994 -- type D [(...)] is new A [(...)] with private; <-- partial view
5995 -- type D [(...)] is new P [(...)] with null record; <-- full view
5997 -- Type A is called the ancestor subtype of the private extension.
5998 -- Type P is the parent type of the full view of the private extension. It
5999 -- must be A or a type derived from A.
6001 -- The rules concerning the discriminants of private type extensions are
6004 -- o If a private extension inherits known discriminants from the ancestor
6005 -- subtype, then the full view shall also inherit its discriminants from
6006 -- the ancestor subtype and the parent subtype of the full view shall be
6007 -- constrained if and only if the ancestor subtype is constrained.
6009 -- o If a partial view has unknown discriminants, then the full view may
6010 -- define a definite or an indefinite subtype, with or without
6013 -- o If a partial view has neither known nor unknown discriminants, then
6014 -- the full view shall define a definite subtype.
6016 -- o If the ancestor subtype of a private extension has constrained
6017 -- discriminants, then the parent subtype of the full view shall impose a
6018 -- statically matching constraint on those discriminants.
6020 -- This means that only the following forms of private extensions are
6023 -- type D is new A with private; <-- partial view
6024 -- type D is new P with null record; <-- full view
6026 -- If A has no discriminants than P has no discriminants, otherwise P must
6027 -- inherit A's discriminants.
6029 -- type D is new A (...) with private; <-- partial view
6030 -- type D is new P (:::) with null record; <-- full view
6032 -- P must inherit A's discriminants and (...) and (:::) must statically
6035 -- subtype A is R (...);
6036 -- type D is new A with private; <-- partial view
6037 -- type D is new P with null record; <-- full view
6039 -- P must have inherited R's discriminants and must be derived from A or
6040 -- any of its subtypes.
6042 -- type D (..) is new A with private; <-- partial view
6043 -- type D (..) is new P [(:::)] with null record; <-- full view
6045 -- No specific constraints on P's discriminants or constraint (:::).
6046 -- Note that A can be unconstrained, but the parent subtype P must either
6047 -- be constrained or (:::) must be present.
6049 -- type D (..) is new A [(...)] with private; <-- partial view
6050 -- type D (..) is new P [(:::)] with null record; <-- full view
6052 -- P's constraints on A's discriminants must statically match those
6053 -- imposed by (...).
6055 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
6057 -- The full view of a private extension is handled exactly as described
6058 -- above. The model chose for the private view of a private extension is
6059 -- the same for what concerns discriminants (i.e. they receive the same
6060 -- treatment as in the tagged case). However, the private view of the
6061 -- private extension always inherits the components of the parent base,
6062 -- without replacing any discriminant reference. Strictly speaking this is
6063 -- incorrect. However, Gigi never uses this view to generate code so this
6064 -- is a purely semantic issue. In theory, a set of transformations similar
6065 -- to those given in 5. and 6. above could be applied to private views of
6066 -- private extensions to have the same model of component inheritance as
6067 -- for non private extensions. However, this is not done because it would
6068 -- further complicate private type processing. Semantically speaking, this
6069 -- leaves us in an uncomfortable situation. As an example consider:
6072 -- type R (D : integer) is tagged record
6073 -- S : String (1 .. D);
6075 -- procedure P (X : R);
6076 -- type T is new R (1) with private;
6078 -- type T is new R (1) with null record;
6081 -- This is transformed into:
6084 -- type R (D : integer) is tagged record
6085 -- S : String (1 .. D);
6087 -- procedure P (X : R);
6088 -- type T is new R (1) with private;
6090 -- type BaseT is new R with null record;
6091 -- subtype T is BaseT (1);
6094 -- (strictly speaking the above is incorrect Ada)
6096 -- From the semantic standpoint the private view of private extension T
6097 -- should be flagged as constrained since one can clearly have
6101 -- in a unit withing Pack. However, when deriving subprograms for the
6102 -- private view of private extension T, T must be seen as unconstrained
6103 -- since T has discriminants (this is a constraint of the current
6104 -- subprogram derivation model). Thus, when processing the private view of
6105 -- a private extension such as T, we first mark T as unconstrained, we
6106 -- process it, we perform program derivation and just before returning from
6107 -- Build_Derived_Record_Type we mark T as constrained.
6109 -- ??? Are there are other uncomfortable cases that we will have to
6112 -- 10. RECORD_TYPE_WITH_PRIVATE complications
6114 -- Types that are derived from a visible record type and have a private
6115 -- extension present other peculiarities. They behave mostly like private
6116 -- types, but if they have primitive operations defined, these will not
6117 -- have the proper signatures for further inheritance, because other
6118 -- primitive operations will use the implicit base that we define for
6119 -- private derivations below. This affect subprogram inheritance (see
6120 -- Derive_Subprograms for details). We also derive the implicit base from
6121 -- the base type of the full view, so that the implicit base is a record
6122 -- type and not another private type, This avoids infinite loops.
6124 procedure Build_Derived_Record_Type
6126 Parent_Type : Entity_Id;
6127 Derived_Type : Entity_Id;
6128 Derive_Subps : Boolean := True)
6130 Loc : constant Source_Ptr := Sloc (N);
6131 Parent_Base : Entity_Id;
6134 Discrim : Entity_Id;
6135 Last_Discrim : Entity_Id;
6138 Discs : Elist_Id := New_Elmt_List;
6139 -- An empty Discs list means that there were no constraints in the
6140 -- subtype indication or that there was an error processing it.
6142 Assoc_List : Elist_Id;
6143 New_Discrs : Elist_Id;
6144 New_Base : Entity_Id;
6146 New_Indic : Node_Id;
6148 Is_Tagged : constant Boolean := Is_Tagged_Type (Parent_Type);
6149 Discriminant_Specs : constant Boolean :=
6150 Present (Discriminant_Specifications (N));
6151 Private_Extension : constant Boolean :=
6152 Nkind (N) = N_Private_Extension_Declaration;
6154 Constraint_Present : Boolean;
6155 Inherit_Discrims : Boolean := False;
6156 Save_Etype : Entity_Id;
6157 Save_Discr_Constr : Elist_Id;
6158 Save_Next_Entity : Entity_Id;
6161 if Ekind (Parent_Type) = E_Record_Type_With_Private
6162 and then Present (Full_View (Parent_Type))
6163 and then Has_Discriminants (Parent_Type)
6165 Parent_Base := Base_Type (Full_View (Parent_Type));
6167 Parent_Base := Base_Type (Parent_Type);
6170 -- Before we start the previously documented transformations, here is
6171 -- little fix for size and alignment of tagged types. Normally when we
6172 -- derive type D from type P, we copy the size and alignment of P as the
6173 -- default for D, and in the absence of explicit representation clauses
6174 -- for D, the size and alignment are indeed the same as the parent.
6176 -- But this is wrong for tagged types, since fields may be added, and
6177 -- the default size may need to be larger, and the default alignment may
6178 -- need to be larger.
6180 -- We therefore reset the size and alignment fields in the tagged case.
6181 -- Note that the size and alignment will in any case be at least as
6182 -- large as the parent type (since the derived type has a copy of the
6183 -- parent type in the _parent field)
6185 -- The type is also marked as being tagged here, which is needed when
6186 -- processing components with a self-referential anonymous access type
6187 -- in the call to Check_Anonymous_Access_Components below. Note that
6188 -- this flag is also set later on for completeness.
6191 Set_Is_Tagged_Type (Derived_Type);
6192 Init_Size_Align (Derived_Type);
6195 -- STEP 0a: figure out what kind of derived type declaration we have
6197 if Private_Extension then
6199 Set_Ekind (Derived_Type, E_Record_Type_With_Private);
6202 Type_Def := Type_Definition (N);
6204 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
6205 -- Parent_Base can be a private type or private extension. However,
6206 -- for tagged types with an extension the newly added fields are
6207 -- visible and hence the Derived_Type is always an E_Record_Type.
6208 -- (except that the parent may have its own private fields).
6209 -- For untagged types we preserve the Ekind of the Parent_Base.
6211 if Present (Record_Extension_Part (Type_Def)) then
6212 Set_Ekind (Derived_Type, E_Record_Type);
6214 -- Create internal access types for components with anonymous
6217 if Ada_Version >= Ada_05 then
6218 Check_Anonymous_Access_Components
6219 (N, Derived_Type, Derived_Type,
6220 Component_List (Record_Extension_Part (Type_Def)));
6224 Set_Ekind (Derived_Type, Ekind (Parent_Base));
6228 -- Indic can either be an N_Identifier if the subtype indication
6229 -- contains no constraint or an N_Subtype_Indication if the subtype
6230 -- indication has a constraint.
6232 Indic := Subtype_Indication (Type_Def);
6233 Constraint_Present := (Nkind (Indic) = N_Subtype_Indication);
6235 -- Check that the type has visible discriminants. The type may be
6236 -- a private type with unknown discriminants whose full view has
6237 -- discriminants which are invisible.
6239 if Constraint_Present then
6240 if not Has_Discriminants (Parent_Base)
6242 (Has_Unknown_Discriminants (Parent_Base)
6243 and then Is_Private_Type (Parent_Base))
6246 ("invalid constraint: type has no discriminant",
6247 Constraint (Indic));
6249 Constraint_Present := False;
6250 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6252 elsif Is_Constrained (Parent_Type) then
6254 ("invalid constraint: parent type is already constrained",
6255 Constraint (Indic));
6257 Constraint_Present := False;
6258 Rewrite (Indic, New_Copy_Tree (Subtype_Mark (Indic)));
6262 -- STEP 0b: If needed, apply transformation given in point 5. above
6264 if not Private_Extension
6265 and then Has_Discriminants (Parent_Type)
6266 and then not Discriminant_Specs
6267 and then (Is_Constrained (Parent_Type) or else Constraint_Present)
6269 -- First, we must analyze the constraint (see comment in point 5.)
6271 if Constraint_Present then
6272 New_Discrs := Build_Discriminant_Constraints (Parent_Type, Indic);
6274 if Has_Discriminants (Derived_Type)
6275 and then Has_Private_Declaration (Derived_Type)
6276 and then Present (Discriminant_Constraint (Derived_Type))
6278 -- Verify that constraints of the full view statically match
6279 -- those given in the partial view.
6285 C1 := First_Elmt (New_Discrs);
6286 C2 := First_Elmt (Discriminant_Constraint (Derived_Type));
6287 while Present (C1) and then Present (C2) loop
6289 if Fully_Conformant_Expressions (Node (C1), Node (C2))
6291 (Is_OK_Static_Expression (Node (C1))
6293 Is_OK_Static_Expression (Node (C2))
6295 Expr_Value (Node (C1)) = Expr_Value (Node (C2)))
6301 "constraint not conformant to previous declaration",
6312 -- Insert and analyze the declaration for the unconstrained base type
6314 New_Base := Create_Itype (Ekind (Derived_Type), N, Derived_Type, 'B');
6317 Make_Full_Type_Declaration (Loc,
6318 Defining_Identifier => New_Base,
6320 Make_Derived_Type_Definition (Loc,
6321 Abstract_Present => Abstract_Present (Type_Def),
6322 Subtype_Indication =>
6323 New_Occurrence_Of (Parent_Base, Loc),
6324 Record_Extension_Part =>
6325 Relocate_Node (Record_Extension_Part (Type_Def))));
6327 Set_Parent (New_Decl, Parent (N));
6328 Mark_Rewrite_Insertion (New_Decl);
6329 Insert_Before (N, New_Decl);
6331 -- Note that this call passes False for the Derive_Subps parameter
6332 -- because subprogram derivation is deferred until after creating
6333 -- the subtype (see below).
6336 (New_Decl, Parent_Base, New_Base,
6337 Is_Completion => True, Derive_Subps => False);
6339 -- ??? This needs re-examination to determine whether the
6340 -- above call can simply be replaced by a call to Analyze.
6342 Set_Analyzed (New_Decl);
6344 -- Insert and analyze the declaration for the constrained subtype
6346 if Constraint_Present then
6348 Make_Subtype_Indication (Loc,
6349 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6350 Constraint => Relocate_Node (Constraint (Indic)));
6354 Constr_List : constant List_Id := New_List;
6359 C := First_Elmt (Discriminant_Constraint (Parent_Type));
6360 while Present (C) loop
6363 -- It is safe here to call New_Copy_Tree since
6364 -- Force_Evaluation was called on each constraint in
6365 -- Build_Discriminant_Constraints.
6367 Append (New_Copy_Tree (Expr), To => Constr_List);
6373 Make_Subtype_Indication (Loc,
6374 Subtype_Mark => New_Occurrence_Of (New_Base, Loc),
6376 Make_Index_Or_Discriminant_Constraint (Loc, Constr_List));
6381 Make_Subtype_Declaration (Loc,
6382 Defining_Identifier => Derived_Type,
6383 Subtype_Indication => New_Indic));
6387 -- Derivation of subprograms must be delayed until the full subtype
6388 -- has been established to ensure proper overriding of subprograms
6389 -- inherited by full types. If the derivations occurred as part of
6390 -- the call to Build_Derived_Type above, then the check for type
6391 -- conformance would fail because earlier primitive subprograms
6392 -- could still refer to the full type prior the change to the new
6393 -- subtype and hence would not match the new base type created here.
6395 Derive_Subprograms (Parent_Type, Derived_Type);
6397 -- For tagged types the Discriminant_Constraint of the new base itype
6398 -- is inherited from the first subtype so that no subtype conformance
6399 -- problem arise when the first subtype overrides primitive
6400 -- operations inherited by the implicit base type.
6403 Set_Discriminant_Constraint
6404 (New_Base, Discriminant_Constraint (Derived_Type));
6410 -- If we get here Derived_Type will have no discriminants or it will be
6411 -- a discriminated unconstrained base type.
6413 -- STEP 1a: perform preliminary actions/checks for derived tagged types
6417 -- The parent type is frozen for non-private extensions (RM 13.14(7))
6418 -- The declaration of a specific descendant of an interface type
6419 -- freezes the interface type (RM 13.14).
6421 if not Private_Extension
6422 or else Is_Interface (Parent_Base)
6424 Freeze_Before (N, Parent_Type);
6427 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
6428 -- cannot be declared at a deeper level than its parent type is
6429 -- removed. The check on derivation within a generic body is also
6430 -- relaxed, but there's a restriction that a derived tagged type
6431 -- cannot be declared in a generic body if it's derived directly
6432 -- or indirectly from a formal type of that generic.
6434 if Ada_Version >= Ada_05 then
6435 if Present (Enclosing_Generic_Body (Derived_Type)) then
6437 Ancestor_Type : Entity_Id;
6440 -- Check to see if any ancestor of the derived type is a
6443 Ancestor_Type := Parent_Type;
6444 while not Is_Generic_Type (Ancestor_Type)
6445 and then Etype (Ancestor_Type) /= Ancestor_Type
6447 Ancestor_Type := Etype (Ancestor_Type);
6450 -- If the derived type does have a formal type as an
6451 -- ancestor, then it's an error if the derived type is
6452 -- declared within the body of the generic unit that
6453 -- declares the formal type in its generic formal part. It's
6454 -- sufficient to check whether the ancestor type is declared
6455 -- inside the same generic body as the derived type (such as
6456 -- within a nested generic spec), in which case the
6457 -- derivation is legal. If the formal type is declared
6458 -- outside of that generic body, then it's guaranteed that
6459 -- the derived type is declared within the generic body of
6460 -- the generic unit declaring the formal type.
6462 if Is_Generic_Type (Ancestor_Type)
6463 and then Enclosing_Generic_Body (Ancestor_Type) /=
6464 Enclosing_Generic_Body (Derived_Type)
6467 ("parent type of& must not be descendant of formal type"
6468 & " of an enclosing generic body",
6469 Indic, Derived_Type);
6474 elsif Type_Access_Level (Derived_Type) /=
6475 Type_Access_Level (Parent_Type)
6476 and then not Is_Generic_Type (Derived_Type)
6478 if Is_Controlled (Parent_Type) then
6480 ("controlled type must be declared at the library level",
6484 ("type extension at deeper accessibility level than parent",
6490 GB : constant Node_Id := Enclosing_Generic_Body (Derived_Type);
6494 and then GB /= Enclosing_Generic_Body (Parent_Base)
6497 ("parent type of& must not be outside generic body"
6499 Indic, Derived_Type);
6505 -- Ada 2005 (AI-251)
6507 if Ada_Version = Ada_05
6510 -- "The declaration of a specific descendant of an interface type
6511 -- freezes the interface type" (RM 13.14).
6516 if Is_Non_Empty_List (Interface_List (Type_Def)) then
6517 Iface := First (Interface_List (Type_Def));
6518 while Present (Iface) loop
6519 Freeze_Before (N, Etype (Iface));
6526 -- STEP 1b : preliminary cleanup of the full view of private types
6528 -- If the type is already marked as having discriminants, then it's the
6529 -- completion of a private type or private extension and we need to
6530 -- retain the discriminants from the partial view if the current
6531 -- declaration has Discriminant_Specifications so that we can verify
6532 -- conformance. However, we must remove any existing components that
6533 -- were inherited from the parent (and attached in Copy_And_Swap)
6534 -- because the full type inherits all appropriate components anyway, and
6535 -- we do not want the partial view's components interfering.
6537 if Has_Discriminants (Derived_Type) and then Discriminant_Specs then
6538 Discrim := First_Discriminant (Derived_Type);
6540 Last_Discrim := Discrim;
6541 Next_Discriminant (Discrim);
6542 exit when No (Discrim);
6545 Set_Last_Entity (Derived_Type, Last_Discrim);
6547 -- In all other cases wipe out the list of inherited components (even
6548 -- inherited discriminants), it will be properly rebuilt here.
6551 Set_First_Entity (Derived_Type, Empty);
6552 Set_Last_Entity (Derived_Type, Empty);
6555 -- STEP 1c: Initialize some flags for the Derived_Type
6557 -- The following flags must be initialized here so that
6558 -- Process_Discriminants can check that discriminants of tagged types do
6559 -- not have a default initial value and that access discriminants are
6560 -- only specified for limited records. For completeness, these flags are
6561 -- also initialized along with all the other flags below.
6563 -- AI-419: Limitedness is not inherited from an interface parent, so to
6564 -- be limited in that case the type must be explicitly declared as
6565 -- limited. However, task and protected interfaces are always limited.
6567 if Limited_Present (Type_Def) then
6568 Set_Is_Limited_Record (Derived_Type);
6570 elsif Is_Limited_Record (Parent_Type)
6571 or else (Present (Full_View (Parent_Type))
6572 and then Is_Limited_Record (Full_View (Parent_Type)))
6574 if not Is_Interface (Parent_Type)
6575 or else Is_Synchronized_Interface (Parent_Type)
6576 or else Is_Protected_Interface (Parent_Type)
6577 or else Is_Task_Interface (Parent_Type)
6579 Set_Is_Limited_Record (Derived_Type);
6583 -- STEP 2a: process discriminants of derived type if any
6585 Push_Scope (Derived_Type);
6587 if Discriminant_Specs then
6588 Set_Has_Unknown_Discriminants (Derived_Type, False);
6590 -- The following call initializes fields Has_Discriminants and
6591 -- Discriminant_Constraint, unless we are processing the completion
6592 -- of a private type declaration.
6594 Check_Or_Process_Discriminants (N, Derived_Type);
6596 -- For non-tagged types the constraint on the Parent_Type must be
6597 -- present and is used to rename the discriminants.
6599 if not Is_Tagged and then not Has_Discriminants (Parent_Type) then
6600 Error_Msg_N ("untagged parent must have discriminants", Indic);
6602 elsif not Is_Tagged and then not Constraint_Present then
6604 ("discriminant constraint needed for derived untagged records",
6607 -- Otherwise the parent subtype must be constrained unless we have a
6608 -- private extension.
6610 elsif not Constraint_Present
6611 and then not Private_Extension
6612 and then not Is_Constrained (Parent_Type)
6615 ("unconstrained type not allowed in this context", Indic);
6617 elsif Constraint_Present then
6618 -- The following call sets the field Corresponding_Discriminant
6619 -- for the discriminants in the Derived_Type.
6621 Discs := Build_Discriminant_Constraints (Parent_Type, Indic, True);
6623 -- For untagged types all new discriminants must rename
6624 -- discriminants in the parent. For private extensions new
6625 -- discriminants cannot rename old ones (implied by [7.3(13)]).
6627 Discrim := First_Discriminant (Derived_Type);
6628 while Present (Discrim) loop
6630 and then No (Corresponding_Discriminant (Discrim))
6633 ("new discriminants must constrain old ones", Discrim);
6635 elsif Private_Extension
6636 and then Present (Corresponding_Discriminant (Discrim))
6639 ("only static constraints allowed for parent"
6640 & " discriminants in the partial view", Indic);
6644 -- If a new discriminant is used in the constraint, then its
6645 -- subtype must be statically compatible with the parent
6646 -- discriminant's subtype (3.7(15)).
6648 if Present (Corresponding_Discriminant (Discrim))
6650 not Subtypes_Statically_Compatible
6652 Etype (Corresponding_Discriminant (Discrim)))
6655 ("subtype must be compatible with parent discriminant",
6659 Next_Discriminant (Discrim);
6662 -- Check whether the constraints of the full view statically
6663 -- match those imposed by the parent subtype [7.3(13)].
6665 if Present (Stored_Constraint (Derived_Type)) then
6670 C1 := First_Elmt (Discs);
6671 C2 := First_Elmt (Stored_Constraint (Derived_Type));
6672 while Present (C1) and then Present (C2) loop
6674 Fully_Conformant_Expressions (Node (C1), Node (C2))
6677 ("not conformant with previous declaration",
6688 -- STEP 2b: No new discriminants, inherit discriminants if any
6691 if Private_Extension then
6692 Set_Has_Unknown_Discriminants
6694 Has_Unknown_Discriminants (Parent_Type)
6695 or else Unknown_Discriminants_Present (N));
6697 -- The partial view of the parent may have unknown discriminants,
6698 -- but if the full view has discriminants and the parent type is
6699 -- in scope they must be inherited.
6701 elsif Has_Unknown_Discriminants (Parent_Type)
6703 (not Has_Discriminants (Parent_Type)
6704 or else not In_Open_Scopes (Scope (Parent_Type)))
6706 Set_Has_Unknown_Discriminants (Derived_Type);
6709 if not Has_Unknown_Discriminants (Derived_Type)
6710 and then not Has_Unknown_Discriminants (Parent_Base)
6711 and then Has_Discriminants (Parent_Type)
6713 Inherit_Discrims := True;
6714 Set_Has_Discriminants
6715 (Derived_Type, True);
6716 Set_Discriminant_Constraint
6717 (Derived_Type, Discriminant_Constraint (Parent_Base));
6720 -- The following test is true for private types (remember
6721 -- transformation 5. is not applied to those) and in an error
6724 if Constraint_Present then
6725 Discs := Build_Discriminant_Constraints (Parent_Type, Indic);
6728 -- For now mark a new derived type as constrained only if it has no
6729 -- discriminants. At the end of Build_Derived_Record_Type we properly
6730 -- set this flag in the case of private extensions. See comments in
6731 -- point 9. just before body of Build_Derived_Record_Type.
6735 not (Inherit_Discrims
6736 or else Has_Unknown_Discriminants (Derived_Type)));
6739 -- STEP 3: initialize fields of derived type
6741 Set_Is_Tagged_Type (Derived_Type, Is_Tagged);
6742 Set_Stored_Constraint (Derived_Type, No_Elist);
6744 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
6745 -- but cannot be interfaces
6747 if not Private_Extension
6748 and then Ekind (Derived_Type) /= E_Private_Type
6749 and then Ekind (Derived_Type) /= E_Limited_Private_Type
6751 if Interface_Present (Type_Def) then
6752 Analyze_Interface_Declaration (Derived_Type, Type_Def);
6755 Set_Interfaces (Derived_Type, No_Elist);
6758 -- Fields inherited from the Parent_Type
6761 (Derived_Type, Einfo.Discard_Names (Parent_Type));
6762 Set_Has_Specified_Layout
6763 (Derived_Type, Has_Specified_Layout (Parent_Type));
6764 Set_Is_Limited_Composite
6765 (Derived_Type, Is_Limited_Composite (Parent_Type));
6766 Set_Is_Private_Composite
6767 (Derived_Type, Is_Private_Composite (Parent_Type));
6769 -- Fields inherited from the Parent_Base
6771 Set_Has_Controlled_Component
6772 (Derived_Type, Has_Controlled_Component (Parent_Base));
6773 Set_Has_Non_Standard_Rep
6774 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6775 Set_Has_Primitive_Operations
6776 (Derived_Type, Has_Primitive_Operations (Parent_Base));
6778 -- Fields inherited from the Parent_Base in the non-private case
6780 if Ekind (Derived_Type) = E_Record_Type then
6781 Set_Has_Complex_Representation
6782 (Derived_Type, Has_Complex_Representation (Parent_Base));
6785 -- Fields inherited from the Parent_Base for record types
6787 if Is_Record_Type (Derived_Type) then
6788 Set_OK_To_Reorder_Components
6789 (Derived_Type, OK_To_Reorder_Components (Parent_Base));
6790 Set_Reverse_Bit_Order
6791 (Derived_Type, Reverse_Bit_Order (Parent_Base));
6794 -- Direct controlled types do not inherit Finalize_Storage_Only flag
6796 if not Is_Controlled (Parent_Type) then
6797 Set_Finalize_Storage_Only
6798 (Derived_Type, Finalize_Storage_Only (Parent_Type));
6801 -- Set fields for private derived types
6803 if Is_Private_Type (Derived_Type) then
6804 Set_Depends_On_Private (Derived_Type, True);
6805 Set_Private_Dependents (Derived_Type, New_Elmt_List);
6807 -- Inherit fields from non private record types. If this is the
6808 -- completion of a derivation from a private type, the parent itself
6809 -- is private, and the attributes come from its full view, which must
6813 if Is_Private_Type (Parent_Base)
6814 and then not Is_Record_Type (Parent_Base)
6816 Set_Component_Alignment
6817 (Derived_Type, Component_Alignment (Full_View (Parent_Base)));
6819 (Derived_Type, C_Pass_By_Copy (Full_View (Parent_Base)));
6821 Set_Component_Alignment
6822 (Derived_Type, Component_Alignment (Parent_Base));
6825 (Derived_Type, C_Pass_By_Copy (Parent_Base));
6829 -- Set fields for tagged types
6832 Set_Primitive_Operations (Derived_Type, New_Elmt_List);
6834 -- All tagged types defined in Ada.Finalization are controlled
6836 if Chars (Scope (Derived_Type)) = Name_Finalization
6837 and then Chars (Scope (Scope (Derived_Type))) = Name_Ada
6838 and then Scope (Scope (Scope (Derived_Type))) = Standard_Standard
6840 Set_Is_Controlled (Derived_Type);
6842 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Base));
6845 Make_Class_Wide_Type (Derived_Type);
6846 Set_Is_Abstract_Type (Derived_Type, Abstract_Present (Type_Def));
6848 if Has_Discriminants (Derived_Type)
6849 and then Constraint_Present
6851 Set_Stored_Constraint
6852 (Derived_Type, Expand_To_Stored_Constraint (Parent_Base, Discs));
6855 if Ada_Version >= Ada_05 then
6857 Ifaces_List : Elist_Id;
6860 -- Checks rules 3.9.4 (13/2 and 14/2)
6862 if Comes_From_Source (Derived_Type)
6863 and then not Is_Private_Type (Derived_Type)
6864 and then Is_Interface (Parent_Type)
6865 and then not Is_Interface (Derived_Type)
6867 if Is_Task_Interface (Parent_Type) then
6869 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
6872 elsif Is_Protected_Interface (Parent_Type) then
6874 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
6879 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
6881 Check_Interfaces (N, Type_Def);
6883 -- Ada 2005 (AI-251): Collect the list of progenitors that are
6884 -- not already in the parents.
6888 Ifaces_List => Ifaces_List,
6889 Exclude_Parents => True);
6891 Set_Interfaces (Derived_Type, Ifaces_List);
6896 Set_Is_Packed (Derived_Type, Is_Packed (Parent_Base));
6897 Set_Has_Non_Standard_Rep
6898 (Derived_Type, Has_Non_Standard_Rep (Parent_Base));
6901 -- STEP 4: Inherit components from the parent base and constrain them.
6902 -- Apply the second transformation described in point 6. above.
6904 if (not Is_Empty_Elmt_List (Discs) or else Inherit_Discrims)
6905 or else not Has_Discriminants (Parent_Type)
6906 or else not Is_Constrained (Parent_Type)
6910 Constrs := Discriminant_Constraint (Parent_Type);
6915 (N, Parent_Base, Derived_Type, Is_Tagged, Inherit_Discrims, Constrs);
6917 -- STEP 5a: Copy the parent record declaration for untagged types
6919 if not Is_Tagged then
6921 -- Discriminant_Constraint (Derived_Type) has been properly
6922 -- constructed. Save it and temporarily set it to Empty because we
6923 -- do not want the call to New_Copy_Tree below to mess this list.
6925 if Has_Discriminants (Derived_Type) then
6926 Save_Discr_Constr := Discriminant_Constraint (Derived_Type);
6927 Set_Discriminant_Constraint (Derived_Type, No_Elist);
6929 Save_Discr_Constr := No_Elist;
6932 -- Save the Etype field of Derived_Type. It is correctly set now,
6933 -- but the call to New_Copy tree may remap it to point to itself,
6934 -- which is not what we want. Ditto for the Next_Entity field.
6936 Save_Etype := Etype (Derived_Type);
6937 Save_Next_Entity := Next_Entity (Derived_Type);
6939 -- Assoc_List maps all stored discriminants in the Parent_Base to
6940 -- stored discriminants in the Derived_Type. It is fundamental that
6941 -- no types or itypes with discriminants other than the stored
6942 -- discriminants appear in the entities declared inside
6943 -- Derived_Type, since the back end cannot deal with it.
6947 (Parent (Parent_Base), Map => Assoc_List, New_Sloc => Loc);
6949 -- Restore the fields saved prior to the New_Copy_Tree call
6950 -- and compute the stored constraint.
6952 Set_Etype (Derived_Type, Save_Etype);
6953 Set_Next_Entity (Derived_Type, Save_Next_Entity);
6955 if Has_Discriminants (Derived_Type) then
6956 Set_Discriminant_Constraint
6957 (Derived_Type, Save_Discr_Constr);
6958 Set_Stored_Constraint
6959 (Derived_Type, Expand_To_Stored_Constraint (Parent_Type, Discs));
6960 Replace_Components (Derived_Type, New_Decl);
6963 -- Insert the new derived type declaration
6965 Rewrite (N, New_Decl);
6967 -- STEP 5b: Complete the processing for record extensions in generics
6969 -- There is no completion for record extensions declared in the
6970 -- parameter part of a generic, so we need to complete processing for
6971 -- these generic record extensions here. The Record_Type_Definition call
6972 -- will change the Ekind of the components from E_Void to E_Component.
6974 elsif Private_Extension and then Is_Generic_Type (Derived_Type) then
6975 Record_Type_Definition (Empty, Derived_Type);
6977 -- STEP 5c: Process the record extension for non private tagged types
6979 elsif not Private_Extension then
6981 -- Add the _parent field in the derived type
6983 Expand_Record_Extension (Derived_Type, Type_Def);
6985 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
6986 -- implemented interfaces if we are in expansion mode
6989 and then Has_Interfaces (Derived_Type)
6991 Add_Interface_Tag_Components (N, Derived_Type);
6994 -- Analyze the record extension
6996 Record_Type_Definition
6997 (Record_Extension_Part (Type_Def), Derived_Type);
7002 -- Nothing else to do if there is an error in the derivation.
7003 -- An unusual case: the full view may be derived from a type in an
7004 -- instance, when the partial view was used illegally as an actual
7005 -- in that instance, leading to a circular definition.
7007 if Etype (Derived_Type) = Any_Type
7008 or else Etype (Parent_Type) = Derived_Type
7013 -- Set delayed freeze and then derive subprograms, we need to do
7014 -- this in this order so that derived subprograms inherit the
7015 -- derived freeze if necessary.
7017 Set_Has_Delayed_Freeze (Derived_Type);
7019 if Derive_Subps then
7020 Derive_Subprograms (Parent_Type, Derived_Type);
7023 -- If we have a private extension which defines a constrained derived
7024 -- type mark as constrained here after we have derived subprograms. See
7025 -- comment on point 9. just above the body of Build_Derived_Record_Type.
7027 if Private_Extension and then Inherit_Discrims then
7028 if Constraint_Present and then not Is_Empty_Elmt_List (Discs) then
7029 Set_Is_Constrained (Derived_Type, True);
7030 Set_Discriminant_Constraint (Derived_Type, Discs);
7032 elsif Is_Constrained (Parent_Type) then
7034 (Derived_Type, True);
7035 Set_Discriminant_Constraint
7036 (Derived_Type, Discriminant_Constraint (Parent_Type));
7040 -- Update the class_wide type, which shares the now-completed
7041 -- entity list with its specific type.
7045 (Class_Wide_Type (Derived_Type), First_Entity (Derived_Type));
7047 (Class_Wide_Type (Derived_Type), Last_Entity (Derived_Type));
7050 -- Update the scope of anonymous access types of discriminants and other
7051 -- components, to prevent scope anomalies in gigi, when the derivation
7052 -- appears in a scope nested within that of the parent.
7058 D := First_Entity (Derived_Type);
7059 while Present (D) loop
7060 if Ekind (D) = E_Discriminant
7061 or else Ekind (D) = E_Component
7063 if Is_Itype (Etype (D))
7064 and then Ekind (Etype (D)) = E_Anonymous_Access_Type
7066 Set_Scope (Etype (D), Current_Scope);
7073 end Build_Derived_Record_Type;
7075 ------------------------
7076 -- Build_Derived_Type --
7077 ------------------------
7079 procedure Build_Derived_Type
7081 Parent_Type : Entity_Id;
7082 Derived_Type : Entity_Id;
7083 Is_Completion : Boolean;
7084 Derive_Subps : Boolean := True)
7086 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
7089 -- Set common attributes
7091 Set_Scope (Derived_Type, Current_Scope);
7093 Set_Ekind (Derived_Type, Ekind (Parent_Base));
7094 Set_Etype (Derived_Type, Parent_Base);
7095 Set_Has_Task (Derived_Type, Has_Task (Parent_Base));
7097 Set_Size_Info (Derived_Type, Parent_Type);
7098 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
7099 Set_Convention (Derived_Type, Convention (Parent_Type));
7100 Set_Is_Controlled (Derived_Type, Is_Controlled (Parent_Type));
7102 -- The derived type inherits the representation clauses of the parent.
7103 -- However, for a private type that is completed by a derivation, there
7104 -- may be operation attributes that have been specified already (stream
7105 -- attributes and External_Tag) and those must be provided. Finally,
7106 -- if the partial view is a private extension, the representation items
7107 -- of the parent have been inherited already, and should not be chained
7108 -- twice to the derived type.
7110 if Is_Tagged_Type (Parent_Type)
7111 and then Present (First_Rep_Item (Derived_Type))
7113 -- The existing items are either operational items or items inherited
7114 -- from a private extension declaration.
7118 -- Used to iterate over representation items of the derived type
7121 -- Last representation item of the (non-empty) representation
7122 -- item list of the derived type.
7124 Found : Boolean := False;
7127 Rep := First_Rep_Item (Derived_Type);
7129 while Present (Rep) loop
7130 if Rep = First_Rep_Item (Parent_Type) then
7135 Rep := Next_Rep_Item (Rep);
7137 if Present (Rep) then
7143 -- Here if we either encountered the parent type's first rep
7144 -- item on the derived type's rep item list (in which case
7145 -- Found is True, and we have nothing else to do), or if we
7146 -- reached the last rep item of the derived type, which is
7147 -- Last_Rep, in which case we further chain the parent type's
7148 -- rep items to those of the derived type.
7151 Set_Next_Rep_Item (Last_Rep, First_Rep_Item (Parent_Type));
7156 Set_First_Rep_Item (Derived_Type, First_Rep_Item (Parent_Type));
7159 case Ekind (Parent_Type) is
7160 when Numeric_Kind =>
7161 Build_Derived_Numeric_Type (N, Parent_Type, Derived_Type);
7164 Build_Derived_Array_Type (N, Parent_Type, Derived_Type);
7168 | Class_Wide_Kind =>
7169 Build_Derived_Record_Type
7170 (N, Parent_Type, Derived_Type, Derive_Subps);
7173 when Enumeration_Kind =>
7174 Build_Derived_Enumeration_Type (N, Parent_Type, Derived_Type);
7177 Build_Derived_Access_Type (N, Parent_Type, Derived_Type);
7179 when Incomplete_Or_Private_Kind =>
7180 Build_Derived_Private_Type
7181 (N, Parent_Type, Derived_Type, Is_Completion, Derive_Subps);
7183 -- For discriminated types, the derivation includes deriving
7184 -- primitive operations. For others it is done below.
7186 if Is_Tagged_Type (Parent_Type)
7187 or else Has_Discriminants (Parent_Type)
7188 or else (Present (Full_View (Parent_Type))
7189 and then Has_Discriminants (Full_View (Parent_Type)))
7194 when Concurrent_Kind =>
7195 Build_Derived_Concurrent_Type (N, Parent_Type, Derived_Type);
7198 raise Program_Error;
7201 if Etype (Derived_Type) = Any_Type then
7205 -- Set delayed freeze and then derive subprograms, we need to do this
7206 -- in this order so that derived subprograms inherit the derived freeze
7209 Set_Has_Delayed_Freeze (Derived_Type);
7210 if Derive_Subps then
7211 Derive_Subprograms (Parent_Type, Derived_Type);
7214 Set_Has_Primitive_Operations
7215 (Base_Type (Derived_Type), Has_Primitive_Operations (Parent_Type));
7216 end Build_Derived_Type;
7218 -----------------------
7219 -- Build_Discriminal --
7220 -----------------------
7222 procedure Build_Discriminal (Discrim : Entity_Id) is
7223 D_Minal : Entity_Id;
7224 CR_Disc : Entity_Id;
7227 -- A discriminal has the same name as the discriminant
7230 Make_Defining_Identifier (Sloc (Discrim),
7231 Chars => Chars (Discrim));
7233 Set_Ekind (D_Minal, E_In_Parameter);
7234 Set_Mechanism (D_Minal, Default_Mechanism);
7235 Set_Etype (D_Minal, Etype (Discrim));
7237 Set_Discriminal (Discrim, D_Minal);
7238 Set_Discriminal_Link (D_Minal, Discrim);
7240 -- For task types, build at once the discriminants of the corresponding
7241 -- record, which are needed if discriminants are used in entry defaults
7242 -- and in family bounds.
7244 if Is_Concurrent_Type (Current_Scope)
7245 or else Is_Limited_Type (Current_Scope)
7247 CR_Disc := Make_Defining_Identifier (Sloc (Discrim), Chars (Discrim));
7249 Set_Ekind (CR_Disc, E_In_Parameter);
7250 Set_Mechanism (CR_Disc, Default_Mechanism);
7251 Set_Etype (CR_Disc, Etype (Discrim));
7252 Set_Discriminal_Link (CR_Disc, Discrim);
7253 Set_CR_Discriminant (Discrim, CR_Disc);
7255 end Build_Discriminal;
7257 ------------------------------------
7258 -- Build_Discriminant_Constraints --
7259 ------------------------------------
7261 function Build_Discriminant_Constraints
7264 Derived_Def : Boolean := False) return Elist_Id
7266 C : constant Node_Id := Constraint (Def);
7267 Nb_Discr : constant Nat := Number_Discriminants (T);
7269 Discr_Expr : array (1 .. Nb_Discr) of Node_Id := (others => Empty);
7270 -- Saves the expression corresponding to a given discriminant in T
7272 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat;
7273 -- Return the Position number within array Discr_Expr of a discriminant
7274 -- D within the discriminant list of the discriminated type T.
7280 function Pos_Of_Discr (T : Entity_Id; D : Entity_Id) return Nat is
7284 Disc := First_Discriminant (T);
7285 for J in Discr_Expr'Range loop
7290 Next_Discriminant (Disc);
7293 -- Note: Since this function is called on discriminants that are
7294 -- known to belong to the discriminated type, falling through the
7295 -- loop with no match signals an internal compiler error.
7297 raise Program_Error;
7300 -- Declarations local to Build_Discriminant_Constraints
7304 Elist : constant Elist_Id := New_Elmt_List;
7312 Discrim_Present : Boolean := False;
7314 -- Start of processing for Build_Discriminant_Constraints
7317 -- The following loop will process positional associations only.
7318 -- For a positional association, the (single) discriminant is
7319 -- implicitly specified by position, in textual order (RM 3.7.2).
7321 Discr := First_Discriminant (T);
7322 Constr := First (Constraints (C));
7323 for D in Discr_Expr'Range loop
7324 exit when Nkind (Constr) = N_Discriminant_Association;
7327 Error_Msg_N ("too few discriminants given in constraint", C);
7328 return New_Elmt_List;
7330 elsif Nkind (Constr) = N_Range
7331 or else (Nkind (Constr) = N_Attribute_Reference
7333 Attribute_Name (Constr) = Name_Range)
7336 ("a range is not a valid discriminant constraint", Constr);
7337 Discr_Expr (D) := Error;
7340 Analyze_And_Resolve (Constr, Base_Type (Etype (Discr)));
7341 Discr_Expr (D) := Constr;
7344 Next_Discriminant (Discr);
7348 if No (Discr) and then Present (Constr) then
7349 Error_Msg_N ("too many discriminants given in constraint", Constr);
7350 return New_Elmt_List;
7353 -- Named associations can be given in any order, but if both positional
7354 -- and named associations are used in the same discriminant constraint,
7355 -- then positional associations must occur first, at their normal
7356 -- position. Hence once a named association is used, the rest of the
7357 -- discriminant constraint must use only named associations.
7359 while Present (Constr) loop
7361 -- Positional association forbidden after a named association
7363 if Nkind (Constr) /= N_Discriminant_Association then
7364 Error_Msg_N ("positional association follows named one", Constr);
7365 return New_Elmt_List;
7367 -- Otherwise it is a named association
7370 -- E records the type of the discriminants in the named
7371 -- association. All the discriminants specified in the same name
7372 -- association must have the same type.
7376 -- Search the list of discriminants in T to see if the simple name
7377 -- given in the constraint matches any of them.
7379 Id := First (Selector_Names (Constr));
7380 while Present (Id) loop
7383 -- If Original_Discriminant is present, we are processing a
7384 -- generic instantiation and this is an instance node. We need
7385 -- to find the name of the corresponding discriminant in the
7386 -- actual record type T and not the name of the discriminant in
7387 -- the generic formal. Example:
7390 -- type G (D : int) is private;
7392 -- subtype W is G (D => 1);
7394 -- type Rec (X : int) is record ... end record;
7395 -- package Q is new P (G => Rec);
7397 -- At the point of the instantiation, formal type G is Rec
7398 -- and therefore when reanalyzing "subtype W is G (D => 1);"
7399 -- which really looks like "subtype W is Rec (D => 1);" at
7400 -- the point of instantiation, we want to find the discriminant
7401 -- that corresponds to D in Rec, i.e. X.
7403 if Present (Original_Discriminant (Id)) then
7404 Discr := Find_Corresponding_Discriminant (Id, T);
7408 Discr := First_Discriminant (T);
7409 while Present (Discr) loop
7410 if Chars (Discr) = Chars (Id) then
7415 Next_Discriminant (Discr);
7419 Error_Msg_N ("& does not match any discriminant", Id);
7420 return New_Elmt_List;
7422 -- The following is only useful for the benefit of generic
7423 -- instances but it does not interfere with other
7424 -- processing for the non-generic case so we do it in all
7425 -- cases (for generics this statement is executed when
7426 -- processing the generic definition, see comment at the
7427 -- beginning of this if statement).
7430 Set_Original_Discriminant (Id, Discr);
7434 Position := Pos_Of_Discr (T, Discr);
7436 if Present (Discr_Expr (Position)) then
7437 Error_Msg_N ("duplicate constraint for discriminant&", Id);
7440 -- Each discriminant specified in the same named association
7441 -- must be associated with a separate copy of the
7442 -- corresponding expression.
7444 if Present (Next (Id)) then
7445 Expr := New_Copy_Tree (Expression (Constr));
7446 Set_Parent (Expr, Parent (Expression (Constr)));
7448 Expr := Expression (Constr);
7451 Discr_Expr (Position) := Expr;
7452 Analyze_And_Resolve (Expr, Base_Type (Etype (Discr)));
7455 -- A discriminant association with more than one discriminant
7456 -- name is only allowed if the named discriminants are all of
7457 -- the same type (RM 3.7.1(8)).
7460 E := Base_Type (Etype (Discr));
7462 elsif Base_Type (Etype (Discr)) /= E then
7464 ("all discriminants in an association " &
7465 "must have the same type", Id);
7475 -- A discriminant constraint must provide exactly one value for each
7476 -- discriminant of the type (RM 3.7.1(8)).
7478 for J in Discr_Expr'Range loop
7479 if No (Discr_Expr (J)) then
7480 Error_Msg_N ("too few discriminants given in constraint", C);
7481 return New_Elmt_List;
7485 -- Determine if there are discriminant expressions in the constraint
7487 for J in Discr_Expr'Range loop
7488 if Denotes_Discriminant
7489 (Discr_Expr (J), Check_Concurrent => True)
7491 Discrim_Present := True;
7495 -- Build an element list consisting of the expressions given in the
7496 -- discriminant constraint and apply the appropriate checks. The list
7497 -- is constructed after resolving any named discriminant associations
7498 -- and therefore the expressions appear in the textual order of the
7501 Discr := First_Discriminant (T);
7502 for J in Discr_Expr'Range loop
7503 if Discr_Expr (J) /= Error then
7504 Append_Elmt (Discr_Expr (J), Elist);
7506 -- If any of the discriminant constraints is given by a
7507 -- discriminant and we are in a derived type declaration we
7508 -- have a discriminant renaming. Establish link between new
7509 -- and old discriminant.
7511 if Denotes_Discriminant (Discr_Expr (J)) then
7513 Set_Corresponding_Discriminant
7514 (Entity (Discr_Expr (J)), Discr);
7517 -- Force the evaluation of non-discriminant expressions.
7518 -- If we have found a discriminant in the constraint 3.4(26)
7519 -- and 3.8(18) demand that no range checks are performed are
7520 -- after evaluation. If the constraint is for a component
7521 -- definition that has a per-object constraint, expressions are
7522 -- evaluated but not checked either. In all other cases perform
7526 if Discrim_Present then
7529 elsif Nkind (Parent (Parent (Def))) = N_Component_Declaration
7531 Has_Per_Object_Constraint
7532 (Defining_Identifier (Parent (Parent (Def))))
7536 elsif Is_Access_Type (Etype (Discr)) then
7537 Apply_Constraint_Check (Discr_Expr (J), Etype (Discr));
7540 Apply_Range_Check (Discr_Expr (J), Etype (Discr));
7543 Force_Evaluation (Discr_Expr (J));
7546 -- Check that the designated type of an access discriminant's
7547 -- expression is not a class-wide type unless the discriminant's
7548 -- designated type is also class-wide.
7550 if Ekind (Etype (Discr)) = E_Anonymous_Access_Type
7551 and then not Is_Class_Wide_Type
7552 (Designated_Type (Etype (Discr)))
7553 and then Etype (Discr_Expr (J)) /= Any_Type
7554 and then Is_Class_Wide_Type
7555 (Designated_Type (Etype (Discr_Expr (J))))
7557 Wrong_Type (Discr_Expr (J), Etype (Discr));
7561 Next_Discriminant (Discr);
7565 end Build_Discriminant_Constraints;
7567 ---------------------------------
7568 -- Build_Discriminated_Subtype --
7569 ---------------------------------
7571 procedure Build_Discriminated_Subtype
7575 Related_Nod : Node_Id;
7576 For_Access : Boolean := False)
7578 Has_Discrs : constant Boolean := Has_Discriminants (T);
7579 Constrained : constant Boolean :=
7581 and then not Is_Empty_Elmt_List (Elist)
7582 and then not Is_Class_Wide_Type (T))
7583 or else Is_Constrained (T);
7586 if Ekind (T) = E_Record_Type then
7588 Set_Ekind (Def_Id, E_Private_Subtype);
7589 Set_Is_For_Access_Subtype (Def_Id, True);
7591 Set_Ekind (Def_Id, E_Record_Subtype);
7594 -- Inherit preelaboration flag from base, for types for which it
7595 -- may have been set: records, private types, protected types.
7597 Set_Known_To_Have_Preelab_Init
7598 (Def_Id, Known_To_Have_Preelab_Init (T));
7600 elsif Ekind (T) = E_Task_Type then
7601 Set_Ekind (Def_Id, E_Task_Subtype);
7603 elsif Ekind (T) = E_Protected_Type then
7604 Set_Ekind (Def_Id, E_Protected_Subtype);
7605 Set_Known_To_Have_Preelab_Init
7606 (Def_Id, Known_To_Have_Preelab_Init (T));
7608 elsif Is_Private_Type (T) then
7609 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
7610 Set_Known_To_Have_Preelab_Init
7611 (Def_Id, Known_To_Have_Preelab_Init (T));
7613 elsif Is_Class_Wide_Type (T) then
7614 Set_Ekind (Def_Id, E_Class_Wide_Subtype);
7617 -- Incomplete type. Attach subtype to list of dependents, to be
7618 -- completed with full view of parent type, unless is it the
7619 -- designated subtype of a record component within an init_proc.
7620 -- This last case arises for a component of an access type whose
7621 -- designated type is incomplete (e.g. a Taft Amendment type).
7622 -- The designated subtype is within an inner scope, and needs no
7623 -- elaboration, because only the access type is needed in the
7624 -- initialization procedure.
7626 Set_Ekind (Def_Id, Ekind (T));
7628 if For_Access and then Within_Init_Proc then
7631 Append_Elmt (Def_Id, Private_Dependents (T));
7635 Set_Etype (Def_Id, T);
7636 Init_Size_Align (Def_Id);
7637 Set_Has_Discriminants (Def_Id, Has_Discrs);
7638 Set_Is_Constrained (Def_Id, Constrained);
7640 Set_First_Entity (Def_Id, First_Entity (T));
7641 Set_Last_Entity (Def_Id, Last_Entity (T));
7643 -- If the subtype is the completion of a private declaration, there may
7644 -- have been representation clauses for the partial view, and they must
7645 -- be preserved. Build_Derived_Type chains the inherited clauses with
7646 -- the ones appearing on the extension. If this comes from a subtype
7647 -- declaration, all clauses are inherited.
7649 if No (First_Rep_Item (Def_Id)) then
7650 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
7653 if Is_Tagged_Type (T) then
7654 Set_Is_Tagged_Type (Def_Id);
7655 Make_Class_Wide_Type (Def_Id);
7658 Set_Stored_Constraint (Def_Id, No_Elist);
7661 Set_Discriminant_Constraint (Def_Id, Elist);
7662 Set_Stored_Constraint_From_Discriminant_Constraint (Def_Id);
7665 if Is_Tagged_Type (T) then
7667 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
7668 -- concurrent record type (which has the list of primitive
7671 if Ada_Version >= Ada_05
7672 and then Is_Concurrent_Type (T)
7674 Set_Corresponding_Record_Type (Def_Id,
7675 Corresponding_Record_Type (T));
7677 Set_Primitive_Operations (Def_Id, Primitive_Operations (T));
7680 Set_Is_Abstract_Type (Def_Id, Is_Abstract_Type (T));
7683 -- Subtypes introduced by component declarations do not need to be
7684 -- marked as delayed, and do not get freeze nodes, because the semantics
7685 -- verifies that the parents of the subtypes are frozen before the
7686 -- enclosing record is frozen.
7688 if not Is_Type (Scope (Def_Id)) then
7689 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
7691 if Is_Private_Type (T)
7692 and then Present (Full_View (T))
7694 Conditional_Delay (Def_Id, Full_View (T));
7696 Conditional_Delay (Def_Id, T);
7700 if Is_Record_Type (T) then
7701 Set_Is_Limited_Record (Def_Id, Is_Limited_Record (T));
7704 and then not Is_Empty_Elmt_List (Elist)
7705 and then not For_Access
7707 Create_Constrained_Components (Def_Id, Related_Nod, T, Elist);
7708 elsif not For_Access then
7709 Set_Cloned_Subtype (Def_Id, T);
7712 end Build_Discriminated_Subtype;
7714 ---------------------------
7715 -- Build_Itype_Reference --
7716 ---------------------------
7718 procedure Build_Itype_Reference
7722 IR : constant Node_Id := Make_Itype_Reference (Sloc (Nod));
7724 Set_Itype (IR, Ityp);
7725 Insert_After (Nod, IR);
7726 end Build_Itype_Reference;
7728 ------------------------
7729 -- Build_Scalar_Bound --
7730 ------------------------
7732 function Build_Scalar_Bound
7735 Der_T : Entity_Id) return Node_Id
7737 New_Bound : Entity_Id;
7740 -- Note: not clear why this is needed, how can the original bound
7741 -- be unanalyzed at this point? and if it is, what business do we
7742 -- have messing around with it? and why is the base type of the
7743 -- parent type the right type for the resolution. It probably is
7744 -- not! It is OK for the new bound we are creating, but not for
7745 -- the old one??? Still if it never happens, no problem!
7747 Analyze_And_Resolve (Bound, Base_Type (Par_T));
7749 if Nkind_In (Bound, N_Integer_Literal, N_Real_Literal) then
7750 New_Bound := New_Copy (Bound);
7751 Set_Etype (New_Bound, Der_T);
7752 Set_Analyzed (New_Bound);
7754 elsif Is_Entity_Name (Bound) then
7755 New_Bound := OK_Convert_To (Der_T, New_Copy (Bound));
7757 -- The following is almost certainly wrong. What business do we have
7758 -- relocating a node (Bound) that is presumably still attached to
7759 -- the tree elsewhere???
7762 New_Bound := OK_Convert_To (Der_T, Relocate_Node (Bound));
7765 Set_Etype (New_Bound, Der_T);
7767 end Build_Scalar_Bound;
7769 --------------------------------
7770 -- Build_Underlying_Full_View --
7771 --------------------------------
7773 procedure Build_Underlying_Full_View
7778 Loc : constant Source_Ptr := Sloc (N);
7779 Subt : constant Entity_Id :=
7780 Make_Defining_Identifier
7781 (Loc, New_External_Name (Chars (Typ), 'S'));
7788 procedure Set_Discriminant_Name (Id : Node_Id);
7789 -- If the derived type has discriminants, they may rename discriminants
7790 -- of the parent. When building the full view of the parent, we need to
7791 -- recover the names of the original discriminants if the constraint is
7792 -- given by named associations.
7794 ---------------------------
7795 -- Set_Discriminant_Name --
7796 ---------------------------
7798 procedure Set_Discriminant_Name (Id : Node_Id) is
7802 Set_Original_Discriminant (Id, Empty);
7804 if Has_Discriminants (Typ) then
7805 Disc := First_Discriminant (Typ);
7806 while Present (Disc) loop
7807 if Chars (Disc) = Chars (Id)
7808 and then Present (Corresponding_Discriminant (Disc))
7810 Set_Chars (Id, Chars (Corresponding_Discriminant (Disc)));
7812 Next_Discriminant (Disc);
7815 end Set_Discriminant_Name;
7817 -- Start of processing for Build_Underlying_Full_View
7820 if Nkind (N) = N_Full_Type_Declaration then
7821 Constr := Constraint (Subtype_Indication (Type_Definition (N)));
7823 elsif Nkind (N) = N_Subtype_Declaration then
7824 Constr := New_Copy_Tree (Constraint (Subtype_Indication (N)));
7826 elsif Nkind (N) = N_Component_Declaration then
7829 (Constraint (Subtype_Indication (Component_Definition (N))));
7832 raise Program_Error;
7835 C := First (Constraints (Constr));
7836 while Present (C) loop
7837 if Nkind (C) = N_Discriminant_Association then
7838 Id := First (Selector_Names (C));
7839 while Present (Id) loop
7840 Set_Discriminant_Name (Id);
7849 Make_Subtype_Declaration (Loc,
7850 Defining_Identifier => Subt,
7851 Subtype_Indication =>
7852 Make_Subtype_Indication (Loc,
7853 Subtype_Mark => New_Reference_To (Par, Loc),
7854 Constraint => New_Copy_Tree (Constr)));
7856 -- If this is a component subtype for an outer itype, it is not
7857 -- a list member, so simply set the parent link for analysis: if
7858 -- the enclosing type does not need to be in a declarative list,
7859 -- neither do the components.
7861 if Is_List_Member (N)
7862 and then Nkind (N) /= N_Component_Declaration
7864 Insert_Before (N, Indic);
7866 Set_Parent (Indic, Parent (N));
7870 Set_Underlying_Full_View (Typ, Full_View (Subt));
7871 end Build_Underlying_Full_View;
7873 -------------------------------
7874 -- Check_Abstract_Overriding --
7875 -------------------------------
7877 procedure Check_Abstract_Overriding (T : Entity_Id) is
7878 Alias_Subp : Entity_Id;
7885 Op_List := Primitive_Operations (T);
7887 -- Loop to check primitive operations
7889 Elmt := First_Elmt (Op_List);
7890 while Present (Elmt) loop
7891 Subp := Node (Elmt);
7892 Alias_Subp := Alias (Subp);
7894 -- Inherited subprograms are identified by the fact that they do not
7895 -- come from source, and the associated source location is the
7896 -- location of the first subtype of the derived type.
7898 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
7899 -- subprograms that "require overriding".
7901 -- Special exception, do not complain about failure to override the
7902 -- stream routines _Input and _Output, as well as the primitive
7903 -- operations used in dispatching selects since we always provide
7904 -- automatic overridings for these subprograms.
7906 -- Also ignore this rule for convention CIL since .NET libraries
7907 -- do bizarre things with interfaces???
7909 -- The partial view of T may have been a private extension, for
7910 -- which inherited functions dispatching on result are abstract.
7911 -- If the full view is a null extension, there is no need for
7912 -- overriding in Ada2005, but wrappers need to be built for them
7913 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
7915 if Is_Null_Extension (T)
7916 and then Has_Controlling_Result (Subp)
7917 and then Ada_Version >= Ada_05
7918 and then Present (Alias_Subp)
7919 and then not Comes_From_Source (Subp)
7920 and then not Is_Abstract_Subprogram (Alias_Subp)
7921 and then not Is_Access_Type (Etype (Subp))
7925 -- Ada 2005 (AI-251): Internal entities of interfaces need no
7926 -- processing because this check is done with the aliased
7929 elsif Present (Interface_Alias (Subp)) then
7932 elsif (Is_Abstract_Subprogram (Subp)
7933 or else Requires_Overriding (Subp)
7935 (Has_Controlling_Result (Subp)
7936 and then Present (Alias_Subp)
7937 and then not Comes_From_Source (Subp)
7938 and then Sloc (Subp) = Sloc (First_Subtype (T))))
7939 and then not Is_TSS (Subp, TSS_Stream_Input)
7940 and then not Is_TSS (Subp, TSS_Stream_Output)
7941 and then not Is_Abstract_Type (T)
7942 and then Convention (T) /= Convention_CIL
7943 and then not Is_Predefined_Interface_Primitive (Subp)
7945 -- Ada 2005 (AI-251): Do not consider hidden entities associated
7946 -- with abstract interface types because the check will be done
7947 -- with the aliased entity (otherwise we generate a duplicated
7950 and then not Present (Interface_Alias (Subp))
7952 if Present (Alias_Subp) then
7954 -- Only perform the check for a derived subprogram when the
7955 -- type has an explicit record extension. This avoids incorrect
7956 -- flagging of abstract subprograms for the case of a type
7957 -- without an extension that is derived from a formal type
7958 -- with a tagged actual (can occur within a private part).
7960 -- Ada 2005 (AI-391): In the case of an inherited function with
7961 -- a controlling result of the type, the rule does not apply if
7962 -- the type is a null extension (unless the parent function
7963 -- itself is abstract, in which case the function must still be
7964 -- be overridden). The expander will generate an overriding
7965 -- wrapper function calling the parent subprogram (see
7966 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
7968 Type_Def := Type_Definition (Parent (T));
7970 if Nkind (Type_Def) = N_Derived_Type_Definition
7971 and then Present (Record_Extension_Part (Type_Def))
7973 (Ada_Version < Ada_05
7974 or else not Is_Null_Extension (T)
7975 or else Ekind (Subp) = E_Procedure
7976 or else not Has_Controlling_Result (Subp)
7977 or else Is_Abstract_Subprogram (Alias_Subp)
7978 or else Requires_Overriding (Subp)
7979 or else Is_Access_Type (Etype (Subp)))
7981 -- Avoid reporting error in case of abstract predefined
7982 -- primitive inherited from interface type because the
7983 -- body of internally generated predefined primitives
7984 -- of tagged types are generated later by Freeze_Type
7986 if Is_Interface (Root_Type (T))
7987 and then Is_Abstract_Subprogram (Subp)
7988 and then Is_Predefined_Dispatching_Operation (Subp)
7989 and then not Comes_From_Source (Ultimate_Alias (Subp))
7995 ("type must be declared abstract or & overridden",
7998 -- Traverse the whole chain of aliased subprograms to
7999 -- complete the error notification. This is especially
8000 -- useful for traceability of the chain of entities when
8001 -- the subprogram corresponds with an interface
8002 -- subprogram (which may be defined in another package).
8004 if Present (Alias_Subp) then
8010 while Present (Alias (E)) loop
8011 Error_Msg_Sloc := Sloc (E);
8013 ("\& has been inherited #", T, Subp);
8017 Error_Msg_Sloc := Sloc (E);
8019 ("\& has been inherited from subprogram #",
8025 -- Ada 2005 (AI-345): Protected or task type implementing
8026 -- abstract interfaces.
8028 elsif Is_Concurrent_Record_Type (T)
8029 and then Present (Interfaces (T))
8031 -- The controlling formal of Subp must be of mode "out",
8032 -- "in out" or an access-to-variable to be overridden.
8034 -- Error message below needs rewording (remember comma
8035 -- in -gnatj mode) ???
8037 if Ekind (First_Formal (Subp)) = E_In_Parameter then
8038 if not Is_Predefined_Dispatching_Operation (Subp) then
8040 ("first formal of & must be of mode `OUT`, " &
8041 "`IN OUT` or access-to-variable", T, Subp);
8043 ("\to be overridden by protected procedure or " &
8044 "entry (RM 9.4(11.9/2))", T);
8047 -- Some other kind of overriding failure
8051 ("interface subprogram & must be overridden",
8057 Error_Msg_Node_2 := T;
8059 ("abstract subprogram& not allowed for type&", Subp);
8061 -- Also post unconditional warning on the type (unconditional
8062 -- so that if there are more than one of these cases, we get
8063 -- them all, and not just the first one).
8065 Error_Msg_Node_2 := Subp;
8067 ("nonabstract type& has abstract subprogram&!", T);
8071 -- Ada 2005 (AI05-0030): Inspect hidden subprograms which provide
8072 -- the mapping between interface and implementing type primitives.
8073 -- If the interface alias is marked as Implemented_By_Entry, the
8074 -- alias must be an entry wrapper.
8076 if Ada_Version >= Ada_05
8077 and then Is_Hidden (Subp)
8078 and then Present (Interface_Alias (Subp))
8079 and then Implemented_By_Entry (Interface_Alias (Subp))
8080 and then Present (Alias_Subp)
8082 (not Is_Primitive_Wrapper (Alias_Subp)
8083 or else Ekind (Wrapped_Entity (Alias_Subp)) /= E_Entry)
8086 Error_Ent : Entity_Id := T;
8089 if Is_Concurrent_Record_Type (Error_Ent) then
8090 Error_Ent := Corresponding_Concurrent_Type (Error_Ent);
8093 Error_Msg_Node_2 := Interface_Alias (Subp);
8095 ("type & must implement abstract subprogram & with an entry",
8096 Error_Ent, Error_Ent);
8102 end Check_Abstract_Overriding;
8104 ------------------------------------------------
8105 -- Check_Access_Discriminant_Requires_Limited --
8106 ------------------------------------------------
8108 procedure Check_Access_Discriminant_Requires_Limited
8113 -- A discriminant_specification for an access discriminant shall appear
8114 -- only in the declaration for a task or protected type, or for a type
8115 -- with the reserved word 'limited' in its definition or in one of its
8116 -- ancestors. (RM 3.7(10))
8118 if Nkind (Discriminant_Type (D)) = N_Access_Definition
8119 and then not Is_Concurrent_Type (Current_Scope)
8120 and then not Is_Concurrent_Record_Type (Current_Scope)
8121 and then not Is_Limited_Record (Current_Scope)
8122 and then Ekind (Current_Scope) /= E_Limited_Private_Type
8125 ("access discriminants allowed only for limited types", Loc);
8127 end Check_Access_Discriminant_Requires_Limited;
8129 -----------------------------------
8130 -- Check_Aliased_Component_Types --
8131 -----------------------------------
8133 procedure Check_Aliased_Component_Types (T : Entity_Id) is
8137 -- ??? Also need to check components of record extensions, but not
8138 -- components of protected types (which are always limited).
8140 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
8141 -- types to be unconstrained. This is safe because it is illegal to
8142 -- create access subtypes to such types with explicit discriminant
8145 if not Is_Limited_Type (T) then
8146 if Ekind (T) = E_Record_Type then
8147 C := First_Component (T);
8148 while Present (C) loop
8150 and then Has_Discriminants (Etype (C))
8151 and then not Is_Constrained (Etype (C))
8152 and then not In_Instance_Body
8153 and then Ada_Version < Ada_05
8156 ("aliased component must be constrained (RM 3.6(11))",
8163 elsif Ekind (T) = E_Array_Type then
8164 if Has_Aliased_Components (T)
8165 and then Has_Discriminants (Component_Type (T))
8166 and then not Is_Constrained (Component_Type (T))
8167 and then not In_Instance_Body
8168 and then Ada_Version < Ada_05
8171 ("aliased component type must be constrained (RM 3.6(11))",
8176 end Check_Aliased_Component_Types;
8178 ----------------------
8179 -- Check_Completion --
8180 ----------------------
8182 procedure Check_Completion (Body_Id : Node_Id := Empty) is
8185 procedure Post_Error;
8186 -- Post error message for lack of completion for entity E
8192 procedure Post_Error is
8194 if not Comes_From_Source (E) then
8196 if Ekind (E) = E_Task_Type
8197 or else Ekind (E) = E_Protected_Type
8199 -- It may be an anonymous protected type created for a
8200 -- single variable. Post error on variable, if present.
8206 Var := First_Entity (Current_Scope);
8207 while Present (Var) loop
8208 exit when Etype (Var) = E
8209 and then Comes_From_Source (Var);
8214 if Present (Var) then
8221 -- If a generated entity has no completion, then either previous
8222 -- semantic errors have disabled the expansion phase, or else we had
8223 -- missing subunits, or else we are compiling without expansion,
8224 -- or else something is very wrong.
8226 if not Comes_From_Source (E) then
8228 (Serious_Errors_Detected > 0
8229 or else Configurable_Run_Time_Violations > 0
8230 or else Subunits_Missing
8231 or else not Expander_Active);
8234 -- Here for source entity
8237 -- Here if no body to post the error message, so we post the error
8238 -- on the declaration that has no completion. This is not really
8239 -- the right place to post it, think about this later ???
8241 if No (Body_Id) then
8244 ("missing full declaration for }", Parent (E), E);
8247 ("missing body for &", Parent (E), E);
8250 -- Package body has no completion for a declaration that appears
8251 -- in the corresponding spec. Post error on the body, with a
8252 -- reference to the non-completed declaration.
8255 Error_Msg_Sloc := Sloc (E);
8259 ("missing full declaration for }!", Body_Id, E);
8261 elsif Is_Overloadable (E)
8262 and then Current_Entity_In_Scope (E) /= E
8264 -- It may be that the completion is mistyped and appears as
8265 -- a distinct overloading of the entity.
8268 Candidate : constant Entity_Id :=
8269 Current_Entity_In_Scope (E);
8270 Decl : constant Node_Id :=
8271 Unit_Declaration_Node (Candidate);
8274 if Is_Overloadable (Candidate)
8275 and then Ekind (Candidate) = Ekind (E)
8276 and then Nkind (Decl) = N_Subprogram_Body
8277 and then Acts_As_Spec (Decl)
8279 Check_Type_Conformant (Candidate, E);
8282 Error_Msg_NE ("missing body for & declared#!",
8287 Error_Msg_NE ("missing body for & declared#!",
8294 -- Start processing for Check_Completion
8297 E := First_Entity (Current_Scope);
8298 while Present (E) loop
8299 if Is_Intrinsic_Subprogram (E) then
8302 -- The following situation requires special handling: a child unit
8303 -- that appears in the context clause of the body of its parent:
8305 -- procedure Parent.Child (...);
8307 -- with Parent.Child;
8308 -- package body Parent is
8310 -- Here Parent.Child appears as a local entity, but should not be
8311 -- flagged as requiring completion, because it is a compilation
8314 -- Ignore missing completion for a subprogram that does not come from
8315 -- source (including the _Call primitive operation of RAS types,
8316 -- which has to have the flag Comes_From_Source for other purposes):
8317 -- we assume that the expander will provide the missing completion.
8319 elsif Ekind (E) = E_Function
8320 or else Ekind (E) = E_Procedure
8321 or else Ekind (E) = E_Generic_Function
8322 or else Ekind (E) = E_Generic_Procedure
8324 if not Has_Completion (E)
8325 and then not (Is_Subprogram (E)
8326 and then Is_Abstract_Subprogram (E))
8327 and then not (Is_Subprogram (E)
8329 (not Comes_From_Source (E)
8330 or else Chars (E) = Name_uCall))
8331 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8333 and then Chars (E) /= Name_uSize
8338 elsif Is_Entry (E) then
8339 if not Has_Completion (E) and then
8340 (Ekind (Scope (E)) = E_Protected_Object
8341 or else Ekind (Scope (E)) = E_Protected_Type)
8346 elsif Is_Package_Or_Generic_Package (E) then
8347 if Unit_Requires_Body (E) then
8348 if not Has_Completion (E)
8349 and then Nkind (Parent (Unit_Declaration_Node (E))) /=
8355 elsif not Is_Child_Unit (E) then
8356 May_Need_Implicit_Body (E);
8359 elsif Ekind (E) = E_Incomplete_Type
8360 and then No (Underlying_Type (E))
8364 elsif (Ekind (E) = E_Task_Type or else
8365 Ekind (E) = E_Protected_Type)
8366 and then not Has_Completion (E)
8370 -- A single task declared in the current scope is a constant, verify
8371 -- that the body of its anonymous type is in the same scope. If the
8372 -- task is defined elsewhere, this may be a renaming declaration for
8373 -- which no completion is needed.
8375 elsif Ekind (E) = E_Constant
8376 and then Ekind (Etype (E)) = E_Task_Type
8377 and then not Has_Completion (Etype (E))
8378 and then Scope (Etype (E)) = Current_Scope
8382 elsif Ekind (E) = E_Protected_Object
8383 and then not Has_Completion (Etype (E))
8387 elsif Ekind (E) = E_Record_Type then
8388 if Is_Tagged_Type (E) then
8389 Check_Abstract_Overriding (E);
8390 Check_Conventions (E);
8393 Check_Aliased_Component_Types (E);
8395 elsif Ekind (E) = E_Array_Type then
8396 Check_Aliased_Component_Types (E);
8402 end Check_Completion;
8404 ----------------------------
8405 -- Check_Delta_Expression --
8406 ----------------------------
8408 procedure Check_Delta_Expression (E : Node_Id) is
8410 if not (Is_Real_Type (Etype (E))) then
8411 Wrong_Type (E, Any_Real);
8413 elsif not Is_OK_Static_Expression (E) then
8414 Flag_Non_Static_Expr
8415 ("non-static expression used for delta value!", E);
8417 elsif not UR_Is_Positive (Expr_Value_R (E)) then
8418 Error_Msg_N ("delta expression must be positive", E);
8424 -- If any of above errors occurred, then replace the incorrect
8425 -- expression by the real 0.1, which should prevent further errors.
8428 Make_Real_Literal (Sloc (E), Ureal_Tenth));
8429 Analyze_And_Resolve (E, Standard_Float);
8430 end Check_Delta_Expression;
8432 -----------------------------
8433 -- Check_Digits_Expression --
8434 -----------------------------
8436 procedure Check_Digits_Expression (E : Node_Id) is
8438 if not (Is_Integer_Type (Etype (E))) then
8439 Wrong_Type (E, Any_Integer);
8441 elsif not Is_OK_Static_Expression (E) then
8442 Flag_Non_Static_Expr
8443 ("non-static expression used for digits value!", E);
8445 elsif Expr_Value (E) <= 0 then
8446 Error_Msg_N ("digits value must be greater than zero", E);
8452 -- If any of above errors occurred, then replace the incorrect
8453 -- expression by the integer 1, which should prevent further errors.
8455 Rewrite (E, Make_Integer_Literal (Sloc (E), 1));
8456 Analyze_And_Resolve (E, Standard_Integer);
8458 end Check_Digits_Expression;
8460 --------------------------
8461 -- Check_Initialization --
8462 --------------------------
8464 procedure Check_Initialization (T : Entity_Id; Exp : Node_Id) is
8466 if Is_Limited_Type (T)
8467 and then not In_Instance
8468 and then not In_Inlined_Body
8470 if not OK_For_Limited_Init (Exp) then
8472 -- In GNAT mode, this is just a warning, to allow it to be evilly
8473 -- turned off. Otherwise it is a real error.
8477 ("?cannot initialize entities of limited type!", Exp);
8479 elsif Ada_Version < Ada_05 then
8481 ("cannot initialize entities of limited type", Exp);
8482 Explain_Limited_Type (T, Exp);
8485 -- Specialize error message according to kind of illegal
8486 -- initial expression.
8488 if Nkind (Exp) = N_Type_Conversion
8489 and then Nkind (Expression (Exp)) = N_Function_Call
8492 ("illegal context for call"
8493 & " to function with limited result", Exp);
8497 ("initialization of limited object requires aggregate "
8498 & "or function call", Exp);
8503 end Check_Initialization;
8505 ----------------------
8506 -- Check_Interfaces --
8507 ----------------------
8509 procedure Check_Interfaces (N : Node_Id; Def : Node_Id) is
8510 Parent_Type : constant Entity_Id := Etype (Defining_Identifier (N));
8513 Iface_Def : Node_Id;
8514 Iface_Typ : Entity_Id;
8515 Parent_Node : Node_Id;
8517 Is_Task : Boolean := False;
8518 -- Set True if parent type or any progenitor is a task interface
8520 Is_Protected : Boolean := False;
8521 -- Set True if parent type or any progenitor is a protected interface
8523 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id);
8524 -- Check that a progenitor is compatible with declaration.
8525 -- Error is posted on Error_Node.
8531 procedure Check_Ifaces (Iface_Def : Node_Id; Error_Node : Node_Id) is
8532 Iface_Id : constant Entity_Id :=
8533 Defining_Identifier (Parent (Iface_Def));
8537 if Nkind (N) = N_Private_Extension_Declaration then
8540 Type_Def := Type_Definition (N);
8543 if Is_Task_Interface (Iface_Id) then
8546 elsif Is_Protected_Interface (Iface_Id) then
8547 Is_Protected := True;
8550 -- Check that the characteristics of the progenitor are compatible
8551 -- with the explicit qualifier in the declaration.
8552 -- The check only applies to qualifiers that come from source.
8553 -- Limited_Present also appears in the declaration of corresponding
8554 -- records, and the check does not apply to them.
8556 if Limited_Present (Type_Def)
8558 Is_Concurrent_Record_Type (Defining_Identifier (N))
8560 if Is_Limited_Interface (Parent_Type)
8561 and then not Is_Limited_Interface (Iface_Id)
8564 ("progenitor& must be limited interface",
8565 Error_Node, Iface_Id);
8568 (Task_Present (Iface_Def)
8569 or else Protected_Present (Iface_Def)
8570 or else Synchronized_Present (Iface_Def))
8571 and then Nkind (N) /= N_Private_Extension_Declaration
8574 ("progenitor& must be limited interface",
8575 Error_Node, Iface_Id);
8578 -- Protected interfaces can only inherit from limited, synchronized
8579 -- or protected interfaces.
8581 elsif Nkind (N) = N_Full_Type_Declaration
8582 and then Protected_Present (Type_Def)
8584 if Limited_Present (Iface_Def)
8585 or else Synchronized_Present (Iface_Def)
8586 or else Protected_Present (Iface_Def)
8590 elsif Task_Present (Iface_Def) then
8591 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
8592 & " from task interface", Error_Node);
8595 Error_Msg_N ("(Ada 2005) protected interface cannot inherit"
8596 & " from non-limited interface", Error_Node);
8599 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
8600 -- limited and synchronized.
8602 elsif Synchronized_Present (Type_Def) then
8603 if Limited_Present (Iface_Def)
8604 or else Synchronized_Present (Iface_Def)
8608 elsif Protected_Present (Iface_Def)
8609 and then Nkind (N) /= N_Private_Extension_Declaration
8611 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8612 & " from protected interface", Error_Node);
8614 elsif Task_Present (Iface_Def)
8615 and then Nkind (N) /= N_Private_Extension_Declaration
8617 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8618 & " from task interface", Error_Node);
8620 elsif not Is_Limited_Interface (Iface_Id) then
8621 Error_Msg_N ("(Ada 2005) synchronized interface cannot inherit"
8622 & " from non-limited interface", Error_Node);
8625 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
8626 -- synchronized or task interfaces.
8628 elsif Nkind (N) = N_Full_Type_Declaration
8629 and then Task_Present (Type_Def)
8631 if Limited_Present (Iface_Def)
8632 or else Synchronized_Present (Iface_Def)
8633 or else Task_Present (Iface_Def)
8637 elsif Protected_Present (Iface_Def) then
8638 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
8639 & " protected interface", Error_Node);
8642 Error_Msg_N ("(Ada 2005) task interface cannot inherit from"
8643 & " non-limited interface", Error_Node);
8648 -- Start of processing for Check_Interfaces
8651 if Is_Interface (Parent_Type) then
8652 if Is_Task_Interface (Parent_Type) then
8655 elsif Is_Protected_Interface (Parent_Type) then
8656 Is_Protected := True;
8660 if Nkind (N) = N_Private_Extension_Declaration then
8662 -- Check that progenitors are compatible with declaration
8664 Iface := First (Interface_List (Def));
8665 while Present (Iface) loop
8666 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8668 Parent_Node := Parent (Base_Type (Iface_Typ));
8669 Iface_Def := Type_Definition (Parent_Node);
8671 if not Is_Interface (Iface_Typ) then
8672 Diagnose_Interface (Iface, Iface_Typ);
8675 Check_Ifaces (Iface_Def, Iface);
8681 if Is_Task and Is_Protected then
8683 ("type cannot derive from task and protected interface", N);
8689 -- Full type declaration of derived type.
8690 -- Check compatibility with parent if it is interface type
8692 if Nkind (Type_Definition (N)) = N_Derived_Type_Definition
8693 and then Is_Interface (Parent_Type)
8695 Parent_Node := Parent (Parent_Type);
8697 -- More detailed checks for interface varieties
8700 (Iface_Def => Type_Definition (Parent_Node),
8701 Error_Node => Subtype_Indication (Type_Definition (N)));
8704 Iface := First (Interface_List (Def));
8705 while Present (Iface) loop
8706 Iface_Typ := Find_Type_Of_Subtype_Indic (Iface);
8708 Parent_Node := Parent (Base_Type (Iface_Typ));
8709 Iface_Def := Type_Definition (Parent_Node);
8711 if not Is_Interface (Iface_Typ) then
8712 Diagnose_Interface (Iface, Iface_Typ);
8715 -- "The declaration of a specific descendant of an interface
8716 -- type freezes the interface type" RM 13.14
8718 Freeze_Before (N, Iface_Typ);
8719 Check_Ifaces (Iface_Def, Error_Node => Iface);
8725 if Is_Task and Is_Protected then
8727 ("type cannot derive from task and protected interface", N);
8729 end Check_Interfaces;
8731 ------------------------------------
8732 -- Check_Or_Process_Discriminants --
8733 ------------------------------------
8735 -- If an incomplete or private type declaration was already given for the
8736 -- type, the discriminants may have already been processed if they were
8737 -- present on the incomplete declaration. In this case a full conformance
8738 -- check is performed otherwise just process them.
8740 procedure Check_Or_Process_Discriminants
8743 Prev : Entity_Id := Empty)
8746 if Has_Discriminants (T) then
8748 -- Make the discriminants visible to component declarations
8755 D := First_Discriminant (T);
8756 while Present (D) loop
8757 Prev := Current_Entity (D);
8758 Set_Current_Entity (D);
8759 Set_Is_Immediately_Visible (D);
8760 Set_Homonym (D, Prev);
8762 -- Ada 2005 (AI-230): Access discriminant allowed in
8763 -- non-limited record types.
8765 if Ada_Version < Ada_05 then
8767 -- This restriction gets applied to the full type here. It
8768 -- has already been applied earlier to the partial view.
8770 Check_Access_Discriminant_Requires_Limited (Parent (D), N);
8773 Next_Discriminant (D);
8777 elsif Present (Discriminant_Specifications (N)) then
8778 Process_Discriminants (N, Prev);
8780 end Check_Or_Process_Discriminants;
8782 ----------------------
8783 -- Check_Real_Bound --
8784 ----------------------
8786 procedure Check_Real_Bound (Bound : Node_Id) is
8788 if not Is_Real_Type (Etype (Bound)) then
8790 ("bound in real type definition must be of real type", Bound);
8792 elsif not Is_OK_Static_Expression (Bound) then
8793 Flag_Non_Static_Expr
8794 ("non-static expression used for real type bound!", Bound);
8801 (Bound, Make_Real_Literal (Sloc (Bound), Ureal_0));
8803 Resolve (Bound, Standard_Float);
8804 end Check_Real_Bound;
8806 ------------------------------
8807 -- Complete_Private_Subtype --
8808 ------------------------------
8810 procedure Complete_Private_Subtype
8813 Full_Base : Entity_Id;
8814 Related_Nod : Node_Id)
8816 Save_Next_Entity : Entity_Id;
8817 Save_Homonym : Entity_Id;
8820 -- Set semantic attributes for (implicit) private subtype completion.
8821 -- If the full type has no discriminants, then it is a copy of the full
8822 -- view of the base. Otherwise, it is a subtype of the base with a
8823 -- possible discriminant constraint. Save and restore the original
8824 -- Next_Entity field of full to ensure that the calls to Copy_Node
8825 -- do not corrupt the entity chain.
8827 -- Note that the type of the full view is the same entity as the type of
8828 -- the partial view. In this fashion, the subtype has access to the
8829 -- correct view of the parent.
8831 Save_Next_Entity := Next_Entity (Full);
8832 Save_Homonym := Homonym (Priv);
8834 case Ekind (Full_Base) is
8835 when E_Record_Type |
8841 Copy_Node (Priv, Full);
8843 Set_Has_Discriminants (Full, Has_Discriminants (Full_Base));
8844 Set_First_Entity (Full, First_Entity (Full_Base));
8845 Set_Last_Entity (Full, Last_Entity (Full_Base));
8848 Copy_Node (Full_Base, Full);
8849 Set_Chars (Full, Chars (Priv));
8850 Conditional_Delay (Full, Priv);
8851 Set_Sloc (Full, Sloc (Priv));
8854 Set_Next_Entity (Full, Save_Next_Entity);
8855 Set_Homonym (Full, Save_Homonym);
8856 Set_Associated_Node_For_Itype (Full, Related_Nod);
8858 -- Set common attributes for all subtypes
8860 Set_Ekind (Full, Subtype_Kind (Ekind (Full_Base)));
8862 -- The Etype of the full view is inconsistent. Gigi needs to see the
8863 -- structural full view, which is what the current scheme gives:
8864 -- the Etype of the full view is the etype of the full base. However,
8865 -- if the full base is a derived type, the full view then looks like
8866 -- a subtype of the parent, not a subtype of the full base. If instead
8869 -- Set_Etype (Full, Full_Base);
8871 -- then we get inconsistencies in the front-end (confusion between
8872 -- views). Several outstanding bugs are related to this ???
8874 Set_Is_First_Subtype (Full, False);
8875 Set_Scope (Full, Scope (Priv));
8876 Set_Size_Info (Full, Full_Base);
8877 Set_RM_Size (Full, RM_Size (Full_Base));
8878 Set_Is_Itype (Full);
8880 -- A subtype of a private-type-without-discriminants, whose full-view
8881 -- has discriminants with default expressions, is not constrained!
8883 if not Has_Discriminants (Priv) then
8884 Set_Is_Constrained (Full, Is_Constrained (Full_Base));
8886 if Has_Discriminants (Full_Base) then
8887 Set_Discriminant_Constraint
8888 (Full, Discriminant_Constraint (Full_Base));
8890 -- The partial view may have been indefinite, the full view
8893 Set_Has_Unknown_Discriminants
8894 (Full, Has_Unknown_Discriminants (Full_Base));
8898 Set_First_Rep_Item (Full, First_Rep_Item (Full_Base));
8899 Set_Depends_On_Private (Full, Has_Private_Component (Full));
8901 -- Freeze the private subtype entity if its parent is delayed, and not
8902 -- already frozen. We skip this processing if the type is an anonymous
8903 -- subtype of a record component, or is the corresponding record of a
8904 -- protected type, since ???
8906 if not Is_Type (Scope (Full)) then
8907 Set_Has_Delayed_Freeze (Full,
8908 Has_Delayed_Freeze (Full_Base)
8909 and then (not Is_Frozen (Full_Base)));
8912 Set_Freeze_Node (Full, Empty);
8913 Set_Is_Frozen (Full, False);
8914 Set_Full_View (Priv, Full);
8916 if Has_Discriminants (Full) then
8917 Set_Stored_Constraint_From_Discriminant_Constraint (Full);
8918 Set_Stored_Constraint (Priv, Stored_Constraint (Full));
8920 if Has_Unknown_Discriminants (Full) then
8921 Set_Discriminant_Constraint (Full, No_Elist);
8925 if Ekind (Full_Base) = E_Record_Type
8926 and then Has_Discriminants (Full_Base)
8927 and then Has_Discriminants (Priv) -- might not, if errors
8928 and then not Has_Unknown_Discriminants (Priv)
8929 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Priv))
8931 Create_Constrained_Components
8932 (Full, Related_Nod, Full_Base, Discriminant_Constraint (Priv));
8934 -- If the full base is itself derived from private, build a congruent
8935 -- subtype of its underlying type, for use by the back end. For a
8936 -- constrained record component, the declaration cannot be placed on
8937 -- the component list, but it must nevertheless be built an analyzed, to
8938 -- supply enough information for Gigi to compute the size of component.
8940 elsif Ekind (Full_Base) in Private_Kind
8941 and then Is_Derived_Type (Full_Base)
8942 and then Has_Discriminants (Full_Base)
8943 and then (Ekind (Current_Scope) /= E_Record_Subtype)
8945 if not Is_Itype (Priv)
8947 Nkind (Subtype_Indication (Parent (Priv))) = N_Subtype_Indication
8949 Build_Underlying_Full_View
8950 (Parent (Priv), Full, Etype (Full_Base));
8952 elsif Nkind (Related_Nod) = N_Component_Declaration then
8953 Build_Underlying_Full_View (Related_Nod, Full, Etype (Full_Base));
8956 elsif Is_Record_Type (Full_Base) then
8958 -- Show Full is simply a renaming of Full_Base
8960 Set_Cloned_Subtype (Full, Full_Base);
8963 -- It is unsafe to share to bounds of a scalar type, because the Itype
8964 -- is elaborated on demand, and if a bound is non-static then different
8965 -- orders of elaboration in different units will lead to different
8966 -- external symbols.
8968 if Is_Scalar_Type (Full_Base) then
8969 Set_Scalar_Range (Full,
8970 Make_Range (Sloc (Related_Nod),
8972 Duplicate_Subexpr_No_Checks (Type_Low_Bound (Full_Base)),
8974 Duplicate_Subexpr_No_Checks (Type_High_Bound (Full_Base))));
8976 -- This completion inherits the bounds of the full parent, but if
8977 -- the parent is an unconstrained floating point type, so is the
8980 if Is_Floating_Point_Type (Full_Base) then
8981 Set_Includes_Infinities
8982 (Scalar_Range (Full), Has_Infinities (Full_Base));
8986 -- ??? It seems that a lot of fields are missing that should be copied
8987 -- from Full_Base to Full. Here are some that are introduced in a
8988 -- non-disruptive way but a cleanup is necessary.
8990 if Is_Tagged_Type (Full_Base) then
8991 Set_Is_Tagged_Type (Full);
8992 Set_Primitive_Operations (Full, Primitive_Operations (Full_Base));
8993 Set_Class_Wide_Type (Full, Class_Wide_Type (Full_Base));
8995 -- If this is a subtype of a protected or task type, constrain its
8996 -- corresponding record, unless this is a subtype without constraints,
8997 -- i.e. a simple renaming as with an actual subtype in an instance.
8999 elsif Is_Concurrent_Type (Full_Base) then
9000 if Has_Discriminants (Full)
9001 and then Present (Corresponding_Record_Type (Full_Base))
9003 not Is_Empty_Elmt_List (Discriminant_Constraint (Full))
9005 Set_Corresponding_Record_Type (Full,
9006 Constrain_Corresponding_Record
9007 (Full, Corresponding_Record_Type (Full_Base),
9008 Related_Nod, Full_Base));
9011 Set_Corresponding_Record_Type (Full,
9012 Corresponding_Record_Type (Full_Base));
9015 end Complete_Private_Subtype;
9017 ----------------------------
9018 -- Constant_Redeclaration --
9019 ----------------------------
9021 procedure Constant_Redeclaration
9026 Prev : constant Entity_Id := Current_Entity_In_Scope (Id);
9027 Obj_Def : constant Node_Id := Object_Definition (N);
9030 procedure Check_Possible_Deferred_Completion
9031 (Prev_Id : Entity_Id;
9032 Prev_Obj_Def : Node_Id;
9033 Curr_Obj_Def : Node_Id);
9034 -- Determine whether the two object definitions describe the partial
9035 -- and the full view of a constrained deferred constant. Generate
9036 -- a subtype for the full view and verify that it statically matches
9037 -- the subtype of the partial view.
9039 procedure Check_Recursive_Declaration (Typ : Entity_Id);
9040 -- If deferred constant is an access type initialized with an allocator,
9041 -- check whether there is an illegal recursion in the definition,
9042 -- through a default value of some record subcomponent. This is normally
9043 -- detected when generating init procs, but requires this additional
9044 -- mechanism when expansion is disabled.
9046 ----------------------------------------
9047 -- Check_Possible_Deferred_Completion --
9048 ----------------------------------------
9050 procedure Check_Possible_Deferred_Completion
9051 (Prev_Id : Entity_Id;
9052 Prev_Obj_Def : Node_Id;
9053 Curr_Obj_Def : Node_Id)
9056 if Nkind (Prev_Obj_Def) = N_Subtype_Indication
9057 and then Present (Constraint (Prev_Obj_Def))
9058 and then Nkind (Curr_Obj_Def) = N_Subtype_Indication
9059 and then Present (Constraint (Curr_Obj_Def))
9062 Loc : constant Source_Ptr := Sloc (N);
9063 Def_Id : constant Entity_Id :=
9064 Make_Defining_Identifier (Loc,
9065 New_Internal_Name ('S'));
9066 Decl : constant Node_Id :=
9067 Make_Subtype_Declaration (Loc,
9068 Defining_Identifier =>
9070 Subtype_Indication =>
9071 Relocate_Node (Curr_Obj_Def));
9074 Insert_Before_And_Analyze (N, Decl);
9075 Set_Etype (Id, Def_Id);
9077 if not Subtypes_Statically_Match (Etype (Prev_Id), Def_Id) then
9078 Error_Msg_Sloc := Sloc (Prev_Id);
9079 Error_Msg_N ("subtype does not statically match deferred " &
9084 end Check_Possible_Deferred_Completion;
9086 ---------------------------------
9087 -- Check_Recursive_Declaration --
9088 ---------------------------------
9090 procedure Check_Recursive_Declaration (Typ : Entity_Id) is
9094 if Is_Record_Type (Typ) then
9095 Comp := First_Component (Typ);
9096 while Present (Comp) loop
9097 if Comes_From_Source (Comp) then
9098 if Present (Expression (Parent (Comp)))
9099 and then Is_Entity_Name (Expression (Parent (Comp)))
9100 and then Entity (Expression (Parent (Comp))) = Prev
9102 Error_Msg_Sloc := Sloc (Parent (Comp));
9104 ("illegal circularity with declaration for&#",
9108 elsif Is_Record_Type (Etype (Comp)) then
9109 Check_Recursive_Declaration (Etype (Comp));
9113 Next_Component (Comp);
9116 end Check_Recursive_Declaration;
9118 -- Start of processing for Constant_Redeclaration
9121 if Nkind (Parent (Prev)) = N_Object_Declaration then
9122 if Nkind (Object_Definition
9123 (Parent (Prev))) = N_Subtype_Indication
9125 -- Find type of new declaration. The constraints of the two
9126 -- views must match statically, but there is no point in
9127 -- creating an itype for the full view.
9129 if Nkind (Obj_Def) = N_Subtype_Indication then
9130 Find_Type (Subtype_Mark (Obj_Def));
9131 New_T := Entity (Subtype_Mark (Obj_Def));
9134 Find_Type (Obj_Def);
9135 New_T := Entity (Obj_Def);
9141 -- The full view may impose a constraint, even if the partial
9142 -- view does not, so construct the subtype.
9144 New_T := Find_Type_Of_Object (Obj_Def, N);
9149 -- Current declaration is illegal, diagnosed below in Enter_Name
9155 -- If previous full declaration exists, or if a homograph is present,
9156 -- let Enter_Name handle it, either with an error, or with the removal
9157 -- of an overridden implicit subprogram.
9159 if Ekind (Prev) /= E_Constant
9160 or else Present (Expression (Parent (Prev)))
9161 or else Present (Full_View (Prev))
9165 -- Verify that types of both declarations match, or else that both types
9166 -- are anonymous access types whose designated subtypes statically match
9167 -- (as allowed in Ada 2005 by AI-385).
9169 elsif Base_Type (Etype (Prev)) /= Base_Type (New_T)
9171 (Ekind (Etype (Prev)) /= E_Anonymous_Access_Type
9172 or else Ekind (Etype (New_T)) /= E_Anonymous_Access_Type
9173 or else Is_Access_Constant (Etype (New_T)) /=
9174 Is_Access_Constant (Etype (Prev))
9175 or else Can_Never_Be_Null (Etype (New_T)) /=
9176 Can_Never_Be_Null (Etype (Prev))
9177 or else Null_Exclusion_Present (Parent (Prev)) /=
9178 Null_Exclusion_Present (Parent (Id))
9179 or else not Subtypes_Statically_Match
9180 (Designated_Type (Etype (Prev)),
9181 Designated_Type (Etype (New_T))))
9183 Error_Msg_Sloc := Sloc (Prev);
9184 Error_Msg_N ("type does not match declaration#", N);
9185 Set_Full_View (Prev, Id);
9186 Set_Etype (Id, Any_Type);
9189 Null_Exclusion_Present (Parent (Prev))
9190 and then not Null_Exclusion_Present (N)
9192 Error_Msg_Sloc := Sloc (Prev);
9193 Error_Msg_N ("null-exclusion does not match declaration#", N);
9194 Set_Full_View (Prev, Id);
9195 Set_Etype (Id, Any_Type);
9197 -- If so, process the full constant declaration
9200 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
9201 -- the deferred declaration is constrained, then the subtype defined
9202 -- by the subtype_indication in the full declaration shall match it
9205 Check_Possible_Deferred_Completion
9207 Prev_Obj_Def => Object_Definition (Parent (Prev)),
9208 Curr_Obj_Def => Obj_Def);
9210 Set_Full_View (Prev, Id);
9211 Set_Is_Public (Id, Is_Public (Prev));
9212 Set_Is_Internal (Id);
9213 Append_Entity (Id, Current_Scope);
9215 -- Check ALIASED present if present before (RM 7.4(7))
9217 if Is_Aliased (Prev)
9218 and then not Aliased_Present (N)
9220 Error_Msg_Sloc := Sloc (Prev);
9221 Error_Msg_N ("ALIASED required (see declaration#)", N);
9224 -- Allow incomplete declaration of tags (used to handle forward
9225 -- references to tags). The check on Ada_Tags avoids circularities
9226 -- when rebuilding the compiler.
9228 if RTU_Loaded (Ada_Tags)
9229 and then T = RTE (RE_Tag)
9233 -- Check that placement is in private part and that the incomplete
9234 -- declaration appeared in the visible part.
9236 elsif Ekind (Current_Scope) = E_Package
9237 and then not In_Private_Part (Current_Scope)
9239 Error_Msg_Sloc := Sloc (Prev);
9240 Error_Msg_N ("full constant for declaration#"
9241 & " must be in private part", N);
9243 elsif Ekind (Current_Scope) = E_Package
9244 and then List_Containing (Parent (Prev))
9245 /= Visible_Declarations
9246 (Specification (Unit_Declaration_Node (Current_Scope)))
9249 ("deferred constant must be declared in visible part",
9253 if Is_Access_Type (T)
9254 and then Nkind (Expression (N)) = N_Allocator
9256 Check_Recursive_Declaration (Designated_Type (T));
9259 end Constant_Redeclaration;
9261 ----------------------
9262 -- Constrain_Access --
9263 ----------------------
9265 procedure Constrain_Access
9266 (Def_Id : in out Entity_Id;
9268 Related_Nod : Node_Id)
9270 T : constant Entity_Id := Entity (Subtype_Mark (S));
9271 Desig_Type : constant Entity_Id := Designated_Type (T);
9272 Desig_Subtype : Entity_Id := Create_Itype (E_Void, Related_Nod);
9273 Constraint_OK : Boolean := True;
9275 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean;
9276 -- Simple predicate to test for defaulted discriminants
9277 -- Shouldn't this be in sem_util???
9279 ---------------------------------
9280 -- Has_Defaulted_Discriminants --
9281 ---------------------------------
9283 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
9285 return Has_Discriminants (Typ)
9286 and then Present (First_Discriminant (Typ))
9288 (Discriminant_Default_Value (First_Discriminant (Typ)));
9289 end Has_Defaulted_Discriminants;
9291 -- Start of processing for Constrain_Access
9294 if Is_Array_Type (Desig_Type) then
9295 Constrain_Array (Desig_Subtype, S, Related_Nod, Def_Id, 'P');
9297 elsif (Is_Record_Type (Desig_Type)
9298 or else Is_Incomplete_Or_Private_Type (Desig_Type))
9299 and then not Is_Constrained (Desig_Type)
9301 -- ??? The following code is a temporary kludge to ignore a
9302 -- discriminant constraint on access type if it is constraining
9303 -- the current record. Avoid creating the implicit subtype of the
9304 -- record we are currently compiling since right now, we cannot
9305 -- handle these. For now, just return the access type itself.
9307 if Desig_Type = Current_Scope
9308 and then No (Def_Id)
9310 Set_Ekind (Desig_Subtype, E_Record_Subtype);
9311 Def_Id := Entity (Subtype_Mark (S));
9313 -- This call added to ensure that the constraint is analyzed
9314 -- (needed for a B test). Note that we still return early from
9315 -- this procedure to avoid recursive processing. ???
9317 Constrain_Discriminated_Type
9318 (Desig_Subtype, S, Related_Nod, For_Access => True);
9322 if (Ekind (T) = E_General_Access_Type
9323 or else Ada_Version >= Ada_05)
9324 and then Has_Private_Declaration (Desig_Type)
9325 and then In_Open_Scopes (Scope (Desig_Type))
9326 and then Has_Discriminants (Desig_Type)
9328 -- Enforce rule that the constraint is illegal if there is
9329 -- an unconstrained view of the designated type. This means
9330 -- that the partial view (either a private type declaration or
9331 -- a derivation from a private type) has no discriminants.
9332 -- (Defect Report 8652/0008, Technical Corrigendum 1, checked
9333 -- by ACATS B371001).
9335 -- Rule updated for Ada 2005: the private type is said to have
9336 -- a constrained partial view, given that objects of the type
9337 -- can be declared. Furthermore, the rule applies to all access
9338 -- types, unlike the rule concerning default discriminants.
9341 Pack : constant Node_Id :=
9342 Unit_Declaration_Node (Scope (Desig_Type));
9347 if Nkind (Pack) = N_Package_Declaration then
9348 Decls := Visible_Declarations (Specification (Pack));
9349 Decl := First (Decls);
9350 while Present (Decl) loop
9351 if (Nkind (Decl) = N_Private_Type_Declaration
9353 Chars (Defining_Identifier (Decl)) =
9357 (Nkind (Decl) = N_Full_Type_Declaration
9359 Chars (Defining_Identifier (Decl)) =
9361 and then Is_Derived_Type (Desig_Type)
9363 Has_Private_Declaration (Etype (Desig_Type)))
9365 if No (Discriminant_Specifications (Decl)) then
9367 ("cannot constrain general access type if " &
9368 "designated type has constrained partial view",
9381 Constrain_Discriminated_Type (Desig_Subtype, S, Related_Nod,
9382 For_Access => True);
9384 elsif (Is_Task_Type (Desig_Type)
9385 or else Is_Protected_Type (Desig_Type))
9386 and then not Is_Constrained (Desig_Type)
9388 Constrain_Concurrent
9389 (Desig_Subtype, S, Related_Nod, Desig_Type, ' ');
9392 Error_Msg_N ("invalid constraint on access type", S);
9393 Desig_Subtype := Desig_Type; -- Ignore invalid constraint.
9394 Constraint_OK := False;
9398 Def_Id := Create_Itype (E_Access_Subtype, Related_Nod);
9400 Set_Ekind (Def_Id, E_Access_Subtype);
9403 if Constraint_OK then
9404 Set_Etype (Def_Id, Base_Type (T));
9406 if Is_Private_Type (Desig_Type) then
9407 Prepare_Private_Subtype_Completion (Desig_Subtype, Related_Nod);
9410 Set_Etype (Def_Id, Any_Type);
9413 Set_Size_Info (Def_Id, T);
9414 Set_Is_Constrained (Def_Id, Constraint_OK);
9415 Set_Directly_Designated_Type (Def_Id, Desig_Subtype);
9416 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9417 Set_Is_Access_Constant (Def_Id, Is_Access_Constant (T));
9419 Conditional_Delay (Def_Id, T);
9421 -- AI-363 : Subtypes of general access types whose designated types have
9422 -- default discriminants are disallowed. In instances, the rule has to
9423 -- be checked against the actual, of which T is the subtype. In a
9424 -- generic body, the rule is checked assuming that the actual type has
9425 -- defaulted discriminants.
9427 if Ada_Version >= Ada_05 or else Warn_On_Ada_2005_Compatibility then
9428 if Ekind (Base_Type (T)) = E_General_Access_Type
9429 and then Has_Defaulted_Discriminants (Desig_Type)
9431 if Ada_Version < Ada_05 then
9433 ("access subtype of general access type would not " &
9434 "be allowed in Ada 2005?", S);
9437 ("access subype of general access type not allowed", S);
9440 Error_Msg_N ("\discriminants have defaults", S);
9442 elsif Is_Access_Type (T)
9443 and then Is_Generic_Type (Desig_Type)
9444 and then Has_Discriminants (Desig_Type)
9445 and then In_Package_Body (Current_Scope)
9447 if Ada_Version < Ada_05 then
9449 ("access subtype would not be allowed in generic body " &
9453 ("access subtype not allowed in generic body", S);
9457 ("\designated type is a discriminated formal", S);
9460 end Constrain_Access;
9462 ---------------------
9463 -- Constrain_Array --
9464 ---------------------
9466 procedure Constrain_Array
9467 (Def_Id : in out Entity_Id;
9469 Related_Nod : Node_Id;
9470 Related_Id : Entity_Id;
9473 C : constant Node_Id := Constraint (SI);
9474 Number_Of_Constraints : Nat := 0;
9477 Constraint_OK : Boolean := True;
9480 T := Entity (Subtype_Mark (SI));
9482 if Ekind (T) in Access_Kind then
9483 T := Designated_Type (T);
9486 -- If an index constraint follows a subtype mark in a subtype indication
9487 -- then the type or subtype denoted by the subtype mark must not already
9488 -- impose an index constraint. The subtype mark must denote either an
9489 -- unconstrained array type or an access type whose designated type
9490 -- is such an array type... (RM 3.6.1)
9492 if Is_Constrained (T) then
9494 ("array type is already constrained", Subtype_Mark (SI));
9495 Constraint_OK := False;
9498 S := First (Constraints (C));
9499 while Present (S) loop
9500 Number_Of_Constraints := Number_Of_Constraints + 1;
9504 -- In either case, the index constraint must provide a discrete
9505 -- range for each index of the array type and the type of each
9506 -- discrete range must be the same as that of the corresponding
9507 -- index. (RM 3.6.1)
9509 if Number_Of_Constraints /= Number_Dimensions (T) then
9510 Error_Msg_NE ("incorrect number of index constraints for }", C, T);
9511 Constraint_OK := False;
9514 S := First (Constraints (C));
9515 Index := First_Index (T);
9518 -- Apply constraints to each index type
9520 for J in 1 .. Number_Of_Constraints loop
9521 Constrain_Index (Index, S, Related_Nod, Related_Id, Suffix, J);
9531 Create_Itype (E_Array_Subtype, Related_Nod, Related_Id, Suffix);
9532 Set_Parent (Def_Id, Related_Nod);
9535 Set_Ekind (Def_Id, E_Array_Subtype);
9538 Set_Size_Info (Def_Id, (T));
9539 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
9540 Set_Etype (Def_Id, Base_Type (T));
9542 if Constraint_OK then
9543 Set_First_Index (Def_Id, First (Constraints (C)));
9545 Set_First_Index (Def_Id, First_Index (T));
9548 Set_Is_Constrained (Def_Id, True);
9549 Set_Is_Aliased (Def_Id, Is_Aliased (T));
9550 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
9552 Set_Is_Private_Composite (Def_Id, Is_Private_Composite (T));
9553 Set_Is_Limited_Composite (Def_Id, Is_Limited_Composite (T));
9555 -- A subtype does not inherit the packed_array_type of is parent. We
9556 -- need to initialize the attribute because if Def_Id is previously
9557 -- analyzed through a limited_with clause, it will have the attributes
9558 -- of an incomplete type, one of which is an Elist that overlaps the
9559 -- Packed_Array_Type field.
9561 Set_Packed_Array_Type (Def_Id, Empty);
9563 -- Build a freeze node if parent still needs one. Also make sure that
9564 -- the Depends_On_Private status is set because the subtype will need
9565 -- reprocessing at the time the base type does, and also we must set a
9566 -- conditional delay.
9568 Set_Depends_On_Private (Def_Id, Depends_On_Private (T));
9569 Conditional_Delay (Def_Id, T);
9570 end Constrain_Array;
9572 ------------------------------
9573 -- Constrain_Component_Type --
9574 ------------------------------
9576 function Constrain_Component_Type
9578 Constrained_Typ : Entity_Id;
9579 Related_Node : Node_Id;
9581 Constraints : Elist_Id) return Entity_Id
9583 Loc : constant Source_Ptr := Sloc (Constrained_Typ);
9584 Compon_Type : constant Entity_Id := Etype (Comp);
9586 function Build_Constrained_Array_Type
9587 (Old_Type : Entity_Id) return Entity_Id;
9588 -- If Old_Type is an array type, one of whose indices is constrained
9589 -- by a discriminant, build an Itype whose constraint replaces the
9590 -- discriminant with its value in the constraint.
9592 function Build_Constrained_Discriminated_Type
9593 (Old_Type : Entity_Id) return Entity_Id;
9594 -- Ditto for record components
9596 function Build_Constrained_Access_Type
9597 (Old_Type : Entity_Id) return Entity_Id;
9598 -- Ditto for access types. Makes use of previous two functions, to
9599 -- constrain designated type.
9601 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id;
9602 -- T is an array or discriminated type, C is a list of constraints
9603 -- that apply to T. This routine builds the constrained subtype.
9605 function Is_Discriminant (Expr : Node_Id) return Boolean;
9606 -- Returns True if Expr is a discriminant
9608 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id;
9609 -- Find the value of discriminant Discrim in Constraint
9611 -----------------------------------
9612 -- Build_Constrained_Access_Type --
9613 -----------------------------------
9615 function Build_Constrained_Access_Type
9616 (Old_Type : Entity_Id) return Entity_Id
9618 Desig_Type : constant Entity_Id := Designated_Type (Old_Type);
9620 Desig_Subtype : Entity_Id;
9624 -- if the original access type was not embedded in the enclosing
9625 -- type definition, there is no need to produce a new access
9626 -- subtype. In fact every access type with an explicit constraint
9627 -- generates an itype whose scope is the enclosing record.
9629 if not Is_Type (Scope (Old_Type)) then
9632 elsif Is_Array_Type (Desig_Type) then
9633 Desig_Subtype := Build_Constrained_Array_Type (Desig_Type);
9635 elsif Has_Discriminants (Desig_Type) then
9637 -- This may be an access type to an enclosing record type for
9638 -- which we are constructing the constrained components. Return
9639 -- the enclosing record subtype. This is not always correct,
9640 -- but avoids infinite recursion. ???
9642 Desig_Subtype := Any_Type;
9644 for J in reverse 0 .. Scope_Stack.Last loop
9645 Scop := Scope_Stack.Table (J).Entity;
9648 and then Base_Type (Scop) = Base_Type (Desig_Type)
9650 Desig_Subtype := Scop;
9653 exit when not Is_Type (Scop);
9656 if Desig_Subtype = Any_Type then
9658 Build_Constrained_Discriminated_Type (Desig_Type);
9665 if Desig_Subtype /= Desig_Type then
9667 -- The Related_Node better be here or else we won't be able
9668 -- to attach new itypes to a node in the tree.
9670 pragma Assert (Present (Related_Node));
9672 Itype := Create_Itype (E_Access_Subtype, Related_Node);
9674 Set_Etype (Itype, Base_Type (Old_Type));
9675 Set_Size_Info (Itype, (Old_Type));
9676 Set_Directly_Designated_Type (Itype, Desig_Subtype);
9677 Set_Depends_On_Private (Itype, Has_Private_Component
9679 Set_Is_Access_Constant (Itype, Is_Access_Constant
9682 -- The new itype needs freezing when it depends on a not frozen
9683 -- type and the enclosing subtype needs freezing.
9685 if Has_Delayed_Freeze (Constrained_Typ)
9686 and then not Is_Frozen (Constrained_Typ)
9688 Conditional_Delay (Itype, Base_Type (Old_Type));
9696 end Build_Constrained_Access_Type;
9698 ----------------------------------
9699 -- Build_Constrained_Array_Type --
9700 ----------------------------------
9702 function Build_Constrained_Array_Type
9703 (Old_Type : Entity_Id) return Entity_Id
9707 Old_Index : Node_Id;
9708 Range_Node : Node_Id;
9709 Constr_List : List_Id;
9711 Need_To_Create_Itype : Boolean := False;
9714 Old_Index := First_Index (Old_Type);
9715 while Present (Old_Index) loop
9716 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9718 if Is_Discriminant (Lo_Expr)
9719 or else Is_Discriminant (Hi_Expr)
9721 Need_To_Create_Itype := True;
9724 Next_Index (Old_Index);
9727 if Need_To_Create_Itype then
9728 Constr_List := New_List;
9730 Old_Index := First_Index (Old_Type);
9731 while Present (Old_Index) loop
9732 Get_Index_Bounds (Old_Index, Lo_Expr, Hi_Expr);
9734 if Is_Discriminant (Lo_Expr) then
9735 Lo_Expr := Get_Discr_Value (Lo_Expr);
9738 if Is_Discriminant (Hi_Expr) then
9739 Hi_Expr := Get_Discr_Value (Hi_Expr);
9744 (Loc, New_Copy_Tree (Lo_Expr), New_Copy_Tree (Hi_Expr));
9746 Append (Range_Node, To => Constr_List);
9748 Next_Index (Old_Index);
9751 return Build_Subtype (Old_Type, Constr_List);
9756 end Build_Constrained_Array_Type;
9758 ------------------------------------------
9759 -- Build_Constrained_Discriminated_Type --
9760 ------------------------------------------
9762 function Build_Constrained_Discriminated_Type
9763 (Old_Type : Entity_Id) return Entity_Id
9766 Constr_List : List_Id;
9767 Old_Constraint : Elmt_Id;
9769 Need_To_Create_Itype : Boolean := False;
9772 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9773 while Present (Old_Constraint) loop
9774 Expr := Node (Old_Constraint);
9776 if Is_Discriminant (Expr) then
9777 Need_To_Create_Itype := True;
9780 Next_Elmt (Old_Constraint);
9783 if Need_To_Create_Itype then
9784 Constr_List := New_List;
9786 Old_Constraint := First_Elmt (Discriminant_Constraint (Old_Type));
9787 while Present (Old_Constraint) loop
9788 Expr := Node (Old_Constraint);
9790 if Is_Discriminant (Expr) then
9791 Expr := Get_Discr_Value (Expr);
9794 Append (New_Copy_Tree (Expr), To => Constr_List);
9796 Next_Elmt (Old_Constraint);
9799 return Build_Subtype (Old_Type, Constr_List);
9804 end Build_Constrained_Discriminated_Type;
9810 function Build_Subtype (T : Entity_Id; C : List_Id) return Entity_Id is
9812 Subtyp_Decl : Node_Id;
9814 Btyp : Entity_Id := Base_Type (T);
9817 -- The Related_Node better be here or else we won't be able to
9818 -- attach new itypes to a node in the tree.
9820 pragma Assert (Present (Related_Node));
9822 -- If the view of the component's type is incomplete or private
9823 -- with unknown discriminants, then the constraint must be applied
9824 -- to the full type.
9826 if Has_Unknown_Discriminants (Btyp)
9827 and then Present (Underlying_Type (Btyp))
9829 Btyp := Underlying_Type (Btyp);
9833 Make_Subtype_Indication (Loc,
9834 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
9835 Constraint => Make_Index_Or_Discriminant_Constraint (Loc, C));
9837 Def_Id := Create_Itype (Ekind (T), Related_Node);
9840 Make_Subtype_Declaration (Loc,
9841 Defining_Identifier => Def_Id,
9842 Subtype_Indication => Indic);
9844 Set_Parent (Subtyp_Decl, Parent (Related_Node));
9846 -- Itypes must be analyzed with checks off (see package Itypes)
9848 Analyze (Subtyp_Decl, Suppress => All_Checks);
9853 ---------------------
9854 -- Get_Discr_Value --
9855 ---------------------
9857 function Get_Discr_Value (Discrim : Entity_Id) return Node_Id is
9862 -- The discriminant may be declared for the type, in which case we
9863 -- find it by iterating over the list of discriminants. If the
9864 -- discriminant is inherited from a parent type, it appears as the
9865 -- corresponding discriminant of the current type. This will be the
9866 -- case when constraining an inherited component whose constraint is
9867 -- given by a discriminant of the parent.
9869 D := First_Discriminant (Typ);
9870 E := First_Elmt (Constraints);
9872 while Present (D) loop
9873 if D = Entity (Discrim)
9874 or else D = CR_Discriminant (Entity (Discrim))
9875 or else Corresponding_Discriminant (D) = Entity (Discrim)
9880 Next_Discriminant (D);
9884 -- The corresponding_Discriminant mechanism is incomplete, because
9885 -- the correspondence between new and old discriminants is not one
9886 -- to one: one new discriminant can constrain several old ones. In
9887 -- that case, scan sequentially the stored_constraint, the list of
9888 -- discriminants of the parents, and the constraints.
9889 -- Previous code checked for the present of the Stored_Constraint
9890 -- list for the derived type, but did not use it at all. Should it
9891 -- be present when the component is a discriminated task type?
9893 if Is_Derived_Type (Typ)
9894 and then Scope (Entity (Discrim)) = Etype (Typ)
9896 D := First_Discriminant (Etype (Typ));
9897 E := First_Elmt (Constraints);
9898 while Present (D) loop
9899 if D = Entity (Discrim) then
9903 Next_Discriminant (D);
9908 -- Something is wrong if we did not find the value
9910 raise Program_Error;
9911 end Get_Discr_Value;
9913 ---------------------
9914 -- Is_Discriminant --
9915 ---------------------
9917 function Is_Discriminant (Expr : Node_Id) return Boolean is
9918 Discrim_Scope : Entity_Id;
9921 if Denotes_Discriminant (Expr) then
9922 Discrim_Scope := Scope (Entity (Expr));
9924 -- Either we have a reference to one of Typ's discriminants,
9926 pragma Assert (Discrim_Scope = Typ
9928 -- or to the discriminants of the parent type, in the case
9929 -- of a derivation of a tagged type with variants.
9931 or else Discrim_Scope = Etype (Typ)
9932 or else Full_View (Discrim_Scope) = Etype (Typ)
9934 -- or same as above for the case where the discriminants
9935 -- were declared in Typ's private view.
9937 or else (Is_Private_Type (Discrim_Scope)
9938 and then Chars (Discrim_Scope) = Chars (Typ))
9940 -- or else we are deriving from the full view and the
9941 -- discriminant is declared in the private entity.
9943 or else (Is_Private_Type (Typ)
9944 and then Chars (Discrim_Scope) = Chars (Typ))
9946 -- Or we are constrained the corresponding record of a
9947 -- synchronized type that completes a private declaration.
9949 or else (Is_Concurrent_Record_Type (Typ)
9951 Corresponding_Concurrent_Type (Typ) = Discrim_Scope)
9953 -- or we have a class-wide type, in which case make sure the
9954 -- discriminant found belongs to the root type.
9956 or else (Is_Class_Wide_Type (Typ)
9957 and then Etype (Typ) = Discrim_Scope));
9962 -- In all other cases we have something wrong
9965 end Is_Discriminant;
9967 -- Start of processing for Constrain_Component_Type
9970 if Nkind (Parent (Comp)) = N_Component_Declaration
9971 and then Comes_From_Source (Parent (Comp))
9972 and then Comes_From_Source
9973 (Subtype_Indication (Component_Definition (Parent (Comp))))
9976 (Subtype_Indication (Component_Definition (Parent (Comp))))
9980 elsif Is_Array_Type (Compon_Type) then
9981 return Build_Constrained_Array_Type (Compon_Type);
9983 elsif Has_Discriminants (Compon_Type) then
9984 return Build_Constrained_Discriminated_Type (Compon_Type);
9986 elsif Is_Access_Type (Compon_Type) then
9987 return Build_Constrained_Access_Type (Compon_Type);
9992 end Constrain_Component_Type;
9994 --------------------------
9995 -- Constrain_Concurrent --
9996 --------------------------
9998 -- For concurrent types, the associated record value type carries the same
9999 -- discriminants, so when we constrain a concurrent type, we must constrain
10000 -- the corresponding record type as well.
10002 procedure Constrain_Concurrent
10003 (Def_Id : in out Entity_Id;
10005 Related_Nod : Node_Id;
10006 Related_Id : Entity_Id;
10007 Suffix : Character)
10009 T_Ent : Entity_Id := Entity (Subtype_Mark (SI));
10013 if Ekind (T_Ent) in Access_Kind then
10014 T_Ent := Designated_Type (T_Ent);
10017 T_Val := Corresponding_Record_Type (T_Ent);
10019 if Present (T_Val) then
10021 if No (Def_Id) then
10022 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
10025 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
10027 Set_Depends_On_Private (Def_Id, Has_Private_Component (Def_Id));
10028 Set_Corresponding_Record_Type (Def_Id,
10029 Constrain_Corresponding_Record
10030 (Def_Id, T_Val, Related_Nod, Related_Id));
10033 -- If there is no associated record, expansion is disabled and this
10034 -- is a generic context. Create a subtype in any case, so that
10035 -- semantic analysis can proceed.
10037 if No (Def_Id) then
10038 Def_Id := Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
10041 Constrain_Discriminated_Type (Def_Id, SI, Related_Nod);
10043 end Constrain_Concurrent;
10045 ------------------------------------
10046 -- Constrain_Corresponding_Record --
10047 ------------------------------------
10049 function Constrain_Corresponding_Record
10050 (Prot_Subt : Entity_Id;
10051 Corr_Rec : Entity_Id;
10052 Related_Nod : Node_Id;
10053 Related_Id : Entity_Id) return Entity_Id
10055 T_Sub : constant Entity_Id :=
10056 Create_Itype (E_Record_Subtype, Related_Nod, Related_Id, 'V');
10059 Set_Etype (T_Sub, Corr_Rec);
10060 Set_Has_Discriminants (T_Sub, Has_Discriminants (Prot_Subt));
10061 Set_Is_Constrained (T_Sub, True);
10062 Set_First_Entity (T_Sub, First_Entity (Corr_Rec));
10063 Set_Last_Entity (T_Sub, Last_Entity (Corr_Rec));
10065 -- As elsewhere, we do not want to create a freeze node for this itype
10066 -- if it is created for a constrained component of an enclosing record
10067 -- because references to outer discriminants will appear out of scope.
10069 if Ekind (Scope (Prot_Subt)) /= E_Record_Type then
10070 Conditional_Delay (T_Sub, Corr_Rec);
10072 Set_Is_Frozen (T_Sub);
10075 if Has_Discriminants (Prot_Subt) then -- False only if errors.
10076 Set_Discriminant_Constraint
10077 (T_Sub, Discriminant_Constraint (Prot_Subt));
10078 Set_Stored_Constraint_From_Discriminant_Constraint (T_Sub);
10079 Create_Constrained_Components
10080 (T_Sub, Related_Nod, Corr_Rec, Discriminant_Constraint (T_Sub));
10083 Set_Depends_On_Private (T_Sub, Has_Private_Component (T_Sub));
10086 end Constrain_Corresponding_Record;
10088 -----------------------
10089 -- Constrain_Decimal --
10090 -----------------------
10092 procedure Constrain_Decimal (Def_Id : Node_Id; S : Node_Id) is
10093 T : constant Entity_Id := Entity (Subtype_Mark (S));
10094 C : constant Node_Id := Constraint (S);
10095 Loc : constant Source_Ptr := Sloc (C);
10096 Range_Expr : Node_Id;
10097 Digits_Expr : Node_Id;
10102 Set_Ekind (Def_Id, E_Decimal_Fixed_Point_Subtype);
10104 if Nkind (C) = N_Range_Constraint then
10105 Range_Expr := Range_Expression (C);
10106 Digits_Val := Digits_Value (T);
10109 pragma Assert (Nkind (C) = N_Digits_Constraint);
10110 Digits_Expr := Digits_Expression (C);
10111 Analyze_And_Resolve (Digits_Expr, Any_Integer);
10113 Check_Digits_Expression (Digits_Expr);
10114 Digits_Val := Expr_Value (Digits_Expr);
10116 if Digits_Val > Digits_Value (T) then
10118 ("digits expression is incompatible with subtype", C);
10119 Digits_Val := Digits_Value (T);
10122 if Present (Range_Constraint (C)) then
10123 Range_Expr := Range_Expression (Range_Constraint (C));
10125 Range_Expr := Empty;
10129 Set_Etype (Def_Id, Base_Type (T));
10130 Set_Size_Info (Def_Id, (T));
10131 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10132 Set_Delta_Value (Def_Id, Delta_Value (T));
10133 Set_Scale_Value (Def_Id, Scale_Value (T));
10134 Set_Small_Value (Def_Id, Small_Value (T));
10135 Set_Machine_Radix_10 (Def_Id, Machine_Radix_10 (T));
10136 Set_Digits_Value (Def_Id, Digits_Val);
10138 -- Manufacture range from given digits value if no range present
10140 if No (Range_Expr) then
10141 Bound_Val := (Ureal_10 ** Digits_Val - Ureal_1) * Small_Value (T);
10145 Convert_To (T, Make_Real_Literal (Loc, (-Bound_Val))),
10147 Convert_To (T, Make_Real_Literal (Loc, Bound_Val)));
10150 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expr, T);
10151 Set_Discrete_RM_Size (Def_Id);
10153 -- Unconditionally delay the freeze, since we cannot set size
10154 -- information in all cases correctly until the freeze point.
10156 Set_Has_Delayed_Freeze (Def_Id);
10157 end Constrain_Decimal;
10159 ----------------------------------
10160 -- Constrain_Discriminated_Type --
10161 ----------------------------------
10163 procedure Constrain_Discriminated_Type
10164 (Def_Id : Entity_Id;
10166 Related_Nod : Node_Id;
10167 For_Access : Boolean := False)
10169 E : constant Entity_Id := Entity (Subtype_Mark (S));
10172 Elist : Elist_Id := New_Elmt_List;
10174 procedure Fixup_Bad_Constraint;
10175 -- This is called after finding a bad constraint, and after having
10176 -- posted an appropriate error message. The mission is to leave the
10177 -- entity T in as reasonable state as possible!
10179 --------------------------
10180 -- Fixup_Bad_Constraint --
10181 --------------------------
10183 procedure Fixup_Bad_Constraint is
10185 -- Set a reasonable Ekind for the entity. For an incomplete type,
10186 -- we can't do much, but for other types, we can set the proper
10187 -- corresponding subtype kind.
10189 if Ekind (T) = E_Incomplete_Type then
10190 Set_Ekind (Def_Id, Ekind (T));
10192 Set_Ekind (Def_Id, Subtype_Kind (Ekind (T)));
10195 -- Set Etype to the known type, to reduce chances of cascaded errors
10197 Set_Etype (Def_Id, E);
10198 Set_Error_Posted (Def_Id);
10199 end Fixup_Bad_Constraint;
10201 -- Start of processing for Constrain_Discriminated_Type
10204 C := Constraint (S);
10206 -- A discriminant constraint is only allowed in a subtype indication,
10207 -- after a subtype mark. This subtype mark must denote either a type
10208 -- with discriminants, or an access type whose designated type is a
10209 -- type with discriminants. A discriminant constraint specifies the
10210 -- values of these discriminants (RM 3.7.2(5)).
10212 T := Base_Type (Entity (Subtype_Mark (S)));
10214 if Ekind (T) in Access_Kind then
10215 T := Designated_Type (T);
10218 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal.
10219 -- Avoid generating an error for access-to-incomplete subtypes.
10221 if Ada_Version >= Ada_05
10222 and then Ekind (T) = E_Incomplete_Type
10223 and then Nkind (Parent (S)) = N_Subtype_Declaration
10224 and then not Is_Itype (Def_Id)
10226 -- A little sanity check, emit an error message if the type
10227 -- has discriminants to begin with. Type T may be a regular
10228 -- incomplete type or imported via a limited with clause.
10230 if Has_Discriminants (T)
10232 (From_With_Type (T)
10233 and then Present (Non_Limited_View (T))
10234 and then Nkind (Parent (Non_Limited_View (T))) =
10235 N_Full_Type_Declaration
10236 and then Present (Discriminant_Specifications
10237 (Parent (Non_Limited_View (T)))))
10240 ("(Ada 2005) incomplete subtype may not be constrained", C);
10243 ("invalid constraint: type has no discriminant", C);
10246 Fixup_Bad_Constraint;
10249 -- Check that the type has visible discriminants. The type may be
10250 -- a private type with unknown discriminants whose full view has
10251 -- discriminants which are invisible.
10253 elsif not Has_Discriminants (T)
10255 (Has_Unknown_Discriminants (T)
10256 and then Is_Private_Type (T))
10258 Error_Msg_N ("invalid constraint: type has no discriminant", C);
10259 Fixup_Bad_Constraint;
10262 elsif Is_Constrained (E)
10263 or else (Ekind (E) = E_Class_Wide_Subtype
10264 and then Present (Discriminant_Constraint (E)))
10266 Error_Msg_N ("type is already constrained", Subtype_Mark (S));
10267 Fixup_Bad_Constraint;
10271 -- T may be an unconstrained subtype (e.g. a generic actual).
10272 -- Constraint applies to the base type.
10274 T := Base_Type (T);
10276 Elist := Build_Discriminant_Constraints (T, S);
10278 -- If the list returned was empty we had an error in building the
10279 -- discriminant constraint. We have also already signalled an error
10280 -- in the incomplete type case
10282 if Is_Empty_Elmt_List (Elist) then
10283 Fixup_Bad_Constraint;
10287 Build_Discriminated_Subtype (T, Def_Id, Elist, Related_Nod, For_Access);
10288 end Constrain_Discriminated_Type;
10290 ---------------------------
10291 -- Constrain_Enumeration --
10292 ---------------------------
10294 procedure Constrain_Enumeration (Def_Id : Node_Id; S : Node_Id) is
10295 T : constant Entity_Id := Entity (Subtype_Mark (S));
10296 C : constant Node_Id := Constraint (S);
10299 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10301 Set_First_Literal (Def_Id, First_Literal (Base_Type (T)));
10303 Set_Etype (Def_Id, Base_Type (T));
10304 Set_Size_Info (Def_Id, (T));
10305 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10306 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10308 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10310 Set_Discrete_RM_Size (Def_Id);
10311 end Constrain_Enumeration;
10313 ----------------------
10314 -- Constrain_Float --
10315 ----------------------
10317 procedure Constrain_Float (Def_Id : Node_Id; S : Node_Id) is
10318 T : constant Entity_Id := Entity (Subtype_Mark (S));
10324 Set_Ekind (Def_Id, E_Floating_Point_Subtype);
10326 Set_Etype (Def_Id, Base_Type (T));
10327 Set_Size_Info (Def_Id, (T));
10328 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10330 -- Process the constraint
10332 C := Constraint (S);
10334 -- Digits constraint present
10336 if Nkind (C) = N_Digits_Constraint then
10337 Check_Restriction (No_Obsolescent_Features, C);
10339 if Warn_On_Obsolescent_Feature then
10341 ("subtype digits constraint is an " &
10342 "obsolescent feature (RM J.3(8))?", C);
10345 D := Digits_Expression (C);
10346 Analyze_And_Resolve (D, Any_Integer);
10347 Check_Digits_Expression (D);
10348 Set_Digits_Value (Def_Id, Expr_Value (D));
10350 -- Check that digits value is in range. Obviously we can do this
10351 -- at compile time, but it is strictly a runtime check, and of
10352 -- course there is an ACVC test that checks this!
10354 if Digits_Value (Def_Id) > Digits_Value (T) then
10355 Error_Msg_Uint_1 := Digits_Value (T);
10356 Error_Msg_N ("?digits value is too large, maximum is ^", D);
10358 Make_Raise_Constraint_Error (Sloc (D),
10359 Reason => CE_Range_Check_Failed);
10360 Insert_Action (Declaration_Node (Def_Id), Rais);
10363 C := Range_Constraint (C);
10365 -- No digits constraint present
10368 Set_Digits_Value (Def_Id, Digits_Value (T));
10371 -- Range constraint present
10373 if Nkind (C) = N_Range_Constraint then
10374 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10376 -- No range constraint present
10379 pragma Assert (No (C));
10380 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10383 Set_Is_Constrained (Def_Id);
10384 end Constrain_Float;
10386 ---------------------
10387 -- Constrain_Index --
10388 ---------------------
10390 procedure Constrain_Index
10393 Related_Nod : Node_Id;
10394 Related_Id : Entity_Id;
10395 Suffix : Character;
10396 Suffix_Index : Nat)
10398 Def_Id : Entity_Id;
10399 R : Node_Id := Empty;
10400 T : constant Entity_Id := Etype (Index);
10403 if Nkind (S) = N_Range
10405 (Nkind (S) = N_Attribute_Reference
10406 and then Attribute_Name (S) = Name_Range)
10408 -- A Range attribute will transformed into N_Range by Resolve
10414 Process_Range_Expr_In_Decl (R, T, Empty_List);
10416 if not Error_Posted (S)
10418 (Nkind (S) /= N_Range
10419 or else not Covers (T, (Etype (Low_Bound (S))))
10420 or else not Covers (T, (Etype (High_Bound (S)))))
10422 if Base_Type (T) /= Any_Type
10423 and then Etype (Low_Bound (S)) /= Any_Type
10424 and then Etype (High_Bound (S)) /= Any_Type
10426 Error_Msg_N ("range expected", S);
10430 elsif Nkind (S) = N_Subtype_Indication then
10432 -- The parser has verified that this is a discrete indication
10434 Resolve_Discrete_Subtype_Indication (S, T);
10435 R := Range_Expression (Constraint (S));
10437 elsif Nkind (S) = N_Discriminant_Association then
10439 -- Syntactically valid in subtype indication
10441 Error_Msg_N ("invalid index constraint", S);
10442 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10445 -- Subtype_Mark case, no anonymous subtypes to construct
10450 if Is_Entity_Name (S) then
10451 if not Is_Type (Entity (S)) then
10452 Error_Msg_N ("expect subtype mark for index constraint", S);
10454 elsif Base_Type (Entity (S)) /= Base_Type (T) then
10455 Wrong_Type (S, Base_Type (T));
10461 Error_Msg_N ("invalid index constraint", S);
10462 Rewrite (S, New_Occurrence_Of (T, Sloc (S)));
10468 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index);
10470 Set_Etype (Def_Id, Base_Type (T));
10472 if Is_Modular_Integer_Type (T) then
10473 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10475 elsif Is_Integer_Type (T) then
10476 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10479 Set_Ekind (Def_Id, E_Enumeration_Subtype);
10480 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
10483 Set_Size_Info (Def_Id, (T));
10484 Set_RM_Size (Def_Id, RM_Size (T));
10485 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10487 Set_Scalar_Range (Def_Id, R);
10489 Set_Etype (S, Def_Id);
10490 Set_Discrete_RM_Size (Def_Id);
10491 end Constrain_Index;
10493 -----------------------
10494 -- Constrain_Integer --
10495 -----------------------
10497 procedure Constrain_Integer (Def_Id : Node_Id; S : Node_Id) is
10498 T : constant Entity_Id := Entity (Subtype_Mark (S));
10499 C : constant Node_Id := Constraint (S);
10502 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10504 if Is_Modular_Integer_Type (T) then
10505 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
10507 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
10510 Set_Etype (Def_Id, Base_Type (T));
10511 Set_Size_Info (Def_Id, (T));
10512 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10513 Set_Discrete_RM_Size (Def_Id);
10514 end Constrain_Integer;
10516 ------------------------------
10517 -- Constrain_Ordinary_Fixed --
10518 ------------------------------
10520 procedure Constrain_Ordinary_Fixed (Def_Id : Node_Id; S : Node_Id) is
10521 T : constant Entity_Id := Entity (Subtype_Mark (S));
10527 Set_Ekind (Def_Id, E_Ordinary_Fixed_Point_Subtype);
10528 Set_Etype (Def_Id, Base_Type (T));
10529 Set_Size_Info (Def_Id, (T));
10530 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
10531 Set_Small_Value (Def_Id, Small_Value (T));
10533 -- Process the constraint
10535 C := Constraint (S);
10537 -- Delta constraint present
10539 if Nkind (C) = N_Delta_Constraint then
10540 Check_Restriction (No_Obsolescent_Features, C);
10542 if Warn_On_Obsolescent_Feature then
10544 ("subtype delta constraint is an " &
10545 "obsolescent feature (RM J.3(7))?");
10548 D := Delta_Expression (C);
10549 Analyze_And_Resolve (D, Any_Real);
10550 Check_Delta_Expression (D);
10551 Set_Delta_Value (Def_Id, Expr_Value_R (D));
10553 -- Check that delta value is in range. Obviously we can do this
10554 -- at compile time, but it is strictly a runtime check, and of
10555 -- course there is an ACVC test that checks this!
10557 if Delta_Value (Def_Id) < Delta_Value (T) then
10558 Error_Msg_N ("?delta value is too small", D);
10560 Make_Raise_Constraint_Error (Sloc (D),
10561 Reason => CE_Range_Check_Failed);
10562 Insert_Action (Declaration_Node (Def_Id), Rais);
10565 C := Range_Constraint (C);
10567 -- No delta constraint present
10570 Set_Delta_Value (Def_Id, Delta_Value (T));
10573 -- Range constraint present
10575 if Nkind (C) = N_Range_Constraint then
10576 Set_Scalar_Range_For_Subtype (Def_Id, Range_Expression (C), T);
10578 -- No range constraint present
10581 pragma Assert (No (C));
10582 Set_Scalar_Range (Def_Id, Scalar_Range (T));
10586 Set_Discrete_RM_Size (Def_Id);
10588 -- Unconditionally delay the freeze, since we cannot set size
10589 -- information in all cases correctly until the freeze point.
10591 Set_Has_Delayed_Freeze (Def_Id);
10592 end Constrain_Ordinary_Fixed;
10594 -----------------------
10595 -- Contain_Interface --
10596 -----------------------
10598 function Contain_Interface
10599 (Iface : Entity_Id;
10600 Ifaces : Elist_Id) return Boolean
10602 Iface_Elmt : Elmt_Id;
10605 if Present (Ifaces) then
10606 Iface_Elmt := First_Elmt (Ifaces);
10607 while Present (Iface_Elmt) loop
10608 if Node (Iface_Elmt) = Iface then
10612 Next_Elmt (Iface_Elmt);
10617 end Contain_Interface;
10619 ---------------------------
10620 -- Convert_Scalar_Bounds --
10621 ---------------------------
10623 procedure Convert_Scalar_Bounds
10625 Parent_Type : Entity_Id;
10626 Derived_Type : Entity_Id;
10629 Implicit_Base : constant Entity_Id := Base_Type (Derived_Type);
10636 Lo := Build_Scalar_Bound
10637 (Type_Low_Bound (Derived_Type),
10638 Parent_Type, Implicit_Base);
10640 Hi := Build_Scalar_Bound
10641 (Type_High_Bound (Derived_Type),
10642 Parent_Type, Implicit_Base);
10649 Set_Includes_Infinities (Rng, Has_Infinities (Derived_Type));
10651 Set_Parent (Rng, N);
10652 Set_Scalar_Range (Derived_Type, Rng);
10654 -- Analyze the bounds
10656 Analyze_And_Resolve (Lo, Implicit_Base);
10657 Analyze_And_Resolve (Hi, Implicit_Base);
10659 -- Analyze the range itself, except that we do not analyze it if
10660 -- the bounds are real literals, and we have a fixed-point type.
10661 -- The reason for this is that we delay setting the bounds in this
10662 -- case till we know the final Small and Size values (see circuit
10663 -- in Freeze.Freeze_Fixed_Point_Type for further details).
10665 if Is_Fixed_Point_Type (Parent_Type)
10666 and then Nkind (Lo) = N_Real_Literal
10667 and then Nkind (Hi) = N_Real_Literal
10671 -- Here we do the analysis of the range
10673 -- Note: we do this manually, since if we do a normal Analyze and
10674 -- Resolve call, there are problems with the conversions used for
10675 -- the derived type range.
10678 Set_Etype (Rng, Implicit_Base);
10679 Set_Analyzed (Rng, True);
10681 end Convert_Scalar_Bounds;
10683 -------------------
10684 -- Copy_And_Swap --
10685 -------------------
10687 procedure Copy_And_Swap (Priv, Full : Entity_Id) is
10689 -- Initialize new full declaration entity by copying the pertinent
10690 -- fields of the corresponding private declaration entity.
10692 -- We temporarily set Ekind to a value appropriate for a type to
10693 -- avoid assert failures in Einfo from checking for setting type
10694 -- attributes on something that is not a type. Ekind (Priv) is an
10695 -- appropriate choice, since it allowed the attributes to be set
10696 -- in the first place. This Ekind value will be modified later.
10698 Set_Ekind (Full, Ekind (Priv));
10700 -- Also set Etype temporarily to Any_Type, again, in the absence
10701 -- of errors, it will be properly reset, and if there are errors,
10702 -- then we want a value of Any_Type to remain.
10704 Set_Etype (Full, Any_Type);
10706 -- Now start copying attributes
10708 Set_Has_Discriminants (Full, Has_Discriminants (Priv));
10710 if Has_Discriminants (Full) then
10711 Set_Discriminant_Constraint (Full, Discriminant_Constraint (Priv));
10712 Set_Stored_Constraint (Full, Stored_Constraint (Priv));
10715 Set_First_Rep_Item (Full, First_Rep_Item (Priv));
10716 Set_Homonym (Full, Homonym (Priv));
10717 Set_Is_Immediately_Visible (Full, Is_Immediately_Visible (Priv));
10718 Set_Is_Public (Full, Is_Public (Priv));
10719 Set_Is_Pure (Full, Is_Pure (Priv));
10720 Set_Is_Tagged_Type (Full, Is_Tagged_Type (Priv));
10721 Set_Has_Pragma_Unreferenced (Full, Has_Pragma_Unreferenced (Priv));
10722 Set_Has_Pragma_Unreferenced_Objects
10723 (Full, Has_Pragma_Unreferenced_Objects
10726 Conditional_Delay (Full, Priv);
10728 if Is_Tagged_Type (Full) then
10729 Set_Primitive_Operations (Full, Primitive_Operations (Priv));
10731 if Priv = Base_Type (Priv) then
10732 Set_Class_Wide_Type (Full, Class_Wide_Type (Priv));
10736 Set_Is_Volatile (Full, Is_Volatile (Priv));
10737 Set_Treat_As_Volatile (Full, Treat_As_Volatile (Priv));
10738 Set_Scope (Full, Scope (Priv));
10739 Set_Next_Entity (Full, Next_Entity (Priv));
10740 Set_First_Entity (Full, First_Entity (Priv));
10741 Set_Last_Entity (Full, Last_Entity (Priv));
10743 -- If access types have been recorded for later handling, keep them in
10744 -- the full view so that they get handled when the full view freeze
10745 -- node is expanded.
10747 if Present (Freeze_Node (Priv))
10748 and then Present (Access_Types_To_Process (Freeze_Node (Priv)))
10750 Ensure_Freeze_Node (Full);
10751 Set_Access_Types_To_Process
10752 (Freeze_Node (Full),
10753 Access_Types_To_Process (Freeze_Node (Priv)));
10756 -- Swap the two entities. Now Privat is the full type entity and
10757 -- Full is the private one. They will be swapped back at the end
10758 -- of the private part. This swapping ensures that the entity that
10759 -- is visible in the private part is the full declaration.
10761 Exchange_Entities (Priv, Full);
10762 Append_Entity (Full, Scope (Full));
10765 -------------------------------------
10766 -- Copy_Array_Base_Type_Attributes --
10767 -------------------------------------
10769 procedure Copy_Array_Base_Type_Attributes (T1, T2 : Entity_Id) is
10771 Set_Component_Alignment (T1, Component_Alignment (T2));
10772 Set_Component_Type (T1, Component_Type (T2));
10773 Set_Component_Size (T1, Component_Size (T2));
10774 Set_Has_Controlled_Component (T1, Has_Controlled_Component (T2));
10775 Set_Finalize_Storage_Only (T1, Finalize_Storage_Only (T2));
10776 Set_Has_Non_Standard_Rep (T1, Has_Non_Standard_Rep (T2));
10777 Set_Has_Task (T1, Has_Task (T2));
10778 Set_Is_Packed (T1, Is_Packed (T2));
10779 Set_Has_Aliased_Components (T1, Has_Aliased_Components (T2));
10780 Set_Has_Atomic_Components (T1, Has_Atomic_Components (T2));
10781 Set_Has_Volatile_Components (T1, Has_Volatile_Components (T2));
10782 end Copy_Array_Base_Type_Attributes;
10784 -----------------------------------
10785 -- Copy_Array_Subtype_Attributes --
10786 -----------------------------------
10788 procedure Copy_Array_Subtype_Attributes (T1, T2 : Entity_Id) is
10790 Set_Size_Info (T1, T2);
10792 Set_First_Index (T1, First_Index (T2));
10793 Set_Is_Aliased (T1, Is_Aliased (T2));
10794 Set_Is_Atomic (T1, Is_Atomic (T2));
10795 Set_Is_Volatile (T1, Is_Volatile (T2));
10796 Set_Treat_As_Volatile (T1, Treat_As_Volatile (T2));
10797 Set_Is_Constrained (T1, Is_Constrained (T2));
10798 Set_Depends_On_Private (T1, Has_Private_Component (T2));
10799 Set_First_Rep_Item (T1, First_Rep_Item (T2));
10800 Set_Convention (T1, Convention (T2));
10801 Set_Is_Limited_Composite (T1, Is_Limited_Composite (T2));
10802 Set_Is_Private_Composite (T1, Is_Private_Composite (T2));
10803 end Copy_Array_Subtype_Attributes;
10805 -----------------------------------
10806 -- Create_Constrained_Components --
10807 -----------------------------------
10809 procedure Create_Constrained_Components
10811 Decl_Node : Node_Id;
10813 Constraints : Elist_Id)
10815 Loc : constant Source_Ptr := Sloc (Subt);
10816 Comp_List : constant Elist_Id := New_Elmt_List;
10817 Parent_Type : constant Entity_Id := Etype (Typ);
10818 Assoc_List : constant List_Id := New_List;
10819 Discr_Val : Elmt_Id;
10823 Is_Static : Boolean := True;
10825 procedure Collect_Fixed_Components (Typ : Entity_Id);
10826 -- Collect parent type components that do not appear in a variant part
10828 procedure Create_All_Components;
10829 -- Iterate over Comp_List to create the components of the subtype
10831 function Create_Component (Old_Compon : Entity_Id) return Entity_Id;
10832 -- Creates a new component from Old_Compon, copying all the fields from
10833 -- it, including its Etype, inserts the new component in the Subt entity
10834 -- chain and returns the new component.
10836 function Is_Variant_Record (T : Entity_Id) return Boolean;
10837 -- If true, and discriminants are static, collect only components from
10838 -- variants selected by discriminant values.
10840 ------------------------------
10841 -- Collect_Fixed_Components --
10842 ------------------------------
10844 procedure Collect_Fixed_Components (Typ : Entity_Id) is
10846 -- Build association list for discriminants, and find components of the
10847 -- variant part selected by the values of the discriminants.
10849 Old_C := First_Discriminant (Typ);
10850 Discr_Val := First_Elmt (Constraints);
10851 while Present (Old_C) loop
10852 Append_To (Assoc_List,
10853 Make_Component_Association (Loc,
10854 Choices => New_List (New_Occurrence_Of (Old_C, Loc)),
10855 Expression => New_Copy (Node (Discr_Val))));
10857 Next_Elmt (Discr_Val);
10858 Next_Discriminant (Old_C);
10861 -- The tag, and the possible parent and controller components
10862 -- are unconditionally in the subtype.
10864 if Is_Tagged_Type (Typ)
10865 or else Has_Controlled_Component (Typ)
10867 Old_C := First_Component (Typ);
10868 while Present (Old_C) loop
10869 if Chars ((Old_C)) = Name_uTag
10870 or else Chars ((Old_C)) = Name_uParent
10871 or else Chars ((Old_C)) = Name_uController
10873 Append_Elmt (Old_C, Comp_List);
10876 Next_Component (Old_C);
10879 end Collect_Fixed_Components;
10881 ---------------------------
10882 -- Create_All_Components --
10883 ---------------------------
10885 procedure Create_All_Components is
10889 Comp := First_Elmt (Comp_List);
10890 while Present (Comp) loop
10891 Old_C := Node (Comp);
10892 New_C := Create_Component (Old_C);
10896 Constrain_Component_Type
10897 (Old_C, Subt, Decl_Node, Typ, Constraints));
10898 Set_Is_Public (New_C, Is_Public (Subt));
10902 end Create_All_Components;
10904 ----------------------
10905 -- Create_Component --
10906 ----------------------
10908 function Create_Component (Old_Compon : Entity_Id) return Entity_Id is
10909 New_Compon : constant Entity_Id := New_Copy (Old_Compon);
10912 if Ekind (Old_Compon) = E_Discriminant
10913 and then Is_Completely_Hidden (Old_Compon)
10915 -- This is a shadow discriminant created for a discriminant of
10916 -- the parent type that is one of several renamed by the same
10917 -- new discriminant. Give the shadow discriminant an internal
10918 -- name that cannot conflict with that of visible components.
10920 Set_Chars (New_Compon, New_Internal_Name ('C'));
10923 -- Set the parent so we have a proper link for freezing etc. This is
10924 -- not a real parent pointer, since of course our parent does not own
10925 -- up to us and reference us, we are an illegitimate child of the
10926 -- original parent!
10928 Set_Parent (New_Compon, Parent (Old_Compon));
10930 -- If the old component's Esize was already determined and is a
10931 -- static value, then the new component simply inherits it. Otherwise
10932 -- the old component's size may require run-time determination, but
10933 -- the new component's size still might be statically determinable
10934 -- (if, for example it has a static constraint). In that case we want
10935 -- Layout_Type to recompute the component's size, so we reset its
10936 -- size and positional fields.
10938 if Frontend_Layout_On_Target
10939 and then not Known_Static_Esize (Old_Compon)
10941 Set_Esize (New_Compon, Uint_0);
10942 Init_Normalized_First_Bit (New_Compon);
10943 Init_Normalized_Position (New_Compon);
10944 Init_Normalized_Position_Max (New_Compon);
10947 -- We do not want this node marked as Comes_From_Source, since
10948 -- otherwise it would get first class status and a separate cross-
10949 -- reference line would be generated. Illegitimate children do not
10950 -- rate such recognition.
10952 Set_Comes_From_Source (New_Compon, False);
10954 -- But it is a real entity, and a birth certificate must be properly
10955 -- registered by entering it into the entity list.
10957 Enter_Name (New_Compon);
10960 end Create_Component;
10962 -----------------------
10963 -- Is_Variant_Record --
10964 -----------------------
10966 function Is_Variant_Record (T : Entity_Id) return Boolean is
10968 return Nkind (Parent (T)) = N_Full_Type_Declaration
10969 and then Nkind (Type_Definition (Parent (T))) = N_Record_Definition
10970 and then Present (Component_List (Type_Definition (Parent (T))))
10973 (Variant_Part (Component_List (Type_Definition (Parent (T)))));
10974 end Is_Variant_Record;
10976 -- Start of processing for Create_Constrained_Components
10979 pragma Assert (Subt /= Base_Type (Subt));
10980 pragma Assert (Typ = Base_Type (Typ));
10982 Set_First_Entity (Subt, Empty);
10983 Set_Last_Entity (Subt, Empty);
10985 -- Check whether constraint is fully static, in which case we can
10986 -- optimize the list of components.
10988 Discr_Val := First_Elmt (Constraints);
10989 while Present (Discr_Val) loop
10990 if not Is_OK_Static_Expression (Node (Discr_Val)) then
10991 Is_Static := False;
10995 Next_Elmt (Discr_Val);
10998 Set_Has_Static_Discriminants (Subt, Is_Static);
11002 -- Inherit the discriminants of the parent type
11004 Add_Discriminants : declare
11010 Old_C := First_Discriminant (Typ);
11012 while Present (Old_C) loop
11013 Num_Disc := Num_Disc + 1;
11014 New_C := Create_Component (Old_C);
11015 Set_Is_Public (New_C, Is_Public (Subt));
11016 Next_Discriminant (Old_C);
11019 -- For an untagged derived subtype, the number of discriminants may
11020 -- be smaller than the number of inherited discriminants, because
11021 -- several of them may be renamed by a single new discriminant.
11022 -- In this case, add the hidden discriminants back into the subtype,
11023 -- because otherwise the size of the subtype is computed incorrectly
11028 if Is_Derived_Type (Typ)
11029 and then not Is_Tagged_Type (Typ)
11031 Old_C := First_Stored_Discriminant (Typ);
11033 while Present (Old_C) loop
11034 Num_Gird := Num_Gird + 1;
11035 Next_Stored_Discriminant (Old_C);
11039 if Num_Gird > Num_Disc then
11041 -- Find out multiple uses of new discriminants, and add hidden
11042 -- components for the extra renamed discriminants. We recognize
11043 -- multiple uses through the Corresponding_Discriminant of a
11044 -- new discriminant: if it constrains several old discriminants,
11045 -- this field points to the last one in the parent type. The
11046 -- stored discriminants of the derived type have the same name
11047 -- as those of the parent.
11051 New_Discr : Entity_Id;
11052 Old_Discr : Entity_Id;
11055 Constr := First_Elmt (Stored_Constraint (Typ));
11056 Old_Discr := First_Stored_Discriminant (Typ);
11057 while Present (Constr) loop
11058 if Is_Entity_Name (Node (Constr))
11059 and then Ekind (Entity (Node (Constr))) = E_Discriminant
11061 New_Discr := Entity (Node (Constr));
11063 if Chars (Corresponding_Discriminant (New_Discr)) /=
11066 -- The new discriminant has been used to rename a
11067 -- subsequent old discriminant. Introduce a shadow
11068 -- component for the current old discriminant.
11070 New_C := Create_Component (Old_Discr);
11071 Set_Original_Record_Component (New_C, Old_Discr);
11075 Next_Elmt (Constr);
11076 Next_Stored_Discriminant (Old_Discr);
11080 end Add_Discriminants;
11083 and then Is_Variant_Record (Typ)
11085 Collect_Fixed_Components (Typ);
11087 Gather_Components (
11089 Component_List (Type_Definition (Parent (Typ))),
11090 Governed_By => Assoc_List,
11092 Report_Errors => Errors);
11093 pragma Assert (not Errors);
11095 Create_All_Components;
11097 -- If the subtype declaration is created for a tagged type derivation
11098 -- with constraints, we retrieve the record definition of the parent
11099 -- type to select the components of the proper variant.
11102 and then Is_Tagged_Type (Typ)
11103 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11105 Nkind (Type_Definition (Parent (Typ))) = N_Derived_Type_Definition
11106 and then Is_Variant_Record (Parent_Type)
11108 Collect_Fixed_Components (Typ);
11110 Gather_Components (
11112 Component_List (Type_Definition (Parent (Parent_Type))),
11113 Governed_By => Assoc_List,
11115 Report_Errors => Errors);
11116 pragma Assert (not Errors);
11118 -- If the tagged derivation has a type extension, collect all the
11119 -- new components therein.
11122 (Record_Extension_Part (Type_Definition (Parent (Typ))))
11124 Old_C := First_Component (Typ);
11125 while Present (Old_C) loop
11126 if Original_Record_Component (Old_C) = Old_C
11127 and then Chars (Old_C) /= Name_uTag
11128 and then Chars (Old_C) /= Name_uParent
11129 and then Chars (Old_C) /= Name_uController
11131 Append_Elmt (Old_C, Comp_List);
11134 Next_Component (Old_C);
11138 Create_All_Components;
11141 -- If discriminants are not static, or if this is a multi-level type
11142 -- extension, we have to include all components of the parent type.
11144 Old_C := First_Component (Typ);
11145 while Present (Old_C) loop
11146 New_C := Create_Component (Old_C);
11150 Constrain_Component_Type
11151 (Old_C, Subt, Decl_Node, Typ, Constraints));
11152 Set_Is_Public (New_C, Is_Public (Subt));
11154 Next_Component (Old_C);
11159 end Create_Constrained_Components;
11161 ------------------------------------------
11162 -- Decimal_Fixed_Point_Type_Declaration --
11163 ------------------------------------------
11165 procedure Decimal_Fixed_Point_Type_Declaration
11169 Loc : constant Source_Ptr := Sloc (Def);
11170 Digs_Expr : constant Node_Id := Digits_Expression (Def);
11171 Delta_Expr : constant Node_Id := Delta_Expression (Def);
11172 Implicit_Base : Entity_Id;
11179 Check_Restriction (No_Fixed_Point, Def);
11181 -- Create implicit base type
11184 Create_Itype (E_Decimal_Fixed_Point_Type, Parent (Def), T, 'B');
11185 Set_Etype (Implicit_Base, Implicit_Base);
11187 -- Analyze and process delta expression
11189 Analyze_And_Resolve (Delta_Expr, Universal_Real);
11191 Check_Delta_Expression (Delta_Expr);
11192 Delta_Val := Expr_Value_R (Delta_Expr);
11194 -- Check delta is power of 10, and determine scale value from it
11200 Scale_Val := Uint_0;
11203 if Val < Ureal_1 then
11204 while Val < Ureal_1 loop
11205 Val := Val * Ureal_10;
11206 Scale_Val := Scale_Val + 1;
11209 if Scale_Val > 18 then
11210 Error_Msg_N ("scale exceeds maximum value of 18", Def);
11211 Scale_Val := UI_From_Int (+18);
11215 while Val > Ureal_1 loop
11216 Val := Val / Ureal_10;
11217 Scale_Val := Scale_Val - 1;
11220 if Scale_Val < -18 then
11221 Error_Msg_N ("scale is less than minimum value of -18", Def);
11222 Scale_Val := UI_From_Int (-18);
11226 if Val /= Ureal_1 then
11227 Error_Msg_N ("delta expression must be a power of 10", Def);
11228 Delta_Val := Ureal_10 ** (-Scale_Val);
11232 -- Set delta, scale and small (small = delta for decimal type)
11234 Set_Delta_Value (Implicit_Base, Delta_Val);
11235 Set_Scale_Value (Implicit_Base, Scale_Val);
11236 Set_Small_Value (Implicit_Base, Delta_Val);
11238 -- Analyze and process digits expression
11240 Analyze_And_Resolve (Digs_Expr, Any_Integer);
11241 Check_Digits_Expression (Digs_Expr);
11242 Digs_Val := Expr_Value (Digs_Expr);
11244 if Digs_Val > 18 then
11245 Digs_Val := UI_From_Int (+18);
11246 Error_Msg_N ("digits value out of range, maximum is 18", Digs_Expr);
11249 Set_Digits_Value (Implicit_Base, Digs_Val);
11250 Bound_Val := UR_From_Uint (10 ** Digs_Val - 1) * Delta_Val;
11252 -- Set range of base type from digits value for now. This will be
11253 -- expanded to represent the true underlying base range by Freeze.
11255 Set_Fixed_Range (Implicit_Base, Loc, -Bound_Val, Bound_Val);
11257 -- Note: We leave size as zero for now, size will be set at freeze
11258 -- time. We have to do this for ordinary fixed-point, because the size
11259 -- depends on the specified small, and we might as well do the same for
11260 -- decimal fixed-point.
11262 pragma Assert (Esize (Implicit_Base) = Uint_0);
11264 -- If there are bounds given in the declaration use them as the
11265 -- bounds of the first named subtype.
11267 if Present (Real_Range_Specification (Def)) then
11269 RRS : constant Node_Id := Real_Range_Specification (Def);
11270 Low : constant Node_Id := Low_Bound (RRS);
11271 High : constant Node_Id := High_Bound (RRS);
11276 Analyze_And_Resolve (Low, Any_Real);
11277 Analyze_And_Resolve (High, Any_Real);
11278 Check_Real_Bound (Low);
11279 Check_Real_Bound (High);
11280 Low_Val := Expr_Value_R (Low);
11281 High_Val := Expr_Value_R (High);
11283 if Low_Val < (-Bound_Val) then
11285 ("range low bound too small for digits value", Low);
11286 Low_Val := -Bound_Val;
11289 if High_Val > Bound_Val then
11291 ("range high bound too large for digits value", High);
11292 High_Val := Bound_Val;
11295 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
11298 -- If no explicit range, use range that corresponds to given
11299 -- digits value. This will end up as the final range for the
11303 Set_Fixed_Range (T, Loc, -Bound_Val, Bound_Val);
11306 -- Complete entity for first subtype
11308 Set_Ekind (T, E_Decimal_Fixed_Point_Subtype);
11309 Set_Etype (T, Implicit_Base);
11310 Set_Size_Info (T, Implicit_Base);
11311 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
11312 Set_Digits_Value (T, Digs_Val);
11313 Set_Delta_Value (T, Delta_Val);
11314 Set_Small_Value (T, Delta_Val);
11315 Set_Scale_Value (T, Scale_Val);
11316 Set_Is_Constrained (T);
11317 end Decimal_Fixed_Point_Type_Declaration;
11319 -----------------------------------
11320 -- Derive_Progenitor_Subprograms --
11321 -----------------------------------
11323 procedure Derive_Progenitor_Subprograms
11324 (Parent_Type : Entity_Id;
11325 Tagged_Type : Entity_Id)
11330 Iface_Elmt : Elmt_Id;
11331 Iface_Subp : Entity_Id;
11332 New_Subp : Entity_Id := Empty;
11333 Prim_Elmt : Elmt_Id;
11338 pragma Assert (Ada_Version >= Ada_05
11339 and then Is_Record_Type (Tagged_Type)
11340 and then Is_Tagged_Type (Tagged_Type)
11341 and then Has_Interfaces (Tagged_Type));
11343 -- Step 1: Transfer to the full-view primitives asociated with the
11344 -- partial-view that cover interface primitives. Conceptually this
11345 -- work should be done later by Process_Full_View; done here to
11346 -- simplify its implementation at later stages. It can be safely
11347 -- done here because interfaces must be visible in the partial and
11348 -- private view (RM 7.3(7.3/2)).
11350 -- Small optimization: This work is only required if the parent is
11351 -- abstract. If the tagged type is not abstract, it cannot have
11352 -- abstract primitives (the only entities in the list of primitives of
11353 -- non-abstract tagged types that can reference abstract primitives
11354 -- through its Alias attribute are the internal entities that have
11355 -- attribute Interface_Alias, and these entities are generated later
11356 -- by Freeze_Record_Type).
11358 if In_Private_Part (Current_Scope)
11359 and then Is_Abstract_Type (Parent_Type)
11361 Elmt := First_Elmt (Primitive_Operations (Tagged_Type));
11362 while Present (Elmt) loop
11363 Subp := Node (Elmt);
11365 -- At this stage it is not possible to have entities in the list
11366 -- of primitives that have attribute Interface_Alias
11368 pragma Assert (No (Interface_Alias (Subp)));
11370 Typ := Find_Dispatching_Type (Ultimate_Alias (Subp));
11372 if Is_Interface (Typ) then
11373 E := Find_Primitive_Covering_Interface
11374 (Tagged_Type => Tagged_Type,
11375 Iface_Prim => Subp);
11378 and then Find_Dispatching_Type (Ultimate_Alias (E)) /= Typ
11380 Replace_Elmt (Elmt, E);
11381 Remove_Homonym (Subp);
11389 -- Step 2: Add primitives of progenitors that are not implemented by
11390 -- parents of Tagged_Type
11392 if Present (Interfaces (Tagged_Type)) then
11393 Iface_Elmt := First_Elmt (Interfaces (Tagged_Type));
11394 while Present (Iface_Elmt) loop
11395 Iface := Node (Iface_Elmt);
11397 Prim_Elmt := First_Elmt (Primitive_Operations (Iface));
11398 while Present (Prim_Elmt) loop
11399 Iface_Subp := Node (Prim_Elmt);
11401 if not Is_Predefined_Dispatching_Operation (Iface_Subp)
11402 or else Comes_From_Source (Iface_Subp)
11404 E := Find_Primitive_Covering_Interface
11405 (Tagged_Type => Tagged_Type,
11406 Iface_Prim => Iface_Subp);
11408 -- If not found we derive a new primitive leaving its alias
11409 -- attribute referencing the interface primitive
11413 (New_Subp, Iface_Subp, Tagged_Type, Iface);
11415 -- Propagate to the full view interface entities associated
11416 -- with the partial view
11418 elsif In_Private_Part (Current_Scope)
11419 and then Present (Alias (E))
11420 and then Alias (E) = Iface_Subp
11422 List_Containing (Parent (E)) /=
11423 Private_Declarations
11425 (Unit_Declaration_Node (Current_Scope)))
11427 Append_Elmt (E, Primitive_Operations (Tagged_Type));
11431 Next_Elmt (Prim_Elmt);
11434 Next_Elmt (Iface_Elmt);
11437 end Derive_Progenitor_Subprograms;
11439 -----------------------
11440 -- Derive_Subprogram --
11441 -----------------------
11443 procedure Derive_Subprogram
11444 (New_Subp : in out Entity_Id;
11445 Parent_Subp : Entity_Id;
11446 Derived_Type : Entity_Id;
11447 Parent_Type : Entity_Id;
11448 Actual_Subp : Entity_Id := Empty)
11450 Formal : Entity_Id;
11451 -- Formal parameter of parent primitive operation
11453 Formal_Of_Actual : Entity_Id;
11454 -- Formal parameter of actual operation, when the derivation is to
11455 -- create a renaming for a primitive operation of an actual in an
11458 New_Formal : Entity_Id;
11459 -- Formal of inherited operation
11461 Visible_Subp : Entity_Id := Parent_Subp;
11463 function Is_Private_Overriding return Boolean;
11464 -- If Subp is a private overriding of a visible operation, the inherited
11465 -- operation derives from the overridden op (even though its body is the
11466 -- overriding one) and the inherited operation is visible now. See
11467 -- sem_disp to see the full details of the handling of the overridden
11468 -- subprogram, which is removed from the list of primitive operations of
11469 -- the type. The overridden subprogram is saved locally in Visible_Subp,
11470 -- and used to diagnose abstract operations that need overriding in the
11473 procedure Replace_Type (Id, New_Id : Entity_Id);
11474 -- When the type is an anonymous access type, create a new access type
11475 -- designating the derived type.
11477 procedure Set_Derived_Name;
11478 -- This procedure sets the appropriate Chars name for New_Subp. This
11479 -- is normally just a copy of the parent name. An exception arises for
11480 -- type support subprograms, where the name is changed to reflect the
11481 -- name of the derived type, e.g. if type foo is derived from type bar,
11482 -- then a procedure barDA is derived with a name fooDA.
11484 ---------------------------
11485 -- Is_Private_Overriding --
11486 ---------------------------
11488 function Is_Private_Overriding return Boolean is
11492 -- If the parent is not a dispatching operation there is no
11493 -- need to investigate overridings
11495 if not Is_Dispatching_Operation (Parent_Subp) then
11499 -- The visible operation that is overridden is a homonym of the
11500 -- parent subprogram. We scan the homonym chain to find the one
11501 -- whose alias is the subprogram we are deriving.
11503 Prev := Current_Entity (Parent_Subp);
11504 while Present (Prev) loop
11505 if Ekind (Prev) = Ekind (Parent_Subp)
11506 and then Alias (Prev) = Parent_Subp
11507 and then Scope (Parent_Subp) = Scope (Prev)
11508 and then not Is_Hidden (Prev)
11510 Visible_Subp := Prev;
11514 Prev := Homonym (Prev);
11518 end Is_Private_Overriding;
11524 procedure Replace_Type (Id, New_Id : Entity_Id) is
11525 Acc_Type : Entity_Id;
11526 Par : constant Node_Id := Parent (Derived_Type);
11529 -- When the type is an anonymous access type, create a new access
11530 -- type designating the derived type. This itype must be elaborated
11531 -- at the point of the derivation, not on subsequent calls that may
11532 -- be out of the proper scope for Gigi, so we insert a reference to
11533 -- it after the derivation.
11535 if Ekind (Etype (Id)) = E_Anonymous_Access_Type then
11537 Desig_Typ : Entity_Id := Designated_Type (Etype (Id));
11540 if Ekind (Desig_Typ) = E_Record_Type_With_Private
11541 and then Present (Full_View (Desig_Typ))
11542 and then not Is_Private_Type (Parent_Type)
11544 Desig_Typ := Full_View (Desig_Typ);
11547 if Base_Type (Desig_Typ) = Base_Type (Parent_Type)
11549 -- Ada 2005 (AI-251): Handle also derivations of abstract
11550 -- interface primitives.
11552 or else (Is_Interface (Desig_Typ)
11553 and then not Is_Class_Wide_Type (Desig_Typ))
11555 Acc_Type := New_Copy (Etype (Id));
11556 Set_Etype (Acc_Type, Acc_Type);
11557 Set_Scope (Acc_Type, New_Subp);
11559 -- Compute size of anonymous access type
11561 if Is_Array_Type (Desig_Typ)
11562 and then not Is_Constrained (Desig_Typ)
11564 Init_Size (Acc_Type, 2 * System_Address_Size);
11566 Init_Size (Acc_Type, System_Address_Size);
11569 Init_Alignment (Acc_Type);
11570 Set_Directly_Designated_Type (Acc_Type, Derived_Type);
11572 Set_Etype (New_Id, Acc_Type);
11573 Set_Scope (New_Id, New_Subp);
11575 -- Create a reference to it
11576 Build_Itype_Reference (Acc_Type, Parent (Derived_Type));
11579 Set_Etype (New_Id, Etype (Id));
11583 elsif Base_Type (Etype (Id)) = Base_Type (Parent_Type)
11585 (Ekind (Etype (Id)) = E_Record_Type_With_Private
11586 and then Present (Full_View (Etype (Id)))
11588 Base_Type (Full_View (Etype (Id))) = Base_Type (Parent_Type))
11590 -- Constraint checks on formals are generated during expansion,
11591 -- based on the signature of the original subprogram. The bounds
11592 -- of the derived type are not relevant, and thus we can use
11593 -- the base type for the formals. However, the return type may be
11594 -- used in a context that requires that the proper static bounds
11595 -- be used (a case statement, for example) and for those cases
11596 -- we must use the derived type (first subtype), not its base.
11598 -- If the derived_type_definition has no constraints, we know that
11599 -- the derived type has the same constraints as the first subtype
11600 -- of the parent, and we can also use it rather than its base,
11601 -- which can lead to more efficient code.
11603 if Etype (Id) = Parent_Type then
11604 if Is_Scalar_Type (Parent_Type)
11606 Subtypes_Statically_Compatible (Parent_Type, Derived_Type)
11608 Set_Etype (New_Id, Derived_Type);
11610 elsif Nkind (Par) = N_Full_Type_Declaration
11612 Nkind (Type_Definition (Par)) = N_Derived_Type_Definition
11615 (Subtype_Indication (Type_Definition (Par)))
11617 Set_Etype (New_Id, Derived_Type);
11620 Set_Etype (New_Id, Base_Type (Derived_Type));
11624 Set_Etype (New_Id, Base_Type (Derived_Type));
11627 -- Ada 2005 (AI-251): Handle derivations of abstract interface
11630 elsif Is_Interface (Etype (Id))
11631 and then not Is_Class_Wide_Type (Etype (Id))
11632 and then Is_Progenitor (Etype (Id), Derived_Type)
11634 Set_Etype (New_Id, Derived_Type);
11637 Set_Etype (New_Id, Etype (Id));
11641 ----------------------
11642 -- Set_Derived_Name --
11643 ----------------------
11645 procedure Set_Derived_Name is
11646 Nm : constant TSS_Name_Type := Get_TSS_Name (Parent_Subp);
11648 if Nm = TSS_Null then
11649 Set_Chars (New_Subp, Chars (Parent_Subp));
11651 Set_Chars (New_Subp, Make_TSS_Name (Base_Type (Derived_Type), Nm));
11653 end Set_Derived_Name;
11657 Parent_Overrides_Interface_Primitive : Boolean := False;
11659 -- Start of processing for Derive_Subprogram
11663 New_Entity (Nkind (Parent_Subp), Sloc (Derived_Type));
11664 Set_Ekind (New_Subp, Ekind (Parent_Subp));
11666 -- Check whether the parent overrides an interface primitive
11668 if Is_Overriding_Operation (Parent_Subp) then
11670 E : Entity_Id := Parent_Subp;
11672 while Present (Overridden_Operation (E)) loop
11673 E := Ultimate_Alias (Overridden_Operation (E));
11676 Parent_Overrides_Interface_Primitive :=
11677 Is_Dispatching_Operation (E)
11678 and then Present (Find_Dispatching_Type (E))
11679 and then Is_Interface (Find_Dispatching_Type (E));
11683 -- Check whether the inherited subprogram is a private operation that
11684 -- should be inherited but not yet made visible. Such subprograms can
11685 -- become visible at a later point (e.g., the private part of a public
11686 -- child unit) via Declare_Inherited_Private_Subprograms. If the
11687 -- following predicate is true, then this is not such a private
11688 -- operation and the subprogram simply inherits the name of the parent
11689 -- subprogram. Note the special check for the names of controlled
11690 -- operations, which are currently exempted from being inherited with
11691 -- a hidden name because they must be findable for generation of
11692 -- implicit run-time calls.
11694 if not Is_Hidden (Parent_Subp)
11695 or else Is_Internal (Parent_Subp)
11696 or else Is_Private_Overriding
11697 or else Is_Internal_Name (Chars (Parent_Subp))
11698 or else Chars (Parent_Subp) = Name_Initialize
11699 or else Chars (Parent_Subp) = Name_Adjust
11700 or else Chars (Parent_Subp) = Name_Finalize
11704 -- If parent is hidden, this can be a regular derivation if the
11705 -- parent is immediately visible in a non-instantiating context,
11706 -- or if we are in the private part of an instance. This test
11707 -- should still be refined ???
11709 -- The test for In_Instance_Not_Visible avoids inheriting the derived
11710 -- operation as a non-visible operation in cases where the parent
11711 -- subprogram might not be visible now, but was visible within the
11712 -- original generic, so it would be wrong to make the inherited
11713 -- subprogram non-visible now. (Not clear if this test is fully
11714 -- correct; are there any cases where we should declare the inherited
11715 -- operation as not visible to avoid it being overridden, e.g., when
11716 -- the parent type is a generic actual with private primitives ???)
11718 -- (they should be treated the same as other private inherited
11719 -- subprograms, but it's not clear how to do this cleanly). ???
11721 elsif (In_Open_Scopes (Scope (Base_Type (Parent_Type)))
11722 and then Is_Immediately_Visible (Parent_Subp)
11723 and then not In_Instance)
11724 or else In_Instance_Not_Visible
11728 -- Ada 2005 (AI-251): Regular derivation if the parent subprogram
11729 -- overrides an interface primitive because interface primitives
11730 -- must be visible in the partial view of the parent (RM 7.3 (7.3/2))
11732 elsif Parent_Overrides_Interface_Primitive then
11735 -- The type is inheriting a private operation, so enter
11736 -- it with a special name so it can't be overridden.
11739 Set_Chars (New_Subp, New_External_Name (Chars (Parent_Subp), 'P'));
11742 Set_Parent (New_Subp, Parent (Derived_Type));
11744 if Present (Actual_Subp) then
11745 Replace_Type (Actual_Subp, New_Subp);
11747 Replace_Type (Parent_Subp, New_Subp);
11750 Conditional_Delay (New_Subp, Parent_Subp);
11752 -- If we are creating a renaming for a primitive operation of an
11753 -- actual of a generic derived type, we must examine the signature
11754 -- of the actual primitive, not that of the generic formal, which for
11755 -- example may be an interface. However the name and initial value
11756 -- of the inherited operation are those of the formal primitive.
11758 Formal := First_Formal (Parent_Subp);
11760 if Present (Actual_Subp) then
11761 Formal_Of_Actual := First_Formal (Actual_Subp);
11763 Formal_Of_Actual := Empty;
11766 while Present (Formal) loop
11767 New_Formal := New_Copy (Formal);
11769 -- Normally we do not go copying parents, but in the case of
11770 -- formals, we need to link up to the declaration (which is the
11771 -- parameter specification), and it is fine to link up to the
11772 -- original formal's parameter specification in this case.
11774 Set_Parent (New_Formal, Parent (Formal));
11775 Append_Entity (New_Formal, New_Subp);
11777 if Present (Formal_Of_Actual) then
11778 Replace_Type (Formal_Of_Actual, New_Formal);
11779 Next_Formal (Formal_Of_Actual);
11781 Replace_Type (Formal, New_Formal);
11784 Next_Formal (Formal);
11787 -- If this derivation corresponds to a tagged generic actual, then
11788 -- primitive operations rename those of the actual. Otherwise the
11789 -- primitive operations rename those of the parent type, If the parent
11790 -- renames an intrinsic operator, so does the new subprogram. We except
11791 -- concatenation, which is always properly typed, and does not get
11792 -- expanded as other intrinsic operations.
11794 if No (Actual_Subp) then
11795 if Is_Intrinsic_Subprogram (Parent_Subp) then
11796 Set_Is_Intrinsic_Subprogram (New_Subp);
11798 if Present (Alias (Parent_Subp))
11799 and then Chars (Parent_Subp) /= Name_Op_Concat
11801 Set_Alias (New_Subp, Alias (Parent_Subp));
11803 Set_Alias (New_Subp, Parent_Subp);
11807 Set_Alias (New_Subp, Parent_Subp);
11811 Set_Alias (New_Subp, Actual_Subp);
11814 -- Derived subprograms of a tagged type must inherit the convention
11815 -- of the parent subprogram (a requirement of AI-117). Derived
11816 -- subprograms of untagged types simply get convention Ada by default.
11818 if Is_Tagged_Type (Derived_Type) then
11819 Set_Convention (New_Subp, Convention (Parent_Subp));
11822 Set_Is_Imported (New_Subp, Is_Imported (Parent_Subp));
11823 Set_Is_Exported (New_Subp, Is_Exported (Parent_Subp));
11825 if Ekind (Parent_Subp) = E_Procedure then
11826 Set_Is_Valued_Procedure
11827 (New_Subp, Is_Valued_Procedure (Parent_Subp));
11830 -- No_Return must be inherited properly. If this is overridden in the
11831 -- case of a dispatching operation, then a check is made in Sem_Disp
11832 -- that the overriding operation is also No_Return (no such check is
11833 -- required for the case of non-dispatching operation.
11835 Set_No_Return (New_Subp, No_Return (Parent_Subp));
11837 -- A derived function with a controlling result is abstract. If the
11838 -- Derived_Type is a nonabstract formal generic derived type, then
11839 -- inherited operations are not abstract: the required check is done at
11840 -- instantiation time. If the derivation is for a generic actual, the
11841 -- function is not abstract unless the actual is.
11843 if Is_Generic_Type (Derived_Type)
11844 and then not Is_Abstract_Type (Derived_Type)
11848 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
11849 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2).
11851 elsif Ada_Version >= Ada_05
11852 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11853 or else (Is_Tagged_Type (Derived_Type)
11854 and then Etype (New_Subp) = Derived_Type
11855 and then not Is_Null_Extension (Derived_Type))
11856 or else (Is_Tagged_Type (Derived_Type)
11857 and then Ekind (Etype (New_Subp)) =
11858 E_Anonymous_Access_Type
11859 and then Designated_Type (Etype (New_Subp)) =
11861 and then not Is_Null_Extension (Derived_Type)))
11862 and then No (Actual_Subp)
11864 if not Is_Tagged_Type (Derived_Type)
11865 or else Is_Abstract_Type (Derived_Type)
11866 or else Is_Abstract_Subprogram (Alias (New_Subp))
11868 Set_Is_Abstract_Subprogram (New_Subp);
11870 Set_Requires_Overriding (New_Subp);
11873 elsif Ada_Version < Ada_05
11874 and then (Is_Abstract_Subprogram (Alias (New_Subp))
11875 or else (Is_Tagged_Type (Derived_Type)
11876 and then Etype (New_Subp) = Derived_Type
11877 and then No (Actual_Subp)))
11879 Set_Is_Abstract_Subprogram (New_Subp);
11881 -- Finally, if the parent type is abstract we must verify that all
11882 -- inherited operations are either non-abstract or overridden, or that
11883 -- the derived type itself is abstract (this check is performed at the
11884 -- end of a package declaration, in Check_Abstract_Overriding). A
11885 -- private overriding in the parent type will not be visible in the
11886 -- derivation if we are not in an inner package or in a child unit of
11887 -- the parent type, in which case the abstractness of the inherited
11888 -- operation is carried to the new subprogram.
11890 elsif Is_Abstract_Type (Parent_Type)
11891 and then not In_Open_Scopes (Scope (Parent_Type))
11892 and then Is_Private_Overriding
11893 and then Is_Abstract_Subprogram (Visible_Subp)
11895 if No (Actual_Subp) then
11896 Set_Alias (New_Subp, Visible_Subp);
11897 Set_Is_Abstract_Subprogram
11900 -- If this is a derivation for an instance of a formal derived
11901 -- type, abstractness comes from the primitive operation of the
11902 -- actual, not from the operation inherited from the ancestor.
11904 Set_Is_Abstract_Subprogram
11905 (New_Subp, Is_Abstract_Subprogram (Actual_Subp));
11909 New_Overloaded_Entity (New_Subp, Derived_Type);
11911 -- Check for case of a derived subprogram for the instantiation of a
11912 -- formal derived tagged type, if so mark the subprogram as dispatching
11913 -- and inherit the dispatching attributes of the parent subprogram. The
11914 -- derived subprogram is effectively renaming of the actual subprogram,
11915 -- so it needs to have the same attributes as the actual.
11917 if Present (Actual_Subp)
11918 and then Is_Dispatching_Operation (Parent_Subp)
11920 Set_Is_Dispatching_Operation (New_Subp);
11922 if Present (DTC_Entity (Parent_Subp)) then
11923 Set_DTC_Entity (New_Subp, DTC_Entity (Parent_Subp));
11924 Set_DT_Position (New_Subp, DT_Position (Parent_Subp));
11928 -- Indicate that a derived subprogram does not require a body and that
11929 -- it does not require processing of default expressions.
11931 Set_Has_Completion (New_Subp);
11932 Set_Default_Expressions_Processed (New_Subp);
11934 if Ekind (New_Subp) = E_Function then
11935 Set_Mechanism (New_Subp, Mechanism (Parent_Subp));
11937 end Derive_Subprogram;
11939 ------------------------
11940 -- Derive_Subprograms --
11941 ------------------------
11943 procedure Derive_Subprograms
11944 (Parent_Type : Entity_Id;
11945 Derived_Type : Entity_Id;
11946 Generic_Actual : Entity_Id := Empty)
11948 Op_List : constant Elist_Id :=
11949 Collect_Primitive_Operations (Parent_Type);
11951 function Check_Derived_Type return Boolean;
11952 -- Check that all primitive inherited from Parent_Type are found in
11953 -- the list of primitives of Derived_Type exactly in the same order.
11955 function Check_Derived_Type return Boolean is
11959 New_Subp : Entity_Id;
11964 -- Traverse list of entities in the current scope searching for
11965 -- an incomplete type whose full-view is derived type
11967 E := First_Entity (Scope (Derived_Type));
11969 and then E /= Derived_Type
11971 if Ekind (E) = E_Incomplete_Type
11972 and then Present (Full_View (E))
11973 and then Full_View (E) = Derived_Type
11975 -- Disable this test if Derived_Type completes an incomplete
11976 -- type because in such case more primitives can be added
11977 -- later to the list of primitives of Derived_Type by routine
11978 -- Process_Incomplete_Dependents
11983 E := Next_Entity (E);
11986 List := Collect_Primitive_Operations (Derived_Type);
11987 Elmt := First_Elmt (List);
11989 Op_Elmt := First_Elmt (Op_List);
11990 while Present (Op_Elmt) loop
11991 Subp := Node (Op_Elmt);
11992 New_Subp := Node (Elmt);
11994 -- At this early stage Derived_Type has no entities with attribute
11995 -- Interface_Alias. In addition, such primitives are always
11996 -- located at the end of the list of primitives of Parent_Type.
11997 -- Therefore, if found we can safely stop processing pending
12000 exit when Present (Interface_Alias (Subp));
12002 -- Handle hidden entities
12004 if not Is_Predefined_Dispatching_Operation (Subp)
12005 and then Is_Hidden (Subp)
12007 if Present (New_Subp)
12008 and then Primitive_Names_Match (Subp, New_Subp)
12014 if not Present (New_Subp)
12015 or else Ekind (Subp) /= Ekind (New_Subp)
12016 or else not Primitive_Names_Match (Subp, New_Subp)
12024 Next_Elmt (Op_Elmt);
12028 end Check_Derived_Type;
12032 Alias_Subp : Entity_Id;
12033 Act_List : Elist_Id;
12034 Act_Elmt : Elmt_Id := No_Elmt;
12035 Act_Subp : Entity_Id := Empty;
12037 Need_Search : Boolean := False;
12038 New_Subp : Entity_Id := Empty;
12039 Parent_Base : Entity_Id;
12042 -- Start of processing for Derive_Subprograms
12045 if Ekind (Parent_Type) = E_Record_Type_With_Private
12046 and then Has_Discriminants (Parent_Type)
12047 and then Present (Full_View (Parent_Type))
12049 Parent_Base := Full_View (Parent_Type);
12051 Parent_Base := Parent_Type;
12054 if Present (Generic_Actual) then
12055 Act_List := Collect_Primitive_Operations (Generic_Actual);
12056 Act_Elmt := First_Elmt (Act_List);
12059 -- Derive primitives inherited from the parent. Note that if the generic
12060 -- actual is present, this is not really a type derivation, it is a
12061 -- completion within an instance.
12063 -- Case 1: Derived_Type does not implement interfaces
12065 if not Is_Tagged_Type (Derived_Type)
12066 or else (not Has_Interfaces (Derived_Type)
12067 and then not (Present (Generic_Actual)
12069 Has_Interfaces (Generic_Actual)))
12071 Elmt := First_Elmt (Op_List);
12072 while Present (Elmt) loop
12073 Subp := Node (Elmt);
12075 -- Literals are derived earlier in the process of building the
12076 -- derived type, and are skipped here.
12078 if Ekind (Subp) = E_Enumeration_Literal then
12081 -- The actual is a direct descendant and the common primitive
12082 -- operations appear in the same order.
12084 -- If the generic parent type is present, the derived type is an
12085 -- instance of a formal derived type, and within the instance its
12086 -- operations are those of the actual. We derive from the formal
12087 -- type but make the inherited operations aliases of the
12088 -- corresponding operations of the actual.
12092 (New_Subp, Subp, Derived_Type, Parent_Base, Node (Act_Elmt));
12094 if Present (Act_Elmt) then
12095 Next_Elmt (Act_Elmt);
12102 -- Case 2: Derived_Type implements interfaces
12105 -- If the parent type has no predefined primitives we remove
12106 -- predefined primitives from the list of primitives of generic
12107 -- actual to simplify the complexity of this algorithm.
12109 if Present (Generic_Actual) then
12111 Has_Predefined_Primitives : Boolean := False;
12114 -- Check if the parent type has predefined primitives
12116 Elmt := First_Elmt (Op_List);
12117 while Present (Elmt) loop
12118 Subp := Node (Elmt);
12120 if Is_Predefined_Dispatching_Operation (Subp)
12121 and then not Comes_From_Source (Ultimate_Alias (Subp))
12123 Has_Predefined_Primitives := True;
12130 -- Remove predefined primitives of Generic_Actual. We must use
12131 -- an auxiliary list because in case of tagged types the value
12132 -- returned by Collect_Primitive_Operations is the value stored
12133 -- in its Primitive_Operations attribute (and we don't want to
12134 -- modify its current contents).
12136 if not Has_Predefined_Primitives then
12138 Aux_List : constant Elist_Id := New_Elmt_List;
12141 Elmt := First_Elmt (Act_List);
12142 while Present (Elmt) loop
12143 Subp := Node (Elmt);
12145 if not Is_Predefined_Dispatching_Operation (Subp)
12146 or else Comes_From_Source (Subp)
12148 Append_Elmt (Subp, Aux_List);
12154 Act_List := Aux_List;
12158 Act_Elmt := First_Elmt (Act_List);
12159 Act_Subp := Node (Act_Elmt);
12163 -- Stage 1: If the generic actual is not present we derive the
12164 -- primitives inherited from the parent type. If the generic parent
12165 -- type is present, the derived type is an instance of a formal
12166 -- derived type, and within the instance its operations are those of
12167 -- the actual. We derive from the formal type but make the inherited
12168 -- operations aliases of the corresponding operations of the actual.
12170 Elmt := First_Elmt (Op_List);
12171 while Present (Elmt) loop
12172 Subp := Node (Elmt);
12173 Alias_Subp := Ultimate_Alias (Subp);
12175 -- At this early stage Derived_Type has no entities with attribute
12176 -- Interface_Alias. In addition, such primitives are always
12177 -- located at the end of the list of primitives of Parent_Type.
12178 -- Therefore, if found we can safely stop processing pending
12181 exit when Present (Interface_Alias (Subp));
12183 -- If the generic actual is present find the corresponding
12184 -- operation in the generic actual. If the parent type is a
12185 -- direct ancestor of the derived type then, even if it is an
12186 -- interface, the operations are inherited from the primary
12187 -- dispatch table and are in the proper order. If we detect here
12188 -- that primitives are not in the same order we traverse the list
12189 -- of primitive operations of the actual to find the one that
12190 -- implements the interface primitive.
12194 (Present (Generic_Actual)
12195 and then Present (Act_Subp)
12196 and then not Primitive_Names_Match (Subp, Act_Subp))
12198 pragma Assert (not Is_Ancestor (Parent_Base, Generic_Actual));
12199 pragma Assert (Is_Interface (Parent_Base));
12201 -- Remember that we need searching for all the pending
12204 Need_Search := True;
12206 -- Handle entities associated with interface primitives
12208 if Present (Alias (Subp))
12209 and then Is_Interface (Find_Dispatching_Type (Alias (Subp)))
12210 and then not Is_Predefined_Dispatching_Operation (Subp)
12213 Find_Primitive_Covering_Interface
12214 (Tagged_Type => Generic_Actual,
12215 Iface_Prim => Subp);
12217 -- Handle predefined primitives plus the rest of user-defined
12221 Act_Elmt := First_Elmt (Act_List);
12222 while Present (Act_Elmt) loop
12223 Act_Subp := Node (Act_Elmt);
12225 exit when Primitive_Names_Match (Subp, Act_Subp)
12226 and then Type_Conformant (Subp, Act_Subp,
12227 Skip_Controlling_Formals => True)
12228 and then No (Interface_Alias (Act_Subp));
12230 Next_Elmt (Act_Elmt);
12235 -- Case 1: If the parent is a limited interface then it has the
12236 -- predefined primitives of synchronized interfaces. However, the
12237 -- actual type may be a non-limited type and hence it does not
12238 -- have such primitives.
12240 if Present (Generic_Actual)
12241 and then not Present (Act_Subp)
12242 and then Is_Limited_Interface (Parent_Base)
12243 and then Is_Predefined_Interface_Primitive (Subp)
12247 -- Case 2: Inherit entities associated with interfaces that
12248 -- were not covered by the parent type. We exclude here null
12249 -- interface primitives because they do not need special
12252 elsif Present (Alias (Subp))
12253 and then Is_Interface (Find_Dispatching_Type (Alias_Subp))
12255 (Nkind (Parent (Alias_Subp)) = N_Procedure_Specification
12256 and then Null_Present (Parent (Alias_Subp)))
12259 (New_Subp => New_Subp,
12260 Parent_Subp => Alias_Subp,
12261 Derived_Type => Derived_Type,
12262 Parent_Type => Find_Dispatching_Type (Alias_Subp),
12263 Actual_Subp => Act_Subp);
12265 if No (Generic_Actual) then
12266 Set_Alias (New_Subp, Subp);
12269 -- Case 3: Common derivation
12273 (New_Subp => New_Subp,
12274 Parent_Subp => Subp,
12275 Derived_Type => Derived_Type,
12276 Parent_Type => Parent_Base,
12277 Actual_Subp => Act_Subp);
12280 -- No need to update Act_Elm if we must search for the
12281 -- corresponding operation in the generic actual
12284 and then Present (Act_Elmt)
12286 Next_Elmt (Act_Elmt);
12287 Act_Subp := Node (Act_Elmt);
12293 -- Inherit additional operations from progenitors. If the derived
12294 -- type is a generic actual, there are not new primitive operations
12295 -- for the type because it has those of the actual, and therefore
12296 -- nothing needs to be done. The renamings generated above are not
12297 -- primitive operations, and their purpose is simply to make the
12298 -- proper operations visible within an instantiation.
12300 if No (Generic_Actual) then
12301 Derive_Progenitor_Subprograms (Parent_Base, Derived_Type);
12305 -- Final check: Direct descendants must have their primitives in the
12306 -- same order. We exclude from this test non-tagged types and instances
12307 -- of formal derived types. We skip this test if we have already
12308 -- reported serious errors in the sources.
12310 pragma Assert (not Is_Tagged_Type (Derived_Type)
12311 or else Present (Generic_Actual)
12312 or else Serious_Errors_Detected > 0
12313 or else Check_Derived_Type);
12314 end Derive_Subprograms;
12316 --------------------------------
12317 -- Derived_Standard_Character --
12318 --------------------------------
12320 procedure Derived_Standard_Character
12322 Parent_Type : Entity_Id;
12323 Derived_Type : Entity_Id)
12325 Loc : constant Source_Ptr := Sloc (N);
12326 Def : constant Node_Id := Type_Definition (N);
12327 Indic : constant Node_Id := Subtype_Indication (Def);
12328 Parent_Base : constant Entity_Id := Base_Type (Parent_Type);
12329 Implicit_Base : constant Entity_Id :=
12331 (E_Enumeration_Type, N, Derived_Type, 'B');
12337 Discard_Node (Process_Subtype (Indic, N));
12339 Set_Etype (Implicit_Base, Parent_Base);
12340 Set_Size_Info (Implicit_Base, Root_Type (Parent_Type));
12341 Set_RM_Size (Implicit_Base, RM_Size (Root_Type (Parent_Type)));
12343 Set_Is_Character_Type (Implicit_Base, True);
12344 Set_Has_Delayed_Freeze (Implicit_Base);
12346 -- The bounds of the implicit base are the bounds of the parent base.
12347 -- Note that their type is the parent base.
12349 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Base));
12350 Hi := New_Copy_Tree (Type_High_Bound (Parent_Base));
12352 Set_Scalar_Range (Implicit_Base,
12355 High_Bound => Hi));
12357 Conditional_Delay (Derived_Type, Parent_Type);
12359 Set_Ekind (Derived_Type, E_Enumeration_Subtype);
12360 Set_Etype (Derived_Type, Implicit_Base);
12361 Set_Size_Info (Derived_Type, Parent_Type);
12363 if Unknown_RM_Size (Derived_Type) then
12364 Set_RM_Size (Derived_Type, RM_Size (Parent_Type));
12367 Set_Is_Character_Type (Derived_Type, True);
12369 if Nkind (Indic) /= N_Subtype_Indication then
12371 -- If no explicit constraint, the bounds are those
12372 -- of the parent type.
12374 Lo := New_Copy_Tree (Type_Low_Bound (Parent_Type));
12375 Hi := New_Copy_Tree (Type_High_Bound (Parent_Type));
12376 Set_Scalar_Range (Derived_Type, Make_Range (Loc, Lo, Hi));
12379 Convert_Scalar_Bounds (N, Parent_Type, Derived_Type, Loc);
12381 -- Because the implicit base is used in the conversion of the bounds, we
12382 -- have to freeze it now. This is similar to what is done for numeric
12383 -- types, and it equally suspicious, but otherwise a non-static bound
12384 -- will have a reference to an unfrozen type, which is rejected by Gigi
12385 -- (???). This requires specific care for definition of stream
12386 -- attributes. For details, see comments at the end of
12387 -- Build_Derived_Numeric_Type.
12389 Freeze_Before (N, Implicit_Base);
12390 end Derived_Standard_Character;
12392 ------------------------------
12393 -- Derived_Type_Declaration --
12394 ------------------------------
12396 procedure Derived_Type_Declaration
12399 Is_Completion : Boolean)
12401 Parent_Type : Entity_Id;
12403 function Comes_From_Generic (Typ : Entity_Id) return Boolean;
12404 -- Check whether the parent type is a generic formal, or derives
12405 -- directly or indirectly from one.
12407 ------------------------
12408 -- Comes_From_Generic --
12409 ------------------------
12411 function Comes_From_Generic (Typ : Entity_Id) return Boolean is
12413 if Is_Generic_Type (Typ) then
12416 elsif Is_Generic_Type (Root_Type (Parent_Type)) then
12419 elsif Is_Private_Type (Typ)
12420 and then Present (Full_View (Typ))
12421 and then Is_Generic_Type (Root_Type (Full_View (Typ)))
12425 elsif Is_Generic_Actual_Type (Typ) then
12431 end Comes_From_Generic;
12435 Def : constant Node_Id := Type_Definition (N);
12436 Iface_Def : Node_Id;
12437 Indic : constant Node_Id := Subtype_Indication (Def);
12438 Extension : constant Node_Id := Record_Extension_Part (Def);
12439 Parent_Node : Node_Id;
12440 Parent_Scope : Entity_Id;
12443 -- Start of processing for Derived_Type_Declaration
12446 Parent_Type := Find_Type_Of_Subtype_Indic (Indic);
12448 -- Ada 2005 (AI-251): In case of interface derivation check that the
12449 -- parent is also an interface.
12451 if Interface_Present (Def) then
12452 if not Is_Interface (Parent_Type) then
12453 Diagnose_Interface (Indic, Parent_Type);
12456 Parent_Node := Parent (Base_Type (Parent_Type));
12457 Iface_Def := Type_Definition (Parent_Node);
12459 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
12460 -- other limited interfaces.
12462 if Limited_Present (Def) then
12463 if Limited_Present (Iface_Def) then
12466 elsif Protected_Present (Iface_Def) then
12468 ("(Ada 2005) limited interface cannot "
12469 & "inherit from protected interface", Indic);
12471 elsif Synchronized_Present (Iface_Def) then
12473 ("(Ada 2005) limited interface cannot "
12474 & "inherit from synchronized interface", Indic);
12476 elsif Task_Present (Iface_Def) then
12478 ("(Ada 2005) limited interface cannot "
12479 & "inherit from task interface", Indic);
12483 ("(Ada 2005) limited interface cannot "
12484 & "inherit from non-limited interface", Indic);
12487 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
12488 -- from non-limited or limited interfaces.
12490 elsif not Protected_Present (Def)
12491 and then not Synchronized_Present (Def)
12492 and then not Task_Present (Def)
12494 if Limited_Present (Iface_Def) then
12497 elsif Protected_Present (Iface_Def) then
12499 ("(Ada 2005) non-limited interface cannot "
12500 & "inherit from protected interface", Indic);
12502 elsif Synchronized_Present (Iface_Def) then
12504 ("(Ada 2005) non-limited interface cannot "
12505 & "inherit from synchronized interface", Indic);
12507 elsif Task_Present (Iface_Def) then
12509 ("(Ada 2005) non-limited interface cannot "
12510 & "inherit from task interface", Indic);
12519 if Is_Tagged_Type (Parent_Type)
12520 and then Is_Concurrent_Type (Parent_Type)
12521 and then not Is_Interface (Parent_Type)
12524 ("parent type of a record extension cannot be "
12525 & "a synchronized tagged type (RM 3.9.1 (3/1))", N);
12526 Set_Etype (T, Any_Type);
12530 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
12533 if Is_Tagged_Type (Parent_Type)
12534 and then Is_Non_Empty_List (Interface_List (Def))
12541 Intf := First (Interface_List (Def));
12542 while Present (Intf) loop
12543 T := Find_Type_Of_Subtype_Indic (Intf);
12545 if not Is_Interface (T) then
12546 Diagnose_Interface (Intf, T);
12548 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
12549 -- a limited type from having a nonlimited progenitor.
12551 elsif (Limited_Present (Def)
12552 or else (not Is_Interface (Parent_Type)
12553 and then Is_Limited_Type (Parent_Type)))
12554 and then not Is_Limited_Interface (T)
12557 ("progenitor interface& of limited type must be limited",
12566 if Parent_Type = Any_Type
12567 or else Etype (Parent_Type) = Any_Type
12568 or else (Is_Class_Wide_Type (Parent_Type)
12569 and then Etype (Parent_Type) = T)
12571 -- If Parent_Type is undefined or illegal, make new type into a
12572 -- subtype of Any_Type, and set a few attributes to prevent cascaded
12573 -- errors. If this is a self-definition, emit error now.
12576 or else T = Etype (Parent_Type)
12578 Error_Msg_N ("type cannot be used in its own definition", Indic);
12581 Set_Ekind (T, Ekind (Parent_Type));
12582 Set_Etype (T, Any_Type);
12583 Set_Scalar_Range (T, Scalar_Range (Any_Type));
12585 if Is_Tagged_Type (T) then
12586 Set_Primitive_Operations (T, New_Elmt_List);
12592 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
12593 -- an interface is special because the list of interfaces in the full
12594 -- view can be given in any order. For example:
12596 -- type A is interface;
12597 -- type B is interface and A;
12598 -- type D is new B with private;
12600 -- type D is new A and B with null record; -- 1 --
12602 -- In this case we perform the following transformation of -1-:
12604 -- type D is new B and A with null record;
12606 -- If the parent of the full-view covers the parent of the partial-view
12607 -- we have two possible cases:
12609 -- 1) They have the same parent
12610 -- 2) The parent of the full-view implements some further interfaces
12612 -- In both cases we do not need to perform the transformation. In the
12613 -- first case the source program is correct and the transformation is
12614 -- not needed; in the second case the source program does not fulfill
12615 -- the no-hidden interfaces rule (AI-396) and the error will be reported
12618 -- This transformation not only simplifies the rest of the analysis of
12619 -- this type declaration but also simplifies the correct generation of
12620 -- the object layout to the expander.
12622 if In_Private_Part (Current_Scope)
12623 and then Is_Interface (Parent_Type)
12627 Partial_View : Entity_Id;
12628 Partial_View_Parent : Entity_Id;
12629 New_Iface : Node_Id;
12632 -- Look for the associated private type declaration
12634 Partial_View := First_Entity (Current_Scope);
12636 exit when No (Partial_View)
12637 or else (Has_Private_Declaration (Partial_View)
12638 and then Full_View (Partial_View) = T);
12640 Next_Entity (Partial_View);
12643 -- If the partial view was not found then the source code has
12644 -- errors and the transformation is not needed.
12646 if Present (Partial_View) then
12647 Partial_View_Parent := Etype (Partial_View);
12649 -- If the parent of the full-view covers the parent of the
12650 -- partial-view we have nothing else to do.
12652 if Interface_Present_In_Ancestor
12653 (Parent_Type, Partial_View_Parent)
12657 -- Traverse the list of interfaces of the full-view to look
12658 -- for the parent of the partial-view and perform the tree
12662 Iface := First (Interface_List (Def));
12663 while Present (Iface) loop
12664 if Etype (Iface) = Etype (Partial_View) then
12665 Rewrite (Subtype_Indication (Def),
12666 New_Copy (Subtype_Indication
12667 (Parent (Partial_View))));
12669 New_Iface := Make_Identifier (Sloc (N),
12670 Chars (Parent_Type));
12671 Append (New_Iface, Interface_List (Def));
12673 -- Analyze the transformed code
12675 Derived_Type_Declaration (T, N, Is_Completion);
12686 -- Only composite types other than array types are allowed to have
12689 if Present (Discriminant_Specifications (N))
12690 and then (Is_Elementary_Type (Parent_Type)
12691 or else Is_Array_Type (Parent_Type))
12692 and then not Error_Posted (N)
12695 ("elementary or array type cannot have discriminants",
12696 Defining_Identifier (First (Discriminant_Specifications (N))));
12697 Set_Has_Discriminants (T, False);
12700 -- In Ada 83, a derived type defined in a package specification cannot
12701 -- be used for further derivation until the end of its visible part.
12702 -- Note that derivation in the private part of the package is allowed.
12704 if Ada_Version = Ada_83
12705 and then Is_Derived_Type (Parent_Type)
12706 and then In_Visible_Part (Scope (Parent_Type))
12708 if Ada_Version = Ada_83 and then Comes_From_Source (Indic) then
12710 ("(Ada 83): premature use of type for derivation", Indic);
12714 -- Check for early use of incomplete or private type
12716 if Ekind (Parent_Type) = E_Void
12717 or else Ekind (Parent_Type) = E_Incomplete_Type
12719 Error_Msg_N ("premature derivation of incomplete type", Indic);
12722 elsif (Is_Incomplete_Or_Private_Type (Parent_Type)
12723 and then not Comes_From_Generic (Parent_Type))
12724 or else Has_Private_Component (Parent_Type)
12726 -- The ancestor type of a formal type can be incomplete, in which
12727 -- case only the operations of the partial view are available in
12728 -- the generic. Subsequent checks may be required when the full
12729 -- view is analyzed, to verify that derivation from a tagged type
12730 -- has an extension.
12732 if Nkind (Original_Node (N)) = N_Formal_Type_Declaration then
12735 elsif No (Underlying_Type (Parent_Type))
12736 or else Has_Private_Component (Parent_Type)
12739 ("premature derivation of derived or private type", Indic);
12741 -- Flag the type itself as being in error, this prevents some
12742 -- nasty problems with subsequent uses of the malformed type.
12744 Set_Error_Posted (T);
12746 -- Check that within the immediate scope of an untagged partial
12747 -- view it's illegal to derive from the partial view if the
12748 -- full view is tagged. (7.3(7))
12750 -- We verify that the Parent_Type is a partial view by checking
12751 -- that it is not a Full_Type_Declaration (i.e. a private type or
12752 -- private extension declaration), to distinguish a partial view
12753 -- from a derivation from a private type which also appears as
12756 elsif Present (Full_View (Parent_Type))
12757 and then Nkind (Parent (Parent_Type)) /= N_Full_Type_Declaration
12758 and then not Is_Tagged_Type (Parent_Type)
12759 and then Is_Tagged_Type (Full_View (Parent_Type))
12761 Parent_Scope := Scope (T);
12762 while Present (Parent_Scope)
12763 and then Parent_Scope /= Standard_Standard
12765 if Parent_Scope = Scope (Parent_Type) then
12767 ("premature derivation from type with tagged full view",
12771 Parent_Scope := Scope (Parent_Scope);
12776 -- Check that form of derivation is appropriate
12778 Taggd := Is_Tagged_Type (Parent_Type);
12780 -- Perhaps the parent type should be changed to the class-wide type's
12781 -- specific type in this case to prevent cascading errors ???
12783 if Present (Extension) and then Is_Class_Wide_Type (Parent_Type) then
12784 Error_Msg_N ("parent type must not be a class-wide type", Indic);
12788 if Present (Extension) and then not Taggd then
12790 ("type derived from untagged type cannot have extension", Indic);
12792 elsif No (Extension) and then Taggd then
12794 -- If this declaration is within a private part (or body) of a
12795 -- generic instantiation then the derivation is allowed (the parent
12796 -- type can only appear tagged in this case if it's a generic actual
12797 -- type, since it would otherwise have been rejected in the analysis
12798 -- of the generic template).
12800 if not Is_Generic_Actual_Type (Parent_Type)
12801 or else In_Visible_Part (Scope (Parent_Type))
12804 ("type derived from tagged type must have extension", Indic);
12808 -- AI-443: Synchronized formal derived types require a private
12809 -- extension. There is no point in checking the ancestor type or
12810 -- the progenitors since the construct is wrong to begin with.
12812 if Ada_Version >= Ada_05
12813 and then Is_Generic_Type (T)
12814 and then Present (Original_Node (N))
12817 Decl : constant Node_Id := Original_Node (N);
12820 if Nkind (Decl) = N_Formal_Type_Declaration
12821 and then Nkind (Formal_Type_Definition (Decl)) =
12822 N_Formal_Derived_Type_Definition
12823 and then Synchronized_Present (Formal_Type_Definition (Decl))
12824 and then No (Extension)
12826 -- Avoid emitting a duplicate error message
12828 and then not Error_Posted (Indic)
12831 ("synchronized derived type must have extension", N);
12836 Build_Derived_Type (N, Parent_Type, T, Is_Completion);
12838 -- AI-419: The parent type of an explicitly limited derived type must
12839 -- be a limited type or a limited interface.
12841 if Limited_Present (Def) then
12842 Set_Is_Limited_Record (T);
12844 if Is_Interface (T) then
12845 Set_Is_Limited_Interface (T);
12848 if not Is_Limited_Type (Parent_Type)
12850 (not Is_Interface (Parent_Type)
12851 or else not Is_Limited_Interface (Parent_Type))
12853 Error_Msg_NE ("parent type& of limited type must be limited",
12857 end Derived_Type_Declaration;
12859 ------------------------
12860 -- Diagnose_Interface --
12861 ------------------------
12863 procedure Diagnose_Interface (N : Node_Id; E : Entity_Id) is
12865 if not Is_Interface (E)
12866 and then E /= Any_Type
12868 Error_Msg_NE ("(Ada 2005) & must be an interface", N, E);
12870 end Diagnose_Interface;
12872 ----------------------------------
12873 -- Enumeration_Type_Declaration --
12874 ----------------------------------
12876 procedure Enumeration_Type_Declaration (T : Entity_Id; Def : Node_Id) is
12883 -- Create identifier node representing lower bound
12885 B_Node := New_Node (N_Identifier, Sloc (Def));
12886 L := First (Literals (Def));
12887 Set_Chars (B_Node, Chars (L));
12888 Set_Entity (B_Node, L);
12889 Set_Etype (B_Node, T);
12890 Set_Is_Static_Expression (B_Node, True);
12892 R_Node := New_Node (N_Range, Sloc (Def));
12893 Set_Low_Bound (R_Node, B_Node);
12895 Set_Ekind (T, E_Enumeration_Type);
12896 Set_First_Literal (T, L);
12898 Set_Is_Constrained (T);
12902 -- Loop through literals of enumeration type setting pos and rep values
12903 -- except that if the Ekind is already set, then it means that the
12904 -- literal was already constructed (case of a derived type declaration
12905 -- and we should not disturb the Pos and Rep values.
12907 while Present (L) loop
12908 if Ekind (L) /= E_Enumeration_Literal then
12909 Set_Ekind (L, E_Enumeration_Literal);
12910 Set_Enumeration_Pos (L, Ev);
12911 Set_Enumeration_Rep (L, Ev);
12912 Set_Is_Known_Valid (L, True);
12916 New_Overloaded_Entity (L);
12917 Generate_Definition (L);
12918 Set_Convention (L, Convention_Intrinsic);
12920 if Nkind (L) = N_Defining_Character_Literal then
12921 Set_Is_Character_Type (T, True);
12928 -- Now create a node representing upper bound
12930 B_Node := New_Node (N_Identifier, Sloc (Def));
12931 Set_Chars (B_Node, Chars (Last (Literals (Def))));
12932 Set_Entity (B_Node, Last (Literals (Def)));
12933 Set_Etype (B_Node, T);
12934 Set_Is_Static_Expression (B_Node, True);
12936 Set_High_Bound (R_Node, B_Node);
12938 -- Initialize various fields of the type. Some of this information
12939 -- may be overwritten later through rep.clauses.
12941 Set_Scalar_Range (T, R_Node);
12942 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
12943 Set_Enum_Esize (T);
12944 Set_Enum_Pos_To_Rep (T, Empty);
12946 -- Set Discard_Names if configuration pragma set, or if there is
12947 -- a parameterless pragma in the current declarative region
12949 if Global_Discard_Names
12950 or else Discard_Names (Scope (T))
12952 Set_Discard_Names (T);
12955 -- Process end label if there is one
12957 if Present (Def) then
12958 Process_End_Label (Def, 'e', T);
12960 end Enumeration_Type_Declaration;
12962 ---------------------------------
12963 -- Expand_To_Stored_Constraint --
12964 ---------------------------------
12966 function Expand_To_Stored_Constraint
12968 Constraint : Elist_Id) return Elist_Id
12970 Explicitly_Discriminated_Type : Entity_Id;
12971 Expansion : Elist_Id;
12972 Discriminant : Entity_Id;
12974 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id;
12975 -- Find the nearest type that actually specifies discriminants
12977 ---------------------------------
12978 -- Type_With_Explicit_Discrims --
12979 ---------------------------------
12981 function Type_With_Explicit_Discrims (Id : Entity_Id) return Entity_Id is
12982 Typ : constant E := Base_Type (Id);
12985 if Ekind (Typ) in Incomplete_Or_Private_Kind then
12986 if Present (Full_View (Typ)) then
12987 return Type_With_Explicit_Discrims (Full_View (Typ));
12991 if Has_Discriminants (Typ) then
12996 if Etype (Typ) = Typ then
12998 elsif Has_Discriminants (Typ) then
13001 return Type_With_Explicit_Discrims (Etype (Typ));
13004 end Type_With_Explicit_Discrims;
13006 -- Start of processing for Expand_To_Stored_Constraint
13010 or else Is_Empty_Elmt_List (Constraint)
13015 Explicitly_Discriminated_Type := Type_With_Explicit_Discrims (Typ);
13017 if No (Explicitly_Discriminated_Type) then
13021 Expansion := New_Elmt_List;
13024 First_Stored_Discriminant (Explicitly_Discriminated_Type);
13025 while Present (Discriminant) loop
13027 Get_Discriminant_Value (
13028 Discriminant, Explicitly_Discriminated_Type, Constraint),
13030 Next_Stored_Discriminant (Discriminant);
13034 end Expand_To_Stored_Constraint;
13036 ---------------------------
13037 -- Find_Hidden_Interface --
13038 ---------------------------
13040 function Find_Hidden_Interface
13042 Dest : Elist_Id) return Entity_Id
13045 Iface_Elmt : Elmt_Id;
13048 if Present (Src) and then Present (Dest) then
13049 Iface_Elmt := First_Elmt (Src);
13050 while Present (Iface_Elmt) loop
13051 Iface := Node (Iface_Elmt);
13053 if Is_Interface (Iface)
13054 and then not Contain_Interface (Iface, Dest)
13059 Next_Elmt (Iface_Elmt);
13064 end Find_Hidden_Interface;
13066 --------------------
13067 -- Find_Type_Name --
13068 --------------------
13070 function Find_Type_Name (N : Node_Id) return Entity_Id is
13071 Id : constant Entity_Id := Defining_Identifier (N);
13073 New_Id : Entity_Id;
13074 Prev_Par : Node_Id;
13076 procedure Tag_Mismatch;
13077 -- Diagnose a tagged partial view whose full view is untagged.
13078 -- We post the message on the full view, with a reference to
13079 -- the previous partial view. The partial view can be private
13080 -- or incomplete, and these are handled in a different manner,
13081 -- so we determine the position of the error message from the
13082 -- respective slocs of both.
13088 procedure Tag_Mismatch is
13090 if Sloc (Prev) < Sloc (Id) then
13092 ("full declaration of } must be a tagged type ", Id, Prev);
13095 ("full declaration of } must be a tagged type ", Prev, Id);
13099 -- Start processing for Find_Type_Name
13102 -- Find incomplete declaration, if one was given
13104 Prev := Current_Entity_In_Scope (Id);
13106 if Present (Prev) then
13108 -- Previous declaration exists. Error if not incomplete/private case
13109 -- except if previous declaration is implicit, etc. Enter_Name will
13110 -- emit error if appropriate.
13112 Prev_Par := Parent (Prev);
13114 if not Is_Incomplete_Or_Private_Type (Prev) then
13118 elsif not Nkind_In (N, N_Full_Type_Declaration,
13119 N_Task_Type_Declaration,
13120 N_Protected_Type_Declaration)
13122 -- Completion must be a full type declarations (RM 7.3(4))
13124 Error_Msg_Sloc := Sloc (Prev);
13125 Error_Msg_NE ("invalid completion of }", Id, Prev);
13127 -- Set scope of Id to avoid cascaded errors. Entity is never
13128 -- examined again, except when saving globals in generics.
13130 Set_Scope (Id, Current_Scope);
13133 -- Case of full declaration of incomplete type
13135 elsif Ekind (Prev) = E_Incomplete_Type then
13137 -- Indicate that the incomplete declaration has a matching full
13138 -- declaration. The defining occurrence of the incomplete
13139 -- declaration remains the visible one, and the procedure
13140 -- Get_Full_View dereferences it whenever the type is used.
13142 if Present (Full_View (Prev)) then
13143 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
13146 Set_Full_View (Prev, Id);
13147 Append_Entity (Id, Current_Scope);
13148 Set_Is_Public (Id, Is_Public (Prev));
13149 Set_Is_Internal (Id);
13152 -- Case of full declaration of private type
13155 if Nkind (Parent (Prev)) /= N_Private_Extension_Declaration then
13156 if Etype (Prev) /= Prev then
13158 -- Prev is a private subtype or a derived type, and needs
13161 Error_Msg_NE ("invalid redeclaration of }", Id, Prev);
13164 elsif Ekind (Prev) = E_Private_Type
13165 and then Nkind_In (N, N_Task_Type_Declaration,
13166 N_Protected_Type_Declaration)
13169 ("completion of nonlimited type cannot be limited", N);
13171 elsif Ekind (Prev) = E_Record_Type_With_Private
13172 and then Nkind_In (N, N_Task_Type_Declaration,
13173 N_Protected_Type_Declaration)
13175 if not Is_Limited_Record (Prev) then
13177 ("completion of nonlimited type cannot be limited", N);
13179 elsif No (Interface_List (N)) then
13181 ("completion of tagged private type must be tagged",
13186 -- Ada 2005 (AI-251): Private extension declaration of a task
13187 -- type or a protected type. This case arises when covering
13188 -- interface types.
13190 elsif Nkind_In (N, N_Task_Type_Declaration,
13191 N_Protected_Type_Declaration)
13195 elsif Nkind (N) /= N_Full_Type_Declaration
13196 or else Nkind (Type_Definition (N)) /= N_Derived_Type_Definition
13199 ("full view of private extension must be an extension", N);
13201 elsif not (Abstract_Present (Parent (Prev)))
13202 and then Abstract_Present (Type_Definition (N))
13205 ("full view of non-abstract extension cannot be abstract", N);
13208 if not In_Private_Part (Current_Scope) then
13210 ("declaration of full view must appear in private part", N);
13213 Copy_And_Swap (Prev, Id);
13214 Set_Has_Private_Declaration (Prev);
13215 Set_Has_Private_Declaration (Id);
13217 -- If no error, propagate freeze_node from private to full view.
13218 -- It may have been generated for an early operational item.
13220 if Present (Freeze_Node (Id))
13221 and then Serious_Errors_Detected = 0
13222 and then No (Full_View (Id))
13224 Set_Freeze_Node (Prev, Freeze_Node (Id));
13225 Set_Freeze_Node (Id, Empty);
13226 Set_First_Rep_Item (Prev, First_Rep_Item (Id));
13229 Set_Full_View (Id, Prev);
13233 -- Verify that full declaration conforms to partial one
13235 if Is_Incomplete_Or_Private_Type (Prev)
13236 and then Present (Discriminant_Specifications (Prev_Par))
13238 if Present (Discriminant_Specifications (N)) then
13239 if Ekind (Prev) = E_Incomplete_Type then
13240 Check_Discriminant_Conformance (N, Prev, Prev);
13242 Check_Discriminant_Conformance (N, Prev, Id);
13247 ("missing discriminants in full type declaration", N);
13249 -- To avoid cascaded errors on subsequent use, share the
13250 -- discriminants of the partial view.
13252 Set_Discriminant_Specifications (N,
13253 Discriminant_Specifications (Prev_Par));
13257 -- A prior untagged partial view can have an associated class-wide
13258 -- type due to use of the class attribute, and in this case the full
13259 -- type must also be tagged. This Ada 95 usage is deprecated in favor
13260 -- of incomplete tagged declarations, but we check for it.
13263 and then (Is_Tagged_Type (Prev)
13264 or else Present (Class_Wide_Type (Prev)))
13266 -- The full declaration is either a tagged type (including
13267 -- a synchronized type that implements interfaces) or a
13268 -- type extension, otherwise this is an error.
13270 if Nkind_In (N, N_Task_Type_Declaration,
13271 N_Protected_Type_Declaration)
13273 if No (Interface_List (N))
13274 and then not Error_Posted (N)
13279 elsif Nkind (Type_Definition (N)) = N_Record_Definition then
13281 -- Indicate that the previous declaration (tagged incomplete
13282 -- or private declaration) requires the same on the full one.
13284 if not Tagged_Present (Type_Definition (N)) then
13286 Set_Is_Tagged_Type (Id);
13287 Set_Primitive_Operations (Id, New_Elmt_List);
13290 elsif Nkind (Type_Definition (N)) = N_Derived_Type_Definition then
13291 if No (Record_Extension_Part (Type_Definition (N))) then
13293 "full declaration of } must be a record extension",
13295 Set_Is_Tagged_Type (Id);
13296 Set_Primitive_Operations (Id, New_Elmt_List);
13307 -- New type declaration
13312 end Find_Type_Name;
13314 -------------------------
13315 -- Find_Type_Of_Object --
13316 -------------------------
13318 function Find_Type_Of_Object
13319 (Obj_Def : Node_Id;
13320 Related_Nod : Node_Id) return Entity_Id
13322 Def_Kind : constant Node_Kind := Nkind (Obj_Def);
13323 P : Node_Id := Parent (Obj_Def);
13328 -- If the parent is a component_definition node we climb to the
13329 -- component_declaration node
13331 if Nkind (P) = N_Component_Definition then
13335 -- Case of an anonymous array subtype
13337 if Nkind_In (Def_Kind, N_Constrained_Array_Definition,
13338 N_Unconstrained_Array_Definition)
13341 Array_Type_Declaration (T, Obj_Def);
13343 -- Create an explicit subtype whenever possible
13345 elsif Nkind (P) /= N_Component_Declaration
13346 and then Def_Kind = N_Subtype_Indication
13348 -- Base name of subtype on object name, which will be unique in
13349 -- the current scope.
13351 -- If this is a duplicate declaration, return base type, to avoid
13352 -- generating duplicate anonymous types.
13354 if Error_Posted (P) then
13355 Analyze (Subtype_Mark (Obj_Def));
13356 return Entity (Subtype_Mark (Obj_Def));
13361 (Chars (Defining_Identifier (Related_Nod)), 'S', 0, 'T');
13363 T := Make_Defining_Identifier (Sloc (P), Nam);
13365 Insert_Action (Obj_Def,
13366 Make_Subtype_Declaration (Sloc (P),
13367 Defining_Identifier => T,
13368 Subtype_Indication => Relocate_Node (Obj_Def)));
13370 -- This subtype may need freezing, and this will not be done
13371 -- automatically if the object declaration is not in declarative
13372 -- part. Since this is an object declaration, the type cannot always
13373 -- be frozen here. Deferred constants do not freeze their type
13374 -- (which often enough will be private).
13376 if Nkind (P) = N_Object_Declaration
13377 and then Constant_Present (P)
13378 and then No (Expression (P))
13382 Insert_Actions (Obj_Def, Freeze_Entity (T, Sloc (P)));
13385 -- Ada 2005 AI-406: the object definition in an object declaration
13386 -- can be an access definition.
13388 elsif Def_Kind = N_Access_Definition then
13389 T := Access_Definition (Related_Nod, Obj_Def);
13390 Set_Is_Local_Anonymous_Access (T);
13392 -- Otherwise, the object definition is just a subtype_mark
13395 T := Process_Subtype (Obj_Def, Related_Nod);
13399 end Find_Type_Of_Object;
13401 --------------------------------
13402 -- Find_Type_Of_Subtype_Indic --
13403 --------------------------------
13405 function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id is
13409 -- Case of subtype mark with a constraint
13411 if Nkind (S) = N_Subtype_Indication then
13412 Find_Type (Subtype_Mark (S));
13413 Typ := Entity (Subtype_Mark (S));
13416 Is_Valid_Constraint_Kind (Ekind (Typ), Nkind (Constraint (S)))
13419 ("incorrect constraint for this kind of type", Constraint (S));
13420 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
13423 -- Otherwise we have a subtype mark without a constraint
13425 elsif Error_Posted (S) then
13426 Rewrite (S, New_Occurrence_Of (Any_Id, Sloc (S)));
13434 -- Check No_Wide_Characters restriction
13436 if Typ = Standard_Wide_Character
13437 or else Typ = Standard_Wide_Wide_Character
13438 or else Typ = Standard_Wide_String
13439 or else Typ = Standard_Wide_Wide_String
13441 Check_Restriction (No_Wide_Characters, S);
13445 end Find_Type_Of_Subtype_Indic;
13447 -------------------------------------
13448 -- Floating_Point_Type_Declaration --
13449 -------------------------------------
13451 procedure Floating_Point_Type_Declaration (T : Entity_Id; Def : Node_Id) is
13452 Digs : constant Node_Id := Digits_Expression (Def);
13454 Base_Typ : Entity_Id;
13455 Implicit_Base : Entity_Id;
13458 function Can_Derive_From (E : Entity_Id) return Boolean;
13459 -- Find if given digits value allows derivation from specified type
13461 ---------------------
13462 -- Can_Derive_From --
13463 ---------------------
13465 function Can_Derive_From (E : Entity_Id) return Boolean is
13466 Spec : constant Entity_Id := Real_Range_Specification (Def);
13469 if Digs_Val > Digits_Value (E) then
13473 if Present (Spec) then
13474 if Expr_Value_R (Type_Low_Bound (E)) >
13475 Expr_Value_R (Low_Bound (Spec))
13480 if Expr_Value_R (Type_High_Bound (E)) <
13481 Expr_Value_R (High_Bound (Spec))
13488 end Can_Derive_From;
13490 -- Start of processing for Floating_Point_Type_Declaration
13493 Check_Restriction (No_Floating_Point, Def);
13495 -- Create an implicit base type
13498 Create_Itype (E_Floating_Point_Type, Parent (Def), T, 'B');
13500 -- Analyze and verify digits value
13502 Analyze_And_Resolve (Digs, Any_Integer);
13503 Check_Digits_Expression (Digs);
13504 Digs_Val := Expr_Value (Digs);
13506 -- Process possible range spec and find correct type to derive from
13508 Process_Real_Range_Specification (Def);
13510 if Can_Derive_From (Standard_Short_Float) then
13511 Base_Typ := Standard_Short_Float;
13512 elsif Can_Derive_From (Standard_Float) then
13513 Base_Typ := Standard_Float;
13514 elsif Can_Derive_From (Standard_Long_Float) then
13515 Base_Typ := Standard_Long_Float;
13516 elsif Can_Derive_From (Standard_Long_Long_Float) then
13517 Base_Typ := Standard_Long_Long_Float;
13519 -- If we can't derive from any existing type, use long_long_float
13520 -- and give appropriate message explaining the problem.
13523 Base_Typ := Standard_Long_Long_Float;
13525 if Digs_Val >= Digits_Value (Standard_Long_Long_Float) then
13526 Error_Msg_Uint_1 := Digits_Value (Standard_Long_Long_Float);
13527 Error_Msg_N ("digits value out of range, maximum is ^", Digs);
13531 ("range too large for any predefined type",
13532 Real_Range_Specification (Def));
13536 -- If there are bounds given in the declaration use them as the bounds
13537 -- of the type, otherwise use the bounds of the predefined base type
13538 -- that was chosen based on the Digits value.
13540 if Present (Real_Range_Specification (Def)) then
13541 Set_Scalar_Range (T, Real_Range_Specification (Def));
13542 Set_Is_Constrained (T);
13544 -- The bounds of this range must be converted to machine numbers
13545 -- in accordance with RM 4.9(38).
13547 Bound := Type_Low_Bound (T);
13549 if Nkind (Bound) = N_Real_Literal then
13551 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13552 Set_Is_Machine_Number (Bound);
13555 Bound := Type_High_Bound (T);
13557 if Nkind (Bound) = N_Real_Literal then
13559 (Bound, Machine (Base_Typ, Realval (Bound), Round, Bound));
13560 Set_Is_Machine_Number (Bound);
13564 Set_Scalar_Range (T, Scalar_Range (Base_Typ));
13567 -- Complete definition of implicit base and declared first subtype
13569 Set_Etype (Implicit_Base, Base_Typ);
13571 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
13572 Set_Size_Info (Implicit_Base, (Base_Typ));
13573 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
13574 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
13575 Set_Digits_Value (Implicit_Base, Digits_Value (Base_Typ));
13576 Set_Vax_Float (Implicit_Base, Vax_Float (Base_Typ));
13578 Set_Ekind (T, E_Floating_Point_Subtype);
13579 Set_Etype (T, Implicit_Base);
13581 Set_Size_Info (T, (Implicit_Base));
13582 Set_RM_Size (T, RM_Size (Implicit_Base));
13583 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
13584 Set_Digits_Value (T, Digs_Val);
13585 end Floating_Point_Type_Declaration;
13587 ----------------------------
13588 -- Get_Discriminant_Value --
13589 ----------------------------
13591 -- This is the situation:
13593 -- There is a non-derived type
13595 -- type T0 (Dx, Dy, Dz...)
13597 -- There are zero or more levels of derivation, with each derivation
13598 -- either purely inheriting the discriminants, or defining its own.
13600 -- type Ti is new Ti-1
13602 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
13604 -- subtype Ti is ...
13606 -- The subtype issue is avoided by the use of Original_Record_Component,
13607 -- and the fact that derived subtypes also derive the constraints.
13609 -- This chain leads back from
13611 -- Typ_For_Constraint
13613 -- Typ_For_Constraint has discriminants, and the value for each
13614 -- discriminant is given by its corresponding Elmt of Constraints.
13616 -- Discriminant is some discriminant in this hierarchy
13618 -- We need to return its value
13620 -- We do this by recursively searching each level, and looking for
13621 -- Discriminant. Once we get to the bottom, we start backing up
13622 -- returning the value for it which may in turn be a discriminant
13623 -- further up, so on the backup we continue the substitution.
13625 function Get_Discriminant_Value
13626 (Discriminant : Entity_Id;
13627 Typ_For_Constraint : Entity_Id;
13628 Constraint : Elist_Id) return Node_Id
13630 function Search_Derivation_Levels
13632 Discrim_Values : Elist_Id;
13633 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id;
13634 -- This is the routine that performs the recursive search of levels
13635 -- as described above.
13637 ------------------------------
13638 -- Search_Derivation_Levels --
13639 ------------------------------
13641 function Search_Derivation_Levels
13643 Discrim_Values : Elist_Id;
13644 Stored_Discrim_Values : Boolean) return Node_Or_Entity_Id
13648 Result : Node_Or_Entity_Id;
13649 Result_Entity : Node_Id;
13652 -- If inappropriate type, return Error, this happens only in
13653 -- cascaded error situations, and we want to avoid a blow up.
13655 if not Is_Composite_Type (Ti) or else Is_Array_Type (Ti) then
13659 -- Look deeper if possible. Use Stored_Constraints only for
13660 -- untagged types. For tagged types use the given constraint.
13661 -- This asymmetry needs explanation???
13663 if not Stored_Discrim_Values
13664 and then Present (Stored_Constraint (Ti))
13665 and then not Is_Tagged_Type (Ti)
13668 Search_Derivation_Levels (Ti, Stored_Constraint (Ti), True);
13671 Td : constant Entity_Id := Etype (Ti);
13675 Result := Discriminant;
13678 if Present (Stored_Constraint (Ti)) then
13680 Search_Derivation_Levels
13681 (Td, Stored_Constraint (Ti), True);
13684 Search_Derivation_Levels
13685 (Td, Discrim_Values, Stored_Discrim_Values);
13691 -- Extra underlying places to search, if not found above. For
13692 -- concurrent types, the relevant discriminant appears in the
13693 -- corresponding record. For a type derived from a private type
13694 -- without discriminant, the full view inherits the discriminants
13695 -- of the full view of the parent.
13697 if Result = Discriminant then
13698 if Is_Concurrent_Type (Ti)
13699 and then Present (Corresponding_Record_Type (Ti))
13702 Search_Derivation_Levels (
13703 Corresponding_Record_Type (Ti),
13705 Stored_Discrim_Values);
13707 elsif Is_Private_Type (Ti)
13708 and then not Has_Discriminants (Ti)
13709 and then Present (Full_View (Ti))
13710 and then Etype (Full_View (Ti)) /= Ti
13713 Search_Derivation_Levels (
13716 Stored_Discrim_Values);
13720 -- If Result is not a (reference to a) discriminant, return it,
13721 -- otherwise set Result_Entity to the discriminant.
13723 if Nkind (Result) = N_Defining_Identifier then
13724 pragma Assert (Result = Discriminant);
13725 Result_Entity := Result;
13728 if not Denotes_Discriminant (Result) then
13732 Result_Entity := Entity (Result);
13735 -- See if this level of derivation actually has discriminants
13736 -- because tagged derivations can add them, hence the lower
13737 -- levels need not have any.
13739 if not Has_Discriminants (Ti) then
13743 -- Scan Ti's discriminants for Result_Entity,
13744 -- and return its corresponding value, if any.
13746 Result_Entity := Original_Record_Component (Result_Entity);
13748 Assoc := First_Elmt (Discrim_Values);
13750 if Stored_Discrim_Values then
13751 Disc := First_Stored_Discriminant (Ti);
13753 Disc := First_Discriminant (Ti);
13756 while Present (Disc) loop
13757 pragma Assert (Present (Assoc));
13759 if Original_Record_Component (Disc) = Result_Entity then
13760 return Node (Assoc);
13765 if Stored_Discrim_Values then
13766 Next_Stored_Discriminant (Disc);
13768 Next_Discriminant (Disc);
13772 -- Could not find it
13775 end Search_Derivation_Levels;
13779 Result : Node_Or_Entity_Id;
13781 -- Start of processing for Get_Discriminant_Value
13784 -- ??? This routine is a gigantic mess and will be deleted. For the
13785 -- time being just test for the trivial case before calling recurse.
13787 if Base_Type (Scope (Discriminant)) = Base_Type (Typ_For_Constraint) then
13793 D := First_Discriminant (Typ_For_Constraint);
13794 E := First_Elmt (Constraint);
13795 while Present (D) loop
13796 if Chars (D) = Chars (Discriminant) then
13800 Next_Discriminant (D);
13806 Result := Search_Derivation_Levels
13807 (Typ_For_Constraint, Constraint, False);
13809 -- ??? hack to disappear when this routine is gone
13811 if Nkind (Result) = N_Defining_Identifier then
13817 D := First_Discriminant (Typ_For_Constraint);
13818 E := First_Elmt (Constraint);
13819 while Present (D) loop
13820 if Corresponding_Discriminant (D) = Discriminant then
13824 Next_Discriminant (D);
13830 pragma Assert (Nkind (Result) /= N_Defining_Identifier);
13832 end Get_Discriminant_Value;
13834 --------------------------
13835 -- Has_Range_Constraint --
13836 --------------------------
13838 function Has_Range_Constraint (N : Node_Id) return Boolean is
13839 C : constant Node_Id := Constraint (N);
13842 if Nkind (C) = N_Range_Constraint then
13845 elsif Nkind (C) = N_Digits_Constraint then
13847 Is_Decimal_Fixed_Point_Type (Entity (Subtype_Mark (N)))
13849 Present (Range_Constraint (C));
13851 elsif Nkind (C) = N_Delta_Constraint then
13852 return Present (Range_Constraint (C));
13857 end Has_Range_Constraint;
13859 ------------------------
13860 -- Inherit_Components --
13861 ------------------------
13863 function Inherit_Components
13865 Parent_Base : Entity_Id;
13866 Derived_Base : Entity_Id;
13867 Is_Tagged : Boolean;
13868 Inherit_Discr : Boolean;
13869 Discs : Elist_Id) return Elist_Id
13871 Assoc_List : constant Elist_Id := New_Elmt_List;
13873 procedure Inherit_Component
13874 (Old_C : Entity_Id;
13875 Plain_Discrim : Boolean := False;
13876 Stored_Discrim : Boolean := False);
13877 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
13878 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
13879 -- True, Old_C is a stored discriminant. If they are both false then
13880 -- Old_C is a regular component.
13882 -----------------------
13883 -- Inherit_Component --
13884 -----------------------
13886 procedure Inherit_Component
13887 (Old_C : Entity_Id;
13888 Plain_Discrim : Boolean := False;
13889 Stored_Discrim : Boolean := False)
13891 New_C : constant Entity_Id := New_Copy (Old_C);
13893 Discrim : Entity_Id;
13894 Corr_Discrim : Entity_Id;
13897 pragma Assert (not Is_Tagged or else not Stored_Discrim);
13899 Set_Parent (New_C, Parent (Old_C));
13901 -- Regular discriminants and components must be inserted in the scope
13902 -- of the Derived_Base. Do it here.
13904 if not Stored_Discrim then
13905 Enter_Name (New_C);
13908 -- For tagged types the Original_Record_Component must point to
13909 -- whatever this field was pointing to in the parent type. This has
13910 -- already been achieved by the call to New_Copy above.
13912 if not Is_Tagged then
13913 Set_Original_Record_Component (New_C, New_C);
13916 -- If we have inherited a component then see if its Etype contains
13917 -- references to Parent_Base discriminants. In this case, replace
13918 -- these references with the constraints given in Discs. We do not
13919 -- do this for the partial view of private types because this is
13920 -- not needed (only the components of the full view will be used
13921 -- for code generation) and cause problem. We also avoid this
13922 -- transformation in some error situations.
13924 if Ekind (New_C) = E_Component then
13925 if (Is_Private_Type (Derived_Base)
13926 and then not Is_Generic_Type (Derived_Base))
13927 or else (Is_Empty_Elmt_List (Discs)
13928 and then not Expander_Active)
13930 Set_Etype (New_C, Etype (Old_C));
13933 -- The current component introduces a circularity of the
13936 -- limited with Pack_2;
13937 -- package Pack_1 is
13938 -- type T_1 is tagged record
13939 -- Comp : access Pack_2.T_2;
13945 -- package Pack_2 is
13946 -- type T_2 is new Pack_1.T_1 with ...;
13951 Constrain_Component_Type
13952 (Old_C, Derived_Base, N, Parent_Base, Discs));
13956 -- In derived tagged types it is illegal to reference a non
13957 -- discriminant component in the parent type. To catch this, mark
13958 -- these components with an Ekind of E_Void. This will be reset in
13959 -- Record_Type_Definition after processing the record extension of
13960 -- the derived type.
13962 -- If the declaration is a private extension, there is no further
13963 -- record extension to process, and the components retain their
13964 -- current kind, because they are visible at this point.
13966 if Is_Tagged and then Ekind (New_C) = E_Component
13967 and then Nkind (N) /= N_Private_Extension_Declaration
13969 Set_Ekind (New_C, E_Void);
13972 if Plain_Discrim then
13973 Set_Corresponding_Discriminant (New_C, Old_C);
13974 Build_Discriminal (New_C);
13976 -- If we are explicitly inheriting a stored discriminant it will be
13977 -- completely hidden.
13979 elsif Stored_Discrim then
13980 Set_Corresponding_Discriminant (New_C, Empty);
13981 Set_Discriminal (New_C, Empty);
13982 Set_Is_Completely_Hidden (New_C);
13984 -- Set the Original_Record_Component of each discriminant in the
13985 -- derived base to point to the corresponding stored that we just
13988 Discrim := First_Discriminant (Derived_Base);
13989 while Present (Discrim) loop
13990 Corr_Discrim := Corresponding_Discriminant (Discrim);
13992 -- Corr_Discrim could be missing in an error situation
13994 if Present (Corr_Discrim)
13995 and then Original_Record_Component (Corr_Discrim) = Old_C
13997 Set_Original_Record_Component (Discrim, New_C);
14000 Next_Discriminant (Discrim);
14003 Append_Entity (New_C, Derived_Base);
14006 if not Is_Tagged then
14007 Append_Elmt (Old_C, Assoc_List);
14008 Append_Elmt (New_C, Assoc_List);
14010 end Inherit_Component;
14012 -- Variables local to Inherit_Component
14014 Loc : constant Source_Ptr := Sloc (N);
14016 Parent_Discrim : Entity_Id;
14017 Stored_Discrim : Entity_Id;
14019 Component : Entity_Id;
14021 -- Start of processing for Inherit_Components
14024 if not Is_Tagged then
14025 Append_Elmt (Parent_Base, Assoc_List);
14026 Append_Elmt (Derived_Base, Assoc_List);
14029 -- Inherit parent discriminants if needed
14031 if Inherit_Discr then
14032 Parent_Discrim := First_Discriminant (Parent_Base);
14033 while Present (Parent_Discrim) loop
14034 Inherit_Component (Parent_Discrim, Plain_Discrim => True);
14035 Next_Discriminant (Parent_Discrim);
14039 -- Create explicit stored discrims for untagged types when necessary
14041 if not Has_Unknown_Discriminants (Derived_Base)
14042 and then Has_Discriminants (Parent_Base)
14043 and then not Is_Tagged
14046 or else First_Discriminant (Parent_Base) /=
14047 First_Stored_Discriminant (Parent_Base))
14049 Stored_Discrim := First_Stored_Discriminant (Parent_Base);
14050 while Present (Stored_Discrim) loop
14051 Inherit_Component (Stored_Discrim, Stored_Discrim => True);
14052 Next_Stored_Discriminant (Stored_Discrim);
14056 -- See if we can apply the second transformation for derived types, as
14057 -- explained in point 6. in the comments above Build_Derived_Record_Type
14058 -- This is achieved by appending Derived_Base discriminants into Discs,
14059 -- which has the side effect of returning a non empty Discs list to the
14060 -- caller of Inherit_Components, which is what we want. This must be
14061 -- done for private derived types if there are explicit stored
14062 -- discriminants, to ensure that we can retrieve the values of the
14063 -- constraints provided in the ancestors.
14066 and then Is_Empty_Elmt_List (Discs)
14067 and then Present (First_Discriminant (Derived_Base))
14069 (not Is_Private_Type (Derived_Base)
14070 or else Is_Completely_Hidden
14071 (First_Stored_Discriminant (Derived_Base))
14072 or else Is_Generic_Type (Derived_Base))
14074 D := First_Discriminant (Derived_Base);
14075 while Present (D) loop
14076 Append_Elmt (New_Reference_To (D, Loc), Discs);
14077 Next_Discriminant (D);
14081 -- Finally, inherit non-discriminant components unless they are not
14082 -- visible because defined or inherited from the full view of the
14083 -- parent. Don't inherit the _parent field of the parent type.
14085 Component := First_Entity (Parent_Base);
14086 while Present (Component) loop
14088 -- Ada 2005 (AI-251): Do not inherit components associated with
14089 -- secondary tags of the parent.
14091 if Ekind (Component) = E_Component
14092 and then Present (Related_Type (Component))
14096 elsif Ekind (Component) /= E_Component
14097 or else Chars (Component) = Name_uParent
14101 -- If the derived type is within the parent type's declarative
14102 -- region, then the components can still be inherited even though
14103 -- they aren't visible at this point. This can occur for cases
14104 -- such as within public child units where the components must
14105 -- become visible upon entering the child unit's private part.
14107 elsif not Is_Visible_Component (Component)
14108 and then not In_Open_Scopes (Scope (Parent_Base))
14112 elsif Ekind (Derived_Base) = E_Private_Type
14113 or else Ekind (Derived_Base) = E_Limited_Private_Type
14118 Inherit_Component (Component);
14121 Next_Entity (Component);
14124 -- For tagged derived types, inherited discriminants cannot be used in
14125 -- component declarations of the record extension part. To achieve this
14126 -- we mark the inherited discriminants as not visible.
14128 if Is_Tagged and then Inherit_Discr then
14129 D := First_Discriminant (Derived_Base);
14130 while Present (D) loop
14131 Set_Is_Immediately_Visible (D, False);
14132 Next_Discriminant (D);
14137 end Inherit_Components;
14139 -----------------------
14140 -- Is_Null_Extension --
14141 -----------------------
14143 function Is_Null_Extension (T : Entity_Id) return Boolean is
14144 Type_Decl : constant Node_Id := Parent (T);
14145 Comp_List : Node_Id;
14149 if Nkind (Type_Decl) /= N_Full_Type_Declaration
14150 or else not Is_Tagged_Type (T)
14151 or else Nkind (Type_Definition (Type_Decl)) /=
14152 N_Derived_Type_Definition
14153 or else No (Record_Extension_Part (Type_Definition (Type_Decl)))
14159 Component_List (Record_Extension_Part (Type_Definition (Type_Decl)));
14161 if Present (Discriminant_Specifications (Type_Decl)) then
14164 elsif Present (Comp_List)
14165 and then Is_Non_Empty_List (Component_Items (Comp_List))
14167 Comp := First (Component_Items (Comp_List));
14169 -- Only user-defined components are relevant. The component list
14170 -- may also contain a parent component and internal components
14171 -- corresponding to secondary tags, but these do not determine
14172 -- whether this is a null extension.
14174 while Present (Comp) loop
14175 if Comes_From_Source (Comp) then
14186 end Is_Null_Extension;
14188 --------------------
14189 -- Is_Progenitor --
14190 --------------------
14192 function Is_Progenitor
14193 (Iface : Entity_Id;
14194 Typ : Entity_Id) return Boolean
14197 return Implements_Interface (Typ, Iface,
14198 Exclude_Parents => True);
14201 ------------------------------
14202 -- Is_Valid_Constraint_Kind --
14203 ------------------------------
14205 function Is_Valid_Constraint_Kind
14206 (T_Kind : Type_Kind;
14207 Constraint_Kind : Node_Kind) return Boolean
14211 when Enumeration_Kind |
14213 return Constraint_Kind = N_Range_Constraint;
14215 when Decimal_Fixed_Point_Kind =>
14216 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14217 N_Range_Constraint);
14219 when Ordinary_Fixed_Point_Kind =>
14220 return Nkind_In (Constraint_Kind, N_Delta_Constraint,
14221 N_Range_Constraint);
14224 return Nkind_In (Constraint_Kind, N_Digits_Constraint,
14225 N_Range_Constraint);
14232 E_Incomplete_Type |
14235 return Constraint_Kind = N_Index_Or_Discriminant_Constraint;
14238 return True; -- Error will be detected later
14240 end Is_Valid_Constraint_Kind;
14242 --------------------------
14243 -- Is_Visible_Component --
14244 --------------------------
14246 function Is_Visible_Component (C : Entity_Id) return Boolean is
14247 Original_Comp : Entity_Id := Empty;
14248 Original_Scope : Entity_Id;
14249 Type_Scope : Entity_Id;
14251 function Is_Local_Type (Typ : Entity_Id) return Boolean;
14252 -- Check whether parent type of inherited component is declared locally,
14253 -- possibly within a nested package or instance. The current scope is
14254 -- the derived record itself.
14256 -------------------
14257 -- Is_Local_Type --
14258 -------------------
14260 function Is_Local_Type (Typ : Entity_Id) return Boolean is
14264 Scop := Scope (Typ);
14265 while Present (Scop)
14266 and then Scop /= Standard_Standard
14268 if Scop = Scope (Current_Scope) then
14272 Scop := Scope (Scop);
14278 -- Start of processing for Is_Visible_Component
14281 if Ekind (C) = E_Component
14282 or else Ekind (C) = E_Discriminant
14284 Original_Comp := Original_Record_Component (C);
14287 if No (Original_Comp) then
14289 -- Premature usage, or previous error
14294 Original_Scope := Scope (Original_Comp);
14295 Type_Scope := Scope (Base_Type (Scope (C)));
14298 -- This test only concerns tagged types
14300 if not Is_Tagged_Type (Original_Scope) then
14303 -- If it is _Parent or _Tag, there is no visibility issue
14305 elsif not Comes_From_Source (Original_Comp) then
14308 -- If we are in the body of an instantiation, the component is visible
14309 -- even when the parent type (possibly defined in an enclosing unit or
14310 -- in a parent unit) might not.
14312 elsif In_Instance_Body then
14315 -- Discriminants are always visible
14317 elsif Ekind (Original_Comp) = E_Discriminant
14318 and then not Has_Unknown_Discriminants (Original_Scope)
14322 -- If the component has been declared in an ancestor which is currently
14323 -- a private type, then it is not visible. The same applies if the
14324 -- component's containing type is not in an open scope and the original
14325 -- component's enclosing type is a visible full view of a private type
14326 -- (which can occur in cases where an attempt is being made to reference
14327 -- a component in a sibling package that is inherited from a visible
14328 -- component of a type in an ancestor package; the component in the
14329 -- sibling package should not be visible even though the component it
14330 -- inherited from is visible). This does not apply however in the case
14331 -- where the scope of the type is a private child unit, or when the
14332 -- parent comes from a local package in which the ancestor is currently
14333 -- visible. The latter suppression of visibility is needed for cases
14334 -- that are tested in B730006.
14336 elsif Is_Private_Type (Original_Scope)
14338 (not Is_Private_Descendant (Type_Scope)
14339 and then not In_Open_Scopes (Type_Scope)
14340 and then Has_Private_Declaration (Original_Scope))
14342 -- If the type derives from an entity in a formal package, there
14343 -- are no additional visible components.
14345 if Nkind (Original_Node (Unit_Declaration_Node (Type_Scope))) =
14346 N_Formal_Package_Declaration
14350 -- if we are not in the private part of the current package, there
14351 -- are no additional visible components.
14353 elsif Ekind (Scope (Current_Scope)) = E_Package
14354 and then not In_Private_Part (Scope (Current_Scope))
14359 Is_Child_Unit (Cunit_Entity (Current_Sem_Unit))
14360 and then In_Open_Scopes (Scope (Original_Scope))
14361 and then Is_Local_Type (Type_Scope);
14364 -- There is another weird way in which a component may be invisible
14365 -- when the private and the full view are not derived from the same
14366 -- ancestor. Here is an example :
14368 -- type A1 is tagged record F1 : integer; end record;
14369 -- type A2 is new A1 with record F2 : integer; end record;
14370 -- type T is new A1 with private;
14372 -- type T is new A2 with null record;
14374 -- In this case, the full view of T inherits F1 and F2 but the private
14375 -- view inherits only F1
14379 Ancestor : Entity_Id := Scope (C);
14383 if Ancestor = Original_Scope then
14385 elsif Ancestor = Etype (Ancestor) then
14389 Ancestor := Etype (Ancestor);
14393 end Is_Visible_Component;
14395 --------------------------
14396 -- Make_Class_Wide_Type --
14397 --------------------------
14399 procedure Make_Class_Wide_Type (T : Entity_Id) is
14400 CW_Type : Entity_Id;
14402 Next_E : Entity_Id;
14405 -- The class wide type can have been defined by the partial view, in
14406 -- which case everything is already done.
14408 if Present (Class_Wide_Type (T)) then
14413 New_External_Entity (E_Void, Scope (T), Sloc (T), T, 'C', 0, 'T');
14415 -- Inherit root type characteristics
14417 CW_Name := Chars (CW_Type);
14418 Next_E := Next_Entity (CW_Type);
14419 Copy_Node (T, CW_Type);
14420 Set_Comes_From_Source (CW_Type, False);
14421 Set_Chars (CW_Type, CW_Name);
14422 Set_Parent (CW_Type, Parent (T));
14423 Set_Next_Entity (CW_Type, Next_E);
14425 -- Ensure we have a new freeze node for the class-wide type. The partial
14426 -- view may have freeze action of its own, requiring a proper freeze
14427 -- node, and the same freeze node cannot be shared between the two
14430 Set_Has_Delayed_Freeze (CW_Type);
14431 Set_Freeze_Node (CW_Type, Empty);
14433 -- Customize the class-wide type: It has no prim. op., it cannot be
14434 -- abstract and its Etype points back to the specific root type.
14436 Set_Ekind (CW_Type, E_Class_Wide_Type);
14437 Set_Is_Tagged_Type (CW_Type, True);
14438 Set_Primitive_Operations (CW_Type, New_Elmt_List);
14439 Set_Is_Abstract_Type (CW_Type, False);
14440 Set_Is_Constrained (CW_Type, False);
14441 Set_Is_First_Subtype (CW_Type, Is_First_Subtype (T));
14443 if Ekind (T) = E_Class_Wide_Subtype then
14444 Set_Etype (CW_Type, Etype (Base_Type (T)));
14446 Set_Etype (CW_Type, T);
14449 -- If this is the class_wide type of a constrained subtype, it does
14450 -- not have discriminants.
14452 Set_Has_Discriminants (CW_Type,
14453 Has_Discriminants (T) and then not Is_Constrained (T));
14455 Set_Has_Unknown_Discriminants (CW_Type, True);
14456 Set_Class_Wide_Type (T, CW_Type);
14457 Set_Equivalent_Type (CW_Type, Empty);
14459 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
14461 Set_Class_Wide_Type (CW_Type, CW_Type);
14462 end Make_Class_Wide_Type;
14468 procedure Make_Index
14470 Related_Nod : Node_Id;
14471 Related_Id : Entity_Id := Empty;
14472 Suffix_Index : Nat := 1)
14476 Def_Id : Entity_Id := Empty;
14477 Found : Boolean := False;
14480 -- For a discrete range used in a constrained array definition and
14481 -- defined by a range, an implicit conversion to the predefined type
14482 -- INTEGER is assumed if each bound is either a numeric literal, a named
14483 -- number, or an attribute, and the type of both bounds (prior to the
14484 -- implicit conversion) is the type universal_integer. Otherwise, both
14485 -- bounds must be of the same discrete type, other than universal
14486 -- integer; this type must be determinable independently of the
14487 -- context, but using the fact that the type must be discrete and that
14488 -- both bounds must have the same type.
14490 -- Character literals also have a universal type in the absence of
14491 -- of additional context, and are resolved to Standard_Character.
14493 if Nkind (I) = N_Range then
14495 -- The index is given by a range constraint. The bounds are known
14496 -- to be of a consistent type.
14498 if not Is_Overloaded (I) then
14501 -- For universal bounds, choose the specific predefined type
14503 if T = Universal_Integer then
14504 T := Standard_Integer;
14506 elsif T = Any_Character then
14507 Ambiguous_Character (Low_Bound (I));
14509 T := Standard_Character;
14512 -- The node may be overloaded because some user-defined operators
14513 -- are available, but if a universal interpretation exists it is
14514 -- also the selected one.
14516 elsif Universal_Interpretation (I) = Universal_Integer then
14517 T := Standard_Integer;
14523 Ind : Interp_Index;
14527 Get_First_Interp (I, Ind, It);
14528 while Present (It.Typ) loop
14529 if Is_Discrete_Type (It.Typ) then
14532 and then not Covers (It.Typ, T)
14533 and then not Covers (T, It.Typ)
14535 Error_Msg_N ("ambiguous bounds in discrete range", I);
14543 Get_Next_Interp (Ind, It);
14546 if T = Any_Type then
14547 Error_Msg_N ("discrete type required for range", I);
14548 Set_Etype (I, Any_Type);
14551 elsif T = Universal_Integer then
14552 T := Standard_Integer;
14557 if not Is_Discrete_Type (T) then
14558 Error_Msg_N ("discrete type required for range", I);
14559 Set_Etype (I, Any_Type);
14563 if Nkind (Low_Bound (I)) = N_Attribute_Reference
14564 and then Attribute_Name (Low_Bound (I)) = Name_First
14565 and then Is_Entity_Name (Prefix (Low_Bound (I)))
14566 and then Is_Type (Entity (Prefix (Low_Bound (I))))
14567 and then Is_Discrete_Type (Entity (Prefix (Low_Bound (I))))
14569 -- The type of the index will be the type of the prefix, as long
14570 -- as the upper bound is 'Last of the same type.
14572 Def_Id := Entity (Prefix (Low_Bound (I)));
14574 if Nkind (High_Bound (I)) /= N_Attribute_Reference
14575 or else Attribute_Name (High_Bound (I)) /= Name_Last
14576 or else not Is_Entity_Name (Prefix (High_Bound (I)))
14577 or else Entity (Prefix (High_Bound (I))) /= Def_Id
14584 Process_Range_Expr_In_Decl (R, T);
14586 elsif Nkind (I) = N_Subtype_Indication then
14588 -- The index is given by a subtype with a range constraint
14590 T := Base_Type (Entity (Subtype_Mark (I)));
14592 if not Is_Discrete_Type (T) then
14593 Error_Msg_N ("discrete type required for range", I);
14594 Set_Etype (I, Any_Type);
14598 R := Range_Expression (Constraint (I));
14601 Process_Range_Expr_In_Decl (R, Entity (Subtype_Mark (I)));
14603 elsif Nkind (I) = N_Attribute_Reference then
14605 -- The parser guarantees that the attribute is a RANGE attribute
14607 -- If the node denotes the range of a type mark, that is also the
14608 -- resulting type, and we do no need to create an Itype for it.
14610 if Is_Entity_Name (Prefix (I))
14611 and then Comes_From_Source (I)
14612 and then Is_Type (Entity (Prefix (I)))
14613 and then Is_Discrete_Type (Entity (Prefix (I)))
14615 Def_Id := Entity (Prefix (I));
14618 Analyze_And_Resolve (I);
14622 -- If none of the above, must be a subtype. We convert this to a
14623 -- range attribute reference because in the case of declared first
14624 -- named subtypes, the types in the range reference can be different
14625 -- from the type of the entity. A range attribute normalizes the
14626 -- reference and obtains the correct types for the bounds.
14628 -- This transformation is in the nature of an expansion, is only
14629 -- done if expansion is active. In particular, it is not done on
14630 -- formal generic types, because we need to retain the name of the
14631 -- original index for instantiation purposes.
14634 if not Is_Entity_Name (I) or else not Is_Type (Entity (I)) then
14635 Error_Msg_N ("invalid subtype mark in discrete range ", I);
14636 Set_Etype (I, Any_Integer);
14640 -- The type mark may be that of an incomplete type. It is only
14641 -- now that we can get the full view, previous analysis does
14642 -- not look specifically for a type mark.
14644 Set_Entity (I, Get_Full_View (Entity (I)));
14645 Set_Etype (I, Entity (I));
14646 Def_Id := Entity (I);
14648 if not Is_Discrete_Type (Def_Id) then
14649 Error_Msg_N ("discrete type required for index", I);
14650 Set_Etype (I, Any_Type);
14655 if Expander_Active then
14657 Make_Attribute_Reference (Sloc (I),
14658 Attribute_Name => Name_Range,
14659 Prefix => Relocate_Node (I)));
14661 -- The original was a subtype mark that does not freeze. This
14662 -- means that the rewritten version must not freeze either.
14664 Set_Must_Not_Freeze (I);
14665 Set_Must_Not_Freeze (Prefix (I));
14667 -- Is order critical??? if so, document why, if not
14668 -- use Analyze_And_Resolve
14670 Analyze_And_Resolve (I);
14674 -- If expander is inactive, type is legal, nothing else to construct
14681 if not Is_Discrete_Type (T) then
14682 Error_Msg_N ("discrete type required for range", I);
14683 Set_Etype (I, Any_Type);
14686 elsif T = Any_Type then
14687 Set_Etype (I, Any_Type);
14691 -- We will now create the appropriate Itype to describe the range, but
14692 -- first a check. If we originally had a subtype, then we just label
14693 -- the range with this subtype. Not only is there no need to construct
14694 -- a new subtype, but it is wrong to do so for two reasons:
14696 -- 1. A legality concern, if we have a subtype, it must not freeze,
14697 -- and the Itype would cause freezing incorrectly
14699 -- 2. An efficiency concern, if we created an Itype, it would not be
14700 -- recognized as the same type for the purposes of eliminating
14701 -- checks in some circumstances.
14703 -- We signal this case by setting the subtype entity in Def_Id
14705 if No (Def_Id) then
14707 Create_Itype (E_Void, Related_Nod, Related_Id, 'D', Suffix_Index);
14708 Set_Etype (Def_Id, Base_Type (T));
14710 if Is_Signed_Integer_Type (T) then
14711 Set_Ekind (Def_Id, E_Signed_Integer_Subtype);
14713 elsif Is_Modular_Integer_Type (T) then
14714 Set_Ekind (Def_Id, E_Modular_Integer_Subtype);
14717 Set_Ekind (Def_Id, E_Enumeration_Subtype);
14718 Set_Is_Character_Type (Def_Id, Is_Character_Type (T));
14719 Set_First_Literal (Def_Id, First_Literal (T));
14722 Set_Size_Info (Def_Id, (T));
14723 Set_RM_Size (Def_Id, RM_Size (T));
14724 Set_First_Rep_Item (Def_Id, First_Rep_Item (T));
14726 Set_Scalar_Range (Def_Id, R);
14727 Conditional_Delay (Def_Id, T);
14729 -- In the subtype indication case, if the immediate parent of the
14730 -- new subtype is non-static, then the subtype we create is non-
14731 -- static, even if its bounds are static.
14733 if Nkind (I) = N_Subtype_Indication
14734 and then not Is_Static_Subtype (Entity (Subtype_Mark (I)))
14736 Set_Is_Non_Static_Subtype (Def_Id);
14740 -- Final step is to label the index with this constructed type
14742 Set_Etype (I, Def_Id);
14745 ------------------------------
14746 -- Modular_Type_Declaration --
14747 ------------------------------
14749 procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id) is
14750 Mod_Expr : constant Node_Id := Expression (Def);
14753 procedure Set_Modular_Size (Bits : Int);
14754 -- Sets RM_Size to Bits, and Esize to normal word size above this
14756 ----------------------
14757 -- Set_Modular_Size --
14758 ----------------------
14760 procedure Set_Modular_Size (Bits : Int) is
14762 Set_RM_Size (T, UI_From_Int (Bits));
14767 elsif Bits <= 16 then
14768 Init_Esize (T, 16);
14770 elsif Bits <= 32 then
14771 Init_Esize (T, 32);
14774 Init_Esize (T, System_Max_Binary_Modulus_Power);
14776 end Set_Modular_Size;
14778 -- Start of processing for Modular_Type_Declaration
14781 Analyze_And_Resolve (Mod_Expr, Any_Integer);
14783 Set_Ekind (T, E_Modular_Integer_Type);
14784 Init_Alignment (T);
14785 Set_Is_Constrained (T);
14787 if not Is_OK_Static_Expression (Mod_Expr) then
14788 Flag_Non_Static_Expr
14789 ("non-static expression used for modular type bound!", Mod_Expr);
14790 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14792 M_Val := Expr_Value (Mod_Expr);
14796 Error_Msg_N ("modulus value must be positive", Mod_Expr);
14797 M_Val := 2 ** System_Max_Binary_Modulus_Power;
14800 Set_Modulus (T, M_Val);
14802 -- Create bounds for the modular type based on the modulus given in
14803 -- the type declaration and then analyze and resolve those bounds.
14805 Set_Scalar_Range (T,
14806 Make_Range (Sloc (Mod_Expr),
14808 Make_Integer_Literal (Sloc (Mod_Expr), 0),
14810 Make_Integer_Literal (Sloc (Mod_Expr), M_Val - 1)));
14812 -- Properly analyze the literals for the range. We do this manually
14813 -- because we can't go calling Resolve, since we are resolving these
14814 -- bounds with the type, and this type is certainly not complete yet!
14816 Set_Etype (Low_Bound (Scalar_Range (T)), T);
14817 Set_Etype (High_Bound (Scalar_Range (T)), T);
14818 Set_Is_Static_Expression (Low_Bound (Scalar_Range (T)));
14819 Set_Is_Static_Expression (High_Bound (Scalar_Range (T)));
14821 -- Loop through powers of two to find number of bits required
14823 for Bits in Int range 0 .. System_Max_Binary_Modulus_Power loop
14827 if M_Val = 2 ** Bits then
14828 Set_Modular_Size (Bits);
14833 elsif M_Val < 2 ** Bits then
14834 Set_Non_Binary_Modulus (T);
14836 if Bits > System_Max_Nonbinary_Modulus_Power then
14837 Error_Msg_Uint_1 :=
14838 UI_From_Int (System_Max_Nonbinary_Modulus_Power);
14840 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr);
14841 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14845 -- In the non-binary case, set size as per RM 13.3(55)
14847 Set_Modular_Size (Bits);
14854 -- If we fall through, then the size exceed System.Max_Binary_Modulus
14855 -- so we just signal an error and set the maximum size.
14857 Error_Msg_Uint_1 := UI_From_Int (System_Max_Binary_Modulus_Power);
14858 Error_Msg_F ("modulus exceeds limit (2 '*'*^)", Mod_Expr);
14860 Set_Modular_Size (System_Max_Binary_Modulus_Power);
14861 Init_Alignment (T);
14863 end Modular_Type_Declaration;
14865 --------------------------
14866 -- New_Concatenation_Op --
14867 --------------------------
14869 procedure New_Concatenation_Op (Typ : Entity_Id) is
14870 Loc : constant Source_Ptr := Sloc (Typ);
14873 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id;
14874 -- Create abbreviated declaration for the formal of a predefined
14875 -- Operator 'Op' of type 'Typ'
14877 --------------------
14878 -- Make_Op_Formal --
14879 --------------------
14881 function Make_Op_Formal (Typ, Op : Entity_Id) return Entity_Id is
14882 Formal : Entity_Id;
14884 Formal := New_Internal_Entity (E_In_Parameter, Op, Loc, 'P');
14885 Set_Etype (Formal, Typ);
14886 Set_Mechanism (Formal, Default_Mechanism);
14888 end Make_Op_Formal;
14890 -- Start of processing for New_Concatenation_Op
14893 Op := Make_Defining_Operator_Symbol (Loc, Name_Op_Concat);
14895 Set_Ekind (Op, E_Operator);
14896 Set_Scope (Op, Current_Scope);
14897 Set_Etype (Op, Typ);
14898 Set_Homonym (Op, Get_Name_Entity_Id (Name_Op_Concat));
14899 Set_Is_Immediately_Visible (Op);
14900 Set_Is_Intrinsic_Subprogram (Op);
14901 Set_Has_Completion (Op);
14902 Append_Entity (Op, Current_Scope);
14904 Set_Name_Entity_Id (Name_Op_Concat, Op);
14906 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14907 Append_Entity (Make_Op_Formal (Typ, Op), Op);
14908 end New_Concatenation_Op;
14910 -------------------------
14911 -- OK_For_Limited_Init --
14912 -------------------------
14914 -- ???Check all calls of this, and compare the conditions under which it's
14917 function OK_For_Limited_Init (Exp : Node_Id) return Boolean is
14919 return Ada_Version >= Ada_05
14920 and then not Debug_Flag_Dot_L
14921 and then OK_For_Limited_Init_In_05 (Exp);
14922 end OK_For_Limited_Init;
14924 -------------------------------
14925 -- OK_For_Limited_Init_In_05 --
14926 -------------------------------
14928 function OK_For_Limited_Init_In_05 (Exp : Node_Id) return Boolean is
14930 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
14931 -- case of limited aggregates (including extension aggregates), and
14932 -- function calls. The function call may have been give in prefixed
14933 -- notation, in which case the original node is an indexed component.
14935 case Nkind (Original_Node (Exp)) is
14936 when N_Aggregate | N_Extension_Aggregate | N_Function_Call | N_Op =>
14939 when N_Qualified_Expression =>
14941 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
14943 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
14944 -- with a function call, the expander has rewritten the call into an
14945 -- N_Type_Conversion node to force displacement of the pointer to
14946 -- reference the component containing the secondary dispatch table.
14947 -- Otherwise a type conversion is not a legal context.
14949 when N_Type_Conversion =>
14950 return not Comes_From_Source (Exp)
14952 OK_For_Limited_Init_In_05 (Expression (Original_Node (Exp)));
14954 when N_Indexed_Component | N_Selected_Component =>
14955 return Nkind (Exp) = N_Function_Call;
14957 -- A use of 'Input is a function call, hence allowed. Normally the
14958 -- attribute will be changed to a call, but the attribute by itself
14959 -- can occur with -gnatc.
14961 when N_Attribute_Reference =>
14962 return Attribute_Name (Original_Node (Exp)) = Name_Input;
14967 end OK_For_Limited_Init_In_05;
14969 -------------------------------------------
14970 -- Ordinary_Fixed_Point_Type_Declaration --
14971 -------------------------------------------
14973 procedure Ordinary_Fixed_Point_Type_Declaration
14977 Loc : constant Source_Ptr := Sloc (Def);
14978 Delta_Expr : constant Node_Id := Delta_Expression (Def);
14979 RRS : constant Node_Id := Real_Range_Specification (Def);
14980 Implicit_Base : Entity_Id;
14987 Check_Restriction (No_Fixed_Point, Def);
14989 -- Create implicit base type
14992 Create_Itype (E_Ordinary_Fixed_Point_Type, Parent (Def), T, 'B');
14993 Set_Etype (Implicit_Base, Implicit_Base);
14995 -- Analyze and process delta expression
14997 Analyze_And_Resolve (Delta_Expr, Any_Real);
14999 Check_Delta_Expression (Delta_Expr);
15000 Delta_Val := Expr_Value_R (Delta_Expr);
15002 Set_Delta_Value (Implicit_Base, Delta_Val);
15004 -- Compute default small from given delta, which is the largest power
15005 -- of two that does not exceed the given delta value.
15015 if Delta_Val < Ureal_1 then
15016 while Delta_Val < Tmp loop
15017 Tmp := Tmp / Ureal_2;
15018 Scale := Scale + 1;
15023 Tmp := Tmp * Ureal_2;
15024 exit when Tmp > Delta_Val;
15025 Scale := Scale - 1;
15029 Small_Val := UR_From_Components (Uint_1, UI_From_Int (Scale), 2);
15032 Set_Small_Value (Implicit_Base, Small_Val);
15034 -- If no range was given, set a dummy range
15036 if RRS <= Empty_Or_Error then
15037 Low_Val := -Small_Val;
15038 High_Val := Small_Val;
15040 -- Otherwise analyze and process given range
15044 Low : constant Node_Id := Low_Bound (RRS);
15045 High : constant Node_Id := High_Bound (RRS);
15048 Analyze_And_Resolve (Low, Any_Real);
15049 Analyze_And_Resolve (High, Any_Real);
15050 Check_Real_Bound (Low);
15051 Check_Real_Bound (High);
15053 -- Obtain and set the range
15055 Low_Val := Expr_Value_R (Low);
15056 High_Val := Expr_Value_R (High);
15058 if Low_Val > High_Val then
15059 Error_Msg_NE ("?fixed point type& has null range", Def, T);
15064 -- The range for both the implicit base and the declared first subtype
15065 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
15066 -- set a temporary range in place. Note that the bounds of the base
15067 -- type will be widened to be symmetrical and to fill the available
15068 -- bits when the type is frozen.
15070 -- We could do this with all discrete types, and probably should, but
15071 -- we absolutely have to do it for fixed-point, since the end-points
15072 -- of the range and the size are determined by the small value, which
15073 -- could be reset before the freeze point.
15075 Set_Fixed_Range (Implicit_Base, Loc, Low_Val, High_Val);
15076 Set_Fixed_Range (T, Loc, Low_Val, High_Val);
15078 -- Complete definition of first subtype
15080 Set_Ekind (T, E_Ordinary_Fixed_Point_Subtype);
15081 Set_Etype (T, Implicit_Base);
15082 Init_Size_Align (T);
15083 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
15084 Set_Small_Value (T, Small_Val);
15085 Set_Delta_Value (T, Delta_Val);
15086 Set_Is_Constrained (T);
15088 end Ordinary_Fixed_Point_Type_Declaration;
15090 ----------------------------------------
15091 -- Prepare_Private_Subtype_Completion --
15092 ----------------------------------------
15094 procedure Prepare_Private_Subtype_Completion
15096 Related_Nod : Node_Id)
15098 Id_B : constant Entity_Id := Base_Type (Id);
15099 Full_B : constant Entity_Id := Full_View (Id_B);
15103 if Present (Full_B) then
15105 -- The Base_Type is already completed, we can complete the subtype
15106 -- now. We have to create a new entity with the same name, Thus we
15107 -- can't use Create_Itype.
15109 -- This is messy, should be fixed ???
15111 Full := Make_Defining_Identifier (Sloc (Id), Chars (Id));
15112 Set_Is_Itype (Full);
15113 Set_Associated_Node_For_Itype (Full, Related_Nod);
15114 Complete_Private_Subtype (Id, Full, Full_B, Related_Nod);
15117 -- The parent subtype may be private, but the base might not, in some
15118 -- nested instances. In that case, the subtype does not need to be
15119 -- exchanged. It would still be nice to make private subtypes and their
15120 -- bases consistent at all times ???
15122 if Is_Private_Type (Id_B) then
15123 Append_Elmt (Id, Private_Dependents (Id_B));
15126 end Prepare_Private_Subtype_Completion;
15128 ---------------------------
15129 -- Process_Discriminants --
15130 ---------------------------
15132 procedure Process_Discriminants
15134 Prev : Entity_Id := Empty)
15136 Elist : constant Elist_Id := New_Elmt_List;
15139 Discr_Number : Uint;
15140 Discr_Type : Entity_Id;
15141 Default_Present : Boolean := False;
15142 Default_Not_Present : Boolean := False;
15145 -- A composite type other than an array type can have discriminants.
15146 -- On entry, the current scope is the composite type.
15148 -- The discriminants are initially entered into the scope of the type
15149 -- via Enter_Name with the default Ekind of E_Void to prevent premature
15150 -- use, as explained at the end of this procedure.
15152 Discr := First (Discriminant_Specifications (N));
15153 while Present (Discr) loop
15154 Enter_Name (Defining_Identifier (Discr));
15156 -- For navigation purposes we add a reference to the discriminant
15157 -- in the entity for the type. If the current declaration is a
15158 -- completion, place references on the partial view. Otherwise the
15159 -- type is the current scope.
15161 if Present (Prev) then
15163 -- The references go on the partial view, if present. If the
15164 -- partial view has discriminants, the references have been
15165 -- generated already.
15167 if not Has_Discriminants (Prev) then
15168 Generate_Reference (Prev, Defining_Identifier (Discr), 'd');
15172 (Current_Scope, Defining_Identifier (Discr), 'd');
15175 if Nkind (Discriminant_Type (Discr)) = N_Access_Definition then
15176 Discr_Type := Access_Definition (Discr, Discriminant_Type (Discr));
15178 -- Ada 2005 (AI-254)
15180 if Present (Access_To_Subprogram_Definition
15181 (Discriminant_Type (Discr)))
15182 and then Protected_Present (Access_To_Subprogram_Definition
15183 (Discriminant_Type (Discr)))
15186 Replace_Anonymous_Access_To_Protected_Subprogram (Discr);
15190 Find_Type (Discriminant_Type (Discr));
15191 Discr_Type := Etype (Discriminant_Type (Discr));
15193 if Error_Posted (Discriminant_Type (Discr)) then
15194 Discr_Type := Any_Type;
15198 if Is_Access_Type (Discr_Type) then
15200 -- Ada 2005 (AI-230): Access discriminant allowed in non-limited
15203 if Ada_Version < Ada_05 then
15204 Check_Access_Discriminant_Requires_Limited
15205 (Discr, Discriminant_Type (Discr));
15208 if Ada_Version = Ada_83 and then Comes_From_Source (Discr) then
15210 ("(Ada 83) access discriminant not allowed", Discr);
15213 elsif not Is_Discrete_Type (Discr_Type) then
15214 Error_Msg_N ("discriminants must have a discrete or access type",
15215 Discriminant_Type (Discr));
15218 Set_Etype (Defining_Identifier (Discr), Discr_Type);
15220 -- If a discriminant specification includes the assignment compound
15221 -- delimiter followed by an expression, the expression is the default
15222 -- expression of the discriminant; the default expression must be of
15223 -- the type of the discriminant. (RM 3.7.1) Since this expression is
15224 -- a default expression, we do the special preanalysis, since this
15225 -- expression does not freeze (see "Handling of Default and Per-
15226 -- Object Expressions" in spec of package Sem).
15228 if Present (Expression (Discr)) then
15229 Preanalyze_Spec_Expression (Expression (Discr), Discr_Type);
15231 if Nkind (N) = N_Formal_Type_Declaration then
15233 ("discriminant defaults not allowed for formal type",
15234 Expression (Discr));
15236 -- Tagged types cannot have defaulted discriminants, but a
15237 -- non-tagged private type with defaulted discriminants
15238 -- can have a tagged completion.
15240 elsif Is_Tagged_Type (Current_Scope)
15241 and then Comes_From_Source (N)
15244 ("discriminants of tagged type cannot have defaults",
15245 Expression (Discr));
15248 Default_Present := True;
15249 Append_Elmt (Expression (Discr), Elist);
15251 -- Tag the defining identifiers for the discriminants with
15252 -- their corresponding default expressions from the tree.
15254 Set_Discriminant_Default_Value
15255 (Defining_Identifier (Discr), Expression (Discr));
15259 Default_Not_Present := True;
15262 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
15263 -- Discr_Type but with the null-exclusion attribute
15265 if Ada_Version >= Ada_05 then
15267 -- Ada 2005 (AI-231): Static checks
15269 if Can_Never_Be_Null (Discr_Type) then
15270 Null_Exclusion_Static_Checks (Discr);
15272 elsif Is_Access_Type (Discr_Type)
15273 and then Null_Exclusion_Present (Discr)
15275 -- No need to check itypes because in their case this check
15276 -- was done at their point of creation
15278 and then not Is_Itype (Discr_Type)
15280 if Can_Never_Be_Null (Discr_Type) then
15282 ("`NOT NULL` not allowed (& already excludes null)",
15287 Set_Etype (Defining_Identifier (Discr),
15288 Create_Null_Excluding_Itype
15290 Related_Nod => Discr));
15293 -- Ada 2005 (AI-402): access discriminants of nonlimited types
15294 -- can't have defaults. Synchronized types, or types that are
15295 -- explicitly limited are fine, but special tests apply to derived
15296 -- types in generics: in a generic body we have to assume the
15297 -- worst, and therefore defaults are not allowed if the parent is
15298 -- a generic formal private type (see ACATS B370001).
15300 if Is_Access_Type (Discr_Type) then
15301 if Ekind (Discr_Type) /= E_Anonymous_Access_Type
15302 or else not Default_Present
15303 or else Is_Limited_Record (Current_Scope)
15304 or else Is_Concurrent_Type (Current_Scope)
15305 or else Is_Concurrent_Record_Type (Current_Scope)
15306 or else Ekind (Current_Scope) = E_Limited_Private_Type
15308 if not Is_Derived_Type (Current_Scope)
15309 or else not Is_Generic_Type (Etype (Current_Scope))
15310 or else not In_Package_Body (Scope (Etype (Current_Scope)))
15311 or else Limited_Present
15312 (Type_Definition (Parent (Current_Scope)))
15317 Error_Msg_N ("access discriminants of nonlimited types",
15318 Expression (Discr));
15319 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15322 elsif Present (Expression (Discr)) then
15324 ("(Ada 2005) access discriminants of nonlimited types",
15325 Expression (Discr));
15326 Error_Msg_N ("\cannot have defaults", Expression (Discr));
15334 -- An element list consisting of the default expressions of the
15335 -- discriminants is constructed in the above loop and used to set
15336 -- the Discriminant_Constraint attribute for the type. If an object
15337 -- is declared of this (record or task) type without any explicit
15338 -- discriminant constraint given, this element list will form the
15339 -- actual parameters for the corresponding initialization procedure
15342 Set_Discriminant_Constraint (Current_Scope, Elist);
15343 Set_Stored_Constraint (Current_Scope, No_Elist);
15345 -- Default expressions must be provided either for all or for none
15346 -- of the discriminants of a discriminant part. (RM 3.7.1)
15348 if Default_Present and then Default_Not_Present then
15350 ("incomplete specification of defaults for discriminants", N);
15353 -- The use of the name of a discriminant is not allowed in default
15354 -- expressions of a discriminant part if the specification of the
15355 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
15357 -- To detect this, the discriminant names are entered initially with an
15358 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
15359 -- attempt to use a void entity (for example in an expression that is
15360 -- type-checked) produces the error message: premature usage. Now after
15361 -- completing the semantic analysis of the discriminant part, we can set
15362 -- the Ekind of all the discriminants appropriately.
15364 Discr := First (Discriminant_Specifications (N));
15365 Discr_Number := Uint_1;
15366 while Present (Discr) loop
15367 Id := Defining_Identifier (Discr);
15368 Set_Ekind (Id, E_Discriminant);
15369 Init_Component_Location (Id);
15371 Set_Discriminant_Number (Id, Discr_Number);
15373 -- Make sure this is always set, even in illegal programs
15375 Set_Corresponding_Discriminant (Id, Empty);
15377 -- Initialize the Original_Record_Component to the entity itself.
15378 -- Inherit_Components will propagate the right value to
15379 -- discriminants in derived record types.
15381 Set_Original_Record_Component (Id, Id);
15383 -- Create the discriminal for the discriminant
15385 Build_Discriminal (Id);
15388 Discr_Number := Discr_Number + 1;
15391 Set_Has_Discriminants (Current_Scope);
15392 end Process_Discriminants;
15394 -----------------------
15395 -- Process_Full_View --
15396 -----------------------
15398 procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id) is
15399 Priv_Parent : Entity_Id;
15400 Full_Parent : Entity_Id;
15401 Full_Indic : Node_Id;
15403 procedure Collect_Implemented_Interfaces
15405 Ifaces : Elist_Id);
15406 -- Ada 2005: Gather all the interfaces that Typ directly or
15407 -- inherently implements. Duplicate entries are not added to
15408 -- the list Ifaces.
15410 ------------------------------------
15411 -- Collect_Implemented_Interfaces --
15412 ------------------------------------
15414 procedure Collect_Implemented_Interfaces
15419 Iface_Elmt : Elmt_Id;
15422 -- Abstract interfaces are only associated with tagged record types
15424 if not Is_Tagged_Type (Typ)
15425 or else not Is_Record_Type (Typ)
15430 -- Recursively climb to the ancestors
15432 if Etype (Typ) /= Typ
15434 -- Protect the frontend against wrong cyclic declarations like:
15436 -- type B is new A with private;
15437 -- type C is new A with private;
15439 -- type B is new C with null record;
15440 -- type C is new B with null record;
15442 and then Etype (Typ) /= Priv_T
15443 and then Etype (Typ) /= Full_T
15445 -- Keep separate the management of private type declarations
15447 if Ekind (Typ) = E_Record_Type_With_Private then
15449 -- Handle the following erronous case:
15450 -- type Private_Type is tagged private;
15452 -- type Private_Type is new Type_Implementing_Iface;
15454 if Present (Full_View (Typ))
15455 and then Etype (Typ) /= Full_View (Typ)
15457 if Is_Interface (Etype (Typ)) then
15458 Append_Unique_Elmt (Etype (Typ), Ifaces);
15461 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15464 -- Non-private types
15467 if Is_Interface (Etype (Typ)) then
15468 Append_Unique_Elmt (Etype (Typ), Ifaces);
15471 Collect_Implemented_Interfaces (Etype (Typ), Ifaces);
15475 -- Handle entities in the list of abstract interfaces
15477 if Present (Interfaces (Typ)) then
15478 Iface_Elmt := First_Elmt (Interfaces (Typ));
15479 while Present (Iface_Elmt) loop
15480 Iface := Node (Iface_Elmt);
15482 pragma Assert (Is_Interface (Iface));
15484 if not Contain_Interface (Iface, Ifaces) then
15485 Append_Elmt (Iface, Ifaces);
15486 Collect_Implemented_Interfaces (Iface, Ifaces);
15489 Next_Elmt (Iface_Elmt);
15492 end Collect_Implemented_Interfaces;
15494 -- Start of processing for Process_Full_View
15497 -- First some sanity checks that must be done after semantic
15498 -- decoration of the full view and thus cannot be placed with other
15499 -- similar checks in Find_Type_Name
15501 if not Is_Limited_Type (Priv_T)
15502 and then (Is_Limited_Type (Full_T)
15503 or else Is_Limited_Composite (Full_T))
15506 ("completion of nonlimited type cannot be limited", Full_T);
15507 Explain_Limited_Type (Full_T, Full_T);
15509 elsif Is_Abstract_Type (Full_T)
15510 and then not Is_Abstract_Type (Priv_T)
15513 ("completion of nonabstract type cannot be abstract", Full_T);
15515 elsif Is_Tagged_Type (Priv_T)
15516 and then Is_Limited_Type (Priv_T)
15517 and then not Is_Limited_Type (Full_T)
15519 -- If pragma CPP_Class was applied to the private declaration
15520 -- propagate the limitedness to the full-view
15522 if Is_CPP_Class (Priv_T) then
15523 Set_Is_Limited_Record (Full_T);
15525 -- GNAT allow its own definition of Limited_Controlled to disobey
15526 -- this rule in order in ease the implementation. The next test is
15527 -- safe because Root_Controlled is defined in a private system child
15529 elsif Etype (Full_T) = Full_View (RTE (RE_Root_Controlled)) then
15530 Set_Is_Limited_Composite (Full_T);
15533 ("completion of limited tagged type must be limited", Full_T);
15536 elsif Is_Generic_Type (Priv_T) then
15537 Error_Msg_N ("generic type cannot have a completion", Full_T);
15540 -- Check that ancestor interfaces of private and full views are
15541 -- consistent. We omit this check for synchronized types because
15542 -- they are performed on the corresponding record type when frozen.
15544 if Ada_Version >= Ada_05
15545 and then Is_Tagged_Type (Priv_T)
15546 and then Is_Tagged_Type (Full_T)
15547 and then not Is_Concurrent_Type (Full_T)
15551 Priv_T_Ifaces : constant Elist_Id := New_Elmt_List;
15552 Full_T_Ifaces : constant Elist_Id := New_Elmt_List;
15555 Collect_Implemented_Interfaces (Priv_T, Priv_T_Ifaces);
15556 Collect_Implemented_Interfaces (Full_T, Full_T_Ifaces);
15558 -- Ada 2005 (AI-251): The partial view shall be a descendant of
15559 -- an interface type if and only if the full type is descendant
15560 -- of the interface type (AARM 7.3 (7.3/2).
15562 Iface := Find_Hidden_Interface (Priv_T_Ifaces, Full_T_Ifaces);
15564 if Present (Iface) then
15565 Error_Msg_NE ("interface & not implemented by full type " &
15566 "(RM-2005 7.3 (7.3/2))", Priv_T, Iface);
15569 Iface := Find_Hidden_Interface (Full_T_Ifaces, Priv_T_Ifaces);
15571 if Present (Iface) then
15572 Error_Msg_NE ("interface & not implemented by partial view " &
15573 "(RM-2005 7.3 (7.3/2))", Full_T, Iface);
15578 if Is_Tagged_Type (Priv_T)
15579 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15580 and then Is_Derived_Type (Full_T)
15582 Priv_Parent := Etype (Priv_T);
15584 -- The full view of a private extension may have been transformed
15585 -- into an unconstrained derived type declaration and a subtype
15586 -- declaration (see build_derived_record_type for details).
15588 if Nkind (N) = N_Subtype_Declaration then
15589 Full_Indic := Subtype_Indication (N);
15590 Full_Parent := Etype (Base_Type (Full_T));
15592 Full_Indic := Subtype_Indication (Type_Definition (N));
15593 Full_Parent := Etype (Full_T);
15596 -- Check that the parent type of the full type is a descendant of
15597 -- the ancestor subtype given in the private extension. If either
15598 -- entity has an Etype equal to Any_Type then we had some previous
15599 -- error situation [7.3(8)].
15601 if Priv_Parent = Any_Type or else Full_Parent = Any_Type then
15604 -- Ada 2005 (AI-251): Interfaces in the full-typ can be given in
15605 -- any order. Therefore we don't have to check that its parent must
15606 -- be a descendant of the parent of the private type declaration.
15608 elsif Is_Interface (Priv_Parent)
15609 and then Is_Interface (Full_Parent)
15613 -- Ada 2005 (AI-251): If the parent of the private type declaration
15614 -- is an interface there is no need to check that it is an ancestor
15615 -- of the associated full type declaration. The required tests for
15616 -- this case case are performed by Build_Derived_Record_Type.
15618 elsif not Is_Interface (Base_Type (Priv_Parent))
15619 and then not Is_Ancestor (Base_Type (Priv_Parent), Full_Parent)
15622 ("parent of full type must descend from parent"
15623 & " of private extension", Full_Indic);
15625 -- Check the rules of 7.3(10): if the private extension inherits
15626 -- known discriminants, then the full type must also inherit those
15627 -- discriminants from the same (ancestor) type, and the parent
15628 -- subtype of the full type must be constrained if and only if
15629 -- the ancestor subtype of the private extension is constrained.
15631 elsif No (Discriminant_Specifications (Parent (Priv_T)))
15632 and then not Has_Unknown_Discriminants (Priv_T)
15633 and then Has_Discriminants (Base_Type (Priv_Parent))
15636 Priv_Indic : constant Node_Id :=
15637 Subtype_Indication (Parent (Priv_T));
15639 Priv_Constr : constant Boolean :=
15640 Is_Constrained (Priv_Parent)
15642 Nkind (Priv_Indic) = N_Subtype_Indication
15643 or else Is_Constrained (Entity (Priv_Indic));
15645 Full_Constr : constant Boolean :=
15646 Is_Constrained (Full_Parent)
15648 Nkind (Full_Indic) = N_Subtype_Indication
15649 or else Is_Constrained (Entity (Full_Indic));
15651 Priv_Discr : Entity_Id;
15652 Full_Discr : Entity_Id;
15655 Priv_Discr := First_Discriminant (Priv_Parent);
15656 Full_Discr := First_Discriminant (Full_Parent);
15657 while Present (Priv_Discr) and then Present (Full_Discr) loop
15658 if Original_Record_Component (Priv_Discr) =
15659 Original_Record_Component (Full_Discr)
15661 Corresponding_Discriminant (Priv_Discr) =
15662 Corresponding_Discriminant (Full_Discr)
15669 Next_Discriminant (Priv_Discr);
15670 Next_Discriminant (Full_Discr);
15673 if Present (Priv_Discr) or else Present (Full_Discr) then
15675 ("full view must inherit discriminants of the parent type"
15676 & " used in the private extension", Full_Indic);
15678 elsif Priv_Constr and then not Full_Constr then
15680 ("parent subtype of full type must be constrained",
15683 elsif Full_Constr and then not Priv_Constr then
15685 ("parent subtype of full type must be unconstrained",
15690 -- Check the rules of 7.3(12): if a partial view has neither known
15691 -- or unknown discriminants, then the full type declaration shall
15692 -- define a definite subtype.
15694 elsif not Has_Unknown_Discriminants (Priv_T)
15695 and then not Has_Discriminants (Priv_T)
15696 and then not Is_Constrained (Full_T)
15699 ("full view must define a constrained type if partial view"
15700 & " has no discriminants", Full_T);
15703 -- ??????? Do we implement the following properly ?????
15704 -- If the ancestor subtype of a private extension has constrained
15705 -- discriminants, then the parent subtype of the full view shall
15706 -- impose a statically matching constraint on those discriminants
15710 -- For untagged types, verify that a type without discriminants
15711 -- is not completed with an unconstrained type.
15713 if not Is_Indefinite_Subtype (Priv_T)
15714 and then Is_Indefinite_Subtype (Full_T)
15716 Error_Msg_N ("full view of type must be definite subtype", Full_T);
15720 -- AI-419: verify that the use of "limited" is consistent
15723 Orig_Decl : constant Node_Id := Original_Node (N);
15726 if Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15727 and then not Limited_Present (Parent (Priv_T))
15728 and then not Synchronized_Present (Parent (Priv_T))
15729 and then Nkind (Orig_Decl) = N_Full_Type_Declaration
15731 (Type_Definition (Orig_Decl)) = N_Derived_Type_Definition
15732 and then Limited_Present (Type_Definition (Orig_Decl))
15735 ("full view of non-limited extension cannot be limited", N);
15739 -- Ada 2005 (AI-443): A synchronized private extension must be
15740 -- completed by a task or protected type.
15742 if Ada_Version >= Ada_05
15743 and then Nkind (Parent (Priv_T)) = N_Private_Extension_Declaration
15744 and then Synchronized_Present (Parent (Priv_T))
15745 and then not Is_Concurrent_Type (Full_T)
15747 Error_Msg_N ("full view of synchronized extension must " &
15748 "be synchronized type", N);
15751 -- Ada 2005 AI-363: if the full view has discriminants with
15752 -- defaults, it is illegal to declare constrained access subtypes
15753 -- whose designated type is the current type. This allows objects
15754 -- of the type that are declared in the heap to be unconstrained.
15756 if not Has_Unknown_Discriminants (Priv_T)
15757 and then not Has_Discriminants (Priv_T)
15758 and then Has_Discriminants (Full_T)
15760 Present (Discriminant_Default_Value (First_Discriminant (Full_T)))
15762 Set_Has_Constrained_Partial_View (Full_T);
15763 Set_Has_Constrained_Partial_View (Priv_T);
15766 -- Create a full declaration for all its subtypes recorded in
15767 -- Private_Dependents and swap them similarly to the base type. These
15768 -- are subtypes that have been define before the full declaration of
15769 -- the private type. We also swap the entry in Private_Dependents list
15770 -- so we can properly restore the private view on exit from the scope.
15773 Priv_Elmt : Elmt_Id;
15778 Priv_Elmt := First_Elmt (Private_Dependents (Priv_T));
15779 while Present (Priv_Elmt) loop
15780 Priv := Node (Priv_Elmt);
15782 if Ekind (Priv) = E_Private_Subtype
15783 or else Ekind (Priv) = E_Limited_Private_Subtype
15784 or else Ekind (Priv) = E_Record_Subtype_With_Private
15786 Full := Make_Defining_Identifier (Sloc (Priv), Chars (Priv));
15787 Set_Is_Itype (Full);
15788 Set_Parent (Full, Parent (Priv));
15789 Set_Associated_Node_For_Itype (Full, N);
15791 -- Now we need to complete the private subtype, but since the
15792 -- base type has already been swapped, we must also swap the
15793 -- subtypes (and thus, reverse the arguments in the call to
15794 -- Complete_Private_Subtype).
15796 Copy_And_Swap (Priv, Full);
15797 Complete_Private_Subtype (Full, Priv, Full_T, N);
15798 Replace_Elmt (Priv_Elmt, Full);
15801 Next_Elmt (Priv_Elmt);
15805 -- If the private view was tagged, copy the new primitive operations
15806 -- from the private view to the full view.
15808 -- Note: Subprograms covering interface primitives were previously
15809 -- propagated to the full view by Derive_Progenitor_Primitives
15811 if Is_Tagged_Type (Full_T)
15812 and then not Is_Concurrent_Type (Full_T)
15815 Priv_List : Elist_Id;
15816 Full_List : constant Elist_Id := Primitive_Operations (Full_T);
15819 D_Type : Entity_Id;
15822 if Is_Tagged_Type (Priv_T) then
15823 Priv_List := Primitive_Operations (Priv_T);
15825 P1 := First_Elmt (Priv_List);
15826 while Present (P1) loop
15829 -- Transfer explicit primitives, not those inherited from
15830 -- parent of partial view, which will be re-inherited on
15833 if Comes_From_Source (Prim) then
15834 P2 := First_Elmt (Full_List);
15835 while Present (P2) and then Node (P2) /= Prim loop
15839 -- If not found, that is a new one
15842 Append_Elmt (Prim, Full_List);
15850 -- In this case the partial view is untagged, so here we locate
15851 -- all of the earlier primitives that need to be treated as
15852 -- dispatching (those that appear between the two views). Note
15853 -- that these additional operations must all be new operations
15854 -- (any earlier operations that override inherited operations
15855 -- of the full view will already have been inserted in the
15856 -- primitives list, marked by Check_Operation_From_Private_View
15857 -- as dispatching. Note that implicit "/=" operators are
15858 -- excluded from being added to the primitives list since they
15859 -- shouldn't be treated as dispatching (tagged "/=" is handled
15862 Prim := Next_Entity (Full_T);
15863 while Present (Prim) and then Prim /= Priv_T loop
15864 if Ekind (Prim) = E_Procedure
15866 Ekind (Prim) = E_Function
15869 D_Type := Find_Dispatching_Type (Prim);
15872 and then (Chars (Prim) /= Name_Op_Ne
15873 or else Comes_From_Source (Prim))
15875 Check_Controlling_Formals (Full_T, Prim);
15877 if not Is_Dispatching_Operation (Prim) then
15878 Append_Elmt (Prim, Full_List);
15879 Set_Is_Dispatching_Operation (Prim, True);
15880 Set_DT_Position (Prim, No_Uint);
15883 elsif Is_Dispatching_Operation (Prim)
15884 and then D_Type /= Full_T
15887 -- Verify that it is not otherwise controlled by a
15888 -- formal or a return value of type T.
15890 Check_Controlling_Formals (D_Type, Prim);
15894 Next_Entity (Prim);
15898 -- For the tagged case, the two views can share the same
15899 -- Primitive Operation list and the same class wide type.
15900 -- Update attributes of the class-wide type which depend on
15901 -- the full declaration.
15903 if Is_Tagged_Type (Priv_T) then
15904 Set_Primitive_Operations (Priv_T, Full_List);
15905 Set_Class_Wide_Type
15906 (Base_Type (Full_T), Class_Wide_Type (Priv_T));
15908 Set_Has_Task (Class_Wide_Type (Priv_T), Has_Task (Full_T));
15913 -- Ada 2005 AI 161: Check preelaboratable initialization consistency
15915 if Known_To_Have_Preelab_Init (Priv_T) then
15917 -- Case where there is a pragma Preelaborable_Initialization. We
15918 -- always allow this in predefined units, which is a bit of a kludge,
15919 -- but it means we don't have to struggle to meet the requirements in
15920 -- the RM for having Preelaborable Initialization. Otherwise we
15921 -- require that the type meets the RM rules. But we can't check that
15922 -- yet, because of the rule about overriding Ininitialize, so we
15923 -- simply set a flag that will be checked at freeze time.
15925 if not In_Predefined_Unit (Full_T) then
15926 Set_Must_Have_Preelab_Init (Full_T);
15930 -- If pragma CPP_Class was applied to the private type declaration,
15931 -- propagate it now to the full type declaration.
15933 if Is_CPP_Class (Priv_T) then
15934 Set_Is_CPP_Class (Full_T);
15935 Set_Convention (Full_T, Convention_CPP);
15937 end Process_Full_View;
15939 -----------------------------------
15940 -- Process_Incomplete_Dependents --
15941 -----------------------------------
15943 procedure Process_Incomplete_Dependents
15945 Full_T : Entity_Id;
15948 Inc_Elmt : Elmt_Id;
15949 Priv_Dep : Entity_Id;
15950 New_Subt : Entity_Id;
15952 Disc_Constraint : Elist_Id;
15955 if No (Private_Dependents (Inc_T)) then
15959 -- Itypes that may be generated by the completion of an incomplete
15960 -- subtype are not used by the back-end and not attached to the tree.
15961 -- They are created only for constraint-checking purposes.
15963 Inc_Elmt := First_Elmt (Private_Dependents (Inc_T));
15964 while Present (Inc_Elmt) loop
15965 Priv_Dep := Node (Inc_Elmt);
15967 if Ekind (Priv_Dep) = E_Subprogram_Type then
15969 -- An Access_To_Subprogram type may have a return type or a
15970 -- parameter type that is incomplete. Replace with the full view.
15972 if Etype (Priv_Dep) = Inc_T then
15973 Set_Etype (Priv_Dep, Full_T);
15977 Formal : Entity_Id;
15980 Formal := First_Formal (Priv_Dep);
15981 while Present (Formal) loop
15982 if Etype (Formal) = Inc_T then
15983 Set_Etype (Formal, Full_T);
15986 Next_Formal (Formal);
15990 elsif Is_Overloadable (Priv_Dep) then
15992 -- A protected operation is never dispatching: only its
15993 -- wrapper operation (which has convention Ada) is.
15995 if Is_Tagged_Type (Full_T)
15996 and then Convention (Priv_Dep) /= Convention_Protected
15999 -- Subprogram has an access parameter whose designated type
16000 -- was incomplete. Reexamine declaration now, because it may
16001 -- be a primitive operation of the full type.
16003 Check_Operation_From_Incomplete_Type (Priv_Dep, Inc_T);
16004 Set_Is_Dispatching_Operation (Priv_Dep);
16005 Check_Controlling_Formals (Full_T, Priv_Dep);
16008 elsif Ekind (Priv_Dep) = E_Subprogram_Body then
16010 -- Can happen during processing of a body before the completion
16011 -- of a TA type. Ignore, because spec is also on dependent list.
16015 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
16016 -- corresponding subtype of the full view.
16018 elsif Ekind (Priv_Dep) = E_Incomplete_Subtype then
16019 Set_Subtype_Indication
16020 (Parent (Priv_Dep), New_Reference_To (Full_T, Sloc (Priv_Dep)));
16021 Set_Etype (Priv_Dep, Full_T);
16022 Set_Ekind (Priv_Dep, Subtype_Kind (Ekind (Full_T)));
16023 Set_Analyzed (Parent (Priv_Dep), False);
16025 -- Reanalyze the declaration, suppressing the call to
16026 -- Enter_Name to avoid duplicate names.
16028 Analyze_Subtype_Declaration
16029 (N => Parent (Priv_Dep),
16032 -- Dependent is a subtype
16035 -- We build a new subtype indication using the full view of the
16036 -- incomplete parent. The discriminant constraints have been
16037 -- elaborated already at the point of the subtype declaration.
16039 New_Subt := Create_Itype (E_Void, N);
16041 if Has_Discriminants (Full_T) then
16042 Disc_Constraint := Discriminant_Constraint (Priv_Dep);
16044 Disc_Constraint := No_Elist;
16047 Build_Discriminated_Subtype (Full_T, New_Subt, Disc_Constraint, N);
16048 Set_Full_View (Priv_Dep, New_Subt);
16051 Next_Elmt (Inc_Elmt);
16053 end Process_Incomplete_Dependents;
16055 --------------------------------
16056 -- Process_Range_Expr_In_Decl --
16057 --------------------------------
16059 procedure Process_Range_Expr_In_Decl
16062 Check_List : List_Id := Empty_List;
16063 R_Check_Off : Boolean := False)
16066 R_Checks : Check_Result;
16067 Type_Decl : Node_Id;
16068 Def_Id : Entity_Id;
16071 Analyze_And_Resolve (R, Base_Type (T));
16073 if Nkind (R) = N_Range then
16074 Lo := Low_Bound (R);
16075 Hi := High_Bound (R);
16077 -- We need to ensure validity of the bounds here, because if we
16078 -- go ahead and do the expansion, then the expanded code will get
16079 -- analyzed with range checks suppressed and we miss the check.
16081 Validity_Check_Range (R);
16083 -- If there were errors in the declaration, try and patch up some
16084 -- common mistakes in the bounds. The cases handled are literals
16085 -- which are Integer where the expected type is Real and vice versa.
16086 -- These corrections allow the compilation process to proceed further
16087 -- along since some basic assumptions of the format of the bounds
16090 if Etype (R) = Any_Type then
16092 if Nkind (Lo) = N_Integer_Literal and then Is_Real_Type (T) then
16094 Make_Real_Literal (Sloc (Lo), UR_From_Uint (Intval (Lo))));
16096 elsif Nkind (Hi) = N_Integer_Literal and then Is_Real_Type (T) then
16098 Make_Real_Literal (Sloc (Hi), UR_From_Uint (Intval (Hi))));
16100 elsif Nkind (Lo) = N_Real_Literal and then Is_Integer_Type (T) then
16102 Make_Integer_Literal (Sloc (Lo), UR_To_Uint (Realval (Lo))));
16104 elsif Nkind (Hi) = N_Real_Literal and then Is_Integer_Type (T) then
16106 Make_Integer_Literal (Sloc (Hi), UR_To_Uint (Realval (Hi))));
16113 -- If the bounds of the range have been mistakenly given as string
16114 -- literals (perhaps in place of character literals), then an error
16115 -- has already been reported, but we rewrite the string literal as a
16116 -- bound of the range's type to avoid blowups in later processing
16117 -- that looks at static values.
16119 if Nkind (Lo) = N_String_Literal then
16121 Make_Attribute_Reference (Sloc (Lo),
16122 Attribute_Name => Name_First,
16123 Prefix => New_Reference_To (T, Sloc (Lo))));
16124 Analyze_And_Resolve (Lo);
16127 if Nkind (Hi) = N_String_Literal then
16129 Make_Attribute_Reference (Sloc (Hi),
16130 Attribute_Name => Name_First,
16131 Prefix => New_Reference_To (T, Sloc (Hi))));
16132 Analyze_And_Resolve (Hi);
16135 -- If bounds aren't scalar at this point then exit, avoiding
16136 -- problems with further processing of the range in this procedure.
16138 if not Is_Scalar_Type (Etype (Lo)) then
16142 -- Resolve (actually Sem_Eval) has checked that the bounds are in
16143 -- then range of the base type. Here we check whether the bounds
16144 -- are in the range of the subtype itself. Note that if the bounds
16145 -- represent the null range the Constraint_Error exception should
16148 -- ??? The following code should be cleaned up as follows
16150 -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
16151 -- is done in the call to Range_Check (R, T); below
16153 -- 2. The use of R_Check_Off should be investigated and possibly
16154 -- removed, this would clean up things a bit.
16156 if Is_Null_Range (Lo, Hi) then
16160 -- Capture values of bounds and generate temporaries for them
16161 -- if needed, before applying checks, since checks may cause
16162 -- duplication of the expression without forcing evaluation.
16164 if Expander_Active then
16165 Force_Evaluation (Lo);
16166 Force_Evaluation (Hi);
16169 -- We use a flag here instead of suppressing checks on the
16170 -- type because the type we check against isn't necessarily
16171 -- the place where we put the check.
16173 if not R_Check_Off then
16174 R_Checks := Get_Range_Checks (R, T);
16176 -- Look up tree to find an appropriate insertion point.
16177 -- This seems really junk code, and very brittle, couldn't
16178 -- we just use an insert actions call of some kind ???
16180 Type_Decl := Parent (R);
16181 while Present (Type_Decl) and then not
16182 (Nkind_In (Type_Decl, N_Full_Type_Declaration,
16183 N_Subtype_Declaration,
16185 N_Task_Type_Declaration)
16187 Nkind_In (Type_Decl, N_Single_Task_Declaration,
16188 N_Protected_Type_Declaration,
16189 N_Single_Protected_Declaration))
16191 Type_Decl := Parent (Type_Decl);
16194 -- Why would Type_Decl not be present??? Without this test,
16195 -- short regression tests fail.
16197 if Present (Type_Decl) then
16199 -- Case of loop statement (more comments ???)
16201 if Nkind (Type_Decl) = N_Loop_Statement then
16206 Indic := Parent (R);
16207 while Present (Indic)
16208 and then Nkind (Indic) /= N_Subtype_Indication
16210 Indic := Parent (Indic);
16213 if Present (Indic) then
16214 Def_Id := Etype (Subtype_Mark (Indic));
16216 Insert_Range_Checks
16222 Do_Before => True);
16226 -- All other cases (more comments ???)
16229 Def_Id := Defining_Identifier (Type_Decl);
16231 if (Ekind (Def_Id) = E_Record_Type
16232 and then Depends_On_Discriminant (R))
16234 (Ekind (Def_Id) = E_Protected_Type
16235 and then Has_Discriminants (Def_Id))
16237 Append_Range_Checks
16238 (R_Checks, Check_List, Def_Id, Sloc (Type_Decl), R);
16241 Insert_Range_Checks
16242 (R_Checks, Type_Decl, Def_Id, Sloc (Type_Decl), R);
16250 elsif Expander_Active then
16251 Get_Index_Bounds (R, Lo, Hi);
16252 Force_Evaluation (Lo);
16253 Force_Evaluation (Hi);
16255 end Process_Range_Expr_In_Decl;
16257 --------------------------------------
16258 -- Process_Real_Range_Specification --
16259 --------------------------------------
16261 procedure Process_Real_Range_Specification (Def : Node_Id) is
16262 Spec : constant Node_Id := Real_Range_Specification (Def);
16265 Err : Boolean := False;
16267 procedure Analyze_Bound (N : Node_Id);
16268 -- Analyze and check one bound
16270 -------------------
16271 -- Analyze_Bound --
16272 -------------------
16274 procedure Analyze_Bound (N : Node_Id) is
16276 Analyze_And_Resolve (N, Any_Real);
16278 if not Is_OK_Static_Expression (N) then
16279 Flag_Non_Static_Expr
16280 ("bound in real type definition is not static!", N);
16285 -- Start of processing for Process_Real_Range_Specification
16288 if Present (Spec) then
16289 Lo := Low_Bound (Spec);
16290 Hi := High_Bound (Spec);
16291 Analyze_Bound (Lo);
16292 Analyze_Bound (Hi);
16294 -- If error, clear away junk range specification
16297 Set_Real_Range_Specification (Def, Empty);
16300 end Process_Real_Range_Specification;
16302 ---------------------
16303 -- Process_Subtype --
16304 ---------------------
16306 function Process_Subtype
16308 Related_Nod : Node_Id;
16309 Related_Id : Entity_Id := Empty;
16310 Suffix : Character := ' ') return Entity_Id
16313 Def_Id : Entity_Id;
16314 Error_Node : Node_Id;
16315 Full_View_Id : Entity_Id;
16316 Subtype_Mark_Id : Entity_Id;
16318 May_Have_Null_Exclusion : Boolean;
16320 procedure Check_Incomplete (T : Entity_Id);
16321 -- Called to verify that an incomplete type is not used prematurely
16323 ----------------------
16324 -- Check_Incomplete --
16325 ----------------------
16327 procedure Check_Incomplete (T : Entity_Id) is
16329 -- Ada 2005 (AI-412): Incomplete subtypes are legal
16331 if Ekind (Root_Type (Entity (T))) = E_Incomplete_Type
16333 not (Ada_Version >= Ada_05
16335 (Nkind (Parent (T)) = N_Subtype_Declaration
16337 (Nkind (Parent (T)) = N_Subtype_Indication
16338 and then Nkind (Parent (Parent (T))) =
16339 N_Subtype_Declaration)))
16341 Error_Msg_N ("invalid use of type before its full declaration", T);
16343 end Check_Incomplete;
16345 -- Start of processing for Process_Subtype
16348 -- Case of no constraints present
16350 if Nkind (S) /= N_Subtype_Indication then
16352 Check_Incomplete (S);
16355 -- Ada 2005 (AI-231): Static check
16357 if Ada_Version >= Ada_05
16358 and then Present (P)
16359 and then Null_Exclusion_Present (P)
16360 and then Nkind (P) /= N_Access_To_Object_Definition
16361 and then not Is_Access_Type (Entity (S))
16363 Error_Msg_N ("`NOT NULL` only allowed for an access type", S);
16366 -- The following is ugly, can't we have a range or even a flag???
16368 May_Have_Null_Exclusion :=
16369 Nkind_In (P, N_Access_Definition,
16370 N_Access_Function_Definition,
16371 N_Access_Procedure_Definition,
16372 N_Access_To_Object_Definition,
16374 N_Component_Definition)
16376 Nkind_In (P, N_Derived_Type_Definition,
16377 N_Discriminant_Specification,
16378 N_Object_Declaration,
16379 N_Parameter_Specification,
16380 N_Subtype_Declaration);
16382 -- Create an Itype that is a duplicate of Entity (S) but with the
16383 -- null-exclusion attribute
16385 if May_Have_Null_Exclusion
16386 and then Is_Access_Type (Entity (S))
16387 and then Null_Exclusion_Present (P)
16389 -- No need to check the case of an access to object definition.
16390 -- It is correct to define double not-null pointers.
16393 -- type Not_Null_Int_Ptr is not null access Integer;
16394 -- type Acc is not null access Not_Null_Int_Ptr;
16396 and then Nkind (P) /= N_Access_To_Object_Definition
16398 if Can_Never_Be_Null (Entity (S)) then
16399 case Nkind (Related_Nod) is
16400 when N_Full_Type_Declaration =>
16401 if Nkind (Type_Definition (Related_Nod))
16402 in N_Array_Type_Definition
16406 (Component_Definition
16407 (Type_Definition (Related_Nod)));
16410 Subtype_Indication (Type_Definition (Related_Nod));
16413 when N_Subtype_Declaration =>
16414 Error_Node := Subtype_Indication (Related_Nod);
16416 when N_Object_Declaration =>
16417 Error_Node := Object_Definition (Related_Nod);
16419 when N_Component_Declaration =>
16421 Subtype_Indication (Component_Definition (Related_Nod));
16424 pragma Assert (False);
16425 Error_Node := Related_Nod;
16429 ("`NOT NULL` not allowed (& already excludes null)",
16435 Create_Null_Excluding_Itype
16437 Related_Nod => P));
16438 Set_Entity (S, Etype (S));
16443 -- Case of constraint present, so that we have an N_Subtype_Indication
16444 -- node (this node is created only if constraints are present).
16447 Find_Type (Subtype_Mark (S));
16449 if Nkind (Parent (S)) /= N_Access_To_Object_Definition
16451 (Nkind (Parent (S)) = N_Subtype_Declaration
16452 and then Is_Itype (Defining_Identifier (Parent (S))))
16454 Check_Incomplete (Subtype_Mark (S));
16458 Subtype_Mark_Id := Entity (Subtype_Mark (S));
16460 -- Explicit subtype declaration case
16462 if Nkind (P) = N_Subtype_Declaration then
16463 Def_Id := Defining_Identifier (P);
16465 -- Explicit derived type definition case
16467 elsif Nkind (P) = N_Derived_Type_Definition then
16468 Def_Id := Defining_Identifier (Parent (P));
16470 -- Implicit case, the Def_Id must be created as an implicit type.
16471 -- The one exception arises in the case of concurrent types, array
16472 -- and access types, where other subsidiary implicit types may be
16473 -- created and must appear before the main implicit type. In these
16474 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
16475 -- has not yet been called to create Def_Id.
16478 if Is_Array_Type (Subtype_Mark_Id)
16479 or else Is_Concurrent_Type (Subtype_Mark_Id)
16480 or else Is_Access_Type (Subtype_Mark_Id)
16484 -- For the other cases, we create a new unattached Itype,
16485 -- and set the indication to ensure it gets attached later.
16489 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16493 -- If the kind of constraint is invalid for this kind of type,
16494 -- then give an error, and then pretend no constraint was given.
16496 if not Is_Valid_Constraint_Kind
16497 (Ekind (Subtype_Mark_Id), Nkind (Constraint (S)))
16500 ("incorrect constraint for this kind of type", Constraint (S));
16502 Rewrite (S, New_Copy_Tree (Subtype_Mark (S)));
16504 -- Set Ekind of orphan itype, to prevent cascaded errors
16506 if Present (Def_Id) then
16507 Set_Ekind (Def_Id, Ekind (Any_Type));
16510 -- Make recursive call, having got rid of the bogus constraint
16512 return Process_Subtype (S, Related_Nod, Related_Id, Suffix);
16515 -- Remaining processing depends on type
16517 case Ekind (Subtype_Mark_Id) is
16518 when Access_Kind =>
16519 Constrain_Access (Def_Id, S, Related_Nod);
16522 and then Is_Itype (Designated_Type (Def_Id))
16523 and then Nkind (Related_Nod) = N_Subtype_Declaration
16524 and then not Is_Incomplete_Type (Designated_Type (Def_Id))
16526 Build_Itype_Reference
16527 (Designated_Type (Def_Id), Related_Nod);
16531 Constrain_Array (Def_Id, S, Related_Nod, Related_Id, Suffix);
16533 when Decimal_Fixed_Point_Kind =>
16534 Constrain_Decimal (Def_Id, S);
16536 when Enumeration_Kind =>
16537 Constrain_Enumeration (Def_Id, S);
16539 when Ordinary_Fixed_Point_Kind =>
16540 Constrain_Ordinary_Fixed (Def_Id, S);
16543 Constrain_Float (Def_Id, S);
16545 when Integer_Kind =>
16546 Constrain_Integer (Def_Id, S);
16548 when E_Record_Type |
16551 E_Incomplete_Type =>
16552 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16554 when Private_Kind =>
16555 Constrain_Discriminated_Type (Def_Id, S, Related_Nod);
16556 Set_Private_Dependents (Def_Id, New_Elmt_List);
16558 -- In case of an invalid constraint prevent further processing
16559 -- since the type constructed is missing expected fields.
16561 if Etype (Def_Id) = Any_Type then
16565 -- If the full view is that of a task with discriminants,
16566 -- we must constrain both the concurrent type and its
16567 -- corresponding record type. Otherwise we will just propagate
16568 -- the constraint to the full view, if available.
16570 if Present (Full_View (Subtype_Mark_Id))
16571 and then Has_Discriminants (Subtype_Mark_Id)
16572 and then Is_Concurrent_Type (Full_View (Subtype_Mark_Id))
16575 Create_Itype (E_Void, Related_Nod, Related_Id, Suffix);
16577 Set_Entity (Subtype_Mark (S), Full_View (Subtype_Mark_Id));
16578 Constrain_Concurrent (Full_View_Id, S,
16579 Related_Nod, Related_Id, Suffix);
16580 Set_Entity (Subtype_Mark (S), Subtype_Mark_Id);
16581 Set_Full_View (Def_Id, Full_View_Id);
16583 -- Introduce an explicit reference to the private subtype,
16584 -- to prevent scope anomalies in gigi if first use appears
16585 -- in a nested context, e.g. a later function body.
16586 -- Should this be generated in other contexts than a full
16587 -- type declaration?
16589 if Is_Itype (Def_Id)
16591 Nkind (Parent (P)) = N_Full_Type_Declaration
16593 Build_Itype_Reference (Def_Id, Parent (P));
16597 Prepare_Private_Subtype_Completion (Def_Id, Related_Nod);
16600 when Concurrent_Kind =>
16601 Constrain_Concurrent (Def_Id, S,
16602 Related_Nod, Related_Id, Suffix);
16605 Error_Msg_N ("invalid subtype mark in subtype indication", S);
16608 -- Size and Convention are always inherited from the base type
16610 Set_Size_Info (Def_Id, (Subtype_Mark_Id));
16611 Set_Convention (Def_Id, Convention (Subtype_Mark_Id));
16615 end Process_Subtype;
16617 ---------------------------------------
16618 -- Check_Anonymous_Access_Components --
16619 ---------------------------------------
16621 procedure Check_Anonymous_Access_Components
16622 (Typ_Decl : Node_Id;
16625 Comp_List : Node_Id)
16627 Loc : constant Source_Ptr := Sloc (Typ_Decl);
16628 Anon_Access : Entity_Id;
16631 Comp_Def : Node_Id;
16633 Type_Def : Node_Id;
16635 procedure Build_Incomplete_Type_Declaration;
16636 -- If the record type contains components that include an access to the
16637 -- current record, then create an incomplete type declaration for the
16638 -- record, to be used as the designated type of the anonymous access.
16639 -- This is done only once, and only if there is no previous partial
16640 -- view of the type.
16642 function Designates_T (Subt : Node_Id) return Boolean;
16643 -- Check whether a node designates the enclosing record type, or 'Class
16646 function Mentions_T (Acc_Def : Node_Id) return Boolean;
16647 -- Check whether an access definition includes a reference to
16648 -- the enclosing record type. The reference can be a subtype mark
16649 -- in the access definition itself, a 'Class attribute reference, or
16650 -- recursively a reference appearing in a parameter specification
16651 -- or result definition of an access_to_subprogram definition.
16653 --------------------------------------
16654 -- Build_Incomplete_Type_Declaration --
16655 --------------------------------------
16657 procedure Build_Incomplete_Type_Declaration is
16662 -- Is_Tagged indicates whether the type is tagged. It is tagged if
16663 -- it's "is new ... with record" or else "is tagged record ...".
16665 Is_Tagged : constant Boolean :=
16666 (Nkind (Type_Definition (Typ_Decl)) = N_Derived_Type_Definition
16669 (Record_Extension_Part (Type_Definition (Typ_Decl))))
16671 (Nkind (Type_Definition (Typ_Decl)) = N_Record_Definition
16672 and then Tagged_Present (Type_Definition (Typ_Decl)));
16675 -- If there is a previous partial view, no need to create a new one
16676 -- If the partial view, given by Prev, is incomplete, If Prev is
16677 -- a private declaration, full declaration is flagged accordingly.
16679 if Prev /= Typ then
16681 Make_Class_Wide_Type (Prev);
16682 Set_Class_Wide_Type (Typ, Class_Wide_Type (Prev));
16683 Set_Etype (Class_Wide_Type (Typ), Typ);
16688 elsif Has_Private_Declaration (Typ) then
16690 -- If we refer to T'Class inside T, and T is the completion of a
16691 -- private type, then we need to make sure the class-wide type
16695 Make_Class_Wide_Type (Typ);
16700 -- If there was a previous anonymous access type, the incomplete
16701 -- type declaration will have been created already.
16703 elsif Present (Current_Entity (Typ))
16704 and then Ekind (Current_Entity (Typ)) = E_Incomplete_Type
16705 and then Full_View (Current_Entity (Typ)) = Typ
16710 Inc_T := Make_Defining_Identifier (Loc, Chars (Typ));
16711 Decl := Make_Incomplete_Type_Declaration (Loc, Inc_T);
16713 -- Type has already been inserted into the current scope.
16714 -- Remove it, and add incomplete declaration for type, so
16715 -- that subsequent anonymous access types can use it.
16716 -- The entity is unchained from the homonym list and from
16717 -- immediate visibility. After analysis, the entity in the
16718 -- incomplete declaration becomes immediately visible in the
16719 -- record declaration that follows.
16721 H := Current_Entity (Typ);
16724 Set_Name_Entity_Id (Chars (Typ), Homonym (Typ));
16727 and then Homonym (H) /= Typ
16729 H := Homonym (Typ);
16732 Set_Homonym (H, Homonym (Typ));
16735 Insert_Before (Typ_Decl, Decl);
16737 Set_Full_View (Inc_T, Typ);
16740 -- Create a common class-wide type for both views, and set
16741 -- the Etype of the class-wide type to the full view.
16743 Make_Class_Wide_Type (Inc_T);
16744 Set_Class_Wide_Type (Typ, Class_Wide_Type (Inc_T));
16745 Set_Etype (Class_Wide_Type (Typ), Typ);
16748 end Build_Incomplete_Type_Declaration;
16754 function Designates_T (Subt : Node_Id) return Boolean is
16755 Type_Id : constant Name_Id := Chars (Typ);
16757 function Names_T (Nam : Node_Id) return Boolean;
16758 -- The record type has not been introduced in the current scope
16759 -- yet, so we must examine the name of the type itself, either
16760 -- an identifier T, or an expanded name of the form P.T, where
16761 -- P denotes the current scope.
16767 function Names_T (Nam : Node_Id) return Boolean is
16769 if Nkind (Nam) = N_Identifier then
16770 return Chars (Nam) = Type_Id;
16772 elsif Nkind (Nam) = N_Selected_Component then
16773 if Chars (Selector_Name (Nam)) = Type_Id then
16774 if Nkind (Prefix (Nam)) = N_Identifier then
16775 return Chars (Prefix (Nam)) = Chars (Current_Scope);
16777 elsif Nkind (Prefix (Nam)) = N_Selected_Component then
16778 return Chars (Selector_Name (Prefix (Nam))) =
16779 Chars (Current_Scope);
16793 -- Start of processing for Designates_T
16796 if Nkind (Subt) = N_Identifier then
16797 return Chars (Subt) = Type_Id;
16799 -- Reference can be through an expanded name which has not been
16800 -- analyzed yet, and which designates enclosing scopes.
16802 elsif Nkind (Subt) = N_Selected_Component then
16803 if Names_T (Subt) then
16806 -- Otherwise it must denote an entity that is already visible.
16807 -- The access definition may name a subtype of the enclosing
16808 -- type, if there is a previous incomplete declaration for it.
16811 Find_Selected_Component (Subt);
16813 Is_Entity_Name (Subt)
16814 and then Scope (Entity (Subt)) = Current_Scope
16816 (Chars (Base_Type (Entity (Subt))) = Type_Id
16818 (Is_Class_Wide_Type (Entity (Subt))
16820 Chars (Etype (Base_Type (Entity (Subt)))) =
16824 -- A reference to the current type may appear as the prefix of
16825 -- a 'Class attribute.
16827 elsif Nkind (Subt) = N_Attribute_Reference
16828 and then Attribute_Name (Subt) = Name_Class
16830 return Names_T (Prefix (Subt));
16841 function Mentions_T (Acc_Def : Node_Id) return Boolean is
16842 Param_Spec : Node_Id;
16844 Acc_Subprg : constant Node_Id :=
16845 Access_To_Subprogram_Definition (Acc_Def);
16848 if No (Acc_Subprg) then
16849 return Designates_T (Subtype_Mark (Acc_Def));
16852 -- Component is an access_to_subprogram: examine its formals,
16853 -- and result definition in the case of an access_to_function.
16855 Param_Spec := First (Parameter_Specifications (Acc_Subprg));
16856 while Present (Param_Spec) loop
16857 if Nkind (Parameter_Type (Param_Spec)) = N_Access_Definition
16858 and then Mentions_T (Parameter_Type (Param_Spec))
16862 elsif Designates_T (Parameter_Type (Param_Spec)) then
16869 if Nkind (Acc_Subprg) = N_Access_Function_Definition then
16870 if Nkind (Result_Definition (Acc_Subprg)) =
16871 N_Access_Definition
16873 return Mentions_T (Result_Definition (Acc_Subprg));
16875 return Designates_T (Result_Definition (Acc_Subprg));
16882 -- Start of processing for Check_Anonymous_Access_Components
16885 if No (Comp_List) then
16889 Comp := First (Component_Items (Comp_List));
16890 while Present (Comp) loop
16891 if Nkind (Comp) = N_Component_Declaration
16893 (Access_Definition (Component_Definition (Comp)))
16895 Mentions_T (Access_Definition (Component_Definition (Comp)))
16897 Comp_Def := Component_Definition (Comp);
16899 Access_To_Subprogram_Definition
16900 (Access_Definition (Comp_Def));
16902 Build_Incomplete_Type_Declaration;
16904 Make_Defining_Identifier (Loc,
16905 Chars => New_Internal_Name ('S'));
16907 -- Create a declaration for the anonymous access type: either
16908 -- an access_to_object or an access_to_subprogram.
16910 if Present (Acc_Def) then
16911 if Nkind (Acc_Def) = N_Access_Function_Definition then
16913 Make_Access_Function_Definition (Loc,
16914 Parameter_Specifications =>
16915 Parameter_Specifications (Acc_Def),
16916 Result_Definition => Result_Definition (Acc_Def));
16919 Make_Access_Procedure_Definition (Loc,
16920 Parameter_Specifications =>
16921 Parameter_Specifications (Acc_Def));
16926 Make_Access_To_Object_Definition (Loc,
16927 Subtype_Indication =>
16930 (Access_Definition (Comp_Def))));
16932 Set_Constant_Present
16933 (Type_Def, Constant_Present (Access_Definition (Comp_Def)));
16935 (Type_Def, All_Present (Access_Definition (Comp_Def)));
16938 Set_Null_Exclusion_Present
16940 Null_Exclusion_Present (Access_Definition (Comp_Def)));
16943 Make_Full_Type_Declaration (Loc,
16944 Defining_Identifier => Anon_Access,
16945 Type_Definition => Type_Def);
16947 Insert_Before (Typ_Decl, Decl);
16950 -- If an access to object, Preserve entity of designated type,
16951 -- for ASIS use, before rewriting the component definition.
16953 if No (Acc_Def) then
16958 Desig := Entity (Subtype_Indication (Type_Def));
16960 -- If the access definition is to the current record,
16961 -- the visible entity at this point is an incomplete
16962 -- type. Retrieve the full view to simplify ASIS queries
16964 if Ekind (Desig) = E_Incomplete_Type then
16965 Desig := Full_View (Desig);
16969 (Subtype_Mark (Access_Definition (Comp_Def)), Desig);
16974 Make_Component_Definition (Loc,
16975 Subtype_Indication =>
16976 New_Occurrence_Of (Anon_Access, Loc)));
16978 if Ekind (Designated_Type (Anon_Access)) = E_Subprogram_Type then
16979 Set_Ekind (Anon_Access, E_Anonymous_Access_Subprogram_Type);
16981 Set_Ekind (Anon_Access, E_Anonymous_Access_Type);
16984 Set_Is_Local_Anonymous_Access (Anon_Access);
16990 if Present (Variant_Part (Comp_List)) then
16994 V := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
16995 while Present (V) loop
16996 Check_Anonymous_Access_Components
16997 (Typ_Decl, Typ, Prev, Component_List (V));
16998 Next_Non_Pragma (V);
17002 end Check_Anonymous_Access_Components;
17004 --------------------------------
17005 -- Preanalyze_Spec_Expression --
17006 --------------------------------
17008 procedure Preanalyze_Spec_Expression (N : Node_Id; T : Entity_Id) is
17009 Save_In_Spec_Expression : constant Boolean := In_Spec_Expression;
17011 In_Spec_Expression := True;
17012 Preanalyze_And_Resolve (N, T);
17013 In_Spec_Expression := Save_In_Spec_Expression;
17014 end Preanalyze_Spec_Expression;
17016 -----------------------------
17017 -- Record_Type_Declaration --
17018 -----------------------------
17020 procedure Record_Type_Declaration
17025 Def : constant Node_Id := Type_Definition (N);
17026 Is_Tagged : Boolean;
17027 Tag_Comp : Entity_Id;
17030 -- These flags must be initialized before calling Process_Discriminants
17031 -- because this routine makes use of them.
17033 Set_Ekind (T, E_Record_Type);
17035 Init_Size_Align (T);
17036 Set_Interfaces (T, No_Elist);
17037 Set_Stored_Constraint (T, No_Elist);
17041 if Ada_Version < Ada_05
17042 or else not Interface_Present (Def)
17044 -- The flag Is_Tagged_Type might have already been set by
17045 -- Find_Type_Name if it detected an error for declaration T. This
17046 -- arises in the case of private tagged types where the full view
17047 -- omits the word tagged.
17050 Tagged_Present (Def)
17051 or else (Serious_Errors_Detected > 0 and then Is_Tagged_Type (T));
17053 Set_Is_Tagged_Type (T, Is_Tagged);
17054 Set_Is_Limited_Record (T, Limited_Present (Def));
17056 -- Type is abstract if full declaration carries keyword, or if
17057 -- previous partial view did.
17059 Set_Is_Abstract_Type (T, Is_Abstract_Type (T)
17060 or else Abstract_Present (Def));
17064 Analyze_Interface_Declaration (T, Def);
17066 if Present (Discriminant_Specifications (N)) then
17068 ("interface types cannot have discriminants",
17069 Defining_Identifier
17070 (First (Discriminant_Specifications (N))));
17074 -- First pass: if there are self-referential access components,
17075 -- create the required anonymous access type declarations, and if
17076 -- need be an incomplete type declaration for T itself.
17078 Check_Anonymous_Access_Components (N, T, Prev, Component_List (Def));
17080 if Ada_Version >= Ada_05
17081 and then Present (Interface_List (Def))
17083 Check_Interfaces (N, Def);
17086 Ifaces_List : Elist_Id;
17089 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
17090 -- already in the parents.
17094 Ifaces_List => Ifaces_List,
17095 Exclude_Parents => True);
17097 Set_Interfaces (T, Ifaces_List);
17101 -- Records constitute a scope for the component declarations within.
17102 -- The scope is created prior to the processing of these declarations.
17103 -- Discriminants are processed first, so that they are visible when
17104 -- processing the other components. The Ekind of the record type itself
17105 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
17107 -- Enter record scope
17111 -- If an incomplete or private type declaration was already given for
17112 -- the type, then this scope already exists, and the discriminants have
17113 -- been declared within. We must verify that the full declaration
17114 -- matches the incomplete one.
17116 Check_Or_Process_Discriminants (N, T, Prev);
17118 Set_Is_Constrained (T, not Has_Discriminants (T));
17119 Set_Has_Delayed_Freeze (T, True);
17121 -- For tagged types add a manually analyzed component corresponding
17122 -- to the component _tag, the corresponding piece of tree will be
17123 -- expanded as part of the freezing actions if it is not a CPP_Class.
17127 -- Do not add the tag unless we are in expansion mode
17129 if Expander_Active then
17130 Tag_Comp := Make_Defining_Identifier (Sloc (Def), Name_uTag);
17131 Enter_Name (Tag_Comp);
17133 Set_Ekind (Tag_Comp, E_Component);
17134 Set_Is_Tag (Tag_Comp);
17135 Set_Is_Aliased (Tag_Comp);
17136 Set_Etype (Tag_Comp, RTE (RE_Tag));
17137 Set_DT_Entry_Count (Tag_Comp, No_Uint);
17138 Set_Original_Record_Component (Tag_Comp, Tag_Comp);
17139 Init_Component_Location (Tag_Comp);
17141 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
17142 -- implemented interfaces.
17144 if Has_Interfaces (T) then
17145 Add_Interface_Tag_Components (N, T);
17149 Make_Class_Wide_Type (T);
17150 Set_Primitive_Operations (T, New_Elmt_List);
17153 -- We must suppress range checks when processing the components
17154 -- of a record in the presence of discriminants, since we don't
17155 -- want spurious checks to be generated during their analysis, but
17156 -- must reset the Suppress_Range_Checks flags after having processed
17157 -- the record definition.
17159 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
17160 -- couldn't we just use the normal range check suppression method here.
17161 -- That would seem cleaner ???
17163 if Has_Discriminants (T) and then not Range_Checks_Suppressed (T) then
17164 Set_Kill_Range_Checks (T, True);
17165 Record_Type_Definition (Def, Prev);
17166 Set_Kill_Range_Checks (T, False);
17168 Record_Type_Definition (Def, Prev);
17171 -- Exit from record scope
17175 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
17176 -- the implemented interfaces and associate them an aliased entity.
17179 and then not Is_Empty_List (Interface_List (Def))
17181 Derive_Progenitor_Subprograms (T, T);
17183 end Record_Type_Declaration;
17185 ----------------------------
17186 -- Record_Type_Definition --
17187 ----------------------------
17189 procedure Record_Type_Definition (Def : Node_Id; Prev_T : Entity_Id) is
17190 Component : Entity_Id;
17191 Ctrl_Components : Boolean := False;
17192 Final_Storage_Only : Boolean;
17196 if Ekind (Prev_T) = E_Incomplete_Type then
17197 T := Full_View (Prev_T);
17202 Final_Storage_Only := not Is_Controlled (T);
17204 -- Ada 2005: check whether an explicit Limited is present in a derived
17205 -- type declaration.
17207 if Nkind (Parent (Def)) = N_Derived_Type_Definition
17208 and then Limited_Present (Parent (Def))
17210 Set_Is_Limited_Record (T);
17213 -- If the component list of a record type is defined by the reserved
17214 -- word null and there is no discriminant part, then the record type has
17215 -- no components and all records of the type are null records (RM 3.7)
17216 -- This procedure is also called to process the extension part of a
17217 -- record extension, in which case the current scope may have inherited
17221 or else No (Component_List (Def))
17222 or else Null_Present (Component_List (Def))
17227 Analyze_Declarations (Component_Items (Component_List (Def)));
17229 if Present (Variant_Part (Component_List (Def))) then
17230 Analyze (Variant_Part (Component_List (Def)));
17234 -- After completing the semantic analysis of the record definition,
17235 -- record components, both new and inherited, are accessible. Set their
17236 -- kind accordingly. Exclude malformed itypes from illegal declarations,
17237 -- whose Ekind may be void.
17239 Component := First_Entity (Current_Scope);
17240 while Present (Component) loop
17241 if Ekind (Component) = E_Void
17242 and then not Is_Itype (Component)
17244 Set_Ekind (Component, E_Component);
17245 Init_Component_Location (Component);
17248 if Has_Task (Etype (Component)) then
17252 if Ekind (Component) /= E_Component then
17255 elsif Has_Controlled_Component (Etype (Component))
17256 or else (Chars (Component) /= Name_uParent
17257 and then Is_Controlled (Etype (Component)))
17259 Set_Has_Controlled_Component (T, True);
17260 Final_Storage_Only :=
17262 and then Finalize_Storage_Only (Etype (Component));
17263 Ctrl_Components := True;
17266 Next_Entity (Component);
17269 -- A Type is Finalize_Storage_Only only if all its controlled components
17272 if Ctrl_Components then
17273 Set_Finalize_Storage_Only (T, Final_Storage_Only);
17276 -- Place reference to end record on the proper entity, which may
17277 -- be a partial view.
17279 if Present (Def) then
17280 Process_End_Label (Def, 'e', Prev_T);
17282 end Record_Type_Definition;
17284 ------------------------
17285 -- Replace_Components --
17286 ------------------------
17288 procedure Replace_Components (Typ : Entity_Id; Decl : Node_Id) is
17289 function Process (N : Node_Id) return Traverse_Result;
17295 function Process (N : Node_Id) return Traverse_Result is
17299 if Nkind (N) = N_Discriminant_Specification then
17300 Comp := First_Discriminant (Typ);
17301 while Present (Comp) loop
17302 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17303 Set_Defining_Identifier (N, Comp);
17307 Next_Discriminant (Comp);
17310 elsif Nkind (N) = N_Component_Declaration then
17311 Comp := First_Component (Typ);
17312 while Present (Comp) loop
17313 if Chars (Comp) = Chars (Defining_Identifier (N)) then
17314 Set_Defining_Identifier (N, Comp);
17318 Next_Component (Comp);
17325 procedure Replace is new Traverse_Proc (Process);
17327 -- Start of processing for Replace_Components
17331 end Replace_Components;
17333 -------------------------------
17334 -- Set_Completion_Referenced --
17335 -------------------------------
17337 procedure Set_Completion_Referenced (E : Entity_Id) is
17339 -- If in main unit, mark entity that is a completion as referenced,
17340 -- warnings go on the partial view when needed.
17342 if In_Extended_Main_Source_Unit (E) then
17343 Set_Referenced (E);
17345 end Set_Completion_Referenced;
17347 ---------------------
17348 -- Set_Fixed_Range --
17349 ---------------------
17351 -- The range for fixed-point types is complicated by the fact that we
17352 -- do not know the exact end points at the time of the declaration. This
17353 -- is true for three reasons:
17355 -- A size clause may affect the fudging of the end-points
17356 -- A small clause may affect the values of the end-points
17357 -- We try to include the end-points if it does not affect the size
17359 -- This means that the actual end-points must be established at the point
17360 -- when the type is frozen. Meanwhile, we first narrow the range as
17361 -- permitted (so that it will fit if necessary in a small specified size),
17362 -- and then build a range subtree with these narrowed bounds.
17364 -- Set_Fixed_Range constructs the range from real literal values, and sets
17365 -- the range as the Scalar_Range of the given fixed-point type entity.
17367 -- The parent of this range is set to point to the entity so that it is
17368 -- properly hooked into the tree (unlike normal Scalar_Range entries for
17369 -- other scalar types, which are just pointers to the range in the
17370 -- original tree, this would otherwise be an orphan).
17372 -- The tree is left unanalyzed. When the type is frozen, the processing
17373 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
17374 -- analyzed, and uses this as an indication that it should complete
17375 -- work on the range (it will know the final small and size values).
17377 procedure Set_Fixed_Range
17383 S : constant Node_Id :=
17385 Low_Bound => Make_Real_Literal (Loc, Lo),
17386 High_Bound => Make_Real_Literal (Loc, Hi));
17388 Set_Scalar_Range (E, S);
17390 end Set_Fixed_Range;
17392 ----------------------------------
17393 -- Set_Scalar_Range_For_Subtype --
17394 ----------------------------------
17396 procedure Set_Scalar_Range_For_Subtype
17397 (Def_Id : Entity_Id;
17401 Kind : constant Entity_Kind := Ekind (Def_Id);
17404 Set_Scalar_Range (Def_Id, R);
17406 -- We need to link the range into the tree before resolving it so
17407 -- that types that are referenced, including importantly the subtype
17408 -- itself, are properly frozen (Freeze_Expression requires that the
17409 -- expression be properly linked into the tree). Of course if it is
17410 -- already linked in, then we do not disturb the current link.
17412 if No (Parent (R)) then
17413 Set_Parent (R, Def_Id);
17416 -- Reset the kind of the subtype during analysis of the range, to
17417 -- catch possible premature use in the bounds themselves.
17419 Set_Ekind (Def_Id, E_Void);
17420 Process_Range_Expr_In_Decl (R, Subt);
17421 Set_Ekind (Def_Id, Kind);
17422 end Set_Scalar_Range_For_Subtype;
17424 --------------------------------------------------------
17425 -- Set_Stored_Constraint_From_Discriminant_Constraint --
17426 --------------------------------------------------------
17428 procedure Set_Stored_Constraint_From_Discriminant_Constraint
17432 -- Make sure set if encountered during Expand_To_Stored_Constraint
17434 Set_Stored_Constraint (E, No_Elist);
17436 -- Give it the right value
17438 if Is_Constrained (E) and then Has_Discriminants (E) then
17439 Set_Stored_Constraint (E,
17440 Expand_To_Stored_Constraint (E, Discriminant_Constraint (E)));
17442 end Set_Stored_Constraint_From_Discriminant_Constraint;
17444 -------------------------------------
17445 -- Signed_Integer_Type_Declaration --
17446 -------------------------------------
17448 procedure Signed_Integer_Type_Declaration (T : Entity_Id; Def : Node_Id) is
17449 Implicit_Base : Entity_Id;
17450 Base_Typ : Entity_Id;
17453 Errs : Boolean := False;
17457 function Can_Derive_From (E : Entity_Id) return Boolean;
17458 -- Determine whether given bounds allow derivation from specified type
17460 procedure Check_Bound (Expr : Node_Id);
17461 -- Check bound to make sure it is integral and static. If not, post
17462 -- appropriate error message and set Errs flag
17464 ---------------------
17465 -- Can_Derive_From --
17466 ---------------------
17468 -- Note we check both bounds against both end values, to deal with
17469 -- strange types like ones with a range of 0 .. -12341234.
17471 function Can_Derive_From (E : Entity_Id) return Boolean is
17472 Lo : constant Uint := Expr_Value (Type_Low_Bound (E));
17473 Hi : constant Uint := Expr_Value (Type_High_Bound (E));
17475 return Lo <= Lo_Val and then Lo_Val <= Hi
17477 Lo <= Hi_Val and then Hi_Val <= Hi;
17478 end Can_Derive_From;
17484 procedure Check_Bound (Expr : Node_Id) is
17486 -- If a range constraint is used as an integer type definition, each
17487 -- bound of the range must be defined by a static expression of some
17488 -- integer type, but the two bounds need not have the same integer
17489 -- type (Negative bounds are allowed.) (RM 3.5.4)
17491 if not Is_Integer_Type (Etype (Expr)) then
17493 ("integer type definition bounds must be of integer type", Expr);
17496 elsif not Is_OK_Static_Expression (Expr) then
17497 Flag_Non_Static_Expr
17498 ("non-static expression used for integer type bound!", Expr);
17501 -- The bounds are folded into literals, and we set their type to be
17502 -- universal, to avoid typing difficulties: we cannot set the type
17503 -- of the literal to the new type, because this would be a forward
17504 -- reference for the back end, and if the original type is user-
17505 -- defined this can lead to spurious semantic errors (e.g. 2928-003).
17508 if Is_Entity_Name (Expr) then
17509 Fold_Uint (Expr, Expr_Value (Expr), True);
17512 Set_Etype (Expr, Universal_Integer);
17516 -- Start of processing for Signed_Integer_Type_Declaration
17519 -- Create an anonymous base type
17522 Create_Itype (E_Signed_Integer_Type, Parent (Def), T, 'B');
17524 -- Analyze and check the bounds, they can be of any integer type
17526 Lo := Low_Bound (Def);
17527 Hi := High_Bound (Def);
17529 -- Arbitrarily use Integer as the type if either bound had an error
17531 if Hi = Error or else Lo = Error then
17532 Base_Typ := Any_Integer;
17533 Set_Error_Posted (T, True);
17535 -- Here both bounds are OK expressions
17538 Analyze_And_Resolve (Lo, Any_Integer);
17539 Analyze_And_Resolve (Hi, Any_Integer);
17545 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17546 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17549 -- Find type to derive from
17551 Lo_Val := Expr_Value (Lo);
17552 Hi_Val := Expr_Value (Hi);
17554 if Can_Derive_From (Standard_Short_Short_Integer) then
17555 Base_Typ := Base_Type (Standard_Short_Short_Integer);
17557 elsif Can_Derive_From (Standard_Short_Integer) then
17558 Base_Typ := Base_Type (Standard_Short_Integer);
17560 elsif Can_Derive_From (Standard_Integer) then
17561 Base_Typ := Base_Type (Standard_Integer);
17563 elsif Can_Derive_From (Standard_Long_Integer) then
17564 Base_Typ := Base_Type (Standard_Long_Integer);
17566 elsif Can_Derive_From (Standard_Long_Long_Integer) then
17567 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17570 Base_Typ := Base_Type (Standard_Long_Long_Integer);
17571 Error_Msg_N ("integer type definition bounds out of range", Def);
17572 Hi := Type_High_Bound (Standard_Long_Long_Integer);
17573 Lo := Type_Low_Bound (Standard_Long_Long_Integer);
17577 -- Complete both implicit base and declared first subtype entities
17579 Set_Etype (Implicit_Base, Base_Typ);
17580 Set_Scalar_Range (Implicit_Base, Scalar_Range (Base_Typ));
17581 Set_Size_Info (Implicit_Base, (Base_Typ));
17582 Set_RM_Size (Implicit_Base, RM_Size (Base_Typ));
17583 Set_First_Rep_Item (Implicit_Base, First_Rep_Item (Base_Typ));
17585 Set_Ekind (T, E_Signed_Integer_Subtype);
17586 Set_Etype (T, Implicit_Base);
17588 Set_Size_Info (T, (Implicit_Base));
17589 Set_First_Rep_Item (T, First_Rep_Item (Implicit_Base));
17590 Set_Scalar_Range (T, Def);
17591 Set_RM_Size (T, UI_From_Int (Minimum_Size (T)));
17592 Set_Is_Constrained (T);
17593 end Signed_Integer_Type_Declaration;