1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, 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 Contracts
; use Contracts
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Einfo
.Entities
; use Einfo
.Entities
;
33 with Einfo
.Utils
; use Einfo
.Utils
;
34 with Elists
; use Elists
;
35 with Errout
; use Errout
;
36 with Exp_Ch3
; use Exp_Ch3
;
37 with Exp_Ch7
; use Exp_Ch7
;
38 with Exp_Disp
; use Exp_Disp
;
39 with Exp_Pakd
; use Exp_Pakd
;
40 with Exp_Util
; use Exp_Util
;
41 with Exp_Tss
; use Exp_Tss
;
42 with Ghost
; use Ghost
;
43 with Layout
; use Layout
;
46 with Namet
; use Namet
;
47 with Nlists
; use Nlists
;
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_Cat
; use Sem_Cat
;
56 with Sem_Ch3
; use Sem_Ch3
;
57 with Sem_Ch6
; use Sem_Ch6
;
58 with Sem_Ch7
; use Sem_Ch7
;
59 with Sem_Ch8
; use Sem_Ch8
;
60 with Sem_Ch13
; use Sem_Ch13
;
61 with Sem_Disp
; use Sem_Disp
;
62 with Sem_Eval
; use Sem_Eval
;
63 with Sem_Mech
; use Sem_Mech
;
64 with Sem_Prag
; use Sem_Prag
;
65 with Sem_Res
; use Sem_Res
;
66 with Sem_Util
; use Sem_Util
;
67 with Sinfo
; use Sinfo
;
68 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
69 with Sinfo
.Utils
; use Sinfo
.Utils
;
70 with Snames
; use Snames
;
71 with Stand
; use Stand
;
72 with Stringt
; use Stringt
;
73 with Strub
; use Strub
;
74 with Targparm
; use Targparm
;
75 with Tbuild
; use Tbuild
;
76 with Ttypes
; use Ttypes
;
77 with Uintp
; use Uintp
;
78 with Urealp
; use Urealp
;
79 with Warnsw
; use Warnsw
;
81 package body Freeze
is
83 -----------------------
84 -- Local Subprograms --
85 -----------------------
87 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
88 -- Typ is a type that is being frozen. If no size clause is given,
89 -- but a default Esize has been computed, then this default Esize is
90 -- adjusted up if necessary to be consistent with a given alignment,
91 -- but never to a value greater than System_Max_Integer_Size. This is
92 -- used for all discrete types and for fixed-point types.
94 procedure Build_And_Analyze_Renamed_Body
97 After
: in out Node_Id
);
98 -- Build body for a renaming declaration, insert in tree and analyze
100 procedure Check_Address_Clause
(E
: Entity_Id
);
101 -- Apply legality checks to address clauses for object declarations,
102 -- at the point the object is frozen. Also ensure any initialization is
103 -- performed only after the object has been frozen.
105 procedure Check_Component_Storage_Order
106 (Encl_Type
: Entity_Id
;
109 Comp_ADC_Present
: out Boolean);
110 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
111 -- clause, verify that the component type has an explicit and compatible
112 -- attribute/aspect. For arrays, Comp is Empty; for records, it is the
113 -- entity of the component under consideration. For an Encl_Type that
114 -- does not have a Scalar_Storage_Order attribute definition clause,
115 -- verify that the component also does not have such a clause.
116 -- ADC is the attribute definition clause if present (or Empty). On return,
117 -- Comp_ADC_Present is set True if the component has a Scalar_Storage_Order
118 -- attribute definition clause.
120 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
121 -- As each entity is frozen, this routine is called to deal with the
122 -- setting of Debug_Info_Needed for the entity. This flag is set if
123 -- the entity comes from source, or if we are in Debug_Generated_Code
124 -- mode or if the -gnatdV debug flag is set. However, it never sets
125 -- the flag if Debug_Info_Off is set. This procedure also ensures that
126 -- subsidiary entities have the flag set as required.
128 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
);
129 -- When an expression function is frozen by a use of it, the expression
130 -- itself is frozen. Check that the expression does not include references
131 -- to deferred constants without completion. We report this at the freeze
132 -- point of the function, to provide a better error message.
134 -- In most cases the expression itself is frozen by the time the function
135 -- itself is frozen, because the formals will be frozen by then. However,
136 -- Attribute references to outer types are freeze points for those types;
137 -- this routine generates the required freeze nodes for them.
139 procedure Check_Strict_Alignment
(E
: Entity_Id
);
140 -- E is a base type. If E is tagged or has a component that is aliased
141 -- or tagged or contains something this is aliased or tagged, set
144 procedure Check_Unsigned_Type
(E
: Entity_Id
);
145 pragma Inline
(Check_Unsigned_Type
);
146 -- If E is a fixed-point or discrete type, then all the necessary work
147 -- to freeze it is completed except for possible setting of the flag
148 -- Is_Unsigned_Type, which is done by this procedure. The call has no
149 -- effect if the entity E is not a discrete or fixed-point type.
151 procedure Freeze_And_Append
154 Result
: in out List_Id
);
155 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
156 -- nodes to Result, modifying Result from No_List if necessary. N has
157 -- the same usage as in Freeze_Entity.
159 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
160 -- Freeze enumeration type. The Esize field is set as processing
161 -- proceeds (i.e. set by default when the type is declared and then
162 -- adjusted by rep clauses). What this procedure does is to make sure
163 -- that if a foreign convention is specified, and no specific size
164 -- is given, then the size must be at least Integer'Size.
166 procedure Freeze_Static_Object
(E
: Entity_Id
);
167 -- If an object is frozen which has Is_Statically_Allocated set, then
168 -- all referenced types must also be marked with this flag. This routine
169 -- is in charge of meeting this requirement for the object entity E.
171 procedure Freeze_Subprogram
(E
: Entity_Id
);
172 -- Perform freezing actions for a subprogram (create extra formals,
173 -- and set proper default mechanism values). Note that this routine
174 -- is not called for internal subprograms, for which neither of these
175 -- actions is needed (or desirable, we do not want for example to have
176 -- these extra formals present in initialization procedures, where they
177 -- would serve no purpose). In this call E is either a subprogram or
178 -- a subprogram type (i.e. an access to a subprogram).
180 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
181 -- True if T is not private and has no private components, or has a full
182 -- view. Used to determine whether the designated type of an access type
183 -- should be frozen when the access type is frozen. This is done when an
184 -- allocator is frozen, or an expression that may involve attributes of
185 -- the designated type. Otherwise freezing the access type does not freeze
186 -- the designated type.
188 procedure Process_Default_Expressions
190 After
: in out Node_Id
);
191 -- This procedure is called for each subprogram to complete processing of
192 -- default expressions at the point where all types are known to be frozen.
193 -- The expressions must be analyzed in full, to make sure that all error
194 -- processing is done (they have only been preanalyzed). If the expression
195 -- is not an entity or literal, its analysis may generate code which must
196 -- not be executed. In that case we build a function body to hold that
197 -- code. This wrapper function serves no other purpose (it used to be
198 -- called to evaluate the default, but now the default is inlined at each
201 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
202 -- Typ is a record or array type that is being frozen. This routine sets
203 -- the default component alignment from the scope stack values if the
204 -- alignment is otherwise not specified.
206 procedure Set_SSO_From_Default
(T
: Entity_Id
);
207 -- T is a record or array type that is being frozen. If it is a base type,
208 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
209 -- will be set appropriately. Note that an explicit occurrence of aspect
210 -- Scalar_Storage_Order or an explicit setting of this aspect with an
211 -- attribute definition clause occurs, then these two flags are reset in
212 -- any case, so call will have no effect.
214 function Should_Freeze_Type
217 N
: Node_Id
) return Boolean;
218 -- True if Typ should be frozen when the profile of E is being frozen at N.
220 -- ??? Expression functions that are not completions shouldn't freeze types
221 -- but our current expansion and freezing model requires an early freezing
222 -- when the tag of Typ is needed or for an aggregate with a subtype of Typ,
223 -- so we return True in these cases.
225 procedure Undelay_Type
(T
: Entity_Id
);
226 -- T is a type of a component that we know to be an Itype. We don't want
227 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
228 -- Full_View or Corresponding_Record_Type.
230 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
);
231 -- Expr is the expression for an address clause for the entity denoted by
232 -- Nam whose type is Typ. If Typ has a default initialization, and there is
233 -- no explicit initialization in the source declaration, check whether the
234 -- address clause might cause overlaying of an entity, and emit a warning
235 -- on the side effect that the initialization will cause.
237 -------------------------------
238 -- Adjust_Esize_For_Alignment --
239 -------------------------------
241 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
245 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
246 Align
:= Alignment_In_Bits
(Typ
);
248 if Align
> Esize
(Typ
) then
249 if Align
> System_Max_Integer_Size
then
250 pragma Assert
(Serious_Errors_Detected
> 0);
252 Set_Esize
(Typ
, Align
);
256 end Adjust_Esize_For_Alignment
;
258 ------------------------------------
259 -- Build_And_Analyze_Renamed_Body --
260 ------------------------------------
262 procedure Build_And_Analyze_Renamed_Body
265 After
: in out Node_Id
)
267 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
268 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
270 Renamed_Subp
: Entity_Id
;
273 -- If the renamed subprogram is intrinsic, there is no need for a
274 -- wrapper body: we set the alias that will be called and expanded which
275 -- completes the declaration. This transformation is only legal if the
276 -- renamed entity has already been elaborated.
278 -- Note that it is legal for a renaming_as_body to rename an intrinsic
279 -- subprogram, as long as the renaming occurs before the new entity
280 -- is frozen (RM 8.5.4 (5)).
282 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
283 and then Is_Entity_Name
(Name
(Body_Decl
))
285 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
287 Renamed_Subp
:= Empty
;
290 if Present
(Renamed_Subp
)
291 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
293 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
294 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
296 -- We can make the renaming entity intrinsic if the renamed function
297 -- has an interface name, or if it is one of the shift/rotate
298 -- operations known to the compiler.
301 (Present
(Interface_Name
(Renamed_Subp
))
302 or else Chars
(Renamed_Subp
) in Name_Rotate_Left
306 | Name_Shift_Right_Arithmetic
)
308 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
310 if Present
(Alias
(Renamed_Subp
)) then
311 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
313 Set_Alias
(Ent
, Renamed_Subp
);
316 Set_Is_Intrinsic_Subprogram
(Ent
);
317 Set_Has_Completion
(Ent
);
320 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
321 Insert_After
(After
, Body_Node
);
322 Mark_Rewrite_Insertion
(Body_Node
);
326 end Build_And_Analyze_Renamed_Body
;
328 ------------------------
329 -- Build_Renamed_Body --
330 ------------------------
332 function Build_Renamed_Body
334 New_S
: Entity_Id
) return Node_Id
336 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
337 -- We use for the source location of the renamed body, the location of
338 -- the spec entity. It might seem more natural to use the location of
339 -- the renaming declaration itself, but that would be wrong, since then
340 -- the body we create would look as though it was created far too late,
341 -- and this could cause problems with elaboration order analysis,
342 -- particularly in connection with instantiations.
344 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
345 Nam
: constant Node_Id
:= Name
(N
);
347 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
353 O_Formal
: Entity_Id
;
354 Param_Spec
: Node_Id
;
356 Pref
: Node_Id
:= Empty
;
357 -- If the renamed entity is a primitive operation given in prefix form,
358 -- the prefix is the target object and it has to be added as the first
359 -- actual in the generated call.
362 -- Determine the entity being renamed, which is the target of the call
363 -- statement. If the name is an explicit dereference, this is a renaming
364 -- of a subprogram type rather than a subprogram. The name itself is
367 if Nkind
(Nam
) = N_Selected_Component
then
368 Old_S
:= Entity
(Selector_Name
(Nam
));
370 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
371 Old_S
:= Etype
(Nam
);
373 elsif Nkind
(Nam
) = N_Indexed_Component
then
374 if Is_Entity_Name
(Prefix
(Nam
)) then
375 Old_S
:= Entity
(Prefix
(Nam
));
377 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
380 elsif Nkind
(Nam
) = N_Character_Literal
then
381 Old_S
:= Etype
(New_S
);
384 Old_S
:= Entity
(Nam
);
387 if Is_Entity_Name
(Nam
) then
389 -- If the renamed entity is a predefined operator, retain full name
390 -- to ensure its visibility.
392 if Ekind
(Old_S
) = E_Operator
393 and then Nkind
(Nam
) = N_Expanded_Name
395 Call_Name
:= New_Copy
(Name
(N
));
397 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
401 if Nkind
(Nam
) = N_Selected_Component
402 and then Present
(First_Formal
(Old_S
))
404 (Is_Controlling_Formal
(First_Formal
(Old_S
))
405 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
408 -- Retrieve the target object, to be added as a first actual
411 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
412 Pref
:= Prefix
(Nam
);
415 Call_Name
:= New_Copy
(Name
(N
));
418 -- Original name may have been overloaded, but is fully resolved now
420 Set_Is_Overloaded
(Call_Name
, False);
423 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
425 Make_Subprogram_Declaration
(Loc
,
426 Specification
=> Specification
(N
)));
429 -- For simple renamings, subsequent calls can be expanded directly as
430 -- calls to the renamed entity. The body must be generated in any case
431 -- for calls that may appear elsewhere. This is not done in the case
432 -- where the subprogram is an instantiation because the actual proper
433 -- body has not been built yet.
435 if Ekind
(Old_S
) in E_Function | E_Procedure
436 and then not Is_Generic_Instance
(Old_S
)
438 Set_Body_To_Inline
(Decl
, Old_S
);
441 -- Check whether the return type is a limited view. If the subprogram
442 -- is already frozen the generated body may have a non-limited view
443 -- of the type, that must be used, because it is the one in the spec
444 -- of the renaming declaration.
446 if Ekind
(Old_S
) = E_Function
447 and then Is_Entity_Name
(Result_Definition
(Spec
))
450 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
452 if Has_Non_Limited_View
(Ret_Type
) then
453 Set_Result_Definition
454 (Spec
, New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
459 -- The body generated for this renaming is an internal artifact, and
460 -- does not constitute a freeze point for the called entity.
462 Set_Must_Not_Freeze
(Call_Name
);
464 Formal
:= First_Formal
(Defining_Entity
(Decl
));
466 if Present
(Pref
) then
468 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
469 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
472 -- The controlling formal may be an access parameter, or the
473 -- actual may be an access value, so adjust accordingly.
475 if Is_Access_Type
(Pref_Type
)
476 and then not Is_Access_Type
(Form_Type
)
479 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
481 elsif Is_Access_Type
(Form_Type
)
482 and then not Is_Access_Type
(Pref
)
486 Make_Attribute_Reference
(Loc
,
487 Attribute_Name
=> Name_Access
,
488 Prefix
=> Relocate_Node
(Pref
)));
490 Actuals
:= New_List
(Pref
);
494 elsif Present
(Formal
) then
501 while Present
(Formal
) loop
502 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
503 Next_Formal
(Formal
);
506 -- If the renamed entity is an entry, inherit its profile. For other
507 -- renamings as bodies, both profiles must be subtype conformant, so it
508 -- is not necessary to replace the profile given in the declaration.
509 -- However, default values that are aggregates are rewritten when
510 -- partially analyzed, so we recover the original aggregate to insure
511 -- that subsequent conformity checking works. Similarly, if the default
512 -- expression was constant-folded, recover the original expression.
514 Formal
:= First_Formal
(Defining_Entity
(Decl
));
516 if Present
(Formal
) then
517 O_Formal
:= First_Formal
(Old_S
);
518 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
519 while Present
(Formal
) loop
520 if Is_Entry
(Old_S
) then
521 if Nkind
(Parameter_Type
(Param_Spec
)) /=
524 Set_Etype
(Formal
, Etype
(O_Formal
));
525 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
528 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
529 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
530 Nkind
(Default_Value
(O_Formal
))
532 Set_Expression
(Param_Spec
,
533 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
536 Next_Formal
(Formal
);
537 Next_Formal
(O_Formal
);
542 -- If the renamed entity is a function, the generated body contains a
543 -- return statement. Otherwise, build a procedure call. If the entity is
544 -- an entry, subsequent analysis of the call will transform it into the
545 -- proper entry or protected operation call. If the renamed entity is
546 -- a character literal, return it directly.
548 if Ekind
(Old_S
) = E_Function
549 or else Ekind
(Old_S
) = E_Operator
550 or else (Ekind
(Old_S
) = E_Subprogram_Type
551 and then Etype
(Old_S
) /= Standard_Void_Type
)
554 Make_Simple_Return_Statement
(Loc
,
556 Make_Function_Call
(Loc
,
558 Parameter_Associations
=> Actuals
));
560 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
562 Make_Simple_Return_Statement
(Loc
,
563 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
565 elsif Nkind
(Nam
) = N_Character_Literal
then
567 Make_Simple_Return_Statement
(Loc
, Expression
=> Call_Name
);
571 Make_Procedure_Call_Statement
(Loc
,
573 Parameter_Associations
=> Actuals
);
576 -- Create entities for subprogram body and formals
578 Set_Defining_Unit_Name
(Spec
,
579 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
581 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
582 while Present
(Param_Spec
) loop
583 Set_Defining_Identifier
(Param_Spec
,
584 Make_Defining_Identifier
(Loc
,
585 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
589 -- Copy SPARK pragma from renaming declaration
592 (Defining_Unit_Name
(Spec
), SPARK_Pragma
(New_S
));
593 Set_SPARK_Pragma_Inherited
594 (Defining_Unit_Name
(Spec
), SPARK_Pragma_Inherited
(New_S
));
596 -- In GNATprove, prefer to generate an expression function whenever
597 -- possible, to benefit from the more precise analysis in that case
598 -- (as if an implicit postcondition had been generated).
601 and then Nkind
(Call_Node
) = N_Simple_Return_Statement
604 Make_Expression_Function
(Loc
,
605 Specification
=> Spec
,
606 Expression
=> Expression
(Call_Node
));
609 Make_Subprogram_Body
(Loc
,
610 Specification
=> Spec
,
611 Declarations
=> New_List
,
612 Handled_Statement_Sequence
=>
613 Make_Handled_Sequence_Of_Statements
(Loc
,
614 Statements
=> New_List
(Call_Node
)));
617 -- Link the body to the entity whose declaration it completes. If
618 -- the body is analyzed when the renamed entity is frozen, it may
619 -- be necessary to restore the proper scope (see package Exp_Ch13).
621 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
622 and then Present
(Corresponding_Spec
(N
))
624 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
626 Set_Corresponding_Spec
(Body_Node
, New_S
);
630 end Build_Renamed_Body
;
632 --------------------------
633 -- Check_Address_Clause --
634 --------------------------
636 procedure Check_Address_Clause
(E
: Entity_Id
) is
637 Addr
: constant Node_Id
:= Address_Clause
(E
);
638 Typ
: constant Entity_Id
:= Etype
(E
);
643 Tag_Assign
: Node_Id
;
646 if Present
(Addr
) then
648 -- For a deferred constant, the initialization value is on full view
650 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
651 Decl
:= Declaration_Node
(Full_View
(E
));
653 Decl
:= Declaration_Node
(E
);
656 Expr
:= Expression
(Addr
);
658 if Needs_Constant_Address
(Decl
, Typ
) then
659 Check_Constant_Address_Clause
(Expr
, E
);
661 -- Has_Delayed_Freeze was set on E when the address clause was
662 -- analyzed, and must remain set because we want the address
663 -- clause to be elaborated only after any entity it references
664 -- has been elaborated.
667 -- If Rep_Clauses are to be ignored, remove address clause from
668 -- list attached to entity, because it may be illegal for gigi,
669 -- for example by breaking order of elaboration.
671 if Ignore_Rep_Clauses
then
676 Rep
:= First_Rep_Item
(E
);
679 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
683 and then Next_Rep_Item
(Rep
) /= Addr
689 if Present
(Rep
) then
690 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
694 -- And now remove the address clause
696 Kill_Rep_Clause
(Addr
);
698 elsif not Error_Posted
(Expr
)
699 and then not Needs_Finalization
(Typ
)
701 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
704 Init
:= Expression
(Decl
);
706 -- If a variable, or a non-imported constant, overlays a constant
707 -- object and has an initialization value, then the initialization
708 -- may end up writing into read-only memory. Detect the cases of
709 -- statically identical values and remove the initialization. In
710 -- the other cases, give a warning. We will give other warnings
711 -- later for the variable if it is assigned.
713 if (Ekind
(E
) = E_Variable
714 or else (Ekind
(E
) = E_Constant
715 and then not Is_Imported
(E
)))
716 and then Overlays_Constant
(E
)
717 and then Present
(Init
)
724 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
726 if Ekind
(O_Ent
) = E_Constant
727 and then Etype
(O_Ent
) = Typ
728 and then Present
(Constant_Value
(O_Ent
))
729 and then Compile_Time_Compare
731 Constant_Value
(O_Ent
),
732 Assume_Valid
=> True) = EQ
734 Set_No_Initialization
(Decl
);
737 elsif Comes_From_Source
(Init
)
738 and then Address_Clause_Overlay_Warnings
740 Error_Msg_Sloc
:= Sloc
(Addr
);
742 ("?o?constant& may be modified via address clause#",
748 -- Remove side effects from initial expression, except in the case of
749 -- limited build-in-place calls and aggregates, which have their own
750 -- expansion elsewhere. This exception is necessary to avoid copying
754 and then not Is_Inherently_Limited_Type
(Typ
)
756 -- Capture initialization value at point of declaration, and make
757 -- explicit assignment legal, because object may be a constant.
759 Remove_Side_Effects
(Init
);
760 Lhs
:= New_Occurrence_Of
(E
, Sloc
(Decl
));
761 Set_Assignment_OK
(Lhs
);
763 -- Move initialization to freeze actions, once the object has
764 -- been frozen and the address clause alignment check has been
767 Append_Freeze_Action
(E
,
768 Make_Assignment_Statement
(Sloc
(Decl
),
770 Expression
=> Expression
(Decl
)));
772 Set_No_Initialization
(Decl
);
774 -- If the object is tagged, check whether the tag must be
775 -- reassigned explicitly.
777 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
778 if Present
(Tag_Assign
) then
779 Append_Freeze_Action
(E
, Tag_Assign
);
783 end Check_Address_Clause
;
785 -----------------------------
786 -- Check_Compile_Time_Size --
787 -----------------------------
789 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
791 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
792 -- Sets the compile time known size in the RM_Size field of T, checking
793 -- for a size clause that was given which attempts to give a small size.
795 function Size_Known
(T
: Entity_Id
) return Boolean;
796 -- Recursive function that does all the work
798 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
799 -- If T is a constrained subtype, its size is not known if any of its
800 -- discriminant constraints is not static and it is not a null record.
801 -- The test is conservative and doesn't check that the components are
802 -- in fact constrained by non-static discriminant values. Could be made
809 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
811 if S
> System_Max_Integer_Size
then
814 -- Check for bad size clause given
816 elsif Has_Size_Clause
(T
) then
817 if RM_Size
(T
) < S
then
818 Error_Msg_Uint_1
:= S
;
819 Error_Msg_NE
(Size_Too_Small_Message
, Size_Clause
(T
), T
);
822 -- Set size if not set already. Do not set it to Uint_0, because in
823 -- some cases (notably array-of-record), the Component_Size is
824 -- No_Uint, which causes S to be Uint_0. Presumably the RM_Size and
825 -- Component_Size will eventually be set correctly by the back end.
827 elsif not Known_RM_Size
(T
) and then S
/= Uint_0
then
836 function Size_Known
(T
: Entity_Id
) return Boolean is
841 if Size_Known_At_Compile_Time
(T
) then
844 -- Always True for elementary types, even generic formal elementary
845 -- types. We used to return False in the latter case, but the size
846 -- is known at compile time, even in the template, we just do not
847 -- know the exact size but that's not the point of this routine.
849 elsif Is_Elementary_Type
(T
) or else Is_Task_Type
(T
) then
854 elsif Is_Array_Type
(T
) then
856 -- String literals always have known size, and we can set it
858 if Ekind
(T
) = E_String_Literal_Subtype
then
859 if Known_Component_Size
(T
) then
861 (T
, Component_Size
(T
) * String_Literal_Length
(T
));
864 -- The following is wrong, but does what previous versions
865 -- did. The Component_Size is unknown for the string in a
867 Set_Small_Size
(T
, Uint_0
);
872 -- Unconstrained types never have known at compile time size
874 elsif not Is_Constrained
(T
) then
877 -- Don't do any recursion on type with error posted, since we may
878 -- have a malformed type that leads us into a loop.
880 elsif Error_Posted
(T
) then
883 -- Otherwise if component size unknown, then array size unknown
885 elsif not Size_Known
(Component_Type
(T
)) then
889 -- Check for all indexes static, and also compute possible size
890 -- (in case it is not greater than System_Max_Integer_Size and
891 -- thus may be packable).
897 Size
: Uint
:= Component_Size
(T
);
901 -- See comment in Set_Small_Size above
907 Index
:= First_Index
(T
);
908 while Present
(Index
) loop
909 if Nkind
(Index
) = N_Range
then
910 Get_Index_Bounds
(Index
, Low
, High
);
912 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
916 Low
:= Type_Low_Bound
(Etype
(Index
));
917 High
:= Type_High_Bound
(Etype
(Index
));
920 if not Compile_Time_Known_Value
(Low
)
921 or else not Compile_Time_Known_Value
(High
)
922 or else Etype
(Index
) = Any_Type
927 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
939 Set_Small_Size
(T
, Size
);
943 -- For non-generic private types, go to underlying type if present
945 elsif Is_Private_Type
(T
)
946 and then not Is_Generic_Type
(T
)
947 and then Present
(Underlying_Type
(T
))
949 -- Don't do any recursion on type with error posted, since we may
950 -- have a malformed type that leads us into a loop.
952 if Error_Posted
(T
) then
955 return Size_Known
(Underlying_Type
(T
));
960 elsif Is_Record_Type
(T
) then
962 -- A subtype of a variant record must not have non-static
963 -- discriminated components.
965 if T
/= Base_Type
(T
)
966 and then not Static_Discriminated_Components
(T
)
970 -- Don't do any recursion on type with error posted, since we may
971 -- have a malformed type that leads us into a loop.
973 elsif Error_Posted
(T
) then
977 -- Now look at the components of the record
980 -- The following two variables are used to keep track of the
981 -- size of packed records if we can tell the size of the packed
982 -- record in the front end. Packed_Size_Known is True if so far
983 -- we can figure out the size. It is initialized to True for a
984 -- packed record, unless the record has either discriminants or
985 -- independent components, or is a strict-alignment type, since
986 -- it cannot be fully packed in this case.
988 -- The reason we eliminate the discriminated case is that
989 -- we don't know the way the back end lays out discriminated
990 -- packed records. If Packed_Size_Known is True, then
991 -- Packed_Size is the size in bits so far.
993 Packed_Size_Known
: Boolean :=
995 and then not Has_Discriminants
(T
)
996 and then not Has_Independent_Components
(T
)
997 and then not Strict_Alignment
(T
);
999 Packed_Size
: Uint
:= Uint_0
;
1000 -- Size in bits so far
1003 -- Test for variant part present
1005 if Has_Discriminants
(T
)
1006 and then Present
(Parent
(T
))
1007 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
1008 and then Nkind
(Type_Definition
(Parent
(T
))) =
1010 and then not Null_Present
(Type_Definition
(Parent
(T
)))
1012 Present
(Variant_Part
1013 (Component_List
(Type_Definition
(Parent
(T
)))))
1015 -- If variant part is present, and type is unconstrained,
1016 -- then we must have defaulted discriminants, or a size
1017 -- clause must be present for the type, or else the size
1018 -- is definitely not known at compile time.
1020 if not Is_Constrained
(T
)
1022 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
1023 and then not Known_RM_Size
(T
)
1024 and then not Known_Esize
(T
)
1030 -- Loop through components
1032 Comp
:= First_Component_Or_Discriminant
(T
);
1033 while Present
(Comp
) loop
1034 Ctyp
:= Etype
(Comp
);
1036 -- We do not know the packed size if there is a component
1037 -- clause present (we possibly could, but this would only
1038 -- help in the case of a record with partial rep clauses.
1039 -- That's because in the case of full rep clauses, the
1040 -- size gets figured out anyway by a different circuit).
1042 if Present
(Component_Clause
(Comp
)) then
1043 Packed_Size_Known
:= False;
1046 -- We do not know the packed size for an independent
1047 -- component or if it is of a strict-alignment type,
1048 -- since packing does not touch these (RM 13.2(7)).
1050 if Is_Independent
(Comp
)
1051 or else Is_Independent
(Ctyp
)
1052 or else Strict_Alignment
(Ctyp
)
1054 Packed_Size_Known
:= False;
1057 -- We need to identify a component that is an array where
1058 -- the index type is an enumeration type with non-standard
1059 -- representation, and some bound of the type depends on a
1062 -- This is because gigi computes the size by doing a
1063 -- substitution of the appropriate discriminant value in
1064 -- the size expression for the base type, and gigi is not
1065 -- clever enough to evaluate the resulting expression (which
1066 -- involves a call to rep_to_pos) at compile time.
1068 -- It would be nice if gigi would either recognize that
1069 -- this expression can be computed at compile time, or
1070 -- alternatively figured out the size from the subtype
1071 -- directly, where all the information is at hand ???
1073 if Is_Array_Type
(Etype
(Comp
))
1074 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1077 Ocomp
: constant Entity_Id
:=
1078 Original_Record_Component
(Comp
);
1079 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1085 Ind
:= First_Index
(OCtyp
);
1086 while Present
(Ind
) loop
1087 Indtyp
:= Etype
(Ind
);
1089 if Is_Enumeration_Type
(Indtyp
)
1090 and then Has_Non_Standard_Rep
(Indtyp
)
1092 Lo
:= Type_Low_Bound
(Indtyp
);
1093 Hi
:= Type_High_Bound
(Indtyp
);
1095 if Is_Entity_Name
(Lo
)
1096 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1100 elsif Is_Entity_Name
(Hi
)
1101 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1112 -- Clearly size of record is not known if the size of one of
1113 -- the components is not known.
1115 if not Size_Known
(Ctyp
) then
1119 -- Accumulate packed size if possible
1121 if Packed_Size_Known
then
1123 -- We can deal with elementary types, small packed arrays
1124 -- if the representation is a modular type and also small
1125 -- record types as checked by Set_Small_Size.
1127 if Is_Elementary_Type
(Ctyp
)
1128 or else (Is_Array_Type
(Ctyp
)
1130 (Packed_Array_Impl_Type
(Ctyp
))
1131 and then Is_Modular_Integer_Type
1132 (Packed_Array_Impl_Type
(Ctyp
)))
1133 or else Is_Record_Type
(Ctyp
)
1135 -- If RM_Size is known and static, then we can keep
1136 -- accumulating the packed size.
1138 if Known_Static_RM_Size
(Ctyp
) then
1140 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1142 -- If we have a field whose RM_Size is not known then
1143 -- we can't figure out the packed size here.
1146 Packed_Size_Known
:= False;
1149 -- For other types we can't figure out the packed size
1152 Packed_Size_Known
:= False;
1156 Next_Component_Or_Discriminant
(Comp
);
1159 if Packed_Size_Known
then
1160 Set_Small_Size
(T
, Packed_Size
);
1166 -- All other cases, size not known at compile time
1173 -------------------------------------
1174 -- Static_Discriminated_Components --
1175 -------------------------------------
1177 function Static_Discriminated_Components
1178 (T
: Entity_Id
) return Boolean
1180 Constraint
: Elmt_Id
;
1183 if Has_Discriminants
(T
)
1184 and then Present
(Discriminant_Constraint
(T
))
1185 and then Present
(First_Component
(T
))
1187 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1188 while Present
(Constraint
) loop
1189 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1193 Next_Elmt
(Constraint
);
1198 end Static_Discriminated_Components
;
1200 -- Start of processing for Check_Compile_Time_Size
1203 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1204 end Check_Compile_Time_Size
;
1206 -----------------------------------
1207 -- Check_Component_Storage_Order --
1208 -----------------------------------
1210 procedure Check_Component_Storage_Order
1211 (Encl_Type
: Entity_Id
;
1214 Comp_ADC_Present
: out Boolean)
1216 Comp_Base
: Entity_Id
;
1218 Encl_Base
: Entity_Id
;
1221 Component_Aliased
: Boolean;
1223 Comp_Byte_Aligned
: Boolean := False;
1224 -- Set for the record case, True if Comp is aligned on byte boundaries
1225 -- (in which case it is allowed to have different storage order).
1227 Comp_SSO_Differs
: Boolean;
1228 -- Set True when the component is a nested composite, and it does not
1229 -- have the same scalar storage order as Encl_Type.
1234 if Present
(Comp
) then
1236 Comp_Base
:= Etype
(Comp
);
1238 if Is_Tag
(Comp
) then
1239 Comp_Byte_Aligned
:= True;
1240 Component_Aliased
:= False;
1243 -- If a component clause is present, check if the component starts
1244 -- and ends on byte boundaries. Otherwise conservatively assume it
1245 -- does so only in the case where the record is not packed.
1247 if Present
(Component_Clause
(Comp
)) then
1248 Comp_Byte_Aligned
:=
1249 Known_Normalized_First_Bit
(Comp
)
1253 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0
1255 Esize
(Comp
) mod System_Storage_Unit
= 0;
1257 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1260 Component_Aliased
:= Is_Aliased
(Comp
);
1266 Err_Node
:= Encl_Type
;
1267 Comp_Base
:= Component_Type
(Encl_Type
);
1269 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1272 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1273 -- the attribute definition clause is attached to the first subtype.
1274 -- Also, if the base type is incomplete or private, go to full view
1277 Encl_Base
:= Base_Type
(Encl_Type
);
1278 if Present
(Underlying_Type
(Encl_Base
)) then
1279 Encl_Base
:= Underlying_Type
(Encl_Base
);
1282 Comp_Base
:= Base_Type
(Comp_Base
);
1283 if Present
(Underlying_Type
(Comp_Base
)) then
1284 Comp_Base
:= Underlying_Type
(Comp_Base
);
1288 Get_Attribute_Definition_Clause
1289 (First_Subtype
(Comp_Base
), Attribute_Scalar_Storage_Order
);
1290 Comp_ADC_Present
:= Present
(Comp_ADC
);
1292 -- Case of record or array component: check storage order compatibility.
1293 -- But, if the record has Complex_Representation, then it is treated as
1294 -- a scalar in the back end so the storage order is irrelevant.
1296 if (Is_Record_Type
(Comp_Base
)
1297 and then not Has_Complex_Representation
(Comp_Base
))
1298 or else Is_Array_Type
(Comp_Base
)
1301 Reverse_Storage_Order
(Encl_Base
) /=
1302 Reverse_Storage_Order
(Comp_Base
);
1304 -- Parent and extension must have same storage order
1306 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1307 if Comp_SSO_Differs
then
1309 ("record extension must have same scalar storage order as "
1310 & "parent", Err_Node
);
1313 -- If component and composite SSO differs, check that component
1314 -- falls on byte boundaries and isn't bit packed.
1316 elsif Comp_SSO_Differs
then
1318 -- Component SSO differs from enclosing composite:
1320 -- Reject if composite is a bit-packed array, as it is rewritten
1321 -- into an array of scalars.
1323 if Is_Bit_Packed_Array
(Encl_Base
) then
1325 ("type of packed array must have same scalar storage order "
1326 & "as component", Err_Node
);
1328 -- Reject if not byte aligned
1330 elsif Is_Record_Type
(Encl_Base
)
1331 and then not Comp_Byte_Aligned
1333 if Present
(Component_Clause
(Comp
)) then
1335 ("type of non-byte-aligned component must have same scalar"
1336 & " storage order as enclosing record", Err_Node
);
1339 ("type of packed component must have same scalar"
1340 & " storage order as enclosing record", Err_Node
);
1343 -- Warn if specified only for the outer composite
1345 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1347 ("scalar storage order specified for & does not apply to "
1348 & "component?", Err_Node
, Encl_Base
);
1352 -- Enclosing type has explicit SSO: non-composite component must not
1355 elsif Present
(ADC
) and then Component_Aliased
then
1357 ("aliased component not permitted for type with explicit "
1358 & "Scalar_Storage_Order", Err_Node
);
1360 end Check_Component_Storage_Order
;
1362 -----------------------------
1363 -- Check_Debug_Info_Needed --
1364 -----------------------------
1366 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1368 if Debug_Info_Off
(T
) then
1371 elsif Comes_From_Source
(T
)
1372 or else Debug_Generated_Code
1373 or else Debug_Flag_VV
1374 or else Needs_Debug_Info
(T
)
1376 Set_Debug_Info_Needed
(T
);
1378 end Check_Debug_Info_Needed
;
1380 -------------------------------
1381 -- Check_Expression_Function --
1382 -------------------------------
1384 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1385 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1386 -- Function to search for deferred constant
1392 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1394 -- When a constant is initialized with the result of a dispatching
1395 -- call, the constant declaration is rewritten as a renaming of the
1396 -- displaced function result. This scenario is not a premature use of
1397 -- a constant even though the Has_Completion flag is not set.
1399 if Is_Entity_Name
(Nod
)
1400 and then Present
(Entity
(Nod
))
1401 and then Ekind
(Entity
(Nod
)) = E_Constant
1402 and then Scope
(Entity
(Nod
)) = Current_Scope
1403 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1404 N_Object_Declaration
1405 and then not Is_Imported
(Entity
(Nod
))
1406 and then not Has_Completion
(Entity
(Nod
))
1407 and then not (Present
(Full_View
(Entity
(Nod
)))
1408 and then Has_Completion
(Full_View
(Entity
(Nod
))))
1411 ("premature use of& in call or instance", N
, Entity
(Nod
));
1413 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1414 Analyze
(Prefix
(Nod
));
1416 if Is_Entity_Name
(Prefix
(Nod
))
1417 and then Is_Type
(Entity
(Prefix
(Nod
)))
1419 if Expander_Active
then
1420 Check_Fully_Declared
(Entity
(Prefix
(Nod
)), N
);
1423 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1430 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1436 -- Start of processing for Check_Expression_Function
1439 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1441 -- The subprogram body created for the expression function is not
1442 -- itself a freeze point.
1444 if Scope
(Nam
) = Current_Scope
1445 and then Nkind
(Decl
) = N_Expression_Function
1446 and then Nkind
(N
) /= N_Subprogram_Body
1448 Check_Deferred
(Expression
(Decl
));
1450 end Check_Expression_Function
;
1452 --------------------------------
1453 -- Check_Inherited_Conditions --
1454 --------------------------------
1456 procedure Check_Inherited_Conditions
1458 Late_Overriding
: Boolean := False)
1460 Prim_Ops
: constant Elist_Id
:= Primitive_Operations
(R
);
1463 Par_Prim
: Entity_Id
;
1466 type Wrapper_Kind
is (No_Wrapper
, LSP_Wrapper
, Postcond_Wrapper
);
1468 Wrapper_Needed
: Wrapper_Kind
;
1469 -- Kind of wrapper needed by a given inherited primitive of tagged
1471 -- * No_Wrapper: No wrapper is needed.
1472 -- * LSP_Wrapper: Wrapper that handles inherited class-wide pre/post
1473 -- conditions that call overridden primitives.
1474 -- * Postcond_Wrapper: Wrapper that handles postconditions of interface
1477 function Build_DTW_Body
1480 DTW_Decls
: List_Id
;
1481 Par_Prim
: Entity_Id
;
1482 Wrapped_Subp
: Entity_Id
) return Node_Id
;
1483 -- Build the body of the dispatch table wrapper containing the given
1484 -- spec and declarations; the call to the wrapped subprogram includes
1485 -- the proper type conversion.
1487 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
;
1488 -- Build the spec of the dispatch table wrapper
1490 procedure Build_Inherited_Condition_Pragmas
1492 LSP_Wrapper_Needed
: out Boolean);
1493 -- Build corresponding pragmas for an operation whose ancestor has
1494 -- class-wide pre/postconditions. If the operation is inherited then
1495 -- Wrapper_Needed is returned True to force the creation of a wrapper
1496 -- for the inherited operation. If the ancestor is being overridden,
1497 -- the pragmas are constructed only to verify their legality, in case
1498 -- they contain calls to other primitives that may have been overridden.
1500 procedure Check_Interface_Primitives_Strub_Mode
;
1501 -- Called when R is an interface type to check strub mode compatibility
1502 -- all its primitives.
1504 function Needs_Wrapper
1505 (Class_Cond
: Node_Id
;
1507 Par_Subp
: Entity_Id
) return Boolean;
1508 -- Checks whether the dispatch-table wrapper (DTW) for Subp must be
1509 -- built to evaluate the given class-wide condition.
1511 --------------------
1512 -- Build_DTW_Body --
1513 --------------------
1515 function Build_DTW_Body
1518 DTW_Decls
: List_Id
;
1519 Par_Prim
: Entity_Id
;
1520 Wrapped_Subp
: Entity_Id
) return Node_Id
1522 Actuals
: constant List_Id
:= Empty_List
;
1524 Formal
: Entity_Id
:= First_Formal
(Par_Prim
);
1525 New_F_Spec
: Entity_Id
:= First
(Parameter_Specifications
(DTW_Spec
));
1526 New_Formal
: Entity_Id
;
1529 -- Build parameter association for call to wrapped subprogram
1531 while Present
(Formal
) loop
1532 New_Formal
:= Defining_Identifier
(New_F_Spec
);
1534 -- If the controlling argument is inherited, add conversion to
1535 -- parent type for the call.
1537 if Is_Controlling_Formal
(Formal
) then
1539 Make_Type_Conversion
(Loc
,
1540 New_Occurrence_Of
(Etype
(Formal
), Loc
),
1541 New_Occurrence_Of
(New_Formal
, Loc
)));
1543 Append_To
(Actuals
, New_Occurrence_Of
(New_Formal
, Loc
));
1546 Next_Formal
(Formal
);
1550 if Ekind
(Wrapped_Subp
) = E_Procedure
then
1552 Make_Procedure_Call_Statement
(Loc
,
1553 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1554 Parameter_Associations
=> Actuals
);
1557 Make_Simple_Return_Statement
(Loc
,
1559 Make_Function_Call
(Loc
,
1560 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1561 Parameter_Associations
=> Actuals
));
1565 Make_Subprogram_Body
(Loc
,
1566 Specification
=> Copy_Subprogram_Spec
(DTW_Spec
),
1567 Declarations
=> DTW_Decls
,
1568 Handled_Statement_Sequence
=>
1569 Make_Handled_Sequence_Of_Statements
(Loc
,
1570 Statements
=> New_List
(Call
),
1571 End_Label
=> Make_Identifier
(Loc
,
1572 Chars
(Defining_Entity
(DTW_Spec
)))));
1575 --------------------
1576 -- Build_DTW_Spec --
1577 --------------------
1579 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
is
1584 DTW_Spec
:= Build_Overriding_Spec
(Par_Prim
, R
);
1585 DTW_Id
:= Defining_Entity
(DTW_Spec
);
1587 -- Clear the not-overriding indicator since the DTW wrapper overrides
1588 -- its wrapped subprogram; required because if present in the parent
1589 -- primitive, given that Build_Overriding_Spec inherits it, we report
1592 Set_Must_Not_Override
(DTW_Spec
, False);
1594 -- Add minimal decoration of fields
1596 Mutate_Ekind
(DTW_Id
, Ekind
(Par_Prim
));
1597 Set_Is_Dispatch_Table_Wrapper
(DTW_Id
);
1598 Set_Is_Wrapper
(DTW_Id
);
1600 -- The DTW wrapper is never a null procedure
1602 if Nkind
(DTW_Spec
) = N_Procedure_Specification
then
1603 Set_Null_Present
(DTW_Spec
, False);
1609 ---------------------------------------
1610 -- Build_Inherited_Condition_Pragmas --
1611 ---------------------------------------
1613 procedure Build_Inherited_Condition_Pragmas
1615 LSP_Wrapper_Needed
: out Boolean)
1617 Class_Pre
: constant Node_Id
:=
1618 Class_Preconditions
(Ultimate_Alias
(Subp
));
1619 Class_Post
: Node_Id
:= Class_Postconditions
(Par_Prim
);
1624 LSP_Wrapper_Needed
:= False;
1626 if No
(Class_Pre
) and then No
(Class_Post
) then
1630 -- For class-wide preconditions we just evaluate whether the wrapper
1631 -- is needed; there is no need to build the pragma since the check
1632 -- is performed on the caller side.
1634 if Present
(Class_Pre
)
1635 and then Needs_Wrapper
(Class_Pre
, Subp
, Par_Prim
)
1637 LSP_Wrapper_Needed
:= True;
1640 -- For class-wide postconditions we evaluate whether the wrapper is
1641 -- needed and we build the class-wide postcondition pragma to install
1642 -- it in the wrapper.
1644 if Present
(Class_Post
)
1645 and then Needs_Wrapper
(Class_Post
, Subp
, Par_Prim
)
1647 LSP_Wrapper_Needed
:= True;
1649 -- Update the class-wide postcondition
1651 Class_Post
:= New_Copy_Tree
(Class_Post
);
1652 Build_Class_Wide_Expression
1653 (Pragma_Or_Expr
=> Class_Post
,
1655 Par_Subp
=> Par_Prim
,
1656 Adjust_Sloc
=> False);
1658 -- Install the updated class-wide postcondition in a copy of the
1659 -- pragma postcondition defined for the nearest ancestor.
1661 A_Post
:= Get_Class_Wide_Pragma
(Par_Prim
,
1662 Pragma_Postcondition
);
1666 Subps
: constant Subprogram_List
:=
1667 Inherited_Subprograms
(Subp
);
1669 for Index
in Subps
'Range loop
1670 A_Post
:= Get_Class_Wide_Pragma
(Subps
(Index
),
1671 Pragma_Postcondition
);
1672 exit when Present
(A_Post
);
1677 -- A_Post can be null here if the postcondition was inlined in the
1678 -- called subprogram.
1680 if Present
(A_Post
) then
1681 New_Prag
:= New_Copy_Tree
(A_Post
);
1683 (Expression
(First
(Pragma_Argument_Associations
(New_Prag
))),
1685 Append
(New_Prag
, Decls
);
1688 end Build_Inherited_Condition_Pragmas
;
1690 -------------------------------------------
1691 -- Check_Interface_Primitives_Strub_Mode --
1692 -------------------------------------------
1694 procedure Check_Interface_Primitives_Strub_Mode
is
1696 Iface_Elmt
: Elmt_Id
;
1698 Iface_Prim
: Entity_Id
;
1699 Ifaces_List
: Elist_Id
;
1702 Prim_Iface
: Entity_Id
;
1705 pragma Assert
(Is_Interface
(R
));
1707 -- Collect interfaces extended by interface type R
1709 Collect_Interfaces
(R
, Ifaces_List
);
1711 Op_Node
:= First_Elmt
(Prim_Ops
);
1712 while Present
(Op_Node
) loop
1713 Prim
:= Node
(Op_Node
);
1715 Par_Prim
:= Overridden_Operation
(Prim
);
1717 -- We only need to check entities defined in the sources
1719 -- Check that overrider and overridden primitives have the same
1722 if Present
(Par_Prim
) then
1723 Check_Same_Strub_Mode
(Prim
, Par_Prim
);
1725 -- No need to check internally added predefined primitives since
1726 -- they all have the same strub mode.
1728 elsif Is_Predefined_Dispatching_Operation
(Prim
)
1729 and then not Comes_From_Source
(Prim
)
1733 -- Check strub mode of matching primitives of all the interface
1734 -- types, since several interface types may define primitives with
1735 -- the same profile that will be implemented by a single primitive
1736 -- of tagged types implementing R, and therefore must have the
1740 -- If this interface primitive has been inherited this is an
1741 -- internal entity we rely on its renamed entity (which is the
1742 -- entity defined in the sources).
1744 if Present
(Alias
(Prim
)) then
1745 Prim
:= Ultimate_Alias
(Prim
);
1746 Prim_Iface
:= Find_Dispatching_Type
(Prim
);
1749 -- Search for primitives conformant with this one in the other
1752 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1753 while Present
(Iface_Elmt
) loop
1754 Iface
:= Node
(Iface_Elmt
);
1756 if Iface
/= Prim_Iface
then
1757 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1758 while Present
(Elmt
) loop
1759 Iface_Prim
:= Node
(Elmt
);
1761 if Chars
(Iface_Prim
) = Chars
(Prim
)
1762 and then Comes_From_Source
(Iface_Prim
)
1763 and then Is_Interface_Conformant
1764 (Prim_Iface
, Iface_Prim
, Prim
)
1766 -- Check the strub mode passing the original
1767 -- primitive (instead of its alias); required
1768 -- to report the error at the right location.
1770 Check_Same_Strub_Mode
(Node
(Op_Node
), Iface_Prim
);
1777 Next_Elmt
(Iface_Elmt
);
1781 Next_Elmt
(Op_Node
);
1783 end Check_Interface_Primitives_Strub_Mode
;
1789 function Needs_Wrapper
1790 (Class_Cond
: Node_Id
;
1792 Par_Subp
: Entity_Id
) return Boolean
1794 Result
: Boolean := False;
1796 function Check_Entity
(N
: Node_Id
) return Traverse_Result
;
1797 -- Check calls to overridden primitives
1799 --------------------
1800 -- Replace_Entity --
1801 --------------------
1803 function Check_Entity
(N
: Node_Id
) return Traverse_Result
is
1807 if Nkind
(N
) = N_Identifier
1808 and then Present
(Entity
(N
))
1810 (Is_Formal
(Entity
(N
)) or else Is_Subprogram
(Entity
(N
)))
1812 (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1813 or else Attribute_Name
(Parent
(N
)) /= Name_Class
)
1815 -- Determine whether entity has a renaming
1817 New_E
:= Get_Mapped_Entity
(Entity
(N
));
1819 -- If the entity is an overridden primitive and we are not
1820 -- in GNATprove mode, we must build a wrapper for the current
1821 -- inherited operation. If the reference is the prefix of an
1822 -- attribute such as 'Result (or others ???) there is no need
1823 -- for a wrapper: the condition is just rewritten in terms of
1824 -- the inherited subprogram.
1827 and then Comes_From_Source
(New_E
)
1828 and then Is_Subprogram
(New_E
)
1829 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
1830 and then not GNATprove_Mode
1840 procedure Check_Condition_Entities
is
1841 new Traverse_Proc
(Check_Entity
);
1843 -- Start of processing for Needs_Wrapper
1846 Update_Primitives_Mapping
(Par_Subp
, Subp
);
1848 Map_Formals
(Par_Subp
, Subp
);
1849 Check_Condition_Entities
(Class_Cond
);
1854 Wrappers_List
: Elist_Id
:= No_Elist
;
1855 -- List containing identifiers of built wrappers. Used to defer building
1856 -- and analyzing their class-wide precondition subprograms.
1858 Postcond_Candidates_List
: Elist_Id
:= No_Elist
;
1859 -- List containing inherited primitives of tagged type R that implement
1860 -- interface primitives that have postconditions.
1862 -- Start of processing for Check_Inherited_Conditions
1865 if Late_Overriding
then
1866 Op_Node
:= First_Elmt
(Prim_Ops
);
1867 while Present
(Op_Node
) loop
1868 Prim
:= Node
(Op_Node
);
1870 -- Map the overridden primitive to the overriding one
1872 if Present
(Overridden_Operation
(Prim
))
1873 and then Comes_From_Source
(Prim
)
1875 Par_Prim
:= Overridden_Operation
(Prim
);
1876 Update_Primitives_Mapping
(Par_Prim
, Prim
);
1878 -- Force discarding previous mappings of its formals
1880 Map_Formals
(Par_Prim
, Prim
, Force_Update
=> True);
1883 Next_Elmt
(Op_Node
);
1887 -- For interface types we only need to check strub mode compatibility
1888 -- of their primitives (since they don't have wrappers).
1890 if Is_Interface
(R
) then
1891 Check_Interface_Primitives_Strub_Mode
;
1895 -- Perform validity checks on the inherited conditions of overriding
1896 -- operations, for conformance with LSP, and apply SPARK-specific
1897 -- restrictions on inherited conditions.
1899 Op_Node
:= First_Elmt
(Prim_Ops
);
1900 while Present
(Op_Node
) loop
1901 Prim
:= Node
(Op_Node
);
1902 Par_Prim
:= Overridden_Operation
(Prim
);
1904 if Present
(Par_Prim
)
1905 and then Comes_From_Source
(Prim
)
1907 -- When the primitive is an LSP wrapper we climb to the parent
1908 -- primitive that has the inherited contract.
1910 if Is_Wrapper
(Par_Prim
)
1911 and then Present
(LSP_Subprogram
(Par_Prim
))
1913 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
1916 -- Check that overrider and overridden operations have
1917 -- the same strub mode.
1919 Check_Same_Strub_Mode
(Prim
, Par_Prim
);
1921 -- Analyze the contract items of the overridden operation, before
1922 -- they are rewritten as pragmas.
1924 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1926 -- In GNATprove mode this is where we can collect the inherited
1927 -- conditions, because we do not create the Check pragmas that
1928 -- normally convey the modified class-wide conditions on
1929 -- overriding operations.
1931 if GNATprove_Mode
then
1932 Collect_Inherited_Class_Wide_Conditions
(Prim
);
1935 -- Check strub mode compatibility of primitives that implement
1936 -- interface primitives.
1938 elsif Present
(Interface_Alias
(Prim
)) then
1939 Check_Same_Strub_Mode
(Alias
(Prim
), Interface_Alias
(Prim
));
1942 Next_Elmt
(Op_Node
);
1945 -- Collect inherited primitives that may need a wrapper to handle
1946 -- postconditions of interface primitives; done to improve the
1947 -- performance when checking if postcondition wrappers are needed.
1949 Op_Node
:= First_Elmt
(Prim_Ops
);
1950 while Present
(Op_Node
) loop
1951 Prim
:= Node
(Op_Node
);
1953 if Present
(Interface_Alias
(Prim
))
1954 and then not Comes_From_Source
(Alias
(Prim
))
1955 and then Present
(Class_Postconditions
(Interface_Alias
(Prim
)))
1957 if No
(Postcond_Candidates_List
) then
1958 Postcond_Candidates_List
:= New_Elmt_List
;
1961 Append_Unique_Elmt
(Alias
(Prim
), Postcond_Candidates_List
);
1964 Next_Elmt
(Op_Node
);
1967 -- Now examine the inherited operations to check whether they require
1968 -- a wrapper to handle inherited conditions that call other primitives,
1969 -- so that LSP can be verified/enforced.
1971 Op_Node
:= First_Elmt
(Prim_Ops
);
1973 while Present
(Op_Node
) loop
1974 Decls
:= Empty_List
;
1975 Prim
:= Node
(Op_Node
);
1976 Wrapper_Needed
:= No_Wrapper
;
1978 -- Skip internal entities built for mapping interface primitives
1980 if not Comes_From_Source
(Prim
)
1981 and then Present
(Alias
(Prim
))
1982 and then No
(Interface_Alias
(Prim
))
1984 Par_Prim
:= Ultimate_Alias
(Prim
);
1986 -- When the primitive is an LSP wrapper we climb to the parent
1987 -- primitive that has the inherited contract.
1989 if Is_Wrapper
(Par_Prim
)
1990 and then Present
(LSP_Subprogram
(Par_Prim
))
1992 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
1995 -- Analyze the contract items of the parent operation, and
1996 -- determine whether this inherited primitive needs a LSP
1997 -- wrapper. This is determined when the condition is rewritten
1998 -- in sem_prag, using the mapping between overridden and
1999 -- overriding operations built in the loop above.
2002 LSP_Wrapper_Needed
: Boolean;
2005 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
2006 Build_Inherited_Condition_Pragmas
(Prim
, LSP_Wrapper_Needed
);
2008 if LSP_Wrapper_Needed
then
2009 Wrapper_Needed
:= LSP_Wrapper
;
2013 -- If the LSP wrapper is not needed but the tagged type R
2014 -- implements additional interface types, and this inherited
2015 -- primitive covers an interface primitive of these additional
2016 -- interface types that has class-wide postconditions, then it
2017 -- requires a postconditions wrapper.
2019 if Wrapper_Needed
= No_Wrapper
2020 and then Present
(Interfaces
(R
))
2021 and then Present
(Postcond_Candidates_List
)
2022 and then Contains
(Postcond_Candidates_List
, Prim
)
2028 Iface_Elmt
: Elmt_Id
;
2031 Elmt
:= First_Elmt
(Prim_Ops
);
2032 while Present
(Elmt
) loop
2035 -- Perform the search relying on the internal entities
2036 -- that link tagged type primitives with interface
2039 if Present
(Interface_Alias
(Ent
))
2040 and then (Alias
(Ent
)) = Prim
2042 Present
(Class_Postconditions
(Interface_Alias
(Ent
)))
2044 Iface
:= Find_Dispatching_Type
(Interface_Alias
(Ent
));
2046 -- We only need to locate primitives of additional
2047 -- interfaces implemented by tagged type R (since
2048 -- inherited primitives of parent types that cover
2049 -- primitives of inherited interface types don't
2052 Iface_Elmt
:= First_Elmt
(Interfaces
(R
));
2053 while Present
(Iface_Elmt
) loop
2054 if Node
(Iface_Elmt
) = Iface
then
2055 Wrapper_Needed
:= Postcond_Wrapper
;
2059 Next_Elmt
(Iface_Elmt
);
2069 if Wrapper_Needed
/= No_Wrapper
2070 and then not Is_Abstract_Subprogram
(Par_Prim
)
2071 and then Expander_Active
2073 -- Build the dispatch-table wrapper (DTW). The support for
2074 -- AI12-0195 relies on two kind of wrappers: one for indirect
2075 -- calls (also used for AI12-0220), and one for putting in the
2078 -- 1) "indirect-call wrapper" (ICW) is needed anytime there are
2079 -- class-wide preconditions. Prim'Access will point directly
2080 -- at the ICW if any, or at the "pristine" body if Prim has
2081 -- no class-wide preconditions.
2083 -- 2) "dispatch-table wrapper" (DTW) is needed anytime the class
2084 -- wide preconditions *or* the class-wide postconditions are
2085 -- affected by overriding.
2087 -- The DTW holds a single statement that is a single call where
2088 -- the controlling actuals are conversions to the corresponding
2089 -- type in the parent primitive. If the primitive is a function
2090 -- the statement is a return statement with a call.
2093 Alias_Id
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
2094 Loc
: constant Source_Ptr
:= Sloc
(R
);
2100 Prim_Next_E
: constant Entity_Id
:= Next_Entity
(Prim
);
2101 Prim_Prev_E
: constant Entity_Id
:= Prev_Entity
(Prim
);
2104 DTW_Spec
:= Build_DTW_Spec
(Par_Prim
);
2105 DTW_Id
:= Defining_Entity
(DTW_Spec
);
2106 DTW_Decl
:= Make_Subprogram_Declaration
(Loc
,
2107 Specification
=> DTW_Spec
);
2109 -- LSP wrappers reference the parent primitive that has the
2110 -- the class-wide pre/post condition that calls overridden
2113 if Wrapper_Needed
= LSP_Wrapper
then
2114 Set_LSP_Subprogram
(DTW_Id
, Par_Prim
);
2117 -- The spec of the wrapper has been built using the source
2118 -- location of its parent primitive; we must update it now
2119 -- (with the source location of the internal primitive built
2120 -- by Derive_Subprogram that will override this wrapper) to
2121 -- avoid inlining conflicts between internally built helpers
2122 -- for class-wide pre/postconditions of the parent and the
2123 -- helpers built for this wrapper.
2125 Set_Sloc
(DTW_Id
, Sloc
(Prim
));
2127 -- For inherited class-wide preconditions the DTW wrapper
2128 -- reuses the ICW of the parent (which checks the parent
2129 -- interpretation of the class-wide preconditions); the
2130 -- interpretation of the class-wide preconditions for the
2131 -- inherited subprogram is checked at the caller side.
2133 -- When the subprogram inherits class-wide postconditions
2134 -- the DTW also checks the interpretation of the class-wide
2135 -- postconditions for the inherited subprogram, and the body
2136 -- of the parent checks its interpretation of the parent for
2137 -- the class-wide postconditions.
2139 -- procedure Prim (F1 : T1; ...) is
2140 -- [ pragma Check (Postcondition, Expr); ]
2142 -- Par_Prim_ICW (Par_Type (F1), ...);
2145 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2147 Build_DTW_Body
(Loc
,
2148 DTW_Spec
=> DTW_Spec
,
2150 Par_Prim
=> Par_Prim
,
2151 Wrapped_Subp
=> Indirect_Call_Wrapper
(Par_Prim
));
2153 -- For subprograms that only inherit class-wide postconditions
2154 -- the DTW wrapper calls the parent primitive (which on its
2155 -- body checks the interpretation of the class-wide post-
2156 -- conditions for the parent subprogram), and the DTW checks
2157 -- the interpretation of the class-wide postconditions for the
2158 -- inherited subprogram.
2160 -- procedure Prim (F1 : T1; ...) is
2161 -- pragma Check (Postcondition, Expr);
2163 -- Par_Prim (Par_Type (F1), ...);
2168 Build_DTW_Body
(Loc
,
2169 DTW_Spec
=> DTW_Spec
,
2171 Par_Prim
=> Par_Prim
,
2172 Wrapped_Subp
=> Par_Prim
);
2175 -- Insert the declaration of the wrapper before the freezing
2176 -- node of the record type declaration to ensure that it will
2177 -- override the internal primitive built by Derive_Subprogram.
2179 if Late_Overriding
then
2180 Ensure_Freeze_Node
(R
);
2181 Insert_Before_And_Analyze
(Freeze_Node
(R
), DTW_Decl
);
2183 Append_Freeze_Action
(R
, DTW_Decl
);
2187 -- The analyis of DTW_Decl has removed Prim from its scope
2188 -- chain and added DTW_Id at the end of the scope chain. Move
2189 -- DTW_Id to its correct place in the scope chain: the analysis
2190 -- of the wrapper declaration has just added DTW_Id at the end
2191 -- of the list of entities of its scope. However, given that
2192 -- this wrapper overrides Prim, we must move DTW_Id to the
2193 -- original place of Prim in its scope chain. This is required
2194 -- for wrappers of private type primitives to ensure their
2195 -- correct visibility since wrappers are built when the full
2196 -- tagged type declaration is frozen (in the private part of
2197 -- the package) but they may override primitives defined in the
2198 -- public part of the package.
2201 DTW_Prev_E
: constant Entity_Id
:= Prev_Entity
(DTW_Id
);
2204 pragma Assert
(Last_Entity
(Current_Scope
) = DTW_Id
);
2206 (Ekind
(Current_Scope
) not in E_Package | E_Generic_Package
2207 or else No
(First_Private_Entity
(Current_Scope
))
2208 or else First_Private_Entity
(Current_Scope
) /= DTW_Id
);
2210 -- Remove DTW_Id from the end of the doubly-linked list of
2211 -- entities of this scope; no need to handle removing it
2212 -- from the beginning of the chain since such case can never
2213 -- occur for this entity.
2215 Set_Last_Entity
(Current_Scope
, DTW_Prev_E
);
2216 Set_Next_Entity
(DTW_Prev_E
, Empty
);
2218 -- Place DTW_Id back in the original place of its wrapped
2219 -- primitive in the list of entities of this scope.
2221 Link_Entities
(Prim_Prev_E
, DTW_Id
);
2222 Link_Entities
(DTW_Id
, Prim_Next_E
);
2225 -- Insert the body of the wrapper in the freeze actions of
2226 -- its record type declaration to ensure that it is placed
2227 -- in the scope of its declaration but not too early to cause
2228 -- premature freezing of other entities.
2230 Append_Freeze_Action
(R
, DTW_Body
);
2233 -- Ensure correct decoration
2235 pragma Assert
(Is_Dispatching_Operation
(DTW_Id
));
2236 pragma Assert
(Present
(Overridden_Operation
(DTW_Id
)));
2237 pragma Assert
(Overridden_Operation
(DTW_Id
) = Alias_Id
);
2239 -- Inherit dispatch table slot
2241 Set_DTC_Entity_Value
(R
, DTW_Id
);
2242 Set_DT_Position
(DTW_Id
, DT_Position
(Alias_Id
));
2244 -- Register the wrapper in the dispatch table
2247 and then not Building_Static_DT
(R
)
2249 Insert_List_After_And_Analyze
(Freeze_Node
(R
),
2250 Register_Primitive
(Loc
, DTW_Id
));
2253 -- Defer building helpers and ICW for the DTW. Required to
2254 -- ensure uniqueness in their names because when building
2255 -- these wrappers for overlapped subprograms their homonym
2256 -- number is not definite until all these dispatch table
2257 -- wrappers of tagged type R have been analyzed.
2259 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2260 Append_New_Elmt
(DTW_Id
, Wrappers_List
);
2265 Next_Elmt
(Op_Node
);
2268 -- Build and analyze deferred class-wide precondition subprograms of
2271 if Present
(Wrappers_List
) then
2274 CW_Subp
: Entity_Id
;
2280 Elmt
:= First_Elmt
(Wrappers_List
);
2282 while Present
(Elmt
) loop
2283 DTW_Id
:= Node
(Elmt
);
2286 Merge_Class_Conditions
(DTW_Id
);
2287 Make_Class_Precondition_Subps
(DTW_Id
, Late_Overriding
);
2289 CW_Subp
:= Static_Call_Helper
(DTW_Id
);
2290 Decl_N
:= Unit_Declaration_Node
(CW_Subp
);
2293 -- If the DTW was built for a late-overriding primitive
2294 -- its body must be analyzed now (since the tagged type
2295 -- is already frozen).
2297 if Late_Overriding
then
2299 Unit_Declaration_Node
(Corresponding_Body
(Decl_N
));
2305 end Check_Inherited_Conditions
;
2307 ----------------------------
2308 -- Check_Strict_Alignment --
2309 ----------------------------
2311 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
2315 -- Bit-packed array types do not require strict alignment, even if they
2316 -- are by-reference types, because they are accessed in a special way.
2318 if Is_By_Reference_Type
(E
) and then not Is_Bit_Packed_Array
(E
) then
2319 Set_Strict_Alignment
(E
);
2321 elsif Is_Array_Type
(E
) then
2322 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
2324 -- RM 13.2(7.1/4): Any component of a packed type that contains an
2325 -- aliased part shall be aligned according to the alignment of its
2328 -- Unfortunately this breaks Florist, which has had the bad habit
2329 -- of overaligning all the types it declares on 32-bit platforms,
2330 -- so make an exception if the component size is the storage unit.
2332 -- Other legacy codebases could also be affected because this was
2333 -- historically not enforced, so -gnatd_l can be used to disable it.
2335 if Has_Aliased_Components
(E
)
2336 and then not (Known_Component_Size
(E
)
2337 and then Component_Size
(E
) = System_Storage_Unit
)
2338 and then not Debug_Flag_Underscore_L
2340 Set_Strict_Alignment
(E
);
2343 elsif Is_Record_Type
(E
) then
2344 Comp
:= First_Component
(E
);
2345 while Present
(Comp
) loop
2346 if not Is_Type
(Comp
)
2347 and then (Is_Aliased
(Comp
)
2348 or else Strict_Alignment
(Etype
(Comp
)))
2350 Set_Strict_Alignment
(E
);
2354 Next_Component
(Comp
);
2357 end Check_Strict_Alignment
;
2359 -------------------------
2360 -- Check_Unsigned_Type --
2361 -------------------------
2363 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
2364 Ancestor
: Entity_Id
;
2369 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
2373 -- Do not attempt to analyze case where range was in error
2375 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
2379 -- The situation that is nontrivial is something like:
2381 -- subtype x1 is integer range -10 .. +10;
2382 -- subtype x2 is x1 range 0 .. V1;
2383 -- subtype x3 is x2 range V2 .. V3;
2384 -- subtype x4 is x3 range V4 .. V5;
2386 -- where Vn are variables. Here the base type is signed, but we still
2387 -- know that x4 is unsigned because of the lower bound of x2.
2389 -- The only way to deal with this is to look up the ancestor chain
2393 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
2397 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
2399 if Compile_Time_Known_Value
(Lo_Bound
) then
2400 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
2401 Set_Is_Unsigned_Type
(E
, True);
2407 Ancestor
:= Ancestor_Subtype
(Ancestor
);
2409 -- If no ancestor had a static lower bound, go to base type
2411 if No
(Ancestor
) then
2413 -- Note: the reason we still check for a compile time known
2414 -- value for the base type is that at least in the case of
2415 -- generic formals, we can have bounds that fail this test,
2416 -- and there may be other cases in error situations.
2418 Btyp
:= Base_Type
(E
);
2420 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
2424 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
2426 if Compile_Time_Known_Value
(Lo_Bound
)
2427 and then Expr_Rep_Value
(Lo_Bound
) >= 0
2429 Set_Is_Unsigned_Type
(E
, True);
2436 end Check_Unsigned_Type
;
2438 -----------------------------------------------
2439 -- Explode_Initialization_Compound_Statement --
2440 -----------------------------------------------
2442 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
2443 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
2446 if Present
(Init_Stmts
)
2447 and then Nkind
(Init_Stmts
) = N_Compound_Statement
2449 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
2451 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
2452 -- just removing it, because Freeze_All may rely on this particular
2453 -- Node_Id still being present in the enclosing list to know where to
2456 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
2458 Set_Initialization_Statements
(E
, Empty
);
2460 end Explode_Initialization_Compound_Statement
;
2466 -- Note: the easy coding for this procedure would be to just build a
2467 -- single list of freeze nodes and then insert them and analyze them
2468 -- all at once. This won't work, because the analysis of earlier freeze
2469 -- nodes may recursively freeze types which would otherwise appear later
2470 -- on in the freeze list. So we must analyze and expand the freeze nodes
2471 -- as they are generated.
2473 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
2474 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
2475 -- This is the internal recursive routine that does freezing of entities
2476 -- (but NOT the analysis of default expressions, which should not be
2477 -- recursive, we don't want to analyze those till we are sure that ALL
2478 -- the types are frozen).
2480 --------------------
2481 -- Freeze_All_Ent --
2482 --------------------
2484 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
2488 procedure Process_Flist
;
2489 -- If freeze nodes are present, insert and analyze, and reset cursor
2490 -- for next insertion.
2496 procedure Process_Flist
is
2499 if Is_Non_Empty_List
(Flist
) then
2500 Lastn
:= Next
(After
);
2501 Insert_List_After_And_Analyze
(After
, Flist
);
2503 if Present
(Lastn
) then
2504 After
:= Prev
(Lastn
);
2506 After
:= Last
(List_Containing
(After
));
2511 -- Start of processing for Freeze_All_Ent
2515 while Present
(E
) loop
2517 -- If the entity is an inner package which is not a package
2518 -- renaming, then its entities must be frozen at this point. Note
2519 -- that such entities do NOT get frozen at the end of the nested
2520 -- package itself (only library packages freeze).
2522 -- Same is true for task declarations, where anonymous records
2523 -- created for entry parameters must be frozen.
2525 if Ekind
(E
) = E_Package
2526 and then No
(Renamed_Entity
(E
))
2527 and then not Is_Child_Unit
(E
)
2528 and then not Is_Frozen
(E
)
2532 Install_Visible_Declarations
(E
);
2533 Install_Private_Declarations
(E
);
2534 Freeze_All
(First_Entity
(E
), After
);
2536 End_Package_Scope
(E
);
2538 if Is_Generic_Instance
(E
)
2539 and then Has_Delayed_Freeze
(E
)
2541 Set_Has_Delayed_Freeze
(E
, False);
2542 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
2545 elsif Ekind
(E
) in Task_Kind
2546 and then Nkind
(Parent
(E
)) in
2547 N_Single_Task_Declaration | N_Task_Type_Declaration
2550 Freeze_All
(First_Entity
(E
), After
);
2553 -- For a derived tagged type, we must ensure that all the
2554 -- primitive operations of the parent have been frozen, so that
2555 -- their addresses will be in the parent's dispatch table at the
2556 -- point it is inherited.
2558 elsif Ekind
(E
) = E_Record_Type
2559 and then Is_Tagged_Type
(E
)
2560 and then Is_Tagged_Type
(Etype
(E
))
2561 and then Is_Derived_Type
(E
)
2564 Prim_List
: constant Elist_Id
:=
2565 Primitive_Operations
(Etype
(E
));
2571 Prim
:= First_Elmt
(Prim_List
);
2572 while Present
(Prim
) loop
2573 Subp
:= Node
(Prim
);
2575 if Comes_From_Source
(Subp
)
2576 and then not Is_Frozen
(Subp
)
2578 Flist
:= Freeze_Entity
(Subp
, After
);
2587 if not Is_Frozen
(E
) then
2588 Flist
:= Freeze_Entity
(E
, After
);
2591 -- If already frozen, and there are delayed aspects, this is where
2592 -- we do the visibility check for these aspects (see Sem_Ch13 spec
2593 -- for a description of how we handle aspect visibility).
2595 elsif Has_Delayed_Aspects
(E
) then
2596 Check_Aspects_At_End_Of_Declarations
(E
);
2599 -- If an incomplete type is still not frozen, this may be a
2600 -- premature freezing because of a body declaration that follows.
2601 -- Indicate where the freezing took place. Freezing will happen
2602 -- if the body comes from source, but not if it is internally
2603 -- generated, for example as the body of a type invariant.
2605 -- If the freezing is caused by the end of the current declarative
2606 -- part, it is a Taft Amendment type, and there is no error.
2608 if not Is_Frozen
(E
)
2609 and then Ekind
(E
) = E_Incomplete_Type
2612 Bod
: constant Node_Id
:= Next
(After
);
2615 -- The presence of a body freezes all entities previously
2616 -- declared in the current list of declarations, but this
2617 -- does not apply if the body does not come from source.
2618 -- A type invariant is transformed into a subprogram body
2619 -- which is placed at the end of the private part of the
2620 -- current package, but this body does not freeze incomplete
2621 -- types that may be declared in this private part.
2623 if Comes_From_Source
(Bod
)
2624 and then Nkind
(Bod
) in N_Entry_Body
2631 In_Same_List
(After
, Parent
(E
))
2633 Error_Msg_Sloc
:= Sloc
(Next
(After
));
2635 ("type& is frozen# before its full declaration",
2651 -- Start of processing for Freeze_All
2654 Freeze_All_Ent
(From
, After
);
2656 -- Now that all types are frozen, we can deal with default expressions
2657 -- that require us to build a default expression functions. This is the
2658 -- point at which such functions are constructed (after all types that
2659 -- might be used in such expressions have been frozen).
2661 -- For subprograms that are renaming_as_body, we create the wrapper
2662 -- bodies as needed.
2664 -- We also add finalization chains to access types whose designated
2665 -- types are controlled. This is normally done when freezing the type,
2666 -- but this misses recursive type definitions where the later members
2667 -- of the recursion introduce controlled components.
2669 -- Loop through entities
2672 while Present
(E
) loop
2673 if Is_Subprogram
(E
) then
2674 if not Default_Expressions_Processed
(E
) then
2675 Process_Default_Expressions
(E
, After
);
2678 -- Check subprogram renamings for the same strub-mode.
2679 -- Avoid rechecking dispatching operations, that's taken
2680 -- care of in Check_Inherited_Conditions, that covers
2681 -- inherited interface operations.
2685 and then not Is_Dispatching_Operation
(E
)
2687 Check_Same_Strub_Mode
(E
, Item
);
2690 if not Has_Completion
(E
) then
2691 Decl
:= Unit_Declaration_Node
(E
);
2693 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
2694 if Error_Posted
(Decl
) then
2695 Set_Has_Completion
(E
);
2697 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
2700 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2701 and then Present
(Corresponding_Body
(Decl
))
2703 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
2704 N_Subprogram_Renaming_Declaration
2706 Build_And_Analyze_Renamed_Body
2707 (Decl
, Corresponding_Body
(Decl
), After
);
2711 -- Freeze the default expressions of entries, entry families, and
2712 -- protected subprograms.
2714 elsif Is_Concurrent_Type
(E
) then
2715 Item
:= First_Entity
(E
);
2716 while Present
(Item
) loop
2717 if Is_Subprogram_Or_Entry
(Item
)
2718 and then not Default_Expressions_Processed
(Item
)
2720 Process_Default_Expressions
(Item
, After
);
2727 -- Historical note: We used to create a finalization collection for
2728 -- access types whose designated type is not controlled, but contains
2729 -- private controlled compoments. This form of postprocessing is no
2730 -- longer needed because the finalization collection is now created
2731 -- when the access type is frozen (see Exp_Ch3.Freeze_Type).
2737 -----------------------
2738 -- Freeze_And_Append --
2739 -----------------------
2741 procedure Freeze_And_Append
2744 Result
: in out List_Id
)
2746 -- Freezing an Expression_Function does not freeze its profile:
2747 -- the formals will have been frozen otherwise before the E_F
2750 L
: constant List_Id
:=
2752 (Ent
, N
, Do_Freeze_Profile
=> not Is_Expression_Function
(Ent
));
2754 if Is_Non_Empty_List
(L
) then
2755 if Result
= No_List
then
2758 Append_List
(L
, Result
);
2761 end Freeze_And_Append
;
2767 procedure Freeze_Before
2770 Do_Freeze_Profile
: Boolean := True)
2772 -- Freeze T, then insert the generated Freeze nodes before the node N.
2773 -- Flag Freeze_Profile is used when T is an overloadable entity, and
2774 -- indicates whether its profile should be frozen at the same time.
2776 Freeze_Nodes
: constant List_Id
:=
2777 Freeze_Entity
(T
, N
, Do_Freeze_Profile
);
2778 Pack
: constant Entity_Id
:= Scope
(T
);
2781 if Ekind
(T
) = E_Function
then
2782 Check_Expression_Function
(N
, T
);
2785 if Is_Non_Empty_List
(Freeze_Nodes
) then
2787 -- If the entity is a type declared in an inner package, it may be
2788 -- frozen by an outer declaration before the package itself is
2789 -- frozen. Install the package scope to analyze the freeze nodes,
2790 -- which may include generated subprograms such as predicate
2793 if Is_Type
(T
) and then From_Nested_Package
(T
) then
2795 Install_Visible_Declarations
(Pack
);
2796 Install_Private_Declarations
(Pack
);
2797 Insert_Actions
(N
, Freeze_Nodes
);
2798 End_Package_Scope
(Pack
);
2801 Insert_Actions
(N
, Freeze_Nodes
);
2810 -- WARNING: This routine manages Ghost regions. Return statements must be
2811 -- replaced by gotos which jump to the end of the routine and restore the
2814 function Freeze_Entity
2817 Do_Freeze_Profile
: Boolean := True) return List_Id
2819 Loc
: constant Source_Ptr
:= Sloc
(N
);
2821 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2822 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
2823 -- Save the Ghost-related attributes to restore on exit
2831 Result
: List_Id
:= No_List
;
2832 -- List of freezing actions, left at No_List if none
2834 Test_E
: Entity_Id
:= E
;
2835 -- A local temporary used to test if freezing is necessary for E, since
2836 -- its value can be set to something other than E in certain cases. For
2837 -- example, E cannot be used directly in cases such as when it is an
2838 -- Itype defined within a record - since it is the location of record
2841 procedure Add_To_Result
(Fnod
: Node_Id
);
2842 -- Add freeze action Fnod to list Result
2844 function After_Last_Declaration
return Boolean;
2845 -- If Loc is a freeze_entity that appears after the last declaration
2846 -- in the scope, inhibit error messages on late completion.
2848 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
2849 -- Check that an Access or Unchecked_Access attribute with a prefix
2850 -- which is the current instance type can only be applied when the type
2853 procedure Check_No_Parts_Violations
2854 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
) with
2855 Pre
=> Aspect_No_Parts
in
2856 Aspect_No_Controlled_Parts | Aspect_No_Task_Parts
;
2857 -- Check that Typ does not violate the semantics of the specified
2858 -- Aspect_No_Parts (No_Controlled_Parts or No_Task_Parts) when it is
2859 -- specified on Typ or one of its ancestors.
2861 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
);
2862 -- Give a warning for pragma Convention with language C or C++ applied
2863 -- to a discriminated record type. This is suppressed for the unchecked
2864 -- union case, since the whole point in this case is interface C. We
2865 -- also do not generate this within instantiations, since we will have
2866 -- generated a message on the template.
2868 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
2869 -- Give warning for modulus of 8, 16, 32, 64 or 128 given as an explicit
2870 -- integer literal without an explicit corresponding size clause. The
2871 -- caller has checked that Utype is a modular integer type.
2873 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
2874 -- Freeze array type, including freezing index and component types
2876 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
2877 -- Perform checks and generate freeze node if needed for a constant or
2878 -- variable declared by an object declaration.
2880 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
2881 -- Create Freeze_Generic_Entity nodes for types declared in a generic
2882 -- package. Recurse on inner generic packages.
2884 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
2885 -- Freeze formals and return type of subprogram. If some type in the
2886 -- profile is incomplete and we are in an instance, freezing of the
2887 -- entity will take place elsewhere, and the function returns False.
2889 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
2890 -- Freeze record type, including freezing component types, and freezing
2891 -- primitive operations if this is a tagged type.
2893 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
2894 -- Determine whether an arbitrary entity is subject to Boolean aspect
2895 -- Import and its value is specified as True.
2897 procedure Inherit_Freeze_Node
2900 -- Set type Typ's freeze node to refer to Fnode. This routine ensures
2901 -- that any attributes attached to Typ's original node are preserved.
2903 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
2904 -- If E is an entity for an imported subprogram with pre/post-conditions
2905 -- then this procedure will create a wrapper to ensure that proper run-
2906 -- time checking of the pre/postconditions. See body for details.
2912 procedure Add_To_Result
(Fnod
: Node_Id
) is
2914 Append_New_To
(Result
, Fnod
);
2917 ----------------------------
2918 -- After_Last_Declaration --
2919 ----------------------------
2921 function After_Last_Declaration
return Boolean is
2922 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2925 if Nkind
(Spec
) = N_Package_Specification
then
2926 if Present
(Private_Declarations
(Spec
)) then
2927 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2928 elsif Present
(Visible_Declarations
(Spec
)) then
2929 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2937 end After_Last_Declaration
;
2939 ----------------------------
2940 -- Check_Current_Instance --
2941 ----------------------------
2943 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2945 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2946 -- Determine whether Typ is compatible with the rules for aliased
2947 -- views of types as defined in RM 3.10 in the various dialects.
2949 function Process
(N
: Node_Id
) return Traverse_Result
;
2950 -- Process routine to apply check to given node
2952 -----------------------------
2953 -- Is_Aliased_View_Of_Type --
2954 -----------------------------
2956 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
2957 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
2962 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
2963 and then Limited_Present
(Type_Definition
(Typ_Decl
))
2967 -- The following paragraphs describe what a legal aliased view of
2968 -- a type is in the various dialects of Ada.
2972 -- The current instance of a limited type, and a formal parameter
2973 -- or generic formal object of a tagged type.
2975 -- Ada 95 limited type
2976 -- * Type with reserved word "limited"
2977 -- * A protected or task type
2978 -- * A composite type with limited component
2980 elsif Ada_Version
<= Ada_95
then
2981 return Is_Limited_Type
(Typ
);
2985 -- The current instance of a limited tagged type, a protected
2986 -- type, a task type, or a type that has the reserved word
2987 -- "limited" in its full definition ... a formal parameter or
2988 -- generic formal object of a tagged type.
2990 -- Ada 2005 limited type
2991 -- * Type with reserved word "limited", "synchronized", "task"
2993 -- * A composite type with limited component
2994 -- * A derived type whose parent is a non-interface limited type
2996 elsif Ada_Version
= Ada_2005
then
2998 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
3000 (Is_Derived_Type
(Typ
)
3001 and then not Is_Interface
(Etype
(Typ
))
3002 and then Is_Limited_Type
(Etype
(Typ
)));
3004 -- Ada 2012 and beyond
3006 -- The current instance of an immutably limited type ... a formal
3007 -- parameter or generic formal object of a tagged type.
3009 -- Ada 2012 limited type
3010 -- * Type with reserved word "limited", "synchronized", "task"
3012 -- * A composite type with limited component
3013 -- * A derived type whose parent is a non-interface limited type
3014 -- * An incomplete view
3016 -- Ada 2012 immutably limited type
3017 -- * Explicitly limited record type
3018 -- * Record extension with "limited" present
3019 -- * Non-formal limited private type that is either tagged
3020 -- or has at least one access discriminant with a default
3022 -- * Task type, protected type or synchronized interface
3023 -- * Type derived from immutably limited type
3027 Is_Immutably_Limited_Type
(Typ
)
3028 or else Is_Incomplete_Type
(Typ
);
3030 end Is_Aliased_View_Of_Type
;
3036 function Process
(N
: Node_Id
) return Traverse_Result
is
3039 when N_Attribute_Reference
=>
3040 if Attribute_Name
(N
) in Name_Access | Name_Unchecked_Access
3041 and then Is_Entity_Name
(Prefix
(N
))
3042 and then Entity
(Prefix
(N
)) = E
3044 if Ada_Version
< Ada_2012
then
3046 ("current instance must be a limited type",
3050 ("current instance must be an immutably limited "
3051 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
3065 procedure Traverse
is new Traverse_Proc
(Process
);
3069 Rec_Type
: constant Entity_Id
:=
3070 Scope
(Defining_Identifier
(Comp_Decl
));
3072 -- Start of processing for Check_Current_Instance
3075 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
3076 Traverse
(Comp_Decl
);
3078 end Check_Current_Instance
;
3080 -------------------------------
3081 -- Check_No_Parts_Violations --
3082 -------------------------------
3084 procedure Check_No_Parts_Violations
3085 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
)
3088 function Find_Aspect_No_Parts
3089 (Typ
: Entity_Id
) return Node_Id
;
3090 -- Search for Aspect_No_Parts on a given type. When
3091 -- the aspect is not explicity specified Empty is returned.
3093 function Get_Aspect_No_Parts_Value
3094 (Typ
: Entity_Id
) return Entity_Id
;
3095 -- Obtain the value for the Aspect_No_Parts on a given
3096 -- type. When the aspect is not explicitly specified Empty is
3099 function Has_Aspect_No_Parts
3100 (Typ
: Entity_Id
) return Boolean;
3101 -- Predicate function which identifies whether No_Parts
3102 -- is explicitly specified on a given type.
3104 -------------------------------------
3105 -- Find_Aspect_No_Parts --
3106 -------------------------------------
3108 function Find_Aspect_No_Parts
3109 (Typ
: Entity_Id
) return Node_Id
3111 Partial_View
: constant Entity_Id
:=
3112 Incomplete_Or_Partial_View
(Typ
);
3114 Aspect_Spec
: Entity_Id
:=
3115 Find_Aspect
(Typ
, Aspect_No_Parts
);
3116 Curr_Aspect_Spec
: Entity_Id
;
3118 -- Examine Typ's associated node, when present, since aspect
3119 -- specifications do not get transferred when nodes get rewritten.
3121 -- For example, this can happen in the expansion of array types
3124 and then Present
(Associated_Node_For_Itype
(Typ
))
3125 and then Nkind
(Associated_Node_For_Itype
(Typ
))
3126 = N_Full_Type_Declaration
3130 (Id
=> Defining_Identifier
3131 (Associated_Node_For_Itype
(Typ
)),
3132 A
=> Aspect_No_Parts
);
3135 -- Examine aspects specifications on private type declarations
3137 -- Should Find_Aspect be improved to handle this case ???
3140 and then Present
(Partial_View
)
3142 (Aspect_Specifications
3148 (Aspect_Specifications
3152 -- Search through aspects present on the private type
3154 while Present
(Curr_Aspect_Spec
) loop
3155 if Get_Aspect_Id
(Curr_Aspect_Spec
) = Aspect_No_Parts
then
3156 Aspect_Spec
:= Curr_Aspect_Spec
;
3160 Next
(Curr_Aspect_Spec
);
3165 -- When errors are posted on the aspect return Empty
3167 if Error_Posted
(Aspect_Spec
) then
3172 end Find_Aspect_No_Parts
;
3174 ------------------------------------------
3175 -- Get_Aspect_No_Parts_Value --
3176 ------------------------------------------
3178 function Get_Aspect_No_Parts_Value
3179 (Typ
: Entity_Id
) return Entity_Id
3181 Aspect_Spec
: constant Entity_Id
:=
3182 Find_Aspect_No_Parts
(Typ
);
3184 -- Return the value of the aspect when present
3186 if Present
(Aspect_Spec
) then
3188 -- No expression is the same as True
3190 if No
(Expression
(Aspect_Spec
)) then
3191 return Standard_True
;
3194 -- Assume its expression has already been constant folded into
3195 -- a Boolean value and return its value.
3197 return Entity
(Expression
(Aspect_Spec
));
3200 -- Otherwise, the aspect is not specified - so return Empty
3203 end Get_Aspect_No_Parts_Value
;
3205 ------------------------------------
3206 -- Has_Aspect_No_Parts --
3207 ------------------------------------
3209 function Has_Aspect_No_Parts
3210 (Typ
: Entity_Id
) return Boolean
3211 is (Present
(Find_Aspect_No_Parts
(Typ
)));
3213 -- Generic instances
3215 -------------------------------------------
3216 -- Get_Generic_Formal_Types_In_Hierarchy --
3217 -------------------------------------------
3219 function Get_Generic_Formal_Types_In_Hierarchy
3220 is new Collect_Types_In_Hierarchy
(Predicate
=> Is_Generic_Formal
);
3221 -- Return a list of all types within a given type's hierarchy which
3222 -- are generic formals.
3224 ----------------------------------------
3225 -- Get_Types_With_Aspect_In_Hierarchy --
3226 ----------------------------------------
3228 function Get_Types_With_Aspect_In_Hierarchy
3229 is new Collect_Types_In_Hierarchy
3230 (Predicate
=> Has_Aspect_No_Parts
);
3231 -- Returns a list of all types within a given type's hierarchy which
3232 -- have the Aspect_No_Parts specified.
3234 -- Local declarations
3236 Aspect_Value
: Entity_Id
;
3237 Curr_Value
: Entity_Id
;
3238 Curr_Typ_Elmt
: Elmt_Id
;
3239 Curr_Body_Elmt
: Elmt_Id
;
3240 Curr_Formal_Elmt
: Elmt_Id
;
3241 Gen_Bodies
: Elist_Id
;
3242 Gen_Formals
: Elist_Id
;
3244 Types_With_Aspect
: Elist_Id
;
3246 -- Start of processing for Check_No_Parts_Violations
3249 -- Nothing to check if the type is elementary or artificial
3251 if Is_Elementary_Type
(Typ
) or else not Comes_From_Source
(Typ
) then
3255 Types_With_Aspect
:= Get_Types_With_Aspect_In_Hierarchy
(Typ
);
3257 -- Nothing to check if there are no types with No_Parts specified
3259 if Is_Empty_Elmt_List
(Types_With_Aspect
) then
3263 -- Set name for all errors below
3265 Error_Msg_Name_1
:= Aspect_Names
(Aspect_No_Parts
);
3267 -- Obtain the aspect value for No_Parts for comparison
3270 Get_Aspect_No_Parts_Value
3271 (Node
(First_Elmt
(Types_With_Aspect
)));
3273 -- When the value is True and there are controlled/task parts or the
3274 -- type itself is controlled/task, trigger the appropriate error.
3276 if Aspect_Value
= Standard_True
then
3277 if Aspect_No_Parts
= Aspect_No_Controlled_Parts
then
3278 if Is_Controlled
(Typ
) or else Has_Controlled_Component
(Typ
)
3281 ("aspect % applied to controlled type &", Typ
);
3284 elsif Aspect_No_Parts
= Aspect_No_Task_Parts
then
3285 if Has_Task
(Typ
) then
3287 ("aspect % applied to task type &", Typ
);
3289 ("\replace task components with access-to-task-type "
3290 & "components", Typ
);
3294 raise Program_Error
;
3298 -- Move through Types_With_Aspect - checking that the value specified
3299 -- for their corresponding Aspect_No_Parts do not override each
3302 Curr_Typ_Elmt
:= First_Elmt
(Types_With_Aspect
);
3303 while Present
(Curr_Typ_Elmt
) loop
3305 Get_Aspect_No_Parts_Value
(Node
(Curr_Typ_Elmt
));
3307 -- Compare the aspect value against the current type
3309 if Curr_Value
/= Aspect_Value
then
3311 ("cannot override aspect % of "
3312 & "ancestor type &", Typ
, Node
(Curr_Typ_Elmt
));
3316 Next_Elmt
(Curr_Typ_Elmt
);
3319 -- Issue an error if the aspect applies to a type declared inside a
3320 -- generic body and if said type derives from or has a component
3321 -- of ageneric formal type - since those are considered to have
3322 -- controlled/task parts and have Aspect_No_Parts specified as
3323 -- False by default (RM H.4.1(4/5) is about the language-defined
3324 -- No_Controlled_Parts aspect, and we are using the same rules for
3327 -- We do not check tagged types since deriving from a formal type
3328 -- within an enclosing generic unit is already illegal
3329 -- (RM 3.9.1 (4/2)).
3331 if Aspect_Value
= Standard_True
3332 and then In_Generic_Body
(Typ
)
3333 and then not Is_Tagged_Type
(Typ
)
3335 Gen_Bodies
:= New_Elmt_List
;
3337 Get_Generic_Formal_Types_In_Hierarchy
3339 Examine_Components
=> True);
3341 -- Climb scopes collecting generic bodies
3343 Scop
:= Scope
(Typ
);
3344 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
3346 -- Generic package body
3348 if Ekind
(Scop
) = E_Generic_Package
3349 and then In_Package_Body
(Scop
)
3351 Append_Elmt
(Scop
, Gen_Bodies
);
3353 -- Generic subprogram body
3355 elsif Is_Generic_Subprogram
(Scop
) then
3356 Append_Elmt
(Scop
, Gen_Bodies
);
3359 Scop
:= Scope
(Scop
);
3362 -- Warn about the improper use of Aspect_No_Parts on a type
3363 -- declaration deriving from or that has a component of a generic
3364 -- formal type within the formal type's corresponding generic
3365 -- body by moving through all formal types in Typ's hierarchy and
3366 -- checking if they are formals in any of the enclosing generic
3369 -- However, a special exception gets made for formal types which
3370 -- derive from a type which has Aspect_No_Parts True.
3375 -- type Form is private;
3377 -- type Type_A is new Form with No_Controlled_Parts; -- OK
3380 -- package body G is
3381 -- type Type_B is new Form with No_Controlled_Parts; -- ERROR
3385 -- type Form is private;
3387 -- type Type_A is record C : Form; end record
3388 -- with No_Controlled_Parts; -- OK
3391 -- package body G is
3392 -- type Type_B is record C : Form; end record
3393 -- with No_Controlled_Parts; -- ERROR
3396 -- type Root is tagged null record with No_Controlled_Parts;
3399 -- type Form is new Root with private;
3401 -- type Type_A is record C : Form; end record
3402 -- with No_Controlled_Parts; -- OK
3405 -- package body G is
3406 -- type Type_B is record C : Form; end record
3407 -- with No_Controlled_Parts; -- OK
3410 Curr_Formal_Elmt
:= First_Elmt
(Gen_Formals
);
3411 while Present
(Curr_Formal_Elmt
) loop
3413 Curr_Body_Elmt
:= First_Elmt
(Gen_Bodies
);
3414 while Present
(Curr_Body_Elmt
) loop
3416 -- Obtain types in the formal type's hierarchy which have
3417 -- the aspect specified.
3419 Types_With_Aspect
:=
3420 Get_Types_With_Aspect_In_Hierarchy
3421 (Node
(Curr_Formal_Elmt
));
3423 -- We found a type declaration in a generic body where both
3424 -- Aspect_No_Parts is true and one of its ancestors is a
3425 -- generic formal type.
3427 if Scope
(Node
(Curr_Formal_Elmt
)) =
3428 Node
(Curr_Body_Elmt
)
3430 -- Check that no ancestors of the formal type have
3431 -- Aspect_No_Parts True before issuing the error.
3433 and then (Is_Empty_Elmt_List
(Types_With_Aspect
)
3435 Get_Aspect_No_Parts_Value
3436 (Node
(First_Elmt
(Types_With_Aspect
)))
3439 Error_Msg_Node_1
:= Typ
;
3440 Error_Msg_Node_2
:= Node
(Curr_Formal_Elmt
);
3442 ("aspect % cannot be applied to "
3443 & "type & which has an ancestor or component of "
3444 & "formal type & within the formal type's "
3445 & "corresponding generic body", Sloc
(Typ
));
3448 Next_Elmt
(Curr_Body_Elmt
);
3451 Next_Elmt
(Curr_Formal_Elmt
);
3454 end Check_No_Parts_Violations
;
3456 ---------------------------------
3457 -- Check_Suspicious_Convention --
3458 ---------------------------------
3460 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
) is
3462 if Has_Discriminants
(Rec_Type
)
3463 and then Is_Base_Type
(Rec_Type
)
3464 and then not Is_Unchecked_Union
(Rec_Type
)
3465 and then (Convention
(Rec_Type
) = Convention_C
3467 Convention
(Rec_Type
) = Convention_CPP
)
3468 and then Comes_From_Source
(Rec_Type
)
3469 and then not In_Instance
3470 and then not Has_Warnings_Off
(Rec_Type
)
3473 Cprag
: constant Node_Id
:=
3474 Get_Rep_Pragma
(Rec_Type
, Name_Convention
);
3478 if Present
(Cprag
) then
3479 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3481 if Convention
(Rec_Type
) = Convention_C
then
3483 ("?x?discriminated record has no direct equivalent in "
3487 ("?x?discriminated record has no direct equivalent in "
3492 ("\?x?use of convention for type& is dubious",
3497 end Check_Suspicious_Convention
;
3499 ------------------------------
3500 -- Check_Suspicious_Modulus --
3501 ------------------------------
3503 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
3504 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
3507 if not Warn_On_Suspicious_Modulus_Value
then
3511 if Nkind
(Decl
) = N_Full_Type_Declaration
then
3513 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
3516 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
3518 Modulus
: constant Node_Id
:=
3519 Original_Node
(Expression
(Tdef
));
3522 if Nkind
(Modulus
) = N_Integer_Literal
then
3524 Modv
: constant Uint
:= Intval
(Modulus
);
3525 Sizv
: constant Uint
:= RM_Size
(Utype
);
3528 -- First case, modulus and size are the same. This
3529 -- happens if you have something like mod 32, with
3530 -- an explicit size of 32, this is for sure a case
3531 -- where the warning is given, since it is seems
3532 -- very unlikely that someone would want e.g. a
3533 -- five bit type stored in 32 bits. It is much
3534 -- more likely they wanted a 32-bit type.
3539 -- Second case, the modulus is 32 or 64 and no
3540 -- size clause is present. This is a less clear
3541 -- case for giving the warning, but in the case
3542 -- of 32/64 (5-bit or 6-bit types) these seem rare
3543 -- enough that it is a likely error (and in any
3544 -- case using 2**5 or 2**6 in these cases seems
3545 -- clearer. We don't include 8 or 16 here, simply
3546 -- because in practice 3-bit and 4-bit types are
3547 -- more common and too many false positives if
3548 -- we warn in these cases.
3550 elsif not Has_Size_Clause
(Utype
)
3551 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
3555 -- No warning needed
3561 -- If we fall through, give warning
3563 Error_Msg_Uint_1
:= Modv
;
3565 ("?.m?2 '*'*^' may have been intended here",
3573 end Check_Suspicious_Modulus
;
3575 -----------------------
3576 -- Freeze_Array_Type --
3577 -----------------------
3579 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
3580 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
3581 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
3584 -- Set to Component_Size clause or Atomic pragma, if any
3586 Non_Standard_Enum
: Boolean := False;
3587 -- Set true if any of the index types is an enumeration type with a
3588 -- non-standard representation.
3591 Freeze_And_Append
(Ctyp
, N
, Result
);
3593 Indx
:= First_Index
(Arr
);
3594 while Present
(Indx
) loop
3595 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
3597 if Is_Enumeration_Type
(Etype
(Indx
))
3598 and then Has_Non_Standard_Rep
(Etype
(Indx
))
3600 Non_Standard_Enum
:= True;
3606 -- Processing that is done only for base types
3608 if Ekind
(Arr
) = E_Array_Type
then
3610 -- Deal with default setting of reverse storage order
3612 Set_SSO_From_Default
(Arr
);
3614 -- Propagate flags from component type
3616 Propagate_Concurrent_Flags
(Arr
, Ctyp
);
3617 Propagate_Controlled_Flags
(Arr
, Ctyp
, Comp
=> True);
3619 if Has_Unchecked_Union
(Ctyp
) then
3620 Set_Has_Unchecked_Union
(Arr
);
3623 -- The array type requires its own invariant procedure in order to
3624 -- verify the component invariant over all elements. In GNATprove
3625 -- mode, the component invariants are checked by other means. They
3626 -- should not be added to the array type invariant procedure, so
3627 -- that the procedure can be used to check the array type
3628 -- invariants if any.
3630 if Has_Invariants
(Ctyp
)
3631 and then not GNATprove_Mode
3633 Set_Has_Own_Invariants
(Arr
);
3636 -- Warn for pragma Pack overriding foreign convention
3638 if Has_Foreign_Convention
(Ctyp
)
3639 and then Has_Pragma_Pack
(Arr
)
3642 CN
: constant Name_Id
:=
3643 Get_Convention_Name
(Convention
(Ctyp
));
3644 PP
: constant Node_Id
:=
3645 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
3647 if Present
(PP
) then
3648 Error_Msg_Name_1
:= CN
;
3649 Error_Msg_Sloc
:= Sloc
(Arr
);
3651 ("pragma Pack affects convention % components #??", PP
);
3652 Error_Msg_Name_1
:= CN
;
3654 ("\array components may not have % compatible "
3655 & "representation??", PP
);
3660 -- Check for Aliased or Atomic or Full Access or Independent
3661 -- components with an unsuitable component size clause given.
3662 -- The main purpose is to give an error when bit packing would
3663 -- be required to honor the component size, because bit packing
3664 -- is incompatible with these aspects; when bit packing is not
3665 -- required, the final validation of the component size may be
3666 -- left to the back end.
3668 if Has_Component_Size_Clause
(Arr
) then
3670 procedure Complain_CS
(T
: String; Min
: Boolean := False);
3671 -- Output an error message for an unsuitable component size
3672 -- clause for independent components (T is either "aliased"
3673 -- or "atomic" or "volatile full access" or "independent").
3679 procedure Complain_CS
(T
: String; Min
: Boolean := False) is
3682 Get_Attribute_Definition_Clause
3683 (FS
, Attribute_Component_Size
);
3686 ("incorrect component size for " & T
& " components",
3689 if Known_Static_Esize
(Ctyp
) then
3690 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3692 Error_Msg_N
("\minimum allowed value is^", Clause
);
3694 Error_Msg_N
("\only allowed value is^", Clause
);
3698 ("\must be multiple of storage unit", Clause
);
3702 -- Start of processing for CS_Check
3705 -- OK if the component size and object size are equal, or
3706 -- if the component size is a multiple of the storage unit.
3708 if (if Known_Static_Esize
(Ctyp
)
3709 then Component_Size
(Arr
) = Esize
(Ctyp
)
3710 else Component_Size
(Arr
) mod System_Storage_Unit
= 0)
3714 elsif Has_Aliased_Components
(Arr
) then
3715 Complain_CS
("aliased");
3717 elsif Has_Atomic_Components
(Arr
)
3718 or else Is_Atomic
(Ctyp
)
3720 Complain_CS
("atomic");
3722 elsif Is_Volatile_Full_Access
(Ctyp
) then
3723 Complain_CS
("volatile full access");
3725 -- For Independent a larger size is permitted
3727 elsif (Has_Independent_Components
(Arr
)
3728 or else Is_Independent
(Ctyp
))
3729 and then (not Known_Static_Esize
(Ctyp
)
3730 or else Component_Size
(Arr
) < Esize
(Ctyp
))
3732 Complain_CS
("independent", Min
=> True);
3736 -- Check for Aliased or Atomic or Full Access or Independent
3737 -- components with an unsuitable aspect/pragma Pack given.
3738 -- The main purpose is to prevent bit packing from occurring,
3739 -- because bit packing is incompatible with these aspects; when
3740 -- bit packing cannot occur, the final handling of the packing
3741 -- may be left to the back end.
3743 elsif Is_Packed
(Arr
) and then Known_Static_RM_Size
(Ctyp
) then
3744 Pack_Check
: declare
3746 procedure Complain_Pack
(T
: String);
3747 -- Output a warning message for an unsuitable aspect/pragma
3748 -- Pack for independent components (T is either "aliased" or
3749 -- "atomic" or "volatile full access" or "independent") and
3750 -- reset the Is_Packed flag on the array type.
3756 procedure Complain_Pack
(T
: String) is
3759 ("?cannot pack " & T
& " components (RM 13.2(7))",
3760 Get_Rep_Pragma
(FS
, Name_Pack
));
3762 Set_Is_Packed
(Arr
, False);
3765 -- Start of processing for Pack_Check
3768 -- OK if the component size and object size are equal, or
3769 -- if the component size is a multiple of the storage unit.
3771 if (if Known_Static_Esize
(Ctyp
)
3772 then RM_Size
(Ctyp
) = Esize
(Ctyp
)
3773 else RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
3777 elsif Has_Aliased_Components
(Arr
) then
3778 Complain_Pack
("aliased");
3780 elsif Has_Atomic_Components
(Arr
)
3781 or else Is_Atomic
(Ctyp
)
3783 Complain_Pack
("atomic");
3785 elsif Is_Volatile_Full_Access
(Ctyp
) then
3786 Complain_Pack
("volatile full access");
3788 elsif Has_Independent_Components
(Arr
)
3789 or else Is_Independent
(Ctyp
)
3791 Complain_Pack
("independent");
3796 -- If packing was requested or if the component size was
3797 -- set explicitly, then see if bit packing is required. This
3798 -- processing is only done for base types, since all of the
3799 -- representation aspects involved are type-related.
3801 -- This is not just an optimization, if we start processing the
3802 -- subtypes, they interfere with the settings on the base type
3803 -- (this is because Is_Packed has a slightly different meaning
3804 -- before and after freezing).
3812 and then Known_Static_RM_Size
(Ctyp
)
3813 and then not Has_Component_Size_Clause
(Arr
)
3815 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
3817 elsif Known_Component_Size
(Arr
) then
3818 Csiz
:= Component_Size
(Arr
);
3820 elsif not Known_Static_Esize
(Ctyp
) then
3824 Esiz
:= Esize
(Ctyp
);
3826 -- We can set the component size if it is less than 16,
3827 -- rounding it up to the next storage unit size.
3831 elsif Esiz
<= 16 then
3837 -- Set component size up to match alignment if it would
3838 -- otherwise be less than the alignment. This deals with
3839 -- cases of types whose alignment exceeds their size (the
3840 -- padded type cases).
3842 if Csiz
/= 0 and then Known_Alignment
(Ctyp
) then
3844 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
3853 -- Case of component size that may result in bit packing
3855 if 1 <= Csiz
and then Csiz
<= System_Max_Integer_Size
then
3857 Ent
: constant Entity_Id
:=
3858 First_Subtype
(Arr
);
3859 Pack_Pragma
: constant Node_Id
:=
3860 Get_Rep_Pragma
(Ent
, Name_Pack
);
3861 Comp_Size_C
: constant Node_Id
:=
3862 Get_Attribute_Definition_Clause
3863 (Ent
, Attribute_Component_Size
);
3866 -- Warn if we have pack and component size so that the
3869 -- Note: here we must check for the presence of a
3870 -- component size before checking for a Pack pragma to
3871 -- deal with the case where the array type is a derived
3872 -- type whose parent is currently private.
3874 if Present
(Comp_Size_C
)
3875 and then Has_Pragma_Pack
(Ent
)
3876 and then Warn_On_Redundant_Constructs
3878 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
3880 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
3882 ("\?r?explicit component size given#!", Pack_Pragma
);
3883 Set_Is_Packed
(Base_Type
(Ent
), False);
3884 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
3887 -- Set component size if not already set by a component
3890 if No
(Comp_Size_C
) then
3891 Set_Component_Size
(Arr
, Csiz
);
3894 -- Check for base type of 8, 16, 32 bits, where an
3895 -- unsigned subtype has a length one less than the
3896 -- base type (e.g. Natural subtype of Integer).
3898 -- In such cases, if a component size was not set
3899 -- explicitly, then generate a warning.
3901 if Has_Pragma_Pack
(Arr
)
3902 and then No
(Comp_Size_C
)
3903 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
3904 and then Known_Esize
(Base_Type
(Ctyp
))
3905 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
3907 Error_Msg_Uint_1
:= Csiz
;
3909 if Present
(Pack_Pragma
) then
3911 ("??pragma Pack causes component size to be ^!",
3914 ("\??use Component_Size to set desired value!",
3919 -- Bit packing is never needed for 8, 16, 32, 64 or 128
3921 if Addressable
(Csiz
) then
3923 -- If the Esize of the component is known and equal to
3924 -- the component size then even packing is not needed.
3926 if Known_Static_Esize
(Ctyp
)
3927 and then Esize
(Ctyp
) = Csiz
3929 -- Here the array was requested to be packed, but
3930 -- the packing request had no effect whatsoever,
3931 -- so flag Is_Packed is reset.
3933 -- Note: semantically this means that we lose track
3934 -- of the fact that a derived type inherited pragma
3935 -- Pack that was non-effective, but that is fine.
3937 -- We regard a Pack pragma as a request to set a
3938 -- representation characteristic, and this request
3941 Set_Is_Packed
(Base_Type
(Arr
), False);
3942 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
3944 Set_Is_Packed
(Base_Type
(Arr
), True);
3945 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3948 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3950 -- Bit packing is not needed for multiples of the storage
3951 -- unit if the type is composite because the back end can
3952 -- byte pack composite types efficiently. That's not true
3953 -- for discrete types because every read would generate a
3954 -- lot of instructions, so we keep using the manipulation
3955 -- routines of the runtime for them.
3957 elsif Csiz
mod System_Storage_Unit
= 0
3958 and then Is_Composite_Type
(Ctyp
)
3960 Set_Is_Packed
(Base_Type
(Arr
), True);
3961 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3962 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3964 -- In all other cases, bit packing is needed
3967 Set_Is_Packed
(Base_Type
(Arr
), True);
3968 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3969 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
3975 -- Warn for case of atomic type
3977 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
3980 and then not Addressable
(Component_Size
(FS
))
3983 ("non-atomic components of type& may not be "
3984 & "accessible by separate tasks??", Clause
, Arr
);
3986 if Has_Component_Size_Clause
(Arr
) then
3987 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
3988 (FS
, Attribute_Component_Size
));
3989 Error_Msg_N
("\because of component size clause#??", Clause
);
3991 elsif Has_Pragma_Pack
(Arr
) then
3992 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
3993 Error_Msg_N
("\because of pragma Pack#??", Clause
);
3997 -- Check for scalar storage order
4002 Check_Component_Storage_Order
4005 ADC
=> Get_Attribute_Definition_Clause
4006 (First_Subtype
(Arr
),
4007 Attribute_Scalar_Storage_Order
),
4008 Comp_ADC_Present
=> Dummy
);
4011 -- Processing that is done only for subtypes
4014 -- Acquire alignment from base type. Known_Alignment of the base
4015 -- type is False for Wide_String, for example.
4017 if not Known_Alignment
(Arr
)
4018 and then Known_Alignment
(Base_Type
(Arr
))
4020 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
4021 Adjust_Esize_Alignment
(Arr
);
4025 -- Specific checks for bit-packed arrays
4027 if Is_Bit_Packed_Array
(Arr
) then
4029 -- Check number of elements for bit-packed arrays that come from
4030 -- source and have compile time known ranges. The bit-packed
4031 -- arrays circuitry does not support arrays with more than
4032 -- Integer'Last + 1 elements, and when this restriction is
4033 -- violated, causes incorrect data access.
4035 -- For the case where this is not compile time known, a run-time
4036 -- check should be generated???
4038 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
4047 Index
:= First_Index
(Arr
);
4048 while Present
(Index
) loop
4049 Ityp
:= Etype
(Index
);
4051 -- Never generate an error if any index is of a generic
4052 -- type. We will check this in instances.
4054 if Is_Generic_Type
(Ityp
) then
4060 Make_Attribute_Reference
(Loc
,
4061 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
4062 Attribute_Name
=> Name_Range_Length
);
4063 Analyze_And_Resolve
(Ilen
);
4065 -- No attempt is made to check number of elements if not
4066 -- compile time known.
4068 if Nkind
(Ilen
) /= N_Integer_Literal
then
4073 Elmts
:= Elmts
* Intval
(Ilen
);
4077 if Elmts
> Intval
(High_Bound
4078 (Scalar_Range
(Standard_Integer
))) + 1
4081 ("bit packed array type may not have "
4082 & "more than Integer''Last+1 elements", Arr
);
4089 if Known_RM_Size
(Arr
) then
4091 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
4095 -- It is not clear if it is possible to have no size clause
4096 -- at this stage, but it is not worth worrying about. Post
4097 -- error on the entity name in the size clause if present,
4098 -- else on the type entity itself.
4100 if Present
(SizC
) then
4101 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
4103 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
4109 -- If any of the index types was an enumeration type with a non-
4110 -- standard rep clause, then we indicate that the array type is
4111 -- always packed (even if it is not bit-packed).
4113 if Non_Standard_Enum
then
4114 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
4115 Set_Is_Packed
(Base_Type
(Arr
));
4118 Set_Component_Alignment_If_Not_Set
(Arr
);
4120 -- If the array is packed and bit-packed or packed to eliminate holes
4121 -- in the non-contiguous enumeration index types, we must create the
4122 -- packed array type to be used to actually implement the type. This
4123 -- is only needed for real array types (not for string literal types,
4124 -- since they are present only for the front end).
4127 and then (Is_Bit_Packed_Array
(Arr
) or else Non_Standard_Enum
)
4128 and then Ekind
(Arr
) /= E_String_Literal_Subtype
4130 Create_Packed_Array_Impl_Type
(Arr
);
4131 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
4133 -- Make sure that we have the necessary routines to implement the
4134 -- packing, and complain now if not. Note that we only test this
4135 -- for constrained array types.
4137 if Is_Constrained
(Arr
)
4138 and then Is_Bit_Packed_Array
(Arr
)
4139 and then Present
(Packed_Array_Impl_Type
(Arr
))
4140 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
4143 CS
: constant Uint
:= Component_Size
(Arr
);
4144 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
4148 and then not RTE_Available
(RE
)
4151 ("packing of " & UI_Image
(CS
) & "-bit components",
4152 First_Subtype
(Etype
(Arr
)));
4154 -- Cancel the packing
4156 Set_Is_Packed
(Base_Type
(Arr
), False);
4157 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
4158 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
4164 -- Size information of packed array type is copied to the array
4165 -- type, since this is really the representation. But do not
4166 -- override explicit existing size values. If the ancestor subtype
4167 -- is constrained the Packed_Array_Impl_Type will be inherited
4168 -- from it, but the size may have been provided already, and
4169 -- must not be overridden either.
4171 if not Has_Size_Clause
(Arr
)
4173 (No
(Ancestor_Subtype
(Arr
))
4174 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
4176 Copy_Esize
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4177 Copy_RM_Size
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4180 if not Has_Alignment_Clause
(Arr
) then
4182 (To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4188 -- A Ghost type cannot have a component of protected or task type
4189 -- (SPARK RM 6.9(21)).
4191 if Is_Ghost_Entity
(Arr
) and then Is_Concurrent_Type
(Ctyp
) then
4193 ("ghost array type & cannot have concurrent component type",
4196 end Freeze_Array_Type
;
4198 -------------------------------
4199 -- Freeze_Object_Declaration --
4200 -------------------------------
4202 procedure Freeze_Object_Declaration
(E
: Entity_Id
) is
4203 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
);
4204 -- Check that the size of array type Typ can be computed without
4205 -- overflow, and generates a Storage_Error otherwise. This is only
4206 -- relevant for array types whose index is a modular type with
4207 -- Standard_Long_Long_Integer_Size bits: wrap-around arithmetic
4208 -- might yield a meaningless value for the length of the array,
4209 -- or its corresponding attribute.
4211 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
);
4212 -- Ensure that the initialization state of variable Var_Id subject
4213 -- to pragma Thread_Local_Storage agrees with the semantics of the
4216 function Has_Default_Initialization
4217 (Obj_Id
: Entity_Id
) return Boolean;
4218 -- Determine whether object Obj_Id default initialized
4220 -------------------------------
4221 -- Check_Large_Modular_Array --
4222 -------------------------------
4224 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
) is
4225 Obj_Loc
: constant Source_Ptr
:= Sloc
(E
);
4226 Idx_Typ
: Entity_Id
;
4229 -- Nothing to do when expansion is disabled because this routine
4230 -- generates a runtime check.
4232 if not Expander_Active
then
4235 -- Nothing to do for String literal subtypes because their index
4236 -- cannot be a modular type.
4238 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
4241 -- Nothing to do for an imported object because the object will
4242 -- be created on the exporting side.
4244 elsif Is_Imported
(E
) then
4247 -- Nothing to do for unconstrained array types. This case arises
4248 -- when the object declaration is illegal.
4250 elsif not Is_Constrained
(Typ
) then
4254 Idx_Typ
:= Etype
(First_Index
(Typ
));
4256 -- To prevent arithmetic overflow with large values, we raise
4257 -- Storage_Error under the following guard:
4259 -- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
4261 -- This takes care of the boundary case, but it is preferable to
4262 -- use a smaller limit, because even on 64-bit architectures an
4263 -- array of more than 2 ** 30 bytes is likely to raise
4266 if Is_Modular_Integer_Type
(Idx_Typ
)
4267 and then RM_Size
(Idx_Typ
) = Standard_Long_Long_Integer_Size
4269 -- Ensure that the type of the object is elaborated before
4270 -- the check itself is emitted to avoid elaboration issues
4271 -- in the code generator at the library level.
4273 if Is_Itype
(Etype
(E
))
4274 and then In_Open_Scopes
(Scope
(Etype
(E
)))
4277 Ref_Node
: constant Node_Id
:=
4278 Make_Itype_Reference
(Obj_Loc
);
4280 Set_Itype
(Ref_Node
, Etype
(E
));
4281 Insert_Action
(Declaration_Node
(E
), Ref_Node
);
4285 Insert_Action
(Declaration_Node
(E
),
4286 Make_Raise_Storage_Error
(Obj_Loc
,
4288 Make_Op_Ge
(Obj_Loc
,
4290 Make_Op_Subtract
(Obj_Loc
,
4292 Make_Op_Divide
(Obj_Loc
,
4294 Make_Attribute_Reference
(Obj_Loc
,
4296 New_Occurrence_Of
(Typ
, Obj_Loc
),
4297 Attribute_Name
=> Name_Last
),
4299 Make_Integer_Literal
(Obj_Loc
, Uint_2
)),
4301 Make_Op_Divide
(Obj_Loc
,
4303 Make_Attribute_Reference
(Obj_Loc
,
4305 New_Occurrence_Of
(Typ
, Obj_Loc
),
4306 Attribute_Name
=> Name_First
),
4308 Make_Integer_Literal
(Obj_Loc
, Uint_2
))),
4310 Make_Integer_Literal
(Obj_Loc
, (Uint_2
** 30))),
4311 Reason
=> SE_Object_Too_Large
));
4313 end Check_Large_Modular_Array
;
4315 ---------------------------------------
4316 -- Check_Pragma_Thread_Local_Storage --
4317 ---------------------------------------
4319 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
) is
4320 function Has_Incompatible_Initialization
4321 (Var_Decl
: Node_Id
) return Boolean;
4322 -- Determine whether variable Var_Id with declaration Var_Decl is
4323 -- initialized with a value that violates the semantics of pragma
4324 -- Thread_Local_Storage.
4326 -------------------------------------
4327 -- Has_Incompatible_Initialization --
4328 -------------------------------------
4330 function Has_Incompatible_Initialization
4331 (Var_Decl
: Node_Id
) return Boolean
4333 Init_Expr
: constant Node_Id
:= Expression
(Var_Decl
);
4336 -- The variable is default-initialized. This directly violates
4337 -- the semantics of the pragma.
4339 if Has_Default_Initialization
(Var_Id
) then
4342 -- The variable has explicit initialization. In this case only
4343 -- a handful of values satisfy the semantics of the pragma.
4345 elsif Has_Init_Expression
(Var_Decl
)
4346 and then Present
(Init_Expr
)
4348 -- "null" is a legal form of initialization
4350 if Nkind
(Init_Expr
) = N_Null
then
4353 -- A static expression is a legal form of initialization
4355 elsif Is_Static_Expression
(Init_Expr
) then
4358 -- A static aggregate is a legal form of initialization
4360 elsif Nkind
(Init_Expr
) = N_Aggregate
4361 and then Compile_Time_Known_Aggregate
(Init_Expr
)
4365 -- All other initialization expressions violate the semantic
4372 -- The variable lacks any kind of initialization, which agrees
4373 -- with the semantics of the pragma.
4378 end Has_Incompatible_Initialization
;
4380 -- Local declarations
4382 Var_Decl
: constant Node_Id
:= Declaration_Node
(Var_Id
);
4384 -- Start of processing for Check_Pragma_Thread_Local_Storage
4387 -- A variable whose initialization is suppressed lacks any kind of
4390 if Suppress_Initialization
(Var_Id
) then
4393 -- The variable has default initialization, or is explicitly
4394 -- initialized to a value other than null, static expression,
4395 -- or a static aggregate.
4397 elsif Has_Incompatible_Initialization
(Var_Decl
) then
4399 ("Thread_Local_Storage variable& is improperly initialized",
4402 ("\only allowed initialization is explicit NULL, static "
4403 & "expression or static aggregate", Var_Decl
, Var_Id
);
4405 end Check_Pragma_Thread_Local_Storage
;
4407 --------------------------------
4408 -- Has_Default_Initialization --
4409 --------------------------------
4411 function Has_Default_Initialization
4412 (Obj_Id
: Entity_Id
) return Boolean
4414 Obj_Decl
: constant Node_Id
:= Declaration_Node
(Obj_Id
);
4415 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
4419 Comes_From_Source
(Obj_Id
)
4420 and then not Is_Imported
(Obj_Id
)
4421 and then not Has_Init_Expression
(Obj_Decl
)
4423 ((Has_Non_Null_Base_Init_Proc
(Obj_Typ
)
4424 and then not No_Initialization
(Obj_Decl
)
4425 and then not Initialization_Suppressed
(Obj_Typ
))
4427 (Needs_Simple_Initialization
(Obj_Typ
)
4428 and then not Is_Internal
(Obj_Id
)));
4429 end Has_Default_Initialization
;
4433 Typ
: constant Entity_Id
:= Etype
(E
);
4436 -- Start of processing for Freeze_Object_Declaration
4439 -- Abstract type allowed only for C++ imported variables or constants
4441 -- Note: we inhibit this check for objects that do not come from
4442 -- source because there is at least one case (the expansion of
4443 -- x'Class'Input where x is abstract) where we legitimately
4444 -- generate an abstract object.
4446 if Is_Abstract_Type
(Typ
)
4447 and then Comes_From_Source
(Parent
(E
))
4448 and then not (Is_Imported
(E
) and then Is_CPP_Class
(Typ
))
4450 Def
:= Object_Definition
(Parent
(E
));
4452 Error_Msg_N
("type of object cannot be abstract", Def
);
4454 if Is_CPP_Class
(Etype
(E
)) then
4455 Error_Msg_NE
("\} may need a cpp_constructor", Def
, Typ
);
4457 elsif Present
(Expression
(Parent
(E
))) then
4458 Error_Msg_N
-- CODEFIX
4459 ("\maybe a class-wide type was meant", Def
);
4463 -- For object created by object declaration, perform required
4464 -- categorization (preelaborate and pure) checks. Defer these
4465 -- checks to freeze time since pragma Import inhibits default
4466 -- initialization and thus pragma Import affects these checks.
4468 Validate_Object_Declaration
(Declaration_Node
(E
));
4470 -- If there is an address clause, check that it is valid and if need
4471 -- be move initialization to the freeze node.
4473 Check_Address_Clause
(E
);
4475 -- Similar processing is needed for aspects that may affect object
4476 -- layout, like Address, if there is an initialization expression.
4477 -- We don't do this if there is a pragma Linker_Section, because it
4478 -- would prevent the back end from statically initializing the
4479 -- object; we don't want elaboration code in that case.
4481 if Has_Delayed_Aspects
(E
)
4482 and then Expander_Active
4483 and then Is_Array_Type
(Typ
)
4484 and then Present
(Expression
(Declaration_Node
(E
)))
4485 and then No
(Linker_Section_Pragma
(E
))
4488 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4489 Lhs
: constant Node_Id
:= New_Occurrence_Of
(E
, Loc
);
4492 -- Capture initialization value at point of declaration, and
4493 -- make explicit assignment legal, because object may be a
4496 Remove_Side_Effects
(Expression
(Decl
));
4497 Set_Assignment_OK
(Lhs
);
4499 -- Move initialization to freeze actions
4501 Append_Freeze_Action
(E
,
4502 Make_Assignment_Statement
(Loc
,
4504 Expression
=> Expression
(Decl
)));
4506 Set_No_Initialization
(Decl
);
4507 -- Set_Is_Frozen (E, False);
4511 -- Reset Is_True_Constant for non-constant aliased object. We
4512 -- consider that the fact that a non-constant object is aliased may
4513 -- indicate that some funny business is going on, e.g. an aliased
4514 -- object is passed by reference to a procedure which captures the
4515 -- address of the object, which is later used to assign a new value,
4516 -- even though the compiler thinks that it is not modified. Such
4517 -- code is highly dubious, but we choose to make it "work" for
4518 -- non-constant aliased objects.
4520 -- Note that we used to do this for all aliased objects, whether or
4521 -- not constant, but this caused anomalies down the line because we
4522 -- ended up with static objects that were not Is_True_Constant. Not
4523 -- resetting Is_True_Constant for (aliased) constant objects ensures
4524 -- that this anomaly never occurs.
4526 -- However, we don't do that for internal entities. We figure that if
4527 -- we deliberately set Is_True_Constant for an internal entity, e.g.
4528 -- a dispatch table entry, then we mean it.
4530 if Ekind
(E
) /= E_Constant
4531 and then (Is_Aliased
(E
) or else Is_Aliased
(Typ
))
4532 and then not Is_Internal_Name
(Chars
(E
))
4534 Set_Is_True_Constant
(E
, False);
4537 -- If the object needs any kind of default initialization, an error
4538 -- must be issued if No_Default_Initialization applies. The check
4539 -- doesn't apply to imported objects, which are not ever default
4540 -- initialized, and is why the check is deferred until freezing, at
4541 -- which point we know if Import applies. Deferred constants are also
4542 -- exempted from this test because their completion is explicit, or
4543 -- through an import pragma.
4545 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
4548 elsif Has_Default_Initialization
(E
) then
4550 (No_Default_Initialization
, Declaration_Node
(E
));
4553 -- Ensure that a variable subject to pragma Thread_Local_Storage
4555 -- * Lacks default initialization, or
4557 -- * The initialization expression is either "null", a static
4558 -- constant, or a compile-time known aggregate.
4560 if Has_Pragma_Thread_Local_Storage
(E
) then
4561 Check_Pragma_Thread_Local_Storage
(E
);
4564 -- For imported objects, set Is_Public unless there is also an
4565 -- address clause, which means that there is no external symbol
4566 -- needed for the Import (Is_Public may still be set for other
4567 -- unrelated reasons). Note that we delayed this processing
4568 -- till freeze time so that we can be sure not to set the flag
4569 -- if there is an address clause. If there is such a clause,
4570 -- then the only purpose of the Import pragma is to suppress
4571 -- implicit initialization.
4573 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4577 -- For source objects that are not Imported and are library level, if
4578 -- no linker section pragma was given inherit the appropriate linker
4579 -- section from the corresponding type.
4581 if Comes_From_Source
(E
)
4582 and then not Is_Imported
(E
)
4583 and then Is_Library_Level_Entity
(E
)
4584 and then No
(Linker_Section_Pragma
(E
))
4586 Set_Linker_Section_Pragma
(E
, Linker_Section_Pragma
(Typ
));
4589 -- For convention C objects of an enumeration type, warn if the size
4590 -- is not integer size and no explicit size given. Skip warning for
4591 -- Boolean and Character, and assume programmer expects 8-bit sizes
4594 if (Convention
(E
) = Convention_C
4596 Convention
(E
) = Convention_CPP
)
4597 and then Is_Enumeration_Type
(Typ
)
4598 and then not Is_Character_Type
(Typ
)
4599 and then not Is_Boolean_Type
(Typ
)
4600 and then Esize
(Typ
) < Standard_Integer_Size
4601 and then not Has_Size_Clause
(E
)
4603 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4605 ("??convention C enumeration object has size less than ^", E
);
4606 Error_Msg_N
("\??use explicit size clause to set size", E
);
4609 -- Declaring too big an array in disabled ghost code is OK
4611 if Is_Array_Type
(Typ
) and then not Is_Ignored_Ghost_Entity
(E
) then
4612 Check_Large_Modular_Array
(Typ
);
4614 end Freeze_Object_Declaration
;
4616 -----------------------------
4617 -- Freeze_Generic_Entities --
4618 -----------------------------
4620 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
4627 E
:= First_Entity
(Pack
);
4628 while Present
(E
) loop
4629 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
4630 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
4632 Append_To
(Flist
, F
);
4634 elsif Ekind
(E
) = E_Generic_Package
then
4635 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
4642 end Freeze_Generic_Entities
;
4644 --------------------
4645 -- Freeze_Profile --
4646 --------------------
4648 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
4651 Warn_Node
: Node_Id
;
4654 -- Loop through formals
4656 Formal
:= First_Formal
(E
);
4657 while Present
(Formal
) loop
4658 F_Type
:= Etype
(Formal
);
4660 -- AI05-0151: incomplete types can appear in a profile. By the
4661 -- time the entity is frozen, the full view must be available,
4662 -- unless it is a limited view.
4664 if Is_Incomplete_Type
(F_Type
)
4665 and then Present
(Full_View
(F_Type
))
4666 and then not From_Limited_With
(F_Type
)
4668 F_Type
:= Full_View
(F_Type
);
4669 Set_Etype
(Formal
, F_Type
);
4672 if not From_Limited_With
(F_Type
)
4673 and then Should_Freeze_Type
(F_Type
, E
, N
)
4675 Freeze_And_Append
(F_Type
, N
, Result
);
4678 if Is_Private_Type
(F_Type
)
4679 and then Is_Private_Type
(Base_Type
(F_Type
))
4680 and then No
(Full_View
(Base_Type
(F_Type
)))
4681 and then not Is_Generic_Type
(F_Type
)
4682 and then not Is_Derived_Type
(F_Type
)
4684 -- If the type of a formal is incomplete, subprogram is being
4685 -- frozen prematurely. Within an instance (but not within a
4686 -- wrapper package) this is an artifact of our need to regard
4687 -- the end of an instantiation as a freeze point. Otherwise it
4688 -- is a definite error.
4691 Set_Is_Frozen
(E
, False);
4695 elsif not After_Last_Declaration
then
4697 ("type & must be fully defined before this point",
4703 -- Check suspicious parameter for C function. These tests apply
4704 -- only to exported/imported subprograms.
4706 if Warn_On_Export_Import
4707 and then Comes_From_Source
(E
)
4708 and then Convention
(E
) in Convention_C_Family
4709 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4710 and then Convention
(E
) /= Convention
(Formal
)
4711 and then not Has_Warnings_Off
(E
)
4712 and then not Has_Warnings_Off
(F_Type
)
4713 and then not Has_Warnings_Off
(Formal
)
4715 -- Qualify mention of formals with subprogram name
4717 Error_Msg_Qual_Level
:= 1;
4719 -- Check suspicious use of fat C pointer, but do not emit
4720 -- a warning on an access to subprogram when unnesting is
4723 if Is_Access_Type
(F_Type
)
4724 and then Known_Esize
(F_Type
)
4725 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
4726 and then (not Unnest_Subprogram_Mode
4727 or else not Is_Access_Subprogram_Type
(F_Type
))
4730 ("?x?type of & does not correspond to C pointer!", Formal
);
4732 -- Check suspicious return of boolean
4734 elsif Root_Type
(F_Type
) = Standard_Boolean
4735 and then Convention
(F_Type
) = Convention_Ada
4736 and then not Has_Warnings_Off
(F_Type
)
4737 and then not Has_Size_Clause
(F_Type
)
4740 ("& is an 8-bit Ada Boolean?x?", Formal
);
4742 ("\use appropriate corresponding type in C "
4743 & "(e.g. char)?x?", Formal
);
4745 -- Check suspicious tagged type
4747 elsif (Is_Tagged_Type
(F_Type
)
4749 (Is_Access_Type
(F_Type
)
4750 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
4751 and then Convention
(E
) = Convention_C
4754 ("?x?& involves a tagged type which does not "
4755 & "correspond to any C type!", Formal
);
4757 -- Check wrong convention subprogram pointer
4759 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
4760 and then not Has_Foreign_Convention
(F_Type
)
4763 ("?x?subprogram pointer & should "
4764 & "have foreign convention!", Formal
);
4765 Error_Msg_Sloc
:= Sloc
(F_Type
);
4767 ("\?x?add Convention pragma to declaration of &#",
4771 -- Turn off name qualification after message output
4773 Error_Msg_Qual_Level
:= 0;
4776 -- Check for unconstrained array in exported foreign convention
4779 if Has_Foreign_Convention
(E
)
4780 and then not Is_Imported
(E
)
4781 and then Is_Array_Type
(F_Type
)
4782 and then not Is_Constrained
(F_Type
)
4783 and then Warn_On_Export_Import
4785 Error_Msg_Qual_Level
:= 1;
4787 -- If this is an inherited operation, place the warning on
4788 -- the derived type declaration, rather than on the original
4791 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
4793 Warn_Node
:= Parent
(E
);
4795 if Formal
= First_Formal
(E
) then
4796 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
4799 Warn_Node
:= Formal
;
4802 Error_Msg_NE
("?x?type of argument& is unconstrained array",
4804 Error_Msg_N
("\?x?foreign caller must pass bounds explicitly",
4806 Error_Msg_Qual_Level
:= 0;
4809 if not From_Limited_With
(F_Type
) then
4810 if Is_Access_Type
(F_Type
) then
4811 F_Type
:= Designated_Type
(F_Type
);
4815 Next_Formal
(Formal
);
4818 -- Case of function: similar checks on return type
4820 if Ekind
(E
) = E_Function
then
4822 -- Freeze return type
4824 R_Type
:= Etype
(E
);
4826 -- AI05-0151: the return type may have been incomplete at the
4827 -- point of declaration. Replace it with the full view, unless the
4828 -- current type is a limited view. In that case the full view is
4829 -- in a different unit, and gigi finds the non-limited view after
4830 -- the other unit is elaborated.
4832 if Ekind
(R_Type
) = E_Incomplete_Type
4833 and then Present
(Full_View
(R_Type
))
4834 and then not From_Limited_With
(R_Type
)
4836 R_Type
:= Full_View
(R_Type
);
4837 Set_Etype
(E
, R_Type
);
4840 if Should_Freeze_Type
(R_Type
, E
, N
) then
4841 Freeze_And_Append
(R_Type
, N
, Result
);
4844 -- Check suspicious return type for C function
4846 if Warn_On_Export_Import
4847 and then Comes_From_Source
(E
)
4848 and then Convention
(E
) in Convention_C_Family
4849 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4851 -- Check suspicious return of fat C pointer
4853 if Is_Access_Type
(R_Type
)
4854 and then Known_Esize
(R_Type
)
4855 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
4856 and then not Has_Warnings_Off
(E
)
4857 and then not Has_Warnings_Off
(R_Type
)
4860 ("?x?return type of& does not correspond to C pointer!",
4863 -- Check suspicious return of boolean
4865 elsif Root_Type
(R_Type
) = Standard_Boolean
4866 and then Convention
(R_Type
) = Convention_Ada
4867 and then not Has_Warnings_Off
(E
)
4868 and then not Has_Warnings_Off
(R_Type
)
4869 and then not Has_Size_Clause
(R_Type
)
4872 N
: constant Node_Id
:=
4873 Result_Definition
(Declaration_Node
(E
));
4876 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
4878 ("\use appropriate corresponding type in C "
4879 & "(e.g. char)?x?", N
, E
);
4882 -- Check suspicious return tagged type
4884 elsif (Is_Tagged_Type
(R_Type
)
4885 or else (Is_Access_Type
(R_Type
)
4888 (Designated_Type
(R_Type
))))
4889 and then Convention
(E
) = Convention_C
4890 and then not Has_Warnings_Off
(E
)
4891 and then not Has_Warnings_Off
(R_Type
)
4893 Error_Msg_N
("?x?return type of & does not "
4894 & "correspond to C type!", E
);
4896 -- Check return of wrong convention subprogram pointer
4898 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
4899 and then not Has_Foreign_Convention
(R_Type
)
4900 and then not Has_Warnings_Off
(E
)
4901 and then not Has_Warnings_Off
(R_Type
)
4903 Error_Msg_N
("?x?& should return a foreign "
4904 & "convention subprogram pointer", E
);
4905 Error_Msg_Sloc
:= Sloc
(R_Type
);
4907 ("\?x?add Convention pragma to declaration of& #",
4912 -- Give warning for suspicious return of a result of an
4913 -- unconstrained array type in a foreign convention function.
4915 if Has_Foreign_Convention
(E
)
4917 -- We are looking for a return of unconstrained array
4919 and then Is_Array_Type
(R_Type
)
4920 and then not Is_Constrained
(R_Type
)
4922 -- Exclude imported routines, the warning does not belong on
4923 -- the import, but rather on the routine definition.
4925 and then not Is_Imported
(E
)
4927 -- Check that general warning is enabled, and that it is not
4928 -- suppressed for this particular case.
4930 and then Warn_On_Export_Import
4931 and then not Has_Warnings_Off
(E
)
4932 and then not Has_Warnings_Off
(R_Type
)
4935 ("?x?foreign convention function& should not return "
4936 & "unconstrained array!", E
);
4940 -- Check suspicious use of Import in pure unit (cases where the RM
4941 -- allows calls to be omitted).
4945 -- It might be suspicious if the compilation unit has the Pure
4948 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
4950 -- The RM allows omission of calls only in the case of
4951 -- library-level subprograms (see RM-10.2.1(18)).
4953 and then Is_Library_Level_Entity
(E
)
4955 -- Ignore internally generated entity. This happens in some cases
4956 -- of subprograms in specs, where we generate an implied body.
4958 and then Comes_From_Source
(Import_Pragma
(E
))
4960 -- Assume run-time knows what it is doing
4962 and then not GNAT_Mode
4964 -- Assume explicit Pure_Function means import is pure
4966 and then not Has_Pragma_Pure_Function
(E
)
4968 -- Don't need warning in relaxed semantics mode
4970 and then not Relaxed_RM_Semantics
4972 -- Assume convention Intrinsic is OK, since this is specialized.
4973 -- This deals with the DEC unit current_exception.ads
4975 and then Convention
(E
) /= Convention_Intrinsic
4977 -- Assume that ASM interface knows what it is doing
4979 and then Convention
(E
) /= Convention_Assembler
4982 ("pragma Import in Pure unit??", Import_Pragma
(E
));
4984 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
4985 Import_Pragma
(E
), E
);
4991 ------------------------
4992 -- Freeze_Record_Type --
4993 ------------------------
4995 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
5002 pragma Warnings
(Off
, Junk
);
5004 Aliased_Component
: Boolean := False;
5005 -- Set True if we find at least one component which is aliased. This
5006 -- is used to prevent Implicit_Packing of the record, since packing
5007 -- cannot modify the size of alignment of an aliased component.
5009 All_Elem_Components
: Boolean := True;
5010 -- True if all components are of a type whose underlying type is
5013 All_Sized_Components
: Boolean := True;
5014 -- True if all components have a known RM_Size
5016 All_Storage_Unit_Components
: Boolean := True;
5017 -- True if all components have an RM_Size that is a multiple of the
5020 Elem_Component_Total_Esize
: Uint
:= Uint_0
;
5021 -- Accumulates total Esize values of all elementary components. Used
5022 -- for processing of Implicit_Packing.
5024 Final_Storage_Only
: Boolean := True;
5025 -- Used to compute the Finalize_Storage_Only flag
5027 Placed_Component
: Boolean := False;
5028 -- Set True if we find at least one component with a component
5029 -- clause (used to warn about useless Bit_Order pragmas, and also
5030 -- to detect cases where Implicit_Packing may have an effect).
5032 Relaxed_Finalization
: Boolean := True;
5033 -- Used to compute the Has_Relaxed_Finalization flag
5035 Sized_Component_Total_RM_Size
: Uint
:= Uint_0
;
5036 -- Accumulates total RM_Size values of all sized components. Used
5037 -- for processing of Implicit_Packing.
5039 Sized_Component_Total_Round_RM_Size
: Uint
:= Uint_0
;
5040 -- Accumulates total RM_Size values of all sized components, rounded
5041 -- individually to a multiple of the storage unit.
5044 -- Scalar_Storage_Order attribute definition clause for the record
5046 SSO_ADC_Component
: Boolean := False;
5047 -- Set True if we find at least one component whose type has a
5048 -- Scalar_Storage_Order attribute definition clause.
5050 Unplaced_Component
: Boolean := False;
5051 -- Set True if we find at least one component with no component
5052 -- clause (used to warn about useless Pack pragmas).
5054 procedure Check_Itype
(Typ
: Entity_Id
);
5055 -- If the component subtype is an access to a constrained subtype of
5056 -- an already frozen type, make the subtype frozen as well. It might
5057 -- otherwise be frozen in the wrong scope, and a freeze node on
5058 -- subtype has no effect. Similarly, if the component subtype is a
5059 -- regular (not protected) access to subprogram, set the anonymous
5060 -- subprogram type to frozen as well, to prevent an out-of-scope
5061 -- freeze node at some eventual point of call. Protected operations
5062 -- are handled elsewhere.
5064 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
5065 -- Make sure that all types mentioned in Discrete_Choices of the
5066 -- variants referenceed by the Variant_Part VP are frozen. This is
5067 -- a recursive routine to deal with nested variants.
5069 procedure Warn_If_Implicitly_Inherited_Aspects
(Tag_Typ
: Entity_Id
);
5070 -- Report a warning for Tag_Typ when it implicitly inherits the
5071 -- First_Controlling_Parameter aspect but does not explicitly
5078 procedure Check_Itype
(Typ
: Entity_Id
) is
5079 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
5082 if not Is_Frozen
(Desig
)
5083 and then Is_Frozen
(Base_Type
(Desig
))
5085 Set_Is_Frozen
(Desig
);
5087 -- In addition, add an Itype_Reference to ensure that the
5088 -- access subtype is elaborated early enough. This cannot be
5089 -- done if the subtype may depend on discriminants.
5091 if Ekind
(Comp
) = E_Component
5092 and then Is_Itype
(Etype
(Comp
))
5093 and then not Has_Discriminants
(Rec
)
5095 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
5096 Set_Itype
(IR
, Desig
);
5100 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
5101 and then Convention
(Desig
) /= Convention_Protected
5103 Set_Is_Frozen
(Desig
);
5104 Create_Extra_Formals
(Desig
);
5108 ------------------------------------
5109 -- Freeze_Choices_In_Variant_Part --
5110 ------------------------------------
5112 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
5113 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
5120 -- Loop through variants
5122 Variant
:= First_Non_Pragma
(Variants
(VP
));
5123 while Present
(Variant
) loop
5125 -- Loop through choices, checking that all types are frozen
5127 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
5128 while Present
(Choice
) loop
5129 if Nkind
(Choice
) in N_Has_Etype
5130 and then Present
(Etype
(Choice
))
5132 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
5135 Next_Non_Pragma
(Choice
);
5138 -- Check for nested variant part to process
5140 CL
:= Component_List
(Variant
);
5142 if not Null_Present
(CL
) then
5143 if Present
(Variant_Part
(CL
)) then
5144 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
5148 Next_Non_Pragma
(Variant
);
5150 end Freeze_Choices_In_Variant_Part
;
5152 ------------------------------------------
5153 -- Warn_If_Implicitly_Inherited_Aspects --
5154 ------------------------------------------
5156 procedure Warn_If_Implicitly_Inherited_Aspects
(Tag_Typ
: Entity_Id
)
5158 function Has_First_Ctrl_Param_Aspect
return Boolean;
5159 -- Determines if Tag_Typ explicitly has the aspect/pragma
5160 -- First_Controlling_Parameter.
5162 ---------------------------------
5163 -- Has_First_Ctrl_Param_Aspect --
5164 ---------------------------------
5166 function Has_First_Ctrl_Param_Aspect
return Boolean is
5167 Decl_Nod
: constant Node_Id
:= Parent
(Tag_Typ
);
5170 Pragma_Arg
: Node_Id
;
5171 Pragma_Ent
: Entity_Id
;
5174 pragma Assert
(Nkind
(Decl_Nod
) = N_Full_Type_Declaration
);
5176 if Present
(Aspect_Specifications
(Decl_Nod
)) then
5177 Asp_Nod
:= First
(Aspect_Specifications
(Decl_Nod
));
5178 while Present
(Asp_Nod
) loop
5179 if Chars
(Identifier
(Asp_Nod
))
5180 = Name_First_Controlling_Parameter
5189 -- Search for the occurrence of the pragma
5191 Nod
:= Next
(Decl_Nod
);
5192 while Present
(Nod
) loop
5193 if Nkind
(Nod
) = N_Pragma
5194 and then Chars
(Pragma_Identifier
(Nod
))
5195 = Name_First_Controlling_Parameter
5196 and then Present
(Pragma_Argument_Associations
(Nod
))
5199 Expression
(First
(Pragma_Argument_Associations
(Nod
)));
5201 if Nkind
(Pragma_Arg
) = N_Identifier
5202 and then Present
(Entity
(Pragma_Arg
))
5204 Pragma_Ent
:= Entity
(Pragma_Arg
);
5206 if Pragma_Ent
= Tag_Typ
5208 (Is_Concurrent_Type
(Pragma_Ent
)
5210 Corresponding_Record_Type
(Pragma_Ent
)
5222 end Has_First_Ctrl_Param_Aspect
;
5226 Has_Aspect_First_Ctrl_Param
: constant Boolean :=
5227 Has_First_Ctrl_Param_Aspect
;
5229 -- Start of processing for Warn_Implicitly_Inherited_Aspects
5232 -- Handle cases where reporting the warning is not needed
5234 if not Warn_On_Non_Dispatching_Primitives
then
5237 -- No check needed when this is the full view of a private type
5238 -- declaration since the pragma/aspect must be placed and checked
5239 -- in the partial view, and it is implicitly propagated to the
5242 elsif Has_Private_Declaration
(Tag_Typ
)
5243 and then Is_Tagged_Type
(Incomplete_Or_Partial_View
(Tag_Typ
))
5247 -- Similar case but applied to concurrent types
5249 elsif Is_Concurrent_Record_Type
(Tag_Typ
)
5250 and then Has_Private_Declaration
5251 (Corresponding_Concurrent_Type
(Tag_Typ
))
5252 and then Is_Tagged_Type
5253 (Incomplete_Or_Partial_View
5254 (Corresponding_Concurrent_Type
(Tag_Typ
)))
5259 if Etype
(Tag_Typ
) /= Tag_Typ
5260 and then Has_First_Controlling_Parameter_Aspect
(Etype
(Tag_Typ
))
5262 -- The attribute was implicitly inherited
5264 (Has_First_Controlling_Parameter_Aspect
(Tag_Typ
));
5266 -- No warning needed when the current tagged type is not
5267 -- an interface type since by definition the aspect is
5268 -- implicitly propagated from its parent type; the warning
5269 -- is reported on interface types since it may not be so
5270 -- clear when some implemented interface types have the
5271 -- aspect and other interface types don't have it. For
5272 -- interface types, we don't report the warning when the
5273 -- interface type is an extension of a single interface
5274 -- type (for similarity with the behavior with regular
5277 if not Has_Aspect_First_Ctrl_Param
5278 and then Is_Interface
(Tag_Typ
)
5279 and then not Is_Empty_Elmt_List
(Interfaces
(Tag_Typ
))
5282 ("?_j?implicitly inherits aspect 'First_'Controlling_'"
5283 & "Parameter!", Tag_Typ
);
5285 ("\?_j?from & and must be confirmed explicitly!",
5286 Tag_Typ
, Etype
(Tag_Typ
));
5289 elsif Present
(Interfaces
(Tag_Typ
))
5290 and then not Is_Empty_Elmt_List
(Interfaces
(Tag_Typ
))
5292 -- To maintain consistency with the behavior when the aspect
5293 -- is implicitly inherited from its parent type, we do not
5294 -- report a warning for concurrent record types that implement
5295 -- a single interface type. By definition, the aspect is
5296 -- propagated from that interface type as if it were the parent
5297 -- type. For example:
5299 -- type Iface is interface with First_Controlling_Parameter;
5300 -- task type T is new Iface with ...
5302 if Is_Concurrent_Record_Type
(Tag_Typ
)
5303 and then No
(Next_Elmt
(First_Elmt
(Interfaces
(Tag_Typ
))))
5309 Elmt
: Elmt_Id
:= First_Elmt
(Interfaces
(Tag_Typ
));
5313 while Present
(Elmt
) loop
5314 Iface
:= Node
(Elmt
);
5315 pragma Assert
(Present
(Iface
));
5317 if Has_First_Controlling_Parameter_Aspect
(Iface
)
5318 and then not Has_Aspect_First_Ctrl_Param
5321 (Has_First_Controlling_Parameter_Aspect
5324 ("?_j?implicitly inherits aspect 'First_'"
5325 & "Controlling_'Parameter", Tag_Typ
);
5327 ("\?_j?from & and must be confirmed explicitly!",
5337 end Warn_If_Implicitly_Inherited_Aspects
;
5339 -- Start of processing for Freeze_Record_Type
5342 -- Freeze components and embedded subtypes
5344 Comp
:= First_Entity
(Rec
);
5346 while Present
(Comp
) loop
5347 if Is_Aliased
(Comp
) then
5348 Aliased_Component
:= True;
5351 -- Handle the component and discriminant case
5353 if Ekind
(Comp
) in E_Component | E_Discriminant
then
5355 CC
: constant Node_Id
:= Component_Clause
(Comp
);
5358 -- Freezing a record type freezes the type of each of its
5359 -- components. However, if the type of the component is
5360 -- part of this record, we do not want or need a separate
5361 -- Freeze_Node. Note that Is_Itype is wrong because that's
5362 -- also set in private type cases. We also can't check for
5363 -- the Scope being exactly Rec because of private types and
5364 -- record extensions.
5366 if Is_Itype
(Etype
(Comp
))
5367 and then Is_Record_Type
(Underlying_Type
5368 (Scope
(Etype
(Comp
))))
5370 Undelay_Type
(Etype
(Comp
));
5373 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5375 -- Warn for pragma Pack overriding foreign convention
5377 if Has_Foreign_Convention
(Etype
(Comp
))
5378 and then Has_Pragma_Pack
(Rec
)
5380 -- Don't warn for aliased components, since override
5381 -- cannot happen in that case.
5383 and then not Is_Aliased
(Comp
)
5386 CN
: constant Name_Id
:=
5387 Get_Convention_Name
(Convention
(Etype
(Comp
)));
5388 PP
: constant Node_Id
:=
5389 Get_Pragma
(Rec
, Pragma_Pack
);
5391 if Present
(PP
) then
5392 Error_Msg_Name_1
:= CN
;
5393 Error_Msg_Sloc
:= Sloc
(Comp
);
5395 ("pragma Pack affects convention % component#??",
5397 Error_Msg_Name_1
:= CN
;
5399 ("\component & may not have % compatible "
5400 & "representation??", PP
, Comp
);
5405 -- Check for error of component clause given for variable
5406 -- sized type. We have to delay this test till this point,
5407 -- since the component type has to be frozen for us to know
5408 -- if it is variable length.
5410 if Present
(CC
) then
5411 Placed_Component
:= True;
5413 -- We omit this test in a generic context, it will be
5414 -- applied at instantiation time.
5416 if Inside_A_Generic
then
5419 -- Also omit this test in CodePeer mode, since we do not
5420 -- have sufficient info on size and rep clauses.
5422 elsif CodePeer_Mode
then
5428 Size_Known_At_Compile_Time
5429 (Underlying_Type
(Etype
(Comp
)))
5432 ("component clause not allowed for variable " &
5433 "length component", CC
);
5437 Unplaced_Component
:= True;
5440 -- Case of component requires byte alignment
5442 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
5444 -- Set the enclosing record to also require byte align
5446 Set_Must_Be_On_Byte_Boundary
(Rec
);
5448 -- Check for component clause that is inconsistent with
5449 -- the required byte boundary alignment.
5452 and then Normalized_First_Bit
(Comp
) mod
5453 System_Storage_Unit
/= 0
5456 ("component & must be byte aligned",
5457 Component_Name
(Component_Clause
(Comp
)));
5463 -- Gather data for possible Implicit_Packing later. Note that at
5464 -- this stage we might be dealing with a real component, or with
5465 -- an implicit subtype declaration.
5467 if Known_Static_RM_Size
(Etype
(Comp
)) then
5469 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
5470 Comp_Size
: constant Uint
:= RM_Size
(Comp_Type
);
5471 SSU
: constant Int
:= Ttypes
.System_Storage_Unit
;
5474 Sized_Component_Total_RM_Size
:=
5475 Sized_Component_Total_RM_Size
+ Comp_Size
;
5477 Sized_Component_Total_Round_RM_Size
:=
5478 Sized_Component_Total_Round_RM_Size
+
5479 (Comp_Size
+ SSU
- 1) / SSU
* SSU
;
5481 if Present
(Underlying_Type
(Comp_Type
))
5482 and then Is_Elementary_Type
(Underlying_Type
(Comp_Type
))
5484 Elem_Component_Total_Esize
:=
5485 Elem_Component_Total_Esize
+ Esize
(Comp_Type
);
5487 All_Elem_Components
:= False;
5489 if Comp_Size
mod SSU
/= 0 then
5490 All_Storage_Unit_Components
:= False;
5495 All_Sized_Components
:= False;
5498 -- If the component is an Itype with Delayed_Freeze and is either
5499 -- a record or array subtype and its base type has not yet been
5500 -- frozen, we must remove this from the entity list of this record
5501 -- and put it on the entity list of the scope of its base type.
5502 -- Note that we know that this is not the type of a component
5503 -- since we cleared Has_Delayed_Freeze for it in the previous
5504 -- loop. Thus this must be the Designated_Type of an access type,
5505 -- which is the type of a component.
5508 and then Is_Type
(Scope
(Comp
))
5509 and then Is_Composite_Type
(Comp
)
5510 and then Base_Type
(Comp
) /= Comp
5511 and then Has_Delayed_Freeze
(Comp
)
5512 and then not Is_Frozen
(Base_Type
(Comp
))
5515 Will_Be_Frozen
: Boolean := False;
5519 -- We have a difficult case to handle here. Suppose Rec is
5520 -- subtype being defined in a subprogram that's created as
5521 -- part of the freezing of Rec'Base. In that case, we know
5522 -- that Comp'Base must have already been frozen by the time
5523 -- we get to elaborate this because Gigi doesn't elaborate
5524 -- any bodies until it has elaborated all of the declarative
5525 -- part. But Is_Frozen will not be set at this point because
5526 -- we are processing code in lexical order.
5528 -- We detect this case by going up the Scope chain of Rec
5529 -- and seeing if we have a subprogram scope before reaching
5530 -- the top of the scope chain or that of Comp'Base. If we
5531 -- do, then mark that Comp'Base will actually be frozen. If
5532 -- so, we merely undelay it.
5535 while Present
(S
) loop
5536 if Is_Subprogram
(S
) then
5537 Will_Be_Frozen
:= True;
5539 elsif S
= Scope
(Base_Type
(Comp
)) then
5546 if Will_Be_Frozen
then
5547 Undelay_Type
(Comp
);
5550 if Present
(Prev
) then
5551 Link_Entities
(Prev
, Next_Entity
(Comp
));
5553 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
5556 -- Insert in entity list of scope of base type (which
5557 -- must be an enclosing scope, because still unfrozen).
5559 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
5563 -- If the component is an access type with an allocator as default
5564 -- value, the designated type will be frozen by the corresponding
5565 -- expression in init_proc. In order to place the freeze node for
5566 -- the designated type before that for the current record type,
5569 -- Same process if the component is an array of access types,
5570 -- initialized with an aggregate. If the designated type is
5571 -- private, it cannot contain allocators, and it is premature
5572 -- to freeze the type, so we check for this as well.
5574 elsif Is_Access_Type
(Etype
(Comp
))
5575 and then Present
(Parent
(Comp
))
5577 Nkind
(Parent
(Comp
))
5578 in N_Component_Declaration | N_Discriminant_Specification
5579 and then Present
(Expression
(Parent
(Comp
)))
5582 Alloc
: constant Node_Id
:=
5583 Unqualify
(Expression
(Parent
(Comp
)));
5586 if Nkind
(Alloc
) = N_Allocator
then
5588 -- If component is pointer to a class-wide type, freeze
5589 -- the specific type in the expression being allocated.
5590 -- The expression may be a subtype indication, in which
5591 -- case freeze the subtype mark.
5593 if Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp
)))
5595 if Is_Entity_Name
(Expression
(Alloc
)) then
5597 (Entity
(Expression
(Alloc
)), N
, Result
);
5599 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
5602 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
5605 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
5606 Check_Itype
(Etype
(Comp
));
5609 (Designated_Type
(Etype
(Comp
)), N
, Result
);
5613 elsif Is_Access_Type
(Etype
(Comp
))
5614 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
5616 Check_Itype
(Etype
(Comp
));
5618 -- Freeze the designated type when initializing a component with
5619 -- an aggregate in case the aggregate contains allocators.
5622 -- type T_Ptr is access all T;
5623 -- type T_Array is array ... of T_Ptr;
5625 -- type Rec is record
5626 -- Comp : T_Array := (others => ...);
5629 elsif Is_Array_Type
(Etype
(Comp
))
5630 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
5633 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
5634 Desig_Typ
: constant Entity_Id
:=
5636 (Component_Type
(Etype
(Comp
)));
5639 -- The only case when this sort of freezing is not done is
5640 -- when the designated type is class-wide and the root type
5641 -- is the record owning the component. This scenario results
5642 -- in a circularity because the class-wide type requires
5643 -- primitives that have not been created yet as the root
5644 -- type is in the process of being frozen.
5646 -- type Rec is tagged;
5647 -- type Rec_Ptr is access all Rec'Class;
5648 -- type Rec_Array is array ... of Rec_Ptr;
5650 -- type Rec is record
5651 -- Comp : Rec_Array := (others => ...);
5654 if Is_Class_Wide_Type
(Desig_Typ
)
5655 and then Root_Type
(Desig_Typ
) = Rec
5659 elsif Is_Fully_Defined
(Desig_Typ
)
5660 and then Present
(Comp_Par
)
5661 and then Nkind
(Comp_Par
) = N_Component_Declaration
5662 and then Present
(Expression
(Comp_Par
))
5663 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
5665 Freeze_And_Append
(Desig_Typ
, N
, Result
);
5675 Get_Attribute_Definition_Clause
5676 (Rec
, Attribute_Scalar_Storage_Order
);
5678 -- If the record type has Complex_Representation, then it is treated
5679 -- as a scalar in the back end so the storage order is irrelevant.
5681 if Has_Complex_Representation
(Rec
) then
5682 if Present
(SSO_ADC
) then
5684 ("??storage order has no effect with Complex_Representation",
5689 -- Deal with default setting of reverse storage order
5691 Set_SSO_From_Default
(Rec
);
5693 -- Check consistent attribute setting on component types
5696 Comp_ADC_Present
: Boolean;
5698 Comp
:= First_Component
(Rec
);
5699 while Present
(Comp
) loop
5700 Check_Component_Storage_Order
5704 Comp_ADC_Present
=> Comp_ADC_Present
);
5705 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
5706 Next_Component
(Comp
);
5710 -- Now deal with reverse storage order/bit order issues
5712 if Present
(SSO_ADC
) then
5714 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
5715 -- if the former is specified.
5717 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
5719 -- Note: report error on Rec, not on SSO_ADC, as ADC may
5720 -- apply to some ancestor type.
5722 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
5724 ("scalar storage order for& specified# inconsistent with "
5725 & "bit order", Rec
);
5728 -- Warn if there is a Scalar_Storage_Order attribute definition
5729 -- clause but no component clause, no component that itself has
5730 -- such an attribute definition, and no pragma Pack.
5732 if not (Placed_Component
5739 ("??scalar storage order specified but no component "
5740 & "clause", SSO_ADC
);
5745 -- Deal with Bit_Order aspect
5747 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
5749 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
5750 if not (Placed_Component
5751 or else Present
(SSO_ADC
)
5752 or else Is_Packed
(Rec
))
5754 -- Warn if clause has no effect when no component clause is
5755 -- present, but suppress warning if the Bit_Order is required
5756 -- due to the presence of a Scalar_Storage_Order attribute.
5759 ("??bit order specification has no effect", ADC
);
5761 ("\??since no component clauses were specified", ADC
);
5763 -- Here is where we do the processing to adjust component clauses
5764 -- for reversed bit order, when not using reverse SSO. If an error
5765 -- has been reported on Rec already (such as SSO incompatible with
5766 -- bit order), don't bother adjusting as this may generate extra
5769 elsif Reverse_Bit_Order
(Rec
)
5770 and then not Reverse_Storage_Order
(Rec
)
5771 and then not Error_Posted
(Rec
)
5773 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
5775 -- Case where we have both an explicit Bit_Order and the same
5776 -- Scalar_Storage_Order: leave record untouched, the back-end
5777 -- will take care of required layout conversions.
5785 -- Check for useless pragma Pack when all components placed. We only
5786 -- do this check for record types, not subtypes, since a subtype may
5787 -- have all its components placed, and it still makes perfectly good
5788 -- sense to pack other subtypes or the parent type. We do not give
5789 -- this warning if Optimize_Alignment is set to Space, since the
5790 -- pragma Pack does have an effect in this case (it always resets
5791 -- the alignment to one).
5793 if Ekind
(Rec
) = E_Record_Type
5794 and then Is_Packed
(Rec
)
5795 and then not Unplaced_Component
5796 and then Optimize_Alignment
/= 'S'
5798 -- Reset packed status. Probably not necessary, but we do it so
5799 -- that there is no chance of the back end doing something strange
5800 -- with this redundant indication of packing.
5802 Set_Is_Packed
(Rec
, False);
5804 -- Give warning if redundant constructs warnings on
5806 if Warn_On_Redundant_Constructs
then
5807 Error_Msg_N
-- CODEFIX
5808 ("?r?pragma Pack has no effect, no unplaced components",
5809 Get_Rep_Pragma
(Rec
, Name_Pack
));
5813 -- If this is the record corresponding to a remote type, freeze the
5814 -- remote type here since that is what we are semantically freezing.
5815 -- This prevents the freeze node for that type in an inner scope.
5817 if Ekind
(Rec
) = E_Record_Type
then
5818 if Present
(Corresponding_Remote_Type
(Rec
)) then
5819 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
5822 -- Check for tasks, protected and controlled components, unchecked
5823 -- unions, and type invariants.
5825 Comp
:= First_Component
(Rec
);
5826 while Present
(Comp
) loop
5827 Propagate_Concurrent_Flags
(Rec
, Etype
(Comp
));
5829 -- Do not set Has_Controlled_Component on a class-wide
5830 -- equivalent type. See Make_CW_Equivalent_Type.
5832 if not Is_Class_Wide_Equivalent_Type
(Rec
)
5834 (Has_Controlled_Component
(Etype
(Comp
))
5836 (Chars
(Comp
) /= Name_uParent
5837 and then Is_Controlled
(Etype
(Comp
)))
5839 (Is_Protected_Type
(Etype
(Comp
))
5841 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
5843 Has_Controlled_Component
5844 (Corresponding_Record_Type
(Etype
(Comp
)))))
5846 Set_Has_Controlled_Component
(Rec
);
5847 Final_Storage_Only
:=
5849 and then Finalize_Storage_Only
(Etype
(Comp
));
5850 Relaxed_Finalization
:=
5851 Relaxed_Finalization
5852 and then Has_Relaxed_Finalization
(Etype
(Comp
));
5855 if Has_Unchecked_Union
(Etype
(Comp
)) then
5856 Set_Has_Unchecked_Union
(Rec
);
5859 -- The record type requires its own invariant procedure in
5860 -- order to verify the invariant of each individual component.
5861 -- Do not consider internal components such as _parent because
5862 -- parent class-wide invariants are always inherited.
5863 -- In GNATprove mode, the component invariants are checked by
5864 -- other means. They should not be added to the record type
5865 -- invariant procedure, so that the procedure can be used to
5866 -- check the recordy type invariants if any.
5868 if Comes_From_Source
(Comp
)
5869 and then Has_Invariants
(Etype
(Comp
))
5870 and then not GNATprove_Mode
5872 Set_Has_Own_Invariants
(Rec
);
5875 -- Scan component declaration for likely misuses of current
5876 -- instance, either in a constraint or a default expression.
5878 if Has_Per_Object_Constraint
(Comp
) then
5879 Check_Current_Instance
(Parent
(Comp
));
5882 Next_Component
(Comp
);
5885 -- For a type that is not directly controlled but has controlled
5886 -- components, Finalize_Storage_Only is set if all the controlled
5887 -- components are Finalize_Storage_Only. The same processing is
5888 -- appled to Has_Relaxed_Finalization.
5890 if not Is_Controlled
(Rec
) and then Has_Controlled_Component
(Rec
)
5892 Set_Finalize_Storage_Only
(Rec
, Final_Storage_Only
);
5893 Set_Has_Relaxed_Finalization
(Rec
, Relaxed_Finalization
);
5897 -- Enforce the restriction that access attributes with a current
5898 -- instance prefix can only apply to limited types. This comment
5899 -- is floating here, but does not seem to belong here???
5901 -- Set component alignment if not otherwise already set
5903 Set_Component_Alignment_If_Not_Set
(Rec
);
5905 -- For first subtypes, check if there are any fixed-point fields with
5906 -- component clauses, where we must check the size. This is not done
5907 -- till the freeze point since for fixed-point types, we do not know
5908 -- the size until the type is frozen. Similar processing applies to
5909 -- bit-packed arrays.
5911 if Is_First_Subtype
(Rec
) then
5912 Comp
:= First_Component
(Rec
);
5913 while Present
(Comp
) loop
5914 if Present
(Component_Clause
(Comp
))
5915 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
5916 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
5919 (Component_Name
(Component_Clause
(Comp
)),
5925 Next_Component
(Comp
);
5929 -- See if Size is too small as is (and implicit packing might help)
5931 if not Is_Packed
(Rec
)
5933 -- No implicit packing if even one component is explicitly placed
5935 and then not Placed_Component
5937 -- Or even one component is aliased
5939 and then not Aliased_Component
5941 -- Must have size clause and all sized components
5943 and then Has_Size_Clause
(Rec
)
5944 and then All_Sized_Components
5946 -- Do not try implicit packing on records with discriminants, too
5947 -- complicated, especially in the variant record case.
5949 and then not Has_Discriminants
(Rec
)
5951 -- We want to implicitly pack if the specified size of the record
5952 -- is less than the sum of the object sizes (no point in packing
5953 -- if this is not the case), if we can compute it, i.e. if we have
5954 -- only elementary components. Otherwise, we have at least one
5955 -- composite component and we want to implicitly pack only if bit
5956 -- packing is required for it, as we are sure in this case that
5957 -- the back end cannot do the expected layout without packing.
5960 ((All_Elem_Components
5961 and then RM_Size
(Rec
) < Elem_Component_Total_Esize
)
5963 (not All_Elem_Components
5964 and then not All_Storage_Unit_Components
5965 and then RM_Size
(Rec
) < Sized_Component_Total_Round_RM_Size
))
5967 -- And the total RM size cannot be greater than the specified size
5968 -- since otherwise packing will not get us where we have to be.
5970 and then Sized_Component_Total_RM_Size
<= RM_Size
(Rec
)
5972 -- Never do implicit packing in CodePeer or SPARK modes since
5973 -- we don't do any packing in these modes, since this generates
5974 -- over-complex code that confuses static analysis, and in
5975 -- general, neither CodePeer not GNATprove care about the
5976 -- internal representation of objects.
5978 and then not (CodePeer_Mode
or GNATprove_Mode
)
5980 -- If implicit packing enabled, do it
5982 if Implicit_Packing
then
5983 Set_Is_Packed
(Rec
);
5985 -- Otherwise flag the size clause
5989 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
5991 Error_Msg_NE
-- CODEFIX
5992 ("size given for& too small", Sz
, Rec
);
5993 Error_Msg_N
-- CODEFIX
5994 ("\use explicit pragma Pack "
5995 & "or use pragma Implicit_Packing", Sz
);
6000 -- Make sure that if we have an iterator aspect, then we have
6001 -- either Constant_Indexing or Variable_Indexing.
6004 Iterator_Aspect
: Node_Id
;
6007 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
6009 if No
(Iterator_Aspect
) then
6010 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
6013 if Present
(Iterator_Aspect
) then
6014 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
6016 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
6021 ("Iterator_Element requires indexing aspect",
6027 -- All done if not a full record definition
6029 if Ekind
(Rec
) /= E_Record_Type
then
6033 -- Finally we need to check the variant part to make sure that
6034 -- all types within choices are properly frozen as part of the
6035 -- freezing of the record type.
6037 Check_Variant_Part
: declare
6038 D
: constant Node_Id
:= Declaration_Node
(Rec
);
6043 -- Find component list
6047 if Nkind
(D
) = N_Full_Type_Declaration
then
6048 T
:= Type_Definition
(D
);
6050 if Nkind
(T
) = N_Record_Definition
then
6051 C
:= Component_List
(T
);
6053 elsif Nkind
(T
) = N_Derived_Type_Definition
6054 and then Present
(Record_Extension_Part
(T
))
6056 C
:= Component_List
(Record_Extension_Part
(T
));
6060 -- Case of variant part present
6062 if Present
(C
) and then Present
(Variant_Part
(C
)) then
6063 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
6066 -- Note: we used to call Check_Choices here, but it is too early,
6067 -- since predicated subtypes are frozen here, but their freezing
6068 -- actions are in Analyze_Freeze_Entity, which has not been called
6069 -- yet for entities frozen within this procedure, so we moved that
6070 -- call to the Analyze_Freeze_Entity for the record type.
6072 end Check_Variant_Part
;
6074 -- Check that all the primitives of an interface type are abstract
6075 -- or null procedures.
6077 if Is_Interface
(Rec
)
6078 and then not Error_Posted
(Parent
(Rec
))
6085 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
6086 while Present
(Elmt
) loop
6087 Subp
:= Node
(Elmt
);
6089 if not Is_Abstract_Subprogram
(Subp
)
6091 -- Avoid reporting the error on inherited primitives
6093 and then Comes_From_Source
(Subp
)
6095 Error_Msg_Name_1
:= Chars
(Subp
);
6097 if Ekind
(Subp
) = E_Procedure
then
6098 if not Null_Present
(Parent
(Subp
)) then
6100 ("interface procedure % must be abstract or null",
6105 ("interface function % must be abstract",
6115 -- For tagged types, warn on an implicitly inherited aspect/pragma
6116 -- First_Controlling_Parameter that is not explicitly set.
6118 if Is_Tagged_Type
(Rec
) then
6119 Warn_If_Implicitly_Inherited_Aspects
(Rec
);
6121 end Freeze_Record_Type
;
6123 -------------------------------
6124 -- Has_Boolean_Aspect_Import --
6125 -------------------------------
6127 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
6128 Decl
: constant Node_Id
:= Declaration_Node
(E
);
6133 if Has_Aspects
(Decl
) then
6134 Asp
:= First
(Aspect_Specifications
(Decl
));
6135 while Present
(Asp
) loop
6136 Expr
:= Expression
(Asp
);
6138 -- The value of aspect Import is True when the expression is
6139 -- either missing or it is explicitly set to True.
6141 if Get_Aspect_Id
(Asp
) = Aspect_Import
6143 or else (Compile_Time_Known_Value
(Expr
)
6144 and then Is_True
(Expr_Value
(Expr
))))
6154 end Has_Boolean_Aspect_Import
;
6156 -------------------------
6157 -- Inherit_Freeze_Node --
6158 -------------------------
6160 procedure Inherit_Freeze_Node
6164 Typ_Fnod
: constant Node_Id
:= Freeze_Node
(Typ
);
6167 Set_Freeze_Node
(Typ
, Fnod
);
6168 Set_Entity
(Fnod
, Typ
);
6170 -- The input type had an existing node. Propagate relevant attributes
6171 -- from the old freeze node to the inherited freeze node.
6173 -- ??? if both freeze nodes have attributes, would they differ?
6175 if Present
(Typ_Fnod
) then
6177 -- Attribute Access_Types_To_Process
6179 if Present
(Access_Types_To_Process
(Typ_Fnod
))
6180 and then No
(Access_Types_To_Process
(Fnod
))
6182 Set_Access_Types_To_Process
(Fnod
,
6183 Access_Types_To_Process
(Typ_Fnod
));
6186 -- Attribute Actions
6188 if Present
(Actions
(Typ_Fnod
)) and then No
(Actions
(Fnod
)) then
6189 Set_Actions
(Fnod
, Actions
(Typ_Fnod
));
6192 -- Attribute First_Subtype_Link
6194 if Present
(First_Subtype_Link
(Typ_Fnod
))
6195 and then No
(First_Subtype_Link
(Fnod
))
6197 Set_First_Subtype_Link
(Fnod
, First_Subtype_Link
(Typ_Fnod
));
6200 -- Attribute TSS_Elist
6202 if Present
(TSS_Elist
(Typ_Fnod
))
6203 and then No
(TSS_Elist
(Fnod
))
6205 Set_TSS_Elist
(Fnod
, TSS_Elist
(Typ_Fnod
));
6208 end Inherit_Freeze_Node
;
6210 ------------------------------
6211 -- Wrap_Imported_Subprogram --
6212 ------------------------------
6214 -- The issue here is that our normal approach of checking preconditions
6215 -- and postconditions does not work for imported procedures, since we
6216 -- are not generating code for the body. To get around this we create
6217 -- a wrapper, as shown by the following example:
6219 -- procedure K (A : Integer);
6220 -- pragma Import (C, K);
6222 -- The spec is rewritten by removing the effects of pragma Import, but
6223 -- leaving the convention unchanged, as though the source had said:
6225 -- procedure K (A : Integer);
6226 -- pragma Convention (C, K);
6228 -- and we create a body, added to the entity K freeze actions, which
6231 -- procedure K (A : Integer) is
6232 -- procedure K (A : Integer);
6233 -- pragma Import (C, K);
6238 -- Now the contract applies in the normal way to the outer procedure,
6239 -- and the inner procedure has no contracts, so there is no problem
6240 -- in just calling it to get the original effect.
6242 -- In the case of a function, we create an appropriate return statement
6243 -- for the subprogram body that calls the inner procedure.
6245 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
6246 function Copy_Import_Pragma
return Node_Id
;
6247 -- Obtain a copy of the Import_Pragma which belongs to subprogram E
6249 ------------------------
6250 -- Copy_Import_Pragma --
6251 ------------------------
6253 function Copy_Import_Pragma
return Node_Id
is
6255 -- The subprogram should have an import pragma, otherwise it does
6258 Prag
: constant Node_Id
:= Import_Pragma
(E
);
6259 pragma Assert
(Present
(Prag
));
6261 -- Save all semantic fields of the pragma
6263 Save_Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
6264 Save_From
: constant Boolean := From_Aspect_Specification
(Prag
);
6265 Save_Prag
: constant Node_Id
:= Next_Pragma
(Prag
);
6266 Save_Rep
: constant Node_Id
:= Next_Rep_Item
(Prag
);
6271 -- Reset all semantic fields. This avoids a potential infinite
6272 -- loop when the pragma comes from an aspect as the duplication
6273 -- will copy the aspect, then copy the corresponding pragma and
6276 Set_Corresponding_Aspect
(Prag
, Empty
);
6277 Set_From_Aspect_Specification
(Prag
, False);
6278 Set_Next_Pragma
(Prag
, Empty
);
6279 Set_Next_Rep_Item
(Prag
, Empty
);
6281 Result
:= Copy_Separate_Tree
(Prag
);
6283 -- Restore the original semantic fields
6285 Set_Corresponding_Aspect
(Prag
, Save_Asp
);
6286 Set_From_Aspect_Specification
(Prag
, Save_From
);
6287 Set_Next_Pragma
(Prag
, Save_Prag
);
6288 Set_Next_Rep_Item
(Prag
, Save_Rep
);
6291 end Copy_Import_Pragma
;
6295 Loc
: constant Source_Ptr
:= Sloc
(E
);
6296 CE
: constant Name_Id
:= Chars
(E
);
6304 -- Start of processing for Wrap_Imported_Subprogram
6307 -- Nothing to do if not imported
6309 if not Is_Imported
(E
) then
6312 -- Test enabling conditions for wrapping
6314 elsif Is_Subprogram
(E
)
6315 and then Present
(Contract
(E
))
6316 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
6317 and then not GNATprove_Mode
6319 -- Here we do the wrap
6321 Prag
:= Copy_Import_Pragma
;
6323 -- Fix up spec so it is no longer imported and has convention Ada
6325 Set_Has_Completion
(E
, False);
6326 Set_Import_Pragma
(E
, Empty
);
6327 Set_Interface_Name
(E
, Empty
);
6328 Set_Is_Imported
(E
, False);
6329 Set_Convention
(E
, Convention_Ada
);
6331 -- Grab the subprogram declaration and specification
6333 Spec
:= Declaration_Node
(E
);
6335 -- Build parameter list that we need
6338 Forml
:= First_Formal
(E
);
6339 while Present
(Forml
) loop
6340 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
6341 Next_Formal
(Forml
);
6346 -- An imported function whose result type is anonymous access
6347 -- creates a new anonymous access type when it is relocated into
6348 -- the declarations of the body generated below. As a result, the
6349 -- accessibility level of these two anonymous access types may not
6350 -- be compatible even though they are essentially the same type.
6351 -- Use an unchecked type conversion to reconcile this case. Note
6352 -- that the conversion is safe because in the named access type
6353 -- case, both the body and imported function utilize the same
6356 if Ekind
(E
) in E_Function | E_Generic_Function
then
6358 Make_Simple_Return_Statement
(Loc
,
6360 Unchecked_Convert_To
(Etype
(E
),
6361 Make_Function_Call
(Loc
,
6362 Name
=> Make_Identifier
(Loc
, CE
),
6363 Parameter_Associations
=> Parms
)));
6367 Make_Procedure_Call_Statement
(Loc
,
6368 Name
=> Make_Identifier
(Loc
, CE
),
6369 Parameter_Associations
=> Parms
);
6372 -- Now build the body
6375 Make_Subprogram_Body
(Loc
,
6376 Specification
=> Copy_Subprogram_Spec
(Spec
),
6377 Declarations
=> New_List
(
6378 Make_Subprogram_Declaration
(Loc
,
6379 Specification
=> Copy_Subprogram_Spec
(Spec
)),
6381 Handled_Statement_Sequence
=>
6382 Make_Handled_Sequence_Of_Statements
(Loc
,
6383 Statements
=> New_List
(Stmt
),
6384 End_Label
=> Make_Identifier
(Loc
, CE
)));
6386 -- Append the body to freeze result
6388 Add_To_Result
(Bod
);
6391 -- Case of imported subprogram that does not get wrapped
6394 -- Set Is_Public. All imported entities need an external symbol
6395 -- created for them since they are always referenced from another
6396 -- object file. Note this used to be set when we set Is_Imported
6397 -- back in Sem_Prag, but now we delay it to this point, since we
6398 -- don't want to set this flag if we wrap an imported subprogram.
6402 end Wrap_Imported_Subprogram
;
6404 -- Start of processing for Freeze_Entity
6407 -- The entity being frozen may be subject to pragma Ghost. Set the mode
6408 -- now to ensure that any nodes generated during freezing are properly
6409 -- flagged as Ghost.
6413 -- We are going to test for various reasons why this entity need not be
6414 -- frozen here, but in the case of an Itype that's defined within a
6415 -- record, that test actually applies to the record.
6417 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
6418 Test_E
:= Scope
(E
);
6420 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
6421 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
6423 Test_E
:= Underlying_Type
(Scope
(E
));
6426 -- Do not freeze if already frozen since we only need one freeze node
6428 if Is_Frozen
(E
) then
6431 and then not Is_Base_Type
(E
)
6432 and then not Is_Frozen
(Etype
(E
))
6434 -- If a frozen subtype of an unfrozen type seems impossible
6435 -- then see Analyze_Protected_Definition.Undelay_Itypes.
6437 Result
:= Freeze_Entity
6438 (Etype
(E
), N
, Do_Freeze_Profile
=> Do_Freeze_Profile
);
6445 -- Do not freeze if we are preanalyzing without freezing
6447 elsif Inside_Preanalysis_Without_Freezing
> 0 then
6451 elsif Ekind
(E
) = E_Generic_Package
then
6452 Result
:= Freeze_Generic_Entities
(E
);
6455 -- It is improper to freeze an external entity within a generic because
6456 -- its freeze node will appear in a non-valid context. The entity will
6457 -- be frozen in the proper scope after the current generic is analyzed.
6458 -- However, aspects must be analyzed because they may be queried later
6459 -- within the generic itself, and the corresponding pragma or attribute
6460 -- definition has not been analyzed yet. After this, indicate that the
6461 -- entity has no further delayed aspects, to prevent a later aspect
6462 -- analysis out of the scope of the generic.
6464 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
6465 if Has_Delayed_Aspects
(E
) then
6466 Analyze_Aspects_At_Freeze_Point
(E
);
6467 Set_Has_Delayed_Aspects
(E
, False);
6473 -- AI05-0213: A formal incomplete type does not freeze the actual. In
6474 -- the instance, the same applies to the subtype renaming the actual.
6476 elsif Is_Private_Type
(E
)
6477 and then Is_Generic_Actual_Type
(E
)
6478 and then No
(Full_View
(Base_Type
(E
)))
6479 and then Ada_Version
>= Ada_2012
6484 -- Formal subprograms are never frozen
6486 elsif Is_Formal_Subprogram
(E
) then
6490 -- Generic types are never frozen as they lack delayed semantic checks
6492 elsif Is_Generic_Type
(E
) then
6496 -- Do not freeze a global entity within an inner scope created during
6497 -- expansion. A call to subprogram E within some internal procedure
6498 -- (a stream attribute for example) might require freezing E, but the
6499 -- freeze node must appear in the same declarative part as E itself.
6500 -- The two-pass elaboration mechanism in gigi guarantees that E will
6501 -- be frozen before the inner call is elaborated. We exclude constants
6502 -- from this test, because deferred constants may be frozen early, and
6503 -- must be diagnosed (e.g. in the case of a deferred constant being used
6504 -- in a default expression). If the enclosing subprogram comes from
6505 -- source, or is a generic instance, then the freeze point is the one
6506 -- mandated by the language, and we freeze the entity. A subprogram that
6507 -- is a child unit body that acts as a spec does not have a spec that
6508 -- comes from source, but can only come from source.
6510 elsif In_Open_Scopes
(Scope
(Test_E
))
6511 and then Scope
(Test_E
) /= Current_Scope
6512 and then Ekind
(Test_E
) /= E_Constant
6514 -- Here we deal with the special case of the expansion of
6515 -- postconditions. Previously this was handled by the loop below,
6516 -- since these postcondition checks got isolated to a separate,
6517 -- internally generated, subprogram. Now, however, the postcondition
6518 -- checks get contained within their corresponding subprogram
6521 if not Comes_From_Source
(N
)
6522 and then Nkind
(N
) = N_Pragma
6523 and then From_Aspect_Specification
(N
)
6524 and then Is_Valid_Assertion_Kind
(Original_Aspect_Pragma_Name
(N
))
6526 -- Now, verify the placement of the pragma is within an expanded
6527 -- subprogram which contains postcondition expansion - detected
6528 -- through the presence of the "Wrapped_Statements" field.
6530 and then Present
(Enclosing_Subprogram
(Current_Scope
))
6531 and then Present
(Wrapped_Statements
6532 (Enclosing_Subprogram
(Current_Scope
)))
6537 -- Otherwise, loop through scopes checking if an enclosing scope
6538 -- comes from source or is a generic. Note that, for the purpose
6539 -- of this test, we need to consider that the internally generated
6540 -- subprogram described above comes from source too if the original
6541 -- subprogram itself does.
6548 while Present
(S
) loop
6549 if Is_Overloadable
(S
) then
6550 if Comes_From_Source
(S
)
6551 or else (Chars
(S
) = Name_uWrapped_Statements
6552 and then Comes_From_Source
(Scope
(S
)))
6553 or else Is_Generic_Instance
(S
)
6554 or else Is_Child_Unit
(S
)
6567 -- Similarly, an inlined instance body may make reference to global
6568 -- entities, but these references cannot be the proper freezing point
6569 -- for them, and in the absence of inlining freezing will take place in
6570 -- their own scope. Normally instance bodies are analyzed after the
6571 -- enclosing compilation, and everything has been frozen at the proper
6572 -- place, but with front-end inlining an instance body is compiled
6573 -- before the end of the enclosing scope, and as a result out-of-order
6574 -- freezing must be prevented.
6576 elsif Front_End_Inlining
6577 and then In_Instance_Body
6578 and then Present
(Scope
(Test_E
))
6584 S
:= Scope
(Test_E
);
6585 while Present
(S
) loop
6586 if Is_Generic_Instance
(S
) then
6600 -- Add checks to detect proper initialization of scalars that may appear
6601 -- as subprogram parameters.
6603 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
6604 Apply_Parameter_Validity_Checks
(E
);
6607 -- Deal with delayed aspect specifications. The analysis of the aspect
6608 -- is required to be delayed to the freeze point, thus we analyze the
6609 -- pragma or attribute definition clause in the tree at this point. We
6610 -- also analyze the aspect specification node at the freeze point when
6611 -- the aspect doesn't correspond to pragma/attribute definition clause.
6612 -- In addition, a derived type may have inherited aspects that were
6613 -- delayed in the parent, so these must also be captured now.
6615 -- For a record type, we deal with the delayed aspect specifications on
6616 -- components first, which is consistent with the non-delayed case and
6617 -- makes it possible to have a single processing to detect conflicts.
6619 if Is_Record_Type
(E
) then
6623 Rec_Pushed
: Boolean := False;
6624 -- Set True if the record type E has been pushed on the scope
6625 -- stack. Needed for the analysis of delayed aspects specified
6626 -- to the components of Rec.
6629 Comp
:= First_Component
(E
);
6630 while Present
(Comp
) loop
6631 if Has_Delayed_Aspects
(Comp
) then
6632 if not Rec_Pushed
then
6636 -- The visibility to the discriminants must be restored
6637 -- in order to properly analyze the aspects.
6639 if Has_Discriminants
(E
) then
6640 Install_Discriminants
(E
);
6644 Analyze_Aspects_At_Freeze_Point
(Comp
);
6647 Next_Component
(Comp
);
6650 -- Pop the scope if Rec scope has been pushed on the scope stack
6651 -- during the delayed aspect analysis process.
6654 if Has_Discriminants
(E
) then
6655 Uninstall_Discriminants
(E
);
6663 if Has_Delayed_Aspects
(E
) then
6664 Analyze_Aspects_At_Freeze_Point
(E
);
6667 -- Here to freeze the entity
6671 -- Case of entity being frozen is other than a type
6673 if not Is_Type
(E
) then
6675 -- If entity is exported or imported and does not have an external
6676 -- name, now is the time to provide the appropriate default name.
6677 -- Skip this if the entity is stubbed, since we don't need a name
6678 -- for any stubbed routine. For the case on intrinsics, if no
6679 -- external name is specified, then calls will be handled in
6680 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
6681 -- external name is provided, then Expand_Intrinsic_Call leaves
6682 -- calls in place for expansion by GIGI.
6684 if (Is_Imported
(E
) or else Is_Exported
(E
))
6685 and then No
(Interface_Name
(E
))
6686 and then Convention
(E
) /= Convention_Stubbed
6687 and then Convention
(E
) /= Convention_Intrinsic
6689 Set_Encoded_Interface_Name
6690 (E
, Get_Default_External_Name
(E
));
6695 if Is_Subprogram
(E
) then
6697 -- Check for needing to wrap imported subprogram
6699 if not Inside_A_Generic
then
6700 Wrap_Imported_Subprogram
(E
);
6703 -- Freeze all parameter types and the return type (RM 13.14(14)).
6704 -- However skip this for internal subprograms. This is also where
6705 -- any extra formal parameters are created since we now know
6706 -- whether the subprogram will use a foreign convention.
6708 -- In Ada 2012, freezing a subprogram does not always freeze the
6709 -- corresponding profile (see AI05-019). An attribute reference
6710 -- is not a freezing point of the profile. Similarly, we do not
6711 -- freeze the profile of primitives of a library-level tagged type
6712 -- when we are building its dispatch table. Flag Do_Freeze_Profile
6713 -- indicates whether the profile should be frozen now.
6715 -- This processing doesn't apply to internal entities (see below)
6717 if not Is_Internal
(E
) and then Do_Freeze_Profile
then
6718 if not Freeze_Profile
(E
) then
6723 -- Must freeze its parent first if it is a derived subprogram
6725 if Present
(Alias
(E
)) then
6726 Freeze_And_Append
(Alias
(E
), N
, Result
);
6729 -- We don't freeze internal subprograms, because we don't normally
6730 -- want addition of extra formals or mechanism setting to happen
6731 -- for those. However we do pass through predefined dispatching
6732 -- cases, since extra formals may be needed in some cases, such as
6733 -- for the stream 'Input function (build-in-place formals).
6735 if not Is_Internal
(E
)
6736 or else Is_Predefined_Dispatching_Operation
(E
)
6738 Freeze_Subprogram
(E
);
6741 -- If warning on suspicious contracts then check for the case of
6742 -- a postcondition other than False for a No_Return subprogram.
6745 and then Warn_On_Suspicious_Contract
6746 and then Present
(Contract
(E
))
6749 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
6753 while Present
(Prag
) loop
6754 if Pragma_Name_Unmapped
(Prag
) in Name_Post
6755 | Name_Postcondition
6760 (First
(Pragma_Argument_Associations
(Prag
)));
6762 if Nkind
(Exp
) /= N_Identifier
6763 or else Chars
(Exp
) /= Name_False
6766 ("useless postcondition, & is marked "
6767 & "No_Return?.t?", Exp
, E
);
6771 Prag
:= Next_Pragma
(Prag
);
6776 -- Here for other than a subprogram or type
6779 -- If entity has a type declared in the current scope, and it is
6780 -- not a generic unit, then freeze it first.
6782 if Present
(Etype
(E
))
6783 and then Ekind
(E
) /= E_Generic_Function
6784 and then Within_Scope
(Etype
(E
), Current_Scope
)
6786 Freeze_And_Append
(Etype
(E
), N
, Result
);
6788 -- For an object of an anonymous array type, aspects on the
6789 -- object declaration apply to the type itself. This is the
6790 -- case for Atomic_Components, Volatile_Components, and
6791 -- Independent_Components. In these cases analysis of the
6792 -- generated pragma will mark the anonymous types accordingly,
6793 -- and the object itself does not require a freeze node.
6795 if Ekind
(E
) = E_Variable
6796 and then Is_Itype
(Etype
(E
))
6797 and then Is_Array_Type
(Etype
(E
))
6798 and then Has_Delayed_Aspects
(E
)
6800 Set_Has_Delayed_Aspects
(E
, False);
6801 Set_Has_Delayed_Freeze
(E
, False);
6802 Set_Freeze_Node
(E
, Empty
);
6806 -- Special processing for objects created by object declaration;
6807 -- we protect the call to Declaration_Node against entities of
6808 -- expressions replaced by the frontend with an N_Raise_CE node.
6810 if Ekind
(E
) in E_Constant | E_Variable
6811 and then Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
6813 Freeze_Object_Declaration
(E
);
6816 -- Check that a constant which has a pragma Volatile[_Components]
6817 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
6819 -- Note: Atomic[_Components] also sets Volatile[_Components]
6821 if Ekind
(E
) = E_Constant
6822 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
6823 and then not Is_Imported
(E
)
6824 and then not Has_Boolean_Aspect_Import
(E
)
6826 -- Make sure we actually have a pragma, and have not merely
6827 -- inherited the indication from elsewhere (e.g. an address
6828 -- clause, which is not good enough in RM terms).
6830 if Has_Rep_Pragma
(E
, Name_Atomic
)
6832 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
6835 ("standalone atomic constant must be " &
6836 "imported (RM C.6(13))", E
);
6838 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
6840 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
6843 ("standalone volatile constant must be " &
6844 "imported (RM C.6(13))", E
);
6848 -- Static objects require special handling
6850 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
6851 and then Is_Statically_Allocated
(E
)
6853 Freeze_Static_Object
(E
);
6856 -- Remaining step is to layout objects
6858 if Ekind
(E
) in E_Variable | E_Constant | E_Loop_Parameter
6859 or else Is_Formal
(E
)
6864 -- For an object that does not have delayed freezing, and whose
6865 -- initialization actions have been captured in a compound
6866 -- statement, move them back now directly within the enclosing
6867 -- statement sequence.
6869 if Ekind
(E
) in E_Constant | E_Variable
6870 and then not Has_Delayed_Freeze
(E
)
6872 Explode_Initialization_Compound_Statement
(E
);
6875 -- Do not generate a freeze node for a generic unit
6877 if Is_Generic_Unit
(E
) then
6883 -- Case of a type or subtype being frozen
6886 -- Verify several SPARK legality rules related to Ghost types now
6887 -- that the type is frozen.
6889 Check_Ghost_Type
(E
);
6891 -- We used to check here that a full type must have preelaborable
6892 -- initialization if it completes a private type specified with
6893 -- pragma Preelaborable_Initialization, but that missed cases where
6894 -- the types occur within a generic package, since the freezing
6895 -- that occurs within a containing scope generally skips traversal
6896 -- of a generic unit's declarations (those will be frozen within
6897 -- instances). This check was moved to Analyze_Package_Specification.
6899 -- The type may be defined in a generic unit. This can occur when
6900 -- freezing a generic function that returns the type (which is
6901 -- defined in a parent unit). It is clearly meaningless to freeze
6902 -- this type. However, if it is a subtype, its size may be determi-
6903 -- nable and used in subsequent checks, so might as well try to
6906 -- In Ada 2012, Freeze_Entities is also used in the front end to
6907 -- trigger the analysis of aspect expressions, so in this case we
6908 -- want to continue the freezing process.
6910 -- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead
6911 -- In_Generic_Scope (E)???
6913 if Present
(Scope
(E
))
6914 and then Is_Generic_Unit
(Scope
(E
))
6916 (not Has_Predicates
(E
)
6917 and then not Has_Delayed_Freeze
(E
))
6919 Check_Compile_Time_Size
(E
);
6924 -- Check for error of Type_Invariant'Class applied to an untagged
6925 -- type (check delayed to freeze time when full type is available).
6928 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
6931 and then Class_Present
(Prag
)
6932 and then not Is_Tagged_Type
(E
)
6935 ("Type_Invariant''Class cannot be specified for &", Prag
, E
);
6937 ("\can only be specified for a tagged type", Prag
);
6941 -- Deal with special cases of freezing for subtype
6943 if E
/= Base_Type
(E
) then
6945 -- Before we do anything else, a specific test for the case of a
6946 -- size given for an array where the array would need to be packed
6947 -- in order for the size to be honored, but is not. This is the
6948 -- case where implicit packing may apply. The reason we do this so
6949 -- early is that, if we have implicit packing, the layout of the
6950 -- base type is affected, so we must do this before we freeze the
6953 -- We could do this processing only if implicit packing is enabled
6954 -- since in all other cases, the error would be caught by the back
6955 -- end. However, we choose to do the check even if we do not have
6956 -- implicit packing enabled, since this allows us to give a more
6957 -- useful error message (advising use of pragma Implicit_Packing
6960 if Is_Array_Type
(E
) then
6962 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
6963 Rsiz
: constant Uint
:=
6964 (if Known_RM_Size
(Ctyp
) then RM_Size
(Ctyp
) else Uint_0
);
6965 SZ
: constant Node_Id
:= Size_Clause
(E
);
6966 Btyp
: constant Entity_Id
:= Base_Type
(E
);
6973 Num_Elmts
: Uint
:= Uint_1
;
6974 -- Number of elements in array
6977 -- Check enabling conditions. These are straightforward
6978 -- except for the test for a limited composite type. This
6979 -- eliminates the rare case of a array of limited components
6980 -- where there are issues of whether or not we can go ahead
6981 -- and pack the array (since we can't freely pack and unpack
6982 -- arrays if they are limited).
6984 -- Note that we check the root type explicitly because the
6985 -- whole point is we are doing this test before we have had
6986 -- a chance to freeze the base type (and it is that freeze
6987 -- action that causes stuff to be inherited).
6989 -- The conditions on the size are identical to those used in
6990 -- Freeze_Array_Type to set the Is_Packed flag.
6992 if Has_Size_Clause
(E
)
6993 and then Known_Static_RM_Size
(E
)
6994 and then not Is_Packed
(E
)
6995 and then not Has_Pragma_Pack
(E
)
6996 and then not Has_Component_Size_Clause
(E
)
6997 and then Known_Static_RM_Size
(Ctyp
)
6998 and then Rsiz
<= System_Max_Integer_Size
6999 and then not (Addressable
(Rsiz
)
7000 and then Known_Static_Esize
(Ctyp
)
7001 and then Esize
(Ctyp
) = Rsiz
)
7002 and then not (Rsiz
mod System_Storage_Unit
= 0
7003 and then Is_Composite_Type
(Ctyp
))
7004 and then not Is_Limited_Composite
(E
)
7005 and then not Is_Packed
(Root_Type
(E
))
7006 and then not Has_Component_Size_Clause
(Root_Type
(E
))
7007 and then not (CodePeer_Mode
or GNATprove_Mode
)
7009 -- Compute number of elements in array
7011 Indx
:= First_Index
(E
);
7012 while Present
(Indx
) loop
7013 Get_Index_Bounds
(Indx
, Lo
, Hi
);
7015 if not (Compile_Time_Known_Value
(Lo
)
7017 Compile_Time_Known_Value
(Hi
))
7019 goto No_Implicit_Packing
;
7022 Dim
:= Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1;
7024 if Dim
> Uint_0
then
7025 Num_Elmts
:= Num_Elmts
* Dim
;
7027 Num_Elmts
:= Uint_0
;
7033 -- What we are looking for here is the situation where
7034 -- the RM_Size given would be exactly right if there was
7035 -- a pragma Pack, resulting in the component size being
7036 -- the RM_Size of the component type.
7038 if RM_Size
(E
) = Num_Elmts
* Rsiz
then
7040 -- For implicit packing mode, just set the component
7041 -- size and Freeze_Array_Type will do the rest.
7043 if Implicit_Packing
then
7044 Set_Component_Size
(Btyp
, Rsiz
);
7046 -- Otherwise give an error message, except that if the
7047 -- specified Size is zero, there is no need for pragma
7048 -- Pack. Note that size zero is not considered
7051 elsif RM_Size
(E
) /= Uint_0
then
7053 ("size given for& too small", SZ
, E
);
7054 Error_Msg_N
-- CODEFIX
7055 ("\use explicit pragma Pack or use pragma "
7056 & "Implicit_Packing", SZ
);
7063 <<No_Implicit_Packing
>>
7065 -- If ancestor subtype present, freeze that first. Note that this
7066 -- will also get the base type frozen. Need RM reference ???
7068 Atype
:= Ancestor_Subtype
(E
);
7070 if Present
(Atype
) then
7071 Freeze_And_Append
(Atype
, N
, Result
);
7073 -- No ancestor subtype present
7076 -- See if we have a nearest ancestor that has a predicate.
7077 -- That catches the case of derived type with a predicate.
7078 -- Need RM reference here ???
7080 Atype
:= Nearest_Ancestor
(E
);
7082 if Present
(Atype
) and then Has_Predicates
(Atype
) then
7083 Freeze_And_Append
(Atype
, N
, Result
);
7086 -- Freeze base type before freezing the entity (RM 13.14(15))
7088 if E
/= Base_Type
(E
) then
7089 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
7093 -- A subtype inherits all the type-related representation aspects
7094 -- from its parents (RM 13.1(8)).
7096 if May_Inherit_Delayed_Rep_Aspects
(E
) then
7097 Inherit_Delayed_Rep_Aspects
(E
);
7100 Inherit_Aspects_At_Freeze_Point
(E
);
7102 -- For a derived type, freeze its parent type first (RM 13.14(15))
7104 elsif Is_Derived_Type
(E
) then
7105 Freeze_And_Append
(Etype
(E
), N
, Result
);
7107 -- A derived type inherits each type-related representation aspect
7108 -- of its parent type that was directly specified before the
7109 -- declaration of the derived type (RM 13.1(15)).
7111 if May_Inherit_Delayed_Rep_Aspects
(E
) then
7112 Inherit_Delayed_Rep_Aspects
(E
);
7115 Inherit_Aspects_At_Freeze_Point
(E
);
7118 -- Case of array type
7120 if Is_Array_Type
(E
) then
7121 Freeze_Array_Type
(E
);
7124 -- Check for incompatible size and alignment for array/record type
7126 if Warn_On_Size_Alignment
7127 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
7128 and then Has_Size_Clause
(E
)
7129 and then Has_Alignment_Clause
(E
)
7131 -- If explicit Object_Size clause given assume that the programmer
7132 -- knows what he is doing, and expects the compiler behavior.
7134 and then not Has_Object_Size_Clause
(E
)
7136 -- It does not really make sense to warn for the minimum alignment
7137 -- since the programmer could not get rid of the warning.
7139 and then Alignment
(E
) > 1
7141 -- Check for size not a multiple of alignment
7143 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
7146 SC
: constant Node_Id
:= Size_Clause
(E
);
7147 AC
: constant Node_Id
:= Alignment_Clause
(E
);
7149 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
7152 if Present
(SC
) and then Present
(AC
) then
7156 if Sloc
(SC
) > Sloc
(AC
) then
7159 ("?.z?size is not a multiple of alignment for &",
7161 Error_Msg_Sloc
:= Sloc
(AC
);
7162 Error_Msg_Uint_1
:= Alignment
(E
);
7163 Error_Msg_N
("\?.z?alignment of ^ specified #", Loc
);
7168 ("?.z?size is not a multiple of alignment for &",
7170 Error_Msg_Sloc
:= Sloc
(SC
);
7171 Error_Msg_Uint_1
:= RM_Size
(E
);
7172 Error_Msg_N
("\?.z?size of ^ specified #", Loc
);
7175 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
7176 Error_Msg_N
("\?.z?Object_Size will be increased to ^", Loc
);
7181 -- For a class-wide type, the corresponding specific type is
7182 -- frozen as well (RM 13.14(15))
7184 if Is_Class_Wide_Type
(E
) then
7185 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
7187 -- If the base type of the class-wide type is still incomplete,
7188 -- the class-wide remains unfrozen as well. This is legal when
7189 -- E is the formal of a primitive operation of some other type
7190 -- which is being frozen.
7192 if not Is_Frozen
(Root_Type
(E
)) then
7193 Set_Is_Frozen
(E
, False);
7197 -- The equivalent type associated with a class-wide subtype needs
7198 -- to be frozen to ensure that its layout is done.
7200 if Ekind
(E
) = E_Class_Wide_Subtype
7201 and then Present
(Equivalent_Type
(E
))
7203 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
7206 -- Generate an itype reference for a library-level class-wide type
7207 -- at the freeze point. Otherwise the first explicit reference to
7208 -- the type may appear in an inner scope which will be rejected by
7212 and then Is_Compilation_Unit
(Scope
(E
))
7215 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
7220 -- From a gigi point of view, a class-wide subtype derives
7221 -- from its record equivalent type. As a result, the itype
7222 -- reference must appear after the freeze node of the
7223 -- equivalent type or gigi will reject the reference.
7225 if Ekind
(E
) = E_Class_Wide_Subtype
7226 and then Present
(Equivalent_Type
(E
))
7228 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
7230 Add_To_Result
(Ref
);
7235 -- For a record type or record subtype, freeze all component types
7236 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
7237 -- using Is_Record_Type, because we don't want to attempt the freeze
7238 -- for the case of a private type with record extension (we will do
7239 -- that later when the full type is frozen).
7241 elsif Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
7242 if not In_Generic_Scope
(E
) then
7243 Freeze_Record_Type
(E
);
7246 -- Report a warning if a discriminated record base type has a
7247 -- convention with language C or C++ applied to it. This check is
7248 -- done even within generic scopes (but not in instantiations),
7249 -- which is why we don't do it as part of Freeze_Record_Type.
7251 Check_Suspicious_Convention
(E
);
7253 -- For a concurrent type, freeze corresponding record type. This does
7254 -- not correspond to any specific rule in the RM, but the record type
7255 -- is essentially part of the concurrent type. Also freeze all local
7256 -- entities. This includes record types created for entry parameter
7257 -- blocks and whatever local entities may appear in the private part.
7259 elsif Is_Concurrent_Type
(E
) then
7260 if Present
(Corresponding_Record_Type
(E
)) then
7261 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
7264 Comp
:= First_Entity
(E
);
7265 while Present
(Comp
) loop
7266 if Is_Type
(Comp
) then
7267 Freeze_And_Append
(Comp
, N
, Result
);
7269 elsif Ekind
(Comp
) /= E_Function
then
7271 -- The guard on the presence of the Etype seems to be needed
7272 -- for some CodePeer (-gnatcC) cases, but not clear why???
7274 if Present
(Etype
(Comp
)) then
7275 if Is_Itype
(Etype
(Comp
))
7276 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
7278 Undelay_Type
(Etype
(Comp
));
7281 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
7288 -- Private types are required to point to the same freeze node as
7289 -- their corresponding full views. The freeze node itself has to
7290 -- point to the partial view of the entity (because from the partial
7291 -- view, we can retrieve the full view, but not the reverse).
7292 -- However, in order to freeze correctly, we need to freeze the full
7293 -- view. If we are freezing at the end of a scope (or within the
7294 -- scope) of the private type, the partial and full views will have
7295 -- been swapped, the full view appears first in the entity chain and
7296 -- the swapping mechanism ensures that the pointers are properly set
7299 -- If we encounter the partial view before the full view (e.g. when
7300 -- freezing from another scope), we freeze the full view, and then
7301 -- set the pointers appropriately since we cannot rely on swapping to
7302 -- fix things up (subtypes in an outer scope might not get swapped).
7304 -- If the full view is itself private, the above requirements apply
7305 -- to the underlying full view instead of the full view. But there is
7306 -- no swapping mechanism for the underlying full view so we need to
7307 -- set the pointers appropriately in both cases.
7309 elsif Is_Incomplete_Or_Private_Type
(E
)
7310 and then not Is_Generic_Type
(E
)
7312 -- The construction of the dispatch table associated with library
7313 -- level tagged types forces freezing of all the primitives of the
7314 -- type, which may cause premature freezing of the partial view.
7318 -- type T is tagged private;
7319 -- type DT is new T with private;
7320 -- procedure Prim (X : in out T; Y : in out DT'Class);
7322 -- type T is tagged null record;
7324 -- type DT is new T with null record;
7327 -- In this case the type will be frozen later by the usual
7328 -- mechanism: an object declaration, an instantiation, or the
7329 -- end of a declarative part.
7331 if Is_Library_Level_Tagged_Type
(E
)
7332 and then No
(Full_View
(E
))
7334 Set_Is_Frozen
(E
, False);
7337 -- Case of full view present
7339 elsif Present
(Full_View
(E
)) then
7341 -- If full view has already been frozen, then no further
7342 -- processing is required
7344 if Is_Frozen
(Full_View
(E
)) then
7345 Set_Has_Delayed_Freeze
(E
, False);
7346 Set_Freeze_Node
(E
, Empty
);
7348 -- Otherwise freeze full view and patch the pointers so that
7349 -- the freeze node will elaborate both views in the back end.
7350 -- However, if full view is itself private, freeze underlying
7351 -- full view instead and patch the pointers so that the freeze
7352 -- node will elaborate the three views in the back end.
7356 Full
: Entity_Id
:= Full_View
(E
);
7359 if Is_Private_Type
(Full
)
7360 and then Present
(Underlying_Full_View
(Full
))
7362 Full
:= Underlying_Full_View
(Full
);
7365 Freeze_And_Append
(Full
, N
, Result
);
7367 if Full
/= Full_View
(E
)
7368 and then Has_Delayed_Freeze
(Full_View
(E
))
7370 F_Node
:= Freeze_Node
(Full
);
7372 if Present
(F_Node
) then
7374 (Fnod
=> F_Node
, Typ
=> Full_View
(E
));
7376 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
7377 Set_Freeze_Node
(Full_View
(E
), Empty
);
7381 if Has_Delayed_Freeze
(E
) then
7382 F_Node
:= Freeze_Node
(Full_View
(E
));
7384 if Present
(F_Node
) then
7385 Inherit_Freeze_Node
(Fnod
=> F_Node
, Typ
=> E
);
7387 -- {Incomplete,Private}_Subtypes with Full_Views
7388 -- constrained by discriminants.
7390 Set_Has_Delayed_Freeze
(E
, False);
7391 Set_Freeze_Node
(E
, Empty
);
7397 Check_Debug_Info_Needed
(E
);
7399 -- AI95-117 requires that the convention of a partial view be
7400 -- the same as the convention of the full view. Note that this
7401 -- is a recognized breach of privacy, but it's essential for
7402 -- logical consistency of representation, and the lack of a
7403 -- rule in RM95 was an oversight.
7405 Set_Convention
(E
, Convention
(Full_View
(E
)));
7407 Set_Size_Known_At_Compile_Time
(E
,
7408 Size_Known_At_Compile_Time
(Full_View
(E
)));
7410 -- Size information is copied from the full view to the
7411 -- incomplete or private view for consistency.
7413 -- We skip this is the full view is not a type. This is very
7414 -- strange of course, and can only happen as a result of
7415 -- certain illegalities, such as a premature attempt to derive
7416 -- from an incomplete type.
7418 if Is_Type
(Full_View
(E
)) then
7419 Set_Size_Info
(E
, Full_View
(E
));
7420 Copy_RM_Size
(To
=> E
, From
=> Full_View
(E
));
7425 -- Case of underlying full view present
7427 elsif Is_Private_Type
(E
)
7428 and then Present
(Underlying_Full_View
(E
))
7430 if not Is_Frozen
(Underlying_Full_View
(E
)) then
7431 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
7434 -- Patch the pointers so that the freeze node will elaborate
7435 -- both views in the back end.
7437 if Has_Delayed_Freeze
(E
) then
7438 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
7440 if Present
(F_Node
) then
7445 Set_Has_Delayed_Freeze
(E
, False);
7446 Set_Freeze_Node
(E
, Empty
);
7450 Check_Debug_Info_Needed
(E
);
7454 -- Case of no full view present. If entity is subtype or derived,
7455 -- it is safe to freeze, correctness depends on the frozen status
7456 -- of parent. Otherwise it is either premature usage, or a Taft
7457 -- amendment type, so diagnosis is at the point of use and the
7458 -- type might be frozen later.
7460 elsif E
/= Base_Type
(E
) then
7462 Btyp
: constant Entity_Id
:= Base_Type
(E
);
7465 -- However, if the base type is itself private and has no
7466 -- (underlying) full view either, wait until the full type
7467 -- declaration is seen and all the full views are created.
7469 if Is_Private_Type
(Btyp
)
7470 and then No
(Full_View
(Btyp
))
7471 and then No
(Underlying_Full_View
(Btyp
))
7472 and then Has_Delayed_Freeze
(Btyp
)
7473 and then No
(Freeze_Node
(Btyp
))
7475 Set_Is_Frozen
(E
, False);
7481 elsif Is_Derived_Type
(E
) then
7485 Set_Is_Frozen
(E
, False);
7490 -- For access subprogram, freeze types of all formals, the return
7491 -- type was already frozen, since it is the Etype of the function.
7492 -- Formal types can be tagged Taft amendment types, but otherwise
7493 -- they cannot be incomplete.
7495 elsif Ekind
(E
) = E_Subprogram_Type
then
7496 Formal
:= First_Formal
(E
);
7497 while Present
(Formal
) loop
7498 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
7499 and then No
(Full_View
(Etype
(Formal
)))
7501 if Is_Tagged_Type
(Etype
(Formal
)) then
7504 -- AI05-151: Incomplete types are allowed in access to
7505 -- subprogram specifications.
7507 elsif Ada_Version
< Ada_2012
then
7509 ("invalid use of incomplete type&", E
, Etype
(Formal
));
7513 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
7514 Next_Formal
(Formal
);
7517 Freeze_Subprogram
(E
);
7519 -- For access to a protected subprogram, freeze the equivalent type
7520 -- (however this is not set if we are not generating code or if this
7521 -- is an anonymous type used just for resolution).
7523 elsif Is_Access_Protected_Subprogram_Type
(E
) then
7524 if Present
(Equivalent_Type
(E
)) then
7525 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
7529 -- Generic types are never seen by the back-end, and are also not
7530 -- processed by the expander (since the expander is turned off for
7531 -- generic processing), so we never need freeze nodes for them.
7533 if Is_Generic_Type
(E
) then
7537 -- Some special processing for non-generic types to complete
7538 -- representation details not known till the freeze point.
7540 if Is_Fixed_Point_Type
(E
) then
7541 Freeze_Fixed_Point_Type
(E
);
7543 elsif Is_Enumeration_Type
(E
) then
7544 Freeze_Enumeration_Type
(E
);
7546 elsif Is_Integer_Type
(E
) then
7547 Adjust_Esize_For_Alignment
(E
);
7549 if Is_Modular_Integer_Type
(E
) then
7550 -- Standard_Address has been built with the assumption that its
7551 -- modulus was System_Address_Size, but this is not a universal
7552 -- property and may need to be corrected.
7554 if Is_RTE
(E
, RE_Address
) then
7555 Set_Modulus
(Standard_Address
, Modulus
(E
));
7557 (High_Bound
(Scalar_Range
(Standard_Address
)),
7560 elsif Warn_On_Suspicious_Modulus_Value
then
7561 Check_Suspicious_Modulus
(E
);
7565 -- The pool applies to named and anonymous access types, but not
7566 -- to subprogram and to internal types generated for 'Access
7569 elsif Is_Access_Object_Type
(E
)
7570 and then Ekind
(E
) /= E_Access_Attribute_Type
7572 -- If a pragma Default_Storage_Pool applies, and this type has no
7573 -- Storage_Pool or Storage_Size clause (which must have occurred
7574 -- before the freezing point), then use the default. This applies
7575 -- only to base types.
7577 -- None of this applies to access to subprograms, for which there
7578 -- are clearly no pools.
7580 if Present
(Default_Pool
)
7581 and then Is_Base_Type
(E
)
7582 and then not Has_Storage_Size_Clause
(E
)
7583 and then No
(Associated_Storage_Pool
(E
))
7585 -- Case of pragma Default_Storage_Pool (null)
7587 if Nkind
(Default_Pool
) = N_Null
then
7588 Set_No_Pool_Assigned
(E
);
7590 -- Case of pragma Default_Storage_Pool (Standard)
7592 elsif Entity
(Default_Pool
) = Standard_Standard
then
7593 Set_Associated_Storage_Pool
(E
, RTE
(RE_Global_Pool_Object
));
7595 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
7598 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
7602 -- Check restriction for standard storage pool
7604 if No
(Associated_Storage_Pool
(E
)) then
7605 Check_Restriction
(No_Standard_Storage_Pools
, E
);
7608 -- Deal with error message for pure access type. This is not an
7609 -- error in Ada 2005 if there is no pool (see AI-366).
7611 if Is_Pure_Unit_Access_Type
(E
)
7612 and then (Ada_Version
< Ada_2005
7613 or else not No_Pool_Assigned
(E
))
7614 and then not Is_Generic_Unit
(Scope
(E
))
7616 Error_Msg_N
("named access type not allowed in pure unit", E
);
7618 if Ada_Version
>= Ada_2005
then
7620 ("\would be legal if Storage_Size of 0 given", E
);
7622 elsif No_Pool_Assigned
(E
) then
7624 ("\would be legal in Ada 2005", E
);
7628 ("\would be legal in Ada 2005 if "
7629 & "Storage_Size of 0 given", E
);
7634 -- Case of composite types
7636 if Is_Composite_Type
(E
) then
7638 -- AI95-117 requires that all new primitives of a tagged type
7639 -- must inherit the convention of the full view of the
7640 -- type. Inherited and overriding operations are defined to
7641 -- inherit the convention of their parent or overridden
7642 -- subprogram (also specified in AI-117), which will have
7643 -- occurred earlier (in Derive_Subprogram and
7644 -- New_Overloaded_Entity). Here we set the convention of
7645 -- primitives that are still convention Ada, which will ensure
7646 -- that any new primitives inherit the type's convention. We
7647 -- don't do this for primitives that are internal to avoid
7648 -- potential problems in the case of nested subprograms and
7649 -- convention C. In addition, class-wide types can have a
7650 -- foreign convention inherited from their specific type, but
7651 -- are excluded from this since they don't have any associated
7654 if Is_Tagged_Type
(E
)
7655 and then not Is_Class_Wide_Type
(E
)
7656 and then Convention
(E
) /= Convention_Ada
7659 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
7663 Prim
:= First_Elmt
(Prim_List
);
7664 while Present
(Prim
) loop
7665 if Convention
(Node
(Prim
)) = Convention_Ada
7666 and then Comes_From_Source
(Node
(Prim
))
7668 Set_Convention
(Node
(Prim
), Convention
(E
));
7676 -- If the type is a simple storage pool type, then this is where
7677 -- we attempt to locate and validate its Allocate, Deallocate, and
7678 -- Storage_Size operations (the first is required, and the latter
7679 -- two are optional). We also verify that the full type for a
7680 -- private type is allowed to be a simple storage pool type.
7682 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
7683 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
7685 -- If the type is marked Has_Private_Declaration, then this is
7686 -- a full type for a private type that was specified with the
7687 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
7688 -- pragma is allowed for the full type (for example, it can't
7689 -- be an array type, or a nonlimited record type).
7691 if Has_Private_Declaration
(E
) then
7692 if (not Is_Record_Type
(E
)
7693 or else not Is_Inherently_Limited_Type
(E
))
7694 and then not Is_Private_Type
(E
)
7696 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
7698 ("pragma% can only apply to full type that is an " &
7699 "explicitly limited type", E
);
7703 Validate_Simple_Pool_Ops
: declare
7704 Pool_Type
: Entity_Id
renames E
;
7705 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
7706 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
7708 procedure Validate_Simple_Pool_Op_Formal
7709 (Pool_Op
: Entity_Id
;
7710 Pool_Op_Formal
: in out Entity_Id
;
7711 Expected_Mode
: Formal_Kind
;
7712 Expected_Type
: Entity_Id
;
7713 Formal_Name
: String;
7714 OK_Formal
: in out Boolean);
7715 -- Validate one formal Pool_Op_Formal of the candidate pool
7716 -- operation Pool_Op. The formal must be of Expected_Type
7717 -- and have mode Expected_Mode. OK_Formal will be set to
7718 -- False if the formal doesn't match. If OK_Formal is False
7719 -- on entry, then the formal will effectively be ignored
7720 -- (because validation of the pool op has already failed).
7721 -- Upon return, Pool_Op_Formal will be updated to the next
7724 procedure Validate_Simple_Pool_Operation
7725 (Op_Name
: Name_Id
);
7726 -- Search for and validate a simple pool operation with the
7727 -- name Op_Name. If the name is Allocate, then there must be
7728 -- exactly one such primitive operation for the simple pool
7729 -- type. If the name is Deallocate or Storage_Size, then
7730 -- there can be at most one such primitive operation. The
7731 -- profile of the located primitive must conform to what
7732 -- is expected for each operation.
7734 ------------------------------------
7735 -- Validate_Simple_Pool_Op_Formal --
7736 ------------------------------------
7738 procedure Validate_Simple_Pool_Op_Formal
7739 (Pool_Op
: Entity_Id
;
7740 Pool_Op_Formal
: in out Entity_Id
;
7741 Expected_Mode
: Formal_Kind
;
7742 Expected_Type
: Entity_Id
;
7743 Formal_Name
: String;
7744 OK_Formal
: in out Boolean)
7747 -- If OK_Formal is False on entry, then simply ignore
7748 -- the formal, because an earlier formal has already
7751 if not OK_Formal
then
7754 -- If no formal is passed in, then issue an error for a
7757 elsif No
(Pool_Op_Formal
) then
7759 ("simple storage pool op missing formal " &
7760 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
7766 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
7768 -- If the pool type was expected for this formal, then
7769 -- this will not be considered a candidate operation
7770 -- for the simple pool, so we unset OK_Formal so that
7771 -- the op and any later formals will be ignored.
7773 if Expected_Type
= Pool_Type
then
7780 ("wrong type for formal " & Formal_Name
&
7781 " of simple storage pool op; expected type&",
7782 Pool_Op_Formal
, Expected_Type
);
7786 -- Issue error if formal's mode is not the expected one
7788 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
7790 ("wrong mode for formal of simple storage pool op",
7794 -- Advance to the next formal
7796 Next_Formal
(Pool_Op_Formal
);
7797 end Validate_Simple_Pool_Op_Formal
;
7799 ------------------------------------
7800 -- Validate_Simple_Pool_Operation --
7801 ------------------------------------
7803 procedure Validate_Simple_Pool_Operation
7807 Found_Op
: Entity_Id
:= Empty
;
7813 (Op_Name
in Name_Allocate
7815 | Name_Storage_Size
);
7817 Error_Msg_Name_1
:= Op_Name
;
7819 -- For each homonym declared immediately in the scope
7820 -- of the simple storage pool type, determine whether
7821 -- the homonym is an operation of the pool type, and,
7822 -- if so, check that its profile is as expected for
7823 -- a simple pool operation of that name.
7825 Op
:= Get_Name_Entity_Id
(Op_Name
);
7826 while Present
(Op
) loop
7827 if Ekind
(Op
) in E_Function | E_Procedure
7828 and then Scope
(Op
) = Current_Scope
7830 Formal
:= First_Entity
(Op
);
7834 -- The first parameter must be of the pool type
7835 -- in order for the operation to qualify.
7837 if Op_Name
= Name_Storage_Size
then
7838 Validate_Simple_Pool_Op_Formal
7839 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
7842 Validate_Simple_Pool_Op_Formal
7843 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
7847 -- If another operation with this name has already
7848 -- been located for the type, then flag an error,
7849 -- since we only allow the type to have a single
7852 if Present
(Found_Op
) and then Is_OK
then
7854 ("only one % operation allowed for " &
7855 "simple storage pool type&", Op
, Pool_Type
);
7858 -- In the case of Allocate and Deallocate, a formal
7859 -- of type System.Address is required.
7861 if Op_Name
= Name_Allocate
then
7862 Validate_Simple_Pool_Op_Formal
7863 (Op
, Formal
, E_Out_Parameter
,
7864 Address_Type
, "Storage_Address", Is_OK
);
7866 elsif Op_Name
= Name_Deallocate
then
7867 Validate_Simple_Pool_Op_Formal
7868 (Op
, Formal
, E_In_Parameter
,
7869 Address_Type
, "Storage_Address", Is_OK
);
7872 -- In the case of Allocate and Deallocate, formals
7873 -- of type Storage_Count are required as the third
7874 -- and fourth parameters.
7876 if Op_Name
/= Name_Storage_Size
then
7877 Validate_Simple_Pool_Op_Formal
7878 (Op
, Formal
, E_In_Parameter
,
7879 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
7880 Validate_Simple_Pool_Op_Formal
7881 (Op
, Formal
, E_In_Parameter
,
7882 Stg_Cnt_Type
, "Alignment", Is_OK
);
7885 -- If no mismatched formals have been found (Is_OK)
7886 -- and no excess formals are present, then this
7887 -- operation has been validated, so record it.
7889 if No
(Formal
) and then Is_OK
then
7897 -- There must be a valid Allocate operation for the type,
7898 -- so issue an error if none was found.
7900 if Op_Name
= Name_Allocate
7901 and then No
(Found_Op
)
7903 Error_Msg_N
("missing % operation for simple " &
7904 "storage pool type", Pool_Type
);
7906 elsif Present
(Found_Op
) then
7908 -- Simple pool operations can't be abstract
7910 if Is_Abstract_Subprogram
(Found_Op
) then
7912 ("simple storage pool operation must not be " &
7913 "abstract", Found_Op
);
7916 -- The Storage_Size operation must be a function with
7917 -- Storage_Count as its result type.
7919 if Op_Name
= Name_Storage_Size
then
7920 if Ekind
(Found_Op
) = E_Procedure
then
7922 ("% operation must be a function", Found_Op
);
7924 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
7926 ("wrong result type for%, expected type&",
7927 Found_Op
, Stg_Cnt_Type
);
7930 -- Allocate and Deallocate must be procedures
7932 elsif Ekind
(Found_Op
) = E_Function
then
7934 ("% operation must be a procedure", Found_Op
);
7937 end Validate_Simple_Pool_Operation
;
7939 -- Start of processing for Validate_Simple_Pool_Ops
7942 Validate_Simple_Pool_Operation
(Name_Allocate
);
7943 Validate_Simple_Pool_Operation
(Name_Deallocate
);
7944 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
7945 end Validate_Simple_Pool_Ops
;
7949 -- Now that all types from which E may depend are frozen, see if
7950 -- strict alignment is required, a component clause on a record
7951 -- is correct, the size is known at compile time and if it must
7952 -- be unsigned, in that order.
7954 if Base_Type
(E
) = E
then
7955 Check_Strict_Alignment
(E
);
7958 if Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
7960 RC
: constant Node_Id
:= Get_Record_Representation_Clause
(E
);
7962 if Present
(RC
) then
7963 Check_Record_Representation_Clause
(RC
);
7968 Check_Compile_Time_Size
(E
);
7970 Check_Unsigned_Type
(E
);
7972 -- Do not allow a size clause for a type which does not have a size
7973 -- that is known at compile time
7975 if (Has_Size_Clause
(E
) or else Has_Object_Size_Clause
(E
))
7976 and then not Size_Known_At_Compile_Time
(E
)
7977 and then not Is_Mutably_Tagged_Type
(E
)
7979 -- Suppress this message if errors posted on E, even if we are
7980 -- in all errors mode, since this is often a junk message
7982 if not Error_Posted
(E
) then
7984 ("size clause not allowed for variable length type",
7989 -- Now we set/verify the representation information, in particular
7990 -- the size and alignment values. This processing is not required for
7991 -- generic types, since generic types do not play any part in code
7992 -- generation, and so the size and alignment values for such types
7993 -- are irrelevant. Ditto for types declared within a generic unit,
7994 -- which may have components that depend on generic parameters, and
7995 -- that will be recreated in an instance.
7997 if Inside_A_Generic
then
8000 -- Otherwise we call the layout procedure
8006 -- If this is an access to subprogram whose designated type is itself
8007 -- a subprogram type, the return type of this anonymous subprogram
8008 -- type must be decorated as well.
8010 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
8011 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
8013 Layout_Type
(Etype
(Designated_Type
(E
)));
8016 -- If the type has a Defaut_Value/Default_Component_Value aspect,
8017 -- this is where we analyze the expression (after the type is frozen,
8018 -- since in the case of Default_Value, we are analyzing with the
8019 -- type itself, and we treat Default_Component_Value similarly for
8020 -- the sake of uniformity).
8022 -- But for an inherited Default_Value aspect specification, the type
8023 -- of the aspect remains the parent type. RM 3.3.1(11.1), a dynamic
8024 -- semantics rule, says "The implicit initial value for a scalar
8025 -- subtype that has the Default_Value aspect specified is the value
8026 -- of that aspect converted to the nominal subtype". For an inherited
8027 -- Default_Value aspect specification, no conversion is evaluated at
8028 -- the point of the derived type declaration.
8030 if Is_First_Subtype
(E
)
8031 and then Has_Default_Aspect
(E
)
8033 (not Is_Scalar_Type
(E
)
8035 not Is_Derived_Type
(E
)
8037 Default_Aspect_Value
(E
)
8038 /= Default_Aspect_Value
(Etype
(Base_Type
(E
))))
8046 if Is_Scalar_Type
(E
) then
8047 Nam
:= Name_Default_Value
;
8049 Exp
:= Default_Aspect_Value
(Typ
);
8051 Nam
:= Name_Default_Component_Value
;
8052 Typ
:= Component_Type
(E
);
8053 Exp
:= Default_Aspect_Component_Value
(E
);
8056 Analyze_And_Resolve
(Exp
, Typ
);
8058 if Etype
(Exp
) /= Any_Type
then
8059 if not Is_OK_Static_Expression
(Exp
) then
8060 Error_Msg_Name_1
:= Nam
;
8061 Flag_Non_Static_Expr
8062 ("aspect% requires static expression", Exp
);
8068 -- Verify at this point that No_Controlled_Parts and No_Task_Parts,
8069 -- when specified on the current type or one of its ancestors, has
8070 -- not been overridden and that no violation of the aspect has
8073 -- It is important that we perform the checks here after the type has
8074 -- been processed because if said type depended on a private type it
8075 -- will not have been marked controlled or having tasks.
8077 Check_No_Parts_Violations
(E
, Aspect_No_Controlled_Parts
);
8078 Check_No_Parts_Violations
(E
, Aspect_No_Task_Parts
);
8080 -- End of freeze processing for type entities
8083 -- Here is where we logically freeze the current entity. If it has a
8084 -- freeze node, then this is the point at which the freeze node is
8085 -- linked into the result list.
8087 if Has_Delayed_Freeze
(E
) then
8089 -- If a freeze node is already allocated, use it, otherwise allocate
8090 -- a new one. The preallocation happens in the case of anonymous base
8091 -- types, where we preallocate so that we can set First_Subtype_Link.
8092 -- Note that we reset the Sloc to the current freeze location.
8094 if Present
(Freeze_Node
(E
)) then
8095 F_Node
:= Freeze_Node
(E
);
8096 Set_Sloc
(F_Node
, Loc
);
8099 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
8100 Set_Freeze_Node
(E
, F_Node
);
8101 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
8102 Set_TSS_Elist
(F_Node
, No_Elist
);
8103 Set_Actions
(F_Node
, No_List
);
8106 Set_Entity
(F_Node
, E
);
8107 Add_To_Result
(F_Node
);
8109 -- A final pass over record types with discriminants. If the type
8110 -- has an incomplete declaration, there may be constrained access
8111 -- subtypes declared elsewhere, which do not depend on the discrimi-
8112 -- nants of the type, and which are used as component types (i.e.
8113 -- the full view is a recursive type). The designated types of these
8114 -- subtypes can only be elaborated after the type itself, and they
8115 -- need an itype reference.
8117 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
8124 Comp
:= First_Component
(E
);
8125 while Present
(Comp
) loop
8126 Typ
:= Etype
(Comp
);
8128 if Is_Access_Type
(Typ
)
8129 and then Scope
(Typ
) /= E
8130 and then Base_Type
(Designated_Type
(Typ
)) = E
8131 and then Is_Itype
(Designated_Type
(Typ
))
8133 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
8134 Set_Itype
(IR
, Designated_Type
(Typ
));
8135 Append
(IR
, Result
);
8138 Next_Component
(Comp
);
8144 -- When a type is frozen, the first subtype of the type is frozen as
8145 -- well (RM 13.14(15)). This has to be done after freezing the type,
8146 -- since obviously the first subtype depends on its own base type.
8149 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
8151 -- If we just froze a tagged non-class-wide record, then freeze the
8152 -- corresponding class-wide type. This must be done after the tagged
8153 -- type itself is frozen, because the class-wide type refers to the
8154 -- tagged type which generates the class.
8156 -- For a tagged type, freeze explicitly those primitive operations
8157 -- that are expression functions, which otherwise have no clear
8158 -- freeze point: these have to be frozen before the dispatch table
8159 -- for the type is built, and before any explicit call to the
8160 -- primitive, which would otherwise be the freeze point for it.
8162 if Is_Tagged_Type
(E
)
8163 and then not Is_Class_Wide_Type
(E
)
8164 and then Present
(Class_Wide_Type
(E
))
8166 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
8169 Ops
: constant Elist_Id
:= Primitive_Operations
(E
);
8175 if Ops
/= No_Elist
then
8176 Elmt
:= First_Elmt
(Ops
);
8177 while Present
(Elmt
) loop
8178 Subp
:= Node
(Elmt
);
8179 if Is_Expression_Function
(Subp
) then
8180 Freeze_And_Append
(Subp
, N
, Result
);
8190 Check_Debug_Info_Needed
(E
);
8192 -- If subprogram has address clause then reset Is_Public flag, since we
8193 -- do not want the backend to generate external references.
8195 if Is_Subprogram
(E
)
8196 and then Present
(Address_Clause
(E
))
8197 and then not Is_Library_Level_Entity
(E
)
8199 Set_Is_Public
(E
, False);
8202 -- The Ghost mode of the enclosing context is ignored, while the
8203 -- entity being frozen is living. Insert the freezing action prior
8204 -- to the start of the enclosing ignored Ghost region. As a result
8205 -- the freezeing action will be preserved when the ignored Ghost
8206 -- context is eliminated. The insertion must take place even when
8207 -- the context is a spec expression, otherwise "Handling of Default
8208 -- and Per-Object Expressions" will suppress the insertion, and the
8209 -- freeze node will be dropped on the floor.
8211 if Saved_GM
= Ignore
8212 and then Ghost_Mode
/= Ignore
8213 and then Present
(Ignored_Ghost_Region
)
8216 (Assoc_Node
=> Ignored_Ghost_Region
,
8217 Ins_Actions
=> Result
,
8218 Spec_Expr_OK
=> True);
8224 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
8229 -----------------------------
8230 -- Freeze_Enumeration_Type --
8231 -----------------------------
8233 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
8235 -- By default, if no size clause is present, an enumeration type with
8236 -- Convention C is assumed to interface to a C enum and has integer
8237 -- size, except for a boolean type because it is assumed to interface
8238 -- to _Bool introduced in C99. This applies to types. For subtypes,
8239 -- verify that its base type has no size clause either. Treat other
8240 -- foreign conventions in the same way, and also make sure alignment
8243 if Has_Foreign_Convention
(Typ
)
8244 and then not Is_Boolean_Type
(Typ
)
8245 and then not Has_Size_Clause
(Typ
)
8246 and then not Has_Size_Clause
(Base_Type
(Typ
))
8247 and then Esize
(Typ
) < Standard_Integer_Size
8249 -- Don't do this if Short_Enums on target
8251 and then not Target_Short_Enums
8253 Set_Esize
(Typ
, UI_From_Int
(Standard_Integer_Size
));
8254 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
8256 -- Normal Ada case or size clause present or not Long_C_Enums on target
8259 -- If the enumeration type interfaces to C, and it has a size clause
8260 -- that is smaller than the size of int, it warrants a warning. The
8261 -- user may intend the C type to be a boolean or a char, so this is
8262 -- not by itself an error that the Ada compiler can detect, but it
8263 -- is worth a heads-up. For Boolean and Character types we
8264 -- assume that the programmer has the proper C type in mind.
8265 -- For explicit sizes larger than int, assume the user knows what
8266 -- he is doing and that the code is intentional.
8268 if Convention
(Typ
) = Convention_C
8269 and then Has_Size_Clause
(Typ
)
8270 and then Esize
(Typ
) < Standard_Integer_Size
8271 and then not Is_Boolean_Type
(Typ
)
8272 and then not Is_Character_Type
(Typ
)
8274 -- Don't do this if Short_Enums on target
8276 and then not Target_Short_Enums
8279 ("??the size of enums in C is implementation-defined",
8282 ("\??check that the C counterpart has size of " &
8283 UI_Image
(Esize
(Typ
)),
8287 Adjust_Esize_For_Alignment
(Typ
);
8290 -- Reject a very large size on a type with a non-standard representation
8291 -- because Expand_Freeze_Enumeration_Type cannot deal with it.
8293 if Has_Non_Standard_Rep
(Typ
)
8294 and then Known_Esize
(Typ
)
8295 and then Esize
(Typ
) > System_Max_Integer_Size
8298 ("enumeration type with representation clause too large", Typ
);
8299 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Integer_Size
);
8301 ("\the size of such a type cannot exceed ^ bits", Typ
);
8303 end Freeze_Enumeration_Type
;
8305 -----------------------
8306 -- Freeze_Expression --
8307 -----------------------
8309 procedure Freeze_Expression
(N
: Node_Id
) is
8311 function Declared_In_Expanded_Body
8314 Nam
: Entity_Id
) return Boolean;
8315 -- Given the N_Handled_Sequence_Of_Statements node of an expander
8316 -- generated subprogram body, determines if the frozen entity is
8317 -- declared inside this body. This is recognized locating the
8318 -- enclosing subprogram of the entity Name or its Type and
8319 -- checking if it is this subprogram body.
8321 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
8322 -- If the expression is an array aggregate, the type of the component
8323 -- expressions is also frozen. If the component type is an access type
8324 -- and the expressions include allocators, the designed type is frozen
8327 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
8328 -- Given an N_Handled_Sequence_Of_Statements node, determines whether it
8329 -- is the statement sequence of an expander-generated subprogram: body
8330 -- created for an expression function, for a predicate function, an init
8331 -- proc, a stream subprogram, or a renaming as body. If so, this is not
8332 -- a freezing context and the entity will be frozen at a later point.
8334 function Has_Decl_In_List
8337 L
: List_Id
) return Boolean;
8338 -- Determines whether an entity E referenced in node N is declared in
8341 -------------------------------
8342 -- Declared_In_Expanded_Body --
8343 -------------------------------
8345 function Declared_In_Expanded_Body
8348 Nam
: Entity_Id
) return Boolean
8350 pragma Assert
(In_Expanded_Body
(N
));
8352 Subp_Body
: constant Node_Id
:= Parent
(N
);
8353 Subp_Id
: Entity_Id
;
8357 if Acts_As_Spec
(Subp_Body
) then
8358 Subp_Id
:= Unique_Defining_Entity
(Specification
(Subp_Body
));
8360 Subp_Id
:= Corresponding_Spec
(Subp_Body
);
8363 if Present
(Typ
) then
8364 Scop
:= Scope
(Typ
);
8365 elsif Present
(Nam
) then
8366 Scop
:= Scope
(Nam
);
8368 Scop
:= Standard_Standard
;
8371 while Scop
/= Standard_Standard
8372 and then not Is_Subprogram
(Scop
)
8374 Scop
:= Scope
(Scop
);
8377 return Scop
= Subp_Id
;
8378 end Declared_In_Expanded_Body
;
8380 -----------------------------------------
8381 -- Find_Aggregate_Component_Desig_Type --
8382 -----------------------------------------
8384 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
8389 if Present
(Expressions
(N
)) then
8390 Exp
:= First
(Expressions
(N
));
8391 while Present
(Exp
) loop
8392 if Nkind
(Exp
) = N_Allocator
then
8393 return Designated_Type
(Component_Type
(Etype
(N
)));
8400 if Present
(Component_Associations
(N
)) then
8401 Assoc
:= First
(Component_Associations
(N
));
8402 while Present
(Assoc
) loop
8403 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
8404 return Designated_Type
(Component_Type
(Etype
(N
)));
8412 end Find_Aggregate_Component_Desig_Type
;
8414 ----------------------
8415 -- In_Expanded_Body --
8416 ----------------------
8418 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
8419 P
: constant Node_Id
:= Parent
(N
);
8423 if Nkind
(P
) /= N_Subprogram_Body
then
8426 -- Treat the generated body of an expression function like other
8427 -- bodies generated during expansion (e.g. stream subprograms) so
8428 -- that those bodies are not treated as freezing points.
8430 elsif Was_Expression_Function
(P
) then
8431 pragma Assert
(not Comes_From_Source
(P
));
8434 -- This is the body of a generated predicate function
8436 elsif Present
(Corresponding_Spec
(P
))
8437 and then Is_Predicate_Function
(Corresponding_Spec
(P
))
8442 Id
:= Defining_Unit_Name
(Specification
(P
));
8444 -- The following are expander-created bodies, or bodies that
8445 -- are not freeze points.
8447 if Nkind
(Id
) = N_Defining_Identifier
8448 and then (Is_Init_Proc
(Id
)
8449 or else Is_TSS
(Id
, TSS_Stream_Input
)
8450 or else Is_TSS
(Id
, TSS_Stream_Output
)
8451 or else Is_TSS
(Id
, TSS_Stream_Read
)
8452 or else Is_TSS
(Id
, TSS_Stream_Write
)
8453 or else Is_TSS
(Id
, TSS_Put_Image
)
8454 or else Nkind
(Original_Node
(P
)) =
8455 N_Subprogram_Renaming_Declaration
)
8462 end In_Expanded_Body
;
8464 ----------------------
8465 -- Has_Decl_In_List --
8466 ----------------------
8468 function Has_Decl_In_List
8471 L
: List_Id
) return Boolean
8473 Decl_Node
: Node_Id
;
8476 -- If E is an itype, pretend that it is declared in N except for a
8477 -- class-wide subtype with an equivalent type, because this latter
8478 -- type comes with a bona-fide declaration node.
8480 if Is_Itype
(E
) then
8481 if Ekind
(E
) = E_Class_Wide_Subtype
8482 and then Present
(Equivalent_Type
(E
))
8484 Decl_Node
:= Declaration_Node
(Equivalent_Type
(E
));
8490 Decl_Node
:= Declaration_Node
(E
);
8493 return Is_List_Member
(Decl_Node
)
8494 and then List_Containing
(Decl_Node
) = L
;
8495 end Has_Decl_In_List
;
8499 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
8501 Desig_Typ
: Entity_Id
;
8507 Allocator_Typ
: Entity_Id
:= Empty
;
8509 Freeze_Outside_Subp
: Entity_Id
:= Empty
;
8510 -- This entity is set if we are inside a subprogram body and the frozen
8511 -- entity is defined in the enclosing scope of this subprogram. In such
8512 -- case we must skip the subprogram body when climbing the parents chain
8513 -- to locate the correct placement for the freezing node.
8515 -- Start of processing for Freeze_Expression
8518 -- Immediate return if freezing is inhibited. This flag is set by the
8519 -- analyzer to stop freezing on generated expressions that would cause
8520 -- freezing if they were in the source program, but which are not
8521 -- supposed to freeze, since they are created.
8523 if Must_Not_Freeze
(N
) then
8527 -- If expression is non-static, then it does not freeze in a default
8528 -- expression, see section "Handling of Default Expressions" in the
8529 -- spec of package Sem for further details. Note that we have to make
8530 -- sure that we actually have a real expression (if we have a subtype
8531 -- indication, we can't test Is_OK_Static_Expression). However, we
8532 -- exclude the case of the prefix of an attribute of a static scalar
8533 -- subtype from this early return, because static subtype attributes
8534 -- should always cause freezing, even in default expressions, but
8535 -- the attribute may not have been marked as static yet (because in
8536 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
8537 -- Freeze_Expression on the prefix).
8540 and then Nkind
(N
) in N_Subexpr
8541 and then not Is_OK_Static_Expression
(N
)
8542 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
8543 or else not (Is_Entity_Name
(N
)
8544 and then Is_Type
(Entity
(N
))
8545 and then Is_OK_Static_Subtype
(Entity
(N
))))
8550 -- Freeze type of expression if not frozen already
8554 if Nkind
(N
) in N_Has_Etype
and then Present
(Etype
(N
)) then
8555 if not Is_Frozen
(Etype
(N
)) then
8558 -- Base type may be an derived numeric type that is frozen at the
8559 -- point of declaration, but first_subtype is still unfrozen.
8561 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
8562 Typ
:= First_Subtype
(Etype
(N
));
8566 -- For entity name, freeze entity if not frozen already. A special
8567 -- exception occurs for an identifier that did not come from source.
8568 -- We don't let such identifiers freeze a non-internal entity, i.e.
8569 -- an entity that did come from source, since such an identifier was
8570 -- generated by the expander, and cannot have any semantic effect on
8571 -- the freezing semantics. For example, this stops the parameter of
8572 -- an initialization procedure from freezing the variable.
8574 if Is_Entity_Name
(N
)
8575 and then Present
(Entity
(N
))
8576 and then not Is_Frozen
(Entity
(N
))
8577 and then (Nkind
(N
) /= N_Identifier
8578 or else Comes_From_Source
(N
)
8579 or else not Comes_From_Source
(Entity
(N
)))
8583 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
8584 Check_Expression_Function
(N
, Nam
);
8591 -- For an allocator freeze designated type if not frozen already
8593 -- For an aggregate whose component type is an access type, freeze the
8594 -- designated type now, so that its freeze does not appear within the
8595 -- loop that might be created in the expansion of the aggregate. If the
8596 -- designated type is a private type without full view, the expression
8597 -- cannot contain an allocator, so the type is not frozen.
8599 -- For a function, we freeze the entity when the subprogram declaration
8600 -- is frozen, but a function call may appear in an initialization proc.
8601 -- before the declaration is frozen. We need to generate the extra
8602 -- formals, if any, to ensure that the expansion of the call includes
8603 -- the proper actuals. This only applies to Ada subprograms, not to
8610 Desig_Typ
:= Designated_Type
(Etype
(N
));
8612 if Nkind
(Expression
(N
)) = N_Qualified_Expression
then
8613 Allocator_Typ
:= Entity
(Subtype_Mark
(Expression
(N
)));
8617 if Is_Array_Type
(Etype
(N
))
8618 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
8620 -- Check whether aggregate includes allocators
8622 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
8625 when N_Indexed_Component
8626 | N_Selected_Component
8629 if Is_Access_Type
(Etype
(Prefix
(N
))) then
8630 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
8633 when N_Identifier
=>
8635 and then Ekind
(Nam
) = E_Function
8636 and then Nkind
(Parent
(N
)) = N_Function_Call
8637 and then not Has_Foreign_Convention
(Nam
)
8639 Create_Extra_Formals
(Nam
);
8646 if Desig_Typ
/= Empty
8647 and then (Is_Frozen
(Desig_Typ
)
8648 or else not Is_Fully_Defined
(Desig_Typ
))
8653 -- All done if nothing needs freezing
8657 and then No
(Desig_Typ
)
8658 and then No
(Allocator_Typ
)
8663 -- Check if we are inside a subprogram body and the frozen entity is
8664 -- defined in the enclosing scope of this subprogram. In such case we
8665 -- must skip the subprogram when climbing the parents chain to locate
8666 -- the correct placement for the freezing node.
8668 -- This is not needed for default expressions and other spec expressions
8669 -- in generic units since the Move_Freeze_Nodes mechanism (sem_ch12.adb)
8670 -- takes care of placing them at the proper place, after the generic
8674 and then Scope
(Nam
) /= Current_Scope
8675 and then not (In_Spec_Exp
and then Inside_A_Generic
)
8678 S
: Entity_Id
:= Current_Scope
;
8682 and then In_Same_Source_Unit
(Nam
, S
)
8684 if Scope
(S
) = Scope
(Nam
) then
8685 if Is_Subprogram
(S
) and then Has_Completion
(S
) then
8686 Freeze_Outside_Subp
:= S
;
8697 -- Examine the enclosing context by climbing the parent chain
8699 -- If we identified that we must freeze the entity outside of a given
8700 -- subprogram then we just climb up to that subprogram checking if some
8701 -- enclosing node is marked as Must_Not_Freeze (since in such case we
8702 -- must not freeze yet this entity).
8706 if Present
(Freeze_Outside_Subp
) then
8708 -- Do not freeze the current expression if another expression in
8709 -- the chain of parents must not be frozen.
8711 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8715 Parent_P
:= Parent
(P
);
8717 -- If we don't have a parent, then we are not in a well-formed
8718 -- tree. This is an unusual case, but there are some legitimate
8719 -- situations in which this occurs, notably when the expressions
8720 -- in the range of a type declaration are resolved. We simply
8721 -- ignore the freeze request in this case.
8723 if No
(Parent_P
) then
8727 -- If the parent is a subprogram body, the candidate insertion
8728 -- point is just ahead of it.
8730 if Nkind
(Parent_P
) = N_Subprogram_Body
8731 and then Unique_Defining_Entity
(Parent_P
) =
8741 -- Otherwise the traversal serves two purposes - to detect scenarios
8742 -- where freezeing is not needed and to find the proper insertion point
8743 -- for the freeze nodes. Although somewhat similar to Insert_Actions,
8744 -- this traversal is freezing semantics-sensitive. Inserting freeze
8745 -- nodes blindly in the tree may result in types being frozen too early.
8749 -- Do not freeze the current expression if another expression in
8750 -- the chain of parents must not be frozen.
8752 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8756 Parent_P
:= Parent
(P
);
8758 -- If we don't have a parent, then we are not in a well-formed
8759 -- tree. This is an unusual case, but there are some legitimate
8760 -- situations in which this occurs, notably when the expressions
8761 -- in the range of a type declaration are resolved. We simply
8762 -- ignore the freeze request in this case.
8764 if No
(Parent_P
) then
8768 -- See if we have got to an appropriate point in the tree
8770 case Nkind
(Parent_P
) is
8772 -- A special test for the exception of (RM 13.14(8)) for the
8773 -- case of per-object expressions (RM 3.8(18)) occurring in
8774 -- component definition or a discrete subtype definition. Note
8775 -- that we test for a component declaration which includes both
8776 -- cases we are interested in, and furthermore the tree does
8777 -- not have explicit nodes for either of these two constructs.
8779 when N_Component_Declaration
=>
8781 -- The case we want to test for here is an identifier that
8782 -- is a per-object expression, this is either a discriminant
8783 -- that appears in a context other than the component
8784 -- declaration or it is a reference to the type of the
8785 -- enclosing construct.
8787 -- For either of these cases, we skip the freezing
8789 if not In_Spec_Expression
8790 and then Nkind
(N
) = N_Identifier
8791 and then Present
(Entity
(N
))
8793 -- We recognize the discriminant case by just looking for
8794 -- a reference to a discriminant. It can only be one for
8795 -- the enclosing construct. Skip freezing in this case.
8797 if Ekind
(Entity
(N
)) = E_Discriminant
then
8800 -- For the case of a reference to the enclosing record,
8801 -- (or task or protected type), we look for a type that
8802 -- matches the current scope.
8804 elsif Entity
(N
) = Current_Scope
then
8809 -- If we have an enumeration literal that appears as the choice
8810 -- in the aggregate of an enumeration representation clause,
8811 -- then freezing does not occur (RM 13.14(10)).
8813 when N_Enumeration_Representation_Clause
=>
8815 -- The case we are looking for is an enumeration literal
8817 if Nkind
(N
) in N_Identifier | N_Character_Literal
8818 and then Is_Enumeration_Type
(Etype
(N
))
8820 -- If enumeration literal appears directly as the choice,
8821 -- do not freeze (this is the normal non-overloaded case)
8823 if Nkind
(Parent
(N
)) = N_Component_Association
8824 and then First
(Choices
(Parent
(N
))) = N
8828 -- If enumeration literal appears as the name of function
8829 -- which is the choice, then also do not freeze. This
8830 -- happens in the overloaded literal case, where the
8831 -- enumeration literal is temporarily changed to a
8832 -- function call for overloading analysis purposes.
8834 elsif Nkind
(Parent
(N
)) = N_Function_Call
8835 and then Nkind
(Parent
(Parent
(N
))) =
8836 N_Component_Association
8837 and then First
(Choices
(Parent
(Parent
(N
)))) =
8844 -- Normally if the parent is a handled sequence of statements,
8845 -- then the current node must be a statement, and that is an
8846 -- appropriate place to insert a freeze node.
8848 when N_Handled_Sequence_Of_Statements
=>
8850 -- An exception occurs when the sequence of statements is
8851 -- for an expander generated body that did not do the usual
8852 -- freeze all operation. In this case we usually want to
8853 -- freeze outside this body, not inside it, unless the
8854 -- entity is declared inside this expander generated body.
8856 exit when not In_Expanded_Body
(Parent_P
)
8857 or else Declared_In_Expanded_Body
(Parent_P
, Typ
, Nam
);
8859 -- If parent is a body or a spec or a block, then the current
8860 -- node is a statement or declaration and we can insert the
8861 -- freeze node before it.
8863 when N_Block_Statement
8866 | N_Package_Specification
8873 -- The expander is allowed to define types in any statements
8874 -- list, so any of the following parent nodes also mark a
8875 -- freezing point if the actual node is in a list of
8876 -- statements or declarations.
8878 when N_Abortable_Part
8879 | N_Accept_Alternative
8880 | N_Case_Statement_Alternative
8881 | N_Compilation_Unit_Aux
8882 | N_Conditional_Entry_Call
8883 | N_Delay_Alternative
8885 | N_Entry_Call_Alternative
8886 | N_Exception_Handler
8887 | N_Extended_Return_Statement
8890 | N_Selective_Accept
8891 | N_Triggering_Alternative
8893 if No
(Current_Subprogram
) then
8894 exit when Is_List_Member
(P
);
8896 -- Check exceptional case documented above for an enclosing
8897 -- handled sequence of statements.
8901 Par
: Node_Id
:= Parent
(Parent_P
);
8906 Nkind
(Par
) /= N_Handled_Sequence_Of_Statements
8907 and then Nkind
(Parent
(Par
)) /= N_Subprogram_Body
8909 Par
:= Parent
(Par
);
8912 -- If we don't have a parent, then we are not in a
8913 -- well-formed tree and we ignore the freeze request.
8914 -- See previous comment in the enclosing loop.
8920 exit when not In_Expanded_Body
(Par
)
8921 or else Declared_In_Expanded_Body
(Par
, Typ
, Nam
);
8925 -- The freeze nodes produced by an expression coming from the
8926 -- Actions list of an N_Expression_With_Actions, short-circuit
8927 -- expression or N_Case_Expression_Alternative node must remain
8928 -- within the Actions list if they freeze an entity declared in
8929 -- this list, as inserting the freeze nodes further up the tree
8930 -- may lead to use before declaration issues for the entity.
8932 when N_Case_Expression_Alternative
8933 | N_Expression_With_Actions
8936 exit when (Present
(Nam
)
8938 Has_Decl_In_List
(Nam
, P
, Actions
(Parent_P
)))
8939 or else (Present
(Typ
)
8941 Has_Decl_In_List
(Typ
, P
, Actions
(Parent_P
)));
8943 -- Likewise for an N_If_Expression and its two Actions list
8945 when N_If_Expression
=>
8947 L1
: constant List_Id
:= Then_Actions
(Parent_P
);
8948 L2
: constant List_Id
:= Else_Actions
(Parent_P
);
8951 exit when (Present
(Nam
)
8953 Has_Decl_In_List
(Nam
, P
, L1
))
8954 or else (Present
(Typ
)
8956 Has_Decl_In_List
(Typ
, P
, L1
))
8957 or else (Present
(Nam
)
8959 Has_Decl_In_List
(Nam
, P
, L2
))
8960 or else (Present
(Typ
)
8962 Has_Decl_In_List
(Typ
, P
, L2
));
8965 -- N_Loop_Statement is a special case: a type that appears in
8966 -- the source can never be frozen in a loop (this occurs only
8967 -- because of a loop expanded by the expander), so we keep on
8968 -- going. Otherwise we terminate the search. Same is true of
8969 -- any entity which comes from source (if it has a predefined
8970 -- type, this type does not appear to come from source, but the
8971 -- entity should not be frozen here).
8973 when N_Loop_Statement
=>
8974 exit when not Comes_From_Source
(Etype
(N
))
8975 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
8977 -- For all other cases, keep looking at parents
8983 -- We fall through the case if we did not yet find the proper
8984 -- place in the tree for inserting the freeze node, so climb.
8990 -- If the expression appears in a record or an initialization procedure,
8991 -- the freeze nodes are collected and attached to the current scope, to
8992 -- be inserted and analyzed on exit from the scope, to insure that
8993 -- generated entities appear in the correct scope. If the expression is
8994 -- a default for a discriminant specification, the scope is still void.
8995 -- The expression can also appear in the discriminant part of a private
8996 -- or concurrent type.
8998 -- If the expression appears in a constrained subcomponent of an
8999 -- enclosing record declaration, the freeze nodes must be attached to
9000 -- the outer record type so they can eventually be placed in the
9001 -- enclosing declaration list.
9003 -- The other case requiring this special handling is if we are in a
9004 -- default expression, since in that case we are about to freeze a
9005 -- static type, and the freeze scope needs to be the outer scope, not
9006 -- the scope of the subprogram with the default parameter.
9008 -- For default expressions and other spec expressions in generic units,
9009 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
9010 -- placing them at the proper place, after the generic unit.
9012 if (In_Spec_Exp
and not Inside_A_Generic
)
9013 or else (Is_Type
(Current_Scope
)
9014 and then (not Is_Concurrent_Type
(Current_Scope
)
9015 or else not Has_Completion
(Current_Scope
)))
9016 or else Ekind
(Current_Scope
) = E_Void
9019 Freeze_Nodes
: List_Id
:= No_List
;
9020 Pos
: Int
:= Scope_Stack
.Last
;
9023 if Present
(Desig_Typ
) then
9024 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
9027 if Present
(Typ
) then
9028 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
9031 if Present
(Nam
) then
9032 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
9035 -- The current scope may be that of a constrained component of
9036 -- an enclosing record declaration, or a block of an enclosing
9037 -- declare expression in Ada 2022, or of a loop of an enclosing
9038 -- quantified expression or aggregate with an iterated component
9039 -- in Ada 2022, which is above the current scope in the scope
9040 -- stack. Indeed in the context of a quantified expression or
9041 -- an aggregate with an iterated component, an internal scope is
9042 -- created and pushed above the current scope in order to emulate
9043 -- the loop-like behavior of the construct.
9044 -- If the expression is within a top-level pragma, as for a pre-
9045 -- condition on a library-level subprogram, nothing to do.
9047 if not Is_Compilation_Unit
(Current_Scope
)
9048 and then (Is_Record_Type
(Scope
(Current_Scope
))
9049 or else (Ekind
(Current_Scope
) in E_Block | E_Loop
9050 and then Is_Internal
(Current_Scope
)))
9055 if Is_Non_Empty_List
(Freeze_Nodes
) then
9057 -- When the current scope is transient, insert the freeze nodes
9058 -- prior to the expression that produced them. Transient scopes
9059 -- may create additional declarations when finalizing objects
9060 -- or managing the secondary stack. Inserting the freeze nodes
9061 -- of those constructs prior to the scope would result in a
9062 -- freeze-before-declaration, therefore the freeze node must
9063 -- remain interleaved with their constructs.
9065 if Scope_Is_Transient
then
9066 Insert_Actions
(N
, Freeze_Nodes
);
9068 elsif No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
9069 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
9072 Append_List
(Freeze_Nodes
,
9073 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
9081 -- Now we have the right place to do the freezing. First, a special
9082 -- adjustment, if we are in spec-expression analysis mode, these freeze
9083 -- actions must not be thrown away (normally all inserted actions are
9084 -- thrown away in this mode). However, the freeze actions are from
9085 -- static expressions and one of the important reasons we are doing this
9086 -- special analysis is to get these freeze actions. Therefore we turn
9087 -- off the In_Spec_Expression mode to propagate these freeze actions.
9088 -- This also means they get properly analyzed and expanded.
9090 In_Spec_Expression
:= False;
9092 -- Freeze the subtype mark before a qualified expression on an
9093 -- allocator as per AARM 13.14(4.a). This is needed in particular to
9094 -- generate predicate functions.
9096 if Present
(Allocator_Typ
) then
9097 Freeze_Before
(P
, Allocator_Typ
);
9100 -- Freeze the designated type of an allocator (RM 13.14(13))
9102 if Present
(Desig_Typ
) then
9103 Freeze_Before
(P
, Desig_Typ
);
9106 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
9107 -- the enumeration representation clause exception in the loop above.
9109 if Present
(Typ
) then
9110 Freeze_Before
(P
, Typ
);
9113 -- Freeze name if one is present (RM 13.14(11))
9115 if Present
(Nam
) then
9116 Freeze_Before
(P
, Nam
);
9119 -- Restore In_Spec_Expression flag
9121 In_Spec_Expression
:= In_Spec_Exp
;
9122 end Freeze_Expression
;
9124 -----------------------
9125 -- Freeze_Expr_Types --
9126 -----------------------
9128 procedure Freeze_Expr_Types
9129 (Def_Id
: Entity_Id
;
9134 function Cloned_Expression
return Node_Id
;
9135 -- Build a duplicate of the expression of the return statement that has
9136 -- no defining entities shared with the original expression.
9138 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
9139 -- Freeze all types referenced in the subtree rooted at Node
9141 -----------------------
9142 -- Cloned_Expression --
9143 -----------------------
9145 function Cloned_Expression
return Node_Id
is
9146 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
9147 -- Tree traversal routine that clones the defining identifier of
9148 -- iterator and loop parameter specification nodes.
9154 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
9157 N_Iterator_Specification | N_Loop_Parameter_Specification
9159 Set_Defining_Identifier
9160 (Node
, New_Copy
(Defining_Identifier
(Node
)));
9166 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
9170 Dup_Expr
: constant Node_Id
:= New_Copy_Tree
(Expr
);
9172 -- Start of processing for Cloned_Expression
9175 -- We must duplicate the expression with semantic information to
9176 -- inherit the decoration of global entities in generic instances.
9177 -- Set the parent of the new node to be the parent of the original
9178 -- to get the proper context, which is needed for complete error
9179 -- reporting and for semantic analysis.
9181 Set_Parent
(Dup_Expr
, Parent
(Expr
));
9183 -- Replace the defining identifier of iterators and loop param
9184 -- specifications by a clone to ensure that the cloned expression
9185 -- and the original expression don't have shared identifiers;
9186 -- otherwise, as part of the preanalysis of the expression, these
9187 -- shared identifiers may be left decorated with itypes which
9188 -- will not be available in the tree passed to the backend.
9190 Clone_Def_Ids
(Dup_Expr
);
9193 end Cloned_Expression
;
9195 ----------------------
9196 -- Freeze_Type_Refs --
9197 ----------------------
9199 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
9200 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
);
9201 -- Check that Typ is fully declared and freeze it if so
9203 ---------------------------
9204 -- Check_And_Freeze_Type --
9205 ---------------------------
9207 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
) is
9209 -- Skip Itypes created by the preanalysis, and itypes whose
9210 -- scope is another type (i.e. component subtypes that depend
9211 -- on a discriminant),
9214 and then (Scope_Within_Or_Same
(Scope
(Typ
), Def_Id
)
9215 or else Is_Type
(Scope
(Typ
)))
9220 -- This provides a better error message than generating primitives
9221 -- whose compilation fails much later. Refine the error message if
9224 Check_Fully_Declared
(Typ
, Node
);
9226 if Error_Posted
(Node
) then
9227 if Has_Private_Component
(Typ
)
9228 and then not Is_Private_Type
(Typ
)
9230 Error_Msg_NE
("\type& has private component", Node
, Typ
);
9234 Freeze_Before
(N
, Typ
);
9236 end Check_And_Freeze_Type
;
9238 -- Start of processing for Freeze_Type_Refs
9241 -- Check that a type referenced by an entity can be frozen
9243 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
9244 -- The entity itself may be a type, as in a membership test
9245 -- or an attribute reference. Freezing its own type would be
9246 -- incomplete if the entity is derived or an extension.
9248 if Is_Type
(Entity
(Node
)) then
9249 Check_And_Freeze_Type
(Entity
(Node
));
9252 Check_And_Freeze_Type
(Etype
(Entity
(Node
)));
9255 -- Check that the enclosing record type can be frozen
9257 if Ekind
(Entity
(Node
)) in E_Component | E_Discriminant
then
9258 Check_And_Freeze_Type
(Scope
(Entity
(Node
)));
9261 -- Freezing an access type does not freeze the designated type, but
9262 -- freezing conversions between access to interfaces requires that
9263 -- the interface types themselves be frozen, so that dispatch table
9264 -- entities are properly created.
9266 -- Unclear whether a more general rule is needed ???
9268 elsif Nkind
(Node
) = N_Type_Conversion
9269 and then Is_Access_Type
(Etype
(Node
))
9270 and then Is_Interface
(Designated_Type
(Etype
(Node
)))
9272 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
9275 -- An implicit dereference freezes the designated type. In the case
9276 -- of a dispatching call whose controlling argument is an access
9277 -- type, the dereference is not made explicit, so we must check for
9278 -- such a call and freeze the designated type.
9280 if Nkind
(Node
) in N_Has_Etype
9281 and then Present
(Etype
(Node
))
9282 and then Is_Access_Type
(Etype
(Node
))
9284 if Nkind
(Parent
(Node
)) = N_Function_Call
9285 and then Node
= Controlling_Argument
(Parent
(Node
))
9287 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
9289 -- An explicit dereference freezes the designated type as well,
9290 -- even though that type is not attached to an entity in the
9293 elsif Nkind
(Parent
(Node
)) = N_Explicit_Dereference
then
9294 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
9297 -- An iterator specification freezes the iterator type, even though
9298 -- that type is not attached to an entity in the construct.
9300 elsif Nkind
(Node
) in N_Has_Etype
9301 and then Present
(Etype
(Node
))
9302 and then Nkind
(Parent
(Node
)) = N_Iterator_Specification
9303 and then Node
= Name
(Parent
(Node
))
9306 Iter
: constant Node_Id
:=
9307 Find_Value_Of_Aspect
(Etype
(Node
), Aspect_Default_Iterator
);
9310 if Present
(Iter
) then
9311 Check_And_Freeze_Type
(Etype
(Iter
));
9316 -- No point in posting several errors on the same expression
9318 if Serious_Errors_Detected
> 0 then
9323 end Freeze_Type_Refs
;
9325 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
9329 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Def_Id
);
9330 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Def_Id
);
9331 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
9333 -- Start of processing for Freeze_Expr_Types
9336 -- Preanalyze a duplicate of the expression to have available the
9337 -- minimum decoration needed to locate referenced unfrozen types
9338 -- without adding any decoration to the function expression.
9340 -- This routine is also applied to expressions in the contract for
9341 -- the subprogram. If that happens when expanding the code for
9342 -- pre/postconditions during expansion of the subprogram body, the
9343 -- subprogram is already installed.
9345 if Def_Id
/= Current_Scope
then
9346 Push_Scope
(Def_Id
);
9347 Install_Formals
(Def_Id
);
9349 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
9352 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
9355 -- Restore certain attributes of Def_Id since the preanalysis may
9356 -- have introduced itypes to this scope, thus modifying attributes
9357 -- First_Entity and Last_Entity.
9359 Set_First_Entity
(Def_Id
, Saved_First_Entity
);
9360 Set_Last_Entity
(Def_Id
, Saved_Last_Entity
);
9362 if Present
(Last_Entity
(Def_Id
)) then
9363 Set_Next_Entity
(Last_Entity
(Def_Id
), Empty
);
9366 -- Freeze all types referenced in the expression
9368 Freeze_References
(Dup_Expr
);
9369 end Freeze_Expr_Types
;
9371 -----------------------------
9372 -- Freeze_Fixed_Point_Type --
9373 -----------------------------
9375 -- Certain fixed-point types and subtypes, including implicit base types
9376 -- and declared first subtypes, have not yet set up a range. This is
9377 -- because the range cannot be set until the Small and Size values are
9378 -- known, and these are not known till the type is frozen.
9380 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
9381 -- whose bounds are unanalyzed real literals. This routine will recognize
9382 -- this case, and transform this range node into a properly typed range
9383 -- with properly analyzed and resolved values.
9385 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
9386 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
9387 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
9388 Hi
: constant Node_Id
:= High_Bound
(Rng
);
9389 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9390 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
9391 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
9392 BHi
: constant Node_Id
:= High_Bound
(Brng
);
9393 Ftyp
: constant Entity_Id
:= Underlying_Type
(First_Subtype
(Typ
));
9402 -- Save original bounds (for shaving tests)
9405 -- Actual size chosen
9407 function Fsize
(Lov
, Hiv
: Ureal
) return Int
;
9408 -- Returns size of type with given bounds. Also leaves these
9409 -- bounds set as the current bounds of the Typ.
9411 function Larger
(A
, B
: Ureal
) return Boolean;
9412 -- Returns true if A > B with a margin of Typ'Small
9414 function Smaller
(A
, B
: Ureal
) return Boolean;
9415 -- Returns true if A < B with a margin of Typ'Small
9421 function Fsize
(Lov
, Hiv
: Ureal
) return Int
is
9423 Set_Realval
(Lo
, Lov
);
9424 Set_Realval
(Hi
, Hiv
);
9425 return Minimum_Size
(Typ
);
9432 function Larger
(A
, B
: Ureal
) return Boolean is
9434 return A
> B
and then A
- Small_Value
(Typ
) > B
;
9441 function Smaller
(A
, B
: Ureal
) return Boolean is
9443 return A
< B
and then A
+ Small_Value
(Typ
) < B
;
9446 -- Start of processing for Freeze_Fixed_Point_Type
9449 -- The type, or its first subtype if we are freezing the anonymous
9450 -- base, may have a delayed Small aspect. It must be analyzed now,
9451 -- so that all characteristics of the type (size, bounds) can be
9452 -- computed and validated in the call to Minimum_Size that follows.
9454 if Has_Delayed_Aspects
(Ftyp
) then
9455 Analyze_Aspects_At_Freeze_Point
(Ftyp
);
9456 Set_Has_Delayed_Aspects
(Ftyp
, False);
9459 if May_Inherit_Delayed_Rep_Aspects
(Ftyp
) then
9460 Inherit_Delayed_Rep_Aspects
(Ftyp
);
9461 Set_May_Inherit_Delayed_Rep_Aspects
(Ftyp
, False);
9464 -- Inherit the Small value from the first subtype in any case
9467 Set_Small_Value
(Typ
, Small_Value
(Ftyp
));
9470 -- If Esize of a subtype has not previously been set, set it now
9472 if not Known_Esize
(Typ
) then
9473 Atype
:= Ancestor_Subtype
(Typ
);
9475 if Present
(Atype
) then
9476 Set_Esize
(Typ
, Esize
(Atype
));
9478 Copy_Esize
(To
=> Typ
, From
=> Btyp
);
9482 -- Immediate return if the range is already analyzed. This means that
9483 -- the range is already set, and does not need to be computed by this
9486 if Analyzed
(Rng
) then
9490 -- Immediate return if either of the bounds raises Constraint_Error
9492 if Raises_Constraint_Error
(Lo
)
9493 or else Raises_Constraint_Error
(Hi
)
9498 Small
:= Small_Value
(Typ
);
9499 Loval
:= Realval
(Lo
);
9500 Hival
:= Realval
(Hi
);
9505 -- Ordinary fixed-point case
9507 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
9509 -- For the ordinary fixed-point case, we are allowed to fudge the
9510 -- end-points up or down by small. Generally we prefer to fudge up,
9511 -- i.e. widen the bounds for non-model numbers so that the end points
9512 -- are included. However there are cases in which this cannot be
9513 -- done, and indeed cases in which we may need to narrow the bounds.
9514 -- The following circuit makes the decision.
9516 -- Note: our terminology here is that Incl_EP means that the bounds
9517 -- are widened by Small if necessary to include the end points, and
9518 -- Excl_EP means that the bounds are narrowed by Small to exclude the
9519 -- end-points if this reduces the size.
9521 -- Note that in the Incl case, all we care about is including the
9522 -- end-points. In the Excl case, we want to narrow the bounds as
9523 -- much as permitted by the RM, to give the smallest possible size.
9526 Loval_Incl_EP
: Ureal
;
9527 Hival_Incl_EP
: Ureal
;
9529 Loval_Excl_EP
: Ureal
;
9530 Hival_Excl_EP
: Ureal
;
9540 -- First step. Base types are required to be symmetrical. Right
9541 -- now, the base type range is a copy of the first subtype range.
9542 -- This will be corrected before we are done, but right away we
9543 -- need to deal with the case where both bounds are non-negative.
9544 -- In this case, we set the low bound to the negative of the high
9545 -- bound, to make sure that the size is computed to include the
9546 -- required sign. Note that we do not need to worry about the
9547 -- case of both bounds negative, because the sign will be dealt
9548 -- with anyway. Furthermore we can't just go making such a bound
9549 -- symmetrical, since in a twos-complement system, there is an
9550 -- extra negative value which could not be accommodated on the
9554 and then not UR_Is_Negative
(Loval
)
9555 and then Hival
> Loval
9558 Set_Realval
(Lo
, Loval
);
9561 -- Compute the fudged bounds. If the bound is a model number, (or
9562 -- greater if given low bound, smaller if high bound) then we do
9563 -- nothing to include it, but we are allowed to backoff to the
9564 -- next adjacent model number when we exclude it. If it is not a
9565 -- model number then we straddle the two values with the model
9566 -- numbers on either side.
9568 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
9570 if UR_Ge
(Loval
, Model_Num
) then
9571 Loval_Incl_EP
:= Model_Num
;
9573 Loval_Incl_EP
:= Model_Num
- Small
;
9576 -- The low value excluding the end point is Small greater, but
9577 -- we do not do this exclusion if the low value is positive,
9578 -- since it can't help the size and could actually hurt by
9579 -- crossing the high bound.
9581 if UR_Is_Negative
(Loval_Incl_EP
) then
9582 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
9584 -- If the value went from negative to zero, then we have the
9585 -- case where Loval_Incl_EP is the model number just below
9586 -- zero, so we want to stick to the negative value for the
9587 -- base type to maintain the condition that the size will
9588 -- include signed values.
9591 and then UR_Is_Zero
(Loval_Excl_EP
)
9593 Loval_Excl_EP
:= Loval_Incl_EP
;
9597 Loval_Excl_EP
:= Loval_Incl_EP
;
9600 -- Similar processing for upper bound and high value
9602 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
9604 if UR_Le
(Hival
, Model_Num
) then
9605 Hival_Incl_EP
:= Model_Num
;
9607 Hival_Incl_EP
:= Model_Num
+ Small
;
9610 if UR_Is_Positive
(Hival_Incl_EP
) then
9611 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
9613 Hival_Excl_EP
:= Hival_Incl_EP
;
9616 -- One further adjustment is needed. In the case of subtypes, we
9617 -- cannot go outside the range of the base type, or we get
9618 -- peculiarities, and the base type range is already set. This
9619 -- only applies to the Incl values, since clearly the Excl values
9620 -- are already as restricted as they are allowed to be.
9623 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
9624 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
9627 -- Get size including and excluding end points
9629 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
9630 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
9632 -- No need to exclude end-points if it does not reduce size
9634 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
9635 Loval_Excl_EP
:= Loval_Incl_EP
;
9638 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
9639 Hival_Excl_EP
:= Hival_Incl_EP
;
9642 -- Now we set the actual size to be used. We want to use the
9643 -- bounds fudged up to include the end-points but only if this
9644 -- can be done without violating a specifically given size
9645 -- size clause or causing an unacceptable increase in size.
9647 -- Case of size clause given
9649 if Has_Size_Clause
(Typ
) then
9651 -- Use the inclusive size only if it is consistent with
9652 -- the explicitly specified size.
9654 if Size_Incl_EP
<= RM_Size
(Typ
) then
9655 Actual_Lo
:= Loval_Incl_EP
;
9656 Actual_Hi
:= Hival_Incl_EP
;
9657 Actual_Size
:= Size_Incl_EP
;
9659 -- If the inclusive size is too large, we try excluding
9660 -- the end-points (will be caught later if does not work).
9663 Actual_Lo
:= Loval_Excl_EP
;
9664 Actual_Hi
:= Hival_Excl_EP
;
9665 Actual_Size
:= Size_Excl_EP
;
9668 -- Case of size clause not given
9671 -- If we have a base type whose corresponding first subtype
9672 -- has an explicit size that is large enough to include our
9673 -- end-points, then do so. There is no point in working hard
9674 -- to get a base type whose size is smaller than the specified
9675 -- size of the first subtype.
9677 if Has_Size_Clause
(Ftyp
)
9678 and then Size_Incl_EP
<= Esize
(Ftyp
)
9680 Actual_Size
:= Size_Incl_EP
;
9681 Actual_Lo
:= Loval_Incl_EP
;
9682 Actual_Hi
:= Hival_Incl_EP
;
9684 -- If excluding the end-points makes the size smaller and
9685 -- results in a size of 8,16,32,64, then we take the smaller
9686 -- size. For the 64 case, this is compulsory. For the other
9687 -- cases, it seems reasonable. We like to include end points
9688 -- if we can, but not at the expense of moving to the next
9689 -- natural boundary of size.
9691 elsif Size_Incl_EP
/= Size_Excl_EP
9692 and then Addressable
(Size_Excl_EP
)
9694 Actual_Size
:= Size_Excl_EP
;
9695 Actual_Lo
:= Loval_Excl_EP
;
9696 Actual_Hi
:= Hival_Excl_EP
;
9698 -- Otherwise we can definitely include the end points
9701 Actual_Size
:= Size_Incl_EP
;
9702 Actual_Lo
:= Loval_Incl_EP
;
9703 Actual_Hi
:= Hival_Incl_EP
;
9706 -- One pathological case: normally we never fudge a low bound
9707 -- down, since it would seem to increase the size (if it has
9708 -- any effect), but for ranges containing single value, or no
9709 -- values, the high bound can be small too large. Consider:
9711 -- type t is delta 2.0**(-14)
9712 -- range 131072.0 .. 0;
9714 -- That lower bound is *just* outside the range of 32 bits, and
9715 -- does need fudging down in this case. Note that the bounds
9716 -- will always have crossed here, since the high bound will be
9717 -- fudged down if necessary, as in the case of:
9719 -- type t is delta 2.0**(-14)
9720 -- range 131072.0 .. 131072.0;
9722 -- So we detect the situation by looking for crossed bounds,
9723 -- and if the bounds are crossed, and the low bound is greater
9724 -- than zero, we will always back it off by small, since this
9725 -- is completely harmless.
9727 if Actual_Lo
> Actual_Hi
then
9728 if UR_Is_Positive
(Actual_Lo
) then
9729 Actual_Lo
:= Loval_Incl_EP
- Small
;
9730 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9732 -- And of course, we need to do exactly the same parallel
9733 -- fudge for flat ranges in the negative region.
9735 elsif UR_Is_Negative
(Actual_Hi
) then
9736 Actual_Hi
:= Hival_Incl_EP
+ Small
;
9737 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9742 Set_Realval
(Lo
, Actual_Lo
);
9743 Set_Realval
(Hi
, Actual_Hi
);
9746 -- Enforce some limitations for ordinary fixed-point types. They come
9747 -- from an exact algorithm used to implement Text_IO.Fixed_IO and the
9748 -- Fore, Image and Value attributes. The requirement on the Small is
9749 -- to lie in the range 2**(-(Siz - 1)) .. 2**(Siz - 1) for a type of
9750 -- Siz bits (Siz=32,64,128) and the requirement on the bounds is to
9751 -- be smaller in magnitude than 10.0**N * 2**(Siz - 1), where N is
9752 -- given by the formula N = floor ((Siz - 1) * log 2 / log 10).
9754 -- If the bounds of a 32-bit type are too large, force 64-bit type
9756 if Actual_Size
<= 32
9757 and then Small
<= Ureal_2_31
9758 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_2_10_18
)
9759 or else Larger
(Expr_Value_R
(Hi
), Ureal_2_10_18
))
9764 -- If the bounds of a 64-bit type are too large, force 128-bit type
9766 if System_Max_Integer_Size
= 128
9767 and then Actual_Size
<= 64
9768 and then Small
<= Ureal_2_63
9769 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
)
9770 or else Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
))
9775 -- Give error messages for first subtypes and not base types, as the
9776 -- bounds of base types are always maximum for their size, see below.
9778 if System_Max_Integer_Size
< 128 and then Typ
/= Btyp
then
9780 -- See the 128-bit case below for the reason why we cannot test
9781 -- against the 2**(-63) .. 2**63 range. This quirk should have
9782 -- been kludged around as in the 128-bit case below, but it was
9783 -- not and we end up with a ludicrous range as a result???
9785 if Small
< Ureal_2_M_80
then
9786 Error_Msg_Name_1
:= Name_Small
;
9788 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", Typ
);
9790 elsif Small
> Ureal_2_80
then
9791 Error_Msg_Name_1
:= Name_Small
;
9793 ("`&''%` too large, maximum allowed is 2.0'*'*80", Typ
);
9796 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
) then
9797 Error_Msg_Name_1
:= Name_First
;
9799 ("`&''%` too small, minimum allowed is -9.0E+36", Typ
);
9802 if Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
) then
9803 Error_Msg_Name_1
:= Name_Last
;
9805 ("`&''%` too large, maximum allowed is 9.0E+36", Typ
);
9808 elsif System_Max_Integer_Size
= 128 and then Typ
/= Btyp
then
9810 -- ACATS c35902d tests a delta equal to 2**(-(Max_Mantissa + 1))
9811 -- but we cannot really support anything smaller than Fine_Delta
9812 -- because of the way we implement I/O for fixed point types???
9814 if Small
= Ureal_2_M_128
then
9817 elsif Small
< Ureal_2_M_127
then
9818 Error_Msg_Name_1
:= Name_Small
;
9820 ("`&''%` too small, minimum allowed is 2.0'*'*(-127)", Typ
);
9822 elsif Small
> Ureal_2_127
then
9823 Error_Msg_Name_1
:= Name_Small
;
9825 ("`&''%` too large, maximum allowed is 2.0'*'*127", Typ
);
9829 and then (Norm_Num
(Small
) > Uint_2
** 127
9830 or else Norm_Den
(Small
) > Uint_2
** 127)
9831 and then Small
/= Ureal_2_M_128
9833 Error_Msg_Name_1
:= Name_Small
;
9835 ("`&''%` not the ratio of two 128-bit integers", Typ
);
9838 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_10_76
) then
9839 Error_Msg_Name_1
:= Name_First
;
9841 ("`&''%` too small, minimum allowed is -1.0E+76", Typ
);
9844 if Larger
(Expr_Value_R
(Hi
), Ureal_10_76
) then
9845 Error_Msg_Name_1
:= Name_Last
;
9847 ("`&''%` too large, maximum allowed is 1.0E+76", Typ
);
9851 -- For the decimal case, none of this fudging is required, since there
9852 -- are no end-point problems in the decimal case (the end-points are
9853 -- always included).
9856 Actual_Size
:= Fsize
(Loval
, Hival
);
9859 -- At this stage, the actual size has been calculated and the proper
9860 -- required bounds are stored in the low and high bounds.
9862 if Actual_Size
> System_Max_Integer_Size
then
9863 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
9864 Error_Msg_Uint_2
:= UI_From_Int
(System_Max_Integer_Size
);
9866 ("size required (^) for type& too large, maximum allowed is ^",
9868 Actual_Size
:= System_Max_Integer_Size
;
9871 -- Check size against explicit given size
9873 if Has_Size_Clause
(Typ
) then
9874 if Actual_Size
> RM_Size
(Typ
) then
9875 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9876 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
9878 ("size given (^) for type& too small, minimum allowed is ^",
9879 Size_Clause
(Typ
), Typ
);
9882 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
9885 -- Increase size to next natural boundary if no size clause given
9888 if Actual_Size
<= 8 then
9890 elsif Actual_Size
<= 16 then
9892 elsif Actual_Size
<= 32 then
9894 elsif Actual_Size
<= 64 then
9900 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9901 Adjust_Esize_For_Alignment
(Typ
);
9904 -- If we have a base type, then expand the bounds so that they extend to
9905 -- the full width of the allocated size in bits, to avoid junk range
9906 -- checks on intermediate computations.
9909 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
9910 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
9913 -- Final step is to reanalyze the bounds using the proper type
9914 -- and set the Corresponding_Integer_Value fields of the literals.
9916 Set_Etype
(Lo
, Empty
);
9917 Set_Analyzed
(Lo
, False);
9920 -- Resolve with universal fixed if the base type, and with the base
9921 -- type if we are freezing a subtype. Note we can't resolve the base
9922 -- type with itself, that would be a reference before definition.
9923 -- The resolution of the bounds of a subtype, if they are given by real
9924 -- literals, includes the setting of the Corresponding_Integer_Value,
9925 -- as for other literals of a fixed-point type.
9928 Resolve
(Lo
, Universal_Fixed
);
9929 Set_Corresponding_Integer_Value
9930 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
9935 -- Similar processing for high bound
9937 Set_Etype
(Hi
, Empty
);
9938 Set_Analyzed
(Hi
, False);
9942 Resolve
(Hi
, Universal_Fixed
);
9943 Set_Corresponding_Integer_Value
9944 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
9949 -- Set type of range to correspond to bounds
9951 Set_Etype
(Rng
, Etype
(Lo
));
9953 -- Set Esize to calculated size if not set already
9955 if not Known_Esize
(Typ
) then
9956 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9959 -- Set RM_Size if not already set. If already set, check value
9962 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
9965 if Known_RM_Size
(Typ
) then
9966 if RM_Size
(Typ
) < Minsiz
then
9967 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9968 Error_Msg_Uint_2
:= Minsiz
;
9970 ("size given (^) for type& too small, minimum allowed is ^",
9971 Size_Clause
(Typ
), Typ
);
9975 Set_RM_Size
(Typ
, Minsiz
);
9979 -- Check for shaving
9981 if Comes_From_Source
(Typ
) then
9983 -- In SPARK mode the given bounds must be strictly representable
9985 if SPARK_Mode
= On
then
9986 if Orig_Lo
< Expr_Value_R
(Lo
) then
9988 ("declared low bound of type & is outside type range",
9992 if Orig_Hi
> Expr_Value_R
(Hi
) then
9994 ("declared high bound of type & is outside type range",
9999 if Orig_Lo
< Expr_Value_R
(Lo
) then
10001 ("declared low bound of type & is outside type range??", Typ
);
10003 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
10006 if Orig_Hi
> Expr_Value_R
(Hi
) then
10008 ("declared high bound of type & is outside type range??",
10011 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
10015 end Freeze_Fixed_Point_Type
;
10021 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
10025 Set_Has_Delayed_Freeze
(T
);
10026 L
:= Freeze_Entity
(T
, N
);
10028 Insert_Actions
(N
, L
);
10031 --------------------------
10032 -- Freeze_Static_Object --
10033 --------------------------
10035 procedure Freeze_Static_Object
(E
: Entity_Id
) is
10037 Cannot_Be_Static
: exception;
10038 -- Exception raised if the type of a static object cannot be made
10039 -- static. This happens if the type depends on non-global objects.
10041 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
10042 -- Called to ensure that an expression used as part of a type definition
10043 -- is statically allocatable, which means that the expression type is
10044 -- statically allocatable, and the expression is either static, or a
10045 -- reference to a library level constant.
10047 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
10048 -- Called to mark a type as static, checking that it is possible
10049 -- to set the type as static. If it is not possible, then the
10050 -- exception Cannot_Be_Static is raised.
10052 -----------------------------
10053 -- Ensure_Expression_Is_SA --
10054 -----------------------------
10056 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
10060 Ensure_Type_Is_SA
(Etype
(N
));
10062 if Is_OK_Static_Expression
(N
) then
10065 elsif Nkind
(N
) = N_Identifier
then
10069 and then Ekind
(Ent
) = E_Constant
10070 and then Is_Library_Level_Entity
(Ent
)
10076 raise Cannot_Be_Static
;
10077 end Ensure_Expression_Is_SA
;
10079 -----------------------
10080 -- Ensure_Type_Is_SA --
10081 -----------------------
10083 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
10088 -- If type is library level, we are all set
10090 if Is_Library_Level_Entity
(Typ
) then
10094 -- We are also OK if the type already marked as statically allocated,
10095 -- which means we processed it before.
10097 if Is_Statically_Allocated
(Typ
) then
10101 -- Mark type as statically allocated
10103 Set_Is_Statically_Allocated
(Typ
);
10105 -- Check that it is safe to statically allocate this type
10107 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
10108 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
10109 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
10111 elsif Is_Array_Type
(Typ
) then
10112 N
:= First_Index
(Typ
);
10113 while Present
(N
) loop
10114 Ensure_Type_Is_SA
(Etype
(N
));
10118 Ensure_Type_Is_SA
(Component_Type
(Typ
));
10120 elsif Is_Access_Type
(Typ
) then
10121 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
10125 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
10128 if T
/= Standard_Void_Type
then
10129 Ensure_Type_Is_SA
(T
);
10132 F
:= First_Formal
(Designated_Type
(Typ
));
10133 while Present
(F
) loop
10134 Ensure_Type_Is_SA
(Etype
(F
));
10140 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
10143 elsif Is_Record_Type
(Typ
) then
10144 C
:= First_Entity
(Typ
);
10145 while Present
(C
) loop
10146 if Ekind
(C
) = E_Discriminant
10147 or else Ekind
(C
) = E_Component
10149 Ensure_Type_Is_SA
(Etype
(C
));
10151 elsif Is_Type
(C
) then
10152 Ensure_Type_Is_SA
(C
);
10158 elsif Ekind
(Typ
) = E_Subprogram_Type
then
10159 Ensure_Type_Is_SA
(Etype
(Typ
));
10161 C
:= First_Formal
(Typ
);
10162 while Present
(C
) loop
10163 Ensure_Type_Is_SA
(Etype
(C
));
10168 raise Cannot_Be_Static
;
10170 end Ensure_Type_Is_SA
;
10172 -- Start of processing for Freeze_Static_Object
10175 Ensure_Type_Is_SA
(Etype
(E
));
10178 when Cannot_Be_Static
=>
10180 -- If the object that cannot be static is imported or exported, then
10181 -- issue an error message saying that this object cannot be imported
10182 -- or exported. If it has an address clause it is an overlay in the
10183 -- current partition and the static requirement is not relevant.
10184 -- Do not issue any error message when ignoring rep clauses.
10186 if Ignore_Rep_Clauses
then
10189 elsif Is_Imported
(E
) then
10190 if No
(Address_Clause
(E
)) then
10192 ("& cannot be imported (local type is not constant)", E
);
10195 -- Otherwise must be exported, something is wrong if compiler
10196 -- is marking something as statically allocated which cannot be).
10198 else pragma Assert
(Is_Exported
(E
));
10200 ("& cannot be exported (local type is not constant)", E
);
10202 end Freeze_Static_Object
;
10204 -----------------------
10205 -- Freeze_Subprogram --
10206 -----------------------
10208 procedure Freeze_Subprogram
(E
: Entity_Id
) is
10210 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
);
10211 -- Set the conventions of all anonymous access-to-subprogram formals and
10212 -- result subtype of subprogram Subp_Id to the convention of Subp_Id.
10214 ----------------------------
10215 -- Set_Profile_Convention --
10216 ----------------------------
10218 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
) is
10219 Conv
: constant Convention_Id
:= Convention
(Subp_Id
);
10221 procedure Set_Type_Convention
(Typ
: Entity_Id
);
10222 -- Set the convention of anonymous access-to-subprogram type Typ and
10223 -- its designated type to Conv.
10225 -------------------------
10226 -- Set_Type_Convention --
10227 -------------------------
10229 procedure Set_Type_Convention
(Typ
: Entity_Id
) is
10231 -- Set the convention on both the anonymous access-to-subprogram
10232 -- type and the subprogram type it points to because both types
10233 -- participate in conformance-related checks.
10235 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
10236 Set_Convention
(Typ
, Conv
);
10237 Set_Convention
(Designated_Type
(Typ
), Conv
);
10239 end Set_Type_Convention
;
10243 Formal
: Entity_Id
;
10245 -- Start of processing for Set_Profile_Convention
10248 Formal
:= First_Formal
(Subp_Id
);
10249 while Present
(Formal
) loop
10250 Set_Type_Convention
(Etype
(Formal
));
10251 Next_Formal
(Formal
);
10254 if Ekind
(Subp_Id
) = E_Function
then
10255 Set_Type_Convention
(Etype
(Subp_Id
));
10257 end Set_Profile_Convention
;
10262 Retype
: Entity_Id
;
10264 -- Start of processing for Freeze_Subprogram
10267 -- Subprogram may not have an address clause unless it is imported
10269 if Present
(Address_Clause
(E
)) then
10270 if not Is_Imported
(E
) then
10272 ("address clause can only be given for imported subprogram",
10273 Name
(Address_Clause
(E
)));
10277 -- Reset the Pure indication on an imported subprogram unless an
10278 -- explicit Pure_Function pragma was present or the subprogram is an
10279 -- intrinsic. We do this because otherwise it is an insidious error
10280 -- to call a non-pure function from pure unit and have calls
10281 -- mysteriously optimized away. What happens here is that the Import
10282 -- can bypass the normal check to ensure that pure units call only pure
10285 -- The reason for the intrinsic exception is that in general, intrinsic
10286 -- functions (such as shifts) are pure anyway. The only exceptions are
10287 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
10288 -- in any case, so no problem arises.
10291 and then Is_Pure
(E
)
10292 and then not Has_Pragma_Pure_Function
(E
)
10293 and then not Is_Intrinsic_Subprogram
(E
)
10295 Set_Is_Pure
(E
, False);
10298 -- For C++ constructors check that their external name has been given
10299 -- (either in pragma CPP_Constructor or in a pragma import).
10301 if Is_Constructor
(E
)
10302 and then Convention
(E
) = Convention_CPP
10304 (No
(Interface_Name
(E
))
10305 or else String_Equal
10306 (L
=> Strval
(Interface_Name
(E
)),
10307 R
=> Strval
(Get_Default_External_Name
(E
))))
10310 ("'C++ constructor must have external name or link name", E
);
10313 -- We also reset the Pure indication on a subprogram with an Address
10314 -- parameter, because the parameter may be used as a pointer and the
10315 -- referenced data may change even if the address value does not.
10317 -- Note that if the programmer gave an explicit Pure_Function pragma,
10318 -- then we believe the programmer, and leave the subprogram Pure. We
10319 -- also suppress this check on run-time files.
10322 and then Is_Subprogram
(E
)
10323 and then not Has_Pragma_Pure_Function
(E
)
10324 and then not Is_Internal_Unit
(Current_Sem_Unit
)
10326 Check_Function_With_Address_Parameter
(E
);
10329 -- Ensure that all anonymous access-to-subprogram types inherit the
10330 -- convention of their related subprogram (RM 6.3.1(13.1/5)). This is
10331 -- not done for a defaulted convention Ada because those types also
10332 -- default to Ada. Convention Protected must not be propagated when
10333 -- the subprogram is an entry because this would be illegal. The only
10334 -- way to force convention Protected on these kinds of types is to
10335 -- include keyword "protected" in the access definition. Conventions
10336 -- Entry and Intrinsic are also not propagated (specified by AI12-0207).
10338 if Convention
(E
) /= Convention_Ada
10339 and then Convention
(E
) /= Convention_Protected
10340 and then Convention
(E
) /= Convention_Entry
10341 and then Convention
(E
) /= Convention_Intrinsic
10343 Set_Profile_Convention
(E
);
10346 -- For non-foreign convention subprograms, this is where we create
10347 -- the extra formals (for accessibility level and constrained bit
10348 -- information). We delay this till the freeze point precisely so
10349 -- that we know the convention.
10351 if not Has_Foreign_Convention
(E
) then
10353 -- Extra formals of dispatching operations are added later by
10354 -- Expand_Freeze_Record_Type, which also adds extra formals to
10355 -- internal entities built to handle interface types.
10357 if not Is_Dispatching_Operation
(E
) then
10358 Create_Extra_Formals
(E
);
10361 ((Ekind
(E
) = E_Subprogram_Type
10362 and then Extra_Formals_OK
(E
))
10365 and then Extra_Formals_OK
(E
)
10367 (No
(Overridden_Operation
(E
))
10368 or else Extra_Formals_Match_OK
(E
,
10369 Ultimate_Alias
(Overridden_Operation
(E
))))));
10372 Set_Mechanisms
(E
);
10374 -- If this is convention Ada and a Valued_Procedure, that's odd
10376 if Ekind
(E
) = E_Procedure
10377 and then Is_Valued_Procedure
(E
)
10378 and then Convention
(E
) = Convention_Ada
10379 and then Warn_On_Export_Import
10382 ("??Valued_Procedure has no effect for convention Ada", E
);
10383 Set_Is_Valued_Procedure
(E
, False);
10386 -- Case of foreign convention
10389 Set_Mechanisms
(E
);
10391 -- For foreign conventions, warn about return of unconstrained array
10393 if Ekind
(E
) = E_Function
then
10394 Retype
:= Underlying_Type
(Etype
(E
));
10396 -- If no return type, probably some other error, e.g. a
10397 -- missing full declaration, so ignore.
10399 if No
(Retype
) then
10402 -- If the return type is generic, we have emitted a warning
10403 -- earlier on, and there is nothing else to check here. Specific
10404 -- instantiations may lead to erroneous behavior.
10406 elsif Is_Generic_Type
(Etype
(E
)) then
10409 -- Display warning if returning unconstrained array
10411 elsif Is_Array_Type
(Retype
)
10412 and then not Is_Constrained
(Retype
)
10414 -- Check appropriate warning is enabled (should we check for
10415 -- Warnings (Off) on specific entities here, probably so???)
10417 and then Warn_On_Export_Import
10420 ("?x?foreign convention function& should not return " &
10421 "unconstrained array", E
);
10426 -- If any of the formals for an exported foreign convention
10427 -- subprogram have defaults, then emit an appropriate warning since
10428 -- this is odd (default cannot be used from non-Ada code)
10430 if Is_Exported
(E
) then
10431 F
:= First_Formal
(E
);
10432 while Present
(F
) loop
10433 if Warn_On_Export_Import
10434 and then Present
(Default_Value
(F
))
10437 ("?x?parameter cannot be defaulted in non-Ada call",
10438 Default_Value
(F
));
10446 -- Pragma Inline_Always is disallowed for dispatching subprograms
10447 -- because the address of such subprograms is saved in the dispatch
10448 -- table to support dispatching calls, and dispatching calls cannot
10449 -- be inlined. This is consistent with the restriction against using
10450 -- 'Access or 'Address on an Inline_Always subprogram.
10452 if Is_Dispatching_Operation
(E
)
10453 and then Has_Pragma_Inline_Always
(E
)
10456 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
10459 if Is_Dispatching_Operation
(E
)
10460 and then Present
(Overridden_Operation
(E
))
10462 Local_Restrict
.Check_Overriding
10463 (Overrider_Op
=> E
, Overridden_Op
=> Overridden_Operation
(E
));
10466 -- Because of the implicit representation of inherited predefined
10467 -- operators in the front-end, the overriding status of the operation
10468 -- may be affected when a full view of a type is analyzed, and this is
10469 -- not captured by the analysis of the corresponding type declaration.
10470 -- Therefore the correctness of a not-overriding indicator must be
10471 -- rechecked when the subprogram is frozen.
10473 if Nkind
(E
) = N_Defining_Operator_Symbol
10474 and then not Error_Posted
(Parent
(E
))
10476 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
10479 -- Check illegal subprograms of tagged types and interface types that
10480 -- have aspect/pragma First_Controlling_Parameter.
10482 if Comes_From_Source
(E
)
10483 and then Is_Abstract_Subprogram
(E
)
10485 if Is_Dispatching_Operation
(E
) then
10486 if Ekind
(E
) = E_Function
10487 and then Is_Interface
(Etype
(E
))
10488 and then not Is_Class_Wide_Type
(Etype
(E
))
10489 and then Has_First_Controlling_Parameter_Aspect
10490 (Find_Dispatching_Type
(E
))
10493 ("'First_'Controlling_'Parameter disallows returning a "
10494 & "non-class-wide interface type",
10499 -- The type of the formals cannot be an interface type
10501 if Present
(First_Formal
(E
)) then
10503 Formal
: Entity_Id
:= First_Formal
(E
);
10504 Has_Aspect
: Boolean := False;
10507 -- Check if some formal has the aspect
10509 while Present
(Formal
) loop
10510 if Is_Tagged_Type
(Etype
(Formal
))
10512 Has_First_Controlling_Parameter_Aspect
10515 Has_Aspect
:= True;
10518 Next_Formal
(Formal
);
10521 -- If the aspect is present then report the error
10524 Formal
:= First_Formal
(E
);
10526 while Present
(Formal
) loop
10527 if Is_Interface
(Etype
(Formal
))
10528 and then not Is_Class_Wide_Type
(Etype
(Formal
))
10531 ("not a dispatching primitive of interface type&",
10532 E
, Etype
(Formal
));
10534 ("\disallowed by 'First_'Controlling_'Parameter "
10538 Next_Formal
(Formal
);
10544 if Ekind
(E
) = E_Function
10545 and then Is_Interface
(Etype
(E
))
10546 and then not Is_Class_Wide_Type
(Etype
(E
))
10547 and then Has_First_Controlling_Parameter_Aspect
(Etype
(E
))
10550 ("not a dispatching primitive of interface type&",
10553 ("\disallowed by 'First_'Controlling_'Parameter "
10558 end Freeze_Subprogram
;
10560 ----------------------
10561 -- Is_Fully_Defined --
10562 ----------------------
10564 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
10566 if Ekind
(T
) = E_Class_Wide_Type
then
10567 return Is_Fully_Defined
(Etype
(T
));
10569 elsif Is_Array_Type
(T
) then
10570 return Is_Fully_Defined
(Component_Type
(T
));
10572 elsif Is_Record_Type
(T
)
10573 and not Is_Private_Type
(T
)
10575 -- Verify that the record type has no components with private types
10576 -- without completion.
10582 Comp
:= First_Component
(T
);
10583 while Present
(Comp
) loop
10584 if not Is_Fully_Defined
(Etype
(Comp
)) then
10588 Next_Component
(Comp
);
10593 -- For the designated type of an access to subprogram, all types in
10594 -- the profile must be fully defined.
10596 elsif Ekind
(T
) = E_Subprogram_Type
then
10601 F
:= First_Formal
(T
);
10602 while Present
(F
) loop
10603 if not Is_Fully_Defined
(Etype
(F
)) then
10610 return Is_Fully_Defined
(Etype
(T
));
10614 return not Is_Private_Type
(T
)
10615 or else Present
(Full_View
(Base_Type
(T
)));
10617 end Is_Fully_Defined
;
10619 ---------------------------------
10620 -- Process_Default_Expressions --
10621 ---------------------------------
10623 procedure Process_Default_Expressions
10625 After
: in out Node_Id
)
10627 Loc
: constant Source_Ptr
:= Sloc
(E
);
10634 Set_Default_Expressions_Processed
(E
);
10636 -- A subprogram instance and its associated anonymous subprogram share
10637 -- their signature. The default expression functions are defined in the
10638 -- wrapper packages for the anonymous subprogram, and should not be
10639 -- generated again for the instance.
10641 if Is_Generic_Instance
(E
)
10642 and then Present
(Alias
(E
))
10643 and then Default_Expressions_Processed
(Alias
(E
))
10648 Formal
:= First_Formal
(E
);
10649 while Present
(Formal
) loop
10650 if Present
(Default_Value
(Formal
)) then
10652 -- We work with a copy of the default expression because we
10653 -- do not want to disturb the original, since this would mess
10654 -- up the conformance checking.
10656 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
10658 -- The analysis of the expression may generate insert actions,
10659 -- which of course must not be executed. We wrap those actions
10660 -- in a procedure that is not called, and later on eliminated.
10661 -- The following cases have no side effects, and are analyzed
10664 if Nkind
(Dcopy
) = N_Identifier
10665 or else Nkind
(Dcopy
) in N_Expanded_Name
10666 | N_Integer_Literal
10667 | N_Character_Literal
10670 or else (Nkind
(Dcopy
) = N_Attribute_Reference
10671 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
10672 or else Known_Null
(Dcopy
)
10674 -- If there is no default function, we must still do a full
10675 -- analyze call on the default value, to ensure that all error
10676 -- checks are performed, e.g. those associated with static
10677 -- evaluation. Note: this branch will always be taken if the
10678 -- analyzer is turned off (but we still need the error checks).
10680 -- Note: the setting of parent here is to meet the requirement
10681 -- that we can only analyze the expression while attached to
10682 -- the tree. Really the requirement is that the parent chain
10683 -- be set, we don't actually need to be in the tree.
10685 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
10688 -- Default expressions are resolved with their own type if the
10689 -- context is generic, to avoid anomalies with private types.
10691 if Ekind
(Scope
(E
)) = E_Generic_Package
then
10694 Resolve
(Dcopy
, Etype
(Formal
));
10697 -- If that resolved expression will raise constraint error,
10698 -- then flag the default value as raising constraint error.
10699 -- This allows a proper error message on the calls.
10701 if Raises_Constraint_Error
(Dcopy
) then
10702 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
10705 -- If the default is a parameterless call, we use the name of
10706 -- the called function directly, and there is no body to build.
10708 elsif Nkind
(Dcopy
) = N_Function_Call
10709 and then No
(Parameter_Associations
(Dcopy
))
10713 -- Else construct and analyze the body of a wrapper procedure
10714 -- that contains an object declaration to hold the expression.
10715 -- Given that this is done only to complete the analysis, it is
10716 -- simpler to build a procedure than a function which might
10717 -- involve secondary stack expansion.
10720 Dnam
:= Make_Temporary
(Loc
, 'D');
10723 Make_Subprogram_Body
(Loc
,
10725 Make_Procedure_Specification
(Loc
,
10726 Defining_Unit_Name
=> Dnam
),
10728 Declarations
=> New_List
(
10729 Make_Object_Declaration
(Loc
,
10730 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
10731 Object_Definition
=>
10732 New_Occurrence_Of
(Etype
(Formal
), Loc
),
10733 Expression
=> New_Copy_Tree
(Dcopy
))),
10735 Handled_Statement_Sequence
=>
10736 Make_Handled_Sequence_Of_Statements
(Loc
,
10737 Statements
=> Empty_List
));
10739 Set_Scope
(Dnam
, Scope
(E
));
10740 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
10741 Set_Is_Eliminated
(Dnam
);
10742 Insert_After
(After
, Dbody
);
10748 Next_Formal
(Formal
);
10750 end Process_Default_Expressions
;
10752 ----------------------------------------
10753 -- Set_Component_Alignment_If_Not_Set --
10754 ----------------------------------------
10756 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
10758 -- Ignore if not base type, subtypes don't need anything
10760 if Typ
/= Base_Type
(Typ
) then
10764 -- Do not override existing representation
10766 if Is_Packed
(Typ
) then
10769 elsif Has_Specified_Layout
(Typ
) then
10772 elsif Component_Alignment
(Typ
) /= Calign_Default
then
10776 Set_Component_Alignment
10777 (Typ
, Scope_Stack
.Table
10778 (Scope_Stack
.Last
).Component_Alignment_Default
);
10780 end Set_Component_Alignment_If_Not_Set
;
10782 --------------------------
10783 -- Set_SSO_From_Default --
10784 --------------------------
10786 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
10787 Reversed
: Boolean;
10790 -- Set default SSO for an array or record base type, except in case of
10791 -- a type extension (which always inherits the SSO of its parent type).
10793 if Is_Base_Type
(T
)
10794 and then (Is_Array_Type
(T
)
10795 or else (Is_Record_Type
(T
)
10796 and then not (Is_Tagged_Type
(T
)
10797 and then Is_Derived_Type
(T
))))
10800 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
10802 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
10804 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
10806 -- For a record type, if bit order is specified explicitly,
10807 -- then do not set SSO from default if not consistent. Note that
10808 -- we do not want to look at a Bit_Order attribute definition
10809 -- for a parent: if we were to inherit Bit_Order, then both
10810 -- SSO_Set_*_By_Default flags would have been cleared already
10811 -- (by Inherit_Aspects_At_Freeze_Point).
10814 (Is_Record_Type
(T
)
10816 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
10817 and then Reverse_Bit_Order
(T
) /= Reversed
)
10819 -- If flags cause reverse storage order, then set the result. Note
10820 -- that we would have ignored the pragma setting the non default
10821 -- storage order in any case, hence the assertion at this point.
10824 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
10826 Set_Reverse_Storage_Order
(T
, Reversed
);
10828 -- For a record type, also set reversed bit order. Note: if a bit
10829 -- order has been specified explicitly, then this is a no-op.
10831 if Is_Record_Type
(T
) then
10832 Set_Reverse_Bit_Order
(T
, Reversed
);
10836 end Set_SSO_From_Default
;
10838 ------------------------
10839 -- Should_Freeze_Type --
10840 ------------------------
10842 function Should_Freeze_Type
10845 N
: Node_Id
) return Boolean
10847 Decl
: constant Node_Id
:= Original_Node
(Unit_Declaration_Node
(E
));
10849 function Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate
10850 (N
: Node_Id
) return Traverse_Result
;
10851 -- Return Abandon if N is a dispatching call to a subprogram
10852 -- declared in the same scope as Typ, or a tagged result that
10853 -- needs specific expansion, or an aggregate whose type is Typ.
10855 function Check_Freezing
is new
10856 Traverse_Func
(Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate
);
10857 -- Return Abandon if the input expression requires freezing Typ
10859 function Within_Simple_Return_Statement
(N
: Node_Id
) return Boolean;
10860 -- Determine whether N is the expression of a simple return statement,
10861 -- or the dependent expression of a conditional expression which is
10862 -- the expression of a simple return statement, including recursively.
10864 -------------------------------------------------------
10865 -- Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate --
10866 -------------------------------------------------------
10868 function Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate
10869 (N
: Node_Id
) return Traverse_Result
10872 if Nkind
(N
) = N_Function_Call
10873 and then Present
(Controlling_Argument
(N
))
10874 and then Scope
(Entity
(Original_Node
(Name
(N
)))) = Scope
(Typ
)
10878 -- The expansion done in Expand_Simple_Function_Return will assign
10879 -- the tag to the result in this case.
10881 elsif Is_Conversion_Or_Reference_To_Formal
(N
)
10882 and then Within_Simple_Return_Statement
(N
)
10883 and then Etype
(N
) = Typ
10884 and then Is_Tagged_Type
(Typ
)
10885 and then not Is_Class_Wide_Type
(Typ
)
10889 elsif Nkind
(N
) in N_Aggregate
10890 | N_Delta_Aggregate
10891 | N_Extension_Aggregate
10892 and then Base_Type
(Etype
(N
)) = Base_Type
(Typ
)
10899 end Is_Dispatching_Call_Or_Tagged_Result_Or_Aggregate
;
10901 ------------------------------------
10902 -- Within_Simple_Return_Statement --
10903 ------------------------------------
10905 function Within_Simple_Return_Statement
(N
: Node_Id
) return Boolean is
10906 Par
: constant Node_Id
:= Parent
(N
);
10909 if Nkind
(Par
) = N_Simple_Return_Statement
then
10912 elsif Nkind
(Par
) = N_Case_Expression_Alternative
then
10913 return Within_Simple_Return_Statement
(Parent
(Par
));
10915 elsif Nkind
(Par
) = N_If_Expression
10916 and then N
/= First
(Expressions
(Par
))
10918 return Within_Simple_Return_Statement
(Par
);
10923 end Within_Simple_Return_Statement
;
10925 -- Start of processing for Should_Freeze_Type
10928 return Within_Scope
(Typ
, Current_Scope
)
10929 or else (Nkind
(N
) = N_Subprogram_Renaming_Declaration
10930 and then Present
(Corresponding_Formal_Spec
(N
)))
10931 or else (Present
(Decl
)
10932 and then Nkind
(Decl
) = N_Expression_Function
10933 and then Check_Freezing
(Expression
(Decl
)) = Abandon
);
10934 end Should_Freeze_Type
;
10940 procedure Undelay_Type
(T
: Entity_Id
) is
10942 Set_Has_Delayed_Freeze
(T
, False);
10943 Set_Freeze_Node
(T
, Empty
);
10945 -- Since we don't want T to have a Freeze_Node, we don't want its
10946 -- Full_View or Corresponding_Record_Type to have one either.
10948 -- ??? Fundamentally, this whole handling is unpleasant. What we really
10949 -- want is to be sure that for an Itype that's part of record R and is a
10950 -- subtype of type T, that it's frozen after the later of the freeze
10951 -- points of R and T. We have no way of doing that directly, so what we
10952 -- do is force most such Itypes to be frozen as part of freezing R via
10953 -- this procedure and only delay the ones that need to be delayed
10954 -- (mostly the designated types of access types that are defined as part
10957 if Is_Private_Type
(T
)
10958 and then Present
(Full_View
(T
))
10959 and then Is_Itype
(Full_View
(T
))
10960 and then Is_Record_Type
(Scope
(Full_View
(T
)))
10962 Undelay_Type
(Full_View
(T
));
10965 if Is_Concurrent_Type
(T
)
10966 and then Present
(Corresponding_Record_Type
(T
))
10967 and then Is_Itype
(Corresponding_Record_Type
(T
))
10968 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
10970 Undelay_Type
(Corresponding_Record_Type
(T
));
10978 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
) is
10979 Ent
: constant Entity_Id
:= Entity
(Nam
);
10980 -- The object to which the address clause applies
10983 Old
: Entity_Id
:= Empty
;
10987 -- No warning if address clause overlay warnings are off
10989 if not Address_Clause_Overlay_Warnings
then
10993 -- No warning if there is an explicit initialization
10995 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
10997 if Present
(Init
) and then Comes_From_Source
(Init
) then
11001 -- We only give the warning for non-imported entities of a type for
11002 -- which a non-null base init proc is defined, or for objects of access
11003 -- types with implicit null initialization, or when Normalize_Scalars
11004 -- applies and the type is scalar or a string type (the latter being
11005 -- tested for because predefined String types are initialized by inline
11006 -- code rather than by an init_proc). Note that we do not give the
11007 -- warning for Initialize_Scalars, since we suppressed initialization
11008 -- in this case. Also, do not warn if Suppress_Initialization is set
11009 -- either on the type, or on the object via pragma or aspect.
11012 and then not Is_Imported
(Ent
)
11013 and then not Initialization_Suppressed
(Typ
)
11014 and then not (Ekind
(Ent
) = E_Variable
11015 and then Initialization_Suppressed
(Ent
))
11016 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
11017 or else Is_Access_Type
(Typ
)
11018 or else (Normalize_Scalars
11019 and then (Is_Scalar_Type
(Typ
)
11020 or else Is_String_Type
(Typ
))))
11022 if Nkind
(Expr
) = N_Attribute_Reference
11023 and then Is_Entity_Name
(Prefix
(Expr
))
11025 Old
:= Entity
(Prefix
(Expr
));
11027 elsif Is_Entity_Name
(Expr
)
11028 and then Ekind
(Entity
(Expr
)) = E_Constant
11030 Decl
:= Declaration_Node
(Entity
(Expr
));
11032 if Nkind
(Decl
) = N_Object_Declaration
11033 and then Present
(Expression
(Decl
))
11034 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
11035 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
11037 Old
:= Entity
(Prefix
(Expression
(Decl
)));
11039 elsif Nkind
(Expr
) = N_Function_Call
then
11043 -- A function call (most likely to To_Address) is probably not an
11044 -- overlay, so skip warning. Ditto if the function call was inlined
11045 -- and transformed into an entity.
11047 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
11051 -- If a pragma Import follows, we assume that it is for the current
11052 -- target of the address clause, and skip the warning. There may be
11053 -- a source pragma or an aspect that specifies import and generates
11054 -- the corresponding pragma. These will indicate that the entity is
11055 -- imported and that is checked above so that the spurious warning
11056 -- (generated when the entity is frozen) will be suppressed. The
11057 -- pragma may be attached to the aspect, so it is not yet a list
11060 if Is_List_Member
(Parent
(Expr
)) then
11061 Decl
:= Next
(Parent
(Expr
));
11064 and then Nkind
(Decl
) = N_Pragma
11065 and then Pragma_Name
(Decl
) = Name_Import
11071 -- Otherwise give warning message
11073 if Present
(Old
) then
11074 Error_Msg_Node_2
:= Old
;
11076 ("default initialization of & may modify &?o?",
11080 ("default initialization of & may modify overlaid storage?o?",
11084 -- Add friendly warning if initialization comes from a packed array
11087 if Is_Record_Type
(Typ
) then
11092 Comp
:= First_Component
(Typ
);
11093 while Present
(Comp
) loop
11094 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
11095 and then Present
(Expression
(Parent
(Comp
)))
11098 elsif Is_Array_Type
(Etype
(Comp
))
11099 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
11102 ("\packed array component& " &
11103 "will be initialized to zero?o?",
11107 Next_Component
(Comp
);
11114 ("\use pragma Import for & to " &
11115 "suppress initialization (RM B.1(24))?o?",