1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Elists
; use Elists
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
33 with Eval_Fat
; use Eval_Fat
;
34 with Exp_Ch3
; use Exp_Ch3
;
35 with Exp_Ch9
; use Exp_Ch9
;
36 with Exp_Disp
; use Exp_Disp
;
37 with Exp_Dist
; use Exp_Dist
;
38 with Exp_Tss
; use Exp_Tss
;
39 with Exp_Util
; use Exp_Util
;
40 with Fname
; use Fname
;
41 with Freeze
; use Freeze
;
42 with Ghost
; use Ghost
;
43 with Itypes
; use Itypes
;
44 with Layout
; use Layout
;
46 with Lib
.Xref
; use Lib
.Xref
;
47 with Namet
; use Namet
;
48 with Nmake
; use Nmake
;
50 with Restrict
; use Restrict
;
51 with Rident
; use Rident
;
52 with Rtsfind
; use Rtsfind
;
54 with Sem_Aux
; use Sem_Aux
;
55 with Sem_Case
; use Sem_Case
;
56 with Sem_Cat
; use Sem_Cat
;
57 with Sem_Ch6
; use Sem_Ch6
;
58 with Sem_Ch7
; use Sem_Ch7
;
59 with Sem_Ch8
; use Sem_Ch8
;
60 with Sem_Ch10
; use Sem_Ch10
;
61 with Sem_Ch12
; use Sem_Ch12
;
62 with Sem_Ch13
; use Sem_Ch13
;
63 with Sem_Dim
; use Sem_Dim
;
64 with Sem_Disp
; use Sem_Disp
;
65 with Sem_Dist
; use Sem_Dist
;
66 with Sem_Elim
; use Sem_Elim
;
67 with Sem_Eval
; use Sem_Eval
;
68 with Sem_Mech
; use Sem_Mech
;
69 with Sem_Prag
; use Sem_Prag
;
70 with Sem_Res
; use Sem_Res
;
71 with Sem_Smem
; use Sem_Smem
;
72 with Sem_Type
; use Sem_Type
;
73 with Sem_Util
; use Sem_Util
;
74 with Sem_Warn
; use Sem_Warn
;
75 with Stand
; use Stand
;
76 with Sinfo
; use Sinfo
;
77 with Sinput
; use Sinput
;
78 with Snames
; use Snames
;
79 with Targparm
; use Targparm
;
80 with Tbuild
; use Tbuild
;
81 with Ttypes
; use Ttypes
;
82 with Uintp
; use Uintp
;
83 with Urealp
; use Urealp
;
85 package body Sem_Ch3
is
87 -----------------------
88 -- Local Subprograms --
89 -----------------------
91 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
);
92 -- Ada 2005 (AI-251): Add the tag components corresponding to all the
93 -- abstract interface types implemented by a record type or a derived
96 procedure Analyze_Object_Contract
(Obj_Id
: Entity_Id
);
97 -- Analyze all delayed pragmas chained on the contract of object Obj_Id as
98 -- if they appeared at the end of the declarative region. The pragmas to be
106 procedure Build_Derived_Type
108 Parent_Type
: Entity_Id
;
109 Derived_Type
: Entity_Id
;
110 Is_Completion
: Boolean;
111 Derive_Subps
: Boolean := True);
112 -- Create and decorate a Derived_Type given the Parent_Type entity. N is
113 -- the N_Full_Type_Declaration node containing the derived type definition.
114 -- Parent_Type is the entity for the parent type in the derived type
115 -- definition and Derived_Type the actual derived type. Is_Completion must
116 -- be set to False if Derived_Type is the N_Defining_Identifier node in N
117 -- (i.e. Derived_Type = Defining_Identifier (N)). In this case N is not the
118 -- completion of a private type declaration. If Is_Completion is set to
119 -- True, N is the completion of a private type declaration and Derived_Type
120 -- is different from the defining identifier inside N (i.e. Derived_Type /=
121 -- Defining_Identifier (N)). Derive_Subps indicates whether the parent
122 -- subprograms should be derived. The only case where this parameter is
123 -- False is when Build_Derived_Type is recursively called to process an
124 -- implicit derived full type for a type derived from a private type (in
125 -- that case the subprograms must only be derived for the private view of
128 -- ??? These flags need a bit of re-examination and re-documentation:
129 -- ??? are they both necessary (both seem related to the recursion)?
131 procedure Build_Derived_Access_Type
133 Parent_Type
: Entity_Id
;
134 Derived_Type
: Entity_Id
);
135 -- Subsidiary procedure to Build_Derived_Type. For a derived access type,
136 -- create an implicit base if the parent type is constrained or if the
137 -- subtype indication has a constraint.
139 procedure Build_Derived_Array_Type
141 Parent_Type
: Entity_Id
;
142 Derived_Type
: Entity_Id
);
143 -- Subsidiary procedure to Build_Derived_Type. For a derived array type,
144 -- create an implicit base if the parent type is constrained or if the
145 -- subtype indication has a constraint.
147 procedure Build_Derived_Concurrent_Type
149 Parent_Type
: Entity_Id
;
150 Derived_Type
: Entity_Id
);
151 -- Subsidiary procedure to Build_Derived_Type. For a derived task or
152 -- protected type, inherit entries and protected subprograms, check
153 -- legality of discriminant constraints if any.
155 procedure Build_Derived_Enumeration_Type
157 Parent_Type
: Entity_Id
;
158 Derived_Type
: Entity_Id
);
159 -- Subsidiary procedure to Build_Derived_Type. For a derived enumeration
160 -- type, we must create a new list of literals. Types derived from
161 -- Character and [Wide_]Wide_Character are special-cased.
163 procedure Build_Derived_Numeric_Type
165 Parent_Type
: Entity_Id
;
166 Derived_Type
: Entity_Id
);
167 -- Subsidiary procedure to Build_Derived_Type. For numeric types, create
168 -- an anonymous base type, and propagate constraint to subtype if needed.
170 procedure Build_Derived_Private_Type
172 Parent_Type
: Entity_Id
;
173 Derived_Type
: Entity_Id
;
174 Is_Completion
: Boolean;
175 Derive_Subps
: Boolean := True);
176 -- Subsidiary procedure to Build_Derived_Type. This procedure is complex
177 -- because the parent may or may not have a completion, and the derivation
178 -- may itself be a completion.
180 procedure Build_Derived_Record_Type
182 Parent_Type
: Entity_Id
;
183 Derived_Type
: Entity_Id
;
184 Derive_Subps
: Boolean := True);
185 -- Subsidiary procedure used for tagged and untagged record types
186 -- by Build_Derived_Type and Analyze_Private_Extension_Declaration.
187 -- All parameters are as in Build_Derived_Type except that N, in
188 -- addition to being an N_Full_Type_Declaration node, can also be an
189 -- N_Private_Extension_Declaration node. See the definition of this routine
190 -- for much more info. Derive_Subps indicates whether subprograms should be
191 -- derived from the parent type. The only case where Derive_Subps is False
192 -- is for an implicit derived full type for a type derived from a private
193 -- type (see Build_Derived_Type).
195 procedure Build_Discriminal
(Discrim
: Entity_Id
);
196 -- Create the discriminal corresponding to discriminant Discrim, that is
197 -- the parameter corresponding to Discrim to be used in initialization
198 -- procedures for the type where Discrim is a discriminant. Discriminals
199 -- are not used during semantic analysis, and are not fully defined
200 -- entities until expansion. Thus they are not given a scope until
201 -- initialization procedures are built.
203 function Build_Discriminant_Constraints
206 Derived_Def
: Boolean := False) return Elist_Id
;
207 -- Validate discriminant constraints and return the list of the constraints
208 -- in order of discriminant declarations, where T is the discriminated
209 -- unconstrained type. Def is the N_Subtype_Indication node where the
210 -- discriminants constraints for T are specified. Derived_Def is True
211 -- when building the discriminant constraints in a derived type definition
212 -- of the form "type D (...) is new T (xxx)". In this case T is the parent
213 -- type and Def is the constraint "(xxx)" on T and this routine sets the
214 -- Corresponding_Discriminant field of the discriminants in the derived
215 -- type D to point to the corresponding discriminants in the parent type T.
217 procedure Build_Discriminated_Subtype
221 Related_Nod
: Node_Id
;
222 For_Access
: Boolean := False);
223 -- Subsidiary procedure to Constrain_Discriminated_Type and to
224 -- Process_Incomplete_Dependents. Given
226 -- T (a possibly discriminated base type)
227 -- Def_Id (a very partially built subtype for T),
229 -- the call completes Def_Id to be the appropriate E_*_Subtype.
231 -- The Elist is the list of discriminant constraints if any (it is set
232 -- to No_Elist if T is not a discriminated type, and to an empty list if
233 -- T has discriminants but there are no discriminant constraints). The
234 -- Related_Nod is the same as Decl_Node in Create_Constrained_Components.
235 -- The For_Access says whether or not this subtype is really constraining
236 -- an access type. That is its sole purpose is the designated type of an
237 -- access type -- in which case a Private_Subtype Is_For_Access_Subtype
238 -- is built to avoid freezing T when the access subtype is frozen.
240 function Build_Scalar_Bound
243 Der_T
: Entity_Id
) return Node_Id
;
244 -- The bounds of a derived scalar type are conversions of the bounds of
245 -- the parent type. Optimize the representation if the bounds are literals.
246 -- Needs a more complete spec--what are the parameters exactly, and what
247 -- exactly is the returned value, and how is Bound affected???
249 procedure Build_Underlying_Full_View
253 -- If the completion of a private type is itself derived from a private
254 -- type, or if the full view of a private subtype is itself private, the
255 -- back-end has no way to compute the actual size of this type. We build
256 -- an internal subtype declaration of the proper parent type to convey
257 -- this information. This extra mechanism is needed because a full
258 -- view cannot itself have a full view (it would get clobbered during
261 procedure Check_Access_Discriminant_Requires_Limited
264 -- Check the restriction that the type to which an access discriminant
265 -- belongs must be a concurrent type or a descendant of a type with
266 -- the reserved word 'limited' in its declaration.
268 procedure Check_Anonymous_Access_Components
272 Comp_List
: Node_Id
);
273 -- Ada 2005 AI-382: an access component in a record definition can refer to
274 -- the enclosing record, in which case it denotes the type itself, and not
275 -- the current instance of the type. We create an anonymous access type for
276 -- the component, and flag it as an access to a component, so accessibility
277 -- checks are properly performed on it. The declaration of the access type
278 -- is placed ahead of that of the record to prevent order-of-elaboration
279 -- circularity issues in Gigi. We create an incomplete type for the record
280 -- declaration, which is the designated type of the anonymous access.
282 procedure Check_Delta_Expression
(E
: Node_Id
);
283 -- Check that the expression represented by E is suitable for use as a
284 -- delta expression, i.e. it is of real type and is static.
286 procedure Check_Digits_Expression
(E
: Node_Id
);
287 -- Check that the expression represented by E is suitable for use as a
288 -- digits expression, i.e. it is of integer type, positive and static.
290 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
);
291 -- Validate the initialization of an object declaration. T is the required
292 -- type, and Exp is the initialization expression.
294 procedure Check_Interfaces
(N
: Node_Id
; Def
: Node_Id
);
295 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
297 procedure Check_Or_Process_Discriminants
300 Prev
: Entity_Id
:= Empty
);
301 -- If N is the full declaration of the completion T of an incomplete or
302 -- private type, check its discriminants (which are already known to be
303 -- conformant with those of the partial view, see Find_Type_Name),
304 -- otherwise process them. Prev is the entity of the partial declaration,
307 procedure Check_Real_Bound
(Bound
: Node_Id
);
308 -- Check given bound for being of real type and static. If not, post an
309 -- appropriate message, and rewrite the bound with the real literal zero.
311 procedure Constant_Redeclaration
315 -- Various checks on legality of full declaration of deferred constant.
316 -- Id is the entity for the redeclaration, N is the N_Object_Declaration,
317 -- node. The caller has not yet set any attributes of this entity.
319 function Contain_Interface
321 Ifaces
: Elist_Id
) return Boolean;
322 -- Ada 2005: Determine whether Iface is present in the list Ifaces
324 procedure Convert_Scalar_Bounds
326 Parent_Type
: Entity_Id
;
327 Derived_Type
: Entity_Id
;
329 -- For derived scalar types, convert the bounds in the type definition to
330 -- the derived type, and complete their analysis. Given a constraint of the
331 -- form ".. new T range Lo .. Hi", Lo and Hi are analyzed and resolved with
332 -- T'Base, the parent_type. The bounds of the derived type (the anonymous
333 -- base) are copies of Lo and Hi. Finally, the bounds of the derived
334 -- subtype are conversions of those bounds to the derived_type, so that
335 -- their typing is consistent.
337 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
);
338 -- Copies attributes from array base type T2 to array base type T1. Copies
339 -- only attributes that apply to base types, but not subtypes.
341 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
);
342 -- Copies attributes from array subtype T2 to array subtype T1. Copies
343 -- attributes that apply to both subtypes and base types.
345 procedure Create_Constrained_Components
349 Constraints
: Elist_Id
);
350 -- Build the list of entities for a constrained discriminated record
351 -- subtype. If a component depends on a discriminant, replace its subtype
352 -- using the discriminant values in the discriminant constraint. Subt
353 -- is the defining identifier for the subtype whose list of constrained
354 -- entities we will create. Decl_Node is the type declaration node where
355 -- we will attach all the itypes created. Typ is the base discriminated
356 -- type for the subtype Subt. Constraints is the list of discriminant
357 -- constraints for Typ.
359 function Constrain_Component_Type
361 Constrained_Typ
: Entity_Id
;
362 Related_Node
: Node_Id
;
364 Constraints
: Elist_Id
) return Entity_Id
;
365 -- Given a discriminated base type Typ, a list of discriminant constraints,
366 -- Constraints, for Typ and a component Comp of Typ, create and return the
367 -- type corresponding to Etype (Comp) where all discriminant references
368 -- are replaced with the corresponding constraint. If Etype (Comp) contains
369 -- no discriminant references then it is returned as-is. Constrained_Typ
370 -- is the final constrained subtype to which the constrained component
371 -- belongs. Related_Node is the node where we attach all created itypes.
373 procedure Constrain_Access
374 (Def_Id
: in out Entity_Id
;
376 Related_Nod
: Node_Id
);
377 -- Apply a list of constraints to an access type. If Def_Id is empty, it is
378 -- an anonymous type created for a subtype indication. In that case it is
379 -- created in the procedure and attached to Related_Nod.
381 procedure Constrain_Array
382 (Def_Id
: in out Entity_Id
;
384 Related_Nod
: Node_Id
;
385 Related_Id
: Entity_Id
;
387 -- Apply a list of index constraints to an unconstrained array type. The
388 -- first parameter is the entity for the resulting subtype. A value of
389 -- Empty for Def_Id indicates that an implicit type must be created, but
390 -- creation is delayed (and must be done by this procedure) because other
391 -- subsidiary implicit types must be created first (which is why Def_Id
392 -- is an in/out parameter). The second parameter is a subtype indication
393 -- node for the constrained array to be created (e.g. something of the
394 -- form string (1 .. 10)). Related_Nod gives the place where this type
395 -- has to be inserted in the tree. The Related_Id and Suffix parameters
396 -- are used to build the associated Implicit type name.
398 procedure Constrain_Concurrent
399 (Def_Id
: in out Entity_Id
;
401 Related_Nod
: Node_Id
;
402 Related_Id
: Entity_Id
;
404 -- Apply list of discriminant constraints to an unconstrained concurrent
407 -- SI is the N_Subtype_Indication node containing the constraint and
408 -- the unconstrained type to constrain.
410 -- Def_Id is the entity for the resulting constrained subtype. A value
411 -- of Empty for Def_Id indicates that an implicit type must be created,
412 -- but creation is delayed (and must be done by this procedure) because
413 -- other subsidiary implicit types must be created first (which is why
414 -- Def_Id is an in/out parameter).
416 -- Related_Nod gives the place where this type has to be inserted
419 -- The last two arguments are used to create its external name if needed.
421 function Constrain_Corresponding_Record
422 (Prot_Subt
: Entity_Id
;
423 Corr_Rec
: Entity_Id
;
424 Related_Nod
: Node_Id
) return Entity_Id
;
425 -- When constraining a protected type or task type with discriminants,
426 -- constrain the corresponding record with the same discriminant values.
428 procedure Constrain_Decimal
(Def_Id
: Node_Id
; S
: Node_Id
);
429 -- Constrain a decimal fixed point type with a digits constraint and/or a
430 -- range constraint, and build E_Decimal_Fixed_Point_Subtype entity.
432 procedure Constrain_Discriminated_Type
435 Related_Nod
: Node_Id
;
436 For_Access
: Boolean := False);
437 -- Process discriminant constraints of composite type. Verify that values
438 -- have been provided for all discriminants, that the original type is
439 -- unconstrained, and that the types of the supplied expressions match
440 -- the discriminant types. The first three parameters are like in routine
441 -- Constrain_Concurrent. See Build_Discriminated_Subtype for an explanation
444 procedure Constrain_Enumeration
(Def_Id
: Node_Id
; S
: Node_Id
);
445 -- Constrain an enumeration type with a range constraint. This is identical
446 -- to Constrain_Integer, but for the Ekind of the resulting subtype.
448 procedure Constrain_Float
(Def_Id
: Node_Id
; S
: Node_Id
);
449 -- Constrain a floating point type with either a digits constraint
450 -- and/or a range constraint, building a E_Floating_Point_Subtype.
452 procedure Constrain_Index
455 Related_Nod
: Node_Id
;
456 Related_Id
: Entity_Id
;
459 -- Process an index constraint S in a constrained array declaration. The
460 -- constraint can be a subtype name, or a range with or without an explicit
461 -- subtype mark. The index is the corresponding index of the unconstrained
462 -- array. The Related_Id and Suffix parameters are used to build the
463 -- associated Implicit type name.
465 procedure Constrain_Integer
(Def_Id
: Node_Id
; S
: Node_Id
);
466 -- Build subtype of a signed or modular integer type
468 procedure Constrain_Ordinary_Fixed
(Def_Id
: Node_Id
; S
: Node_Id
);
469 -- Constrain an ordinary fixed point type with a range constraint, and
470 -- build an E_Ordinary_Fixed_Point_Subtype entity.
472 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
);
473 -- Copy the Priv entity into the entity of its full declaration then swap
474 -- the two entities in such a manner that the former private type is now
475 -- seen as a full type.
477 procedure Decimal_Fixed_Point_Type_Declaration
480 -- Create a new decimal fixed point type, and apply the constraint to
481 -- obtain a subtype of this new type.
483 procedure Complete_Private_Subtype
486 Full_Base
: Entity_Id
;
487 Related_Nod
: Node_Id
);
488 -- Complete the implicit full view of a private subtype by setting the
489 -- appropriate semantic fields. If the full view of the parent is a record
490 -- type, build constrained components of subtype.
492 procedure Derive_Progenitor_Subprograms
493 (Parent_Type
: Entity_Id
;
494 Tagged_Type
: Entity_Id
);
495 -- Ada 2005 (AI-251): To complete type derivation, collect the primitive
496 -- operations of progenitors of Tagged_Type, and replace the subsidiary
497 -- subtypes with Tagged_Type, to build the specs of the inherited interface
498 -- primitives. The derived primitives are aliased to those of the
499 -- interface. This routine takes care also of transferring to the full view
500 -- subprograms associated with the partial view of Tagged_Type that cover
501 -- interface primitives.
503 procedure Derived_Standard_Character
505 Parent_Type
: Entity_Id
;
506 Derived_Type
: Entity_Id
);
507 -- Subsidiary procedure to Build_Derived_Enumeration_Type which handles
508 -- derivations from types Standard.Character and Standard.Wide_Character.
510 procedure Derived_Type_Declaration
513 Is_Completion
: Boolean);
514 -- Process a derived type declaration. Build_Derived_Type is invoked
515 -- to process the actual derived type definition. Parameters N and
516 -- Is_Completion have the same meaning as in Build_Derived_Type.
517 -- T is the N_Defining_Identifier for the entity defined in the
518 -- N_Full_Type_Declaration node N, that is T is the derived type.
520 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
521 -- Insert each literal in symbol table, as an overloadable identifier. Each
522 -- enumeration type is mapped into a sequence of integers, and each literal
523 -- is defined as a constant with integer value. If any of the literals are
524 -- character literals, the type is a character type, which means that
525 -- strings are legal aggregates for arrays of components of the type.
527 function Expand_To_Stored_Constraint
529 Constraint
: Elist_Id
) return Elist_Id
;
530 -- Given a constraint (i.e. a list of expressions) on the discriminants of
531 -- Typ, expand it into a constraint on the stored discriminants and return
532 -- the new list of expressions constraining the stored discriminants.
534 function Find_Type_Of_Object
536 Related_Nod
: Node_Id
) return Entity_Id
;
537 -- Get type entity for object referenced by Obj_Def, attaching the implicit
538 -- types generated to Related_Nod.
540 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
541 -- Create a new float and apply the constraint to obtain subtype of it
543 function Has_Range_Constraint
(N
: Node_Id
) return Boolean;
544 -- Given an N_Subtype_Indication node N, return True if a range constraint
545 -- is present, either directly, or as part of a digits or delta constraint.
546 -- In addition, a digits constraint in the decimal case returns True, since
547 -- it establishes a default range if no explicit range is present.
549 function Inherit_Components
551 Parent_Base
: Entity_Id
;
552 Derived_Base
: Entity_Id
;
554 Inherit_Discr
: Boolean;
555 Discs
: Elist_Id
) return Elist_Id
;
556 -- Called from Build_Derived_Record_Type to inherit the components of
557 -- Parent_Base (a base type) into the Derived_Base (the derived base type).
558 -- For more information on derived types and component inheritance please
559 -- consult the comment above the body of Build_Derived_Record_Type.
561 -- N is the original derived type declaration
563 -- Is_Tagged is set if we are dealing with tagged types
565 -- If Inherit_Discr is set, Derived_Base inherits its discriminants from
566 -- Parent_Base, otherwise no discriminants are inherited.
568 -- Discs gives the list of constraints that apply to Parent_Base in the
569 -- derived type declaration. If Discs is set to No_Elist, then we have
570 -- the following situation:
572 -- type Parent (D1..Dn : ..) is [tagged] record ...;
573 -- type Derived is new Parent [with ...];
575 -- which gets treated as
577 -- type Derived (D1..Dn : ..) is new Parent (D1,..,Dn) [with ...];
579 -- For untagged types the returned value is an association list. The list
580 -- starts from the association (Parent_Base => Derived_Base), and then it
581 -- contains a sequence of the associations of the form
583 -- (Old_Component => New_Component),
585 -- where Old_Component is the Entity_Id of a component in Parent_Base and
586 -- New_Component is the Entity_Id of the corresponding component in
587 -- Derived_Base. For untagged records, this association list is needed when
588 -- copying the record declaration for the derived base. In the tagged case
589 -- the value returned is irrelevant.
591 procedure Inherit_Predicate_Flags
(Subt
, Par
: Entity_Id
);
592 -- Propagate static and dynamic predicate flags from a parent to the
593 -- subtype in a subtype declaration with and without constraints.
595 function Is_EVF_Procedure
(Subp
: Entity_Id
) return Boolean;
596 -- Subsidiary to Check_Abstract_Overriding and Derive_Subprogram.
597 -- Determine whether subprogram Subp is a procedure subject to pragma
598 -- Extensions_Visible with value False and has at least one controlling
599 -- parameter of mode OUT.
601 function Is_Valid_Constraint_Kind
603 Constraint_Kind
: Node_Kind
) return Boolean;
604 -- Returns True if it is legal to apply the given kind of constraint to the
605 -- given kind of type (index constraint to an array type, for example).
607 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
608 -- Create new modular type. Verify that modulus is in bounds
610 procedure New_Concatenation_Op
(Typ
: Entity_Id
);
611 -- Create an abbreviated declaration for an operator in order to
612 -- materialize concatenation on array types.
614 procedure Ordinary_Fixed_Point_Type_Declaration
617 -- Create a new ordinary fixed point type, and apply the constraint to
618 -- obtain subtype of it.
620 procedure Prepare_Private_Subtype_Completion
622 Related_Nod
: Node_Id
);
623 -- Id is a subtype of some private type. Creates the full declaration
624 -- associated with Id whenever possible, i.e. when the full declaration
625 -- of the base type is already known. Records each subtype into
626 -- Private_Dependents of the base type.
628 procedure Process_Incomplete_Dependents
632 -- Process all entities that depend on an incomplete type. There include
633 -- subtypes, subprogram types that mention the incomplete type in their
634 -- profiles, and subprogram with access parameters that designate the
637 -- Inc_T is the defining identifier of an incomplete type declaration, its
638 -- Ekind is E_Incomplete_Type.
640 -- N is the corresponding N_Full_Type_Declaration for Inc_T.
642 -- Full_T is N's defining identifier.
644 -- Subtypes of incomplete types with discriminants are completed when the
645 -- parent type is. This is simpler than private subtypes, because they can
646 -- only appear in the same scope, and there is no need to exchange views.
647 -- Similarly, access_to_subprogram types may have a parameter or a return
648 -- type that is an incomplete type, and that must be replaced with the
651 -- If the full type is tagged, subprogram with access parameters that
652 -- designated the incomplete may be primitive operations of the full type,
653 -- and have to be processed accordingly.
655 procedure Process_Real_Range_Specification
(Def
: Node_Id
);
656 -- Given the type definition for a real type, this procedure processes and
657 -- checks the real range specification of this type definition if one is
658 -- present. If errors are found, error messages are posted, and the
659 -- Real_Range_Specification of Def is reset to Empty.
661 procedure Propagate_Default_Init_Cond_Attributes
662 (From_Typ
: Entity_Id
;
664 Parent_To_Derivation
: Boolean := False;
665 Private_To_Full_View
: Boolean := False);
666 -- Subsidiary to routines Build_Derived_Type and Process_Full_View. Inherit
667 -- all attributes related to pragma Default_Initial_Condition from From_Typ
668 -- to To_Typ. Flag Parent_To_Derivation should be set when the context is
669 -- the creation of a derived type. Flag Private_To_Full_View should be set
670 -- when processing both views of a private type.
672 procedure Record_Type_Declaration
676 -- Process a record type declaration (for both untagged and tagged
677 -- records). Parameters T and N are exactly like in procedure
678 -- Derived_Type_Declaration, except that no flag Is_Completion is needed
679 -- for this routine. If this is the completion of an incomplete type
680 -- declaration, Prev is the entity of the incomplete declaration, used for
681 -- cross-referencing. Otherwise Prev = T.
683 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
);
684 -- This routine is used to process the actual record type definition (both
685 -- for untagged and tagged records). Def is a record type definition node.
686 -- This procedure analyzes the components in this record type definition.
687 -- Prev_T is the entity for the enclosing record type. It is provided so
688 -- that its Has_Task flag can be set if any of the component have Has_Task
689 -- set. If the declaration is the completion of an incomplete type
690 -- declaration, Prev_T is the original incomplete type, whose full view is
693 procedure Replace_Components
(Typ
: Entity_Id
; Decl
: Node_Id
);
694 -- Subsidiary to Build_Derived_Record_Type. For untagged records, we
695 -- build a copy of the declaration tree of the parent, and we create
696 -- independently the list of components for the derived type. Semantic
697 -- information uses the component entities, but record representation
698 -- clauses are validated on the declaration tree. This procedure replaces
699 -- discriminants and components in the declaration with those that have
700 -- been created by Inherit_Components.
702 procedure Set_Fixed_Range
707 -- Build a range node with the given bounds and set it as the Scalar_Range
708 -- of the given fixed-point type entity. Loc is the source location used
709 -- for the constructed range. See body for further details.
711 procedure Set_Scalar_Range_For_Subtype
715 -- This routine is used to set the scalar range field for a subtype given
716 -- Def_Id, the entity for the subtype, and R, the range expression for the
717 -- scalar range. Subt provides the parent subtype to be used to analyze,
718 -- resolve, and check the given range.
720 procedure Set_Default_SSO
(T
: Entity_Id
);
721 -- T is the entity for an array or record being declared. This procedure
722 -- sets the flags SSO_Set_Low_By_Default/SSO_Set_High_By_Default according
723 -- to the setting of Opt.Default_SSO.
725 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
);
726 -- Create a new signed integer entity, and apply the constraint to obtain
727 -- the required first named subtype of this type.
729 procedure Set_Stored_Constraint_From_Discriminant_Constraint
731 -- E is some record type. This routine computes E's Stored_Constraint
732 -- from its Discriminant_Constraint.
734 procedure Diagnose_Interface
(N
: Node_Id
; E
: Entity_Id
);
735 -- Check that an entity in a list of progenitors is an interface,
736 -- emit error otherwise.
738 -----------------------
739 -- Access_Definition --
740 -----------------------
742 function Access_Definition
743 (Related_Nod
: Node_Id
;
744 N
: Node_Id
) return Entity_Id
746 Anon_Type
: Entity_Id
;
747 Anon_Scope
: Entity_Id
;
748 Desig_Type
: Entity_Id
;
749 Enclosing_Prot_Type
: Entity_Id
:= Empty
;
752 Check_SPARK_05_Restriction
("access type is not allowed", N
);
754 if Is_Entry
(Current_Scope
)
755 and then Is_Task_Type
(Etype
(Scope
(Current_Scope
)))
757 Error_Msg_N
("task entries cannot have access parameters", N
);
761 -- Ada 2005: For an object declaration the corresponding anonymous
762 -- type is declared in the current scope.
764 -- If the access definition is the return type of another access to
765 -- function, scope is the current one, because it is the one of the
766 -- current type declaration, except for the pathological case below.
768 if Nkind_In
(Related_Nod
, N_Object_Declaration
,
769 N_Access_Function_Definition
)
771 Anon_Scope
:= Current_Scope
;
773 -- A pathological case: function returning access functions that
774 -- return access functions, etc. Each anonymous access type created
775 -- is in the enclosing scope of the outermost function.
782 while Nkind_In
(Par
, N_Access_Function_Definition
,
788 if Nkind
(Par
) = N_Function_Specification
then
789 Anon_Scope
:= Scope
(Defining_Entity
(Par
));
793 -- For the anonymous function result case, retrieve the scope of the
794 -- function specification's associated entity rather than using the
795 -- current scope. The current scope will be the function itself if the
796 -- formal part is currently being analyzed, but will be the parent scope
797 -- in the case of a parameterless function, and we always want to use
798 -- the function's parent scope. Finally, if the function is a child
799 -- unit, we must traverse the tree to retrieve the proper entity.
801 elsif Nkind
(Related_Nod
) = N_Function_Specification
802 and then Nkind
(Parent
(N
)) /= N_Parameter_Specification
804 -- If the current scope is a protected type, the anonymous access
805 -- is associated with one of the protected operations, and must
806 -- be available in the scope that encloses the protected declaration.
807 -- Otherwise the type is in the scope enclosing the subprogram.
809 -- If the function has formals, The return type of a subprogram
810 -- declaration is analyzed in the scope of the subprogram (see
811 -- Process_Formals) and thus the protected type, if present, is
812 -- the scope of the current function scope.
814 if Ekind
(Current_Scope
) = E_Protected_Type
then
815 Enclosing_Prot_Type
:= Current_Scope
;
817 elsif Ekind
(Current_Scope
) = E_Function
818 and then Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
820 Enclosing_Prot_Type
:= Scope
(Current_Scope
);
823 if Present
(Enclosing_Prot_Type
) then
824 Anon_Scope
:= Scope
(Enclosing_Prot_Type
);
827 Anon_Scope
:= Scope
(Defining_Entity
(Related_Nod
));
830 -- For an access type definition, if the current scope is a child
831 -- unit it is the scope of the type.
833 elsif Is_Compilation_Unit
(Current_Scope
) then
834 Anon_Scope
:= Current_Scope
;
836 -- For access formals, access components, and access discriminants, the
837 -- scope is that of the enclosing declaration,
840 Anon_Scope
:= Scope
(Current_Scope
);
845 (E_Anonymous_Access_Type
, Related_Nod
, Scope_Id
=> Anon_Scope
);
848 and then Ada_Version
>= Ada_2005
850 Error_Msg_N
("ALL is not permitted for anonymous access types", N
);
853 -- Ada 2005 (AI-254): In case of anonymous access to subprograms call
854 -- the corresponding semantic routine
856 if Present
(Access_To_Subprogram_Definition
(N
)) then
858 -- Compiler runtime units are compiled in Ada 2005 mode when building
859 -- the runtime library but must also be compilable in Ada 95 mode
860 -- (when bootstrapping the compiler).
862 Check_Compiler_Unit
("anonymous access to subprogram", N
);
864 Access_Subprogram_Declaration
865 (T_Name
=> Anon_Type
,
866 T_Def
=> Access_To_Subprogram_Definition
(N
));
868 if Ekind
(Anon_Type
) = E_Access_Protected_Subprogram_Type
then
870 (Anon_Type
, E_Anonymous_Access_Protected_Subprogram_Type
);
872 Set_Ekind
(Anon_Type
, E_Anonymous_Access_Subprogram_Type
);
875 Set_Can_Use_Internal_Rep
876 (Anon_Type
, not Always_Compatible_Rep_On_Target
);
878 -- If the anonymous access is associated with a protected operation,
879 -- create a reference to it after the enclosing protected definition
880 -- because the itype will be used in the subsequent bodies.
882 -- If the anonymous access itself is protected, a full type
883 -- declaratiton will be created for it, so that the equivalent
884 -- record type can be constructed. For further details, see
885 -- Replace_Anonymous_Access_To_Protected-Subprogram.
887 if Ekind
(Current_Scope
) = E_Protected_Type
888 and then not Protected_Present
(Access_To_Subprogram_Definition
(N
))
890 Build_Itype_Reference
(Anon_Type
, Parent
(Current_Scope
));
896 Find_Type
(Subtype_Mark
(N
));
897 Desig_Type
:= Entity
(Subtype_Mark
(N
));
899 Set_Directly_Designated_Type
(Anon_Type
, Desig_Type
);
900 Set_Etype
(Anon_Type
, Anon_Type
);
902 -- Make sure the anonymous access type has size and alignment fields
903 -- set, as required by gigi. This is necessary in the case of the
904 -- Task_Body_Procedure.
906 if not Has_Private_Component
(Desig_Type
) then
907 Layout_Type
(Anon_Type
);
910 -- Ada 2005 (AI-231): Ada 2005 semantics for anonymous access differs
911 -- from Ada 95 semantics. In Ada 2005, anonymous access must specify if
912 -- the null value is allowed. In Ada 95 the null value is never allowed.
914 if Ada_Version
>= Ada_2005
then
915 Set_Can_Never_Be_Null
(Anon_Type
, Null_Exclusion_Present
(N
));
917 Set_Can_Never_Be_Null
(Anon_Type
, True);
920 -- The anonymous access type is as public as the discriminated type or
921 -- subprogram that defines it. It is imported (for back-end purposes)
922 -- if the designated type is.
924 Set_Is_Public
(Anon_Type
, Is_Public
(Scope
(Anon_Type
)));
926 -- Ada 2005 (AI-231): Propagate the access-constant attribute
928 Set_Is_Access_Constant
(Anon_Type
, Constant_Present
(N
));
930 -- The context is either a subprogram declaration, object declaration,
931 -- or an access discriminant, in a private or a full type declaration.
932 -- In the case of a subprogram, if the designated type is incomplete,
933 -- the operation will be a primitive operation of the full type, to be
934 -- updated subsequently. If the type is imported through a limited_with
935 -- clause, the subprogram is not a primitive operation of the type
936 -- (which is declared elsewhere in some other scope).
938 if Ekind
(Desig_Type
) = E_Incomplete_Type
939 and then not From_Limited_With
(Desig_Type
)
940 and then Is_Overloadable
(Current_Scope
)
942 Append_Elmt
(Current_Scope
, Private_Dependents
(Desig_Type
));
943 Set_Has_Delayed_Freeze
(Current_Scope
);
946 -- Ada 2005: If the designated type is an interface that may contain
947 -- tasks, create a Master entity for the declaration. This must be done
948 -- before expansion of the full declaration, because the declaration may
949 -- include an expression that is an allocator, whose expansion needs the
950 -- proper Master for the created tasks.
952 if Nkind
(Related_Nod
) = N_Object_Declaration
and then Expander_Active
954 if Is_Interface
(Desig_Type
) and then Is_Limited_Record
(Desig_Type
)
956 Build_Class_Wide_Master
(Anon_Type
);
958 -- Similarly, if the type is an anonymous access that designates
959 -- tasks, create a master entity for it in the current context.
961 elsif Has_Task
(Desig_Type
) and then Comes_From_Source
(Related_Nod
)
963 Build_Master_Entity
(Defining_Identifier
(Related_Nod
));
964 Build_Master_Renaming
(Anon_Type
);
968 -- For a private component of a protected type, it is imperative that
969 -- the back-end elaborate the type immediately after the protected
970 -- declaration, because this type will be used in the declarations
971 -- created for the component within each protected body, so we must
972 -- create an itype reference for it now.
974 if Nkind
(Parent
(Related_Nod
)) = N_Protected_Definition
then
975 Build_Itype_Reference
(Anon_Type
, Parent
(Parent
(Related_Nod
)));
977 -- Similarly, if the access definition is the return result of a
978 -- function, create an itype reference for it because it will be used
979 -- within the function body. For a regular function that is not a
980 -- compilation unit, insert reference after the declaration. For a
981 -- protected operation, insert it after the enclosing protected type
982 -- declaration. In either case, do not create a reference for a type
983 -- obtained through a limited_with clause, because this would introduce
984 -- semantic dependencies.
986 -- Similarly, do not create a reference if the designated type is a
987 -- generic formal, because no use of it will reach the backend.
989 elsif Nkind
(Related_Nod
) = N_Function_Specification
990 and then not From_Limited_With
(Desig_Type
)
991 and then not Is_Generic_Type
(Desig_Type
)
993 if Present
(Enclosing_Prot_Type
) then
994 Build_Itype_Reference
(Anon_Type
, Parent
(Enclosing_Prot_Type
));
996 elsif Is_List_Member
(Parent
(Related_Nod
))
997 and then Nkind
(Parent
(N
)) /= N_Parameter_Specification
999 Build_Itype_Reference
(Anon_Type
, Parent
(Related_Nod
));
1002 -- Finally, create an itype reference for an object declaration of an
1003 -- anonymous access type. This is strictly necessary only for deferred
1004 -- constants, but in any case will avoid out-of-scope problems in the
1007 elsif Nkind
(Related_Nod
) = N_Object_Declaration
then
1008 Build_Itype_Reference
(Anon_Type
, Related_Nod
);
1012 end Access_Definition
;
1014 -----------------------------------
1015 -- Access_Subprogram_Declaration --
1016 -----------------------------------
1018 procedure Access_Subprogram_Declaration
1019 (T_Name
: Entity_Id
;
1022 procedure Check_For_Premature_Usage
(Def
: Node_Id
);
1023 -- Check that type T_Name is not used, directly or recursively, as a
1024 -- parameter or a return type in Def. Def is either a subtype, an
1025 -- access_definition, or an access_to_subprogram_definition.
1027 -------------------------------
1028 -- Check_For_Premature_Usage --
1029 -------------------------------
1031 procedure Check_For_Premature_Usage
(Def
: Node_Id
) is
1035 -- Check for a subtype mark
1037 if Nkind
(Def
) in N_Has_Etype
then
1038 if Etype
(Def
) = T_Name
then
1040 ("type& cannot be used before end of its declaration", Def
);
1043 -- If this is not a subtype, then this is an access_definition
1045 elsif Nkind
(Def
) = N_Access_Definition
then
1046 if Present
(Access_To_Subprogram_Definition
(Def
)) then
1047 Check_For_Premature_Usage
1048 (Access_To_Subprogram_Definition
(Def
));
1050 Check_For_Premature_Usage
(Subtype_Mark
(Def
));
1053 -- The only cases left are N_Access_Function_Definition and
1054 -- N_Access_Procedure_Definition.
1057 if Present
(Parameter_Specifications
(Def
)) then
1058 Param
:= First
(Parameter_Specifications
(Def
));
1059 while Present
(Param
) loop
1060 Check_For_Premature_Usage
(Parameter_Type
(Param
));
1061 Param
:= Next
(Param
);
1065 if Nkind
(Def
) = N_Access_Function_Definition
then
1066 Check_For_Premature_Usage
(Result_Definition
(Def
));
1069 end Check_For_Premature_Usage
;
1073 Formals
: constant List_Id
:= Parameter_Specifications
(T_Def
);
1076 Desig_Type
: constant Entity_Id
:=
1077 Create_Itype
(E_Subprogram_Type
, Parent
(T_Def
));
1079 -- Start of processing for Access_Subprogram_Declaration
1082 Check_SPARK_05_Restriction
("access type is not allowed", T_Def
);
1084 -- Associate the Itype node with the inner full-type declaration or
1085 -- subprogram spec or entry body. This is required to handle nested
1086 -- anonymous declarations. For example:
1089 -- (X : access procedure
1090 -- (Y : access procedure
1093 D_Ityp
:= Associated_Node_For_Itype
(Desig_Type
);
1094 while not (Nkind_In
(D_Ityp
, N_Full_Type_Declaration
,
1095 N_Private_Type_Declaration
,
1096 N_Private_Extension_Declaration
,
1097 N_Procedure_Specification
,
1098 N_Function_Specification
,
1102 Nkind_In
(D_Ityp
, N_Object_Declaration
,
1103 N_Object_Renaming_Declaration
,
1104 N_Formal_Object_Declaration
,
1105 N_Formal_Type_Declaration
,
1106 N_Task_Type_Declaration
,
1107 N_Protected_Type_Declaration
))
1109 D_Ityp
:= Parent
(D_Ityp
);
1110 pragma Assert
(D_Ityp
/= Empty
);
1113 Set_Associated_Node_For_Itype
(Desig_Type
, D_Ityp
);
1115 if Nkind_In
(D_Ityp
, N_Procedure_Specification
,
1116 N_Function_Specification
)
1118 Set_Scope
(Desig_Type
, Scope
(Defining_Entity
(D_Ityp
)));
1120 elsif Nkind_In
(D_Ityp
, N_Full_Type_Declaration
,
1121 N_Object_Declaration
,
1122 N_Object_Renaming_Declaration
,
1123 N_Formal_Type_Declaration
)
1125 Set_Scope
(Desig_Type
, Scope
(Defining_Identifier
(D_Ityp
)));
1128 if Nkind
(T_Def
) = N_Access_Function_Definition
then
1129 if Nkind
(Result_Definition
(T_Def
)) = N_Access_Definition
then
1131 Acc
: constant Node_Id
:= Result_Definition
(T_Def
);
1134 if Present
(Access_To_Subprogram_Definition
(Acc
))
1136 Protected_Present
(Access_To_Subprogram_Definition
(Acc
))
1140 Replace_Anonymous_Access_To_Protected_Subprogram
1146 Access_Definition
(T_Def
, Result_Definition
(T_Def
)));
1151 Analyze
(Result_Definition
(T_Def
));
1154 Typ
: constant Entity_Id
:= Entity
(Result_Definition
(T_Def
));
1157 -- If a null exclusion is imposed on the result type, then
1158 -- create a null-excluding itype (an access subtype) and use
1159 -- it as the function's Etype.
1161 if Is_Access_Type
(Typ
)
1162 and then Null_Exclusion_In_Return_Present
(T_Def
)
1164 Set_Etype
(Desig_Type
,
1165 Create_Null_Excluding_Itype
1167 Related_Nod
=> T_Def
,
1168 Scope_Id
=> Current_Scope
));
1171 if From_Limited_With
(Typ
) then
1173 -- AI05-151: Incomplete types are allowed in all basic
1174 -- declarations, including access to subprograms.
1176 if Ada_Version
>= Ada_2012
then
1181 ("illegal use of incomplete type&",
1182 Result_Definition
(T_Def
), Typ
);
1185 elsif Ekind
(Current_Scope
) = E_Package
1186 and then In_Private_Part
(Current_Scope
)
1188 if Ekind
(Typ
) = E_Incomplete_Type
then
1189 Append_Elmt
(Desig_Type
, Private_Dependents
(Typ
));
1191 elsif Is_Class_Wide_Type
(Typ
)
1192 and then Ekind
(Etype
(Typ
)) = E_Incomplete_Type
1195 (Desig_Type
, Private_Dependents
(Etype
(Typ
)));
1199 Set_Etype
(Desig_Type
, Typ
);
1204 if not (Is_Type
(Etype
(Desig_Type
))) then
1206 ("expect type in function specification",
1207 Result_Definition
(T_Def
));
1211 Set_Etype
(Desig_Type
, Standard_Void_Type
);
1214 if Present
(Formals
) then
1215 Push_Scope
(Desig_Type
);
1217 -- Some special tests here. These special tests can be removed
1218 -- if and when Itypes always have proper parent pointers to their
1221 -- Special test 1) Link defining_identifier of formals. Required by
1222 -- First_Formal to provide its functionality.
1228 F
:= First
(Formals
);
1230 -- In ASIS mode, the access_to_subprogram may be analyzed twice,
1231 -- when it is part of an unconstrained type and subtype expansion
1232 -- is disabled. To avoid back-end problems with shared profiles,
1233 -- use previous subprogram type as the designated type, and then
1234 -- remove scope added above.
1236 if ASIS_Mode
and then Present
(Scope
(Defining_Identifier
(F
)))
1238 Set_Etype
(T_Name
, T_Name
);
1239 Init_Size_Align
(T_Name
);
1240 Set_Directly_Designated_Type
(T_Name
,
1241 Scope
(Defining_Identifier
(F
)));
1246 while Present
(F
) loop
1247 if No
(Parent
(Defining_Identifier
(F
))) then
1248 Set_Parent
(Defining_Identifier
(F
), F
);
1255 Process_Formals
(Formals
, Parent
(T_Def
));
1257 -- Special test 2) End_Scope requires that the parent pointer be set
1258 -- to something reasonable, but Itypes don't have parent pointers. So
1259 -- we set it and then unset it ???
1261 Set_Parent
(Desig_Type
, T_Name
);
1263 Set_Parent
(Desig_Type
, Empty
);
1266 -- Check for premature usage of the type being defined
1268 Check_For_Premature_Usage
(T_Def
);
1270 -- The return type and/or any parameter type may be incomplete. Mark the
1271 -- subprogram_type as depending on the incomplete type, so that it can
1272 -- be updated when the full type declaration is seen. This only applies
1273 -- to incomplete types declared in some enclosing scope, not to limited
1274 -- views from other packages.
1276 -- Prior to Ada 2012, access to functions can only have in_parameters.
1278 if Present
(Formals
) then
1279 Formal
:= First_Formal
(Desig_Type
);
1280 while Present
(Formal
) loop
1281 if Ekind
(Formal
) /= E_In_Parameter
1282 and then Nkind
(T_Def
) = N_Access_Function_Definition
1283 and then Ada_Version
< Ada_2012
1285 Error_Msg_N
("functions can only have IN parameters", Formal
);
1288 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
1289 and then In_Open_Scopes
(Scope
(Etype
(Formal
)))
1291 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Formal
)));
1292 Set_Has_Delayed_Freeze
(Desig_Type
);
1295 Next_Formal
(Formal
);
1299 -- Check whether an indirect call without actuals may be possible. This
1300 -- is used when resolving calls whose result is then indexed.
1302 May_Need_Actuals
(Desig_Type
);
1304 -- If the return type is incomplete, this is legal as long as the type
1305 -- is declared in the current scope and will be completed in it (rather
1306 -- than being part of limited view).
1308 if Ekind
(Etype
(Desig_Type
)) = E_Incomplete_Type
1309 and then not Has_Delayed_Freeze
(Desig_Type
)
1310 and then In_Open_Scopes
(Scope
(Etype
(Desig_Type
)))
1312 Append_Elmt
(Desig_Type
, Private_Dependents
(Etype
(Desig_Type
)));
1313 Set_Has_Delayed_Freeze
(Desig_Type
);
1316 Check_Delayed_Subprogram
(Desig_Type
);
1318 if Protected_Present
(T_Def
) then
1319 Set_Ekind
(T_Name
, E_Access_Protected_Subprogram_Type
);
1320 Set_Convention
(Desig_Type
, Convention_Protected
);
1322 Set_Ekind
(T_Name
, E_Access_Subprogram_Type
);
1325 Set_Can_Use_Internal_Rep
(T_Name
, not Always_Compatible_Rep_On_Target
);
1327 Set_Etype
(T_Name
, T_Name
);
1328 Init_Size_Align
(T_Name
);
1329 Set_Directly_Designated_Type
(T_Name
, Desig_Type
);
1331 Generate_Reference_To_Formals
(T_Name
);
1333 -- Ada 2005 (AI-231): Propagate the null-excluding attribute
1335 Set_Can_Never_Be_Null
(T_Name
, Null_Exclusion_Present
(T_Def
));
1337 Check_Restriction
(No_Access_Subprograms
, T_Def
);
1338 end Access_Subprogram_Declaration
;
1340 ----------------------------
1341 -- Access_Type_Declaration --
1342 ----------------------------
1344 procedure Access_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
1345 P
: constant Node_Id
:= Parent
(Def
);
1346 S
: constant Node_Id
:= Subtype_Indication
(Def
);
1348 Full_Desig
: Entity_Id
;
1351 Check_SPARK_05_Restriction
("access type is not allowed", Def
);
1353 -- Check for permissible use of incomplete type
1355 if Nkind
(S
) /= N_Subtype_Indication
then
1358 if Ekind
(Root_Type
(Entity
(S
))) = E_Incomplete_Type
then
1359 Set_Directly_Designated_Type
(T
, Entity
(S
));
1361 -- If the designated type is a limited view, we cannot tell if
1362 -- the full view contains tasks, and there is no way to handle
1363 -- that full view in a client. We create a master entity for the
1364 -- scope, which will be used when a client determines that one
1367 if From_Limited_With
(Entity
(S
))
1368 and then not Is_Class_Wide_Type
(Entity
(S
))
1370 Set_Ekind
(T
, E_Access_Type
);
1371 Build_Master_Entity
(T
);
1372 Build_Master_Renaming
(T
);
1376 Set_Directly_Designated_Type
(T
, Process_Subtype
(S
, P
, T
, 'P'));
1379 -- If the access definition is of the form: ACCESS NOT NULL ..
1380 -- the subtype indication must be of an access type. Create
1381 -- a null-excluding subtype of it.
1383 if Null_Excluding_Subtype
(Def
) then
1384 if not Is_Access_Type
(Entity
(S
)) then
1385 Error_Msg_N
("null exclusion must apply to access type", Def
);
1389 Loc
: constant Source_Ptr
:= Sloc
(S
);
1391 Nam
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1395 Make_Subtype_Declaration
(Loc
,
1396 Defining_Identifier
=> Nam
,
1397 Subtype_Indication
=>
1398 New_Occurrence_Of
(Entity
(S
), Loc
));
1399 Set_Null_Exclusion_Present
(Decl
);
1400 Insert_Before
(Parent
(Def
), Decl
);
1402 Set_Entity
(S
, Nam
);
1408 Set_Directly_Designated_Type
(T
,
1409 Process_Subtype
(S
, P
, T
, 'P'));
1412 if All_Present
(Def
) or Constant_Present
(Def
) then
1413 Set_Ekind
(T
, E_General_Access_Type
);
1415 Set_Ekind
(T
, E_Access_Type
);
1418 Full_Desig
:= Designated_Type
(T
);
1420 if Base_Type
(Full_Desig
) = T
then
1421 Error_Msg_N
("access type cannot designate itself", S
);
1423 -- In Ada 2005, the type may have a limited view through some unit in
1424 -- its own context, allowing the following circularity that cannot be
1425 -- detected earlier.
1427 elsif Is_Class_Wide_Type
(Full_Desig
) and then Etype
(Full_Desig
) = T
1430 ("access type cannot designate its own classwide type", S
);
1432 -- Clean up indication of tagged status to prevent cascaded errors
1434 Set_Is_Tagged_Type
(T
, False);
1439 -- If the type has appeared already in a with_type clause, it is frozen
1440 -- and the pointer size is already set. Else, initialize.
1442 if not From_Limited_With
(T
) then
1443 Init_Size_Align
(T
);
1446 -- Note that Has_Task is always false, since the access type itself
1447 -- is not a task type. See Einfo for more description on this point.
1448 -- Exactly the same consideration applies to Has_Controlled_Component
1449 -- and to Has_Protected.
1451 Set_Has_Task
(T
, False);
1452 Set_Has_Controlled_Component
(T
, False);
1453 Set_Has_Protected
(T
, False);
1455 -- Initialize field Finalization_Master explicitly to Empty, to avoid
1456 -- problems where an incomplete view of this entity has been previously
1457 -- established by a limited with and an overlaid version of this field
1458 -- (Stored_Constraint) was initialized for the incomplete view.
1460 -- This reset is performed in most cases except where the access type
1461 -- has been created for the purposes of allocating or deallocating a
1462 -- build-in-place object. Such access types have explicitly set pools
1463 -- and finalization masters.
1465 if No
(Associated_Storage_Pool
(T
)) then
1466 Set_Finalization_Master
(T
, Empty
);
1469 -- Ada 2005 (AI-231): Propagate the null-excluding and access-constant
1472 Set_Can_Never_Be_Null
(T
, Null_Exclusion_Present
(Def
));
1473 Set_Is_Access_Constant
(T
, Constant_Present
(Def
));
1474 end Access_Type_Declaration
;
1476 ----------------------------------
1477 -- Add_Interface_Tag_Components --
1478 ----------------------------------
1480 procedure Add_Interface_Tag_Components
(N
: Node_Id
; Typ
: Entity_Id
) is
1481 Loc
: constant Source_Ptr
:= Sloc
(N
);
1485 procedure Add_Tag
(Iface
: Entity_Id
);
1486 -- Add tag for one of the progenitor interfaces
1492 procedure Add_Tag
(Iface
: Entity_Id
) is
1499 pragma Assert
(Is_Tagged_Type
(Iface
) and then Is_Interface
(Iface
));
1501 -- This is a reasonable place to propagate predicates
1503 if Has_Predicates
(Iface
) then
1504 Set_Has_Predicates
(Typ
);
1508 Make_Component_Definition
(Loc
,
1509 Aliased_Present
=> True,
1510 Subtype_Indication
=>
1511 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
));
1513 Tag
:= Make_Temporary
(Loc
, 'V');
1516 Make_Component_Declaration
(Loc
,
1517 Defining_Identifier
=> Tag
,
1518 Component_Definition
=> Def
);
1520 Analyze_Component_Declaration
(Decl
);
1522 Set_Analyzed
(Decl
);
1523 Set_Ekind
(Tag
, E_Component
);
1525 Set_Is_Aliased
(Tag
);
1526 Set_Related_Type
(Tag
, Iface
);
1527 Init_Component_Location
(Tag
);
1529 pragma Assert
(Is_Frozen
(Iface
));
1531 Set_DT_Entry_Count
(Tag
,
1532 DT_Entry_Count
(First_Entity
(Iface
)));
1534 if No
(Last_Tag
) then
1537 Insert_After
(Last_Tag
, Decl
);
1542 -- If the ancestor has discriminants we need to give special support
1543 -- to store the offset_to_top value of the secondary dispatch tables.
1544 -- For this purpose we add a supplementary component just after the
1545 -- field that contains the tag associated with each secondary DT.
1547 if Typ
/= Etype
(Typ
) and then Has_Discriminants
(Etype
(Typ
)) then
1549 Make_Component_Definition
(Loc
,
1550 Subtype_Indication
=>
1551 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
));
1553 Offset
:= Make_Temporary
(Loc
, 'V');
1556 Make_Component_Declaration
(Loc
,
1557 Defining_Identifier
=> Offset
,
1558 Component_Definition
=> Def
);
1560 Analyze_Component_Declaration
(Decl
);
1562 Set_Analyzed
(Decl
);
1563 Set_Ekind
(Offset
, E_Component
);
1564 Set_Is_Aliased
(Offset
);
1565 Set_Related_Type
(Offset
, Iface
);
1566 Init_Component_Location
(Offset
);
1567 Insert_After
(Last_Tag
, Decl
);
1578 -- Start of processing for Add_Interface_Tag_Components
1581 if not RTE_Available
(RE_Interface_Tag
) then
1583 ("(Ada 2005) interface types not supported by this run-time!",
1588 if Ekind
(Typ
) /= E_Record_Type
1589 or else (Is_Concurrent_Record_Type
(Typ
)
1590 and then Is_Empty_List
(Abstract_Interface_List
(Typ
)))
1591 or else (not Is_Concurrent_Record_Type
(Typ
)
1592 and then No
(Interfaces
(Typ
))
1593 and then Is_Empty_Elmt_List
(Interfaces
(Typ
)))
1598 -- Find the current last tag
1600 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1601 Ext
:= Record_Extension_Part
(Type_Definition
(N
));
1603 pragma Assert
(Nkind
(Type_Definition
(N
)) = N_Record_Definition
);
1604 Ext
:= Type_Definition
(N
);
1609 if not (Present
(Component_List
(Ext
))) then
1610 Set_Null_Present
(Ext
, False);
1612 Set_Component_List
(Ext
,
1613 Make_Component_List
(Loc
,
1614 Component_Items
=> L
,
1615 Null_Present
=> False));
1617 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
1618 L
:= Component_Items
1620 (Record_Extension_Part
1621 (Type_Definition
(N
))));
1623 L
:= Component_Items
1625 (Type_Definition
(N
)));
1628 -- Find the last tag component
1631 while Present
(Comp
) loop
1632 if Nkind
(Comp
) = N_Component_Declaration
1633 and then Is_Tag
(Defining_Identifier
(Comp
))
1642 -- At this point L references the list of components and Last_Tag
1643 -- references the current last tag (if any). Now we add the tag
1644 -- corresponding with all the interfaces that are not implemented
1647 if Present
(Interfaces
(Typ
)) then
1648 Elmt
:= First_Elmt
(Interfaces
(Typ
));
1649 while Present
(Elmt
) loop
1650 Add_Tag
(Node
(Elmt
));
1654 end Add_Interface_Tag_Components
;
1656 -------------------------------------
1657 -- Add_Internal_Interface_Entities --
1658 -------------------------------------
1660 procedure Add_Internal_Interface_Entities
(Tagged_Type
: Entity_Id
) is
1663 Iface_Elmt
: Elmt_Id
;
1664 Iface_Prim
: Entity_Id
;
1665 Ifaces_List
: Elist_Id
;
1666 New_Subp
: Entity_Id
:= Empty
;
1668 Restore_Scope
: Boolean := False;
1671 pragma Assert
(Ada_Version
>= Ada_2005
1672 and then Is_Record_Type
(Tagged_Type
)
1673 and then Is_Tagged_Type
(Tagged_Type
)
1674 and then Has_Interfaces
(Tagged_Type
)
1675 and then not Is_Interface
(Tagged_Type
));
1677 -- Ensure that the internal entities are added to the scope of the type
1679 if Scope
(Tagged_Type
) /= Current_Scope
then
1680 Push_Scope
(Scope
(Tagged_Type
));
1681 Restore_Scope
:= True;
1684 Collect_Interfaces
(Tagged_Type
, Ifaces_List
);
1686 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1687 while Present
(Iface_Elmt
) loop
1688 Iface
:= Node
(Iface_Elmt
);
1690 -- Originally we excluded here from this processing interfaces that
1691 -- are parents of Tagged_Type because their primitives are located
1692 -- in the primary dispatch table (and hence no auxiliary internal
1693 -- entities are required to handle secondary dispatch tables in such
1694 -- case). However, these auxiliary entities are also required to
1695 -- handle derivations of interfaces in formals of generics (see
1696 -- Derive_Subprograms).
1698 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1699 while Present
(Elmt
) loop
1700 Iface_Prim
:= Node
(Elmt
);
1702 if not Is_Predefined_Dispatching_Operation
(Iface_Prim
) then
1704 Find_Primitive_Covering_Interface
1705 (Tagged_Type
=> Tagged_Type
,
1706 Iface_Prim
=> Iface_Prim
);
1708 if No
(Prim
) and then Serious_Errors_Detected
> 0 then
1712 pragma Assert
(Present
(Prim
));
1714 -- Ada 2012 (AI05-0197): If the name of the covering primitive
1715 -- differs from the name of the interface primitive then it is
1716 -- a private primitive inherited from a parent type. In such
1717 -- case, given that Tagged_Type covers the interface, the
1718 -- inherited private primitive becomes visible. For such
1719 -- purpose we add a new entity that renames the inherited
1720 -- private primitive.
1722 if Chars
(Prim
) /= Chars
(Iface_Prim
) then
1723 pragma Assert
(Has_Suffix
(Prim
, 'P'));
1725 (New_Subp
=> New_Subp
,
1726 Parent_Subp
=> Iface_Prim
,
1727 Derived_Type
=> Tagged_Type
,
1728 Parent_Type
=> Iface
);
1729 Set_Alias
(New_Subp
, Prim
);
1730 Set_Is_Abstract_Subprogram
1731 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1735 (New_Subp
=> New_Subp
,
1736 Parent_Subp
=> Iface_Prim
,
1737 Derived_Type
=> Tagged_Type
,
1738 Parent_Type
=> Iface
);
1740 -- Ada 2005 (AI-251): Decorate internal entity Iface_Subp
1741 -- associated with interface types. These entities are
1742 -- only registered in the list of primitives of its
1743 -- corresponding tagged type because they are only used
1744 -- to fill the contents of the secondary dispatch tables.
1745 -- Therefore they are removed from the homonym chains.
1747 Set_Is_Hidden
(New_Subp
);
1748 Set_Is_Internal
(New_Subp
);
1749 Set_Alias
(New_Subp
, Prim
);
1750 Set_Is_Abstract_Subprogram
1751 (New_Subp
, Is_Abstract_Subprogram
(Prim
));
1752 Set_Interface_Alias
(New_Subp
, Iface_Prim
);
1754 -- If the returned type is an interface then propagate it to
1755 -- the returned type. Needed by the thunk to generate the code
1756 -- which displaces "this" to reference the corresponding
1757 -- secondary dispatch table in the returned object.
1759 if Is_Interface
(Etype
(Iface_Prim
)) then
1760 Set_Etype
(New_Subp
, Etype
(Iface_Prim
));
1763 -- Internal entities associated with interface types are only
1764 -- registered in the list of primitives of the tagged type.
1765 -- They are only used to fill the contents of the secondary
1766 -- dispatch tables. Therefore they are not needed in the
1769 Remove_Homonym
(New_Subp
);
1771 -- Hidden entities associated with interfaces must have set
1772 -- the Has_Delay_Freeze attribute to ensure that, in case
1773 -- of locally defined tagged types (or compiling with static
1774 -- dispatch tables generation disabled) the corresponding
1775 -- entry of the secondary dispatch table is filled when such
1776 -- an entity is frozen. This is an expansion activity that must
1777 -- be suppressed for ASIS because it leads to gigi elaboration
1778 -- issues in annotate mode.
1780 if not ASIS_Mode
then
1781 Set_Has_Delayed_Freeze
(New_Subp
);
1789 Next_Elmt
(Iface_Elmt
);
1792 if Restore_Scope
then
1795 end Add_Internal_Interface_Entities
;
1797 -----------------------------------
1798 -- Analyze_Component_Declaration --
1799 -----------------------------------
1801 procedure Analyze_Component_Declaration
(N
: Node_Id
) is
1802 Loc
: constant Source_Ptr
:= Sloc
(Component_Definition
(N
));
1803 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1804 E
: constant Node_Id
:= Expression
(N
);
1805 Typ
: constant Node_Id
:=
1806 Subtype_Indication
(Component_Definition
(N
));
1810 function Contains_POC
(Constr
: Node_Id
) return Boolean;
1811 -- Determines whether a constraint uses the discriminant of a record
1812 -- type thus becoming a per-object constraint (POC).
1814 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean;
1815 -- Typ is the type of the current component, check whether this type is
1816 -- a limited type. Used to validate declaration against that of
1817 -- enclosing record.
1823 function Contains_POC
(Constr
: Node_Id
) return Boolean is
1825 -- Prevent cascaded errors
1827 if Error_Posted
(Constr
) then
1831 case Nkind
(Constr
) is
1832 when N_Attribute_Reference
=>
1833 return Attribute_Name
(Constr
) = Name_Access
1834 and then Prefix
(Constr
) = Scope
(Entity
(Prefix
(Constr
)));
1836 when N_Discriminant_Association
=>
1837 return Denotes_Discriminant
(Expression
(Constr
));
1839 when N_Identifier
=>
1840 return Denotes_Discriminant
(Constr
);
1842 when N_Index_Or_Discriminant_Constraint
=>
1847 IDC
:= First
(Constraints
(Constr
));
1848 while Present
(IDC
) loop
1850 -- One per-object constraint is sufficient
1852 if Contains_POC
(IDC
) then
1863 return Denotes_Discriminant
(Low_Bound
(Constr
))
1865 Denotes_Discriminant
(High_Bound
(Constr
));
1867 when N_Range_Constraint
=>
1868 return Denotes_Discriminant
(Range_Expression
(Constr
));
1876 ----------------------
1877 -- Is_Known_Limited --
1878 ----------------------
1880 function Is_Known_Limited
(Typ
: Entity_Id
) return Boolean is
1881 P
: constant Entity_Id
:= Etype
(Typ
);
1882 R
: constant Entity_Id
:= Root_Type
(Typ
);
1885 if Is_Limited_Record
(Typ
) then
1888 -- If the root type is limited (and not a limited interface)
1889 -- so is the current type
1891 elsif Is_Limited_Record
(R
)
1892 and then (not Is_Interface
(R
) or else not Is_Limited_Interface
(R
))
1896 -- Else the type may have a limited interface progenitor, but a
1897 -- limited record parent.
1899 elsif R
/= P
and then Is_Limited_Record
(P
) then
1905 end Is_Known_Limited
;
1907 -- Start of processing for Analyze_Component_Declaration
1910 Generate_Definition
(Id
);
1913 if Present
(Typ
) then
1914 T
:= Find_Type_Of_Object
1915 (Subtype_Indication
(Component_Definition
(N
)), N
);
1917 if not Nkind_In
(Typ
, N_Identifier
, N_Expanded_Name
) then
1918 Check_SPARK_05_Restriction
("subtype mark required", Typ
);
1921 -- Ada 2005 (AI-230): Access Definition case
1924 pragma Assert
(Present
1925 (Access_Definition
(Component_Definition
(N
))));
1927 T
:= Access_Definition
1929 N
=> Access_Definition
(Component_Definition
(N
)));
1930 Set_Is_Local_Anonymous_Access
(T
);
1932 -- Ada 2005 (AI-254)
1934 if Present
(Access_To_Subprogram_Definition
1935 (Access_Definition
(Component_Definition
(N
))))
1936 and then Protected_Present
(Access_To_Subprogram_Definition
1938 (Component_Definition
(N
))))
1940 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
1944 -- If the subtype is a constrained subtype of the enclosing record,
1945 -- (which must have a partial view) the back-end does not properly
1946 -- handle the recursion. Rewrite the component declaration with an
1947 -- explicit subtype indication, which is acceptable to Gigi. We can copy
1948 -- the tree directly because side effects have already been removed from
1949 -- discriminant constraints.
1951 if Ekind
(T
) = E_Access_Subtype
1952 and then Is_Entity_Name
(Subtype_Indication
(Component_Definition
(N
)))
1953 and then Comes_From_Source
(T
)
1954 and then Nkind
(Parent
(T
)) = N_Subtype_Declaration
1955 and then Etype
(Directly_Designated_Type
(T
)) = Current_Scope
1958 (Subtype_Indication
(Component_Definition
(N
)),
1959 New_Copy_Tree
(Subtype_Indication
(Parent
(T
))));
1960 T
:= Find_Type_Of_Object
1961 (Subtype_Indication
(Component_Definition
(N
)), N
);
1964 -- If the component declaration includes a default expression, then we
1965 -- check that the component is not of a limited type (RM 3.7(5)),
1966 -- and do the special preanalysis of the expression (see section on
1967 -- "Handling of Default and Per-Object Expressions" in the spec of
1971 Check_SPARK_05_Restriction
("default expression is not allowed", E
);
1972 Preanalyze_Default_Expression
(E
, T
);
1973 Check_Initialization
(T
, E
);
1975 if Ada_Version
>= Ada_2005
1976 and then Ekind
(T
) = E_Anonymous_Access_Type
1977 and then Etype
(E
) /= Any_Type
1979 -- Check RM 3.9.2(9): "if the expected type for an expression is
1980 -- an anonymous access-to-specific tagged type, then the object
1981 -- designated by the expression shall not be dynamically tagged
1982 -- unless it is a controlling operand in a call on a dispatching
1985 if Is_Tagged_Type
(Directly_Designated_Type
(T
))
1987 Ekind
(Directly_Designated_Type
(T
)) /= E_Class_Wide_Type
1989 Ekind
(Directly_Designated_Type
(Etype
(E
))) =
1993 ("access to specific tagged type required (RM 3.9.2(9))", E
);
1996 -- (Ada 2005: AI-230): Accessibility check for anonymous
1999 if Type_Access_Level
(Etype
(E
)) >
2000 Deepest_Type_Access_Level
(T
)
2003 ("expression has deeper access level than component " &
2004 "(RM 3.10.2 (12.2))", E
);
2007 -- The initialization expression is a reference to an access
2008 -- discriminant. The type of the discriminant is always deeper
2009 -- than any access type.
2011 if Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
2012 and then Is_Entity_Name
(E
)
2013 and then Ekind
(Entity
(E
)) = E_In_Parameter
2014 and then Present
(Discriminal_Link
(Entity
(E
)))
2017 ("discriminant has deeper accessibility level than target",
2023 -- The parent type may be a private view with unknown discriminants,
2024 -- and thus unconstrained. Regular components must be constrained.
2026 if Is_Indefinite_Subtype
(T
) and then Chars
(Id
) /= Name_uParent
then
2027 if Is_Class_Wide_Type
(T
) then
2029 ("class-wide subtype with unknown discriminants" &
2030 " in component declaration",
2031 Subtype_Indication
(Component_Definition
(N
)));
2034 ("unconstrained subtype in component declaration",
2035 Subtype_Indication
(Component_Definition
(N
)));
2038 -- Components cannot be abstract, except for the special case of
2039 -- the _Parent field (case of extending an abstract tagged type)
2041 elsif Is_Abstract_Type
(T
) and then Chars
(Id
) /= Name_uParent
then
2042 Error_Msg_N
("type of a component cannot be abstract", N
);
2046 Set_Is_Aliased
(Id
, Aliased_Present
(Component_Definition
(N
)));
2048 -- The component declaration may have a per-object constraint, set
2049 -- the appropriate flag in the defining identifier of the subtype.
2051 if Present
(Subtype_Indication
(Component_Definition
(N
))) then
2053 Sindic
: constant Node_Id
:=
2054 Subtype_Indication
(Component_Definition
(N
));
2056 if Nkind
(Sindic
) = N_Subtype_Indication
2057 and then Present
(Constraint
(Sindic
))
2058 and then Contains_POC
(Constraint
(Sindic
))
2060 Set_Has_Per_Object_Constraint
(Id
);
2065 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
2066 -- out some static checks.
2068 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(T
) then
2069 Null_Exclusion_Static_Checks
(N
);
2072 -- If this component is private (or depends on a private type), flag the
2073 -- record type to indicate that some operations are not available.
2075 P
:= Private_Component
(T
);
2079 -- Check for circular definitions
2081 if P
= Any_Type
then
2082 Set_Etype
(Id
, Any_Type
);
2084 -- There is a gap in the visibility of operations only if the
2085 -- component type is not defined in the scope of the record type.
2087 elsif Scope
(P
) = Scope
(Current_Scope
) then
2090 elsif Is_Limited_Type
(P
) then
2091 Set_Is_Limited_Composite
(Current_Scope
);
2094 Set_Is_Private_Composite
(Current_Scope
);
2099 and then Is_Limited_Type
(T
)
2100 and then Chars
(Id
) /= Name_uParent
2101 and then Is_Tagged_Type
(Current_Scope
)
2103 if Is_Derived_Type
(Current_Scope
)
2104 and then not Is_Known_Limited
(Current_Scope
)
2107 ("extension of nonlimited type cannot have limited components",
2110 if Is_Interface
(Root_Type
(Current_Scope
)) then
2112 ("\limitedness is not inherited from limited interface", N
);
2113 Error_Msg_N
("\add LIMITED to type indication", N
);
2116 Explain_Limited_Type
(T
, N
);
2117 Set_Etype
(Id
, Any_Type
);
2118 Set_Is_Limited_Composite
(Current_Scope
, False);
2120 elsif not Is_Derived_Type
(Current_Scope
)
2121 and then not Is_Limited_Record
(Current_Scope
)
2122 and then not Is_Concurrent_Type
(Current_Scope
)
2125 ("nonlimited tagged type cannot have limited components", N
);
2126 Explain_Limited_Type
(T
, N
);
2127 Set_Etype
(Id
, Any_Type
);
2128 Set_Is_Limited_Composite
(Current_Scope
, False);
2132 -- If the component is an unconstrained task or protected type with
2133 -- discriminants, the component and the enclosing record are limited
2134 -- and the component is constrained by its default values. Compute
2135 -- its actual subtype, else it may be allocated the maximum size by
2136 -- the backend, and possibly overflow.
2138 if Is_Concurrent_Type
(T
)
2139 and then not Is_Constrained
(T
)
2140 and then Has_Discriminants
(T
)
2141 and then not Has_Discriminants
(Current_Scope
)
2144 Act_T
: constant Entity_Id
:= Build_Default_Subtype
(T
, N
);
2147 Set_Etype
(Id
, Act_T
);
2149 -- Rewrite component definition to use the constrained subtype
2151 Rewrite
(Component_Definition
(N
),
2152 Make_Component_Definition
(Loc
,
2153 Subtype_Indication
=> New_Occurrence_Of
(Act_T
, Loc
)));
2157 Set_Original_Record_Component
(Id
, Id
);
2159 if Has_Aspects
(N
) then
2160 Analyze_Aspect_Specifications
(N
, Id
);
2163 Analyze_Dimension
(N
);
2164 end Analyze_Component_Declaration
;
2166 --------------------------
2167 -- Analyze_Declarations --
2168 --------------------------
2170 procedure Analyze_Declarations
(L
: List_Id
) is
2173 procedure Adjust_Decl
;
2174 -- Adjust Decl not to include implicit label declarations, since these
2175 -- have strange Sloc values that result in elaboration check problems.
2176 -- (They have the sloc of the label as found in the source, and that
2177 -- is ahead of the current declarative part).
2179 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
);
2180 -- Determine whether Body_Decl denotes the body of a late controlled
2181 -- primitive (either Initialize, Adjust or Finalize). If this is the
2182 -- case, add a proper spec if the body lacks one. The spec is inserted
2183 -- before Body_Decl and immedately analyzed.
2185 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
);
2186 -- Spec_Id is the entity of a package that may define abstract states.
2187 -- If the states have visible refinement, remove the visibility of each
2188 -- constituent at the end of the package body declarations.
2194 procedure Adjust_Decl
is
2196 while Present
(Prev
(Decl
))
2197 and then Nkind
(Decl
) = N_Implicit_Label_Declaration
2203 --------------------------------------
2204 -- Handle_Late_Controlled_Primitive --
2205 --------------------------------------
2207 procedure Handle_Late_Controlled_Primitive
(Body_Decl
: Node_Id
) is
2208 Body_Spec
: constant Node_Id
:= Specification
(Body_Decl
);
2209 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2210 Loc
: constant Source_Ptr
:= Sloc
(Body_Id
);
2211 Params
: constant List_Id
:=
2212 Parameter_Specifications
(Body_Spec
);
2214 Spec_Id
: Entity_Id
;
2218 -- Consider only procedure bodies whose name matches one of the three
2219 -- controlled primitives.
2221 if Nkind
(Body_Spec
) /= N_Procedure_Specification
2222 or else not Nam_In
(Chars
(Body_Id
), Name_Adjust
,
2228 -- A controlled primitive must have exactly one formal which is not
2229 -- an anonymous access type.
2231 elsif List_Length
(Params
) /= 1 then
2235 Typ
:= Parameter_Type
(First
(Params
));
2237 if Nkind
(Typ
) = N_Access_Definition
then
2243 -- The type of the formal must be derived from [Limited_]Controlled
2245 if not Is_Controlled
(Entity
(Typ
)) then
2249 -- Check whether a specification exists for this body. We do not
2250 -- analyze the spec of the body in full, because it will be analyzed
2251 -- again when the body is properly analyzed, and we cannot create
2252 -- duplicate entries in the formals chain. We look for an explicit
2253 -- specification because the body may be an overriding operation and
2254 -- an inherited spec may be present.
2256 Spec_Id
:= Current_Entity
(Body_Id
);
2258 while Present
(Spec_Id
) loop
2259 if Ekind_In
(Spec_Id
, E_Procedure
, E_Generic_Procedure
)
2260 and then Scope
(Spec_Id
) = Current_Scope
2261 and then Present
(First_Formal
(Spec_Id
))
2262 and then No
(Next_Formal
(First_Formal
(Spec_Id
)))
2263 and then Etype
(First_Formal
(Spec_Id
)) = Entity
(Typ
)
2264 and then Comes_From_Source
(Spec_Id
)
2269 Spec_Id
:= Homonym
(Spec_Id
);
2272 -- At this point the body is known to be a late controlled primitive.
2273 -- Generate a matching spec and insert it before the body. Note the
2274 -- use of Copy_Separate_Tree - we want an entirely separate semantic
2275 -- tree in this case.
2277 Spec
:= Copy_Separate_Tree
(Body_Spec
);
2279 -- Ensure that the subprogram declaration does not inherit the null
2280 -- indicator from the body as we now have a proper spec/body pair.
2282 Set_Null_Present
(Spec
, False);
2284 Insert_Before_And_Analyze
(Body_Decl
,
2285 Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
));
2286 end Handle_Late_Controlled_Primitive
;
2288 --------------------------------
2289 -- Remove_Visible_Refinements --
2290 --------------------------------
2292 procedure Remove_Visible_Refinements
(Spec_Id
: Entity_Id
) is
2293 State_Elmt
: Elmt_Id
;
2295 if Present
(Abstract_States
(Spec_Id
)) then
2296 State_Elmt
:= First_Elmt
(Abstract_States
(Spec_Id
));
2297 while Present
(State_Elmt
) loop
2298 Set_Has_Visible_Refinement
(Node
(State_Elmt
), False);
2299 Next_Elmt
(State_Elmt
);
2302 end Remove_Visible_Refinements
;
2306 Context
: Node_Id
:= Empty
;
2307 Freeze_From
: Entity_Id
:= Empty
;
2308 Next_Decl
: Node_Id
;
2309 Pack_Decl
: Node_Id
:= Empty
;
2311 Body_Seen
: Boolean := False;
2312 -- Flag set when the first body [stub] is encountered
2314 -- Start of processing for Analyze_Declarations
2317 if Restriction_Check_Required
(SPARK_05
) then
2318 Check_Later_Vs_Basic_Declarations
(L
, During_Parsing
=> False);
2322 while Present
(Decl
) loop
2324 -- Package spec cannot contain a package declaration in SPARK
2326 if Nkind
(Decl
) = N_Package_Declaration
2327 and then Nkind
(Parent
(L
)) = N_Package_Specification
2329 Check_SPARK_05_Restriction
2330 ("package specification cannot contain a package declaration",
2334 -- Complete analysis of declaration
2337 Next_Decl
:= Next
(Decl
);
2339 if No
(Freeze_From
) then
2340 Freeze_From
:= First_Entity
(Current_Scope
);
2343 -- At the end of a declarative part, freeze remaining entities
2344 -- declared in it. The end of the visible declarations of package
2345 -- specification is not the end of a declarative part if private
2346 -- declarations are present. The end of a package declaration is a
2347 -- freezing point only if it a library package. A task definition or
2348 -- protected type definition is not a freeze point either. Finally,
2349 -- we do not freeze entities in generic scopes, because there is no
2350 -- code generated for them and freeze nodes will be generated for
2353 -- The end of a package instantiation is not a freeze point, but
2354 -- for now we make it one, because the generic body is inserted
2355 -- (currently) immediately after. Generic instantiations will not
2356 -- be a freeze point once delayed freezing of bodies is implemented.
2357 -- (This is needed in any case for early instantiations ???).
2359 if No
(Next_Decl
) then
2360 if Nkind_In
(Parent
(L
), N_Component_List
,
2362 N_Protected_Definition
)
2366 elsif Nkind
(Parent
(L
)) /= N_Package_Specification
then
2367 if Nkind
(Parent
(L
)) = N_Package_Body
then
2368 Freeze_From
:= First_Entity
(Current_Scope
);
2371 -- There may have been several freezing points previously,
2372 -- for example object declarations or subprogram bodies, but
2373 -- at the end of a declarative part we check freezing from
2374 -- the beginning, even though entities may already be frozen,
2375 -- in order to perform visibility checks on delayed aspects.
2378 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2379 Freeze_From
:= Last_Entity
(Current_Scope
);
2381 elsif Scope
(Current_Scope
) /= Standard_Standard
2382 and then not Is_Child_Unit
(Current_Scope
)
2383 and then No
(Generic_Parent
(Parent
(L
)))
2387 elsif L
/= Visible_Declarations
(Parent
(L
))
2388 or else No
(Private_Declarations
(Parent
(L
)))
2389 or else Is_Empty_List
(Private_Declarations
(Parent
(L
)))
2392 Freeze_All
(First_Entity
(Current_Scope
), Decl
);
2393 Freeze_From
:= Last_Entity
(Current_Scope
);
2396 -- If next node is a body then freeze all types before the body.
2397 -- An exception occurs for some expander-generated bodies. If these
2398 -- are generated at places where in general language rules would not
2399 -- allow a freeze point, then we assume that the expander has
2400 -- explicitly checked that all required types are properly frozen,
2401 -- and we do not cause general freezing here. This special circuit
2402 -- is used when the encountered body is marked as having already
2405 -- In all other cases (bodies that come from source, and expander
2406 -- generated bodies that have not been analyzed yet), freeze all
2407 -- types now. Note that in the latter case, the expander must take
2408 -- care to attach the bodies at a proper place in the tree so as to
2409 -- not cause unwanted freezing at that point.
2411 elsif not Analyzed
(Next_Decl
) and then Is_Body
(Next_Decl
) then
2413 -- When a controlled type is frozen, the expander generates stream
2414 -- and controlled type support routines. If the freeze is caused
2415 -- by the stand alone body of Initialize, Adjust and Finalize, the
2416 -- expander will end up using the wrong version of these routines
2417 -- as the body has not been processed yet. To remedy this, detect
2418 -- a late controlled primitive and create a proper spec for it.
2419 -- This ensures that the primitive will override its inherited
2420 -- counterpart before the freeze takes place.
2422 -- If the declaration we just processed is a body, do not attempt
2423 -- to examine Next_Decl as the late primitive idiom can only apply
2424 -- to the first encountered body.
2426 -- The spec of the late primitive is not generated in ASIS mode to
2427 -- ensure a consistent list of primitives that indicates the true
2428 -- semantic structure of the program (which is not relevant when
2429 -- generating executable code.
2431 -- ??? a cleaner approach may be possible and/or this solution
2432 -- could be extended to general-purpose late primitives, TBD.
2434 if not ASIS_Mode
and then not Body_Seen
and then not Is_Body
(Decl
)
2438 if Nkind
(Next_Decl
) = N_Subprogram_Body
then
2439 Handle_Late_Controlled_Primitive
(Next_Decl
);
2444 Freeze_All
(Freeze_From
, Decl
);
2445 Freeze_From
:= Last_Entity
(Current_Scope
);
2451 -- Analyze the contracts of packages and their bodies
2454 Context
:= Parent
(L
);
2456 if Nkind
(Context
) = N_Package_Specification
then
2457 Pack_Decl
:= Parent
(Context
);
2459 -- When a package has private declarations, its contract must be
2460 -- analyzed at the end of the said declarations. This way both the
2461 -- analysis and freeze actions are properly synchronized in case
2462 -- of private type use within the contract.
2464 if L
= Private_Declarations
(Context
) then
2465 Analyze_Package_Contract
(Defining_Entity
(Context
));
2467 -- Build the bodies of the default initial condition procedures
2468 -- for all types subject to pragma Default_Initial_Condition.
2469 -- From a purely Ada stand point, this is a freezing activity,
2470 -- however freezing is not available under GNATprove_Mode. To
2471 -- accomodate both scenarios, the bodies are build at the end
2472 -- of private declaration analysis.
2474 Build_Default_Init_Cond_Procedure_Bodies
(L
);
2476 -- Otherwise the contract is analyzed at the end of the visible
2479 elsif L
= Visible_Declarations
(Context
)
2480 and then No
(Private_Declarations
(Context
))
2482 Analyze_Package_Contract
(Defining_Entity
(Context
));
2485 elsif Nkind
(Context
) = N_Package_Body
then
2486 Pack_Decl
:= Context
;
2487 Analyze_Package_Body_Contract
(Defining_Entity
(Context
));
2490 -- Analyze the contracts of all subprogram declarations, subprogram
2491 -- bodies and variables now due to the delayed visibility needs of
2492 -- of their aspects and pragmas. Capture global references in generic
2493 -- subprograms or bodies.
2496 while Present
(Decl
) loop
2497 if Nkind
(Decl
) = N_Object_Declaration
then
2498 Analyze_Object_Contract
(Defining_Entity
(Decl
));
2500 elsif Nkind_In
(Decl
, N_Abstract_Subprogram_Declaration
,
2501 N_Generic_Subprogram_Declaration
,
2502 N_Subprogram_Declaration
)
2504 Analyze_Subprogram_Contract
(Defining_Entity
(Decl
));
2506 elsif Nkind
(Decl
) = N_Subprogram_Body
then
2507 Analyze_Subprogram_Body_Contract
(Defining_Entity
(Decl
));
2509 elsif Nkind
(Decl
) = N_Subprogram_Body_Stub
then
2510 Analyze_Subprogram_Body_Stub_Contract
(Defining_Entity
(Decl
));
2513 -- Capture all global references in a generic subprogram or a body
2514 -- [stub] now that the contract has been analyzed.
2516 if Nkind_In
(Decl
, N_Generic_Subprogram_Declaration
,
2518 N_Subprogram_Body_Stub
)
2519 and then Is_Generic_Declaration_Or_Body
(Decl
)
2521 Save_Global_References_In_Contract
2522 (Templ
=> Original_Node
(Decl
),
2523 Gen_Id
=> Corresponding_Spec_Of
(Decl
));
2529 -- The owner of the declarations is a package [body]
2531 if Present
(Pack_Decl
) then
2533 -- Capture all global references in a generic package or a body
2534 -- after all nested generic subprograms and bodies were subjected
2535 -- to the same processing.
2537 if Is_Generic_Declaration_Or_Body
(Pack_Decl
) then
2538 Save_Global_References_In_Contract
2539 (Templ
=> Original_Node
(Pack_Decl
),
2540 Gen_Id
=> Corresponding_Spec_Of
(Pack_Decl
));
2543 -- State refinements are visible upto the end the of the package
2544 -- body declarations. Hide the state refinements from visibility
2545 -- to restore the original state conditions.
2547 if Nkind
(Pack_Decl
) = N_Package_Body
then
2548 Remove_Visible_Refinements
(Corresponding_Spec
(Pack_Decl
));
2552 end Analyze_Declarations
;
2554 -----------------------------------
2555 -- Analyze_Full_Type_Declaration --
2556 -----------------------------------
2558 procedure Analyze_Full_Type_Declaration
(N
: Node_Id
) is
2559 Def
: constant Node_Id
:= Type_Definition
(N
);
2560 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
2564 Is_Remote
: constant Boolean :=
2565 (Is_Remote_Types
(Current_Scope
)
2566 or else Is_Remote_Call_Interface
(Current_Scope
))
2567 and then not (In_Private_Part
(Current_Scope
)
2568 or else In_Package_Body
(Current_Scope
));
2570 procedure Check_Ops_From_Incomplete_Type
;
2571 -- If there is a tagged incomplete partial view of the type, traverse
2572 -- the primitives of the incomplete view and change the type of any
2573 -- controlling formals and result to indicate the full view. The
2574 -- primitives will be added to the full type's primitive operations
2575 -- list later in Sem_Disp.Check_Operation_From_Incomplete_Type (which
2576 -- is called from Process_Incomplete_Dependents).
2578 ------------------------------------
2579 -- Check_Ops_From_Incomplete_Type --
2580 ------------------------------------
2582 procedure Check_Ops_From_Incomplete_Type
is
2589 and then Ekind
(Prev
) = E_Incomplete_Type
2590 and then Is_Tagged_Type
(Prev
)
2591 and then Is_Tagged_Type
(T
)
2593 Elmt
:= First_Elmt
(Primitive_Operations
(Prev
));
2594 while Present
(Elmt
) loop
2597 Formal
:= First_Formal
(Op
);
2598 while Present
(Formal
) loop
2599 if Etype
(Formal
) = Prev
then
2600 Set_Etype
(Formal
, T
);
2603 Next_Formal
(Formal
);
2606 if Etype
(Op
) = Prev
then
2613 end Check_Ops_From_Incomplete_Type
;
2615 -- Start of processing for Analyze_Full_Type_Declaration
2618 Prev
:= Find_Type_Name
(N
);
2620 -- The type declaration may be subject to pragma Ghost with policy
2621 -- Ignore. Set the mode now to ensure that any nodes generated during
2622 -- analysis and expansion are properly flagged as ignored Ghost.
2624 Set_Ghost_Mode
(N
, Prev
);
2626 -- The full view, if present, now points to the current type. If there
2627 -- is an incomplete partial view, set a link to it, to simplify the
2628 -- retrieval of primitive operations of the type.
2630 -- Ada 2005 (AI-50217): If the type was previously decorated when
2631 -- imported through a LIMITED WITH clause, it appears as incomplete
2632 -- but has no full view.
2634 if Ekind
(Prev
) = E_Incomplete_Type
2635 and then Present
(Full_View
(Prev
))
2637 T
:= Full_View
(Prev
);
2638 Set_Incomplete_View
(N
, Parent
(Prev
));
2643 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
2645 -- We set the flag Is_First_Subtype here. It is needed to set the
2646 -- corresponding flag for the Implicit class-wide-type created
2647 -- during tagged types processing.
2649 Set_Is_First_Subtype
(T
, True);
2651 -- Only composite types other than array types are allowed to have
2656 -- For derived types, the rule will be checked once we've figured
2657 -- out the parent type.
2659 when N_Derived_Type_Definition
=>
2662 -- For record types, discriminants are allowed, unless we are in
2665 when N_Record_Definition
=>
2666 if Present
(Discriminant_Specifications
(N
)) then
2667 Check_SPARK_05_Restriction
2668 ("discriminant type is not allowed",
2670 (First
(Discriminant_Specifications
(N
))));
2674 if Present
(Discriminant_Specifications
(N
)) then
2676 ("elementary or array type cannot have discriminants",
2678 (First
(Discriminant_Specifications
(N
))));
2682 -- Elaborate the type definition according to kind, and generate
2683 -- subsidiary (implicit) subtypes where needed. We skip this if it was
2684 -- already done (this happens during the reanalysis that follows a call
2685 -- to the high level optimizer).
2687 if not Analyzed
(T
) then
2691 when N_Access_To_Subprogram_Definition
=>
2692 Access_Subprogram_Declaration
(T
, Def
);
2694 -- If this is a remote access to subprogram, we must create the
2695 -- equivalent fat pointer type, and related subprograms.
2698 Process_Remote_AST_Declaration
(N
);
2701 -- Validate categorization rule against access type declaration
2702 -- usually a violation in Pure unit, Shared_Passive unit.
2704 Validate_Access_Type_Declaration
(T
, N
);
2706 when N_Access_To_Object_Definition
=>
2707 Access_Type_Declaration
(T
, Def
);
2709 -- Validate categorization rule against access type declaration
2710 -- usually a violation in Pure unit, Shared_Passive unit.
2712 Validate_Access_Type_Declaration
(T
, N
);
2714 -- If we are in a Remote_Call_Interface package and define a
2715 -- RACW, then calling stubs and specific stream attributes
2719 and then Is_Remote_Access_To_Class_Wide_Type
(Def_Id
)
2721 Add_RACW_Features
(Def_Id
);
2724 when N_Array_Type_Definition
=>
2725 Array_Type_Declaration
(T
, Def
);
2727 when N_Derived_Type_Definition
=>
2728 Derived_Type_Declaration
(T
, N
, T
/= Def_Id
);
2730 when N_Enumeration_Type_Definition
=>
2731 Enumeration_Type_Declaration
(T
, Def
);
2733 when N_Floating_Point_Definition
=>
2734 Floating_Point_Type_Declaration
(T
, Def
);
2736 when N_Decimal_Fixed_Point_Definition
=>
2737 Decimal_Fixed_Point_Type_Declaration
(T
, Def
);
2739 when N_Ordinary_Fixed_Point_Definition
=>
2740 Ordinary_Fixed_Point_Type_Declaration
(T
, Def
);
2742 when N_Signed_Integer_Type_Definition
=>
2743 Signed_Integer_Type_Declaration
(T
, Def
);
2745 when N_Modular_Type_Definition
=>
2746 Modular_Type_Declaration
(T
, Def
);
2748 when N_Record_Definition
=>
2749 Record_Type_Declaration
(T
, N
, Prev
);
2751 -- If declaration has a parse error, nothing to elaborate.
2757 raise Program_Error
;
2762 if Etype
(T
) = Any_Type
then
2766 -- Controlled type is not allowed in SPARK
2768 if Is_Visibly_Controlled
(T
) then
2769 Check_SPARK_05_Restriction
("controlled type is not allowed", N
);
2772 -- A type declared within a Ghost region is automatically Ghost
2773 -- (SPARK RM 6.9(2)).
2775 if Comes_From_Source
(T
) and then Ghost_Mode
> None
then
2776 Set_Is_Ghost_Entity
(T
);
2779 -- Some common processing for all types
2781 Set_Depends_On_Private
(T
, Has_Private_Component
(T
));
2782 Check_Ops_From_Incomplete_Type
;
2784 -- Both the declared entity, and its anonymous base type if one was
2785 -- created, need freeze nodes allocated.
2788 B
: constant Entity_Id
:= Base_Type
(T
);
2791 -- In the case where the base type differs from the first subtype, we
2792 -- pre-allocate a freeze node, and set the proper link to the first
2793 -- subtype. Freeze_Entity will use this preallocated freeze node when
2794 -- it freezes the entity.
2796 -- This does not apply if the base type is a generic type, whose
2797 -- declaration is independent of the current derived definition.
2799 if B
/= T
and then not Is_Generic_Type
(B
) then
2800 Ensure_Freeze_Node
(B
);
2801 Set_First_Subtype_Link
(Freeze_Node
(B
), T
);
2804 -- A type that is imported through a limited_with clause cannot
2805 -- generate any code, and thus need not be frozen. However, an access
2806 -- type with an imported designated type needs a finalization list,
2807 -- which may be referenced in some other package that has non-limited
2808 -- visibility on the designated type. Thus we must create the
2809 -- finalization list at the point the access type is frozen, to
2810 -- prevent unsatisfied references at link time.
2812 if not From_Limited_With
(T
) or else Is_Access_Type
(T
) then
2813 Set_Has_Delayed_Freeze
(T
);
2817 -- Case where T is the full declaration of some private type which has
2818 -- been swapped in Defining_Identifier (N).
2820 if T
/= Def_Id
and then Is_Private_Type
(Def_Id
) then
2821 Process_Full_View
(N
, T
, Def_Id
);
2823 -- Record the reference. The form of this is a little strange, since
2824 -- the full declaration has been swapped in. So the first parameter
2825 -- here represents the entity to which a reference is made which is
2826 -- the "real" entity, i.e. the one swapped in, and the second
2827 -- parameter provides the reference location.
2829 -- Also, we want to kill Has_Pragma_Unreferenced temporarily here
2830 -- since we don't want a complaint about the full type being an
2831 -- unwanted reference to the private type
2834 B
: constant Boolean := Has_Pragma_Unreferenced
(T
);
2836 Set_Has_Pragma_Unreferenced
(T
, False);
2837 Generate_Reference
(T
, T
, 'c');
2838 Set_Has_Pragma_Unreferenced
(T
, B
);
2841 Set_Completion_Referenced
(Def_Id
);
2843 -- For completion of incomplete type, process incomplete dependents
2844 -- and always mark the full type as referenced (it is the incomplete
2845 -- type that we get for any real reference).
2847 elsif Ekind
(Prev
) = E_Incomplete_Type
then
2848 Process_Incomplete_Dependents
(N
, T
, Prev
);
2849 Generate_Reference
(Prev
, Def_Id
, 'c');
2850 Set_Completion_Referenced
(Def_Id
);
2852 -- If not private type or incomplete type completion, this is a real
2853 -- definition of a new entity, so record it.
2856 Generate_Definition
(Def_Id
);
2859 -- Propagate any pending access types whose finalization masters need to
2860 -- be fully initialized from the partial to the full view. Guard against
2861 -- an illegal full view that remains unanalyzed.
2863 if Is_Type
(Def_Id
) and then Is_Incomplete_Or_Private_Type
(Prev
) then
2864 Set_Pending_Access_Types
(Def_Id
, Pending_Access_Types
(Prev
));
2867 if Chars
(Scope
(Def_Id
)) = Name_System
2868 and then Chars
(Def_Id
) = Name_Address
2869 and then Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(N
)))
2871 Set_Is_Descendent_Of_Address
(Def_Id
);
2872 Set_Is_Descendent_Of_Address
(Base_Type
(Def_Id
));
2873 Set_Is_Descendent_Of_Address
(Prev
);
2876 Set_Optimize_Alignment_Flags
(Def_Id
);
2877 Check_Eliminated
(Def_Id
);
2879 -- If the declaration is a completion and aspects are present, apply
2880 -- them to the entity for the type which is currently the partial
2881 -- view, but which is the one that will be frozen.
2883 if Has_Aspects
(N
) then
2885 -- In most cases the partial view is a private type, and both views
2886 -- appear in different declarative parts. In the unusual case where
2887 -- the partial view is incomplete, perform the analysis on the
2888 -- full view, to prevent freezing anomalies with the corresponding
2889 -- class-wide type, which otherwise might be frozen before the
2890 -- dispatch table is built.
2893 and then Ekind
(Prev
) /= E_Incomplete_Type
2895 Analyze_Aspect_Specifications
(N
, Prev
);
2900 Analyze_Aspect_Specifications
(N
, Def_Id
);
2903 end Analyze_Full_Type_Declaration
;
2905 ----------------------------------
2906 -- Analyze_Incomplete_Type_Decl --
2907 ----------------------------------
2909 procedure Analyze_Incomplete_Type_Decl
(N
: Node_Id
) is
2910 F
: constant Boolean := Is_Pure
(Current_Scope
);
2914 Check_SPARK_05_Restriction
("incomplete type is not allowed", N
);
2916 Generate_Definition
(Defining_Identifier
(N
));
2918 -- Process an incomplete declaration. The identifier must not have been
2919 -- declared already in the scope. However, an incomplete declaration may
2920 -- appear in the private part of a package, for a private type that has
2921 -- already been declared.
2923 -- In this case, the discriminants (if any) must match
2925 T
:= Find_Type_Name
(N
);
2927 Set_Ekind
(T
, E_Incomplete_Type
);
2928 Init_Size_Align
(T
);
2929 Set_Is_First_Subtype
(T
, True);
2932 -- An incomplete type declared within a Ghost region is automatically
2933 -- Ghost (SPARK RM 6.9(2)).
2935 if Ghost_Mode
> None
then
2936 Set_Is_Ghost_Entity
(T
);
2939 -- Ada 2005 (AI-326): Minimum decoration to give support to tagged
2940 -- incomplete types.
2942 if Tagged_Present
(N
) then
2943 Set_Is_Tagged_Type
(T
, True);
2944 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
2945 Make_Class_Wide_Type
(T
);
2946 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
2951 Set_Stored_Constraint
(T
, No_Elist
);
2953 if Present
(Discriminant_Specifications
(N
)) then
2954 Process_Discriminants
(N
);
2959 -- If the type has discriminants, non-trivial subtypes may be
2960 -- declared before the full view of the type. The full views of those
2961 -- subtypes will be built after the full view of the type.
2963 Set_Private_Dependents
(T
, New_Elmt_List
);
2965 end Analyze_Incomplete_Type_Decl
;
2967 -----------------------------------
2968 -- Analyze_Interface_Declaration --
2969 -----------------------------------
2971 procedure Analyze_Interface_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
2972 CW
: constant Entity_Id
:= Class_Wide_Type
(T
);
2975 Set_Is_Tagged_Type
(T
);
2976 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
2978 Set_Is_Limited_Record
(T
, Limited_Present
(Def
)
2979 or else Task_Present
(Def
)
2980 or else Protected_Present
(Def
)
2981 or else Synchronized_Present
(Def
));
2983 -- Type is abstract if full declaration carries keyword, or if previous
2984 -- partial view did.
2986 Set_Is_Abstract_Type
(T
);
2987 Set_Is_Interface
(T
);
2989 -- Type is a limited interface if it includes the keyword limited, task,
2990 -- protected, or synchronized.
2992 Set_Is_Limited_Interface
2993 (T
, Limited_Present
(Def
)
2994 or else Protected_Present
(Def
)
2995 or else Synchronized_Present
(Def
)
2996 or else Task_Present
(Def
));
2998 Set_Interfaces
(T
, New_Elmt_List
);
2999 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
3001 -- Complete the decoration of the class-wide entity if it was already
3002 -- built (i.e. during the creation of the limited view)
3004 if Present
(CW
) then
3005 Set_Is_Interface
(CW
);
3006 Set_Is_Limited_Interface
(CW
, Is_Limited_Interface
(T
));
3009 -- Check runtime support for synchronized interfaces
3011 if VM_Target
= No_VM
3012 and then (Is_Task_Interface
(T
)
3013 or else Is_Protected_Interface
(T
)
3014 or else Is_Synchronized_Interface
(T
))
3015 and then not RTE_Available
(RE_Select_Specific_Data
)
3017 Error_Msg_CRT
("synchronized interfaces", T
);
3019 end Analyze_Interface_Declaration
;
3021 -----------------------------
3022 -- Analyze_Itype_Reference --
3023 -----------------------------
3025 -- Nothing to do. This node is placed in the tree only for the benefit of
3026 -- back end processing, and has no effect on the semantic processing.
3028 procedure Analyze_Itype_Reference
(N
: Node_Id
) is
3030 pragma Assert
(Is_Itype
(Itype
(N
)));
3032 end Analyze_Itype_Reference
;
3034 --------------------------------
3035 -- Analyze_Number_Declaration --
3036 --------------------------------
3038 procedure Analyze_Number_Declaration
(N
: Node_Id
) is
3039 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3040 E
: constant Node_Id
:= Expression
(N
);
3042 Index
: Interp_Index
;
3046 -- The number declaration may be subject to pragma Ghost with policy
3047 -- Ignore. Set the mode now to ensure that any nodes generated during
3048 -- analysis and expansion are properly flagged as ignored Ghost.
3052 Generate_Definition
(Id
);
3055 -- A number declared within a Ghost region is automatically Ghost
3056 -- (SPARK RM 6.9(2)).
3058 if Ghost_Mode
> None
then
3059 Set_Is_Ghost_Entity
(Id
);
3062 -- This is an optimization of a common case of an integer literal
3064 if Nkind
(E
) = N_Integer_Literal
then
3065 Set_Is_Static_Expression
(E
, True);
3066 Set_Etype
(E
, Universal_Integer
);
3068 Set_Etype
(Id
, Universal_Integer
);
3069 Set_Ekind
(Id
, E_Named_Integer
);
3070 Set_Is_Frozen
(Id
, True);
3074 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
3076 -- Process expression, replacing error by integer zero, to avoid
3077 -- cascaded errors or aborts further along in the processing
3079 -- Replace Error by integer zero, which seems least likely to cause
3083 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), Uint_0
));
3084 Set_Error_Posted
(E
);
3089 -- Verify that the expression is static and numeric. If
3090 -- the expression is overloaded, we apply the preference
3091 -- rule that favors root numeric types.
3093 if not Is_Overloaded
(E
) then
3095 if Has_Dynamic_Predicate_Aspect
(T
) then
3097 ("subtype has dynamic predicate, "
3098 & "not allowed in number declaration", N
);
3104 Get_First_Interp
(E
, Index
, It
);
3105 while Present
(It
.Typ
) loop
3106 if (Is_Integer_Type
(It
.Typ
) or else Is_Real_Type
(It
.Typ
))
3107 and then (Scope
(Base_Type
(It
.Typ
))) = Standard_Standard
3109 if T
= Any_Type
then
3112 elsif It
.Typ
= Universal_Real
3114 It
.Typ
= Universal_Integer
3116 -- Choose universal interpretation over any other
3123 Get_Next_Interp
(Index
, It
);
3127 if Is_Integer_Type
(T
) then
3129 Set_Etype
(Id
, Universal_Integer
);
3130 Set_Ekind
(Id
, E_Named_Integer
);
3132 elsif Is_Real_Type
(T
) then
3134 -- Because the real value is converted to universal_real, this is a
3135 -- legal context for a universal fixed expression.
3137 if T
= Universal_Fixed
then
3139 Loc
: constant Source_Ptr
:= Sloc
(N
);
3140 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3142 New_Occurrence_Of
(Universal_Real
, Loc
),
3143 Expression
=> Relocate_Node
(E
));
3150 elsif T
= Any_Fixed
then
3151 Error_Msg_N
("illegal context for mixed mode operation", E
);
3153 -- Expression is of the form : universal_fixed * integer. Try to
3154 -- resolve as universal_real.
3156 T
:= Universal_Real
;
3161 Set_Etype
(Id
, Universal_Real
);
3162 Set_Ekind
(Id
, E_Named_Real
);
3165 Wrong_Type
(E
, Any_Numeric
);
3169 Set_Ekind
(Id
, E_Constant
);
3170 Set_Never_Set_In_Source
(Id
, True);
3171 Set_Is_True_Constant
(Id
, True);
3175 if Nkind_In
(E
, N_Integer_Literal
, N_Real_Literal
) then
3176 Set_Etype
(E
, Etype
(Id
));
3179 if not Is_OK_Static_Expression
(E
) then
3180 Flag_Non_Static_Expr
3181 ("non-static expression used in number declaration!", E
);
3182 Rewrite
(E
, Make_Integer_Literal
(Sloc
(N
), 1));
3183 Set_Etype
(E
, Any_Type
);
3185 end Analyze_Number_Declaration
;
3187 -----------------------------
3188 -- Analyze_Object_Contract --
3189 -----------------------------
3191 procedure Analyze_Object_Contract
(Obj_Id
: Entity_Id
) is
3192 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
3193 AR_Val
: Boolean := False;
3194 AW_Val
: Boolean := False;
3195 ER_Val
: Boolean := False;
3196 EW_Val
: Boolean := False;
3198 Seen
: Boolean := False;
3201 -- The loop parameter in an element iterator over a formal container
3202 -- is declared with an object declaration but no contracts apply.
3204 if Ekind
(Obj_Id
) = E_Loop_Parameter
then
3208 -- Constant related checks
3210 if Ekind
(Obj_Id
) = E_Constant
then
3212 -- A constant cannot be effectively volatile. This check is only
3213 -- relevant with SPARK_Mode on as it is not a standard Ada legality
3214 -- rule. Do not flag internally-generated constants that map generic
3215 -- formals to actuals in instantiations (SPARK RM 7.1.3(6)).
3218 and then Is_Effectively_Volatile
(Obj_Id
)
3219 and then No
(Corresponding_Generic_Association
(Parent
(Obj_Id
)))
3221 -- Don't give this for internally generated entities (such as the
3222 -- FIRST and LAST temporaries generated for bounds).
3224 and then Comes_From_Source
(Obj_Id
)
3226 Error_Msg_N
("constant cannot be volatile", Obj_Id
);
3229 -- Variable related checks
3231 else pragma Assert
(Ekind
(Obj_Id
) = E_Variable
);
3233 -- The following checks are only relevant when SPARK_Mode is on as
3234 -- they are not standard Ada legality rules. Internally generated
3235 -- temporaries are ignored.
3237 if SPARK_Mode
= On
and then Comes_From_Source
(Obj_Id
) then
3238 if Is_Effectively_Volatile
(Obj_Id
) then
3240 -- The declaration of an effectively volatile object must
3241 -- appear at the library level (SPARK RM 7.1.3(7), C.6(6)).
3243 if not Is_Library_Level_Entity
(Obj_Id
) then
3245 ("volatile variable & must be declared at library level",
3248 -- An object of a discriminated type cannot be effectively
3249 -- volatile (SPARK RM C.6(4)).
3251 elsif Has_Discriminants
(Obj_Typ
) then
3253 ("discriminated object & cannot be volatile", Obj_Id
);
3255 -- An object of a tagged type cannot be effectively volatile
3256 -- (SPARK RM C.6(5)).
3258 elsif Is_Tagged_Type
(Obj_Typ
) then
3259 Error_Msg_N
("tagged object & cannot be volatile", Obj_Id
);
3262 -- The object is not effectively volatile
3265 -- A non-effectively volatile object cannot have effectively
3266 -- volatile components (SPARK RM 7.1.3(7)).
3268 if not Is_Effectively_Volatile
(Obj_Id
)
3269 and then Has_Volatile_Component
(Obj_Typ
)
3272 ("non-volatile object & cannot have volatile components",
3278 if Is_Ghost_Entity
(Obj_Id
) then
3280 -- A Ghost object cannot be effectively volatile (SPARK RM 6.9(8))
3282 if Is_Effectively_Volatile
(Obj_Id
) then
3283 Error_Msg_N
("ghost variable & cannot be volatile", Obj_Id
);
3285 -- A Ghost object cannot be imported or exported (SPARK RM 6.9(8))
3287 elsif Is_Imported
(Obj_Id
) then
3288 Error_Msg_N
("ghost object & cannot be imported", Obj_Id
);
3290 elsif Is_Exported
(Obj_Id
) then
3291 Error_Msg_N
("ghost object & cannot be exported", Obj_Id
);
3295 -- Analyze all external properties
3297 Prag
:= Get_Pragma
(Obj_Id
, Pragma_Async_Readers
);
3299 if Present
(Prag
) then
3300 Analyze_External_Property_In_Decl_Part
(Prag
, AR_Val
);
3304 Prag
:= Get_Pragma
(Obj_Id
, Pragma_Async_Writers
);
3306 if Present
(Prag
) then
3307 Analyze_External_Property_In_Decl_Part
(Prag
, AW_Val
);
3311 Prag
:= Get_Pragma
(Obj_Id
, Pragma_Effective_Reads
);
3313 if Present
(Prag
) then
3314 Analyze_External_Property_In_Decl_Part
(Prag
, ER_Val
);
3318 Prag
:= Get_Pragma
(Obj_Id
, Pragma_Effective_Writes
);
3320 if Present
(Prag
) then
3321 Analyze_External_Property_In_Decl_Part
(Prag
, EW_Val
);
3325 -- Verify the mutual interaction of the various external properties
3328 Check_External_Properties
(Obj_Id
, AR_Val
, AW_Val
, ER_Val
, EW_Val
);
3332 -- Check whether the lack of indicator Part_Of agrees with the placement
3333 -- of the object with respect to the state space.
3335 Prag
:= Get_Pragma
(Obj_Id
, Pragma_Part_Of
);
3338 Check_Missing_Part_Of
(Obj_Id
);
3341 -- A ghost object cannot be imported or exported (SPARK RM 6.9(8))
3343 if Is_Ghost_Entity
(Obj_Id
) then
3344 if Is_Exported
(Obj_Id
) then
3345 Error_Msg_N
("ghost object & cannot be exported", Obj_Id
);
3347 elsif Is_Imported
(Obj_Id
) then
3348 Error_Msg_N
("ghost object & cannot be imported", Obj_Id
);
3351 end Analyze_Object_Contract
;
3353 --------------------------------
3354 -- Analyze_Object_Declaration --
3355 --------------------------------
3357 procedure Analyze_Object_Declaration
(N
: Node_Id
) is
3358 Loc
: constant Source_Ptr
:= Sloc
(N
);
3359 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
3363 E
: Node_Id
:= Expression
(N
);
3364 -- E is set to Expression (N) throughout this routine. When
3365 -- Expression (N) is modified, E is changed accordingly.
3367 Prev_Entity
: Entity_Id
:= Empty
;
3369 function Count_Tasks
(T
: Entity_Id
) return Uint
;
3370 -- This function is called when a non-generic library level object of a
3371 -- task type is declared. Its function is to count the static number of
3372 -- tasks declared within the type (it is only called if Has_Tasks is set
3373 -- for T). As a side effect, if an array of tasks with non-static bounds
3374 -- or a variant record type is encountered, Check_Restrictions is called
3375 -- indicating the count is unknown.
3377 function Delayed_Aspect_Present
return Boolean;
3378 -- If the declaration has an expression that is an aggregate, and it
3379 -- has aspects that require delayed analysis, the resolution of the
3380 -- aggregate must be deferred to the freeze point of the objet. This
3381 -- special processing was created for address clauses, but it must
3382 -- also apply to Alignment. This must be done before the aspect
3383 -- specifications are analyzed because we must handle the aggregate
3384 -- before the analysis of the object declaration is complete.
3386 -- Any other relevant delayed aspects on object declarations ???
3392 function Count_Tasks
(T
: Entity_Id
) return Uint
is
3398 if Is_Task_Type
(T
) then
3401 elsif Is_Record_Type
(T
) then
3402 if Has_Discriminants
(T
) then
3403 Check_Restriction
(Max_Tasks
, N
);
3408 C
:= First_Component
(T
);
3409 while Present
(C
) loop
3410 V
:= V
+ Count_Tasks
(Etype
(C
));
3417 elsif Is_Array_Type
(T
) then
3418 X
:= First_Index
(T
);
3419 V
:= Count_Tasks
(Component_Type
(T
));
3420 while Present
(X
) loop
3423 if not Is_OK_Static_Subtype
(C
) then
3424 Check_Restriction
(Max_Tasks
, N
);
3427 V
:= V
* (UI_Max
(Uint_0
,
3428 Expr_Value
(Type_High_Bound
(C
)) -
3429 Expr_Value
(Type_Low_Bound
(C
)) + Uint_1
));
3442 ----------------------------
3443 -- Delayed_Aspect_Present --
3444 ----------------------------
3446 function Delayed_Aspect_Present
return Boolean is
3451 if Present
(Aspect_Specifications
(N
)) then
3452 A
:= First
(Aspect_Specifications
(N
));
3453 A_Id
:= Get_Aspect_Id
(Chars
(Identifier
(A
)));
3454 while Present
(A
) loop
3455 if A_Id
= Aspect_Alignment
or else A_Id
= Aspect_Address
then
3464 end Delayed_Aspect_Present
;
3466 -- Start of processing for Analyze_Object_Declaration
3469 -- There are three kinds of implicit types generated by an
3470 -- object declaration:
3472 -- 1. Those generated by the original Object Definition
3474 -- 2. Those generated by the Expression
3476 -- 3. Those used to constrain the Object Definition with the
3477 -- expression constraints when the definition is unconstrained.
3479 -- They must be generated in this order to avoid order of elaboration
3480 -- issues. Thus the first step (after entering the name) is to analyze
3481 -- the object definition.
3483 if Constant_Present
(N
) then
3484 Prev_Entity
:= Current_Entity_In_Scope
(Id
);
3486 if Present
(Prev_Entity
)
3488 -- If the homograph is an implicit subprogram, it is overridden
3489 -- by the current declaration.
3491 ((Is_Overloadable
(Prev_Entity
)
3492 and then Is_Inherited_Operation
(Prev_Entity
))
3494 -- The current object is a discriminal generated for an entry
3495 -- family index. Even though the index is a constant, in this
3496 -- particular context there is no true constant redeclaration.
3497 -- Enter_Name will handle the visibility.
3500 (Is_Discriminal
(Id
)
3501 and then Ekind
(Discriminal_Link
(Id
)) =
3502 E_Entry_Index_Parameter
)
3504 -- The current object is the renaming for a generic declared
3505 -- within the instance.
3508 (Ekind
(Prev_Entity
) = E_Package
3509 and then Nkind
(Parent
(Prev_Entity
)) =
3510 N_Package_Renaming_Declaration
3511 and then not Comes_From_Source
(Prev_Entity
)
3513 Is_Generic_Instance
(Renamed_Entity
(Prev_Entity
))))
3515 Prev_Entity
:= Empty
;
3519 -- The object declaration may be subject to pragma Ghost with policy
3520 -- Ignore. Set the mode now to ensure that any nodes generated during
3521 -- analysis and expansion are properly flagged as ignored Ghost.
3523 Set_Ghost_Mode
(N
, Prev_Entity
);
3525 if Present
(Prev_Entity
) then
3526 Constant_Redeclaration
(Id
, N
, T
);
3528 Generate_Reference
(Prev_Entity
, Id
, 'c');
3529 Set_Completion_Referenced
(Id
);
3531 if Error_Posted
(N
) then
3533 -- Type mismatch or illegal redeclaration, Do not analyze
3534 -- expression to avoid cascaded errors.
3536 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
3538 Set_Ekind
(Id
, E_Variable
);
3542 -- In the normal case, enter identifier at the start to catch premature
3543 -- usage in the initialization expression.
3546 Generate_Definition
(Id
);
3549 Mark_Coextensions
(N
, Object_Definition
(N
));
3551 T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
3553 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
3555 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
3556 and then Protected_Present
3557 (Access_To_Subprogram_Definition
(Object_Definition
(N
)))
3559 T
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
3562 if Error_Posted
(Id
) then
3564 Set_Ekind
(Id
, E_Variable
);
3569 -- Ada 2005 (AI-231): Propagate the null-excluding attribute and carry
3570 -- out some static checks
3572 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(T
) then
3574 -- In case of aggregates we must also take care of the correct
3575 -- initialization of nested aggregates bug this is done at the
3576 -- point of the analysis of the aggregate (see sem_aggr.adb).
3578 if Present
(Expression
(N
))
3579 and then Nkind
(Expression
(N
)) = N_Aggregate
3585 Save_Typ
: constant Entity_Id
:= Etype
(Id
);
3587 Set_Etype
(Id
, T
); -- Temp. decoration for static checks
3588 Null_Exclusion_Static_Checks
(N
);
3589 Set_Etype
(Id
, Save_Typ
);
3594 -- Object is marked pure if it is in a pure scope
3596 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
3598 -- If deferred constant, make sure context is appropriate. We detect
3599 -- a deferred constant as a constant declaration with no expression.
3600 -- A deferred constant can appear in a package body if its completion
3601 -- is by means of an interface pragma.
3603 if Constant_Present
(N
) and then No
(E
) then
3605 -- A deferred constant may appear in the declarative part of the
3606 -- following constructs:
3610 -- extended return statements
3613 -- subprogram bodies
3616 -- When declared inside a package spec, a deferred constant must be
3617 -- completed by a full constant declaration or pragma Import. In all
3618 -- other cases, the only proper completion is pragma Import. Extended
3619 -- return statements are flagged as invalid contexts because they do
3620 -- not have a declarative part and so cannot accommodate the pragma.
3622 if Ekind
(Current_Scope
) = E_Return_Statement
then
3624 ("invalid context for deferred constant declaration (RM 7.4)",
3627 ("\declaration requires an initialization expression",
3629 Set_Constant_Present
(N
, False);
3631 -- In Ada 83, deferred constant must be of private type
3633 elsif not Is_Private_Type
(T
) then
3634 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3636 ("(Ada 83) deferred constant must be private type", N
);
3640 -- If not a deferred constant, then the object declaration freezes
3641 -- its type, unless the object is of an anonymous type and has delayed
3642 -- aspects. In that case the type is frozen when the object itself is.
3645 Check_Fully_Declared
(T
, N
);
3647 if Has_Delayed_Aspects
(Id
)
3648 and then Is_Array_Type
(T
)
3649 and then Is_Itype
(T
)
3651 Set_Has_Delayed_Freeze
(T
);
3653 Freeze_Before
(N
, T
);
3657 -- If the object was created by a constrained array definition, then
3658 -- set the link in both the anonymous base type and anonymous subtype
3659 -- that are built to represent the array type to point to the object.
3661 if Nkind
(Object_Definition
(Declaration_Node
(Id
))) =
3662 N_Constrained_Array_Definition
3664 Set_Related_Array_Object
(T
, Id
);
3665 Set_Related_Array_Object
(Base_Type
(T
), Id
);
3668 -- Special checks for protected objects not at library level
3670 if Is_Protected_Type
(T
)
3671 and then not Is_Library_Level_Entity
(Id
)
3673 Check_Restriction
(No_Local_Protected_Objects
, Id
);
3675 -- Protected objects with interrupt handlers must be at library level
3677 -- Ada 2005: This test is not needed (and the corresponding clause
3678 -- in the RM is removed) because accessibility checks are sufficient
3679 -- to make handlers not at the library level illegal.
3681 -- AI05-0303: The AI is in fact a binding interpretation, and thus
3682 -- applies to the '95 version of the language as well.
3684 if Has_Interrupt_Handler
(T
) and then Ada_Version
< Ada_95
then
3686 ("interrupt object can only be declared at library level", Id
);
3690 -- The actual subtype of the object is the nominal subtype, unless
3691 -- the nominal one is unconstrained and obtained from the expression.
3695 -- These checks should be performed before the initialization expression
3696 -- is considered, so that the Object_Definition node is still the same
3697 -- as in source code.
3699 -- In SPARK, the nominal subtype is always given by a subtype mark
3700 -- and must not be unconstrained. (The only exception to this is the
3701 -- acceptance of declarations of constants of type String.)
3703 if not Nkind_In
(Object_Definition
(N
), N_Expanded_Name
, N_Identifier
)
3705 Check_SPARK_05_Restriction
3706 ("subtype mark required", Object_Definition
(N
));
3708 elsif Is_Array_Type
(T
)
3709 and then not Is_Constrained
(T
)
3710 and then T
/= Standard_String
3712 Check_SPARK_05_Restriction
3713 ("subtype mark of constrained type expected",
3714 Object_Definition
(N
));
3717 -- There are no aliased objects in SPARK
3719 if Aliased_Present
(N
) then
3720 Check_SPARK_05_Restriction
("aliased object is not allowed", N
);
3723 -- Process initialization expression if present and not in error
3725 if Present
(E
) and then E
/= Error
then
3727 -- Generate an error in case of CPP class-wide object initialization.
3728 -- Required because otherwise the expansion of the class-wide
3729 -- assignment would try to use 'size to initialize the object
3730 -- (primitive that is not available in CPP tagged types).
3732 if Is_Class_Wide_Type
(Act_T
)
3734 (Is_CPP_Class
(Root_Type
(Etype
(Act_T
)))
3736 (Present
(Full_View
(Root_Type
(Etype
(Act_T
))))
3738 Is_CPP_Class
(Full_View
(Root_Type
(Etype
(Act_T
))))))
3741 ("predefined assignment not available for 'C'P'P tagged types",
3745 Mark_Coextensions
(N
, E
);
3748 -- In case of errors detected in the analysis of the expression,
3749 -- decorate it with the expected type to avoid cascaded errors
3751 if No
(Etype
(E
)) then
3755 -- If an initialization expression is present, then we set the
3756 -- Is_True_Constant flag. It will be reset if this is a variable
3757 -- and it is indeed modified.
3759 Set_Is_True_Constant
(Id
, True);
3761 -- If we are analyzing a constant declaration, set its completion
3762 -- flag after analyzing and resolving the expression.
3764 if Constant_Present
(N
) then
3765 Set_Has_Completion
(Id
);
3768 -- Set type and resolve (type may be overridden later on). Note:
3769 -- Ekind (Id) must still be E_Void at this point so that incorrect
3770 -- early usage within E is properly diagnosed.
3774 -- If the expression is an aggregate we must look ahead to detect
3775 -- the possible presence of an address clause, and defer resolution
3776 -- and expansion of the aggregate to the freeze point of the entity.
3778 if Comes_From_Source
(N
)
3779 and then Expander_Active
3780 and then Nkind
(E
) = N_Aggregate
3781 and then (Present
(Following_Address_Clause
(N
))
3782 or else Delayed_Aspect_Present
)
3790 -- No further action needed if E is a call to an inlined function
3791 -- which returns an unconstrained type and it has been expanded into
3792 -- a procedure call. In that case N has been replaced by an object
3793 -- declaration without initializing expression and it has been
3794 -- analyzed (see Expand_Inlined_Call).
3796 if Back_End_Inlining
3797 and then Expander_Active
3798 and then Nkind
(E
) = N_Function_Call
3799 and then Nkind
(Name
(E
)) in N_Has_Entity
3800 and then Is_Inlined
(Entity
(Name
(E
)))
3801 and then not Is_Constrained
(Etype
(E
))
3802 and then Analyzed
(N
)
3803 and then No
(Expression
(N
))
3808 -- If E is null and has been replaced by an N_Raise_Constraint_Error
3809 -- node (which was marked already-analyzed), we need to set the type
3810 -- to something other than Any_Access in order to keep gigi happy.
3812 if Etype
(E
) = Any_Access
then
3816 -- If the object is an access to variable, the initialization
3817 -- expression cannot be an access to constant.
3819 if Is_Access_Type
(T
)
3820 and then not Is_Access_Constant
(T
)
3821 and then Is_Access_Type
(Etype
(E
))
3822 and then Is_Access_Constant
(Etype
(E
))
3825 ("access to variable cannot be initialized with an "
3826 & "access-to-constant expression", E
);
3829 if not Assignment_OK
(N
) then
3830 Check_Initialization
(T
, E
);
3833 Check_Unset_Reference
(E
);
3835 -- If this is a variable, then set current value. If this is a
3836 -- declared constant of a scalar type with a static expression,
3837 -- indicate that it is always valid.
3839 if not Constant_Present
(N
) then
3840 if Compile_Time_Known_Value
(E
) then
3841 Set_Current_Value
(Id
, E
);
3844 elsif Is_Scalar_Type
(T
) and then Is_OK_Static_Expression
(E
) then
3845 Set_Is_Known_Valid
(Id
);
3848 -- Deal with setting of null flags
3850 if Is_Access_Type
(T
) then
3851 if Known_Non_Null
(E
) then
3852 Set_Is_Known_Non_Null
(Id
, True);
3853 elsif Known_Null
(E
) and then not Can_Never_Be_Null
(Id
) then
3854 Set_Is_Known_Null
(Id
, True);
3858 -- Check incorrect use of dynamically tagged expressions
3860 if Is_Tagged_Type
(T
) then
3861 Check_Dynamically_Tagged_Expression
3867 Apply_Scalar_Range_Check
(E
, T
);
3868 Apply_Static_Length_Check
(E
, T
);
3870 if Nkind
(Original_Node
(N
)) = N_Object_Declaration
3871 and then Comes_From_Source
(Original_Node
(N
))
3873 -- Only call test if needed
3875 and then Restriction_Check_Required
(SPARK_05
)
3876 and then not Is_SPARK_05_Initialization_Expr
(Original_Node
(E
))
3878 Check_SPARK_05_Restriction
3879 ("initialization expression is not appropriate", E
);
3882 -- A formal parameter of a specific tagged type whose related
3883 -- subprogram is subject to pragma Extensions_Visible with value
3884 -- "False" cannot be implicitly converted to a class-wide type by
3885 -- means of an initialization expression (SPARK RM 6.1.7(3)).
3887 if Is_Class_Wide_Type
(T
) and then Is_EVF_Expression
(E
) then
3889 ("formal parameter with Extensions_Visible False cannot be "
3890 & "implicitly converted to class-wide type", E
);
3894 -- If the No_Streams restriction is set, check that the type of the
3895 -- object is not, and does not contain, any subtype derived from
3896 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
3897 -- Has_Stream just for efficiency reasons. There is no point in
3898 -- spending time on a Has_Stream check if the restriction is not set.
3900 if Restriction_Check_Required
(No_Streams
) then
3901 if Has_Stream
(T
) then
3902 Check_Restriction
(No_Streams
, N
);
3906 -- Deal with predicate check before we start to do major rewriting. It
3907 -- is OK to initialize and then check the initialized value, since the
3908 -- object goes out of scope if we get a predicate failure. Note that we
3909 -- do this in the analyzer and not the expander because the analyzer
3910 -- does some substantial rewriting in some cases.
3912 -- We need a predicate check if the type has predicates, and if either
3913 -- there is an initializing expression, or for default initialization
3914 -- when we have at least one case of an explicit default initial value
3915 -- and then this is not an internal declaration whose initialization
3916 -- comes later (as for an aggregate expansion).
3918 if not Suppress_Assignment_Checks
(N
)
3919 and then Present
(Predicate_Function
(T
))
3920 and then not No_Initialization
(N
)
3924 Is_Partially_Initialized_Type
(T
, Include_Implicit
=> False))
3926 -- If the type has a static predicate and the expression is known at
3927 -- compile time, see if the expression satisfies the predicate.
3930 Check_Expression_Against_Static_Predicate
(E
, T
);
3934 Make_Predicate_Check
(T
, New_Occurrence_Of
(Id
, Loc
)));
3937 -- Case of unconstrained type
3939 if Is_Indefinite_Subtype
(T
) then
3941 -- In SPARK, a declaration of unconstrained type is allowed
3942 -- only for constants of type string.
3944 if Is_String_Type
(T
) and then not Constant_Present
(N
) then
3945 Check_SPARK_05_Restriction
3946 ("declaration of object of unconstrained type not allowed", N
);
3949 -- Nothing to do in deferred constant case
3951 if Constant_Present
(N
) and then No
(E
) then
3954 -- Case of no initialization present
3957 if No_Initialization
(N
) then
3960 elsif Is_Class_Wide_Type
(T
) then
3962 ("initialization required in class-wide declaration ", N
);
3966 ("unconstrained subtype not allowed (need initialization)",
3967 Object_Definition
(N
));
3969 if Is_Record_Type
(T
) and then Has_Discriminants
(T
) then
3971 ("\provide initial value or explicit discriminant values",
3972 Object_Definition
(N
));
3975 ("\or give default discriminant values for type&",
3976 Object_Definition
(N
), T
);
3978 elsif Is_Array_Type
(T
) then
3980 ("\provide initial value or explicit array bounds",
3981 Object_Definition
(N
));
3985 -- Case of initialization present but in error. Set initial
3986 -- expression as absent (but do not make above complaints)
3988 elsif E
= Error
then
3989 Set_Expression
(N
, Empty
);
3992 -- Case of initialization present
3995 -- Check restrictions in Ada 83
3997 if not Constant_Present
(N
) then
3999 -- Unconstrained variables not allowed in Ada 83 mode
4001 if Ada_Version
= Ada_83
4002 and then Comes_From_Source
(Object_Definition
(N
))
4005 ("(Ada 83) unconstrained variable not allowed",
4006 Object_Definition
(N
));
4010 -- Now we constrain the variable from the initializing expression
4012 -- If the expression is an aggregate, it has been expanded into
4013 -- individual assignments. Retrieve the actual type from the
4014 -- expanded construct.
4016 if Is_Array_Type
(T
)
4017 and then No_Initialization
(N
)
4018 and then Nkind
(Original_Node
(E
)) = N_Aggregate
4022 -- In case of class-wide interface object declarations we delay
4023 -- the generation of the equivalent record type declarations until
4024 -- its expansion because there are cases in they are not required.
4026 elsif Is_Interface
(T
) then
4029 -- In GNATprove mode, Expand_Subtype_From_Expr does nothing. Thus,
4030 -- we should prevent the generation of another Itype with the
4031 -- same name as the one already generated, or we end up with
4032 -- two identical types in GNATprove.
4034 elsif GNATprove_Mode
then
4037 -- If the type is an unchecked union, no subtype can be built from
4038 -- the expression. Rewrite declaration as a renaming, which the
4039 -- back-end can handle properly. This is a rather unusual case,
4040 -- because most unchecked_union declarations have default values
4041 -- for discriminants and are thus not indefinite.
4043 elsif Is_Unchecked_Union
(T
) then
4044 if Constant_Present
(N
) or else Nkind
(E
) = N_Function_Call
then
4045 Set_Ekind
(Id
, E_Constant
);
4047 Set_Ekind
(Id
, E_Variable
);
4050 -- An object declared within a Ghost region is automatically
4051 -- Ghost (SPARK RM 6.9(2)).
4053 if Comes_From_Source
(Id
) and then Ghost_Mode
> None
then
4054 Set_Is_Ghost_Entity
(Id
);
4056 -- The Ghost policy in effect at the point of declaration
4057 -- and at the point of completion must match
4058 -- (SPARK RM 6.9(15)).
4060 if Present
(Prev_Entity
)
4061 and then Is_Ghost_Entity
(Prev_Entity
)
4063 Check_Ghost_Completion
(Prev_Entity
, Id
);
4068 Make_Object_Renaming_Declaration
(Loc
,
4069 Defining_Identifier
=> Id
,
4070 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
4073 Set_Renamed_Object
(Id
, E
);
4074 Freeze_Before
(N
, T
);
4079 Expand_Subtype_From_Expr
(N
, T
, Object_Definition
(N
), E
);
4080 Act_T
:= Find_Type_Of_Object
(Object_Definition
(N
), N
);
4083 Set_Is_Constr_Subt_For_U_Nominal
(Act_T
);
4085 if Aliased_Present
(N
) then
4086 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
4089 Freeze_Before
(N
, Act_T
);
4090 Freeze_Before
(N
, T
);
4093 elsif Is_Array_Type
(T
)
4094 and then No_Initialization
(N
)
4095 and then Nkind
(Original_Node
(E
)) = N_Aggregate
4097 if not Is_Entity_Name
(Object_Definition
(N
)) then
4099 Check_Compile_Time_Size
(Act_T
);
4101 if Aliased_Present
(N
) then
4102 Set_Is_Constr_Subt_For_UN_Aliased
(Act_T
);
4106 -- When the given object definition and the aggregate are specified
4107 -- independently, and their lengths might differ do a length check.
4108 -- This cannot happen if the aggregate is of the form (others =>...)
4110 if not Is_Constrained
(T
) then
4113 elsif Nkind
(E
) = N_Raise_Constraint_Error
then
4115 -- Aggregate is statically illegal. Place back in declaration
4117 Set_Expression
(N
, E
);
4118 Set_No_Initialization
(N
, False);
4120 elsif T
= Etype
(E
) then
4123 elsif Nkind
(E
) = N_Aggregate
4124 and then Present
(Component_Associations
(E
))
4125 and then Present
(Choices
(First
(Component_Associations
(E
))))
4126 and then Nkind
(First
4127 (Choices
(First
(Component_Associations
(E
))))) = N_Others_Choice
4132 Apply_Length_Check
(E
, T
);
4135 -- If the type is limited unconstrained with defaulted discriminants and
4136 -- there is no expression, then the object is constrained by the
4137 -- defaults, so it is worthwhile building the corresponding subtype.
4139 elsif (Is_Limited_Record
(T
) or else Is_Concurrent_Type
(T
))
4140 and then not Is_Constrained
(T
)
4141 and then Has_Discriminants
(T
)
4144 Act_T
:= Build_Default_Subtype
(T
, N
);
4146 -- Ada 2005: A limited object may be initialized by means of an
4147 -- aggregate. If the type has default discriminants it has an
4148 -- unconstrained nominal type, Its actual subtype will be obtained
4149 -- from the aggregate, and not from the default discriminants.
4154 Rewrite
(Object_Definition
(N
), New_Occurrence_Of
(Act_T
, Loc
));
4156 elsif Nkind
(E
) = N_Function_Call
4157 and then Constant_Present
(N
)
4158 and then Has_Unconstrained_Elements
(Etype
(E
))
4160 -- The back-end has problems with constants of a discriminated type
4161 -- with defaults, if the initial value is a function call. We
4162 -- generate an intermediate temporary that will receive a reference
4163 -- to the result of the call. The initialization expression then
4164 -- becomes a dereference of that temporary.
4166 Remove_Side_Effects
(E
);
4168 -- If this is a constant declaration of an unconstrained type and
4169 -- the initialization is an aggregate, we can use the subtype of the
4170 -- aggregate for the declared entity because it is immutable.
4172 elsif not Is_Constrained
(T
)
4173 and then Has_Discriminants
(T
)
4174 and then Constant_Present
(N
)
4175 and then not Has_Unchecked_Union
(T
)
4176 and then Nkind
(E
) = N_Aggregate
4181 -- Check No_Wide_Characters restriction
4183 Check_Wide_Character_Restriction
(T
, Object_Definition
(N
));
4185 -- Indicate this is not set in source. Certainly true for constants, and
4186 -- true for variables so far (will be reset for a variable if and when
4187 -- we encounter a modification in the source).
4189 Set_Never_Set_In_Source
(Id
);
4191 -- Now establish the proper kind and type of the object
4193 if Constant_Present
(N
) then
4194 Set_Ekind
(Id
, E_Constant
);
4195 Set_Is_True_Constant
(Id
);
4198 Set_Ekind
(Id
, E_Variable
);
4200 -- A variable is set as shared passive if it appears in a shared
4201 -- passive package, and is at the outer level. This is not done for
4202 -- entities generated during expansion, because those are always
4203 -- manipulated locally.
4205 if Is_Shared_Passive
(Current_Scope
)
4206 and then Is_Library_Level_Entity
(Id
)
4207 and then Comes_From_Source
(Id
)
4209 Set_Is_Shared_Passive
(Id
);
4210 Check_Shared_Var
(Id
, T
, N
);
4213 -- Set Has_Initial_Value if initializing expression present. Note
4214 -- that if there is no initializing expression, we leave the state
4215 -- of this flag unchanged (usually it will be False, but notably in
4216 -- the case of exception choice variables, it will already be true).
4219 Set_Has_Initial_Value
(Id
);
4223 -- Initialize alignment and size and capture alignment setting
4225 Init_Alignment
(Id
);
4227 Set_Optimize_Alignment_Flags
(Id
);
4229 -- An object declared within a Ghost region is automatically Ghost
4230 -- (SPARK RM 6.9(2)).
4232 if Comes_From_Source
(Id
)
4233 and then (Ghost_Mode
> None
4234 or else (Present
(Prev_Entity
)
4235 and then Is_Ghost_Entity
(Prev_Entity
)))
4237 Set_Is_Ghost_Entity
(Id
);
4239 -- The Ghost policy in effect at the point of declaration and at the
4240 -- point of completion must match (SPARK RM 6.9(16)).
4242 if Present
(Prev_Entity
) and then Is_Ghost_Entity
(Prev_Entity
) then
4243 Check_Ghost_Completion
(Prev_Entity
, Id
);
4247 -- Deal with aliased case
4249 if Aliased_Present
(N
) then
4250 Set_Is_Aliased
(Id
);
4252 -- If the object is aliased and the type is unconstrained with
4253 -- defaulted discriminants and there is no expression, then the
4254 -- object is constrained by the defaults, so it is worthwhile
4255 -- building the corresponding subtype.
4257 -- Ada 2005 (AI-363): If the aliased object is discriminated and
4258 -- unconstrained, then only establish an actual subtype if the
4259 -- nominal subtype is indefinite. In definite cases the object is
4260 -- unconstrained in Ada 2005.
4263 and then Is_Record_Type
(T
)
4264 and then not Is_Constrained
(T
)
4265 and then Has_Discriminants
(T
)
4266 and then (Ada_Version
< Ada_2005
or else Is_Indefinite_Subtype
(T
))
4268 Set_Actual_Subtype
(Id
, Build_Default_Subtype
(T
, N
));
4272 -- Now we can set the type of the object
4274 Set_Etype
(Id
, Act_T
);
4276 -- Non-constant object is marked to be treated as volatile if type is
4277 -- volatile and we clear the Current_Value setting that may have been
4278 -- set above. Doing so for constants isn't required and might interfere
4279 -- with possible uses of the object as a static expression in contexts
4280 -- incompatible with volatility (e.g. as a case-statement alternative).
4282 if Ekind
(Id
) /= E_Constant
and then Treat_As_Volatile
(Etype
(Id
)) then
4283 Set_Treat_As_Volatile
(Id
);
4284 Set_Current_Value
(Id
, Empty
);
4287 -- Deal with controlled types
4289 if Has_Controlled_Component
(Etype
(Id
))
4290 or else Is_Controlled
(Etype
(Id
))
4292 if not Is_Library_Level_Entity
(Id
) then
4293 Check_Restriction
(No_Nested_Finalization
, N
);
4295 Validate_Controlled_Object
(Id
);
4299 if Has_Task
(Etype
(Id
)) then
4300 Check_Restriction
(No_Tasking
, N
);
4302 -- Deal with counting max tasks
4304 -- Nothing to do if inside a generic
4306 if Inside_A_Generic
then
4309 -- If library level entity, then count tasks
4311 elsif Is_Library_Level_Entity
(Id
) then
4312 Check_Restriction
(Max_Tasks
, N
, Count_Tasks
(Etype
(Id
)));
4314 -- If not library level entity, then indicate we don't know max
4315 -- tasks and also check task hierarchy restriction and blocking
4316 -- operation (since starting a task is definitely blocking).
4319 Check_Restriction
(Max_Tasks
, N
);
4320 Check_Restriction
(No_Task_Hierarchy
, N
);
4321 Check_Potentially_Blocking_Operation
(N
);
4324 -- A rather specialized test. If we see two tasks being declared
4325 -- of the same type in the same object declaration, and the task
4326 -- has an entry with an address clause, we know that program error
4327 -- will be raised at run time since we can't have two tasks with
4328 -- entries at the same address.
4330 if Is_Task_Type
(Etype
(Id
)) and then More_Ids
(N
) then
4335 E
:= First_Entity
(Etype
(Id
));
4336 while Present
(E
) loop
4337 if Ekind
(E
) = E_Entry
4338 and then Present
(Get_Attribute_Definition_Clause
4339 (E
, Attribute_Address
))
4341 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4343 ("more than one task with same entry address<<", N
);
4344 Error_Msg_N
("\Program_Error [<<", N
);
4346 Make_Raise_Program_Error
(Loc
,
4347 Reason
=> PE_Duplicated_Entry_Address
));
4357 -- Some simple constant-propagation: if the expression is a constant
4358 -- string initialized with a literal, share the literal. This avoids
4362 and then Is_Entity_Name
(E
)
4363 and then Ekind
(Entity
(E
)) = E_Constant
4364 and then Base_Type
(Etype
(E
)) = Standard_String
4367 Val
: constant Node_Id
:= Constant_Value
(Entity
(E
));
4369 if Present
(Val
) and then Nkind
(Val
) = N_String_Literal
then
4370 Rewrite
(E
, New_Copy
(Val
));
4375 -- Another optimization: if the nominal subtype is unconstrained and
4376 -- the expression is a function call that returns an unconstrained
4377 -- type, rewrite the declaration as a renaming of the result of the
4378 -- call. The exceptions below are cases where the copy is expected,
4379 -- either by the back end (Aliased case) or by the semantics, as for
4380 -- initializing controlled types or copying tags for classwide types.
4383 and then Nkind
(E
) = N_Explicit_Dereference
4384 and then Nkind
(Original_Node
(E
)) = N_Function_Call
4385 and then not Is_Library_Level_Entity
(Id
)
4386 and then not Is_Constrained
(Underlying_Type
(T
))
4387 and then not Is_Aliased
(Id
)
4388 and then not Is_Class_Wide_Type
(T
)
4389 and then not Is_Controlled
(T
)
4390 and then not Has_Controlled_Component
(Base_Type
(T
))
4391 and then Expander_Active
4394 Make_Object_Renaming_Declaration
(Loc
,
4395 Defining_Identifier
=> Id
,
4396 Access_Definition
=> Empty
,
4397 Subtype_Mark
=> New_Occurrence_Of
4398 (Base_Type
(Etype
(Id
)), Loc
),
4401 Set_Renamed_Object
(Id
, E
);
4403 -- Force generation of debugging information for the constant and for
4404 -- the renamed function call.
4406 Set_Debug_Info_Needed
(Id
);
4407 Set_Debug_Info_Needed
(Entity
(Prefix
(E
)));
4410 if Present
(Prev_Entity
)
4411 and then Is_Frozen
(Prev_Entity
)
4412 and then not Error_Posted
(Id
)
4414 Error_Msg_N
("full constant declaration appears too late", N
);
4417 Check_Eliminated
(Id
);
4419 -- Deal with setting In_Private_Part flag if in private part
4421 if Ekind
(Scope
(Id
)) = E_Package
and then In_Private_Part
(Scope
(Id
))
4423 Set_In_Private_Part
(Id
);
4426 -- Check for violation of No_Local_Timing_Events
4428 if Restriction_Check_Required
(No_Local_Timing_Events
)
4429 and then not Is_Library_Level_Entity
(Id
)
4430 and then Is_RTE
(Etype
(Id
), RE_Timing_Event
)
4432 Check_Restriction
(No_Local_Timing_Events
, N
);
4436 -- Initialize the refined state of a variable here because this is a
4437 -- common destination for legal and illegal object declarations.
4439 if Ekind
(Id
) = E_Variable
then
4440 Set_Encapsulating_State
(Id
, Empty
);
4443 if Has_Aspects
(N
) then
4444 Analyze_Aspect_Specifications
(N
, Id
);
4447 Analyze_Dimension
(N
);
4449 -- Verify whether the object declaration introduces an illegal hidden
4450 -- state within a package subject to a null abstract state.
4452 if Ekind
(Id
) = E_Variable
then
4453 Check_No_Hidden_State
(Id
);
4455 end Analyze_Object_Declaration
;
4457 ---------------------------
4458 -- Analyze_Others_Choice --
4459 ---------------------------
4461 -- Nothing to do for the others choice node itself, the semantic analysis
4462 -- of the others choice will occur as part of the processing of the parent
4464 procedure Analyze_Others_Choice
(N
: Node_Id
) is
4465 pragma Warnings
(Off
, N
);
4468 end Analyze_Others_Choice
;
4470 -------------------------------------------
4471 -- Analyze_Private_Extension_Declaration --
4472 -------------------------------------------
4474 procedure Analyze_Private_Extension_Declaration
(N
: Node_Id
) is
4475 T
: constant Entity_Id
:= Defining_Identifier
(N
);
4476 Indic
: constant Node_Id
:= Subtype_Indication
(N
);
4477 Parent_Type
: Entity_Id
;
4478 Parent_Base
: Entity_Id
;
4481 -- The private extension declaration may be subject to pragma Ghost with
4482 -- policy Ignore. Set the mode now to ensure that any nodes generated
4483 -- during analysis and expansion are properly flagged as ignored Ghost.
4487 -- Ada 2005 (AI-251): Decorate all names in list of ancestor interfaces
4489 if Is_Non_Empty_List
(Interface_List
(N
)) then
4495 Intf
:= First
(Interface_List
(N
));
4496 while Present
(Intf
) loop
4497 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
4499 Diagnose_Interface
(Intf
, T
);
4505 Generate_Definition
(T
);
4507 -- For other than Ada 2012, just enter the name in the current scope
4509 if Ada_Version
< Ada_2012
then
4512 -- Ada 2012 (AI05-0162): Enter the name in the current scope handling
4513 -- case of private type that completes an incomplete type.
4520 Prev
:= Find_Type_Name
(N
);
4522 pragma Assert
(Prev
= T
4523 or else (Ekind
(Prev
) = E_Incomplete_Type
4524 and then Present
(Full_View
(Prev
))
4525 and then Full_View
(Prev
) = T
));
4529 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
4530 Parent_Base
:= Base_Type
(Parent_Type
);
4532 if Parent_Type
= Any_Type
or else Etype
(Parent_Type
) = Any_Type
then
4533 Set_Ekind
(T
, Ekind
(Parent_Type
));
4534 Set_Etype
(T
, Any_Type
);
4537 elsif not Is_Tagged_Type
(Parent_Type
) then
4539 ("parent of type extension must be a tagged type ", Indic
);
4542 elsif Ekind_In
(Parent_Type
, E_Void
, E_Incomplete_Type
) then
4543 Error_Msg_N
("premature derivation of incomplete type", Indic
);
4546 elsif Is_Concurrent_Type
(Parent_Type
) then
4548 ("parent type of a private extension cannot be "
4549 & "a synchronized tagged type (RM 3.9.1 (3/1))", N
);
4551 Set_Etype
(T
, Any_Type
);
4552 Set_Ekind
(T
, E_Limited_Private_Type
);
4553 Set_Private_Dependents
(T
, New_Elmt_List
);
4554 Set_Error_Posted
(T
);
4558 -- Perhaps the parent type should be changed to the class-wide type's
4559 -- specific type in this case to prevent cascading errors ???
4561 if Is_Class_Wide_Type
(Parent_Type
) then
4563 ("parent of type extension must not be a class-wide type", Indic
);
4567 if (not Is_Package_Or_Generic_Package
(Current_Scope
)
4568 and then Nkind
(Parent
(N
)) /= N_Generic_Subprogram_Declaration
)
4569 or else In_Private_Part
(Current_Scope
)
4572 Error_Msg_N
("invalid context for private extension", N
);
4575 -- Set common attributes
4577 Set_Is_Pure
(T
, Is_Pure
(Current_Scope
));
4578 Set_Scope
(T
, Current_Scope
);
4579 Set_Ekind
(T
, E_Record_Type_With_Private
);
4580 Init_Size_Align
(T
);
4581 Set_Default_SSO
(T
);
4583 Set_Etype
(T
, Parent_Base
);
4584 Set_Has_Task
(T
, Has_Task
(Parent_Base
));
4585 Set_Has_Protected
(T
, Has_Task
(Parent_Base
));
4587 Set_Convention
(T
, Convention
(Parent_Type
));
4588 Set_First_Rep_Item
(T
, First_Rep_Item
(Parent_Type
));
4589 Set_Is_First_Subtype
(T
);
4590 Make_Class_Wide_Type
(T
);
4592 if Unknown_Discriminants_Present
(N
) then
4593 Set_Discriminant_Constraint
(T
, No_Elist
);
4596 Build_Derived_Record_Type
(N
, Parent_Type
, T
);
4598 -- Propagate inherited invariant information. The new type has
4599 -- invariants, if the parent type has inheritable invariants,
4600 -- and these invariants can in turn be inherited.
4602 if Has_Inheritable_Invariants
(Parent_Type
) then
4603 Set_Has_Inheritable_Invariants
(T
);
4604 Set_Has_Invariants
(T
);
4607 -- Ada 2005 (AI-443): Synchronized private extension or a rewritten
4608 -- synchronized formal derived type.
4610 if Ada_Version
>= Ada_2005
and then Synchronized_Present
(N
) then
4611 Set_Is_Limited_Record
(T
);
4613 -- Formal derived type case
4615 if Is_Generic_Type
(T
) then
4617 -- The parent must be a tagged limited type or a synchronized
4620 if (not Is_Tagged_Type
(Parent_Type
)
4621 or else not Is_Limited_Type
(Parent_Type
))
4623 (not Is_Interface
(Parent_Type
)
4624 or else not Is_Synchronized_Interface
(Parent_Type
))
4626 Error_Msg_NE
("parent type of & must be tagged limited " &
4627 "or synchronized", N
, T
);
4630 -- The progenitors (if any) must be limited or synchronized
4633 if Present
(Interfaces
(T
)) then
4636 Iface_Elmt
: Elmt_Id
;
4639 Iface_Elmt
:= First_Elmt
(Interfaces
(T
));
4640 while Present
(Iface_Elmt
) loop
4641 Iface
:= Node
(Iface_Elmt
);
4643 if not Is_Limited_Interface
(Iface
)
4644 and then not Is_Synchronized_Interface
(Iface
)
4646 Error_Msg_NE
("progenitor & must be limited " &
4647 "or synchronized", N
, Iface
);
4650 Next_Elmt
(Iface_Elmt
);
4655 -- Regular derived extension, the parent must be a limited or
4656 -- synchronized interface.
4659 if not Is_Interface
(Parent_Type
)
4660 or else (not Is_Limited_Interface
(Parent_Type
)
4661 and then not Is_Synchronized_Interface
(Parent_Type
))
4664 ("parent type of & must be limited interface", N
, T
);
4668 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
4669 -- extension with a synchronized parent must be explicitly declared
4670 -- synchronized, because the full view will be a synchronized type.
4671 -- This must be checked before the check for limited types below,
4672 -- to ensure that types declared limited are not allowed to extend
4673 -- synchronized interfaces.
4675 elsif Is_Interface
(Parent_Type
)
4676 and then Is_Synchronized_Interface
(Parent_Type
)
4677 and then not Synchronized_Present
(N
)
4680 ("private extension of& must be explicitly synchronized",
4683 elsif Limited_Present
(N
) then
4684 Set_Is_Limited_Record
(T
);
4686 if not Is_Limited_Type
(Parent_Type
)
4688 (not Is_Interface
(Parent_Type
)
4689 or else not Is_Limited_Interface
(Parent_Type
))
4691 Error_Msg_NE
("parent type& of limited extension must be limited",
4697 if Has_Aspects
(N
) then
4698 Analyze_Aspect_Specifications
(N
, T
);
4700 end Analyze_Private_Extension_Declaration
;
4702 ---------------------------------
4703 -- Analyze_Subtype_Declaration --
4704 ---------------------------------
4706 procedure Analyze_Subtype_Declaration
4708 Skip
: Boolean := False)
4710 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
4712 R_Checks
: Check_Result
;
4715 -- The subtype declaration may be subject to pragma Ghost with policy
4716 -- Ignore. Set the mode now to ensure that any nodes generated during
4717 -- analysis and expansion are properly flagged as ignored Ghost.
4721 Generate_Definition
(Id
);
4722 Set_Is_Pure
(Id
, Is_Pure
(Current_Scope
));
4723 Init_Size_Align
(Id
);
4725 -- The following guard condition on Enter_Name is to handle cases where
4726 -- the defining identifier has already been entered into the scope but
4727 -- the declaration as a whole needs to be analyzed.
4729 -- This case in particular happens for derived enumeration types. The
4730 -- derived enumeration type is processed as an inserted enumeration type
4731 -- declaration followed by a rewritten subtype declaration. The defining
4732 -- identifier, however, is entered into the name scope very early in the
4733 -- processing of the original type declaration and therefore needs to be
4734 -- avoided here, when the created subtype declaration is analyzed. (See
4735 -- Build_Derived_Types)
4737 -- This also happens when the full view of a private type is derived
4738 -- type with constraints. In this case the entity has been introduced
4739 -- in the private declaration.
4741 -- Finally this happens in some complex cases when validity checks are
4742 -- enabled, where the same subtype declaration may be analyzed twice.
4743 -- This can happen if the subtype is created by the pre-analysis of
4744 -- an attribute tht gives the range of a loop statement, and the loop
4745 -- itself appears within an if_statement that will be rewritten during
4749 or else (Present
(Etype
(Id
))
4750 and then (Is_Private_Type
(Etype
(Id
))
4751 or else Is_Task_Type
(Etype
(Id
))
4752 or else Is_Rewrite_Substitution
(N
)))
4756 elsif Current_Entity
(Id
) = Id
then
4763 T
:= Process_Subtype
(Subtype_Indication
(N
), N
, Id
, 'P');
4765 -- Class-wide equivalent types of records with unknown discriminants
4766 -- involve the generation of an itype which serves as the private view
4767 -- of a constrained record subtype. In such cases the base type of the
4768 -- current subtype we are processing is the private itype. Use the full
4769 -- of the private itype when decorating various attributes.
4772 and then Is_Private_Type
(T
)
4773 and then Present
(Full_View
(T
))
4778 -- Inherit common attributes
4780 Set_Is_Volatile
(Id
, Is_Volatile
(T
));
4781 Set_Treat_As_Volatile
(Id
, Treat_As_Volatile
(T
));
4782 Set_Is_Generic_Type
(Id
, Is_Generic_Type
(Base_Type
(T
)));
4783 Set_Convention
(Id
, Convention
(T
));
4785 -- If ancestor has predicates then so does the subtype, and in addition
4786 -- we must delay the freeze to properly arrange predicate inheritance.
4788 -- The Ancestor_Type test is really unpleasant, there seem to be cases
4789 -- in which T = ID, so the above tests and assignments do nothing???
4791 if Has_Predicates
(T
)
4792 or else (Present
(Ancestor_Subtype
(T
))
4793 and then Has_Predicates
(Ancestor_Subtype
(T
)))
4795 Set_Has_Predicates
(Id
);
4796 Set_Has_Delayed_Freeze
(Id
);
4799 -- Subtype of Boolean cannot have a constraint in SPARK
4801 if Is_Boolean_Type
(T
)
4802 and then Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
4804 Check_SPARK_05_Restriction
4805 ("subtype of Boolean cannot have constraint", N
);
4808 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
4810 Cstr
: constant Node_Id
:= Constraint
(Subtype_Indication
(N
));
4816 if Nkind
(Cstr
) = N_Index_Or_Discriminant_Constraint
then
4817 One_Cstr
:= First
(Constraints
(Cstr
));
4818 while Present
(One_Cstr
) loop
4820 -- Index or discriminant constraint in SPARK must be a
4824 Nkind_In
(One_Cstr
, N_Identifier
, N_Expanded_Name
)
4826 Check_SPARK_05_Restriction
4827 ("subtype mark required", One_Cstr
);
4829 -- String subtype must have a lower bound of 1 in SPARK.
4830 -- Note that we do not need to test for the non-static case
4831 -- here, since that was already taken care of in
4832 -- Process_Range_Expr_In_Decl.
4834 elsif Base_Type
(T
) = Standard_String
then
4835 Get_Index_Bounds
(One_Cstr
, Low
, High
);
4837 if Is_OK_Static_Expression
(Low
)
4838 and then Expr_Value
(Low
) /= 1
4840 Check_SPARK_05_Restriction
4841 ("String subtype must have lower bound of 1", N
);
4851 -- In the case where there is no constraint given in the subtype
4852 -- indication, Process_Subtype just returns the Subtype_Mark, so its
4853 -- semantic attributes must be established here.
4855 if Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
then
4856 Set_Etype
(Id
, Base_Type
(T
));
4858 -- Subtype of unconstrained array without constraint is not allowed
4861 if Is_Array_Type
(T
) and then not Is_Constrained
(T
) then
4862 Check_SPARK_05_Restriction
4863 ("subtype of unconstrained array must have constraint", N
);
4868 Set_Ekind
(Id
, E_Array_Subtype
);
4869 Copy_Array_Subtype_Attributes
(Id
, T
);
4871 when Decimal_Fixed_Point_Kind
=>
4872 Set_Ekind
(Id
, E_Decimal_Fixed_Point_Subtype
);
4873 Set_Digits_Value
(Id
, Digits_Value
(T
));
4874 Set_Delta_Value
(Id
, Delta_Value
(T
));
4875 Set_Scale_Value
(Id
, Scale_Value
(T
));
4876 Set_Small_Value
(Id
, Small_Value
(T
));
4877 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
4878 Set_Machine_Radix_10
(Id
, Machine_Radix_10
(T
));
4879 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
4880 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
4881 Set_RM_Size
(Id
, RM_Size
(T
));
4883 when Enumeration_Kind
=>
4884 Set_Ekind
(Id
, E_Enumeration_Subtype
);
4885 Set_First_Literal
(Id
, First_Literal
(Base_Type
(T
)));
4886 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
4887 Set_Is_Character_Type
(Id
, Is_Character_Type
(T
));
4888 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
4889 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
4890 Set_RM_Size
(Id
, RM_Size
(T
));
4891 Inherit_Predicate_Flags
(Id
, T
);
4893 when Ordinary_Fixed_Point_Kind
=>
4894 Set_Ekind
(Id
, E_Ordinary_Fixed_Point_Subtype
);
4895 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
4896 Set_Small_Value
(Id
, Small_Value
(T
));
4897 Set_Delta_Value
(Id
, Delta_Value
(T
));
4898 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
4899 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
4900 Set_RM_Size
(Id
, RM_Size
(T
));
4903 Set_Ekind
(Id
, E_Floating_Point_Subtype
);
4904 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
4905 Set_Digits_Value
(Id
, Digits_Value
(T
));
4906 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
4908 when Signed_Integer_Kind
=>
4909 Set_Ekind
(Id
, E_Signed_Integer_Subtype
);
4910 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
4911 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
4912 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
4913 Set_RM_Size
(Id
, RM_Size
(T
));
4914 Inherit_Predicate_Flags
(Id
, T
);
4916 when Modular_Integer_Kind
=>
4917 Set_Ekind
(Id
, E_Modular_Integer_Subtype
);
4918 Set_Scalar_Range
(Id
, Scalar_Range
(T
));
4919 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
4920 Set_Is_Known_Valid
(Id
, Is_Known_Valid
(T
));
4921 Set_RM_Size
(Id
, RM_Size
(T
));
4922 Inherit_Predicate_Flags
(Id
, T
);
4924 when Class_Wide_Kind
=>
4925 Set_Ekind
(Id
, E_Class_Wide_Subtype
);
4926 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
4927 Set_Cloned_Subtype
(Id
, T
);
4928 Set_Is_Tagged_Type
(Id
, True);
4929 Set_Has_Unknown_Discriminants
4931 Set_No_Tagged_Streams_Pragma
4932 (Id
, No_Tagged_Streams_Pragma
(T
));
4934 if Ekind
(T
) = E_Class_Wide_Subtype
then
4935 Set_Equivalent_Type
(Id
, Equivalent_Type
(T
));
4938 when E_Record_Type | E_Record_Subtype
=>
4939 Set_Ekind
(Id
, E_Record_Subtype
);
4941 if Ekind
(T
) = E_Record_Subtype
4942 and then Present
(Cloned_Subtype
(T
))
4944 Set_Cloned_Subtype
(Id
, Cloned_Subtype
(T
));
4946 Set_Cloned_Subtype
(Id
, T
);
4949 Set_First_Entity
(Id
, First_Entity
(T
));
4950 Set_Last_Entity
(Id
, Last_Entity
(T
));
4951 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
4952 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
4953 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
4954 Set_Has_Implicit_Dereference
4955 (Id
, Has_Implicit_Dereference
(T
));
4956 Set_Has_Unknown_Discriminants
4957 (Id
, Has_Unknown_Discriminants
(T
));
4959 if Has_Discriminants
(T
) then
4960 Set_Discriminant_Constraint
4961 (Id
, Discriminant_Constraint
(T
));
4962 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
4964 elsif Has_Unknown_Discriminants
(Id
) then
4965 Set_Discriminant_Constraint
(Id
, No_Elist
);
4968 if Is_Tagged_Type
(T
) then
4969 Set_Is_Tagged_Type
(Id
, True);
4970 Set_No_Tagged_Streams_Pragma
4971 (Id
, No_Tagged_Streams_Pragma
(T
));
4972 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
4973 Set_Direct_Primitive_Operations
4974 (Id
, Direct_Primitive_Operations
(T
));
4975 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
4977 if Is_Interface
(T
) then
4978 Set_Is_Interface
(Id
);
4979 Set_Is_Limited_Interface
(Id
, Is_Limited_Interface
(T
));
4983 when Private_Kind
=>
4984 Set_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
4985 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
4986 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
4987 Set_First_Entity
(Id
, First_Entity
(T
));
4988 Set_Last_Entity
(Id
, Last_Entity
(T
));
4989 Set_Private_Dependents
(Id
, New_Elmt_List
);
4990 Set_Is_Limited_Record
(Id
, Is_Limited_Record
(T
));
4991 Set_Has_Implicit_Dereference
4992 (Id
, Has_Implicit_Dereference
(T
));
4993 Set_Has_Unknown_Discriminants
4994 (Id
, Has_Unknown_Discriminants
(T
));
4995 Set_Known_To_Have_Preelab_Init
4996 (Id
, Known_To_Have_Preelab_Init
(T
));
4998 if Is_Tagged_Type
(T
) then
4999 Set_Is_Tagged_Type
(Id
);
5000 Set_No_Tagged_Streams_Pragma
(Id
,
5001 No_Tagged_Streams_Pragma
(T
));
5002 Set_Is_Abstract_Type
(Id
, Is_Abstract_Type
(T
));
5003 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(T
));
5004 Set_Direct_Primitive_Operations
(Id
,
5005 Direct_Primitive_Operations
(T
));
5008 -- In general the attributes of the subtype of a private type
5009 -- are the attributes of the partial view of parent. However,
5010 -- the full view may be a discriminated type, and the subtype
5011 -- must share the discriminant constraint to generate correct
5012 -- calls to initialization procedures.
5014 if Has_Discriminants
(T
) then
5015 Set_Discriminant_Constraint
5016 (Id
, Discriminant_Constraint
(T
));
5017 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5019 elsif Present
(Full_View
(T
))
5020 and then Has_Discriminants
(Full_View
(T
))
5022 Set_Discriminant_Constraint
5023 (Id
, Discriminant_Constraint
(Full_View
(T
)));
5024 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5026 -- This would seem semantically correct, but apparently
5027 -- generates spurious errors about missing components ???
5029 -- Set_Has_Discriminants (Id);
5032 Prepare_Private_Subtype_Completion
(Id
, N
);
5034 -- If this is the subtype of a constrained private type with
5035 -- discriminants that has got a full view and we also have
5036 -- built a completion just above, show that the completion
5037 -- is a clone of the full view to the back-end.
5039 if Has_Discriminants
(T
)
5040 and then not Has_Unknown_Discriminants
(T
)
5041 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(T
))
5042 and then Present
(Full_View
(T
))
5043 and then Present
(Full_View
(Id
))
5045 Set_Cloned_Subtype
(Full_View
(Id
), Full_View
(T
));
5049 Set_Ekind
(Id
, E_Access_Subtype
);
5050 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5051 Set_Is_Access_Constant
5052 (Id
, Is_Access_Constant
(T
));
5053 Set_Directly_Designated_Type
5054 (Id
, Designated_Type
(T
));
5055 Set_Can_Never_Be_Null
(Id
, Can_Never_Be_Null
(T
));
5057 -- A Pure library_item must not contain the declaration of a
5058 -- named access type, except within a subprogram, generic
5059 -- subprogram, task unit, or protected unit, or if it has
5060 -- a specified Storage_Size of zero (RM05-10.2.1(15.4-15.5)).
5062 if Comes_From_Source
(Id
)
5063 and then In_Pure_Unit
5064 and then not In_Subprogram_Task_Protected_Unit
5065 and then not No_Pool_Assigned
(Id
)
5068 ("named access types not allowed in pure unit", N
);
5071 when Concurrent_Kind
=>
5072 Set_Ekind
(Id
, Subtype_Kind
(Ekind
(T
)));
5073 Set_Corresponding_Record_Type
(Id
,
5074 Corresponding_Record_Type
(T
));
5075 Set_First_Entity
(Id
, First_Entity
(T
));
5076 Set_First_Private_Entity
(Id
, First_Private_Entity
(T
));
5077 Set_Has_Discriminants
(Id
, Has_Discriminants
(T
));
5078 Set_Is_Constrained
(Id
, Is_Constrained
(T
));
5079 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5080 Set_Last_Entity
(Id
, Last_Entity
(T
));
5082 if Is_Tagged_Type
(T
) then
5083 Set_No_Tagged_Streams_Pragma
5084 (Id
, No_Tagged_Streams_Pragma
(T
));
5087 if Has_Discriminants
(T
) then
5088 Set_Discriminant_Constraint
5089 (Id
, Discriminant_Constraint
(T
));
5090 Set_Stored_Constraint_From_Discriminant_Constraint
(Id
);
5093 when Incomplete_Kind
=>
5094 if Ada_Version
>= Ada_2005
then
5096 -- In Ada 2005 an incomplete type can be explicitly tagged:
5097 -- propagate indication. Note that we also have to include
5098 -- subtypes for Ada 2012 extended use of incomplete types.
5100 Set_Ekind
(Id
, E_Incomplete_Subtype
);
5101 Set_Is_Tagged_Type
(Id
, Is_Tagged_Type
(T
));
5102 Set_Private_Dependents
(Id
, New_Elmt_List
);
5104 if Is_Tagged_Type
(Id
) then
5105 Set_No_Tagged_Streams_Pragma
5106 (Id
, No_Tagged_Streams_Pragma
(T
));
5107 Set_Direct_Primitive_Operations
(Id
, New_Elmt_List
);
5110 -- Ada 2005 (AI-412): Decorate an incomplete subtype of an
5111 -- incomplete type visible through a limited with clause.
5113 if From_Limited_With
(T
)
5114 and then Present
(Non_Limited_View
(T
))
5116 Set_From_Limited_With
(Id
);
5117 Set_Non_Limited_View
(Id
, Non_Limited_View
(T
));
5119 -- Ada 2005 (AI-412): Add the regular incomplete subtype
5120 -- to the private dependents of the original incomplete
5121 -- type for future transformation.
5124 Append_Elmt
(Id
, Private_Dependents
(T
));
5127 -- If the subtype name denotes an incomplete type an error
5128 -- was already reported by Process_Subtype.
5131 Set_Etype
(Id
, Any_Type
);
5135 raise Program_Error
;
5139 if Etype
(Id
) = Any_Type
then
5143 -- Some common processing on all types
5145 Set_Size_Info
(Id
, T
);
5146 Set_First_Rep_Item
(Id
, First_Rep_Item
(T
));
5148 -- If the parent type is a generic actual, so is the subtype. This may
5149 -- happen in a nested instance. Why Comes_From_Source test???
5151 if not Comes_From_Source
(N
) then
5152 Set_Is_Generic_Actual_Type
(Id
, Is_Generic_Actual_Type
(T
));
5157 Set_Is_Immediately_Visible
(Id
, True);
5158 Set_Depends_On_Private
(Id
, Has_Private_Component
(T
));
5159 Set_Is_Descendent_Of_Address
(Id
, Is_Descendent_Of_Address
(T
));
5161 if Is_Interface
(T
) then
5162 Set_Is_Interface
(Id
);
5165 if Present
(Generic_Parent_Type
(N
))
5167 (Nkind
(Parent
(Generic_Parent_Type
(N
))) /=
5168 N_Formal_Type_Declaration
5169 or else Nkind
(Formal_Type_Definition
5170 (Parent
(Generic_Parent_Type
(N
)))) /=
5171 N_Formal_Private_Type_Definition
)
5173 if Is_Tagged_Type
(Id
) then
5175 -- If this is a generic actual subtype for a synchronized type,
5176 -- the primitive operations are those of the corresponding record
5177 -- for which there is a separate subtype declaration.
5179 if Is_Concurrent_Type
(Id
) then
5181 elsif Is_Class_Wide_Type
(Id
) then
5182 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, Etype
(T
));
5184 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
, T
);
5187 elsif Scope
(Etype
(Id
)) /= Standard_Standard
then
5188 Derive_Subprograms
(Generic_Parent_Type
(N
), Id
);
5192 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
5193 Conditional_Delay
(Id
, Full_View
(T
));
5195 -- The subtypes of components or subcomponents of protected types
5196 -- do not need freeze nodes, which would otherwise appear in the
5197 -- wrong scope (before the freeze node for the protected type). The
5198 -- proper subtypes are those of the subcomponents of the corresponding
5201 elsif Ekind
(Scope
(Id
)) /= E_Protected_Type
5202 and then Present
(Scope
(Scope
(Id
))) -- error defense
5203 and then Ekind
(Scope
(Scope
(Id
))) /= E_Protected_Type
5205 Conditional_Delay
(Id
, T
);
5208 -- Check that Constraint_Error is raised for a scalar subtype indication
5209 -- when the lower or upper bound of a non-null range lies outside the
5210 -- range of the type mark.
5212 if Nkind
(Subtype_Indication
(N
)) = N_Subtype_Indication
then
5213 if Is_Scalar_Type
(Etype
(Id
))
5214 and then Scalar_Range
(Id
) /=
5215 Scalar_Range
(Etype
(Subtype_Mark
5216 (Subtype_Indication
(N
))))
5220 Etype
(Subtype_Mark
(Subtype_Indication
(N
))));
5222 -- In the array case, check compatibility for each index
5224 elsif Is_Array_Type
(Etype
(Id
)) and then Present
(First_Index
(Id
))
5226 -- This really should be a subprogram that finds the indications
5230 Subt_Index
: Node_Id
:= First_Index
(Id
);
5231 Target_Index
: Node_Id
:=
5233 (Subtype_Mark
(Subtype_Indication
(N
))));
5234 Has_Dyn_Chk
: Boolean := Has_Dynamic_Range_Check
(N
);
5237 while Present
(Subt_Index
) loop
5238 if ((Nkind
(Subt_Index
) = N_Identifier
5239 and then Ekind
(Entity
(Subt_Index
)) in Scalar_Kind
)
5240 or else Nkind
(Subt_Index
) = N_Subtype_Indication
)
5242 Nkind
(Scalar_Range
(Etype
(Subt_Index
))) = N_Range
5245 Target_Typ
: constant Entity_Id
:=
5246 Etype
(Target_Index
);
5250 (Scalar_Range
(Etype
(Subt_Index
)),
5253 Defining_Identifier
(N
));
5255 -- Reset Has_Dynamic_Range_Check on the subtype to
5256 -- prevent elision of the index check due to a dynamic
5257 -- check generated for a preceding index (needed since
5258 -- Insert_Range_Checks tries to avoid generating
5259 -- redundant checks on a given declaration).
5261 Set_Has_Dynamic_Range_Check
(N
, False);
5267 Sloc
(Defining_Identifier
(N
)));
5269 -- Record whether this index involved a dynamic check
5272 Has_Dyn_Chk
or else Has_Dynamic_Range_Check
(N
);
5276 Next_Index
(Subt_Index
);
5277 Next_Index
(Target_Index
);
5280 -- Finally, mark whether the subtype involves dynamic checks
5282 Set_Has_Dynamic_Range_Check
(N
, Has_Dyn_Chk
);
5287 -- A type invariant applies to any subtype in its scope, in particular
5288 -- to a generic actual.
5290 if Has_Invariants
(T
) and then In_Open_Scopes
(Scope
(T
)) then
5291 Set_Has_Invariants
(Id
);
5292 Set_Invariant_Procedure
(Id
, Invariant_Procedure
(T
));
5295 -- Make sure that generic actual types are properly frozen. The subtype
5296 -- is marked as a generic actual type when the enclosing instance is
5297 -- analyzed, so here we identify the subtype from the tree structure.
5300 and then Is_Generic_Actual_Type
(Id
)
5301 and then In_Instance
5302 and then not Comes_From_Source
(N
)
5303 and then Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
5304 and then Is_Frozen
(T
)
5306 Freeze_Before
(N
, Id
);
5309 Set_Optimize_Alignment_Flags
(Id
);
5310 Check_Eliminated
(Id
);
5313 if Has_Aspects
(N
) then
5314 Analyze_Aspect_Specifications
(N
, Id
);
5317 Analyze_Dimension
(N
);
5318 end Analyze_Subtype_Declaration
;
5320 --------------------------------
5321 -- Analyze_Subtype_Indication --
5322 --------------------------------
5324 procedure Analyze_Subtype_Indication
(N
: Node_Id
) is
5325 T
: constant Entity_Id
:= Subtype_Mark
(N
);
5326 R
: constant Node_Id
:= Range_Expression
(Constraint
(N
));
5333 Set_Etype
(N
, Etype
(R
));
5334 Resolve
(R
, Entity
(T
));
5336 Set_Error_Posted
(R
);
5337 Set_Error_Posted
(T
);
5339 end Analyze_Subtype_Indication
;
5341 --------------------------
5342 -- Analyze_Variant_Part --
5343 --------------------------
5345 procedure Analyze_Variant_Part
(N
: Node_Id
) is
5346 Discr_Name
: Node_Id
;
5347 Discr_Type
: Entity_Id
;
5349 procedure Process_Variant
(A
: Node_Id
);
5350 -- Analyze declarations for a single variant
5352 package Analyze_Variant_Choices
is
5353 new Generic_Analyze_Choices
(Process_Variant
);
5354 use Analyze_Variant_Choices
;
5356 ---------------------
5357 -- Process_Variant --
5358 ---------------------
5360 procedure Process_Variant
(A
: Node_Id
) is
5361 CL
: constant Node_Id
:= Component_List
(A
);
5363 if not Null_Present
(CL
) then
5364 Analyze_Declarations
(Component_Items
(CL
));
5366 if Present
(Variant_Part
(CL
)) then
5367 Analyze
(Variant_Part
(CL
));
5370 end Process_Variant
;
5372 -- Start of processing for Analyze_Variant_Part
5375 Discr_Name
:= Name
(N
);
5376 Analyze
(Discr_Name
);
5378 -- If Discr_Name bad, get out (prevent cascaded errors)
5380 if Etype
(Discr_Name
) = Any_Type
then
5384 -- Check invalid discriminant in variant part
5386 if Ekind
(Entity
(Discr_Name
)) /= E_Discriminant
then
5387 Error_Msg_N
("invalid discriminant name in variant part", Discr_Name
);
5390 Discr_Type
:= Etype
(Entity
(Discr_Name
));
5392 if not Is_Discrete_Type
(Discr_Type
) then
5394 ("discriminant in a variant part must be of a discrete type",
5399 -- Now analyze the choices, which also analyzes the declarations that
5400 -- are associated with each choice.
5402 Analyze_Choices
(Variants
(N
), Discr_Type
);
5404 -- Note: we used to instantiate and call Check_Choices here to check
5405 -- that the choices covered the discriminant, but it's too early to do
5406 -- that because of statically predicated subtypes, whose analysis may
5407 -- be deferred to their freeze point which may be as late as the freeze
5408 -- point of the containing record. So this call is now to be found in
5409 -- Freeze_Record_Declaration.
5411 end Analyze_Variant_Part
;
5413 ----------------------------
5414 -- Array_Type_Declaration --
5415 ----------------------------
5417 procedure Array_Type_Declaration
(T
: in out Entity_Id
; Def
: Node_Id
) is
5418 Component_Def
: constant Node_Id
:= Component_Definition
(Def
);
5419 Component_Typ
: constant Node_Id
:= Subtype_Indication
(Component_Def
);
5420 Element_Type
: Entity_Id
;
5421 Implicit_Base
: Entity_Id
;
5423 Related_Id
: Entity_Id
:= Empty
;
5425 P
: constant Node_Id
:= Parent
(Def
);
5429 if Nkind
(Def
) = N_Constrained_Array_Definition
then
5430 Index
:= First
(Discrete_Subtype_Definitions
(Def
));
5432 Index
:= First
(Subtype_Marks
(Def
));
5435 -- Find proper names for the implicit types which may be public. In case
5436 -- of anonymous arrays we use the name of the first object of that type
5440 Related_Id
:= Defining_Identifier
(P
);
5446 while Present
(Index
) loop
5449 -- Test for odd case of trying to index a type by the type itself
5451 if Is_Entity_Name
(Index
) and then Entity
(Index
) = T
then
5452 Error_Msg_N
("type& cannot be indexed by itself", Index
);
5453 Set_Entity
(Index
, Standard_Boolean
);
5454 Set_Etype
(Index
, Standard_Boolean
);
5457 -- Check SPARK restriction requiring a subtype mark
5459 if not Nkind_In
(Index
, N_Identifier
, N_Expanded_Name
) then
5460 Check_SPARK_05_Restriction
("subtype mark required", Index
);
5463 -- Add a subtype declaration for each index of private array type
5464 -- declaration whose etype is also private. For example:
5467 -- type Index is private;
5469 -- type Table is array (Index) of ...
5472 -- This is currently required by the expander for the internally
5473 -- generated equality subprogram of records with variant parts in
5474 -- which the etype of some component is such private type.
5476 if Ekind
(Current_Scope
) = E_Package
5477 and then In_Private_Part
(Current_Scope
)
5478 and then Has_Private_Declaration
(Etype
(Index
))
5481 Loc
: constant Source_Ptr
:= Sloc
(Def
);
5486 New_E
:= Make_Temporary
(Loc
, 'T');
5487 Set_Is_Internal
(New_E
);
5490 Make_Subtype_Declaration
(Loc
,
5491 Defining_Identifier
=> New_E
,
5492 Subtype_Indication
=>
5493 New_Occurrence_Of
(Etype
(Index
), Loc
));
5495 Insert_Before
(Parent
(Def
), Decl
);
5497 Set_Etype
(Index
, New_E
);
5499 -- If the index is a range the Entity attribute is not
5500 -- available. Example:
5503 -- type T is private;
5505 -- type T is new Natural;
5506 -- Table : array (T(1) .. T(10)) of Boolean;
5509 if Nkind
(Index
) /= N_Range
then
5510 Set_Entity
(Index
, New_E
);
5515 Make_Index
(Index
, P
, Related_Id
, Nb_Index
);
5517 -- Check error of subtype with predicate for index type
5519 Bad_Predicated_Subtype_Use
5520 ("subtype& has predicate, not allowed as index subtype",
5521 Index
, Etype
(Index
));
5523 -- Move to next index
5526 Nb_Index
:= Nb_Index
+ 1;
5529 -- Process subtype indication if one is present
5531 if Present
(Component_Typ
) then
5532 Element_Type
:= Process_Subtype
(Component_Typ
, P
, Related_Id
, 'C');
5534 Set_Etype
(Component_Typ
, Element_Type
);
5536 if not Nkind_In
(Component_Typ
, N_Identifier
, N_Expanded_Name
) then
5537 Check_SPARK_05_Restriction
5538 ("subtype mark required", Component_Typ
);
5541 -- Ada 2005 (AI-230): Access Definition case
5543 else pragma Assert
(Present
(Access_Definition
(Component_Def
)));
5545 -- Indicate that the anonymous access type is created by the
5546 -- array type declaration.
5548 Element_Type
:= Access_Definition
5550 N
=> Access_Definition
(Component_Def
));
5551 Set_Is_Local_Anonymous_Access
(Element_Type
);
5553 -- Propagate the parent. This field is needed if we have to generate
5554 -- the master_id associated with an anonymous access to task type
5555 -- component (see Expand_N_Full_Type_Declaration.Build_Master)
5557 Set_Parent
(Element_Type
, Parent
(T
));
5559 -- Ada 2005 (AI-230): In case of components that are anonymous access
5560 -- types the level of accessibility depends on the enclosing type
5563 Set_Scope
(Element_Type
, Current_Scope
); -- Ada 2005 (AI-230)
5565 -- Ada 2005 (AI-254)
5568 CD
: constant Node_Id
:=
5569 Access_To_Subprogram_Definition
5570 (Access_Definition
(Component_Def
));
5572 if Present
(CD
) and then Protected_Present
(CD
) then
5574 Replace_Anonymous_Access_To_Protected_Subprogram
(Def
);
5579 -- Constrained array case
5582 T
:= Create_Itype
(E_Void
, P
, Related_Id
, 'T');
5585 if Nkind
(Def
) = N_Constrained_Array_Definition
then
5587 -- Establish Implicit_Base as unconstrained base type
5589 Implicit_Base
:= Create_Itype
(E_Array_Type
, P
, Related_Id
, 'B');
5591 Set_Etype
(Implicit_Base
, Implicit_Base
);
5592 Set_Scope
(Implicit_Base
, Current_Scope
);
5593 Set_Has_Delayed_Freeze
(Implicit_Base
);
5594 Set_Default_SSO
(Implicit_Base
);
5596 -- The constrained array type is a subtype of the unconstrained one
5598 Set_Ekind
(T
, E_Array_Subtype
);
5599 Init_Size_Align
(T
);
5600 Set_Etype
(T
, Implicit_Base
);
5601 Set_Scope
(T
, Current_Scope
);
5602 Set_Is_Constrained
(T
);
5604 First
(Discrete_Subtype_Definitions
(Def
)));
5605 Set_Has_Delayed_Freeze
(T
);
5607 -- Complete setup of implicit base type
5609 Set_First_Index
(Implicit_Base
, First_Index
(T
));
5610 Set_Component_Type
(Implicit_Base
, Element_Type
);
5611 Set_Has_Task
(Implicit_Base
, Has_Task
(Element_Type
));
5612 Set_Has_Protected
(Implicit_Base
, Has_Protected
(Element_Type
));
5613 Set_Component_Size
(Implicit_Base
, Uint_0
);
5614 Set_Packed_Array_Impl_Type
(Implicit_Base
, Empty
);
5615 Set_Has_Controlled_Component
(Implicit_Base
,
5616 Has_Controlled_Component
(Element_Type
)
5617 or else Is_Controlled
(Element_Type
));
5618 Set_Finalize_Storage_Only
(Implicit_Base
,
5619 Finalize_Storage_Only
(Element_Type
));
5621 -- Inherit the "ghostness" from the constrained array type
5623 if Is_Ghost_Entity
(T
) or else Ghost_Mode
> None
then
5624 Set_Is_Ghost_Entity
(Implicit_Base
);
5627 -- Unconstrained array case
5630 Set_Ekind
(T
, E_Array_Type
);
5631 Init_Size_Align
(T
);
5633 Set_Scope
(T
, Current_Scope
);
5634 Set_Component_Size
(T
, Uint_0
);
5635 Set_Is_Constrained
(T
, False);
5636 Set_First_Index
(T
, First
(Subtype_Marks
(Def
)));
5637 Set_Has_Delayed_Freeze
(T
, True);
5638 Set_Has_Task
(T
, Has_Task
(Element_Type
));
5639 Set_Has_Protected
(T
, Has_Protected
(Element_Type
));
5640 Set_Has_Controlled_Component
(T
, Has_Controlled_Component
5643 Is_Controlled
(Element_Type
));
5644 Set_Finalize_Storage_Only
(T
, Finalize_Storage_Only
5646 Set_Default_SSO
(T
);
5649 -- Common attributes for both cases
5651 Set_Component_Type
(Base_Type
(T
), Element_Type
);
5652 Set_Packed_Array_Impl_Type
(T
, Empty
);
5654 if Aliased_Present
(Component_Definition
(Def
)) then
5655 Check_SPARK_05_Restriction
5656 ("aliased is not allowed", Component_Definition
(Def
));
5657 Set_Has_Aliased_Components
(Etype
(T
));
5660 -- Ada 2005 (AI-231): Propagate the null-excluding attribute to the
5661 -- array type to ensure that objects of this type are initialized.
5663 if Ada_Version
>= Ada_2005
and then Can_Never_Be_Null
(Element_Type
) then
5664 Set_Can_Never_Be_Null
(T
);
5666 if Null_Exclusion_Present
(Component_Definition
(Def
))
5668 -- No need to check itypes because in their case this check was
5669 -- done at their point of creation
5671 and then not Is_Itype
(Element_Type
)
5674 ("`NOT NULL` not allowed (null already excluded)",
5675 Subtype_Indication
(Component_Definition
(Def
)));
5679 Priv
:= Private_Component
(Element_Type
);
5681 if Present
(Priv
) then
5683 -- Check for circular definitions
5685 if Priv
= Any_Type
then
5686 Set_Component_Type
(Etype
(T
), Any_Type
);
5688 -- There is a gap in the visibility of operations on the composite
5689 -- type only if the component type is defined in a different scope.
5691 elsif Scope
(Priv
) = Current_Scope
then
5694 elsif Is_Limited_Type
(Priv
) then
5695 Set_Is_Limited_Composite
(Etype
(T
));
5696 Set_Is_Limited_Composite
(T
);
5698 Set_Is_Private_Composite
(Etype
(T
));
5699 Set_Is_Private_Composite
(T
);
5703 -- A syntax error in the declaration itself may lead to an empty index
5704 -- list, in which case do a minimal patch.
5706 if No
(First_Index
(T
)) then
5707 Error_Msg_N
("missing index definition in array type declaration", T
);
5710 Indexes
: constant List_Id
:=
5711 New_List
(New_Occurrence_Of
(Any_Id
, Sloc
(T
)));
5713 Set_Discrete_Subtype_Definitions
(Def
, Indexes
);
5714 Set_First_Index
(T
, First
(Indexes
));
5719 -- Create a concatenation operator for the new type. Internal array
5720 -- types created for packed entities do not need such, they are
5721 -- compatible with the user-defined type.
5723 if Number_Dimensions
(T
) = 1
5724 and then not Is_Packed_Array_Impl_Type
(T
)
5726 New_Concatenation_Op
(T
);
5729 -- In the case of an unconstrained array the parser has already verified
5730 -- that all the indexes are unconstrained but we still need to make sure
5731 -- that the element type is constrained.
5733 if Is_Indefinite_Subtype
(Element_Type
) then
5735 ("unconstrained element type in array declaration",
5736 Subtype_Indication
(Component_Def
));
5738 elsif Is_Abstract_Type
(Element_Type
) then
5740 ("the type of a component cannot be abstract",
5741 Subtype_Indication
(Component_Def
));
5744 -- There may be an invariant declared for the component type, but
5745 -- the construction of the component invariant checking procedure
5746 -- takes place during expansion.
5747 end Array_Type_Declaration
;
5749 ------------------------------------------------------
5750 -- Replace_Anonymous_Access_To_Protected_Subprogram --
5751 ------------------------------------------------------
5753 function Replace_Anonymous_Access_To_Protected_Subprogram
5754 (N
: Node_Id
) return Entity_Id
5756 Loc
: constant Source_Ptr
:= Sloc
(N
);
5758 Curr_Scope
: constant Scope_Stack_Entry
:=
5759 Scope_Stack
.Table
(Scope_Stack
.Last
);
5761 Anon
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
5764 -- Access definition in declaration
5767 -- Object definition or formal definition with an access definition
5770 -- Declaration of anonymous access to subprogram type
5773 -- Original specification in access to subprogram
5778 Set_Is_Internal
(Anon
);
5781 when N_Component_Declaration |
5782 N_Unconstrained_Array_Definition |
5783 N_Constrained_Array_Definition
=>
5784 Comp
:= Component_Definition
(N
);
5785 Acc
:= Access_Definition
(Comp
);
5787 when N_Discriminant_Specification
=>
5788 Comp
:= Discriminant_Type
(N
);
5791 when N_Parameter_Specification
=>
5792 Comp
:= Parameter_Type
(N
);
5795 when N_Access_Function_Definition
=>
5796 Comp
:= Result_Definition
(N
);
5799 when N_Object_Declaration
=>
5800 Comp
:= Object_Definition
(N
);
5803 when N_Function_Specification
=>
5804 Comp
:= Result_Definition
(N
);
5808 raise Program_Error
;
5811 Spec
:= Access_To_Subprogram_Definition
(Acc
);
5814 Make_Full_Type_Declaration
(Loc
,
5815 Defining_Identifier
=> Anon
,
5816 Type_Definition
=> Copy_Separate_Tree
(Spec
));
5818 Mark_Rewrite_Insertion
(Decl
);
5820 -- In ASIS mode, analyze the profile on the original node, because
5821 -- the separate copy does not provide enough links to recover the
5822 -- original tree. Analysis is limited to type annotations, within
5823 -- a temporary scope that serves as an anonymous subprogram to collect
5824 -- otherwise useless temporaries and itypes.
5828 Typ
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
5831 if Nkind
(Spec
) = N_Access_Function_Definition
then
5832 Set_Ekind
(Typ
, E_Function
);
5834 Set_Ekind
(Typ
, E_Procedure
);
5837 Set_Parent
(Typ
, N
);
5838 Set_Scope
(Typ
, Current_Scope
);
5841 -- Nothing to do if procedure is parameterless
5843 if Present
(Parameter_Specifications
(Spec
)) then
5844 Process_Formals
(Parameter_Specifications
(Spec
), Spec
);
5847 if Nkind
(Spec
) = N_Access_Function_Definition
then
5849 Def
: constant Node_Id
:= Result_Definition
(Spec
);
5852 -- The result might itself be an anonymous access type, so
5855 if Nkind
(Def
) = N_Access_Definition
then
5856 if Present
(Access_To_Subprogram_Definition
(Def
)) then
5859 Replace_Anonymous_Access_To_Protected_Subprogram
5862 Find_Type
(Subtype_Mark
(Def
));
5875 -- Insert the new declaration in the nearest enclosing scope. If the
5876 -- node is a body and N is its return type, the declaration belongs in
5877 -- the enclosing scope.
5881 if Nkind
(P
) = N_Subprogram_Body
5882 and then Nkind
(N
) = N_Function_Specification
5887 while Present
(P
) and then not Has_Declarations
(P
) loop
5891 pragma Assert
(Present
(P
));
5893 if Nkind
(P
) = N_Package_Specification
then
5894 Prepend
(Decl
, Visible_Declarations
(P
));
5896 Prepend
(Decl
, Declarations
(P
));
5899 -- Replace the anonymous type with an occurrence of the new declaration.
5900 -- In all cases the rewritten node does not have the null-exclusion
5901 -- attribute because (if present) it was already inherited by the
5902 -- anonymous entity (Anon). Thus, in case of components we do not
5903 -- inherit this attribute.
5905 if Nkind
(N
) = N_Parameter_Specification
then
5906 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
5907 Set_Etype
(Defining_Identifier
(N
), Anon
);
5908 Set_Null_Exclusion_Present
(N
, False);
5910 elsif Nkind
(N
) = N_Object_Declaration
then
5911 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
5912 Set_Etype
(Defining_Identifier
(N
), Anon
);
5914 elsif Nkind
(N
) = N_Access_Function_Definition
then
5915 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
5917 elsif Nkind
(N
) = N_Function_Specification
then
5918 Rewrite
(Comp
, New_Occurrence_Of
(Anon
, Loc
));
5919 Set_Etype
(Defining_Unit_Name
(N
), Anon
);
5923 Make_Component_Definition
(Loc
,
5924 Subtype_Indication
=> New_Occurrence_Of
(Anon
, Loc
)));
5927 Mark_Rewrite_Insertion
(Comp
);
5929 if Nkind_In
(N
, N_Object_Declaration
, N_Access_Function_Definition
) then
5933 -- Temporarily remove the current scope (record or subprogram) from
5934 -- the stack to add the new declarations to the enclosing scope.
5936 Scope_Stack
.Decrement_Last
;
5938 Set_Is_Itype
(Anon
);
5939 Scope_Stack
.Append
(Curr_Scope
);
5942 Set_Ekind
(Anon
, E_Anonymous_Access_Protected_Subprogram_Type
);
5943 Set_Can_Use_Internal_Rep
(Anon
, not Always_Compatible_Rep_On_Target
);
5945 end Replace_Anonymous_Access_To_Protected_Subprogram
;
5947 -------------------------------
5948 -- Build_Derived_Access_Type --
5949 -------------------------------
5951 procedure Build_Derived_Access_Type
5953 Parent_Type
: Entity_Id
;
5954 Derived_Type
: Entity_Id
)
5956 S
: constant Node_Id
:= Subtype_Indication
(Type_Definition
(N
));
5958 Desig_Type
: Entity_Id
;
5960 Discr_Con_Elist
: Elist_Id
;
5961 Discr_Con_El
: Elmt_Id
;
5965 -- Set the designated type so it is available in case this is an access
5966 -- to a self-referential type, e.g. a standard list type with a next
5967 -- pointer. Will be reset after subtype is built.
5969 Set_Directly_Designated_Type
5970 (Derived_Type
, Designated_Type
(Parent_Type
));
5972 Subt
:= Process_Subtype
(S
, N
);
5974 if Nkind
(S
) /= N_Subtype_Indication
5975 and then Subt
/= Base_Type
(Subt
)
5977 Set_Ekind
(Derived_Type
, E_Access_Subtype
);
5980 if Ekind
(Derived_Type
) = E_Access_Subtype
then
5982 Pbase
: constant Entity_Id
:= Base_Type
(Parent_Type
);
5983 Ibase
: constant Entity_Id
:=
5984 Create_Itype
(Ekind
(Pbase
), N
, Derived_Type
, 'B');
5985 Svg_Chars
: constant Name_Id
:= Chars
(Ibase
);
5986 Svg_Next_E
: constant Entity_Id
:= Next_Entity
(Ibase
);
5989 Copy_Node
(Pbase
, Ibase
);
5991 Set_Chars
(Ibase
, Svg_Chars
);
5992 Set_Next_Entity
(Ibase
, Svg_Next_E
);
5993 Set_Sloc
(Ibase
, Sloc
(Derived_Type
));
5994 Set_Scope
(Ibase
, Scope
(Derived_Type
));
5995 Set_Freeze_Node
(Ibase
, Empty
);
5996 Set_Is_Frozen
(Ibase
, False);
5997 Set_Comes_From_Source
(Ibase
, False);
5998 Set_Is_First_Subtype
(Ibase
, False);
6000 Set_Etype
(Ibase
, Pbase
);
6001 Set_Etype
(Derived_Type
, Ibase
);
6005 Set_Directly_Designated_Type
6006 (Derived_Type
, Designated_Type
(Subt
));
6008 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Subt
));
6009 Set_Is_Access_Constant
(Derived_Type
, Is_Access_Constant
(Parent_Type
));
6010 Set_Size_Info
(Derived_Type
, Parent_Type
);
6011 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
6012 Set_Depends_On_Private
(Derived_Type
,
6013 Has_Private_Component
(Derived_Type
));
6014 Conditional_Delay
(Derived_Type
, Subt
);
6016 -- Ada 2005 (AI-231): Set the null-exclusion attribute, and verify
6017 -- that it is not redundant.
6019 if Null_Exclusion_Present
(Type_Definition
(N
)) then
6020 Set_Can_Never_Be_Null
(Derived_Type
);
6022 -- What is with the "AND THEN FALSE" here ???
6024 if Can_Never_Be_Null
(Parent_Type
)
6028 ("`NOT NULL` not allowed (& already excludes null)",
6032 elsif Can_Never_Be_Null
(Parent_Type
) then
6033 Set_Can_Never_Be_Null
(Derived_Type
);
6036 -- Note: we do not copy the Storage_Size_Variable, since we always go to
6037 -- the root type for this information.
6039 -- Apply range checks to discriminants for derived record case
6040 -- ??? THIS CODE SHOULD NOT BE HERE REALLY.
6042 Desig_Type
:= Designated_Type
(Derived_Type
);
6043 if Is_Composite_Type
(Desig_Type
)
6044 and then (not Is_Array_Type
(Desig_Type
))
6045 and then Has_Discriminants
(Desig_Type
)
6046 and then Base_Type
(Desig_Type
) /= Desig_Type
6048 Discr_Con_Elist
:= Discriminant_Constraint
(Desig_Type
);
6049 Discr_Con_El
:= First_Elmt
(Discr_Con_Elist
);
6051 Discr
:= First_Discriminant
(Base_Type
(Desig_Type
));
6052 while Present
(Discr_Con_El
) loop
6053 Apply_Range_Check
(Node
(Discr_Con_El
), Etype
(Discr
));
6054 Next_Elmt
(Discr_Con_El
);
6055 Next_Discriminant
(Discr
);
6058 end Build_Derived_Access_Type
;
6060 ------------------------------
6061 -- Build_Derived_Array_Type --
6062 ------------------------------
6064 procedure Build_Derived_Array_Type
6066 Parent_Type
: Entity_Id
;
6067 Derived_Type
: Entity_Id
)
6069 Loc
: constant Source_Ptr
:= Sloc
(N
);
6070 Tdef
: constant Node_Id
:= Type_Definition
(N
);
6071 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
6072 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
6073 Implicit_Base
: Entity_Id
;
6074 New_Indic
: Node_Id
;
6076 procedure Make_Implicit_Base
;
6077 -- If the parent subtype is constrained, the derived type is a subtype
6078 -- of an implicit base type derived from the parent base.
6080 ------------------------
6081 -- Make_Implicit_Base --
6082 ------------------------
6084 procedure Make_Implicit_Base
is
6087 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
6089 Set_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
6090 Set_Etype
(Implicit_Base
, Parent_Base
);
6092 Copy_Array_Subtype_Attributes
(Implicit_Base
, Parent_Base
);
6093 Copy_Array_Base_Type_Attributes
(Implicit_Base
, Parent_Base
);
6095 Set_Has_Delayed_Freeze
(Implicit_Base
, True);
6097 -- Inherit the "ghostness" from the parent base type
6099 if Is_Ghost_Entity
(Parent_Base
) or else Ghost_Mode
> None
then
6100 Set_Is_Ghost_Entity
(Implicit_Base
);
6102 end Make_Implicit_Base
;
6104 -- Start of processing for Build_Derived_Array_Type
6107 if not Is_Constrained
(Parent_Type
) then
6108 if Nkind
(Indic
) /= N_Subtype_Indication
then
6109 Set_Ekind
(Derived_Type
, E_Array_Type
);
6111 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
6112 Copy_Array_Base_Type_Attributes
(Derived_Type
, Parent_Type
);
6114 Set_Has_Delayed_Freeze
(Derived_Type
, True);
6118 Set_Etype
(Derived_Type
, Implicit_Base
);
6121 Make_Subtype_Declaration
(Loc
,
6122 Defining_Identifier
=> Derived_Type
,
6123 Subtype_Indication
=>
6124 Make_Subtype_Indication
(Loc
,
6125 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
6126 Constraint
=> Constraint
(Indic
)));
6128 Rewrite
(N
, New_Indic
);
6133 if Nkind
(Indic
) /= N_Subtype_Indication
then
6136 Set_Ekind
(Derived_Type
, Ekind
(Parent_Type
));
6137 Set_Etype
(Derived_Type
, Implicit_Base
);
6138 Copy_Array_Subtype_Attributes
(Derived_Type
, Parent_Type
);
6141 Error_Msg_N
("illegal constraint on constrained type", Indic
);
6145 -- If parent type is not a derived type itself, and is declared in
6146 -- closed scope (e.g. a subprogram), then we must explicitly introduce
6147 -- the new type's concatenation operator since Derive_Subprograms
6148 -- will not inherit the parent's operator. If the parent type is
6149 -- unconstrained, the operator is of the unconstrained base type.
6151 if Number_Dimensions
(Parent_Type
) = 1
6152 and then not Is_Limited_Type
(Parent_Type
)
6153 and then not Is_Derived_Type
(Parent_Type
)
6154 and then not Is_Package_Or_Generic_Package
6155 (Scope
(Base_Type
(Parent_Type
)))
6157 if not Is_Constrained
(Parent_Type
)
6158 and then Is_Constrained
(Derived_Type
)
6160 New_Concatenation_Op
(Implicit_Base
);
6162 New_Concatenation_Op
(Derived_Type
);
6165 end Build_Derived_Array_Type
;
6167 -----------------------------------
6168 -- Build_Derived_Concurrent_Type --
6169 -----------------------------------
6171 procedure Build_Derived_Concurrent_Type
6173 Parent_Type
: Entity_Id
;
6174 Derived_Type
: Entity_Id
)
6176 Loc
: constant Source_Ptr
:= Sloc
(N
);
6178 Corr_Record
: constant Entity_Id
:= Make_Temporary
(Loc
, 'C');
6179 Corr_Decl
: Node_Id
;
6180 Corr_Decl_Needed
: Boolean;
6181 -- If the derived type has fewer discriminants than its parent, the
6182 -- corresponding record is also a derived type, in order to account for
6183 -- the bound discriminants. We create a full type declaration for it in
6186 Constraint_Present
: constant Boolean :=
6187 Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
6188 N_Subtype_Indication
;
6190 D_Constraint
: Node_Id
;
6191 New_Constraint
: Elist_Id
;
6192 Old_Disc
: Entity_Id
;
6193 New_Disc
: Entity_Id
;
6197 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
6198 Corr_Decl_Needed
:= False;
6201 if Present
(Discriminant_Specifications
(N
))
6202 and then Constraint_Present
6204 Old_Disc
:= First_Discriminant
(Parent_Type
);
6205 New_Disc
:= First
(Discriminant_Specifications
(N
));
6206 while Present
(New_Disc
) and then Present
(Old_Disc
) loop
6207 Next_Discriminant
(Old_Disc
);
6212 if Present
(Old_Disc
) and then Expander_Active
then
6214 -- The new type has fewer discriminants, so we need to create a new
6215 -- corresponding record, which is derived from the corresponding
6216 -- record of the parent, and has a stored constraint that captures
6217 -- the values of the discriminant constraints. The corresponding
6218 -- record is needed only if expander is active and code generation is
6221 -- The type declaration for the derived corresponding record has the
6222 -- same discriminant part and constraints as the current declaration.
6223 -- Copy the unanalyzed tree to build declaration.
6225 Corr_Decl_Needed
:= True;
6226 New_N
:= Copy_Separate_Tree
(N
);
6229 Make_Full_Type_Declaration
(Loc
,
6230 Defining_Identifier
=> Corr_Record
,
6231 Discriminant_Specifications
=>
6232 Discriminant_Specifications
(New_N
),
6234 Make_Derived_Type_Definition
(Loc
,
6235 Subtype_Indication
=>
6236 Make_Subtype_Indication
(Loc
,
6239 (Corresponding_Record_Type
(Parent_Type
), Loc
),
6242 (Subtype_Indication
(Type_Definition
(New_N
))))));
6245 -- Copy Storage_Size and Relative_Deadline variables if task case
6247 if Is_Task_Type
(Parent_Type
) then
6248 Set_Storage_Size_Variable
(Derived_Type
,
6249 Storage_Size_Variable
(Parent_Type
));
6250 Set_Relative_Deadline_Variable
(Derived_Type
,
6251 Relative_Deadline_Variable
(Parent_Type
));
6254 if Present
(Discriminant_Specifications
(N
)) then
6255 Push_Scope
(Derived_Type
);
6256 Check_Or_Process_Discriminants
(N
, Derived_Type
);
6258 if Constraint_Present
then
6260 Expand_To_Stored_Constraint
6262 Build_Discriminant_Constraints
6264 Subtype_Indication
(Type_Definition
(N
)), True));
6269 elsif Constraint_Present
then
6271 -- Build constrained subtype, copying the constraint, and derive
6272 -- from it to create a derived constrained type.
6275 Loc
: constant Source_Ptr
:= Sloc
(N
);
6276 Anon
: constant Entity_Id
:=
6277 Make_Defining_Identifier
(Loc
,
6278 Chars
=> New_External_Name
(Chars
(Derived_Type
), 'T'));
6283 Make_Subtype_Declaration
(Loc
,
6284 Defining_Identifier
=> Anon
,
6285 Subtype_Indication
=>
6286 New_Copy_Tree
(Subtype_Indication
(Type_Definition
(N
))));
6287 Insert_Before
(N
, Decl
);
6290 Rewrite
(Subtype_Indication
(Type_Definition
(N
)),
6291 New_Occurrence_Of
(Anon
, Loc
));
6292 Set_Analyzed
(Derived_Type
, False);
6298 -- By default, operations and private data are inherited from parent.
6299 -- However, in the presence of bound discriminants, a new corresponding
6300 -- record will be created, see below.
6302 Set_Has_Discriminants
6303 (Derived_Type
, Has_Discriminants
(Parent_Type
));
6304 Set_Corresponding_Record_Type
6305 (Derived_Type
, Corresponding_Record_Type
(Parent_Type
));
6307 -- Is_Constrained is set according the parent subtype, but is set to
6308 -- False if the derived type is declared with new discriminants.
6312 (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
6313 and then not Present
(Discriminant_Specifications
(N
)));
6315 if Constraint_Present
then
6316 if not Has_Discriminants
(Parent_Type
) then
6317 Error_Msg_N
("untagged parent must have discriminants", N
);
6319 elsif Present
(Discriminant_Specifications
(N
)) then
6321 -- Verify that new discriminants are used to constrain old ones
6326 (Constraint
(Subtype_Indication
(Type_Definition
(N
)))));
6328 Old_Disc
:= First_Discriminant
(Parent_Type
);
6330 while Present
(D_Constraint
) loop
6331 if Nkind
(D_Constraint
) /= N_Discriminant_Association
then
6333 -- Positional constraint. If it is a reference to a new
6334 -- discriminant, it constrains the corresponding old one.
6336 if Nkind
(D_Constraint
) = N_Identifier
then
6337 New_Disc
:= First_Discriminant
(Derived_Type
);
6338 while Present
(New_Disc
) loop
6339 exit when Chars
(New_Disc
) = Chars
(D_Constraint
);
6340 Next_Discriminant
(New_Disc
);
6343 if Present
(New_Disc
) then
6344 Set_Corresponding_Discriminant
(New_Disc
, Old_Disc
);
6348 Next_Discriminant
(Old_Disc
);
6350 -- if this is a named constraint, search by name for the old
6351 -- discriminants constrained by the new one.
6353 elsif Nkind
(Expression
(D_Constraint
)) = N_Identifier
then
6355 -- Find new discriminant with that name
6357 New_Disc
:= First_Discriminant
(Derived_Type
);
6358 while Present
(New_Disc
) loop
6360 Chars
(New_Disc
) = Chars
(Expression
(D_Constraint
));
6361 Next_Discriminant
(New_Disc
);
6364 if Present
(New_Disc
) then
6366 -- Verify that new discriminant renames some discriminant
6367 -- of the parent type, and associate the new discriminant
6368 -- with one or more old ones that it renames.
6374 Selector
:= First
(Selector_Names
(D_Constraint
));
6375 while Present
(Selector
) loop
6376 Old_Disc
:= First_Discriminant
(Parent_Type
);
6377 while Present
(Old_Disc
) loop
6378 exit when Chars
(Old_Disc
) = Chars
(Selector
);
6379 Next_Discriminant
(Old_Disc
);
6382 if Present
(Old_Disc
) then
6383 Set_Corresponding_Discriminant
6384 (New_Disc
, Old_Disc
);
6393 Next
(D_Constraint
);
6396 New_Disc
:= First_Discriminant
(Derived_Type
);
6397 while Present
(New_Disc
) loop
6398 if No
(Corresponding_Discriminant
(New_Disc
)) then
6400 ("new discriminant& must constrain old one", N
, New_Disc
);
6403 Subtypes_Statically_Compatible
6405 Etype
(Corresponding_Discriminant
(New_Disc
)))
6408 ("& not statically compatible with parent discriminant",
6412 Next_Discriminant
(New_Disc
);
6416 elsif Present
(Discriminant_Specifications
(N
)) then
6418 ("missing discriminant constraint in untagged derivation", N
);
6421 -- The entity chain of the derived type includes the new discriminants
6422 -- but shares operations with the parent.
6424 if Present
(Discriminant_Specifications
(N
)) then
6425 Old_Disc
:= First_Discriminant
(Parent_Type
);
6426 while Present
(Old_Disc
) loop
6427 if No
(Next_Entity
(Old_Disc
))
6428 or else Ekind
(Next_Entity
(Old_Disc
)) /= E_Discriminant
6431 (Last_Entity
(Derived_Type
), Next_Entity
(Old_Disc
));
6435 Next_Discriminant
(Old_Disc
);
6439 Set_First_Entity
(Derived_Type
, First_Entity
(Parent_Type
));
6440 if Has_Discriminants
(Parent_Type
) then
6441 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
6442 Set_Discriminant_Constraint
(
6443 Derived_Type
, Discriminant_Constraint
(Parent_Type
));
6447 Set_Last_Entity
(Derived_Type
, Last_Entity
(Parent_Type
));
6449 Set_Has_Completion
(Derived_Type
);
6451 if Corr_Decl_Needed
then
6452 Set_Stored_Constraint
(Derived_Type
, New_Constraint
);
6453 Insert_After
(N
, Corr_Decl
);
6454 Analyze
(Corr_Decl
);
6455 Set_Corresponding_Record_Type
(Derived_Type
, Corr_Record
);
6457 end Build_Derived_Concurrent_Type
;
6459 ------------------------------------
6460 -- Build_Derived_Enumeration_Type --
6461 ------------------------------------
6463 procedure Build_Derived_Enumeration_Type
6465 Parent_Type
: Entity_Id
;
6466 Derived_Type
: Entity_Id
)
6468 Loc
: constant Source_Ptr
:= Sloc
(N
);
6469 Def
: constant Node_Id
:= Type_Definition
(N
);
6470 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
6471 Implicit_Base
: Entity_Id
;
6472 Literal
: Entity_Id
;
6473 New_Lit
: Entity_Id
;
6474 Literals_List
: List_Id
;
6475 Type_Decl
: Node_Id
;
6477 Rang_Expr
: Node_Id
;
6480 -- Since types Standard.Character and Standard.[Wide_]Wide_Character do
6481 -- not have explicit literals lists we need to process types derived
6482 -- from them specially. This is handled by Derived_Standard_Character.
6483 -- If the parent type is a generic type, there are no literals either,
6484 -- and we construct the same skeletal representation as for the generic
6487 if Is_Standard_Character_Type
(Parent_Type
) then
6488 Derived_Standard_Character
(N
, Parent_Type
, Derived_Type
);
6490 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
6496 if Nkind
(Indic
) /= N_Subtype_Indication
then
6498 Make_Attribute_Reference
(Loc
,
6499 Attribute_Name
=> Name_First
,
6500 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
6501 Set_Etype
(Lo
, Derived_Type
);
6504 Make_Attribute_Reference
(Loc
,
6505 Attribute_Name
=> Name_Last
,
6506 Prefix
=> New_Occurrence_Of
(Derived_Type
, Loc
));
6507 Set_Etype
(Hi
, Derived_Type
);
6509 Set_Scalar_Range
(Derived_Type
,
6515 -- Analyze subtype indication and verify compatibility
6516 -- with parent type.
6518 if Base_Type
(Process_Subtype
(Indic
, N
)) /=
6519 Base_Type
(Parent_Type
)
6522 ("illegal constraint for formal discrete type", N
);
6528 -- If a constraint is present, analyze the bounds to catch
6529 -- premature usage of the derived literals.
6531 if Nkind
(Indic
) = N_Subtype_Indication
6532 and then Nkind
(Range_Expression
(Constraint
(Indic
))) = N_Range
6534 Analyze
(Low_Bound
(Range_Expression
(Constraint
(Indic
))));
6535 Analyze
(High_Bound
(Range_Expression
(Constraint
(Indic
))));
6538 -- Introduce an implicit base type for the derived type even if there
6539 -- is no constraint attached to it, since this seems closer to the
6540 -- Ada semantics. Build a full type declaration tree for the derived
6541 -- type using the implicit base type as the defining identifier. The
6542 -- build a subtype declaration tree which applies the constraint (if
6543 -- any) have it replace the derived type declaration.
6545 Literal
:= First_Literal
(Parent_Type
);
6546 Literals_List
:= New_List
;
6547 while Present
(Literal
)
6548 and then Ekind
(Literal
) = E_Enumeration_Literal
6550 -- Literals of the derived type have the same representation as
6551 -- those of the parent type, but this representation can be
6552 -- overridden by an explicit representation clause. Indicate
6553 -- that there is no explicit representation given yet. These
6554 -- derived literals are implicit operations of the new type,
6555 -- and can be overridden by explicit ones.
6557 if Nkind
(Literal
) = N_Defining_Character_Literal
then
6559 Make_Defining_Character_Literal
(Loc
, Chars
(Literal
));
6561 New_Lit
:= Make_Defining_Identifier
(Loc
, Chars
(Literal
));
6564 Set_Ekind
(New_Lit
, E_Enumeration_Literal
);
6565 Set_Enumeration_Pos
(New_Lit
, Enumeration_Pos
(Literal
));
6566 Set_Enumeration_Rep
(New_Lit
, Enumeration_Rep
(Literal
));
6567 Set_Enumeration_Rep_Expr
(New_Lit
, Empty
);
6568 Set_Alias
(New_Lit
, Literal
);
6569 Set_Is_Known_Valid
(New_Lit
, True);
6571 Append
(New_Lit
, Literals_List
);
6572 Next_Literal
(Literal
);
6576 Make_Defining_Identifier
(Sloc
(Derived_Type
),
6577 Chars
=> New_External_Name
(Chars
(Derived_Type
), 'B'));
6579 -- Indicate the proper nature of the derived type. This must be done
6580 -- before analysis of the literals, to recognize cases when a literal
6581 -- may be hidden by a previous explicit function definition (cf.
6584 Set_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
6585 Set_Etype
(Derived_Type
, Implicit_Base
);
6588 Make_Full_Type_Declaration
(Loc
,
6589 Defining_Identifier
=> Implicit_Base
,
6590 Discriminant_Specifications
=> No_List
,
6592 Make_Enumeration_Type_Definition
(Loc
, Literals_List
));
6594 Mark_Rewrite_Insertion
(Type_Decl
);
6595 Insert_Before
(N
, Type_Decl
);
6596 Analyze
(Type_Decl
);
6598 -- The anonymous base now has a full declaration, but this base
6599 -- is not a first subtype.
6601 Set_Is_First_Subtype
(Implicit_Base
, False);
6603 -- After the implicit base is analyzed its Etype needs to be changed
6604 -- to reflect the fact that it is derived from the parent type which
6605 -- was ignored during analysis. We also set the size at this point.
6607 Set_Etype
(Implicit_Base
, Parent_Type
);
6609 Set_Size_Info
(Implicit_Base
, Parent_Type
);
6610 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Type
));
6611 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Type
));
6613 -- Copy other flags from parent type
6615 Set_Has_Non_Standard_Rep
6616 (Implicit_Base
, Has_Non_Standard_Rep
6618 Set_Has_Pragma_Ordered
6619 (Implicit_Base
, Has_Pragma_Ordered
6621 Set_Has_Delayed_Freeze
(Implicit_Base
);
6623 -- Process the subtype indication including a validation check on the
6624 -- constraint, if any. If a constraint is given, its bounds must be
6625 -- implicitly converted to the new type.
6627 if Nkind
(Indic
) = N_Subtype_Indication
then
6629 R
: constant Node_Id
:=
6630 Range_Expression
(Constraint
(Indic
));
6633 if Nkind
(R
) = N_Range
then
6634 Hi
:= Build_Scalar_Bound
6635 (High_Bound
(R
), Parent_Type
, Implicit_Base
);
6636 Lo
:= Build_Scalar_Bound
6637 (Low_Bound
(R
), Parent_Type
, Implicit_Base
);
6640 -- Constraint is a Range attribute. Replace with explicit
6641 -- mention of the bounds of the prefix, which must be a
6644 Analyze
(Prefix
(R
));
6646 Convert_To
(Implicit_Base
,
6647 Make_Attribute_Reference
(Loc
,
6648 Attribute_Name
=> Name_Last
,
6650 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
6653 Convert_To
(Implicit_Base
,
6654 Make_Attribute_Reference
(Loc
,
6655 Attribute_Name
=> Name_First
,
6657 New_Occurrence_Of
(Entity
(Prefix
(R
)), Loc
)));
6664 (Type_High_Bound
(Parent_Type
),
6665 Parent_Type
, Implicit_Base
);
6668 (Type_Low_Bound
(Parent_Type
),
6669 Parent_Type
, Implicit_Base
);
6677 -- If we constructed a default range for the case where no range
6678 -- was given, then the expressions in the range must not freeze
6679 -- since they do not correspond to expressions in the source.
6681 if Nkind
(Indic
) /= N_Subtype_Indication
then
6682 Set_Must_Not_Freeze
(Lo
);
6683 Set_Must_Not_Freeze
(Hi
);
6684 Set_Must_Not_Freeze
(Rang_Expr
);
6688 Make_Subtype_Declaration
(Loc
,
6689 Defining_Identifier
=> Derived_Type
,
6690 Subtype_Indication
=>
6691 Make_Subtype_Indication
(Loc
,
6692 Subtype_Mark
=> New_Occurrence_Of
(Implicit_Base
, Loc
),
6694 Make_Range_Constraint
(Loc
,
6695 Range_Expression
=> Rang_Expr
))));
6699 -- Propagate the aspects from the original type declaration to the
6700 -- declaration of the implicit base.
6702 Move_Aspects
(From
=> Original_Node
(N
), To
=> Type_Decl
);
6704 -- Apply a range check. Since this range expression doesn't have an
6705 -- Etype, we have to specifically pass the Source_Typ parameter. Is
6708 if Nkind
(Indic
) = N_Subtype_Indication
then
6710 (Range_Expression
(Constraint
(Indic
)), Parent_Type
,
6711 Source_Typ
=> Entity
(Subtype_Mark
(Indic
)));
6714 end Build_Derived_Enumeration_Type
;
6716 --------------------------------
6717 -- Build_Derived_Numeric_Type --
6718 --------------------------------
6720 procedure Build_Derived_Numeric_Type
6722 Parent_Type
: Entity_Id
;
6723 Derived_Type
: Entity_Id
)
6725 Loc
: constant Source_Ptr
:= Sloc
(N
);
6726 Tdef
: constant Node_Id
:= Type_Definition
(N
);
6727 Indic
: constant Node_Id
:= Subtype_Indication
(Tdef
);
6728 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
6729 No_Constraint
: constant Boolean := Nkind
(Indic
) /=
6730 N_Subtype_Indication
;
6731 Implicit_Base
: Entity_Id
;
6737 -- Process the subtype indication including a validation check on
6738 -- the constraint if any.
6740 Discard_Node
(Process_Subtype
(Indic
, N
));
6742 -- Introduce an implicit base type for the derived type even if there
6743 -- is no constraint attached to it, since this seems closer to the Ada
6747 Create_Itype
(Ekind
(Parent_Base
), N
, Derived_Type
, 'B');
6749 Set_Etype
(Implicit_Base
, Parent_Base
);
6750 Set_Ekind
(Implicit_Base
, Ekind
(Parent_Base
));
6751 Set_Size_Info
(Implicit_Base
, Parent_Base
);
6752 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Parent_Base
));
6753 Set_Parent
(Implicit_Base
, Parent
(Derived_Type
));
6754 Set_Is_Known_Valid
(Implicit_Base
, Is_Known_Valid
(Parent_Base
));
6756 -- Set RM Size for discrete type or decimal fixed-point type
6757 -- Ordinary fixed-point is excluded, why???
6759 if Is_Discrete_Type
(Parent_Base
)
6760 or else Is_Decimal_Fixed_Point_Type
(Parent_Base
)
6762 Set_RM_Size
(Implicit_Base
, RM_Size
(Parent_Base
));
6765 Set_Has_Delayed_Freeze
(Implicit_Base
);
6767 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
6768 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
6770 Set_Scalar_Range
(Implicit_Base
,
6775 if Has_Infinities
(Parent_Base
) then
6776 Set_Includes_Infinities
(Scalar_Range
(Implicit_Base
));
6779 -- The Derived_Type, which is the entity of the declaration, is a
6780 -- subtype of the implicit base. Its Ekind is a subtype, even in the
6781 -- absence of an explicit constraint.
6783 Set_Etype
(Derived_Type
, Implicit_Base
);
6785 -- If we did not have a constraint, then the Ekind is set from the
6786 -- parent type (otherwise Process_Subtype has set the bounds)
6788 if No_Constraint
then
6789 Set_Ekind
(Derived_Type
, Subtype_Kind
(Ekind
(Parent_Type
)));
6792 -- If we did not have a range constraint, then set the range from the
6793 -- parent type. Otherwise, the Process_Subtype call has set the bounds.
6795 if No_Constraint
or else not Has_Range_Constraint
(Indic
) then
6796 Set_Scalar_Range
(Derived_Type
,
6798 Low_Bound
=> New_Copy_Tree
(Type_Low_Bound
(Parent_Type
)),
6799 High_Bound
=> New_Copy_Tree
(Type_High_Bound
(Parent_Type
))));
6800 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
6802 if Has_Infinities
(Parent_Type
) then
6803 Set_Includes_Infinities
(Scalar_Range
(Derived_Type
));
6806 Set_Is_Known_Valid
(Derived_Type
, Is_Known_Valid
(Parent_Type
));
6809 Set_Is_Descendent_Of_Address
(Derived_Type
,
6810 Is_Descendent_Of_Address
(Parent_Type
));
6811 Set_Is_Descendent_Of_Address
(Implicit_Base
,
6812 Is_Descendent_Of_Address
(Parent_Type
));
6814 -- Set remaining type-specific fields, depending on numeric type
6816 if Is_Modular_Integer_Type
(Parent_Type
) then
6817 Set_Modulus
(Implicit_Base
, Modulus
(Parent_Base
));
6819 Set_Non_Binary_Modulus
6820 (Implicit_Base
, Non_Binary_Modulus
(Parent_Base
));
6823 (Implicit_Base
, Is_Known_Valid
(Parent_Base
));
6825 elsif Is_Floating_Point_Type
(Parent_Type
) then
6827 -- Digits of base type is always copied from the digits value of
6828 -- the parent base type, but the digits of the derived type will
6829 -- already have been set if there was a constraint present.
6831 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
6832 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Parent_Base
));
6834 if No_Constraint
then
6835 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Type
));
6838 elsif Is_Fixed_Point_Type
(Parent_Type
) then
6840 -- Small of base type and derived type are always copied from the
6841 -- parent base type, since smalls never change. The delta of the
6842 -- base type is also copied from the parent base type. However the
6843 -- delta of the derived type will have been set already if a
6844 -- constraint was present.
6846 Set_Small_Value
(Derived_Type
, Small_Value
(Parent_Base
));
6847 Set_Small_Value
(Implicit_Base
, Small_Value
(Parent_Base
));
6848 Set_Delta_Value
(Implicit_Base
, Delta_Value
(Parent_Base
));
6850 if No_Constraint
then
6851 Set_Delta_Value
(Derived_Type
, Delta_Value
(Parent_Type
));
6854 -- The scale and machine radix in the decimal case are always
6855 -- copied from the parent base type.
6857 if Is_Decimal_Fixed_Point_Type
(Parent_Type
) then
6858 Set_Scale_Value
(Derived_Type
, Scale_Value
(Parent_Base
));
6859 Set_Scale_Value
(Implicit_Base
, Scale_Value
(Parent_Base
));
6861 Set_Machine_Radix_10
6862 (Derived_Type
, Machine_Radix_10
(Parent_Base
));
6863 Set_Machine_Radix_10
6864 (Implicit_Base
, Machine_Radix_10
(Parent_Base
));
6866 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Parent_Base
));
6868 if No_Constraint
then
6869 Set_Digits_Value
(Derived_Type
, Digits_Value
(Parent_Base
));
6872 -- the analysis of the subtype_indication sets the
6873 -- digits value of the derived type.
6880 if Is_Integer_Type
(Parent_Type
) then
6881 Set_Has_Shift_Operator
6882 (Implicit_Base
, Has_Shift_Operator
(Parent_Type
));
6885 -- The type of the bounds is that of the parent type, and they
6886 -- must be converted to the derived type.
6888 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
6890 -- The implicit_base should be frozen when the derived type is frozen,
6891 -- but note that it is used in the conversions of the bounds. For fixed
6892 -- types we delay the determination of the bounds until the proper
6893 -- freezing point. For other numeric types this is rejected by GCC, for
6894 -- reasons that are currently unclear (???), so we choose to freeze the
6895 -- implicit base now. In the case of integers and floating point types
6896 -- this is harmless because subsequent representation clauses cannot
6897 -- affect anything, but it is still baffling that we cannot use the
6898 -- same mechanism for all derived numeric types.
6900 -- There is a further complication: actually some representation
6901 -- clauses can affect the implicit base type. For example, attribute
6902 -- definition clauses for stream-oriented attributes need to set the
6903 -- corresponding TSS entries on the base type, and this normally
6904 -- cannot be done after the base type is frozen, so the circuitry in
6905 -- Sem_Ch13.New_Stream_Subprogram must account for this possibility
6906 -- and not use Set_TSS in this case.
6908 -- There are also consequences for the case of delayed representation
6909 -- aspects for some cases. For example, a Size aspect is delayed and
6910 -- should not be evaluated to the freeze point. This early freezing
6911 -- means that the size attribute evaluation happens too early???
6913 if Is_Fixed_Point_Type
(Parent_Type
) then
6914 Conditional_Delay
(Implicit_Base
, Parent_Type
);
6916 Freeze_Before
(N
, Implicit_Base
);
6918 end Build_Derived_Numeric_Type
;
6920 --------------------------------
6921 -- Build_Derived_Private_Type --
6922 --------------------------------
6924 procedure Build_Derived_Private_Type
6926 Parent_Type
: Entity_Id
;
6927 Derived_Type
: Entity_Id
;
6928 Is_Completion
: Boolean;
6929 Derive_Subps
: Boolean := True)
6931 Loc
: constant Source_Ptr
:= Sloc
(N
);
6932 Par_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
6933 Par_Scope
: constant Entity_Id
:= Scope
(Par_Base
);
6934 Full_N
: constant Node_Id
:= New_Copy_Tree
(N
);
6935 Full_Der
: Entity_Id
:= New_Copy
(Derived_Type
);
6938 procedure Build_Full_Derivation
;
6939 -- Build full derivation, i.e. derive from the full view
6941 procedure Copy_And_Build
;
6942 -- Copy derived type declaration, replace parent with its full view,
6943 -- and build derivation
6945 ---------------------------
6946 -- Build_Full_Derivation --
6947 ---------------------------
6949 procedure Build_Full_Derivation
is
6951 -- If parent scope is not open, install the declarations
6953 if not In_Open_Scopes
(Par_Scope
) then
6954 Install_Private_Declarations
(Par_Scope
);
6955 Install_Visible_Declarations
(Par_Scope
);
6957 Uninstall_Declarations
(Par_Scope
);
6959 -- If parent scope is open and in another unit, and parent has a
6960 -- completion, then the derivation is taking place in the visible
6961 -- part of a child unit. In that case retrieve the full view of
6962 -- the parent momentarily.
6964 elsif not In_Same_Source_Unit
(N
, Parent_Type
) then
6965 Full_P
:= Full_View
(Parent_Type
);
6966 Exchange_Declarations
(Parent_Type
);
6968 Exchange_Declarations
(Full_P
);
6970 -- Otherwise it is a local derivation
6975 end Build_Full_Derivation
;
6977 --------------------
6978 -- Copy_And_Build --
6979 --------------------
6981 procedure Copy_And_Build
is
6982 Full_Parent
: Entity_Id
:= Parent_Type
;
6985 -- If the parent is itself derived from another private type,
6986 -- installing the private declarations has not affected its
6987 -- privacy status, so use its own full view explicitly.
6989 if Is_Private_Type
(Full_Parent
)
6990 and then Present
(Full_View
(Full_Parent
))
6992 Full_Parent
:= Full_View
(Full_Parent
);
6995 -- And its underlying full view if necessary
6997 if Is_Private_Type
(Full_Parent
)
6998 and then Present
(Underlying_Full_View
(Full_Parent
))
7000 Full_Parent
:= Underlying_Full_View
(Full_Parent
);
7003 -- For record, access and most enumeration types, derivation from
7004 -- the full view requires a fully-fledged declaration. In the other
7005 -- cases, just use an itype.
7007 if Ekind
(Full_Parent
) in Record_Kind
7008 or else Ekind
(Full_Parent
) in Access_Kind
7010 (Ekind
(Full_Parent
) in Enumeration_Kind
7011 and then not Is_Standard_Character_Type
(Full_Parent
)
7012 and then not Is_Generic_Type
(Root_Type
(Full_Parent
)))
7014 -- Copy and adjust declaration to provide a completion for what
7015 -- is originally a private declaration. Indicate that full view
7016 -- is internally generated.
7018 Set_Comes_From_Source
(Full_N
, False);
7019 Set_Comes_From_Source
(Full_Der
, False);
7020 Set_Parent
(Full_Der
, Full_N
);
7021 Set_Defining_Identifier
(Full_N
, Full_Der
);
7023 -- If there are no constraints, adjust the subtype mark
7025 if Nkind
(Subtype_Indication
(Type_Definition
(Full_N
))) /=
7026 N_Subtype_Indication
7028 Set_Subtype_Indication
7029 (Type_Definition
(Full_N
),
7030 New_Occurrence_Of
(Full_Parent
, Sloc
(Full_N
)));
7033 Insert_After
(N
, Full_N
);
7035 -- Build full view of derived type from full view of parent which
7036 -- is now installed. Subprograms have been derived on the partial
7037 -- view, the completion does not derive them anew.
7039 if Ekind
(Full_Parent
) in Record_Kind
then
7041 -- If parent type is tagged, the completion inherits the proper
7042 -- primitive operations.
7044 if Is_Tagged_Type
(Parent_Type
) then
7045 Build_Derived_Record_Type
7046 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
);
7048 Build_Derived_Record_Type
7049 (Full_N
, Full_Parent
, Full_Der
, Derive_Subps
=> False);
7054 (Full_N
, Full_Parent
, Full_Der
,
7055 Is_Completion
=> False, Derive_Subps
=> False);
7058 -- The full declaration has been introduced into the tree and
7059 -- processed in the step above. It should not be analyzed again
7060 -- (when encountered later in the current list of declarations)
7061 -- to prevent spurious name conflicts. The full entity remains
7064 Set_Analyzed
(Full_N
);
7068 Make_Defining_Identifier
(Sloc
(Derived_Type
),
7069 Chars
=> Chars
(Derived_Type
));
7070 Set_Is_Itype
(Full_Der
);
7071 Set_Associated_Node_For_Itype
(Full_Der
, N
);
7072 Set_Parent
(Full_Der
, N
);
7074 (N
, Full_Parent
, Full_Der
,
7075 Is_Completion
=> False, Derive_Subps
=> False);
7078 Set_Has_Private_Declaration
(Full_Der
);
7079 Set_Has_Private_Declaration
(Derived_Type
);
7081 Set_Scope
(Full_Der
, Scope
(Derived_Type
));
7082 Set_Is_First_Subtype
(Full_Der
, Is_First_Subtype
(Derived_Type
));
7083 Set_Has_Size_Clause
(Full_Der
, False);
7084 Set_Has_Alignment_Clause
(Full_Der
, False);
7085 Set_Has_Delayed_Freeze
(Full_Der
);
7086 Set_Is_Frozen
(Full_Der
, False);
7087 Set_Freeze_Node
(Full_Der
, Empty
);
7088 Set_Depends_On_Private
(Full_Der
, Has_Private_Component
(Full_Der
));
7089 Set_Is_Public
(Full_Der
, Is_Public
(Derived_Type
));
7091 -- The convention on the base type may be set in the private part
7092 -- and not propagated to the subtype until later, so we obtain the
7093 -- convention from the base type of the parent.
7095 Set_Convention
(Full_Der
, Convention
(Base_Type
(Full_Parent
)));
7098 -- Start of processing for Build_Derived_Private_Type
7101 if Is_Tagged_Type
(Parent_Type
) then
7102 Full_P
:= Full_View
(Parent_Type
);
7104 -- A type extension of a type with unknown discriminants is an
7105 -- indefinite type that the back-end cannot handle directly.
7106 -- We treat it as a private type, and build a completion that is
7107 -- derived from the full view of the parent, and hopefully has
7108 -- known discriminants.
7110 -- If the full view of the parent type has an underlying record view,
7111 -- use it to generate the underlying record view of this derived type
7112 -- (required for chains of derivations with unknown discriminants).
7114 -- Minor optimization: we avoid the generation of useless underlying
7115 -- record view entities if the private type declaration has unknown
7116 -- discriminants but its corresponding full view has no
7119 if Has_Unknown_Discriminants
(Parent_Type
)
7120 and then Present
(Full_P
)
7121 and then (Has_Discriminants
(Full_P
)
7122 or else Present
(Underlying_Record_View
(Full_P
)))
7123 and then not In_Open_Scopes
(Par_Scope
)
7124 and then Expander_Active
7127 Full_Der
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
7128 New_Ext
: constant Node_Id
:=
7130 (Record_Extension_Part
(Type_Definition
(N
)));
7134 Build_Derived_Record_Type
7135 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
7137 -- Build anonymous completion, as a derivation from the full
7138 -- view of the parent. This is not a completion in the usual
7139 -- sense, because the current type is not private.
7142 Make_Full_Type_Declaration
(Loc
,
7143 Defining_Identifier
=> Full_Der
,
7145 Make_Derived_Type_Definition
(Loc
,
7146 Subtype_Indication
=>
7148 (Subtype_Indication
(Type_Definition
(N
))),
7149 Record_Extension_Part
=> New_Ext
));
7151 -- If the parent type has an underlying record view, use it
7152 -- here to build the new underlying record view.
7154 if Present
(Underlying_Record_View
(Full_P
)) then
7156 (Nkind
(Subtype_Indication
(Type_Definition
(Decl
)))
7158 Set_Entity
(Subtype_Indication
(Type_Definition
(Decl
)),
7159 Underlying_Record_View
(Full_P
));
7162 Install_Private_Declarations
(Par_Scope
);
7163 Install_Visible_Declarations
(Par_Scope
);
7164 Insert_Before
(N
, Decl
);
7166 -- Mark entity as an underlying record view before analysis,
7167 -- to avoid generating the list of its primitive operations
7168 -- (which is not really required for this entity) and thus
7169 -- prevent spurious errors associated with missing overriding
7170 -- of abstract primitives (overridden only for Derived_Type).
7172 Set_Ekind
(Full_Der
, E_Record_Type
);
7173 Set_Is_Underlying_Record_View
(Full_Der
);
7174 Set_Default_SSO
(Full_Der
);
7178 pragma Assert
(Has_Discriminants
(Full_Der
)
7179 and then not Has_Unknown_Discriminants
(Full_Der
));
7181 Uninstall_Declarations
(Par_Scope
);
7183 -- Freeze the underlying record view, to prevent generation of
7184 -- useless dispatching information, which is simply shared with
7185 -- the real derived type.
7187 Set_Is_Frozen
(Full_Der
);
7189 -- If the derived type has access discriminants, create
7190 -- references to their anonymous types now, to prevent
7191 -- back-end problems when their first use is in generated
7192 -- bodies of primitives.
7198 E
:= First_Entity
(Full_Der
);
7200 while Present
(E
) loop
7201 if Ekind
(E
) = E_Discriminant
7202 and then Ekind
(Etype
(E
)) = E_Anonymous_Access_Type
7204 Build_Itype_Reference
(Etype
(E
), Decl
);
7211 -- Set up links between real entity and underlying record view
7213 Set_Underlying_Record_View
(Derived_Type
, Base_Type
(Full_Der
));
7214 Set_Underlying_Record_View
(Base_Type
(Full_Der
), Derived_Type
);
7217 -- If discriminants are known, build derived record
7220 Build_Derived_Record_Type
7221 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
7226 elsif Has_Discriminants
(Parent_Type
) then
7228 -- Build partial view of derived type from partial view of parent.
7229 -- This must be done before building the full derivation because the
7230 -- second derivation will modify the discriminants of the first and
7231 -- the discriminants are chained with the rest of the components in
7232 -- the full derivation.
7234 Build_Derived_Record_Type
7235 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
7237 -- Build the full derivation if this is not the anonymous derived
7238 -- base type created by Build_Derived_Record_Type in the constrained
7239 -- case (see point 5. of its head comment) since we build it for the
7240 -- derived subtype. And skip it for protected types altogether, as
7241 -- gigi does not use these types directly.
7243 if Present
(Full_View
(Parent_Type
))
7244 and then not Is_Itype
(Derived_Type
)
7245 and then not (Ekind
(Full_View
(Parent_Type
)) in Protected_Kind
)
7248 Der_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
7250 Last_Discr
: Entity_Id
;
7253 -- If this is not a completion, construct the implicit full
7254 -- view by deriving from the full view of the parent type.
7255 -- But if this is a completion, the derived private type
7256 -- being built is a full view and the full derivation can
7257 -- only be its underlying full view.
7259 Build_Full_Derivation
;
7261 if not Is_Completion
then
7262 Set_Full_View
(Derived_Type
, Full_Der
);
7264 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
7267 if not Is_Base_Type
(Derived_Type
) then
7268 Set_Full_View
(Der_Base
, Base_Type
(Full_Der
));
7271 -- Copy the discriminant list from full view to the partial
7272 -- view (base type and its subtype). Gigi requires that the
7273 -- partial and full views have the same discriminants.
7275 -- Note that since the partial view points to discriminants
7276 -- in the full view, their scope will be that of the full
7277 -- view. This might cause some front end problems and need
7280 Discr
:= First_Discriminant
(Base_Type
(Full_Der
));
7281 Set_First_Entity
(Der_Base
, Discr
);
7284 Last_Discr
:= Discr
;
7285 Next_Discriminant
(Discr
);
7286 exit when No
(Discr
);
7289 Set_Last_Entity
(Der_Base
, Last_Discr
);
7290 Set_First_Entity
(Derived_Type
, First_Entity
(Der_Base
));
7291 Set_Last_Entity
(Derived_Type
, Last_Entity
(Der_Base
));
7293 Set_Stored_Constraint
7294 (Full_Der
, Stored_Constraint
(Derived_Type
));
7298 elsif Present
(Full_View
(Parent_Type
))
7299 and then Has_Discriminants
(Full_View
(Parent_Type
))
7301 if Has_Unknown_Discriminants
(Parent_Type
)
7302 and then Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
7303 N_Subtype_Indication
7306 ("cannot constrain type with unknown discriminants",
7307 Subtype_Indication
(Type_Definition
(N
)));
7311 -- If this is not a completion, construct the implicit full view by
7312 -- deriving from the full view of the parent type. But if this is a
7313 -- completion, the derived private type being built is a full view
7314 -- and the full derivation can only be its underlying full view.
7316 Build_Full_Derivation
;
7318 if not Is_Completion
then
7319 Set_Full_View
(Derived_Type
, Full_Der
);
7321 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
7324 -- In any case, the primitive operations are inherited from the
7325 -- parent type, not from the internal full view.
7327 Set_Etype
(Base_Type
(Derived_Type
), Base_Type
(Parent_Type
));
7329 if Derive_Subps
then
7330 Derive_Subprograms
(Parent_Type
, Derived_Type
);
7333 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
7335 (Derived_Type
, Is_Constrained
(Full_View
(Parent_Type
)));
7338 -- Untagged type, No discriminants on either view
7340 if Nkind
(Subtype_Indication
(Type_Definition
(N
))) =
7341 N_Subtype_Indication
7344 ("illegal constraint on type without discriminants", N
);
7347 if Present
(Discriminant_Specifications
(N
))
7348 and then Present
(Full_View
(Parent_Type
))
7349 and then not Is_Tagged_Type
(Full_View
(Parent_Type
))
7351 Error_Msg_N
("cannot add discriminants to untagged type", N
);
7354 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
7355 Set_Is_Constrained
(Derived_Type
, Is_Constrained
(Parent_Type
));
7356 Set_Is_Controlled
(Derived_Type
, Is_Controlled
(Parent_Type
));
7357 Set_Has_Controlled_Component
7358 (Derived_Type
, Has_Controlled_Component
7361 -- Direct controlled types do not inherit Finalize_Storage_Only flag
7363 if not Is_Controlled
(Parent_Type
) then
7364 Set_Finalize_Storage_Only
7365 (Base_Type
(Derived_Type
), Finalize_Storage_Only
(Parent_Type
));
7368 -- If this is not a completion, construct the implicit full view by
7369 -- deriving from the full view of the parent type.
7371 -- ??? If the parent is untagged private and its completion is
7372 -- tagged, this mechanism will not work because we cannot derive from
7373 -- the tagged full view unless we have an extension.
7375 if Present
(Full_View
(Parent_Type
))
7376 and then not Is_Tagged_Type
(Full_View
(Parent_Type
))
7377 and then not Is_Completion
7379 Build_Full_Derivation
;
7380 Set_Full_View
(Derived_Type
, Full_Der
);
7384 Set_Has_Unknown_Discriminants
(Derived_Type
,
7385 Has_Unknown_Discriminants
(Parent_Type
));
7387 if Is_Private_Type
(Derived_Type
) then
7388 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
7391 -- If the parent base type is in scope, add the derived type to its
7392 -- list of private dependents, because its full view may become
7393 -- visible subsequently (in a nested private part, a body, or in a
7394 -- further child unit).
7396 if Is_Private_Type
(Par_Base
) and then In_Open_Scopes
(Par_Scope
) then
7397 Append_Elmt
(Derived_Type
, Private_Dependents
(Parent_Type
));
7399 -- Check for unusual case where a type completed by a private
7400 -- derivation occurs within a package nested in a child unit, and
7401 -- the parent is declared in an ancestor.
7403 if Is_Child_Unit
(Scope
(Current_Scope
))
7404 and then Is_Completion
7405 and then In_Private_Part
(Current_Scope
)
7406 and then Scope
(Parent_Type
) /= Current_Scope
7408 -- Note that if the parent has a completion in the private part,
7409 -- (which is itself a derivation from some other private type)
7410 -- it is that completion that is visible, there is no full view
7411 -- available, and no special processing is needed.
7413 and then Present
(Full_View
(Parent_Type
))
7415 -- In this case, the full view of the parent type will become
7416 -- visible in the body of the enclosing child, and only then will
7417 -- the current type be possibly non-private. Build an underlying
7418 -- full view that will be installed when the enclosing child body
7421 if Present
(Underlying_Full_View
(Derived_Type
)) then
7422 Full_Der
:= Underlying_Full_View
(Derived_Type
);
7424 Build_Full_Derivation
;
7425 Set_Underlying_Full_View
(Derived_Type
, Full_Der
);
7428 -- The full view will be used to swap entities on entry/exit to
7429 -- the body, and must appear in the entity list for the package.
7431 Append_Entity
(Full_Der
, Scope
(Derived_Type
));
7434 end Build_Derived_Private_Type
;
7436 -------------------------------
7437 -- Build_Derived_Record_Type --
7438 -------------------------------
7442 -- Ideally we would like to use the same model of type derivation for
7443 -- tagged and untagged record types. Unfortunately this is not quite
7444 -- possible because the semantics of representation clauses is different
7445 -- for tagged and untagged records under inheritance. Consider the
7448 -- type R (...) is [tagged] record ... end record;
7449 -- type T (...) is new R (...) [with ...];
7451 -- The representation clauses for T can specify a completely different
7452 -- record layout from R's. Hence the same component can be placed in two
7453 -- very different positions in objects of type T and R. If R and T are
7454 -- tagged types, representation clauses for T can only specify the layout
7455 -- of non inherited components, thus components that are common in R and T
7456 -- have the same position in objects of type R and T.
7458 -- This has two implications. The first is that the entire tree for R's
7459 -- declaration needs to be copied for T in the untagged case, so that T
7460 -- can be viewed as a record type of its own with its own representation
7461 -- clauses. The second implication is the way we handle discriminants.
7462 -- Specifically, in the untagged case we need a way to communicate to Gigi
7463 -- what are the real discriminants in the record, while for the semantics
7464 -- we need to consider those introduced by the user to rename the
7465 -- discriminants in the parent type. This is handled by introducing the
7466 -- notion of stored discriminants. See below for more.
7468 -- Fortunately the way regular components are inherited can be handled in
7469 -- the same way in tagged and untagged types.
7471 -- To complicate things a bit more the private view of a private extension
7472 -- cannot be handled in the same way as the full view (for one thing the
7473 -- semantic rules are somewhat different). We will explain what differs
7476 -- 2. DISCRIMINANTS UNDER INHERITANCE
7478 -- The semantic rules governing the discriminants of derived types are
7481 -- type Derived_Type_Name [KNOWN_DISCRIMINANT_PART] is new
7482 -- [abstract] Parent_Type_Name [CONSTRAINT] [RECORD_EXTENSION_PART]
7484 -- If parent type has discriminants, then the discriminants that are
7485 -- declared in the derived type are [3.4 (11)]:
7487 -- o The discriminants specified by a new KNOWN_DISCRIMINANT_PART, if
7490 -- o Otherwise, each discriminant of the parent type (implicitly declared
7491 -- in the same order with the same specifications). In this case, the
7492 -- discriminants are said to be "inherited", or if unknown in the parent
7493 -- are also unknown in the derived type.
7495 -- Furthermore if a KNOWN_DISCRIMINANT_PART is provided, then [3.7(13-18)]:
7497 -- o The parent subtype must be constrained;
7499 -- o If the parent type is not a tagged type, then each discriminant of
7500 -- the derived type must be used in the constraint defining a parent
7501 -- subtype. [Implementation note: This ensures that the new discriminant
7502 -- can share storage with an existing discriminant.]
7504 -- For the derived type each discriminant of the parent type is either
7505 -- inherited, constrained to equal some new discriminant of the derived
7506 -- type, or constrained to the value of an expression.
7508 -- When inherited or constrained to equal some new discriminant, the
7509 -- parent discriminant and the discriminant of the derived type are said
7512 -- If a discriminant of the parent type is constrained to a specific value
7513 -- in the derived type definition, then the discriminant is said to be
7514 -- "specified" by that derived type definition.
7516 -- 3. DISCRIMINANTS IN DERIVED UNTAGGED RECORD TYPES
7518 -- We have spoken about stored discriminants in point 1 (introduction)
7519 -- above. There are two sort of stored discriminants: implicit and
7520 -- explicit. As long as the derived type inherits the same discriminants as
7521 -- the root record type, stored discriminants are the same as regular
7522 -- discriminants, and are said to be implicit. However, if any discriminant
7523 -- in the root type was renamed in the derived type, then the derived
7524 -- type will contain explicit stored discriminants. Explicit stored
7525 -- discriminants are discriminants in addition to the semantically visible
7526 -- discriminants defined for the derived type. Stored discriminants are
7527 -- used by Gigi to figure out what are the physical discriminants in
7528 -- objects of the derived type (see precise definition in einfo.ads).
7529 -- As an example, consider the following:
7531 -- type R (D1, D2, D3 : Int) is record ... end record;
7532 -- type T1 is new R;
7533 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1);
7534 -- type T3 is new T2;
7535 -- type T4 (Y : Int) is new T3 (Y, 99);
7537 -- The following table summarizes the discriminants and stored
7538 -- discriminants in R and T1 through T4.
7540 -- Type Discrim Stored Discrim Comment
7541 -- R (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in R
7542 -- T1 (D1, D2, D3) (D1, D2, D3) Girder discrims implicit in T1
7543 -- T2 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T2
7544 -- T3 (X1, X2) (D1, D2, D3) Girder discrims EXPLICIT in T3
7545 -- T4 (Y) (D1, D2, D3) Girder discrims EXPLICIT in T4
7547 -- Field Corresponding_Discriminant (abbreviated CD below) allows us to
7548 -- find the corresponding discriminant in the parent type, while
7549 -- Original_Record_Component (abbreviated ORC below), the actual physical
7550 -- component that is renamed. Finally the field Is_Completely_Hidden
7551 -- (abbreviated ICH below) is set for all explicit stored discriminants
7552 -- (see einfo.ads for more info). For the above example this gives:
7554 -- Discrim CD ORC ICH
7555 -- ^^^^^^^ ^^ ^^^ ^^^
7556 -- D1 in R empty itself no
7557 -- D2 in R empty itself no
7558 -- D3 in R empty itself no
7560 -- D1 in T1 D1 in R itself no
7561 -- D2 in T1 D2 in R itself no
7562 -- D3 in T1 D3 in R itself no
7564 -- X1 in T2 D3 in T1 D3 in T2 no
7565 -- X2 in T2 D1 in T1 D1 in T2 no
7566 -- D1 in T2 empty itself yes
7567 -- D2 in T2 empty itself yes
7568 -- D3 in T2 empty itself yes
7570 -- X1 in T3 X1 in T2 D3 in T3 no
7571 -- X2 in T3 X2 in T2 D1 in T3 no
7572 -- D1 in T3 empty itself yes
7573 -- D2 in T3 empty itself yes
7574 -- D3 in T3 empty itself yes
7576 -- Y in T4 X1 in T3 D3 in T3 no
7577 -- D1 in T3 empty itself yes
7578 -- D2 in T3 empty itself yes
7579 -- D3 in T3 empty itself yes
7581 -- 4. DISCRIMINANTS IN DERIVED TAGGED RECORD TYPES
7583 -- Type derivation for tagged types is fairly straightforward. If no
7584 -- discriminants are specified by the derived type, these are inherited
7585 -- from the parent. No explicit stored discriminants are ever necessary.
7586 -- The only manipulation that is done to the tree is that of adding a
7587 -- _parent field with parent type and constrained to the same constraint
7588 -- specified for the parent in the derived type definition. For instance:
7590 -- type R (D1, D2, D3 : Int) is tagged record ... end record;
7591 -- type T1 is new R with null record;
7592 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with null record;
7594 -- are changed into:
7596 -- type T1 (D1, D2, D3 : Int) is new R (D1, D2, D3) with record
7597 -- _parent : R (D1, D2, D3);
7600 -- type T2 (X1, X2: Int) is new T1 (X2, 88, X1) with record
7601 -- _parent : T1 (X2, 88, X1);
7604 -- The discriminants actually present in R, T1 and T2 as well as their CD,
7605 -- ORC and ICH fields are:
7607 -- Discrim CD ORC ICH
7608 -- ^^^^^^^ ^^ ^^^ ^^^
7609 -- D1 in R empty itself no
7610 -- D2 in R empty itself no
7611 -- D3 in R empty itself no
7613 -- D1 in T1 D1 in R D1 in R no
7614 -- D2 in T1 D2 in R D2 in R no
7615 -- D3 in T1 D3 in R D3 in R no
7617 -- X1 in T2 D3 in T1 D3 in R no
7618 -- X2 in T2 D1 in T1 D1 in R no
7620 -- 5. FIRST TRANSFORMATION FOR DERIVED RECORDS
7622 -- Regardless of whether we dealing with a tagged or untagged type
7623 -- we will transform all derived type declarations of the form
7625 -- type T is new R (...) [with ...];
7627 -- subtype S is R (...);
7628 -- type T is new S [with ...];
7630 -- type BT is new R [with ...];
7631 -- subtype T is BT (...);
7633 -- That is, the base derived type is constrained only if it has no
7634 -- discriminants. The reason for doing this is that GNAT's semantic model
7635 -- assumes that a base type with discriminants is unconstrained.
7637 -- Note that, strictly speaking, the above transformation is not always
7638 -- correct. Consider for instance the following excerpt from ACVC b34011a:
7640 -- procedure B34011A is
7641 -- type REC (D : integer := 0) is record
7646 -- type T6 is new Rec;
7647 -- function F return T6;
7652 -- type U is new T6 (Q6.F.I); -- ERROR: Q6.F.
7655 -- The definition of Q6.U is illegal. However transforming Q6.U into
7657 -- type BaseU is new T6;
7658 -- subtype U is BaseU (Q6.F.I)
7660 -- turns U into a legal subtype, which is incorrect. To avoid this problem
7661 -- we always analyze the constraint (in this case (Q6.F.I)) before applying
7662 -- the transformation described above.
7664 -- There is another instance where the above transformation is incorrect.
7668 -- type Base (D : Integer) is tagged null record;
7669 -- procedure P (X : Base);
7671 -- type Der is new Base (2) with null record;
7672 -- procedure P (X : Der);
7675 -- Then the above transformation turns this into
7677 -- type Der_Base is new Base with null record;
7678 -- -- procedure P (X : Base) is implicitly inherited here
7679 -- -- as procedure P (X : Der_Base).
7681 -- subtype Der is Der_Base (2);
7682 -- procedure P (X : Der);
7683 -- -- The overriding of P (X : Der_Base) is illegal since we
7684 -- -- have a parameter conformance problem.
7686 -- To get around this problem, after having semantically processed Der_Base
7687 -- and the rewritten subtype declaration for Der, we copy Der_Base field
7688 -- Discriminant_Constraint from Der so that when parameter conformance is
7689 -- checked when P is overridden, no semantic errors are flagged.
7691 -- 6. SECOND TRANSFORMATION FOR DERIVED RECORDS
7693 -- Regardless of whether we are dealing with a tagged or untagged type
7694 -- we will transform all derived type declarations of the form
7696 -- type R (D1, .., Dn : ...) is [tagged] record ...;
7697 -- type T is new R [with ...];
7699 -- type T (D1, .., Dn : ...) is new R (D1, .., Dn) [with ...];
7701 -- The reason for such transformation is that it allows us to implement a
7702 -- very clean form of component inheritance as explained below.
7704 -- Note that this transformation is not achieved by direct tree rewriting
7705 -- and manipulation, but rather by redoing the semantic actions that the
7706 -- above transformation will entail. This is done directly in routine
7707 -- Inherit_Components.
7709 -- 7. TYPE DERIVATION AND COMPONENT INHERITANCE
7711 -- In both tagged and untagged derived types, regular non discriminant
7712 -- components are inherited in the derived type from the parent type. In
7713 -- the absence of discriminants component, inheritance is straightforward
7714 -- as components can simply be copied from the parent.
7716 -- If the parent has discriminants, inheriting components constrained with
7717 -- these discriminants requires caution. Consider the following example:
7719 -- type R (D1, D2 : Positive) is [tagged] record
7720 -- S : String (D1 .. D2);
7723 -- type T1 is new R [with null record];
7724 -- type T2 (X : positive) is new R (1, X) [with null record];
7726 -- As explained in 6. above, T1 is rewritten as
7727 -- type T1 (D1, D2 : Positive) is new R (D1, D2) [with null record];
7728 -- which makes the treatment for T1 and T2 identical.
7730 -- What we want when inheriting S, is that references to D1 and D2 in R are
7731 -- replaced with references to their correct constraints, i.e. D1 and D2 in
7732 -- T1 and 1 and X in T2. So all R's discriminant references are replaced
7733 -- with either discriminant references in the derived type or expressions.
7734 -- This replacement is achieved as follows: before inheriting R's
7735 -- components, a subtype R (D1, D2) for T1 (resp. R (1, X) for T2) is
7736 -- created in the scope of T1 (resp. scope of T2) so that discriminants D1
7737 -- and D2 of T1 are visible (resp. discriminant X of T2 is visible).
7738 -- For T2, for instance, this has the effect of replacing String (D1 .. D2)
7739 -- by String (1 .. X).
7741 -- 8. TYPE DERIVATION IN PRIVATE TYPE EXTENSIONS
7743 -- We explain here the rules governing private type extensions relevant to
7744 -- type derivation. These rules are explained on the following example:
7746 -- type D [(...)] is new A [(...)] with private; <-- partial view
7747 -- type D [(...)] is new P [(...)] with null record; <-- full view
7749 -- Type A is called the ancestor subtype of the private extension.
7750 -- Type P is the parent type of the full view of the private extension. It
7751 -- must be A or a type derived from A.
7753 -- The rules concerning the discriminants of private type extensions are
7756 -- o If a private extension inherits known discriminants from the ancestor
7757 -- subtype, then the full view must also inherit its discriminants from
7758 -- the ancestor subtype and the parent subtype of the full view must be
7759 -- constrained if and only if the ancestor subtype is constrained.
7761 -- o If a partial view has unknown discriminants, then the full view may
7762 -- define a definite or an indefinite subtype, with or without
7765 -- o If a partial view has neither known nor unknown discriminants, then
7766 -- the full view must define a definite subtype.
7768 -- o If the ancestor subtype of a private extension has constrained
7769 -- discriminants, then the parent subtype of the full view must impose a
7770 -- statically matching constraint on those discriminants.
7772 -- This means that only the following forms of private extensions are
7775 -- type D is new A with private; <-- partial view
7776 -- type D is new P with null record; <-- full view
7778 -- If A has no discriminants than P has no discriminants, otherwise P must
7779 -- inherit A's discriminants.
7781 -- type D is new A (...) with private; <-- partial view
7782 -- type D is new P (:::) with null record; <-- full view
7784 -- P must inherit A's discriminants and (...) and (:::) must statically
7787 -- subtype A is R (...);
7788 -- type D is new A with private; <-- partial view
7789 -- type D is new P with null record; <-- full view
7791 -- P must have inherited R's discriminants and must be derived from A or
7792 -- any of its subtypes.
7794 -- type D (..) is new A with private; <-- partial view
7795 -- type D (..) is new P [(:::)] with null record; <-- full view
7797 -- No specific constraints on P's discriminants or constraint (:::).
7798 -- Note that A can be unconstrained, but the parent subtype P must either
7799 -- be constrained or (:::) must be present.
7801 -- type D (..) is new A [(...)] with private; <-- partial view
7802 -- type D (..) is new P [(:::)] with null record; <-- full view
7804 -- P's constraints on A's discriminants must statically match those
7805 -- imposed by (...).
7807 -- 9. IMPLEMENTATION OF TYPE DERIVATION FOR PRIVATE EXTENSIONS
7809 -- The full view of a private extension is handled exactly as described
7810 -- above. The model chose for the private view of a private extension is
7811 -- the same for what concerns discriminants (i.e. they receive the same
7812 -- treatment as in the tagged case). However, the private view of the
7813 -- private extension always inherits the components of the parent base,
7814 -- without replacing any discriminant reference. Strictly speaking this is
7815 -- incorrect. However, Gigi never uses this view to generate code so this
7816 -- is a purely semantic issue. In theory, a set of transformations similar
7817 -- to those given in 5. and 6. above could be applied to private views of
7818 -- private extensions to have the same model of component inheritance as
7819 -- for non private extensions. However, this is not done because it would
7820 -- further complicate private type processing. Semantically speaking, this
7821 -- leaves us in an uncomfortable situation. As an example consider:
7824 -- type R (D : integer) is tagged record
7825 -- S : String (1 .. D);
7827 -- procedure P (X : R);
7828 -- type T is new R (1) with private;
7830 -- type T is new R (1) with null record;
7833 -- This is transformed into:
7836 -- type R (D : integer) is tagged record
7837 -- S : String (1 .. D);
7839 -- procedure P (X : R);
7840 -- type T is new R (1) with private;
7842 -- type BaseT is new R with null record;
7843 -- subtype T is BaseT (1);
7846 -- (strictly speaking the above is incorrect Ada)
7848 -- From the semantic standpoint the private view of private extension T
7849 -- should be flagged as constrained since one can clearly have
7853 -- in a unit withing Pack. However, when deriving subprograms for the
7854 -- private view of private extension T, T must be seen as unconstrained
7855 -- since T has discriminants (this is a constraint of the current
7856 -- subprogram derivation model). Thus, when processing the private view of
7857 -- a private extension such as T, we first mark T as unconstrained, we
7858 -- process it, we perform program derivation and just before returning from
7859 -- Build_Derived_Record_Type we mark T as constrained.
7861 -- ??? Are there are other uncomfortable cases that we will have to
7864 -- 10. RECORD_TYPE_WITH_PRIVATE complications
7866 -- Types that are derived from a visible record type and have a private
7867 -- extension present other peculiarities. They behave mostly like private
7868 -- types, but if they have primitive operations defined, these will not
7869 -- have the proper signatures for further inheritance, because other
7870 -- primitive operations will use the implicit base that we define for
7871 -- private derivations below. This affect subprogram inheritance (see
7872 -- Derive_Subprograms for details). We also derive the implicit base from
7873 -- the base type of the full view, so that the implicit base is a record
7874 -- type and not another private type, This avoids infinite loops.
7876 procedure Build_Derived_Record_Type
7878 Parent_Type
: Entity_Id
;
7879 Derived_Type
: Entity_Id
;
7880 Derive_Subps
: Boolean := True)
7882 Discriminant_Specs
: constant Boolean :=
7883 Present
(Discriminant_Specifications
(N
));
7884 Is_Tagged
: constant Boolean := Is_Tagged_Type
(Parent_Type
);
7885 Loc
: constant Source_Ptr
:= Sloc
(N
);
7886 Private_Extension
: constant Boolean :=
7887 Nkind
(N
) = N_Private_Extension_Declaration
;
7888 Assoc_List
: Elist_Id
;
7889 Constraint_Present
: Boolean;
7891 Discrim
: Entity_Id
;
7893 Inherit_Discrims
: Boolean := False;
7894 Last_Discrim
: Entity_Id
;
7895 New_Base
: Entity_Id
;
7897 New_Discrs
: Elist_Id
;
7898 New_Indic
: Node_Id
;
7899 Parent_Base
: Entity_Id
;
7900 Save_Etype
: Entity_Id
;
7901 Save_Discr_Constr
: Elist_Id
;
7902 Save_Next_Entity
: Entity_Id
;
7905 Discs
: Elist_Id
:= New_Elmt_List
;
7906 -- An empty Discs list means that there were no constraints in the
7907 -- subtype indication or that there was an error processing it.
7910 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
7911 and then Present
(Full_View
(Parent_Type
))
7912 and then Has_Discriminants
(Parent_Type
)
7914 Parent_Base
:= Base_Type
(Full_View
(Parent_Type
));
7916 Parent_Base
:= Base_Type
(Parent_Type
);
7919 -- AI05-0115 : if this is a derivation from a private type in some
7920 -- other scope that may lead to invisible components for the derived
7921 -- type, mark it accordingly.
7923 if Is_Private_Type
(Parent_Type
) then
7924 if Scope
(Parent_Type
) = Scope
(Derived_Type
) then
7927 elsif In_Open_Scopes
(Scope
(Parent_Type
))
7928 and then In_Private_Part
(Scope
(Parent_Type
))
7933 Set_Has_Private_Ancestor
(Derived_Type
);
7937 Set_Has_Private_Ancestor
7938 (Derived_Type
, Has_Private_Ancestor
(Parent_Type
));
7941 -- Before we start the previously documented transformations, here is
7942 -- little fix for size and alignment of tagged types. Normally when we
7943 -- derive type D from type P, we copy the size and alignment of P as the
7944 -- default for D, and in the absence of explicit representation clauses
7945 -- for D, the size and alignment are indeed the same as the parent.
7947 -- But this is wrong for tagged types, since fields may be added, and
7948 -- the default size may need to be larger, and the default alignment may
7949 -- need to be larger.
7951 -- We therefore reset the size and alignment fields in the tagged case.
7952 -- Note that the size and alignment will in any case be at least as
7953 -- large as the parent type (since the derived type has a copy of the
7954 -- parent type in the _parent field)
7956 -- The type is also marked as being tagged here, which is needed when
7957 -- processing components with a self-referential anonymous access type
7958 -- in the call to Check_Anonymous_Access_Components below. Note that
7959 -- this flag is also set later on for completeness.
7962 Set_Is_Tagged_Type
(Derived_Type
);
7963 Init_Size_Align
(Derived_Type
);
7966 -- STEP 0a: figure out what kind of derived type declaration we have
7968 if Private_Extension
then
7970 Set_Ekind
(Derived_Type
, E_Record_Type_With_Private
);
7971 Set_Default_SSO
(Derived_Type
);
7974 Type_Def
:= Type_Definition
(N
);
7976 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
7977 -- Parent_Base can be a private type or private extension. However,
7978 -- for tagged types with an extension the newly added fields are
7979 -- visible and hence the Derived_Type is always an E_Record_Type.
7980 -- (except that the parent may have its own private fields).
7981 -- For untagged types we preserve the Ekind of the Parent_Base.
7983 if Present
(Record_Extension_Part
(Type_Def
)) then
7984 Set_Ekind
(Derived_Type
, E_Record_Type
);
7985 Set_Default_SSO
(Derived_Type
);
7987 -- Create internal access types for components with anonymous
7990 if Ada_Version
>= Ada_2005
then
7991 Check_Anonymous_Access_Components
7992 (N
, Derived_Type
, Derived_Type
,
7993 Component_List
(Record_Extension_Part
(Type_Def
)));
7997 Set_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
8001 -- Indic can either be an N_Identifier if the subtype indication
8002 -- contains no constraint or an N_Subtype_Indication if the subtype
8003 -- indication has a constraint.
8005 Indic
:= Subtype_Indication
(Type_Def
);
8006 Constraint_Present
:= (Nkind
(Indic
) = N_Subtype_Indication
);
8008 -- Check that the type has visible discriminants. The type may be
8009 -- a private type with unknown discriminants whose full view has
8010 -- discriminants which are invisible.
8012 if Constraint_Present
then
8013 if not Has_Discriminants
(Parent_Base
)
8015 (Has_Unknown_Discriminants
(Parent_Base
)
8016 and then Is_Private_Type
(Parent_Base
))
8019 ("invalid constraint: type has no discriminant",
8020 Constraint
(Indic
));
8022 Constraint_Present
:= False;
8023 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
8025 elsif Is_Constrained
(Parent_Type
) then
8027 ("invalid constraint: parent type is already constrained",
8028 Constraint
(Indic
));
8030 Constraint_Present
:= False;
8031 Rewrite
(Indic
, New_Copy_Tree
(Subtype_Mark
(Indic
)));
8035 -- STEP 0b: If needed, apply transformation given in point 5. above
8037 if not Private_Extension
8038 and then Has_Discriminants
(Parent_Type
)
8039 and then not Discriminant_Specs
8040 and then (Is_Constrained
(Parent_Type
) or else Constraint_Present
)
8042 -- First, we must analyze the constraint (see comment in point 5.)
8043 -- The constraint may come from the subtype indication of the full
8046 if Constraint_Present
then
8047 New_Discrs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
8049 -- If there is no explicit constraint, there might be one that is
8050 -- inherited from a constrained parent type. In that case verify that
8051 -- it conforms to the constraint in the partial view. In perverse
8052 -- cases the parent subtypes of the partial and full view can have
8053 -- different constraints.
8055 elsif Present
(Stored_Constraint
(Parent_Type
)) then
8056 New_Discrs
:= Stored_Constraint
(Parent_Type
);
8059 New_Discrs
:= No_Elist
;
8062 if Has_Discriminants
(Derived_Type
)
8063 and then Has_Private_Declaration
(Derived_Type
)
8064 and then Present
(Discriminant_Constraint
(Derived_Type
))
8065 and then Present
(New_Discrs
)
8067 -- Verify that constraints of the full view statically match
8068 -- those given in the partial view.
8074 C1
:= First_Elmt
(New_Discrs
);
8075 C2
:= First_Elmt
(Discriminant_Constraint
(Derived_Type
));
8076 while Present
(C1
) and then Present
(C2
) loop
8077 if Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
8079 (Is_OK_Static_Expression
(Node
(C1
))
8080 and then Is_OK_Static_Expression
(Node
(C2
))
8082 Expr_Value
(Node
(C1
)) = Expr_Value
(Node
(C2
)))
8087 if Constraint_Present
then
8089 ("constraint not conformant to previous declaration",
8093 ("constraint of full view is incompatible "
8094 & "with partial view", N
);
8104 -- Insert and analyze the declaration for the unconstrained base type
8106 New_Base
:= Create_Itype
(Ekind
(Derived_Type
), N
, Derived_Type
, 'B');
8109 Make_Full_Type_Declaration
(Loc
,
8110 Defining_Identifier
=> New_Base
,
8112 Make_Derived_Type_Definition
(Loc
,
8113 Abstract_Present
=> Abstract_Present
(Type_Def
),
8114 Limited_Present
=> Limited_Present
(Type_Def
),
8115 Subtype_Indication
=>
8116 New_Occurrence_Of
(Parent_Base
, Loc
),
8117 Record_Extension_Part
=>
8118 Relocate_Node
(Record_Extension_Part
(Type_Def
)),
8119 Interface_List
=> Interface_List
(Type_Def
)));
8121 Set_Parent
(New_Decl
, Parent
(N
));
8122 Mark_Rewrite_Insertion
(New_Decl
);
8123 Insert_Before
(N
, New_Decl
);
8125 -- In the extension case, make sure ancestor is frozen appropriately
8126 -- (see also non-discriminated case below).
8128 if Present
(Record_Extension_Part
(Type_Def
))
8129 or else Is_Interface
(Parent_Base
)
8131 Freeze_Before
(New_Decl
, Parent_Type
);
8134 -- Note that this call passes False for the Derive_Subps parameter
8135 -- because subprogram derivation is deferred until after creating
8136 -- the subtype (see below).
8139 (New_Decl
, Parent_Base
, New_Base
,
8140 Is_Completion
=> False, Derive_Subps
=> False);
8142 -- ??? This needs re-examination to determine whether the
8143 -- above call can simply be replaced by a call to Analyze.
8145 Set_Analyzed
(New_Decl
);
8147 -- Insert and analyze the declaration for the constrained subtype
8149 if Constraint_Present
then
8151 Make_Subtype_Indication
(Loc
,
8152 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
8153 Constraint
=> Relocate_Node
(Constraint
(Indic
)));
8157 Constr_List
: constant List_Id
:= New_List
;
8162 C
:= First_Elmt
(Discriminant_Constraint
(Parent_Type
));
8163 while Present
(C
) loop
8166 -- It is safe here to call New_Copy_Tree since we called
8167 -- Force_Evaluation on each constraint previously
8168 -- in Build_Discriminant_Constraints.
8170 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
8176 Make_Subtype_Indication
(Loc
,
8177 Subtype_Mark
=> New_Occurrence_Of
(New_Base
, Loc
),
8179 Make_Index_Or_Discriminant_Constraint
(Loc
, Constr_List
));
8184 Make_Subtype_Declaration
(Loc
,
8185 Defining_Identifier
=> Derived_Type
,
8186 Subtype_Indication
=> New_Indic
));
8190 -- Derivation of subprograms must be delayed until the full subtype
8191 -- has been established, to ensure proper overriding of subprograms
8192 -- inherited by full types. If the derivations occurred as part of
8193 -- the call to Build_Derived_Type above, then the check for type
8194 -- conformance would fail because earlier primitive subprograms
8195 -- could still refer to the full type prior the change to the new
8196 -- subtype and hence would not match the new base type created here.
8197 -- Subprograms are not derived, however, when Derive_Subps is False
8198 -- (since otherwise there could be redundant derivations).
8200 if Derive_Subps
then
8201 Derive_Subprograms
(Parent_Type
, Derived_Type
);
8204 -- For tagged types the Discriminant_Constraint of the new base itype
8205 -- is inherited from the first subtype so that no subtype conformance
8206 -- problem arise when the first subtype overrides primitive
8207 -- operations inherited by the implicit base type.
8210 Set_Discriminant_Constraint
8211 (New_Base
, Discriminant_Constraint
(Derived_Type
));
8217 -- If we get here Derived_Type will have no discriminants or it will be
8218 -- a discriminated unconstrained base type.
8220 -- STEP 1a: perform preliminary actions/checks for derived tagged types
8224 -- The parent type is frozen for non-private extensions (RM 13.14(7))
8225 -- The declaration of a specific descendant of an interface type
8226 -- freezes the interface type (RM 13.14).
8228 if not Private_Extension
or else Is_Interface
(Parent_Base
) then
8229 Freeze_Before
(N
, Parent_Type
);
8232 -- In Ada 2005 (AI-344), the restriction that a derived tagged type
8233 -- cannot be declared at a deeper level than its parent type is
8234 -- removed. The check on derivation within a generic body is also
8235 -- relaxed, but there's a restriction that a derived tagged type
8236 -- cannot be declared in a generic body if it's derived directly
8237 -- or indirectly from a formal type of that generic.
8239 if Ada_Version
>= Ada_2005
then
8240 if Present
(Enclosing_Generic_Body
(Derived_Type
)) then
8242 Ancestor_Type
: Entity_Id
;
8245 -- Check to see if any ancestor of the derived type is a
8248 Ancestor_Type
:= Parent_Type
;
8249 while not Is_Generic_Type
(Ancestor_Type
)
8250 and then Etype
(Ancestor_Type
) /= Ancestor_Type
8252 Ancestor_Type
:= Etype
(Ancestor_Type
);
8255 -- If the derived type does have a formal type as an
8256 -- ancestor, then it's an error if the derived type is
8257 -- declared within the body of the generic unit that
8258 -- declares the formal type in its generic formal part. It's
8259 -- sufficient to check whether the ancestor type is declared
8260 -- inside the same generic body as the derived type (such as
8261 -- within a nested generic spec), in which case the
8262 -- derivation is legal. If the formal type is declared
8263 -- outside of that generic body, then it's guaranteed that
8264 -- the derived type is declared within the generic body of
8265 -- the generic unit declaring the formal type.
8267 if Is_Generic_Type
(Ancestor_Type
)
8268 and then Enclosing_Generic_Body
(Ancestor_Type
) /=
8269 Enclosing_Generic_Body
(Derived_Type
)
8272 ("parent type of& must not be descendant of formal type"
8273 & " of an enclosing generic body",
8274 Indic
, Derived_Type
);
8279 elsif Type_Access_Level
(Derived_Type
) /=
8280 Type_Access_Level
(Parent_Type
)
8281 and then not Is_Generic_Type
(Derived_Type
)
8283 if Is_Controlled
(Parent_Type
) then
8285 ("controlled type must be declared at the library level",
8289 ("type extension at deeper accessibility level than parent",
8295 GB
: constant Node_Id
:= Enclosing_Generic_Body
(Derived_Type
);
8298 and then GB
/= Enclosing_Generic_Body
(Parent_Base
)
8301 ("parent type of& must not be outside generic body"
8303 Indic
, Derived_Type
);
8309 -- Ada 2005 (AI-251)
8311 if Ada_Version
>= Ada_2005
and then Is_Tagged
then
8313 -- "The declaration of a specific descendant of an interface type
8314 -- freezes the interface type" (RM 13.14).
8319 if Is_Non_Empty_List
(Interface_List
(Type_Def
)) then
8320 Iface
:= First
(Interface_List
(Type_Def
));
8321 while Present
(Iface
) loop
8322 Freeze_Before
(N
, Etype
(Iface
));
8329 -- STEP 1b : preliminary cleanup of the full view of private types
8331 -- If the type is already marked as having discriminants, then it's the
8332 -- completion of a private type or private extension and we need to
8333 -- retain the discriminants from the partial view if the current
8334 -- declaration has Discriminant_Specifications so that we can verify
8335 -- conformance. However, we must remove any existing components that
8336 -- were inherited from the parent (and attached in Copy_And_Swap)
8337 -- because the full type inherits all appropriate components anyway, and
8338 -- we do not want the partial view's components interfering.
8340 if Has_Discriminants
(Derived_Type
) and then Discriminant_Specs
then
8341 Discrim
:= First_Discriminant
(Derived_Type
);
8343 Last_Discrim
:= Discrim
;
8344 Next_Discriminant
(Discrim
);
8345 exit when No
(Discrim
);
8348 Set_Last_Entity
(Derived_Type
, Last_Discrim
);
8350 -- In all other cases wipe out the list of inherited components (even
8351 -- inherited discriminants), it will be properly rebuilt here.
8354 Set_First_Entity
(Derived_Type
, Empty
);
8355 Set_Last_Entity
(Derived_Type
, Empty
);
8358 -- STEP 1c: Initialize some flags for the Derived_Type
8360 -- The following flags must be initialized here so that
8361 -- Process_Discriminants can check that discriminants of tagged types do
8362 -- not have a default initial value and that access discriminants are
8363 -- only specified for limited records. For completeness, these flags are
8364 -- also initialized along with all the other flags below.
8366 -- AI-419: Limitedness is not inherited from an interface parent, so to
8367 -- be limited in that case the type must be explicitly declared as
8368 -- limited. However, task and protected interfaces are always limited.
8370 if Limited_Present
(Type_Def
) then
8371 Set_Is_Limited_Record
(Derived_Type
);
8373 elsif Is_Limited_Record
(Parent_Type
)
8374 or else (Present
(Full_View
(Parent_Type
))
8375 and then Is_Limited_Record
(Full_View
(Parent_Type
)))
8377 if not Is_Interface
(Parent_Type
)
8378 or else Is_Synchronized_Interface
(Parent_Type
)
8379 or else Is_Protected_Interface
(Parent_Type
)
8380 or else Is_Task_Interface
(Parent_Type
)
8382 Set_Is_Limited_Record
(Derived_Type
);
8386 -- STEP 2a: process discriminants of derived type if any
8388 Push_Scope
(Derived_Type
);
8390 if Discriminant_Specs
then
8391 Set_Has_Unknown_Discriminants
(Derived_Type
, False);
8393 -- The following call initializes fields Has_Discriminants and
8394 -- Discriminant_Constraint, unless we are processing the completion
8395 -- of a private type declaration.
8397 Check_Or_Process_Discriminants
(N
, Derived_Type
);
8399 -- For untagged types, the constraint on the Parent_Type must be
8400 -- present and is used to rename the discriminants.
8402 if not Is_Tagged
and then not Has_Discriminants
(Parent_Type
) then
8403 Error_Msg_N
("untagged parent must have discriminants", Indic
);
8405 elsif not Is_Tagged
and then not Constraint_Present
then
8407 ("discriminant constraint needed for derived untagged records",
8410 -- Otherwise the parent subtype must be constrained unless we have a
8411 -- private extension.
8413 elsif not Constraint_Present
8414 and then not Private_Extension
8415 and then not Is_Constrained
(Parent_Type
)
8418 ("unconstrained type not allowed in this context", Indic
);
8420 elsif Constraint_Present
then
8421 -- The following call sets the field Corresponding_Discriminant
8422 -- for the discriminants in the Derived_Type.
8424 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
, True);
8426 -- For untagged types all new discriminants must rename
8427 -- discriminants in the parent. For private extensions new
8428 -- discriminants cannot rename old ones (implied by [7.3(13)]).
8430 Discrim
:= First_Discriminant
(Derived_Type
);
8431 while Present
(Discrim
) loop
8433 and then No
(Corresponding_Discriminant
(Discrim
))
8436 ("new discriminants must constrain old ones", Discrim
);
8438 elsif Private_Extension
8439 and then Present
(Corresponding_Discriminant
(Discrim
))
8442 ("only static constraints allowed for parent"
8443 & " discriminants in the partial view", Indic
);
8447 -- If a new discriminant is used in the constraint, then its
8448 -- subtype must be statically compatible with the parent
8449 -- discriminant's subtype (3.7(15)).
8451 -- However, if the record contains an array constrained by
8452 -- the discriminant but with some different bound, the compiler
8453 -- attemps to create a smaller range for the discriminant type.
8454 -- (See exp_ch3.Adjust_Discriminants). In this case, where
8455 -- the discriminant type is a scalar type, the check must use
8456 -- the original discriminant type in the parent declaration.
8459 Corr_Disc
: constant Entity_Id
:=
8460 Corresponding_Discriminant
(Discrim
);
8461 Disc_Type
: constant Entity_Id
:= Etype
(Discrim
);
8462 Corr_Type
: Entity_Id
;
8465 if Present
(Corr_Disc
) then
8466 if Is_Scalar_Type
(Disc_Type
) then
8468 Entity
(Discriminant_Type
(Parent
(Corr_Disc
)));
8470 Corr_Type
:= Etype
(Corr_Disc
);
8474 Subtypes_Statically_Compatible
(Disc_Type
, Corr_Type
)
8477 ("subtype must be compatible "
8478 & "with parent discriminant",
8484 Next_Discriminant
(Discrim
);
8487 -- Check whether the constraints of the full view statically
8488 -- match those imposed by the parent subtype [7.3(13)].
8490 if Present
(Stored_Constraint
(Derived_Type
)) then
8495 C1
:= First_Elmt
(Discs
);
8496 C2
:= First_Elmt
(Stored_Constraint
(Derived_Type
));
8497 while Present
(C1
) and then Present
(C2
) loop
8499 Fully_Conformant_Expressions
(Node
(C1
), Node
(C2
))
8502 ("not conformant with previous declaration",
8513 -- STEP 2b: No new discriminants, inherit discriminants if any
8516 if Private_Extension
then
8517 Set_Has_Unknown_Discriminants
8519 Has_Unknown_Discriminants
(Parent_Type
)
8520 or else Unknown_Discriminants_Present
(N
));
8522 -- The partial view of the parent may have unknown discriminants,
8523 -- but if the full view has discriminants and the parent type is
8524 -- in scope they must be inherited.
8526 elsif Has_Unknown_Discriminants
(Parent_Type
)
8528 (not Has_Discriminants
(Parent_Type
)
8529 or else not In_Open_Scopes
(Scope
(Parent_Type
)))
8531 Set_Has_Unknown_Discriminants
(Derived_Type
);
8534 if not Has_Unknown_Discriminants
(Derived_Type
)
8535 and then not Has_Unknown_Discriminants
(Parent_Base
)
8536 and then Has_Discriminants
(Parent_Type
)
8538 Inherit_Discrims
:= True;
8539 Set_Has_Discriminants
8540 (Derived_Type
, True);
8541 Set_Discriminant_Constraint
8542 (Derived_Type
, Discriminant_Constraint
(Parent_Base
));
8545 -- The following test is true for private types (remember
8546 -- transformation 5. is not applied to those) and in an error
8549 if Constraint_Present
then
8550 Discs
:= Build_Discriminant_Constraints
(Parent_Type
, Indic
);
8553 -- For now mark a new derived type as constrained only if it has no
8554 -- discriminants. At the end of Build_Derived_Record_Type we properly
8555 -- set this flag in the case of private extensions. See comments in
8556 -- point 9. just before body of Build_Derived_Record_Type.
8560 not (Inherit_Discrims
8561 or else Has_Unknown_Discriminants
(Derived_Type
)));
8564 -- STEP 3: initialize fields of derived type
8566 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged
);
8567 Set_Stored_Constraint
(Derived_Type
, No_Elist
);
8569 -- Ada 2005 (AI-251): Private type-declarations can implement interfaces
8570 -- but cannot be interfaces
8572 if not Private_Extension
8573 and then Ekind
(Derived_Type
) /= E_Private_Type
8574 and then Ekind
(Derived_Type
) /= E_Limited_Private_Type
8576 if Interface_Present
(Type_Def
) then
8577 Analyze_Interface_Declaration
(Derived_Type
, Type_Def
);
8580 Set_Interfaces
(Derived_Type
, No_Elist
);
8583 -- Fields inherited from the Parent_Type
8585 Set_Has_Specified_Layout
8586 (Derived_Type
, Has_Specified_Layout
(Parent_Type
));
8587 Set_Is_Limited_Composite
8588 (Derived_Type
, Is_Limited_Composite
(Parent_Type
));
8589 Set_Is_Private_Composite
8590 (Derived_Type
, Is_Private_Composite
(Parent_Type
));
8592 if Is_Tagged_Type
(Parent_Type
) then
8593 Set_No_Tagged_Streams_Pragma
8594 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
8597 -- Fields inherited from the Parent_Base
8599 Set_Has_Controlled_Component
8600 (Derived_Type
, Has_Controlled_Component
(Parent_Base
));
8601 Set_Has_Non_Standard_Rep
8602 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
8603 Set_Has_Primitive_Operations
8604 (Derived_Type
, Has_Primitive_Operations
(Parent_Base
));
8606 -- Fields inherited from the Parent_Base in the non-private case
8608 if Ekind
(Derived_Type
) = E_Record_Type
then
8609 Set_Has_Complex_Representation
8610 (Derived_Type
, Has_Complex_Representation
(Parent_Base
));
8613 -- Fields inherited from the Parent_Base for record types
8615 if Is_Record_Type
(Derived_Type
) then
8617 Parent_Full
: Entity_Id
;
8620 -- Ekind (Parent_Base) is not necessarily E_Record_Type since
8621 -- Parent_Base can be a private type or private extension. Go
8622 -- to the full view here to get the E_Record_Type specific flags.
8624 if Present
(Full_View
(Parent_Base
)) then
8625 Parent_Full
:= Full_View
(Parent_Base
);
8627 Parent_Full
:= Parent_Base
;
8630 Set_OK_To_Reorder_Components
8631 (Derived_Type
, OK_To_Reorder_Components
(Parent_Full
));
8635 -- Set fields for private derived types
8637 if Is_Private_Type
(Derived_Type
) then
8638 Set_Depends_On_Private
(Derived_Type
, True);
8639 Set_Private_Dependents
(Derived_Type
, New_Elmt_List
);
8641 -- Inherit fields from non private record types. If this is the
8642 -- completion of a derivation from a private type, the parent itself
8643 -- is private, and the attributes come from its full view, which must
8647 if Is_Private_Type
(Parent_Base
)
8648 and then not Is_Record_Type
(Parent_Base
)
8650 Set_Component_Alignment
8651 (Derived_Type
, Component_Alignment
(Full_View
(Parent_Base
)));
8653 (Derived_Type
, C_Pass_By_Copy
(Full_View
(Parent_Base
)));
8655 Set_Component_Alignment
8656 (Derived_Type
, Component_Alignment
(Parent_Base
));
8658 (Derived_Type
, C_Pass_By_Copy
(Parent_Base
));
8662 -- Set fields for tagged types
8665 Set_Direct_Primitive_Operations
(Derived_Type
, New_Elmt_List
);
8667 -- All tagged types defined in Ada.Finalization are controlled
8669 if Chars
(Scope
(Derived_Type
)) = Name_Finalization
8670 and then Chars
(Scope
(Scope
(Derived_Type
))) = Name_Ada
8671 and then Scope
(Scope
(Scope
(Derived_Type
))) = Standard_Standard
8673 Set_Is_Controlled
(Derived_Type
);
8675 Set_Is_Controlled
(Derived_Type
, Is_Controlled
(Parent_Base
));
8678 -- Minor optimization: there is no need to generate the class-wide
8679 -- entity associated with an underlying record view.
8681 if not Is_Underlying_Record_View
(Derived_Type
) then
8682 Make_Class_Wide_Type
(Derived_Type
);
8685 Set_Is_Abstract_Type
(Derived_Type
, Abstract_Present
(Type_Def
));
8687 if Has_Discriminants
(Derived_Type
)
8688 and then Constraint_Present
8690 Set_Stored_Constraint
8691 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Base
, Discs
));
8694 if Ada_Version
>= Ada_2005
then
8696 Ifaces_List
: Elist_Id
;
8699 -- Checks rules 3.9.4 (13/2 and 14/2)
8701 if Comes_From_Source
(Derived_Type
)
8702 and then not Is_Private_Type
(Derived_Type
)
8703 and then Is_Interface
(Parent_Type
)
8704 and then not Is_Interface
(Derived_Type
)
8706 if Is_Task_Interface
(Parent_Type
) then
8708 ("(Ada 2005) task type required (RM 3.9.4 (13.2))",
8711 elsif Is_Protected_Interface
(Parent_Type
) then
8713 ("(Ada 2005) protected type required (RM 3.9.4 (14.2))",
8718 -- Check ARM rules 3.9.4 (15/2), 9.1 (9.d/2) and 9.4 (11.d/2)
8720 Check_Interfaces
(N
, Type_Def
);
8722 -- Ada 2005 (AI-251): Collect the list of progenitors that are
8723 -- not already in the parents.
8727 Ifaces_List
=> Ifaces_List
,
8728 Exclude_Parents
=> True);
8730 Set_Interfaces
(Derived_Type
, Ifaces_List
);
8732 -- If the derived type is the anonymous type created for
8733 -- a declaration whose parent has a constraint, propagate
8734 -- the interface list to the source type. This must be done
8735 -- prior to the completion of the analysis of the source type
8736 -- because the components in the extension may contain current
8737 -- instances whose legality depends on some ancestor.
8739 if Is_Itype
(Derived_Type
) then
8741 Def
: constant Node_Id
:=
8742 Associated_Node_For_Itype
(Derived_Type
);
8745 and then Nkind
(Def
) = N_Full_Type_Declaration
8748 (Defining_Identifier
(Def
), Ifaces_List
);
8753 -- Propagate inherited invariant information of parents
8756 if Ada_Version
>= Ada_2012
8757 and then not Is_Interface
(Derived_Type
)
8759 if Has_Inheritable_Invariants
(Parent_Type
) then
8760 Set_Has_Invariants
(Derived_Type
);
8761 Set_Has_Inheritable_Invariants
(Derived_Type
);
8763 elsif not Is_Empty_Elmt_List
(Ifaces_List
) then
8768 AI
:= First_Elmt
(Ifaces_List
);
8769 while Present
(AI
) loop
8770 if Has_Inheritable_Invariants
(Node
(AI
)) then
8771 Set_Has_Invariants
(Derived_Type
);
8772 Set_Has_Inheritable_Invariants
(Derived_Type
);
8783 -- A type extension is automatically Ghost when one of its
8784 -- progenitors is Ghost (SPARK RM 6.9(9)). This property is
8785 -- also inherited when the parent type is Ghost, but this is
8786 -- done in Build_Derived_Type as the mechanism also handles
8787 -- untagged derivations.
8789 if Implements_Ghost_Interface
(Derived_Type
) then
8790 Set_Is_Ghost_Entity
(Derived_Type
);
8796 Set_Is_Packed
(Derived_Type
, Is_Packed
(Parent_Base
));
8797 Set_Has_Non_Standard_Rep
8798 (Derived_Type
, Has_Non_Standard_Rep
(Parent_Base
));
8801 -- STEP 4: Inherit components from the parent base and constrain them.
8802 -- Apply the second transformation described in point 6. above.
8804 if (not Is_Empty_Elmt_List
(Discs
) or else Inherit_Discrims
)
8805 or else not Has_Discriminants
(Parent_Type
)
8806 or else not Is_Constrained
(Parent_Type
)
8810 Constrs
:= Discriminant_Constraint
(Parent_Type
);
8815 (N
, Parent_Base
, Derived_Type
, Is_Tagged
, Inherit_Discrims
, Constrs
);
8817 -- STEP 5a: Copy the parent record declaration for untagged types
8819 if not Is_Tagged
then
8821 -- Discriminant_Constraint (Derived_Type) has been properly
8822 -- constructed. Save it and temporarily set it to Empty because we
8823 -- do not want the call to New_Copy_Tree below to mess this list.
8825 if Has_Discriminants
(Derived_Type
) then
8826 Save_Discr_Constr
:= Discriminant_Constraint
(Derived_Type
);
8827 Set_Discriminant_Constraint
(Derived_Type
, No_Elist
);
8829 Save_Discr_Constr
:= No_Elist
;
8832 -- Save the Etype field of Derived_Type. It is correctly set now,
8833 -- but the call to New_Copy tree may remap it to point to itself,
8834 -- which is not what we want. Ditto for the Next_Entity field.
8836 Save_Etype
:= Etype
(Derived_Type
);
8837 Save_Next_Entity
:= Next_Entity
(Derived_Type
);
8839 -- Assoc_List maps all stored discriminants in the Parent_Base to
8840 -- stored discriminants in the Derived_Type. It is fundamental that
8841 -- no types or itypes with discriminants other than the stored
8842 -- discriminants appear in the entities declared inside
8843 -- Derived_Type, since the back end cannot deal with it.
8847 (Parent
(Parent_Base
), Map
=> Assoc_List
, New_Sloc
=> Loc
);
8849 -- Restore the fields saved prior to the New_Copy_Tree call
8850 -- and compute the stored constraint.
8852 Set_Etype
(Derived_Type
, Save_Etype
);
8853 Set_Next_Entity
(Derived_Type
, Save_Next_Entity
);
8855 if Has_Discriminants
(Derived_Type
) then
8856 Set_Discriminant_Constraint
8857 (Derived_Type
, Save_Discr_Constr
);
8858 Set_Stored_Constraint
8859 (Derived_Type
, Expand_To_Stored_Constraint
(Parent_Type
, Discs
));
8860 Replace_Components
(Derived_Type
, New_Decl
);
8861 Set_Has_Implicit_Dereference
8862 (Derived_Type
, Has_Implicit_Dereference
(Parent_Type
));
8865 -- Insert the new derived type declaration
8867 Rewrite
(N
, New_Decl
);
8869 -- STEP 5b: Complete the processing for record extensions in generics
8871 -- There is no completion for record extensions declared in the
8872 -- parameter part of a generic, so we need to complete processing for
8873 -- these generic record extensions here. The Record_Type_Definition call
8874 -- will change the Ekind of the components from E_Void to E_Component.
8876 elsif Private_Extension
and then Is_Generic_Type
(Derived_Type
) then
8877 Record_Type_Definition
(Empty
, Derived_Type
);
8879 -- STEP 5c: Process the record extension for non private tagged types
8881 elsif not Private_Extension
then
8882 Expand_Record_Extension
(Derived_Type
, Type_Def
);
8884 -- Note : previously in ASIS mode we set the Parent_Subtype of the
8885 -- derived type to propagate some semantic information. This led
8886 -- to other ASIS failures and has been removed.
8888 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
8889 -- implemented interfaces if we are in expansion mode
8892 and then Has_Interfaces
(Derived_Type
)
8894 Add_Interface_Tag_Components
(N
, Derived_Type
);
8897 -- Analyze the record extension
8899 Record_Type_Definition
8900 (Record_Extension_Part
(Type_Def
), Derived_Type
);
8905 -- Nothing else to do if there is an error in the derivation.
8906 -- An unusual case: the full view may be derived from a type in an
8907 -- instance, when the partial view was used illegally as an actual
8908 -- in that instance, leading to a circular definition.
8910 if Etype
(Derived_Type
) = Any_Type
8911 or else Etype
(Parent_Type
) = Derived_Type
8916 -- Set delayed freeze and then derive subprograms, we need to do
8917 -- this in this order so that derived subprograms inherit the
8918 -- derived freeze if necessary.
8920 Set_Has_Delayed_Freeze
(Derived_Type
);
8922 if Derive_Subps
then
8923 Derive_Subprograms
(Parent_Type
, Derived_Type
);
8926 -- If we have a private extension which defines a constrained derived
8927 -- type mark as constrained here after we have derived subprograms. See
8928 -- comment on point 9. just above the body of Build_Derived_Record_Type.
8930 if Private_Extension
and then Inherit_Discrims
then
8931 if Constraint_Present
and then not Is_Empty_Elmt_List
(Discs
) then
8932 Set_Is_Constrained
(Derived_Type
, True);
8933 Set_Discriminant_Constraint
(Derived_Type
, Discs
);
8935 elsif Is_Constrained
(Parent_Type
) then
8937 (Derived_Type
, True);
8938 Set_Discriminant_Constraint
8939 (Derived_Type
, Discriminant_Constraint
(Parent_Type
));
8943 -- Update the class-wide type, which shares the now-completed entity
8944 -- list with its specific type. In case of underlying record views,
8945 -- we do not generate the corresponding class wide entity.
8948 and then not Is_Underlying_Record_View
(Derived_Type
)
8951 (Class_Wide_Type
(Derived_Type
), First_Entity
(Derived_Type
));
8953 (Class_Wide_Type
(Derived_Type
), Last_Entity
(Derived_Type
));
8956 Check_Function_Writable_Actuals
(N
);
8957 end Build_Derived_Record_Type
;
8959 ------------------------
8960 -- Build_Derived_Type --
8961 ------------------------
8963 procedure Build_Derived_Type
8965 Parent_Type
: Entity_Id
;
8966 Derived_Type
: Entity_Id
;
8967 Is_Completion
: Boolean;
8968 Derive_Subps
: Boolean := True)
8970 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
8973 -- Set common attributes
8975 Set_Scope
(Derived_Type
, Current_Scope
);
8977 Set_Etype
(Derived_Type
, Parent_Base
);
8978 Set_Ekind
(Derived_Type
, Ekind
(Parent_Base
));
8979 Set_Has_Task
(Derived_Type
, Has_Task
(Parent_Base
));
8980 Set_Has_Protected
(Derived_Type
, Has_Protected
(Parent_Base
));
8982 Set_Size_Info
(Derived_Type
, Parent_Type
);
8983 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
8984 Set_Is_Controlled
(Derived_Type
, Is_Controlled
(Parent_Type
));
8985 Set_Is_Tagged_Type
(Derived_Type
, Is_Tagged_Type
(Parent_Type
));
8986 Set_Is_Volatile
(Derived_Type
, Is_Volatile
(Parent_Type
));
8988 if Is_Tagged_Type
(Derived_Type
) then
8989 Set_No_Tagged_Streams_Pragma
8990 (Derived_Type
, No_Tagged_Streams_Pragma
(Parent_Type
));
8993 -- If the parent has primitive routines, set the derived type link
8995 if Has_Primitive_Operations
(Parent_Type
) then
8996 Set_Derived_Type_Link
(Parent_Base
, Derived_Type
);
8999 -- If the parent type is a private subtype, the convention on the base
9000 -- type may be set in the private part, and not propagated to the
9001 -- subtype until later, so we obtain the convention from the base type.
9003 Set_Convention
(Derived_Type
, Convention
(Parent_Base
));
9005 -- Set SSO default for record or array type
9007 if (Is_Array_Type
(Derived_Type
) or else Is_Record_Type
(Derived_Type
))
9008 and then Is_Base_Type
(Derived_Type
)
9010 Set_Default_SSO
(Derived_Type
);
9013 -- Propagate invariant information. The new type has invariants if
9014 -- they are inherited from the parent type, and these invariants can
9015 -- be further inherited, so both flags are set.
9017 -- We similarly inherit predicates
9019 if Has_Predicates
(Parent_Type
) then
9020 Set_Has_Predicates
(Derived_Type
);
9023 -- The derived type inherits the representation clauses of the parent
9025 Inherit_Rep_Item_Chain
(Derived_Type
, Parent_Type
);
9027 -- Propagate the attributes related to pragma Default_Initial_Condition
9028 -- from the parent type to the private extension. A derived type always
9029 -- inherits the default initial condition flag from the parent type. If
9030 -- the derived type carries its own Default_Initial_Condition pragma,
9031 -- the flag is later reset in Analyze_Pragma. Note that both flags are
9032 -- mutually exclusive.
9034 Propagate_Default_Init_Cond_Attributes
9035 (From_Typ
=> Parent_Type
,
9036 To_Typ
=> Derived_Type
,
9037 Parent_To_Derivation
=> True);
9039 -- If the parent type has delayed rep aspects, then mark the derived
9040 -- type as possibly inheriting a delayed rep aspect.
9042 if Has_Delayed_Rep_Aspects
(Parent_Type
) then
9043 Set_May_Inherit_Delayed_Rep_Aspects
(Derived_Type
);
9046 -- Propagate the attributes related to pragma Ghost from the parent type
9047 -- to the derived type or type extension (SPARK RM 6.9(9)).
9049 if Is_Ghost_Entity
(Parent_Type
) then
9050 Set_Is_Ghost_Entity
(Derived_Type
);
9053 -- Type dependent processing
9055 case Ekind
(Parent_Type
) is
9056 when Numeric_Kind
=>
9057 Build_Derived_Numeric_Type
(N
, Parent_Type
, Derived_Type
);
9060 Build_Derived_Array_Type
(N
, Parent_Type
, Derived_Type
);
9064 | Class_Wide_Kind
=>
9065 Build_Derived_Record_Type
9066 (N
, Parent_Type
, Derived_Type
, Derive_Subps
);
9069 when Enumeration_Kind
=>
9070 Build_Derived_Enumeration_Type
(N
, Parent_Type
, Derived_Type
);
9073 Build_Derived_Access_Type
(N
, Parent_Type
, Derived_Type
);
9075 when Incomplete_Or_Private_Kind
=>
9076 Build_Derived_Private_Type
9077 (N
, Parent_Type
, Derived_Type
, Is_Completion
, Derive_Subps
);
9079 -- For discriminated types, the derivation includes deriving
9080 -- primitive operations. For others it is done below.
9082 if Is_Tagged_Type
(Parent_Type
)
9083 or else Has_Discriminants
(Parent_Type
)
9084 or else (Present
(Full_View
(Parent_Type
))
9085 and then Has_Discriminants
(Full_View
(Parent_Type
)))
9090 when Concurrent_Kind
=>
9091 Build_Derived_Concurrent_Type
(N
, Parent_Type
, Derived_Type
);
9094 raise Program_Error
;
9097 -- Nothing more to do if some error occurred
9099 if Etype
(Derived_Type
) = Any_Type
then
9103 -- Set delayed freeze and then derive subprograms, we need to do this
9104 -- in this order so that derived subprograms inherit the derived freeze
9107 Set_Has_Delayed_Freeze
(Derived_Type
);
9109 if Derive_Subps
then
9110 Derive_Subprograms
(Parent_Type
, Derived_Type
);
9113 Set_Has_Primitive_Operations
9114 (Base_Type
(Derived_Type
), Has_Primitive_Operations
(Parent_Type
));
9115 end Build_Derived_Type
;
9117 -----------------------
9118 -- Build_Discriminal --
9119 -----------------------
9121 procedure Build_Discriminal
(Discrim
: Entity_Id
) is
9122 D_Minal
: Entity_Id
;
9123 CR_Disc
: Entity_Id
;
9126 -- A discriminal has the same name as the discriminant
9128 D_Minal
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
9130 Set_Ekind
(D_Minal
, E_In_Parameter
);
9131 Set_Mechanism
(D_Minal
, Default_Mechanism
);
9132 Set_Etype
(D_Minal
, Etype
(Discrim
));
9133 Set_Scope
(D_Minal
, Current_Scope
);
9135 Set_Discriminal
(Discrim
, D_Minal
);
9136 Set_Discriminal_Link
(D_Minal
, Discrim
);
9138 -- For task types, build at once the discriminants of the corresponding
9139 -- record, which are needed if discriminants are used in entry defaults
9140 -- and in family bounds.
9142 if Is_Concurrent_Type
(Current_Scope
)
9144 Is_Limited_Type
(Current_Scope
)
9146 CR_Disc
:= Make_Defining_Identifier
(Sloc
(Discrim
), Chars
(Discrim
));
9148 Set_Ekind
(CR_Disc
, E_In_Parameter
);
9149 Set_Mechanism
(CR_Disc
, Default_Mechanism
);
9150 Set_Etype
(CR_Disc
, Etype
(Discrim
));
9151 Set_Scope
(CR_Disc
, Current_Scope
);
9152 Set_Discriminal_Link
(CR_Disc
, Discrim
);
9153 Set_CR_Discriminant
(Discrim
, CR_Disc
);
9155 end Build_Discriminal
;
9157 ------------------------------------
9158 -- Build_Discriminant_Constraints --
9159 ------------------------------------
9161 function Build_Discriminant_Constraints
9164 Derived_Def
: Boolean := False) return Elist_Id
9166 C
: constant Node_Id
:= Constraint
(Def
);
9167 Nb_Discr
: constant Nat
:= Number_Discriminants
(T
);
9169 Discr_Expr
: array (1 .. Nb_Discr
) of Node_Id
:= (others => Empty
);
9170 -- Saves the expression corresponding to a given discriminant in T
9172 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
;
9173 -- Return the Position number within array Discr_Expr of a discriminant
9174 -- D within the discriminant list of the discriminated type T.
9176 procedure Process_Discriminant_Expression
9179 -- If this is a discriminant constraint on a partial view, do not
9180 -- generate an overflow check on the discriminant expression. The check
9181 -- will be generated when constraining the full view. Otherwise the
9182 -- backend creates duplicate symbols for the temporaries corresponding
9183 -- to the expressions to be checked, causing spurious assembler errors.
9189 function Pos_Of_Discr
(T
: Entity_Id
; D
: Entity_Id
) return Nat
is
9193 Disc
:= First_Discriminant
(T
);
9194 for J
in Discr_Expr
'Range loop
9199 Next_Discriminant
(Disc
);
9202 -- Note: Since this function is called on discriminants that are
9203 -- known to belong to the discriminated type, falling through the
9204 -- loop with no match signals an internal compiler error.
9206 raise Program_Error
;
9209 -------------------------------------
9210 -- Process_Discriminant_Expression --
9211 -------------------------------------
9213 procedure Process_Discriminant_Expression
9217 BDT
: constant Entity_Id
:= Base_Type
(Etype
(D
));
9220 -- If this is a discriminant constraint on a partial view, do
9221 -- not generate an overflow on the discriminant expression. The
9222 -- check will be generated when constraining the full view.
9224 if Is_Private_Type
(T
)
9225 and then Present
(Full_View
(T
))
9227 Analyze_And_Resolve
(Expr
, BDT
, Suppress
=> Overflow_Check
);
9229 Analyze_And_Resolve
(Expr
, BDT
);
9231 end Process_Discriminant_Expression
;
9233 -- Declarations local to Build_Discriminant_Constraints
9237 Elist
: constant Elist_Id
:= New_Elmt_List
;
9245 Discrim_Present
: Boolean := False;
9247 -- Start of processing for Build_Discriminant_Constraints
9250 -- The following loop will process positional associations only.
9251 -- For a positional association, the (single) discriminant is
9252 -- implicitly specified by position, in textual order (RM 3.7.2).
9254 Discr
:= First_Discriminant
(T
);
9255 Constr
:= First
(Constraints
(C
));
9256 for D
in Discr_Expr
'Range loop
9257 exit when Nkind
(Constr
) = N_Discriminant_Association
;
9260 Error_Msg_N
("too few discriminants given in constraint", C
);
9261 return New_Elmt_List
;
9263 elsif Nkind
(Constr
) = N_Range
9264 or else (Nkind
(Constr
) = N_Attribute_Reference
9265 and then Attribute_Name
(Constr
) = Name_Range
)
9268 ("a range is not a valid discriminant constraint", Constr
);
9269 Discr_Expr
(D
) := Error
;
9272 Process_Discriminant_Expression
(Constr
, Discr
);
9273 Discr_Expr
(D
) := Constr
;
9276 Next_Discriminant
(Discr
);
9280 if No
(Discr
) and then Present
(Constr
) then
9281 Error_Msg_N
("too many discriminants given in constraint", Constr
);
9282 return New_Elmt_List
;
9285 -- Named associations can be given in any order, but if both positional
9286 -- and named associations are used in the same discriminant constraint,
9287 -- then positional associations must occur first, at their normal
9288 -- position. Hence once a named association is used, the rest of the
9289 -- discriminant constraint must use only named associations.
9291 while Present
(Constr
) loop
9293 -- Positional association forbidden after a named association
9295 if Nkind
(Constr
) /= N_Discriminant_Association
then
9296 Error_Msg_N
("positional association follows named one", Constr
);
9297 return New_Elmt_List
;
9299 -- Otherwise it is a named association
9302 -- E records the type of the discriminants in the named
9303 -- association. All the discriminants specified in the same name
9304 -- association must have the same type.
9308 -- Search the list of discriminants in T to see if the simple name
9309 -- given in the constraint matches any of them.
9311 Id
:= First
(Selector_Names
(Constr
));
9312 while Present
(Id
) loop
9315 -- If Original_Discriminant is present, we are processing a
9316 -- generic instantiation and this is an instance node. We need
9317 -- to find the name of the corresponding discriminant in the
9318 -- actual record type T and not the name of the discriminant in
9319 -- the generic formal. Example:
9322 -- type G (D : int) is private;
9324 -- subtype W is G (D => 1);
9326 -- type Rec (X : int) is record ... end record;
9327 -- package Q is new P (G => Rec);
9329 -- At the point of the instantiation, formal type G is Rec
9330 -- and therefore when reanalyzing "subtype W is G (D => 1);"
9331 -- which really looks like "subtype W is Rec (D => 1);" at
9332 -- the point of instantiation, we want to find the discriminant
9333 -- that corresponds to D in Rec, i.e. X.
9335 if Present
(Original_Discriminant
(Id
))
9336 and then In_Instance
9338 Discr
:= Find_Corresponding_Discriminant
(Id
, T
);
9342 Discr
:= First_Discriminant
(T
);
9343 while Present
(Discr
) loop
9344 if Chars
(Discr
) = Chars
(Id
) then
9349 Next_Discriminant
(Discr
);
9353 Error_Msg_N
("& does not match any discriminant", Id
);
9354 return New_Elmt_List
;
9356 -- If the parent type is a generic formal, preserve the
9357 -- name of the discriminant for subsequent instances.
9358 -- see comment at the beginning of this if statement.
9360 elsif Is_Generic_Type
(Root_Type
(T
)) then
9361 Set_Original_Discriminant
(Id
, Discr
);
9365 Position
:= Pos_Of_Discr
(T
, Discr
);
9367 if Present
(Discr_Expr
(Position
)) then
9368 Error_Msg_N
("duplicate constraint for discriminant&", Id
);
9371 -- Each discriminant specified in the same named association
9372 -- must be associated with a separate copy of the
9373 -- corresponding expression.
9375 if Present
(Next
(Id
)) then
9376 Expr
:= New_Copy_Tree
(Expression
(Constr
));
9377 Set_Parent
(Expr
, Parent
(Expression
(Constr
)));
9379 Expr
:= Expression
(Constr
);
9382 Discr_Expr
(Position
) := Expr
;
9383 Process_Discriminant_Expression
(Expr
, Discr
);
9386 -- A discriminant association with more than one discriminant
9387 -- name is only allowed if the named discriminants are all of
9388 -- the same type (RM 3.7.1(8)).
9391 E
:= Base_Type
(Etype
(Discr
));
9393 elsif Base_Type
(Etype
(Discr
)) /= E
then
9395 ("all discriminants in an association " &
9396 "must have the same type", Id
);
9406 -- A discriminant constraint must provide exactly one value for each
9407 -- discriminant of the type (RM 3.7.1(8)).
9409 for J
in Discr_Expr
'Range loop
9410 if No
(Discr_Expr
(J
)) then
9411 Error_Msg_N
("too few discriminants given in constraint", C
);
9412 return New_Elmt_List
;
9416 -- Determine if there are discriminant expressions in the constraint
9418 for J
in Discr_Expr
'Range loop
9419 if Denotes_Discriminant
9420 (Discr_Expr
(J
), Check_Concurrent
=> True)
9422 Discrim_Present
:= True;
9426 -- Build an element list consisting of the expressions given in the
9427 -- discriminant constraint and apply the appropriate checks. The list
9428 -- is constructed after resolving any named discriminant associations
9429 -- and therefore the expressions appear in the textual order of the
9432 Discr
:= First_Discriminant
(T
);
9433 for J
in Discr_Expr
'Range loop
9434 if Discr_Expr
(J
) /= Error
then
9435 Append_Elmt
(Discr_Expr
(J
), Elist
);
9437 -- If any of the discriminant constraints is given by a
9438 -- discriminant and we are in a derived type declaration we
9439 -- have a discriminant renaming. Establish link between new
9440 -- and old discriminant.
9442 if Denotes_Discriminant
(Discr_Expr
(J
)) then
9444 Set_Corresponding_Discriminant
9445 (Entity
(Discr_Expr
(J
)), Discr
);
9448 -- Force the evaluation of non-discriminant expressions.
9449 -- If we have found a discriminant in the constraint 3.4(26)
9450 -- and 3.8(18) demand that no range checks are performed are
9451 -- after evaluation. If the constraint is for a component
9452 -- definition that has a per-object constraint, expressions are
9453 -- evaluated but not checked either. In all other cases perform
9457 if Discrim_Present
then
9460 elsif Nkind
(Parent
(Parent
(Def
))) = N_Component_Declaration
9462 Has_Per_Object_Constraint
9463 (Defining_Identifier
(Parent
(Parent
(Def
))))
9467 elsif Is_Access_Type
(Etype
(Discr
)) then
9468 Apply_Constraint_Check
(Discr_Expr
(J
), Etype
(Discr
));
9471 Apply_Range_Check
(Discr_Expr
(J
), Etype
(Discr
));
9474 Force_Evaluation
(Discr_Expr
(J
));
9477 -- Check that the designated type of an access discriminant's
9478 -- expression is not a class-wide type unless the discriminant's
9479 -- designated type is also class-wide.
9481 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
9482 and then not Is_Class_Wide_Type
9483 (Designated_Type
(Etype
(Discr
)))
9484 and then Etype
(Discr_Expr
(J
)) /= Any_Type
9485 and then Is_Class_Wide_Type
9486 (Designated_Type
(Etype
(Discr_Expr
(J
))))
9488 Wrong_Type
(Discr_Expr
(J
), Etype
(Discr
));
9490 elsif Is_Access_Type
(Etype
(Discr
))
9491 and then not Is_Access_Constant
(Etype
(Discr
))
9492 and then Is_Access_Type
(Etype
(Discr_Expr
(J
)))
9493 and then Is_Access_Constant
(Etype
(Discr_Expr
(J
)))
9496 ("constraint for discriminant& must be access to variable",
9501 Next_Discriminant
(Discr
);
9505 end Build_Discriminant_Constraints
;
9507 ---------------------------------
9508 -- Build_Discriminated_Subtype --
9509 ---------------------------------
9511 procedure Build_Discriminated_Subtype
9515 Related_Nod
: Node_Id
;
9516 For_Access
: Boolean := False)
9518 Has_Discrs
: constant Boolean := Has_Discriminants
(T
);
9519 Constrained
: constant Boolean :=
9521 and then not Is_Empty_Elmt_List
(Elist
)
9522 and then not Is_Class_Wide_Type
(T
))
9523 or else Is_Constrained
(T
);
9526 if Ekind
(T
) = E_Record_Type
then
9528 Set_Ekind
(Def_Id
, E_Private_Subtype
);
9529 Set_Is_For_Access_Subtype
(Def_Id
, True);
9531 Set_Ekind
(Def_Id
, E_Record_Subtype
);
9534 -- Inherit preelaboration flag from base, for types for which it
9535 -- may have been set: records, private types, protected types.
9537 Set_Known_To_Have_Preelab_Init
9538 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
9540 elsif Ekind
(T
) = E_Task_Type
then
9541 Set_Ekind
(Def_Id
, E_Task_Subtype
);
9543 elsif Ekind
(T
) = E_Protected_Type
then
9544 Set_Ekind
(Def_Id
, E_Protected_Subtype
);
9545 Set_Known_To_Have_Preelab_Init
9546 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
9548 elsif Is_Private_Type
(T
) then
9549 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
9550 Set_Known_To_Have_Preelab_Init
9551 (Def_Id
, Known_To_Have_Preelab_Init
(T
));
9553 -- Private subtypes may have private dependents
9555 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
9557 elsif Is_Class_Wide_Type
(T
) then
9558 Set_Ekind
(Def_Id
, E_Class_Wide_Subtype
);
9561 -- Incomplete type. Attach subtype to list of dependents, to be
9562 -- completed with full view of parent type, unless is it the
9563 -- designated subtype of a record component within an init_proc.
9564 -- This last case arises for a component of an access type whose
9565 -- designated type is incomplete (e.g. a Taft Amendment type).
9566 -- The designated subtype is within an inner scope, and needs no
9567 -- elaboration, because only the access type is needed in the
9568 -- initialization procedure.
9570 Set_Ekind
(Def_Id
, Ekind
(T
));
9572 if For_Access
and then Within_Init_Proc
then
9575 Append_Elmt
(Def_Id
, Private_Dependents
(T
));
9579 Set_Etype
(Def_Id
, T
);
9580 Init_Size_Align
(Def_Id
);
9581 Set_Has_Discriminants
(Def_Id
, Has_Discrs
);
9582 Set_Is_Constrained
(Def_Id
, Constrained
);
9584 Set_First_Entity
(Def_Id
, First_Entity
(T
));
9585 Set_Last_Entity
(Def_Id
, Last_Entity
(T
));
9586 Set_Has_Implicit_Dereference
9587 (Def_Id
, Has_Implicit_Dereference
(T
));
9589 -- If the subtype is the completion of a private declaration, there may
9590 -- have been representation clauses for the partial view, and they must
9591 -- be preserved. Build_Derived_Type chains the inherited clauses with
9592 -- the ones appearing on the extension. If this comes from a subtype
9593 -- declaration, all clauses are inherited.
9595 if No
(First_Rep_Item
(Def_Id
)) then
9596 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
9599 if Is_Tagged_Type
(T
) then
9600 Set_Is_Tagged_Type
(Def_Id
);
9601 Set_No_Tagged_Streams_Pragma
(Def_Id
, No_Tagged_Streams_Pragma
(T
));
9602 Make_Class_Wide_Type
(Def_Id
);
9605 Set_Stored_Constraint
(Def_Id
, No_Elist
);
9608 Set_Discriminant_Constraint
(Def_Id
, Elist
);
9609 Set_Stored_Constraint_From_Discriminant_Constraint
(Def_Id
);
9612 if Is_Tagged_Type
(T
) then
9614 -- Ada 2005 (AI-251): In case of concurrent types we inherit the
9615 -- concurrent record type (which has the list of primitive
9618 if Ada_Version
>= Ada_2005
9619 and then Is_Concurrent_Type
(T
)
9621 Set_Corresponding_Record_Type
(Def_Id
,
9622 Corresponding_Record_Type
(T
));
9624 Set_Direct_Primitive_Operations
(Def_Id
,
9625 Direct_Primitive_Operations
(T
));
9628 Set_Is_Abstract_Type
(Def_Id
, Is_Abstract_Type
(T
));
9631 -- Subtypes introduced by component declarations do not need to be
9632 -- marked as delayed, and do not get freeze nodes, because the semantics
9633 -- verifies that the parents of the subtypes are frozen before the
9634 -- enclosing record is frozen.
9636 if not Is_Type
(Scope
(Def_Id
)) then
9637 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
9639 if Is_Private_Type
(T
)
9640 and then Present
(Full_View
(T
))
9642 Conditional_Delay
(Def_Id
, Full_View
(T
));
9644 Conditional_Delay
(Def_Id
, T
);
9648 if Is_Record_Type
(T
) then
9649 Set_Is_Limited_Record
(Def_Id
, Is_Limited_Record
(T
));
9652 and then not Is_Empty_Elmt_List
(Elist
)
9653 and then not For_Access
9655 Create_Constrained_Components
(Def_Id
, Related_Nod
, T
, Elist
);
9656 elsif not For_Access
then
9657 Set_Cloned_Subtype
(Def_Id
, T
);
9660 end Build_Discriminated_Subtype
;
9662 ---------------------------
9663 -- Build_Itype_Reference --
9664 ---------------------------
9666 procedure Build_Itype_Reference
9670 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(Nod
));
9673 -- Itype references are only created for use by the back-end
9675 if Inside_A_Generic
then
9678 Set_Itype
(IR
, Ityp
);
9679 Insert_After
(Nod
, IR
);
9681 end Build_Itype_Reference
;
9683 ------------------------
9684 -- Build_Scalar_Bound --
9685 ------------------------
9687 function Build_Scalar_Bound
9690 Der_T
: Entity_Id
) return Node_Id
9692 New_Bound
: Entity_Id
;
9695 -- Note: not clear why this is needed, how can the original bound
9696 -- be unanalyzed at this point? and if it is, what business do we
9697 -- have messing around with it? and why is the base type of the
9698 -- parent type the right type for the resolution. It probably is
9699 -- not. It is OK for the new bound we are creating, but not for
9700 -- the old one??? Still if it never happens, no problem.
9702 Analyze_And_Resolve
(Bound
, Base_Type
(Par_T
));
9704 if Nkind_In
(Bound
, N_Integer_Literal
, N_Real_Literal
) then
9705 New_Bound
:= New_Copy
(Bound
);
9706 Set_Etype
(New_Bound
, Der_T
);
9707 Set_Analyzed
(New_Bound
);
9709 elsif Is_Entity_Name
(Bound
) then
9710 New_Bound
:= OK_Convert_To
(Der_T
, New_Copy
(Bound
));
9712 -- The following is almost certainly wrong. What business do we have
9713 -- relocating a node (Bound) that is presumably still attached to
9714 -- the tree elsewhere???
9717 New_Bound
:= OK_Convert_To
(Der_T
, Relocate_Node
(Bound
));
9720 Set_Etype
(New_Bound
, Der_T
);
9722 end Build_Scalar_Bound
;
9724 --------------------------------
9725 -- Build_Underlying_Full_View --
9726 --------------------------------
9728 procedure Build_Underlying_Full_View
9733 Loc
: constant Source_Ptr
:= Sloc
(N
);
9734 Subt
: constant Entity_Id
:=
9735 Make_Defining_Identifier
9736 (Loc
, New_External_Name
(Chars
(Typ
), 'S'));
9743 procedure Set_Discriminant_Name
(Id
: Node_Id
);
9744 -- If the derived type has discriminants, they may rename discriminants
9745 -- of the parent. When building the full view of the parent, we need to
9746 -- recover the names of the original discriminants if the constraint is
9747 -- given by named associations.
9749 ---------------------------
9750 -- Set_Discriminant_Name --
9751 ---------------------------
9753 procedure Set_Discriminant_Name
(Id
: Node_Id
) is
9757 Set_Original_Discriminant
(Id
, Empty
);
9759 if Has_Discriminants
(Typ
) then
9760 Disc
:= First_Discriminant
(Typ
);
9761 while Present
(Disc
) loop
9762 if Chars
(Disc
) = Chars
(Id
)
9763 and then Present
(Corresponding_Discriminant
(Disc
))
9765 Set_Chars
(Id
, Chars
(Corresponding_Discriminant
(Disc
)));
9767 Next_Discriminant
(Disc
);
9770 end Set_Discriminant_Name
;
9772 -- Start of processing for Build_Underlying_Full_View
9775 if Nkind
(N
) = N_Full_Type_Declaration
then
9776 Constr
:= Constraint
(Subtype_Indication
(Type_Definition
(N
)));
9778 elsif Nkind
(N
) = N_Subtype_Declaration
then
9779 Constr
:= New_Copy_Tree
(Constraint
(Subtype_Indication
(N
)));
9781 elsif Nkind
(N
) = N_Component_Declaration
then
9784 (Constraint
(Subtype_Indication
(Component_Definition
(N
))));
9787 raise Program_Error
;
9790 C
:= First
(Constraints
(Constr
));
9791 while Present
(C
) loop
9792 if Nkind
(C
) = N_Discriminant_Association
then
9793 Id
:= First
(Selector_Names
(C
));
9794 while Present
(Id
) loop
9795 Set_Discriminant_Name
(Id
);
9804 Make_Subtype_Declaration
(Loc
,
9805 Defining_Identifier
=> Subt
,
9806 Subtype_Indication
=>
9807 Make_Subtype_Indication
(Loc
,
9808 Subtype_Mark
=> New_Occurrence_Of
(Par
, Loc
),
9809 Constraint
=> New_Copy_Tree
(Constr
)));
9811 -- If this is a component subtype for an outer itype, it is not
9812 -- a list member, so simply set the parent link for analysis: if
9813 -- the enclosing type does not need to be in a declarative list,
9814 -- neither do the components.
9816 if Is_List_Member
(N
)
9817 and then Nkind
(N
) /= N_Component_Declaration
9819 Insert_Before
(N
, Indic
);
9821 Set_Parent
(Indic
, Parent
(N
));
9825 Set_Underlying_Full_View
(Typ
, Full_View
(Subt
));
9826 end Build_Underlying_Full_View
;
9828 -------------------------------
9829 -- Check_Abstract_Overriding --
9830 -------------------------------
9832 procedure Check_Abstract_Overriding
(T
: Entity_Id
) is
9833 Alias_Subp
: Entity_Id
;
9839 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
);
9840 -- Ada 2012 (AI05-0030): Subprogram Subp overrides an interface routine
9841 -- which has pragma Implemented already set. Check whether Subp's entity
9842 -- kind conforms to the implementation kind of the overridden routine.
9844 procedure Check_Pragma_Implemented
9846 Iface_Subp
: Entity_Id
);
9847 -- Ada 2012 (AI05-0030): Subprogram Subp overrides interface routine
9848 -- Iface_Subp and both entities have pragma Implemented already set on
9849 -- them. Check whether the two implementation kinds are conforming.
9851 procedure Inherit_Pragma_Implemented
9853 Iface_Subp
: Entity_Id
);
9854 -- Ada 2012 (AI05-0030): Interface primitive Subp overrides interface
9855 -- subprogram Iface_Subp which has been marked by pragma Implemented.
9856 -- Propagate the implementation kind of Iface_Subp to Subp.
9858 ------------------------------
9859 -- Check_Pragma_Implemented --
9860 ------------------------------
9862 procedure Check_Pragma_Implemented
(Subp
: Entity_Id
) is
9863 Iface_Alias
: constant Entity_Id
:= Interface_Alias
(Subp
);
9864 Impl_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Alias
);
9865 Subp_Alias
: constant Entity_Id
:= Alias
(Subp
);
9866 Contr_Typ
: Entity_Id
;
9867 Impl_Subp
: Entity_Id
;
9870 -- Subp must have an alias since it is a hidden entity used to link
9871 -- an interface subprogram to its overriding counterpart.
9873 pragma Assert
(Present
(Subp_Alias
));
9875 -- Handle aliases to synchronized wrappers
9877 Impl_Subp
:= Subp_Alias
;
9879 if Is_Primitive_Wrapper
(Impl_Subp
) then
9880 Impl_Subp
:= Wrapped_Entity
(Impl_Subp
);
9883 -- Extract the type of the controlling formal
9885 Contr_Typ
:= Etype
(First_Formal
(Subp_Alias
));
9887 if Is_Concurrent_Record_Type
(Contr_Typ
) then
9888 Contr_Typ
:= Corresponding_Concurrent_Type
(Contr_Typ
);
9891 -- An interface subprogram whose implementation kind is By_Entry must
9892 -- be implemented by an entry.
9894 if Impl_Kind
= Name_By_Entry
9895 and then Ekind
(Impl_Subp
) /= E_Entry
9897 Error_Msg_Node_2
:= Iface_Alias
;
9899 ("type & must implement abstract subprogram & with an entry",
9900 Subp_Alias
, Contr_Typ
);
9902 elsif Impl_Kind
= Name_By_Protected_Procedure
then
9904 -- An interface subprogram whose implementation kind is By_
9905 -- Protected_Procedure cannot be implemented by a primitive
9906 -- procedure of a task type.
9908 if Ekind
(Contr_Typ
) /= E_Protected_Type
then
9909 Error_Msg_Node_2
:= Contr_Typ
;
9911 ("interface subprogram & cannot be implemented by a " &
9912 "primitive procedure of task type &", Subp_Alias
,
9915 -- An interface subprogram whose implementation kind is By_
9916 -- Protected_Procedure must be implemented by a procedure.
9918 elsif Ekind
(Impl_Subp
) /= E_Procedure
then
9919 Error_Msg_Node_2
:= Iface_Alias
;
9921 ("type & must implement abstract subprogram & with a " &
9922 "procedure", Subp_Alias
, Contr_Typ
);
9924 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
9925 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
9927 Error_Msg_Name_1
:= Impl_Kind
;
9929 ("overriding operation& must have synchronization%",
9933 -- If primitive has Optional synchronization, overriding operation
9934 -- must match if it has an explicit synchronization..
9936 elsif Present
(Get_Rep_Pragma
(Impl_Subp
, Name_Implemented
))
9937 and then Implementation_Kind
(Impl_Subp
) /= Impl_Kind
9939 Error_Msg_Name_1
:= Impl_Kind
;
9941 ("overriding operation& must have syncrhonization%",
9944 end Check_Pragma_Implemented
;
9946 ------------------------------
9947 -- Check_Pragma_Implemented --
9948 ------------------------------
9950 procedure Check_Pragma_Implemented
9952 Iface_Subp
: Entity_Id
)
9954 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
9955 Subp_Kind
: constant Name_Id
:= Implementation_Kind
(Subp
);
9958 -- Ada 2012 (AI05-0030): The implementation kinds of an overridden
9959 -- and overriding subprogram are different. In general this is an
9960 -- error except when the implementation kind of the overridden
9961 -- subprograms is By_Any or Optional.
9963 if Iface_Kind
/= Subp_Kind
9964 and then Iface_Kind
/= Name_By_Any
9965 and then Iface_Kind
/= Name_Optional
9967 if Iface_Kind
= Name_By_Entry
then
9969 ("incompatible implementation kind, overridden subprogram " &
9970 "is marked By_Entry", Subp
);
9973 ("incompatible implementation kind, overridden subprogram " &
9974 "is marked By_Protected_Procedure", Subp
);
9977 end Check_Pragma_Implemented
;
9979 --------------------------------
9980 -- Inherit_Pragma_Implemented --
9981 --------------------------------
9983 procedure Inherit_Pragma_Implemented
9985 Iface_Subp
: Entity_Id
)
9987 Iface_Kind
: constant Name_Id
:= Implementation_Kind
(Iface_Subp
);
9988 Loc
: constant Source_Ptr
:= Sloc
(Subp
);
9989 Impl_Prag
: Node_Id
;
9992 -- Since the implementation kind is stored as a representation item
9993 -- rather than a flag, create a pragma node.
9997 Chars
=> Name_Implemented
,
9998 Pragma_Argument_Associations
=> New_List
(
9999 Make_Pragma_Argument_Association
(Loc
,
10000 Expression
=> New_Occurrence_Of
(Subp
, Loc
)),
10002 Make_Pragma_Argument_Association
(Loc
,
10003 Expression
=> Make_Identifier
(Loc
, Iface_Kind
))));
10005 -- The pragma doesn't need to be analyzed because it is internally
10006 -- built. It is safe to directly register it as a rep item since we
10007 -- are only interested in the characters of the implementation kind.
10009 Record_Rep_Item
(Subp
, Impl_Prag
);
10010 end Inherit_Pragma_Implemented
;
10012 -- Start of processing for Check_Abstract_Overriding
10015 Op_List
:= Primitive_Operations
(T
);
10017 -- Loop to check primitive operations
10019 Elmt
:= First_Elmt
(Op_List
);
10020 while Present
(Elmt
) loop
10021 Subp
:= Node
(Elmt
);
10022 Alias_Subp
:= Alias
(Subp
);
10024 -- Inherited subprograms are identified by the fact that they do not
10025 -- come from source, and the associated source location is the
10026 -- location of the first subtype of the derived type.
10028 -- Ada 2005 (AI-228): Apply the rules of RM-3.9.3(6/2) for
10029 -- subprograms that "require overriding".
10031 -- Special exception, do not complain about failure to override the
10032 -- stream routines _Input and _Output, as well as the primitive
10033 -- operations used in dispatching selects since we always provide
10034 -- automatic overridings for these subprograms.
10036 -- Also ignore this rule for convention CIL since .NET libraries
10037 -- do bizarre things with interfaces???
10039 -- The partial view of T may have been a private extension, for
10040 -- which inherited functions dispatching on result are abstract.
10041 -- If the full view is a null extension, there is no need for
10042 -- overriding in Ada 2005, but wrappers need to be built for them
10043 -- (see exp_ch3, Build_Controlling_Function_Wrappers).
10045 if Is_Null_Extension
(T
)
10046 and then Has_Controlling_Result
(Subp
)
10047 and then Ada_Version
>= Ada_2005
10048 and then Present
(Alias_Subp
)
10049 and then not Comes_From_Source
(Subp
)
10050 and then not Is_Abstract_Subprogram
(Alias_Subp
)
10051 and then not Is_Access_Type
(Etype
(Subp
))
10055 -- Ada 2005 (AI-251): Internal entities of interfaces need no
10056 -- processing because this check is done with the aliased
10059 elsif Present
(Interface_Alias
(Subp
)) then
10062 elsif (Is_Abstract_Subprogram
(Subp
)
10063 or else Requires_Overriding
(Subp
)
10065 (Has_Controlling_Result
(Subp
)
10066 and then Present
(Alias_Subp
)
10067 and then not Comes_From_Source
(Subp
)
10068 and then Sloc
(Subp
) = Sloc
(First_Subtype
(T
))))
10069 and then not Is_TSS
(Subp
, TSS_Stream_Input
)
10070 and then not Is_TSS
(Subp
, TSS_Stream_Output
)
10071 and then not Is_Abstract_Type
(T
)
10072 and then Convention
(T
) /= Convention_CIL
10073 and then not Is_Predefined_Interface_Primitive
(Subp
)
10075 -- Ada 2005 (AI-251): Do not consider hidden entities associated
10076 -- with abstract interface types because the check will be done
10077 -- with the aliased entity (otherwise we generate a duplicated
10080 and then not Present
(Interface_Alias
(Subp
))
10082 if Present
(Alias_Subp
) then
10084 -- Only perform the check for a derived subprogram when the
10085 -- type has an explicit record extension. This avoids incorrect
10086 -- flagging of abstract subprograms for the case of a type
10087 -- without an extension that is derived from a formal type
10088 -- with a tagged actual (can occur within a private part).
10090 -- Ada 2005 (AI-391): In the case of an inherited function with
10091 -- a controlling result of the type, the rule does not apply if
10092 -- the type is a null extension (unless the parent function
10093 -- itself is abstract, in which case the function must still be
10094 -- be overridden). The expander will generate an overriding
10095 -- wrapper function calling the parent subprogram (see
10096 -- Exp_Ch3.Make_Controlling_Wrapper_Functions).
10098 Type_Def
:= Type_Definition
(Parent
(T
));
10100 if Nkind
(Type_Def
) = N_Derived_Type_Definition
10101 and then Present
(Record_Extension_Part
(Type_Def
))
10103 (Ada_Version
< Ada_2005
10104 or else not Is_Null_Extension
(T
)
10105 or else Ekind
(Subp
) = E_Procedure
10106 or else not Has_Controlling_Result
(Subp
)
10107 or else Is_Abstract_Subprogram
(Alias_Subp
)
10108 or else Requires_Overriding
(Subp
)
10109 or else Is_Access_Type
(Etype
(Subp
)))
10111 -- Avoid reporting error in case of abstract predefined
10112 -- primitive inherited from interface type because the
10113 -- body of internally generated predefined primitives
10114 -- of tagged types are generated later by Freeze_Type
10116 if Is_Interface
(Root_Type
(T
))
10117 and then Is_Abstract_Subprogram
(Subp
)
10118 and then Is_Predefined_Dispatching_Operation
(Subp
)
10119 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
10123 -- A null extension is not obliged to override an inherited
10124 -- procedure subject to pragma Extensions_Visible with value
10125 -- False and at least one controlling OUT parameter
10126 -- (SPARK RM 6.1.7(6)).
10128 elsif Is_Null_Extension
(T
)
10129 and then Is_EVF_Procedure
(Subp
)
10135 ("type must be declared abstract or & overridden",
10138 -- Traverse the whole chain of aliased subprograms to
10139 -- complete the error notification. This is especially
10140 -- useful for traceability of the chain of entities when
10141 -- the subprogram corresponds with an interface
10142 -- subprogram (which may be defined in another package).
10144 if Present
(Alias_Subp
) then
10150 while Present
(Alias
(E
)) loop
10152 -- Avoid reporting redundant errors on entities
10153 -- inherited from interfaces
10155 if Sloc
(E
) /= Sloc
(T
) then
10156 Error_Msg_Sloc
:= Sloc
(E
);
10158 ("\& has been inherited #", T
, Subp
);
10164 Error_Msg_Sloc
:= Sloc
(E
);
10166 -- AI05-0068: report if there is an overriding
10167 -- non-abstract subprogram that is invisible.
10170 and then not Is_Abstract_Subprogram
(E
)
10173 ("\& subprogram# is not visible",
10176 -- Clarify the case where a non-null extension must
10177 -- override inherited procedure subject to pragma
10178 -- Extensions_Visible with value False and at least
10179 -- one controlling OUT param.
10181 elsif Is_EVF_Procedure
(E
) then
10183 ("\& # is subject to Extensions_Visible False",
10188 ("\& has been inherited from subprogram #",
10195 -- Ada 2005 (AI-345): Protected or task type implementing
10196 -- abstract interfaces.
10198 elsif Is_Concurrent_Record_Type
(T
)
10199 and then Present
(Interfaces
(T
))
10201 -- There is no need to check here RM 9.4(11.9/3) since we
10202 -- are processing the corresponding record type and the
10203 -- mode of the overriding subprograms was verified by
10204 -- Check_Conformance when the corresponding concurrent
10205 -- type declaration was analyzed.
10208 ("interface subprogram & must be overridden", T
, Subp
);
10210 -- Examine primitive operations of synchronized type to find
10211 -- homonyms that have the wrong profile.
10217 Prim
:= First_Entity
(Corresponding_Concurrent_Type
(T
));
10218 while Present
(Prim
) loop
10219 if Chars
(Prim
) = Chars
(Subp
) then
10221 ("profile is not type conformant with prefixed "
10222 & "view profile of inherited operation&",
10226 Next_Entity
(Prim
);
10232 Error_Msg_Node_2
:= T
;
10234 ("abstract subprogram& not allowed for type&", Subp
);
10236 -- Also post unconditional warning on the type (unconditional
10237 -- so that if there are more than one of these cases, we get
10238 -- them all, and not just the first one).
10240 Error_Msg_Node_2
:= Subp
;
10241 Error_Msg_N
("nonabstract type& has abstract subprogram&!", T
);
10244 -- A subprogram subject to pragma Extensions_Visible with value
10245 -- "True" cannot override a subprogram subject to the same pragma
10246 -- with value "False" (SPARK RM 6.1.7(5)).
10248 elsif Extensions_Visible_Status
(Subp
) = Extensions_Visible_True
10249 and then Present
(Overridden_Operation
(Subp
))
10250 and then Extensions_Visible_Status
(Overridden_Operation
(Subp
)) =
10251 Extensions_Visible_False
10253 Error_Msg_Sloc
:= Sloc
(Overridden_Operation
(Subp
));
10255 ("subprogram & with Extensions_Visible True cannot override "
10256 & "subprogram # with Extensions_Visible False", Subp
);
10259 -- Ada 2012 (AI05-0030): Perform checks related to pragma Implemented
10261 -- Subp is an expander-generated procedure which maps an interface
10262 -- alias to a protected wrapper. The interface alias is flagged by
10263 -- pragma Implemented. Ensure that Subp is a procedure when the
10264 -- implementation kind is By_Protected_Procedure or an entry when
10267 if Ada_Version
>= Ada_2012
10268 and then Is_Hidden
(Subp
)
10269 and then Present
(Interface_Alias
(Subp
))
10270 and then Has_Rep_Pragma
(Interface_Alias
(Subp
), Name_Implemented
)
10272 Check_Pragma_Implemented
(Subp
);
10275 -- Subp is an interface primitive which overrides another interface
10276 -- primitive marked with pragma Implemented.
10278 if Ada_Version
>= Ada_2012
10279 and then Present
(Overridden_Operation
(Subp
))
10280 and then Has_Rep_Pragma
10281 (Overridden_Operation
(Subp
), Name_Implemented
)
10283 -- If the overriding routine is also marked by Implemented, check
10284 -- that the two implementation kinds are conforming.
10286 if Has_Rep_Pragma
(Subp
, Name_Implemented
) then
10287 Check_Pragma_Implemented
10289 Iface_Subp
=> Overridden_Operation
(Subp
));
10291 -- Otherwise the overriding routine inherits the implementation
10292 -- kind from the overridden subprogram.
10295 Inherit_Pragma_Implemented
10297 Iface_Subp
=> Overridden_Operation
(Subp
));
10301 -- If the operation is a wrapper for a synchronized primitive, it
10302 -- may be called indirectly through a dispatching select. We assume
10303 -- that it will be referenced elsewhere indirectly, and suppress
10304 -- warnings about an unused entity.
10306 if Is_Primitive_Wrapper
(Subp
)
10307 and then Present
(Wrapped_Entity
(Subp
))
10309 Set_Referenced
(Wrapped_Entity
(Subp
));
10314 end Check_Abstract_Overriding
;
10316 ------------------------------------------------
10317 -- Check_Access_Discriminant_Requires_Limited --
10318 ------------------------------------------------
10320 procedure Check_Access_Discriminant_Requires_Limited
10325 -- A discriminant_specification for an access discriminant shall appear
10326 -- only in the declaration for a task or protected type, or for a type
10327 -- with the reserved word 'limited' in its definition or in one of its
10328 -- ancestors (RM 3.7(10)).
10330 -- AI-0063: The proper condition is that type must be immutably limited,
10331 -- or else be a partial view.
10333 if Nkind
(Discriminant_Type
(D
)) = N_Access_Definition
then
10334 if Is_Limited_View
(Current_Scope
)
10336 (Nkind
(Parent
(Current_Scope
)) = N_Private_Type_Declaration
10337 and then Limited_Present
(Parent
(Current_Scope
)))
10343 ("access discriminants allowed only for limited types", Loc
);
10346 end Check_Access_Discriminant_Requires_Limited
;
10348 -----------------------------------
10349 -- Check_Aliased_Component_Types --
10350 -----------------------------------
10352 procedure Check_Aliased_Component_Types
(T
: Entity_Id
) is
10356 -- ??? Also need to check components of record extensions, but not
10357 -- components of protected types (which are always limited).
10359 -- Ada 2005: AI-363 relaxes this rule, to allow heap objects of such
10360 -- types to be unconstrained. This is safe because it is illegal to
10361 -- create access subtypes to such types with explicit discriminant
10364 if not Is_Limited_Type
(T
) then
10365 if Ekind
(T
) = E_Record_Type
then
10366 C
:= First_Component
(T
);
10367 while Present
(C
) loop
10369 and then Has_Discriminants
(Etype
(C
))
10370 and then not Is_Constrained
(Etype
(C
))
10371 and then not In_Instance_Body
10372 and then Ada_Version
< Ada_2005
10375 ("aliased component must be constrained (RM 3.6(11))",
10379 Next_Component
(C
);
10382 elsif Ekind
(T
) = E_Array_Type
then
10383 if Has_Aliased_Components
(T
)
10384 and then Has_Discriminants
(Component_Type
(T
))
10385 and then not Is_Constrained
(Component_Type
(T
))
10386 and then not In_Instance_Body
10387 and then Ada_Version
< Ada_2005
10390 ("aliased component type must be constrained (RM 3.6(11))",
10395 end Check_Aliased_Component_Types
;
10397 ---------------------------------------
10398 -- Check_Anonymous_Access_Components --
10399 ---------------------------------------
10401 procedure Check_Anonymous_Access_Components
10402 (Typ_Decl
: Node_Id
;
10405 Comp_List
: Node_Id
)
10407 Loc
: constant Source_Ptr
:= Sloc
(Typ_Decl
);
10408 Anon_Access
: Entity_Id
;
10411 Comp_Def
: Node_Id
;
10413 Type_Def
: Node_Id
;
10415 procedure Build_Incomplete_Type_Declaration
;
10416 -- If the record type contains components that include an access to the
10417 -- current record, then create an incomplete type declaration for the
10418 -- record, to be used as the designated type of the anonymous access.
10419 -- This is done only once, and only if there is no previous partial
10420 -- view of the type.
10422 function Designates_T
(Subt
: Node_Id
) return Boolean;
10423 -- Check whether a node designates the enclosing record type, or 'Class
10426 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean;
10427 -- Check whether an access definition includes a reference to
10428 -- the enclosing record type. The reference can be a subtype mark
10429 -- in the access definition itself, a 'Class attribute reference, or
10430 -- recursively a reference appearing in a parameter specification
10431 -- or result definition of an access_to_subprogram definition.
10433 --------------------------------------
10434 -- Build_Incomplete_Type_Declaration --
10435 --------------------------------------
10437 procedure Build_Incomplete_Type_Declaration
is
10442 -- Is_Tagged indicates whether the type is tagged. It is tagged if
10443 -- it's "is new ... with record" or else "is tagged record ...".
10445 Is_Tagged
: constant Boolean :=
10446 (Nkind
(Type_Definition
(Typ_Decl
)) = N_Derived_Type_Definition
10448 Present
(Record_Extension_Part
(Type_Definition
(Typ_Decl
))))
10450 (Nkind
(Type_Definition
(Typ_Decl
)) = N_Record_Definition
10451 and then Tagged_Present
(Type_Definition
(Typ_Decl
)));
10454 -- If there is a previous partial view, no need to create a new one
10455 -- If the partial view, given by Prev, is incomplete, If Prev is
10456 -- a private declaration, full declaration is flagged accordingly.
10458 if Prev
/= Typ
then
10460 Make_Class_Wide_Type
(Prev
);
10461 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Prev
));
10462 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
10467 elsif Has_Private_Declaration
(Typ
) then
10469 -- If we refer to T'Class inside T, and T is the completion of a
10470 -- private type, then make sure the class-wide type exists.
10473 Make_Class_Wide_Type
(Typ
);
10478 -- If there was a previous anonymous access type, the incomplete
10479 -- type declaration will have been created already.
10481 elsif Present
(Current_Entity
(Typ
))
10482 and then Ekind
(Current_Entity
(Typ
)) = E_Incomplete_Type
10483 and then Full_View
(Current_Entity
(Typ
)) = Typ
10486 and then Comes_From_Source
(Current_Entity
(Typ
))
10487 and then not Is_Tagged_Type
(Current_Entity
(Typ
))
10489 Make_Class_Wide_Type
(Typ
);
10491 ("incomplete view of tagged type should be declared tagged??",
10492 Parent
(Current_Entity
(Typ
)));
10497 Inc_T
:= Make_Defining_Identifier
(Loc
, Chars
(Typ
));
10498 Decl
:= Make_Incomplete_Type_Declaration
(Loc
, Inc_T
);
10500 -- Type has already been inserted into the current scope. Remove
10501 -- it, and add incomplete declaration for type, so that subsequent
10502 -- anonymous access types can use it. The entity is unchained from
10503 -- the homonym list and from immediate visibility. After analysis,
10504 -- the entity in the incomplete declaration becomes immediately
10505 -- visible in the record declaration that follows.
10507 H
:= Current_Entity
(Typ
);
10510 Set_Name_Entity_Id
(Chars
(Typ
), Homonym
(Typ
));
10513 and then Homonym
(H
) /= Typ
10515 H
:= Homonym
(Typ
);
10518 Set_Homonym
(H
, Homonym
(Typ
));
10521 Insert_Before
(Typ_Decl
, Decl
);
10523 Set_Full_View
(Inc_T
, Typ
);
10527 -- Create a common class-wide type for both views, and set the
10528 -- Etype of the class-wide type to the full view.
10530 Make_Class_Wide_Type
(Inc_T
);
10531 Set_Class_Wide_Type
(Typ
, Class_Wide_Type
(Inc_T
));
10532 Set_Etype
(Class_Wide_Type
(Typ
), Typ
);
10535 end Build_Incomplete_Type_Declaration
;
10541 function Designates_T
(Subt
: Node_Id
) return Boolean is
10542 Type_Id
: constant Name_Id
:= Chars
(Typ
);
10544 function Names_T
(Nam
: Node_Id
) return Boolean;
10545 -- The record type has not been introduced in the current scope
10546 -- yet, so we must examine the name of the type itself, either
10547 -- an identifier T, or an expanded name of the form P.T, where
10548 -- P denotes the current scope.
10554 function Names_T
(Nam
: Node_Id
) return Boolean is
10556 if Nkind
(Nam
) = N_Identifier
then
10557 return Chars
(Nam
) = Type_Id
;
10559 elsif Nkind
(Nam
) = N_Selected_Component
then
10560 if Chars
(Selector_Name
(Nam
)) = Type_Id
then
10561 if Nkind
(Prefix
(Nam
)) = N_Identifier
then
10562 return Chars
(Prefix
(Nam
)) = Chars
(Current_Scope
);
10564 elsif Nkind
(Prefix
(Nam
)) = N_Selected_Component
then
10565 return Chars
(Selector_Name
(Prefix
(Nam
))) =
10566 Chars
(Current_Scope
);
10580 -- Start of processing for Designates_T
10583 if Nkind
(Subt
) = N_Identifier
then
10584 return Chars
(Subt
) = Type_Id
;
10586 -- Reference can be through an expanded name which has not been
10587 -- analyzed yet, and which designates enclosing scopes.
10589 elsif Nkind
(Subt
) = N_Selected_Component
then
10590 if Names_T
(Subt
) then
10593 -- Otherwise it must denote an entity that is already visible.
10594 -- The access definition may name a subtype of the enclosing
10595 -- type, if there is a previous incomplete declaration for it.
10598 Find_Selected_Component
(Subt
);
10600 Is_Entity_Name
(Subt
)
10601 and then Scope
(Entity
(Subt
)) = Current_Scope
10603 (Chars
(Base_Type
(Entity
(Subt
))) = Type_Id
10605 (Is_Class_Wide_Type
(Entity
(Subt
))
10607 Chars
(Etype
(Base_Type
(Entity
(Subt
)))) =
10611 -- A reference to the current type may appear as the prefix of
10612 -- a 'Class attribute.
10614 elsif Nkind
(Subt
) = N_Attribute_Reference
10615 and then Attribute_Name
(Subt
) = Name_Class
10617 return Names_T
(Prefix
(Subt
));
10628 function Mentions_T
(Acc_Def
: Node_Id
) return Boolean is
10629 Param_Spec
: Node_Id
;
10631 Acc_Subprg
: constant Node_Id
:=
10632 Access_To_Subprogram_Definition
(Acc_Def
);
10635 if No
(Acc_Subprg
) then
10636 return Designates_T
(Subtype_Mark
(Acc_Def
));
10639 -- Component is an access_to_subprogram: examine its formals,
10640 -- and result definition in the case of an access_to_function.
10642 Param_Spec
:= First
(Parameter_Specifications
(Acc_Subprg
));
10643 while Present
(Param_Spec
) loop
10644 if Nkind
(Parameter_Type
(Param_Spec
)) = N_Access_Definition
10645 and then Mentions_T
(Parameter_Type
(Param_Spec
))
10649 elsif Designates_T
(Parameter_Type
(Param_Spec
)) then
10656 if Nkind
(Acc_Subprg
) = N_Access_Function_Definition
then
10657 if Nkind
(Result_Definition
(Acc_Subprg
)) =
10658 N_Access_Definition
10660 return Mentions_T
(Result_Definition
(Acc_Subprg
));
10662 return Designates_T
(Result_Definition
(Acc_Subprg
));
10669 -- Start of processing for Check_Anonymous_Access_Components
10672 if No
(Comp_List
) then
10676 Comp
:= First
(Component_Items
(Comp_List
));
10677 while Present
(Comp
) loop
10678 if Nkind
(Comp
) = N_Component_Declaration
10680 (Access_Definition
(Component_Definition
(Comp
)))
10682 Mentions_T
(Access_Definition
(Component_Definition
(Comp
)))
10684 Comp_Def
:= Component_Definition
(Comp
);
10686 Access_To_Subprogram_Definition
(Access_Definition
(Comp_Def
));
10688 Build_Incomplete_Type_Declaration
;
10689 Anon_Access
:= Make_Temporary
(Loc
, 'S');
10691 -- Create a declaration for the anonymous access type: either
10692 -- an access_to_object or an access_to_subprogram.
10694 if Present
(Acc_Def
) then
10695 if Nkind
(Acc_Def
) = N_Access_Function_Definition
then
10697 Make_Access_Function_Definition
(Loc
,
10698 Parameter_Specifications
=>
10699 Parameter_Specifications
(Acc_Def
),
10700 Result_Definition
=> Result_Definition
(Acc_Def
));
10703 Make_Access_Procedure_Definition
(Loc
,
10704 Parameter_Specifications
=>
10705 Parameter_Specifications
(Acc_Def
));
10710 Make_Access_To_Object_Definition
(Loc
,
10711 Subtype_Indication
=>
10713 (Subtype_Mark
(Access_Definition
(Comp_Def
))));
10715 Set_Constant_Present
10716 (Type_Def
, Constant_Present
(Access_Definition
(Comp_Def
)));
10718 (Type_Def
, All_Present
(Access_Definition
(Comp_Def
)));
10721 Set_Null_Exclusion_Present
10723 Null_Exclusion_Present
(Access_Definition
(Comp_Def
)));
10726 Make_Full_Type_Declaration
(Loc
,
10727 Defining_Identifier
=> Anon_Access
,
10728 Type_Definition
=> Type_Def
);
10730 Insert_Before
(Typ_Decl
, Decl
);
10733 -- If an access to subprogram, create the extra formals
10735 if Present
(Acc_Def
) then
10736 Create_Extra_Formals
(Designated_Type
(Anon_Access
));
10738 -- If an access to object, preserve entity of designated type,
10739 -- for ASIS use, before rewriting the component definition.
10746 Desig
:= Entity
(Subtype_Indication
(Type_Def
));
10748 -- If the access definition is to the current record,
10749 -- the visible entity at this point is an incomplete
10750 -- type. Retrieve the full view to simplify ASIS queries
10752 if Ekind
(Desig
) = E_Incomplete_Type
then
10753 Desig
:= Full_View
(Desig
);
10757 (Subtype_Mark
(Access_Definition
(Comp_Def
)), Desig
);
10762 Make_Component_Definition
(Loc
,
10763 Subtype_Indication
=>
10764 New_Occurrence_Of
(Anon_Access
, Loc
)));
10766 if Ekind
(Designated_Type
(Anon_Access
)) = E_Subprogram_Type
then
10767 Set_Ekind
(Anon_Access
, E_Anonymous_Access_Subprogram_Type
);
10769 Set_Ekind
(Anon_Access
, E_Anonymous_Access_Type
);
10772 Set_Is_Local_Anonymous_Access
(Anon_Access
);
10778 if Present
(Variant_Part
(Comp_List
)) then
10782 V
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
10783 while Present
(V
) loop
10784 Check_Anonymous_Access_Components
10785 (Typ_Decl
, Typ
, Prev
, Component_List
(V
));
10786 Next_Non_Pragma
(V
);
10790 end Check_Anonymous_Access_Components
;
10792 ----------------------
10793 -- Check_Completion --
10794 ----------------------
10796 procedure Check_Completion
(Body_Id
: Node_Id
:= Empty
) is
10799 procedure Post_Error
;
10800 -- Post error message for lack of completion for entity E
10806 procedure Post_Error
is
10808 procedure Missing_Body
;
10809 -- Output missing body message
10815 procedure Missing_Body
is
10817 -- Spec is in same unit, so we can post on spec
10819 if In_Same_Source_Unit
(Body_Id
, E
) then
10820 Error_Msg_N
("missing body for &", E
);
10822 -- Spec is in a separate unit, so we have to post on the body
10825 Error_Msg_NE
("missing body for & declared#!", Body_Id
, E
);
10829 -- Start of processing for Post_Error
10832 if not Comes_From_Source
(E
) then
10834 if Ekind_In
(E
, E_Task_Type
, E_Protected_Type
) then
10836 -- It may be an anonymous protected type created for a
10837 -- single variable. Post error on variable, if present.
10843 Var
:= First_Entity
(Current_Scope
);
10844 while Present
(Var
) loop
10845 exit when Etype
(Var
) = E
10846 and then Comes_From_Source
(Var
);
10851 if Present
(Var
) then
10858 -- If a generated entity has no completion, then either previous
10859 -- semantic errors have disabled the expansion phase, or else we had
10860 -- missing subunits, or else we are compiling without expansion,
10861 -- or else something is very wrong.
10863 if not Comes_From_Source
(E
) then
10865 (Serious_Errors_Detected
> 0
10866 or else Configurable_Run_Time_Violations
> 0
10867 or else Subunits_Missing
10868 or else not Expander_Active
);
10871 -- Here for source entity
10874 -- Here if no body to post the error message, so we post the error
10875 -- on the declaration that has no completion. This is not really
10876 -- the right place to post it, think about this later ???
10878 if No
(Body_Id
) then
10879 if Is_Type
(E
) then
10881 ("missing full declaration for }", Parent
(E
), E
);
10883 Error_Msg_NE
("missing body for &", Parent
(E
), E
);
10886 -- Package body has no completion for a declaration that appears
10887 -- in the corresponding spec. Post error on the body, with a
10888 -- reference to the non-completed declaration.
10891 Error_Msg_Sloc
:= Sloc
(E
);
10893 if Is_Type
(E
) then
10894 Error_Msg_NE
("missing full declaration for }!", Body_Id
, E
);
10896 elsif Is_Overloadable
(E
)
10897 and then Current_Entity_In_Scope
(E
) /= E
10899 -- It may be that the completion is mistyped and appears as
10900 -- a distinct overloading of the entity.
10903 Candidate
: constant Entity_Id
:=
10904 Current_Entity_In_Scope
(E
);
10905 Decl
: constant Node_Id
:=
10906 Unit_Declaration_Node
(Candidate
);
10909 if Is_Overloadable
(Candidate
)
10910 and then Ekind
(Candidate
) = Ekind
(E
)
10911 and then Nkind
(Decl
) = N_Subprogram_Body
10912 and then Acts_As_Spec
(Decl
)
10914 Check_Type_Conformant
(Candidate
, E
);
10930 Pack_Id
: constant Entity_Id
:= Current_Scope
;
10932 -- Start of processing for Check_Completion
10935 E
:= First_Entity
(Pack_Id
);
10936 while Present
(E
) loop
10937 if Is_Intrinsic_Subprogram
(E
) then
10940 -- A Ghost entity declared in a non-Ghost package does not force the
10941 -- need for a body (SPARK RM 6.9(11)).
10943 elsif not Is_Ghost_Entity
(Pack_Id
) and then Is_Ghost_Entity
(E
) then
10946 -- The following situation requires special handling: a child unit
10947 -- that appears in the context clause of the body of its parent:
10949 -- procedure Parent.Child (...);
10951 -- with Parent.Child;
10952 -- package body Parent is
10954 -- Here Parent.Child appears as a local entity, but should not be
10955 -- flagged as requiring completion, because it is a compilation
10958 -- Ignore missing completion for a subprogram that does not come from
10959 -- source (including the _Call primitive operation of RAS types,
10960 -- which has to have the flag Comes_From_Source for other purposes):
10961 -- we assume that the expander will provide the missing completion.
10962 -- In case of previous errors, other expansion actions that provide
10963 -- bodies for null procedures with not be invoked, so inhibit message
10966 -- Note that E_Operator is not in the list that follows, because
10967 -- this kind is reserved for predefined operators, that are
10968 -- intrinsic and do not need completion.
10970 elsif Ekind_In
(E
, E_Function
,
10972 E_Generic_Function
,
10973 E_Generic_Procedure
)
10975 if Has_Completion
(E
) then
10978 elsif Is_Subprogram
(E
) and then Is_Abstract_Subprogram
(E
) then
10981 elsif Is_Subprogram
(E
)
10982 and then (not Comes_From_Source
(E
)
10983 or else Chars
(E
) = Name_uCall
)
10988 Nkind
(Parent
(Unit_Declaration_Node
(E
))) = N_Compilation_Unit
10992 elsif Nkind
(Parent
(E
)) = N_Procedure_Specification
10993 and then Null_Present
(Parent
(E
))
10994 and then Serious_Errors_Detected
> 0
11002 elsif Is_Entry
(E
) then
11003 if not Has_Completion
(E
) and then
11004 (Ekind
(Scope
(E
)) = E_Protected_Object
11005 or else Ekind
(Scope
(E
)) = E_Protected_Type
)
11010 elsif Is_Package_Or_Generic_Package
(E
) then
11011 if Unit_Requires_Body
(E
) then
11012 if not Has_Completion
(E
)
11013 and then Nkind
(Parent
(Unit_Declaration_Node
(E
))) /=
11019 elsif not Is_Child_Unit
(E
) then
11020 May_Need_Implicit_Body
(E
);
11023 -- A formal incomplete type (Ada 2012) does not require a completion;
11024 -- other incomplete type declarations do.
11026 elsif Ekind
(E
) = E_Incomplete_Type
11027 and then No
(Underlying_Type
(E
))
11028 and then not Is_Generic_Type
(E
)
11032 elsif Ekind_In
(E
, E_Task_Type
, E_Protected_Type
)
11033 and then not Has_Completion
(E
)
11037 -- A single task declared in the current scope is a constant, verify
11038 -- that the body of its anonymous type is in the same scope. If the
11039 -- task is defined elsewhere, this may be a renaming declaration for
11040 -- which no completion is needed.
11042 elsif Ekind
(E
) = E_Constant
11043 and then Ekind
(Etype
(E
)) = E_Task_Type
11044 and then not Has_Completion
(Etype
(E
))
11045 and then Scope
(Etype
(E
)) = Current_Scope
11049 elsif Ekind
(E
) = E_Protected_Object
11050 and then not Has_Completion
(Etype
(E
))
11054 elsif Ekind
(E
) = E_Record_Type
then
11055 if Is_Tagged_Type
(E
) then
11056 Check_Abstract_Overriding
(E
);
11057 Check_Conventions
(E
);
11060 Check_Aliased_Component_Types
(E
);
11062 elsif Ekind
(E
) = E_Array_Type
then
11063 Check_Aliased_Component_Types
(E
);
11069 end Check_Completion
;
11071 ------------------------------------
11072 -- Check_CPP_Type_Has_No_Defaults --
11073 ------------------------------------
11075 procedure Check_CPP_Type_Has_No_Defaults
(T
: Entity_Id
) is
11076 Tdef
: constant Node_Id
:= Type_Definition
(Declaration_Node
(T
));
11081 -- Obtain the component list
11083 if Nkind
(Tdef
) = N_Record_Definition
then
11084 Clist
:= Component_List
(Tdef
);
11085 else pragma Assert
(Nkind
(Tdef
) = N_Derived_Type_Definition
);
11086 Clist
:= Component_List
(Record_Extension_Part
(Tdef
));
11089 -- Check all components to ensure no default expressions
11091 if Present
(Clist
) then
11092 Comp
:= First
(Component_Items
(Clist
));
11093 while Present
(Comp
) loop
11094 if Present
(Expression
(Comp
)) then
11096 ("component of imported 'C'P'P type cannot have "
11097 & "default expression", Expression
(Comp
));
11103 end Check_CPP_Type_Has_No_Defaults
;
11105 ----------------------------
11106 -- Check_Delta_Expression --
11107 ----------------------------
11109 procedure Check_Delta_Expression
(E
: Node_Id
) is
11111 if not (Is_Real_Type
(Etype
(E
))) then
11112 Wrong_Type
(E
, Any_Real
);
11114 elsif not Is_OK_Static_Expression
(E
) then
11115 Flag_Non_Static_Expr
11116 ("non-static expression used for delta value!", E
);
11118 elsif not UR_Is_Positive
(Expr_Value_R
(E
)) then
11119 Error_Msg_N
("delta expression must be positive", E
);
11125 -- If any of above errors occurred, then replace the incorrect
11126 -- expression by the real 0.1, which should prevent further errors.
11129 Make_Real_Literal
(Sloc
(E
), Ureal_Tenth
));
11130 Analyze_And_Resolve
(E
, Standard_Float
);
11131 end Check_Delta_Expression
;
11133 -----------------------------
11134 -- Check_Digits_Expression --
11135 -----------------------------
11137 procedure Check_Digits_Expression
(E
: Node_Id
) is
11139 if not (Is_Integer_Type
(Etype
(E
))) then
11140 Wrong_Type
(E
, Any_Integer
);
11142 elsif not Is_OK_Static_Expression
(E
) then
11143 Flag_Non_Static_Expr
11144 ("non-static expression used for digits value!", E
);
11146 elsif Expr_Value
(E
) <= 0 then
11147 Error_Msg_N
("digits value must be greater than zero", E
);
11153 -- If any of above errors occurred, then replace the incorrect
11154 -- expression by the integer 1, which should prevent further errors.
11156 Rewrite
(E
, Make_Integer_Literal
(Sloc
(E
), 1));
11157 Analyze_And_Resolve
(E
, Standard_Integer
);
11159 end Check_Digits_Expression
;
11161 --------------------------
11162 -- Check_Initialization --
11163 --------------------------
11165 procedure Check_Initialization
(T
: Entity_Id
; Exp
: Node_Id
) is
11167 -- Special processing for limited types
11169 if Is_Limited_Type
(T
)
11170 and then not In_Instance
11171 and then not In_Inlined_Body
11173 if not OK_For_Limited_Init
(T
, Exp
) then
11175 -- In GNAT mode, this is just a warning, to allow it to be evilly
11176 -- turned off. Otherwise it is a real error.
11180 ("??cannot initialize entities of limited type!", Exp
);
11182 elsif Ada_Version
< Ada_2005
then
11184 -- The side effect removal machinery may generate illegal Ada
11185 -- code to avoid the usage of access types and 'reference in
11186 -- SPARK mode. Since this is legal code with respect to theorem
11187 -- proving, do not emit the error.
11190 and then Nkind
(Exp
) = N_Function_Call
11191 and then Nkind
(Parent
(Exp
)) = N_Object_Declaration
11192 and then not Comes_From_Source
11193 (Defining_Identifier
(Parent
(Exp
)))
11199 ("cannot initialize entities of limited type", Exp
);
11200 Explain_Limited_Type
(T
, Exp
);
11204 -- Specialize error message according to kind of illegal
11205 -- initial expression.
11207 if Nkind
(Exp
) = N_Type_Conversion
11208 and then Nkind
(Expression
(Exp
)) = N_Function_Call
11211 ("illegal context for call"
11212 & " to function with limited result", Exp
);
11216 ("initialization of limited object requires aggregate "
11217 & "or function call", Exp
);
11223 -- In gnatc or gnatprove mode, make sure set Do_Range_Check flag gets
11224 -- set unless we can be sure that no range check is required.
11226 if (GNATprove_Mode
or not Expander_Active
)
11227 and then Is_Scalar_Type
(T
)
11228 and then not Is_In_Range
(Exp
, T
, Assume_Valid
=> True)
11230 Set_Do_Range_Check
(Exp
);
11232 end Check_Initialization
;
11234 ----------------------
11235 -- Check_Interfaces --
11236 ----------------------
11238 procedure Check_Interfaces
(N
: Node_Id
; Def
: Node_Id
) is
11239 Parent_Type
: constant Entity_Id
:= Etype
(Defining_Identifier
(N
));
11242 Iface_Def
: Node_Id
;
11243 Iface_Typ
: Entity_Id
;
11244 Parent_Node
: Node_Id
;
11246 Is_Task
: Boolean := False;
11247 -- Set True if parent type or any progenitor is a task interface
11249 Is_Protected
: Boolean := False;
11250 -- Set True if parent type or any progenitor is a protected interface
11252 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
);
11253 -- Check that a progenitor is compatible with declaration. If an error
11254 -- message is output, it is posted on Error_Node.
11260 procedure Check_Ifaces
(Iface_Def
: Node_Id
; Error_Node
: Node_Id
) is
11261 Iface_Id
: constant Entity_Id
:=
11262 Defining_Identifier
(Parent
(Iface_Def
));
11263 Type_Def
: Node_Id
;
11266 if Nkind
(N
) = N_Private_Extension_Declaration
then
11269 Type_Def
:= Type_Definition
(N
);
11272 if Is_Task_Interface
(Iface_Id
) then
11275 elsif Is_Protected_Interface
(Iface_Id
) then
11276 Is_Protected
:= True;
11279 if Is_Synchronized_Interface
(Iface_Id
) then
11281 -- A consequence of 3.9.4 (6/2) and 7.3 (7.2/2) is that a private
11282 -- extension derived from a synchronized interface must explicitly
11283 -- be declared synchronized, because the full view will be a
11284 -- synchronized type.
11286 if Nkind
(N
) = N_Private_Extension_Declaration
then
11287 if not Synchronized_Present
(N
) then
11289 ("private extension of& must be explicitly synchronized",
11293 -- However, by 3.9.4(16/2), a full type that is a record extension
11294 -- is never allowed to derive from a synchronized interface (note
11295 -- that interfaces must be excluded from this check, because those
11296 -- are represented by derived type definitions in some cases).
11298 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
11299 and then not Interface_Present
(Type_Definition
(N
))
11301 Error_Msg_N
("record extension cannot derive from synchronized "
11302 & "interface", Error_Node
);
11306 -- Check that the characteristics of the progenitor are compatible
11307 -- with the explicit qualifier in the declaration.
11308 -- The check only applies to qualifiers that come from source.
11309 -- Limited_Present also appears in the declaration of corresponding
11310 -- records, and the check does not apply to them.
11312 if Limited_Present
(Type_Def
)
11314 Is_Concurrent_Record_Type
(Defining_Identifier
(N
))
11316 if Is_Limited_Interface
(Parent_Type
)
11317 and then not Is_Limited_Interface
(Iface_Id
)
11320 ("progenitor & must be limited interface",
11321 Error_Node
, Iface_Id
);
11324 (Task_Present
(Iface_Def
)
11325 or else Protected_Present
(Iface_Def
)
11326 or else Synchronized_Present
(Iface_Def
))
11327 and then Nkind
(N
) /= N_Private_Extension_Declaration
11328 and then not Error_Posted
(N
)
11331 ("progenitor & must be limited interface",
11332 Error_Node
, Iface_Id
);
11335 -- Protected interfaces can only inherit from limited, synchronized
11336 -- or protected interfaces.
11338 elsif Nkind
(N
) = N_Full_Type_Declaration
11339 and then Protected_Present
(Type_Def
)
11341 if Limited_Present
(Iface_Def
)
11342 or else Synchronized_Present
(Iface_Def
)
11343 or else Protected_Present
(Iface_Def
)
11347 elsif Task_Present
(Iface_Def
) then
11348 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
11349 & "from task interface", Error_Node
);
11352 Error_Msg_N
("(Ada 2005) protected interface cannot inherit "
11353 & "from non-limited interface", Error_Node
);
11356 -- Ada 2005 (AI-345): Synchronized interfaces can only inherit from
11357 -- limited and synchronized.
11359 elsif Synchronized_Present
(Type_Def
) then
11360 if Limited_Present
(Iface_Def
)
11361 or else Synchronized_Present
(Iface_Def
)
11365 elsif Protected_Present
(Iface_Def
)
11366 and then Nkind
(N
) /= N_Private_Extension_Declaration
11368 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
11369 & "from protected interface", Error_Node
);
11371 elsif Task_Present
(Iface_Def
)
11372 and then Nkind
(N
) /= N_Private_Extension_Declaration
11374 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
11375 & "from task interface", Error_Node
);
11377 elsif not Is_Limited_Interface
(Iface_Id
) then
11378 Error_Msg_N
("(Ada 2005) synchronized interface cannot inherit "
11379 & "from non-limited interface", Error_Node
);
11382 -- Ada 2005 (AI-345): Task interfaces can only inherit from limited,
11383 -- synchronized or task interfaces.
11385 elsif Nkind
(N
) = N_Full_Type_Declaration
11386 and then Task_Present
(Type_Def
)
11388 if Limited_Present
(Iface_Def
)
11389 or else Synchronized_Present
(Iface_Def
)
11390 or else Task_Present
(Iface_Def
)
11394 elsif Protected_Present
(Iface_Def
) then
11395 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
11396 & "protected interface", Error_Node
);
11399 Error_Msg_N
("(Ada 2005) task interface cannot inherit from "
11400 & "non-limited interface", Error_Node
);
11405 -- Start of processing for Check_Interfaces
11408 if Is_Interface
(Parent_Type
) then
11409 if Is_Task_Interface
(Parent_Type
) then
11412 elsif Is_Protected_Interface
(Parent_Type
) then
11413 Is_Protected
:= True;
11417 if Nkind
(N
) = N_Private_Extension_Declaration
then
11419 -- Check that progenitors are compatible with declaration
11421 Iface
:= First
(Interface_List
(Def
));
11422 while Present
(Iface
) loop
11423 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
11425 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
11426 Iface_Def
:= Type_Definition
(Parent_Node
);
11428 if not Is_Interface
(Iface_Typ
) then
11429 Diagnose_Interface
(Iface
, Iface_Typ
);
11431 Check_Ifaces
(Iface_Def
, Iface
);
11437 if Is_Task
and Is_Protected
then
11439 ("type cannot derive from task and protected interface", N
);
11445 -- Full type declaration of derived type.
11446 -- Check compatibility with parent if it is interface type
11448 if Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
11449 and then Is_Interface
(Parent_Type
)
11451 Parent_Node
:= Parent
(Parent_Type
);
11453 -- More detailed checks for interface varieties
11456 (Iface_Def
=> Type_Definition
(Parent_Node
),
11457 Error_Node
=> Subtype_Indication
(Type_Definition
(N
)));
11460 Iface
:= First
(Interface_List
(Def
));
11461 while Present
(Iface
) loop
11462 Iface_Typ
:= Find_Type_Of_Subtype_Indic
(Iface
);
11464 Parent_Node
:= Parent
(Base_Type
(Iface_Typ
));
11465 Iface_Def
:= Type_Definition
(Parent_Node
);
11467 if not Is_Interface
(Iface_Typ
) then
11468 Diagnose_Interface
(Iface
, Iface_Typ
);
11471 -- "The declaration of a specific descendant of an interface
11472 -- type freezes the interface type" RM 13.14
11474 Freeze_Before
(N
, Iface_Typ
);
11475 Check_Ifaces
(Iface_Def
, Error_Node
=> Iface
);
11481 if Is_Task
and Is_Protected
then
11483 ("type cannot derive from task and protected interface", N
);
11485 end Check_Interfaces
;
11487 ------------------------------------
11488 -- Check_Or_Process_Discriminants --
11489 ------------------------------------
11491 -- If an incomplete or private type declaration was already given for the
11492 -- type, the discriminants may have already been processed if they were
11493 -- present on the incomplete declaration. In this case a full conformance
11494 -- check has been performed in Find_Type_Name, and we then recheck here
11495 -- some properties that can't be checked on the partial view alone.
11496 -- Otherwise we call Process_Discriminants.
11498 procedure Check_Or_Process_Discriminants
11501 Prev
: Entity_Id
:= Empty
)
11504 if Has_Discriminants
(T
) then
11506 -- Discriminants are already set on T if they were already present
11507 -- on the partial view. Make them visible to component declarations.
11511 -- Discriminant on T (full view) referencing expr on partial view
11513 Prev_D
: Entity_Id
;
11514 -- Entity of corresponding discriminant on partial view
11517 -- Discriminant specification for full view, expression is
11518 -- the syntactic copy on full view (which has been checked for
11519 -- conformance with partial view), only used here to post error
11523 D
:= First_Discriminant
(T
);
11524 New_D
:= First
(Discriminant_Specifications
(N
));
11525 while Present
(D
) loop
11526 Prev_D
:= Current_Entity
(D
);
11527 Set_Current_Entity
(D
);
11528 Set_Is_Immediately_Visible
(D
);
11529 Set_Homonym
(D
, Prev_D
);
11531 -- Handle the case where there is an untagged partial view and
11532 -- the full view is tagged: must disallow discriminants with
11533 -- defaults, unless compiling for Ada 2012, which allows a
11534 -- limited tagged type to have defaulted discriminants (see
11535 -- AI05-0214). However, suppress error here if it was already
11536 -- reported on the default expression of the partial view.
11538 if Is_Tagged_Type
(T
)
11539 and then Present
(Expression
(Parent
(D
)))
11540 and then (not Is_Limited_Type
(Current_Scope
)
11541 or else Ada_Version
< Ada_2012
)
11542 and then not Error_Posted
(Expression
(Parent
(D
)))
11544 if Ada_Version
>= Ada_2012
then
11546 ("discriminants of nonlimited tagged type cannot have "
11548 Expression
(New_D
));
11551 ("discriminants of tagged type cannot have defaults",
11552 Expression
(New_D
));
11556 -- Ada 2005 (AI-230): Access discriminant allowed in
11557 -- non-limited record types.
11559 if Ada_Version
< Ada_2005
then
11561 -- This restriction gets applied to the full type here. It
11562 -- has already been applied earlier to the partial view.
11564 Check_Access_Discriminant_Requires_Limited
(Parent
(D
), N
);
11567 Next_Discriminant
(D
);
11572 elsif Present
(Discriminant_Specifications
(N
)) then
11573 Process_Discriminants
(N
, Prev
);
11575 end Check_Or_Process_Discriminants
;
11577 ----------------------
11578 -- Check_Real_Bound --
11579 ----------------------
11581 procedure Check_Real_Bound
(Bound
: Node_Id
) is
11583 if not Is_Real_Type
(Etype
(Bound
)) then
11585 ("bound in real type definition must be of real type", Bound
);
11587 elsif not Is_OK_Static_Expression
(Bound
) then
11588 Flag_Non_Static_Expr
11589 ("non-static expression used for real type bound!", Bound
);
11596 (Bound
, Make_Real_Literal
(Sloc
(Bound
), Ureal_0
));
11598 Resolve
(Bound
, Standard_Float
);
11599 end Check_Real_Bound
;
11601 ------------------------------
11602 -- Complete_Private_Subtype --
11603 ------------------------------
11605 procedure Complete_Private_Subtype
11608 Full_Base
: Entity_Id
;
11609 Related_Nod
: Node_Id
)
11611 Save_Next_Entity
: Entity_Id
;
11612 Save_Homonym
: Entity_Id
;
11615 -- Set semantic attributes for (implicit) private subtype completion.
11616 -- If the full type has no discriminants, then it is a copy of the
11617 -- full view of the base. Otherwise, it is a subtype of the base with
11618 -- a possible discriminant constraint. Save and restore the original
11619 -- Next_Entity field of full to ensure that the calls to Copy_Node do
11620 -- not corrupt the entity chain.
11622 -- Note that the type of the full view is the same entity as the type
11623 -- of the partial view. In this fashion, the subtype has access to the
11624 -- correct view of the parent.
11626 Save_Next_Entity
:= Next_Entity
(Full
);
11627 Save_Homonym
:= Homonym
(Priv
);
11629 case Ekind
(Full_Base
) is
11630 when E_Record_Type |
11636 Copy_Node
(Priv
, Full
);
11638 Set_Has_Discriminants
11639 (Full
, Has_Discriminants
(Full_Base
));
11640 Set_Has_Unknown_Discriminants
11641 (Full
, Has_Unknown_Discriminants
(Full_Base
));
11642 Set_First_Entity
(Full
, First_Entity
(Full_Base
));
11643 Set_Last_Entity
(Full
, Last_Entity
(Full_Base
));
11645 -- If the underlying base type is constrained, we know that the
11646 -- full view of the subtype is constrained as well (the converse
11647 -- is not necessarily true).
11649 if Is_Constrained
(Full_Base
) then
11650 Set_Is_Constrained
(Full
);
11654 Copy_Node
(Full_Base
, Full
);
11656 Set_Chars
(Full
, Chars
(Priv
));
11657 Conditional_Delay
(Full
, Priv
);
11658 Set_Sloc
(Full
, Sloc
(Priv
));
11661 Set_Next_Entity
(Full
, Save_Next_Entity
);
11662 Set_Homonym
(Full
, Save_Homonym
);
11663 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
11665 -- Set common attributes for all subtypes: kind, convention, etc.
11667 Set_Ekind
(Full
, Subtype_Kind
(Ekind
(Full_Base
)));
11668 Set_Convention
(Full
, Convention
(Full_Base
));
11670 -- The Etype of the full view is inconsistent. Gigi needs to see the
11671 -- structural full view, which is what the current scheme gives: the
11672 -- Etype of the full view is the etype of the full base. However, if the
11673 -- full base is a derived type, the full view then looks like a subtype
11674 -- of the parent, not a subtype of the full base. If instead we write:
11676 -- Set_Etype (Full, Full_Base);
11678 -- then we get inconsistencies in the front-end (confusion between
11679 -- views). Several outstanding bugs are related to this ???
11681 Set_Is_First_Subtype
(Full
, False);
11682 Set_Scope
(Full
, Scope
(Priv
));
11683 Set_Size_Info
(Full
, Full_Base
);
11684 Set_RM_Size
(Full
, RM_Size
(Full_Base
));
11685 Set_Is_Itype
(Full
);
11687 -- A subtype of a private-type-without-discriminants, whose full-view
11688 -- has discriminants with default expressions, is not constrained.
11690 if not Has_Discriminants
(Priv
) then
11691 Set_Is_Constrained
(Full
, Is_Constrained
(Full_Base
));
11693 if Has_Discriminants
(Full_Base
) then
11694 Set_Discriminant_Constraint
11695 (Full
, Discriminant_Constraint
(Full_Base
));
11697 -- The partial view may have been indefinite, the full view
11700 Set_Has_Unknown_Discriminants
11701 (Full
, Has_Unknown_Discriminants
(Full_Base
));
11705 Set_First_Rep_Item
(Full
, First_Rep_Item
(Full_Base
));
11706 Set_Depends_On_Private
(Full
, Has_Private_Component
(Full
));
11708 -- Freeze the private subtype entity if its parent is delayed, and not
11709 -- already frozen. We skip this processing if the type is an anonymous
11710 -- subtype of a record component, or is the corresponding record of a
11711 -- protected type, since these are processed when the enclosing type
11714 if not Is_Type
(Scope
(Full
)) then
11715 Set_Has_Delayed_Freeze
(Full
,
11716 Has_Delayed_Freeze
(Full_Base
)
11717 and then (not Is_Frozen
(Full_Base
)));
11720 Set_Freeze_Node
(Full
, Empty
);
11721 Set_Is_Frozen
(Full
, False);
11722 Set_Full_View
(Priv
, Full
);
11724 if Has_Discriminants
(Full
) then
11725 Set_Stored_Constraint_From_Discriminant_Constraint
(Full
);
11726 Set_Stored_Constraint
(Priv
, Stored_Constraint
(Full
));
11728 if Has_Unknown_Discriminants
(Full
) then
11729 Set_Discriminant_Constraint
(Full
, No_Elist
);
11733 if Ekind
(Full_Base
) = E_Record_Type
11734 and then Has_Discriminants
(Full_Base
)
11735 and then Has_Discriminants
(Priv
) -- might not, if errors
11736 and then not Has_Unknown_Discriminants
(Priv
)
11737 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(Priv
))
11739 Create_Constrained_Components
11740 (Full
, Related_Nod
, Full_Base
, Discriminant_Constraint
(Priv
));
11742 -- If the full base is itself derived from private, build a congruent
11743 -- subtype of its underlying type, for use by the back end. For a
11744 -- constrained record component, the declaration cannot be placed on
11745 -- the component list, but it must nevertheless be built an analyzed, to
11746 -- supply enough information for Gigi to compute the size of component.
11748 elsif Ekind
(Full_Base
) in Private_Kind
11749 and then Is_Derived_Type
(Full_Base
)
11750 and then Has_Discriminants
(Full_Base
)
11751 and then (Ekind
(Current_Scope
) /= E_Record_Subtype
)
11753 if not Is_Itype
(Priv
)
11755 Nkind
(Subtype_Indication
(Parent
(Priv
))) = N_Subtype_Indication
11757 Build_Underlying_Full_View
11758 (Parent
(Priv
), Full
, Etype
(Full_Base
));
11760 elsif Nkind
(Related_Nod
) = N_Component_Declaration
then
11761 Build_Underlying_Full_View
(Related_Nod
, Full
, Etype
(Full_Base
));
11764 elsif Is_Record_Type
(Full_Base
) then
11766 -- Show Full is simply a renaming of Full_Base
11768 Set_Cloned_Subtype
(Full
, Full_Base
);
11771 -- It is unsafe to share the bounds of a scalar type, because the Itype
11772 -- is elaborated on demand, and if a bound is non-static then different
11773 -- orders of elaboration in different units will lead to different
11774 -- external symbols.
11776 if Is_Scalar_Type
(Full_Base
) then
11777 Set_Scalar_Range
(Full
,
11778 Make_Range
(Sloc
(Related_Nod
),
11780 Duplicate_Subexpr_No_Checks
(Type_Low_Bound
(Full_Base
)),
11782 Duplicate_Subexpr_No_Checks
(Type_High_Bound
(Full_Base
))));
11784 -- This completion inherits the bounds of the full parent, but if
11785 -- the parent is an unconstrained floating point type, so is the
11788 if Is_Floating_Point_Type
(Full_Base
) then
11789 Set_Includes_Infinities
11790 (Scalar_Range
(Full
), Has_Infinities
(Full_Base
));
11794 -- ??? It seems that a lot of fields are missing that should be copied
11795 -- from Full_Base to Full. Here are some that are introduced in a
11796 -- non-disruptive way but a cleanup is necessary.
11798 if Is_Tagged_Type
(Full_Base
) then
11799 Set_Is_Tagged_Type
(Full
);
11800 Set_Direct_Primitive_Operations
11801 (Full
, Direct_Primitive_Operations
(Full_Base
));
11802 Set_No_Tagged_Streams_Pragma
11803 (Full
, No_Tagged_Streams_Pragma
(Full_Base
));
11805 -- Inherit class_wide type of full_base in case the partial view was
11806 -- not tagged. Otherwise it has already been created when the private
11807 -- subtype was analyzed.
11809 if No
(Class_Wide_Type
(Full
)) then
11810 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Full_Base
));
11813 -- If this is a subtype of a protected or task type, constrain its
11814 -- corresponding record, unless this is a subtype without constraints,
11815 -- i.e. a simple renaming as with an actual subtype in an instance.
11817 elsif Is_Concurrent_Type
(Full_Base
) then
11818 if Has_Discriminants
(Full
)
11819 and then Present
(Corresponding_Record_Type
(Full_Base
))
11821 not Is_Empty_Elmt_List
(Discriminant_Constraint
(Full
))
11823 Set_Corresponding_Record_Type
(Full
,
11824 Constrain_Corresponding_Record
11825 (Full
, Corresponding_Record_Type
(Full_Base
), Related_Nod
));
11828 Set_Corresponding_Record_Type
(Full
,
11829 Corresponding_Record_Type
(Full_Base
));
11833 -- Link rep item chain, and also setting of Has_Predicates from private
11834 -- subtype to full subtype, since we will need these on the full subtype
11835 -- to create the predicate function. Note that the full subtype may
11836 -- already have rep items, inherited from the full view of the base
11837 -- type, so we must be sure not to overwrite these entries.
11842 Next_Item
: Node_Id
;
11845 Item
:= First_Rep_Item
(Full
);
11847 -- If no existing rep items on full type, we can just link directly
11848 -- to the list of items on the private type, if any exist.. Same if
11849 -- the rep items are only those inherited from the base
11852 or else Nkind
(Item
) /= N_Aspect_Specification
11853 or else Entity
(Item
) = Full_Base
)
11854 and then Present
(First_Rep_Item
(Priv
))
11856 Set_First_Rep_Item
(Full
, First_Rep_Item
(Priv
));
11858 -- Otherwise, search to the end of items currently linked to the full
11859 -- subtype and append the private items to the end. However, if Priv
11860 -- and Full already have the same list of rep items, then the append
11861 -- is not done, as that would create a circularity.
11863 elsif Item
/= First_Rep_Item
(Priv
) then
11866 Next_Item
:= Next_Rep_Item
(Item
);
11867 exit when No
(Next_Item
);
11870 -- If the private view has aspect specifications, the full view
11871 -- inherits them. Since these aspects may already have been
11872 -- attached to the full view during derivation, do not append
11873 -- them if already present.
11875 if Item
= First_Rep_Item
(Priv
) then
11881 -- And link the private type items at the end of the chain
11884 Set_Next_Rep_Item
(Item
, First_Rep_Item
(Priv
));
11889 -- Make sure Has_Predicates is set on full type if it is set on the
11890 -- private type. Note that it may already be set on the full type and
11891 -- if so, we don't want to unset it. Similarly, propagate information
11892 -- about delayed aspects, because the corresponding pragmas must be
11893 -- analyzed when one of the views is frozen. This last step is needed
11894 -- in particular when the full type is a scalar type for which an
11895 -- anonymous base type is constructed.
11897 if Has_Predicates
(Priv
) then
11898 Set_Has_Predicates
(Full
);
11901 if Has_Delayed_Aspects
(Priv
) then
11902 Set_Has_Delayed_Aspects
(Full
);
11904 end Complete_Private_Subtype
;
11906 ----------------------------
11907 -- Constant_Redeclaration --
11908 ----------------------------
11910 procedure Constant_Redeclaration
11915 Prev
: constant Entity_Id
:= Current_Entity_In_Scope
(Id
);
11916 Obj_Def
: constant Node_Id
:= Object_Definition
(N
);
11919 procedure Check_Possible_Deferred_Completion
11920 (Prev_Id
: Entity_Id
;
11921 Prev_Obj_Def
: Node_Id
;
11922 Curr_Obj_Def
: Node_Id
);
11923 -- Determine whether the two object definitions describe the partial
11924 -- and the full view of a constrained deferred constant. Generate
11925 -- a subtype for the full view and verify that it statically matches
11926 -- the subtype of the partial view.
11928 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
);
11929 -- If deferred constant is an access type initialized with an allocator,
11930 -- check whether there is an illegal recursion in the definition,
11931 -- through a default value of some record subcomponent. This is normally
11932 -- detected when generating init procs, but requires this additional
11933 -- mechanism when expansion is disabled.
11935 ----------------------------------------
11936 -- Check_Possible_Deferred_Completion --
11937 ----------------------------------------
11939 procedure Check_Possible_Deferred_Completion
11940 (Prev_Id
: Entity_Id
;
11941 Prev_Obj_Def
: Node_Id
;
11942 Curr_Obj_Def
: Node_Id
)
11945 if Nkind
(Prev_Obj_Def
) = N_Subtype_Indication
11946 and then Present
(Constraint
(Prev_Obj_Def
))
11947 and then Nkind
(Curr_Obj_Def
) = N_Subtype_Indication
11948 and then Present
(Constraint
(Curr_Obj_Def
))
11951 Loc
: constant Source_Ptr
:= Sloc
(N
);
11952 Def_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
11953 Decl
: constant Node_Id
:=
11954 Make_Subtype_Declaration
(Loc
,
11955 Defining_Identifier
=> Def_Id
,
11956 Subtype_Indication
=>
11957 Relocate_Node
(Curr_Obj_Def
));
11960 Insert_Before_And_Analyze
(N
, Decl
);
11961 Set_Etype
(Id
, Def_Id
);
11963 if not Subtypes_Statically_Match
(Etype
(Prev_Id
), Def_Id
) then
11964 Error_Msg_Sloc
:= Sloc
(Prev_Id
);
11965 Error_Msg_N
("subtype does not statically match deferred "
11966 & "declaration #", N
);
11970 end Check_Possible_Deferred_Completion
;
11972 ---------------------------------
11973 -- Check_Recursive_Declaration --
11974 ---------------------------------
11976 procedure Check_Recursive_Declaration
(Typ
: Entity_Id
) is
11980 if Is_Record_Type
(Typ
) then
11981 Comp
:= First_Component
(Typ
);
11982 while Present
(Comp
) loop
11983 if Comes_From_Source
(Comp
) then
11984 if Present
(Expression
(Parent
(Comp
)))
11985 and then Is_Entity_Name
(Expression
(Parent
(Comp
)))
11986 and then Entity
(Expression
(Parent
(Comp
))) = Prev
11988 Error_Msg_Sloc
:= Sloc
(Parent
(Comp
));
11990 ("illegal circularity with declaration for & #",
11994 elsif Is_Record_Type
(Etype
(Comp
)) then
11995 Check_Recursive_Declaration
(Etype
(Comp
));
11999 Next_Component
(Comp
);
12002 end Check_Recursive_Declaration
;
12004 -- Start of processing for Constant_Redeclaration
12007 if Nkind
(Parent
(Prev
)) = N_Object_Declaration
then
12008 if Nkind
(Object_Definition
12009 (Parent
(Prev
))) = N_Subtype_Indication
12011 -- Find type of new declaration. The constraints of the two
12012 -- views must match statically, but there is no point in
12013 -- creating an itype for the full view.
12015 if Nkind
(Obj_Def
) = N_Subtype_Indication
then
12016 Find_Type
(Subtype_Mark
(Obj_Def
));
12017 New_T
:= Entity
(Subtype_Mark
(Obj_Def
));
12020 Find_Type
(Obj_Def
);
12021 New_T
:= Entity
(Obj_Def
);
12027 -- The full view may impose a constraint, even if the partial
12028 -- view does not, so construct the subtype.
12030 New_T
:= Find_Type_Of_Object
(Obj_Def
, N
);
12035 -- Current declaration is illegal, diagnosed below in Enter_Name
12041 -- If previous full declaration or a renaming declaration exists, or if
12042 -- a homograph is present, let Enter_Name handle it, either with an
12043 -- error or with the removal of an overridden implicit subprogram.
12044 -- The previous one is a full declaration if it has an expression
12045 -- (which in the case of an aggregate is indicated by the Init flag).
12047 if Ekind
(Prev
) /= E_Constant
12048 or else Nkind
(Parent
(Prev
)) = N_Object_Renaming_Declaration
12049 or else Present
(Expression
(Parent
(Prev
)))
12050 or else Has_Init_Expression
(Parent
(Prev
))
12051 or else Present
(Full_View
(Prev
))
12055 -- Verify that types of both declarations match, or else that both types
12056 -- are anonymous access types whose designated subtypes statically match
12057 -- (as allowed in Ada 2005 by AI-385).
12059 elsif Base_Type
(Etype
(Prev
)) /= Base_Type
(New_T
)
12061 (Ekind
(Etype
(Prev
)) /= E_Anonymous_Access_Type
12062 or else Ekind
(Etype
(New_T
)) /= E_Anonymous_Access_Type
12063 or else Is_Access_Constant
(Etype
(New_T
)) /=
12064 Is_Access_Constant
(Etype
(Prev
))
12065 or else Can_Never_Be_Null
(Etype
(New_T
)) /=
12066 Can_Never_Be_Null
(Etype
(Prev
))
12067 or else Null_Exclusion_Present
(Parent
(Prev
)) /=
12068 Null_Exclusion_Present
(Parent
(Id
))
12069 or else not Subtypes_Statically_Match
12070 (Designated_Type
(Etype
(Prev
)),
12071 Designated_Type
(Etype
(New_T
))))
12073 Error_Msg_Sloc
:= Sloc
(Prev
);
12074 Error_Msg_N
("type does not match declaration#", N
);
12075 Set_Full_View
(Prev
, Id
);
12076 Set_Etype
(Id
, Any_Type
);
12078 -- A deferred constant whose type is an anonymous array is always
12079 -- illegal (unless imported). A detailed error message might be
12080 -- helpful for Ada beginners.
12082 if Nkind
(Object_Definition
(Parent
(Prev
)))
12083 = N_Constrained_Array_Definition
12084 and then Nkind
(Object_Definition
(N
))
12085 = N_Constrained_Array_Definition
12087 Error_Msg_N
("\each anonymous array is a distinct type", N
);
12088 Error_Msg_N
("a deferred constant must have a named type",
12089 Object_Definition
(Parent
(Prev
)));
12093 Null_Exclusion_Present
(Parent
(Prev
))
12094 and then not Null_Exclusion_Present
(N
)
12096 Error_Msg_Sloc
:= Sloc
(Prev
);
12097 Error_Msg_N
("null-exclusion does not match declaration#", N
);
12098 Set_Full_View
(Prev
, Id
);
12099 Set_Etype
(Id
, Any_Type
);
12101 -- If so, process the full constant declaration
12104 -- RM 7.4 (6): If the subtype defined by the subtype_indication in
12105 -- the deferred declaration is constrained, then the subtype defined
12106 -- by the subtype_indication in the full declaration shall match it
12109 Check_Possible_Deferred_Completion
12111 Prev_Obj_Def
=> Object_Definition
(Parent
(Prev
)),
12112 Curr_Obj_Def
=> Obj_Def
);
12114 Set_Full_View
(Prev
, Id
);
12115 Set_Is_Public
(Id
, Is_Public
(Prev
));
12116 Set_Is_Internal
(Id
);
12117 Append_Entity
(Id
, Current_Scope
);
12119 -- Check ALIASED present if present before (RM 7.4(7))
12121 if Is_Aliased
(Prev
)
12122 and then not Aliased_Present
(N
)
12124 Error_Msg_Sloc
:= Sloc
(Prev
);
12125 Error_Msg_N
("ALIASED required (see declaration #)", N
);
12128 -- Check that placement is in private part and that the incomplete
12129 -- declaration appeared in the visible part.
12131 if Ekind
(Current_Scope
) = E_Package
12132 and then not In_Private_Part
(Current_Scope
)
12134 Error_Msg_Sloc
:= Sloc
(Prev
);
12136 ("full constant for declaration # must be in private part", N
);
12138 elsif Ekind
(Current_Scope
) = E_Package
12140 List_Containing
(Parent
(Prev
)) /=
12141 Visible_Declarations
(Package_Specification
(Current_Scope
))
12144 ("deferred constant must be declared in visible part",
12148 if Is_Access_Type
(T
)
12149 and then Nkind
(Expression
(N
)) = N_Allocator
12151 Check_Recursive_Declaration
(Designated_Type
(T
));
12154 -- A deferred constant is a visible entity. If type has invariants,
12155 -- verify that the initial value satisfies them.
12157 if Has_Invariants
(T
) and then Present
(Invariant_Procedure
(T
)) then
12159 Make_Invariant_Call
(New_Occurrence_Of
(Prev
, Sloc
(N
))));
12162 end Constant_Redeclaration
;
12164 ----------------------
12165 -- Constrain_Access --
12166 ----------------------
12168 procedure Constrain_Access
12169 (Def_Id
: in out Entity_Id
;
12171 Related_Nod
: Node_Id
)
12173 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
12174 Desig_Type
: constant Entity_Id
:= Designated_Type
(T
);
12175 Desig_Subtype
: Entity_Id
:= Create_Itype
(E_Void
, Related_Nod
);
12176 Constraint_OK
: Boolean := True;
12179 if Is_Array_Type
(Desig_Type
) then
12180 Constrain_Array
(Desig_Subtype
, S
, Related_Nod
, Def_Id
, 'P');
12182 elsif (Is_Record_Type
(Desig_Type
)
12183 or else Is_Incomplete_Or_Private_Type
(Desig_Type
))
12184 and then not Is_Constrained
(Desig_Type
)
12186 -- ??? The following code is a temporary bypass to ignore a
12187 -- discriminant constraint on access type if it is constraining
12188 -- the current record. Avoid creating the implicit subtype of the
12189 -- record we are currently compiling since right now, we cannot
12190 -- handle these. For now, just return the access type itself.
12192 if Desig_Type
= Current_Scope
12193 and then No
(Def_Id
)
12195 Set_Ekind
(Desig_Subtype
, E_Record_Subtype
);
12196 Def_Id
:= Entity
(Subtype_Mark
(S
));
12198 -- This call added to ensure that the constraint is analyzed
12199 -- (needed for a B test). Note that we still return early from
12200 -- this procedure to avoid recursive processing. ???
12202 Constrain_Discriminated_Type
12203 (Desig_Subtype
, S
, Related_Nod
, For_Access
=> True);
12207 -- Enforce rule that the constraint is illegal if there is an
12208 -- unconstrained view of the designated type. This means that the
12209 -- partial view (either a private type declaration or a derivation
12210 -- from a private type) has no discriminants. (Defect Report
12211 -- 8652/0008, Technical Corrigendum 1, checked by ACATS B371001).
12213 -- Rule updated for Ada 2005: The private type is said to have
12214 -- a constrained partial view, given that objects of the type
12215 -- can be declared. Furthermore, the rule applies to all access
12216 -- types, unlike the rule concerning default discriminants (see
12219 if (Ekind
(T
) = E_General_Access_Type
or else Ada_Version
>= Ada_2005
)
12220 and then Has_Private_Declaration
(Desig_Type
)
12221 and then In_Open_Scopes
(Scope
(Desig_Type
))
12222 and then Has_Discriminants
(Desig_Type
)
12225 Pack
: constant Node_Id
:=
12226 Unit_Declaration_Node
(Scope
(Desig_Type
));
12231 if Nkind
(Pack
) = N_Package_Declaration
then
12232 Decls
:= Visible_Declarations
(Specification
(Pack
));
12233 Decl
:= First
(Decls
);
12234 while Present
(Decl
) loop
12235 if (Nkind
(Decl
) = N_Private_Type_Declaration
12236 and then Chars
(Defining_Identifier
(Decl
)) =
12237 Chars
(Desig_Type
))
12240 (Nkind
(Decl
) = N_Full_Type_Declaration
12242 Chars
(Defining_Identifier
(Decl
)) =
12244 and then Is_Derived_Type
(Desig_Type
)
12246 Has_Private_Declaration
(Etype
(Desig_Type
)))
12248 if No
(Discriminant_Specifications
(Decl
)) then
12250 ("cannot constrain access type if designated "
12251 & "type has constrained partial view", S
);
12263 Constrain_Discriminated_Type
(Desig_Subtype
, S
, Related_Nod
,
12264 For_Access
=> True);
12266 elsif Is_Concurrent_Type
(Desig_Type
)
12267 and then not Is_Constrained
(Desig_Type
)
12269 Constrain_Concurrent
(Desig_Subtype
, S
, Related_Nod
, Desig_Type
, ' ');
12272 Error_Msg_N
("invalid constraint on access type", S
);
12274 -- We simply ignore an invalid constraint
12276 Desig_Subtype
:= Desig_Type
;
12277 Constraint_OK
:= False;
12280 if No
(Def_Id
) then
12281 Def_Id
:= Create_Itype
(E_Access_Subtype
, Related_Nod
);
12283 Set_Ekind
(Def_Id
, E_Access_Subtype
);
12286 if Constraint_OK
then
12287 Set_Etype
(Def_Id
, Base_Type
(T
));
12289 if Is_Private_Type
(Desig_Type
) then
12290 Prepare_Private_Subtype_Completion
(Desig_Subtype
, Related_Nod
);
12293 Set_Etype
(Def_Id
, Any_Type
);
12296 Set_Size_Info
(Def_Id
, T
);
12297 Set_Is_Constrained
(Def_Id
, Constraint_OK
);
12298 Set_Directly_Designated_Type
(Def_Id
, Desig_Subtype
);
12299 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
12300 Set_Is_Access_Constant
(Def_Id
, Is_Access_Constant
(T
));
12302 Conditional_Delay
(Def_Id
, T
);
12304 -- AI-363 : Subtypes of general access types whose designated types have
12305 -- default discriminants are disallowed. In instances, the rule has to
12306 -- be checked against the actual, of which T is the subtype. In a
12307 -- generic body, the rule is checked assuming that the actual type has
12308 -- defaulted discriminants.
12310 if Ada_Version
>= Ada_2005
or else Warn_On_Ada_2005_Compatibility
then
12311 if Ekind
(Base_Type
(T
)) = E_General_Access_Type
12312 and then Has_Defaulted_Discriminants
(Desig_Type
)
12314 if Ada_Version
< Ada_2005
then
12316 ("access subtype of general access type would not " &
12317 "be allowed in Ada 2005?y?", S
);
12320 ("access subtype of general access type not allowed", S
);
12323 Error_Msg_N
("\discriminants have defaults", S
);
12325 elsif Is_Access_Type
(T
)
12326 and then Is_Generic_Type
(Desig_Type
)
12327 and then Has_Discriminants
(Desig_Type
)
12328 and then In_Package_Body
(Current_Scope
)
12330 if Ada_Version
< Ada_2005
then
12332 ("access subtype would not be allowed in generic body "
12333 & "in Ada 2005?y?", S
);
12336 ("access subtype not allowed in generic body", S
);
12340 ("\designated type is a discriminated formal", S
);
12343 end Constrain_Access
;
12345 ---------------------
12346 -- Constrain_Array --
12347 ---------------------
12349 procedure Constrain_Array
12350 (Def_Id
: in out Entity_Id
;
12352 Related_Nod
: Node_Id
;
12353 Related_Id
: Entity_Id
;
12354 Suffix
: Character)
12356 C
: constant Node_Id
:= Constraint
(SI
);
12357 Number_Of_Constraints
: Nat
:= 0;
12360 Constraint_OK
: Boolean := True;
12363 T
:= Entity
(Subtype_Mark
(SI
));
12365 if Is_Access_Type
(T
) then
12366 T
:= Designated_Type
(T
);
12369 -- If an index constraint follows a subtype mark in a subtype indication
12370 -- then the type or subtype denoted by the subtype mark must not already
12371 -- impose an index constraint. The subtype mark must denote either an
12372 -- unconstrained array type or an access type whose designated type
12373 -- is such an array type... (RM 3.6.1)
12375 if Is_Constrained
(T
) then
12376 Error_Msg_N
("array type is already constrained", Subtype_Mark
(SI
));
12377 Constraint_OK
:= False;
12380 S
:= First
(Constraints
(C
));
12381 while Present
(S
) loop
12382 Number_Of_Constraints
:= Number_Of_Constraints
+ 1;
12386 -- In either case, the index constraint must provide a discrete
12387 -- range for each index of the array type and the type of each
12388 -- discrete range must be the same as that of the corresponding
12389 -- index. (RM 3.6.1)
12391 if Number_Of_Constraints
/= Number_Dimensions
(T
) then
12392 Error_Msg_NE
("incorrect number of index constraints for }", C
, T
);
12393 Constraint_OK
:= False;
12396 S
:= First
(Constraints
(C
));
12397 Index
:= First_Index
(T
);
12400 -- Apply constraints to each index type
12402 for J
in 1 .. Number_Of_Constraints
loop
12403 Constrain_Index
(Index
, S
, Related_Nod
, Related_Id
, Suffix
, J
);
12411 if No
(Def_Id
) then
12413 Create_Itype
(E_Array_Subtype
, Related_Nod
, Related_Id
, Suffix
);
12414 Set_Parent
(Def_Id
, Related_Nod
);
12417 Set_Ekind
(Def_Id
, E_Array_Subtype
);
12420 Set_Size_Info
(Def_Id
, (T
));
12421 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
12422 Set_Etype
(Def_Id
, Base_Type
(T
));
12424 if Constraint_OK
then
12425 Set_First_Index
(Def_Id
, First
(Constraints
(C
)));
12427 Set_First_Index
(Def_Id
, First_Index
(T
));
12430 Set_Is_Constrained
(Def_Id
, True);
12431 Set_Is_Aliased
(Def_Id
, Is_Aliased
(T
));
12432 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
12434 Set_Is_Private_Composite
(Def_Id
, Is_Private_Composite
(T
));
12435 Set_Is_Limited_Composite
(Def_Id
, Is_Limited_Composite
(T
));
12437 -- A subtype does not inherit the Packed_Array_Impl_Type of is parent.
12438 -- We need to initialize the attribute because if Def_Id is previously
12439 -- analyzed through a limited_with clause, it will have the attributes
12440 -- of an incomplete type, one of which is an Elist that overlaps the
12441 -- Packed_Array_Impl_Type field.
12443 Set_Packed_Array_Impl_Type
(Def_Id
, Empty
);
12445 -- Build a freeze node if parent still needs one. Also make sure that
12446 -- the Depends_On_Private status is set because the subtype will need
12447 -- reprocessing at the time the base type does, and also we must set a
12448 -- conditional delay.
12450 Set_Depends_On_Private
(Def_Id
, Depends_On_Private
(T
));
12451 Conditional_Delay
(Def_Id
, T
);
12452 end Constrain_Array
;
12454 ------------------------------
12455 -- Constrain_Component_Type --
12456 ------------------------------
12458 function Constrain_Component_Type
12460 Constrained_Typ
: Entity_Id
;
12461 Related_Node
: Node_Id
;
12463 Constraints
: Elist_Id
) return Entity_Id
12465 Loc
: constant Source_Ptr
:= Sloc
(Constrained_Typ
);
12466 Compon_Type
: constant Entity_Id
:= Etype
(Comp
);
12468 function Build_Constrained_Array_Type
12469 (Old_Type
: Entity_Id
) return Entity_Id
;
12470 -- If Old_Type is an array type, one of whose indexes is constrained
12471 -- by a discriminant, build an Itype whose constraint replaces the
12472 -- discriminant with its value in the constraint.
12474 function Build_Constrained_Discriminated_Type
12475 (Old_Type
: Entity_Id
) return Entity_Id
;
12476 -- Ditto for record components
12478 function Build_Constrained_Access_Type
12479 (Old_Type
: Entity_Id
) return Entity_Id
;
12480 -- Ditto for access types. Makes use of previous two functions, to
12481 -- constrain designated type.
12483 function Build_Subtype
(T
: Entity_Id
; C
: List_Id
) return Entity_Id
;
12484 -- T is an array or discriminated type, C is a list of constraints
12485 -- that apply to T. This routine builds the constrained subtype.
12487 function Is_Discriminant
(Expr
: Node_Id
) return Boolean;
12488 -- Returns True if Expr is a discriminant
12490 function Get_Discr_Value
(Discrim
: Entity_Id
) return Node_Id
;
12491 -- Find the value of discriminant Discrim in Constraint
12493 -----------------------------------
12494 -- Build_Constrained_Access_Type --
12495 -----------------------------------
12497 function Build_Constrained_Access_Type
12498 (Old_Type
: Entity_Id
) return Entity_Id
12500 Desig_Type
: constant Entity_Id
:= Designated_Type
(Old_Type
);
12502 Desig_Subtype
: Entity_Id
;
12506 -- if the original access type was not embedded in the enclosing
12507 -- type definition, there is no need to produce a new access
12508 -- subtype. In fact every access type with an explicit constraint
12509 -- generates an itype whose scope is the enclosing record.
12511 if not Is_Type
(Scope
(Old_Type
)) then
12514 elsif Is_Array_Type
(Desig_Type
) then
12515 Desig_Subtype
:= Build_Constrained_Array_Type
(Desig_Type
);
12517 elsif Has_Discriminants
(Desig_Type
) then
12519 -- This may be an access type to an enclosing record type for
12520 -- which we are constructing the constrained components. Return
12521 -- the enclosing record subtype. This is not always correct,
12522 -- but avoids infinite recursion. ???
12524 Desig_Subtype
:= Any_Type
;
12526 for J
in reverse 0 .. Scope_Stack
.Last
loop
12527 Scop
:= Scope_Stack
.Table
(J
).Entity
;
12530 and then Base_Type
(Scop
) = Base_Type
(Desig_Type
)
12532 Desig_Subtype
:= Scop
;
12535 exit when not Is_Type
(Scop
);
12538 if Desig_Subtype
= Any_Type
then
12540 Build_Constrained_Discriminated_Type
(Desig_Type
);
12547 if Desig_Subtype
/= Desig_Type
then
12549 -- The Related_Node better be here or else we won't be able
12550 -- to attach new itypes to a node in the tree.
12552 pragma Assert
(Present
(Related_Node
));
12554 Itype
:= Create_Itype
(E_Access_Subtype
, Related_Node
);
12556 Set_Etype
(Itype
, Base_Type
(Old_Type
));
12557 Set_Size_Info
(Itype
, (Old_Type
));
12558 Set_Directly_Designated_Type
(Itype
, Desig_Subtype
);
12559 Set_Depends_On_Private
(Itype
, Has_Private_Component
12561 Set_Is_Access_Constant
(Itype
, Is_Access_Constant
12564 -- The new itype needs freezing when it depends on a not frozen
12565 -- type and the enclosing subtype needs freezing.
12567 if Has_Delayed_Freeze
(Constrained_Typ
)
12568 and then not Is_Frozen
(Constrained_Typ
)
12570 Conditional_Delay
(Itype
, Base_Type
(Old_Type
));
12578 end Build_Constrained_Access_Type
;
12580 ----------------------------------
12581 -- Build_Constrained_Array_Type --
12582 ----------------------------------
12584 function Build_Constrained_Array_Type
12585 (Old_Type
: Entity_Id
) return Entity_Id
12589 Old_Index
: Node_Id
;
12590 Range_Node
: Node_Id
;
12591 Constr_List
: List_Id
;
12593 Need_To_Create_Itype
: Boolean := False;
12596 Old_Index
:= First_Index
(Old_Type
);
12597 while Present
(Old_Index
) loop
12598 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
12600 if Is_Discriminant
(Lo_Expr
)
12602 Is_Discriminant
(Hi_Expr
)
12604 Need_To_Create_Itype
:= True;
12607 Next_Index
(Old_Index
);
12610 if Need_To_Create_Itype
then
12611 Constr_List
:= New_List
;
12613 Old_Index
:= First_Index
(Old_Type
);
12614 while Present
(Old_Index
) loop
12615 Get_Index_Bounds
(Old_Index
, Lo_Expr
, Hi_Expr
);
12617 if Is_Discriminant
(Lo_Expr
) then
12618 Lo_Expr
:= Get_Discr_Value
(Lo_Expr
);
12621 if Is_Discriminant
(Hi_Expr
) then
12622 Hi_Expr
:= Get_Discr_Value
(Hi_Expr
);
12627 (Loc
, New_Copy_Tree
(Lo_Expr
), New_Copy_Tree
(Hi_Expr
));
12629 Append
(Range_Node
, To
=> Constr_List
);
12631 Next_Index
(Old_Index
);
12634 return Build_Subtype
(Old_Type
, Constr_List
);
12639 end Build_Constrained_Array_Type
;
12641 ------------------------------------------
12642 -- Build_Constrained_Discriminated_Type --
12643 ------------------------------------------
12645 function Build_Constrained_Discriminated_Type
12646 (Old_Type
: Entity_Id
) return Entity_Id
12649 Constr_List
: List_Id
;
12650 Old_Constraint
: Elmt_Id
;
12652 Need_To_Create_Itype
: Boolean := False;
12655 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
12656 while Present
(Old_Constraint
) loop
12657 Expr
:= Node
(Old_Constraint
);
12659 if Is_Discriminant
(Expr
) then
12660 Need_To_Create_Itype
:= True;
12663 Next_Elmt
(Old_Constraint
);
12666 if Need_To_Create_Itype
then
12667 Constr_List
:= New_List
;
12669 Old_Constraint
:= First_Elmt
(Discriminant_Constraint
(Old_Type
));
12670 while Present
(Old_Constraint
) loop
12671 Expr
:= Node
(Old_Constraint
);
12673 if Is_Discriminant
(Expr
) then
12674 Expr
:= Get_Discr_Value
(Expr
);
12677 Append
(New_Copy_Tree
(Expr
), To
=> Constr_List
);
12679 Next_Elmt
(Old_Constraint
);
12682 return Build_Subtype
(Old_Type
, Constr_List
);
12687 end Build_Constrained_Discriminated_Type
;
12689 -------------------
12690 -- Build_Subtype --
12691 -------------------
12693 function Build_Subtype
(T
: Entity_Id
; C
: List_Id
) return Entity_Id
is
12695 Subtyp_Decl
: Node_Id
;
12696 Def_Id
: Entity_Id
;
12697 Btyp
: Entity_Id
:= Base_Type
(T
);
12700 -- The Related_Node better be here or else we won't be able to
12701 -- attach new itypes to a node in the tree.
12703 pragma Assert
(Present
(Related_Node
));
12705 -- If the view of the component's type is incomplete or private
12706 -- with unknown discriminants, then the constraint must be applied
12707 -- to the full type.
12709 if Has_Unknown_Discriminants
(Btyp
)
12710 and then Present
(Underlying_Type
(Btyp
))
12712 Btyp
:= Underlying_Type
(Btyp
);
12716 Make_Subtype_Indication
(Loc
,
12717 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
12718 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
, C
));
12720 Def_Id
:= Create_Itype
(Ekind
(T
), Related_Node
);
12723 Make_Subtype_Declaration
(Loc
,
12724 Defining_Identifier
=> Def_Id
,
12725 Subtype_Indication
=> Indic
);
12727 Set_Parent
(Subtyp_Decl
, Parent
(Related_Node
));
12729 -- Itypes must be analyzed with checks off (see package Itypes)
12731 Analyze
(Subtyp_Decl
, Suppress
=> All_Checks
);
12736 ---------------------
12737 -- Get_Discr_Value --
12738 ---------------------
12740 function Get_Discr_Value
(Discrim
: Entity_Id
) return Node_Id
is
12745 -- The discriminant may be declared for the type, in which case we
12746 -- find it by iterating over the list of discriminants. If the
12747 -- discriminant is inherited from a parent type, it appears as the
12748 -- corresponding discriminant of the current type. This will be the
12749 -- case when constraining an inherited component whose constraint is
12750 -- given by a discriminant of the parent.
12752 D
:= First_Discriminant
(Typ
);
12753 E
:= First_Elmt
(Constraints
);
12755 while Present
(D
) loop
12756 if D
= Entity
(Discrim
)
12757 or else D
= CR_Discriminant
(Entity
(Discrim
))
12758 or else Corresponding_Discriminant
(D
) = Entity
(Discrim
)
12763 Next_Discriminant
(D
);
12767 -- The Corresponding_Discriminant mechanism is incomplete, because
12768 -- the correspondence between new and old discriminants is not one
12769 -- to one: one new discriminant can constrain several old ones. In
12770 -- that case, scan sequentially the stored_constraint, the list of
12771 -- discriminants of the parents, and the constraints.
12773 -- Previous code checked for the present of the Stored_Constraint
12774 -- list for the derived type, but did not use it at all. Should it
12775 -- be present when the component is a discriminated task type?
12777 if Is_Derived_Type
(Typ
)
12778 and then Scope
(Entity
(Discrim
)) = Etype
(Typ
)
12780 D
:= First_Discriminant
(Etype
(Typ
));
12781 E
:= First_Elmt
(Constraints
);
12782 while Present
(D
) loop
12783 if D
= Entity
(Discrim
) then
12787 Next_Discriminant
(D
);
12792 -- Something is wrong if we did not find the value
12794 raise Program_Error
;
12795 end Get_Discr_Value
;
12797 ---------------------
12798 -- Is_Discriminant --
12799 ---------------------
12801 function Is_Discriminant
(Expr
: Node_Id
) return Boolean is
12802 Discrim_Scope
: Entity_Id
;
12805 if Denotes_Discriminant
(Expr
) then
12806 Discrim_Scope
:= Scope
(Entity
(Expr
));
12808 -- Either we have a reference to one of Typ's discriminants,
12810 pragma Assert
(Discrim_Scope
= Typ
12812 -- or to the discriminants of the parent type, in the case
12813 -- of a derivation of a tagged type with variants.
12815 or else Discrim_Scope
= Etype
(Typ
)
12816 or else Full_View
(Discrim_Scope
) = Etype
(Typ
)
12818 -- or same as above for the case where the discriminants
12819 -- were declared in Typ's private view.
12821 or else (Is_Private_Type
(Discrim_Scope
)
12822 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
12824 -- or else we are deriving from the full view and the
12825 -- discriminant is declared in the private entity.
12827 or else (Is_Private_Type
(Typ
)
12828 and then Chars
(Discrim_Scope
) = Chars
(Typ
))
12830 -- Or we are constrained the corresponding record of a
12831 -- synchronized type that completes a private declaration.
12833 or else (Is_Concurrent_Record_Type
(Typ
)
12835 Corresponding_Concurrent_Type
(Typ
) = Discrim_Scope
)
12837 -- or we have a class-wide type, in which case make sure the
12838 -- discriminant found belongs to the root type.
12840 or else (Is_Class_Wide_Type
(Typ
)
12841 and then Etype
(Typ
) = Discrim_Scope
));
12846 -- In all other cases we have something wrong
12849 end Is_Discriminant
;
12851 -- Start of processing for Constrain_Component_Type
12854 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
12855 and then Comes_From_Source
(Parent
(Comp
))
12856 and then Comes_From_Source
12857 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
12860 (Subtype_Indication
(Component_Definition
(Parent
(Comp
))))
12862 return Compon_Type
;
12864 elsif Is_Array_Type
(Compon_Type
) then
12865 return Build_Constrained_Array_Type
(Compon_Type
);
12867 elsif Has_Discriminants
(Compon_Type
) then
12868 return Build_Constrained_Discriminated_Type
(Compon_Type
);
12870 elsif Is_Access_Type
(Compon_Type
) then
12871 return Build_Constrained_Access_Type
(Compon_Type
);
12874 return Compon_Type
;
12876 end Constrain_Component_Type
;
12878 --------------------------
12879 -- Constrain_Concurrent --
12880 --------------------------
12882 -- For concurrent types, the associated record value type carries the same
12883 -- discriminants, so when we constrain a concurrent type, we must constrain
12884 -- the corresponding record type as well.
12886 procedure Constrain_Concurrent
12887 (Def_Id
: in out Entity_Id
;
12889 Related_Nod
: Node_Id
;
12890 Related_Id
: Entity_Id
;
12891 Suffix
: Character)
12893 -- Retrieve Base_Type to ensure getting to the concurrent type in the
12894 -- case of a private subtype (needed when only doing semantic analysis).
12896 T_Ent
: Entity_Id
:= Base_Type
(Entity
(Subtype_Mark
(SI
)));
12900 if Is_Access_Type
(T_Ent
) then
12901 T_Ent
:= Designated_Type
(T_Ent
);
12904 T_Val
:= Corresponding_Record_Type
(T_Ent
);
12906 if Present
(T_Val
) then
12908 if No
(Def_Id
) then
12909 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
12912 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
12914 Set_Depends_On_Private
(Def_Id
, Has_Private_Component
(Def_Id
));
12915 Set_Corresponding_Record_Type
(Def_Id
,
12916 Constrain_Corresponding_Record
(Def_Id
, T_Val
, Related_Nod
));
12919 -- If there is no associated record, expansion is disabled and this
12920 -- is a generic context. Create a subtype in any case, so that
12921 -- semantic analysis can proceed.
12923 if No
(Def_Id
) then
12924 Def_Id
:= Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
12927 Constrain_Discriminated_Type
(Def_Id
, SI
, Related_Nod
);
12929 end Constrain_Concurrent
;
12931 ------------------------------------
12932 -- Constrain_Corresponding_Record --
12933 ------------------------------------
12935 function Constrain_Corresponding_Record
12936 (Prot_Subt
: Entity_Id
;
12937 Corr_Rec
: Entity_Id
;
12938 Related_Nod
: Node_Id
) return Entity_Id
12940 T_Sub
: constant Entity_Id
:=
12941 Create_Itype
(E_Record_Subtype
, Related_Nod
, Corr_Rec
, 'C');
12944 Set_Etype
(T_Sub
, Corr_Rec
);
12945 Set_Has_Discriminants
(T_Sub
, Has_Discriminants
(Prot_Subt
));
12946 Set_Is_Constrained
(T_Sub
, True);
12947 Set_First_Entity
(T_Sub
, First_Entity
(Corr_Rec
));
12948 Set_Last_Entity
(T_Sub
, Last_Entity
(Corr_Rec
));
12950 if Has_Discriminants
(Prot_Subt
) then -- False only if errors.
12951 Set_Discriminant_Constraint
12952 (T_Sub
, Discriminant_Constraint
(Prot_Subt
));
12953 Set_Stored_Constraint_From_Discriminant_Constraint
(T_Sub
);
12954 Create_Constrained_Components
12955 (T_Sub
, Related_Nod
, Corr_Rec
, Discriminant_Constraint
(T_Sub
));
12958 Set_Depends_On_Private
(T_Sub
, Has_Private_Component
(T_Sub
));
12960 if Ekind
(Scope
(Prot_Subt
)) /= E_Record_Type
then
12961 Conditional_Delay
(T_Sub
, Corr_Rec
);
12964 -- This is a component subtype: it will be frozen in the context of
12965 -- the enclosing record's init_proc, so that discriminant references
12966 -- are resolved to discriminals. (Note: we used to skip freezing
12967 -- altogether in that case, which caused errors downstream for
12968 -- components of a bit packed array type).
12970 Set_Has_Delayed_Freeze
(T_Sub
);
12974 end Constrain_Corresponding_Record
;
12976 -----------------------
12977 -- Constrain_Decimal --
12978 -----------------------
12980 procedure Constrain_Decimal
(Def_Id
: Node_Id
; S
: Node_Id
) is
12981 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
12982 C
: constant Node_Id
:= Constraint
(S
);
12983 Loc
: constant Source_Ptr
:= Sloc
(C
);
12984 Range_Expr
: Node_Id
;
12985 Digits_Expr
: Node_Id
;
12990 Set_Ekind
(Def_Id
, E_Decimal_Fixed_Point_Subtype
);
12992 if Nkind
(C
) = N_Range_Constraint
then
12993 Range_Expr
:= Range_Expression
(C
);
12994 Digits_Val
:= Digits_Value
(T
);
12997 pragma Assert
(Nkind
(C
) = N_Digits_Constraint
);
12999 Check_SPARK_05_Restriction
("digits constraint is not allowed", S
);
13001 Digits_Expr
:= Digits_Expression
(C
);
13002 Analyze_And_Resolve
(Digits_Expr
, Any_Integer
);
13004 Check_Digits_Expression
(Digits_Expr
);
13005 Digits_Val
:= Expr_Value
(Digits_Expr
);
13007 if Digits_Val
> Digits_Value
(T
) then
13009 ("digits expression is incompatible with subtype", C
);
13010 Digits_Val
:= Digits_Value
(T
);
13013 if Present
(Range_Constraint
(C
)) then
13014 Range_Expr
:= Range_Expression
(Range_Constraint
(C
));
13016 Range_Expr
:= Empty
;
13020 Set_Etype
(Def_Id
, Base_Type
(T
));
13021 Set_Size_Info
(Def_Id
, (T
));
13022 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13023 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
13024 Set_Scale_Value
(Def_Id
, Scale_Value
(T
));
13025 Set_Small_Value
(Def_Id
, Small_Value
(T
));
13026 Set_Machine_Radix_10
(Def_Id
, Machine_Radix_10
(T
));
13027 Set_Digits_Value
(Def_Id
, Digits_Val
);
13029 -- Manufacture range from given digits value if no range present
13031 if No
(Range_Expr
) then
13032 Bound_Val
:= (Ureal_10
** Digits_Val
- Ureal_1
) * Small_Value
(T
);
13036 Convert_To
(T
, Make_Real_Literal
(Loc
, (-Bound_Val
))),
13038 Convert_To
(T
, Make_Real_Literal
(Loc
, Bound_Val
)));
13041 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expr
, T
);
13042 Set_Discrete_RM_Size
(Def_Id
);
13044 -- Unconditionally delay the freeze, since we cannot set size
13045 -- information in all cases correctly until the freeze point.
13047 Set_Has_Delayed_Freeze
(Def_Id
);
13048 end Constrain_Decimal
;
13050 ----------------------------------
13051 -- Constrain_Discriminated_Type --
13052 ----------------------------------
13054 procedure Constrain_Discriminated_Type
13055 (Def_Id
: Entity_Id
;
13057 Related_Nod
: Node_Id
;
13058 For_Access
: Boolean := False)
13060 E
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
13063 Elist
: Elist_Id
:= New_Elmt_List
;
13065 procedure Fixup_Bad_Constraint
;
13066 -- This is called after finding a bad constraint, and after having
13067 -- posted an appropriate error message. The mission is to leave the
13068 -- entity T in as reasonable state as possible.
13070 --------------------------
13071 -- Fixup_Bad_Constraint --
13072 --------------------------
13074 procedure Fixup_Bad_Constraint
is
13076 -- Set a reasonable Ekind for the entity. For an incomplete type,
13077 -- we can't do much, but for other types, we can set the proper
13078 -- corresponding subtype kind.
13080 if Ekind
(T
) = E_Incomplete_Type
then
13081 Set_Ekind
(Def_Id
, Ekind
(T
));
13083 Set_Ekind
(Def_Id
, Subtype_Kind
(Ekind
(T
)));
13086 -- Set Etype to the known type, to reduce chances of cascaded errors
13088 Set_Etype
(Def_Id
, E
);
13089 Set_Error_Posted
(Def_Id
);
13090 end Fixup_Bad_Constraint
;
13092 -- Start of processing for Constrain_Discriminated_Type
13095 C
:= Constraint
(S
);
13097 -- A discriminant constraint is only allowed in a subtype indication,
13098 -- after a subtype mark. This subtype mark must denote either a type
13099 -- with discriminants, or an access type whose designated type is a
13100 -- type with discriminants. A discriminant constraint specifies the
13101 -- values of these discriminants (RM 3.7.2(5)).
13103 T
:= Base_Type
(Entity
(Subtype_Mark
(S
)));
13105 if Is_Access_Type
(T
) then
13106 T
:= Designated_Type
(T
);
13109 -- Ada 2005 (AI-412): Constrained incomplete subtypes are illegal.
13110 -- Avoid generating an error for access-to-incomplete subtypes.
13112 if Ada_Version
>= Ada_2005
13113 and then Ekind
(T
) = E_Incomplete_Type
13114 and then Nkind
(Parent
(S
)) = N_Subtype_Declaration
13115 and then not Is_Itype
(Def_Id
)
13117 -- A little sanity check, emit an error message if the type
13118 -- has discriminants to begin with. Type T may be a regular
13119 -- incomplete type or imported via a limited with clause.
13121 if Has_Discriminants
(T
)
13122 or else (From_Limited_With
(T
)
13123 and then Present
(Non_Limited_View
(T
))
13124 and then Nkind
(Parent
(Non_Limited_View
(T
))) =
13125 N_Full_Type_Declaration
13126 and then Present
(Discriminant_Specifications
13127 (Parent
(Non_Limited_View
(T
)))))
13130 ("(Ada 2005) incomplete subtype may not be constrained", C
);
13132 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
13135 Fixup_Bad_Constraint
;
13138 -- Check that the type has visible discriminants. The type may be
13139 -- a private type with unknown discriminants whose full view has
13140 -- discriminants which are invisible.
13142 elsif not Has_Discriminants
(T
)
13144 (Has_Unknown_Discriminants
(T
)
13145 and then Is_Private_Type
(T
))
13147 Error_Msg_N
("invalid constraint: type has no discriminant", C
);
13148 Fixup_Bad_Constraint
;
13151 elsif Is_Constrained
(E
)
13152 or else (Ekind
(E
) = E_Class_Wide_Subtype
13153 and then Present
(Discriminant_Constraint
(E
)))
13155 Error_Msg_N
("type is already constrained", Subtype_Mark
(S
));
13156 Fixup_Bad_Constraint
;
13160 -- T may be an unconstrained subtype (e.g. a generic actual).
13161 -- Constraint applies to the base type.
13163 T
:= Base_Type
(T
);
13165 Elist
:= Build_Discriminant_Constraints
(T
, S
);
13167 -- If the list returned was empty we had an error in building the
13168 -- discriminant constraint. We have also already signalled an error
13169 -- in the incomplete type case
13171 if Is_Empty_Elmt_List
(Elist
) then
13172 Fixup_Bad_Constraint
;
13176 Build_Discriminated_Subtype
(T
, Def_Id
, Elist
, Related_Nod
, For_Access
);
13177 end Constrain_Discriminated_Type
;
13179 ---------------------------
13180 -- Constrain_Enumeration --
13181 ---------------------------
13183 procedure Constrain_Enumeration
(Def_Id
: Node_Id
; S
: Node_Id
) is
13184 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
13185 C
: constant Node_Id
:= Constraint
(S
);
13188 Set_Ekind
(Def_Id
, E_Enumeration_Subtype
);
13190 Set_First_Literal
(Def_Id
, First_Literal
(Base_Type
(T
)));
13192 Set_Etype
(Def_Id
, Base_Type
(T
));
13193 Set_Size_Info
(Def_Id
, (T
));
13194 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13195 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
13197 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
13199 Set_Discrete_RM_Size
(Def_Id
);
13200 end Constrain_Enumeration
;
13202 ----------------------
13203 -- Constrain_Float --
13204 ----------------------
13206 procedure Constrain_Float
(Def_Id
: Node_Id
; S
: Node_Id
) is
13207 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
13213 Set_Ekind
(Def_Id
, E_Floating_Point_Subtype
);
13215 Set_Etype
(Def_Id
, Base_Type
(T
));
13216 Set_Size_Info
(Def_Id
, (T
));
13217 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13219 -- Process the constraint
13221 C
:= Constraint
(S
);
13223 -- Digits constraint present
13225 if Nkind
(C
) = N_Digits_Constraint
then
13227 Check_SPARK_05_Restriction
("digits constraint is not allowed", S
);
13228 Check_Restriction
(No_Obsolescent_Features
, C
);
13230 if Warn_On_Obsolescent_Feature
then
13232 ("subtype digits constraint is an " &
13233 "obsolescent feature (RM J.3(8))?j?", C
);
13236 D
:= Digits_Expression
(C
);
13237 Analyze_And_Resolve
(D
, Any_Integer
);
13238 Check_Digits_Expression
(D
);
13239 Set_Digits_Value
(Def_Id
, Expr_Value
(D
));
13241 -- Check that digits value is in range. Obviously we can do this
13242 -- at compile time, but it is strictly a runtime check, and of
13243 -- course there is an ACVC test that checks this.
13245 if Digits_Value
(Def_Id
) > Digits_Value
(T
) then
13246 Error_Msg_Uint_1
:= Digits_Value
(T
);
13247 Error_Msg_N
("??digits value is too large, maximum is ^", D
);
13249 Make_Raise_Constraint_Error
(Sloc
(D
),
13250 Reason
=> CE_Range_Check_Failed
);
13251 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
13254 C
:= Range_Constraint
(C
);
13256 -- No digits constraint present
13259 Set_Digits_Value
(Def_Id
, Digits_Value
(T
));
13262 -- Range constraint present
13264 if Nkind
(C
) = N_Range_Constraint
then
13265 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
13267 -- No range constraint present
13270 pragma Assert
(No
(C
));
13271 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
13274 Set_Is_Constrained
(Def_Id
);
13275 end Constrain_Float
;
13277 ---------------------
13278 -- Constrain_Index --
13279 ---------------------
13281 procedure Constrain_Index
13284 Related_Nod
: Node_Id
;
13285 Related_Id
: Entity_Id
;
13286 Suffix
: Character;
13287 Suffix_Index
: Nat
)
13289 Def_Id
: Entity_Id
;
13290 R
: Node_Id
:= Empty
;
13291 T
: constant Entity_Id
:= Etype
(Index
);
13295 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
, Suffix_Index
);
13296 Set_Etype
(Def_Id
, Base_Type
(T
));
13298 if Nkind
(S
) = N_Range
13300 (Nkind
(S
) = N_Attribute_Reference
13301 and then Attribute_Name
(S
) = Name_Range
)
13303 -- A Range attribute will be transformed into N_Range by Resolve
13309 Process_Range_Expr_In_Decl
(R
, T
);
13311 if not Error_Posted
(S
)
13313 (Nkind
(S
) /= N_Range
13314 or else not Covers
(T
, (Etype
(Low_Bound
(S
))))
13315 or else not Covers
(T
, (Etype
(High_Bound
(S
)))))
13317 if Base_Type
(T
) /= Any_Type
13318 and then Etype
(Low_Bound
(S
)) /= Any_Type
13319 and then Etype
(High_Bound
(S
)) /= Any_Type
13321 Error_Msg_N
("range expected", S
);
13325 elsif Nkind
(S
) = N_Subtype_Indication
then
13327 -- The parser has verified that this is a discrete indication
13329 Resolve_Discrete_Subtype_Indication
(S
, T
);
13330 Bad_Predicated_Subtype_Use
13331 ("subtype& has predicate, not allowed in index constraint",
13332 S
, Entity
(Subtype_Mark
(S
)));
13334 R
:= Range_Expression
(Constraint
(S
));
13336 -- Capture values of bounds and generate temporaries for them if
13337 -- needed, since checks may cause duplication of the expressions
13338 -- which must not be reevaluated.
13340 -- The forced evaluation removes side effects from expressions, which
13341 -- should occur also in GNATprove mode. Otherwise, we end up with
13342 -- unexpected insertions of actions at places where this is not
13343 -- supposed to occur, e.g. on default parameters of a call.
13345 if Expander_Active
or GNATprove_Mode
then
13347 (Low_Bound
(R
), Related_Id
=> Def_Id
, Is_Low_Bound
=> True);
13349 (High_Bound
(R
), Related_Id
=> Def_Id
, Is_High_Bound
=> True);
13352 elsif Nkind
(S
) = N_Discriminant_Association
then
13354 -- Syntactically valid in subtype indication
13356 Error_Msg_N
("invalid index constraint", S
);
13357 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
13360 -- Subtype_Mark case, no anonymous subtypes to construct
13365 if Is_Entity_Name
(S
) then
13366 if not Is_Type
(Entity
(S
)) then
13367 Error_Msg_N
("expect subtype mark for index constraint", S
);
13369 elsif Base_Type
(Entity
(S
)) /= Base_Type
(T
) then
13370 Wrong_Type
(S
, Base_Type
(T
));
13372 -- Check error of subtype with predicate in index constraint
13375 Bad_Predicated_Subtype_Use
13376 ("subtype& has predicate, not allowed in index constraint",
13383 Error_Msg_N
("invalid index constraint", S
);
13384 Rewrite
(S
, New_Occurrence_Of
(T
, Sloc
(S
)));
13389 -- Complete construction of the Itype
13391 if Is_Modular_Integer_Type
(T
) then
13392 Set_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
13394 elsif Is_Integer_Type
(T
) then
13395 Set_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
13398 Set_Ekind
(Def_Id
, E_Enumeration_Subtype
);
13399 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
13400 Set_First_Literal
(Def_Id
, First_Literal
(T
));
13403 Set_Size_Info
(Def_Id
, (T
));
13404 Set_RM_Size
(Def_Id
, RM_Size
(T
));
13405 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13407 Set_Scalar_Range
(Def_Id
, R
);
13409 Set_Etype
(S
, Def_Id
);
13410 Set_Discrete_RM_Size
(Def_Id
);
13411 end Constrain_Index
;
13413 -----------------------
13414 -- Constrain_Integer --
13415 -----------------------
13417 procedure Constrain_Integer
(Def_Id
: Node_Id
; S
: Node_Id
) is
13418 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
13419 C
: constant Node_Id
:= Constraint
(S
);
13422 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
13424 if Is_Modular_Integer_Type
(T
) then
13425 Set_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
13427 Set_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
13430 Set_Etype
(Def_Id
, Base_Type
(T
));
13431 Set_Size_Info
(Def_Id
, (T
));
13432 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13433 Set_Discrete_RM_Size
(Def_Id
);
13434 end Constrain_Integer
;
13436 ------------------------------
13437 -- Constrain_Ordinary_Fixed --
13438 ------------------------------
13440 procedure Constrain_Ordinary_Fixed
(Def_Id
: Node_Id
; S
: Node_Id
) is
13441 T
: constant Entity_Id
:= Entity
(Subtype_Mark
(S
));
13447 Set_Ekind
(Def_Id
, E_Ordinary_Fixed_Point_Subtype
);
13448 Set_Etype
(Def_Id
, Base_Type
(T
));
13449 Set_Size_Info
(Def_Id
, (T
));
13450 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
13451 Set_Small_Value
(Def_Id
, Small_Value
(T
));
13453 -- Process the constraint
13455 C
:= Constraint
(S
);
13457 -- Delta constraint present
13459 if Nkind
(C
) = N_Delta_Constraint
then
13461 Check_SPARK_05_Restriction
("delta constraint is not allowed", S
);
13462 Check_Restriction
(No_Obsolescent_Features
, C
);
13464 if Warn_On_Obsolescent_Feature
then
13466 ("subtype delta constraint is an " &
13467 "obsolescent feature (RM J.3(7))?j?");
13470 D
:= Delta_Expression
(C
);
13471 Analyze_And_Resolve
(D
, Any_Real
);
13472 Check_Delta_Expression
(D
);
13473 Set_Delta_Value
(Def_Id
, Expr_Value_R
(D
));
13475 -- Check that delta value is in range. Obviously we can do this
13476 -- at compile time, but it is strictly a runtime check, and of
13477 -- course there is an ACVC test that checks this.
13479 if Delta_Value
(Def_Id
) < Delta_Value
(T
) then
13480 Error_Msg_N
("??delta value is too small", D
);
13482 Make_Raise_Constraint_Error
(Sloc
(D
),
13483 Reason
=> CE_Range_Check_Failed
);
13484 Insert_Action
(Declaration_Node
(Def_Id
), Rais
);
13487 C
:= Range_Constraint
(C
);
13489 -- No delta constraint present
13492 Set_Delta_Value
(Def_Id
, Delta_Value
(T
));
13495 -- Range constraint present
13497 if Nkind
(C
) = N_Range_Constraint
then
13498 Set_Scalar_Range_For_Subtype
(Def_Id
, Range_Expression
(C
), T
);
13500 -- No range constraint present
13503 pragma Assert
(No
(C
));
13504 Set_Scalar_Range
(Def_Id
, Scalar_Range
(T
));
13507 Set_Discrete_RM_Size
(Def_Id
);
13509 -- Unconditionally delay the freeze, since we cannot set size
13510 -- information in all cases correctly until the freeze point.
13512 Set_Has_Delayed_Freeze
(Def_Id
);
13513 end Constrain_Ordinary_Fixed
;
13515 -----------------------
13516 -- Contain_Interface --
13517 -----------------------
13519 function Contain_Interface
13520 (Iface
: Entity_Id
;
13521 Ifaces
: Elist_Id
) return Boolean
13523 Iface_Elmt
: Elmt_Id
;
13526 if Present
(Ifaces
) then
13527 Iface_Elmt
:= First_Elmt
(Ifaces
);
13528 while Present
(Iface_Elmt
) loop
13529 if Node
(Iface_Elmt
) = Iface
then
13533 Next_Elmt
(Iface_Elmt
);
13538 end Contain_Interface
;
13540 ---------------------------
13541 -- Convert_Scalar_Bounds --
13542 ---------------------------
13544 procedure Convert_Scalar_Bounds
13546 Parent_Type
: Entity_Id
;
13547 Derived_Type
: Entity_Id
;
13550 Implicit_Base
: constant Entity_Id
:= Base_Type
(Derived_Type
);
13557 -- Defend against previous errors
13559 if No
(Scalar_Range
(Derived_Type
)) then
13560 Check_Error_Detected
;
13564 Lo
:= Build_Scalar_Bound
13565 (Type_Low_Bound
(Derived_Type
),
13566 Parent_Type
, Implicit_Base
);
13568 Hi
:= Build_Scalar_Bound
13569 (Type_High_Bound
(Derived_Type
),
13570 Parent_Type
, Implicit_Base
);
13577 Set_Includes_Infinities
(Rng
, Has_Infinities
(Derived_Type
));
13579 Set_Parent
(Rng
, N
);
13580 Set_Scalar_Range
(Derived_Type
, Rng
);
13582 -- Analyze the bounds
13584 Analyze_And_Resolve
(Lo
, Implicit_Base
);
13585 Analyze_And_Resolve
(Hi
, Implicit_Base
);
13587 -- Analyze the range itself, except that we do not analyze it if
13588 -- the bounds are real literals, and we have a fixed-point type.
13589 -- The reason for this is that we delay setting the bounds in this
13590 -- case till we know the final Small and Size values (see circuit
13591 -- in Freeze.Freeze_Fixed_Point_Type for further details).
13593 if Is_Fixed_Point_Type
(Parent_Type
)
13594 and then Nkind
(Lo
) = N_Real_Literal
13595 and then Nkind
(Hi
) = N_Real_Literal
13599 -- Here we do the analysis of the range
13601 -- Note: we do this manually, since if we do a normal Analyze and
13602 -- Resolve call, there are problems with the conversions used for
13603 -- the derived type range.
13606 Set_Etype
(Rng
, Implicit_Base
);
13607 Set_Analyzed
(Rng
, True);
13609 end Convert_Scalar_Bounds
;
13611 -------------------
13612 -- Copy_And_Swap --
13613 -------------------
13615 procedure Copy_And_Swap
(Priv
, Full
: Entity_Id
) is
13617 -- Initialize new full declaration entity by copying the pertinent
13618 -- fields of the corresponding private declaration entity.
13620 -- We temporarily set Ekind to a value appropriate for a type to
13621 -- avoid assert failures in Einfo from checking for setting type
13622 -- attributes on something that is not a type. Ekind (Priv) is an
13623 -- appropriate choice, since it allowed the attributes to be set
13624 -- in the first place. This Ekind value will be modified later.
13626 Set_Ekind
(Full
, Ekind
(Priv
));
13628 -- Also set Etype temporarily to Any_Type, again, in the absence
13629 -- of errors, it will be properly reset, and if there are errors,
13630 -- then we want a value of Any_Type to remain.
13632 Set_Etype
(Full
, Any_Type
);
13634 -- Now start copying attributes
13636 Set_Has_Discriminants
(Full
, Has_Discriminants
(Priv
));
13638 if Has_Discriminants
(Full
) then
13639 Set_Discriminant_Constraint
(Full
, Discriminant_Constraint
(Priv
));
13640 Set_Stored_Constraint
(Full
, Stored_Constraint
(Priv
));
13643 Set_First_Rep_Item
(Full
, First_Rep_Item
(Priv
));
13644 Set_Homonym
(Full
, Homonym
(Priv
));
13645 Set_Is_Immediately_Visible
(Full
, Is_Immediately_Visible
(Priv
));
13646 Set_Is_Public
(Full
, Is_Public
(Priv
));
13647 Set_Is_Pure
(Full
, Is_Pure
(Priv
));
13648 Set_Is_Tagged_Type
(Full
, Is_Tagged_Type
(Priv
));
13649 Set_Has_Pragma_Unmodified
(Full
, Has_Pragma_Unmodified
(Priv
));
13650 Set_Has_Pragma_Unreferenced
(Full
, Has_Pragma_Unreferenced
(Priv
));
13651 Set_Has_Pragma_Unreferenced_Objects
13652 (Full
, Has_Pragma_Unreferenced_Objects
13655 Conditional_Delay
(Full
, Priv
);
13657 if Is_Tagged_Type
(Full
) then
13658 Set_Direct_Primitive_Operations
13659 (Full
, Direct_Primitive_Operations
(Priv
));
13660 Set_No_Tagged_Streams_Pragma
13661 (Full
, No_Tagged_Streams_Pragma
(Priv
));
13663 if Is_Base_Type
(Priv
) then
13664 Set_Class_Wide_Type
(Full
, Class_Wide_Type
(Priv
));
13668 Set_Is_Volatile
(Full
, Is_Volatile
(Priv
));
13669 Set_Treat_As_Volatile
(Full
, Treat_As_Volatile
(Priv
));
13670 Set_Scope
(Full
, Scope
(Priv
));
13671 Set_Next_Entity
(Full
, Next_Entity
(Priv
));
13672 Set_First_Entity
(Full
, First_Entity
(Priv
));
13673 Set_Last_Entity
(Full
, Last_Entity
(Priv
));
13675 -- If access types have been recorded for later handling, keep them in
13676 -- the full view so that they get handled when the full view freeze
13677 -- node is expanded.
13679 if Present
(Freeze_Node
(Priv
))
13680 and then Present
(Access_Types_To_Process
(Freeze_Node
(Priv
)))
13682 Ensure_Freeze_Node
(Full
);
13683 Set_Access_Types_To_Process
13684 (Freeze_Node
(Full
),
13685 Access_Types_To_Process
(Freeze_Node
(Priv
)));
13688 -- Swap the two entities. Now Private is the full type entity and Full
13689 -- is the private one. They will be swapped back at the end of the
13690 -- private part. This swapping ensures that the entity that is visible
13691 -- in the private part is the full declaration.
13693 Exchange_Entities
(Priv
, Full
);
13694 Append_Entity
(Full
, Scope
(Full
));
13697 -------------------------------------
13698 -- Copy_Array_Base_Type_Attributes --
13699 -------------------------------------
13701 procedure Copy_Array_Base_Type_Attributes
(T1
, T2
: Entity_Id
) is
13703 Set_Component_Alignment
(T1
, Component_Alignment
(T2
));
13704 Set_Component_Type
(T1
, Component_Type
(T2
));
13705 Set_Component_Size
(T1
, Component_Size
(T2
));
13706 Set_Has_Controlled_Component
(T1
, Has_Controlled_Component
(T2
));
13707 Set_Has_Non_Standard_Rep
(T1
, Has_Non_Standard_Rep
(T2
));
13708 Set_Has_Protected
(T1
, Has_Protected
(T2
));
13709 Set_Has_Task
(T1
, Has_Task
(T2
));
13710 Set_Is_Packed
(T1
, Is_Packed
(T2
));
13711 Set_Has_Aliased_Components
(T1
, Has_Aliased_Components
(T2
));
13712 Set_Has_Atomic_Components
(T1
, Has_Atomic_Components
(T2
));
13713 Set_Has_Volatile_Components
(T1
, Has_Volatile_Components
(T2
));
13714 end Copy_Array_Base_Type_Attributes
;
13716 -----------------------------------
13717 -- Copy_Array_Subtype_Attributes --
13718 -----------------------------------
13720 procedure Copy_Array_Subtype_Attributes
(T1
, T2
: Entity_Id
) is
13722 Set_Size_Info
(T1
, T2
);
13724 Set_First_Index
(T1
, First_Index
(T2
));
13725 Set_Is_Aliased
(T1
, Is_Aliased
(T2
));
13726 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
13727 Set_Treat_As_Volatile
(T1
, Treat_As_Volatile
(T2
));
13728 Set_Is_Constrained
(T1
, Is_Constrained
(T2
));
13729 Set_Depends_On_Private
(T1
, Has_Private_Component
(T2
));
13730 Inherit_Rep_Item_Chain
(T1
, T2
);
13731 Set_Convention
(T1
, Convention
(T2
));
13732 Set_Is_Limited_Composite
(T1
, Is_Limited_Composite
(T2
));
13733 Set_Is_Private_Composite
(T1
, Is_Private_Composite
(T2
));
13734 Set_Packed_Array_Impl_Type
(T1
, Packed_Array_Impl_Type
(T2
));
13735 end Copy_Array_Subtype_Attributes
;
13737 -----------------------------------
13738 -- Create_Constrained_Components --
13739 -----------------------------------
13741 procedure Create_Constrained_Components
13743 Decl_Node
: Node_Id
;
13745 Constraints
: Elist_Id
)
13747 Loc
: constant Source_Ptr
:= Sloc
(Subt
);
13748 Comp_List
: constant Elist_Id
:= New_Elmt_List
;
13749 Parent_Type
: constant Entity_Id
:= Etype
(Typ
);
13750 Assoc_List
: constant List_Id
:= New_List
;
13751 Discr_Val
: Elmt_Id
;
13755 Is_Static
: Boolean := True;
13757 procedure Collect_Fixed_Components
(Typ
: Entity_Id
);
13758 -- Collect parent type components that do not appear in a variant part
13760 procedure Create_All_Components
;
13761 -- Iterate over Comp_List to create the components of the subtype
13763 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
;
13764 -- Creates a new component from Old_Compon, copying all the fields from
13765 -- it, including its Etype, inserts the new component in the Subt entity
13766 -- chain and returns the new component.
13768 function Is_Variant_Record
(T
: Entity_Id
) return Boolean;
13769 -- If true, and discriminants are static, collect only components from
13770 -- variants selected by discriminant values.
13772 ------------------------------
13773 -- Collect_Fixed_Components --
13774 ------------------------------
13776 procedure Collect_Fixed_Components
(Typ
: Entity_Id
) is
13778 -- Build association list for discriminants, and find components of the
13779 -- variant part selected by the values of the discriminants.
13781 Old_C
:= First_Discriminant
(Typ
);
13782 Discr_Val
:= First_Elmt
(Constraints
);
13783 while Present
(Old_C
) loop
13784 Append_To
(Assoc_List
,
13785 Make_Component_Association
(Loc
,
13786 Choices
=> New_List
(New_Occurrence_Of
(Old_C
, Loc
)),
13787 Expression
=> New_Copy
(Node
(Discr_Val
))));
13789 Next_Elmt
(Discr_Val
);
13790 Next_Discriminant
(Old_C
);
13793 -- The tag and the possible parent component are unconditionally in
13796 if Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
13797 Old_C
:= First_Component
(Typ
);
13798 while Present
(Old_C
) loop
13799 if Nam_In
(Chars
(Old_C
), Name_uTag
, Name_uParent
) then
13800 Append_Elmt
(Old_C
, Comp_List
);
13803 Next_Component
(Old_C
);
13806 end Collect_Fixed_Components
;
13808 ---------------------------
13809 -- Create_All_Components --
13810 ---------------------------
13812 procedure Create_All_Components
is
13816 Comp
:= First_Elmt
(Comp_List
);
13817 while Present
(Comp
) loop
13818 Old_C
:= Node
(Comp
);
13819 New_C
:= Create_Component
(Old_C
);
13823 Constrain_Component_Type
13824 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
13825 Set_Is_Public
(New_C
, Is_Public
(Subt
));
13829 end Create_All_Components
;
13831 ----------------------
13832 -- Create_Component --
13833 ----------------------
13835 function Create_Component
(Old_Compon
: Entity_Id
) return Entity_Id
is
13836 New_Compon
: constant Entity_Id
:= New_Copy
(Old_Compon
);
13839 if Ekind
(Old_Compon
) = E_Discriminant
13840 and then Is_Completely_Hidden
(Old_Compon
)
13842 -- This is a shadow discriminant created for a discriminant of
13843 -- the parent type, which needs to be present in the subtype.
13844 -- Give the shadow discriminant an internal name that cannot
13845 -- conflict with that of visible components.
13847 Set_Chars
(New_Compon
, New_Internal_Name
('C'));
13850 -- Set the parent so we have a proper link for freezing etc. This is
13851 -- not a real parent pointer, since of course our parent does not own
13852 -- up to us and reference us, we are an illegitimate child of the
13853 -- original parent.
13855 Set_Parent
(New_Compon
, Parent
(Old_Compon
));
13857 -- If the old component's Esize was already determined and is a
13858 -- static value, then the new component simply inherits it. Otherwise
13859 -- the old component's size may require run-time determination, but
13860 -- the new component's size still might be statically determinable
13861 -- (if, for example it has a static constraint). In that case we want
13862 -- Layout_Type to recompute the component's size, so we reset its
13863 -- size and positional fields.
13865 if Frontend_Layout_On_Target
13866 and then not Known_Static_Esize
(Old_Compon
)
13868 Set_Esize
(New_Compon
, Uint_0
);
13869 Init_Normalized_First_Bit
(New_Compon
);
13870 Init_Normalized_Position
(New_Compon
);
13871 Init_Normalized_Position_Max
(New_Compon
);
13874 -- We do not want this node marked as Comes_From_Source, since
13875 -- otherwise it would get first class status and a separate cross-
13876 -- reference line would be generated. Illegitimate children do not
13877 -- rate such recognition.
13879 Set_Comes_From_Source
(New_Compon
, False);
13881 -- But it is a real entity, and a birth certificate must be properly
13882 -- registered by entering it into the entity list.
13884 Enter_Name
(New_Compon
);
13887 end Create_Component
;
13889 -----------------------
13890 -- Is_Variant_Record --
13891 -----------------------
13893 function Is_Variant_Record
(T
: Entity_Id
) return Boolean is
13895 return Nkind
(Parent
(T
)) = N_Full_Type_Declaration
13896 and then Nkind
(Type_Definition
(Parent
(T
))) = N_Record_Definition
13897 and then Present
(Component_List
(Type_Definition
(Parent
(T
))))
13900 (Variant_Part
(Component_List
(Type_Definition
(Parent
(T
)))));
13901 end Is_Variant_Record
;
13903 -- Start of processing for Create_Constrained_Components
13906 pragma Assert
(Subt
/= Base_Type
(Subt
));
13907 pragma Assert
(Typ
= Base_Type
(Typ
));
13909 Set_First_Entity
(Subt
, Empty
);
13910 Set_Last_Entity
(Subt
, Empty
);
13912 -- Check whether constraint is fully static, in which case we can
13913 -- optimize the list of components.
13915 Discr_Val
:= First_Elmt
(Constraints
);
13916 while Present
(Discr_Val
) loop
13917 if not Is_OK_Static_Expression
(Node
(Discr_Val
)) then
13918 Is_Static
:= False;
13922 Next_Elmt
(Discr_Val
);
13925 Set_Has_Static_Discriminants
(Subt
, Is_Static
);
13929 -- Inherit the discriminants of the parent type
13931 Add_Discriminants
: declare
13937 Old_C
:= First_Discriminant
(Typ
);
13939 while Present
(Old_C
) loop
13940 Num_Disc
:= Num_Disc
+ 1;
13941 New_C
:= Create_Component
(Old_C
);
13942 Set_Is_Public
(New_C
, Is_Public
(Subt
));
13943 Next_Discriminant
(Old_C
);
13946 -- For an untagged derived subtype, the number of discriminants may
13947 -- be smaller than the number of inherited discriminants, because
13948 -- several of them may be renamed by a single new discriminant or
13949 -- constrained. In this case, add the hidden discriminants back into
13950 -- the subtype, because they need to be present if the optimizer of
13951 -- the GCC 4.x back-end decides to break apart assignments between
13952 -- objects using the parent view into member-wise assignments.
13956 if Is_Derived_Type
(Typ
)
13957 and then not Is_Tagged_Type
(Typ
)
13959 Old_C
:= First_Stored_Discriminant
(Typ
);
13961 while Present
(Old_C
) loop
13962 Num_Gird
:= Num_Gird
+ 1;
13963 Next_Stored_Discriminant
(Old_C
);
13967 if Num_Gird
> Num_Disc
then
13969 -- Find out multiple uses of new discriminants, and add hidden
13970 -- components for the extra renamed discriminants. We recognize
13971 -- multiple uses through the Corresponding_Discriminant of a
13972 -- new discriminant: if it constrains several old discriminants,
13973 -- this field points to the last one in the parent type. The
13974 -- stored discriminants of the derived type have the same name
13975 -- as those of the parent.
13979 New_Discr
: Entity_Id
;
13980 Old_Discr
: Entity_Id
;
13983 Constr
:= First_Elmt
(Stored_Constraint
(Typ
));
13984 Old_Discr
:= First_Stored_Discriminant
(Typ
);
13985 while Present
(Constr
) loop
13986 if Is_Entity_Name
(Node
(Constr
))
13987 and then Ekind
(Entity
(Node
(Constr
))) = E_Discriminant
13989 New_Discr
:= Entity
(Node
(Constr
));
13991 if Chars
(Corresponding_Discriminant
(New_Discr
)) /=
13994 -- The new discriminant has been used to rename a
13995 -- subsequent old discriminant. Introduce a shadow
13996 -- component for the current old discriminant.
13998 New_C
:= Create_Component
(Old_Discr
);
13999 Set_Original_Record_Component
(New_C
, Old_Discr
);
14003 -- The constraint has eliminated the old discriminant.
14004 -- Introduce a shadow component.
14006 New_C
:= Create_Component
(Old_Discr
);
14007 Set_Original_Record_Component
(New_C
, Old_Discr
);
14010 Next_Elmt
(Constr
);
14011 Next_Stored_Discriminant
(Old_Discr
);
14015 end Add_Discriminants
;
14018 and then Is_Variant_Record
(Typ
)
14020 Collect_Fixed_Components
(Typ
);
14022 Gather_Components
(
14024 Component_List
(Type_Definition
(Parent
(Typ
))),
14025 Governed_By
=> Assoc_List
,
14027 Report_Errors
=> Errors
);
14028 pragma Assert
(not Errors
);
14030 Create_All_Components
;
14032 -- If the subtype declaration is created for a tagged type derivation
14033 -- with constraints, we retrieve the record definition of the parent
14034 -- type to select the components of the proper variant.
14037 and then Is_Tagged_Type
(Typ
)
14038 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
14040 Nkind
(Type_Definition
(Parent
(Typ
))) = N_Derived_Type_Definition
14041 and then Is_Variant_Record
(Parent_Type
)
14043 Collect_Fixed_Components
(Typ
);
14047 Component_List
(Type_Definition
(Parent
(Parent_Type
))),
14048 Governed_By
=> Assoc_List
,
14050 Report_Errors
=> Errors
);
14052 -- Note: previously there was a check at this point that no errors
14053 -- were detected. As a consequence of AI05-220 there may be an error
14054 -- if an inherited discriminant that controls a variant has a non-
14055 -- static constraint.
14057 -- If the tagged derivation has a type extension, collect all the
14058 -- new components therein.
14060 if Present
(Record_Extension_Part
(Type_Definition
(Parent
(Typ
))))
14062 Old_C
:= First_Component
(Typ
);
14063 while Present
(Old_C
) loop
14064 if Original_Record_Component
(Old_C
) = Old_C
14065 and then Chars
(Old_C
) /= Name_uTag
14066 and then Chars
(Old_C
) /= Name_uParent
14068 Append_Elmt
(Old_C
, Comp_List
);
14071 Next_Component
(Old_C
);
14075 Create_All_Components
;
14078 -- If discriminants are not static, or if this is a multi-level type
14079 -- extension, we have to include all components of the parent type.
14081 Old_C
:= First_Component
(Typ
);
14082 while Present
(Old_C
) loop
14083 New_C
:= Create_Component
(Old_C
);
14087 Constrain_Component_Type
14088 (Old_C
, Subt
, Decl_Node
, Typ
, Constraints
));
14089 Set_Is_Public
(New_C
, Is_Public
(Subt
));
14091 Next_Component
(Old_C
);
14096 end Create_Constrained_Components
;
14098 ------------------------------------------
14099 -- Decimal_Fixed_Point_Type_Declaration --
14100 ------------------------------------------
14102 procedure Decimal_Fixed_Point_Type_Declaration
14106 Loc
: constant Source_Ptr
:= Sloc
(Def
);
14107 Digs_Expr
: constant Node_Id
:= Digits_Expression
(Def
);
14108 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
14109 Implicit_Base
: Entity_Id
;
14116 Check_SPARK_05_Restriction
14117 ("decimal fixed point type is not allowed", Def
);
14118 Check_Restriction
(No_Fixed_Point
, Def
);
14120 -- Create implicit base type
14123 Create_Itype
(E_Decimal_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
14124 Set_Etype
(Implicit_Base
, Implicit_Base
);
14126 -- Analyze and process delta expression
14128 Analyze_And_Resolve
(Delta_Expr
, Universal_Real
);
14130 Check_Delta_Expression
(Delta_Expr
);
14131 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
14133 -- Check delta is power of 10, and determine scale value from it
14139 Scale_Val
:= Uint_0
;
14142 if Val
< Ureal_1
then
14143 while Val
< Ureal_1
loop
14144 Val
:= Val
* Ureal_10
;
14145 Scale_Val
:= Scale_Val
+ 1;
14148 if Scale_Val
> 18 then
14149 Error_Msg_N
("scale exceeds maximum value of 18", Def
);
14150 Scale_Val
:= UI_From_Int
(+18);
14154 while Val
> Ureal_1
loop
14155 Val
:= Val
/ Ureal_10
;
14156 Scale_Val
:= Scale_Val
- 1;
14159 if Scale_Val
< -18 then
14160 Error_Msg_N
("scale is less than minimum value of -18", Def
);
14161 Scale_Val
:= UI_From_Int
(-18);
14165 if Val
/= Ureal_1
then
14166 Error_Msg_N
("delta expression must be a power of 10", Def
);
14167 Delta_Val
:= Ureal_10
** (-Scale_Val
);
14171 -- Set delta, scale and small (small = delta for decimal type)
14173 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
14174 Set_Scale_Value
(Implicit_Base
, Scale_Val
);
14175 Set_Small_Value
(Implicit_Base
, Delta_Val
);
14177 -- Analyze and process digits expression
14179 Analyze_And_Resolve
(Digs_Expr
, Any_Integer
);
14180 Check_Digits_Expression
(Digs_Expr
);
14181 Digs_Val
:= Expr_Value
(Digs_Expr
);
14183 if Digs_Val
> 18 then
14184 Digs_Val
:= UI_From_Int
(+18);
14185 Error_Msg_N
("digits value out of range, maximum is 18", Digs_Expr
);
14188 Set_Digits_Value
(Implicit_Base
, Digs_Val
);
14189 Bound_Val
:= UR_From_Uint
(10 ** Digs_Val
- 1) * Delta_Val
;
14191 -- Set range of base type from digits value for now. This will be
14192 -- expanded to represent the true underlying base range by Freeze.
14194 Set_Fixed_Range
(Implicit_Base
, Loc
, -Bound_Val
, Bound_Val
);
14196 -- Note: We leave size as zero for now, size will be set at freeze
14197 -- time. We have to do this for ordinary fixed-point, because the size
14198 -- depends on the specified small, and we might as well do the same for
14199 -- decimal fixed-point.
14201 pragma Assert
(Esize
(Implicit_Base
) = Uint_0
);
14203 -- If there are bounds given in the declaration use them as the
14204 -- bounds of the first named subtype.
14206 if Present
(Real_Range_Specification
(Def
)) then
14208 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
14209 Low
: constant Node_Id
:= Low_Bound
(RRS
);
14210 High
: constant Node_Id
:= High_Bound
(RRS
);
14215 Analyze_And_Resolve
(Low
, Any_Real
);
14216 Analyze_And_Resolve
(High
, Any_Real
);
14217 Check_Real_Bound
(Low
);
14218 Check_Real_Bound
(High
);
14219 Low_Val
:= Expr_Value_R
(Low
);
14220 High_Val
:= Expr_Value_R
(High
);
14222 if Low_Val
< (-Bound_Val
) then
14224 ("range low bound too small for digits value", Low
);
14225 Low_Val
:= -Bound_Val
;
14228 if High_Val
> Bound_Val
then
14230 ("range high bound too large for digits value", High
);
14231 High_Val
:= Bound_Val
;
14234 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
14237 -- If no explicit range, use range that corresponds to given
14238 -- digits value. This will end up as the final range for the
14242 Set_Fixed_Range
(T
, Loc
, -Bound_Val
, Bound_Val
);
14245 -- Complete entity for first subtype. The inheritance of the rep item
14246 -- chain ensures that SPARK-related pragmas are not clobbered when the
14247 -- decimal fixed point type acts as a full view of a private type.
14249 Set_Ekind
(T
, E_Decimal_Fixed_Point_Subtype
);
14250 Set_Etype
(T
, Implicit_Base
);
14251 Set_Size_Info
(T
, Implicit_Base
);
14252 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
14253 Set_Digits_Value
(T
, Digs_Val
);
14254 Set_Delta_Value
(T
, Delta_Val
);
14255 Set_Small_Value
(T
, Delta_Val
);
14256 Set_Scale_Value
(T
, Scale_Val
);
14257 Set_Is_Constrained
(T
);
14258 end Decimal_Fixed_Point_Type_Declaration
;
14260 -----------------------------------
14261 -- Derive_Progenitor_Subprograms --
14262 -----------------------------------
14264 procedure Derive_Progenitor_Subprograms
14265 (Parent_Type
: Entity_Id
;
14266 Tagged_Type
: Entity_Id
)
14271 Iface_Elmt
: Elmt_Id
;
14272 Iface_Subp
: Entity_Id
;
14273 New_Subp
: Entity_Id
:= Empty
;
14274 Prim_Elmt
: Elmt_Id
;
14279 pragma Assert
(Ada_Version
>= Ada_2005
14280 and then Is_Record_Type
(Tagged_Type
)
14281 and then Is_Tagged_Type
(Tagged_Type
)
14282 and then Has_Interfaces
(Tagged_Type
));
14284 -- Step 1: Transfer to the full-view primitives associated with the
14285 -- partial-view that cover interface primitives. Conceptually this
14286 -- work should be done later by Process_Full_View; done here to
14287 -- simplify its implementation at later stages. It can be safely
14288 -- done here because interfaces must be visible in the partial and
14289 -- private view (RM 7.3(7.3/2)).
14291 -- Small optimization: This work is only required if the parent may
14292 -- have entities whose Alias attribute reference an interface primitive.
14293 -- Such a situation may occur if the parent is an abstract type and the
14294 -- primitive has not been yet overridden or if the parent is a generic
14295 -- formal type covering interfaces.
14297 -- If the tagged type is not abstract, it cannot have abstract
14298 -- primitives (the only entities in the list of primitives of
14299 -- non-abstract tagged types that can reference abstract primitives
14300 -- through its Alias attribute are the internal entities that have
14301 -- attribute Interface_Alias, and these entities are generated later
14302 -- by Add_Internal_Interface_Entities).
14304 if In_Private_Part
(Current_Scope
)
14305 and then (Is_Abstract_Type
(Parent_Type
)
14307 Is_Generic_Type
(Parent_Type
))
14309 Elmt
:= First_Elmt
(Primitive_Operations
(Tagged_Type
));
14310 while Present
(Elmt
) loop
14311 Subp
:= Node
(Elmt
);
14313 -- At this stage it is not possible to have entities in the list
14314 -- of primitives that have attribute Interface_Alias.
14316 pragma Assert
(No
(Interface_Alias
(Subp
)));
14318 Typ
:= Find_Dispatching_Type
(Ultimate_Alias
(Subp
));
14320 if Is_Interface
(Typ
) then
14321 E
:= Find_Primitive_Covering_Interface
14322 (Tagged_Type
=> Tagged_Type
,
14323 Iface_Prim
=> Subp
);
14326 and then Find_Dispatching_Type
(Ultimate_Alias
(E
)) /= Typ
14328 Replace_Elmt
(Elmt
, E
);
14329 Remove_Homonym
(Subp
);
14337 -- Step 2: Add primitives of progenitors that are not implemented by
14338 -- parents of Tagged_Type.
14340 if Present
(Interfaces
(Base_Type
(Tagged_Type
))) then
14341 Iface_Elmt
:= First_Elmt
(Interfaces
(Base_Type
(Tagged_Type
)));
14342 while Present
(Iface_Elmt
) loop
14343 Iface
:= Node
(Iface_Elmt
);
14345 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
14346 while Present
(Prim_Elmt
) loop
14347 Iface_Subp
:= Node
(Prim_Elmt
);
14349 -- Exclude derivation of predefined primitives except those
14350 -- that come from source, or are inherited from one that comes
14351 -- from source. Required to catch declarations of equality
14352 -- operators of interfaces. For example:
14354 -- type Iface is interface;
14355 -- function "=" (Left, Right : Iface) return Boolean;
14357 if not Is_Predefined_Dispatching_Operation
(Iface_Subp
)
14358 or else Comes_From_Source
(Ultimate_Alias
(Iface_Subp
))
14360 E
:= Find_Primitive_Covering_Interface
14361 (Tagged_Type
=> Tagged_Type
,
14362 Iface_Prim
=> Iface_Subp
);
14364 -- If not found we derive a new primitive leaving its alias
14365 -- attribute referencing the interface primitive.
14369 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
14371 -- Ada 2012 (AI05-0197): If the covering primitive's name
14372 -- differs from the name of the interface primitive then it
14373 -- is a private primitive inherited from a parent type. In
14374 -- such case, given that Tagged_Type covers the interface,
14375 -- the inherited private primitive becomes visible. For such
14376 -- purpose we add a new entity that renames the inherited
14377 -- private primitive.
14379 elsif Chars
(E
) /= Chars
(Iface_Subp
) then
14380 pragma Assert
(Has_Suffix
(E
, 'P'));
14382 (New_Subp
, Iface_Subp
, Tagged_Type
, Iface
);
14383 Set_Alias
(New_Subp
, E
);
14384 Set_Is_Abstract_Subprogram
(New_Subp
,
14385 Is_Abstract_Subprogram
(E
));
14387 -- Propagate to the full view interface entities associated
14388 -- with the partial view.
14390 elsif In_Private_Part
(Current_Scope
)
14391 and then Present
(Alias
(E
))
14392 and then Alias
(E
) = Iface_Subp
14394 List_Containing
(Parent
(E
)) /=
14395 Private_Declarations
14397 (Unit_Declaration_Node
(Current_Scope
)))
14399 Append_Elmt
(E
, Primitive_Operations
(Tagged_Type
));
14403 Next_Elmt
(Prim_Elmt
);
14406 Next_Elmt
(Iface_Elmt
);
14409 end Derive_Progenitor_Subprograms
;
14411 -----------------------
14412 -- Derive_Subprogram --
14413 -----------------------
14415 procedure Derive_Subprogram
14416 (New_Subp
: in out Entity_Id
;
14417 Parent_Subp
: Entity_Id
;
14418 Derived_Type
: Entity_Id
;
14419 Parent_Type
: Entity_Id
;
14420 Actual_Subp
: Entity_Id
:= Empty
)
14422 Formal
: Entity_Id
;
14423 -- Formal parameter of parent primitive operation
14425 Formal_Of_Actual
: Entity_Id
;
14426 -- Formal parameter of actual operation, when the derivation is to
14427 -- create a renaming for a primitive operation of an actual in an
14430 New_Formal
: Entity_Id
;
14431 -- Formal of inherited operation
14433 Visible_Subp
: Entity_Id
:= Parent_Subp
;
14435 function Is_Private_Overriding
return Boolean;
14436 -- If Subp is a private overriding of a visible operation, the inherited
14437 -- operation derives from the overridden op (even though its body is the
14438 -- overriding one) and the inherited operation is visible now. See
14439 -- sem_disp to see the full details of the handling of the overridden
14440 -- subprogram, which is removed from the list of primitive operations of
14441 -- the type. The overridden subprogram is saved locally in Visible_Subp,
14442 -- and used to diagnose abstract operations that need overriding in the
14445 procedure Replace_Type
(Id
, New_Id
: Entity_Id
);
14446 -- When the type is an anonymous access type, create a new access type
14447 -- designating the derived type.
14449 procedure Set_Derived_Name
;
14450 -- This procedure sets the appropriate Chars name for New_Subp. This
14451 -- is normally just a copy of the parent name. An exception arises for
14452 -- type support subprograms, where the name is changed to reflect the
14453 -- name of the derived type, e.g. if type foo is derived from type bar,
14454 -- then a procedure barDA is derived with a name fooDA.
14456 ---------------------------
14457 -- Is_Private_Overriding --
14458 ---------------------------
14460 function Is_Private_Overriding
return Boolean is
14464 -- If the parent is not a dispatching operation there is no
14465 -- need to investigate overridings
14467 if not Is_Dispatching_Operation
(Parent_Subp
) then
14471 -- The visible operation that is overridden is a homonym of the
14472 -- parent subprogram. We scan the homonym chain to find the one
14473 -- whose alias is the subprogram we are deriving.
14475 Prev
:= Current_Entity
(Parent_Subp
);
14476 while Present
(Prev
) loop
14477 if Ekind
(Prev
) = Ekind
(Parent_Subp
)
14478 and then Alias
(Prev
) = Parent_Subp
14479 and then Scope
(Parent_Subp
) = Scope
(Prev
)
14480 and then not Is_Hidden
(Prev
)
14482 Visible_Subp
:= Prev
;
14486 Prev
:= Homonym
(Prev
);
14490 end Is_Private_Overriding
;
14496 procedure Replace_Type
(Id
, New_Id
: Entity_Id
) is
14497 Id_Type
: constant Entity_Id
:= Etype
(Id
);
14498 Acc_Type
: Entity_Id
;
14499 Par
: constant Node_Id
:= Parent
(Derived_Type
);
14502 -- When the type is an anonymous access type, create a new access
14503 -- type designating the derived type. This itype must be elaborated
14504 -- at the point of the derivation, not on subsequent calls that may
14505 -- be out of the proper scope for Gigi, so we insert a reference to
14506 -- it after the derivation.
14508 if Ekind
(Id_Type
) = E_Anonymous_Access_Type
then
14510 Desig_Typ
: Entity_Id
:= Designated_Type
(Id_Type
);
14513 if Ekind
(Desig_Typ
) = E_Record_Type_With_Private
14514 and then Present
(Full_View
(Desig_Typ
))
14515 and then not Is_Private_Type
(Parent_Type
)
14517 Desig_Typ
:= Full_View
(Desig_Typ
);
14520 if Base_Type
(Desig_Typ
) = Base_Type
(Parent_Type
)
14522 -- Ada 2005 (AI-251): Handle also derivations of abstract
14523 -- interface primitives.
14525 or else (Is_Interface
(Desig_Typ
)
14526 and then not Is_Class_Wide_Type
(Desig_Typ
))
14528 Acc_Type
:= New_Copy
(Id_Type
);
14529 Set_Etype
(Acc_Type
, Acc_Type
);
14530 Set_Scope
(Acc_Type
, New_Subp
);
14532 -- Set size of anonymous access type. If we have an access
14533 -- to an unconstrained array, this is a fat pointer, so it
14534 -- is sizes at twice addtress size.
14536 if Is_Array_Type
(Desig_Typ
)
14537 and then not Is_Constrained
(Desig_Typ
)
14539 Init_Size
(Acc_Type
, 2 * System_Address_Size
);
14541 -- Other cases use a thin pointer
14544 Init_Size
(Acc_Type
, System_Address_Size
);
14547 -- Set remaining characterstics of anonymous access type
14549 Init_Alignment
(Acc_Type
);
14550 Set_Directly_Designated_Type
(Acc_Type
, Derived_Type
);
14552 Set_Etype
(New_Id
, Acc_Type
);
14553 Set_Scope
(New_Id
, New_Subp
);
14555 -- Create a reference to it
14557 Build_Itype_Reference
(Acc_Type
, Parent
(Derived_Type
));
14560 Set_Etype
(New_Id
, Id_Type
);
14564 -- In Ada2012, a formal may have an incomplete type but the type
14565 -- derivation that inherits the primitive follows the full view.
14567 elsif Base_Type
(Id_Type
) = Base_Type
(Parent_Type
)
14569 (Ekind
(Id_Type
) = E_Record_Type_With_Private
14570 and then Present
(Full_View
(Id_Type
))
14572 Base_Type
(Full_View
(Id_Type
)) = Base_Type
(Parent_Type
))
14574 (Ada_Version
>= Ada_2012
14575 and then Ekind
(Id_Type
) = E_Incomplete_Type
14576 and then Full_View
(Id_Type
) = Parent_Type
)
14578 -- Constraint checks on formals are generated during expansion,
14579 -- based on the signature of the original subprogram. The bounds
14580 -- of the derived type are not relevant, and thus we can use
14581 -- the base type for the formals. However, the return type may be
14582 -- used in a context that requires that the proper static bounds
14583 -- be used (a case statement, for example) and for those cases
14584 -- we must use the derived type (first subtype), not its base.
14586 -- If the derived_type_definition has no constraints, we know that
14587 -- the derived type has the same constraints as the first subtype
14588 -- of the parent, and we can also use it rather than its base,
14589 -- which can lead to more efficient code.
14591 if Etype
(Id
) = Parent_Type
then
14592 if Is_Scalar_Type
(Parent_Type
)
14594 Subtypes_Statically_Compatible
(Parent_Type
, Derived_Type
)
14596 Set_Etype
(New_Id
, Derived_Type
);
14598 elsif Nkind
(Par
) = N_Full_Type_Declaration
14600 Nkind
(Type_Definition
(Par
)) = N_Derived_Type_Definition
14603 (Subtype_Indication
(Type_Definition
(Par
)))
14605 Set_Etype
(New_Id
, Derived_Type
);
14608 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
14612 Set_Etype
(New_Id
, Base_Type
(Derived_Type
));
14616 Set_Etype
(New_Id
, Etype
(Id
));
14620 ----------------------
14621 -- Set_Derived_Name --
14622 ----------------------
14624 procedure Set_Derived_Name
is
14625 Nm
: constant TSS_Name_Type
:= Get_TSS_Name
(Parent_Subp
);
14627 if Nm
= TSS_Null
then
14628 Set_Chars
(New_Subp
, Chars
(Parent_Subp
));
14630 Set_Chars
(New_Subp
, Make_TSS_Name
(Base_Type
(Derived_Type
), Nm
));
14632 end Set_Derived_Name
;
14634 -- Start of processing for Derive_Subprogram
14637 New_Subp
:= New_Entity
(Nkind
(Parent_Subp
), Sloc
(Derived_Type
));
14638 Set_Ekind
(New_Subp
, Ekind
(Parent_Subp
));
14640 -- Check whether the inherited subprogram is a private operation that
14641 -- should be inherited but not yet made visible. Such subprograms can
14642 -- become visible at a later point (e.g., the private part of a public
14643 -- child unit) via Declare_Inherited_Private_Subprograms. If the
14644 -- following predicate is true, then this is not such a private
14645 -- operation and the subprogram simply inherits the name of the parent
14646 -- subprogram. Note the special check for the names of controlled
14647 -- operations, which are currently exempted from being inherited with
14648 -- a hidden name because they must be findable for generation of
14649 -- implicit run-time calls.
14651 if not Is_Hidden
(Parent_Subp
)
14652 or else Is_Internal
(Parent_Subp
)
14653 or else Is_Private_Overriding
14654 or else Is_Internal_Name
(Chars
(Parent_Subp
))
14655 or else Nam_In
(Chars
(Parent_Subp
), Name_Initialize
,
14661 -- An inherited dispatching equality will be overridden by an internally
14662 -- generated one, or by an explicit one, so preserve its name and thus
14663 -- its entry in the dispatch table. Otherwise, if Parent_Subp is a
14664 -- private operation it may become invisible if the full view has
14665 -- progenitors, and the dispatch table will be malformed.
14666 -- We check that the type is limited to handle the anomalous declaration
14667 -- of Limited_Controlled, which is derived from a non-limited type, and
14668 -- which is handled specially elsewhere as well.
14670 elsif Chars
(Parent_Subp
) = Name_Op_Eq
14671 and then Is_Dispatching_Operation
(Parent_Subp
)
14672 and then Etype
(Parent_Subp
) = Standard_Boolean
14673 and then not Is_Limited_Type
(Etype
(First_Formal
(Parent_Subp
)))
14675 Etype
(First_Formal
(Parent_Subp
)) =
14676 Etype
(Next_Formal
(First_Formal
(Parent_Subp
)))
14680 -- If parent is hidden, this can be a regular derivation if the
14681 -- parent is immediately visible in a non-instantiating context,
14682 -- or if we are in the private part of an instance. This test
14683 -- should still be refined ???
14685 -- The test for In_Instance_Not_Visible avoids inheriting the derived
14686 -- operation as a non-visible operation in cases where the parent
14687 -- subprogram might not be visible now, but was visible within the
14688 -- original generic, so it would be wrong to make the inherited
14689 -- subprogram non-visible now. (Not clear if this test is fully
14690 -- correct; are there any cases where we should declare the inherited
14691 -- operation as not visible to avoid it being overridden, e.g., when
14692 -- the parent type is a generic actual with private primitives ???)
14694 -- (they should be treated the same as other private inherited
14695 -- subprograms, but it's not clear how to do this cleanly). ???
14697 elsif (In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
14698 and then Is_Immediately_Visible
(Parent_Subp
)
14699 and then not In_Instance
)
14700 or else In_Instance_Not_Visible
14704 -- Ada 2005 (AI-251): Regular derivation if the parent subprogram
14705 -- overrides an interface primitive because interface primitives
14706 -- must be visible in the partial view of the parent (RM 7.3 (7.3/2))
14708 elsif Ada_Version
>= Ada_2005
14709 and then Is_Dispatching_Operation
(Parent_Subp
)
14710 and then Covers_Some_Interface
(Parent_Subp
)
14714 -- Otherwise, the type is inheriting a private operation, so enter
14715 -- it with a special name so it can't be overridden.
14718 Set_Chars
(New_Subp
, New_External_Name
(Chars
(Parent_Subp
), 'P'));
14721 Set_Parent
(New_Subp
, Parent
(Derived_Type
));
14723 if Present
(Actual_Subp
) then
14724 Replace_Type
(Actual_Subp
, New_Subp
);
14726 Replace_Type
(Parent_Subp
, New_Subp
);
14729 Conditional_Delay
(New_Subp
, Parent_Subp
);
14731 -- If we are creating a renaming for a primitive operation of an
14732 -- actual of a generic derived type, we must examine the signature
14733 -- of the actual primitive, not that of the generic formal, which for
14734 -- example may be an interface. However the name and initial value
14735 -- of the inherited operation are those of the formal primitive.
14737 Formal
:= First_Formal
(Parent_Subp
);
14739 if Present
(Actual_Subp
) then
14740 Formal_Of_Actual
:= First_Formal
(Actual_Subp
);
14742 Formal_Of_Actual
:= Empty
;
14745 while Present
(Formal
) loop
14746 New_Formal
:= New_Copy
(Formal
);
14748 -- Normally we do not go copying parents, but in the case of
14749 -- formals, we need to link up to the declaration (which is the
14750 -- parameter specification), and it is fine to link up to the
14751 -- original formal's parameter specification in this case.
14753 Set_Parent
(New_Formal
, Parent
(Formal
));
14754 Append_Entity
(New_Formal
, New_Subp
);
14756 if Present
(Formal_Of_Actual
) then
14757 Replace_Type
(Formal_Of_Actual
, New_Formal
);
14758 Next_Formal
(Formal_Of_Actual
);
14760 Replace_Type
(Formal
, New_Formal
);
14763 Next_Formal
(Formal
);
14766 -- If this derivation corresponds to a tagged generic actual, then
14767 -- primitive operations rename those of the actual. Otherwise the
14768 -- primitive operations rename those of the parent type, If the parent
14769 -- renames an intrinsic operator, so does the new subprogram. We except
14770 -- concatenation, which is always properly typed, and does not get
14771 -- expanded as other intrinsic operations.
14773 if No
(Actual_Subp
) then
14774 if Is_Intrinsic_Subprogram
(Parent_Subp
) then
14775 Set_Is_Intrinsic_Subprogram
(New_Subp
);
14777 if Present
(Alias
(Parent_Subp
))
14778 and then Chars
(Parent_Subp
) /= Name_Op_Concat
14780 Set_Alias
(New_Subp
, Alias
(Parent_Subp
));
14782 Set_Alias
(New_Subp
, Parent_Subp
);
14786 Set_Alias
(New_Subp
, Parent_Subp
);
14790 Set_Alias
(New_Subp
, Actual_Subp
);
14793 -- Inherit the "ghostness" from the parent subprogram
14795 if Is_Ghost_Entity
(Alias
(New_Subp
)) then
14796 Set_Is_Ghost_Entity
(New_Subp
);
14799 -- Derived subprograms of a tagged type must inherit the convention
14800 -- of the parent subprogram (a requirement of AI-117). Derived
14801 -- subprograms of untagged types simply get convention Ada by default.
14803 -- If the derived type is a tagged generic formal type with unknown
14804 -- discriminants, its convention is intrinsic (RM 6.3.1 (8)).
14806 -- However, if the type is derived from a generic formal, the further
14807 -- inherited subprogram has the convention of the non-generic ancestor.
14808 -- Otherwise there would be no way to override the operation.
14809 -- (This is subject to forthcoming ARG discussions).
14811 if Is_Tagged_Type
(Derived_Type
) then
14812 if Is_Generic_Type
(Derived_Type
)
14813 and then Has_Unknown_Discriminants
(Derived_Type
)
14815 Set_Convention
(New_Subp
, Convention_Intrinsic
);
14818 if Is_Generic_Type
(Parent_Type
)
14819 and then Has_Unknown_Discriminants
(Parent_Type
)
14821 Set_Convention
(New_Subp
, Convention
(Alias
(Parent_Subp
)));
14823 Set_Convention
(New_Subp
, Convention
(Parent_Subp
));
14828 -- Predefined controlled operations retain their name even if the parent
14829 -- is hidden (see above), but they are not primitive operations if the
14830 -- ancestor is not visible, for example if the parent is a private
14831 -- extension completed with a controlled extension. Note that a full
14832 -- type that is controlled can break privacy: the flag Is_Controlled is
14833 -- set on both views of the type.
14835 if Is_Controlled
(Parent_Type
)
14836 and then Nam_In
(Chars
(Parent_Subp
), Name_Initialize
,
14839 and then Is_Hidden
(Parent_Subp
)
14840 and then not Is_Visibly_Controlled
(Parent_Type
)
14842 Set_Is_Hidden
(New_Subp
);
14845 Set_Is_Imported
(New_Subp
, Is_Imported
(Parent_Subp
));
14846 Set_Is_Exported
(New_Subp
, Is_Exported
(Parent_Subp
));
14848 if Ekind
(Parent_Subp
) = E_Procedure
then
14849 Set_Is_Valued_Procedure
14850 (New_Subp
, Is_Valued_Procedure
(Parent_Subp
));
14852 Set_Has_Controlling_Result
14853 (New_Subp
, Has_Controlling_Result
(Parent_Subp
));
14856 -- No_Return must be inherited properly. If this is overridden in the
14857 -- case of a dispatching operation, then a check is made in Sem_Disp
14858 -- that the overriding operation is also No_Return (no such check is
14859 -- required for the case of non-dispatching operation.
14861 Set_No_Return
(New_Subp
, No_Return
(Parent_Subp
));
14863 -- A derived function with a controlling result is abstract. If the
14864 -- Derived_Type is a nonabstract formal generic derived type, then
14865 -- inherited operations are not abstract: the required check is done at
14866 -- instantiation time. If the derivation is for a generic actual, the
14867 -- function is not abstract unless the actual is.
14869 if Is_Generic_Type
(Derived_Type
)
14870 and then not Is_Abstract_Type
(Derived_Type
)
14874 -- Ada 2005 (AI-228): Calculate the "require overriding" and "abstract"
14875 -- properties of the subprogram, as defined in RM-3.9.3(4/2-6/2).
14877 -- A subprogram subject to pragma Extensions_Visible with value False
14878 -- requires overriding if the subprogram has at least one controlling
14879 -- OUT parameter (SPARK RM 6.1.7(6)).
14881 elsif Ada_Version
>= Ada_2005
14882 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
14883 or else (Is_Tagged_Type
(Derived_Type
)
14884 and then Etype
(New_Subp
) = Derived_Type
14885 and then not Is_Null_Extension
(Derived_Type
))
14886 or else (Is_Tagged_Type
(Derived_Type
)
14887 and then Ekind
(Etype
(New_Subp
)) =
14888 E_Anonymous_Access_Type
14889 and then Designated_Type
(Etype
(New_Subp
)) =
14891 and then not Is_Null_Extension
(Derived_Type
))
14892 or else (Comes_From_Source
(Alias
(New_Subp
))
14893 and then Is_EVF_Procedure
(Alias
(New_Subp
))))
14894 and then No
(Actual_Subp
)
14896 if not Is_Tagged_Type
(Derived_Type
)
14897 or else Is_Abstract_Type
(Derived_Type
)
14898 or else Is_Abstract_Subprogram
(Alias
(New_Subp
))
14900 Set_Is_Abstract_Subprogram
(New_Subp
);
14902 Set_Requires_Overriding
(New_Subp
);
14905 elsif Ada_Version
< Ada_2005
14906 and then (Is_Abstract_Subprogram
(Alias
(New_Subp
))
14907 or else (Is_Tagged_Type
(Derived_Type
)
14908 and then Etype
(New_Subp
) = Derived_Type
14909 and then No
(Actual_Subp
)))
14911 Set_Is_Abstract_Subprogram
(New_Subp
);
14913 -- AI05-0097 : an inherited operation that dispatches on result is
14914 -- abstract if the derived type is abstract, even if the parent type
14915 -- is concrete and the derived type is a null extension.
14917 elsif Has_Controlling_Result
(Alias
(New_Subp
))
14918 and then Is_Abstract_Type
(Etype
(New_Subp
))
14920 Set_Is_Abstract_Subprogram
(New_Subp
);
14922 -- Finally, if the parent type is abstract we must verify that all
14923 -- inherited operations are either non-abstract or overridden, or that
14924 -- the derived type itself is abstract (this check is performed at the
14925 -- end of a package declaration, in Check_Abstract_Overriding). A
14926 -- private overriding in the parent type will not be visible in the
14927 -- derivation if we are not in an inner package or in a child unit of
14928 -- the parent type, in which case the abstractness of the inherited
14929 -- operation is carried to the new subprogram.
14931 elsif Is_Abstract_Type
(Parent_Type
)
14932 and then not In_Open_Scopes
(Scope
(Parent_Type
))
14933 and then Is_Private_Overriding
14934 and then Is_Abstract_Subprogram
(Visible_Subp
)
14936 if No
(Actual_Subp
) then
14937 Set_Alias
(New_Subp
, Visible_Subp
);
14938 Set_Is_Abstract_Subprogram
(New_Subp
, True);
14941 -- If this is a derivation for an instance of a formal derived
14942 -- type, abstractness comes from the primitive operation of the
14943 -- actual, not from the operation inherited from the ancestor.
14945 Set_Is_Abstract_Subprogram
14946 (New_Subp
, Is_Abstract_Subprogram
(Actual_Subp
));
14950 New_Overloaded_Entity
(New_Subp
, Derived_Type
);
14952 -- Check for case of a derived subprogram for the instantiation of a
14953 -- formal derived tagged type, if so mark the subprogram as dispatching
14954 -- and inherit the dispatching attributes of the actual subprogram. The
14955 -- derived subprogram is effectively renaming of the actual subprogram,
14956 -- so it needs to have the same attributes as the actual.
14958 if Present
(Actual_Subp
)
14959 and then Is_Dispatching_Operation
(Actual_Subp
)
14961 Set_Is_Dispatching_Operation
(New_Subp
);
14963 if Present
(DTC_Entity
(Actual_Subp
)) then
14964 Set_DTC_Entity
(New_Subp
, DTC_Entity
(Actual_Subp
));
14965 Set_DT_Position_Value
(New_Subp
, DT_Position
(Actual_Subp
));
14969 -- Indicate that a derived subprogram does not require a body and that
14970 -- it does not require processing of default expressions.
14972 Set_Has_Completion
(New_Subp
);
14973 Set_Default_Expressions_Processed
(New_Subp
);
14975 if Ekind
(New_Subp
) = E_Function
then
14976 Set_Mechanism
(New_Subp
, Mechanism
(Parent_Subp
));
14978 end Derive_Subprogram
;
14980 ------------------------
14981 -- Derive_Subprograms --
14982 ------------------------
14984 procedure Derive_Subprograms
14985 (Parent_Type
: Entity_Id
;
14986 Derived_Type
: Entity_Id
;
14987 Generic_Actual
: Entity_Id
:= Empty
)
14989 Op_List
: constant Elist_Id
:=
14990 Collect_Primitive_Operations
(Parent_Type
);
14992 function Check_Derived_Type
return Boolean;
14993 -- Check that all the entities derived from Parent_Type are found in
14994 -- the list of primitives of Derived_Type exactly in the same order.
14996 procedure Derive_Interface_Subprogram
14997 (New_Subp
: in out Entity_Id
;
14999 Actual_Subp
: Entity_Id
);
15000 -- Derive New_Subp from the ultimate alias of the parent subprogram Subp
15001 -- (which is an interface primitive). If Generic_Actual is present then
15002 -- Actual_Subp is the actual subprogram corresponding with the generic
15003 -- subprogram Subp.
15005 function Check_Derived_Type
return Boolean is
15009 New_Subp
: Entity_Id
;
15014 -- Traverse list of entities in the current scope searching for
15015 -- an incomplete type whose full-view is derived type
15017 E
:= First_Entity
(Scope
(Derived_Type
));
15018 while Present
(E
) and then E
/= Derived_Type
loop
15019 if Ekind
(E
) = E_Incomplete_Type
15020 and then Present
(Full_View
(E
))
15021 and then Full_View
(E
) = Derived_Type
15023 -- Disable this test if Derived_Type completes an incomplete
15024 -- type because in such case more primitives can be added
15025 -- later to the list of primitives of Derived_Type by routine
15026 -- Process_Incomplete_Dependents
15031 E
:= Next_Entity
(E
);
15034 List
:= Collect_Primitive_Operations
(Derived_Type
);
15035 Elmt
:= First_Elmt
(List
);
15037 Op_Elmt
:= First_Elmt
(Op_List
);
15038 while Present
(Op_Elmt
) loop
15039 Subp
:= Node
(Op_Elmt
);
15040 New_Subp
:= Node
(Elmt
);
15042 -- At this early stage Derived_Type has no entities with attribute
15043 -- Interface_Alias. In addition, such primitives are always
15044 -- located at the end of the list of primitives of Parent_Type.
15045 -- Therefore, if found we can safely stop processing pending
15048 exit when Present
(Interface_Alias
(Subp
));
15050 -- Handle hidden entities
15052 if not Is_Predefined_Dispatching_Operation
(Subp
)
15053 and then Is_Hidden
(Subp
)
15055 if Present
(New_Subp
)
15056 and then Primitive_Names_Match
(Subp
, New_Subp
)
15062 if not Present
(New_Subp
)
15063 or else Ekind
(Subp
) /= Ekind
(New_Subp
)
15064 or else not Primitive_Names_Match
(Subp
, New_Subp
)
15072 Next_Elmt
(Op_Elmt
);
15076 end Check_Derived_Type
;
15078 ---------------------------------
15079 -- Derive_Interface_Subprogram --
15080 ---------------------------------
15082 procedure Derive_Interface_Subprogram
15083 (New_Subp
: in out Entity_Id
;
15085 Actual_Subp
: Entity_Id
)
15087 Iface_Subp
: constant Entity_Id
:= Ultimate_Alias
(Subp
);
15088 Iface_Type
: constant Entity_Id
:= Find_Dispatching_Type
(Iface_Subp
);
15091 pragma Assert
(Is_Interface
(Iface_Type
));
15094 (New_Subp
=> New_Subp
,
15095 Parent_Subp
=> Iface_Subp
,
15096 Derived_Type
=> Derived_Type
,
15097 Parent_Type
=> Iface_Type
,
15098 Actual_Subp
=> Actual_Subp
);
15100 -- Given that this new interface entity corresponds with a primitive
15101 -- of the parent that was not overridden we must leave it associated
15102 -- with its parent primitive to ensure that it will share the same
15103 -- dispatch table slot when overridden.
15105 if No
(Actual_Subp
) then
15106 Set_Alias
(New_Subp
, Subp
);
15108 -- For instantiations this is not needed since the previous call to
15109 -- Derive_Subprogram leaves the entity well decorated.
15112 pragma Assert
(Alias
(New_Subp
) = Actual_Subp
);
15115 end Derive_Interface_Subprogram
;
15119 Alias_Subp
: Entity_Id
;
15120 Act_List
: Elist_Id
;
15121 Act_Elmt
: Elmt_Id
;
15122 Act_Subp
: Entity_Id
:= Empty
;
15124 Need_Search
: Boolean := False;
15125 New_Subp
: Entity_Id
:= Empty
;
15126 Parent_Base
: Entity_Id
;
15129 -- Start of processing for Derive_Subprograms
15132 if Ekind
(Parent_Type
) = E_Record_Type_With_Private
15133 and then Has_Discriminants
(Parent_Type
)
15134 and then Present
(Full_View
(Parent_Type
))
15136 Parent_Base
:= Full_View
(Parent_Type
);
15138 Parent_Base
:= Parent_Type
;
15141 if Present
(Generic_Actual
) then
15142 Act_List
:= Collect_Primitive_Operations
(Generic_Actual
);
15143 Act_Elmt
:= First_Elmt
(Act_List
);
15145 Act_List
:= No_Elist
;
15146 Act_Elmt
:= No_Elmt
;
15149 -- Derive primitives inherited from the parent. Note that if the generic
15150 -- actual is present, this is not really a type derivation, it is a
15151 -- completion within an instance.
15153 -- Case 1: Derived_Type does not implement interfaces
15155 if not Is_Tagged_Type
(Derived_Type
)
15156 or else (not Has_Interfaces
(Derived_Type
)
15157 and then not (Present
(Generic_Actual
)
15158 and then Has_Interfaces
(Generic_Actual
)))
15160 Elmt
:= First_Elmt
(Op_List
);
15161 while Present
(Elmt
) loop
15162 Subp
:= Node
(Elmt
);
15164 -- Literals are derived earlier in the process of building the
15165 -- derived type, and are skipped here.
15167 if Ekind
(Subp
) = E_Enumeration_Literal
then
15170 -- The actual is a direct descendant and the common primitive
15171 -- operations appear in the same order.
15173 -- If the generic parent type is present, the derived type is an
15174 -- instance of a formal derived type, and within the instance its
15175 -- operations are those of the actual. We derive from the formal
15176 -- type but make the inherited operations aliases of the
15177 -- corresponding operations of the actual.
15180 pragma Assert
(No
(Node
(Act_Elmt
))
15181 or else (Primitive_Names_Match
(Subp
, Node
(Act_Elmt
))
15184 (Subp
, Node
(Act_Elmt
),
15185 Skip_Controlling_Formals
=> True)));
15188 (New_Subp
, Subp
, Derived_Type
, Parent_Base
, Node
(Act_Elmt
));
15190 if Present
(Act_Elmt
) then
15191 Next_Elmt
(Act_Elmt
);
15198 -- Case 2: Derived_Type implements interfaces
15201 -- If the parent type has no predefined primitives we remove
15202 -- predefined primitives from the list of primitives of generic
15203 -- actual to simplify the complexity of this algorithm.
15205 if Present
(Generic_Actual
) then
15207 Has_Predefined_Primitives
: Boolean := False;
15210 -- Check if the parent type has predefined primitives
15212 Elmt
:= First_Elmt
(Op_List
);
15213 while Present
(Elmt
) loop
15214 Subp
:= Node
(Elmt
);
15216 if Is_Predefined_Dispatching_Operation
(Subp
)
15217 and then not Comes_From_Source
(Ultimate_Alias
(Subp
))
15219 Has_Predefined_Primitives
:= True;
15226 -- Remove predefined primitives of Generic_Actual. We must use
15227 -- an auxiliary list because in case of tagged types the value
15228 -- returned by Collect_Primitive_Operations is the value stored
15229 -- in its Primitive_Operations attribute (and we don't want to
15230 -- modify its current contents).
15232 if not Has_Predefined_Primitives
then
15234 Aux_List
: constant Elist_Id
:= New_Elmt_List
;
15237 Elmt
:= First_Elmt
(Act_List
);
15238 while Present
(Elmt
) loop
15239 Subp
:= Node
(Elmt
);
15241 if not Is_Predefined_Dispatching_Operation
(Subp
)
15242 or else Comes_From_Source
(Subp
)
15244 Append_Elmt
(Subp
, Aux_List
);
15250 Act_List
:= Aux_List
;
15254 Act_Elmt
:= First_Elmt
(Act_List
);
15255 Act_Subp
:= Node
(Act_Elmt
);
15259 -- Stage 1: If the generic actual is not present we derive the
15260 -- primitives inherited from the parent type. If the generic parent
15261 -- type is present, the derived type is an instance of a formal
15262 -- derived type, and within the instance its operations are those of
15263 -- the actual. We derive from the formal type but make the inherited
15264 -- operations aliases of the corresponding operations of the actual.
15266 Elmt
:= First_Elmt
(Op_List
);
15267 while Present
(Elmt
) loop
15268 Subp
:= Node
(Elmt
);
15269 Alias_Subp
:= Ultimate_Alias
(Subp
);
15271 -- Do not derive internal entities of the parent that link
15272 -- interface primitives with their covering primitive. These
15273 -- entities will be added to this type when frozen.
15275 if Present
(Interface_Alias
(Subp
)) then
15279 -- If the generic actual is present find the corresponding
15280 -- operation in the generic actual. If the parent type is a
15281 -- direct ancestor of the derived type then, even if it is an
15282 -- interface, the operations are inherited from the primary
15283 -- dispatch table and are in the proper order. If we detect here
15284 -- that primitives are not in the same order we traverse the list
15285 -- of primitive operations of the actual to find the one that
15286 -- implements the interface primitive.
15290 (Present
(Generic_Actual
)
15291 and then Present
(Act_Subp
)
15293 (Primitive_Names_Match
(Subp
, Act_Subp
)
15295 Type_Conformant
(Subp
, Act_Subp
,
15296 Skip_Controlling_Formals
=> True)))
15298 pragma Assert
(not Is_Ancestor
(Parent_Base
, Generic_Actual
,
15299 Use_Full_View
=> True));
15301 -- Remember that we need searching for all pending primitives
15303 Need_Search
:= True;
15305 -- Handle entities associated with interface primitives
15307 if Present
(Alias_Subp
)
15308 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
15309 and then not Is_Predefined_Dispatching_Operation
(Subp
)
15311 -- Search for the primitive in the homonym chain
15314 Find_Primitive_Covering_Interface
15315 (Tagged_Type
=> Generic_Actual
,
15316 Iface_Prim
=> Alias_Subp
);
15318 -- Previous search may not locate primitives covering
15319 -- interfaces defined in generics units or instantiations.
15320 -- (it fails if the covering primitive has formals whose
15321 -- type is also defined in generics or instantiations).
15322 -- In such case we search in the list of primitives of the
15323 -- generic actual for the internal entity that links the
15324 -- interface primitive and the covering primitive.
15327 and then Is_Generic_Type
(Parent_Type
)
15329 -- This code has been designed to handle only generic
15330 -- formals that implement interfaces that are defined
15331 -- in a generic unit or instantiation. If this code is
15332 -- needed for other cases we must review it because
15333 -- (given that it relies on Original_Location to locate
15334 -- the primitive of Generic_Actual that covers the
15335 -- interface) it could leave linked through attribute
15336 -- Alias entities of unrelated instantiations).
15340 (Scope
(Find_Dispatching_Type
(Alias_Subp
)))
15342 Instantiation_Depth
15343 (Sloc
(Find_Dispatching_Type
(Alias_Subp
))) > 0);
15346 Iface_Prim_Loc
: constant Source_Ptr
:=
15347 Original_Location
(Sloc
(Alias_Subp
));
15354 First_Elmt
(Primitive_Operations
(Generic_Actual
));
15356 Search
: while Present
(Elmt
) loop
15357 Prim
:= Node
(Elmt
);
15359 if Present
(Interface_Alias
(Prim
))
15360 and then Original_Location
15361 (Sloc
(Interface_Alias
(Prim
))) =
15364 Act_Subp
:= Alias
(Prim
);
15373 pragma Assert
(Present
(Act_Subp
)
15374 or else Is_Abstract_Type
(Generic_Actual
)
15375 or else Serious_Errors_Detected
> 0);
15377 -- Handle predefined primitives plus the rest of user-defined
15381 Act_Elmt
:= First_Elmt
(Act_List
);
15382 while Present
(Act_Elmt
) loop
15383 Act_Subp
:= Node
(Act_Elmt
);
15385 exit when Primitive_Names_Match
(Subp
, Act_Subp
)
15386 and then Type_Conformant
15388 Skip_Controlling_Formals
=> True)
15389 and then No
(Interface_Alias
(Act_Subp
));
15391 Next_Elmt
(Act_Elmt
);
15394 if No
(Act_Elmt
) then
15400 -- Case 1: If the parent is a limited interface then it has the
15401 -- predefined primitives of synchronized interfaces. However, the
15402 -- actual type may be a non-limited type and hence it does not
15403 -- have such primitives.
15405 if Present
(Generic_Actual
)
15406 and then not Present
(Act_Subp
)
15407 and then Is_Limited_Interface
(Parent_Base
)
15408 and then Is_Predefined_Interface_Primitive
(Subp
)
15412 -- Case 2: Inherit entities associated with interfaces that were
15413 -- not covered by the parent type. We exclude here null interface
15414 -- primitives because they do not need special management.
15416 -- We also exclude interface operations that are renamings. If the
15417 -- subprogram is an explicit renaming of an interface primitive,
15418 -- it is a regular primitive operation, and the presence of its
15419 -- alias is not relevant: it has to be derived like any other
15422 elsif Present
(Alias
(Subp
))
15423 and then Nkind
(Unit_Declaration_Node
(Subp
)) /=
15424 N_Subprogram_Renaming_Declaration
15425 and then Is_Interface
(Find_Dispatching_Type
(Alias_Subp
))
15427 (Nkind
(Parent
(Alias_Subp
)) = N_Procedure_Specification
15428 and then Null_Present
(Parent
(Alias_Subp
)))
15430 -- If this is an abstract private type then we transfer the
15431 -- derivation of the interface primitive from the partial view
15432 -- to the full view. This is safe because all the interfaces
15433 -- must be visible in the partial view. Done to avoid adding
15434 -- a new interface derivation to the private part of the
15435 -- enclosing package; otherwise this new derivation would be
15436 -- decorated as hidden when the analysis of the enclosing
15437 -- package completes.
15439 if Is_Abstract_Type
(Derived_Type
)
15440 and then In_Private_Part
(Current_Scope
)
15441 and then Has_Private_Declaration
(Derived_Type
)
15444 Partial_View
: Entity_Id
;
15449 Partial_View
:= First_Entity
(Current_Scope
);
15451 exit when No
(Partial_View
)
15452 or else (Has_Private_Declaration
(Partial_View
)
15454 Full_View
(Partial_View
) = Derived_Type
);
15456 Next_Entity
(Partial_View
);
15459 -- If the partial view was not found then the source code
15460 -- has errors and the derivation is not needed.
15462 if Present
(Partial_View
) then
15464 First_Elmt
(Primitive_Operations
(Partial_View
));
15465 while Present
(Elmt
) loop
15466 Ent
:= Node
(Elmt
);
15468 if Present
(Alias
(Ent
))
15469 and then Ultimate_Alias
(Ent
) = Alias
(Subp
)
15472 (Ent
, Primitive_Operations
(Derived_Type
));
15479 -- If the interface primitive was not found in the
15480 -- partial view then this interface primitive was
15481 -- overridden. We add a derivation to activate in
15482 -- Derive_Progenitor_Subprograms the machinery to
15486 Derive_Interface_Subprogram
15487 (New_Subp
=> New_Subp
,
15489 Actual_Subp
=> Act_Subp
);
15494 Derive_Interface_Subprogram
15495 (New_Subp
=> New_Subp
,
15497 Actual_Subp
=> Act_Subp
);
15500 -- Case 3: Common derivation
15504 (New_Subp
=> New_Subp
,
15505 Parent_Subp
=> Subp
,
15506 Derived_Type
=> Derived_Type
,
15507 Parent_Type
=> Parent_Base
,
15508 Actual_Subp
=> Act_Subp
);
15511 -- No need to update Act_Elm if we must search for the
15512 -- corresponding operation in the generic actual
15515 and then Present
(Act_Elmt
)
15517 Next_Elmt
(Act_Elmt
);
15518 Act_Subp
:= Node
(Act_Elmt
);
15525 -- Inherit additional operations from progenitors. If the derived
15526 -- type is a generic actual, there are not new primitive operations
15527 -- for the type because it has those of the actual, and therefore
15528 -- nothing needs to be done. The renamings generated above are not
15529 -- primitive operations, and their purpose is simply to make the
15530 -- proper operations visible within an instantiation.
15532 if No
(Generic_Actual
) then
15533 Derive_Progenitor_Subprograms
(Parent_Base
, Derived_Type
);
15537 -- Final check: Direct descendants must have their primitives in the
15538 -- same order. We exclude from this test untagged types and instances
15539 -- of formal derived types. We skip this test if we have already
15540 -- reported serious errors in the sources.
15542 pragma Assert
(not Is_Tagged_Type
(Derived_Type
)
15543 or else Present
(Generic_Actual
)
15544 or else Serious_Errors_Detected
> 0
15545 or else Check_Derived_Type
);
15546 end Derive_Subprograms
;
15548 --------------------------------
15549 -- Derived_Standard_Character --
15550 --------------------------------
15552 procedure Derived_Standard_Character
15554 Parent_Type
: Entity_Id
;
15555 Derived_Type
: Entity_Id
)
15557 Loc
: constant Source_Ptr
:= Sloc
(N
);
15558 Def
: constant Node_Id
:= Type_Definition
(N
);
15559 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
15560 Parent_Base
: constant Entity_Id
:= Base_Type
(Parent_Type
);
15561 Implicit_Base
: constant Entity_Id
:=
15563 (E_Enumeration_Type
, N
, Derived_Type
, 'B');
15569 Discard_Node
(Process_Subtype
(Indic
, N
));
15571 Set_Etype
(Implicit_Base
, Parent_Base
);
15572 Set_Size_Info
(Implicit_Base
, Root_Type
(Parent_Type
));
15573 Set_RM_Size
(Implicit_Base
, RM_Size
(Root_Type
(Parent_Type
)));
15575 Set_Is_Character_Type
(Implicit_Base
, True);
15576 Set_Has_Delayed_Freeze
(Implicit_Base
);
15578 -- The bounds of the implicit base are the bounds of the parent base.
15579 -- Note that their type is the parent base.
15581 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Base
));
15582 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Base
));
15584 Set_Scalar_Range
(Implicit_Base
,
15587 High_Bound
=> Hi
));
15589 Conditional_Delay
(Derived_Type
, Parent_Type
);
15591 Set_Ekind
(Derived_Type
, E_Enumeration_Subtype
);
15592 Set_Etype
(Derived_Type
, Implicit_Base
);
15593 Set_Size_Info
(Derived_Type
, Parent_Type
);
15595 if Unknown_RM_Size
(Derived_Type
) then
15596 Set_RM_Size
(Derived_Type
, RM_Size
(Parent_Type
));
15599 Set_Is_Character_Type
(Derived_Type
, True);
15601 if Nkind
(Indic
) /= N_Subtype_Indication
then
15603 -- If no explicit constraint, the bounds are those
15604 -- of the parent type.
15606 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Parent_Type
));
15607 Hi
:= New_Copy_Tree
(Type_High_Bound
(Parent_Type
));
15608 Set_Scalar_Range
(Derived_Type
, Make_Range
(Loc
, Lo
, Hi
));
15611 Convert_Scalar_Bounds
(N
, Parent_Type
, Derived_Type
, Loc
);
15613 -- Because the implicit base is used in the conversion of the bounds, we
15614 -- have to freeze it now. This is similar to what is done for numeric
15615 -- types, and it equally suspicious, but otherwise a non-static bound
15616 -- will have a reference to an unfrozen type, which is rejected by Gigi
15617 -- (???). This requires specific care for definition of stream
15618 -- attributes. For details, see comments at the end of
15619 -- Build_Derived_Numeric_Type.
15621 Freeze_Before
(N
, Implicit_Base
);
15622 end Derived_Standard_Character
;
15624 ------------------------------
15625 -- Derived_Type_Declaration --
15626 ------------------------------
15628 procedure Derived_Type_Declaration
15631 Is_Completion
: Boolean)
15633 Parent_Type
: Entity_Id
;
15635 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean;
15636 -- Check whether the parent type is a generic formal, or derives
15637 -- directly or indirectly from one.
15639 ------------------------
15640 -- Comes_From_Generic --
15641 ------------------------
15643 function Comes_From_Generic
(Typ
: Entity_Id
) return Boolean is
15645 if Is_Generic_Type
(Typ
) then
15648 elsif Is_Generic_Type
(Root_Type
(Parent_Type
)) then
15651 elsif Is_Private_Type
(Typ
)
15652 and then Present
(Full_View
(Typ
))
15653 and then Is_Generic_Type
(Root_Type
(Full_View
(Typ
)))
15657 elsif Is_Generic_Actual_Type
(Typ
) then
15663 end Comes_From_Generic
;
15667 Def
: constant Node_Id
:= Type_Definition
(N
);
15668 Iface_Def
: Node_Id
;
15669 Indic
: constant Node_Id
:= Subtype_Indication
(Def
);
15670 Extension
: constant Node_Id
:= Record_Extension_Part
(Def
);
15671 Parent_Node
: Node_Id
;
15674 -- Start of processing for Derived_Type_Declaration
15677 Parent_Type
:= Find_Type_Of_Subtype_Indic
(Indic
);
15679 -- Ada 2005 (AI-251): In case of interface derivation check that the
15680 -- parent is also an interface.
15682 if Interface_Present
(Def
) then
15683 Check_SPARK_05_Restriction
("interface is not allowed", Def
);
15685 if not Is_Interface
(Parent_Type
) then
15686 Diagnose_Interface
(Indic
, Parent_Type
);
15689 Parent_Node
:= Parent
(Base_Type
(Parent_Type
));
15690 Iface_Def
:= Type_Definition
(Parent_Node
);
15692 -- Ada 2005 (AI-251): Limited interfaces can only inherit from
15693 -- other limited interfaces.
15695 if Limited_Present
(Def
) then
15696 if Limited_Present
(Iface_Def
) then
15699 elsif Protected_Present
(Iface_Def
) then
15701 ("descendant of& must be declared"
15702 & " as a protected interface",
15705 elsif Synchronized_Present
(Iface_Def
) then
15707 ("descendant of& must be declared"
15708 & " as a synchronized interface",
15711 elsif Task_Present
(Iface_Def
) then
15713 ("descendant of& must be declared as a task interface",
15718 ("(Ada 2005) limited interface cannot "
15719 & "inherit from non-limited interface", Indic
);
15722 -- Ada 2005 (AI-345): Non-limited interfaces can only inherit
15723 -- from non-limited or limited interfaces.
15725 elsif not Protected_Present
(Def
)
15726 and then not Synchronized_Present
(Def
)
15727 and then not Task_Present
(Def
)
15729 if Limited_Present
(Iface_Def
) then
15732 elsif Protected_Present
(Iface_Def
) then
15734 ("descendant of& must be declared"
15735 & " as a protected interface",
15738 elsif Synchronized_Present
(Iface_Def
) then
15740 ("descendant of& must be declared"
15741 & " as a synchronized interface",
15744 elsif Task_Present
(Iface_Def
) then
15746 ("descendant of& must be declared as a task interface",
15755 if Is_Tagged_Type
(Parent_Type
)
15756 and then Is_Concurrent_Type
(Parent_Type
)
15757 and then not Is_Interface
(Parent_Type
)
15760 ("parent type of a record extension cannot be "
15761 & "a synchronized tagged type (RM 3.9.1 (3/1))", N
);
15762 Set_Etype
(T
, Any_Type
);
15766 -- Ada 2005 (AI-251): Decorate all the names in the list of ancestor
15769 if Is_Tagged_Type
(Parent_Type
)
15770 and then Is_Non_Empty_List
(Interface_List
(Def
))
15777 Intf
:= First
(Interface_List
(Def
));
15778 while Present
(Intf
) loop
15779 T
:= Find_Type_Of_Subtype_Indic
(Intf
);
15781 if not Is_Interface
(T
) then
15782 Diagnose_Interface
(Intf
, T
);
15784 -- Check the rules of 3.9.4(12/2) and 7.5(2/2) that disallow
15785 -- a limited type from having a nonlimited progenitor.
15787 elsif (Limited_Present
(Def
)
15788 or else (not Is_Interface
(Parent_Type
)
15789 and then Is_Limited_Type
(Parent_Type
)))
15790 and then not Is_Limited_Interface
(T
)
15793 ("progenitor interface& of limited type must be limited",
15802 if Parent_Type
= Any_Type
15803 or else Etype
(Parent_Type
) = Any_Type
15804 or else (Is_Class_Wide_Type
(Parent_Type
)
15805 and then Etype
(Parent_Type
) = T
)
15807 -- If Parent_Type is undefined or illegal, make new type into a
15808 -- subtype of Any_Type, and set a few attributes to prevent cascaded
15809 -- errors. If this is a self-definition, emit error now.
15811 if T
= Parent_Type
or else T
= Etype
(Parent_Type
) then
15812 Error_Msg_N
("type cannot be used in its own definition", Indic
);
15815 Set_Ekind
(T
, Ekind
(Parent_Type
));
15816 Set_Etype
(T
, Any_Type
);
15817 Set_Scalar_Range
(T
, Scalar_Range
(Any_Type
));
15819 if Is_Tagged_Type
(T
)
15820 and then Is_Record_Type
(T
)
15822 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
15828 -- Ada 2005 (AI-251): The case in which the parent of the full-view is
15829 -- an interface is special because the list of interfaces in the full
15830 -- view can be given in any order. For example:
15832 -- type A is interface;
15833 -- type B is interface and A;
15834 -- type D is new B with private;
15836 -- type D is new A and B with null record; -- 1 --
15838 -- In this case we perform the following transformation of -1-:
15840 -- type D is new B and A with null record;
15842 -- If the parent of the full-view covers the parent of the partial-view
15843 -- we have two possible cases:
15845 -- 1) They have the same parent
15846 -- 2) The parent of the full-view implements some further interfaces
15848 -- In both cases we do not need to perform the transformation. In the
15849 -- first case the source program is correct and the transformation is
15850 -- not needed; in the second case the source program does not fulfill
15851 -- the no-hidden interfaces rule (AI-396) and the error will be reported
15854 -- This transformation not only simplifies the rest of the analysis of
15855 -- this type declaration but also simplifies the correct generation of
15856 -- the object layout to the expander.
15858 if In_Private_Part
(Current_Scope
)
15859 and then Is_Interface
(Parent_Type
)
15863 Partial_View
: Entity_Id
;
15864 Partial_View_Parent
: Entity_Id
;
15865 New_Iface
: Node_Id
;
15868 -- Look for the associated private type declaration
15870 Partial_View
:= First_Entity
(Current_Scope
);
15872 exit when No
(Partial_View
)
15873 or else (Has_Private_Declaration
(Partial_View
)
15874 and then Full_View
(Partial_View
) = T
);
15876 Next_Entity
(Partial_View
);
15879 -- If the partial view was not found then the source code has
15880 -- errors and the transformation is not needed.
15882 if Present
(Partial_View
) then
15883 Partial_View_Parent
:= Etype
(Partial_View
);
15885 -- If the parent of the full-view covers the parent of the
15886 -- partial-view we have nothing else to do.
15888 if Interface_Present_In_Ancestor
15889 (Parent_Type
, Partial_View_Parent
)
15893 -- Traverse the list of interfaces of the full-view to look
15894 -- for the parent of the partial-view and perform the tree
15898 Iface
:= First
(Interface_List
(Def
));
15899 while Present
(Iface
) loop
15900 if Etype
(Iface
) = Etype
(Partial_View
) then
15901 Rewrite
(Subtype_Indication
(Def
),
15902 New_Copy
(Subtype_Indication
15903 (Parent
(Partial_View
))));
15906 Make_Identifier
(Sloc
(N
), Chars
(Parent_Type
));
15907 Append
(New_Iface
, Interface_List
(Def
));
15909 -- Analyze the transformed code
15911 Derived_Type_Declaration
(T
, N
, Is_Completion
);
15922 -- Only composite types other than array types are allowed to have
15925 if Present
(Discriminant_Specifications
(N
)) then
15926 if (Is_Elementary_Type
(Parent_Type
)
15928 Is_Array_Type
(Parent_Type
))
15929 and then not Error_Posted
(N
)
15932 ("elementary or array type cannot have discriminants",
15933 Defining_Identifier
(First
(Discriminant_Specifications
(N
))));
15934 Set_Has_Discriminants
(T
, False);
15936 -- The type is allowed to have discriminants
15939 Check_SPARK_05_Restriction
("discriminant type is not allowed", N
);
15943 -- In Ada 83, a derived type defined in a package specification cannot
15944 -- be used for further derivation until the end of its visible part.
15945 -- Note that derivation in the private part of the package is allowed.
15947 if Ada_Version
= Ada_83
15948 and then Is_Derived_Type
(Parent_Type
)
15949 and then In_Visible_Part
(Scope
(Parent_Type
))
15951 if Ada_Version
= Ada_83
and then Comes_From_Source
(Indic
) then
15953 ("(Ada 83): premature use of type for derivation", Indic
);
15957 -- Check for early use of incomplete or private type
15959 if Ekind_In
(Parent_Type
, E_Void
, E_Incomplete_Type
) then
15960 Error_Msg_N
("premature derivation of incomplete type", Indic
);
15963 elsif (Is_Incomplete_Or_Private_Type
(Parent_Type
)
15964 and then not Comes_From_Generic
(Parent_Type
))
15965 or else Has_Private_Component
(Parent_Type
)
15967 -- The ancestor type of a formal type can be incomplete, in which
15968 -- case only the operations of the partial view are available in the
15969 -- generic. Subsequent checks may be required when the full view is
15970 -- analyzed to verify that a derivation from a tagged type has an
15973 if Nkind
(Original_Node
(N
)) = N_Formal_Type_Declaration
then
15976 elsif No
(Underlying_Type
(Parent_Type
))
15977 or else Has_Private_Component
(Parent_Type
)
15980 ("premature derivation of derived or private type", Indic
);
15982 -- Flag the type itself as being in error, this prevents some
15983 -- nasty problems with subsequent uses of the malformed type.
15985 Set_Error_Posted
(T
);
15987 -- Check that within the immediate scope of an untagged partial
15988 -- view it's illegal to derive from the partial view if the
15989 -- full view is tagged. (7.3(7))
15991 -- We verify that the Parent_Type is a partial view by checking
15992 -- that it is not a Full_Type_Declaration (i.e. a private type or
15993 -- private extension declaration), to distinguish a partial view
15994 -- from a derivation from a private type which also appears as
15995 -- E_Private_Type. If the parent base type is not declared in an
15996 -- enclosing scope there is no need to check.
15998 elsif Present
(Full_View
(Parent_Type
))
15999 and then Nkind
(Parent
(Parent_Type
)) /= N_Full_Type_Declaration
16000 and then not Is_Tagged_Type
(Parent_Type
)
16001 and then Is_Tagged_Type
(Full_View
(Parent_Type
))
16002 and then In_Open_Scopes
(Scope
(Base_Type
(Parent_Type
)))
16005 ("premature derivation from type with tagged full view",
16010 -- Check that form of derivation is appropriate
16012 Taggd
:= Is_Tagged_Type
(Parent_Type
);
16014 -- Set the parent type to the class-wide type's specific type in this
16015 -- case to prevent cascading errors
16017 if Present
(Extension
) and then Is_Class_Wide_Type
(Parent_Type
) then
16018 Error_Msg_N
("parent type must not be a class-wide type", Indic
);
16019 Set_Etype
(T
, Etype
(Parent_Type
));
16023 if Present
(Extension
) and then not Taggd
then
16025 ("type derived from untagged type cannot have extension", Indic
);
16027 elsif No
(Extension
) and then Taggd
then
16029 -- If this declaration is within a private part (or body) of a
16030 -- generic instantiation then the derivation is allowed (the parent
16031 -- type can only appear tagged in this case if it's a generic actual
16032 -- type, since it would otherwise have been rejected in the analysis
16033 -- of the generic template).
16035 if not Is_Generic_Actual_Type
(Parent_Type
)
16036 or else In_Visible_Part
(Scope
(Parent_Type
))
16038 if Is_Class_Wide_Type
(Parent_Type
) then
16040 ("parent type must not be a class-wide type", Indic
);
16042 -- Use specific type to prevent cascaded errors.
16044 Parent_Type
:= Etype
(Parent_Type
);
16048 ("type derived from tagged type must have extension", Indic
);
16053 -- AI-443: Synchronized formal derived types require a private
16054 -- extension. There is no point in checking the ancestor type or
16055 -- the progenitors since the construct is wrong to begin with.
16057 if Ada_Version
>= Ada_2005
16058 and then Is_Generic_Type
(T
)
16059 and then Present
(Original_Node
(N
))
16062 Decl
: constant Node_Id
:= Original_Node
(N
);
16065 if Nkind
(Decl
) = N_Formal_Type_Declaration
16066 and then Nkind
(Formal_Type_Definition
(Decl
)) =
16067 N_Formal_Derived_Type_Definition
16068 and then Synchronized_Present
(Formal_Type_Definition
(Decl
))
16069 and then No
(Extension
)
16071 -- Avoid emitting a duplicate error message
16073 and then not Error_Posted
(Indic
)
16076 ("synchronized derived type must have extension", N
);
16081 if Null_Exclusion_Present
(Def
)
16082 and then not Is_Access_Type
(Parent_Type
)
16084 Error_Msg_N
("null exclusion can only apply to an access type", N
);
16087 -- Avoid deriving parent primitives of underlying record views
16089 Build_Derived_Type
(N
, Parent_Type
, T
, Is_Completion
,
16090 Derive_Subps
=> not Is_Underlying_Record_View
(T
));
16092 -- AI-419: The parent type of an explicitly limited derived type must
16093 -- be a limited type or a limited interface.
16095 if Limited_Present
(Def
) then
16096 Set_Is_Limited_Record
(T
);
16098 if Is_Interface
(T
) then
16099 Set_Is_Limited_Interface
(T
);
16102 if not Is_Limited_Type
(Parent_Type
)
16104 (not Is_Interface
(Parent_Type
)
16105 or else not Is_Limited_Interface
(Parent_Type
))
16107 -- AI05-0096: a derivation in the private part of an instance is
16108 -- legal if the generic formal is untagged limited, and the actual
16111 if Is_Generic_Actual_Type
(Parent_Type
)
16112 and then In_Private_Part
(Current_Scope
)
16115 (Generic_Parent_Type
(Parent
(Parent_Type
)))
16121 ("parent type& of limited type must be limited",
16127 -- In SPARK, there are no derived type definitions other than type
16128 -- extensions of tagged record types.
16130 if No
(Extension
) then
16131 Check_SPARK_05_Restriction
16132 ("derived type is not allowed", Original_Node
(N
));
16134 end Derived_Type_Declaration
;
16136 ------------------------
16137 -- Diagnose_Interface --
16138 ------------------------
16140 procedure Diagnose_Interface
(N
: Node_Id
; E
: Entity_Id
) is
16142 if not Is_Interface
(E
) and then E
/= Any_Type
then
16143 Error_Msg_NE
("(Ada 2005) & must be an interface", N
, E
);
16145 end Diagnose_Interface
;
16147 ----------------------------------
16148 -- Enumeration_Type_Declaration --
16149 ----------------------------------
16151 procedure Enumeration_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
16158 -- Create identifier node representing lower bound
16160 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
16161 L
:= First
(Literals
(Def
));
16162 Set_Chars
(B_Node
, Chars
(L
));
16163 Set_Entity
(B_Node
, L
);
16164 Set_Etype
(B_Node
, T
);
16165 Set_Is_Static_Expression
(B_Node
, True);
16167 R_Node
:= New_Node
(N_Range
, Sloc
(Def
));
16168 Set_Low_Bound
(R_Node
, B_Node
);
16170 Set_Ekind
(T
, E_Enumeration_Type
);
16171 Set_First_Literal
(T
, L
);
16173 Set_Is_Constrained
(T
);
16177 -- Loop through literals of enumeration type setting pos and rep values
16178 -- except that if the Ekind is already set, then it means the literal
16179 -- was already constructed (case of a derived type declaration and we
16180 -- should not disturb the Pos and Rep values.
16182 while Present
(L
) loop
16183 if Ekind
(L
) /= E_Enumeration_Literal
then
16184 Set_Ekind
(L
, E_Enumeration_Literal
);
16185 Set_Enumeration_Pos
(L
, Ev
);
16186 Set_Enumeration_Rep
(L
, Ev
);
16187 Set_Is_Known_Valid
(L
, True);
16191 New_Overloaded_Entity
(L
);
16192 Generate_Definition
(L
);
16193 Set_Convention
(L
, Convention_Intrinsic
);
16195 -- Case of character literal
16197 if Nkind
(L
) = N_Defining_Character_Literal
then
16198 Set_Is_Character_Type
(T
, True);
16200 -- Check violation of No_Wide_Characters
16202 if Restriction_Check_Required
(No_Wide_Characters
) then
16203 Get_Name_String
(Chars
(L
));
16205 if Name_Len
>= 3 and then Name_Buffer
(1 .. 2) = "QW" then
16206 Check_Restriction
(No_Wide_Characters
, L
);
16215 -- Now create a node representing upper bound
16217 B_Node
:= New_Node
(N_Identifier
, Sloc
(Def
));
16218 Set_Chars
(B_Node
, Chars
(Last
(Literals
(Def
))));
16219 Set_Entity
(B_Node
, Last
(Literals
(Def
)));
16220 Set_Etype
(B_Node
, T
);
16221 Set_Is_Static_Expression
(B_Node
, True);
16223 Set_High_Bound
(R_Node
, B_Node
);
16225 -- Initialize various fields of the type. Some of this information
16226 -- may be overwritten later through rep.clauses.
16228 Set_Scalar_Range
(T
, R_Node
);
16229 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
16230 Set_Enum_Esize
(T
);
16231 Set_Enum_Pos_To_Rep
(T
, Empty
);
16233 -- Set Discard_Names if configuration pragma set, or if there is
16234 -- a parameterless pragma in the current declarative region
16236 if Global_Discard_Names
or else Discard_Names
(Scope
(T
)) then
16237 Set_Discard_Names
(T
);
16240 -- Process end label if there is one
16242 if Present
(Def
) then
16243 Process_End_Label
(Def
, 'e', T
);
16245 end Enumeration_Type_Declaration
;
16247 ---------------------------------
16248 -- Expand_To_Stored_Constraint --
16249 ---------------------------------
16251 function Expand_To_Stored_Constraint
16253 Constraint
: Elist_Id
) return Elist_Id
16255 Explicitly_Discriminated_Type
: Entity_Id
;
16256 Expansion
: Elist_Id
;
16257 Discriminant
: Entity_Id
;
16259 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
;
16260 -- Find the nearest type that actually specifies discriminants
16262 ---------------------------------
16263 -- Type_With_Explicit_Discrims --
16264 ---------------------------------
16266 function Type_With_Explicit_Discrims
(Id
: Entity_Id
) return Entity_Id
is
16267 Typ
: constant E
:= Base_Type
(Id
);
16270 if Ekind
(Typ
) in Incomplete_Or_Private_Kind
then
16271 if Present
(Full_View
(Typ
)) then
16272 return Type_With_Explicit_Discrims
(Full_View
(Typ
));
16276 if Has_Discriminants
(Typ
) then
16281 if Etype
(Typ
) = Typ
then
16283 elsif Has_Discriminants
(Typ
) then
16286 return Type_With_Explicit_Discrims
(Etype
(Typ
));
16289 end Type_With_Explicit_Discrims
;
16291 -- Start of processing for Expand_To_Stored_Constraint
16294 if No
(Constraint
) or else Is_Empty_Elmt_List
(Constraint
) then
16298 Explicitly_Discriminated_Type
:= Type_With_Explicit_Discrims
(Typ
);
16300 if No
(Explicitly_Discriminated_Type
) then
16304 Expansion
:= New_Elmt_List
;
16307 First_Stored_Discriminant
(Explicitly_Discriminated_Type
);
16308 while Present
(Discriminant
) loop
16310 (Get_Discriminant_Value
16311 (Discriminant
, Explicitly_Discriminated_Type
, Constraint
),
16313 Next_Stored_Discriminant
(Discriminant
);
16317 end Expand_To_Stored_Constraint
;
16319 ---------------------------
16320 -- Find_Hidden_Interface --
16321 ---------------------------
16323 function Find_Hidden_Interface
16325 Dest
: Elist_Id
) return Entity_Id
16328 Iface_Elmt
: Elmt_Id
;
16331 if Present
(Src
) and then Present
(Dest
) then
16332 Iface_Elmt
:= First_Elmt
(Src
);
16333 while Present
(Iface_Elmt
) loop
16334 Iface
:= Node
(Iface_Elmt
);
16336 if Is_Interface
(Iface
)
16337 and then not Contain_Interface
(Iface
, Dest
)
16342 Next_Elmt
(Iface_Elmt
);
16347 end Find_Hidden_Interface
;
16349 --------------------
16350 -- Find_Type_Name --
16351 --------------------
16353 function Find_Type_Name
(N
: Node_Id
) return Entity_Id
is
16354 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
16356 New_Id
: Entity_Id
;
16357 Prev_Par
: Node_Id
;
16359 procedure Check_Duplicate_Aspects
;
16360 -- Check that aspects specified in a completion have not been specified
16361 -- already in the partial view. Type_Invariant and others can be
16362 -- specified on either view but never on both.
16364 procedure Tag_Mismatch
;
16365 -- Diagnose a tagged partial view whose full view is untagged.
16366 -- We post the message on the full view, with a reference to
16367 -- the previous partial view. The partial view can be private
16368 -- or incomplete, and these are handled in a different manner,
16369 -- so we determine the position of the error message from the
16370 -- respective slocs of both.
16372 -----------------------------
16373 -- Check_Duplicate_Aspects --
16374 -----------------------------
16375 procedure Check_Duplicate_Aspects
is
16376 Prev_Aspects
: constant List_Id
:= Aspect_Specifications
(Prev_Par
);
16377 Full_Aspects
: constant List_Id
:= Aspect_Specifications
(N
);
16378 F_Spec
, P_Spec
: Node_Id
;
16381 if Present
(Prev_Aspects
) and then Present
(Full_Aspects
) then
16382 F_Spec
:= First
(Full_Aspects
);
16383 while Present
(F_Spec
) loop
16384 P_Spec
:= First
(Prev_Aspects
);
16385 while Present
(P_Spec
) loop
16386 if Chars
(Identifier
(P_Spec
)) = Chars
(Identifier
(F_Spec
))
16389 ("aspect already specified in private declaration",
16401 end Check_Duplicate_Aspects
;
16407 procedure Tag_Mismatch
is
16409 if Sloc
(Prev
) < Sloc
(Id
) then
16410 if Ada_Version
>= Ada_2012
16411 and then Nkind
(N
) = N_Private_Type_Declaration
16414 ("declaration of private } must be a tagged type ", Id
, Prev
);
16417 ("full declaration of } must be a tagged type ", Id
, Prev
);
16421 if Ada_Version
>= Ada_2012
16422 and then Nkind
(N
) = N_Private_Type_Declaration
16425 ("declaration of private } must be a tagged type ", Prev
, Id
);
16428 ("full declaration of } must be a tagged type ", Prev
, Id
);
16433 -- Start of processing for Find_Type_Name
16436 -- Find incomplete declaration, if one was given
16438 Prev
:= Current_Entity_In_Scope
(Id
);
16440 -- New type declaration
16446 -- Previous declaration exists
16449 Prev_Par
:= Parent
(Prev
);
16451 -- Error if not incomplete/private case except if previous
16452 -- declaration is implicit, etc. Enter_Name will emit error if
16455 if not Is_Incomplete_Or_Private_Type
(Prev
) then
16459 -- Check invalid completion of private or incomplete type
16461 elsif not Nkind_In
(N
, N_Full_Type_Declaration
,
16462 N_Task_Type_Declaration
,
16463 N_Protected_Type_Declaration
)
16465 (Ada_Version
< Ada_2012
16466 or else not Is_Incomplete_Type
(Prev
)
16467 or else not Nkind_In
(N
, N_Private_Type_Declaration
,
16468 N_Private_Extension_Declaration
))
16470 -- Completion must be a full type declarations (RM 7.3(4))
16472 Error_Msg_Sloc
:= Sloc
(Prev
);
16473 Error_Msg_NE
("invalid completion of }", Id
, Prev
);
16475 -- Set scope of Id to avoid cascaded errors. Entity is never
16476 -- examined again, except when saving globals in generics.
16478 Set_Scope
(Id
, Current_Scope
);
16481 -- If this is a repeated incomplete declaration, no further
16482 -- checks are possible.
16484 if Nkind
(N
) = N_Incomplete_Type_Declaration
then
16488 -- Case of full declaration of incomplete type
16490 elsif Ekind
(Prev
) = E_Incomplete_Type
16491 and then (Ada_Version
< Ada_2012
16492 or else No
(Full_View
(Prev
))
16493 or else not Is_Private_Type
(Full_View
(Prev
)))
16495 -- Indicate that the incomplete declaration has a matching full
16496 -- declaration. The defining occurrence of the incomplete
16497 -- declaration remains the visible one, and the procedure
16498 -- Get_Full_View dereferences it whenever the type is used.
16500 if Present
(Full_View
(Prev
)) then
16501 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
16504 Set_Full_View
(Prev
, Id
);
16505 Append_Entity
(Id
, Current_Scope
);
16506 Set_Is_Public
(Id
, Is_Public
(Prev
));
16507 Set_Is_Internal
(Id
);
16510 -- If the incomplete view is tagged, a class_wide type has been
16511 -- created already. Use it for the private type as well, in order
16512 -- to prevent multiple incompatible class-wide types that may be
16513 -- created for self-referential anonymous access components.
16515 if Is_Tagged_Type
(Prev
)
16516 and then Present
(Class_Wide_Type
(Prev
))
16518 Set_Ekind
(Id
, Ekind
(Prev
)); -- will be reset later
16519 Set_Class_Wide_Type
(Id
, Class_Wide_Type
(Prev
));
16521 -- The type of the classwide type is the current Id. Previously
16522 -- this was not done for private declarations because of order-
16523 -- of elaboration issues in the back-end, but gigi now handles
16526 Set_Etype
(Class_Wide_Type
(Id
), Id
);
16529 -- Case of full declaration of private type
16532 -- If the private type was a completion of an incomplete type then
16533 -- update Prev to reference the private type
16535 if Ada_Version
>= Ada_2012
16536 and then Ekind
(Prev
) = E_Incomplete_Type
16537 and then Present
(Full_View
(Prev
))
16538 and then Is_Private_Type
(Full_View
(Prev
))
16540 Prev
:= Full_View
(Prev
);
16541 Prev_Par
:= Parent
(Prev
);
16544 if Nkind
(N
) = N_Full_Type_Declaration
16546 (Type_Definition
(N
), N_Record_Definition
,
16547 N_Derived_Type_Definition
)
16548 and then Interface_Present
(Type_Definition
(N
))
16551 ("completion of private type cannot be an interface", N
);
16554 if Nkind
(Parent
(Prev
)) /= N_Private_Extension_Declaration
then
16555 if Etype
(Prev
) /= Prev
then
16557 -- Prev is a private subtype or a derived type, and needs
16560 Error_Msg_NE
("invalid redeclaration of }", Id
, Prev
);
16563 elsif Ekind
(Prev
) = E_Private_Type
16564 and then Nkind_In
(N
, N_Task_Type_Declaration
,
16565 N_Protected_Type_Declaration
)
16568 ("completion of nonlimited type cannot be limited", N
);
16570 elsif Ekind
(Prev
) = E_Record_Type_With_Private
16571 and then Nkind_In
(N
, N_Task_Type_Declaration
,
16572 N_Protected_Type_Declaration
)
16574 if not Is_Limited_Record
(Prev
) then
16576 ("completion of nonlimited type cannot be limited", N
);
16578 elsif No
(Interface_List
(N
)) then
16580 ("completion of tagged private type must be tagged",
16585 -- Ada 2005 (AI-251): Private extension declaration of a task
16586 -- type or a protected type. This case arises when covering
16587 -- interface types.
16589 elsif Nkind_In
(N
, N_Task_Type_Declaration
,
16590 N_Protected_Type_Declaration
)
16594 elsif Nkind
(N
) /= N_Full_Type_Declaration
16595 or else Nkind
(Type_Definition
(N
)) /= N_Derived_Type_Definition
16598 ("full view of private extension must be an extension", N
);
16600 elsif not (Abstract_Present
(Parent
(Prev
)))
16601 and then Abstract_Present
(Type_Definition
(N
))
16604 ("full view of non-abstract extension cannot be abstract", N
);
16607 if not In_Private_Part
(Current_Scope
) then
16609 ("declaration of full view must appear in private part", N
);
16612 if Ada_Version
>= Ada_2012
then
16613 Check_Duplicate_Aspects
;
16616 Copy_And_Swap
(Prev
, Id
);
16617 Set_Has_Private_Declaration
(Prev
);
16618 Set_Has_Private_Declaration
(Id
);
16620 -- AI12-0133: Indicate whether we have a partial view with
16621 -- unknown discriminants, in which case initialization of objects
16622 -- of the type do not receive an invariant check.
16624 Set_Partial_View_Has_Unknown_Discr
16625 (Prev
, Has_Unknown_Discriminants
(Id
));
16627 -- Preserve aspect and iterator flags that may have been set on
16628 -- the partial view.
16630 Set_Has_Delayed_Aspects
(Prev
, Has_Delayed_Aspects
(Id
));
16631 Set_Has_Implicit_Dereference
(Prev
, Has_Implicit_Dereference
(Id
));
16633 -- If no error, propagate freeze_node from private to full view.
16634 -- It may have been generated for an early operational item.
16636 if Present
(Freeze_Node
(Id
))
16637 and then Serious_Errors_Detected
= 0
16638 and then No
(Full_View
(Id
))
16640 Set_Freeze_Node
(Prev
, Freeze_Node
(Id
));
16641 Set_Freeze_Node
(Id
, Empty
);
16642 Set_First_Rep_Item
(Prev
, First_Rep_Item
(Id
));
16645 Set_Full_View
(Id
, Prev
);
16649 -- Verify that full declaration conforms to partial one
16651 if Is_Incomplete_Or_Private_Type
(Prev
)
16652 and then Present
(Discriminant_Specifications
(Prev_Par
))
16654 if Present
(Discriminant_Specifications
(N
)) then
16655 if Ekind
(Prev
) = E_Incomplete_Type
then
16656 Check_Discriminant_Conformance
(N
, Prev
, Prev
);
16658 Check_Discriminant_Conformance
(N
, Prev
, Id
);
16663 ("missing discriminants in full type declaration", N
);
16665 -- To avoid cascaded errors on subsequent use, share the
16666 -- discriminants of the partial view.
16668 Set_Discriminant_Specifications
(N
,
16669 Discriminant_Specifications
(Prev_Par
));
16673 -- A prior untagged partial view can have an associated class-wide
16674 -- type due to use of the class attribute, and in this case the full
16675 -- type must also be tagged. This Ada 95 usage is deprecated in favor
16676 -- of incomplete tagged declarations, but we check for it.
16679 and then (Is_Tagged_Type
(Prev
)
16680 or else Present
(Class_Wide_Type
(Prev
)))
16682 -- Ada 2012 (AI05-0162): A private type may be the completion of
16683 -- an incomplete type.
16685 if Ada_Version
>= Ada_2012
16686 and then Is_Incomplete_Type
(Prev
)
16687 and then Nkind_In
(N
, N_Private_Type_Declaration
,
16688 N_Private_Extension_Declaration
)
16690 -- No need to check private extensions since they are tagged
16692 if Nkind
(N
) = N_Private_Type_Declaration
16693 and then not Tagged_Present
(N
)
16698 -- The full declaration is either a tagged type (including
16699 -- a synchronized type that implements interfaces) or a
16700 -- type extension, otherwise this is an error.
16702 elsif Nkind_In
(N
, N_Task_Type_Declaration
,
16703 N_Protected_Type_Declaration
)
16705 if No
(Interface_List
(N
)) and then not Error_Posted
(N
) then
16709 elsif Nkind
(Type_Definition
(N
)) = N_Record_Definition
then
16711 -- Indicate that the previous declaration (tagged incomplete
16712 -- or private declaration) requires the same on the full one.
16714 if not Tagged_Present
(Type_Definition
(N
)) then
16716 Set_Is_Tagged_Type
(Id
);
16719 elsif Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
then
16720 if No
(Record_Extension_Part
(Type_Definition
(N
))) then
16722 ("full declaration of } must be a record extension",
16725 -- Set some attributes to produce a usable full view
16727 Set_Is_Tagged_Type
(Id
);
16736 and then Nkind
(Parent
(Prev
)) = N_Incomplete_Type_Declaration
16737 and then Present
(Premature_Use
(Parent
(Prev
)))
16739 Error_Msg_Sloc
:= Sloc
(N
);
16741 ("\full declaration #", Premature_Use
(Parent
(Prev
)));
16746 end Find_Type_Name
;
16748 -------------------------
16749 -- Find_Type_Of_Object --
16750 -------------------------
16752 function Find_Type_Of_Object
16753 (Obj_Def
: Node_Id
;
16754 Related_Nod
: Node_Id
) return Entity_Id
16756 Def_Kind
: constant Node_Kind
:= Nkind
(Obj_Def
);
16757 P
: Node_Id
:= Parent
(Obj_Def
);
16762 -- If the parent is a component_definition node we climb to the
16763 -- component_declaration node
16765 if Nkind
(P
) = N_Component_Definition
then
16769 -- Case of an anonymous array subtype
16771 if Nkind_In
(Def_Kind
, N_Constrained_Array_Definition
,
16772 N_Unconstrained_Array_Definition
)
16775 Array_Type_Declaration
(T
, Obj_Def
);
16777 -- Create an explicit subtype whenever possible
16779 elsif Nkind
(P
) /= N_Component_Declaration
16780 and then Def_Kind
= N_Subtype_Indication
16782 -- Base name of subtype on object name, which will be unique in
16783 -- the current scope.
16785 -- If this is a duplicate declaration, return base type, to avoid
16786 -- generating duplicate anonymous types.
16788 if Error_Posted
(P
) then
16789 Analyze
(Subtype_Mark
(Obj_Def
));
16790 return Entity
(Subtype_Mark
(Obj_Def
));
16795 (Chars
(Defining_Identifier
(Related_Nod
)), 'S', 0, 'T');
16797 T
:= Make_Defining_Identifier
(Sloc
(P
), Nam
);
16799 Insert_Action
(Obj_Def
,
16800 Make_Subtype_Declaration
(Sloc
(P
),
16801 Defining_Identifier
=> T
,
16802 Subtype_Indication
=> Relocate_Node
(Obj_Def
)));
16804 -- This subtype may need freezing, and this will not be done
16805 -- automatically if the object declaration is not in declarative
16806 -- part. Since this is an object declaration, the type cannot always
16807 -- be frozen here. Deferred constants do not freeze their type
16808 -- (which often enough will be private).
16810 if Nkind
(P
) = N_Object_Declaration
16811 and then Constant_Present
(P
)
16812 and then No
(Expression
(P
))
16816 -- Here we freeze the base type of object type to catch premature use
16817 -- of discriminated private type without a full view.
16820 Insert_Actions
(Obj_Def
, Freeze_Entity
(Base_Type
(T
), P
));
16823 -- Ada 2005 AI-406: the object definition in an object declaration
16824 -- can be an access definition.
16826 elsif Def_Kind
= N_Access_Definition
then
16827 T
:= Access_Definition
(Related_Nod
, Obj_Def
);
16829 Set_Is_Local_Anonymous_Access
16831 V
=> (Ada_Version
< Ada_2012
)
16832 or else (Nkind
(P
) /= N_Object_Declaration
)
16833 or else Is_Library_Level_Entity
(Defining_Identifier
(P
)));
16835 -- Otherwise, the object definition is just a subtype_mark
16838 T
:= Process_Subtype
(Obj_Def
, Related_Nod
);
16840 -- If expansion is disabled an object definition that is an aggregate
16841 -- will not get expanded and may lead to scoping problems in the back
16842 -- end, if the object is referenced in an inner scope. In that case
16843 -- create an itype reference for the object definition now. This
16844 -- may be redundant in some cases, but harmless.
16847 and then Nkind
(Related_Nod
) = N_Object_Declaration
16850 Build_Itype_Reference
(T
, Related_Nod
);
16855 end Find_Type_Of_Object
;
16857 --------------------------------
16858 -- Find_Type_Of_Subtype_Indic --
16859 --------------------------------
16861 function Find_Type_Of_Subtype_Indic
(S
: Node_Id
) return Entity_Id
is
16865 -- Case of subtype mark with a constraint
16867 if Nkind
(S
) = N_Subtype_Indication
then
16868 Find_Type
(Subtype_Mark
(S
));
16869 Typ
:= Entity
(Subtype_Mark
(S
));
16872 Is_Valid_Constraint_Kind
(Ekind
(Typ
), Nkind
(Constraint
(S
)))
16875 ("incorrect constraint for this kind of type", Constraint
(S
));
16876 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
16879 -- Otherwise we have a subtype mark without a constraint
16881 elsif Error_Posted
(S
) then
16882 Rewrite
(S
, New_Occurrence_Of
(Any_Id
, Sloc
(S
)));
16890 -- Check No_Wide_Characters restriction
16892 Check_Wide_Character_Restriction
(Typ
, S
);
16895 end Find_Type_Of_Subtype_Indic
;
16897 -------------------------------------
16898 -- Floating_Point_Type_Declaration --
16899 -------------------------------------
16901 procedure Floating_Point_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
16902 Digs
: constant Node_Id
:= Digits_Expression
(Def
);
16903 Max_Digs_Val
: constant Uint
:= Digits_Value
(Standard_Long_Long_Float
);
16905 Base_Typ
: Entity_Id
;
16906 Implicit_Base
: Entity_Id
;
16909 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
16910 -- Find if given digits value, and possibly a specified range, allows
16911 -- derivation from specified type
16913 function Find_Base_Type
return Entity_Id
;
16914 -- Find a predefined base type that Def can derive from, or generate
16915 -- an error and substitute Long_Long_Float if none exists.
16917 ---------------------
16918 -- Can_Derive_From --
16919 ---------------------
16921 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
16922 Spec
: constant Entity_Id
:= Real_Range_Specification
(Def
);
16925 -- Check specified "digits" constraint
16927 if Digs_Val
> Digits_Value
(E
) then
16931 -- Check for matching range, if specified
16933 if Present
(Spec
) then
16934 if Expr_Value_R
(Type_Low_Bound
(E
)) >
16935 Expr_Value_R
(Low_Bound
(Spec
))
16940 if Expr_Value_R
(Type_High_Bound
(E
)) <
16941 Expr_Value_R
(High_Bound
(Spec
))
16948 end Can_Derive_From
;
16950 --------------------
16951 -- Find_Base_Type --
16952 --------------------
16954 function Find_Base_Type
return Entity_Id
is
16955 Choice
: Elmt_Id
:= First_Elmt
(Predefined_Float_Types
);
16958 -- Iterate over the predefined types in order, returning the first
16959 -- one that Def can derive from.
16961 while Present
(Choice
) loop
16962 if Can_Derive_From
(Node
(Choice
)) then
16963 return Node
(Choice
);
16966 Next_Elmt
(Choice
);
16969 -- If we can't derive from any existing type, use Long_Long_Float
16970 -- and give appropriate message explaining the problem.
16972 if Digs_Val
> Max_Digs_Val
then
16973 -- It might be the case that there is a type with the requested
16974 -- range, just not the combination of digits and range.
16977 ("no predefined type has requested range and precision",
16978 Real_Range_Specification
(Def
));
16982 ("range too large for any predefined type",
16983 Real_Range_Specification
(Def
));
16986 return Standard_Long_Long_Float
;
16987 end Find_Base_Type
;
16989 -- Start of processing for Floating_Point_Type_Declaration
16992 Check_Restriction
(No_Floating_Point
, Def
);
16994 -- Create an implicit base type
16997 Create_Itype
(E_Floating_Point_Type
, Parent
(Def
), T
, 'B');
16999 -- Analyze and verify digits value
17001 Analyze_And_Resolve
(Digs
, Any_Integer
);
17002 Check_Digits_Expression
(Digs
);
17003 Digs_Val
:= Expr_Value
(Digs
);
17005 -- Process possible range spec and find correct type to derive from
17007 Process_Real_Range_Specification
(Def
);
17009 -- Check that requested number of digits is not too high.
17011 if Digs_Val
> Max_Digs_Val
then
17013 -- The check for Max_Base_Digits may be somewhat expensive, as it
17014 -- requires reading System, so only do it when necessary.
17017 Max_Base_Digits
: constant Uint
:=
17020 (Parent
(RTE
(RE_Max_Base_Digits
))));
17023 if Digs_Val
> Max_Base_Digits
then
17024 Error_Msg_Uint_1
:= Max_Base_Digits
;
17025 Error_Msg_N
("digits value out of range, maximum is ^", Digs
);
17027 elsif No
(Real_Range_Specification
(Def
)) then
17028 Error_Msg_Uint_1
:= Max_Digs_Val
;
17029 Error_Msg_N
("types with more than ^ digits need range spec "
17030 & "(RM 3.5.7(6))", Digs
);
17035 -- Find a suitable type to derive from or complain and use a substitute
17037 Base_Typ
:= Find_Base_Type
;
17039 -- If there are bounds given in the declaration use them as the bounds
17040 -- of the type, otherwise use the bounds of the predefined base type
17041 -- that was chosen based on the Digits value.
17043 if Present
(Real_Range_Specification
(Def
)) then
17044 Set_Scalar_Range
(T
, Real_Range_Specification
(Def
));
17045 Set_Is_Constrained
(T
);
17047 -- The bounds of this range must be converted to machine numbers
17048 -- in accordance with RM 4.9(38).
17050 Bound
:= Type_Low_Bound
(T
);
17052 if Nkind
(Bound
) = N_Real_Literal
then
17054 (Bound
, Machine
(Base_Typ
, Realval
(Bound
), Round
, Bound
));
17055 Set_Is_Machine_Number
(Bound
);
17058 Bound
:= Type_High_Bound
(T
);
17060 if Nkind
(Bound
) = N_Real_Literal
then
17062 (Bound
, Machine
(Base_Typ
, Realval
(Bound
), Round
, Bound
));
17063 Set_Is_Machine_Number
(Bound
);
17067 Set_Scalar_Range
(T
, Scalar_Range
(Base_Typ
));
17070 -- Complete definition of implicit base and declared first subtype. The
17071 -- inheritance of the rep item chain ensures that SPARK-related pragmas
17072 -- are not clobbered when the floating point type acts as a full view of
17075 Set_Etype
(Implicit_Base
, Base_Typ
);
17076 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
17077 Set_Size_Info
(Implicit_Base
, Base_Typ
);
17078 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
17079 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
17080 Set_Digits_Value
(Implicit_Base
, Digits_Value
(Base_Typ
));
17081 Set_Float_Rep
(Implicit_Base
, Float_Rep
(Base_Typ
));
17083 Set_Ekind
(T
, E_Floating_Point_Subtype
);
17084 Set_Etype
(T
, Implicit_Base
);
17085 Set_Size_Info
(T
, Implicit_Base
);
17086 Set_RM_Size
(T
, RM_Size
(Implicit_Base
));
17087 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
17088 Set_Digits_Value
(T
, Digs_Val
);
17089 end Floating_Point_Type_Declaration
;
17091 ----------------------------
17092 -- Get_Discriminant_Value --
17093 ----------------------------
17095 -- This is the situation:
17097 -- There is a non-derived type
17099 -- type T0 (Dx, Dy, Dz...)
17101 -- There are zero or more levels of derivation, with each derivation
17102 -- either purely inheriting the discriminants, or defining its own.
17104 -- type Ti is new Ti-1
17106 -- type Ti (Dw) is new Ti-1(Dw, 1, X+Y)
17108 -- subtype Ti is ...
17110 -- The subtype issue is avoided by the use of Original_Record_Component,
17111 -- and the fact that derived subtypes also derive the constraints.
17113 -- This chain leads back from
17115 -- Typ_For_Constraint
17117 -- Typ_For_Constraint has discriminants, and the value for each
17118 -- discriminant is given by its corresponding Elmt of Constraints.
17120 -- Discriminant is some discriminant in this hierarchy
17122 -- We need to return its value
17124 -- We do this by recursively searching each level, and looking for
17125 -- Discriminant. Once we get to the bottom, we start backing up
17126 -- returning the value for it which may in turn be a discriminant
17127 -- further up, so on the backup we continue the substitution.
17129 function Get_Discriminant_Value
17130 (Discriminant
: Entity_Id
;
17131 Typ_For_Constraint
: Entity_Id
;
17132 Constraint
: Elist_Id
) return Node_Id
17134 function Root_Corresponding_Discriminant
17135 (Discr
: Entity_Id
) return Entity_Id
;
17136 -- Given a discriminant, traverse the chain of inherited discriminants
17137 -- and return the topmost discriminant.
17139 function Search_Derivation_Levels
17141 Discrim_Values
: Elist_Id
;
17142 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
;
17143 -- This is the routine that performs the recursive search of levels
17144 -- as described above.
17146 -------------------------------------
17147 -- Root_Corresponding_Discriminant --
17148 -------------------------------------
17150 function Root_Corresponding_Discriminant
17151 (Discr
: Entity_Id
) return Entity_Id
17157 while Present
(Corresponding_Discriminant
(D
)) loop
17158 D
:= Corresponding_Discriminant
(D
);
17162 end Root_Corresponding_Discriminant
;
17164 ------------------------------
17165 -- Search_Derivation_Levels --
17166 ------------------------------
17168 function Search_Derivation_Levels
17170 Discrim_Values
: Elist_Id
;
17171 Stored_Discrim_Values
: Boolean) return Node_Or_Entity_Id
17175 Result
: Node_Or_Entity_Id
;
17176 Result_Entity
: Node_Id
;
17179 -- If inappropriate type, return Error, this happens only in
17180 -- cascaded error situations, and we want to avoid a blow up.
17182 if not Is_Composite_Type
(Ti
) or else Is_Array_Type
(Ti
) then
17186 -- Look deeper if possible. Use Stored_Constraints only for
17187 -- untagged types. For tagged types use the given constraint.
17188 -- This asymmetry needs explanation???
17190 if not Stored_Discrim_Values
17191 and then Present
(Stored_Constraint
(Ti
))
17192 and then not Is_Tagged_Type
(Ti
)
17195 Search_Derivation_Levels
(Ti
, Stored_Constraint
(Ti
), True);
17198 Td
: constant Entity_Id
:= Etype
(Ti
);
17202 Result
:= Discriminant
;
17205 if Present
(Stored_Constraint
(Ti
)) then
17207 Search_Derivation_Levels
17208 (Td
, Stored_Constraint
(Ti
), True);
17211 Search_Derivation_Levels
17212 (Td
, Discrim_Values
, Stored_Discrim_Values
);
17218 -- Extra underlying places to search, if not found above. For
17219 -- concurrent types, the relevant discriminant appears in the
17220 -- corresponding record. For a type derived from a private type
17221 -- without discriminant, the full view inherits the discriminants
17222 -- of the full view of the parent.
17224 if Result
= Discriminant
then
17225 if Is_Concurrent_Type
(Ti
)
17226 and then Present
(Corresponding_Record_Type
(Ti
))
17229 Search_Derivation_Levels
(
17230 Corresponding_Record_Type
(Ti
),
17232 Stored_Discrim_Values
);
17234 elsif Is_Private_Type
(Ti
)
17235 and then not Has_Discriminants
(Ti
)
17236 and then Present
(Full_View
(Ti
))
17237 and then Etype
(Full_View
(Ti
)) /= Ti
17240 Search_Derivation_Levels
(
17243 Stored_Discrim_Values
);
17247 -- If Result is not a (reference to a) discriminant, return it,
17248 -- otherwise set Result_Entity to the discriminant.
17250 if Nkind
(Result
) = N_Defining_Identifier
then
17251 pragma Assert
(Result
= Discriminant
);
17252 Result_Entity
:= Result
;
17255 if not Denotes_Discriminant
(Result
) then
17259 Result_Entity
:= Entity
(Result
);
17262 -- See if this level of derivation actually has discriminants because
17263 -- tagged derivations can add them, hence the lower levels need not
17266 if not Has_Discriminants
(Ti
) then
17270 -- Scan Ti's discriminants for Result_Entity, and return its
17271 -- corresponding value, if any.
17273 Result_Entity
:= Original_Record_Component
(Result_Entity
);
17275 Assoc
:= First_Elmt
(Discrim_Values
);
17277 if Stored_Discrim_Values
then
17278 Disc
:= First_Stored_Discriminant
(Ti
);
17280 Disc
:= First_Discriminant
(Ti
);
17283 while Present
(Disc
) loop
17284 pragma Assert
(Present
(Assoc
));
17286 if Original_Record_Component
(Disc
) = Result_Entity
then
17287 return Node
(Assoc
);
17292 if Stored_Discrim_Values
then
17293 Next_Stored_Discriminant
(Disc
);
17295 Next_Discriminant
(Disc
);
17299 -- Could not find it
17302 end Search_Derivation_Levels
;
17306 Result
: Node_Or_Entity_Id
;
17308 -- Start of processing for Get_Discriminant_Value
17311 -- ??? This routine is a gigantic mess and will be deleted. For the
17312 -- time being just test for the trivial case before calling recurse.
17314 if Base_Type
(Scope
(Discriminant
)) = Base_Type
(Typ_For_Constraint
) then
17320 D
:= First_Discriminant
(Typ_For_Constraint
);
17321 E
:= First_Elmt
(Constraint
);
17322 while Present
(D
) loop
17323 if Chars
(D
) = Chars
(Discriminant
) then
17327 Next_Discriminant
(D
);
17333 Result
:= Search_Derivation_Levels
17334 (Typ_For_Constraint
, Constraint
, False);
17336 -- ??? hack to disappear when this routine is gone
17338 if Nkind
(Result
) = N_Defining_Identifier
then
17344 D
:= First_Discriminant
(Typ_For_Constraint
);
17345 E
:= First_Elmt
(Constraint
);
17346 while Present
(D
) loop
17347 if Root_Corresponding_Discriminant
(D
) = Discriminant
then
17351 Next_Discriminant
(D
);
17357 pragma Assert
(Nkind
(Result
) /= N_Defining_Identifier
);
17359 end Get_Discriminant_Value
;
17361 --------------------------
17362 -- Has_Range_Constraint --
17363 --------------------------
17365 function Has_Range_Constraint
(N
: Node_Id
) return Boolean is
17366 C
: constant Node_Id
:= Constraint
(N
);
17369 if Nkind
(C
) = N_Range_Constraint
then
17372 elsif Nkind
(C
) = N_Digits_Constraint
then
17374 Is_Decimal_Fixed_Point_Type
(Entity
(Subtype_Mark
(N
)))
17375 or else Present
(Range_Constraint
(C
));
17377 elsif Nkind
(C
) = N_Delta_Constraint
then
17378 return Present
(Range_Constraint
(C
));
17383 end Has_Range_Constraint
;
17385 ------------------------
17386 -- Inherit_Components --
17387 ------------------------
17389 function Inherit_Components
17391 Parent_Base
: Entity_Id
;
17392 Derived_Base
: Entity_Id
;
17393 Is_Tagged
: Boolean;
17394 Inherit_Discr
: Boolean;
17395 Discs
: Elist_Id
) return Elist_Id
17397 Assoc_List
: constant Elist_Id
:= New_Elmt_List
;
17399 procedure Inherit_Component
17400 (Old_C
: Entity_Id
;
17401 Plain_Discrim
: Boolean := False;
17402 Stored_Discrim
: Boolean := False);
17403 -- Inherits component Old_C from Parent_Base to the Derived_Base. If
17404 -- Plain_Discrim is True, Old_C is a discriminant. If Stored_Discrim is
17405 -- True, Old_C is a stored discriminant. If they are both false then
17406 -- Old_C is a regular component.
17408 -----------------------
17409 -- Inherit_Component --
17410 -----------------------
17412 procedure Inherit_Component
17413 (Old_C
: Entity_Id
;
17414 Plain_Discrim
: Boolean := False;
17415 Stored_Discrim
: Boolean := False)
17417 procedure Set_Anonymous_Type
(Id
: Entity_Id
);
17418 -- Id denotes the entity of an access discriminant or anonymous
17419 -- access component. Set the type of Id to either the same type of
17420 -- Old_C or create a new one depending on whether the parent and
17421 -- the child types are in the same scope.
17423 ------------------------
17424 -- Set_Anonymous_Type --
17425 ------------------------
17427 procedure Set_Anonymous_Type
(Id
: Entity_Id
) is
17428 Old_Typ
: constant Entity_Id
:= Etype
(Old_C
);
17431 if Scope
(Parent_Base
) = Scope
(Derived_Base
) then
17432 Set_Etype
(Id
, Old_Typ
);
17434 -- The parent and the derived type are in two different scopes.
17435 -- Reuse the type of the original discriminant / component by
17436 -- copying it in order to preserve all attributes.
17440 Typ
: constant Entity_Id
:= New_Copy
(Old_Typ
);
17443 Set_Etype
(Id
, Typ
);
17445 -- Since we do not generate component declarations for
17446 -- inherited components, associate the itype with the
17449 Set_Associated_Node_For_Itype
(Typ
, Parent
(Derived_Base
));
17450 Set_Scope
(Typ
, Derived_Base
);
17453 end Set_Anonymous_Type
;
17455 -- Local variables and constants
17457 New_C
: constant Entity_Id
:= New_Copy
(Old_C
);
17459 Corr_Discrim
: Entity_Id
;
17460 Discrim
: Entity_Id
;
17462 -- Start of processing for Inherit_Component
17465 pragma Assert
(not Is_Tagged
or not Stored_Discrim
);
17467 Set_Parent
(New_C
, Parent
(Old_C
));
17469 -- Regular discriminants and components must be inserted in the scope
17470 -- of the Derived_Base. Do it here.
17472 if not Stored_Discrim
then
17473 Enter_Name
(New_C
);
17476 -- For tagged types the Original_Record_Component must point to
17477 -- whatever this field was pointing to in the parent type. This has
17478 -- already been achieved by the call to New_Copy above.
17480 if not Is_Tagged
then
17481 Set_Original_Record_Component
(New_C
, New_C
);
17484 -- Set the proper type of an access discriminant
17486 if Ekind
(New_C
) = E_Discriminant
17487 and then Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
17489 Set_Anonymous_Type
(New_C
);
17492 -- If we have inherited a component then see if its Etype contains
17493 -- references to Parent_Base discriminants. In this case, replace
17494 -- these references with the constraints given in Discs. We do not
17495 -- do this for the partial view of private types because this is
17496 -- not needed (only the components of the full view will be used
17497 -- for code generation) and cause problem. We also avoid this
17498 -- transformation in some error situations.
17500 if Ekind
(New_C
) = E_Component
then
17502 -- Set the proper type of an anonymous access component
17504 if Ekind
(Etype
(New_C
)) = E_Anonymous_Access_Type
then
17505 Set_Anonymous_Type
(New_C
);
17507 elsif (Is_Private_Type
(Derived_Base
)
17508 and then not Is_Generic_Type
(Derived_Base
))
17509 or else (Is_Empty_Elmt_List
(Discs
)
17510 and then not Expander_Active
)
17512 Set_Etype
(New_C
, Etype
(Old_C
));
17515 -- The current component introduces a circularity of the
17518 -- limited with Pack_2;
17519 -- package Pack_1 is
17520 -- type T_1 is tagged record
17521 -- Comp : access Pack_2.T_2;
17527 -- package Pack_2 is
17528 -- type T_2 is new Pack_1.T_1 with ...;
17533 Constrain_Component_Type
17534 (Old_C
, Derived_Base
, N
, Parent_Base
, Discs
));
17538 -- In derived tagged types it is illegal to reference a non
17539 -- discriminant component in the parent type. To catch this, mark
17540 -- these components with an Ekind of E_Void. This will be reset in
17541 -- Record_Type_Definition after processing the record extension of
17542 -- the derived type.
17544 -- If the declaration is a private extension, there is no further
17545 -- record extension to process, and the components retain their
17546 -- current kind, because they are visible at this point.
17548 if Is_Tagged
and then Ekind
(New_C
) = E_Component
17549 and then Nkind
(N
) /= N_Private_Extension_Declaration
17551 Set_Ekind
(New_C
, E_Void
);
17554 if Plain_Discrim
then
17555 Set_Corresponding_Discriminant
(New_C
, Old_C
);
17556 Build_Discriminal
(New_C
);
17558 -- If we are explicitly inheriting a stored discriminant it will be
17559 -- completely hidden.
17561 elsif Stored_Discrim
then
17562 Set_Corresponding_Discriminant
(New_C
, Empty
);
17563 Set_Discriminal
(New_C
, Empty
);
17564 Set_Is_Completely_Hidden
(New_C
);
17566 -- Set the Original_Record_Component of each discriminant in the
17567 -- derived base to point to the corresponding stored that we just
17570 Discrim
:= First_Discriminant
(Derived_Base
);
17571 while Present
(Discrim
) loop
17572 Corr_Discrim
:= Corresponding_Discriminant
(Discrim
);
17574 -- Corr_Discrim could be missing in an error situation
17576 if Present
(Corr_Discrim
)
17577 and then Original_Record_Component
(Corr_Discrim
) = Old_C
17579 Set_Original_Record_Component
(Discrim
, New_C
);
17582 Next_Discriminant
(Discrim
);
17585 Append_Entity
(New_C
, Derived_Base
);
17588 if not Is_Tagged
then
17589 Append_Elmt
(Old_C
, Assoc_List
);
17590 Append_Elmt
(New_C
, Assoc_List
);
17592 end Inherit_Component
;
17594 -- Variables local to Inherit_Component
17596 Loc
: constant Source_Ptr
:= Sloc
(N
);
17598 Parent_Discrim
: Entity_Id
;
17599 Stored_Discrim
: Entity_Id
;
17601 Component
: Entity_Id
;
17603 -- Start of processing for Inherit_Components
17606 if not Is_Tagged
then
17607 Append_Elmt
(Parent_Base
, Assoc_List
);
17608 Append_Elmt
(Derived_Base
, Assoc_List
);
17611 -- Inherit parent discriminants if needed
17613 if Inherit_Discr
then
17614 Parent_Discrim
:= First_Discriminant
(Parent_Base
);
17615 while Present
(Parent_Discrim
) loop
17616 Inherit_Component
(Parent_Discrim
, Plain_Discrim
=> True);
17617 Next_Discriminant
(Parent_Discrim
);
17621 -- Create explicit stored discrims for untagged types when necessary
17623 if not Has_Unknown_Discriminants
(Derived_Base
)
17624 and then Has_Discriminants
(Parent_Base
)
17625 and then not Is_Tagged
17628 or else First_Discriminant
(Parent_Base
) /=
17629 First_Stored_Discriminant
(Parent_Base
))
17631 Stored_Discrim
:= First_Stored_Discriminant
(Parent_Base
);
17632 while Present
(Stored_Discrim
) loop
17633 Inherit_Component
(Stored_Discrim
, Stored_Discrim
=> True);
17634 Next_Stored_Discriminant
(Stored_Discrim
);
17638 -- See if we can apply the second transformation for derived types, as
17639 -- explained in point 6. in the comments above Build_Derived_Record_Type
17640 -- This is achieved by appending Derived_Base discriminants into Discs,
17641 -- which has the side effect of returning a non empty Discs list to the
17642 -- caller of Inherit_Components, which is what we want. This must be
17643 -- done for private derived types if there are explicit stored
17644 -- discriminants, to ensure that we can retrieve the values of the
17645 -- constraints provided in the ancestors.
17648 and then Is_Empty_Elmt_List
(Discs
)
17649 and then Present
(First_Discriminant
(Derived_Base
))
17651 (not Is_Private_Type
(Derived_Base
)
17652 or else Is_Completely_Hidden
17653 (First_Stored_Discriminant
(Derived_Base
))
17654 or else Is_Generic_Type
(Derived_Base
))
17656 D
:= First_Discriminant
(Derived_Base
);
17657 while Present
(D
) loop
17658 Append_Elmt
(New_Occurrence_Of
(D
, Loc
), Discs
);
17659 Next_Discriminant
(D
);
17663 -- Finally, inherit non-discriminant components unless they are not
17664 -- visible because defined or inherited from the full view of the
17665 -- parent. Don't inherit the _parent field of the parent type.
17667 Component
:= First_Entity
(Parent_Base
);
17668 while Present
(Component
) loop
17670 -- Ada 2005 (AI-251): Do not inherit components associated with
17671 -- secondary tags of the parent.
17673 if Ekind
(Component
) = E_Component
17674 and then Present
(Related_Type
(Component
))
17678 elsif Ekind
(Component
) /= E_Component
17679 or else Chars
(Component
) = Name_uParent
17683 -- If the derived type is within the parent type's declarative
17684 -- region, then the components can still be inherited even though
17685 -- they aren't visible at this point. This can occur for cases
17686 -- such as within public child units where the components must
17687 -- become visible upon entering the child unit's private part.
17689 elsif not Is_Visible_Component
(Component
)
17690 and then not In_Open_Scopes
(Scope
(Parent_Base
))
17694 elsif Ekind_In
(Derived_Base
, E_Private_Type
,
17695 E_Limited_Private_Type
)
17700 Inherit_Component
(Component
);
17703 Next_Entity
(Component
);
17706 -- For tagged derived types, inherited discriminants cannot be used in
17707 -- component declarations of the record extension part. To achieve this
17708 -- we mark the inherited discriminants as not visible.
17710 if Is_Tagged
and then Inherit_Discr
then
17711 D
:= First_Discriminant
(Derived_Base
);
17712 while Present
(D
) loop
17713 Set_Is_Immediately_Visible
(D
, False);
17714 Next_Discriminant
(D
);
17719 end Inherit_Components
;
17721 -----------------------------
17722 -- Inherit_Predicate_Flags --
17723 -----------------------------
17725 procedure Inherit_Predicate_Flags
(Subt
, Par
: Entity_Id
) is
17727 Set_Has_Predicates
(Subt
, Has_Predicates
(Par
));
17728 Set_Has_Static_Predicate_Aspect
17729 (Subt
, Has_Static_Predicate_Aspect
(Par
));
17730 Set_Has_Dynamic_Predicate_Aspect
17731 (Subt
, Has_Dynamic_Predicate_Aspect
(Par
));
17732 end Inherit_Predicate_Flags
;
17734 ----------------------
17735 -- Is_EVF_Procedure --
17736 ----------------------
17738 function Is_EVF_Procedure
(Subp
: Entity_Id
) return Boolean is
17739 Formal
: Entity_Id
;
17742 -- Examine the formals of an Extensions_Visible False procedure looking
17743 -- for a controlling OUT parameter.
17745 if Ekind
(Subp
) = E_Procedure
17746 and then Extensions_Visible_Status
(Subp
) = Extensions_Visible_False
17748 Formal
:= First_Formal
(Subp
);
17749 while Present
(Formal
) loop
17750 if Ekind
(Formal
) = E_Out_Parameter
17751 and then Is_Controlling_Formal
(Formal
)
17756 Next_Formal
(Formal
);
17761 end Is_EVF_Procedure
;
17763 -----------------------
17764 -- Is_Null_Extension --
17765 -----------------------
17767 function Is_Null_Extension
(T
: Entity_Id
) return Boolean is
17768 Type_Decl
: constant Node_Id
:= Parent
(Base_Type
(T
));
17769 Comp_List
: Node_Id
;
17773 if Nkind
(Type_Decl
) /= N_Full_Type_Declaration
17774 or else not Is_Tagged_Type
(T
)
17775 or else Nkind
(Type_Definition
(Type_Decl
)) /=
17776 N_Derived_Type_Definition
17777 or else No
(Record_Extension_Part
(Type_Definition
(Type_Decl
)))
17783 Component_List
(Record_Extension_Part
(Type_Definition
(Type_Decl
)));
17785 if Present
(Discriminant_Specifications
(Type_Decl
)) then
17788 elsif Present
(Comp_List
)
17789 and then Is_Non_Empty_List
(Component_Items
(Comp_List
))
17791 Comp
:= First
(Component_Items
(Comp_List
));
17793 -- Only user-defined components are relevant. The component list
17794 -- may also contain a parent component and internal components
17795 -- corresponding to secondary tags, but these do not determine
17796 -- whether this is a null extension.
17798 while Present
(Comp
) loop
17799 if Comes_From_Source
(Comp
) then
17811 end Is_Null_Extension
;
17813 ------------------------------
17814 -- Is_Valid_Constraint_Kind --
17815 ------------------------------
17817 function Is_Valid_Constraint_Kind
17818 (T_Kind
: Type_Kind
;
17819 Constraint_Kind
: Node_Kind
) return Boolean
17823 when Enumeration_Kind |
17825 return Constraint_Kind
= N_Range_Constraint
;
17827 when Decimal_Fixed_Point_Kind
=>
17828 return Nkind_In
(Constraint_Kind
, N_Digits_Constraint
,
17829 N_Range_Constraint
);
17831 when Ordinary_Fixed_Point_Kind
=>
17832 return Nkind_In
(Constraint_Kind
, N_Delta_Constraint
,
17833 N_Range_Constraint
);
17836 return Nkind_In
(Constraint_Kind
, N_Digits_Constraint
,
17837 N_Range_Constraint
);
17844 E_Incomplete_Type |
17847 return Constraint_Kind
= N_Index_Or_Discriminant_Constraint
;
17850 return True; -- Error will be detected later
17852 end Is_Valid_Constraint_Kind
;
17854 --------------------------
17855 -- Is_Visible_Component --
17856 --------------------------
17858 function Is_Visible_Component
17860 N
: Node_Id
:= Empty
) return Boolean
17862 Original_Comp
: Entity_Id
:= Empty
;
17863 Original_Scope
: Entity_Id
;
17864 Type_Scope
: Entity_Id
;
17866 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean;
17867 -- Check whether parent type of inherited component is declared locally,
17868 -- possibly within a nested package or instance. The current scope is
17869 -- the derived record itself.
17871 -------------------
17872 -- Is_Local_Type --
17873 -------------------
17875 function Is_Local_Type
(Typ
: Entity_Id
) return Boolean is
17879 Scop
:= Scope
(Typ
);
17880 while Present
(Scop
)
17881 and then Scop
/= Standard_Standard
17883 if Scop
= Scope
(Current_Scope
) then
17887 Scop
:= Scope
(Scop
);
17893 -- Start of processing for Is_Visible_Component
17896 if Ekind_In
(C
, E_Component
, E_Discriminant
) then
17897 Original_Comp
:= Original_Record_Component
(C
);
17900 if No
(Original_Comp
) then
17902 -- Premature usage, or previous error
17907 Original_Scope
:= Scope
(Original_Comp
);
17908 Type_Scope
:= Scope
(Base_Type
(Scope
(C
)));
17911 -- This test only concerns tagged types
17913 if not Is_Tagged_Type
(Original_Scope
) then
17916 -- If it is _Parent or _Tag, there is no visibility issue
17918 elsif not Comes_From_Source
(Original_Comp
) then
17921 -- Discriminants are visible unless the (private) type has unknown
17922 -- discriminants. If the discriminant reference is inserted for a
17923 -- discriminant check on a full view it is also visible.
17925 elsif Ekind
(Original_Comp
) = E_Discriminant
17927 (not Has_Unknown_Discriminants
(Original_Scope
)
17928 or else (Present
(N
)
17929 and then Nkind
(N
) = N_Selected_Component
17930 and then Nkind
(Prefix
(N
)) = N_Type_Conversion
17931 and then not Comes_From_Source
(Prefix
(N
))))
17935 -- In the body of an instantiation, no need to check for the visibility
17938 elsif In_Instance_Body
then
17941 -- If the component has been declared in an ancestor which is currently
17942 -- a private type, then it is not visible. The same applies if the
17943 -- component's containing type is not in an open scope and the original
17944 -- component's enclosing type is a visible full view of a private type
17945 -- (which can occur in cases where an attempt is being made to reference
17946 -- a component in a sibling package that is inherited from a visible
17947 -- component of a type in an ancestor package; the component in the
17948 -- sibling package should not be visible even though the component it
17949 -- inherited from is visible). This does not apply however in the case
17950 -- where the scope of the type is a private child unit, or when the
17951 -- parent comes from a local package in which the ancestor is currently
17952 -- visible. The latter suppression of visibility is needed for cases
17953 -- that are tested in B730006.
17955 elsif Is_Private_Type
(Original_Scope
)
17957 (not Is_Private_Descendant
(Type_Scope
)
17958 and then not In_Open_Scopes
(Type_Scope
)
17959 and then Has_Private_Declaration
(Original_Scope
))
17961 -- If the type derives from an entity in a formal package, there
17962 -- are no additional visible components.
17964 if Nkind
(Original_Node
(Unit_Declaration_Node
(Type_Scope
))) =
17965 N_Formal_Package_Declaration
17969 -- if we are not in the private part of the current package, there
17970 -- are no additional visible components.
17972 elsif Ekind
(Scope
(Current_Scope
)) = E_Package
17973 and then not In_Private_Part
(Scope
(Current_Scope
))
17978 Is_Child_Unit
(Cunit_Entity
(Current_Sem_Unit
))
17979 and then In_Open_Scopes
(Scope
(Original_Scope
))
17980 and then Is_Local_Type
(Type_Scope
);
17983 -- There is another weird way in which a component may be invisible when
17984 -- the private and the full view are not derived from the same ancestor.
17985 -- Here is an example :
17987 -- type A1 is tagged record F1 : integer; end record;
17988 -- type A2 is new A1 with record F2 : integer; end record;
17989 -- type T is new A1 with private;
17991 -- type T is new A2 with null record;
17993 -- In this case, the full view of T inherits F1 and F2 but the private
17994 -- view inherits only F1
17998 Ancestor
: Entity_Id
:= Scope
(C
);
18002 if Ancestor
= Original_Scope
then
18004 elsif Ancestor
= Etype
(Ancestor
) then
18008 Ancestor
:= Etype
(Ancestor
);
18012 end Is_Visible_Component
;
18014 --------------------------
18015 -- Make_Class_Wide_Type --
18016 --------------------------
18018 procedure Make_Class_Wide_Type
(T
: Entity_Id
) is
18019 CW_Type
: Entity_Id
;
18021 Next_E
: Entity_Id
;
18024 if Present
(Class_Wide_Type
(T
)) then
18026 -- The class-wide type is a partially decorated entity created for a
18027 -- unanalyzed tagged type referenced through a limited with clause.
18028 -- When the tagged type is analyzed, its class-wide type needs to be
18029 -- redecorated. Note that we reuse the entity created by Decorate_
18030 -- Tagged_Type in order to preserve all links.
18032 if Materialize_Entity
(Class_Wide_Type
(T
)) then
18033 CW_Type
:= Class_Wide_Type
(T
);
18034 Set_Materialize_Entity
(CW_Type
, False);
18036 -- The class wide type can have been defined by the partial view, in
18037 -- which case everything is already done.
18043 -- Default case, we need to create a new class-wide type
18047 New_External_Entity
(E_Void
, Scope
(T
), Sloc
(T
), T
, 'C', 0, 'T');
18050 -- Inherit root type characteristics
18052 CW_Name
:= Chars
(CW_Type
);
18053 Next_E
:= Next_Entity
(CW_Type
);
18054 Copy_Node
(T
, CW_Type
);
18055 Set_Comes_From_Source
(CW_Type
, False);
18056 Set_Chars
(CW_Type
, CW_Name
);
18057 Set_Parent
(CW_Type
, Parent
(T
));
18058 Set_Next_Entity
(CW_Type
, Next_E
);
18060 -- Ensure we have a new freeze node for the class-wide type. The partial
18061 -- view may have freeze action of its own, requiring a proper freeze
18062 -- node, and the same freeze node cannot be shared between the two
18065 Set_Has_Delayed_Freeze
(CW_Type
);
18066 Set_Freeze_Node
(CW_Type
, Empty
);
18068 -- Customize the class-wide type: It has no prim. op., it cannot be
18069 -- abstract and its Etype points back to the specific root type.
18071 Set_Ekind
(CW_Type
, E_Class_Wide_Type
);
18072 Set_Is_Tagged_Type
(CW_Type
, True);
18073 Set_Direct_Primitive_Operations
(CW_Type
, New_Elmt_List
);
18074 Set_Is_Abstract_Type
(CW_Type
, False);
18075 Set_Is_Constrained
(CW_Type
, False);
18076 Set_Is_First_Subtype
(CW_Type
, Is_First_Subtype
(T
));
18077 Set_Default_SSO
(CW_Type
);
18079 if Ekind
(T
) = E_Class_Wide_Subtype
then
18080 Set_Etype
(CW_Type
, Etype
(Base_Type
(T
)));
18082 Set_Etype
(CW_Type
, T
);
18085 Set_No_Tagged_Streams_Pragma
(CW_Type
, No_Tagged_Streams
);
18087 -- If this is the class_wide type of a constrained subtype, it does
18088 -- not have discriminants.
18090 Set_Has_Discriminants
(CW_Type
,
18091 Has_Discriminants
(T
) and then not Is_Constrained
(T
));
18093 Set_Has_Unknown_Discriminants
(CW_Type
, True);
18094 Set_Class_Wide_Type
(T
, CW_Type
);
18095 Set_Equivalent_Type
(CW_Type
, Empty
);
18097 -- The class-wide type of a class-wide type is itself (RM 3.9(14))
18099 Set_Class_Wide_Type
(CW_Type
, CW_Type
);
18100 end Make_Class_Wide_Type
;
18106 procedure Make_Index
18108 Related_Nod
: Node_Id
;
18109 Related_Id
: Entity_Id
:= Empty
;
18110 Suffix_Index
: Nat
:= 1;
18111 In_Iter_Schm
: Boolean := False)
18115 Def_Id
: Entity_Id
:= Empty
;
18116 Found
: Boolean := False;
18119 -- For a discrete range used in a constrained array definition and
18120 -- defined by a range, an implicit conversion to the predefined type
18121 -- INTEGER is assumed if each bound is either a numeric literal, a named
18122 -- number, or an attribute, and the type of both bounds (prior to the
18123 -- implicit conversion) is the type universal_integer. Otherwise, both
18124 -- bounds must be of the same discrete type, other than universal
18125 -- integer; this type must be determinable independently of the
18126 -- context, but using the fact that the type must be discrete and that
18127 -- both bounds must have the same type.
18129 -- Character literals also have a universal type in the absence of
18130 -- of additional context, and are resolved to Standard_Character.
18132 if Nkind
(N
) = N_Range
then
18134 -- The index is given by a range constraint. The bounds are known
18135 -- to be of a consistent type.
18137 if not Is_Overloaded
(N
) then
18140 -- For universal bounds, choose the specific predefined type
18142 if T
= Universal_Integer
then
18143 T
:= Standard_Integer
;
18145 elsif T
= Any_Character
then
18146 Ambiguous_Character
(Low_Bound
(N
));
18148 T
:= Standard_Character
;
18151 -- The node may be overloaded because some user-defined operators
18152 -- are available, but if a universal interpretation exists it is
18153 -- also the selected one.
18155 elsif Universal_Interpretation
(N
) = Universal_Integer
then
18156 T
:= Standard_Integer
;
18162 Ind
: Interp_Index
;
18166 Get_First_Interp
(N
, Ind
, It
);
18167 while Present
(It
.Typ
) loop
18168 if Is_Discrete_Type
(It
.Typ
) then
18171 and then not Covers
(It
.Typ
, T
)
18172 and then not Covers
(T
, It
.Typ
)
18174 Error_Msg_N
("ambiguous bounds in discrete range", N
);
18182 Get_Next_Interp
(Ind
, It
);
18185 if T
= Any_Type
then
18186 Error_Msg_N
("discrete type required for range", N
);
18187 Set_Etype
(N
, Any_Type
);
18190 elsif T
= Universal_Integer
then
18191 T
:= Standard_Integer
;
18196 if not Is_Discrete_Type
(T
) then
18197 Error_Msg_N
("discrete type required for range", N
);
18198 Set_Etype
(N
, Any_Type
);
18202 if Nkind
(Low_Bound
(N
)) = N_Attribute_Reference
18203 and then Attribute_Name
(Low_Bound
(N
)) = Name_First
18204 and then Is_Entity_Name
(Prefix
(Low_Bound
(N
)))
18205 and then Is_Type
(Entity
(Prefix
(Low_Bound
(N
))))
18206 and then Is_Discrete_Type
(Entity
(Prefix
(Low_Bound
(N
))))
18208 -- The type of the index will be the type of the prefix, as long
18209 -- as the upper bound is 'Last of the same type.
18211 Def_Id
:= Entity
(Prefix
(Low_Bound
(N
)));
18213 if Nkind
(High_Bound
(N
)) /= N_Attribute_Reference
18214 or else Attribute_Name
(High_Bound
(N
)) /= Name_Last
18215 or else not Is_Entity_Name
(Prefix
(High_Bound
(N
)))
18216 or else Entity
(Prefix
(High_Bound
(N
))) /= Def_Id
18223 Process_Range_Expr_In_Decl
(R
, T
, In_Iter_Schm
=> In_Iter_Schm
);
18225 elsif Nkind
(N
) = N_Subtype_Indication
then
18227 -- The index is given by a subtype with a range constraint
18229 T
:= Base_Type
(Entity
(Subtype_Mark
(N
)));
18231 if not Is_Discrete_Type
(T
) then
18232 Error_Msg_N
("discrete type required for range", N
);
18233 Set_Etype
(N
, Any_Type
);
18237 R
:= Range_Expression
(Constraint
(N
));
18240 Process_Range_Expr_In_Decl
18241 (R
, Entity
(Subtype_Mark
(N
)), In_Iter_Schm
=> In_Iter_Schm
);
18243 elsif Nkind
(N
) = N_Attribute_Reference
then
18245 -- Catch beginner's error (use of attribute other than 'Range)
18247 if Attribute_Name
(N
) /= Name_Range
then
18248 Error_Msg_N
("expect attribute ''Range", N
);
18249 Set_Etype
(N
, Any_Type
);
18253 -- If the node denotes the range of a type mark, that is also the
18254 -- resulting type, and we do not need to create an Itype for it.
18256 if Is_Entity_Name
(Prefix
(N
))
18257 and then Comes_From_Source
(N
)
18258 and then Is_Type
(Entity
(Prefix
(N
)))
18259 and then Is_Discrete_Type
(Entity
(Prefix
(N
)))
18261 Def_Id
:= Entity
(Prefix
(N
));
18264 Analyze_And_Resolve
(N
);
18268 -- If none of the above, must be a subtype. We convert this to a
18269 -- range attribute reference because in the case of declared first
18270 -- named subtypes, the types in the range reference can be different
18271 -- from the type of the entity. A range attribute normalizes the
18272 -- reference and obtains the correct types for the bounds.
18274 -- This transformation is in the nature of an expansion, is only
18275 -- done if expansion is active. In particular, it is not done on
18276 -- formal generic types, because we need to retain the name of the
18277 -- original index for instantiation purposes.
18280 if not Is_Entity_Name
(N
) or else not Is_Type
(Entity
(N
)) then
18281 Error_Msg_N
("invalid subtype mark in discrete range ", N
);
18282 Set_Etype
(N
, Any_Integer
);
18286 -- The type mark may be that of an incomplete type. It is only
18287 -- now that we can get the full view, previous analysis does
18288 -- not look specifically for a type mark.
18290 Set_Entity
(N
, Get_Full_View
(Entity
(N
)));
18291 Set_Etype
(N
, Entity
(N
));
18292 Def_Id
:= Entity
(N
);
18294 if not Is_Discrete_Type
(Def_Id
) then
18295 Error_Msg_N
("discrete type required for index", N
);
18296 Set_Etype
(N
, Any_Type
);
18301 if Expander_Active
then
18303 Make_Attribute_Reference
(Sloc
(N
),
18304 Attribute_Name
=> Name_Range
,
18305 Prefix
=> Relocate_Node
(N
)));
18307 -- The original was a subtype mark that does not freeze. This
18308 -- means that the rewritten version must not freeze either.
18310 Set_Must_Not_Freeze
(N
);
18311 Set_Must_Not_Freeze
(Prefix
(N
));
18312 Analyze_And_Resolve
(N
);
18316 -- If expander is inactive, type is legal, nothing else to construct
18323 if not Is_Discrete_Type
(T
) then
18324 Error_Msg_N
("discrete type required for range", N
);
18325 Set_Etype
(N
, Any_Type
);
18328 elsif T
= Any_Type
then
18329 Set_Etype
(N
, Any_Type
);
18333 -- We will now create the appropriate Itype to describe the range, but
18334 -- first a check. If we originally had a subtype, then we just label
18335 -- the range with this subtype. Not only is there no need to construct
18336 -- a new subtype, but it is wrong to do so for two reasons:
18338 -- 1. A legality concern, if we have a subtype, it must not freeze,
18339 -- and the Itype would cause freezing incorrectly
18341 -- 2. An efficiency concern, if we created an Itype, it would not be
18342 -- recognized as the same type for the purposes of eliminating
18343 -- checks in some circumstances.
18345 -- We signal this case by setting the subtype entity in Def_Id
18347 if No
(Def_Id
) then
18349 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, 'D', Suffix_Index
);
18350 Set_Etype
(Def_Id
, Base_Type
(T
));
18352 if Is_Signed_Integer_Type
(T
) then
18353 Set_Ekind
(Def_Id
, E_Signed_Integer_Subtype
);
18355 elsif Is_Modular_Integer_Type
(T
) then
18356 Set_Ekind
(Def_Id
, E_Modular_Integer_Subtype
);
18359 Set_Ekind
(Def_Id
, E_Enumeration_Subtype
);
18360 Set_Is_Character_Type
(Def_Id
, Is_Character_Type
(T
));
18361 Set_First_Literal
(Def_Id
, First_Literal
(T
));
18364 Set_Size_Info
(Def_Id
, (T
));
18365 Set_RM_Size
(Def_Id
, RM_Size
(T
));
18366 Set_First_Rep_Item
(Def_Id
, First_Rep_Item
(T
));
18368 Set_Scalar_Range
(Def_Id
, R
);
18369 Conditional_Delay
(Def_Id
, T
);
18371 if Nkind
(N
) = N_Subtype_Indication
then
18372 Inherit_Predicate_Flags
(Def_Id
, Entity
(Subtype_Mark
(N
)));
18375 -- In the subtype indication case, if the immediate parent of the
18376 -- new subtype is non-static, then the subtype we create is non-
18377 -- static, even if its bounds are static.
18379 if Nkind
(N
) = N_Subtype_Indication
18380 and then not Is_OK_Static_Subtype
(Entity
(Subtype_Mark
(N
)))
18382 Set_Is_Non_Static_Subtype
(Def_Id
);
18386 -- Final step is to label the index with this constructed type
18388 Set_Etype
(N
, Def_Id
);
18391 ------------------------------
18392 -- Modular_Type_Declaration --
18393 ------------------------------
18395 procedure Modular_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
18396 Mod_Expr
: constant Node_Id
:= Expression
(Def
);
18399 procedure Set_Modular_Size
(Bits
: Int
);
18400 -- Sets RM_Size to Bits, and Esize to normal word size above this
18402 ----------------------
18403 -- Set_Modular_Size --
18404 ----------------------
18406 procedure Set_Modular_Size
(Bits
: Int
) is
18408 Set_RM_Size
(T
, UI_From_Int
(Bits
));
18413 elsif Bits
<= 16 then
18414 Init_Esize
(T
, 16);
18416 elsif Bits
<= 32 then
18417 Init_Esize
(T
, 32);
18420 Init_Esize
(T
, System_Max_Binary_Modulus_Power
);
18423 if not Non_Binary_Modulus
(T
) and then Esize
(T
) = RM_Size
(T
) then
18424 Set_Is_Known_Valid
(T
);
18426 end Set_Modular_Size
;
18428 -- Start of processing for Modular_Type_Declaration
18431 -- If the mod expression is (exactly) 2 * literal, where literal is
18432 -- 64 or less,then almost certainly the * was meant to be **. Warn.
18434 if Warn_On_Suspicious_Modulus_Value
18435 and then Nkind
(Mod_Expr
) = N_Op_Multiply
18436 and then Nkind
(Left_Opnd
(Mod_Expr
)) = N_Integer_Literal
18437 and then Intval
(Left_Opnd
(Mod_Expr
)) = Uint_2
18438 and then Nkind
(Right_Opnd
(Mod_Expr
)) = N_Integer_Literal
18439 and then Intval
(Right_Opnd
(Mod_Expr
)) <= Uint_64
18442 ("suspicious MOD value, was '*'* intended'??M?", Mod_Expr
);
18445 -- Proceed with analysis of mod expression
18447 Analyze_And_Resolve
(Mod_Expr
, Any_Integer
);
18449 Set_Ekind
(T
, E_Modular_Integer_Type
);
18450 Init_Alignment
(T
);
18451 Set_Is_Constrained
(T
);
18453 if not Is_OK_Static_Expression
(Mod_Expr
) then
18454 Flag_Non_Static_Expr
18455 ("non-static expression used for modular type bound!", Mod_Expr
);
18456 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
18458 M_Val
:= Expr_Value
(Mod_Expr
);
18462 Error_Msg_N
("modulus value must be positive", Mod_Expr
);
18463 M_Val
:= 2 ** System_Max_Binary_Modulus_Power
;
18466 if M_Val
> 2 ** Standard_Long_Integer_Size
then
18467 Check_Restriction
(No_Long_Long_Integers
, Mod_Expr
);
18470 Set_Modulus
(T
, M_Val
);
18472 -- Create bounds for the modular type based on the modulus given in
18473 -- the type declaration and then analyze and resolve those bounds.
18475 Set_Scalar_Range
(T
,
18476 Make_Range
(Sloc
(Mod_Expr
),
18477 Low_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), 0),
18478 High_Bound
=> Make_Integer_Literal
(Sloc
(Mod_Expr
), M_Val
- 1)));
18480 -- Properly analyze the literals for the range. We do this manually
18481 -- because we can't go calling Resolve, since we are resolving these
18482 -- bounds with the type, and this type is certainly not complete yet.
18484 Set_Etype
(Low_Bound
(Scalar_Range
(T
)), T
);
18485 Set_Etype
(High_Bound
(Scalar_Range
(T
)), T
);
18486 Set_Is_Static_Expression
(Low_Bound
(Scalar_Range
(T
)));
18487 Set_Is_Static_Expression
(High_Bound
(Scalar_Range
(T
)));
18489 -- Loop through powers of two to find number of bits required
18491 for Bits
in Int
range 0 .. System_Max_Binary_Modulus_Power
loop
18495 if M_Val
= 2 ** Bits
then
18496 Set_Modular_Size
(Bits
);
18501 elsif M_Val
< 2 ** Bits
then
18502 Check_SPARK_05_Restriction
("modulus should be a power of 2", T
);
18503 Set_Non_Binary_Modulus
(T
);
18505 if Bits
> System_Max_Nonbinary_Modulus_Power
then
18506 Error_Msg_Uint_1
:=
18507 UI_From_Int
(System_Max_Nonbinary_Modulus_Power
);
18509 ("nonbinary modulus exceeds limit (2 '*'*^ - 1)", Mod_Expr
);
18510 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
18514 -- In the non-binary case, set size as per RM 13.3(55)
18516 Set_Modular_Size
(Bits
);
18523 -- If we fall through, then the size exceed System.Max_Binary_Modulus
18524 -- so we just signal an error and set the maximum size.
18526 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Binary_Modulus_Power
);
18527 Error_Msg_F
("modulus exceeds limit (2 '*'*^)", Mod_Expr
);
18529 Set_Modular_Size
(System_Max_Binary_Modulus_Power
);
18530 Init_Alignment
(T
);
18532 end Modular_Type_Declaration
;
18534 --------------------------
18535 -- New_Concatenation_Op --
18536 --------------------------
18538 procedure New_Concatenation_Op
(Typ
: Entity_Id
) is
18539 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
18542 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
;
18543 -- Create abbreviated declaration for the formal of a predefined
18544 -- Operator 'Op' of type 'Typ'
18546 --------------------
18547 -- Make_Op_Formal --
18548 --------------------
18550 function Make_Op_Formal
(Typ
, Op
: Entity_Id
) return Entity_Id
is
18551 Formal
: Entity_Id
;
18553 Formal
:= New_Internal_Entity
(E_In_Parameter
, Op
, Loc
, 'P');
18554 Set_Etype
(Formal
, Typ
);
18555 Set_Mechanism
(Formal
, Default_Mechanism
);
18557 end Make_Op_Formal
;
18559 -- Start of processing for New_Concatenation_Op
18562 Op
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Concat
);
18564 Set_Ekind
(Op
, E_Operator
);
18565 Set_Scope
(Op
, Current_Scope
);
18566 Set_Etype
(Op
, Typ
);
18567 Set_Homonym
(Op
, Get_Name_Entity_Id
(Name_Op_Concat
));
18568 Set_Is_Immediately_Visible
(Op
);
18569 Set_Is_Intrinsic_Subprogram
(Op
);
18570 Set_Has_Completion
(Op
);
18571 Append_Entity
(Op
, Current_Scope
);
18573 Set_Name_Entity_Id
(Name_Op_Concat
, Op
);
18575 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
18576 Append_Entity
(Make_Op_Formal
(Typ
, Op
), Op
);
18577 end New_Concatenation_Op
;
18579 -------------------------
18580 -- OK_For_Limited_Init --
18581 -------------------------
18583 -- ???Check all calls of this, and compare the conditions under which it's
18586 function OK_For_Limited_Init
18588 Exp
: Node_Id
) return Boolean
18591 return Is_CPP_Constructor_Call
(Exp
)
18592 or else (Ada_Version
>= Ada_2005
18593 and then not Debug_Flag_Dot_L
18594 and then OK_For_Limited_Init_In_05
(Typ
, Exp
));
18595 end OK_For_Limited_Init
;
18597 -------------------------------
18598 -- OK_For_Limited_Init_In_05 --
18599 -------------------------------
18601 function OK_For_Limited_Init_In_05
18603 Exp
: Node_Id
) return Boolean
18606 -- An object of a limited interface type can be initialized with any
18607 -- expression of a nonlimited descendant type.
18609 if Is_Class_Wide_Type
(Typ
)
18610 and then Is_Limited_Interface
(Typ
)
18611 and then not Is_Limited_Type
(Etype
(Exp
))
18616 -- Ada 2005 (AI-287, AI-318): Relax the strictness of the front end in
18617 -- case of limited aggregates (including extension aggregates), and
18618 -- function calls. The function call may have been given in prefixed
18619 -- notation, in which case the original node is an indexed component.
18620 -- If the function is parameterless, the original node was an explicit
18621 -- dereference. The function may also be parameterless, in which case
18622 -- the source node is just an identifier.
18624 case Nkind
(Original_Node
(Exp
)) is
18625 when N_Aggregate | N_Extension_Aggregate | N_Function_Call | N_Op
=>
18628 when N_Identifier
=>
18629 return Present
(Entity
(Original_Node
(Exp
)))
18630 and then Ekind
(Entity
(Original_Node
(Exp
))) = E_Function
;
18632 when N_Qualified_Expression
=>
18634 OK_For_Limited_Init_In_05
18635 (Typ
, Expression
(Original_Node
(Exp
)));
18637 -- Ada 2005 (AI-251): If a class-wide interface object is initialized
18638 -- with a function call, the expander has rewritten the call into an
18639 -- N_Type_Conversion node to force displacement of the pointer to
18640 -- reference the component containing the secondary dispatch table.
18641 -- Otherwise a type conversion is not a legal context.
18642 -- A return statement for a build-in-place function returning a
18643 -- synchronized type also introduces an unchecked conversion.
18645 when N_Type_Conversion |
18646 N_Unchecked_Type_Conversion
=>
18647 return not Comes_From_Source
(Exp
)
18649 OK_For_Limited_Init_In_05
18650 (Typ
, Expression
(Original_Node
(Exp
)));
18652 when N_Indexed_Component |
18653 N_Selected_Component |
18654 N_Explicit_Dereference
=>
18655 return Nkind
(Exp
) = N_Function_Call
;
18657 -- A use of 'Input is a function call, hence allowed. Normally the
18658 -- attribute will be changed to a call, but the attribute by itself
18659 -- can occur with -gnatc.
18661 when N_Attribute_Reference
=>
18662 return Attribute_Name
(Original_Node
(Exp
)) = Name_Input
;
18664 -- For a case expression, all dependent expressions must be legal
18666 when N_Case_Expression
=>
18671 Alt
:= First
(Alternatives
(Original_Node
(Exp
)));
18672 while Present
(Alt
) loop
18673 if not OK_For_Limited_Init_In_05
(Typ
, Expression
(Alt
)) then
18683 -- For an if expression, all dependent expressions must be legal
18685 when N_If_Expression
=>
18687 Then_Expr
: constant Node_Id
:=
18688 Next
(First
(Expressions
(Original_Node
(Exp
))));
18689 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
18691 return OK_For_Limited_Init_In_05
(Typ
, Then_Expr
)
18693 OK_For_Limited_Init_In_05
(Typ
, Else_Expr
);
18699 end OK_For_Limited_Init_In_05
;
18701 -------------------------------------------
18702 -- Ordinary_Fixed_Point_Type_Declaration --
18703 -------------------------------------------
18705 procedure Ordinary_Fixed_Point_Type_Declaration
18709 Loc
: constant Source_Ptr
:= Sloc
(Def
);
18710 Delta_Expr
: constant Node_Id
:= Delta_Expression
(Def
);
18711 RRS
: constant Node_Id
:= Real_Range_Specification
(Def
);
18712 Implicit_Base
: Entity_Id
;
18719 Check_Restriction
(No_Fixed_Point
, Def
);
18721 -- Create implicit base type
18724 Create_Itype
(E_Ordinary_Fixed_Point_Type
, Parent
(Def
), T
, 'B');
18725 Set_Etype
(Implicit_Base
, Implicit_Base
);
18727 -- Analyze and process delta expression
18729 Analyze_And_Resolve
(Delta_Expr
, Any_Real
);
18731 Check_Delta_Expression
(Delta_Expr
);
18732 Delta_Val
:= Expr_Value_R
(Delta_Expr
);
18734 Set_Delta_Value
(Implicit_Base
, Delta_Val
);
18736 -- Compute default small from given delta, which is the largest power
18737 -- of two that does not exceed the given delta value.
18747 if Delta_Val
< Ureal_1
then
18748 while Delta_Val
< Tmp
loop
18749 Tmp
:= Tmp
/ Ureal_2
;
18750 Scale
:= Scale
+ 1;
18755 Tmp
:= Tmp
* Ureal_2
;
18756 exit when Tmp
> Delta_Val
;
18757 Scale
:= Scale
- 1;
18761 Small_Val
:= UR_From_Components
(Uint_1
, UI_From_Int
(Scale
), 2);
18764 Set_Small_Value
(Implicit_Base
, Small_Val
);
18766 -- If no range was given, set a dummy range
18768 if RRS
<= Empty_Or_Error
then
18769 Low_Val
:= -Small_Val
;
18770 High_Val
:= Small_Val
;
18772 -- Otherwise analyze and process given range
18776 Low
: constant Node_Id
:= Low_Bound
(RRS
);
18777 High
: constant Node_Id
:= High_Bound
(RRS
);
18780 Analyze_And_Resolve
(Low
, Any_Real
);
18781 Analyze_And_Resolve
(High
, Any_Real
);
18782 Check_Real_Bound
(Low
);
18783 Check_Real_Bound
(High
);
18785 -- Obtain and set the range
18787 Low_Val
:= Expr_Value_R
(Low
);
18788 High_Val
:= Expr_Value_R
(High
);
18790 if Low_Val
> High_Val
then
18791 Error_Msg_NE
("??fixed point type& has null range", Def
, T
);
18796 -- The range for both the implicit base and the declared first subtype
18797 -- cannot be set yet, so we use the special routine Set_Fixed_Range to
18798 -- set a temporary range in place. Note that the bounds of the base
18799 -- type will be widened to be symmetrical and to fill the available
18800 -- bits when the type is frozen.
18802 -- We could do this with all discrete types, and probably should, but
18803 -- we absolutely have to do it for fixed-point, since the end-points
18804 -- of the range and the size are determined by the small value, which
18805 -- could be reset before the freeze point.
18807 Set_Fixed_Range
(Implicit_Base
, Loc
, Low_Val
, High_Val
);
18808 Set_Fixed_Range
(T
, Loc
, Low_Val
, High_Val
);
18810 -- Complete definition of first subtype. The inheritance of the rep item
18811 -- chain ensures that SPARK-related pragmas are not clobbered when the
18812 -- ordinary fixed point type acts as a full view of a private type.
18814 Set_Ekind
(T
, E_Ordinary_Fixed_Point_Subtype
);
18815 Set_Etype
(T
, Implicit_Base
);
18816 Init_Size_Align
(T
);
18817 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
18818 Set_Small_Value
(T
, Small_Val
);
18819 Set_Delta_Value
(T
, Delta_Val
);
18820 Set_Is_Constrained
(T
);
18821 end Ordinary_Fixed_Point_Type_Declaration
;
18823 ----------------------------------
18824 -- Preanalyze_Assert_Expression --
18825 ----------------------------------
18827 procedure Preanalyze_Assert_Expression
(N
: Node_Id
; T
: Entity_Id
) is
18829 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
18830 Preanalyze_Spec_Expression
(N
, T
);
18831 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
18832 end Preanalyze_Assert_Expression
;
18834 -----------------------------------
18835 -- Preanalyze_Default_Expression --
18836 -----------------------------------
18838 procedure Preanalyze_Default_Expression
(N
: Node_Id
; T
: Entity_Id
) is
18839 Save_In_Default_Expr
: constant Boolean := In_Default_Expr
;
18841 In_Default_Expr
:= True;
18842 Preanalyze_Spec_Expression
(N
, T
);
18843 In_Default_Expr
:= Save_In_Default_Expr
;
18844 end Preanalyze_Default_Expression
;
18846 --------------------------------
18847 -- Preanalyze_Spec_Expression --
18848 --------------------------------
18850 procedure Preanalyze_Spec_Expression
(N
: Node_Id
; T
: Entity_Id
) is
18851 Save_In_Spec_Expression
: constant Boolean := In_Spec_Expression
;
18853 In_Spec_Expression
:= True;
18854 Preanalyze_And_Resolve
(N
, T
);
18855 In_Spec_Expression
:= Save_In_Spec_Expression
;
18856 end Preanalyze_Spec_Expression
;
18858 ----------------------------------------
18859 -- Prepare_Private_Subtype_Completion --
18860 ----------------------------------------
18862 procedure Prepare_Private_Subtype_Completion
18864 Related_Nod
: Node_Id
)
18866 Id_B
: constant Entity_Id
:= Base_Type
(Id
);
18867 Full_B
: Entity_Id
:= Full_View
(Id_B
);
18871 if Present
(Full_B
) then
18873 -- Get to the underlying full view if necessary
18875 if Is_Private_Type
(Full_B
)
18876 and then Present
(Underlying_Full_View
(Full_B
))
18878 Full_B
:= Underlying_Full_View
(Full_B
);
18881 -- The Base_Type is already completed, we can complete the subtype
18882 -- now. We have to create a new entity with the same name, Thus we
18883 -- can't use Create_Itype.
18885 Full
:= Make_Defining_Identifier
(Sloc
(Id
), Chars
(Id
));
18886 Set_Is_Itype
(Full
);
18887 Set_Associated_Node_For_Itype
(Full
, Related_Nod
);
18888 Complete_Private_Subtype
(Id
, Full
, Full_B
, Related_Nod
);
18891 -- The parent subtype may be private, but the base might not, in some
18892 -- nested instances. In that case, the subtype does not need to be
18893 -- exchanged. It would still be nice to make private subtypes and their
18894 -- bases consistent at all times ???
18896 if Is_Private_Type
(Id_B
) then
18897 Append_Elmt
(Id
, Private_Dependents
(Id_B
));
18899 end Prepare_Private_Subtype_Completion
;
18901 ---------------------------
18902 -- Process_Discriminants --
18903 ---------------------------
18905 procedure Process_Discriminants
18907 Prev
: Entity_Id
:= Empty
)
18909 Elist
: constant Elist_Id
:= New_Elmt_List
;
18912 Discr_Number
: Uint
;
18913 Discr_Type
: Entity_Id
;
18914 Default_Present
: Boolean := False;
18915 Default_Not_Present
: Boolean := False;
18918 -- A composite type other than an array type can have discriminants.
18919 -- On entry, the current scope is the composite type.
18921 -- The discriminants are initially entered into the scope of the type
18922 -- via Enter_Name with the default Ekind of E_Void to prevent premature
18923 -- use, as explained at the end of this procedure.
18925 Discr
:= First
(Discriminant_Specifications
(N
));
18926 while Present
(Discr
) loop
18927 Enter_Name
(Defining_Identifier
(Discr
));
18929 -- For navigation purposes we add a reference to the discriminant
18930 -- in the entity for the type. If the current declaration is a
18931 -- completion, place references on the partial view. Otherwise the
18932 -- type is the current scope.
18934 if Present
(Prev
) then
18936 -- The references go on the partial view, if present. If the
18937 -- partial view has discriminants, the references have been
18938 -- generated already.
18940 if not Has_Discriminants
(Prev
) then
18941 Generate_Reference
(Prev
, Defining_Identifier
(Discr
), 'd');
18945 (Current_Scope
, Defining_Identifier
(Discr
), 'd');
18948 if Nkind
(Discriminant_Type
(Discr
)) = N_Access_Definition
then
18949 Discr_Type
:= Access_Definition
(Discr
, Discriminant_Type
(Discr
));
18951 -- Ada 2005 (AI-254)
18953 if Present
(Access_To_Subprogram_Definition
18954 (Discriminant_Type
(Discr
)))
18955 and then Protected_Present
(Access_To_Subprogram_Definition
18956 (Discriminant_Type
(Discr
)))
18959 Replace_Anonymous_Access_To_Protected_Subprogram
(Discr
);
18963 Find_Type
(Discriminant_Type
(Discr
));
18964 Discr_Type
:= Etype
(Discriminant_Type
(Discr
));
18966 if Error_Posted
(Discriminant_Type
(Discr
)) then
18967 Discr_Type
:= Any_Type
;
18971 -- Handling of discriminants that are access types
18973 if Is_Access_Type
(Discr_Type
) then
18975 -- Ada 2005 (AI-230): Access discriminant allowed in non-
18976 -- limited record types
18978 if Ada_Version
< Ada_2005
then
18979 Check_Access_Discriminant_Requires_Limited
18980 (Discr
, Discriminant_Type
(Discr
));
18983 if Ada_Version
= Ada_83
and then Comes_From_Source
(Discr
) then
18985 ("(Ada 83) access discriminant not allowed", Discr
);
18988 -- If not access type, must be a discrete type
18990 elsif not Is_Discrete_Type
(Discr_Type
) then
18992 ("discriminants must have a discrete or access type",
18993 Discriminant_Type
(Discr
));
18996 Set_Etype
(Defining_Identifier
(Discr
), Discr_Type
);
18998 -- If a discriminant specification includes the assignment compound
18999 -- delimiter followed by an expression, the expression is the default
19000 -- expression of the discriminant; the default expression must be of
19001 -- the type of the discriminant. (RM 3.7.1) Since this expression is
19002 -- a default expression, we do the special preanalysis, since this
19003 -- expression does not freeze (see section "Handling of Default and
19004 -- Per-Object Expressions" in spec of package Sem).
19006 if Present
(Expression
(Discr
)) then
19007 Preanalyze_Spec_Expression
(Expression
(Discr
), Discr_Type
);
19011 if Nkind
(N
) = N_Formal_Type_Declaration
then
19013 ("discriminant defaults not allowed for formal type",
19014 Expression
(Discr
));
19016 -- Flag an error for a tagged type with defaulted discriminants,
19017 -- excluding limited tagged types when compiling for Ada 2012
19018 -- (see AI05-0214).
19020 elsif Is_Tagged_Type
(Current_Scope
)
19021 and then (not Is_Limited_Type
(Current_Scope
)
19022 or else Ada_Version
< Ada_2012
)
19023 and then Comes_From_Source
(N
)
19025 -- Note: see similar test in Check_Or_Process_Discriminants, to
19026 -- handle the (illegal) case of the completion of an untagged
19027 -- view with discriminants with defaults by a tagged full view.
19028 -- We skip the check if Discr does not come from source, to
19029 -- account for the case of an untagged derived type providing
19030 -- defaults for a renamed discriminant from a private untagged
19031 -- ancestor with a tagged full view (ACATS B460006).
19033 if Ada_Version
>= Ada_2012
then
19035 ("discriminants of nonlimited tagged type cannot have"
19037 Expression
(Discr
));
19040 ("discriminants of tagged type cannot have defaults",
19041 Expression
(Discr
));
19045 Default_Present
:= True;
19046 Append_Elmt
(Expression
(Discr
), Elist
);
19048 -- Tag the defining identifiers for the discriminants with
19049 -- their corresponding default expressions from the tree.
19051 Set_Discriminant_Default_Value
19052 (Defining_Identifier
(Discr
), Expression
(Discr
));
19055 -- In gnatc or gnatprove mode, make sure set Do_Range_Check flag
19056 -- gets set unless we can be sure that no range check is required.
19058 if (GNATprove_Mode
or not Expander_Active
)
19061 (Expression
(Discr
), Discr_Type
, Assume_Valid
=> True)
19063 Set_Do_Range_Check
(Expression
(Discr
));
19066 -- No default discriminant value given
19069 Default_Not_Present
:= True;
19072 -- Ada 2005 (AI-231): Create an Itype that is a duplicate of
19073 -- Discr_Type but with the null-exclusion attribute
19075 if Ada_Version
>= Ada_2005
then
19077 -- Ada 2005 (AI-231): Static checks
19079 if Can_Never_Be_Null
(Discr_Type
) then
19080 Null_Exclusion_Static_Checks
(Discr
);
19082 elsif Is_Access_Type
(Discr_Type
)
19083 and then Null_Exclusion_Present
(Discr
)
19085 -- No need to check itypes because in their case this check
19086 -- was done at their point of creation
19088 and then not Is_Itype
(Discr_Type
)
19090 if Can_Never_Be_Null
(Discr_Type
) then
19092 ("`NOT NULL` not allowed (& already excludes null)",
19097 Set_Etype
(Defining_Identifier
(Discr
),
19098 Create_Null_Excluding_Itype
19100 Related_Nod
=> Discr
));
19102 -- Check for improper null exclusion if the type is otherwise
19103 -- legal for a discriminant.
19105 elsif Null_Exclusion_Present
(Discr
)
19106 and then Is_Discrete_Type
(Discr_Type
)
19109 ("null exclusion can only apply to an access type", Discr
);
19112 -- Ada 2005 (AI-402): access discriminants of nonlimited types
19113 -- can't have defaults. Synchronized types, or types that are
19114 -- explicitly limited are fine, but special tests apply to derived
19115 -- types in generics: in a generic body we have to assume the
19116 -- worst, and therefore defaults are not allowed if the parent is
19117 -- a generic formal private type (see ACATS B370001).
19119 if Is_Access_Type
(Discr_Type
) and then Default_Present
then
19120 if Ekind
(Discr_Type
) /= E_Anonymous_Access_Type
19121 or else Is_Limited_Record
(Current_Scope
)
19122 or else Is_Concurrent_Type
(Current_Scope
)
19123 or else Is_Concurrent_Record_Type
(Current_Scope
)
19124 or else Ekind
(Current_Scope
) = E_Limited_Private_Type
19126 if not Is_Derived_Type
(Current_Scope
)
19127 or else not Is_Generic_Type
(Etype
(Current_Scope
))
19128 or else not In_Package_Body
(Scope
(Etype
(Current_Scope
)))
19129 or else Limited_Present
19130 (Type_Definition
(Parent
(Current_Scope
)))
19136 ("access discriminants of nonlimited types cannot "
19137 & "have defaults", Expression
(Discr
));
19140 elsif Present
(Expression
(Discr
)) then
19142 ("(Ada 2005) access discriminants of nonlimited types "
19143 & "cannot have defaults", Expression
(Discr
));
19148 -- A discriminant cannot be effectively volatile. This check is only
19149 -- relevant when SPARK_Mode is on as it is not standard Ada legality
19150 -- rule (SPARK RM 7.1.3(6)).
19153 and then Is_Effectively_Volatile
(Defining_Identifier
(Discr
))
19155 Error_Msg_N
("discriminant cannot be volatile", Discr
);
19161 -- An element list consisting of the default expressions of the
19162 -- discriminants is constructed in the above loop and used to set
19163 -- the Discriminant_Constraint attribute for the type. If an object
19164 -- is declared of this (record or task) type without any explicit
19165 -- discriminant constraint given, this element list will form the
19166 -- actual parameters for the corresponding initialization procedure
19169 Set_Discriminant_Constraint
(Current_Scope
, Elist
);
19170 Set_Stored_Constraint
(Current_Scope
, No_Elist
);
19172 -- Default expressions must be provided either for all or for none
19173 -- of the discriminants of a discriminant part. (RM 3.7.1)
19175 if Default_Present
and then Default_Not_Present
then
19177 ("incomplete specification of defaults for discriminants", N
);
19180 -- The use of the name of a discriminant is not allowed in default
19181 -- expressions of a discriminant part if the specification of the
19182 -- discriminant is itself given in the discriminant part. (RM 3.7.1)
19184 -- To detect this, the discriminant names are entered initially with an
19185 -- Ekind of E_Void (which is the default Ekind given by Enter_Name). Any
19186 -- attempt to use a void entity (for example in an expression that is
19187 -- type-checked) produces the error message: premature usage. Now after
19188 -- completing the semantic analysis of the discriminant part, we can set
19189 -- the Ekind of all the discriminants appropriately.
19191 Discr
:= First
(Discriminant_Specifications
(N
));
19192 Discr_Number
:= Uint_1
;
19193 while Present
(Discr
) loop
19194 Id
:= Defining_Identifier
(Discr
);
19195 Set_Ekind
(Id
, E_Discriminant
);
19196 Init_Component_Location
(Id
);
19198 Set_Discriminant_Number
(Id
, Discr_Number
);
19200 -- Make sure this is always set, even in illegal programs
19202 Set_Corresponding_Discriminant
(Id
, Empty
);
19204 -- Initialize the Original_Record_Component to the entity itself.
19205 -- Inherit_Components will propagate the right value to
19206 -- discriminants in derived record types.
19208 Set_Original_Record_Component
(Id
, Id
);
19210 -- Create the discriminal for the discriminant
19212 Build_Discriminal
(Id
);
19215 Discr_Number
:= Discr_Number
+ 1;
19218 Set_Has_Discriminants
(Current_Scope
);
19219 end Process_Discriminants
;
19221 -----------------------
19222 -- Process_Full_View --
19223 -----------------------
19225 procedure Process_Full_View
(N
: Node_Id
; Full_T
, Priv_T
: Entity_Id
) is
19226 procedure Collect_Implemented_Interfaces
19228 Ifaces
: Elist_Id
);
19229 -- Ada 2005: Gather all the interfaces that Typ directly or
19230 -- inherently implements. Duplicate entries are not added to
19231 -- the list Ifaces.
19233 ------------------------------------
19234 -- Collect_Implemented_Interfaces --
19235 ------------------------------------
19237 procedure Collect_Implemented_Interfaces
19242 Iface_Elmt
: Elmt_Id
;
19245 -- Abstract interfaces are only associated with tagged record types
19247 if not Is_Tagged_Type
(Typ
) or else not Is_Record_Type
(Typ
) then
19251 -- Recursively climb to the ancestors
19253 if Etype
(Typ
) /= Typ
19255 -- Protect the frontend against wrong cyclic declarations like:
19257 -- type B is new A with private;
19258 -- type C is new A with private;
19260 -- type B is new C with null record;
19261 -- type C is new B with null record;
19263 and then Etype
(Typ
) /= Priv_T
19264 and then Etype
(Typ
) /= Full_T
19266 -- Keep separate the management of private type declarations
19268 if Ekind
(Typ
) = E_Record_Type_With_Private
then
19270 -- Handle the following illegal usage:
19271 -- type Private_Type is tagged private;
19273 -- type Private_Type is new Type_Implementing_Iface;
19275 if Present
(Full_View
(Typ
))
19276 and then Etype
(Typ
) /= Full_View
(Typ
)
19278 if Is_Interface
(Etype
(Typ
)) then
19279 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
19282 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
19285 -- Non-private types
19288 if Is_Interface
(Etype
(Typ
)) then
19289 Append_Unique_Elmt
(Etype
(Typ
), Ifaces
);
19292 Collect_Implemented_Interfaces
(Etype
(Typ
), Ifaces
);
19296 -- Handle entities in the list of abstract interfaces
19298 if Present
(Interfaces
(Typ
)) then
19299 Iface_Elmt
:= First_Elmt
(Interfaces
(Typ
));
19300 while Present
(Iface_Elmt
) loop
19301 Iface
:= Node
(Iface_Elmt
);
19303 pragma Assert
(Is_Interface
(Iface
));
19305 if not Contain_Interface
(Iface
, Ifaces
) then
19306 Append_Elmt
(Iface
, Ifaces
);
19307 Collect_Implemented_Interfaces
(Iface
, Ifaces
);
19310 Next_Elmt
(Iface_Elmt
);
19313 end Collect_Implemented_Interfaces
;
19317 Full_Indic
: Node_Id
;
19318 Full_Parent
: Entity_Id
;
19319 Priv_Parent
: Entity_Id
;
19321 -- Start of processing for Process_Full_View
19324 -- First some sanity checks that must be done after semantic
19325 -- decoration of the full view and thus cannot be placed with other
19326 -- similar checks in Find_Type_Name
19328 if not Is_Limited_Type
(Priv_T
)
19329 and then (Is_Limited_Type
(Full_T
)
19330 or else Is_Limited_Composite
(Full_T
))
19332 if In_Instance
then
19336 ("completion of nonlimited type cannot be limited", Full_T
);
19337 Explain_Limited_Type
(Full_T
, Full_T
);
19340 elsif Is_Abstract_Type
(Full_T
)
19341 and then not Is_Abstract_Type
(Priv_T
)
19344 ("completion of nonabstract type cannot be abstract", Full_T
);
19346 elsif Is_Tagged_Type
(Priv_T
)
19347 and then Is_Limited_Type
(Priv_T
)
19348 and then not Is_Limited_Type
(Full_T
)
19350 -- If pragma CPP_Class was applied to the private declaration
19351 -- propagate the limitedness to the full-view
19353 if Is_CPP_Class
(Priv_T
) then
19354 Set_Is_Limited_Record
(Full_T
);
19356 -- GNAT allow its own definition of Limited_Controlled to disobey
19357 -- this rule in order in ease the implementation. This test is safe
19358 -- because Root_Controlled is defined in a child of System that
19359 -- normal programs are not supposed to use.
19361 elsif Is_RTE
(Etype
(Full_T
), RE_Root_Controlled
) then
19362 Set_Is_Limited_Composite
(Full_T
);
19365 ("completion of limited tagged type must be limited", Full_T
);
19368 elsif Is_Generic_Type
(Priv_T
) then
19369 Error_Msg_N
("generic type cannot have a completion", Full_T
);
19372 -- Check that ancestor interfaces of private and full views are
19373 -- consistent. We omit this check for synchronized types because
19374 -- they are performed on the corresponding record type when frozen.
19376 if Ada_Version
>= Ada_2005
19377 and then Is_Tagged_Type
(Priv_T
)
19378 and then Is_Tagged_Type
(Full_T
)
19379 and then not Is_Concurrent_Type
(Full_T
)
19383 Priv_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
19384 Full_T_Ifaces
: constant Elist_Id
:= New_Elmt_List
;
19387 Collect_Implemented_Interfaces
(Priv_T
, Priv_T_Ifaces
);
19388 Collect_Implemented_Interfaces
(Full_T
, Full_T_Ifaces
);
19390 -- Ada 2005 (AI-251): The partial view shall be a descendant of
19391 -- an interface type if and only if the full type is descendant
19392 -- of the interface type (AARM 7.3 (7.3/2)).
19394 Iface
:= Find_Hidden_Interface
(Priv_T_Ifaces
, Full_T_Ifaces
);
19396 if Present
(Iface
) then
19398 ("interface in partial view& not implemented by full type "
19399 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
19402 Iface
:= Find_Hidden_Interface
(Full_T_Ifaces
, Priv_T_Ifaces
);
19404 if Present
(Iface
) then
19406 ("interface & not implemented by partial view "
19407 & "(RM-2005 7.3 (7.3/2))", Full_T
, Iface
);
19412 if Is_Tagged_Type
(Priv_T
)
19413 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
19414 and then Is_Derived_Type
(Full_T
)
19416 Priv_Parent
:= Etype
(Priv_T
);
19418 -- The full view of a private extension may have been transformed
19419 -- into an unconstrained derived type declaration and a subtype
19420 -- declaration (see build_derived_record_type for details).
19422 if Nkind
(N
) = N_Subtype_Declaration
then
19423 Full_Indic
:= Subtype_Indication
(N
);
19424 Full_Parent
:= Etype
(Base_Type
(Full_T
));
19426 Full_Indic
:= Subtype_Indication
(Type_Definition
(N
));
19427 Full_Parent
:= Etype
(Full_T
);
19430 -- Check that the parent type of the full type is a descendant of
19431 -- the ancestor subtype given in the private extension. If either
19432 -- entity has an Etype equal to Any_Type then we had some previous
19433 -- error situation [7.3(8)].
19435 if Priv_Parent
= Any_Type
or else Full_Parent
= Any_Type
then
19438 -- Ada 2005 (AI-251): Interfaces in the full type can be given in
19439 -- any order. Therefore we don't have to check that its parent must
19440 -- be a descendant of the parent of the private type declaration.
19442 elsif Is_Interface
(Priv_Parent
)
19443 and then Is_Interface
(Full_Parent
)
19447 -- Ada 2005 (AI-251): If the parent of the private type declaration
19448 -- is an interface there is no need to check that it is an ancestor
19449 -- of the associated full type declaration. The required tests for
19450 -- this case are performed by Build_Derived_Record_Type.
19452 elsif not Is_Interface
(Base_Type
(Priv_Parent
))
19453 and then not Is_Ancestor
(Base_Type
(Priv_Parent
), Full_Parent
)
19456 ("parent of full type must descend from parent"
19457 & " of private extension", Full_Indic
);
19459 -- First check a formal restriction, and then proceed with checking
19460 -- Ada rules. Since the formal restriction is not a serious error, we
19461 -- don't prevent further error detection for this check, hence the
19465 -- In formal mode, when completing a private extension the type
19466 -- named in the private part must be exactly the same as that
19467 -- named in the visible part.
19469 if Priv_Parent
/= Full_Parent
then
19470 Error_Msg_Name_1
:= Chars
(Priv_Parent
);
19471 Check_SPARK_05_Restriction
("% expected", Full_Indic
);
19474 -- Check the rules of 7.3(10): if the private extension inherits
19475 -- known discriminants, then the full type must also inherit those
19476 -- discriminants from the same (ancestor) type, and the parent
19477 -- subtype of the full type must be constrained if and only if
19478 -- the ancestor subtype of the private extension is constrained.
19480 if No
(Discriminant_Specifications
(Parent
(Priv_T
)))
19481 and then not Has_Unknown_Discriminants
(Priv_T
)
19482 and then Has_Discriminants
(Base_Type
(Priv_Parent
))
19485 Priv_Indic
: constant Node_Id
:=
19486 Subtype_Indication
(Parent
(Priv_T
));
19488 Priv_Constr
: constant Boolean :=
19489 Is_Constrained
(Priv_Parent
)
19491 Nkind
(Priv_Indic
) = N_Subtype_Indication
19493 Is_Constrained
(Entity
(Priv_Indic
));
19495 Full_Constr
: constant Boolean :=
19496 Is_Constrained
(Full_Parent
)
19498 Nkind
(Full_Indic
) = N_Subtype_Indication
19500 Is_Constrained
(Entity
(Full_Indic
));
19502 Priv_Discr
: Entity_Id
;
19503 Full_Discr
: Entity_Id
;
19506 Priv_Discr
:= First_Discriminant
(Priv_Parent
);
19507 Full_Discr
:= First_Discriminant
(Full_Parent
);
19508 while Present
(Priv_Discr
) and then Present
(Full_Discr
) loop
19509 if Original_Record_Component
(Priv_Discr
) =
19510 Original_Record_Component
(Full_Discr
)
19512 Corresponding_Discriminant
(Priv_Discr
) =
19513 Corresponding_Discriminant
(Full_Discr
)
19520 Next_Discriminant
(Priv_Discr
);
19521 Next_Discriminant
(Full_Discr
);
19524 if Present
(Priv_Discr
) or else Present
(Full_Discr
) then
19526 ("full view must inherit discriminants of the parent"
19527 & " type used in the private extension", Full_Indic
);
19529 elsif Priv_Constr
and then not Full_Constr
then
19531 ("parent subtype of full type must be constrained",
19534 elsif Full_Constr
and then not Priv_Constr
then
19536 ("parent subtype of full type must be unconstrained",
19541 -- Check the rules of 7.3(12): if a partial view has neither
19542 -- known or unknown discriminants, then the full type
19543 -- declaration shall define a definite subtype.
19545 elsif not Has_Unknown_Discriminants
(Priv_T
)
19546 and then not Has_Discriminants
(Priv_T
)
19547 and then not Is_Constrained
(Full_T
)
19550 ("full view must define a constrained type if partial view"
19551 & " has no discriminants", Full_T
);
19554 -- ??????? Do we implement the following properly ?????
19555 -- If the ancestor subtype of a private extension has constrained
19556 -- discriminants, then the parent subtype of the full view shall
19557 -- impose a statically matching constraint on those discriminants
19562 -- For untagged types, verify that a type without discriminants is
19563 -- not completed with an unconstrained type. A separate error message
19564 -- is produced if the full type has defaulted discriminants.
19566 if not Is_Indefinite_Subtype
(Priv_T
)
19567 and then Is_Indefinite_Subtype
(Full_T
)
19569 Error_Msg_Sloc
:= Sloc
(Parent
(Priv_T
));
19571 ("full view of& not compatible with declaration#",
19574 if not Is_Tagged_Type
(Full_T
) then
19576 ("\one is constrained, the other unconstrained", Full_T
);
19581 -- AI-419: verify that the use of "limited" is consistent
19584 Orig_Decl
: constant Node_Id
:= Original_Node
(N
);
19587 if Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
19588 and then Nkind
(Orig_Decl
) = N_Full_Type_Declaration
19590 (Type_Definition
(Orig_Decl
)) = N_Derived_Type_Definition
19592 if not Limited_Present
(Parent
(Priv_T
))
19593 and then not Synchronized_Present
(Parent
(Priv_T
))
19594 and then Limited_Present
(Type_Definition
(Orig_Decl
))
19597 ("full view of non-limited extension cannot be limited", N
);
19599 -- Conversely, if the partial view carries the limited keyword,
19600 -- the full view must as well, even if it may be redundant.
19602 elsif Limited_Present
(Parent
(Priv_T
))
19603 and then not Limited_Present
(Type_Definition
(Orig_Decl
))
19606 ("full view of limited extension must be explicitly limited",
19612 -- Ada 2005 (AI-443): A synchronized private extension must be
19613 -- completed by a task or protected type.
19615 if Ada_Version
>= Ada_2005
19616 and then Nkind
(Parent
(Priv_T
)) = N_Private_Extension_Declaration
19617 and then Synchronized_Present
(Parent
(Priv_T
))
19618 and then not Is_Concurrent_Type
(Full_T
)
19620 Error_Msg_N
("full view of synchronized extension must " &
19621 "be synchronized type", N
);
19624 -- Ada 2005 AI-363: if the full view has discriminants with
19625 -- defaults, it is illegal to declare constrained access subtypes
19626 -- whose designated type is the current type. This allows objects
19627 -- of the type that are declared in the heap to be unconstrained.
19629 if not Has_Unknown_Discriminants
(Priv_T
)
19630 and then not Has_Discriminants
(Priv_T
)
19631 and then Has_Discriminants
(Full_T
)
19633 Present
(Discriminant_Default_Value
(First_Discriminant
(Full_T
)))
19635 Set_Has_Constrained_Partial_View
(Full_T
);
19636 Set_Has_Constrained_Partial_View
(Priv_T
);
19639 -- Create a full declaration for all its subtypes recorded in
19640 -- Private_Dependents and swap them similarly to the base type. These
19641 -- are subtypes that have been define before the full declaration of
19642 -- the private type. We also swap the entry in Private_Dependents list
19643 -- so we can properly restore the private view on exit from the scope.
19646 Priv_Elmt
: Elmt_Id
;
19647 Priv_Scop
: Entity_Id
;
19652 Priv_Elmt
:= First_Elmt
(Private_Dependents
(Priv_T
));
19653 while Present
(Priv_Elmt
) loop
19654 Priv
:= Node
(Priv_Elmt
);
19655 Priv_Scop
:= Scope
(Priv
);
19657 if Ekind_In
(Priv
, E_Private_Subtype
,
19658 E_Limited_Private_Subtype
,
19659 E_Record_Subtype_With_Private
)
19661 Full
:= Make_Defining_Identifier
(Sloc
(Priv
), Chars
(Priv
));
19662 Set_Is_Itype
(Full
);
19663 Set_Parent
(Full
, Parent
(Priv
));
19664 Set_Associated_Node_For_Itype
(Full
, N
);
19666 -- Now we need to complete the private subtype, but since the
19667 -- base type has already been swapped, we must also swap the
19668 -- subtypes (and thus, reverse the arguments in the call to
19669 -- Complete_Private_Subtype). Also note that we may need to
19670 -- re-establish the scope of the private subtype.
19672 Copy_And_Swap
(Priv
, Full
);
19674 if not In_Open_Scopes
(Priv_Scop
) then
19675 Push_Scope
(Priv_Scop
);
19678 -- Reset Priv_Scop to Empty to indicate no scope was pushed
19680 Priv_Scop
:= Empty
;
19683 Complete_Private_Subtype
(Full
, Priv
, Full_T
, N
);
19685 if Present
(Priv_Scop
) then
19689 Replace_Elmt
(Priv_Elmt
, Full
);
19692 Next_Elmt
(Priv_Elmt
);
19696 -- If the private view was tagged, copy the new primitive operations
19697 -- from the private view to the full view.
19699 if Is_Tagged_Type
(Full_T
) then
19701 Disp_Typ
: Entity_Id
;
19702 Full_List
: Elist_Id
;
19704 Prim_Elmt
: Elmt_Id
;
19705 Priv_List
: Elist_Id
;
19709 L
: Elist_Id
) return Boolean;
19710 -- Determine whether list L contains element E
19718 L
: Elist_Id
) return Boolean
19720 List_Elmt
: Elmt_Id
;
19723 List_Elmt
:= First_Elmt
(L
);
19724 while Present
(List_Elmt
) loop
19725 if Node
(List_Elmt
) = E
then
19729 Next_Elmt
(List_Elmt
);
19735 -- Start of processing
19738 if Is_Tagged_Type
(Priv_T
) then
19739 Priv_List
:= Primitive_Operations
(Priv_T
);
19740 Prim_Elmt
:= First_Elmt
(Priv_List
);
19742 -- In the case of a concurrent type completing a private tagged
19743 -- type, primitives may have been declared in between the two
19744 -- views. These subprograms need to be wrapped the same way
19745 -- entries and protected procedures are handled because they
19746 -- cannot be directly shared by the two views.
19748 if Is_Concurrent_Type
(Full_T
) then
19750 Conc_Typ
: constant Entity_Id
:=
19751 Corresponding_Record_Type
(Full_T
);
19752 Curr_Nod
: Node_Id
:= Parent
(Conc_Typ
);
19753 Wrap_Spec
: Node_Id
;
19756 while Present
(Prim_Elmt
) loop
19757 Prim
:= Node
(Prim_Elmt
);
19759 if Comes_From_Source
(Prim
)
19760 and then not Is_Abstract_Subprogram
(Prim
)
19763 Make_Subprogram_Declaration
(Sloc
(Prim
),
19767 Obj_Typ
=> Conc_Typ
,
19769 Parameter_Specifications
(
19772 Insert_After
(Curr_Nod
, Wrap_Spec
);
19773 Curr_Nod
:= Wrap_Spec
;
19775 Analyze
(Wrap_Spec
);
19778 Next_Elmt
(Prim_Elmt
);
19784 -- For non-concurrent types, transfer explicit primitives, but
19785 -- omit those inherited from the parent of the private view
19786 -- since they will be re-inherited later on.
19789 Full_List
:= Primitive_Operations
(Full_T
);
19791 while Present
(Prim_Elmt
) loop
19792 Prim
:= Node
(Prim_Elmt
);
19794 if Comes_From_Source
(Prim
)
19795 and then not Contains
(Prim
, Full_List
)
19797 Append_Elmt
(Prim
, Full_List
);
19800 Next_Elmt
(Prim_Elmt
);
19804 -- Untagged private view
19807 Full_List
:= Primitive_Operations
(Full_T
);
19809 -- In this case the partial view is untagged, so here we locate
19810 -- all of the earlier primitives that need to be treated as
19811 -- dispatching (those that appear between the two views). Note
19812 -- that these additional operations must all be new operations
19813 -- (any earlier operations that override inherited operations
19814 -- of the full view will already have been inserted in the
19815 -- primitives list, marked by Check_Operation_From_Private_View
19816 -- as dispatching. Note that implicit "/=" operators are
19817 -- excluded from being added to the primitives list since they
19818 -- shouldn't be treated as dispatching (tagged "/=" is handled
19821 Prim
:= Next_Entity
(Full_T
);
19822 while Present
(Prim
) and then Prim
/= Priv_T
loop
19823 if Ekind_In
(Prim
, E_Procedure
, E_Function
) then
19824 Disp_Typ
:= Find_Dispatching_Type
(Prim
);
19826 if Disp_Typ
= Full_T
19827 and then (Chars
(Prim
) /= Name_Op_Ne
19828 or else Comes_From_Source
(Prim
))
19830 Check_Controlling_Formals
(Full_T
, Prim
);
19832 if not Is_Dispatching_Operation
(Prim
) then
19833 Append_Elmt
(Prim
, Full_List
);
19834 Set_Is_Dispatching_Operation
(Prim
, True);
19835 Set_DT_Position_Value
(Prim
, No_Uint
);
19838 elsif Is_Dispatching_Operation
(Prim
)
19839 and then Disp_Typ
/= Full_T
19842 -- Verify that it is not otherwise controlled by a
19843 -- formal or a return value of type T.
19845 Check_Controlling_Formals
(Disp_Typ
, Prim
);
19849 Next_Entity
(Prim
);
19853 -- For the tagged case, the two views can share the same primitive
19854 -- operations list and the same class-wide type. Update attributes
19855 -- of the class-wide type which depend on the full declaration.
19857 if Is_Tagged_Type
(Priv_T
) then
19858 Set_Direct_Primitive_Operations
(Priv_T
, Full_List
);
19859 Set_Class_Wide_Type
19860 (Base_Type
(Full_T
), Class_Wide_Type
(Priv_T
));
19862 Set_Has_Task
(Class_Wide_Type
(Priv_T
), Has_Task
(Full_T
));
19864 (Class_Wide_Type
(Priv_T
), Has_Protected
(Full_T
));
19869 -- Ada 2005 AI 161: Check preelaborable initialization consistency
19871 if Known_To_Have_Preelab_Init
(Priv_T
) then
19873 -- Case where there is a pragma Preelaborable_Initialization. We
19874 -- always allow this in predefined units, which is cheating a bit,
19875 -- but it means we don't have to struggle to meet the requirements in
19876 -- the RM for having Preelaborable Initialization. Otherwise we
19877 -- require that the type meets the RM rules. But we can't check that
19878 -- yet, because of the rule about overriding Initialize, so we simply
19879 -- set a flag that will be checked at freeze time.
19881 if not In_Predefined_Unit
(Full_T
) then
19882 Set_Must_Have_Preelab_Init
(Full_T
);
19886 -- If pragma CPP_Class was applied to the private type declaration,
19887 -- propagate it now to the full type declaration.
19889 if Is_CPP_Class
(Priv_T
) then
19890 Set_Is_CPP_Class
(Full_T
);
19891 Set_Convention
(Full_T
, Convention_CPP
);
19893 -- Check that components of imported CPP types do not have default
19896 Check_CPP_Type_Has_No_Defaults
(Full_T
);
19899 -- If the private view has user specified stream attributes, then so has
19902 -- Why the test, how could these flags be already set in Full_T ???
19904 if Has_Specified_Stream_Read
(Priv_T
) then
19905 Set_Has_Specified_Stream_Read
(Full_T
);
19908 if Has_Specified_Stream_Write
(Priv_T
) then
19909 Set_Has_Specified_Stream_Write
(Full_T
);
19912 if Has_Specified_Stream_Input
(Priv_T
) then
19913 Set_Has_Specified_Stream_Input
(Full_T
);
19916 if Has_Specified_Stream_Output
(Priv_T
) then
19917 Set_Has_Specified_Stream_Output
(Full_T
);
19920 -- Propagate the attributes related to pragma Default_Initial_Condition
19921 -- from the private to the full view. Note that both flags are mutually
19924 if Has_Default_Init_Cond
(Priv_T
)
19925 or else Has_Inherited_Default_Init_Cond
(Priv_T
)
19927 Propagate_Default_Init_Cond_Attributes
19928 (From_Typ
=> Priv_T
,
19930 Private_To_Full_View
=> True);
19932 -- In the case where the full view is derived from another private type,
19933 -- the attributes related to pragma Default_Initial_Condition must be
19934 -- propagated from the full to the private view to maintain consistency
19938 -- type Parent_Typ is private
19939 -- with Default_Initial_Condition ...;
19941 -- type Parent_Typ is ...;
19944 -- with Pack; use Pack;
19945 -- package Pack_2 is
19946 -- type Deriv_Typ is private; -- must inherit
19948 -- type Deriv_Typ is new Parent_Typ; -- must inherit
19951 elsif Has_Default_Init_Cond
(Full_T
)
19952 or else Has_Inherited_Default_Init_Cond
(Full_T
)
19954 Propagate_Default_Init_Cond_Attributes
19955 (From_Typ
=> Full_T
,
19957 Private_To_Full_View
=> True);
19960 -- Propagate the attributes related to pragma Ghost from the private to
19963 if Is_Ghost_Entity
(Priv_T
) then
19964 Set_Is_Ghost_Entity
(Full_T
);
19966 -- The Ghost policy in effect at the point of declaration and at the
19967 -- point of completion must match (SPARK RM 6.9(15)).
19969 Check_Ghost_Completion
(Priv_T
, Full_T
);
19971 -- In the case where the private view of a tagged type lacks a parent
19972 -- type and is subject to pragma Ghost, ensure that the parent type
19973 -- specified by the full view is also Ghost (SPARK RM 6.9(9)).
19975 if Is_Derived_Type
(Full_T
) then
19976 Check_Ghost_Derivation
(Full_T
);
19980 -- Propagate invariants to full type
19982 if Has_Invariants
(Priv_T
) then
19983 Set_Has_Invariants
(Full_T
);
19984 Set_Invariant_Procedure
(Full_T
, Invariant_Procedure
(Priv_T
));
19987 if Has_Inheritable_Invariants
(Priv_T
) then
19988 Set_Has_Inheritable_Invariants
(Full_T
);
19991 -- Check hidden inheritance of class-wide type invariants
19993 if Ada_Version
>= Ada_2012
19994 and then not Has_Inheritable_Invariants
(Full_T
)
19995 and then In_Private_Part
(Current_Scope
)
19996 and then Has_Interfaces
(Full_T
)
20003 Collect_Interfaces
(Full_T
, Ifaces
, Exclude_Parents
=> True);
20005 AI
:= First_Elmt
(Ifaces
);
20006 while Present
(AI
) loop
20007 if Has_Inheritable_Invariants
(Node
(AI
)) then
20009 ("hidden inheritance of class-wide type invariants " &
20019 -- Propagate predicates to full type, and predicate function if already
20020 -- defined. It is not clear that this can actually happen? the partial
20021 -- view cannot be frozen yet, and the predicate function has not been
20022 -- built. Still it is a cheap check and seems safer to make it.
20024 if Has_Predicates
(Priv_T
) then
20025 if Present
(Predicate_Function
(Priv_T
)) then
20026 Set_Predicate_Function
(Full_T
, Predicate_Function
(Priv_T
));
20029 Set_Has_Predicates
(Full_T
);
20031 end Process_Full_View
;
20033 -----------------------------------
20034 -- Process_Incomplete_Dependents --
20035 -----------------------------------
20037 procedure Process_Incomplete_Dependents
20039 Full_T
: Entity_Id
;
20042 Inc_Elmt
: Elmt_Id
;
20043 Priv_Dep
: Entity_Id
;
20044 New_Subt
: Entity_Id
;
20046 Disc_Constraint
: Elist_Id
;
20049 if No
(Private_Dependents
(Inc_T
)) then
20053 -- Itypes that may be generated by the completion of an incomplete
20054 -- subtype are not used by the back-end and not attached to the tree.
20055 -- They are created only for constraint-checking purposes.
20057 Inc_Elmt
:= First_Elmt
(Private_Dependents
(Inc_T
));
20058 while Present
(Inc_Elmt
) loop
20059 Priv_Dep
:= Node
(Inc_Elmt
);
20061 if Ekind
(Priv_Dep
) = E_Subprogram_Type
then
20063 -- An Access_To_Subprogram type may have a return type or a
20064 -- parameter type that is incomplete. Replace with the full view.
20066 if Etype
(Priv_Dep
) = Inc_T
then
20067 Set_Etype
(Priv_Dep
, Full_T
);
20071 Formal
: Entity_Id
;
20074 Formal
:= First_Formal
(Priv_Dep
);
20075 while Present
(Formal
) loop
20076 if Etype
(Formal
) = Inc_T
then
20077 Set_Etype
(Formal
, Full_T
);
20080 Next_Formal
(Formal
);
20084 elsif Is_Overloadable
(Priv_Dep
) then
20086 -- If a subprogram in the incomplete dependents list is primitive
20087 -- for a tagged full type then mark it as a dispatching operation,
20088 -- check whether it overrides an inherited subprogram, and check
20089 -- restrictions on its controlling formals. Note that a protected
20090 -- operation is never dispatching: only its wrapper operation
20091 -- (which has convention Ada) is.
20093 if Is_Tagged_Type
(Full_T
)
20094 and then Is_Primitive
(Priv_Dep
)
20095 and then Convention
(Priv_Dep
) /= Convention_Protected
20097 Check_Operation_From_Incomplete_Type
(Priv_Dep
, Inc_T
);
20098 Set_Is_Dispatching_Operation
(Priv_Dep
);
20099 Check_Controlling_Formals
(Full_T
, Priv_Dep
);
20102 elsif Ekind
(Priv_Dep
) = E_Subprogram_Body
then
20104 -- Can happen during processing of a body before the completion
20105 -- of a TA type. Ignore, because spec is also on dependent list.
20109 -- Ada 2005 (AI-412): Transform a regular incomplete subtype into a
20110 -- corresponding subtype of the full view.
20112 elsif Ekind
(Priv_Dep
) = E_Incomplete_Subtype
then
20113 Set_Subtype_Indication
20114 (Parent
(Priv_Dep
), New_Occurrence_Of
(Full_T
, Sloc
(Priv_Dep
)));
20115 Set_Etype
(Priv_Dep
, Full_T
);
20116 Set_Ekind
(Priv_Dep
, Subtype_Kind
(Ekind
(Full_T
)));
20117 Set_Analyzed
(Parent
(Priv_Dep
), False);
20119 -- Reanalyze the declaration, suppressing the call to
20120 -- Enter_Name to avoid duplicate names.
20122 Analyze_Subtype_Declaration
20123 (N
=> Parent
(Priv_Dep
),
20126 -- Dependent is a subtype
20129 -- We build a new subtype indication using the full view of the
20130 -- incomplete parent. The discriminant constraints have been
20131 -- elaborated already at the point of the subtype declaration.
20133 New_Subt
:= Create_Itype
(E_Void
, N
);
20135 if Has_Discriminants
(Full_T
) then
20136 Disc_Constraint
:= Discriminant_Constraint
(Priv_Dep
);
20138 Disc_Constraint
:= No_Elist
;
20141 Build_Discriminated_Subtype
(Full_T
, New_Subt
, Disc_Constraint
, N
);
20142 Set_Full_View
(Priv_Dep
, New_Subt
);
20145 Next_Elmt
(Inc_Elmt
);
20147 end Process_Incomplete_Dependents
;
20149 --------------------------------
20150 -- Process_Range_Expr_In_Decl --
20151 --------------------------------
20153 procedure Process_Range_Expr_In_Decl
20156 Subtyp
: Entity_Id
:= Empty
;
20157 Check_List
: List_Id
:= Empty_List
;
20158 R_Check_Off
: Boolean := False;
20159 In_Iter_Schm
: Boolean := False)
20162 R_Checks
: Check_Result
;
20163 Insert_Node
: Node_Id
;
20164 Def_Id
: Entity_Id
;
20167 Analyze_And_Resolve
(R
, Base_Type
(T
));
20169 if Nkind
(R
) = N_Range
then
20171 -- In SPARK, all ranges should be static, with the exception of the
20172 -- discrete type definition of a loop parameter specification.
20174 if not In_Iter_Schm
20175 and then not Is_OK_Static_Range
(R
)
20177 Check_SPARK_05_Restriction
("range should be static", R
);
20180 Lo
:= Low_Bound
(R
);
20181 Hi
:= High_Bound
(R
);
20183 -- Validity checks on the range of a quantified expression are
20184 -- delayed until the construct is transformed into a loop.
20186 if Nkind
(Parent
(R
)) = N_Loop_Parameter_Specification
20187 and then Nkind
(Parent
(Parent
(R
))) = N_Quantified_Expression
20191 -- We need to ensure validity of the bounds here, because if we
20192 -- go ahead and do the expansion, then the expanded code will get
20193 -- analyzed with range checks suppressed and we miss the check.
20195 -- WARNING: The capture of the range bounds with xxx_FIRST/_LAST and
20196 -- the temporaries generated by routine Remove_Side_Effects by means
20197 -- of validity checks must use the same names. When a range appears
20198 -- in the parent of a generic, the range is processed with checks
20199 -- disabled as part of the generic context and with checks enabled
20200 -- for code generation purposes. This leads to link issues as the
20201 -- generic contains references to xxx_FIRST/_LAST, but the inlined
20202 -- template sees the temporaries generated by Remove_Side_Effects.
20205 Validity_Check_Range
(R
, Subtyp
);
20208 -- If there were errors in the declaration, try and patch up some
20209 -- common mistakes in the bounds. The cases handled are literals
20210 -- which are Integer where the expected type is Real and vice versa.
20211 -- These corrections allow the compilation process to proceed further
20212 -- along since some basic assumptions of the format of the bounds
20215 if Etype
(R
) = Any_Type
then
20216 if Nkind
(Lo
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
20218 Make_Real_Literal
(Sloc
(Lo
), UR_From_Uint
(Intval
(Lo
))));
20220 elsif Nkind
(Hi
) = N_Integer_Literal
and then Is_Real_Type
(T
) then
20222 Make_Real_Literal
(Sloc
(Hi
), UR_From_Uint
(Intval
(Hi
))));
20224 elsif Nkind
(Lo
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
20226 Make_Integer_Literal
(Sloc
(Lo
), UR_To_Uint
(Realval
(Lo
))));
20228 elsif Nkind
(Hi
) = N_Real_Literal
and then Is_Integer_Type
(T
) then
20230 Make_Integer_Literal
(Sloc
(Hi
), UR_To_Uint
(Realval
(Hi
))));
20237 -- If the bounds of the range have been mistakenly given as string
20238 -- literals (perhaps in place of character literals), then an error
20239 -- has already been reported, but we rewrite the string literal as a
20240 -- bound of the range's type to avoid blowups in later processing
20241 -- that looks at static values.
20243 if Nkind
(Lo
) = N_String_Literal
then
20245 Make_Attribute_Reference
(Sloc
(Lo
),
20246 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Lo
)),
20247 Attribute_Name
=> Name_First
));
20248 Analyze_And_Resolve
(Lo
);
20251 if Nkind
(Hi
) = N_String_Literal
then
20253 Make_Attribute_Reference
(Sloc
(Hi
),
20254 Prefix
=> New_Occurrence_Of
(T
, Sloc
(Hi
)),
20255 Attribute_Name
=> Name_First
));
20256 Analyze_And_Resolve
(Hi
);
20259 -- If bounds aren't scalar at this point then exit, avoiding
20260 -- problems with further processing of the range in this procedure.
20262 if not Is_Scalar_Type
(Etype
(Lo
)) then
20266 -- Resolve (actually Sem_Eval) has checked that the bounds are in
20267 -- then range of the base type. Here we check whether the bounds
20268 -- are in the range of the subtype itself. Note that if the bounds
20269 -- represent the null range the Constraint_Error exception should
20272 -- ??? The following code should be cleaned up as follows
20274 -- 1. The Is_Null_Range (Lo, Hi) test should disappear since it
20275 -- is done in the call to Range_Check (R, T); below
20277 -- 2. The use of R_Check_Off should be investigated and possibly
20278 -- removed, this would clean up things a bit.
20280 if Is_Null_Range
(Lo
, Hi
) then
20284 -- Capture values of bounds and generate temporaries for them
20285 -- if needed, before applying checks, since checks may cause
20286 -- duplication of the expression without forcing evaluation.
20288 -- The forced evaluation removes side effects from expressions,
20289 -- which should occur also in GNATprove mode. Otherwise, we end up
20290 -- with unexpected insertions of actions at places where this is
20291 -- not supposed to occur, e.g. on default parameters of a call.
20293 if Expander_Active
or GNATprove_Mode
then
20295 -- Call Force_Evaluation to create declarations as needed to
20296 -- deal with side effects, and also create typ_FIRST/LAST
20297 -- entities for bounds if we have a subtype name.
20299 -- Note: we do this transformation even if expansion is not
20300 -- active if we are in GNATprove_Mode since the transformation
20301 -- is in general required to ensure that the resulting tree has
20302 -- proper Ada semantics.
20305 (Lo
, Related_Id
=> Subtyp
, Is_Low_Bound
=> True);
20307 (Hi
, Related_Id
=> Subtyp
, Is_High_Bound
=> True);
20310 -- We use a flag here instead of suppressing checks on the type
20311 -- because the type we check against isn't necessarily the place
20312 -- where we put the check.
20314 if not R_Check_Off
then
20315 R_Checks
:= Get_Range_Checks
(R
, T
);
20317 -- Look up tree to find an appropriate insertion point. We
20318 -- can't just use insert_actions because later processing
20319 -- depends on the insertion node. Prior to Ada 2012 the
20320 -- insertion point could only be a declaration or a loop, but
20321 -- quantified expressions can appear within any context in an
20322 -- expression, and the insertion point can be any statement,
20323 -- pragma, or declaration.
20325 Insert_Node
:= Parent
(R
);
20326 while Present
(Insert_Node
) loop
20328 Nkind
(Insert_Node
) in N_Declaration
20331 (Insert_Node
, N_Component_Declaration
,
20332 N_Loop_Parameter_Specification
,
20333 N_Function_Specification
,
20334 N_Procedure_Specification
);
20336 exit when Nkind
(Insert_Node
) in N_Later_Decl_Item
20337 or else Nkind
(Insert_Node
) in
20338 N_Statement_Other_Than_Procedure_Call
20339 or else Nkind_In
(Insert_Node
, N_Procedure_Call_Statement
,
20342 Insert_Node
:= Parent
(Insert_Node
);
20345 -- Why would Type_Decl not be present??? Without this test,
20346 -- short regression tests fail.
20348 if Present
(Insert_Node
) then
20350 -- Case of loop statement. Verify that the range is part
20351 -- of the subtype indication of the iteration scheme.
20353 if Nkind
(Insert_Node
) = N_Loop_Statement
then
20358 Indic
:= Parent
(R
);
20359 while Present
(Indic
)
20360 and then Nkind
(Indic
) /= N_Subtype_Indication
20362 Indic
:= Parent
(Indic
);
20365 if Present
(Indic
) then
20366 Def_Id
:= Etype
(Subtype_Mark
(Indic
));
20368 Insert_Range_Checks
20372 Sloc
(Insert_Node
),
20374 Do_Before
=> True);
20378 -- Insertion before a declaration. If the declaration
20379 -- includes discriminants, the list of applicable checks
20380 -- is given by the caller.
20382 elsif Nkind
(Insert_Node
) in N_Declaration
then
20383 Def_Id
:= Defining_Identifier
(Insert_Node
);
20385 if (Ekind
(Def_Id
) = E_Record_Type
20386 and then Depends_On_Discriminant
(R
))
20388 (Ekind
(Def_Id
) = E_Protected_Type
20389 and then Has_Discriminants
(Def_Id
))
20391 Append_Range_Checks
20393 Check_List
, Def_Id
, Sloc
(Insert_Node
), R
);
20396 Insert_Range_Checks
20398 Insert_Node
, Def_Id
, Sloc
(Insert_Node
), R
);
20402 -- Insertion before a statement. Range appears in the
20403 -- context of a quantified expression. Insertion will
20404 -- take place when expression is expanded.
20413 -- Case of other than an explicit N_Range node
20415 -- The forced evaluation removes side effects from expressions, which
20416 -- should occur also in GNATprove mode. Otherwise, we end up with
20417 -- unexpected insertions of actions at places where this is not
20418 -- supposed to occur, e.g. on default parameters of a call.
20420 elsif Expander_Active
or GNATprove_Mode
then
20421 Get_Index_Bounds
(R
, Lo
, Hi
);
20422 Force_Evaluation
(Lo
);
20423 Force_Evaluation
(Hi
);
20425 end Process_Range_Expr_In_Decl
;
20427 --------------------------------------
20428 -- Process_Real_Range_Specification --
20429 --------------------------------------
20431 procedure Process_Real_Range_Specification
(Def
: Node_Id
) is
20432 Spec
: constant Node_Id
:= Real_Range_Specification
(Def
);
20435 Err
: Boolean := False;
20437 procedure Analyze_Bound
(N
: Node_Id
);
20438 -- Analyze and check one bound
20440 -------------------
20441 -- Analyze_Bound --
20442 -------------------
20444 procedure Analyze_Bound
(N
: Node_Id
) is
20446 Analyze_And_Resolve
(N
, Any_Real
);
20448 if not Is_OK_Static_Expression
(N
) then
20449 Flag_Non_Static_Expr
20450 ("bound in real type definition is not static!", N
);
20455 -- Start of processing for Process_Real_Range_Specification
20458 if Present
(Spec
) then
20459 Lo
:= Low_Bound
(Spec
);
20460 Hi
:= High_Bound
(Spec
);
20461 Analyze_Bound
(Lo
);
20462 Analyze_Bound
(Hi
);
20464 -- If error, clear away junk range specification
20467 Set_Real_Range_Specification
(Def
, Empty
);
20470 end Process_Real_Range_Specification
;
20472 ---------------------
20473 -- Process_Subtype --
20474 ---------------------
20476 function Process_Subtype
20478 Related_Nod
: Node_Id
;
20479 Related_Id
: Entity_Id
:= Empty
;
20480 Suffix
: Character := ' ') return Entity_Id
20483 Def_Id
: Entity_Id
;
20484 Error_Node
: Node_Id
;
20485 Full_View_Id
: Entity_Id
;
20486 Subtype_Mark_Id
: Entity_Id
;
20488 May_Have_Null_Exclusion
: Boolean;
20490 procedure Check_Incomplete
(T
: Entity_Id
);
20491 -- Called to verify that an incomplete type is not used prematurely
20493 ----------------------
20494 -- Check_Incomplete --
20495 ----------------------
20497 procedure Check_Incomplete
(T
: Entity_Id
) is
20499 -- Ada 2005 (AI-412): Incomplete subtypes are legal
20501 if Ekind
(Root_Type
(Entity
(T
))) = E_Incomplete_Type
20503 not (Ada_Version
>= Ada_2005
20505 (Nkind
(Parent
(T
)) = N_Subtype_Declaration
20506 or else (Nkind
(Parent
(T
)) = N_Subtype_Indication
20507 and then Nkind
(Parent
(Parent
(T
))) =
20508 N_Subtype_Declaration
)))
20510 Error_Msg_N
("invalid use of type before its full declaration", T
);
20512 end Check_Incomplete
;
20514 -- Start of processing for Process_Subtype
20517 -- Case of no constraints present
20519 if Nkind
(S
) /= N_Subtype_Indication
then
20521 Check_Incomplete
(S
);
20524 -- Ada 2005 (AI-231): Static check
20526 if Ada_Version
>= Ada_2005
20527 and then Present
(P
)
20528 and then Null_Exclusion_Present
(P
)
20529 and then Nkind
(P
) /= N_Access_To_Object_Definition
20530 and then not Is_Access_Type
(Entity
(S
))
20532 Error_Msg_N
("`NOT NULL` only allowed for an access type", S
);
20535 -- The following is ugly, can't we have a range or even a flag???
20537 May_Have_Null_Exclusion
:=
20538 Nkind_In
(P
, N_Access_Definition
,
20539 N_Access_Function_Definition
,
20540 N_Access_Procedure_Definition
,
20541 N_Access_To_Object_Definition
,
20543 N_Component_Definition
)
20545 Nkind_In
(P
, N_Derived_Type_Definition
,
20546 N_Discriminant_Specification
,
20547 N_Formal_Object_Declaration
,
20548 N_Object_Declaration
,
20549 N_Object_Renaming_Declaration
,
20550 N_Parameter_Specification
,
20551 N_Subtype_Declaration
);
20553 -- Create an Itype that is a duplicate of Entity (S) but with the
20554 -- null-exclusion attribute.
20556 if May_Have_Null_Exclusion
20557 and then Is_Access_Type
(Entity
(S
))
20558 and then Null_Exclusion_Present
(P
)
20560 -- No need to check the case of an access to object definition.
20561 -- It is correct to define double not-null pointers.
20564 -- type Not_Null_Int_Ptr is not null access Integer;
20565 -- type Acc is not null access Not_Null_Int_Ptr;
20567 and then Nkind
(P
) /= N_Access_To_Object_Definition
20569 if Can_Never_Be_Null
(Entity
(S
)) then
20570 case Nkind
(Related_Nod
) is
20571 when N_Full_Type_Declaration
=>
20572 if Nkind
(Type_Definition
(Related_Nod
))
20573 in N_Array_Type_Definition
20577 (Component_Definition
20578 (Type_Definition
(Related_Nod
)));
20581 Subtype_Indication
(Type_Definition
(Related_Nod
));
20584 when N_Subtype_Declaration
=>
20585 Error_Node
:= Subtype_Indication
(Related_Nod
);
20587 when N_Object_Declaration
=>
20588 Error_Node
:= Object_Definition
(Related_Nod
);
20590 when N_Component_Declaration
=>
20592 Subtype_Indication
(Component_Definition
(Related_Nod
));
20594 when N_Allocator
=>
20595 Error_Node
:= Expression
(Related_Nod
);
20598 pragma Assert
(False);
20599 Error_Node
:= Related_Nod
;
20603 ("`NOT NULL` not allowed (& already excludes null)",
20609 Create_Null_Excluding_Itype
20611 Related_Nod
=> P
));
20612 Set_Entity
(S
, Etype
(S
));
20617 -- Case of constraint present, so that we have an N_Subtype_Indication
20618 -- node (this node is created only if constraints are present).
20621 Find_Type
(Subtype_Mark
(S
));
20623 if Nkind
(Parent
(S
)) /= N_Access_To_Object_Definition
20625 (Nkind
(Parent
(S
)) = N_Subtype_Declaration
20626 and then Is_Itype
(Defining_Identifier
(Parent
(S
))))
20628 Check_Incomplete
(Subtype_Mark
(S
));
20632 Subtype_Mark_Id
:= Entity
(Subtype_Mark
(S
));
20634 -- Explicit subtype declaration case
20636 if Nkind
(P
) = N_Subtype_Declaration
then
20637 Def_Id
:= Defining_Identifier
(P
);
20639 -- Explicit derived type definition case
20641 elsif Nkind
(P
) = N_Derived_Type_Definition
then
20642 Def_Id
:= Defining_Identifier
(Parent
(P
));
20644 -- Implicit case, the Def_Id must be created as an implicit type.
20645 -- The one exception arises in the case of concurrent types, array
20646 -- and access types, where other subsidiary implicit types may be
20647 -- created and must appear before the main implicit type. In these
20648 -- cases we leave Def_Id set to Empty as a signal that Create_Itype
20649 -- has not yet been called to create Def_Id.
20652 if Is_Array_Type
(Subtype_Mark_Id
)
20653 or else Is_Concurrent_Type
(Subtype_Mark_Id
)
20654 or else Is_Access_Type
(Subtype_Mark_Id
)
20658 -- For the other cases, we create a new unattached Itype,
20659 -- and set the indication to ensure it gets attached later.
20663 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
20667 -- If the kind of constraint is invalid for this kind of type,
20668 -- then give an error, and then pretend no constraint was given.
20670 if not Is_Valid_Constraint_Kind
20671 (Ekind
(Subtype_Mark_Id
), Nkind
(Constraint
(S
)))
20674 ("incorrect constraint for this kind of type", Constraint
(S
));
20676 Rewrite
(S
, New_Copy_Tree
(Subtype_Mark
(S
)));
20678 -- Set Ekind of orphan itype, to prevent cascaded errors
20680 if Present
(Def_Id
) then
20681 Set_Ekind
(Def_Id
, Ekind
(Any_Type
));
20684 -- Make recursive call, having got rid of the bogus constraint
20686 return Process_Subtype
(S
, Related_Nod
, Related_Id
, Suffix
);
20689 -- Remaining processing depends on type. Select on Base_Type kind to
20690 -- ensure getting to the concrete type kind in the case of a private
20691 -- subtype (needed when only doing semantic analysis).
20693 case Ekind
(Base_Type
(Subtype_Mark_Id
)) is
20694 when Access_Kind
=>
20696 -- If this is a constraint on a class-wide type, discard it.
20697 -- There is currently no way to express a partial discriminant
20698 -- constraint on a type with unknown discriminants. This is
20699 -- a pathology that the ACATS wisely decides not to test.
20701 if Is_Class_Wide_Type
(Designated_Type
(Subtype_Mark_Id
)) then
20702 if Comes_From_Source
(S
) then
20704 ("constraint on class-wide type ignored??",
20708 if Nkind
(P
) = N_Subtype_Declaration
then
20709 Set_Subtype_Indication
(P
,
20710 New_Occurrence_Of
(Subtype_Mark_Id
, Sloc
(S
)));
20713 return Subtype_Mark_Id
;
20716 Constrain_Access
(Def_Id
, S
, Related_Nod
);
20719 and then Is_Itype
(Designated_Type
(Def_Id
))
20720 and then Nkind
(Related_Nod
) = N_Subtype_Declaration
20721 and then not Is_Incomplete_Type
(Designated_Type
(Def_Id
))
20723 Build_Itype_Reference
20724 (Designated_Type
(Def_Id
), Related_Nod
);
20728 Constrain_Array
(Def_Id
, S
, Related_Nod
, Related_Id
, Suffix
);
20730 when Decimal_Fixed_Point_Kind
=>
20731 Constrain_Decimal
(Def_Id
, S
);
20733 when Enumeration_Kind
=>
20734 Constrain_Enumeration
(Def_Id
, S
);
20735 Inherit_Predicate_Flags
(Def_Id
, Subtype_Mark_Id
);
20737 when Ordinary_Fixed_Point_Kind
=>
20738 Constrain_Ordinary_Fixed
(Def_Id
, S
);
20741 Constrain_Float
(Def_Id
, S
);
20743 when Integer_Kind
=>
20744 Constrain_Integer
(Def_Id
, S
);
20745 Inherit_Predicate_Flags
(Def_Id
, Subtype_Mark_Id
);
20747 when E_Record_Type |
20750 E_Incomplete_Type
=>
20751 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
20753 if Ekind
(Def_Id
) = E_Incomplete_Type
then
20754 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
20757 when Private_Kind
=>
20758 Constrain_Discriminated_Type
(Def_Id
, S
, Related_Nod
);
20759 Set_Private_Dependents
(Def_Id
, New_Elmt_List
);
20761 -- In case of an invalid constraint prevent further processing
20762 -- since the type constructed is missing expected fields.
20764 if Etype
(Def_Id
) = Any_Type
then
20768 -- If the full view is that of a task with discriminants,
20769 -- we must constrain both the concurrent type and its
20770 -- corresponding record type. Otherwise we will just propagate
20771 -- the constraint to the full view, if available.
20773 if Present
(Full_View
(Subtype_Mark_Id
))
20774 and then Has_Discriminants
(Subtype_Mark_Id
)
20775 and then Is_Concurrent_Type
(Full_View
(Subtype_Mark_Id
))
20778 Create_Itype
(E_Void
, Related_Nod
, Related_Id
, Suffix
);
20780 Set_Entity
(Subtype_Mark
(S
), Full_View
(Subtype_Mark_Id
));
20781 Constrain_Concurrent
(Full_View_Id
, S
,
20782 Related_Nod
, Related_Id
, Suffix
);
20783 Set_Entity
(Subtype_Mark
(S
), Subtype_Mark_Id
);
20784 Set_Full_View
(Def_Id
, Full_View_Id
);
20786 -- Introduce an explicit reference to the private subtype,
20787 -- to prevent scope anomalies in gigi if first use appears
20788 -- in a nested context, e.g. a later function body.
20789 -- Should this be generated in other contexts than a full
20790 -- type declaration?
20792 if Is_Itype
(Def_Id
)
20794 Nkind
(Parent
(P
)) = N_Full_Type_Declaration
20796 Build_Itype_Reference
(Def_Id
, Parent
(P
));
20800 Prepare_Private_Subtype_Completion
(Def_Id
, Related_Nod
);
20803 when Concurrent_Kind
=>
20804 Constrain_Concurrent
(Def_Id
, S
,
20805 Related_Nod
, Related_Id
, Suffix
);
20808 Error_Msg_N
("invalid subtype mark in subtype indication", S
);
20811 -- Size and Convention are always inherited from the base type
20813 Set_Size_Info
(Def_Id
, (Subtype_Mark_Id
));
20814 Set_Convention
(Def_Id
, Convention
(Subtype_Mark_Id
));
20818 end Process_Subtype
;
20820 --------------------------------------------
20821 -- Propagate_Default_Init_Cond_Attributes --
20822 --------------------------------------------
20824 procedure Propagate_Default_Init_Cond_Attributes
20825 (From_Typ
: Entity_Id
;
20826 To_Typ
: Entity_Id
;
20827 Parent_To_Derivation
: Boolean := False;
20828 Private_To_Full_View
: Boolean := False)
20830 procedure Remove_Default_Init_Cond_Procedure
(Typ
: Entity_Id
);
20831 -- Remove the default initial procedure (if any) from the rep chain of
20834 ----------------------------------------
20835 -- Remove_Default_Init_Cond_Procedure --
20836 ----------------------------------------
20838 procedure Remove_Default_Init_Cond_Procedure
(Typ
: Entity_Id
) is
20839 Found
: Boolean := False;
20845 Subp
:= Subprograms_For_Type
(Typ
);
20846 while Present
(Subp
) loop
20847 if Is_Default_Init_Cond_Procedure
(Subp
) then
20853 Subp
:= Subprograms_For_Type
(Subp
);
20857 Set_Subprograms_For_Type
(Prev
, Subprograms_For_Type
(Subp
));
20858 Set_Subprograms_For_Type
(Subp
, Empty
);
20860 end Remove_Default_Init_Cond_Procedure
;
20864 Inherit_Procedure
: Boolean := False;
20866 -- Start of processing for Propagate_Default_Init_Cond_Attributes
20869 if Has_Default_Init_Cond
(From_Typ
) then
20871 -- A derived type inherits the attributes from its parent type
20873 if Parent_To_Derivation
then
20874 Set_Has_Inherited_Default_Init_Cond
(To_Typ
);
20876 -- A full view shares the attributes with its private view
20879 Set_Has_Default_Init_Cond
(To_Typ
);
20882 Inherit_Procedure
:= True;
20884 -- Due to the order of expansion, a derived private type is processed
20885 -- by two routines which both attempt to set the attributes related
20886 -- to pragma Default_Initial_Condition - Build_Derived_Type and then
20887 -- Process_Full_View.
20890 -- type Parent_Typ is private
20891 -- with Default_Initial_Condition ...;
20893 -- type Parent_Typ is ...;
20896 -- with Pack; use Pack;
20897 -- package Pack_2 is
20898 -- type Deriv_Typ is private
20899 -- with Default_Initial_Condition ...;
20901 -- type Deriv_Typ is new Parent_Typ;
20904 -- When Build_Derived_Type operates, it sets the attributes on the
20905 -- full view without taking into account that the private view may
20906 -- define its own default initial condition procedure. This becomes
20907 -- apparent in Process_Full_View which must undo some of the work by
20908 -- Build_Derived_Type and propagate the attributes from the private
20909 -- to the full view.
20911 if Private_To_Full_View
then
20912 Set_Has_Inherited_Default_Init_Cond
(To_Typ
, False);
20913 Remove_Default_Init_Cond_Procedure
(To_Typ
);
20916 -- A type must inherit the default initial condition procedure from a
20917 -- parent type when the parent itself is inheriting the procedure or
20918 -- when it is defining one. This circuitry is also used when dealing
20919 -- with the private / full view of a type.
20921 elsif Has_Inherited_Default_Init_Cond
(From_Typ
)
20922 or (Parent_To_Derivation
20923 and Present
(Get_Pragma
20924 (From_Typ
, Pragma_Default_Initial_Condition
)))
20926 Set_Has_Inherited_Default_Init_Cond
(To_Typ
);
20927 Inherit_Procedure
:= True;
20930 if Inherit_Procedure
20931 and then No
(Default_Init_Cond_Procedure
(To_Typ
))
20933 Set_Default_Init_Cond_Procedure
20934 (To_Typ
, Default_Init_Cond_Procedure
(From_Typ
));
20936 end Propagate_Default_Init_Cond_Attributes
;
20938 -----------------------------
20939 -- Record_Type_Declaration --
20940 -----------------------------
20942 procedure Record_Type_Declaration
20947 Def
: constant Node_Id
:= Type_Definition
(N
);
20948 Is_Tagged
: Boolean;
20949 Tag_Comp
: Entity_Id
;
20952 -- These flags must be initialized before calling Process_Discriminants
20953 -- because this routine makes use of them.
20955 Set_Ekind
(T
, E_Record_Type
);
20957 Init_Size_Align
(T
);
20958 Set_Interfaces
(T
, No_Elist
);
20959 Set_Stored_Constraint
(T
, No_Elist
);
20960 Set_Default_SSO
(T
);
20964 if Ada_Version
< Ada_2005
or else not Interface_Present
(Def
) then
20965 if Limited_Present
(Def
) then
20966 Check_SPARK_05_Restriction
("limited is not allowed", N
);
20969 if Abstract_Present
(Def
) then
20970 Check_SPARK_05_Restriction
("abstract is not allowed", N
);
20973 -- The flag Is_Tagged_Type might have already been set by
20974 -- Find_Type_Name if it detected an error for declaration T. This
20975 -- arises in the case of private tagged types where the full view
20976 -- omits the word tagged.
20979 Tagged_Present
(Def
)
20980 or else (Serious_Errors_Detected
> 0 and then Is_Tagged_Type
(T
));
20982 Set_Is_Limited_Record
(T
, Limited_Present
(Def
));
20985 Set_Is_Tagged_Type
(T
, True);
20986 Set_No_Tagged_Streams_Pragma
(T
, No_Tagged_Streams
);
20989 -- Type is abstract if full declaration carries keyword, or if
20990 -- previous partial view did.
20992 Set_Is_Abstract_Type
(T
, Is_Abstract_Type
(T
)
20993 or else Abstract_Present
(Def
));
20996 Check_SPARK_05_Restriction
("interface is not allowed", N
);
20999 Analyze_Interface_Declaration
(T
, Def
);
21001 if Present
(Discriminant_Specifications
(N
)) then
21003 ("interface types cannot have discriminants",
21004 Defining_Identifier
21005 (First
(Discriminant_Specifications
(N
))));
21009 -- First pass: if there are self-referential access components,
21010 -- create the required anonymous access type declarations, and if
21011 -- need be an incomplete type declaration for T itself.
21013 Check_Anonymous_Access_Components
(N
, T
, Prev
, Component_List
(Def
));
21015 if Ada_Version
>= Ada_2005
21016 and then Present
(Interface_List
(Def
))
21018 Check_Interfaces
(N
, Def
);
21021 Ifaces_List
: Elist_Id
;
21024 -- Ada 2005 (AI-251): Collect the list of progenitors that are not
21025 -- already in the parents.
21029 Ifaces_List
=> Ifaces_List
,
21030 Exclude_Parents
=> True);
21032 Set_Interfaces
(T
, Ifaces_List
);
21036 -- Records constitute a scope for the component declarations within.
21037 -- The scope is created prior to the processing of these declarations.
21038 -- Discriminants are processed first, so that they are visible when
21039 -- processing the other components. The Ekind of the record type itself
21040 -- is set to E_Record_Type (subtypes appear as E_Record_Subtype).
21042 -- Enter record scope
21046 -- If an incomplete or private type declaration was already given for
21047 -- the type, then this scope already exists, and the discriminants have
21048 -- been declared within. We must verify that the full declaration
21049 -- matches the incomplete one.
21051 Check_Or_Process_Discriminants
(N
, T
, Prev
);
21053 Set_Is_Constrained
(T
, not Has_Discriminants
(T
));
21054 Set_Has_Delayed_Freeze
(T
, True);
21056 -- For tagged types add a manually analyzed component corresponding
21057 -- to the component _tag, the corresponding piece of tree will be
21058 -- expanded as part of the freezing actions if it is not a CPP_Class.
21062 -- Do not add the tag unless we are in expansion mode
21064 if Expander_Active
then
21065 Tag_Comp
:= Make_Defining_Identifier
(Sloc
(Def
), Name_uTag
);
21066 Enter_Name
(Tag_Comp
);
21068 Set_Ekind
(Tag_Comp
, E_Component
);
21069 Set_Is_Tag
(Tag_Comp
);
21070 Set_Is_Aliased
(Tag_Comp
);
21071 Set_Etype
(Tag_Comp
, RTE
(RE_Tag
));
21072 Set_DT_Entry_Count
(Tag_Comp
, No_Uint
);
21073 Set_Original_Record_Component
(Tag_Comp
, Tag_Comp
);
21074 Init_Component_Location
(Tag_Comp
);
21076 -- Ada 2005 (AI-251): Addition of the Tag corresponding to all the
21077 -- implemented interfaces.
21079 if Has_Interfaces
(T
) then
21080 Add_Interface_Tag_Components
(N
, T
);
21084 Make_Class_Wide_Type
(T
);
21085 Set_Direct_Primitive_Operations
(T
, New_Elmt_List
);
21088 -- We must suppress range checks when processing record components in
21089 -- the presence of discriminants, since we don't want spurious checks to
21090 -- be generated during their analysis, but Suppress_Range_Checks flags
21091 -- must be reset the after processing the record definition.
21093 -- Note: this is the only use of Kill_Range_Checks, and is a bit odd,
21094 -- couldn't we just use the normal range check suppression method here.
21095 -- That would seem cleaner ???
21097 if Has_Discriminants
(T
) and then not Range_Checks_Suppressed
(T
) then
21098 Set_Kill_Range_Checks
(T
, True);
21099 Record_Type_Definition
(Def
, Prev
);
21100 Set_Kill_Range_Checks
(T
, False);
21102 Record_Type_Definition
(Def
, Prev
);
21105 -- Exit from record scope
21109 -- Ada 2005 (AI-251 and AI-345): Derive the interface subprograms of all
21110 -- the implemented interfaces and associate them an aliased entity.
21113 and then not Is_Empty_List
(Interface_List
(Def
))
21115 Derive_Progenitor_Subprograms
(T
, T
);
21118 Check_Function_Writable_Actuals
(N
);
21119 end Record_Type_Declaration
;
21121 ----------------------------
21122 -- Record_Type_Definition --
21123 ----------------------------
21125 procedure Record_Type_Definition
(Def
: Node_Id
; Prev_T
: Entity_Id
) is
21126 Component
: Entity_Id
;
21127 Ctrl_Components
: Boolean := False;
21128 Final_Storage_Only
: Boolean;
21132 if Ekind
(Prev_T
) = E_Incomplete_Type
then
21133 T
:= Full_View
(Prev_T
);
21138 -- In SPARK, tagged types and type extensions may only be declared in
21139 -- the specification of library unit packages.
21141 if Present
(Def
) and then Is_Tagged_Type
(T
) then
21147 if Nkind
(Parent
(Def
)) = N_Full_Type_Declaration
then
21148 Typ
:= Parent
(Def
);
21151 (Nkind
(Parent
(Def
)) = N_Derived_Type_Definition
);
21152 Typ
:= Parent
(Parent
(Def
));
21155 Ctxt
:= Parent
(Typ
);
21157 if Nkind
(Ctxt
) = N_Package_Body
21158 and then Nkind
(Parent
(Ctxt
)) = N_Compilation_Unit
21160 Check_SPARK_05_Restriction
21161 ("type should be defined in package specification", Typ
);
21163 elsif Nkind
(Ctxt
) /= N_Package_Specification
21164 or else Nkind
(Parent
(Parent
(Ctxt
))) /= N_Compilation_Unit
21166 Check_SPARK_05_Restriction
21167 ("type should be defined in library unit package", Typ
);
21172 Final_Storage_Only
:= not Is_Controlled
(T
);
21174 -- Ada 2005: Check whether an explicit Limited is present in a derived
21175 -- type declaration.
21177 if Nkind
(Parent
(Def
)) = N_Derived_Type_Definition
21178 and then Limited_Present
(Parent
(Def
))
21180 Set_Is_Limited_Record
(T
);
21183 -- If the component list of a record type is defined by the reserved
21184 -- word null and there is no discriminant part, then the record type has
21185 -- no components and all records of the type are null records (RM 3.7)
21186 -- This procedure is also called to process the extension part of a
21187 -- record extension, in which case the current scope may have inherited
21191 or else No
(Component_List
(Def
))
21192 or else Null_Present
(Component_List
(Def
))
21194 if not Is_Tagged_Type
(T
) then
21195 Check_SPARK_05_Restriction
("untagged record cannot be null", Def
);
21199 Analyze_Declarations
(Component_Items
(Component_List
(Def
)));
21201 if Present
(Variant_Part
(Component_List
(Def
))) then
21202 Check_SPARK_05_Restriction
("variant part is not allowed", Def
);
21203 Analyze
(Variant_Part
(Component_List
(Def
)));
21207 -- After completing the semantic analysis of the record definition,
21208 -- record components, both new and inherited, are accessible. Set their
21209 -- kind accordingly. Exclude malformed itypes from illegal declarations,
21210 -- whose Ekind may be void.
21212 Component
:= First_Entity
(Current_Scope
);
21213 while Present
(Component
) loop
21214 if Ekind
(Component
) = E_Void
21215 and then not Is_Itype
(Component
)
21217 Set_Ekind
(Component
, E_Component
);
21218 Init_Component_Location
(Component
);
21221 if Has_Task
(Etype
(Component
)) then
21225 if Has_Protected
(Etype
(Component
)) then
21226 Set_Has_Protected
(T
);
21229 if Ekind
(Component
) /= E_Component
then
21232 -- Do not set Has_Controlled_Component on a class-wide equivalent
21233 -- type. See Make_CW_Equivalent_Type.
21235 elsif not Is_Class_Wide_Equivalent_Type
(T
)
21236 and then (Has_Controlled_Component
(Etype
(Component
))
21237 or else (Chars
(Component
) /= Name_uParent
21238 and then Is_Controlled
(Etype
(Component
))))
21240 Set_Has_Controlled_Component
(T
, True);
21241 Final_Storage_Only
:=
21243 and then Finalize_Storage_Only
(Etype
(Component
));
21244 Ctrl_Components
:= True;
21247 Next_Entity
(Component
);
21250 -- A Type is Finalize_Storage_Only only if all its controlled components
21253 if Ctrl_Components
then
21254 Set_Finalize_Storage_Only
(T
, Final_Storage_Only
);
21257 -- Place reference to end record on the proper entity, which may
21258 -- be a partial view.
21260 if Present
(Def
) then
21261 Process_End_Label
(Def
, 'e', Prev_T
);
21263 end Record_Type_Definition
;
21265 ------------------------
21266 -- Replace_Components --
21267 ------------------------
21269 procedure Replace_Components
(Typ
: Entity_Id
; Decl
: Node_Id
) is
21270 function Process
(N
: Node_Id
) return Traverse_Result
;
21276 function Process
(N
: Node_Id
) return Traverse_Result
is
21280 if Nkind
(N
) = N_Discriminant_Specification
then
21281 Comp
:= First_Discriminant
(Typ
);
21282 while Present
(Comp
) loop
21283 if Chars
(Comp
) = Chars
(Defining_Identifier
(N
)) then
21284 Set_Defining_Identifier
(N
, Comp
);
21288 Next_Discriminant
(Comp
);
21291 elsif Nkind
(N
) = N_Component_Declaration
then
21292 Comp
:= First_Component
(Typ
);
21293 while Present
(Comp
) loop
21294 if Chars
(Comp
) = Chars
(Defining_Identifier
(N
)) then
21295 Set_Defining_Identifier
(N
, Comp
);
21299 Next_Component
(Comp
);
21306 procedure Replace
is new Traverse_Proc
(Process
);
21308 -- Start of processing for Replace_Components
21312 end Replace_Components
;
21314 -------------------------------
21315 -- Set_Completion_Referenced --
21316 -------------------------------
21318 procedure Set_Completion_Referenced
(E
: Entity_Id
) is
21320 -- If in main unit, mark entity that is a completion as referenced,
21321 -- warnings go on the partial view when needed.
21323 if In_Extended_Main_Source_Unit
(E
) then
21324 Set_Referenced
(E
);
21326 end Set_Completion_Referenced
;
21328 ---------------------
21329 -- Set_Default_SSO --
21330 ---------------------
21332 procedure Set_Default_SSO
(T
: Entity_Id
) is
21334 case Opt
.Default_SSO
is
21338 Set_SSO_Set_Low_By_Default
(T
, True);
21340 Set_SSO_Set_High_By_Default
(T
, True);
21342 raise Program_Error
;
21344 end Set_Default_SSO
;
21346 ---------------------
21347 -- Set_Fixed_Range --
21348 ---------------------
21350 -- The range for fixed-point types is complicated by the fact that we
21351 -- do not know the exact end points at the time of the declaration. This
21352 -- is true for three reasons:
21354 -- A size clause may affect the fudging of the end-points.
21355 -- A small clause may affect the values of the end-points.
21356 -- We try to include the end-points if it does not affect the size.
21358 -- This means that the actual end-points must be established at the
21359 -- point when the type is frozen. Meanwhile, we first narrow the range
21360 -- as permitted (so that it will fit if necessary in a small specified
21361 -- size), and then build a range subtree with these narrowed bounds.
21362 -- Set_Fixed_Range constructs the range from real literal values, and
21363 -- sets the range as the Scalar_Range of the given fixed-point type entity.
21365 -- The parent of this range is set to point to the entity so that it is
21366 -- properly hooked into the tree (unlike normal Scalar_Range entries for
21367 -- other scalar types, which are just pointers to the range in the
21368 -- original tree, this would otherwise be an orphan).
21370 -- The tree is left unanalyzed. When the type is frozen, the processing
21371 -- in Freeze.Freeze_Fixed_Point_Type notices that the range is not
21372 -- analyzed, and uses this as an indication that it should complete
21373 -- work on the range (it will know the final small and size values).
21375 procedure Set_Fixed_Range
21381 S
: constant Node_Id
:=
21383 Low_Bound
=> Make_Real_Literal
(Loc
, Lo
),
21384 High_Bound
=> Make_Real_Literal
(Loc
, Hi
));
21386 Set_Scalar_Range
(E
, S
);
21389 -- Before the freeze point, the bounds of a fixed point are universal
21390 -- and carry the corresponding type.
21392 Set_Etype
(Low_Bound
(S
), Universal_Real
);
21393 Set_Etype
(High_Bound
(S
), Universal_Real
);
21394 end Set_Fixed_Range
;
21396 ----------------------------------
21397 -- Set_Scalar_Range_For_Subtype --
21398 ----------------------------------
21400 procedure Set_Scalar_Range_For_Subtype
21401 (Def_Id
: Entity_Id
;
21405 Kind
: constant Entity_Kind
:= Ekind
(Def_Id
);
21408 -- Defend against previous error
21410 if Nkind
(R
) = N_Error
then
21414 Set_Scalar_Range
(Def_Id
, R
);
21416 -- We need to link the range into the tree before resolving it so
21417 -- that types that are referenced, including importantly the subtype
21418 -- itself, are properly frozen (Freeze_Expression requires that the
21419 -- expression be properly linked into the tree). Of course if it is
21420 -- already linked in, then we do not disturb the current link.
21422 if No
(Parent
(R
)) then
21423 Set_Parent
(R
, Def_Id
);
21426 -- Reset the kind of the subtype during analysis of the range, to
21427 -- catch possible premature use in the bounds themselves.
21429 Set_Ekind
(Def_Id
, E_Void
);
21430 Process_Range_Expr_In_Decl
(R
, Subt
, Subtyp
=> Def_Id
);
21431 Set_Ekind
(Def_Id
, Kind
);
21432 end Set_Scalar_Range_For_Subtype
;
21434 --------------------------------------------------------
21435 -- Set_Stored_Constraint_From_Discriminant_Constraint --
21436 --------------------------------------------------------
21438 procedure Set_Stored_Constraint_From_Discriminant_Constraint
21442 -- Make sure set if encountered during Expand_To_Stored_Constraint
21444 Set_Stored_Constraint
(E
, No_Elist
);
21446 -- Give it the right value
21448 if Is_Constrained
(E
) and then Has_Discriminants
(E
) then
21449 Set_Stored_Constraint
(E
,
21450 Expand_To_Stored_Constraint
(E
, Discriminant_Constraint
(E
)));
21452 end Set_Stored_Constraint_From_Discriminant_Constraint
;
21454 -------------------------------------
21455 -- Signed_Integer_Type_Declaration --
21456 -------------------------------------
21458 procedure Signed_Integer_Type_Declaration
(T
: Entity_Id
; Def
: Node_Id
) is
21459 Implicit_Base
: Entity_Id
;
21460 Base_Typ
: Entity_Id
;
21463 Errs
: Boolean := False;
21467 function Can_Derive_From
(E
: Entity_Id
) return Boolean;
21468 -- Determine whether given bounds allow derivation from specified type
21470 procedure Check_Bound
(Expr
: Node_Id
);
21471 -- Check bound to make sure it is integral and static. If not, post
21472 -- appropriate error message and set Errs flag
21474 ---------------------
21475 -- Can_Derive_From --
21476 ---------------------
21478 -- Note we check both bounds against both end values, to deal with
21479 -- strange types like ones with a range of 0 .. -12341234.
21481 function Can_Derive_From
(E
: Entity_Id
) return Boolean is
21482 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(E
));
21483 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(E
));
21485 return Lo
<= Lo_Val
and then Lo_Val
<= Hi
21487 Lo
<= Hi_Val
and then Hi_Val
<= Hi
;
21488 end Can_Derive_From
;
21494 procedure Check_Bound
(Expr
: Node_Id
) is
21496 -- If a range constraint is used as an integer type definition, each
21497 -- bound of the range must be defined by a static expression of some
21498 -- integer type, but the two bounds need not have the same integer
21499 -- type (Negative bounds are allowed.) (RM 3.5.4)
21501 if not Is_Integer_Type
(Etype
(Expr
)) then
21503 ("integer type definition bounds must be of integer type", Expr
);
21506 elsif not Is_OK_Static_Expression
(Expr
) then
21507 Flag_Non_Static_Expr
21508 ("non-static expression used for integer type bound!", Expr
);
21511 -- The bounds are folded into literals, and we set their type to be
21512 -- universal, to avoid typing difficulties: we cannot set the type
21513 -- of the literal to the new type, because this would be a forward
21514 -- reference for the back end, and if the original type is user-
21515 -- defined this can lead to spurious semantic errors (e.g. 2928-003).
21518 if Is_Entity_Name
(Expr
) then
21519 Fold_Uint
(Expr
, Expr_Value
(Expr
), True);
21522 Set_Etype
(Expr
, Universal_Integer
);
21526 -- Start of processing for Signed_Integer_Type_Declaration
21529 -- Create an anonymous base type
21532 Create_Itype
(E_Signed_Integer_Type
, Parent
(Def
), T
, 'B');
21534 -- Analyze and check the bounds, they can be of any integer type
21536 Lo
:= Low_Bound
(Def
);
21537 Hi
:= High_Bound
(Def
);
21539 -- Arbitrarily use Integer as the type if either bound had an error
21541 if Hi
= Error
or else Lo
= Error
then
21542 Base_Typ
:= Any_Integer
;
21543 Set_Error_Posted
(T
, True);
21545 -- Here both bounds are OK expressions
21548 Analyze_And_Resolve
(Lo
, Any_Integer
);
21549 Analyze_And_Resolve
(Hi
, Any_Integer
);
21555 Hi
:= Type_High_Bound
(Standard_Long_Long_Integer
);
21556 Lo
:= Type_Low_Bound
(Standard_Long_Long_Integer
);
21559 -- Find type to derive from
21561 Lo_Val
:= Expr_Value
(Lo
);
21562 Hi_Val
:= Expr_Value
(Hi
);
21564 if Can_Derive_From
(Standard_Short_Short_Integer
) then
21565 Base_Typ
:= Base_Type
(Standard_Short_Short_Integer
);
21567 elsif Can_Derive_From
(Standard_Short_Integer
) then
21568 Base_Typ
:= Base_Type
(Standard_Short_Integer
);
21570 elsif Can_Derive_From
(Standard_Integer
) then
21571 Base_Typ
:= Base_Type
(Standard_Integer
);
21573 elsif Can_Derive_From
(Standard_Long_Integer
) then
21574 Base_Typ
:= Base_Type
(Standard_Long_Integer
);
21576 elsif Can_Derive_From
(Standard_Long_Long_Integer
) then
21577 Check_Restriction
(No_Long_Long_Integers
, Def
);
21578 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
21581 Base_Typ
:= Base_Type
(Standard_Long_Long_Integer
);
21582 Error_Msg_N
("integer type definition bounds out of range", Def
);
21583 Hi
:= Type_High_Bound
(Standard_Long_Long_Integer
);
21584 Lo
:= Type_Low_Bound
(Standard_Long_Long_Integer
);
21588 -- Complete both implicit base and declared first subtype entities. The
21589 -- inheritance of the rep item chain ensures that SPARK-related pragmas
21590 -- are not clobbered when the signed integer type acts as a full view of
21593 Set_Etype
(Implicit_Base
, Base_Typ
);
21594 Set_Size_Info
(Implicit_Base
, Base_Typ
);
21595 Set_RM_Size
(Implicit_Base
, RM_Size
(Base_Typ
));
21596 Set_First_Rep_Item
(Implicit_Base
, First_Rep_Item
(Base_Typ
));
21597 Set_Scalar_Range
(Implicit_Base
, Scalar_Range
(Base_Typ
));
21599 Set_Ekind
(T
, E_Signed_Integer_Subtype
);
21600 Set_Etype
(T
, Implicit_Base
);
21601 Set_Size_Info
(T
, Implicit_Base
);
21602 Inherit_Rep_Item_Chain
(T
, Implicit_Base
);
21603 Set_Scalar_Range
(T
, Def
);
21604 Set_RM_Size
(T
, UI_From_Int
(Minimum_Size
(T
)));
21605 Set_Is_Constrained
(T
);
21606 end Signed_Integer_Type_Declaration
;