1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
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 Freeze
; use Freeze
;
38 with Itypes
; use Itypes
;
39 with Layout
; use Layout
;
41 with Lib
.Xref
; use Lib
.Xref
;
42 with Namet
; use Namet
;
43 with Nmake
; use Nmake
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
49 with Sem_Case
; use Sem_Case
;
50 with Sem_Cat
; use Sem_Cat
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch7
; use Sem_Ch7
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Ch13
; use Sem_Ch13
;
55 with Sem_Disp
; use Sem_Disp
;
56 with Sem_Dist
; use Sem_Dist
;
57 with Sem_Elim
; use Sem_Elim
;
58 with Sem_Eval
; use Sem_Eval
;
59 with Sem_Mech
; use Sem_Mech
;
60 with Sem_Res
; use Sem_Res
;
61 with Sem_Smem
; use Sem_Smem
;
62 with Sem_Type
; use Sem_Type
;
63 with Sem_Util
; use Sem_Util
;
64 with Sem_Warn
; use Sem_Warn
;
65 with Stand
; use Stand
;
66 with Sinfo
; use Sinfo
;
67 with Snames
; use Snames
;
68 with Tbuild
; use Tbuild
;
69 with Ttypes
; use Ttypes
;
70 with Uintp
; use Uintp
;
71 with Urealp
; use Urealp
;
73 package body Sem_Ch3
is
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 procedure Build_Derived_Type
81 Parent_Type
: Entity_Id
;
82 Derived_Type
: Entity_Id
;
83 Is_Completion
: Boolean;
84 Derive_Subps
: Boolean := True);
85 -- Create and decorate a Derived_Type given the Parent_Type entity.
86 -- N is the N_Full_Type_Declaration node containing the derived type
87 -- definition. Parent_Type is the entity for the parent type in the derived
88 -- type definition and Derived_Type the actual derived type. Is_Completion
89 -- must be set to False if Derived_Type is the N_Defining_Identifier node
90 -- in N (ie Derived_Type = Defining_Identifier (N)). In this case N is not
91 -- the completion of a private type declaration. If Is_Completion is
92 -- set to True, N is the completion of a private type declaration and
93 -- Derived_Type is different from the defining identifier inside N (i.e.
94 -- Derived_Type /= Defining_Identifier (N)). Derive_Subps indicates whether
95 -- the parent subprograms should be derived. The only case where this
96 -- parameter is False is when Build_Derived_Type is recursively called to
97 -- process an implicit derived full type for a type derived from a private
98 -- type (in that case the subprograms must only be derived for the private
100 -- ??? These flags need a bit of re-examination and re-documentation:
101 -- ??? are they both necessary (both seem related to the recursion)?
103 procedure Build_Derived_Access_Type
105 Parent_Type
: Entity_Id
;
106 Derived_Type
: Entity_Id
);
107 -- Subsidiary procedure to Build_Derived_Type. For a derived access type,
108 -- create an implicit base if the parent type is constrained or if the
109 -- subtype indication has a constraint.
111 procedure Build_Derived_Array_Type
113 Parent_Type
: Entity_Id
;
114 Derived_Type
: Entity_Id
);
115 -- Subsidiary procedure to Build_Derived_Type. For a derived array 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_Concurrent_Type
121 Parent_Type
: Entity_Id
;
122 Derived_Type
: Entity_Id
);
123 -- Subsidiary procedure to Build_Derived_Type. For a derived task or pro-
124 -- tected type, inherit entries and protected subprograms, check legality
125 -- of discriminant constraints if any.
127 procedure Build_Derived_Enumeration_Type
129 Parent_Type
: Entity_Id
;
130 Derived_Type
: Entity_Id
);
131 -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
132 -- type, we must create a new list of literals. Types derived from
133 -- Character and Wide_Character are special-cased.
135 procedure Build_Derived_Numeric_Type
137 Parent_Type
: Entity_Id
;
138 Derived_Type
: Entity_Id
);
139 -- Subsidiary procedure to Build_Derived_Type. For numeric types, create
140 -- an anonymous base type, and propagate constraint to subtype if needed.
142 procedure Build_Derived_Private_Type
144 Parent_Type
: Entity_Id
;
145 Derived_Type
: Entity_Id
;
146 Is_Completion
: Boolean;
147 Derive_Subps
: Boolean := True);
148 -- Subsidiary procedure to Build_Derived_Type. This procedure is complex
149 -- because the parent may or may not have a completion, and the derivation
150 -- may itself be a completion.
152 procedure Build_Derived_Record_Type
154 Parent_Type
: Entity_Id
;
155 Derived_Type
: Entity_Id
;
156 Derive_Subps
: Boolean := True);
157 -- Subsidiary procedure to Build_Derived_Type and
158 -- Analyze_Private_Extension_Declaration used for tagged and untagged
159 -- record types. All parameters are as in Build_Derived_Type except that
160 -- N, in addition to being an N_Full_Type_Declaration node, can also be an
161 -- N_Private_Extension_Declaration node. See the definition of this routine
162 -- for much more info. Derive_Subps indicates whether subprograms should
163 -- be derived from the parent type. The only case where Derive_Subps is
164 -- False is for an implicit derived full type for a type derived from a
165 -- private type (see Build_Derived_Type).
167 function Inherit_Components
169 Parent_Base
: Entity_Id
;
170 Derived_Base
: Entity_Id
;
172 Inherit_Discr
: Boolean;
173 Discs
: Elist_Id
) return Elist_Id
;
174 -- Called from Build_Derived_Record_Type to inherit the components of
175 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
176 -- For more information on derived types and component inheritance please
177 -- consult the comment above the body of Build_Derived_Record_Type.
179 -- N is the original derived type declaration.
181 -- Is_Tagged is set if we are dealing with tagged types.
183 -- If Inherit_Discr is set, Derived_Base inherits its discriminants
184 -- from Parent_Base, otherwise no discriminants are inherited.
186 -- Discs gives the list of constraints that apply to Parent_Base in the
187 -- derived type declaration. If Discs is set to No_Elist, then we have
188 -- the following situation:
190 -- type Parent (D1..Dn : ..) is [tagged] record ...;
191 -- type Derived is new Parent [with ...];
193 -- which gets treated as
195 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
197 -- For untagged types the returned value is an association list. The list
198 -- starts from the association (Parent_Base => Derived_Base), and then it
199 -- contains a sequence of the associations of the form
201 -- (Old_Component => New_Component),
203 -- where Old_Component is the Entity_Id of a component in Parent_Base
204 -- and New_Component is the Entity_Id of the corresponding component
205 -- in Derived_Base. For untagged records, this association list is
206 -- needed when copying the record declaration for the derived base.
207 -- In the tagged case the value returned is irrelevant.
209 procedure Build_Discriminal
(Discrim
: Entity_Id
);
210 -- Create the discriminal corresponding to discriminant Discrim, that is
211 -- the parameter corresponding to Discrim to be used in initialization
212 -- procedures for the type where Discrim is a discriminant. Discriminals
213 -- are not used during semantic analysis, and are not fully defined
214 -- entities until expansion. Thus they are not given a scope until
215 -- initialization procedures are built.
217 function Build_Discriminant_Constraints
220 Derived_Def
: Boolean := False) return Elist_Id
;
221 -- Validate discriminant constraints, and return the list of the
222 -- constraints in order of discriminant declarations. T is the
223 -- discriminated unconstrained type. Def is the N_Subtype_Indication
224 -- node where the discriminants constraints for T are specified.
225 -- Derived_Def is True if we are building the discriminant constraints
226 -- in a derived type definition of the form "type D (...) is new T (xxx)".
227 -- In this case T is the parent type and Def is the constraint "(xxx)" on
228 -- T and this routine sets the Corresponding_Discriminant field of the
229 -- discriminants in the derived type D to point to the corresponding
230 -- discriminants in the parent type T.
232 procedure Build_Discriminated_Subtype
236 Related_Nod
: Node_Id
;
237 For_Access
: Boolean := False);
238 -- Subsidiary procedure to Constrain_Discriminated_Type and to
239 -- Process_Incomplete_Dependents. Given
241 -- T (a possibly discriminated base type)
242 -- Def_Id (a very partially built subtype for T),
244 -- the call completes Def_Id to be the appropriate E_*_Subtype.
246 -- The Elist is the list of discriminant constraints if any (it is set to
247 -- No_Elist if T is not a discriminated type, and to an empty list if
248 -- T has discriminants but there are no discriminant constraints). The
249 -- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
250 -- The For_Access says whether or not this subtype is really constraining
251 -- an access type. That is its sole purpose is the designated type of an
252 -- access type -- in which case a Private_Subtype Is_For_Access_Subtype
253 -- is built to avoid freezing T when the access subtype is frozen.
255 function Build_Scalar_Bound
258 Der_T
: Entity_Id
) return Node_Id
;
259 -- The bounds of a derived scalar type are conversions of the bounds of
260 -- the parent type. Optimize the representation if the bounds are literals.
261 -- Needs a more complete spec--what are the parameters exactly, and what
262 -- exactly is the returned value, and how is Bound affected???
264 procedure Build_Underlying_Full_View
268 -- If the completion of a private type is itself derived from a private
269 -- type, or if the full view of a private subtype is itself private, the
270 -- back-end has no way to compute the actual size of this type. We build
271 -- an internal subtype declaration of the proper parent type to convey
272 -- this information. This extra mechanism is needed because a full
273 -- view cannot itself have a full view (it would get clobbered during
276 procedure Check_Access_Discriminant_Requires_Limited
279 -- Check the restriction that the type to which an access discriminant
280 -- belongs must be a concurrent type or a descendant of a type with
281 -- the reserved word 'limited' in its declaration.
283 procedure Check_Delta_Expression
(E
: Node_Id
);
284 -- Check that the expression represented by E is suitable for use
285 -- as a delta expression, i.e. it is of real type and is static.
287 procedure Check_Digits_Expression
(E
: Node_Id
);
288 -- Check that the expression represented by E is suitable for use as
289 -- a digits expression, i.e. it is of integer type, positive and static.
291 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
);
292 -- Validate the initialization of an object declaration. T is the
293 -- required type, and Exp is the initialization expression.
295 procedure Check_Or_Process_Discriminants
298 Prev
: Entity_Id
:= Empty
);
299 -- If T is the full declaration of an incomplete or private type, check
300 -- the conformance of the discriminants, otherwise process them. Prev
301 -- is the entity of the partial declaration, if any.
303 procedure Check_Real_Bound
(Bound
: Node_Id
);
304 -- Check given bound for being of real type and static. If not, post an
305 -- appropriate message, and rewrite the bound with the real literal zero.
307 procedure Constant_Redeclaration
311 -- Various checks on legality of full declaration of deferred constant.
312 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
313 -- node. The caller has not yet set any attributes of this entity.
315 procedure Convert_Scalar_Bounds
317 Parent_Type
: Entity_Id
;
318 Derived_Type
: Entity_Id
;
320 -- For derived scalar types, convert the bounds in the type definition
321 -- to the derived type, and complete their analysis. Given a constraint
323 -- .. new T range Lo .. Hi;
324 -- Lo and Hi are analyzed and resolved with T'Base, the parent_type.
325 -- The bounds of the derived type (the anonymous base) are copies of
326 -- Lo and Hi. Finally, the bounds of the derived subtype are conversions
327 -- of those bounds to the derived_type, so that their typing is
330 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
);
331 -- Copies attributes from array base type T2 to array base type T1.
332 -- Copies only attributes that apply to base types, but not subtypes.
334 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
);
335 -- Copies attributes from array subtype T2 to array subtype T1. Copies
336 -- attributes that apply to both subtypes and base types.
338 procedure Create_Constrained_Components
342 Constraints
: Elist_Id
);
343 -- Build the list of entities for a constrained discriminated record
344 -- subtype. If a component depends on a discriminant, replace its subtype
345 -- using the discriminant values in the discriminant constraint.
346 -- Subt is the defining identifier for the subtype whose list of
347 -- constrained entities we will create. Decl_Node is the type declaration
348 -- node where we will attach all the itypes created. Typ is the base
349 -- discriminated type for the subtype Subt. Constraints is the list of
350 -- discriminant constraints for Typ.
352 function Constrain_Component_Type
353 (Compon_Type
: Entity_Id
;
354 Constrained_Typ
: Entity_Id
;
355 Related_Node
: Node_Id
;
357 Constraints
: Elist_Id
) return Entity_Id
;
358 -- Given a discriminated base type Typ, a list of discriminant constraint
359 -- Constraints for Typ and the type of a component of Typ, Compon_Type,
360 -- create and return the type corresponding to Compon_type where all
361 -- discriminant references are replaced with the corresponding
362 -- constraint. If no discriminant references occur in Compon_Typ then
363 -- return it as is. Constrained_Typ is the final constrained subtype to
364 -- which the constrained Compon_Type belongs. Related_Node is the node
365 -- where we will attach all the itypes created.
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,
372 -- it is an anonymous type created for a subtype indication. In that
373 -- case it is 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
441 -- identical to Constrain_Integer, but for the Ekind of the
442 -- resulting subtype.
444 procedure Constrain_Float
(Def_Id
: Node_Id
; S
: Node_Id
);
445 -- Constrain a floating point type with either a digits constraint
446 -- and/or a range constraint, building a E_Floating_Point_Subtype.
448 procedure Constrain_Index
451 Related_Nod
: Node_Id
;
452 Related_Id
: Entity_Id
;
455 -- Process an index constraint in a constrained array declaration. The
456 -- constraint can be a subtype name, or a range with or without an
457 -- explicit subtype mark. The index is the corresponding index of the
458 -- unconstrained array. The Related_Id and Suffix parameters are used to
459 -- build the associated Implicit type name.
461 procedure Constrain_Integer
(Def_Id
: Node_Id
; S
: Node_Id
);
462 -- Build subtype of a signed or modular integer type
464 procedure Constrain_Ordinary_Fixed
(Def_Id
: Node_Id
; S
: Node_Id
);
465 -- Constrain an ordinary fixed point type with a range constraint, and
466 -- build an E_Ordinary_Fixed_Point_Subtype entity.
468 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
);
469 -- Copy the Priv entity into the entity of its full declaration
470 -- then swap the two entities in such a manner that the former private
471 -- type is now seen as a full type.
473 procedure Decimal_Fixed_Point_Type_Declaration
476 -- Create a new decimal fixed point type, and apply the constraint to
477 -- obtain a subtype of this new type.
479 procedure Complete_Private_Subtype
482 Full_Base
: Entity_Id
;
483 Related_Nod
: Node_Id
);
484 -- Complete the implicit full view of a private subtype by setting
485 -- the appropriate semantic fields. If the full view of the parent is
486 -- a record type, build constrained components of subtype.
488 procedure Derived_Standard_Character
490 Parent_Type
: Entity_Id
;
491 Derived_Type
: Entity_Id
);
492 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
493 -- derivations from types Standard.Character and Standard.Wide_Character.
495 procedure Derived_Type_Declaration
498 Is_Completion
: Boolean);
499 -- Process a derived type declaration. This routine will invoke
500 -- Build_Derived_Type to process the actual derived type definition.
501 -- Parameters N and Is_Completion have the same meaning as in
502 -- Build_Derived_Type. T is the N_Defining_Identifier for the entity
503 -- defined in the N_Full_Type_Declaration node N, that is T is the
506 function Find_Type_Of_Subtype_Indic
(S
: Node_Id
) return Entity_Id
;
507 -- Given a subtype indication S (which is really an N_Subtype_Indication
508 -- node or a plain N_Identifier), find the type of the subtype mark.
510 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
511 -- Insert each literal in symbol table, as an overloadable identifier
512 -- Each enumeration type is mapped into a sequence of integers, and
513 -- each literal is defined as a constant with integer value. If any
514 -- of the literals are character literals, the type is a character
515 -- type, which means that strings are legal aggregates for arrays of
516 -- components of the type.
518 function Expand_To_Stored_Constraint
520 Constraint
: Elist_Id
) return Elist_Id
;
521 -- Given a Constraint (ie a list of expressions) on the discriminants of
522 -- Typ, expand it into a constraint on the stored discriminants and
523 -- return the new list of expressions constraining the stored
526 function Find_Type_Of_Object
528 Related_Nod
: Node_Id
) return Entity_Id
;
529 -- Get type entity for object referenced by Obj_Def, attaching the
530 -- implicit types generated to Related_Nod
532 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
533 -- Create a new float, and apply the constraint to obtain subtype of it
535 function Has_Range_Constraint
(N
: Node_Id
) return Boolean;
536 -- Given an N_Subtype_Indication node N, return True if a range constraint
537 -- is present, either directly, or as part of a digits or delta constraint.
538 -- In addition, a digits constraint in the decimal case returns True, since
539 -- it establishes a default range if no explicit range is present.
541 function Is_Valid_Constraint_Kind
543 Constraint_Kind
: Node_Kind
) return Boolean;
544 -- Returns True if it is legal to apply the given kind of constraint
545 -- to the given kind of type (index constraint to an array type,
548 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
549 -- Create new modular type. Verify that modulus is in bounds and is
550 -- a power of two (implementation restriction).
552 procedure New_Concatenation_Op
(Typ
: Entity_Id
);
553 -- Create an abbreviated declaration for an operator in order to
554 -- materialize concatenation on array types.
556 procedure Ordinary_Fixed_Point_Type_Declaration
559 -- Create a new ordinary fixed point type, and apply the constraint
560 -- to obtain subtype of it.
562 procedure Prepare_Private_Subtype_Completion
564 Related_Nod
: Node_Id
);
565 -- Id is a subtype of some private type. Creates the full declaration
566 -- associated with Id whenever possible, i.e. when the full declaration
567 -- of the base type is already known. Records each subtype into
568 -- Private_Dependents of the base type.
570 procedure Process_Incomplete_Dependents
574 -- Process all entities that depend on an incomplete type. There include
575 -- subtypes, subprogram types that mention the incomplete type in their
576 -- profiles, and subprogram with access parameters that designate the
579 -- Inc_T is the defining identifier of an incomplete type declaration, its
580 -- Ekind is E_Incomplete_Type.
582 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
584 -- Full_T is N's defining identifier.
586 -- Subtypes of incomplete types with discriminants are completed when the
587 -- parent type is. This is simpler than private subtypes, because they can
588 -- only appear in the same scope, and there is no need to exchange views.
589 -- Similarly, access_to_subprogram types may have a parameter or a return
590 -- type that is an incomplete type, and that must be replaced with the
593 -- If the full type is tagged, subprogram with access parameters that
594 -- designated the incomplete may be primitive operations of the full type,
595 -- and have to be processed accordingly.
597 procedure Process_Real_Range_Specification
(Def
: Node_Id
);
598 -- Given the type definition for a real type, this procedure processes
599 -- and checks the real range specification of this type definition if
600 -- one is present. If errors are found, error messages are posted, and
601 -- the Real_Range_Specification of Def is reset to Empty.
603 procedure Record_Type_Declaration
607 -- Process a record type declaration (for both untagged and tagged
608 -- records). Parameters T and N are exactly like in procedure
609 -- Derived_Type_Declaration, except that no flag Is_Completion is
610 -- needed for this routine. If this is the completion of an incomplete
611 -- type declaration, Prev is the entity of the incomplete declaration,
612 -- used for cross-referencing. Otherwise Prev = T.
614 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
);
615 -- This routine is used to process the actual record type definition
616 -- (both for untagged and tagged records). Def is a record type
617 -- definition node. This procedure analyzes the components in this
618 -- record type definition. Prev_T is the entity for the enclosing record
619 -- type. It is provided so that its Has_Task flag can be set if any of
620 -- the component have Has_Task set. If the declaration is the completion
621 -- of an incomplete type declaration, Prev_T is the original incomplete
622 -- type, whose full view is the record type.
624 procedure Replace_Components
(Typ
: Entity_Id
; Decl
: Node_Id
);
625 -- Subsidiary to Build_Derived_Record_Type. For untagged records, we
626 -- build a copy of the declaration tree of the parent, and we create
627 -- independently the list of components for the derived type. Semantic
628 -- information uses the component entities, but record representation
629 -- clauses are validated on the declaration tree. This procedure replaces
630 -- discriminants and components in the declaration with those that have
631 -- been created by Inherit_Components.
633 procedure Set_Fixed_Range
638 -- Build a range node with the given bounds and set it as the Scalar_Range
639 -- of the given fixed-point type entity. Loc is the source location used
640 -- for the constructed range. See body for further details.
642 procedure Set_Scalar_Range_For_Subtype
646 -- This routine is used to set the scalar range field for a subtype
647 -- given Def_Id, the entity for the subtype, and R, the range expression
648 -- for the scalar range. Subt provides the parent subtype to be used
649 -- to analyze, resolve, and check the given range.
651 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
652 -- Create a new signed integer entity, and apply the constraint to obtain
653 -- the required first named subtype of this type.
655 procedure Set_Stored_Constraint_From_Discriminant_Constraint
657 -- E is some record type. This routine computes E's Stored_Constraint
658 -- from its Discriminant_Constraint.
660 -----------------------
661 -- Access_Definition --
662 -----------------------
664 function Access_Definition
665 (Related_Nod
: Node_Id
;
666 N
: Node_Id
) return Entity_Id
668 Anon_Type
: constant Entity_Id
:=
669 Create_Itype
(E_Anonymous_Access_Type
, Related_Nod
,
670 Scope_Id
=> Scope
(Current_Scope
));
671 Desig_Type
: Entity_Id
;
674 if Is_Entry
(Current_Scope
)
675 and then Is_Task_Type
(Etype
(Scope
(Current_Scope
)))
677 Error_Msg_N
("task entries cannot have access parameters", N
);
680 -- Ada 2005 (AI-254): In case of anonymous access to subprograms
681 -- call the corresponding semantic routine
683 if Present
(Access_To_Subprogram_Definition
(N
)) then
684 Access_Subprogram_Declaration
685 (T_Name
=> Anon_Type
,
686 T_Def
=> Access_To_Subprogram_Definition
(N
));
688 if Ekind
(Anon_Type
) = E_Access_Protected_Subprogram_Type
then
690 (Anon_Type
, E_Anonymous_Access_Protected_Subprogram_Type
);
693 (Anon_Type
, E_Anonymous_Access_Subprogram_Type
);
699 Find_Type
(Subtype_Mark
(N
));
700 Desig_Type
:= Entity
(Subtype_Mark
(N
));
702 Set_Directly_Designated_Type
703 (Anon_Type
, Desig_Type
);
704 Set_Etype
(Anon_Type
, Anon_Type
);
705 Init_Size_Align
(Anon_Type
);
706 Set_Depends_On_Private
(Anon_Type
, Has_Private_Component
(Anon_Type
));
708 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
709 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify
710 -- if the null value is allowed. In Ada 95 the null value is never
713 if Ada_Version
>= Ada_05
then
714 Set_Can_Never_Be_Null
(Anon_Type
, Null_Exclusion_Present
(N
));
716 Set_Can_Never_Be_Null
(Anon_Type
, True);
719 -- The anonymous access type is as public as the discriminated type or
720 -- subprogram that defines it. It is imported (for back-end purposes)
721 -- if the designated type is.
723 Set_Is_Public
(Anon_Type
, Is_Public
(Scope
(Anon_Type
)));
725 -- Ada 2005 (AI-50217): Propagate the attribute that indicates that the
726 -- designated type comes from the limited view (for back-end purposes).
728 Set_From_With_Type
(Anon_Type
, From_With_Type
(Desig_Type
));
730 -- Ada 2005 (AI-231): Propagate the access-constant attribute
732 Set_Is_Access_Constant
(Anon_Type
, Constant_Present
(N
));
734 -- The context is either a subprogram declaration or an access
735 -- discriminant, in a private or a full type declaration. In the case
736 -- of a subprogram, If the designated type is incomplete, the operation
737 -- will be a primitive operation of the full type, to be updated
738 -- subsequently. If the type is imported through a limited with clause,
739 -- it is not a primitive operation of the type (which is declared
740 -- elsewhere in some other scope).
742 if Ekind
(Desig_Type
) = E_Incomplete_Type
743 and then not From_With_Type
(Desig_Type
)
744 and then Is_Overloadable
(Current_Scope
)
746 Append_Elmt
(Current_Scope
, Private_Dependents
(Desig_Type
));
747 Set_Has_Delayed_Freeze
(Current_Scope
);
751 end Access_Definition
;
753 -----------------------------------
754 -- Access_Subprogram_Declaration --
755 -----------------------------------
757 procedure Access_Subprogram_Declaration
761 Formals
: constant List_Id
:= Parameter_Specifications
(T_Def
);
764 Desig_Type
: constant Entity_Id
:=
765 Create_Itype
(E_Subprogram_Type
, Parent
(T_Def
));
768 if Nkind
(T_Def
) = N_Access_Function_Definition
then
769 Analyze
(Subtype_Mark
(T_Def
));
770 Set_Etype
(Desig_Type
, Entity
(Subtype_Mark
(T_Def
)));
772 if not (Is_Type
(Etype
(Desig_Type
))) then
774 ("expect type in function specification", Subtype_Mark
(T_Def
));
778 Set_Etype
(Desig_Type
, Standard_Void_Type
);
781 if Present
(Formals
) then
782 New_Scope
(Desig_Type
);
783 Process_Formals
(Formals
, Parent
(T_Def
));
785 -- A bit of a kludge here, End_Scope requires that the parent
786 -- pointer be set to something reasonable, but Itypes don't have
787 -- parent pointers. So we set it and then unset it ??? If and when
788 -- Itypes have proper parent pointers to their declarations, this
789 -- kludge can be removed.
791 Set_Parent
(Desig_Type
, T_Name
);
793 Set_Parent
(Desig_Type
, Empty
);
796 -- The return type and/or any parameter type may be incomplete. Mark
797 -- the subprogram_type as depending on the incomplete type, so that
798 -- it can be updated when the full type declaration is seen.
800 if Present
(Formals
) then
801 Formal
:= First_Formal
(Desig_Type
);
803 while Present
(Formal
) loop
804 if Ekind
(Formal
) /= E_In_Parameter
805 and then Nkind
(T_Def
) = N_Access_Function_Definition
807 Error_Msg_N
("functions can only have IN parameters", Formal
);
810 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
then
811 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Formal
)));
812 Set_Has_Delayed_Freeze
(Desig_Type
);
815 Next_Formal
(Formal
);
819 if Ekind
(Etype
(Desig_Type
)) = E_Incomplete_Type
820 and then not Has_Delayed_Freeze
(Desig_Type
)
822 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Desig_Type
)));
823 Set_Has_Delayed_Freeze
(Desig_Type
);
826 Check_Delayed_Subprogram
(Desig_Type
);
828 if Protected_Present
(T_Def
) then
829 Set_Ekind
(T_Name
, E_Access_Protected_Subprogram_Type
);
830 Set_Convention
(Desig_Type
, Convention_Protected
);
832 Set_Ekind
(T_Name
, E_Access_Subprogram_Type
);
835 Set_Etype
(T_Name
, T_Name
);
836 Init_Size_Align
(T_Name
);
837 Set_Directly_Designated_Type
(T_Name
, Desig_Type
);
839 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
841 Set_Can_Never_Be_Null
(T_Name
, Null_Exclusion_Present
(T_Def
));
843 Check_Restriction
(No_Access_Subprograms
, T_Def
);
844 end Access_Subprogram_Declaration
;
846 ----------------------------
847 -- Access_Type_Declaration --
848 ----------------------------
850 procedure Access_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
851 S
: constant Node_Id
:= Subtype_Indication
(Def
);
852 P
: constant Node_Id
:= Parent
(Def
);
858 -- Check for permissible use of incomplete type
860 if Nkind
(S
) /= N_Subtype_Indication
then
863 if Ekind
(Root_Type
(Entity
(S
))) = E_Incomplete_Type
then
864 Set_Directly_Designated_Type
(T
, Entity
(S
));
866 Set_Directly_Designated_Type
(T
,
867 Process_Subtype
(S
, P
, T
, 'P'));
871 Set_Directly_Designated_Type
(T
,
872 Process_Subtype
(S
, P
, T
, 'P'));
875 if All_Present
(Def
) or Constant_Present
(Def
) then
876 Set_Ekind
(T
, E_General_Access_Type
);
878 Set_Ekind
(T
, E_Access_Type
);
881 if Base_Type
(Designated_Type
(T
)) = T
then
882 Error_Msg_N
("access type cannot designate itself", S
);
887 -- If the type has appeared already in a with_type clause, it is
888 -- frozen and the pointer size is already set. Else, initialize.
890 if not From_With_Type
(T
) then
894 Set_Is_Access_Constant
(T
, Constant_Present
(Def
));
896 Desig
:= Designated_Type
(T
);
898 -- If designated type is an imported tagged type, indicate that the
899 -- access type is also imported, and therefore restricted in its use.
900 -- The access type may already be imported, so keep setting otherwise.
902 -- Ada 2005 (AI-50217): If the non-limited view of the designated type
903 -- is available, use it as the designated type of the access type, so
904 -- that the back-end gets a usable entity.
910 if From_With_Type
(Desig
) then
911 Set_From_With_Type
(T
);
913 if Ekind
(Desig
) = E_Incomplete_Type
then
914 N_Desig
:= Non_Limited_View
(Desig
);
916 else pragma Assert
(Ekind
(Desig
) = E_Class_Wide_Type
);
917 if From_With_Type
(Etype
(Desig
)) then
918 N_Desig
:= Non_Limited_View
(Etype
(Desig
));
920 N_Desig
:= Etype
(Desig
);
924 pragma Assert
(Present
(N_Desig
));
925 Set_Directly_Designated_Type
(T
, N_Desig
);
929 -- Note that Has_Task is always false, since the access type itself
930 -- is not a task type. See Einfo for more description on this point.
931 -- Exactly the same consideration applies to Has_Controlled_Component.
933 Set_Has_Task
(T
, False);
934 Set_Has_Controlled_Component
(T
, False);
936 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
939 Set_Can_Never_Be_Null
(T
, Null_Exclusion_Present
(Def
));
940 Set_Is_Access_Constant
(T
, Constant_Present
(Def
));
941 end Access_Type_Declaration
;
943 -----------------------------------
944 -- Analyze_Component_Declaration --
945 -----------------------------------
947 procedure Analyze_Component_Declaration
(N
: Node_Id
) is
948 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
952 function Contains_POC
(Constr
: Node_Id
) return Boolean;
953 -- Determines whether a constraint uses the discriminant of a record
954 -- type thus becoming a per-object constraint (POC).
960 function Contains_POC
(Constr
: Node_Id
) return Boolean is
962 case Nkind
(Constr
) is
963 when N_Attribute_Reference
=>
964 return Attribute_Name
(Constr
) = Name_Access
966 Prefix
(Constr
) = Scope
(Entity
(Prefix
(Constr
)));
968 when N_Discriminant_Association
=>
969 return Denotes_Discriminant
(Expression
(Constr
));
972 return Denotes_Discriminant
(Constr
);
974 when N_Index_Or_Discriminant_Constraint
=>
976 IDC
: Node_Id
:= First
(Constraints
(Constr
));
979 while Present
(IDC
) loop
981 -- One per-object constraint is sufficent
983 if Contains_POC
(IDC
) then
994 return Denotes_Discriminant
(Low_Bound
(Constr
))
996 Denotes_Discriminant
(High_Bound
(Constr
));
998 when N_Range_Constraint
=>
999 return Denotes_Discriminant
(Range_Expression
(Constr
));
1007 -- Start of processing for Analyze_Component_Declaration
1010 Generate_Definition
(Id
);
1013 if Present
(Subtype_Indication
(Component_Definition
(N
))) then
1014 T
:= Find_Type_Of_Object
1015 (Subtype_Indication
(Component_Definition
(N
)), N
);
1017 -- Ada 2005 (AI-230): Access Definition case
1020 pragma Assert
(Present
1021 (Access_Definition
(Component_Definition
(N
))));
1023 T
:= Access_Definition
1025 N
=> Access_Definition
(Component_Definition
(N
)));
1027 -- Ada 2005 (AI-230): In case of components that are anonymous
1028 -- access types the level of accessibility depends on the enclosing
1031 Set_Scope
(T
, Current_Scope
); -- Ada 2005 (AI-230)
1033 -- Ada 2005 (AI-254)
1035 if Present
(Access_To_Subprogram_Definition
1036 (Access_Definition
(Component_Definition
(N
))))
1037 and then Protected_Present
(Access_To_Subprogram_Definition
1039 (Component_Definition
(N
))))
1041 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
, T
);
1045 -- If the subtype is a constrained subtype of the enclosing record,
1046 -- (which must have a partial view) the back-end does not handle
1047 -- properly the recursion. Rewrite the component declaration with
1048 -- an explicit subtype indication, which is acceptable to Gigi. We
1049 -- can copy the tree directly because side effects have already been
1050 -- removed from discriminant constraints.
1052 if Ekind
(T
) = E_Access_Subtype
1053 and then Is_Entity_Name
(Subtype_Indication
(Component_Definition
(N
)))
1054 and then Comes_From_Source
(T
)
1055 and then Nkind
(Parent
(T
)) = N_Subtype_Declaration
1056 and then Etype
(Directly_Designated_Type
(T
)) = Current_Scope
1059 (Subtype_Indication
(Component_Definition
(N
)),
1060 New_Copy_Tree
(Subtype_Indication
(Parent
(T
))));
1061 T
:= Find_Type_Of_Object
1062 (Subtype_Indication
(Component_Definition
(N
)), N
);
1065 -- If the component declaration includes a default expression, then we
1066 -- check that the component is not of a limited type (RM 3.7(5)),
1067 -- and do the special preanalysis of the expression (see section on
1068 -- "Handling of Default and Per-Object Expressions" in the spec of
1071 if Present
(Expression
(N
)) then
1072 Analyze_Per_Use_Expression
(Expression
(N
), T
);
1073 Check_Initialization
(T
, Expression
(N
));
1076 -- The parent type may be a private view with unknown discriminants,
1077 -- and thus unconstrained. Regular components must be constrained.
1079 if Is_Indefinite_Subtype
(T
) and then Chars
(Id
) /= Name_uParent
then
1080 if Is_Class_Wide_Type
(T
) then
1082 ("class-wide subtype with unknown discriminants" &
1083 " in component declaration",
1084 Subtype_Indication
(Component_Definition
(N
)));
1087 ("unconstrained subtype in component declaration",
1088 Subtype_Indication
(Component_Definition
(N
)));
1091 -- Components cannot be abstract, except for the special case of
1092 -- the _Parent field (case of extending an abstract tagged type)
1094 elsif Is_Abstract
(T
) and then Chars
(Id
) /= Name_uParent
then
1095 Error_Msg_N
("type of a component cannot be abstract", N
);
1099 Set_Is_Aliased
(Id
, Aliased_Present
(Component_Definition
(N
)));
1101 -- The component declaration may have a per-object constraint, set
1102 -- the appropriate flag in the defining identifier of the subtype.
1104 if Present
(Subtype_Indication
(Component_Definition
(N
))) then
1106 Sindic
: constant Node_Id
:=
1107 Subtype_Indication
(Component_Definition
(N
));
1110 if Nkind
(Sindic
) = N_Subtype_Indication
1111 and then Present
(Constraint
(Sindic
))
1112 and then Contains_POC
(Constraint
(Sindic
))
1114 Set_Has_Per_Object_Constraint
(Id
);
1119 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
1120 -- out some static checks.
1122 if Ada_Version
>= Ada_05
1123 and then (Null_Exclusion_Present
(Component_Definition
(N
))
1124 or else Can_Never_Be_Null
(T
))
1126 Set_Can_Never_Be_Null
(Id
);
1127 Null_Exclusion_Static_Checks
(N
);
1130 -- If this component is private (or depends on a private type),
1131 -- flag the record type to indicate that some operations are not
1134 P
:= Private_Component
(T
);
1137 -- Check for circular definitions
1139 if P
= Any_Type
then
1140 Set_Etype
(Id
, Any_Type
);
1142 -- There is a gap in the visibility of operations only if the
1143 -- component type is not defined in the scope of the record type.
1145 elsif Scope
(P
) = Scope
(Current_Scope
) then
1148 elsif Is_Limited_Type
(P
) then
1149 Set_Is_Limited_Composite
(Current_Scope
);
1152 Set_Is_Private_Composite
(Current_Scope
);
1157 and then Is_Limited_Type
(T
)
1158 and then Chars
(Id
) /= Name_uParent
1159 and then Is_Tagged_Type
(Current_Scope
)
1161 if Is_Derived_Type
(Current_Scope
)
1162 and then not Is_Limited_Record
(Root_Type
(Current_Scope
))
1165 ("extension of nonlimited type cannot have limited components",
1167 Explain_Limited_Type
(T
, N
);
1168 Set_Etype
(Id
, Any_Type
);
1169 Set_Is_Limited_Composite
(Current_Scope
, False);
1171 elsif not Is_Derived_Type
(Current_Scope
)
1172 and then not Is_Limited_Record
(Current_Scope
)
1175 ("nonlimited tagged type cannot have limited components", N
);
1176 Explain_Limited_Type
(T
, N
);
1177 Set_Etype
(Id
, Any_Type
);
1178 Set_Is_Limited_Composite
(Current_Scope
, False);
1182 Set_Original_Record_Component
(Id
, Id
);
1183 end Analyze_Component_Declaration
;
1185 --------------------------
1186 -- Analyze_Declarations --
1187 --------------------------
1189 procedure Analyze_Declarations
(L
: List_Id
) is
1191 Next_Node
: Node_Id
;
1192 Freeze_From
: Entity_Id
:= Empty
;
1195 -- Adjust D not to include implicit label declarations, since these
1196 -- have strange Sloc values that result in elaboration check problems.
1197 -- (They have the sloc of the label as found in the source, and that
1198 -- is ahead of the current declarative part).
1204 procedure Adjust_D
is
1206 while Present
(Prev
(D
))
1207 and then Nkind
(D
) = N_Implicit_Label_Declaration
1213 -- Start of processing for Analyze_Declarations
1217 while Present
(D
) loop
1219 -- Complete analysis of declaration
1222 Next_Node
:= Next
(D
);
1224 if No
(Freeze_From
) then
1225 Freeze_From
:= First_Entity
(Current_Scope
);
1228 -- At the end of a declarative part, freeze remaining entities
1229 -- declared in it. The end of the visible declarations of package
1230 -- specification is not the end of a declarative part if private
1231 -- declarations are present. The end of a package declaration is a
1232 -- freezing point only if it a library package. A task definition or
1233 -- protected type definition is not a freeze point either. Finally,
1234 -- we do not freeze entities in generic scopes, because there is no
1235 -- code generated for them and freeze nodes will be generated for
1238 -- The end of a package instantiation is not a freeze point, but
1239 -- for now we make it one, because the generic body is inserted
1240 -- (currently) immediately after. Generic instantiations will not
1241 -- be a freeze point once delayed freezing of bodies is implemented.
1242 -- (This is needed in any case for early instantiations ???).
1244 if No
(Next_Node
) then
1245 if Nkind
(Parent
(L
)) = N_Component_List
1246 or else Nkind
(Parent
(L
)) = N_Task_Definition
1247 or else Nkind
(Parent
(L
)) = N_Protected_Definition
1251 elsif Nkind
(Parent
(L
)) /= N_Package_Specification
then
1252 if Nkind
(Parent
(L
)) = N_Package_Body
then
1253 Freeze_From
:= First_Entity
(Current_Scope
);
1257 Freeze_All
(Freeze_From
, D
);
1258 Freeze_From
:= Last_Entity
(Current_Scope
);
1260 elsif Scope
(Current_Scope
) /= Standard_Standard
1261 and then not Is_Child_Unit
(Current_Scope
)
1262 and then No
(Generic_Parent
(Parent
(L
)))
1266 elsif L
/= Visible_Declarations
(Parent
(L
))
1267 or else No
(Private_Declarations
(Parent
(L
)))
1268 or else Is_Empty_List
(Private_Declarations
(Parent
(L
)))
1271 Freeze_All
(Freeze_From
, D
);
1272 Freeze_From
:= Last_Entity
(Current_Scope
);
1275 -- If next node is a body then freeze all types before the body.
1276 -- An exception occurs for expander generated bodies, which can
1277 -- be recognized by their already being analyzed. The expander
1278 -- ensures that all types needed by these bodies have been frozen
1279 -- but it is not necessary to freeze all types (and would be wrong
1280 -- since it would not correspond to an RM defined freeze point).
1282 elsif not Analyzed
(Next_Node
)
1283 and then (Nkind
(Next_Node
) = N_Subprogram_Body
1284 or else Nkind
(Next_Node
) = N_Entry_Body
1285 or else Nkind
(Next_Node
) = N_Package_Body
1286 or else Nkind
(Next_Node
) = N_Protected_Body
1287 or else Nkind
(Next_Node
) = N_Task_Body
1288 or else Nkind
(Next_Node
) in N_Body_Stub
)
1291 Freeze_All
(Freeze_From
, D
);
1292 Freeze_From
:= Last_Entity
(Current_Scope
);
1297 end Analyze_Declarations
;
1299 ----------------------------------
1300 -- Analyze_Incomplete_Type_Decl --
1301 ----------------------------------
1303 procedure Analyze_Incomplete_Type_Decl
(N
: Node_Id
) is
1304 F
: constant Boolean := Is_Pure
(Current_Scope
);
1308 Generate_Definition
(Defining_Identifier
(N
));
1310 -- Process an incomplete declaration. The identifier must not have been
1311 -- declared already in the scope. However, an incomplete declaration may
1312 -- appear in the private part of a package, for a private type that has
1313 -- already been declared.
1315 -- In this case, the discriminants (if any) must match
1317 T
:= Find_Type_Name
(N
);
1319 Set_Ekind
(T
, E_Incomplete_Type
);
1320 Init_Size_Align
(T
);
1321 Set_Is_First_Subtype
(T
, True);
1325 Set_Stored_Constraint
(T
, No_Elist
);
1327 if Present
(Discriminant_Specifications
(N
)) then
1328 Process_Discriminants
(N
);
1333 -- If the type has discriminants, non-trivial subtypes may be be
1334 -- declared before the full view of the type. The full views of those
1335 -- subtypes will be built after the full view of the type.
1337 Set_Private_Dependents
(T
, New_Elmt_List
);
1339 end Analyze_Incomplete_Type_Decl
;
1341 -----------------------------
1342 -- Analyze_Itype_Reference --
1343 -----------------------------
1345 -- Nothing to do. This node is placed in the tree only for the benefit
1346 -- of Gigi processing, and has no effect on the semantic processing.
1348 procedure Analyze_Itype_Reference
(N
: Node_Id
) is
1350 pragma Assert
(Is_Itype
(Itype
(N
)));
1352 end Analyze_Itype_Reference
;
1354 --------------------------------
1355 -- Analyze_Number_Declaration --
1356 --------------------------------
1358 procedure Analyze_Number_Declaration
(N
: Node_Id
) is
1359 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1360 E
: constant Node_Id
:= Expression
(N
);
1362 Index
: Interp_Index
;
1366 Generate_Definition
(Id
);
1369 -- This is an optimization of a common case of an integer literal
1371 if Nkind
(E
) = N_Integer_Literal
then
1372 Set_Is_Static_Expression
(E
, True);
1373 Set_Etype
(E
, Universal_Integer
);
1375 Set_Etype
(Id
, Universal_Integer
);
1376 Set_Ekind
(Id
, E_Named_Integer
);
1377 Set_Is_Frozen
(Id
, True);
1381 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
1383 -- Process expression, replacing error by integer zero, to avoid
1384 -- cascaded errors or aborts further along in the processing
1386 -- Replace Error by integer zero, which seems least likely to
1387 -- cause cascaded errors.
1390 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), Uint_0
));
1391 Set_Error_Posted
(E
);
1396 -- Verify that the expression is static and numeric. If
1397 -- the expression is overloaded, we apply the preference
1398 -- rule that favors root numeric types.
1400 if not Is_Overloaded
(E
) then
1405 Get_First_Interp
(E
, Index
, It
);
1407 while Present
(It
.Typ
) loop
1408 if (Is_Integer_Type
(It
.Typ
)
1409 or else Is_Real_Type
(It
.Typ
))
1410 and then (Scope
(Base_Type
(It
.Typ
))) = Standard_Standard
1412 if T
= Any_Type
then
1415 elsif It
.Typ
= Universal_Real
1416 or else It
.Typ
= Universal_Integer
1418 -- Choose universal interpretation over any other
1425 Get_Next_Interp
(Index
, It
);
1429 if Is_Integer_Type
(T
) then
1431 Set_Etype
(Id
, Universal_Integer
);
1432 Set_Ekind
(Id
, E_Named_Integer
);
1434 elsif Is_Real_Type
(T
) then
1436 -- Because the real value is converted to universal_real, this
1437 -- is a legal context for a universal fixed expression.
1439 if T
= Universal_Fixed
then
1441 Loc
: constant Source_Ptr
:= Sloc
(N
);
1442 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
1444 New_Occurrence_Of
(Universal_Real
, Loc
),
1445 Expression
=> Relocate_Node
(E
));
1452 elsif T
= Any_Fixed
then
1453 Error_Msg_N
("illegal context for mixed mode operation", E
);
1455 -- Expression is of the form : universal_fixed * integer.
1456 -- Try to resolve as universal_real.
1458 T
:= Universal_Real
;
1463 Set_Etype
(Id
, Universal_Real
);
1464 Set_Ekind
(Id
, E_Named_Real
);
1467 Wrong_Type
(E
, Any_Numeric
);
1471 Set_Ekind
(Id
, E_Constant
);
1472 Set_Never_Set_In_Source
(Id
, True);
1473 Set_Is_True_Constant
(Id
, True);
1477 if Nkind
(E
) = N_Integer_Literal
1478 or else Nkind
(E
) = N_Real_Literal
1480 Set_Etype
(E
, Etype
(Id
));
1483 if not Is_OK_Static_Expression
(E
) then
1484 Flag_Non_Static_Expr
1485 ("non-static expression used in number declaration!", E
);
1486 Rewrite
(E
, Make_Integer_Literal
(Sloc
(N
), 1));
1487 Set_Etype
(E
, Any_Type
);
1489 end Analyze_Number_Declaration
;
1491 --------------------------------
1492 -- Analyze_Object_Declaration --
1493 --------------------------------
1495 procedure Analyze_Object_Declaration
(N
: Node_Id
) is
1496 Loc
: constant Source_Ptr
:= Sloc
(N
);
1497 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1501 E
: Node_Id
:= Expression
(N
);
1502 -- E is set to Expression (N) throughout this routine. When
1503 -- Expression (N) is modified, E is changed accordingly.
1505 Prev_Entity
: Entity_Id
:= Empty
;
1507 function Build_Default_Subtype
return Entity_Id
;
1508 -- If the object is limited or aliased, and if the type is unconstrained
1509 -- and there is no expression, the discriminants cannot be modified and
1510 -- the subtype of the object is constrained by the defaults, so it is
1511 -- worthile building the corresponding subtype.
1513 function Count_Tasks
(T
: Entity_Id
) return Uint
;
1514 -- This function is called when a library level object of type is
1515 -- declared. It's function is to count the static number of tasks
1516 -- declared within the type (it is only called if Has_Tasks is set for
1517 -- T). As a side effect, if an array of tasks with non-static bounds or
1518 -- a variant record type is encountered, Check_Restrictions is called
1519 -- indicating the count is unknown.
1521 ---------------------------
1522 -- Build_Default_Subtype --
1523 ---------------------------
1525 function Build_Default_Subtype
return Entity_Id
is
1526 Constraints
: constant List_Id
:= New_List
;
1532 Disc
:= First_Discriminant
(T
);
1534 if No
(Discriminant_Default_Value
(Disc
)) then
1535 return T
; -- previous error.
1538 Act
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
1539 while Present
(Disc
) loop
1542 Discriminant_Default_Value
(Disc
)), Constraints
);
1543 Next_Discriminant
(Disc
);
1547 Make_Subtype_Declaration
(Loc
,
1548 Defining_Identifier
=> Act
,
1549 Subtype_Indication
=>
1550 Make_Subtype_Indication
(Loc
,
1551 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
1553 Make_Index_Or_Discriminant_Constraint
1554 (Loc
, Constraints
)));
1556 Insert_Before
(N
, Decl
);
1559 end Build_Default_Subtype
;
1565 function Count_Tasks
(T
: Entity_Id
) return Uint
is
1571 if Is_Task_Type
(T
) then
1574 elsif Is_Record_Type
(T
) then
1575 if Has_Discriminants
(T
) then
1576 Check_Restriction
(Max_Tasks
, N
);
1581 C
:= First_Component
(T
);
1582 while Present
(C
) loop
1583 V
:= V
+ Count_Tasks
(Etype
(C
));
1590 elsif Is_Array_Type
(T
) then
1591 X
:= First_Index
(T
);
1592 V
:= Count_Tasks
(Component_Type
(T
));
1593 while Present
(X
) loop
1596 if not Is_Static_Subtype
(C
) then
1597 Check_Restriction
(Max_Tasks
, N
);
1600 V
:= V
* (UI_Max
(Uint_0
,
1601 Expr_Value
(Type_High_Bound
(C
)) -
1602 Expr_Value
(Type_Low_Bound
(C
)) + Uint_1
));
1615 -- Start of processing for Analyze_Object_Declaration
1618 -- There are three kinds of implicit types generated by an
1619 -- object declaration:
1621 -- 1. Those for generated by the original Object Definition
1623 -- 2. Those generated by the Expression
1625 -- 3. Those used to constrained the Object Definition with the
1626 -- expression constraints when it is unconstrained
1628 -- They must be generated in this order to avoid order of elaboration
1629 -- issues. Thus the first step (after entering the name) is to analyze
1630 -- the object definition.
1632 if Constant_Present
(N
) then
1633 Prev_Entity
:= Current_Entity_In_Scope
(Id
);
1635 -- If homograph is an implicit subprogram, it is overridden by the
1636 -- current declaration.
1638 if Present
(Prev_Entity
)
1639 and then Is_Overloadable
(Prev_Entity
)
1640 and then Is_Inherited_Operation
(Prev_Entity
)
1642 Prev_Entity
:= Empty
;
1646 if Present
(Prev_Entity
) then
1647 Constant_Redeclaration
(Id
, N
, T
);
1649 Generate_Reference
(Prev_Entity
, Id
, 'c');
1650 Set_Completion_Referenced
(Id
);
1652 if Error_Posted
(N
) then
1654 -- Type mismatch or illegal redeclaration, Do not analyze
1655 -- expression to avoid cascaded errors.
1657 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
1659 Set_Ekind
(Id
, E_Variable
);
1663 -- In the normal case, enter identifier at the start to catch
1664 -- premature usage in the initialization expression.
1667 Generate_Definition
(Id
);
1670 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
1672 if Error_Posted
(Id
) then
1674 Set_Ekind
(Id
, E_Variable
);
1679 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
1680 -- out some static checks
1682 if Ada_Version
>= Ada_05
1683 and then (Null_Exclusion_Present
(N
)
1684 or else Can_Never_Be_Null
(T
))
1686 Set_Can_Never_Be_Null
(Id
);
1687 Null_Exclusion_Static_Checks
(N
);
1690 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
1692 -- If deferred constant, make sure context is appropriate. We detect
1693 -- a deferred constant as a constant declaration with no expression.
1694 -- A deferred constant can appear in a package body if its completion
1695 -- is by means of an interface pragma.
1697 if Constant_Present
(N
)
1700 if not Is_Package
(Current_Scope
) then
1702 ("invalid context for deferred constant declaration ('R'M 7.4)",
1705 ("\declaration requires an initialization expression",
1707 Set_Constant_Present
(N
, False);
1709 -- In Ada 83, deferred constant must be of private type
1711 elsif not Is_Private_Type
(T
) then
1712 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1714 ("(Ada 83) deferred constant must be private type", N
);
1718 -- If not a deferred constant, then object declaration freezes its type
1721 Check_Fully_Declared
(T
, N
);
1722 Freeze_Before
(N
, T
);
1725 -- If the object was created by a constrained array definition, then
1726 -- set the link in both the anonymous base type and anonymous subtype
1727 -- that are built to represent the array type to point to the object.
1729 if Nkind
(Object_Definition
(Declaration_Node
(Id
))) =
1730 N_Constrained_Array_Definition
1732 Set_Related_Array_Object
(T
, Id
);
1733 Set_Related_Array_Object
(Base_Type
(T
), Id
);
1736 -- Special checks for protected objects not at library level
1738 if Is_Protected_Type
(T
)
1739 and then not Is_Library_Level_Entity
(Id
)
1741 Check_Restriction
(No_Local_Protected_Objects
, Id
);
1743 -- Protected objects with interrupt handlers must be at library level
1745 if Has_Interrupt_Handler
(T
) then
1747 ("interrupt object can only be declared at library level", Id
);
1751 -- The actual subtype of the object is the nominal subtype, unless
1752 -- the nominal one is unconstrained and obtained from the expression.
1756 -- Process initialization expression if present and not in error
1758 if Present
(E
) and then E
/= Error
then
1761 -- In case of errors detected in the analysis of the expression,
1762 -- decorate it with the expected type to avoid cascade errors
1764 if not Present
(Etype
(E
)) then
1768 -- If an initialization expression is present, then we set the
1769 -- Is_True_Constant flag. It will be reset if this is a variable
1770 -- and it is indeed modified.
1772 Set_Is_True_Constant
(Id
, True);
1774 -- If we are analyzing a constant declaration, set its completion
1775 -- flag after analyzing the expression.
1777 if Constant_Present
(N
) then
1778 Set_Has_Completion
(Id
);
1781 if not Assignment_OK
(N
) then
1782 Check_Initialization
(T
, E
);
1785 Set_Etype
(Id
, T
); -- may be overridden later on
1787 Check_Unset_Reference
(E
);
1789 if Compile_Time_Known_Value
(E
) then
1790 Set_Current_Value
(Id
, E
);
1793 -- Check incorrect use of dynamically tagged expressions. Note
1794 -- the use of Is_Tagged_Type (T) which seems redundant but is in
1795 -- fact important to avoid spurious errors due to expanded code
1796 -- for dispatching functions over an anonymous access type
1798 if (Is_Class_Wide_Type
(Etype
(E
)) or else Is_Dynamically_Tagged
(E
))
1799 and then Is_Tagged_Type
(T
)
1800 and then not Is_Class_Wide_Type
(T
)
1802 Error_Msg_N
("dynamically tagged expression not allowed!", E
);
1805 Apply_Scalar_Range_Check
(E
, T
);
1806 Apply_Static_Length_Check
(E
, T
);
1809 -- If the No_Streams restriction is set, check that the type of the
1810 -- object is not, and does not contain, any subtype derived from
1811 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
1812 -- Has_Stream just for efficiency reasons. There is no point in
1813 -- spending time on a Has_Stream check if the restriction is not set.
1815 if Restrictions
.Set
(No_Streams
) then
1816 if Has_Stream
(T
) then
1817 Check_Restriction
(No_Streams
, N
);
1821 -- Abstract type is never permitted for a variable or constant.
1822 -- Note: we inhibit this check for objects that do not come from
1823 -- source because there is at least one case (the expansion of
1824 -- x'class'input where x is abstract) where we legitimately
1825 -- generate an abstract object.
1827 if Is_Abstract
(T
) and then Comes_From_Source
(N
) then
1828 Error_Msg_N
("type of object cannot be abstract",
1829 Object_Definition
(N
));
1831 if Is_CPP_Class
(T
) then
1832 Error_Msg_NE
("\} may need a cpp_constructor",
1833 Object_Definition
(N
), T
);
1836 -- Case of unconstrained type
1838 elsif Is_Indefinite_Subtype
(T
) then
1840 -- Nothing to do in deferred constant case
1842 if Constant_Present
(N
) and then No
(E
) then
1845 -- Case of no initialization present
1848 if No_Initialization
(N
) then
1851 elsif Is_Class_Wide_Type
(T
) then
1853 ("initialization required in class-wide declaration ", N
);
1857 ("unconstrained subtype not allowed (need initialization)",
1858 Object_Definition
(N
));
1861 -- Case of initialization present but in error. Set initial
1862 -- expression as absent (but do not make above complaints)
1864 elsif E
= Error
then
1865 Set_Expression
(N
, Empty
);
1868 -- Case of initialization present
1871 -- Not allowed in Ada 83
1873 if not Constant_Present
(N
) then
1874 if Ada_Version
= Ada_83
1875 and then Comes_From_Source
(Object_Definition
(N
))
1878 ("(Ada 83) unconstrained variable not allowed",
1879 Object_Definition
(N
));
1883 -- Now we constrain the variable from the initializing expression
1885 -- If the expression is an aggregate, it has been expanded into
1886 -- individual assignments. Retrieve the actual type from the
1887 -- expanded construct.
1889 if Is_Array_Type
(T
)
1890 and then No_Initialization
(N
)
1891 and then Nkind
(Original_Node
(E
)) = N_Aggregate
1896 Expand_Subtype_From_Expr
(N
, T
, Object_Definition
(N
), E
);
1897 Act_T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
1900 Set_Is_Constr_Subt_For_U_Nominal
(Act_T
);
1902 if Aliased_Present
(N
) then
1903 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
1906 Freeze_Before
(N
, Act_T
);
1907 Freeze_Before
(N
, T
);
1910 elsif Is_Array_Type
(T
)
1911 and then No_Initialization
(N
)
1912 and then Nkind
(Original_Node
(E
)) = N_Aggregate
1914 if not Is_Entity_Name
(Object_Definition
(N
)) then
1916 Check_Compile_Time_Size
(Act_T
);
1918 if Aliased_Present
(N
) then
1919 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
1923 -- When the given object definition and the aggregate are specified
1924 -- independently, and their lengths might differ do a length check.
1925 -- This cannot happen if the aggregate is of the form (others =>...)
1927 if not Is_Constrained
(T
) then
1930 elsif Nkind
(E
) = N_Raise_Constraint_Error
then
1932 -- Aggregate is statically illegal. Place back in declaration
1934 Set_Expression
(N
, E
);
1935 Set_No_Initialization
(N
, False);
1937 elsif T
= Etype
(E
) then
1940 elsif Nkind
(E
) = N_Aggregate
1941 and then Present
(Component_Associations
(E
))
1942 and then Present
(Choices
(First
(Component_Associations
(E
))))
1943 and then Nkind
(First
1944 (Choices
(First
(Component_Associations
(E
))))) = N_Others_Choice
1949 Apply_Length_Check
(E
, T
);
1952 elsif (Is_Limited_Record
(T
)
1953 or else Is_Concurrent_Type
(T
))
1954 and then not Is_Constrained
(T
)
1955 and then Has_Discriminants
(T
)
1957 Act_T
:= Build_Default_Subtype
;
1958 Rewrite
(Object_Definition
(N
), New_Occurrence_Of
(Act_T
, Loc
));
1960 elsif not Is_Constrained
(T
)
1961 and then Has_Discriminants
(T
)
1962 and then Constant_Present
(N
)
1963 and then Nkind
(E
) = N_Function_Call
1965 -- The back-end has problems with constants of a discriminated type
1966 -- with defaults, if the initial value is a function call. We
1967 -- generate an intermediate temporary for the result of the call.
1968 -- It is unclear why this should make it acceptable to gcc. ???
1970 Remove_Side_Effects
(E
);
1973 if T
= Standard_Wide_Character
or else T
= Standard_Wide_Wide_Character
1974 or else Root_Type
(T
) = Standard_Wide_String
1975 or else Root_Type
(T
) = Standard_Wide_Wide_String
1977 Check_Restriction
(No_Wide_Characters
, Object_Definition
(N
));
1980 -- Now establish the proper kind and type of the object
1982 if Constant_Present
(N
) then
1983 Set_Ekind
(Id
, E_Constant
);
1984 Set_Never_Set_In_Source
(Id
, True);
1985 Set_Is_True_Constant
(Id
, True);
1988 Set_Ekind
(Id
, E_Variable
);
1990 -- A variable is set as shared passive if it appears in a shared
1991 -- passive package, and is at the outer level. This is not done
1992 -- for entities generated during expansion, because those are
1993 -- always manipulated locally.
1995 if Is_Shared_Passive
(Current_Scope
)
1996 and then Is_Library_Level_Entity
(Id
)
1997 and then Comes_From_Source
(Id
)
1999 Set_Is_Shared_Passive
(Id
);
2000 Check_Shared_Var
(Id
, T
, N
);
2003 -- Case of no initializing expression present. If the type is not
2004 -- fully initialized, then we set Never_Set_In_Source, since this
2005 -- is a case of a potentially uninitialized object. Note that we
2006 -- do not consider access variables to be fully initialized for
2007 -- this purpose, since it still seems dubious if someone declares
2009 -- Note that we only do this for source declarations. If the object
2010 -- is declared by a generated declaration, we assume that it is not
2011 -- appropriate to generate warnings in that case.
2014 if (Is_Access_Type
(T
)
2015 or else not Is_Fully_Initialized_Type
(T
))
2016 and then Comes_From_Source
(N
)
2018 Set_Never_Set_In_Source
(Id
);
2023 Init_Alignment
(Id
);
2026 if Aliased_Present
(N
) then
2027 Set_Is_Aliased
(Id
);
2030 and then Is_Record_Type
(T
)
2031 and then not Is_Constrained
(T
)
2032 and then Has_Discriminants
(T
)
2034 Set_Actual_Subtype
(Id
, Build_Default_Subtype
);
2038 Set_Etype
(Id
, Act_T
);
2040 if Has_Controlled_Component
(Etype
(Id
))
2041 or else Is_Controlled
(Etype
(Id
))
2043 if not Is_Library_Level_Entity
(Id
) then
2044 Check_Restriction
(No_Nested_Finalization
, N
);
2046 Validate_Controlled_Object
(Id
);
2049 -- Generate a warning when an initialization causes an obvious
2050 -- ABE violation. If the init expression is a simple aggregate
2051 -- there shouldn't be any initialize/adjust call generated. This
2052 -- will be true as soon as aggregates are built in place when
2053 -- possible. ??? at the moment we do not generate warnings for
2054 -- temporaries created for those aggregates although a
2055 -- Program_Error might be generated if compiled with -gnato
2057 if Is_Controlled
(Etype
(Id
))
2058 and then Comes_From_Source
(Id
)
2061 BT
: constant Entity_Id
:= Base_Type
(Etype
(Id
));
2063 Implicit_Call
: Entity_Id
;
2064 pragma Warnings
(Off
, Implicit_Call
);
2065 -- What is this about, it is never referenced ???
2067 function Is_Aggr
(N
: Node_Id
) return Boolean;
2068 -- Check that N is an aggregate
2074 function Is_Aggr
(N
: Node_Id
) return Boolean is
2076 case Nkind
(Original_Node
(N
)) is
2077 when N_Aggregate | N_Extension_Aggregate
=>
2080 when N_Qualified_Expression |
2082 N_Unchecked_Type_Conversion
=>
2083 return Is_Aggr
(Expression
(Original_Node
(N
)));
2091 -- If no underlying type, we already are in an error situation
2092 -- don't try to add a warning since we do not have access
2095 if No
(Underlying_Type
(BT
)) then
2096 Implicit_Call
:= Empty
;
2098 -- A generic type does not have usable primitive operators.
2099 -- Initialization calls are built for instances.
2101 elsif Is_Generic_Type
(BT
) then
2102 Implicit_Call
:= Empty
;
2104 -- if the init expression is not an aggregate, an adjust
2105 -- call will be generated
2107 elsif Present
(E
) and then not Is_Aggr
(E
) then
2108 Implicit_Call
:= Find_Prim_Op
(BT
, Name_Adjust
);
2110 -- if no init expression and we are not in the deferred
2111 -- constant case, an Initialize call will be generated
2113 elsif No
(E
) and then not Constant_Present
(N
) then
2114 Implicit_Call
:= Find_Prim_Op
(BT
, Name_Initialize
);
2117 Implicit_Call
:= Empty
;
2123 if Has_Task
(Etype
(Id
)) then
2124 Check_Restriction
(No_Tasking
, N
);
2126 if Is_Library_Level_Entity
(Id
) then
2127 Check_Restriction
(Max_Tasks
, N
, Count_Tasks
(Etype
(Id
)));
2129 Check_Restriction
(Max_Tasks
, N
);
2130 Check_Restriction
(No_Task_Hierarchy
, N
);
2131 Check_Potentially_Blocking_Operation
(N
);
2134 -- A rather specialized test. If we see two tasks being declared
2135 -- of the same type in the same object declaration, and the task
2136 -- has an entry with an address clause, we know that program error
2137 -- will be raised at run-time since we can't have two tasks with
2138 -- entries at the same address.
2140 if Is_Task_Type
(Etype
(Id
)) and then More_Ids
(N
) then
2145 E
:= First_Entity
(Etype
(Id
));
2146 while Present
(E
) loop
2147 if Ekind
(E
) = E_Entry
2148 and then Present
(Get_Attribute_Definition_Clause
2149 (E
, Attribute_Address
))
2152 ("?more than one task with same entry address", N
);
2154 ("\?Program_Error will be raised at run time", N
);
2156 Make_Raise_Program_Error
(Loc
,
2157 Reason
=> PE_Duplicated_Entry_Address
));
2167 -- Some simple constant-propagation: if the expression is a constant
2168 -- string initialized with a literal, share the literal. This avoids
2172 and then Is_Entity_Name
(E
)
2173 and then Ekind
(Entity
(E
)) = E_Constant
2174 and then Base_Type
(Etype
(E
)) = Standard_String
2177 Val
: constant Node_Id
:= Constant_Value
(Entity
(E
));
2180 and then Nkind
(Val
) = N_String_Literal
2182 Rewrite
(E
, New_Copy
(Val
));
2187 -- Another optimization: if the nominal subtype is unconstrained and
2188 -- the expression is a function call that returns an unconstrained
2189 -- type, rewrite the declaration as a renaming of the result of the
2190 -- call. The exceptions below are cases where the copy is expected,
2191 -- either by the back end (Aliased case) or by the semantics, as for
2192 -- initializing controlled types or copying tags for classwide types.
2195 and then Nkind
(E
) = N_Explicit_Dereference
2196 and then Nkind
(Original_Node
(E
)) = N_Function_Call
2197 and then not Is_Library_Level_Entity
(Id
)
2198 and then not Is_Constrained
(T
)
2199 and then not Is_Aliased
(Id
)
2200 and then not Is_Class_Wide_Type
(T
)
2201 and then not Is_Controlled
(T
)
2202 and then not Has_Controlled_Component
(Base_Type
(T
))
2203 and then Expander_Active
2206 Make_Object_Renaming_Declaration
(Loc
,
2207 Defining_Identifier
=> Id
,
2208 Access_Definition
=> Empty
,
2209 Subtype_Mark
=> New_Occurrence_Of
2210 (Base_Type
(Etype
(Id
)), Loc
),
2213 Set_Renamed_Object
(Id
, E
);
2215 -- Force generation of debugging information for the constant
2216 -- and for the renamed function call.
2218 Set_Needs_Debug_Info
(Id
);
2219 Set_Needs_Debug_Info
(Entity
(Prefix
(E
)));
2222 if Present
(Prev_Entity
)
2223 and then Is_Frozen
(Prev_Entity
)
2224 and then not Error_Posted
(Id
)
2226 Error_Msg_N
("full constant declaration appears too late", N
);
2229 Check_Eliminated
(Id
);
2230 end Analyze_Object_Declaration
;
2232 ---------------------------
2233 -- Analyze_Others_Choice --
2234 ---------------------------
2236 -- Nothing to do for the others choice node itself, the semantic analysis
2237 -- of the others choice will occur as part of the processing of the parent
2239 procedure Analyze_Others_Choice
(N
: Node_Id
) is
2240 pragma Warnings
(Off
, N
);
2243 end Analyze_Others_Choice
;
2245 --------------------------------
2246 -- Analyze_Per_Use_Expression --
2247 --------------------------------
2249 procedure Analyze_Per_Use_Expression
(N
: Node_Id
; T
: Entity_Id
) is
2250 Save_In_Default_Expression
: constant Boolean := In_Default_Expression
;
2252 In_Default_Expression
:= True;
2253 Pre_Analyze_And_Resolve
(N
, T
);
2254 In_Default_Expression
:= Save_In_Default_Expression
;
2255 end Analyze_Per_Use_Expression
;
2257 -------------------------------------------
2258 -- Analyze_Private_Extension_Declaration --
2259 -------------------------------------------
2261 procedure Analyze_Private_Extension_Declaration
(N
: Node_Id
) is
2262 T
: constant Entity_Id
:= Defining_Identifier
(N
);
2263 Indic
: constant Node_Id
:= Subtype_Indication
(N
);
2264 Parent_Type
: Entity_Id
;
2265 Parent_Base
: Entity_Id
;
2268 Generate_Definition
(T
);
2271 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
2272 Parent_Base
:= Base_Type
(Parent_Type
);
2274 if Parent_Type
= Any_Type
2275 or else Etype
(Parent_Type
) = Any_Type
2277 Set_Ekind
(T
, Ekind
(Parent_Type
));
2278 Set_Etype
(T
, Any_Type
);
2281 elsif not Is_Tagged_Type
(Parent_Type
) then
2283 ("parent of type extension must be a tagged type ", Indic
);
2286 elsif Ekind
(Parent_Type
) = E_Void
2287 or else Ekind
(Parent_Type
) = E_Incomplete_Type
2289 Error_Msg_N
("premature derivation of incomplete type", Indic
);
2293 -- Perhaps the parent type should be changed to the class-wide type's
2294 -- specific type in this case to prevent cascading errors ???
2296 if Is_Class_Wide_Type
(Parent_Type
) then
2298 ("parent of type extension must not be a class-wide type", Indic
);
2302 if (not Is_Package
(Current_Scope
)
2303 and then Nkind
(Parent
(N
)) /= N_Generic_Subprogram_Declaration
)
2304 or else In_Private_Part
(Current_Scope
)
2307 Error_Msg_N
("invalid context for private extension", N
);
2310 -- Set common attributes
2312 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
2313 Set_Scope
(T
, Current_Scope
);
2314 Set_Ekind
(T
, E_Record_Type_With_Private
);
2315 Init_Size_Align
(T
);
2317 Set_Etype
(T
, Parent_Base
);
2318 Set_Has_Task
(T
, Has_Task
(Parent_Base
));
2320 Set_Convention
(T
, Convention
(Parent_Type
));
2321 Set_First_Rep_Item
(T
, First_Rep_Item
(Parent_Type
));
2322 Set_Is_First_Subtype
(T
);
2323 Make_Class_Wide_Type
(T
);
2325 if Unknown_Discriminants_Present
(N
) then
2326 Set_Discriminant_Constraint
(T
, No_Elist
);
2329 Build_Derived_Record_Type
(N
, Parent_Type
, T
);
2330 end Analyze_Private_Extension_Declaration
;
2332 ---------------------------------
2333 -- Analyze_Subtype_Declaration --
2334 ---------------------------------
2336 procedure Analyze_Subtype_Declaration
(N
: Node_Id
) is
2337 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
2339 R_Checks
: Check_Result
;
2342 Generate_Definition
(Id
);
2343 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
2344 Init_Size_Align
(Id
);
2346 -- The following guard condition on Enter_Name is to handle cases
2347 -- where the defining identifier has already been entered into the
2348 -- scope but the declaration as a whole needs to be analyzed.
2350 -- This case in particular happens for derived enumeration types. The
2351 -- derived enumeration type is processed as an inserted enumeration
2352 -- type declaration followed by a rewritten subtype declaration. The
2353 -- defining identifier, however, is entered into the name scope very
2354 -- early in the processing of the original type declaration and
2355 -- therefore needs to be avoided here, when the created subtype
2356 -- declaration is analyzed. (See Build_Derived_Types)
2358 -- This also happens when the full view of a private type is derived
2359 -- type with constraints. In this case the entity has been introduced
2360 -- in the private declaration.
2362 if Present
(Etype
(Id
))
2363 and then (Is_Private_Type
(Etype
(Id
))
2364 or else Is_Task_Type
(Etype
(Id
))
2365 or else Is_Rewrite_Substitution
(N
))
2373 T
:= Process_Subtype
(Subtype_Indication
(N
), N
, Id
, 'P');
2375 -- Inherit common attributes
2377 Set_Is_Generic_Type
(Id
, Is_Generic_Type
(Base_Type
(T
)));
2378 Set_Is_Volatile
(Id
, Is_Volatile
(T
));
2379 Set_Treat_As_Volatile
(Id
, Treat_As_Volatile
(T
));
2380 Set_Is_Atomic
(Id
, Is_Atomic
(T
));
2382 -- In the case where there is no constraint given in the subtype
2383 -- indication, Process_Subtype just returns the Subtype_Mark,
2384 -- so its semantic attributes must be established here.
2386 if Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
then
2387 Set_Etype
(Id
, Base_Type
(T
));
2391 Set_Ekind
(Id
, E_Array_Subtype
);
2392 Copy_Array_Subtype_Attributes
(Id
, T
);
2394 when Decimal_Fixed_Point_Kind
=>
2395 Set_Ekind
(Id
, E_Decimal_Fixed_Point_Subtype
);
2396 Set_Digits_Value
(Id
, Digits_Value
(T
));
2397 Set_Delta_Value
(Id
, Delta_Value
(T
));
2398 Set_Scale_Value
(Id
, Scale_Value
(T
));
2399 Set_Small_Value
(Id
, Small_Value
(T
));
2400 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
2401 Set_Machine_Radix_10
(Id
, Machine_Radix_10
(T
));
2402 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2403 Set_RM_Size
(Id
, RM_Size
(T
));
2405 when Enumeration_Kind
=>
2406 Set_Ekind
(Id
, E_Enumeration_Subtype
);
2407 Set_First_Literal
(Id
, First_Literal
(Base_Type
(T
)));
2408 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
2409 Set_Is_Character_Type
(Id
, Is_Character_Type
(T
));
2410 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2411 Set_RM_Size
(Id
, RM_Size
(T
));
2413 when Ordinary_Fixed_Point_Kind
=>
2414 Set_Ekind
(Id
, E_Ordinary_Fixed_Point_Subtype
);
2415 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
2416 Set_Small_Value
(Id
, Small_Value
(T
));
2417 Set_Delta_Value
(Id
, Delta_Value
(T
));
2418 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2419 Set_RM_Size
(Id
, RM_Size
(T
));
2422 Set_Ekind
(Id
, E_Floating_Point_Subtype
);
2423 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
2424 Set_Digits_Value
(Id
, Digits_Value
(T
));
2425 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2427 when Signed_Integer_Kind
=>
2428 Set_Ekind
(Id
, E_Signed_Integer_Subtype
);
2429 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
2430 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2431 Set_RM_Size
(Id
, RM_Size
(T
));
2433 when Modular_Integer_Kind
=>
2434 Set_Ekind
(Id
, E_Modular_Integer_Subtype
);
2435 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
2436 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2437 Set_RM_Size
(Id
, RM_Size
(T
));
2439 when Class_Wide_Kind
=>
2440 Set_Ekind
(Id
, E_Class_Wide_Subtype
);
2441 Set_First_Entity
(Id
, First_Entity
(T
));
2442 Set_Last_Entity
(Id
, Last_Entity
(T
));
2443 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
2444 Set_Cloned_Subtype
(Id
, T
);
2445 Set_Is_Tagged_Type
(Id
, True);
2446 Set_Has_Unknown_Discriminants
2449 if Ekind
(T
) = E_Class_Wide_Subtype
then
2450 Set_Equivalent_Type
(Id
, Equivalent_Type
(T
));
2453 when E_Record_Type | E_Record_Subtype
=>
2454 Set_Ekind
(Id
, E_Record_Subtype
);
2456 if Ekind
(T
) = E_Record_Subtype
2457 and then Present
(Cloned_Subtype
(T
))
2459 Set_Cloned_Subtype
(Id
, Cloned_Subtype
(T
));
2461 Set_Cloned_Subtype
(Id
, T
);
2464 Set_First_Entity
(Id
, First_Entity
(T
));
2465 Set_Last_Entity
(Id
, Last_Entity
(T
));
2466 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
2467 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2468 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
2469 Set_Has_Unknown_Discriminants
2470 (Id
, Has_Unknown_Discriminants
(T
));
2472 if Has_Discriminants
(T
) then
2473 Set_Discriminant_Constraint
2474 (Id
, Discriminant_Constraint
(T
));
2475 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
2477 elsif Has_Unknown_Discriminants
(Id
) then
2478 Set_Discriminant_Constraint
(Id
, No_Elist
);
2481 if Is_Tagged_Type
(T
) then
2482 Set_Is_Tagged_Type
(Id
);
2483 Set_Is_Abstract
(Id
, Is_Abstract
(T
));
2484 Set_Primitive_Operations
2485 (Id
, Primitive_Operations
(T
));
2486 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
2489 when Private_Kind
=>
2490 Set_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
2491 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
2492 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2493 Set_First_Entity
(Id
, First_Entity
(T
));
2494 Set_Last_Entity
(Id
, Last_Entity
(T
));
2495 Set_Private_Dependents
(Id
, New_Elmt_List
);
2496 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
2497 Set_Has_Unknown_Discriminants
2498 (Id
, Has_Unknown_Discriminants
(T
));
2500 if Is_Tagged_Type
(T
) then
2501 Set_Is_Tagged_Type
(Id
);
2502 Set_Is_Abstract
(Id
, Is_Abstract
(T
));
2503 Set_Primitive_Operations
2504 (Id
, Primitive_Operations
(T
));
2505 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
2508 -- In general the attributes of the subtype of a private
2509 -- type are the attributes of the partial view of parent.
2510 -- However, the full view may be a discriminated type,
2511 -- and the subtype must share the discriminant constraint
2512 -- to generate correct calls to initialization procedures.
2514 if Has_Discriminants
(T
) then
2515 Set_Discriminant_Constraint
2516 (Id
, Discriminant_Constraint
(T
));
2517 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
2519 elsif Present
(Full_View
(T
))
2520 and then Has_Discriminants
(Full_View
(T
))
2522 Set_Discriminant_Constraint
2523 (Id
, Discriminant_Constraint
(Full_View
(T
)));
2524 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
2526 -- This would seem semantically correct, but apparently
2527 -- confuses the back-end (4412-009). To be explained ???
2529 -- Set_Has_Discriminants (Id);
2532 Prepare_Private_Subtype_Completion
(Id
, N
);
2535 Set_Ekind
(Id
, E_Access_Subtype
);
2536 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2537 Set_Is_Access_Constant
2538 (Id
, Is_Access_Constant
(T
));
2539 Set_Directly_Designated_Type
2540 (Id
, Designated_Type
(T
));
2542 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
2543 -- and carry out some static checks
2545 if Null_Exclusion_Present
(N
)
2546 or else Can_Never_Be_Null
(T
)
2548 Set_Can_Never_Be_Null
(Id
);
2550 if Null_Exclusion_Present
(N
)
2551 and then Can_Never_Be_Null
(T
)
2554 ("(Ada 2005) null exclusion not allowed if parent "
2555 & "is already non-null", Subtype_Indication
(N
));
2559 -- A Pure library_item must not contain the declaration of a
2560 -- named access type, except within a subprogram, generic
2561 -- subprogram, task unit, or protected unit (RM 10.2.1(16)).
2563 if Comes_From_Source
(Id
)
2564 and then In_Pure_Unit
2565 and then not In_Subprogram_Task_Protected_Unit
2568 ("named access types not allowed in pure unit", N
);
2571 when Concurrent_Kind
=>
2572 Set_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
2573 Set_Corresponding_Record_Type
(Id
,
2574 Corresponding_Record_Type
(T
));
2575 Set_First_Entity
(Id
, First_Entity
(T
));
2576 Set_First_Private_Entity
(Id
, First_Private_Entity
(T
));
2577 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
2578 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
2579 Set_Last_Entity
(Id
, Last_Entity
(T
));
2581 if Has_Discriminants
(T
) then
2582 Set_Discriminant_Constraint
(Id
,
2583 Discriminant_Constraint
(T
));
2584 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
2587 -- If the subtype name denotes an incomplete type
2588 -- an error was already reported by Process_Subtype.
2590 when E_Incomplete_Type
=>
2591 Set_Etype
(Id
, Any_Type
);
2594 raise Program_Error
;
2598 if Etype
(Id
) = Any_Type
then
2602 -- Some common processing on all types
2604 Set_Size_Info
(Id
, T
);
2605 Set_First_Rep_Item
(Id
, First_Rep_Item
(T
));
2609 Set_Is_Immediately_Visible
(Id
, True);
2610 Set_Depends_On_Private
(Id
, Has_Private_Component
(T
));
2612 if Present
(Generic_Parent_Type
(N
))
2615 (Parent
(Generic_Parent_Type
(N
))) /= N_Formal_Type_Declaration
2617 (Formal_Type_Definition
(Parent
(Generic_Parent_Type
(N
))))
2618 /= N_Formal_Private_Type_Definition
)
2620 if Is_Tagged_Type
(Id
) then
2621 if Is_Class_Wide_Type
(Id
) then
2622 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, Etype
(T
));
2624 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, T
);
2627 elsif Scope
(Etype
(Id
)) /= Standard_Standard
then
2628 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
);
2632 if Is_Private_Type
(T
)
2633 and then Present
(Full_View
(T
))
2635 Conditional_Delay
(Id
, Full_View
(T
));
2637 -- The subtypes of components or subcomponents of protected types
2638 -- do not need freeze nodes, which would otherwise appear in the
2639 -- wrong scope (before the freeze node for the protected type). The
2640 -- proper subtypes are those of the subcomponents of the corresponding
2643 elsif Ekind
(Scope
(Id
)) /= E_Protected_Type
2644 and then Present
(Scope
(Scope
(Id
))) -- error defense!
2645 and then Ekind
(Scope
(Scope
(Id
))) /= E_Protected_Type
2647 Conditional_Delay
(Id
, T
);
2650 -- Check that constraint_error is raised for a scalar subtype
2651 -- indication when the lower or upper bound of a non-null range
2652 -- lies outside the range of the type mark.
2654 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
2655 if Is_Scalar_Type
(Etype
(Id
))
2656 and then Scalar_Range
(Id
) /=
2657 Scalar_Range
(Etype
(Subtype_Mark
2658 (Subtype_Indication
(N
))))
2662 Etype
(Subtype_Mark
(Subtype_Indication
(N
))));
2664 elsif Is_Array_Type
(Etype
(Id
))
2665 and then Present
(First_Index
(Id
))
2667 -- This really should be a subprogram that finds the indications
2670 if ((Nkind
(First_Index
(Id
)) = N_Identifier
2671 and then Ekind
(Entity
(First_Index
(Id
))) in Scalar_Kind
)
2672 or else Nkind
(First_Index
(Id
)) = N_Subtype_Indication
)
2674 Nkind
(Scalar_Range
(Etype
(First_Index
(Id
)))) = N_Range
2677 Target_Typ
: constant Entity_Id
:=
2680 (Subtype_Mark
(Subtype_Indication
(N
)))));
2684 (Scalar_Range
(Etype
(First_Index
(Id
))),
2686 Etype
(First_Index
(Id
)),
2687 Defining_Identifier
(N
));
2693 Sloc
(Defining_Identifier
(N
)));
2699 Check_Eliminated
(Id
);
2700 end Analyze_Subtype_Declaration
;
2702 --------------------------------
2703 -- Analyze_Subtype_Indication --
2704 --------------------------------
2706 procedure Analyze_Subtype_Indication
(N
: Node_Id
) is
2707 T
: constant Entity_Id
:= Subtype_Mark
(N
);
2708 R
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
2715 Set_Etype
(N
, Etype
(R
));
2717 Set_Error_Posted
(R
);
2718 Set_Error_Posted
(T
);
2720 end Analyze_Subtype_Indication
;
2722 ------------------------------
2723 -- Analyze_Type_Declaration --
2724 ------------------------------
2726 procedure Analyze_Type_Declaration
(N
: Node_Id
) is
2727 Def
: constant Node_Id
:= Type_Definition
(N
);
2728 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
2732 Is_Remote
: constant Boolean :=
2733 (Is_Remote_Types
(Current_Scope
)
2734 or else Is_Remote_Call_Interface
(Current_Scope
))
2735 and then not (In_Private_Part
(Current_Scope
)
2737 In_Package_Body
(Current_Scope
));
2740 Prev
:= Find_Type_Name
(N
);
2742 -- The full view, if present, now points to the current type
2744 -- Ada 2005 (AI-50217): If the type was previously decorated when
2745 -- imported through a LIMITED WITH clause, it appears as incomplete
2746 -- but has no full view.
2748 if Ekind
(Prev
) = E_Incomplete_Type
2749 and then Present
(Full_View
(Prev
))
2751 T
:= Full_View
(Prev
);
2756 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
2758 -- We set the flag Is_First_Subtype here. It is needed to set the
2759 -- corresponding flag for the Implicit class-wide-type created
2760 -- during tagged types processing.
2762 Set_Is_First_Subtype
(T
, True);
2764 -- Only composite types other than array types are allowed to have
2769 -- For derived types, the rule will be checked once we've figured
2770 -- out the parent type.
2772 when N_Derived_Type_Definition
=>
2775 -- For record types, discriminants are allowed
2777 when N_Record_Definition
=>
2781 if Present
(Discriminant_Specifications
(N
)) then
2783 ("elementary or array type cannot have discriminants",
2785 (First
(Discriminant_Specifications
(N
))));
2789 -- Elaborate the type definition according to kind, and generate
2790 -- subsidiary (implicit) subtypes where needed. We skip this if
2791 -- it was already done (this happens during the reanalysis that
2792 -- follows a call to the high level optimizer).
2794 if not Analyzed
(T
) then
2799 when N_Access_To_Subprogram_Definition
=>
2800 Access_Subprogram_Declaration
(T
, Def
);
2802 -- If this is a remote access to subprogram, we must create
2803 -- the equivalent fat pointer type, and related subprograms.
2806 Process_Remote_AST_Declaration
(N
);
2809 -- Validate categorization rule against access type declaration
2810 -- usually a violation in Pure unit, Shared_Passive unit.
2812 Validate_Access_Type_Declaration
(T
, N
);
2814 when N_Access_To_Object_Definition
=>
2815 Access_Type_Declaration
(T
, Def
);
2817 -- Validate categorization rule against access type declaration
2818 -- usually a violation in Pure unit, Shared_Passive unit.
2820 Validate_Access_Type_Declaration
(T
, N
);
2822 -- If we are in a Remote_Call_Interface package and define
2823 -- a RACW, Read and Write attribute must be added.
2826 and then Is_Remote_Access_To_Class_Wide_Type
(Def_Id
)
2828 Add_RACW_Features
(Def_Id
);
2831 -- Set no strict aliasing flag if config pragma seen
2833 if Opt
.No_Strict_Aliasing
then
2834 Set_No_Strict_Aliasing
(Base_Type
(Def_Id
));
2837 when N_Array_Type_Definition
=>
2838 Array_Type_Declaration
(T
, Def
);
2840 when N_Derived_Type_Definition
=>
2841 Derived_Type_Declaration
(T
, N
, T
/= Def_Id
);
2843 when N_Enumeration_Type_Definition
=>
2844 Enumeration_Type_Declaration
(T
, Def
);
2846 when N_Floating_Point_Definition
=>
2847 Floating_Point_Type_Declaration
(T
, Def
);
2849 when N_Decimal_Fixed_Point_Definition
=>
2850 Decimal_Fixed_Point_Type_Declaration
(T
, Def
);
2852 when N_Ordinary_Fixed_Point_Definition
=>
2853 Ordinary_Fixed_Point_Type_Declaration
(T
, Def
);
2855 when N_Signed_Integer_Type_Definition
=>
2856 Signed_Integer_Type_Declaration
(T
, Def
);
2858 when N_Modular_Type_Definition
=>
2859 Modular_Type_Declaration
(T
, Def
);
2861 when N_Record_Definition
=>
2862 Record_Type_Declaration
(T
, N
, Prev
);
2865 raise Program_Error
;
2870 if Etype
(T
) = Any_Type
then
2874 -- Some common processing for all types
2876 Set_Depends_On_Private
(T
, Has_Private_Component
(T
));
2878 -- Both the declared entity, and its anonymous base type if one
2879 -- was created, need freeze nodes allocated.
2882 B
: constant Entity_Id
:= Base_Type
(T
);
2885 -- In the case where the base type is different from the first
2886 -- subtype, we pre-allocate a freeze node, and set the proper link
2887 -- to the first subtype. Freeze_Entity will use this preallocated
2888 -- freeze node when it freezes the entity.
2891 Ensure_Freeze_Node
(B
);
2892 Set_First_Subtype_Link
(Freeze_Node
(B
), T
);
2895 if not From_With_Type
(T
) then
2896 Set_Has_Delayed_Freeze
(T
);
2900 -- Case of T is the full declaration of some private type which has
2901 -- been swapped in Defining_Identifier (N).
2903 if T
/= Def_Id
and then Is_Private_Type
(Def_Id
) then
2904 Process_Full_View
(N
, T
, Def_Id
);
2906 -- Record the reference. The form of this is a little strange,
2907 -- since the full declaration has been swapped in. So the first
2908 -- parameter here represents the entity to which a reference is
2909 -- made which is the "real" entity, i.e. the one swapped in,
2910 -- and the second parameter provides the reference location.
2912 Generate_Reference
(T
, T
, 'c');
2913 Set_Completion_Referenced
(Def_Id
);
2915 -- For completion of incomplete type, process incomplete dependents
2916 -- and always mark the full type as referenced (it is the incomplete
2917 -- type that we get for any real reference).
2919 elsif Ekind
(Prev
) = E_Incomplete_Type
then
2920 Process_Incomplete_Dependents
(N
, T
, Prev
);
2921 Generate_Reference
(Prev
, Def_Id
, 'c');
2922 Set_Completion_Referenced
(Def_Id
);
2924 -- If not private type or incomplete type completion, this is a real
2925 -- definition of a new entity, so record it.
2928 Generate_Definition
(Def_Id
);
2931 Check_Eliminated
(Def_Id
);
2932 end Analyze_Type_Declaration
;
2934 --------------------------
2935 -- Analyze_Variant_Part --
2936 --------------------------
2938 procedure Analyze_Variant_Part
(N
: Node_Id
) is
2940 procedure Non_Static_Choice_Error
(Choice
: Node_Id
);
2941 -- Error routine invoked by the generic instantiation below when
2942 -- the variant part has a non static choice.
2944 procedure Process_Declarations
(Variant
: Node_Id
);
2945 -- Analyzes all the declarations associated with a Variant.
2946 -- Needed by the generic instantiation below.
2948 package Variant_Choices_Processing
is new
2949 Generic_Choices_Processing
2950 (Get_Alternatives
=> Variants
,
2951 Get_Choices
=> Discrete_Choices
,
2952 Process_Empty_Choice
=> No_OP
,
2953 Process_Non_Static_Choice
=> Non_Static_Choice_Error
,
2954 Process_Associated_Node
=> Process_Declarations
);
2955 use Variant_Choices_Processing
;
2956 -- Instantiation of the generic choice processing package
2958 -----------------------------
2959 -- Non_Static_Choice_Error --
2960 -----------------------------
2962 procedure Non_Static_Choice_Error
(Choice
: Node_Id
) is
2964 Flag_Non_Static_Expr
2965 ("choice given in variant part is not static!", Choice
);
2966 end Non_Static_Choice_Error
;
2968 --------------------------
2969 -- Process_Declarations --
2970 --------------------------
2972 procedure Process_Declarations
(Variant
: Node_Id
) is
2974 if not Null_Present
(Component_List
(Variant
)) then
2975 Analyze_Declarations
(Component_Items
(Component_List
(Variant
)));
2977 if Present
(Variant_Part
(Component_List
(Variant
))) then
2978 Analyze
(Variant_Part
(Component_List
(Variant
)));
2981 end Process_Declarations
;
2983 -- Variables local to Analyze_Case_Statement
2985 Discr_Name
: Node_Id
;
2986 Discr_Type
: Entity_Id
;
2988 Case_Table
: Choice_Table_Type
(1 .. Number_Of_Choices
(N
));
2990 Dont_Care
: Boolean;
2991 Others_Present
: Boolean := False;
2993 -- Start of processing for Analyze_Variant_Part
2996 Discr_Name
:= Name
(N
);
2997 Analyze
(Discr_Name
);
2999 if Ekind
(Entity
(Discr_Name
)) /= E_Discriminant
then
3000 Error_Msg_N
("invalid discriminant name in variant part", Discr_Name
);
3003 Discr_Type
:= Etype
(Entity
(Discr_Name
));
3005 if not Is_Discrete_Type
(Discr_Type
) then
3007 ("discriminant in a variant part must be of a discrete type",
3012 -- Call the instantiated Analyze_Choices which does the rest of the work
3015 (N
, Discr_Type
, Case_Table
, Last_Choice
, Dont_Care
, Others_Present
);
3016 end Analyze_Variant_Part
;
3018 ----------------------------
3019 -- Array_Type_Declaration --
3020 ----------------------------
3022 procedure Array_Type_Declaration
(T
: in out Entity_Id
; Def
: Node_Id
) is
3023 Component_Def
: constant Node_Id
:= Component_Definition
(Def
);
3024 Element_Type
: Entity_Id
;
3025 Implicit_Base
: Entity_Id
;
3027 Related_Id
: Entity_Id
:= Empty
;
3029 P
: constant Node_Id
:= Parent
(Def
);
3033 if Nkind
(Def
) = N_Constrained_Array_Definition
then
3034 Index
:= First
(Discrete_Subtype_Definitions
(Def
));
3036 Index
:= First
(Subtype_Marks
(Def
));
3039 -- Find proper names for the implicit types which may be public.
3040 -- in case of anonymous arrays we use the name of the first object
3041 -- of that type as prefix.
3044 Related_Id
:= Defining_Identifier
(P
);
3050 while Present
(Index
) loop
3052 Make_Index
(Index
, P
, Related_Id
, Nb_Index
);
3054 Nb_Index
:= Nb_Index
+ 1;
3057 if Present
(Subtype_Indication
(Component_Def
)) then
3058 Element_Type
:= Process_Subtype
(Subtype_Indication
(Component_Def
),
3059 P
, Related_Id
, 'C');
3061 -- Ada 2005 (AI-230): Access Definition case
3063 else pragma Assert
(Present
(Access_Definition
(Component_Def
)));
3064 Element_Type
:= Access_Definition
3065 (Related_Nod
=> Related_Id
,
3066 N
=> Access_Definition
(Component_Def
));
3068 -- Ada 2005 (AI-230): In case of components that are anonymous
3069 -- access types the level of accessibility depends on the enclosing
3072 Set_Scope
(Element_Type
, Current_Scope
); -- Ada 2005 (AI-230)
3074 -- Ada 2005 (AI-254)
3077 CD
: constant Node_Id
:=
3078 Access_To_Subprogram_Definition
3079 (Access_Definition
(Component_Def
));
3081 if Present
(CD
) and then Protected_Present
(CD
) then
3083 Replace_Anonymous_Access_To_Protected_Subprogram
3084 (Def
, Element_Type
);
3089 -- Constrained array case
3092 T
:= Create_Itype
(E_Void
, P
, Related_Id
, 'T');
3095 if Nkind
(Def
) = N_Constrained_Array_Definition
then
3097 -- Establish Implicit_Base as unconstrained base type
3099 Implicit_Base
:= Create_Itype
(E_Array_Type
, P
, Related_Id
, 'B');
3101 Init_Size_Align
(Implicit_Base
);
3102 Set_Etype
(Implicit_Base
, Implicit_Base
);
3103 Set_Scope
(Implicit_Base
, Current_Scope
);
3104 Set_Has_Delayed_Freeze
(Implicit_Base
);
3106 -- The constrained array type is a subtype of the unconstrained one
3108 Set_Ekind
(T
, E_Array_Subtype
);
3109 Init_Size_Align
(T
);
3110 Set_Etype
(T
, Implicit_Base
);
3111 Set_Scope
(T
, Current_Scope
);
3112 Set_Is_Constrained
(T
, True);
3113 Set_First_Index
(T
, First
(Discrete_Subtype_Definitions
(Def
)));
3114 Set_Has_Delayed_Freeze
(T
);
3116 -- Complete setup of implicit base type
3118 Set_First_Index
(Implicit_Base
, First_Index
(T
));
3119 Set_Component_Type
(Implicit_Base
, Element_Type
);
3120 Set_Has_Task
(Implicit_Base
, Has_Task
(Element_Type
));
3121 Set_Component_Size
(Implicit_Base
, Uint_0
);
3122 Set_Has_Controlled_Component
3123 (Implicit_Base
, Has_Controlled_Component
3126 Is_Controlled
(Element_Type
));
3127 Set_Finalize_Storage_Only
3128 (Implicit_Base
, Finalize_Storage_Only
3131 -- Unconstrained array case
3134 Set_Ekind
(T
, E_Array_Type
);
3135 Init_Size_Align
(T
);
3137 Set_Scope
(T
, Current_Scope
);
3138 Set_Component_Size
(T
, Uint_0
);
3139 Set_Is_Constrained
(T
, False);
3140 Set_First_Index
(T
, First
(Subtype_Marks
(Def
)));
3141 Set_Has_Delayed_Freeze
(T
, True);
3142 Set_Has_Task
(T
, Has_Task
(Element_Type
));
3143 Set_Has_Controlled_Component
(T
, Has_Controlled_Component
3146 Is_Controlled
(Element_Type
));
3147 Set_Finalize_Storage_Only
(T
, Finalize_Storage_Only
3151 Set_Component_Type
(Base_Type
(T
), Element_Type
);
3153 if Aliased_Present
(Component_Definition
(Def
)) then
3154 Set_Has_Aliased_Components
(Etype
(T
));
3157 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
3158 -- array to ensure that objects of this type are initialized.
3160 if Ada_Version
>= Ada_05
3161 and then (Null_Exclusion_Present
(Component_Definition
(Def
))
3162 or else Can_Never_Be_Null
(Element_Type
))
3164 Set_Can_Never_Be_Null
(T
);
3166 if Null_Exclusion_Present
(Component_Definition
(Def
))
3167 and then Can_Never_Be_Null
(Element_Type
)
3170 ("(Ada 2005) already a null-excluding type",
3171 Subtype_Indication
(Component_Definition
(Def
)));
3175 Priv
:= Private_Component
(Element_Type
);
3177 if Present
(Priv
) then
3179 -- Check for circular definitions
3181 if Priv
= Any_Type
then
3182 Set_Component_Type
(Etype
(T
), Any_Type
);
3184 -- There is a gap in the visibility of operations on the composite
3185 -- type only if the component type is defined in a different scope.
3187 elsif Scope
(Priv
) = Current_Scope
then
3190 elsif Is_Limited_Type
(Priv
) then
3191 Set_Is_Limited_Composite
(Etype
(T
));
3192 Set_Is_Limited_Composite
(T
);
3194 Set_Is_Private_Composite
(Etype
(T
));
3195 Set_Is_Private_Composite
(T
);
3199 -- Create a concatenation operator for the new type. Internal
3200 -- array types created for packed entities do not need such, they
3201 -- are compatible with the user-defined type.
3203 if Number_Dimensions
(T
) = 1
3204 and then not Is_Packed_Array_Type
(T
)
3206 New_Concatenation_Op
(T
);
3209 -- In the case of an unconstrained array the parser has already
3210 -- verified that all the indices are unconstrained but we still
3211 -- need to make sure that the element type is constrained.
3213 if Is_Indefinite_Subtype
(Element_Type
) then
3215 ("unconstrained element type in array declaration",
3216 Subtype_Indication
(Component_Def
));
3218 elsif Is_Abstract
(Element_Type
) then
3220 ("The type of a component cannot be abstract",
3221 Subtype_Indication
(Component_Def
));
3224 end Array_Type_Declaration
;
3226 ------------------------------------------------------
3227 -- Replace_Anonymous_Access_To_Protected_Subprogram --
3228 ------------------------------------------------------
3230 function Replace_Anonymous_Access_To_Protected_Subprogram
3232 Prev_E
: Entity_Id
) return Entity_Id
3234 Loc
: constant Source_Ptr
:= Sloc
(N
);
3236 Curr_Scope
: constant Scope_Stack_Entry
:=
3237 Scope_Stack
.Table
(Scope_Stack
.Last
);
3239 Anon
: constant Entity_Id
:=
3240 Make_Defining_Identifier
(Loc
,
3241 Chars
=> New_Internal_Name
('S'));
3246 P
: Node_Id
:= Parent
(N
);
3249 Set_Is_Internal
(Anon
);
3252 when N_Component_Declaration |
3253 N_Unconstrained_Array_Definition |
3254 N_Constrained_Array_Definition
=>
3255 Comp
:= Component_Definition
(N
);
3256 Acc
:= Access_Definition
(Component_Definition
(N
));
3258 when N_Discriminant_Specification
=>
3259 Comp
:= Discriminant_Type
(N
);
3260 Acc
:= Discriminant_Type
(N
);
3262 when N_Parameter_Specification
=>
3263 Comp
:= Parameter_Type
(N
);
3264 Acc
:= Parameter_Type
(N
);
3267 raise Program_Error
;
3270 Decl
:= Make_Full_Type_Declaration
(Loc
,
3271 Defining_Identifier
=> Anon
,
3273 Copy_Separate_Tree
(Access_To_Subprogram_Definition
(Acc
)));
3275 Mark_Rewrite_Insertion
(Decl
);
3277 -- Insert the new declaration in the nearest enclosing scope
3279 while Present
(P
) and then not Has_Declarations
(P
) loop
3283 pragma Assert
(Present
(P
));
3285 if Nkind
(P
) = N_Package_Specification
then
3286 Prepend
(Decl
, Visible_Declarations
(P
));
3288 Prepend
(Decl
, Declarations
(P
));
3291 -- Replace the anonymous type with an occurrence of the new declaration.
3292 -- In all cases the rewriten node does not have the null-exclusion
3293 -- attribute because (if present) it was already inherited by the
3294 -- anonymous entity (Anon). Thus, in case of components we do not
3295 -- inherit this attribute.
3297 if Nkind
(N
) = N_Parameter_Specification
then
3298 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
3299 Set_Etype
(Defining_Identifier
(N
), Anon
);
3300 Set_Null_Exclusion_Present
(N
, False);
3303 Make_Component_Definition
(Loc
,
3304 Subtype_Indication
=> New_Occurrence_Of
(Anon
, Loc
)));
3307 Mark_Rewrite_Insertion
(Comp
);
3309 -- Temporarily remove the current scope from the stack to add the new
3310 -- declarations to the enclosing scope
3312 Scope_Stack
.Decrement_Last
;
3314 Scope_Stack
.Append
(Curr_Scope
);
3316 Set_Original_Access_Type
(Anon
, Prev_E
);
3318 end Replace_Anonymous_Access_To_Protected_Subprogram
;
3320 -------------------------------
3321 -- Build_Derived_Access_Type --
3322 -------------------------------
3324 procedure Build_Derived_Access_Type
3326 Parent_Type
: Entity_Id
;
3327 Derived_Type
: Entity_Id
)
3329 S
: constant Node_Id
:= Subtype_Indication
(Type_Definition
(N
));
3331 Desig_Type
: Entity_Id
;
3333 Discr_Con_Elist
: Elist_Id
;
3334 Discr_Con_El
: Elmt_Id
;
3338 -- Set the designated type so it is available in case this is
3339 -- an access to a self-referential type, e.g. a standard list
3340 -- type with a next pointer. Will be reset after subtype is built.
3342 Set_Directly_Designated_Type
3343 (Derived_Type
, Designated_Type
(Parent_Type
));
3345 Subt
:= Process_Subtype
(S
, N
);
3347 if Nkind
(S
) /= N_Subtype_Indication
3348 and then Subt
/= Base_Type
(Subt
)
3350 Set_Ekind
(Derived_Type
, E_Access_Subtype
);
3353 if Ekind
(Derived_Type
) = E_Access_Subtype
then
3355 Pbase
: constant Entity_Id
:= Base_Type
(Parent_Type
);
3356 Ibase
: constant Entity_Id
:=
3357 Create_Itype
(Ekind
(Pbase
), N
, Derived_Type
, 'B');
3358 Svg_Chars
: constant Name_Id
:= Chars
(Ibase
);
3359 Svg_Next_E
: constant Entity_Id
:= Next_Entity
(Ibase
);
3362 Copy_Node
(Pbase
, Ibase
);
3364 Set_Chars
(Ibase
, Svg_Chars
);
3365 Set_Next_Entity
(Ibase
, Svg_Next_E
);
3366 Set_Sloc
(Ibase
, Sloc
(Derived_Type
));
3367 Set_Scope
(Ibase
, Scope
(Derived_Type
));
3368 Set_Freeze_Node
(Ibase
, Empty
);
3369 Set_Is_Frozen
(Ibase
, False);
3370 Set_Comes_From_Source
(Ibase
, False);
3371 Set_Is_First_Subtype
(Ibase
, False);
3373 Set_Etype
(Ibase
, Pbase
);
3374 Set_Etype
(Derived_Type
, Ibase
);
3378 Set_Directly_Designated_Type
3379 (Derived_Type
, Designated_Type
(Subt
));
3381 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Subt
));
3382 Set_Is_Access_Constant
(Derived_Type
, Is_Access_Constant
(Parent_Type
));
3383 Set_Size_Info
(Derived_Type
, Parent_Type
);
3384 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
3385 Set_Depends_On_Private
(Derived_Type
,
3386 Has_Private_Component
(Derived_Type
));
3387 Conditional_Delay
(Derived_Type
, Subt
);
3389 -- Ada 2005 (AI-231). Set the null-exclusion attribute
3391 if Null_Exclusion_Present
(Type_Definition
(N
))
3392 or else Can_Never_Be_Null
(Parent_Type
)
3394 Set_Can_Never_Be_Null
(Derived_Type
);
3397 -- Note: we do not copy the Storage_Size_Variable, since
3398 -- we always go to the root type for this information.
3400 -- Apply range checks to discriminants for derived record case
3401 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
3403 Desig_Type
:= Designated_Type
(Derived_Type
);
3404 if Is_Composite_Type
(Desig_Type
)
3405 and then (not Is_Array_Type
(Desig_Type
))
3406 and then Has_Discriminants
(Desig_Type
)
3407 and then Base_Type
(Desig_Type
) /= Desig_Type
3409 Discr_Con_Elist
:= Discriminant_Constraint
(Desig_Type
);
3410 Discr_Con_El
:= First_Elmt
(Discr_Con_Elist
);
3412 Discr
:= First_Discriminant
(Base_Type
(Desig_Type
));
3413 while Present
(Discr_Con_El
) loop
3414 Apply_Range_Check
(Node
(Discr_Con_El
), Etype
(Discr
));
3415 Next_Elmt
(Discr_Con_El
);
3416 Next_Discriminant
(Discr
);
3419 end Build_Derived_Access_Type
;
3421 ------------------------------
3422 -- Build_Derived_Array_Type --
3423 ------------------------------
3425 procedure Build_Derived_Array_Type
3427 Parent_Type
: Entity_Id
;
3428 Derived_Type
: Entity_Id
)
3430 Loc
: constant Source_Ptr
:= Sloc
(N
);
3431 Tdef
: constant Node_Id
:= Type_Definition
(N
);
3432 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
3433 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
3434 Implicit_Base
: Entity_Id
;
3435 New_Indic
: Node_Id
;
3437 procedure Make_Implicit_Base
;
3438 -- If the parent subtype is constrained, the derived type is a
3439 -- subtype of an implicit base type derived from the parent base.
3441 ------------------------
3442 -- Make_Implicit_Base --
3443 ------------------------
3445 procedure Make_Implicit_Base
is
3448 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
3450 Set_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
3451 Set_Etype
(Implicit_Base
, Parent_Base
);
3453 Copy_Array_Subtype_Attributes
(Implicit_Base
, Parent_Base
);
3454 Copy_Array_Base_Type_Attributes
(Implicit_Base
, Parent_Base
);
3456 Set_Has_Delayed_Freeze
(Implicit_Base
, True);
3457 end Make_Implicit_Base
;
3459 -- Start of processing for Build_Derived_Array_Type
3462 if not Is_Constrained
(Parent_Type
) then
3463 if Nkind
(Indic
) /= N_Subtype_Indication
then
3464 Set_Ekind
(Derived_Type
, E_Array_Type
);
3466 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
3467 Copy_Array_Base_Type_Attributes
(Derived_Type
, Parent_Type
);
3469 Set_Has_Delayed_Freeze
(Derived_Type
, True);
3473 Set_Etype
(Derived_Type
, Implicit_Base
);
3476 Make_Subtype_Declaration
(Loc
,
3477 Defining_Identifier
=> Derived_Type
,
3478 Subtype_Indication
=>
3479 Make_Subtype_Indication
(Loc
,
3480 Subtype_Mark
=> New_Reference_To
(Implicit_Base
, Loc
),
3481 Constraint
=> Constraint
(Indic
)));
3483 Rewrite
(N
, New_Indic
);
3488 if Nkind
(Indic
) /= N_Subtype_Indication
then
3491 Set_Ekind
(Derived_Type
, Ekind
(Parent_Type
));
3492 Set_Etype
(Derived_Type
, Implicit_Base
);
3493 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
3496 Error_Msg_N
("illegal constraint on constrained type", Indic
);
3500 -- If the parent type is not a derived type itself, and is
3501 -- declared in a closed scope (e.g., a subprogram), then we
3502 -- need to explicitly introduce the new type's concatenation
3503 -- operator since Derive_Subprograms will not inherit the
3504 -- parent's operator. If the parent type is unconstrained, the
3505 -- operator is of the unconstrained base type.
3507 if Number_Dimensions
(Parent_Type
) = 1
3508 and then not Is_Limited_Type
(Parent_Type
)
3509 and then not Is_Derived_Type
(Parent_Type
)
3510 and then not Is_Package
(Scope
(Base_Type
(Parent_Type
)))
3512 if not Is_Constrained
(Parent_Type
)
3513 and then Is_Constrained
(Derived_Type
)
3515 New_Concatenation_Op
(Implicit_Base
);
3517 New_Concatenation_Op
(Derived_Type
);
3520 end Build_Derived_Array_Type
;
3522 -----------------------------------
3523 -- Build_Derived_Concurrent_Type --
3524 -----------------------------------
3526 procedure Build_Derived_Concurrent_Type
3528 Parent_Type
: Entity_Id
;
3529 Derived_Type
: Entity_Id
)
3531 D_Constraint
: Node_Id
;
3532 Disc_Spec
: Node_Id
;
3533 Old_Disc
: Entity_Id
;
3534 New_Disc
: Entity_Id
;
3536 Constraint_Present
: constant Boolean :=
3537 Nkind
(Subtype_Indication
(Type_Definition
(N
)))
3538 = N_Subtype_Indication
;
3541 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
3543 if Is_Task_Type
(Parent_Type
) then
3544 Set_Storage_Size_Variable
(Derived_Type
,
3545 Storage_Size_Variable
(Parent_Type
));
3548 if Present
(Discriminant_Specifications
(N
)) then
3549 New_Scope
(Derived_Type
);
3550 Check_Or_Process_Discriminants
(N
, Derived_Type
);
3553 elsif Constraint_Present
then
3555 -- Build constrained subtype and derive from it
3558 Loc
: constant Source_Ptr
:= Sloc
(N
);
3559 Anon
: constant Entity_Id
:=
3560 Make_Defining_Identifier
(Loc
,
3561 New_External_Name
(Chars
(Derived_Type
), 'T'));
3566 Make_Subtype_Declaration
(Loc
,
3567 Defining_Identifier
=> Anon
,
3568 Subtype_Indication
=>
3569 New_Copy_Tree
(Subtype_Indication
(Type_Definition
(N
))));
3570 Insert_Before
(N
, Decl
);
3571 Rewrite
(Subtype_Indication
(Type_Definition
(N
)),
3572 New_Occurrence_Of
(Anon
, Loc
));
3574 Set_Analyzed
(Derived_Type
, False);
3580 -- All attributes are inherited from parent. In particular,
3581 -- entries and the corresponding record type are the same.
3582 -- Discriminants may be renamed, and must be treated separately.
3584 Set_Has_Discriminants
3585 (Derived_Type
, Has_Discriminants
(Parent_Type
));
3586 Set_Corresponding_Record_Type
3587 (Derived_Type
, Corresponding_Record_Type
(Parent_Type
));
3589 if Constraint_Present
then
3590 if not Has_Discriminants
(Parent_Type
) then
3591 Error_Msg_N
("untagged parent must have discriminants", N
);
3593 elsif Present
(Discriminant_Specifications
(N
)) then
3595 -- Verify that new discriminants are used to constrain
3598 Old_Disc
:= First_Discriminant
(Parent_Type
);
3599 New_Disc
:= First_Discriminant
(Derived_Type
);
3600 Disc_Spec
:= First
(Discriminant_Specifications
(N
));
3604 (Constraint
(Subtype_Indication
(Type_Definition
(N
)))));
3606 while Present
(Old_Disc
) and then Present
(Disc_Spec
) loop
3608 if Nkind
(Discriminant_Type
(Disc_Spec
)) /=
3611 Analyze
(Discriminant_Type
(Disc_Spec
));
3613 if not Subtypes_Statically_Compatible
(
3614 Etype
(Discriminant_Type
(Disc_Spec
)),
3618 ("not statically compatible with parent discriminant",
3619 Discriminant_Type
(Disc_Spec
));
3623 if Nkind
(D_Constraint
) = N_Identifier
3624 and then Chars
(D_Constraint
) /=
3625 Chars
(Defining_Identifier
(Disc_Spec
))
3627 Error_Msg_N
("new discriminants must constrain old ones",
3630 Set_Corresponding_Discriminant
(New_Disc
, Old_Disc
);
3633 Next_Discriminant
(Old_Disc
);
3634 Next_Discriminant
(New_Disc
);
3638 if Present
(Old_Disc
) or else Present
(Disc_Spec
) then
3639 Error_Msg_N
("discriminant mismatch in derivation", N
);
3644 elsif Present
(Discriminant_Specifications
(N
)) then
3646 ("missing discriminant constraint in untagged derivation",
3650 if Present
(Discriminant_Specifications
(N
)) then
3651 Old_Disc
:= First_Discriminant
(Parent_Type
);
3652 while Present
(Old_Disc
) loop
3654 if No
(Next_Entity
(Old_Disc
))
3655 or else Ekind
(Next_Entity
(Old_Disc
)) /= E_Discriminant
3657 Set_Next_Entity
(Last_Entity
(Derived_Type
),
3658 Next_Entity
(Old_Disc
));
3662 Next_Discriminant
(Old_Disc
);
3666 Set_First_Entity
(Derived_Type
, First_Entity
(Parent_Type
));
3667 if Has_Discriminants
(Parent_Type
) then
3668 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
3669 Set_Discriminant_Constraint
(
3670 Derived_Type
, Discriminant_Constraint
(Parent_Type
));
3674 Set_Last_Entity
(Derived_Type
, Last_Entity
(Parent_Type
));
3676 Set_Has_Completion
(Derived_Type
);
3677 end Build_Derived_Concurrent_Type
;
3679 ------------------------------------
3680 -- Build_Derived_Enumeration_Type --
3681 ------------------------------------
3683 procedure Build_Derived_Enumeration_Type
3685 Parent_Type
: Entity_Id
;
3686 Derived_Type
: Entity_Id
)
3688 Loc
: constant Source_Ptr
:= Sloc
(N
);
3689 Def
: constant Node_Id
:= Type_Definition
(N
);
3690 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
3691 Implicit_Base
: Entity_Id
;
3692 Literal
: Entity_Id
;
3693 New_Lit
: Entity_Id
;
3694 Literals_List
: List_Id
;
3695 Type_Decl
: Node_Id
;
3697 Rang_Expr
: Node_Id
;
3700 -- Since types Standard.Character and Standard.Wide_Character do
3701 -- not have explicit literals lists we need to process types derived
3702 -- from them specially. This is handled by Derived_Standard_Character.
3703 -- If the parent type is a generic type, there are no literals either,
3704 -- and we construct the same skeletal representation as for the generic
3707 if Root_Type
(Parent_Type
) = Standard_Character
3708 or else Root_Type
(Parent_Type
) = Standard_Wide_Character
3709 or else Root_Type
(Parent_Type
) = Standard_Wide_Wide_Character
3711 Derived_Standard_Character
(N
, Parent_Type
, Derived_Type
);
3713 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
3720 Make_Attribute_Reference
(Loc
,
3721 Attribute_Name
=> Name_First
,
3722 Prefix
=> New_Reference_To
(Derived_Type
, Loc
));
3723 Set_Etype
(Lo
, Derived_Type
);
3726 Make_Attribute_Reference
(Loc
,
3727 Attribute_Name
=> Name_Last
,
3728 Prefix
=> New_Reference_To
(Derived_Type
, Loc
));
3729 Set_Etype
(Hi
, Derived_Type
);
3731 Set_Scalar_Range
(Derived_Type
,
3738 -- If a constraint is present, analyze the bounds to catch
3739 -- premature usage of the derived literals.
3741 if Nkind
(Indic
) = N_Subtype_Indication
3742 and then Nkind
(Range_Expression
(Constraint
(Indic
))) = N_Range
3744 Analyze
(Low_Bound
(Range_Expression
(Constraint
(Indic
))));
3745 Analyze
(High_Bound
(Range_Expression
(Constraint
(Indic
))));
3748 -- Introduce an implicit base type for the derived type even
3749 -- if there is no constraint attached to it, since this seems
3750 -- closer to the Ada semantics. Build a full type declaration
3751 -- tree for the derived type using the implicit base type as
3752 -- the defining identifier. The build a subtype declaration
3753 -- tree which applies the constraint (if any) have it replace
3754 -- the derived type declaration.
3756 Literal
:= First_Literal
(Parent_Type
);
3757 Literals_List
:= New_List
;
3759 while Present
(Literal
)
3760 and then Ekind
(Literal
) = E_Enumeration_Literal
3762 -- Literals of the derived type have the same representation as
3763 -- those of the parent type, but this representation can be
3764 -- overridden by an explicit representation clause. Indicate
3765 -- that there is no explicit representation given yet. These
3766 -- derived literals are implicit operations of the new type,
3767 -- and can be overriden by explicit ones.
3769 if Nkind
(Literal
) = N_Defining_Character_Literal
then
3771 Make_Defining_Character_Literal
(Loc
, Chars
(Literal
));
3773 New_Lit
:= Make_Defining_Identifier
(Loc
, Chars
(Literal
));
3776 Set_Ekind
(New_Lit
, E_Enumeration_Literal
);
3777 Set_Enumeration_Pos
(New_Lit
, Enumeration_Pos
(Literal
));
3778 Set_Enumeration_Rep
(New_Lit
, Enumeration_Rep
(Literal
));
3779 Set_Enumeration_Rep_Expr
(New_Lit
, Empty
);
3780 Set_Alias
(New_Lit
, Literal
);
3781 Set_Is_Known_Valid
(New_Lit
, True);
3783 Append
(New_Lit
, Literals_List
);
3784 Next_Literal
(Literal
);
3788 Make_Defining_Identifier
(Sloc
(Derived_Type
),
3789 New_External_Name
(Chars
(Derived_Type
), 'B'));
3791 -- Indicate the proper nature of the derived type. This must
3792 -- be done before analysis of the literals, to recognize cases
3793 -- when a literal may be hidden by a previous explicit function
3794 -- definition (cf. c83031a).
3796 Set_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
3797 Set_Etype
(Derived_Type
, Implicit_Base
);
3800 Make_Full_Type_Declaration
(Loc
,
3801 Defining_Identifier
=> Implicit_Base
,
3802 Discriminant_Specifications
=> No_List
,
3804 Make_Enumeration_Type_Definition
(Loc
, Literals_List
));
3806 Mark_Rewrite_Insertion
(Type_Decl
);
3807 Insert_Before
(N
, Type_Decl
);
3808 Analyze
(Type_Decl
);
3810 -- After the implicit base is analyzed its Etype needs to be changed
3811 -- to reflect the fact that it is derived from the parent type which
3812 -- was ignored during analysis. We also set the size at this point.
3814 Set_Etype
(Implicit_Base
, Parent_Type
);
3816 Set_Size_Info
(Implicit_Base
, Parent_Type
);
3817 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Type
));
3818 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Type
));
3820 Set_Has_Non_Standard_Rep
3821 (Implicit_Base
, Has_Non_Standard_Rep
3823 Set_Has_Delayed_Freeze
(Implicit_Base
);
3825 -- Process the subtype indication including a validation check
3826 -- on the constraint, if any. If a constraint is given, its bounds
3827 -- must be implicitly converted to the new type.
3829 if Nkind
(Indic
) = N_Subtype_Indication
then
3831 R
: constant Node_Id
:=
3832 Range_Expression
(Constraint
(Indic
));
3835 if Nkind
(R
) = N_Range
then
3836 Hi
:= Build_Scalar_Bound
3837 (High_Bound
(R
), Parent_Type
, Implicit_Base
);
3838 Lo
:= Build_Scalar_Bound
3839 (Low_Bound
(R
), Parent_Type
, Implicit_Base
);
3842 -- Constraint is a Range attribute. Replace with the
3843 -- explicit mention of the bounds of the prefix, which must
3846 Analyze
(Prefix
(R
));
3848 Convert_To
(Implicit_Base
,
3849 Make_Attribute_Reference
(Loc
,
3850 Attribute_Name
=> Name_Last
,
3852 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
3855 Convert_To
(Implicit_Base
,
3856 Make_Attribute_Reference
(Loc
,
3857 Attribute_Name
=> Name_First
,
3859 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
3866 (Type_High_Bound
(Parent_Type
),
3867 Parent_Type
, Implicit_Base
);
3870 (Type_Low_Bound
(Parent_Type
),
3871 Parent_Type
, Implicit_Base
);
3879 -- If we constructed a default range for the case where no range
3880 -- was given, then the expressions in the range must not freeze
3881 -- since they do not correspond to expressions in the source.
3883 if Nkind
(Indic
) /= N_Subtype_Indication
then
3884 Set_Must_Not_Freeze
(Lo
);
3885 Set_Must_Not_Freeze
(Hi
);
3886 Set_Must_Not_Freeze
(Rang_Expr
);
3890 Make_Subtype_Declaration
(Loc
,
3891 Defining_Identifier
=> Derived_Type
,
3892 Subtype_Indication
=>
3893 Make_Subtype_Indication
(Loc
,
3894 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
3896 Make_Range_Constraint
(Loc
,
3897 Range_Expression
=> Rang_Expr
))));
3901 -- If pragma Discard_Names applies on the first subtype of the
3902 -- parent type, then it must be applied on this subtype as well.
3904 if Einfo
.Discard_Names
(First_Subtype
(Parent_Type
)) then
3905 Set_Discard_Names
(Derived_Type
);
3908 -- Apply a range check. Since this range expression doesn't have an
3909 -- Etype, we have to specifically pass the Source_Typ parameter. Is
3912 if Nkind
(Indic
) = N_Subtype_Indication
then
3913 Apply_Range_Check
(Range_Expression
(Constraint
(Indic
)),
3915 Source_Typ
=> Entity
(Subtype_Mark
(Indic
)));
3918 end Build_Derived_Enumeration_Type
;
3920 --------------------------------
3921 -- Build_Derived_Numeric_Type --
3922 --------------------------------
3924 procedure Build_Derived_Numeric_Type
3926 Parent_Type
: Entity_Id
;
3927 Derived_Type
: Entity_Id
)
3929 Loc
: constant Source_Ptr
:= Sloc
(N
);
3930 Tdef
: constant Node_Id
:= Type_Definition
(N
);
3931 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
3932 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
3933 No_Constraint
: constant Boolean := Nkind
(Indic
) /=
3934 N_Subtype_Indication
;
3935 Implicit_Base
: Entity_Id
;
3941 -- Process the subtype indication including a validation check on
3942 -- the constraint if any.
3944 Discard_Node
(Process_Subtype
(Indic
, N
));
3946 -- Introduce an implicit base type for the derived type even if there
3947 -- is no constraint attached to it, since this seems closer to the Ada
3951 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
3953 Set_Etype
(Implicit_Base
, Parent_Base
);
3954 Set_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
3955 Set_Size_Info
(Implicit_Base
, Parent_Base
);
3956 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Base
));
3957 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Base
));
3958 Set_Parent
(Implicit_Base
, Parent
(Derived_Type
));
3960 if Is_Discrete_Or_Fixed_Point_Type
(Parent_Base
) then
3961 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Base
));
3964 Set_Has_Delayed_Freeze
(Implicit_Base
);
3966 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
3967 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
3969 Set_Scalar_Range
(Implicit_Base
,
3974 if Has_Infinities
(Parent_Base
) then
3975 Set_Includes_Infinities
(Scalar_Range
(Implicit_Base
));
3978 -- The Derived_Type, which is the entity of the declaration, is a
3979 -- subtype of the implicit base. Its Ekind is a subtype, even in the
3980 -- absence of an explicit constraint.
3982 Set_Etype
(Derived_Type
, Implicit_Base
);
3984 -- If we did not have a constraint, then the Ekind is set from the
3985 -- parent type (otherwise Process_Subtype has set the bounds)
3987 if No_Constraint
then
3988 Set_Ekind
(Derived_Type
, Subtype_Kind
(Ekind
(Parent_Type
)));
3991 -- If we did not have a range constraint, then set the range from the
3992 -- parent type. Otherwise, the call to Process_Subtype has set the
3996 or else not Has_Range_Constraint
(Indic
)
3998 Set_Scalar_Range
(Derived_Type
,
4000 Low_Bound
=> New_Copy_Tree
(Type_Low_Bound
(Parent_Type
)),
4001 High_Bound
=> New_Copy_Tree
(Type_High_Bound
(Parent_Type
))));
4002 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
4004 if Has_Infinities
(Parent_Type
) then
4005 Set_Includes_Infinities
(Scalar_Range
(Derived_Type
));
4009 -- Set remaining type-specific fields, depending on numeric type
4011 if Is_Modular_Integer_Type
(Parent_Type
) then
4012 Set_Modulus
(Implicit_Base
, Modulus
(Parent_Base
));
4014 Set_Non_Binary_Modulus
4015 (Implicit_Base
, Non_Binary_Modulus
(Parent_Base
));
4017 elsif Is_Floating_Point_Type
(Parent_Type
) then
4019 -- Digits of base type is always copied from the digits value of
4020 -- the parent base type, but the digits of the derived type will
4021 -- already have been set if there was a constraint present.
4023 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
4024 Set_Vax_Float
(Implicit_Base
, Vax_Float
(Parent_Base
));
4026 if No_Constraint
then
4027 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Type
));
4030 elsif Is_Fixed_Point_Type
(Parent_Type
) then
4032 -- Small of base type and derived type are always copied from the
4033 -- parent base type, since smalls never change. The delta of the
4034 -- base type is also copied from the parent base type. However the
4035 -- delta of the derived type will have been set already if a
4036 -- constraint was present.
4038 Set_Small_Value
(Derived_Type
, Small_Value
(Parent_Base
));
4039 Set_Small_Value
(Implicit_Base
, Small_Value
(Parent_Base
));
4040 Set_Delta_Value
(Implicit_Base
, Delta_Value
(Parent_Base
));
4042 if No_Constraint
then
4043 Set_Delta_Value
(Derived_Type
, Delta_Value
(Parent_Type
));
4046 -- The scale and machine radix in the decimal case are always
4047 -- copied from the parent base type.
4049 if Is_Decimal_Fixed_Point_Type
(Parent_Type
) then
4050 Set_Scale_Value
(Derived_Type
, Scale_Value
(Parent_Base
));
4051 Set_Scale_Value
(Implicit_Base
, Scale_Value
(Parent_Base
));
4053 Set_Machine_Radix_10
4054 (Derived_Type
, Machine_Radix_10
(Parent_Base
));
4055 Set_Machine_Radix_10
4056 (Implicit_Base
, Machine_Radix_10
(Parent_Base
));
4058 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
4060 if No_Constraint
then
4061 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Base
));
4064 -- the analysis of the subtype_indication sets the
4065 -- digits value of the derived type.
4072 -- The type of the bounds is that of the parent type, and they
4073 -- must be converted to the derived type.
4075 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
4077 -- The implicit_base should be frozen when the derived type is frozen,
4078 -- but note that it is used in the conversions of the bounds. For fixed
4079 -- types we delay the determination of the bounds until the proper
4080 -- freezing point. For other numeric types this is rejected by GCC, for
4081 -- reasons that are currently unclear (???), so we choose to freeze the
4082 -- implicit base now. In the case of integers and floating point types
4083 -- this is harmless because subsequent representation clauses cannot
4084 -- affect anything, but it is still baffling that we cannot use the
4085 -- same mechanism for all derived numeric types.
4087 if Is_Fixed_Point_Type
(Parent_Type
) then
4088 Conditional_Delay
(Implicit_Base
, Parent_Type
);
4090 Freeze_Before
(N
, Implicit_Base
);
4092 end Build_Derived_Numeric_Type
;
4094 --------------------------------
4095 -- Build_Derived_Private_Type --
4096 --------------------------------
4098 procedure Build_Derived_Private_Type
4100 Parent_Type
: Entity_Id
;
4101 Derived_Type
: Entity_Id
;
4102 Is_Completion
: Boolean;
4103 Derive_Subps
: Boolean := True)
4105 Der_Base
: Entity_Id
;
4107 Full_Decl
: Node_Id
:= Empty
;
4108 Full_Der
: Entity_Id
;
4110 Last_Discr
: Entity_Id
;
4111 Par_Scope
: constant Entity_Id
:= Scope
(Base_Type
(Parent_Type
));
4112 Swapped
: Boolean := False;
4114 procedure Copy_And_Build
;
4115 -- Copy derived type declaration, replace parent with its full view,
4116 -- and analyze new declaration.
4118 --------------------
4119 -- Copy_And_Build --
4120 --------------------
4122 procedure Copy_And_Build
is
4126 if Ekind
(Parent_Type
) in Record_Kind
4128 (Ekind
(Parent_Type
) in Enumeration_Kind
4129 and then Root_Type
(Parent_Type
) /= Standard_Character
4130 and then Root_Type
(Parent_Type
) /= Standard_Wide_Character
4131 and then Root_Type
(Parent_Type
) /= Standard_Wide_Wide_Character
4132 and then not Is_Generic_Type
(Root_Type
(Parent_Type
)))
4134 Full_N
:= New_Copy_Tree
(N
);
4135 Insert_After
(N
, Full_N
);
4136 Build_Derived_Type
(
4137 Full_N
, Parent_Type
, Full_Der
, True, Derive_Subps
=> False);
4140 Build_Derived_Type
(
4141 N
, Parent_Type
, Full_Der
, True, Derive_Subps
=> False);
4145 -- Start of processing for Build_Derived_Private_Type
4148 if Is_Tagged_Type
(Parent_Type
) then
4149 Build_Derived_Record_Type
4150 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
4153 elsif Has_Discriminants
(Parent_Type
) then
4154 if Present
(Full_View
(Parent_Type
)) then
4155 if not Is_Completion
then
4157 -- Copy declaration for subsequent analysis, to provide a
4158 -- completion for what is a private declaration. Indicate that
4159 -- the full type is internally generated.
4161 Full_Decl
:= New_Copy_Tree
(N
);
4162 Full_Der
:= New_Copy
(Derived_Type
);
4163 Set_Comes_From_Source
(Full_Decl
, False);
4165 Insert_After
(N
, Full_Decl
);
4168 -- If this is a completion, the full view being built is
4169 -- itself private. We build a subtype of the parent with
4170 -- the same constraints as this full view, to convey to the
4171 -- back end the constrained components and the size of this
4172 -- subtype. If the parent is constrained, its full view can
4173 -- serve as the underlying full view of the derived type.
4175 if No
(Discriminant_Specifications
(N
)) then
4176 if Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
4177 N_Subtype_Indication
4179 Build_Underlying_Full_View
(N
, Derived_Type
, Parent_Type
);
4181 elsif Is_Constrained
(Full_View
(Parent_Type
)) then
4182 Set_Underlying_Full_View
(Derived_Type
,
4183 Full_View
(Parent_Type
));
4187 -- If there are new discriminants, the parent subtype is
4188 -- constrained by them, but it is not clear how to build
4189 -- the underlying_full_view in this case ???
4196 -- Build partial view of derived type from partial view of parent
4198 Build_Derived_Record_Type
4199 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
4201 if Present
(Full_View
(Parent_Type
))
4202 and then not Is_Completion
4204 if not In_Open_Scopes
(Par_Scope
)
4205 or else not In_Same_Source_Unit
(N
, Parent_Type
)
4207 -- Swap partial and full views temporarily
4209 Install_Private_Declarations
(Par_Scope
);
4210 Install_Visible_Declarations
(Par_Scope
);
4214 -- Build full view of derived type from full view of parent which
4215 -- is now installed. Subprograms have been derived on the partial
4216 -- view, the completion does not derive them anew.
4218 if not Is_Tagged_Type
(Parent_Type
) then
4219 Build_Derived_Record_Type
4220 (Full_Decl
, Parent_Type
, Full_Der
, False);
4223 -- If full view of parent is tagged, the completion
4224 -- inherits the proper primitive operations.
4226 Set_Defining_Identifier
(Full_Decl
, Full_Der
);
4227 Build_Derived_Record_Type
4228 (Full_Decl
, Parent_Type
, Full_Der
, Derive_Subps
);
4229 Set_Analyzed
(Full_Decl
);
4233 Uninstall_Declarations
(Par_Scope
);
4235 if In_Open_Scopes
(Par_Scope
) then
4236 Install_Visible_Declarations
(Par_Scope
);
4240 Der_Base
:= Base_Type
(Derived_Type
);
4241 Set_Full_View
(Derived_Type
, Full_Der
);
4242 Set_Full_View
(Der_Base
, Base_Type
(Full_Der
));
4244 -- Copy the discriminant list from full view to the partial views
4245 -- (base type and its subtype). Gigi requires that the partial
4246 -- and full views have the same discriminants.
4248 -- Note that since the partial view is pointing to discriminants
4249 -- in the full view, their scope will be that of the full view.
4250 -- This might cause some front end problems and need
4253 Discr
:= First_Discriminant
(Base_Type
(Full_Der
));
4254 Set_First_Entity
(Der_Base
, Discr
);
4257 Last_Discr
:= Discr
;
4258 Next_Discriminant
(Discr
);
4259 exit when No
(Discr
);
4262 Set_Last_Entity
(Der_Base
, Last_Discr
);
4264 Set_First_Entity
(Derived_Type
, First_Entity
(Der_Base
));
4265 Set_Last_Entity
(Derived_Type
, Last_Entity
(Der_Base
));
4266 Set_Stored_Constraint
(Full_Der
, Stored_Constraint
(Derived_Type
));
4269 -- If this is a completion, the derived type stays private
4270 -- and there is no need to create a further full view, except
4271 -- in the unusual case when the derivation is nested within a
4272 -- child unit, see below.
4277 elsif Present
(Full_View
(Parent_Type
))
4278 and then Has_Discriminants
(Full_View
(Parent_Type
))
4280 if Has_Unknown_Discriminants
(Parent_Type
)
4281 and then Nkind
(Subtype_Indication
(Type_Definition
(N
)))
4282 = N_Subtype_Indication
4285 ("cannot constrain type with unknown discriminants",
4286 Subtype_Indication
(Type_Definition
(N
)));
4290 -- If full view of parent is a record type, Build full view as
4291 -- a derivation from the parent's full view. Partial view remains
4292 -- private. For code generation and linking, the full view must
4293 -- have the same public status as the partial one. This full view
4294 -- is only needed if the parent type is in an enclosing scope, so
4295 -- that the full view may actually become visible, e.g. in a child
4296 -- unit. This is both more efficient, and avoids order of freezing
4297 -- problems with the added entities.
4299 if not Is_Private_Type
(Full_View
(Parent_Type
))
4300 and then (In_Open_Scopes
(Scope
(Parent_Type
)))
4302 Full_Der
:= Make_Defining_Identifier
(Sloc
(Derived_Type
),
4303 Chars
(Derived_Type
));
4304 Set_Is_Itype
(Full_Der
);
4305 Set_Has_Private_Declaration
(Full_Der
);
4306 Set_Has_Private_Declaration
(Derived_Type
);
4307 Set_Associated_Node_For_Itype
(Full_Der
, N
);
4308 Set_Parent
(Full_Der
, Parent
(Derived_Type
));
4309 Set_Full_View
(Derived_Type
, Full_Der
);
4310 Set_Is_Public
(Full_Der
, Is_Public
(Derived_Type
));
4311 Full_P
:= Full_View
(Parent_Type
);
4312 Exchange_Declarations
(Parent_Type
);
4314 Exchange_Declarations
(Full_P
);
4317 Build_Derived_Record_Type
4318 (N
, Full_View
(Parent_Type
), Derived_Type
,
4319 Derive_Subps
=> False);
4322 -- In any case, the primitive operations are inherited from
4323 -- the parent type, not from the internal full view.
4325 Set_Etype
(Base_Type
(Derived_Type
), Base_Type
(Parent_Type
));
4327 if Derive_Subps
then
4328 Derive_Subprograms
(Parent_Type
, Derived_Type
);
4332 -- Untagged type, No discriminants on either view
4334 if Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
4335 N_Subtype_Indication
4338 ("illegal constraint on type without discriminants", N
);
4341 if Present
(Discriminant_Specifications
(N
))
4342 and then Present
(Full_View
(Parent_Type
))
4343 and then not Is_Tagged_Type
(Full_View
(Parent_Type
))
4346 ("cannot add discriminants to untagged type", N
);
4349 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
4350 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
4351 Set_Is_Controlled
(Derived_Type
, Is_Controlled
(Parent_Type
));
4352 Set_Has_Controlled_Component
4353 (Derived_Type
, Has_Controlled_Component
4356 -- Direct controlled types do not inherit Finalize_Storage_Only flag
4358 if not Is_Controlled
(Parent_Type
) then
4359 Set_Finalize_Storage_Only
4360 (Base_Type
(Derived_Type
), Finalize_Storage_Only
(Parent_Type
));
4363 -- Construct the implicit full view by deriving from full view of
4364 -- the parent type. In order to get proper visibility, we install
4365 -- the parent scope and its declarations.
4367 -- ??? if the parent is untagged private and its completion is
4368 -- tagged, this mechanism will not work because we cannot derive
4369 -- from the tagged full view unless we have an extension
4371 if Present
(Full_View
(Parent_Type
))
4372 and then not Is_Tagged_Type
(Full_View
(Parent_Type
))
4373 and then not Is_Completion
4376 Make_Defining_Identifier
(Sloc
(Derived_Type
),
4377 Chars
=> Chars
(Derived_Type
));
4378 Set_Is_Itype
(Full_Der
);
4379 Set_Has_Private_Declaration
(Full_Der
);
4380 Set_Has_Private_Declaration
(Derived_Type
);
4381 Set_Associated_Node_For_Itype
(Full_Der
, N
);
4382 Set_Parent
(Full_Der
, Parent
(Derived_Type
));
4383 Set_Full_View
(Derived_Type
, Full_Der
);
4385 if not In_Open_Scopes
(Par_Scope
) then
4386 Install_Private_Declarations
(Par_Scope
);
4387 Install_Visible_Declarations
(Par_Scope
);
4389 Uninstall_Declarations
(Par_Scope
);
4391 -- If parent scope is open and in another unit, and parent has a
4392 -- completion, then the derivation is taking place in the visible
4393 -- part of a child unit. In that case retrieve the full view of
4394 -- the parent momentarily.
4396 elsif not In_Same_Source_Unit
(N
, Parent_Type
) then
4397 Full_P
:= Full_View
(Parent_Type
);
4398 Exchange_Declarations
(Parent_Type
);
4400 Exchange_Declarations
(Full_P
);
4402 -- Otherwise it is a local derivation
4408 Set_Scope
(Full_Der
, Current_Scope
);
4409 Set_Is_First_Subtype
(Full_Der
,
4410 Is_First_Subtype
(Derived_Type
));
4411 Set_Has_Size_Clause
(Full_Der
, False);
4412 Set_Has_Alignment_Clause
(Full_Der
, False);
4413 Set_Next_Entity
(Full_Der
, Empty
);
4414 Set_Has_Delayed_Freeze
(Full_Der
);
4415 Set_Is_Frozen
(Full_Der
, False);
4416 Set_Freeze_Node
(Full_Der
, Empty
);
4417 Set_Depends_On_Private
(Full_Der
,
4418 Has_Private_Component
(Full_Der
));
4419 Set_Public_Status
(Full_Der
);
4423 Set_Has_Unknown_Discriminants
(Derived_Type
,
4424 Has_Unknown_Discriminants
(Parent_Type
));
4426 if Is_Private_Type
(Derived_Type
) then
4427 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
4430 if Is_Private_Type
(Parent_Type
)
4431 and then Base_Type
(Parent_Type
) = Parent_Type
4432 and then In_Open_Scopes
(Scope
(Parent_Type
))
4434 Append_Elmt
(Derived_Type
, Private_Dependents
(Parent_Type
));
4436 if Is_Child_Unit
(Scope
(Current_Scope
))
4437 and then Is_Completion
4438 and then In_Private_Part
(Current_Scope
)
4439 and then Scope
(Parent_Type
) /= Current_Scope
4441 -- This is the unusual case where a type completed by a private
4442 -- derivation occurs within a package nested in a child unit,
4443 -- and the parent is declared in an ancestor. In this case, the
4444 -- full view of the parent type will become visible in the body
4445 -- of the enclosing child, and only then will the current type
4446 -- be possibly non-private. We build a underlying full view that
4447 -- will be installed when the enclosing child body is compiled.
4450 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
4454 Make_Defining_Identifier
(Sloc
(Derived_Type
),
4455 Chars
(Derived_Type
));
4456 Set_Is_Itype
(Full_Der
);
4457 Set_Itype
(IR
, Full_Der
);
4458 Insert_After
(N
, IR
);
4460 -- The full view will be used to swap entities on entry/exit
4461 -- to the body, and must appear in the entity list for the
4464 Append_Entity
(Full_Der
, Scope
(Derived_Type
));
4465 Set_Has_Private_Declaration
(Full_Der
);
4466 Set_Has_Private_Declaration
(Derived_Type
);
4467 Set_Associated_Node_For_Itype
(Full_Der
, N
);
4468 Set_Parent
(Full_Der
, Parent
(Derived_Type
));
4469 Full_P
:= Full_View
(Parent_Type
);
4470 Exchange_Declarations
(Parent_Type
);
4472 Exchange_Declarations
(Full_P
);
4473 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
4477 end Build_Derived_Private_Type
;
4479 -------------------------------
4480 -- Build_Derived_Record_Type --
4481 -------------------------------
4485 -- Ideally we would like to use the same model of type derivation for
4486 -- tagged and untagged record types. Unfortunately this is not quite
4487 -- possible because the semantics of representation clauses is different
4488 -- for tagged and untagged records under inheritance. Consider the
4491 -- type R (...) is [tagged] record ... end record;
4492 -- type T (...) is new R (...) [with ...];
4494 -- The representation clauses of T can specify a completely different
4495 -- record layout from R's. Hence the same component can be placed in
4496 -- two very different positions in objects of type T and R. If R and T
4497 -- are tagged types, representation clauses for T can only specify the
4498 -- layout of non inherited components, thus components that are common
4499 -- in R and T have the same position in objects of type R and T.
4501 -- This has two implications. The first is that the entire tree for R's
4502 -- declaration needs to be copied for T in the untagged case, so that T
4503 -- can be viewed as a record type of its own with its own representation
4504 -- clauses. The second implication is the way we handle discriminants.
4505 -- Specifically, in the untagged case we need a way to communicate to Gigi
4506 -- what are the real discriminants in the record, while for the semantics
4507 -- we need to consider those introduced by the user to rename the
4508 -- discriminants in the parent type. This is handled by introducing the
4509 -- notion of stored discriminants. See below for more.
4511 -- Fortunately the way regular components are inherited can be handled in
4512 -- the same way in tagged and untagged types.
4514 -- To complicate things a bit more the private view of a private extension
4515 -- cannot be handled in the same way as the full view (for one thing the
4516 -- semantic rules are somewhat different). We will explain what differs
4519 -- 2. DISCRIMINANTS UNDER INHERITANCE
4521 -- The semantic rules governing the discriminants of derived types are
4524 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
4525 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
4527 -- If parent type has discriminants, then the discriminants that are
4528 -- declared in the derived type are [3.4 (11)]:
4530 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
4533 -- o Otherwise, each discriminant of the parent type (implicitly declared
4534 -- in the same order with the same specifications). In this case, the
4535 -- discriminants are said to be "inherited", or if unknown in the parent
4536 -- are also unknown in the derived type.
4538 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
4540 -- o The parent subtype shall be constrained;
4542 -- o If the parent type is not a tagged type, then each discriminant of
4543 -- the derived type shall be used in the constraint defining a parent
4544 -- subtype [Implementation note: this ensures that the new discriminant
4545 -- can share storage with an existing discriminant.].
4547 -- For the derived type each discriminant of the parent type is either
4548 -- inherited, constrained to equal some new discriminant of the derived
4549 -- type, or constrained to the value of an expression.
4551 -- When inherited or constrained to equal some new discriminant, the
4552 -- parent discriminant and the discriminant of the derived type are said
4555 -- If a discriminant of the parent type is constrained to a specific value
4556 -- in the derived type definition, then the discriminant is said to be
4557 -- "specified" by that derived type definition.
4559 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
4561 -- We have spoken about stored discriminants in point 1 (introduction)
4562 -- above. There are two sort of stored discriminants: implicit and
4563 -- explicit. As long as the derived type inherits the same discriminants as
4564 -- the root record type, stored discriminants are the same as regular
4565 -- discriminants, and are said to be implicit. However, if any discriminant
4566 -- in the root type was renamed in the derived type, then the derived
4567 -- type will contain explicit stored discriminants. Explicit stored
4568 -- discriminants are discriminants in addition to the semantically visible
4569 -- discriminants defined for the derived type. Stored discriminants are
4570 -- used by Gigi to figure out what are the physical discriminants in
4571 -- objects of the derived type (see precise definition in einfo.ads).
4572 -- As an example, consider the following:
4574 -- type R (D1, D2, D3 : Int) is record ... end record;
4575 -- type T1 is new R;
4576 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
4577 -- type T3 is new T2;
4578 -- type T4 (Y : Int) is new T3 (Y, 99);
4580 -- The following table summarizes the discriminants and stored
4581 -- discriminants in R and T1 through T4.
4583 -- Type Discrim Stored Discrim Comment
4584 -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
4585 -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
4586 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
4587 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
4588 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
4590 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
4591 -- find the corresponding discriminant in the parent type, while
4592 -- Original_Record_Component (abbreviated ORC below), the actual physical
4593 -- component that is renamed. Finally the field Is_Completely_Hidden
4594 -- (abbreviated ICH below) is set for all explicit stored discriminants
4595 -- (see einfo.ads for more info). For the above example this gives:
4597 -- Discrim CD ORC ICH
4598 -- ^^^^^^^ ^^ ^^^ ^^^
4599 -- D1 in R empty itself no
4600 -- D2 in R empty itself no
4601 -- D3 in R empty itself no
4603 -- D1 in T1 D1 in R itself no
4604 -- D2 in T1 D2 in R itself no
4605 -- D3 in T1 D3 in R itself no
4607 -- X1 in T2 D3 in T1 D3 in T2 no
4608 -- X2 in T2 D1 in T1 D1 in T2 no
4609 -- D1 in T2 empty itself yes
4610 -- D2 in T2 empty itself yes
4611 -- D3 in T2 empty itself yes
4613 -- X1 in T3 X1 in T2 D3 in T3 no
4614 -- X2 in T3 X2 in T2 D1 in T3 no
4615 -- D1 in T3 empty itself yes
4616 -- D2 in T3 empty itself yes
4617 -- D3 in T3 empty itself yes
4619 -- Y in T4 X1 in T3 D3 in T3 no
4620 -- D1 in T3 empty itself yes
4621 -- D2 in T3 empty itself yes
4622 -- D3 in T3 empty itself yes
4624 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
4626 -- Type derivation for tagged types is fairly straightforward. if no
4627 -- discriminants are specified by the derived type, these are inherited
4628 -- from the parent. No explicit stored discriminants are ever necessary.
4629 -- The only manipulation that is done to the tree is that of adding a
4630 -- _parent field with parent type and constrained to the same constraint
4631 -- specified for the parent in the derived type definition. For instance:
4633 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
4634 -- type T1 is new R with null record;
4635 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
4637 -- are changed into:
4639 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
4640 -- _parent : R (D1, D2, D3);
4643 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
4644 -- _parent : T1 (X2, 88, X1);
4647 -- The discriminants actually present in R, T1 and T2 as well as their CD,
4648 -- ORC and ICH fields are:
4650 -- Discrim CD ORC ICH
4651 -- ^^^^^^^ ^^ ^^^ ^^^
4652 -- D1 in R empty itself no
4653 -- D2 in R empty itself no
4654 -- D3 in R empty itself no
4656 -- D1 in T1 D1 in R D1 in R no
4657 -- D2 in T1 D2 in R D2 in R no
4658 -- D3 in T1 D3 in R D3 in R no
4660 -- X1 in T2 D3 in T1 D3 in R no
4661 -- X2 in T2 D1 in T1 D1 in R no
4663 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
4665 -- Regardless of whether we dealing with a tagged or untagged type
4666 -- we will transform all derived type declarations of the form
4668 -- type T is new R (...) [with ...];
4670 -- subtype S is R (...);
4671 -- type T is new S [with ...];
4673 -- type BT is new R [with ...];
4674 -- subtype T is BT (...);
4676 -- That is, the base derived type is constrained only if it has no
4677 -- discriminants. The reason for doing this is that GNAT's semantic model
4678 -- assumes that a base type with discriminants is unconstrained.
4680 -- Note that, strictly speaking, the above transformation is not always
4681 -- correct. Consider for instance the following excerpt from ACVC b34011a:
4683 -- procedure B34011A is
4684 -- type REC (D : integer := 0) is record
4689 -- type T6 is new Rec;
4690 -- function F return T6;
4695 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
4698 -- The definition of Q6.U is illegal. However transforming Q6.U into
4700 -- type BaseU is new T6;
4701 -- subtype U is BaseU (Q6.F.I)
4703 -- turns U into a legal subtype, which is incorrect. To avoid this problem
4704 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
4705 -- the transformation described above.
4707 -- There is another instance where the above transformation is incorrect.
4711 -- type Base (D : Integer) is tagged null record;
4712 -- procedure P (X : Base);
4714 -- type Der is new Base (2) with null record;
4715 -- procedure P (X : Der);
4718 -- Then the above transformation turns this into
4720 -- type Der_Base is new Base with null record;
4721 -- -- procedure P (X : Base) is implicitly inherited here
4722 -- -- as procedure P (X : Der_Base).
4724 -- subtype Der is Der_Base (2);
4725 -- procedure P (X : Der);
4726 -- -- The overriding of P (X : Der_Base) is illegal since we
4727 -- -- have a parameter conformance problem.
4729 -- To get around this problem, after having semantically processed Der_Base
4730 -- and the rewritten subtype declaration for Der, we copy Der_Base field
4731 -- Discriminant_Constraint from Der so that when parameter conformance is
4732 -- checked when P is overridden, no semantic errors are flagged.
4734 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
4736 -- Regardless of whether we are dealing with a tagged or untagged type
4737 -- we will transform all derived type declarations of the form
4739 -- type R (D1, .., Dn : ...) is [tagged] record ...;
4740 -- type T is new R [with ...];
4742 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
4744 -- The reason for such transformation is that it allows us to implement a
4745 -- very clean form of component inheritance as explained below.
4747 -- Note that this transformation is not achieved by direct tree rewriting
4748 -- and manipulation, but rather by redoing the semantic actions that the
4749 -- above transformation will entail. This is done directly in routine
4750 -- Inherit_Components.
4752 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
4754 -- In both tagged and untagged derived types, regular non discriminant
4755 -- components are inherited in the derived type from the parent type. In
4756 -- the absence of discriminants component, inheritance is straightforward
4757 -- as components can simply be copied from the parent.
4759 -- If the parent has discriminants, inheriting components constrained with
4760 -- these discriminants requires caution. Consider the following example:
4762 -- type R (D1, D2 : Positive) is [tagged] record
4763 -- S : String (D1 .. D2);
4766 -- type T1 is new R [with null record];
4767 -- type T2 (X : positive) is new R (1, X) [with null record];
4769 -- As explained in 6. above, T1 is rewritten as
4770 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
4771 -- which makes the treatment for T1 and T2 identical.
4773 -- What we want when inheriting S, is that references to D1 and D2 in R are
4774 -- replaced with references to their correct constraints, ie D1 and D2 in
4775 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
4776 -- with either discriminant references in the derived type or expressions.
4777 -- This replacement is achieved as follows: before inheriting R's
4778 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
4779 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
4780 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
4781 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
4782 -- by String (1 .. X).
4784 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
4786 -- We explain here the rules governing private type extensions relevant to
4787 -- type derivation. These rules are explained on the following example:
4789 -- type D [(...)] is new A [(...)] with private; <-- partial view
4790 -- type D [(...)] is new P [(...)] with null record; <-- full view
4792 -- Type A is called the ancestor subtype of the private extension.
4793 -- Type P is the parent type of the full view of the private extension. It
4794 -- must be A or a type derived from A.
4796 -- The rules concerning the discriminants of private type extensions are
4799 -- o If a private extension inherits known discriminants from the ancestor
4800 -- subtype, then the full view shall also inherit its discriminants from
4801 -- the ancestor subtype and the parent subtype of the full view shall be
4802 -- constrained if and only if the ancestor subtype is constrained.
4804 -- o If a partial view has unknown discriminants, then the full view may
4805 -- define a definite or an indefinite subtype, with or without
4808 -- o If a partial view has neither known nor unknown discriminants, then
4809 -- the full view shall define a definite subtype.
4811 -- o If the ancestor subtype of a private extension has constrained
4812 -- discriminants, then the parent subtype of the full view shall impose a
4813 -- statically matching constraint on those discriminants.
4815 -- This means that only the following forms of private extensions are
4818 -- type D is new A with private; <-- partial view
4819 -- type D is new P with null record; <-- full view
4821 -- If A has no discriminants than P has no discriminants, otherwise P must
4822 -- inherit A's discriminants.
4824 -- type D is new A (...) with private; <-- partial view
4825 -- type D is new P (:::) with null record; <-- full view
4827 -- P must inherit A's discriminants and (...) and (:::) must statically
4830 -- subtype A is R (...);
4831 -- type D is new A with private; <-- partial view
4832 -- type D is new P with null record; <-- full view
4834 -- P must have inherited R's discriminants and must be derived from A or
4835 -- any of its subtypes.
4837 -- type D (..) is new A with private; <-- partial view
4838 -- type D (..) is new P [(:::)] with null record; <-- full view
4840 -- No specific constraints on P's discriminants or constraint (:::).
4841 -- Note that A can be unconstrained, but the parent subtype P must either
4842 -- be constrained or (:::) must be present.
4844 -- type D (..) is new A [(...)] with private; <-- partial view
4845 -- type D (..) is new P [(:::)] with null record; <-- full view
4847 -- P's constraints on A's discriminants must statically match those
4848 -- imposed by (...).
4850 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
4852 -- The full view of a private extension is handled exactly as described
4853 -- above. The model chose for the private view of a private extension is
4854 -- the same for what concerns discriminants (ie they receive the same
4855 -- treatment as in the tagged case). However, the private view of the
4856 -- private extension always inherits the components of the parent base,
4857 -- without replacing any discriminant reference. Strictly speaking this is
4858 -- incorrect. However, Gigi never uses this view to generate code so this
4859 -- is a purely semantic issue. In theory, a set of transformations similar
4860 -- to those given in 5. and 6. above could be applied to private views of
4861 -- private extensions to have the same model of component inheritance as
4862 -- for non private extensions. However, this is not done because it would
4863 -- further complicate private type processing. Semantically speaking, this
4864 -- leaves us in an uncomfortable situation. As an example consider:
4867 -- type R (D : integer) is tagged record
4868 -- S : String (1 .. D);
4870 -- procedure P (X : R);
4871 -- type T is new R (1) with private;
4873 -- type T is new R (1) with null record;
4876 -- This is transformed into:
4879 -- type R (D : integer) is tagged record
4880 -- S : String (1 .. D);
4882 -- procedure P (X : R);
4883 -- type T is new R (1) with private;
4885 -- type BaseT is new R with null record;
4886 -- subtype T is BaseT (1);
4889 -- (strictly speaking the above is incorrect Ada)
4891 -- From the semantic standpoint the private view of private extension T
4892 -- should be flagged as constrained since one can clearly have
4896 -- in a unit withing Pack. However, when deriving subprograms for the
4897 -- private view of private extension T, T must be seen as unconstrained
4898 -- since T has discriminants (this is a constraint of the current
4899 -- subprogram derivation model). Thus, when processing the private view of
4900 -- a private extension such as T, we first mark T as unconstrained, we
4901 -- process it, we perform program derivation and just before returning from
4902 -- Build_Derived_Record_Type we mark T as constrained.
4904 -- ??? Are there are other uncomfortable cases that we will have to
4907 -- 10. RECORD_TYPE_WITH_PRIVATE complications
4909 -- Types that are derived from a visible record type and have a private
4910 -- extension present other peculiarities. They behave mostly like private
4911 -- types, but if they have primitive operations defined, these will not
4912 -- have the proper signatures for further inheritance, because other
4913 -- primitive operations will use the implicit base that we define for
4914 -- private derivations below. This affect subprogram inheritance (see
4915 -- Derive_Subprograms for details). We also derive the implicit base from
4916 -- the base type of the full view, so that the implicit base is a record
4917 -- type and not another private type, This avoids infinite loops.
4919 procedure Build_Derived_Record_Type
4921 Parent_Type
: Entity_Id
;
4922 Derived_Type
: Entity_Id
;
4923 Derive_Subps
: Boolean := True)
4925 Loc
: constant Source_Ptr
:= Sloc
(N
);
4926 Parent_Base
: Entity_Id
;
4929 Discrim
: Entity_Id
;
4930 Last_Discrim
: Entity_Id
;
4933 Discs
: Elist_Id
:= New_Elmt_List
;
4934 -- An empty Discs list means that there were no constraints in the
4935 -- subtype indication or that there was an error processing it.
4937 Assoc_List
: Elist_Id
;
4938 New_Discrs
: Elist_Id
;
4939 New_Base
: Entity_Id
;
4941 New_Indic
: Node_Id
;
4943 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Parent_Type
);
4944 Discriminant_Specs
: constant Boolean :=
4945 Present
(Discriminant_Specifications
(N
));
4946 Private_Extension
: constant Boolean :=
4947 (Nkind
(N
) = N_Private_Extension_Declaration
);
4949 Constraint_Present
: Boolean;
4950 Inherit_Discrims
: Boolean := False;
4952 Save_Etype
: Entity_Id
;
4953 Save_Discr_Constr
: Elist_Id
;
4954 Save_Next_Entity
: Entity_Id
;
4957 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
4958 and then Present
(Full_View
(Parent_Type
))
4959 and then Has_Discriminants
(Parent_Type
)
4961 Parent_Base
:= Base_Type
(Full_View
(Parent_Type
));
4963 Parent_Base
:= Base_Type
(Parent_Type
);
4966 -- Before we start the previously documented transformations, here is
4967 -- a little fix for size and alignment of tagged types. Normally when
4968 -- we derive type D from type P, we copy the size and alignment of P
4969 -- as the default for D, and in the absence of explicit representation
4970 -- clauses for D, the size and alignment are indeed the same as the
4973 -- But this is wrong for tagged types, since fields may be added,
4974 -- and the default size may need to be larger, and the default
4975 -- alignment may need to be larger.
4977 -- We therefore reset the size and alignment fields in the tagged
4978 -- case. Note that the size and alignment will in any case be at
4979 -- least as large as the parent type (since the derived type has
4980 -- a copy of the parent type in the _parent field)
4983 Init_Size_Align
(Derived_Type
);
4986 -- STEP 0a: figure out what kind of derived type declaration we have
4988 if Private_Extension
then
4990 Set_Ekind
(Derived_Type
, E_Record_Type_With_Private
);
4993 Type_Def
:= Type_Definition
(N
);
4995 -- Ekind (Parent_Base) in not necessarily E_Record_Type since
4996 -- Parent_Base can be a private type or private extension. However,
4997 -- for tagged types with an extension the newly added fields are
4998 -- visible and hence the Derived_Type is always an E_Record_Type.
4999 -- (except that the parent may have its own private fields).
5000 -- For untagged types we preserve the Ekind of the Parent_Base.
5002 if Present
(Record_Extension_Part
(Type_Def
)) then
5003 Set_Ekind
(Derived_Type
, E_Record_Type
);
5005 Set_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
5009 -- Indic can either be an N_Identifier if the subtype indication
5010 -- contains no constraint or an N_Subtype_Indication if the subtype
5011 -- indication has a constraint.
5013 Indic
:= Subtype_Indication
(Type_Def
);
5014 Constraint_Present
:= (Nkind
(Indic
) = N_Subtype_Indication
);
5016 -- Check that the type has visible discriminants. The type may be
5017 -- a private type with unknown discriminants whose full view has
5018 -- discriminants which are invisible.
5020 if Constraint_Present
then
5021 if not Has_Discriminants
(Parent_Base
)
5023 (Has_Unknown_Discriminants
(Parent_Base
)
5024 and then Is_Private_Type
(Parent_Base
))
5027 ("invalid constraint: type has no discriminant",
5028 Constraint
(Indic
));
5030 Constraint_Present
:= False;
5031 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
5033 elsif Is_Constrained
(Parent_Type
) then
5035 ("invalid constraint: parent type is already constrained",
5036 Constraint
(Indic
));
5038 Constraint_Present
:= False;
5039 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
5043 -- STEP 0b: If needed, apply transformation given in point 5. above
5045 if not Private_Extension
5046 and then Has_Discriminants
(Parent_Type
)
5047 and then not Discriminant_Specs
5048 and then (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
5050 -- First, we must analyze the constraint (see comment in point 5.)
5052 if Constraint_Present
then
5053 New_Discrs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
5055 if Has_Discriminants
(Derived_Type
)
5056 and then Has_Private_Declaration
(Derived_Type
)
5057 and then Present
(Discriminant_Constraint
(Derived_Type
))
5059 -- Verify that constraints of the full view conform to those
5060 -- given in partial view.
5066 C1
:= First_Elmt
(New_Discrs
);
5067 C2
:= First_Elmt
(Discriminant_Constraint
(Derived_Type
));
5069 while Present
(C1
) and then Present
(C2
) loop
5071 Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
5074 "constraint not conformant to previous declaration",
5084 -- Insert and analyze the declaration for the unconstrained base type
5086 New_Base
:= Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
5089 Make_Full_Type_Declaration
(Loc
,
5090 Defining_Identifier
=> New_Base
,
5092 Make_Derived_Type_Definition
(Loc
,
5093 Abstract_Present
=> Abstract_Present
(Type_Def
),
5094 Subtype_Indication
=>
5095 New_Occurrence_Of
(Parent_Base
, Loc
),
5096 Record_Extension_Part
=>
5097 Relocate_Node
(Record_Extension_Part
(Type_Def
))));
5099 Set_Parent
(New_Decl
, Parent
(N
));
5100 Mark_Rewrite_Insertion
(New_Decl
);
5101 Insert_Before
(N
, New_Decl
);
5103 -- Note that this call passes False for the Derive_Subps parameter
5104 -- because subprogram derivation is deferred until after creating
5105 -- the subtype (see below).
5108 (New_Decl
, Parent_Base
, New_Base
,
5109 Is_Completion
=> True, Derive_Subps
=> False);
5111 -- ??? This needs re-examination to determine whether the
5112 -- above call can simply be replaced by a call to Analyze.
5114 Set_Analyzed
(New_Decl
);
5116 -- Insert and analyze the declaration for the constrained subtype
5118 if Constraint_Present
then
5120 Make_Subtype_Indication
(Loc
,
5121 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
5122 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
5126 Constr_List
: constant List_Id
:= New_List
;
5131 C
:= First_Elmt
(Discriminant_Constraint
(Parent_Type
));
5132 while Present
(C
) loop
5135 -- It is safe here to call New_Copy_Tree since
5136 -- Force_Evaluation was called on each constraint in
5137 -- Build_Discriminant_Constraints.
5139 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
5145 Make_Subtype_Indication
(Loc
,
5146 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
5148 Make_Index_Or_Discriminant_Constraint
(Loc
, Constr_List
));
5153 Make_Subtype_Declaration
(Loc
,
5154 Defining_Identifier
=> Derived_Type
,
5155 Subtype_Indication
=> New_Indic
));
5159 -- Derivation of subprograms must be delayed until the full subtype
5160 -- has been established to ensure proper overriding of subprograms
5161 -- inherited by full types. If the derivations occurred as part of
5162 -- the call to Build_Derived_Type above, then the check for type
5163 -- conformance would fail because earlier primitive subprograms
5164 -- could still refer to the full type prior the change to the new
5165 -- subtype and hence would not match the new base type created here.
5167 Derive_Subprograms
(Parent_Type
, Derived_Type
);
5169 -- For tagged types the Discriminant_Constraint of the new base itype
5170 -- is inherited from the first subtype so that no subtype conformance
5171 -- problem arise when the first subtype overrides primitive
5172 -- operations inherited by the implicit base type.
5175 Set_Discriminant_Constraint
5176 (New_Base
, Discriminant_Constraint
(Derived_Type
));
5182 -- If we get here Derived_Type will have no discriminants or it will be
5183 -- a discriminated unconstrained base type.
5185 -- STEP 1a: perform preliminary actions/checks for derived tagged types
5189 -- The parent type is frozen for non-private extensions (RM 13.14(7))
5191 if not Private_Extension
then
5192 Freeze_Before
(N
, Parent_Type
);
5195 if Type_Access_Level
(Derived_Type
) /= Type_Access_Level
(Parent_Type
)
5196 and then not Is_Generic_Type
(Derived_Type
)
5198 if Is_Controlled
(Parent_Type
) then
5200 ("controlled type must be declared at the library level",
5204 ("type extension at deeper accessibility level than parent",
5210 GB
: constant Node_Id
:= Enclosing_Generic_Body
(Derived_Type
);
5214 and then GB
/= Enclosing_Generic_Body
(Parent_Base
)
5217 ("parent type of& must not be outside generic body"
5218 & " ('R'M 3.9.1(4))",
5219 Indic
, Derived_Type
);
5225 -- STEP 1b : preliminary cleanup of the full view of private types
5227 -- If the type is already marked as having discriminants, then it's the
5228 -- completion of a private type or private extension and we need to
5229 -- retain the discriminants from the partial view if the current
5230 -- declaration has Discriminant_Specifications so that we can verify
5231 -- conformance. However, we must remove any existing components that
5232 -- were inherited from the parent (and attached in Copy_And_Swap)
5233 -- because the full type inherits all appropriate components anyway, and
5234 -- we do not want the partial view's components interfering.
5236 if Has_Discriminants
(Derived_Type
) and then Discriminant_Specs
then
5237 Discrim
:= First_Discriminant
(Derived_Type
);
5239 Last_Discrim
:= Discrim
;
5240 Next_Discriminant
(Discrim
);
5241 exit when No
(Discrim
);
5244 Set_Last_Entity
(Derived_Type
, Last_Discrim
);
5246 -- In all other cases wipe out the list of inherited components (even
5247 -- inherited discriminants), it will be properly rebuilt here.
5250 Set_First_Entity
(Derived_Type
, Empty
);
5251 Set_Last_Entity
(Derived_Type
, Empty
);
5254 -- STEP 1c: Initialize some flags for the Derived_Type
5256 -- The following flags must be initialized here so that
5257 -- Process_Discriminants can check that discriminants of tagged types
5258 -- do not have a default initial value and that access discriminants
5259 -- are only specified for limited records. For completeness, these
5260 -- flags are also initialized along with all the other flags below.
5262 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged
);
5263 Set_Is_Limited_Record
(Derived_Type
, Is_Limited_Record
(Parent_Type
));
5265 -- STEP 2a: process discriminants of derived type if any
5267 New_Scope
(Derived_Type
);
5269 if Discriminant_Specs
then
5270 Set_Has_Unknown_Discriminants
(Derived_Type
, False);
5272 -- The following call initializes fields Has_Discriminants and
5273 -- Discriminant_Constraint, unless we are processing the completion
5274 -- of a private type declaration.
5276 Check_Or_Process_Discriminants
(N
, Derived_Type
);
5278 -- For non-tagged types the constraint on the Parent_Type must be
5279 -- present and is used to rename the discriminants.
5281 if not Is_Tagged
and then not Has_Discriminants
(Parent_Type
) then
5282 Error_Msg_N
("untagged parent must have discriminants", Indic
);
5284 elsif not Is_Tagged
and then not Constraint_Present
then
5286 ("discriminant constraint needed for derived untagged records",
5289 -- Otherwise the parent subtype must be constrained unless we have a
5290 -- private extension.
5292 elsif not Constraint_Present
5293 and then not Private_Extension
5294 and then not Is_Constrained
(Parent_Type
)
5297 ("unconstrained type not allowed in this context", Indic
);
5299 elsif Constraint_Present
then
5300 -- The following call sets the field Corresponding_Discriminant
5301 -- for the discriminants in the Derived_Type.
5303 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
, True);
5305 -- For untagged types all new discriminants must rename
5306 -- discriminants in the parent. For private extensions new
5307 -- discriminants cannot rename old ones (implied by [7.3(13)]).
5309 Discrim
:= First_Discriminant
(Derived_Type
);
5310 while Present
(Discrim
) loop
5312 and then not Present
(Corresponding_Discriminant
(Discrim
))
5315 ("new discriminants must constrain old ones", Discrim
);
5317 elsif Private_Extension
5318 and then Present
(Corresponding_Discriminant
(Discrim
))
5321 ("only static constraints allowed for parent"
5322 & " discriminants in the partial view", Indic
);
5326 -- If a new discriminant is used in the constraint, then its
5327 -- subtype must be statically compatible with the parent
5328 -- discriminant's subtype (3.7(15)).
5330 if Present
(Corresponding_Discriminant
(Discrim
))
5332 not Subtypes_Statically_Compatible
5334 Etype
(Corresponding_Discriminant
(Discrim
)))
5337 ("subtype must be compatible with parent discriminant",
5341 Next_Discriminant
(Discrim
);
5344 -- Check whether the constraints of the full view statically
5345 -- match those imposed by the parent subtype [7.3(13)].
5347 if Present
(Stored_Constraint
(Derived_Type
)) then
5352 C1
:= First_Elmt
(Discs
);
5353 C2
:= First_Elmt
(Stored_Constraint
(Derived_Type
));
5354 while Present
(C1
) and then Present
(C2
) loop
5356 Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
5359 "not conformant with previous declaration",
5370 -- STEP 2b: No new discriminants, inherit discriminants if any
5373 if Private_Extension
then
5374 Set_Has_Unknown_Discriminants
5376 Has_Unknown_Discriminants
(Parent_Type
)
5377 or else Unknown_Discriminants_Present
(N
));
5379 -- The partial view of the parent may have unknown discriminants,
5380 -- but if the full view has discriminants and the parent type is
5381 -- in scope they must be inherited.
5383 elsif Has_Unknown_Discriminants
(Parent_Type
)
5385 (not Has_Discriminants
(Parent_Type
)
5386 or else not In_Open_Scopes
(Scope
(Parent_Type
)))
5388 Set_Has_Unknown_Discriminants
(Derived_Type
);
5391 if not Has_Unknown_Discriminants
(Derived_Type
)
5392 and then not Has_Unknown_Discriminants
(Parent_Base
)
5393 and then Has_Discriminants
(Parent_Type
)
5395 Inherit_Discrims
:= True;
5396 Set_Has_Discriminants
5397 (Derived_Type
, True);
5398 Set_Discriminant_Constraint
5399 (Derived_Type
, Discriminant_Constraint
(Parent_Base
));
5402 -- The following test is true for private types (remember
5403 -- transformation 5. is not applied to those) and in an error
5406 if Constraint_Present
then
5407 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
5410 -- For now mark a new derived type as constrained only if it has no
5411 -- discriminants. At the end of Build_Derived_Record_Type we properly
5412 -- set this flag in the case of private extensions. See comments in
5413 -- point 9. just before body of Build_Derived_Record_Type.
5417 not (Inherit_Discrims
5418 or else Has_Unknown_Discriminants
(Derived_Type
)));
5421 -- STEP 3: initialize fields of derived type
5423 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged
);
5424 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
5426 -- Fields inherited from the Parent_Type
5429 (Derived_Type
, Einfo
.Discard_Names
(Parent_Type
));
5430 Set_Has_Specified_Layout
5431 (Derived_Type
, Has_Specified_Layout
(Parent_Type
));
5432 Set_Is_Limited_Composite
5433 (Derived_Type
, Is_Limited_Composite
(Parent_Type
));
5434 Set_Is_Limited_Record
5435 (Derived_Type
, Is_Limited_Record
(Parent_Type
));
5436 Set_Is_Private_Composite
5437 (Derived_Type
, Is_Private_Composite
(Parent_Type
));
5439 -- Fields inherited from the Parent_Base
5441 Set_Has_Controlled_Component
5442 (Derived_Type
, Has_Controlled_Component
(Parent_Base
));
5443 Set_Has_Non_Standard_Rep
5444 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
5445 Set_Has_Primitive_Operations
5446 (Derived_Type
, Has_Primitive_Operations
(Parent_Base
));
5448 -- Direct controlled types do not inherit Finalize_Storage_Only flag
5450 if not Is_Controlled
(Parent_Type
) then
5451 Set_Finalize_Storage_Only
5452 (Derived_Type
, Finalize_Storage_Only
(Parent_Type
));
5455 -- Set fields for private derived types
5457 if Is_Private_Type
(Derived_Type
) then
5458 Set_Depends_On_Private
(Derived_Type
, True);
5459 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
5461 -- Inherit fields from non private record types. If this is the
5462 -- completion of a derivation from a private type, the parent itself
5463 -- is private, and the attributes come from its full view, which must
5467 if Is_Private_Type
(Parent_Base
)
5468 and then not Is_Record_Type
(Parent_Base
)
5470 Set_Component_Alignment
5471 (Derived_Type
, Component_Alignment
(Full_View
(Parent_Base
)));
5473 (Derived_Type
, C_Pass_By_Copy
(Full_View
(Parent_Base
)));
5475 Set_Component_Alignment
5476 (Derived_Type
, Component_Alignment
(Parent_Base
));
5479 (Derived_Type
, C_Pass_By_Copy
(Parent_Base
));
5483 -- Set fields for tagged types
5486 Set_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
5488 -- All tagged types defined in Ada.Finalization are controlled
5490 if Chars
(Scope
(Derived_Type
)) = Name_Finalization
5491 and then Chars
(Scope
(Scope
(Derived_Type
))) = Name_Ada
5492 and then Scope
(Scope
(Scope
(Derived_Type
))) = Standard_Standard
5494 Set_Is_Controlled
(Derived_Type
);
5496 Set_Is_Controlled
(Derived_Type
, Is_Controlled
(Parent_Base
));
5499 Make_Class_Wide_Type
(Derived_Type
);
5500 Set_Is_Abstract
(Derived_Type
, Abstract_Present
(Type_Def
));
5502 if Has_Discriminants
(Derived_Type
)
5503 and then Constraint_Present
5505 Set_Stored_Constraint
5506 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Base
, Discs
));
5510 Set_Is_Packed
(Derived_Type
, Is_Packed
(Parent_Base
));
5511 Set_Has_Non_Standard_Rep
5512 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
5515 -- STEP 4: Inherit components from the parent base and constrain them.
5516 -- Apply the second transformation described in point 6. above.
5518 if (not Is_Empty_Elmt_List
(Discs
) or else Inherit_Discrims
)
5519 or else not Has_Discriminants
(Parent_Type
)
5520 or else not Is_Constrained
(Parent_Type
)
5524 Constrs
:= Discriminant_Constraint
(Parent_Type
);
5527 Assoc_List
:= Inherit_Components
(N
,
5528 Parent_Base
, Derived_Type
, Is_Tagged
, Inherit_Discrims
, Constrs
);
5530 -- STEP 5a: Copy the parent record declaration for untagged types
5532 if not Is_Tagged
then
5534 -- Discriminant_Constraint (Derived_Type) has been properly
5535 -- constructed. Save it and temporarily set it to Empty because we
5536 -- do not want the call to New_Copy_Tree below to mess this list.
5538 if Has_Discriminants
(Derived_Type
) then
5539 Save_Discr_Constr
:= Discriminant_Constraint
(Derived_Type
);
5540 Set_Discriminant_Constraint
(Derived_Type
, No_Elist
);
5542 Save_Discr_Constr
:= No_Elist
;
5545 -- Save the Etype field of Derived_Type. It is correctly set now,
5546 -- but the call to New_Copy tree may remap it to point to itself,
5547 -- which is not what we want. Ditto for the Next_Entity field.
5549 Save_Etype
:= Etype
(Derived_Type
);
5550 Save_Next_Entity
:= Next_Entity
(Derived_Type
);
5552 -- Assoc_List maps all stored discriminants in the Parent_Base to
5553 -- stored discriminants in the Derived_Type. It is fundamental that
5554 -- no types or itypes with discriminants other than the stored
5555 -- discriminants appear in the entities declared inside
5556 -- Derived_Type, since the back end cannot deal with it.
5560 (Parent
(Parent_Base
), Map
=> Assoc_List
, New_Sloc
=> Loc
);
5562 -- Restore the fields saved prior to the New_Copy_Tree call
5563 -- and compute the stored constraint.
5565 Set_Etype
(Derived_Type
, Save_Etype
);
5566 Set_Next_Entity
(Derived_Type
, Save_Next_Entity
);
5568 if Has_Discriminants
(Derived_Type
) then
5569 Set_Discriminant_Constraint
5570 (Derived_Type
, Save_Discr_Constr
);
5571 Set_Stored_Constraint
5572 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Type
, Discs
));
5573 Replace_Components
(Derived_Type
, New_Decl
);
5576 -- Insert the new derived type declaration
5578 Rewrite
(N
, New_Decl
);
5580 -- STEP 5b: Complete the processing for record extensions in generics
5582 -- There is no completion for record extensions declared in the
5583 -- parameter part of a generic, so we need to complete processing for
5584 -- these generic record extensions here. The Record_Type_Definition call
5585 -- will change the Ekind of the components from E_Void to E_Component.
5587 elsif Private_Extension
and then Is_Generic_Type
(Derived_Type
) then
5588 Record_Type_Definition
(Empty
, Derived_Type
);
5590 -- STEP 5c: Process the record extension for non private tagged types
5592 elsif not Private_Extension
then
5594 -- Add the _parent field in the derived type
5596 Expand_Record_Extension
(Derived_Type
, Type_Def
);
5598 -- Analyze the record extension
5600 Record_Type_Definition
5601 (Record_Extension_Part
(Type_Def
), Derived_Type
);
5606 if Etype
(Derived_Type
) = Any_Type
then
5610 -- Set delayed freeze and then derive subprograms, we need to do
5611 -- this in this order so that derived subprograms inherit the
5612 -- derived freeze if necessary.
5614 Set_Has_Delayed_Freeze
(Derived_Type
);
5615 if Derive_Subps
then
5616 Derive_Subprograms
(Parent_Type
, Derived_Type
);
5619 -- If we have a private extension which defines a constrained derived
5620 -- type mark as constrained here after we have derived subprograms. See
5621 -- comment on point 9. just above the body of Build_Derived_Record_Type.
5623 if Private_Extension
and then Inherit_Discrims
then
5624 if Constraint_Present
and then not Is_Empty_Elmt_List
(Discs
) then
5625 Set_Is_Constrained
(Derived_Type
, True);
5626 Set_Discriminant_Constraint
(Derived_Type
, Discs
);
5628 elsif Is_Constrained
(Parent_Type
) then
5630 (Derived_Type
, True);
5631 Set_Discriminant_Constraint
5632 (Derived_Type
, Discriminant_Constraint
(Parent_Type
));
5636 -- Update the class_wide type, which shares the now-completed
5637 -- entity list with its specific type.
5641 (Class_Wide_Type
(Derived_Type
), First_Entity
(Derived_Type
));
5643 (Class_Wide_Type
(Derived_Type
), Last_Entity
(Derived_Type
));
5646 end Build_Derived_Record_Type
;
5648 ------------------------
5649 -- Build_Derived_Type --
5650 ------------------------
5652 procedure Build_Derived_Type
5654 Parent_Type
: Entity_Id
;
5655 Derived_Type
: Entity_Id
;
5656 Is_Completion
: Boolean;
5657 Derive_Subps
: Boolean := True)
5659 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
5662 -- Set common attributes
5664 Set_Scope
(Derived_Type
, Current_Scope
);
5666 Set_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
5667 Set_Etype
(Derived_Type
, Parent_Base
);
5668 Set_Has_Task
(Derived_Type
, Has_Task
(Parent_Base
));
5670 Set_Size_Info
(Derived_Type
, Parent_Type
);
5671 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
5672 Set_Convention
(Derived_Type
, Convention
(Parent_Type
));
5673 Set_Is_Controlled
(Derived_Type
, Is_Controlled
(Parent_Type
));
5675 -- The derived type inherits the representation clauses of the parent.
5676 -- However, for a private type that is completed by a derivation, there
5677 -- may be operation attributes that have been specified already (stream
5678 -- attributes and External_Tag) and those must be provided. Finally,
5679 -- if the partial view is a private extension, the representation items
5680 -- of the parent have been inherited already, and should not be chained
5681 -- twice to the derived type.
5683 if Is_Tagged_Type
(Parent_Type
)
5684 and then Present
(First_Rep_Item
(Derived_Type
))
5686 -- The existing items are either operational items or items inherited
5687 -- from a private extension declaration.
5690 Rep
: Node_Id
:= First_Rep_Item
(Derived_Type
);
5691 Found
: Boolean := False;
5694 while Present
(Rep
) loop
5695 if Rep
= First_Rep_Item
(Parent_Type
) then
5699 Rep
:= Next_Rep_Item
(Rep
);
5705 (First_Rep_Item
(Derived_Type
), First_Rep_Item
(Parent_Type
));
5710 Set_First_Rep_Item
(Derived_Type
, First_Rep_Item
(Parent_Type
));
5713 case Ekind
(Parent_Type
) is
5714 when Numeric_Kind
=>
5715 Build_Derived_Numeric_Type
(N
, Parent_Type
, Derived_Type
);
5718 Build_Derived_Array_Type
(N
, Parent_Type
, Derived_Type
);
5722 | Class_Wide_Kind
=>
5723 Build_Derived_Record_Type
5724 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
5727 when Enumeration_Kind
=>
5728 Build_Derived_Enumeration_Type
(N
, Parent_Type
, Derived_Type
);
5731 Build_Derived_Access_Type
(N
, Parent_Type
, Derived_Type
);
5733 when Incomplete_Or_Private_Kind
=>
5734 Build_Derived_Private_Type
5735 (N
, Parent_Type
, Derived_Type
, Is_Completion
, Derive_Subps
);
5737 -- For discriminated types, the derivation includes deriving
5738 -- primitive operations. For others it is done below.
5740 if Is_Tagged_Type
(Parent_Type
)
5741 or else Has_Discriminants
(Parent_Type
)
5742 or else (Present
(Full_View
(Parent_Type
))
5743 and then Has_Discriminants
(Full_View
(Parent_Type
)))
5748 when Concurrent_Kind
=>
5749 Build_Derived_Concurrent_Type
(N
, Parent_Type
, Derived_Type
);
5752 raise Program_Error
;
5755 if Etype
(Derived_Type
) = Any_Type
then
5759 -- Set delayed freeze and then derive subprograms, we need to do this
5760 -- in this order so that derived subprograms inherit the derived freeze
5763 Set_Has_Delayed_Freeze
(Derived_Type
);
5764 if Derive_Subps
then
5765 Derive_Subprograms
(Parent_Type
, Derived_Type
);
5768 Set_Has_Primitive_Operations
5769 (Base_Type
(Derived_Type
), Has_Primitive_Operations
(Parent_Type
));
5770 end Build_Derived_Type
;
5772 -----------------------
5773 -- Build_Discriminal --
5774 -----------------------
5776 procedure Build_Discriminal
(Discrim
: Entity_Id
) is
5777 D_Minal
: Entity_Id
;
5778 CR_Disc
: Entity_Id
;
5781 -- A discriminal has the same name as the discriminant
5784 Make_Defining_Identifier
(Sloc
(Discrim
),
5785 Chars
=> Chars
(Discrim
));
5787 Set_Ekind
(D_Minal
, E_In_Parameter
);
5788 Set_Mechanism
(D_Minal
, Default_Mechanism
);
5789 Set_Etype
(D_Minal
, Etype
(Discrim
));
5791 Set_Discriminal
(Discrim
, D_Minal
);
5792 Set_Discriminal_Link
(D_Minal
, Discrim
);
5794 -- For task types, build at once the discriminants of the corresponding
5795 -- record, which are needed if discriminants are used in entry defaults
5796 -- and in family bounds.
5798 if Is_Concurrent_Type
(Current_Scope
)
5799 or else Is_Limited_Type
(Current_Scope
)
5801 CR_Disc
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
5803 Set_Ekind
(CR_Disc
, E_In_Parameter
);
5804 Set_Mechanism
(CR_Disc
, Default_Mechanism
);
5805 Set_Etype
(CR_Disc
, Etype
(Discrim
));
5806 Set_CR_Discriminant
(Discrim
, CR_Disc
);
5808 end Build_Discriminal
;
5810 ------------------------------------
5811 -- Build_Discriminant_Constraints --
5812 ------------------------------------
5814 function Build_Discriminant_Constraints
5817 Derived_Def
: Boolean := False) return Elist_Id
5819 C
: constant Node_Id
:= Constraint
(Def
);
5820 Nb_Discr
: constant Nat
:= Number_Discriminants
(T
);
5822 Discr_Expr
: array (1 .. Nb_Discr
) of Node_Id
:= (others => Empty
);
5823 -- Saves the expression corresponding to a given discriminant in T
5825 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
;
5826 -- Return the Position number within array Discr_Expr of a discriminant
5827 -- D within the discriminant list of the discriminated type T.
5833 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
is
5837 Disc
:= First_Discriminant
(T
);
5838 for J
in Discr_Expr
'Range loop
5843 Next_Discriminant
(Disc
);
5846 -- Note: Since this function is called on discriminants that are
5847 -- known to belong to the discriminated type, falling through the
5848 -- loop with no match signals an internal compiler error.
5850 raise Program_Error
;
5853 -- Declarations local to Build_Discriminant_Constraints
5857 Elist
: constant Elist_Id
:= New_Elmt_List
;
5865 Discrim_Present
: Boolean := False;
5867 -- Start of processing for Build_Discriminant_Constraints
5870 -- The following loop will process positional associations only.
5871 -- For a positional association, the (single) discriminant is
5872 -- implicitly specified by position, in textual order (RM 3.7.2).
5874 Discr
:= First_Discriminant
(T
);
5875 Constr
:= First
(Constraints
(C
));
5877 for D
in Discr_Expr
'Range loop
5878 exit when Nkind
(Constr
) = N_Discriminant_Association
;
5881 Error_Msg_N
("too few discriminants given in constraint", C
);
5882 return New_Elmt_List
;
5884 elsif Nkind
(Constr
) = N_Range
5885 or else (Nkind
(Constr
) = N_Attribute_Reference
5887 Attribute_Name
(Constr
) = Name_Range
)
5890 ("a range is not a valid discriminant constraint", Constr
);
5891 Discr_Expr
(D
) := Error
;
5894 Analyze_And_Resolve
(Constr
, Base_Type
(Etype
(Discr
)));
5895 Discr_Expr
(D
) := Constr
;
5898 Next_Discriminant
(Discr
);
5902 if No
(Discr
) and then Present
(Constr
) then
5903 Error_Msg_N
("too many discriminants given in constraint", Constr
);
5904 return New_Elmt_List
;
5907 -- Named associations can be given in any order, but if both positional
5908 -- and named associations are used in the same discriminant constraint,
5909 -- then positional associations must occur first, at their normal
5910 -- position. Hence once a named association is used, the rest of the
5911 -- discriminant constraint must use only named associations.
5913 while Present
(Constr
) loop
5915 -- Positional association forbidden after a named association
5917 if Nkind
(Constr
) /= N_Discriminant_Association
then
5918 Error_Msg_N
("positional association follows named one", Constr
);
5919 return New_Elmt_List
;
5921 -- Otherwise it is a named association
5924 -- E records the type of the discriminants in the named
5925 -- association. All the discriminants specified in the same name
5926 -- association must have the same type.
5930 -- Search the list of discriminants in T to see if the simple name
5931 -- given in the constraint matches any of them.
5933 Id
:= First
(Selector_Names
(Constr
));
5934 while Present
(Id
) loop
5937 -- If Original_Discriminant is present, we are processing a
5938 -- generic instantiation and this is an instance node. We need
5939 -- to find the name of the corresponding discriminant in the
5940 -- actual record type T and not the name of the discriminant in
5941 -- the generic formal. Example:
5944 -- type G (D : int) is private;
5946 -- subtype W is G (D => 1);
5948 -- type Rec (X : int) is record ... end record;
5949 -- package Q is new P (G => Rec);
5951 -- At the point of the instantiation, formal type G is Rec
5952 -- and therefore when reanalyzing "subtype W is G (D => 1);"
5953 -- which really looks like "subtype W is Rec (D => 1);" at
5954 -- the point of instantiation, we want to find the discriminant
5955 -- that corresponds to D in Rec, ie X.
5957 if Present
(Original_Discriminant
(Id
)) then
5958 Discr
:= Find_Corresponding_Discriminant
(Id
, T
);
5962 Discr
:= First_Discriminant
(T
);
5963 while Present
(Discr
) loop
5964 if Chars
(Discr
) = Chars
(Id
) then
5969 Next_Discriminant
(Discr
);
5973 Error_Msg_N
("& does not match any discriminant", Id
);
5974 return New_Elmt_List
;
5976 -- The following is only useful for the benefit of generic
5977 -- instances but it does not interfere with other
5978 -- processing for the non-generic case so we do it in all
5979 -- cases (for generics this statement is executed when
5980 -- processing the generic definition, see comment at the
5981 -- beginning of this if statement).
5984 Set_Original_Discriminant
(Id
, Discr
);
5988 Position
:= Pos_Of_Discr
(T
, Discr
);
5990 if Present
(Discr_Expr
(Position
)) then
5991 Error_Msg_N
("duplicate constraint for discriminant&", Id
);
5994 -- Each discriminant specified in the same named association
5995 -- must be associated with a separate copy of the
5996 -- corresponding expression.
5998 if Present
(Next
(Id
)) then
5999 Expr
:= New_Copy_Tree
(Expression
(Constr
));
6000 Set_Parent
(Expr
, Parent
(Expression
(Constr
)));
6002 Expr
:= Expression
(Constr
);
6005 Discr_Expr
(Position
) := Expr
;
6006 Analyze_And_Resolve
(Expr
, Base_Type
(Etype
(Discr
)));
6009 -- A discriminant association with more than one discriminant
6010 -- name is only allowed if the named discriminants are all of
6011 -- the same type (RM 3.7.1(8)).
6014 E
:= Base_Type
(Etype
(Discr
));
6016 elsif Base_Type
(Etype
(Discr
)) /= E
then
6018 ("all discriminants in an association " &
6019 "must have the same type", Id
);
6029 -- A discriminant constraint must provide exactly one value for each
6030 -- discriminant of the type (RM 3.7.1(8)).
6032 for J
in Discr_Expr
'Range loop
6033 if No
(Discr_Expr
(J
)) then
6034 Error_Msg_N
("too few discriminants given in constraint", C
);
6035 return New_Elmt_List
;
6039 -- Determine if there are discriminant expressions in the constraint
6041 for J
in Discr_Expr
'Range loop
6042 if Denotes_Discriminant
(Discr_Expr
(J
), Check_Protected
=> True) then
6043 Discrim_Present
:= True;
6047 -- Build an element list consisting of the expressions given in the
6048 -- discriminant constraint and apply the appropriate checks. The list
6049 -- is constructed after resolving any named discriminant associations
6050 -- and therefore the expressions appear in the textual order of the
6053 Discr
:= First_Discriminant
(T
);
6054 for J
in Discr_Expr
'Range loop
6055 if Discr_Expr
(J
) /= Error
then
6057 Append_Elmt
(Discr_Expr
(J
), Elist
);
6059 -- If any of the discriminant constraints is given by a
6060 -- discriminant and we are in a derived type declaration we
6061 -- have a discriminant renaming. Establish link between new
6062 -- and old discriminant.
6064 if Denotes_Discriminant
(Discr_Expr
(J
)) then
6066 Set_Corresponding_Discriminant
6067 (Entity
(Discr_Expr
(J
)), Discr
);
6070 -- Force the evaluation of non-discriminant expressions.
6071 -- If we have found a discriminant in the constraint 3.4(26)
6072 -- and 3.8(18) demand that no range checks are performed are
6073 -- after evaluation. If the constraint is for a component
6074 -- definition that has a per-object constraint, expressions are
6075 -- evaluated but not checked either. In all other cases perform
6079 if Discrim_Present
then
6082 elsif Nkind
(Parent
(Parent
(Def
))) = N_Component_Declaration
6084 Has_Per_Object_Constraint
6085 (Defining_Identifier
(Parent
(Parent
(Def
))))
6089 elsif Is_Access_Type
(Etype
(Discr
)) then
6090 Apply_Constraint_Check
(Discr_Expr
(J
), Etype
(Discr
));
6093 Apply_Range_Check
(Discr_Expr
(J
), Etype
(Discr
));
6096 Force_Evaluation
(Discr_Expr
(J
));
6099 -- Check that the designated type of an access discriminant's
6100 -- expression is not a class-wide type unless the discriminant's
6101 -- designated type is also class-wide.
6103 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
6104 and then not Is_Class_Wide_Type
6105 (Designated_Type
(Etype
(Discr
)))
6106 and then Etype
(Discr_Expr
(J
)) /= Any_Type
6107 and then Is_Class_Wide_Type
6108 (Designated_Type
(Etype
(Discr_Expr
(J
))))
6110 Wrong_Type
(Discr_Expr
(J
), Etype
(Discr
));
6114 Next_Discriminant
(Discr
);
6118 end Build_Discriminant_Constraints
;
6120 ---------------------------------
6121 -- Build_Discriminated_Subtype --
6122 ---------------------------------
6124 procedure Build_Discriminated_Subtype
6128 Related_Nod
: Node_Id
;
6129 For_Access
: Boolean := False)
6131 Has_Discrs
: constant Boolean := Has_Discriminants
(T
);
6132 Constrained
: constant Boolean
6134 and then not Is_Empty_Elmt_List
(Elist
)
6135 and then not Is_Class_Wide_Type
(T
))
6136 or else Is_Constrained
(T
);
6139 if Ekind
(T
) = E_Record_Type
then
6141 Set_Ekind
(Def_Id
, E_Private_Subtype
);
6142 Set_Is_For_Access_Subtype
(Def_Id
, True);
6144 Set_Ekind
(Def_Id
, E_Record_Subtype
);
6147 elsif Ekind
(T
) = E_Task_Type
then
6148 Set_Ekind
(Def_Id
, E_Task_Subtype
);
6150 elsif Ekind
(T
) = E_Protected_Type
then
6151 Set_Ekind
(Def_Id
, E_Protected_Subtype
);
6153 elsif Is_Private_Type
(T
) then
6154 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
6156 elsif Is_Class_Wide_Type
(T
) then
6157 Set_Ekind
(Def_Id
, E_Class_Wide_Subtype
);
6160 -- Incomplete type. attach subtype to list of dependents, to be
6161 -- completed with full view of parent type, unless is it the
6162 -- designated subtype of a record component within an init_proc.
6163 -- This last case arises for a component of an access type whose
6164 -- designated type is incomplete (e.g. a Taft Amendment type).
6165 -- The designated subtype is within an inner scope, and needs no
6166 -- elaboration, because only the access type is needed in the
6167 -- initialization procedure.
6169 Set_Ekind
(Def_Id
, Ekind
(T
));
6171 if For_Access
and then Within_Init_Proc
then
6174 Append_Elmt
(Def_Id
, Private_Dependents
(T
));
6178 Set_Etype
(Def_Id
, T
);
6179 Init_Size_Align
(Def_Id
);
6180 Set_Has_Discriminants
(Def_Id
, Has_Discrs
);
6181 Set_Is_Constrained
(Def_Id
, Constrained
);
6183 Set_First_Entity
(Def_Id
, First_Entity
(T
));
6184 Set_Last_Entity
(Def_Id
, Last_Entity
(T
));
6185 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
6187 if Is_Tagged_Type
(T
) then
6188 Set_Is_Tagged_Type
(Def_Id
);
6189 Make_Class_Wide_Type
(Def_Id
);
6192 Set_Stored_Constraint
(Def_Id
, No_Elist
);
6195 Set_Discriminant_Constraint
(Def_Id
, Elist
);
6196 Set_Stored_Constraint_From_Discriminant_Constraint
(Def_Id
);
6199 if Is_Tagged_Type
(T
) then
6200 Set_Primitive_Operations
(Def_Id
, Primitive_Operations
(T
));
6201 Set_Is_Abstract
(Def_Id
, Is_Abstract
(T
));
6204 -- Subtypes introduced by component declarations do not need to be
6205 -- marked as delayed, and do not get freeze nodes, because the semantics
6206 -- verifies that the parents of the subtypes are frozen before the
6207 -- enclosing record is frozen.
6209 if not Is_Type
(Scope
(Def_Id
)) then
6210 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
6212 if Is_Private_Type
(T
)
6213 and then Present
(Full_View
(T
))
6215 Conditional_Delay
(Def_Id
, Full_View
(T
));
6217 Conditional_Delay
(Def_Id
, T
);
6221 if Is_Record_Type
(T
) then
6222 Set_Is_Limited_Record
(Def_Id
, Is_Limited_Record
(T
));
6225 and then not Is_Empty_Elmt_List
(Elist
)
6226 and then not For_Access
6228 Create_Constrained_Components
(Def_Id
, Related_Nod
, T
, Elist
);
6229 elsif not For_Access
then
6230 Set_Cloned_Subtype
(Def_Id
, T
);
6234 end Build_Discriminated_Subtype
;
6236 ------------------------
6237 -- Build_Scalar_Bound --
6238 ------------------------
6240 function Build_Scalar_Bound
6243 Der_T
: Entity_Id
) return Node_Id
6245 New_Bound
: Entity_Id
;
6248 -- Note: not clear why this is needed, how can the original bound
6249 -- be unanalyzed at this point? and if it is, what business do we
6250 -- have messing around with it? and why is the base type of the
6251 -- parent type the right type for the resolution. It probably is
6252 -- not! It is OK for the new bound we are creating, but not for
6253 -- the old one??? Still if it never happens, no problem!
6255 Analyze_And_Resolve
(Bound
, Base_Type
(Par_T
));
6257 if Nkind
(Bound
) = N_Integer_Literal
6258 or else Nkind
(Bound
) = N_Real_Literal
6260 New_Bound
:= New_Copy
(Bound
);
6261 Set_Etype
(New_Bound
, Der_T
);
6262 Set_Analyzed
(New_Bound
);
6264 elsif Is_Entity_Name
(Bound
) then
6265 New_Bound
:= OK_Convert_To
(Der_T
, New_Copy
(Bound
));
6267 -- The following is almost certainly wrong. What business do we have
6268 -- relocating a node (Bound) that is presumably still attached to
6269 -- the tree elsewhere???
6272 New_Bound
:= OK_Convert_To
(Der_T
, Relocate_Node
(Bound
));
6275 Set_Etype
(New_Bound
, Der_T
);
6277 end Build_Scalar_Bound
;
6279 --------------------------------
6280 -- Build_Underlying_Full_View --
6281 --------------------------------
6283 procedure Build_Underlying_Full_View
6288 Loc
: constant Source_Ptr
:= Sloc
(N
);
6289 Subt
: constant Entity_Id
:=
6290 Make_Defining_Identifier
6291 (Loc
, New_External_Name
(Chars
(Typ
), 'S'));
6298 procedure Set_Discriminant_Name
(Id
: Node_Id
);
6299 -- If the derived type has discriminants, they may rename discriminants
6300 -- of the parent. When building the full view of the parent, we need to
6301 -- recover the names of the original discriminants if the constraint is
6302 -- given by named associations.
6304 ---------------------------
6305 -- Set_Discriminant_Name --
6306 ---------------------------
6308 procedure Set_Discriminant_Name
(Id
: Node_Id
) is
6312 Set_Original_Discriminant
(Id
, Empty
);
6314 if Has_Discriminants
(Typ
) then
6315 Disc
:= First_Discriminant
(Typ
);
6317 while Present
(Disc
) loop
6318 if Chars
(Disc
) = Chars
(Id
)
6319 and then Present
(Corresponding_Discriminant
(Disc
))
6321 Set_Chars
(Id
, Chars
(Corresponding_Discriminant
(Disc
)));
6323 Next_Discriminant
(Disc
);
6326 end Set_Discriminant_Name
;
6328 -- Start of processing for Build_Underlying_Full_View
6331 if Nkind
(N
) = N_Full_Type_Declaration
then
6332 Constr
:= Constraint
(Subtype_Indication
(Type_Definition
(N
)));
6334 elsif Nkind
(N
) = N_Subtype_Declaration
then
6335 Constr
:= New_Copy_Tree
(Constraint
(Subtype_Indication
(N
)));
6337 elsif Nkind
(N
) = N_Component_Declaration
then
6340 (Constraint
(Subtype_Indication
(Component_Definition
(N
))));
6343 raise Program_Error
;
6346 C
:= First
(Constraints
(Constr
));
6347 while Present
(C
) loop
6348 if Nkind
(C
) = N_Discriminant_Association
then
6349 Id
:= First
(Selector_Names
(C
));
6350 while Present
(Id
) loop
6351 Set_Discriminant_Name
(Id
);
6360 Make_Subtype_Declaration
(Loc
,
6361 Defining_Identifier
=> Subt
,
6362 Subtype_Indication
=>
6363 Make_Subtype_Indication
(Loc
,
6364 Subtype_Mark
=> New_Reference_To
(Par
, Loc
),
6365 Constraint
=> New_Copy_Tree
(Constr
)));
6367 -- If this is a component subtype for an outer itype, it is not
6368 -- a list member, so simply set the parent link for analysis: if
6369 -- the enclosing type does not need to be in a declarative list,
6370 -- neither do the components.
6372 if Is_List_Member
(N
)
6373 and then Nkind
(N
) /= N_Component_Declaration
6375 Insert_Before
(N
, Indic
);
6377 Set_Parent
(Indic
, Parent
(N
));
6381 Set_Underlying_Full_View
(Typ
, Full_View
(Subt
));
6382 end Build_Underlying_Full_View
;
6384 -------------------------------
6385 -- Check_Abstract_Overriding --
6386 -------------------------------
6388 procedure Check_Abstract_Overriding
(T
: Entity_Id
) is
6395 Op_List
:= Primitive_Operations
(T
);
6397 -- Loop to check primitive operations
6399 Elmt
:= First_Elmt
(Op_List
);
6400 while Present
(Elmt
) loop
6401 Subp
:= Node
(Elmt
);
6403 -- Special exception, do not complain about failure to override the
6404 -- stream routines _Input and _Output, since we always provide
6405 -- automatic overridings for these subprograms.
6407 if Is_Abstract
(Subp
)
6408 and then not Is_TSS
(Subp
, TSS_Stream_Input
)
6409 and then not Is_TSS
(Subp
, TSS_Stream_Output
)
6410 and then not Is_Abstract
(T
)
6412 if Present
(Alias
(Subp
)) then
6413 -- Only perform the check for a derived subprogram when
6414 -- the type has an explicit record extension. This avoids
6415 -- incorrectly flagging abstract subprograms for the case
6416 -- of a type without an extension derived from a formal type
6417 -- with a tagged actual (can occur within a private part).
6419 Type_Def
:= Type_Definition
(Parent
(T
));
6420 if Nkind
(Type_Def
) = N_Derived_Type_Definition
6421 and then Present
(Record_Extension_Part
(Type_Def
))
6424 ("type must be declared abstract or & overridden",
6429 ("abstract subprogram not allowed for type&",
6432 ("nonabstract type has abstract subprogram&",
6439 end Check_Abstract_Overriding
;
6441 ------------------------------------------------
6442 -- Check_Access_Discriminant_Requires_Limited --
6443 ------------------------------------------------
6445 procedure Check_Access_Discriminant_Requires_Limited
6450 -- A discriminant_specification for an access discriminant
6451 -- shall appear only in the declaration for a task or protected
6452 -- type, or for a type with the reserved word 'limited' in
6453 -- its definition or in one of its ancestors. (RM 3.7(10))
6455 if Nkind
(Discriminant_Type
(D
)) = N_Access_Definition
6456 and then not Is_Concurrent_Type
(Current_Scope
)
6457 and then not Is_Concurrent_Record_Type
(Current_Scope
)
6458 and then not Is_Limited_Record
(Current_Scope
)
6459 and then Ekind
(Current_Scope
) /= E_Limited_Private_Type
6462 ("access discriminants allowed only for limited types", Loc
);
6464 end Check_Access_Discriminant_Requires_Limited
;
6466 -----------------------------------
6467 -- Check_Aliased_Component_Types --
6468 -----------------------------------
6470 procedure Check_Aliased_Component_Types
(T
: Entity_Id
) is
6474 -- ??? Also need to check components of record extensions, but not
6475 -- components of protected types (which are always limited).
6477 if not Is_Limited_Type
(T
) then
6478 if Ekind
(T
) = E_Record_Type
then
6479 C
:= First_Component
(T
);
6480 while Present
(C
) loop
6482 and then Has_Discriminants
(Etype
(C
))
6483 and then not Is_Constrained
(Etype
(C
))
6484 and then not In_Instance
6487 ("aliased component must be constrained ('R'M 3.6(11))",
6494 elsif Ekind
(T
) = E_Array_Type
then
6495 if Has_Aliased_Components
(T
)
6496 and then Has_Discriminants
(Component_Type
(T
))
6497 and then not Is_Constrained
(Component_Type
(T
))
6498 and then not In_Instance
6501 ("aliased component type must be constrained ('R'M 3.6(11))",
6506 end Check_Aliased_Component_Types
;
6508 ----------------------
6509 -- Check_Completion --
6510 ----------------------
6512 procedure Check_Completion
(Body_Id
: Node_Id
:= Empty
) is
6515 procedure Post_Error
;
6516 -- Post error message for lack of completion for entity E
6522 procedure Post_Error
is
6524 if not Comes_From_Source
(E
) then
6526 if Ekind
(E
) = E_Task_Type
6527 or else Ekind
(E
) = E_Protected_Type
6529 -- It may be an anonymous protected type created for a
6530 -- single variable. Post error on variable, if present.
6536 Var
:= First_Entity
(Current_Scope
);
6538 while Present
(Var
) loop
6539 exit when Etype
(Var
) = E
6540 and then Comes_From_Source
(Var
);
6545 if Present
(Var
) then
6552 -- If a generated entity has no completion, then either previous
6553 -- semantic errors have disabled the expansion phase, or else we had
6554 -- missing subunits, or else we are compiling without expan- sion,
6555 -- or else something is very wrong.
6557 if not Comes_From_Source
(E
) then
6559 (Serious_Errors_Detected
> 0
6560 or else Configurable_Run_Time_Violations
> 0
6561 or else Subunits_Missing
6562 or else not Expander_Active
);
6565 -- Here for source entity
6568 -- Here if no body to post the error message, so we post the error
6569 -- on the declaration that has no completion. This is not really
6570 -- the right place to post it, think about this later ???
6572 if No
(Body_Id
) then
6575 ("missing full declaration for }", Parent
(E
), E
);
6578 ("missing body for &", Parent
(E
), E
);
6581 -- Package body has no completion for a declaration that appears
6582 -- in the corresponding spec. Post error on the body, with a
6583 -- reference to the non-completed declaration.
6586 Error_Msg_Sloc
:= Sloc
(E
);
6590 ("missing full declaration for }!", Body_Id
, E
);
6592 elsif Is_Overloadable
(E
)
6593 and then Current_Entity_In_Scope
(E
) /= E
6595 -- It may be that the completion is mistyped and appears
6596 -- as a distinct overloading of the entity.
6599 Candidate
: constant Entity_Id
:=
6600 Current_Entity_In_Scope
(E
);
6601 Decl
: constant Node_Id
:=
6602 Unit_Declaration_Node
(Candidate
);
6605 if Is_Overloadable
(Candidate
)
6606 and then Ekind
(Candidate
) = Ekind
(E
)
6607 and then Nkind
(Decl
) = N_Subprogram_Body
6608 and then Acts_As_Spec
(Decl
)
6610 Check_Type_Conformant
(Candidate
, E
);
6613 Error_Msg_NE
("missing body for & declared#!",
6618 Error_Msg_NE
("missing body for & declared#!",
6625 -- Start processing for Check_Completion
6628 E
:= First_Entity
(Current_Scope
);
6629 while Present
(E
) loop
6630 if Is_Intrinsic_Subprogram
(E
) then
6633 -- The following situation requires special handling: a child
6634 -- unit that appears in the context clause of the body of its
6637 -- procedure Parent.Child (...);
6639 -- with Parent.Child;
6640 -- package body Parent is
6642 -- Here Parent.Child appears as a local entity, but should not
6643 -- be flagged as requiring completion, because it is a
6644 -- compilation unit.
6646 elsif Ekind
(E
) = E_Function
6647 or else Ekind
(E
) = E_Procedure
6648 or else Ekind
(E
) = E_Generic_Function
6649 or else Ekind
(E
) = E_Generic_Procedure
6651 if not Has_Completion
(E
)
6652 and then not Is_Abstract
(E
)
6653 and then Nkind
(Parent
(Unit_Declaration_Node
(E
))) /=
6655 and then Chars
(E
) /= Name_uSize
6660 elsif Is_Entry
(E
) then
6661 if not Has_Completion
(E
) and then
6662 (Ekind
(Scope
(E
)) = E_Protected_Object
6663 or else Ekind
(Scope
(E
)) = E_Protected_Type
)
6668 elsif Is_Package
(E
) then
6669 if Unit_Requires_Body
(E
) then
6670 if not Has_Completion
(E
)
6671 and then Nkind
(Parent
(Unit_Declaration_Node
(E
))) /=
6677 elsif not Is_Child_Unit
(E
) then
6678 May_Need_Implicit_Body
(E
);
6681 elsif Ekind
(E
) = E_Incomplete_Type
6682 and then No
(Underlying_Type
(E
))
6686 elsif (Ekind
(E
) = E_Task_Type
or else
6687 Ekind
(E
) = E_Protected_Type
)
6688 and then not Has_Completion
(E
)
6692 -- A single task declared in the current scope is a constant, verify
6693 -- that the body of its anonymous type is in the same scope. If the
6694 -- task is defined elsewhere, this may be a renaming declaration for
6695 -- which no completion is needed.
6697 elsif Ekind
(E
) = E_Constant
6698 and then Ekind
(Etype
(E
)) = E_Task_Type
6699 and then not Has_Completion
(Etype
(E
))
6700 and then Scope
(Etype
(E
)) = Current_Scope
6704 elsif Ekind
(E
) = E_Protected_Object
6705 and then not Has_Completion
(Etype
(E
))
6709 elsif Ekind
(E
) = E_Record_Type
then
6710 if Is_Tagged_Type
(E
) then
6711 Check_Abstract_Overriding
(E
);
6714 Check_Aliased_Component_Types
(E
);
6716 elsif Ekind
(E
) = E_Array_Type
then
6717 Check_Aliased_Component_Types
(E
);
6723 end Check_Completion
;
6725 ----------------------------
6726 -- Check_Delta_Expression --
6727 ----------------------------
6729 procedure Check_Delta_Expression
(E
: Node_Id
) is
6731 if not (Is_Real_Type
(Etype
(E
))) then
6732 Wrong_Type
(E
, Any_Real
);
6734 elsif not Is_OK_Static_Expression
(E
) then
6735 Flag_Non_Static_Expr
6736 ("non-static expression used for delta value!", E
);
6738 elsif not UR_Is_Positive
(Expr_Value_R
(E
)) then
6739 Error_Msg_N
("delta expression must be positive", E
);
6745 -- If any of above errors occurred, then replace the incorrect
6746 -- expression by the real 0.1, which should prevent further errors.
6749 Make_Real_Literal
(Sloc
(E
), Ureal_Tenth
));
6750 Analyze_And_Resolve
(E
, Standard_Float
);
6751 end Check_Delta_Expression
;
6753 -----------------------------
6754 -- Check_Digits_Expression --
6755 -----------------------------
6757 procedure Check_Digits_Expression
(E
: Node_Id
) is
6759 if not (Is_Integer_Type
(Etype
(E
))) then
6760 Wrong_Type
(E
, Any_Integer
);
6762 elsif not Is_OK_Static_Expression
(E
) then
6763 Flag_Non_Static_Expr
6764 ("non-static expression used for digits value!", E
);
6766 elsif Expr_Value
(E
) <= 0 then
6767 Error_Msg_N
("digits value must be greater than zero", E
);
6773 -- If any of above errors occurred, then replace the incorrect
6774 -- expression by the integer 1, which should prevent further errors.
6776 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), 1));
6777 Analyze_And_Resolve
(E
, Standard_Integer
);
6779 end Check_Digits_Expression
;
6781 --------------------------
6782 -- Check_Initialization --
6783 --------------------------
6785 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
) is
6787 if (Is_Limited_Type
(T
)
6788 or else Is_Limited_Composite
(T
))
6789 and then not In_Instance
6790 and then not In_Inlined_Body
6792 -- Ada 2005 (AI-287): Relax the strictness of the front-end in
6793 -- case of limited aggregates and extension aggregates.
6795 if Ada_Version
>= Ada_05
6796 and then (Nkind
(Exp
) = N_Aggregate
6797 or else Nkind
(Exp
) = N_Extension_Aggregate
)
6802 ("cannot initialize entities of limited type", Exp
);
6803 Explain_Limited_Type
(T
, Exp
);
6806 end Check_Initialization
;
6808 ------------------------------------
6809 -- Check_Or_Process_Discriminants --
6810 ------------------------------------
6812 -- If an incomplete or private type declaration was already given for
6813 -- the type, the discriminants may have already been processed if they
6814 -- were present on the incomplete declaration. In this case a full
6815 -- conformance check is performed otherwise just process them.
6817 procedure Check_Or_Process_Discriminants
6820 Prev
: Entity_Id
:= Empty
)
6823 if Has_Discriminants
(T
) then
6825 -- Make the discriminants visible to component declarations
6828 D
: Entity_Id
:= First_Discriminant
(T
);
6832 while Present
(D
) loop
6833 Prev
:= Current_Entity
(D
);
6834 Set_Current_Entity
(D
);
6835 Set_Is_Immediately_Visible
(D
);
6836 Set_Homonym
(D
, Prev
);
6838 -- Ada 2005 (AI-230): Access discriminant allowed in
6839 -- non-limited record types.
6841 if Ada_Version
< Ada_05
then
6843 -- This restriction gets applied to the full type here; it
6844 -- has already been applied earlier to the partial view
6846 Check_Access_Discriminant_Requires_Limited
(Parent
(D
), N
);
6849 Next_Discriminant
(D
);
6853 elsif Present
(Discriminant_Specifications
(N
)) then
6854 Process_Discriminants
(N
, Prev
);
6856 end Check_Or_Process_Discriminants
;
6858 ----------------------
6859 -- Check_Real_Bound --
6860 ----------------------
6862 procedure Check_Real_Bound
(Bound
: Node_Id
) is
6864 if not Is_Real_Type
(Etype
(Bound
)) then
6866 ("bound in real type definition must be of real type", Bound
);
6868 elsif not Is_OK_Static_Expression
(Bound
) then
6869 Flag_Non_Static_Expr
6870 ("non-static expression used for real type bound!", Bound
);
6877 (Bound
, Make_Real_Literal
(Sloc
(Bound
), Ureal_0
));
6879 Resolve
(Bound
, Standard_Float
);
6880 end Check_Real_Bound
;
6882 ------------------------------
6883 -- Complete_Private_Subtype --
6884 ------------------------------
6886 procedure Complete_Private_Subtype
6889 Full_Base
: Entity_Id
;
6890 Related_Nod
: Node_Id
)
6892 Save_Next_Entity
: Entity_Id
;
6893 Save_Homonym
: Entity_Id
;
6896 -- Set semantic attributes for (implicit) private subtype completion.
6897 -- If the full type has no discriminants, then it is a copy of the full
6898 -- view of the base. Otherwise, it is a subtype of the base with a
6899 -- possible discriminant constraint. Save and restore the original
6900 -- Next_Entity field of full to ensure that the calls to Copy_Node
6901 -- do not corrupt the entity chain.
6903 -- Note that the type of the full view is the same entity as the
6904 -- type of the partial view. In this fashion, the subtype has
6905 -- access to the correct view of the parent.
6907 Save_Next_Entity
:= Next_Entity
(Full
);
6908 Save_Homonym
:= Homonym
(Priv
);
6910 case Ekind
(Full_Base
) is
6911 when E_Record_Type |
6917 Copy_Node
(Priv
, Full
);
6919 Set_Has_Discriminants
(Full
, Has_Discriminants
(Full_Base
));
6920 Set_First_Entity
(Full
, First_Entity
(Full_Base
));
6921 Set_Last_Entity
(Full
, Last_Entity
(Full_Base
));
6924 Copy_Node
(Full_Base
, Full
);
6925 Set_Chars
(Full
, Chars
(Priv
));
6926 Conditional_Delay
(Full
, Priv
);
6927 Set_Sloc
(Full
, Sloc
(Priv
));
6930 Set_Next_Entity
(Full
, Save_Next_Entity
);
6931 Set_Homonym
(Full
, Save_Homonym
);
6932 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
6934 -- Set common attributes for all subtypes
6936 Set_Ekind
(Full
, Subtype_Kind
(Ekind
(Full_Base
)));
6938 -- The Etype of the full view is inconsistent. Gigi needs to see the
6939 -- structural full view, which is what the current scheme gives:
6940 -- the Etype of the full view is the etype of the full base. However,
6941 -- if the full base is a derived type, the full view then looks like
6942 -- a subtype of the parent, not a subtype of the full base. If instead
6945 -- Set_Etype (Full, Full_Base);
6947 -- then we get inconsistencies in the front-end (confusion between
6948 -- views). Several outstanding bugs are related to this ???
6950 Set_Is_First_Subtype
(Full
, False);
6951 Set_Scope
(Full
, Scope
(Priv
));
6952 Set_Size_Info
(Full
, Full_Base
);
6953 Set_RM_Size
(Full
, RM_Size
(Full_Base
));
6954 Set_Is_Itype
(Full
);
6956 -- A subtype of a private-type-without-discriminants, whose full-view
6957 -- has discriminants with default expressions, is not constrained!
6959 if not Has_Discriminants
(Priv
) then
6960 Set_Is_Constrained
(Full
, Is_Constrained
(Full_Base
));
6962 if Has_Discriminants
(Full_Base
) then
6963 Set_Discriminant_Constraint
6964 (Full
, Discriminant_Constraint
(Full_Base
));
6966 -- The partial view may have been indefinite, the full view
6969 Set_Has_Unknown_Discriminants
6970 (Full
, Has_Unknown_Discriminants
(Full_Base
));
6974 Set_First_Rep_Item
(Full
, First_Rep_Item
(Full_Base
));
6975 Set_Depends_On_Private
(Full
, Has_Private_Component
(Full
));
6977 -- Freeze the private subtype entity if its parent is delayed, and not
6978 -- already frozen. We skip this processing if the type is an anonymous
6979 -- subtype of a record component, or is the corresponding record of a
6980 -- protected type, since ???
6982 if not Is_Type
(Scope
(Full
)) then
6983 Set_Has_Delayed_Freeze
(Full
,
6984 Has_Delayed_Freeze
(Full_Base
)
6985 and then (not Is_Frozen
(Full_Base
)));
6988 Set_Freeze_Node
(Full
, Empty
);
6989 Set_Is_Frozen
(Full
, False);
6990 Set_Full_View
(Priv
, Full
);
6992 if Has_Discriminants
(Full
) then
6993 Set_Stored_Constraint_From_Discriminant_Constraint
(Full
);
6994 Set_Stored_Constraint
(Priv
, Stored_Constraint
(Full
));
6996 if Has_Unknown_Discriminants
(Full
) then
6997 Set_Discriminant_Constraint
(Full
, No_Elist
);
7001 if Ekind
(Full_Base
) = E_Record_Type
7002 and then Has_Discriminants
(Full_Base
)
7003 and then Has_Discriminants
(Priv
) -- might not, if errors
7004 and then not Has_Unknown_Discriminants
(Priv
)
7005 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(Priv
))
7007 Create_Constrained_Components
7008 (Full
, Related_Nod
, Full_Base
, Discriminant_Constraint
(Priv
));
7010 -- If the full base is itself derived from private, build a congruent
7011 -- subtype of its underlying type, for use by the back end. For a
7012 -- constrained record component, the declaration cannot be placed on
7013 -- the component list, but it must neverthess be built an analyzed, to
7014 -- supply enough information for gigi to compute the size of component.
7016 elsif Ekind
(Full_Base
) in Private_Kind
7017 and then Is_Derived_Type
(Full_Base
)
7018 and then Has_Discriminants
(Full_Base
)
7019 and then (Ekind
(Current_Scope
) /= E_Record_Subtype
)
7021 if not Is_Itype
(Priv
)
7023 Nkind
(Subtype_Indication
(Parent
(Priv
))) = N_Subtype_Indication
7025 Build_Underlying_Full_View
7026 (Parent
(Priv
), Full
, Etype
(Full_Base
));
7028 elsif Nkind
(Related_Nod
) = N_Component_Declaration
then
7029 Build_Underlying_Full_View
(Related_Nod
, Full
, Etype
(Full_Base
));
7032 elsif Is_Record_Type
(Full_Base
) then
7034 -- Show Full is simply a renaming of Full_Base
7036 Set_Cloned_Subtype
(Full
, Full_Base
);
7039 -- It is unsafe to share to bounds of a scalar type, because the Itype
7040 -- is elaborated on demand, and if a bound is non-static then different
7041 -- orders of elaboration in different units will lead to different
7042 -- external symbols.
7044 if Is_Scalar_Type
(Full_Base
) then
7045 Set_Scalar_Range
(Full
,
7046 Make_Range
(Sloc
(Related_Nod
),
7048 Duplicate_Subexpr_No_Checks
(Type_Low_Bound
(Full_Base
)),
7050 Duplicate_Subexpr_No_Checks
(Type_High_Bound
(Full_Base
))));
7052 -- This completion inherits the bounds of the full parent, but if
7053 -- the parent is an unconstrained floating point type, so is the
7056 if Is_Floating_Point_Type
(Full_Base
) then
7057 Set_Includes_Infinities
7058 (Scalar_Range
(Full
), Has_Infinities
(Full_Base
));
7062 -- ??? It seems that a lot of fields are missing that should be copied
7063 -- from Full_Base to Full. Here are some that are introduced in a
7064 -- non-disruptive way but a cleanup is necessary.
7066 if Is_Tagged_Type
(Full_Base
) then
7067 Set_Is_Tagged_Type
(Full
);
7068 Set_Primitive_Operations
(Full
, Primitive_Operations
(Full_Base
));
7069 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Full_Base
));
7071 -- If this is a subtype of a protected or task type, constrain its
7072 -- corresponding record, unless this is a subtype without constraints,
7073 -- i.e. a simple renaming as with an actual subtype in an instance.
7075 elsif Is_Concurrent_Type
(Full_Base
) then
7076 if Has_Discriminants
(Full
)
7077 and then Present
(Corresponding_Record_Type
(Full_Base
))
7079 not Is_Empty_Elmt_List
(Discriminant_Constraint
(Full
))
7081 Set_Corresponding_Record_Type
(Full
,
7082 Constrain_Corresponding_Record
7083 (Full
, Corresponding_Record_Type
(Full_Base
),
7084 Related_Nod
, Full_Base
));
7087 Set_Corresponding_Record_Type
(Full
,
7088 Corresponding_Record_Type
(Full_Base
));
7091 end Complete_Private_Subtype
;
7093 ----------------------------
7094 -- Constant_Redeclaration --
7095 ----------------------------
7097 procedure Constant_Redeclaration
7102 Prev
: constant Entity_Id
:= Current_Entity_In_Scope
(Id
);
7103 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
7106 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
);
7107 -- If deferred constant is an access type initialized with an
7108 -- allocator, check whether there is an illegal recursion in the
7109 -- definition, through a default value of some record subcomponent.
7110 -- This is normally detected when generating init procs, but requires
7111 -- this additional mechanism when expansion is disabled.
7113 ---------------------------------
7114 -- Check_Recursive_Declaration --
7115 ---------------------------------
7117 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
) is
7121 if Is_Record_Type
(Typ
) then
7122 Comp
:= First_Component
(Typ
);
7123 while Present
(Comp
) loop
7124 if Comes_From_Source
(Comp
) then
7125 if Present
(Expression
(Parent
(Comp
)))
7126 and then Is_Entity_Name
(Expression
(Parent
(Comp
)))
7127 and then Entity
(Expression
(Parent
(Comp
))) = Prev
7129 Error_Msg_Sloc
:= Sloc
(Parent
(Comp
));
7131 ("illegal circularity with declaration for&#",
7135 elsif Is_Record_Type
(Etype
(Comp
)) then
7136 Check_Recursive_Declaration
(Etype
(Comp
));
7140 Next_Component
(Comp
);
7143 end Check_Recursive_Declaration
;
7145 -- Start of processing for Constant_Redeclaration
7148 if Nkind
(Parent
(Prev
)) = N_Object_Declaration
then
7149 if Nkind
(Object_Definition
7150 (Parent
(Prev
))) = N_Subtype_Indication
7152 -- Find type of new declaration. The constraints of the two
7153 -- views must match statically, but there is no point in
7154 -- creating an itype for the full view.
7156 if Nkind
(Obj_Def
) = N_Subtype_Indication
then
7157 Find_Type
(Subtype_Mark
(Obj_Def
));
7158 New_T
:= Entity
(Subtype_Mark
(Obj_Def
));
7161 Find_Type
(Obj_Def
);
7162 New_T
:= Entity
(Obj_Def
);
7168 -- The full view may impose a constraint, even if the partial
7169 -- view does not, so construct the subtype.
7171 New_T
:= Find_Type_Of_Object
(Obj_Def
, N
);
7176 -- Current declaration is illegal, diagnosed below in Enter_Name
7182 -- If previous full declaration exists, or if a homograph is present,
7183 -- let Enter_Name handle it, either with an error, or with the removal
7184 -- of an overridden implicit subprogram.
7186 if Ekind
(Prev
) /= E_Constant
7187 or else Present
(Expression
(Parent
(Prev
)))
7188 or else Present
(Full_View
(Prev
))
7192 -- Verify that types of both declarations match
7194 elsif Base_Type
(Etype
(Prev
)) /= Base_Type
(New_T
) then
7195 Error_Msg_Sloc
:= Sloc
(Prev
);
7196 Error_Msg_N
("type does not match declaration#", N
);
7197 Set_Full_View
(Prev
, Id
);
7198 Set_Etype
(Id
, Any_Type
);
7200 -- If so, process the full constant declaration
7203 Set_Full_View
(Prev
, Id
);
7204 Set_Is_Public
(Id
, Is_Public
(Prev
));
7205 Set_Is_Internal
(Id
);
7206 Append_Entity
(Id
, Current_Scope
);
7208 -- Check ALIASED present if present before (RM 7.4(7))
7210 if Is_Aliased
(Prev
)
7211 and then not Aliased_Present
(N
)
7213 Error_Msg_Sloc
:= Sloc
(Prev
);
7214 Error_Msg_N
("ALIASED required (see declaration#)", N
);
7217 -- Check that placement is in private part and that the incomplete
7218 -- declaration appeared in the visible part.
7220 if Ekind
(Current_Scope
) = E_Package
7221 and then not In_Private_Part
(Current_Scope
)
7223 Error_Msg_Sloc
:= Sloc
(Prev
);
7224 Error_Msg_N
("full constant for declaration#"
7225 & " must be in private part", N
);
7227 elsif Ekind
(Current_Scope
) = E_Package
7228 and then List_Containing
(Parent
(Prev
))
7229 /= Visible_Declarations
7230 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
7233 ("deferred constant must be declared in visible part",
7237 if Is_Access_Type
(T
)
7238 and then Nkind
(Expression
(N
)) = N_Allocator
7240 Check_Recursive_Declaration
(Designated_Type
(T
));
7243 end Constant_Redeclaration
;
7245 ----------------------
7246 -- Constrain_Access --
7247 ----------------------
7249 procedure Constrain_Access
7250 (Def_Id
: in out Entity_Id
;
7252 Related_Nod
: Node_Id
)
7254 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
7255 Desig_Type
: constant Entity_Id
:= Designated_Type
(T
);
7256 Desig_Subtype
: Entity_Id
:= Create_Itype
(E_Void
, Related_Nod
);
7257 Constraint_OK
: Boolean := True;
7260 if Is_Array_Type
(Desig_Type
) then
7261 Constrain_Array
(Desig_Subtype
, S
, Related_Nod
, Def_Id
, 'P');
7263 elsif (Is_Record_Type
(Desig_Type
)
7264 or else Is_Incomplete_Or_Private_Type
(Desig_Type
))
7265 and then not Is_Constrained
(Desig_Type
)
7267 -- ??? The following code is a temporary kludge to ignore a
7268 -- discriminant constraint on access type if it is constraining
7269 -- the current record. Avoid creating the implicit subtype of the
7270 -- record we are currently compiling since right now, we cannot
7271 -- handle these. For now, just return the access type itself.
7273 if Desig_Type
= Current_Scope
7274 and then No
(Def_Id
)
7276 Set_Ekind
(Desig_Subtype
, E_Record_Subtype
);
7277 Def_Id
:= Entity
(Subtype_Mark
(S
));
7279 -- This call added to ensure that the constraint is analyzed
7280 -- (needed for a B test). Note that we still return early from
7281 -- this procedure to avoid recursive processing. ???
7283 Constrain_Discriminated_Type
7284 (Desig_Subtype
, S
, Related_Nod
, For_Access
=> True);
7288 if Ekind
(T
) = E_General_Access_Type
7289 and then Has_Private_Declaration
(Desig_Type
)
7290 and then In_Open_Scopes
(Scope
(Desig_Type
))
7292 -- Enforce rule that the constraint is illegal if there is
7293 -- an unconstrained view of the designated type. This means
7294 -- that the partial view (either a private type declaration or
7295 -- a derivation from a private type) has no discriminants.
7296 -- (Defect Report 8652/0008, Technical Corrigendum 1, checked
7297 -- by ACATS B371001).
7300 Pack
: constant Node_Id
:=
7301 Unit_Declaration_Node
(Scope
(Desig_Type
));
7306 if Nkind
(Pack
) = N_Package_Declaration
then
7307 Decls
:= Visible_Declarations
(Specification
(Pack
));
7308 Decl
:= First
(Decls
);
7309 while Present
(Decl
) loop
7310 if (Nkind
(Decl
) = N_Private_Type_Declaration
7312 Chars
(Defining_Identifier
(Decl
)) =
7316 (Nkind
(Decl
) = N_Full_Type_Declaration
7318 Chars
(Defining_Identifier
(Decl
)) =
7320 and then Is_Derived_Type
(Desig_Type
)
7322 Has_Private_Declaration
(Etype
(Desig_Type
)))
7324 if No
(Discriminant_Specifications
(Decl
)) then
7326 ("cannot constrain general access type " &
7327 "if designated type has unconstrained view", S
);
7339 Constrain_Discriminated_Type
(Desig_Subtype
, S
, Related_Nod
,
7340 For_Access
=> True);
7342 elsif (Is_Task_Type
(Desig_Type
)
7343 or else Is_Protected_Type
(Desig_Type
))
7344 and then not Is_Constrained
(Desig_Type
)
7346 Constrain_Concurrent
7347 (Desig_Subtype
, S
, Related_Nod
, Desig_Type
, ' ');
7350 Error_Msg_N
("invalid constraint on access type", S
);
7351 Desig_Subtype
:= Desig_Type
; -- Ignore invalid constraint.
7352 Constraint_OK
:= False;
7356 Def_Id
:= Create_Itype
(E_Access_Subtype
, Related_Nod
);
7358 Set_Ekind
(Def_Id
, E_Access_Subtype
);
7361 if Constraint_OK
then
7362 Set_Etype
(Def_Id
, Base_Type
(T
));
7364 if Is_Private_Type
(Desig_Type
) then
7365 Prepare_Private_Subtype_Completion
(Desig_Subtype
, Related_Nod
);
7368 Set_Etype
(Def_Id
, Any_Type
);
7371 Set_Size_Info
(Def_Id
, T
);
7372 Set_Is_Constrained
(Def_Id
, Constraint_OK
);
7373 Set_Directly_Designated_Type
(Def_Id
, Desig_Subtype
);
7374 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
7375 Set_Is_Access_Constant
(Def_Id
, Is_Access_Constant
(T
));
7377 Conditional_Delay
(Def_Id
, T
);
7378 end Constrain_Access
;
7380 ---------------------
7381 -- Constrain_Array --
7382 ---------------------
7384 procedure Constrain_Array
7385 (Def_Id
: in out Entity_Id
;
7387 Related_Nod
: Node_Id
;
7388 Related_Id
: Entity_Id
;
7391 C
: constant Node_Id
:= Constraint
(SI
);
7392 Number_Of_Constraints
: Nat
:= 0;
7395 Constraint_OK
: Boolean := True;
7398 T
:= Entity
(Subtype_Mark
(SI
));
7400 if Ekind
(T
) in Access_Kind
then
7401 T
:= Designated_Type
(T
);
7404 -- If an index constraint follows a subtype mark in a subtype indication
7405 -- then the type or subtype denoted by the subtype mark must not already
7406 -- impose an index constraint. The subtype mark must denote either an
7407 -- unconstrained array type or an access type whose designated type
7408 -- is such an array type... (RM 3.6.1)
7410 if Is_Constrained
(T
) then
7412 ("array type is already constrained", Subtype_Mark
(SI
));
7413 Constraint_OK
:= False;
7416 S
:= First
(Constraints
(C
));
7418 while Present
(S
) loop
7419 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
7423 -- In either case, the index constraint must provide a discrete
7424 -- range for each index of the array type and the type of each
7425 -- discrete range must be the same as that of the corresponding
7426 -- index. (RM 3.6.1)
7428 if Number_Of_Constraints
/= Number_Dimensions
(T
) then
7429 Error_Msg_NE
("incorrect number of index constraints for }", C
, T
);
7430 Constraint_OK
:= False;
7433 S
:= First
(Constraints
(C
));
7434 Index
:= First_Index
(T
);
7437 -- Apply constraints to each index type
7439 for J
in 1 .. Number_Of_Constraints
loop
7440 Constrain_Index
(Index
, S
, Related_Nod
, Related_Id
, Suffix
, J
);
7450 Create_Itype
(E_Array_Subtype
, Related_Nod
, Related_Id
, Suffix
);
7451 Set_Parent
(Def_Id
, Related_Nod
);
7454 Set_Ekind
(Def_Id
, E_Array_Subtype
);
7457 Set_Size_Info
(Def_Id
, (T
));
7458 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
7459 Set_Etype
(Def_Id
, Base_Type
(T
));
7461 if Constraint_OK
then
7462 Set_First_Index
(Def_Id
, First
(Constraints
(C
)));
7465 Set_Is_Constrained
(Def_Id
, True);
7466 Set_Is_Aliased
(Def_Id
, Is_Aliased
(T
));
7467 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
7469 Set_Is_Private_Composite
(Def_Id
, Is_Private_Composite
(T
));
7470 Set_Is_Limited_Composite
(Def_Id
, Is_Limited_Composite
(T
));
7472 -- Build a freeze node if parent still needs one. Also, make sure
7473 -- that the Depends_On_Private status is set (explanation ???)
7474 -- and also that a conditional delay is set.
7476 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
7477 Conditional_Delay
(Def_Id
, T
);
7479 end Constrain_Array
;
7481 ------------------------------
7482 -- Constrain_Component_Type --
7483 ------------------------------
7485 function Constrain_Component_Type
7486 (Compon_Type
: Entity_Id
;
7487 Constrained_Typ
: Entity_Id
;
7488 Related_Node
: Node_Id
;
7490 Constraints
: Elist_Id
) return Entity_Id
7492 Loc
: constant Source_Ptr
:= Sloc
(Constrained_Typ
);
7494 function Build_Constrained_Array_Type
7495 (Old_Type
: Entity_Id
) return Entity_Id
;
7496 -- If Old_Type is an array type, one of whose indices is constrained
7497 -- by a discriminant, build an Itype whose constraint replaces the
7498 -- discriminant with its value in the constraint.
7500 function Build_Constrained_Discriminated_Type
7501 (Old_Type
: Entity_Id
) return Entity_Id
;
7502 -- Ditto for record components
7504 function Build_Constrained_Access_Type
7505 (Old_Type
: Entity_Id
) return Entity_Id
;
7506 -- Ditto for access types. Makes use of previous two functions, to
7507 -- constrain designated type.
7509 function Build_Subtype
(T
: Entity_Id
; C
: List_Id
) return Entity_Id
;
7510 -- T is an array or discriminated type, C is a list of constraints
7511 -- that apply to T. This routine builds the constrained subtype.
7513 function Is_Discriminant
(Expr
: Node_Id
) return Boolean;
7514 -- Returns True if Expr is a discriminant
7516 function Get_Discr_Value
(Discrim
: Entity_Id
) return Node_Id
;
7517 -- Find the value of discriminant Discrim in Constraint
7519 -----------------------------------
7520 -- Build_Constrained_Access_Type --
7521 -----------------------------------
7523 function Build_Constrained_Access_Type
7524 (Old_Type
: Entity_Id
) return Entity_Id
7526 Desig_Type
: constant Entity_Id
:= Designated_Type
(Old_Type
);
7528 Desig_Subtype
: Entity_Id
;
7532 -- if the original access type was not embedded in the enclosing
7533 -- type definition, there is no need to produce a new access
7534 -- subtype. In fact every access type with an explicit constraint
7535 -- generates an itype whose scope is the enclosing record.
7537 if not Is_Type
(Scope
(Old_Type
)) then
7540 elsif Is_Array_Type
(Desig_Type
) then
7541 Desig_Subtype
:= Build_Constrained_Array_Type
(Desig_Type
);
7543 elsif Has_Discriminants
(Desig_Type
) then
7545 -- This may be an access type to an enclosing record type for
7546 -- which we are constructing the constrained components. Return
7547 -- the enclosing record subtype. This is not always correct,
7548 -- but avoids infinite recursion. ???
7550 Desig_Subtype
:= Any_Type
;
7552 for J
in reverse 0 .. Scope_Stack
.Last
loop
7553 Scop
:= Scope_Stack
.Table
(J
).Entity
;
7556 and then Base_Type
(Scop
) = Base_Type
(Desig_Type
)
7558 Desig_Subtype
:= Scop
;
7561 exit when not Is_Type
(Scop
);
7564 if Desig_Subtype
= Any_Type
then
7566 Build_Constrained_Discriminated_Type
(Desig_Type
);
7573 if Desig_Subtype
/= Desig_Type
then
7575 -- The Related_Node better be here or else we won't be able
7576 -- to attach new itypes to a node in the tree.
7578 pragma Assert
(Present
(Related_Node
));
7580 Itype
:= Create_Itype
(E_Access_Subtype
, Related_Node
);
7582 Set_Etype
(Itype
, Base_Type
(Old_Type
));
7583 Set_Size_Info
(Itype
, (Old_Type
));
7584 Set_Directly_Designated_Type
(Itype
, Desig_Subtype
);
7585 Set_Depends_On_Private
(Itype
, Has_Private_Component
7587 Set_Is_Access_Constant
(Itype
, Is_Access_Constant
7590 -- The new itype needs freezing when it depends on a not frozen
7591 -- type and the enclosing subtype needs freezing.
7593 if Has_Delayed_Freeze
(Constrained_Typ
)
7594 and then not Is_Frozen
(Constrained_Typ
)
7596 Conditional_Delay
(Itype
, Base_Type
(Old_Type
));
7604 end Build_Constrained_Access_Type
;
7606 ----------------------------------
7607 -- Build_Constrained_Array_Type --
7608 ----------------------------------
7610 function Build_Constrained_Array_Type
7611 (Old_Type
: Entity_Id
) return Entity_Id
7615 Old_Index
: Node_Id
;
7616 Range_Node
: Node_Id
;
7617 Constr_List
: List_Id
;
7619 Need_To_Create_Itype
: Boolean := False;
7622 Old_Index
:= First_Index
(Old_Type
);
7623 while Present
(Old_Index
) loop
7624 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
7626 if Is_Discriminant
(Lo_Expr
)
7627 or else Is_Discriminant
(Hi_Expr
)
7629 Need_To_Create_Itype
:= True;
7632 Next_Index
(Old_Index
);
7635 if Need_To_Create_Itype
then
7636 Constr_List
:= New_List
;
7638 Old_Index
:= First_Index
(Old_Type
);
7639 while Present
(Old_Index
) loop
7640 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
7642 if Is_Discriminant
(Lo_Expr
) then
7643 Lo_Expr
:= Get_Discr_Value
(Lo_Expr
);
7646 if Is_Discriminant
(Hi_Expr
) then
7647 Hi_Expr
:= Get_Discr_Value
(Hi_Expr
);
7652 (Loc
, New_Copy_Tree
(Lo_Expr
), New_Copy_Tree
(Hi_Expr
));
7654 Append
(Range_Node
, To
=> Constr_List
);
7656 Next_Index
(Old_Index
);
7659 return Build_Subtype
(Old_Type
, Constr_List
);
7664 end Build_Constrained_Array_Type
;
7666 ------------------------------------------
7667 -- Build_Constrained_Discriminated_Type --
7668 ------------------------------------------
7670 function Build_Constrained_Discriminated_Type
7671 (Old_Type
: Entity_Id
) return Entity_Id
7674 Constr_List
: List_Id
;
7675 Old_Constraint
: Elmt_Id
;
7677 Need_To_Create_Itype
: Boolean := False;
7680 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
7681 while Present
(Old_Constraint
) loop
7682 Expr
:= Node
(Old_Constraint
);
7684 if Is_Discriminant
(Expr
) then
7685 Need_To_Create_Itype
:= True;
7688 Next_Elmt
(Old_Constraint
);
7691 if Need_To_Create_Itype
then
7692 Constr_List
:= New_List
;
7694 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
7695 while Present
(Old_Constraint
) loop
7696 Expr
:= Node
(Old_Constraint
);
7698 if Is_Discriminant
(Expr
) then
7699 Expr
:= Get_Discr_Value
(Expr
);
7702 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
7704 Next_Elmt
(Old_Constraint
);
7707 return Build_Subtype
(Old_Type
, Constr_List
);
7712 end Build_Constrained_Discriminated_Type
;
7718 function Build_Subtype
(T
: Entity_Id
; C
: List_Id
) return Entity_Id
is
7720 Subtyp_Decl
: Node_Id
;
7722 Btyp
: Entity_Id
:= Base_Type
(T
);
7725 -- The Related_Node better be here or else we won't be able to
7726 -- attach new itypes to a node in the tree.
7728 pragma Assert
(Present
(Related_Node
));
7730 -- If the view of the component's type is incomplete or private
7731 -- with unknown discriminants, then the constraint must be applied
7732 -- to the full type.
7734 if Has_Unknown_Discriminants
(Btyp
)
7735 and then Present
(Underlying_Type
(Btyp
))
7737 Btyp
:= Underlying_Type
(Btyp
);
7741 Make_Subtype_Indication
(Loc
,
7742 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
7743 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
, C
));
7745 Def_Id
:= Create_Itype
(Ekind
(T
), Related_Node
);
7748 Make_Subtype_Declaration
(Loc
,
7749 Defining_Identifier
=> Def_Id
,
7750 Subtype_Indication
=> Indic
);
7752 Set_Parent
(Subtyp_Decl
, Parent
(Related_Node
));
7754 -- Itypes must be analyzed with checks off (see package Itypes)
7756 Analyze
(Subtyp_Decl
, Suppress
=> All_Checks
);
7761 ---------------------
7762 -- Get_Discr_Value --
7763 ---------------------
7765 function Get_Discr_Value
(Discrim
: Entity_Id
) return Node_Id
is
7766 D
: Entity_Id
:= First_Discriminant
(Typ
);
7767 E
: Elmt_Id
:= First_Elmt
(Constraints
);
7771 -- The discriminant may be declared for the type, in which case we
7772 -- find it by iterating over the list of discriminants. If the
7773 -- discriminant is inherited from a parent type, it appears as the
7774 -- corresponding discriminant of the current type. This will be the
7775 -- case when constraining an inherited component whose constraint is
7776 -- given by a discriminant of the parent.
7778 while Present
(D
) loop
7779 if D
= Entity
(Discrim
)
7780 or else Corresponding_Discriminant
(D
) = Entity
(Discrim
)
7785 Next_Discriminant
(D
);
7789 -- The corresponding_Discriminant mechanism is incomplete, because
7790 -- the correspondence between new and old discriminants is not one
7791 -- to one: one new discriminant can constrain several old ones. In
7792 -- that case, scan sequentially the stored_constraint, the list of
7793 -- discriminants of the parents, and the constraints.
7795 if Is_Derived_Type
(Typ
)
7796 and then Present
(Stored_Constraint
(Typ
))
7797 and then Scope
(Entity
(Discrim
)) = Etype
(Typ
)
7799 D
:= First_Discriminant
(Etype
(Typ
));
7800 E
:= First_Elmt
(Constraints
);
7801 G
:= First_Elmt
(Stored_Constraint
(Typ
));
7803 while Present
(D
) loop
7804 if D
= Entity
(Discrim
) then
7808 Next_Discriminant
(D
);
7814 -- Something is wrong if we did not find the value
7816 raise Program_Error
;
7817 end Get_Discr_Value
;
7819 ---------------------
7820 -- Is_Discriminant --
7821 ---------------------
7823 function Is_Discriminant
(Expr
: Node_Id
) return Boolean is
7824 Discrim_Scope
: Entity_Id
;
7827 if Denotes_Discriminant
(Expr
) then
7828 Discrim_Scope
:= Scope
(Entity
(Expr
));
7830 -- Either we have a reference to one of Typ's discriminants,
7832 pragma Assert
(Discrim_Scope
= Typ
7834 -- or to the discriminants of the parent type, in the case
7835 -- of a derivation of a tagged type with variants.
7837 or else Discrim_Scope
= Etype
(Typ
)
7838 or else Full_View
(Discrim_Scope
) = Etype
(Typ
)
7840 -- or same as above for the case where the discriminants
7841 -- were declared in Typ's private view.
7843 or else (Is_Private_Type
(Discrim_Scope
)
7844 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
7846 -- or else we are deriving from the full view and the
7847 -- discriminant is declared in the private entity.
7849 or else (Is_Private_Type
(Typ
)
7850 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
7852 -- or we have a class-wide type, in which case make sure the
7853 -- discriminant found belongs to the root type.
7855 or else (Is_Class_Wide_Type
(Typ
)
7856 and then Etype
(Typ
) = Discrim_Scope
));
7861 -- In all other cases we have something wrong
7864 end Is_Discriminant
;
7866 -- Start of processing for Constrain_Component_Type
7869 if Is_Array_Type
(Compon_Type
) then
7870 return Build_Constrained_Array_Type
(Compon_Type
);
7872 elsif Has_Discriminants
(Compon_Type
) then
7873 return Build_Constrained_Discriminated_Type
(Compon_Type
);
7875 elsif Is_Access_Type
(Compon_Type
) then
7876 return Build_Constrained_Access_Type
(Compon_Type
);
7880 end Constrain_Component_Type
;
7882 --------------------------
7883 -- Constrain_Concurrent --
7884 --------------------------
7886 -- For concurrent types, the associated record value type carries the same
7887 -- discriminants, so when we constrain a concurrent type, we must constrain
7888 -- the value type as well.
7890 procedure Constrain_Concurrent
7891 (Def_Id
: in out Entity_Id
;
7893 Related_Nod
: Node_Id
;
7894 Related_Id
: Entity_Id
;
7897 T_Ent
: Entity_Id
:= Entity
(Subtype_Mark
(SI
));
7901 if Ekind
(T_Ent
) in Access_Kind
then
7902 T_Ent
:= Designated_Type
(T_Ent
);
7905 T_Val
:= Corresponding_Record_Type
(T_Ent
);
7907 if Present
(T_Val
) then
7910 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
7913 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
7915 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
7916 Set_Corresponding_Record_Type
(Def_Id
,
7917 Constrain_Corresponding_Record
7918 (Def_Id
, T_Val
, Related_Nod
, Related_Id
));
7921 -- If there is no associated record, expansion is disabled and this
7922 -- is a generic context. Create a subtype in any case, so that
7923 -- semantic analysis can proceed.
7926 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
7929 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
7931 end Constrain_Concurrent
;
7933 ------------------------------------
7934 -- Constrain_Corresponding_Record --
7935 ------------------------------------
7937 function Constrain_Corresponding_Record
7938 (Prot_Subt
: Entity_Id
;
7939 Corr_Rec
: Entity_Id
;
7940 Related_Nod
: Node_Id
;
7941 Related_Id
: Entity_Id
) return Entity_Id
7943 T_Sub
: constant Entity_Id
:=
7944 Create_Itype
(E_Record_Subtype
, Related_Nod
, Related_Id
, 'V');
7947 Set_Etype
(T_Sub
, Corr_Rec
);
7948 Init_Size_Align
(T_Sub
);
7949 Set_Has_Discriminants
(T_Sub
, Has_Discriminants
(Prot_Subt
));
7950 Set_Is_Constrained
(T_Sub
, True);
7951 Set_First_Entity
(T_Sub
, First_Entity
(Corr_Rec
));
7952 Set_Last_Entity
(T_Sub
, Last_Entity
(Corr_Rec
));
7954 Conditional_Delay
(T_Sub
, Corr_Rec
);
7956 if Has_Discriminants
(Prot_Subt
) then -- False only if errors.
7957 Set_Discriminant_Constraint
7958 (T_Sub
, Discriminant_Constraint
(Prot_Subt
));
7959 Set_Stored_Constraint_From_Discriminant_Constraint
(T_Sub
);
7960 Create_Constrained_Components
7961 (T_Sub
, Related_Nod
, Corr_Rec
, Discriminant_Constraint
(T_Sub
));
7964 Set_Depends_On_Private
(T_Sub
, Has_Private_Component
(T_Sub
));
7967 end Constrain_Corresponding_Record
;
7969 -----------------------
7970 -- Constrain_Decimal --
7971 -----------------------
7973 procedure Constrain_Decimal
(Def_Id
: Node_Id
; S
: Node_Id
) is
7974 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
7975 C
: constant Node_Id
:= Constraint
(S
);
7976 Loc
: constant Source_Ptr
:= Sloc
(C
);
7977 Range_Expr
: Node_Id
;
7978 Digits_Expr
: Node_Id
;
7983 Set_Ekind
(Def_Id
, E_Decimal_Fixed_Point_Subtype
);
7985 if Nkind
(C
) = N_Range_Constraint
then
7986 Range_Expr
:= Range_Expression
(C
);
7987 Digits_Val
:= Digits_Value
(T
);
7990 pragma Assert
(Nkind
(C
) = N_Digits_Constraint
);
7991 Digits_Expr
:= Digits_Expression
(C
);
7992 Analyze_And_Resolve
(Digits_Expr
, Any_Integer
);
7994 Check_Digits_Expression
(Digits_Expr
);
7995 Digits_Val
:= Expr_Value
(Digits_Expr
);
7997 if Digits_Val
> Digits_Value
(T
) then
7999 ("digits expression is incompatible with subtype", C
);
8000 Digits_Val
:= Digits_Value
(T
);
8003 if Present
(Range_Constraint
(C
)) then
8004 Range_Expr
:= Range_Expression
(Range_Constraint
(C
));
8006 Range_Expr
:= Empty
;
8010 Set_Etype
(Def_Id
, Base_Type
(T
));
8011 Set_Size_Info
(Def_Id
, (T
));
8012 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
8013 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
8014 Set_Scale_Value
(Def_Id
, Scale_Value
(T
));
8015 Set_Small_Value
(Def_Id
, Small_Value
(T
));
8016 Set_Machine_Radix_10
(Def_Id
, Machine_Radix_10
(T
));
8017 Set_Digits_Value
(Def_Id
, Digits_Val
);
8019 -- Manufacture range from given digits value if no range present
8021 if No
(Range_Expr
) then
8022 Bound_Val
:= (Ureal_10
** Digits_Val
- Ureal_1
) * Small_Value
(T
);
8026 Convert_To
(T
, Make_Real_Literal
(Loc
, (-Bound_Val
))),
8028 Convert_To
(T
, Make_Real_Literal
(Loc
, Bound_Val
)));
8031 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expr
, T
);
8032 Set_Discrete_RM_Size
(Def_Id
);
8034 -- Unconditionally delay the freeze, since we cannot set size
8035 -- information in all cases correctly until the freeze point.
8037 Set_Has_Delayed_Freeze
(Def_Id
);
8038 end Constrain_Decimal
;
8040 ----------------------------------
8041 -- Constrain_Discriminated_Type --
8042 ----------------------------------
8044 procedure Constrain_Discriminated_Type
8045 (Def_Id
: Entity_Id
;
8047 Related_Nod
: Node_Id
;
8048 For_Access
: Boolean := False)
8050 E
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
8053 Elist
: Elist_Id
:= New_Elmt_List
;
8055 procedure Fixup_Bad_Constraint
;
8056 -- This is called after finding a bad constraint, and after having
8057 -- posted an appropriate error message. The mission is to leave the
8058 -- entity T in as reasonable state as possible!
8060 --------------------------
8061 -- Fixup_Bad_Constraint --
8062 --------------------------
8064 procedure Fixup_Bad_Constraint
is
8066 -- Set a reasonable Ekind for the entity. For an incomplete type,
8067 -- we can't do much, but for other types, we can set the proper
8068 -- corresponding subtype kind.
8070 if Ekind
(T
) = E_Incomplete_Type
then
8071 Set_Ekind
(Def_Id
, Ekind
(T
));
8073 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
8076 Set_Etype
(Def_Id
, Any_Type
);
8077 Set_Error_Posted
(Def_Id
);
8078 end Fixup_Bad_Constraint
;
8080 -- Start of processing for Constrain_Discriminated_Type
8083 C
:= Constraint
(S
);
8085 -- A discriminant constraint is only allowed in a subtype indication,
8086 -- after a subtype mark. This subtype mark must denote either a type
8087 -- with discriminants, or an access type whose designated type is a
8088 -- type with discriminants. A discriminant constraint specifies the
8089 -- values of these discriminants (RM 3.7.2(5)).
8091 T
:= Base_Type
(Entity
(Subtype_Mark
(S
)));
8093 if Ekind
(T
) in Access_Kind
then
8094 T
:= Designated_Type
(T
);
8097 -- Check that the type has visible discriminants. The type may be
8098 -- a private type with unknown discriminants whose full view has
8099 -- discriminants which are invisible.
8101 if not Has_Discriminants
(T
)
8103 (Has_Unknown_Discriminants
(T
)
8104 and then Is_Private_Type
(T
))
8106 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
8107 Fixup_Bad_Constraint
;
8110 elsif Is_Constrained
(E
)
8111 or else (Ekind
(E
) = E_Class_Wide_Subtype
8112 and then Present
(Discriminant_Constraint
(E
)))
8114 Error_Msg_N
("type is already constrained", Subtype_Mark
(S
));
8115 Fixup_Bad_Constraint
;
8119 -- T may be an unconstrained subtype (e.g. a generic actual).
8120 -- Constraint applies to the base type.
8124 Elist
:= Build_Discriminant_Constraints
(T
, S
);
8126 -- If the list returned was empty we had an error in building the
8127 -- discriminant constraint. We have also already signalled an error
8128 -- in the incomplete type case
8130 if Is_Empty_Elmt_List
(Elist
) then
8131 Fixup_Bad_Constraint
;
8135 Build_Discriminated_Subtype
(T
, Def_Id
, Elist
, Related_Nod
, For_Access
);
8136 end Constrain_Discriminated_Type
;
8138 ---------------------------
8139 -- Constrain_Enumeration --
8140 ---------------------------
8142 procedure Constrain_Enumeration
(Def_Id
: Node_Id
; S
: Node_Id
) is
8143 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
8144 C
: constant Node_Id
:= Constraint
(S
);
8147 Set_Ekind
(Def_Id
, E_Enumeration_Subtype
);
8149 Set_First_Literal
(Def_Id
, First_Literal
(Base_Type
(T
)));
8151 Set_Etype
(Def_Id
, Base_Type
(T
));
8152 Set_Size_Info
(Def_Id
, (T
));
8153 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
8154 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
8156 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
8158 Set_Discrete_RM_Size
(Def_Id
);
8159 end Constrain_Enumeration
;
8161 ----------------------
8162 -- Constrain_Float --
8163 ----------------------
8165 procedure Constrain_Float
(Def_Id
: Node_Id
; S
: Node_Id
) is
8166 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
8172 Set_Ekind
(Def_Id
, E_Floating_Point_Subtype
);
8174 Set_Etype
(Def_Id
, Base_Type
(T
));
8175 Set_Size_Info
(Def_Id
, (T
));
8176 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
8178 -- Process the constraint
8180 C
:= Constraint
(S
);
8182 -- Digits constraint present
8184 if Nkind
(C
) = N_Digits_Constraint
then
8185 Check_Restriction
(No_Obsolescent_Features
, C
);
8187 if Warn_On_Obsolescent_Feature
then
8189 ("subtype digits constraint is an " &
8190 "obsolescent feature ('R'M 'J.3(8))?", C
);
8193 D
:= Digits_Expression
(C
);
8194 Analyze_And_Resolve
(D
, Any_Integer
);
8195 Check_Digits_Expression
(D
);
8196 Set_Digits_Value
(Def_Id
, Expr_Value
(D
));
8198 -- Check that digits value is in range. Obviously we can do this
8199 -- at compile time, but it is strictly a runtime check, and of
8200 -- course there is an ACVC test that checks this!
8202 if Digits_Value
(Def_Id
) > Digits_Value
(T
) then
8203 Error_Msg_Uint_1
:= Digits_Value
(T
);
8204 Error_Msg_N
("?digits value is too large, maximum is ^", D
);
8206 Make_Raise_Constraint_Error
(Sloc
(D
),
8207 Reason
=> CE_Range_Check_Failed
);
8208 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
8211 C
:= Range_Constraint
(C
);
8213 -- No digits constraint present
8216 Set_Digits_Value
(Def_Id
, Digits_Value
(T
));
8219 -- Range constraint present
8221 if Nkind
(C
) = N_Range_Constraint
then
8222 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
8224 -- No range constraint present
8227 pragma Assert
(No
(C
));
8228 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
8231 Set_Is_Constrained
(Def_Id
);
8232 end Constrain_Float
;
8234 ---------------------
8235 -- Constrain_Index --
8236 ---------------------
8238 procedure Constrain_Index
8241 Related_Nod
: Node_Id
;
8242 Related_Id
: Entity_Id
;
8247 R
: Node_Id
:= Empty
;
8248 T
: constant Entity_Id
:= Etype
(Index
);
8251 if Nkind
(S
) = N_Range
8253 (Nkind
(S
) = N_Attribute_Reference
8254 and then Attribute_Name
(S
) = Name_Range
)
8256 -- A Range attribute will transformed into N_Range by Resolve
8262 Process_Range_Expr_In_Decl
(R
, T
, Empty_List
);
8264 if not Error_Posted
(S
)
8266 (Nkind
(S
) /= N_Range
8267 or else not Covers
(T
, (Etype
(Low_Bound
(S
))))
8268 or else not Covers
(T
, (Etype
(High_Bound
(S
)))))
8270 if Base_Type
(T
) /= Any_Type
8271 and then Etype
(Low_Bound
(S
)) /= Any_Type
8272 and then Etype
(High_Bound
(S
)) /= Any_Type
8274 Error_Msg_N
("range expected", S
);
8278 elsif Nkind
(S
) = N_Subtype_Indication
then
8280 -- The parser has verified that this is a discrete indication
8282 Resolve_Discrete_Subtype_Indication
(S
, T
);
8283 R
:= Range_Expression
(Constraint
(S
));
8285 elsif Nkind
(S
) = N_Discriminant_Association
then
8287 -- Syntactically valid in subtype indication
8289 Error_Msg_N
("invalid index constraint", S
);
8290 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
8293 -- Subtype_Mark case, no anonymous subtypes to construct
8298 if Is_Entity_Name
(S
) then
8299 if not Is_Type
(Entity
(S
)) then
8300 Error_Msg_N
("expect subtype mark for index constraint", S
);
8302 elsif Base_Type
(Entity
(S
)) /= Base_Type
(T
) then
8303 Wrong_Type
(S
, Base_Type
(T
));
8309 Error_Msg_N
("invalid index constraint", S
);
8310 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
8316 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
, Suffix_Index
);
8318 Set_Etype
(Def_Id
, Base_Type
(T
));
8320 if Is_Modular_Integer_Type
(T
) then
8321 Set_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
8323 elsif Is_Integer_Type
(T
) then
8324 Set_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
8327 Set_Ekind
(Def_Id
, E_Enumeration_Subtype
);
8328 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
8331 Set_Size_Info
(Def_Id
, (T
));
8332 Set_RM_Size
(Def_Id
, RM_Size
(T
));
8333 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
8335 Set_Scalar_Range
(Def_Id
, R
);
8337 Set_Etype
(S
, Def_Id
);
8338 Set_Discrete_RM_Size
(Def_Id
);
8339 end Constrain_Index
;
8341 -----------------------
8342 -- Constrain_Integer --
8343 -----------------------
8345 procedure Constrain_Integer
(Def_Id
: Node_Id
; S
: Node_Id
) is
8346 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
8347 C
: constant Node_Id
:= Constraint
(S
);
8350 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
8352 if Is_Modular_Integer_Type
(T
) then
8353 Set_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
8355 Set_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
8358 Set_Etype
(Def_Id
, Base_Type
(T
));
8359 Set_Size_Info
(Def_Id
, (T
));
8360 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
8361 Set_Discrete_RM_Size
(Def_Id
);
8362 end Constrain_Integer
;
8364 ------------------------------
8365 -- Constrain_Ordinary_Fixed --
8366 ------------------------------
8368 procedure Constrain_Ordinary_Fixed
(Def_Id
: Node_Id
; S
: Node_Id
) is
8369 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
8375 Set_Ekind
(Def_Id
, E_Ordinary_Fixed_Point_Subtype
);
8376 Set_Etype
(Def_Id
, Base_Type
(T
));
8377 Set_Size_Info
(Def_Id
, (T
));
8378 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
8379 Set_Small_Value
(Def_Id
, Small_Value
(T
));
8381 -- Process the constraint
8383 C
:= Constraint
(S
);
8385 -- Delta constraint present
8387 if Nkind
(C
) = N_Delta_Constraint
then
8388 Check_Restriction
(No_Obsolescent_Features
, C
);
8390 if Warn_On_Obsolescent_Feature
then
8392 ("subtype delta constraint is an " &
8393 "obsolescent feature ('R'M 'J.3(7))?");
8396 D
:= Delta_Expression
(C
);
8397 Analyze_And_Resolve
(D
, Any_Real
);
8398 Check_Delta_Expression
(D
);
8399 Set_Delta_Value
(Def_Id
, Expr_Value_R
(D
));
8401 -- Check that delta value is in range. Obviously we can do this
8402 -- at compile time, but it is strictly a runtime check, and of
8403 -- course there is an ACVC test that checks this!
8405 if Delta_Value
(Def_Id
) < Delta_Value
(T
) then
8406 Error_Msg_N
("?delta value is too small", D
);
8408 Make_Raise_Constraint_Error
(Sloc
(D
),
8409 Reason
=> CE_Range_Check_Failed
);
8410 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
8413 C
:= Range_Constraint
(C
);
8415 -- No delta constraint present
8418 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
8421 -- Range constraint present
8423 if Nkind
(C
) = N_Range_Constraint
then
8424 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
8426 -- No range constraint present
8429 pragma Assert
(No
(C
));
8430 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
8434 Set_Discrete_RM_Size
(Def_Id
);
8436 -- Unconditionally delay the freeze, since we cannot set size
8437 -- information in all cases correctly until the freeze point.
8439 Set_Has_Delayed_Freeze
(Def_Id
);
8440 end Constrain_Ordinary_Fixed
;
8442 ---------------------------
8443 -- Convert_Scalar_Bounds --
8444 ---------------------------
8446 procedure Convert_Scalar_Bounds
8448 Parent_Type
: Entity_Id
;
8449 Derived_Type
: Entity_Id
;
8452 Implicit_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
8459 Lo
:= Build_Scalar_Bound
8460 (Type_Low_Bound
(Derived_Type
),
8461 Parent_Type
, Implicit_Base
);
8463 Hi
:= Build_Scalar_Bound
8464 (Type_High_Bound
(Derived_Type
),
8465 Parent_Type
, Implicit_Base
);
8472 Set_Includes_Infinities
(Rng
, Has_Infinities
(Derived_Type
));
8474 Set_Parent
(Rng
, N
);
8475 Set_Scalar_Range
(Derived_Type
, Rng
);
8477 -- Analyze the bounds
8479 Analyze_And_Resolve
(Lo
, Implicit_Base
);
8480 Analyze_And_Resolve
(Hi
, Implicit_Base
);
8482 -- Analyze the range itself, except that we do not analyze it if
8483 -- the bounds are real literals, and we have a fixed-point type.
8484 -- The reason for this is that we delay setting the bounds in this
8485 -- case till we know the final Small and Size values (see circuit
8486 -- in Freeze.Freeze_Fixed_Point_Type for further details).
8488 if Is_Fixed_Point_Type
(Parent_Type
)
8489 and then Nkind
(Lo
) = N_Real_Literal
8490 and then Nkind
(Hi
) = N_Real_Literal
8494 -- Here we do the analysis of the range
8496 -- Note: we do this manually, since if we do a normal Analyze and
8497 -- Resolve call, there are problems with the conversions used for
8498 -- the derived type range.
8501 Set_Etype
(Rng
, Implicit_Base
);
8502 Set_Analyzed
(Rng
, True);
8504 end Convert_Scalar_Bounds
;
8510 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
) is
8512 -- Initialize new full declaration entity by copying the pertinent
8513 -- fields of the corresponding private declaration entity.
8515 -- We temporarily set Ekind to a value appropriate for a type to
8516 -- avoid assert failures in Einfo from checking for setting type
8517 -- attributes on something that is not a type. Ekind (Priv) is an
8518 -- appropriate choice, since it allowed the attributes to be set
8519 -- in the first place. This Ekind value will be modified later.
8521 Set_Ekind
(Full
, Ekind
(Priv
));
8523 -- Also set Etype temporarily to Any_Type, again, in the absence
8524 -- of errors, it will be properly reset, and if there are errors,
8525 -- then we want a value of Any_Type to remain.
8527 Set_Etype
(Full
, Any_Type
);
8529 -- Now start copying attributes
8531 Set_Has_Discriminants
(Full
, Has_Discriminants
(Priv
));
8533 if Has_Discriminants
(Full
) then
8534 Set_Discriminant_Constraint
(Full
, Discriminant_Constraint
(Priv
));
8535 Set_Stored_Constraint
(Full
, Stored_Constraint
(Priv
));
8538 Set_First_Rep_Item
(Full
, First_Rep_Item
(Priv
));
8539 Set_Homonym
(Full
, Homonym
(Priv
));
8540 Set_Is_Immediately_Visible
(Full
, Is_Immediately_Visible
(Priv
));
8541 Set_Is_Public
(Full
, Is_Public
(Priv
));
8542 Set_Is_Pure
(Full
, Is_Pure
(Priv
));
8543 Set_Is_Tagged_Type
(Full
, Is_Tagged_Type
(Priv
));
8545 Conditional_Delay
(Full
, Priv
);
8547 if Is_Tagged_Type
(Full
) then
8548 Set_Primitive_Operations
(Full
, Primitive_Operations
(Priv
));
8550 if Priv
= Base_Type
(Priv
) then
8551 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Priv
));
8555 Set_Is_Volatile
(Full
, Is_Volatile
(Priv
));
8556 Set_Treat_As_Volatile
(Full
, Treat_As_Volatile
(Priv
));
8557 Set_Scope
(Full
, Scope
(Priv
));
8558 Set_Next_Entity
(Full
, Next_Entity
(Priv
));
8559 Set_First_Entity
(Full
, First_Entity
(Priv
));
8560 Set_Last_Entity
(Full
, Last_Entity
(Priv
));
8562 -- If access types have been recorded for later handling, keep them in
8563 -- the full view so that they get handled when the full view freeze
8564 -- node is expanded.
8566 if Present
(Freeze_Node
(Priv
))
8567 and then Present
(Access_Types_To_Process
(Freeze_Node
(Priv
)))
8569 Ensure_Freeze_Node
(Full
);
8570 Set_Access_Types_To_Process
8571 (Freeze_Node
(Full
),
8572 Access_Types_To_Process
(Freeze_Node
(Priv
)));
8575 -- Swap the two entities. Now Privat is the full type entity and
8576 -- Full is the private one. They will be swapped back at the end
8577 -- of the private part. This swapping ensures that the entity that
8578 -- is visible in the private part is the full declaration.
8580 Exchange_Entities
(Priv
, Full
);
8581 Append_Entity
(Full
, Scope
(Full
));
8584 -------------------------------------
8585 -- Copy_Array_Base_Type_Attributes --
8586 -------------------------------------
8588 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
) is
8590 Set_Component_Alignment
(T1
, Component_Alignment
(T2
));
8591 Set_Component_Type
(T1
, Component_Type
(T2
));
8592 Set_Component_Size
(T1
, Component_Size
(T2
));
8593 Set_Has_Controlled_Component
(T1
, Has_Controlled_Component
(T2
));
8594 Set_Finalize_Storage_Only
(T1
, Finalize_Storage_Only
(T2
));
8595 Set_Has_Non_Standard_Rep
(T1
, Has_Non_Standard_Rep
(T2
));
8596 Set_Has_Task
(T1
, Has_Task
(T2
));
8597 Set_Is_Packed
(T1
, Is_Packed
(T2
));
8598 Set_Has_Aliased_Components
(T1
, Has_Aliased_Components
(T2
));
8599 Set_Has_Atomic_Components
(T1
, Has_Atomic_Components
(T2
));
8600 Set_Has_Volatile_Components
(T1
, Has_Volatile_Components
(T2
));
8601 end Copy_Array_Base_Type_Attributes
;
8603 -----------------------------------
8604 -- Copy_Array_Subtype_Attributes --
8605 -----------------------------------
8607 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
) is
8609 Set_Size_Info
(T1
, T2
);
8611 Set_First_Index
(T1
, First_Index
(T2
));
8612 Set_Is_Aliased
(T1
, Is_Aliased
(T2
));
8613 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
8614 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
8615 Set_Treat_As_Volatile
(T1
, Treat_As_Volatile
(T2
));
8616 Set_Is_Constrained
(T1
, Is_Constrained
(T2
));
8617 Set_Depends_On_Private
(T1
, Has_Private_Component
(T2
));
8618 Set_First_Rep_Item
(T1
, First_Rep_Item
(T2
));
8619 Set_Convention
(T1
, Convention
(T2
));
8620 Set_Is_Limited_Composite
(T1
, Is_Limited_Composite
(T2
));
8621 Set_Is_Private_Composite
(T1
, Is_Private_Composite
(T2
));
8622 end Copy_Array_Subtype_Attributes
;
8624 -----------------------------------
8625 -- Create_Constrained_Components --
8626 -----------------------------------
8628 procedure Create_Constrained_Components
8630 Decl_Node
: Node_Id
;
8632 Constraints
: Elist_Id
)
8634 Loc
: constant Source_Ptr
:= Sloc
(Subt
);
8635 Comp_List
: constant Elist_Id
:= New_Elmt_List
;
8636 Parent_Type
: constant Entity_Id
:= Etype
(Typ
);
8637 Assoc_List
: constant List_Id
:= New_List
;
8638 Discr_Val
: Elmt_Id
;
8642 Is_Static
: Boolean := True;
8644 procedure Collect_Fixed_Components
(Typ
: Entity_Id
);
8645 -- Collect parent type components that do not appear in a variant part
8647 procedure Create_All_Components
;
8648 -- Iterate over Comp_List to create the components of the subtype
8650 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
;
8651 -- Creates a new component from Old_Compon, copying all the fields from
8652 -- it, including its Etype, inserts the new component in the Subt entity
8653 -- chain and returns the new component.
8655 function Is_Variant_Record
(T
: Entity_Id
) return Boolean;
8656 -- If true, and discriminants are static, collect only components from
8657 -- variants selected by discriminant values.
8659 ------------------------------
8660 -- Collect_Fixed_Components --
8661 ------------------------------
8663 procedure Collect_Fixed_Components
(Typ
: Entity_Id
) is
8665 -- Build association list for discriminants, and find components of the
8666 -- variant part selected by the values of the discriminants.
8668 Old_C
:= First_Discriminant
(Typ
);
8669 Discr_Val
:= First_Elmt
(Constraints
);
8670 while Present
(Old_C
) loop
8671 Append_To
(Assoc_List
,
8672 Make_Component_Association
(Loc
,
8673 Choices
=> New_List
(New_Occurrence_Of
(Old_C
, Loc
)),
8674 Expression
=> New_Copy
(Node
(Discr_Val
))));
8676 Next_Elmt
(Discr_Val
);
8677 Next_Discriminant
(Old_C
);
8680 -- The tag, and the possible parent and controller components
8681 -- are unconditionally in the subtype.
8683 if Is_Tagged_Type
(Typ
)
8684 or else Has_Controlled_Component
(Typ
)
8686 Old_C
:= First_Component
(Typ
);
8687 while Present
(Old_C
) loop
8688 if Chars
((Old_C
)) = Name_uTag
8689 or else Chars
((Old_C
)) = Name_uParent
8690 or else Chars
((Old_C
)) = Name_uController
8692 Append_Elmt
(Old_C
, Comp_List
);
8695 Next_Component
(Old_C
);
8698 end Collect_Fixed_Components
;
8700 ---------------------------
8701 -- Create_All_Components --
8702 ---------------------------
8704 procedure Create_All_Components
is
8708 Comp
:= First_Elmt
(Comp_List
);
8709 while Present
(Comp
) loop
8710 Old_C
:= Node
(Comp
);
8711 New_C
:= Create_Component
(Old_C
);
8715 Constrain_Component_Type
8716 (Etype
(Old_C
), Subt
, Decl_Node
, Typ
, Constraints
));
8717 Set_Is_Public
(New_C
, Is_Public
(Subt
));
8721 end Create_All_Components
;
8723 ----------------------
8724 -- Create_Component --
8725 ----------------------
8727 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
is
8728 New_Compon
: constant Entity_Id
:= New_Copy
(Old_Compon
);
8731 -- Set the parent so we have a proper link for freezing etc. This
8732 -- is not a real parent pointer, since of course our parent does
8733 -- not own up to us and reference us, we are an illegitimate
8734 -- child of the original parent!
8736 Set_Parent
(New_Compon
, Parent
(Old_Compon
));
8738 -- We do not want this node marked as Comes_From_Source, since
8739 -- otherwise it would get first class status and a separate
8740 -- cross-reference line would be generated. Illegitimate
8741 -- children do not rate such recognition.
8743 Set_Comes_From_Source
(New_Compon
, False);
8745 -- But it is a real entity, and a birth certificate must be
8746 -- properly registered by entering it into the entity list.
8748 Enter_Name
(New_Compon
);
8750 end Create_Component
;
8752 -----------------------
8753 -- Is_Variant_Record --
8754 -----------------------
8756 function Is_Variant_Record
(T
: Entity_Id
) return Boolean is
8758 return Nkind
(Parent
(T
)) = N_Full_Type_Declaration
8759 and then Nkind
(Type_Definition
(Parent
(T
))) = N_Record_Definition
8760 and then Present
(Component_List
(Type_Definition
(Parent
(T
))))
8762 Variant_Part
(Component_List
(Type_Definition
(Parent
(T
)))));
8763 end Is_Variant_Record
;
8765 -- Start of processing for Create_Constrained_Components
8768 pragma Assert
(Subt
/= Base_Type
(Subt
));
8769 pragma Assert
(Typ
= Base_Type
(Typ
));
8771 Set_First_Entity
(Subt
, Empty
);
8772 Set_Last_Entity
(Subt
, Empty
);
8774 -- Check whether constraint is fully static, in which case we can
8775 -- optimize the list of components.
8777 Discr_Val
:= First_Elmt
(Constraints
);
8778 while Present
(Discr_Val
) loop
8779 if not Is_OK_Static_Expression
(Node
(Discr_Val
)) then
8784 Next_Elmt
(Discr_Val
);
8789 -- Inherit the discriminants of the parent type
8791 Old_C
:= First_Discriminant
(Typ
);
8792 while Present
(Old_C
) loop
8793 New_C
:= Create_Component
(Old_C
);
8794 Set_Is_Public
(New_C
, Is_Public
(Subt
));
8795 Next_Discriminant
(Old_C
);
8799 and then Is_Variant_Record
(Typ
)
8801 Collect_Fixed_Components
(Typ
);
8805 Component_List
(Type_Definition
(Parent
(Typ
))),
8806 Governed_By
=> Assoc_List
,
8808 Report_Errors
=> Errors
);
8809 pragma Assert
(not Errors
);
8811 Create_All_Components
;
8813 -- If the subtype declaration is created for a tagged type derivation
8814 -- with constraints, we retrieve the record definition of the parent
8815 -- type to select the components of the proper variant.
8818 and then Is_Tagged_Type
(Typ
)
8819 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
8821 Nkind
(Type_Definition
(Parent
(Typ
))) = N_Derived_Type_Definition
8822 and then Is_Variant_Record
(Parent_Type
)
8824 Collect_Fixed_Components
(Typ
);
8828 Component_List
(Type_Definition
(Parent
(Parent_Type
))),
8829 Governed_By
=> Assoc_List
,
8831 Report_Errors
=> Errors
);
8832 pragma Assert
(not Errors
);
8834 -- If the tagged derivation has a type extension, collect all the
8835 -- new components therein.
8838 (Record_Extension_Part
(Type_Definition
(Parent
(Typ
))))
8840 Old_C
:= First_Component
(Typ
);
8841 while Present
(Old_C
) loop
8842 if Original_Record_Component
(Old_C
) = Old_C
8843 and then Chars
(Old_C
) /= Name_uTag
8844 and then Chars
(Old_C
) /= Name_uParent
8845 and then Chars
(Old_C
) /= Name_uController
8847 Append_Elmt
(Old_C
, Comp_List
);
8850 Next_Component
(Old_C
);
8854 Create_All_Components
;
8857 -- If the discriminants are not static, or if this is a multi-level
8858 -- type extension, we have to include all the components of the
8861 Old_C
:= First_Component
(Typ
);
8862 while Present
(Old_C
) loop
8863 New_C
:= Create_Component
(Old_C
);
8867 Constrain_Component_Type
8868 (Etype
(Old_C
), Subt
, Decl_Node
, Typ
, Constraints
));
8869 Set_Is_Public
(New_C
, Is_Public
(Subt
));
8871 Next_Component
(Old_C
);
8876 end Create_Constrained_Components
;
8878 ------------------------------------------
8879 -- Decimal_Fixed_Point_Type_Declaration --
8880 ------------------------------------------
8882 procedure Decimal_Fixed_Point_Type_Declaration
8886 Loc
: constant Source_Ptr
:= Sloc
(Def
);
8887 Digs_Expr
: constant Node_Id
:= Digits_Expression
(Def
);
8888 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
8889 Implicit_Base
: Entity_Id
;
8895 -- Start of processing for Decimal_Fixed_Point_Type_Declaration
8898 Check_Restriction
(No_Fixed_Point
, Def
);
8900 -- Create implicit base type
8903 Create_Itype
(E_Decimal_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
8904 Set_Etype
(Implicit_Base
, Implicit_Base
);
8906 -- Analyze and process delta expression
8908 Analyze_And_Resolve
(Delta_Expr
, Universal_Real
);
8910 Check_Delta_Expression
(Delta_Expr
);
8911 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
8913 -- Check delta is power of 10, and determine scale value from it
8916 Val
: Ureal
:= Delta_Val
;
8919 Scale_Val
:= Uint_0
;
8921 if Val
< Ureal_1
then
8922 while Val
< Ureal_1
loop
8923 Val
:= Val
* Ureal_10
;
8924 Scale_Val
:= Scale_Val
+ 1;
8927 if Scale_Val
> 18 then
8928 Error_Msg_N
("scale exceeds maximum value of 18", Def
);
8929 Scale_Val
:= UI_From_Int
(+18);
8933 while Val
> Ureal_1
loop
8934 Val
:= Val
/ Ureal_10
;
8935 Scale_Val
:= Scale_Val
- 1;
8938 if Scale_Val
< -18 then
8939 Error_Msg_N
("scale is less than minimum value of -18", Def
);
8940 Scale_Val
:= UI_From_Int
(-18);
8944 if Val
/= Ureal_1
then
8945 Error_Msg_N
("delta expression must be a power of 10", Def
);
8946 Delta_Val
:= Ureal_10
** (-Scale_Val
);
8950 -- Set delta, scale and small (small = delta for decimal type)
8952 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
8953 Set_Scale_Value
(Implicit_Base
, Scale_Val
);
8954 Set_Small_Value
(Implicit_Base
, Delta_Val
);
8956 -- Analyze and process digits expression
8958 Analyze_And_Resolve
(Digs_Expr
, Any_Integer
);
8959 Check_Digits_Expression
(Digs_Expr
);
8960 Digs_Val
:= Expr_Value
(Digs_Expr
);
8962 if Digs_Val
> 18 then
8963 Digs_Val
:= UI_From_Int
(+18);
8964 Error_Msg_N
("digits value out of range, maximum is 18", Digs_Expr
);
8967 Set_Digits_Value
(Implicit_Base
, Digs_Val
);
8968 Bound_Val
:= UR_From_Uint
(10 ** Digs_Val
- 1) * Delta_Val
;
8970 -- Set range of base type from digits value for now. This will be
8971 -- expanded to represent the true underlying base range by Freeze.
8973 Set_Fixed_Range
(Implicit_Base
, Loc
, -Bound_Val
, Bound_Val
);
8975 -- Set size to zero for now, size will be set at freeze time. We have
8976 -- to do this for ordinary fixed-point, because the size depends on
8977 -- the specified small, and we might as well do the same for decimal
8980 Init_Size_Align
(Implicit_Base
);
8982 -- If there are bounds given in the declaration use them as the
8983 -- bounds of the first named subtype.
8985 if Present
(Real_Range_Specification
(Def
)) then
8987 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
8988 Low
: constant Node_Id
:= Low_Bound
(RRS
);
8989 High
: constant Node_Id
:= High_Bound
(RRS
);
8994 Analyze_And_Resolve
(Low
, Any_Real
);
8995 Analyze_And_Resolve
(High
, Any_Real
);
8996 Check_Real_Bound
(Low
);
8997 Check_Real_Bound
(High
);
8998 Low_Val
:= Expr_Value_R
(Low
);
8999 High_Val
:= Expr_Value_R
(High
);
9001 if Low_Val
< (-Bound_Val
) then
9003 ("range low bound too small for digits value", Low
);
9004 Low_Val
:= -Bound_Val
;
9007 if High_Val
> Bound_Val
then
9009 ("range high bound too large for digits value", High
);
9010 High_Val
:= Bound_Val
;
9013 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
9016 -- If no explicit range, use range that corresponds to given
9017 -- digits value. This will end up as the final range for the
9021 Set_Fixed_Range
(T
, Loc
, -Bound_Val
, Bound_Val
);
9024 -- Complete entity for first subtype
9026 Set_Ekind
(T
, E_Decimal_Fixed_Point_Subtype
);
9027 Set_Etype
(T
, Implicit_Base
);
9028 Set_Size_Info
(T
, Implicit_Base
);
9029 Set_First_Rep_Item
(T
, First_Rep_Item
(Implicit_Base
));
9030 Set_Digits_Value
(T
, Digs_Val
);
9031 Set_Delta_Value
(T
, Delta_Val
);
9032 Set_Small_Value
(T
, Delta_Val
);
9033 Set_Scale_Value
(T
, Scale_Val
);
9034 Set_Is_Constrained
(T
);
9035 end Decimal_Fixed_Point_Type_Declaration
;
9037 -----------------------
9038 -- Derive_Subprogram --
9039 -----------------------
9041 procedure Derive_Subprogram
9042 (New_Subp
: in out Entity_Id
;
9043 Parent_Subp
: Entity_Id
;
9044 Derived_Type
: Entity_Id
;
9045 Parent_Type
: Entity_Id
;
9046 Actual_Subp
: Entity_Id
:= Empty
)
9049 New_Formal
: Entity_Id
;
9050 Visible_Subp
: Entity_Id
:= Parent_Subp
;
9052 function Is_Private_Overriding
return Boolean;
9053 -- If Subp is a private overriding of a visible operation, the in-
9054 -- herited operation derives from the overridden op (even though
9055 -- its body is the overriding one) and the inherited operation is
9056 -- visible now. See sem_disp to see the details of the handling of
9057 -- the overridden subprogram, which is removed from the list of
9058 -- primitive operations of the type. The overridden subprogram is
9059 -- saved locally in Visible_Subp, and used to diagnose abstract
9060 -- operations that need overriding in the derived type.
9062 procedure Replace_Type
(Id
, New_Id
: Entity_Id
);
9063 -- When the type is an anonymous access type, create a new access type
9064 -- designating the derived type.
9066 procedure Set_Derived_Name
;
9067 -- This procedure sets the appropriate Chars name for New_Subp. This
9068 -- is normally just a copy of the parent name. An exception arises for
9069 -- type support subprograms, where the name is changed to reflect the
9070 -- name of the derived type, e.g. if type foo is derived from type bar,
9071 -- then a procedure barDA is derived with a name fooDA.
9073 ---------------------------
9074 -- Is_Private_Overriding --
9075 ---------------------------
9077 function Is_Private_Overriding
return Boolean is
9081 -- The visible operation that is overriden is a homonym of the
9082 -- parent subprogram. We scan the homonym chain to find the one
9083 -- whose alias is the subprogram we are deriving.
9085 Prev
:= Homonym
(Parent_Subp
);
9086 while Present
(Prev
) loop
9087 if Is_Dispatching_Operation
(Parent_Subp
)
9088 and then Present
(Prev
)
9089 and then Ekind
(Prev
) = Ekind
(Parent_Subp
)
9090 and then Alias
(Prev
) = Parent_Subp
9091 and then Scope
(Parent_Subp
) = Scope
(Prev
)
9092 and then not Is_Hidden
(Prev
)
9094 Visible_Subp
:= Prev
;
9098 Prev
:= Homonym
(Prev
);
9102 end Is_Private_Overriding
;
9108 procedure Replace_Type
(Id
, New_Id
: Entity_Id
) is
9109 Acc_Type
: Entity_Id
;
9111 Par
: constant Node_Id
:= Parent
(Derived_Type
);
9114 -- When the type is an anonymous access type, create a new access
9115 -- type designating the derived type. This itype must be elaborated
9116 -- at the point of the derivation, not on subsequent calls that may
9117 -- be out of the proper scope for Gigi, so we insert a reference to
9118 -- it after the derivation.
9120 if Ekind
(Etype
(Id
)) = E_Anonymous_Access_Type
then
9122 Desig_Typ
: Entity_Id
:= Designated_Type
(Etype
(Id
));
9125 if Ekind
(Desig_Typ
) = E_Record_Type_With_Private
9126 and then Present
(Full_View
(Desig_Typ
))
9127 and then not Is_Private_Type
(Parent_Type
)
9129 Desig_Typ
:= Full_View
(Desig_Typ
);
9132 if Base_Type
(Desig_Typ
) = Base_Type
(Parent_Type
) then
9133 Acc_Type
:= New_Copy
(Etype
(Id
));
9134 Set_Etype
(Acc_Type
, Acc_Type
);
9135 Set_Scope
(Acc_Type
, New_Subp
);
9137 -- Compute size of anonymous access type
9139 if Is_Array_Type
(Desig_Typ
)
9140 and then not Is_Constrained
(Desig_Typ
)
9142 Init_Size
(Acc_Type
, 2 * System_Address_Size
);
9144 Init_Size
(Acc_Type
, System_Address_Size
);
9147 Init_Alignment
(Acc_Type
);
9148 Set_Directly_Designated_Type
(Acc_Type
, Derived_Type
);
9150 Set_Etype
(New_Id
, Acc_Type
);
9151 Set_Scope
(New_Id
, New_Subp
);
9153 -- Create a reference to it
9155 IR
:= Make_Itype_Reference
(Sloc
(Parent
(Derived_Type
)));
9156 Set_Itype
(IR
, Acc_Type
);
9157 Insert_After
(Parent
(Derived_Type
), IR
);
9160 Set_Etype
(New_Id
, Etype
(Id
));
9164 elsif Base_Type
(Etype
(Id
)) = Base_Type
(Parent_Type
)
9166 (Ekind
(Etype
(Id
)) = E_Record_Type_With_Private
9167 and then Present
(Full_View
(Etype
(Id
)))
9169 Base_Type
(Full_View
(Etype
(Id
))) = Base_Type
(Parent_Type
))
9171 -- Constraint checks on formals are generated during expansion,
9172 -- based on the signature of the original subprogram. The bounds
9173 -- of the derived type are not relevant, and thus we can use
9174 -- the base type for the formals. However, the return type may be
9175 -- used in a context that requires that the proper static bounds
9176 -- be used (a case statement, for example) and for those cases
9177 -- we must use the derived type (first subtype), not its base.
9179 -- If the derived_type_definition has no constraints, we know that
9180 -- the derived type has the same constraints as the first subtype
9181 -- of the parent, and we can also use it rather than its base,
9182 -- which can lead to more efficient code.
9184 if Etype
(Id
) = Parent_Type
then
9185 if Is_Scalar_Type
(Parent_Type
)
9187 Subtypes_Statically_Compatible
(Parent_Type
, Derived_Type
)
9189 Set_Etype
(New_Id
, Derived_Type
);
9191 elsif Nkind
(Par
) = N_Full_Type_Declaration
9193 Nkind
(Type_Definition
(Par
)) = N_Derived_Type_Definition
9196 (Subtype_Indication
(Type_Definition
(Par
)))
9198 Set_Etype
(New_Id
, Derived_Type
);
9201 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
9205 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
9209 Set_Etype
(New_Id
, Etype
(Id
));
9213 ----------------------
9214 -- Set_Derived_Name --
9215 ----------------------
9217 procedure Set_Derived_Name
is
9218 Nm
: constant TSS_Name_Type
:= Get_TSS_Name
(Parent_Subp
);
9220 if Nm
= TSS_Null
then
9221 Set_Chars
(New_Subp
, Chars
(Parent_Subp
));
9223 Set_Chars
(New_Subp
, Make_TSS_Name
(Base_Type
(Derived_Type
), Nm
));
9225 end Set_Derived_Name
;
9227 -- Start of processing for Derive_Subprogram
9231 New_Entity
(Nkind
(Parent_Subp
), Sloc
(Derived_Type
));
9232 Set_Ekind
(New_Subp
, Ekind
(Parent_Subp
));
9234 -- Check whether the inherited subprogram is a private operation that
9235 -- should be inherited but not yet made visible. Such subprograms can
9236 -- become visible at a later point (e.g., the private part of a public
9237 -- child unit) via Declare_Inherited_Private_Subprograms. If the
9238 -- following predicate is true, then this is not such a private
9239 -- operation and the subprogram simply inherits the name of the parent
9240 -- subprogram. Note the special check for the names of controlled
9241 -- operations, which are currently exempted from being inherited with
9242 -- a hidden name because they must be findable for generation of
9243 -- implicit run-time calls.
9245 if not Is_Hidden
(Parent_Subp
)
9246 or else Is_Internal
(Parent_Subp
)
9247 or else Is_Private_Overriding
9248 or else Is_Internal_Name
(Chars
(Parent_Subp
))
9249 or else Chars
(Parent_Subp
) = Name_Initialize
9250 or else Chars
(Parent_Subp
) = Name_Adjust
9251 or else Chars
(Parent_Subp
) = Name_Finalize
9255 -- If parent is hidden, this can be a regular derivation if the
9256 -- parent is immediately visible in a non-instantiating context,
9257 -- or if we are in the private part of an instance. This test
9258 -- should still be refined ???
9260 -- The test for In_Instance_Not_Visible avoids inheriting the derived
9261 -- operation as a non-visible operation in cases where the parent
9262 -- subprogram might not be visible now, but was visible within the
9263 -- original generic, so it would be wrong to make the inherited
9264 -- subprogram non-visible now. (Not clear if this test is fully
9265 -- correct; are there any cases where we should declare the inherited
9266 -- operation as not visible to avoid it being overridden, e.g., when
9267 -- the parent type is a generic actual with private primitives ???)
9269 -- (they should be treated the same as other private inherited
9270 -- subprograms, but it's not clear how to do this cleanly). ???
9272 elsif (In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
9273 and then Is_Immediately_Visible
(Parent_Subp
)
9274 and then not In_Instance
)
9275 or else In_Instance_Not_Visible
9279 -- The type is inheriting a private operation, so enter
9280 -- it with a special name so it can't be overridden.
9283 Set_Chars
(New_Subp
, New_External_Name
(Chars
(Parent_Subp
), 'P'));
9286 Set_Parent
(New_Subp
, Parent
(Derived_Type
));
9287 Replace_Type
(Parent_Subp
, New_Subp
);
9288 Conditional_Delay
(New_Subp
, Parent_Subp
);
9290 Formal
:= First_Formal
(Parent_Subp
);
9291 while Present
(Formal
) loop
9292 New_Formal
:= New_Copy
(Formal
);
9294 -- Normally we do not go copying parents, but in the case of
9295 -- formals, we need to link up to the declaration (which is the
9296 -- parameter specification), and it is fine to link up to the
9297 -- original formal's parameter specification in this case.
9299 Set_Parent
(New_Formal
, Parent
(Formal
));
9301 Append_Entity
(New_Formal
, New_Subp
);
9303 Replace_Type
(Formal
, New_Formal
);
9304 Next_Formal
(Formal
);
9307 -- If this derivation corresponds to a tagged generic actual, then
9308 -- primitive operations rename those of the actual. Otherwise the
9309 -- primitive operations rename those of the parent type, If the
9310 -- parent renames an intrinsic operator, so does the new subprogram.
9311 -- We except concatenation, which is always properly typed, and does
9312 -- not get expanded as other intrinsic operations.
9314 if No
(Actual_Subp
) then
9315 if Is_Intrinsic_Subprogram
(Parent_Subp
) then
9316 Set_Is_Intrinsic_Subprogram
(New_Subp
);
9318 if Present
(Alias
(Parent_Subp
))
9319 and then Chars
(Parent_Subp
) /= Name_Op_Concat
9321 Set_Alias
(New_Subp
, Alias
(Parent_Subp
));
9323 Set_Alias
(New_Subp
, Parent_Subp
);
9327 Set_Alias
(New_Subp
, Parent_Subp
);
9331 Set_Alias
(New_Subp
, Actual_Subp
);
9334 -- Derived subprograms of a tagged type must inherit the convention
9335 -- of the parent subprogram (a requirement of AI-117). Derived
9336 -- subprograms of untagged types simply get convention Ada by default.
9338 if Is_Tagged_Type
(Derived_Type
) then
9339 Set_Convention
(New_Subp
, Convention
(Parent_Subp
));
9342 Set_Is_Imported
(New_Subp
, Is_Imported
(Parent_Subp
));
9343 Set_Is_Exported
(New_Subp
, Is_Exported
(Parent_Subp
));
9345 if Ekind
(Parent_Subp
) = E_Procedure
then
9346 Set_Is_Valued_Procedure
9347 (New_Subp
, Is_Valued_Procedure
(Parent_Subp
));
9350 -- A derived function with a controlling result is abstract. If the
9351 -- Derived_Type is a nonabstract formal generic derived type, then
9352 -- inherited operations are not abstract: the required check is done at
9353 -- instantiation time. If the derivation is for a generic actual, the
9354 -- function is not abstract unless the actual is.
9356 if Is_Generic_Type
(Derived_Type
)
9357 and then not Is_Abstract
(Derived_Type
)
9361 elsif Is_Abstract
(Alias
(New_Subp
))
9362 or else (Is_Tagged_Type
(Derived_Type
)
9363 and then Etype
(New_Subp
) = Derived_Type
9364 and then No
(Actual_Subp
))
9366 Set_Is_Abstract
(New_Subp
);
9368 -- Finally, if the parent type is abstract we must verify that all
9369 -- inherited operations are either non-abstract or overridden, or
9370 -- that the derived type itself is abstract (this check is performed
9371 -- at the end of a package declaration, in Check_Abstract_Overriding).
9372 -- A private overriding in the parent type will not be visible in the
9373 -- derivation if we are not in an inner package or in a child unit of
9374 -- the parent type, in which case the abstractness of the inherited
9375 -- operation is carried to the new subprogram.
9377 elsif Is_Abstract
(Parent_Type
)
9378 and then not In_Open_Scopes
(Scope
(Parent_Type
))
9379 and then Is_Private_Overriding
9380 and then Is_Abstract
(Visible_Subp
)
9382 Set_Alias
(New_Subp
, Visible_Subp
);
9383 Set_Is_Abstract
(New_Subp
);
9386 New_Overloaded_Entity
(New_Subp
, Derived_Type
);
9388 -- Check for case of a derived subprogram for the instantiation of a
9389 -- formal derived tagged type, if so mark the subprogram as dispatching
9390 -- and inherit the dispatching attributes of the parent subprogram. The
9391 -- derived subprogram is effectively renaming of the actual subprogram,
9392 -- so it needs to have the same attributes as the actual.
9394 if Present
(Actual_Subp
)
9395 and then Is_Dispatching_Operation
(Parent_Subp
)
9397 Set_Is_Dispatching_Operation
(New_Subp
);
9398 if Present
(DTC_Entity
(Parent_Subp
)) then
9399 Set_DTC_Entity
(New_Subp
, DTC_Entity
(Parent_Subp
));
9400 Set_DT_Position
(New_Subp
, DT_Position
(Parent_Subp
));
9404 -- Indicate that a derived subprogram does not require a body and that
9405 -- it does not require processing of default expressions.
9407 Set_Has_Completion
(New_Subp
);
9408 Set_Default_Expressions_Processed
(New_Subp
);
9410 if Ekind
(New_Subp
) = E_Function
then
9411 Set_Mechanism
(New_Subp
, Mechanism
(Parent_Subp
));
9413 end Derive_Subprogram
;
9415 ------------------------
9416 -- Derive_Subprograms --
9417 ------------------------
9419 procedure Derive_Subprograms
9420 (Parent_Type
: Entity_Id
;
9421 Derived_Type
: Entity_Id
;
9422 Generic_Actual
: Entity_Id
:= Empty
)
9424 Op_List
: constant Elist_Id
:=
9425 Collect_Primitive_Operations
(Parent_Type
);
9426 Act_List
: Elist_Id
;
9430 New_Subp
: Entity_Id
:= Empty
;
9431 Parent_Base
: Entity_Id
;
9434 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
9435 and then Has_Discriminants
(Parent_Type
)
9436 and then Present
(Full_View
(Parent_Type
))
9438 Parent_Base
:= Full_View
(Parent_Type
);
9440 Parent_Base
:= Parent_Type
;
9443 if Present
(Generic_Actual
) then
9444 Act_List
:= Collect_Primitive_Operations
(Generic_Actual
);
9445 Act_Elmt
:= First_Elmt
(Act_List
);
9447 Act_Elmt
:= No_Elmt
;
9450 -- Literals are derived earlier in the process of building the derived
9451 -- type, and are skipped here.
9453 Elmt
:= First_Elmt
(Op_List
);
9454 while Present
(Elmt
) loop
9455 Subp
:= Node
(Elmt
);
9457 if Ekind
(Subp
) /= E_Enumeration_Literal
then
9458 if No
(Generic_Actual
) then
9460 (New_Subp
, Subp
, Derived_Type
, Parent_Base
);
9463 Derive_Subprogram
(New_Subp
, Subp
,
9464 Derived_Type
, Parent_Base
, Node
(Act_Elmt
));
9465 Next_Elmt
(Act_Elmt
);
9471 end Derive_Subprograms
;
9473 --------------------------------
9474 -- Derived_Standard_Character --
9475 --------------------------------
9477 procedure Derived_Standard_Character
9479 Parent_Type
: Entity_Id
;
9480 Derived_Type
: Entity_Id
)
9482 Loc
: constant Source_Ptr
:= Sloc
(N
);
9483 Def
: constant Node_Id
:= Type_Definition
(N
);
9484 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
9485 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
9486 Implicit_Base
: constant Entity_Id
:=
9488 (E_Enumeration_Type
, N
, Derived_Type
, 'B');
9494 Discard_Node
(Process_Subtype
(Indic
, N
));
9496 Set_Etype
(Implicit_Base
, Parent_Base
);
9497 Set_Size_Info
(Implicit_Base
, Root_Type
(Parent_Type
));
9498 Set_RM_Size
(Implicit_Base
, RM_Size
(Root_Type
(Parent_Type
)));
9500 Set_Is_Character_Type
(Implicit_Base
, True);
9501 Set_Has_Delayed_Freeze
(Implicit_Base
);
9503 -- The bounds of the implicit base are the bounds of the parent base.
9504 -- Note that their type is the parent base.
9506 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
9507 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
9509 Set_Scalar_Range
(Implicit_Base
,
9514 Conditional_Delay
(Derived_Type
, Parent_Type
);
9516 Set_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
9517 Set_Etype
(Derived_Type
, Implicit_Base
);
9518 Set_Size_Info
(Derived_Type
, Parent_Type
);
9520 if Unknown_RM_Size
(Derived_Type
) then
9521 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
9524 Set_Is_Character_Type
(Derived_Type
, True);
9526 if Nkind
(Indic
) /= N_Subtype_Indication
then
9528 -- If no explicit constraint, the bounds are those
9529 -- of the parent type.
9531 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Type
));
9532 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Type
));
9533 Set_Scalar_Range
(Derived_Type
, Make_Range
(Loc
, Lo
, Hi
));
9536 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
9538 -- Because the implicit base is used in the conversion of the bounds,
9539 -- we have to freeze it now. This is similar to what is done for
9540 -- numeric types, and it equally suspicious, but otherwise a non-
9541 -- static bound will have a reference to an unfrozen type, which is
9542 -- rejected by Gigi (???).
9544 Freeze_Before
(N
, Implicit_Base
);
9545 end Derived_Standard_Character
;
9547 ------------------------------
9548 -- Derived_Type_Declaration --
9549 ------------------------------
9551 procedure Derived_Type_Declaration
9554 Is_Completion
: Boolean)
9556 Def
: constant Node_Id
:= Type_Definition
(N
);
9557 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
9558 Extension
: constant Node_Id
:= Record_Extension_Part
(Def
);
9559 Parent_Type
: Entity_Id
;
9560 Parent_Scope
: Entity_Id
;
9564 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
9566 if Parent_Type
= Any_Type
9567 or else Etype
(Parent_Type
) = Any_Type
9568 or else (Is_Class_Wide_Type
(Parent_Type
)
9569 and then Etype
(Parent_Type
) = T
)
9571 -- If Parent_Type is undefined or illegal, make new type into a
9572 -- subtype of Any_Type, and set a few attributes to prevent cascaded
9573 -- errors. If this is a self-definition, emit error now.
9576 or else T
= Etype
(Parent_Type
)
9578 Error_Msg_N
("type cannot be used in its own definition", Indic
);
9581 Set_Ekind
(T
, Ekind
(Parent_Type
));
9582 Set_Etype
(T
, Any_Type
);
9583 Set_Scalar_Range
(T
, Scalar_Range
(Any_Type
));
9585 if Is_Tagged_Type
(T
) then
9586 Set_Primitive_Operations
(T
, New_Elmt_List
);
9591 -- Ada 2005 (AI-231): Static check
9593 elsif Is_Access_Type
(Parent_Type
)
9594 and then Null_Exclusion_Present
(Type_Definition
(N
))
9595 and then Can_Never_Be_Null
(Parent_Type
)
9597 Error_Msg_N
("(Ada 2005) null exclusion not allowed if parent is "
9598 & "already non-null", Type_Definition
(N
));
9601 -- Only composite types other than array types are allowed to have
9604 if Present
(Discriminant_Specifications
(N
))
9605 and then (Is_Elementary_Type
(Parent_Type
)
9606 or else Is_Array_Type
(Parent_Type
))
9607 and then not Error_Posted
(N
)
9610 ("elementary or array type cannot have discriminants",
9611 Defining_Identifier
(First
(Discriminant_Specifications
(N
))));
9612 Set_Has_Discriminants
(T
, False);
9615 -- In Ada 83, a derived type defined in a package specification cannot
9616 -- be used for further derivation until the end of its visible part.
9617 -- Note that derivation in the private part of the package is allowed.
9619 if Ada_Version
= Ada_83
9620 and then Is_Derived_Type
(Parent_Type
)
9621 and then In_Visible_Part
(Scope
(Parent_Type
))
9623 if Ada_Version
= Ada_83
and then Comes_From_Source
(Indic
) then
9625 ("(Ada 83): premature use of type for derivation", Indic
);
9629 -- Check for early use of incomplete or private type
9631 if Ekind
(Parent_Type
) = E_Void
9632 or else Ekind
(Parent_Type
) = E_Incomplete_Type
9634 Error_Msg_N
("premature derivation of incomplete type", Indic
);
9637 elsif (Is_Incomplete_Or_Private_Type
(Parent_Type
)
9638 and then not Is_Generic_Type
(Parent_Type
)
9639 and then not Is_Generic_Type
(Root_Type
(Parent_Type
))
9640 and then not Is_Generic_Actual_Type
(Parent_Type
))
9641 or else Has_Private_Component
(Parent_Type
)
9643 -- The ancestor type of a formal type can be incomplete, in which
9644 -- case only the operations of the partial view are available in
9645 -- the generic. Subsequent checks may be required when the full
9646 -- view is analyzed, to verify that derivation from a tagged type
9647 -- has an extension.
9649 if Nkind
(Original_Node
(N
)) = N_Formal_Type_Declaration
then
9652 elsif No
(Underlying_Type
(Parent_Type
))
9653 or else Has_Private_Component
(Parent_Type
)
9656 ("premature derivation of derived or private type", Indic
);
9658 -- Flag the type itself as being in error, this prevents some
9659 -- nasty problems with people looking at the malformed type.
9661 Set_Error_Posted
(T
);
9663 -- Check that within the immediate scope of an untagged partial
9664 -- view it's illegal to derive from the partial view if the
9665 -- full view is tagged. (7.3(7))
9667 -- We verify that the Parent_Type is a partial view by checking
9668 -- that it is not a Full_Type_Declaration (i.e. a private type or
9669 -- private extension declaration), to distinguish a partial view
9670 -- from a derivation from a private type which also appears as
9673 elsif Present
(Full_View
(Parent_Type
))
9674 and then Nkind
(Parent
(Parent_Type
)) /= N_Full_Type_Declaration
9675 and then not Is_Tagged_Type
(Parent_Type
)
9676 and then Is_Tagged_Type
(Full_View
(Parent_Type
))
9678 Parent_Scope
:= Scope
(T
);
9679 while Present
(Parent_Scope
)
9680 and then Parent_Scope
/= Standard_Standard
9682 if Parent_Scope
= Scope
(Parent_Type
) then
9684 ("premature derivation from type with tagged full view",
9688 Parent_Scope
:= Scope
(Parent_Scope
);
9693 -- Check that form of derivation is appropriate
9695 Taggd
:= Is_Tagged_Type
(Parent_Type
);
9697 -- Perhaps the parent type should be changed to the class-wide type's
9698 -- specific type in this case to prevent cascading errors ???
9700 if Present
(Extension
) and then Is_Class_Wide_Type
(Parent_Type
) then
9701 Error_Msg_N
("parent type must not be a class-wide type", Indic
);
9705 if Present
(Extension
) and then not Taggd
then
9707 ("type derived from untagged type cannot have extension", Indic
);
9709 elsif No
(Extension
) and then Taggd
then
9711 -- If this declaration is within a private part (or body) of a
9712 -- generic instantiation then the derivation is allowed (the parent
9713 -- type can only appear tagged in this case if it's a generic actual
9714 -- type, since it would otherwise have been rejected in the analysis
9715 -- of the generic template).
9717 if not Is_Generic_Actual_Type
(Parent_Type
)
9718 or else In_Visible_Part
(Scope
(Parent_Type
))
9721 ("type derived from tagged type must have extension", Indic
);
9725 Build_Derived_Type
(N
, Parent_Type
, T
, Is_Completion
);
9726 end Derived_Type_Declaration
;
9728 ----------------------------------
9729 -- Enumeration_Type_Declaration --
9730 ----------------------------------
9732 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
9739 -- Create identifier node representing lower bound
9741 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
9742 L
:= First
(Literals
(Def
));
9743 Set_Chars
(B_Node
, Chars
(L
));
9744 Set_Entity
(B_Node
, L
);
9745 Set_Etype
(B_Node
, T
);
9746 Set_Is_Static_Expression
(B_Node
, True);
9748 R_Node
:= New_Node
(N_Range
, Sloc
(Def
));
9749 Set_Low_Bound
(R_Node
, B_Node
);
9751 Set_Ekind
(T
, E_Enumeration_Type
);
9752 Set_First_Literal
(T
, L
);
9754 Set_Is_Constrained
(T
);
9758 -- Loop through literals of enumeration type setting pos and rep values
9759 -- except that if the Ekind is already set, then it means that the
9760 -- literal was already constructed (case of a derived type declaration
9761 -- and we should not disturb the Pos and Rep values.
9763 while Present
(L
) loop
9764 if Ekind
(L
) /= E_Enumeration_Literal
then
9765 Set_Ekind
(L
, E_Enumeration_Literal
);
9766 Set_Enumeration_Pos
(L
, Ev
);
9767 Set_Enumeration_Rep
(L
, Ev
);
9768 Set_Is_Known_Valid
(L
, True);
9772 New_Overloaded_Entity
(L
);
9773 Generate_Definition
(L
);
9774 Set_Convention
(L
, Convention_Intrinsic
);
9776 if Nkind
(L
) = N_Defining_Character_Literal
then
9777 Set_Is_Character_Type
(T
, True);
9784 -- Now create a node representing upper bound
9786 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
9787 Set_Chars
(B_Node
, Chars
(Last
(Literals
(Def
))));
9788 Set_Entity
(B_Node
, Last
(Literals
(Def
)));
9789 Set_Etype
(B_Node
, T
);
9790 Set_Is_Static_Expression
(B_Node
, True);
9792 Set_High_Bound
(R_Node
, B_Node
);
9793 Set_Scalar_Range
(T
, R_Node
);
9794 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
9797 -- Set Discard_Names if configuration pragma set, or if there is
9798 -- a parameterless pragma in the current declarative region
9800 if Global_Discard_Names
9801 or else Discard_Names
(Scope
(T
))
9803 Set_Discard_Names
(T
);
9806 -- Process end label if there is one
9808 if Present
(Def
) then
9809 Process_End_Label
(Def
, 'e', T
);
9811 end Enumeration_Type_Declaration
;
9813 ---------------------------------
9814 -- Expand_To_Stored_Constraint --
9815 ---------------------------------
9817 function Expand_To_Stored_Constraint
9819 Constraint
: Elist_Id
) return Elist_Id
9821 Explicitly_Discriminated_Type
: Entity_Id
;
9822 Expansion
: Elist_Id
;
9823 Discriminant
: Entity_Id
;
9825 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
;
9826 -- Find the nearest type that actually specifies discriminants
9828 ---------------------------------
9829 -- Type_With_Explicit_Discrims --
9830 ---------------------------------
9832 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
is
9833 Typ
: constant E
:= Base_Type
(Id
);
9836 if Ekind
(Typ
) in Incomplete_Or_Private_Kind
then
9837 if Present
(Full_View
(Typ
)) then
9838 return Type_With_Explicit_Discrims
(Full_View
(Typ
));
9842 if Has_Discriminants
(Typ
) then
9847 if Etype
(Typ
) = Typ
then
9849 elsif Has_Discriminants
(Typ
) then
9852 return Type_With_Explicit_Discrims
(Etype
(Typ
));
9855 end Type_With_Explicit_Discrims
;
9857 -- Start of processing for Expand_To_Stored_Constraint
9861 or else Is_Empty_Elmt_List
(Constraint
)
9866 Explicitly_Discriminated_Type
:= Type_With_Explicit_Discrims
(Typ
);
9868 if No
(Explicitly_Discriminated_Type
) then
9872 Expansion
:= New_Elmt_List
;
9875 First_Stored_Discriminant
(Explicitly_Discriminated_Type
);
9876 while Present
(Discriminant
) loop
9878 Get_Discriminant_Value
(
9879 Discriminant
, Explicitly_Discriminated_Type
, Constraint
),
9881 Next_Stored_Discriminant
(Discriminant
);
9885 end Expand_To_Stored_Constraint
;
9887 --------------------
9888 -- Find_Type_Name --
9889 --------------------
9891 function Find_Type_Name
(N
: Node_Id
) return Entity_Id
is
9892 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
9898 -- Find incomplete declaration, if one was given
9900 Prev
:= Current_Entity_In_Scope
(Id
);
9902 if Present
(Prev
) then
9904 -- Previous declaration exists. Error if not incomplete/private case
9905 -- except if previous declaration is implicit, etc. Enter_Name will
9906 -- emit error if appropriate.
9908 Prev_Par
:= Parent
(Prev
);
9910 if not Is_Incomplete_Or_Private_Type
(Prev
) then
9914 elsif Nkind
(N
) /= N_Full_Type_Declaration
9915 and then Nkind
(N
) /= N_Task_Type_Declaration
9916 and then Nkind
(N
) /= N_Protected_Type_Declaration
9918 -- Completion must be a full type declarations (RM 7.3(4))
9920 Error_Msg_Sloc
:= Sloc
(Prev
);
9921 Error_Msg_NE
("invalid completion of }", Id
, Prev
);
9923 -- Set scope of Id to avoid cascaded errors. Entity is never
9924 -- examined again, except when saving globals in generics.
9926 Set_Scope
(Id
, Current_Scope
);
9929 -- Case of full declaration of incomplete type
9931 elsif Ekind
(Prev
) = E_Incomplete_Type
then
9933 -- Indicate that the incomplete declaration has a matching full
9934 -- declaration. The defining occurrence of the incomplete
9935 -- declaration remains the visible one, and the procedure
9936 -- Get_Full_View dereferences it whenever the type is used.
9938 if Present
(Full_View
(Prev
)) then
9939 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
9942 Set_Full_View
(Prev
, Id
);
9943 Append_Entity
(Id
, Current_Scope
);
9944 Set_Is_Public
(Id
, Is_Public
(Prev
));
9945 Set_Is_Internal
(Id
);
9948 -- Case of full declaration of private type
9951 if Nkind
(Parent
(Prev
)) /= N_Private_Extension_Declaration
then
9952 if Etype
(Prev
) /= Prev
then
9954 -- Prev is a private subtype or a derived type, and needs
9957 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
9960 elsif Ekind
(Prev
) = E_Private_Type
9962 (Nkind
(N
) = N_Task_Type_Declaration
9963 or else Nkind
(N
) = N_Protected_Type_Declaration
)
9966 ("completion of nonlimited type cannot be limited", N
);
9969 elsif Nkind
(N
) /= N_Full_Type_Declaration
9970 or else Nkind
(Type_Definition
(N
)) /= N_Derived_Type_Definition
9973 ("full view of private extension must be an extension", N
);
9975 elsif not (Abstract_Present
(Parent
(Prev
)))
9976 and then Abstract_Present
(Type_Definition
(N
))
9979 ("full view of non-abstract extension cannot be abstract", N
);
9982 if not In_Private_Part
(Current_Scope
) then
9984 ("declaration of full view must appear in private part", N
);
9987 Copy_And_Swap
(Prev
, Id
);
9988 Set_Has_Private_Declaration
(Prev
);
9989 Set_Has_Private_Declaration
(Id
);
9991 -- If no error, propagate freeze_node from private to full view.
9992 -- It may have been generated for an early operational item.
9994 if Present
(Freeze_Node
(Id
))
9995 and then Serious_Errors_Detected
= 0
9996 and then No
(Full_View
(Id
))
9998 Set_Freeze_Node
(Prev
, Freeze_Node
(Id
));
9999 Set_Freeze_Node
(Id
, Empty
);
10000 Set_First_Rep_Item
(Prev
, First_Rep_Item
(Id
));
10003 Set_Full_View
(Id
, Prev
);
10007 -- Verify that full declaration conforms to incomplete one
10009 if Is_Incomplete_Or_Private_Type
(Prev
)
10010 and then Present
(Discriminant_Specifications
(Prev_Par
))
10012 if Present
(Discriminant_Specifications
(N
)) then
10013 if Ekind
(Prev
) = E_Incomplete_Type
then
10014 Check_Discriminant_Conformance
(N
, Prev
, Prev
);
10016 Check_Discriminant_Conformance
(N
, Prev
, Id
);
10021 ("missing discriminants in full type declaration", N
);
10023 -- To avoid cascaded errors on subsequent use, share the
10024 -- discriminants of the partial view.
10026 Set_Discriminant_Specifications
(N
,
10027 Discriminant_Specifications
(Prev_Par
));
10031 -- A prior untagged private type can have an associated class-wide
10032 -- type due to use of the class attribute, and in this case also the
10033 -- full type is required to be tagged.
10036 and then (Is_Tagged_Type
(Prev
)
10037 or else Present
(Class_Wide_Type
(Prev
)))
10039 -- The full declaration is either a tagged record or an
10040 -- extension otherwise this is an error
10042 if Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
10043 if not Tagged_Present
(Type_Definition
(N
)) then
10045 ("full declaration of } must be tagged", Prev
, Id
);
10046 Set_Is_Tagged_Type
(Id
);
10047 Set_Primitive_Operations
(Id
, New_Elmt_List
);
10050 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
10051 if No
(Record_Extension_Part
(Type_Definition
(N
))) then
10053 "full declaration of } must be a record extension",
10055 Set_Is_Tagged_Type
(Id
);
10056 Set_Primitive_Operations
(Id
, New_Elmt_List
);
10061 ("full declaration of } must be a tagged type", Prev
, Id
);
10069 -- New type declaration
10074 end Find_Type_Name
;
10076 -------------------------
10077 -- Find_Type_Of_Object --
10078 -------------------------
10080 function Find_Type_Of_Object
10081 (Obj_Def
: Node_Id
;
10082 Related_Nod
: Node_Id
) return Entity_Id
10084 Def_Kind
: constant Node_Kind
:= Nkind
(Obj_Def
);
10085 P
: Node_Id
:= Parent
(Obj_Def
);
10090 -- If the parent is a component_definition node we climb to the
10091 -- component_declaration node
10093 if Nkind
(P
) = N_Component_Definition
then
10097 -- Case of an anonymous array subtype
10099 if Def_Kind
= N_Constrained_Array_Definition
10100 or else Def_Kind
= N_Unconstrained_Array_Definition
10103 Array_Type_Declaration
(T
, Obj_Def
);
10105 -- Create an explicit subtype whenever possible
10107 elsif Nkind
(P
) /= N_Component_Declaration
10108 and then Def_Kind
= N_Subtype_Indication
10110 -- Base name of subtype on object name, which will be unique in
10111 -- the current scope.
10113 -- If this is a duplicate declaration, return base type, to avoid
10114 -- generating duplicate anonymous types.
10116 if Error_Posted
(P
) then
10117 Analyze
(Subtype_Mark
(Obj_Def
));
10118 return Entity
(Subtype_Mark
(Obj_Def
));
10123 (Chars
(Defining_Identifier
(Related_Nod
)), 'S', 0, 'T');
10125 T
:= Make_Defining_Identifier
(Sloc
(P
), Nam
);
10127 Insert_Action
(Obj_Def
,
10128 Make_Subtype_Declaration
(Sloc
(P
),
10129 Defining_Identifier
=> T
,
10130 Subtype_Indication
=> Relocate_Node
(Obj_Def
)));
10132 -- This subtype may need freezing, and this will not be done
10133 -- automatically if the object declaration is not in declarative
10134 -- part. Since this is an object declaration, the type cannot always
10135 -- be frozen here. Deferred constants do not freeze their type
10136 -- (which often enough will be private).
10138 if Nkind
(P
) = N_Object_Declaration
10139 and then Constant_Present
(P
)
10140 and then No
(Expression
(P
))
10145 Insert_Actions
(Obj_Def
, Freeze_Entity
(T
, Sloc
(P
)));
10149 T
:= Process_Subtype
(Obj_Def
, Related_Nod
);
10153 end Find_Type_Of_Object
;
10155 --------------------------------
10156 -- Find_Type_Of_Subtype_Indic --
10157 --------------------------------
10159 function Find_Type_Of_Subtype_Indic
(S
: Node_Id
) return Entity_Id
is
10163 -- Case of subtype mark with a constraint
10165 if Nkind
(S
) = N_Subtype_Indication
then
10166 Find_Type
(Subtype_Mark
(S
));
10167 Typ
:= Entity
(Subtype_Mark
(S
));
10170 Is_Valid_Constraint_Kind
(Ekind
(Typ
), Nkind
(Constraint
(S
)))
10173 ("incorrect constraint for this kind of type", Constraint
(S
));
10174 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
10177 -- Otherwise we have a subtype mark without a constraint
10179 elsif Error_Posted
(S
) then
10180 Rewrite
(S
, New_Occurrence_Of
(Any_Id
, Sloc
(S
)));
10188 if Typ
= Standard_Wide_Character
10189 or else Typ
= Standard_Wide_Wide_Character
10190 or else Typ
= Standard_Wide_String
10191 or else Typ
= Standard_Wide_Wide_String
10193 Check_Restriction
(No_Wide_Characters
, S
);
10197 end Find_Type_Of_Subtype_Indic
;
10199 -------------------------------------
10200 -- Floating_Point_Type_Declaration --
10201 -------------------------------------
10203 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
10204 Digs
: constant Node_Id
:= Digits_Expression
(Def
);
10206 Base_Typ
: Entity_Id
;
10207 Implicit_Base
: Entity_Id
;
10210 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
10211 -- Find if given digits value allows derivation from specified type
10213 ---------------------
10214 -- Can_Derive_From --
10215 ---------------------
10217 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
10218 Spec
: constant Entity_Id
:= Real_Range_Specification
(Def
);
10221 if Digs_Val
> Digits_Value
(E
) then
10225 if Present
(Spec
) then
10226 if Expr_Value_R
(Type_Low_Bound
(E
)) >
10227 Expr_Value_R
(Low_Bound
(Spec
))
10232 if Expr_Value_R
(Type_High_Bound
(E
)) <
10233 Expr_Value_R
(High_Bound
(Spec
))
10240 end Can_Derive_From
;
10242 -- Start of processing for Floating_Point_Type_Declaration
10245 Check_Restriction
(No_Floating_Point
, Def
);
10247 -- Create an implicit base type
10250 Create_Itype
(E_Floating_Point_Type
, Parent
(Def
), T
, 'B');
10252 -- Analyze and verify digits value
10254 Analyze_And_Resolve
(Digs
, Any_Integer
);
10255 Check_Digits_Expression
(Digs
);
10256 Digs_Val
:= Expr_Value
(Digs
);
10258 -- Process possible range spec and find correct type to derive from
10260 Process_Real_Range_Specification
(Def
);
10262 if Can_Derive_From
(Standard_Short_Float
) then
10263 Base_Typ
:= Standard_Short_Float
;
10264 elsif Can_Derive_From
(Standard_Float
) then
10265 Base_Typ
:= Standard_Float
;
10266 elsif Can_Derive_From
(Standard_Long_Float
) then
10267 Base_Typ
:= Standard_Long_Float
;
10268 elsif Can_Derive_From
(Standard_Long_Long_Float
) then
10269 Base_Typ
:= Standard_Long_Long_Float
;
10271 -- If we can't derive from any existing type, use long_long_float
10272 -- and give appropriate message explaining the problem.
10275 Base_Typ
:= Standard_Long_Long_Float
;
10277 if Digs_Val
>= Digits_Value
(Standard_Long_Long_Float
) then
10278 Error_Msg_Uint_1
:= Digits_Value
(Standard_Long_Long_Float
);
10279 Error_Msg_N
("digits value out of range, maximum is ^", Digs
);
10283 ("range too large for any predefined type",
10284 Real_Range_Specification
(Def
));
10288 -- If there are bounds given in the declaration use them as the bounds
10289 -- of the type, otherwise use the bounds of the predefined base type
10290 -- that was chosen based on the Digits value.
10292 if Present
(Real_Range_Specification
(Def
)) then
10293 Set_Scalar_Range
(T
, Real_Range_Specification
(Def
));
10294 Set_Is_Constrained
(T
);
10296 -- The bounds of this range must be converted to machine numbers
10297 -- in accordance with RM 4.9(38).
10299 Bound
:= Type_Low_Bound
(T
);
10301 if Nkind
(Bound
) = N_Real_Literal
then
10303 (Bound
, Machine
(Base_Typ
, Realval
(Bound
), Round
, Bound
));
10304 Set_Is_Machine_Number
(Bound
);
10307 Bound
:= Type_High_Bound
(T
);
10309 if Nkind
(Bound
) = N_Real_Literal
then
10311 (Bound
, Machine
(Base_Typ
, Realval
(Bound
), Round
, Bound
));
10312 Set_Is_Machine_Number
(Bound
);
10316 Set_Scalar_Range
(T
, Scalar_Range
(Base_Typ
));
10319 -- Complete definition of implicit base and declared first subtype
10321 Set_Etype
(Implicit_Base
, Base_Typ
);
10323 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
10324 Set_Size_Info
(Implicit_Base
, (Base_Typ
));
10325 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
10326 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
10327 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Base_Typ
));
10328 Set_Vax_Float
(Implicit_Base
, Vax_Float
(Base_Typ
));
10330 Set_Ekind
(T
, E_Floating_Point_Subtype
);
10331 Set_Etype
(T
, Implicit_Base
);
10333 Set_Size_Info
(T
, (Implicit_Base
));
10334 Set_RM_Size
(T
, RM_Size
(Implicit_Base
));
10335 Set_First_Rep_Item
(T
, First_Rep_Item
(Implicit_Base
));
10336 Set_Digits_Value
(T
, Digs_Val
);
10337 end Floating_Point_Type_Declaration
;
10339 ----------------------------
10340 -- Get_Discriminant_Value --
10341 ----------------------------
10343 -- This is the situation:
10345 -- There is a non-derived type
10347 -- type T0 (Dx, Dy, Dz...)
10349 -- There are zero or more levels of derivation, with each derivation
10350 -- either purely inheriting the discriminants, or defining its own.
10352 -- type Ti is new Ti-1
10354 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
10356 -- subtype Ti is ...
10358 -- The subtype issue is avoided by the use of Original_Record_Component,
10359 -- and the fact that derived subtypes also derive the constraints.
10361 -- This chain leads back from
10363 -- Typ_For_Constraint
10365 -- Typ_For_Constraint has discriminants, and the value for each
10366 -- discriminant is given by its corresponding Elmt of Constraints.
10368 -- Discriminant is some discriminant in this hierarchy
10370 -- We need to return its value
10372 -- We do this by recursively searching each level, and looking for
10373 -- Discriminant. Once we get to the bottom, we start backing up
10374 -- returning the value for it which may in turn be a discriminant
10375 -- further up, so on the backup we continue the substitution.
10377 function Get_Discriminant_Value
10378 (Discriminant
: Entity_Id
;
10379 Typ_For_Constraint
: Entity_Id
;
10380 Constraint
: Elist_Id
) return Node_Id
10382 function Search_Derivation_Levels
10384 Discrim_Values
: Elist_Id
;
10385 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
;
10386 -- This is the routine that performs the recursive search of levels
10387 -- as described above.
10389 ------------------------------
10390 -- Search_Derivation_Levels --
10391 ------------------------------
10393 function Search_Derivation_Levels
10395 Discrim_Values
: Elist_Id
;
10396 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
10400 Result
: Node_Or_Entity_Id
;
10401 Result_Entity
: Node_Id
;
10404 -- If inappropriate type, return Error, this happens only in
10405 -- cascaded error situations, and we want to avoid a blow up.
10407 if not Is_Composite_Type
(Ti
) or else Is_Array_Type
(Ti
) then
10411 -- Look deeper if possible. Use Stored_Constraints only for
10412 -- untagged types. For tagged types use the given constraint.
10413 -- This asymmetry needs explanation???
10415 if not Stored_Discrim_Values
10416 and then Present
(Stored_Constraint
(Ti
))
10417 and then not Is_Tagged_Type
(Ti
)
10420 Search_Derivation_Levels
(Ti
, Stored_Constraint
(Ti
), True);
10423 Td
: constant Entity_Id
:= Etype
(Ti
);
10427 Result
:= Discriminant
;
10430 if Present
(Stored_Constraint
(Ti
)) then
10432 Search_Derivation_Levels
10433 (Td
, Stored_Constraint
(Ti
), True);
10436 Search_Derivation_Levels
10437 (Td
, Discrim_Values
, Stored_Discrim_Values
);
10443 -- Extra underlying places to search, if not found above. For
10444 -- concurrent types, the relevant discriminant appears in the
10445 -- corresponding record. For a type derived from a private type
10446 -- without discriminant, the full view inherits the discriminants
10447 -- of the full view of the parent.
10449 if Result
= Discriminant
then
10450 if Is_Concurrent_Type
(Ti
)
10451 and then Present
(Corresponding_Record_Type
(Ti
))
10454 Search_Derivation_Levels
(
10455 Corresponding_Record_Type
(Ti
),
10457 Stored_Discrim_Values
);
10459 elsif Is_Private_Type
(Ti
)
10460 and then not Has_Discriminants
(Ti
)
10461 and then Present
(Full_View
(Ti
))
10462 and then Etype
(Full_View
(Ti
)) /= Ti
10465 Search_Derivation_Levels
(
10468 Stored_Discrim_Values
);
10472 -- If Result is not a (reference to a) discriminant, return it,
10473 -- otherwise set Result_Entity to the discriminant.
10475 if Nkind
(Result
) = N_Defining_Identifier
then
10476 pragma Assert
(Result
= Discriminant
);
10477 Result_Entity
:= Result
;
10480 if not Denotes_Discriminant
(Result
) then
10484 Result_Entity
:= Entity
(Result
);
10487 -- See if this level of derivation actually has discriminants
10488 -- because tagged derivations can add them, hence the lower
10489 -- levels need not have any.
10491 if not Has_Discriminants
(Ti
) then
10495 -- Scan Ti's discriminants for Result_Entity,
10496 -- and return its corresponding value, if any.
10498 Result_Entity
:= Original_Record_Component
(Result_Entity
);
10500 Assoc
:= First_Elmt
(Discrim_Values
);
10502 if Stored_Discrim_Values
then
10503 Disc
:= First_Stored_Discriminant
(Ti
);
10505 Disc
:= First_Discriminant
(Ti
);
10508 while Present
(Disc
) loop
10509 pragma Assert
(Present
(Assoc
));
10511 if Original_Record_Component
(Disc
) = Result_Entity
then
10512 return Node
(Assoc
);
10517 if Stored_Discrim_Values
then
10518 Next_Stored_Discriminant
(Disc
);
10520 Next_Discriminant
(Disc
);
10524 -- Could not find it
10527 end Search_Derivation_Levels
;
10529 Result
: Node_Or_Entity_Id
;
10531 -- Start of processing for Get_Discriminant_Value
10534 -- ??? This routine is a gigantic mess and will be deleted. For the
10535 -- time being just test for the trivial case before calling recurse.
10537 if Base_Type
(Scope
(Discriminant
)) = Base_Type
(Typ_For_Constraint
) then
10539 D
: Entity_Id
:= First_Discriminant
(Typ_For_Constraint
);
10540 E
: Elmt_Id
:= First_Elmt
(Constraint
);
10543 while Present
(D
) loop
10544 if Chars
(D
) = Chars
(Discriminant
) then
10548 Next_Discriminant
(D
);
10554 Result
:= Search_Derivation_Levels
10555 (Typ_For_Constraint
, Constraint
, False);
10557 -- ??? hack to disappear when this routine is gone
10559 if Nkind
(Result
) = N_Defining_Identifier
then
10561 D
: Entity_Id
:= First_Discriminant
(Typ_For_Constraint
);
10562 E
: Elmt_Id
:= First_Elmt
(Constraint
);
10565 while Present
(D
) loop
10566 if Corresponding_Discriminant
(D
) = Discriminant
then
10570 Next_Discriminant
(D
);
10576 pragma Assert
(Nkind
(Result
) /= N_Defining_Identifier
);
10578 end Get_Discriminant_Value
;
10580 --------------------------
10581 -- Has_Range_Constraint --
10582 --------------------------
10584 function Has_Range_Constraint
(N
: Node_Id
) return Boolean is
10585 C
: constant Node_Id
:= Constraint
(N
);
10588 if Nkind
(C
) = N_Range_Constraint
then
10591 elsif Nkind
(C
) = N_Digits_Constraint
then
10593 Is_Decimal_Fixed_Point_Type
(Entity
(Subtype_Mark
(N
)))
10595 Present
(Range_Constraint
(C
));
10597 elsif Nkind
(C
) = N_Delta_Constraint
then
10598 return Present
(Range_Constraint
(C
));
10603 end Has_Range_Constraint
;
10605 ------------------------
10606 -- Inherit_Components --
10607 ------------------------
10609 function Inherit_Components
10611 Parent_Base
: Entity_Id
;
10612 Derived_Base
: Entity_Id
;
10613 Is_Tagged
: Boolean;
10614 Inherit_Discr
: Boolean;
10615 Discs
: Elist_Id
) return Elist_Id
10617 Assoc_List
: constant Elist_Id
:= New_Elmt_List
;
10619 procedure Inherit_Component
10620 (Old_C
: Entity_Id
;
10621 Plain_Discrim
: Boolean := False;
10622 Stored_Discrim
: Boolean := False);
10623 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
10624 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
10625 -- True, Old_C is a stored discriminant. If they are both false then
10626 -- Old_C is a regular component.
10628 -----------------------
10629 -- Inherit_Component --
10630 -----------------------
10632 procedure Inherit_Component
10633 (Old_C
: Entity_Id
;
10634 Plain_Discrim
: Boolean := False;
10635 Stored_Discrim
: Boolean := False)
10637 New_C
: constant Entity_Id
:= New_Copy
(Old_C
);
10639 Discrim
: Entity_Id
;
10640 Corr_Discrim
: Entity_Id
;
10643 pragma Assert
(not Is_Tagged
or else not Stored_Discrim
);
10645 Set_Parent
(New_C
, Parent
(Old_C
));
10647 -- Regular discriminants and components must be inserted
10648 -- in the scope of the Derived_Base. Do it here.
10650 if not Stored_Discrim
then
10651 Enter_Name
(New_C
);
10654 -- For tagged types the Original_Record_Component must point to
10655 -- whatever this field was pointing to in the parent type. This has
10656 -- already been achieved by the call to New_Copy above.
10658 if not Is_Tagged
then
10659 Set_Original_Record_Component
(New_C
, New_C
);
10662 -- If we have inherited a component then see if its Etype contains
10663 -- references to Parent_Base discriminants. In this case, replace
10664 -- these references with the constraints given in Discs. We do not
10665 -- do this for the partial view of private types because this is
10666 -- not needed (only the components of the full view will be used
10667 -- for code generation) and cause problem. We also avoid this
10668 -- transformation in some error situations.
10670 if Ekind
(New_C
) = E_Component
then
10671 if (Is_Private_Type
(Derived_Base
)
10672 and then not Is_Generic_Type
(Derived_Base
))
10673 or else (Is_Empty_Elmt_List
(Discs
)
10674 and then not Expander_Active
)
10676 Set_Etype
(New_C
, Etype
(Old_C
));
10678 Set_Etype
(New_C
, Constrain_Component_Type
(Etype
(Old_C
),
10679 Derived_Base
, N
, Parent_Base
, Discs
));
10683 -- In derived tagged types it is illegal to reference a non
10684 -- discriminant component in the parent type. To catch this, mark
10685 -- these components with an Ekind of E_Void. This will be reset in
10686 -- Record_Type_Definition after processing the record extension of
10687 -- the derived type.
10689 if Is_Tagged
and then Ekind
(New_C
) = E_Component
then
10690 Set_Ekind
(New_C
, E_Void
);
10693 if Plain_Discrim
then
10694 Set_Corresponding_Discriminant
(New_C
, Old_C
);
10695 Build_Discriminal
(New_C
);
10697 -- If we are explicitly inheriting a stored discriminant it will be
10698 -- completely hidden.
10700 elsif Stored_Discrim
then
10701 Set_Corresponding_Discriminant
(New_C
, Empty
);
10702 Set_Discriminal
(New_C
, Empty
);
10703 Set_Is_Completely_Hidden
(New_C
);
10705 -- Set the Original_Record_Component of each discriminant in the
10706 -- derived base to point to the corresponding stored that we just
10709 Discrim
:= First_Discriminant
(Derived_Base
);
10710 while Present
(Discrim
) loop
10711 Corr_Discrim
:= Corresponding_Discriminant
(Discrim
);
10713 -- Corr_Discrimm could be missing in an error situation
10715 if Present
(Corr_Discrim
)
10716 and then Original_Record_Component
(Corr_Discrim
) = Old_C
10718 Set_Original_Record_Component
(Discrim
, New_C
);
10721 Next_Discriminant
(Discrim
);
10724 Append_Entity
(New_C
, Derived_Base
);
10727 if not Is_Tagged
then
10728 Append_Elmt
(Old_C
, Assoc_List
);
10729 Append_Elmt
(New_C
, Assoc_List
);
10731 end Inherit_Component
;
10733 -- Variables local to Inherit_Component
10735 Loc
: constant Source_Ptr
:= Sloc
(N
);
10737 Parent_Discrim
: Entity_Id
;
10738 Stored_Discrim
: Entity_Id
;
10740 Component
: Entity_Id
;
10742 -- Start of processing for Inherit_Components
10745 if not Is_Tagged
then
10746 Append_Elmt
(Parent_Base
, Assoc_List
);
10747 Append_Elmt
(Derived_Base
, Assoc_List
);
10750 -- Inherit parent discriminants if needed
10752 if Inherit_Discr
then
10753 Parent_Discrim
:= First_Discriminant
(Parent_Base
);
10754 while Present
(Parent_Discrim
) loop
10755 Inherit_Component
(Parent_Discrim
, Plain_Discrim
=> True);
10756 Next_Discriminant
(Parent_Discrim
);
10760 -- Create explicit stored discrims for untagged types when necessary
10762 if not Has_Unknown_Discriminants
(Derived_Base
)
10763 and then Has_Discriminants
(Parent_Base
)
10764 and then not Is_Tagged
10767 or else First_Discriminant
(Parent_Base
) /=
10768 First_Stored_Discriminant
(Parent_Base
))
10770 Stored_Discrim
:= First_Stored_Discriminant
(Parent_Base
);
10771 while Present
(Stored_Discrim
) loop
10772 Inherit_Component
(Stored_Discrim
, Stored_Discrim
=> True);
10773 Next_Stored_Discriminant
(Stored_Discrim
);
10777 -- See if we can apply the second transformation for derived types, as
10778 -- explained in point 6. in the comments above Build_Derived_Record_Type
10779 -- This is achieved by appending Derived_Base discriminants into Discs,
10780 -- which has the side effect of returning a non empty Discs list to the
10781 -- caller of Inherit_Components, which is what we want. This must be
10782 -- done for private derived types if there are explicit stored
10783 -- discriminants, to ensure that we can retrieve the values of the
10784 -- constraints provided in the ancestors.
10787 and then Is_Empty_Elmt_List
(Discs
)
10788 and then Present
(First_Discriminant
(Derived_Base
))
10790 (not Is_Private_Type
(Derived_Base
)
10791 or else Is_Completely_Hidden
10792 (First_Stored_Discriminant
(Derived_Base
))
10793 or else Is_Generic_Type
(Derived_Base
))
10795 D
:= First_Discriminant
(Derived_Base
);
10796 while Present
(D
) loop
10797 Append_Elmt
(New_Reference_To
(D
, Loc
), Discs
);
10798 Next_Discriminant
(D
);
10802 -- Finally, inherit non-discriminant components unless they are not
10803 -- visible because defined or inherited from the full view of the
10804 -- parent. Don't inherit the _parent field of the parent type.
10806 Component
:= First_Entity
(Parent_Base
);
10807 while Present
(Component
) loop
10808 if Ekind
(Component
) /= E_Component
10809 or else Chars
(Component
) = Name_uParent
10813 -- If the derived type is within the parent type's declarative
10814 -- region, then the components can still be inherited even though
10815 -- they aren't visible at this point. This can occur for cases
10816 -- such as within public child units where the components must
10817 -- become visible upon entering the child unit's private part.
10819 elsif not Is_Visible_Component
(Component
)
10820 and then not In_Open_Scopes
(Scope
(Parent_Base
))
10824 elsif Ekind
(Derived_Base
) = E_Private_Type
10825 or else Ekind
(Derived_Base
) = E_Limited_Private_Type
10830 Inherit_Component
(Component
);
10833 Next_Entity
(Component
);
10836 -- For tagged derived types, inherited discriminants cannot be used in
10837 -- component declarations of the record extension part. To achieve this
10838 -- we mark the inherited discriminants as not visible.
10840 if Is_Tagged
and then Inherit_Discr
then
10841 D
:= First_Discriminant
(Derived_Base
);
10842 while Present
(D
) loop
10843 Set_Is_Immediately_Visible
(D
, False);
10844 Next_Discriminant
(D
);
10849 end Inherit_Components
;
10851 ------------------------------
10852 -- Is_Valid_Constraint_Kind --
10853 ------------------------------
10855 function Is_Valid_Constraint_Kind
10856 (T_Kind
: Type_Kind
;
10857 Constraint_Kind
: Node_Kind
) return Boolean
10861 when Enumeration_Kind |
10863 return Constraint_Kind
= N_Range_Constraint
;
10865 when Decimal_Fixed_Point_Kind
=>
10867 Constraint_Kind
= N_Digits_Constraint
10869 Constraint_Kind
= N_Range_Constraint
;
10871 when Ordinary_Fixed_Point_Kind
=>
10873 Constraint_Kind
= N_Delta_Constraint
10875 Constraint_Kind
= N_Range_Constraint
;
10879 Constraint_Kind
= N_Digits_Constraint
10881 Constraint_Kind
= N_Range_Constraint
;
10888 E_Incomplete_Type |
10891 return Constraint_Kind
= N_Index_Or_Discriminant_Constraint
;
10894 return True; -- Error will be detected later
10896 end Is_Valid_Constraint_Kind
;
10898 --------------------------
10899 -- Is_Visible_Component --
10900 --------------------------
10902 function Is_Visible_Component
(C
: Entity_Id
) return Boolean is
10903 Original_Comp
: Entity_Id
:= Empty
;
10904 Original_Scope
: Entity_Id
;
10905 Type_Scope
: Entity_Id
;
10907 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean;
10908 -- Check whether parent type of inherited component is declared locally,
10909 -- possibly within a nested package or instance. The current scope is
10910 -- the derived record itself.
10912 -------------------
10913 -- Is_Local_Type --
10914 -------------------
10916 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean is
10917 Scop
: Entity_Id
:= Scope
(Typ
);
10920 while Present
(Scop
)
10921 and then Scop
/= Standard_Standard
10923 if Scop
= Scope
(Current_Scope
) then
10927 Scop
:= Scope
(Scop
);
10933 -- Start of processing for Is_Visible_Component
10936 if Ekind
(C
) = E_Component
10937 or else Ekind
(C
) = E_Discriminant
10939 Original_Comp
:= Original_Record_Component
(C
);
10942 if No
(Original_Comp
) then
10944 -- Premature usage, or previous error
10949 Original_Scope
:= Scope
(Original_Comp
);
10950 Type_Scope
:= Scope
(Base_Type
(Scope
(C
)));
10953 -- This test only concerns tagged types
10955 if not Is_Tagged_Type
(Original_Scope
) then
10958 -- If it is _Parent or _Tag, there is no visibility issue
10960 elsif not Comes_From_Source
(Original_Comp
) then
10963 -- If we are in the body of an instantiation, the component is visible
10964 -- even when the parent type (possibly defined in an enclosing unit or
10965 -- in a parent unit) might not.
10967 elsif In_Instance_Body
then
10970 -- Discriminants are always visible
10972 elsif Ekind
(Original_Comp
) = E_Discriminant
10973 and then not Has_Unknown_Discriminants
(Original_Scope
)
10977 -- If the component has been declared in an ancestor which is currently
10978 -- a private type, then it is not visible. The same applies if the
10979 -- component's containing type is not in an open scope and the original
10980 -- component's enclosing type is a visible full type of a private type
10981 -- (which can occur in cases where an attempt is being made to reference
10982 -- a component in a sibling package that is inherited from a visible
10983 -- component of a type in an ancestor package; the component in the
10984 -- sibling package should not be visible even though the component it
10985 -- inherited from is visible). This does not apply however in the case
10986 -- where the scope of the type is a private child unit, or when the
10987 -- parent comes from a local package in which the ancestor is currently
10988 -- visible. The latter suppression of visibility is needed for cases
10989 -- that are tested in B730006.
10991 elsif Is_Private_Type
(Original_Scope
)
10993 (not Is_Private_Descendant
(Type_Scope
)
10994 and then not In_Open_Scopes
(Type_Scope
)
10995 and then Has_Private_Declaration
(Original_Scope
))
10997 -- If the type derives from an entity in a formal package, there
10998 -- are no additional visible components.
11000 if Nkind
(Original_Node
(Unit_Declaration_Node
(Type_Scope
))) =
11001 N_Formal_Package_Declaration
11005 -- if we are not in the private part of the current package, there
11006 -- are no additional visible components.
11008 elsif Ekind
(Scope
(Current_Scope
)) = E_Package
11009 and then not In_Private_Part
(Scope
(Current_Scope
))
11014 Is_Child_Unit
(Cunit_Entity
(Current_Sem_Unit
))
11015 and then Is_Local_Type
(Type_Scope
);
11018 -- There is another weird way in which a component may be invisible
11019 -- when the private and the full view are not derived from the same
11020 -- ancestor. Here is an example :
11022 -- type A1 is tagged record F1 : integer; end record;
11023 -- type A2 is new A1 with record F2 : integer; end record;
11024 -- type T is new A1 with private;
11026 -- type T is new A2 with null record;
11028 -- In this case, the full view of T inherits F1 and F2 but the private
11029 -- view inherits only F1
11033 Ancestor
: Entity_Id
:= Scope
(C
);
11037 if Ancestor
= Original_Scope
then
11039 elsif Ancestor
= Etype
(Ancestor
) then
11043 Ancestor
:= Etype
(Ancestor
);
11049 end Is_Visible_Component
;
11051 --------------------------
11052 -- Make_Class_Wide_Type --
11053 --------------------------
11055 procedure Make_Class_Wide_Type
(T
: Entity_Id
) is
11056 CW_Type
: Entity_Id
;
11058 Next_E
: Entity_Id
;
11061 -- The class wide type can have been defined by the partial view in
11062 -- which case everything is already done
11064 if Present
(Class_Wide_Type
(T
)) then
11069 New_External_Entity
(E_Void
, Scope
(T
), Sloc
(T
), T
, 'C', 0, 'T');
11071 -- Inherit root type characteristics
11073 CW_Name
:= Chars
(CW_Type
);
11074 Next_E
:= Next_Entity
(CW_Type
);
11075 Copy_Node
(T
, CW_Type
);
11076 Set_Comes_From_Source
(CW_Type
, False);
11077 Set_Chars
(CW_Type
, CW_Name
);
11078 Set_Parent
(CW_Type
, Parent
(T
));
11079 Set_Next_Entity
(CW_Type
, Next_E
);
11080 Set_Has_Delayed_Freeze
(CW_Type
);
11082 -- Customize the class-wide type: It has no prim. op., it cannot be
11083 -- abstract and its Etype points back to the specific root type.
11085 Set_Ekind
(CW_Type
, E_Class_Wide_Type
);
11086 Set_Is_Tagged_Type
(CW_Type
, True);
11087 Set_Primitive_Operations
(CW_Type
, New_Elmt_List
);
11088 Set_Is_Abstract
(CW_Type
, False);
11089 Set_Is_Constrained
(CW_Type
, False);
11090 Set_Is_First_Subtype
(CW_Type
, Is_First_Subtype
(T
));
11091 Init_Size_Align
(CW_Type
);
11093 if Ekind
(T
) = E_Class_Wide_Subtype
then
11094 Set_Etype
(CW_Type
, Etype
(Base_Type
(T
)));
11096 Set_Etype
(CW_Type
, T
);
11099 -- If this is the class_wide type of a constrained subtype, it does
11100 -- not have discriminants.
11102 Set_Has_Discriminants
(CW_Type
,
11103 Has_Discriminants
(T
) and then not Is_Constrained
(T
));
11105 Set_Has_Unknown_Discriminants
(CW_Type
, True);
11106 Set_Class_Wide_Type
(T
, CW_Type
);
11107 Set_Equivalent_Type
(CW_Type
, Empty
);
11109 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
11111 Set_Class_Wide_Type
(CW_Type
, CW_Type
);
11112 end Make_Class_Wide_Type
;
11118 procedure Make_Index
11120 Related_Nod
: Node_Id
;
11121 Related_Id
: Entity_Id
:= Empty
;
11122 Suffix_Index
: Nat
:= 1)
11126 Def_Id
: Entity_Id
:= Empty
;
11127 Found
: Boolean := False;
11130 -- For a discrete range used in a constrained array definition and
11131 -- defined by a range, an implicit conversion to the predefined type
11132 -- INTEGER is assumed if each bound is either a numeric literal, a named
11133 -- number, or an attribute, and the type of both bounds (prior to the
11134 -- implicit conversion) is the type universal_integer. Otherwise, both
11135 -- bounds must be of the same discrete type, other than universal
11136 -- integer; this type must be determinable independently of the
11137 -- context, but using the fact that the type must be discrete and that
11138 -- both bounds must have the same type.
11140 -- Character literals also have a universal type in the absence of
11141 -- of additional context, and are resolved to Standard_Character.
11143 if Nkind
(I
) = N_Range
then
11145 -- The index is given by a range constraint. The bounds are known
11146 -- to be of a consistent type.
11148 if not Is_Overloaded
(I
) then
11151 -- If the bounds are universal, choose the specific predefined
11154 if T
= Universal_Integer
then
11155 T
:= Standard_Integer
;
11157 elsif T
= Any_Character
then
11159 if Ada_Version
>= Ada_95
then
11161 ("ambiguous character literals (could be Wide_Character)",
11165 T
:= Standard_Character
;
11172 Ind
: Interp_Index
;
11176 Get_First_Interp
(I
, Ind
, It
);
11178 while Present
(It
.Typ
) loop
11179 if Is_Discrete_Type
(It
.Typ
) then
11182 and then not Covers
(It
.Typ
, T
)
11183 and then not Covers
(T
, It
.Typ
)
11185 Error_Msg_N
("ambiguous bounds in discrete range", I
);
11193 Get_Next_Interp
(Ind
, It
);
11196 if T
= Any_Type
then
11197 Error_Msg_N
("discrete type required for range", I
);
11198 Set_Etype
(I
, Any_Type
);
11201 elsif T
= Universal_Integer
then
11202 T
:= Standard_Integer
;
11207 if not Is_Discrete_Type
(T
) then
11208 Error_Msg_N
("discrete type required for range", I
);
11209 Set_Etype
(I
, Any_Type
);
11213 if Nkind
(Low_Bound
(I
)) = N_Attribute_Reference
11214 and then Attribute_Name
(Low_Bound
(I
)) = Name_First
11215 and then Is_Entity_Name
(Prefix
(Low_Bound
(I
)))
11216 and then Is_Type
(Entity
(Prefix
(Low_Bound
(I
))))
11217 and then Is_Discrete_Type
(Entity
(Prefix
(Low_Bound
(I
))))
11219 -- The type of the index will be the type of the prefix, as long
11220 -- as the upper bound is 'Last of the same type.
11222 Def_Id
:= Entity
(Prefix
(Low_Bound
(I
)));
11224 if Nkind
(High_Bound
(I
)) /= N_Attribute_Reference
11225 or else Attribute_Name
(High_Bound
(I
)) /= Name_Last
11226 or else not Is_Entity_Name
(Prefix
(High_Bound
(I
)))
11227 or else Entity
(Prefix
(High_Bound
(I
))) /= Def_Id
11234 Process_Range_Expr_In_Decl
(R
, T
);
11236 elsif Nkind
(I
) = N_Subtype_Indication
then
11238 -- The index is given by a subtype with a range constraint
11240 T
:= Base_Type
(Entity
(Subtype_Mark
(I
)));
11242 if not Is_Discrete_Type
(T
) then
11243 Error_Msg_N
("discrete type required for range", I
);
11244 Set_Etype
(I
, Any_Type
);
11248 R
:= Range_Expression
(Constraint
(I
));
11251 Process_Range_Expr_In_Decl
(R
, Entity
(Subtype_Mark
(I
)));
11253 elsif Nkind
(I
) = N_Attribute_Reference
then
11255 -- The parser guarantees that the attribute is a RANGE attribute
11257 -- If the node denotes the range of a type mark, that is also the
11258 -- resulting type, and we do no need to create an Itype for it.
11260 if Is_Entity_Name
(Prefix
(I
))
11261 and then Comes_From_Source
(I
)
11262 and then Is_Type
(Entity
(Prefix
(I
)))
11263 and then Is_Discrete_Type
(Entity
(Prefix
(I
)))
11265 Def_Id
:= Entity
(Prefix
(I
));
11268 Analyze_And_Resolve
(I
);
11272 -- If none of the above, must be a subtype. We convert this to a
11273 -- range attribute reference because in the case of declared first
11274 -- named subtypes, the types in the range reference can be different
11275 -- from the type of the entity. A range attribute normalizes the
11276 -- reference and obtains the correct types for the bounds.
11278 -- This transformation is in the nature of an expansion, is only
11279 -- done if expansion is active. In particular, it is not done on
11280 -- formal generic types, because we need to retain the name of the
11281 -- original index for instantiation purposes.
11284 if not Is_Entity_Name
(I
) or else not Is_Type
(Entity
(I
)) then
11285 Error_Msg_N
("invalid subtype mark in discrete range ", I
);
11286 Set_Etype
(I
, Any_Integer
);
11290 -- The type mark may be that of an incomplete type. It is only
11291 -- now that we can get the full view, previous analysis does
11292 -- not look specifically for a type mark.
11294 Set_Entity
(I
, Get_Full_View
(Entity
(I
)));
11295 Set_Etype
(I
, Entity
(I
));
11296 Def_Id
:= Entity
(I
);
11298 if not Is_Discrete_Type
(Def_Id
) then
11299 Error_Msg_N
("discrete type required for index", I
);
11300 Set_Etype
(I
, Any_Type
);
11305 if Expander_Active
then
11307 Make_Attribute_Reference
(Sloc
(I
),
11308 Attribute_Name
=> Name_Range
,
11309 Prefix
=> Relocate_Node
(I
)));
11311 -- The original was a subtype mark that does not freeze. This
11312 -- means that the rewritten version must not freeze either.
11314 Set_Must_Not_Freeze
(I
);
11315 Set_Must_Not_Freeze
(Prefix
(I
));
11317 -- Is order critical??? if so, document why, if not
11318 -- use Analyze_And_Resolve
11325 -- If expander is inactive, type is legal, nothing else to construct
11332 if not Is_Discrete_Type
(T
) then
11333 Error_Msg_N
("discrete type required for range", I
);
11334 Set_Etype
(I
, Any_Type
);
11337 elsif T
= Any_Type
then
11338 Set_Etype
(I
, Any_Type
);
11342 -- We will now create the appropriate Itype to describe the range, but
11343 -- first a check. If we originally had a subtype, then we just label
11344 -- the range with this subtype. Not only is there no need to construct
11345 -- a new subtype, but it is wrong to do so for two reasons:
11347 -- 1. A legality concern, if we have a subtype, it must not freeze,
11348 -- and the Itype would cause freezing incorrectly
11350 -- 2. An efficiency concern, if we created an Itype, it would not be
11351 -- recognized as the same type for the purposes of eliminating
11352 -- checks in some circumstances.
11354 -- We signal this case by setting the subtype entity in Def_Id
11356 if No
(Def_Id
) then
11358 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, 'D', Suffix_Index
);
11359 Set_Etype
(Def_Id
, Base_Type
(T
));
11361 if Is_Signed_Integer_Type
(T
) then
11362 Set_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
11364 elsif Is_Modular_Integer_Type
(T
) then
11365 Set_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
11368 Set_Ekind
(Def_Id
, E_Enumeration_Subtype
);
11369 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
11370 Set_First_Literal
(Def_Id
, First_Literal
(T
));
11373 Set_Size_Info
(Def_Id
, (T
));
11374 Set_RM_Size
(Def_Id
, RM_Size
(T
));
11375 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
11377 Set_Scalar_Range
(Def_Id
, R
);
11378 Conditional_Delay
(Def_Id
, T
);
11380 -- In the subtype indication case, if the immediate parent of the
11381 -- new subtype is non-static, then the subtype we create is non-
11382 -- static, even if its bounds are static.
11384 if Nkind
(I
) = N_Subtype_Indication
11385 and then not Is_Static_Subtype
(Entity
(Subtype_Mark
(I
)))
11387 Set_Is_Non_Static_Subtype
(Def_Id
);
11391 -- Final step is to label the index with this constructed type
11393 Set_Etype
(I
, Def_Id
);
11396 ------------------------------
11397 -- Modular_Type_Declaration --
11398 ------------------------------
11400 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
11401 Mod_Expr
: constant Node_Id
:= Expression
(Def
);
11404 procedure Set_Modular_Size
(Bits
: Int
);
11405 -- Sets RM_Size to Bits, and Esize to normal word size above this
11407 ----------------------
11408 -- Set_Modular_Size --
11409 ----------------------
11411 procedure Set_Modular_Size
(Bits
: Int
) is
11413 Set_RM_Size
(T
, UI_From_Int
(Bits
));
11418 elsif Bits
<= 16 then
11419 Init_Esize
(T
, 16);
11421 elsif Bits
<= 32 then
11422 Init_Esize
(T
, 32);
11425 Init_Esize
(T
, System_Max_Binary_Modulus_Power
);
11427 end Set_Modular_Size
;
11429 -- Start of processing for Modular_Type_Declaration
11432 Analyze_And_Resolve
(Mod_Expr
, Any_Integer
);
11434 Set_Ekind
(T
, E_Modular_Integer_Type
);
11435 Init_Alignment
(T
);
11436 Set_Is_Constrained
(T
);
11438 if not Is_OK_Static_Expression
(Mod_Expr
) then
11439 Flag_Non_Static_Expr
11440 ("non-static expression used for modular type bound!", Mod_Expr
);
11441 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
11443 M_Val
:= Expr_Value
(Mod_Expr
);
11447 Error_Msg_N
("modulus value must be positive", Mod_Expr
);
11448 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
11451 Set_Modulus
(T
, M_Val
);
11453 -- Create bounds for the modular type based on the modulus given in
11454 -- the type declaration and then analyze and resolve those bounds.
11456 Set_Scalar_Range
(T
,
11457 Make_Range
(Sloc
(Mod_Expr
),
11459 Make_Integer_Literal
(Sloc
(Mod_Expr
), 0),
11461 Make_Integer_Literal
(Sloc
(Mod_Expr
), M_Val
- 1)));
11463 -- Properly analyze the literals for the range. We do this manually
11464 -- because we can't go calling Resolve, since we are resolving these
11465 -- bounds with the type, and this type is certainly not complete yet!
11467 Set_Etype
(Low_Bound
(Scalar_Range
(T
)), T
);
11468 Set_Etype
(High_Bound
(Scalar_Range
(T
)), T
);
11469 Set_Is_Static_Expression
(Low_Bound
(Scalar_Range
(T
)));
11470 Set_Is_Static_Expression
(High_Bound
(Scalar_Range
(T
)));
11472 -- Loop through powers of two to find number of bits required
11474 for Bits
in Int
range 0 .. System_Max_Binary_Modulus_Power
loop
11478 if M_Val
= 2 ** Bits
then
11479 Set_Modular_Size
(Bits
);
11484 elsif M_Val
< 2 ** Bits
then
11485 Set_Non_Binary_Modulus
(T
);
11487 if Bits
> System_Max_Nonbinary_Modulus_Power
then
11488 Error_Msg_Uint_1
:=
11489 UI_From_Int
(System_Max_Nonbinary_Modulus_Power
);
11491 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr
);
11492 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
11496 -- In the non-binary case, set size as per RM 13.3(55)
11498 Set_Modular_Size
(Bits
);
11505 -- If we fall through, then the size exceed System.Max_Binary_Modulus
11506 -- so we just signal an error and set the maximum size.
11508 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Binary_Modulus_Power
);
11509 Error_Msg_N
("modulus exceeds limit (2 '*'*^)", Mod_Expr
);
11511 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
11512 Init_Alignment
(T
);
11514 end Modular_Type_Declaration
;
11516 --------------------------
11517 -- New_Concatenation_Op --
11518 --------------------------
11520 procedure New_Concatenation_Op
(Typ
: Entity_Id
) is
11521 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
11524 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
;
11525 -- Create abbreviated declaration for the formal of a predefined
11526 -- Operator 'Op' of type 'Typ'
11528 --------------------
11529 -- Make_Op_Formal --
11530 --------------------
11532 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
is
11533 Formal
: Entity_Id
;
11535 Formal
:= New_Internal_Entity
(E_In_Parameter
, Op
, Loc
, 'P');
11536 Set_Etype
(Formal
, Typ
);
11537 Set_Mechanism
(Formal
, Default_Mechanism
);
11539 end Make_Op_Formal
;
11541 -- Start of processing for New_Concatenation_Op
11544 Op
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Concat
);
11546 Set_Ekind
(Op
, E_Operator
);
11547 Set_Scope
(Op
, Current_Scope
);
11548 Set_Etype
(Op
, Typ
);
11549 Set_Homonym
(Op
, Get_Name_Entity_Id
(Name_Op_Concat
));
11550 Set_Is_Immediately_Visible
(Op
);
11551 Set_Is_Intrinsic_Subprogram
(Op
);
11552 Set_Has_Completion
(Op
);
11553 Append_Entity
(Op
, Current_Scope
);
11555 Set_Name_Entity_Id
(Name_Op_Concat
, Op
);
11557 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
11558 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
11559 end New_Concatenation_Op
;
11561 -------------------------------------------
11562 -- Ordinary_Fixed_Point_Type_Declaration --
11563 -------------------------------------------
11565 procedure Ordinary_Fixed_Point_Type_Declaration
11569 Loc
: constant Source_Ptr
:= Sloc
(Def
);
11570 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
11571 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
11572 Implicit_Base
: Entity_Id
;
11579 Check_Restriction
(No_Fixed_Point
, Def
);
11581 -- Create implicit base type
11584 Create_Itype
(E_Ordinary_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
11585 Set_Etype
(Implicit_Base
, Implicit_Base
);
11587 -- Analyze and process delta expression
11589 Analyze_And_Resolve
(Delta_Expr
, Any_Real
);
11591 Check_Delta_Expression
(Delta_Expr
);
11592 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
11594 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
11596 -- Compute default small from given delta, which is the largest power
11597 -- of two that does not exceed the given delta value.
11600 Tmp
: Ureal
:= Ureal_1
;
11604 if Delta_Val
< Ureal_1
then
11605 while Delta_Val
< Tmp
loop
11606 Tmp
:= Tmp
/ Ureal_2
;
11607 Scale
:= Scale
+ 1;
11612 Tmp
:= Tmp
* Ureal_2
;
11613 exit when Tmp
> Delta_Val
;
11614 Scale
:= Scale
- 1;
11618 Small_Val
:= UR_From_Components
(Uint_1
, UI_From_Int
(Scale
), 2);
11621 Set_Small_Value
(Implicit_Base
, Small_Val
);
11623 -- If no range was given, set a dummy range
11625 if RRS
<= Empty_Or_Error
then
11626 Low_Val
:= -Small_Val
;
11627 High_Val
:= Small_Val
;
11629 -- Otherwise analyze and process given range
11633 Low
: constant Node_Id
:= Low_Bound
(RRS
);
11634 High
: constant Node_Id
:= High_Bound
(RRS
);
11637 Analyze_And_Resolve
(Low
, Any_Real
);
11638 Analyze_And_Resolve
(High
, Any_Real
);
11639 Check_Real_Bound
(Low
);
11640 Check_Real_Bound
(High
);
11642 -- Obtain and set the range
11644 Low_Val
:= Expr_Value_R
(Low
);
11645 High_Val
:= Expr_Value_R
(High
);
11647 if Low_Val
> High_Val
then
11648 Error_Msg_NE
("?fixed point type& has null range", Def
, T
);
11653 -- The range for both the implicit base and the declared first subtype
11654 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
11655 -- set a temporary range in place. Note that the bounds of the base
11656 -- type will be widened to be symmetrical and to fill the available
11657 -- bits when the type is frozen.
11659 -- We could do this with all discrete types, and probably should, but
11660 -- we absolutely have to do it for fixed-point, since the end-points
11661 -- of the range and the size are determined by the small value, which
11662 -- could be reset before the freeze point.
11664 Set_Fixed_Range
(Implicit_Base
, Loc
, Low_Val
, High_Val
);
11665 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
11667 Init_Size_Align
(Implicit_Base
);
11669 -- Complete definition of first subtype
11671 Set_Ekind
(T
, E_Ordinary_Fixed_Point_Subtype
);
11672 Set_Etype
(T
, Implicit_Base
);
11673 Init_Size_Align
(T
);
11674 Set_First_Rep_Item
(T
, First_Rep_Item
(Implicit_Base
));
11675 Set_Small_Value
(T
, Small_Val
);
11676 Set_Delta_Value
(T
, Delta_Val
);
11677 Set_Is_Constrained
(T
);
11679 end Ordinary_Fixed_Point_Type_Declaration
;
11681 ----------------------------------------
11682 -- Prepare_Private_Subtype_Completion --
11683 ----------------------------------------
11685 procedure Prepare_Private_Subtype_Completion
11687 Related_Nod
: Node_Id
)
11689 Id_B
: constant Entity_Id
:= Base_Type
(Id
);
11690 Full_B
: constant Entity_Id
:= Full_View
(Id_B
);
11694 if Present
(Full_B
) then
11696 -- The Base_Type is already completed, we can complete the subtype
11697 -- now. We have to create a new entity with the same name, Thus we
11698 -- can't use Create_Itype.
11700 -- This is messy, should be fixed ???
11702 Full
:= Make_Defining_Identifier
(Sloc
(Id
), Chars
(Id
));
11703 Set_Is_Itype
(Full
);
11704 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
11705 Complete_Private_Subtype
(Id
, Full
, Full_B
, Related_Nod
);
11708 -- The parent subtype may be private, but the base might not, in some
11709 -- nested instances. In that case, the subtype does not need to be
11710 -- exchanged. It would still be nice to make private subtypes and their
11711 -- bases consistent at all times ???
11713 if Is_Private_Type
(Id_B
) then
11714 Append_Elmt
(Id
, Private_Dependents
(Id_B
));
11717 end Prepare_Private_Subtype_Completion
;
11719 ---------------------------
11720 -- Process_Discriminants --
11721 ---------------------------
11723 procedure Process_Discriminants
11725 Prev
: Entity_Id
:= Empty
)
11727 Elist
: constant Elist_Id
:= New_Elmt_List
;
11730 Discr_Number
: Uint
;
11731 Discr_Type
: Entity_Id
;
11732 Default_Present
: Boolean := False;
11733 Default_Not_Present
: Boolean := False;
11736 -- A composite type other than an array type can have discriminants.
11737 -- Discriminants of non-limited types must have a discrete type.
11738 -- On entry, the current scope is the composite type.
11740 -- The discriminants are initially entered into the scope of the type
11741 -- via Enter_Name with the default Ekind of E_Void to prevent premature
11742 -- use, as explained at the end of this procedure.
11744 Discr
:= First
(Discriminant_Specifications
(N
));
11745 while Present
(Discr
) loop
11746 Enter_Name
(Defining_Identifier
(Discr
));
11748 -- For navigation purposes we add a reference to the discriminant
11749 -- in the entity for the type. If the current declaration is a
11750 -- completion, place references on the partial view. Otherwise the
11751 -- type is the current scope.
11753 if Present
(Prev
) then
11755 -- The references go on the partial view, if present. If the
11756 -- partial view has discriminants, the references have been
11757 -- generated already.
11759 if not Has_Discriminants
(Prev
) then
11760 Generate_Reference
(Prev
, Defining_Identifier
(Discr
), 'd');
11764 (Current_Scope
, Defining_Identifier
(Discr
), 'd');
11767 if Nkind
(Discriminant_Type
(Discr
)) = N_Access_Definition
then
11768 Discr_Type
:= Access_Definition
(N
, Discriminant_Type
(Discr
));
11770 -- Ada 2005 (AI-254)
11772 if Present
(Access_To_Subprogram_Definition
11773 (Discriminant_Type
(Discr
)))
11774 and then Protected_Present
(Access_To_Subprogram_Definition
11775 (Discriminant_Type
(Discr
)))
11778 Replace_Anonymous_Access_To_Protected_Subprogram
11779 (Discr
, Discr_Type
);
11783 Find_Type
(Discriminant_Type
(Discr
));
11784 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
11786 if Error_Posted
(Discriminant_Type
(Discr
)) then
11787 Discr_Type
:= Any_Type
;
11791 if Is_Access_Type
(Discr_Type
) then
11793 -- Ada 2005 (AI-230): Access discriminant allowed in non-limited
11796 if Ada_Version
< Ada_05
then
11797 Check_Access_Discriminant_Requires_Limited
11798 (Discr
, Discriminant_Type
(Discr
));
11801 if Ada_Version
= Ada_83
and then Comes_From_Source
(Discr
) then
11803 ("(Ada 83) access discriminant not allowed", Discr
);
11806 elsif not Is_Discrete_Type
(Discr_Type
) then
11807 Error_Msg_N
("discriminants must have a discrete or access type",
11808 Discriminant_Type
(Discr
));
11811 Set_Etype
(Defining_Identifier
(Discr
), Discr_Type
);
11813 -- If a discriminant specification includes the assignment compound
11814 -- delimiter followed by an expression, the expression is the default
11815 -- expression of the discriminant; the default expression must be of
11816 -- the type of the discriminant. (RM 3.7.1) Since this expression is
11817 -- a default expression, we do the special preanalysis, since this
11818 -- expression does not freeze (see "Handling of Default and Per-
11819 -- Object Expressions" in spec of package Sem).
11821 if Present
(Expression
(Discr
)) then
11822 Analyze_Per_Use_Expression
(Expression
(Discr
), Discr_Type
);
11824 if Nkind
(N
) = N_Formal_Type_Declaration
then
11826 ("discriminant defaults not allowed for formal type",
11827 Expression
(Discr
));
11829 -- Tagged types cannot have defaulted discriminants, but a
11830 -- non-tagged private type with defaulted discriminants
11831 -- can have a tagged completion.
11833 elsif Is_Tagged_Type
(Current_Scope
)
11834 and then Comes_From_Source
(N
)
11837 ("discriminants of tagged type cannot have defaults",
11838 Expression
(Discr
));
11841 Default_Present
:= True;
11842 Append_Elmt
(Expression
(Discr
), Elist
);
11844 -- Tag the defining identifiers for the discriminants with
11845 -- their corresponding default expressions from the tree.
11847 Set_Discriminant_Default_Value
11848 (Defining_Identifier
(Discr
), Expression
(Discr
));
11852 Default_Not_Present
:= True;
11855 -- Ada 2005 (AI-231): Set the null-excluding attribute and carry
11856 -- out some static checks.
11858 if Ada_Version
>= Ada_05
11859 and then (Null_Exclusion_Present
(Discr
)
11860 or else Can_Never_Be_Null
(Discr_Type
))
11862 Set_Can_Never_Be_Null
(Defining_Identifier
(Discr
));
11863 Null_Exclusion_Static_Checks
(Discr
);
11869 -- An element list consisting of the default expressions of the
11870 -- discriminants is constructed in the above loop and used to set
11871 -- the Discriminant_Constraint attribute for the type. If an object
11872 -- is declared of this (record or task) type without any explicit
11873 -- discriminant constraint given, this element list will form the
11874 -- actual parameters for the corresponding initialization procedure
11877 Set_Discriminant_Constraint
(Current_Scope
, Elist
);
11878 Set_Stored_Constraint
(Current_Scope
, No_Elist
);
11880 -- Default expressions must be provided either for all or for none
11881 -- of the discriminants of a discriminant part. (RM 3.7.1)
11883 if Default_Present
and then Default_Not_Present
then
11885 ("incomplete specification of defaults for discriminants", N
);
11888 -- The use of the name of a discriminant is not allowed in default
11889 -- expressions of a discriminant part if the specification of the
11890 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
11892 -- To detect this, the discriminant names are entered initially with an
11893 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
11894 -- attempt to use a void entity (for example in an expression that is
11895 -- type-checked) produces the error message: premature usage. Now after
11896 -- completing the semantic analysis of the discriminant part, we can set
11897 -- the Ekind of all the discriminants appropriately.
11899 Discr
:= First
(Discriminant_Specifications
(N
));
11900 Discr_Number
:= Uint_1
;
11902 while Present
(Discr
) loop
11903 Id
:= Defining_Identifier
(Discr
);
11904 Set_Ekind
(Id
, E_Discriminant
);
11905 Init_Component_Location
(Id
);
11907 Set_Discriminant_Number
(Id
, Discr_Number
);
11909 -- Make sure this is always set, even in illegal programs
11911 Set_Corresponding_Discriminant
(Id
, Empty
);
11913 -- Initialize the Original_Record_Component to the entity itself.
11914 -- Inherit_Components will propagate the right value to
11915 -- discriminants in derived record types.
11917 Set_Original_Record_Component
(Id
, Id
);
11919 -- Create the discriminal for the discriminant
11921 Build_Discriminal
(Id
);
11924 Discr_Number
:= Discr_Number
+ 1;
11927 Set_Has_Discriminants
(Current_Scope
);
11928 end Process_Discriminants
;
11930 -----------------------
11931 -- Process_Full_View --
11932 -----------------------
11934 procedure Process_Full_View
(N
: Node_Id
; Full_T
, Priv_T
: Entity_Id
) is
11935 Priv_Parent
: Entity_Id
;
11936 Full_Parent
: Entity_Id
;
11937 Full_Indic
: Node_Id
;
11940 -- First some sanity checks that must be done after semantic
11941 -- decoration of the full view and thus cannot be placed with other
11942 -- similar checks in Find_Type_Name
11944 if not Is_Limited_Type
(Priv_T
)
11945 and then (Is_Limited_Type
(Full_T
)
11946 or else Is_Limited_Composite
(Full_T
))
11949 ("completion of nonlimited type cannot be limited", Full_T
);
11950 Explain_Limited_Type
(Full_T
, Full_T
);
11952 elsif Is_Abstract
(Full_T
) and then not Is_Abstract
(Priv_T
) then
11954 ("completion of nonabstract type cannot be abstract", Full_T
);
11956 elsif Is_Tagged_Type
(Priv_T
)
11957 and then Is_Limited_Type
(Priv_T
)
11958 and then not Is_Limited_Type
(Full_T
)
11960 -- GNAT allow its own definition of Limited_Controlled to disobey
11961 -- this rule in order in ease the implementation. The next test is
11962 -- safe because Root_Controlled is defined in a private system child
11964 if Etype
(Full_T
) = Full_View
(RTE
(RE_Root_Controlled
)) then
11965 Set_Is_Limited_Composite
(Full_T
);
11968 ("completion of limited tagged type must be limited", Full_T
);
11971 elsif Is_Generic_Type
(Priv_T
) then
11972 Error_Msg_N
("generic type cannot have a completion", Full_T
);
11975 if Is_Tagged_Type
(Priv_T
)
11976 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
11977 and then Is_Derived_Type
(Full_T
)
11979 Priv_Parent
:= Etype
(Priv_T
);
11981 -- The full view of a private extension may have been transformed
11982 -- into an unconstrained derived type declaration and a subtype
11983 -- declaration (see build_derived_record_type for details).
11985 if Nkind
(N
) = N_Subtype_Declaration
then
11986 Full_Indic
:= Subtype_Indication
(N
);
11987 Full_Parent
:= Etype
(Base_Type
(Full_T
));
11989 Full_Indic
:= Subtype_Indication
(Type_Definition
(N
));
11990 Full_Parent
:= Etype
(Full_T
);
11993 -- Check that the parent type of the full type is a descendant of
11994 -- the ancestor subtype given in the private extension. If either
11995 -- entity has an Etype equal to Any_Type then we had some previous
11996 -- error situation [7.3(8)].
11998 if Priv_Parent
= Any_Type
or else Full_Parent
= Any_Type
then
12001 elsif not Is_Ancestor
(Base_Type
(Priv_Parent
), Full_Parent
) then
12003 ("parent of full type must descend from parent"
12004 & " of private extension", Full_Indic
);
12006 -- Check the rules of 7.3(10): if the private extension inherits
12007 -- known discriminants, then the full type must also inherit those
12008 -- discriminants from the same (ancestor) type, and the parent
12009 -- subtype of the full type must be constrained if and only if
12010 -- the ancestor subtype of the private extension is constrained.
12012 elsif not Present
(Discriminant_Specifications
(Parent
(Priv_T
)))
12013 and then not Has_Unknown_Discriminants
(Priv_T
)
12014 and then Has_Discriminants
(Base_Type
(Priv_Parent
))
12017 Priv_Indic
: constant Node_Id
:=
12018 Subtype_Indication
(Parent
(Priv_T
));
12020 Priv_Constr
: constant Boolean :=
12021 Is_Constrained
(Priv_Parent
)
12023 Nkind
(Priv_Indic
) = N_Subtype_Indication
12024 or else Is_Constrained
(Entity
(Priv_Indic
));
12026 Full_Constr
: constant Boolean :=
12027 Is_Constrained
(Full_Parent
)
12029 Nkind
(Full_Indic
) = N_Subtype_Indication
12030 or else Is_Constrained
(Entity
(Full_Indic
));
12032 Priv_Discr
: Entity_Id
;
12033 Full_Discr
: Entity_Id
;
12036 Priv_Discr
:= First_Discriminant
(Priv_Parent
);
12037 Full_Discr
:= First_Discriminant
(Full_Parent
);
12039 while Present
(Priv_Discr
) and then Present
(Full_Discr
) loop
12040 if Original_Record_Component
(Priv_Discr
) =
12041 Original_Record_Component
(Full_Discr
)
12043 Corresponding_Discriminant
(Priv_Discr
) =
12044 Corresponding_Discriminant
(Full_Discr
)
12051 Next_Discriminant
(Priv_Discr
);
12052 Next_Discriminant
(Full_Discr
);
12055 if Present
(Priv_Discr
) or else Present
(Full_Discr
) then
12057 ("full view must inherit discriminants of the parent type"
12058 & " used in the private extension", Full_Indic
);
12060 elsif Priv_Constr
and then not Full_Constr
then
12062 ("parent subtype of full type must be constrained",
12065 elsif Full_Constr
and then not Priv_Constr
then
12067 ("parent subtype of full type must be unconstrained",
12072 -- Check the rules of 7.3(12): if a partial view has neither known
12073 -- or unknown discriminants, then the full type declaration shall
12074 -- define a definite subtype.
12076 elsif not Has_Unknown_Discriminants
(Priv_T
)
12077 and then not Has_Discriminants
(Priv_T
)
12078 and then not Is_Constrained
(Full_T
)
12081 ("full view must define a constrained type if partial view"
12082 & " has no discriminants", Full_T
);
12085 -- ??????? Do we implement the following properly ?????
12086 -- If the ancestor subtype of a private extension has constrained
12087 -- discriminants, then the parent subtype of the full view shall
12088 -- impose a statically matching constraint on those discriminants
12092 -- For untagged types, verify that a type without discriminants
12093 -- is not completed with an unconstrained type.
12095 if not Is_Indefinite_Subtype
(Priv_T
)
12096 and then Is_Indefinite_Subtype
(Full_T
)
12098 Error_Msg_N
("full view of type must be definite subtype", Full_T
);
12102 -- Create a full declaration for all its subtypes recorded in
12103 -- Private_Dependents and swap them similarly to the base type. These
12104 -- are subtypes that have been define before the full declaration of
12105 -- the private type. We also swap the entry in Private_Dependents list
12106 -- so we can properly restore the private view on exit from the scope.
12109 Priv_Elmt
: Elmt_Id
;
12114 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Priv_T
));
12115 while Present
(Priv_Elmt
) loop
12116 Priv
:= Node
(Priv_Elmt
);
12118 if Ekind
(Priv
) = E_Private_Subtype
12119 or else Ekind
(Priv
) = E_Limited_Private_Subtype
12120 or else Ekind
(Priv
) = E_Record_Subtype_With_Private
12122 Full
:= Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
12123 Set_Is_Itype
(Full
);
12124 Set_Parent
(Full
, Parent
(Priv
));
12125 Set_Associated_Node_For_Itype
(Full
, N
);
12127 -- Now we need to complete the private subtype, but since the
12128 -- base type has already been swapped, we must also swap the
12129 -- subtypes (and thus, reverse the arguments in the call to
12130 -- Complete_Private_Subtype).
12132 Copy_And_Swap
(Priv
, Full
);
12133 Complete_Private_Subtype
(Full
, Priv
, Full_T
, N
);
12134 Replace_Elmt
(Priv_Elmt
, Full
);
12137 Next_Elmt
(Priv_Elmt
);
12141 -- If the private view was tagged, copy the new Primitive
12142 -- operations from the private view to the full view.
12144 if Is_Tagged_Type
(Full_T
) then
12146 Priv_List
: Elist_Id
;
12147 Full_List
: constant Elist_Id
:= Primitive_Operations
(Full_T
);
12150 D_Type
: Entity_Id
;
12153 if Is_Tagged_Type
(Priv_T
) then
12154 Priv_List
:= Primitive_Operations
(Priv_T
);
12156 P1
:= First_Elmt
(Priv_List
);
12157 while Present
(P1
) loop
12160 -- Transfer explicit primitives, not those inherited from
12161 -- parent of partial view, which will be re-inherited on
12164 if Comes_From_Source
(Prim
) then
12165 P2
:= First_Elmt
(Full_List
);
12166 while Present
(P2
) and then Node
(P2
) /= Prim
loop
12170 -- If not found, that is a new one
12173 Append_Elmt
(Prim
, Full_List
);
12181 -- In this case the partial view is untagged, so here we
12182 -- locate all of the earlier primitives that need to be
12183 -- treated as dispatching (those that appear between the two
12184 -- views). Note that these additional operations must all be
12185 -- new operations (any earlier operations that override
12186 -- inherited operations of the full view will already have
12187 -- been inserted in the primitives list and marked as
12188 -- dispatching by Check_Operation_From_Private_View. Note that
12189 -- implicit "/=" operators are excluded from being added to
12190 -- the primitives list since they shouldn't be treated as
12191 -- dispatching (tagged "/=" is handled specially).
12193 Prim
:= Next_Entity
(Full_T
);
12194 while Present
(Prim
) and then Prim
/= Priv_T
loop
12195 if Ekind
(Prim
) = E_Procedure
12197 Ekind
(Prim
) = E_Function
12200 D_Type
:= Find_Dispatching_Type
(Prim
);
12203 and then (Chars
(Prim
) /= Name_Op_Ne
12204 or else Comes_From_Source
(Prim
))
12206 Check_Controlling_Formals
(Full_T
, Prim
);
12208 if not Is_Dispatching_Operation
(Prim
) then
12209 Append_Elmt
(Prim
, Full_List
);
12210 Set_Is_Dispatching_Operation
(Prim
, True);
12211 Set_DT_Position
(Prim
, No_Uint
);
12214 elsif Is_Dispatching_Operation
(Prim
)
12215 and then D_Type
/= Full_T
12218 -- Verify that it is not otherwise controlled by
12219 -- a formal or a return value ot type T.
12221 Check_Controlling_Formals
(D_Type
, Prim
);
12225 Next_Entity
(Prim
);
12229 -- For the tagged case, the two views can share the same
12230 -- Primitive Operation list and the same class wide type.
12231 -- Update attributes of the class-wide type which depend on
12232 -- the full declaration.
12234 if Is_Tagged_Type
(Priv_T
) then
12235 Set_Primitive_Operations
(Priv_T
, Full_List
);
12236 Set_Class_Wide_Type
12237 (Base_Type
(Full_T
), Class_Wide_Type
(Priv_T
));
12239 -- Any other attributes should be propagated to C_W ???
12241 Set_Has_Task
(Class_Wide_Type
(Priv_T
), Has_Task
(Full_T
));
12246 end Process_Full_View
;
12248 -----------------------------------
12249 -- Process_Incomplete_Dependents --
12250 -----------------------------------
12252 procedure Process_Incomplete_Dependents
12254 Full_T
: Entity_Id
;
12257 Inc_Elmt
: Elmt_Id
;
12258 Priv_Dep
: Entity_Id
;
12259 New_Subt
: Entity_Id
;
12261 Disc_Constraint
: Elist_Id
;
12264 if No
(Private_Dependents
(Inc_T
)) then
12268 Inc_Elmt
:= First_Elmt
(Private_Dependents
(Inc_T
));
12270 -- Itypes that may be generated by the completion of an incomplete
12271 -- subtype are not used by the back-end and not attached to the tree.
12272 -- They are created only for constraint-checking purposes.
12275 while Present
(Inc_Elmt
) loop
12276 Priv_Dep
:= Node
(Inc_Elmt
);
12278 if Ekind
(Priv_Dep
) = E_Subprogram_Type
then
12280 -- An Access_To_Subprogram type may have a return type or a
12281 -- parameter type that is incomplete. Replace with the full view.
12283 if Etype
(Priv_Dep
) = Inc_T
then
12284 Set_Etype
(Priv_Dep
, Full_T
);
12288 Formal
: Entity_Id
;
12291 Formal
:= First_Formal
(Priv_Dep
);
12293 while Present
(Formal
) loop
12295 if Etype
(Formal
) = Inc_T
then
12296 Set_Etype
(Formal
, Full_T
);
12299 Next_Formal
(Formal
);
12303 elsif Is_Overloadable
(Priv_Dep
) then
12305 if Is_Tagged_Type
(Full_T
) then
12307 -- Subprogram has an access parameter whose designated type
12308 -- was incomplete. Reexamine declaration now, because it may
12309 -- be a primitive operation of the full type.
12311 Check_Operation_From_Incomplete_Type
(Priv_Dep
, Inc_T
);
12312 Set_Is_Dispatching_Operation
(Priv_Dep
);
12313 Check_Controlling_Formals
(Full_T
, Priv_Dep
);
12316 elsif Ekind
(Priv_Dep
) = E_Subprogram_Body
then
12318 -- Can happen during processing of a body before the completion
12319 -- of a TA type. Ignore, because spec is also on dependent list.
12323 -- Dependent is a subtype
12326 -- We build a new subtype indication using the full view of the
12327 -- incomplete parent. The discriminant constraints have been
12328 -- elaborated already at the point of the subtype declaration.
12330 New_Subt
:= Create_Itype
(E_Void
, N
);
12332 if Has_Discriminants
(Full_T
) then
12333 Disc_Constraint
:= Discriminant_Constraint
(Priv_Dep
);
12335 Disc_Constraint
:= No_Elist
;
12338 Build_Discriminated_Subtype
(Full_T
, New_Subt
, Disc_Constraint
, N
);
12339 Set_Full_View
(Priv_Dep
, New_Subt
);
12342 Next_Elmt
(Inc_Elmt
);
12344 end Process_Incomplete_Dependents
;
12346 --------------------------------
12347 -- Process_Range_Expr_In_Decl --
12348 --------------------------------
12350 procedure Process_Range_Expr_In_Decl
12353 Check_List
: List_Id
:= Empty_List
;
12354 R_Check_Off
: Boolean := False)
12357 R_Checks
: Check_Result
;
12358 Type_Decl
: Node_Id
;
12359 Def_Id
: Entity_Id
;
12362 Analyze_And_Resolve
(R
, Base_Type
(T
));
12364 if Nkind
(R
) = N_Range
then
12365 Lo
:= Low_Bound
(R
);
12366 Hi
:= High_Bound
(R
);
12368 -- If there were errors in the declaration, try and patch up some
12369 -- common mistakes in the bounds. The cases handled are literals
12370 -- which are Integer where the expected type is Real and vice versa.
12371 -- These corrections allow the compilation process to proceed further
12372 -- along since some basic assumptions of the format of the bounds
12375 if Etype
(R
) = Any_Type
then
12377 if Nkind
(Lo
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
12379 Make_Real_Literal
(Sloc
(Lo
), UR_From_Uint
(Intval
(Lo
))));
12381 elsif Nkind
(Hi
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
12383 Make_Real_Literal
(Sloc
(Hi
), UR_From_Uint
(Intval
(Hi
))));
12385 elsif Nkind
(Lo
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
12387 Make_Integer_Literal
(Sloc
(Lo
), UR_To_Uint
(Realval
(Lo
))));
12389 elsif Nkind
(Hi
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
12391 Make_Integer_Literal
(Sloc
(Hi
), UR_To_Uint
(Realval
(Hi
))));
12398 -- If the bounds of the range have been mistakenly given as string
12399 -- literals (perhaps in place of character literals), then an error
12400 -- has already been reported, but we rewrite the string literal as a
12401 -- bound of the range's type to avoid blowups in later processing
12402 -- that looks at static values.
12404 if Nkind
(Lo
) = N_String_Literal
then
12406 Make_Attribute_Reference
(Sloc
(Lo
),
12407 Attribute_Name
=> Name_First
,
12408 Prefix
=> New_Reference_To
(T
, Sloc
(Lo
))));
12409 Analyze_And_Resolve
(Lo
);
12412 if Nkind
(Hi
) = N_String_Literal
then
12414 Make_Attribute_Reference
(Sloc
(Hi
),
12415 Attribute_Name
=> Name_First
,
12416 Prefix
=> New_Reference_To
(T
, Sloc
(Hi
))));
12417 Analyze_And_Resolve
(Hi
);
12420 -- If bounds aren't scalar at this point then exit, avoiding
12421 -- problems with further processing of the range in this procedure.
12423 if not Is_Scalar_Type
(Etype
(Lo
)) then
12427 -- Resolve (actually Sem_Eval) has checked that the bounds are in
12428 -- then range of the base type. Here we check whether the bounds
12429 -- are in the range of the subtype itself. Note that if the bounds
12430 -- represent the null range the Constraint_Error exception should
12433 -- ??? The following code should be cleaned up as follows
12435 -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
12436 -- is done in the call to Range_Check (R, T); below
12438 -- 2. The use of R_Check_Off should be investigated and possibly
12439 -- removed, this would clean up things a bit.
12441 if Is_Null_Range
(Lo
, Hi
) then
12445 -- Capture values of bounds and generate temporaries for them
12446 -- if needed, before applying checks, since checks may cause
12447 -- duplication of the expression without forcing evaluation.
12449 if Expander_Active
then
12450 Force_Evaluation
(Lo
);
12451 Force_Evaluation
(Hi
);
12454 -- We use a flag here instead of suppressing checks on the
12455 -- type because the type we check against isn't necessarily
12456 -- the place where we put the check.
12458 if not R_Check_Off
then
12459 R_Checks
:= Range_Check
(R
, T
);
12460 Type_Decl
:= Parent
(R
);
12462 -- Look up tree to find an appropriate insertion point.
12463 -- This seems really junk code, and very brittle, couldn't
12464 -- we just use an insert actions call of some kind ???
12466 while Present
(Type_Decl
) and then not
12467 (Nkind
(Type_Decl
) = N_Full_Type_Declaration
12469 Nkind
(Type_Decl
) = N_Subtype_Declaration
12471 Nkind
(Type_Decl
) = N_Loop_Statement
12473 Nkind
(Type_Decl
) = N_Task_Type_Declaration
12475 Nkind
(Type_Decl
) = N_Single_Task_Declaration
12477 Nkind
(Type_Decl
) = N_Protected_Type_Declaration
12479 Nkind
(Type_Decl
) = N_Single_Protected_Declaration
)
12481 Type_Decl
:= Parent
(Type_Decl
);
12484 -- Why would Type_Decl not be present??? Without this test,
12485 -- short regression tests fail.
12487 if Present
(Type_Decl
) then
12489 -- Case of loop statement (more comments ???)
12491 if Nkind
(Type_Decl
) = N_Loop_Statement
then
12493 Indic
: Node_Id
:= Parent
(R
);
12496 while Present
(Indic
) and then not
12497 (Nkind
(Indic
) = N_Subtype_Indication
)
12499 Indic
:= Parent
(Indic
);
12502 if Present
(Indic
) then
12503 Def_Id
:= Etype
(Subtype_Mark
(Indic
));
12505 Insert_Range_Checks
12511 Do_Before
=> True);
12515 -- All other cases (more comments ???)
12518 Def_Id
:= Defining_Identifier
(Type_Decl
);
12520 if (Ekind
(Def_Id
) = E_Record_Type
12521 and then Depends_On_Discriminant
(R
))
12523 (Ekind
(Def_Id
) = E_Protected_Type
12524 and then Has_Discriminants
(Def_Id
))
12526 Append_Range_Checks
12527 (R_Checks
, Check_List
, Def_Id
, Sloc
(Type_Decl
), R
);
12530 Insert_Range_Checks
12531 (R_Checks
, Type_Decl
, Def_Id
, Sloc
(Type_Decl
), R
);
12539 elsif Expander_Active
then
12540 Get_Index_Bounds
(R
, Lo
, Hi
);
12541 Force_Evaluation
(Lo
);
12542 Force_Evaluation
(Hi
);
12544 end Process_Range_Expr_In_Decl
;
12546 --------------------------------------
12547 -- Process_Real_Range_Specification --
12548 --------------------------------------
12550 procedure Process_Real_Range_Specification
(Def
: Node_Id
) is
12551 Spec
: constant Node_Id
:= Real_Range_Specification
(Def
);
12554 Err
: Boolean := False;
12556 procedure Analyze_Bound
(N
: Node_Id
);
12557 -- Analyze and check one bound
12559 -------------------
12560 -- Analyze_Bound --
12561 -------------------
12563 procedure Analyze_Bound
(N
: Node_Id
) is
12565 Analyze_And_Resolve
(N
, Any_Real
);
12567 if not Is_OK_Static_Expression
(N
) then
12568 Flag_Non_Static_Expr
12569 ("bound in real type definition is not static!", N
);
12574 -- Start of processing for Process_Real_Range_Specification
12577 if Present
(Spec
) then
12578 Lo
:= Low_Bound
(Spec
);
12579 Hi
:= High_Bound
(Spec
);
12580 Analyze_Bound
(Lo
);
12581 Analyze_Bound
(Hi
);
12583 -- If error, clear away junk range specification
12586 Set_Real_Range_Specification
(Def
, Empty
);
12589 end Process_Real_Range_Specification
;
12591 ---------------------
12592 -- Process_Subtype --
12593 ---------------------
12595 function Process_Subtype
12597 Related_Nod
: Node_Id
;
12598 Related_Id
: Entity_Id
:= Empty
;
12599 Suffix
: Character := ' ') return Entity_Id
12602 Def_Id
: Entity_Id
;
12603 Full_View_Id
: Entity_Id
;
12604 Subtype_Mark_Id
: Entity_Id
;
12606 procedure Check_Incomplete
(T
: Entity_Id
);
12607 -- Called to verify that an incomplete type is not used prematurely
12609 ----------------------
12610 -- Check_Incomplete --
12611 ----------------------
12613 procedure Check_Incomplete
(T
: Entity_Id
) is
12615 if Ekind
(Root_Type
(Entity
(T
))) = E_Incomplete_Type
then
12616 Error_Msg_N
("invalid use of type before its full declaration", T
);
12618 end Check_Incomplete
;
12620 -- Start of processing for Process_Subtype
12623 -- Case of no constraints present
12625 if Nkind
(S
) /= N_Subtype_Indication
then
12628 Check_Incomplete
(S
);
12630 -- Ada 2005 (AI-231): Static check
12632 if Ada_Version
>= Ada_05
12633 and then Present
(Parent
(S
))
12634 and then Null_Exclusion_Present
(Parent
(S
))
12635 and then Nkind
(Parent
(S
)) /= N_Access_To_Object_Definition
12636 and then not Is_Access_Type
(Entity
(S
))
12639 ("(Ada 2005) null-exclusion part requires an access type", S
);
12643 -- Case of constraint present, so that we have an N_Subtype_Indication
12644 -- node (this node is created only if constraints are present).
12648 Find_Type
(Subtype_Mark
(S
));
12650 if Nkind
(Parent
(S
)) /= N_Access_To_Object_Definition
12652 (Nkind
(Parent
(S
)) = N_Subtype_Declaration
12654 Is_Itype
(Defining_Identifier
(Parent
(S
))))
12656 Check_Incomplete
(Subtype_Mark
(S
));
12660 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
12662 -- Explicit subtype declaration case
12664 if Nkind
(P
) = N_Subtype_Declaration
then
12665 Def_Id
:= Defining_Identifier
(P
);
12667 -- Explicit derived type definition case
12669 elsif Nkind
(P
) = N_Derived_Type_Definition
then
12670 Def_Id
:= Defining_Identifier
(Parent
(P
));
12672 -- Implicit case, the Def_Id must be created as an implicit type.
12673 -- The one exception arises in the case of concurrent types, array
12674 -- and access types, where other subsidiary implicit types may be
12675 -- created and must appear before the main implicit type. In these
12676 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
12677 -- has not yet been called to create Def_Id.
12680 if Is_Array_Type
(Subtype_Mark_Id
)
12681 or else Is_Concurrent_Type
(Subtype_Mark_Id
)
12682 or else Is_Access_Type
(Subtype_Mark_Id
)
12686 -- For the other cases, we create a new unattached Itype,
12687 -- and set the indication to ensure it gets attached later.
12691 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
12695 -- If the kind of constraint is invalid for this kind of type,
12696 -- then give an error, and then pretend no constraint was given.
12698 if not Is_Valid_Constraint_Kind
12699 (Ekind
(Subtype_Mark_Id
), Nkind
(Constraint
(S
)))
12702 ("incorrect constraint for this kind of type", Constraint
(S
));
12704 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
12706 -- Set Ekind of orphan itype, to prevent cascaded errors.
12708 if Present
(Def_Id
) then
12709 Set_Ekind
(Def_Id
, Ekind
(Any_Type
));
12712 -- Make recursive call, having got rid of the bogus constraint
12714 return Process_Subtype
(S
, Related_Nod
, Related_Id
, Suffix
);
12717 -- Remaining processing depends on type
12719 case Ekind
(Subtype_Mark_Id
) is
12720 when Access_Kind
=>
12721 Constrain_Access
(Def_Id
, S
, Related_Nod
);
12724 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
12726 when Decimal_Fixed_Point_Kind
=>
12727 Constrain_Decimal
(Def_Id
, S
);
12729 when Enumeration_Kind
=>
12730 Constrain_Enumeration
(Def_Id
, S
);
12732 when Ordinary_Fixed_Point_Kind
=>
12733 Constrain_Ordinary_Fixed
(Def_Id
, S
);
12736 Constrain_Float
(Def_Id
, S
);
12738 when Integer_Kind
=>
12739 Constrain_Integer
(Def_Id
, S
);
12741 when E_Record_Type |
12744 E_Incomplete_Type
=>
12745 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
12747 when Private_Kind
=>
12748 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
12749 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
12751 -- In case of an invalid constraint prevent further processing
12752 -- since the type constructed is missing expected fields.
12754 if Etype
(Def_Id
) = Any_Type
then
12758 -- If the full view is that of a task with discriminants,
12759 -- we must constrain both the concurrent type and its
12760 -- corresponding record type. Otherwise we will just propagate
12761 -- the constraint to the full view, if available.
12763 if Present
(Full_View
(Subtype_Mark_Id
))
12764 and then Has_Discriminants
(Subtype_Mark_Id
)
12765 and then Is_Concurrent_Type
(Full_View
(Subtype_Mark_Id
))
12768 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
12770 Set_Entity
(Subtype_Mark
(S
), Full_View
(Subtype_Mark_Id
));
12771 Constrain_Concurrent
(Full_View_Id
, S
,
12772 Related_Nod
, Related_Id
, Suffix
);
12773 Set_Entity
(Subtype_Mark
(S
), Subtype_Mark_Id
);
12774 Set_Full_View
(Def_Id
, Full_View_Id
);
12777 Prepare_Private_Subtype_Completion
(Def_Id
, Related_Nod
);
12780 when Concurrent_Kind
=>
12781 Constrain_Concurrent
(Def_Id
, S
,
12782 Related_Nod
, Related_Id
, Suffix
);
12785 Error_Msg_N
("invalid subtype mark in subtype indication", S
);
12788 -- Size and Convention are always inherited from the base type
12790 Set_Size_Info
(Def_Id
, (Subtype_Mark_Id
));
12791 Set_Convention
(Def_Id
, Convention
(Subtype_Mark_Id
));
12795 end Process_Subtype
;
12797 -----------------------------
12798 -- Record_Type_Declaration --
12799 -----------------------------
12801 procedure Record_Type_Declaration
12806 Def
: constant Node_Id
:= Type_Definition
(N
);
12808 Is_Tagged
: Boolean;
12809 Tag_Comp
: Entity_Id
;
12812 -- The flag Is_Tagged_Type might have already been set by Find_Type_Name
12813 -- if it detected an error for declaration T. This arises in the case of
12814 -- private tagged types where the full view omits the word tagged.
12817 Tagged_Present
(Def
)
12818 or else (Serious_Errors_Detected
> 0 and then Is_Tagged_Type
(T
));
12820 -- Records constitute a scope for the component declarations within.
12821 -- The scope is created prior to the processing of these declarations.
12822 -- Discriminants are processed first, so that they are visible when
12823 -- processing the other components. The Ekind of the record type itself
12824 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
12826 -- Enter record scope
12830 -- These flags must be initialized before calling Process_Discriminants
12831 -- because this routine makes use of them.
12833 Set_Is_Tagged_Type
(T
, Is_Tagged
);
12834 Set_Is_Limited_Record
(T
, Limited_Present
(Def
));
12836 -- Type is abstract if full declaration carries keyword, or if
12837 -- previous partial view did.
12839 Set_Is_Abstract
(T
, Is_Abstract
(T
) or else Abstract_Present
(Def
));
12841 Set_Ekind
(T
, E_Record_Type
);
12843 Init_Size_Align
(T
);
12845 Set_Stored_Constraint
(T
, No_Elist
);
12847 -- If an incomplete or private type declaration was already given for
12848 -- the type, then this scope already exists, and the discriminants have
12849 -- been declared within. We must verify that the full declaration
12850 -- matches the incomplete one.
12852 Check_Or_Process_Discriminants
(N
, T
, Prev
);
12854 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
12855 Set_Has_Delayed_Freeze
(T
, True);
12857 -- For tagged types add a manually analyzed component corresponding
12858 -- to the component _tag, the corresponding piece of tree will be
12859 -- expanded as part of the freezing actions if it is not a CPP_Class.
12863 -- Do not add the tag unless we are in expansion mode
12865 if Expander_Active
then
12866 Tag_Comp
:= Make_Defining_Identifier
(Sloc
(Def
), Name_uTag
);
12867 Enter_Name
(Tag_Comp
);
12869 Set_Is_Tag
(Tag_Comp
);
12870 Set_Ekind
(Tag_Comp
, E_Component
);
12871 Set_Etype
(Tag_Comp
, RTE
(RE_Tag
));
12872 Set_DT_Entry_Count
(Tag_Comp
, No_Uint
);
12873 Set_Original_Record_Component
(Tag_Comp
, Tag_Comp
);
12874 Init_Component_Location
(Tag_Comp
);
12877 Make_Class_Wide_Type
(T
);
12878 Set_Primitive_Operations
(T
, New_Elmt_List
);
12881 -- We must suppress range checks when processing the components
12882 -- of a record in the presence of discriminants, since we don't
12883 -- want spurious checks to be generated during their analysis, but
12884 -- must reset the Suppress_Range_Checks flags after having processed
12885 -- the record definition.
12887 if Has_Discriminants
(T
) and then not Range_Checks_Suppressed
(T
) then
12888 Set_Kill_Range_Checks
(T
, True);
12889 Record_Type_Definition
(Def
, Prev
);
12890 Set_Kill_Range_Checks
(T
, False);
12892 Record_Type_Definition
(Def
, Prev
);
12895 -- Exit from record scope
12898 end Record_Type_Declaration
;
12900 ----------------------------
12901 -- Record_Type_Definition --
12902 ----------------------------
12904 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
) is
12905 Component
: Entity_Id
;
12906 Ctrl_Components
: Boolean := False;
12907 Final_Storage_Only
: Boolean;
12911 if Ekind
(Prev_T
) = E_Incomplete_Type
then
12912 T
:= Full_View
(Prev_T
);
12917 Final_Storage_Only
:= not Is_Controlled
(T
);
12919 -- If the component list of a record type is defined by the reserved
12920 -- word null and there is no discriminant part, then the record type has
12921 -- no components and all records of the type are null records (RM 3.7)
12922 -- This procedure is also called to process the extension part of a
12923 -- record extension, in which case the current scope may have inherited
12927 or else No
(Component_List
(Def
))
12928 or else Null_Present
(Component_List
(Def
))
12933 Analyze_Declarations
(Component_Items
(Component_List
(Def
)));
12935 if Present
(Variant_Part
(Component_List
(Def
))) then
12936 Analyze
(Variant_Part
(Component_List
(Def
)));
12940 -- After completing the semantic analysis of the record definition,
12941 -- record components, both new and inherited, are accessible. Set
12942 -- their kind accordingly.
12944 Component
:= First_Entity
(Current_Scope
);
12945 while Present
(Component
) loop
12946 if Ekind
(Component
) = E_Void
then
12947 Set_Ekind
(Component
, E_Component
);
12948 Init_Component_Location
(Component
);
12951 if Has_Task
(Etype
(Component
)) then
12955 if Ekind
(Component
) /= E_Component
then
12958 elsif Has_Controlled_Component
(Etype
(Component
))
12959 or else (Chars
(Component
) /= Name_uParent
12960 and then Is_Controlled
(Etype
(Component
)))
12962 Set_Has_Controlled_Component
(T
, True);
12963 Final_Storage_Only
:= Final_Storage_Only
12964 and then Finalize_Storage_Only
(Etype
(Component
));
12965 Ctrl_Components
:= True;
12968 Next_Entity
(Component
);
12971 -- A type is Finalize_Storage_Only only if all its controlled
12972 -- components are so.
12974 if Ctrl_Components
then
12975 Set_Finalize_Storage_Only
(T
, Final_Storage_Only
);
12978 -- Place reference to end record on the proper entity, which may
12979 -- be a partial view.
12981 if Present
(Def
) then
12982 Process_End_Label
(Def
, 'e', Prev_T
);
12984 end Record_Type_Definition
;
12986 ------------------------
12987 -- Replace_Components --
12988 ------------------------
12990 procedure Replace_Components
(Typ
: Entity_Id
; Decl
: Node_Id
) is
12991 function Process
(N
: Node_Id
) return Traverse_Result
;
12997 function Process
(N
: Node_Id
) return Traverse_Result
is
13001 if Nkind
(N
) = N_Discriminant_Specification
then
13002 Comp
:= First_Discriminant
(Typ
);
13004 while Present
(Comp
) loop
13005 if Chars
(Comp
) = Chars
(Defining_Identifier
(N
)) then
13006 Set_Defining_Identifier
(N
, Comp
);
13010 Next_Discriminant
(Comp
);
13013 elsif Nkind
(N
) = N_Component_Declaration
then
13014 Comp
:= First_Component
(Typ
);
13016 while Present
(Comp
) loop
13017 if Chars
(Comp
) = Chars
(Defining_Identifier
(N
)) then
13018 Set_Defining_Identifier
(N
, Comp
);
13022 Next_Component
(Comp
);
13029 procedure Replace
is new Traverse_Proc
(Process
);
13031 -- Start of processing for Replace_Components
13035 end Replace_Components
;
13037 -------------------------------
13038 -- Set_Completion_Referenced --
13039 -------------------------------
13041 procedure Set_Completion_Referenced
(E
: Entity_Id
) is
13043 -- If in main unit, mark entity that is a completion as referenced,
13044 -- warnings go on the partial view when needed.
13046 if In_Extended_Main_Source_Unit
(E
) then
13047 Set_Referenced
(E
);
13049 end Set_Completion_Referenced
;
13051 ---------------------
13052 -- Set_Fixed_Range --
13053 ---------------------
13055 -- The range for fixed-point types is complicated by the fact that we
13056 -- do not know the exact end points at the time of the declaration. This
13057 -- is true for three reasons:
13059 -- A size clause may affect the fudging of the end-points
13060 -- A small clause may affect the values of the end-points
13061 -- We try to include the end-points if it does not affect the size
13063 -- This means that the actual end-points must be established at the point
13064 -- when the type is frozen. Meanwhile, we first narrow the range as
13065 -- permitted (so that it will fit if necessary in a small specified size),
13066 -- and then build a range subtree with these narrowed bounds.
13068 -- Set_Fixed_Range constructs the range from real literal values, and sets
13069 -- the range as the Scalar_Range of the given fixed-point type entity.
13071 -- The parent of this range is set to point to the entity so that it is
13072 -- properly hooked into the tree (unlike normal Scalar_Range entries for
13073 -- other scalar types, which are just pointers to the range in the
13074 -- original tree, this would otherwise be an orphan).
13076 -- The tree is left unanalyzed. When the type is frozen, the processing
13077 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
13078 -- analyzed, and uses this as an indication that it should complete
13079 -- work on the range (it will know the final small and size values).
13081 procedure Set_Fixed_Range
13087 S
: constant Node_Id
:=
13089 Low_Bound
=> Make_Real_Literal
(Loc
, Lo
),
13090 High_Bound
=> Make_Real_Literal
(Loc
, Hi
));
13093 Set_Scalar_Range
(E
, S
);
13095 end Set_Fixed_Range
;
13097 ----------------------------------
13098 -- Set_Scalar_Range_For_Subtype --
13099 ----------------------------------
13101 procedure Set_Scalar_Range_For_Subtype
13102 (Def_Id
: Entity_Id
;
13106 Kind
: constant Entity_Kind
:= Ekind
(Def_Id
);
13109 Set_Scalar_Range
(Def_Id
, R
);
13111 -- We need to link the range into the tree before resolving it so
13112 -- that types that are referenced, including importantly the subtype
13113 -- itself, are properly frozen (Freeze_Expression requires that the
13114 -- expression be properly linked into the tree). Of course if it is
13115 -- already linked in, then we do not disturb the current link.
13117 if No
(Parent
(R
)) then
13118 Set_Parent
(R
, Def_Id
);
13121 -- Reset the kind of the subtype during analysis of the range, to
13122 -- catch possible premature use in the bounds themselves.
13124 Set_Ekind
(Def_Id
, E_Void
);
13125 Process_Range_Expr_In_Decl
(R
, Subt
);
13126 Set_Ekind
(Def_Id
, Kind
);
13128 end Set_Scalar_Range_For_Subtype
;
13130 --------------------------------------------------------
13131 -- Set_Stored_Constraint_From_Discriminant_Constraint --
13132 --------------------------------------------------------
13134 procedure Set_Stored_Constraint_From_Discriminant_Constraint
13138 -- Make sure set if encountered during Expand_To_Stored_Constraint
13140 Set_Stored_Constraint
(E
, No_Elist
);
13142 -- Give it the right value
13144 if Is_Constrained
(E
) and then Has_Discriminants
(E
) then
13145 Set_Stored_Constraint
(E
,
13146 Expand_To_Stored_Constraint
(E
, Discriminant_Constraint
(E
)));
13148 end Set_Stored_Constraint_From_Discriminant_Constraint
;
13150 -------------------------------------
13151 -- Signed_Integer_Type_Declaration --
13152 -------------------------------------
13154 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
13155 Implicit_Base
: Entity_Id
;
13156 Base_Typ
: Entity_Id
;
13159 Errs
: Boolean := False;
13163 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
13164 -- Determine whether given bounds allow derivation from specified type
13166 procedure Check_Bound
(Expr
: Node_Id
);
13167 -- Check bound to make sure it is integral and static. If not, post
13168 -- appropriate error message and set Errs flag
13170 ---------------------
13171 -- Can_Derive_From --
13172 ---------------------
13174 -- Note we check both bounds against both end values, to deal with
13175 -- strange types like ones with a range of 0 .. -12341234.
13177 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
13178 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(E
));
13179 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(E
));
13181 return Lo
<= Lo_Val
and then Lo_Val
<= Hi
13183 Lo
<= Hi_Val
and then Hi_Val
<= Hi
;
13184 end Can_Derive_From
;
13190 procedure Check_Bound
(Expr
: Node_Id
) is
13192 -- If a range constraint is used as an integer type definition, each
13193 -- bound of the range must be defined by a static expression of some
13194 -- integer type, but the two bounds need not have the same integer
13195 -- type (Negative bounds are allowed.) (RM 3.5.4)
13197 if not Is_Integer_Type
(Etype
(Expr
)) then
13199 ("integer type definition bounds must be of integer type", Expr
);
13202 elsif not Is_OK_Static_Expression
(Expr
) then
13203 Flag_Non_Static_Expr
13204 ("non-static expression used for integer type bound!", Expr
);
13207 -- The bounds are folded into literals, and we set their type to be
13208 -- universal, to avoid typing difficulties: we cannot set the type
13209 -- of the literal to the new type, because this would be a forward
13210 -- reference for the back end, and if the original type is user-
13211 -- defined this can lead to spurious semantic errors (e.g. 2928-003).
13214 if Is_Entity_Name
(Expr
) then
13215 Fold_Uint
(Expr
, Expr_Value
(Expr
), True);
13218 Set_Etype
(Expr
, Universal_Integer
);
13222 -- Start of processing for Signed_Integer_Type_Declaration
13225 -- Create an anonymous base type
13228 Create_Itype
(E_Signed_Integer_Type
, Parent
(Def
), T
, 'B');
13230 -- Analyze and check the bounds, they can be of any integer type
13232 Lo
:= Low_Bound
(Def
);
13233 Hi
:= High_Bound
(Def
);
13235 -- Arbitrarily use Integer as the type if either bound had an error
13237 if Hi
= Error
or else Lo
= Error
then
13238 Base_Typ
:= Any_Integer
;
13239 Set_Error_Posted
(T
, True);
13241 -- Here both bounds are OK expressions
13244 Analyze_And_Resolve
(Lo
, Any_Integer
);
13245 Analyze_And_Resolve
(Hi
, Any_Integer
);
13251 Hi
:= Type_High_Bound
(Standard_Long_Long_Integer
);
13252 Lo
:= Type_Low_Bound
(Standard_Long_Long_Integer
);
13255 -- Find type to derive from
13257 Lo_Val
:= Expr_Value
(Lo
);
13258 Hi_Val
:= Expr_Value
(Hi
);
13260 if Can_Derive_From
(Standard_Short_Short_Integer
) then
13261 Base_Typ
:= Base_Type
(Standard_Short_Short_Integer
);
13263 elsif Can_Derive_From
(Standard_Short_Integer
) then
13264 Base_Typ
:= Base_Type
(Standard_Short_Integer
);
13266 elsif Can_Derive_From
(Standard_Integer
) then
13267 Base_Typ
:= Base_Type
(Standard_Integer
);
13269 elsif Can_Derive_From
(Standard_Long_Integer
) then
13270 Base_Typ
:= Base_Type
(Standard_Long_Integer
);
13272 elsif Can_Derive_From
(Standard_Long_Long_Integer
) then
13273 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
13276 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
13277 Error_Msg_N
("integer type definition bounds out of range", Def
);
13278 Hi
:= Type_High_Bound
(Standard_Long_Long_Integer
);
13279 Lo
:= Type_Low_Bound
(Standard_Long_Long_Integer
);
13283 -- Complete both implicit base and declared first subtype entities
13285 Set_Etype
(Implicit_Base
, Base_Typ
);
13286 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
13287 Set_Size_Info
(Implicit_Base
, (Base_Typ
));
13288 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
13289 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
13291 Set_Ekind
(T
, E_Signed_Integer_Subtype
);
13292 Set_Etype
(T
, Implicit_Base
);
13294 Set_Size_Info
(T
, (Implicit_Base
));
13295 Set_First_Rep_Item
(T
, First_Rep_Item
(Implicit_Base
));
13296 Set_Scalar_Range
(T
, Def
);
13297 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
13298 Set_Is_Constrained
(T
);
13299 end Signed_Integer_Type_Declaration
;