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 function Should_Freeze_Type
189 (Typ
: Entity_Id
; E
: Entity_Id
; N
: Node_Id
) return Boolean;
190 -- If Typ is in the current scope, then return True.
191 -- N is a node whose source location corresponds to the freeze point.
192 -- ??? Expression functions (represented by E) shouldn't freeze types in
193 -- general, but our current expansion and freezing model requires an early
194 -- freezing when the dispatch table is needed or when building an aggregate
195 -- with a subtype of Typ, so return True also in this case.
196 -- Note that expression function completions do freeze and are
197 -- handled in Sem_Ch6.Analyze_Expression_Function.
199 ------------------------
200 -- Should_Freeze_Type --
201 ------------------------
203 function Should_Freeze_Type
204 (Typ
: Entity_Id
; E
: Entity_Id
; N
: Node_Id
) return Boolean
206 function Is_Dispatching_Call_Or_Aggregate
207 (N
: Node_Id
) return Traverse_Result
;
208 -- Return Abandon if N is a dispatching call to a subprogram
209 -- declared in the same scope as Typ or an aggregate whose type
212 --------------------------------------
213 -- Is_Dispatching_Call_Or_Aggregate --
214 --------------------------------------
216 function Is_Dispatching_Call_Or_Aggregate
217 (N
: Node_Id
) return Traverse_Result
is
219 if Nkind
(N
) = N_Function_Call
220 and then Present
(Controlling_Argument
(N
))
221 and then Scope
(Entity
(Original_Node
(Name
(N
))))
225 elsif Nkind
(N
) in N_Aggregate
226 | N_Extension_Aggregate
228 and then Base_Type
(Etype
(N
)) = Base_Type
(Typ
)
234 end Is_Dispatching_Call_Or_Aggregate
;
236 -------------------------
237 -- Need_Dispatch_Table --
238 -------------------------
240 function Need_Dispatch_Table
is new
241 Traverse_Func
(Is_Dispatching_Call_Or_Aggregate
);
242 -- Return Abandon if the input expression requires access to
243 -- Typ's dispatch table.
245 Decl
: constant Node_Id
:=
246 (if No
(E
) then E
else Original_Node
(Unit_Declaration_Node
(E
)));
248 -- Start of processing for Should_Freeze_Type
251 return Within_Scope
(Typ
, Current_Scope
)
252 or else (Nkind
(N
) = N_Subprogram_Renaming_Declaration
253 and then Present
(Corresponding_Formal_Spec
(N
)))
254 or else (Present
(Decl
)
255 and then Nkind
(Decl
) = N_Expression_Function
256 and then Need_Dispatch_Table
(Expression
(Decl
)) = Abandon
);
257 end Should_Freeze_Type
;
259 procedure Process_Default_Expressions
261 After
: in out Node_Id
);
262 -- This procedure is called for each subprogram to complete processing of
263 -- default expressions at the point where all types are known to be frozen.
264 -- The expressions must be analyzed in full, to make sure that all error
265 -- processing is done (they have only been preanalyzed). If the expression
266 -- is not an entity or literal, its analysis may generate code which must
267 -- not be executed. In that case we build a function body to hold that
268 -- code. This wrapper function serves no other purpose (it used to be
269 -- called to evaluate the default, but now the default is inlined at each
272 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
273 -- Typ is a record or array type that is being frozen. This routine sets
274 -- the default component alignment from the scope stack values if the
275 -- alignment is otherwise not specified.
277 procedure Set_SSO_From_Default
(T
: Entity_Id
);
278 -- T is a record or array type that is being frozen. If it is a base type,
279 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
280 -- will be set appropriately. Note that an explicit occurrence of aspect
281 -- Scalar_Storage_Order or an explicit setting of this aspect with an
282 -- attribute definition clause occurs, then these two flags are reset in
283 -- any case, so call will have no effect.
285 procedure Undelay_Type
(T
: Entity_Id
);
286 -- T is a type of a component that we know to be an Itype. We don't want
287 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
288 -- Full_View or Corresponding_Record_Type.
290 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
);
291 -- Expr is the expression for an address clause for the entity denoted by
292 -- Nam whose type is Typ. If Typ has a default initialization, and there is
293 -- no explicit initialization in the source declaration, check whether the
294 -- address clause might cause overlaying of an entity, and emit a warning
295 -- on the side effect that the initialization will cause.
297 -------------------------------
298 -- Adjust_Esize_For_Alignment --
299 -------------------------------
301 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
305 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
306 Align
:= Alignment_In_Bits
(Typ
);
308 if Align
> Esize
(Typ
) then
309 if Align
> System_Max_Integer_Size
then
310 pragma Assert
(Serious_Errors_Detected
> 0);
312 Set_Esize
(Typ
, Align
);
316 end Adjust_Esize_For_Alignment
;
318 ------------------------------------
319 -- Build_And_Analyze_Renamed_Body --
320 ------------------------------------
322 procedure Build_And_Analyze_Renamed_Body
325 After
: in out Node_Id
)
327 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
328 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
330 Renamed_Subp
: Entity_Id
;
333 -- If the renamed subprogram is intrinsic, there is no need for a
334 -- wrapper body: we set the alias that will be called and expanded which
335 -- completes the declaration. This transformation is only legal if the
336 -- renamed entity has already been elaborated.
338 -- Note that it is legal for a renaming_as_body to rename an intrinsic
339 -- subprogram, as long as the renaming occurs before the new entity
340 -- is frozen (RM 8.5.4 (5)).
342 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
343 and then Is_Entity_Name
(Name
(Body_Decl
))
345 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
347 Renamed_Subp
:= Empty
;
350 if Present
(Renamed_Subp
)
351 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
353 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
354 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
356 -- We can make the renaming entity intrinsic if the renamed function
357 -- has an interface name, or if it is one of the shift/rotate
358 -- operations known to the compiler.
361 (Present
(Interface_Name
(Renamed_Subp
))
362 or else Chars
(Renamed_Subp
) in Name_Rotate_Left
366 | Name_Shift_Right_Arithmetic
)
368 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
370 if Present
(Alias
(Renamed_Subp
)) then
371 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
373 Set_Alias
(Ent
, Renamed_Subp
);
376 Set_Is_Intrinsic_Subprogram
(Ent
);
377 Set_Has_Completion
(Ent
);
380 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
381 Insert_After
(After
, Body_Node
);
382 Mark_Rewrite_Insertion
(Body_Node
);
386 end Build_And_Analyze_Renamed_Body
;
388 ------------------------
389 -- Build_Renamed_Body --
390 ------------------------
392 function Build_Renamed_Body
394 New_S
: Entity_Id
) return Node_Id
396 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
397 -- We use for the source location of the renamed body, the location of
398 -- the spec entity. It might seem more natural to use the location of
399 -- the renaming declaration itself, but that would be wrong, since then
400 -- the body we create would look as though it was created far too late,
401 -- and this could cause problems with elaboration order analysis,
402 -- particularly in connection with instantiations.
404 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
405 Nam
: constant Node_Id
:= Name
(N
);
407 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
413 O_Formal
: Entity_Id
;
414 Param_Spec
: Node_Id
;
416 Pref
: Node_Id
:= Empty
;
417 -- If the renamed entity is a primitive operation given in prefix form,
418 -- the prefix is the target object and it has to be added as the first
419 -- actual in the generated call.
422 -- Determine the entity being renamed, which is the target of the call
423 -- statement. If the name is an explicit dereference, this is a renaming
424 -- of a subprogram type rather than a subprogram. The name itself is
427 if Nkind
(Nam
) = N_Selected_Component
then
428 Old_S
:= Entity
(Selector_Name
(Nam
));
430 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
431 Old_S
:= Etype
(Nam
);
433 elsif Nkind
(Nam
) = N_Indexed_Component
then
434 if Is_Entity_Name
(Prefix
(Nam
)) then
435 Old_S
:= Entity
(Prefix
(Nam
));
437 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
440 elsif Nkind
(Nam
) = N_Character_Literal
then
441 Old_S
:= Etype
(New_S
);
444 Old_S
:= Entity
(Nam
);
447 if Is_Entity_Name
(Nam
) then
449 -- If the renamed entity is a predefined operator, retain full name
450 -- to ensure its visibility.
452 if Ekind
(Old_S
) = E_Operator
453 and then Nkind
(Nam
) = N_Expanded_Name
455 Call_Name
:= New_Copy
(Name
(N
));
457 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
461 if Nkind
(Nam
) = N_Selected_Component
462 and then Present
(First_Formal
(Old_S
))
464 (Is_Controlling_Formal
(First_Formal
(Old_S
))
465 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
468 -- Retrieve the target object, to be added as a first actual
471 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
472 Pref
:= Prefix
(Nam
);
475 Call_Name
:= New_Copy
(Name
(N
));
478 -- Original name may have been overloaded, but is fully resolved now
480 Set_Is_Overloaded
(Call_Name
, False);
483 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
485 Make_Subprogram_Declaration
(Loc
,
486 Specification
=> Specification
(N
)));
489 -- For simple renamings, subsequent calls can be expanded directly as
490 -- calls to the renamed entity. The body must be generated in any case
491 -- for calls that may appear elsewhere. This is not done in the case
492 -- where the subprogram is an instantiation because the actual proper
493 -- body has not been built yet.
495 if Ekind
(Old_S
) in E_Function | E_Procedure
496 and then not Is_Generic_Instance
(Old_S
)
498 Set_Body_To_Inline
(Decl
, Old_S
);
501 -- Check whether the return type is a limited view. If the subprogram
502 -- is already frozen the generated body may have a non-limited view
503 -- of the type, that must be used, because it is the one in the spec
504 -- of the renaming declaration.
506 if Ekind
(Old_S
) = E_Function
507 and then Is_Entity_Name
(Result_Definition
(Spec
))
510 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
512 if Has_Non_Limited_View
(Ret_Type
) then
513 Set_Result_Definition
514 (Spec
, New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
519 -- The body generated for this renaming is an internal artifact, and
520 -- does not constitute a freeze point for the called entity.
522 Set_Must_Not_Freeze
(Call_Name
);
524 Formal
:= First_Formal
(Defining_Entity
(Decl
));
526 if Present
(Pref
) then
528 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
529 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
532 -- The controlling formal may be an access parameter, or the
533 -- actual may be an access value, so adjust accordingly.
535 if Is_Access_Type
(Pref_Type
)
536 and then not Is_Access_Type
(Form_Type
)
539 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
541 elsif Is_Access_Type
(Form_Type
)
542 and then not Is_Access_Type
(Pref
)
546 Make_Attribute_Reference
(Loc
,
547 Attribute_Name
=> Name_Access
,
548 Prefix
=> Relocate_Node
(Pref
)));
550 Actuals
:= New_List
(Pref
);
554 elsif Present
(Formal
) then
561 while Present
(Formal
) loop
562 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
563 Next_Formal
(Formal
);
566 -- If the renamed entity is an entry, inherit its profile. For other
567 -- renamings as bodies, both profiles must be subtype conformant, so it
568 -- is not necessary to replace the profile given in the declaration.
569 -- However, default values that are aggregates are rewritten when
570 -- partially analyzed, so we recover the original aggregate to insure
571 -- that subsequent conformity checking works. Similarly, if the default
572 -- expression was constant-folded, recover the original expression.
574 Formal
:= First_Formal
(Defining_Entity
(Decl
));
576 if Present
(Formal
) then
577 O_Formal
:= First_Formal
(Old_S
);
578 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
579 while Present
(Formal
) loop
580 if Is_Entry
(Old_S
) then
581 if Nkind
(Parameter_Type
(Param_Spec
)) /=
584 Set_Etype
(Formal
, Etype
(O_Formal
));
585 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
588 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
589 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
590 Nkind
(Default_Value
(O_Formal
))
592 Set_Expression
(Param_Spec
,
593 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
596 Next_Formal
(Formal
);
597 Next_Formal
(O_Formal
);
602 -- If the renamed entity is a function, the generated body contains a
603 -- return statement. Otherwise, build a procedure call. If the entity is
604 -- an entry, subsequent analysis of the call will transform it into the
605 -- proper entry or protected operation call. If the renamed entity is
606 -- a character literal, return it directly.
608 if Ekind
(Old_S
) = E_Function
609 or else Ekind
(Old_S
) = E_Operator
610 or else (Ekind
(Old_S
) = E_Subprogram_Type
611 and then Etype
(Old_S
) /= Standard_Void_Type
)
614 Make_Simple_Return_Statement
(Loc
,
616 Make_Function_Call
(Loc
,
618 Parameter_Associations
=> Actuals
));
620 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
622 Make_Simple_Return_Statement
(Loc
,
623 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
625 elsif Nkind
(Nam
) = N_Character_Literal
then
627 Make_Simple_Return_Statement
(Loc
, Expression
=> Call_Name
);
631 Make_Procedure_Call_Statement
(Loc
,
633 Parameter_Associations
=> Actuals
);
636 -- Create entities for subprogram body and formals
638 Set_Defining_Unit_Name
(Spec
,
639 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
641 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
642 while Present
(Param_Spec
) loop
643 Set_Defining_Identifier
(Param_Spec
,
644 Make_Defining_Identifier
(Loc
,
645 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
649 -- In GNATprove, prefer to generate an expression function whenever
650 -- possible, to benefit from the more precise analysis in that case
651 -- (as if an implicit postcondition had been generated).
654 and then Nkind
(Call_Node
) = N_Simple_Return_Statement
657 Make_Expression_Function
(Loc
,
658 Specification
=> Spec
,
659 Expression
=> Expression
(Call_Node
));
662 Make_Subprogram_Body
(Loc
,
663 Specification
=> Spec
,
664 Declarations
=> New_List
,
665 Handled_Statement_Sequence
=>
666 Make_Handled_Sequence_Of_Statements
(Loc
,
667 Statements
=> New_List
(Call_Node
)));
670 -- Link the body to the entity whose declaration it completes. If
671 -- the body is analyzed when the renamed entity is frozen, it may
672 -- be necessary to restore the proper scope (see package Exp_Ch13).
674 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
675 and then Present
(Corresponding_Spec
(N
))
677 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
679 Set_Corresponding_Spec
(Body_Node
, New_S
);
683 end Build_Renamed_Body
;
685 --------------------------
686 -- Check_Address_Clause --
687 --------------------------
689 procedure Check_Address_Clause
(E
: Entity_Id
) is
690 Addr
: constant Node_Id
:= Address_Clause
(E
);
691 Typ
: constant Entity_Id
:= Etype
(E
);
696 Tag_Assign
: Node_Id
;
699 if Present
(Addr
) then
701 -- For a deferred constant, the initialization value is on full view
703 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
704 Decl
:= Declaration_Node
(Full_View
(E
));
706 Decl
:= Declaration_Node
(E
);
709 Expr
:= Expression
(Addr
);
711 if Needs_Constant_Address
(Decl
, Typ
) then
712 Check_Constant_Address_Clause
(Expr
, E
);
714 -- Has_Delayed_Freeze was set on E when the address clause was
715 -- analyzed, and must remain set because we want the address
716 -- clause to be elaborated only after any entity it references
717 -- has been elaborated.
720 -- If Rep_Clauses are to be ignored, remove address clause from
721 -- list attached to entity, because it may be illegal for gigi,
722 -- for example by breaking order of elaboration.
724 if Ignore_Rep_Clauses
then
729 Rep
:= First_Rep_Item
(E
);
732 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
736 and then Next_Rep_Item
(Rep
) /= Addr
742 if Present
(Rep
) then
743 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
747 -- And now remove the address clause
749 Kill_Rep_Clause
(Addr
);
751 elsif not Error_Posted
(Expr
)
752 and then not Needs_Finalization
(Typ
)
754 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
757 Init
:= Expression
(Decl
);
759 -- If a variable, or a non-imported constant, overlays a constant
760 -- object and has an initialization value, then the initialization
761 -- may end up writing into read-only memory. Detect the cases of
762 -- statically identical values and remove the initialization. In
763 -- the other cases, give a warning. We will give other warnings
764 -- later for the variable if it is assigned.
766 if (Ekind
(E
) = E_Variable
767 or else (Ekind
(E
) = E_Constant
768 and then not Is_Imported
(E
)))
769 and then Overlays_Constant
(E
)
770 and then Present
(Init
)
777 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
779 if Ekind
(O_Ent
) = E_Constant
780 and then Etype
(O_Ent
) = Typ
781 and then Present
(Constant_Value
(O_Ent
))
782 and then Compile_Time_Compare
784 Constant_Value
(O_Ent
),
785 Assume_Valid
=> True) = EQ
787 Set_No_Initialization
(Decl
);
790 elsif Comes_From_Source
(Init
)
791 and then Address_Clause_Overlay_Warnings
793 Error_Msg_Sloc
:= Sloc
(Addr
);
795 ("?o?constant& may be modified via address clause#",
801 -- Remove side effects from initial expression, except in the case of
802 -- limited build-in-place calls and aggregates, which have their own
803 -- expansion elsewhere. This exception is necessary to avoid copying
807 and then not Is_Inherently_Limited_Type
(Typ
)
809 -- Capture initialization value at point of declaration, and make
810 -- explicit assignment legal, because object may be a constant.
812 Remove_Side_Effects
(Init
);
813 Lhs
:= New_Occurrence_Of
(E
, Sloc
(Decl
));
814 Set_Assignment_OK
(Lhs
);
816 -- Move initialization to freeze actions, once the object has
817 -- been frozen and the address clause alignment check has been
820 Append_Freeze_Action
(E
,
821 Make_Assignment_Statement
(Sloc
(Decl
),
823 Expression
=> Expression
(Decl
)));
825 Set_No_Initialization
(Decl
);
827 -- If the object is tagged, check whether the tag must be
828 -- reassigned explicitly.
830 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
831 if Present
(Tag_Assign
) then
832 Append_Freeze_Action
(E
, Tag_Assign
);
836 end Check_Address_Clause
;
838 -----------------------------
839 -- Check_Compile_Time_Size --
840 -----------------------------
842 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
844 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
845 -- Sets the compile time known size in the RM_Size field of T, checking
846 -- for a size clause that was given which attempts to give a small size.
848 function Size_Known
(T
: Entity_Id
) return Boolean;
849 -- Recursive function that does all the work
851 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
852 -- If T is a constrained subtype, its size is not known if any of its
853 -- discriminant constraints is not static and it is not a null record.
854 -- The test is conservative and doesn't check that the components are
855 -- in fact constrained by non-static discriminant values. Could be made
862 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
864 if S
> System_Max_Integer_Size
then
867 -- Check for bad size clause given
869 elsif Has_Size_Clause
(T
) then
870 if RM_Size
(T
) < S
then
871 Error_Msg_Uint_1
:= S
;
872 Error_Msg_NE
(Size_Too_Small_Message
, Size_Clause
(T
), T
);
875 -- Set size if not set already. Do not set it to Uint_0, because in
876 -- some cases (notably array-of-record), the Component_Size is
877 -- No_Uint, which causes S to be Uint_0. Presumably the RM_Size and
878 -- Component_Size will eventually be set correctly by the back end.
880 elsif not Known_RM_Size
(T
) and then S
/= Uint_0
then
889 function Size_Known
(T
: Entity_Id
) return Boolean is
894 if Size_Known_At_Compile_Time
(T
) then
897 -- Always True for elementary types, even generic formal elementary
898 -- types. We used to return False in the latter case, but the size
899 -- is known at compile time, even in the template, we just do not
900 -- know the exact size but that's not the point of this routine.
902 elsif Is_Elementary_Type
(T
) or else Is_Task_Type
(T
) then
907 elsif Is_Array_Type
(T
) then
909 -- String literals always have known size, and we can set it
911 if Ekind
(T
) = E_String_Literal_Subtype
then
912 if Known_Component_Size
(T
) then
914 (T
, Component_Size
(T
) * String_Literal_Length
(T
));
917 -- The following is wrong, but does what previous versions
918 -- did. The Component_Size is unknown for the string in a
920 Set_Small_Size
(T
, Uint_0
);
925 -- Unconstrained types never have known at compile time size
927 elsif not Is_Constrained
(T
) then
930 -- Don't do any recursion on type with error posted, since we may
931 -- have a malformed type that leads us into a loop.
933 elsif Error_Posted
(T
) then
936 -- Otherwise if component size unknown, then array size unknown
938 elsif not Size_Known
(Component_Type
(T
)) then
942 -- Check for all indexes static, and also compute possible size
943 -- (in case it is not greater than System_Max_Integer_Size and
944 -- thus may be packable).
950 Size
: Uint
:= Component_Size
(T
);
954 -- See comment in Set_Small_Size above
960 Index
:= First_Index
(T
);
961 while Present
(Index
) loop
962 if Nkind
(Index
) = N_Range
then
963 Get_Index_Bounds
(Index
, Low
, High
);
965 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
969 Low
:= Type_Low_Bound
(Etype
(Index
));
970 High
:= Type_High_Bound
(Etype
(Index
));
973 if not Compile_Time_Known_Value
(Low
)
974 or else not Compile_Time_Known_Value
(High
)
975 or else Etype
(Index
) = Any_Type
980 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
992 Set_Small_Size
(T
, Size
);
996 -- For non-generic private types, go to underlying type if present
998 elsif Is_Private_Type
(T
)
999 and then not Is_Generic_Type
(T
)
1000 and then Present
(Underlying_Type
(T
))
1002 -- Don't do any recursion on type with error posted, since we may
1003 -- have a malformed type that leads us into a loop.
1005 if Error_Posted
(T
) then
1008 return Size_Known
(Underlying_Type
(T
));
1013 elsif Is_Record_Type
(T
) then
1015 -- A subtype of a variant record must not have non-static
1016 -- discriminated components.
1018 if T
/= Base_Type
(T
)
1019 and then not Static_Discriminated_Components
(T
)
1023 -- Don't do any recursion on type with error posted, since we may
1024 -- have a malformed type that leads us into a loop.
1026 elsif Error_Posted
(T
) then
1030 -- Now look at the components of the record
1033 -- The following two variables are used to keep track of the
1034 -- size of packed records if we can tell the size of the packed
1035 -- record in the front end. Packed_Size_Known is True if so far
1036 -- we can figure out the size. It is initialized to True for a
1037 -- packed record, unless the record has either discriminants or
1038 -- independent components, or is a strict-alignment type, since
1039 -- it cannot be fully packed in this case.
1041 -- The reason we eliminate the discriminated case is that
1042 -- we don't know the way the back end lays out discriminated
1043 -- packed records. If Packed_Size_Known is True, then
1044 -- Packed_Size is the size in bits so far.
1046 Packed_Size_Known
: Boolean :=
1048 and then not Has_Discriminants
(T
)
1049 and then not Has_Independent_Components
(T
)
1050 and then not Strict_Alignment
(T
);
1052 Packed_Size
: Uint
:= Uint_0
;
1053 -- Size in bits so far
1056 -- Test for variant part present
1058 if Has_Discriminants
(T
)
1059 and then Present
(Parent
(T
))
1060 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
1061 and then Nkind
(Type_Definition
(Parent
(T
))) =
1063 and then not Null_Present
(Type_Definition
(Parent
(T
)))
1065 Present
(Variant_Part
1066 (Component_List
(Type_Definition
(Parent
(T
)))))
1068 -- If variant part is present, and type is unconstrained,
1069 -- then we must have defaulted discriminants, or a size
1070 -- clause must be present for the type, or else the size
1071 -- is definitely not known at compile time.
1073 if not Is_Constrained
(T
)
1075 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
1076 and then not Known_RM_Size
(T
)
1077 and then not Known_Esize
(T
)
1083 -- Loop through components
1085 Comp
:= First_Component_Or_Discriminant
(T
);
1086 while Present
(Comp
) loop
1087 Ctyp
:= Etype
(Comp
);
1089 -- We do not know the packed size if there is a component
1090 -- clause present (we possibly could, but this would only
1091 -- help in the case of a record with partial rep clauses.
1092 -- That's because in the case of full rep clauses, the
1093 -- size gets figured out anyway by a different circuit).
1095 if Present
(Component_Clause
(Comp
)) then
1096 Packed_Size_Known
:= False;
1099 -- We do not know the packed size for an independent
1100 -- component or if it is of a strict-alignment type,
1101 -- since packing does not touch these (RM 13.2(7)).
1103 if Is_Independent
(Comp
)
1104 or else Is_Independent
(Ctyp
)
1105 or else Strict_Alignment
(Ctyp
)
1107 Packed_Size_Known
:= False;
1110 -- We need to identify a component that is an array where
1111 -- the index type is an enumeration type with non-standard
1112 -- representation, and some bound of the type depends on a
1115 -- This is because gigi computes the size by doing a
1116 -- substitution of the appropriate discriminant value in
1117 -- the size expression for the base type, and gigi is not
1118 -- clever enough to evaluate the resulting expression (which
1119 -- involves a call to rep_to_pos) at compile time.
1121 -- It would be nice if gigi would either recognize that
1122 -- this expression can be computed at compile time, or
1123 -- alternatively figured out the size from the subtype
1124 -- directly, where all the information is at hand ???
1126 if Is_Array_Type
(Etype
(Comp
))
1127 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1130 Ocomp
: constant Entity_Id
:=
1131 Original_Record_Component
(Comp
);
1132 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1138 Ind
:= First_Index
(OCtyp
);
1139 while Present
(Ind
) loop
1140 Indtyp
:= Etype
(Ind
);
1142 if Is_Enumeration_Type
(Indtyp
)
1143 and then Has_Non_Standard_Rep
(Indtyp
)
1145 Lo
:= Type_Low_Bound
(Indtyp
);
1146 Hi
:= Type_High_Bound
(Indtyp
);
1148 if Is_Entity_Name
(Lo
)
1149 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1153 elsif Is_Entity_Name
(Hi
)
1154 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1165 -- Clearly size of record is not known if the size of one of
1166 -- the components is not known.
1168 if not Size_Known
(Ctyp
) then
1172 -- Accumulate packed size if possible
1174 if Packed_Size_Known
then
1176 -- We can deal with elementary types, small packed arrays
1177 -- if the representation is a modular type and also small
1178 -- record types as checked by Set_Small_Size.
1180 if Is_Elementary_Type
(Ctyp
)
1181 or else (Is_Array_Type
(Ctyp
)
1183 (Packed_Array_Impl_Type
(Ctyp
))
1184 and then Is_Modular_Integer_Type
1185 (Packed_Array_Impl_Type
(Ctyp
)))
1186 or else Is_Record_Type
(Ctyp
)
1188 -- If RM_Size is known and static, then we can keep
1189 -- accumulating the packed size.
1191 if Known_Static_RM_Size
(Ctyp
) then
1193 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1195 -- If we have a field whose RM_Size is not known then
1196 -- we can't figure out the packed size here.
1199 Packed_Size_Known
:= False;
1202 -- For other types we can't figure out the packed size
1205 Packed_Size_Known
:= False;
1209 Next_Component_Or_Discriminant
(Comp
);
1212 if Packed_Size_Known
then
1213 Set_Small_Size
(T
, Packed_Size
);
1219 -- All other cases, size not known at compile time
1226 -------------------------------------
1227 -- Static_Discriminated_Components --
1228 -------------------------------------
1230 function Static_Discriminated_Components
1231 (T
: Entity_Id
) return Boolean
1233 Constraint
: Elmt_Id
;
1236 if Has_Discriminants
(T
)
1237 and then Present
(Discriminant_Constraint
(T
))
1238 and then Present
(First_Component
(T
))
1240 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1241 while Present
(Constraint
) loop
1242 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1246 Next_Elmt
(Constraint
);
1251 end Static_Discriminated_Components
;
1253 -- Start of processing for Check_Compile_Time_Size
1256 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1257 end Check_Compile_Time_Size
;
1259 -----------------------------------
1260 -- Check_Component_Storage_Order --
1261 -----------------------------------
1263 procedure Check_Component_Storage_Order
1264 (Encl_Type
: Entity_Id
;
1267 Comp_ADC_Present
: out Boolean)
1269 Comp_Base
: Entity_Id
;
1271 Encl_Base
: Entity_Id
;
1274 Component_Aliased
: Boolean;
1276 Comp_Byte_Aligned
: Boolean := False;
1277 -- Set for the record case, True if Comp is aligned on byte boundaries
1278 -- (in which case it is allowed to have different storage order).
1280 Comp_SSO_Differs
: Boolean;
1281 -- Set True when the component is a nested composite, and it does not
1282 -- have the same scalar storage order as Encl_Type.
1287 if Present
(Comp
) then
1289 Comp_Base
:= Etype
(Comp
);
1291 if Is_Tag
(Comp
) then
1292 Comp_Byte_Aligned
:= True;
1293 Component_Aliased
:= False;
1296 -- If a component clause is present, check if the component starts
1297 -- and ends on byte boundaries. Otherwise conservatively assume it
1298 -- does so only in the case where the record is not packed.
1300 if Present
(Component_Clause
(Comp
)) then
1301 Comp_Byte_Aligned
:=
1302 Known_Normalized_First_Bit
(Comp
)
1306 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0
1308 Esize
(Comp
) mod System_Storage_Unit
= 0;
1310 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1313 Component_Aliased
:= Is_Aliased
(Comp
);
1319 Err_Node
:= Encl_Type
;
1320 Comp_Base
:= Component_Type
(Encl_Type
);
1322 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1325 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1326 -- the attribute definition clause is attached to the first subtype.
1327 -- Also, if the base type is incomplete or private, go to full view
1330 Encl_Base
:= Base_Type
(Encl_Type
);
1331 if Present
(Underlying_Type
(Encl_Base
)) then
1332 Encl_Base
:= Underlying_Type
(Encl_Base
);
1335 Comp_Base
:= Base_Type
(Comp_Base
);
1336 if Present
(Underlying_Type
(Comp_Base
)) then
1337 Comp_Base
:= Underlying_Type
(Comp_Base
);
1341 Get_Attribute_Definition_Clause
1342 (First_Subtype
(Comp_Base
), Attribute_Scalar_Storage_Order
);
1343 Comp_ADC_Present
:= Present
(Comp_ADC
);
1345 -- Case of record or array component: check storage order compatibility.
1346 -- But, if the record has Complex_Representation, then it is treated as
1347 -- a scalar in the back end so the storage order is irrelevant.
1349 if (Is_Record_Type
(Comp_Base
)
1350 and then not Has_Complex_Representation
(Comp_Base
))
1351 or else Is_Array_Type
(Comp_Base
)
1354 Reverse_Storage_Order
(Encl_Base
) /=
1355 Reverse_Storage_Order
(Comp_Base
);
1357 -- Parent and extension must have same storage order
1359 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1360 if Comp_SSO_Differs
then
1362 ("record extension must have same scalar storage order as "
1363 & "parent", Err_Node
);
1366 -- If component and composite SSO differs, check that component
1367 -- falls on byte boundaries and isn't bit packed.
1369 elsif Comp_SSO_Differs
then
1371 -- Component SSO differs from enclosing composite:
1373 -- Reject if composite is a bit-packed array, as it is rewritten
1374 -- into an array of scalars.
1376 if Is_Bit_Packed_Array
(Encl_Base
) then
1378 ("type of packed array must have same scalar storage order "
1379 & "as component", Err_Node
);
1381 -- Reject if not byte aligned
1383 elsif Is_Record_Type
(Encl_Base
)
1384 and then not Comp_Byte_Aligned
1386 if Present
(Component_Clause
(Comp
)) then
1388 ("type of non-byte-aligned component must have same scalar"
1389 & " storage order as enclosing record", Err_Node
);
1392 ("type of packed component must have same scalar"
1393 & " storage order as enclosing record", Err_Node
);
1396 -- Warn if specified only for the outer composite
1398 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1400 ("scalar storage order specified for & does not apply to "
1401 & "component?", Err_Node
, Encl_Base
);
1405 -- Enclosing type has explicit SSO: non-composite component must not
1408 elsif Present
(ADC
) and then Component_Aliased
then
1410 ("aliased component not permitted for type with explicit "
1411 & "Scalar_Storage_Order", Err_Node
);
1413 end Check_Component_Storage_Order
;
1415 -----------------------------
1416 -- Check_Debug_Info_Needed --
1417 -----------------------------
1419 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1421 if Debug_Info_Off
(T
) then
1424 elsif Comes_From_Source
(T
)
1425 or else Debug_Generated_Code
1426 or else Debug_Flag_VV
1427 or else Needs_Debug_Info
(T
)
1429 Set_Debug_Info_Needed
(T
);
1431 end Check_Debug_Info_Needed
;
1433 -------------------------------
1434 -- Check_Expression_Function --
1435 -------------------------------
1437 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1438 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1439 -- Function to search for deferred constant
1445 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1447 -- When a constant is initialized with the result of a dispatching
1448 -- call, the constant declaration is rewritten as a renaming of the
1449 -- displaced function result. This scenario is not a premature use of
1450 -- a constant even though the Has_Completion flag is not set.
1452 if Is_Entity_Name
(Nod
)
1453 and then Present
(Entity
(Nod
))
1454 and then Ekind
(Entity
(Nod
)) = E_Constant
1455 and then Scope
(Entity
(Nod
)) = Current_Scope
1456 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1457 N_Object_Declaration
1458 and then not Is_Imported
(Entity
(Nod
))
1459 and then not Has_Completion
(Entity
(Nod
))
1460 and then not (Present
(Full_View
(Entity
(Nod
)))
1461 and then Has_Completion
(Full_View
(Entity
(Nod
))))
1464 ("premature use of& in call or instance", N
, Entity
(Nod
));
1466 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1467 Analyze
(Prefix
(Nod
));
1469 if Is_Entity_Name
(Prefix
(Nod
))
1470 and then Is_Type
(Entity
(Prefix
(Nod
)))
1472 if Expander_Active
then
1473 Check_Fully_Declared
(Entity
(Prefix
(Nod
)), N
);
1476 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1483 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1489 -- Start of processing for Check_Expression_Function
1492 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1494 -- The subprogram body created for the expression function is not
1495 -- itself a freeze point.
1497 if Scope
(Nam
) = Current_Scope
1498 and then Nkind
(Decl
) = N_Expression_Function
1499 and then Nkind
(N
) /= N_Subprogram_Body
1501 Check_Deferred
(Expression
(Decl
));
1503 end Check_Expression_Function
;
1505 --------------------------------
1506 -- Check_Inherited_Conditions --
1507 --------------------------------
1509 procedure Check_Inherited_Conditions
1511 Late_Overriding
: Boolean := False)
1513 Prim_Ops
: constant Elist_Id
:= Primitive_Operations
(R
);
1516 Par_Prim
: Entity_Id
;
1519 type Wrapper_Kind
is (No_Wrapper
, LSP_Wrapper
, Postcond_Wrapper
);
1521 Wrapper_Needed
: Wrapper_Kind
;
1522 -- Kind of wrapper needed by a given inherited primitive of tagged
1524 -- * No_Wrapper: No wrapper is needed.
1525 -- * LSP_Wrapper: Wrapper that handles inherited class-wide pre/post
1526 -- conditions that call overridden primitives.
1527 -- * Postcond_Wrapper: Wrapper that handles postconditions of interface
1530 function Build_DTW_Body
1533 DTW_Decls
: List_Id
;
1534 Par_Prim
: Entity_Id
;
1535 Wrapped_Subp
: Entity_Id
) return Node_Id
;
1536 -- Build the body of the dispatch table wrapper containing the given
1537 -- spec and declarations; the call to the wrapped subprogram includes
1538 -- the proper type conversion.
1540 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
;
1541 -- Build the spec of the dispatch table wrapper
1543 procedure Build_Inherited_Condition_Pragmas
1545 LSP_Wrapper_Needed
: out Boolean);
1546 -- Build corresponding pragmas for an operation whose ancestor has
1547 -- class-wide pre/postconditions. If the operation is inherited then
1548 -- Wrapper_Needed is returned True to force the creation of a wrapper
1549 -- for the inherited operation. If the ancestor is being overridden,
1550 -- the pragmas are constructed only to verify their legality, in case
1551 -- they contain calls to other primitives that may have been overridden.
1553 procedure Check_Interface_Primitives_Strub_Mode
;
1554 -- Called when R is an interface type to check strub mode compatibility
1555 -- all its primitives.
1557 function Needs_Wrapper
1558 (Class_Cond
: Node_Id
;
1560 Par_Subp
: Entity_Id
) return Boolean;
1561 -- Checks whether the dispatch-table wrapper (DTW) for Subp must be
1562 -- built to evaluate the given class-wide condition.
1564 --------------------
1565 -- Build_DTW_Body --
1566 --------------------
1568 function Build_DTW_Body
1571 DTW_Decls
: List_Id
;
1572 Par_Prim
: Entity_Id
;
1573 Wrapped_Subp
: Entity_Id
) return Node_Id
1575 Actuals
: constant List_Id
:= Empty_List
;
1577 Formal
: Entity_Id
:= First_Formal
(Par_Prim
);
1578 New_F_Spec
: Entity_Id
:= First
(Parameter_Specifications
(DTW_Spec
));
1579 New_Formal
: Entity_Id
;
1582 -- Build parameter association for call to wrapped subprogram
1584 while Present
(Formal
) loop
1585 New_Formal
:= Defining_Identifier
(New_F_Spec
);
1587 -- If the controlling argument is inherited, add conversion to
1588 -- parent type for the call.
1590 if Is_Controlling_Formal
(Formal
) then
1592 Make_Type_Conversion
(Loc
,
1593 New_Occurrence_Of
(Etype
(Formal
), Loc
),
1594 New_Occurrence_Of
(New_Formal
, Loc
)));
1596 Append_To
(Actuals
, New_Occurrence_Of
(New_Formal
, Loc
));
1599 Next_Formal
(Formal
);
1603 if Ekind
(Wrapped_Subp
) = E_Procedure
then
1605 Make_Procedure_Call_Statement
(Loc
,
1606 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1607 Parameter_Associations
=> Actuals
);
1610 Make_Simple_Return_Statement
(Loc
,
1612 Make_Function_Call
(Loc
,
1613 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1614 Parameter_Associations
=> Actuals
));
1618 Make_Subprogram_Body
(Loc
,
1619 Specification
=> Copy_Subprogram_Spec
(DTW_Spec
),
1620 Declarations
=> DTW_Decls
,
1621 Handled_Statement_Sequence
=>
1622 Make_Handled_Sequence_Of_Statements
(Loc
,
1623 Statements
=> New_List
(Call
),
1624 End_Label
=> Make_Identifier
(Loc
,
1625 Chars
(Defining_Entity
(DTW_Spec
)))));
1628 --------------------
1629 -- Build_DTW_Spec --
1630 --------------------
1632 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
is
1637 DTW_Spec
:= Build_Overriding_Spec
(Par_Prim
, R
);
1638 DTW_Id
:= Defining_Entity
(DTW_Spec
);
1640 -- Clear the not-overriding indicator since the DTW wrapper overrides
1641 -- its wrapped subprogram; required because if present in the parent
1642 -- primitive, given that Build_Overriding_Spec inherits it, we report
1645 Set_Must_Not_Override
(DTW_Spec
, False);
1647 -- Add minimal decoration of fields
1649 Mutate_Ekind
(DTW_Id
, Ekind
(Par_Prim
));
1650 Set_Is_Dispatch_Table_Wrapper
(DTW_Id
);
1651 Set_Is_Wrapper
(DTW_Id
);
1653 -- The DTW wrapper is never a null procedure
1655 if Nkind
(DTW_Spec
) = N_Procedure_Specification
then
1656 Set_Null_Present
(DTW_Spec
, False);
1662 ---------------------------------------
1663 -- Build_Inherited_Condition_Pragmas --
1664 ---------------------------------------
1666 procedure Build_Inherited_Condition_Pragmas
1668 LSP_Wrapper_Needed
: out Boolean)
1670 Class_Pre
: constant Node_Id
:=
1671 Class_Preconditions
(Ultimate_Alias
(Subp
));
1672 Class_Post
: Node_Id
:= Class_Postconditions
(Par_Prim
);
1677 LSP_Wrapper_Needed
:= False;
1679 if No
(Class_Pre
) and then No
(Class_Post
) then
1683 -- For class-wide preconditions we just evaluate whether the wrapper
1684 -- is needed; there is no need to build the pragma since the check
1685 -- is performed on the caller side.
1687 if Present
(Class_Pre
)
1688 and then Needs_Wrapper
(Class_Pre
, Subp
, Par_Prim
)
1690 LSP_Wrapper_Needed
:= True;
1693 -- For class-wide postconditions we evaluate whether the wrapper is
1694 -- needed and we build the class-wide postcondition pragma to install
1695 -- it in the wrapper.
1697 if Present
(Class_Post
)
1698 and then Needs_Wrapper
(Class_Post
, Subp
, Par_Prim
)
1700 LSP_Wrapper_Needed
:= True;
1702 -- Update the class-wide postcondition
1704 Class_Post
:= New_Copy_Tree
(Class_Post
);
1705 Build_Class_Wide_Expression
1706 (Pragma_Or_Expr
=> Class_Post
,
1708 Par_Subp
=> Par_Prim
,
1709 Adjust_Sloc
=> False);
1711 -- Install the updated class-wide postcondition in a copy of the
1712 -- pragma postcondition defined for the nearest ancestor.
1714 A_Post
:= Get_Class_Wide_Pragma
(Par_Prim
,
1715 Pragma_Postcondition
);
1719 Subps
: constant Subprogram_List
:=
1720 Inherited_Subprograms
(Subp
);
1722 for Index
in Subps
'Range loop
1723 A_Post
:= Get_Class_Wide_Pragma
(Subps
(Index
),
1724 Pragma_Postcondition
);
1725 exit when Present
(A_Post
);
1730 -- A_Post can be null here if the postcondition was inlined in the
1731 -- called subprogram.
1733 if Present
(A_Post
) then
1734 New_Prag
:= New_Copy_Tree
(A_Post
);
1736 (Expression
(First
(Pragma_Argument_Associations
(New_Prag
))),
1738 Append
(New_Prag
, Decls
);
1741 end Build_Inherited_Condition_Pragmas
;
1743 -------------------------------------------
1744 -- Check_Interface_Primitives_Strub_Mode --
1745 -------------------------------------------
1747 procedure Check_Interface_Primitives_Strub_Mode
is
1749 Iface_Elmt
: Elmt_Id
;
1751 Iface_Prim
: Entity_Id
;
1752 Ifaces_List
: Elist_Id
;
1755 Prim_Iface
: Entity_Id
;
1758 pragma Assert
(Is_Interface
(R
));
1760 -- Collect interfaces extended by interface type R
1762 Collect_Interfaces
(R
, Ifaces_List
);
1764 Op_Node
:= First_Elmt
(Prim_Ops
);
1765 while Present
(Op_Node
) loop
1766 Prim
:= Node
(Op_Node
);
1768 Par_Prim
:= Overridden_Operation
(Prim
);
1770 -- We only need to check entities defined in the sources
1772 -- Check that overrider and overridden primitives have the same
1775 if Present
(Par_Prim
) then
1776 Check_Same_Strub_Mode
(Prim
, Par_Prim
);
1778 -- No need to check internally added predefined primitives since
1779 -- they all have the same strub mode.
1781 elsif Is_Predefined_Dispatching_Operation
(Prim
)
1782 and then not Comes_From_Source
(Prim
)
1786 -- Check strub mode of matching primitives of all the interface
1787 -- types, since several interface types may define primitives with
1788 -- the same profile that will be implemented by a single primitive
1789 -- of tagged types implementing R, and therefore must have the
1793 -- If this interface primitive has been inherited this is an
1794 -- internal entity we rely on its renamed entity (which is the
1795 -- entity defined in the sources).
1797 if Present
(Alias
(Prim
)) then
1798 Prim
:= Ultimate_Alias
(Prim
);
1799 Prim_Iface
:= Find_Dispatching_Type
(Prim
);
1802 -- Search for primitives conformant with this one in the other
1805 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1806 while Present
(Iface_Elmt
) loop
1807 Iface
:= Node
(Iface_Elmt
);
1809 if Iface
/= Prim_Iface
then
1810 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1811 while Present
(Elmt
) loop
1812 Iface_Prim
:= Node
(Elmt
);
1814 if Chars
(Iface_Prim
) = Chars
(Prim
)
1815 and then Comes_From_Source
(Iface_Prim
)
1816 and then Is_Interface_Conformant
1817 (Prim_Iface
, Iface_Prim
, Prim
)
1819 -- Check the strub mode passing the original
1820 -- primitive (instead of its alias); required
1821 -- to report the error at the right location.
1823 Check_Same_Strub_Mode
(Node
(Op_Node
), Iface_Prim
);
1830 Next_Elmt
(Iface_Elmt
);
1834 Next_Elmt
(Op_Node
);
1836 end Check_Interface_Primitives_Strub_Mode
;
1842 function Needs_Wrapper
1843 (Class_Cond
: Node_Id
;
1845 Par_Subp
: Entity_Id
) return Boolean
1847 Result
: Boolean := False;
1849 function Check_Entity
(N
: Node_Id
) return Traverse_Result
;
1850 -- Check calls to overridden primitives
1852 --------------------
1853 -- Replace_Entity --
1854 --------------------
1856 function Check_Entity
(N
: Node_Id
) return Traverse_Result
is
1860 if Nkind
(N
) = N_Identifier
1861 and then Present
(Entity
(N
))
1863 (Is_Formal
(Entity
(N
)) or else Is_Subprogram
(Entity
(N
)))
1865 (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1866 or else Attribute_Name
(Parent
(N
)) /= Name_Class
)
1868 -- Determine whether entity has a renaming
1870 New_E
:= Get_Mapped_Entity
(Entity
(N
));
1872 -- If the entity is an overridden primitive and we are not
1873 -- in GNATprove mode, we must build a wrapper for the current
1874 -- inherited operation. If the reference is the prefix of an
1875 -- attribute such as 'Result (or others ???) there is no need
1876 -- for a wrapper: the condition is just rewritten in terms of
1877 -- the inherited subprogram.
1880 and then Comes_From_Source
(New_E
)
1881 and then Is_Subprogram
(New_E
)
1882 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
1883 and then not GNATprove_Mode
1893 procedure Check_Condition_Entities
is
1894 new Traverse_Proc
(Check_Entity
);
1896 -- Start of processing for Needs_Wrapper
1899 Update_Primitives_Mapping
(Par_Subp
, Subp
);
1901 Map_Formals
(Par_Subp
, Subp
);
1902 Check_Condition_Entities
(Class_Cond
);
1907 Wrappers_List
: Elist_Id
:= No_Elist
;
1908 -- List containing identifiers of built wrappers. Used to defer building
1909 -- and analyzing their class-wide precondition subprograms.
1911 Postcond_Candidates_List
: Elist_Id
:= No_Elist
;
1912 -- List containing inherited primitives of tagged type R that implement
1913 -- interface primitives that have postconditions.
1915 -- Start of processing for Check_Inherited_Conditions
1918 if Late_Overriding
then
1919 Op_Node
:= First_Elmt
(Prim_Ops
);
1920 while Present
(Op_Node
) loop
1921 Prim
:= Node
(Op_Node
);
1923 -- Map the overridden primitive to the overriding one
1925 if Present
(Overridden_Operation
(Prim
))
1926 and then Comes_From_Source
(Prim
)
1928 Par_Prim
:= Overridden_Operation
(Prim
);
1929 Update_Primitives_Mapping
(Par_Prim
, Prim
);
1931 -- Force discarding previous mappings of its formals
1933 Map_Formals
(Par_Prim
, Prim
, Force_Update
=> True);
1936 Next_Elmt
(Op_Node
);
1940 -- For interface types we only need to check strub mode compatibility
1941 -- of their primitives (since they don't have wrappers).
1943 if Is_Interface
(R
) then
1944 Check_Interface_Primitives_Strub_Mode
;
1948 -- Perform validity checks on the inherited conditions of overriding
1949 -- operations, for conformance with LSP, and apply SPARK-specific
1950 -- restrictions on inherited conditions.
1952 Op_Node
:= First_Elmt
(Prim_Ops
);
1953 while Present
(Op_Node
) loop
1954 Prim
:= Node
(Op_Node
);
1955 Par_Prim
:= Overridden_Operation
(Prim
);
1957 if Present
(Par_Prim
)
1958 and then Comes_From_Source
(Prim
)
1960 -- When the primitive is an LSP wrapper we climb to the parent
1961 -- primitive that has the inherited contract.
1963 if Is_Wrapper
(Par_Prim
)
1964 and then Present
(LSP_Subprogram
(Par_Prim
))
1966 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
1969 -- Check that overrider and overridden operations have
1970 -- the same strub mode.
1972 Check_Same_Strub_Mode
(Prim
, Par_Prim
);
1974 -- Analyze the contract items of the overridden operation, before
1975 -- they are rewritten as pragmas.
1977 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1979 -- In GNATprove mode this is where we can collect the inherited
1980 -- conditions, because we do not create the Check pragmas that
1981 -- normally convey the modified class-wide conditions on
1982 -- overriding operations.
1984 if GNATprove_Mode
then
1985 Collect_Inherited_Class_Wide_Conditions
(Prim
);
1988 -- Check strub mode compatibility of primitives that implement
1989 -- interface primitives.
1991 elsif Present
(Interface_Alias
(Prim
)) then
1992 Check_Same_Strub_Mode
(Alias
(Prim
), Interface_Alias
(Prim
));
1995 Next_Elmt
(Op_Node
);
1998 -- Collect inherited primitives that may need a wrapper to handle
1999 -- postconditions of interface primitives; done to improve the
2000 -- performance when checking if postcondition wrappers are needed.
2002 Op_Node
:= First_Elmt
(Prim_Ops
);
2003 while Present
(Op_Node
) loop
2004 Prim
:= Node
(Op_Node
);
2006 if Present
(Interface_Alias
(Prim
))
2007 and then not Comes_From_Source
(Alias
(Prim
))
2008 and then Present
(Class_Postconditions
(Interface_Alias
(Prim
)))
2010 if No
(Postcond_Candidates_List
) then
2011 Postcond_Candidates_List
:= New_Elmt_List
;
2014 Append_Unique_Elmt
(Alias
(Prim
), Postcond_Candidates_List
);
2017 Next_Elmt
(Op_Node
);
2020 -- Now examine the inherited operations to check whether they require
2021 -- a wrapper to handle inherited conditions that call other primitives,
2022 -- so that LSP can be verified/enforced.
2024 Op_Node
:= First_Elmt
(Prim_Ops
);
2026 while Present
(Op_Node
) loop
2027 Decls
:= Empty_List
;
2028 Prim
:= Node
(Op_Node
);
2029 Wrapper_Needed
:= No_Wrapper
;
2031 -- Skip internal entities built for mapping interface primitives
2033 if not Comes_From_Source
(Prim
)
2034 and then Present
(Alias
(Prim
))
2035 and then No
(Interface_Alias
(Prim
))
2037 Par_Prim
:= Ultimate_Alias
(Prim
);
2039 -- When the primitive is an LSP wrapper we climb to the parent
2040 -- primitive that has the inherited contract.
2042 if Is_Wrapper
(Par_Prim
)
2043 and then Present
(LSP_Subprogram
(Par_Prim
))
2045 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
2048 -- Analyze the contract items of the parent operation, and
2049 -- determine whether this inherited primitive needs a LSP
2050 -- wrapper. This is determined when the condition is rewritten
2051 -- in sem_prag, using the mapping between overridden and
2052 -- overriding operations built in the loop above.
2055 LSP_Wrapper_Needed
: Boolean;
2058 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
2059 Build_Inherited_Condition_Pragmas
(Prim
, LSP_Wrapper_Needed
);
2061 if LSP_Wrapper_Needed
then
2062 Wrapper_Needed
:= LSP_Wrapper
;
2066 -- If the LSP wrapper is not needed but the tagged type R
2067 -- implements additional interface types, and this inherited
2068 -- primitive covers an interface primitive of these additional
2069 -- interface types that has class-wide postconditions, then it
2070 -- requires a postconditions wrapper.
2072 if Wrapper_Needed
= No_Wrapper
2073 and then Present
(Interfaces
(R
))
2074 and then Present
(Postcond_Candidates_List
)
2075 and then Contains
(Postcond_Candidates_List
, Prim
)
2081 Iface_Elmt
: Elmt_Id
;
2084 Elmt
:= First_Elmt
(Prim_Ops
);
2085 while Present
(Elmt
) loop
2088 -- Perform the search relying on the internal entities
2089 -- that link tagged type primitives with interface
2092 if Present
(Interface_Alias
(Ent
))
2093 and then (Alias
(Ent
)) = Prim
2095 Present
(Class_Postconditions
(Interface_Alias
(Ent
)))
2097 Iface
:= Find_Dispatching_Type
(Interface_Alias
(Ent
));
2099 -- We only need to locate primitives of additional
2100 -- interfaces implemented by tagged type R (since
2101 -- inherited primitives of parent types that cover
2102 -- primitives of inherited interface types don't
2105 Iface_Elmt
:= First_Elmt
(Interfaces
(R
));
2106 while Present
(Iface_Elmt
) loop
2107 if Node
(Iface_Elmt
) = Iface
then
2108 Wrapper_Needed
:= Postcond_Wrapper
;
2112 Next_Elmt
(Iface_Elmt
);
2122 if Wrapper_Needed
/= No_Wrapper
2123 and then not Is_Abstract_Subprogram
(Par_Prim
)
2124 and then Expander_Active
2126 -- Build the dispatch-table wrapper (DTW). The support for
2127 -- AI12-0195 relies on two kind of wrappers: one for indirect
2128 -- calls (also used for AI12-0220), and one for putting in the
2131 -- 1) "indirect-call wrapper" (ICW) is needed anytime there are
2132 -- class-wide preconditions. Prim'Access will point directly
2133 -- at the ICW if any, or at the "pristine" body if Prim has
2134 -- no class-wide preconditions.
2136 -- 2) "dispatch-table wrapper" (DTW) is needed anytime the class
2137 -- wide preconditions *or* the class-wide postconditions are
2138 -- affected by overriding.
2140 -- The DTW holds a single statement that is a single call where
2141 -- the controlling actuals are conversions to the corresponding
2142 -- type in the parent primitive. If the primitive is a function
2143 -- the statement is a return statement with a call.
2146 Alias_Id
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
2147 Loc
: constant Source_Ptr
:= Sloc
(R
);
2153 Prim_Next_E
: constant Entity_Id
:= Next_Entity
(Prim
);
2154 Prim_Prev_E
: constant Entity_Id
:= Prev_Entity
(Prim
);
2157 DTW_Spec
:= Build_DTW_Spec
(Par_Prim
);
2158 DTW_Id
:= Defining_Entity
(DTW_Spec
);
2159 DTW_Decl
:= Make_Subprogram_Declaration
(Loc
,
2160 Specification
=> DTW_Spec
);
2162 -- LSP wrappers reference the parent primitive that has the
2163 -- the class-wide pre/post condition that calls overridden
2166 if Wrapper_Needed
= LSP_Wrapper
then
2167 Set_LSP_Subprogram
(DTW_Id
, Par_Prim
);
2170 -- The spec of the wrapper has been built using the source
2171 -- location of its parent primitive; we must update it now
2172 -- (with the source location of the internal primitive built
2173 -- by Derive_Subprogram that will override this wrapper) to
2174 -- avoid inlining conflicts between internally built helpers
2175 -- for class-wide pre/postconditions of the parent and the
2176 -- helpers built for this wrapper.
2178 Set_Sloc
(DTW_Id
, Sloc
(Prim
));
2180 -- For inherited class-wide preconditions the DTW wrapper
2181 -- reuses the ICW of the parent (which checks the parent
2182 -- interpretation of the class-wide preconditions); the
2183 -- interpretation of the class-wide preconditions for the
2184 -- inherited subprogram is checked at the caller side.
2186 -- When the subprogram inherits class-wide postconditions
2187 -- the DTW also checks the interpretation of the class-wide
2188 -- postconditions for the inherited subprogram, and the body
2189 -- of the parent checks its interpretation of the parent for
2190 -- the class-wide postconditions.
2192 -- procedure Prim (F1 : T1; ...) is
2193 -- [ pragma Check (Postcondition, Expr); ]
2195 -- Par_Prim_ICW (Par_Type (F1), ...);
2198 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2200 Build_DTW_Body
(Loc
,
2201 DTW_Spec
=> DTW_Spec
,
2203 Par_Prim
=> Par_Prim
,
2204 Wrapped_Subp
=> Indirect_Call_Wrapper
(Par_Prim
));
2206 -- For subprograms that only inherit class-wide postconditions
2207 -- the DTW wrapper calls the parent primitive (which on its
2208 -- body checks the interpretation of the class-wide post-
2209 -- conditions for the parent subprogram), and the DTW checks
2210 -- the interpretation of the class-wide postconditions for the
2211 -- inherited subprogram.
2213 -- procedure Prim (F1 : T1; ...) is
2214 -- pragma Check (Postcondition, Expr);
2216 -- Par_Prim (Par_Type (F1), ...);
2221 Build_DTW_Body
(Loc
,
2222 DTW_Spec
=> DTW_Spec
,
2224 Par_Prim
=> Par_Prim
,
2225 Wrapped_Subp
=> Par_Prim
);
2228 -- Insert the declaration of the wrapper before the freezing
2229 -- node of the record type declaration to ensure that it will
2230 -- override the internal primitive built by Derive_Subprogram.
2232 if Late_Overriding
then
2233 Ensure_Freeze_Node
(R
);
2234 Insert_Before_And_Analyze
(Freeze_Node
(R
), DTW_Decl
);
2236 Append_Freeze_Action
(R
, DTW_Decl
);
2240 -- The analyis of DTW_Decl has removed Prim from its scope
2241 -- chain and added DTW_Id at the end of the scope chain. Move
2242 -- DTW_Id to its correct place in the scope chain: the analysis
2243 -- of the wrapper declaration has just added DTW_Id at the end
2244 -- of the list of entities of its scope. However, given that
2245 -- this wrapper overrides Prim, we must move DTW_Id to the
2246 -- original place of Prim in its scope chain. This is required
2247 -- for wrappers of private type primitives to ensure their
2248 -- correct visibility since wrappers are built when the full
2249 -- tagged type declaration is frozen (in the private part of
2250 -- the package) but they may override primitives defined in the
2251 -- public part of the package.
2254 DTW_Prev_E
: constant Entity_Id
:= Prev_Entity
(DTW_Id
);
2257 pragma Assert
(Last_Entity
(Current_Scope
) = DTW_Id
);
2259 (Ekind
(Current_Scope
) not in E_Package | E_Generic_Package
2260 or else No
(First_Private_Entity
(Current_Scope
))
2261 or else First_Private_Entity
(Current_Scope
) /= DTW_Id
);
2263 -- Remove DTW_Id from the end of the doubly-linked list of
2264 -- entities of this scope; no need to handle removing it
2265 -- from the beginning of the chain since such case can never
2266 -- occur for this entity.
2268 Set_Last_Entity
(Current_Scope
, DTW_Prev_E
);
2269 Set_Next_Entity
(DTW_Prev_E
, Empty
);
2271 -- Place DTW_Id back in the original place of its wrapped
2272 -- primitive in the list of entities of this scope.
2274 Link_Entities
(Prim_Prev_E
, DTW_Id
);
2275 Link_Entities
(DTW_Id
, Prim_Next_E
);
2278 -- Insert the body of the wrapper in the freeze actions of
2279 -- its record type declaration to ensure that it is placed
2280 -- in the scope of its declaration but not too early to cause
2281 -- premature freezing of other entities.
2283 Append_Freeze_Action
(R
, DTW_Body
);
2286 -- Ensure correct decoration
2288 pragma Assert
(Is_Dispatching_Operation
(DTW_Id
));
2289 pragma Assert
(Present
(Overridden_Operation
(DTW_Id
)));
2290 pragma Assert
(Overridden_Operation
(DTW_Id
) = Alias_Id
);
2292 -- Inherit dispatch table slot
2294 Set_DTC_Entity_Value
(R
, DTW_Id
);
2295 Set_DT_Position
(DTW_Id
, DT_Position
(Alias_Id
));
2297 -- Register the wrapper in the dispatch table
2300 and then not Building_Static_DT
(R
)
2302 Insert_List_After_And_Analyze
(Freeze_Node
(R
),
2303 Register_Primitive
(Loc
, DTW_Id
));
2306 -- Defer building helpers and ICW for the DTW. Required to
2307 -- ensure uniqueness in their names because when building
2308 -- these wrappers for overlapped subprograms their homonym
2309 -- number is not definite until all these dispatch table
2310 -- wrappers of tagged type R have been analyzed.
2312 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2313 Append_New_Elmt
(DTW_Id
, Wrappers_List
);
2318 Next_Elmt
(Op_Node
);
2321 -- Build and analyze deferred class-wide precondition subprograms of
2324 if Present
(Wrappers_List
) then
2327 CW_Subp
: Entity_Id
;
2333 Elmt
:= First_Elmt
(Wrappers_List
);
2335 while Present
(Elmt
) loop
2336 DTW_Id
:= Node
(Elmt
);
2339 Merge_Class_Conditions
(DTW_Id
);
2340 Make_Class_Precondition_Subps
(DTW_Id
, Late_Overriding
);
2342 CW_Subp
:= Static_Call_Helper
(DTW_Id
);
2343 Decl_N
:= Unit_Declaration_Node
(CW_Subp
);
2346 -- If the DTW was built for a late-overriding primitive
2347 -- its body must be analyzed now (since the tagged type
2348 -- is already frozen).
2350 if Late_Overriding
then
2352 Unit_Declaration_Node
(Corresponding_Body
(Decl_N
));
2358 end Check_Inherited_Conditions
;
2360 ----------------------------
2361 -- Check_Strict_Alignment --
2362 ----------------------------
2364 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
2368 -- Bit-packed array types do not require strict alignment, even if they
2369 -- are by-reference types, because they are accessed in a special way.
2371 if Is_By_Reference_Type
(E
) and then not Is_Bit_Packed_Array
(E
) then
2372 Set_Strict_Alignment
(E
);
2374 elsif Is_Array_Type
(E
) then
2375 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
2377 -- RM 13.2(7.1/4): Any component of a packed type that contains an
2378 -- aliased part shall be aligned according to the alignment of its
2381 -- Unfortunately this breaks Florist, which has had the bad habit
2382 -- of overaligning all the types it declares on 32-bit platforms,
2383 -- so make an exception if the component size is the storage unit.
2385 -- Other legacy codebases could also be affected because this was
2386 -- historically not enforced, so -gnatd_l can be used to disable it.
2388 if Has_Aliased_Components
(E
)
2389 and then not (Known_Component_Size
(E
)
2390 and then Component_Size
(E
) = System_Storage_Unit
)
2391 and then not Debug_Flag_Underscore_L
2393 Set_Strict_Alignment
(E
);
2396 elsif Is_Record_Type
(E
) then
2397 Comp
:= First_Component
(E
);
2398 while Present
(Comp
) loop
2399 if not Is_Type
(Comp
)
2400 and then (Is_Aliased
(Comp
)
2401 or else Strict_Alignment
(Etype
(Comp
)))
2403 Set_Strict_Alignment
(E
);
2407 Next_Component
(Comp
);
2410 end Check_Strict_Alignment
;
2412 -------------------------
2413 -- Check_Unsigned_Type --
2414 -------------------------
2416 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
2417 Ancestor
: Entity_Id
;
2422 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
2426 -- Do not attempt to analyze case where range was in error
2428 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
2432 -- The situation that is nontrivial is something like:
2434 -- subtype x1 is integer range -10 .. +10;
2435 -- subtype x2 is x1 range 0 .. V1;
2436 -- subtype x3 is x2 range V2 .. V3;
2437 -- subtype x4 is x3 range V4 .. V5;
2439 -- where Vn are variables. Here the base type is signed, but we still
2440 -- know that x4 is unsigned because of the lower bound of x2.
2442 -- The only way to deal with this is to look up the ancestor chain
2446 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
2450 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
2452 if Compile_Time_Known_Value
(Lo_Bound
) then
2453 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
2454 Set_Is_Unsigned_Type
(E
, True);
2460 Ancestor
:= Ancestor_Subtype
(Ancestor
);
2462 -- If no ancestor had a static lower bound, go to base type
2464 if No
(Ancestor
) then
2466 -- Note: the reason we still check for a compile time known
2467 -- value for the base type is that at least in the case of
2468 -- generic formals, we can have bounds that fail this test,
2469 -- and there may be other cases in error situations.
2471 Btyp
:= Base_Type
(E
);
2473 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
2477 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
2479 if Compile_Time_Known_Value
(Lo_Bound
)
2480 and then Expr_Rep_Value
(Lo_Bound
) >= 0
2482 Set_Is_Unsigned_Type
(E
, True);
2489 end Check_Unsigned_Type
;
2491 -----------------------------------------------
2492 -- Explode_Initialization_Compound_Statement --
2493 -----------------------------------------------
2495 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
2496 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
2499 if Present
(Init_Stmts
)
2500 and then Nkind
(Init_Stmts
) = N_Compound_Statement
2502 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
2504 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
2505 -- just removing it, because Freeze_All may rely on this particular
2506 -- Node_Id still being present in the enclosing list to know where to
2509 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
2511 Set_Initialization_Statements
(E
, Empty
);
2513 end Explode_Initialization_Compound_Statement
;
2519 -- Note: the easy coding for this procedure would be to just build a
2520 -- single list of freeze nodes and then insert them and analyze them
2521 -- all at once. This won't work, because the analysis of earlier freeze
2522 -- nodes may recursively freeze types which would otherwise appear later
2523 -- on in the freeze list. So we must analyze and expand the freeze nodes
2524 -- as they are generated.
2526 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
2527 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
2528 -- This is the internal recursive routine that does freezing of entities
2529 -- (but NOT the analysis of default expressions, which should not be
2530 -- recursive, we don't want to analyze those till we are sure that ALL
2531 -- the types are frozen).
2533 --------------------
2534 -- Freeze_All_Ent --
2535 --------------------
2537 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
2541 procedure Process_Flist
;
2542 -- If freeze nodes are present, insert and analyze, and reset cursor
2543 -- for next insertion.
2549 procedure Process_Flist
is
2552 if Is_Non_Empty_List
(Flist
) then
2553 Lastn
:= Next
(After
);
2554 Insert_List_After_And_Analyze
(After
, Flist
);
2556 if Present
(Lastn
) then
2557 After
:= Prev
(Lastn
);
2559 After
:= Last
(List_Containing
(After
));
2564 -- Start of processing for Freeze_All_Ent
2568 while Present
(E
) loop
2570 -- If the entity is an inner package which is not a package
2571 -- renaming, then its entities must be frozen at this point. Note
2572 -- that such entities do NOT get frozen at the end of the nested
2573 -- package itself (only library packages freeze).
2575 -- Same is true for task declarations, where anonymous records
2576 -- created for entry parameters must be frozen.
2578 if Ekind
(E
) = E_Package
2579 and then No
(Renamed_Entity
(E
))
2580 and then not Is_Child_Unit
(E
)
2581 and then not Is_Frozen
(E
)
2585 Install_Visible_Declarations
(E
);
2586 Install_Private_Declarations
(E
);
2587 Freeze_All
(First_Entity
(E
), After
);
2589 End_Package_Scope
(E
);
2591 if Is_Generic_Instance
(E
)
2592 and then Has_Delayed_Freeze
(E
)
2594 Set_Has_Delayed_Freeze
(E
, False);
2595 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
2598 elsif Ekind
(E
) in Task_Kind
2599 and then Nkind
(Parent
(E
)) in
2600 N_Single_Task_Declaration | N_Task_Type_Declaration
2603 Freeze_All
(First_Entity
(E
), After
);
2606 -- For a derived tagged type, we must ensure that all the
2607 -- primitive operations of the parent have been frozen, so that
2608 -- their addresses will be in the parent's dispatch table at the
2609 -- point it is inherited.
2611 elsif Ekind
(E
) = E_Record_Type
2612 and then Is_Tagged_Type
(E
)
2613 and then Is_Tagged_Type
(Etype
(E
))
2614 and then Is_Derived_Type
(E
)
2617 Prim_List
: constant Elist_Id
:=
2618 Primitive_Operations
(Etype
(E
));
2624 Prim
:= First_Elmt
(Prim_List
);
2625 while Present
(Prim
) loop
2626 Subp
:= Node
(Prim
);
2628 if Comes_From_Source
(Subp
)
2629 and then not Is_Frozen
(Subp
)
2631 Flist
:= Freeze_Entity
(Subp
, After
);
2640 if not Is_Frozen
(E
) then
2641 Flist
:= Freeze_Entity
(E
, After
);
2644 -- If already frozen, and there are delayed aspects, this is where
2645 -- we do the visibility check for these aspects (see Sem_Ch13 spec
2646 -- for a description of how we handle aspect visibility).
2648 elsif Has_Delayed_Aspects
(E
) then
2649 Check_Aspects_At_End_Of_Declarations
(E
);
2652 -- If an incomplete type is still not frozen, this may be a
2653 -- premature freezing because of a body declaration that follows.
2654 -- Indicate where the freezing took place. Freezing will happen
2655 -- if the body comes from source, but not if it is internally
2656 -- generated, for example as the body of a type invariant.
2658 -- If the freezing is caused by the end of the current declarative
2659 -- part, it is a Taft Amendment type, and there is no error.
2661 if not Is_Frozen
(E
)
2662 and then Ekind
(E
) = E_Incomplete_Type
2665 Bod
: constant Node_Id
:= Next
(After
);
2668 -- The presence of a body freezes all entities previously
2669 -- declared in the current list of declarations, but this
2670 -- does not apply if the body does not come from source.
2671 -- A type invariant is transformed into a subprogram body
2672 -- which is placed at the end of the private part of the
2673 -- current package, but this body does not freeze incomplete
2674 -- types that may be declared in this private part.
2676 if Comes_From_Source
(Bod
)
2677 and then Nkind
(Bod
) in N_Entry_Body
2684 In_Same_List
(After
, Parent
(E
))
2686 Error_Msg_Sloc
:= Sloc
(Next
(After
));
2688 ("type& is frozen# before its full declaration",
2704 -- Start of processing for Freeze_All
2707 Freeze_All_Ent
(From
, After
);
2709 -- Now that all types are frozen, we can deal with default expressions
2710 -- that require us to build a default expression functions. This is the
2711 -- point at which such functions are constructed (after all types that
2712 -- might be used in such expressions have been frozen).
2714 -- For subprograms that are renaming_as_body, we create the wrapper
2715 -- bodies as needed.
2717 -- We also add finalization chains to access types whose designated
2718 -- types are controlled. This is normally done when freezing the type,
2719 -- but this misses recursive type definitions where the later members
2720 -- of the recursion introduce controlled components.
2722 -- Loop through entities
2725 while Present
(E
) loop
2726 if Is_Subprogram
(E
) then
2727 if not Default_Expressions_Processed
(E
) then
2728 Process_Default_Expressions
(E
, After
);
2731 -- Check subprogram renamings for the same strub-mode.
2732 -- Avoid rechecking dispatching operations, that's taken
2733 -- care of in Check_Inherited_Conditions, that covers
2734 -- inherited interface operations.
2738 and then not Is_Dispatching_Operation
(E
)
2740 Check_Same_Strub_Mode
(E
, Item
);
2743 if not Has_Completion
(E
) then
2744 Decl
:= Unit_Declaration_Node
(E
);
2746 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
2747 if Error_Posted
(Decl
) then
2748 Set_Has_Completion
(E
);
2750 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
2753 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2754 and then Present
(Corresponding_Body
(Decl
))
2756 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
2757 N_Subprogram_Renaming_Declaration
2759 Build_And_Analyze_Renamed_Body
2760 (Decl
, Corresponding_Body
(Decl
), After
);
2764 -- Freeze the default expressions of entries, entry families, and
2765 -- protected subprograms.
2767 elsif Is_Concurrent_Type
(E
) then
2768 Item
:= First_Entity
(E
);
2769 while Present
(Item
) loop
2770 if Is_Subprogram_Or_Entry
(Item
)
2771 and then not Default_Expressions_Processed
(Item
)
2773 Process_Default_Expressions
(Item
, After
);
2780 -- Historical note: We used to create a finalization collection for
2781 -- access types whose designated type is not controlled, but contains
2782 -- private controlled compoments. This form of postprocessing is no
2783 -- longer needed because the finalization collection is now created
2784 -- when the access type is frozen (see Exp_Ch3.Freeze_Type).
2790 -----------------------
2791 -- Freeze_And_Append --
2792 -----------------------
2794 procedure Freeze_And_Append
2797 Result
: in out List_Id
)
2799 -- Freezing an Expression_Function does not freeze its profile:
2800 -- the formals will have been frozen otherwise before the E_F
2803 L
: constant List_Id
:=
2805 (Ent
, N
, Do_Freeze_Profile
=> not Is_Expression_Function
(Ent
));
2807 if Is_Non_Empty_List
(L
) then
2808 if Result
= No_List
then
2811 Append_List
(L
, Result
);
2814 end Freeze_And_Append
;
2820 procedure Freeze_Before
2823 Do_Freeze_Profile
: Boolean := True)
2825 -- Freeze T, then insert the generated Freeze nodes before the node N.
2826 -- Flag Freeze_Profile is used when T is an overloadable entity, and
2827 -- indicates whether its profile should be frozen at the same time.
2829 Freeze_Nodes
: constant List_Id
:=
2830 Freeze_Entity
(T
, N
, Do_Freeze_Profile
);
2831 Pack
: constant Entity_Id
:= Scope
(T
);
2834 if Ekind
(T
) = E_Function
then
2835 Check_Expression_Function
(N
, T
);
2838 if Is_Non_Empty_List
(Freeze_Nodes
) then
2840 -- If the entity is a type declared in an inner package, it may be
2841 -- frozen by an outer declaration before the package itself is
2842 -- frozen. Install the package scope to analyze the freeze nodes,
2843 -- which may include generated subprograms such as predicate
2846 if Is_Type
(T
) and then From_Nested_Package
(T
) then
2848 Install_Visible_Declarations
(Pack
);
2849 Install_Private_Declarations
(Pack
);
2850 Insert_Actions
(N
, Freeze_Nodes
);
2851 End_Package_Scope
(Pack
);
2854 Insert_Actions
(N
, Freeze_Nodes
);
2863 -- WARNING: This routine manages Ghost regions. Return statements must be
2864 -- replaced by gotos which jump to the end of the routine and restore the
2867 function Freeze_Entity
2870 Do_Freeze_Profile
: Boolean := True) return List_Id
2872 Loc
: constant Source_Ptr
:= Sloc
(N
);
2874 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2875 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
2876 -- Save the Ghost-related attributes to restore on exit
2884 Result
: List_Id
:= No_List
;
2885 -- List of freezing actions, left at No_List if none
2887 Test_E
: Entity_Id
:= E
;
2888 -- A local temporary used to test if freezing is necessary for E, since
2889 -- its value can be set to something other than E in certain cases. For
2890 -- example, E cannot be used directly in cases such as when it is an
2891 -- Itype defined within a record - since it is the location of record
2894 procedure Add_To_Result
(Fnod
: Node_Id
);
2895 -- Add freeze action Fnod to list Result
2897 function After_Last_Declaration
return Boolean;
2898 -- If Loc is a freeze_entity that appears after the last declaration
2899 -- in the scope, inhibit error messages on late completion.
2901 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
2902 -- Check that an Access or Unchecked_Access attribute with a prefix
2903 -- which is the current instance type can only be applied when the type
2906 procedure Check_No_Parts_Violations
2907 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
) with
2908 Pre
=> Aspect_No_Parts
in
2909 Aspect_No_Controlled_Parts | Aspect_No_Task_Parts
;
2910 -- Check that Typ does not violate the semantics of the specified
2911 -- Aspect_No_Parts (No_Controlled_Parts or No_Task_Parts) when it is
2912 -- specified on Typ or one of its ancestors.
2914 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
);
2915 -- Give a warning for pragma Convention with language C or C++ applied
2916 -- to a discriminated record type. This is suppressed for the unchecked
2917 -- union case, since the whole point in this case is interface C. We
2918 -- also do not generate this within instantiations, since we will have
2919 -- generated a message on the template.
2921 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
2922 -- Give warning for modulus of 8, 16, 32, 64 or 128 given as an explicit
2923 -- integer literal without an explicit corresponding size clause. The
2924 -- caller has checked that Utype is a modular integer type.
2926 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
2927 -- Freeze array type, including freezing index and component types
2929 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
2930 -- Perform checks and generate freeze node if needed for a constant or
2931 -- variable declared by an object declaration.
2933 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
2934 -- Create Freeze_Generic_Entity nodes for types declared in a generic
2935 -- package. Recurse on inner generic packages.
2937 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
2938 -- Freeze formals and return type of subprogram. If some type in the
2939 -- profile is incomplete and we are in an instance, freezing of the
2940 -- entity will take place elsewhere, and the function returns False.
2942 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
2943 -- Freeze record type, including freezing component types, and freezing
2944 -- primitive operations if this is a tagged type.
2946 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
2947 -- Determine whether an arbitrary entity is subject to Boolean aspect
2948 -- Import and its value is specified as True.
2950 procedure Inherit_Freeze_Node
2953 -- Set type Typ's freeze node to refer to Fnode. This routine ensures
2954 -- that any attributes attached to Typ's original node are preserved.
2956 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
2957 -- If E is an entity for an imported subprogram with pre/post-conditions
2958 -- then this procedure will create a wrapper to ensure that proper run-
2959 -- time checking of the pre/postconditions. See body for details.
2965 procedure Add_To_Result
(Fnod
: Node_Id
) is
2967 Append_New_To
(Result
, Fnod
);
2970 ----------------------------
2971 -- After_Last_Declaration --
2972 ----------------------------
2974 function After_Last_Declaration
return Boolean is
2975 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2978 if Nkind
(Spec
) = N_Package_Specification
then
2979 if Present
(Private_Declarations
(Spec
)) then
2980 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2981 elsif Present
(Visible_Declarations
(Spec
)) then
2982 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2990 end After_Last_Declaration
;
2992 ----------------------------
2993 -- Check_Current_Instance --
2994 ----------------------------
2996 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2998 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2999 -- Determine whether Typ is compatible with the rules for aliased
3000 -- views of types as defined in RM 3.10 in the various dialects.
3002 function Process
(N
: Node_Id
) return Traverse_Result
;
3003 -- Process routine to apply check to given node
3005 -----------------------------
3006 -- Is_Aliased_View_Of_Type --
3007 -----------------------------
3009 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
3010 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
3015 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
3016 and then Limited_Present
(Type_Definition
(Typ_Decl
))
3020 -- The following paragraphs describe what a legal aliased view of
3021 -- a type is in the various dialects of Ada.
3025 -- The current instance of a limited type, and a formal parameter
3026 -- or generic formal object of a tagged type.
3028 -- Ada 95 limited type
3029 -- * Type with reserved word "limited"
3030 -- * A protected or task type
3031 -- * A composite type with limited component
3033 elsif Ada_Version
<= Ada_95
then
3034 return Is_Limited_Type
(Typ
);
3038 -- The current instance of a limited tagged type, a protected
3039 -- type, a task type, or a type that has the reserved word
3040 -- "limited" in its full definition ... a formal parameter or
3041 -- generic formal object of a tagged type.
3043 -- Ada 2005 limited type
3044 -- * Type with reserved word "limited", "synchronized", "task"
3046 -- * A composite type with limited component
3047 -- * A derived type whose parent is a non-interface limited type
3049 elsif Ada_Version
= Ada_2005
then
3051 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
3053 (Is_Derived_Type
(Typ
)
3054 and then not Is_Interface
(Etype
(Typ
))
3055 and then Is_Limited_Type
(Etype
(Typ
)));
3057 -- Ada 2012 and beyond
3059 -- The current instance of an immutably limited type ... a formal
3060 -- parameter or generic formal object of a tagged type.
3062 -- Ada 2012 limited type
3063 -- * Type with reserved word "limited", "synchronized", "task"
3065 -- * A composite type with limited component
3066 -- * A derived type whose parent is a non-interface limited type
3067 -- * An incomplete view
3069 -- Ada 2012 immutably limited type
3070 -- * Explicitly limited record type
3071 -- * Record extension with "limited" present
3072 -- * Non-formal limited private type that is either tagged
3073 -- or has at least one access discriminant with a default
3075 -- * Task type, protected type or synchronized interface
3076 -- * Type derived from immutably limited type
3080 Is_Immutably_Limited_Type
(Typ
)
3081 or else Is_Incomplete_Type
(Typ
);
3083 end Is_Aliased_View_Of_Type
;
3089 function Process
(N
: Node_Id
) return Traverse_Result
is
3092 when N_Attribute_Reference
=>
3093 if Attribute_Name
(N
) in Name_Access | Name_Unchecked_Access
3094 and then Is_Entity_Name
(Prefix
(N
))
3095 and then Entity
(Prefix
(N
)) = E
3097 if Ada_Version
< Ada_2012
then
3099 ("current instance must be a limited type",
3103 ("current instance must be an immutably limited "
3104 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
3118 procedure Traverse
is new Traverse_Proc
(Process
);
3122 Rec_Type
: constant Entity_Id
:=
3123 Scope
(Defining_Identifier
(Comp_Decl
));
3125 -- Start of processing for Check_Current_Instance
3128 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
3129 Traverse
(Comp_Decl
);
3131 end Check_Current_Instance
;
3133 -------------------------------
3134 -- Check_No_Parts_Violations --
3135 -------------------------------
3137 procedure Check_No_Parts_Violations
3138 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
)
3141 function Find_Aspect_No_Parts
3142 (Typ
: Entity_Id
) return Node_Id
;
3143 -- Search for Aspect_No_Parts on a given type. When
3144 -- the aspect is not explicity specified Empty is returned.
3146 function Get_Aspect_No_Parts_Value
3147 (Typ
: Entity_Id
) return Entity_Id
;
3148 -- Obtain the value for the Aspect_No_Parts on a given
3149 -- type. When the aspect is not explicitly specified Empty is
3152 function Has_Aspect_No_Parts
3153 (Typ
: Entity_Id
) return Boolean;
3154 -- Predicate function which identifies whether No_Parts
3155 -- is explicitly specified on a given type.
3157 -------------------------------------
3158 -- Find_Aspect_No_Parts --
3159 -------------------------------------
3161 function Find_Aspect_No_Parts
3162 (Typ
: Entity_Id
) return Node_Id
3164 Partial_View
: constant Entity_Id
:=
3165 Incomplete_Or_Partial_View
(Typ
);
3167 Aspect_Spec
: Entity_Id
:=
3168 Find_Aspect
(Typ
, Aspect_No_Parts
);
3169 Curr_Aspect_Spec
: Entity_Id
;
3172 -- Examine Typ's associated node, when present, since aspect
3173 -- specifications do not get transferred when nodes get rewritten.
3175 -- For example, this can happen in the expansion of array types
3178 and then Present
(Associated_Node_For_Itype
(Typ
))
3179 and then Nkind
(Associated_Node_For_Itype
(Typ
))
3180 = N_Full_Type_Declaration
3184 (Id
=> Defining_Identifier
3185 (Associated_Node_For_Itype
(Typ
)),
3186 A
=> Aspect_No_Parts
);
3189 -- Examine aspects specifications on private type declarations
3191 -- Should Find_Aspect be improved to handle this case ???
3194 and then Present
(Partial_View
)
3196 (Aspect_Specifications
3202 (Aspect_Specifications
3206 -- Search through aspects present on the private type
3208 while Present
(Curr_Aspect_Spec
) loop
3209 if Get_Aspect_Id
(Curr_Aspect_Spec
) = Aspect_No_Parts
then
3210 Aspect_Spec
:= Curr_Aspect_Spec
;
3214 Next
(Curr_Aspect_Spec
);
3219 -- When errors are posted on the aspect return Empty
3221 if Error_Posted
(Aspect_Spec
) then
3226 end Find_Aspect_No_Parts
;
3228 ------------------------------------------
3229 -- Get_Aspect_No_Parts_Value --
3230 ------------------------------------------
3232 function Get_Aspect_No_Parts_Value
3233 (Typ
: Entity_Id
) return Entity_Id
3235 Aspect_Spec
: constant Entity_Id
:=
3236 Find_Aspect_No_Parts
(Typ
);
3239 -- Return the value of the aspect when present
3241 if Present
(Aspect_Spec
) then
3243 -- No expression is the same as True
3245 if No
(Expression
(Aspect_Spec
)) then
3246 return Standard_True
;
3249 -- Assume its expression has already been constant folded into
3250 -- a Boolean value and return its value.
3252 return Entity
(Expression
(Aspect_Spec
));
3255 -- Otherwise, the aspect is not specified - so return Empty
3258 end Get_Aspect_No_Parts_Value
;
3260 ------------------------------------
3261 -- Has_Aspect_No_Parts --
3262 ------------------------------------
3264 function Has_Aspect_No_Parts
3265 (Typ
: Entity_Id
) return Boolean
3266 is (Present
(Find_Aspect_No_Parts
(Typ
)));
3268 -- Generic instances
3270 -------------------------------------------
3271 -- Get_Generic_Formal_Types_In_Hierarchy --
3272 -------------------------------------------
3274 function Get_Generic_Formal_Types_In_Hierarchy
3275 is new Collect_Types_In_Hierarchy
(Predicate
=> Is_Generic_Formal
);
3276 -- Return a list of all types within a given type's hierarchy which
3277 -- are generic formals.
3279 ----------------------------------------
3280 -- Get_Types_With_Aspect_In_Hierarchy --
3281 ----------------------------------------
3283 function Get_Types_With_Aspect_In_Hierarchy
3284 is new Collect_Types_In_Hierarchy
3285 (Predicate
=> Has_Aspect_No_Parts
);
3286 -- Returns a list of all types within a given type's hierarchy which
3287 -- have the Aspect_No_Parts specified.
3289 -- Local declarations
3291 Aspect_Value
: Entity_Id
;
3292 Curr_Value
: Entity_Id
;
3293 Curr_Typ_Elmt
: Elmt_Id
;
3294 Curr_Body_Elmt
: Elmt_Id
;
3295 Curr_Formal_Elmt
: Elmt_Id
;
3296 Gen_Bodies
: Elist_Id
;
3297 Gen_Formals
: Elist_Id
;
3299 Types_With_Aspect
: Elist_Id
;
3301 -- Start of processing for Check_No_Parts_Violations
3304 -- Nothing to check if the type is elementary or artificial
3306 if Is_Elementary_Type
(Typ
) or else not Comes_From_Source
(Typ
) then
3310 Types_With_Aspect
:= Get_Types_With_Aspect_In_Hierarchy
(Typ
);
3312 -- Nothing to check if there are no types with No_Parts specified
3314 if Is_Empty_Elmt_List
(Types_With_Aspect
) then
3318 -- Set name for all errors below
3320 Error_Msg_Name_1
:= Aspect_Names
(Aspect_No_Parts
);
3322 -- Obtain the aspect value for No_Parts for comparison
3325 Get_Aspect_No_Parts_Value
3326 (Node
(First_Elmt
(Types_With_Aspect
)));
3328 -- When the value is True and there are controlled/task parts or the
3329 -- type itself is controlled/task, trigger the appropriate error.
3331 if Aspect_Value
= Standard_True
then
3332 if Aspect_No_Parts
= Aspect_No_Controlled_Parts
then
3333 if Is_Controlled
(Typ
) or else Has_Controlled_Component
(Typ
)
3336 ("aspect % applied to controlled type &", Typ
);
3339 elsif Aspect_No_Parts
= Aspect_No_Task_Parts
then
3340 if Has_Task
(Typ
) then
3342 ("aspect % applied to task type &", Typ
);
3344 ("\replace task components with access-to-task-type "
3345 & "components??", Typ
);
3349 raise Program_Error
;
3353 -- Move through Types_With_Aspect - checking that the value specified
3354 -- for their corresponding Aspect_No_Parts do not override each
3357 Curr_Typ_Elmt
:= First_Elmt
(Types_With_Aspect
);
3358 while Present
(Curr_Typ_Elmt
) loop
3360 Get_Aspect_No_Parts_Value
(Node
(Curr_Typ_Elmt
));
3362 -- Compare the aspect value against the current type
3364 if Curr_Value
/= Aspect_Value
then
3366 ("cannot override aspect % of "
3367 & "ancestor type &", Typ
, Node
(Curr_Typ_Elmt
));
3371 Next_Elmt
(Curr_Typ_Elmt
);
3374 -- Issue an error if the aspect applies to a type declared inside a
3375 -- generic body and if said type derives from or has a component
3376 -- of ageneric formal type - since those are considered to have
3377 -- controlled/task parts and have Aspect_No_Parts specified as
3378 -- False by default (RM H.4.1(4/5) is about the language-defined
3379 -- No_Controlled_Parts aspect, and we are using the same rules for
3382 -- We do not check tagged types since deriving from a formal type
3383 -- within an enclosing generic unit is already illegal
3384 -- (RM 3.9.1 (4/2)).
3386 if Aspect_Value
= Standard_True
3387 and then In_Generic_Body
(Typ
)
3388 and then not Is_Tagged_Type
(Typ
)
3390 Gen_Bodies
:= New_Elmt_List
;
3392 Get_Generic_Formal_Types_In_Hierarchy
3394 Examine_Components
=> True);
3396 -- Climb scopes collecting generic bodies
3398 Scop
:= Scope
(Typ
);
3399 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
3401 -- Generic package body
3403 if Ekind
(Scop
) = E_Generic_Package
3404 and then In_Package_Body
(Scop
)
3406 Append_Elmt
(Scop
, Gen_Bodies
);
3408 -- Generic subprogram body
3410 elsif Is_Generic_Subprogram
(Scop
) then
3411 Append_Elmt
(Scop
, Gen_Bodies
);
3414 Scop
:= Scope
(Scop
);
3417 -- Warn about the improper use of Aspect_No_Parts on a type
3418 -- declaration deriving from or that has a component of a generic
3419 -- formal type within the formal type's corresponding generic
3420 -- body by moving through all formal types in Typ's hierarchy and
3421 -- checking if they are formals in any of the enclosing generic
3424 -- However, a special exception gets made for formal types which
3425 -- derive from a type which has Aspect_No_Parts True.
3430 -- type Form is private;
3432 -- type Type_A is new Form with No_Controlled_Parts; -- OK
3435 -- package body G is
3436 -- type Type_B is new Form with No_Controlled_Parts; -- ERROR
3440 -- type Form is private;
3442 -- type Type_A is record C : Form; end record
3443 -- with No_Controlled_Parts; -- OK
3446 -- package body G is
3447 -- type Type_B is record C : Form; end record
3448 -- with No_Controlled_Parts; -- ERROR
3451 -- type Root is tagged null record with No_Controlled_Parts;
3454 -- type Form is new Root with private;
3456 -- type Type_A is record C : Form; end record
3457 -- with No_Controlled_Parts; -- OK
3460 -- package body G is
3461 -- type Type_B is record C : Form; end record
3462 -- with No_Controlled_Parts; -- OK
3465 Curr_Formal_Elmt
:= First_Elmt
(Gen_Formals
);
3466 while Present
(Curr_Formal_Elmt
) loop
3468 Curr_Body_Elmt
:= First_Elmt
(Gen_Bodies
);
3469 while Present
(Curr_Body_Elmt
) loop
3471 -- Obtain types in the formal type's hierarchy which have
3472 -- the aspect specified.
3474 Types_With_Aspect
:=
3475 Get_Types_With_Aspect_In_Hierarchy
3476 (Node
(Curr_Formal_Elmt
));
3478 -- We found a type declaration in a generic body where both
3479 -- Aspect_No_Parts is true and one of its ancestors is a
3480 -- generic formal type.
3482 if Scope
(Node
(Curr_Formal_Elmt
)) =
3483 Node
(Curr_Body_Elmt
)
3485 -- Check that no ancestors of the formal type have
3486 -- Aspect_No_Parts True before issuing the error.
3488 and then (Is_Empty_Elmt_List
(Types_With_Aspect
)
3490 Get_Aspect_No_Parts_Value
3491 (Node
(First_Elmt
(Types_With_Aspect
)))
3494 Error_Msg_Node_1
:= Typ
;
3495 Error_Msg_Node_2
:= Node
(Curr_Formal_Elmt
);
3497 ("aspect % cannot be applied to "
3498 & "type & which has an ancestor or component of "
3499 & "formal type & within the formal type's "
3500 & "corresponding generic body", Sloc
(Typ
));
3503 Next_Elmt
(Curr_Body_Elmt
);
3506 Next_Elmt
(Curr_Formal_Elmt
);
3509 end Check_No_Parts_Violations
;
3511 ---------------------------------
3512 -- Check_Suspicious_Convention --
3513 ---------------------------------
3515 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
) is
3517 if Has_Discriminants
(Rec_Type
)
3518 and then Is_Base_Type
(Rec_Type
)
3519 and then not Is_Unchecked_Union
(Rec_Type
)
3520 and then (Convention
(Rec_Type
) = Convention_C
3522 Convention
(Rec_Type
) = Convention_CPP
)
3523 and then Comes_From_Source
(Rec_Type
)
3524 and then not In_Instance
3525 and then not Has_Warnings_Off
(Rec_Type
)
3528 Cprag
: constant Node_Id
:=
3529 Get_Rep_Pragma
(Rec_Type
, Name_Convention
);
3533 if Present
(Cprag
) then
3534 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3536 if Convention
(Rec_Type
) = Convention_C
then
3538 ("?x?discriminated record has no direct equivalent in "
3542 ("?x?discriminated record has no direct equivalent in "
3547 ("\?x?use of convention for type& is dubious",
3552 end Check_Suspicious_Convention
;
3554 ------------------------------
3555 -- Check_Suspicious_Modulus --
3556 ------------------------------
3558 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
3559 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
3562 if not Warn_On_Suspicious_Modulus_Value
then
3566 if Nkind
(Decl
) = N_Full_Type_Declaration
then
3568 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
3571 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
3573 Modulus
: constant Node_Id
:=
3574 Original_Node
(Expression
(Tdef
));
3577 if Nkind
(Modulus
) = N_Integer_Literal
then
3579 Modv
: constant Uint
:= Intval
(Modulus
);
3580 Sizv
: constant Uint
:= RM_Size
(Utype
);
3583 -- First case, modulus and size are the same. This
3584 -- happens if you have something like mod 32, with
3585 -- an explicit size of 32, this is for sure a case
3586 -- where the warning is given, since it is seems
3587 -- very unlikely that someone would want e.g. a
3588 -- five bit type stored in 32 bits. It is much
3589 -- more likely they wanted a 32-bit type.
3594 -- Second case, the modulus is 32 or 64 and no
3595 -- size clause is present. This is a less clear
3596 -- case for giving the warning, but in the case
3597 -- of 32/64 (5-bit or 6-bit types) these seem rare
3598 -- enough that it is a likely error (and in any
3599 -- case using 2**5 or 2**6 in these cases seems
3600 -- clearer. We don't include 8 or 16 here, simply
3601 -- because in practice 3-bit and 4-bit types are
3602 -- more common and too many false positives if
3603 -- we warn in these cases.
3605 elsif not Has_Size_Clause
(Utype
)
3606 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
3610 -- No warning needed
3616 -- If we fall through, give warning
3618 Error_Msg_Uint_1
:= Modv
;
3620 ("?.m?2 '*'*^' may have been intended here",
3628 end Check_Suspicious_Modulus
;
3630 -----------------------
3631 -- Freeze_Array_Type --
3632 -----------------------
3634 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
3635 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
3636 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
3639 -- Set to Component_Size clause or Atomic pragma, if any
3641 Non_Standard_Enum
: Boolean := False;
3642 -- Set true if any of the index types is an enumeration type with a
3643 -- non-standard representation.
3646 Freeze_And_Append
(Ctyp
, N
, Result
);
3648 Indx
:= First_Index
(Arr
);
3649 while Present
(Indx
) loop
3650 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
3652 if Is_Enumeration_Type
(Etype
(Indx
))
3653 and then Has_Non_Standard_Rep
(Etype
(Indx
))
3655 Non_Standard_Enum
:= True;
3661 -- Processing that is done only for base types
3663 if Ekind
(Arr
) = E_Array_Type
then
3665 -- Deal with default setting of reverse storage order
3667 Set_SSO_From_Default
(Arr
);
3669 -- Propagate flags from component type
3671 Propagate_Concurrent_Flags
(Arr
, Ctyp
);
3672 Propagate_Controlled_Flags
(Arr
, Ctyp
, Comp
=> True);
3674 if Has_Unchecked_Union
(Ctyp
) then
3675 Set_Has_Unchecked_Union
(Arr
);
3678 -- The array type requires its own invariant procedure in order to
3679 -- verify the component invariant over all elements. In GNATprove
3680 -- mode, the component invariants are checked by other means. They
3681 -- should not be added to the array type invariant procedure, so
3682 -- that the procedure can be used to check the array type
3683 -- invariants if any.
3685 if Has_Invariants
(Ctyp
)
3686 and then not GNATprove_Mode
3688 Set_Has_Own_Invariants
(Arr
);
3691 -- Warn for pragma Pack overriding foreign convention
3693 if Has_Foreign_Convention
(Ctyp
)
3694 and then Has_Pragma_Pack
(Arr
)
3697 CN
: constant Name_Id
:=
3698 Get_Convention_Name
(Convention
(Ctyp
));
3699 PP
: constant Node_Id
:=
3700 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
3702 if Present
(PP
) then
3703 Error_Msg_Name_1
:= CN
;
3704 Error_Msg_Sloc
:= Sloc
(Arr
);
3706 ("pragma Pack affects convention % components #??", PP
);
3707 Error_Msg_Name_1
:= CN
;
3709 ("\array components may not have % compatible "
3710 & "representation??", PP
);
3715 -- Check for Aliased or Atomic or Full Access or Independent
3716 -- components with an unsuitable component size clause given.
3717 -- The main purpose is to give an error when bit packing would
3718 -- be required to honor the component size, because bit packing
3719 -- is incompatible with these aspects; when bit packing is not
3720 -- required, the final validation of the component size may be
3721 -- left to the back end.
3723 if Has_Component_Size_Clause
(Arr
) then
3725 procedure Complain_CS
(T
: String; Min
: Boolean := False);
3726 -- Output an error message for an unsuitable component size
3727 -- clause for independent components (T is either "aliased"
3728 -- or "atomic" or "volatile full access" or "independent").
3734 procedure Complain_CS
(T
: String; Min
: Boolean := False) is
3737 Get_Attribute_Definition_Clause
3738 (FS
, Attribute_Component_Size
);
3741 ("incorrect component size for " & T
& " components",
3744 if Known_Static_Esize
(Ctyp
) then
3745 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3747 Error_Msg_N
("\minimum allowed value is^", Clause
);
3749 Error_Msg_N
("\only allowed value is^", Clause
);
3753 ("\must be multiple of storage unit", Clause
);
3757 -- Start of processing for CS_Check
3760 -- OK if the component size and object size are equal, or
3761 -- if the component size is a multiple of the storage unit.
3763 if (if Known_Static_Esize
(Ctyp
)
3764 then Component_Size
(Arr
) = Esize
(Ctyp
)
3765 else Component_Size
(Arr
) mod System_Storage_Unit
= 0)
3769 elsif Has_Aliased_Components
(Arr
) then
3770 Complain_CS
("aliased");
3772 elsif Has_Atomic_Components
(Arr
)
3773 or else Is_Atomic
(Ctyp
)
3775 Complain_CS
("atomic");
3777 elsif Is_Volatile_Full_Access
(Ctyp
) then
3778 Complain_CS
("volatile full access");
3780 -- For Independent a larger size is permitted
3782 elsif (Has_Independent_Components
(Arr
)
3783 or else Is_Independent
(Ctyp
))
3784 and then (not Known_Static_Esize
(Ctyp
)
3785 or else Component_Size
(Arr
) < Esize
(Ctyp
))
3787 Complain_CS
("independent", Min
=> True);
3791 -- Check for Aliased or Atomic or Full Access or Independent
3792 -- components with an unsuitable aspect/pragma Pack given.
3793 -- The main purpose is to prevent bit packing from occurring,
3794 -- because bit packing is incompatible with these aspects; when
3795 -- bit packing cannot occur, the final handling of the packing
3796 -- may be left to the back end.
3798 elsif Is_Packed
(Arr
) and then Known_Static_RM_Size
(Ctyp
) then
3799 Pack_Check
: declare
3801 procedure Complain_Pack
(T
: String);
3802 -- Output a warning message for an unsuitable aspect/pragma
3803 -- Pack for independent components (T is either "aliased" or
3804 -- "atomic" or "volatile full access" or "independent") and
3805 -- reset the Is_Packed flag on the array type.
3811 procedure Complain_Pack
(T
: String) is
3814 ("?cannot pack " & T
& " components (RM 13.2(7))",
3815 Get_Rep_Pragma
(FS
, Name_Pack
));
3817 Set_Is_Packed
(Arr
, False);
3820 -- Start of processing for Pack_Check
3823 -- OK if the component size and object size are equal, or
3824 -- if the component size is a multiple of the storage unit.
3826 if (if Known_Static_Esize
(Ctyp
)
3827 then RM_Size
(Ctyp
) = Esize
(Ctyp
)
3828 else RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
3832 elsif Has_Aliased_Components
(Arr
) then
3833 Complain_Pack
("aliased");
3835 elsif Has_Atomic_Components
(Arr
)
3836 or else Is_Atomic
(Ctyp
)
3838 Complain_Pack
("atomic");
3840 elsif Is_Volatile_Full_Access
(Ctyp
) then
3841 Complain_Pack
("volatile full access");
3843 elsif Has_Independent_Components
(Arr
)
3844 or else Is_Independent
(Ctyp
)
3846 Complain_Pack
("independent");
3851 -- If packing was requested or if the component size was
3852 -- set explicitly, then see if bit packing is required. This
3853 -- processing is only done for base types, since all of the
3854 -- representation aspects involved are type-related.
3856 -- This is not just an optimization, if we start processing the
3857 -- subtypes, they interfere with the settings on the base type
3858 -- (this is because Is_Packed has a slightly different meaning
3859 -- before and after freezing).
3867 and then Known_Static_RM_Size
(Ctyp
)
3868 and then not Has_Component_Size_Clause
(Arr
)
3870 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
3872 elsif Known_Component_Size
(Arr
) then
3873 Csiz
:= Component_Size
(Arr
);
3875 elsif not Known_Static_Esize
(Ctyp
) then
3879 Esiz
:= Esize
(Ctyp
);
3881 -- We can set the component size if it is less than 16,
3882 -- rounding it up to the next storage unit size.
3886 elsif Esiz
<= 16 then
3892 -- Set component size up to match alignment if it would
3893 -- otherwise be less than the alignment. This deals with
3894 -- cases of types whose alignment exceeds their size (the
3895 -- padded type cases).
3897 if Csiz
/= 0 and then Known_Alignment
(Ctyp
) then
3899 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
3908 -- Case of component size that may result in bit packing
3910 if 1 <= Csiz
and then Csiz
<= System_Max_Integer_Size
then
3912 Ent
: constant Entity_Id
:=
3913 First_Subtype
(Arr
);
3914 Pack_Pragma
: constant Node_Id
:=
3915 Get_Rep_Pragma
(Ent
, Name_Pack
);
3916 Comp_Size_C
: constant Node_Id
:=
3917 Get_Attribute_Definition_Clause
3918 (Ent
, Attribute_Component_Size
);
3921 -- Warn if we have pack and component size so that the
3924 -- Note: here we must check for the presence of a
3925 -- component size before checking for a Pack pragma to
3926 -- deal with the case where the array type is a derived
3927 -- type whose parent is currently private.
3929 if Present
(Comp_Size_C
)
3930 and then Has_Pragma_Pack
(Ent
)
3931 and then Warn_On_Redundant_Constructs
3933 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
3935 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
3937 ("\?r?explicit component size given#!", Pack_Pragma
);
3938 Set_Is_Packed
(Base_Type
(Ent
), False);
3939 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
3942 -- Set component size if not already set by a component
3945 if No
(Comp_Size_C
) then
3946 Set_Component_Size
(Arr
, Csiz
);
3949 -- Check for base type of 8, 16, 32 bits, where an
3950 -- unsigned subtype has a length one less than the
3951 -- base type (e.g. Natural subtype of Integer).
3953 -- In such cases, if a component size was not set
3954 -- explicitly, then generate a warning.
3956 if Has_Pragma_Pack
(Arr
)
3957 and then No
(Comp_Size_C
)
3958 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
3959 and then Known_Esize
(Base_Type
(Ctyp
))
3960 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
3962 Error_Msg_Uint_1
:= Csiz
;
3964 if Present
(Pack_Pragma
) then
3966 ("??pragma Pack causes component size to be ^!",
3969 ("\??use Component_Size to set desired value!",
3974 -- Bit packing is never needed for 8, 16, 32, 64 or 128
3976 if Addressable
(Csiz
) then
3978 -- If the Esize of the component is known and equal to
3979 -- the component size then even packing is not needed.
3981 if Known_Static_Esize
(Ctyp
)
3982 and then Esize
(Ctyp
) = Csiz
3984 -- Here the array was requested to be packed, but
3985 -- the packing request had no effect whatsoever,
3986 -- so flag Is_Packed is reset.
3988 -- Note: semantically this means that we lose track
3989 -- of the fact that a derived type inherited pragma
3990 -- Pack that was non-effective, but that is fine.
3992 -- We regard a Pack pragma as a request to set a
3993 -- representation characteristic, and this request
3996 Set_Is_Packed
(Base_Type
(Arr
), False);
3997 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
3999 Set_Is_Packed
(Base_Type
(Arr
), True);
4000 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
4003 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
4005 -- Bit packing is not needed for multiples of the storage
4006 -- unit if the type is composite because the back end can
4007 -- byte pack composite types efficiently. That's not true
4008 -- for discrete types because every read would generate a
4009 -- lot of instructions, so we keep using the manipulation
4010 -- routines of the runtime for them.
4012 elsif Csiz
mod System_Storage_Unit
= 0
4013 and then Is_Composite_Type
(Ctyp
)
4015 Set_Is_Packed
(Base_Type
(Arr
), True);
4016 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
4017 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
4019 -- In all other cases, bit packing is needed
4022 Set_Is_Packed
(Base_Type
(Arr
), True);
4023 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
4024 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
4030 -- Warn for case of atomic type
4032 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
4035 and then not Addressable
(Component_Size
(FS
))
4038 ("non-atomic components of type& may not be "
4039 & "accessible by separate tasks??", Clause
, Arr
);
4041 if Has_Component_Size_Clause
(Arr
) then
4042 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
4043 (FS
, Attribute_Component_Size
));
4044 Error_Msg_N
("\because of component size clause#??", Clause
);
4046 elsif Has_Pragma_Pack
(Arr
) then
4047 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
4048 Error_Msg_N
("\because of pragma Pack#??", Clause
);
4052 -- Check for scalar storage order
4057 Check_Component_Storage_Order
4060 ADC
=> Get_Attribute_Definition_Clause
4061 (First_Subtype
(Arr
),
4062 Attribute_Scalar_Storage_Order
),
4063 Comp_ADC_Present
=> Dummy
);
4066 -- Processing that is done only for subtypes
4069 -- Acquire alignment from base type. Known_Alignment of the base
4070 -- type is False for Wide_String, for example.
4072 if not Known_Alignment
(Arr
)
4073 and then Known_Alignment
(Base_Type
(Arr
))
4075 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
4076 Adjust_Esize_Alignment
(Arr
);
4080 -- Specific checks for bit-packed arrays
4082 if Is_Bit_Packed_Array
(Arr
) then
4084 -- Check number of elements for bit-packed arrays that come from
4085 -- source and have compile time known ranges. The bit-packed
4086 -- arrays circuitry does not support arrays with more than
4087 -- Integer'Last + 1 elements, and when this restriction is
4088 -- violated, causes incorrect data access.
4090 -- For the case where this is not compile time known, a run-time
4091 -- check should be generated???
4093 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
4102 Index
:= First_Index
(Arr
);
4103 while Present
(Index
) loop
4104 Ityp
:= Etype
(Index
);
4106 -- Never generate an error if any index is of a generic
4107 -- type. We will check this in instances.
4109 if Is_Generic_Type
(Ityp
) then
4115 Make_Attribute_Reference
(Loc
,
4116 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
4117 Attribute_Name
=> Name_Range_Length
);
4118 Analyze_And_Resolve
(Ilen
);
4120 -- No attempt is made to check number of elements if not
4121 -- compile time known.
4123 if Nkind
(Ilen
) /= N_Integer_Literal
then
4128 Elmts
:= Elmts
* Intval
(Ilen
);
4132 if Elmts
> Intval
(High_Bound
4133 (Scalar_Range
(Standard_Integer
))) + 1
4136 ("bit packed array type may not have "
4137 & "more than Integer''Last+1 elements", Arr
);
4144 if Known_RM_Size
(Arr
) then
4146 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
4150 -- It is not clear if it is possible to have no size clause
4151 -- at this stage, but it is not worth worrying about. Post
4152 -- error on the entity name in the size clause if present,
4153 -- else on the type entity itself.
4155 if Present
(SizC
) then
4156 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
4158 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
4164 -- If any of the index types was an enumeration type with a non-
4165 -- standard rep clause, then we indicate that the array type is
4166 -- always packed (even if it is not bit-packed).
4168 if Non_Standard_Enum
then
4169 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
4170 Set_Is_Packed
(Base_Type
(Arr
));
4173 Set_Component_Alignment_If_Not_Set
(Arr
);
4175 -- If the array is packed and bit-packed or packed to eliminate holes
4176 -- in the non-contiguous enumeration index types, we must create the
4177 -- packed array type to be used to actually implement the type. This
4178 -- is only needed for real array types (not for string literal types,
4179 -- since they are present only for the front end).
4182 and then (Is_Bit_Packed_Array
(Arr
) or else Non_Standard_Enum
)
4183 and then Ekind
(Arr
) /= E_String_Literal_Subtype
4185 Create_Packed_Array_Impl_Type
(Arr
);
4186 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
4188 -- Make sure that we have the necessary routines to implement the
4189 -- packing, and complain now if not. Note that we only test this
4190 -- for constrained array types.
4192 if Is_Constrained
(Arr
)
4193 and then Is_Bit_Packed_Array
(Arr
)
4194 and then Present
(Packed_Array_Impl_Type
(Arr
))
4195 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
4198 CS
: constant Uint
:= Component_Size
(Arr
);
4199 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
4203 and then not RTE_Available
(RE
)
4206 ("packing of " & UI_Image
(CS
) & "-bit components",
4207 First_Subtype
(Etype
(Arr
)));
4209 -- Cancel the packing
4211 Set_Is_Packed
(Base_Type
(Arr
), False);
4212 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
4213 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
4219 -- Size information of packed array type is copied to the array
4220 -- type, since this is really the representation. But do not
4221 -- override explicit existing size values. If the ancestor subtype
4222 -- is constrained the Packed_Array_Impl_Type will be inherited
4223 -- from it, but the size may have been provided already, and
4224 -- must not be overridden either.
4226 if not Has_Size_Clause
(Arr
)
4228 (No
(Ancestor_Subtype
(Arr
))
4229 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
4231 Copy_Esize
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4232 Copy_RM_Size
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4235 if not Has_Alignment_Clause
(Arr
) then
4237 (To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4243 -- A Ghost type cannot have a component of protected or task type
4244 -- (SPARK RM 6.9(21)).
4246 if Is_Ghost_Entity
(Arr
) and then Is_Concurrent_Type
(Ctyp
) then
4248 ("ghost array type & cannot have concurrent component type",
4251 end Freeze_Array_Type
;
4253 -------------------------------
4254 -- Freeze_Object_Declaration --
4255 -------------------------------
4257 procedure Freeze_Object_Declaration
(E
: Entity_Id
) is
4258 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
);
4259 -- Check that the size of array type Typ can be computed without
4260 -- overflow, and generates a Storage_Error otherwise. This is only
4261 -- relevant for array types whose index is a modular type with
4262 -- Standard_Long_Long_Integer_Size bits: wrap-around arithmetic
4263 -- might yield a meaningless value for the length of the array,
4264 -- or its corresponding attribute.
4266 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
);
4267 -- Ensure that the initialization state of variable Var_Id subject
4268 -- to pragma Thread_Local_Storage agrees with the semantics of the
4271 function Has_Default_Initialization
4272 (Obj_Id
: Entity_Id
) return Boolean;
4273 -- Determine whether object Obj_Id default initialized
4275 -------------------------------
4276 -- Check_Large_Modular_Array --
4277 -------------------------------
4279 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
) is
4280 Obj_Loc
: constant Source_Ptr
:= Sloc
(E
);
4281 Idx_Typ
: Entity_Id
;
4284 -- Nothing to do when expansion is disabled because this routine
4285 -- generates a runtime check.
4287 if not Expander_Active
then
4290 -- Nothing to do for String literal subtypes because their index
4291 -- cannot be a modular type.
4293 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
4296 -- Nothing to do for an imported object because the object will
4297 -- be created on the exporting side.
4299 elsif Is_Imported
(E
) then
4302 -- Nothing to do for unconstrained array types. This case arises
4303 -- when the object declaration is illegal.
4305 elsif not Is_Constrained
(Typ
) then
4309 Idx_Typ
:= Etype
(First_Index
(Typ
));
4311 -- To prevent arithmetic overflow with large values, we raise
4312 -- Storage_Error under the following guard:
4314 -- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
4316 -- This takes care of the boundary case, but it is preferable to
4317 -- use a smaller limit, because even on 64-bit architectures an
4318 -- array of more than 2 ** 30 bytes is likely to raise
4321 if Is_Modular_Integer_Type
(Idx_Typ
)
4322 and then RM_Size
(Idx_Typ
) = Standard_Long_Long_Integer_Size
4324 -- Ensure that the type of the object is elaborated before
4325 -- the check itself is emitted to avoid elaboration issues
4326 -- in the code generator at the library level.
4328 if Is_Itype
(Etype
(E
))
4329 and then In_Open_Scopes
(Scope
(Etype
(E
)))
4332 Ref_Node
: constant Node_Id
:=
4333 Make_Itype_Reference
(Obj_Loc
);
4335 Set_Itype
(Ref_Node
, Etype
(E
));
4336 Insert_Action
(Declaration_Node
(E
), Ref_Node
);
4340 Insert_Action
(Declaration_Node
(E
),
4341 Make_Raise_Storage_Error
(Obj_Loc
,
4343 Make_Op_Ge
(Obj_Loc
,
4345 Make_Op_Subtract
(Obj_Loc
,
4347 Make_Op_Divide
(Obj_Loc
,
4349 Make_Attribute_Reference
(Obj_Loc
,
4351 New_Occurrence_Of
(Typ
, Obj_Loc
),
4352 Attribute_Name
=> Name_Last
),
4354 Make_Integer_Literal
(Obj_Loc
, Uint_2
)),
4356 Make_Op_Divide
(Obj_Loc
,
4358 Make_Attribute_Reference
(Obj_Loc
,
4360 New_Occurrence_Of
(Typ
, Obj_Loc
),
4361 Attribute_Name
=> Name_First
),
4363 Make_Integer_Literal
(Obj_Loc
, Uint_2
))),
4365 Make_Integer_Literal
(Obj_Loc
, (Uint_2
** 30))),
4366 Reason
=> SE_Object_Too_Large
));
4368 end Check_Large_Modular_Array
;
4370 ---------------------------------------
4371 -- Check_Pragma_Thread_Local_Storage --
4372 ---------------------------------------
4374 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
) is
4375 function Has_Incompatible_Initialization
4376 (Var_Decl
: Node_Id
) return Boolean;
4377 -- Determine whether variable Var_Id with declaration Var_Decl is
4378 -- initialized with a value that violates the semantics of pragma
4379 -- Thread_Local_Storage.
4381 -------------------------------------
4382 -- Has_Incompatible_Initialization --
4383 -------------------------------------
4385 function Has_Incompatible_Initialization
4386 (Var_Decl
: Node_Id
) return Boolean
4388 Init_Expr
: constant Node_Id
:= Expression
(Var_Decl
);
4391 -- The variable is default-initialized. This directly violates
4392 -- the semantics of the pragma.
4394 if Has_Default_Initialization
(Var_Id
) then
4397 -- The variable has explicit initialization. In this case only
4398 -- a handful of values satisfy the semantics of the pragma.
4400 elsif Has_Init_Expression
(Var_Decl
)
4401 and then Present
(Init_Expr
)
4403 -- "null" is a legal form of initialization
4405 if Nkind
(Init_Expr
) = N_Null
then
4408 -- A static expression is a legal form of initialization
4410 elsif Is_Static_Expression
(Init_Expr
) then
4413 -- A static aggregate is a legal form of initialization
4415 elsif Nkind
(Init_Expr
) = N_Aggregate
4416 and then Compile_Time_Known_Aggregate
(Init_Expr
)
4420 -- All other initialization expressions violate the semantic
4427 -- The variable lacks any kind of initialization, which agrees
4428 -- with the semantics of the pragma.
4433 end Has_Incompatible_Initialization
;
4435 -- Local declarations
4437 Var_Decl
: constant Node_Id
:= Declaration_Node
(Var_Id
);
4439 -- Start of processing for Check_Pragma_Thread_Local_Storage
4442 -- A variable whose initialization is suppressed lacks any kind of
4445 if Suppress_Initialization
(Var_Id
) then
4448 -- The variable has default initialization, or is explicitly
4449 -- initialized to a value other than null, static expression,
4450 -- or a static aggregate.
4452 elsif Has_Incompatible_Initialization
(Var_Decl
) then
4454 ("Thread_Local_Storage variable& is improperly initialized",
4457 ("\only allowed initialization is explicit NULL, static "
4458 & "expression or static aggregate", Var_Decl
, Var_Id
);
4460 end Check_Pragma_Thread_Local_Storage
;
4462 --------------------------------
4463 -- Has_Default_Initialization --
4464 --------------------------------
4466 function Has_Default_Initialization
4467 (Obj_Id
: Entity_Id
) return Boolean
4469 Obj_Decl
: constant Node_Id
:= Declaration_Node
(Obj_Id
);
4470 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
4474 Comes_From_Source
(Obj_Id
)
4475 and then not Is_Imported
(Obj_Id
)
4476 and then not Has_Init_Expression
(Obj_Decl
)
4478 ((Has_Non_Null_Base_Init_Proc
(Obj_Typ
)
4479 and then not No_Initialization
(Obj_Decl
)
4480 and then not Initialization_Suppressed
(Obj_Typ
))
4482 (Needs_Simple_Initialization
(Obj_Typ
)
4483 and then not Is_Internal
(Obj_Id
)));
4484 end Has_Default_Initialization
;
4488 Typ
: constant Entity_Id
:= Etype
(E
);
4491 -- Start of processing for Freeze_Object_Declaration
4494 -- Abstract type allowed only for C++ imported variables or constants
4496 -- Note: we inhibit this check for objects that do not come from
4497 -- source because there is at least one case (the expansion of
4498 -- x'Class'Input where x is abstract) where we legitimately
4499 -- generate an abstract object.
4501 if Is_Abstract_Type
(Typ
)
4502 and then Comes_From_Source
(Parent
(E
))
4503 and then not (Is_Imported
(E
) and then Is_CPP_Class
(Typ
))
4505 Def
:= Object_Definition
(Parent
(E
));
4507 Error_Msg_N
("type of object cannot be abstract", Def
);
4509 if Is_CPP_Class
(Etype
(E
)) then
4510 Error_Msg_NE
("\} may need a cpp_constructor", Def
, Typ
);
4512 elsif Present
(Expression
(Parent
(E
))) then
4513 Error_Msg_N
-- CODEFIX
4514 ("\maybe a class-wide type was meant", Def
);
4518 -- For object created by object declaration, perform required
4519 -- categorization (preelaborate and pure) checks. Defer these
4520 -- checks to freeze time since pragma Import inhibits default
4521 -- initialization and thus pragma Import affects these checks.
4523 Validate_Object_Declaration
(Declaration_Node
(E
));
4525 -- If there is an address clause, check that it is valid and if need
4526 -- be move initialization to the freeze node.
4528 Check_Address_Clause
(E
);
4530 -- Similar processing is needed for aspects that may affect object
4531 -- layout, like Address, if there is an initialization expression.
4532 -- We don't do this if there is a pragma Linker_Section, because it
4533 -- would prevent the back end from statically initializing the
4534 -- object; we don't want elaboration code in that case.
4536 if Has_Delayed_Aspects
(E
)
4537 and then Expander_Active
4538 and then Is_Array_Type
(Typ
)
4539 and then Present
(Expression
(Declaration_Node
(E
)))
4540 and then No
(Linker_Section_Pragma
(E
))
4543 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4544 Lhs
: constant Node_Id
:= New_Occurrence_Of
(E
, Loc
);
4547 -- Capture initialization value at point of declaration, and
4548 -- make explicit assignment legal, because object may be a
4551 Remove_Side_Effects
(Expression
(Decl
));
4552 Set_Assignment_OK
(Lhs
);
4554 -- Move initialization to freeze actions
4556 Append_Freeze_Action
(E
,
4557 Make_Assignment_Statement
(Loc
,
4559 Expression
=> Expression
(Decl
)));
4561 Set_No_Initialization
(Decl
);
4562 -- Set_Is_Frozen (E, False);
4566 -- Reset Is_True_Constant for non-constant aliased object. We
4567 -- consider that the fact that a non-constant object is aliased may
4568 -- indicate that some funny business is going on, e.g. an aliased
4569 -- object is passed by reference to a procedure which captures the
4570 -- address of the object, which is later used to assign a new value,
4571 -- even though the compiler thinks that it is not modified. Such
4572 -- code is highly dubious, but we choose to make it "work" for
4573 -- non-constant aliased objects.
4575 -- Note that we used to do this for all aliased objects, whether or
4576 -- not constant, but this caused anomalies down the line because we
4577 -- ended up with static objects that were not Is_True_Constant. Not
4578 -- resetting Is_True_Constant for (aliased) constant objects ensures
4579 -- that this anomaly never occurs.
4581 -- However, we don't do that for internal entities. We figure that if
4582 -- we deliberately set Is_True_Constant for an internal entity, e.g.
4583 -- a dispatch table entry, then we mean it.
4585 if Ekind
(E
) /= E_Constant
4586 and then (Is_Aliased
(E
) or else Is_Aliased
(Typ
))
4587 and then not Is_Internal_Name
(Chars
(E
))
4589 Set_Is_True_Constant
(E
, False);
4592 -- If the object needs any kind of default initialization, an error
4593 -- must be issued if No_Default_Initialization applies. The check
4594 -- doesn't apply to imported objects, which are not ever default
4595 -- initialized, and is why the check is deferred until freezing, at
4596 -- which point we know if Import applies. Deferred constants are also
4597 -- exempted from this test because their completion is explicit, or
4598 -- through an import pragma.
4600 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
4603 elsif Has_Default_Initialization
(E
) then
4605 (No_Default_Initialization
, Declaration_Node
(E
));
4608 -- Ensure that a variable subject to pragma Thread_Local_Storage
4610 -- * Lacks default initialization, or
4612 -- * The initialization expression is either "null", a static
4613 -- constant, or a compile-time known aggregate.
4615 if Has_Pragma_Thread_Local_Storage
(E
) then
4616 Check_Pragma_Thread_Local_Storage
(E
);
4619 -- For imported objects, set Is_Public unless there is also an
4620 -- address clause, which means that there is no external symbol
4621 -- needed for the Import (Is_Public may still be set for other
4622 -- unrelated reasons). Note that we delayed this processing
4623 -- till freeze time so that we can be sure not to set the flag
4624 -- if there is an address clause. If there is such a clause,
4625 -- then the only purpose of the Import pragma is to suppress
4626 -- implicit initialization.
4628 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4632 -- For source objects that are not Imported and are library level, if
4633 -- no linker section pragma was given inherit the appropriate linker
4634 -- section from the corresponding type.
4636 if Comes_From_Source
(E
)
4637 and then not Is_Imported
(E
)
4638 and then Is_Library_Level_Entity
(E
)
4639 and then No
(Linker_Section_Pragma
(E
))
4641 Set_Linker_Section_Pragma
(E
, Linker_Section_Pragma
(Typ
));
4644 -- For convention C objects of an enumeration type, warn if the size
4645 -- is not integer size and no explicit size given. Skip warning for
4646 -- Boolean and Character, and assume programmer expects 8-bit sizes
4649 if (Convention
(E
) = Convention_C
4651 Convention
(E
) = Convention_CPP
)
4652 and then Is_Enumeration_Type
(Typ
)
4653 and then not Is_Character_Type
(Typ
)
4654 and then not Is_Boolean_Type
(Typ
)
4655 and then Esize
(Typ
) < Standard_Integer_Size
4656 and then not Has_Size_Clause
(E
)
4658 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4660 ("??convention C enumeration object has size less than ^", E
);
4661 Error_Msg_N
("\??use explicit size clause to set size", E
);
4664 -- Declaring too big an array in disabled ghost code is OK
4666 if Is_Array_Type
(Typ
) and then not Is_Ignored_Ghost_Entity
(E
) then
4667 Check_Large_Modular_Array
(Typ
);
4669 end Freeze_Object_Declaration
;
4671 -----------------------------
4672 -- Freeze_Generic_Entities --
4673 -----------------------------
4675 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
4682 E
:= First_Entity
(Pack
);
4683 while Present
(E
) loop
4684 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
4685 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
4687 Append_To
(Flist
, F
);
4689 elsif Ekind
(E
) = E_Generic_Package
then
4690 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
4697 end Freeze_Generic_Entities
;
4699 --------------------
4700 -- Freeze_Profile --
4701 --------------------
4703 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
4706 Warn_Node
: Node_Id
;
4709 -- Loop through formals
4711 Formal
:= First_Formal
(E
);
4712 while Present
(Formal
) loop
4713 F_Type
:= Etype
(Formal
);
4715 -- AI05-0151: incomplete types can appear in a profile. By the
4716 -- time the entity is frozen, the full view must be available,
4717 -- unless it is a limited view.
4719 if Is_Incomplete_Type
(F_Type
)
4720 and then Present
(Full_View
(F_Type
))
4721 and then not From_Limited_With
(F_Type
)
4723 F_Type
:= Full_View
(F_Type
);
4724 Set_Etype
(Formal
, F_Type
);
4727 if not From_Limited_With
(F_Type
)
4728 and then Should_Freeze_Type
(F_Type
, E
, N
)
4730 Freeze_And_Append
(F_Type
, N
, Result
);
4733 if Is_Private_Type
(F_Type
)
4734 and then Is_Private_Type
(Base_Type
(F_Type
))
4735 and then No
(Full_View
(Base_Type
(F_Type
)))
4736 and then not Is_Generic_Type
(F_Type
)
4737 and then not Is_Derived_Type
(F_Type
)
4739 -- If the type of a formal is incomplete, subprogram is being
4740 -- frozen prematurely. Within an instance (but not within a
4741 -- wrapper package) this is an artifact of our need to regard
4742 -- the end of an instantiation as a freeze point. Otherwise it
4743 -- is a definite error.
4746 Set_Is_Frozen
(E
, False);
4750 elsif not After_Last_Declaration
then
4752 ("type & must be fully defined before this point",
4758 -- Check suspicious parameter for C function. These tests apply
4759 -- only to exported/imported subprograms.
4761 if Warn_On_Export_Import
4762 and then Comes_From_Source
(E
)
4763 and then Convention
(E
) in Convention_C_Family
4764 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4765 and then Convention
(E
) /= Convention
(Formal
)
4766 and then not Has_Warnings_Off
(E
)
4767 and then not Has_Warnings_Off
(F_Type
)
4768 and then not Has_Warnings_Off
(Formal
)
4770 -- Qualify mention of formals with subprogram name
4772 Error_Msg_Qual_Level
:= 1;
4774 -- Check suspicious use of fat C pointer, but do not emit
4775 -- a warning on an access to subprogram when unnesting is
4778 if Is_Access_Type
(F_Type
)
4779 and then Known_Esize
(F_Type
)
4780 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
4781 and then (not Unnest_Subprogram_Mode
4782 or else not Is_Access_Subprogram_Type
(F_Type
))
4785 ("?x?type of & does not correspond to C pointer!", Formal
);
4787 -- Check suspicious return of boolean
4789 elsif Root_Type
(F_Type
) = Standard_Boolean
4790 and then Convention
(F_Type
) = Convention_Ada
4791 and then not Has_Warnings_Off
(F_Type
)
4792 and then not Has_Size_Clause
(F_Type
)
4795 ("& is an 8-bit Ada Boolean?x?", Formal
);
4797 ("\use appropriate corresponding type in C "
4798 & "(e.g. char)?x?", Formal
);
4800 -- Check suspicious tagged type
4802 elsif (Is_Tagged_Type
(F_Type
)
4804 (Is_Access_Type
(F_Type
)
4805 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
4806 and then Convention
(E
) = Convention_C
4809 ("?x?& involves a tagged type which does not "
4810 & "correspond to any C type!", Formal
);
4812 -- Check wrong convention subprogram pointer
4814 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
4815 and then not Has_Foreign_Convention
(F_Type
)
4818 ("?x?subprogram pointer & should "
4819 & "have foreign convention!", Formal
);
4820 Error_Msg_Sloc
:= Sloc
(F_Type
);
4822 ("\?x?add Convention pragma to declaration of &#",
4826 -- Turn off name qualification after message output
4828 Error_Msg_Qual_Level
:= 0;
4831 -- Check for unconstrained array in exported foreign convention
4834 if Has_Foreign_Convention
(E
)
4835 and then not Is_Imported
(E
)
4836 and then Is_Array_Type
(F_Type
)
4837 and then not Is_Constrained
(F_Type
)
4838 and then Warn_On_Export_Import
4840 Error_Msg_Qual_Level
:= 1;
4842 -- If this is an inherited operation, place the warning on
4843 -- the derived type declaration, rather than on the original
4846 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
4848 Warn_Node
:= Parent
(E
);
4850 if Formal
= First_Formal
(E
) then
4851 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
4854 Warn_Node
:= Formal
;
4857 Error_Msg_NE
("?x?type of argument& is unconstrained array",
4859 Error_Msg_N
("\?x?foreign caller must pass bounds explicitly",
4861 Error_Msg_Qual_Level
:= 0;
4864 if not From_Limited_With
(F_Type
) then
4865 if Is_Access_Type
(F_Type
) then
4866 F_Type
:= Designated_Type
(F_Type
);
4870 Next_Formal
(Formal
);
4873 -- Case of function: similar checks on return type
4875 if Ekind
(E
) = E_Function
then
4877 -- Freeze return type
4879 R_Type
:= Etype
(E
);
4881 -- AI05-0151: the return type may have been incomplete at the
4882 -- point of declaration. Replace it with the full view, unless the
4883 -- current type is a limited view. In that case the full view is
4884 -- in a different unit, and gigi finds the non-limited view after
4885 -- the other unit is elaborated.
4887 if Ekind
(R_Type
) = E_Incomplete_Type
4888 and then Present
(Full_View
(R_Type
))
4889 and then not From_Limited_With
(R_Type
)
4891 R_Type
:= Full_View
(R_Type
);
4892 Set_Etype
(E
, R_Type
);
4895 if Should_Freeze_Type
(R_Type
, E
, N
) then
4896 Freeze_And_Append
(R_Type
, N
, Result
);
4899 -- Check suspicious return type for C function
4901 if Warn_On_Export_Import
4902 and then Comes_From_Source
(E
)
4903 and then Convention
(E
) in Convention_C_Family
4904 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4906 -- Check suspicious return of fat C pointer
4908 if Is_Access_Type
(R_Type
)
4909 and then Known_Esize
(R_Type
)
4910 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
4911 and then not Has_Warnings_Off
(E
)
4912 and then not Has_Warnings_Off
(R_Type
)
4915 ("?x?return type of& does not correspond to C pointer!",
4918 -- Check suspicious return of boolean
4920 elsif Root_Type
(R_Type
) = Standard_Boolean
4921 and then Convention
(R_Type
) = Convention_Ada
4922 and then not Has_Warnings_Off
(E
)
4923 and then not Has_Warnings_Off
(R_Type
)
4924 and then not Has_Size_Clause
(R_Type
)
4927 N
: constant Node_Id
:=
4928 Result_Definition
(Declaration_Node
(E
));
4931 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
4933 ("\use appropriate corresponding type in C "
4934 & "(e.g. char)?x?", N
, E
);
4937 -- Check suspicious return tagged type
4939 elsif (Is_Tagged_Type
(R_Type
)
4940 or else (Is_Access_Type
(R_Type
)
4943 (Designated_Type
(R_Type
))))
4944 and then Convention
(E
) = Convention_C
4945 and then not Has_Warnings_Off
(E
)
4946 and then not Has_Warnings_Off
(R_Type
)
4948 Error_Msg_N
("?x?return type of & does not "
4949 & "correspond to C type!", E
);
4951 -- Check return of wrong convention subprogram pointer
4953 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
4954 and then not Has_Foreign_Convention
(R_Type
)
4955 and then not Has_Warnings_Off
(E
)
4956 and then not Has_Warnings_Off
(R_Type
)
4958 Error_Msg_N
("?x?& should return a foreign "
4959 & "convention subprogram pointer", E
);
4960 Error_Msg_Sloc
:= Sloc
(R_Type
);
4962 ("\?x?add Convention pragma to declaration of& #",
4967 -- Give warning for suspicious return of a result of an
4968 -- unconstrained array type in a foreign convention function.
4970 if Has_Foreign_Convention
(E
)
4972 -- We are looking for a return of unconstrained array
4974 and then Is_Array_Type
(R_Type
)
4975 and then not Is_Constrained
(R_Type
)
4977 -- Exclude imported routines, the warning does not belong on
4978 -- the import, but rather on the routine definition.
4980 and then not Is_Imported
(E
)
4982 -- Check that general warning is enabled, and that it is not
4983 -- suppressed for this particular case.
4985 and then Warn_On_Export_Import
4986 and then not Has_Warnings_Off
(E
)
4987 and then not Has_Warnings_Off
(R_Type
)
4990 ("?x?foreign convention function& should not return "
4991 & "unconstrained array!", E
);
4995 -- Check suspicious use of Import in pure unit (cases where the RM
4996 -- allows calls to be omitted).
5000 -- It might be suspicious if the compilation unit has the Pure
5003 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
5005 -- The RM allows omission of calls only in the case of
5006 -- library-level subprograms (see RM-10.2.1(18)).
5008 and then Is_Library_Level_Entity
(E
)
5010 -- Ignore internally generated entity. This happens in some cases
5011 -- of subprograms in specs, where we generate an implied body.
5013 and then Comes_From_Source
(Import_Pragma
(E
))
5015 -- Assume run-time knows what it is doing
5017 and then not GNAT_Mode
5019 -- Assume explicit Pure_Function means import is pure
5021 and then not Has_Pragma_Pure_Function
(E
)
5023 -- Don't need warning in relaxed semantics mode
5025 and then not Relaxed_RM_Semantics
5027 -- Assume convention Intrinsic is OK, since this is specialized.
5028 -- This deals with the DEC unit current_exception.ads
5030 and then Convention
(E
) /= Convention_Intrinsic
5032 -- Assume that ASM interface knows what it is doing
5034 and then Convention
(E
) /= Convention_Assembler
5037 ("pragma Import in Pure unit??", Import_Pragma
(E
));
5039 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
5040 Import_Pragma
(E
), E
);
5046 ------------------------
5047 -- Freeze_Record_Type --
5048 ------------------------
5050 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
5057 pragma Warnings
(Off
, Junk
);
5059 Aliased_Component
: Boolean := False;
5060 -- Set True if we find at least one component which is aliased. This
5061 -- is used to prevent Implicit_Packing of the record, since packing
5062 -- cannot modify the size of alignment of an aliased component.
5064 All_Elem_Components
: Boolean := True;
5065 -- True if all components are of a type whose underlying type is
5068 All_Sized_Components
: Boolean := True;
5069 -- True if all components have a known RM_Size
5071 All_Storage_Unit_Components
: Boolean := True;
5072 -- True if all components have an RM_Size that is a multiple of the
5075 Elem_Component_Total_Esize
: Uint
:= Uint_0
;
5076 -- Accumulates total Esize values of all elementary components. Used
5077 -- for processing of Implicit_Packing.
5079 Final_Storage_Only
: Boolean := True;
5080 -- Used to compute the Finalize_Storage_Only flag
5082 Placed_Component
: Boolean := False;
5083 -- Set True if we find at least one component with a component
5084 -- clause (used to warn about useless Bit_Order pragmas, and also
5085 -- to detect cases where Implicit_Packing may have an effect).
5087 Relaxed_Finalization
: Boolean := True;
5088 -- Used to compute the Has_Relaxed_Finalization flag
5090 Sized_Component_Total_RM_Size
: Uint
:= Uint_0
;
5091 -- Accumulates total RM_Size values of all sized components. Used
5092 -- for processing of Implicit_Packing.
5094 Sized_Component_Total_Round_RM_Size
: Uint
:= Uint_0
;
5095 -- Accumulates total RM_Size values of all sized components, rounded
5096 -- individually to a multiple of the storage unit.
5099 -- Scalar_Storage_Order attribute definition clause for the record
5101 SSO_ADC_Component
: Boolean := False;
5102 -- Set True if we find at least one component whose type has a
5103 -- Scalar_Storage_Order attribute definition clause.
5105 Unplaced_Component
: Boolean := False;
5106 -- Set True if we find at least one component with no component
5107 -- clause (used to warn about useless Pack pragmas).
5109 procedure Check_Itype
(Typ
: Entity_Id
);
5110 -- If the component subtype is an access to a constrained subtype of
5111 -- an already frozen type, make the subtype frozen as well. It might
5112 -- otherwise be frozen in the wrong scope, and a freeze node on
5113 -- subtype has no effect. Similarly, if the component subtype is a
5114 -- regular (not protected) access to subprogram, set the anonymous
5115 -- subprogram type to frozen as well, to prevent an out-of-scope
5116 -- freeze node at some eventual point of call. Protected operations
5117 -- are handled elsewhere.
5119 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
5120 -- Make sure that all types mentioned in Discrete_Choices of the
5121 -- variants referenceed by the Variant_Part VP are frozen. This is
5122 -- a recursive routine to deal with nested variants.
5128 procedure Check_Itype
(Typ
: Entity_Id
) is
5129 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
5132 if not Is_Frozen
(Desig
)
5133 and then Is_Frozen
(Base_Type
(Desig
))
5135 Set_Is_Frozen
(Desig
);
5137 -- In addition, add an Itype_Reference to ensure that the
5138 -- access subtype is elaborated early enough. This cannot be
5139 -- done if the subtype may depend on discriminants.
5141 if Ekind
(Comp
) = E_Component
5142 and then Is_Itype
(Etype
(Comp
))
5143 and then not Has_Discriminants
(Rec
)
5145 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
5146 Set_Itype
(IR
, Desig
);
5150 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
5151 and then Convention
(Desig
) /= Convention_Protected
5153 Set_Is_Frozen
(Desig
);
5154 Create_Extra_Formals
(Desig
);
5158 ------------------------------------
5159 -- Freeze_Choices_In_Variant_Part --
5160 ------------------------------------
5162 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
5163 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
5170 -- Loop through variants
5172 Variant
:= First_Non_Pragma
(Variants
(VP
));
5173 while Present
(Variant
) loop
5175 -- Loop through choices, checking that all types are frozen
5177 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
5178 while Present
(Choice
) loop
5179 if Nkind
(Choice
) in N_Has_Etype
5180 and then Present
(Etype
(Choice
))
5182 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
5185 Next_Non_Pragma
(Choice
);
5188 -- Check for nested variant part to process
5190 CL
:= Component_List
(Variant
);
5192 if not Null_Present
(CL
) then
5193 if Present
(Variant_Part
(CL
)) then
5194 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
5198 Next_Non_Pragma
(Variant
);
5200 end Freeze_Choices_In_Variant_Part
;
5202 -- Start of processing for Freeze_Record_Type
5205 -- Freeze components and embedded subtypes
5207 Comp
:= First_Entity
(Rec
);
5209 while Present
(Comp
) loop
5210 if Is_Aliased
(Comp
) then
5211 Aliased_Component
:= True;
5214 -- Handle the component and discriminant case
5216 if Ekind
(Comp
) in E_Component | E_Discriminant
then
5218 CC
: constant Node_Id
:= Component_Clause
(Comp
);
5221 -- Freezing a record type freezes the type of each of its
5222 -- components. However, if the type of the component is
5223 -- part of this record, we do not want or need a separate
5224 -- Freeze_Node. Note that Is_Itype is wrong because that's
5225 -- also set in private type cases. We also can't check for
5226 -- the Scope being exactly Rec because of private types and
5227 -- record extensions.
5229 if Is_Itype
(Etype
(Comp
))
5230 and then Is_Record_Type
(Underlying_Type
5231 (Scope
(Etype
(Comp
))))
5233 Undelay_Type
(Etype
(Comp
));
5236 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5238 -- Warn for pragma Pack overriding foreign convention
5240 if Has_Foreign_Convention
(Etype
(Comp
))
5241 and then Has_Pragma_Pack
(Rec
)
5243 -- Don't warn for aliased components, since override
5244 -- cannot happen in that case.
5246 and then not Is_Aliased
(Comp
)
5249 CN
: constant Name_Id
:=
5250 Get_Convention_Name
(Convention
(Etype
(Comp
)));
5251 PP
: constant Node_Id
:=
5252 Get_Pragma
(Rec
, Pragma_Pack
);
5254 if Present
(PP
) then
5255 Error_Msg_Name_1
:= CN
;
5256 Error_Msg_Sloc
:= Sloc
(Comp
);
5258 ("pragma Pack affects convention % component#??",
5260 Error_Msg_Name_1
:= CN
;
5262 ("\component & may not have % compatible "
5263 & "representation??", PP
, Comp
);
5268 -- Check for error of component clause given for variable
5269 -- sized type. We have to delay this test till this point,
5270 -- since the component type has to be frozen for us to know
5271 -- if it is variable length.
5273 if Present
(CC
) then
5274 Placed_Component
:= True;
5276 -- We omit this test in a generic context, it will be
5277 -- applied at instantiation time.
5279 if Inside_A_Generic
then
5282 -- Also omit this test in CodePeer mode, since we do not
5283 -- have sufficient info on size and rep clauses.
5285 elsif CodePeer_Mode
then
5291 Size_Known_At_Compile_Time
5292 (Underlying_Type
(Etype
(Comp
)))
5295 ("component clause not allowed for variable " &
5296 "length component", CC
);
5300 Unplaced_Component
:= True;
5303 -- Case of component requires byte alignment
5305 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
5307 -- Set the enclosing record to also require byte align
5309 Set_Must_Be_On_Byte_Boundary
(Rec
);
5311 -- Check for component clause that is inconsistent with
5312 -- the required byte boundary alignment.
5315 and then Normalized_First_Bit
(Comp
) mod
5316 System_Storage_Unit
/= 0
5319 ("component & must be byte aligned",
5320 Component_Name
(Component_Clause
(Comp
)));
5326 -- Gather data for possible Implicit_Packing later. Note that at
5327 -- this stage we might be dealing with a real component, or with
5328 -- an implicit subtype declaration.
5330 if Known_Static_RM_Size
(Etype
(Comp
)) then
5332 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
5333 Comp_Size
: constant Uint
:= RM_Size
(Comp_Type
);
5334 SSU
: constant Int
:= Ttypes
.System_Storage_Unit
;
5337 Sized_Component_Total_RM_Size
:=
5338 Sized_Component_Total_RM_Size
+ Comp_Size
;
5340 Sized_Component_Total_Round_RM_Size
:=
5341 Sized_Component_Total_Round_RM_Size
+
5342 (Comp_Size
+ SSU
- 1) / SSU
* SSU
;
5344 if Present
(Underlying_Type
(Comp_Type
))
5345 and then Is_Elementary_Type
(Underlying_Type
(Comp_Type
))
5347 Elem_Component_Total_Esize
:=
5348 Elem_Component_Total_Esize
+ Esize
(Comp_Type
);
5350 All_Elem_Components
:= False;
5352 if Comp_Size
mod SSU
/= 0 then
5353 All_Storage_Unit_Components
:= False;
5358 All_Sized_Components
:= False;
5361 -- If the component is an Itype with Delayed_Freeze and is either
5362 -- a record or array subtype and its base type has not yet been
5363 -- frozen, we must remove this from the entity list of this record
5364 -- and put it on the entity list of the scope of its base type.
5365 -- Note that we know that this is not the type of a component
5366 -- since we cleared Has_Delayed_Freeze for it in the previous
5367 -- loop. Thus this must be the Designated_Type of an access type,
5368 -- which is the type of a component.
5371 and then Is_Type
(Scope
(Comp
))
5372 and then Is_Composite_Type
(Comp
)
5373 and then Base_Type
(Comp
) /= Comp
5374 and then Has_Delayed_Freeze
(Comp
)
5375 and then not Is_Frozen
(Base_Type
(Comp
))
5378 Will_Be_Frozen
: Boolean := False;
5382 -- We have a difficult case to handle here. Suppose Rec is
5383 -- subtype being defined in a subprogram that's created as
5384 -- part of the freezing of Rec'Base. In that case, we know
5385 -- that Comp'Base must have already been frozen by the time
5386 -- we get to elaborate this because Gigi doesn't elaborate
5387 -- any bodies until it has elaborated all of the declarative
5388 -- part. But Is_Frozen will not be set at this point because
5389 -- we are processing code in lexical order.
5391 -- We detect this case by going up the Scope chain of Rec
5392 -- and seeing if we have a subprogram scope before reaching
5393 -- the top of the scope chain or that of Comp'Base. If we
5394 -- do, then mark that Comp'Base will actually be frozen. If
5395 -- so, we merely undelay it.
5398 while Present
(S
) loop
5399 if Is_Subprogram
(S
) then
5400 Will_Be_Frozen
:= True;
5402 elsif S
= Scope
(Base_Type
(Comp
)) then
5409 if Will_Be_Frozen
then
5410 Undelay_Type
(Comp
);
5413 if Present
(Prev
) then
5414 Link_Entities
(Prev
, Next_Entity
(Comp
));
5416 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
5419 -- Insert in entity list of scope of base type (which
5420 -- must be an enclosing scope, because still unfrozen).
5422 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
5426 -- If the component is an access type with an allocator as default
5427 -- value, the designated type will be frozen by the corresponding
5428 -- expression in init_proc. In order to place the freeze node for
5429 -- the designated type before that for the current record type,
5432 -- Same process if the component is an array of access types,
5433 -- initialized with an aggregate. If the designated type is
5434 -- private, it cannot contain allocators, and it is premature
5435 -- to freeze the type, so we check for this as well.
5437 elsif Is_Access_Type
(Etype
(Comp
))
5438 and then Present
(Parent
(Comp
))
5440 Nkind
(Parent
(Comp
))
5441 in N_Component_Declaration | N_Discriminant_Specification
5442 and then Present
(Expression
(Parent
(Comp
)))
5445 Alloc
: constant Node_Id
:=
5446 Unqualify
(Expression
(Parent
(Comp
)));
5449 if Nkind
(Alloc
) = N_Allocator
then
5451 -- If component is pointer to a class-wide type, freeze
5452 -- the specific type in the expression being allocated.
5453 -- The expression may be a subtype indication, in which
5454 -- case freeze the subtype mark.
5456 if Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp
)))
5458 if Is_Entity_Name
(Expression
(Alloc
)) then
5460 (Entity
(Expression
(Alloc
)), N
, Result
);
5462 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
5465 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
5468 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
5469 Check_Itype
(Etype
(Comp
));
5472 (Designated_Type
(Etype
(Comp
)), N
, Result
);
5476 elsif Is_Access_Type
(Etype
(Comp
))
5477 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
5479 Check_Itype
(Etype
(Comp
));
5481 -- Freeze the designated type when initializing a component with
5482 -- an aggregate in case the aggregate contains allocators.
5485 -- type T_Ptr is access all T;
5486 -- type T_Array is array ... of T_Ptr;
5488 -- type Rec is record
5489 -- Comp : T_Array := (others => ...);
5492 elsif Is_Array_Type
(Etype
(Comp
))
5493 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
5496 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
5497 Desig_Typ
: constant Entity_Id
:=
5499 (Component_Type
(Etype
(Comp
)));
5502 -- The only case when this sort of freezing is not done is
5503 -- when the designated type is class-wide and the root type
5504 -- is the record owning the component. This scenario results
5505 -- in a circularity because the class-wide type requires
5506 -- primitives that have not been created yet as the root
5507 -- type is in the process of being frozen.
5509 -- type Rec is tagged;
5510 -- type Rec_Ptr is access all Rec'Class;
5511 -- type Rec_Array is array ... of Rec_Ptr;
5513 -- type Rec is record
5514 -- Comp : Rec_Array := (others => ...);
5517 if Is_Class_Wide_Type
(Desig_Typ
)
5518 and then Root_Type
(Desig_Typ
) = Rec
5522 elsif Is_Fully_Defined
(Desig_Typ
)
5523 and then Present
(Comp_Par
)
5524 and then Nkind
(Comp_Par
) = N_Component_Declaration
5525 and then Present
(Expression
(Comp_Par
))
5526 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
5528 Freeze_And_Append
(Desig_Typ
, N
, Result
);
5538 Get_Attribute_Definition_Clause
5539 (Rec
, Attribute_Scalar_Storage_Order
);
5541 -- If the record type has Complex_Representation, then it is treated
5542 -- as a scalar in the back end so the storage order is irrelevant.
5544 if Has_Complex_Representation
(Rec
) then
5545 if Present
(SSO_ADC
) then
5547 ("??storage order has no effect with Complex_Representation",
5552 -- Deal with default setting of reverse storage order
5554 Set_SSO_From_Default
(Rec
);
5556 -- Check consistent attribute setting on component types
5559 Comp_ADC_Present
: Boolean;
5561 Comp
:= First_Component
(Rec
);
5562 while Present
(Comp
) loop
5563 Check_Component_Storage_Order
5567 Comp_ADC_Present
=> Comp_ADC_Present
);
5568 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
5569 Next_Component
(Comp
);
5573 -- Now deal with reverse storage order/bit order issues
5575 if Present
(SSO_ADC
) then
5577 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
5578 -- if the former is specified.
5580 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
5582 -- Note: report error on Rec, not on SSO_ADC, as ADC may
5583 -- apply to some ancestor type.
5585 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
5587 ("scalar storage order for& specified# inconsistent with "
5588 & "bit order", Rec
);
5591 -- Warn if there is a Scalar_Storage_Order attribute definition
5592 -- clause but no component clause, no component that itself has
5593 -- such an attribute definition, and no pragma Pack.
5595 if not (Placed_Component
5602 ("??scalar storage order specified but no component "
5603 & "clause", SSO_ADC
);
5608 -- Deal with Bit_Order aspect
5610 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
5612 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
5613 if not (Placed_Component
5614 or else Present
(SSO_ADC
)
5615 or else Is_Packed
(Rec
))
5617 -- Warn if clause has no effect when no component clause is
5618 -- present, but suppress warning if the Bit_Order is required
5619 -- due to the presence of a Scalar_Storage_Order attribute.
5622 ("??bit order specification has no effect", ADC
);
5624 ("\??since no component clauses were specified", ADC
);
5626 -- Here is where we do the processing to adjust component clauses
5627 -- for reversed bit order, when not using reverse SSO. If an error
5628 -- has been reported on Rec already (such as SSO incompatible with
5629 -- bit order), don't bother adjusting as this may generate extra
5632 elsif Reverse_Bit_Order
(Rec
)
5633 and then not Reverse_Storage_Order
(Rec
)
5634 and then not Error_Posted
(Rec
)
5636 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
5638 -- Case where we have both an explicit Bit_Order and the same
5639 -- Scalar_Storage_Order: leave record untouched, the back-end
5640 -- will take care of required layout conversions.
5648 -- Check for useless pragma Pack when all components placed. We only
5649 -- do this check for record types, not subtypes, since a subtype may
5650 -- have all its components placed, and it still makes perfectly good
5651 -- sense to pack other subtypes or the parent type. We do not give
5652 -- this warning if Optimize_Alignment is set to Space, since the
5653 -- pragma Pack does have an effect in this case (it always resets
5654 -- the alignment to one).
5656 if Ekind
(Rec
) = E_Record_Type
5657 and then Is_Packed
(Rec
)
5658 and then not Unplaced_Component
5659 and then Optimize_Alignment
/= 'S'
5661 -- Reset packed status. Probably not necessary, but we do it so
5662 -- that there is no chance of the back end doing something strange
5663 -- with this redundant indication of packing.
5665 Set_Is_Packed
(Rec
, False);
5667 -- Give warning if redundant constructs warnings on
5669 if Warn_On_Redundant_Constructs
then
5670 Error_Msg_N
-- CODEFIX
5671 ("?r?pragma Pack has no effect, no unplaced components",
5672 Get_Rep_Pragma
(Rec
, Name_Pack
));
5676 -- If this is the record corresponding to a remote type, freeze the
5677 -- remote type here since that is what we are semantically freezing.
5678 -- This prevents the freeze node for that type in an inner scope.
5680 if Ekind
(Rec
) = E_Record_Type
then
5681 if Present
(Corresponding_Remote_Type
(Rec
)) then
5682 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
5685 -- Check for tasks, protected and controlled components, unchecked
5686 -- unions, and type invariants.
5688 Comp
:= First_Component
(Rec
);
5689 while Present
(Comp
) loop
5690 Propagate_Concurrent_Flags
(Rec
, Etype
(Comp
));
5692 -- Do not set Has_Controlled_Component on a class-wide
5693 -- equivalent type. See Make_CW_Equivalent_Type.
5695 if not Is_Class_Wide_Equivalent_Type
(Rec
)
5697 (Has_Controlled_Component
(Etype
(Comp
))
5699 (Chars
(Comp
) /= Name_uParent
5700 and then Is_Controlled
(Etype
(Comp
)))
5702 (Is_Protected_Type
(Etype
(Comp
))
5704 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
5706 Has_Controlled_Component
5707 (Corresponding_Record_Type
(Etype
(Comp
)))))
5709 Set_Has_Controlled_Component
(Rec
);
5710 Final_Storage_Only
:=
5712 and then Finalize_Storage_Only
(Etype
(Comp
));
5713 Relaxed_Finalization
:=
5714 Relaxed_Finalization
5715 and then Has_Relaxed_Finalization
(Etype
(Comp
));
5718 if Has_Unchecked_Union
(Etype
(Comp
)) then
5719 Set_Has_Unchecked_Union
(Rec
);
5722 -- The record type requires its own invariant procedure in
5723 -- order to verify the invariant of each individual component.
5724 -- Do not consider internal components such as _parent because
5725 -- parent class-wide invariants are always inherited.
5726 -- In GNATprove mode, the component invariants are checked by
5727 -- other means. They should not be added to the record type
5728 -- invariant procedure, so that the procedure can be used to
5729 -- check the recordy type invariants if any.
5731 if Comes_From_Source
(Comp
)
5732 and then Has_Invariants
(Etype
(Comp
))
5733 and then not GNATprove_Mode
5735 Set_Has_Own_Invariants
(Rec
);
5738 -- Scan component declaration for likely misuses of current
5739 -- instance, either in a constraint or a default expression.
5741 if Has_Per_Object_Constraint
(Comp
) then
5742 Check_Current_Instance
(Parent
(Comp
));
5745 Next_Component
(Comp
);
5748 -- For a type that is not directly controlled but has controlled
5749 -- components, Finalize_Storage_Only is set if all the controlled
5750 -- components are Finalize_Storage_Only. The same processing is
5751 -- appled to Has_Relaxed_Finalization.
5753 if not Is_Controlled
(Rec
) and then Has_Controlled_Component
(Rec
)
5755 Set_Finalize_Storage_Only
(Rec
, Final_Storage_Only
);
5756 Set_Has_Relaxed_Finalization
(Rec
, Relaxed_Finalization
);
5760 -- Enforce the restriction that access attributes with a current
5761 -- instance prefix can only apply to limited types. This comment
5762 -- is floating here, but does not seem to belong here???
5764 -- Set component alignment if not otherwise already set
5766 Set_Component_Alignment_If_Not_Set
(Rec
);
5768 -- For first subtypes, check if there are any fixed-point fields with
5769 -- component clauses, where we must check the size. This is not done
5770 -- till the freeze point since for fixed-point types, we do not know
5771 -- the size until the type is frozen. Similar processing applies to
5772 -- bit-packed arrays.
5774 if Is_First_Subtype
(Rec
) then
5775 Comp
:= First_Component
(Rec
);
5776 while Present
(Comp
) loop
5777 if Present
(Component_Clause
(Comp
))
5778 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
5779 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
5782 (Component_Name
(Component_Clause
(Comp
)),
5788 Next_Component
(Comp
);
5792 -- See if Size is too small as is (and implicit packing might help)
5794 if not Is_Packed
(Rec
)
5796 -- No implicit packing if even one component is explicitly placed
5798 and then not Placed_Component
5800 -- Or even one component is aliased
5802 and then not Aliased_Component
5804 -- Must have size clause and all sized components
5806 and then Has_Size_Clause
(Rec
)
5807 and then All_Sized_Components
5809 -- Do not try implicit packing on records with discriminants, too
5810 -- complicated, especially in the variant record case.
5812 and then not Has_Discriminants
(Rec
)
5814 -- We want to implicitly pack if the specified size of the record
5815 -- is less than the sum of the object sizes (no point in packing
5816 -- if this is not the case), if we can compute it, i.e. if we have
5817 -- only elementary components. Otherwise, we have at least one
5818 -- composite component and we want to implicitly pack only if bit
5819 -- packing is required for it, as we are sure in this case that
5820 -- the back end cannot do the expected layout without packing.
5823 ((All_Elem_Components
5824 and then RM_Size
(Rec
) < Elem_Component_Total_Esize
)
5826 (not All_Elem_Components
5827 and then not All_Storage_Unit_Components
5828 and then RM_Size
(Rec
) < Sized_Component_Total_Round_RM_Size
))
5830 -- And the total RM size cannot be greater than the specified size
5831 -- since otherwise packing will not get us where we have to be.
5833 and then Sized_Component_Total_RM_Size
<= RM_Size
(Rec
)
5835 -- Never do implicit packing in CodePeer or SPARK modes since
5836 -- we don't do any packing in these modes, since this generates
5837 -- over-complex code that confuses static analysis, and in
5838 -- general, neither CodePeer not GNATprove care about the
5839 -- internal representation of objects.
5841 and then not (CodePeer_Mode
or GNATprove_Mode
)
5843 -- If implicit packing enabled, do it
5845 if Implicit_Packing
then
5846 Set_Is_Packed
(Rec
);
5848 -- Otherwise flag the size clause
5852 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
5854 Error_Msg_NE
-- CODEFIX
5855 ("size given for& too small", Sz
, Rec
);
5856 Error_Msg_N
-- CODEFIX
5857 ("\use explicit pragma Pack "
5858 & "or use pragma Implicit_Packing", Sz
);
5863 -- Make sure that if we have an iterator aspect, then we have
5864 -- either Constant_Indexing or Variable_Indexing.
5867 Iterator_Aspect
: Node_Id
;
5870 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
5872 if No
(Iterator_Aspect
) then
5873 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
5876 if Present
(Iterator_Aspect
) then
5877 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
5879 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
5884 ("Iterator_Element requires indexing aspect",
5890 -- All done if not a full record definition
5892 if Ekind
(Rec
) /= E_Record_Type
then
5896 -- Finally we need to check the variant part to make sure that
5897 -- all types within choices are properly frozen as part of the
5898 -- freezing of the record type.
5900 Check_Variant_Part
: declare
5901 D
: constant Node_Id
:= Declaration_Node
(Rec
);
5906 -- Find component list
5910 if Nkind
(D
) = N_Full_Type_Declaration
then
5911 T
:= Type_Definition
(D
);
5913 if Nkind
(T
) = N_Record_Definition
then
5914 C
:= Component_List
(T
);
5916 elsif Nkind
(T
) = N_Derived_Type_Definition
5917 and then Present
(Record_Extension_Part
(T
))
5919 C
:= Component_List
(Record_Extension_Part
(T
));
5923 -- Case of variant part present
5925 if Present
(C
) and then Present
(Variant_Part
(C
)) then
5926 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
5929 -- Note: we used to call Check_Choices here, but it is too early,
5930 -- since predicated subtypes are frozen here, but their freezing
5931 -- actions are in Analyze_Freeze_Entity, which has not been called
5932 -- yet for entities frozen within this procedure, so we moved that
5933 -- call to the Analyze_Freeze_Entity for the record type.
5935 end Check_Variant_Part
;
5937 -- Check that all the primitives of an interface type are abstract
5938 -- or null procedures.
5940 if Is_Interface
(Rec
)
5941 and then not Error_Posted
(Parent
(Rec
))
5948 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
5949 while Present
(Elmt
) loop
5950 Subp
:= Node
(Elmt
);
5952 if not Is_Abstract_Subprogram
(Subp
)
5954 -- Avoid reporting the error on inherited primitives
5956 and then Comes_From_Source
(Subp
)
5958 Error_Msg_Name_1
:= Chars
(Subp
);
5960 if Ekind
(Subp
) = E_Procedure
then
5961 if not Null_Present
(Parent
(Subp
)) then
5963 ("interface procedure % must be abstract or null",
5968 ("interface function % must be abstract",
5977 end Freeze_Record_Type
;
5979 -------------------------------
5980 -- Has_Boolean_Aspect_Import --
5981 -------------------------------
5983 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
5984 Decl
: constant Node_Id
:= Declaration_Node
(E
);
5989 if Has_Aspects
(Decl
) then
5990 Asp
:= First
(Aspect_Specifications
(Decl
));
5991 while Present
(Asp
) loop
5992 Expr
:= Expression
(Asp
);
5994 -- The value of aspect Import is True when the expression is
5995 -- either missing or it is explicitly set to True.
5997 if Get_Aspect_Id
(Asp
) = Aspect_Import
5999 or else (Compile_Time_Known_Value
(Expr
)
6000 and then Is_True
(Expr_Value
(Expr
))))
6010 end Has_Boolean_Aspect_Import
;
6012 -------------------------
6013 -- Inherit_Freeze_Node --
6014 -------------------------
6016 procedure Inherit_Freeze_Node
6020 Typ_Fnod
: constant Node_Id
:= Freeze_Node
(Typ
);
6023 Set_Freeze_Node
(Typ
, Fnod
);
6024 Set_Entity
(Fnod
, Typ
);
6026 -- The input type had an existing node. Propagate relevant attributes
6027 -- from the old freeze node to the inherited freeze node.
6029 -- ??? if both freeze nodes have attributes, would they differ?
6031 if Present
(Typ_Fnod
) then
6033 -- Attribute Access_Types_To_Process
6035 if Present
(Access_Types_To_Process
(Typ_Fnod
))
6036 and then No
(Access_Types_To_Process
(Fnod
))
6038 Set_Access_Types_To_Process
(Fnod
,
6039 Access_Types_To_Process
(Typ_Fnod
));
6042 -- Attribute Actions
6044 if Present
(Actions
(Typ_Fnod
)) and then No
(Actions
(Fnod
)) then
6045 Set_Actions
(Fnod
, Actions
(Typ_Fnod
));
6048 -- Attribute First_Subtype_Link
6050 if Present
(First_Subtype_Link
(Typ_Fnod
))
6051 and then No
(First_Subtype_Link
(Fnod
))
6053 Set_First_Subtype_Link
(Fnod
, First_Subtype_Link
(Typ_Fnod
));
6056 -- Attribute TSS_Elist
6058 if Present
(TSS_Elist
(Typ_Fnod
))
6059 and then No
(TSS_Elist
(Fnod
))
6061 Set_TSS_Elist
(Fnod
, TSS_Elist
(Typ_Fnod
));
6064 end Inherit_Freeze_Node
;
6066 ------------------------------
6067 -- Wrap_Imported_Subprogram --
6068 ------------------------------
6070 -- The issue here is that our normal approach of checking preconditions
6071 -- and postconditions does not work for imported procedures, since we
6072 -- are not generating code for the body. To get around this we create
6073 -- a wrapper, as shown by the following example:
6075 -- procedure K (A : Integer);
6076 -- pragma Import (C, K);
6078 -- The spec is rewritten by removing the effects of pragma Import, but
6079 -- leaving the convention unchanged, as though the source had said:
6081 -- procedure K (A : Integer);
6082 -- pragma Convention (C, K);
6084 -- and we create a body, added to the entity K freeze actions, which
6087 -- procedure K (A : Integer) is
6088 -- procedure K (A : Integer);
6089 -- pragma Import (C, K);
6094 -- Now the contract applies in the normal way to the outer procedure,
6095 -- and the inner procedure has no contracts, so there is no problem
6096 -- in just calling it to get the original effect.
6098 -- In the case of a function, we create an appropriate return statement
6099 -- for the subprogram body that calls the inner procedure.
6101 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
6102 function Copy_Import_Pragma
return Node_Id
;
6103 -- Obtain a copy of the Import_Pragma which belongs to subprogram E
6105 ------------------------
6106 -- Copy_Import_Pragma --
6107 ------------------------
6109 function Copy_Import_Pragma
return Node_Id
is
6111 -- The subprogram should have an import pragma, otherwise it does
6114 Prag
: constant Node_Id
:= Import_Pragma
(E
);
6115 pragma Assert
(Present
(Prag
));
6117 -- Save all semantic fields of the pragma
6119 Save_Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
6120 Save_From
: constant Boolean := From_Aspect_Specification
(Prag
);
6121 Save_Prag
: constant Node_Id
:= Next_Pragma
(Prag
);
6122 Save_Rep
: constant Node_Id
:= Next_Rep_Item
(Prag
);
6127 -- Reset all semantic fields. This avoids a potential infinite
6128 -- loop when the pragma comes from an aspect as the duplication
6129 -- will copy the aspect, then copy the corresponding pragma and
6132 Set_Corresponding_Aspect
(Prag
, Empty
);
6133 Set_From_Aspect_Specification
(Prag
, False);
6134 Set_Next_Pragma
(Prag
, Empty
);
6135 Set_Next_Rep_Item
(Prag
, Empty
);
6137 Result
:= Copy_Separate_Tree
(Prag
);
6139 -- Restore the original semantic fields
6141 Set_Corresponding_Aspect
(Prag
, Save_Asp
);
6142 Set_From_Aspect_Specification
(Prag
, Save_From
);
6143 Set_Next_Pragma
(Prag
, Save_Prag
);
6144 Set_Next_Rep_Item
(Prag
, Save_Rep
);
6147 end Copy_Import_Pragma
;
6151 Loc
: constant Source_Ptr
:= Sloc
(E
);
6152 CE
: constant Name_Id
:= Chars
(E
);
6160 -- Start of processing for Wrap_Imported_Subprogram
6163 -- Nothing to do if not imported
6165 if not Is_Imported
(E
) then
6168 -- Test enabling conditions for wrapping
6170 elsif Is_Subprogram
(E
)
6171 and then Present
(Contract
(E
))
6172 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
6173 and then not GNATprove_Mode
6175 -- Here we do the wrap
6177 Prag
:= Copy_Import_Pragma
;
6179 -- Fix up spec so it is no longer imported and has convention Ada
6181 Set_Has_Completion
(E
, False);
6182 Set_Import_Pragma
(E
, Empty
);
6183 Set_Interface_Name
(E
, Empty
);
6184 Set_Is_Imported
(E
, False);
6185 Set_Convention
(E
, Convention_Ada
);
6187 -- Grab the subprogram declaration and specification
6189 Spec
:= Declaration_Node
(E
);
6191 -- Build parameter list that we need
6194 Forml
:= First_Formal
(E
);
6195 while Present
(Forml
) loop
6196 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
6197 Next_Formal
(Forml
);
6202 -- An imported function whose result type is anonymous access
6203 -- creates a new anonymous access type when it is relocated into
6204 -- the declarations of the body generated below. As a result, the
6205 -- accessibility level of these two anonymous access types may not
6206 -- be compatible even though they are essentially the same type.
6207 -- Use an unchecked type conversion to reconcile this case. Note
6208 -- that the conversion is safe because in the named access type
6209 -- case, both the body and imported function utilize the same
6212 if Ekind
(E
) in E_Function | E_Generic_Function
then
6214 Make_Simple_Return_Statement
(Loc
,
6216 Unchecked_Convert_To
(Etype
(E
),
6217 Make_Function_Call
(Loc
,
6218 Name
=> Make_Identifier
(Loc
, CE
),
6219 Parameter_Associations
=> Parms
)));
6223 Make_Procedure_Call_Statement
(Loc
,
6224 Name
=> Make_Identifier
(Loc
, CE
),
6225 Parameter_Associations
=> Parms
);
6228 -- Now build the body
6231 Make_Subprogram_Body
(Loc
,
6232 Specification
=> Copy_Subprogram_Spec
(Spec
),
6233 Declarations
=> New_List
(
6234 Make_Subprogram_Declaration
(Loc
,
6235 Specification
=> Copy_Subprogram_Spec
(Spec
)),
6237 Handled_Statement_Sequence
=>
6238 Make_Handled_Sequence_Of_Statements
(Loc
,
6239 Statements
=> New_List
(Stmt
),
6240 End_Label
=> Make_Identifier
(Loc
, CE
)));
6242 -- Append the body to freeze result
6244 Add_To_Result
(Bod
);
6247 -- Case of imported subprogram that does not get wrapped
6250 -- Set Is_Public. All imported entities need an external symbol
6251 -- created for them since they are always referenced from another
6252 -- object file. Note this used to be set when we set Is_Imported
6253 -- back in Sem_Prag, but now we delay it to this point, since we
6254 -- don't want to set this flag if we wrap an imported subprogram.
6258 end Wrap_Imported_Subprogram
;
6260 -- Start of processing for Freeze_Entity
6263 -- The entity being frozen may be subject to pragma Ghost. Set the mode
6264 -- now to ensure that any nodes generated during freezing are properly
6265 -- flagged as Ghost.
6269 -- We are going to test for various reasons why this entity need not be
6270 -- frozen here, but in the case of an Itype that's defined within a
6271 -- record, that test actually applies to the record.
6273 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
6274 Test_E
:= Scope
(E
);
6276 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
6277 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
6279 Test_E
:= Underlying_Type
(Scope
(E
));
6282 -- Do not freeze if already frozen since we only need one freeze node
6284 if Is_Frozen
(E
) then
6287 and then not Is_Base_Type
(E
)
6288 and then not Is_Frozen
(Etype
(E
))
6290 -- If a frozen subtype of an unfrozen type seems impossible
6291 -- then see Analyze_Protected_Definition.Undelay_Itypes.
6293 Result
:= Freeze_Entity
6294 (Etype
(E
), N
, Do_Freeze_Profile
=> Do_Freeze_Profile
);
6301 -- Do not freeze if we are preanalyzing without freezing
6303 elsif Inside_Preanalysis_Without_Freezing
> 0 then
6307 elsif Ekind
(E
) = E_Generic_Package
then
6308 Result
:= Freeze_Generic_Entities
(E
);
6311 -- It is improper to freeze an external entity within a generic because
6312 -- its freeze node will appear in a non-valid context. The entity will
6313 -- be frozen in the proper scope after the current generic is analyzed.
6314 -- However, aspects must be analyzed because they may be queried later
6315 -- within the generic itself, and the corresponding pragma or attribute
6316 -- definition has not been analyzed yet. After this, indicate that the
6317 -- entity has no further delayed aspects, to prevent a later aspect
6318 -- analysis out of the scope of the generic.
6320 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
6321 if Has_Delayed_Aspects
(E
) then
6322 Analyze_Aspects_At_Freeze_Point
(E
);
6323 Set_Has_Delayed_Aspects
(E
, False);
6329 -- AI05-0213: A formal incomplete type does not freeze the actual. In
6330 -- the instance, the same applies to the subtype renaming the actual.
6332 elsif Is_Private_Type
(E
)
6333 and then Is_Generic_Actual_Type
(E
)
6334 and then No
(Full_View
(Base_Type
(E
)))
6335 and then Ada_Version
>= Ada_2012
6340 -- Formal subprograms are never frozen
6342 elsif Is_Formal_Subprogram
(E
) then
6346 -- Generic types are never frozen as they lack delayed semantic checks
6348 elsif Is_Generic_Type
(E
) then
6352 -- Do not freeze a global entity within an inner scope created during
6353 -- expansion. A call to subprogram E within some internal procedure
6354 -- (a stream attribute for example) might require freezing E, but the
6355 -- freeze node must appear in the same declarative part as E itself.
6356 -- The two-pass elaboration mechanism in gigi guarantees that E will
6357 -- be frozen before the inner call is elaborated. We exclude constants
6358 -- from this test, because deferred constants may be frozen early, and
6359 -- must be diagnosed (e.g. in the case of a deferred constant being used
6360 -- in a default expression). If the enclosing subprogram comes from
6361 -- source, or is a generic instance, then the freeze point is the one
6362 -- mandated by the language, and we freeze the entity. A subprogram that
6363 -- is a child unit body that acts as a spec does not have a spec that
6364 -- comes from source, but can only come from source.
6366 elsif In_Open_Scopes
(Scope
(Test_E
))
6367 and then Scope
(Test_E
) /= Current_Scope
6368 and then Ekind
(Test_E
) /= E_Constant
6370 -- Here we deal with the special case of the expansion of
6371 -- postconditions. Previously this was handled by the loop below,
6372 -- since these postcondition checks got isolated to a separate,
6373 -- internally generated, subprogram. Now, however, the postcondition
6374 -- checks get contained within their corresponding subprogram
6377 if not Comes_From_Source
(N
)
6378 and then Nkind
(N
) = N_Pragma
6379 and then From_Aspect_Specification
(N
)
6380 and then Is_Valid_Assertion_Kind
(Original_Aspect_Pragma_Name
(N
))
6382 -- Now, verify the placement of the pragma is within an expanded
6383 -- subprogram which contains postcondition expansion - detected
6384 -- through the presence of the "Wrapped_Statements" field.
6386 and then Present
(Enclosing_Subprogram
(Current_Scope
))
6387 and then Present
(Wrapped_Statements
6388 (Enclosing_Subprogram
(Current_Scope
)))
6393 -- Otherwise, loop through scopes checking if an enclosing scope
6394 -- comes from source or is a generic. Note that, for the purpose
6395 -- of this test, we need to consider that the internally generated
6396 -- subprogram described above comes from source too if the original
6397 -- subprogram itself does.
6404 while Present
(S
) loop
6405 if Is_Overloadable
(S
) then
6406 if Comes_From_Source
(S
)
6407 or else (Chars
(S
) = Name_uWrapped_Statements
6408 and then Comes_From_Source
(Scope
(S
)))
6409 or else Is_Generic_Instance
(S
)
6410 or else Is_Child_Unit
(S
)
6423 -- Similarly, an inlined instance body may make reference to global
6424 -- entities, but these references cannot be the proper freezing point
6425 -- for them, and in the absence of inlining freezing will take place in
6426 -- their own scope. Normally instance bodies are analyzed after the
6427 -- enclosing compilation, and everything has been frozen at the proper
6428 -- place, but with front-end inlining an instance body is compiled
6429 -- before the end of the enclosing scope, and as a result out-of-order
6430 -- freezing must be prevented.
6432 elsif Front_End_Inlining
6433 and then In_Instance_Body
6434 and then Present
(Scope
(Test_E
))
6440 S
:= Scope
(Test_E
);
6441 while Present
(S
) loop
6442 if Is_Generic_Instance
(S
) then
6456 -- Add checks to detect proper initialization of scalars that may appear
6457 -- as subprogram parameters.
6459 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
6460 Apply_Parameter_Validity_Checks
(E
);
6463 -- Deal with delayed aspect specifications. The analysis of the aspect
6464 -- is required to be delayed to the freeze point, thus we analyze the
6465 -- pragma or attribute definition clause in the tree at this point. We
6466 -- also analyze the aspect specification node at the freeze point when
6467 -- the aspect doesn't correspond to pragma/attribute definition clause.
6468 -- In addition, a derived type may have inherited aspects that were
6469 -- delayed in the parent, so these must also be captured now.
6471 -- For a record type, we deal with the delayed aspect specifications on
6472 -- components first, which is consistent with the non-delayed case and
6473 -- makes it possible to have a single processing to detect conflicts.
6475 if Is_Record_Type
(E
) then
6479 Rec_Pushed
: Boolean := False;
6480 -- Set True if the record type E has been pushed on the scope
6481 -- stack. Needed for the analysis of delayed aspects specified
6482 -- to the components of Rec.
6485 Comp
:= First_Component
(E
);
6486 while Present
(Comp
) loop
6487 if Has_Delayed_Aspects
(Comp
) then
6488 if not Rec_Pushed
then
6492 -- The visibility to the discriminants must be restored
6493 -- in order to properly analyze the aspects.
6495 if Has_Discriminants
(E
) then
6496 Install_Discriminants
(E
);
6500 Analyze_Aspects_At_Freeze_Point
(Comp
);
6503 Next_Component
(Comp
);
6506 -- Pop the scope if Rec scope has been pushed on the scope stack
6507 -- during the delayed aspect analysis process.
6510 if Has_Discriminants
(E
) then
6511 Uninstall_Discriminants
(E
);
6519 if Has_Delayed_Aspects
(E
) then
6520 Analyze_Aspects_At_Freeze_Point
(E
);
6523 -- Here to freeze the entity
6527 -- Case of entity being frozen is other than a type
6529 if not Is_Type
(E
) then
6531 -- If entity is exported or imported and does not have an external
6532 -- name, now is the time to provide the appropriate default name.
6533 -- Skip this if the entity is stubbed, since we don't need a name
6534 -- for any stubbed routine. For the case on intrinsics, if no
6535 -- external name is specified, then calls will be handled in
6536 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
6537 -- external name is provided, then Expand_Intrinsic_Call leaves
6538 -- calls in place for expansion by GIGI.
6540 if (Is_Imported
(E
) or else Is_Exported
(E
))
6541 and then No
(Interface_Name
(E
))
6542 and then Convention
(E
) /= Convention_Stubbed
6543 and then Convention
(E
) /= Convention_Intrinsic
6545 Set_Encoded_Interface_Name
6546 (E
, Get_Default_External_Name
(E
));
6551 if Is_Subprogram
(E
) then
6553 -- Check for needing to wrap imported subprogram
6555 if not Inside_A_Generic
then
6556 Wrap_Imported_Subprogram
(E
);
6559 -- Freeze all parameter types and the return type (RM 13.14(14)).
6560 -- However skip this for internal subprograms. This is also where
6561 -- any extra formal parameters are created since we now know
6562 -- whether the subprogram will use a foreign convention.
6564 -- In Ada 2012, freezing a subprogram does not always freeze the
6565 -- corresponding profile (see AI05-019). An attribute reference
6566 -- is not a freezing point of the profile. Similarly, we do not
6567 -- freeze the profile of primitives of a library-level tagged type
6568 -- when we are building its dispatch table. Flag Do_Freeze_Profile
6569 -- indicates whether the profile should be frozen now.
6571 -- This processing doesn't apply to internal entities (see below)
6573 if not Is_Internal
(E
) and then Do_Freeze_Profile
then
6574 if not Freeze_Profile
(E
) then
6579 -- Must freeze its parent first if it is a derived subprogram
6581 if Present
(Alias
(E
)) then
6582 Freeze_And_Append
(Alias
(E
), N
, Result
);
6585 -- We don't freeze internal subprograms, because we don't normally
6586 -- want addition of extra formals or mechanism setting to happen
6587 -- for those. However we do pass through predefined dispatching
6588 -- cases, since extra formals may be needed in some cases, such as
6589 -- for the stream 'Input function (build-in-place formals).
6591 if not Is_Internal
(E
)
6592 or else Is_Predefined_Dispatching_Operation
(E
)
6594 Freeze_Subprogram
(E
);
6597 -- If warning on suspicious contracts then check for the case of
6598 -- a postcondition other than False for a No_Return subprogram.
6601 and then Warn_On_Suspicious_Contract
6602 and then Present
(Contract
(E
))
6605 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
6609 while Present
(Prag
) loop
6610 if Pragma_Name_Unmapped
(Prag
) in Name_Post
6611 | Name_Postcondition
6616 (First
(Pragma_Argument_Associations
(Prag
)));
6618 if Nkind
(Exp
) /= N_Identifier
6619 or else Chars
(Exp
) /= Name_False
6622 ("useless postcondition, & is marked "
6623 & "No_Return?.t?", Exp
, E
);
6627 Prag
:= Next_Pragma
(Prag
);
6632 -- Here for other than a subprogram or type
6635 -- If entity has a type declared in the current scope, and it is
6636 -- not a generic unit, then freeze it first.
6638 if Present
(Etype
(E
))
6639 and then Ekind
(E
) /= E_Generic_Function
6640 and then Within_Scope
(Etype
(E
), Current_Scope
)
6642 Freeze_And_Append
(Etype
(E
), N
, Result
);
6644 -- For an object of an anonymous array type, aspects on the
6645 -- object declaration apply to the type itself. This is the
6646 -- case for Atomic_Components, Volatile_Components, and
6647 -- Independent_Components. In these cases analysis of the
6648 -- generated pragma will mark the anonymous types accordingly,
6649 -- and the object itself does not require a freeze node.
6651 if Ekind
(E
) = E_Variable
6652 and then Is_Itype
(Etype
(E
))
6653 and then Is_Array_Type
(Etype
(E
))
6654 and then Has_Delayed_Aspects
(E
)
6656 Set_Has_Delayed_Aspects
(E
, False);
6657 Set_Has_Delayed_Freeze
(E
, False);
6658 Set_Freeze_Node
(E
, Empty
);
6662 -- Special processing for objects created by object declaration;
6663 -- we protect the call to Declaration_Node against entities of
6664 -- expressions replaced by the frontend with an N_Raise_CE node.
6666 if Ekind
(E
) in E_Constant | E_Variable
6667 and then Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
6669 Freeze_Object_Declaration
(E
);
6672 -- Check that a constant which has a pragma Volatile[_Components]
6673 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
6675 -- Note: Atomic[_Components] also sets Volatile[_Components]
6677 if Ekind
(E
) = E_Constant
6678 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
6679 and then not Is_Imported
(E
)
6680 and then not Has_Boolean_Aspect_Import
(E
)
6682 -- Make sure we actually have a pragma, and have not merely
6683 -- inherited the indication from elsewhere (e.g. an address
6684 -- clause, which is not good enough in RM terms).
6686 if Has_Rep_Pragma
(E
, Name_Atomic
)
6688 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
6691 ("standalone atomic constant must be " &
6692 "imported (RM C.6(13))", E
);
6694 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
6696 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
6699 ("standalone volatile constant must be " &
6700 "imported (RM C.6(13))", E
);
6704 -- Static objects require special handling
6706 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
6707 and then Is_Statically_Allocated
(E
)
6709 Freeze_Static_Object
(E
);
6712 -- Remaining step is to layout objects
6714 if Ekind
(E
) in E_Variable | E_Constant | E_Loop_Parameter
6715 or else Is_Formal
(E
)
6720 -- For an object that does not have delayed freezing, and whose
6721 -- initialization actions have been captured in a compound
6722 -- statement, move them back now directly within the enclosing
6723 -- statement sequence.
6725 if Ekind
(E
) in E_Constant | E_Variable
6726 and then not Has_Delayed_Freeze
(E
)
6728 Explode_Initialization_Compound_Statement
(E
);
6731 -- Do not generate a freeze node for a generic unit
6733 if Is_Generic_Unit
(E
) then
6739 -- Case of a type or subtype being frozen
6742 -- Verify several SPARK legality rules related to Ghost types now
6743 -- that the type is frozen.
6745 Check_Ghost_Type
(E
);
6747 -- We used to check here that a full type must have preelaborable
6748 -- initialization if it completes a private type specified with
6749 -- pragma Preelaborable_Initialization, but that missed cases where
6750 -- the types occur within a generic package, since the freezing
6751 -- that occurs within a containing scope generally skips traversal
6752 -- of a generic unit's declarations (those will be frozen within
6753 -- instances). This check was moved to Analyze_Package_Specification.
6755 -- The type may be defined in a generic unit. This can occur when
6756 -- freezing a generic function that returns the type (which is
6757 -- defined in a parent unit). It is clearly meaningless to freeze
6758 -- this type. However, if it is a subtype, its size may be determi-
6759 -- nable and used in subsequent checks, so might as well try to
6762 -- In Ada 2012, Freeze_Entities is also used in the front end to
6763 -- trigger the analysis of aspect expressions, so in this case we
6764 -- want to continue the freezing process.
6766 -- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead
6767 -- In_Generic_Scope (E)???
6769 if Present
(Scope
(E
))
6770 and then Is_Generic_Unit
(Scope
(E
))
6772 (not Has_Predicates
(E
)
6773 and then not Has_Delayed_Freeze
(E
))
6775 Check_Compile_Time_Size
(E
);
6780 -- Check for error of Type_Invariant'Class applied to an untagged
6781 -- type (check delayed to freeze time when full type is available).
6784 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
6787 and then Class_Present
(Prag
)
6788 and then not Is_Tagged_Type
(E
)
6791 ("Type_Invariant''Class cannot be specified for &", Prag
, E
);
6793 ("\can only be specified for a tagged type", Prag
);
6797 -- Deal with special cases of freezing for subtype
6799 if E
/= Base_Type
(E
) then
6801 -- Before we do anything else, a specific test for the case of a
6802 -- size given for an array where the array would need to be packed
6803 -- in order for the size to be honored, but is not. This is the
6804 -- case where implicit packing may apply. The reason we do this so
6805 -- early is that, if we have implicit packing, the layout of the
6806 -- base type is affected, so we must do this before we freeze the
6809 -- We could do this processing only if implicit packing is enabled
6810 -- since in all other cases, the error would be caught by the back
6811 -- end. However, we choose to do the check even if we do not have
6812 -- implicit packing enabled, since this allows us to give a more
6813 -- useful error message (advising use of pragma Implicit_Packing
6816 if Is_Array_Type
(E
) then
6818 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
6819 Rsiz
: constant Uint
:=
6820 (if Known_RM_Size
(Ctyp
) then RM_Size
(Ctyp
) else Uint_0
);
6821 SZ
: constant Node_Id
:= Size_Clause
(E
);
6822 Btyp
: constant Entity_Id
:= Base_Type
(E
);
6829 Num_Elmts
: Uint
:= Uint_1
;
6830 -- Number of elements in array
6833 -- Check enabling conditions. These are straightforward
6834 -- except for the test for a limited composite type. This
6835 -- eliminates the rare case of a array of limited components
6836 -- where there are issues of whether or not we can go ahead
6837 -- and pack the array (since we can't freely pack and unpack
6838 -- arrays if they are limited).
6840 -- Note that we check the root type explicitly because the
6841 -- whole point is we are doing this test before we have had
6842 -- a chance to freeze the base type (and it is that freeze
6843 -- action that causes stuff to be inherited).
6845 -- The conditions on the size are identical to those used in
6846 -- Freeze_Array_Type to set the Is_Packed flag.
6848 if Has_Size_Clause
(E
)
6849 and then Known_Static_RM_Size
(E
)
6850 and then not Is_Packed
(E
)
6851 and then not Has_Pragma_Pack
(E
)
6852 and then not Has_Component_Size_Clause
(E
)
6853 and then Known_Static_RM_Size
(Ctyp
)
6854 and then Rsiz
<= System_Max_Integer_Size
6855 and then not (Addressable
(Rsiz
)
6856 and then Known_Static_Esize
(Ctyp
)
6857 and then Esize
(Ctyp
) = Rsiz
)
6858 and then not (Rsiz
mod System_Storage_Unit
= 0
6859 and then Is_Composite_Type
(Ctyp
))
6860 and then not Is_Limited_Composite
(E
)
6861 and then not Is_Packed
(Root_Type
(E
))
6862 and then not Has_Component_Size_Clause
(Root_Type
(E
))
6863 and then not (CodePeer_Mode
or GNATprove_Mode
)
6865 -- Compute number of elements in array
6867 Indx
:= First_Index
(E
);
6868 while Present
(Indx
) loop
6869 Get_Index_Bounds
(Indx
, Lo
, Hi
);
6871 if not (Compile_Time_Known_Value
(Lo
)
6873 Compile_Time_Known_Value
(Hi
))
6875 goto No_Implicit_Packing
;
6878 Dim
:= Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1;
6880 if Dim
> Uint_0
then
6881 Num_Elmts
:= Num_Elmts
* Dim
;
6883 Num_Elmts
:= Uint_0
;
6889 -- What we are looking for here is the situation where
6890 -- the RM_Size given would be exactly right if there was
6891 -- a pragma Pack, resulting in the component size being
6892 -- the RM_Size of the component type.
6894 if RM_Size
(E
) = Num_Elmts
* Rsiz
then
6896 -- For implicit packing mode, just set the component
6897 -- size and Freeze_Array_Type will do the rest.
6899 if Implicit_Packing
then
6900 Set_Component_Size
(Btyp
, Rsiz
);
6902 -- Otherwise give an error message, except that if the
6903 -- specified Size is zero, there is no need for pragma
6904 -- Pack. Note that size zero is not considered
6907 elsif RM_Size
(E
) /= Uint_0
then
6909 ("size given for& too small", SZ
, E
);
6910 Error_Msg_N
-- CODEFIX
6911 ("\use explicit pragma Pack or use pragma "
6912 & "Implicit_Packing", SZ
);
6919 <<No_Implicit_Packing
>>
6921 -- If ancestor subtype present, freeze that first. Note that this
6922 -- will also get the base type frozen. Need RM reference ???
6924 Atype
:= Ancestor_Subtype
(E
);
6926 if Present
(Atype
) then
6927 Freeze_And_Append
(Atype
, N
, Result
);
6929 -- No ancestor subtype present
6932 -- See if we have a nearest ancestor that has a predicate.
6933 -- That catches the case of derived type with a predicate.
6934 -- Need RM reference here ???
6936 Atype
:= Nearest_Ancestor
(E
);
6938 if Present
(Atype
) and then Has_Predicates
(Atype
) then
6939 Freeze_And_Append
(Atype
, N
, Result
);
6942 -- Freeze base type before freezing the entity (RM 13.14(15))
6944 if E
/= Base_Type
(E
) then
6945 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
6949 -- A subtype inherits all the type-related representation aspects
6950 -- from its parents (RM 13.1(8)).
6952 if May_Inherit_Delayed_Rep_Aspects
(E
) then
6953 Inherit_Delayed_Rep_Aspects
(E
);
6956 Inherit_Aspects_At_Freeze_Point
(E
);
6958 -- For a derived type, freeze its parent type first (RM 13.14(15))
6960 elsif Is_Derived_Type
(E
) then
6961 Freeze_And_Append
(Etype
(E
), N
, Result
);
6963 -- A derived type inherits each type-related representation aspect
6964 -- of its parent type that was directly specified before the
6965 -- declaration of the derived type (RM 13.1(15)).
6967 if May_Inherit_Delayed_Rep_Aspects
(E
) then
6968 Inherit_Delayed_Rep_Aspects
(E
);
6971 Inherit_Aspects_At_Freeze_Point
(E
);
6974 -- Case of array type
6976 if Is_Array_Type
(E
) then
6977 Freeze_Array_Type
(E
);
6980 -- Check for incompatible size and alignment for array/record type
6982 if Warn_On_Size_Alignment
6983 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
6984 and then Has_Size_Clause
(E
)
6985 and then Has_Alignment_Clause
(E
)
6987 -- If explicit Object_Size clause given assume that the programmer
6988 -- knows what he is doing, and expects the compiler behavior.
6990 and then not Has_Object_Size_Clause
(E
)
6992 -- It does not really make sense to warn for the minimum alignment
6993 -- since the programmer could not get rid of the warning.
6995 and then Alignment
(E
) > 1
6997 -- Check for size not a multiple of alignment
6999 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
7002 SC
: constant Node_Id
:= Size_Clause
(E
);
7003 AC
: constant Node_Id
:= Alignment_Clause
(E
);
7005 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
7008 if Present
(SC
) and then Present
(AC
) then
7012 if Sloc
(SC
) > Sloc
(AC
) then
7015 ("?.z?size is not a multiple of alignment for &",
7017 Error_Msg_Sloc
:= Sloc
(AC
);
7018 Error_Msg_Uint_1
:= Alignment
(E
);
7019 Error_Msg_N
("\?.z?alignment of ^ specified #", Loc
);
7024 ("?.z?size is not a multiple of alignment for &",
7026 Error_Msg_Sloc
:= Sloc
(SC
);
7027 Error_Msg_Uint_1
:= RM_Size
(E
);
7028 Error_Msg_N
("\?.z?size of ^ specified #", Loc
);
7031 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
7032 Error_Msg_N
("\?.z?Object_Size will be increased to ^", Loc
);
7037 -- For a class-wide type, the corresponding specific type is
7038 -- frozen as well (RM 13.14(15))
7040 if Is_Class_Wide_Type
(E
) then
7041 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
7043 -- If the base type of the class-wide type is still incomplete,
7044 -- the class-wide remains unfrozen as well. This is legal when
7045 -- E is the formal of a primitive operation of some other type
7046 -- which is being frozen.
7048 if not Is_Frozen
(Root_Type
(E
)) then
7049 Set_Is_Frozen
(E
, False);
7053 -- The equivalent type associated with a class-wide subtype needs
7054 -- to be frozen to ensure that its layout is done.
7056 if Ekind
(E
) = E_Class_Wide_Subtype
7057 and then Present
(Equivalent_Type
(E
))
7059 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
7062 -- Generate an itype reference for a library-level class-wide type
7063 -- at the freeze point. Otherwise the first explicit reference to
7064 -- the type may appear in an inner scope which will be rejected by
7068 and then Is_Compilation_Unit
(Scope
(E
))
7071 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
7076 -- From a gigi point of view, a class-wide subtype derives
7077 -- from its record equivalent type. As a result, the itype
7078 -- reference must appear after the freeze node of the
7079 -- equivalent type or gigi will reject the reference.
7081 if Ekind
(E
) = E_Class_Wide_Subtype
7082 and then Present
(Equivalent_Type
(E
))
7084 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
7086 Add_To_Result
(Ref
);
7091 -- For a record type or record subtype, freeze all component types
7092 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
7093 -- using Is_Record_Type, because we don't want to attempt the freeze
7094 -- for the case of a private type with record extension (we will do
7095 -- that later when the full type is frozen).
7097 elsif Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
7098 if not In_Generic_Scope
(E
) then
7099 Freeze_Record_Type
(E
);
7102 -- Report a warning if a discriminated record base type has a
7103 -- convention with language C or C++ applied to it. This check is
7104 -- done even within generic scopes (but not in instantiations),
7105 -- which is why we don't do it as part of Freeze_Record_Type.
7107 Check_Suspicious_Convention
(E
);
7109 -- For a concurrent type, freeze corresponding record type. This does
7110 -- not correspond to any specific rule in the RM, but the record type
7111 -- is essentially part of the concurrent type. Also freeze all local
7112 -- entities. This includes record types created for entry parameter
7113 -- blocks and whatever local entities may appear in the private part.
7115 elsif Is_Concurrent_Type
(E
) then
7116 if Present
(Corresponding_Record_Type
(E
)) then
7117 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
7120 Comp
:= First_Entity
(E
);
7121 while Present
(Comp
) loop
7122 if Is_Type
(Comp
) then
7123 Freeze_And_Append
(Comp
, N
, Result
);
7125 elsif Ekind
(Comp
) /= E_Function
then
7127 -- The guard on the presence of the Etype seems to be needed
7128 -- for some CodePeer (-gnatcC) cases, but not clear why???
7130 if Present
(Etype
(Comp
)) then
7131 if Is_Itype
(Etype
(Comp
))
7132 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
7134 Undelay_Type
(Etype
(Comp
));
7137 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
7144 -- Private types are required to point to the same freeze node as
7145 -- their corresponding full views. The freeze node itself has to
7146 -- point to the partial view of the entity (because from the partial
7147 -- view, we can retrieve the full view, but not the reverse).
7148 -- However, in order to freeze correctly, we need to freeze the full
7149 -- view. If we are freezing at the end of a scope (or within the
7150 -- scope) of the private type, the partial and full views will have
7151 -- been swapped, the full view appears first in the entity chain and
7152 -- the swapping mechanism ensures that the pointers are properly set
7155 -- If we encounter the partial view before the full view (e.g. when
7156 -- freezing from another scope), we freeze the full view, and then
7157 -- set the pointers appropriately since we cannot rely on swapping to
7158 -- fix things up (subtypes in an outer scope might not get swapped).
7160 -- If the full view is itself private, the above requirements apply
7161 -- to the underlying full view instead of the full view. But there is
7162 -- no swapping mechanism for the underlying full view so we need to
7163 -- set the pointers appropriately in both cases.
7165 elsif Is_Incomplete_Or_Private_Type
(E
)
7166 and then not Is_Generic_Type
(E
)
7168 -- The construction of the dispatch table associated with library
7169 -- level tagged types forces freezing of all the primitives of the
7170 -- type, which may cause premature freezing of the partial view.
7174 -- type T is tagged private;
7175 -- type DT is new T with private;
7176 -- procedure Prim (X : in out T; Y : in out DT'Class);
7178 -- type T is tagged null record;
7180 -- type DT is new T with null record;
7183 -- In this case the type will be frozen later by the usual
7184 -- mechanism: an object declaration, an instantiation, or the
7185 -- end of a declarative part.
7187 if Is_Library_Level_Tagged_Type
(E
)
7188 and then No
(Full_View
(E
))
7190 Set_Is_Frozen
(E
, False);
7193 -- Case of full view present
7195 elsif Present
(Full_View
(E
)) then
7197 -- If full view has already been frozen, then no further
7198 -- processing is required
7200 if Is_Frozen
(Full_View
(E
)) then
7201 Set_Has_Delayed_Freeze
(E
, False);
7202 Set_Freeze_Node
(E
, Empty
);
7204 -- Otherwise freeze full view and patch the pointers so that
7205 -- the freeze node will elaborate both views in the back end.
7206 -- However, if full view is itself private, freeze underlying
7207 -- full view instead and patch the pointers so that the freeze
7208 -- node will elaborate the three views in the back end.
7212 Full
: Entity_Id
:= Full_View
(E
);
7215 if Is_Private_Type
(Full
)
7216 and then Present
(Underlying_Full_View
(Full
))
7218 Full
:= Underlying_Full_View
(Full
);
7221 Freeze_And_Append
(Full
, N
, Result
);
7223 if Full
/= Full_View
(E
)
7224 and then Has_Delayed_Freeze
(Full_View
(E
))
7226 F_Node
:= Freeze_Node
(Full
);
7228 if Present
(F_Node
) then
7230 (Fnod
=> F_Node
, Typ
=> Full_View
(E
));
7232 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
7233 Set_Freeze_Node
(Full_View
(E
), Empty
);
7237 if Has_Delayed_Freeze
(E
) then
7238 F_Node
:= Freeze_Node
(Full_View
(E
));
7240 if Present
(F_Node
) then
7241 Inherit_Freeze_Node
(Fnod
=> F_Node
, Typ
=> E
);
7243 -- {Incomplete,Private}_Subtypes with Full_Views
7244 -- constrained by discriminants.
7246 Set_Has_Delayed_Freeze
(E
, False);
7247 Set_Freeze_Node
(E
, Empty
);
7253 Check_Debug_Info_Needed
(E
);
7255 -- AI95-117 requires that the convention of a partial view be
7256 -- the same as the convention of the full view. Note that this
7257 -- is a recognized breach of privacy, but it's essential for
7258 -- logical consistency of representation, and the lack of a
7259 -- rule in RM95 was an oversight.
7261 Set_Convention
(E
, Convention
(Full_View
(E
)));
7263 Set_Size_Known_At_Compile_Time
(E
,
7264 Size_Known_At_Compile_Time
(Full_View
(E
)));
7266 -- Size information is copied from the full view to the
7267 -- incomplete or private view for consistency.
7269 -- We skip this is the full view is not a type. This is very
7270 -- strange of course, and can only happen as a result of
7271 -- certain illegalities, such as a premature attempt to derive
7272 -- from an incomplete type.
7274 if Is_Type
(Full_View
(E
)) then
7275 Set_Size_Info
(E
, Full_View
(E
));
7276 Copy_RM_Size
(To
=> E
, From
=> Full_View
(E
));
7281 -- Case of underlying full view present
7283 elsif Is_Private_Type
(E
)
7284 and then Present
(Underlying_Full_View
(E
))
7286 if not Is_Frozen
(Underlying_Full_View
(E
)) then
7287 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
7290 -- Patch the pointers so that the freeze node will elaborate
7291 -- both views in the back end.
7293 if Has_Delayed_Freeze
(E
) then
7294 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
7296 if Present
(F_Node
) then
7301 Set_Has_Delayed_Freeze
(E
, False);
7302 Set_Freeze_Node
(E
, Empty
);
7306 Check_Debug_Info_Needed
(E
);
7310 -- Case of no full view present. If entity is subtype or derived,
7311 -- it is safe to freeze, correctness depends on the frozen status
7312 -- of parent. Otherwise it is either premature usage, or a Taft
7313 -- amendment type, so diagnosis is at the point of use and the
7314 -- type might be frozen later.
7316 elsif E
/= Base_Type
(E
) then
7318 Btyp
: constant Entity_Id
:= Base_Type
(E
);
7321 -- However, if the base type is itself private and has no
7322 -- (underlying) full view either, wait until the full type
7323 -- declaration is seen and all the full views are created.
7325 if Is_Private_Type
(Btyp
)
7326 and then No
(Full_View
(Btyp
))
7327 and then No
(Underlying_Full_View
(Btyp
))
7328 and then Has_Delayed_Freeze
(Btyp
)
7329 and then No
(Freeze_Node
(Btyp
))
7331 Set_Is_Frozen
(E
, False);
7337 elsif Is_Derived_Type
(E
) then
7341 Set_Is_Frozen
(E
, False);
7346 -- For access subprogram, freeze types of all formals, the return
7347 -- type was already frozen, since it is the Etype of the function.
7348 -- Formal types can be tagged Taft amendment types, but otherwise
7349 -- they cannot be incomplete.
7351 elsif Ekind
(E
) = E_Subprogram_Type
then
7352 Formal
:= First_Formal
(E
);
7353 while Present
(Formal
) loop
7354 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
7355 and then No
(Full_View
(Etype
(Formal
)))
7357 if Is_Tagged_Type
(Etype
(Formal
)) then
7360 -- AI05-151: Incomplete types are allowed in access to
7361 -- subprogram specifications.
7363 elsif Ada_Version
< Ada_2012
then
7365 ("invalid use of incomplete type&", E
, Etype
(Formal
));
7369 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
7370 Next_Formal
(Formal
);
7373 Freeze_Subprogram
(E
);
7375 -- For access to a protected subprogram, freeze the equivalent type
7376 -- (however this is not set if we are not generating code or if this
7377 -- is an anonymous type used just for resolution).
7379 elsif Is_Access_Protected_Subprogram_Type
(E
) then
7380 if Present
(Equivalent_Type
(E
)) then
7381 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
7385 -- Generic types are never seen by the back-end, and are also not
7386 -- processed by the expander (since the expander is turned off for
7387 -- generic processing), so we never need freeze nodes for them.
7389 if Is_Generic_Type
(E
) then
7393 -- Some special processing for non-generic types to complete
7394 -- representation details not known till the freeze point.
7396 if Is_Fixed_Point_Type
(E
) then
7397 Freeze_Fixed_Point_Type
(E
);
7399 elsif Is_Enumeration_Type
(E
) then
7400 Freeze_Enumeration_Type
(E
);
7402 elsif Is_Integer_Type
(E
) then
7403 Adjust_Esize_For_Alignment
(E
);
7405 if Is_Modular_Integer_Type
(E
) then
7406 -- Standard_Address has been built with the assumption that its
7407 -- modulus was System_Address_Size, but this is not a universal
7408 -- property and may need to be corrected.
7410 if Is_RTE
(E
, RE_Address
) then
7411 Set_Modulus
(Standard_Address
, Modulus
(E
));
7413 (High_Bound
(Scalar_Range
(Standard_Address
)),
7416 elsif Warn_On_Suspicious_Modulus_Value
then
7417 Check_Suspicious_Modulus
(E
);
7421 -- The pool applies to named and anonymous access types, but not
7422 -- to subprogram and to internal types generated for 'Access
7425 elsif Is_Access_Object_Type
(E
)
7426 and then Ekind
(E
) /= E_Access_Attribute_Type
7428 -- If a pragma Default_Storage_Pool applies, and this type has no
7429 -- Storage_Pool or Storage_Size clause (which must have occurred
7430 -- before the freezing point), then use the default. This applies
7431 -- only to base types.
7433 -- None of this applies to access to subprograms, for which there
7434 -- are clearly no pools.
7436 if Present
(Default_Pool
)
7437 and then Is_Base_Type
(E
)
7438 and then not Has_Storage_Size_Clause
(E
)
7439 and then No
(Associated_Storage_Pool
(E
))
7441 -- Case of pragma Default_Storage_Pool (null)
7443 if Nkind
(Default_Pool
) = N_Null
then
7444 Set_No_Pool_Assigned
(E
);
7446 -- Case of pragma Default_Storage_Pool (Standard)
7448 elsif Entity
(Default_Pool
) = Standard_Standard
then
7449 Set_Associated_Storage_Pool
(E
, RTE
(RE_Global_Pool_Object
));
7451 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
7454 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
7458 -- Check restriction for standard storage pool
7460 if No
(Associated_Storage_Pool
(E
)) then
7461 Check_Restriction
(No_Standard_Storage_Pools
, E
);
7464 -- Deal with error message for pure access type. This is not an
7465 -- error in Ada 2005 if there is no pool (see AI-366).
7467 if Is_Pure_Unit_Access_Type
(E
)
7468 and then (Ada_Version
< Ada_2005
7469 or else not No_Pool_Assigned
(E
))
7470 and then not Is_Generic_Unit
(Scope
(E
))
7472 Error_Msg_N
("named access type not allowed in pure unit", E
);
7474 if Ada_Version
>= Ada_2005
then
7476 ("\would be legal if Storage_Size of 0 given??", E
);
7478 elsif No_Pool_Assigned
(E
) then
7480 ("\would be legal in Ada 2005??", E
);
7484 ("\would be legal in Ada 2005 if "
7485 & "Storage_Size of 0 given??", E
);
7490 -- Case of composite types
7492 if Is_Composite_Type
(E
) then
7494 -- AI95-117 requires that all new primitives of a tagged type
7495 -- must inherit the convention of the full view of the
7496 -- type. Inherited and overriding operations are defined to
7497 -- inherit the convention of their parent or overridden
7498 -- subprogram (also specified in AI-117), which will have
7499 -- occurred earlier (in Derive_Subprogram and
7500 -- New_Overloaded_Entity). Here we set the convention of
7501 -- primitives that are still convention Ada, which will ensure
7502 -- that any new primitives inherit the type's convention. We
7503 -- don't do this for primitives that are internal to avoid
7504 -- potential problems in the case of nested subprograms and
7505 -- convention C. In addition, class-wide types can have a
7506 -- foreign convention inherited from their specific type, but
7507 -- are excluded from this since they don't have any associated
7510 if Is_Tagged_Type
(E
)
7511 and then not Is_Class_Wide_Type
(E
)
7512 and then Convention
(E
) /= Convention_Ada
7515 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
7519 Prim
:= First_Elmt
(Prim_List
);
7520 while Present
(Prim
) loop
7521 if Convention
(Node
(Prim
)) = Convention_Ada
7522 and then Comes_From_Source
(Node
(Prim
))
7524 Set_Convention
(Node
(Prim
), Convention
(E
));
7532 -- If the type is a simple storage pool type, then this is where
7533 -- we attempt to locate and validate its Allocate, Deallocate, and
7534 -- Storage_Size operations (the first is required, and the latter
7535 -- two are optional). We also verify that the full type for a
7536 -- private type is allowed to be a simple storage pool type.
7538 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
7539 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
7541 -- If the type is marked Has_Private_Declaration, then this is
7542 -- a full type for a private type that was specified with the
7543 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
7544 -- pragma is allowed for the full type (for example, it can't
7545 -- be an array type, or a nonlimited record type).
7547 if Has_Private_Declaration
(E
) then
7548 if (not Is_Record_Type
(E
)
7549 or else not Is_Inherently_Limited_Type
(E
))
7550 and then not Is_Private_Type
(E
)
7552 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
7554 ("pragma% can only apply to full type that is an " &
7555 "explicitly limited type", E
);
7559 Validate_Simple_Pool_Ops
: declare
7560 Pool_Type
: Entity_Id
renames E
;
7561 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
7562 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
7564 procedure Validate_Simple_Pool_Op_Formal
7565 (Pool_Op
: Entity_Id
;
7566 Pool_Op_Formal
: in out Entity_Id
;
7567 Expected_Mode
: Formal_Kind
;
7568 Expected_Type
: Entity_Id
;
7569 Formal_Name
: String;
7570 OK_Formal
: in out Boolean);
7571 -- Validate one formal Pool_Op_Formal of the candidate pool
7572 -- operation Pool_Op. The formal must be of Expected_Type
7573 -- and have mode Expected_Mode. OK_Formal will be set to
7574 -- False if the formal doesn't match. If OK_Formal is False
7575 -- on entry, then the formal will effectively be ignored
7576 -- (because validation of the pool op has already failed).
7577 -- Upon return, Pool_Op_Formal will be updated to the next
7580 procedure Validate_Simple_Pool_Operation
7581 (Op_Name
: Name_Id
);
7582 -- Search for and validate a simple pool operation with the
7583 -- name Op_Name. If the name is Allocate, then there must be
7584 -- exactly one such primitive operation for the simple pool
7585 -- type. If the name is Deallocate or Storage_Size, then
7586 -- there can be at most one such primitive operation. The
7587 -- profile of the located primitive must conform to what
7588 -- is expected for each operation.
7590 ------------------------------------
7591 -- Validate_Simple_Pool_Op_Formal --
7592 ------------------------------------
7594 procedure Validate_Simple_Pool_Op_Formal
7595 (Pool_Op
: Entity_Id
;
7596 Pool_Op_Formal
: in out Entity_Id
;
7597 Expected_Mode
: Formal_Kind
;
7598 Expected_Type
: Entity_Id
;
7599 Formal_Name
: String;
7600 OK_Formal
: in out Boolean)
7603 -- If OK_Formal is False on entry, then simply ignore
7604 -- the formal, because an earlier formal has already
7607 if not OK_Formal
then
7610 -- If no formal is passed in, then issue an error for a
7613 elsif No
(Pool_Op_Formal
) then
7615 ("simple storage pool op missing formal " &
7616 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
7622 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
7624 -- If the pool type was expected for this formal, then
7625 -- this will not be considered a candidate operation
7626 -- for the simple pool, so we unset OK_Formal so that
7627 -- the op and any later formals will be ignored.
7629 if Expected_Type
= Pool_Type
then
7636 ("wrong type for formal " & Formal_Name
&
7637 " of simple storage pool op; expected type&",
7638 Pool_Op_Formal
, Expected_Type
);
7642 -- Issue error if formal's mode is not the expected one
7644 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
7646 ("wrong mode for formal of simple storage pool op",
7650 -- Advance to the next formal
7652 Next_Formal
(Pool_Op_Formal
);
7653 end Validate_Simple_Pool_Op_Formal
;
7655 ------------------------------------
7656 -- Validate_Simple_Pool_Operation --
7657 ------------------------------------
7659 procedure Validate_Simple_Pool_Operation
7663 Found_Op
: Entity_Id
:= Empty
;
7669 (Op_Name
in Name_Allocate
7671 | Name_Storage_Size
);
7673 Error_Msg_Name_1
:= Op_Name
;
7675 -- For each homonym declared immediately in the scope
7676 -- of the simple storage pool type, determine whether
7677 -- the homonym is an operation of the pool type, and,
7678 -- if so, check that its profile is as expected for
7679 -- a simple pool operation of that name.
7681 Op
:= Get_Name_Entity_Id
(Op_Name
);
7682 while Present
(Op
) loop
7683 if Ekind
(Op
) in E_Function | E_Procedure
7684 and then Scope
(Op
) = Current_Scope
7686 Formal
:= First_Entity
(Op
);
7690 -- The first parameter must be of the pool type
7691 -- in order for the operation to qualify.
7693 if Op_Name
= Name_Storage_Size
then
7694 Validate_Simple_Pool_Op_Formal
7695 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
7698 Validate_Simple_Pool_Op_Formal
7699 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
7703 -- If another operation with this name has already
7704 -- been located for the type, then flag an error,
7705 -- since we only allow the type to have a single
7708 if Present
(Found_Op
) and then Is_OK
then
7710 ("only one % operation allowed for " &
7711 "simple storage pool type&", Op
, Pool_Type
);
7714 -- In the case of Allocate and Deallocate, a formal
7715 -- of type System.Address is required.
7717 if Op_Name
= Name_Allocate
then
7718 Validate_Simple_Pool_Op_Formal
7719 (Op
, Formal
, E_Out_Parameter
,
7720 Address_Type
, "Storage_Address", Is_OK
);
7722 elsif Op_Name
= Name_Deallocate
then
7723 Validate_Simple_Pool_Op_Formal
7724 (Op
, Formal
, E_In_Parameter
,
7725 Address_Type
, "Storage_Address", Is_OK
);
7728 -- In the case of Allocate and Deallocate, formals
7729 -- of type Storage_Count are required as the third
7730 -- and fourth parameters.
7732 if Op_Name
/= Name_Storage_Size
then
7733 Validate_Simple_Pool_Op_Formal
7734 (Op
, Formal
, E_In_Parameter
,
7735 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
7736 Validate_Simple_Pool_Op_Formal
7737 (Op
, Formal
, E_In_Parameter
,
7738 Stg_Cnt_Type
, "Alignment", Is_OK
);
7741 -- If no mismatched formals have been found (Is_OK)
7742 -- and no excess formals are present, then this
7743 -- operation has been validated, so record it.
7745 if No
(Formal
) and then Is_OK
then
7753 -- There must be a valid Allocate operation for the type,
7754 -- so issue an error if none was found.
7756 if Op_Name
= Name_Allocate
7757 and then No
(Found_Op
)
7759 Error_Msg_N
("missing % operation for simple " &
7760 "storage pool type", Pool_Type
);
7762 elsif Present
(Found_Op
) then
7764 -- Simple pool operations can't be abstract
7766 if Is_Abstract_Subprogram
(Found_Op
) then
7768 ("simple storage pool operation must not be " &
7769 "abstract", Found_Op
);
7772 -- The Storage_Size operation must be a function with
7773 -- Storage_Count as its result type.
7775 if Op_Name
= Name_Storage_Size
then
7776 if Ekind
(Found_Op
) = E_Procedure
then
7778 ("% operation must be a function", Found_Op
);
7780 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
7782 ("wrong result type for%, expected type&",
7783 Found_Op
, Stg_Cnt_Type
);
7786 -- Allocate and Deallocate must be procedures
7788 elsif Ekind
(Found_Op
) = E_Function
then
7790 ("% operation must be a procedure", Found_Op
);
7793 end Validate_Simple_Pool_Operation
;
7795 -- Start of processing for Validate_Simple_Pool_Ops
7798 Validate_Simple_Pool_Operation
(Name_Allocate
);
7799 Validate_Simple_Pool_Operation
(Name_Deallocate
);
7800 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
7801 end Validate_Simple_Pool_Ops
;
7805 -- Now that all types from which E may depend are frozen, see if
7806 -- strict alignment is required, a component clause on a record
7807 -- is correct, the size is known at compile time and if it must
7808 -- be unsigned, in that order.
7810 if Base_Type
(E
) = E
then
7811 Check_Strict_Alignment
(E
);
7814 if Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
7816 RC
: constant Node_Id
:= Get_Record_Representation_Clause
(E
);
7818 if Present
(RC
) then
7819 Check_Record_Representation_Clause
(RC
);
7824 Check_Compile_Time_Size
(E
);
7826 Check_Unsigned_Type
(E
);
7828 -- Do not allow a size clause for a type which does not have a size
7829 -- that is known at compile time
7831 if (Has_Size_Clause
(E
) or else Has_Object_Size_Clause
(E
))
7832 and then not Size_Known_At_Compile_Time
(E
)
7833 and then not Is_Mutably_Tagged_Type
(E
)
7835 -- Suppress this message if errors posted on E, even if we are
7836 -- in all errors mode, since this is often a junk message
7838 if not Error_Posted
(E
) then
7840 ("size clause not allowed for variable length type",
7845 -- Now we set/verify the representation information, in particular
7846 -- the size and alignment values. This processing is not required for
7847 -- generic types, since generic types do not play any part in code
7848 -- generation, and so the size and alignment values for such types
7849 -- are irrelevant. Ditto for types declared within a generic unit,
7850 -- which may have components that depend on generic parameters, and
7851 -- that will be recreated in an instance.
7853 if Inside_A_Generic
then
7856 -- Otherwise we call the layout procedure
7862 -- If this is an access to subprogram whose designated type is itself
7863 -- a subprogram type, the return type of this anonymous subprogram
7864 -- type must be decorated as well.
7866 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
7867 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
7869 Layout_Type
(Etype
(Designated_Type
(E
)));
7872 -- If the type has a Defaut_Value/Default_Component_Value aspect,
7873 -- this is where we analyze the expression (after the type is frozen,
7874 -- since in the case of Default_Value, we are analyzing with the
7875 -- type itself, and we treat Default_Component_Value similarly for
7876 -- the sake of uniformity).
7878 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
7885 if Is_Scalar_Type
(E
) then
7886 Nam
:= Name_Default_Value
;
7888 Exp
:= Default_Aspect_Value
(Typ
);
7890 Nam
:= Name_Default_Component_Value
;
7891 Typ
:= Component_Type
(E
);
7892 Exp
:= Default_Aspect_Component_Value
(E
);
7895 Analyze_And_Resolve
(Exp
, Typ
);
7897 if Etype
(Exp
) /= Any_Type
then
7898 if not Is_OK_Static_Expression
(Exp
) then
7899 Error_Msg_Name_1
:= Nam
;
7900 Flag_Non_Static_Expr
7901 ("aspect% requires static expression", Exp
);
7907 -- Verify at this point that No_Controlled_Parts and No_Task_Parts,
7908 -- when specified on the current type or one of its ancestors, has
7909 -- not been overridden and that no violation of the aspect has
7912 -- It is important that we perform the checks here after the type has
7913 -- been processed because if said type depended on a private type it
7914 -- will not have been marked controlled or having tasks.
7916 Check_No_Parts_Violations
(E
, Aspect_No_Controlled_Parts
);
7917 Check_No_Parts_Violations
(E
, Aspect_No_Task_Parts
);
7919 -- End of freeze processing for type entities
7922 -- Here is where we logically freeze the current entity. If it has a
7923 -- freeze node, then this is the point at which the freeze node is
7924 -- linked into the result list.
7926 if Has_Delayed_Freeze
(E
) then
7928 -- If a freeze node is already allocated, use it, otherwise allocate
7929 -- a new one. The preallocation happens in the case of anonymous base
7930 -- types, where we preallocate so that we can set First_Subtype_Link.
7931 -- Note that we reset the Sloc to the current freeze location.
7933 if Present
(Freeze_Node
(E
)) then
7934 F_Node
:= Freeze_Node
(E
);
7935 Set_Sloc
(F_Node
, Loc
);
7938 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
7939 Set_Freeze_Node
(E
, F_Node
);
7940 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
7941 Set_TSS_Elist
(F_Node
, No_Elist
);
7942 Set_Actions
(F_Node
, No_List
);
7945 Set_Entity
(F_Node
, E
);
7946 Add_To_Result
(F_Node
);
7948 -- A final pass over record types with discriminants. If the type
7949 -- has an incomplete declaration, there may be constrained access
7950 -- subtypes declared elsewhere, which do not depend on the discrimi-
7951 -- nants of the type, and which are used as component types (i.e.
7952 -- the full view is a recursive type). The designated types of these
7953 -- subtypes can only be elaborated after the type itself, and they
7954 -- need an itype reference.
7956 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
7963 Comp
:= First_Component
(E
);
7964 while Present
(Comp
) loop
7965 Typ
:= Etype
(Comp
);
7967 if Is_Access_Type
(Typ
)
7968 and then Scope
(Typ
) /= E
7969 and then Base_Type
(Designated_Type
(Typ
)) = E
7970 and then Is_Itype
(Designated_Type
(Typ
))
7972 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
7973 Set_Itype
(IR
, Designated_Type
(Typ
));
7974 Append
(IR
, Result
);
7977 Next_Component
(Comp
);
7983 -- When a type is frozen, the first subtype of the type is frozen as
7984 -- well (RM 13.14(15)). This has to be done after freezing the type,
7985 -- since obviously the first subtype depends on its own base type.
7988 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
7990 -- If we just froze a tagged non-class-wide record, then freeze the
7991 -- corresponding class-wide type. This must be done after the tagged
7992 -- type itself is frozen, because the class-wide type refers to the
7993 -- tagged type which generates the class.
7995 -- For a tagged type, freeze explicitly those primitive operations
7996 -- that are expression functions, which otherwise have no clear
7997 -- freeze point: these have to be frozen before the dispatch table
7998 -- for the type is built, and before any explicit call to the
7999 -- primitive, which would otherwise be the freeze point for it.
8001 if Is_Tagged_Type
(E
)
8002 and then not Is_Class_Wide_Type
(E
)
8003 and then Present
(Class_Wide_Type
(E
))
8005 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
8008 Ops
: constant Elist_Id
:= Primitive_Operations
(E
);
8014 if Ops
/= No_Elist
then
8015 Elmt
:= First_Elmt
(Ops
);
8016 while Present
(Elmt
) loop
8017 Subp
:= Node
(Elmt
);
8018 if Is_Expression_Function
(Subp
) then
8019 Freeze_And_Append
(Subp
, N
, Result
);
8029 Check_Debug_Info_Needed
(E
);
8031 -- If subprogram has address clause then reset Is_Public flag, since we
8032 -- do not want the backend to generate external references.
8034 if Is_Subprogram
(E
)
8035 and then Present
(Address_Clause
(E
))
8036 and then not Is_Library_Level_Entity
(E
)
8038 Set_Is_Public
(E
, False);
8041 -- The Ghost mode of the enclosing context is ignored, while the
8042 -- entity being frozen is living. Insert the freezing action prior
8043 -- to the start of the enclosing ignored Ghost region. As a result
8044 -- the freezeing action will be preserved when the ignored Ghost
8045 -- context is eliminated. The insertion must take place even when
8046 -- the context is a spec expression, otherwise "Handling of Default
8047 -- and Per-Object Expressions" will suppress the insertion, and the
8048 -- freeze node will be dropped on the floor.
8050 if Saved_GM
= Ignore
8051 and then Ghost_Mode
/= Ignore
8052 and then Present
(Ignored_Ghost_Region
)
8055 (Assoc_Node
=> Ignored_Ghost_Region
,
8056 Ins_Actions
=> Result
,
8057 Spec_Expr_OK
=> True);
8063 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
8068 -----------------------------
8069 -- Freeze_Enumeration_Type --
8070 -----------------------------
8072 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
8074 -- By default, if no size clause is present, an enumeration type with
8075 -- Convention C is assumed to interface to a C enum and has integer
8076 -- size, except for a boolean type because it is assumed to interface
8077 -- to _Bool introduced in C99. This applies to types. For subtypes,
8078 -- verify that its base type has no size clause either. Treat other
8079 -- foreign conventions in the same way, and also make sure alignment
8082 if Has_Foreign_Convention
(Typ
)
8083 and then not Is_Boolean_Type
(Typ
)
8084 and then not Has_Size_Clause
(Typ
)
8085 and then not Has_Size_Clause
(Base_Type
(Typ
))
8086 and then Esize
(Typ
) < Standard_Integer_Size
8088 -- Don't do this if Short_Enums on target
8090 and then not Target_Short_Enums
8092 Set_Esize
(Typ
, UI_From_Int
(Standard_Integer_Size
));
8093 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
8095 -- Normal Ada case or size clause present or not Long_C_Enums on target
8098 -- If the enumeration type interfaces to C, and it has a size clause
8099 -- that is smaller than the size of int, it warrants a warning. The
8100 -- user may intend the C type to be a boolean or a char, so this is
8101 -- not by itself an error that the Ada compiler can detect, but it
8102 -- is worth a heads-up. For Boolean and Character types we
8103 -- assume that the programmer has the proper C type in mind.
8104 -- For explicit sizes larger than int, assume the user knows what
8105 -- he is doing and that the code is intentional.
8107 if Convention
(Typ
) = Convention_C
8108 and then Has_Size_Clause
(Typ
)
8109 and then Esize
(Typ
) < Standard_Integer_Size
8110 and then not Is_Boolean_Type
(Typ
)
8111 and then not Is_Character_Type
(Typ
)
8113 -- Don't do this if Short_Enums on target
8115 and then not Target_Short_Enums
8118 ("??the size of enums in C is implementation-defined",
8121 ("\??check that the C counterpart has size of " &
8122 UI_Image
(Esize
(Typ
)),
8126 Adjust_Esize_For_Alignment
(Typ
);
8129 -- Reject a very large size on a type with a non-standard representation
8130 -- because Expand_Freeze_Enumeration_Type cannot deal with it.
8132 if Has_Non_Standard_Rep
(Typ
)
8133 and then Known_Esize
(Typ
)
8134 and then Esize
(Typ
) > System_Max_Integer_Size
8137 ("enumeration type with representation clause too large", Typ
);
8138 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Integer_Size
);
8140 ("\the size of such a type cannot exceed ^ bits", Typ
);
8142 end Freeze_Enumeration_Type
;
8144 -----------------------
8145 -- Freeze_Expression --
8146 -----------------------
8148 procedure Freeze_Expression
(N
: Node_Id
) is
8150 function Declared_In_Expanded_Body
8153 Nam
: Entity_Id
) return Boolean;
8154 -- Given the N_Handled_Sequence_Of_Statements node of an expander
8155 -- generated subprogram body, determines if the frozen entity is
8156 -- declared inside this body. This is recognized locating the
8157 -- enclosing subprogram of the entity Name or its Type and
8158 -- checking if it is this subprogram body.
8160 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
8161 -- If the expression is an array aggregate, the type of the component
8162 -- expressions is also frozen. If the component type is an access type
8163 -- and the expressions include allocators, the designed type is frozen
8166 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
8167 -- Given an N_Handled_Sequence_Of_Statements node, determines whether it
8168 -- is the statement sequence of an expander-generated subprogram: body
8169 -- created for an expression function, for a predicate function, an init
8170 -- proc, a stream subprogram, or a renaming as body. If so, this is not
8171 -- a freezing context and the entity will be frozen at a later point.
8173 function Has_Decl_In_List
8176 L
: List_Id
) return Boolean;
8177 -- Determines whether an entity E referenced in node N is declared in
8180 -------------------------------
8181 -- Declared_In_Expanded_Body --
8182 -------------------------------
8184 function Declared_In_Expanded_Body
8187 Nam
: Entity_Id
) return Boolean
8189 pragma Assert
(In_Expanded_Body
(N
));
8191 Subp_Body
: constant Node_Id
:= Parent
(N
);
8192 Subp_Id
: Entity_Id
;
8196 if Acts_As_Spec
(Subp_Body
) then
8197 Subp_Id
:= Unique_Defining_Entity
(Specification
(Subp_Body
));
8199 Subp_Id
:= Corresponding_Spec
(Subp_Body
);
8202 if Present
(Typ
) then
8203 Scop
:= Scope
(Typ
);
8204 elsif Present
(Nam
) then
8205 Scop
:= Scope
(Nam
);
8207 Scop
:= Standard_Standard
;
8210 while Scop
/= Standard_Standard
8211 and then not Is_Subprogram
(Scop
)
8213 Scop
:= Scope
(Scop
);
8216 return Scop
= Subp_Id
;
8217 end Declared_In_Expanded_Body
;
8219 -----------------------------------------
8220 -- Find_Aggregate_Component_Desig_Type --
8221 -----------------------------------------
8223 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
8228 if Present
(Expressions
(N
)) then
8229 Exp
:= First
(Expressions
(N
));
8230 while Present
(Exp
) loop
8231 if Nkind
(Exp
) = N_Allocator
then
8232 return Designated_Type
(Component_Type
(Etype
(N
)));
8239 if Present
(Component_Associations
(N
)) then
8240 Assoc
:= First
(Component_Associations
(N
));
8241 while Present
(Assoc
) loop
8242 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
8243 return Designated_Type
(Component_Type
(Etype
(N
)));
8251 end Find_Aggregate_Component_Desig_Type
;
8253 ----------------------
8254 -- In_Expanded_Body --
8255 ----------------------
8257 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
8258 P
: constant Node_Id
:= Parent
(N
);
8262 if Nkind
(P
) /= N_Subprogram_Body
then
8265 -- Treat the generated body of an expression function like other
8266 -- bodies generated during expansion (e.g. stream subprograms) so
8267 -- that those bodies are not treated as freezing points.
8269 elsif Was_Expression_Function
(P
) then
8270 pragma Assert
(not Comes_From_Source
(P
));
8273 -- This is the body of a generated predicate function
8275 elsif Present
(Corresponding_Spec
(P
))
8276 and then Is_Predicate_Function
(Corresponding_Spec
(P
))
8281 Id
:= Defining_Unit_Name
(Specification
(P
));
8283 -- The following are expander-created bodies, or bodies that
8284 -- are not freeze points.
8286 if Nkind
(Id
) = N_Defining_Identifier
8287 and then (Is_Init_Proc
(Id
)
8288 or else Is_TSS
(Id
, TSS_Stream_Input
)
8289 or else Is_TSS
(Id
, TSS_Stream_Output
)
8290 or else Is_TSS
(Id
, TSS_Stream_Read
)
8291 or else Is_TSS
(Id
, TSS_Stream_Write
)
8292 or else Is_TSS
(Id
, TSS_Put_Image
)
8293 or else Nkind
(Original_Node
(P
)) =
8294 N_Subprogram_Renaming_Declaration
)
8301 end In_Expanded_Body
;
8303 ----------------------
8304 -- Has_Decl_In_List --
8305 ----------------------
8307 function Has_Decl_In_List
8310 L
: List_Id
) return Boolean
8312 Decl_Node
: Node_Id
;
8315 -- If E is an itype, pretend that it is declared in N except for a
8316 -- class-wide subtype with an equivalent type, because this latter
8317 -- type comes with a bona-fide declaration node.
8319 if Is_Itype
(E
) then
8320 if Ekind
(E
) = E_Class_Wide_Subtype
8321 and then Present
(Equivalent_Type
(E
))
8323 Decl_Node
:= Declaration_Node
(Equivalent_Type
(E
));
8329 Decl_Node
:= Declaration_Node
(E
);
8332 return Is_List_Member
(Decl_Node
)
8333 and then List_Containing
(Decl_Node
) = L
;
8334 end Has_Decl_In_List
;
8338 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
8340 Desig_Typ
: Entity_Id
;
8346 Allocator_Typ
: Entity_Id
:= Empty
;
8348 Freeze_Outside_Subp
: Entity_Id
:= Empty
;
8349 -- This entity is set if we are inside a subprogram body and the frozen
8350 -- entity is defined in the enclosing scope of this subprogram. In such
8351 -- case we must skip the subprogram body when climbing the parents chain
8352 -- to locate the correct placement for the freezing node.
8354 -- Start of processing for Freeze_Expression
8357 -- Immediate return if freezing is inhibited. This flag is set by the
8358 -- analyzer to stop freezing on generated expressions that would cause
8359 -- freezing if they were in the source program, but which are not
8360 -- supposed to freeze, since they are created.
8362 if Must_Not_Freeze
(N
) then
8366 -- If expression is non-static, then it does not freeze in a default
8367 -- expression, see section "Handling of Default Expressions" in the
8368 -- spec of package Sem for further details. Note that we have to make
8369 -- sure that we actually have a real expression (if we have a subtype
8370 -- indication, we can't test Is_OK_Static_Expression). However, we
8371 -- exclude the case of the prefix of an attribute of a static scalar
8372 -- subtype from this early return, because static subtype attributes
8373 -- should always cause freezing, even in default expressions, but
8374 -- the attribute may not have been marked as static yet (because in
8375 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
8376 -- Freeze_Expression on the prefix).
8379 and then Nkind
(N
) in N_Subexpr
8380 and then not Is_OK_Static_Expression
(N
)
8381 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
8382 or else not (Is_Entity_Name
(N
)
8383 and then Is_Type
(Entity
(N
))
8384 and then Is_OK_Static_Subtype
(Entity
(N
))))
8389 -- Freeze type of expression if not frozen already
8393 if Nkind
(N
) in N_Has_Etype
and then Present
(Etype
(N
)) then
8394 if not Is_Frozen
(Etype
(N
)) then
8397 -- Base type may be an derived numeric type that is frozen at the
8398 -- point of declaration, but first_subtype is still unfrozen.
8400 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
8401 Typ
:= First_Subtype
(Etype
(N
));
8405 -- For entity name, freeze entity if not frozen already. A special
8406 -- exception occurs for an identifier that did not come from source.
8407 -- We don't let such identifiers freeze a non-internal entity, i.e.
8408 -- an entity that did come from source, since such an identifier was
8409 -- generated by the expander, and cannot have any semantic effect on
8410 -- the freezing semantics. For example, this stops the parameter of
8411 -- an initialization procedure from freezing the variable.
8413 if Is_Entity_Name
(N
)
8414 and then Present
(Entity
(N
))
8415 and then not Is_Frozen
(Entity
(N
))
8416 and then (Nkind
(N
) /= N_Identifier
8417 or else Comes_From_Source
(N
)
8418 or else not Comes_From_Source
(Entity
(N
)))
8422 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
8423 Check_Expression_Function
(N
, Nam
);
8430 -- For an allocator freeze designated type if not frozen already
8432 -- For an aggregate whose component type is an access type, freeze the
8433 -- designated type now, so that its freeze does not appear within the
8434 -- loop that might be created in the expansion of the aggregate. If the
8435 -- designated type is a private type without full view, the expression
8436 -- cannot contain an allocator, so the type is not frozen.
8438 -- For a function, we freeze the entity when the subprogram declaration
8439 -- is frozen, but a function call may appear in an initialization proc.
8440 -- before the declaration is frozen. We need to generate the extra
8441 -- formals, if any, to ensure that the expansion of the call includes
8442 -- the proper actuals. This only applies to Ada subprograms, not to
8449 Desig_Typ
:= Designated_Type
(Etype
(N
));
8451 if Nkind
(Expression
(N
)) = N_Qualified_Expression
then
8452 Allocator_Typ
:= Entity
(Subtype_Mark
(Expression
(N
)));
8456 if Is_Array_Type
(Etype
(N
))
8457 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
8459 -- Check whether aggregate includes allocators
8461 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
8464 when N_Indexed_Component
8465 | N_Selected_Component
8468 if Is_Access_Type
(Etype
(Prefix
(N
))) then
8469 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
8472 when N_Identifier
=>
8474 and then Ekind
(Nam
) = E_Function
8475 and then Nkind
(Parent
(N
)) = N_Function_Call
8476 and then not Has_Foreign_Convention
(Nam
)
8478 Create_Extra_Formals
(Nam
);
8485 if Desig_Typ
/= Empty
8486 and then (Is_Frozen
(Desig_Typ
)
8487 or else not Is_Fully_Defined
(Desig_Typ
))
8492 -- All done if nothing needs freezing
8496 and then No
(Desig_Typ
)
8497 and then No
(Allocator_Typ
)
8502 -- Check if we are inside a subprogram body and the frozen entity is
8503 -- defined in the enclosing scope of this subprogram. In such case we
8504 -- must skip the subprogram when climbing the parents chain to locate
8505 -- the correct placement for the freezing node.
8507 -- This is not needed for default expressions and other spec expressions
8508 -- in generic units since the Move_Freeze_Nodes mechanism (sem_ch12.adb)
8509 -- takes care of placing them at the proper place, after the generic
8513 and then Scope
(Nam
) /= Current_Scope
8514 and then not (In_Spec_Exp
and then Inside_A_Generic
)
8517 S
: Entity_Id
:= Current_Scope
;
8521 and then In_Same_Source_Unit
(Nam
, S
)
8523 if Scope
(S
) = Scope
(Nam
) then
8524 if Is_Subprogram
(S
) and then Has_Completion
(S
) then
8525 Freeze_Outside_Subp
:= S
;
8536 -- Examine the enclosing context by climbing the parent chain
8538 -- If we identified that we must freeze the entity outside of a given
8539 -- subprogram then we just climb up to that subprogram checking if some
8540 -- enclosing node is marked as Must_Not_Freeze (since in such case we
8541 -- must not freeze yet this entity).
8545 if Present
(Freeze_Outside_Subp
) then
8547 -- Do not freeze the current expression if another expression in
8548 -- the chain of parents must not be frozen.
8550 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8554 Parent_P
:= Parent
(P
);
8556 -- If we don't have a parent, then we are not in a well-formed
8557 -- tree. This is an unusual case, but there are some legitimate
8558 -- situations in which this occurs, notably when the expressions
8559 -- in the range of a type declaration are resolved. We simply
8560 -- ignore the freeze request in this case.
8562 if No
(Parent_P
) then
8566 -- If the parent is a subprogram body, the candidate insertion
8567 -- point is just ahead of it.
8569 if Nkind
(Parent_P
) = N_Subprogram_Body
8570 and then Unique_Defining_Entity
(Parent_P
) =
8580 -- Otherwise the traversal serves two purposes - to detect scenarios
8581 -- where freezeing is not needed and to find the proper insertion point
8582 -- for the freeze nodes. Although somewhat similar to Insert_Actions,
8583 -- this traversal is freezing semantics-sensitive. Inserting freeze
8584 -- nodes blindly in the tree may result in types being frozen too early.
8588 -- Do not freeze the current expression if another expression in
8589 -- the chain of parents must not be frozen.
8591 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8595 Parent_P
:= Parent
(P
);
8597 -- If we don't have a parent, then we are not in a well-formed
8598 -- tree. This is an unusual case, but there are some legitimate
8599 -- situations in which this occurs, notably when the expressions
8600 -- in the range of a type declaration are resolved. We simply
8601 -- ignore the freeze request in this case.
8603 if No
(Parent_P
) then
8607 -- See if we have got to an appropriate point in the tree
8609 case Nkind
(Parent_P
) is
8611 -- A special test for the exception of (RM 13.14(8)) for the
8612 -- case of per-object expressions (RM 3.8(18)) occurring in
8613 -- component definition or a discrete subtype definition. Note
8614 -- that we test for a component declaration which includes both
8615 -- cases we are interested in, and furthermore the tree does
8616 -- not have explicit nodes for either of these two constructs.
8618 when N_Component_Declaration
=>
8620 -- The case we want to test for here is an identifier that
8621 -- is a per-object expression, this is either a discriminant
8622 -- that appears in a context other than the component
8623 -- declaration or it is a reference to the type of the
8624 -- enclosing construct.
8626 -- For either of these cases, we skip the freezing
8628 if not In_Spec_Expression
8629 and then Nkind
(N
) = N_Identifier
8630 and then Present
(Entity
(N
))
8632 -- We recognize the discriminant case by just looking for
8633 -- a reference to a discriminant. It can only be one for
8634 -- the enclosing construct. Skip freezing in this case.
8636 if Ekind
(Entity
(N
)) = E_Discriminant
then
8639 -- For the case of a reference to the enclosing record,
8640 -- (or task or protected type), we look for a type that
8641 -- matches the current scope.
8643 elsif Entity
(N
) = Current_Scope
then
8648 -- If we have an enumeration literal that appears as the choice
8649 -- in the aggregate of an enumeration representation clause,
8650 -- then freezing does not occur (RM 13.14(10)).
8652 when N_Enumeration_Representation_Clause
=>
8654 -- The case we are looking for is an enumeration literal
8656 if Nkind
(N
) in N_Identifier | N_Character_Literal
8657 and then Is_Enumeration_Type
(Etype
(N
))
8659 -- If enumeration literal appears directly as the choice,
8660 -- do not freeze (this is the normal non-overloaded case)
8662 if Nkind
(Parent
(N
)) = N_Component_Association
8663 and then First
(Choices
(Parent
(N
))) = N
8667 -- If enumeration literal appears as the name of function
8668 -- which is the choice, then also do not freeze. This
8669 -- happens in the overloaded literal case, where the
8670 -- enumeration literal is temporarily changed to a
8671 -- function call for overloading analysis purposes.
8673 elsif Nkind
(Parent
(N
)) = N_Function_Call
8674 and then Nkind
(Parent
(Parent
(N
))) =
8675 N_Component_Association
8676 and then First
(Choices
(Parent
(Parent
(N
)))) =
8683 -- Normally if the parent is a handled sequence of statements,
8684 -- then the current node must be a statement, and that is an
8685 -- appropriate place to insert a freeze node.
8687 when N_Handled_Sequence_Of_Statements
=>
8689 -- An exception occurs when the sequence of statements is
8690 -- for an expander generated body that did not do the usual
8691 -- freeze all operation. In this case we usually want to
8692 -- freeze outside this body, not inside it, unless the
8693 -- entity is declared inside this expander generated body.
8695 exit when not In_Expanded_Body
(Parent_P
)
8696 or else Declared_In_Expanded_Body
(Parent_P
, Typ
, Nam
);
8698 -- If parent is a body or a spec or a block, then the current
8699 -- node is a statement or declaration and we can insert the
8700 -- freeze node before it.
8702 when N_Block_Statement
8705 | N_Package_Specification
8712 -- The expander is allowed to define types in any statements
8713 -- list, so any of the following parent nodes also mark a
8714 -- freezing point if the actual node is in a list of
8715 -- statements or declarations.
8717 when N_Abortable_Part
8718 | N_Accept_Alternative
8719 | N_Case_Statement_Alternative
8720 | N_Compilation_Unit_Aux
8721 | N_Conditional_Entry_Call
8722 | N_Delay_Alternative
8724 | N_Entry_Call_Alternative
8725 | N_Exception_Handler
8726 | N_Extended_Return_Statement
8729 | N_Selective_Accept
8730 | N_Triggering_Alternative
8732 if No
(Current_Subprogram
) then
8733 exit when Is_List_Member
(P
);
8735 -- Check exceptional case documented above for an enclosing
8736 -- handled sequence of statements.
8740 Par
: Node_Id
:= Parent
(Parent_P
);
8745 Nkind
(Par
) /= N_Handled_Sequence_Of_Statements
8746 and then Nkind
(Parent
(Par
)) /= N_Subprogram_Body
8748 Par
:= Parent
(Par
);
8751 -- If we don't have a parent, then we are not in a
8752 -- well-formed tree and we ignore the freeze request.
8753 -- See previous comment in the enclosing loop.
8759 exit when not In_Expanded_Body
(Par
)
8760 or else Declared_In_Expanded_Body
(Par
, Typ
, Nam
);
8764 -- The freeze nodes produced by an expression coming from the
8765 -- Actions list of an N_Expression_With_Actions, short-circuit
8766 -- expression or N_Case_Expression_Alternative node must remain
8767 -- within the Actions list if they freeze an entity declared in
8768 -- this list, as inserting the freeze nodes further up the tree
8769 -- may lead to use before declaration issues for the entity.
8771 when N_Case_Expression_Alternative
8772 | N_Expression_With_Actions
8775 exit when (Present
(Nam
)
8777 Has_Decl_In_List
(Nam
, P
, Actions
(Parent_P
)))
8778 or else (Present
(Typ
)
8780 Has_Decl_In_List
(Typ
, P
, Actions
(Parent_P
)));
8782 -- Likewise for an N_If_Expression and its two Actions list
8784 when N_If_Expression
=>
8786 L1
: constant List_Id
:= Then_Actions
(Parent_P
);
8787 L2
: constant List_Id
:= Else_Actions
(Parent_P
);
8790 exit when (Present
(Nam
)
8792 Has_Decl_In_List
(Nam
, P
, L1
))
8793 or else (Present
(Typ
)
8795 Has_Decl_In_List
(Typ
, P
, L1
))
8796 or else (Present
(Nam
)
8798 Has_Decl_In_List
(Nam
, P
, L2
))
8799 or else (Present
(Typ
)
8801 Has_Decl_In_List
(Typ
, P
, L2
));
8804 -- N_Loop_Statement is a special case: a type that appears in
8805 -- the source can never be frozen in a loop (this occurs only
8806 -- because of a loop expanded by the expander), so we keep on
8807 -- going. Otherwise we terminate the search. Same is true of
8808 -- any entity which comes from source (if it has a predefined
8809 -- type, this type does not appear to come from source, but the
8810 -- entity should not be frozen here).
8812 when N_Loop_Statement
=>
8813 exit when not Comes_From_Source
(Etype
(N
))
8814 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
8816 -- For all other cases, keep looking at parents
8822 -- We fall through the case if we did not yet find the proper
8823 -- place in the tree for inserting the freeze node, so climb.
8829 -- If the expression appears in a record or an initialization procedure,
8830 -- the freeze nodes are collected and attached to the current scope, to
8831 -- be inserted and analyzed on exit from the scope, to insure that
8832 -- generated entities appear in the correct scope. If the expression is
8833 -- a default for a discriminant specification, the scope is still void.
8834 -- The expression can also appear in the discriminant part of a private
8835 -- or concurrent type.
8837 -- If the expression appears in a constrained subcomponent of an
8838 -- enclosing record declaration, the freeze nodes must be attached to
8839 -- the outer record type so they can eventually be placed in the
8840 -- enclosing declaration list.
8842 -- The other case requiring this special handling is if we are in a
8843 -- default expression, since in that case we are about to freeze a
8844 -- static type, and the freeze scope needs to be the outer scope, not
8845 -- the scope of the subprogram with the default parameter.
8847 -- For default expressions and other spec expressions in generic units,
8848 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
8849 -- placing them at the proper place, after the generic unit.
8851 if (In_Spec_Exp
and not Inside_A_Generic
)
8852 or else (Is_Type
(Current_Scope
)
8853 and then (not Is_Concurrent_Type
(Current_Scope
)
8854 or else not Has_Completion
(Current_Scope
)))
8855 or else Ekind
(Current_Scope
) = E_Void
8858 Freeze_Nodes
: List_Id
:= No_List
;
8859 Pos
: Int
:= Scope_Stack
.Last
;
8862 if Present
(Desig_Typ
) then
8863 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
8866 if Present
(Typ
) then
8867 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
8870 if Present
(Nam
) then
8871 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
8874 -- The current scope may be that of a constrained component of
8875 -- an enclosing record declaration, or a block of an enclosing
8876 -- declare expression in Ada 2022, or of a loop of an enclosing
8877 -- quantified expression or aggregate with an iterated component
8878 -- in Ada 2022, which is above the current scope in the scope
8879 -- stack. Indeed in the context of a quantified expression or
8880 -- an aggregate with an iterated component, an internal scope is
8881 -- created and pushed above the current scope in order to emulate
8882 -- the loop-like behavior of the construct.
8883 -- If the expression is within a top-level pragma, as for a pre-
8884 -- condition on a library-level subprogram, nothing to do.
8886 if not Is_Compilation_Unit
(Current_Scope
)
8887 and then (Is_Record_Type
(Scope
(Current_Scope
))
8888 or else (Ekind
(Current_Scope
) in E_Block | E_Loop
8889 and then Is_Internal
(Current_Scope
)))
8894 if Is_Non_Empty_List
(Freeze_Nodes
) then
8896 -- When the current scope is transient, insert the freeze nodes
8897 -- prior to the expression that produced them. Transient scopes
8898 -- may create additional declarations when finalizing objects
8899 -- or managing the secondary stack. Inserting the freeze nodes
8900 -- of those constructs prior to the scope would result in a
8901 -- freeze-before-declaration, therefore the freeze node must
8902 -- remain interleaved with their constructs.
8904 if Scope_Is_Transient
then
8905 Insert_Actions
(N
, Freeze_Nodes
);
8907 elsif No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
8908 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
8911 Append_List
(Freeze_Nodes
,
8912 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
8920 -- Now we have the right place to do the freezing. First, a special
8921 -- adjustment, if we are in spec-expression analysis mode, these freeze
8922 -- actions must not be thrown away (normally all inserted actions are
8923 -- thrown away in this mode). However, the freeze actions are from
8924 -- static expressions and one of the important reasons we are doing this
8925 -- special analysis is to get these freeze actions. Therefore we turn
8926 -- off the In_Spec_Expression mode to propagate these freeze actions.
8927 -- This also means they get properly analyzed and expanded.
8929 In_Spec_Expression
:= False;
8931 -- Freeze the subtype mark before a qualified expression on an
8932 -- allocator as per AARM 13.14(4.a). This is needed in particular to
8933 -- generate predicate functions.
8935 if Present
(Allocator_Typ
) then
8936 Freeze_Before
(P
, Allocator_Typ
);
8939 -- Freeze the designated type of an allocator (RM 13.14(13))
8941 if Present
(Desig_Typ
) then
8942 Freeze_Before
(P
, Desig_Typ
);
8945 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
8946 -- the enumeration representation clause exception in the loop above.
8948 if Present
(Typ
) then
8949 Freeze_Before
(P
, Typ
);
8952 -- Freeze name if one is present (RM 13.14(11))
8954 if Present
(Nam
) then
8955 Freeze_Before
(P
, Nam
);
8958 -- Restore In_Spec_Expression flag
8960 In_Spec_Expression
:= In_Spec_Exp
;
8961 end Freeze_Expression
;
8963 -----------------------
8964 -- Freeze_Expr_Types --
8965 -----------------------
8967 procedure Freeze_Expr_Types
8968 (Def_Id
: Entity_Id
;
8973 function Cloned_Expression
return Node_Id
;
8974 -- Build a duplicate of the expression of the return statement that has
8975 -- no defining entities shared with the original expression.
8977 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
8978 -- Freeze all types referenced in the subtree rooted at Node
8980 -----------------------
8981 -- Cloned_Expression --
8982 -----------------------
8984 function Cloned_Expression
return Node_Id
is
8985 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
8986 -- Tree traversal routine that clones the defining identifier of
8987 -- iterator and loop parameter specification nodes.
8993 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
8996 N_Iterator_Specification | N_Loop_Parameter_Specification
8998 Set_Defining_Identifier
8999 (Node
, New_Copy
(Defining_Identifier
(Node
)));
9005 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
9009 Dup_Expr
: constant Node_Id
:= New_Copy_Tree
(Expr
);
9011 -- Start of processing for Cloned_Expression
9014 -- We must duplicate the expression with semantic information to
9015 -- inherit the decoration of global entities in generic instances.
9016 -- Set the parent of the new node to be the parent of the original
9017 -- to get the proper context, which is needed for complete error
9018 -- reporting and for semantic analysis.
9020 Set_Parent
(Dup_Expr
, Parent
(Expr
));
9022 -- Replace the defining identifier of iterators and loop param
9023 -- specifications by a clone to ensure that the cloned expression
9024 -- and the original expression don't have shared identifiers;
9025 -- otherwise, as part of the preanalysis of the expression, these
9026 -- shared identifiers may be left decorated with itypes which
9027 -- will not be available in the tree passed to the backend.
9029 Clone_Def_Ids
(Dup_Expr
);
9032 end Cloned_Expression
;
9034 ----------------------
9035 -- Freeze_Type_Refs --
9036 ----------------------
9038 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
9039 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
);
9040 -- Check that Typ is fully declared and freeze it if so
9042 ---------------------------
9043 -- Check_And_Freeze_Type --
9044 ---------------------------
9046 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
) is
9048 -- Skip Itypes created by the preanalysis, and itypes whose
9049 -- scope is another type (i.e. component subtypes that depend
9050 -- on a discriminant),
9053 and then (Scope_Within_Or_Same
(Scope
(Typ
), Def_Id
)
9054 or else Is_Type
(Scope
(Typ
)))
9059 -- This provides a better error message than generating primitives
9060 -- whose compilation fails much later. Refine the error message if
9063 Check_Fully_Declared
(Typ
, Node
);
9065 if Error_Posted
(Node
) then
9066 if Has_Private_Component
(Typ
)
9067 and then not Is_Private_Type
(Typ
)
9069 Error_Msg_NE
("\type& has private component", Node
, Typ
);
9073 Freeze_Before
(N
, Typ
);
9075 end Check_And_Freeze_Type
;
9077 -- Start of processing for Freeze_Type_Refs
9080 -- Check that a type referenced by an entity can be frozen
9082 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
9083 -- The entity itself may be a type, as in a membership test
9084 -- or an attribute reference. Freezing its own type would be
9085 -- incomplete if the entity is derived or an extension.
9087 if Is_Type
(Entity
(Node
)) then
9088 Check_And_Freeze_Type
(Entity
(Node
));
9091 Check_And_Freeze_Type
(Etype
(Entity
(Node
)));
9094 -- Check that the enclosing record type can be frozen
9096 if Ekind
(Entity
(Node
)) in E_Component | E_Discriminant
then
9097 Check_And_Freeze_Type
(Scope
(Entity
(Node
)));
9100 -- Freezing an access type does not freeze the designated type, but
9101 -- freezing conversions between access to interfaces requires that
9102 -- the interface types themselves be frozen, so that dispatch table
9103 -- entities are properly created.
9105 -- Unclear whether a more general rule is needed ???
9107 elsif Nkind
(Node
) = N_Type_Conversion
9108 and then Is_Access_Type
(Etype
(Node
))
9109 and then Is_Interface
(Designated_Type
(Etype
(Node
)))
9111 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
9114 -- An implicit dereference freezes the designated type. In the case
9115 -- of a dispatching call whose controlling argument is an access
9116 -- type, the dereference is not made explicit, so we must check for
9117 -- such a call and freeze the designated type.
9119 if Nkind
(Node
) in N_Has_Etype
9120 and then Present
(Etype
(Node
))
9121 and then Is_Access_Type
(Etype
(Node
))
9123 if Nkind
(Parent
(Node
)) = N_Function_Call
9124 and then Node
= Controlling_Argument
(Parent
(Node
))
9126 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
9128 -- An explicit dereference freezes the designated type as well,
9129 -- even though that type is not attached to an entity in the
9132 elsif Nkind
(Parent
(Node
)) = N_Explicit_Dereference
then
9133 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
9136 -- An iterator specification freezes the iterator type, even though
9137 -- that type is not attached to an entity in the construct.
9139 elsif Nkind
(Node
) in N_Has_Etype
9140 and then Nkind
(Parent
(Node
)) = N_Iterator_Specification
9141 and then Node
= Name
(Parent
(Node
))
9144 Iter
: constant Node_Id
:=
9145 Find_Value_Of_Aspect
(Etype
(Node
), Aspect_Default_Iterator
);
9148 if Present
(Iter
) then
9149 Check_And_Freeze_Type
(Etype
(Iter
));
9154 -- No point in posting several errors on the same expression
9156 if Serious_Errors_Detected
> 0 then
9161 end Freeze_Type_Refs
;
9163 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
9167 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Def_Id
);
9168 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Def_Id
);
9169 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
9171 -- Start of processing for Freeze_Expr_Types
9174 -- Preanalyze a duplicate of the expression to have available the
9175 -- minimum decoration needed to locate referenced unfrozen types
9176 -- without adding any decoration to the function expression.
9178 -- This routine is also applied to expressions in the contract for
9179 -- the subprogram. If that happens when expanding the code for
9180 -- pre/postconditions during expansion of the subprogram body, the
9181 -- subprogram is already installed.
9183 if Def_Id
/= Current_Scope
then
9184 Push_Scope
(Def_Id
);
9185 Install_Formals
(Def_Id
);
9187 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
9190 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
9193 -- Restore certain attributes of Def_Id since the preanalysis may
9194 -- have introduced itypes to this scope, thus modifying attributes
9195 -- First_Entity and Last_Entity.
9197 Set_First_Entity
(Def_Id
, Saved_First_Entity
);
9198 Set_Last_Entity
(Def_Id
, Saved_Last_Entity
);
9200 if Present
(Last_Entity
(Def_Id
)) then
9201 Set_Next_Entity
(Last_Entity
(Def_Id
), Empty
);
9204 -- Freeze all types referenced in the expression
9206 Freeze_References
(Dup_Expr
);
9207 end Freeze_Expr_Types
;
9209 -----------------------------
9210 -- Freeze_Fixed_Point_Type --
9211 -----------------------------
9213 -- Certain fixed-point types and subtypes, including implicit base types
9214 -- and declared first subtypes, have not yet set up a range. This is
9215 -- because the range cannot be set until the Small and Size values are
9216 -- known, and these are not known till the type is frozen.
9218 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
9219 -- whose bounds are unanalyzed real literals. This routine will recognize
9220 -- this case, and transform this range node into a properly typed range
9221 -- with properly analyzed and resolved values.
9223 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
9224 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
9225 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
9226 Hi
: constant Node_Id
:= High_Bound
(Rng
);
9227 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9228 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
9229 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
9230 BHi
: constant Node_Id
:= High_Bound
(Brng
);
9231 Ftyp
: constant Entity_Id
:= Underlying_Type
(First_Subtype
(Typ
));
9240 -- Save original bounds (for shaving tests)
9243 -- Actual size chosen
9245 function Fsize
(Lov
, Hiv
: Ureal
) return Int
;
9246 -- Returns size of type with given bounds. Also leaves these
9247 -- bounds set as the current bounds of the Typ.
9249 function Larger
(A
, B
: Ureal
) return Boolean;
9250 -- Returns true if A > B with a margin of Typ'Small
9252 function Smaller
(A
, B
: Ureal
) return Boolean;
9253 -- Returns true if A < B with a margin of Typ'Small
9259 function Fsize
(Lov
, Hiv
: Ureal
) return Int
is
9261 Set_Realval
(Lo
, Lov
);
9262 Set_Realval
(Hi
, Hiv
);
9263 return Minimum_Size
(Typ
);
9270 function Larger
(A
, B
: Ureal
) return Boolean is
9272 return A
> B
and then A
- Small_Value
(Typ
) > B
;
9279 function Smaller
(A
, B
: Ureal
) return Boolean is
9281 return A
< B
and then A
+ Small_Value
(Typ
) < B
;
9284 -- Start of processing for Freeze_Fixed_Point_Type
9287 -- The type, or its first subtype if we are freezing the anonymous
9288 -- base, may have a delayed Small aspect. It must be analyzed now,
9289 -- so that all characteristics of the type (size, bounds) can be
9290 -- computed and validated in the call to Minimum_Size that follows.
9292 if Has_Delayed_Aspects
(Ftyp
) then
9293 Analyze_Aspects_At_Freeze_Point
(Ftyp
);
9294 Set_Has_Delayed_Aspects
(Ftyp
, False);
9297 if May_Inherit_Delayed_Rep_Aspects
(Ftyp
) then
9298 Inherit_Delayed_Rep_Aspects
(Ftyp
);
9299 Set_May_Inherit_Delayed_Rep_Aspects
(Ftyp
, False);
9302 -- Inherit the Small value from the first subtype in any case
9305 Set_Small_Value
(Typ
, Small_Value
(Ftyp
));
9308 -- If Esize of a subtype has not previously been set, set it now
9310 if not Known_Esize
(Typ
) then
9311 Atype
:= Ancestor_Subtype
(Typ
);
9313 if Present
(Atype
) then
9314 Set_Esize
(Typ
, Esize
(Atype
));
9316 Copy_Esize
(To
=> Typ
, From
=> Btyp
);
9320 -- Immediate return if the range is already analyzed. This means that
9321 -- the range is already set, and does not need to be computed by this
9324 if Analyzed
(Rng
) then
9328 -- Immediate return if either of the bounds raises Constraint_Error
9330 if Raises_Constraint_Error
(Lo
)
9331 or else Raises_Constraint_Error
(Hi
)
9336 Small
:= Small_Value
(Typ
);
9337 Loval
:= Realval
(Lo
);
9338 Hival
:= Realval
(Hi
);
9343 -- Ordinary fixed-point case
9345 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
9347 -- For the ordinary fixed-point case, we are allowed to fudge the
9348 -- end-points up or down by small. Generally we prefer to fudge up,
9349 -- i.e. widen the bounds for non-model numbers so that the end points
9350 -- are included. However there are cases in which this cannot be
9351 -- done, and indeed cases in which we may need to narrow the bounds.
9352 -- The following circuit makes the decision.
9354 -- Note: our terminology here is that Incl_EP means that the bounds
9355 -- are widened by Small if necessary to include the end points, and
9356 -- Excl_EP means that the bounds are narrowed by Small to exclude the
9357 -- end-points if this reduces the size.
9359 -- Note that in the Incl case, all we care about is including the
9360 -- end-points. In the Excl case, we want to narrow the bounds as
9361 -- much as permitted by the RM, to give the smallest possible size.
9364 Loval_Incl_EP
: Ureal
;
9365 Hival_Incl_EP
: Ureal
;
9367 Loval_Excl_EP
: Ureal
;
9368 Hival_Excl_EP
: Ureal
;
9378 -- First step. Base types are required to be symmetrical. Right
9379 -- now, the base type range is a copy of the first subtype range.
9380 -- This will be corrected before we are done, but right away we
9381 -- need to deal with the case where both bounds are non-negative.
9382 -- In this case, we set the low bound to the negative of the high
9383 -- bound, to make sure that the size is computed to include the
9384 -- required sign. Note that we do not need to worry about the
9385 -- case of both bounds negative, because the sign will be dealt
9386 -- with anyway. Furthermore we can't just go making such a bound
9387 -- symmetrical, since in a twos-complement system, there is an
9388 -- extra negative value which could not be accommodated on the
9392 and then not UR_Is_Negative
(Loval
)
9393 and then Hival
> Loval
9396 Set_Realval
(Lo
, Loval
);
9399 -- Compute the fudged bounds. If the bound is a model number, (or
9400 -- greater if given low bound, smaller if high bound) then we do
9401 -- nothing to include it, but we are allowed to backoff to the
9402 -- next adjacent model number when we exclude it. If it is not a
9403 -- model number then we straddle the two values with the model
9404 -- numbers on either side.
9406 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
9408 if UR_Ge
(Loval
, Model_Num
) then
9409 Loval_Incl_EP
:= Model_Num
;
9411 Loval_Incl_EP
:= Model_Num
- Small
;
9414 -- The low value excluding the end point is Small greater, but
9415 -- we do not do this exclusion if the low value is positive,
9416 -- since it can't help the size and could actually hurt by
9417 -- crossing the high bound.
9419 if UR_Is_Negative
(Loval_Incl_EP
) then
9420 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
9422 -- If the value went from negative to zero, then we have the
9423 -- case where Loval_Incl_EP is the model number just below
9424 -- zero, so we want to stick to the negative value for the
9425 -- base type to maintain the condition that the size will
9426 -- include signed values.
9429 and then UR_Is_Zero
(Loval_Excl_EP
)
9431 Loval_Excl_EP
:= Loval_Incl_EP
;
9435 Loval_Excl_EP
:= Loval_Incl_EP
;
9438 -- Similar processing for upper bound and high value
9440 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
9442 if UR_Le
(Hival
, Model_Num
) then
9443 Hival_Incl_EP
:= Model_Num
;
9445 Hival_Incl_EP
:= Model_Num
+ Small
;
9448 if UR_Is_Positive
(Hival_Incl_EP
) then
9449 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
9451 Hival_Excl_EP
:= Hival_Incl_EP
;
9454 -- One further adjustment is needed. In the case of subtypes, we
9455 -- cannot go outside the range of the base type, or we get
9456 -- peculiarities, and the base type range is already set. This
9457 -- only applies to the Incl values, since clearly the Excl values
9458 -- are already as restricted as they are allowed to be.
9461 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
9462 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
9465 -- Get size including and excluding end points
9467 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
9468 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
9470 -- No need to exclude end-points if it does not reduce size
9472 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
9473 Loval_Excl_EP
:= Loval_Incl_EP
;
9476 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
9477 Hival_Excl_EP
:= Hival_Incl_EP
;
9480 -- Now we set the actual size to be used. We want to use the
9481 -- bounds fudged up to include the end-points but only if this
9482 -- can be done without violating a specifically given size
9483 -- size clause or causing an unacceptable increase in size.
9485 -- Case of size clause given
9487 if Has_Size_Clause
(Typ
) then
9489 -- Use the inclusive size only if it is consistent with
9490 -- the explicitly specified size.
9492 if Size_Incl_EP
<= RM_Size
(Typ
) then
9493 Actual_Lo
:= Loval_Incl_EP
;
9494 Actual_Hi
:= Hival_Incl_EP
;
9495 Actual_Size
:= Size_Incl_EP
;
9497 -- If the inclusive size is too large, we try excluding
9498 -- the end-points (will be caught later if does not work).
9501 Actual_Lo
:= Loval_Excl_EP
;
9502 Actual_Hi
:= Hival_Excl_EP
;
9503 Actual_Size
:= Size_Excl_EP
;
9506 -- Case of size clause not given
9509 -- If we have a base type whose corresponding first subtype
9510 -- has an explicit size that is large enough to include our
9511 -- end-points, then do so. There is no point in working hard
9512 -- to get a base type whose size is smaller than the specified
9513 -- size of the first subtype.
9515 if Has_Size_Clause
(Ftyp
)
9516 and then Size_Incl_EP
<= Esize
(Ftyp
)
9518 Actual_Size
:= Size_Incl_EP
;
9519 Actual_Lo
:= Loval_Incl_EP
;
9520 Actual_Hi
:= Hival_Incl_EP
;
9522 -- If excluding the end-points makes the size smaller and
9523 -- results in a size of 8,16,32,64, then we take the smaller
9524 -- size. For the 64 case, this is compulsory. For the other
9525 -- cases, it seems reasonable. We like to include end points
9526 -- if we can, but not at the expense of moving to the next
9527 -- natural boundary of size.
9529 elsif Size_Incl_EP
/= Size_Excl_EP
9530 and then Addressable
(Size_Excl_EP
)
9532 Actual_Size
:= Size_Excl_EP
;
9533 Actual_Lo
:= Loval_Excl_EP
;
9534 Actual_Hi
:= Hival_Excl_EP
;
9536 -- Otherwise we can definitely include the end points
9539 Actual_Size
:= Size_Incl_EP
;
9540 Actual_Lo
:= Loval_Incl_EP
;
9541 Actual_Hi
:= Hival_Incl_EP
;
9544 -- One pathological case: normally we never fudge a low bound
9545 -- down, since it would seem to increase the size (if it has
9546 -- any effect), but for ranges containing single value, or no
9547 -- values, the high bound can be small too large. Consider:
9549 -- type t is delta 2.0**(-14)
9550 -- range 131072.0 .. 0;
9552 -- That lower bound is *just* outside the range of 32 bits, and
9553 -- does need fudging down in this case. Note that the bounds
9554 -- will always have crossed here, since the high bound will be
9555 -- fudged down if necessary, as in the case of:
9557 -- type t is delta 2.0**(-14)
9558 -- range 131072.0 .. 131072.0;
9560 -- So we detect the situation by looking for crossed bounds,
9561 -- and if the bounds are crossed, and the low bound is greater
9562 -- than zero, we will always back it off by small, since this
9563 -- is completely harmless.
9565 if Actual_Lo
> Actual_Hi
then
9566 if UR_Is_Positive
(Actual_Lo
) then
9567 Actual_Lo
:= Loval_Incl_EP
- Small
;
9568 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9570 -- And of course, we need to do exactly the same parallel
9571 -- fudge for flat ranges in the negative region.
9573 elsif UR_Is_Negative
(Actual_Hi
) then
9574 Actual_Hi
:= Hival_Incl_EP
+ Small
;
9575 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9580 Set_Realval
(Lo
, Actual_Lo
);
9581 Set_Realval
(Hi
, Actual_Hi
);
9584 -- Enforce some limitations for ordinary fixed-point types. They come
9585 -- from an exact algorithm used to implement Text_IO.Fixed_IO and the
9586 -- Fore, Image and Value attributes. The requirement on the Small is
9587 -- to lie in the range 2**(-(Siz - 1)) .. 2**(Siz - 1) for a type of
9588 -- Siz bits (Siz=32,64,128) and the requirement on the bounds is to
9589 -- be smaller in magnitude than 10.0**N * 2**(Siz - 1), where N is
9590 -- given by the formula N = floor ((Siz - 1) * log 2 / log 10).
9592 -- If the bounds of a 32-bit type are too large, force 64-bit type
9594 if Actual_Size
<= 32
9595 and then Small
<= Ureal_2_31
9596 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_2_10_18
)
9597 or else Larger
(Expr_Value_R
(Hi
), Ureal_2_10_18
))
9602 -- If the bounds of a 64-bit type are too large, force 128-bit type
9604 if System_Max_Integer_Size
= 128
9605 and then Actual_Size
<= 64
9606 and then Small
<= Ureal_2_63
9607 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
)
9608 or else Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
))
9613 -- Give error messages for first subtypes and not base types, as the
9614 -- bounds of base types are always maximum for their size, see below.
9616 if System_Max_Integer_Size
< 128 and then Typ
/= Btyp
then
9618 -- See the 128-bit case below for the reason why we cannot test
9619 -- against the 2**(-63) .. 2**63 range. This quirk should have
9620 -- been kludged around as in the 128-bit case below, but it was
9621 -- not and we end up with a ludicrous range as a result???
9623 if Small
< Ureal_2_M_80
then
9624 Error_Msg_Name_1
:= Name_Small
;
9626 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", Typ
);
9628 elsif Small
> Ureal_2_80
then
9629 Error_Msg_Name_1
:= Name_Small
;
9631 ("`&''%` too large, maximum allowed is 2.0'*'*80", Typ
);
9634 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
) then
9635 Error_Msg_Name_1
:= Name_First
;
9637 ("`&''%` too small, minimum allowed is -9.0E+36", Typ
);
9640 if Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
) then
9641 Error_Msg_Name_1
:= Name_Last
;
9643 ("`&''%` too large, maximum allowed is 9.0E+36", Typ
);
9646 elsif System_Max_Integer_Size
= 128 and then Typ
/= Btyp
then
9648 -- ACATS c35902d tests a delta equal to 2**(-(Max_Mantissa + 1))
9649 -- but we cannot really support anything smaller than Fine_Delta
9650 -- because of the way we implement I/O for fixed point types???
9652 if Small
= Ureal_2_M_128
then
9655 elsif Small
< Ureal_2_M_127
then
9656 Error_Msg_Name_1
:= Name_Small
;
9658 ("`&''%` too small, minimum allowed is 2.0'*'*(-127)", Typ
);
9660 elsif Small
> Ureal_2_127
then
9661 Error_Msg_Name_1
:= Name_Small
;
9663 ("`&''%` too large, maximum allowed is 2.0'*'*127", Typ
);
9667 and then (Norm_Num
(Small
) > Uint_2
** 127
9668 or else Norm_Den
(Small
) > Uint_2
** 127)
9669 and then Small
/= Ureal_2_M_128
9671 Error_Msg_Name_1
:= Name_Small
;
9673 ("`&''%` not the ratio of two 128-bit integers", Typ
);
9676 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_10_76
) then
9677 Error_Msg_Name_1
:= Name_First
;
9679 ("`&''%` too small, minimum allowed is -1.0E+76", Typ
);
9682 if Larger
(Expr_Value_R
(Hi
), Ureal_10_76
) then
9683 Error_Msg_Name_1
:= Name_Last
;
9685 ("`&''%` too large, maximum allowed is 1.0E+76", Typ
);
9689 -- For the decimal case, none of this fudging is required, since there
9690 -- are no end-point problems in the decimal case (the end-points are
9691 -- always included).
9694 Actual_Size
:= Fsize
(Loval
, Hival
);
9697 -- At this stage, the actual size has been calculated and the proper
9698 -- required bounds are stored in the low and high bounds.
9700 if Actual_Size
> System_Max_Integer_Size
then
9701 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
9702 Error_Msg_Uint_2
:= UI_From_Int
(System_Max_Integer_Size
);
9704 ("size required (^) for type& too large, maximum allowed is ^",
9706 Actual_Size
:= System_Max_Integer_Size
;
9709 -- Check size against explicit given size
9711 if Has_Size_Clause
(Typ
) then
9712 if Actual_Size
> RM_Size
(Typ
) then
9713 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9714 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
9716 ("size given (^) for type& too small, minimum allowed is ^",
9717 Size_Clause
(Typ
), Typ
);
9720 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
9723 -- Increase size to next natural boundary if no size clause given
9726 if Actual_Size
<= 8 then
9728 elsif Actual_Size
<= 16 then
9730 elsif Actual_Size
<= 32 then
9732 elsif Actual_Size
<= 64 then
9738 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9739 Adjust_Esize_For_Alignment
(Typ
);
9742 -- If we have a base type, then expand the bounds so that they extend to
9743 -- the full width of the allocated size in bits, to avoid junk range
9744 -- checks on intermediate computations.
9747 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
9748 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
9751 -- Final step is to reanalyze the bounds using the proper type
9752 -- and set the Corresponding_Integer_Value fields of the literals.
9754 Set_Etype
(Lo
, Empty
);
9755 Set_Analyzed
(Lo
, False);
9758 -- Resolve with universal fixed if the base type, and with the base
9759 -- type if we are freezing a subtype. Note we can't resolve the base
9760 -- type with itself, that would be a reference before definition.
9761 -- The resolution of the bounds of a subtype, if they are given by real
9762 -- literals, includes the setting of the Corresponding_Integer_Value,
9763 -- as for other literals of a fixed-point type.
9766 Resolve
(Lo
, Universal_Fixed
);
9767 Set_Corresponding_Integer_Value
9768 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
9773 -- Similar processing for high bound
9775 Set_Etype
(Hi
, Empty
);
9776 Set_Analyzed
(Hi
, False);
9780 Resolve
(Hi
, Universal_Fixed
);
9781 Set_Corresponding_Integer_Value
9782 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
9787 -- Set type of range to correspond to bounds
9789 Set_Etype
(Rng
, Etype
(Lo
));
9791 -- Set Esize to calculated size if not set already
9793 if not Known_Esize
(Typ
) then
9794 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9797 -- Set RM_Size if not already set. If already set, check value
9800 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
9803 if Known_RM_Size
(Typ
) then
9804 if RM_Size
(Typ
) < Minsiz
then
9805 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9806 Error_Msg_Uint_2
:= Minsiz
;
9808 ("size given (^) for type& too small, minimum allowed is ^",
9809 Size_Clause
(Typ
), Typ
);
9813 Set_RM_Size
(Typ
, Minsiz
);
9817 -- Check for shaving
9819 if Comes_From_Source
(Typ
) then
9821 -- In SPARK mode the given bounds must be strictly representable
9823 if SPARK_Mode
= On
then
9824 if Orig_Lo
< Expr_Value_R
(Lo
) then
9826 ("declared low bound of type & is outside type range",
9830 if Orig_Hi
> Expr_Value_R
(Hi
) then
9832 ("declared high bound of type & is outside type range",
9837 if Orig_Lo
< Expr_Value_R
(Lo
) then
9839 ("declared low bound of type & is outside type range??", Typ
);
9841 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
9844 if Orig_Hi
> Expr_Value_R
(Hi
) then
9846 ("declared high bound of type & is outside type range??",
9849 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
9853 end Freeze_Fixed_Point_Type
;
9859 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
9863 Set_Has_Delayed_Freeze
(T
);
9864 L
:= Freeze_Entity
(T
, N
);
9866 Insert_Actions
(N
, L
);
9869 --------------------------
9870 -- Freeze_Static_Object --
9871 --------------------------
9873 procedure Freeze_Static_Object
(E
: Entity_Id
) is
9875 Cannot_Be_Static
: exception;
9876 -- Exception raised if the type of a static object cannot be made
9877 -- static. This happens if the type depends on non-global objects.
9879 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
9880 -- Called to ensure that an expression used as part of a type definition
9881 -- is statically allocatable, which means that the expression type is
9882 -- statically allocatable, and the expression is either static, or a
9883 -- reference to a library level constant.
9885 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
9886 -- Called to mark a type as static, checking that it is possible
9887 -- to set the type as static. If it is not possible, then the
9888 -- exception Cannot_Be_Static is raised.
9890 -----------------------------
9891 -- Ensure_Expression_Is_SA --
9892 -----------------------------
9894 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
9898 Ensure_Type_Is_SA
(Etype
(N
));
9900 if Is_OK_Static_Expression
(N
) then
9903 elsif Nkind
(N
) = N_Identifier
then
9907 and then Ekind
(Ent
) = E_Constant
9908 and then Is_Library_Level_Entity
(Ent
)
9914 raise Cannot_Be_Static
;
9915 end Ensure_Expression_Is_SA
;
9917 -----------------------
9918 -- Ensure_Type_Is_SA --
9919 -----------------------
9921 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
9926 -- If type is library level, we are all set
9928 if Is_Library_Level_Entity
(Typ
) then
9932 -- We are also OK if the type already marked as statically allocated,
9933 -- which means we processed it before.
9935 if Is_Statically_Allocated
(Typ
) then
9939 -- Mark type as statically allocated
9941 Set_Is_Statically_Allocated
(Typ
);
9943 -- Check that it is safe to statically allocate this type
9945 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
9946 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
9947 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
9949 elsif Is_Array_Type
(Typ
) then
9950 N
:= First_Index
(Typ
);
9951 while Present
(N
) loop
9952 Ensure_Type_Is_SA
(Etype
(N
));
9956 Ensure_Type_Is_SA
(Component_Type
(Typ
));
9958 elsif Is_Access_Type
(Typ
) then
9959 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
9963 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
9966 if T
/= Standard_Void_Type
then
9967 Ensure_Type_Is_SA
(T
);
9970 F
:= First_Formal
(Designated_Type
(Typ
));
9971 while Present
(F
) loop
9972 Ensure_Type_Is_SA
(Etype
(F
));
9978 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
9981 elsif Is_Record_Type
(Typ
) then
9982 C
:= First_Entity
(Typ
);
9983 while Present
(C
) loop
9984 if Ekind
(C
) = E_Discriminant
9985 or else Ekind
(C
) = E_Component
9987 Ensure_Type_Is_SA
(Etype
(C
));
9989 elsif Is_Type
(C
) then
9990 Ensure_Type_Is_SA
(C
);
9996 elsif Ekind
(Typ
) = E_Subprogram_Type
then
9997 Ensure_Type_Is_SA
(Etype
(Typ
));
9999 C
:= First_Formal
(Typ
);
10000 while Present
(C
) loop
10001 Ensure_Type_Is_SA
(Etype
(C
));
10006 raise Cannot_Be_Static
;
10008 end Ensure_Type_Is_SA
;
10010 -- Start of processing for Freeze_Static_Object
10013 Ensure_Type_Is_SA
(Etype
(E
));
10016 when Cannot_Be_Static
=>
10018 -- If the object that cannot be static is imported or exported, then
10019 -- issue an error message saying that this object cannot be imported
10020 -- or exported. If it has an address clause it is an overlay in the
10021 -- current partition and the static requirement is not relevant.
10022 -- Do not issue any error message when ignoring rep clauses.
10024 if Ignore_Rep_Clauses
then
10027 elsif Is_Imported
(E
) then
10028 if No
(Address_Clause
(E
)) then
10030 ("& cannot be imported (local type is not constant)", E
);
10033 -- Otherwise must be exported, something is wrong if compiler
10034 -- is marking something as statically allocated which cannot be).
10036 else pragma Assert
(Is_Exported
(E
));
10038 ("& cannot be exported (local type is not constant)", E
);
10040 end Freeze_Static_Object
;
10042 -----------------------
10043 -- Freeze_Subprogram --
10044 -----------------------
10046 procedure Freeze_Subprogram
(E
: Entity_Id
) is
10048 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
);
10049 -- Set the conventions of all anonymous access-to-subprogram formals and
10050 -- result subtype of subprogram Subp_Id to the convention of Subp_Id.
10052 ----------------------------
10053 -- Set_Profile_Convention --
10054 ----------------------------
10056 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
) is
10057 Conv
: constant Convention_Id
:= Convention
(Subp_Id
);
10059 procedure Set_Type_Convention
(Typ
: Entity_Id
);
10060 -- Set the convention of anonymous access-to-subprogram type Typ and
10061 -- its designated type to Conv.
10063 -------------------------
10064 -- Set_Type_Convention --
10065 -------------------------
10067 procedure Set_Type_Convention
(Typ
: Entity_Id
) is
10069 -- Set the convention on both the anonymous access-to-subprogram
10070 -- type and the subprogram type it points to because both types
10071 -- participate in conformance-related checks.
10073 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
10074 Set_Convention
(Typ
, Conv
);
10075 Set_Convention
(Designated_Type
(Typ
), Conv
);
10077 end Set_Type_Convention
;
10081 Formal
: Entity_Id
;
10083 -- Start of processing for Set_Profile_Convention
10086 Formal
:= First_Formal
(Subp_Id
);
10087 while Present
(Formal
) loop
10088 Set_Type_Convention
(Etype
(Formal
));
10089 Next_Formal
(Formal
);
10092 if Ekind
(Subp_Id
) = E_Function
then
10093 Set_Type_Convention
(Etype
(Subp_Id
));
10095 end Set_Profile_Convention
;
10100 Retype
: Entity_Id
;
10102 -- Start of processing for Freeze_Subprogram
10105 -- Subprogram may not have an address clause unless it is imported
10107 if Present
(Address_Clause
(E
)) then
10108 if not Is_Imported
(E
) then
10110 ("address clause can only be given for imported subprogram",
10111 Name
(Address_Clause
(E
)));
10115 -- Reset the Pure indication on an imported subprogram unless an
10116 -- explicit Pure_Function pragma was present or the subprogram is an
10117 -- intrinsic. We do this because otherwise it is an insidious error
10118 -- to call a non-pure function from pure unit and have calls
10119 -- mysteriously optimized away. What happens here is that the Import
10120 -- can bypass the normal check to ensure that pure units call only pure
10123 -- The reason for the intrinsic exception is that in general, intrinsic
10124 -- functions (such as shifts) are pure anyway. The only exceptions are
10125 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
10126 -- in any case, so no problem arises.
10129 and then Is_Pure
(E
)
10130 and then not Has_Pragma_Pure_Function
(E
)
10131 and then not Is_Intrinsic_Subprogram
(E
)
10133 Set_Is_Pure
(E
, False);
10136 -- For C++ constructors check that their external name has been given
10137 -- (either in pragma CPP_Constructor or in a pragma import).
10139 if Is_Constructor
(E
)
10140 and then Convention
(E
) = Convention_CPP
10142 (No
(Interface_Name
(E
))
10143 or else String_Equal
10144 (L
=> Strval
(Interface_Name
(E
)),
10145 R
=> Strval
(Get_Default_External_Name
(E
))))
10148 ("'C++ constructor must have external name or link name", E
);
10151 -- We also reset the Pure indication on a subprogram with an Address
10152 -- parameter, because the parameter may be used as a pointer and the
10153 -- referenced data may change even if the address value does not.
10155 -- Note that if the programmer gave an explicit Pure_Function pragma,
10156 -- then we believe the programmer, and leave the subprogram Pure. We
10157 -- also suppress this check on run-time files.
10160 and then Is_Subprogram
(E
)
10161 and then not Has_Pragma_Pure_Function
(E
)
10162 and then not Is_Internal_Unit
(Current_Sem_Unit
)
10164 Check_Function_With_Address_Parameter
(E
);
10167 -- Ensure that all anonymous access-to-subprogram types inherit the
10168 -- convention of their related subprogram (RM 6.3.1(13.1/5)). This is
10169 -- not done for a defaulted convention Ada because those types also
10170 -- default to Ada. Convention Protected must not be propagated when
10171 -- the subprogram is an entry because this would be illegal. The only
10172 -- way to force convention Protected on these kinds of types is to
10173 -- include keyword "protected" in the access definition. Conventions
10174 -- Entry and Intrinsic are also not propagated (specified by AI12-0207).
10176 if Convention
(E
) /= Convention_Ada
10177 and then Convention
(E
) /= Convention_Protected
10178 and then Convention
(E
) /= Convention_Entry
10179 and then Convention
(E
) /= Convention_Intrinsic
10181 Set_Profile_Convention
(E
);
10184 -- For non-foreign convention subprograms, this is where we create
10185 -- the extra formals (for accessibility level and constrained bit
10186 -- information). We delay this till the freeze point precisely so
10187 -- that we know the convention.
10189 if not Has_Foreign_Convention
(E
) then
10191 -- Extra formals of dispatching operations are added later by
10192 -- Expand_Freeze_Record_Type, which also adds extra formals to
10193 -- internal entities built to handle interface types.
10195 if not Is_Dispatching_Operation
(E
) then
10196 Create_Extra_Formals
(E
);
10199 ((Ekind
(E
) = E_Subprogram_Type
10200 and then Extra_Formals_OK
(E
))
10203 and then Extra_Formals_OK
(E
)
10205 (No
(Overridden_Operation
(E
))
10206 or else Extra_Formals_Match_OK
(E
,
10207 Ultimate_Alias
(Overridden_Operation
(E
))))));
10210 Set_Mechanisms
(E
);
10212 -- If this is convention Ada and a Valued_Procedure, that's odd
10214 if Ekind
(E
) = E_Procedure
10215 and then Is_Valued_Procedure
(E
)
10216 and then Convention
(E
) = Convention_Ada
10217 and then Warn_On_Export_Import
10220 ("??Valued_Procedure has no effect for convention Ada", E
);
10221 Set_Is_Valued_Procedure
(E
, False);
10224 -- Case of foreign convention
10227 Set_Mechanisms
(E
);
10229 -- For foreign conventions, warn about return of unconstrained array
10231 if Ekind
(E
) = E_Function
then
10232 Retype
:= Underlying_Type
(Etype
(E
));
10234 -- If no return type, probably some other error, e.g. a
10235 -- missing full declaration, so ignore.
10237 if No
(Retype
) then
10240 -- If the return type is generic, we have emitted a warning
10241 -- earlier on, and there is nothing else to check here. Specific
10242 -- instantiations may lead to erroneous behavior.
10244 elsif Is_Generic_Type
(Etype
(E
)) then
10247 -- Display warning if returning unconstrained array
10249 elsif Is_Array_Type
(Retype
)
10250 and then not Is_Constrained
(Retype
)
10252 -- Check appropriate warning is enabled (should we check for
10253 -- Warnings (Off) on specific entities here, probably so???)
10255 and then Warn_On_Export_Import
10258 ("?x?foreign convention function& should not return " &
10259 "unconstrained array", E
);
10264 -- If any of the formals for an exported foreign convention
10265 -- subprogram have defaults, then emit an appropriate warning since
10266 -- this is odd (default cannot be used from non-Ada code)
10268 if Is_Exported
(E
) then
10269 F
:= First_Formal
(E
);
10270 while Present
(F
) loop
10271 if Warn_On_Export_Import
10272 and then Present
(Default_Value
(F
))
10275 ("?x?parameter cannot be defaulted in non-Ada call",
10276 Default_Value
(F
));
10284 -- Pragma Inline_Always is disallowed for dispatching subprograms
10285 -- because the address of such subprograms is saved in the dispatch
10286 -- table to support dispatching calls, and dispatching calls cannot
10287 -- be inlined. This is consistent with the restriction against using
10288 -- 'Access or 'Address on an Inline_Always subprogram.
10290 if Is_Dispatching_Operation
(E
)
10291 and then Has_Pragma_Inline_Always
(E
)
10294 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
10297 if Is_Dispatching_Operation
(E
)
10298 and then Present
(Overridden_Operation
(E
))
10300 Local_Restrict
.Check_Overriding
10301 (Overrider_Op
=> E
, Overridden_Op
=> Overridden_Operation
(E
));
10304 -- Because of the implicit representation of inherited predefined
10305 -- operators in the front-end, the overriding status of the operation
10306 -- may be affected when a full view of a type is analyzed, and this is
10307 -- not captured by the analysis of the corresponding type declaration.
10308 -- Therefore the correctness of a not-overriding indicator must be
10309 -- rechecked when the subprogram is frozen.
10311 if Nkind
(E
) = N_Defining_Operator_Symbol
10312 and then not Error_Posted
(Parent
(E
))
10314 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
10317 Retype
:= Get_Fullest_View
(Etype
(E
));
10319 if Transform_Function_Array
10320 and then Nkind
(Parent
(E
)) = N_Function_Specification
10321 and then Is_Array_Type
(Retype
)
10322 and then Is_Constrained
(Retype
)
10323 and then not Is_Unchecked_Conversion_Instance
(E
)
10324 and then not Rewritten_For_C
(E
)
10326 Build_Procedure_Form
(Unit_Declaration_Node
(E
));
10328 end Freeze_Subprogram
;
10330 ----------------------
10331 -- Is_Fully_Defined --
10332 ----------------------
10334 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
10336 if Ekind
(T
) = E_Class_Wide_Type
then
10337 return Is_Fully_Defined
(Etype
(T
));
10339 elsif Is_Array_Type
(T
) then
10340 return Is_Fully_Defined
(Component_Type
(T
));
10342 elsif Is_Record_Type
(T
)
10343 and not Is_Private_Type
(T
)
10345 -- Verify that the record type has no components with private types
10346 -- without completion.
10352 Comp
:= First_Component
(T
);
10353 while Present
(Comp
) loop
10354 if not Is_Fully_Defined
(Etype
(Comp
)) then
10358 Next_Component
(Comp
);
10363 -- For the designated type of an access to subprogram, all types in
10364 -- the profile must be fully defined.
10366 elsif Ekind
(T
) = E_Subprogram_Type
then
10371 F
:= First_Formal
(T
);
10372 while Present
(F
) loop
10373 if not Is_Fully_Defined
(Etype
(F
)) then
10380 return Is_Fully_Defined
(Etype
(T
));
10384 return not Is_Private_Type
(T
)
10385 or else Present
(Full_View
(Base_Type
(T
)));
10387 end Is_Fully_Defined
;
10389 ---------------------------------
10390 -- Process_Default_Expressions --
10391 ---------------------------------
10393 procedure Process_Default_Expressions
10395 After
: in out Node_Id
)
10397 Loc
: constant Source_Ptr
:= Sloc
(E
);
10404 Set_Default_Expressions_Processed
(E
);
10406 -- A subprogram instance and its associated anonymous subprogram share
10407 -- their signature. The default expression functions are defined in the
10408 -- wrapper packages for the anonymous subprogram, and should not be
10409 -- generated again for the instance.
10411 if Is_Generic_Instance
(E
)
10412 and then Present
(Alias
(E
))
10413 and then Default_Expressions_Processed
(Alias
(E
))
10418 Formal
:= First_Formal
(E
);
10419 while Present
(Formal
) loop
10420 if Present
(Default_Value
(Formal
)) then
10422 -- We work with a copy of the default expression because we
10423 -- do not want to disturb the original, since this would mess
10424 -- up the conformance checking.
10426 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
10428 -- The analysis of the expression may generate insert actions,
10429 -- which of course must not be executed. We wrap those actions
10430 -- in a procedure that is not called, and later on eliminated.
10431 -- The following cases have no side effects, and are analyzed
10434 if Nkind
(Dcopy
) = N_Identifier
10435 or else Nkind
(Dcopy
) in N_Expanded_Name
10436 | N_Integer_Literal
10437 | N_Character_Literal
10440 or else (Nkind
(Dcopy
) = N_Attribute_Reference
10441 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
10442 or else Known_Null
(Dcopy
)
10444 -- If there is no default function, we must still do a full
10445 -- analyze call on the default value, to ensure that all error
10446 -- checks are performed, e.g. those associated with static
10447 -- evaluation. Note: this branch will always be taken if the
10448 -- analyzer is turned off (but we still need the error checks).
10450 -- Note: the setting of parent here is to meet the requirement
10451 -- that we can only analyze the expression while attached to
10452 -- the tree. Really the requirement is that the parent chain
10453 -- be set, we don't actually need to be in the tree.
10455 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
10458 -- Default expressions are resolved with their own type if the
10459 -- context is generic, to avoid anomalies with private types.
10461 if Ekind
(Scope
(E
)) = E_Generic_Package
then
10464 Resolve
(Dcopy
, Etype
(Formal
));
10467 -- If that resolved expression will raise constraint error,
10468 -- then flag the default value as raising constraint error.
10469 -- This allows a proper error message on the calls.
10471 if Raises_Constraint_Error
(Dcopy
) then
10472 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
10475 -- If the default is a parameterless call, we use the name of
10476 -- the called function directly, and there is no body to build.
10478 elsif Nkind
(Dcopy
) = N_Function_Call
10479 and then No
(Parameter_Associations
(Dcopy
))
10483 -- Else construct and analyze the body of a wrapper procedure
10484 -- that contains an object declaration to hold the expression.
10485 -- Given that this is done only to complete the analysis, it is
10486 -- simpler to build a procedure than a function which might
10487 -- involve secondary stack expansion.
10490 Dnam
:= Make_Temporary
(Loc
, 'D');
10493 Make_Subprogram_Body
(Loc
,
10495 Make_Procedure_Specification
(Loc
,
10496 Defining_Unit_Name
=> Dnam
),
10498 Declarations
=> New_List
(
10499 Make_Object_Declaration
(Loc
,
10500 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
10501 Object_Definition
=>
10502 New_Occurrence_Of
(Etype
(Formal
), Loc
),
10503 Expression
=> New_Copy_Tree
(Dcopy
))),
10505 Handled_Statement_Sequence
=>
10506 Make_Handled_Sequence_Of_Statements
(Loc
,
10507 Statements
=> Empty_List
));
10509 Set_Scope
(Dnam
, Scope
(E
));
10510 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
10511 Set_Is_Eliminated
(Dnam
);
10512 Insert_After
(After
, Dbody
);
10518 Next_Formal
(Formal
);
10520 end Process_Default_Expressions
;
10522 ----------------------------------------
10523 -- Set_Component_Alignment_If_Not_Set --
10524 ----------------------------------------
10526 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
10528 -- Ignore if not base type, subtypes don't need anything
10530 if Typ
/= Base_Type
(Typ
) then
10534 -- Do not override existing representation
10536 if Is_Packed
(Typ
) then
10539 elsif Has_Specified_Layout
(Typ
) then
10542 elsif Component_Alignment
(Typ
) /= Calign_Default
then
10546 Set_Component_Alignment
10547 (Typ
, Scope_Stack
.Table
10548 (Scope_Stack
.Last
).Component_Alignment_Default
);
10550 end Set_Component_Alignment_If_Not_Set
;
10552 --------------------------
10553 -- Set_SSO_From_Default --
10554 --------------------------
10556 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
10557 Reversed
: Boolean;
10560 -- Set default SSO for an array or record base type, except in case of
10561 -- a type extension (which always inherits the SSO of its parent type).
10563 if Is_Base_Type
(T
)
10564 and then (Is_Array_Type
(T
)
10565 or else (Is_Record_Type
(T
)
10566 and then not (Is_Tagged_Type
(T
)
10567 and then Is_Derived_Type
(T
))))
10570 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
10572 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
10574 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
10576 -- For a record type, if bit order is specified explicitly,
10577 -- then do not set SSO from default if not consistent. Note that
10578 -- we do not want to look at a Bit_Order attribute definition
10579 -- for a parent: if we were to inherit Bit_Order, then both
10580 -- SSO_Set_*_By_Default flags would have been cleared already
10581 -- (by Inherit_Aspects_At_Freeze_Point).
10584 (Is_Record_Type
(T
)
10586 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
10587 and then Reverse_Bit_Order
(T
) /= Reversed
)
10589 -- If flags cause reverse storage order, then set the result. Note
10590 -- that we would have ignored the pragma setting the non default
10591 -- storage order in any case, hence the assertion at this point.
10594 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
10596 Set_Reverse_Storage_Order
(T
, Reversed
);
10598 -- For a record type, also set reversed bit order. Note: if a bit
10599 -- order has been specified explicitly, then this is a no-op.
10601 if Is_Record_Type
(T
) then
10602 Set_Reverse_Bit_Order
(T
, Reversed
);
10606 end Set_SSO_From_Default
;
10612 procedure Undelay_Type
(T
: Entity_Id
) is
10614 Set_Has_Delayed_Freeze
(T
, False);
10615 Set_Freeze_Node
(T
, Empty
);
10617 -- Since we don't want T to have a Freeze_Node, we don't want its
10618 -- Full_View or Corresponding_Record_Type to have one either.
10620 -- ??? Fundamentally, this whole handling is unpleasant. What we really
10621 -- want is to be sure that for an Itype that's part of record R and is a
10622 -- subtype of type T, that it's frozen after the later of the freeze
10623 -- points of R and T. We have no way of doing that directly, so what we
10624 -- do is force most such Itypes to be frozen as part of freezing R via
10625 -- this procedure and only delay the ones that need to be delayed
10626 -- (mostly the designated types of access types that are defined as part
10629 if Is_Private_Type
(T
)
10630 and then Present
(Full_View
(T
))
10631 and then Is_Itype
(Full_View
(T
))
10632 and then Is_Record_Type
(Scope
(Full_View
(T
)))
10634 Undelay_Type
(Full_View
(T
));
10637 if Is_Concurrent_Type
(T
)
10638 and then Present
(Corresponding_Record_Type
(T
))
10639 and then Is_Itype
(Corresponding_Record_Type
(T
))
10640 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
10642 Undelay_Type
(Corresponding_Record_Type
(T
));
10650 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
) is
10651 Ent
: constant Entity_Id
:= Entity
(Nam
);
10652 -- The object to which the address clause applies
10655 Old
: Entity_Id
:= Empty
;
10659 -- No warning if address clause overlay warnings are off
10661 if not Address_Clause_Overlay_Warnings
then
10665 -- No warning if there is an explicit initialization
10667 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
10669 if Present
(Init
) and then Comes_From_Source
(Init
) then
10673 -- We only give the warning for non-imported entities of a type for
10674 -- which a non-null base init proc is defined, or for objects of access
10675 -- types with implicit null initialization, or when Normalize_Scalars
10676 -- applies and the type is scalar or a string type (the latter being
10677 -- tested for because predefined String types are initialized by inline
10678 -- code rather than by an init_proc). Note that we do not give the
10679 -- warning for Initialize_Scalars, since we suppressed initialization
10680 -- in this case. Also, do not warn if Suppress_Initialization is set
10681 -- either on the type, or on the object via pragma or aspect.
10684 and then not Is_Imported
(Ent
)
10685 and then not Initialization_Suppressed
(Typ
)
10686 and then not (Ekind
(Ent
) = E_Variable
10687 and then Initialization_Suppressed
(Ent
))
10688 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
10689 or else Is_Access_Type
(Typ
)
10690 or else (Normalize_Scalars
10691 and then (Is_Scalar_Type
(Typ
)
10692 or else Is_String_Type
(Typ
))))
10694 if Nkind
(Expr
) = N_Attribute_Reference
10695 and then Is_Entity_Name
(Prefix
(Expr
))
10697 Old
:= Entity
(Prefix
(Expr
));
10699 elsif Is_Entity_Name
(Expr
)
10700 and then Ekind
(Entity
(Expr
)) = E_Constant
10702 Decl
:= Declaration_Node
(Entity
(Expr
));
10704 if Nkind
(Decl
) = N_Object_Declaration
10705 and then Present
(Expression
(Decl
))
10706 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
10707 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
10709 Old
:= Entity
(Prefix
(Expression
(Decl
)));
10711 elsif Nkind
(Expr
) = N_Function_Call
then
10715 -- A function call (most likely to To_Address) is probably not an
10716 -- overlay, so skip warning. Ditto if the function call was inlined
10717 -- and transformed into an entity.
10719 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
10723 -- If a pragma Import follows, we assume that it is for the current
10724 -- target of the address clause, and skip the warning. There may be
10725 -- a source pragma or an aspect that specifies import and generates
10726 -- the corresponding pragma. These will indicate that the entity is
10727 -- imported and that is checked above so that the spurious warning
10728 -- (generated when the entity is frozen) will be suppressed. The
10729 -- pragma may be attached to the aspect, so it is not yet a list
10732 if Is_List_Member
(Parent
(Expr
)) then
10733 Decl
:= Next
(Parent
(Expr
));
10736 and then Nkind
(Decl
) = N_Pragma
10737 and then Pragma_Name
(Decl
) = Name_Import
10743 -- Otherwise give warning message
10745 if Present
(Old
) then
10746 Error_Msg_Node_2
:= Old
;
10748 ("default initialization of & may modify &?o?",
10752 ("default initialization of & may modify overlaid storage?o?",
10756 -- Add friendly warning if initialization comes from a packed array
10759 if Is_Record_Type
(Typ
) then
10764 Comp
:= First_Component
(Typ
);
10765 while Present
(Comp
) loop
10766 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
10767 and then Present
(Expression
(Parent
(Comp
)))
10770 elsif Is_Array_Type
(Etype
(Comp
))
10771 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
10774 ("\packed array component& " &
10775 "will be initialized to zero??",
10779 Next_Component
(Comp
);
10786 ("\use pragma Import for & to " &
10787 "suppress initialization (RM B.1(24))??",