1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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
) = N_Aggregate
226 and then Base_Type
(Etype
(N
)) = Base_Type
(Typ
)
232 end Is_Dispatching_Call_Or_Aggregate
;
234 -------------------------
235 -- Need_Dispatch_Table --
236 -------------------------
238 function Need_Dispatch_Table
is new
239 Traverse_Func
(Is_Dispatching_Call_Or_Aggregate
);
240 -- Return Abandon if the input expression requires access to
241 -- Typ's dispatch table.
243 Decl
: constant Node_Id
:=
244 (if No
(E
) then E
else Original_Node
(Unit_Declaration_Node
(E
)));
246 -- Start of processing for Should_Freeze_Type
249 return Within_Scope
(Typ
, Current_Scope
)
250 or else (Nkind
(N
) = N_Subprogram_Renaming_Declaration
251 and then Present
(Corresponding_Formal_Spec
(N
)))
252 or else (Present
(Decl
)
253 and then Nkind
(Decl
) = N_Expression_Function
254 and then Need_Dispatch_Table
(Expression
(Decl
)) = Abandon
);
255 end Should_Freeze_Type
;
257 procedure Process_Default_Expressions
259 After
: in out Node_Id
);
260 -- This procedure is called for each subprogram to complete processing of
261 -- default expressions at the point where all types are known to be frozen.
262 -- The expressions must be analyzed in full, to make sure that all error
263 -- processing is done (they have only been preanalyzed). If the expression
264 -- is not an entity or literal, its analysis may generate code which must
265 -- not be executed. In that case we build a function body to hold that
266 -- code. This wrapper function serves no other purpose (it used to be
267 -- called to evaluate the default, but now the default is inlined at each
270 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
271 -- Typ is a record or array type that is being frozen. This routine sets
272 -- the default component alignment from the scope stack values if the
273 -- alignment is otherwise not specified.
275 procedure Set_SSO_From_Default
(T
: Entity_Id
);
276 -- T is a record or array type that is being frozen. If it is a base type,
277 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
278 -- will be set appropriately. Note that an explicit occurrence of aspect
279 -- Scalar_Storage_Order or an explicit setting of this aspect with an
280 -- attribute definition clause occurs, then these two flags are reset in
281 -- any case, so call will have no effect.
283 procedure Undelay_Type
(T
: Entity_Id
);
284 -- T is a type of a component that we know to be an Itype. We don't want
285 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
286 -- Full_View or Corresponding_Record_Type.
288 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
);
289 -- Expr is the expression for an address clause for the entity denoted by
290 -- Nam whose type is Typ. If Typ has a default initialization, and there is
291 -- no explicit initialization in the source declaration, check whether the
292 -- address clause might cause overlaying of an entity, and emit a warning
293 -- on the side effect that the initialization will cause.
295 -------------------------------
296 -- Adjust_Esize_For_Alignment --
297 -------------------------------
299 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
303 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
304 Align
:= Alignment_In_Bits
(Typ
);
306 if Align
> Esize
(Typ
) and then Align
<= System_Max_Integer_Size
then
307 Set_Esize
(Typ
, Align
);
310 end Adjust_Esize_For_Alignment
;
312 ------------------------------------
313 -- Build_And_Analyze_Renamed_Body --
314 ------------------------------------
316 procedure Build_And_Analyze_Renamed_Body
319 After
: in out Node_Id
)
321 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
322 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
324 Renamed_Subp
: Entity_Id
;
327 -- If the renamed subprogram is intrinsic, there is no need for a
328 -- wrapper body: we set the alias that will be called and expanded which
329 -- completes the declaration. This transformation is only legal if the
330 -- renamed entity has already been elaborated.
332 -- Note that it is legal for a renaming_as_body to rename an intrinsic
333 -- subprogram, as long as the renaming occurs before the new entity
334 -- is frozen (RM 8.5.4 (5)).
336 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
337 and then Is_Entity_Name
(Name
(Body_Decl
))
339 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
341 Renamed_Subp
:= Empty
;
344 if Present
(Renamed_Subp
)
345 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
347 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
348 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
350 -- We can make the renaming entity intrinsic if the renamed function
351 -- has an interface name, or if it is one of the shift/rotate
352 -- operations known to the compiler.
355 (Present
(Interface_Name
(Renamed_Subp
))
356 or else Chars
(Renamed_Subp
) in Name_Rotate_Left
360 | Name_Shift_Right_Arithmetic
)
362 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
364 if Present
(Alias
(Renamed_Subp
)) then
365 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
367 Set_Alias
(Ent
, Renamed_Subp
);
370 Set_Is_Intrinsic_Subprogram
(Ent
);
371 Set_Has_Completion
(Ent
);
374 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
375 Insert_After
(After
, Body_Node
);
376 Mark_Rewrite_Insertion
(Body_Node
);
380 end Build_And_Analyze_Renamed_Body
;
382 ------------------------
383 -- Build_Renamed_Body --
384 ------------------------
386 function Build_Renamed_Body
388 New_S
: Entity_Id
) return Node_Id
390 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
391 -- We use for the source location of the renamed body, the location of
392 -- the spec entity. It might seem more natural to use the location of
393 -- the renaming declaration itself, but that would be wrong, since then
394 -- the body we create would look as though it was created far too late,
395 -- and this could cause problems with elaboration order analysis,
396 -- particularly in connection with instantiations.
398 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
399 Nam
: constant Node_Id
:= Name
(N
);
401 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
407 O_Formal
: Entity_Id
;
408 Param_Spec
: Node_Id
;
410 Pref
: Node_Id
:= Empty
;
411 -- If the renamed entity is a primitive operation given in prefix form,
412 -- the prefix is the target object and it has to be added as the first
413 -- actual in the generated call.
416 -- Determine the entity being renamed, which is the target of the call
417 -- statement. If the name is an explicit dereference, this is a renaming
418 -- of a subprogram type rather than a subprogram. The name itself is
421 if Nkind
(Nam
) = N_Selected_Component
then
422 Old_S
:= Entity
(Selector_Name
(Nam
));
424 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
425 Old_S
:= Etype
(Nam
);
427 elsif Nkind
(Nam
) = N_Indexed_Component
then
428 if Is_Entity_Name
(Prefix
(Nam
)) then
429 Old_S
:= Entity
(Prefix
(Nam
));
431 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
434 elsif Nkind
(Nam
) = N_Character_Literal
then
435 Old_S
:= Etype
(New_S
);
438 Old_S
:= Entity
(Nam
);
441 if Is_Entity_Name
(Nam
) then
443 -- If the renamed entity is a predefined operator, retain full name
444 -- to ensure its visibility.
446 if Ekind
(Old_S
) = E_Operator
447 and then Nkind
(Nam
) = N_Expanded_Name
449 Call_Name
:= New_Copy
(Name
(N
));
451 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
455 if Nkind
(Nam
) = N_Selected_Component
456 and then Present
(First_Formal
(Old_S
))
458 (Is_Controlling_Formal
(First_Formal
(Old_S
))
459 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
462 -- Retrieve the target object, to be added as a first actual
465 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
466 Pref
:= Prefix
(Nam
);
469 Call_Name
:= New_Copy
(Name
(N
));
472 -- Original name may have been overloaded, but is fully resolved now
474 Set_Is_Overloaded
(Call_Name
, False);
477 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
479 Make_Subprogram_Declaration
(Loc
,
480 Specification
=> Specification
(N
)));
483 -- For simple renamings, subsequent calls can be expanded directly as
484 -- calls to the renamed entity. The body must be generated in any case
485 -- for calls that may appear elsewhere. This is not done in the case
486 -- where the subprogram is an instantiation because the actual proper
487 -- body has not been built yet.
489 if Ekind
(Old_S
) in E_Function | E_Procedure
490 and then not Is_Generic_Instance
(Old_S
)
492 Set_Body_To_Inline
(Decl
, Old_S
);
495 -- Check whether the return type is a limited view. If the subprogram
496 -- is already frozen the generated body may have a non-limited view
497 -- of the type, that must be used, because it is the one in the spec
498 -- of the renaming declaration.
500 if Ekind
(Old_S
) = E_Function
501 and then Is_Entity_Name
(Result_Definition
(Spec
))
504 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
506 if Has_Non_Limited_View
(Ret_Type
) then
507 Set_Result_Definition
508 (Spec
, New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
513 -- The body generated for this renaming is an internal artifact, and
514 -- does not constitute a freeze point for the called entity.
516 Set_Must_Not_Freeze
(Call_Name
);
518 Formal
:= First_Formal
(Defining_Entity
(Decl
));
520 if Present
(Pref
) then
522 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
523 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
526 -- The controlling formal may be an access parameter, or the
527 -- actual may be an access value, so adjust accordingly.
529 if Is_Access_Type
(Pref_Type
)
530 and then not Is_Access_Type
(Form_Type
)
533 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
535 elsif Is_Access_Type
(Form_Type
)
536 and then not Is_Access_Type
(Pref
)
540 Make_Attribute_Reference
(Loc
,
541 Attribute_Name
=> Name_Access
,
542 Prefix
=> Relocate_Node
(Pref
)));
544 Actuals
:= New_List
(Pref
);
548 elsif Present
(Formal
) then
555 while Present
(Formal
) loop
556 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
557 Next_Formal
(Formal
);
560 -- If the renamed entity is an entry, inherit its profile. For other
561 -- renamings as bodies, both profiles must be subtype conformant, so it
562 -- is not necessary to replace the profile given in the declaration.
563 -- However, default values that are aggregates are rewritten when
564 -- partially analyzed, so we recover the original aggregate to insure
565 -- that subsequent conformity checking works. Similarly, if the default
566 -- expression was constant-folded, recover the original expression.
568 Formal
:= First_Formal
(Defining_Entity
(Decl
));
570 if Present
(Formal
) then
571 O_Formal
:= First_Formal
(Old_S
);
572 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
573 while Present
(Formal
) loop
574 if Is_Entry
(Old_S
) then
575 if Nkind
(Parameter_Type
(Param_Spec
)) /=
578 Set_Etype
(Formal
, Etype
(O_Formal
));
579 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
582 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
583 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
584 Nkind
(Default_Value
(O_Formal
))
586 Set_Expression
(Param_Spec
,
587 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
590 Next_Formal
(Formal
);
591 Next_Formal
(O_Formal
);
596 -- If the renamed entity is a function, the generated body contains a
597 -- return statement. Otherwise, build a procedure call. If the entity is
598 -- an entry, subsequent analysis of the call will transform it into the
599 -- proper entry or protected operation call. If the renamed entity is
600 -- a character literal, return it directly.
602 if Ekind
(Old_S
) = E_Function
603 or else Ekind
(Old_S
) = E_Operator
604 or else (Ekind
(Old_S
) = E_Subprogram_Type
605 and then Etype
(Old_S
) /= Standard_Void_Type
)
608 Make_Simple_Return_Statement
(Loc
,
610 Make_Function_Call
(Loc
,
612 Parameter_Associations
=> Actuals
));
614 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
616 Make_Simple_Return_Statement
(Loc
,
617 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
619 elsif Nkind
(Nam
) = N_Character_Literal
then
621 Make_Simple_Return_Statement
(Loc
, Expression
=> Call_Name
);
625 Make_Procedure_Call_Statement
(Loc
,
627 Parameter_Associations
=> Actuals
);
630 -- Create entities for subprogram body and formals
632 Set_Defining_Unit_Name
(Spec
,
633 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
635 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
636 while Present
(Param_Spec
) loop
637 Set_Defining_Identifier
(Param_Spec
,
638 Make_Defining_Identifier
(Loc
,
639 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
643 -- In GNATprove, prefer to generate an expression function whenever
644 -- possible, to benefit from the more precise analysis in that case
645 -- (as if an implicit postcondition had been generated).
648 and then Nkind
(Call_Node
) = N_Simple_Return_Statement
651 Make_Expression_Function
(Loc
,
652 Specification
=> Spec
,
653 Expression
=> Expression
(Call_Node
));
656 Make_Subprogram_Body
(Loc
,
657 Specification
=> Spec
,
658 Declarations
=> New_List
,
659 Handled_Statement_Sequence
=>
660 Make_Handled_Sequence_Of_Statements
(Loc
,
661 Statements
=> New_List
(Call_Node
)));
664 -- Link the body to the entity whose declaration it completes. If
665 -- the body is analyzed when the renamed entity is frozen, it may
666 -- be necessary to restore the proper scope (see package Exp_Ch13).
668 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
669 and then Present
(Corresponding_Spec
(N
))
671 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
673 Set_Corresponding_Spec
(Body_Node
, New_S
);
677 end Build_Renamed_Body
;
679 --------------------------
680 -- Check_Address_Clause --
681 --------------------------
683 procedure Check_Address_Clause
(E
: Entity_Id
) is
684 Addr
: constant Node_Id
:= Address_Clause
(E
);
685 Typ
: constant Entity_Id
:= Etype
(E
);
690 Tag_Assign
: Node_Id
;
693 if Present
(Addr
) then
695 -- For a deferred constant, the initialization value is on full view
697 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
698 Decl
:= Declaration_Node
(Full_View
(E
));
700 Decl
:= Declaration_Node
(E
);
703 Expr
:= Expression
(Addr
);
705 if Needs_Constant_Address
(Decl
, Typ
) then
706 Check_Constant_Address_Clause
(Expr
, E
);
708 -- Has_Delayed_Freeze was set on E when the address clause was
709 -- analyzed, and must remain set because we want the address
710 -- clause to be elaborated only after any entity it references
711 -- has been elaborated.
714 -- If Rep_Clauses are to be ignored, remove address clause from
715 -- list attached to entity, because it may be illegal for gigi,
716 -- for example by breaking order of elaboration.
718 if Ignore_Rep_Clauses
then
723 Rep
:= First_Rep_Item
(E
);
726 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
730 and then Next_Rep_Item
(Rep
) /= Addr
736 if Present
(Rep
) then
737 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
741 -- And now remove the address clause
743 Kill_Rep_Clause
(Addr
);
745 elsif not Error_Posted
(Expr
)
746 and then not Needs_Finalization
(Typ
)
748 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
751 Init
:= Expression
(Decl
);
753 -- If a variable, or a non-imported constant, overlays a constant
754 -- object and has an initialization value, then the initialization
755 -- may end up writing into read-only memory. Detect the cases of
756 -- statically identical values and remove the initialization. In
757 -- the other cases, give a warning. We will give other warnings
758 -- later for the variable if it is assigned.
760 if (Ekind
(E
) = E_Variable
761 or else (Ekind
(E
) = E_Constant
762 and then not Is_Imported
(E
)))
763 and then Overlays_Constant
(E
)
764 and then Present
(Init
)
771 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
773 if Ekind
(O_Ent
) = E_Constant
774 and then Etype
(O_Ent
) = Typ
775 and then Present
(Constant_Value
(O_Ent
))
776 and then Compile_Time_Compare
778 Constant_Value
(O_Ent
),
779 Assume_Valid
=> True) = EQ
781 Set_No_Initialization
(Decl
);
784 elsif Comes_From_Source
(Init
)
785 and then Address_Clause_Overlay_Warnings
787 Error_Msg_Sloc
:= Sloc
(Addr
);
789 ("?o?constant& may be modified via address clause#",
795 -- Remove side effects from initial expression, except in the case of
796 -- limited build-in-place calls and aggregates, which have their own
797 -- expansion elsewhere. This exception is necessary to avoid copying
801 and then not Is_Inherently_Limited_Type
(Typ
)
803 -- Capture initialization value at point of declaration, and make
804 -- explicit assignment legal, because object may be a constant.
806 Remove_Side_Effects
(Init
);
807 Lhs
:= New_Occurrence_Of
(E
, Sloc
(Decl
));
808 Set_Assignment_OK
(Lhs
);
810 -- Move initialization to freeze actions, once the object has
811 -- been frozen and the address clause alignment check has been
814 Append_Freeze_Action
(E
,
815 Make_Assignment_Statement
(Sloc
(Decl
),
817 Expression
=> Expression
(Decl
)));
819 Set_No_Initialization
(Decl
);
821 -- If the object is tagged, check whether the tag must be
822 -- reassigned explicitly.
824 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
825 if Present
(Tag_Assign
) then
826 Append_Freeze_Action
(E
, Tag_Assign
);
830 end Check_Address_Clause
;
832 -----------------------------
833 -- Check_Compile_Time_Size --
834 -----------------------------
836 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
838 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
839 -- Sets the compile time known size in the RM_Size field of T, checking
840 -- for a size clause that was given which attempts to give a small size.
842 function Size_Known
(T
: Entity_Id
) return Boolean;
843 -- Recursive function that does all the work
845 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
846 -- If T is a constrained subtype, its size is not known if any of its
847 -- discriminant constraints is not static and it is not a null record.
848 -- The test is conservative and doesn't check that the components are
849 -- in fact constrained by non-static discriminant values. Could be made
856 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
858 if S
> System_Max_Integer_Size
then
861 -- Check for bad size clause given
863 elsif Has_Size_Clause
(T
) then
864 if RM_Size
(T
) < S
then
865 Error_Msg_Uint_1
:= S
;
866 Error_Msg_NE
(Size_Too_Small_Message
, Size_Clause
(T
), T
);
869 -- Set size if not set already. Do not set it to Uint_0, because in
870 -- some cases (notably array-of-record), the Component_Size is
871 -- No_Uint, which causes S to be Uint_0. Presumably the RM_Size and
872 -- Component_Size will eventually be set correctly by the back end.
874 elsif not Known_RM_Size
(T
) and then S
/= Uint_0
then
883 function Size_Known
(T
: Entity_Id
) return Boolean is
888 if Size_Known_At_Compile_Time
(T
) then
891 -- Always True for elementary types, even generic formal elementary
892 -- types. We used to return False in the latter case, but the size
893 -- is known at compile time, even in the template, we just do not
894 -- know the exact size but that's not the point of this routine.
896 elsif Is_Elementary_Type
(T
) or else Is_Task_Type
(T
) then
901 elsif Is_Array_Type
(T
) then
903 -- String literals always have known size, and we can set it
905 if Ekind
(T
) = E_String_Literal_Subtype
then
906 if Known_Component_Size
(T
) then
908 (T
, Component_Size
(T
) * String_Literal_Length
(T
));
911 -- The following is wrong, but does what previous versions
912 -- did. The Component_Size is unknown for the string in a
914 Set_Small_Size
(T
, Uint_0
);
919 -- Unconstrained types never have known at compile time size
921 elsif not Is_Constrained
(T
) then
924 -- Don't do any recursion on type with error posted, since we may
925 -- have a malformed type that leads us into a loop.
927 elsif Error_Posted
(T
) then
930 -- Otherwise if component size unknown, then array size unknown
932 elsif not Size_Known
(Component_Type
(T
)) then
936 -- Check for all indexes static, and also compute possible size
937 -- (in case it is not greater than System_Max_Integer_Size and
938 -- thus may be packable).
944 Size
: Uint
:= Component_Size
(T
);
948 -- See comment in Set_Small_Size above
954 Index
:= First_Index
(T
);
955 while Present
(Index
) loop
956 if Nkind
(Index
) = N_Range
then
957 Get_Index_Bounds
(Index
, Low
, High
);
959 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
963 Low
:= Type_Low_Bound
(Etype
(Index
));
964 High
:= Type_High_Bound
(Etype
(Index
));
967 if not Compile_Time_Known_Value
(Low
)
968 or else not Compile_Time_Known_Value
(High
)
969 or else Etype
(Index
) = Any_Type
974 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
986 Set_Small_Size
(T
, Size
);
990 -- For non-generic private types, go to underlying type if present
992 elsif Is_Private_Type
(T
)
993 and then not Is_Generic_Type
(T
)
994 and then Present
(Underlying_Type
(T
))
996 -- Don't do any recursion on type with error posted, since we may
997 -- have a malformed type that leads us into a loop.
999 if Error_Posted
(T
) then
1002 return Size_Known
(Underlying_Type
(T
));
1007 elsif Is_Record_Type
(T
) then
1009 -- A class-wide type is never considered to have a known size
1011 if Is_Class_Wide_Type
(T
) then
1014 -- A subtype of a variant record must not have non-static
1015 -- discriminated components.
1017 elsif T
/= Base_Type
(T
)
1018 and then not Static_Discriminated_Components
(T
)
1022 -- Don't do any recursion on type with error posted, since we may
1023 -- have a malformed type that leads us into a loop.
1025 elsif Error_Posted
(T
) then
1029 -- Now look at the components of the record
1032 -- The following two variables are used to keep track of the
1033 -- size of packed records if we can tell the size of the packed
1034 -- record in the front end. Packed_Size_Known is True if so far
1035 -- we can figure out the size. It is initialized to True for a
1036 -- packed record, unless the record has either discriminants or
1037 -- independent components, or is a strict-alignment type, since
1038 -- it cannot be fully packed in this case.
1040 -- The reason we eliminate the discriminated case is that
1041 -- we don't know the way the back end lays out discriminated
1042 -- packed records. If Packed_Size_Known is True, then
1043 -- Packed_Size is the size in bits so far.
1045 Packed_Size_Known
: Boolean :=
1047 and then not Has_Discriminants
(T
)
1048 and then not Has_Independent_Components
(T
)
1049 and then not Strict_Alignment
(T
);
1051 Packed_Size
: Uint
:= Uint_0
;
1052 -- Size in bits so far
1055 -- Test for variant part present
1057 if Has_Discriminants
(T
)
1058 and then Present
(Parent
(T
))
1059 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
1060 and then Nkind
(Type_Definition
(Parent
(T
))) =
1062 and then not Null_Present
(Type_Definition
(Parent
(T
)))
1064 Present
(Variant_Part
1065 (Component_List
(Type_Definition
(Parent
(T
)))))
1067 -- If variant part is present, and type is unconstrained,
1068 -- then we must have defaulted discriminants, or a size
1069 -- clause must be present for the type, or else the size
1070 -- is definitely not known at compile time.
1072 if not Is_Constrained
(T
)
1074 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
1075 and then not Known_RM_Size
(T
)
1081 -- Loop through components
1083 Comp
:= First_Component_Or_Discriminant
(T
);
1084 while Present
(Comp
) loop
1085 Ctyp
:= Etype
(Comp
);
1087 -- We do not know the packed size if there is a component
1088 -- clause present (we possibly could, but this would only
1089 -- help in the case of a record with partial rep clauses.
1090 -- That's because in the case of full rep clauses, the
1091 -- size gets figured out anyway by a different circuit).
1093 if Present
(Component_Clause
(Comp
)) then
1094 Packed_Size_Known
:= False;
1097 -- We do not know the packed size for an independent
1098 -- component or if it is of a strict-alignment type,
1099 -- since packing does not touch these (RM 13.2(7)).
1101 if Is_Independent
(Comp
)
1102 or else Is_Independent
(Ctyp
)
1103 or else Strict_Alignment
(Ctyp
)
1105 Packed_Size_Known
:= False;
1108 -- We need to identify a component that is an array where
1109 -- the index type is an enumeration type with non-standard
1110 -- representation, and some bound of the type depends on a
1113 -- This is because gigi computes the size by doing a
1114 -- substitution of the appropriate discriminant value in
1115 -- the size expression for the base type, and gigi is not
1116 -- clever enough to evaluate the resulting expression (which
1117 -- involves a call to rep_to_pos) at compile time.
1119 -- It would be nice if gigi would either recognize that
1120 -- this expression can be computed at compile time, or
1121 -- alternatively figured out the size from the subtype
1122 -- directly, where all the information is at hand ???
1124 if Is_Array_Type
(Etype
(Comp
))
1125 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1128 Ocomp
: constant Entity_Id
:=
1129 Original_Record_Component
(Comp
);
1130 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1136 Ind
:= First_Index
(OCtyp
);
1137 while Present
(Ind
) loop
1138 Indtyp
:= Etype
(Ind
);
1140 if Is_Enumeration_Type
(Indtyp
)
1141 and then Has_Non_Standard_Rep
(Indtyp
)
1143 Lo
:= Type_Low_Bound
(Indtyp
);
1144 Hi
:= Type_High_Bound
(Indtyp
);
1146 if Is_Entity_Name
(Lo
)
1147 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1151 elsif Is_Entity_Name
(Hi
)
1152 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1163 -- Clearly size of record is not known if the size of one of
1164 -- the components is not known.
1166 if not Size_Known
(Ctyp
) then
1170 -- Accumulate packed size if possible
1172 if Packed_Size_Known
then
1174 -- We can deal with elementary types, small packed arrays
1175 -- if the representation is a modular type and also small
1176 -- record types as checked by Set_Small_Size.
1178 if Is_Elementary_Type
(Ctyp
)
1179 or else (Is_Array_Type
(Ctyp
)
1181 (Packed_Array_Impl_Type
(Ctyp
))
1182 and then Is_Modular_Integer_Type
1183 (Packed_Array_Impl_Type
(Ctyp
)))
1184 or else Is_Record_Type
(Ctyp
)
1186 -- If RM_Size is known and static, then we can keep
1187 -- accumulating the packed size.
1189 if Known_Static_RM_Size
(Ctyp
) then
1191 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1193 -- If we have a field whose RM_Size is not known then
1194 -- we can't figure out the packed size here.
1197 Packed_Size_Known
:= False;
1200 -- For other types we can't figure out the packed size
1203 Packed_Size_Known
:= False;
1207 Next_Component_Or_Discriminant
(Comp
);
1210 if Packed_Size_Known
then
1211 Set_Small_Size
(T
, Packed_Size
);
1217 -- All other cases, size not known at compile time
1224 -------------------------------------
1225 -- Static_Discriminated_Components --
1226 -------------------------------------
1228 function Static_Discriminated_Components
1229 (T
: Entity_Id
) return Boolean
1231 Constraint
: Elmt_Id
;
1234 if Has_Discriminants
(T
)
1235 and then Present
(Discriminant_Constraint
(T
))
1236 and then Present
(First_Component
(T
))
1238 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1239 while Present
(Constraint
) loop
1240 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1244 Next_Elmt
(Constraint
);
1249 end Static_Discriminated_Components
;
1251 -- Start of processing for Check_Compile_Time_Size
1254 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1255 end Check_Compile_Time_Size
;
1257 -----------------------------------
1258 -- Check_Component_Storage_Order --
1259 -----------------------------------
1261 procedure Check_Component_Storage_Order
1262 (Encl_Type
: Entity_Id
;
1265 Comp_ADC_Present
: out Boolean)
1267 Comp_Base
: Entity_Id
;
1269 Encl_Base
: Entity_Id
;
1272 Component_Aliased
: Boolean;
1274 Comp_Byte_Aligned
: Boolean := False;
1275 -- Set for the record case, True if Comp is aligned on byte boundaries
1276 -- (in which case it is allowed to have different storage order).
1278 Comp_SSO_Differs
: Boolean;
1279 -- Set True when the component is a nested composite, and it does not
1280 -- have the same scalar storage order as Encl_Type.
1285 if Present
(Comp
) then
1287 Comp_Base
:= Etype
(Comp
);
1289 if Is_Tag
(Comp
) then
1290 Comp_Byte_Aligned
:= True;
1291 Component_Aliased
:= False;
1294 -- If a component clause is present, check if the component starts
1295 -- and ends on byte boundaries. Otherwise conservatively assume it
1296 -- does so only in the case where the record is not packed.
1298 if Present
(Component_Clause
(Comp
)) then
1299 Comp_Byte_Aligned
:=
1300 Known_Normalized_First_Bit
(Comp
)
1304 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0
1306 Esize
(Comp
) mod System_Storage_Unit
= 0;
1308 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1311 Component_Aliased
:= Is_Aliased
(Comp
);
1317 Err_Node
:= Encl_Type
;
1318 Comp_Base
:= Component_Type
(Encl_Type
);
1320 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1323 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1324 -- the attribute definition clause is attached to the first subtype.
1325 -- Also, if the base type is incomplete or private, go to full view
1328 Encl_Base
:= Base_Type
(Encl_Type
);
1329 if Present
(Underlying_Type
(Encl_Base
)) then
1330 Encl_Base
:= Underlying_Type
(Encl_Base
);
1333 Comp_Base
:= Base_Type
(Comp_Base
);
1334 if Present
(Underlying_Type
(Comp_Base
)) then
1335 Comp_Base
:= Underlying_Type
(Comp_Base
);
1339 Get_Attribute_Definition_Clause
1340 (First_Subtype
(Comp_Base
), Attribute_Scalar_Storage_Order
);
1341 Comp_ADC_Present
:= Present
(Comp_ADC
);
1343 -- Case of record or array component: check storage order compatibility.
1344 -- But, if the record has Complex_Representation, then it is treated as
1345 -- a scalar in the back end so the storage order is irrelevant.
1347 if (Is_Record_Type
(Comp_Base
)
1348 and then not Has_Complex_Representation
(Comp_Base
))
1349 or else Is_Array_Type
(Comp_Base
)
1352 Reverse_Storage_Order
(Encl_Base
) /=
1353 Reverse_Storage_Order
(Comp_Base
);
1355 -- Parent and extension must have same storage order
1357 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1358 if Comp_SSO_Differs
then
1360 ("record extension must have same scalar storage order as "
1361 & "parent", Err_Node
);
1364 -- If component and composite SSO differs, check that component
1365 -- falls on byte boundaries and isn't bit packed.
1367 elsif Comp_SSO_Differs
then
1369 -- Component SSO differs from enclosing composite:
1371 -- Reject if composite is a bit-packed array, as it is rewritten
1372 -- into an array of scalars.
1374 if Is_Bit_Packed_Array
(Encl_Base
) then
1376 ("type of packed array must have same scalar storage order "
1377 & "as component", Err_Node
);
1379 -- Reject if not byte aligned
1381 elsif Is_Record_Type
(Encl_Base
)
1382 and then not Comp_Byte_Aligned
1384 if Present
(Component_Clause
(Comp
)) then
1386 ("type of non-byte-aligned component must have same scalar"
1387 & " storage order as enclosing record", Err_Node
);
1390 ("type of packed component must have same scalar"
1391 & " storage order as enclosing record", Err_Node
);
1394 -- Warn if specified only for the outer composite
1396 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1398 ("scalar storage order specified for & does not apply to "
1399 & "component?", Err_Node
, Encl_Base
);
1403 -- Enclosing type has explicit SSO: non-composite component must not
1406 elsif Present
(ADC
) and then Component_Aliased
then
1408 ("aliased component not permitted for type with explicit "
1409 & "Scalar_Storage_Order", Err_Node
);
1411 end Check_Component_Storage_Order
;
1413 -----------------------------
1414 -- Check_Debug_Info_Needed --
1415 -----------------------------
1417 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1419 if Debug_Info_Off
(T
) then
1422 elsif Comes_From_Source
(T
)
1423 or else Debug_Generated_Code
1424 or else Debug_Flag_VV
1425 or else Needs_Debug_Info
(T
)
1427 Set_Debug_Info_Needed
(T
);
1429 end Check_Debug_Info_Needed
;
1431 -------------------------------
1432 -- Check_Expression_Function --
1433 -------------------------------
1435 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1436 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1437 -- Function to search for deferred constant
1443 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1445 -- When a constant is initialized with the result of a dispatching
1446 -- call, the constant declaration is rewritten as a renaming of the
1447 -- displaced function result. This scenario is not a premature use of
1448 -- a constant even though the Has_Completion flag is not set.
1450 if Is_Entity_Name
(Nod
)
1451 and then Present
(Entity
(Nod
))
1452 and then Ekind
(Entity
(Nod
)) = E_Constant
1453 and then Scope
(Entity
(Nod
)) = Current_Scope
1454 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1455 N_Object_Declaration
1456 and then not Is_Imported
(Entity
(Nod
))
1457 and then not Has_Completion
(Entity
(Nod
))
1458 and then not (Present
(Full_View
(Entity
(Nod
)))
1459 and then Has_Completion
(Full_View
(Entity
(Nod
))))
1462 ("premature use of& in call or instance", N
, Entity
(Nod
));
1464 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1465 Analyze
(Prefix
(Nod
));
1467 if Is_Entity_Name
(Prefix
(Nod
))
1468 and then Is_Type
(Entity
(Prefix
(Nod
)))
1470 if Expander_Active
then
1471 Check_Fully_Declared
(Entity
(Prefix
(Nod
)), N
);
1474 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1481 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1487 -- Start of processing for Check_Expression_Function
1490 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1492 -- The subprogram body created for the expression function is not
1493 -- itself a freeze point.
1495 if Scope
(Nam
) = Current_Scope
1496 and then Nkind
(Decl
) = N_Expression_Function
1497 and then Nkind
(N
) /= N_Subprogram_Body
1499 Check_Deferred
(Expression
(Decl
));
1501 end Check_Expression_Function
;
1503 --------------------------------
1504 -- Check_Inherited_Conditions --
1505 --------------------------------
1507 procedure Check_Inherited_Conditions
1509 Late_Overriding
: Boolean := False)
1511 Prim_Ops
: constant Elist_Id
:= Primitive_Operations
(R
);
1514 Par_Prim
: Entity_Id
;
1516 Wrapper_Needed
: Boolean;
1518 function Build_DTW_Body
1521 DTW_Decls
: List_Id
;
1522 Par_Prim
: Entity_Id
;
1523 Wrapped_Subp
: Entity_Id
) return Node_Id
;
1524 -- Build the body of the dispatch table wrapper containing the given
1525 -- spec and declarations; the call to the wrapped subprogram includes
1526 -- the proper type conversion.
1528 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
;
1529 -- Build the spec of the dispatch table wrapper
1531 procedure Build_Inherited_Condition_Pragmas
1533 Wrapper_Needed
: out Boolean);
1534 -- Build corresponding pragmas for an operation whose ancestor has
1535 -- class-wide pre/postconditions. If the operation is inherited then
1536 -- Wrapper_Needed is returned True to force the creation of a wrapper
1537 -- for the inherited operation. If the ancestor is being overridden,
1538 -- the pragmas are constructed only to verify their legality, in case
1539 -- they contain calls to other primitives that may have been overridden.
1541 function Needs_Wrapper
1542 (Class_Cond
: Node_Id
;
1544 Par_Subp
: Entity_Id
) return Boolean;
1545 -- Checks whether the dispatch-table wrapper (DTW) for Subp must be
1546 -- built to evaluate the given class-wide condition.
1548 --------------------
1549 -- Build_DTW_Body --
1550 --------------------
1552 function Build_DTW_Body
1555 DTW_Decls
: List_Id
;
1556 Par_Prim
: Entity_Id
;
1557 Wrapped_Subp
: Entity_Id
) return Node_Id
1559 Actuals
: constant List_Id
:= Empty_List
;
1561 Formal
: Entity_Id
:= First_Formal
(Par_Prim
);
1562 New_F_Spec
: Entity_Id
:= First
(Parameter_Specifications
(DTW_Spec
));
1563 New_Formal
: Entity_Id
;
1566 -- Build parameter association for call to wrapped subprogram
1568 while Present
(Formal
) loop
1569 New_Formal
:= Defining_Identifier
(New_F_Spec
);
1571 -- If the controlling argument is inherited, add conversion to
1572 -- parent type for the call.
1574 if Is_Controlling_Formal
(Formal
) then
1576 Make_Type_Conversion
(Loc
,
1577 New_Occurrence_Of
(Etype
(Formal
), Loc
),
1578 New_Occurrence_Of
(New_Formal
, Loc
)));
1580 Append_To
(Actuals
, New_Occurrence_Of
(New_Formal
, Loc
));
1583 Next_Formal
(Formal
);
1587 if Ekind
(Wrapped_Subp
) = E_Procedure
then
1589 Make_Procedure_Call_Statement
(Loc
,
1590 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1591 Parameter_Associations
=> Actuals
);
1594 Make_Simple_Return_Statement
(Loc
,
1596 Make_Function_Call
(Loc
,
1597 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1598 Parameter_Associations
=> Actuals
));
1602 Make_Subprogram_Body
(Loc
,
1603 Specification
=> Copy_Subprogram_Spec
(DTW_Spec
),
1604 Declarations
=> DTW_Decls
,
1605 Handled_Statement_Sequence
=>
1606 Make_Handled_Sequence_Of_Statements
(Loc
,
1607 Statements
=> New_List
(Call
),
1608 End_Label
=> Make_Identifier
(Loc
,
1609 Chars
(Defining_Entity
(DTW_Spec
)))));
1612 --------------------
1613 -- Build_DTW_Spec --
1614 --------------------
1616 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
is
1621 DTW_Spec
:= Build_Overriding_Spec
(Par_Prim
, R
);
1622 DTW_Id
:= Defining_Entity
(DTW_Spec
);
1624 -- Clear the not-overriding indicator since the DTW wrapper overrides
1625 -- its wrapped subprogram; required because if present in the parent
1626 -- primitive, given that Build_Overriding_Spec inherits it, we report
1629 Set_Must_Not_Override
(DTW_Spec
, False);
1631 -- Add minimal decoration of fields
1633 Mutate_Ekind
(DTW_Id
, Ekind
(Par_Prim
));
1634 Set_LSP_Subprogram
(DTW_Id
, Par_Prim
);
1635 Set_Is_Dispatch_Table_Wrapper
(DTW_Id
);
1636 Set_Is_Wrapper
(DTW_Id
);
1638 -- The DTW wrapper is never a null procedure
1640 if Nkind
(DTW_Spec
) = N_Procedure_Specification
then
1641 Set_Null_Present
(DTW_Spec
, False);
1647 ---------------------------------------
1648 -- Build_Inherited_Condition_Pragmas --
1649 ---------------------------------------
1651 procedure Build_Inherited_Condition_Pragmas
1653 Wrapper_Needed
: out Boolean)
1655 Class_Pre
: constant Node_Id
:=
1656 Class_Preconditions
(Ultimate_Alias
(Subp
));
1657 Class_Post
: Node_Id
:= Class_Postconditions
(Par_Prim
);
1662 Wrapper_Needed
:= False;
1664 if No
(Class_Pre
) and then No
(Class_Post
) then
1668 -- For class-wide preconditions we just evaluate whether the wrapper
1669 -- is needed; there is no need to build the pragma since the check
1670 -- is performed on the caller side.
1672 if Present
(Class_Pre
)
1673 and then Needs_Wrapper
(Class_Pre
, Subp
, Par_Prim
)
1675 Wrapper_Needed
:= True;
1678 -- For class-wide postconditions we evaluate whether the wrapper is
1679 -- needed and we build the class-wide postcondition pragma to install
1680 -- it in the wrapper.
1682 if Present
(Class_Post
)
1683 and then Needs_Wrapper
(Class_Post
, Subp
, Par_Prim
)
1685 Wrapper_Needed
:= True;
1687 -- Update the class-wide postcondition
1689 Class_Post
:= New_Copy_Tree
(Class_Post
);
1690 Build_Class_Wide_Expression
1691 (Pragma_Or_Expr
=> Class_Post
,
1693 Par_Subp
=> Par_Prim
,
1694 Adjust_Sloc
=> False);
1696 -- Install the updated class-wide postcondition in a copy of the
1697 -- pragma postcondition defined for the nearest ancestor.
1699 A_Post
:= Get_Class_Wide_Pragma
(Par_Prim
,
1700 Pragma_Postcondition
);
1704 Subps
: constant Subprogram_List
:=
1705 Inherited_Subprograms
(Subp
);
1707 for Index
in Subps
'Range loop
1708 A_Post
:= Get_Class_Wide_Pragma
(Subps
(Index
),
1709 Pragma_Postcondition
);
1710 exit when Present
(A_Post
);
1715 -- A_Post can be null here if the postcondition was inlined in the
1716 -- called subprogram.
1718 if Present
(A_Post
) then
1719 New_Prag
:= New_Copy_Tree
(A_Post
);
1721 (Expression
(First
(Pragma_Argument_Associations
(New_Prag
))),
1723 Append
(New_Prag
, Decls
);
1726 end Build_Inherited_Condition_Pragmas
;
1732 function Needs_Wrapper
1733 (Class_Cond
: Node_Id
;
1735 Par_Subp
: Entity_Id
) return Boolean
1737 Result
: Boolean := False;
1739 function Check_Entity
(N
: Node_Id
) return Traverse_Result
;
1740 -- Check calls to overridden primitives
1742 --------------------
1743 -- Replace_Entity --
1744 --------------------
1746 function Check_Entity
(N
: Node_Id
) return Traverse_Result
is
1750 if Nkind
(N
) = N_Identifier
1751 and then Present
(Entity
(N
))
1753 (Is_Formal
(Entity
(N
)) or else Is_Subprogram
(Entity
(N
)))
1755 (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1756 or else Attribute_Name
(Parent
(N
)) /= Name_Class
)
1758 -- Determine whether entity has a renaming
1760 New_E
:= Get_Mapped_Entity
(Entity
(N
));
1762 -- If the entity is an overridden primitive and we are not
1763 -- in GNATprove mode, we must build a wrapper for the current
1764 -- inherited operation. If the reference is the prefix of an
1765 -- attribute such as 'Result (or others ???) there is no need
1766 -- for a wrapper: the condition is just rewritten in terms of
1767 -- the inherited subprogram.
1770 and then Comes_From_Source
(New_E
)
1771 and then Is_Subprogram
(New_E
)
1772 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
1773 and then not GNATprove_Mode
1783 procedure Check_Condition_Entities
is
1784 new Traverse_Proc
(Check_Entity
);
1786 -- Start of processing for Needs_Wrapper
1789 Update_Primitives_Mapping
(Par_Subp
, Subp
);
1791 Map_Formals
(Par_Subp
, Subp
);
1792 Check_Condition_Entities
(Class_Cond
);
1797 Ifaces_List
: Elist_Id
:= No_Elist
;
1798 Ifaces_Listed
: Boolean := False;
1799 -- Cache the list of interface operations inherited by R
1801 Wrappers_List
: Elist_Id
:= No_Elist
;
1802 -- List containing identifiers of built wrappers. Used to defer building
1803 -- and analyzing their class-wide precondition subprograms.
1805 -- Start of processing for Check_Inherited_Conditions
1808 if Late_Overriding
then
1809 Op_Node
:= First_Elmt
(Prim_Ops
);
1810 while Present
(Op_Node
) loop
1811 Prim
:= Node
(Op_Node
);
1813 -- Map the overridden primitive to the overriding one
1815 if Present
(Overridden_Operation
(Prim
))
1816 and then Comes_From_Source
(Prim
)
1818 Par_Prim
:= Overridden_Operation
(Prim
);
1819 Update_Primitives_Mapping
(Par_Prim
, Prim
);
1821 -- Force discarding previous mappings of its formals
1823 Map_Formals
(Par_Prim
, Prim
, Force_Update
=> True);
1826 Next_Elmt
(Op_Node
);
1830 -- Perform validity checks on the inherited conditions of overriding
1831 -- operations, for conformance with LSP, and apply SPARK-specific
1832 -- restrictions on inherited conditions.
1834 Op_Node
:= First_Elmt
(Prim_Ops
);
1835 while Present
(Op_Node
) loop
1836 Prim
:= Node
(Op_Node
);
1838 Par_Prim
:= Overridden_Operation
(Prim
);
1839 if Present
(Par_Prim
)
1840 and then Comes_From_Source
(Prim
)
1842 -- When the primitive is an LSP wrapper we climb to the parent
1843 -- primitive that has the inherited contract.
1845 if Is_Wrapper
(Par_Prim
)
1846 and then Present
(LSP_Subprogram
(Par_Prim
))
1848 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
1851 -- Check that overrider and overridden operations have
1852 -- the same strub mode.
1854 Check_Same_Strub_Mode
(Prim
, Par_Prim
);
1856 -- Analyze the contract items of the overridden operation, before
1857 -- they are rewritten as pragmas.
1859 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1861 -- In GNATprove mode this is where we can collect the inherited
1862 -- conditions, because we do not create the Check pragmas that
1863 -- normally convey the modified class-wide conditions on
1864 -- overriding operations.
1866 if GNATprove_Mode
then
1867 Collect_Inherited_Class_Wide_Conditions
(Prim
);
1871 -- Go over operations inherited from interfaces and check
1872 -- them for strub mode compatibility as well.
1874 if Has_Interfaces
(R
)
1875 and then Is_Dispatching_Operation
(Prim
)
1876 and then Find_Dispatching_Type
(Prim
) = R
1880 Iface_Elmt
: Elmt_Id
;
1882 Iface_Prim
: Entity_Id
;
1885 -- Collect the interfaces only once. We haven't
1886 -- finished freezing yet, so we can't use the faster
1887 -- search from Sem_Disp.Covered_Interface_Primitives.
1889 if not Ifaces_Listed
then
1890 Collect_Interfaces
(R
, Ifaces_List
);
1891 Ifaces_Listed
:= True;
1894 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1895 while Present
(Iface_Elmt
) loop
1896 Iface
:= Node
(Iface_Elmt
);
1898 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1899 while Present
(Elmt
) loop
1900 Iface_Prim
:= Node
(Elmt
);
1902 if Iface_Prim
/= Par_Prim
1903 and then Chars
(Iface_Prim
) = Chars
(Prim
)
1904 and then Comes_From_Source
(Iface_Prim
)
1905 and then Is_Interface_Conformant
1906 (R
, Iface_Prim
, Prim
)
1908 Check_Same_Strub_Mode
(Prim
, Iface_Prim
);
1914 Next_Elmt
(Iface_Elmt
);
1919 Next_Elmt
(Op_Node
);
1922 -- Now examine the inherited operations to check whether they require
1923 -- a wrapper to handle inherited conditions that call other primitives,
1924 -- so that LSP can be verified/enforced.
1926 Op_Node
:= First_Elmt
(Prim_Ops
);
1928 while Present
(Op_Node
) loop
1929 Decls
:= Empty_List
;
1930 Prim
:= Node
(Op_Node
);
1931 Wrapper_Needed
:= False;
1933 -- Skip internal entities built for mapping interface primitives
1935 if not Comes_From_Source
(Prim
)
1936 and then Present
(Alias
(Prim
))
1937 and then No
(Interface_Alias
(Prim
))
1939 Par_Prim
:= Ultimate_Alias
(Prim
);
1941 -- When the primitive is an LSP wrapper we climb to the parent
1942 -- primitive that has the inherited contract.
1944 if Is_Wrapper
(Par_Prim
)
1945 and then Present
(LSP_Subprogram
(Par_Prim
))
1947 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
1950 -- Analyze the contract items of the parent operation, and
1951 -- determine whether a wrapper is needed. This is determined
1952 -- when the condition is rewritten in sem_prag, using the
1953 -- mapping between overridden and overriding operations built
1954 -- in the loop above.
1956 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1957 Build_Inherited_Condition_Pragmas
(Prim
, Wrapper_Needed
);
1961 and then not Is_Abstract_Subprogram
(Par_Prim
)
1962 and then Expander_Active
1964 -- Build the dispatch-table wrapper (DTW). The support for
1965 -- AI12-0195 relies on two kind of wrappers: one for indirect
1966 -- calls (also used for AI12-0220), and one for putting in the
1969 -- 1) "indirect-call wrapper" (ICW) is needed anytime there are
1970 -- class-wide preconditions. Prim'Access will point directly
1971 -- at the ICW if any, or at the "pristine" body if Prim has
1972 -- no class-wide preconditions.
1974 -- 2) "dispatch-table wrapper" (DTW) is needed anytime the class
1975 -- wide preconditions *or* the class-wide postconditions are
1976 -- affected by overriding.
1978 -- The DTW holds a single statement that is a single call where
1979 -- the controlling actuals are conversions to the corresponding
1980 -- type in the parent primitive. If the primitive is a function
1981 -- the statement is a return statement with a call.
1984 Alias_Id
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1985 Loc
: constant Source_Ptr
:= Sloc
(R
);
1991 Prim_Next_E
: constant Entity_Id
:= Next_Entity
(Prim
);
1992 Prim_Prev_E
: constant Entity_Id
:= Prev_Entity
(Prim
);
1995 DTW_Spec
:= Build_DTW_Spec
(Par_Prim
);
1996 DTW_Id
:= Defining_Entity
(DTW_Spec
);
1997 DTW_Decl
:= Make_Subprogram_Declaration
(Loc
,
1998 Specification
=> DTW_Spec
);
2000 -- The spec of the wrapper has been built using the source
2001 -- location of its parent primitive; we must update it now
2002 -- (with the source location of the internal primitive built
2003 -- by Derive_Subprogram that will override this wrapper) to
2004 -- avoid inlining conflicts between internally built helpers
2005 -- for class-wide pre/postconditions of the parent and the
2006 -- helpers built for this wrapper.
2008 Set_Sloc
(DTW_Id
, Sloc
(Prim
));
2010 -- For inherited class-wide preconditions the DTW wrapper
2011 -- reuses the ICW of the parent (which checks the parent
2012 -- interpretation of the class-wide preconditions); the
2013 -- interpretation of the class-wide preconditions for the
2014 -- inherited subprogram is checked at the caller side.
2016 -- When the subprogram inherits class-wide postconditions
2017 -- the DTW also checks the interpretation of the class-wide
2018 -- postconditions for the inherited subprogram, and the body
2019 -- of the parent checks its interpretation of the parent for
2020 -- the class-wide postconditions.
2022 -- procedure Prim (F1 : T1; ...) is
2023 -- [ pragma Check (Postcondition, Expr); ]
2025 -- Par_Prim_ICW (Par_Type (F1), ...);
2028 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2030 Build_DTW_Body
(Loc
,
2031 DTW_Spec
=> DTW_Spec
,
2033 Par_Prim
=> Par_Prim
,
2034 Wrapped_Subp
=> Indirect_Call_Wrapper
(Par_Prim
));
2036 -- For subprograms that only inherit class-wide postconditions
2037 -- the DTW wrapper calls the parent primitive (which on its
2038 -- body checks the interpretation of the class-wide post-
2039 -- conditions for the parent subprogram), and the DTW checks
2040 -- the interpretation of the class-wide postconditions for the
2041 -- inherited subprogram.
2043 -- procedure Prim (F1 : T1; ...) is
2044 -- pragma Check (Postcondition, Expr);
2046 -- Par_Prim (Par_Type (F1), ...);
2051 Build_DTW_Body
(Loc
,
2052 DTW_Spec
=> DTW_Spec
,
2054 Par_Prim
=> Par_Prim
,
2055 Wrapped_Subp
=> Par_Prim
);
2058 -- Insert the declaration of the wrapper before the freezing
2059 -- node of the record type declaration to ensure that it will
2060 -- override the internal primitive built by Derive_Subprogram.
2062 if Late_Overriding
then
2063 Ensure_Freeze_Node
(R
);
2064 Insert_Before_And_Analyze
(Freeze_Node
(R
), DTW_Decl
);
2066 Append_Freeze_Action
(R
, DTW_Decl
);
2070 -- The analyis of DTW_Decl has removed Prim from its scope
2071 -- chain and added DTW_Id at the end of the scope chain. Move
2072 -- DTW_Id to its correct place in the scope chain: the analysis
2073 -- of the wrapper declaration has just added DTW_Id at the end
2074 -- of the list of entities of its scope. However, given that
2075 -- this wrapper overrides Prim, we must move DTW_Id to the
2076 -- original place of Prim in its scope chain. This is required
2077 -- for wrappers of private type primitives to ensure their
2078 -- correct visibility since wrappers are built when the full
2079 -- tagged type declaration is frozen (in the private part of
2080 -- the package) but they may override primitives defined in the
2081 -- public part of the package.
2084 DTW_Prev_E
: constant Entity_Id
:= Prev_Entity
(DTW_Id
);
2087 pragma Assert
(Last_Entity
(Current_Scope
) = DTW_Id
);
2089 (Ekind
(Current_Scope
) not in E_Package | E_Generic_Package
2090 or else No
(First_Private_Entity
(Current_Scope
))
2091 or else First_Private_Entity
(Current_Scope
) /= DTW_Id
);
2093 -- Remove DTW_Id from the end of the doubly-linked list of
2094 -- entities of this scope; no need to handle removing it
2095 -- from the beginning of the chain since such case can never
2096 -- occur for this entity.
2098 Set_Last_Entity
(Current_Scope
, DTW_Prev_E
);
2099 Set_Next_Entity
(DTW_Prev_E
, Empty
);
2101 -- Place DTW_Id back in the original place of its wrapped
2102 -- primitive in the list of entities of this scope.
2104 Link_Entities
(Prim_Prev_E
, DTW_Id
);
2105 Link_Entities
(DTW_Id
, Prim_Next_E
);
2108 -- Insert the body of the wrapper in the freeze actions of
2109 -- its record type declaration to ensure that it is placed
2110 -- in the scope of its declaration but not too early to cause
2111 -- premature freezing of other entities.
2113 Append_Freeze_Action
(R
, DTW_Body
);
2116 -- Ensure correct decoration
2118 pragma Assert
(Is_Dispatching_Operation
(DTW_Id
));
2119 pragma Assert
(Present
(Overridden_Operation
(DTW_Id
)));
2120 pragma Assert
(Overridden_Operation
(DTW_Id
) = Alias_Id
);
2122 -- Inherit dispatch table slot
2124 Set_DTC_Entity_Value
(R
, DTW_Id
);
2125 Set_DT_Position
(DTW_Id
, DT_Position
(Alias_Id
));
2127 -- Register the wrapper in the dispatch table
2130 and then not Building_Static_DT
(R
)
2132 Insert_List_After_And_Analyze
(Freeze_Node
(R
),
2133 Register_Primitive
(Loc
, DTW_Id
));
2136 -- Defer building helpers and ICW for the DTW. Required to
2137 -- ensure uniqueness in their names because when building
2138 -- these wrappers for overlapped subprograms their homonym
2139 -- number is not definite until all these dispatch table
2140 -- wrappers of tagged type R have been analyzed.
2142 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2143 Append_New_Elmt
(DTW_Id
, Wrappers_List
);
2148 Next_Elmt
(Op_Node
);
2151 -- Build and analyze deferred class-wide precondition subprograms of
2154 if Present
(Wrappers_List
) then
2157 CW_Subp
: Entity_Id
;
2163 Elmt
:= First_Elmt
(Wrappers_List
);
2165 while Present
(Elmt
) loop
2166 DTW_Id
:= Node
(Elmt
);
2169 Merge_Class_Conditions
(DTW_Id
);
2170 Make_Class_Precondition_Subps
(DTW_Id
, Late_Overriding
);
2172 CW_Subp
:= Static_Call_Helper
(DTW_Id
);
2173 Decl_N
:= Unit_Declaration_Node
(CW_Subp
);
2176 -- If the DTW was built for a late-overriding primitive
2177 -- its body must be analyzed now (since the tagged type
2178 -- is already frozen).
2180 if Late_Overriding
then
2182 Unit_Declaration_Node
(Corresponding_Body
(Decl_N
));
2188 end Check_Inherited_Conditions
;
2190 ----------------------------
2191 -- Check_Strict_Alignment --
2192 ----------------------------
2194 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
2198 -- Bit-packed array types do not require strict alignment, even if they
2199 -- are by-reference types, because they are accessed in a special way.
2201 if Is_By_Reference_Type
(E
) and then not Is_Bit_Packed_Array
(E
) then
2202 Set_Strict_Alignment
(E
);
2204 elsif Is_Array_Type
(E
) then
2205 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
2207 -- ??? AI12-001: Any component of a packed type that contains an
2208 -- aliased part must be aligned according to the alignment of its
2209 -- subtype (RM 13.2(7)). This means that the following test:
2211 -- if Has_Aliased_Components (E) then
2212 -- Set_Strict_Alignment (E);
2215 -- should be implemented here. Unfortunately it would break Florist,
2216 -- which has the bad habit of overaligning all the types it declares
2217 -- on 32-bit platforms. Other legacy codebases could also be affected
2218 -- because this check has historically been missing in GNAT.
2220 elsif Is_Record_Type
(E
) then
2221 Comp
:= First_Component
(E
);
2222 while Present
(Comp
) loop
2223 if not Is_Type
(Comp
)
2224 and then (Is_Aliased
(Comp
)
2225 or else Strict_Alignment
(Etype
(Comp
)))
2227 Set_Strict_Alignment
(E
);
2231 Next_Component
(Comp
);
2234 end Check_Strict_Alignment
;
2236 -------------------------
2237 -- Check_Unsigned_Type --
2238 -------------------------
2240 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
2241 Ancestor
: Entity_Id
;
2246 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
2250 -- Do not attempt to analyze case where range was in error
2252 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
2256 -- The situation that is nontrivial is something like:
2258 -- subtype x1 is integer range -10 .. +10;
2259 -- subtype x2 is x1 range 0 .. V1;
2260 -- subtype x3 is x2 range V2 .. V3;
2261 -- subtype x4 is x3 range V4 .. V5;
2263 -- where Vn are variables. Here the base type is signed, but we still
2264 -- know that x4 is unsigned because of the lower bound of x2.
2266 -- The only way to deal with this is to look up the ancestor chain
2270 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
2274 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
2276 if Compile_Time_Known_Value
(Lo_Bound
) then
2277 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
2278 Set_Is_Unsigned_Type
(E
, True);
2284 Ancestor
:= Ancestor_Subtype
(Ancestor
);
2286 -- If no ancestor had a static lower bound, go to base type
2288 if No
(Ancestor
) then
2290 -- Note: the reason we still check for a compile time known
2291 -- value for the base type is that at least in the case of
2292 -- generic formals, we can have bounds that fail this test,
2293 -- and there may be other cases in error situations.
2295 Btyp
:= Base_Type
(E
);
2297 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
2301 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
2303 if Compile_Time_Known_Value
(Lo_Bound
)
2304 and then Expr_Rep_Value
(Lo_Bound
) >= 0
2306 Set_Is_Unsigned_Type
(E
, True);
2313 end Check_Unsigned_Type
;
2315 -----------------------------------------------
2316 -- Explode_Initialization_Compound_Statement --
2317 -----------------------------------------------
2319 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
2320 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
2323 if Present
(Init_Stmts
)
2324 and then Nkind
(Init_Stmts
) = N_Compound_Statement
2326 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
2328 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
2329 -- just removing it, because Freeze_All may rely on this particular
2330 -- Node_Id still being present in the enclosing list to know where to
2333 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
2335 Set_Initialization_Statements
(E
, Empty
);
2337 end Explode_Initialization_Compound_Statement
;
2343 -- Note: the easy coding for this procedure would be to just build a
2344 -- single list of freeze nodes and then insert them and analyze them
2345 -- all at once. This won't work, because the analysis of earlier freeze
2346 -- nodes may recursively freeze types which would otherwise appear later
2347 -- on in the freeze list. So we must analyze and expand the freeze nodes
2348 -- as they are generated.
2350 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
2351 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
2352 -- This is the internal recursive routine that does freezing of entities
2353 -- (but NOT the analysis of default expressions, which should not be
2354 -- recursive, we don't want to analyze those till we are sure that ALL
2355 -- the types are frozen).
2357 --------------------
2358 -- Freeze_All_Ent --
2359 --------------------
2361 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
2365 procedure Process_Flist
;
2366 -- If freeze nodes are present, insert and analyze, and reset cursor
2367 -- for next insertion.
2373 procedure Process_Flist
is
2376 if Is_Non_Empty_List
(Flist
) then
2377 Lastn
:= Next
(After
);
2378 Insert_List_After_And_Analyze
(After
, Flist
);
2380 if Present
(Lastn
) then
2381 After
:= Prev
(Lastn
);
2383 After
:= Last
(List_Containing
(After
));
2388 -- Start of processing for Freeze_All_Ent
2392 while Present
(E
) loop
2394 -- If the entity is an inner package which is not a package
2395 -- renaming, then its entities must be frozen at this point. Note
2396 -- that such entities do NOT get frozen at the end of the nested
2397 -- package itself (only library packages freeze).
2399 -- Same is true for task declarations, where anonymous records
2400 -- created for entry parameters must be frozen.
2402 if Ekind
(E
) = E_Package
2403 and then No
(Renamed_Entity
(E
))
2404 and then not Is_Child_Unit
(E
)
2405 and then not Is_Frozen
(E
)
2409 Install_Visible_Declarations
(E
);
2410 Install_Private_Declarations
(E
);
2411 Freeze_All
(First_Entity
(E
), After
);
2413 End_Package_Scope
(E
);
2415 if Is_Generic_Instance
(E
)
2416 and then Has_Delayed_Freeze
(E
)
2418 Set_Has_Delayed_Freeze
(E
, False);
2419 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
2422 elsif Ekind
(E
) in Task_Kind
2423 and then Nkind
(Parent
(E
)) in
2424 N_Single_Task_Declaration | N_Task_Type_Declaration
2427 Freeze_All
(First_Entity
(E
), After
);
2430 -- For a derived tagged type, we must ensure that all the
2431 -- primitive operations of the parent have been frozen, so that
2432 -- their addresses will be in the parent's dispatch table at the
2433 -- point it is inherited.
2435 elsif Ekind
(E
) = E_Record_Type
2436 and then Is_Tagged_Type
(E
)
2437 and then Is_Tagged_Type
(Etype
(E
))
2438 and then Is_Derived_Type
(E
)
2441 Prim_List
: constant Elist_Id
:=
2442 Primitive_Operations
(Etype
(E
));
2448 Prim
:= First_Elmt
(Prim_List
);
2449 while Present
(Prim
) loop
2450 Subp
:= Node
(Prim
);
2452 if Comes_From_Source
(Subp
)
2453 and then not Is_Frozen
(Subp
)
2455 Flist
:= Freeze_Entity
(Subp
, After
);
2464 if not Is_Frozen
(E
) then
2465 Flist
:= Freeze_Entity
(E
, After
);
2468 -- If already frozen, and there are delayed aspects, this is where
2469 -- we do the visibility check for these aspects (see Sem_Ch13 spec
2470 -- for a description of how we handle aspect visibility).
2472 elsif Has_Delayed_Aspects
(E
) then
2477 Ritem
:= First_Rep_Item
(E
);
2478 while Present
(Ritem
) loop
2479 if Nkind
(Ritem
) = N_Aspect_Specification
2480 and then Entity
(Ritem
) = E
2481 and then Is_Delayed_Aspect
(Ritem
)
2483 Check_Aspect_At_End_Of_Declarations
(Ritem
);
2486 Next_Rep_Item
(Ritem
);
2491 -- If an incomplete type is still not frozen, this may be a
2492 -- premature freezing because of a body declaration that follows.
2493 -- Indicate where the freezing took place. Freezing will happen
2494 -- if the body comes from source, but not if it is internally
2495 -- generated, for example as the body of a type invariant.
2497 -- If the freezing is caused by the end of the current declarative
2498 -- part, it is a Taft Amendment type, and there is no error.
2500 if not Is_Frozen
(E
)
2501 and then Ekind
(E
) = E_Incomplete_Type
2504 Bod
: constant Node_Id
:= Next
(After
);
2507 -- The presence of a body freezes all entities previously
2508 -- declared in the current list of declarations, but this
2509 -- does not apply if the body does not come from source.
2510 -- A type invariant is transformed into a subprogram body
2511 -- which is placed at the end of the private part of the
2512 -- current package, but this body does not freeze incomplete
2513 -- types that may be declared in this private part.
2515 if Comes_From_Source
(Bod
)
2516 and then Nkind
(Bod
) in N_Entry_Body
2523 In_Same_List
(After
, Parent
(E
))
2525 Error_Msg_Sloc
:= Sloc
(Next
(After
));
2527 ("type& is frozen# before its full declaration",
2543 -- Start of processing for Freeze_All
2546 Freeze_All_Ent
(From
, After
);
2548 -- Now that all types are frozen, we can deal with default expressions
2549 -- that require us to build a default expression functions. This is the
2550 -- point at which such functions are constructed (after all types that
2551 -- might be used in such expressions have been frozen).
2553 -- For subprograms that are renaming_as_body, we create the wrapper
2554 -- bodies as needed.
2556 -- We also add finalization chains to access types whose designated
2557 -- types are controlled. This is normally done when freezing the type,
2558 -- but this misses recursive type definitions where the later members
2559 -- of the recursion introduce controlled components.
2561 -- Loop through entities
2564 while Present
(E
) loop
2565 if Is_Subprogram
(E
) then
2566 if not Default_Expressions_Processed
(E
) then
2567 Process_Default_Expressions
(E
, After
);
2570 -- Check subprogram renamings for the same strub-mode.
2571 -- Avoid rechecking dispatching operations, that's taken
2572 -- care of in Check_Inherited_Conditions, that covers
2573 -- inherited interface operations.
2577 and then not Is_Dispatching_Operation
(E
)
2579 Check_Same_Strub_Mode
(E
, Item
);
2582 if not Has_Completion
(E
) then
2583 Decl
:= Unit_Declaration_Node
(E
);
2585 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
2586 if Error_Posted
(Decl
) then
2587 Set_Has_Completion
(E
);
2589 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
2592 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2593 and then Present
(Corresponding_Body
(Decl
))
2595 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
2596 N_Subprogram_Renaming_Declaration
2598 Build_And_Analyze_Renamed_Body
2599 (Decl
, Corresponding_Body
(Decl
), After
);
2603 -- Freeze the default expressions of entries, entry families, and
2604 -- protected subprograms.
2606 elsif Is_Concurrent_Type
(E
) then
2607 Item
:= First_Entity
(E
);
2608 while Present
(Item
) loop
2609 if Is_Subprogram_Or_Entry
(Item
)
2610 and then not Default_Expressions_Processed
(Item
)
2612 Process_Default_Expressions
(Item
, After
);
2619 -- Historical note: We used to create a finalization master for an
2620 -- access type whose designated type is not controlled, but contains
2621 -- private controlled compoments. This form of postprocessing is no
2622 -- longer needed because the finalization master is now created when
2623 -- the access type is frozen (see Exp_Ch3.Freeze_Type).
2629 -----------------------
2630 -- Freeze_And_Append --
2631 -----------------------
2633 procedure Freeze_And_Append
2636 Result
: in out List_Id
)
2638 -- Freezing an Expression_Function does not freeze its profile:
2639 -- the formals will have been frozen otherwise before the E_F
2642 L
: constant List_Id
:=
2644 (Ent
, N
, Do_Freeze_Profile
=> not Is_Expression_Function
(Ent
));
2646 if Is_Non_Empty_List
(L
) then
2647 if Result
= No_List
then
2650 Append_List
(L
, Result
);
2653 end Freeze_And_Append
;
2659 procedure Freeze_Before
2662 Do_Freeze_Profile
: Boolean := True)
2664 -- Freeze T, then insert the generated Freeze nodes before the node N.
2665 -- Flag Freeze_Profile is used when T is an overloadable entity, and
2666 -- indicates whether its profile should be frozen at the same time.
2668 Freeze_Nodes
: constant List_Id
:=
2669 Freeze_Entity
(T
, N
, Do_Freeze_Profile
);
2670 Pack
: constant Entity_Id
:= Scope
(T
);
2673 if Ekind
(T
) = E_Function
then
2674 Check_Expression_Function
(N
, T
);
2677 if Is_Non_Empty_List
(Freeze_Nodes
) then
2679 -- If the entity is a type declared in an inner package, it may be
2680 -- frozen by an outer declaration before the package itself is
2681 -- frozen. Install the package scope to analyze the freeze nodes,
2682 -- which may include generated subprograms such as predicate
2685 if Is_Type
(T
) and then From_Nested_Package
(T
) then
2687 Install_Visible_Declarations
(Pack
);
2688 Install_Private_Declarations
(Pack
);
2689 Insert_Actions
(N
, Freeze_Nodes
);
2690 End_Package_Scope
(Pack
);
2693 Insert_Actions
(N
, Freeze_Nodes
);
2702 -- WARNING: This routine manages Ghost regions. Return statements must be
2703 -- replaced by gotos which jump to the end of the routine and restore the
2706 function Freeze_Entity
2709 Do_Freeze_Profile
: Boolean := True) return List_Id
2711 Loc
: constant Source_Ptr
:= Sloc
(N
);
2713 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2714 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
2715 -- Save the Ghost-related attributes to restore on exit
2723 Result
: List_Id
:= No_List
;
2724 -- List of freezing actions, left at No_List if none
2726 Test_E
: Entity_Id
:= E
;
2727 -- A local temporary used to test if freezing is necessary for E, since
2728 -- its value can be set to something other than E in certain cases. For
2729 -- example, E cannot be used directly in cases such as when it is an
2730 -- Itype defined within a record - since it is the location of record
2733 procedure Add_To_Result
(Fnod
: Node_Id
);
2734 -- Add freeze action Fnod to list Result
2736 function After_Last_Declaration
return Boolean;
2737 -- If Loc is a freeze_entity that appears after the last declaration
2738 -- in the scope, inhibit error messages on late completion.
2740 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
2741 -- Check that an Access or Unchecked_Access attribute with a prefix
2742 -- which is the current instance type can only be applied when the type
2745 procedure Check_No_Parts_Violations
2746 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
) with
2747 Pre
=> Aspect_No_Parts
in
2748 Aspect_No_Controlled_Parts | Aspect_No_Task_Parts
;
2749 -- Check that Typ does not violate the semantics of the specified
2750 -- Aspect_No_Parts (No_Controlled_Parts or No_Task_Parts) when it is
2751 -- specified on Typ or one of its ancestors.
2753 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
);
2754 -- Give a warning for pragma Convention with language C or C++ applied
2755 -- to a discriminated record type. This is suppressed for the unchecked
2756 -- union case, since the whole point in this case is interface C. We
2757 -- also do not generate this within instantiations, since we will have
2758 -- generated a message on the template.
2760 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
2761 -- Give warning for modulus of 8, 16, 32, 64 or 128 given as an explicit
2762 -- integer literal without an explicit corresponding size clause. The
2763 -- caller has checked that Utype is a modular integer type.
2765 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
2766 -- Freeze array type, including freezing index and component types
2768 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
2769 -- Perform checks and generate freeze node if needed for a constant or
2770 -- variable declared by an object declaration.
2772 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
2773 -- Create Freeze_Generic_Entity nodes for types declared in a generic
2774 -- package. Recurse on inner generic packages.
2776 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
2777 -- Freeze formals and return type of subprogram. If some type in the
2778 -- profile is incomplete and we are in an instance, freezing of the
2779 -- entity will take place elsewhere, and the function returns False.
2781 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
2782 -- Freeze record type, including freezing component types, and freezing
2783 -- primitive operations if this is a tagged type.
2785 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
2786 -- Determine whether an arbitrary entity is subject to Boolean aspect
2787 -- Import and its value is specified as True.
2789 procedure Inherit_Freeze_Node
2792 -- Set type Typ's freeze node to refer to Fnode. This routine ensures
2793 -- that any attributes attached to Typ's original node are preserved.
2795 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
2796 -- If E is an entity for an imported subprogram with pre/post-conditions
2797 -- then this procedure will create a wrapper to ensure that proper run-
2798 -- time checking of the pre/postconditions. See body for details.
2804 procedure Add_To_Result
(Fnod
: Node_Id
) is
2806 Append_New_To
(Result
, Fnod
);
2809 ----------------------------
2810 -- After_Last_Declaration --
2811 ----------------------------
2813 function After_Last_Declaration
return Boolean is
2814 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2817 if Nkind
(Spec
) = N_Package_Specification
then
2818 if Present
(Private_Declarations
(Spec
)) then
2819 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2820 elsif Present
(Visible_Declarations
(Spec
)) then
2821 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2829 end After_Last_Declaration
;
2831 ----------------------------
2832 -- Check_Current_Instance --
2833 ----------------------------
2835 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2837 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2838 -- Determine whether Typ is compatible with the rules for aliased
2839 -- views of types as defined in RM 3.10 in the various dialects.
2841 function Process
(N
: Node_Id
) return Traverse_Result
;
2842 -- Process routine to apply check to given node
2844 -----------------------------
2845 -- Is_Aliased_View_Of_Type --
2846 -----------------------------
2848 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
2849 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
2854 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
2855 and then Limited_Present
(Type_Definition
(Typ_Decl
))
2859 -- The following paragraphs describe what a legal aliased view of
2860 -- a type is in the various dialects of Ada.
2864 -- The current instance of a limited type, and a formal parameter
2865 -- or generic formal object of a tagged type.
2867 -- Ada 95 limited type
2868 -- * Type with reserved word "limited"
2869 -- * A protected or task type
2870 -- * A composite type with limited component
2872 elsif Ada_Version
<= Ada_95
then
2873 return Is_Limited_Type
(Typ
);
2877 -- The current instance of a limited tagged type, a protected
2878 -- type, a task type, or a type that has the reserved word
2879 -- "limited" in its full definition ... a formal parameter or
2880 -- generic formal object of a tagged type.
2882 -- Ada 2005 limited type
2883 -- * Type with reserved word "limited", "synchronized", "task"
2885 -- * A composite type with limited component
2886 -- * A derived type whose parent is a non-interface limited type
2888 elsif Ada_Version
= Ada_2005
then
2890 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2892 (Is_Derived_Type
(Typ
)
2893 and then not Is_Interface
(Etype
(Typ
))
2894 and then Is_Limited_Type
(Etype
(Typ
)));
2896 -- Ada 2012 and beyond
2898 -- The current instance of an immutably limited type ... a formal
2899 -- parameter or generic formal object of a tagged type.
2901 -- Ada 2012 limited type
2902 -- * Type with reserved word "limited", "synchronized", "task"
2904 -- * A composite type with limited component
2905 -- * A derived type whose parent is a non-interface limited type
2906 -- * An incomplete view
2908 -- Ada 2012 immutably limited type
2909 -- * Explicitly limited record type
2910 -- * Record extension with "limited" present
2911 -- * Non-formal limited private type that is either tagged
2912 -- or has at least one access discriminant with a default
2914 -- * Task type, protected type or synchronized interface
2915 -- * Type derived from immutably limited type
2919 Is_Immutably_Limited_Type
(Typ
)
2920 or else Is_Incomplete_Type
(Typ
);
2922 end Is_Aliased_View_Of_Type
;
2928 function Process
(N
: Node_Id
) return Traverse_Result
is
2931 when N_Attribute_Reference
=>
2932 if Attribute_Name
(N
) in Name_Access | Name_Unchecked_Access
2933 and then Is_Entity_Name
(Prefix
(N
))
2934 and then Is_Type
(Entity
(Prefix
(N
)))
2935 and then Entity
(Prefix
(N
)) = E
2937 if Ada_Version
< Ada_2012
then
2939 ("current instance must be a limited type",
2943 ("current instance must be an immutably limited "
2944 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2958 procedure Traverse
is new Traverse_Proc
(Process
);
2962 Rec_Type
: constant Entity_Id
:=
2963 Scope
(Defining_Identifier
(Comp_Decl
));
2965 -- Start of processing for Check_Current_Instance
2968 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2969 Traverse
(Comp_Decl
);
2971 end Check_Current_Instance
;
2973 -------------------------------
2974 -- Check_No_Parts_Violations --
2975 -------------------------------
2977 procedure Check_No_Parts_Violations
2978 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
)
2981 function Find_Aspect_No_Parts
2982 (Typ
: Entity_Id
) return Node_Id
;
2983 -- Search for Aspect_No_Parts on a given type. When
2984 -- the aspect is not explicity specified Empty is returned.
2986 function Get_Aspect_No_Parts_Value
2987 (Typ
: Entity_Id
) return Entity_Id
;
2988 -- Obtain the value for the Aspect_No_Parts on a given
2989 -- type. When the aspect is not explicitly specified Empty is
2992 function Has_Aspect_No_Parts
2993 (Typ
: Entity_Id
) return Boolean;
2994 -- Predicate function which identifies whether No_Parts
2995 -- is explicitly specified on a given type.
2997 -------------------------------------
2998 -- Find_Aspect_No_Parts --
2999 -------------------------------------
3001 function Find_Aspect_No_Parts
3002 (Typ
: Entity_Id
) return Node_Id
3004 Partial_View
: constant Entity_Id
:=
3005 Incomplete_Or_Partial_View
(Typ
);
3007 Aspect_Spec
: Entity_Id
:=
3008 Find_Aspect
(Typ
, Aspect_No_Parts
);
3009 Curr_Aspect_Spec
: Entity_Id
;
3012 -- Examine Typ's associated node, when present, since aspect
3013 -- specifications do not get transferred when nodes get rewritten.
3015 -- For example, this can happen in the expansion of array types
3018 and then Present
(Associated_Node_For_Itype
(Typ
))
3019 and then Nkind
(Associated_Node_For_Itype
(Typ
))
3020 = N_Full_Type_Declaration
3024 (Id
=> Defining_Identifier
3025 (Associated_Node_For_Itype
(Typ
)),
3026 A
=> Aspect_No_Parts
);
3029 -- Examine aspects specifications on private type declarations
3031 -- Should Find_Aspect be improved to handle this case ???
3034 and then Present
(Partial_View
)
3036 (Aspect_Specifications
3042 (Aspect_Specifications
3046 -- Search through aspects present on the private type
3048 while Present
(Curr_Aspect_Spec
) loop
3049 if Get_Aspect_Id
(Curr_Aspect_Spec
)
3052 Aspect_Spec
:= Curr_Aspect_Spec
;
3056 Next
(Curr_Aspect_Spec
);
3061 -- When errors are posted on the aspect return Empty
3063 if Error_Posted
(Aspect_Spec
) then
3068 end Find_Aspect_No_Parts
;
3070 ------------------------------------------
3071 -- Get_Aspect_No_Parts_Value --
3072 ------------------------------------------
3074 function Get_Aspect_No_Parts_Value
3075 (Typ
: Entity_Id
) return Entity_Id
3077 Aspect_Spec
: constant Entity_Id
:=
3078 Find_Aspect_No_Parts
(Typ
);
3081 -- Return the value of the aspect when present
3083 if Present
(Aspect_Spec
) then
3085 -- No expression is the same as True
3087 if No
(Expression
(Aspect_Spec
)) then
3088 return Standard_True
;
3091 -- Assume its expression has already been constant folded into
3092 -- a Boolean value and return its value.
3094 return Entity
(Expression
(Aspect_Spec
));
3097 -- Otherwise, the aspect is not specified - so return Empty
3100 end Get_Aspect_No_Parts_Value
;
3102 ------------------------------------
3103 -- Has_Aspect_No_Parts --
3104 ------------------------------------
3106 function Has_Aspect_No_Parts
3107 (Typ
: Entity_Id
) return Boolean
3108 is (Present
(Find_Aspect_No_Parts
(Typ
)));
3110 -- Generic instances
3112 -------------------------------------------
3113 -- Get_Generic_Formal_Types_In_Hierarchy --
3114 -------------------------------------------
3116 function Get_Generic_Formal_Types_In_Hierarchy
3117 is new Collect_Types_In_Hierarchy
(Predicate
=> Is_Generic_Formal
);
3118 -- Return a list of all types within a given type's hierarchy which
3119 -- are generic formals.
3121 ----------------------------------------
3122 -- Get_Types_With_Aspect_In_Hierarchy --
3123 ----------------------------------------
3125 function Get_Types_With_Aspect_In_Hierarchy
3126 is new Collect_Types_In_Hierarchy
3127 (Predicate
=> Has_Aspect_No_Parts
);
3128 -- Returns a list of all types within a given type's hierarchy which
3129 -- have the Aspect_No_Parts specified.
3131 -- Local declarations
3133 Aspect_Value
: Entity_Id
;
3134 Curr_Value
: Entity_Id
;
3135 Curr_Typ_Elmt
: Elmt_Id
;
3136 Curr_Body_Elmt
: Elmt_Id
;
3137 Curr_Formal_Elmt
: Elmt_Id
;
3138 Gen_Bodies
: Elist_Id
;
3139 Gen_Formals
: Elist_Id
;
3141 Types_With_Aspect
: Elist_Id
;
3143 -- Start of processing for Check_No_Parts_Violations
3146 -- Nothing to check if the type is elementary or artificial
3148 if Is_Elementary_Type
(Typ
) or else not Comes_From_Source
(Typ
) then
3152 Types_With_Aspect
:= Get_Types_With_Aspect_In_Hierarchy
(Typ
);
3154 -- Nothing to check if there are no types with No_Parts specified
3156 if Is_Empty_Elmt_List
(Types_With_Aspect
) then
3160 -- Set name for all errors below
3162 Error_Msg_Name_1
:= Aspect_Names
(Aspect_No_Parts
);
3164 -- Obtain the aspect value for No_Parts for comparison
3167 Get_Aspect_No_Parts_Value
3168 (Node
(First_Elmt
(Types_With_Aspect
)));
3170 -- When the value is True and there are controlled/task parts or the
3171 -- type itself is controlled/task, trigger the appropriate error.
3173 if Aspect_Value
= Standard_True
then
3174 if Aspect_No_Parts
= Aspect_No_Controlled_Parts
then
3175 if Is_Controlled
(Typ
) or else Has_Controlled_Component
(Typ
)
3178 ("aspect % applied to controlled type &", Typ
);
3181 elsif Aspect_No_Parts
= Aspect_No_Task_Parts
then
3182 if Has_Task
(Typ
) then
3184 ("aspect % applied to task type &", Typ
);
3186 ("\replace task components with access-to-task-type "
3187 & "components??", Typ
);
3191 raise Program_Error
;
3195 -- Move through Types_With_Aspect - checking that the value specified
3196 -- for their corresponding Aspect_No_Parts do not override each
3199 Curr_Typ_Elmt
:= First_Elmt
(Types_With_Aspect
);
3200 while Present
(Curr_Typ_Elmt
) loop
3202 Get_Aspect_No_Parts_Value
(Node
(Curr_Typ_Elmt
));
3204 -- Compare the aspect value against the current type
3206 if Curr_Value
/= Aspect_Value
then
3208 ("cannot override aspect % of "
3209 & "ancestor type &", Typ
, Node
(Curr_Typ_Elmt
));
3213 Next_Elmt
(Curr_Typ_Elmt
);
3216 -- Issue an error if the aspect applies to a type declared inside a
3217 -- generic body and if said type derives from or has a component
3218 -- of ageneric formal type - since those are considered to have
3219 -- controlled/task parts and have Aspect_No_Parts specified as
3220 -- False by default (RM H.4.1(4/5) is about the language-defined
3221 -- No_Controlled_Parts aspect, and we are using the same rules for
3224 -- We do not check tagged types since deriving from a formal type
3225 -- within an enclosing generic unit is already illegal
3226 -- (RM 3.9.1 (4/2)).
3228 if Aspect_Value
= Standard_True
3229 and then In_Generic_Body
(Typ
)
3230 and then not Is_Tagged_Type
(Typ
)
3232 Gen_Bodies
:= New_Elmt_List
;
3234 Get_Generic_Formal_Types_In_Hierarchy
3236 Examine_Components
=> True);
3238 -- Climb scopes collecting generic bodies
3240 Scop
:= Scope
(Typ
);
3241 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
3243 -- Generic package body
3245 if Ekind
(Scop
) = E_Generic_Package
3246 and then In_Package_Body
(Scop
)
3248 Append_Elmt
(Scop
, Gen_Bodies
);
3250 -- Generic subprogram body
3252 elsif Is_Generic_Subprogram
(Scop
) then
3253 Append_Elmt
(Scop
, Gen_Bodies
);
3256 Scop
:= Scope
(Scop
);
3259 -- Warn about the improper use of Aspect_No_Parts on a type
3260 -- declaration deriving from or that has a component of a generic
3261 -- formal type within the formal type's corresponding generic
3262 -- body by moving through all formal types in Typ's hierarchy and
3263 -- checking if they are formals in any of the enclosing generic
3266 -- However, a special exception gets made for formal types which
3267 -- derive from a type which has Aspect_No_Parts True.
3272 -- type Form is private;
3274 -- type Type_A is new Form with No_Controlled_Parts; -- OK
3277 -- package body G is
3278 -- type Type_B is new Form with No_Controlled_Parts; -- ERROR
3282 -- type Form is private;
3284 -- type Type_A is record C : Form; end record
3285 -- with No_Controlled_Parts; -- OK
3288 -- package body G is
3289 -- type Type_B is record C : Form; end record
3290 -- with No_Controlled_Parts; -- ERROR
3293 -- type Root is tagged null record with No_Controlled_Parts;
3296 -- type Form is new Root with private;
3298 -- type Type_A is record C : Form; end record
3299 -- with No_Controlled_Parts; -- OK
3302 -- package body G is
3303 -- type Type_B is record C : Form; end record
3304 -- with No_Controlled_Parts; -- OK
3307 Curr_Formal_Elmt
:= First_Elmt
(Gen_Formals
);
3308 while Present
(Curr_Formal_Elmt
) loop
3310 Curr_Body_Elmt
:= First_Elmt
(Gen_Bodies
);
3311 while Present
(Curr_Body_Elmt
) loop
3313 -- Obtain types in the formal type's hierarchy which have
3314 -- the aspect specified.
3316 Types_With_Aspect
:=
3317 Get_Types_With_Aspect_In_Hierarchy
3318 (Node
(Curr_Formal_Elmt
));
3320 -- We found a type declaration in a generic body where both
3321 -- Aspect_No_Parts is true and one of its ancestors is a
3322 -- generic formal type.
3324 if Scope
(Node
(Curr_Formal_Elmt
)) =
3325 Node
(Curr_Body_Elmt
)
3327 -- Check that no ancestors of the formal type have
3328 -- Aspect_No_Parts True before issuing the error.
3330 and then (Is_Empty_Elmt_List
(Types_With_Aspect
)
3332 Get_Aspect_No_Parts_Value
3333 (Node
(First_Elmt
(Types_With_Aspect
)))
3336 Error_Msg_Node_1
:= Typ
;
3337 Error_Msg_Node_2
:= Node
(Curr_Formal_Elmt
);
3339 ("aspect % cannot be applied to "
3340 & "type & which has an ancestor or component of "
3341 & "formal type & within the formal type's "
3342 & "corresponding generic body", Sloc
(Typ
));
3345 Next_Elmt
(Curr_Body_Elmt
);
3348 Next_Elmt
(Curr_Formal_Elmt
);
3351 end Check_No_Parts_Violations
;
3353 ---------------------------------
3354 -- Check_Suspicious_Convention --
3355 ---------------------------------
3357 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
) is
3359 if Has_Discriminants
(Rec_Type
)
3360 and then Is_Base_Type
(Rec_Type
)
3361 and then not Is_Unchecked_Union
(Rec_Type
)
3362 and then (Convention
(Rec_Type
) = Convention_C
3364 Convention
(Rec_Type
) = Convention_CPP
)
3365 and then Comes_From_Source
(Rec_Type
)
3366 and then not In_Instance
3367 and then not Has_Warnings_Off
(Rec_Type
)
3370 Cprag
: constant Node_Id
:=
3371 Get_Rep_Pragma
(Rec_Type
, Name_Convention
);
3375 if Present
(Cprag
) then
3376 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3378 if Convention
(Rec_Type
) = Convention_C
then
3380 ("?x?discriminated record has no direct equivalent in "
3384 ("?x?discriminated record has no direct equivalent in "
3389 ("\?x?use of convention for type& is dubious",
3394 end Check_Suspicious_Convention
;
3396 ------------------------------
3397 -- Check_Suspicious_Modulus --
3398 ------------------------------
3400 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
3401 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
3404 if not Warn_On_Suspicious_Modulus_Value
then
3408 if Nkind
(Decl
) = N_Full_Type_Declaration
then
3410 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
3413 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
3415 Modulus
: constant Node_Id
:=
3416 Original_Node
(Expression
(Tdef
));
3419 if Nkind
(Modulus
) = N_Integer_Literal
then
3421 Modv
: constant Uint
:= Intval
(Modulus
);
3422 Sizv
: constant Uint
:= RM_Size
(Utype
);
3425 -- First case, modulus and size are the same. This
3426 -- happens if you have something like mod 32, with
3427 -- an explicit size of 32, this is for sure a case
3428 -- where the warning is given, since it is seems
3429 -- very unlikely that someone would want e.g. a
3430 -- five bit type stored in 32 bits. It is much
3431 -- more likely they wanted a 32-bit type.
3436 -- Second case, the modulus is 32 or 64 and no
3437 -- size clause is present. This is a less clear
3438 -- case for giving the warning, but in the case
3439 -- of 32/64 (5-bit or 6-bit types) these seem rare
3440 -- enough that it is a likely error (and in any
3441 -- case using 2**5 or 2**6 in these cases seems
3442 -- clearer. We don't include 8 or 16 here, simply
3443 -- because in practice 3-bit and 4-bit types are
3444 -- more common and too many false positives if
3445 -- we warn in these cases.
3447 elsif not Has_Size_Clause
(Utype
)
3448 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
3452 -- No warning needed
3458 -- If we fall through, give warning
3460 Error_Msg_Uint_1
:= Modv
;
3462 ("?.m?2 '*'*^' may have been intended here",
3470 end Check_Suspicious_Modulus
;
3472 -----------------------
3473 -- Freeze_Array_Type --
3474 -----------------------
3476 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
3477 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
3478 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
3481 Non_Standard_Enum
: Boolean := False;
3482 -- Set true if any of the index types is an enumeration type with a
3483 -- non-standard representation.
3486 Freeze_And_Append
(Ctyp
, N
, Result
);
3488 Indx
:= First_Index
(Arr
);
3489 while Present
(Indx
) loop
3490 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
3492 if Is_Enumeration_Type
(Etype
(Indx
))
3493 and then Has_Non_Standard_Rep
(Etype
(Indx
))
3495 Non_Standard_Enum
:= True;
3501 -- Processing that is done only for base types
3503 if Ekind
(Arr
) = E_Array_Type
then
3505 -- Deal with default setting of reverse storage order
3507 Set_SSO_From_Default
(Arr
);
3509 -- Propagate flags for component type
3511 if Is_Controlled
(Ctyp
)
3512 or else Has_Controlled_Component
(Ctyp
)
3514 Set_Has_Controlled_Component
(Arr
);
3517 if Has_Unchecked_Union
(Ctyp
) then
3518 Set_Has_Unchecked_Union
(Arr
);
3521 -- The array type requires its own invariant procedure in order to
3522 -- verify the component invariant over all elements. In GNATprove
3523 -- mode, the component invariants are checked by other means. They
3524 -- should not be added to the array type invariant procedure, so
3525 -- that the procedure can be used to check the array type
3526 -- invariants if any.
3528 if Has_Invariants
(Ctyp
)
3529 and then not GNATprove_Mode
3531 Set_Has_Own_Invariants
(Arr
);
3534 -- Warn for pragma Pack overriding foreign convention
3536 if Has_Foreign_Convention
(Ctyp
)
3537 and then Has_Pragma_Pack
(Arr
)
3540 CN
: constant Name_Id
:=
3541 Get_Convention_Name
(Convention
(Ctyp
));
3542 PP
: constant Node_Id
:=
3543 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
3545 if Present
(PP
) then
3546 Error_Msg_Name_1
:= CN
;
3547 Error_Msg_Sloc
:= Sloc
(Arr
);
3549 ("pragma Pack affects convention % components #??", PP
);
3550 Error_Msg_Name_1
:= CN
;
3552 ("\array components may not have % compatible "
3553 & "representation??", PP
);
3558 -- Check for Aliased or Atomic_Components or Full Access with
3559 -- unsuitable packing or explicit component size clause given.
3561 if (Has_Aliased_Components
(Arr
)
3562 or else Has_Atomic_Components
(Arr
)
3563 or else Is_Full_Access
(Ctyp
))
3565 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
3567 Alias_Atomic_Check
: declare
3569 procedure Complain_CS
(T
: String);
3570 -- Outputs error messages for incorrect CS clause or pragma
3571 -- Pack for aliased or full access components (T is either
3572 -- "aliased" or "atomic" or "volatile full access");
3578 procedure Complain_CS
(T
: String) is
3580 if Has_Component_Size_Clause
(Arr
) then
3582 Get_Attribute_Definition_Clause
3583 (FS
, Attribute_Component_Size
);
3586 ("incorrect component size for "
3587 & T
& " components", Clause
);
3588 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3590 ("\only allowed value is^", Clause
);
3594 ("?cannot pack " & T
& " components (RM 13.2(7))",
3595 Get_Rep_Pragma
(FS
, Name_Pack
));
3596 Set_Is_Packed
(Arr
, False);
3600 -- Start of processing for Alias_Atomic_Check
3603 -- If object size of component type isn't known, we cannot
3604 -- be sure so we defer to the back end.
3606 if not Known_Static_Esize
(Ctyp
) then
3609 -- Case where component size has no effect. First check for
3610 -- object size of component type multiple of the storage
3613 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
3615 -- OK in both packing case and component size case if RM
3616 -- size is known and static and same as the object size.
3619 ((Known_Static_RM_Size
(Ctyp
)
3620 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
3622 -- Or if we have an explicit component size clause and
3623 -- the component size and object size are equal.
3626 (Has_Component_Size_Clause
(Arr
)
3627 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
3631 elsif Has_Aliased_Components
(Arr
) then
3632 Complain_CS
("aliased");
3634 elsif Has_Atomic_Components
(Arr
)
3635 or else Is_Atomic
(Ctyp
)
3637 Complain_CS
("atomic");
3639 elsif Is_Volatile_Full_Access
(Ctyp
) then
3640 Complain_CS
("volatile full access");
3642 end Alias_Atomic_Check
;
3645 -- Check for Independent_Components/Independent with unsuitable
3646 -- packing or explicit component size clause given.
3648 if (Has_Independent_Components
(Arr
) or else Is_Independent
(Ctyp
))
3650 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
3653 -- If object size of component type isn't known, we cannot
3654 -- be sure so we defer to the back end.
3656 if not Known_Static_Esize
(Ctyp
) then
3659 -- Case where component size has no effect. First check for
3660 -- object size of component type multiple of the storage
3663 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
3665 -- OK in both packing case and component size case if RM
3666 -- size is known and multiple of the storage unit size.
3669 ((Known_Static_RM_Size
(Ctyp
)
3670 and then RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
3672 -- Or if we have an explicit component size clause and
3673 -- the component size is larger than the object size.
3676 (Has_Component_Size_Clause
(Arr
)
3677 and then Component_Size
(Arr
) >= Esize
(Ctyp
)))
3682 if Has_Component_Size_Clause
(Arr
) then
3684 Get_Attribute_Definition_Clause
3685 (FS
, Attribute_Component_Size
);
3688 ("incorrect component size for "
3689 & "independent components", Clause
);
3690 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3692 ("\minimum allowed is^", Clause
);
3696 ("?cannot pack independent components (RM 13.2(7))",
3697 Get_Rep_Pragma
(FS
, Name_Pack
));
3698 Set_Is_Packed
(Arr
, False);
3704 -- If packing was requested or if the component size was
3705 -- set explicitly, then see if bit packing is required. This
3706 -- processing is only done for base types, since all of the
3707 -- representation aspects involved are type-related.
3709 -- This is not just an optimization, if we start processing the
3710 -- subtypes, they interfere with the settings on the base type
3711 -- (this is because Is_Packed has a slightly different meaning
3712 -- before and after freezing).
3720 and then Known_Static_RM_Size
(Ctyp
)
3721 and then not Has_Component_Size_Clause
(Arr
)
3723 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
3725 elsif Known_Component_Size
(Arr
) then
3726 Csiz
:= Component_Size
(Arr
);
3728 elsif not Known_Static_Esize
(Ctyp
) then
3732 Esiz
:= Esize
(Ctyp
);
3734 -- We can set the component size if it is less than 16,
3735 -- rounding it up to the next storage unit size.
3739 elsif Esiz
<= 16 then
3745 -- Set component size up to match alignment if it would
3746 -- otherwise be less than the alignment. This deals with
3747 -- cases of types whose alignment exceeds their size (the
3748 -- padded type cases).
3750 if Csiz
/= 0 and then Known_Alignment
(Ctyp
) then
3752 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
3761 -- Case of component size that may result in bit packing
3763 if 1 <= Csiz
and then Csiz
<= System_Max_Integer_Size
then
3765 Ent
: constant Entity_Id
:=
3766 First_Subtype
(Arr
);
3767 Pack_Pragma
: constant Node_Id
:=
3768 Get_Rep_Pragma
(Ent
, Name_Pack
);
3769 Comp_Size_C
: constant Node_Id
:=
3770 Get_Attribute_Definition_Clause
3771 (Ent
, Attribute_Component_Size
);
3774 -- Warn if we have pack and component size so that the
3777 -- Note: here we must check for the presence of a
3778 -- component size before checking for a Pack pragma to
3779 -- deal with the case where the array type is a derived
3780 -- type whose parent is currently private.
3782 if Present
(Comp_Size_C
)
3783 and then Has_Pragma_Pack
(Ent
)
3784 and then Warn_On_Redundant_Constructs
3786 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
3788 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
3790 ("\?r?explicit component size given#!", Pack_Pragma
);
3791 Set_Is_Packed
(Base_Type
(Ent
), False);
3792 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
3795 -- Set component size if not already set by a component
3798 if No
(Comp_Size_C
) then
3799 Set_Component_Size
(Arr
, Csiz
);
3802 -- Check for base type of 8, 16, 32 bits, where an
3803 -- unsigned subtype has a length one less than the
3804 -- base type (e.g. Natural subtype of Integer).
3806 -- In such cases, if a component size was not set
3807 -- explicitly, then generate a warning.
3809 if Has_Pragma_Pack
(Arr
)
3810 and then No
(Comp_Size_C
)
3811 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
3812 and then Known_Esize
(Base_Type
(Ctyp
))
3813 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
3815 Error_Msg_Uint_1
:= Csiz
;
3817 if Present
(Pack_Pragma
) then
3819 ("??pragma Pack causes component size to be ^!",
3822 ("\??use Component_Size to set desired value!",
3827 -- Bit packing is never needed for 8, 16, 32, 64 or 128
3829 if Addressable
(Csiz
) then
3831 -- If the Esize of the component is known and equal to
3832 -- the component size then even packing is not needed.
3834 if Known_Static_Esize
(Ctyp
)
3835 and then Esize
(Ctyp
) = Csiz
3837 -- Here the array was requested to be packed, but
3838 -- the packing request had no effect whatsoever,
3839 -- so flag Is_Packed is reset.
3841 -- Note: semantically this means that we lose track
3842 -- of the fact that a derived type inherited pragma
3843 -- Pack that was non-effective, but that is fine.
3845 -- We regard a Pack pragma as a request to set a
3846 -- representation characteristic, and this request
3849 Set_Is_Packed
(Base_Type
(Arr
), False);
3850 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
3852 Set_Is_Packed
(Base_Type
(Arr
), True);
3853 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3856 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3858 -- Bit packing is not needed for multiples of the storage
3859 -- unit if the type is composite because the back end can
3860 -- byte pack composite types efficiently. That's not true
3861 -- for discrete types because every read would generate a
3862 -- lot of instructions, so we keep using the manipulation
3863 -- routines of the runtime for them.
3865 elsif Csiz
mod System_Storage_Unit
= 0
3866 and then Is_Composite_Type
(Ctyp
)
3868 Set_Is_Packed
(Base_Type
(Arr
), True);
3869 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3870 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3872 -- In all other cases, bit packing is needed
3875 Set_Is_Packed
(Base_Type
(Arr
), True);
3876 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3877 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
3883 -- Warn for case of atomic type
3885 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
3888 and then not Addressable
(Component_Size
(FS
))
3891 ("non-atomic components of type& may not be "
3892 & "accessible by separate tasks??", Clause
, Arr
);
3894 if Has_Component_Size_Clause
(Arr
) then
3895 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
3896 (FS
, Attribute_Component_Size
));
3897 Error_Msg_N
("\because of component size clause#??", Clause
);
3899 elsif Has_Pragma_Pack
(Arr
) then
3900 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
3901 Error_Msg_N
("\because of pragma Pack#??", Clause
);
3905 -- Check for scalar storage order
3910 Check_Component_Storage_Order
3913 ADC
=> Get_Attribute_Definition_Clause
3914 (First_Subtype
(Arr
),
3915 Attribute_Scalar_Storage_Order
),
3916 Comp_ADC_Present
=> Dummy
);
3919 -- Processing that is done only for subtypes
3922 -- Acquire alignment from base type. Known_Alignment of the base
3923 -- type is False for Wide_String, for example.
3925 if not Known_Alignment
(Arr
)
3926 and then Known_Alignment
(Base_Type
(Arr
))
3928 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
3929 Adjust_Esize_Alignment
(Arr
);
3933 -- Specific checks for bit-packed arrays
3935 if Is_Bit_Packed_Array
(Arr
) then
3937 -- Check number of elements for bit-packed arrays that come from
3938 -- source and have compile time known ranges. The bit-packed
3939 -- arrays circuitry does not support arrays with more than
3940 -- Integer'Last + 1 elements, and when this restriction is
3941 -- violated, causes incorrect data access.
3943 -- For the case where this is not compile time known, a run-time
3944 -- check should be generated???
3946 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
3955 Index
:= First_Index
(Arr
);
3956 while Present
(Index
) loop
3957 Ityp
:= Etype
(Index
);
3959 -- Never generate an error if any index is of a generic
3960 -- type. We will check this in instances.
3962 if Is_Generic_Type
(Ityp
) then
3968 Make_Attribute_Reference
(Loc
,
3969 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
3970 Attribute_Name
=> Name_Range_Length
);
3971 Analyze_And_Resolve
(Ilen
);
3973 -- No attempt is made to check number of elements if not
3974 -- compile time known.
3976 if Nkind
(Ilen
) /= N_Integer_Literal
then
3981 Elmts
:= Elmts
* Intval
(Ilen
);
3985 if Elmts
> Intval
(High_Bound
3986 (Scalar_Range
(Standard_Integer
))) + 1
3989 ("bit packed array type may not have "
3990 & "more than Integer''Last+1 elements", Arr
);
3997 if Known_RM_Size
(Arr
) then
3999 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
4003 -- It is not clear if it is possible to have no size clause
4004 -- at this stage, but it is not worth worrying about. Post
4005 -- error on the entity name in the size clause if present,
4006 -- else on the type entity itself.
4008 if Present
(SizC
) then
4009 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
4011 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
4017 -- If any of the index types was an enumeration type with a non-
4018 -- standard rep clause, then we indicate that the array type is
4019 -- always packed (even if it is not bit-packed).
4021 if Non_Standard_Enum
then
4022 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
4023 Set_Is_Packed
(Base_Type
(Arr
));
4026 Set_Component_Alignment_If_Not_Set
(Arr
);
4028 -- If the array is packed and bit-packed or packed to eliminate holes
4029 -- in the non-contiguous enumeration index types, we must create the
4030 -- packed array type to be used to actually implement the type. This
4031 -- is only needed for real array types (not for string literal types,
4032 -- since they are present only for the front end).
4035 and then (Is_Bit_Packed_Array
(Arr
) or else Non_Standard_Enum
)
4036 and then Ekind
(Arr
) /= E_String_Literal_Subtype
4038 Create_Packed_Array_Impl_Type
(Arr
);
4039 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
4041 -- Make sure that we have the necessary routines to implement the
4042 -- packing, and complain now if not. Note that we only test this
4043 -- for constrained array types.
4045 if Is_Constrained
(Arr
)
4046 and then Is_Bit_Packed_Array
(Arr
)
4047 and then Present
(Packed_Array_Impl_Type
(Arr
))
4048 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
4051 CS
: constant Uint
:= Component_Size
(Arr
);
4052 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
4056 and then not RTE_Available
(RE
)
4059 ("packing of " & UI_Image
(CS
) & "-bit components",
4060 First_Subtype
(Etype
(Arr
)));
4062 -- Cancel the packing
4064 Set_Is_Packed
(Base_Type
(Arr
), False);
4065 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
4066 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
4072 -- Size information of packed array type is copied to the array
4073 -- type, since this is really the representation. But do not
4074 -- override explicit existing size values. If the ancestor subtype
4075 -- is constrained the Packed_Array_Impl_Type will be inherited
4076 -- from it, but the size may have been provided already, and
4077 -- must not be overridden either.
4079 if not Has_Size_Clause
(Arr
)
4081 (No
(Ancestor_Subtype
(Arr
))
4082 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
4084 Copy_Esize
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4085 Copy_RM_Size
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4088 if not Has_Alignment_Clause
(Arr
) then
4090 (To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4096 -- A Ghost type cannot have a component of protected or task type
4097 -- (SPARK RM 6.9(19)).
4099 if Is_Ghost_Entity
(Arr
) and then Is_Concurrent_Type
(Ctyp
) then
4101 ("ghost array type & cannot have concurrent component type",
4104 end Freeze_Array_Type
;
4106 -------------------------------
4107 -- Freeze_Object_Declaration --
4108 -------------------------------
4110 procedure Freeze_Object_Declaration
(E
: Entity_Id
) is
4111 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
);
4112 -- Check that the size of array type Typ can be computed without
4113 -- overflow, and generates a Storage_Error otherwise. This is only
4114 -- relevant for array types whose index is a modular type with
4115 -- Standard_Long_Long_Integer_Size bits: wrap-around arithmetic
4116 -- might yield a meaningless value for the length of the array,
4117 -- or its corresponding attribute.
4119 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
);
4120 -- Ensure that the initialization state of variable Var_Id subject
4121 -- to pragma Thread_Local_Storage agrees with the semantics of the
4124 function Has_Default_Initialization
4125 (Obj_Id
: Entity_Id
) return Boolean;
4126 -- Determine whether object Obj_Id default initialized
4128 -------------------------------
4129 -- Check_Large_Modular_Array --
4130 -------------------------------
4132 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
) is
4133 Obj_Loc
: constant Source_Ptr
:= Sloc
(E
);
4134 Idx_Typ
: Entity_Id
;
4137 -- Nothing to do when expansion is disabled because this routine
4138 -- generates a runtime check.
4140 if not Expander_Active
then
4143 -- Nothing to do for String literal subtypes because their index
4144 -- cannot be a modular type.
4146 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
4149 -- Nothing to do for an imported object because the object will
4150 -- be created on the exporting side.
4152 elsif Is_Imported
(E
) then
4155 -- Nothing to do for unconstrained array types. This case arises
4156 -- when the object declaration is illegal.
4158 elsif not Is_Constrained
(Typ
) then
4162 Idx_Typ
:= Etype
(First_Index
(Typ
));
4164 -- To prevent arithmetic overflow with large values, we raise
4165 -- Storage_Error under the following guard:
4167 -- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
4169 -- This takes care of the boundary case, but it is preferable to
4170 -- use a smaller limit, because even on 64-bit architectures an
4171 -- array of more than 2 ** 30 bytes is likely to raise
4174 if Is_Modular_Integer_Type
(Idx_Typ
)
4175 and then RM_Size
(Idx_Typ
) = Standard_Long_Long_Integer_Size
4177 -- Ensure that the type of the object is elaborated before
4178 -- the check itself is emitted to avoid elaboration issues
4179 -- in the code generator at the library level.
4181 if Is_Itype
(Etype
(E
))
4182 and then In_Open_Scopes
(Scope
(Etype
(E
)))
4185 Ref_Node
: constant Node_Id
:=
4186 Make_Itype_Reference
(Obj_Loc
);
4188 Set_Itype
(Ref_Node
, Etype
(E
));
4189 Insert_Action
(Declaration_Node
(E
), Ref_Node
);
4193 Insert_Action
(Declaration_Node
(E
),
4194 Make_Raise_Storage_Error
(Obj_Loc
,
4196 Make_Op_Ge
(Obj_Loc
,
4198 Make_Op_Subtract
(Obj_Loc
,
4200 Make_Op_Divide
(Obj_Loc
,
4202 Make_Attribute_Reference
(Obj_Loc
,
4204 New_Occurrence_Of
(Typ
, Obj_Loc
),
4205 Attribute_Name
=> Name_Last
),
4207 Make_Integer_Literal
(Obj_Loc
, Uint_2
)),
4209 Make_Op_Divide
(Obj_Loc
,
4211 Make_Attribute_Reference
(Obj_Loc
,
4213 New_Occurrence_Of
(Typ
, Obj_Loc
),
4214 Attribute_Name
=> Name_First
),
4216 Make_Integer_Literal
(Obj_Loc
, Uint_2
))),
4218 Make_Integer_Literal
(Obj_Loc
, (Uint_2
** 30))),
4219 Reason
=> SE_Object_Too_Large
));
4221 end Check_Large_Modular_Array
;
4223 ---------------------------------------
4224 -- Check_Pragma_Thread_Local_Storage --
4225 ---------------------------------------
4227 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
) is
4228 function Has_Incompatible_Initialization
4229 (Var_Decl
: Node_Id
) return Boolean;
4230 -- Determine whether variable Var_Id with declaration Var_Decl is
4231 -- initialized with a value that violates the semantics of pragma
4232 -- Thread_Local_Storage.
4234 -------------------------------------
4235 -- Has_Incompatible_Initialization --
4236 -------------------------------------
4238 function Has_Incompatible_Initialization
4239 (Var_Decl
: Node_Id
) return Boolean
4241 Init_Expr
: constant Node_Id
:= Expression
(Var_Decl
);
4244 -- The variable is default-initialized. This directly violates
4245 -- the semantics of the pragma.
4247 if Has_Default_Initialization
(Var_Id
) then
4250 -- The variable has explicit initialization. In this case only
4251 -- a handful of values satisfy the semantics of the pragma.
4253 elsif Has_Init_Expression
(Var_Decl
)
4254 and then Present
(Init_Expr
)
4256 -- "null" is a legal form of initialization
4258 if Nkind
(Init_Expr
) = N_Null
then
4261 -- A static expression is a legal form of initialization
4263 elsif Is_Static_Expression
(Init_Expr
) then
4266 -- A static aggregate is a legal form of initialization
4268 elsif Nkind
(Init_Expr
) = N_Aggregate
4269 and then Compile_Time_Known_Aggregate
(Init_Expr
)
4273 -- All other initialization expressions violate the semantic
4280 -- The variable lacks any kind of initialization, which agrees
4281 -- with the semantics of the pragma.
4286 end Has_Incompatible_Initialization
;
4288 -- Local declarations
4290 Var_Decl
: constant Node_Id
:= Declaration_Node
(Var_Id
);
4292 -- Start of processing for Check_Pragma_Thread_Local_Storage
4295 -- A variable whose initialization is suppressed lacks any kind of
4298 if Suppress_Initialization
(Var_Id
) then
4301 -- The variable has default initialization, or is explicitly
4302 -- initialized to a value other than null, static expression,
4303 -- or a static aggregate.
4305 elsif Has_Incompatible_Initialization
(Var_Decl
) then
4307 ("Thread_Local_Storage variable& is improperly initialized",
4310 ("\only allowed initialization is explicit NULL, static "
4311 & "expression or static aggregate", Var_Decl
, Var_Id
);
4313 end Check_Pragma_Thread_Local_Storage
;
4315 --------------------------------
4316 -- Has_Default_Initialization --
4317 --------------------------------
4319 function Has_Default_Initialization
4320 (Obj_Id
: Entity_Id
) return Boolean
4322 Obj_Decl
: constant Node_Id
:= Declaration_Node
(Obj_Id
);
4323 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
4327 Comes_From_Source
(Obj_Id
)
4328 and then not Is_Imported
(Obj_Id
)
4329 and then not Has_Init_Expression
(Obj_Decl
)
4331 ((Has_Non_Null_Base_Init_Proc
(Obj_Typ
)
4332 and then not No_Initialization
(Obj_Decl
)
4333 and then not Initialization_Suppressed
(Obj_Typ
))
4335 (Needs_Simple_Initialization
(Obj_Typ
)
4336 and then not Is_Internal
(Obj_Id
)));
4337 end Has_Default_Initialization
;
4341 Typ
: constant Entity_Id
:= Etype
(E
);
4344 -- Start of processing for Freeze_Object_Declaration
4347 -- Abstract type allowed only for C++ imported variables or constants
4349 -- Note: we inhibit this check for objects that do not come from
4350 -- source because there is at least one case (the expansion of
4351 -- x'Class'Input where x is abstract) where we legitimately
4352 -- generate an abstract object.
4354 if Is_Abstract_Type
(Typ
)
4355 and then Comes_From_Source
(Parent
(E
))
4356 and then not (Is_Imported
(E
) and then Is_CPP_Class
(Typ
))
4358 Def
:= Object_Definition
(Parent
(E
));
4360 Error_Msg_N
("type of object cannot be abstract", Def
);
4362 if Is_CPP_Class
(Etype
(E
)) then
4363 Error_Msg_NE
("\} may need a cpp_constructor", Def
, Typ
);
4365 elsif Present
(Expression
(Parent
(E
))) then
4366 Error_Msg_N
-- CODEFIX
4367 ("\maybe a class-wide type was meant", Def
);
4371 -- For object created by object declaration, perform required
4372 -- categorization (preelaborate and pure) checks. Defer these
4373 -- checks to freeze time since pragma Import inhibits default
4374 -- initialization and thus pragma Import affects these checks.
4376 Validate_Object_Declaration
(Declaration_Node
(E
));
4378 -- If there is an address clause, check that it is valid and if need
4379 -- be move initialization to the freeze node.
4381 Check_Address_Clause
(E
);
4383 -- Similar processing is needed for aspects that may affect object
4384 -- layout, like Address, if there is an initialization expression.
4385 -- We don't do this if there is a pragma Linker_Section, because it
4386 -- would prevent the back end from statically initializing the
4387 -- object; we don't want elaboration code in that case.
4389 if Has_Delayed_Aspects
(E
)
4390 and then Expander_Active
4391 and then Is_Array_Type
(Typ
)
4392 and then Present
(Expression
(Declaration_Node
(E
)))
4393 and then No
(Linker_Section_Pragma
(E
))
4396 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4397 Lhs
: constant Node_Id
:= New_Occurrence_Of
(E
, Loc
);
4400 -- Capture initialization value at point of declaration, and
4401 -- make explicit assignment legal, because object may be a
4404 Remove_Side_Effects
(Expression
(Decl
));
4405 Set_Assignment_OK
(Lhs
);
4407 -- Move initialization to freeze actions
4409 Append_Freeze_Action
(E
,
4410 Make_Assignment_Statement
(Loc
,
4412 Expression
=> Expression
(Decl
)));
4414 Set_No_Initialization
(Decl
);
4415 -- Set_Is_Frozen (E, False);
4419 -- Reset Is_True_Constant for non-constant aliased object. We
4420 -- consider that the fact that a non-constant object is aliased may
4421 -- indicate that some funny business is going on, e.g. an aliased
4422 -- object is passed by reference to a procedure which captures the
4423 -- address of the object, which is later used to assign a new value,
4424 -- even though the compiler thinks that it is not modified. Such
4425 -- code is highly dubious, but we choose to make it "work" for
4426 -- non-constant aliased objects.
4428 -- Note that we used to do this for all aliased objects, whether or
4429 -- not constant, but this caused anomalies down the line because we
4430 -- ended up with static objects that were not Is_True_Constant. Not
4431 -- resetting Is_True_Constant for (aliased) constant objects ensures
4432 -- that this anomaly never occurs.
4434 -- However, we don't do that for internal entities. We figure that if
4435 -- we deliberately set Is_True_Constant for an internal entity, e.g.
4436 -- a dispatch table entry, then we mean it.
4438 if Ekind
(E
) /= E_Constant
4439 and then (Is_Aliased
(E
) or else Is_Aliased
(Typ
))
4440 and then not Is_Internal_Name
(Chars
(E
))
4442 Set_Is_True_Constant
(E
, False);
4445 -- If the object needs any kind of default initialization, an error
4446 -- must be issued if No_Default_Initialization applies. The check
4447 -- doesn't apply to imported objects, which are not ever default
4448 -- initialized, and is why the check is deferred until freezing, at
4449 -- which point we know if Import applies. Deferred constants are also
4450 -- exempted from this test because their completion is explicit, or
4451 -- through an import pragma.
4453 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
4456 elsif Has_Default_Initialization
(E
) then
4458 (No_Default_Initialization
, Declaration_Node
(E
));
4461 -- Ensure that a variable subject to pragma Thread_Local_Storage
4463 -- * Lacks default initialization, or
4465 -- * The initialization expression is either "null", a static
4466 -- constant, or a compile-time known aggregate.
4468 if Has_Pragma_Thread_Local_Storage
(E
) then
4469 Check_Pragma_Thread_Local_Storage
(E
);
4472 -- For imported objects, set Is_Public unless there is also an
4473 -- address clause, which means that there is no external symbol
4474 -- needed for the Import (Is_Public may still be set for other
4475 -- unrelated reasons). Note that we delayed this processing
4476 -- till freeze time so that we can be sure not to set the flag
4477 -- if there is an address clause. If there is such a clause,
4478 -- then the only purpose of the Import pragma is to suppress
4479 -- implicit initialization.
4481 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4485 -- For source objects that are not Imported and are library level, if
4486 -- no linker section pragma was given inherit the appropriate linker
4487 -- section from the corresponding type.
4489 if Comes_From_Source
(E
)
4490 and then not Is_Imported
(E
)
4491 and then Is_Library_Level_Entity
(E
)
4492 and then No
(Linker_Section_Pragma
(E
))
4494 Set_Linker_Section_Pragma
(E
, Linker_Section_Pragma
(Typ
));
4497 -- For convention C objects of an enumeration type, warn if the size
4498 -- is not integer size and no explicit size given. Skip warning for
4499 -- Boolean and Character, and assume programmer expects 8-bit sizes
4502 if (Convention
(E
) = Convention_C
4504 Convention
(E
) = Convention_CPP
)
4505 and then Is_Enumeration_Type
(Typ
)
4506 and then not Is_Character_Type
(Typ
)
4507 and then not Is_Boolean_Type
(Typ
)
4508 and then Esize
(Typ
) < Standard_Integer_Size
4509 and then not Has_Size_Clause
(E
)
4511 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4513 ("??convention C enumeration object has size less than ^", E
);
4514 Error_Msg_N
("\??use explicit size clause to set size", E
);
4517 -- Declaring too big an array in disabled ghost code is OK
4519 if Is_Array_Type
(Typ
) and then not Is_Ignored_Ghost_Entity
(E
) then
4520 Check_Large_Modular_Array
(Typ
);
4522 end Freeze_Object_Declaration
;
4524 -----------------------------
4525 -- Freeze_Generic_Entities --
4526 -----------------------------
4528 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
4535 E
:= First_Entity
(Pack
);
4536 while Present
(E
) loop
4537 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
4538 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
4540 Append_To
(Flist
, F
);
4542 elsif Ekind
(E
) = E_Generic_Package
then
4543 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
4550 end Freeze_Generic_Entities
;
4552 --------------------
4553 -- Freeze_Profile --
4554 --------------------
4556 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
4559 Warn_Node
: Node_Id
;
4562 -- Loop through formals
4564 Formal
:= First_Formal
(E
);
4565 while Present
(Formal
) loop
4566 F_Type
:= Etype
(Formal
);
4568 -- AI05-0151: incomplete types can appear in a profile. By the
4569 -- time the entity is frozen, the full view must be available,
4570 -- unless it is a limited view.
4572 if Is_Incomplete_Type
(F_Type
)
4573 and then Present
(Full_View
(F_Type
))
4574 and then not From_Limited_With
(F_Type
)
4576 F_Type
:= Full_View
(F_Type
);
4577 Set_Etype
(Formal
, F_Type
);
4580 if not From_Limited_With
(F_Type
)
4581 and then Should_Freeze_Type
(F_Type
, E
, N
)
4583 Freeze_And_Append
(F_Type
, N
, Result
);
4586 if Is_Private_Type
(F_Type
)
4587 and then Is_Private_Type
(Base_Type
(F_Type
))
4588 and then No
(Full_View
(Base_Type
(F_Type
)))
4589 and then not Is_Generic_Type
(F_Type
)
4590 and then not Is_Derived_Type
(F_Type
)
4592 -- If the type of a formal is incomplete, subprogram is being
4593 -- frozen prematurely. Within an instance (but not within a
4594 -- wrapper package) this is an artifact of our need to regard
4595 -- the end of an instantiation as a freeze point. Otherwise it
4596 -- is a definite error.
4599 Set_Is_Frozen
(E
, False);
4603 elsif not After_Last_Declaration
then
4605 ("type & must be fully defined before this point",
4611 -- Check suspicious parameter for C function. These tests apply
4612 -- only to exported/imported subprograms.
4614 if Warn_On_Export_Import
4615 and then Comes_From_Source
(E
)
4616 and then Convention
(E
) in Convention_C_Family
4617 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4618 and then Convention
(E
) /= Convention
(Formal
)
4619 and then not Has_Warnings_Off
(E
)
4620 and then not Has_Warnings_Off
(F_Type
)
4621 and then not Has_Warnings_Off
(Formal
)
4623 -- Qualify mention of formals with subprogram name
4625 Error_Msg_Qual_Level
:= 1;
4627 -- Check suspicious use of fat C pointer, but do not emit
4628 -- a warning on an access to subprogram when unnesting is
4631 if Is_Access_Type
(F_Type
)
4632 and then Known_Esize
(F_Type
)
4633 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
4634 and then (not Unnest_Subprogram_Mode
4635 or else not Is_Access_Subprogram_Type
(F_Type
))
4638 ("?x?type of & does not correspond to C pointer!", Formal
);
4640 -- Check suspicious return of boolean
4642 elsif Root_Type
(F_Type
) = Standard_Boolean
4643 and then Convention
(F_Type
) = Convention_Ada
4644 and then not Has_Warnings_Off
(F_Type
)
4645 and then not Has_Size_Clause
(F_Type
)
4648 ("& is an 8-bit Ada Boolean?x?", Formal
);
4650 ("\use appropriate corresponding type in C "
4651 & "(e.g. char)?x?", Formal
);
4653 -- Check suspicious tagged type
4655 elsif (Is_Tagged_Type
(F_Type
)
4657 (Is_Access_Type
(F_Type
)
4658 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
4659 and then Convention
(E
) = Convention_C
4662 ("?x?& involves a tagged type which does not "
4663 & "correspond to any C type!", Formal
);
4665 -- Check wrong convention subprogram pointer
4667 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
4668 and then not Has_Foreign_Convention
(F_Type
)
4671 ("?x?subprogram pointer & should "
4672 & "have foreign convention!", Formal
);
4673 Error_Msg_Sloc
:= Sloc
(F_Type
);
4675 ("\?x?add Convention pragma to declaration of &#",
4679 -- Turn off name qualification after message output
4681 Error_Msg_Qual_Level
:= 0;
4684 -- Check for unconstrained array in exported foreign convention
4687 if Has_Foreign_Convention
(E
)
4688 and then not Is_Imported
(E
)
4689 and then Is_Array_Type
(F_Type
)
4690 and then not Is_Constrained
(F_Type
)
4691 and then Warn_On_Export_Import
4693 Error_Msg_Qual_Level
:= 1;
4695 -- If this is an inherited operation, place the warning on
4696 -- the derived type declaration, rather than on the original
4699 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
4701 Warn_Node
:= Parent
(E
);
4703 if Formal
= First_Formal
(E
) then
4704 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
4707 Warn_Node
:= Formal
;
4710 Error_Msg_NE
("?x?type of argument& is unconstrained array",
4712 Error_Msg_N
("\?x?foreign caller must pass bounds explicitly",
4714 Error_Msg_Qual_Level
:= 0;
4717 if not From_Limited_With
(F_Type
) then
4718 if Is_Access_Type
(F_Type
) then
4719 F_Type
:= Designated_Type
(F_Type
);
4723 Next_Formal
(Formal
);
4726 -- Case of function: similar checks on return type
4728 if Ekind
(E
) = E_Function
then
4730 -- Freeze return type
4732 R_Type
:= Etype
(E
);
4734 -- AI05-0151: the return type may have been incomplete at the
4735 -- point of declaration. Replace it with the full view, unless the
4736 -- current type is a limited view. In that case the full view is
4737 -- in a different unit, and gigi finds the non-limited view after
4738 -- the other unit is elaborated.
4740 if Ekind
(R_Type
) = E_Incomplete_Type
4741 and then Present
(Full_View
(R_Type
))
4742 and then not From_Limited_With
(R_Type
)
4744 R_Type
:= Full_View
(R_Type
);
4745 Set_Etype
(E
, R_Type
);
4748 if Should_Freeze_Type
(R_Type
, E
, N
) then
4749 Freeze_And_Append
(R_Type
, N
, Result
);
4752 -- Check suspicious return type for C function
4754 if Warn_On_Export_Import
4755 and then Comes_From_Source
(E
)
4756 and then Convention
(E
) in Convention_C_Family
4757 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4759 -- Check suspicious return of fat C pointer
4761 if Is_Access_Type
(R_Type
)
4762 and then Known_Esize
(R_Type
)
4763 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
4764 and then not Has_Warnings_Off
(E
)
4765 and then not Has_Warnings_Off
(R_Type
)
4768 ("?x?return type of& does not correspond to C pointer!",
4771 -- Check suspicious return of boolean
4773 elsif Root_Type
(R_Type
) = Standard_Boolean
4774 and then Convention
(R_Type
) = Convention_Ada
4775 and then not Has_Warnings_Off
(E
)
4776 and then not Has_Warnings_Off
(R_Type
)
4777 and then not Has_Size_Clause
(R_Type
)
4780 N
: constant Node_Id
:=
4781 Result_Definition
(Declaration_Node
(E
));
4784 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
4786 ("\use appropriate corresponding type in C "
4787 & "(e.g. char)?x?", N
, E
);
4790 -- Check suspicious return tagged type
4792 elsif (Is_Tagged_Type
(R_Type
)
4793 or else (Is_Access_Type
(R_Type
)
4796 (Designated_Type
(R_Type
))))
4797 and then Convention
(E
) = Convention_C
4798 and then not Has_Warnings_Off
(E
)
4799 and then not Has_Warnings_Off
(R_Type
)
4801 Error_Msg_N
("?x?return type of & does not "
4802 & "correspond to C type!", E
);
4804 -- Check return of wrong convention subprogram pointer
4806 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
4807 and then not Has_Foreign_Convention
(R_Type
)
4808 and then not Has_Warnings_Off
(E
)
4809 and then not Has_Warnings_Off
(R_Type
)
4811 Error_Msg_N
("?x?& should return a foreign "
4812 & "convention subprogram pointer", E
);
4813 Error_Msg_Sloc
:= Sloc
(R_Type
);
4815 ("\?x?add Convention pragma to declaration of& #",
4820 -- Give warning for suspicious return of a result of an
4821 -- unconstrained array type in a foreign convention function.
4823 if Has_Foreign_Convention
(E
)
4825 -- We are looking for a return of unconstrained array
4827 and then Is_Array_Type
(R_Type
)
4828 and then not Is_Constrained
(R_Type
)
4830 -- Exclude imported routines, the warning does not belong on
4831 -- the import, but rather on the routine definition.
4833 and then not Is_Imported
(E
)
4835 -- Check that general warning is enabled, and that it is not
4836 -- suppressed for this particular case.
4838 and then Warn_On_Export_Import
4839 and then not Has_Warnings_Off
(E
)
4840 and then not Has_Warnings_Off
(R_Type
)
4843 ("?x?foreign convention function& should not return "
4844 & "unconstrained array!", E
);
4848 -- Check suspicious use of Import in pure unit (cases where the RM
4849 -- allows calls to be omitted).
4853 -- It might be suspicious if the compilation unit has the Pure
4856 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
4858 -- The RM allows omission of calls only in the case of
4859 -- library-level subprograms (see RM-10.2.1(18)).
4861 and then Is_Library_Level_Entity
(E
)
4863 -- Ignore internally generated entity. This happens in some cases
4864 -- of subprograms in specs, where we generate an implied body.
4866 and then Comes_From_Source
(Import_Pragma
(E
))
4868 -- Assume run-time knows what it is doing
4870 and then not GNAT_Mode
4872 -- Assume explicit Pure_Function means import is pure
4874 and then not Has_Pragma_Pure_Function
(E
)
4876 -- Don't need warning in relaxed semantics mode
4878 and then not Relaxed_RM_Semantics
4880 -- Assume convention Intrinsic is OK, since this is specialized.
4881 -- This deals with the DEC unit current_exception.ads
4883 and then Convention
(E
) /= Convention_Intrinsic
4885 -- Assume that ASM interface knows what it is doing
4887 and then Convention
(E
) /= Convention_Assembler
4890 ("pragma Import in Pure unit??", Import_Pragma
(E
));
4892 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
4893 Import_Pragma
(E
), E
);
4899 ------------------------
4900 -- Freeze_Record_Type --
4901 ------------------------
4903 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
4910 pragma Warnings
(Off
, Junk
);
4912 Aliased_Component
: Boolean := False;
4913 -- Set True if we find at least one component which is aliased. This
4914 -- is used to prevent Implicit_Packing of the record, since packing
4915 -- cannot modify the size of alignment of an aliased component.
4917 All_Elem_Components
: Boolean := True;
4918 -- True if all components are of a type whose underlying type is
4921 All_Sized_Components
: Boolean := True;
4922 -- True if all components have a known RM_Size
4924 All_Storage_Unit_Components
: Boolean := True;
4925 -- True if all components have an RM_Size that is a multiple of the
4928 Elem_Component_Total_Esize
: Uint
:= Uint_0
;
4929 -- Accumulates total Esize values of all elementary components. Used
4930 -- for processing of Implicit_Packing.
4932 Placed_Component
: Boolean := False;
4933 -- Set True if we find at least one component with a component
4934 -- clause (used to warn about useless Bit_Order pragmas, and also
4935 -- to detect cases where Implicit_Packing may have an effect).
4937 Sized_Component_Total_RM_Size
: Uint
:= Uint_0
;
4938 -- Accumulates total RM_Size values of all sized components. Used
4939 -- for processing of Implicit_Packing.
4941 Sized_Component_Total_Round_RM_Size
: Uint
:= Uint_0
;
4942 -- Accumulates total RM_Size values of all sized components, rounded
4943 -- individually to a multiple of the storage unit.
4946 -- Scalar_Storage_Order attribute definition clause for the record
4948 SSO_ADC_Component
: Boolean := False;
4949 -- Set True if we find at least one component whose type has a
4950 -- Scalar_Storage_Order attribute definition clause.
4952 Unplaced_Component
: Boolean := False;
4953 -- Set True if we find at least one component with no component
4954 -- clause (used to warn about useless Pack pragmas).
4956 procedure Check_Itype
(Typ
: Entity_Id
);
4957 -- If the component subtype is an access to a constrained subtype of
4958 -- an already frozen type, make the subtype frozen as well. It might
4959 -- otherwise be frozen in the wrong scope, and a freeze node on
4960 -- subtype has no effect. Similarly, if the component subtype is a
4961 -- regular (not protected) access to subprogram, set the anonymous
4962 -- subprogram type to frozen as well, to prevent an out-of-scope
4963 -- freeze node at some eventual point of call. Protected operations
4964 -- are handled elsewhere.
4966 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
4967 -- Make sure that all types mentioned in Discrete_Choices of the
4968 -- variants referenceed by the Variant_Part VP are frozen. This is
4969 -- a recursive routine to deal with nested variants.
4975 procedure Check_Itype
(Typ
: Entity_Id
) is
4976 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
4979 if not Is_Frozen
(Desig
)
4980 and then Is_Frozen
(Base_Type
(Desig
))
4982 Set_Is_Frozen
(Desig
);
4984 -- In addition, add an Itype_Reference to ensure that the
4985 -- access subtype is elaborated early enough. This cannot be
4986 -- done if the subtype may depend on discriminants.
4988 if Ekind
(Comp
) = E_Component
4989 and then Is_Itype
(Etype
(Comp
))
4990 and then not Has_Discriminants
(Rec
)
4992 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
4993 Set_Itype
(IR
, Desig
);
4997 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
4998 and then Convention
(Desig
) /= Convention_Protected
5000 Set_Is_Frozen
(Desig
);
5001 Create_Extra_Formals
(Desig
);
5005 ------------------------------------
5006 -- Freeze_Choices_In_Variant_Part --
5007 ------------------------------------
5009 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
5010 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
5017 -- Loop through variants
5019 Variant
:= First_Non_Pragma
(Variants
(VP
));
5020 while Present
(Variant
) loop
5022 -- Loop through choices, checking that all types are frozen
5024 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
5025 while Present
(Choice
) loop
5026 if Nkind
(Choice
) in N_Has_Etype
5027 and then Present
(Etype
(Choice
))
5029 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
5032 Next_Non_Pragma
(Choice
);
5035 -- Check for nested variant part to process
5037 CL
:= Component_List
(Variant
);
5039 if not Null_Present
(CL
) then
5040 if Present
(Variant_Part
(CL
)) then
5041 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
5045 Next_Non_Pragma
(Variant
);
5047 end Freeze_Choices_In_Variant_Part
;
5049 -- Start of processing for Freeze_Record_Type
5052 -- Freeze components and embedded subtypes
5054 Comp
:= First_Entity
(Rec
);
5056 while Present
(Comp
) loop
5057 if Is_Aliased
(Comp
) then
5058 Aliased_Component
:= True;
5061 -- Handle the component and discriminant case
5063 if Ekind
(Comp
) in E_Component | E_Discriminant
then
5065 CC
: constant Node_Id
:= Component_Clause
(Comp
);
5068 -- Freezing a record type freezes the type of each of its
5069 -- components. However, if the type of the component is
5070 -- part of this record, we do not want or need a separate
5071 -- Freeze_Node. Note that Is_Itype is wrong because that's
5072 -- also set in private type cases. We also can't check for
5073 -- the Scope being exactly Rec because of private types and
5074 -- record extensions.
5076 if Is_Itype
(Etype
(Comp
))
5077 and then Is_Record_Type
(Underlying_Type
5078 (Scope
(Etype
(Comp
))))
5080 Undelay_Type
(Etype
(Comp
));
5083 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5085 -- Warn for pragma Pack overriding foreign convention
5087 if Has_Foreign_Convention
(Etype
(Comp
))
5088 and then Has_Pragma_Pack
(Rec
)
5090 -- Don't warn for aliased components, since override
5091 -- cannot happen in that case.
5093 and then not Is_Aliased
(Comp
)
5096 CN
: constant Name_Id
:=
5097 Get_Convention_Name
(Convention
(Etype
(Comp
)));
5098 PP
: constant Node_Id
:=
5099 Get_Pragma
(Rec
, Pragma_Pack
);
5101 if Present
(PP
) then
5102 Error_Msg_Name_1
:= CN
;
5103 Error_Msg_Sloc
:= Sloc
(Comp
);
5105 ("pragma Pack affects convention % component#??",
5107 Error_Msg_Name_1
:= CN
;
5109 ("\component & may not have % compatible "
5110 & "representation??", PP
, Comp
);
5115 -- Check for error of component clause given for variable
5116 -- sized type. We have to delay this test till this point,
5117 -- since the component type has to be frozen for us to know
5118 -- if it is variable length.
5120 if Present
(CC
) then
5121 Placed_Component
:= True;
5123 -- We omit this test in a generic context, it will be
5124 -- applied at instantiation time.
5126 if Inside_A_Generic
then
5129 -- Also omit this test in CodePeer mode, since we do not
5130 -- have sufficient info on size and rep clauses.
5132 elsif CodePeer_Mode
then
5138 Size_Known_At_Compile_Time
5139 (Underlying_Type
(Etype
(Comp
)))
5142 ("component clause not allowed for variable " &
5143 "length component", CC
);
5147 Unplaced_Component
:= True;
5150 -- Case of component requires byte alignment
5152 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
5154 -- Set the enclosing record to also require byte align
5156 Set_Must_Be_On_Byte_Boundary
(Rec
);
5158 -- Check for component clause that is inconsistent with
5159 -- the required byte boundary alignment.
5162 and then Normalized_First_Bit
(Comp
) mod
5163 System_Storage_Unit
/= 0
5166 ("component & must be byte aligned",
5167 Component_Name
(Component_Clause
(Comp
)));
5173 -- Gather data for possible Implicit_Packing later. Note that at
5174 -- this stage we might be dealing with a real component, or with
5175 -- an implicit subtype declaration.
5177 if Known_Static_RM_Size
(Etype
(Comp
)) then
5179 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
5180 Comp_Size
: constant Uint
:= RM_Size
(Comp_Type
);
5181 SSU
: constant Int
:= Ttypes
.System_Storage_Unit
;
5184 Sized_Component_Total_RM_Size
:=
5185 Sized_Component_Total_RM_Size
+ Comp_Size
;
5187 Sized_Component_Total_Round_RM_Size
:=
5188 Sized_Component_Total_Round_RM_Size
+
5189 (Comp_Size
+ SSU
- 1) / SSU
* SSU
;
5191 if Present
(Underlying_Type
(Comp_Type
))
5192 and then Is_Elementary_Type
(Underlying_Type
(Comp_Type
))
5194 Elem_Component_Total_Esize
:=
5195 Elem_Component_Total_Esize
+ Esize
(Comp_Type
);
5197 All_Elem_Components
:= False;
5199 if Comp_Size
mod SSU
/= 0 then
5200 All_Storage_Unit_Components
:= False;
5205 All_Sized_Components
:= False;
5208 -- If the component is an Itype with Delayed_Freeze and is either
5209 -- a record or array subtype and its base type has not yet been
5210 -- frozen, we must remove this from the entity list of this record
5211 -- and put it on the entity list of the scope of its base type.
5212 -- Note that we know that this is not the type of a component
5213 -- since we cleared Has_Delayed_Freeze for it in the previous
5214 -- loop. Thus this must be the Designated_Type of an access type,
5215 -- which is the type of a component.
5218 and then Is_Type
(Scope
(Comp
))
5219 and then Is_Composite_Type
(Comp
)
5220 and then Base_Type
(Comp
) /= Comp
5221 and then Has_Delayed_Freeze
(Comp
)
5222 and then not Is_Frozen
(Base_Type
(Comp
))
5225 Will_Be_Frozen
: Boolean := False;
5229 -- We have a difficult case to handle here. Suppose Rec is
5230 -- subtype being defined in a subprogram that's created as
5231 -- part of the freezing of Rec'Base. In that case, we know
5232 -- that Comp'Base must have already been frozen by the time
5233 -- we get to elaborate this because Gigi doesn't elaborate
5234 -- any bodies until it has elaborated all of the declarative
5235 -- part. But Is_Frozen will not be set at this point because
5236 -- we are processing code in lexical order.
5238 -- We detect this case by going up the Scope chain of Rec
5239 -- and seeing if we have a subprogram scope before reaching
5240 -- the top of the scope chain or that of Comp'Base. If we
5241 -- do, then mark that Comp'Base will actually be frozen. If
5242 -- so, we merely undelay it.
5245 while Present
(S
) loop
5246 if Is_Subprogram
(S
) then
5247 Will_Be_Frozen
:= True;
5249 elsif S
= Scope
(Base_Type
(Comp
)) then
5256 if Will_Be_Frozen
then
5257 Undelay_Type
(Comp
);
5260 if Present
(Prev
) then
5261 Link_Entities
(Prev
, Next_Entity
(Comp
));
5263 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
5266 -- Insert in entity list of scope of base type (which
5267 -- must be an enclosing scope, because still unfrozen).
5269 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
5273 -- If the component is an access type with an allocator as default
5274 -- value, the designated type will be frozen by the corresponding
5275 -- expression in init_proc. In order to place the freeze node for
5276 -- the designated type before that for the current record type,
5279 -- Same process if the component is an array of access types,
5280 -- initialized with an aggregate. If the designated type is
5281 -- private, it cannot contain allocators, and it is premature
5282 -- to freeze the type, so we check for this as well.
5284 elsif Is_Access_Type
(Etype
(Comp
))
5285 and then Present
(Parent
(Comp
))
5287 Nkind
(Parent
(Comp
))
5288 in N_Component_Declaration | N_Discriminant_Specification
5289 and then Present
(Expression
(Parent
(Comp
)))
5292 Alloc
: constant Node_Id
:=
5293 Unqualify
(Expression
(Parent
(Comp
)));
5296 if Nkind
(Alloc
) = N_Allocator
then
5298 -- If component is pointer to a class-wide type, freeze
5299 -- the specific type in the expression being allocated.
5300 -- The expression may be a subtype indication, in which
5301 -- case freeze the subtype mark.
5303 if Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp
)))
5305 if Is_Entity_Name
(Expression
(Alloc
)) then
5307 (Entity
(Expression
(Alloc
)), N
, Result
);
5309 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
5312 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
5315 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
5316 Check_Itype
(Etype
(Comp
));
5319 (Designated_Type
(Etype
(Comp
)), N
, Result
);
5323 elsif Is_Access_Type
(Etype
(Comp
))
5324 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
5326 Check_Itype
(Etype
(Comp
));
5328 -- Freeze the designated type when initializing a component with
5329 -- an aggregate in case the aggregate contains allocators.
5332 -- type T_Ptr is access all T;
5333 -- type T_Array is array ... of T_Ptr;
5335 -- type Rec is record
5336 -- Comp : T_Array := (others => ...);
5339 elsif Is_Array_Type
(Etype
(Comp
))
5340 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
5343 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
5344 Desig_Typ
: constant Entity_Id
:=
5346 (Component_Type
(Etype
(Comp
)));
5349 -- The only case when this sort of freezing is not done is
5350 -- when the designated type is class-wide and the root type
5351 -- is the record owning the component. This scenario results
5352 -- in a circularity because the class-wide type requires
5353 -- primitives that have not been created yet as the root
5354 -- type is in the process of being frozen.
5356 -- type Rec is tagged;
5357 -- type Rec_Ptr is access all Rec'Class;
5358 -- type Rec_Array is array ... of Rec_Ptr;
5360 -- type Rec is record
5361 -- Comp : Rec_Array := (others => ...);
5364 if Is_Class_Wide_Type
(Desig_Typ
)
5365 and then Root_Type
(Desig_Typ
) = Rec
5369 elsif Is_Fully_Defined
(Desig_Typ
)
5370 and then Present
(Comp_Par
)
5371 and then Nkind
(Comp_Par
) = N_Component_Declaration
5372 and then Present
(Expression
(Comp_Par
))
5373 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
5375 Freeze_And_Append
(Desig_Typ
, N
, Result
);
5385 Get_Attribute_Definition_Clause
5386 (Rec
, Attribute_Scalar_Storage_Order
);
5388 -- If the record type has Complex_Representation, then it is treated
5389 -- as a scalar in the back end so the storage order is irrelevant.
5391 if Has_Complex_Representation
(Rec
) then
5392 if Present
(SSO_ADC
) then
5394 ("??storage order has no effect with Complex_Representation",
5399 -- Deal with default setting of reverse storage order
5401 Set_SSO_From_Default
(Rec
);
5403 -- Check consistent attribute setting on component types
5406 Comp_ADC_Present
: Boolean;
5408 Comp
:= First_Component
(Rec
);
5409 while Present
(Comp
) loop
5410 Check_Component_Storage_Order
5414 Comp_ADC_Present
=> Comp_ADC_Present
);
5415 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
5416 Next_Component
(Comp
);
5420 -- Now deal with reverse storage order/bit order issues
5422 if Present
(SSO_ADC
) then
5424 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
5425 -- if the former is specified.
5427 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
5429 -- Note: report error on Rec, not on SSO_ADC, as ADC may
5430 -- apply to some ancestor type.
5432 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
5434 ("scalar storage order for& specified# inconsistent with "
5435 & "bit order", Rec
);
5438 -- Warn if there is a Scalar_Storage_Order attribute definition
5439 -- clause but no component clause, no component that itself has
5440 -- such an attribute definition, and no pragma Pack.
5442 if not (Placed_Component
5449 ("??scalar storage order specified but no component "
5450 & "clause", SSO_ADC
);
5455 -- Deal with Bit_Order aspect
5457 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
5459 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
5460 if not (Placed_Component
5461 or else Present
(SSO_ADC
)
5462 or else Is_Packed
(Rec
))
5464 -- Warn if clause has no effect when no component clause is
5465 -- present, but suppress warning if the Bit_Order is required
5466 -- due to the presence of a Scalar_Storage_Order attribute.
5469 ("??bit order specification has no effect", ADC
);
5471 ("\??since no component clauses were specified", ADC
);
5473 -- Here is where we do the processing to adjust component clauses
5474 -- for reversed bit order, when not using reverse SSO. If an error
5475 -- has been reported on Rec already (such as SSO incompatible with
5476 -- bit order), don't bother adjusting as this may generate extra
5479 elsif Reverse_Bit_Order
(Rec
)
5480 and then not Reverse_Storage_Order
(Rec
)
5481 and then not Error_Posted
(Rec
)
5483 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
5485 -- Case where we have both an explicit Bit_Order and the same
5486 -- Scalar_Storage_Order: leave record untouched, the back-end
5487 -- will take care of required layout conversions.
5495 -- Check for useless pragma Pack when all components placed. We only
5496 -- do this check for record types, not subtypes, since a subtype may
5497 -- have all its components placed, and it still makes perfectly good
5498 -- sense to pack other subtypes or the parent type. We do not give
5499 -- this warning if Optimize_Alignment is set to Space, since the
5500 -- pragma Pack does have an effect in this case (it always resets
5501 -- the alignment to one).
5503 if Ekind
(Rec
) = E_Record_Type
5504 and then Is_Packed
(Rec
)
5505 and then not Unplaced_Component
5506 and then Optimize_Alignment
/= 'S'
5508 -- Reset packed status. Probably not necessary, but we do it so
5509 -- that there is no chance of the back end doing something strange
5510 -- with this redundant indication of packing.
5512 Set_Is_Packed
(Rec
, False);
5514 -- Give warning if redundant constructs warnings on
5516 if Warn_On_Redundant_Constructs
then
5517 Error_Msg_N
-- CODEFIX
5518 ("?r?pragma Pack has no effect, no unplaced components",
5519 Get_Rep_Pragma
(Rec
, Name_Pack
));
5523 -- If this is the record corresponding to a remote type, freeze the
5524 -- remote type here since that is what we are semantically freezing.
5525 -- This prevents the freeze node for that type in an inner scope.
5527 if Ekind
(Rec
) = E_Record_Type
then
5528 if Present
(Corresponding_Remote_Type
(Rec
)) then
5529 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
5532 -- Check for controlled components, unchecked unions, and type
5535 Comp
:= First_Component
(Rec
);
5536 while Present
(Comp
) loop
5538 -- Do not set Has_Controlled_Component on a class-wide
5539 -- equivalent type. See Make_CW_Equivalent_Type.
5541 if not Is_Class_Wide_Equivalent_Type
(Rec
)
5543 (Has_Controlled_Component
(Etype
(Comp
))
5545 (Chars
(Comp
) /= Name_uParent
5546 and then Is_Controlled
(Etype
(Comp
)))
5548 (Is_Protected_Type
(Etype
(Comp
))
5550 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
5552 Has_Controlled_Component
5553 (Corresponding_Record_Type
(Etype
(Comp
)))))
5555 Set_Has_Controlled_Component
(Rec
);
5558 if Has_Unchecked_Union
(Etype
(Comp
)) then
5559 Set_Has_Unchecked_Union
(Rec
);
5562 -- The record type requires its own invariant procedure in
5563 -- order to verify the invariant of each individual component.
5564 -- Do not consider internal components such as _parent because
5565 -- parent class-wide invariants are always inherited.
5566 -- In GNATprove mode, the component invariants are checked by
5567 -- other means. They should not be added to the record type
5568 -- invariant procedure, so that the procedure can be used to
5569 -- check the recordy type invariants if any.
5571 if Comes_From_Source
(Comp
)
5572 and then Has_Invariants
(Etype
(Comp
))
5573 and then not GNATprove_Mode
5575 Set_Has_Own_Invariants
(Rec
);
5578 -- Scan component declaration for likely misuses of current
5579 -- instance, either in a constraint or a default expression.
5581 if Has_Per_Object_Constraint
(Comp
) then
5582 Check_Current_Instance
(Parent
(Comp
));
5585 Next_Component
(Comp
);
5589 -- Enforce the restriction that access attributes with a current
5590 -- instance prefix can only apply to limited types. This comment
5591 -- is floating here, but does not seem to belong here???
5593 -- Set component alignment if not otherwise already set
5595 Set_Component_Alignment_If_Not_Set
(Rec
);
5597 -- For first subtypes, check if there are any fixed-point fields with
5598 -- component clauses, where we must check the size. This is not done
5599 -- till the freeze point since for fixed-point types, we do not know
5600 -- the size until the type is frozen. Similar processing applies to
5601 -- bit-packed arrays.
5603 if Is_First_Subtype
(Rec
) then
5604 Comp
:= First_Component
(Rec
);
5605 while Present
(Comp
) loop
5606 if Present
(Component_Clause
(Comp
))
5607 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
5608 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
5611 (Component_Name
(Component_Clause
(Comp
)),
5617 Next_Component
(Comp
);
5621 -- See if Size is too small as is (and implicit packing might help)
5623 if not Is_Packed
(Rec
)
5625 -- No implicit packing if even one component is explicitly placed
5627 and then not Placed_Component
5629 -- Or even one component is aliased
5631 and then not Aliased_Component
5633 -- Must have size clause and all sized components
5635 and then Has_Size_Clause
(Rec
)
5636 and then All_Sized_Components
5638 -- Do not try implicit packing on records with discriminants, too
5639 -- complicated, especially in the variant record case.
5641 and then not Has_Discriminants
(Rec
)
5643 -- We want to implicitly pack if the specified size of the record
5644 -- is less than the sum of the object sizes (no point in packing
5645 -- if this is not the case), if we can compute it, i.e. if we have
5646 -- only elementary components. Otherwise, we have at least one
5647 -- composite component and we want to implicitly pack only if bit
5648 -- packing is required for it, as we are sure in this case that
5649 -- the back end cannot do the expected layout without packing.
5652 ((All_Elem_Components
5653 and then RM_Size
(Rec
) < Elem_Component_Total_Esize
)
5655 (not All_Elem_Components
5656 and then not All_Storage_Unit_Components
5657 and then RM_Size
(Rec
) < Sized_Component_Total_Round_RM_Size
))
5659 -- And the total RM size cannot be greater than the specified size
5660 -- since otherwise packing will not get us where we have to be.
5662 and then Sized_Component_Total_RM_Size
<= RM_Size
(Rec
)
5664 -- Never do implicit packing in CodePeer or SPARK modes since
5665 -- we don't do any packing in these modes, since this generates
5666 -- over-complex code that confuses static analysis, and in
5667 -- general, neither CodePeer not GNATprove care about the
5668 -- internal representation of objects.
5670 and then not (CodePeer_Mode
or GNATprove_Mode
)
5672 -- If implicit packing enabled, do it
5674 if Implicit_Packing
then
5675 Set_Is_Packed
(Rec
);
5677 -- Otherwise flag the size clause
5681 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
5683 Error_Msg_NE
-- CODEFIX
5684 ("size given for& too small", Sz
, Rec
);
5685 Error_Msg_N
-- CODEFIX
5686 ("\use explicit pragma Pack "
5687 & "or use pragma Implicit_Packing", Sz
);
5692 -- Make sure that if we have an iterator aspect, then we have
5693 -- either Constant_Indexing or Variable_Indexing.
5696 Iterator_Aspect
: Node_Id
;
5699 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
5701 if No
(Iterator_Aspect
) then
5702 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
5705 if Present
(Iterator_Aspect
) then
5706 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
5708 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
5713 ("Iterator_Element requires indexing aspect",
5719 -- All done if not a full record definition
5721 if Ekind
(Rec
) /= E_Record_Type
then
5725 -- Finally we need to check the variant part to make sure that
5726 -- all types within choices are properly frozen as part of the
5727 -- freezing of the record type.
5729 Check_Variant_Part
: declare
5730 D
: constant Node_Id
:= Declaration_Node
(Rec
);
5735 -- Find component list
5739 if Nkind
(D
) = N_Full_Type_Declaration
then
5740 T
:= Type_Definition
(D
);
5742 if Nkind
(T
) = N_Record_Definition
then
5743 C
:= Component_List
(T
);
5745 elsif Nkind
(T
) = N_Derived_Type_Definition
5746 and then Present
(Record_Extension_Part
(T
))
5748 C
:= Component_List
(Record_Extension_Part
(T
));
5752 -- Case of variant part present
5754 if Present
(C
) and then Present
(Variant_Part
(C
)) then
5755 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
5758 -- Note: we used to call Check_Choices here, but it is too early,
5759 -- since predicated subtypes are frozen here, but their freezing
5760 -- actions are in Analyze_Freeze_Entity, which has not been called
5761 -- yet for entities frozen within this procedure, so we moved that
5762 -- call to the Analyze_Freeze_Entity for the record type.
5764 end Check_Variant_Part
;
5766 -- Check that all the primitives of an interface type are abstract
5767 -- or null procedures.
5769 if Is_Interface
(Rec
)
5770 and then not Error_Posted
(Parent
(Rec
))
5777 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
5778 while Present
(Elmt
) loop
5779 Subp
:= Node
(Elmt
);
5781 if not Is_Abstract_Subprogram
(Subp
)
5783 -- Avoid reporting the error on inherited primitives
5785 and then Comes_From_Source
(Subp
)
5787 Error_Msg_Name_1
:= Chars
(Subp
);
5789 if Ekind
(Subp
) = E_Procedure
then
5790 if not Null_Present
(Parent
(Subp
)) then
5792 ("interface procedure % must be abstract or null",
5797 ("interface function % must be abstract",
5807 -- For a derived tagged type, check whether inherited primitives
5808 -- might require a wrapper to handle class-wide conditions.
5810 if Is_Tagged_Type
(Rec
) and then Is_Derived_Type
(Rec
) then
5811 Check_Inherited_Conditions
(Rec
);
5813 end Freeze_Record_Type
;
5815 -------------------------------
5816 -- Has_Boolean_Aspect_Import --
5817 -------------------------------
5819 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
5820 Decl
: constant Node_Id
:= Declaration_Node
(E
);
5825 if Has_Aspects
(Decl
) then
5826 Asp
:= First
(Aspect_Specifications
(Decl
));
5827 while Present
(Asp
) loop
5828 Expr
:= Expression
(Asp
);
5830 -- The value of aspect Import is True when the expression is
5831 -- either missing or it is explicitly set to True.
5833 if Get_Aspect_Id
(Asp
) = Aspect_Import
5835 or else (Compile_Time_Known_Value
(Expr
)
5836 and then Is_True
(Expr_Value
(Expr
))))
5846 end Has_Boolean_Aspect_Import
;
5848 -------------------------
5849 -- Inherit_Freeze_Node --
5850 -------------------------
5852 procedure Inherit_Freeze_Node
5856 Typ_Fnod
: constant Node_Id
:= Freeze_Node
(Typ
);
5859 Set_Freeze_Node
(Typ
, Fnod
);
5860 Set_Entity
(Fnod
, Typ
);
5862 -- The input type had an existing node. Propagate relevant attributes
5863 -- from the old freeze node to the inherited freeze node.
5865 -- ??? if both freeze nodes have attributes, would they differ?
5867 if Present
(Typ_Fnod
) then
5869 -- Attribute Access_Types_To_Process
5871 if Present
(Access_Types_To_Process
(Typ_Fnod
))
5872 and then No
(Access_Types_To_Process
(Fnod
))
5874 Set_Access_Types_To_Process
(Fnod
,
5875 Access_Types_To_Process
(Typ_Fnod
));
5878 -- Attribute Actions
5880 if Present
(Actions
(Typ_Fnod
)) and then No
(Actions
(Fnod
)) then
5881 Set_Actions
(Fnod
, Actions
(Typ_Fnod
));
5884 -- Attribute First_Subtype_Link
5886 if Present
(First_Subtype_Link
(Typ_Fnod
))
5887 and then No
(First_Subtype_Link
(Fnod
))
5889 Set_First_Subtype_Link
(Fnod
, First_Subtype_Link
(Typ_Fnod
));
5892 -- Attribute TSS_Elist
5894 if Present
(TSS_Elist
(Typ_Fnod
))
5895 and then No
(TSS_Elist
(Fnod
))
5897 Set_TSS_Elist
(Fnod
, TSS_Elist
(Typ_Fnod
));
5900 end Inherit_Freeze_Node
;
5902 ------------------------------
5903 -- Wrap_Imported_Subprogram --
5904 ------------------------------
5906 -- The issue here is that our normal approach of checking preconditions
5907 -- and postconditions does not work for imported procedures, since we
5908 -- are not generating code for the body. To get around this we create
5909 -- a wrapper, as shown by the following example:
5911 -- procedure K (A : Integer);
5912 -- pragma Import (C, K);
5914 -- The spec is rewritten by removing the effects of pragma Import, but
5915 -- leaving the convention unchanged, as though the source had said:
5917 -- procedure K (A : Integer);
5918 -- pragma Convention (C, K);
5920 -- and we create a body, added to the entity K freeze actions, which
5923 -- procedure K (A : Integer) is
5924 -- procedure K (A : Integer);
5925 -- pragma Import (C, K);
5930 -- Now the contract applies in the normal way to the outer procedure,
5931 -- and the inner procedure has no contracts, so there is no problem
5932 -- in just calling it to get the original effect.
5934 -- In the case of a function, we create an appropriate return statement
5935 -- for the subprogram body that calls the inner procedure.
5937 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
5938 function Copy_Import_Pragma
return Node_Id
;
5939 -- Obtain a copy of the Import_Pragma which belongs to subprogram E
5941 ------------------------
5942 -- Copy_Import_Pragma --
5943 ------------------------
5945 function Copy_Import_Pragma
return Node_Id
is
5947 -- The subprogram should have an import pragma, otherwise it does
5950 Prag
: constant Node_Id
:= Import_Pragma
(E
);
5951 pragma Assert
(Present
(Prag
));
5953 -- Save all semantic fields of the pragma
5955 Save_Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
5956 Save_From
: constant Boolean := From_Aspect_Specification
(Prag
);
5957 Save_Prag
: constant Node_Id
:= Next_Pragma
(Prag
);
5958 Save_Rep
: constant Node_Id
:= Next_Rep_Item
(Prag
);
5963 -- Reset all semantic fields. This avoids a potential infinite
5964 -- loop when the pragma comes from an aspect as the duplication
5965 -- will copy the aspect, then copy the corresponding pragma and
5968 Set_Corresponding_Aspect
(Prag
, Empty
);
5969 Set_From_Aspect_Specification
(Prag
, False);
5970 Set_Next_Pragma
(Prag
, Empty
);
5971 Set_Next_Rep_Item
(Prag
, Empty
);
5973 Result
:= Copy_Separate_Tree
(Prag
);
5975 -- Restore the original semantic fields
5977 Set_Corresponding_Aspect
(Prag
, Save_Asp
);
5978 Set_From_Aspect_Specification
(Prag
, Save_From
);
5979 Set_Next_Pragma
(Prag
, Save_Prag
);
5980 Set_Next_Rep_Item
(Prag
, Save_Rep
);
5983 end Copy_Import_Pragma
;
5987 Loc
: constant Source_Ptr
:= Sloc
(E
);
5988 CE
: constant Name_Id
:= Chars
(E
);
5996 -- Start of processing for Wrap_Imported_Subprogram
5999 -- Nothing to do if not imported
6001 if not Is_Imported
(E
) then
6004 -- Test enabling conditions for wrapping
6006 elsif Is_Subprogram
(E
)
6007 and then Present
(Contract
(E
))
6008 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
6009 and then not GNATprove_Mode
6011 -- Here we do the wrap
6013 Prag
:= Copy_Import_Pragma
;
6015 -- Fix up spec so it is no longer imported and has convention Ada
6017 Set_Has_Completion
(E
, False);
6018 Set_Import_Pragma
(E
, Empty
);
6019 Set_Interface_Name
(E
, Empty
);
6020 Set_Is_Imported
(E
, False);
6021 Set_Convention
(E
, Convention_Ada
);
6023 -- Grab the subprogram declaration and specification
6025 Spec
:= Declaration_Node
(E
);
6027 -- Build parameter list that we need
6030 Forml
:= First_Formal
(E
);
6031 while Present
(Forml
) loop
6032 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
6033 Next_Formal
(Forml
);
6038 -- An imported function whose result type is anonymous access
6039 -- creates a new anonymous access type when it is relocated into
6040 -- the declarations of the body generated below. As a result, the
6041 -- accessibility level of these two anonymous access types may not
6042 -- be compatible even though they are essentially the same type.
6043 -- Use an unchecked type conversion to reconcile this case. Note
6044 -- that the conversion is safe because in the named access type
6045 -- case, both the body and imported function utilize the same
6048 if Ekind
(E
) in E_Function | E_Generic_Function
then
6050 Make_Simple_Return_Statement
(Loc
,
6052 Unchecked_Convert_To
(Etype
(E
),
6053 Make_Function_Call
(Loc
,
6054 Name
=> Make_Identifier
(Loc
, CE
),
6055 Parameter_Associations
=> Parms
)));
6059 Make_Procedure_Call_Statement
(Loc
,
6060 Name
=> Make_Identifier
(Loc
, CE
),
6061 Parameter_Associations
=> Parms
);
6064 -- Now build the body
6067 Make_Subprogram_Body
(Loc
,
6068 Specification
=> Copy_Subprogram_Spec
(Spec
),
6069 Declarations
=> New_List
(
6070 Make_Subprogram_Declaration
(Loc
,
6071 Specification
=> Copy_Subprogram_Spec
(Spec
)),
6073 Handled_Statement_Sequence
=>
6074 Make_Handled_Sequence_Of_Statements
(Loc
,
6075 Statements
=> New_List
(Stmt
),
6076 End_Label
=> Make_Identifier
(Loc
, CE
)));
6078 -- Append the body to freeze result
6080 Add_To_Result
(Bod
);
6083 -- Case of imported subprogram that does not get wrapped
6086 -- Set Is_Public. All imported entities need an external symbol
6087 -- created for them since they are always referenced from another
6088 -- object file. Note this used to be set when we set Is_Imported
6089 -- back in Sem_Prag, but now we delay it to this point, since we
6090 -- don't want to set this flag if we wrap an imported subprogram.
6094 end Wrap_Imported_Subprogram
;
6096 -- Start of processing for Freeze_Entity
6099 -- The entity being frozen may be subject to pragma Ghost. Set the mode
6100 -- now to ensure that any nodes generated during freezing are properly
6101 -- flagged as Ghost.
6105 -- We are going to test for various reasons why this entity need not be
6106 -- frozen here, but in the case of an Itype that's defined within a
6107 -- record, that test actually applies to the record.
6109 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
6110 Test_E
:= Scope
(E
);
6112 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
6113 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
6115 Test_E
:= Underlying_Type
(Scope
(E
));
6118 -- Do not freeze if already frozen since we only need one freeze node
6120 if Is_Frozen
(E
) then
6123 and then not Is_Base_Type
(E
)
6124 and then not Is_Frozen
(Etype
(E
))
6126 -- If a frozen subtype of an unfrozen type seems impossible
6127 -- then see Analyze_Protected_Definition.Undelay_Itypes.
6129 Result
:= Freeze_Entity
6130 (Etype
(E
), N
, Do_Freeze_Profile
=> Do_Freeze_Profile
);
6137 -- Do not freeze if we are preanalyzing without freezing
6139 elsif Inside_Preanalysis_Without_Freezing
> 0 then
6143 elsif Ekind
(E
) = E_Generic_Package
then
6144 Result
:= Freeze_Generic_Entities
(E
);
6147 -- It is improper to freeze an external entity within a generic because
6148 -- its freeze node will appear in a non-valid context. The entity will
6149 -- be frozen in the proper scope after the current generic is analyzed.
6150 -- However, aspects must be analyzed because they may be queried later
6151 -- within the generic itself, and the corresponding pragma or attribute
6152 -- definition has not been analyzed yet. After this, indicate that the
6153 -- entity has no further delayed aspects, to prevent a later aspect
6154 -- analysis out of the scope of the generic.
6156 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
6157 if Has_Delayed_Aspects
(E
) then
6158 Analyze_Aspects_At_Freeze_Point
(E
);
6159 Set_Has_Delayed_Aspects
(E
, False);
6165 -- AI05-0213: A formal incomplete type does not freeze the actual. In
6166 -- the instance, the same applies to the subtype renaming the actual.
6168 elsif Is_Private_Type
(E
)
6169 and then Is_Generic_Actual_Type
(E
)
6170 and then No
(Full_View
(Base_Type
(E
)))
6171 and then Ada_Version
>= Ada_2012
6176 -- Formal subprograms are never frozen
6178 elsif Is_Formal_Subprogram
(E
) then
6182 -- Generic types are never frozen as they lack delayed semantic checks
6184 elsif Is_Generic_Type
(E
) then
6188 -- Do not freeze a global entity within an inner scope created during
6189 -- expansion. A call to subprogram E within some internal procedure
6190 -- (a stream attribute for example) might require freezing E, but the
6191 -- freeze node must appear in the same declarative part as E itself.
6192 -- The two-pass elaboration mechanism in gigi guarantees that E will
6193 -- be frozen before the inner call is elaborated. We exclude constants
6194 -- from this test, because deferred constants may be frozen early, and
6195 -- must be diagnosed (e.g. in the case of a deferred constant being used
6196 -- in a default expression). If the enclosing subprogram comes from
6197 -- source, or is a generic instance, then the freeze point is the one
6198 -- mandated by the language, and we freeze the entity. A subprogram that
6199 -- is a child unit body that acts as a spec does not have a spec that
6200 -- comes from source, but can only come from source.
6202 elsif In_Open_Scopes
(Scope
(Test_E
))
6203 and then Scope
(Test_E
) /= Current_Scope
6204 and then Ekind
(Test_E
) /= E_Constant
6206 -- Here we deal with the special case of the expansion of
6207 -- postconditions. Previously this was handled by the loop below,
6208 -- since these postcondition checks got isolated to a separate,
6209 -- internally generated, subprogram. Now, however, the postcondition
6210 -- checks get contained within their corresponding subprogram
6213 if not Comes_From_Source
(N
)
6214 and then Nkind
(N
) = N_Pragma
6215 and then From_Aspect_Specification
(N
)
6216 and then Is_Valid_Assertion_Kind
(Original_Aspect_Pragma_Name
(N
))
6218 -- Now, verify the placement of the pragma is within an expanded
6219 -- subprogram which contains postcondition expansion - detected
6220 -- through the presence of the "Wrapped_Statements" field.
6222 and then Present
(Enclosing_Subprogram
(Current_Scope
))
6223 and then Present
(Wrapped_Statements
6224 (Enclosing_Subprogram
(Current_Scope
)))
6229 -- Otherwise, loop through scopes checking if an enclosing scope
6230 -- comes from source or is a generic. Note that, for the purpose
6231 -- of this test, we need to consider that the internally generated
6232 -- subprogram described above comes from source too if the original
6233 -- subprogram itself does.
6240 while Present
(S
) loop
6241 if Is_Overloadable
(S
) then
6242 if Comes_From_Source
(S
)
6243 or else (Chars
(S
) = Name_uWrapped_Statements
6244 and then Comes_From_Source
(Scope
(S
)))
6245 or else Is_Generic_Instance
(S
)
6246 or else Is_Child_Unit
(S
)
6259 -- Similarly, an inlined instance body may make reference to global
6260 -- entities, but these references cannot be the proper freezing point
6261 -- for them, and in the absence of inlining freezing will take place in
6262 -- their own scope. Normally instance bodies are analyzed after the
6263 -- enclosing compilation, and everything has been frozen at the proper
6264 -- place, but with front-end inlining an instance body is compiled
6265 -- before the end of the enclosing scope, and as a result out-of-order
6266 -- freezing must be prevented.
6268 elsif Front_End_Inlining
6269 and then In_Instance_Body
6270 and then Present
(Scope
(Test_E
))
6276 S
:= Scope
(Test_E
);
6277 while Present
(S
) loop
6278 if Is_Generic_Instance
(S
) then
6292 -- Add checks to detect proper initialization of scalars that may appear
6293 -- as subprogram parameters.
6295 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
6296 Apply_Parameter_Validity_Checks
(E
);
6299 -- Deal with delayed aspect specifications. The analysis of the aspect
6300 -- is required to be delayed to the freeze point, thus we analyze the
6301 -- pragma or attribute definition clause in the tree at this point. We
6302 -- also analyze the aspect specification node at the freeze point when
6303 -- the aspect doesn't correspond to pragma/attribute definition clause.
6304 -- In addition, a derived type may have inherited aspects that were
6305 -- delayed in the parent, so these must also be captured now.
6307 -- For a record type, we deal with the delayed aspect specifications on
6308 -- components first, which is consistent with the non-delayed case and
6309 -- makes it possible to have a single processing to detect conflicts.
6311 if Is_Record_Type
(E
) then
6315 Rec_Pushed
: Boolean := False;
6316 -- Set True if the record type E has been pushed on the scope
6317 -- stack. Needed for the analysis of delayed aspects specified
6318 -- to the components of Rec.
6321 Comp
:= First_Component
(E
);
6322 while Present
(Comp
) loop
6323 if Has_Delayed_Aspects
(Comp
) then
6324 if not Rec_Pushed
then
6328 -- The visibility to the discriminants must be restored
6329 -- in order to properly analyze the aspects.
6331 if Has_Discriminants
(E
) then
6332 Install_Discriminants
(E
);
6336 Analyze_Aspects_At_Freeze_Point
(Comp
);
6339 Next_Component
(Comp
);
6342 -- Pop the scope if Rec scope has been pushed on the scope stack
6343 -- during the delayed aspect analysis process.
6346 if Has_Discriminants
(E
) then
6347 Uninstall_Discriminants
(E
);
6355 if Has_Delayed_Aspects
(E
) then
6356 Analyze_Aspects_At_Freeze_Point
(E
);
6359 -- Here to freeze the entity
6363 -- Case of entity being frozen is other than a type
6365 if not Is_Type
(E
) then
6367 -- If entity is exported or imported and does not have an external
6368 -- name, now is the time to provide the appropriate default name.
6369 -- Skip this if the entity is stubbed, since we don't need a name
6370 -- for any stubbed routine. For the case on intrinsics, if no
6371 -- external name is specified, then calls will be handled in
6372 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
6373 -- external name is provided, then Expand_Intrinsic_Call leaves
6374 -- calls in place for expansion by GIGI.
6376 if (Is_Imported
(E
) or else Is_Exported
(E
))
6377 and then No
(Interface_Name
(E
))
6378 and then Convention
(E
) /= Convention_Stubbed
6379 and then Convention
(E
) /= Convention_Intrinsic
6381 Set_Encoded_Interface_Name
6382 (E
, Get_Default_External_Name
(E
));
6387 if Is_Subprogram
(E
) then
6389 -- Check for needing to wrap imported subprogram
6391 if not Inside_A_Generic
then
6392 Wrap_Imported_Subprogram
(E
);
6395 -- Freeze all parameter types and the return type (RM 13.14(14)).
6396 -- However skip this for internal subprograms. This is also where
6397 -- any extra formal parameters are created since we now know
6398 -- whether the subprogram will use a foreign convention.
6400 -- In Ada 2012, freezing a subprogram does not always freeze the
6401 -- corresponding profile (see AI05-019). An attribute reference
6402 -- is not a freezing point of the profile. Similarly, we do not
6403 -- freeze the profile of primitives of a library-level tagged type
6404 -- when we are building its dispatch table. Flag Do_Freeze_Profile
6405 -- indicates whether the profile should be frozen now.
6407 -- This processing doesn't apply to internal entities (see below)
6409 if not Is_Internal
(E
) and then Do_Freeze_Profile
then
6410 if not Freeze_Profile
(E
) then
6415 -- Must freeze its parent first if it is a derived subprogram
6417 if Present
(Alias
(E
)) then
6418 Freeze_And_Append
(Alias
(E
), N
, Result
);
6421 -- We don't freeze internal subprograms, because we don't normally
6422 -- want addition of extra formals or mechanism setting to happen
6423 -- for those. However we do pass through predefined dispatching
6424 -- cases, since extra formals may be needed in some cases, such as
6425 -- for the stream 'Input function (build-in-place formals).
6427 if not Is_Internal
(E
)
6428 or else Is_Predefined_Dispatching_Operation
(E
)
6430 Freeze_Subprogram
(E
);
6433 -- If warning on suspicious contracts then check for the case of
6434 -- a postcondition other than False for a No_Return subprogram.
6437 and then Warn_On_Suspicious_Contract
6438 and then Present
(Contract
(E
))
6441 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
6445 while Present
(Prag
) loop
6446 if Pragma_Name_Unmapped
(Prag
) in Name_Post
6447 | Name_Postcondition
6452 (First
(Pragma_Argument_Associations
(Prag
)));
6454 if Nkind
(Exp
) /= N_Identifier
6455 or else Chars
(Exp
) /= Name_False
6458 ("useless postcondition, & is marked "
6459 & "No_Return?.t?", Exp
, E
);
6463 Prag
:= Next_Pragma
(Prag
);
6468 -- Here for other than a subprogram or type
6471 -- If entity has a type declared in the current scope, and it is
6472 -- not a generic unit, then freeze it first.
6474 if Present
(Etype
(E
))
6475 and then Ekind
(E
) /= E_Generic_Function
6476 and then Within_Scope
(Etype
(E
), Current_Scope
)
6478 Freeze_And_Append
(Etype
(E
), N
, Result
);
6480 -- For an object of an anonymous array type, aspects on the
6481 -- object declaration apply to the type itself. This is the
6482 -- case for Atomic_Components, Volatile_Components, and
6483 -- Independent_Components. In these cases analysis of the
6484 -- generated pragma will mark the anonymous types accordingly,
6485 -- and the object itself does not require a freeze node.
6487 if Ekind
(E
) = E_Variable
6488 and then Is_Itype
(Etype
(E
))
6489 and then Is_Array_Type
(Etype
(E
))
6490 and then Has_Delayed_Aspects
(E
)
6492 Set_Has_Delayed_Aspects
(E
, False);
6493 Set_Has_Delayed_Freeze
(E
, False);
6494 Set_Freeze_Node
(E
, Empty
);
6498 -- Special processing for objects created by object declaration;
6499 -- we protect the call to Declaration_Node against entities of
6500 -- expressions replaced by the frontend with an N_Raise_CE node.
6502 if Ekind
(E
) in E_Constant | E_Variable
6503 and then Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
6505 Freeze_Object_Declaration
(E
);
6508 -- Check that a constant which has a pragma Volatile[_Components]
6509 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
6511 -- Note: Atomic[_Components] also sets Volatile[_Components]
6513 if Ekind
(E
) = E_Constant
6514 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
6515 and then not Is_Imported
(E
)
6516 and then not Has_Boolean_Aspect_Import
(E
)
6518 -- Make sure we actually have a pragma, and have not merely
6519 -- inherited the indication from elsewhere (e.g. an address
6520 -- clause, which is not good enough in RM terms).
6522 if Has_Rep_Pragma
(E
, Name_Atomic
)
6524 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
6527 ("standalone atomic constant must be " &
6528 "imported (RM C.6(13))", E
);
6530 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
6532 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
6535 ("standalone volatile constant must be " &
6536 "imported (RM C.6(13))", E
);
6540 -- Static objects require special handling
6542 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
6543 and then Is_Statically_Allocated
(E
)
6545 Freeze_Static_Object
(E
);
6548 -- Remaining step is to layout objects
6550 if Ekind
(E
) in E_Variable | E_Constant | E_Loop_Parameter
6551 or else Is_Formal
(E
)
6556 -- For an object that does not have delayed freezing, and whose
6557 -- initialization actions have been captured in a compound
6558 -- statement, move them back now directly within the enclosing
6559 -- statement sequence.
6561 if Ekind
(E
) in E_Constant | E_Variable
6562 and then not Has_Delayed_Freeze
(E
)
6564 Explode_Initialization_Compound_Statement
(E
);
6567 -- Do not generate a freeze node for a generic unit
6569 if Is_Generic_Unit
(E
) then
6575 -- Case of a type or subtype being frozen
6578 -- Verify several SPARK legality rules related to Ghost types now
6579 -- that the type is frozen.
6581 Check_Ghost_Type
(E
);
6583 -- We used to check here that a full type must have preelaborable
6584 -- initialization if it completes a private type specified with
6585 -- pragma Preelaborable_Initialization, but that missed cases where
6586 -- the types occur within a generic package, since the freezing
6587 -- that occurs within a containing scope generally skips traversal
6588 -- of a generic unit's declarations (those will be frozen within
6589 -- instances). This check was moved to Analyze_Package_Specification.
6591 -- The type may be defined in a generic unit. This can occur when
6592 -- freezing a generic function that returns the type (which is
6593 -- defined in a parent unit). It is clearly meaningless to freeze
6594 -- this type. However, if it is a subtype, its size may be determi-
6595 -- nable and used in subsequent checks, so might as well try to
6598 -- In Ada 2012, Freeze_Entities is also used in the front end to
6599 -- trigger the analysis of aspect expressions, so in this case we
6600 -- want to continue the freezing process.
6602 -- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead
6603 -- In_Generic_Scope (E)???
6605 if Present
(Scope
(E
))
6606 and then Is_Generic_Unit
(Scope
(E
))
6608 (not Has_Predicates
(E
)
6609 and then not Has_Delayed_Freeze
(E
))
6611 Check_Compile_Time_Size
(E
);
6616 -- Check for error of Type_Invariant'Class applied to an untagged
6617 -- type (check delayed to freeze time when full type is available).
6620 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
6623 and then Class_Present
(Prag
)
6624 and then not Is_Tagged_Type
(E
)
6627 ("Type_Invariant''Class cannot be specified for &", Prag
, E
);
6629 ("\can only be specified for a tagged type", Prag
);
6633 -- Deal with special cases of freezing for subtype
6635 if E
/= Base_Type
(E
) then
6637 -- Before we do anything else, a specific test for the case of a
6638 -- size given for an array where the array would need to be packed
6639 -- in order for the size to be honored, but is not. This is the
6640 -- case where implicit packing may apply. The reason we do this so
6641 -- early is that, if we have implicit packing, the layout of the
6642 -- base type is affected, so we must do this before we freeze the
6645 -- We could do this processing only if implicit packing is enabled
6646 -- since in all other cases, the error would be caught by the back
6647 -- end. However, we choose to do the check even if we do not have
6648 -- implicit packing enabled, since this allows us to give a more
6649 -- useful error message (advising use of pragma Implicit_Packing
6652 if Is_Array_Type
(E
) then
6654 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
6655 Rsiz
: constant Uint
:=
6656 (if Known_RM_Size
(Ctyp
) then RM_Size
(Ctyp
) else Uint_0
);
6657 SZ
: constant Node_Id
:= Size_Clause
(E
);
6658 Btyp
: constant Entity_Id
:= Base_Type
(E
);
6665 Num_Elmts
: Uint
:= Uint_1
;
6666 -- Number of elements in array
6669 -- Check enabling conditions. These are straightforward
6670 -- except for the test for a limited composite type. This
6671 -- eliminates the rare case of a array of limited components
6672 -- where there are issues of whether or not we can go ahead
6673 -- and pack the array (since we can't freely pack and unpack
6674 -- arrays if they are limited).
6676 -- Note that we check the root type explicitly because the
6677 -- whole point is we are doing this test before we have had
6678 -- a chance to freeze the base type (and it is that freeze
6679 -- action that causes stuff to be inherited).
6681 -- The conditions on the size are identical to those used in
6682 -- Freeze_Array_Type to set the Is_Packed flag.
6684 if Has_Size_Clause
(E
)
6685 and then Known_Static_RM_Size
(E
)
6686 and then not Is_Packed
(E
)
6687 and then not Has_Pragma_Pack
(E
)
6688 and then not Has_Component_Size_Clause
(E
)
6689 and then Known_Static_RM_Size
(Ctyp
)
6690 and then Rsiz
<= System_Max_Integer_Size
6691 and then not (Addressable
(Rsiz
)
6692 and then Known_Static_Esize
(Ctyp
)
6693 and then Esize
(Ctyp
) = Rsiz
)
6694 and then not (Rsiz
mod System_Storage_Unit
= 0
6695 and then Is_Composite_Type
(Ctyp
))
6696 and then not Is_Limited_Composite
(E
)
6697 and then not Is_Packed
(Root_Type
(E
))
6698 and then not Has_Component_Size_Clause
(Root_Type
(E
))
6699 and then not (CodePeer_Mode
or GNATprove_Mode
)
6701 -- Compute number of elements in array
6703 Indx
:= First_Index
(E
);
6704 while Present
(Indx
) loop
6705 Get_Index_Bounds
(Indx
, Lo
, Hi
);
6707 if not (Compile_Time_Known_Value
(Lo
)
6709 Compile_Time_Known_Value
(Hi
))
6711 goto No_Implicit_Packing
;
6714 Dim
:= Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1;
6716 if Dim
> Uint_0
then
6717 Num_Elmts
:= Num_Elmts
* Dim
;
6719 Num_Elmts
:= Uint_0
;
6725 -- What we are looking for here is the situation where
6726 -- the RM_Size given would be exactly right if there was
6727 -- a pragma Pack, resulting in the component size being
6728 -- the RM_Size of the component type.
6730 if RM_Size
(E
) = Num_Elmts
* Rsiz
then
6732 -- For implicit packing mode, just set the component
6733 -- size and Freeze_Array_Type will do the rest.
6735 if Implicit_Packing
then
6736 Set_Component_Size
(Btyp
, Rsiz
);
6738 -- Otherwise give an error message, except that if the
6739 -- specified Size is zero, there is no need for pragma
6740 -- Pack. Note that size zero is not considered
6743 elsif RM_Size
(E
) /= Uint_0
then
6745 ("size given for& too small", SZ
, E
);
6746 Error_Msg_N
-- CODEFIX
6747 ("\use explicit pragma Pack or use pragma "
6748 & "Implicit_Packing", SZ
);
6755 <<No_Implicit_Packing
>>
6757 -- If ancestor subtype present, freeze that first. Note that this
6758 -- will also get the base type frozen. Need RM reference ???
6760 Atype
:= Ancestor_Subtype
(E
);
6762 if Present
(Atype
) then
6763 Freeze_And_Append
(Atype
, N
, Result
);
6765 -- No ancestor subtype present
6768 -- See if we have a nearest ancestor that has a predicate.
6769 -- That catches the case of derived type with a predicate.
6770 -- Need RM reference here ???
6772 Atype
:= Nearest_Ancestor
(E
);
6774 if Present
(Atype
) and then Has_Predicates
(Atype
) then
6775 Freeze_And_Append
(Atype
, N
, Result
);
6778 -- Freeze base type before freezing the entity (RM 13.14(15))
6780 if E
/= Base_Type
(E
) then
6781 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
6785 -- A subtype inherits all the type-related representation aspects
6786 -- from its parents (RM 13.1(8)).
6788 if May_Inherit_Delayed_Rep_Aspects
(E
) then
6789 Inherit_Delayed_Rep_Aspects
(E
);
6792 Inherit_Aspects_At_Freeze_Point
(E
);
6794 -- For a derived type, freeze its parent type first (RM 13.14(15))
6796 elsif Is_Derived_Type
(E
) then
6797 Freeze_And_Append
(Etype
(E
), N
, Result
);
6799 -- A derived type inherits each type-related representation aspect
6800 -- of its parent type that was directly specified before the
6801 -- declaration of the derived type (RM 13.1(15)).
6803 if May_Inherit_Delayed_Rep_Aspects
(E
) then
6804 Inherit_Delayed_Rep_Aspects
(E
);
6807 Inherit_Aspects_At_Freeze_Point
(E
);
6810 -- Case of array type
6812 if Is_Array_Type
(E
) then
6813 Freeze_Array_Type
(E
);
6816 -- Check for incompatible size and alignment for array/record type
6818 if Warn_On_Size_Alignment
6819 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
6820 and then Has_Size_Clause
(E
)
6821 and then Has_Alignment_Clause
(E
)
6823 -- If explicit Object_Size clause given assume that the programmer
6824 -- knows what he is doing, and expects the compiler behavior.
6826 and then not Has_Object_Size_Clause
(E
)
6828 -- It does not really make sense to warn for the minimum alignment
6829 -- since the programmer could not get rid of the warning.
6831 and then Alignment
(E
) > 1
6833 -- Check for size not a multiple of alignment
6835 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
6838 SC
: constant Node_Id
:= Size_Clause
(E
);
6839 AC
: constant Node_Id
:= Alignment_Clause
(E
);
6841 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
6844 if Present
(SC
) and then Present
(AC
) then
6848 if Sloc
(SC
) > Sloc
(AC
) then
6851 ("?.z?size is not a multiple of alignment for &",
6853 Error_Msg_Sloc
:= Sloc
(AC
);
6854 Error_Msg_Uint_1
:= Alignment
(E
);
6855 Error_Msg_N
("\?.z?alignment of ^ specified #", Loc
);
6860 ("?.z?size is not a multiple of alignment for &",
6862 Error_Msg_Sloc
:= Sloc
(SC
);
6863 Error_Msg_Uint_1
:= RM_Size
(E
);
6864 Error_Msg_N
("\?.z?size of ^ specified #", Loc
);
6867 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
6868 Error_Msg_N
("\?.z?Object_Size will be increased to ^", Loc
);
6873 -- For a class-wide type, the corresponding specific type is
6874 -- frozen as well (RM 13.14(15))
6876 if Is_Class_Wide_Type
(E
) then
6877 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
6879 -- If the base type of the class-wide type is still incomplete,
6880 -- the class-wide remains unfrozen as well. This is legal when
6881 -- E is the formal of a primitive operation of some other type
6882 -- which is being frozen.
6884 if not Is_Frozen
(Root_Type
(E
)) then
6885 Set_Is_Frozen
(E
, False);
6889 -- The equivalent type associated with a class-wide subtype needs
6890 -- to be frozen to ensure that its layout is done.
6892 if Ekind
(E
) = E_Class_Wide_Subtype
6893 and then Present
(Equivalent_Type
(E
))
6895 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
6898 -- Generate an itype reference for a library-level class-wide type
6899 -- at the freeze point. Otherwise the first explicit reference to
6900 -- the type may appear in an inner scope which will be rejected by
6904 and then Is_Compilation_Unit
(Scope
(E
))
6907 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
6912 -- From a gigi point of view, a class-wide subtype derives
6913 -- from its record equivalent type. As a result, the itype
6914 -- reference must appear after the freeze node of the
6915 -- equivalent type or gigi will reject the reference.
6917 if Ekind
(E
) = E_Class_Wide_Subtype
6918 and then Present
(Equivalent_Type
(E
))
6920 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
6922 Add_To_Result
(Ref
);
6927 -- For a record type or record subtype, freeze all component types
6928 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
6929 -- using Is_Record_Type, because we don't want to attempt the freeze
6930 -- for the case of a private type with record extension (we will do
6931 -- that later when the full type is frozen).
6933 elsif Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
6934 if not In_Generic_Scope
(E
) then
6935 Freeze_Record_Type
(E
);
6938 -- Report a warning if a discriminated record base type has a
6939 -- convention with language C or C++ applied to it. This check is
6940 -- done even within generic scopes (but not in instantiations),
6941 -- which is why we don't do it as part of Freeze_Record_Type.
6943 Check_Suspicious_Convention
(E
);
6945 -- For a concurrent type, freeze corresponding record type. This does
6946 -- not correspond to any specific rule in the RM, but the record type
6947 -- is essentially part of the concurrent type. Also freeze all local
6948 -- entities. This includes record types created for entry parameter
6949 -- blocks and whatever local entities may appear in the private part.
6951 elsif Is_Concurrent_Type
(E
) then
6952 if Present
(Corresponding_Record_Type
(E
)) then
6953 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
6956 Comp
:= First_Entity
(E
);
6957 while Present
(Comp
) loop
6958 if Is_Type
(Comp
) then
6959 Freeze_And_Append
(Comp
, N
, Result
);
6961 elsif (Ekind
(Comp
)) /= E_Function
then
6963 -- The guard on the presence of the Etype seems to be needed
6964 -- for some CodePeer (-gnatcC) cases, but not clear why???
6966 if Present
(Etype
(Comp
)) then
6967 if Is_Itype
(Etype
(Comp
))
6968 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
6970 Undelay_Type
(Etype
(Comp
));
6973 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
6980 -- Private types are required to point to the same freeze node as
6981 -- their corresponding full views. The freeze node itself has to
6982 -- point to the partial view of the entity (because from the partial
6983 -- view, we can retrieve the full view, but not the reverse).
6984 -- However, in order to freeze correctly, we need to freeze the full
6985 -- view. If we are freezing at the end of a scope (or within the
6986 -- scope) of the private type, the partial and full views will have
6987 -- been swapped, the full view appears first in the entity chain and
6988 -- the swapping mechanism ensures that the pointers are properly set
6991 -- If we encounter the partial view before the full view (e.g. when
6992 -- freezing from another scope), we freeze the full view, and then
6993 -- set the pointers appropriately since we cannot rely on swapping to
6994 -- fix things up (subtypes in an outer scope might not get swapped).
6996 -- If the full view is itself private, the above requirements apply
6997 -- to the underlying full view instead of the full view. But there is
6998 -- no swapping mechanism for the underlying full view so we need to
6999 -- set the pointers appropriately in both cases.
7001 elsif Is_Incomplete_Or_Private_Type
(E
)
7002 and then not Is_Generic_Type
(E
)
7004 -- The construction of the dispatch table associated with library
7005 -- level tagged types forces freezing of all the primitives of the
7006 -- type, which may cause premature freezing of the partial view.
7010 -- type T is tagged private;
7011 -- type DT is new T with private;
7012 -- procedure Prim (X : in out T; Y : in out DT'Class);
7014 -- type T is tagged null record;
7016 -- type DT is new T with null record;
7019 -- In this case the type will be frozen later by the usual
7020 -- mechanism: an object declaration, an instantiation, or the
7021 -- end of a declarative part.
7023 if Is_Library_Level_Tagged_Type
(E
)
7024 and then No
(Full_View
(E
))
7026 Set_Is_Frozen
(E
, False);
7029 -- Case of full view present
7031 elsif Present
(Full_View
(E
)) then
7033 -- If full view has already been frozen, then no further
7034 -- processing is required
7036 if Is_Frozen
(Full_View
(E
)) then
7037 Set_Has_Delayed_Freeze
(E
, False);
7038 Set_Freeze_Node
(E
, Empty
);
7040 -- Otherwise freeze full view and patch the pointers so that
7041 -- the freeze node will elaborate both views in the back end.
7042 -- However, if full view is itself private, freeze underlying
7043 -- full view instead and patch the pointers so that the freeze
7044 -- node will elaborate the three views in the back end.
7048 Full
: Entity_Id
:= Full_View
(E
);
7051 if Is_Private_Type
(Full
)
7052 and then Present
(Underlying_Full_View
(Full
))
7054 Full
:= Underlying_Full_View
(Full
);
7057 Freeze_And_Append
(Full
, N
, Result
);
7059 if Full
/= Full_View
(E
)
7060 and then Has_Delayed_Freeze
(Full_View
(E
))
7062 F_Node
:= Freeze_Node
(Full
);
7064 if Present
(F_Node
) then
7066 (Fnod
=> F_Node
, Typ
=> Full_View
(E
));
7068 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
7069 Set_Freeze_Node
(Full_View
(E
), Empty
);
7073 if Has_Delayed_Freeze
(E
) then
7074 F_Node
:= Freeze_Node
(Full_View
(E
));
7076 if Present
(F_Node
) then
7077 Inherit_Freeze_Node
(Fnod
=> F_Node
, Typ
=> E
);
7079 -- {Incomplete,Private}_Subtypes with Full_Views
7080 -- constrained by discriminants.
7082 Set_Has_Delayed_Freeze
(E
, False);
7083 Set_Freeze_Node
(E
, Empty
);
7089 Check_Debug_Info_Needed
(E
);
7091 -- AI95-117 requires that the convention of a partial view be
7092 -- the same as the convention of the full view. Note that this
7093 -- is a recognized breach of privacy, but it's essential for
7094 -- logical consistency of representation, and the lack of a
7095 -- rule in RM95 was an oversight.
7097 Set_Convention
(E
, Convention
(Full_View
(E
)));
7099 Set_Size_Known_At_Compile_Time
(E
,
7100 Size_Known_At_Compile_Time
(Full_View
(E
)));
7102 -- Size information is copied from the full view to the
7103 -- incomplete or private view for consistency.
7105 -- We skip this is the full view is not a type. This is very
7106 -- strange of course, and can only happen as a result of
7107 -- certain illegalities, such as a premature attempt to derive
7108 -- from an incomplete type.
7110 if Is_Type
(Full_View
(E
)) then
7111 Set_Size_Info
(E
, Full_View
(E
));
7112 Copy_RM_Size
(To
=> E
, From
=> Full_View
(E
));
7117 -- Case of underlying full view present
7119 elsif Is_Private_Type
(E
)
7120 and then Present
(Underlying_Full_View
(E
))
7122 if not Is_Frozen
(Underlying_Full_View
(E
)) then
7123 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
7126 -- Patch the pointers so that the freeze node will elaborate
7127 -- both views in the back end.
7129 if Has_Delayed_Freeze
(E
) then
7130 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
7132 if Present
(F_Node
) then
7137 Set_Has_Delayed_Freeze
(E
, False);
7138 Set_Freeze_Node
(E
, Empty
);
7142 Check_Debug_Info_Needed
(E
);
7146 -- Case of no full view present. If entity is subtype or derived,
7147 -- it is safe to freeze, correctness depends on the frozen status
7148 -- of parent. Otherwise it is either premature usage, or a Taft
7149 -- amendment type, so diagnosis is at the point of use and the
7150 -- type might be frozen later.
7152 elsif E
/= Base_Type
(E
) then
7154 Btyp
: constant Entity_Id
:= Base_Type
(E
);
7157 -- However, if the base type is itself private and has no
7158 -- (underlying) full view either, wait until the full type
7159 -- declaration is seen and all the full views are created.
7161 if Is_Private_Type
(Btyp
)
7162 and then No
(Full_View
(Btyp
))
7163 and then No
(Underlying_Full_View
(Btyp
))
7164 and then Has_Delayed_Freeze
(Btyp
)
7165 and then No
(Freeze_Node
(Btyp
))
7167 Set_Is_Frozen
(E
, False);
7173 elsif Is_Derived_Type
(E
) then
7177 Set_Is_Frozen
(E
, False);
7182 -- For access subprogram, freeze types of all formals, the return
7183 -- type was already frozen, since it is the Etype of the function.
7184 -- Formal types can be tagged Taft amendment types, but otherwise
7185 -- they cannot be incomplete.
7187 elsif Ekind
(E
) = E_Subprogram_Type
then
7188 Formal
:= First_Formal
(E
);
7189 while Present
(Formal
) loop
7190 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
7191 and then No
(Full_View
(Etype
(Formal
)))
7193 if Is_Tagged_Type
(Etype
(Formal
)) then
7196 -- AI05-151: Incomplete types are allowed in access to
7197 -- subprogram specifications.
7199 elsif Ada_Version
< Ada_2012
then
7201 ("invalid use of incomplete type&", E
, Etype
(Formal
));
7205 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
7206 Next_Formal
(Formal
);
7209 Freeze_Subprogram
(E
);
7211 -- For access to a protected subprogram, freeze the equivalent type
7212 -- (however this is not set if we are not generating code or if this
7213 -- is an anonymous type used just for resolution).
7215 elsif Is_Access_Protected_Subprogram_Type
(E
) then
7216 if Present
(Equivalent_Type
(E
)) then
7217 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
7221 -- Generic types are never seen by the back-end, and are also not
7222 -- processed by the expander (since the expander is turned off for
7223 -- generic processing), so we never need freeze nodes for them.
7225 if Is_Generic_Type
(E
) then
7229 -- Some special processing for non-generic types to complete
7230 -- representation details not known till the freeze point.
7232 if Is_Fixed_Point_Type
(E
) then
7233 Freeze_Fixed_Point_Type
(E
);
7235 elsif Is_Enumeration_Type
(E
) then
7236 Freeze_Enumeration_Type
(E
);
7238 elsif Is_Integer_Type
(E
) then
7239 Adjust_Esize_For_Alignment
(E
);
7241 if Is_Modular_Integer_Type
(E
) then
7242 -- Standard_Address has been built with the assumption that its
7243 -- modulus was System_Address_Size, but this is not a universal
7244 -- property and may need to be corrected.
7246 if Is_RTE
(E
, RE_Address
) then
7247 Set_Modulus
(Standard_Address
, Modulus
(E
));
7249 (High_Bound
(Scalar_Range
(Standard_Address
)),
7252 elsif Warn_On_Suspicious_Modulus_Value
then
7253 Check_Suspicious_Modulus
(E
);
7257 -- The pool applies to named and anonymous access types, but not
7258 -- to subprogram and to internal types generated for 'Access
7261 elsif Is_Access_Object_Type
(E
)
7262 and then Ekind
(E
) /= E_Access_Attribute_Type
7264 -- If a pragma Default_Storage_Pool applies, and this type has no
7265 -- Storage_Pool or Storage_Size clause (which must have occurred
7266 -- before the freezing point), then use the default. This applies
7267 -- only to base types.
7269 -- None of this applies to access to subprograms, for which there
7270 -- are clearly no pools.
7272 if Present
(Default_Pool
)
7273 and then Is_Base_Type
(E
)
7274 and then not Has_Storage_Size_Clause
(E
)
7275 and then No
(Associated_Storage_Pool
(E
))
7277 -- Case of pragma Default_Storage_Pool (null)
7279 if Nkind
(Default_Pool
) = N_Null
then
7280 Set_No_Pool_Assigned
(E
);
7282 -- Case of pragma Default_Storage_Pool (Standard)
7284 elsif Entity
(Default_Pool
) = Standard_Standard
then
7285 Set_Associated_Storage_Pool
(E
, RTE
(RE_Global_Pool_Object
));
7287 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
7290 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
7294 -- Check restriction for standard storage pool
7296 if No
(Associated_Storage_Pool
(E
)) then
7297 Check_Restriction
(No_Standard_Storage_Pools
, E
);
7300 -- Deal with error message for pure access type. This is not an
7301 -- error in Ada 2005 if there is no pool (see AI-366).
7303 if Is_Pure_Unit_Access_Type
(E
)
7304 and then (Ada_Version
< Ada_2005
7305 or else not No_Pool_Assigned
(E
))
7306 and then not Is_Generic_Unit
(Scope
(E
))
7308 Error_Msg_N
("named access type not allowed in pure unit", E
);
7310 if Ada_Version
>= Ada_2005
then
7312 ("\would be legal if Storage_Size of 0 given??", E
);
7314 elsif No_Pool_Assigned
(E
) then
7316 ("\would be legal in Ada 2005??", E
);
7320 ("\would be legal in Ada 2005 if "
7321 & "Storage_Size of 0 given??", E
);
7326 -- Case of composite types
7328 if Is_Composite_Type
(E
) then
7330 -- AI95-117 requires that all new primitives of a tagged type must
7331 -- inherit the convention of the full view of the type. Inherited
7332 -- and overriding operations are defined to inherit the convention
7333 -- of their parent or overridden subprogram (also specified in
7334 -- AI-117), which will have occurred earlier (in Derive_Subprogram
7335 -- and New_Overloaded_Entity). Here we set the convention of
7336 -- primitives that are still convention Ada, which will ensure
7337 -- that any new primitives inherit the type's convention. Class-
7338 -- wide types can have a foreign convention inherited from their
7339 -- specific type, but are excluded from this since they don't have
7340 -- any associated primitives.
7342 if Is_Tagged_Type
(E
)
7343 and then not Is_Class_Wide_Type
(E
)
7344 and then Convention
(E
) /= Convention_Ada
7347 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
7351 Prim
:= First_Elmt
(Prim_List
);
7352 while Present
(Prim
) loop
7353 if Convention
(Node
(Prim
)) = Convention_Ada
then
7354 Set_Convention
(Node
(Prim
), Convention
(E
));
7362 -- If the type is a simple storage pool type, then this is where
7363 -- we attempt to locate and validate its Allocate, Deallocate, and
7364 -- Storage_Size operations (the first is required, and the latter
7365 -- two are optional). We also verify that the full type for a
7366 -- private type is allowed to be a simple storage pool type.
7368 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
7369 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
7371 -- If the type is marked Has_Private_Declaration, then this is
7372 -- a full type for a private type that was specified with the
7373 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
7374 -- pragma is allowed for the full type (for example, it can't
7375 -- be an array type, or a nonlimited record type).
7377 if Has_Private_Declaration
(E
) then
7378 if (not Is_Record_Type
(E
)
7379 or else not Is_Inherently_Limited_Type
(E
))
7380 and then not Is_Private_Type
(E
)
7382 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
7384 ("pragma% can only apply to full type that is an " &
7385 "explicitly limited type", E
);
7389 Validate_Simple_Pool_Ops
: declare
7390 Pool_Type
: Entity_Id
renames E
;
7391 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
7392 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
7394 procedure Validate_Simple_Pool_Op_Formal
7395 (Pool_Op
: Entity_Id
;
7396 Pool_Op_Formal
: in out Entity_Id
;
7397 Expected_Mode
: Formal_Kind
;
7398 Expected_Type
: Entity_Id
;
7399 Formal_Name
: String;
7400 OK_Formal
: in out Boolean);
7401 -- Validate one formal Pool_Op_Formal of the candidate pool
7402 -- operation Pool_Op. The formal must be of Expected_Type
7403 -- and have mode Expected_Mode. OK_Formal will be set to
7404 -- False if the formal doesn't match. If OK_Formal is False
7405 -- on entry, then the formal will effectively be ignored
7406 -- (because validation of the pool op has already failed).
7407 -- Upon return, Pool_Op_Formal will be updated to the next
7410 procedure Validate_Simple_Pool_Operation
7411 (Op_Name
: Name_Id
);
7412 -- Search for and validate a simple pool operation with the
7413 -- name Op_Name. If the name is Allocate, then there must be
7414 -- exactly one such primitive operation for the simple pool
7415 -- type. If the name is Deallocate or Storage_Size, then
7416 -- there can be at most one such primitive operation. The
7417 -- profile of the located primitive must conform to what
7418 -- is expected for each operation.
7420 ------------------------------------
7421 -- Validate_Simple_Pool_Op_Formal --
7422 ------------------------------------
7424 procedure Validate_Simple_Pool_Op_Formal
7425 (Pool_Op
: Entity_Id
;
7426 Pool_Op_Formal
: in out Entity_Id
;
7427 Expected_Mode
: Formal_Kind
;
7428 Expected_Type
: Entity_Id
;
7429 Formal_Name
: String;
7430 OK_Formal
: in out Boolean)
7433 -- If OK_Formal is False on entry, then simply ignore
7434 -- the formal, because an earlier formal has already
7437 if not OK_Formal
then
7440 -- If no formal is passed in, then issue an error for a
7443 elsif No
(Pool_Op_Formal
) then
7445 ("simple storage pool op missing formal " &
7446 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
7452 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
7454 -- If the pool type was expected for this formal, then
7455 -- this will not be considered a candidate operation
7456 -- for the simple pool, so we unset OK_Formal so that
7457 -- the op and any later formals will be ignored.
7459 if Expected_Type
= Pool_Type
then
7466 ("wrong type for formal " & Formal_Name
&
7467 " of simple storage pool op; expected type&",
7468 Pool_Op_Formal
, Expected_Type
);
7472 -- Issue error if formal's mode is not the expected one
7474 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
7476 ("wrong mode for formal of simple storage pool op",
7480 -- Advance to the next formal
7482 Next_Formal
(Pool_Op_Formal
);
7483 end Validate_Simple_Pool_Op_Formal
;
7485 ------------------------------------
7486 -- Validate_Simple_Pool_Operation --
7487 ------------------------------------
7489 procedure Validate_Simple_Pool_Operation
7493 Found_Op
: Entity_Id
:= Empty
;
7499 (Op_Name
in Name_Allocate
7501 | Name_Storage_Size
);
7503 Error_Msg_Name_1
:= Op_Name
;
7505 -- For each homonym declared immediately in the scope
7506 -- of the simple storage pool type, determine whether
7507 -- the homonym is an operation of the pool type, and,
7508 -- if so, check that its profile is as expected for
7509 -- a simple pool operation of that name.
7511 Op
:= Get_Name_Entity_Id
(Op_Name
);
7512 while Present
(Op
) loop
7513 if Ekind
(Op
) in E_Function | E_Procedure
7514 and then Scope
(Op
) = Current_Scope
7516 Formal
:= First_Entity
(Op
);
7520 -- The first parameter must be of the pool type
7521 -- in order for the operation to qualify.
7523 if Op_Name
= Name_Storage_Size
then
7524 Validate_Simple_Pool_Op_Formal
7525 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
7528 Validate_Simple_Pool_Op_Formal
7529 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
7533 -- If another operation with this name has already
7534 -- been located for the type, then flag an error,
7535 -- since we only allow the type to have a single
7538 if Present
(Found_Op
) and then Is_OK
then
7540 ("only one % operation allowed for " &
7541 "simple storage pool type&", Op
, Pool_Type
);
7544 -- In the case of Allocate and Deallocate, a formal
7545 -- of type System.Address is required.
7547 if Op_Name
= Name_Allocate
then
7548 Validate_Simple_Pool_Op_Formal
7549 (Op
, Formal
, E_Out_Parameter
,
7550 Address_Type
, "Storage_Address", Is_OK
);
7552 elsif Op_Name
= Name_Deallocate
then
7553 Validate_Simple_Pool_Op_Formal
7554 (Op
, Formal
, E_In_Parameter
,
7555 Address_Type
, "Storage_Address", Is_OK
);
7558 -- In the case of Allocate and Deallocate, formals
7559 -- of type Storage_Count are required as the third
7560 -- and fourth parameters.
7562 if Op_Name
/= Name_Storage_Size
then
7563 Validate_Simple_Pool_Op_Formal
7564 (Op
, Formal
, E_In_Parameter
,
7565 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
7566 Validate_Simple_Pool_Op_Formal
7567 (Op
, Formal
, E_In_Parameter
,
7568 Stg_Cnt_Type
, "Alignment", Is_OK
);
7571 -- If no mismatched formals have been found (Is_OK)
7572 -- and no excess formals are present, then this
7573 -- operation has been validated, so record it.
7575 if No
(Formal
) and then Is_OK
then
7583 -- There must be a valid Allocate operation for the type,
7584 -- so issue an error if none was found.
7586 if Op_Name
= Name_Allocate
7587 and then No
(Found_Op
)
7589 Error_Msg_N
("missing % operation for simple " &
7590 "storage pool type", Pool_Type
);
7592 elsif Present
(Found_Op
) then
7594 -- Simple pool operations can't be abstract
7596 if Is_Abstract_Subprogram
(Found_Op
) then
7598 ("simple storage pool operation must not be " &
7599 "abstract", Found_Op
);
7602 -- The Storage_Size operation must be a function with
7603 -- Storage_Count as its result type.
7605 if Op_Name
= Name_Storage_Size
then
7606 if Ekind
(Found_Op
) = E_Procedure
then
7608 ("% operation must be a function", Found_Op
);
7610 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
7612 ("wrong result type for%, expected type&",
7613 Found_Op
, Stg_Cnt_Type
);
7616 -- Allocate and Deallocate must be procedures
7618 elsif Ekind
(Found_Op
) = E_Function
then
7620 ("% operation must be a procedure", Found_Op
);
7623 end Validate_Simple_Pool_Operation
;
7625 -- Start of processing for Validate_Simple_Pool_Ops
7628 Validate_Simple_Pool_Operation
(Name_Allocate
);
7629 Validate_Simple_Pool_Operation
(Name_Deallocate
);
7630 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
7631 end Validate_Simple_Pool_Ops
;
7635 -- Now that all types from which E may depend are frozen, see if
7636 -- strict alignment is required, a component clause on a record
7637 -- is correct, the size is known at compile time and if it must
7638 -- be unsigned, in that order.
7640 if Base_Type
(E
) = E
then
7641 Check_Strict_Alignment
(E
);
7644 if Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
7646 RC
: constant Node_Id
:= Get_Record_Representation_Clause
(E
);
7648 if Present
(RC
) then
7649 Check_Record_Representation_Clause
(RC
);
7654 Check_Compile_Time_Size
(E
);
7656 Check_Unsigned_Type
(E
);
7658 -- Do not allow a size clause for a type which does not have a size
7659 -- that is known at compile time
7661 if (Has_Size_Clause
(E
) or else Has_Object_Size_Clause
(E
))
7662 and then not Size_Known_At_Compile_Time
(E
)
7664 -- Suppress this message if errors posted on E, even if we are
7665 -- in all errors mode, since this is often a junk message
7667 if not Error_Posted
(E
) then
7669 ("size clause not allowed for variable length type",
7674 -- Now we set/verify the representation information, in particular
7675 -- the size and alignment values. This processing is not required for
7676 -- generic types, since generic types do not play any part in code
7677 -- generation, and so the size and alignment values for such types
7678 -- are irrelevant. Ditto for types declared within a generic unit,
7679 -- which may have components that depend on generic parameters, and
7680 -- that will be recreated in an instance.
7682 if Inside_A_Generic
then
7685 -- Otherwise we call the layout procedure
7691 -- If this is an access to subprogram whose designated type is itself
7692 -- a subprogram type, the return type of this anonymous subprogram
7693 -- type must be decorated as well.
7695 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
7696 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
7698 Layout_Type
(Etype
(Designated_Type
(E
)));
7701 -- If the type has a Defaut_Value/Default_Component_Value aspect,
7702 -- this is where we analyze the expression (after the type is frozen,
7703 -- since in the case of Default_Value, we are analyzing with the
7704 -- type itself, and we treat Default_Component_Value similarly for
7705 -- the sake of uniformity).
7707 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
7714 if Is_Scalar_Type
(E
) then
7715 Nam
:= Name_Default_Value
;
7717 Exp
:= Default_Aspect_Value
(Typ
);
7719 Nam
:= Name_Default_Component_Value
;
7720 Typ
:= Component_Type
(E
);
7721 Exp
:= Default_Aspect_Component_Value
(E
);
7724 Analyze_And_Resolve
(Exp
, Typ
);
7726 if Etype
(Exp
) /= Any_Type
then
7727 if not Is_OK_Static_Expression
(Exp
) then
7728 Error_Msg_Name_1
:= Nam
;
7729 Flag_Non_Static_Expr
7730 ("aspect% requires static expression", Exp
);
7736 -- Verify at this point that No_Controlled_Parts and No_Task_Parts,
7737 -- when specified on the current type or one of its ancestors, has
7738 -- not been overridden and that no violation of the aspect has
7741 -- It is important that we perform the checks here after the type has
7742 -- been processed because if said type depended on a private type it
7743 -- will not have been marked controlled or having tasks.
7745 Check_No_Parts_Violations
(E
, Aspect_No_Controlled_Parts
);
7746 Check_No_Parts_Violations
(E
, Aspect_No_Task_Parts
);
7748 -- End of freeze processing for type entities
7751 -- Here is where we logically freeze the current entity. If it has a
7752 -- freeze node, then this is the point at which the freeze node is
7753 -- linked into the result list.
7755 if Has_Delayed_Freeze
(E
) then
7757 -- If a freeze node is already allocated, use it, otherwise allocate
7758 -- a new one. The preallocation happens in the case of anonymous base
7759 -- types, where we preallocate so that we can set First_Subtype_Link.
7760 -- Note that we reset the Sloc to the current freeze location.
7762 if Present
(Freeze_Node
(E
)) then
7763 F_Node
:= Freeze_Node
(E
);
7764 Set_Sloc
(F_Node
, Loc
);
7767 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
7768 Set_Freeze_Node
(E
, F_Node
);
7769 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
7770 Set_TSS_Elist
(F_Node
, No_Elist
);
7771 Set_Actions
(F_Node
, No_List
);
7774 Set_Entity
(F_Node
, E
);
7775 Add_To_Result
(F_Node
);
7777 -- A final pass over record types with discriminants. If the type
7778 -- has an incomplete declaration, there may be constrained access
7779 -- subtypes declared elsewhere, which do not depend on the discrimi-
7780 -- nants of the type, and which are used as component types (i.e.
7781 -- the full view is a recursive type). The designated types of these
7782 -- subtypes can only be elaborated after the type itself, and they
7783 -- need an itype reference.
7785 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
7792 Comp
:= First_Component
(E
);
7793 while Present
(Comp
) loop
7794 Typ
:= Etype
(Comp
);
7796 if Is_Access_Type
(Typ
)
7797 and then Scope
(Typ
) /= E
7798 and then Base_Type
(Designated_Type
(Typ
)) = E
7799 and then Is_Itype
(Designated_Type
(Typ
))
7801 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
7802 Set_Itype
(IR
, Designated_Type
(Typ
));
7803 Append
(IR
, Result
);
7806 Next_Component
(Comp
);
7812 -- When a type is frozen, the first subtype of the type is frozen as
7813 -- well (RM 13.14(15)). This has to be done after freezing the type,
7814 -- since obviously the first subtype depends on its own base type.
7817 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
7819 -- If we just froze a tagged non-class-wide record, then freeze the
7820 -- corresponding class-wide type. This must be done after the tagged
7821 -- type itself is frozen, because the class-wide type refers to the
7822 -- tagged type which generates the class.
7824 -- For a tagged type, freeze explicitly those primitive operations
7825 -- that are expression functions, which otherwise have no clear
7826 -- freeze point: these have to be frozen before the dispatch table
7827 -- for the type is built, and before any explicit call to the
7828 -- primitive, which would otherwise be the freeze point for it.
7830 if Is_Tagged_Type
(E
)
7831 and then not Is_Class_Wide_Type
(E
)
7832 and then Present
(Class_Wide_Type
(E
))
7834 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
7837 Ops
: constant Elist_Id
:= Primitive_Operations
(E
);
7843 if Ops
/= No_Elist
then
7844 Elmt
:= First_Elmt
(Ops
);
7845 while Present
(Elmt
) loop
7846 Subp
:= Node
(Elmt
);
7847 if Is_Expression_Function
(Subp
) then
7848 Freeze_And_Append
(Subp
, N
, Result
);
7858 Check_Debug_Info_Needed
(E
);
7860 -- If subprogram has address clause then reset Is_Public flag, since we
7861 -- do not want the backend to generate external references.
7863 if Is_Subprogram
(E
)
7864 and then Present
(Address_Clause
(E
))
7865 and then not Is_Library_Level_Entity
(E
)
7867 Set_Is_Public
(E
, False);
7870 -- The Ghost mode of the enclosing context is ignored, while the
7871 -- entity being frozen is living. Insert the freezing action prior
7872 -- to the start of the enclosing ignored Ghost region. As a result
7873 -- the freezeing action will be preserved when the ignored Ghost
7874 -- context is eliminated. The insertion must take place even when
7875 -- the context is a spec expression, otherwise "Handling of Default
7876 -- and Per-Object Expressions" will suppress the insertion, and the
7877 -- freeze node will be dropped on the floor.
7879 if Saved_GM
= Ignore
7880 and then Ghost_Mode
/= Ignore
7881 and then Present
(Ignored_Ghost_Region
)
7884 (Assoc_Node
=> Ignored_Ghost_Region
,
7885 Ins_Actions
=> Result
,
7886 Spec_Expr_OK
=> True);
7892 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
7897 -----------------------------
7898 -- Freeze_Enumeration_Type --
7899 -----------------------------
7901 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
7903 -- By default, if no size clause is present, an enumeration type with
7904 -- Convention C is assumed to interface to a C enum and has integer
7905 -- size, except for a boolean type because it is assumed to interface
7906 -- to _Bool introduced in C99. This applies to types. For subtypes,
7907 -- verify that its base type has no size clause either. Treat other
7908 -- foreign conventions in the same way, and also make sure alignment
7911 if Has_Foreign_Convention
(Typ
)
7912 and then not Is_Boolean_Type
(Typ
)
7913 and then not Has_Size_Clause
(Typ
)
7914 and then not Has_Size_Clause
(Base_Type
(Typ
))
7915 and then Esize
(Typ
) < Standard_Integer_Size
7917 -- Don't do this if Short_Enums on target
7919 and then not Target_Short_Enums
7921 Set_Esize
(Typ
, UI_From_Int
(Standard_Integer_Size
));
7922 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
7924 -- Normal Ada case or size clause present or not Long_C_Enums on target
7927 -- If the enumeration type interfaces to C, and it has a size clause
7928 -- that is smaller than the size of int, it warrants a warning. The
7929 -- user may intend the C type to be a boolean or a char, so this is
7930 -- not by itself an error that the Ada compiler can detect, but it
7931 -- is worth a heads-up. For Boolean and Character types we
7932 -- assume that the programmer has the proper C type in mind.
7933 -- For explicit sizes larger than int, assume the user knows what
7934 -- he is doing and that the code is intentional.
7936 if Convention
(Typ
) = Convention_C
7937 and then Has_Size_Clause
(Typ
)
7938 and then Esize
(Typ
) < Standard_Integer_Size
7939 and then not Is_Boolean_Type
(Typ
)
7940 and then not Is_Character_Type
(Typ
)
7942 -- Don't do this if Short_Enums on target
7944 and then not Target_Short_Enums
7947 ("??the size of enums in C is implementation-defined",
7950 ("\??check that the C counterpart has size of " &
7951 UI_Image
(Esize
(Typ
)),
7955 Adjust_Esize_For_Alignment
(Typ
);
7958 -- Reject a very large size on a type with a non-standard representation
7959 -- because Expand_Freeze_Enumeration_Type cannot deal with it.
7961 if Has_Non_Standard_Rep
(Typ
)
7962 and then Known_Esize
(Typ
)
7963 and then Esize
(Typ
) > System_Max_Integer_Size
7966 ("enumeration type with representation clause too large", Typ
);
7967 Error_Msg_Uint_1
:= UI_From_Int
(System_Max_Integer_Size
);
7969 ("\the size of such a type cannot exceed ^ bits", Typ
);
7971 end Freeze_Enumeration_Type
;
7973 -----------------------
7974 -- Freeze_Expression --
7975 -----------------------
7977 procedure Freeze_Expression
(N
: Node_Id
) is
7979 function Declared_In_Expanded_Body
7982 Nam
: Entity_Id
) return Boolean;
7983 -- Given the N_Handled_Sequence_Of_Statements node of an expander
7984 -- generated subprogram body, determines if the frozen entity is
7985 -- declared inside this body. This is recognized locating the
7986 -- enclosing subprogram of the entity Name or its Type and
7987 -- checking if it is this subprogram body.
7989 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
7990 -- If the expression is an array aggregate, the type of the component
7991 -- expressions is also frozen. If the component type is an access type
7992 -- and the expressions include allocators, the designed type is frozen
7995 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
7996 -- Given an N_Handled_Sequence_Of_Statements node, determines whether it
7997 -- is the statement sequence of an expander-generated subprogram: body
7998 -- created for an expression function, for a predicate function, an init
7999 -- proc, a stream subprogram, or a renaming as body. If so, this is not
8000 -- a freezing context and the entity will be frozen at a later point.
8002 function Has_Decl_In_List
8005 L
: List_Id
) return Boolean;
8006 -- Determines whether an entity E referenced in node N is declared in
8009 -------------------------------
8010 -- Declared_In_Expanded_Body --
8011 -------------------------------
8013 function Declared_In_Expanded_Body
8016 Nam
: Entity_Id
) return Boolean
8018 pragma Assert
(In_Expanded_Body
(N
));
8020 Subp_Body
: constant Node_Id
:= Parent
(N
);
8021 Subp_Id
: Entity_Id
;
8025 if Acts_As_Spec
(Subp_Body
) then
8026 Subp_Id
:= Unique_Defining_Entity
(Specification
(Subp_Body
));
8028 Subp_Id
:= Corresponding_Spec
(Subp_Body
);
8031 if Present
(Typ
) then
8032 Scop
:= Scope
(Typ
);
8033 elsif Present
(Nam
) then
8034 Scop
:= Scope
(Nam
);
8036 Scop
:= Standard_Standard
;
8039 while Scop
/= Standard_Standard
8040 and then not Is_Subprogram
(Scop
)
8042 Scop
:= Scope
(Scop
);
8045 return Scop
= Subp_Id
;
8046 end Declared_In_Expanded_Body
;
8048 -----------------------------------------
8049 -- Find_Aggregate_Component_Desig_Type --
8050 -----------------------------------------
8052 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
8057 if Present
(Expressions
(N
)) then
8058 Exp
:= First
(Expressions
(N
));
8059 while Present
(Exp
) loop
8060 if Nkind
(Exp
) = N_Allocator
then
8061 return Designated_Type
(Component_Type
(Etype
(N
)));
8068 if Present
(Component_Associations
(N
)) then
8069 Assoc
:= First
(Component_Associations
(N
));
8070 while Present
(Assoc
) loop
8071 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
8072 return Designated_Type
(Component_Type
(Etype
(N
)));
8080 end Find_Aggregate_Component_Desig_Type
;
8082 ----------------------
8083 -- In_Expanded_Body --
8084 ----------------------
8086 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
8087 P
: constant Node_Id
:= Parent
(N
);
8091 if Nkind
(P
) /= N_Subprogram_Body
then
8094 -- Treat the generated body of an expression function like other
8095 -- bodies generated during expansion (e.g. stream subprograms) so
8096 -- that those bodies are not treated as freezing points.
8098 elsif Was_Expression_Function
(P
) then
8099 pragma Assert
(not Comes_From_Source
(P
));
8102 -- This is the body of a generated predicate function
8104 elsif Present
(Corresponding_Spec
(P
))
8105 and then Is_Predicate_Function
(Corresponding_Spec
(P
))
8110 Id
:= Defining_Unit_Name
(Specification
(P
));
8112 -- The following are expander-created bodies, or bodies that
8113 -- are not freeze points.
8115 if Nkind
(Id
) = N_Defining_Identifier
8116 and then (Is_Init_Proc
(Id
)
8117 or else Is_TSS
(Id
, TSS_Stream_Input
)
8118 or else Is_TSS
(Id
, TSS_Stream_Output
)
8119 or else Is_TSS
(Id
, TSS_Stream_Read
)
8120 or else Is_TSS
(Id
, TSS_Stream_Write
)
8121 or else Is_TSS
(Id
, TSS_Put_Image
)
8122 or else Nkind
(Original_Node
(P
)) =
8123 N_Subprogram_Renaming_Declaration
)
8130 end In_Expanded_Body
;
8132 ----------------------
8133 -- Has_Decl_In_List --
8134 ----------------------
8136 function Has_Decl_In_List
8139 L
: List_Id
) return Boolean
8141 Decl_Node
: Node_Id
;
8144 -- If E is an itype, pretend that it is declared in N except for a
8145 -- class-wide subtype with an equivalent type, because this latter
8146 -- type comes with a bona-fide declaration node.
8148 if Is_Itype
(E
) then
8149 if Ekind
(E
) = E_Class_Wide_Subtype
8150 and then Present
(Equivalent_Type
(E
))
8152 Decl_Node
:= Declaration_Node
(Equivalent_Type
(E
));
8158 Decl_Node
:= Declaration_Node
(E
);
8161 return Is_List_Member
(Decl_Node
)
8162 and then List_Containing
(Decl_Node
) = L
;
8163 end Has_Decl_In_List
;
8167 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
8169 Desig_Typ
: Entity_Id
;
8175 Allocator_Typ
: Entity_Id
:= Empty
;
8177 Freeze_Outside_Subp
: Entity_Id
:= Empty
;
8178 -- This entity is set if we are inside a subprogram body and the frozen
8179 -- entity is defined in the enclosing scope of this subprogram. In such
8180 -- case we must skip the subprogram body when climbing the parents chain
8181 -- to locate the correct placement for the freezing node.
8183 -- Start of processing for Freeze_Expression
8186 -- Immediate return if freezing is inhibited. This flag is set by the
8187 -- analyzer to stop freezing on generated expressions that would cause
8188 -- freezing if they were in the source program, but which are not
8189 -- supposed to freeze, since they are created.
8191 if Must_Not_Freeze
(N
) then
8195 -- If expression is non-static, then it does not freeze in a default
8196 -- expression, see section "Handling of Default Expressions" in the
8197 -- spec of package Sem for further details. Note that we have to make
8198 -- sure that we actually have a real expression (if we have a subtype
8199 -- indication, we can't test Is_OK_Static_Expression). However, we
8200 -- exclude the case of the prefix of an attribute of a static scalar
8201 -- subtype from this early return, because static subtype attributes
8202 -- should always cause freezing, even in default expressions, but
8203 -- the attribute may not have been marked as static yet (because in
8204 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
8205 -- Freeze_Expression on the prefix).
8208 and then Nkind
(N
) in N_Subexpr
8209 and then not Is_OK_Static_Expression
(N
)
8210 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
8211 or else not (Is_Entity_Name
(N
)
8212 and then Is_Type
(Entity
(N
))
8213 and then Is_OK_Static_Subtype
(Entity
(N
))))
8218 -- Freeze type of expression if not frozen already
8222 if Nkind
(N
) in N_Has_Etype
and then Present
(Etype
(N
)) then
8223 if not Is_Frozen
(Etype
(N
)) then
8226 -- Base type may be an derived numeric type that is frozen at the
8227 -- point of declaration, but first_subtype is still unfrozen.
8229 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
8230 Typ
:= First_Subtype
(Etype
(N
));
8234 -- For entity name, freeze entity if not frozen already. A special
8235 -- exception occurs for an identifier that did not come from source.
8236 -- We don't let such identifiers freeze a non-internal entity, i.e.
8237 -- an entity that did come from source, since such an identifier was
8238 -- generated by the expander, and cannot have any semantic effect on
8239 -- the freezing semantics. For example, this stops the parameter of
8240 -- an initialization procedure from freezing the variable.
8242 if Is_Entity_Name
(N
)
8243 and then Present
(Entity
(N
))
8244 and then not Is_Frozen
(Entity
(N
))
8245 and then (Nkind
(N
) /= N_Identifier
8246 or else Comes_From_Source
(N
)
8247 or else not Comes_From_Source
(Entity
(N
)))
8251 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
8252 Check_Expression_Function
(N
, Nam
);
8259 -- For an allocator freeze designated type if not frozen already
8261 -- For an aggregate whose component type is an access type, freeze the
8262 -- designated type now, so that its freeze does not appear within the
8263 -- loop that might be created in the expansion of the aggregate. If the
8264 -- designated type is a private type without full view, the expression
8265 -- cannot contain an allocator, so the type is not frozen.
8267 -- For a function, we freeze the entity when the subprogram declaration
8268 -- is frozen, but a function call may appear in an initialization proc.
8269 -- before the declaration is frozen. We need to generate the extra
8270 -- formals, if any, to ensure that the expansion of the call includes
8271 -- the proper actuals. This only applies to Ada subprograms, not to
8278 Desig_Typ
:= Designated_Type
(Etype
(N
));
8280 if Nkind
(Expression
(N
)) = N_Qualified_Expression
then
8281 Allocator_Typ
:= Entity
(Subtype_Mark
(Expression
(N
)));
8285 if Is_Array_Type
(Etype
(N
))
8286 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
8288 -- Check whether aggregate includes allocators
8290 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
8293 when N_Indexed_Component
8294 | N_Selected_Component
8297 if Is_Access_Type
(Etype
(Prefix
(N
))) then
8298 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
8301 when N_Identifier
=>
8303 and then Ekind
(Nam
) = E_Function
8304 and then Nkind
(Parent
(N
)) = N_Function_Call
8305 and then not Has_Foreign_Convention
(Nam
)
8307 Create_Extra_Formals
(Nam
);
8314 if Desig_Typ
/= Empty
8315 and then (Is_Frozen
(Desig_Typ
)
8316 or else not Is_Fully_Defined
(Desig_Typ
))
8321 -- All done if nothing needs freezing
8325 and then No
(Desig_Typ
)
8326 and then No
(Allocator_Typ
)
8331 -- Check if we are inside a subprogram body and the frozen entity is
8332 -- defined in the enclosing scope of this subprogram. In such case we
8333 -- must skip the subprogram when climbing the parents chain to locate
8334 -- the correct placement for the freezing node.
8336 -- This is not needed for default expressions and other spec expressions
8337 -- in generic units since the Move_Freeze_Nodes mechanism (sem_ch12.adb)
8338 -- takes care of placing them at the proper place, after the generic
8342 and then Scope
(Nam
) /= Current_Scope
8343 and then not (In_Spec_Exp
and then Inside_A_Generic
)
8346 S
: Entity_Id
:= Current_Scope
;
8350 and then In_Same_Source_Unit
(Nam
, S
)
8352 if Scope
(S
) = Scope
(Nam
) then
8353 if Is_Subprogram
(S
) and then Has_Completion
(S
) then
8354 Freeze_Outside_Subp
:= S
;
8365 -- Examine the enclosing context by climbing the parent chain
8367 -- If we identified that we must freeze the entity outside of a given
8368 -- subprogram then we just climb up to that subprogram checking if some
8369 -- enclosing node is marked as Must_Not_Freeze (since in such case we
8370 -- must not freeze yet this entity).
8374 if Present
(Freeze_Outside_Subp
) then
8376 -- Do not freeze the current expression if another expression in
8377 -- the chain of parents must not be frozen.
8379 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8383 Parent_P
:= Parent
(P
);
8385 -- If we don't have a parent, then we are not in a well-formed
8386 -- tree. This is an unusual case, but there are some legitimate
8387 -- situations in which this occurs, notably when the expressions
8388 -- in the range of a type declaration are resolved. We simply
8389 -- ignore the freeze request in this case.
8391 if No
(Parent_P
) then
8395 -- If the parent is a subprogram body, the candidate insertion
8396 -- point is just ahead of it.
8398 if Nkind
(Parent_P
) = N_Subprogram_Body
8399 and then Unique_Defining_Entity
(Parent_P
) =
8409 -- Otherwise the traversal serves two purposes - to detect scenarios
8410 -- where freezeing is not needed and to find the proper insertion point
8411 -- for the freeze nodes. Although somewhat similar to Insert_Actions,
8412 -- this traversal is freezing semantics-sensitive. Inserting freeze
8413 -- nodes blindly in the tree may result in types being frozen too early.
8417 -- Do not freeze the current expression if another expression in
8418 -- the chain of parents must not be frozen.
8420 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8424 Parent_P
:= Parent
(P
);
8426 -- If we don't have a parent, then we are not in a well-formed
8427 -- tree. This is an unusual case, but there are some legitimate
8428 -- situations in which this occurs, notably when the expressions
8429 -- in the range of a type declaration are resolved. We simply
8430 -- ignore the freeze request in this case.
8432 if No
(Parent_P
) then
8436 -- See if we have got to an appropriate point in the tree
8438 case Nkind
(Parent_P
) is
8440 -- A special test for the exception of (RM 13.14(8)) for the
8441 -- case of per-object expressions (RM 3.8(18)) occurring in
8442 -- component definition or a discrete subtype definition. Note
8443 -- that we test for a component declaration which includes both
8444 -- cases we are interested in, and furthermore the tree does
8445 -- not have explicit nodes for either of these two constructs.
8447 when N_Component_Declaration
=>
8449 -- The case we want to test for here is an identifier that
8450 -- is a per-object expression, this is either a discriminant
8451 -- that appears in a context other than the component
8452 -- declaration or it is a reference to the type of the
8453 -- enclosing construct.
8455 -- For either of these cases, we skip the freezing
8457 if not In_Spec_Expression
8458 and then Nkind
(N
) = N_Identifier
8459 and then Present
(Entity
(N
))
8461 -- We recognize the discriminant case by just looking for
8462 -- a reference to a discriminant. It can only be one for
8463 -- the enclosing construct. Skip freezing in this case.
8465 if Ekind
(Entity
(N
)) = E_Discriminant
then
8468 -- For the case of a reference to the enclosing record,
8469 -- (or task or protected type), we look for a type that
8470 -- matches the current scope.
8472 elsif Entity
(N
) = Current_Scope
then
8477 -- If we have an enumeration literal that appears as the choice
8478 -- in the aggregate of an enumeration representation clause,
8479 -- then freezing does not occur (RM 13.14(10)).
8481 when N_Enumeration_Representation_Clause
=>
8483 -- The case we are looking for is an enumeration literal
8485 if Nkind
(N
) in N_Identifier | N_Character_Literal
8486 and then Is_Enumeration_Type
(Etype
(N
))
8488 -- If enumeration literal appears directly as the choice,
8489 -- do not freeze (this is the normal non-overloaded case)
8491 if Nkind
(Parent
(N
)) = N_Component_Association
8492 and then First
(Choices
(Parent
(N
))) = N
8496 -- If enumeration literal appears as the name of function
8497 -- which is the choice, then also do not freeze. This
8498 -- happens in the overloaded literal case, where the
8499 -- enumeration literal is temporarily changed to a
8500 -- function call for overloading analysis purposes.
8502 elsif Nkind
(Parent
(N
)) = N_Function_Call
8503 and then Nkind
(Parent
(Parent
(N
))) =
8504 N_Component_Association
8505 and then First
(Choices
(Parent
(Parent
(N
)))) =
8512 -- Normally if the parent is a handled sequence of statements,
8513 -- then the current node must be a statement, and that is an
8514 -- appropriate place to insert a freeze node.
8516 when N_Handled_Sequence_Of_Statements
=>
8518 -- An exception occurs when the sequence of statements is
8519 -- for an expander generated body that did not do the usual
8520 -- freeze all operation. In this case we usually want to
8521 -- freeze outside this body, not inside it, unless the
8522 -- entity is declared inside this expander generated body.
8524 exit when not In_Expanded_Body
(Parent_P
)
8525 or else Declared_In_Expanded_Body
(Parent_P
, Typ
, Nam
);
8527 -- If parent is a body or a spec or a block, then the current
8528 -- node is a statement or declaration and we can insert the
8529 -- freeze node before it.
8531 when N_Block_Statement
8534 | N_Package_Specification
8541 -- The expander is allowed to define types in any statements
8542 -- list, so any of the following parent nodes also mark a
8543 -- freezing point if the actual node is in a list of
8544 -- statements or declarations.
8546 when N_Abortable_Part
8547 | N_Accept_Alternative
8548 | N_Case_Statement_Alternative
8549 | N_Compilation_Unit_Aux
8550 | N_Conditional_Entry_Call
8551 | N_Delay_Alternative
8553 | N_Entry_Call_Alternative
8554 | N_Exception_Handler
8555 | N_Extended_Return_Statement
8558 | N_Selective_Accept
8559 | N_Triggering_Alternative
8561 if No
(Current_Subprogram
) then
8562 exit when Is_List_Member
(P
);
8564 -- Check exceptional case documented above for an enclosing
8565 -- handled sequence of statements.
8569 Par
: Node_Id
:= Parent
(Parent_P
);
8574 Nkind
(Par
) /= N_Handled_Sequence_Of_Statements
8575 and then Nkind
(Parent
(Par
)) /= N_Subprogram_Body
8577 Par
:= Parent
(Par
);
8580 -- If we don't have a parent, then we are not in a
8581 -- well-formed tree and we ignore the freeze request.
8582 -- See previous comment in the enclosing loop.
8588 exit when not In_Expanded_Body
(Par
)
8589 or else Declared_In_Expanded_Body
(Par
, Typ
, Nam
);
8593 -- The freeze nodes produced by an expression coming from the
8594 -- Actions list of an N_Expression_With_Actions, short-circuit
8595 -- expression or N_Case_Expression_Alternative node must remain
8596 -- within the Actions list if they freeze an entity declared in
8597 -- this list, as inserting the freeze nodes further up the tree
8598 -- may lead to use before declaration issues for the entity.
8600 when N_Case_Expression_Alternative
8601 | N_Expression_With_Actions
8604 exit when (Present
(Nam
)
8606 Has_Decl_In_List
(Nam
, P
, Actions
(Parent_P
)))
8607 or else (Present
(Typ
)
8609 Has_Decl_In_List
(Typ
, P
, Actions
(Parent_P
)));
8611 -- Likewise for an N_If_Expression and its two Actions list
8613 when N_If_Expression
=>
8615 L1
: constant List_Id
:= Then_Actions
(Parent_P
);
8616 L2
: constant List_Id
:= Else_Actions
(Parent_P
);
8619 exit when (Present
(Nam
)
8621 Has_Decl_In_List
(Nam
, P
, L1
))
8622 or else (Present
(Typ
)
8624 Has_Decl_In_List
(Typ
, P
, L1
))
8625 or else (Present
(Nam
)
8627 Has_Decl_In_List
(Nam
, P
, L2
))
8628 or else (Present
(Typ
)
8630 Has_Decl_In_List
(Typ
, P
, L2
));
8633 -- N_Loop_Statement is a special case: a type that appears in
8634 -- the source can never be frozen in a loop (this occurs only
8635 -- because of a loop expanded by the expander), so we keep on
8636 -- going. Otherwise we terminate the search. Same is true of
8637 -- any entity which comes from source (if it has a predefined
8638 -- type, this type does not appear to come from source, but the
8639 -- entity should not be frozen here).
8641 when N_Loop_Statement
=>
8642 exit when not Comes_From_Source
(Etype
(N
))
8643 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
8645 -- For all other cases, keep looking at parents
8651 -- We fall through the case if we did not yet find the proper
8652 -- place in the tree for inserting the freeze node, so climb.
8658 -- If the expression appears in a record or an initialization procedure,
8659 -- the freeze nodes are collected and attached to the current scope, to
8660 -- be inserted and analyzed on exit from the scope, to insure that
8661 -- generated entities appear in the correct scope. If the expression is
8662 -- a default for a discriminant specification, the scope is still void.
8663 -- The expression can also appear in the discriminant part of a private
8664 -- or concurrent type.
8666 -- If the expression appears in a constrained subcomponent of an
8667 -- enclosing record declaration, the freeze nodes must be attached to
8668 -- the outer record type so they can eventually be placed in the
8669 -- enclosing declaration list.
8671 -- The other case requiring this special handling is if we are in a
8672 -- default expression, since in that case we are about to freeze a
8673 -- static type, and the freeze scope needs to be the outer scope, not
8674 -- the scope of the subprogram with the default parameter.
8676 -- For default expressions and other spec expressions in generic units,
8677 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
8678 -- placing them at the proper place, after the generic unit.
8680 if (In_Spec_Exp
and not Inside_A_Generic
)
8681 or else (Is_Type
(Current_Scope
)
8682 and then (not Is_Concurrent_Type
(Current_Scope
)
8683 or else not Has_Completion
(Current_Scope
)))
8684 or else Ekind
(Current_Scope
) = E_Void
8687 Freeze_Nodes
: List_Id
:= No_List
;
8688 Pos
: Int
:= Scope_Stack
.Last
;
8691 if Present
(Desig_Typ
) then
8692 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
8695 if Present
(Typ
) then
8696 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
8699 if Present
(Nam
) then
8700 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
8703 -- The current scope may be that of a constrained component of
8704 -- an enclosing record declaration, or of a loop of an enclosing
8705 -- quantified expression or aggregate with an iterated component
8706 -- in Ada 2022, which is above the current scope in the scope
8707 -- stack. Indeed in the context of a quantified expression or
8708 -- an aggregate with an iterated component, an internal scope is
8709 -- created and pushed above the current scope in order to emulate
8710 -- the loop-like behavior of the construct.
8711 -- If the expression is within a top-level pragma, as for a pre-
8712 -- condition on a library-level subprogram, nothing to do.
8714 if not Is_Compilation_Unit
(Current_Scope
)
8715 and then (Is_Record_Type
(Scope
(Current_Scope
))
8716 or else (Ekind
(Current_Scope
) = E_Loop
8717 and then Is_Internal
(Current_Scope
)))
8722 if Is_Non_Empty_List
(Freeze_Nodes
) then
8724 -- When the current scope is transient, insert the freeze nodes
8725 -- prior to the expression that produced them. Transient scopes
8726 -- may create additional declarations when finalizing objects
8727 -- or managing the secondary stack. Inserting the freeze nodes
8728 -- of those constructs prior to the scope would result in a
8729 -- freeze-before-declaration, therefore the freeze node must
8730 -- remain interleaved with their constructs.
8732 if Scope_Is_Transient
then
8733 Insert_Actions
(N
, Freeze_Nodes
);
8735 elsif No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
8736 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
8739 Append_List
(Freeze_Nodes
,
8740 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
8748 -- Now we have the right place to do the freezing. First, a special
8749 -- adjustment, if we are in spec-expression analysis mode, these freeze
8750 -- actions must not be thrown away (normally all inserted actions are
8751 -- thrown away in this mode. However, the freeze actions are from static
8752 -- expressions and one of the important reasons we are doing this
8753 -- special analysis is to get these freeze actions. Therefore we turn
8754 -- off the In_Spec_Expression mode to propagate these freeze actions.
8755 -- This also means they get properly analyzed and expanded.
8757 In_Spec_Expression
:= False;
8759 -- Freeze the subtype mark before a qualified expression on an
8760 -- allocator as per AARM 13.14(4.a). This is needed in particular to
8761 -- generate predicate functions.
8763 if Present
(Allocator_Typ
) then
8764 Freeze_Before
(P
, Allocator_Typ
);
8767 -- Freeze the designated type of an allocator (RM 13.14(13))
8769 if Present
(Desig_Typ
) then
8770 Freeze_Before
(P
, Desig_Typ
);
8773 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
8774 -- the enumeration representation clause exception in the loop above.
8776 if Present
(Typ
) then
8777 Freeze_Before
(P
, Typ
);
8780 -- Freeze name if one is present (RM 13.14(11))
8782 if Present
(Nam
) then
8783 Freeze_Before
(P
, Nam
);
8786 -- Restore In_Spec_Expression flag
8788 In_Spec_Expression
:= In_Spec_Exp
;
8789 end Freeze_Expression
;
8791 -----------------------
8792 -- Freeze_Expr_Types --
8793 -----------------------
8795 procedure Freeze_Expr_Types
8796 (Def_Id
: Entity_Id
;
8801 function Cloned_Expression
return Node_Id
;
8802 -- Build a duplicate of the expression of the return statement that has
8803 -- no defining entities shared with the original expression.
8805 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
8806 -- Freeze all types referenced in the subtree rooted at Node
8808 -----------------------
8809 -- Cloned_Expression --
8810 -----------------------
8812 function Cloned_Expression
return Node_Id
is
8813 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
8814 -- Tree traversal routine that clones the defining identifier of
8815 -- iterator and loop parameter specification nodes.
8821 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
8824 N_Iterator_Specification | N_Loop_Parameter_Specification
8826 Set_Defining_Identifier
8827 (Node
, New_Copy
(Defining_Identifier
(Node
)));
8833 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
8837 Dup_Expr
: constant Node_Id
:= New_Copy_Tree
(Expr
);
8839 -- Start of processing for Cloned_Expression
8842 -- We must duplicate the expression with semantic information to
8843 -- inherit the decoration of global entities in generic instances.
8844 -- Set the parent of the new node to be the parent of the original
8845 -- to get the proper context, which is needed for complete error
8846 -- reporting and for semantic analysis.
8848 Set_Parent
(Dup_Expr
, Parent
(Expr
));
8850 -- Replace the defining identifier of iterators and loop param
8851 -- specifications by a clone to ensure that the cloned expression
8852 -- and the original expression don't have shared identifiers;
8853 -- otherwise, as part of the preanalysis of the expression, these
8854 -- shared identifiers may be left decorated with itypes which
8855 -- will not be available in the tree passed to the backend.
8857 Clone_Def_Ids
(Dup_Expr
);
8860 end Cloned_Expression
;
8862 ----------------------
8863 -- Freeze_Type_Refs --
8864 ----------------------
8866 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
8867 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
);
8868 -- Check that Typ is fully declared and freeze it if so
8870 ---------------------------
8871 -- Check_And_Freeze_Type --
8872 ---------------------------
8874 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
) is
8876 -- Skip Itypes created by the preanalysis, and itypes whose
8877 -- scope is another type (i.e. component subtypes that depend
8878 -- on a discriminant),
8881 and then (Scope_Within_Or_Same
(Scope
(Typ
), Def_Id
)
8882 or else Is_Type
(Scope
(Typ
)))
8887 -- This provides a better error message than generating primitives
8888 -- whose compilation fails much later. Refine the error message if
8891 Check_Fully_Declared
(Typ
, Node
);
8893 if Error_Posted
(Node
) then
8894 if Has_Private_Component
(Typ
)
8895 and then not Is_Private_Type
(Typ
)
8897 Error_Msg_NE
("\type& has private component", Node
, Typ
);
8901 Freeze_Before
(N
, Typ
);
8903 end Check_And_Freeze_Type
;
8905 -- Start of processing for Freeze_Type_Refs
8908 -- Check that a type referenced by an entity can be frozen
8910 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
8911 -- The entity itself may be a type, as in a membership test
8912 -- or an attribute reference. Freezing its own type would be
8913 -- incomplete if the entity is derived or an extension.
8915 if Is_Type
(Entity
(Node
)) then
8916 Check_And_Freeze_Type
(Entity
(Node
));
8919 Check_And_Freeze_Type
(Etype
(Entity
(Node
)));
8922 -- Check that the enclosing record type can be frozen
8924 if Ekind
(Entity
(Node
)) in E_Component | E_Discriminant
then
8925 Check_And_Freeze_Type
(Scope
(Entity
(Node
)));
8928 -- Freezing an access type does not freeze the designated type, but
8929 -- freezing conversions between access to interfaces requires that
8930 -- the interface types themselves be frozen, so that dispatch table
8931 -- entities are properly created.
8933 -- Unclear whether a more general rule is needed ???
8935 elsif Nkind
(Node
) = N_Type_Conversion
8936 and then Is_Access_Type
(Etype
(Node
))
8937 and then Is_Interface
(Designated_Type
(Etype
(Node
)))
8939 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
8942 -- An implicit dereference freezes the designated type. In the case
8943 -- of a dispatching call whose controlling argument is an access
8944 -- type, the dereference is not made explicit, so we must check for
8945 -- such a call and freeze the designated type.
8947 if Nkind
(Node
) in N_Has_Etype
8948 and then Present
(Etype
(Node
))
8949 and then Is_Access_Type
(Etype
(Node
))
8951 if Nkind
(Parent
(Node
)) = N_Function_Call
8952 and then Node
= Controlling_Argument
(Parent
(Node
))
8954 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
8956 -- An explicit dereference freezes the designated type as well,
8957 -- even though that type is not attached to an entity in the
8960 elsif Nkind
(Parent
(Node
)) = N_Explicit_Dereference
then
8961 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
8964 -- An iterator specification freezes the iterator type, even though
8965 -- that type is not attached to an entity in the construct.
8967 elsif Nkind
(Node
) in N_Has_Etype
8968 and then Nkind
(Parent
(Node
)) = N_Iterator_Specification
8969 and then Node
= Name
(Parent
(Node
))
8972 Iter
: constant Node_Id
:=
8973 Find_Value_Of_Aspect
(Etype
(Node
), Aspect_Default_Iterator
);
8976 if Present
(Iter
) then
8977 Check_And_Freeze_Type
(Etype
(Iter
));
8982 -- No point in posting several errors on the same expression
8984 if Serious_Errors_Detected
> 0 then
8989 end Freeze_Type_Refs
;
8991 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
8995 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Def_Id
);
8996 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Def_Id
);
8997 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
8999 -- Start of processing for Freeze_Expr_Types
9002 -- Preanalyze a duplicate of the expression to have available the
9003 -- minimum decoration needed to locate referenced unfrozen types
9004 -- without adding any decoration to the function expression.
9006 -- This routine is also applied to expressions in the contract for
9007 -- the subprogram. If that happens when expanding the code for
9008 -- pre/postconditions during expansion of the subprogram body, the
9009 -- subprogram is already installed.
9011 if Def_Id
/= Current_Scope
then
9012 Push_Scope
(Def_Id
);
9013 Install_Formals
(Def_Id
);
9015 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
9018 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
9021 -- Restore certain attributes of Def_Id since the preanalysis may
9022 -- have introduced itypes to this scope, thus modifying attributes
9023 -- First_Entity and Last_Entity.
9025 Set_First_Entity
(Def_Id
, Saved_First_Entity
);
9026 Set_Last_Entity
(Def_Id
, Saved_Last_Entity
);
9028 if Present
(Last_Entity
(Def_Id
)) then
9029 Set_Next_Entity
(Last_Entity
(Def_Id
), Empty
);
9032 -- Freeze all types referenced in the expression
9034 Freeze_References
(Dup_Expr
);
9035 end Freeze_Expr_Types
;
9037 -----------------------------
9038 -- Freeze_Fixed_Point_Type --
9039 -----------------------------
9041 -- Certain fixed-point types and subtypes, including implicit base types
9042 -- and declared first subtypes, have not yet set up a range. This is
9043 -- because the range cannot be set until the Small and Size values are
9044 -- known, and these are not known till the type is frozen.
9046 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
9047 -- whose bounds are unanalyzed real literals. This routine will recognize
9048 -- this case, and transform this range node into a properly typed range
9049 -- with properly analyzed and resolved values.
9051 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
9052 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
9053 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
9054 Hi
: constant Node_Id
:= High_Bound
(Rng
);
9055 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9056 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
9057 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
9058 BHi
: constant Node_Id
:= High_Bound
(Brng
);
9059 Ftyp
: constant Entity_Id
:= Underlying_Type
(First_Subtype
(Typ
));
9068 -- Save original bounds (for shaving tests)
9071 -- Actual size chosen
9073 function Fsize
(Lov
, Hiv
: Ureal
) return Int
;
9074 -- Returns size of type with given bounds. Also leaves these
9075 -- bounds set as the current bounds of the Typ.
9077 function Larger
(A
, B
: Ureal
) return Boolean;
9078 -- Returns true if A > B with a margin of Typ'Small
9080 function Smaller
(A
, B
: Ureal
) return Boolean;
9081 -- Returns true if A < B with a margin of Typ'Small
9087 function Fsize
(Lov
, Hiv
: Ureal
) return Int
is
9089 Set_Realval
(Lo
, Lov
);
9090 Set_Realval
(Hi
, Hiv
);
9091 return Minimum_Size
(Typ
);
9098 function Larger
(A
, B
: Ureal
) return Boolean is
9100 return A
> B
and then A
- Small_Value
(Typ
) > B
;
9107 function Smaller
(A
, B
: Ureal
) return Boolean is
9109 return A
< B
and then A
+ Small_Value
(Typ
) < B
;
9112 -- Start of processing for Freeze_Fixed_Point_Type
9115 -- The type, or its first subtype if we are freezing the anonymous
9116 -- base, may have a delayed Small aspect. It must be analyzed now,
9117 -- so that all characteristics of the type (size, bounds) can be
9118 -- computed and validated in the call to Minimum_Size that follows.
9120 if Has_Delayed_Aspects
(Ftyp
) then
9121 Analyze_Aspects_At_Freeze_Point
(Ftyp
);
9122 Set_Has_Delayed_Aspects
(Ftyp
, False);
9125 if May_Inherit_Delayed_Rep_Aspects
(Ftyp
) then
9126 Inherit_Delayed_Rep_Aspects
(Ftyp
);
9127 Set_May_Inherit_Delayed_Rep_Aspects
(Ftyp
, False);
9130 -- Inherit the Small value from the first subtype in any case
9133 Set_Small_Value
(Typ
, Small_Value
(Ftyp
));
9136 -- If Esize of a subtype has not previously been set, set it now
9138 if not Known_Esize
(Typ
) then
9139 Atype
:= Ancestor_Subtype
(Typ
);
9141 if Present
(Atype
) then
9142 Set_Esize
(Typ
, Esize
(Atype
));
9144 Copy_Esize
(To
=> Typ
, From
=> Btyp
);
9148 -- Immediate return if the range is already analyzed. This means that
9149 -- the range is already set, and does not need to be computed by this
9152 if Analyzed
(Rng
) then
9156 -- Immediate return if either of the bounds raises Constraint_Error
9158 if Raises_Constraint_Error
(Lo
)
9159 or else Raises_Constraint_Error
(Hi
)
9164 Small
:= Small_Value
(Typ
);
9165 Loval
:= Realval
(Lo
);
9166 Hival
:= Realval
(Hi
);
9171 -- Ordinary fixed-point case
9173 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
9175 -- For the ordinary fixed-point case, we are allowed to fudge the
9176 -- end-points up or down by small. Generally we prefer to fudge up,
9177 -- i.e. widen the bounds for non-model numbers so that the end points
9178 -- are included. However there are cases in which this cannot be
9179 -- done, and indeed cases in which we may need to narrow the bounds.
9180 -- The following circuit makes the decision.
9182 -- Note: our terminology here is that Incl_EP means that the bounds
9183 -- are widened by Small if necessary to include the end points, and
9184 -- Excl_EP means that the bounds are narrowed by Small to exclude the
9185 -- end-points if this reduces the size.
9187 -- Note that in the Incl case, all we care about is including the
9188 -- end-points. In the Excl case, we want to narrow the bounds as
9189 -- much as permitted by the RM, to give the smallest possible size.
9192 Loval_Incl_EP
: Ureal
;
9193 Hival_Incl_EP
: Ureal
;
9195 Loval_Excl_EP
: Ureal
;
9196 Hival_Excl_EP
: Ureal
;
9206 -- First step. Base types are required to be symmetrical. Right
9207 -- now, the base type range is a copy of the first subtype range.
9208 -- This will be corrected before we are done, but right away we
9209 -- need to deal with the case where both bounds are non-negative.
9210 -- In this case, we set the low bound to the negative of the high
9211 -- bound, to make sure that the size is computed to include the
9212 -- required sign. Note that we do not need to worry about the
9213 -- case of both bounds negative, because the sign will be dealt
9214 -- with anyway. Furthermore we can't just go making such a bound
9215 -- symmetrical, since in a twos-complement system, there is an
9216 -- extra negative value which could not be accommodated on the
9220 and then not UR_Is_Negative
(Loval
)
9221 and then Hival
> Loval
9224 Set_Realval
(Lo
, Loval
);
9227 -- Compute the fudged bounds. If the bound is a model number, (or
9228 -- greater if given low bound, smaller if high bound) then we do
9229 -- nothing to include it, but we are allowed to backoff to the
9230 -- next adjacent model number when we exclude it. If it is not a
9231 -- model number then we straddle the two values with the model
9232 -- numbers on either side.
9234 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
9236 if UR_Ge
(Loval
, Model_Num
) then
9237 Loval_Incl_EP
:= Model_Num
;
9239 Loval_Incl_EP
:= Model_Num
- Small
;
9242 -- The low value excluding the end point is Small greater, but
9243 -- we do not do this exclusion if the low value is positive,
9244 -- since it can't help the size and could actually hurt by
9245 -- crossing the high bound.
9247 if UR_Is_Negative
(Loval_Incl_EP
) then
9248 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
9250 -- If the value went from negative to zero, then we have the
9251 -- case where Loval_Incl_EP is the model number just below
9252 -- zero, so we want to stick to the negative value for the
9253 -- base type to maintain the condition that the size will
9254 -- include signed values.
9257 and then UR_Is_Zero
(Loval_Excl_EP
)
9259 Loval_Excl_EP
:= Loval_Incl_EP
;
9263 Loval_Excl_EP
:= Loval_Incl_EP
;
9266 -- Similar processing for upper bound and high value
9268 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
9270 if UR_Le
(Hival
, Model_Num
) then
9271 Hival_Incl_EP
:= Model_Num
;
9273 Hival_Incl_EP
:= Model_Num
+ Small
;
9276 if UR_Is_Positive
(Hival_Incl_EP
) then
9277 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
9279 Hival_Excl_EP
:= Hival_Incl_EP
;
9282 -- One further adjustment is needed. In the case of subtypes, we
9283 -- cannot go outside the range of the base type, or we get
9284 -- peculiarities, and the base type range is already set. This
9285 -- only applies to the Incl values, since clearly the Excl values
9286 -- are already as restricted as they are allowed to be.
9289 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
9290 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
9293 -- Get size including and excluding end points
9295 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
9296 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
9298 -- No need to exclude end-points if it does not reduce size
9300 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
9301 Loval_Excl_EP
:= Loval_Incl_EP
;
9304 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
9305 Hival_Excl_EP
:= Hival_Incl_EP
;
9308 -- Now we set the actual size to be used. We want to use the
9309 -- bounds fudged up to include the end-points but only if this
9310 -- can be done without violating a specifically given size
9311 -- size clause or causing an unacceptable increase in size.
9313 -- Case of size clause given
9315 if Has_Size_Clause
(Typ
) then
9317 -- Use the inclusive size only if it is consistent with
9318 -- the explicitly specified size.
9320 if Size_Incl_EP
<= RM_Size
(Typ
) then
9321 Actual_Lo
:= Loval_Incl_EP
;
9322 Actual_Hi
:= Hival_Incl_EP
;
9323 Actual_Size
:= Size_Incl_EP
;
9325 -- If the inclusive size is too large, we try excluding
9326 -- the end-points (will be caught later if does not work).
9329 Actual_Lo
:= Loval_Excl_EP
;
9330 Actual_Hi
:= Hival_Excl_EP
;
9331 Actual_Size
:= Size_Excl_EP
;
9334 -- Case of size clause not given
9337 -- If we have a base type whose corresponding first subtype
9338 -- has an explicit size that is large enough to include our
9339 -- end-points, then do so. There is no point in working hard
9340 -- to get a base type whose size is smaller than the specified
9341 -- size of the first subtype.
9343 if Has_Size_Clause
(Ftyp
)
9344 and then Size_Incl_EP
<= Esize
(Ftyp
)
9346 Actual_Size
:= Size_Incl_EP
;
9347 Actual_Lo
:= Loval_Incl_EP
;
9348 Actual_Hi
:= Hival_Incl_EP
;
9350 -- If excluding the end-points makes the size smaller and
9351 -- results in a size of 8,16,32,64, then we take the smaller
9352 -- size. For the 64 case, this is compulsory. For the other
9353 -- cases, it seems reasonable. We like to include end points
9354 -- if we can, but not at the expense of moving to the next
9355 -- natural boundary of size.
9357 elsif Size_Incl_EP
/= Size_Excl_EP
9358 and then Addressable
(Size_Excl_EP
)
9360 Actual_Size
:= Size_Excl_EP
;
9361 Actual_Lo
:= Loval_Excl_EP
;
9362 Actual_Hi
:= Hival_Excl_EP
;
9364 -- Otherwise we can definitely include the end points
9367 Actual_Size
:= Size_Incl_EP
;
9368 Actual_Lo
:= Loval_Incl_EP
;
9369 Actual_Hi
:= Hival_Incl_EP
;
9372 -- One pathological case: normally we never fudge a low bound
9373 -- down, since it would seem to increase the size (if it has
9374 -- any effect), but for ranges containing single value, or no
9375 -- values, the high bound can be small too large. Consider:
9377 -- type t is delta 2.0**(-14)
9378 -- range 131072.0 .. 0;
9380 -- That lower bound is *just* outside the range of 32 bits, and
9381 -- does need fudging down in this case. Note that the bounds
9382 -- will always have crossed here, since the high bound will be
9383 -- fudged down if necessary, as in the case of:
9385 -- type t is delta 2.0**(-14)
9386 -- range 131072.0 .. 131072.0;
9388 -- So we detect the situation by looking for crossed bounds,
9389 -- and if the bounds are crossed, and the low bound is greater
9390 -- than zero, we will always back it off by small, since this
9391 -- is completely harmless.
9393 if Actual_Lo
> Actual_Hi
then
9394 if UR_Is_Positive
(Actual_Lo
) then
9395 Actual_Lo
:= Loval_Incl_EP
- Small
;
9396 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9398 -- And of course, we need to do exactly the same parallel
9399 -- fudge for flat ranges in the negative region.
9401 elsif UR_Is_Negative
(Actual_Hi
) then
9402 Actual_Hi
:= Hival_Incl_EP
+ Small
;
9403 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9408 Set_Realval
(Lo
, Actual_Lo
);
9409 Set_Realval
(Hi
, Actual_Hi
);
9412 -- Enforce some limitations for ordinary fixed-point types. They come
9413 -- from an exact algorithm used to implement Text_IO.Fixed_IO and the
9414 -- Fore, Image and Value attributes. The requirement on the Small is
9415 -- to lie in the range 2**(-(Siz - 1)) .. 2**(Siz - 1) for a type of
9416 -- Siz bits (Siz=32,64,128) and the requirement on the bounds is to
9417 -- be smaller in magnitude than 10.0**N * 2**(Siz - 1), where N is
9418 -- given by the formula N = floor ((Siz - 1) * log 2 / log 10).
9420 -- If the bounds of a 32-bit type are too large, force 64-bit type
9422 if Actual_Size
<= 32
9423 and then Small
<= Ureal_2_31
9424 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_2_10_18
)
9425 or else Larger
(Expr_Value_R
(Hi
), Ureal_2_10_18
))
9430 -- If the bounds of a 64-bit type are too large, force 128-bit type
9432 if System_Max_Integer_Size
= 128
9433 and then Actual_Size
<= 64
9434 and then Small
<= Ureal_2_63
9435 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
)
9436 or else Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
))
9441 -- Give error messages for first subtypes and not base types, as the
9442 -- bounds of base types are always maximum for their size, see below.
9444 if System_Max_Integer_Size
< 128 and then Typ
/= Btyp
then
9446 -- See the 128-bit case below for the reason why we cannot test
9447 -- against the 2**(-63) .. 2**63 range. This quirk should have
9448 -- been kludged around as in the 128-bit case below, but it was
9449 -- not and we end up with a ludicrous range as a result???
9451 if Small
< Ureal_2_M_80
then
9452 Error_Msg_Name_1
:= Name_Small
;
9454 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", Typ
);
9456 elsif Small
> Ureal_2_80
then
9457 Error_Msg_Name_1
:= Name_Small
;
9459 ("`&''%` too large, maximum allowed is 2.0'*'*80", Typ
);
9462 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
) then
9463 Error_Msg_Name_1
:= Name_First
;
9465 ("`&''%` too small, minimum allowed is -9.0E+36", Typ
);
9468 if Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
) then
9469 Error_Msg_Name_1
:= Name_Last
;
9471 ("`&''%` too large, maximum allowed is 9.0E+36", Typ
);
9474 elsif System_Max_Integer_Size
= 128 and then Typ
/= Btyp
then
9476 -- ACATS c35902d tests a delta equal to 2**(-(Max_Mantissa + 1))
9477 -- but we cannot really support anything smaller than Fine_Delta
9478 -- because of the way we implement I/O for fixed point types???
9480 if Small
= Ureal_2_M_128
then
9483 elsif Small
< Ureal_2_M_127
then
9484 Error_Msg_Name_1
:= Name_Small
;
9486 ("`&''%` too small, minimum allowed is 2.0'*'*(-127)", Typ
);
9488 elsif Small
> Ureal_2_127
then
9489 Error_Msg_Name_1
:= Name_Small
;
9491 ("`&''%` too large, maximum allowed is 2.0'*'*127", Typ
);
9495 and then (Norm_Num
(Small
) > Uint_2
** 127
9496 or else Norm_Den
(Small
) > Uint_2
** 127)
9497 and then Small
/= Ureal_2_M_128
9499 Error_Msg_Name_1
:= Name_Small
;
9501 ("`&''%` not the ratio of two 128-bit integers", Typ
);
9504 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_10_76
) then
9505 Error_Msg_Name_1
:= Name_First
;
9507 ("`&''%` too small, minimum allowed is -1.0E+76", Typ
);
9510 if Larger
(Expr_Value_R
(Hi
), Ureal_10_76
) then
9511 Error_Msg_Name_1
:= Name_Last
;
9513 ("`&''%` too large, maximum allowed is 1.0E+76", Typ
);
9517 -- For the decimal case, none of this fudging is required, since there
9518 -- are no end-point problems in the decimal case (the end-points are
9519 -- always included).
9522 Actual_Size
:= Fsize
(Loval
, Hival
);
9525 -- At this stage, the actual size has been calculated and the proper
9526 -- required bounds are stored in the low and high bounds.
9528 if Actual_Size
> System_Max_Integer_Size
then
9529 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
9530 Error_Msg_Uint_2
:= UI_From_Int
(System_Max_Integer_Size
);
9532 ("size required (^) for type& too large, maximum allowed is ^",
9534 Actual_Size
:= System_Max_Integer_Size
;
9537 -- Check size against explicit given size
9539 if Has_Size_Clause
(Typ
) then
9540 if Actual_Size
> RM_Size
(Typ
) then
9541 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9542 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
9544 ("size given (^) for type& too small, minimum allowed is ^",
9545 Size_Clause
(Typ
), Typ
);
9548 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
9551 -- Increase size to next natural boundary if no size clause given
9554 if Actual_Size
<= 8 then
9556 elsif Actual_Size
<= 16 then
9558 elsif Actual_Size
<= 32 then
9560 elsif Actual_Size
<= 64 then
9566 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9567 Adjust_Esize_For_Alignment
(Typ
);
9570 -- If we have a base type, then expand the bounds so that they extend to
9571 -- the full width of the allocated size in bits, to avoid junk range
9572 -- checks on intermediate computations.
9575 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
9576 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
9579 -- Final step is to reanalyze the bounds using the proper type
9580 -- and set the Corresponding_Integer_Value fields of the literals.
9582 Set_Etype
(Lo
, Empty
);
9583 Set_Analyzed
(Lo
, False);
9586 -- Resolve with universal fixed if the base type, and with the base
9587 -- type if we are freezing a subtype. Note we can't resolve the base
9588 -- type with itself, that would be a reference before definition.
9589 -- The resolution of the bounds of a subtype, if they are given by real
9590 -- literals, includes the setting of the Corresponding_Integer_Value,
9591 -- as for other literals of a fixed-point type.
9594 Resolve
(Lo
, Universal_Fixed
);
9595 Set_Corresponding_Integer_Value
9596 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
9601 -- Similar processing for high bound
9603 Set_Etype
(Hi
, Empty
);
9604 Set_Analyzed
(Hi
, False);
9608 Resolve
(Hi
, Universal_Fixed
);
9609 Set_Corresponding_Integer_Value
9610 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
9615 -- Set type of range to correspond to bounds
9617 Set_Etype
(Rng
, Etype
(Lo
));
9619 -- Set Esize to calculated size if not set already
9621 if not Known_Esize
(Typ
) then
9622 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9625 -- Set RM_Size if not already set. If already set, check value
9628 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
9631 if Known_RM_Size
(Typ
) then
9632 if RM_Size
(Typ
) < Minsiz
then
9633 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9634 Error_Msg_Uint_2
:= Minsiz
;
9636 ("size given (^) for type& too small, minimum allowed is ^",
9637 Size_Clause
(Typ
), Typ
);
9641 Set_RM_Size
(Typ
, Minsiz
);
9645 -- Check for shaving
9647 if Comes_From_Source
(Typ
) then
9649 -- In SPARK mode the given bounds must be strictly representable
9651 if SPARK_Mode
= On
then
9652 if Orig_Lo
< Expr_Value_R
(Lo
) then
9654 ("declared low bound of type & is outside type range",
9658 if Orig_Hi
> Expr_Value_R
(Hi
) then
9660 ("declared high bound of type & is outside type range",
9665 if Orig_Lo
< Expr_Value_R
(Lo
) then
9667 ("declared low bound of type & is outside type range??", Typ
);
9669 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
9672 if Orig_Hi
> Expr_Value_R
(Hi
) then
9674 ("declared high bound of type & is outside type range??",
9677 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
9681 end Freeze_Fixed_Point_Type
;
9687 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
9691 Set_Has_Delayed_Freeze
(T
);
9692 L
:= Freeze_Entity
(T
, N
);
9694 Insert_Actions
(N
, L
);
9697 --------------------------
9698 -- Freeze_Static_Object --
9699 --------------------------
9701 procedure Freeze_Static_Object
(E
: Entity_Id
) is
9703 Cannot_Be_Static
: exception;
9704 -- Exception raised if the type of a static object cannot be made
9705 -- static. This happens if the type depends on non-global objects.
9707 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
9708 -- Called to ensure that an expression used as part of a type definition
9709 -- is statically allocatable, which means that the expression type is
9710 -- statically allocatable, and the expression is either static, or a
9711 -- reference to a library level constant.
9713 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
9714 -- Called to mark a type as static, checking that it is possible
9715 -- to set the type as static. If it is not possible, then the
9716 -- exception Cannot_Be_Static is raised.
9718 -----------------------------
9719 -- Ensure_Expression_Is_SA --
9720 -----------------------------
9722 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
9726 Ensure_Type_Is_SA
(Etype
(N
));
9728 if Is_OK_Static_Expression
(N
) then
9731 elsif Nkind
(N
) = N_Identifier
then
9735 and then Ekind
(Ent
) = E_Constant
9736 and then Is_Library_Level_Entity
(Ent
)
9742 raise Cannot_Be_Static
;
9743 end Ensure_Expression_Is_SA
;
9745 -----------------------
9746 -- Ensure_Type_Is_SA --
9747 -----------------------
9749 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
9754 -- If type is library level, we are all set
9756 if Is_Library_Level_Entity
(Typ
) then
9760 -- We are also OK if the type already marked as statically allocated,
9761 -- which means we processed it before.
9763 if Is_Statically_Allocated
(Typ
) then
9767 -- Mark type as statically allocated
9769 Set_Is_Statically_Allocated
(Typ
);
9771 -- Check that it is safe to statically allocate this type
9773 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
9774 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
9775 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
9777 elsif Is_Array_Type
(Typ
) then
9778 N
:= First_Index
(Typ
);
9779 while Present
(N
) loop
9780 Ensure_Type_Is_SA
(Etype
(N
));
9784 Ensure_Type_Is_SA
(Component_Type
(Typ
));
9786 elsif Is_Access_Type
(Typ
) then
9787 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
9791 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
9794 if T
/= Standard_Void_Type
then
9795 Ensure_Type_Is_SA
(T
);
9798 F
:= First_Formal
(Designated_Type
(Typ
));
9799 while Present
(F
) loop
9800 Ensure_Type_Is_SA
(Etype
(F
));
9806 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
9809 elsif Is_Record_Type
(Typ
) then
9810 C
:= First_Entity
(Typ
);
9811 while Present
(C
) loop
9812 if Ekind
(C
) = E_Discriminant
9813 or else Ekind
(C
) = E_Component
9815 Ensure_Type_Is_SA
(Etype
(C
));
9817 elsif Is_Type
(C
) then
9818 Ensure_Type_Is_SA
(C
);
9824 elsif Ekind
(Typ
) = E_Subprogram_Type
then
9825 Ensure_Type_Is_SA
(Etype
(Typ
));
9827 C
:= First_Formal
(Typ
);
9828 while Present
(C
) loop
9829 Ensure_Type_Is_SA
(Etype
(C
));
9834 raise Cannot_Be_Static
;
9836 end Ensure_Type_Is_SA
;
9838 -- Start of processing for Freeze_Static_Object
9841 Ensure_Type_Is_SA
(Etype
(E
));
9844 when Cannot_Be_Static
=>
9846 -- If the object that cannot be static is imported or exported, then
9847 -- issue an error message saying that this object cannot be imported
9848 -- or exported. If it has an address clause it is an overlay in the
9849 -- current partition and the static requirement is not relevant.
9850 -- Do not issue any error message when ignoring rep clauses.
9852 if Ignore_Rep_Clauses
then
9855 elsif Is_Imported
(E
) then
9856 if No
(Address_Clause
(E
)) then
9858 ("& cannot be imported (local type is not constant)", E
);
9861 -- Otherwise must be exported, something is wrong if compiler
9862 -- is marking something as statically allocated which cannot be).
9864 else pragma Assert
(Is_Exported
(E
));
9866 ("& cannot be exported (local type is not constant)", E
);
9868 end Freeze_Static_Object
;
9870 -----------------------
9871 -- Freeze_Subprogram --
9872 -----------------------
9874 procedure Freeze_Subprogram
(E
: Entity_Id
) is
9876 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
);
9877 -- Set the conventions of all anonymous access-to-subprogram formals and
9878 -- result subtype of subprogram Subp_Id to the convention of Subp_Id.
9880 ----------------------------
9881 -- Set_Profile_Convention --
9882 ----------------------------
9884 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
) is
9885 Conv
: constant Convention_Id
:= Convention
(Subp_Id
);
9887 procedure Set_Type_Convention
(Typ
: Entity_Id
);
9888 -- Set the convention of anonymous access-to-subprogram type Typ and
9889 -- its designated type to Conv.
9891 -------------------------
9892 -- Set_Type_Convention --
9893 -------------------------
9895 procedure Set_Type_Convention
(Typ
: Entity_Id
) is
9897 -- Set the convention on both the anonymous access-to-subprogram
9898 -- type and the subprogram type it points to because both types
9899 -- participate in conformance-related checks.
9901 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
9902 Set_Convention
(Typ
, Conv
);
9903 Set_Convention
(Designated_Type
(Typ
), Conv
);
9905 end Set_Type_Convention
;
9911 -- Start of processing for Set_Profile_Convention
9914 Formal
:= First_Formal
(Subp_Id
);
9915 while Present
(Formal
) loop
9916 Set_Type_Convention
(Etype
(Formal
));
9917 Next_Formal
(Formal
);
9920 if Ekind
(Subp_Id
) = E_Function
then
9921 Set_Type_Convention
(Etype
(Subp_Id
));
9923 end Set_Profile_Convention
;
9930 -- Start of processing for Freeze_Subprogram
9933 -- Subprogram may not have an address clause unless it is imported
9935 if Present
(Address_Clause
(E
)) then
9936 if not Is_Imported
(E
) then
9938 ("address clause can only be given for imported subprogram",
9939 Name
(Address_Clause
(E
)));
9943 -- Reset the Pure indication on an imported subprogram unless an
9944 -- explicit Pure_Function pragma was present or the subprogram is an
9945 -- intrinsic. We do this because otherwise it is an insidious error
9946 -- to call a non-pure function from pure unit and have calls
9947 -- mysteriously optimized away. What happens here is that the Import
9948 -- can bypass the normal check to ensure that pure units call only pure
9951 -- The reason for the intrinsic exception is that in general, intrinsic
9952 -- functions (such as shifts) are pure anyway. The only exceptions are
9953 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
9954 -- in any case, so no problem arises.
9957 and then Is_Pure
(E
)
9958 and then not Has_Pragma_Pure_Function
(E
)
9959 and then not Is_Intrinsic_Subprogram
(E
)
9961 Set_Is_Pure
(E
, False);
9964 -- For C++ constructors check that their external name has been given
9965 -- (either in pragma CPP_Constructor or in a pragma import).
9967 if Is_Constructor
(E
)
9968 and then Convention
(E
) = Convention_CPP
9970 (No
(Interface_Name
(E
))
9971 or else String_Equal
9972 (L
=> Strval
(Interface_Name
(E
)),
9973 R
=> Strval
(Get_Default_External_Name
(E
))))
9976 ("'C++ constructor must have external name or link name", E
);
9979 -- We also reset the Pure indication on a subprogram with an Address
9980 -- parameter, because the parameter may be used as a pointer and the
9981 -- referenced data may change even if the address value does not.
9983 -- Note that if the programmer gave an explicit Pure_Function pragma,
9984 -- then we believe the programmer, and leave the subprogram Pure. We
9985 -- also suppress this check on run-time files.
9988 and then Is_Subprogram
(E
)
9989 and then not Has_Pragma_Pure_Function
(E
)
9990 and then not Is_Internal_Unit
(Current_Sem_Unit
)
9992 Check_Function_With_Address_Parameter
(E
);
9995 -- Ensure that all anonymous access-to-subprogram types inherit the
9996 -- convention of their related subprogram (RM 6.3.1(13.1/5)). This is
9997 -- not done for a defaulted convention Ada because those types also
9998 -- default to Ada. Convention Protected must not be propagated when
9999 -- the subprogram is an entry because this would be illegal. The only
10000 -- way to force convention Protected on these kinds of types is to
10001 -- include keyword "protected" in the access definition. Conventions
10002 -- Entry and Intrinsic are also not propagated (specified by AI12-0207).
10004 if Convention
(E
) /= Convention_Ada
10005 and then Convention
(E
) /= Convention_Protected
10006 and then Convention
(E
) /= Convention_Entry
10007 and then Convention
(E
) /= Convention_Intrinsic
10009 Set_Profile_Convention
(E
);
10012 -- For non-foreign convention subprograms, this is where we create
10013 -- the extra formals (for accessibility level and constrained bit
10014 -- information). We delay this till the freeze point precisely so
10015 -- that we know the convention.
10017 if not Has_Foreign_Convention
(E
) then
10019 -- Extra formals of dispatching operations are added later by
10020 -- Expand_Freeze_Record_Type, which also adds extra formals to
10021 -- internal entities built to handle interface types.
10023 if not Is_Dispatching_Operation
(E
) then
10024 Create_Extra_Formals
(E
);
10027 ((Ekind
(E
) = E_Subprogram_Type
10028 and then Extra_Formals_OK
(E
))
10031 and then Extra_Formals_OK
(E
)
10033 (No
(Overridden_Operation
(E
))
10034 or else Extra_Formals_Match_OK
(E
,
10035 Ultimate_Alias
(Overridden_Operation
(E
))))));
10038 Set_Mechanisms
(E
);
10040 -- If this is convention Ada and a Valued_Procedure, that's odd
10042 if Ekind
(E
) = E_Procedure
10043 and then Is_Valued_Procedure
(E
)
10044 and then Convention
(E
) = Convention_Ada
10045 and then Warn_On_Export_Import
10048 ("??Valued_Procedure has no effect for convention Ada", E
);
10049 Set_Is_Valued_Procedure
(E
, False);
10052 -- Case of foreign convention
10055 Set_Mechanisms
(E
);
10057 -- For foreign conventions, warn about return of unconstrained array
10059 if Ekind
(E
) = E_Function
then
10060 Retype
:= Underlying_Type
(Etype
(E
));
10062 -- If no return type, probably some other error, e.g. a
10063 -- missing full declaration, so ignore.
10065 if No
(Retype
) then
10068 -- If the return type is generic, we have emitted a warning
10069 -- earlier on, and there is nothing else to check here. Specific
10070 -- instantiations may lead to erroneous behavior.
10072 elsif Is_Generic_Type
(Etype
(E
)) then
10075 -- Display warning if returning unconstrained array
10077 elsif Is_Array_Type
(Retype
)
10078 and then not Is_Constrained
(Retype
)
10080 -- Check appropriate warning is enabled (should we check for
10081 -- Warnings (Off) on specific entities here, probably so???)
10083 and then Warn_On_Export_Import
10086 ("?x?foreign convention function& should not return " &
10087 "unconstrained array", E
);
10092 -- If any of the formals for an exported foreign convention
10093 -- subprogram have defaults, then emit an appropriate warning since
10094 -- this is odd (default cannot be used from non-Ada code)
10096 if Is_Exported
(E
) then
10097 F
:= First_Formal
(E
);
10098 while Present
(F
) loop
10099 if Warn_On_Export_Import
10100 and then Present
(Default_Value
(F
))
10103 ("?x?parameter cannot be defaulted in non-Ada call",
10104 Default_Value
(F
));
10112 -- Pragma Inline_Always is disallowed for dispatching subprograms
10113 -- because the address of such subprograms is saved in the dispatch
10114 -- table to support dispatching calls, and dispatching calls cannot
10115 -- be inlined. This is consistent with the restriction against using
10116 -- 'Access or 'Address on an Inline_Always subprogram.
10118 if Is_Dispatching_Operation
(E
)
10119 and then Has_Pragma_Inline_Always
(E
)
10122 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
10125 if Is_Dispatching_Operation
(E
)
10126 and then Present
(Overridden_Operation
(E
))
10128 Local_Restrict
.Check_Overriding
10129 (Overrider_Op
=> E
, Overridden_Op
=> Overridden_Operation
(E
));
10132 -- Because of the implicit representation of inherited predefined
10133 -- operators in the front-end, the overriding status of the operation
10134 -- may be affected when a full view of a type is analyzed, and this is
10135 -- not captured by the analysis of the corresponding type declaration.
10136 -- Therefore the correctness of a not-overriding indicator must be
10137 -- rechecked when the subprogram is frozen.
10139 if Nkind
(E
) = N_Defining_Operator_Symbol
10140 and then not Error_Posted
(Parent
(E
))
10142 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
10145 Retype
:= Get_Fullest_View
(Etype
(E
));
10147 if Transform_Function_Array
10148 and then Nkind
(Parent
(E
)) = N_Function_Specification
10149 and then Is_Array_Type
(Retype
)
10150 and then Is_Constrained
(Retype
)
10151 and then not Is_Unchecked_Conversion_Instance
(E
)
10152 and then not Rewritten_For_C
(E
)
10154 Build_Procedure_Form
(Unit_Declaration_Node
(E
));
10156 end Freeze_Subprogram
;
10158 ----------------------
10159 -- Is_Fully_Defined --
10160 ----------------------
10162 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
10164 if Ekind
(T
) = E_Class_Wide_Type
then
10165 return Is_Fully_Defined
(Etype
(T
));
10167 elsif Is_Array_Type
(T
) then
10168 return Is_Fully_Defined
(Component_Type
(T
));
10170 elsif Is_Record_Type
(T
)
10171 and not Is_Private_Type
(T
)
10173 -- Verify that the record type has no components with private types
10174 -- without completion.
10180 Comp
:= First_Component
(T
);
10181 while Present
(Comp
) loop
10182 if not Is_Fully_Defined
(Etype
(Comp
)) then
10186 Next_Component
(Comp
);
10191 -- For the designated type of an access to subprogram, all types in
10192 -- the profile must be fully defined.
10194 elsif Ekind
(T
) = E_Subprogram_Type
then
10199 F
:= First_Formal
(T
);
10200 while Present
(F
) loop
10201 if not Is_Fully_Defined
(Etype
(F
)) then
10208 return Is_Fully_Defined
(Etype
(T
));
10212 return not Is_Private_Type
(T
)
10213 or else Present
(Full_View
(Base_Type
(T
)));
10215 end Is_Fully_Defined
;
10217 ---------------------------------
10218 -- Process_Default_Expressions --
10219 ---------------------------------
10221 procedure Process_Default_Expressions
10223 After
: in out Node_Id
)
10225 Loc
: constant Source_Ptr
:= Sloc
(E
);
10232 Set_Default_Expressions_Processed
(E
);
10234 -- A subprogram instance and its associated anonymous subprogram share
10235 -- their signature. The default expression functions are defined in the
10236 -- wrapper packages for the anonymous subprogram, and should not be
10237 -- generated again for the instance.
10239 if Is_Generic_Instance
(E
)
10240 and then Present
(Alias
(E
))
10241 and then Default_Expressions_Processed
(Alias
(E
))
10246 Formal
:= First_Formal
(E
);
10247 while Present
(Formal
) loop
10248 if Present
(Default_Value
(Formal
)) then
10250 -- We work with a copy of the default expression because we
10251 -- do not want to disturb the original, since this would mess
10252 -- up the conformance checking.
10254 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
10256 -- The analysis of the expression may generate insert actions,
10257 -- which of course must not be executed. We wrap those actions
10258 -- in a procedure that is not called, and later on eliminated.
10259 -- The following cases have no side effects, and are analyzed
10262 if Nkind
(Dcopy
) = N_Identifier
10263 or else Nkind
(Dcopy
) in N_Expanded_Name
10264 | N_Integer_Literal
10265 | N_Character_Literal
10268 or else (Nkind
(Dcopy
) = N_Attribute_Reference
10269 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
10270 or else Known_Null
(Dcopy
)
10272 -- If there is no default function, we must still do a full
10273 -- analyze call on the default value, to ensure that all error
10274 -- checks are performed, e.g. those associated with static
10275 -- evaluation. Note: this branch will always be taken if the
10276 -- analyzer is turned off (but we still need the error checks).
10278 -- Note: the setting of parent here is to meet the requirement
10279 -- that we can only analyze the expression while attached to
10280 -- the tree. Really the requirement is that the parent chain
10281 -- be set, we don't actually need to be in the tree.
10283 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
10286 -- Default expressions are resolved with their own type if the
10287 -- context is generic, to avoid anomalies with private types.
10289 if Ekind
(Scope
(E
)) = E_Generic_Package
then
10292 Resolve
(Dcopy
, Etype
(Formal
));
10295 -- If that resolved expression will raise constraint error,
10296 -- then flag the default value as raising constraint error.
10297 -- This allows a proper error message on the calls.
10299 if Raises_Constraint_Error
(Dcopy
) then
10300 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
10303 -- If the default is a parameterless call, we use the name of
10304 -- the called function directly, and there is no body to build.
10306 elsif Nkind
(Dcopy
) = N_Function_Call
10307 and then No
(Parameter_Associations
(Dcopy
))
10311 -- Else construct and analyze the body of a wrapper procedure
10312 -- that contains an object declaration to hold the expression.
10313 -- Given that this is done only to complete the analysis, it is
10314 -- simpler to build a procedure than a function which might
10315 -- involve secondary stack expansion.
10318 Dnam
:= Make_Temporary
(Loc
, 'D');
10321 Make_Subprogram_Body
(Loc
,
10323 Make_Procedure_Specification
(Loc
,
10324 Defining_Unit_Name
=> Dnam
),
10326 Declarations
=> New_List
(
10327 Make_Object_Declaration
(Loc
,
10328 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
10329 Object_Definition
=>
10330 New_Occurrence_Of
(Etype
(Formal
), Loc
),
10331 Expression
=> New_Copy_Tree
(Dcopy
))),
10333 Handled_Statement_Sequence
=>
10334 Make_Handled_Sequence_Of_Statements
(Loc
,
10335 Statements
=> Empty_List
));
10337 Set_Scope
(Dnam
, Scope
(E
));
10338 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
10339 Set_Is_Eliminated
(Dnam
);
10340 Insert_After
(After
, Dbody
);
10346 Next_Formal
(Formal
);
10348 end Process_Default_Expressions
;
10350 ----------------------------------------
10351 -- Set_Component_Alignment_If_Not_Set --
10352 ----------------------------------------
10354 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
10356 -- Ignore if not base type, subtypes don't need anything
10358 if Typ
/= Base_Type
(Typ
) then
10362 -- Do not override existing representation
10364 if Is_Packed
(Typ
) then
10367 elsif Has_Specified_Layout
(Typ
) then
10370 elsif Component_Alignment
(Typ
) /= Calign_Default
then
10374 Set_Component_Alignment
10375 (Typ
, Scope_Stack
.Table
10376 (Scope_Stack
.Last
).Component_Alignment_Default
);
10378 end Set_Component_Alignment_If_Not_Set
;
10380 --------------------------
10381 -- Set_SSO_From_Default --
10382 --------------------------
10384 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
10385 Reversed
: Boolean;
10388 -- Set default SSO for an array or record base type, except in case of
10389 -- a type extension (which always inherits the SSO of its parent type).
10391 if Is_Base_Type
(T
)
10392 and then (Is_Array_Type
(T
)
10393 or else (Is_Record_Type
(T
)
10394 and then not (Is_Tagged_Type
(T
)
10395 and then Is_Derived_Type
(T
))))
10398 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
10400 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
10402 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
10404 -- For a record type, if bit order is specified explicitly,
10405 -- then do not set SSO from default if not consistent. Note that
10406 -- we do not want to look at a Bit_Order attribute definition
10407 -- for a parent: if we were to inherit Bit_Order, then both
10408 -- SSO_Set_*_By_Default flags would have been cleared already
10409 -- (by Inherit_Aspects_At_Freeze_Point).
10412 (Is_Record_Type
(T
)
10414 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
10415 and then Reverse_Bit_Order
(T
) /= Reversed
)
10417 -- If flags cause reverse storage order, then set the result. Note
10418 -- that we would have ignored the pragma setting the non default
10419 -- storage order in any case, hence the assertion at this point.
10422 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
10424 Set_Reverse_Storage_Order
(T
, Reversed
);
10426 -- For a record type, also set reversed bit order. Note: if a bit
10427 -- order has been specified explicitly, then this is a no-op.
10429 if Is_Record_Type
(T
) then
10430 Set_Reverse_Bit_Order
(T
, Reversed
);
10434 end Set_SSO_From_Default
;
10440 procedure Undelay_Type
(T
: Entity_Id
) is
10442 Set_Has_Delayed_Freeze
(T
, False);
10443 Set_Freeze_Node
(T
, Empty
);
10445 -- Since we don't want T to have a Freeze_Node, we don't want its
10446 -- Full_View or Corresponding_Record_Type to have one either.
10448 -- ??? Fundamentally, this whole handling is unpleasant. What we really
10449 -- want is to be sure that for an Itype that's part of record R and is a
10450 -- subtype of type T, that it's frozen after the later of the freeze
10451 -- points of R and T. We have no way of doing that directly, so what we
10452 -- do is force most such Itypes to be frozen as part of freezing R via
10453 -- this procedure and only delay the ones that need to be delayed
10454 -- (mostly the designated types of access types that are defined as part
10457 if Is_Private_Type
(T
)
10458 and then Present
(Full_View
(T
))
10459 and then Is_Itype
(Full_View
(T
))
10460 and then Is_Record_Type
(Scope
(Full_View
(T
)))
10462 Undelay_Type
(Full_View
(T
));
10465 if Is_Concurrent_Type
(T
)
10466 and then Present
(Corresponding_Record_Type
(T
))
10467 and then Is_Itype
(Corresponding_Record_Type
(T
))
10468 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
10470 Undelay_Type
(Corresponding_Record_Type
(T
));
10478 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
) is
10479 Ent
: constant Entity_Id
:= Entity
(Nam
);
10480 -- The object to which the address clause applies
10483 Old
: Entity_Id
:= Empty
;
10487 -- No warning if address clause overlay warnings are off
10489 if not Address_Clause_Overlay_Warnings
then
10493 -- No warning if there is an explicit initialization
10495 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
10497 if Present
(Init
) and then Comes_From_Source
(Init
) then
10501 -- We only give the warning for non-imported entities of a type for
10502 -- which a non-null base init proc is defined, or for objects of access
10503 -- types with implicit null initialization, or when Normalize_Scalars
10504 -- applies and the type is scalar or a string type (the latter being
10505 -- tested for because predefined String types are initialized by inline
10506 -- code rather than by an init_proc). Note that we do not give the
10507 -- warning for Initialize_Scalars, since we suppressed initialization
10508 -- in this case. Also, do not warn if Suppress_Initialization is set
10509 -- either on the type, or on the object via pragma or aspect.
10512 and then not Is_Imported
(Ent
)
10513 and then not Initialization_Suppressed
(Typ
)
10514 and then not (Ekind
(Ent
) = E_Variable
10515 and then Initialization_Suppressed
(Ent
))
10516 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
10517 or else Is_Access_Type
(Typ
)
10518 or else (Normalize_Scalars
10519 and then (Is_Scalar_Type
(Typ
)
10520 or else Is_String_Type
(Typ
))))
10522 if Nkind
(Expr
) = N_Attribute_Reference
10523 and then Is_Entity_Name
(Prefix
(Expr
))
10525 Old
:= Entity
(Prefix
(Expr
));
10527 elsif Is_Entity_Name
(Expr
)
10528 and then Ekind
(Entity
(Expr
)) = E_Constant
10530 Decl
:= Declaration_Node
(Entity
(Expr
));
10532 if Nkind
(Decl
) = N_Object_Declaration
10533 and then Present
(Expression
(Decl
))
10534 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
10535 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
10537 Old
:= Entity
(Prefix
(Expression
(Decl
)));
10539 elsif Nkind
(Expr
) = N_Function_Call
then
10543 -- A function call (most likely to To_Address) is probably not an
10544 -- overlay, so skip warning. Ditto if the function call was inlined
10545 -- and transformed into an entity.
10547 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
10551 -- If a pragma Import follows, we assume that it is for the current
10552 -- target of the address clause, and skip the warning. There may be
10553 -- a source pragma or an aspect that specifies import and generates
10554 -- the corresponding pragma. These will indicate that the entity is
10555 -- imported and that is checked above so that the spurious warning
10556 -- (generated when the entity is frozen) will be suppressed. The
10557 -- pragma may be attached to the aspect, so it is not yet a list
10560 if Is_List_Member
(Parent
(Expr
)) then
10561 Decl
:= Next
(Parent
(Expr
));
10564 and then Nkind
(Decl
) = N_Pragma
10565 and then Pragma_Name
(Decl
) = Name_Import
10571 -- Otherwise give warning message
10573 if Present
(Old
) then
10574 Error_Msg_Node_2
:= Old
;
10576 ("default initialization of & may modify &?o?",
10580 ("default initialization of & may modify overlaid storage?o?",
10584 -- Add friendly warning if initialization comes from a packed array
10587 if Is_Record_Type
(Typ
) then
10592 Comp
:= First_Component
(Typ
);
10593 while Present
(Comp
) loop
10594 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
10595 and then Present
(Expression
(Parent
(Comp
)))
10598 elsif Is_Array_Type
(Etype
(Comp
))
10599 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
10602 ("\packed array component& " &
10603 "will be initialized to zero??",
10607 Next_Component
(Comp
);
10614 ("\use pragma Import for & to " &
10615 "suppress initialization (RM B.1(24))??",