1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Debug
; use Debug
;
29 with Elists
; use Elists
;
30 with Einfo
; use Einfo
;
31 with Errout
; use Errout
;
32 with Eval_Fat
; use Eval_Fat
;
33 with Exp_Ch3
; use Exp_Ch3
;
34 with Exp_Dist
; use Exp_Dist
;
35 with Exp_Tss
; use Exp_Tss
;
36 with Exp_Util
; use Exp_Util
;
37 with Fname
; use Fname
;
38 with Freeze
; use Freeze
;
39 with Itypes
; use Itypes
;
40 with Layout
; use Layout
;
42 with Lib
.Xref
; use Lib
.Xref
;
43 with Namet
; use Namet
;
44 with Nmake
; use Nmake
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Case
; use Sem_Case
;
51 with Sem_Cat
; use Sem_Cat
;
52 with Sem_Ch6
; use Sem_Ch6
;
53 with Sem_Ch7
; use Sem_Ch7
;
54 with Sem_Ch8
; use Sem_Ch8
;
55 with Sem_Ch13
; use Sem_Ch13
;
56 with Sem_Disp
; use Sem_Disp
;
57 with Sem_Dist
; use Sem_Dist
;
58 with Sem_Elim
; use Sem_Elim
;
59 with Sem_Eval
; use Sem_Eval
;
60 with Sem_Mech
; use Sem_Mech
;
61 with Sem_Res
; use Sem_Res
;
62 with Sem_Smem
; use Sem_Smem
;
63 with Sem_Type
; use Sem_Type
;
64 with Sem_Util
; use Sem_Util
;
65 with Sem_Warn
; use Sem_Warn
;
66 with Stand
; use Stand
;
67 with Sinfo
; use Sinfo
;
68 with Snames
; use Snames
;
69 with Targparm
; use Targparm
;
70 with Tbuild
; use Tbuild
;
71 with Ttypes
; use Ttypes
;
72 with Uintp
; use Uintp
;
73 with Urealp
; use Urealp
;
75 package body Sem_Ch3
is
77 -----------------------
78 -- Local Subprograms --
79 -----------------------
81 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
);
82 -- Ada 2005 (AI-251): Add the tag components corresponding to all the
83 -- abstract interface types implemented by a record type or a derived
86 procedure Build_Derived_Type
88 Parent_Type
: Entity_Id
;
89 Derived_Type
: Entity_Id
;
90 Is_Completion
: Boolean;
91 Derive_Subps
: Boolean := True);
92 -- Create and decorate a Derived_Type given the Parent_Type entity. N is
93 -- the N_Full_Type_Declaration node containing the derived type definition.
94 -- Parent_Type is the entity for the parent type in the derived type
95 -- definition and Derived_Type the actual derived type. Is_Completion must
96 -- be set to False if Derived_Type is the N_Defining_Identifier node in N
97 -- (ie Derived_Type = Defining_Identifier (N)). In this case N is not the
98 -- completion of a private type declaration. If Is_Completion is set to
99 -- True, N is the completion of a private type declaration and Derived_Type
100 -- is different from the defining identifier inside N (i.e. Derived_Type /=
101 -- Defining_Identifier (N)). Derive_Subps indicates whether the parent
102 -- subprograms should be derived. The only case where this parameter is
103 -- False is when Build_Derived_Type is recursively called to process an
104 -- implicit derived full type for a type derived from a private type (in
105 -- that case the subprograms must only be derived for the private view of
108 -- ??? These flags need a bit of re-examination and re-documentation:
109 -- ??? are they both necessary (both seem related to the recursion)?
111 procedure Build_Derived_Access_Type
113 Parent_Type
: Entity_Id
;
114 Derived_Type
: Entity_Id
);
115 -- Subsidiary procedure to Build_Derived_Type. For a derived access type,
116 -- create an implicit base if the parent type is constrained or if the
117 -- subtype indication has a constraint.
119 procedure Build_Derived_Array_Type
121 Parent_Type
: Entity_Id
;
122 Derived_Type
: Entity_Id
);
123 -- Subsidiary procedure to Build_Derived_Type. For a derived array type,
124 -- create an implicit base if the parent type is constrained or if the
125 -- subtype indication has a constraint.
127 procedure Build_Derived_Concurrent_Type
129 Parent_Type
: Entity_Id
;
130 Derived_Type
: Entity_Id
);
131 -- Subsidiary procedure to Build_Derived_Type. For a derived task or
132 -- protected type, inherit entries and protected subprograms, check
133 -- legality of discriminant constraints if any.
135 procedure Build_Derived_Enumeration_Type
137 Parent_Type
: Entity_Id
;
138 Derived_Type
: Entity_Id
);
139 -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
140 -- type, we must create a new list of literals. Types derived from
141 -- Character and Wide_Character are special-cased.
143 procedure Build_Derived_Numeric_Type
145 Parent_Type
: Entity_Id
;
146 Derived_Type
: Entity_Id
);
147 -- Subsidiary procedure to Build_Derived_Type. For numeric types, create
148 -- an anonymous base type, and propagate constraint to subtype if needed.
150 procedure Build_Derived_Private_Type
152 Parent_Type
: Entity_Id
;
153 Derived_Type
: Entity_Id
;
154 Is_Completion
: Boolean;
155 Derive_Subps
: Boolean := True);
156 -- Subsidiary procedure to Build_Derived_Type. This procedure is complex
157 -- because the parent may or may not have a completion, and the derivation
158 -- may itself be a completion.
160 procedure Build_Derived_Record_Type
162 Parent_Type
: Entity_Id
;
163 Derived_Type
: Entity_Id
;
164 Derive_Subps
: Boolean := True);
165 -- Subsidiary procedure for Build_Derived_Type and
166 -- Analyze_Private_Extension_Declaration used for tagged and untagged
167 -- record types. All parameters are as in Build_Derived_Type except that
168 -- N, in addition to being an N_Full_Type_Declaration node, can also be an
169 -- N_Private_Extension_Declaration node. See the definition of this routine
170 -- for much more info. Derive_Subps indicates whether subprograms should
171 -- be derived from the parent type. The only case where Derive_Subps is
172 -- False is for an implicit derived full type for a type derived from a
173 -- private type (see Build_Derived_Type).
175 procedure Build_Discriminal
(Discrim
: Entity_Id
);
176 -- Create the discriminal corresponding to discriminant Discrim, that is
177 -- the parameter corresponding to Discrim to be used in initialization
178 -- procedures for the type where Discrim is a discriminant. Discriminals
179 -- are not used during semantic analysis, and are not fully defined
180 -- entities until expansion. Thus they are not given a scope until
181 -- initialization procedures are built.
183 function Build_Discriminant_Constraints
186 Derived_Def
: Boolean := False) return Elist_Id
;
187 -- Validate discriminant constraints and return the list of the constraints
188 -- in order of discriminant declarations, where T is the discriminated
189 -- unconstrained type. Def is the N_Subtype_Indication node where the
190 -- discriminants constraints for T are specified. Derived_Def is True
191 -- when building the discriminant constraints in a derived type definition
192 -- of the form "type D (...) is new T (xxx)". In this case T is the parent
193 -- type and Def is the constraint "(xxx)" on T and this routine sets the
194 -- Corresponding_Discriminant field of the discriminants in the derived
195 -- type D to point to the corresponding discriminants in the parent type T.
197 procedure Build_Discriminated_Subtype
201 Related_Nod
: Node_Id
;
202 For_Access
: Boolean := False);
203 -- Subsidiary procedure to Constrain_Discriminated_Type and to
204 -- Process_Incomplete_Dependents. Given
206 -- T (a possibly discriminated base type)
207 -- Def_Id (a very partially built subtype for T),
209 -- the call completes Def_Id to be the appropriate E_*_Subtype.
211 -- The Elist is the list of discriminant constraints if any (it is set
212 -- to No_Elist if T is not a discriminated type, and to an empty list if
213 -- T has discriminants but there are no discriminant constraints). The
214 -- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
215 -- The For_Access says whether or not this subtype is really constraining
216 -- an access type. That is its sole purpose is the designated type of an
217 -- access type -- in which case a Private_Subtype Is_For_Access_Subtype
218 -- is built to avoid freezing T when the access subtype is frozen.
220 function Build_Scalar_Bound
223 Der_T
: Entity_Id
) return Node_Id
;
224 -- The bounds of a derived scalar type are conversions of the bounds of
225 -- the parent type. Optimize the representation if the bounds are literals.
226 -- Needs a more complete spec--what are the parameters exactly, and what
227 -- exactly is the returned value, and how is Bound affected???
229 procedure Build_Itype_Reference
232 -- Create a reference to an internal type, for use by Gigi. The back-end
233 -- elaborates itypes on demand, i.e. when their first use is seen. This
234 -- can lead to scope anomalies if the first use is within a scope that is
235 -- nested within the scope that contains the point of definition of the
236 -- itype. The Itype_Reference node forces the elaboration of the itype
237 -- in the proper scope. The node is inserted after Nod, which is the
238 -- enclosing declaration that generated Ityp.
239 -- A related mechanism is used during expansion, for itypes created in
240 -- branches of conditionals. See Ensure_Defined in exp_util.
241 -- Could both mechanisms be merged ???
243 procedure Build_Underlying_Full_View
247 -- If the completion of a private type is itself derived from a private
248 -- type, or if the full view of a private subtype is itself private, the
249 -- back-end has no way to compute the actual size of this type. We build
250 -- an internal subtype declaration of the proper parent type to convey
251 -- this information. This extra mechanism is needed because a full
252 -- view cannot itself have a full view (it would get clobbered during
255 procedure Check_Abstract_Interfaces
(N
: Node_Id
; Def
: Node_Id
);
256 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
258 procedure Check_Access_Discriminant_Requires_Limited
261 -- Check the restriction that the type to which an access discriminant
262 -- belongs must be a concurrent type or a descendant of a type with
263 -- the reserved word 'limited' in its declaration.
265 procedure Check_Anonymous_Access_Components
269 Comp_List
: Node_Id
);
270 -- Ada 2005 AI-382: an access component in a record definition can refer to
271 -- the enclosing record, in which case it denotes the type itself, and not
272 -- the current instance of the type. We create an anonymous access type for
273 -- the component, and flag it as an access to a component, so accessibility
274 -- checks are properly performed on it. The declaration of the access type
275 -- is placed ahead of that of the record to prevent order-of-elaboration
276 -- circularity issues in Gigi. We create an incomplete type for the record
277 -- declaration, which is the designated type of the anonymous access.
279 procedure Check_Delta_Expression
(E
: Node_Id
);
280 -- Check that the expression represented by E is suitable for use as a
281 -- delta expression, i.e. it is of real type and is static.
283 procedure Check_Digits_Expression
(E
: Node_Id
);
284 -- Check that the expression represented by E is suitable for use as a
285 -- digits expression, i.e. it is of integer type, positive and static.
287 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
);
288 -- Validate the initialization of an object declaration. T is the required
289 -- type, and Exp is the initialization expression.
291 procedure Check_Or_Process_Discriminants
294 Prev
: Entity_Id
:= Empty
);
295 -- If T is the full declaration of an incomplete or private type, check the
296 -- conformance of the discriminants, otherwise process them. Prev is the
297 -- entity of the partial declaration, if any.
299 procedure Check_Real_Bound
(Bound
: Node_Id
);
300 -- Check given bound for being of real type and static. If not, post an
301 -- appropriate message, and rewrite the bound with the real literal zero.
303 procedure Constant_Redeclaration
307 -- Various checks on legality of full declaration of deferred constant.
308 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
309 -- node. The caller has not yet set any attributes of this entity.
311 function Contain_Interface
313 Ifaces
: Elist_Id
) return Boolean;
314 -- Ada 2005: Determine whether Iface is present in the list Ifaces
316 procedure Convert_Scalar_Bounds
318 Parent_Type
: Entity_Id
;
319 Derived_Type
: Entity_Id
;
321 -- For derived scalar types, convert the bounds in the type definition to
322 -- the derived type, and complete their analysis. Given a constraint of the
323 -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with
324 -- T'Base, the parent_type. The bounds of the derived type (the anonymous
325 -- base) are copies of Lo and Hi. Finally, the bounds of the derived
326 -- subtype are conversions of those bounds to the derived_type, so that
327 -- their typing is consistent.
329 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
);
330 -- Copies attributes from array base type T2 to array base type T1. Copies
331 -- only attributes that apply to base types, but not subtypes.
333 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
);
334 -- Copies attributes from array subtype T2 to array subtype T1. Copies
335 -- attributes that apply to both subtypes and base types.
337 procedure Create_Constrained_Components
341 Constraints
: Elist_Id
);
342 -- Build the list of entities for a constrained discriminated record
343 -- subtype. If a component depends on a discriminant, replace its subtype
344 -- using the discriminant values in the discriminant constraint. Subt is
345 -- the defining identifier for the subtype whose list of constrained
346 -- entities we will create. Decl_Node is the type declaration node where we
347 -- will attach all the itypes created. Typ is the base discriminated type
348 -- for the subtype Subt. Constraints is the list of discriminant
349 -- constraints for Typ.
351 function Constrain_Component_Type
353 Constrained_Typ
: Entity_Id
;
354 Related_Node
: Node_Id
;
356 Constraints
: Elist_Id
) return Entity_Id
;
357 -- Given a discriminated base type Typ, a list of discriminant constraint
358 -- Constraints for Typ and a component of Typ, with type Compon_Type,
359 -- create and return the type corresponding to Compon_type where all
360 -- discriminant references are replaced with the corresponding constraint.
361 -- If no discriminant references occur in Compon_Typ then return it as is.
362 -- Constrained_Typ is the final constrained subtype to which the
363 -- constrained Compon_Type belongs. Related_Node is the node where we will
364 -- attach all the itypes created.
365 -- Above description is confused, what is Compon_Type???
367 procedure Constrain_Access
368 (Def_Id
: in out Entity_Id
;
370 Related_Nod
: Node_Id
);
371 -- Apply a list of constraints to an access type. If Def_Id is empty, it is
372 -- an anonymous type created for a subtype indication. In that case it is
373 -- created in the procedure and attached to Related_Nod.
375 procedure Constrain_Array
376 (Def_Id
: in out Entity_Id
;
378 Related_Nod
: Node_Id
;
379 Related_Id
: Entity_Id
;
381 -- Apply a list of index constraints to an unconstrained array type. The
382 -- first parameter is the entity for the resulting subtype. A value of
383 -- Empty for Def_Id indicates that an implicit type must be created, but
384 -- creation is delayed (and must be done by this procedure) because other
385 -- subsidiary implicit types must be created first (which is why Def_Id
386 -- is an in/out parameter). The second parameter is a subtype indication
387 -- node for the constrained array to be created (e.g. something of the
388 -- form string (1 .. 10)). Related_Nod gives the place where this type
389 -- has to be inserted in the tree. The Related_Id and Suffix parameters
390 -- are used to build the associated Implicit type name.
392 procedure Constrain_Concurrent
393 (Def_Id
: in out Entity_Id
;
395 Related_Nod
: Node_Id
;
396 Related_Id
: Entity_Id
;
398 -- Apply list of discriminant constraints to an unconstrained concurrent
401 -- SI is the N_Subtype_Indication node containing the constraint and
402 -- the unconstrained type to constrain.
404 -- Def_Id is the entity for the resulting constrained subtype. A value
405 -- of Empty for Def_Id indicates that an implicit type must be created,
406 -- but creation is delayed (and must be done by this procedure) because
407 -- other subsidiary implicit types must be created first (which is why
408 -- Def_Id is an in/out parameter).
410 -- Related_Nod gives the place where this type has to be inserted
413 -- The last two arguments are used to create its external name if needed.
415 function Constrain_Corresponding_Record
416 (Prot_Subt
: Entity_Id
;
417 Corr_Rec
: Entity_Id
;
418 Related_Nod
: Node_Id
;
419 Related_Id
: Entity_Id
) return Entity_Id
;
420 -- When constraining a protected type or task type with discriminants,
421 -- constrain the corresponding record with the same discriminant values.
423 procedure Constrain_Decimal
(Def_Id
: Node_Id
; S
: Node_Id
);
424 -- Constrain a decimal fixed point type with a digits constraint and/or a
425 -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
427 procedure Constrain_Discriminated_Type
430 Related_Nod
: Node_Id
;
431 For_Access
: Boolean := False);
432 -- Process discriminant constraints of composite type. Verify that values
433 -- have been provided for all discriminants, that the original type is
434 -- unconstrained, and that the types of the supplied expressions match
435 -- the discriminant types. The first three parameters are like in routine
436 -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
439 procedure Constrain_Enumeration
(Def_Id
: Node_Id
; S
: Node_Id
);
440 -- Constrain an enumeration type with a range constraint. This is identical
441 -- to Constrain_Integer, but for the Ekind of the resulting subtype.
443 procedure Constrain_Float
(Def_Id
: Node_Id
; S
: Node_Id
);
444 -- Constrain a floating point type with either a digits constraint
445 -- and/or a range constraint, building a E_Floating_Point_Subtype.
447 procedure Constrain_Index
450 Related_Nod
: Node_Id
;
451 Related_Id
: Entity_Id
;
454 -- Process an index constraint in a constrained array declaration. The
455 -- constraint can be a subtype name, or a range with or without an explicit
456 -- subtype mark. The index is the corresponding index of the unconstrained
457 -- array. The Related_Id and Suffix parameters are used to build the
458 -- associated Implicit type name.
460 procedure Constrain_Integer
(Def_Id
: Node_Id
; S
: Node_Id
);
461 -- Build subtype of a signed or modular integer type
463 procedure Constrain_Ordinary_Fixed
(Def_Id
: Node_Id
; S
: Node_Id
);
464 -- Constrain an ordinary fixed point type with a range constraint, and
465 -- build an E_Ordinary_Fixed_Point_Subtype entity.
467 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
);
468 -- Copy the Priv entity into the entity of its full declaration then swap
469 -- the two entities in such a manner that the former private type is now
470 -- seen as a full type.
472 procedure Decimal_Fixed_Point_Type_Declaration
475 -- Create a new decimal fixed point type, and apply the constraint to
476 -- obtain a subtype of this new type.
478 procedure Complete_Private_Subtype
481 Full_Base
: Entity_Id
;
482 Related_Nod
: Node_Id
);
483 -- Complete the implicit full view of a private subtype by setting the
484 -- appropriate semantic fields. If the full view of the parent is a record
485 -- type, build constrained components of subtype.
487 procedure Derive_Interface_Subprograms
488 (Parent_Type
: Entity_Id
;
489 Tagged_Type
: Entity_Id
;
490 Ifaces_List
: Elist_Id
);
491 -- Ada 2005 (AI-251): Derive primitives of abstract interface types that
492 -- are not immediate ancestors of Tagged type and associate them their
493 -- aliased primitive. Ifaces_List contains the abstract interface
494 -- primitives that have been derived from Parent_Type.
496 procedure Derived_Standard_Character
498 Parent_Type
: Entity_Id
;
499 Derived_Type
: Entity_Id
);
500 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
501 -- derivations from types Standard.Character and Standard.Wide_Character.
503 procedure Derived_Type_Declaration
506 Is_Completion
: Boolean);
507 -- Process a derived type declaration. This routine will invoke
508 -- Build_Derived_Type to process the actual derived type definition.
509 -- Parameters N and Is_Completion have the same meaning as in
510 -- Build_Derived_Type. T is the N_Defining_Identifier for the entity
511 -- defined in the N_Full_Type_Declaration node N, that is T is the derived
514 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
515 -- Insert each literal in symbol table, as an overloadable identifier. Each
516 -- enumeration type is mapped into a sequence of integers, and each literal
517 -- is defined as a constant with integer value. If any of the literals are
518 -- character literals, the type is a character type, which means that
519 -- strings are legal aggregates for arrays of components of the type.
521 function Expand_To_Stored_Constraint
523 Constraint
: Elist_Id
) return Elist_Id
;
524 -- Given a Constraint (i.e. a list of expressions) on the discriminants of
525 -- Typ, expand it into a constraint on the stored discriminants and return
526 -- the new list of expressions constraining the stored discriminants.
528 function Find_Type_Of_Object
530 Related_Nod
: Node_Id
) return Entity_Id
;
531 -- Get type entity for object referenced by Obj_Def, attaching the
532 -- implicit types generated to Related_Nod
534 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
535 -- Create a new float, and apply the constraint to obtain subtype of it
537 function Has_Range_Constraint
(N
: Node_Id
) return Boolean;
538 -- Given an N_Subtype_Indication node N, return True if a range constraint
539 -- is present, either directly, or as part of a digits or delta constraint.
540 -- In addition, a digits constraint in the decimal case returns True, since
541 -- it establishes a default range if no explicit range is present.
543 function Inherit_Components
545 Parent_Base
: Entity_Id
;
546 Derived_Base
: Entity_Id
;
548 Inherit_Discr
: Boolean;
549 Discs
: Elist_Id
) return Elist_Id
;
550 -- Called from Build_Derived_Record_Type to inherit the components of
551 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
552 -- For more information on derived types and component inheritance please
553 -- consult the comment above the body of Build_Derived_Record_Type.
555 -- N is the original derived type declaration
557 -- Is_Tagged is set if we are dealing with tagged types
559 -- If Inherit_Discr is set, Derived_Base inherits its discriminants from
560 -- Parent_Base, otherwise no discriminants are inherited.
562 -- Discs gives the list of constraints that apply to Parent_Base in the
563 -- derived type declaration. If Discs is set to No_Elist, then we have
564 -- the following situation:
566 -- type Parent (D1..Dn : ..) is [tagged] record ...;
567 -- type Derived is new Parent [with ...];
569 -- which gets treated as
571 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
573 -- For untagged types the returned value is an association list. The list
574 -- starts from the association (Parent_Base => Derived_Base), and then it
575 -- contains a sequence of the associations of the form
577 -- (Old_Component => New_Component),
579 -- where Old_Component is the Entity_Id of a component in Parent_Base and
580 -- New_Component is the Entity_Id of the corresponding component in
581 -- Derived_Base. For untagged records, this association list is needed when
582 -- copying the record declaration for the derived base. In the tagged case
583 -- the value returned is irrelevant.
585 function Is_Valid_Constraint_Kind
587 Constraint_Kind
: Node_Kind
) return Boolean;
588 -- Returns True if it is legal to apply the given kind of constraint to the
589 -- given kind of type (index constraint to an array type, for example).
591 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
592 -- Create new modular type. Verify that modulus is in bounds and is
593 -- a power of two (implementation restriction).
595 procedure New_Concatenation_Op
(Typ
: Entity_Id
);
596 -- Create an abbreviated declaration for an operator in order to
597 -- materialize concatenation on array types.
599 procedure Ordinary_Fixed_Point_Type_Declaration
602 -- Create a new ordinary fixed point type, and apply the constraint to
603 -- obtain subtype of it.
605 procedure Prepare_Private_Subtype_Completion
607 Related_Nod
: Node_Id
);
608 -- Id is a subtype of some private type. Creates the full declaration
609 -- associated with Id whenever possible, i.e. when the full declaration
610 -- of the base type is already known. Records each subtype into
611 -- Private_Dependents of the base type.
613 procedure Process_Incomplete_Dependents
617 -- Process all entities that depend on an incomplete type. There include
618 -- subtypes, subprogram types that mention the incomplete type in their
619 -- profiles, and subprogram with access parameters that designate the
622 -- Inc_T is the defining identifier of an incomplete type declaration, its
623 -- Ekind is E_Incomplete_Type.
625 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
627 -- Full_T is N's defining identifier.
629 -- Subtypes of incomplete types with discriminants are completed when the
630 -- parent type is. This is simpler than private subtypes, because they can
631 -- only appear in the same scope, and there is no need to exchange views.
632 -- Similarly, access_to_subprogram types may have a parameter or a return
633 -- type that is an incomplete type, and that must be replaced with the
636 -- If the full type is tagged, subprogram with access parameters that
637 -- designated the incomplete may be primitive operations of the full type,
638 -- and have to be processed accordingly.
640 procedure Process_Real_Range_Specification
(Def
: Node_Id
);
641 -- Given the type definition for a real type, this procedure processes
642 -- and checks the real range specification of this type definition if
643 -- one is present. If errors are found, error messages are posted, and
644 -- the Real_Range_Specification of Def is reset to Empty.
646 procedure Record_Type_Declaration
650 -- Process a record type declaration (for both untagged and tagged
651 -- records). Parameters T and N are exactly like in procedure
652 -- Derived_Type_Declaration, except that no flag Is_Completion is needed
653 -- for this routine. If this is the completion of an incomplete type
654 -- declaration, Prev is the entity of the incomplete declaration, used for
655 -- cross-referencing. Otherwise Prev = T.
657 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
);
658 -- This routine is used to process the actual record type definition
659 -- (both for untagged and tagged records). Def is a record type
660 -- definition node. This procedure analyzes the components in this
661 -- record type definition. Prev_T is the entity for the enclosing record
662 -- type. It is provided so that its Has_Task flag can be set if any of
663 -- the component have Has_Task set. If the declaration is the completion
664 -- of an incomplete type declaration, Prev_T is the original incomplete
665 -- type, whose full view is the record type.
667 procedure Replace_Components
(Typ
: Entity_Id
; Decl
: Node_Id
);
668 -- Subsidiary to Build_Derived_Record_Type. For untagged records, we
669 -- build a copy of the declaration tree of the parent, and we create
670 -- independently the list of components for the derived type. Semantic
671 -- information uses the component entities, but record representation
672 -- clauses are validated on the declaration tree. This procedure replaces
673 -- discriminants and components in the declaration with those that have
674 -- been created by Inherit_Components.
676 procedure Set_Fixed_Range
681 -- Build a range node with the given bounds and set it as the Scalar_Range
682 -- of the given fixed-point type entity. Loc is the source location used
683 -- for the constructed range. See body for further details.
685 procedure Set_Scalar_Range_For_Subtype
689 -- This routine is used to set the scalar range field for a subtype given
690 -- Def_Id, the entity for the subtype, and R, the range expression for the
691 -- scalar range. Subt provides the parent subtype to be used to analyze,
692 -- resolve, and check the given range.
694 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
695 -- Create a new signed integer entity, and apply the constraint to obtain
696 -- the required first named subtype of this type.
698 procedure Set_Stored_Constraint_From_Discriminant_Constraint
700 -- E is some record type. This routine computes E's Stored_Constraint
701 -- from its Discriminant_Constraint.
703 -----------------------
704 -- Access_Definition --
705 -----------------------
707 function Access_Definition
708 (Related_Nod
: Node_Id
;
709 N
: Node_Id
) return Entity_Id
711 Loc
: constant Source_Ptr
:= Sloc
(Related_Nod
);
712 Anon_Type
: Entity_Id
;
713 Anon_Scope
: Entity_Id
;
714 Desig_Type
: Entity_Id
;
718 if Is_Entry
(Current_Scope
)
719 and then Is_Task_Type
(Etype
(Scope
(Current_Scope
)))
721 Error_Msg_N
("task entries cannot have access parameters", N
);
725 -- Ada 2005: for an object declaration the corresponding anonymous
726 -- type is declared in the current scope.
728 -- If the access definition is the return type of another access to
729 -- function, scope is the current one, because it is the one of the
730 -- current type declaration.
732 if Nkind
(Related_Nod
) = N_Object_Declaration
733 or else Nkind
(Related_Nod
) = N_Access_Function_Definition
735 Anon_Scope
:= Current_Scope
;
737 -- For the anonymous function result case, retrieve the scope of the
738 -- function specification's associated entity rather than using the
739 -- current scope. The current scope will be the function itself if the
740 -- formal part is currently being analyzed, but will be the parent scope
741 -- in the case of a parameterless function, and we always want to use
742 -- the function's parent scope. Finally, if the function is a child
743 -- unit, we must traverse the the tree to retrieve the proper entity.
745 elsif Nkind
(Related_Nod
) = N_Function_Specification
746 and then Nkind
(Parent
(N
)) /= N_Parameter_Specification
748 -- If the current scope is a protected type, the anonymous access
749 -- is associated with one of the protected operations, and must
750 -- be available in the scope that encloses the protected declaration.
751 -- Otherwise the type is is in the scope enclosing the subprogram.
753 if Ekind
(Current_Scope
) = E_Protected_Type
then
754 Anon_Scope
:= Scope
(Scope
(Defining_Entity
(Related_Nod
)));
756 Anon_Scope
:= Scope
(Defining_Entity
(Related_Nod
));
760 -- For access formals, access components, and access discriminants,
761 -- the scope is that of the enclosing declaration,
763 Anon_Scope
:= Scope
(Current_Scope
);
768 (E_Anonymous_Access_Type
, Related_Nod
, Scope_Id
=> Anon_Scope
);
771 and then Ada_Version
>= Ada_05
773 Error_Msg_N
("ALL is not permitted for anonymous access types", N
);
776 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
777 -- the corresponding semantic routine
779 if Present
(Access_To_Subprogram_Definition
(N
)) then
780 Access_Subprogram_Declaration
781 (T_Name
=> Anon_Type
,
782 T_Def
=> Access_To_Subprogram_Definition
(N
));
784 if Ekind
(Anon_Type
) = E_Access_Protected_Subprogram_Type
then
786 (Anon_Type
, E_Anonymous_Access_Protected_Subprogram_Type
);
789 (Anon_Type
, E_Anonymous_Access_Subprogram_Type
);
792 -- If the anonymous access is associated with a protected operation
793 -- create a reference to it after the enclosing protected definition
794 -- because the itype will be used in the subsequent bodies.
796 if Ekind
(Current_Scope
) = E_Protected_Type
then
797 Build_Itype_Reference
(Anon_Type
, Parent
(Current_Scope
));
803 Find_Type
(Subtype_Mark
(N
));
804 Desig_Type
:= Entity
(Subtype_Mark
(N
));
806 Set_Directly_Designated_Type
807 (Anon_Type
, Desig_Type
);
808 Set_Etype
(Anon_Type
, Anon_Type
);
809 Init_Size_Align
(Anon_Type
);
810 Set_Depends_On_Private
(Anon_Type
, Has_Private_Component
(Anon_Type
));
812 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
813 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
814 -- the null value is allowed. In Ada 95 the null value is never allowed.
816 if Ada_Version
>= Ada_05
then
817 Set_Can_Never_Be_Null
(Anon_Type
, Null_Exclusion_Present
(N
));
819 Set_Can_Never_Be_Null
(Anon_Type
, True);
822 -- The anonymous access type is as public as the discriminated type or
823 -- subprogram that defines it. It is imported (for back-end purposes)
824 -- if the designated type is.
826 Set_Is_Public
(Anon_Type
, Is_Public
(Scope
(Anon_Type
)));
828 -- Ada 2005 (AI-50217): Propagate the attribute that indicates that the
829 -- designated type comes from the limited view.
831 Set_From_With_Type
(Anon_Type
, From_With_Type
(Desig_Type
));
833 -- Ada 2005 (AI-231): Propagate the access-constant attribute
835 Set_Is_Access_Constant
(Anon_Type
, Constant_Present
(N
));
837 -- The context is either a subprogram declaration, object declaration,
838 -- or an access discriminant, in a private or a full type declaration.
839 -- In the case of a subprogram, if the designated type is incomplete,
840 -- the operation will be a primitive operation of the full type, to be
841 -- updated subsequently. If the type is imported through a limited_with
842 -- clause, the subprogram is not a primitive operation of the type
843 -- (which is declared elsewhere in some other scope).
845 if Ekind
(Desig_Type
) = E_Incomplete_Type
846 and then not From_With_Type
(Desig_Type
)
847 and then Is_Overloadable
(Current_Scope
)
849 Append_Elmt
(Current_Scope
, Private_Dependents
(Desig_Type
));
850 Set_Has_Delayed_Freeze
(Current_Scope
);
853 -- Ada 2005: if the designated type is an interface that may contain
854 -- tasks, create a Master entity for the declaration. This must be done
855 -- before expansion of the full declaration, because the declaration may
856 -- include an expression that is an allocator, whose expansion needs the
857 -- proper Master for the created tasks.
859 if Nkind
(Related_Nod
) = N_Object_Declaration
860 and then Expander_Active
862 if Is_Interface
(Desig_Type
)
863 and then Is_Limited_Record
(Desig_Type
)
865 Build_Class_Wide_Master
(Anon_Type
);
867 -- Similarly, if the type is an anonymous access that designates
868 -- tasks, create a master entity for it in the current context.
870 elsif Has_Task
(Desig_Type
)
871 and then Comes_From_Source
(Related_Nod
)
873 if not Has_Master_Entity
(Current_Scope
) then
875 Make_Object_Declaration
(Loc
,
876 Defining_Identifier
=>
877 Make_Defining_Identifier
(Loc
, Name_uMaster
),
878 Constant_Present
=> True,
880 New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
882 Make_Explicit_Dereference
(Loc
,
883 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
885 Insert_Before
(Related_Nod
, Decl
);
888 Set_Master_Id
(Anon_Type
, Defining_Identifier
(Decl
));
889 Set_Has_Master_Entity
(Current_Scope
);
891 Build_Master_Renaming
(Related_Nod
, Anon_Type
);
896 -- For a private component of a protected type, it is imperative that
897 -- the back-end elaborate the type immediately after the protected
898 -- declaration, because this type will be used in the declarations
899 -- created for the component within each protected body, so we must
900 -- create an itype reference for it now.
902 if Nkind
(Parent
(Related_Nod
)) = N_Protected_Definition
then
903 Build_Itype_Reference
(Anon_Type
, Parent
(Parent
(Related_Nod
)));
907 end Access_Definition
;
909 -----------------------------------
910 -- Access_Subprogram_Declaration --
911 -----------------------------------
913 procedure Access_Subprogram_Declaration
917 Formals
: constant List_Id
:= Parameter_Specifications
(T_Def
);
921 Desig_Type
: constant Entity_Id
:=
922 Create_Itype
(E_Subprogram_Type
, Parent
(T_Def
));
925 -- Associate the Itype node with the inner full-type declaration or
926 -- subprogram spec. This is required to handle nested anonymous
927 -- declarations. For example:
930 -- (X : access procedure
931 -- (Y : access procedure
934 D_Ityp
:= Associated_Node_For_Itype
(Desig_Type
);
935 while Nkind
(D_Ityp
) /= N_Full_Type_Declaration
936 and then Nkind
(D_Ityp
) /= N_Private_Type_Declaration
937 and then Nkind
(D_Ityp
) /= N_Private_Extension_Declaration
938 and then Nkind
(D_Ityp
) /= N_Procedure_Specification
939 and then Nkind
(D_Ityp
) /= N_Function_Specification
940 and then Nkind
(D_Ityp
) /= N_Object_Declaration
941 and then Nkind
(D_Ityp
) /= N_Object_Renaming_Declaration
942 and then Nkind
(D_Ityp
) /= N_Formal_Type_Declaration
943 and then Nkind
(D_Ityp
) /= N_Task_Type_Declaration
944 and then Nkind
(D_Ityp
) /= N_Protected_Type_Declaration
946 D_Ityp
:= Parent
(D_Ityp
);
947 pragma Assert
(D_Ityp
/= Empty
);
950 Set_Associated_Node_For_Itype
(Desig_Type
, D_Ityp
);
952 if Nkind
(D_Ityp
) = N_Procedure_Specification
953 or else Nkind
(D_Ityp
) = N_Function_Specification
955 Set_Scope
(Desig_Type
, Scope
(Defining_Entity
(D_Ityp
)));
957 elsif Nkind
(D_Ityp
) = N_Full_Type_Declaration
958 or else Nkind
(D_Ityp
) = N_Object_Declaration
959 or else Nkind
(D_Ityp
) = N_Object_Renaming_Declaration
960 or else Nkind
(D_Ityp
) = N_Formal_Type_Declaration
962 Set_Scope
(Desig_Type
, Scope
(Defining_Identifier
(D_Ityp
)));
965 if Nkind
(T_Def
) = N_Access_Function_Definition
then
966 if Nkind
(Result_Definition
(T_Def
)) = N_Access_Definition
then
969 Acc
: constant Node_Id
:= Result_Definition
(T_Def
);
972 if Present
(Access_To_Subprogram_Definition
(Acc
))
974 Protected_Present
(Access_To_Subprogram_Definition
(Acc
))
978 Replace_Anonymous_Access_To_Protected_Subprogram
984 Access_Definition
(T_Def
, Result_Definition
(T_Def
)));
989 Analyze
(Result_Definition
(T_Def
));
990 Set_Etype
(Desig_Type
, Entity
(Result_Definition
(T_Def
)));
993 if not (Is_Type
(Etype
(Desig_Type
))) then
995 ("expect type in function specification",
996 Result_Definition
(T_Def
));
1000 Set_Etype
(Desig_Type
, Standard_Void_Type
);
1003 if Present
(Formals
) then
1004 Push_Scope
(Desig_Type
);
1005 Process_Formals
(Formals
, Parent
(T_Def
));
1007 -- A bit of a kludge here, End_Scope requires that the parent
1008 -- pointer be set to something reasonable, but Itypes don't have
1009 -- parent pointers. So we set it and then unset it ??? If and when
1010 -- Itypes have proper parent pointers to their declarations, this
1011 -- kludge can be removed.
1013 Set_Parent
(Desig_Type
, T_Name
);
1015 Set_Parent
(Desig_Type
, Empty
);
1018 -- The return type and/or any parameter type may be incomplete. Mark
1019 -- the subprogram_type as depending on the incomplete type, so that
1020 -- it can be updated when the full type declaration is seen. This
1021 -- only applies to incomplete types declared in some enclosing scope,
1022 -- not to limited views from other packages.
1024 if Present
(Formals
) then
1025 Formal
:= First_Formal
(Desig_Type
);
1026 while Present
(Formal
) loop
1027 if Ekind
(Formal
) /= E_In_Parameter
1028 and then Nkind
(T_Def
) = N_Access_Function_Definition
1030 Error_Msg_N
("functions can only have IN parameters", Formal
);
1033 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
1034 and then In_Open_Scopes
(Scope
(Etype
(Formal
)))
1036 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Formal
)));
1037 Set_Has_Delayed_Freeze
(Desig_Type
);
1040 Next_Formal
(Formal
);
1044 if Ekind
(Etype
(Desig_Type
)) = E_Incomplete_Type
1045 and then not Has_Delayed_Freeze
(Desig_Type
)
1047 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Desig_Type
)));
1048 Set_Has_Delayed_Freeze
(Desig_Type
);
1051 Check_Delayed_Subprogram
(Desig_Type
);
1053 if Protected_Present
(T_Def
) then
1054 Set_Ekind
(T_Name
, E_Access_Protected_Subprogram_Type
);
1055 Set_Convention
(Desig_Type
, Convention_Protected
);
1057 Set_Ekind
(T_Name
, E_Access_Subprogram_Type
);
1060 Set_Etype
(T_Name
, T_Name
);
1061 Init_Size_Align
(T_Name
);
1062 Set_Directly_Designated_Type
(T_Name
, Desig_Type
);
1064 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1066 Set_Can_Never_Be_Null
(T_Name
, Null_Exclusion_Present
(T_Def
));
1068 Check_Restriction
(No_Access_Subprograms
, T_Def
);
1069 end Access_Subprogram_Declaration
;
1071 ----------------------------
1072 -- Access_Type_Declaration --
1073 ----------------------------
1075 procedure Access_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
1076 S
: constant Node_Id
:= Subtype_Indication
(Def
);
1077 P
: constant Node_Id
:= Parent
(Def
);
1083 -- Check for permissible use of incomplete type
1085 if Nkind
(S
) /= N_Subtype_Indication
then
1088 if Ekind
(Root_Type
(Entity
(S
))) = E_Incomplete_Type
then
1089 Set_Directly_Designated_Type
(T
, Entity
(S
));
1091 Set_Directly_Designated_Type
(T
,
1092 Process_Subtype
(S
, P
, T
, 'P'));
1096 Set_Directly_Designated_Type
(T
,
1097 Process_Subtype
(S
, P
, T
, 'P'));
1100 if All_Present
(Def
) or Constant_Present
(Def
) then
1101 Set_Ekind
(T
, E_General_Access_Type
);
1103 Set_Ekind
(T
, E_Access_Type
);
1106 if Base_Type
(Designated_Type
(T
)) = T
then
1107 Error_Msg_N
("access type cannot designate itself", S
);
1109 -- In Ada 2005, the type may have a limited view through some unit
1110 -- in its own context, allowing the following circularity that cannot
1111 -- be detected earlier
1113 elsif Is_Class_Wide_Type
(Designated_Type
(T
))
1114 and then Etype
(Designated_Type
(T
)) = T
1117 ("access type cannot designate its own classwide type", S
);
1119 -- Clean up indication of tagged status to prevent cascaded errors
1121 Set_Is_Tagged_Type
(T
, False);
1126 -- If the type has appeared already in a with_type clause, it is
1127 -- frozen and the pointer size is already set. Else, initialize.
1129 if not From_With_Type
(T
) then
1130 Init_Size_Align
(T
);
1133 Desig
:= Designated_Type
(T
);
1135 -- If designated type is an imported tagged type, indicate that the
1136 -- access type is also imported, and therefore restricted in its use.
1137 -- The access type may already be imported, so keep setting otherwise.
1139 -- Ada 2005 (AI-50217): If the non-limited view of the designated type
1140 -- is available, use it as the designated type of the access type, so
1141 -- that the back-end gets a usable entity.
1143 if From_With_Type
(Desig
)
1144 and then Ekind
(Desig
) /= E_Access_Type
1146 Set_From_With_Type
(T
);
1149 -- Note that Has_Task is always false, since the access type itself
1150 -- is not a task type. See Einfo for more description on this point.
1151 -- Exactly the same consideration applies to Has_Controlled_Component.
1153 Set_Has_Task
(T
, False);
1154 Set_Has_Controlled_Component
(T
, False);
1156 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1159 Set_Can_Never_Be_Null
(T
, Null_Exclusion_Present
(Def
));
1160 Set_Is_Access_Constant
(T
, Constant_Present
(Def
));
1161 end Access_Type_Declaration
;
1163 ----------------------------------
1164 -- Add_Interface_Tag_Components --
1165 ----------------------------------
1167 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
) is
1168 Loc
: constant Source_Ptr
:= Sloc
(N
);
1175 procedure Add_Sync_Iface_Tags
(T
: Entity_Id
);
1176 -- Local subprogram used to recursively climb through the parents
1177 -- of T to add the tags of all the progenitor interfaces.
1179 procedure Add_Tag
(Iface
: Entity_Id
);
1180 -- Add tag for one of the progenitor interfaces
1182 -------------------------
1183 -- Add_Sync_Iface_Tags --
1184 -------------------------
1186 procedure Add_Sync_Iface_Tags
(T
: Entity_Id
) is
1188 if Etype
(T
) /= T
then
1189 Add_Sync_Iface_Tags
(Etype
(T
));
1192 Elmt
:= First_Elmt
(Abstract_Interfaces
(T
));
1193 while Present
(Elmt
) loop
1194 Add_Tag
(Node
(Elmt
));
1197 end Add_Sync_Iface_Tags
;
1203 procedure Add_Tag
(Iface
: Entity_Id
) is
1210 pragma Assert
(Is_Tagged_Type
(Iface
)
1211 and then Is_Interface
(Iface
));
1214 Make_Component_Definition
(Loc
,
1215 Aliased_Present
=> True,
1216 Subtype_Indication
=>
1217 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
));
1219 Tag
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('V'));
1222 Make_Component_Declaration
(Loc
,
1223 Defining_Identifier
=> Tag
,
1224 Component_Definition
=> Def
);
1226 Analyze_Component_Declaration
(Decl
);
1228 Set_Analyzed
(Decl
);
1229 Set_Ekind
(Tag
, E_Component
);
1231 Set_Is_Aliased
(Tag
);
1232 Set_Related_Interface
(Tag
, Iface
);
1233 Init_Component_Location
(Tag
);
1235 pragma Assert
(Is_Frozen
(Iface
));
1237 Set_DT_Entry_Count
(Tag
,
1238 DT_Entry_Count
(First_Entity
(Iface
)));
1240 if No
(Last_Tag
) then
1243 Insert_After
(Last_Tag
, Decl
);
1248 -- If the ancestor has discriminants we need to give special support
1249 -- to store the offset_to_top value of the secondary dispatch tables.
1250 -- For this purpose we add a supplementary component just after the
1251 -- field that contains the tag associated with each secondary DT.
1253 if Typ
/= Etype
(Typ
)
1254 and then Has_Discriminants
(Etype
(Typ
))
1257 Make_Component_Definition
(Loc
,
1258 Subtype_Indication
=>
1259 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
1262 Make_Defining_Identifier
(Loc
, New_Internal_Name
('V'));
1265 Make_Component_Declaration
(Loc
,
1266 Defining_Identifier
=> Offset
,
1267 Component_Definition
=> Def
);
1269 Analyze_Component_Declaration
(Decl
);
1271 Set_Analyzed
(Decl
);
1272 Set_Ekind
(Offset
, E_Component
);
1273 Set_Is_Aliased
(Offset
);
1274 Set_Related_Interface
(Offset
, Iface
);
1275 Init_Component_Location
(Offset
);
1276 Insert_After
(Last_Tag
, Decl
);
1283 Iface_List
: List_Id
;
1285 -- Start of processing for Add_Interface_Tag_Components
1288 if not RTE_Available
(RE_Interface_Tag
) then
1290 ("(Ada 2005) interface types not supported by this run-time!",
1295 if Ekind
(Typ
) /= E_Record_Type
1296 or else (Is_Concurrent_Record_Type
(Typ
)
1297 and then Is_Empty_List
(Abstract_Interface_List
(Typ
)))
1298 or else (not Is_Concurrent_Record_Type
(Typ
)
1299 and then No
(Abstract_Interfaces
(Typ
))
1300 and then Is_Empty_Elmt_List
(Abstract_Interfaces
(Typ
)))
1305 -- Find the current last tag
1307 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1308 Ext
:= Record_Extension_Part
(Type_Definition
(N
));
1310 pragma Assert
(Nkind
(Type_Definition
(N
)) = N_Record_Definition
);
1311 Ext
:= Type_Definition
(N
);
1316 if not (Present
(Component_List
(Ext
))) then
1317 Set_Null_Present
(Ext
, False);
1319 Set_Component_List
(Ext
,
1320 Make_Component_List
(Loc
,
1321 Component_Items
=> L
,
1322 Null_Present
=> False));
1324 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1325 L
:= Component_Items
1327 (Record_Extension_Part
1328 (Type_Definition
(N
))));
1330 L
:= Component_Items
1332 (Type_Definition
(N
)));
1335 -- Find the last tag component
1338 while Present
(Comp
) loop
1339 if Nkind
(Comp
) = N_Component_Declaration
1340 and then Is_Tag
(Defining_Identifier
(Comp
))
1349 -- At this point L references the list of components and Last_Tag
1350 -- references the current last tag (if any). Now we add the tag
1351 -- corresponding with all the interfaces that are not implemented
1354 if Is_Concurrent_Record_Type
(Typ
) then
1355 Iface_List
:= Abstract_Interface_List
(Typ
);
1357 if Is_Non_Empty_List
(Iface_List
) then
1358 Add_Sync_Iface_Tags
(Etype
(First
(Iface_List
)));
1362 if Present
(Abstract_Interfaces
(Typ
)) then
1363 Elmt
:= First_Elmt
(Abstract_Interfaces
(Typ
));
1364 while Present
(Elmt
) loop
1365 Add_Tag
(Node
(Elmt
));
1369 end Add_Interface_Tag_Components
;
1371 -----------------------------------
1372 -- Analyze_Component_Declaration --
1373 -----------------------------------
1375 procedure Analyze_Component_Declaration
(N
: Node_Id
) is
1376 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1377 E
: constant Node_Id
:= Expression
(N
);
1381 function Contains_POC
(Constr
: Node_Id
) return Boolean;
1382 -- Determines whether a constraint uses the discriminant of a record
1383 -- type thus becoming a per-object constraint (POC).
1385 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean;
1386 -- Typ is the type of the current component, check whether this type is
1387 -- a limited type. Used to validate declaration against that of
1388 -- enclosing record.
1394 function Contains_POC
(Constr
: Node_Id
) return Boolean is
1396 -- Prevent cascaded errors
1398 if Error_Posted
(Constr
) then
1402 case Nkind
(Constr
) is
1403 when N_Attribute_Reference
=>
1405 Attribute_Name
(Constr
) = Name_Access
1406 and then Prefix
(Constr
) = Scope
(Entity
(Prefix
(Constr
)));
1408 when N_Discriminant_Association
=>
1409 return Denotes_Discriminant
(Expression
(Constr
));
1411 when N_Identifier
=>
1412 return Denotes_Discriminant
(Constr
);
1414 when N_Index_Or_Discriminant_Constraint
=>
1419 IDC
:= First
(Constraints
(Constr
));
1420 while Present
(IDC
) loop
1422 -- One per-object constraint is sufficient
1424 if Contains_POC
(IDC
) then
1435 return Denotes_Discriminant
(Low_Bound
(Constr
))
1437 Denotes_Discriminant
(High_Bound
(Constr
));
1439 when N_Range_Constraint
=>
1440 return Denotes_Discriminant
(Range_Expression
(Constr
));
1448 ----------------------
1449 -- Is_Known_Limited --
1450 ----------------------
1452 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean is
1453 P
: constant Entity_Id
:= Etype
(Typ
);
1454 R
: constant Entity_Id
:= Root_Type
(Typ
);
1457 if Is_Limited_Record
(Typ
) then
1460 -- If the root type is limited (and not a limited interface)
1461 -- so is the current type
1463 elsif Is_Limited_Record
(R
)
1465 (not Is_Interface
(R
)
1466 or else not Is_Limited_Interface
(R
))
1470 -- Else the type may have a limited interface progenitor, but a
1471 -- limited record parent.
1474 and then Is_Limited_Record
(P
)
1481 end Is_Known_Limited
;
1483 -- Start of processing for Analyze_Component_Declaration
1486 Generate_Definition
(Id
);
1489 if Present
(Subtype_Indication
(Component_Definition
(N
))) then
1490 T
:= Find_Type_Of_Object
1491 (Subtype_Indication
(Component_Definition
(N
)), N
);
1493 -- Ada 2005 (AI-230): Access Definition case
1496 pragma Assert
(Present
1497 (Access_Definition
(Component_Definition
(N
))));
1499 T
:= Access_Definition
1501 N
=> Access_Definition
(Component_Definition
(N
)));
1502 Set_Is_Local_Anonymous_Access
(T
);
1504 -- Ada 2005 (AI-254)
1506 if Present
(Access_To_Subprogram_Definition
1507 (Access_Definition
(Component_Definition
(N
))))
1508 and then Protected_Present
(Access_To_Subprogram_Definition
1510 (Component_Definition
(N
))))
1512 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
1516 -- If the subtype is a constrained subtype of the enclosing record,
1517 -- (which must have a partial view) the back-end does not properly
1518 -- handle the recursion. Rewrite the component declaration with an
1519 -- explicit subtype indication, which is acceptable to Gigi. We can copy
1520 -- the tree directly because side effects have already been removed from
1521 -- discriminant constraints.
1523 if Ekind
(T
) = E_Access_Subtype
1524 and then Is_Entity_Name
(Subtype_Indication
(Component_Definition
(N
)))
1525 and then Comes_From_Source
(T
)
1526 and then Nkind
(Parent
(T
)) = N_Subtype_Declaration
1527 and then Etype
(Directly_Designated_Type
(T
)) = Current_Scope
1530 (Subtype_Indication
(Component_Definition
(N
)),
1531 New_Copy_Tree
(Subtype_Indication
(Parent
(T
))));
1532 T
:= Find_Type_Of_Object
1533 (Subtype_Indication
(Component_Definition
(N
)), N
);
1536 -- If the component declaration includes a default expression, then we
1537 -- check that the component is not of a limited type (RM 3.7(5)),
1538 -- and do the special preanalysis of the expression (see section on
1539 -- "Handling of Default and Per-Object Expressions" in the spec of
1543 Analyze_Per_Use_Expression
(E
, T
);
1544 Check_Initialization
(T
, E
);
1546 if Ada_Version
>= Ada_05
1547 and then Ekind
(T
) = E_Anonymous_Access_Type
1549 -- Check RM 3.9.2(9): "if the expected type for an expression is
1550 -- an anonymous access-to-specific tagged type, then the object
1551 -- designated by the expression shall not be dynamically tagged
1552 -- unless it is a controlling operand in a call on a dispatching
1555 if Is_Tagged_Type
(Directly_Designated_Type
(T
))
1557 Ekind
(Directly_Designated_Type
(T
)) /= E_Class_Wide_Type
1559 Ekind
(Directly_Designated_Type
(Etype
(E
))) =
1563 ("access to specific tagged type required (RM 3.9.2(9))", E
);
1566 -- (Ada 2005: AI-230): Accessibility check for anonymous
1569 if Type_Access_Level
(Etype
(E
)) > Type_Access_Level
(T
) then
1571 ("expression has deeper access level than component " &
1572 "(RM 3.10.2 (12.2))", E
);
1575 -- The initialization expression is a reference to an access
1576 -- discriminant. The type of the discriminant is always deeper
1577 -- than any access type.
1579 if Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
1580 and then Is_Entity_Name
(E
)
1581 and then Ekind
(Entity
(E
)) = E_In_Parameter
1582 and then Present
(Discriminal_Link
(Entity
(E
)))
1585 ("discriminant has deeper accessibility level than target",
1591 -- The parent type may be a private view with unknown discriminants,
1592 -- and thus unconstrained. Regular components must be constrained.
1594 if Is_Indefinite_Subtype
(T
) and then Chars
(Id
) /= Name_uParent
then
1595 if Is_Class_Wide_Type
(T
) then
1597 ("class-wide subtype with unknown discriminants" &
1598 " in component declaration",
1599 Subtype_Indication
(Component_Definition
(N
)));
1602 ("unconstrained subtype in component declaration",
1603 Subtype_Indication
(Component_Definition
(N
)));
1606 -- Components cannot be abstract, except for the special case of
1607 -- the _Parent field (case of extending an abstract tagged type)
1609 elsif Is_Abstract_Type
(T
) and then Chars
(Id
) /= Name_uParent
then
1610 Error_Msg_N
("type of a component cannot be abstract", N
);
1614 Set_Is_Aliased
(Id
, Aliased_Present
(Component_Definition
(N
)));
1616 -- The component declaration may have a per-object constraint, set
1617 -- the appropriate flag in the defining identifier of the subtype.
1619 if Present
(Subtype_Indication
(Component_Definition
(N
))) then
1621 Sindic
: constant Node_Id
:=
1622 Subtype_Indication
(Component_Definition
(N
));
1625 if Nkind
(Sindic
) = N_Subtype_Indication
1626 and then Present
(Constraint
(Sindic
))
1627 and then Contains_POC
(Constraint
(Sindic
))
1629 Set_Has_Per_Object_Constraint
(Id
);
1634 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
1635 -- out some static checks.
1637 if Ada_Version
>= Ada_05
1638 and then Can_Never_Be_Null
(T
)
1640 Null_Exclusion_Static_Checks
(N
);
1643 -- If this component is private (or depends on a private type), flag the
1644 -- record type to indicate that some operations are not available.
1646 P
:= Private_Component
(T
);
1650 -- Check for circular definitions
1652 if P
= Any_Type
then
1653 Set_Etype
(Id
, Any_Type
);
1655 -- There is a gap in the visibility of operations only if the
1656 -- component type is not defined in the scope of the record type.
1658 elsif Scope
(P
) = Scope
(Current_Scope
) then
1661 elsif Is_Limited_Type
(P
) then
1662 Set_Is_Limited_Composite
(Current_Scope
);
1665 Set_Is_Private_Composite
(Current_Scope
);
1670 and then Is_Limited_Type
(T
)
1671 and then Chars
(Id
) /= Name_uParent
1672 and then Is_Tagged_Type
(Current_Scope
)
1674 if Is_Derived_Type
(Current_Scope
)
1675 and then not Is_Known_Limited
(Current_Scope
)
1678 ("extension of nonlimited type cannot have limited components",
1681 if Is_Interface
(Root_Type
(Current_Scope
)) then
1683 ("\limitedness is not inherited from limited interface", N
);
1685 ("\add LIMITED to type indication", N
);
1688 Explain_Limited_Type
(T
, N
);
1689 Set_Etype
(Id
, Any_Type
);
1690 Set_Is_Limited_Composite
(Current_Scope
, False);
1692 elsif not Is_Derived_Type
(Current_Scope
)
1693 and then not Is_Limited_Record
(Current_Scope
)
1694 and then not Is_Concurrent_Type
(Current_Scope
)
1697 ("nonlimited tagged type cannot have limited components", N
);
1698 Explain_Limited_Type
(T
, N
);
1699 Set_Etype
(Id
, Any_Type
);
1700 Set_Is_Limited_Composite
(Current_Scope
, False);
1704 Set_Original_Record_Component
(Id
, Id
);
1705 end Analyze_Component_Declaration
;
1707 --------------------------
1708 -- Analyze_Declarations --
1709 --------------------------
1711 procedure Analyze_Declarations
(L
: List_Id
) is
1713 Freeze_From
: Entity_Id
:= Empty
;
1714 Next_Node
: Node_Id
;
1717 -- Adjust D not to include implicit label declarations, since these
1718 -- have strange Sloc values that result in elaboration check problems.
1719 -- (They have the sloc of the label as found in the source, and that
1720 -- is ahead of the current declarative part).
1726 procedure Adjust_D
is
1728 while Present
(Prev
(D
))
1729 and then Nkind
(D
) = N_Implicit_Label_Declaration
1735 -- Start of processing for Analyze_Declarations
1739 while Present
(D
) loop
1741 -- Complete analysis of declaration
1744 Next_Node
:= Next
(D
);
1746 if No
(Freeze_From
) then
1747 Freeze_From
:= First_Entity
(Current_Scope
);
1750 -- At the end of a declarative part, freeze remaining entities
1751 -- declared in it. The end of the visible declarations of package
1752 -- specification is not the end of a declarative part if private
1753 -- declarations are present. The end of a package declaration is a
1754 -- freezing point only if it a library package. A task definition or
1755 -- protected type definition is not a freeze point either. Finally,
1756 -- we do not freeze entities in generic scopes, because there is no
1757 -- code generated for them and freeze nodes will be generated for
1760 -- The end of a package instantiation is not a freeze point, but
1761 -- for now we make it one, because the generic body is inserted
1762 -- (currently) immediately after. Generic instantiations will not
1763 -- be a freeze point once delayed freezing of bodies is implemented.
1764 -- (This is needed in any case for early instantiations ???).
1766 if No
(Next_Node
) then
1767 if Nkind
(Parent
(L
)) = N_Component_List
1768 or else Nkind
(Parent
(L
)) = N_Task_Definition
1769 or else Nkind
(Parent
(L
)) = N_Protected_Definition
1773 elsif Nkind
(Parent
(L
)) /= N_Package_Specification
then
1774 if Nkind
(Parent
(L
)) = N_Package_Body
then
1775 Freeze_From
:= First_Entity
(Current_Scope
);
1779 Freeze_All
(Freeze_From
, D
);
1780 Freeze_From
:= Last_Entity
(Current_Scope
);
1782 elsif Scope
(Current_Scope
) /= Standard_Standard
1783 and then not Is_Child_Unit
(Current_Scope
)
1784 and then No
(Generic_Parent
(Parent
(L
)))
1788 elsif L
/= Visible_Declarations
(Parent
(L
))
1789 or else No
(Private_Declarations
(Parent
(L
)))
1790 or else Is_Empty_List
(Private_Declarations
(Parent
(L
)))
1793 Freeze_All
(Freeze_From
, D
);
1794 Freeze_From
:= Last_Entity
(Current_Scope
);
1797 -- If next node is a body then freeze all types before the body.
1798 -- An exception occurs for some expander-generated bodies. If these
1799 -- are generated at places where in general language rules would not
1800 -- allow a freeze point, then we assume that the expander has
1801 -- explicitly checked that all required types are properly frozen,
1802 -- and we do not cause general freezing here. This special circuit
1803 -- is used when the encountered body is marked as having already
1806 -- In all other cases (bodies that come from source, and expander
1807 -- generated bodies that have not been analyzed yet), freeze all
1808 -- types now. Note that in the latter case, the expander must take
1809 -- care to attach the bodies at a proper place in the tree so as to
1810 -- not cause unwanted freezing at that point.
1812 elsif not Analyzed
(Next_Node
)
1813 and then (Nkind
(Next_Node
) = N_Subprogram_Body
1814 or else Nkind
(Next_Node
) = N_Entry_Body
1815 or else Nkind
(Next_Node
) = N_Package_Body
1816 or else Nkind
(Next_Node
) = N_Protected_Body
1817 or else Nkind
(Next_Node
) = N_Task_Body
1818 or else Nkind
(Next_Node
) in N_Body_Stub
)
1821 Freeze_All
(Freeze_From
, D
);
1822 Freeze_From
:= Last_Entity
(Current_Scope
);
1827 end Analyze_Declarations
;
1829 ----------------------------------
1830 -- Analyze_Incomplete_Type_Decl --
1831 ----------------------------------
1833 procedure Analyze_Incomplete_Type_Decl
(N
: Node_Id
) is
1834 F
: constant Boolean := Is_Pure
(Current_Scope
);
1838 Generate_Definition
(Defining_Identifier
(N
));
1840 -- Process an incomplete declaration. The identifier must not have been
1841 -- declared already in the scope. However, an incomplete declaration may
1842 -- appear in the private part of a package, for a private type that has
1843 -- already been declared.
1845 -- In this case, the discriminants (if any) must match
1847 T
:= Find_Type_Name
(N
);
1849 Set_Ekind
(T
, E_Incomplete_Type
);
1850 Init_Size_Align
(T
);
1851 Set_Is_First_Subtype
(T
, True);
1854 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
1855 -- incomplete types.
1857 if Tagged_Present
(N
) then
1858 Set_Is_Tagged_Type
(T
);
1859 Make_Class_Wide_Type
(T
);
1860 Set_Primitive_Operations
(T
, New_Elmt_List
);
1865 Set_Stored_Constraint
(T
, No_Elist
);
1867 if Present
(Discriminant_Specifications
(N
)) then
1868 Process_Discriminants
(N
);
1873 -- If the type has discriminants, non-trivial subtypes may be be
1874 -- declared before the full view of the type. The full views of those
1875 -- subtypes will be built after the full view of the type.
1877 Set_Private_Dependents
(T
, New_Elmt_List
);
1879 end Analyze_Incomplete_Type_Decl
;
1881 -----------------------------------
1882 -- Analyze_Interface_Declaration --
1883 -----------------------------------
1885 procedure Analyze_Interface_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
1886 CW
: constant Entity_Id
:= Class_Wide_Type
(T
);
1889 Set_Is_Tagged_Type
(T
);
1891 Set_Is_Limited_Record
(T
, Limited_Present
(Def
)
1892 or else Task_Present
(Def
)
1893 or else Protected_Present
(Def
)
1894 or else Synchronized_Present
(Def
));
1896 -- Type is abstract if full declaration carries keyword, or if previous
1897 -- partial view did.
1899 Set_Is_Abstract_Type
(T
);
1900 Set_Is_Interface
(T
);
1902 -- Type is a limited interface if it includes the keyword limited, task,
1903 -- protected, or synchronized.
1905 Set_Is_Limited_Interface
1906 (T
, Limited_Present
(Def
)
1907 or else Protected_Present
(Def
)
1908 or else Synchronized_Present
(Def
)
1909 or else Task_Present
(Def
));
1911 Set_Is_Protected_Interface
(T
, Protected_Present
(Def
));
1912 Set_Is_Task_Interface
(T
, Task_Present
(Def
));
1914 -- Type is a synchronized interface if it includes the keyword task,
1915 -- protected, or synchronized.
1917 Set_Is_Synchronized_Interface
1918 (T
, Synchronized_Present
(Def
)
1919 or else Protected_Present
(Def
)
1920 or else Task_Present
(Def
));
1922 Set_Abstract_Interfaces
(T
, New_Elmt_List
);
1923 Set_Primitive_Operations
(T
, New_Elmt_List
);
1925 -- Complete the decoration of the class-wide entity if it was already
1926 -- built (ie. during the creation of the limited view)
1928 if Present
(CW
) then
1929 Set_Is_Interface
(CW
);
1930 Set_Is_Limited_Interface
(CW
, Is_Limited_Interface
(T
));
1931 Set_Is_Protected_Interface
(CW
, Is_Protected_Interface
(T
));
1932 Set_Is_Synchronized_Interface
(CW
, Is_Synchronized_Interface
(T
));
1933 Set_Is_Task_Interface
(CW
, Is_Task_Interface
(T
));
1935 end Analyze_Interface_Declaration
;
1937 -----------------------------
1938 -- Analyze_Itype_Reference --
1939 -----------------------------
1941 -- Nothing to do. This node is placed in the tree only for the benefit of
1942 -- back end processing, and has no effect on the semantic processing.
1944 procedure Analyze_Itype_Reference
(N
: Node_Id
) is
1946 pragma Assert
(Is_Itype
(Itype
(N
)));
1948 end Analyze_Itype_Reference
;
1950 --------------------------------
1951 -- Analyze_Number_Declaration --
1952 --------------------------------
1954 procedure Analyze_Number_Declaration
(N
: Node_Id
) is
1955 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1956 E
: constant Node_Id
:= Expression
(N
);
1958 Index
: Interp_Index
;
1962 Generate_Definition
(Id
);
1965 -- This is an optimization of a common case of an integer literal
1967 if Nkind
(E
) = N_Integer_Literal
then
1968 Set_Is_Static_Expression
(E
, True);
1969 Set_Etype
(E
, Universal_Integer
);
1971 Set_Etype
(Id
, Universal_Integer
);
1972 Set_Ekind
(Id
, E_Named_Integer
);
1973 Set_Is_Frozen
(Id
, True);
1977 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
1979 -- Process expression, replacing error by integer zero, to avoid
1980 -- cascaded errors or aborts further along in the processing
1982 -- Replace Error by integer zero, which seems least likely to
1983 -- cause cascaded errors.
1986 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), Uint_0
));
1987 Set_Error_Posted
(E
);
1992 -- Verify that the expression is static and numeric. If
1993 -- the expression is overloaded, we apply the preference
1994 -- rule that favors root numeric types.
1996 if not Is_Overloaded
(E
) then
2002 Get_First_Interp
(E
, Index
, It
);
2003 while Present
(It
.Typ
) loop
2004 if (Is_Integer_Type
(It
.Typ
)
2005 or else Is_Real_Type
(It
.Typ
))
2006 and then (Scope
(Base_Type
(It
.Typ
))) = Standard_Standard
2008 if T
= Any_Type
then
2011 elsif It
.Typ
= Universal_Real
2012 or else It
.Typ
= Universal_Integer
2014 -- Choose universal interpretation over any other
2021 Get_Next_Interp
(Index
, It
);
2025 if Is_Integer_Type
(T
) then
2027 Set_Etype
(Id
, Universal_Integer
);
2028 Set_Ekind
(Id
, E_Named_Integer
);
2030 elsif Is_Real_Type
(T
) then
2032 -- Because the real value is converted to universal_real, this is a
2033 -- legal context for a universal fixed expression.
2035 if T
= Universal_Fixed
then
2037 Loc
: constant Source_Ptr
:= Sloc
(N
);
2038 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
2040 New_Occurrence_Of
(Universal_Real
, Loc
),
2041 Expression
=> Relocate_Node
(E
));
2048 elsif T
= Any_Fixed
then
2049 Error_Msg_N
("illegal context for mixed mode operation", E
);
2051 -- Expression is of the form : universal_fixed * integer. Try to
2052 -- resolve as universal_real.
2054 T
:= Universal_Real
;
2059 Set_Etype
(Id
, Universal_Real
);
2060 Set_Ekind
(Id
, E_Named_Real
);
2063 Wrong_Type
(E
, Any_Numeric
);
2067 Set_Ekind
(Id
, E_Constant
);
2068 Set_Never_Set_In_Source
(Id
, True);
2069 Set_Is_True_Constant
(Id
, True);
2073 if Nkind
(E
) = N_Integer_Literal
2074 or else Nkind
(E
) = N_Real_Literal
2076 Set_Etype
(E
, Etype
(Id
));
2079 if not Is_OK_Static_Expression
(E
) then
2080 Flag_Non_Static_Expr
2081 ("non-static expression used in number declaration!", E
);
2082 Rewrite
(E
, Make_Integer_Literal
(Sloc
(N
), 1));
2083 Set_Etype
(E
, Any_Type
);
2085 end Analyze_Number_Declaration
;
2087 --------------------------------
2088 -- Analyze_Object_Declaration --
2089 --------------------------------
2091 procedure Analyze_Object_Declaration
(N
: Node_Id
) is
2092 Loc
: constant Source_Ptr
:= Sloc
(N
);
2093 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
2097 E
: Node_Id
:= Expression
(N
);
2098 -- E is set to Expression (N) throughout this routine. When
2099 -- Expression (N) is modified, E is changed accordingly.
2101 Prev_Entity
: Entity_Id
:= Empty
;
2103 function Count_Tasks
(T
: Entity_Id
) return Uint
;
2104 -- This function is called when a library level object of type is
2105 -- declared. It's function is to count the static number of tasks
2106 -- declared within the type (it is only called if Has_Tasks is set for
2107 -- T). As a side effect, if an array of tasks with non-static bounds or
2108 -- a variant record type is encountered, Check_Restrictions is called
2109 -- indicating the count is unknown.
2115 function Count_Tasks
(T
: Entity_Id
) return Uint
is
2121 if Is_Task_Type
(T
) then
2124 elsif Is_Record_Type
(T
) then
2125 if Has_Discriminants
(T
) then
2126 Check_Restriction
(Max_Tasks
, N
);
2131 C
:= First_Component
(T
);
2132 while Present
(C
) loop
2133 V
:= V
+ Count_Tasks
(Etype
(C
));
2140 elsif Is_Array_Type
(T
) then
2141 X
:= First_Index
(T
);
2142 V
:= Count_Tasks
(Component_Type
(T
));
2143 while Present
(X
) loop
2146 if not Is_Static_Subtype
(C
) then
2147 Check_Restriction
(Max_Tasks
, N
);
2150 V
:= V
* (UI_Max
(Uint_0
,
2151 Expr_Value
(Type_High_Bound
(C
)) -
2152 Expr_Value
(Type_Low_Bound
(C
)) + Uint_1
));
2165 -- Start of processing for Analyze_Object_Declaration
2168 -- There are three kinds of implicit types generated by an
2169 -- object declaration:
2171 -- 1. Those for generated by the original Object Definition
2173 -- 2. Those generated by the Expression
2175 -- 3. Those used to constrained the Object Definition with the
2176 -- expression constraints when it is unconstrained
2178 -- They must be generated in this order to avoid order of elaboration
2179 -- issues. Thus the first step (after entering the name) is to analyze
2180 -- the object definition.
2182 if Constant_Present
(N
) then
2183 Prev_Entity
:= Current_Entity_In_Scope
(Id
);
2185 -- If homograph is an implicit subprogram, it is overridden by the
2186 -- current declaration.
2188 if Present
(Prev_Entity
)
2189 and then Is_Overloadable
(Prev_Entity
)
2190 and then Is_Inherited_Operation
(Prev_Entity
)
2192 Prev_Entity
:= Empty
;
2196 if Present
(Prev_Entity
) then
2197 Constant_Redeclaration
(Id
, N
, T
);
2199 Generate_Reference
(Prev_Entity
, Id
, 'c');
2200 Set_Completion_Referenced
(Id
);
2202 if Error_Posted
(N
) then
2204 -- Type mismatch or illegal redeclaration, Do not analyze
2205 -- expression to avoid cascaded errors.
2207 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
2209 Set_Ekind
(Id
, E_Variable
);
2213 -- In the normal case, enter identifier at the start to catch premature
2214 -- usage in the initialization expression.
2217 Generate_Definition
(Id
);
2220 Mark_Coextensions
(N
, Object_Definition
(N
));
2222 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
2224 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
2226 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
2227 and then Protected_Present
2228 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
2230 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
2233 if Error_Posted
(Id
) then
2235 Set_Ekind
(Id
, E_Variable
);
2240 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2241 -- out some static checks
2243 if Ada_Version
>= Ada_05
2244 and then Can_Never_Be_Null
(T
)
2246 -- In case of aggregates we must also take care of the correct
2247 -- initialization of nested aggregates bug this is done at the
2248 -- point of the analysis of the aggregate (see sem_aggr.adb)
2250 if Present
(Expression
(N
))
2251 and then Nkind
(Expression
(N
)) = N_Aggregate
2257 Save_Typ
: constant Entity_Id
:= Etype
(Id
);
2259 Set_Etype
(Id
, T
); -- Temp. decoration for static checks
2260 Null_Exclusion_Static_Checks
(N
);
2261 Set_Etype
(Id
, Save_Typ
);
2266 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
2268 -- If deferred constant, make sure context is appropriate. We detect
2269 -- a deferred constant as a constant declaration with no expression.
2270 -- A deferred constant can appear in a package body if its completion
2271 -- is by means of an interface pragma.
2273 if Constant_Present
(N
)
2276 -- We exclude forward references to tags
2278 if Is_Imported
(Defining_Identifier
(N
))
2281 or else (Present
(Full_View
(T
))
2282 and then Full_View
(T
) = RTE
(RE_Tag
)))
2286 elsif not Is_Package_Or_Generic_Package
(Current_Scope
) then
2288 ("invalid context for deferred constant declaration (RM 7.4)",
2291 ("\declaration requires an initialization expression",
2293 Set_Constant_Present
(N
, False);
2295 -- In Ada 83, deferred constant must be of private type
2297 elsif not Is_Private_Type
(T
) then
2298 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2300 ("(Ada 83) deferred constant must be private type", N
);
2304 -- If not a deferred constant, then object declaration freezes its type
2307 Check_Fully_Declared
(T
, N
);
2308 Freeze_Before
(N
, T
);
2311 -- If the object was created by a constrained array definition, then
2312 -- set the link in both the anonymous base type and anonymous subtype
2313 -- that are built to represent the array type to point to the object.
2315 if Nkind
(Object_Definition
(Declaration_Node
(Id
))) =
2316 N_Constrained_Array_Definition
2318 Set_Related_Array_Object
(T
, Id
);
2319 Set_Related_Array_Object
(Base_Type
(T
), Id
);
2322 -- Special checks for protected objects not at library level
2324 if Is_Protected_Type
(T
)
2325 and then not Is_Library_Level_Entity
(Id
)
2327 Check_Restriction
(No_Local_Protected_Objects
, Id
);
2329 -- Protected objects with interrupt handlers must be at library level
2331 -- Ada 2005: this test is not needed (and the corresponding clause
2332 -- in the RM is removed) because accessibility checks are sufficient
2333 -- to make handlers not at the library level illegal.
2335 if Has_Interrupt_Handler
(T
)
2336 and then Ada_Version
< Ada_05
2339 ("interrupt object can only be declared at library level", Id
);
2343 -- The actual subtype of the object is the nominal subtype, unless
2344 -- the nominal one is unconstrained and obtained from the expression.
2348 -- Process initialization expression if present and not in error
2350 if Present
(E
) and then E
/= Error
then
2351 Mark_Coextensions
(N
, E
);
2354 -- In case of errors detected in the analysis of the expression,
2355 -- decorate it with the expected type to avoid cascade errors
2357 if No
(Etype
(E
)) then
2361 -- If an initialization expression is present, then we set the
2362 -- Is_True_Constant flag. It will be reset if this is a variable
2363 -- and it is indeed modified.
2365 Set_Is_True_Constant
(Id
, True);
2367 -- If we are analyzing a constant declaration, set its completion
2368 -- flag after analyzing the expression.
2370 if Constant_Present
(N
) then
2371 Set_Has_Completion
(Id
);
2374 Set_Etype
(Id
, T
); -- may be overridden later on
2377 if not Assignment_OK
(N
) then
2378 Check_Initialization
(T
, E
);
2381 Check_Unset_Reference
(E
);
2383 -- If this is a variable, then set current value
2385 if not Constant_Present
(N
) then
2386 if Compile_Time_Known_Value
(E
) then
2387 Set_Current_Value
(Id
, E
);
2391 -- Deal with setting of null flags
2393 if Is_Access_Type
(T
) then
2394 if Known_Non_Null
(E
) then
2395 Set_Is_Known_Non_Null
(Id
, True);
2396 elsif Known_Null
(E
)
2397 and then not Can_Never_Be_Null
(Id
)
2399 Set_Is_Known_Null
(Id
, True);
2403 -- Check incorrect use of dynamically tagged expressions. Note
2404 -- the use of Is_Tagged_Type (T) which seems redundant but is in
2405 -- fact important to avoid spurious errors due to expanded code
2406 -- for dispatching functions over an anonymous access type
2408 if (Is_Class_Wide_Type
(Etype
(E
)) or else Is_Dynamically_Tagged
(E
))
2409 and then Is_Tagged_Type
(T
)
2410 and then not Is_Class_Wide_Type
(T
)
2412 Error_Msg_N
("dynamically tagged expression not allowed!", E
);
2415 Apply_Scalar_Range_Check
(E
, T
);
2416 Apply_Static_Length_Check
(E
, T
);
2419 -- If the No_Streams restriction is set, check that the type of the
2420 -- object is not, and does not contain, any subtype derived from
2421 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
2422 -- Has_Stream just for efficiency reasons. There is no point in
2423 -- spending time on a Has_Stream check if the restriction is not set.
2425 if Restrictions
.Set
(No_Streams
) then
2426 if Has_Stream
(T
) then
2427 Check_Restriction
(No_Streams
, N
);
2431 -- Abstract type is never permitted for a variable or constant.
2432 -- Note: we inhibit this check for objects that do not come from
2433 -- source because there is at least one case (the expansion of
2434 -- x'class'input where x is abstract) where we legitimately
2435 -- generate an abstract object.
2437 if Is_Abstract_Type
(T
) and then Comes_From_Source
(N
) then
2438 Error_Msg_N
("type of object cannot be abstract",
2439 Object_Definition
(N
));
2441 if Is_CPP_Class
(T
) then
2442 Error_Msg_NE
("\} may need a cpp_constructor",
2443 Object_Definition
(N
), T
);
2446 -- Case of unconstrained type
2448 elsif Is_Indefinite_Subtype
(T
) then
2450 -- Nothing to do in deferred constant case
2452 if Constant_Present
(N
) and then No
(E
) then
2455 -- Case of no initialization present
2458 if No_Initialization
(N
) then
2461 elsif Is_Class_Wide_Type
(T
) then
2463 ("initialization required in class-wide declaration ", N
);
2467 ("unconstrained subtype not allowed (need initialization)",
2468 Object_Definition
(N
));
2471 -- Case of initialization present but in error. Set initial
2472 -- expression as absent (but do not make above complaints)
2474 elsif E
= Error
then
2475 Set_Expression
(N
, Empty
);
2478 -- Case of initialization present
2481 -- Not allowed in Ada 83
2483 if not Constant_Present
(N
) then
2484 if Ada_Version
= Ada_83
2485 and then Comes_From_Source
(Object_Definition
(N
))
2488 ("(Ada 83) unconstrained variable not allowed",
2489 Object_Definition
(N
));
2493 -- Now we constrain the variable from the initializing expression
2495 -- If the expression is an aggregate, it has been expanded into
2496 -- individual assignments. Retrieve the actual type from the
2497 -- expanded construct.
2499 if Is_Array_Type
(T
)
2500 and then No_Initialization
(N
)
2501 and then Nkind
(Original_Node
(E
)) = N_Aggregate
2506 Expand_Subtype_From_Expr
(N
, T
, Object_Definition
(N
), E
);
2507 Act_T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
2510 Set_Is_Constr_Subt_For_U_Nominal
(Act_T
);
2512 if Aliased_Present
(N
) then
2513 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
2516 Freeze_Before
(N
, Act_T
);
2517 Freeze_Before
(N
, T
);
2520 elsif Is_Array_Type
(T
)
2521 and then No_Initialization
(N
)
2522 and then Nkind
(Original_Node
(E
)) = N_Aggregate
2524 if not Is_Entity_Name
(Object_Definition
(N
)) then
2526 Check_Compile_Time_Size
(Act_T
);
2528 if Aliased_Present
(N
) then
2529 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
2533 -- When the given object definition and the aggregate are specified
2534 -- independently, and their lengths might differ do a length check.
2535 -- This cannot happen if the aggregate is of the form (others =>...)
2537 if not Is_Constrained
(T
) then
2540 elsif Nkind
(E
) = N_Raise_Constraint_Error
then
2542 -- Aggregate is statically illegal. Place back in declaration
2544 Set_Expression
(N
, E
);
2545 Set_No_Initialization
(N
, False);
2547 elsif T
= Etype
(E
) then
2550 elsif Nkind
(E
) = N_Aggregate
2551 and then Present
(Component_Associations
(E
))
2552 and then Present
(Choices
(First
(Component_Associations
(E
))))
2553 and then Nkind
(First
2554 (Choices
(First
(Component_Associations
(E
))))) = N_Others_Choice
2559 Apply_Length_Check
(E
, T
);
2562 -- If the type is limited unconstrained with defaulted discriminants
2563 -- and there is no expression, then the object is constrained by the
2564 -- defaults, so it is worthwhile building the corresponding subtype.
2566 elsif (Is_Limited_Record
(T
)
2567 or else Is_Concurrent_Type
(T
))
2568 and then not Is_Constrained
(T
)
2569 and then Has_Discriminants
(T
)
2572 Act_T
:= Build_Default_Subtype
(T
, N
);
2574 -- Ada 2005: a limited object may be initialized by means of an
2575 -- aggregate. If the type has default discriminants it has an
2576 -- unconstrained nominal type, Its actual subtype will be obtained
2577 -- from the aggregate, and not from the default discriminants.
2582 Rewrite
(Object_Definition
(N
), New_Occurrence_Of
(Act_T
, Loc
));
2584 elsif Present
(Underlying_Type
(T
))
2585 and then not Is_Constrained
(Underlying_Type
(T
))
2586 and then Has_Discriminants
(Underlying_Type
(T
))
2587 and then Nkind
(E
) = N_Function_Call
2588 and then Constant_Present
(N
)
2590 -- The back-end has problems with constants of a discriminated type
2591 -- with defaults, if the initial value is a function call. We
2592 -- generate an intermediate temporary for the result of the call.
2593 -- It is unclear why this should make it acceptable to gcc. ???
2595 Remove_Side_Effects
(E
);
2598 if T
= Standard_Wide_Character
or else T
= Standard_Wide_Wide_Character
2599 or else Root_Type
(T
) = Standard_Wide_String
2600 or else Root_Type
(T
) = Standard_Wide_Wide_String
2602 Check_Restriction
(No_Wide_Characters
, Object_Definition
(N
));
2605 -- Indicate this is not set in source. Certainly true for constants,
2606 -- and true for variables so far (will be reset for a variable if and
2607 -- when we encounter a modification in the source).
2609 Set_Never_Set_In_Source
(Id
, True);
2611 -- Now establish the proper kind and type of the object
2613 if Constant_Present
(N
) then
2614 Set_Ekind
(Id
, E_Constant
);
2615 Set_Is_True_Constant
(Id
, True);
2618 Set_Ekind
(Id
, E_Variable
);
2620 -- A variable is set as shared passive if it appears in a shared
2621 -- passive package, and is at the outer level. This is not done
2622 -- for entities generated during expansion, because those are
2623 -- always manipulated locally.
2625 if Is_Shared_Passive
(Current_Scope
)
2626 and then Is_Library_Level_Entity
(Id
)
2627 and then Comes_From_Source
(Id
)
2629 Set_Is_Shared_Passive
(Id
);
2630 Check_Shared_Var
(Id
, T
, N
);
2633 -- Set Has_Initial_Value if initializing expression present. Note
2634 -- that if there is no initializating expression, we leave the state
2635 -- of this flag unchanged (usually it will be False, but notably in
2636 -- the case of exception choice variables, it will already be true).
2639 Set_Has_Initial_Value
(Id
, True);
2643 -- Initialize alignment and size
2645 Init_Alignment
(Id
);
2648 -- Deal with aliased case
2650 if Aliased_Present
(N
) then
2651 Set_Is_Aliased
(Id
);
2653 -- If the object is aliased and the type is unconstrained with
2654 -- defaulted discriminants and there is no expression, then the
2655 -- object is constrained by the defaults, so it is worthwhile
2656 -- building the corresponding subtype.
2658 -- Ada 2005 (AI-363): If the aliased object is discriminated and
2659 -- unconstrained, then only establish an actual subtype if the
2660 -- nominal subtype is indefinite. In definite cases the object is
2661 -- unconstrained in Ada 2005.
2664 and then Is_Record_Type
(T
)
2665 and then not Is_Constrained
(T
)
2666 and then Has_Discriminants
(T
)
2667 and then (Ada_Version
< Ada_05
or else Is_Indefinite_Subtype
(T
))
2669 Set_Actual_Subtype
(Id
, Build_Default_Subtype
(T
, N
));
2673 -- Now we can set the type of the object
2675 Set_Etype
(Id
, Act_T
);
2677 -- Deal with controlled types
2679 if Has_Controlled_Component
(Etype
(Id
))
2680 or else Is_Controlled
(Etype
(Id
))
2682 if not Is_Library_Level_Entity
(Id
) then
2683 Check_Restriction
(No_Nested_Finalization
, N
);
2685 Validate_Controlled_Object
(Id
);
2688 -- Generate a warning when an initialization causes an obvious ABE
2689 -- violation. If the init expression is a simple aggregate there
2690 -- shouldn't be any initialize/adjust call generated. This will be
2691 -- true as soon as aggregates are built in place when possible.
2693 -- ??? at the moment we do not generate warnings for temporaries
2694 -- created for those aggregates although Program_Error might be
2695 -- generated if compiled with -gnato.
2697 if Is_Controlled
(Etype
(Id
))
2698 and then Comes_From_Source
(Id
)
2701 BT
: constant Entity_Id
:= Base_Type
(Etype
(Id
));
2703 Implicit_Call
: Entity_Id
;
2704 pragma Warnings
(Off
, Implicit_Call
);
2705 -- ??? what is this for (never referenced!)
2707 function Is_Aggr
(N
: Node_Id
) return Boolean;
2708 -- Check that N is an aggregate
2714 function Is_Aggr
(N
: Node_Id
) return Boolean is
2716 case Nkind
(Original_Node
(N
)) is
2717 when N_Aggregate | N_Extension_Aggregate
=>
2720 when N_Qualified_Expression |
2722 N_Unchecked_Type_Conversion
=>
2723 return Is_Aggr
(Expression
(Original_Node
(N
)));
2731 -- If no underlying type, we already are in an error situation.
2732 -- Do not try to add a warning since we do not have access to
2735 if No
(Underlying_Type
(BT
)) then
2736 Implicit_Call
:= Empty
;
2738 -- A generic type does not have usable primitive operators.
2739 -- Initialization calls are built for instances.
2741 elsif Is_Generic_Type
(BT
) then
2742 Implicit_Call
:= Empty
;
2744 -- If the init expression is not an aggregate, an adjust call
2745 -- will be generated
2747 elsif Present
(E
) and then not Is_Aggr
(E
) then
2748 Implicit_Call
:= Find_Prim_Op
(BT
, Name_Adjust
);
2750 -- If no init expression and we are not in the deferred
2751 -- constant case, an Initialize call will be generated
2753 elsif No
(E
) and then not Constant_Present
(N
) then
2754 Implicit_Call
:= Find_Prim_Op
(BT
, Name_Initialize
);
2757 Implicit_Call
:= Empty
;
2763 if Has_Task
(Etype
(Id
)) then
2764 Check_Restriction
(No_Tasking
, N
);
2766 if Is_Library_Level_Entity
(Id
) then
2767 Check_Restriction
(Max_Tasks
, N
, Count_Tasks
(Etype
(Id
)));
2769 Check_Restriction
(Max_Tasks
, N
);
2770 Check_Restriction
(No_Task_Hierarchy
, N
);
2771 Check_Potentially_Blocking_Operation
(N
);
2774 -- A rather specialized test. If we see two tasks being declared
2775 -- of the same type in the same object declaration, and the task
2776 -- has an entry with an address clause, we know that program error
2777 -- will be raised at run-time since we can't have two tasks with
2778 -- entries at the same address.
2780 if Is_Task_Type
(Etype
(Id
)) and then More_Ids
(N
) then
2785 E
:= First_Entity
(Etype
(Id
));
2786 while Present
(E
) loop
2787 if Ekind
(E
) = E_Entry
2788 and then Present
(Get_Attribute_Definition_Clause
2789 (E
, Attribute_Address
))
2792 ("?more than one task with same entry address", N
);
2794 ("\?Program_Error will be raised at run time", N
);
2796 Make_Raise_Program_Error
(Loc
,
2797 Reason
=> PE_Duplicated_Entry_Address
));
2807 -- Some simple constant-propagation: if the expression is a constant
2808 -- string initialized with a literal, share the literal. This avoids
2812 and then Is_Entity_Name
(E
)
2813 and then Ekind
(Entity
(E
)) = E_Constant
2814 and then Base_Type
(Etype
(E
)) = Standard_String
2817 Val
: constant Node_Id
:= Constant_Value
(Entity
(E
));
2820 and then Nkind
(Val
) = N_String_Literal
2822 Rewrite
(E
, New_Copy
(Val
));
2827 -- Another optimization: if the nominal subtype is unconstrained and
2828 -- the expression is a function call that returns an unconstrained
2829 -- type, rewrite the declaration as a renaming of the result of the
2830 -- call. The exceptions below are cases where the copy is expected,
2831 -- either by the back end (Aliased case) or by the semantics, as for
2832 -- initializing controlled types or copying tags for classwide types.
2835 and then Nkind
(E
) = N_Explicit_Dereference
2836 and then Nkind
(Original_Node
(E
)) = N_Function_Call
2837 and then not Is_Library_Level_Entity
(Id
)
2838 and then not Is_Constrained
(Underlying_Type
(T
))
2839 and then not Is_Aliased
(Id
)
2840 and then not Is_Class_Wide_Type
(T
)
2841 and then not Is_Controlled
(T
)
2842 and then not Has_Controlled_Component
(Base_Type
(T
))
2843 and then Expander_Active
2846 Make_Object_Renaming_Declaration
(Loc
,
2847 Defining_Identifier
=> Id
,
2848 Access_Definition
=> Empty
,
2849 Subtype_Mark
=> New_Occurrence_Of
2850 (Base_Type
(Etype
(Id
)), Loc
),
2853 Set_Renamed_Object
(Id
, E
);
2855 -- Force generation of debugging information for the constant and for
2856 -- the renamed function call.
2858 Set_Needs_Debug_Info
(Id
);
2859 Set_Needs_Debug_Info
(Entity
(Prefix
(E
)));
2862 if Present
(Prev_Entity
)
2863 and then Is_Frozen
(Prev_Entity
)
2864 and then not Error_Posted
(Id
)
2866 Error_Msg_N
("full constant declaration appears too late", N
);
2869 Check_Eliminated
(Id
);
2871 -- Deal with setting In_Private_Part flag if in private part
2873 if Ekind
(Scope
(Id
)) = E_Package
2874 and then In_Private_Part
(Scope
(Id
))
2876 Set_In_Private_Part
(Id
);
2878 end Analyze_Object_Declaration
;
2880 ---------------------------
2881 -- Analyze_Others_Choice --
2882 ---------------------------
2884 -- Nothing to do for the others choice node itself, the semantic analysis
2885 -- of the others choice will occur as part of the processing of the parent
2887 procedure Analyze_Others_Choice
(N
: Node_Id
) is
2888 pragma Warnings
(Off
, N
);
2891 end Analyze_Others_Choice
;
2893 --------------------------------
2894 -- Analyze_Per_Use_Expression --
2895 --------------------------------
2897 procedure Analyze_Per_Use_Expression
(N
: Node_Id
; T
: Entity_Id
) is
2898 Save_In_Default_Expression
: constant Boolean := In_Default_Expression
;
2900 In_Default_Expression
:= True;
2901 Pre_Analyze_And_Resolve
(N
, T
);
2902 In_Default_Expression
:= Save_In_Default_Expression
;
2903 end Analyze_Per_Use_Expression
;
2905 -------------------------------------------
2906 -- Analyze_Private_Extension_Declaration --
2907 -------------------------------------------
2909 procedure Analyze_Private_Extension_Declaration
(N
: Node_Id
) is
2910 T
: constant Entity_Id
:= Defining_Identifier
(N
);
2911 Indic
: constant Node_Id
:= Subtype_Indication
(N
);
2912 Parent_Type
: Entity_Id
;
2913 Parent_Base
: Entity_Id
;
2916 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
2918 if Is_Non_Empty_List
(Interface_List
(N
)) then
2924 Intf
:= First
(Interface_List
(N
));
2925 while Present
(Intf
) loop
2926 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
2928 if not Is_Interface
(T
) then
2929 Error_Msg_NE
("(Ada 2005) & must be an interface", Intf
, T
);
2937 Generate_Definition
(T
);
2940 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
2941 Parent_Base
:= Base_Type
(Parent_Type
);
2943 if Parent_Type
= Any_Type
2944 or else Etype
(Parent_Type
) = Any_Type
2946 Set_Ekind
(T
, Ekind
(Parent_Type
));
2947 Set_Etype
(T
, Any_Type
);
2950 elsif not Is_Tagged_Type
(Parent_Type
) then
2952 ("parent of type extension must be a tagged type ", Indic
);
2955 elsif Ekind
(Parent_Type
) = E_Void
2956 or else Ekind
(Parent_Type
) = E_Incomplete_Type
2958 Error_Msg_N
("premature derivation of incomplete type", Indic
);
2961 elsif Is_Concurrent_Type
(Parent_Type
) then
2963 ("parent type of a private extension cannot be "
2964 & "a synchronized tagged type (RM 3.9.1 (3/1))", N
);
2966 Set_Etype
(T
, Any_Type
);
2967 Set_Ekind
(T
, E_Limited_Private_Type
);
2968 Set_Private_Dependents
(T
, New_Elmt_List
);
2969 Set_Error_Posted
(T
);
2973 -- Perhaps the parent type should be changed to the class-wide type's
2974 -- specific type in this case to prevent cascading errors ???
2976 if Is_Class_Wide_Type
(Parent_Type
) then
2978 ("parent of type extension must not be a class-wide type", Indic
);
2982 if (not Is_Package_Or_Generic_Package
(Current_Scope
)
2983 and then Nkind
(Parent
(N
)) /= N_Generic_Subprogram_Declaration
)
2984 or else In_Private_Part
(Current_Scope
)
2987 Error_Msg_N
("invalid context for private extension", N
);
2990 -- Set common attributes
2992 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
2993 Set_Scope
(T
, Current_Scope
);
2994 Set_Ekind
(T
, E_Record_Type_With_Private
);
2995 Init_Size_Align
(T
);
2997 Set_Etype
(T
, Parent_Base
);
2998 Set_Has_Task
(T
, Has_Task
(Parent_Base
));
3000 Set_Convention
(T
, Convention
(Parent_Type
));
3001 Set_First_Rep_Item
(T
, First_Rep_Item
(Parent_Type
));
3002 Set_Is_First_Subtype
(T
);
3003 Make_Class_Wide_Type
(T
);
3005 if Unknown_Discriminants_Present
(N
) then
3006 Set_Discriminant_Constraint
(T
, No_Elist
);
3009 Build_Derived_Record_Type
(N
, Parent_Type
, T
);
3011 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
3012 -- synchronized formal derived type.
3014 if Ada_Version
>= Ada_05
3015 and then Synchronized_Present
(N
)
3017 Set_Is_Limited_Record
(T
);
3019 -- Formal derived type case
3021 if Is_Generic_Type
(T
) then
3023 -- The parent must be a tagged limited type or a synchronized
3026 if (not Is_Tagged_Type
(Parent_Type
)
3027 or else not Is_Limited_Type
(Parent_Type
))
3029 (not Is_Interface
(Parent_Type
)
3030 or else not Is_Synchronized_Interface
(Parent_Type
))
3032 Error_Msg_NE
("parent type of & must be tagged limited " &
3033 "or synchronized", N
, T
);
3036 -- The progenitors (if any) must be limited or synchronized
3039 if Present
(Abstract_Interfaces
(T
)) then
3042 Iface_Elmt
: Elmt_Id
;
3045 Iface_Elmt
:= First_Elmt
(Abstract_Interfaces
(T
));
3046 while Present
(Iface_Elmt
) loop
3047 Iface
:= Node
(Iface_Elmt
);
3049 if not Is_Limited_Interface
(Iface
)
3050 and then not Is_Synchronized_Interface
(Iface
)
3052 Error_Msg_NE
("progenitor & must be limited " &
3053 "or synchronized", N
, Iface
);
3056 Next_Elmt
(Iface_Elmt
);
3061 -- Regular derived extension, the parent must be a limited or
3062 -- synchronized interface.
3065 if not Is_Interface
(Parent_Type
)
3066 or else (not Is_Limited_Interface
(Parent_Type
)
3068 not Is_Synchronized_Interface
(Parent_Type
))
3071 ("parent type of & must be limited interface", N
, T
);
3075 elsif Limited_Present
(N
) then
3076 Set_Is_Limited_Record
(T
);
3078 if not Is_Limited_Type
(Parent_Type
)
3080 (not Is_Interface
(Parent_Type
)
3081 or else not Is_Limited_Interface
(Parent_Type
))
3083 Error_Msg_NE
("parent type& of limited extension must be limited",
3087 end Analyze_Private_Extension_Declaration
;
3089 ---------------------------------
3090 -- Analyze_Subtype_Declaration --
3091 ---------------------------------
3093 procedure Analyze_Subtype_Declaration
3095 Skip
: Boolean := False)
3097 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3099 R_Checks
: Check_Result
;
3102 Generate_Definition
(Id
);
3103 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
3104 Init_Size_Align
(Id
);
3106 -- The following guard condition on Enter_Name is to handle cases where
3107 -- the defining identifier has already been entered into the scope but
3108 -- the declaration as a whole needs to be analyzed.
3110 -- This case in particular happens for derived enumeration types. The
3111 -- derived enumeration type is processed as an inserted enumeration type
3112 -- declaration followed by a rewritten subtype declaration. The defining
3113 -- identifier, however, is entered into the name scope very early in the
3114 -- processing of the original type declaration and therefore needs to be
3115 -- avoided here, when the created subtype declaration is analyzed. (See
3116 -- Build_Derived_Types)
3118 -- This also happens when the full view of a private type is derived
3119 -- type with constraints. In this case the entity has been introduced
3120 -- in the private declaration.
3123 or else (Present
(Etype
(Id
))
3124 and then (Is_Private_Type
(Etype
(Id
))
3125 or else Is_Task_Type
(Etype
(Id
))
3126 or else Is_Rewrite_Substitution
(N
)))
3134 T
:= Process_Subtype
(Subtype_Indication
(N
), N
, Id
, 'P');
3136 -- Inherit common attributes
3138 Set_Is_Generic_Type
(Id
, Is_Generic_Type
(Base_Type
(T
)));
3139 Set_Is_Volatile
(Id
, Is_Volatile
(T
));
3140 Set_Treat_As_Volatile
(Id
, Treat_As_Volatile
(T
));
3141 Set_Is_Atomic
(Id
, Is_Atomic
(T
));
3142 Set_Is_Ada_2005_Only
(Id
, Is_Ada_2005_Only
(T
));
3144 -- In the case where there is no constraint given in the subtype
3145 -- indication, Process_Subtype just returns the Subtype_Mark, so its
3146 -- semantic attributes must be established here.
3148 if Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
then
3149 Set_Etype
(Id
, Base_Type
(T
));
3153 Set_Ekind
(Id
, E_Array_Subtype
);
3154 Copy_Array_Subtype_Attributes
(Id
, T
);
3156 when Decimal_Fixed_Point_Kind
=>
3157 Set_Ekind
(Id
, E_Decimal_Fixed_Point_Subtype
);
3158 Set_Digits_Value
(Id
, Digits_Value
(T
));
3159 Set_Delta_Value
(Id
, Delta_Value
(T
));
3160 Set_Scale_Value
(Id
, Scale_Value
(T
));
3161 Set_Small_Value
(Id
, Small_Value
(T
));
3162 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
3163 Set_Machine_Radix_10
(Id
, Machine_Radix_10
(T
));
3164 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3165 Set_RM_Size
(Id
, RM_Size
(T
));
3167 when Enumeration_Kind
=>
3168 Set_Ekind
(Id
, E_Enumeration_Subtype
);
3169 Set_First_Literal
(Id
, First_Literal
(Base_Type
(T
)));
3170 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
3171 Set_Is_Character_Type
(Id
, Is_Character_Type
(T
));
3172 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3173 Set_RM_Size
(Id
, RM_Size
(T
));
3175 when Ordinary_Fixed_Point_Kind
=>
3176 Set_Ekind
(Id
, E_Ordinary_Fixed_Point_Subtype
);
3177 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
3178 Set_Small_Value
(Id
, Small_Value
(T
));
3179 Set_Delta_Value
(Id
, Delta_Value
(T
));
3180 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3181 Set_RM_Size
(Id
, RM_Size
(T
));
3184 Set_Ekind
(Id
, E_Floating_Point_Subtype
);
3185 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
3186 Set_Digits_Value
(Id
, Digits_Value
(T
));
3187 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3189 when Signed_Integer_Kind
=>
3190 Set_Ekind
(Id
, E_Signed_Integer_Subtype
);
3191 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
3192 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3193 Set_RM_Size
(Id
, RM_Size
(T
));
3195 when Modular_Integer_Kind
=>
3196 Set_Ekind
(Id
, E_Modular_Integer_Subtype
);
3197 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
3198 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3199 Set_RM_Size
(Id
, RM_Size
(T
));
3201 when Class_Wide_Kind
=>
3202 Set_Ekind
(Id
, E_Class_Wide_Subtype
);
3203 Set_First_Entity
(Id
, First_Entity
(T
));
3204 Set_Last_Entity
(Id
, Last_Entity
(T
));
3205 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
3206 Set_Cloned_Subtype
(Id
, T
);
3207 Set_Is_Tagged_Type
(Id
, True);
3208 Set_Has_Unknown_Discriminants
3211 if Ekind
(T
) = E_Class_Wide_Subtype
then
3212 Set_Equivalent_Type
(Id
, Equivalent_Type
(T
));
3215 when E_Record_Type | E_Record_Subtype
=>
3216 Set_Ekind
(Id
, E_Record_Subtype
);
3218 if Ekind
(T
) = E_Record_Subtype
3219 and then Present
(Cloned_Subtype
(T
))
3221 Set_Cloned_Subtype
(Id
, Cloned_Subtype
(T
));
3223 Set_Cloned_Subtype
(Id
, T
);
3226 Set_First_Entity
(Id
, First_Entity
(T
));
3227 Set_Last_Entity
(Id
, Last_Entity
(T
));
3228 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
3229 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3230 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
3231 Set_Has_Unknown_Discriminants
3232 (Id
, Has_Unknown_Discriminants
(T
));
3234 if Has_Discriminants
(T
) then
3235 Set_Discriminant_Constraint
3236 (Id
, Discriminant_Constraint
(T
));
3237 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
3239 elsif Has_Unknown_Discriminants
(Id
) then
3240 Set_Discriminant_Constraint
(Id
, No_Elist
);
3243 if Is_Tagged_Type
(T
) then
3244 Set_Is_Tagged_Type
(Id
);
3245 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
3246 Set_Primitive_Operations
3247 (Id
, Primitive_Operations
(T
));
3248 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
3250 if Is_Interface
(T
) then
3251 Set_Is_Interface
(Id
);
3252 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
3256 when Private_Kind
=>
3257 Set_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
3258 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
3259 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3260 Set_First_Entity
(Id
, First_Entity
(T
));
3261 Set_Last_Entity
(Id
, Last_Entity
(T
));
3262 Set_Private_Dependents
(Id
, New_Elmt_List
);
3263 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
3264 Set_Has_Unknown_Discriminants
3265 (Id
, Has_Unknown_Discriminants
(T
));
3267 if Is_Tagged_Type
(T
) then
3268 Set_Is_Tagged_Type
(Id
);
3269 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
3270 Set_Primitive_Operations
(Id
, Primitive_Operations
(T
));
3271 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
3274 -- In general the attributes of the subtype of a private type
3275 -- are the attributes of the partial view of parent. However,
3276 -- the full view may be a discriminated type, and the subtype
3277 -- must share the discriminant constraint to generate correct
3278 -- calls to initialization procedures.
3280 if Has_Discriminants
(T
) then
3281 Set_Discriminant_Constraint
3282 (Id
, Discriminant_Constraint
(T
));
3283 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
3285 elsif Present
(Full_View
(T
))
3286 and then Has_Discriminants
(Full_View
(T
))
3288 Set_Discriminant_Constraint
3289 (Id
, Discriminant_Constraint
(Full_View
(T
)));
3290 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
3292 -- This would seem semantically correct, but apparently
3293 -- confuses the back-end (4412-009). To be explained ???
3295 -- Set_Has_Discriminants (Id);
3298 Prepare_Private_Subtype_Completion
(Id
, N
);
3301 Set_Ekind
(Id
, E_Access_Subtype
);
3302 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3303 Set_Is_Access_Constant
3304 (Id
, Is_Access_Constant
(T
));
3305 Set_Directly_Designated_Type
3306 (Id
, Designated_Type
(T
));
3307 Set_Can_Never_Be_Null
(Id
, Can_Never_Be_Null
(T
));
3309 -- A Pure library_item must not contain the declaration of a
3310 -- named access type, except within a subprogram, generic
3311 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
3313 if Comes_From_Source
(Id
)
3314 and then In_Pure_Unit
3315 and then not In_Subprogram_Task_Protected_Unit
3318 ("named access types not allowed in pure unit", N
);
3321 when Concurrent_Kind
=>
3322 Set_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
3323 Set_Corresponding_Record_Type
(Id
,
3324 Corresponding_Record_Type
(T
));
3325 Set_First_Entity
(Id
, First_Entity
(T
));
3326 Set_First_Private_Entity
(Id
, First_Private_Entity
(T
));
3327 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
3328 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
3329 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
3330 Set_Last_Entity
(Id
, Last_Entity
(T
));
3332 if Has_Discriminants
(T
) then
3333 Set_Discriminant_Constraint
(Id
,
3334 Discriminant_Constraint
(T
));
3335 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
3338 when E_Incomplete_Type
=>
3339 if Ada_Version
>= Ada_05
then
3340 Set_Ekind
(Id
, E_Incomplete_Subtype
);
3342 -- Ada 2005 (AI-412): Decorate an incomplete subtype
3343 -- of an incomplete type visible through a limited
3346 if From_With_Type
(T
)
3347 and then Present
(Non_Limited_View
(T
))
3349 Set_From_With_Type
(Id
);
3350 Set_Non_Limited_View
(Id
, Non_Limited_View
(T
));
3352 -- Ada 2005 (AI-412): Add the regular incomplete subtype
3353 -- to the private dependents of the original incomplete
3354 -- type for future transformation.
3357 Append_Elmt
(Id
, Private_Dependents
(T
));
3360 -- If the subtype name denotes an incomplete type an error
3361 -- was already reported by Process_Subtype.
3364 Set_Etype
(Id
, Any_Type
);
3368 raise Program_Error
;
3372 if Etype
(Id
) = Any_Type
then
3376 -- Some common processing on all types
3378 Set_Size_Info
(Id
, T
);
3379 Set_First_Rep_Item
(Id
, First_Rep_Item
(T
));
3383 Set_Is_Immediately_Visible
(Id
, True);
3384 Set_Depends_On_Private
(Id
, Has_Private_Component
(T
));
3385 Set_Is_Descendent_Of_Address
(Id
, Is_Descendent_Of_Address
(T
));
3387 if Is_Interface
(T
) then
3388 Set_Is_Interface
(Id
);
3391 if Present
(Generic_Parent_Type
(N
))
3394 (Parent
(Generic_Parent_Type
(N
))) /= N_Formal_Type_Declaration
3396 (Formal_Type_Definition
(Parent
(Generic_Parent_Type
(N
))))
3397 /= N_Formal_Private_Type_Definition
)
3399 if Is_Tagged_Type
(Id
) then
3401 -- If this is a generic actual subtype for a synchronized type,
3402 -- the primitive operations are those of the corresponding record
3403 -- for which there is a separate subtype declaration.
3405 if Is_Concurrent_Type
(Id
) then
3407 elsif Is_Class_Wide_Type
(Id
) then
3408 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, Etype
(T
));
3410 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, T
);
3413 elsif Scope
(Etype
(Id
)) /= Standard_Standard
then
3414 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
);
3418 if Is_Private_Type
(T
)
3419 and then Present
(Full_View
(T
))
3421 Conditional_Delay
(Id
, Full_View
(T
));
3423 -- The subtypes of components or subcomponents of protected types
3424 -- do not need freeze nodes, which would otherwise appear in the
3425 -- wrong scope (before the freeze node for the protected type). The
3426 -- proper subtypes are those of the subcomponents of the corresponding
3429 elsif Ekind
(Scope
(Id
)) /= E_Protected_Type
3430 and then Present
(Scope
(Scope
(Id
))) -- error defense!
3431 and then Ekind
(Scope
(Scope
(Id
))) /= E_Protected_Type
3433 Conditional_Delay
(Id
, T
);
3436 -- Check that constraint_error is raised for a scalar subtype
3437 -- indication when the lower or upper bound of a non-null range
3438 -- lies outside the range of the type mark.
3440 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
3441 if Is_Scalar_Type
(Etype
(Id
))
3442 and then Scalar_Range
(Id
) /=
3443 Scalar_Range
(Etype
(Subtype_Mark
3444 (Subtype_Indication
(N
))))
3448 Etype
(Subtype_Mark
(Subtype_Indication
(N
))));
3450 elsif Is_Array_Type
(Etype
(Id
))
3451 and then Present
(First_Index
(Id
))
3453 -- This really should be a subprogram that finds the indications
3456 if ((Nkind
(First_Index
(Id
)) = N_Identifier
3457 and then Ekind
(Entity
(First_Index
(Id
))) in Scalar_Kind
)
3458 or else Nkind
(First_Index
(Id
)) = N_Subtype_Indication
)
3460 Nkind
(Scalar_Range
(Etype
(First_Index
(Id
)))) = N_Range
3463 Target_Typ
: constant Entity_Id
:=
3466 (Subtype_Mark
(Subtype_Indication
(N
)))));
3470 (Scalar_Range
(Etype
(First_Index
(Id
))),
3472 Etype
(First_Index
(Id
)),
3473 Defining_Identifier
(N
));
3479 Sloc
(Defining_Identifier
(N
)));
3485 Check_Eliminated
(Id
);
3486 end Analyze_Subtype_Declaration
;
3488 --------------------------------
3489 -- Analyze_Subtype_Indication --
3490 --------------------------------
3492 procedure Analyze_Subtype_Indication
(N
: Node_Id
) is
3493 T
: constant Entity_Id
:= Subtype_Mark
(N
);
3494 R
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
3501 Set_Etype
(N
, Etype
(R
));
3502 Resolve
(R
, Entity
(T
));
3504 Set_Error_Posted
(R
);
3505 Set_Error_Posted
(T
);
3507 end Analyze_Subtype_Indication
;
3509 ------------------------------
3510 -- Analyze_Type_Declaration --
3511 ------------------------------
3513 procedure Analyze_Type_Declaration
(N
: Node_Id
) is
3514 Def
: constant Node_Id
:= Type_Definition
(N
);
3515 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3519 Is_Remote
: constant Boolean :=
3520 (Is_Remote_Types
(Current_Scope
)
3521 or else Is_Remote_Call_Interface
(Current_Scope
))
3522 and then not (In_Private_Part
(Current_Scope
)
3523 or else In_Package_Body
(Current_Scope
));
3525 procedure Check_Ops_From_Incomplete_Type
;
3526 -- If there is a tagged incomplete partial view of the type, transfer
3527 -- its operations to the full view, and indicate that the type of the
3528 -- controlling parameter (s) is this full view.
3530 ------------------------------------
3531 -- Check_Ops_From_Incomplete_Type --
3532 ------------------------------------
3534 procedure Check_Ops_From_Incomplete_Type
is
3541 and then Ekind
(Prev
) = E_Incomplete_Type
3542 and then Is_Tagged_Type
(Prev
)
3543 and then Is_Tagged_Type
(T
)
3545 Elmt
:= First_Elmt
(Primitive_Operations
(Prev
));
3546 while Present
(Elmt
) loop
3548 Prepend_Elmt
(Op
, Primitive_Operations
(T
));
3550 Formal
:= First_Formal
(Op
);
3551 while Present
(Formal
) loop
3552 if Etype
(Formal
) = Prev
then
3553 Set_Etype
(Formal
, T
);
3556 Next_Formal
(Formal
);
3559 if Etype
(Op
) = Prev
then
3566 end Check_Ops_From_Incomplete_Type
;
3568 -- Start of processing for Analyze_Type_Declaration
3571 Prev
:= Find_Type_Name
(N
);
3573 -- The full view, if present, now points to the current type
3575 -- Ada 2005 (AI-50217): If the type was previously decorated when
3576 -- imported through a LIMITED WITH clause, it appears as incomplete
3577 -- but has no full view.
3578 -- If the incomplete view is tagged, a class_wide type has been
3579 -- created already. Use it for the full view as well, to prevent
3580 -- multiple incompatible class-wide types that may be created for
3581 -- self-referential anonymous access components.
3583 if Ekind
(Prev
) = E_Incomplete_Type
3584 and then Present
(Full_View
(Prev
))
3586 T
:= Full_View
(Prev
);
3588 if Is_Tagged_Type
(Prev
)
3589 and then Present
(Class_Wide_Type
(Prev
))
3591 Set_Ekind
(T
, Ekind
(Prev
)); -- will be reset later
3592 Set_Class_Wide_Type
(T
, Class_Wide_Type
(Prev
));
3593 Set_Etype
(Class_Wide_Type
(T
), T
);
3600 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
3602 -- We set the flag Is_First_Subtype here. It is needed to set the
3603 -- corresponding flag for the Implicit class-wide-type created
3604 -- during tagged types processing.
3606 Set_Is_First_Subtype
(T
, True);
3608 -- Only composite types other than array types are allowed to have
3613 -- For derived types, the rule will be checked once we've figured
3614 -- out the parent type.
3616 when N_Derived_Type_Definition
=>
3619 -- For record types, discriminants are allowed
3621 when N_Record_Definition
=>
3625 if Present
(Discriminant_Specifications
(N
)) then
3627 ("elementary or array type cannot have discriminants",
3629 (First
(Discriminant_Specifications
(N
))));
3633 -- Elaborate the type definition according to kind, and generate
3634 -- subsidiary (implicit) subtypes where needed. We skip this if it was
3635 -- already done (this happens during the reanalysis that follows a call
3636 -- to the high level optimizer).
3638 if not Analyzed
(T
) then
3643 when N_Access_To_Subprogram_Definition
=>
3644 Access_Subprogram_Declaration
(T
, Def
);
3646 -- If this is a remote access to subprogram, we must create the
3647 -- equivalent fat pointer type, and related subprograms.
3650 Process_Remote_AST_Declaration
(N
);
3653 -- Validate categorization rule against access type declaration
3654 -- usually a violation in Pure unit, Shared_Passive unit.
3656 Validate_Access_Type_Declaration
(T
, N
);
3658 when N_Access_To_Object_Definition
=>
3659 Access_Type_Declaration
(T
, Def
);
3661 -- Validate categorization rule against access type declaration
3662 -- usually a violation in Pure unit, Shared_Passive unit.
3664 Validate_Access_Type_Declaration
(T
, N
);
3666 -- If we are in a Remote_Call_Interface package and define
3667 -- a RACW, Read and Write attribute must be added.
3670 and then Is_Remote_Access_To_Class_Wide_Type
(Def_Id
)
3672 Add_RACW_Features
(Def_Id
);
3675 -- Set no strict aliasing flag if config pragma seen
3677 if Opt
.No_Strict_Aliasing
then
3678 Set_No_Strict_Aliasing
(Base_Type
(Def_Id
));
3681 when N_Array_Type_Definition
=>
3682 Array_Type_Declaration
(T
, Def
);
3684 when N_Derived_Type_Definition
=>
3685 Derived_Type_Declaration
(T
, N
, T
/= Def_Id
);
3687 when N_Enumeration_Type_Definition
=>
3688 Enumeration_Type_Declaration
(T
, Def
);
3690 when N_Floating_Point_Definition
=>
3691 Floating_Point_Type_Declaration
(T
, Def
);
3693 when N_Decimal_Fixed_Point_Definition
=>
3694 Decimal_Fixed_Point_Type_Declaration
(T
, Def
);
3696 when N_Ordinary_Fixed_Point_Definition
=>
3697 Ordinary_Fixed_Point_Type_Declaration
(T
, Def
);
3699 when N_Signed_Integer_Type_Definition
=>
3700 Signed_Integer_Type_Declaration
(T
, Def
);
3702 when N_Modular_Type_Definition
=>
3703 Modular_Type_Declaration
(T
, Def
);
3705 when N_Record_Definition
=>
3706 Record_Type_Declaration
(T
, N
, Prev
);
3709 raise Program_Error
;
3714 if Etype
(T
) = Any_Type
then
3718 -- Some common processing for all types
3720 Set_Depends_On_Private
(T
, Has_Private_Component
(T
));
3721 Check_Ops_From_Incomplete_Type
;
3723 -- Both the declared entity, and its anonymous base type if one
3724 -- was created, need freeze nodes allocated.
3727 B
: constant Entity_Id
:= Base_Type
(T
);
3730 -- In the case where the base type is different from the first
3731 -- subtype, we pre-allocate a freeze node, and set the proper link
3732 -- to the first subtype. Freeze_Entity will use this preallocated
3733 -- freeze node when it freezes the entity.
3736 Ensure_Freeze_Node
(B
);
3737 Set_First_Subtype_Link
(Freeze_Node
(B
), T
);
3740 if not From_With_Type
(T
) then
3741 Set_Has_Delayed_Freeze
(T
);
3745 -- Case of T is the full declaration of some private type which has
3746 -- been swapped in Defining_Identifier (N).
3748 if T
/= Def_Id
and then Is_Private_Type
(Def_Id
) then
3749 Process_Full_View
(N
, T
, Def_Id
);
3751 -- Record the reference. The form of this is a little strange,
3752 -- since the full declaration has been swapped in. So the first
3753 -- parameter here represents the entity to which a reference is
3754 -- made which is the "real" entity, i.e. the one swapped in,
3755 -- and the second parameter provides the reference location.
3757 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
3758 -- since we don't want a complaint about the full type being an
3759 -- unwanted reference to the private type
3762 B
: constant Boolean := Has_Pragma_Unreferenced
(T
);
3764 Set_Has_Pragma_Unreferenced
(T
, False);
3765 Generate_Reference
(T
, T
, 'c');
3766 Set_Has_Pragma_Unreferenced
(T
, B
);
3769 Set_Completion_Referenced
(Def_Id
);
3771 -- For completion of incomplete type, process incomplete dependents
3772 -- and always mark the full type as referenced (it is the incomplete
3773 -- type that we get for any real reference).
3775 elsif Ekind
(Prev
) = E_Incomplete_Type
then
3776 Process_Incomplete_Dependents
(N
, T
, Prev
);
3777 Generate_Reference
(Prev
, Def_Id
, 'c');
3778 Set_Completion_Referenced
(Def_Id
);
3780 -- If not private type or incomplete type completion, this is a real
3781 -- definition of a new entity, so record it.
3784 Generate_Definition
(Def_Id
);
3787 if Chars
(Scope
(Def_Id
)) = Name_System
3788 and then Chars
(Def_Id
) = Name_Address
3789 and then Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(N
)))
3791 Set_Is_Descendent_Of_Address
(Def_Id
);
3792 Set_Is_Descendent_Of_Address
(Base_Type
(Def_Id
));
3793 Set_Is_Descendent_Of_Address
(Prev
);
3796 Check_Eliminated
(Def_Id
);
3797 end Analyze_Type_Declaration
;
3799 --------------------------
3800 -- Analyze_Variant_Part --
3801 --------------------------
3803 procedure Analyze_Variant_Part
(N
: Node_Id
) is
3805 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
3806 -- Error routine invoked by the generic instantiation below when
3807 -- the variant part has a non static choice.
3809 procedure Process_Declarations
(Variant
: Node_Id
);
3810 -- Analyzes all the declarations associated with a Variant.
3811 -- Needed by the generic instantiation below.
3813 package Variant_Choices_Processing
is new
3814 Generic_Choices_Processing
3815 (Get_Alternatives
=> Variants
,
3816 Get_Choices
=> Discrete_Choices
,
3817 Process_Empty_Choice
=> No_OP
,
3818 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
3819 Process_Associated_Node
=> Process_Declarations
);
3820 use Variant_Choices_Processing
;
3821 -- Instantiation of the generic choice processing package
3823 -----------------------------
3824 -- Non_Static_Choice_Error --
3825 -----------------------------
3827 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
3829 Flag_Non_Static_Expr
3830 ("choice given in variant part is not static!", Choice
);
3831 end Non_Static_Choice_Error
;
3833 --------------------------
3834 -- Process_Declarations --
3835 --------------------------
3837 procedure Process_Declarations
(Variant
: Node_Id
) is
3839 if not Null_Present
(Component_List
(Variant
)) then
3840 Analyze_Declarations
(Component_Items
(Component_List
(Variant
)));
3842 if Present
(Variant_Part
(Component_List
(Variant
))) then
3843 Analyze
(Variant_Part
(Component_List
(Variant
)));
3846 end Process_Declarations
;
3848 -- Variables local to Analyze_Case_Statement
3850 Discr_Name
: Node_Id
;
3851 Discr_Type
: Entity_Id
;
3853 Case_Table
: Choice_Table_Type
(1 .. Number_Of_Choices
(N
));
3855 Dont_Care
: Boolean;
3856 Others_Present
: Boolean := False;
3858 -- Start of processing for Analyze_Variant_Part
3861 Discr_Name
:= Name
(N
);
3862 Analyze
(Discr_Name
);
3864 if Etype
(Discr_Name
) = Any_Type
then
3866 -- Prevent cascaded errors
3870 elsif Ekind
(Entity
(Discr_Name
)) /= E_Discriminant
then
3871 Error_Msg_N
("invalid discriminant name in variant part", Discr_Name
);
3874 Discr_Type
:= Etype
(Entity
(Discr_Name
));
3876 if not Is_Discrete_Type
(Discr_Type
) then
3878 ("discriminant in a variant part must be of a discrete type",
3883 -- Call the instantiated Analyze_Choices which does the rest of the work
3886 (N
, Discr_Type
, Case_Table
, Last_Choice
, Dont_Care
, Others_Present
);
3887 end Analyze_Variant_Part
;
3889 ----------------------------
3890 -- Array_Type_Declaration --
3891 ----------------------------
3893 procedure Array_Type_Declaration
(T
: in out Entity_Id
; Def
: Node_Id
) is
3894 Component_Def
: constant Node_Id
:= Component_Definition
(Def
);
3895 Element_Type
: Entity_Id
;
3896 Implicit_Base
: Entity_Id
;
3898 Related_Id
: Entity_Id
:= Empty
;
3900 P
: constant Node_Id
:= Parent
(Def
);
3904 if Nkind
(Def
) = N_Constrained_Array_Definition
then
3905 Index
:= First
(Discrete_Subtype_Definitions
(Def
));
3907 Index
:= First
(Subtype_Marks
(Def
));
3910 -- Find proper names for the implicit types which may be public.
3911 -- in case of anonymous arrays we use the name of the first object
3912 -- of that type as prefix.
3915 Related_Id
:= Defining_Identifier
(P
);
3921 while Present
(Index
) loop
3924 -- Add a subtype declaration for each index of private array type
3925 -- declaration whose etype is also private. For example:
3928 -- type Index is private;
3930 -- type Table is array (Index) of ...
3933 -- This is currently required by the expander to generate the
3934 -- internally generated equality subprogram of records with variant
3935 -- parts in which the etype of some component is such private type.
3937 if Ekind
(Current_Scope
) = E_Package
3938 and then In_Private_Part
(Current_Scope
)
3939 and then Has_Private_Declaration
(Etype
(Index
))
3942 Loc
: constant Source_Ptr
:= Sloc
(Def
);
3948 Make_Defining_Identifier
(Loc
,
3949 Chars
=> New_Internal_Name
('T'));
3950 Set_Is_Internal
(New_E
);
3953 Make_Subtype_Declaration
(Loc
,
3954 Defining_Identifier
=> New_E
,
3955 Subtype_Indication
=>
3956 New_Occurrence_Of
(Etype
(Index
), Loc
));
3958 Insert_Before
(Parent
(Def
), Decl
);
3960 Set_Etype
(Index
, New_E
);
3962 -- If the index is a range the Entity attribute is not
3963 -- available. Example:
3966 -- type T is private;
3968 -- type T is new Natural;
3969 -- Table : array (T(1) .. T(10)) of Boolean;
3972 if Nkind
(Index
) /= N_Range
then
3973 Set_Entity
(Index
, New_E
);
3978 Make_Index
(Index
, P
, Related_Id
, Nb_Index
);
3980 Nb_Index
:= Nb_Index
+ 1;
3983 -- Process subtype indication if one is present
3985 if Present
(Subtype_Indication
(Component_Def
)) then
3988 (Subtype_Indication
(Component_Def
), P
, Related_Id
, 'C');
3990 -- Ada 2005 (AI-230): Access Definition case
3992 else pragma Assert
(Present
(Access_Definition
(Component_Def
)));
3994 -- Indicate that the anonymous access type is created by the
3995 -- array type declaration.
3997 Element_Type
:= Access_Definition
3999 N
=> Access_Definition
(Component_Def
));
4000 Set_Is_Local_Anonymous_Access
(Element_Type
);
4002 -- Propagate the parent. This field is needed if we have to generate
4003 -- the master_id associated with an anonymous access to task type
4004 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
4006 Set_Parent
(Element_Type
, Parent
(T
));
4008 -- Ada 2005 (AI-230): In case of components that are anonymous
4009 -- access types the level of accessibility depends on the enclosing
4012 Set_Scope
(Element_Type
, Current_Scope
); -- Ada 2005 (AI-230)
4014 -- Ada 2005 (AI-254)
4017 CD
: constant Node_Id
:=
4018 Access_To_Subprogram_Definition
4019 (Access_Definition
(Component_Def
));
4021 if Present
(CD
) and then Protected_Present
(CD
) then
4023 Replace_Anonymous_Access_To_Protected_Subprogram
(Def
);
4028 -- Constrained array case
4031 T
:= Create_Itype
(E_Void
, P
, Related_Id
, 'T');
4034 if Nkind
(Def
) = N_Constrained_Array_Definition
then
4036 -- Establish Implicit_Base as unconstrained base type
4038 Implicit_Base
:= Create_Itype
(E_Array_Type
, P
, Related_Id
, 'B');
4040 Init_Size_Align
(Implicit_Base
);
4041 Set_Etype
(Implicit_Base
, Implicit_Base
);
4042 Set_Scope
(Implicit_Base
, Current_Scope
);
4043 Set_Has_Delayed_Freeze
(Implicit_Base
);
4045 -- The constrained array type is a subtype of the unconstrained one
4047 Set_Ekind
(T
, E_Array_Subtype
);
4048 Init_Size_Align
(T
);
4049 Set_Etype
(T
, Implicit_Base
);
4050 Set_Scope
(T
, Current_Scope
);
4051 Set_Is_Constrained
(T
, True);
4052 Set_First_Index
(T
, First
(Discrete_Subtype_Definitions
(Def
)));
4053 Set_Has_Delayed_Freeze
(T
);
4055 -- Complete setup of implicit base type
4057 Set_First_Index
(Implicit_Base
, First_Index
(T
));
4058 Set_Component_Type
(Implicit_Base
, Element_Type
);
4059 Set_Has_Task
(Implicit_Base
, Has_Task
(Element_Type
));
4060 Set_Component_Size
(Implicit_Base
, Uint_0
);
4061 Set_Packed_Array_Type
(Implicit_Base
, Empty
);
4062 Set_Has_Controlled_Component
4063 (Implicit_Base
, Has_Controlled_Component
4065 or else Is_Controlled
4067 Set_Finalize_Storage_Only
4068 (Implicit_Base
, Finalize_Storage_Only
4071 -- Unconstrained array case
4074 Set_Ekind
(T
, E_Array_Type
);
4075 Init_Size_Align
(T
);
4077 Set_Scope
(T
, Current_Scope
);
4078 Set_Component_Size
(T
, Uint_0
);
4079 Set_Is_Constrained
(T
, False);
4080 Set_First_Index
(T
, First
(Subtype_Marks
(Def
)));
4081 Set_Has_Delayed_Freeze
(T
, True);
4082 Set_Has_Task
(T
, Has_Task
(Element_Type
));
4083 Set_Has_Controlled_Component
(T
, Has_Controlled_Component
4086 Is_Controlled
(Element_Type
));
4087 Set_Finalize_Storage_Only
(T
, Finalize_Storage_Only
4091 -- Common attributes for both cases
4093 Set_Component_Type
(Base_Type
(T
), Element_Type
);
4094 Set_Packed_Array_Type
(T
, Empty
);
4096 if Aliased_Present
(Component_Definition
(Def
)) then
4097 Set_Has_Aliased_Components
(Etype
(T
));
4100 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
4101 -- array type to ensure that objects of this type are initialized.
4103 if Ada_Version
>= Ada_05
4104 and then Can_Never_Be_Null
(Element_Type
)
4106 Set_Can_Never_Be_Null
(T
);
4108 if Null_Exclusion_Present
(Component_Definition
(Def
))
4110 -- No need to check itypes because in their case this check
4111 -- was done at their point of creation
4113 and then not Is_Itype
(Element_Type
)
4116 ("`NOT NULL` not allowed (null already excluded)",
4117 Subtype_Indication
(Component_Definition
(Def
)));
4121 Priv
:= Private_Component
(Element_Type
);
4123 if Present
(Priv
) then
4125 -- Check for circular definitions
4127 if Priv
= Any_Type
then
4128 Set_Component_Type
(Etype
(T
), Any_Type
);
4130 -- There is a gap in the visibility of operations on the composite
4131 -- type only if the component type is defined in a different scope.
4133 elsif Scope
(Priv
) = Current_Scope
then
4136 elsif Is_Limited_Type
(Priv
) then
4137 Set_Is_Limited_Composite
(Etype
(T
));
4138 Set_Is_Limited_Composite
(T
);
4140 Set_Is_Private_Composite
(Etype
(T
));
4141 Set_Is_Private_Composite
(T
);
4145 -- A syntax error in the declaration itself may lead to an empty
4146 -- index list, in which case do a minimal patch.
4148 if No
(First_Index
(T
)) then
4149 Error_Msg_N
("missing index definition in array type declaration", T
);
4152 Indices
: constant List_Id
:=
4153 New_List
(New_Occurrence_Of
(Any_Id
, Sloc
(T
)));
4155 Set_Discrete_Subtype_Definitions
(Def
, Indices
);
4156 Set_First_Index
(T
, First
(Indices
));
4161 -- Create a concatenation operator for the new type. Internal array
4162 -- types created for packed entities do not need such, they are
4163 -- compatible with the user-defined type.
4165 if Number_Dimensions
(T
) = 1
4166 and then not Is_Packed_Array_Type
(T
)
4168 New_Concatenation_Op
(T
);
4171 -- In the case of an unconstrained array the parser has already verified
4172 -- that all the indices are unconstrained but we still need to make sure
4173 -- that the element type is constrained.
4175 if Is_Indefinite_Subtype
(Element_Type
) then
4177 ("unconstrained element type in array declaration",
4178 Subtype_Indication
(Component_Def
));
4180 elsif Is_Abstract_Type
(Element_Type
) then
4182 ("the type of a component cannot be abstract",
4183 Subtype_Indication
(Component_Def
));
4186 end Array_Type_Declaration
;
4188 ------------------------------------------------------
4189 -- Replace_Anonymous_Access_To_Protected_Subprogram --
4190 ------------------------------------------------------
4192 function Replace_Anonymous_Access_To_Protected_Subprogram
4193 (N
: Node_Id
) return Entity_Id
4195 Loc
: constant Source_Ptr
:= Sloc
(N
);
4197 Curr_Scope
: constant Scope_Stack_Entry
:=
4198 Scope_Stack
.Table
(Scope_Stack
.Last
);
4200 Anon
: constant Entity_Id
:=
4201 Make_Defining_Identifier
(Loc
,
4202 Chars
=> New_Internal_Name
('S'));
4210 Set_Is_Internal
(Anon
);
4213 when N_Component_Declaration |
4214 N_Unconstrained_Array_Definition |
4215 N_Constrained_Array_Definition
=>
4216 Comp
:= Component_Definition
(N
);
4217 Acc
:= Access_Definition
(Comp
);
4219 when N_Discriminant_Specification
=>
4220 Comp
:= Discriminant_Type
(N
);
4223 when N_Parameter_Specification
=>
4224 Comp
:= Parameter_Type
(N
);
4227 when N_Access_Function_Definition
=>
4228 Comp
:= Result_Definition
(N
);
4231 when N_Object_Declaration
=>
4232 Comp
:= Object_Definition
(N
);
4236 raise Program_Error
;
4239 Decl
:= Make_Full_Type_Declaration
(Loc
,
4240 Defining_Identifier
=> Anon
,
4242 Copy_Separate_Tree
(Access_To_Subprogram_Definition
(Acc
)));
4244 Mark_Rewrite_Insertion
(Decl
);
4246 -- Insert the new declaration in the nearest enclosing scope
4249 while Present
(P
) and then not Has_Declarations
(P
) loop
4253 pragma Assert
(Present
(P
));
4255 if Nkind
(P
) = N_Package_Specification
then
4256 Prepend
(Decl
, Visible_Declarations
(P
));
4258 Prepend
(Decl
, Declarations
(P
));
4261 -- Replace the anonymous type with an occurrence of the new declaration.
4262 -- In all cases the rewritten node does not have the null-exclusion
4263 -- attribute because (if present) it was already inherited by the
4264 -- anonymous entity (Anon). Thus, in case of components we do not
4265 -- inherit this attribute.
4267 if Nkind
(N
) = N_Parameter_Specification
then
4268 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
4269 Set_Etype
(Defining_Identifier
(N
), Anon
);
4270 Set_Null_Exclusion_Present
(N
, False);
4272 elsif Nkind
(N
) = N_Object_Declaration
then
4273 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
4274 Set_Etype
(Defining_Identifier
(N
), Anon
);
4276 elsif Nkind
(N
) = N_Access_Function_Definition
then
4277 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
4281 Make_Component_Definition
(Loc
,
4282 Subtype_Indication
=> New_Occurrence_Of
(Anon
, Loc
)));
4285 Mark_Rewrite_Insertion
(Comp
);
4287 -- Temporarily remove the current scope from the stack to add the new
4288 -- declarations to the enclosing scope
4290 if Nkind
(N
) = N_Object_Declaration
4291 or else Nkind
(N
) = N_Access_Function_Definition
4296 Scope_Stack
.Decrement_Last
;
4298 Set_Is_Itype
(Anon
);
4299 Scope_Stack
.Append
(Curr_Scope
);
4302 Set_Ekind
(Anon
, E_Anonymous_Access_Protected_Subprogram_Type
);
4304 end Replace_Anonymous_Access_To_Protected_Subprogram
;
4306 -------------------------------
4307 -- Build_Derived_Access_Type --
4308 -------------------------------
4310 procedure Build_Derived_Access_Type
4312 Parent_Type
: Entity_Id
;
4313 Derived_Type
: Entity_Id
)
4315 S
: constant Node_Id
:= Subtype_Indication
(Type_Definition
(N
));
4317 Desig_Type
: Entity_Id
;
4319 Discr_Con_Elist
: Elist_Id
;
4320 Discr_Con_El
: Elmt_Id
;
4324 -- Set the designated type so it is available in case this is an access
4325 -- to a self-referential type, e.g. a standard list type with a next
4326 -- pointer. Will be reset after subtype is built.
4328 Set_Directly_Designated_Type
4329 (Derived_Type
, Designated_Type
(Parent_Type
));
4331 Subt
:= Process_Subtype
(S
, N
);
4333 if Nkind
(S
) /= N_Subtype_Indication
4334 and then Subt
/= Base_Type
(Subt
)
4336 Set_Ekind
(Derived_Type
, E_Access_Subtype
);
4339 if Ekind
(Derived_Type
) = E_Access_Subtype
then
4341 Pbase
: constant Entity_Id
:= Base_Type
(Parent_Type
);
4342 Ibase
: constant Entity_Id
:=
4343 Create_Itype
(Ekind
(Pbase
), N
, Derived_Type
, 'B');
4344 Svg_Chars
: constant Name_Id
:= Chars
(Ibase
);
4345 Svg_Next_E
: constant Entity_Id
:= Next_Entity
(Ibase
);
4348 Copy_Node
(Pbase
, Ibase
);
4350 Set_Chars
(Ibase
, Svg_Chars
);
4351 Set_Next_Entity
(Ibase
, Svg_Next_E
);
4352 Set_Sloc
(Ibase
, Sloc
(Derived_Type
));
4353 Set_Scope
(Ibase
, Scope
(Derived_Type
));
4354 Set_Freeze_Node
(Ibase
, Empty
);
4355 Set_Is_Frozen
(Ibase
, False);
4356 Set_Comes_From_Source
(Ibase
, False);
4357 Set_Is_First_Subtype
(Ibase
, False);
4359 Set_Etype
(Ibase
, Pbase
);
4360 Set_Etype
(Derived_Type
, Ibase
);
4364 Set_Directly_Designated_Type
4365 (Derived_Type
, Designated_Type
(Subt
));
4367 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Subt
));
4368 Set_Is_Access_Constant
(Derived_Type
, Is_Access_Constant
(Parent_Type
));
4369 Set_Size_Info
(Derived_Type
, Parent_Type
);
4370 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
4371 Set_Depends_On_Private
(Derived_Type
,
4372 Has_Private_Component
(Derived_Type
));
4373 Conditional_Delay
(Derived_Type
, Subt
);
4375 -- Ada 2005 (AI-231). Set the null-exclusion attribute
4377 if Null_Exclusion_Present
(Type_Definition
(N
))
4378 or else Can_Never_Be_Null
(Parent_Type
)
4380 Set_Can_Never_Be_Null
(Derived_Type
);
4383 -- Note: we do not copy the Storage_Size_Variable, since we always go to
4384 -- the root type for this information.
4386 -- Apply range checks to discriminants for derived record case
4387 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
4389 Desig_Type
:= Designated_Type
(Derived_Type
);
4390 if Is_Composite_Type
(Desig_Type
)
4391 and then (not Is_Array_Type
(Desig_Type
))
4392 and then Has_Discriminants
(Desig_Type
)
4393 and then Base_Type
(Desig_Type
) /= Desig_Type
4395 Discr_Con_Elist
:= Discriminant_Constraint
(Desig_Type
);
4396 Discr_Con_El
:= First_Elmt
(Discr_Con_Elist
);
4398 Discr
:= First_Discriminant
(Base_Type
(Desig_Type
));
4399 while Present
(Discr_Con_El
) loop
4400 Apply_Range_Check
(Node
(Discr_Con_El
), Etype
(Discr
));
4401 Next_Elmt
(Discr_Con_El
);
4402 Next_Discriminant
(Discr
);
4405 end Build_Derived_Access_Type
;
4407 ------------------------------
4408 -- Build_Derived_Array_Type --
4409 ------------------------------
4411 procedure Build_Derived_Array_Type
4413 Parent_Type
: Entity_Id
;
4414 Derived_Type
: Entity_Id
)
4416 Loc
: constant Source_Ptr
:= Sloc
(N
);
4417 Tdef
: constant Node_Id
:= Type_Definition
(N
);
4418 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
4419 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
4420 Implicit_Base
: Entity_Id
;
4421 New_Indic
: Node_Id
;
4423 procedure Make_Implicit_Base
;
4424 -- If the parent subtype is constrained, the derived type is a subtype
4425 -- of an implicit base type derived from the parent base.
4427 ------------------------
4428 -- Make_Implicit_Base --
4429 ------------------------
4431 procedure Make_Implicit_Base
is
4434 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
4436 Set_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
4437 Set_Etype
(Implicit_Base
, Parent_Base
);
4439 Copy_Array_Subtype_Attributes
(Implicit_Base
, Parent_Base
);
4440 Copy_Array_Base_Type_Attributes
(Implicit_Base
, Parent_Base
);
4442 Set_Has_Delayed_Freeze
(Implicit_Base
, True);
4443 end Make_Implicit_Base
;
4445 -- Start of processing for Build_Derived_Array_Type
4448 if not Is_Constrained
(Parent_Type
) then
4449 if Nkind
(Indic
) /= N_Subtype_Indication
then
4450 Set_Ekind
(Derived_Type
, E_Array_Type
);
4452 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
4453 Copy_Array_Base_Type_Attributes
(Derived_Type
, Parent_Type
);
4455 Set_Has_Delayed_Freeze
(Derived_Type
, True);
4459 Set_Etype
(Derived_Type
, Implicit_Base
);
4462 Make_Subtype_Declaration
(Loc
,
4463 Defining_Identifier
=> Derived_Type
,
4464 Subtype_Indication
=>
4465 Make_Subtype_Indication
(Loc
,
4466 Subtype_Mark
=> New_Reference_To
(Implicit_Base
, Loc
),
4467 Constraint
=> Constraint
(Indic
)));
4469 Rewrite
(N
, New_Indic
);
4474 if Nkind
(Indic
) /= N_Subtype_Indication
then
4477 Set_Ekind
(Derived_Type
, Ekind
(Parent_Type
));
4478 Set_Etype
(Derived_Type
, Implicit_Base
);
4479 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
4482 Error_Msg_N
("illegal constraint on constrained type", Indic
);
4486 -- If parent type is not a derived type itself, and is declared in
4487 -- closed scope (e.g. a subprogram), then we must explicitly introduce
4488 -- the new type's concatenation operator since Derive_Subprograms
4489 -- will not inherit the parent's operator. If the parent type is
4490 -- unconstrained, the operator is of the unconstrained base type.
4492 if Number_Dimensions
(Parent_Type
) = 1
4493 and then not Is_Limited_Type
(Parent_Type
)
4494 and then not Is_Derived_Type
(Parent_Type
)
4495 and then not Is_Package_Or_Generic_Package
4496 (Scope
(Base_Type
(Parent_Type
)))
4498 if not Is_Constrained
(Parent_Type
)
4499 and then Is_Constrained
(Derived_Type
)
4501 New_Concatenation_Op
(Implicit_Base
);
4503 New_Concatenation_Op
(Derived_Type
);
4506 end Build_Derived_Array_Type
;
4508 -----------------------------------
4509 -- Build_Derived_Concurrent_Type --
4510 -----------------------------------
4512 procedure Build_Derived_Concurrent_Type
4514 Parent_Type
: Entity_Id
;
4515 Derived_Type
: Entity_Id
)
4517 D_Constraint
: Node_Id
;
4518 Disc_Spec
: Node_Id
;
4519 Old_Disc
: Entity_Id
;
4520 New_Disc
: Entity_Id
;
4522 Constraint_Present
: constant Boolean :=
4523 Nkind
(Subtype_Indication
(Type_Definition
(N
)))
4524 = N_Subtype_Indication
;
4527 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
4529 if Is_Task_Type
(Parent_Type
) then
4530 Set_Storage_Size_Variable
(Derived_Type
,
4531 Storage_Size_Variable
(Parent_Type
));
4534 if Present
(Discriminant_Specifications
(N
)) then
4535 Push_Scope
(Derived_Type
);
4536 Check_Or_Process_Discriminants
(N
, Derived_Type
);
4539 elsif Constraint_Present
then
4541 -- Build constrained subtype and derive from it
4544 Loc
: constant Source_Ptr
:= Sloc
(N
);
4545 Anon
: constant Entity_Id
:=
4546 Make_Defining_Identifier
(Loc
,
4547 New_External_Name
(Chars
(Derived_Type
), 'T'));
4552 Make_Subtype_Declaration
(Loc
,
4553 Defining_Identifier
=> Anon
,
4554 Subtype_Indication
=>
4555 Subtype_Indication
(Type_Definition
(N
)));
4556 Insert_Before
(N
, Decl
);
4559 Rewrite
(Subtype_Indication
(Type_Definition
(N
)),
4560 New_Occurrence_Of
(Anon
, Loc
));
4561 Set_Analyzed
(Derived_Type
, False);
4567 -- All attributes are inherited from parent. In particular,
4568 -- entries and the corresponding record type are the same.
4569 -- Discriminants may be renamed, and must be treated separately.
4571 Set_Has_Discriminants
4572 (Derived_Type
, Has_Discriminants
(Parent_Type
));
4573 Set_Corresponding_Record_Type
4574 (Derived_Type
, Corresponding_Record_Type
(Parent_Type
));
4576 if Constraint_Present
then
4577 if not Has_Discriminants
(Parent_Type
) then
4578 Error_Msg_N
("untagged parent must have discriminants", N
);
4580 elsif Present
(Discriminant_Specifications
(N
)) then
4582 -- Verify that new discriminants are used to constrain old ones
4587 (Constraint
(Subtype_Indication
(Type_Definition
(N
)))));
4589 Old_Disc
:= First_Discriminant
(Parent_Type
);
4590 New_Disc
:= First_Discriminant
(Derived_Type
);
4591 Disc_Spec
:= First
(Discriminant_Specifications
(N
));
4592 while Present
(Old_Disc
) and then Present
(Disc_Spec
) loop
4593 if Nkind
(Discriminant_Type
(Disc_Spec
)) /=
4596 Analyze
(Discriminant_Type
(Disc_Spec
));
4598 if not Subtypes_Statically_Compatible
(
4599 Etype
(Discriminant_Type
(Disc_Spec
)),
4603 ("not statically compatible with parent discriminant",
4604 Discriminant_Type
(Disc_Spec
));
4608 if Nkind
(D_Constraint
) = N_Identifier
4609 and then Chars
(D_Constraint
) /=
4610 Chars
(Defining_Identifier
(Disc_Spec
))
4612 Error_Msg_N
("new discriminants must constrain old ones",
4615 Set_Corresponding_Discriminant
(New_Disc
, Old_Disc
);
4618 Next_Discriminant
(Old_Disc
);
4619 Next_Discriminant
(New_Disc
);
4623 if Present
(Old_Disc
) or else Present
(Disc_Spec
) then
4624 Error_Msg_N
("discriminant mismatch in derivation", N
);
4629 elsif Present
(Discriminant_Specifications
(N
)) then
4631 ("missing discriminant constraint in untagged derivation",
4635 if Present
(Discriminant_Specifications
(N
)) then
4636 Old_Disc
:= First_Discriminant
(Parent_Type
);
4637 while Present
(Old_Disc
) loop
4639 if No
(Next_Entity
(Old_Disc
))
4640 or else Ekind
(Next_Entity
(Old_Disc
)) /= E_Discriminant
4642 Set_Next_Entity
(Last_Entity
(Derived_Type
),
4643 Next_Entity
(Old_Disc
));
4647 Next_Discriminant
(Old_Disc
);
4651 Set_First_Entity
(Derived_Type
, First_Entity
(Parent_Type
));
4652 if Has_Discriminants
(Parent_Type
) then
4653 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
4654 Set_Discriminant_Constraint
(
4655 Derived_Type
, Discriminant_Constraint
(Parent_Type
));
4659 Set_Last_Entity
(Derived_Type
, Last_Entity
(Parent_Type
));
4661 Set_Has_Completion
(Derived_Type
);
4662 end Build_Derived_Concurrent_Type
;
4664 ------------------------------------
4665 -- Build_Derived_Enumeration_Type --
4666 ------------------------------------
4668 procedure Build_Derived_Enumeration_Type
4670 Parent_Type
: Entity_Id
;
4671 Derived_Type
: Entity_Id
)
4673 Loc
: constant Source_Ptr
:= Sloc
(N
);
4674 Def
: constant Node_Id
:= Type_Definition
(N
);
4675 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
4676 Implicit_Base
: Entity_Id
;
4677 Literal
: Entity_Id
;
4678 New_Lit
: Entity_Id
;
4679 Literals_List
: List_Id
;
4680 Type_Decl
: Node_Id
;
4682 Rang_Expr
: Node_Id
;
4685 -- Since types Standard.Character and Standard.Wide_Character do
4686 -- not have explicit literals lists we need to process types derived
4687 -- from them specially. This is handled by Derived_Standard_Character.
4688 -- If the parent type is a generic type, there are no literals either,
4689 -- and we construct the same skeletal representation as for the generic
4692 if Root_Type
(Parent_Type
) = Standard_Character
4693 or else Root_Type
(Parent_Type
) = Standard_Wide_Character
4694 or else Root_Type
(Parent_Type
) = Standard_Wide_Wide_Character
4696 Derived_Standard_Character
(N
, Parent_Type
, Derived_Type
);
4698 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
4705 Make_Attribute_Reference
(Loc
,
4706 Attribute_Name
=> Name_First
,
4707 Prefix
=> New_Reference_To
(Derived_Type
, Loc
));
4708 Set_Etype
(Lo
, Derived_Type
);
4711 Make_Attribute_Reference
(Loc
,
4712 Attribute_Name
=> Name_Last
,
4713 Prefix
=> New_Reference_To
(Derived_Type
, Loc
));
4714 Set_Etype
(Hi
, Derived_Type
);
4716 Set_Scalar_Range
(Derived_Type
,
4723 -- If a constraint is present, analyze the bounds to catch
4724 -- premature usage of the derived literals.
4726 if Nkind
(Indic
) = N_Subtype_Indication
4727 and then Nkind
(Range_Expression
(Constraint
(Indic
))) = N_Range
4729 Analyze
(Low_Bound
(Range_Expression
(Constraint
(Indic
))));
4730 Analyze
(High_Bound
(Range_Expression
(Constraint
(Indic
))));
4733 -- Introduce an implicit base type for the derived type even if there
4734 -- is no constraint attached to it, since this seems closer to the
4735 -- Ada semantics. Build a full type declaration tree for the derived
4736 -- type using the implicit base type as the defining identifier. The
4737 -- build a subtype declaration tree which applies the constraint (if
4738 -- any) have it replace the derived type declaration.
4740 Literal
:= First_Literal
(Parent_Type
);
4741 Literals_List
:= New_List
;
4742 while Present
(Literal
)
4743 and then Ekind
(Literal
) = E_Enumeration_Literal
4745 -- Literals of the derived type have the same representation as
4746 -- those of the parent type, but this representation can be
4747 -- overridden by an explicit representation clause. Indicate
4748 -- that there is no explicit representation given yet. These
4749 -- derived literals are implicit operations of the new type,
4750 -- and can be overridden by explicit ones.
4752 if Nkind
(Literal
) = N_Defining_Character_Literal
then
4754 Make_Defining_Character_Literal
(Loc
, Chars
(Literal
));
4756 New_Lit
:= Make_Defining_Identifier
(Loc
, Chars
(Literal
));
4759 Set_Ekind
(New_Lit
, E_Enumeration_Literal
);
4760 Set_Enumeration_Pos
(New_Lit
, Enumeration_Pos
(Literal
));
4761 Set_Enumeration_Rep
(New_Lit
, Enumeration_Rep
(Literal
));
4762 Set_Enumeration_Rep_Expr
(New_Lit
, Empty
);
4763 Set_Alias
(New_Lit
, Literal
);
4764 Set_Is_Known_Valid
(New_Lit
, True);
4766 Append
(New_Lit
, Literals_List
);
4767 Next_Literal
(Literal
);
4771 Make_Defining_Identifier
(Sloc
(Derived_Type
),
4772 New_External_Name
(Chars
(Derived_Type
), 'B'));
4774 -- Indicate the proper nature of the derived type. This must be done
4775 -- before analysis of the literals, to recognize cases when a literal
4776 -- may be hidden by a previous explicit function definition (cf.
4779 Set_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
4780 Set_Etype
(Derived_Type
, Implicit_Base
);
4783 Make_Full_Type_Declaration
(Loc
,
4784 Defining_Identifier
=> Implicit_Base
,
4785 Discriminant_Specifications
=> No_List
,
4787 Make_Enumeration_Type_Definition
(Loc
, Literals_List
));
4789 Mark_Rewrite_Insertion
(Type_Decl
);
4790 Insert_Before
(N
, Type_Decl
);
4791 Analyze
(Type_Decl
);
4793 -- After the implicit base is analyzed its Etype needs to be changed
4794 -- to reflect the fact that it is derived from the parent type which
4795 -- was ignored during analysis. We also set the size at this point.
4797 Set_Etype
(Implicit_Base
, Parent_Type
);
4799 Set_Size_Info
(Implicit_Base
, Parent_Type
);
4800 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Type
));
4801 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Type
));
4803 Set_Has_Non_Standard_Rep
4804 (Implicit_Base
, Has_Non_Standard_Rep
4806 Set_Has_Delayed_Freeze
(Implicit_Base
);
4808 -- Process the subtype indication including a validation check on the
4809 -- constraint, if any. If a constraint is given, its bounds must be
4810 -- implicitly converted to the new type.
4812 if Nkind
(Indic
) = N_Subtype_Indication
then
4814 R
: constant Node_Id
:=
4815 Range_Expression
(Constraint
(Indic
));
4818 if Nkind
(R
) = N_Range
then
4819 Hi
:= Build_Scalar_Bound
4820 (High_Bound
(R
), Parent_Type
, Implicit_Base
);
4821 Lo
:= Build_Scalar_Bound
4822 (Low_Bound
(R
), Parent_Type
, Implicit_Base
);
4825 -- Constraint is a Range attribute. Replace with explicit
4826 -- mention of the bounds of the prefix, which must be a
4829 Analyze
(Prefix
(R
));
4831 Convert_To
(Implicit_Base
,
4832 Make_Attribute_Reference
(Loc
,
4833 Attribute_Name
=> Name_Last
,
4835 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
4838 Convert_To
(Implicit_Base
,
4839 Make_Attribute_Reference
(Loc
,
4840 Attribute_Name
=> Name_First
,
4842 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
4849 (Type_High_Bound
(Parent_Type
),
4850 Parent_Type
, Implicit_Base
);
4853 (Type_Low_Bound
(Parent_Type
),
4854 Parent_Type
, Implicit_Base
);
4862 -- If we constructed a default range for the case where no range
4863 -- was given, then the expressions in the range must not freeze
4864 -- since they do not correspond to expressions in the source.
4866 if Nkind
(Indic
) /= N_Subtype_Indication
then
4867 Set_Must_Not_Freeze
(Lo
);
4868 Set_Must_Not_Freeze
(Hi
);
4869 Set_Must_Not_Freeze
(Rang_Expr
);
4873 Make_Subtype_Declaration
(Loc
,
4874 Defining_Identifier
=> Derived_Type
,
4875 Subtype_Indication
=>
4876 Make_Subtype_Indication
(Loc
,
4877 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
4879 Make_Range_Constraint
(Loc
,
4880 Range_Expression
=> Rang_Expr
))));
4884 -- If pragma Discard_Names applies on the first subtype of the parent
4885 -- type, then it must be applied on this subtype as well.
4887 if Einfo
.Discard_Names
(First_Subtype
(Parent_Type
)) then
4888 Set_Discard_Names
(Derived_Type
);
4891 -- Apply a range check. Since this range expression doesn't have an
4892 -- Etype, we have to specifically pass the Source_Typ parameter. Is
4895 if Nkind
(Indic
) = N_Subtype_Indication
then
4896 Apply_Range_Check
(Range_Expression
(Constraint
(Indic
)),
4898 Source_Typ
=> Entity
(Subtype_Mark
(Indic
)));
4901 end Build_Derived_Enumeration_Type
;
4903 --------------------------------
4904 -- Build_Derived_Numeric_Type --
4905 --------------------------------
4907 procedure Build_Derived_Numeric_Type
4909 Parent_Type
: Entity_Id
;
4910 Derived_Type
: Entity_Id
)
4912 Loc
: constant Source_Ptr
:= Sloc
(N
);
4913 Tdef
: constant Node_Id
:= Type_Definition
(N
);
4914 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
4915 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
4916 No_Constraint
: constant Boolean := Nkind
(Indic
) /=
4917 N_Subtype_Indication
;
4918 Implicit_Base
: Entity_Id
;
4924 -- Process the subtype indication including a validation check on
4925 -- the constraint if any.
4927 Discard_Node
(Process_Subtype
(Indic
, N
));
4929 -- Introduce an implicit base type for the derived type even if there
4930 -- is no constraint attached to it, since this seems closer to the Ada
4934 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
4936 Set_Etype
(Implicit_Base
, Parent_Base
);
4937 Set_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
4938 Set_Size_Info
(Implicit_Base
, Parent_Base
);
4939 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Base
));
4940 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Base
));
4941 Set_Parent
(Implicit_Base
, Parent
(Derived_Type
));
4943 if Is_Discrete_Or_Fixed_Point_Type
(Parent_Base
) then
4944 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Base
));
4947 Set_Has_Delayed_Freeze
(Implicit_Base
);
4949 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
4950 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
4952 Set_Scalar_Range
(Implicit_Base
,
4957 if Has_Infinities
(Parent_Base
) then
4958 Set_Includes_Infinities
(Scalar_Range
(Implicit_Base
));
4961 -- The Derived_Type, which is the entity of the declaration, is a
4962 -- subtype of the implicit base. Its Ekind is a subtype, even in the
4963 -- absence of an explicit constraint.
4965 Set_Etype
(Derived_Type
, Implicit_Base
);
4967 -- If we did not have a constraint, then the Ekind is set from the
4968 -- parent type (otherwise Process_Subtype has set the bounds)
4970 if No_Constraint
then
4971 Set_Ekind
(Derived_Type
, Subtype_Kind
(Ekind
(Parent_Type
)));
4974 -- If we did not have a range constraint, then set the range from the
4975 -- parent type. Otherwise, the call to Process_Subtype has set the
4979 or else not Has_Range_Constraint
(Indic
)
4981 Set_Scalar_Range
(Derived_Type
,
4983 Low_Bound
=> New_Copy_Tree
(Type_Low_Bound
(Parent_Type
)),
4984 High_Bound
=> New_Copy_Tree
(Type_High_Bound
(Parent_Type
))));
4985 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
4987 if Has_Infinities
(Parent_Type
) then
4988 Set_Includes_Infinities
(Scalar_Range
(Derived_Type
));
4992 Set_Is_Descendent_Of_Address
(Derived_Type
,
4993 Is_Descendent_Of_Address
(Parent_Type
));
4994 Set_Is_Descendent_Of_Address
(Implicit_Base
,
4995 Is_Descendent_Of_Address
(Parent_Type
));
4997 -- Set remaining type-specific fields, depending on numeric type
4999 if Is_Modular_Integer_Type
(Parent_Type
) then
5000 Set_Modulus
(Implicit_Base
, Modulus
(Parent_Base
));
5002 Set_Non_Binary_Modulus
5003 (Implicit_Base
, Non_Binary_Modulus
(Parent_Base
));
5005 elsif Is_Floating_Point_Type
(Parent_Type
) then
5007 -- Digits of base type is always copied from the digits value of
5008 -- the parent base type, but the digits of the derived type will
5009 -- already have been set if there was a constraint present.
5011 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
5012 Set_Vax_Float
(Implicit_Base
, Vax_Float
(Parent_Base
));
5014 if No_Constraint
then
5015 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Type
));
5018 elsif Is_Fixed_Point_Type
(Parent_Type
) then
5020 -- Small of base type and derived type are always copied from the
5021 -- parent base type, since smalls never change. The delta of the
5022 -- base type is also copied from the parent base type. However the
5023 -- delta of the derived type will have been set already if a
5024 -- constraint was present.
5026 Set_Small_Value
(Derived_Type
, Small_Value
(Parent_Base
));
5027 Set_Small_Value
(Implicit_Base
, Small_Value
(Parent_Base
));
5028 Set_Delta_Value
(Implicit_Base
, Delta_Value
(Parent_Base
));
5030 if No_Constraint
then
5031 Set_Delta_Value
(Derived_Type
, Delta_Value
(Parent_Type
));
5034 -- The scale and machine radix in the decimal case are always
5035 -- copied from the parent base type.
5037 if Is_Decimal_Fixed_Point_Type
(Parent_Type
) then
5038 Set_Scale_Value
(Derived_Type
, Scale_Value
(Parent_Base
));
5039 Set_Scale_Value
(Implicit_Base
, Scale_Value
(Parent_Base
));
5041 Set_Machine_Radix_10
5042 (Derived_Type
, Machine_Radix_10
(Parent_Base
));
5043 Set_Machine_Radix_10
5044 (Implicit_Base
, Machine_Radix_10
(Parent_Base
));
5046 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
5048 if No_Constraint
then
5049 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Base
));
5052 -- the analysis of the subtype_indication sets the
5053 -- digits value of the derived type.
5060 -- The type of the bounds is that of the parent type, and they
5061 -- must be converted to the derived type.
5063 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
5065 -- The implicit_base should be frozen when the derived type is frozen,
5066 -- but note that it is used in the conversions of the bounds. For fixed
5067 -- types we delay the determination of the bounds until the proper
5068 -- freezing point. For other numeric types this is rejected by GCC, for
5069 -- reasons that are currently unclear (???), so we choose to freeze the
5070 -- implicit base now. In the case of integers and floating point types
5071 -- this is harmless because subsequent representation clauses cannot
5072 -- affect anything, but it is still baffling that we cannot use the
5073 -- same mechanism for all derived numeric types.
5075 -- There is a further complication: actually *some* representation
5076 -- clauses can affect the implicit base type. Namely, attribute
5077 -- definition clauses for stream-oriented attributes need to set the
5078 -- corresponding TSS entries on the base type, and this normally cannot
5079 -- be done after the base type is frozen, so the circuitry in
5080 -- Sem_Ch13.New_Stream_Subprogram must account for this possibility and
5081 -- not use Set_TSS in this case.
5083 if Is_Fixed_Point_Type
(Parent_Type
) then
5084 Conditional_Delay
(Implicit_Base
, Parent_Type
);
5086 Freeze_Before
(N
, Implicit_Base
);
5088 end Build_Derived_Numeric_Type
;
5090 --------------------------------
5091 -- Build_Derived_Private_Type --
5092 --------------------------------
5094 procedure Build_Derived_Private_Type
5096 Parent_Type
: Entity_Id
;
5097 Derived_Type
: Entity_Id
;
5098 Is_Completion
: Boolean;
5099 Derive_Subps
: Boolean := True)
5101 Der_Base
: Entity_Id
;
5103 Full_Decl
: Node_Id
:= Empty
;
5104 Full_Der
: Entity_Id
;
5106 Last_Discr
: Entity_Id
;
5107 Par_Scope
: constant Entity_Id
:= Scope
(Base_Type
(Parent_Type
));
5108 Swapped
: Boolean := False;
5110 procedure Copy_And_Build
;
5111 -- Copy derived type declaration, replace parent with its full view,
5112 -- and analyze new declaration.
5114 --------------------
5115 -- Copy_And_Build --
5116 --------------------
5118 procedure Copy_And_Build
is
5122 if Ekind
(Parent_Type
) in Record_Kind
5124 (Ekind
(Parent_Type
) in Enumeration_Kind
5125 and then Root_Type
(Parent_Type
) /= Standard_Character
5126 and then Root_Type
(Parent_Type
) /= Standard_Wide_Character
5127 and then Root_Type
(Parent_Type
) /= Standard_Wide_Wide_Character
5128 and then not Is_Generic_Type
(Root_Type
(Parent_Type
)))
5130 Full_N
:= New_Copy_Tree
(N
);
5131 Insert_After
(N
, Full_N
);
5132 Build_Derived_Type
(
5133 Full_N
, Parent_Type
, Full_Der
, True, Derive_Subps
=> False);
5136 Build_Derived_Type
(
5137 N
, Parent_Type
, Full_Der
, True, Derive_Subps
=> False);
5141 -- Start of processing for Build_Derived_Private_Type
5144 if Is_Tagged_Type
(Parent_Type
) then
5145 Build_Derived_Record_Type
5146 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
5149 elsif Has_Discriminants
(Parent_Type
) then
5150 if Present
(Full_View
(Parent_Type
)) then
5151 if not Is_Completion
then
5153 -- Copy declaration for subsequent analysis, to provide a
5154 -- completion for what is a private declaration. Indicate that
5155 -- the full type is internally generated.
5157 Full_Decl
:= New_Copy_Tree
(N
);
5158 Full_Der
:= New_Copy
(Derived_Type
);
5159 Set_Comes_From_Source
(Full_Decl
, False);
5160 Set_Comes_From_Source
(Full_Der
, False);
5162 Insert_After
(N
, Full_Decl
);
5165 -- If this is a completion, the full view being built is
5166 -- itself private. We build a subtype of the parent with
5167 -- the same constraints as this full view, to convey to the
5168 -- back end the constrained components and the size of this
5169 -- subtype. If the parent is constrained, its full view can
5170 -- serve as the underlying full view of the derived type.
5172 if No
(Discriminant_Specifications
(N
)) then
5173 if Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
5174 N_Subtype_Indication
5176 Build_Underlying_Full_View
(N
, Derived_Type
, Parent_Type
);
5178 elsif Is_Constrained
(Full_View
(Parent_Type
)) then
5179 Set_Underlying_Full_View
(Derived_Type
,
5180 Full_View
(Parent_Type
));
5184 -- If there are new discriminants, the parent subtype is
5185 -- constrained by them, but it is not clear how to build
5186 -- the underlying_full_view in this case ???
5193 -- Build partial view of derived type from partial view of parent
5195 Build_Derived_Record_Type
5196 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
5198 if Present
(Full_View
(Parent_Type
))
5199 and then not Is_Completion
5201 if not In_Open_Scopes
(Par_Scope
)
5202 or else not In_Same_Source_Unit
(N
, Parent_Type
)
5204 -- Swap partial and full views temporarily
5206 Install_Private_Declarations
(Par_Scope
);
5207 Install_Visible_Declarations
(Par_Scope
);
5211 -- Build full view of derived type from full view of parent which
5212 -- is now installed. Subprograms have been derived on the partial
5213 -- view, the completion does not derive them anew.
5215 if not Is_Tagged_Type
(Parent_Type
) then
5217 -- If the parent is itself derived from another private type,
5218 -- installing the private declarations has not affected its
5219 -- privacy status, so use its own full view explicitly.
5221 if Is_Private_Type
(Parent_Type
) then
5222 Build_Derived_Record_Type
5223 (Full_Decl
, Full_View
(Parent_Type
), Full_Der
, False);
5225 Build_Derived_Record_Type
5226 (Full_Decl
, Parent_Type
, Full_Der
, False);
5230 -- If full view of parent is tagged, the completion
5231 -- inherits the proper primitive operations.
5233 Set_Defining_Identifier
(Full_Decl
, Full_Der
);
5234 Build_Derived_Record_Type
5235 (Full_Decl
, Parent_Type
, Full_Der
, Derive_Subps
);
5236 Set_Analyzed
(Full_Decl
);
5240 Uninstall_Declarations
(Par_Scope
);
5242 if In_Open_Scopes
(Par_Scope
) then
5243 Install_Visible_Declarations
(Par_Scope
);
5247 Der_Base
:= Base_Type
(Derived_Type
);
5248 Set_Full_View
(Derived_Type
, Full_Der
);
5249 Set_Full_View
(Der_Base
, Base_Type
(Full_Der
));
5251 -- Copy the discriminant list from full view to the partial views
5252 -- (base type and its subtype). Gigi requires that the partial
5253 -- and full views have the same discriminants.
5255 -- Note that since the partial view is pointing to discriminants
5256 -- in the full view, their scope will be that of the full view.
5257 -- This might cause some front end problems and need
5260 Discr
:= First_Discriminant
(Base_Type
(Full_Der
));
5261 Set_First_Entity
(Der_Base
, Discr
);
5264 Last_Discr
:= Discr
;
5265 Next_Discriminant
(Discr
);
5266 exit when No
(Discr
);
5269 Set_Last_Entity
(Der_Base
, Last_Discr
);
5271 Set_First_Entity
(Derived_Type
, First_Entity
(Der_Base
));
5272 Set_Last_Entity
(Derived_Type
, Last_Entity
(Der_Base
));
5273 Set_Stored_Constraint
(Full_Der
, Stored_Constraint
(Derived_Type
));
5276 -- If this is a completion, the derived type stays private
5277 -- and there is no need to create a further full view, except
5278 -- in the unusual case when the derivation is nested within a
5279 -- child unit, see below.
5284 elsif Present
(Full_View
(Parent_Type
))
5285 and then Has_Discriminants
(Full_View
(Parent_Type
))
5287 if Has_Unknown_Discriminants
(Parent_Type
)
5288 and then Nkind
(Subtype_Indication
(Type_Definition
(N
)))
5289 = N_Subtype_Indication
5292 ("cannot constrain type with unknown discriminants",
5293 Subtype_Indication
(Type_Definition
(N
)));
5297 -- If full view of parent is a record type, Build full view as
5298 -- a derivation from the parent's full view. Partial view remains
5299 -- private. For code generation and linking, the full view must
5300 -- have the same public status as the partial one. This full view
5301 -- is only needed if the parent type is in an enclosing scope, so
5302 -- that the full view may actually become visible, e.g. in a child
5303 -- unit. This is both more efficient, and avoids order of freezing
5304 -- problems with the added entities.
5306 if not Is_Private_Type
(Full_View
(Parent_Type
))
5307 and then (In_Open_Scopes
(Scope
(Parent_Type
)))
5309 Full_Der
:= Make_Defining_Identifier
(Sloc
(Derived_Type
),
5310 Chars
(Derived_Type
));
5311 Set_Is_Itype
(Full_Der
);
5312 Set_Has_Private_Declaration
(Full_Der
);
5313 Set_Has_Private_Declaration
(Derived_Type
);
5314 Set_Associated_Node_For_Itype
(Full_Der
, N
);
5315 Set_Parent
(Full_Der
, Parent
(Derived_Type
));
5316 Set_Full_View
(Derived_Type
, Full_Der
);
5317 Set_Is_Public
(Full_Der
, Is_Public
(Derived_Type
));
5318 Full_P
:= Full_View
(Parent_Type
);
5319 Exchange_Declarations
(Parent_Type
);
5321 Exchange_Declarations
(Full_P
);
5324 Build_Derived_Record_Type
5325 (N
, Full_View
(Parent_Type
), Derived_Type
,
5326 Derive_Subps
=> False);
5329 -- In any case, the primitive operations are inherited from
5330 -- the parent type, not from the internal full view.
5332 Set_Etype
(Base_Type
(Derived_Type
), Base_Type
(Parent_Type
));
5334 if Derive_Subps
then
5335 Derive_Subprograms
(Parent_Type
, Derived_Type
);
5339 -- Untagged type, No discriminants on either view
5341 if Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
5342 N_Subtype_Indication
5345 ("illegal constraint on type without discriminants", N
);
5348 if Present
(Discriminant_Specifications
(N
))
5349 and then Present
(Full_View
(Parent_Type
))
5350 and then not Is_Tagged_Type
(Full_View
(Parent_Type
))
5353 ("cannot add discriminants to untagged type", N
);
5356 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
5357 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
5358 Set_Is_Controlled
(Derived_Type
, Is_Controlled
(Parent_Type
));
5359 Set_Has_Controlled_Component
5360 (Derived_Type
, Has_Controlled_Component
5363 -- Direct controlled types do not inherit Finalize_Storage_Only flag
5365 if not Is_Controlled
(Parent_Type
) then
5366 Set_Finalize_Storage_Only
5367 (Base_Type
(Derived_Type
), Finalize_Storage_Only
(Parent_Type
));
5370 -- Construct the implicit full view by deriving from full view of
5371 -- the parent type. In order to get proper visibility, we install
5372 -- the parent scope and its declarations.
5374 -- ??? if the parent is untagged private and its completion is
5375 -- tagged, this mechanism will not work because we cannot derive
5376 -- from the tagged full view unless we have an extension
5378 if Present
(Full_View
(Parent_Type
))
5379 and then not Is_Tagged_Type
(Full_View
(Parent_Type
))
5380 and then not Is_Completion
5383 Make_Defining_Identifier
(Sloc
(Derived_Type
),
5384 Chars
=> Chars
(Derived_Type
));
5385 Set_Is_Itype
(Full_Der
);
5386 Set_Has_Private_Declaration
(Full_Der
);
5387 Set_Has_Private_Declaration
(Derived_Type
);
5388 Set_Associated_Node_For_Itype
(Full_Der
, N
);
5389 Set_Parent
(Full_Der
, Parent
(Derived_Type
));
5390 Set_Full_View
(Derived_Type
, Full_Der
);
5392 if not In_Open_Scopes
(Par_Scope
) then
5393 Install_Private_Declarations
(Par_Scope
);
5394 Install_Visible_Declarations
(Par_Scope
);
5396 Uninstall_Declarations
(Par_Scope
);
5398 -- If parent scope is open and in another unit, and parent has a
5399 -- completion, then the derivation is taking place in the visible
5400 -- part of a child unit. In that case retrieve the full view of
5401 -- the parent momentarily.
5403 elsif not In_Same_Source_Unit
(N
, Parent_Type
) then
5404 Full_P
:= Full_View
(Parent_Type
);
5405 Exchange_Declarations
(Parent_Type
);
5407 Exchange_Declarations
(Full_P
);
5409 -- Otherwise it is a local derivation
5415 Set_Scope
(Full_Der
, Current_Scope
);
5416 Set_Is_First_Subtype
(Full_Der
,
5417 Is_First_Subtype
(Derived_Type
));
5418 Set_Has_Size_Clause
(Full_Der
, False);
5419 Set_Has_Alignment_Clause
(Full_Der
, False);
5420 Set_Next_Entity
(Full_Der
, Empty
);
5421 Set_Has_Delayed_Freeze
(Full_Der
);
5422 Set_Is_Frozen
(Full_Der
, False);
5423 Set_Freeze_Node
(Full_Der
, Empty
);
5424 Set_Depends_On_Private
(Full_Der
,
5425 Has_Private_Component
(Full_Der
));
5426 Set_Public_Status
(Full_Der
);
5430 Set_Has_Unknown_Discriminants
(Derived_Type
,
5431 Has_Unknown_Discriminants
(Parent_Type
));
5433 if Is_Private_Type
(Derived_Type
) then
5434 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
5437 if Is_Private_Type
(Parent_Type
)
5438 and then Base_Type
(Parent_Type
) = Parent_Type
5439 and then In_Open_Scopes
(Scope
(Parent_Type
))
5441 Append_Elmt
(Derived_Type
, Private_Dependents
(Parent_Type
));
5443 if Is_Child_Unit
(Scope
(Current_Scope
))
5444 and then Is_Completion
5445 and then In_Private_Part
(Current_Scope
)
5446 and then Scope
(Parent_Type
) /= Current_Scope
5448 -- This is the unusual case where a type completed by a private
5449 -- derivation occurs within a package nested in a child unit,
5450 -- and the parent is declared in an ancestor. In this case, the
5451 -- full view of the parent type will become visible in the body
5452 -- of the enclosing child, and only then will the current type
5453 -- be possibly non-private. We build a underlying full view that
5454 -- will be installed when the enclosing child body is compiled.
5457 Make_Defining_Identifier
(Sloc
(Derived_Type
),
5458 Chars
=> Chars
(Derived_Type
));
5459 Set_Is_Itype
(Full_Der
);
5460 Build_Itype_Reference
(Full_Der
, N
);
5462 -- The full view will be used to swap entities on entry/exit to
5463 -- the body, and must appear in the entity list for the package.
5465 Append_Entity
(Full_Der
, Scope
(Derived_Type
));
5466 Set_Has_Private_Declaration
(Full_Der
);
5467 Set_Has_Private_Declaration
(Derived_Type
);
5468 Set_Associated_Node_For_Itype
(Full_Der
, N
);
5469 Set_Parent
(Full_Der
, Parent
(Derived_Type
));
5470 Full_P
:= Full_View
(Parent_Type
);
5471 Exchange_Declarations
(Parent_Type
);
5473 Exchange_Declarations
(Full_P
);
5474 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
5477 end Build_Derived_Private_Type
;
5479 -------------------------------
5480 -- Build_Derived_Record_Type --
5481 -------------------------------
5485 -- Ideally we would like to use the same model of type derivation for
5486 -- tagged and untagged record types. Unfortunately this is not quite
5487 -- possible because the semantics of representation clauses is different
5488 -- for tagged and untagged records under inheritance. Consider the
5491 -- type R (...) is [tagged] record ... end record;
5492 -- type T (...) is new R (...) [with ...];
5494 -- The representation clauses for T can specify a completely different
5495 -- record layout from R's. Hence the same component can be placed in two
5496 -- very different positions in objects of type T and R. If R and are tagged
5497 -- types, representation clauses for T can only specify the layout of non
5498 -- inherited components, thus components that are common in R and T have
5499 -- the same position in objects of type R and T.
5501 -- This has two implications. The first is that the entire tree for R's
5502 -- declaration needs to be copied for T in the untagged case, so that T
5503 -- can be viewed as a record type of its own with its own representation
5504 -- clauses. The second implication is the way we handle discriminants.
5505 -- Specifically, in the untagged case we need a way to communicate to Gigi
5506 -- what are the real discriminants in the record, while for the semantics
5507 -- we need to consider those introduced by the user to rename the
5508 -- discriminants in the parent type. This is handled by introducing the
5509 -- notion of stored discriminants. See below for more.
5511 -- Fortunately the way regular components are inherited can be handled in
5512 -- the same way in tagged and untagged types.
5514 -- To complicate things a bit more the private view of a private extension
5515 -- cannot be handled in the same way as the full view (for one thing the
5516 -- semantic rules are somewhat different). We will explain what differs
5519 -- 2. DISCRIMINANTS UNDER INHERITANCE
5521 -- The semantic rules governing the discriminants of derived types are
5524 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
5525 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
5527 -- If parent type has discriminants, then the discriminants that are
5528 -- declared in the derived type are [3.4 (11)]:
5530 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
5533 -- o Otherwise, each discriminant of the parent type (implicitly declared
5534 -- in the same order with the same specifications). In this case, the
5535 -- discriminants are said to be "inherited", or if unknown in the parent
5536 -- are also unknown in the derived type.
5538 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
5540 -- o The parent subtype shall be constrained;
5542 -- o If the parent type is not a tagged type, then each discriminant of
5543 -- the derived type shall be used in the constraint defining a parent
5544 -- subtype. [Implementation note: This ensures that the new discriminant
5545 -- can share storage with an existing discriminant.]
5547 -- For the derived type each discriminant of the parent type is either
5548 -- inherited, constrained to equal some new discriminant of the derived
5549 -- type, or constrained to the value of an expression.
5551 -- When inherited or constrained to equal some new discriminant, the
5552 -- parent discriminant and the discriminant of the derived type are said
5555 -- If a discriminant of the parent type is constrained to a specific value
5556 -- in the derived type definition, then the discriminant is said to be
5557 -- "specified" by that derived type definition.
5559 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
5561 -- We have spoken about stored discriminants in point 1 (introduction)
5562 -- above. There are two sort of stored discriminants: implicit and
5563 -- explicit. As long as the derived type inherits the same discriminants as
5564 -- the root record type, stored discriminants are the same as regular
5565 -- discriminants, and are said to be implicit. However, if any discriminant
5566 -- in the root type was renamed in the derived type, then the derived
5567 -- type will contain explicit stored discriminants. Explicit stored
5568 -- discriminants are discriminants in addition to the semantically visible
5569 -- discriminants defined for the derived type. Stored discriminants are
5570 -- used by Gigi to figure out what are the physical discriminants in
5571 -- objects of the derived type (see precise definition in einfo.ads).
5572 -- As an example, consider the following:
5574 -- type R (D1, D2, D3 : Int) is record ... end record;
5575 -- type T1 is new R;
5576 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
5577 -- type T3 is new T2;
5578 -- type T4 (Y : Int) is new T3 (Y, 99);
5580 -- The following table summarizes the discriminants and stored
5581 -- discriminants in R and T1 through T4.
5583 -- Type Discrim Stored Discrim Comment
5584 -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
5585 -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
5586 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
5587 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
5588 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
5590 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
5591 -- find the corresponding discriminant in the parent type, while
5592 -- Original_Record_Component (abbreviated ORC below), the actual physical
5593 -- component that is renamed. Finally the field Is_Completely_Hidden
5594 -- (abbreviated ICH below) is set for all explicit stored discriminants
5595 -- (see einfo.ads for more info). For the above example this gives:
5597 -- Discrim CD ORC ICH
5598 -- ^^^^^^^ ^^ ^^^ ^^^
5599 -- D1 in R empty itself no
5600 -- D2 in R empty itself no
5601 -- D3 in R empty itself no
5603 -- D1 in T1 D1 in R itself no
5604 -- D2 in T1 D2 in R itself no
5605 -- D3 in T1 D3 in R itself no
5607 -- X1 in T2 D3 in T1 D3 in T2 no
5608 -- X2 in T2 D1 in T1 D1 in T2 no
5609 -- D1 in T2 empty itself yes
5610 -- D2 in T2 empty itself yes
5611 -- D3 in T2 empty itself yes
5613 -- X1 in T3 X1 in T2 D3 in T3 no
5614 -- X2 in T3 X2 in T2 D1 in T3 no
5615 -- D1 in T3 empty itself yes
5616 -- D2 in T3 empty itself yes
5617 -- D3 in T3 empty itself yes
5619 -- Y in T4 X1 in T3 D3 in T3 no
5620 -- D1 in T3 empty itself yes
5621 -- D2 in T3 empty itself yes
5622 -- D3 in T3 empty itself yes
5624 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
5626 -- Type derivation for tagged types is fairly straightforward. If no
5627 -- discriminants are specified by the derived type, these are inherited
5628 -- from the parent. No explicit stored discriminants are ever necessary.
5629 -- The only manipulation that is done to the tree is that of adding a
5630 -- _parent field with parent type and constrained to the same constraint
5631 -- specified for the parent in the derived type definition. For instance:
5633 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
5634 -- type T1 is new R with null record;
5635 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
5637 -- are changed into:
5639 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
5640 -- _parent : R (D1, D2, D3);
5643 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
5644 -- _parent : T1 (X2, 88, X1);
5647 -- The discriminants actually present in R, T1 and T2 as well as their CD,
5648 -- ORC and ICH fields are:
5650 -- Discrim CD ORC ICH
5651 -- ^^^^^^^ ^^ ^^^ ^^^
5652 -- D1 in R empty itself no
5653 -- D2 in R empty itself no
5654 -- D3 in R empty itself no
5656 -- D1 in T1 D1 in R D1 in R no
5657 -- D2 in T1 D2 in R D2 in R no
5658 -- D3 in T1 D3 in R D3 in R no
5660 -- X1 in T2 D3 in T1 D3 in R no
5661 -- X2 in T2 D1 in T1 D1 in R no
5663 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
5665 -- Regardless of whether we dealing with a tagged or untagged type
5666 -- we will transform all derived type declarations of the form
5668 -- type T is new R (...) [with ...];
5670 -- subtype S is R (...);
5671 -- type T is new S [with ...];
5673 -- type BT is new R [with ...];
5674 -- subtype T is BT (...);
5676 -- That is, the base derived type is constrained only if it has no
5677 -- discriminants. The reason for doing this is that GNAT's semantic model
5678 -- assumes that a base type with discriminants is unconstrained.
5680 -- Note that, strictly speaking, the above transformation is not always
5681 -- correct. Consider for instance the following excerpt from ACVC b34011a:
5683 -- procedure B34011A is
5684 -- type REC (D : integer := 0) is record
5689 -- type T6 is new Rec;
5690 -- function F return T6;
5695 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
5698 -- The definition of Q6.U is illegal. However transforming Q6.U into
5700 -- type BaseU is new T6;
5701 -- subtype U is BaseU (Q6.F.I)
5703 -- turns U into a legal subtype, which is incorrect. To avoid this problem
5704 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
5705 -- the transformation described above.
5707 -- There is another instance where the above transformation is incorrect.
5711 -- type Base (D : Integer) is tagged null record;
5712 -- procedure P (X : Base);
5714 -- type Der is new Base (2) with null record;
5715 -- procedure P (X : Der);
5718 -- Then the above transformation turns this into
5720 -- type Der_Base is new Base with null record;
5721 -- -- procedure P (X : Base) is implicitly inherited here
5722 -- -- as procedure P (X : Der_Base).
5724 -- subtype Der is Der_Base (2);
5725 -- procedure P (X : Der);
5726 -- -- The overriding of P (X : Der_Base) is illegal since we
5727 -- -- have a parameter conformance problem.
5729 -- To get around this problem, after having semantically processed Der_Base
5730 -- and the rewritten subtype declaration for Der, we copy Der_Base field
5731 -- Discriminant_Constraint from Der so that when parameter conformance is
5732 -- checked when P is overridden, no semantic errors are flagged.
5734 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
5736 -- Regardless of whether we are dealing with a tagged or untagged type
5737 -- we will transform all derived type declarations of the form
5739 -- type R (D1, .., Dn : ...) is [tagged] record ...;
5740 -- type T is new R [with ...];
5742 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
5744 -- The reason for such transformation is that it allows us to implement a
5745 -- very clean form of component inheritance as explained below.
5747 -- Note that this transformation is not achieved by direct tree rewriting
5748 -- and manipulation, but rather by redoing the semantic actions that the
5749 -- above transformation will entail. This is done directly in routine
5750 -- Inherit_Components.
5752 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
5754 -- In both tagged and untagged derived types, regular non discriminant
5755 -- components are inherited in the derived type from the parent type. In
5756 -- the absence of discriminants component, inheritance is straightforward
5757 -- as components can simply be copied from the parent.
5759 -- If the parent has discriminants, inheriting components constrained with
5760 -- these discriminants requires caution. Consider the following example:
5762 -- type R (D1, D2 : Positive) is [tagged] record
5763 -- S : String (D1 .. D2);
5766 -- type T1 is new R [with null record];
5767 -- type T2 (X : positive) is new R (1, X) [with null record];
5769 -- As explained in 6. above, T1 is rewritten as
5770 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
5771 -- which makes the treatment for T1 and T2 identical.
5773 -- What we want when inheriting S, is that references to D1 and D2 in R are
5774 -- replaced with references to their correct constraints, ie D1 and D2 in
5775 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
5776 -- with either discriminant references in the derived type or expressions.
5777 -- This replacement is achieved as follows: before inheriting R's
5778 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
5779 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
5780 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
5781 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
5782 -- by String (1 .. X).
5784 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
5786 -- We explain here the rules governing private type extensions relevant to
5787 -- type derivation. These rules are explained on the following example:
5789 -- type D [(...)] is new A [(...)] with private; <-- partial view
5790 -- type D [(...)] is new P [(...)] with null record; <-- full view
5792 -- Type A is called the ancestor subtype of the private extension.
5793 -- Type P is the parent type of the full view of the private extension. It
5794 -- must be A or a type derived from A.
5796 -- The rules concerning the discriminants of private type extensions are
5799 -- o If a private extension inherits known discriminants from the ancestor
5800 -- subtype, then the full view shall also inherit its discriminants from
5801 -- the ancestor subtype and the parent subtype of the full view shall be
5802 -- constrained if and only if the ancestor subtype is constrained.
5804 -- o If a partial view has unknown discriminants, then the full view may
5805 -- define a definite or an indefinite subtype, with or without
5808 -- o If a partial view has neither known nor unknown discriminants, then
5809 -- the full view shall define a definite subtype.
5811 -- o If the ancestor subtype of a private extension has constrained
5812 -- discriminants, then the parent subtype of the full view shall impose a
5813 -- statically matching constraint on those discriminants.
5815 -- This means that only the following forms of private extensions are
5818 -- type D is new A with private; <-- partial view
5819 -- type D is new P with null record; <-- full view
5821 -- If A has no discriminants than P has no discriminants, otherwise P must
5822 -- inherit A's discriminants.
5824 -- type D is new A (...) with private; <-- partial view
5825 -- type D is new P (:::) with null record; <-- full view
5827 -- P must inherit A's discriminants and (...) and (:::) must statically
5830 -- subtype A is R (...);
5831 -- type D is new A with private; <-- partial view
5832 -- type D is new P with null record; <-- full view
5834 -- P must have inherited R's discriminants and must be derived from A or
5835 -- any of its subtypes.
5837 -- type D (..) is new A with private; <-- partial view
5838 -- type D (..) is new P [(:::)] with null record; <-- full view
5840 -- No specific constraints on P's discriminants or constraint (:::).
5841 -- Note that A can be unconstrained, but the parent subtype P must either
5842 -- be constrained or (:::) must be present.
5844 -- type D (..) is new A [(...)] with private; <-- partial view
5845 -- type D (..) is new P [(:::)] with null record; <-- full view
5847 -- P's constraints on A's discriminants must statically match those
5848 -- imposed by (...).
5850 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
5852 -- The full view of a private extension is handled exactly as described
5853 -- above. The model chose for the private view of a private extension is
5854 -- the same for what concerns discriminants (ie they receive the same
5855 -- treatment as in the tagged case). However, the private view of the
5856 -- private extension always inherits the components of the parent base,
5857 -- without replacing any discriminant reference. Strictly speaking this is
5858 -- incorrect. However, Gigi never uses this view to generate code so this
5859 -- is a purely semantic issue. In theory, a set of transformations similar
5860 -- to those given in 5. and 6. above could be applied to private views of
5861 -- private extensions to have the same model of component inheritance as
5862 -- for non private extensions. However, this is not done because it would
5863 -- further complicate private type processing. Semantically speaking, this
5864 -- leaves us in an uncomfortable situation. As an example consider:
5867 -- type R (D : integer) is tagged record
5868 -- S : String (1 .. D);
5870 -- procedure P (X : R);
5871 -- type T is new R (1) with private;
5873 -- type T is new R (1) with null record;
5876 -- This is transformed into:
5879 -- type R (D : integer) is tagged record
5880 -- S : String (1 .. D);
5882 -- procedure P (X : R);
5883 -- type T is new R (1) with private;
5885 -- type BaseT is new R with null record;
5886 -- subtype T is BaseT (1);
5889 -- (strictly speaking the above is incorrect Ada)
5891 -- From the semantic standpoint the private view of private extension T
5892 -- should be flagged as constrained since one can clearly have
5896 -- in a unit withing Pack. However, when deriving subprograms for the
5897 -- private view of private extension T, T must be seen as unconstrained
5898 -- since T has discriminants (this is a constraint of the current
5899 -- subprogram derivation model). Thus, when processing the private view of
5900 -- a private extension such as T, we first mark T as unconstrained, we
5901 -- process it, we perform program derivation and just before returning from
5902 -- Build_Derived_Record_Type we mark T as constrained.
5904 -- ??? Are there are other uncomfortable cases that we will have to
5907 -- 10. RECORD_TYPE_WITH_PRIVATE complications
5909 -- Types that are derived from a visible record type and have a private
5910 -- extension present other peculiarities. They behave mostly like private
5911 -- types, but if they have primitive operations defined, these will not
5912 -- have the proper signatures for further inheritance, because other
5913 -- primitive operations will use the implicit base that we define for
5914 -- private derivations below. This affect subprogram inheritance (see
5915 -- Derive_Subprograms for details). We also derive the implicit base from
5916 -- the base type of the full view, so that the implicit base is a record
5917 -- type and not another private type, This avoids infinite loops.
5919 procedure Build_Derived_Record_Type
5921 Parent_Type
: Entity_Id
;
5922 Derived_Type
: Entity_Id
;
5923 Derive_Subps
: Boolean := True)
5925 Loc
: constant Source_Ptr
:= Sloc
(N
);
5926 Parent_Base
: Entity_Id
;
5929 Discrim
: Entity_Id
;
5930 Last_Discrim
: Entity_Id
;
5933 Discs
: Elist_Id
:= New_Elmt_List
;
5934 -- An empty Discs list means that there were no constraints in the
5935 -- subtype indication or that there was an error processing it.
5937 Assoc_List
: Elist_Id
;
5938 New_Discrs
: Elist_Id
;
5939 New_Base
: Entity_Id
;
5941 New_Indic
: Node_Id
;
5943 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Parent_Type
);
5944 Discriminant_Specs
: constant Boolean :=
5945 Present
(Discriminant_Specifications
(N
));
5946 Private_Extension
: constant Boolean :=
5947 (Nkind
(N
) = N_Private_Extension_Declaration
);
5949 Constraint_Present
: Boolean;
5950 Inherit_Discrims
: Boolean := False;
5951 Save_Etype
: Entity_Id
;
5952 Save_Discr_Constr
: Elist_Id
;
5953 Save_Next_Entity
: Entity_Id
;
5956 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
5957 and then Present
(Full_View
(Parent_Type
))
5958 and then Has_Discriminants
(Parent_Type
)
5960 Parent_Base
:= Base_Type
(Full_View
(Parent_Type
));
5962 Parent_Base
:= Base_Type
(Parent_Type
);
5965 -- Before we start the previously documented transformations, here is
5966 -- little fix for size and alignment of tagged types. Normally when we
5967 -- derive type D from type P, we copy the size and alignment of P as the
5968 -- default for D, and in the absence of explicit representation clauses
5969 -- for D, the size and alignment are indeed the same as the parent.
5971 -- But this is wrong for tagged types, since fields may be added, and
5972 -- the default size may need to be larger, and the default alignment may
5973 -- need to be larger.
5975 -- We therefore reset the size and alignment fields in the tagged case.
5976 -- Note that the size and alignment will in any case be at least as
5977 -- large as the parent type (since the derived type has a copy of the
5978 -- parent type in the _parent field)
5980 -- The type is also marked as being tagged here, which is needed when
5981 -- processing components with a self-referential anonymous access type
5982 -- in the call to Check_Anonymous_Access_Components below. Note that
5983 -- this flag is also set later on for completeness.
5986 Set_Is_Tagged_Type
(Derived_Type
);
5987 Init_Size_Align
(Derived_Type
);
5990 -- STEP 0a: figure out what kind of derived type declaration we have
5992 if Private_Extension
then
5994 Set_Ekind
(Derived_Type
, E_Record_Type_With_Private
);
5997 Type_Def
:= Type_Definition
(N
);
5999 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
6000 -- Parent_Base can be a private type or private extension. However,
6001 -- for tagged types with an extension the newly added fields are
6002 -- visible and hence the Derived_Type is always an E_Record_Type.
6003 -- (except that the parent may have its own private fields).
6004 -- For untagged types we preserve the Ekind of the Parent_Base.
6006 if Present
(Record_Extension_Part
(Type_Def
)) then
6007 Set_Ekind
(Derived_Type
, E_Record_Type
);
6009 -- Create internal access types for components with anonymous
6012 if Ada_Version
>= Ada_05
then
6013 Check_Anonymous_Access_Components
6014 (N
, Derived_Type
, Derived_Type
,
6015 Component_List
(Record_Extension_Part
(Type_Def
)));
6019 Set_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
6023 -- Indic can either be an N_Identifier if the subtype indication
6024 -- contains no constraint or an N_Subtype_Indication if the subtype
6025 -- indication has a constraint.
6027 Indic
:= Subtype_Indication
(Type_Def
);
6028 Constraint_Present
:= (Nkind
(Indic
) = N_Subtype_Indication
);
6030 -- Check that the type has visible discriminants. The type may be
6031 -- a private type with unknown discriminants whose full view has
6032 -- discriminants which are invisible.
6034 if Constraint_Present
then
6035 if not Has_Discriminants
(Parent_Base
)
6037 (Has_Unknown_Discriminants
(Parent_Base
)
6038 and then Is_Private_Type
(Parent_Base
))
6041 ("invalid constraint: type has no discriminant",
6042 Constraint
(Indic
));
6044 Constraint_Present
:= False;
6045 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
6047 elsif Is_Constrained
(Parent_Type
) then
6049 ("invalid constraint: parent type is already constrained",
6050 Constraint
(Indic
));
6052 Constraint_Present
:= False;
6053 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
6057 -- STEP 0b: If needed, apply transformation given in point 5. above
6059 if not Private_Extension
6060 and then Has_Discriminants
(Parent_Type
)
6061 and then not Discriminant_Specs
6062 and then (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
6064 -- First, we must analyze the constraint (see comment in point 5.)
6066 if Constraint_Present
then
6067 New_Discrs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
6069 if Has_Discriminants
(Derived_Type
)
6070 and then Has_Private_Declaration
(Derived_Type
)
6071 and then Present
(Discriminant_Constraint
(Derived_Type
))
6073 -- Verify that constraints of the full view conform to those
6074 -- given in partial view.
6080 C1
:= First_Elmt
(New_Discrs
);
6081 C2
:= First_Elmt
(Discriminant_Constraint
(Derived_Type
));
6082 while Present
(C1
) and then Present
(C2
) loop
6084 Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
6087 "constraint not conformant to previous declaration",
6098 -- Insert and analyze the declaration for the unconstrained base type
6100 New_Base
:= Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
6103 Make_Full_Type_Declaration
(Loc
,
6104 Defining_Identifier
=> New_Base
,
6106 Make_Derived_Type_Definition
(Loc
,
6107 Abstract_Present
=> Abstract_Present
(Type_Def
),
6108 Subtype_Indication
=>
6109 New_Occurrence_Of
(Parent_Base
, Loc
),
6110 Record_Extension_Part
=>
6111 Relocate_Node
(Record_Extension_Part
(Type_Def
))));
6113 Set_Parent
(New_Decl
, Parent
(N
));
6114 Mark_Rewrite_Insertion
(New_Decl
);
6115 Insert_Before
(N
, New_Decl
);
6117 -- Note that this call passes False for the Derive_Subps parameter
6118 -- because subprogram derivation is deferred until after creating
6119 -- the subtype (see below).
6122 (New_Decl
, Parent_Base
, New_Base
,
6123 Is_Completion
=> True, Derive_Subps
=> False);
6125 -- ??? This needs re-examination to determine whether the
6126 -- above call can simply be replaced by a call to Analyze.
6128 Set_Analyzed
(New_Decl
);
6130 -- Insert and analyze the declaration for the constrained subtype
6132 if Constraint_Present
then
6134 Make_Subtype_Indication
(Loc
,
6135 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
6136 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
6140 Constr_List
: constant List_Id
:= New_List
;
6145 C
:= First_Elmt
(Discriminant_Constraint
(Parent_Type
));
6146 while Present
(C
) loop
6149 -- It is safe here to call New_Copy_Tree since
6150 -- Force_Evaluation was called on each constraint in
6151 -- Build_Discriminant_Constraints.
6153 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
6159 Make_Subtype_Indication
(Loc
,
6160 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
6162 Make_Index_Or_Discriminant_Constraint
(Loc
, Constr_List
));
6167 Make_Subtype_Declaration
(Loc
,
6168 Defining_Identifier
=> Derived_Type
,
6169 Subtype_Indication
=> New_Indic
));
6173 -- Derivation of subprograms must be delayed until the full subtype
6174 -- has been established to ensure proper overriding of subprograms
6175 -- inherited by full types. If the derivations occurred as part of
6176 -- the call to Build_Derived_Type above, then the check for type
6177 -- conformance would fail because earlier primitive subprograms
6178 -- could still refer to the full type prior the change to the new
6179 -- subtype and hence would not match the new base type created here.
6181 Derive_Subprograms
(Parent_Type
, Derived_Type
);
6183 -- For tagged types the Discriminant_Constraint of the new base itype
6184 -- is inherited from the first subtype so that no subtype conformance
6185 -- problem arise when the first subtype overrides primitive
6186 -- operations inherited by the implicit base type.
6189 Set_Discriminant_Constraint
6190 (New_Base
, Discriminant_Constraint
(Derived_Type
));
6196 -- If we get here Derived_Type will have no discriminants or it will be
6197 -- a discriminated unconstrained base type.
6199 -- STEP 1a: perform preliminary actions/checks for derived tagged types
6203 -- The parent type is frozen for non-private extensions (RM 13.14(7))
6204 -- The declaration of a specific descendant of an interface type
6205 -- freezes the interface type (RM 13.14).
6207 if not Private_Extension
6208 or else Is_Interface
(Parent_Base
)
6210 Freeze_Before
(N
, Parent_Type
);
6213 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
6214 -- cannot be declared at a deeper level than its parent type is
6215 -- removed. The check on derivation within a generic body is also
6216 -- relaxed, but there's a restriction that a derived tagged type
6217 -- cannot be declared in a generic body if it's derived directly
6218 -- or indirectly from a formal type of that generic.
6220 if Ada_Version
>= Ada_05
then
6221 if Present
(Enclosing_Generic_Body
(Derived_Type
)) then
6223 Ancestor_Type
: Entity_Id
;
6226 -- Check to see if any ancestor of the derived type is a
6229 Ancestor_Type
:= Parent_Type
;
6230 while not Is_Generic_Type
(Ancestor_Type
)
6231 and then Etype
(Ancestor_Type
) /= Ancestor_Type
6233 Ancestor_Type
:= Etype
(Ancestor_Type
);
6236 -- If the derived type does have a formal type as an
6237 -- ancestor, then it's an error if the derived type is
6238 -- declared within the body of the generic unit that
6239 -- declares the formal type in its generic formal part. It's
6240 -- sufficient to check whether the ancestor type is declared
6241 -- inside the same generic body as the derived type (such as
6242 -- within a nested generic spec), in which case the
6243 -- derivation is legal. If the formal type is declared
6244 -- outside of that generic body, then it's guaranteed that
6245 -- the derived type is declared within the generic body of
6246 -- the generic unit declaring the formal type.
6248 if Is_Generic_Type
(Ancestor_Type
)
6249 and then Enclosing_Generic_Body
(Ancestor_Type
) /=
6250 Enclosing_Generic_Body
(Derived_Type
)
6253 ("parent type of& must not be descendant of formal type"
6254 & " of an enclosing generic body",
6255 Indic
, Derived_Type
);
6260 elsif Type_Access_Level
(Derived_Type
) /=
6261 Type_Access_Level
(Parent_Type
)
6262 and then not Is_Generic_Type
(Derived_Type
)
6264 if Is_Controlled
(Parent_Type
) then
6266 ("controlled type must be declared at the library level",
6270 ("type extension at deeper accessibility level than parent",
6276 GB
: constant Node_Id
:= Enclosing_Generic_Body
(Derived_Type
);
6280 and then GB
/= Enclosing_Generic_Body
(Parent_Base
)
6283 ("parent type of& must not be outside generic body"
6285 Indic
, Derived_Type
);
6291 -- Ada 2005 (AI-251)
6293 if Ada_Version
= Ada_05
6296 -- "The declaration of a specific descendant of an interface type
6297 -- freezes the interface type" (RM 13.14).
6302 if Is_Non_Empty_List
(Interface_List
(Type_Def
)) then
6303 Iface
:= First
(Interface_List
(Type_Def
));
6304 while Present
(Iface
) loop
6305 Freeze_Before
(N
, Etype
(Iface
));
6312 -- STEP 1b : preliminary cleanup of the full view of private types
6314 -- If the type is already marked as having discriminants, then it's the
6315 -- completion of a private type or private extension and we need to
6316 -- retain the discriminants from the partial view if the current
6317 -- declaration has Discriminant_Specifications so that we can verify
6318 -- conformance. However, we must remove any existing components that
6319 -- were inherited from the parent (and attached in Copy_And_Swap)
6320 -- because the full type inherits all appropriate components anyway, and
6321 -- we do not want the partial view's components interfering.
6323 if Has_Discriminants
(Derived_Type
) and then Discriminant_Specs
then
6324 Discrim
:= First_Discriminant
(Derived_Type
);
6326 Last_Discrim
:= Discrim
;
6327 Next_Discriminant
(Discrim
);
6328 exit when No
(Discrim
);
6331 Set_Last_Entity
(Derived_Type
, Last_Discrim
);
6333 -- In all other cases wipe out the list of inherited components (even
6334 -- inherited discriminants), it will be properly rebuilt here.
6337 Set_First_Entity
(Derived_Type
, Empty
);
6338 Set_Last_Entity
(Derived_Type
, Empty
);
6341 -- STEP 1c: Initialize some flags for the Derived_Type
6343 -- The following flags must be initialized here so that
6344 -- Process_Discriminants can check that discriminants of tagged types do
6345 -- not have a default initial value and that access discriminants are
6346 -- only specified for limited records. For completeness, these flags are
6347 -- also initialized along with all the other flags below.
6349 -- AI-419: Limitedness is not inherited from an interface parent, so to
6350 -- be limited in that case the type must be explicitly declared as
6351 -- limited. However, task and protected interfaces are always limited.
6353 if Limited_Present
(Type_Def
) then
6354 Set_Is_Limited_Record
(Derived_Type
);
6356 elsif Is_Limited_Record
(Parent_Type
) then
6357 if not Is_Interface
(Parent_Type
)
6358 or else Is_Synchronized_Interface
(Parent_Type
)
6359 or else Is_Protected_Interface
(Parent_Type
)
6360 or else Is_Task_Interface
(Parent_Type
)
6362 Set_Is_Limited_Record
(Derived_Type
);
6366 -- STEP 2a: process discriminants of derived type if any
6368 Push_Scope
(Derived_Type
);
6370 if Discriminant_Specs
then
6371 Set_Has_Unknown_Discriminants
(Derived_Type
, False);
6373 -- The following call initializes fields Has_Discriminants and
6374 -- Discriminant_Constraint, unless we are processing the completion
6375 -- of a private type declaration.
6377 Check_Or_Process_Discriminants
(N
, Derived_Type
);
6379 -- For non-tagged types the constraint on the Parent_Type must be
6380 -- present and is used to rename the discriminants.
6382 if not Is_Tagged
and then not Has_Discriminants
(Parent_Type
) then
6383 Error_Msg_N
("untagged parent must have discriminants", Indic
);
6385 elsif not Is_Tagged
and then not Constraint_Present
then
6387 ("discriminant constraint needed for derived untagged records",
6390 -- Otherwise the parent subtype must be constrained unless we have a
6391 -- private extension.
6393 elsif not Constraint_Present
6394 and then not Private_Extension
6395 and then not Is_Constrained
(Parent_Type
)
6398 ("unconstrained type not allowed in this context", Indic
);
6400 elsif Constraint_Present
then
6401 -- The following call sets the field Corresponding_Discriminant
6402 -- for the discriminants in the Derived_Type.
6404 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
, True);
6406 -- For untagged types all new discriminants must rename
6407 -- discriminants in the parent. For private extensions new
6408 -- discriminants cannot rename old ones (implied by [7.3(13)]).
6410 Discrim
:= First_Discriminant
(Derived_Type
);
6411 while Present
(Discrim
) loop
6413 and then No
(Corresponding_Discriminant
(Discrim
))
6416 ("new discriminants must constrain old ones", Discrim
);
6418 elsif Private_Extension
6419 and then Present
(Corresponding_Discriminant
(Discrim
))
6422 ("only static constraints allowed for parent"
6423 & " discriminants in the partial view", Indic
);
6427 -- If a new discriminant is used in the constraint, then its
6428 -- subtype must be statically compatible with the parent
6429 -- discriminant's subtype (3.7(15)).
6431 if Present
(Corresponding_Discriminant
(Discrim
))
6433 not Subtypes_Statically_Compatible
6435 Etype
(Corresponding_Discriminant
(Discrim
)))
6438 ("subtype must be compatible with parent discriminant",
6442 Next_Discriminant
(Discrim
);
6445 -- Check whether the constraints of the full view statically
6446 -- match those imposed by the parent subtype [7.3(13)].
6448 if Present
(Stored_Constraint
(Derived_Type
)) then
6453 C1
:= First_Elmt
(Discs
);
6454 C2
:= First_Elmt
(Stored_Constraint
(Derived_Type
));
6455 while Present
(C1
) and then Present
(C2
) loop
6457 Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
6460 ("not conformant with previous declaration",
6471 -- STEP 2b: No new discriminants, inherit discriminants if any
6474 if Private_Extension
then
6475 Set_Has_Unknown_Discriminants
6477 Has_Unknown_Discriminants
(Parent_Type
)
6478 or else Unknown_Discriminants_Present
(N
));
6480 -- The partial view of the parent may have unknown discriminants,
6481 -- but if the full view has discriminants and the parent type is
6482 -- in scope they must be inherited.
6484 elsif Has_Unknown_Discriminants
(Parent_Type
)
6486 (not Has_Discriminants
(Parent_Type
)
6487 or else not In_Open_Scopes
(Scope
(Parent_Type
)))
6489 Set_Has_Unknown_Discriminants
(Derived_Type
);
6492 if not Has_Unknown_Discriminants
(Derived_Type
)
6493 and then not Has_Unknown_Discriminants
(Parent_Base
)
6494 and then Has_Discriminants
(Parent_Type
)
6496 Inherit_Discrims
:= True;
6497 Set_Has_Discriminants
6498 (Derived_Type
, True);
6499 Set_Discriminant_Constraint
6500 (Derived_Type
, Discriminant_Constraint
(Parent_Base
));
6503 -- The following test is true for private types (remember
6504 -- transformation 5. is not applied to those) and in an error
6507 if Constraint_Present
then
6508 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
6511 -- For now mark a new derived type as constrained only if it has no
6512 -- discriminants. At the end of Build_Derived_Record_Type we properly
6513 -- set this flag in the case of private extensions. See comments in
6514 -- point 9. just before body of Build_Derived_Record_Type.
6518 not (Inherit_Discrims
6519 or else Has_Unknown_Discriminants
(Derived_Type
)));
6522 -- STEP 3: initialize fields of derived type
6524 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged
);
6525 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
6527 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
6528 -- but cannot be interfaces
6530 if not Private_Extension
6531 and then Ekind
(Derived_Type
) /= E_Private_Type
6532 and then Ekind
(Derived_Type
) /= E_Limited_Private_Type
6534 if Interface_Present
(Type_Def
) then
6535 Analyze_Interface_Declaration
(Derived_Type
, Type_Def
);
6538 Set_Abstract_Interfaces
(Derived_Type
, No_Elist
);
6541 -- Fields inherited from the Parent_Type
6544 (Derived_Type
, Einfo
.Discard_Names
(Parent_Type
));
6545 Set_Has_Specified_Layout
6546 (Derived_Type
, Has_Specified_Layout
(Parent_Type
));
6547 Set_Is_Limited_Composite
6548 (Derived_Type
, Is_Limited_Composite
(Parent_Type
));
6549 Set_Is_Private_Composite
6550 (Derived_Type
, Is_Private_Composite
(Parent_Type
));
6552 -- Fields inherited from the Parent_Base
6554 Set_Has_Controlled_Component
6555 (Derived_Type
, Has_Controlled_Component
(Parent_Base
));
6556 Set_Has_Non_Standard_Rep
6557 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
6558 Set_Has_Primitive_Operations
6559 (Derived_Type
, Has_Primitive_Operations
(Parent_Base
));
6561 -- For non-private case, we also inherit Has_Complex_Representation
6563 if Ekind
(Derived_Type
) = E_Record_Type
then
6564 Set_Has_Complex_Representation
6565 (Derived_Type
, Has_Complex_Representation
(Parent_Base
));
6568 -- Direct controlled types do not inherit Finalize_Storage_Only flag
6570 if not Is_Controlled
(Parent_Type
) then
6571 Set_Finalize_Storage_Only
6572 (Derived_Type
, Finalize_Storage_Only
(Parent_Type
));
6575 -- Set fields for private derived types
6577 if Is_Private_Type
(Derived_Type
) then
6578 Set_Depends_On_Private
(Derived_Type
, True);
6579 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
6581 -- Inherit fields from non private record types. If this is the
6582 -- completion of a derivation from a private type, the parent itself
6583 -- is private, and the attributes come from its full view, which must
6587 if Is_Private_Type
(Parent_Base
)
6588 and then not Is_Record_Type
(Parent_Base
)
6590 Set_Component_Alignment
6591 (Derived_Type
, Component_Alignment
(Full_View
(Parent_Base
)));
6593 (Derived_Type
, C_Pass_By_Copy
(Full_View
(Parent_Base
)));
6595 Set_Component_Alignment
6596 (Derived_Type
, Component_Alignment
(Parent_Base
));
6599 (Derived_Type
, C_Pass_By_Copy
(Parent_Base
));
6603 -- Set fields for tagged types
6606 Set_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
6608 -- All tagged types defined in Ada.Finalization are controlled
6610 if Chars
(Scope
(Derived_Type
)) = Name_Finalization
6611 and then Chars
(Scope
(Scope
(Derived_Type
))) = Name_Ada
6612 and then Scope
(Scope
(Scope
(Derived_Type
))) = Standard_Standard
6614 Set_Is_Controlled
(Derived_Type
);
6616 Set_Is_Controlled
(Derived_Type
, Is_Controlled
(Parent_Base
));
6619 Make_Class_Wide_Type
(Derived_Type
);
6620 Set_Is_Abstract_Type
(Derived_Type
, Abstract_Present
(Type_Def
));
6622 if Has_Discriminants
(Derived_Type
)
6623 and then Constraint_Present
6625 Set_Stored_Constraint
6626 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Base
, Discs
));
6629 if Ada_Version
>= Ada_05
then
6631 Ifaces_List
: Elist_Id
;
6634 -- Checks rules 3.9.4 (13/2 and 14/2)
6636 if Comes_From_Source
(Derived_Type
)
6637 and then not Is_Private_Type
(Derived_Type
)
6638 and then Is_Interface
(Parent_Type
)
6639 and then not Is_Interface
(Derived_Type
)
6641 if Is_Task_Interface
(Parent_Type
) then
6643 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
6646 elsif Is_Protected_Interface
(Parent_Type
) then
6648 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
6653 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
6655 Check_Abstract_Interfaces
(N
, Type_Def
);
6657 -- Ada 2005 (AI-251): Collect the list of progenitors that are
6658 -- not already in the parents.
6660 Collect_Abstract_Interfaces
6662 Ifaces_List
=> Ifaces_List
,
6663 Exclude_Parent_Interfaces
=> True);
6664 Set_Abstract_Interfaces
(Derived_Type
, Ifaces_List
);
6669 Set_Is_Packed
(Derived_Type
, Is_Packed
(Parent_Base
));
6670 Set_Has_Non_Standard_Rep
6671 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
6674 -- STEP 4: Inherit components from the parent base and constrain them.
6675 -- Apply the second transformation described in point 6. above.
6677 if (not Is_Empty_Elmt_List
(Discs
) or else Inherit_Discrims
)
6678 or else not Has_Discriminants
(Parent_Type
)
6679 or else not Is_Constrained
(Parent_Type
)
6683 Constrs
:= Discriminant_Constraint
(Parent_Type
);
6688 (N
, Parent_Base
, Derived_Type
, Is_Tagged
, Inherit_Discrims
, Constrs
);
6690 -- STEP 5a: Copy the parent record declaration for untagged types
6692 if not Is_Tagged
then
6694 -- Discriminant_Constraint (Derived_Type) has been properly
6695 -- constructed. Save it and temporarily set it to Empty because we
6696 -- do not want the call to New_Copy_Tree below to mess this list.
6698 if Has_Discriminants
(Derived_Type
) then
6699 Save_Discr_Constr
:= Discriminant_Constraint
(Derived_Type
);
6700 Set_Discriminant_Constraint
(Derived_Type
, No_Elist
);
6702 Save_Discr_Constr
:= No_Elist
;
6705 -- Save the Etype field of Derived_Type. It is correctly set now,
6706 -- but the call to New_Copy tree may remap it to point to itself,
6707 -- which is not what we want. Ditto for the Next_Entity field.
6709 Save_Etype
:= Etype
(Derived_Type
);
6710 Save_Next_Entity
:= Next_Entity
(Derived_Type
);
6712 -- Assoc_List maps all stored discriminants in the Parent_Base to
6713 -- stored discriminants in the Derived_Type. It is fundamental that
6714 -- no types or itypes with discriminants other than the stored
6715 -- discriminants appear in the entities declared inside
6716 -- Derived_Type, since the back end cannot deal with it.
6720 (Parent
(Parent_Base
), Map
=> Assoc_List
, New_Sloc
=> Loc
);
6722 -- Restore the fields saved prior to the New_Copy_Tree call
6723 -- and compute the stored constraint.
6725 Set_Etype
(Derived_Type
, Save_Etype
);
6726 Set_Next_Entity
(Derived_Type
, Save_Next_Entity
);
6728 if Has_Discriminants
(Derived_Type
) then
6729 Set_Discriminant_Constraint
6730 (Derived_Type
, Save_Discr_Constr
);
6731 Set_Stored_Constraint
6732 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Type
, Discs
));
6733 Replace_Components
(Derived_Type
, New_Decl
);
6736 -- Insert the new derived type declaration
6738 Rewrite
(N
, New_Decl
);
6740 -- STEP 5b: Complete the processing for record extensions in generics
6742 -- There is no completion for record extensions declared in the
6743 -- parameter part of a generic, so we need to complete processing for
6744 -- these generic record extensions here. The Record_Type_Definition call
6745 -- will change the Ekind of the components from E_Void to E_Component.
6747 elsif Private_Extension
and then Is_Generic_Type
(Derived_Type
) then
6748 Record_Type_Definition
(Empty
, Derived_Type
);
6750 -- STEP 5c: Process the record extension for non private tagged types
6752 elsif not Private_Extension
then
6754 -- Add the _parent field in the derived type
6756 Expand_Record_Extension
(Derived_Type
, Type_Def
);
6758 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
6759 -- implemented interfaces if we are in expansion mode
6762 and then Has_Abstract_Interfaces
(Derived_Type
)
6764 Add_Interface_Tag_Components
(N
, Derived_Type
);
6767 -- Analyze the record extension
6769 Record_Type_Definition
6770 (Record_Extension_Part
(Type_Def
), Derived_Type
);
6775 -- Nothing else to do if there is an error in the derivation.
6776 -- An unusual case: the full view may be derived from a type in an
6777 -- instance, when the partial view was used illegally as an actual
6778 -- in that instance, leading to a circular definition.
6780 if Etype
(Derived_Type
) = Any_Type
6781 or else Etype
(Parent_Type
) = Derived_Type
6786 -- Set delayed freeze and then derive subprograms, we need to do
6787 -- this in this order so that derived subprograms inherit the
6788 -- derived freeze if necessary.
6790 Set_Has_Delayed_Freeze
(Derived_Type
);
6792 if Derive_Subps
then
6793 Derive_Subprograms
(Parent_Type
, Derived_Type
);
6796 -- If we have a private extension which defines a constrained derived
6797 -- type mark as constrained here after we have derived subprograms. See
6798 -- comment on point 9. just above the body of Build_Derived_Record_Type.
6800 if Private_Extension
and then Inherit_Discrims
then
6801 if Constraint_Present
and then not Is_Empty_Elmt_List
(Discs
) then
6802 Set_Is_Constrained
(Derived_Type
, True);
6803 Set_Discriminant_Constraint
(Derived_Type
, Discs
);
6805 elsif Is_Constrained
(Parent_Type
) then
6807 (Derived_Type
, True);
6808 Set_Discriminant_Constraint
6809 (Derived_Type
, Discriminant_Constraint
(Parent_Type
));
6813 -- Update the class_wide type, which shares the now-completed
6814 -- entity list with its specific type.
6818 (Class_Wide_Type
(Derived_Type
), First_Entity
(Derived_Type
));
6820 (Class_Wide_Type
(Derived_Type
), Last_Entity
(Derived_Type
));
6823 -- Update the scope of anonymous access types of discriminants and other
6824 -- components, to prevent scope anomalies in gigi, when the derivation
6825 -- appears in a scope nested within that of the parent.
6831 D
:= First_Entity
(Derived_Type
);
6832 while Present
(D
) loop
6833 if Ekind
(D
) = E_Discriminant
6834 or else Ekind
(D
) = E_Component
6836 if Is_Itype
(Etype
(D
))
6837 and then Ekind
(Etype
(D
)) = E_Anonymous_Access_Type
6839 Set_Scope
(Etype
(D
), Current_Scope
);
6846 end Build_Derived_Record_Type
;
6848 ------------------------
6849 -- Build_Derived_Type --
6850 ------------------------
6852 procedure Build_Derived_Type
6854 Parent_Type
: Entity_Id
;
6855 Derived_Type
: Entity_Id
;
6856 Is_Completion
: Boolean;
6857 Derive_Subps
: Boolean := True)
6859 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
6862 -- Set common attributes
6864 Set_Scope
(Derived_Type
, Current_Scope
);
6866 Set_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
6867 Set_Etype
(Derived_Type
, Parent_Base
);
6868 Set_Has_Task
(Derived_Type
, Has_Task
(Parent_Base
));
6870 Set_Size_Info
(Derived_Type
, Parent_Type
);
6871 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
6872 Set_Convention
(Derived_Type
, Convention
(Parent_Type
));
6873 Set_Is_Controlled
(Derived_Type
, Is_Controlled
(Parent_Type
));
6875 -- The derived type inherits the representation clauses of the parent.
6876 -- However, for a private type that is completed by a derivation, there
6877 -- may be operation attributes that have been specified already (stream
6878 -- attributes and External_Tag) and those must be provided. Finally,
6879 -- if the partial view is a private extension, the representation items
6880 -- of the parent have been inherited already, and should not be chained
6881 -- twice to the derived type.
6883 if Is_Tagged_Type
(Parent_Type
)
6884 and then Present
(First_Rep_Item
(Derived_Type
))
6886 -- The existing items are either operational items or items inherited
6887 -- from a private extension declaration.
6891 -- Used to iterate over representation items of the derived type
6894 -- Last representation item of the (non-empty) representation
6895 -- item list of the derived type.
6897 Found
: Boolean := False;
6900 Rep
:= First_Rep_Item
(Derived_Type
);
6902 while Present
(Rep
) loop
6903 if Rep
= First_Rep_Item
(Parent_Type
) then
6908 Rep
:= Next_Rep_Item
(Rep
);
6910 if Present
(Rep
) then
6916 -- Here if we either encountered the parent type's first rep
6917 -- item on the derived type's rep item list (in which case
6918 -- Found is True, and we have nothing else to do), or if we
6919 -- reached the last rep item of the derived type, which is
6920 -- Last_Rep, in which case we further chain the parent type's
6921 -- rep items to those of the derived type.
6924 Set_Next_Rep_Item
(Last_Rep
, First_Rep_Item
(Parent_Type
));
6929 Set_First_Rep_Item
(Derived_Type
, First_Rep_Item
(Parent_Type
));
6932 case Ekind
(Parent_Type
) is
6933 when Numeric_Kind
=>
6934 Build_Derived_Numeric_Type
(N
, Parent_Type
, Derived_Type
);
6937 Build_Derived_Array_Type
(N
, Parent_Type
, Derived_Type
);
6941 | Class_Wide_Kind
=>
6942 Build_Derived_Record_Type
6943 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
6946 when Enumeration_Kind
=>
6947 Build_Derived_Enumeration_Type
(N
, Parent_Type
, Derived_Type
);
6950 Build_Derived_Access_Type
(N
, Parent_Type
, Derived_Type
);
6952 when Incomplete_Or_Private_Kind
=>
6953 Build_Derived_Private_Type
6954 (N
, Parent_Type
, Derived_Type
, Is_Completion
, Derive_Subps
);
6956 -- For discriminated types, the derivation includes deriving
6957 -- primitive operations. For others it is done below.
6959 if Is_Tagged_Type
(Parent_Type
)
6960 or else Has_Discriminants
(Parent_Type
)
6961 or else (Present
(Full_View
(Parent_Type
))
6962 and then Has_Discriminants
(Full_View
(Parent_Type
)))
6967 when Concurrent_Kind
=>
6968 Build_Derived_Concurrent_Type
(N
, Parent_Type
, Derived_Type
);
6971 raise Program_Error
;
6974 if Etype
(Derived_Type
) = Any_Type
then
6978 -- Set delayed freeze and then derive subprograms, we need to do this
6979 -- in this order so that derived subprograms inherit the derived freeze
6982 Set_Has_Delayed_Freeze
(Derived_Type
);
6983 if Derive_Subps
then
6984 Derive_Subprograms
(Parent_Type
, Derived_Type
);
6987 Set_Has_Primitive_Operations
6988 (Base_Type
(Derived_Type
), Has_Primitive_Operations
(Parent_Type
));
6989 end Build_Derived_Type
;
6991 -----------------------
6992 -- Build_Discriminal --
6993 -----------------------
6995 procedure Build_Discriminal
(Discrim
: Entity_Id
) is
6996 D_Minal
: Entity_Id
;
6997 CR_Disc
: Entity_Id
;
7000 -- A discriminal has the same name as the discriminant
7003 Make_Defining_Identifier
(Sloc
(Discrim
),
7004 Chars
=> Chars
(Discrim
));
7006 Set_Ekind
(D_Minal
, E_In_Parameter
);
7007 Set_Mechanism
(D_Minal
, Default_Mechanism
);
7008 Set_Etype
(D_Minal
, Etype
(Discrim
));
7010 Set_Discriminal
(Discrim
, D_Minal
);
7011 Set_Discriminal_Link
(D_Minal
, Discrim
);
7013 -- For task types, build at once the discriminants of the corresponding
7014 -- record, which are needed if discriminants are used in entry defaults
7015 -- and in family bounds.
7017 if Is_Concurrent_Type
(Current_Scope
)
7018 or else Is_Limited_Type
(Current_Scope
)
7020 CR_Disc
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
7022 Set_Ekind
(CR_Disc
, E_In_Parameter
);
7023 Set_Mechanism
(CR_Disc
, Default_Mechanism
);
7024 Set_Etype
(CR_Disc
, Etype
(Discrim
));
7025 Set_Discriminal_Link
(CR_Disc
, Discrim
);
7026 Set_CR_Discriminant
(Discrim
, CR_Disc
);
7028 end Build_Discriminal
;
7030 ------------------------------------
7031 -- Build_Discriminant_Constraints --
7032 ------------------------------------
7034 function Build_Discriminant_Constraints
7037 Derived_Def
: Boolean := False) return Elist_Id
7039 C
: constant Node_Id
:= Constraint
(Def
);
7040 Nb_Discr
: constant Nat
:= Number_Discriminants
(T
);
7042 Discr_Expr
: array (1 .. Nb_Discr
) of Node_Id
:= (others => Empty
);
7043 -- Saves the expression corresponding to a given discriminant in T
7045 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
;
7046 -- Return the Position number within array Discr_Expr of a discriminant
7047 -- D within the discriminant list of the discriminated type T.
7053 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
is
7057 Disc
:= First_Discriminant
(T
);
7058 for J
in Discr_Expr
'Range loop
7063 Next_Discriminant
(Disc
);
7066 -- Note: Since this function is called on discriminants that are
7067 -- known to belong to the discriminated type, falling through the
7068 -- loop with no match signals an internal compiler error.
7070 raise Program_Error
;
7073 -- Declarations local to Build_Discriminant_Constraints
7077 Elist
: constant Elist_Id
:= New_Elmt_List
;
7085 Discrim_Present
: Boolean := False;
7087 -- Start of processing for Build_Discriminant_Constraints
7090 -- The following loop will process positional associations only.
7091 -- For a positional association, the (single) discriminant is
7092 -- implicitly specified by position, in textual order (RM 3.7.2).
7094 Discr
:= First_Discriminant
(T
);
7095 Constr
:= First
(Constraints
(C
));
7096 for D
in Discr_Expr
'Range loop
7097 exit when Nkind
(Constr
) = N_Discriminant_Association
;
7100 Error_Msg_N
("too few discriminants given in constraint", C
);
7101 return New_Elmt_List
;
7103 elsif Nkind
(Constr
) = N_Range
7104 or else (Nkind
(Constr
) = N_Attribute_Reference
7106 Attribute_Name
(Constr
) = Name_Range
)
7109 ("a range is not a valid discriminant constraint", Constr
);
7110 Discr_Expr
(D
) := Error
;
7113 Analyze_And_Resolve
(Constr
, Base_Type
(Etype
(Discr
)));
7114 Discr_Expr
(D
) := Constr
;
7117 Next_Discriminant
(Discr
);
7121 if No
(Discr
) and then Present
(Constr
) then
7122 Error_Msg_N
("too many discriminants given in constraint", Constr
);
7123 return New_Elmt_List
;
7126 -- Named associations can be given in any order, but if both positional
7127 -- and named associations are used in the same discriminant constraint,
7128 -- then positional associations must occur first, at their normal
7129 -- position. Hence once a named association is used, the rest of the
7130 -- discriminant constraint must use only named associations.
7132 while Present
(Constr
) loop
7134 -- Positional association forbidden after a named association
7136 if Nkind
(Constr
) /= N_Discriminant_Association
then
7137 Error_Msg_N
("positional association follows named one", Constr
);
7138 return New_Elmt_List
;
7140 -- Otherwise it is a named association
7143 -- E records the type of the discriminants in the named
7144 -- association. All the discriminants specified in the same name
7145 -- association must have the same type.
7149 -- Search the list of discriminants in T to see if the simple name
7150 -- given in the constraint matches any of them.
7152 Id
:= First
(Selector_Names
(Constr
));
7153 while Present
(Id
) loop
7156 -- If Original_Discriminant is present, we are processing a
7157 -- generic instantiation and this is an instance node. We need
7158 -- to find the name of the corresponding discriminant in the
7159 -- actual record type T and not the name of the discriminant in
7160 -- the generic formal. Example:
7163 -- type G (D : int) is private;
7165 -- subtype W is G (D => 1);
7167 -- type Rec (X : int) is record ... end record;
7168 -- package Q is new P (G => Rec);
7170 -- At the point of the instantiation, formal type G is Rec
7171 -- and therefore when reanalyzing "subtype W is G (D => 1);"
7172 -- which really looks like "subtype W is Rec (D => 1);" at
7173 -- the point of instantiation, we want to find the discriminant
7174 -- that corresponds to D in Rec, ie X.
7176 if Present
(Original_Discriminant
(Id
)) then
7177 Discr
:= Find_Corresponding_Discriminant
(Id
, T
);
7181 Discr
:= First_Discriminant
(T
);
7182 while Present
(Discr
) loop
7183 if Chars
(Discr
) = Chars
(Id
) then
7188 Next_Discriminant
(Discr
);
7192 Error_Msg_N
("& does not match any discriminant", Id
);
7193 return New_Elmt_List
;
7195 -- The following is only useful for the benefit of generic
7196 -- instances but it does not interfere with other
7197 -- processing for the non-generic case so we do it in all
7198 -- cases (for generics this statement is executed when
7199 -- processing the generic definition, see comment at the
7200 -- beginning of this if statement).
7203 Set_Original_Discriminant
(Id
, Discr
);
7207 Position
:= Pos_Of_Discr
(T
, Discr
);
7209 if Present
(Discr_Expr
(Position
)) then
7210 Error_Msg_N
("duplicate constraint for discriminant&", Id
);
7213 -- Each discriminant specified in the same named association
7214 -- must be associated with a separate copy of the
7215 -- corresponding expression.
7217 if Present
(Next
(Id
)) then
7218 Expr
:= New_Copy_Tree
(Expression
(Constr
));
7219 Set_Parent
(Expr
, Parent
(Expression
(Constr
)));
7221 Expr
:= Expression
(Constr
);
7224 Discr_Expr
(Position
) := Expr
;
7225 Analyze_And_Resolve
(Expr
, Base_Type
(Etype
(Discr
)));
7228 -- A discriminant association with more than one discriminant
7229 -- name is only allowed if the named discriminants are all of
7230 -- the same type (RM 3.7.1(8)).
7233 E
:= Base_Type
(Etype
(Discr
));
7235 elsif Base_Type
(Etype
(Discr
)) /= E
then
7237 ("all discriminants in an association " &
7238 "must have the same type", Id
);
7248 -- A discriminant constraint must provide exactly one value for each
7249 -- discriminant of the type (RM 3.7.1(8)).
7251 for J
in Discr_Expr
'Range loop
7252 if No
(Discr_Expr
(J
)) then
7253 Error_Msg_N
("too few discriminants given in constraint", C
);
7254 return New_Elmt_List
;
7258 -- Determine if there are discriminant expressions in the constraint
7260 for J
in Discr_Expr
'Range loop
7261 if Denotes_Discriminant
7262 (Discr_Expr
(J
), Check_Concurrent
=> True)
7264 Discrim_Present
:= True;
7268 -- Build an element list consisting of the expressions given in the
7269 -- discriminant constraint and apply the appropriate checks. The list
7270 -- is constructed after resolving any named discriminant associations
7271 -- and therefore the expressions appear in the textual order of the
7274 Discr
:= First_Discriminant
(T
);
7275 for J
in Discr_Expr
'Range loop
7276 if Discr_Expr
(J
) /= Error
then
7277 Append_Elmt
(Discr_Expr
(J
), Elist
);
7279 -- If any of the discriminant constraints is given by a
7280 -- discriminant and we are in a derived type declaration we
7281 -- have a discriminant renaming. Establish link between new
7282 -- and old discriminant.
7284 if Denotes_Discriminant
(Discr_Expr
(J
)) then
7286 Set_Corresponding_Discriminant
7287 (Entity
(Discr_Expr
(J
)), Discr
);
7290 -- Force the evaluation of non-discriminant expressions.
7291 -- If we have found a discriminant in the constraint 3.4(26)
7292 -- and 3.8(18) demand that no range checks are performed are
7293 -- after evaluation. If the constraint is for a component
7294 -- definition that has a per-object constraint, expressions are
7295 -- evaluated but not checked either. In all other cases perform
7299 if Discrim_Present
then
7302 elsif Nkind
(Parent
(Parent
(Def
))) = N_Component_Declaration
7304 Has_Per_Object_Constraint
7305 (Defining_Identifier
(Parent
(Parent
(Def
))))
7309 elsif Is_Access_Type
(Etype
(Discr
)) then
7310 Apply_Constraint_Check
(Discr_Expr
(J
), Etype
(Discr
));
7313 Apply_Range_Check
(Discr_Expr
(J
), Etype
(Discr
));
7316 Force_Evaluation
(Discr_Expr
(J
));
7319 -- Check that the designated type of an access discriminant's
7320 -- expression is not a class-wide type unless the discriminant's
7321 -- designated type is also class-wide.
7323 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
7324 and then not Is_Class_Wide_Type
7325 (Designated_Type
(Etype
(Discr
)))
7326 and then Etype
(Discr_Expr
(J
)) /= Any_Type
7327 and then Is_Class_Wide_Type
7328 (Designated_Type
(Etype
(Discr_Expr
(J
))))
7330 Wrong_Type
(Discr_Expr
(J
), Etype
(Discr
));
7334 Next_Discriminant
(Discr
);
7338 end Build_Discriminant_Constraints
;
7340 ---------------------------------
7341 -- Build_Discriminated_Subtype --
7342 ---------------------------------
7344 procedure Build_Discriminated_Subtype
7348 Related_Nod
: Node_Id
;
7349 For_Access
: Boolean := False)
7351 Has_Discrs
: constant Boolean := Has_Discriminants
(T
);
7352 Constrained
: constant Boolean :=
7354 and then not Is_Empty_Elmt_List
(Elist
)
7355 and then not Is_Class_Wide_Type
(T
))
7356 or else Is_Constrained
(T
);
7359 if Ekind
(T
) = E_Record_Type
then
7361 Set_Ekind
(Def_Id
, E_Private_Subtype
);
7362 Set_Is_For_Access_Subtype
(Def_Id
, True);
7364 Set_Ekind
(Def_Id
, E_Record_Subtype
);
7367 elsif Ekind
(T
) = E_Task_Type
then
7368 Set_Ekind
(Def_Id
, E_Task_Subtype
);
7370 elsif Ekind
(T
) = E_Protected_Type
then
7371 Set_Ekind
(Def_Id
, E_Protected_Subtype
);
7373 elsif Is_Private_Type
(T
) then
7374 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
7376 elsif Is_Class_Wide_Type
(T
) then
7377 Set_Ekind
(Def_Id
, E_Class_Wide_Subtype
);
7380 -- Incomplete type. Attach subtype to list of dependents, to be
7381 -- completed with full view of parent type, unless is it the
7382 -- designated subtype of a record component within an init_proc.
7383 -- This last case arises for a component of an access type whose
7384 -- designated type is incomplete (e.g. a Taft Amendment type).
7385 -- The designated subtype is within an inner scope, and needs no
7386 -- elaboration, because only the access type is needed in the
7387 -- initialization procedure.
7389 Set_Ekind
(Def_Id
, Ekind
(T
));
7391 if For_Access
and then Within_Init_Proc
then
7394 Append_Elmt
(Def_Id
, Private_Dependents
(T
));
7398 Set_Etype
(Def_Id
, T
);
7399 Init_Size_Align
(Def_Id
);
7400 Set_Has_Discriminants
(Def_Id
, Has_Discrs
);
7401 Set_Is_Constrained
(Def_Id
, Constrained
);
7403 Set_First_Entity
(Def_Id
, First_Entity
(T
));
7404 Set_Last_Entity
(Def_Id
, Last_Entity
(T
));
7405 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
7407 if Is_Tagged_Type
(T
) then
7408 Set_Is_Tagged_Type
(Def_Id
);
7409 Make_Class_Wide_Type
(Def_Id
);
7412 Set_Stored_Constraint
(Def_Id
, No_Elist
);
7415 Set_Discriminant_Constraint
(Def_Id
, Elist
);
7416 Set_Stored_Constraint_From_Discriminant_Constraint
(Def_Id
);
7419 if Is_Tagged_Type
(T
) then
7421 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
7422 -- concurrent record type (which has the list of primitive
7425 if Ada_Version
>= Ada_05
7426 and then Is_Concurrent_Type
(T
)
7428 Set_Corresponding_Record_Type
(Def_Id
,
7429 Corresponding_Record_Type
(T
));
7431 Set_Primitive_Operations
(Def_Id
, Primitive_Operations
(T
));
7434 Set_Is_Abstract_Type
(Def_Id
, Is_Abstract_Type
(T
));
7437 -- Subtypes introduced by component declarations do not need to be
7438 -- marked as delayed, and do not get freeze nodes, because the semantics
7439 -- verifies that the parents of the subtypes are frozen before the
7440 -- enclosing record is frozen.
7442 if not Is_Type
(Scope
(Def_Id
)) then
7443 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
7445 if Is_Private_Type
(T
)
7446 and then Present
(Full_View
(T
))
7448 Conditional_Delay
(Def_Id
, Full_View
(T
));
7450 Conditional_Delay
(Def_Id
, T
);
7454 if Is_Record_Type
(T
) then
7455 Set_Is_Limited_Record
(Def_Id
, Is_Limited_Record
(T
));
7458 and then not Is_Empty_Elmt_List
(Elist
)
7459 and then not For_Access
7461 Create_Constrained_Components
(Def_Id
, Related_Nod
, T
, Elist
);
7462 elsif not For_Access
then
7463 Set_Cloned_Subtype
(Def_Id
, T
);
7466 end Build_Discriminated_Subtype
;
7468 ---------------------------
7469 -- Build_Itype_Reference --
7470 ---------------------------
7472 procedure Build_Itype_Reference
7476 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(Nod
));
7478 Set_Itype
(IR
, Ityp
);
7479 Insert_After
(Nod
, IR
);
7480 end Build_Itype_Reference
;
7482 ------------------------
7483 -- Build_Scalar_Bound --
7484 ------------------------
7486 function Build_Scalar_Bound
7489 Der_T
: Entity_Id
) return Node_Id
7491 New_Bound
: Entity_Id
;
7494 -- Note: not clear why this is needed, how can the original bound
7495 -- be unanalyzed at this point? and if it is, what business do we
7496 -- have messing around with it? and why is the base type of the
7497 -- parent type the right type for the resolution. It probably is
7498 -- not! It is OK for the new bound we are creating, but not for
7499 -- the old one??? Still if it never happens, no problem!
7501 Analyze_And_Resolve
(Bound
, Base_Type
(Par_T
));
7503 if Nkind
(Bound
) = N_Integer_Literal
7504 or else Nkind
(Bound
) = N_Real_Literal
7506 New_Bound
:= New_Copy
(Bound
);
7507 Set_Etype
(New_Bound
, Der_T
);
7508 Set_Analyzed
(New_Bound
);
7510 elsif Is_Entity_Name
(Bound
) then
7511 New_Bound
:= OK_Convert_To
(Der_T
, New_Copy
(Bound
));
7513 -- The following is almost certainly wrong. What business do we have
7514 -- relocating a node (Bound) that is presumably still attached to
7515 -- the tree elsewhere???
7518 New_Bound
:= OK_Convert_To
(Der_T
, Relocate_Node
(Bound
));
7521 Set_Etype
(New_Bound
, Der_T
);
7523 end Build_Scalar_Bound
;
7525 --------------------------------
7526 -- Build_Underlying_Full_View --
7527 --------------------------------
7529 procedure Build_Underlying_Full_View
7534 Loc
: constant Source_Ptr
:= Sloc
(N
);
7535 Subt
: constant Entity_Id
:=
7536 Make_Defining_Identifier
7537 (Loc
, New_External_Name
(Chars
(Typ
), 'S'));
7544 procedure Set_Discriminant_Name
(Id
: Node_Id
);
7545 -- If the derived type has discriminants, they may rename discriminants
7546 -- of the parent. When building the full view of the parent, we need to
7547 -- recover the names of the original discriminants if the constraint is
7548 -- given by named associations.
7550 ---------------------------
7551 -- Set_Discriminant_Name --
7552 ---------------------------
7554 procedure Set_Discriminant_Name
(Id
: Node_Id
) is
7558 Set_Original_Discriminant
(Id
, Empty
);
7560 if Has_Discriminants
(Typ
) then
7561 Disc
:= First_Discriminant
(Typ
);
7562 while Present
(Disc
) loop
7563 if Chars
(Disc
) = Chars
(Id
)
7564 and then Present
(Corresponding_Discriminant
(Disc
))
7566 Set_Chars
(Id
, Chars
(Corresponding_Discriminant
(Disc
)));
7568 Next_Discriminant
(Disc
);
7571 end Set_Discriminant_Name
;
7573 -- Start of processing for Build_Underlying_Full_View
7576 if Nkind
(N
) = N_Full_Type_Declaration
then
7577 Constr
:= Constraint
(Subtype_Indication
(Type_Definition
(N
)));
7579 elsif Nkind
(N
) = N_Subtype_Declaration
then
7580 Constr
:= New_Copy_Tree
(Constraint
(Subtype_Indication
(N
)));
7582 elsif Nkind
(N
) = N_Component_Declaration
then
7585 (Constraint
(Subtype_Indication
(Component_Definition
(N
))));
7588 raise Program_Error
;
7591 C
:= First
(Constraints
(Constr
));
7592 while Present
(C
) loop
7593 if Nkind
(C
) = N_Discriminant_Association
then
7594 Id
:= First
(Selector_Names
(C
));
7595 while Present
(Id
) loop
7596 Set_Discriminant_Name
(Id
);
7605 Make_Subtype_Declaration
(Loc
,
7606 Defining_Identifier
=> Subt
,
7607 Subtype_Indication
=>
7608 Make_Subtype_Indication
(Loc
,
7609 Subtype_Mark
=> New_Reference_To
(Par
, Loc
),
7610 Constraint
=> New_Copy_Tree
(Constr
)));
7612 -- If this is a component subtype for an outer itype, it is not
7613 -- a list member, so simply set the parent link for analysis: if
7614 -- the enclosing type does not need to be in a declarative list,
7615 -- neither do the components.
7617 if Is_List_Member
(N
)
7618 and then Nkind
(N
) /= N_Component_Declaration
7620 Insert_Before
(N
, Indic
);
7622 Set_Parent
(Indic
, Parent
(N
));
7626 Set_Underlying_Full_View
(Typ
, Full_View
(Subt
));
7627 end Build_Underlying_Full_View
;
7629 -------------------------------
7630 -- Check_Abstract_Interfaces --
7631 -------------------------------
7633 procedure Check_Abstract_Interfaces
(N
: Node_Id
; Def
: Node_Id
) is
7635 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
);
7636 -- Local subprogram used to avoid code duplication. In case of error
7637 -- the message will be associated to Error_Node.
7643 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
) is
7645 -- Ada 2005 (AI-345): Protected interfaces can only inherit from
7646 -- limited, synchronized or protected interfaces.
7648 if Protected_Present
(Def
) then
7649 if Limited_Present
(Iface_Def
)
7650 or else Synchronized_Present
(Iface_Def
)
7651 or else Protected_Present
(Iface_Def
)
7655 elsif Task_Present
(Iface_Def
) then
7656 Error_Msg_N
("(Ada 2005) protected interface cannot inherit"
7657 & " from task interface", Error_Node
);
7660 Error_Msg_N
("(Ada 2005) protected interface cannot inherit"
7661 & " from non-limited interface", Error_Node
);
7664 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
7665 -- limited and synchronized.
7667 elsif Synchronized_Present
(Def
) then
7668 if Limited_Present
(Iface_Def
)
7669 or else Synchronized_Present
(Iface_Def
)
7673 elsif Protected_Present
(Iface_Def
) then
7674 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit"
7675 & " from protected interface", Error_Node
);
7677 elsif Task_Present
(Iface_Def
) then
7678 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit"
7679 & " from task interface", Error_Node
);
7682 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit"
7683 & " from non-limited interface", Error_Node
);
7686 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
7687 -- synchronized or task interfaces.
7689 elsif Task_Present
(Def
) then
7690 if Limited_Present
(Iface_Def
)
7691 or else Synchronized_Present
(Iface_Def
)
7692 or else Task_Present
(Iface_Def
)
7696 elsif Protected_Present
(Iface_Def
) then
7697 Error_Msg_N
("(Ada 2005) task interface cannot inherit from"
7698 & " protected interface", Error_Node
);
7701 Error_Msg_N
("(Ada 2005) task interface cannot inherit from"
7702 & " non-limited interface", Error_Node
);
7710 Iface_Def
: Node_Id
;
7711 Iface_Typ
: Entity_Id
;
7712 Parent_Node
: Node_Id
;
7714 -- Start of processing for Check_Abstract_Interfaces
7717 -- Why is this still unsupported???
7719 if Nkind
(N
) = N_Private_Extension_Declaration
then
7723 -- Check the parent in case of derivation of interface type
7725 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
7726 and then Is_Interface
(Etype
(Defining_Identifier
(N
)))
7728 Parent_Node
:= Parent
(Etype
(Defining_Identifier
(N
)));
7731 (Iface_Def
=> Type_Definition
(Parent_Node
),
7732 Error_Node
=> Subtype_Indication
(Type_Definition
(N
)));
7735 Iface
:= First
(Interface_List
(Def
));
7736 while Present
(Iface
) loop
7737 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
7739 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
7740 Iface_Def
:= Type_Definition
(Parent_Node
);
7742 if not Is_Interface
(Iface_Typ
) then
7743 Error_Msg_NE
("(Ada 2005) & must be an interface",
7747 -- "The declaration of a specific descendant of an interface
7748 -- type freezes the interface type" RM 13.14
7750 Freeze_Before
(N
, Iface_Typ
);
7751 Check_Ifaces
(Iface_Def
, Error_Node
=> Iface
);
7756 end Check_Abstract_Interfaces
;
7758 -------------------------------
7759 -- Check_Abstract_Overriding --
7760 -------------------------------
7762 procedure Check_Abstract_Overriding
(T
: Entity_Id
) is
7763 Alias_Subp
: Entity_Id
;
7770 Op_List
:= Primitive_Operations
(T
);
7772 -- Loop to check primitive operations
7774 Elmt
:= First_Elmt
(Op_List
);
7775 while Present
(Elmt
) loop
7776 Subp
:= Node
(Elmt
);
7777 Alias_Subp
:= Alias
(Subp
);
7779 -- Inherited subprograms are identified by the fact that they do not
7780 -- come from source, and the associated source location is the
7781 -- location of the first subtype of the derived type.
7783 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
7784 -- subprograms that "require overriding".
7786 -- Special exception, do not complain about failure to override the
7787 -- stream routines _Input and _Output, as well as the primitive
7788 -- operations used in dispatching selects since we always provide
7789 -- automatic overridings for these subprograms.
7791 -- Also ignore this rule for convention CIL since .NET libraries
7792 -- do bizarre things with interfaces???
7794 -- The partial view of T may have been a private extension, for
7795 -- which inherited functions dispatching on result are abstract.
7796 -- If the full view is a null extension, there is no need for
7797 -- overriding in Ada2005, but wrappers need to be built for them
7798 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
7800 -- Use elseif here and avoid above goto???
7802 if Is_Null_Extension
(T
)
7803 and then Has_Controlling_Result
(Subp
)
7804 and then Ada_Version
>= Ada_05
7805 and then Present
(Alias
(Subp
))
7806 and then not Comes_From_Source
(Subp
)
7807 and then not Is_Abstract_Subprogram
(Alias
(Subp
))
7812 if (Is_Abstract_Subprogram
(Subp
)
7813 or else Requires_Overriding
(Subp
)
7814 or else (Has_Controlling_Result
(Subp
)
7815 and then Present
(Alias_Subp
)
7816 and then not Comes_From_Source
(Subp
)
7817 and then Sloc
(Subp
) = Sloc
(First_Subtype
(T
))))
7818 and then not Is_TSS
(Subp
, TSS_Stream_Input
)
7819 and then not Is_TSS
(Subp
, TSS_Stream_Output
)
7820 and then not Is_Abstract_Type
(T
)
7821 and then Convention
(T
) /= Convention_CIL
7822 and then Chars
(Subp
) /= Name_uDisp_Asynchronous_Select
7823 and then Chars
(Subp
) /= Name_uDisp_Conditional_Select
7824 and then Chars
(Subp
) /= Name_uDisp_Get_Prim_Op_Kind
7825 and then Chars
(Subp
) /= Name_uDisp_Timed_Select
7827 -- Ada 2005 (AI-251): Do not consider hidden entities associated
7828 -- with abstract interface types because the check will be done
7829 -- with the aliased entity (otherwise we generate a duplicated
7832 and then not Present
(Abstract_Interface_Alias
(Subp
))
7834 if Present
(Alias_Subp
) then
7836 -- Only perform the check for a derived subprogram when the
7837 -- type has an explicit record extension. This avoids
7838 -- incorrectly flagging abstract subprograms for the case of a
7839 -- type without an extension derived from a formal type with a
7840 -- tagged actual (can occur within a private part).
7842 -- Ada 2005 (AI-391): In the case of an inherited function with
7843 -- a controlling result of the type, the rule does not apply if
7844 -- the type is a null extension (unless the parent function
7845 -- itself is abstract, in which case the function must still be
7846 -- be overridden). The expander will generate an overriding
7847 -- wrapper function calling the parent subprogram (see
7848 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
7850 Type_Def
:= Type_Definition
(Parent
(T
));
7851 if Nkind
(Type_Def
) = N_Derived_Type_Definition
7852 and then Present
(Record_Extension_Part
(Type_Def
))
7854 (Ada_Version
< Ada_05
7855 or else not Is_Null_Extension
(T
)
7856 or else Ekind
(Subp
) = E_Procedure
7857 or else not Has_Controlling_Result
(Subp
)
7858 or else Is_Abstract_Subprogram
(Alias_Subp
)
7859 or else Requires_Overriding
(Subp
)
7860 or else Is_Access_Type
(Etype
(Subp
)))
7863 ("type must be declared abstract or & overridden",
7866 -- Traverse the whole chain of aliased subprograms to
7867 -- complete the error notification. This is especially
7868 -- useful for traceability of the chain of entities when the
7869 -- subprogram corresponds with an interface subprogram
7870 -- (which might be defined in another package)
7872 if Present
(Alias_Subp
) then
7878 while Present
(Alias
(E
)) loop
7879 Error_Msg_Sloc
:= Sloc
(E
);
7880 Error_Msg_NE
("\& has been inherited #", T
, Subp
);
7884 Error_Msg_Sloc
:= Sloc
(E
);
7886 ("\& has been inherited from subprogram #", T
, Subp
);
7890 -- Ada 2005 (AI-345): Protected or task type implementing
7891 -- abstract interfaces.
7893 elsif Is_Concurrent_Record_Type
(T
)
7894 and then Present
(Abstract_Interfaces
(T
))
7896 -- The controlling formal of Subp must be of mode "out",
7897 -- "in out" or an access-to-variable to be overridden.
7899 -- Error message below needs rewording (remember comma
7900 -- in -gnatj mode) ???
7902 if Ekind
(First_Formal
(Subp
)) = E_In_Parameter
then
7904 ("first formal of & must be of mode `OUT`, `IN OUT` " &
7905 "or access-to-variable", T
, Subp
);
7907 ("\to be overridden by protected procedure or " &
7908 "entry (RM 9.4(11.9/2))", T
);
7910 -- Some other kind of overriding failure
7914 ("interface subprogram & must be overridden",
7920 Error_Msg_Node_2
:= T
;
7922 ("abstract subprogram& not allowed for type&", Subp
);
7924 -- Also post unconditional warning on the type (unconditional
7925 -- so that if there are more than one of these cases, we get
7926 -- them all, and not just the first one).
7928 Error_Msg_Node_2
:= Subp
;
7930 ("nonabstract type& has abstract subprogram&!", T
);
7937 end Check_Abstract_Overriding
;
7939 ------------------------------------------------
7940 -- Check_Access_Discriminant_Requires_Limited --
7941 ------------------------------------------------
7943 procedure Check_Access_Discriminant_Requires_Limited
7948 -- A discriminant_specification for an access discriminant shall appear
7949 -- only in the declaration for a task or protected type, or for a type
7950 -- with the reserved word 'limited' in its definition or in one of its
7951 -- ancestors. (RM 3.7(10))
7953 if Nkind
(Discriminant_Type
(D
)) = N_Access_Definition
7954 and then not Is_Concurrent_Type
(Current_Scope
)
7955 and then not Is_Concurrent_Record_Type
(Current_Scope
)
7956 and then not Is_Limited_Record
(Current_Scope
)
7957 and then Ekind
(Current_Scope
) /= E_Limited_Private_Type
7960 ("access discriminants allowed only for limited types", Loc
);
7962 end Check_Access_Discriminant_Requires_Limited
;
7964 -----------------------------------
7965 -- Check_Aliased_Component_Types --
7966 -----------------------------------
7968 procedure Check_Aliased_Component_Types
(T
: Entity_Id
) is
7972 -- ??? Also need to check components of record extensions, but not
7973 -- components of protected types (which are always limited).
7975 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
7976 -- types to be unconstrained. This is safe because it is illegal to
7977 -- create access subtypes to such types with explicit discriminant
7980 if not Is_Limited_Type
(T
) then
7981 if Ekind
(T
) = E_Record_Type
then
7982 C
:= First_Component
(T
);
7983 while Present
(C
) loop
7985 and then Has_Discriminants
(Etype
(C
))
7986 and then not Is_Constrained
(Etype
(C
))
7987 and then not In_Instance_Body
7988 and then Ada_Version
< Ada_05
7991 ("aliased component must be constrained (RM 3.6(11))",
7998 elsif Ekind
(T
) = E_Array_Type
then
7999 if Has_Aliased_Components
(T
)
8000 and then Has_Discriminants
(Component_Type
(T
))
8001 and then not Is_Constrained
(Component_Type
(T
))
8002 and then not In_Instance_Body
8003 and then Ada_Version
< Ada_05
8006 ("aliased component type must be constrained (RM 3.6(11))",
8011 end Check_Aliased_Component_Types
;
8013 ----------------------
8014 -- Check_Completion --
8015 ----------------------
8017 procedure Check_Completion
(Body_Id
: Node_Id
:= Empty
) is
8020 procedure Post_Error
;
8021 -- Post error message for lack of completion for entity E
8027 procedure Post_Error
is
8029 if not Comes_From_Source
(E
) then
8031 if Ekind
(E
) = E_Task_Type
8032 or else Ekind
(E
) = E_Protected_Type
8034 -- It may be an anonymous protected type created for a
8035 -- single variable. Post error on variable, if present.
8041 Var
:= First_Entity
(Current_Scope
);
8042 while Present
(Var
) loop
8043 exit when Etype
(Var
) = E
8044 and then Comes_From_Source
(Var
);
8049 if Present
(Var
) then
8056 -- If a generated entity has no completion, then either previous
8057 -- semantic errors have disabled the expansion phase, or else we had
8058 -- missing subunits, or else we are compiling without expansion,
8059 -- or else something is very wrong.
8061 if not Comes_From_Source
(E
) then
8063 (Serious_Errors_Detected
> 0
8064 or else Configurable_Run_Time_Violations
> 0
8065 or else Subunits_Missing
8066 or else not Expander_Active
);
8069 -- Here for source entity
8072 -- Here if no body to post the error message, so we post the error
8073 -- on the declaration that has no completion. This is not really
8074 -- the right place to post it, think about this later ???
8076 if No
(Body_Id
) then
8079 ("missing full declaration for }", Parent
(E
), E
);
8082 ("missing body for &", Parent
(E
), E
);
8085 -- Package body has no completion for a declaration that appears
8086 -- in the corresponding spec. Post error on the body, with a
8087 -- reference to the non-completed declaration.
8090 Error_Msg_Sloc
:= Sloc
(E
);
8094 ("missing full declaration for }!", Body_Id
, E
);
8096 elsif Is_Overloadable
(E
)
8097 and then Current_Entity_In_Scope
(E
) /= E
8099 -- It may be that the completion is mistyped and appears
8100 -- as a distinct overloading of the entity.
8103 Candidate
: constant Entity_Id
:=
8104 Current_Entity_In_Scope
(E
);
8105 Decl
: constant Node_Id
:=
8106 Unit_Declaration_Node
(Candidate
);
8109 if Is_Overloadable
(Candidate
)
8110 and then Ekind
(Candidate
) = Ekind
(E
)
8111 and then Nkind
(Decl
) = N_Subprogram_Body
8112 and then Acts_As_Spec
(Decl
)
8114 Check_Type_Conformant
(Candidate
, E
);
8117 Error_Msg_NE
("missing body for & declared#!",
8122 Error_Msg_NE
("missing body for & declared#!",
8129 -- Start processing for Check_Completion
8132 E
:= First_Entity
(Current_Scope
);
8133 while Present
(E
) loop
8134 if Is_Intrinsic_Subprogram
(E
) then
8137 -- The following situation requires special handling: a child
8138 -- unit that appears in the context clause of the body of its
8141 -- procedure Parent.Child (...);
8143 -- with Parent.Child;
8144 -- package body Parent is
8146 -- Here Parent.Child appears as a local entity, but should not
8147 -- be flagged as requiring completion, because it is a
8148 -- compilation unit.
8150 -- Ignore missing completion for a subprogram that does not come from
8151 -- source (including the _Call primitive operation of RAS types,
8152 -- which has to have the flag Comes_From_Source for other purposes):
8153 -- we assume that the expander will provide the missing completion.
8155 elsif Ekind
(E
) = E_Function
8156 or else Ekind
(E
) = E_Procedure
8157 or else Ekind
(E
) = E_Generic_Function
8158 or else Ekind
(E
) = E_Generic_Procedure
8160 if not Has_Completion
(E
)
8161 and then not (Is_Subprogram
(E
)
8162 and then Is_Abstract_Subprogram
(E
))
8163 and then not (Is_Subprogram
(E
)
8165 (not Comes_From_Source
(E
)
8166 or else Chars
(E
) = Name_uCall
))
8167 and then Nkind
(Parent
(Unit_Declaration_Node
(E
))) /=
8169 and then Chars
(E
) /= Name_uSize
8174 elsif Is_Entry
(E
) then
8175 if not Has_Completion
(E
) and then
8176 (Ekind
(Scope
(E
)) = E_Protected_Object
8177 or else Ekind
(Scope
(E
)) = E_Protected_Type
)
8182 elsif Is_Package_Or_Generic_Package
(E
) then
8183 if Unit_Requires_Body
(E
) then
8184 if not Has_Completion
(E
)
8185 and then Nkind
(Parent
(Unit_Declaration_Node
(E
))) /=
8191 elsif not Is_Child_Unit
(E
) then
8192 May_Need_Implicit_Body
(E
);
8195 elsif Ekind
(E
) = E_Incomplete_Type
8196 and then No
(Underlying_Type
(E
))
8200 elsif (Ekind
(E
) = E_Task_Type
or else
8201 Ekind
(E
) = E_Protected_Type
)
8202 and then not Has_Completion
(E
)
8206 -- A single task declared in the current scope is a constant, verify
8207 -- that the body of its anonymous type is in the same scope. If the
8208 -- task is defined elsewhere, this may be a renaming declaration for
8209 -- which no completion is needed.
8211 elsif Ekind
(E
) = E_Constant
8212 and then Ekind
(Etype
(E
)) = E_Task_Type
8213 and then not Has_Completion
(Etype
(E
))
8214 and then Scope
(Etype
(E
)) = Current_Scope
8218 elsif Ekind
(E
) = E_Protected_Object
8219 and then not Has_Completion
(Etype
(E
))
8223 elsif Ekind
(E
) = E_Record_Type
then
8224 if Is_Tagged_Type
(E
) then
8225 Check_Abstract_Overriding
(E
);
8226 Check_Conventions
(E
);
8229 Check_Aliased_Component_Types
(E
);
8231 elsif Ekind
(E
) = E_Array_Type
then
8232 Check_Aliased_Component_Types
(E
);
8238 end Check_Completion
;
8240 ----------------------------
8241 -- Check_Delta_Expression --
8242 ----------------------------
8244 procedure Check_Delta_Expression
(E
: Node_Id
) is
8246 if not (Is_Real_Type
(Etype
(E
))) then
8247 Wrong_Type
(E
, Any_Real
);
8249 elsif not Is_OK_Static_Expression
(E
) then
8250 Flag_Non_Static_Expr
8251 ("non-static expression used for delta value!", E
);
8253 elsif not UR_Is_Positive
(Expr_Value_R
(E
)) then
8254 Error_Msg_N
("delta expression must be positive", E
);
8260 -- If any of above errors occurred, then replace the incorrect
8261 -- expression by the real 0.1, which should prevent further errors.
8264 Make_Real_Literal
(Sloc
(E
), Ureal_Tenth
));
8265 Analyze_And_Resolve
(E
, Standard_Float
);
8266 end Check_Delta_Expression
;
8268 -----------------------------
8269 -- Check_Digits_Expression --
8270 -----------------------------
8272 procedure Check_Digits_Expression
(E
: Node_Id
) is
8274 if not (Is_Integer_Type
(Etype
(E
))) then
8275 Wrong_Type
(E
, Any_Integer
);
8277 elsif not Is_OK_Static_Expression
(E
) then
8278 Flag_Non_Static_Expr
8279 ("non-static expression used for digits value!", E
);
8281 elsif Expr_Value
(E
) <= 0 then
8282 Error_Msg_N
("digits value must be greater than zero", E
);
8288 -- If any of above errors occurred, then replace the incorrect
8289 -- expression by the integer 1, which should prevent further errors.
8291 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), 1));
8292 Analyze_And_Resolve
(E
, Standard_Integer
);
8294 end Check_Digits_Expression
;
8296 --------------------------
8297 -- Check_Initialization --
8298 --------------------------
8300 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
) is
8302 if Is_Limited_Type
(T
)
8303 and then not In_Instance
8304 and then not In_Inlined_Body
8306 if not OK_For_Limited_Init
(Exp
) then
8308 -- In GNAT mode, this is just a warning, to allow it to be evilly
8309 -- turned off. Otherwise it is a real error.
8313 ("?cannot initialize entities of limited type!", Exp
);
8315 elsif Ada_Version
< Ada_05
then
8317 ("cannot initialize entities of limited type", Exp
);
8318 Explain_Limited_Type
(T
, Exp
);
8321 -- Specialize error message according to kind of illegal
8322 -- initial expression.
8324 if Nkind
(Exp
) = N_Type_Conversion
8325 and then Nkind
(Expression
(Exp
)) = N_Function_Call
8328 ("illegal context for call"
8329 & " to function with limited result", Exp
);
8333 ("initialization of limited object requires agggregate "
8334 & "or function call", Exp
);
8339 end Check_Initialization
;
8341 ------------------------------------
8342 -- Check_Or_Process_Discriminants --
8343 ------------------------------------
8345 -- If an incomplete or private type declaration was already given for the
8346 -- type, the discriminants may have already been processed if they were
8347 -- present on the incomplete declaration. In this case a full conformance
8348 -- check is performed otherwise just process them.
8350 procedure Check_Or_Process_Discriminants
8353 Prev
: Entity_Id
:= Empty
)
8356 if Has_Discriminants
(T
) then
8358 -- Make the discriminants visible to component declarations
8365 D
:= First_Discriminant
(T
);
8366 while Present
(D
) loop
8367 Prev
:= Current_Entity
(D
);
8368 Set_Current_Entity
(D
);
8369 Set_Is_Immediately_Visible
(D
);
8370 Set_Homonym
(D
, Prev
);
8372 -- Ada 2005 (AI-230): Access discriminant allowed in
8373 -- non-limited record types.
8375 if Ada_Version
< Ada_05
then
8377 -- This restriction gets applied to the full type here. It
8378 -- has already been applied earlier to the partial view.
8380 Check_Access_Discriminant_Requires_Limited
(Parent
(D
), N
);
8383 Next_Discriminant
(D
);
8387 elsif Present
(Discriminant_Specifications
(N
)) then
8388 Process_Discriminants
(N
, Prev
);
8390 end Check_Or_Process_Discriminants
;
8392 ----------------------
8393 -- Check_Real_Bound --
8394 ----------------------
8396 procedure Check_Real_Bound
(Bound
: Node_Id
) is
8398 if not Is_Real_Type
(Etype
(Bound
)) then
8400 ("bound in real type definition must be of real type", Bound
);
8402 elsif not Is_OK_Static_Expression
(Bound
) then
8403 Flag_Non_Static_Expr
8404 ("non-static expression used for real type bound!", Bound
);
8411 (Bound
, Make_Real_Literal
(Sloc
(Bound
), Ureal_0
));
8413 Resolve
(Bound
, Standard_Float
);
8414 end Check_Real_Bound
;
8416 ------------------------------
8417 -- Complete_Private_Subtype --
8418 ------------------------------
8420 procedure Complete_Private_Subtype
8423 Full_Base
: Entity_Id
;
8424 Related_Nod
: Node_Id
)
8426 Save_Next_Entity
: Entity_Id
;
8427 Save_Homonym
: Entity_Id
;
8430 -- Set semantic attributes for (implicit) private subtype completion.
8431 -- If the full type has no discriminants, then it is a copy of the full
8432 -- view of the base. Otherwise, it is a subtype of the base with a
8433 -- possible discriminant constraint. Save and restore the original
8434 -- Next_Entity field of full to ensure that the calls to Copy_Node
8435 -- do not corrupt the entity chain.
8437 -- Note that the type of the full view is the same entity as the type of
8438 -- the partial view. In this fashion, the subtype has access to the
8439 -- correct view of the parent.
8441 Save_Next_Entity
:= Next_Entity
(Full
);
8442 Save_Homonym
:= Homonym
(Priv
);
8444 case Ekind
(Full_Base
) is
8445 when E_Record_Type |
8451 Copy_Node
(Priv
, Full
);
8453 Set_Has_Discriminants
(Full
, Has_Discriminants
(Full_Base
));
8454 Set_First_Entity
(Full
, First_Entity
(Full_Base
));
8455 Set_Last_Entity
(Full
, Last_Entity
(Full_Base
));
8458 Copy_Node
(Full_Base
, Full
);
8459 Set_Chars
(Full
, Chars
(Priv
));
8460 Conditional_Delay
(Full
, Priv
);
8461 Set_Sloc
(Full
, Sloc
(Priv
));
8464 Set_Next_Entity
(Full
, Save_Next_Entity
);
8465 Set_Homonym
(Full
, Save_Homonym
);
8466 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
8468 -- Set common attributes for all subtypes
8470 Set_Ekind
(Full
, Subtype_Kind
(Ekind
(Full_Base
)));
8472 -- The Etype of the full view is inconsistent. Gigi needs to see the
8473 -- structural full view, which is what the current scheme gives:
8474 -- the Etype of the full view is the etype of the full base. However,
8475 -- if the full base is a derived type, the full view then looks like
8476 -- a subtype of the parent, not a subtype of the full base. If instead
8479 -- Set_Etype (Full, Full_Base);
8481 -- then we get inconsistencies in the front-end (confusion between
8482 -- views). Several outstanding bugs are related to this ???
8484 Set_Is_First_Subtype
(Full
, False);
8485 Set_Scope
(Full
, Scope
(Priv
));
8486 Set_Size_Info
(Full
, Full_Base
);
8487 Set_RM_Size
(Full
, RM_Size
(Full_Base
));
8488 Set_Is_Itype
(Full
);
8490 -- A subtype of a private-type-without-discriminants, whose full-view
8491 -- has discriminants with default expressions, is not constrained!
8493 if not Has_Discriminants
(Priv
) then
8494 Set_Is_Constrained
(Full
, Is_Constrained
(Full_Base
));
8496 if Has_Discriminants
(Full_Base
) then
8497 Set_Discriminant_Constraint
8498 (Full
, Discriminant_Constraint
(Full_Base
));
8500 -- The partial view may have been indefinite, the full view
8503 Set_Has_Unknown_Discriminants
8504 (Full
, Has_Unknown_Discriminants
(Full_Base
));
8508 Set_First_Rep_Item
(Full
, First_Rep_Item
(Full_Base
));
8509 Set_Depends_On_Private
(Full
, Has_Private_Component
(Full
));
8511 -- Freeze the private subtype entity if its parent is delayed, and not
8512 -- already frozen. We skip this processing if the type is an anonymous
8513 -- subtype of a record component, or is the corresponding record of a
8514 -- protected type, since ???
8516 if not Is_Type
(Scope
(Full
)) then
8517 Set_Has_Delayed_Freeze
(Full
,
8518 Has_Delayed_Freeze
(Full_Base
)
8519 and then (not Is_Frozen
(Full_Base
)));
8522 Set_Freeze_Node
(Full
, Empty
);
8523 Set_Is_Frozen
(Full
, False);
8524 Set_Full_View
(Priv
, Full
);
8526 if Has_Discriminants
(Full
) then
8527 Set_Stored_Constraint_From_Discriminant_Constraint
(Full
);
8528 Set_Stored_Constraint
(Priv
, Stored_Constraint
(Full
));
8530 if Has_Unknown_Discriminants
(Full
) then
8531 Set_Discriminant_Constraint
(Full
, No_Elist
);
8535 if Ekind
(Full_Base
) = E_Record_Type
8536 and then Has_Discriminants
(Full_Base
)
8537 and then Has_Discriminants
(Priv
) -- might not, if errors
8538 and then not Has_Unknown_Discriminants
(Priv
)
8539 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(Priv
))
8541 Create_Constrained_Components
8542 (Full
, Related_Nod
, Full_Base
, Discriminant_Constraint
(Priv
));
8544 -- If the full base is itself derived from private, build a congruent
8545 -- subtype of its underlying type, for use by the back end. For a
8546 -- constrained record component, the declaration cannot be placed on
8547 -- the component list, but it must nevertheless be built an analyzed, to
8548 -- supply enough information for Gigi to compute the size of component.
8550 elsif Ekind
(Full_Base
) in Private_Kind
8551 and then Is_Derived_Type
(Full_Base
)
8552 and then Has_Discriminants
(Full_Base
)
8553 and then (Ekind
(Current_Scope
) /= E_Record_Subtype
)
8555 if not Is_Itype
(Priv
)
8557 Nkind
(Subtype_Indication
(Parent
(Priv
))) = N_Subtype_Indication
8559 Build_Underlying_Full_View
8560 (Parent
(Priv
), Full
, Etype
(Full_Base
));
8562 elsif Nkind
(Related_Nod
) = N_Component_Declaration
then
8563 Build_Underlying_Full_View
(Related_Nod
, Full
, Etype
(Full_Base
));
8566 elsif Is_Record_Type
(Full_Base
) then
8568 -- Show Full is simply a renaming of Full_Base
8570 Set_Cloned_Subtype
(Full
, Full_Base
);
8573 -- It is unsafe to share to bounds of a scalar type, because the Itype
8574 -- is elaborated on demand, and if a bound is non-static then different
8575 -- orders of elaboration in different units will lead to different
8576 -- external symbols.
8578 if Is_Scalar_Type
(Full_Base
) then
8579 Set_Scalar_Range
(Full
,
8580 Make_Range
(Sloc
(Related_Nod
),
8582 Duplicate_Subexpr_No_Checks
(Type_Low_Bound
(Full_Base
)),
8584 Duplicate_Subexpr_No_Checks
(Type_High_Bound
(Full_Base
))));
8586 -- This completion inherits the bounds of the full parent, but if
8587 -- the parent is an unconstrained floating point type, so is the
8590 if Is_Floating_Point_Type
(Full_Base
) then
8591 Set_Includes_Infinities
8592 (Scalar_Range
(Full
), Has_Infinities
(Full_Base
));
8596 -- ??? It seems that a lot of fields are missing that should be copied
8597 -- from Full_Base to Full. Here are some that are introduced in a
8598 -- non-disruptive way but a cleanup is necessary.
8600 if Is_Tagged_Type
(Full_Base
) then
8601 Set_Is_Tagged_Type
(Full
);
8602 Set_Primitive_Operations
(Full
, Primitive_Operations
(Full_Base
));
8603 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Full_Base
));
8605 -- If this is a subtype of a protected or task type, constrain its
8606 -- corresponding record, unless this is a subtype without constraints,
8607 -- i.e. a simple renaming as with an actual subtype in an instance.
8609 elsif Is_Concurrent_Type
(Full_Base
) then
8610 if Has_Discriminants
(Full
)
8611 and then Present
(Corresponding_Record_Type
(Full_Base
))
8613 not Is_Empty_Elmt_List
(Discriminant_Constraint
(Full
))
8615 Set_Corresponding_Record_Type
(Full
,
8616 Constrain_Corresponding_Record
8617 (Full
, Corresponding_Record_Type
(Full_Base
),
8618 Related_Nod
, Full_Base
));
8621 Set_Corresponding_Record_Type
(Full
,
8622 Corresponding_Record_Type
(Full_Base
));
8625 end Complete_Private_Subtype
;
8627 ----------------------------
8628 -- Constant_Redeclaration --
8629 ----------------------------
8631 procedure Constant_Redeclaration
8636 Prev
: constant Entity_Id
:= Current_Entity_In_Scope
(Id
);
8637 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
8640 procedure Check_Possible_Deferred_Completion
8641 (Prev_Id
: Entity_Id
;
8642 Prev_Obj_Def
: Node_Id
;
8643 Curr_Obj_Def
: Node_Id
);
8644 -- Determine whether the two object definitions describe the partial
8645 -- and the full view of a constrained deferred constant. Generate
8646 -- a subtype for the full view and verify that it statically matches
8647 -- the subtype of the partial view.
8649 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
);
8650 -- If deferred constant is an access type initialized with an allocator,
8651 -- check whether there is an illegal recursion in the definition,
8652 -- through a default value of some record subcomponent. This is normally
8653 -- detected when generating init procs, but requires this additional
8654 -- mechanism when expansion is disabled.
8656 ----------------------------------------
8657 -- Check_Possible_Deferred_Completion --
8658 ----------------------------------------
8660 procedure Check_Possible_Deferred_Completion
8661 (Prev_Id
: Entity_Id
;
8662 Prev_Obj_Def
: Node_Id
;
8663 Curr_Obj_Def
: Node_Id
)
8666 if Nkind
(Prev_Obj_Def
) = N_Subtype_Indication
8667 and then Present
(Constraint
(Prev_Obj_Def
))
8668 and then Nkind
(Curr_Obj_Def
) = N_Subtype_Indication
8669 and then Present
(Constraint
(Curr_Obj_Def
))
8672 Loc
: constant Source_Ptr
:= Sloc
(N
);
8673 Def_Id
: constant Entity_Id
:=
8674 Make_Defining_Identifier
(Loc
,
8675 New_Internal_Name
('S'));
8676 Decl
: constant Node_Id
:=
8677 Make_Subtype_Declaration
(Loc
,
8678 Defining_Identifier
=>
8680 Subtype_Indication
=>
8681 Relocate_Node
(Curr_Obj_Def
));
8684 Insert_Before_And_Analyze
(N
, Decl
);
8685 Set_Etype
(Id
, Def_Id
);
8687 if not Subtypes_Statically_Match
(Etype
(Prev_Id
), Def_Id
) then
8688 Error_Msg_Sloc
:= Sloc
(Prev_Id
);
8689 Error_Msg_N
("subtype does not statically match deferred " &
8694 end Check_Possible_Deferred_Completion
;
8696 ---------------------------------
8697 -- Check_Recursive_Declaration --
8698 ---------------------------------
8700 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
) is
8704 if Is_Record_Type
(Typ
) then
8705 Comp
:= First_Component
(Typ
);
8706 while Present
(Comp
) loop
8707 if Comes_From_Source
(Comp
) then
8708 if Present
(Expression
(Parent
(Comp
)))
8709 and then Is_Entity_Name
(Expression
(Parent
(Comp
)))
8710 and then Entity
(Expression
(Parent
(Comp
))) = Prev
8712 Error_Msg_Sloc
:= Sloc
(Parent
(Comp
));
8714 ("illegal circularity with declaration for&#",
8718 elsif Is_Record_Type
(Etype
(Comp
)) then
8719 Check_Recursive_Declaration
(Etype
(Comp
));
8723 Next_Component
(Comp
);
8726 end Check_Recursive_Declaration
;
8728 -- Start of processing for Constant_Redeclaration
8731 if Nkind
(Parent
(Prev
)) = N_Object_Declaration
then
8732 if Nkind
(Object_Definition
8733 (Parent
(Prev
))) = N_Subtype_Indication
8735 -- Find type of new declaration. The constraints of the two
8736 -- views must match statically, but there is no point in
8737 -- creating an itype for the full view.
8739 if Nkind
(Obj_Def
) = N_Subtype_Indication
then
8740 Find_Type
(Subtype_Mark
(Obj_Def
));
8741 New_T
:= Entity
(Subtype_Mark
(Obj_Def
));
8744 Find_Type
(Obj_Def
);
8745 New_T
:= Entity
(Obj_Def
);
8751 -- The full view may impose a constraint, even if the partial
8752 -- view does not, so construct the subtype.
8754 New_T
:= Find_Type_Of_Object
(Obj_Def
, N
);
8759 -- Current declaration is illegal, diagnosed below in Enter_Name
8765 -- If previous full declaration exists, or if a homograph is present,
8766 -- let Enter_Name handle it, either with an error, or with the removal
8767 -- of an overridden implicit subprogram.
8769 if Ekind
(Prev
) /= E_Constant
8770 or else Present
(Expression
(Parent
(Prev
)))
8771 or else Present
(Full_View
(Prev
))
8775 -- Verify that types of both declarations match, or else that both types
8776 -- are anonymous access types whose designated subtypes statically match
8777 -- (as allowed in Ada 2005 by AI-385).
8779 elsif Base_Type
(Etype
(Prev
)) /= Base_Type
(New_T
)
8781 (Ekind
(Etype
(Prev
)) /= E_Anonymous_Access_Type
8782 or else Ekind
(Etype
(New_T
)) /= E_Anonymous_Access_Type
8783 or else not Subtypes_Statically_Match
8784 (Designated_Type
(Etype
(Prev
)),
8785 Designated_Type
(Etype
(New_T
))))
8787 Error_Msg_Sloc
:= Sloc
(Prev
);
8788 Error_Msg_N
("type does not match declaration#", N
);
8789 Set_Full_View
(Prev
, Id
);
8790 Set_Etype
(Id
, Any_Type
);
8792 -- If so, process the full constant declaration
8795 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
8796 -- the deferred declaration is constrained, then the subtype defined
8797 -- by the subtype_indication in the full declaration shall match it
8800 Check_Possible_Deferred_Completion
8802 Prev_Obj_Def
=> Object_Definition
(Parent
(Prev
)),
8803 Curr_Obj_Def
=> Obj_Def
);
8805 Set_Full_View
(Prev
, Id
);
8806 Set_Is_Public
(Id
, Is_Public
(Prev
));
8807 Set_Is_Internal
(Id
);
8808 Append_Entity
(Id
, Current_Scope
);
8810 -- Check ALIASED present if present before (RM 7.4(7))
8812 if Is_Aliased
(Prev
)
8813 and then not Aliased_Present
(N
)
8815 Error_Msg_Sloc
:= Sloc
(Prev
);
8816 Error_Msg_N
("ALIASED required (see declaration#)", N
);
8819 -- Allow incomplete declaration of tags (used to handle forward
8820 -- references to tags). The check on Ada_Tags avoids cicularities
8821 -- when rebuilding the compiler.
8823 if RTU_Loaded
(Ada_Tags
)
8824 and then T
= RTE
(RE_Tag
)
8828 -- Check that placement is in private part and that the incomplete
8829 -- declaration appeared in the visible part.
8831 elsif Ekind
(Current_Scope
) = E_Package
8832 and then not In_Private_Part
(Current_Scope
)
8834 Error_Msg_Sloc
:= Sloc
(Prev
);
8835 Error_Msg_N
("full constant for declaration#"
8836 & " must be in private part", N
);
8838 elsif Ekind
(Current_Scope
) = E_Package
8839 and then List_Containing
(Parent
(Prev
))
8840 /= Visible_Declarations
8841 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
8844 ("deferred constant must be declared in visible part",
8848 if Is_Access_Type
(T
)
8849 and then Nkind
(Expression
(N
)) = N_Allocator
8851 Check_Recursive_Declaration
(Designated_Type
(T
));
8854 end Constant_Redeclaration
;
8856 ----------------------
8857 -- Constrain_Access --
8858 ----------------------
8860 procedure Constrain_Access
8861 (Def_Id
: in out Entity_Id
;
8863 Related_Nod
: Node_Id
)
8865 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
8866 Desig_Type
: constant Entity_Id
:= Designated_Type
(T
);
8867 Desig_Subtype
: Entity_Id
:= Create_Itype
(E_Void
, Related_Nod
);
8868 Constraint_OK
: Boolean := True;
8870 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean;
8871 -- Simple predicate to test for defaulted discriminants
8872 -- Shouldn't this be in sem_util???
8874 ---------------------------------
8875 -- Has_Defaulted_Discriminants --
8876 ---------------------------------
8878 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
8880 return Has_Discriminants
(Typ
)
8881 and then Present
(First_Discriminant
(Typ
))
8883 (Discriminant_Default_Value
(First_Discriminant
(Typ
)));
8884 end Has_Defaulted_Discriminants
;
8886 -- Start of processing for Constrain_Access
8889 if Is_Array_Type
(Desig_Type
) then
8890 Constrain_Array
(Desig_Subtype
, S
, Related_Nod
, Def_Id
, 'P');
8892 elsif (Is_Record_Type
(Desig_Type
)
8893 or else Is_Incomplete_Or_Private_Type
(Desig_Type
))
8894 and then not Is_Constrained
(Desig_Type
)
8896 -- ??? The following code is a temporary kludge to ignore a
8897 -- discriminant constraint on access type if it is constraining
8898 -- the current record. Avoid creating the implicit subtype of the
8899 -- record we are currently compiling since right now, we cannot
8900 -- handle these. For now, just return the access type itself.
8902 if Desig_Type
= Current_Scope
8903 and then No
(Def_Id
)
8905 Set_Ekind
(Desig_Subtype
, E_Record_Subtype
);
8906 Def_Id
:= Entity
(Subtype_Mark
(S
));
8908 -- This call added to ensure that the constraint is analyzed
8909 -- (needed for a B test). Note that we still return early from
8910 -- this procedure to avoid recursive processing. ???
8912 Constrain_Discriminated_Type
8913 (Desig_Subtype
, S
, Related_Nod
, For_Access
=> True);
8917 if Ekind
(T
) = E_General_Access_Type
8918 and then Has_Private_Declaration
(Desig_Type
)
8919 and then In_Open_Scopes
(Scope
(Desig_Type
))
8921 -- Enforce rule that the constraint is illegal if there is
8922 -- an unconstrained view of the designated type. This means
8923 -- that the partial view (either a private type declaration or
8924 -- a derivation from a private type) has no discriminants.
8925 -- (Defect Report 8652/0008, Technical Corrigendum 1, checked
8926 -- by ACATS B371001).
8928 -- Rule updated for Ada 2005: the private type is said to have
8929 -- a constrained partial view, given that objects of the type
8933 Pack
: constant Node_Id
:=
8934 Unit_Declaration_Node
(Scope
(Desig_Type
));
8939 if Nkind
(Pack
) = N_Package_Declaration
then
8940 Decls
:= Visible_Declarations
(Specification
(Pack
));
8941 Decl
:= First
(Decls
);
8942 while Present
(Decl
) loop
8943 if (Nkind
(Decl
) = N_Private_Type_Declaration
8945 Chars
(Defining_Identifier
(Decl
)) =
8949 (Nkind
(Decl
) = N_Full_Type_Declaration
8951 Chars
(Defining_Identifier
(Decl
)) =
8953 and then Is_Derived_Type
(Desig_Type
)
8955 Has_Private_Declaration
(Etype
(Desig_Type
)))
8957 if No
(Discriminant_Specifications
(Decl
)) then
8959 ("cannot constrain general access type if " &
8960 "designated type has constrained partial view",
8973 Constrain_Discriminated_Type
(Desig_Subtype
, S
, Related_Nod
,
8974 For_Access
=> True);
8976 elsif (Is_Task_Type
(Desig_Type
)
8977 or else Is_Protected_Type
(Desig_Type
))
8978 and then not Is_Constrained
(Desig_Type
)
8980 Constrain_Concurrent
8981 (Desig_Subtype
, S
, Related_Nod
, Desig_Type
, ' ');
8984 Error_Msg_N
("invalid constraint on access type", S
);
8985 Desig_Subtype
:= Desig_Type
; -- Ignore invalid constraint.
8986 Constraint_OK
:= False;
8990 Def_Id
:= Create_Itype
(E_Access_Subtype
, Related_Nod
);
8992 Set_Ekind
(Def_Id
, E_Access_Subtype
);
8995 if Constraint_OK
then
8996 Set_Etype
(Def_Id
, Base_Type
(T
));
8998 if Is_Private_Type
(Desig_Type
) then
8999 Prepare_Private_Subtype_Completion
(Desig_Subtype
, Related_Nod
);
9002 Set_Etype
(Def_Id
, Any_Type
);
9005 Set_Size_Info
(Def_Id
, T
);
9006 Set_Is_Constrained
(Def_Id
, Constraint_OK
);
9007 Set_Directly_Designated_Type
(Def_Id
, Desig_Subtype
);
9008 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
9009 Set_Is_Access_Constant
(Def_Id
, Is_Access_Constant
(T
));
9011 Conditional_Delay
(Def_Id
, T
);
9013 -- AI-363 : Subtypes of general access types whose designated types have
9014 -- default discriminants are disallowed. In instances, the rule has to
9015 -- be checked against the actual, of which T is the subtype. In a
9016 -- generic body, the rule is checked assuming that the actual type has
9017 -- defaulted discriminants.
9019 if Ada_Version
>= Ada_05
or else Warn_On_Ada_2005_Compatibility
then
9020 if Ekind
(Base_Type
(T
)) = E_General_Access_Type
9021 and then Has_Defaulted_Discriminants
(Desig_Type
)
9023 if Ada_Version
< Ada_05
then
9025 ("access subtype of general access type would not " &
9026 "be allowed in Ada 2005?", S
);
9029 ("access subype of general access type not allowed", S
);
9032 Error_Msg_N
("\discriminants have defaults", S
);
9034 elsif Is_Access_Type
(T
)
9035 and then Is_Generic_Type
(Desig_Type
)
9036 and then Has_Discriminants
(Desig_Type
)
9037 and then In_Package_Body
(Current_Scope
)
9039 if Ada_Version
< Ada_05
then
9041 ("access subtype would not be allowed in generic body " &
9045 ("access subtype not allowed in generic body", S
);
9049 ("\designated type is a discriminated formal", S
);
9052 end Constrain_Access
;
9054 ---------------------
9055 -- Constrain_Array --
9056 ---------------------
9058 procedure Constrain_Array
9059 (Def_Id
: in out Entity_Id
;
9061 Related_Nod
: Node_Id
;
9062 Related_Id
: Entity_Id
;
9065 C
: constant Node_Id
:= Constraint
(SI
);
9066 Number_Of_Constraints
: Nat
:= 0;
9069 Constraint_OK
: Boolean := True;
9072 T
:= Entity
(Subtype_Mark
(SI
));
9074 if Ekind
(T
) in Access_Kind
then
9075 T
:= Designated_Type
(T
);
9078 -- If an index constraint follows a subtype mark in a subtype indication
9079 -- then the type or subtype denoted by the subtype mark must not already
9080 -- impose an index constraint. The subtype mark must denote either an
9081 -- unconstrained array type or an access type whose designated type
9082 -- is such an array type... (RM 3.6.1)
9084 if Is_Constrained
(T
) then
9086 ("array type is already constrained", Subtype_Mark
(SI
));
9087 Constraint_OK
:= False;
9090 S
:= First
(Constraints
(C
));
9091 while Present
(S
) loop
9092 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
9096 -- In either case, the index constraint must provide a discrete
9097 -- range for each index of the array type and the type of each
9098 -- discrete range must be the same as that of the corresponding
9099 -- index. (RM 3.6.1)
9101 if Number_Of_Constraints
/= Number_Dimensions
(T
) then
9102 Error_Msg_NE
("incorrect number of index constraints for }", C
, T
);
9103 Constraint_OK
:= False;
9106 S
:= First
(Constraints
(C
));
9107 Index
:= First_Index
(T
);
9110 -- Apply constraints to each index type
9112 for J
in 1 .. Number_Of_Constraints
loop
9113 Constrain_Index
(Index
, S
, Related_Nod
, Related_Id
, Suffix
, J
);
9123 Create_Itype
(E_Array_Subtype
, Related_Nod
, Related_Id
, Suffix
);
9124 Set_Parent
(Def_Id
, Related_Nod
);
9127 Set_Ekind
(Def_Id
, E_Array_Subtype
);
9130 Set_Size_Info
(Def_Id
, (T
));
9131 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
9132 Set_Etype
(Def_Id
, Base_Type
(T
));
9134 if Constraint_OK
then
9135 Set_First_Index
(Def_Id
, First
(Constraints
(C
)));
9137 Set_First_Index
(Def_Id
, First_Index
(T
));
9140 Set_Is_Constrained
(Def_Id
, True);
9141 Set_Is_Aliased
(Def_Id
, Is_Aliased
(T
));
9142 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
9144 Set_Is_Private_Composite
(Def_Id
, Is_Private_Composite
(T
));
9145 Set_Is_Limited_Composite
(Def_Id
, Is_Limited_Composite
(T
));
9147 -- A subtype does not inherit the packed_array_type of is parent. We
9148 -- need to initialize the attribute because if Def_Id is previously
9149 -- analyzed through a limited_with clause, it will have the attributes
9150 -- of an incomplete type, one of which is an Elist that overlaps the
9151 -- Packed_Array_Type field.
9153 Set_Packed_Array_Type
(Def_Id
, Empty
);
9155 -- Build a freeze node if parent still needs one. Also make sure that
9156 -- the Depends_On_Private status is set because the subtype will need
9157 -- reprocessing at the time the base type does, and also we must set a
9158 -- conditional delay.
9160 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
9161 Conditional_Delay
(Def_Id
, T
);
9162 end Constrain_Array
;
9164 ------------------------------
9165 -- Constrain_Component_Type --
9166 ------------------------------
9168 function Constrain_Component_Type
9170 Constrained_Typ
: Entity_Id
;
9171 Related_Node
: Node_Id
;
9173 Constraints
: Elist_Id
) return Entity_Id
9175 Loc
: constant Source_Ptr
:= Sloc
(Constrained_Typ
);
9176 Compon_Type
: constant Entity_Id
:= Etype
(Comp
);
9178 function Build_Constrained_Array_Type
9179 (Old_Type
: Entity_Id
) return Entity_Id
;
9180 -- If Old_Type is an array type, one of whose indices is constrained
9181 -- by a discriminant, build an Itype whose constraint replaces the
9182 -- discriminant with its value in the constraint.
9184 function Build_Constrained_Discriminated_Type
9185 (Old_Type
: Entity_Id
) return Entity_Id
;
9186 -- Ditto for record components
9188 function Build_Constrained_Access_Type
9189 (Old_Type
: Entity_Id
) return Entity_Id
;
9190 -- Ditto for access types. Makes use of previous two functions, to
9191 -- constrain designated type.
9193 function Build_Subtype
(T
: Entity_Id
; C
: List_Id
) return Entity_Id
;
9194 -- T is an array or discriminated type, C is a list of constraints
9195 -- that apply to T. This routine builds the constrained subtype.
9197 function Is_Discriminant
(Expr
: Node_Id
) return Boolean;
9198 -- Returns True if Expr is a discriminant
9200 function Get_Discr_Value
(Discrim
: Entity_Id
) return Node_Id
;
9201 -- Find the value of discriminant Discrim in Constraint
9203 -----------------------------------
9204 -- Build_Constrained_Access_Type --
9205 -----------------------------------
9207 function Build_Constrained_Access_Type
9208 (Old_Type
: Entity_Id
) return Entity_Id
9210 Desig_Type
: constant Entity_Id
:= Designated_Type
(Old_Type
);
9212 Desig_Subtype
: Entity_Id
;
9216 -- if the original access type was not embedded in the enclosing
9217 -- type definition, there is no need to produce a new access
9218 -- subtype. In fact every access type with an explicit constraint
9219 -- generates an itype whose scope is the enclosing record.
9221 if not Is_Type
(Scope
(Old_Type
)) then
9224 elsif Is_Array_Type
(Desig_Type
) then
9225 Desig_Subtype
:= Build_Constrained_Array_Type
(Desig_Type
);
9227 elsif Has_Discriminants
(Desig_Type
) then
9229 -- This may be an access type to an enclosing record type for
9230 -- which we are constructing the constrained components. Return
9231 -- the enclosing record subtype. This is not always correct,
9232 -- but avoids infinite recursion. ???
9234 Desig_Subtype
:= Any_Type
;
9236 for J
in reverse 0 .. Scope_Stack
.Last
loop
9237 Scop
:= Scope_Stack
.Table
(J
).Entity
;
9240 and then Base_Type
(Scop
) = Base_Type
(Desig_Type
)
9242 Desig_Subtype
:= Scop
;
9245 exit when not Is_Type
(Scop
);
9248 if Desig_Subtype
= Any_Type
then
9250 Build_Constrained_Discriminated_Type
(Desig_Type
);
9257 if Desig_Subtype
/= Desig_Type
then
9259 -- The Related_Node better be here or else we won't be able
9260 -- to attach new itypes to a node in the tree.
9262 pragma Assert
(Present
(Related_Node
));
9264 Itype
:= Create_Itype
(E_Access_Subtype
, Related_Node
);
9266 Set_Etype
(Itype
, Base_Type
(Old_Type
));
9267 Set_Size_Info
(Itype
, (Old_Type
));
9268 Set_Directly_Designated_Type
(Itype
, Desig_Subtype
);
9269 Set_Depends_On_Private
(Itype
, Has_Private_Component
9271 Set_Is_Access_Constant
(Itype
, Is_Access_Constant
9274 -- The new itype needs freezing when it depends on a not frozen
9275 -- type and the enclosing subtype needs freezing.
9277 if Has_Delayed_Freeze
(Constrained_Typ
)
9278 and then not Is_Frozen
(Constrained_Typ
)
9280 Conditional_Delay
(Itype
, Base_Type
(Old_Type
));
9288 end Build_Constrained_Access_Type
;
9290 ----------------------------------
9291 -- Build_Constrained_Array_Type --
9292 ----------------------------------
9294 function Build_Constrained_Array_Type
9295 (Old_Type
: Entity_Id
) return Entity_Id
9299 Old_Index
: Node_Id
;
9300 Range_Node
: Node_Id
;
9301 Constr_List
: List_Id
;
9303 Need_To_Create_Itype
: Boolean := False;
9306 Old_Index
:= First_Index
(Old_Type
);
9307 while Present
(Old_Index
) loop
9308 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
9310 if Is_Discriminant
(Lo_Expr
)
9311 or else Is_Discriminant
(Hi_Expr
)
9313 Need_To_Create_Itype
:= True;
9316 Next_Index
(Old_Index
);
9319 if Need_To_Create_Itype
then
9320 Constr_List
:= New_List
;
9322 Old_Index
:= First_Index
(Old_Type
);
9323 while Present
(Old_Index
) loop
9324 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
9326 if Is_Discriminant
(Lo_Expr
) then
9327 Lo_Expr
:= Get_Discr_Value
(Lo_Expr
);
9330 if Is_Discriminant
(Hi_Expr
) then
9331 Hi_Expr
:= Get_Discr_Value
(Hi_Expr
);
9336 (Loc
, New_Copy_Tree
(Lo_Expr
), New_Copy_Tree
(Hi_Expr
));
9338 Append
(Range_Node
, To
=> Constr_List
);
9340 Next_Index
(Old_Index
);
9343 return Build_Subtype
(Old_Type
, Constr_List
);
9348 end Build_Constrained_Array_Type
;
9350 ------------------------------------------
9351 -- Build_Constrained_Discriminated_Type --
9352 ------------------------------------------
9354 function Build_Constrained_Discriminated_Type
9355 (Old_Type
: Entity_Id
) return Entity_Id
9358 Constr_List
: List_Id
;
9359 Old_Constraint
: Elmt_Id
;
9361 Need_To_Create_Itype
: Boolean := False;
9364 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
9365 while Present
(Old_Constraint
) loop
9366 Expr
:= Node
(Old_Constraint
);
9368 if Is_Discriminant
(Expr
) then
9369 Need_To_Create_Itype
:= True;
9372 Next_Elmt
(Old_Constraint
);
9375 if Need_To_Create_Itype
then
9376 Constr_List
:= New_List
;
9378 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
9379 while Present
(Old_Constraint
) loop
9380 Expr
:= Node
(Old_Constraint
);
9382 if Is_Discriminant
(Expr
) then
9383 Expr
:= Get_Discr_Value
(Expr
);
9386 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
9388 Next_Elmt
(Old_Constraint
);
9391 return Build_Subtype
(Old_Type
, Constr_List
);
9396 end Build_Constrained_Discriminated_Type
;
9402 function Build_Subtype
(T
: Entity_Id
; C
: List_Id
) return Entity_Id
is
9404 Subtyp_Decl
: Node_Id
;
9406 Btyp
: Entity_Id
:= Base_Type
(T
);
9409 -- The Related_Node better be here or else we won't be able to
9410 -- attach new itypes to a node in the tree.
9412 pragma Assert
(Present
(Related_Node
));
9414 -- If the view of the component's type is incomplete or private
9415 -- with unknown discriminants, then the constraint must be applied
9416 -- to the full type.
9418 if Has_Unknown_Discriminants
(Btyp
)
9419 and then Present
(Underlying_Type
(Btyp
))
9421 Btyp
:= Underlying_Type
(Btyp
);
9425 Make_Subtype_Indication
(Loc
,
9426 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
9427 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
, C
));
9429 Def_Id
:= Create_Itype
(Ekind
(T
), Related_Node
);
9432 Make_Subtype_Declaration
(Loc
,
9433 Defining_Identifier
=> Def_Id
,
9434 Subtype_Indication
=> Indic
);
9436 Set_Parent
(Subtyp_Decl
, Parent
(Related_Node
));
9438 -- Itypes must be analyzed with checks off (see package Itypes)
9440 Analyze
(Subtyp_Decl
, Suppress
=> All_Checks
);
9445 ---------------------
9446 -- Get_Discr_Value --
9447 ---------------------
9449 function Get_Discr_Value
(Discrim
: Entity_Id
) return Node_Id
is
9455 -- The discriminant may be declared for the type, in which case we
9456 -- find it by iterating over the list of discriminants. If the
9457 -- discriminant is inherited from a parent type, it appears as the
9458 -- corresponding discriminant of the current type. This will be the
9459 -- case when constraining an inherited component whose constraint is
9460 -- given by a discriminant of the parent.
9462 D
:= First_Discriminant
(Typ
);
9463 E
:= First_Elmt
(Constraints
);
9465 while Present
(D
) loop
9466 if D
= Entity
(Discrim
)
9467 or else D
= CR_Discriminant
(Entity
(Discrim
))
9468 or else Corresponding_Discriminant
(D
) = Entity
(Discrim
)
9473 Next_Discriminant
(D
);
9477 -- The corresponding_Discriminant mechanism is incomplete, because
9478 -- the correspondence between new and old discriminants is not one
9479 -- to one: one new discriminant can constrain several old ones. In
9480 -- that case, scan sequentially the stored_constraint, the list of
9481 -- discriminants of the parents, and the constraints.
9483 if Is_Derived_Type
(Typ
)
9484 and then Present
(Stored_Constraint
(Typ
))
9485 and then Scope
(Entity
(Discrim
)) = Etype
(Typ
)
9487 D
:= First_Discriminant
(Etype
(Typ
));
9488 E
:= First_Elmt
(Constraints
);
9489 G
:= First_Elmt
(Stored_Constraint
(Typ
));
9490 while Present
(D
) loop
9491 if D
= Entity
(Discrim
) then
9495 Next_Discriminant
(D
);
9501 -- Something is wrong if we did not find the value
9503 raise Program_Error
;
9504 end Get_Discr_Value
;
9506 ---------------------
9507 -- Is_Discriminant --
9508 ---------------------
9510 function Is_Discriminant
(Expr
: Node_Id
) return Boolean is
9511 Discrim_Scope
: Entity_Id
;
9514 if Denotes_Discriminant
(Expr
) then
9515 Discrim_Scope
:= Scope
(Entity
(Expr
));
9517 -- Either we have a reference to one of Typ's discriminants,
9519 pragma Assert
(Discrim_Scope
= Typ
9521 -- or to the discriminants of the parent type, in the case
9522 -- of a derivation of a tagged type with variants.
9524 or else Discrim_Scope
= Etype
(Typ
)
9525 or else Full_View
(Discrim_Scope
) = Etype
(Typ
)
9527 -- or same as above for the case where the discriminants
9528 -- were declared in Typ's private view.
9530 or else (Is_Private_Type
(Discrim_Scope
)
9531 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
9533 -- or else we are deriving from the full view and the
9534 -- discriminant is declared in the private entity.
9536 or else (Is_Private_Type
(Typ
)
9537 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
9539 -- Or we are constrained the corresponding record of a
9540 -- synchronized type that completes a private declaration.
9542 or else (Is_Concurrent_Record_Type
(Typ
)
9544 Corresponding_Concurrent_Type
(Typ
) = Discrim_Scope
)
9546 -- or we have a class-wide type, in which case make sure the
9547 -- discriminant found belongs to the root type.
9549 or else (Is_Class_Wide_Type
(Typ
)
9550 and then Etype
(Typ
) = Discrim_Scope
));
9555 -- In all other cases we have something wrong
9558 end Is_Discriminant
;
9560 -- Start of processing for Constrain_Component_Type
9563 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
9564 and then Comes_From_Source
(Parent
(Comp
))
9565 and then Comes_From_Source
9566 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
9569 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
9573 elsif Is_Array_Type
(Compon_Type
) then
9574 return Build_Constrained_Array_Type
(Compon_Type
);
9576 elsif Has_Discriminants
(Compon_Type
) then
9577 return Build_Constrained_Discriminated_Type
(Compon_Type
);
9579 elsif Is_Access_Type
(Compon_Type
) then
9580 return Build_Constrained_Access_Type
(Compon_Type
);
9585 end Constrain_Component_Type
;
9587 --------------------------
9588 -- Constrain_Concurrent --
9589 --------------------------
9591 -- For concurrent types, the associated record value type carries the same
9592 -- discriminants, so when we constrain a concurrent type, we must constrain
9593 -- the corresponding record type as well.
9595 procedure Constrain_Concurrent
9596 (Def_Id
: in out Entity_Id
;
9598 Related_Nod
: Node_Id
;
9599 Related_Id
: Entity_Id
;
9602 T_Ent
: Entity_Id
:= Entity
(Subtype_Mark
(SI
));
9606 if Ekind
(T_Ent
) in Access_Kind
then
9607 T_Ent
:= Designated_Type
(T_Ent
);
9610 T_Val
:= Corresponding_Record_Type
(T_Ent
);
9612 if Present
(T_Val
) then
9615 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
9618 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
9620 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
9621 Set_Corresponding_Record_Type
(Def_Id
,
9622 Constrain_Corresponding_Record
9623 (Def_Id
, T_Val
, Related_Nod
, Related_Id
));
9626 -- If there is no associated record, expansion is disabled and this
9627 -- is a generic context. Create a subtype in any case, so that
9628 -- semantic analysis can proceed.
9631 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
9634 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
9636 end Constrain_Concurrent
;
9638 ------------------------------------
9639 -- Constrain_Corresponding_Record --
9640 ------------------------------------
9642 function Constrain_Corresponding_Record
9643 (Prot_Subt
: Entity_Id
;
9644 Corr_Rec
: Entity_Id
;
9645 Related_Nod
: Node_Id
;
9646 Related_Id
: Entity_Id
) return Entity_Id
9648 T_Sub
: constant Entity_Id
:=
9649 Create_Itype
(E_Record_Subtype
, Related_Nod
, Related_Id
, 'V');
9652 Set_Etype
(T_Sub
, Corr_Rec
);
9653 Init_Size_Align
(T_Sub
);
9654 Set_Has_Discriminants
(T_Sub
, Has_Discriminants
(Prot_Subt
));
9655 Set_Is_Constrained
(T_Sub
, True);
9656 Set_First_Entity
(T_Sub
, First_Entity
(Corr_Rec
));
9657 Set_Last_Entity
(T_Sub
, Last_Entity
(Corr_Rec
));
9659 -- As elsewhere, we do not want to create a freeze node for this itype
9660 -- if it is created for a constrained component of an enclosing record
9661 -- because references to outer discriminants will appear out of scope.
9663 if Ekind
(Scope
(Prot_Subt
)) /= E_Record_Type
then
9664 Conditional_Delay
(T_Sub
, Corr_Rec
);
9666 Set_Is_Frozen
(T_Sub
);
9669 if Has_Discriminants
(Prot_Subt
) then -- False only if errors.
9670 Set_Discriminant_Constraint
9671 (T_Sub
, Discriminant_Constraint
(Prot_Subt
));
9672 Set_Stored_Constraint_From_Discriminant_Constraint
(T_Sub
);
9673 Create_Constrained_Components
9674 (T_Sub
, Related_Nod
, Corr_Rec
, Discriminant_Constraint
(T_Sub
));
9677 Set_Depends_On_Private
(T_Sub
, Has_Private_Component
(T_Sub
));
9680 end Constrain_Corresponding_Record
;
9682 -----------------------
9683 -- Constrain_Decimal --
9684 -----------------------
9686 procedure Constrain_Decimal
(Def_Id
: Node_Id
; S
: Node_Id
) is
9687 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
9688 C
: constant Node_Id
:= Constraint
(S
);
9689 Loc
: constant Source_Ptr
:= Sloc
(C
);
9690 Range_Expr
: Node_Id
;
9691 Digits_Expr
: Node_Id
;
9696 Set_Ekind
(Def_Id
, E_Decimal_Fixed_Point_Subtype
);
9698 if Nkind
(C
) = N_Range_Constraint
then
9699 Range_Expr
:= Range_Expression
(C
);
9700 Digits_Val
:= Digits_Value
(T
);
9703 pragma Assert
(Nkind
(C
) = N_Digits_Constraint
);
9704 Digits_Expr
:= Digits_Expression
(C
);
9705 Analyze_And_Resolve
(Digits_Expr
, Any_Integer
);
9707 Check_Digits_Expression
(Digits_Expr
);
9708 Digits_Val
:= Expr_Value
(Digits_Expr
);
9710 if Digits_Val
> Digits_Value
(T
) then
9712 ("digits expression is incompatible with subtype", C
);
9713 Digits_Val
:= Digits_Value
(T
);
9716 if Present
(Range_Constraint
(C
)) then
9717 Range_Expr
:= Range_Expression
(Range_Constraint
(C
));
9719 Range_Expr
:= Empty
;
9723 Set_Etype
(Def_Id
, Base_Type
(T
));
9724 Set_Size_Info
(Def_Id
, (T
));
9725 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
9726 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
9727 Set_Scale_Value
(Def_Id
, Scale_Value
(T
));
9728 Set_Small_Value
(Def_Id
, Small_Value
(T
));
9729 Set_Machine_Radix_10
(Def_Id
, Machine_Radix_10
(T
));
9730 Set_Digits_Value
(Def_Id
, Digits_Val
);
9732 -- Manufacture range from given digits value if no range present
9734 if No
(Range_Expr
) then
9735 Bound_Val
:= (Ureal_10
** Digits_Val
- Ureal_1
) * Small_Value
(T
);
9739 Convert_To
(T
, Make_Real_Literal
(Loc
, (-Bound_Val
))),
9741 Convert_To
(T
, Make_Real_Literal
(Loc
, Bound_Val
)));
9744 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expr
, T
);
9745 Set_Discrete_RM_Size
(Def_Id
);
9747 -- Unconditionally delay the freeze, since we cannot set size
9748 -- information in all cases correctly until the freeze point.
9750 Set_Has_Delayed_Freeze
(Def_Id
);
9751 end Constrain_Decimal
;
9753 ----------------------------------
9754 -- Constrain_Discriminated_Type --
9755 ----------------------------------
9757 procedure Constrain_Discriminated_Type
9758 (Def_Id
: Entity_Id
;
9760 Related_Nod
: Node_Id
;
9761 For_Access
: Boolean := False)
9763 E
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
9766 Elist
: Elist_Id
:= New_Elmt_List
;
9768 procedure Fixup_Bad_Constraint
;
9769 -- This is called after finding a bad constraint, and after having
9770 -- posted an appropriate error message. The mission is to leave the
9771 -- entity T in as reasonable state as possible!
9773 --------------------------
9774 -- Fixup_Bad_Constraint --
9775 --------------------------
9777 procedure Fixup_Bad_Constraint
is
9779 -- Set a reasonable Ekind for the entity. For an incomplete type,
9780 -- we can't do much, but for other types, we can set the proper
9781 -- corresponding subtype kind.
9783 if Ekind
(T
) = E_Incomplete_Type
then
9784 Set_Ekind
(Def_Id
, Ekind
(T
));
9786 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
9789 Set_Etype
(Def_Id
, Any_Type
);
9790 Set_Error_Posted
(Def_Id
);
9791 end Fixup_Bad_Constraint
;
9793 -- Start of processing for Constrain_Discriminated_Type
9796 C
:= Constraint
(S
);
9798 -- A discriminant constraint is only allowed in a subtype indication,
9799 -- after a subtype mark. This subtype mark must denote either a type
9800 -- with discriminants, or an access type whose designated type is a
9801 -- type with discriminants. A discriminant constraint specifies the
9802 -- values of these discriminants (RM 3.7.2(5)).
9804 T
:= Base_Type
(Entity
(Subtype_Mark
(S
)));
9806 if Ekind
(T
) in Access_Kind
then
9807 T
:= Designated_Type
(T
);
9810 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal.
9811 -- Avoid generating an error for access-to-incomplete subtypes.
9813 if Ada_Version
>= Ada_05
9814 and then Ekind
(T
) = E_Incomplete_Type
9815 and then Nkind
(Parent
(S
)) = N_Subtype_Declaration
9816 and then not Is_Itype
(Def_Id
)
9818 -- A little sanity check, emit an error message if the type
9819 -- has discriminants to begin with. Type T may be a regular
9820 -- incomplete type or imported via a limited with clause.
9822 if Has_Discriminants
(T
)
9825 and then Present
(Non_Limited_View
(T
))
9826 and then Nkind
(Parent
(Non_Limited_View
(T
))) =
9827 N_Full_Type_Declaration
9828 and then Present
(Discriminant_Specifications
9829 (Parent
(Non_Limited_View
(T
)))))
9832 ("(Ada 2005) incomplete subtype may not be constrained", C
);
9835 ("invalid constraint: type has no discriminant", C
);
9838 Fixup_Bad_Constraint
;
9841 -- Check that the type has visible discriminants. The type may be
9842 -- a private type with unknown discriminants whose full view has
9843 -- discriminants which are invisible.
9845 elsif not Has_Discriminants
(T
)
9847 (Has_Unknown_Discriminants
(T
)
9848 and then Is_Private_Type
(T
))
9850 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
9851 Fixup_Bad_Constraint
;
9854 elsif Is_Constrained
(E
)
9855 or else (Ekind
(E
) = E_Class_Wide_Subtype
9856 and then Present
(Discriminant_Constraint
(E
)))
9858 Error_Msg_N
("type is already constrained", Subtype_Mark
(S
));
9859 Fixup_Bad_Constraint
;
9863 -- T may be an unconstrained subtype (e.g. a generic actual).
9864 -- Constraint applies to the base type.
9868 Elist
:= Build_Discriminant_Constraints
(T
, S
);
9870 -- If the list returned was empty we had an error in building the
9871 -- discriminant constraint. We have also already signalled an error
9872 -- in the incomplete type case
9874 if Is_Empty_Elmt_List
(Elist
) then
9875 Fixup_Bad_Constraint
;
9879 Build_Discriminated_Subtype
(T
, Def_Id
, Elist
, Related_Nod
, For_Access
);
9880 end Constrain_Discriminated_Type
;
9882 ---------------------------
9883 -- Constrain_Enumeration --
9884 ---------------------------
9886 procedure Constrain_Enumeration
(Def_Id
: Node_Id
; S
: Node_Id
) is
9887 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
9888 C
: constant Node_Id
:= Constraint
(S
);
9891 Set_Ekind
(Def_Id
, E_Enumeration_Subtype
);
9893 Set_First_Literal
(Def_Id
, First_Literal
(Base_Type
(T
)));
9895 Set_Etype
(Def_Id
, Base_Type
(T
));
9896 Set_Size_Info
(Def_Id
, (T
));
9897 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
9898 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
9900 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
9902 Set_Discrete_RM_Size
(Def_Id
);
9903 end Constrain_Enumeration
;
9905 ----------------------
9906 -- Constrain_Float --
9907 ----------------------
9909 procedure Constrain_Float
(Def_Id
: Node_Id
; S
: Node_Id
) is
9910 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
9916 Set_Ekind
(Def_Id
, E_Floating_Point_Subtype
);
9918 Set_Etype
(Def_Id
, Base_Type
(T
));
9919 Set_Size_Info
(Def_Id
, (T
));
9920 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
9922 -- Process the constraint
9924 C
:= Constraint
(S
);
9926 -- Digits constraint present
9928 if Nkind
(C
) = N_Digits_Constraint
then
9929 Check_Restriction
(No_Obsolescent_Features
, C
);
9931 if Warn_On_Obsolescent_Feature
then
9933 ("subtype digits constraint is an " &
9934 "obsolescent feature (RM J.3(8))?", C
);
9937 D
:= Digits_Expression
(C
);
9938 Analyze_And_Resolve
(D
, Any_Integer
);
9939 Check_Digits_Expression
(D
);
9940 Set_Digits_Value
(Def_Id
, Expr_Value
(D
));
9942 -- Check that digits value is in range. Obviously we can do this
9943 -- at compile time, but it is strictly a runtime check, and of
9944 -- course there is an ACVC test that checks this!
9946 if Digits_Value
(Def_Id
) > Digits_Value
(T
) then
9947 Error_Msg_Uint_1
:= Digits_Value
(T
);
9948 Error_Msg_N
("?digits value is too large, maximum is ^", D
);
9950 Make_Raise_Constraint_Error
(Sloc
(D
),
9951 Reason
=> CE_Range_Check_Failed
);
9952 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
9955 C
:= Range_Constraint
(C
);
9957 -- No digits constraint present
9960 Set_Digits_Value
(Def_Id
, Digits_Value
(T
));
9963 -- Range constraint present
9965 if Nkind
(C
) = N_Range_Constraint
then
9966 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
9968 -- No range constraint present
9971 pragma Assert
(No
(C
));
9972 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
9975 Set_Is_Constrained
(Def_Id
);
9976 end Constrain_Float
;
9978 ---------------------
9979 -- Constrain_Index --
9980 ---------------------
9982 procedure Constrain_Index
9985 Related_Nod
: Node_Id
;
9986 Related_Id
: Entity_Id
;
9991 R
: Node_Id
:= Empty
;
9992 T
: constant Entity_Id
:= Etype
(Index
);
9995 if Nkind
(S
) = N_Range
9997 (Nkind
(S
) = N_Attribute_Reference
9998 and then Attribute_Name
(S
) = Name_Range
)
10000 -- A Range attribute will transformed into N_Range by Resolve
10006 Process_Range_Expr_In_Decl
(R
, T
, Empty_List
);
10008 if not Error_Posted
(S
)
10010 (Nkind
(S
) /= N_Range
10011 or else not Covers
(T
, (Etype
(Low_Bound
(S
))))
10012 or else not Covers
(T
, (Etype
(High_Bound
(S
)))))
10014 if Base_Type
(T
) /= Any_Type
10015 and then Etype
(Low_Bound
(S
)) /= Any_Type
10016 and then Etype
(High_Bound
(S
)) /= Any_Type
10018 Error_Msg_N
("range expected", S
);
10022 elsif Nkind
(S
) = N_Subtype_Indication
then
10024 -- The parser has verified that this is a discrete indication
10026 Resolve_Discrete_Subtype_Indication
(S
, T
);
10027 R
:= Range_Expression
(Constraint
(S
));
10029 elsif Nkind
(S
) = N_Discriminant_Association
then
10031 -- Syntactically valid in subtype indication
10033 Error_Msg_N
("invalid index constraint", S
);
10034 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
10037 -- Subtype_Mark case, no anonymous subtypes to construct
10042 if Is_Entity_Name
(S
) then
10043 if not Is_Type
(Entity
(S
)) then
10044 Error_Msg_N
("expect subtype mark for index constraint", S
);
10046 elsif Base_Type
(Entity
(S
)) /= Base_Type
(T
) then
10047 Wrong_Type
(S
, Base_Type
(T
));
10053 Error_Msg_N
("invalid index constraint", S
);
10054 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
10060 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
, Suffix_Index
);
10062 Set_Etype
(Def_Id
, Base_Type
(T
));
10064 if Is_Modular_Integer_Type
(T
) then
10065 Set_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
10067 elsif Is_Integer_Type
(T
) then
10068 Set_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
10071 Set_Ekind
(Def_Id
, E_Enumeration_Subtype
);
10072 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
10075 Set_Size_Info
(Def_Id
, (T
));
10076 Set_RM_Size
(Def_Id
, RM_Size
(T
));
10077 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
10079 Set_Scalar_Range
(Def_Id
, R
);
10081 Set_Etype
(S
, Def_Id
);
10082 Set_Discrete_RM_Size
(Def_Id
);
10083 end Constrain_Index
;
10085 -----------------------
10086 -- Constrain_Integer --
10087 -----------------------
10089 procedure Constrain_Integer
(Def_Id
: Node_Id
; S
: Node_Id
) is
10090 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
10091 C
: constant Node_Id
:= Constraint
(S
);
10094 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
10096 if Is_Modular_Integer_Type
(T
) then
10097 Set_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
10099 Set_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
10102 Set_Etype
(Def_Id
, Base_Type
(T
));
10103 Set_Size_Info
(Def_Id
, (T
));
10104 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
10105 Set_Discrete_RM_Size
(Def_Id
);
10106 end Constrain_Integer
;
10108 ------------------------------
10109 -- Constrain_Ordinary_Fixed --
10110 ------------------------------
10112 procedure Constrain_Ordinary_Fixed
(Def_Id
: Node_Id
; S
: Node_Id
) is
10113 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
10119 Set_Ekind
(Def_Id
, E_Ordinary_Fixed_Point_Subtype
);
10120 Set_Etype
(Def_Id
, Base_Type
(T
));
10121 Set_Size_Info
(Def_Id
, (T
));
10122 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
10123 Set_Small_Value
(Def_Id
, Small_Value
(T
));
10125 -- Process the constraint
10127 C
:= Constraint
(S
);
10129 -- Delta constraint present
10131 if Nkind
(C
) = N_Delta_Constraint
then
10132 Check_Restriction
(No_Obsolescent_Features
, C
);
10134 if Warn_On_Obsolescent_Feature
then
10136 ("subtype delta constraint is an " &
10137 "obsolescent feature (RM J.3(7))?");
10140 D
:= Delta_Expression
(C
);
10141 Analyze_And_Resolve
(D
, Any_Real
);
10142 Check_Delta_Expression
(D
);
10143 Set_Delta_Value
(Def_Id
, Expr_Value_R
(D
));
10145 -- Check that delta value is in range. Obviously we can do this
10146 -- at compile time, but it is strictly a runtime check, and of
10147 -- course there is an ACVC test that checks this!
10149 if Delta_Value
(Def_Id
) < Delta_Value
(T
) then
10150 Error_Msg_N
("?delta value is too small", D
);
10152 Make_Raise_Constraint_Error
(Sloc
(D
),
10153 Reason
=> CE_Range_Check_Failed
);
10154 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
10157 C
:= Range_Constraint
(C
);
10159 -- No delta constraint present
10162 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
10165 -- Range constraint present
10167 if Nkind
(C
) = N_Range_Constraint
then
10168 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
10170 -- No range constraint present
10173 pragma Assert
(No
(C
));
10174 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
10178 Set_Discrete_RM_Size
(Def_Id
);
10180 -- Unconditionally delay the freeze, since we cannot set size
10181 -- information in all cases correctly until the freeze point.
10183 Set_Has_Delayed_Freeze
(Def_Id
);
10184 end Constrain_Ordinary_Fixed
;
10186 -----------------------
10187 -- Contain_Interface --
10188 -----------------------
10190 function Contain_Interface
10191 (Iface
: Entity_Id
;
10192 Ifaces
: Elist_Id
) return Boolean
10194 Iface_Elmt
: Elmt_Id
;
10197 if Present
(Ifaces
) then
10198 Iface_Elmt
:= First_Elmt
(Ifaces
);
10199 while Present
(Iface_Elmt
) loop
10200 if Node
(Iface_Elmt
) = Iface
then
10204 Next_Elmt
(Iface_Elmt
);
10209 end Contain_Interface
;
10211 ---------------------------
10212 -- Convert_Scalar_Bounds --
10213 ---------------------------
10215 procedure Convert_Scalar_Bounds
10217 Parent_Type
: Entity_Id
;
10218 Derived_Type
: Entity_Id
;
10221 Implicit_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
10228 Lo
:= Build_Scalar_Bound
10229 (Type_Low_Bound
(Derived_Type
),
10230 Parent_Type
, Implicit_Base
);
10232 Hi
:= Build_Scalar_Bound
10233 (Type_High_Bound
(Derived_Type
),
10234 Parent_Type
, Implicit_Base
);
10241 Set_Includes_Infinities
(Rng
, Has_Infinities
(Derived_Type
));
10243 Set_Parent
(Rng
, N
);
10244 Set_Scalar_Range
(Derived_Type
, Rng
);
10246 -- Analyze the bounds
10248 Analyze_And_Resolve
(Lo
, Implicit_Base
);
10249 Analyze_And_Resolve
(Hi
, Implicit_Base
);
10251 -- Analyze the range itself, except that we do not analyze it if
10252 -- the bounds are real literals, and we have a fixed-point type.
10253 -- The reason for this is that we delay setting the bounds in this
10254 -- case till we know the final Small and Size values (see circuit
10255 -- in Freeze.Freeze_Fixed_Point_Type for further details).
10257 if Is_Fixed_Point_Type
(Parent_Type
)
10258 and then Nkind
(Lo
) = N_Real_Literal
10259 and then Nkind
(Hi
) = N_Real_Literal
10263 -- Here we do the analysis of the range
10265 -- Note: we do this manually, since if we do a normal Analyze and
10266 -- Resolve call, there are problems with the conversions used for
10267 -- the derived type range.
10270 Set_Etype
(Rng
, Implicit_Base
);
10271 Set_Analyzed
(Rng
, True);
10273 end Convert_Scalar_Bounds
;
10275 -------------------
10276 -- Copy_And_Swap --
10277 -------------------
10279 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
) is
10281 -- Initialize new full declaration entity by copying the pertinent
10282 -- fields of the corresponding private declaration entity.
10284 -- We temporarily set Ekind to a value appropriate for a type to
10285 -- avoid assert failures in Einfo from checking for setting type
10286 -- attributes on something that is not a type. Ekind (Priv) is an
10287 -- appropriate choice, since it allowed the attributes to be set
10288 -- in the first place. This Ekind value will be modified later.
10290 Set_Ekind
(Full
, Ekind
(Priv
));
10292 -- Also set Etype temporarily to Any_Type, again, in the absence
10293 -- of errors, it will be properly reset, and if there are errors,
10294 -- then we want a value of Any_Type to remain.
10296 Set_Etype
(Full
, Any_Type
);
10298 -- Now start copying attributes
10300 Set_Has_Discriminants
(Full
, Has_Discriminants
(Priv
));
10302 if Has_Discriminants
(Full
) then
10303 Set_Discriminant_Constraint
(Full
, Discriminant_Constraint
(Priv
));
10304 Set_Stored_Constraint
(Full
, Stored_Constraint
(Priv
));
10307 Set_First_Rep_Item
(Full
, First_Rep_Item
(Priv
));
10308 Set_Homonym
(Full
, Homonym
(Priv
));
10309 Set_Is_Immediately_Visible
(Full
, Is_Immediately_Visible
(Priv
));
10310 Set_Is_Public
(Full
, Is_Public
(Priv
));
10311 Set_Is_Pure
(Full
, Is_Pure
(Priv
));
10312 Set_Is_Tagged_Type
(Full
, Is_Tagged_Type
(Priv
));
10313 Set_Has_Pragma_Unreferenced
(Full
, Has_Pragma_Unreferenced
(Priv
));
10314 Set_Has_Pragma_Unreferenced_Objects
10315 (Full
, Has_Pragma_Unreferenced_Objects
10318 Conditional_Delay
(Full
, Priv
);
10320 if Is_Tagged_Type
(Full
) then
10321 Set_Primitive_Operations
(Full
, Primitive_Operations
(Priv
));
10323 if Priv
= Base_Type
(Priv
) then
10324 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Priv
));
10328 Set_Is_Volatile
(Full
, Is_Volatile
(Priv
));
10329 Set_Treat_As_Volatile
(Full
, Treat_As_Volatile
(Priv
));
10330 Set_Scope
(Full
, Scope
(Priv
));
10331 Set_Next_Entity
(Full
, Next_Entity
(Priv
));
10332 Set_First_Entity
(Full
, First_Entity
(Priv
));
10333 Set_Last_Entity
(Full
, Last_Entity
(Priv
));
10335 -- If access types have been recorded for later handling, keep them in
10336 -- the full view so that they get handled when the full view freeze
10337 -- node is expanded.
10339 if Present
(Freeze_Node
(Priv
))
10340 and then Present
(Access_Types_To_Process
(Freeze_Node
(Priv
)))
10342 Ensure_Freeze_Node
(Full
);
10343 Set_Access_Types_To_Process
10344 (Freeze_Node
(Full
),
10345 Access_Types_To_Process
(Freeze_Node
(Priv
)));
10348 -- Swap the two entities. Now Privat is the full type entity and
10349 -- Full is the private one. They will be swapped back at the end
10350 -- of the private part. This swapping ensures that the entity that
10351 -- is visible in the private part is the full declaration.
10353 Exchange_Entities
(Priv
, Full
);
10354 Append_Entity
(Full
, Scope
(Full
));
10357 -------------------------------------
10358 -- Copy_Array_Base_Type_Attributes --
10359 -------------------------------------
10361 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
) is
10363 Set_Component_Alignment
(T1
, Component_Alignment
(T2
));
10364 Set_Component_Type
(T1
, Component_Type
(T2
));
10365 Set_Component_Size
(T1
, Component_Size
(T2
));
10366 Set_Has_Controlled_Component
(T1
, Has_Controlled_Component
(T2
));
10367 Set_Finalize_Storage_Only
(T1
, Finalize_Storage_Only
(T2
));
10368 Set_Has_Non_Standard_Rep
(T1
, Has_Non_Standard_Rep
(T2
));
10369 Set_Has_Task
(T1
, Has_Task
(T2
));
10370 Set_Is_Packed
(T1
, Is_Packed
(T2
));
10371 Set_Has_Aliased_Components
(T1
, Has_Aliased_Components
(T2
));
10372 Set_Has_Atomic_Components
(T1
, Has_Atomic_Components
(T2
));
10373 Set_Has_Volatile_Components
(T1
, Has_Volatile_Components
(T2
));
10374 end Copy_Array_Base_Type_Attributes
;
10376 -----------------------------------
10377 -- Copy_Array_Subtype_Attributes --
10378 -----------------------------------
10380 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
) is
10382 Set_Size_Info
(T1
, T2
);
10384 Set_First_Index
(T1
, First_Index
(T2
));
10385 Set_Is_Aliased
(T1
, Is_Aliased
(T2
));
10386 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
10387 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
10388 Set_Treat_As_Volatile
(T1
, Treat_As_Volatile
(T2
));
10389 Set_Is_Constrained
(T1
, Is_Constrained
(T2
));
10390 Set_Depends_On_Private
(T1
, Has_Private_Component
(T2
));
10391 Set_First_Rep_Item
(T1
, First_Rep_Item
(T2
));
10392 Set_Convention
(T1
, Convention
(T2
));
10393 Set_Is_Limited_Composite
(T1
, Is_Limited_Composite
(T2
));
10394 Set_Is_Private_Composite
(T1
, Is_Private_Composite
(T2
));
10395 end Copy_Array_Subtype_Attributes
;
10397 -----------------------------------
10398 -- Create_Constrained_Components --
10399 -----------------------------------
10401 procedure Create_Constrained_Components
10403 Decl_Node
: Node_Id
;
10405 Constraints
: Elist_Id
)
10407 Loc
: constant Source_Ptr
:= Sloc
(Subt
);
10408 Comp_List
: constant Elist_Id
:= New_Elmt_List
;
10409 Parent_Type
: constant Entity_Id
:= Etype
(Typ
);
10410 Assoc_List
: constant List_Id
:= New_List
;
10411 Discr_Val
: Elmt_Id
;
10415 Is_Static
: Boolean := True;
10417 procedure Collect_Fixed_Components
(Typ
: Entity_Id
);
10418 -- Collect parent type components that do not appear in a variant part
10420 procedure Create_All_Components
;
10421 -- Iterate over Comp_List to create the components of the subtype
10423 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
;
10424 -- Creates a new component from Old_Compon, copying all the fields from
10425 -- it, including its Etype, inserts the new component in the Subt entity
10426 -- chain and returns the new component.
10428 function Is_Variant_Record
(T
: Entity_Id
) return Boolean;
10429 -- If true, and discriminants are static, collect only components from
10430 -- variants selected by discriminant values.
10432 ------------------------------
10433 -- Collect_Fixed_Components --
10434 ------------------------------
10436 procedure Collect_Fixed_Components
(Typ
: Entity_Id
) is
10438 -- Build association list for discriminants, and find components of the
10439 -- variant part selected by the values of the discriminants.
10441 Old_C
:= First_Discriminant
(Typ
);
10442 Discr_Val
:= First_Elmt
(Constraints
);
10443 while Present
(Old_C
) loop
10444 Append_To
(Assoc_List
,
10445 Make_Component_Association
(Loc
,
10446 Choices
=> New_List
(New_Occurrence_Of
(Old_C
, Loc
)),
10447 Expression
=> New_Copy
(Node
(Discr_Val
))));
10449 Next_Elmt
(Discr_Val
);
10450 Next_Discriminant
(Old_C
);
10453 -- The tag, and the possible parent and controller components
10454 -- are unconditionally in the subtype.
10456 if Is_Tagged_Type
(Typ
)
10457 or else Has_Controlled_Component
(Typ
)
10459 Old_C
:= First_Component
(Typ
);
10460 while Present
(Old_C
) loop
10461 if Chars
((Old_C
)) = Name_uTag
10462 or else Chars
((Old_C
)) = Name_uParent
10463 or else Chars
((Old_C
)) = Name_uController
10465 Append_Elmt
(Old_C
, Comp_List
);
10468 Next_Component
(Old_C
);
10471 end Collect_Fixed_Components
;
10473 ---------------------------
10474 -- Create_All_Components --
10475 ---------------------------
10477 procedure Create_All_Components
is
10481 Comp
:= First_Elmt
(Comp_List
);
10482 while Present
(Comp
) loop
10483 Old_C
:= Node
(Comp
);
10484 New_C
:= Create_Component
(Old_C
);
10488 Constrain_Component_Type
10489 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
10490 Set_Is_Public
(New_C
, Is_Public
(Subt
));
10494 end Create_All_Components
;
10496 ----------------------
10497 -- Create_Component --
10498 ----------------------
10500 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
is
10501 New_Compon
: constant Entity_Id
:= New_Copy
(Old_Compon
);
10504 if Ekind
(Old_Compon
) = E_Discriminant
10505 and then Is_Completely_Hidden
(Old_Compon
)
10507 -- This is a shadow discriminant created for a discriminant of
10508 -- the parent type that is one of several renamed by the same
10509 -- new discriminant. Give the shadow discriminant an internal
10510 -- name that cannot conflict with that of visible components.
10512 Set_Chars
(New_Compon
, New_Internal_Name
('C'));
10515 -- Set the parent so we have a proper link for freezing etc. This is
10516 -- not a real parent pointer, since of course our parent does not own
10517 -- up to us and reference us, we are an illegitimate child of the
10518 -- original parent!
10520 Set_Parent
(New_Compon
, Parent
(Old_Compon
));
10522 -- If the old component's Esize was already determined and is a
10523 -- static value, then the new component simply inherits it. Otherwise
10524 -- the old component's size may require run-time determination, but
10525 -- the new component's size still might be statically determinable
10526 -- (if, for example it has a static constraint). In that case we want
10527 -- Layout_Type to recompute the component's size, so we reset its
10528 -- size and positional fields.
10530 if Frontend_Layout_On_Target
10531 and then not Known_Static_Esize
(Old_Compon
)
10533 Set_Esize
(New_Compon
, Uint_0
);
10534 Init_Normalized_First_Bit
(New_Compon
);
10535 Init_Normalized_Position
(New_Compon
);
10536 Init_Normalized_Position_Max
(New_Compon
);
10539 -- We do not want this node marked as Comes_From_Source, since
10540 -- otherwise it would get first class status and a separate cross-
10541 -- reference line would be generated. Illegitimate children do not
10542 -- rate such recognition.
10544 Set_Comes_From_Source
(New_Compon
, False);
10546 -- But it is a real entity, and a birth certificate must be properly
10547 -- registered by entering it into the entity list.
10549 Enter_Name
(New_Compon
);
10552 end Create_Component
;
10554 -----------------------
10555 -- Is_Variant_Record --
10556 -----------------------
10558 function Is_Variant_Record
(T
: Entity_Id
) return Boolean is
10560 return Nkind
(Parent
(T
)) = N_Full_Type_Declaration
10561 and then Nkind
(Type_Definition
(Parent
(T
))) = N_Record_Definition
10562 and then Present
(Component_List
(Type_Definition
(Parent
(T
))))
10565 (Variant_Part
(Component_List
(Type_Definition
(Parent
(T
)))));
10566 end Is_Variant_Record
;
10568 -- Start of processing for Create_Constrained_Components
10571 pragma Assert
(Subt
/= Base_Type
(Subt
));
10572 pragma Assert
(Typ
= Base_Type
(Typ
));
10574 Set_First_Entity
(Subt
, Empty
);
10575 Set_Last_Entity
(Subt
, Empty
);
10577 -- Check whether constraint is fully static, in which case we can
10578 -- optimize the list of components.
10580 Discr_Val
:= First_Elmt
(Constraints
);
10581 while Present
(Discr_Val
) loop
10582 if not Is_OK_Static_Expression
(Node
(Discr_Val
)) then
10583 Is_Static
:= False;
10587 Next_Elmt
(Discr_Val
);
10590 Set_Has_Static_Discriminants
(Subt
, Is_Static
);
10594 -- Inherit the discriminants of the parent type
10596 Add_Discriminants
: declare
10602 Old_C
:= First_Discriminant
(Typ
);
10604 while Present
(Old_C
) loop
10605 Num_Disc
:= Num_Disc
+ 1;
10606 New_C
:= Create_Component
(Old_C
);
10607 Set_Is_Public
(New_C
, Is_Public
(Subt
));
10608 Next_Discriminant
(Old_C
);
10611 -- For an untagged derived subtype, the number of discriminants may
10612 -- be smaller than the number of inherited discriminants, because
10613 -- several of them may be renamed by a single new discriminant.
10614 -- In this case, add the hidden discriminants back into the subtype,
10615 -- because otherwise the size of the subtype is computed incorrectly
10620 if Is_Derived_Type
(Typ
)
10621 and then not Is_Tagged_Type
(Typ
)
10623 Old_C
:= First_Stored_Discriminant
(Typ
);
10625 while Present
(Old_C
) loop
10626 Num_Gird
:= Num_Gird
+ 1;
10627 Next_Stored_Discriminant
(Old_C
);
10631 if Num_Gird
> Num_Disc
then
10633 -- Find out multiple uses of new discriminants, and add hidden
10634 -- components for the extra renamed discriminants. We recognize
10635 -- multiple uses through the Corresponding_Discriminant of a
10636 -- new discriminant: if it constrains several old discriminants,
10637 -- this field points to the last one in the parent type. The
10638 -- stored discriminants of the derived type have the same name
10639 -- as those of the parent.
10643 New_Discr
: Entity_Id
;
10644 Old_Discr
: Entity_Id
;
10647 Constr
:= First_Elmt
(Stored_Constraint
(Typ
));
10648 Old_Discr
:= First_Stored_Discriminant
(Typ
);
10649 while Present
(Constr
) loop
10650 if Is_Entity_Name
(Node
(Constr
))
10651 and then Ekind
(Entity
(Node
(Constr
))) = E_Discriminant
10653 New_Discr
:= Entity
(Node
(Constr
));
10655 if Chars
(Corresponding_Discriminant
(New_Discr
)) /=
10658 -- The new discriminant has been used to rename a
10659 -- subsequent old discriminant. Introduce a shadow
10660 -- component for the current old discriminant.
10662 New_C
:= Create_Component
(Old_Discr
);
10663 Set_Original_Record_Component
(New_C
, Old_Discr
);
10667 Next_Elmt
(Constr
);
10668 Next_Stored_Discriminant
(Old_Discr
);
10672 end Add_Discriminants
;
10675 and then Is_Variant_Record
(Typ
)
10677 Collect_Fixed_Components
(Typ
);
10679 Gather_Components
(
10681 Component_List
(Type_Definition
(Parent
(Typ
))),
10682 Governed_By
=> Assoc_List
,
10684 Report_Errors
=> Errors
);
10685 pragma Assert
(not Errors
);
10687 Create_All_Components
;
10689 -- If the subtype declaration is created for a tagged type derivation
10690 -- with constraints, we retrieve the record definition of the parent
10691 -- type to select the components of the proper variant.
10694 and then Is_Tagged_Type
(Typ
)
10695 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
10697 Nkind
(Type_Definition
(Parent
(Typ
))) = N_Derived_Type_Definition
10698 and then Is_Variant_Record
(Parent_Type
)
10700 Collect_Fixed_Components
(Typ
);
10702 Gather_Components
(
10704 Component_List
(Type_Definition
(Parent
(Parent_Type
))),
10705 Governed_By
=> Assoc_List
,
10707 Report_Errors
=> Errors
);
10708 pragma Assert
(not Errors
);
10710 -- If the tagged derivation has a type extension, collect all the
10711 -- new components therein.
10714 (Record_Extension_Part
(Type_Definition
(Parent
(Typ
))))
10716 Old_C
:= First_Component
(Typ
);
10717 while Present
(Old_C
) loop
10718 if Original_Record_Component
(Old_C
) = Old_C
10719 and then Chars
(Old_C
) /= Name_uTag
10720 and then Chars
(Old_C
) /= Name_uParent
10721 and then Chars
(Old_C
) /= Name_uController
10723 Append_Elmt
(Old_C
, Comp_List
);
10726 Next_Component
(Old_C
);
10730 Create_All_Components
;
10733 -- If discriminants are not static, or if this is a multi-level type
10734 -- extension, we have to include all components of the parent type.
10736 Old_C
:= First_Component
(Typ
);
10737 while Present
(Old_C
) loop
10738 New_C
:= Create_Component
(Old_C
);
10742 Constrain_Component_Type
10743 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
10744 Set_Is_Public
(New_C
, Is_Public
(Subt
));
10746 Next_Component
(Old_C
);
10751 end Create_Constrained_Components
;
10753 ------------------------------------------
10754 -- Decimal_Fixed_Point_Type_Declaration --
10755 ------------------------------------------
10757 procedure Decimal_Fixed_Point_Type_Declaration
10761 Loc
: constant Source_Ptr
:= Sloc
(Def
);
10762 Digs_Expr
: constant Node_Id
:= Digits_Expression
(Def
);
10763 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
10764 Implicit_Base
: Entity_Id
;
10770 -- Start of processing for Decimal_Fixed_Point_Type_Declaration
10773 Check_Restriction
(No_Fixed_Point
, Def
);
10775 -- Create implicit base type
10778 Create_Itype
(E_Decimal_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
10779 Set_Etype
(Implicit_Base
, Implicit_Base
);
10781 -- Analyze and process delta expression
10783 Analyze_And_Resolve
(Delta_Expr
, Universal_Real
);
10785 Check_Delta_Expression
(Delta_Expr
);
10786 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
10788 -- Check delta is power of 10, and determine scale value from it
10794 Scale_Val
:= Uint_0
;
10797 if Val
< Ureal_1
then
10798 while Val
< Ureal_1
loop
10799 Val
:= Val
* Ureal_10
;
10800 Scale_Val
:= Scale_Val
+ 1;
10803 if Scale_Val
> 18 then
10804 Error_Msg_N
("scale exceeds maximum value of 18", Def
);
10805 Scale_Val
:= UI_From_Int
(+18);
10809 while Val
> Ureal_1
loop
10810 Val
:= Val
/ Ureal_10
;
10811 Scale_Val
:= Scale_Val
- 1;
10814 if Scale_Val
< -18 then
10815 Error_Msg_N
("scale is less than minimum value of -18", Def
);
10816 Scale_Val
:= UI_From_Int
(-18);
10820 if Val
/= Ureal_1
then
10821 Error_Msg_N
("delta expression must be a power of 10", Def
);
10822 Delta_Val
:= Ureal_10
** (-Scale_Val
);
10826 -- Set delta, scale and small (small = delta for decimal type)
10828 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
10829 Set_Scale_Value
(Implicit_Base
, Scale_Val
);
10830 Set_Small_Value
(Implicit_Base
, Delta_Val
);
10832 -- Analyze and process digits expression
10834 Analyze_And_Resolve
(Digs_Expr
, Any_Integer
);
10835 Check_Digits_Expression
(Digs_Expr
);
10836 Digs_Val
:= Expr_Value
(Digs_Expr
);
10838 if Digs_Val
> 18 then
10839 Digs_Val
:= UI_From_Int
(+18);
10840 Error_Msg_N
("digits value out of range, maximum is 18", Digs_Expr
);
10843 Set_Digits_Value
(Implicit_Base
, Digs_Val
);
10844 Bound_Val
:= UR_From_Uint
(10 ** Digs_Val
- 1) * Delta_Val
;
10846 -- Set range of base type from digits value for now. This will be
10847 -- expanded to represent the true underlying base range by Freeze.
10849 Set_Fixed_Range
(Implicit_Base
, Loc
, -Bound_Val
, Bound_Val
);
10851 -- Set size to zero for now, size will be set at freeze time. We have
10852 -- to do this for ordinary fixed-point, because the size depends on
10853 -- the specified small, and we might as well do the same for decimal
10856 Init_Size_Align
(Implicit_Base
);
10858 -- If there are bounds given in the declaration use them as the
10859 -- bounds of the first named subtype.
10861 if Present
(Real_Range_Specification
(Def
)) then
10863 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
10864 Low
: constant Node_Id
:= Low_Bound
(RRS
);
10865 High
: constant Node_Id
:= High_Bound
(RRS
);
10870 Analyze_And_Resolve
(Low
, Any_Real
);
10871 Analyze_And_Resolve
(High
, Any_Real
);
10872 Check_Real_Bound
(Low
);
10873 Check_Real_Bound
(High
);
10874 Low_Val
:= Expr_Value_R
(Low
);
10875 High_Val
:= Expr_Value_R
(High
);
10877 if Low_Val
< (-Bound_Val
) then
10879 ("range low bound too small for digits value", Low
);
10880 Low_Val
:= -Bound_Val
;
10883 if High_Val
> Bound_Val
then
10885 ("range high bound too large for digits value", High
);
10886 High_Val
:= Bound_Val
;
10889 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
10892 -- If no explicit range, use range that corresponds to given
10893 -- digits value. This will end up as the final range for the
10897 Set_Fixed_Range
(T
, Loc
, -Bound_Val
, Bound_Val
);
10900 -- Complete entity for first subtype
10902 Set_Ekind
(T
, E_Decimal_Fixed_Point_Subtype
);
10903 Set_Etype
(T
, Implicit_Base
);
10904 Set_Size_Info
(T
, Implicit_Base
);
10905 Set_First_Rep_Item
(T
, First_Rep_Item
(Implicit_Base
));
10906 Set_Digits_Value
(T
, Digs_Val
);
10907 Set_Delta_Value
(T
, Delta_Val
);
10908 Set_Small_Value
(T
, Delta_Val
);
10909 Set_Scale_Value
(T
, Scale_Val
);
10910 Set_Is_Constrained
(T
);
10911 end Decimal_Fixed_Point_Type_Declaration
;
10913 ----------------------------------
10914 -- Derive_Interface_Subprograms --
10915 ----------------------------------
10917 procedure Derive_Interface_Subprograms
10918 (Parent_Type
: Entity_Id
;
10919 Tagged_Type
: Entity_Id
;
10920 Ifaces_List
: Elist_Id
)
10922 function Collect_Interface_Primitives
10923 (Tagged_Type
: Entity_Id
) return Elist_Id
;
10924 -- Ada 2005 (AI-251): Collect the primitives of all the implemented
10927 function In_List
(L
: Elist_Id
; Subp
: Entity_Id
) return Boolean;
10928 -- Determine if Subp already in the list L
10930 procedure Remove_Homonym
(E
: Entity_Id
);
10931 -- Removes E from the homonym chain
10933 ----------------------------------
10934 -- Collect_Interface_Primitives --
10935 ----------------------------------
10937 function Collect_Interface_Primitives
10938 (Tagged_Type
: Entity_Id
) return Elist_Id
10940 Op_List
: constant Elist_Id
:= New_Elmt_List
;
10942 Ifaces_List
: Elist_Id
;
10943 Iface_Elmt
: Elmt_Id
;
10947 pragma Assert
(Is_Tagged_Type
(Tagged_Type
)
10948 and then Has_Abstract_Interfaces
(Tagged_Type
));
10950 Collect_Abstract_Interfaces
(Tagged_Type
, Ifaces_List
);
10952 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
10953 while Present
(Iface_Elmt
) loop
10954 Elmt
:= First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
10956 while Present
(Elmt
) loop
10957 Prim
:= Node
(Elmt
);
10959 if not Is_Predefined_Dispatching_Operation
(Prim
) then
10960 Append_Elmt
(Prim
, Op_List
);
10966 Next_Elmt
(Iface_Elmt
);
10970 end Collect_Interface_Primitives
;
10976 function In_List
(L
: Elist_Id
; Subp
: Entity_Id
) return Boolean is
10979 Elmt
:= First_Elmt
(L
);
10980 while Present
(Elmt
) loop
10981 if Node
(Elmt
) = Subp
then
10991 --------------------
10992 -- Remove_Homonym --
10993 --------------------
10995 procedure Remove_Homonym
(E
: Entity_Id
) is
10996 Prev
: Entity_Id
:= Empty
;
11000 if E
= Current_Entity
(E
) then
11001 Set_Current_Entity
(Homonym
(E
));
11003 H
:= Current_Entity
(E
);
11004 while Present
(H
) and then H
/= E
loop
11009 Set_Homonym
(Prev
, Homonym
(E
));
11011 end Remove_Homonym
;
11018 Iface_Subp
: Entity_Id
;
11019 New_Subp
: Entity_Id
:= Empty
;
11020 Op_List
: Elist_Id
;
11021 Parent_Base
: Entity_Id
;
11024 -- Start of processing for Derive_Interface_Subprograms
11027 if Ada_Version
< Ada_05
11028 or else not Is_Record_Type
(Tagged_Type
)
11029 or else not Is_Tagged_Type
(Tagged_Type
)
11030 or else not Has_Abstract_Interfaces
(Tagged_Type
)
11035 -- Add to the list of interface subprograms all the primitives inherited
11036 -- from abstract interfaces that are not immediate ancestors and also
11037 -- add their derivation to the list of interface primitives.
11039 Op_List
:= Collect_Interface_Primitives
(Tagged_Type
);
11041 Elmt
:= First_Elmt
(Op_List
);
11042 while Present
(Elmt
) loop
11043 Subp
:= Node
(Elmt
);
11044 Iface
:= Find_Dispatching_Type
(Subp
);
11046 if Is_Concurrent_Record_Type
(Tagged_Type
) then
11047 if not Present
(Abstract_Interface_Alias
(Subp
)) then
11048 Derive_Subprogram
(New_Subp
, Subp
, Tagged_Type
, Iface
);
11049 Append_Elmt
(New_Subp
, Ifaces_List
);
11052 elsif not Is_Parent
(Iface
, Tagged_Type
) then
11053 Derive_Subprogram
(New_Subp
, Subp
, Tagged_Type
, Iface
);
11054 Append_Elmt
(New_Subp
, Ifaces_List
);
11060 -- Complete the derivation of the interface subprograms. Assignate to
11061 -- each entity associated with abstract interfaces their aliased entity
11062 -- and complete their decoration as hidden interface entities that will
11063 -- be used later to build the secondary dispatch tables.
11065 if not Is_Empty_Elmt_List
(Ifaces_List
) then
11066 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
11067 and then Has_Discriminants
(Parent_Type
)
11068 and then Present
(Full_View
(Parent_Type
))
11070 Parent_Base
:= Full_View
(Parent_Type
);
11072 Parent_Base
:= Parent_Type
;
11075 Elmt
:= First_Elmt
(Ifaces_List
);
11076 while Present
(Elmt
) loop
11077 Iface_Subp
:= Node
(Elmt
);
11079 -- Look for the first overriding entity in the homonym chain.
11080 -- In this way if we are in the private part of a package spec
11081 -- we get the last overriding subprogram.
11083 E
:= Current_Entity_In_Scope
(Iface_Subp
);
11084 while Present
(E
) loop
11085 if Is_Dispatching_Operation
(E
)
11086 and then Scope
(E
) = Scope
(Iface_Subp
)
11087 and then Type_Conformant
(E
, Iface_Subp
)
11088 and then not In_List
(Ifaces_List
, E
)
11096 -- Create an overriding entity if not found in the homonym chain
11098 if not Present
(E
) then
11100 (E
, Alias
(Iface_Subp
), Tagged_Type
, Parent_Base
);
11102 elsif not In_List
(Primitive_Operations
(Tagged_Type
), E
) then
11104 -- Inherit the operation from the private view
11106 Append_Elmt
(E
, Primitive_Operations
(Tagged_Type
));
11109 -- Complete the decoration of the hidden interface entity
11111 Set_Is_Hidden
(Iface_Subp
);
11112 Set_Abstract_Interface_Alias
(Iface_Subp
, Alias
(Iface_Subp
));
11113 Set_Alias
(Iface_Subp
, E
);
11114 Set_Is_Abstract_Subprogram
(Iface_Subp
,
11115 Is_Abstract_Subprogram
(E
));
11116 Remove_Homonym
(Iface_Subp
);
11118 -- Hidden entities associated with interfaces must have set the
11119 -- Has_Delay_Freeze attribute to ensure that the corresponding
11120 -- entry of the secondary dispatch table is filled when such
11121 -- entity is frozen.
11123 Set_Has_Delayed_Freeze
(Iface_Subp
);
11128 end Derive_Interface_Subprograms
;
11130 -----------------------
11131 -- Derive_Subprogram --
11132 -----------------------
11134 procedure Derive_Subprogram
11135 (New_Subp
: in out Entity_Id
;
11136 Parent_Subp
: Entity_Id
;
11137 Derived_Type
: Entity_Id
;
11138 Parent_Type
: Entity_Id
;
11139 Actual_Subp
: Entity_Id
:= Empty
)
11141 Formal
: Entity_Id
;
11142 New_Formal
: Entity_Id
;
11143 Visible_Subp
: Entity_Id
:= Parent_Subp
;
11145 function Is_Private_Overriding
return Boolean;
11146 -- If Subp is a private overriding of a visible operation, the in-
11147 -- herited operation derives from the overridden op (even though
11148 -- its body is the overriding one) and the inherited operation is
11149 -- visible now. See sem_disp to see the details of the handling of
11150 -- the overridden subprogram, which is removed from the list of
11151 -- primitive operations of the type. The overridden subprogram is
11152 -- saved locally in Visible_Subp, and used to diagnose abstract
11153 -- operations that need overriding in the derived type.
11155 procedure Replace_Type
(Id
, New_Id
: Entity_Id
);
11156 -- When the type is an anonymous access type, create a new access type
11157 -- designating the derived type.
11159 procedure Set_Derived_Name
;
11160 -- This procedure sets the appropriate Chars name for New_Subp. This
11161 -- is normally just a copy of the parent name. An exception arises for
11162 -- type support subprograms, where the name is changed to reflect the
11163 -- name of the derived type, e.g. if type foo is derived from type bar,
11164 -- then a procedure barDA is derived with a name fooDA.
11166 ---------------------------
11167 -- Is_Private_Overriding --
11168 ---------------------------
11170 function Is_Private_Overriding
return Boolean is
11174 -- If the parent is not a dispatching operation there is no
11175 -- need to investigate overridings
11177 if not Is_Dispatching_Operation
(Parent_Subp
) then
11181 -- The visible operation that is overridden is a homonym of the
11182 -- parent subprogram. We scan the homonym chain to find the one
11183 -- whose alias is the subprogram we are deriving.
11185 Prev
:= Current_Entity
(Parent_Subp
);
11186 while Present
(Prev
) loop
11187 if Ekind
(Prev
) = Ekind
(Parent_Subp
)
11188 and then Alias
(Prev
) = Parent_Subp
11189 and then Scope
(Parent_Subp
) = Scope
(Prev
)
11190 and then not Is_Hidden
(Prev
)
11192 Visible_Subp
:= Prev
;
11196 Prev
:= Homonym
(Prev
);
11200 end Is_Private_Overriding
;
11206 procedure Replace_Type
(Id
, New_Id
: Entity_Id
) is
11207 Acc_Type
: Entity_Id
;
11208 Par
: constant Node_Id
:= Parent
(Derived_Type
);
11211 -- When the type is an anonymous access type, create a new access
11212 -- type designating the derived type. This itype must be elaborated
11213 -- at the point of the derivation, not on subsequent calls that may
11214 -- be out of the proper scope for Gigi, so we insert a reference to
11215 -- it after the derivation.
11217 if Ekind
(Etype
(Id
)) = E_Anonymous_Access_Type
then
11219 Desig_Typ
: Entity_Id
:= Designated_Type
(Etype
(Id
));
11222 if Ekind
(Desig_Typ
) = E_Record_Type_With_Private
11223 and then Present
(Full_View
(Desig_Typ
))
11224 and then not Is_Private_Type
(Parent_Type
)
11226 Desig_Typ
:= Full_View
(Desig_Typ
);
11229 if Base_Type
(Desig_Typ
) = Base_Type
(Parent_Type
)
11231 -- Ada 2005 (AI-251): Handle also derivations of abstract
11232 -- interface primitives.
11234 or else (Is_Interface
(Desig_Typ
)
11235 and then not Is_Class_Wide_Type
(Desig_Typ
))
11237 Acc_Type
:= New_Copy
(Etype
(Id
));
11238 Set_Etype
(Acc_Type
, Acc_Type
);
11239 Set_Scope
(Acc_Type
, New_Subp
);
11241 -- Compute size of anonymous access type
11243 if Is_Array_Type
(Desig_Typ
)
11244 and then not Is_Constrained
(Desig_Typ
)
11246 Init_Size
(Acc_Type
, 2 * System_Address_Size
);
11248 Init_Size
(Acc_Type
, System_Address_Size
);
11251 Init_Alignment
(Acc_Type
);
11252 Set_Directly_Designated_Type
(Acc_Type
, Derived_Type
);
11254 Set_Etype
(New_Id
, Acc_Type
);
11255 Set_Scope
(New_Id
, New_Subp
);
11257 -- Create a reference to it
11258 Build_Itype_Reference
(Acc_Type
, Parent
(Derived_Type
));
11261 Set_Etype
(New_Id
, Etype
(Id
));
11265 elsif Base_Type
(Etype
(Id
)) = Base_Type
(Parent_Type
)
11267 (Ekind
(Etype
(Id
)) = E_Record_Type_With_Private
11268 and then Present
(Full_View
(Etype
(Id
)))
11270 Base_Type
(Full_View
(Etype
(Id
))) = Base_Type
(Parent_Type
))
11272 -- Constraint checks on formals are generated during expansion,
11273 -- based on the signature of the original subprogram. The bounds
11274 -- of the derived type are not relevant, and thus we can use
11275 -- the base type for the formals. However, the return type may be
11276 -- used in a context that requires that the proper static bounds
11277 -- be used (a case statement, for example) and for those cases
11278 -- we must use the derived type (first subtype), not its base.
11280 -- If the derived_type_definition has no constraints, we know that
11281 -- the derived type has the same constraints as the first subtype
11282 -- of the parent, and we can also use it rather than its base,
11283 -- which can lead to more efficient code.
11285 if Etype
(Id
) = Parent_Type
then
11286 if Is_Scalar_Type
(Parent_Type
)
11288 Subtypes_Statically_Compatible
(Parent_Type
, Derived_Type
)
11290 Set_Etype
(New_Id
, Derived_Type
);
11292 elsif Nkind
(Par
) = N_Full_Type_Declaration
11294 Nkind
(Type_Definition
(Par
)) = N_Derived_Type_Definition
11297 (Subtype_Indication
(Type_Definition
(Par
)))
11299 Set_Etype
(New_Id
, Derived_Type
);
11302 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
11306 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
11309 -- Ada 2005 (AI-251): Handle derivations of abstract interface
11312 elsif Is_Interface
(Etype
(Id
))
11313 and then not Is_Class_Wide_Type
(Etype
(Id
))
11315 Set_Etype
(New_Id
, Derived_Type
);
11318 Set_Etype
(New_Id
, Etype
(Id
));
11322 ----------------------
11323 -- Set_Derived_Name --
11324 ----------------------
11326 procedure Set_Derived_Name
is
11327 Nm
: constant TSS_Name_Type
:= Get_TSS_Name
(Parent_Subp
);
11329 if Nm
= TSS_Null
then
11330 Set_Chars
(New_Subp
, Chars
(Parent_Subp
));
11332 Set_Chars
(New_Subp
, Make_TSS_Name
(Base_Type
(Derived_Type
), Nm
));
11334 end Set_Derived_Name
;
11336 -- Start of processing for Derive_Subprogram
11340 New_Entity
(Nkind
(Parent_Subp
), Sloc
(Derived_Type
));
11341 Set_Ekind
(New_Subp
, Ekind
(Parent_Subp
));
11343 -- Check whether the inherited subprogram is a private operation that
11344 -- should be inherited but not yet made visible. Such subprograms can
11345 -- become visible at a later point (e.g., the private part of a public
11346 -- child unit) via Declare_Inherited_Private_Subprograms. If the
11347 -- following predicate is true, then this is not such a private
11348 -- operation and the subprogram simply inherits the name of the parent
11349 -- subprogram. Note the special check for the names of controlled
11350 -- operations, which are currently exempted from being inherited with
11351 -- a hidden name because they must be findable for generation of
11352 -- implicit run-time calls.
11354 if not Is_Hidden
(Parent_Subp
)
11355 or else Is_Internal
(Parent_Subp
)
11356 or else Is_Private_Overriding
11357 or else Is_Internal_Name
(Chars
(Parent_Subp
))
11358 or else Chars
(Parent_Subp
) = Name_Initialize
11359 or else Chars
(Parent_Subp
) = Name_Adjust
11360 or else Chars
(Parent_Subp
) = Name_Finalize
11364 -- If parent is hidden, this can be a regular derivation if the
11365 -- parent is immediately visible in a non-instantiating context,
11366 -- or if we are in the private part of an instance. This test
11367 -- should still be refined ???
11369 -- The test for In_Instance_Not_Visible avoids inheriting the derived
11370 -- operation as a non-visible operation in cases where the parent
11371 -- subprogram might not be visible now, but was visible within the
11372 -- original generic, so it would be wrong to make the inherited
11373 -- subprogram non-visible now. (Not clear if this test is fully
11374 -- correct; are there any cases where we should declare the inherited
11375 -- operation as not visible to avoid it being overridden, e.g., when
11376 -- the parent type is a generic actual with private primitives ???)
11378 -- (they should be treated the same as other private inherited
11379 -- subprograms, but it's not clear how to do this cleanly). ???
11381 elsif (In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
11382 and then Is_Immediately_Visible
(Parent_Subp
)
11383 and then not In_Instance
)
11384 or else In_Instance_Not_Visible
11388 -- Ada 2005 (AI-251): Hidden entity associated with abstract interface
11391 elsif Present
(Abstract_Interface_Alias
(Parent_Subp
)) then
11394 -- The type is inheriting a private operation, so enter
11395 -- it with a special name so it can't be overridden.
11398 Set_Chars
(New_Subp
, New_External_Name
(Chars
(Parent_Subp
), 'P'));
11401 Set_Parent
(New_Subp
, Parent
(Derived_Type
));
11402 Replace_Type
(Parent_Subp
, New_Subp
);
11403 Conditional_Delay
(New_Subp
, Parent_Subp
);
11405 Formal
:= First_Formal
(Parent_Subp
);
11406 while Present
(Formal
) loop
11407 New_Formal
:= New_Copy
(Formal
);
11409 -- Normally we do not go copying parents, but in the case of
11410 -- formals, we need to link up to the declaration (which is the
11411 -- parameter specification), and it is fine to link up to the
11412 -- original formal's parameter specification in this case.
11414 Set_Parent
(New_Formal
, Parent
(Formal
));
11416 Append_Entity
(New_Formal
, New_Subp
);
11418 Replace_Type
(Formal
, New_Formal
);
11419 Next_Formal
(Formal
);
11422 -- If this derivation corresponds to a tagged generic actual, then
11423 -- primitive operations rename those of the actual. Otherwise the
11424 -- primitive operations rename those of the parent type, If the
11425 -- parent renames an intrinsic operator, so does the new subprogram.
11426 -- We except concatenation, which is always properly typed, and does
11427 -- not get expanded as other intrinsic operations.
11429 if No
(Actual_Subp
) then
11430 if Is_Intrinsic_Subprogram
(Parent_Subp
) then
11431 Set_Is_Intrinsic_Subprogram
(New_Subp
);
11433 if Present
(Alias
(Parent_Subp
))
11434 and then Chars
(Parent_Subp
) /= Name_Op_Concat
11436 Set_Alias
(New_Subp
, Alias
(Parent_Subp
));
11438 Set_Alias
(New_Subp
, Parent_Subp
);
11442 Set_Alias
(New_Subp
, Parent_Subp
);
11446 Set_Alias
(New_Subp
, Actual_Subp
);
11449 -- Derived subprograms of a tagged type must inherit the convention
11450 -- of the parent subprogram (a requirement of AI-117). Derived
11451 -- subprograms of untagged types simply get convention Ada by default.
11453 if Is_Tagged_Type
(Derived_Type
) then
11454 Set_Convention
(New_Subp
, Convention
(Parent_Subp
));
11457 Set_Is_Imported
(New_Subp
, Is_Imported
(Parent_Subp
));
11458 Set_Is_Exported
(New_Subp
, Is_Exported
(Parent_Subp
));
11460 if Ekind
(Parent_Subp
) = E_Procedure
then
11461 Set_Is_Valued_Procedure
11462 (New_Subp
, Is_Valued_Procedure
(Parent_Subp
));
11465 -- No_Return must be inherited properly. If this is overridden in the
11466 -- case of a dispatching operation, then a check is made in Sem_Disp
11467 -- that the overriding operation is also No_Return (no such check is
11468 -- required for the case of non-dispatching operation.
11470 Set_No_Return
(New_Subp
, No_Return
(Parent_Subp
));
11472 -- A derived function with a controlling result is abstract. If the
11473 -- Derived_Type is a nonabstract formal generic derived type, then
11474 -- inherited operations are not abstract: the required check is done at
11475 -- instantiation time. If the derivation is for a generic actual, the
11476 -- function is not abstract unless the actual is.
11478 if Is_Generic_Type
(Derived_Type
)
11479 and then not Is_Abstract_Type
(Derived_Type
)
11483 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
11484 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2).
11486 elsif Ada_Version
>= Ada_05
11487 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
11488 or else (Is_Tagged_Type
(Derived_Type
)
11489 and then Etype
(New_Subp
) = Derived_Type
11490 and then not Is_Null_Extension
(Derived_Type
))
11491 or else (Is_Tagged_Type
(Derived_Type
)
11492 and then Ekind
(Etype
(New_Subp
)) =
11493 E_Anonymous_Access_Type
11494 and then Designated_Type
(Etype
(New_Subp
)) =
11496 and then not Is_Null_Extension
(Derived_Type
)))
11497 and then No
(Actual_Subp
)
11499 if not Is_Tagged_Type
(Derived_Type
)
11500 or else Is_Abstract_Type
(Derived_Type
)
11501 or else Is_Abstract_Subprogram
(Alias
(New_Subp
))
11503 Set_Is_Abstract_Subprogram
(New_Subp
);
11505 Set_Requires_Overriding
(New_Subp
);
11508 elsif Ada_Version
< Ada_05
11509 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
11510 or else (Is_Tagged_Type
(Derived_Type
)
11511 and then Etype
(New_Subp
) = Derived_Type
11512 and then No
(Actual_Subp
)))
11514 Set_Is_Abstract_Subprogram
(New_Subp
);
11516 -- Finally, if the parent type is abstract we must verify that all
11517 -- inherited operations are either non-abstract or overridden, or
11518 -- that the derived type itself is abstract (this check is performed
11519 -- at the end of a package declaration, in Check_Abstract_Overriding).
11520 -- A private overriding in the parent type will not be visible in the
11521 -- derivation if we are not in an inner package or in a child unit of
11522 -- the parent type, in which case the abstractness of the inherited
11523 -- operation is carried to the new subprogram.
11525 elsif Is_Abstract_Type
(Parent_Type
)
11526 and then not In_Open_Scopes
(Scope
(Parent_Type
))
11527 and then Is_Private_Overriding
11528 and then Is_Abstract_Subprogram
(Visible_Subp
)
11530 if No
(Actual_Subp
) then
11531 Set_Alias
(New_Subp
, Visible_Subp
);
11532 Set_Is_Abstract_Subprogram
11535 -- If this is a derivation for an instance of a formal derived
11536 -- type, abstractness comes from the primitive operation of the
11537 -- actual, not from the operation inherited from the ancestor.
11539 Set_Is_Abstract_Subprogram
11540 (New_Subp
, Is_Abstract_Subprogram
(Actual_Subp
));
11544 New_Overloaded_Entity
(New_Subp
, Derived_Type
);
11546 -- Check for case of a derived subprogram for the instantiation of a
11547 -- formal derived tagged type, if so mark the subprogram as dispatching
11548 -- and inherit the dispatching attributes of the parent subprogram. The
11549 -- derived subprogram is effectively renaming of the actual subprogram,
11550 -- so it needs to have the same attributes as the actual.
11552 if Present
(Actual_Subp
)
11553 and then Is_Dispatching_Operation
(Parent_Subp
)
11555 Set_Is_Dispatching_Operation
(New_Subp
);
11557 if Present
(DTC_Entity
(Parent_Subp
)) then
11558 Set_DTC_Entity
(New_Subp
, DTC_Entity
(Parent_Subp
));
11559 Set_DT_Position
(New_Subp
, DT_Position
(Parent_Subp
));
11563 -- Indicate that a derived subprogram does not require a body and that
11564 -- it does not require processing of default expressions.
11566 Set_Has_Completion
(New_Subp
);
11567 Set_Default_Expressions_Processed
(New_Subp
);
11569 if Ekind
(New_Subp
) = E_Function
then
11570 Set_Mechanism
(New_Subp
, Mechanism
(Parent_Subp
));
11572 end Derive_Subprogram
;
11574 ------------------------
11575 -- Derive_Subprograms --
11576 ------------------------
11578 procedure Derive_Subprograms
11579 (Parent_Type
: Entity_Id
;
11580 Derived_Type
: Entity_Id
;
11581 Generic_Actual
: Entity_Id
:= Empty
)
11583 Op_List
: constant Elist_Id
:=
11584 Collect_Primitive_Operations
(Parent_Type
);
11585 Ifaces_List
: constant Elist_Id
:= New_Elmt_List
;
11586 Act_List
: Elist_Id
;
11587 Act_Elmt
: Elmt_Id
;
11589 New_Subp
: Entity_Id
:= Empty
;
11590 Parent_Base
: Entity_Id
;
11594 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
11595 and then Has_Discriminants
(Parent_Type
)
11596 and then Present
(Full_View
(Parent_Type
))
11598 Parent_Base
:= Full_View
(Parent_Type
);
11600 Parent_Base
:= Parent_Type
;
11603 -- Derive primitives inherited from the parent
11605 if Present
(Generic_Actual
) then
11606 Act_List
:= Collect_Primitive_Operations
(Generic_Actual
);
11607 Act_Elmt
:= First_Elmt
(Act_List
);
11609 Act_Elmt
:= No_Elmt
;
11612 -- Literals are derived earlier in the process of building the derived
11613 -- type, and are skipped here.
11615 Elmt
:= First_Elmt
(Op_List
);
11616 while Present
(Elmt
) loop
11617 Subp
:= Node
(Elmt
);
11619 if Ekind
(Subp
) /= E_Enumeration_Literal
then
11621 if Ada_Version
>= Ada_05
11622 and then Present
(Abstract_Interface_Alias
(Subp
))
11626 elsif No
(Generic_Actual
) then
11627 Derive_Subprogram
(New_Subp
, Subp
, Derived_Type
, Parent_Base
);
11629 -- Ada 2005 (AI-251): Add the derivation of an abstract
11630 -- interface primitive to the list of entities to which
11631 -- we have to associate an aliased entity.
11633 if Ada_Version
>= Ada_05
11634 and then Is_Dispatching_Operation
(Subp
)
11635 and then Present
(Find_Dispatching_Type
(Subp
))
11636 and then Is_Interface
(Find_Dispatching_Type
(Subp
))
11637 and then not Is_Predefined_Dispatching_Operation
(Subp
)
11639 Append_Elmt
(New_Subp
, Ifaces_List
);
11643 -- If the generic parent type is present, the derived type
11644 -- is an instance of a formal derived type, and within the
11645 -- instance its operations are those of the actual. We derive
11646 -- from the formal type but make the inherited operations
11647 -- aliases of the corresponding operations of the actual.
11649 if Is_Interface
(Parent_Type
)
11650 and then Root_Type
(Derived_Type
) /= Parent_Type
11652 -- Find the corresponding operation in the generic actual.
11653 -- Given that the actual is not a direct descendant of the
11654 -- parent, as in Ada 95, the primitives are not necessarily
11655 -- in the same order, so we have to traverse the list of
11656 -- primitive operations of the actual to find the one that
11657 -- implements the interface operation.
11659 -- Note that if the parent type is the direct ancestor of
11660 -- the derived type, then even if it is an interface the
11661 -- operations are inherited from the primary dispatch table
11662 -- and are in the proper order.
11664 Act_Elmt
:= First_Elmt
(Act_List
);
11665 while Present
(Act_Elmt
) loop
11667 Abstract_Interface_Alias
(Node
(Act_Elmt
)) = Subp
;
11668 Next_Elmt
(Act_Elmt
);
11672 -- If the formal is not an interface, the actual is a direct
11673 -- descendant and the common primitive operations appear in
11677 (New_Subp
, Subp
, Derived_Type
, Parent_Base
, Node
(Act_Elmt
));
11679 if Present
(Act_Elmt
) then
11680 Next_Elmt
(Act_Elmt
);
11688 -- Inherit additional operations from progenitor interfaces.
11689 -- However, if the derived type is a generic actual, there
11690 -- are not new primitive operations for the type, because
11691 -- it has those of the actual, so nothing needs to be done.
11692 -- The renamings generated above are not primitive operations,
11693 -- and their purpose is simply to make the proper operations
11694 -- visible within an instantiation.
11696 if Ada_Version
>= Ada_05
11697 and then Is_Tagged_Type
(Derived_Type
)
11698 and then No
(Generic_Actual
)
11700 Derive_Interface_Subprograms
(Parent_Type
, Derived_Type
, Ifaces_List
);
11702 end Derive_Subprograms
;
11704 --------------------------------
11705 -- Derived_Standard_Character --
11706 --------------------------------
11708 procedure Derived_Standard_Character
11710 Parent_Type
: Entity_Id
;
11711 Derived_Type
: Entity_Id
)
11713 Loc
: constant Source_Ptr
:= Sloc
(N
);
11714 Def
: constant Node_Id
:= Type_Definition
(N
);
11715 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
11716 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
11717 Implicit_Base
: constant Entity_Id
:=
11719 (E_Enumeration_Type
, N
, Derived_Type
, 'B');
11725 Discard_Node
(Process_Subtype
(Indic
, N
));
11727 Set_Etype
(Implicit_Base
, Parent_Base
);
11728 Set_Size_Info
(Implicit_Base
, Root_Type
(Parent_Type
));
11729 Set_RM_Size
(Implicit_Base
, RM_Size
(Root_Type
(Parent_Type
)));
11731 Set_Is_Character_Type
(Implicit_Base
, True);
11732 Set_Has_Delayed_Freeze
(Implicit_Base
);
11734 -- The bounds of the implicit base are the bounds of the parent base.
11735 -- Note that their type is the parent base.
11737 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
11738 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
11740 Set_Scalar_Range
(Implicit_Base
,
11743 High_Bound
=> Hi
));
11745 Conditional_Delay
(Derived_Type
, Parent_Type
);
11747 Set_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
11748 Set_Etype
(Derived_Type
, Implicit_Base
);
11749 Set_Size_Info
(Derived_Type
, Parent_Type
);
11751 if Unknown_RM_Size
(Derived_Type
) then
11752 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
11755 Set_Is_Character_Type
(Derived_Type
, True);
11757 if Nkind
(Indic
) /= N_Subtype_Indication
then
11759 -- If no explicit constraint, the bounds are those
11760 -- of the parent type.
11762 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Type
));
11763 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Type
));
11764 Set_Scalar_Range
(Derived_Type
, Make_Range
(Loc
, Lo
, Hi
));
11767 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
11769 -- Because the implicit base is used in the conversion of the bounds,
11770 -- we have to freeze it now. This is similar to what is done for
11771 -- numeric types, and it equally suspicious, but otherwise a non-
11772 -- static bound will have a reference to an unfrozen type, which is
11773 -- rejected by Gigi (???). This requires specific care for definition
11774 -- of stream attributes. For details, see comments at the end of
11775 -- Build_Derived_Numeric_Type.
11777 Freeze_Before
(N
, Implicit_Base
);
11778 end Derived_Standard_Character
;
11780 ------------------------------
11781 -- Derived_Type_Declaration --
11782 ------------------------------
11784 procedure Derived_Type_Declaration
11787 Is_Completion
: Boolean)
11789 Parent_Type
: Entity_Id
;
11791 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean;
11792 -- Check whether the parent type is a generic formal, or derives
11793 -- directly or indirectly from one.
11795 ------------------------
11796 -- Comes_From_Generic --
11797 ------------------------
11799 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean is
11801 if Is_Generic_Type
(Typ
) then
11804 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
11807 elsif Is_Private_Type
(Typ
)
11808 and then Present
(Full_View
(Typ
))
11809 and then Is_Generic_Type
(Root_Type
(Full_View
(Typ
)))
11813 elsif Is_Generic_Actual_Type
(Typ
) then
11819 end Comes_From_Generic
;
11823 Def
: constant Node_Id
:= Type_Definition
(N
);
11824 Iface_Def
: Node_Id
;
11825 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
11826 Extension
: constant Node_Id
:= Record_Extension_Part
(Def
);
11827 Parent_Node
: Node_Id
;
11828 Parent_Scope
: Entity_Id
;
11831 -- Start of processing for Derived_Type_Declaration
11834 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
11836 -- Ada 2005 (AI-251): In case of interface derivation check that the
11837 -- parent is also an interface.
11839 if Interface_Present
(Def
) then
11840 if not Is_Interface
(Parent_Type
) then
11842 ("(Ada 2005) & must be an interface", Indic
, Parent_Type
);
11845 Parent_Node
:= Parent
(Base_Type
(Parent_Type
));
11846 Iface_Def
:= Type_Definition
(Parent_Node
);
11848 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
11849 -- other limited interfaces.
11851 if Limited_Present
(Def
) then
11852 if Limited_Present
(Iface_Def
) then
11855 elsif Protected_Present
(Iface_Def
) then
11857 ("(Ada 2005) limited interface cannot "
11858 & "inherit from protected interface", Indic
);
11860 elsif Synchronized_Present
(Iface_Def
) then
11862 ("(Ada 2005) limited interface cannot "
11863 & "inherit from synchronized interface", Indic
);
11865 elsif Task_Present
(Iface_Def
) then
11867 ("(Ada 2005) limited interface cannot "
11868 & "inherit from task interface", Indic
);
11872 ("(Ada 2005) limited interface cannot "
11873 & "inherit from non-limited interface", Indic
);
11876 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
11877 -- from non-limited or limited interfaces.
11879 elsif not Protected_Present
(Def
)
11880 and then not Synchronized_Present
(Def
)
11881 and then not Task_Present
(Def
)
11883 if Limited_Present
(Iface_Def
) then
11886 elsif Protected_Present
(Iface_Def
) then
11888 ("(Ada 2005) non-limited interface cannot "
11889 & "inherit from protected interface", Indic
);
11891 elsif Synchronized_Present
(Iface_Def
) then
11893 ("(Ada 2005) non-limited interface cannot "
11894 & "inherit from synchronized interface", Indic
);
11896 elsif Task_Present
(Iface_Def
) then
11898 ("(Ada 2005) non-limited interface cannot "
11899 & "inherit from task interface", Indic
);
11908 if Is_Tagged_Type
(Parent_Type
)
11909 and then Is_Concurrent_Type
(Parent_Type
)
11910 and then not Is_Interface
(Parent_Type
)
11913 ("parent type of a record extension cannot be "
11914 & "a synchronized tagged type (RM 3.9.1 (3/1))", N
);
11915 Set_Etype
(T
, Any_Type
);
11919 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
11922 if Is_Tagged_Type
(Parent_Type
)
11923 and then Is_Non_Empty_List
(Interface_List
(Def
))
11930 Intf
:= First
(Interface_List
(Def
));
11931 while Present
(Intf
) loop
11932 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
11934 if not Is_Interface
(T
) then
11935 Error_Msg_NE
("(Ada 2005) & must be an interface", Intf
, T
);
11937 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
11938 -- a limited type from having a nonlimited progenitor.
11940 elsif (Limited_Present
(Def
)
11941 or else (not Is_Interface
(Parent_Type
)
11942 and then Is_Limited_Type
(Parent_Type
)))
11943 and then not Is_Limited_Interface
(T
)
11946 ("progenitor interface& of limited type must be limited",
11955 if Parent_Type
= Any_Type
11956 or else Etype
(Parent_Type
) = Any_Type
11957 or else (Is_Class_Wide_Type
(Parent_Type
)
11958 and then Etype
(Parent_Type
) = T
)
11960 -- If Parent_Type is undefined or illegal, make new type into a
11961 -- subtype of Any_Type, and set a few attributes to prevent cascaded
11962 -- errors. If this is a self-definition, emit error now.
11965 or else T
= Etype
(Parent_Type
)
11967 Error_Msg_N
("type cannot be used in its own definition", Indic
);
11970 Set_Ekind
(T
, Ekind
(Parent_Type
));
11971 Set_Etype
(T
, Any_Type
);
11972 Set_Scalar_Range
(T
, Scalar_Range
(Any_Type
));
11974 if Is_Tagged_Type
(T
) then
11975 Set_Primitive_Operations
(T
, New_Elmt_List
);
11981 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
11982 -- an interface is special because the list of interfaces in the full
11983 -- view can be given in any order. For example:
11985 -- type A is interface;
11986 -- type B is interface and A;
11987 -- type D is new B with private;
11989 -- type D is new A and B with null record; -- 1 --
11991 -- In this case we perform the following transformation of -1-:
11993 -- type D is new B and A with null record;
11995 -- If the parent of the full-view covers the parent of the partial-view
11996 -- we have two possible cases:
11998 -- 1) They have the same parent
11999 -- 2) The parent of the full-view implements some further interfaces
12001 -- In both cases we do not need to perform the transformation. In the
12002 -- first case the source program is correct and the transformation is
12003 -- not needed; in the second case the source program does not fulfill
12004 -- the no-hidden interfaces rule (AI-396) and the error will be reported
12007 -- This transformation not only simplifies the rest of the analysis of
12008 -- this type declaration but also simplifies the correct generation of
12009 -- the object layout to the expander.
12011 if In_Private_Part
(Current_Scope
)
12012 and then Is_Interface
(Parent_Type
)
12016 Partial_View
: Entity_Id
;
12017 Partial_View_Parent
: Entity_Id
;
12018 New_Iface
: Node_Id
;
12021 -- Look for the associated private type declaration
12023 Partial_View
:= First_Entity
(Current_Scope
);
12025 exit when No
(Partial_View
)
12026 or else (Has_Private_Declaration
(Partial_View
)
12027 and then Full_View
(Partial_View
) = T
);
12029 Next_Entity
(Partial_View
);
12032 -- If the partial view was not found then the source code has
12033 -- errors and the transformation is not needed.
12035 if Present
(Partial_View
) then
12036 Partial_View_Parent
:= Etype
(Partial_View
);
12038 -- If the parent of the full-view covers the parent of the
12039 -- partial-view we have nothing else to do.
12041 if Interface_Present_In_Ancestor
12042 (Parent_Type
, Partial_View_Parent
)
12046 -- Traverse the list of interfaces of the full-view to look
12047 -- for the parent of the partial-view and perform the tree
12051 Iface
:= First
(Interface_List
(Def
));
12052 while Present
(Iface
) loop
12053 if Etype
(Iface
) = Etype
(Partial_View
) then
12054 Rewrite
(Subtype_Indication
(Def
),
12055 New_Copy
(Subtype_Indication
12056 (Parent
(Partial_View
))));
12058 New_Iface
:= Make_Identifier
(Sloc
(N
),
12059 Chars
(Parent_Type
));
12060 Append
(New_Iface
, Interface_List
(Def
));
12062 -- Analyze the transformed code
12064 Derived_Type_Declaration
(T
, N
, Is_Completion
);
12075 -- Only composite types other than array types are allowed to have
12078 if Present
(Discriminant_Specifications
(N
))
12079 and then (Is_Elementary_Type
(Parent_Type
)
12080 or else Is_Array_Type
(Parent_Type
))
12081 and then not Error_Posted
(N
)
12084 ("elementary or array type cannot have discriminants",
12085 Defining_Identifier
(First
(Discriminant_Specifications
(N
))));
12086 Set_Has_Discriminants
(T
, False);
12089 -- In Ada 83, a derived type defined in a package specification cannot
12090 -- be used for further derivation until the end of its visible part.
12091 -- Note that derivation in the private part of the package is allowed.
12093 if Ada_Version
= Ada_83
12094 and then Is_Derived_Type
(Parent_Type
)
12095 and then In_Visible_Part
(Scope
(Parent_Type
))
12097 if Ada_Version
= Ada_83
and then Comes_From_Source
(Indic
) then
12099 ("(Ada 83): premature use of type for derivation", Indic
);
12103 -- Check for early use of incomplete or private type
12105 if Ekind
(Parent_Type
) = E_Void
12106 or else Ekind
(Parent_Type
) = E_Incomplete_Type
12108 Error_Msg_N
("premature derivation of incomplete type", Indic
);
12111 elsif (Is_Incomplete_Or_Private_Type
(Parent_Type
)
12112 and then not Comes_From_Generic
(Parent_Type
))
12113 or else Has_Private_Component
(Parent_Type
)
12115 -- The ancestor type of a formal type can be incomplete, in which
12116 -- case only the operations of the partial view are available in
12117 -- the generic. Subsequent checks may be required when the full
12118 -- view is analyzed, to verify that derivation from a tagged type
12119 -- has an extension.
12121 if Nkind
(Original_Node
(N
)) = N_Formal_Type_Declaration
then
12124 elsif No
(Underlying_Type
(Parent_Type
))
12125 or else Has_Private_Component
(Parent_Type
)
12128 ("premature derivation of derived or private type", Indic
);
12130 -- Flag the type itself as being in error, this prevents some
12131 -- nasty problems with subsequent uses of the malformed type.
12133 Set_Error_Posted
(T
);
12135 -- Check that within the immediate scope of an untagged partial
12136 -- view it's illegal to derive from the partial view if the
12137 -- full view is tagged. (7.3(7))
12139 -- We verify that the Parent_Type is a partial view by checking
12140 -- that it is not a Full_Type_Declaration (i.e. a private type or
12141 -- private extension declaration), to distinguish a partial view
12142 -- from a derivation from a private type which also appears as
12145 elsif Present
(Full_View
(Parent_Type
))
12146 and then Nkind
(Parent
(Parent_Type
)) /= N_Full_Type_Declaration
12147 and then not Is_Tagged_Type
(Parent_Type
)
12148 and then Is_Tagged_Type
(Full_View
(Parent_Type
))
12150 Parent_Scope
:= Scope
(T
);
12151 while Present
(Parent_Scope
)
12152 and then Parent_Scope
/= Standard_Standard
12154 if Parent_Scope
= Scope
(Parent_Type
) then
12156 ("premature derivation from type with tagged full view",
12160 Parent_Scope
:= Scope
(Parent_Scope
);
12165 -- Check that form of derivation is appropriate
12167 Taggd
:= Is_Tagged_Type
(Parent_Type
);
12169 -- Perhaps the parent type should be changed to the class-wide type's
12170 -- specific type in this case to prevent cascading errors ???
12172 if Present
(Extension
) and then Is_Class_Wide_Type
(Parent_Type
) then
12173 Error_Msg_N
("parent type must not be a class-wide type", Indic
);
12177 if Present
(Extension
) and then not Taggd
then
12179 ("type derived from untagged type cannot have extension", Indic
);
12181 elsif No
(Extension
) and then Taggd
then
12183 -- If this declaration is within a private part (or body) of a
12184 -- generic instantiation then the derivation is allowed (the parent
12185 -- type can only appear tagged in this case if it's a generic actual
12186 -- type, since it would otherwise have been rejected in the analysis
12187 -- of the generic template).
12189 if not Is_Generic_Actual_Type
(Parent_Type
)
12190 or else In_Visible_Part
(Scope
(Parent_Type
))
12193 ("type derived from tagged type must have extension", Indic
);
12197 -- AI-443: Synchronized formal derived types require a private
12198 -- extension. There is no point in checking the ancestor type or
12199 -- the progenitors since the construct is wrong to begin with.
12201 if Ada_Version
>= Ada_05
12202 and then Is_Generic_Type
(T
)
12203 and then Present
(Original_Node
(N
))
12206 Decl
: constant Node_Id
:= Original_Node
(N
);
12209 if Nkind
(Decl
) = N_Formal_Type_Declaration
12210 and then Nkind
(Formal_Type_Definition
(Decl
)) =
12211 N_Formal_Derived_Type_Definition
12212 and then Synchronized_Present
(Formal_Type_Definition
(Decl
))
12213 and then No
(Extension
)
12215 -- Avoid emitting a duplicate error message
12217 and then not Error_Posted
(Indic
)
12220 ("synchronized derived type must have extension", N
);
12225 Build_Derived_Type
(N
, Parent_Type
, T
, Is_Completion
);
12227 -- AI-419: The parent type of an explicitly limited derived type must
12228 -- be a limited type or a limited interface.
12230 if Limited_Present
(Def
) then
12231 Set_Is_Limited_Record
(T
);
12233 if Is_Interface
(T
) then
12234 Set_Is_Limited_Interface
(T
);
12237 if not Is_Limited_Type
(Parent_Type
)
12239 (not Is_Interface
(Parent_Type
)
12240 or else not Is_Limited_Interface
(Parent_Type
))
12242 Error_Msg_NE
("parent type& of limited type must be limited",
12246 end Derived_Type_Declaration
;
12248 ----------------------------------
12249 -- Enumeration_Type_Declaration --
12250 ----------------------------------
12252 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
12259 -- Create identifier node representing lower bound
12261 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
12262 L
:= First
(Literals
(Def
));
12263 Set_Chars
(B_Node
, Chars
(L
));
12264 Set_Entity
(B_Node
, L
);
12265 Set_Etype
(B_Node
, T
);
12266 Set_Is_Static_Expression
(B_Node
, True);
12268 R_Node
:= New_Node
(N_Range
, Sloc
(Def
));
12269 Set_Low_Bound
(R_Node
, B_Node
);
12271 Set_Ekind
(T
, E_Enumeration_Type
);
12272 Set_First_Literal
(T
, L
);
12274 Set_Is_Constrained
(T
);
12278 -- Loop through literals of enumeration type setting pos and rep values
12279 -- except that if the Ekind is already set, then it means that the
12280 -- literal was already constructed (case of a derived type declaration
12281 -- and we should not disturb the Pos and Rep values.
12283 while Present
(L
) loop
12284 if Ekind
(L
) /= E_Enumeration_Literal
then
12285 Set_Ekind
(L
, E_Enumeration_Literal
);
12286 Set_Enumeration_Pos
(L
, Ev
);
12287 Set_Enumeration_Rep
(L
, Ev
);
12288 Set_Is_Known_Valid
(L
, True);
12292 New_Overloaded_Entity
(L
);
12293 Generate_Definition
(L
);
12294 Set_Convention
(L
, Convention_Intrinsic
);
12296 if Nkind
(L
) = N_Defining_Character_Literal
then
12297 Set_Is_Character_Type
(T
, True);
12304 -- Now create a node representing upper bound
12306 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
12307 Set_Chars
(B_Node
, Chars
(Last
(Literals
(Def
))));
12308 Set_Entity
(B_Node
, Last
(Literals
(Def
)));
12309 Set_Etype
(B_Node
, T
);
12310 Set_Is_Static_Expression
(B_Node
, True);
12312 Set_High_Bound
(R_Node
, B_Node
);
12314 -- Initialize various fields of the type. Some of this information
12315 -- may be overwritten later through rep.clauses.
12317 Set_Scalar_Range
(T
, R_Node
);
12318 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
12319 Set_Enum_Esize
(T
);
12320 Set_Enum_Pos_To_Rep
(T
, Empty
);
12322 -- Set Discard_Names if configuration pragma set, or if there is
12323 -- a parameterless pragma in the current declarative region
12325 if Global_Discard_Names
12326 or else Discard_Names
(Scope
(T
))
12328 Set_Discard_Names
(T
);
12331 -- Process end label if there is one
12333 if Present
(Def
) then
12334 Process_End_Label
(Def
, 'e', T
);
12336 end Enumeration_Type_Declaration
;
12338 ---------------------------------
12339 -- Expand_To_Stored_Constraint --
12340 ---------------------------------
12342 function Expand_To_Stored_Constraint
12344 Constraint
: Elist_Id
) return Elist_Id
12346 Explicitly_Discriminated_Type
: Entity_Id
;
12347 Expansion
: Elist_Id
;
12348 Discriminant
: Entity_Id
;
12350 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
;
12351 -- Find the nearest type that actually specifies discriminants
12353 ---------------------------------
12354 -- Type_With_Explicit_Discrims --
12355 ---------------------------------
12357 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
is
12358 Typ
: constant E
:= Base_Type
(Id
);
12361 if Ekind
(Typ
) in Incomplete_Or_Private_Kind
then
12362 if Present
(Full_View
(Typ
)) then
12363 return Type_With_Explicit_Discrims
(Full_View
(Typ
));
12367 if Has_Discriminants
(Typ
) then
12372 if Etype
(Typ
) = Typ
then
12374 elsif Has_Discriminants
(Typ
) then
12377 return Type_With_Explicit_Discrims
(Etype
(Typ
));
12380 end Type_With_Explicit_Discrims
;
12382 -- Start of processing for Expand_To_Stored_Constraint
12386 or else Is_Empty_Elmt_List
(Constraint
)
12391 Explicitly_Discriminated_Type
:= Type_With_Explicit_Discrims
(Typ
);
12393 if No
(Explicitly_Discriminated_Type
) then
12397 Expansion
:= New_Elmt_List
;
12400 First_Stored_Discriminant
(Explicitly_Discriminated_Type
);
12401 while Present
(Discriminant
) loop
12403 Get_Discriminant_Value
(
12404 Discriminant
, Explicitly_Discriminated_Type
, Constraint
),
12406 Next_Stored_Discriminant
(Discriminant
);
12410 end Expand_To_Stored_Constraint
;
12412 ---------------------------
12413 -- Find_Hidden_Interface --
12414 ---------------------------
12416 function Find_Hidden_Interface
12418 Dest
: Elist_Id
) return Entity_Id
12421 Iface_Elmt
: Elmt_Id
;
12424 if Present
(Src
) and then Present
(Dest
) then
12425 Iface_Elmt
:= First_Elmt
(Src
);
12426 while Present
(Iface_Elmt
) loop
12427 Iface
:= Node
(Iface_Elmt
);
12429 if Is_Interface
(Iface
)
12430 and then not Contain_Interface
(Iface
, Dest
)
12435 Next_Elmt
(Iface_Elmt
);
12440 end Find_Hidden_Interface
;
12442 --------------------
12443 -- Find_Type_Name --
12444 --------------------
12446 function Find_Type_Name
(N
: Node_Id
) return Entity_Id
is
12447 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
12449 New_Id
: Entity_Id
;
12450 Prev_Par
: Node_Id
;
12453 -- Find incomplete declaration, if one was given
12455 Prev
:= Current_Entity_In_Scope
(Id
);
12457 if Present
(Prev
) then
12459 -- Previous declaration exists. Error if not incomplete/private case
12460 -- except if previous declaration is implicit, etc. Enter_Name will
12461 -- emit error if appropriate.
12463 Prev_Par
:= Parent
(Prev
);
12465 if not Is_Incomplete_Or_Private_Type
(Prev
) then
12469 elsif Nkind
(N
) /= N_Full_Type_Declaration
12470 and then Nkind
(N
) /= N_Task_Type_Declaration
12471 and then Nkind
(N
) /= N_Protected_Type_Declaration
12473 -- Completion must be a full type declarations (RM 7.3(4))
12475 Error_Msg_Sloc
:= Sloc
(Prev
);
12476 Error_Msg_NE
("invalid completion of }", Id
, Prev
);
12478 -- Set scope of Id to avoid cascaded errors. Entity is never
12479 -- examined again, except when saving globals in generics.
12481 Set_Scope
(Id
, Current_Scope
);
12484 -- Case of full declaration of incomplete type
12486 elsif Ekind
(Prev
) = E_Incomplete_Type
then
12488 -- Indicate that the incomplete declaration has a matching full
12489 -- declaration. The defining occurrence of the incomplete
12490 -- declaration remains the visible one, and the procedure
12491 -- Get_Full_View dereferences it whenever the type is used.
12493 if Present
(Full_View
(Prev
)) then
12494 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
12497 Set_Full_View
(Prev
, Id
);
12498 Append_Entity
(Id
, Current_Scope
);
12499 Set_Is_Public
(Id
, Is_Public
(Prev
));
12500 Set_Is_Internal
(Id
);
12503 -- Case of full declaration of private type
12506 if Nkind
(Parent
(Prev
)) /= N_Private_Extension_Declaration
then
12507 if Etype
(Prev
) /= Prev
then
12509 -- Prev is a private subtype or a derived type, and needs
12512 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
12515 elsif Ekind
(Prev
) = E_Private_Type
12517 (Nkind
(N
) = N_Task_Type_Declaration
12518 or else Nkind
(N
) = N_Protected_Type_Declaration
)
12521 ("completion of nonlimited type cannot be limited", N
);
12523 elsif Ekind
(Prev
) = E_Record_Type_With_Private
12525 (Nkind
(N
) = N_Task_Type_Declaration
12526 or else Nkind
(N
) = N_Protected_Type_Declaration
)
12528 if not Is_Limited_Record
(Prev
) then
12530 ("completion of nonlimited type cannot be limited", N
);
12532 elsif No
(Interface_List
(N
)) then
12534 ("completion of tagged private type must be tagged",
12539 -- Ada 2005 (AI-251): Private extension declaration of a task
12540 -- type or a protected type. This case arises when covering
12541 -- interface types.
12543 elsif Nkind
(N
) = N_Task_Type_Declaration
12544 or else Nkind
(N
) = N_Protected_Type_Declaration
12548 elsif Nkind
(N
) /= N_Full_Type_Declaration
12549 or else Nkind
(Type_Definition
(N
)) /= N_Derived_Type_Definition
12552 ("full view of private extension must be an extension", N
);
12554 elsif not (Abstract_Present
(Parent
(Prev
)))
12555 and then Abstract_Present
(Type_Definition
(N
))
12558 ("full view of non-abstract extension cannot be abstract", N
);
12561 if not In_Private_Part
(Current_Scope
) then
12563 ("declaration of full view must appear in private part", N
);
12566 Copy_And_Swap
(Prev
, Id
);
12567 Set_Has_Private_Declaration
(Prev
);
12568 Set_Has_Private_Declaration
(Id
);
12570 -- If no error, propagate freeze_node from private to full view.
12571 -- It may have been generated for an early operational item.
12573 if Present
(Freeze_Node
(Id
))
12574 and then Serious_Errors_Detected
= 0
12575 and then No
(Full_View
(Id
))
12577 Set_Freeze_Node
(Prev
, Freeze_Node
(Id
));
12578 Set_Freeze_Node
(Id
, Empty
);
12579 Set_First_Rep_Item
(Prev
, First_Rep_Item
(Id
));
12582 Set_Full_View
(Id
, Prev
);
12586 -- Verify that full declaration conforms to incomplete one
12588 if Is_Incomplete_Or_Private_Type
(Prev
)
12589 and then Present
(Discriminant_Specifications
(Prev_Par
))
12591 if Present
(Discriminant_Specifications
(N
)) then
12592 if Ekind
(Prev
) = E_Incomplete_Type
then
12593 Check_Discriminant_Conformance
(N
, Prev
, Prev
);
12595 Check_Discriminant_Conformance
(N
, Prev
, Id
);
12600 ("missing discriminants in full type declaration", N
);
12602 -- To avoid cascaded errors on subsequent use, share the
12603 -- discriminants of the partial view.
12605 Set_Discriminant_Specifications
(N
,
12606 Discriminant_Specifications
(Prev_Par
));
12610 -- A prior untagged private type can have an associated class-wide
12611 -- type due to use of the class attribute, and in this case also the
12612 -- full type is required to be tagged.
12615 and then (Is_Tagged_Type
(Prev
)
12616 or else Present
(Class_Wide_Type
(Prev
)))
12617 and then (Nkind
(N
) /= N_Task_Type_Declaration
12618 and then Nkind
(N
) /= N_Protected_Type_Declaration
)
12620 -- The full declaration is either a tagged record or an
12621 -- extension otherwise this is an error
12623 if Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
12624 if not Tagged_Present
(Type_Definition
(N
)) then
12626 ("full declaration of } must be tagged", Prev
, Id
);
12627 Set_Is_Tagged_Type
(Id
);
12628 Set_Primitive_Operations
(Id
, New_Elmt_List
);
12631 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
12632 if No
(Record_Extension_Part
(Type_Definition
(N
))) then
12634 "full declaration of } must be a record extension",
12636 Set_Is_Tagged_Type
(Id
);
12637 Set_Primitive_Operations
(Id
, New_Elmt_List
);
12642 ("full declaration of } must be a tagged type", Prev
, Id
);
12650 -- New type declaration
12655 end Find_Type_Name
;
12657 -------------------------
12658 -- Find_Type_Of_Object --
12659 -------------------------
12661 function Find_Type_Of_Object
12662 (Obj_Def
: Node_Id
;
12663 Related_Nod
: Node_Id
) return Entity_Id
12665 Def_Kind
: constant Node_Kind
:= Nkind
(Obj_Def
);
12666 P
: Node_Id
:= Parent
(Obj_Def
);
12671 -- If the parent is a component_definition node we climb to the
12672 -- component_declaration node
12674 if Nkind
(P
) = N_Component_Definition
then
12678 -- Case of an anonymous array subtype
12680 if Def_Kind
= N_Constrained_Array_Definition
12681 or else Def_Kind
= N_Unconstrained_Array_Definition
12684 Array_Type_Declaration
(T
, Obj_Def
);
12686 -- Create an explicit subtype whenever possible
12688 elsif Nkind
(P
) /= N_Component_Declaration
12689 and then Def_Kind
= N_Subtype_Indication
12691 -- Base name of subtype on object name, which will be unique in
12692 -- the current scope.
12694 -- If this is a duplicate declaration, return base type, to avoid
12695 -- generating duplicate anonymous types.
12697 if Error_Posted
(P
) then
12698 Analyze
(Subtype_Mark
(Obj_Def
));
12699 return Entity
(Subtype_Mark
(Obj_Def
));
12704 (Chars
(Defining_Identifier
(Related_Nod
)), 'S', 0, 'T');
12706 T
:= Make_Defining_Identifier
(Sloc
(P
), Nam
);
12708 Insert_Action
(Obj_Def
,
12709 Make_Subtype_Declaration
(Sloc
(P
),
12710 Defining_Identifier
=> T
,
12711 Subtype_Indication
=> Relocate_Node
(Obj_Def
)));
12713 -- This subtype may need freezing, and this will not be done
12714 -- automatically if the object declaration is not in declarative
12715 -- part. Since this is an object declaration, the type cannot always
12716 -- be frozen here. Deferred constants do not freeze their type
12717 -- (which often enough will be private).
12719 if Nkind
(P
) = N_Object_Declaration
12720 and then Constant_Present
(P
)
12721 and then No
(Expression
(P
))
12725 Insert_Actions
(Obj_Def
, Freeze_Entity
(T
, Sloc
(P
)));
12728 -- Ada 2005 AI-406: the object definition in an object declaration
12729 -- can be an access definition.
12731 elsif Def_Kind
= N_Access_Definition
then
12732 T
:= Access_Definition
(Related_Nod
, Obj_Def
);
12733 Set_Is_Local_Anonymous_Access
(T
);
12735 -- Otherwise, the object definition is just a subtype_mark
12738 T
:= Process_Subtype
(Obj_Def
, Related_Nod
);
12742 end Find_Type_Of_Object
;
12744 --------------------------------
12745 -- Find_Type_Of_Subtype_Indic --
12746 --------------------------------
12748 function Find_Type_Of_Subtype_Indic
(S
: Node_Id
) return Entity_Id
is
12752 -- Case of subtype mark with a constraint
12754 if Nkind
(S
) = N_Subtype_Indication
then
12755 Find_Type
(Subtype_Mark
(S
));
12756 Typ
:= Entity
(Subtype_Mark
(S
));
12759 Is_Valid_Constraint_Kind
(Ekind
(Typ
), Nkind
(Constraint
(S
)))
12762 ("incorrect constraint for this kind of type", Constraint
(S
));
12763 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
12766 -- Otherwise we have a subtype mark without a constraint
12768 elsif Error_Posted
(S
) then
12769 Rewrite
(S
, New_Occurrence_Of
(Any_Id
, Sloc
(S
)));
12777 if Typ
= Standard_Wide_Character
12778 or else Typ
= Standard_Wide_Wide_Character
12779 or else Typ
= Standard_Wide_String
12780 or else Typ
= Standard_Wide_Wide_String
12782 Check_Restriction
(No_Wide_Characters
, S
);
12786 end Find_Type_Of_Subtype_Indic
;
12788 -------------------------------------
12789 -- Floating_Point_Type_Declaration --
12790 -------------------------------------
12792 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
12793 Digs
: constant Node_Id
:= Digits_Expression
(Def
);
12795 Base_Typ
: Entity_Id
;
12796 Implicit_Base
: Entity_Id
;
12799 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
12800 -- Find if given digits value allows derivation from specified type
12802 ---------------------
12803 -- Can_Derive_From --
12804 ---------------------
12806 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
12807 Spec
: constant Entity_Id
:= Real_Range_Specification
(Def
);
12810 if Digs_Val
> Digits_Value
(E
) then
12814 if Present
(Spec
) then
12815 if Expr_Value_R
(Type_Low_Bound
(E
)) >
12816 Expr_Value_R
(Low_Bound
(Spec
))
12821 if Expr_Value_R
(Type_High_Bound
(E
)) <
12822 Expr_Value_R
(High_Bound
(Spec
))
12829 end Can_Derive_From
;
12831 -- Start of processing for Floating_Point_Type_Declaration
12834 Check_Restriction
(No_Floating_Point
, Def
);
12836 -- Create an implicit base type
12839 Create_Itype
(E_Floating_Point_Type
, Parent
(Def
), T
, 'B');
12841 -- Analyze and verify digits value
12843 Analyze_And_Resolve
(Digs
, Any_Integer
);
12844 Check_Digits_Expression
(Digs
);
12845 Digs_Val
:= Expr_Value
(Digs
);
12847 -- Process possible range spec and find correct type to derive from
12849 Process_Real_Range_Specification
(Def
);
12851 if Can_Derive_From
(Standard_Short_Float
) then
12852 Base_Typ
:= Standard_Short_Float
;
12853 elsif Can_Derive_From
(Standard_Float
) then
12854 Base_Typ
:= Standard_Float
;
12855 elsif Can_Derive_From
(Standard_Long_Float
) then
12856 Base_Typ
:= Standard_Long_Float
;
12857 elsif Can_Derive_From
(Standard_Long_Long_Float
) then
12858 Base_Typ
:= Standard_Long_Long_Float
;
12860 -- If we can't derive from any existing type, use long_long_float
12861 -- and give appropriate message explaining the problem.
12864 Base_Typ
:= Standard_Long_Long_Float
;
12866 if Digs_Val
>= Digits_Value
(Standard_Long_Long_Float
) then
12867 Error_Msg_Uint_1
:= Digits_Value
(Standard_Long_Long_Float
);
12868 Error_Msg_N
("digits value out of range, maximum is ^", Digs
);
12872 ("range too large for any predefined type",
12873 Real_Range_Specification
(Def
));
12877 -- If there are bounds given in the declaration use them as the bounds
12878 -- of the type, otherwise use the bounds of the predefined base type
12879 -- that was chosen based on the Digits value.
12881 if Present
(Real_Range_Specification
(Def
)) then
12882 Set_Scalar_Range
(T
, Real_Range_Specification
(Def
));
12883 Set_Is_Constrained
(T
);
12885 -- The bounds of this range must be converted to machine numbers
12886 -- in accordance with RM 4.9(38).
12888 Bound
:= Type_Low_Bound
(T
);
12890 if Nkind
(Bound
) = N_Real_Literal
then
12892 (Bound
, Machine
(Base_Typ
, Realval
(Bound
), Round
, Bound
));
12893 Set_Is_Machine_Number
(Bound
);
12896 Bound
:= Type_High_Bound
(T
);
12898 if Nkind
(Bound
) = N_Real_Literal
then
12900 (Bound
, Machine
(Base_Typ
, Realval
(Bound
), Round
, Bound
));
12901 Set_Is_Machine_Number
(Bound
);
12905 Set_Scalar_Range
(T
, Scalar_Range
(Base_Typ
));
12908 -- Complete definition of implicit base and declared first subtype
12910 Set_Etype
(Implicit_Base
, Base_Typ
);
12912 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
12913 Set_Size_Info
(Implicit_Base
, (Base_Typ
));
12914 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
12915 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
12916 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Base_Typ
));
12917 Set_Vax_Float
(Implicit_Base
, Vax_Float
(Base_Typ
));
12919 Set_Ekind
(T
, E_Floating_Point_Subtype
);
12920 Set_Etype
(T
, Implicit_Base
);
12922 Set_Size_Info
(T
, (Implicit_Base
));
12923 Set_RM_Size
(T
, RM_Size
(Implicit_Base
));
12924 Set_First_Rep_Item
(T
, First_Rep_Item
(Implicit_Base
));
12925 Set_Digits_Value
(T
, Digs_Val
);
12926 end Floating_Point_Type_Declaration
;
12928 ----------------------------
12929 -- Get_Discriminant_Value --
12930 ----------------------------
12932 -- This is the situation:
12934 -- There is a non-derived type
12936 -- type T0 (Dx, Dy, Dz...)
12938 -- There are zero or more levels of derivation, with each derivation
12939 -- either purely inheriting the discriminants, or defining its own.
12941 -- type Ti is new Ti-1
12943 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
12945 -- subtype Ti is ...
12947 -- The subtype issue is avoided by the use of Original_Record_Component,
12948 -- and the fact that derived subtypes also derive the constraints.
12950 -- This chain leads back from
12952 -- Typ_For_Constraint
12954 -- Typ_For_Constraint has discriminants, and the value for each
12955 -- discriminant is given by its corresponding Elmt of Constraints.
12957 -- Discriminant is some discriminant in this hierarchy
12959 -- We need to return its value
12961 -- We do this by recursively searching each level, and looking for
12962 -- Discriminant. Once we get to the bottom, we start backing up
12963 -- returning the value for it which may in turn be a discriminant
12964 -- further up, so on the backup we continue the substitution.
12966 function Get_Discriminant_Value
12967 (Discriminant
: Entity_Id
;
12968 Typ_For_Constraint
: Entity_Id
;
12969 Constraint
: Elist_Id
) return Node_Id
12971 function Search_Derivation_Levels
12973 Discrim_Values
: Elist_Id
;
12974 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
;
12975 -- This is the routine that performs the recursive search of levels
12976 -- as described above.
12978 ------------------------------
12979 -- Search_Derivation_Levels --
12980 ------------------------------
12982 function Search_Derivation_Levels
12984 Discrim_Values
: Elist_Id
;
12985 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
12989 Result
: Node_Or_Entity_Id
;
12990 Result_Entity
: Node_Id
;
12993 -- If inappropriate type, return Error, this happens only in
12994 -- cascaded error situations, and we want to avoid a blow up.
12996 if not Is_Composite_Type
(Ti
) or else Is_Array_Type
(Ti
) then
13000 -- Look deeper if possible. Use Stored_Constraints only for
13001 -- untagged types. For tagged types use the given constraint.
13002 -- This asymmetry needs explanation???
13004 if not Stored_Discrim_Values
13005 and then Present
(Stored_Constraint
(Ti
))
13006 and then not Is_Tagged_Type
(Ti
)
13009 Search_Derivation_Levels
(Ti
, Stored_Constraint
(Ti
), True);
13012 Td
: constant Entity_Id
:= Etype
(Ti
);
13016 Result
:= Discriminant
;
13019 if Present
(Stored_Constraint
(Ti
)) then
13021 Search_Derivation_Levels
13022 (Td
, Stored_Constraint
(Ti
), True);
13025 Search_Derivation_Levels
13026 (Td
, Discrim_Values
, Stored_Discrim_Values
);
13032 -- Extra underlying places to search, if not found above. For
13033 -- concurrent types, the relevant discriminant appears in the
13034 -- corresponding record. For a type derived from a private type
13035 -- without discriminant, the full view inherits the discriminants
13036 -- of the full view of the parent.
13038 if Result
= Discriminant
then
13039 if Is_Concurrent_Type
(Ti
)
13040 and then Present
(Corresponding_Record_Type
(Ti
))
13043 Search_Derivation_Levels
(
13044 Corresponding_Record_Type
(Ti
),
13046 Stored_Discrim_Values
);
13048 elsif Is_Private_Type
(Ti
)
13049 and then not Has_Discriminants
(Ti
)
13050 and then Present
(Full_View
(Ti
))
13051 and then Etype
(Full_View
(Ti
)) /= Ti
13054 Search_Derivation_Levels
(
13057 Stored_Discrim_Values
);
13061 -- If Result is not a (reference to a) discriminant, return it,
13062 -- otherwise set Result_Entity to the discriminant.
13064 if Nkind
(Result
) = N_Defining_Identifier
then
13065 pragma Assert
(Result
= Discriminant
);
13066 Result_Entity
:= Result
;
13069 if not Denotes_Discriminant
(Result
) then
13073 Result_Entity
:= Entity
(Result
);
13076 -- See if this level of derivation actually has discriminants
13077 -- because tagged derivations can add them, hence the lower
13078 -- levels need not have any.
13080 if not Has_Discriminants
(Ti
) then
13084 -- Scan Ti's discriminants for Result_Entity,
13085 -- and return its corresponding value, if any.
13087 Result_Entity
:= Original_Record_Component
(Result_Entity
);
13089 Assoc
:= First_Elmt
(Discrim_Values
);
13091 if Stored_Discrim_Values
then
13092 Disc
:= First_Stored_Discriminant
(Ti
);
13094 Disc
:= First_Discriminant
(Ti
);
13097 while Present
(Disc
) loop
13098 pragma Assert
(Present
(Assoc
));
13100 if Original_Record_Component
(Disc
) = Result_Entity
then
13101 return Node
(Assoc
);
13106 if Stored_Discrim_Values
then
13107 Next_Stored_Discriminant
(Disc
);
13109 Next_Discriminant
(Disc
);
13113 -- Could not find it
13116 end Search_Derivation_Levels
;
13118 Result
: Node_Or_Entity_Id
;
13120 -- Start of processing for Get_Discriminant_Value
13123 -- ??? This routine is a gigantic mess and will be deleted. For the
13124 -- time being just test for the trivial case before calling recurse.
13126 if Base_Type
(Scope
(Discriminant
)) = Base_Type
(Typ_For_Constraint
) then
13132 D
:= First_Discriminant
(Typ_For_Constraint
);
13133 E
:= First_Elmt
(Constraint
);
13134 while Present
(D
) loop
13135 if Chars
(D
) = Chars
(Discriminant
) then
13139 Next_Discriminant
(D
);
13145 Result
:= Search_Derivation_Levels
13146 (Typ_For_Constraint
, Constraint
, False);
13148 -- ??? hack to disappear when this routine is gone
13150 if Nkind
(Result
) = N_Defining_Identifier
then
13156 D
:= First_Discriminant
(Typ_For_Constraint
);
13157 E
:= First_Elmt
(Constraint
);
13158 while Present
(D
) loop
13159 if Corresponding_Discriminant
(D
) = Discriminant
then
13163 Next_Discriminant
(D
);
13169 pragma Assert
(Nkind
(Result
) /= N_Defining_Identifier
);
13171 end Get_Discriminant_Value
;
13173 --------------------------
13174 -- Has_Range_Constraint --
13175 --------------------------
13177 function Has_Range_Constraint
(N
: Node_Id
) return Boolean is
13178 C
: constant Node_Id
:= Constraint
(N
);
13181 if Nkind
(C
) = N_Range_Constraint
then
13184 elsif Nkind
(C
) = N_Digits_Constraint
then
13186 Is_Decimal_Fixed_Point_Type
(Entity
(Subtype_Mark
(N
)))
13188 Present
(Range_Constraint
(C
));
13190 elsif Nkind
(C
) = N_Delta_Constraint
then
13191 return Present
(Range_Constraint
(C
));
13196 end Has_Range_Constraint
;
13198 ------------------------
13199 -- Inherit_Components --
13200 ------------------------
13202 function Inherit_Components
13204 Parent_Base
: Entity_Id
;
13205 Derived_Base
: Entity_Id
;
13206 Is_Tagged
: Boolean;
13207 Inherit_Discr
: Boolean;
13208 Discs
: Elist_Id
) return Elist_Id
13210 Assoc_List
: constant Elist_Id
:= New_Elmt_List
;
13212 procedure Inherit_Component
13213 (Old_C
: Entity_Id
;
13214 Plain_Discrim
: Boolean := False;
13215 Stored_Discrim
: Boolean := False);
13216 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
13217 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
13218 -- True, Old_C is a stored discriminant. If they are both false then
13219 -- Old_C is a regular component.
13221 -----------------------
13222 -- Inherit_Component --
13223 -----------------------
13225 procedure Inherit_Component
13226 (Old_C
: Entity_Id
;
13227 Plain_Discrim
: Boolean := False;
13228 Stored_Discrim
: Boolean := False)
13230 New_C
: constant Entity_Id
:= New_Copy
(Old_C
);
13232 Discrim
: Entity_Id
;
13233 Corr_Discrim
: Entity_Id
;
13236 pragma Assert
(not Is_Tagged
or else not Stored_Discrim
);
13238 Set_Parent
(New_C
, Parent
(Old_C
));
13240 -- Regular discriminants and components must be inserted in the scope
13241 -- of the Derived_Base. Do it here.
13243 if not Stored_Discrim
then
13244 Enter_Name
(New_C
);
13247 -- For tagged types the Original_Record_Component must point to
13248 -- whatever this field was pointing to in the parent type. This has
13249 -- already been achieved by the call to New_Copy above.
13251 if not Is_Tagged
then
13252 Set_Original_Record_Component
(New_C
, New_C
);
13255 -- If we have inherited a component then see if its Etype contains
13256 -- references to Parent_Base discriminants. In this case, replace
13257 -- these references with the constraints given in Discs. We do not
13258 -- do this for the partial view of private types because this is
13259 -- not needed (only the components of the full view will be used
13260 -- for code generation) and cause problem. We also avoid this
13261 -- transformation in some error situations.
13263 if Ekind
(New_C
) = E_Component
then
13264 if (Is_Private_Type
(Derived_Base
)
13265 and then not Is_Generic_Type
(Derived_Base
))
13266 or else (Is_Empty_Elmt_List
(Discs
)
13267 and then not Expander_Active
)
13269 Set_Etype
(New_C
, Etype
(Old_C
));
13272 -- The current component introduces a circularity of the
13275 -- limited with Pack_2;
13276 -- package Pack_1 is
13277 -- type T_1 is tagged record
13278 -- Comp : access Pack_2.T_2;
13284 -- package Pack_2 is
13285 -- type T_2 is new Pack_1.T_1 with ...;
13290 Constrain_Component_Type
13291 (Old_C
, Derived_Base
, N
, Parent_Base
, Discs
));
13295 -- In derived tagged types it is illegal to reference a non
13296 -- discriminant component in the parent type. To catch this, mark
13297 -- these components with an Ekind of E_Void. This will be reset in
13298 -- Record_Type_Definition after processing the record extension of
13299 -- the derived type.
13301 -- If the declaration is a private extension, there is no further
13302 -- record extension to process, and the components retain their
13303 -- current kind, because they are visible at this point.
13305 if Is_Tagged
and then Ekind
(New_C
) = E_Component
13306 and then Nkind
(N
) /= N_Private_Extension_Declaration
13308 Set_Ekind
(New_C
, E_Void
);
13311 if Plain_Discrim
then
13312 Set_Corresponding_Discriminant
(New_C
, Old_C
);
13313 Build_Discriminal
(New_C
);
13315 -- If we are explicitly inheriting a stored discriminant it will be
13316 -- completely hidden.
13318 elsif Stored_Discrim
then
13319 Set_Corresponding_Discriminant
(New_C
, Empty
);
13320 Set_Discriminal
(New_C
, Empty
);
13321 Set_Is_Completely_Hidden
(New_C
);
13323 -- Set the Original_Record_Component of each discriminant in the
13324 -- derived base to point to the corresponding stored that we just
13327 Discrim
:= First_Discriminant
(Derived_Base
);
13328 while Present
(Discrim
) loop
13329 Corr_Discrim
:= Corresponding_Discriminant
(Discrim
);
13331 -- Corr_Discrim could be missing in an error situation
13333 if Present
(Corr_Discrim
)
13334 and then Original_Record_Component
(Corr_Discrim
) = Old_C
13336 Set_Original_Record_Component
(Discrim
, New_C
);
13339 Next_Discriminant
(Discrim
);
13342 Append_Entity
(New_C
, Derived_Base
);
13345 if not Is_Tagged
then
13346 Append_Elmt
(Old_C
, Assoc_List
);
13347 Append_Elmt
(New_C
, Assoc_List
);
13349 end Inherit_Component
;
13351 -- Variables local to Inherit_Component
13353 Loc
: constant Source_Ptr
:= Sloc
(N
);
13355 Parent_Discrim
: Entity_Id
;
13356 Stored_Discrim
: Entity_Id
;
13358 Component
: Entity_Id
;
13360 -- Start of processing for Inherit_Components
13363 if not Is_Tagged
then
13364 Append_Elmt
(Parent_Base
, Assoc_List
);
13365 Append_Elmt
(Derived_Base
, Assoc_List
);
13368 -- Inherit parent discriminants if needed
13370 if Inherit_Discr
then
13371 Parent_Discrim
:= First_Discriminant
(Parent_Base
);
13372 while Present
(Parent_Discrim
) loop
13373 Inherit_Component
(Parent_Discrim
, Plain_Discrim
=> True);
13374 Next_Discriminant
(Parent_Discrim
);
13378 -- Create explicit stored discrims for untagged types when necessary
13380 if not Has_Unknown_Discriminants
(Derived_Base
)
13381 and then Has_Discriminants
(Parent_Base
)
13382 and then not Is_Tagged
13385 or else First_Discriminant
(Parent_Base
) /=
13386 First_Stored_Discriminant
(Parent_Base
))
13388 Stored_Discrim
:= First_Stored_Discriminant
(Parent_Base
);
13389 while Present
(Stored_Discrim
) loop
13390 Inherit_Component
(Stored_Discrim
, Stored_Discrim
=> True);
13391 Next_Stored_Discriminant
(Stored_Discrim
);
13395 -- See if we can apply the second transformation for derived types, as
13396 -- explained in point 6. in the comments above Build_Derived_Record_Type
13397 -- This is achieved by appending Derived_Base discriminants into Discs,
13398 -- which has the side effect of returning a non empty Discs list to the
13399 -- caller of Inherit_Components, which is what we want. This must be
13400 -- done for private derived types if there are explicit stored
13401 -- discriminants, to ensure that we can retrieve the values of the
13402 -- constraints provided in the ancestors.
13405 and then Is_Empty_Elmt_List
(Discs
)
13406 and then Present
(First_Discriminant
(Derived_Base
))
13408 (not Is_Private_Type
(Derived_Base
)
13409 or else Is_Completely_Hidden
13410 (First_Stored_Discriminant
(Derived_Base
))
13411 or else Is_Generic_Type
(Derived_Base
))
13413 D
:= First_Discriminant
(Derived_Base
);
13414 while Present
(D
) loop
13415 Append_Elmt
(New_Reference_To
(D
, Loc
), Discs
);
13416 Next_Discriminant
(D
);
13420 -- Finally, inherit non-discriminant components unless they are not
13421 -- visible because defined or inherited from the full view of the
13422 -- parent. Don't inherit the _parent field of the parent type.
13424 Component
:= First_Entity
(Parent_Base
);
13425 while Present
(Component
) loop
13427 -- Ada 2005 (AI-251): Do not inherit components associated with
13428 -- secondary tags of the parent.
13430 if Ekind
(Component
) = E_Component
13431 and then Present
(Related_Interface
(Component
))
13435 elsif Ekind
(Component
) /= E_Component
13436 or else Chars
(Component
) = Name_uParent
13440 -- If the derived type is within the parent type's declarative
13441 -- region, then the components can still be inherited even though
13442 -- they aren't visible at this point. This can occur for cases
13443 -- such as within public child units where the components must
13444 -- become visible upon entering the child unit's private part.
13446 elsif not Is_Visible_Component
(Component
)
13447 and then not In_Open_Scopes
(Scope
(Parent_Base
))
13451 elsif Ekind
(Derived_Base
) = E_Private_Type
13452 or else Ekind
(Derived_Base
) = E_Limited_Private_Type
13457 Inherit_Component
(Component
);
13460 Next_Entity
(Component
);
13463 -- For tagged derived types, inherited discriminants cannot be used in
13464 -- component declarations of the record extension part. To achieve this
13465 -- we mark the inherited discriminants as not visible.
13467 if Is_Tagged
and then Inherit_Discr
then
13468 D
:= First_Discriminant
(Derived_Base
);
13469 while Present
(D
) loop
13470 Set_Is_Immediately_Visible
(D
, False);
13471 Next_Discriminant
(D
);
13476 end Inherit_Components
;
13478 -----------------------
13479 -- Is_Null_Extension --
13480 -----------------------
13482 function Is_Null_Extension
(T
: Entity_Id
) return Boolean is
13483 Type_Decl
: constant Node_Id
:= Parent
(T
);
13484 Comp_List
: Node_Id
;
13488 if Nkind
(Type_Decl
) /= N_Full_Type_Declaration
13489 or else not Is_Tagged_Type
(T
)
13490 or else Nkind
(Type_Definition
(Type_Decl
)) /=
13491 N_Derived_Type_Definition
13492 or else No
(Record_Extension_Part
(Type_Definition
(Type_Decl
)))
13498 Component_List
(Record_Extension_Part
(Type_Definition
(Type_Decl
)));
13500 if Present
(Discriminant_Specifications
(Type_Decl
)) then
13503 elsif Present
(Comp_List
)
13504 and then Is_Non_Empty_List
(Component_Items
(Comp_List
))
13506 Comp
:= First
(Component_Items
(Comp_List
));
13508 -- Only user-defined components are relevant. The component list
13509 -- may also contain a parent component and internal components
13510 -- corresponding to secondary tags, but these do not determine
13511 -- whether this is a null extension.
13513 while Present
(Comp
) loop
13514 if Comes_From_Source
(Comp
) then
13525 end Is_Null_Extension
;
13527 ------------------------------
13528 -- Is_Valid_Constraint_Kind --
13529 ------------------------------
13531 function Is_Valid_Constraint_Kind
13532 (T_Kind
: Type_Kind
;
13533 Constraint_Kind
: Node_Kind
) return Boolean
13537 when Enumeration_Kind |
13539 return Constraint_Kind
= N_Range_Constraint
;
13541 when Decimal_Fixed_Point_Kind
=>
13543 Constraint_Kind
= N_Digits_Constraint
13545 Constraint_Kind
= N_Range_Constraint
;
13547 when Ordinary_Fixed_Point_Kind
=>
13549 Constraint_Kind
= N_Delta_Constraint
13551 Constraint_Kind
= N_Range_Constraint
;
13555 Constraint_Kind
= N_Digits_Constraint
13557 Constraint_Kind
= N_Range_Constraint
;
13564 E_Incomplete_Type |
13567 return Constraint_Kind
= N_Index_Or_Discriminant_Constraint
;
13570 return True; -- Error will be detected later
13572 end Is_Valid_Constraint_Kind
;
13574 --------------------------
13575 -- Is_Visible_Component --
13576 --------------------------
13578 function Is_Visible_Component
(C
: Entity_Id
) return Boolean is
13579 Original_Comp
: Entity_Id
:= Empty
;
13580 Original_Scope
: Entity_Id
;
13581 Type_Scope
: Entity_Id
;
13583 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean;
13584 -- Check whether parent type of inherited component is declared locally,
13585 -- possibly within a nested package or instance. The current scope is
13586 -- the derived record itself.
13588 -------------------
13589 -- Is_Local_Type --
13590 -------------------
13592 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean is
13596 Scop
:= Scope
(Typ
);
13597 while Present
(Scop
)
13598 and then Scop
/= Standard_Standard
13600 if Scop
= Scope
(Current_Scope
) then
13604 Scop
:= Scope
(Scop
);
13610 -- Start of processing for Is_Visible_Component
13613 if Ekind
(C
) = E_Component
13614 or else Ekind
(C
) = E_Discriminant
13616 Original_Comp
:= Original_Record_Component
(C
);
13619 if No
(Original_Comp
) then
13621 -- Premature usage, or previous error
13626 Original_Scope
:= Scope
(Original_Comp
);
13627 Type_Scope
:= Scope
(Base_Type
(Scope
(C
)));
13630 -- This test only concerns tagged types
13632 if not Is_Tagged_Type
(Original_Scope
) then
13635 -- If it is _Parent or _Tag, there is no visibility issue
13637 elsif not Comes_From_Source
(Original_Comp
) then
13640 -- If we are in the body of an instantiation, the component is visible
13641 -- even when the parent type (possibly defined in an enclosing unit or
13642 -- in a parent unit) might not.
13644 elsif In_Instance_Body
then
13647 -- Discriminants are always visible
13649 elsif Ekind
(Original_Comp
) = E_Discriminant
13650 and then not Has_Unknown_Discriminants
(Original_Scope
)
13654 -- If the component has been declared in an ancestor which is currently
13655 -- a private type, then it is not visible. The same applies if the
13656 -- component's containing type is not in an open scope and the original
13657 -- component's enclosing type is a visible full view of a private type
13658 -- (which can occur in cases where an attempt is being made to reference
13659 -- a component in a sibling package that is inherited from a visible
13660 -- component of a type in an ancestor package; the component in the
13661 -- sibling package should not be visible even though the component it
13662 -- inherited from is visible). This does not apply however in the case
13663 -- where the scope of the type is a private child unit, or when the
13664 -- parent comes from a local package in which the ancestor is currently
13665 -- visible. The latter suppression of visibility is needed for cases
13666 -- that are tested in B730006.
13668 elsif Is_Private_Type
(Original_Scope
)
13670 (not Is_Private_Descendant
(Type_Scope
)
13671 and then not In_Open_Scopes
(Type_Scope
)
13672 and then Has_Private_Declaration
(Original_Scope
))
13674 -- If the type derives from an entity in a formal package, there
13675 -- are no additional visible components.
13677 if Nkind
(Original_Node
(Unit_Declaration_Node
(Type_Scope
))) =
13678 N_Formal_Package_Declaration
13682 -- if we are not in the private part of the current package, there
13683 -- are no additional visible components.
13685 elsif Ekind
(Scope
(Current_Scope
)) = E_Package
13686 and then not In_Private_Part
(Scope
(Current_Scope
))
13691 Is_Child_Unit
(Cunit_Entity
(Current_Sem_Unit
))
13692 and then In_Open_Scopes
(Scope
(Original_Scope
))
13693 and then Is_Local_Type
(Type_Scope
);
13696 -- There is another weird way in which a component may be invisible
13697 -- when the private and the full view are not derived from the same
13698 -- ancestor. Here is an example :
13700 -- type A1 is tagged record F1 : integer; end record;
13701 -- type A2 is new A1 with record F2 : integer; end record;
13702 -- type T is new A1 with private;
13704 -- type T is new A2 with null record;
13706 -- In this case, the full view of T inherits F1 and F2 but the private
13707 -- view inherits only F1
13711 Ancestor
: Entity_Id
:= Scope
(C
);
13715 if Ancestor
= Original_Scope
then
13717 elsif Ancestor
= Etype
(Ancestor
) then
13721 Ancestor
:= Etype
(Ancestor
);
13727 end Is_Visible_Component
;
13729 --------------------------
13730 -- Make_Class_Wide_Type --
13731 --------------------------
13733 procedure Make_Class_Wide_Type
(T
: Entity_Id
) is
13734 CW_Type
: Entity_Id
;
13736 Next_E
: Entity_Id
;
13739 -- The class wide type can have been defined by the partial view, in
13740 -- which case everything is already done.
13742 if Present
(Class_Wide_Type
(T
)) then
13747 New_External_Entity
(E_Void
, Scope
(T
), Sloc
(T
), T
, 'C', 0, 'T');
13749 -- Inherit root type characteristics
13751 CW_Name
:= Chars
(CW_Type
);
13752 Next_E
:= Next_Entity
(CW_Type
);
13753 Copy_Node
(T
, CW_Type
);
13754 Set_Comes_From_Source
(CW_Type
, False);
13755 Set_Chars
(CW_Type
, CW_Name
);
13756 Set_Parent
(CW_Type
, Parent
(T
));
13757 Set_Next_Entity
(CW_Type
, Next_E
);
13759 -- Ensure we have a new freeze node for the class-wide type. The partial
13760 -- view may have freeze action of its own, requiring a proper freeze
13761 -- node, and the same freeze node cannot be shared between the two
13764 Set_Has_Delayed_Freeze
(CW_Type
);
13765 Set_Freeze_Node
(CW_Type
, Empty
);
13767 -- Customize the class-wide type: It has no prim. op., it cannot be
13768 -- abstract and its Etype points back to the specific root type.
13770 Set_Ekind
(CW_Type
, E_Class_Wide_Type
);
13771 Set_Is_Tagged_Type
(CW_Type
, True);
13772 Set_Primitive_Operations
(CW_Type
, New_Elmt_List
);
13773 Set_Is_Abstract_Type
(CW_Type
, False);
13774 Set_Is_Constrained
(CW_Type
, False);
13775 Set_Is_First_Subtype
(CW_Type
, Is_First_Subtype
(T
));
13776 Init_Size_Align
(CW_Type
);
13778 if Ekind
(T
) = E_Class_Wide_Subtype
then
13779 Set_Etype
(CW_Type
, Etype
(Base_Type
(T
)));
13781 Set_Etype
(CW_Type
, T
);
13784 -- If this is the class_wide type of a constrained subtype, it does
13785 -- not have discriminants.
13787 Set_Has_Discriminants
(CW_Type
,
13788 Has_Discriminants
(T
) and then not Is_Constrained
(T
));
13790 Set_Has_Unknown_Discriminants
(CW_Type
, True);
13791 Set_Class_Wide_Type
(T
, CW_Type
);
13792 Set_Equivalent_Type
(CW_Type
, Empty
);
13794 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
13796 Set_Class_Wide_Type
(CW_Type
, CW_Type
);
13797 end Make_Class_Wide_Type
;
13803 procedure Make_Index
13805 Related_Nod
: Node_Id
;
13806 Related_Id
: Entity_Id
:= Empty
;
13807 Suffix_Index
: Nat
:= 1)
13811 Def_Id
: Entity_Id
:= Empty
;
13812 Found
: Boolean := False;
13815 -- For a discrete range used in a constrained array definition and
13816 -- defined by a range, an implicit conversion to the predefined type
13817 -- INTEGER is assumed if each bound is either a numeric literal, a named
13818 -- number, or an attribute, and the type of both bounds (prior to the
13819 -- implicit conversion) is the type universal_integer. Otherwise, both
13820 -- bounds must be of the same discrete type, other than universal
13821 -- integer; this type must be determinable independently of the
13822 -- context, but using the fact that the type must be discrete and that
13823 -- both bounds must have the same type.
13825 -- Character literals also have a universal type in the absence of
13826 -- of additional context, and are resolved to Standard_Character.
13828 if Nkind
(I
) = N_Range
then
13830 -- The index is given by a range constraint. The bounds are known
13831 -- to be of a consistent type.
13833 if not Is_Overloaded
(I
) then
13836 -- For universal bounds, choose the specific predefined type
13838 if T
= Universal_Integer
then
13839 T
:= Standard_Integer
;
13841 elsif T
= Any_Character
then
13842 Ambiguous_Character
(Low_Bound
(I
));
13844 T
:= Standard_Character
;
13851 Ind
: Interp_Index
;
13855 Get_First_Interp
(I
, Ind
, It
);
13856 while Present
(It
.Typ
) loop
13857 if Is_Discrete_Type
(It
.Typ
) then
13860 and then not Covers
(It
.Typ
, T
)
13861 and then not Covers
(T
, It
.Typ
)
13863 Error_Msg_N
("ambiguous bounds in discrete range", I
);
13871 Get_Next_Interp
(Ind
, It
);
13874 if T
= Any_Type
then
13875 Error_Msg_N
("discrete type required for range", I
);
13876 Set_Etype
(I
, Any_Type
);
13879 elsif T
= Universal_Integer
then
13880 T
:= Standard_Integer
;
13885 if not Is_Discrete_Type
(T
) then
13886 Error_Msg_N
("discrete type required for range", I
);
13887 Set_Etype
(I
, Any_Type
);
13891 if Nkind
(Low_Bound
(I
)) = N_Attribute_Reference
13892 and then Attribute_Name
(Low_Bound
(I
)) = Name_First
13893 and then Is_Entity_Name
(Prefix
(Low_Bound
(I
)))
13894 and then Is_Type
(Entity
(Prefix
(Low_Bound
(I
))))
13895 and then Is_Discrete_Type
(Entity
(Prefix
(Low_Bound
(I
))))
13897 -- The type of the index will be the type of the prefix, as long
13898 -- as the upper bound is 'Last of the same type.
13900 Def_Id
:= Entity
(Prefix
(Low_Bound
(I
)));
13902 if Nkind
(High_Bound
(I
)) /= N_Attribute_Reference
13903 or else Attribute_Name
(High_Bound
(I
)) /= Name_Last
13904 or else not Is_Entity_Name
(Prefix
(High_Bound
(I
)))
13905 or else Entity
(Prefix
(High_Bound
(I
))) /= Def_Id
13912 Process_Range_Expr_In_Decl
(R
, T
);
13914 elsif Nkind
(I
) = N_Subtype_Indication
then
13916 -- The index is given by a subtype with a range constraint
13918 T
:= Base_Type
(Entity
(Subtype_Mark
(I
)));
13920 if not Is_Discrete_Type
(T
) then
13921 Error_Msg_N
("discrete type required for range", I
);
13922 Set_Etype
(I
, Any_Type
);
13926 R
:= Range_Expression
(Constraint
(I
));
13929 Process_Range_Expr_In_Decl
(R
, Entity
(Subtype_Mark
(I
)));
13931 elsif Nkind
(I
) = N_Attribute_Reference
then
13933 -- The parser guarantees that the attribute is a RANGE attribute
13935 -- If the node denotes the range of a type mark, that is also the
13936 -- resulting type, and we do no need to create an Itype for it.
13938 if Is_Entity_Name
(Prefix
(I
))
13939 and then Comes_From_Source
(I
)
13940 and then Is_Type
(Entity
(Prefix
(I
)))
13941 and then Is_Discrete_Type
(Entity
(Prefix
(I
)))
13943 Def_Id
:= Entity
(Prefix
(I
));
13946 Analyze_And_Resolve
(I
);
13950 -- If none of the above, must be a subtype. We convert this to a
13951 -- range attribute reference because in the case of declared first
13952 -- named subtypes, the types in the range reference can be different
13953 -- from the type of the entity. A range attribute normalizes the
13954 -- reference and obtains the correct types for the bounds.
13956 -- This transformation is in the nature of an expansion, is only
13957 -- done if expansion is active. In particular, it is not done on
13958 -- formal generic types, because we need to retain the name of the
13959 -- original index for instantiation purposes.
13962 if not Is_Entity_Name
(I
) or else not Is_Type
(Entity
(I
)) then
13963 Error_Msg_N
("invalid subtype mark in discrete range ", I
);
13964 Set_Etype
(I
, Any_Integer
);
13968 -- The type mark may be that of an incomplete type. It is only
13969 -- now that we can get the full view, previous analysis does
13970 -- not look specifically for a type mark.
13972 Set_Entity
(I
, Get_Full_View
(Entity
(I
)));
13973 Set_Etype
(I
, Entity
(I
));
13974 Def_Id
:= Entity
(I
);
13976 if not Is_Discrete_Type
(Def_Id
) then
13977 Error_Msg_N
("discrete type required for index", I
);
13978 Set_Etype
(I
, Any_Type
);
13983 if Expander_Active
then
13985 Make_Attribute_Reference
(Sloc
(I
),
13986 Attribute_Name
=> Name_Range
,
13987 Prefix
=> Relocate_Node
(I
)));
13989 -- The original was a subtype mark that does not freeze. This
13990 -- means that the rewritten version must not freeze either.
13992 Set_Must_Not_Freeze
(I
);
13993 Set_Must_Not_Freeze
(Prefix
(I
));
13995 -- Is order critical??? if so, document why, if not
13996 -- use Analyze_And_Resolve
13998 Analyze_And_Resolve
(I
);
14002 -- If expander is inactive, type is legal, nothing else to construct
14009 if not Is_Discrete_Type
(T
) then
14010 Error_Msg_N
("discrete type required for range", I
);
14011 Set_Etype
(I
, Any_Type
);
14014 elsif T
= Any_Type
then
14015 Set_Etype
(I
, Any_Type
);
14019 -- We will now create the appropriate Itype to describe the range, but
14020 -- first a check. If we originally had a subtype, then we just label
14021 -- the range with this subtype. Not only is there no need to construct
14022 -- a new subtype, but it is wrong to do so for two reasons:
14024 -- 1. A legality concern, if we have a subtype, it must not freeze,
14025 -- and the Itype would cause freezing incorrectly
14027 -- 2. An efficiency concern, if we created an Itype, it would not be
14028 -- recognized as the same type for the purposes of eliminating
14029 -- checks in some circumstances.
14031 -- We signal this case by setting the subtype entity in Def_Id
14033 if No
(Def_Id
) then
14035 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, 'D', Suffix_Index
);
14036 Set_Etype
(Def_Id
, Base_Type
(T
));
14038 if Is_Signed_Integer_Type
(T
) then
14039 Set_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
14041 elsif Is_Modular_Integer_Type
(T
) then
14042 Set_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
14045 Set_Ekind
(Def_Id
, E_Enumeration_Subtype
);
14046 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
14047 Set_First_Literal
(Def_Id
, First_Literal
(T
));
14050 Set_Size_Info
(Def_Id
, (T
));
14051 Set_RM_Size
(Def_Id
, RM_Size
(T
));
14052 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
14054 Set_Scalar_Range
(Def_Id
, R
);
14055 Conditional_Delay
(Def_Id
, T
);
14057 -- In the subtype indication case, if the immediate parent of the
14058 -- new subtype is non-static, then the subtype we create is non-
14059 -- static, even if its bounds are static.
14061 if Nkind
(I
) = N_Subtype_Indication
14062 and then not Is_Static_Subtype
(Entity
(Subtype_Mark
(I
)))
14064 Set_Is_Non_Static_Subtype
(Def_Id
);
14068 -- Final step is to label the index with this constructed type
14070 Set_Etype
(I
, Def_Id
);
14073 ------------------------------
14074 -- Modular_Type_Declaration --
14075 ------------------------------
14077 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
14078 Mod_Expr
: constant Node_Id
:= Expression
(Def
);
14081 procedure Set_Modular_Size
(Bits
: Int
);
14082 -- Sets RM_Size to Bits, and Esize to normal word size above this
14084 ----------------------
14085 -- Set_Modular_Size --
14086 ----------------------
14088 procedure Set_Modular_Size
(Bits
: Int
) is
14090 Set_RM_Size
(T
, UI_From_Int
(Bits
));
14095 elsif Bits
<= 16 then
14096 Init_Esize
(T
, 16);
14098 elsif Bits
<= 32 then
14099 Init_Esize
(T
, 32);
14102 Init_Esize
(T
, System_Max_Binary_Modulus_Power
);
14104 end Set_Modular_Size
;
14106 -- Start of processing for Modular_Type_Declaration
14109 Analyze_And_Resolve
(Mod_Expr
, Any_Integer
);
14111 Set_Ekind
(T
, E_Modular_Integer_Type
);
14112 Init_Alignment
(T
);
14113 Set_Is_Constrained
(T
);
14115 if not Is_OK_Static_Expression
(Mod_Expr
) then
14116 Flag_Non_Static_Expr
14117 ("non-static expression used for modular type bound!", Mod_Expr
);
14118 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
14120 M_Val
:= Expr_Value
(Mod_Expr
);
14124 Error_Msg_N
("modulus value must be positive", Mod_Expr
);
14125 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
14128 Set_Modulus
(T
, M_Val
);
14130 -- Create bounds for the modular type based on the modulus given in
14131 -- the type declaration and then analyze and resolve those bounds.
14133 Set_Scalar_Range
(T
,
14134 Make_Range
(Sloc
(Mod_Expr
),
14136 Make_Integer_Literal
(Sloc
(Mod_Expr
), 0),
14138 Make_Integer_Literal
(Sloc
(Mod_Expr
), M_Val
- 1)));
14140 -- Properly analyze the literals for the range. We do this manually
14141 -- because we can't go calling Resolve, since we are resolving these
14142 -- bounds with the type, and this type is certainly not complete yet!
14144 Set_Etype
(Low_Bound
(Scalar_Range
(T
)), T
);
14145 Set_Etype
(High_Bound
(Scalar_Range
(T
)), T
);
14146 Set_Is_Static_Expression
(Low_Bound
(Scalar_Range
(T
)));
14147 Set_Is_Static_Expression
(High_Bound
(Scalar_Range
(T
)));
14149 -- Loop through powers of two to find number of bits required
14151 for Bits
in Int
range 0 .. System_Max_Binary_Modulus_Power
loop
14155 if M_Val
= 2 ** Bits
then
14156 Set_Modular_Size
(Bits
);
14161 elsif M_Val
< 2 ** Bits
then
14162 Set_Non_Binary_Modulus
(T
);
14164 if Bits
> System_Max_Nonbinary_Modulus_Power
then
14165 Error_Msg_Uint_1
:=
14166 UI_From_Int
(System_Max_Nonbinary_Modulus_Power
);
14168 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr
);
14169 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
14173 -- In the non-binary case, set size as per RM 13.3(55)
14175 Set_Modular_Size
(Bits
);
14182 -- If we fall through, then the size exceed System.Max_Binary_Modulus
14183 -- so we just signal an error and set the maximum size.
14185 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Binary_Modulus_Power
);
14186 Error_Msg_F
("modulus exceeds limit (2 '*'*^)", Mod_Expr
);
14188 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
14189 Init_Alignment
(T
);
14191 end Modular_Type_Declaration
;
14193 --------------------------
14194 -- New_Concatenation_Op --
14195 --------------------------
14197 procedure New_Concatenation_Op
(Typ
: Entity_Id
) is
14198 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
14201 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
;
14202 -- Create abbreviated declaration for the formal of a predefined
14203 -- Operator 'Op' of type 'Typ'
14205 --------------------
14206 -- Make_Op_Formal --
14207 --------------------
14209 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
is
14210 Formal
: Entity_Id
;
14212 Formal
:= New_Internal_Entity
(E_In_Parameter
, Op
, Loc
, 'P');
14213 Set_Etype
(Formal
, Typ
);
14214 Set_Mechanism
(Formal
, Default_Mechanism
);
14216 end Make_Op_Formal
;
14218 -- Start of processing for New_Concatenation_Op
14221 Op
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Concat
);
14223 Set_Ekind
(Op
, E_Operator
);
14224 Set_Scope
(Op
, Current_Scope
);
14225 Set_Etype
(Op
, Typ
);
14226 Set_Homonym
(Op
, Get_Name_Entity_Id
(Name_Op_Concat
));
14227 Set_Is_Immediately_Visible
(Op
);
14228 Set_Is_Intrinsic_Subprogram
(Op
);
14229 Set_Has_Completion
(Op
);
14230 Append_Entity
(Op
, Current_Scope
);
14232 Set_Name_Entity_Id
(Name_Op_Concat
, Op
);
14234 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
14235 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
14236 end New_Concatenation_Op
;
14238 -------------------------
14239 -- OK_For_Limited_Init --
14240 -------------------------
14242 -- ???Check all calls of this, and compare the conditions under which it's
14245 function OK_For_Limited_Init
(Exp
: Node_Id
) return Boolean is
14247 return Ada_Version
>= Ada_05
14248 and then not Debug_Flag_Dot_L
14249 and then OK_For_Limited_Init_In_05
(Exp
);
14250 end OK_For_Limited_Init
;
14252 -------------------------------
14253 -- OK_For_Limited_Init_In_05 --
14254 -------------------------------
14256 function OK_For_Limited_Init_In_05
(Exp
: Node_Id
) return Boolean is
14259 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
14260 -- case of limited aggregates (including extension aggregates), and
14261 -- function calls. The function call may have been give in prefixed
14262 -- notation, in which case the original node is an indexed component.
14264 case Nkind
(Original_Node
(Exp
)) is
14265 when N_Aggregate | N_Extension_Aggregate | N_Function_Call | N_Op
=>
14268 when N_Qualified_Expression
=>
14270 OK_For_Limited_Init_In_05
(Expression
(Original_Node
(Exp
)));
14272 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
14273 -- with a function call, the expander has rewritten the call into an
14274 -- N_Type_Conversion node to force displacement of the pointer to
14275 -- reference the component containing the secondary dispatch table.
14276 -- Otherwise a type conversion is not a legal context.
14278 when N_Type_Conversion
=>
14279 return not Comes_From_Source
(Exp
)
14281 OK_For_Limited_Init_In_05
(Expression
(Original_Node
(Exp
)));
14283 when N_Indexed_Component | N_Selected_Component
=>
14284 return Nkind
(Exp
) = N_Function_Call
;
14286 -- A use of 'Input is a function call, hence allowed. Normally the
14287 -- attribute will be changed to a call, but the attribute by itself
14288 -- can occur with -gnatc.
14290 when N_Attribute_Reference
=>
14291 return Attribute_Name
(Original_Node
(Exp
)) = Name_Input
;
14296 end OK_For_Limited_Init_In_05
;
14298 -------------------------------------------
14299 -- Ordinary_Fixed_Point_Type_Declaration --
14300 -------------------------------------------
14302 procedure Ordinary_Fixed_Point_Type_Declaration
14306 Loc
: constant Source_Ptr
:= Sloc
(Def
);
14307 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
14308 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
14309 Implicit_Base
: Entity_Id
;
14316 Check_Restriction
(No_Fixed_Point
, Def
);
14318 -- Create implicit base type
14321 Create_Itype
(E_Ordinary_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
14322 Set_Etype
(Implicit_Base
, Implicit_Base
);
14324 -- Analyze and process delta expression
14326 Analyze_And_Resolve
(Delta_Expr
, Any_Real
);
14328 Check_Delta_Expression
(Delta_Expr
);
14329 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
14331 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
14333 -- Compute default small from given delta, which is the largest power
14334 -- of two that does not exceed the given delta value.
14344 if Delta_Val
< Ureal_1
then
14345 while Delta_Val
< Tmp
loop
14346 Tmp
:= Tmp
/ Ureal_2
;
14347 Scale
:= Scale
+ 1;
14352 Tmp
:= Tmp
* Ureal_2
;
14353 exit when Tmp
> Delta_Val
;
14354 Scale
:= Scale
- 1;
14358 Small_Val
:= UR_From_Components
(Uint_1
, UI_From_Int
(Scale
), 2);
14361 Set_Small_Value
(Implicit_Base
, Small_Val
);
14363 -- If no range was given, set a dummy range
14365 if RRS
<= Empty_Or_Error
then
14366 Low_Val
:= -Small_Val
;
14367 High_Val
:= Small_Val
;
14369 -- Otherwise analyze and process given range
14373 Low
: constant Node_Id
:= Low_Bound
(RRS
);
14374 High
: constant Node_Id
:= High_Bound
(RRS
);
14377 Analyze_And_Resolve
(Low
, Any_Real
);
14378 Analyze_And_Resolve
(High
, Any_Real
);
14379 Check_Real_Bound
(Low
);
14380 Check_Real_Bound
(High
);
14382 -- Obtain and set the range
14384 Low_Val
:= Expr_Value_R
(Low
);
14385 High_Val
:= Expr_Value_R
(High
);
14387 if Low_Val
> High_Val
then
14388 Error_Msg_NE
("?fixed point type& has null range", Def
, T
);
14393 -- The range for both the implicit base and the declared first subtype
14394 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
14395 -- set a temporary range in place. Note that the bounds of the base
14396 -- type will be widened to be symmetrical and to fill the available
14397 -- bits when the type is frozen.
14399 -- We could do this with all discrete types, and probably should, but
14400 -- we absolutely have to do it for fixed-point, since the end-points
14401 -- of the range and the size are determined by the small value, which
14402 -- could be reset before the freeze point.
14404 Set_Fixed_Range
(Implicit_Base
, Loc
, Low_Val
, High_Val
);
14405 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
14407 Init_Size_Align
(Implicit_Base
);
14409 -- Complete definition of first subtype
14411 Set_Ekind
(T
, E_Ordinary_Fixed_Point_Subtype
);
14412 Set_Etype
(T
, Implicit_Base
);
14413 Init_Size_Align
(T
);
14414 Set_First_Rep_Item
(T
, First_Rep_Item
(Implicit_Base
));
14415 Set_Small_Value
(T
, Small_Val
);
14416 Set_Delta_Value
(T
, Delta_Val
);
14417 Set_Is_Constrained
(T
);
14419 end Ordinary_Fixed_Point_Type_Declaration
;
14421 ----------------------------------------
14422 -- Prepare_Private_Subtype_Completion --
14423 ----------------------------------------
14425 procedure Prepare_Private_Subtype_Completion
14427 Related_Nod
: Node_Id
)
14429 Id_B
: constant Entity_Id
:= Base_Type
(Id
);
14430 Full_B
: constant Entity_Id
:= Full_View
(Id_B
);
14434 if Present
(Full_B
) then
14436 -- The Base_Type is already completed, we can complete the subtype
14437 -- now. We have to create a new entity with the same name, Thus we
14438 -- can't use Create_Itype.
14440 -- This is messy, should be fixed ???
14442 Full
:= Make_Defining_Identifier
(Sloc
(Id
), Chars
(Id
));
14443 Set_Is_Itype
(Full
);
14444 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
14445 Complete_Private_Subtype
(Id
, Full
, Full_B
, Related_Nod
);
14448 -- The parent subtype may be private, but the base might not, in some
14449 -- nested instances. In that case, the subtype does not need to be
14450 -- exchanged. It would still be nice to make private subtypes and their
14451 -- bases consistent at all times ???
14453 if Is_Private_Type
(Id_B
) then
14454 Append_Elmt
(Id
, Private_Dependents
(Id_B
));
14457 end Prepare_Private_Subtype_Completion
;
14459 ---------------------------
14460 -- Process_Discriminants --
14461 ---------------------------
14463 procedure Process_Discriminants
14465 Prev
: Entity_Id
:= Empty
)
14467 Elist
: constant Elist_Id
:= New_Elmt_List
;
14470 Discr_Number
: Uint
;
14471 Discr_Type
: Entity_Id
;
14472 Default_Present
: Boolean := False;
14473 Default_Not_Present
: Boolean := False;
14476 -- A composite type other than an array type can have discriminants.
14477 -- On entry, the current scope is the composite type.
14479 -- The discriminants are initially entered into the scope of the type
14480 -- via Enter_Name with the default Ekind of E_Void to prevent premature
14481 -- use, as explained at the end of this procedure.
14483 Discr
:= First
(Discriminant_Specifications
(N
));
14484 while Present
(Discr
) loop
14485 Enter_Name
(Defining_Identifier
(Discr
));
14487 -- For navigation purposes we add a reference to the discriminant
14488 -- in the entity for the type. If the current declaration is a
14489 -- completion, place references on the partial view. Otherwise the
14490 -- type is the current scope.
14492 if Present
(Prev
) then
14494 -- The references go on the partial view, if present. If the
14495 -- partial view has discriminants, the references have been
14496 -- generated already.
14498 if not Has_Discriminants
(Prev
) then
14499 Generate_Reference
(Prev
, Defining_Identifier
(Discr
), 'd');
14503 (Current_Scope
, Defining_Identifier
(Discr
), 'd');
14506 if Nkind
(Discriminant_Type
(Discr
)) = N_Access_Definition
then
14507 Discr_Type
:= Access_Definition
(Discr
, Discriminant_Type
(Discr
));
14509 -- Ada 2005 (AI-254)
14511 if Present
(Access_To_Subprogram_Definition
14512 (Discriminant_Type
(Discr
)))
14513 and then Protected_Present
(Access_To_Subprogram_Definition
14514 (Discriminant_Type
(Discr
)))
14517 Replace_Anonymous_Access_To_Protected_Subprogram
(Discr
);
14521 Find_Type
(Discriminant_Type
(Discr
));
14522 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
14524 if Error_Posted
(Discriminant_Type
(Discr
)) then
14525 Discr_Type
:= Any_Type
;
14529 if Is_Access_Type
(Discr_Type
) then
14531 -- Ada 2005 (AI-230): Access discriminant allowed in non-limited
14534 if Ada_Version
< Ada_05
then
14535 Check_Access_Discriminant_Requires_Limited
14536 (Discr
, Discriminant_Type
(Discr
));
14539 if Ada_Version
= Ada_83
and then Comes_From_Source
(Discr
) then
14541 ("(Ada 83) access discriminant not allowed", Discr
);
14544 elsif not Is_Discrete_Type
(Discr_Type
) then
14545 Error_Msg_N
("discriminants must have a discrete or access type",
14546 Discriminant_Type
(Discr
));
14549 Set_Etype
(Defining_Identifier
(Discr
), Discr_Type
);
14551 -- If a discriminant specification includes the assignment compound
14552 -- delimiter followed by an expression, the expression is the default
14553 -- expression of the discriminant; the default expression must be of
14554 -- the type of the discriminant. (RM 3.7.1) Since this expression is
14555 -- a default expression, we do the special preanalysis, since this
14556 -- expression does not freeze (see "Handling of Default and Per-
14557 -- Object Expressions" in spec of package Sem).
14559 if Present
(Expression
(Discr
)) then
14560 Analyze_Per_Use_Expression
(Expression
(Discr
), Discr_Type
);
14562 if Nkind
(N
) = N_Formal_Type_Declaration
then
14564 ("discriminant defaults not allowed for formal type",
14565 Expression
(Discr
));
14567 -- Tagged types cannot have defaulted discriminants, but a
14568 -- non-tagged private type with defaulted discriminants
14569 -- can have a tagged completion.
14571 elsif Is_Tagged_Type
(Current_Scope
)
14572 and then Comes_From_Source
(N
)
14575 ("discriminants of tagged type cannot have defaults",
14576 Expression
(Discr
));
14579 Default_Present
:= True;
14580 Append_Elmt
(Expression
(Discr
), Elist
);
14582 -- Tag the defining identifiers for the discriminants with
14583 -- their corresponding default expressions from the tree.
14585 Set_Discriminant_Default_Value
14586 (Defining_Identifier
(Discr
), Expression
(Discr
));
14590 Default_Not_Present
:= True;
14593 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
14594 -- Discr_Type but with the null-exclusion attribute
14596 if Ada_Version
>= Ada_05
then
14598 -- Ada 2005 (AI-231): Static checks
14600 if Can_Never_Be_Null
(Discr_Type
) then
14601 Null_Exclusion_Static_Checks
(Discr
);
14603 elsif Is_Access_Type
(Discr_Type
)
14604 and then Null_Exclusion_Present
(Discr
)
14606 -- No need to check itypes because in their case this check
14607 -- was done at their point of creation
14609 and then not Is_Itype
(Discr_Type
)
14611 if Can_Never_Be_Null
(Discr_Type
) then
14613 ("`NOT NULL` not allowed (& already excludes null)",
14618 Set_Etype
(Defining_Identifier
(Discr
),
14619 Create_Null_Excluding_Itype
14621 Related_Nod
=> Discr
));
14624 -- Ada 2005 (AI-402): access discriminants of nonlimited types
14625 -- can't have defaults
14627 if Is_Access_Type
(Discr_Type
) then
14628 if Ekind
(Discr_Type
) /= E_Anonymous_Access_Type
14629 or else not Default_Present
14630 or else Is_Limited_Record
(Current_Scope
)
14631 or else Is_Concurrent_Type
(Current_Scope
)
14632 or else Is_Concurrent_Record_Type
(Current_Scope
)
14633 or else Ekind
(Current_Scope
) = E_Limited_Private_Type
14637 elsif Present
(Expression
(Discr
)) then
14639 ("(Ada 2005) access discriminants of nonlimited types",
14640 Expression
(Discr
));
14641 Error_Msg_N
("\cannot have defaults", Expression
(Discr
));
14649 -- An element list consisting of the default expressions of the
14650 -- discriminants is constructed in the above loop and used to set
14651 -- the Discriminant_Constraint attribute for the type. If an object
14652 -- is declared of this (record or task) type without any explicit
14653 -- discriminant constraint given, this element list will form the
14654 -- actual parameters for the corresponding initialization procedure
14657 Set_Discriminant_Constraint
(Current_Scope
, Elist
);
14658 Set_Stored_Constraint
(Current_Scope
, No_Elist
);
14660 -- Default expressions must be provided either for all or for none
14661 -- of the discriminants of a discriminant part. (RM 3.7.1)
14663 if Default_Present
and then Default_Not_Present
then
14665 ("incomplete specification of defaults for discriminants", N
);
14668 -- The use of the name of a discriminant is not allowed in default
14669 -- expressions of a discriminant part if the specification of the
14670 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
14672 -- To detect this, the discriminant names are entered initially with an
14673 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
14674 -- attempt to use a void entity (for example in an expression that is
14675 -- type-checked) produces the error message: premature usage. Now after
14676 -- completing the semantic analysis of the discriminant part, we can set
14677 -- the Ekind of all the discriminants appropriately.
14679 Discr
:= First
(Discriminant_Specifications
(N
));
14680 Discr_Number
:= Uint_1
;
14681 while Present
(Discr
) loop
14682 Id
:= Defining_Identifier
(Discr
);
14683 Set_Ekind
(Id
, E_Discriminant
);
14684 Init_Component_Location
(Id
);
14686 Set_Discriminant_Number
(Id
, Discr_Number
);
14688 -- Make sure this is always set, even in illegal programs
14690 Set_Corresponding_Discriminant
(Id
, Empty
);
14692 -- Initialize the Original_Record_Component to the entity itself.
14693 -- Inherit_Components will propagate the right value to
14694 -- discriminants in derived record types.
14696 Set_Original_Record_Component
(Id
, Id
);
14698 -- Create the discriminal for the discriminant
14700 Build_Discriminal
(Id
);
14703 Discr_Number
:= Discr_Number
+ 1;
14706 Set_Has_Discriminants
(Current_Scope
);
14707 end Process_Discriminants
;
14709 -----------------------
14710 -- Process_Full_View --
14711 -----------------------
14713 procedure Process_Full_View
(N
: Node_Id
; Full_T
, Priv_T
: Entity_Id
) is
14714 Priv_Parent
: Entity_Id
;
14715 Full_Parent
: Entity_Id
;
14716 Full_Indic
: Node_Id
;
14718 procedure Collect_Implemented_Interfaces
14720 Ifaces
: Elist_Id
);
14721 -- Ada 2005: Gather all the interfaces that Typ directly or
14722 -- inherently implements. Duplicate entries are not added to
14723 -- the list Ifaces.
14725 ------------------------------------
14726 -- Collect_Implemented_Interfaces --
14727 ------------------------------------
14729 procedure Collect_Implemented_Interfaces
14734 Iface_Elmt
: Elmt_Id
;
14737 -- Abstract interfaces are only associated with tagged record types
14739 if not Is_Tagged_Type
(Typ
)
14740 or else not Is_Record_Type
(Typ
)
14745 -- Recursively climb to the ancestors
14747 if Etype
(Typ
) /= Typ
14749 -- Protect the frontend against wrong cyclic declarations like:
14751 -- type B is new A with private;
14752 -- type C is new A with private;
14754 -- type B is new C with null record;
14755 -- type C is new B with null record;
14757 and then Etype
(Typ
) /= Priv_T
14758 and then Etype
(Typ
) /= Full_T
14760 -- Keep separate the management of private type declarations
14762 if Ekind
(Typ
) = E_Record_Type_With_Private
then
14764 -- Handle the following erronous case:
14765 -- type Private_Type is tagged private;
14767 -- type Private_Type is new Type_Implementing_Iface;
14769 if Present
(Full_View
(Typ
))
14770 and then Etype
(Typ
) /= Full_View
(Typ
)
14772 if Is_Interface
(Etype
(Typ
)) then
14773 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
14776 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
14779 -- Non-private types
14782 if Is_Interface
(Etype
(Typ
)) then
14783 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
14786 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
14790 -- Handle entities in the list of abstract interfaces
14792 if Present
(Abstract_Interfaces
(Typ
)) then
14793 Iface_Elmt
:= First_Elmt
(Abstract_Interfaces
(Typ
));
14794 while Present
(Iface_Elmt
) loop
14795 Iface
:= Node
(Iface_Elmt
);
14797 pragma Assert
(Is_Interface
(Iface
));
14799 if not Contain_Interface
(Iface
, Ifaces
) then
14800 Append_Elmt
(Iface
, Ifaces
);
14801 Collect_Implemented_Interfaces
(Iface
, Ifaces
);
14804 Next_Elmt
(Iface_Elmt
);
14807 end Collect_Implemented_Interfaces
;
14809 -- Start of processing for Process_Full_View
14812 -- First some sanity checks that must be done after semantic
14813 -- decoration of the full view and thus cannot be placed with other
14814 -- similar checks in Find_Type_Name
14816 if not Is_Limited_Type
(Priv_T
)
14817 and then (Is_Limited_Type
(Full_T
)
14818 or else Is_Limited_Composite
(Full_T
))
14821 ("completion of nonlimited type cannot be limited", Full_T
);
14822 Explain_Limited_Type
(Full_T
, Full_T
);
14824 elsif Is_Abstract_Type
(Full_T
)
14825 and then not Is_Abstract_Type
(Priv_T
)
14828 ("completion of nonabstract type cannot be abstract", Full_T
);
14830 elsif Is_Tagged_Type
(Priv_T
)
14831 and then Is_Limited_Type
(Priv_T
)
14832 and then not Is_Limited_Type
(Full_T
)
14834 -- If pragma CPP_Class was applied to the private declaration
14835 -- propagate the limitedness to the full-view
14837 if Is_CPP_Class
(Priv_T
) then
14838 Set_Is_Limited_Record
(Full_T
);
14840 -- GNAT allow its own definition of Limited_Controlled to disobey
14841 -- this rule in order in ease the implementation. The next test is
14842 -- safe because Root_Controlled is defined in a private system child
14844 elsif Etype
(Full_T
) = Full_View
(RTE
(RE_Root_Controlled
)) then
14845 Set_Is_Limited_Composite
(Full_T
);
14848 ("completion of limited tagged type must be limited", Full_T
);
14851 elsif Is_Generic_Type
(Priv_T
) then
14852 Error_Msg_N
("generic type cannot have a completion", Full_T
);
14855 -- Check that ancestor interfaces of private and full views are
14856 -- consistent. We omit this check for synchronized types because
14857 -- they are performed on the corresponding record type when frozen.
14859 if Ada_Version
>= Ada_05
14860 and then Is_Tagged_Type
(Priv_T
)
14861 and then Is_Tagged_Type
(Full_T
)
14862 and then not Is_Concurrent_Type
(Full_T
)
14866 Priv_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
14867 Full_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
14870 Collect_Implemented_Interfaces
(Priv_T
, Priv_T_Ifaces
);
14871 Collect_Implemented_Interfaces
(Full_T
, Full_T_Ifaces
);
14873 -- Ada 2005 (AI-251): The partial view shall be a descendant of
14874 -- an interface type if and only if the full type is descendant
14875 -- of the interface type (AARM 7.3 (7.3/2).
14877 Iface
:= Find_Hidden_Interface
(Priv_T_Ifaces
, Full_T_Ifaces
);
14879 if Present
(Iface
) then
14880 Error_Msg_NE
("interface & not implemented by full type " &
14881 "(RM-2005 7.3 (7.3/2))", Priv_T
, Iface
);
14884 Iface
:= Find_Hidden_Interface
(Full_T_Ifaces
, Priv_T_Ifaces
);
14886 if Present
(Iface
) then
14887 Error_Msg_NE
("interface & not implemented by partial view " &
14888 "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
14893 if Is_Tagged_Type
(Priv_T
)
14894 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
14895 and then Is_Derived_Type
(Full_T
)
14897 Priv_Parent
:= Etype
(Priv_T
);
14899 -- The full view of a private extension may have been transformed
14900 -- into an unconstrained derived type declaration and a subtype
14901 -- declaration (see build_derived_record_type for details).
14903 if Nkind
(N
) = N_Subtype_Declaration
then
14904 Full_Indic
:= Subtype_Indication
(N
);
14905 Full_Parent
:= Etype
(Base_Type
(Full_T
));
14907 Full_Indic
:= Subtype_Indication
(Type_Definition
(N
));
14908 Full_Parent
:= Etype
(Full_T
);
14911 -- Check that the parent type of the full type is a descendant of
14912 -- the ancestor subtype given in the private extension. If either
14913 -- entity has an Etype equal to Any_Type then we had some previous
14914 -- error situation [7.3(8)].
14916 if Priv_Parent
= Any_Type
or else Full_Parent
= Any_Type
then
14919 -- Ada 2005 (AI-251): Interfaces in the full-typ can be given in
14920 -- any order. Therefore we don't have to check that its parent must
14921 -- be a descendant of the parent of the private type declaration.
14923 elsif Is_Interface
(Priv_Parent
)
14924 and then Is_Interface
(Full_Parent
)
14928 -- Ada 2005 (AI-251): If the parent of the private type declaration
14929 -- is an interface there is no need to check that it is an ancestor
14930 -- of the associated full type declaration. The required tests for
14931 -- this case case are performed by Build_Derived_Record_Type.
14933 elsif not Is_Interface
(Base_Type
(Priv_Parent
))
14934 and then not Is_Ancestor
(Base_Type
(Priv_Parent
), Full_Parent
)
14937 ("parent of full type must descend from parent"
14938 & " of private extension", Full_Indic
);
14940 -- Check the rules of 7.3(10): if the private extension inherits
14941 -- known discriminants, then the full type must also inherit those
14942 -- discriminants from the same (ancestor) type, and the parent
14943 -- subtype of the full type must be constrained if and only if
14944 -- the ancestor subtype of the private extension is constrained.
14946 elsif No
(Discriminant_Specifications
(Parent
(Priv_T
)))
14947 and then not Has_Unknown_Discriminants
(Priv_T
)
14948 and then Has_Discriminants
(Base_Type
(Priv_Parent
))
14951 Priv_Indic
: constant Node_Id
:=
14952 Subtype_Indication
(Parent
(Priv_T
));
14954 Priv_Constr
: constant Boolean :=
14955 Is_Constrained
(Priv_Parent
)
14957 Nkind
(Priv_Indic
) = N_Subtype_Indication
14958 or else Is_Constrained
(Entity
(Priv_Indic
));
14960 Full_Constr
: constant Boolean :=
14961 Is_Constrained
(Full_Parent
)
14963 Nkind
(Full_Indic
) = N_Subtype_Indication
14964 or else Is_Constrained
(Entity
(Full_Indic
));
14966 Priv_Discr
: Entity_Id
;
14967 Full_Discr
: Entity_Id
;
14970 Priv_Discr
:= First_Discriminant
(Priv_Parent
);
14971 Full_Discr
:= First_Discriminant
(Full_Parent
);
14972 while Present
(Priv_Discr
) and then Present
(Full_Discr
) loop
14973 if Original_Record_Component
(Priv_Discr
) =
14974 Original_Record_Component
(Full_Discr
)
14976 Corresponding_Discriminant
(Priv_Discr
) =
14977 Corresponding_Discriminant
(Full_Discr
)
14984 Next_Discriminant
(Priv_Discr
);
14985 Next_Discriminant
(Full_Discr
);
14988 if Present
(Priv_Discr
) or else Present
(Full_Discr
) then
14990 ("full view must inherit discriminants of the parent type"
14991 & " used in the private extension", Full_Indic
);
14993 elsif Priv_Constr
and then not Full_Constr
then
14995 ("parent subtype of full type must be constrained",
14998 elsif Full_Constr
and then not Priv_Constr
then
15000 ("parent subtype of full type must be unconstrained",
15005 -- Check the rules of 7.3(12): if a partial view has neither known
15006 -- or unknown discriminants, then the full type declaration shall
15007 -- define a definite subtype.
15009 elsif not Has_Unknown_Discriminants
(Priv_T
)
15010 and then not Has_Discriminants
(Priv_T
)
15011 and then not Is_Constrained
(Full_T
)
15014 ("full view must define a constrained type if partial view"
15015 & " has no discriminants", Full_T
);
15018 -- ??????? Do we implement the following properly ?????
15019 -- If the ancestor subtype of a private extension has constrained
15020 -- discriminants, then the parent subtype of the full view shall
15021 -- impose a statically matching constraint on those discriminants
15025 -- For untagged types, verify that a type without discriminants
15026 -- is not completed with an unconstrained type.
15028 if not Is_Indefinite_Subtype
(Priv_T
)
15029 and then Is_Indefinite_Subtype
(Full_T
)
15031 Error_Msg_N
("full view of type must be definite subtype", Full_T
);
15035 -- AI-419: verify that the use of "limited" is consistent
15038 Orig_Decl
: constant Node_Id
:= Original_Node
(N
);
15041 if Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
15042 and then not Limited_Present
(Parent
(Priv_T
))
15043 and then not Synchronized_Present
(Parent
(Priv_T
))
15044 and then Nkind
(Orig_Decl
) = N_Full_Type_Declaration
15046 (Type_Definition
(Orig_Decl
)) = N_Derived_Type_Definition
15047 and then Limited_Present
(Type_Definition
(Orig_Decl
))
15050 ("full view of non-limited extension cannot be limited", N
);
15054 -- Ada 2005 (AI-443): A synchronized private extension must be
15055 -- completed by a task or protected type.
15057 if Ada_Version
>= Ada_05
15058 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
15059 and then Synchronized_Present
(Parent
(Priv_T
))
15060 and then not Is_Concurrent_Type
(Full_T
)
15062 Error_Msg_N
("full view of synchronized extension must " &
15063 "be synchronized type", N
);
15066 -- Ada 2005 AI-363: if the full view has discriminants with
15067 -- defaults, it is illegal to declare constrained access subtypes
15068 -- whose designated type is the current type. This allows objects
15069 -- of the type that are declared in the heap to be unconstrained.
15071 if not Has_Unknown_Discriminants
(Priv_T
)
15072 and then not Has_Discriminants
(Priv_T
)
15073 and then Has_Discriminants
(Full_T
)
15075 Present
(Discriminant_Default_Value
(First_Discriminant
(Full_T
)))
15077 Set_Has_Constrained_Partial_View
(Full_T
);
15078 Set_Has_Constrained_Partial_View
(Priv_T
);
15081 -- Create a full declaration for all its subtypes recorded in
15082 -- Private_Dependents and swap them similarly to the base type. These
15083 -- are subtypes that have been define before the full declaration of
15084 -- the private type. We also swap the entry in Private_Dependents list
15085 -- so we can properly restore the private view on exit from the scope.
15088 Priv_Elmt
: Elmt_Id
;
15093 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Priv_T
));
15094 while Present
(Priv_Elmt
) loop
15095 Priv
:= Node
(Priv_Elmt
);
15097 if Ekind
(Priv
) = E_Private_Subtype
15098 or else Ekind
(Priv
) = E_Limited_Private_Subtype
15099 or else Ekind
(Priv
) = E_Record_Subtype_With_Private
15101 Full
:= Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
15102 Set_Is_Itype
(Full
);
15103 Set_Parent
(Full
, Parent
(Priv
));
15104 Set_Associated_Node_For_Itype
(Full
, N
);
15106 -- Now we need to complete the private subtype, but since the
15107 -- base type has already been swapped, we must also swap the
15108 -- subtypes (and thus, reverse the arguments in the call to
15109 -- Complete_Private_Subtype).
15111 Copy_And_Swap
(Priv
, Full
);
15112 Complete_Private_Subtype
(Full
, Priv
, Full_T
, N
);
15113 Replace_Elmt
(Priv_Elmt
, Full
);
15116 Next_Elmt
(Priv_Elmt
);
15120 -- If the private view was tagged, copy the new primitive operations
15121 -- from the private view to the full view.
15123 if Is_Tagged_Type
(Full_T
)
15124 and then not Is_Concurrent_Type
(Full_T
)
15127 Priv_List
: Elist_Id
;
15128 Full_List
: constant Elist_Id
:= Primitive_Operations
(Full_T
);
15131 D_Type
: Entity_Id
;
15134 if Is_Tagged_Type
(Priv_T
) then
15135 Priv_List
:= Primitive_Operations
(Priv_T
);
15137 P1
:= First_Elmt
(Priv_List
);
15138 while Present
(P1
) loop
15141 -- Transfer explicit primitives, not those inherited from
15142 -- parent of partial view, which will be re-inherited on
15145 if Comes_From_Source
(Prim
) then
15146 P2
:= First_Elmt
(Full_List
);
15147 while Present
(P2
) and then Node
(P2
) /= Prim
loop
15151 -- If not found, that is a new one
15154 Append_Elmt
(Prim
, Full_List
);
15162 -- In this case the partial view is untagged, so here we locate
15163 -- all of the earlier primitives that need to be treated as
15164 -- dispatching (those that appear between the two views). Note
15165 -- that these additional operations must all be new operations
15166 -- (any earlier operations that override inherited operations
15167 -- of the full view will already have been inserted in the
15168 -- primitives list, marked by Check_Operation_From_Private_View
15169 -- as dispatching. Note that implicit "/=" operators are
15170 -- excluded from being added to the primitives list since they
15171 -- shouldn't be treated as dispatching (tagged "/=" is handled
15174 Prim
:= Next_Entity
(Full_T
);
15175 while Present
(Prim
) and then Prim
/= Priv_T
loop
15176 if Ekind
(Prim
) = E_Procedure
15178 Ekind
(Prim
) = E_Function
15181 D_Type
:= Find_Dispatching_Type
(Prim
);
15184 and then (Chars
(Prim
) /= Name_Op_Ne
15185 or else Comes_From_Source
(Prim
))
15187 Check_Controlling_Formals
(Full_T
, Prim
);
15189 if not Is_Dispatching_Operation
(Prim
) then
15190 Append_Elmt
(Prim
, Full_List
);
15191 Set_Is_Dispatching_Operation
(Prim
, True);
15192 Set_DT_Position
(Prim
, No_Uint
);
15195 elsif Is_Dispatching_Operation
(Prim
)
15196 and then D_Type
/= Full_T
15199 -- Verify that it is not otherwise controlled by a
15200 -- formal or a return value of type T.
15202 Check_Controlling_Formals
(D_Type
, Prim
);
15206 Next_Entity
(Prim
);
15210 -- For the tagged case, the two views can share the same
15211 -- Primitive Operation list and the same class wide type.
15212 -- Update attributes of the class-wide type which depend on
15213 -- the full declaration.
15215 if Is_Tagged_Type
(Priv_T
) then
15216 Set_Primitive_Operations
(Priv_T
, Full_List
);
15217 Set_Class_Wide_Type
15218 (Base_Type
(Full_T
), Class_Wide_Type
(Priv_T
));
15220 Set_Has_Task
(Class_Wide_Type
(Priv_T
), Has_Task
(Full_T
));
15225 -- Ada 2005 AI 161: Check preelaboratable initialization consistency
15227 if Known_To_Have_Preelab_Init
(Priv_T
) then
15229 -- Case where there is a pragma Preelaborable_Initialization. We
15230 -- always allow this in predefined units, which is a bit of a kludge,
15231 -- but it means we don't have to struggle to meet the requirements in
15232 -- the RM for having Preelaborable Initialization. Otherwise we
15233 -- require that the type meets the RM rules. But we can't check that
15234 -- yet, because of the rule about overriding Ininitialize, so we
15235 -- simply set a flag that will be checked at freeze time.
15237 if not In_Predefined_Unit
(Full_T
) then
15238 Set_Must_Have_Preelab_Init
(Full_T
);
15242 -- If pragma CPP_Class was applied to the private type declaration,
15243 -- propagate it now to the full type declaration.
15245 if Is_CPP_Class
(Priv_T
) then
15246 Set_Is_CPP_Class
(Full_T
);
15247 Set_Convention
(Full_T
, Convention_CPP
);
15249 end Process_Full_View
;
15251 -----------------------------------
15252 -- Process_Incomplete_Dependents --
15253 -----------------------------------
15255 procedure Process_Incomplete_Dependents
15257 Full_T
: Entity_Id
;
15260 Inc_Elmt
: Elmt_Id
;
15261 Priv_Dep
: Entity_Id
;
15262 New_Subt
: Entity_Id
;
15264 Disc_Constraint
: Elist_Id
;
15267 if No
(Private_Dependents
(Inc_T
)) then
15271 -- Itypes that may be generated by the completion of an incomplete
15272 -- subtype are not used by the back-end and not attached to the tree.
15273 -- They are created only for constraint-checking purposes.
15275 Inc_Elmt
:= First_Elmt
(Private_Dependents
(Inc_T
));
15276 while Present
(Inc_Elmt
) loop
15277 Priv_Dep
:= Node
(Inc_Elmt
);
15279 if Ekind
(Priv_Dep
) = E_Subprogram_Type
then
15281 -- An Access_To_Subprogram type may have a return type or a
15282 -- parameter type that is incomplete. Replace with the full view.
15284 if Etype
(Priv_Dep
) = Inc_T
then
15285 Set_Etype
(Priv_Dep
, Full_T
);
15289 Formal
: Entity_Id
;
15292 Formal
:= First_Formal
(Priv_Dep
);
15293 while Present
(Formal
) loop
15294 if Etype
(Formal
) = Inc_T
then
15295 Set_Etype
(Formal
, Full_T
);
15298 Next_Formal
(Formal
);
15302 elsif Is_Overloadable
(Priv_Dep
) then
15304 -- A protected operation is never dispatching: only its
15305 -- wrapper operation (which has convention Ada) is.
15307 if Is_Tagged_Type
(Full_T
)
15308 and then Convention
(Priv_Dep
) /= Convention_Protected
15311 -- Subprogram has an access parameter whose designated type
15312 -- was incomplete. Reexamine declaration now, because it may
15313 -- be a primitive operation of the full type.
15315 Check_Operation_From_Incomplete_Type
(Priv_Dep
, Inc_T
);
15316 Set_Is_Dispatching_Operation
(Priv_Dep
);
15317 Check_Controlling_Formals
(Full_T
, Priv_Dep
);
15320 elsif Ekind
(Priv_Dep
) = E_Subprogram_Body
then
15322 -- Can happen during processing of a body before the completion
15323 -- of a TA type. Ignore, because spec is also on dependent list.
15327 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
15328 -- corresponding subtype of the full view.
15330 elsif Ekind
(Priv_Dep
) = E_Incomplete_Subtype
then
15331 Set_Subtype_Indication
15332 (Parent
(Priv_Dep
), New_Reference_To
(Full_T
, Sloc
(Priv_Dep
)));
15333 Set_Etype
(Priv_Dep
, Full_T
);
15334 Set_Ekind
(Priv_Dep
, Subtype_Kind
(Ekind
(Full_T
)));
15335 Set_Analyzed
(Parent
(Priv_Dep
), False);
15337 -- Reanalyze the declaration, suppressing the call to
15338 -- Enter_Name to avoid duplicate names.
15340 Analyze_Subtype_Declaration
15341 (N
=> Parent
(Priv_Dep
),
15344 -- Dependent is a subtype
15347 -- We build a new subtype indication using the full view of the
15348 -- incomplete parent. The discriminant constraints have been
15349 -- elaborated already at the point of the subtype declaration.
15351 New_Subt
:= Create_Itype
(E_Void
, N
);
15353 if Has_Discriminants
(Full_T
) then
15354 Disc_Constraint
:= Discriminant_Constraint
(Priv_Dep
);
15356 Disc_Constraint
:= No_Elist
;
15359 Build_Discriminated_Subtype
(Full_T
, New_Subt
, Disc_Constraint
, N
);
15360 Set_Full_View
(Priv_Dep
, New_Subt
);
15363 Next_Elmt
(Inc_Elmt
);
15365 end Process_Incomplete_Dependents
;
15367 --------------------------------
15368 -- Process_Range_Expr_In_Decl --
15369 --------------------------------
15371 procedure Process_Range_Expr_In_Decl
15374 Check_List
: List_Id
:= Empty_List
;
15375 R_Check_Off
: Boolean := False)
15378 R_Checks
: Check_Result
;
15379 Type_Decl
: Node_Id
;
15380 Def_Id
: Entity_Id
;
15383 Analyze_And_Resolve
(R
, Base_Type
(T
));
15385 if Nkind
(R
) = N_Range
then
15386 Lo
:= Low_Bound
(R
);
15387 Hi
:= High_Bound
(R
);
15389 -- We need to ensure validity of the bounds here, because if we
15390 -- go ahead and do the expansion, then the expanded code will get
15391 -- analyzed with range checks suppressed and we miss the check.
15393 Validity_Check_Range
(R
);
15395 -- If there were errors in the declaration, try and patch up some
15396 -- common mistakes in the bounds. The cases handled are literals
15397 -- which are Integer where the expected type is Real and vice versa.
15398 -- These corrections allow the compilation process to proceed further
15399 -- along since some basic assumptions of the format of the bounds
15402 if Etype
(R
) = Any_Type
then
15404 if Nkind
(Lo
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
15406 Make_Real_Literal
(Sloc
(Lo
), UR_From_Uint
(Intval
(Lo
))));
15408 elsif Nkind
(Hi
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
15410 Make_Real_Literal
(Sloc
(Hi
), UR_From_Uint
(Intval
(Hi
))));
15412 elsif Nkind
(Lo
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
15414 Make_Integer_Literal
(Sloc
(Lo
), UR_To_Uint
(Realval
(Lo
))));
15416 elsif Nkind
(Hi
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
15418 Make_Integer_Literal
(Sloc
(Hi
), UR_To_Uint
(Realval
(Hi
))));
15425 -- If the bounds of the range have been mistakenly given as string
15426 -- literals (perhaps in place of character literals), then an error
15427 -- has already been reported, but we rewrite the string literal as a
15428 -- bound of the range's type to avoid blowups in later processing
15429 -- that looks at static values.
15431 if Nkind
(Lo
) = N_String_Literal
then
15433 Make_Attribute_Reference
(Sloc
(Lo
),
15434 Attribute_Name
=> Name_First
,
15435 Prefix
=> New_Reference_To
(T
, Sloc
(Lo
))));
15436 Analyze_And_Resolve
(Lo
);
15439 if Nkind
(Hi
) = N_String_Literal
then
15441 Make_Attribute_Reference
(Sloc
(Hi
),
15442 Attribute_Name
=> Name_First
,
15443 Prefix
=> New_Reference_To
(T
, Sloc
(Hi
))));
15444 Analyze_And_Resolve
(Hi
);
15447 -- If bounds aren't scalar at this point then exit, avoiding
15448 -- problems with further processing of the range in this procedure.
15450 if not Is_Scalar_Type
(Etype
(Lo
)) then
15454 -- Resolve (actually Sem_Eval) has checked that the bounds are in
15455 -- then range of the base type. Here we check whether the bounds
15456 -- are in the range of the subtype itself. Note that if the bounds
15457 -- represent the null range the Constraint_Error exception should
15460 -- ??? The following code should be cleaned up as follows
15462 -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
15463 -- is done in the call to Range_Check (R, T); below
15465 -- 2. The use of R_Check_Off should be investigated and possibly
15466 -- removed, this would clean up things a bit.
15468 if Is_Null_Range
(Lo
, Hi
) then
15472 -- Capture values of bounds and generate temporaries for them
15473 -- if needed, before applying checks, since checks may cause
15474 -- duplication of the expression without forcing evaluation.
15476 if Expander_Active
then
15477 Force_Evaluation
(Lo
);
15478 Force_Evaluation
(Hi
);
15481 -- We use a flag here instead of suppressing checks on the
15482 -- type because the type we check against isn't necessarily
15483 -- the place where we put the check.
15485 if not R_Check_Off
then
15486 R_Checks
:= Get_Range_Checks
(R
, T
);
15488 -- Look up tree to find an appropriate insertion point.
15489 -- This seems really junk code, and very brittle, couldn't
15490 -- we just use an insert actions call of some kind ???
15492 Type_Decl
:= Parent
(R
);
15493 while Present
(Type_Decl
) and then not
15494 (Nkind
(Type_Decl
) = N_Full_Type_Declaration
15496 Nkind
(Type_Decl
) = N_Subtype_Declaration
15498 Nkind
(Type_Decl
) = N_Loop_Statement
15500 Nkind
(Type_Decl
) = N_Task_Type_Declaration
15502 Nkind
(Type_Decl
) = N_Single_Task_Declaration
15504 Nkind
(Type_Decl
) = N_Protected_Type_Declaration
15506 Nkind
(Type_Decl
) = N_Single_Protected_Declaration
)
15508 Type_Decl
:= Parent
(Type_Decl
);
15511 -- Why would Type_Decl not be present??? Without this test,
15512 -- short regression tests fail.
15514 if Present
(Type_Decl
) then
15516 -- Case of loop statement (more comments ???)
15518 if Nkind
(Type_Decl
) = N_Loop_Statement
then
15523 Indic
:= Parent
(R
);
15524 while Present
(Indic
) and then not
15525 (Nkind
(Indic
) = N_Subtype_Indication
)
15527 Indic
:= Parent
(Indic
);
15530 if Present
(Indic
) then
15531 Def_Id
:= Etype
(Subtype_Mark
(Indic
));
15533 Insert_Range_Checks
15539 Do_Before
=> True);
15543 -- All other cases (more comments ???)
15546 Def_Id
:= Defining_Identifier
(Type_Decl
);
15548 if (Ekind
(Def_Id
) = E_Record_Type
15549 and then Depends_On_Discriminant
(R
))
15551 (Ekind
(Def_Id
) = E_Protected_Type
15552 and then Has_Discriminants
(Def_Id
))
15554 Append_Range_Checks
15555 (R_Checks
, Check_List
, Def_Id
, Sloc
(Type_Decl
), R
);
15558 Insert_Range_Checks
15559 (R_Checks
, Type_Decl
, Def_Id
, Sloc
(Type_Decl
), R
);
15567 elsif Expander_Active
then
15568 Get_Index_Bounds
(R
, Lo
, Hi
);
15569 Force_Evaluation
(Lo
);
15570 Force_Evaluation
(Hi
);
15572 end Process_Range_Expr_In_Decl
;
15574 --------------------------------------
15575 -- Process_Real_Range_Specification --
15576 --------------------------------------
15578 procedure Process_Real_Range_Specification
(Def
: Node_Id
) is
15579 Spec
: constant Node_Id
:= Real_Range_Specification
(Def
);
15582 Err
: Boolean := False;
15584 procedure Analyze_Bound
(N
: Node_Id
);
15585 -- Analyze and check one bound
15587 -------------------
15588 -- Analyze_Bound --
15589 -------------------
15591 procedure Analyze_Bound
(N
: Node_Id
) is
15593 Analyze_And_Resolve
(N
, Any_Real
);
15595 if not Is_OK_Static_Expression
(N
) then
15596 Flag_Non_Static_Expr
15597 ("bound in real type definition is not static!", N
);
15602 -- Start of processing for Process_Real_Range_Specification
15605 if Present
(Spec
) then
15606 Lo
:= Low_Bound
(Spec
);
15607 Hi
:= High_Bound
(Spec
);
15608 Analyze_Bound
(Lo
);
15609 Analyze_Bound
(Hi
);
15611 -- If error, clear away junk range specification
15614 Set_Real_Range_Specification
(Def
, Empty
);
15617 end Process_Real_Range_Specification
;
15619 ---------------------
15620 -- Process_Subtype --
15621 ---------------------
15623 function Process_Subtype
15625 Related_Nod
: Node_Id
;
15626 Related_Id
: Entity_Id
:= Empty
;
15627 Suffix
: Character := ' ') return Entity_Id
15630 Def_Id
: Entity_Id
;
15631 Error_Node
: Node_Id
;
15632 Full_View_Id
: Entity_Id
;
15633 Subtype_Mark_Id
: Entity_Id
;
15635 May_Have_Null_Exclusion
: Boolean;
15637 procedure Check_Incomplete
(T
: Entity_Id
);
15638 -- Called to verify that an incomplete type is not used prematurely
15640 ----------------------
15641 -- Check_Incomplete --
15642 ----------------------
15644 procedure Check_Incomplete
(T
: Entity_Id
) is
15646 -- Ada 2005 (AI-412): Incomplete subtypes are legal
15648 if Ekind
(Root_Type
(Entity
(T
))) = E_Incomplete_Type
15650 not (Ada_Version
>= Ada_05
15652 (Nkind
(Parent
(T
)) = N_Subtype_Declaration
15654 (Nkind
(Parent
(T
)) = N_Subtype_Indication
15655 and then Nkind
(Parent
(Parent
(T
))) =
15656 N_Subtype_Declaration
)))
15658 Error_Msg_N
("invalid use of type before its full declaration", T
);
15660 end Check_Incomplete
;
15662 -- Start of processing for Process_Subtype
15665 -- Case of no constraints present
15667 if Nkind
(S
) /= N_Subtype_Indication
then
15670 Check_Incomplete
(S
);
15673 -- Ada 2005 (AI-231): Static check
15675 if Ada_Version
>= Ada_05
15676 and then Present
(P
)
15677 and then Null_Exclusion_Present
(P
)
15678 and then Nkind
(P
) /= N_Access_To_Object_Definition
15679 and then not Is_Access_Type
(Entity
(S
))
15681 Error_Msg_N
("`NOT NULL` only allowed for an access type", S
);
15684 May_Have_Null_Exclusion
:=
15685 Nkind
(P
) = N_Access_Definition
15686 or else Nkind
(P
) = N_Access_Function_Definition
15687 or else Nkind
(P
) = N_Access_Procedure_Definition
15688 or else Nkind
(P
) = N_Access_To_Object_Definition
15689 or else Nkind
(P
) = N_Allocator
15690 or else Nkind
(P
) = N_Component_Definition
15691 or else Nkind
(P
) = N_Derived_Type_Definition
15692 or else Nkind
(P
) = N_Discriminant_Specification
15693 or else Nkind
(P
) = N_Object_Declaration
15694 or else Nkind
(P
) = N_Parameter_Specification
15695 or else Nkind
(P
) = N_Subtype_Declaration
;
15697 -- Create an Itype that is a duplicate of Entity (S) but with the
15698 -- null-exclusion attribute
15700 if May_Have_Null_Exclusion
15701 and then Is_Access_Type
(Entity
(S
))
15702 and then Null_Exclusion_Present
(P
)
15704 -- No need to check the case of an access to object definition.
15705 -- It is correct to define double not-null pointers.
15708 -- type Not_Null_Int_Ptr is not null access Integer;
15709 -- type Acc is not null access Not_Null_Int_Ptr;
15711 and then Nkind
(P
) /= N_Access_To_Object_Definition
15713 if Can_Never_Be_Null
(Entity
(S
)) then
15714 case Nkind
(Related_Nod
) is
15715 when N_Full_Type_Declaration
=>
15716 if Nkind
(Type_Definition
(Related_Nod
))
15717 in N_Array_Type_Definition
15721 (Component_Definition
15722 (Type_Definition
(Related_Nod
)));
15725 Subtype_Indication
(Type_Definition
(Related_Nod
));
15728 when N_Subtype_Declaration
=>
15729 Error_Node
:= Subtype_Indication
(Related_Nod
);
15731 when N_Object_Declaration
=>
15732 Error_Node
:= Object_Definition
(Related_Nod
);
15734 when N_Component_Declaration
=>
15736 Subtype_Indication
(Component_Definition
(Related_Nod
));
15739 pragma Assert
(False);
15740 Error_Node
:= Related_Nod
;
15744 ("`NOT NULL` not allowed (& already excludes null)",
15750 Create_Null_Excluding_Itype
15752 Related_Nod
=> P
));
15753 Set_Entity
(S
, Etype
(S
));
15758 -- Case of constraint present, so that we have an N_Subtype_Indication
15759 -- node (this node is created only if constraints are present).
15762 Find_Type
(Subtype_Mark
(S
));
15764 if Nkind
(Parent
(S
)) /= N_Access_To_Object_Definition
15766 (Nkind
(Parent
(S
)) = N_Subtype_Declaration
15767 and then Is_Itype
(Defining_Identifier
(Parent
(S
))))
15769 Check_Incomplete
(Subtype_Mark
(S
));
15773 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
15775 -- Explicit subtype declaration case
15777 if Nkind
(P
) = N_Subtype_Declaration
then
15778 Def_Id
:= Defining_Identifier
(P
);
15780 -- Explicit derived type definition case
15782 elsif Nkind
(P
) = N_Derived_Type_Definition
then
15783 Def_Id
:= Defining_Identifier
(Parent
(P
));
15785 -- Implicit case, the Def_Id must be created as an implicit type.
15786 -- The one exception arises in the case of concurrent types, array
15787 -- and access types, where other subsidiary implicit types may be
15788 -- created and must appear before the main implicit type. In these
15789 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
15790 -- has not yet been called to create Def_Id.
15793 if Is_Array_Type
(Subtype_Mark_Id
)
15794 or else Is_Concurrent_Type
(Subtype_Mark_Id
)
15795 or else Is_Access_Type
(Subtype_Mark_Id
)
15799 -- For the other cases, we create a new unattached Itype,
15800 -- and set the indication to ensure it gets attached later.
15804 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
15808 -- If the kind of constraint is invalid for this kind of type,
15809 -- then give an error, and then pretend no constraint was given.
15811 if not Is_Valid_Constraint_Kind
15812 (Ekind
(Subtype_Mark_Id
), Nkind
(Constraint
(S
)))
15815 ("incorrect constraint for this kind of type", Constraint
(S
));
15817 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
15819 -- Set Ekind of orphan itype, to prevent cascaded errors
15821 if Present
(Def_Id
) then
15822 Set_Ekind
(Def_Id
, Ekind
(Any_Type
));
15825 -- Make recursive call, having got rid of the bogus constraint
15827 return Process_Subtype
(S
, Related_Nod
, Related_Id
, Suffix
);
15830 -- Remaining processing depends on type
15832 case Ekind
(Subtype_Mark_Id
) is
15833 when Access_Kind
=>
15834 Constrain_Access
(Def_Id
, S
, Related_Nod
);
15837 and then Is_Itype
(Designated_Type
(Def_Id
))
15838 and then Nkind
(Related_Nod
) = N_Subtype_Declaration
15839 and then not Is_Incomplete_Type
(Designated_Type
(Def_Id
))
15841 Build_Itype_Reference
15842 (Designated_Type
(Def_Id
), Related_Nod
);
15846 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
15848 when Decimal_Fixed_Point_Kind
=>
15849 Constrain_Decimal
(Def_Id
, S
);
15851 when Enumeration_Kind
=>
15852 Constrain_Enumeration
(Def_Id
, S
);
15854 when Ordinary_Fixed_Point_Kind
=>
15855 Constrain_Ordinary_Fixed
(Def_Id
, S
);
15858 Constrain_Float
(Def_Id
, S
);
15860 when Integer_Kind
=>
15861 Constrain_Integer
(Def_Id
, S
);
15863 when E_Record_Type |
15866 E_Incomplete_Type
=>
15867 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
15869 when Private_Kind
=>
15870 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
15871 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
15873 -- In case of an invalid constraint prevent further processing
15874 -- since the type constructed is missing expected fields.
15876 if Etype
(Def_Id
) = Any_Type
then
15880 -- If the full view is that of a task with discriminants,
15881 -- we must constrain both the concurrent type and its
15882 -- corresponding record type. Otherwise we will just propagate
15883 -- the constraint to the full view, if available.
15885 if Present
(Full_View
(Subtype_Mark_Id
))
15886 and then Has_Discriminants
(Subtype_Mark_Id
)
15887 and then Is_Concurrent_Type
(Full_View
(Subtype_Mark_Id
))
15890 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
15892 Set_Entity
(Subtype_Mark
(S
), Full_View
(Subtype_Mark_Id
));
15893 Constrain_Concurrent
(Full_View_Id
, S
,
15894 Related_Nod
, Related_Id
, Suffix
);
15895 Set_Entity
(Subtype_Mark
(S
), Subtype_Mark_Id
);
15896 Set_Full_View
(Def_Id
, Full_View_Id
);
15898 -- Introduce an explicit reference to the private subtype,
15899 -- to prevent scope anomalies in gigi if first use appears
15900 -- in a nested context, e.g. a later function body.
15901 -- Should this be generated in other contexts than a full
15902 -- type declaration?
15904 if Is_Itype
(Def_Id
)
15906 Nkind
(Parent
(P
)) = N_Full_Type_Declaration
15908 Build_Itype_Reference
(Def_Id
, Parent
(P
));
15912 Prepare_Private_Subtype_Completion
(Def_Id
, Related_Nod
);
15915 when Concurrent_Kind
=>
15916 Constrain_Concurrent
(Def_Id
, S
,
15917 Related_Nod
, Related_Id
, Suffix
);
15920 Error_Msg_N
("invalid subtype mark in subtype indication", S
);
15923 -- Size and Convention are always inherited from the base type
15925 Set_Size_Info
(Def_Id
, (Subtype_Mark_Id
));
15926 Set_Convention
(Def_Id
, Convention
(Subtype_Mark_Id
));
15930 end Process_Subtype
;
15932 ---------------------------------------
15933 -- Check_Anonymous_Access_Components --
15934 ---------------------------------------
15936 procedure Check_Anonymous_Access_Components
15937 (Typ_Decl
: Node_Id
;
15940 Comp_List
: Node_Id
)
15942 Loc
: constant Source_Ptr
:= Sloc
(Typ_Decl
);
15943 Anon_Access
: Entity_Id
;
15946 Comp_Def
: Node_Id
;
15948 Type_Def
: Node_Id
;
15950 procedure Build_Incomplete_Type_Declaration
;
15951 -- If the record type contains components that include an access to the
15952 -- current record, then create an incomplete type declaration for the
15953 -- record, to be used as the designated type of the anonymous access.
15954 -- This is done only once, and only if there is no previous partial
15955 -- view of the type.
15957 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean;
15958 -- Check whether an access definition includes a reference to
15959 -- the enclosing record type. The reference can be a subtype
15960 -- mark in the access definition itself, or a 'Class attribute
15961 -- reference, or recursively a reference appearing in a parameter
15962 -- type in an access_to_subprogram definition.
15964 --------------------------------------
15965 -- Build_Incomplete_Type_Declaration --
15966 --------------------------------------
15968 procedure Build_Incomplete_Type_Declaration
is
15974 -- If there is a previous partial view, no need to create a new one
15975 -- If the partial view, given by Prev, is incomplete, If Prev is
15976 -- a private declaration, full declaration is flagged accordingly.
15978 if Prev
/= Typ
then
15979 if Tagged_Present
(Type_Definition
(Typ_Decl
)) then
15980 Make_Class_Wide_Type
(Prev
);
15981 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Prev
));
15982 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
15987 elsif Has_Private_Declaration
(Typ
) then
15990 -- If there was a previous anonymous access type, the incomplete
15991 -- type declaration will have been created already.
15993 elsif Present
(Current_Entity
(Typ
))
15994 and then Ekind
(Current_Entity
(Typ
)) = E_Incomplete_Type
15995 and then Full_View
(Current_Entity
(Typ
)) = Typ
16000 Inc_T
:= Make_Defining_Identifier
(Loc
, Chars
(Typ
));
16001 Decl
:= Make_Incomplete_Type_Declaration
(Loc
, Inc_T
);
16003 -- Type has already been inserted into the current scope.
16004 -- Remove it, and add incomplete declaration for type, so
16005 -- that subsequent anonymous access types can use it.
16006 -- The entity is unchained from the homonym list and from
16007 -- immediate visibility. After analysis, the entity in the
16008 -- incomplete declaration becomes immediately visible in the
16009 -- record declaration that follows.
16011 H
:= Current_Entity
(Typ
);
16014 Set_Name_Entity_Id
(Chars
(Typ
), Homonym
(Typ
));
16017 and then Homonym
(H
) /= Typ
16019 H
:= Homonym
(Typ
);
16022 Set_Homonym
(H
, Homonym
(Typ
));
16025 Insert_Before
(Typ_Decl
, Decl
);
16027 Set_Full_View
(Inc_T
, Typ
);
16029 if (Nkind
(Type_Definition
(Typ_Decl
)) = N_Derived_Type_Definition
16032 (Record_Extension_Part
(Type_Definition
(Typ_Decl
))))
16033 or else Tagged_Present
(Type_Definition
(Typ_Decl
))
16035 -- Create a common class-wide type for both views, and set
16036 -- the etype of the class-wide type to the full view.
16038 Make_Class_Wide_Type
(Inc_T
);
16039 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Inc_T
));
16040 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
16043 end Build_Incomplete_Type_Declaration
;
16049 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean is
16051 Type_Id
: constant Name_Id
:= Chars
(Typ
);
16053 function Names_T
(Nam
: Node_Id
) return Boolean;
16054 -- The record type has not been introduced in the current scope
16055 -- yet, so we must examine the name of the type itself, either
16056 -- an identifier T, or an expanded name of the form P.T, where
16057 -- P denotes the current scope.
16063 function Names_T
(Nam
: Node_Id
) return Boolean is
16065 if Nkind
(Nam
) = N_Identifier
then
16066 return Chars
(Nam
) = Type_Id
;
16068 elsif Nkind
(Nam
) = N_Selected_Component
then
16069 if Chars
(Selector_Name
(Nam
)) = Type_Id
then
16070 if Nkind
(Prefix
(Nam
)) = N_Identifier
then
16071 return Chars
(Prefix
(Nam
)) = Chars
(Current_Scope
);
16073 elsif Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
16074 return Chars
(Selector_Name
(Prefix
(Nam
))) =
16075 Chars
(Current_Scope
);
16087 -- Start of processing for Mentions_T
16090 if No
(Access_To_Subprogram_Definition
(Acc_Def
)) then
16091 Subt
:= Subtype_Mark
(Acc_Def
);
16093 if Nkind
(Subt
) = N_Identifier
then
16094 return Chars
(Subt
) = Type_Id
;
16096 -- Reference can be through an expanded name which has not been
16097 -- analyzed yet, and which designates enclosing scopes.
16099 elsif Nkind
(Subt
) = N_Selected_Component
then
16100 if Names_T
(Subt
) then
16103 -- Otherwise it must denote an entity that is already visible.
16104 -- The access definition may name a subtype of the enclosing
16105 -- type, if there is a previous incomplete declaration for it.
16108 Find_Selected_Component
(Subt
);
16110 Is_Entity_Name
(Subt
)
16111 and then Scope
(Entity
(Subt
)) = Current_Scope
16112 and then (Chars
(Base_Type
(Entity
(Subt
))) = Type_Id
16114 (Is_Class_Wide_Type
(Entity
(Subt
))
16116 Chars
(Etype
(Base_Type
(Entity
(Subt
))))
16120 -- A reference to the current type may appear as the prefix of
16121 -- a 'Class attribute.
16123 elsif Nkind
(Subt
) = N_Attribute_Reference
16124 and then Attribute_Name
(Subt
) = Name_Class
16126 return Names_T
(Prefix
(Subt
));
16132 -- Component is an access_to_subprogram: examine its formals
16135 Param_Spec
: Node_Id
;
16140 (Parameter_Specifications
16141 (Access_To_Subprogram_Definition
(Acc_Def
)));
16142 while Present
(Param_Spec
) loop
16143 if Nkind
(Parameter_Type
(Param_Spec
))
16144 = N_Access_Definition
16145 and then Mentions_T
(Parameter_Type
(Param_Spec
))
16158 -- Start of processing for Check_Anonymous_Access_Components
16161 if No
(Comp_List
) then
16165 Comp
:= First
(Component_Items
(Comp_List
));
16166 while Present
(Comp
) loop
16167 if Nkind
(Comp
) = N_Component_Declaration
16169 (Access_Definition
(Component_Definition
(Comp
)))
16171 Mentions_T
(Access_Definition
(Component_Definition
(Comp
)))
16173 Comp_Def
:= Component_Definition
(Comp
);
16175 Access_To_Subprogram_Definition
16176 (Access_Definition
(Comp_Def
));
16178 Build_Incomplete_Type_Declaration
;
16180 Make_Defining_Identifier
(Loc
,
16181 Chars
=> New_Internal_Name
('S'));
16183 -- Create a declaration for the anonymous access type: either
16184 -- an access_to_object or an access_to_subprogram.
16186 if Present
(Acc_Def
) then
16187 if Nkind
(Acc_Def
) = N_Access_Function_Definition
then
16189 Make_Access_Function_Definition
(Loc
,
16190 Parameter_Specifications
=>
16191 Parameter_Specifications
(Acc_Def
),
16192 Result_Definition
=> Result_Definition
(Acc_Def
));
16195 Make_Access_Procedure_Definition
(Loc
,
16196 Parameter_Specifications
=>
16197 Parameter_Specifications
(Acc_Def
));
16202 Make_Access_To_Object_Definition
(Loc
,
16203 Subtype_Indication
=>
16206 (Access_Definition
(Comp_Def
))));
16208 Set_Constant_Present
16209 (Type_Def
, Constant_Present
(Access_Definition
(Comp_Def
)));
16211 (Type_Def
, All_Present
(Access_Definition
(Comp_Def
)));
16214 Set_Null_Exclusion_Present
16216 Null_Exclusion_Present
(Access_Definition
(Comp_Def
)));
16219 Make_Full_Type_Declaration
(Loc
,
16220 Defining_Identifier
=> Anon_Access
,
16221 Type_Definition
=> Type_Def
);
16223 Insert_Before
(Typ_Decl
, Decl
);
16226 -- If an access to object, Preserve entity of designated type,
16227 -- for ASIS use, before rewriting the component definition.
16229 if No
(Acc_Def
) then
16234 Desig
:= Entity
(Subtype_Indication
(Type_Def
));
16236 -- If the access definition is to the current record,
16237 -- the visible entity at this point is an incomplete
16238 -- type. Retrieve the full view to simplify ASIS queries
16240 if Ekind
(Desig
) = E_Incomplete_Type
then
16241 Desig
:= Full_View
(Desig
);
16245 (Subtype_Mark
(Access_Definition
(Comp_Def
)), Desig
);
16250 Make_Component_Definition
(Loc
,
16251 Subtype_Indication
=>
16252 New_Occurrence_Of
(Anon_Access
, Loc
)));
16253 Set_Ekind
(Anon_Access
, E_Anonymous_Access_Type
);
16254 Set_Is_Local_Anonymous_Access
(Anon_Access
);
16260 if Present
(Variant_Part
(Comp_List
)) then
16264 V
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
16265 while Present
(V
) loop
16266 Check_Anonymous_Access_Components
16267 (Typ_Decl
, Typ
, Prev
, Component_List
(V
));
16268 Next_Non_Pragma
(V
);
16272 end Check_Anonymous_Access_Components
;
16274 -----------------------------
16275 -- Record_Type_Declaration --
16276 -----------------------------
16278 procedure Record_Type_Declaration
16283 Def
: constant Node_Id
:= Type_Definition
(N
);
16284 Is_Tagged
: Boolean;
16285 Tag_Comp
: Entity_Id
;
16288 -- These flags must be initialized before calling Process_Discriminants
16289 -- because this routine makes use of them.
16291 Set_Ekind
(T
, E_Record_Type
);
16293 Init_Size_Align
(T
);
16294 Set_Abstract_Interfaces
(T
, No_Elist
);
16295 Set_Stored_Constraint
(T
, No_Elist
);
16299 if Ada_Version
< Ada_05
16300 or else not Interface_Present
(Def
)
16302 -- The flag Is_Tagged_Type might have already been set by
16303 -- Find_Type_Name if it detected an error for declaration T. This
16304 -- arises in the case of private tagged types where the full view
16305 -- omits the word tagged.
16308 Tagged_Present
(Def
)
16309 or else (Serious_Errors_Detected
> 0 and then Is_Tagged_Type
(T
));
16311 Set_Is_Tagged_Type
(T
, Is_Tagged
);
16312 Set_Is_Limited_Record
(T
, Limited_Present
(Def
));
16314 -- Type is abstract if full declaration carries keyword, or if
16315 -- previous partial view did.
16317 Set_Is_Abstract_Type
(T
, Is_Abstract_Type
(T
)
16318 or else Abstract_Present
(Def
));
16322 Analyze_Interface_Declaration
(T
, Def
);
16324 if Present
(Discriminant_Specifications
(N
)) then
16326 ("interface types cannot have discriminants",
16327 Defining_Identifier
16328 (First
(Discriminant_Specifications
(N
))));
16332 -- First pass: if there are self-referential access components,
16333 -- create the required anonymous access type declarations, and if
16334 -- need be an incomplete type declaration for T itself.
16336 Check_Anonymous_Access_Components
(N
, T
, Prev
, Component_List
(Def
));
16338 if Ada_Version
>= Ada_05
16339 and then Present
(Interface_List
(Def
))
16341 Check_Abstract_Interfaces
(N
, Def
);
16344 Ifaces_List
: Elist_Id
;
16347 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
16348 -- already in the parents.
16350 Collect_Abstract_Interfaces
16352 Ifaces_List
=> Ifaces_List
,
16353 Exclude_Parent_Interfaces
=> True);
16355 Set_Abstract_Interfaces
(T
, Ifaces_List
);
16359 -- Records constitute a scope for the component declarations within.
16360 -- The scope is created prior to the processing of these declarations.
16361 -- Discriminants are processed first, so that they are visible when
16362 -- processing the other components. The Ekind of the record type itself
16363 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
16365 -- Enter record scope
16369 -- If an incomplete or private type declaration was already given for
16370 -- the type, then this scope already exists, and the discriminants have
16371 -- been declared within. We must verify that the full declaration
16372 -- matches the incomplete one.
16374 Check_Or_Process_Discriminants
(N
, T
, Prev
);
16376 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
16377 Set_Has_Delayed_Freeze
(T
, True);
16379 -- For tagged types add a manually analyzed component corresponding
16380 -- to the component _tag, the corresponding piece of tree will be
16381 -- expanded as part of the freezing actions if it is not a CPP_Class.
16385 -- Do not add the tag unless we are in expansion mode
16387 if Expander_Active
then
16388 Tag_Comp
:= Make_Defining_Identifier
(Sloc
(Def
), Name_uTag
);
16389 Enter_Name
(Tag_Comp
);
16391 Set_Is_Tag
(Tag_Comp
);
16392 Set_Is_Aliased
(Tag_Comp
);
16393 Set_Ekind
(Tag_Comp
, E_Component
);
16394 Set_Etype
(Tag_Comp
, RTE
(RE_Tag
));
16395 Set_DT_Entry_Count
(Tag_Comp
, No_Uint
);
16396 Set_Original_Record_Component
(Tag_Comp
, Tag_Comp
);
16397 Init_Component_Location
(Tag_Comp
);
16399 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
16400 -- implemented interfaces.
16402 if Has_Abstract_Interfaces
(T
) then
16403 Add_Interface_Tag_Components
(N
, T
);
16407 Make_Class_Wide_Type
(T
);
16408 Set_Primitive_Operations
(T
, New_Elmt_List
);
16411 -- We must suppress range checks when processing the components
16412 -- of a record in the presence of discriminants, since we don't
16413 -- want spurious checks to be generated during their analysis, but
16414 -- must reset the Suppress_Range_Checks flags after having processed
16415 -- the record definition.
16417 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
16418 -- couldn't we just use the normal range check suppression method here.
16419 -- That would seem cleaner ???
16421 if Has_Discriminants
(T
) and then not Range_Checks_Suppressed
(T
) then
16422 Set_Kill_Range_Checks
(T
, True);
16423 Record_Type_Definition
(Def
, Prev
);
16424 Set_Kill_Range_Checks
(T
, False);
16426 Record_Type_Definition
(Def
, Prev
);
16429 -- Exit from record scope
16433 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
16434 -- the implemented interfaces and associate them an aliased entity.
16437 and then not Is_Empty_List
(Interface_List
(Def
))
16440 Ifaces_List
: constant Elist_Id
:= New_Elmt_List
;
16442 Derive_Interface_Subprograms
(T
, T
, Ifaces_List
);
16445 end Record_Type_Declaration
;
16447 ----------------------------
16448 -- Record_Type_Definition --
16449 ----------------------------
16451 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
) is
16452 Component
: Entity_Id
;
16453 Ctrl_Components
: Boolean := False;
16454 Final_Storage_Only
: Boolean;
16458 if Ekind
(Prev_T
) = E_Incomplete_Type
then
16459 T
:= Full_View
(Prev_T
);
16464 Final_Storage_Only
:= not Is_Controlled
(T
);
16466 -- Ada 2005: check whether an explicit Limited is present in a derived
16467 -- type declaration.
16469 if Nkind
(Parent
(Def
)) = N_Derived_Type_Definition
16470 and then Limited_Present
(Parent
(Def
))
16472 Set_Is_Limited_Record
(T
);
16475 -- If the component list of a record type is defined by the reserved
16476 -- word null and there is no discriminant part, then the record type has
16477 -- no components and all records of the type are null records (RM 3.7)
16478 -- This procedure is also called to process the extension part of a
16479 -- record extension, in which case the current scope may have inherited
16483 or else No
(Component_List
(Def
))
16484 or else Null_Present
(Component_List
(Def
))
16489 Analyze_Declarations
(Component_Items
(Component_List
(Def
)));
16491 if Present
(Variant_Part
(Component_List
(Def
))) then
16492 Analyze
(Variant_Part
(Component_List
(Def
)));
16496 -- After completing the semantic analysis of the record definition,
16497 -- record components, both new and inherited, are accessible. Set their
16498 -- kind accordingly. Exclude malformed itypes from illegal declarations,
16499 -- whose Ekind may be void.
16501 Component
:= First_Entity
(Current_Scope
);
16502 while Present
(Component
) loop
16503 if Ekind
(Component
) = E_Void
16504 and then not Is_Itype
(Component
)
16506 Set_Ekind
(Component
, E_Component
);
16507 Init_Component_Location
(Component
);
16510 if Has_Task
(Etype
(Component
)) then
16514 if Ekind
(Component
) /= E_Component
then
16517 elsif Has_Controlled_Component
(Etype
(Component
))
16518 or else (Chars
(Component
) /= Name_uParent
16519 and then Is_Controlled
(Etype
(Component
)))
16521 Set_Has_Controlled_Component
(T
, True);
16522 Final_Storage_Only
:= Final_Storage_Only
16523 and then Finalize_Storage_Only
(Etype
(Component
));
16524 Ctrl_Components
:= True;
16527 Next_Entity
(Component
);
16530 -- A Type is Finalize_Storage_Only only if all its controlled components
16533 if Ctrl_Components
then
16534 Set_Finalize_Storage_Only
(T
, Final_Storage_Only
);
16537 -- Place reference to end record on the proper entity, which may
16538 -- be a partial view.
16540 if Present
(Def
) then
16541 Process_End_Label
(Def
, 'e', Prev_T
);
16543 end Record_Type_Definition
;
16545 ------------------------
16546 -- Replace_Components --
16547 ------------------------
16549 procedure Replace_Components
(Typ
: Entity_Id
; Decl
: Node_Id
) is
16550 function Process
(N
: Node_Id
) return Traverse_Result
;
16556 function Process
(N
: Node_Id
) return Traverse_Result
is
16560 if Nkind
(N
) = N_Discriminant_Specification
then
16561 Comp
:= First_Discriminant
(Typ
);
16562 while Present
(Comp
) loop
16563 if Chars
(Comp
) = Chars
(Defining_Identifier
(N
)) then
16564 Set_Defining_Identifier
(N
, Comp
);
16568 Next_Discriminant
(Comp
);
16571 elsif Nkind
(N
) = N_Component_Declaration
then
16572 Comp
:= First_Component
(Typ
);
16573 while Present
(Comp
) loop
16574 if Chars
(Comp
) = Chars
(Defining_Identifier
(N
)) then
16575 Set_Defining_Identifier
(N
, Comp
);
16579 Next_Component
(Comp
);
16586 procedure Replace
is new Traverse_Proc
(Process
);
16588 -- Start of processing for Replace_Components
16592 end Replace_Components
;
16594 -------------------------------
16595 -- Set_Completion_Referenced --
16596 -------------------------------
16598 procedure Set_Completion_Referenced
(E
: Entity_Id
) is
16600 -- If in main unit, mark entity that is a completion as referenced,
16601 -- warnings go on the partial view when needed.
16603 if In_Extended_Main_Source_Unit
(E
) then
16604 Set_Referenced
(E
);
16606 end Set_Completion_Referenced
;
16608 ---------------------
16609 -- Set_Fixed_Range --
16610 ---------------------
16612 -- The range for fixed-point types is complicated by the fact that we
16613 -- do not know the exact end points at the time of the declaration. This
16614 -- is true for three reasons:
16616 -- A size clause may affect the fudging of the end-points
16617 -- A small clause may affect the values of the end-points
16618 -- We try to include the end-points if it does not affect the size
16620 -- This means that the actual end-points must be established at the point
16621 -- when the type is frozen. Meanwhile, we first narrow the range as
16622 -- permitted (so that it will fit if necessary in a small specified size),
16623 -- and then build a range subtree with these narrowed bounds.
16625 -- Set_Fixed_Range constructs the range from real literal values, and sets
16626 -- the range as the Scalar_Range of the given fixed-point type entity.
16628 -- The parent of this range is set to point to the entity so that it is
16629 -- properly hooked into the tree (unlike normal Scalar_Range entries for
16630 -- other scalar types, which are just pointers to the range in the
16631 -- original tree, this would otherwise be an orphan).
16633 -- The tree is left unanalyzed. When the type is frozen, the processing
16634 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
16635 -- analyzed, and uses this as an indication that it should complete
16636 -- work on the range (it will know the final small and size values).
16638 procedure Set_Fixed_Range
16644 S
: constant Node_Id
:=
16646 Low_Bound
=> Make_Real_Literal
(Loc
, Lo
),
16647 High_Bound
=> Make_Real_Literal
(Loc
, Hi
));
16649 Set_Scalar_Range
(E
, S
);
16651 end Set_Fixed_Range
;
16653 ----------------------------------
16654 -- Set_Scalar_Range_For_Subtype --
16655 ----------------------------------
16657 procedure Set_Scalar_Range_For_Subtype
16658 (Def_Id
: Entity_Id
;
16662 Kind
: constant Entity_Kind
:= Ekind
(Def_Id
);
16665 Set_Scalar_Range
(Def_Id
, R
);
16667 -- We need to link the range into the tree before resolving it so
16668 -- that types that are referenced, including importantly the subtype
16669 -- itself, are properly frozen (Freeze_Expression requires that the
16670 -- expression be properly linked into the tree). Of course if it is
16671 -- already linked in, then we do not disturb the current link.
16673 if No
(Parent
(R
)) then
16674 Set_Parent
(R
, Def_Id
);
16677 -- Reset the kind of the subtype during analysis of the range, to
16678 -- catch possible premature use in the bounds themselves.
16680 Set_Ekind
(Def_Id
, E_Void
);
16681 Process_Range_Expr_In_Decl
(R
, Subt
);
16682 Set_Ekind
(Def_Id
, Kind
);
16683 end Set_Scalar_Range_For_Subtype
;
16685 --------------------------------------------------------
16686 -- Set_Stored_Constraint_From_Discriminant_Constraint --
16687 --------------------------------------------------------
16689 procedure Set_Stored_Constraint_From_Discriminant_Constraint
16693 -- Make sure set if encountered during Expand_To_Stored_Constraint
16695 Set_Stored_Constraint
(E
, No_Elist
);
16697 -- Give it the right value
16699 if Is_Constrained
(E
) and then Has_Discriminants
(E
) then
16700 Set_Stored_Constraint
(E
,
16701 Expand_To_Stored_Constraint
(E
, Discriminant_Constraint
(E
)));
16703 end Set_Stored_Constraint_From_Discriminant_Constraint
;
16705 -------------------------------------
16706 -- Signed_Integer_Type_Declaration --
16707 -------------------------------------
16709 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
16710 Implicit_Base
: Entity_Id
;
16711 Base_Typ
: Entity_Id
;
16714 Errs
: Boolean := False;
16718 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
16719 -- Determine whether given bounds allow derivation from specified type
16721 procedure Check_Bound
(Expr
: Node_Id
);
16722 -- Check bound to make sure it is integral and static. If not, post
16723 -- appropriate error message and set Errs flag
16725 ---------------------
16726 -- Can_Derive_From --
16727 ---------------------
16729 -- Note we check both bounds against both end values, to deal with
16730 -- strange types like ones with a range of 0 .. -12341234.
16732 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
16733 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(E
));
16734 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(E
));
16736 return Lo
<= Lo_Val
and then Lo_Val
<= Hi
16738 Lo
<= Hi_Val
and then Hi_Val
<= Hi
;
16739 end Can_Derive_From
;
16745 procedure Check_Bound
(Expr
: Node_Id
) is
16747 -- If a range constraint is used as an integer type definition, each
16748 -- bound of the range must be defined by a static expression of some
16749 -- integer type, but the two bounds need not have the same integer
16750 -- type (Negative bounds are allowed.) (RM 3.5.4)
16752 if not Is_Integer_Type
(Etype
(Expr
)) then
16754 ("integer type definition bounds must be of integer type", Expr
);
16757 elsif not Is_OK_Static_Expression
(Expr
) then
16758 Flag_Non_Static_Expr
16759 ("non-static expression used for integer type bound!", Expr
);
16762 -- The bounds are folded into literals, and we set their type to be
16763 -- universal, to avoid typing difficulties: we cannot set the type
16764 -- of the literal to the new type, because this would be a forward
16765 -- reference for the back end, and if the original type is user-
16766 -- defined this can lead to spurious semantic errors (e.g. 2928-003).
16769 if Is_Entity_Name
(Expr
) then
16770 Fold_Uint
(Expr
, Expr_Value
(Expr
), True);
16773 Set_Etype
(Expr
, Universal_Integer
);
16777 -- Start of processing for Signed_Integer_Type_Declaration
16780 -- Create an anonymous base type
16783 Create_Itype
(E_Signed_Integer_Type
, Parent
(Def
), T
, 'B');
16785 -- Analyze and check the bounds, they can be of any integer type
16787 Lo
:= Low_Bound
(Def
);
16788 Hi
:= High_Bound
(Def
);
16790 -- Arbitrarily use Integer as the type if either bound had an error
16792 if Hi
= Error
or else Lo
= Error
then
16793 Base_Typ
:= Any_Integer
;
16794 Set_Error_Posted
(T
, True);
16796 -- Here both bounds are OK expressions
16799 Analyze_And_Resolve
(Lo
, Any_Integer
);
16800 Analyze_And_Resolve
(Hi
, Any_Integer
);
16806 Hi
:= Type_High_Bound
(Standard_Long_Long_Integer
);
16807 Lo
:= Type_Low_Bound
(Standard_Long_Long_Integer
);
16810 -- Find type to derive from
16812 Lo_Val
:= Expr_Value
(Lo
);
16813 Hi_Val
:= Expr_Value
(Hi
);
16815 if Can_Derive_From
(Standard_Short_Short_Integer
) then
16816 Base_Typ
:= Base_Type
(Standard_Short_Short_Integer
);
16818 elsif Can_Derive_From
(Standard_Short_Integer
) then
16819 Base_Typ
:= Base_Type
(Standard_Short_Integer
);
16821 elsif Can_Derive_From
(Standard_Integer
) then
16822 Base_Typ
:= Base_Type
(Standard_Integer
);
16824 elsif Can_Derive_From
(Standard_Long_Integer
) then
16825 Base_Typ
:= Base_Type
(Standard_Long_Integer
);
16827 elsif Can_Derive_From
(Standard_Long_Long_Integer
) then
16828 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
16831 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
16832 Error_Msg_N
("integer type definition bounds out of range", Def
);
16833 Hi
:= Type_High_Bound
(Standard_Long_Long_Integer
);
16834 Lo
:= Type_Low_Bound
(Standard_Long_Long_Integer
);
16838 -- Complete both implicit base and declared first subtype entities
16840 Set_Etype
(Implicit_Base
, Base_Typ
);
16841 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
16842 Set_Size_Info
(Implicit_Base
, (Base_Typ
));
16843 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
16844 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
16846 Set_Ekind
(T
, E_Signed_Integer_Subtype
);
16847 Set_Etype
(T
, Implicit_Base
);
16849 Set_Size_Info
(T
, (Implicit_Base
));
16850 Set_First_Rep_Item
(T
, First_Rep_Item
(Implicit_Base
));
16851 Set_Scalar_Range
(T
, Def
);
16852 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
16853 Set_Is_Constrained
(T
);
16854 end Signed_Integer_Type_Declaration
;