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
;
45 with Namet
; use Namet
;
46 with Nlists
; use Nlists
;
47 with Nmake
; use Nmake
;
49 with Restrict
; use Restrict
;
50 with Rident
; use Rident
;
51 with Rtsfind
; use Rtsfind
;
53 with Sem_Aux
; use Sem_Aux
;
54 with Sem_Cat
; use Sem_Cat
;
55 with Sem_Ch3
; use Sem_Ch3
;
56 with Sem_Ch6
; use Sem_Ch6
;
57 with Sem_Ch7
; use Sem_Ch7
;
58 with Sem_Ch8
; use Sem_Ch8
;
59 with Sem_Ch13
; use Sem_Ch13
;
60 with Sem_Disp
; use Sem_Disp
;
61 with Sem_Eval
; use Sem_Eval
;
62 with Sem_Mech
; use Sem_Mech
;
63 with Sem_Prag
; use Sem_Prag
;
64 with Sem_Res
; use Sem_Res
;
65 with Sem_Util
; use Sem_Util
;
66 with Sinfo
; use Sinfo
;
67 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
68 with Sinfo
.Utils
; use Sinfo
.Utils
;
69 with Snames
; use Snames
;
70 with Stand
; use Stand
;
71 with Stringt
; use Stringt
;
72 with Strub
; use Strub
;
73 with Targparm
; use Targparm
;
74 with Tbuild
; use Tbuild
;
75 with Ttypes
; use Ttypes
;
76 with Uintp
; use Uintp
;
77 with Urealp
; use Urealp
;
78 with Warnsw
; use Warnsw
;
80 package body Freeze
is
82 -----------------------
83 -- Local Subprograms --
84 -----------------------
86 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
87 -- Typ is a type that is being frozen. If no size clause is given,
88 -- but a default Esize has been computed, then this default Esize is
89 -- adjusted up if necessary to be consistent with a given alignment,
90 -- but never to a value greater than System_Max_Integer_Size. This is
91 -- used for all discrete types and for fixed-point types.
93 procedure Build_And_Analyze_Renamed_Body
96 After
: in out Node_Id
);
97 -- Build body for a renaming declaration, insert in tree and analyze
99 procedure Check_Address_Clause
(E
: Entity_Id
);
100 -- Apply legality checks to address clauses for object declarations,
101 -- at the point the object is frozen. Also ensure any initialization is
102 -- performed only after the object has been frozen.
104 procedure Check_Component_Storage_Order
105 (Encl_Type
: Entity_Id
;
108 Comp_ADC_Present
: out Boolean);
109 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
110 -- clause, verify that the component type has an explicit and compatible
111 -- attribute/aspect. For arrays, Comp is Empty; for records, it is the
112 -- entity of the component under consideration. For an Encl_Type that
113 -- does not have a Scalar_Storage_Order attribute definition clause,
114 -- verify that the component also does not have such a clause.
115 -- ADC is the attribute definition clause if present (or Empty). On return,
116 -- Comp_ADC_Present is set True if the component has a Scalar_Storage_Order
117 -- attribute definition clause.
119 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
120 -- As each entity is frozen, this routine is called to deal with the
121 -- setting of Debug_Info_Needed for the entity. This flag is set if
122 -- the entity comes from source, or if we are in Debug_Generated_Code
123 -- mode or if the -gnatdV debug flag is set. However, it never sets
124 -- the flag if Debug_Info_Off is set. This procedure also ensures that
125 -- subsidiary entities have the flag set as required.
127 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
);
128 -- When an expression function is frozen by a use of it, the expression
129 -- itself is frozen. Check that the expression does not include references
130 -- to deferred constants without completion. We report this at the freeze
131 -- point of the function, to provide a better error message.
133 -- In most cases the expression itself is frozen by the time the function
134 -- itself is frozen, because the formals will be frozen by then. However,
135 -- Attribute references to outer types are freeze points for those types;
136 -- this routine generates the required freeze nodes for them.
138 procedure Check_Strict_Alignment
(E
: Entity_Id
);
139 -- E is a base type. If E is tagged or has a component that is aliased
140 -- or tagged or contains something this is aliased or tagged, set
143 procedure Check_Unsigned_Type
(E
: Entity_Id
);
144 pragma Inline
(Check_Unsigned_Type
);
145 -- If E is a fixed-point or discrete type, then all the necessary work
146 -- to freeze it is completed except for possible setting of the flag
147 -- Is_Unsigned_Type, which is done by this procedure. The call has no
148 -- effect if the entity E is not a discrete or fixed-point type.
150 procedure Freeze_And_Append
153 Result
: in out List_Id
);
154 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
155 -- nodes to Result, modifying Result from No_List if necessary. N has
156 -- the same usage as in Freeze_Entity.
158 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
159 -- Freeze enumeration type. The Esize field is set as processing
160 -- proceeds (i.e. set by default when the type is declared and then
161 -- adjusted by rep clauses). What this procedure does is to make sure
162 -- that if a foreign convention is specified, and no specific size
163 -- is given, then the size must be at least Integer'Size.
165 procedure Freeze_Static_Object
(E
: Entity_Id
);
166 -- If an object is frozen which has Is_Statically_Allocated set, then
167 -- all referenced types must also be marked with this flag. This routine
168 -- is in charge of meeting this requirement for the object entity E.
170 procedure Freeze_Subprogram
(E
: Entity_Id
);
171 -- Perform freezing actions for a subprogram (create extra formals,
172 -- and set proper default mechanism values). Note that this routine
173 -- is not called for internal subprograms, for which neither of these
174 -- actions is needed (or desirable, we do not want for example to have
175 -- these extra formals present in initialization procedures, where they
176 -- would serve no purpose). In this call E is either a subprogram or
177 -- a subprogram type (i.e. an access to a subprogram).
179 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
180 -- True if T is not private and has no private components, or has a full
181 -- view. Used to determine whether the designated type of an access type
182 -- should be frozen when the access type is frozen. This is done when an
183 -- allocator is frozen, or an expression that may involve attributes of
184 -- the designated type. Otherwise freezing the access type does not freeze
185 -- the designated type.
187 function Should_Freeze_Type
188 (Typ
: Entity_Id
; E
: Entity_Id
; N
: Node_Id
) return Boolean;
189 -- If Typ is in the current scope, then return True.
190 -- N is a node whose source location corresponds to the freeze point.
191 -- ??? Expression functions (represented by E) shouldn't freeze types in
192 -- general, but our current expansion and freezing model requires an early
193 -- freezing when the dispatch table is needed or when building an aggregate
194 -- with a subtype of Typ, so return True also in this case.
195 -- Note that expression function completions do freeze and are
196 -- handled in Sem_Ch6.Analyze_Expression_Function.
198 ------------------------
199 -- Should_Freeze_Type --
200 ------------------------
202 function Should_Freeze_Type
203 (Typ
: Entity_Id
; E
: Entity_Id
; N
: Node_Id
) return Boolean
205 function Is_Dispatching_Call_Or_Aggregate
206 (N
: Node_Id
) return Traverse_Result
;
207 -- Return Abandon if N is a dispatching call to a subprogram
208 -- declared in the same scope as Typ or an aggregate whose type
211 --------------------------------------
212 -- Is_Dispatching_Call_Or_Aggregate --
213 --------------------------------------
215 function Is_Dispatching_Call_Or_Aggregate
216 (N
: Node_Id
) return Traverse_Result
is
218 if Nkind
(N
) = N_Function_Call
219 and then Present
(Controlling_Argument
(N
))
220 and then Scope
(Entity
(Original_Node
(Name
(N
))))
224 elsif Nkind
(N
) = N_Aggregate
225 and then Base_Type
(Etype
(N
)) = Base_Type
(Typ
)
231 end Is_Dispatching_Call_Or_Aggregate
;
233 -------------------------
234 -- Need_Dispatch_Table --
235 -------------------------
237 function Need_Dispatch_Table
is new
238 Traverse_Func
(Is_Dispatching_Call_Or_Aggregate
);
239 -- Return Abandon if the input expression requires access to
240 -- Typ's dispatch table.
242 Decl
: constant Node_Id
:=
243 (if No
(E
) then E
else Original_Node
(Unit_Declaration_Node
(E
)));
245 -- Start of processing for Should_Freeze_Type
248 return Within_Scope
(Typ
, Current_Scope
)
249 or else (Nkind
(N
) = N_Subprogram_Renaming_Declaration
250 and then Present
(Corresponding_Formal_Spec
(N
)))
251 or else (Present
(Decl
)
252 and then Nkind
(Decl
) = N_Expression_Function
253 and then Need_Dispatch_Table
(Expression
(Decl
)) = Abandon
);
254 end Should_Freeze_Type
;
256 procedure Process_Default_Expressions
258 After
: in out Node_Id
);
259 -- This procedure is called for each subprogram to complete processing of
260 -- default expressions at the point where all types are known to be frozen.
261 -- The expressions must be analyzed in full, to make sure that all error
262 -- processing is done (they have only been preanalyzed). If the expression
263 -- is not an entity or literal, its analysis may generate code which must
264 -- not be executed. In that case we build a function body to hold that
265 -- code. This wrapper function serves no other purpose (it used to be
266 -- called to evaluate the default, but now the default is inlined at each
269 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
270 -- Typ is a record or array type that is being frozen. This routine sets
271 -- the default component alignment from the scope stack values if the
272 -- alignment is otherwise not specified.
274 procedure Set_SSO_From_Default
(T
: Entity_Id
);
275 -- T is a record or array type that is being frozen. If it is a base type,
276 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
277 -- will be set appropriately. Note that an explicit occurrence of aspect
278 -- Scalar_Storage_Order or an explicit setting of this aspect with an
279 -- attribute definition clause occurs, then these two flags are reset in
280 -- any case, so call will have no effect.
282 procedure Undelay_Type
(T
: Entity_Id
);
283 -- T is a type of a component that we know to be an Itype. We don't want
284 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
285 -- Full_View or Corresponding_Record_Type.
287 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
);
288 -- Expr is the expression for an address clause for the entity denoted by
289 -- Nam whose type is Typ. If Typ has a default initialization, and there is
290 -- no explicit initialization in the source declaration, check whether the
291 -- address clause might cause overlaying of an entity, and emit a warning
292 -- on the side effect that the initialization will cause.
294 -------------------------------
295 -- Adjust_Esize_For_Alignment --
296 -------------------------------
298 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
302 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
303 Align
:= Alignment_In_Bits
(Typ
);
305 if Align
> Esize
(Typ
) and then Align
<= System_Max_Integer_Size
then
306 Set_Esize
(Typ
, Align
);
309 end Adjust_Esize_For_Alignment
;
311 ------------------------------------
312 -- Build_And_Analyze_Renamed_Body --
313 ------------------------------------
315 procedure Build_And_Analyze_Renamed_Body
318 After
: in out Node_Id
)
320 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
321 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
323 Renamed_Subp
: Entity_Id
;
326 -- If the renamed subprogram is intrinsic, there is no need for a
327 -- wrapper body: we set the alias that will be called and expanded which
328 -- completes the declaration. This transformation is only legal if the
329 -- renamed entity has already been elaborated.
331 -- Note that it is legal for a renaming_as_body to rename an intrinsic
332 -- subprogram, as long as the renaming occurs before the new entity
333 -- is frozen (RM 8.5.4 (5)).
335 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
336 and then Is_Entity_Name
(Name
(Body_Decl
))
338 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
340 Renamed_Subp
:= Empty
;
343 if Present
(Renamed_Subp
)
344 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
346 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
347 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
349 -- We can make the renaming entity intrinsic if the renamed function
350 -- has an interface name, or if it is one of the shift/rotate
351 -- operations known to the compiler.
354 (Present
(Interface_Name
(Renamed_Subp
))
355 or else Chars
(Renamed_Subp
) in Name_Rotate_Left
359 | Name_Shift_Right_Arithmetic
)
361 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
363 if Present
(Alias
(Renamed_Subp
)) then
364 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
366 Set_Alias
(Ent
, Renamed_Subp
);
369 Set_Is_Intrinsic_Subprogram
(Ent
);
370 Set_Has_Completion
(Ent
);
373 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
374 Insert_After
(After
, Body_Node
);
375 Mark_Rewrite_Insertion
(Body_Node
);
379 end Build_And_Analyze_Renamed_Body
;
381 ------------------------
382 -- Build_Renamed_Body --
383 ------------------------
385 function Build_Renamed_Body
387 New_S
: Entity_Id
) return Node_Id
389 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
390 -- We use for the source location of the renamed body, the location of
391 -- the spec entity. It might seem more natural to use the location of
392 -- the renaming declaration itself, but that would be wrong, since then
393 -- the body we create would look as though it was created far too late,
394 -- and this could cause problems with elaboration order analysis,
395 -- particularly in connection with instantiations.
397 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
398 Nam
: constant Node_Id
:= Name
(N
);
400 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
406 O_Formal
: Entity_Id
;
407 Param_Spec
: Node_Id
;
409 Pref
: Node_Id
:= Empty
;
410 -- If the renamed entity is a primitive operation given in prefix form,
411 -- the prefix is the target object and it has to be added as the first
412 -- actual in the generated call.
415 -- Determine the entity being renamed, which is the target of the call
416 -- statement. If the name is an explicit dereference, this is a renaming
417 -- of a subprogram type rather than a subprogram. The name itself is
420 if Nkind
(Nam
) = N_Selected_Component
then
421 Old_S
:= Entity
(Selector_Name
(Nam
));
423 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
424 Old_S
:= Etype
(Nam
);
426 elsif Nkind
(Nam
) = N_Indexed_Component
then
427 if Is_Entity_Name
(Prefix
(Nam
)) then
428 Old_S
:= Entity
(Prefix
(Nam
));
430 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
433 elsif Nkind
(Nam
) = N_Character_Literal
then
434 Old_S
:= Etype
(New_S
);
437 Old_S
:= Entity
(Nam
);
440 if Is_Entity_Name
(Nam
) then
442 -- If the renamed entity is a predefined operator, retain full name
443 -- to ensure its visibility.
445 if Ekind
(Old_S
) = E_Operator
446 and then Nkind
(Nam
) = N_Expanded_Name
448 Call_Name
:= New_Copy
(Name
(N
));
450 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
454 if Nkind
(Nam
) = N_Selected_Component
455 and then Present
(First_Formal
(Old_S
))
457 (Is_Controlling_Formal
(First_Formal
(Old_S
))
458 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
461 -- Retrieve the target object, to be added as a first actual
464 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
465 Pref
:= Prefix
(Nam
);
468 Call_Name
:= New_Copy
(Name
(N
));
471 -- Original name may have been overloaded, but is fully resolved now
473 Set_Is_Overloaded
(Call_Name
, False);
476 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
478 Make_Subprogram_Declaration
(Loc
,
479 Specification
=> Specification
(N
)));
482 -- For simple renamings, subsequent calls can be expanded directly as
483 -- calls to the renamed entity. The body must be generated in any case
484 -- for calls that may appear elsewhere. This is not done in the case
485 -- where the subprogram is an instantiation because the actual proper
486 -- body has not been built yet.
488 if Ekind
(Old_S
) in E_Function | E_Procedure
489 and then not Is_Generic_Instance
(Old_S
)
491 Set_Body_To_Inline
(Decl
, Old_S
);
494 -- Check whether the return type is a limited view. If the subprogram
495 -- is already frozen the generated body may have a non-limited view
496 -- of the type, that must be used, because it is the one in the spec
497 -- of the renaming declaration.
499 if Ekind
(Old_S
) = E_Function
500 and then Is_Entity_Name
(Result_Definition
(Spec
))
503 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
505 if Has_Non_Limited_View
(Ret_Type
) then
506 Set_Result_Definition
507 (Spec
, New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
512 -- The body generated for this renaming is an internal artifact, and
513 -- does not constitute a freeze point for the called entity.
515 Set_Must_Not_Freeze
(Call_Name
);
517 Formal
:= First_Formal
(Defining_Entity
(Decl
));
519 if Present
(Pref
) then
521 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
522 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
525 -- The controlling formal may be an access parameter, or the
526 -- actual may be an access value, so adjust accordingly.
528 if Is_Access_Type
(Pref_Type
)
529 and then not Is_Access_Type
(Form_Type
)
532 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
534 elsif Is_Access_Type
(Form_Type
)
535 and then not Is_Access_Type
(Pref
)
539 Make_Attribute_Reference
(Loc
,
540 Attribute_Name
=> Name_Access
,
541 Prefix
=> Relocate_Node
(Pref
)));
543 Actuals
:= New_List
(Pref
);
547 elsif Present
(Formal
) then
554 while Present
(Formal
) loop
555 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
556 Next_Formal
(Formal
);
559 -- If the renamed entity is an entry, inherit its profile. For other
560 -- renamings as bodies, both profiles must be subtype conformant, so it
561 -- is not necessary to replace the profile given in the declaration.
562 -- However, default values that are aggregates are rewritten when
563 -- partially analyzed, so we recover the original aggregate to insure
564 -- that subsequent conformity checking works. Similarly, if the default
565 -- expression was constant-folded, recover the original expression.
567 Formal
:= First_Formal
(Defining_Entity
(Decl
));
569 if Present
(Formal
) then
570 O_Formal
:= First_Formal
(Old_S
);
571 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
572 while Present
(Formal
) loop
573 if Is_Entry
(Old_S
) then
574 if Nkind
(Parameter_Type
(Param_Spec
)) /=
577 Set_Etype
(Formal
, Etype
(O_Formal
));
578 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
581 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
582 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
583 Nkind
(Default_Value
(O_Formal
))
585 Set_Expression
(Param_Spec
,
586 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
589 Next_Formal
(Formal
);
590 Next_Formal
(O_Formal
);
595 -- If the renamed entity is a function, the generated body contains a
596 -- return statement. Otherwise, build a procedure call. If the entity is
597 -- an entry, subsequent analysis of the call will transform it into the
598 -- proper entry or protected operation call. If the renamed entity is
599 -- a character literal, return it directly.
601 if Ekind
(Old_S
) = E_Function
602 or else Ekind
(Old_S
) = E_Operator
603 or else (Ekind
(Old_S
) = E_Subprogram_Type
604 and then Etype
(Old_S
) /= Standard_Void_Type
)
607 Make_Simple_Return_Statement
(Loc
,
609 Make_Function_Call
(Loc
,
611 Parameter_Associations
=> Actuals
));
613 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
615 Make_Simple_Return_Statement
(Loc
,
616 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
618 elsif Nkind
(Nam
) = N_Character_Literal
then
620 Make_Simple_Return_Statement
(Loc
, Expression
=> Call_Name
);
624 Make_Procedure_Call_Statement
(Loc
,
626 Parameter_Associations
=> Actuals
);
629 -- Create entities for subprogram body and formals
631 Set_Defining_Unit_Name
(Spec
,
632 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
634 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
635 while Present
(Param_Spec
) loop
636 Set_Defining_Identifier
(Param_Spec
,
637 Make_Defining_Identifier
(Loc
,
638 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
642 -- In GNATprove, prefer to generate an expression function whenever
643 -- possible, to benefit from the more precise analysis in that case
644 -- (as if an implicit postcondition had been generated).
647 and then Nkind
(Call_Node
) = N_Simple_Return_Statement
650 Make_Expression_Function
(Loc
,
651 Specification
=> Spec
,
652 Expression
=> Expression
(Call_Node
));
655 Make_Subprogram_Body
(Loc
,
656 Specification
=> Spec
,
657 Declarations
=> New_List
,
658 Handled_Statement_Sequence
=>
659 Make_Handled_Sequence_Of_Statements
(Loc
,
660 Statements
=> New_List
(Call_Node
)));
663 -- Link the body to the entity whose declaration it completes. If
664 -- the body is analyzed when the renamed entity is frozen, it may
665 -- be necessary to restore the proper scope (see package Exp_Ch13).
667 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
668 and then Present
(Corresponding_Spec
(N
))
670 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
672 Set_Corresponding_Spec
(Body_Node
, New_S
);
676 end Build_Renamed_Body
;
678 --------------------------
679 -- Check_Address_Clause --
680 --------------------------
682 procedure Check_Address_Clause
(E
: Entity_Id
) is
683 Addr
: constant Node_Id
:= Address_Clause
(E
);
684 Typ
: constant Entity_Id
:= Etype
(E
);
689 Tag_Assign
: Node_Id
;
692 if Present
(Addr
) then
694 -- For a deferred constant, the initialization value is on full view
696 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
697 Decl
:= Declaration_Node
(Full_View
(E
));
699 Decl
:= Declaration_Node
(E
);
702 Expr
:= Expression
(Addr
);
704 if Needs_Constant_Address
(Decl
, Typ
) then
705 Check_Constant_Address_Clause
(Expr
, E
);
707 -- Has_Delayed_Freeze was set on E when the address clause was
708 -- analyzed, and must remain set because we want the address
709 -- clause to be elaborated only after any entity it references
710 -- has been elaborated.
713 -- If Rep_Clauses are to be ignored, remove address clause from
714 -- list attached to entity, because it may be illegal for gigi,
715 -- for example by breaking order of elaboration.
717 if Ignore_Rep_Clauses
then
722 Rep
:= First_Rep_Item
(E
);
725 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
729 and then Next_Rep_Item
(Rep
) /= Addr
735 if Present
(Rep
) then
736 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
740 -- And now remove the address clause
742 Kill_Rep_Clause
(Addr
);
744 elsif not Error_Posted
(Expr
)
745 and then not Needs_Finalization
(Typ
)
747 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
750 Init
:= Expression
(Decl
);
752 -- If a variable, or a non-imported constant, overlays a constant
753 -- object and has an initialization value, then the initialization
754 -- may end up writing into read-only memory. Detect the cases of
755 -- statically identical values and remove the initialization. In
756 -- the other cases, give a warning. We will give other warnings
757 -- later for the variable if it is assigned.
759 if (Ekind
(E
) = E_Variable
760 or else (Ekind
(E
) = E_Constant
761 and then not Is_Imported
(E
)))
762 and then Overlays_Constant
(E
)
763 and then Present
(Init
)
770 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
772 if Ekind
(O_Ent
) = E_Constant
773 and then Etype
(O_Ent
) = Typ
774 and then Present
(Constant_Value
(O_Ent
))
775 and then Compile_Time_Compare
777 Constant_Value
(O_Ent
),
778 Assume_Valid
=> True) = EQ
780 Set_No_Initialization
(Decl
);
783 elsif Comes_From_Source
(Init
)
784 and then Address_Clause_Overlay_Warnings
786 Error_Msg_Sloc
:= Sloc
(Addr
);
788 ("?o?constant& may be modified via address clause#",
794 -- Remove side effects from initial expression, except in the case of
795 -- limited build-in-place calls and aggregates, which have their own
796 -- expansion elsewhere. This exception is necessary to avoid copying
800 and then not Is_Limited_View
(Typ
)
802 -- Capture initialization value at point of declaration, and make
803 -- explicit assignment legal, because object may be a constant.
805 Remove_Side_Effects
(Init
);
806 Lhs
:= New_Occurrence_Of
(E
, Sloc
(Decl
));
807 Set_Assignment_OK
(Lhs
);
809 -- Move initialization to freeze actions, once the object has
810 -- been frozen and the address clause alignment check has been
813 Append_Freeze_Action
(E
,
814 Make_Assignment_Statement
(Sloc
(Decl
),
816 Expression
=> Expression
(Decl
)));
818 Set_No_Initialization
(Decl
);
820 -- If the object is tagged, check whether the tag must be
821 -- reassigned explicitly.
823 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
824 if Present
(Tag_Assign
) then
825 Append_Freeze_Action
(E
, Tag_Assign
);
829 end Check_Address_Clause
;
831 -----------------------------
832 -- Check_Compile_Time_Size --
833 -----------------------------
835 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
837 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
838 -- Sets the compile time known size in the RM_Size field of T, checking
839 -- for a size clause that was given which attempts to give a small size.
841 function Size_Known
(T
: Entity_Id
) return Boolean;
842 -- Recursive function that does all the work
844 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
845 -- If T is a constrained subtype, its size is not known if any of its
846 -- discriminant constraints is not static and it is not a null record.
847 -- The test is conservative and doesn't check that the components are
848 -- in fact constrained by non-static discriminant values. Could be made
855 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
857 if S
> System_Max_Integer_Size
then
860 -- Check for bad size clause given
862 elsif Has_Size_Clause
(T
) then
863 if RM_Size
(T
) < S
then
864 Error_Msg_Uint_1
:= S
;
865 Error_Msg_NE
(Size_Too_Small_Message
, Size_Clause
(T
), T
);
868 -- Set size if not set already. Do not set it to Uint_0, because in
869 -- some cases (notably array-of-record), the Component_Size is
870 -- No_Uint, which causes S to be Uint_0. Presumably the RM_Size and
871 -- Component_Size will eventually be set correctly by the back end.
873 elsif not Known_RM_Size
(T
) and then S
/= Uint_0
then
882 function Size_Known
(T
: Entity_Id
) return Boolean is
887 if Size_Known_At_Compile_Time
(T
) then
890 -- Always True for elementary types, even generic formal elementary
891 -- types. We used to return False in the latter case, but the size
892 -- is known at compile time, even in the template, we just do not
893 -- know the exact size but that's not the point of this routine.
895 elsif Is_Elementary_Type
(T
) or else Is_Task_Type
(T
) then
900 elsif Is_Array_Type
(T
) then
902 -- String literals always have known size, and we can set it
904 if Ekind
(T
) = E_String_Literal_Subtype
then
905 if Known_Component_Size
(T
) then
907 (T
, Component_Size
(T
) * String_Literal_Length
(T
));
910 -- The following is wrong, but does what previous versions
911 -- did. The Component_Size is unknown for the string in a
913 Set_Small_Size
(T
, Uint_0
);
918 -- Unconstrained types never have known at compile time size
920 elsif not Is_Constrained
(T
) then
923 -- Don't do any recursion on type with error posted, since we may
924 -- have a malformed type that leads us into a loop.
926 elsif Error_Posted
(T
) then
929 -- Otherwise if component size unknown, then array size unknown
931 elsif not Size_Known
(Component_Type
(T
)) then
935 -- Check for all indexes static, and also compute possible size
936 -- (in case it is not greater than System_Max_Integer_Size and
937 -- thus may be packable).
943 Size
: Uint
:= Component_Size
(T
);
947 -- See comment in Set_Small_Size above
953 Index
:= First_Index
(T
);
954 while Present
(Index
) loop
955 if Nkind
(Index
) = N_Range
then
956 Get_Index_Bounds
(Index
, Low
, High
);
958 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
962 Low
:= Type_Low_Bound
(Etype
(Index
));
963 High
:= Type_High_Bound
(Etype
(Index
));
966 if not Compile_Time_Known_Value
(Low
)
967 or else not Compile_Time_Known_Value
(High
)
968 or else Etype
(Index
) = Any_Type
973 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
985 Set_Small_Size
(T
, Size
);
989 -- For non-generic private types, go to underlying type if present
991 elsif Is_Private_Type
(T
)
992 and then not Is_Generic_Type
(T
)
993 and then Present
(Underlying_Type
(T
))
995 -- Don't do any recursion on type with error posted, since we may
996 -- have a malformed type that leads us into a loop.
998 if Error_Posted
(T
) then
1001 return Size_Known
(Underlying_Type
(T
));
1006 elsif Is_Record_Type
(T
) then
1008 -- A class-wide type is never considered to have a known size
1010 if Is_Class_Wide_Type
(T
) then
1013 -- A subtype of a variant record must not have non-static
1014 -- discriminated components.
1016 elsif T
/= Base_Type
(T
)
1017 and then not Static_Discriminated_Components
(T
)
1021 -- Don't do any recursion on type with error posted, since we may
1022 -- have a malformed type that leads us into a loop.
1024 elsif Error_Posted
(T
) then
1028 -- Now look at the components of the record
1031 -- The following two variables are used to keep track of the
1032 -- size of packed records if we can tell the size of the packed
1033 -- record in the front end. Packed_Size_Known is True if so far
1034 -- we can figure out the size. It is initialized to True for a
1035 -- packed record, unless the record has either discriminants or
1036 -- independent components, or is a strict-alignment type, since
1037 -- it cannot be fully packed in this case.
1039 -- The reason we eliminate the discriminated case is that
1040 -- we don't know the way the back end lays out discriminated
1041 -- packed records. If Packed_Size_Known is True, then
1042 -- Packed_Size is the size in bits so far.
1044 Packed_Size_Known
: Boolean :=
1046 and then not Has_Discriminants
(T
)
1047 and then not Has_Independent_Components
(T
)
1048 and then not Strict_Alignment
(T
);
1050 Packed_Size
: Uint
:= Uint_0
;
1051 -- Size in bits so far
1054 -- Test for variant part present
1056 if Has_Discriminants
(T
)
1057 and then Present
(Parent
(T
))
1058 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
1059 and then Nkind
(Type_Definition
(Parent
(T
))) =
1061 and then not Null_Present
(Type_Definition
(Parent
(T
)))
1063 Present
(Variant_Part
1064 (Component_List
(Type_Definition
(Parent
(T
)))))
1066 -- If variant part is present, and type is unconstrained,
1067 -- then we must have defaulted discriminants, or a size
1068 -- clause must be present for the type, or else the size
1069 -- is definitely not known at compile time.
1071 if not Is_Constrained
(T
)
1073 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
1074 and then not Known_RM_Size
(T
)
1080 -- Loop through components
1082 Comp
:= First_Component_Or_Discriminant
(T
);
1083 while Present
(Comp
) loop
1084 Ctyp
:= Etype
(Comp
);
1086 -- We do not know the packed size if there is a component
1087 -- clause present (we possibly could, but this would only
1088 -- help in the case of a record with partial rep clauses.
1089 -- That's because in the case of full rep clauses, the
1090 -- size gets figured out anyway by a different circuit).
1092 if Present
(Component_Clause
(Comp
)) then
1093 Packed_Size_Known
:= False;
1096 -- We do not know the packed size for an independent
1097 -- component or if it is of a strict-alignment type,
1098 -- since packing does not touch these (RM 13.2(7)).
1100 if Is_Independent
(Comp
)
1101 or else Is_Independent
(Ctyp
)
1102 or else Strict_Alignment
(Ctyp
)
1104 Packed_Size_Known
:= False;
1107 -- We need to identify a component that is an array where
1108 -- the index type is an enumeration type with non-standard
1109 -- representation, and some bound of the type depends on a
1112 -- This is because gigi computes the size by doing a
1113 -- substitution of the appropriate discriminant value in
1114 -- the size expression for the base type, and gigi is not
1115 -- clever enough to evaluate the resulting expression (which
1116 -- involves a call to rep_to_pos) at compile time.
1118 -- It would be nice if gigi would either recognize that
1119 -- this expression can be computed at compile time, or
1120 -- alternatively figured out the size from the subtype
1121 -- directly, where all the information is at hand ???
1123 if Is_Array_Type
(Etype
(Comp
))
1124 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1127 Ocomp
: constant Entity_Id
:=
1128 Original_Record_Component
(Comp
);
1129 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1135 Ind
:= First_Index
(OCtyp
);
1136 while Present
(Ind
) loop
1137 Indtyp
:= Etype
(Ind
);
1139 if Is_Enumeration_Type
(Indtyp
)
1140 and then Has_Non_Standard_Rep
(Indtyp
)
1142 Lo
:= Type_Low_Bound
(Indtyp
);
1143 Hi
:= Type_High_Bound
(Indtyp
);
1145 if Is_Entity_Name
(Lo
)
1146 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1150 elsif Is_Entity_Name
(Hi
)
1151 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1162 -- Clearly size of record is not known if the size of one of
1163 -- the components is not known.
1165 if not Size_Known
(Ctyp
) then
1169 -- Accumulate packed size if possible
1171 if Packed_Size_Known
then
1173 -- We can deal with elementary types, small packed arrays
1174 -- if the representation is a modular type and also small
1175 -- record types as checked by Set_Small_Size.
1177 if Is_Elementary_Type
(Ctyp
)
1178 or else (Is_Array_Type
(Ctyp
)
1180 (Packed_Array_Impl_Type
(Ctyp
))
1181 and then Is_Modular_Integer_Type
1182 (Packed_Array_Impl_Type
(Ctyp
)))
1183 or else Is_Record_Type
(Ctyp
)
1185 -- If RM_Size is known and static, then we can keep
1186 -- accumulating the packed size.
1188 if Known_Static_RM_Size
(Ctyp
) then
1190 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1192 -- If we have a field whose RM_Size is not known then
1193 -- we can't figure out the packed size here.
1196 Packed_Size_Known
:= False;
1199 -- For other types we can't figure out the packed size
1202 Packed_Size_Known
:= False;
1206 Next_Component_Or_Discriminant
(Comp
);
1209 if Packed_Size_Known
then
1210 Set_Small_Size
(T
, Packed_Size
);
1216 -- All other cases, size not known at compile time
1223 -------------------------------------
1224 -- Static_Discriminated_Components --
1225 -------------------------------------
1227 function Static_Discriminated_Components
1228 (T
: Entity_Id
) return Boolean
1230 Constraint
: Elmt_Id
;
1233 if Has_Discriminants
(T
)
1234 and then Present
(Discriminant_Constraint
(T
))
1235 and then Present
(First_Component
(T
))
1237 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1238 while Present
(Constraint
) loop
1239 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1243 Next_Elmt
(Constraint
);
1248 end Static_Discriminated_Components
;
1250 -- Start of processing for Check_Compile_Time_Size
1253 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1254 end Check_Compile_Time_Size
;
1256 -----------------------------------
1257 -- Check_Component_Storage_Order --
1258 -----------------------------------
1260 procedure Check_Component_Storage_Order
1261 (Encl_Type
: Entity_Id
;
1264 Comp_ADC_Present
: out Boolean)
1266 Comp_Base
: Entity_Id
;
1268 Encl_Base
: Entity_Id
;
1271 Component_Aliased
: Boolean;
1273 Comp_Byte_Aligned
: Boolean := False;
1274 -- Set for the record case, True if Comp is aligned on byte boundaries
1275 -- (in which case it is allowed to have different storage order).
1277 Comp_SSO_Differs
: Boolean;
1278 -- Set True when the component is a nested composite, and it does not
1279 -- have the same scalar storage order as Encl_Type.
1284 if Present
(Comp
) then
1286 Comp_Base
:= Etype
(Comp
);
1288 if Is_Tag
(Comp
) then
1289 Comp_Byte_Aligned
:= True;
1290 Component_Aliased
:= False;
1293 -- If a component clause is present, check if the component starts
1294 -- and ends on byte boundaries. Otherwise conservatively assume it
1295 -- does so only in the case where the record is not packed.
1297 if Present
(Component_Clause
(Comp
)) then
1298 Comp_Byte_Aligned
:=
1299 Known_Normalized_First_Bit
(Comp
)
1303 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0
1305 Esize
(Comp
) mod System_Storage_Unit
= 0;
1307 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1310 Component_Aliased
:= Is_Aliased
(Comp
);
1316 Err_Node
:= Encl_Type
;
1317 Comp_Base
:= Component_Type
(Encl_Type
);
1319 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1322 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1323 -- the attribute definition clause is attached to the first subtype.
1324 -- Also, if the base type is incomplete or private, go to full view
1327 Encl_Base
:= Base_Type
(Encl_Type
);
1328 if Present
(Underlying_Type
(Encl_Base
)) then
1329 Encl_Base
:= Underlying_Type
(Encl_Base
);
1332 Comp_Base
:= Base_Type
(Comp_Base
);
1333 if Present
(Underlying_Type
(Comp_Base
)) then
1334 Comp_Base
:= Underlying_Type
(Comp_Base
);
1338 Get_Attribute_Definition_Clause
1339 (First_Subtype
(Comp_Base
), Attribute_Scalar_Storage_Order
);
1340 Comp_ADC_Present
:= Present
(Comp_ADC
);
1342 -- Case of record or array component: check storage order compatibility.
1343 -- But, if the record has Complex_Representation, then it is treated as
1344 -- a scalar in the back end so the storage order is irrelevant.
1346 if (Is_Record_Type
(Comp_Base
)
1347 and then not Has_Complex_Representation
(Comp_Base
))
1348 or else Is_Array_Type
(Comp_Base
)
1351 Reverse_Storage_Order
(Encl_Base
) /=
1352 Reverse_Storage_Order
(Comp_Base
);
1354 -- Parent and extension must have same storage order
1356 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1357 if Comp_SSO_Differs
then
1359 ("record extension must have same scalar storage order as "
1360 & "parent", Err_Node
);
1363 -- If component and composite SSO differs, check that component
1364 -- falls on byte boundaries and isn't bit packed.
1366 elsif Comp_SSO_Differs
then
1368 -- Component SSO differs from enclosing composite:
1370 -- Reject if composite is a bit-packed array, as it is rewritten
1371 -- into an array of scalars.
1373 if Is_Bit_Packed_Array
(Encl_Base
) then
1375 ("type of packed array must have same scalar storage order "
1376 & "as component", Err_Node
);
1378 -- Reject if not byte aligned
1380 elsif Is_Record_Type
(Encl_Base
)
1381 and then not Comp_Byte_Aligned
1383 if Present
(Component_Clause
(Comp
)) then
1385 ("type of non-byte-aligned component must have same scalar"
1386 & " storage order as enclosing record", Err_Node
);
1389 ("type of packed component must have same scalar"
1390 & " storage order as enclosing record", Err_Node
);
1393 -- Warn if specified only for the outer composite
1395 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1397 ("scalar storage order specified for & does not apply to "
1398 & "component?", Err_Node
, Encl_Base
);
1402 -- Enclosing type has explicit SSO: non-composite component must not
1405 elsif Present
(ADC
) and then Component_Aliased
then
1407 ("aliased component not permitted for type with explicit "
1408 & "Scalar_Storage_Order", Err_Node
);
1410 end Check_Component_Storage_Order
;
1412 -----------------------------
1413 -- Check_Debug_Info_Needed --
1414 -----------------------------
1416 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1418 if Debug_Info_Off
(T
) then
1421 elsif Comes_From_Source
(T
)
1422 or else Debug_Generated_Code
1423 or else Debug_Flag_VV
1424 or else Needs_Debug_Info
(T
)
1426 Set_Debug_Info_Needed
(T
);
1428 end Check_Debug_Info_Needed
;
1430 -------------------------------
1431 -- Check_Expression_Function --
1432 -------------------------------
1434 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1435 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1436 -- Function to search for deferred constant
1442 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1444 -- When a constant is initialized with the result of a dispatching
1445 -- call, the constant declaration is rewritten as a renaming of the
1446 -- displaced function result. This scenario is not a premature use of
1447 -- a constant even though the Has_Completion flag is not set.
1449 if Is_Entity_Name
(Nod
)
1450 and then Present
(Entity
(Nod
))
1451 and then Ekind
(Entity
(Nod
)) = E_Constant
1452 and then Scope
(Entity
(Nod
)) = Current_Scope
1453 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1454 N_Object_Declaration
1455 and then not Is_Imported
(Entity
(Nod
))
1456 and then not Has_Completion
(Entity
(Nod
))
1457 and then not (Present
(Full_View
(Entity
(Nod
)))
1458 and then Has_Completion
(Full_View
(Entity
(Nod
))))
1461 ("premature use of& in call or instance", N
, Entity
(Nod
));
1463 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1464 Analyze
(Prefix
(Nod
));
1466 if Is_Entity_Name
(Prefix
(Nod
))
1467 and then Is_Type
(Entity
(Prefix
(Nod
)))
1469 if Expander_Active
then
1470 Check_Fully_Declared
(Entity
(Prefix
(Nod
)), N
);
1473 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1480 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1486 -- Start of processing for Check_Expression_Function
1489 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1491 -- The subprogram body created for the expression function is not
1492 -- itself a freeze point.
1494 if Scope
(Nam
) = Current_Scope
1495 and then Nkind
(Decl
) = N_Expression_Function
1496 and then Nkind
(N
) /= N_Subprogram_Body
1498 Check_Deferred
(Expression
(Decl
));
1500 end Check_Expression_Function
;
1502 --------------------------------
1503 -- Check_Inherited_Conditions --
1504 --------------------------------
1506 procedure Check_Inherited_Conditions
1508 Late_Overriding
: Boolean := False)
1510 Prim_Ops
: constant Elist_Id
:= Primitive_Operations
(R
);
1513 Par_Prim
: Entity_Id
;
1515 Wrapper_Needed
: Boolean;
1517 function Build_DTW_Body
1520 DTW_Decls
: List_Id
;
1521 Par_Prim
: Entity_Id
;
1522 Wrapped_Subp
: Entity_Id
) return Node_Id
;
1523 -- Build the body of the dispatch table wrapper containing the given
1524 -- spec and declarations; the call to the wrapped subprogram includes
1525 -- the proper type conversion.
1527 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
;
1528 -- Build the spec of the dispatch table wrapper
1530 procedure Build_Inherited_Condition_Pragmas
1532 Wrapper_Needed
: out Boolean);
1533 -- Build corresponding pragmas for an operation whose ancestor has
1534 -- class-wide pre/postconditions. If the operation is inherited then
1535 -- Wrapper_Needed is returned True to force the creation of a wrapper
1536 -- for the inherited operation. If the ancestor is being overridden,
1537 -- the pragmas are constructed only to verify their legality, in case
1538 -- they contain calls to other primitives that may have been overridden.
1540 function Needs_Wrapper
1541 (Class_Cond
: Node_Id
;
1543 Par_Subp
: Entity_Id
) return Boolean;
1544 -- Checks whether the dispatch-table wrapper (DTW) for Subp must be
1545 -- built to evaluate the given class-wide condition.
1547 --------------------
1548 -- Build_DTW_Body --
1549 --------------------
1551 function Build_DTW_Body
1554 DTW_Decls
: List_Id
;
1555 Par_Prim
: Entity_Id
;
1556 Wrapped_Subp
: Entity_Id
) return Node_Id
1558 Actuals
: constant List_Id
:= Empty_List
;
1560 Formal
: Entity_Id
:= First_Formal
(Par_Prim
);
1561 New_F_Spec
: Entity_Id
:= First
(Parameter_Specifications
(DTW_Spec
));
1562 New_Formal
: Entity_Id
;
1565 -- Build parameter association for call to wrapped subprogram
1567 while Present
(Formal
) loop
1568 New_Formal
:= Defining_Identifier
(New_F_Spec
);
1570 -- If the controlling argument is inherited, add conversion to
1571 -- parent type for the call.
1573 if Is_Controlling_Formal
(Formal
) then
1575 Make_Type_Conversion
(Loc
,
1576 New_Occurrence_Of
(Etype
(Formal
), Loc
),
1577 New_Occurrence_Of
(New_Formal
, Loc
)));
1579 Append_To
(Actuals
, New_Occurrence_Of
(New_Formal
, Loc
));
1582 Next_Formal
(Formal
);
1586 if Ekind
(Wrapped_Subp
) = E_Procedure
then
1588 Make_Procedure_Call_Statement
(Loc
,
1589 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1590 Parameter_Associations
=> Actuals
);
1593 Make_Simple_Return_Statement
(Loc
,
1595 Make_Function_Call
(Loc
,
1596 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1597 Parameter_Associations
=> Actuals
));
1601 Make_Subprogram_Body
(Loc
,
1602 Specification
=> Copy_Subprogram_Spec
(DTW_Spec
),
1603 Declarations
=> DTW_Decls
,
1604 Handled_Statement_Sequence
=>
1605 Make_Handled_Sequence_Of_Statements
(Loc
,
1606 Statements
=> New_List
(Call
),
1607 End_Label
=> Make_Identifier
(Loc
,
1608 Chars
(Defining_Entity
(DTW_Spec
)))));
1611 --------------------
1612 -- Build_DTW_Spec --
1613 --------------------
1615 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
is
1620 DTW_Spec
:= Build_Overriding_Spec
(Par_Prim
, R
);
1621 DTW_Id
:= Defining_Entity
(DTW_Spec
);
1623 -- Clear the not-overriding indicator since the DTW wrapper overrides
1624 -- its wrapped subprogram; required because if present in the parent
1625 -- primitive, given that Build_Overriding_Spec inherits it, we report
1628 Set_Must_Not_Override
(DTW_Spec
, False);
1630 -- Add minimal decoration of fields
1632 Mutate_Ekind
(DTW_Id
, Ekind
(Par_Prim
));
1633 Set_LSP_Subprogram
(DTW_Id
, Par_Prim
);
1634 Set_Is_Dispatch_Table_Wrapper
(DTW_Id
);
1635 Set_Is_Wrapper
(DTW_Id
);
1637 -- The DTW wrapper is never a null procedure
1639 if Nkind
(DTW_Spec
) = N_Procedure_Specification
then
1640 Set_Null_Present
(DTW_Spec
, False);
1646 ---------------------------------------
1647 -- Build_Inherited_Condition_Pragmas --
1648 ---------------------------------------
1650 procedure Build_Inherited_Condition_Pragmas
1652 Wrapper_Needed
: out Boolean)
1654 Class_Pre
: constant Node_Id
:=
1655 Class_Preconditions
(Ultimate_Alias
(Subp
));
1656 Class_Post
: Node_Id
:= Class_Postconditions
(Par_Prim
);
1661 Wrapper_Needed
:= False;
1663 if No
(Class_Pre
) and then No
(Class_Post
) then
1667 -- For class-wide preconditions we just evaluate whether the wrapper
1668 -- is needed; there is no need to build the pragma since the check
1669 -- is performed on the caller side.
1671 if Present
(Class_Pre
)
1672 and then Needs_Wrapper
(Class_Pre
, Subp
, Par_Prim
)
1674 Wrapper_Needed
:= True;
1677 -- For class-wide postconditions we evaluate whether the wrapper is
1678 -- needed and we build the class-wide postcondition pragma to install
1679 -- it in the wrapper.
1681 if Present
(Class_Post
)
1682 and then Needs_Wrapper
(Class_Post
, Subp
, Par_Prim
)
1684 Wrapper_Needed
:= True;
1686 -- Update the class-wide postcondition
1688 Class_Post
:= New_Copy_Tree
(Class_Post
);
1689 Build_Class_Wide_Expression
1690 (Pragma_Or_Expr
=> Class_Post
,
1692 Par_Subp
=> Par_Prim
,
1693 Adjust_Sloc
=> False);
1695 -- Install the updated class-wide postcondition in a copy of the
1696 -- pragma postcondition defined for the nearest ancestor.
1698 A_Post
:= Get_Class_Wide_Pragma
(Par_Prim
,
1699 Pragma_Postcondition
);
1703 Subps
: constant Subprogram_List
:=
1704 Inherited_Subprograms
(Subp
);
1706 for Index
in Subps
'Range loop
1707 A_Post
:= Get_Class_Wide_Pragma
(Subps
(Index
),
1708 Pragma_Postcondition
);
1709 exit when Present
(A_Post
);
1714 -- A_Post can be null here if the postcondition was inlined in the
1715 -- called subprogram.
1717 if Present
(A_Post
) then
1718 New_Prag
:= New_Copy_Tree
(A_Post
);
1720 (Expression
(First
(Pragma_Argument_Associations
(New_Prag
))),
1722 Append
(New_Prag
, Decls
);
1725 end Build_Inherited_Condition_Pragmas
;
1731 function Needs_Wrapper
1732 (Class_Cond
: Node_Id
;
1734 Par_Subp
: Entity_Id
) return Boolean
1736 Result
: Boolean := False;
1738 function Check_Entity
(N
: Node_Id
) return Traverse_Result
;
1739 -- Check calls to overridden primitives
1741 --------------------
1742 -- Replace_Entity --
1743 --------------------
1745 function Check_Entity
(N
: Node_Id
) return Traverse_Result
is
1749 if Nkind
(N
) = N_Identifier
1750 and then Present
(Entity
(N
))
1752 (Is_Formal
(Entity
(N
)) or else Is_Subprogram
(Entity
(N
)))
1754 (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1755 or else Attribute_Name
(Parent
(N
)) /= Name_Class
)
1757 -- Determine whether entity has a renaming
1759 New_E
:= Get_Mapped_Entity
(Entity
(N
));
1761 -- If the entity is an overridden primitive and we are not
1762 -- in GNATprove mode, we must build a wrapper for the current
1763 -- inherited operation. If the reference is the prefix of an
1764 -- attribute such as 'Result (or others ???) there is no need
1765 -- for a wrapper: the condition is just rewritten in terms of
1766 -- the inherited subprogram.
1769 and then Comes_From_Source
(New_E
)
1770 and then Is_Subprogram
(New_E
)
1771 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
1772 and then not GNATprove_Mode
1782 procedure Check_Condition_Entities
is
1783 new Traverse_Proc
(Check_Entity
);
1785 -- Start of processing for Needs_Wrapper
1788 Update_Primitives_Mapping
(Par_Subp
, Subp
);
1790 Map_Formals
(Par_Subp
, Subp
);
1791 Check_Condition_Entities
(Class_Cond
);
1796 Ifaces_List
: Elist_Id
:= No_Elist
;
1797 Ifaces_Listed
: Boolean := False;
1798 -- Cache the list of interface operations inherited by R
1800 Wrappers_List
: Elist_Id
:= No_Elist
;
1801 -- List containing identifiers of built wrappers. Used to defer building
1802 -- and analyzing their class-wide precondition subprograms.
1804 -- Start of processing for Check_Inherited_Conditions
1807 if Late_Overriding
then
1808 Op_Node
:= First_Elmt
(Prim_Ops
);
1809 while Present
(Op_Node
) loop
1810 Prim
:= Node
(Op_Node
);
1812 -- Map the overridden primitive to the overriding one
1814 if Present
(Overridden_Operation
(Prim
))
1815 and then Comes_From_Source
(Prim
)
1817 Par_Prim
:= Overridden_Operation
(Prim
);
1818 Update_Primitives_Mapping
(Par_Prim
, Prim
);
1820 -- Force discarding previous mappings of its formals
1822 Map_Formals
(Par_Prim
, Prim
, Force_Update
=> True);
1825 Next_Elmt
(Op_Node
);
1829 -- Perform validity checks on the inherited conditions of overriding
1830 -- operations, for conformance with LSP, and apply SPARK-specific
1831 -- restrictions on inherited conditions.
1833 Op_Node
:= First_Elmt
(Prim_Ops
);
1834 while Present
(Op_Node
) loop
1835 Prim
:= Node
(Op_Node
);
1837 Par_Prim
:= Overridden_Operation
(Prim
);
1838 if Present
(Par_Prim
)
1839 and then Comes_From_Source
(Prim
)
1841 -- When the primitive is an LSP wrapper we climb to the parent
1842 -- primitive that has the inherited contract.
1844 if Is_Wrapper
(Par_Prim
)
1845 and then Present
(LSP_Subprogram
(Par_Prim
))
1847 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
1850 -- Check that overrider and overridden operations have
1851 -- the same strub mode.
1853 Check_Same_Strub_Mode
(Prim
, Par_Prim
);
1855 -- Analyze the contract items of the overridden operation, before
1856 -- they are rewritten as pragmas.
1858 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1860 -- In GNATprove mode this is where we can collect the inherited
1861 -- conditions, because we do not create the Check pragmas that
1862 -- normally convey the modified class-wide conditions on
1863 -- overriding operations.
1865 if GNATprove_Mode
then
1866 Collect_Inherited_Class_Wide_Conditions
(Prim
);
1870 -- Go over operations inherited from interfaces and check
1871 -- them for strub mode compatibility as well.
1873 if Has_Interfaces
(R
)
1874 and then Is_Dispatching_Operation
(Prim
)
1875 and then Find_Dispatching_Type
(Prim
) = R
1879 Iface_Elmt
: Elmt_Id
;
1881 Iface_Prim
: Entity_Id
;
1884 -- Collect the interfaces only once. We haven't
1885 -- finished freezing yet, so we can't use the faster
1886 -- search from Sem_Disp.Covered_Interface_Primitives.
1888 if not Ifaces_Listed
then
1889 Collect_Interfaces
(R
, Ifaces_List
);
1890 Ifaces_Listed
:= True;
1893 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1894 while Present
(Iface_Elmt
) loop
1895 Iface
:= Node
(Iface_Elmt
);
1897 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1898 while Present
(Elmt
) loop
1899 Iface_Prim
:= Node
(Elmt
);
1901 if Iface_Prim
/= Par_Prim
1902 and then Chars
(Iface_Prim
) = Chars
(Prim
)
1903 and then Comes_From_Source
(Iface_Prim
)
1904 and then Is_Interface_Conformant
1905 (R
, Iface_Prim
, Prim
)
1907 Check_Same_Strub_Mode
(Prim
, Iface_Prim
);
1913 Next_Elmt
(Iface_Elmt
);
1918 Next_Elmt
(Op_Node
);
1921 -- Now examine the inherited operations to check whether they require
1922 -- a wrapper to handle inherited conditions that call other primitives,
1923 -- so that LSP can be verified/enforced.
1925 Op_Node
:= First_Elmt
(Prim_Ops
);
1927 while Present
(Op_Node
) loop
1928 Decls
:= Empty_List
;
1929 Prim
:= Node
(Op_Node
);
1930 Wrapper_Needed
:= False;
1932 -- Skip internal entities built for mapping interface primitives
1934 if not Comes_From_Source
(Prim
)
1935 and then Present
(Alias
(Prim
))
1936 and then No
(Interface_Alias
(Prim
))
1938 Par_Prim
:= Ultimate_Alias
(Prim
);
1940 -- When the primitive is an LSP wrapper we climb to the parent
1941 -- primitive that has the inherited contract.
1943 if Is_Wrapper
(Par_Prim
)
1944 and then Present
(LSP_Subprogram
(Par_Prim
))
1946 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
1949 -- Analyze the contract items of the parent operation, and
1950 -- determine whether a wrapper is needed. This is determined
1951 -- when the condition is rewritten in sem_prag, using the
1952 -- mapping between overridden and overriding operations built
1953 -- in the loop above.
1955 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1956 Build_Inherited_Condition_Pragmas
(Prim
, Wrapper_Needed
);
1960 and then not Is_Abstract_Subprogram
(Par_Prim
)
1961 and then Expander_Active
1963 -- Build the dispatch-table wrapper (DTW). The support for
1964 -- AI12-0195 relies on two kind of wrappers: one for indirect
1965 -- calls (also used for AI12-0220), and one for putting in the
1968 -- 1) "indirect-call wrapper" (ICW) is needed anytime there are
1969 -- class-wide preconditions. Prim'Access will point directly
1970 -- at the ICW if any, or at the "pristine" body if Prim has
1971 -- no class-wide preconditions.
1973 -- 2) "dispatch-table wrapper" (DTW) is needed anytime the class
1974 -- wide preconditions *or* the class-wide postconditions are
1975 -- affected by overriding.
1977 -- The DTW holds a single statement that is a single call where
1978 -- the controlling actuals are conversions to the corresponding
1979 -- type in the parent primitive. If the primitive is a function
1980 -- the statement is a return statement with a call.
1983 Alias_Id
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1984 Loc
: constant Source_Ptr
:= Sloc
(R
);
1990 Prim_Next_E
: constant Entity_Id
:= Next_Entity
(Prim
);
1991 Prim_Prev_E
: constant Entity_Id
:= Prev_Entity
(Prim
);
1994 DTW_Spec
:= Build_DTW_Spec
(Par_Prim
);
1995 DTW_Id
:= Defining_Entity
(DTW_Spec
);
1996 DTW_Decl
:= Make_Subprogram_Declaration
(Loc
,
1997 Specification
=> DTW_Spec
);
1999 -- The spec of the wrapper has been built using the source
2000 -- location of its parent primitive; we must update it now
2001 -- (with the source location of the internal primitive built
2002 -- by Derive_Subprogram that will override this wrapper) to
2003 -- avoid inlining conflicts between internally built helpers
2004 -- for class-wide pre/postconditions of the parent and the
2005 -- helpers built for this wrapper.
2007 Set_Sloc
(DTW_Id
, Sloc
(Prim
));
2009 -- For inherited class-wide preconditions the DTW wrapper
2010 -- reuses the ICW of the parent (which checks the parent
2011 -- interpretation of the class-wide preconditions); the
2012 -- interpretation of the class-wide preconditions for the
2013 -- inherited subprogram is checked at the caller side.
2015 -- When the subprogram inherits class-wide postconditions
2016 -- the DTW also checks the interpretation of the class-wide
2017 -- postconditions for the inherited subprogram, and the body
2018 -- of the parent checks its interpretation of the parent for
2019 -- the class-wide postconditions.
2021 -- procedure Prim (F1 : T1; ...) is
2022 -- [ pragma Check (Postcondition, Expr); ]
2024 -- Par_Prim_ICW (Par_Type (F1), ...);
2027 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2029 Build_DTW_Body
(Loc
,
2030 DTW_Spec
=> DTW_Spec
,
2032 Par_Prim
=> Par_Prim
,
2033 Wrapped_Subp
=> Indirect_Call_Wrapper
(Par_Prim
));
2035 -- For subprograms that only inherit class-wide postconditions
2036 -- the DTW wrapper calls the parent primitive (which on its
2037 -- body checks the interpretation of the class-wide post-
2038 -- conditions for the parent subprogram), and the DTW checks
2039 -- the interpretation of the class-wide postconditions for the
2040 -- inherited subprogram.
2042 -- procedure Prim (F1 : T1; ...) is
2043 -- pragma Check (Postcondition, Expr);
2045 -- Par_Prim (Par_Type (F1), ...);
2050 Build_DTW_Body
(Loc
,
2051 DTW_Spec
=> DTW_Spec
,
2053 Par_Prim
=> Par_Prim
,
2054 Wrapped_Subp
=> Par_Prim
);
2057 -- Insert the declaration of the wrapper before the freezing
2058 -- node of the record type declaration to ensure that it will
2059 -- override the internal primitive built by Derive_Subprogram.
2061 if Late_Overriding
then
2062 Ensure_Freeze_Node
(R
);
2063 Insert_Before_And_Analyze
(Freeze_Node
(R
), DTW_Decl
);
2065 Append_Freeze_Action
(R
, DTW_Decl
);
2069 -- The analyis of DTW_Decl has removed Prim from its scope
2070 -- chain and added DTW_Id at the end of the scope chain. Move
2071 -- DTW_Id to its correct place in the scope chain: the analysis
2072 -- of the wrapper declaration has just added DTW_Id at the end
2073 -- of the list of entities of its scope. However, given that
2074 -- this wrapper overrides Prim, we must move DTW_Id to the
2075 -- original place of Prim in its scope chain. This is required
2076 -- for wrappers of private type primitives to ensure their
2077 -- correct visibility since wrappers are built when the full
2078 -- tagged type declaration is frozen (in the private part of
2079 -- the package) but they may override primitives defined in the
2080 -- public part of the package.
2083 DTW_Prev_E
: constant Entity_Id
:= Prev_Entity
(DTW_Id
);
2086 pragma Assert
(Last_Entity
(Current_Scope
) = DTW_Id
);
2088 (Ekind
(Current_Scope
) not in E_Package | E_Generic_Package
2089 or else No
(First_Private_Entity
(Current_Scope
))
2090 or else First_Private_Entity
(Current_Scope
) /= DTW_Id
);
2092 -- Remove DTW_Id from the end of the doubly-linked list of
2093 -- entities of this scope; no need to handle removing it
2094 -- from the beginning of the chain since such case can never
2095 -- occur for this entity.
2097 Set_Last_Entity
(Current_Scope
, DTW_Prev_E
);
2098 Set_Next_Entity
(DTW_Prev_E
, Empty
);
2100 -- Place DTW_Id back in the original place of its wrapped
2101 -- primitive in the list of entities of this scope.
2103 Link_Entities
(Prim_Prev_E
, DTW_Id
);
2104 Link_Entities
(DTW_Id
, Prim_Next_E
);
2107 -- Insert the body of the wrapper in the freeze actions of
2108 -- its record type declaration to ensure that it is placed
2109 -- in the scope of its declaration but not too early to cause
2110 -- premature freezing of other entities.
2112 Append_Freeze_Action
(R
, DTW_Body
);
2115 -- Ensure correct decoration
2117 pragma Assert
(Is_Dispatching_Operation
(DTW_Id
));
2118 pragma Assert
(Present
(Overridden_Operation
(DTW_Id
)));
2119 pragma Assert
(Overridden_Operation
(DTW_Id
) = Alias_Id
);
2121 -- Inherit dispatch table slot
2123 Set_DTC_Entity_Value
(R
, DTW_Id
);
2124 Set_DT_Position
(DTW_Id
, DT_Position
(Alias_Id
));
2126 -- Register the wrapper in the dispatch table
2129 and then not Building_Static_DT
(R
)
2131 Insert_List_After_And_Analyze
(Freeze_Node
(R
),
2132 Register_Primitive
(Loc
, DTW_Id
));
2135 -- Defer building helpers and ICW for the DTW. Required to
2136 -- ensure uniqueness in their names because when building
2137 -- these wrappers for overlapped subprograms their homonym
2138 -- number is not definite until all these dispatch table
2139 -- wrappers of tagged type R have been analyzed.
2141 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2142 Append_New_Elmt
(DTW_Id
, Wrappers_List
);
2147 Next_Elmt
(Op_Node
);
2150 -- Build and analyze deferred class-wide precondition subprograms of
2153 if Present
(Wrappers_List
) then
2156 CW_Subp
: Entity_Id
;
2162 Elmt
:= First_Elmt
(Wrappers_List
);
2164 while Present
(Elmt
) loop
2165 DTW_Id
:= Node
(Elmt
);
2168 Merge_Class_Conditions
(DTW_Id
);
2169 Make_Class_Precondition_Subps
(DTW_Id
, Late_Overriding
);
2171 CW_Subp
:= Static_Call_Helper
(DTW_Id
);
2172 Decl_N
:= Unit_Declaration_Node
(CW_Subp
);
2175 -- If the DTW was built for a late-overriding primitive
2176 -- its body must be analyzed now (since the tagged type
2177 -- is already frozen).
2179 if Late_Overriding
then
2181 Unit_Declaration_Node
(Corresponding_Body
(Decl_N
));
2187 end Check_Inherited_Conditions
;
2189 ----------------------------
2190 -- Check_Strict_Alignment --
2191 ----------------------------
2193 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
2197 -- Bit-packed array types do not require strict alignment, even if they
2198 -- are by-reference types, because they are accessed in a special way.
2200 if Is_By_Reference_Type
(E
) and then not Is_Bit_Packed_Array
(E
) then
2201 Set_Strict_Alignment
(E
);
2203 elsif Is_Array_Type
(E
) then
2204 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
2206 -- ??? AI12-001: Any component of a packed type that contains an
2207 -- aliased part must be aligned according to the alignment of its
2208 -- subtype (RM 13.2(7)). This means that the following test:
2210 -- if Has_Aliased_Components (E) then
2211 -- Set_Strict_Alignment (E);
2214 -- should be implemented here. Unfortunately it would break Florist,
2215 -- which has the bad habit of overaligning all the types it declares
2216 -- on 32-bit platforms. Other legacy codebases could also be affected
2217 -- because this check has historically been missing in GNAT.
2219 elsif Is_Record_Type
(E
) then
2220 Comp
:= First_Component
(E
);
2221 while Present
(Comp
) loop
2222 if not Is_Type
(Comp
)
2223 and then (Is_Aliased
(Comp
)
2224 or else Strict_Alignment
(Etype
(Comp
)))
2226 Set_Strict_Alignment
(E
);
2230 Next_Component
(Comp
);
2233 end Check_Strict_Alignment
;
2235 -------------------------
2236 -- Check_Unsigned_Type --
2237 -------------------------
2239 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
2240 Ancestor
: Entity_Id
;
2245 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
2249 -- Do not attempt to analyze case where range was in error
2251 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
2255 -- The situation that is nontrivial is something like:
2257 -- subtype x1 is integer range -10 .. +10;
2258 -- subtype x2 is x1 range 0 .. V1;
2259 -- subtype x3 is x2 range V2 .. V3;
2260 -- subtype x4 is x3 range V4 .. V5;
2262 -- where Vn are variables. Here the base type is signed, but we still
2263 -- know that x4 is unsigned because of the lower bound of x2.
2265 -- The only way to deal with this is to look up the ancestor chain
2269 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
2273 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
2275 if Compile_Time_Known_Value
(Lo_Bound
) then
2276 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
2277 Set_Is_Unsigned_Type
(E
, True);
2283 Ancestor
:= Ancestor_Subtype
(Ancestor
);
2285 -- If no ancestor had a static lower bound, go to base type
2287 if No
(Ancestor
) then
2289 -- Note: the reason we still check for a compile time known
2290 -- value for the base type is that at least in the case of
2291 -- generic formals, we can have bounds that fail this test,
2292 -- and there may be other cases in error situations.
2294 Btyp
:= Base_Type
(E
);
2296 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
2300 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
2302 if Compile_Time_Known_Value
(Lo_Bound
)
2303 and then Expr_Rep_Value
(Lo_Bound
) >= 0
2305 Set_Is_Unsigned_Type
(E
, True);
2312 end Check_Unsigned_Type
;
2314 -----------------------------------------------
2315 -- Explode_Initialization_Compound_Statement --
2316 -----------------------------------------------
2318 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
2319 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
2322 if Present
(Init_Stmts
)
2323 and then Nkind
(Init_Stmts
) = N_Compound_Statement
2325 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
2327 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
2328 -- just removing it, because Freeze_All may rely on this particular
2329 -- Node_Id still being present in the enclosing list to know where to
2332 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
2334 Set_Initialization_Statements
(E
, Empty
);
2336 end Explode_Initialization_Compound_Statement
;
2342 -- Note: the easy coding for this procedure would be to just build a
2343 -- single list of freeze nodes and then insert them and analyze them
2344 -- all at once. This won't work, because the analysis of earlier freeze
2345 -- nodes may recursively freeze types which would otherwise appear later
2346 -- on in the freeze list. So we must analyze and expand the freeze nodes
2347 -- as they are generated.
2349 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
2350 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
2351 -- This is the internal recursive routine that does freezing of entities
2352 -- (but NOT the analysis of default expressions, which should not be
2353 -- recursive, we don't want to analyze those till we are sure that ALL
2354 -- the types are frozen).
2356 --------------------
2357 -- Freeze_All_Ent --
2358 --------------------
2360 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
2364 procedure Process_Flist
;
2365 -- If freeze nodes are present, insert and analyze, and reset cursor
2366 -- for next insertion.
2372 procedure Process_Flist
is
2375 if Is_Non_Empty_List
(Flist
) then
2376 Lastn
:= Next
(After
);
2377 Insert_List_After_And_Analyze
(After
, Flist
);
2379 if Present
(Lastn
) then
2380 After
:= Prev
(Lastn
);
2382 After
:= Last
(List_Containing
(After
));
2387 -- Start of processing for Freeze_All_Ent
2391 while Present
(E
) loop
2393 -- If the entity is an inner package which is not a package
2394 -- renaming, then its entities must be frozen at this point. Note
2395 -- that such entities do NOT get frozen at the end of the nested
2396 -- package itself (only library packages freeze).
2398 -- Same is true for task declarations, where anonymous records
2399 -- created for entry parameters must be frozen.
2401 if Ekind
(E
) = E_Package
2402 and then No
(Renamed_Entity
(E
))
2403 and then not Is_Child_Unit
(E
)
2404 and then not Is_Frozen
(E
)
2408 Install_Visible_Declarations
(E
);
2409 Install_Private_Declarations
(E
);
2410 Freeze_All
(First_Entity
(E
), After
);
2412 End_Package_Scope
(E
);
2414 if Is_Generic_Instance
(E
)
2415 and then Has_Delayed_Freeze
(E
)
2417 Set_Has_Delayed_Freeze
(E
, False);
2418 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
2421 elsif Ekind
(E
) in Task_Kind
2422 and then Nkind
(Parent
(E
)) in
2423 N_Single_Task_Declaration | N_Task_Type_Declaration
2426 Freeze_All
(First_Entity
(E
), After
);
2429 -- For a derived tagged type, we must ensure that all the
2430 -- primitive operations of the parent have been frozen, so that
2431 -- their addresses will be in the parent's dispatch table at the
2432 -- point it is inherited.
2434 elsif Ekind
(E
) = E_Record_Type
2435 and then Is_Tagged_Type
(E
)
2436 and then Is_Tagged_Type
(Etype
(E
))
2437 and then Is_Derived_Type
(E
)
2440 Prim_List
: constant Elist_Id
:=
2441 Primitive_Operations
(Etype
(E
));
2447 Prim
:= First_Elmt
(Prim_List
);
2448 while Present
(Prim
) loop
2449 Subp
:= Node
(Prim
);
2451 if Comes_From_Source
(Subp
)
2452 and then not Is_Frozen
(Subp
)
2454 Flist
:= Freeze_Entity
(Subp
, After
);
2463 if not Is_Frozen
(E
) then
2464 Flist
:= Freeze_Entity
(E
, After
);
2467 -- If already frozen, and there are delayed aspects, this is where
2468 -- we do the visibility check for these aspects (see Sem_Ch13 spec
2469 -- for a description of how we handle aspect visibility).
2471 elsif Has_Delayed_Aspects
(E
) then
2476 Ritem
:= First_Rep_Item
(E
);
2477 while Present
(Ritem
) loop
2478 if Nkind
(Ritem
) = N_Aspect_Specification
2479 and then Entity
(Ritem
) = E
2480 and then Is_Delayed_Aspect
(Ritem
)
2482 Check_Aspect_At_End_Of_Declarations
(Ritem
);
2485 Next_Rep_Item
(Ritem
);
2490 -- If an incomplete type is still not frozen, this may be a
2491 -- premature freezing because of a body declaration that follows.
2492 -- Indicate where the freezing took place. Freezing will happen
2493 -- if the body comes from source, but not if it is internally
2494 -- generated, for example as the body of a type invariant.
2496 -- If the freezing is caused by the end of the current declarative
2497 -- part, it is a Taft Amendment type, and there is no error.
2499 if not Is_Frozen
(E
)
2500 and then Ekind
(E
) = E_Incomplete_Type
2503 Bod
: constant Node_Id
:= Next
(After
);
2506 -- The presence of a body freezes all entities previously
2507 -- declared in the current list of declarations, but this
2508 -- does not apply if the body does not come from source.
2509 -- A type invariant is transformed into a subprogram body
2510 -- which is placed at the end of the private part of the
2511 -- current package, but this body does not freeze incomplete
2512 -- types that may be declared in this private part.
2514 if Comes_From_Source
(Bod
)
2515 and then Nkind
(Bod
) in N_Entry_Body
2522 In_Same_List
(After
, Parent
(E
))
2524 Error_Msg_Sloc
:= Sloc
(Next
(After
));
2526 ("type& is frozen# before its full declaration",
2542 -- Start of processing for Freeze_All
2545 Freeze_All_Ent
(From
, After
);
2547 -- Now that all types are frozen, we can deal with default expressions
2548 -- that require us to build a default expression functions. This is the
2549 -- point at which such functions are constructed (after all types that
2550 -- might be used in such expressions have been frozen).
2552 -- For subprograms that are renaming_as_body, we create the wrapper
2553 -- bodies as needed.
2555 -- We also add finalization chains to access types whose designated
2556 -- types are controlled. This is normally done when freezing the type,
2557 -- but this misses recursive type definitions where the later members
2558 -- of the recursion introduce controlled components.
2560 -- Loop through entities
2563 while Present
(E
) loop
2564 if Is_Subprogram
(E
) then
2565 if not Default_Expressions_Processed
(E
) then
2566 Process_Default_Expressions
(E
, After
);
2569 -- Check subprogram renamings for the same strub-mode.
2570 -- Avoid rechecking dispatching operations, that's taken
2571 -- care of in Check_Inherited_Conditions, that covers
2572 -- inherited interface operations.
2576 and then not Is_Dispatching_Operation
(E
)
2578 Check_Same_Strub_Mode
(E
, Item
);
2581 if not Has_Completion
(E
) then
2582 Decl
:= Unit_Declaration_Node
(E
);
2584 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
2585 if Error_Posted
(Decl
) then
2586 Set_Has_Completion
(E
);
2588 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
2591 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2592 and then Present
(Corresponding_Body
(Decl
))
2594 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
2595 N_Subprogram_Renaming_Declaration
2597 Build_And_Analyze_Renamed_Body
2598 (Decl
, Corresponding_Body
(Decl
), After
);
2602 -- Freeze the default expressions of entries, entry families, and
2603 -- protected subprograms.
2605 elsif Is_Concurrent_Type
(E
) then
2606 Item
:= First_Entity
(E
);
2607 while Present
(Item
) loop
2608 if Is_Subprogram_Or_Entry
(Item
)
2609 and then not Default_Expressions_Processed
(Item
)
2611 Process_Default_Expressions
(Item
, After
);
2618 -- Historical note: We used to create a finalization master for an
2619 -- access type whose designated type is not controlled, but contains
2620 -- private controlled compoments. This form of postprocessing is no
2621 -- longer needed because the finalization master is now created when
2622 -- the access type is frozen (see Exp_Ch3.Freeze_Type).
2628 -----------------------
2629 -- Freeze_And_Append --
2630 -----------------------
2632 procedure Freeze_And_Append
2635 Result
: in out List_Id
)
2637 -- Freezing an Expression_Function does not freeze its profile:
2638 -- the formals will have been frozen otherwise before the E_F
2641 L
: constant List_Id
:=
2643 (Ent
, N
, Do_Freeze_Profile
=> not Is_Expression_Function
(Ent
));
2645 if Is_Non_Empty_List
(L
) then
2646 if Result
= No_List
then
2649 Append_List
(L
, Result
);
2652 end Freeze_And_Append
;
2658 procedure Freeze_Before
2661 Do_Freeze_Profile
: Boolean := True)
2663 -- Freeze T, then insert the generated Freeze nodes before the node N.
2664 -- Flag Freeze_Profile is used when T is an overloadable entity, and
2665 -- indicates whether its profile should be frozen at the same time.
2667 Freeze_Nodes
: constant List_Id
:=
2668 Freeze_Entity
(T
, N
, Do_Freeze_Profile
);
2669 Pack
: constant Entity_Id
:= Scope
(T
);
2672 if Ekind
(T
) = E_Function
then
2673 Check_Expression_Function
(N
, T
);
2676 if Is_Non_Empty_List
(Freeze_Nodes
) then
2678 -- If the entity is a type declared in an inner package, it may be
2679 -- frozen by an outer declaration before the package itself is
2680 -- frozen. Install the package scope to analyze the freeze nodes,
2681 -- which may include generated subprograms such as predicate
2684 if Is_Type
(T
) and then From_Nested_Package
(T
) then
2686 Install_Visible_Declarations
(Pack
);
2687 Install_Private_Declarations
(Pack
);
2688 Insert_Actions
(N
, Freeze_Nodes
);
2689 End_Package_Scope
(Pack
);
2692 Insert_Actions
(N
, Freeze_Nodes
);
2701 -- WARNING: This routine manages Ghost regions. Return statements must be
2702 -- replaced by gotos which jump to the end of the routine and restore the
2705 function Freeze_Entity
2708 Do_Freeze_Profile
: Boolean := True) return List_Id
2710 Loc
: constant Source_Ptr
:= Sloc
(N
);
2712 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2713 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
2714 -- Save the Ghost-related attributes to restore on exit
2722 Result
: List_Id
:= No_List
;
2723 -- List of freezing actions, left at No_List if none
2725 Test_E
: Entity_Id
:= E
;
2726 -- A local temporary used to test if freezing is necessary for E, since
2727 -- its value can be set to something other than E in certain cases. For
2728 -- example, E cannot be used directly in cases such as when it is an
2729 -- Itype defined within a record - since it is the location of record
2732 procedure Add_To_Result
(Fnod
: Node_Id
);
2733 -- Add freeze action Fnod to list Result
2735 function After_Last_Declaration
return Boolean;
2736 -- If Loc is a freeze_entity that appears after the last declaration
2737 -- in the scope, inhibit error messages on late completion.
2739 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
2740 -- Check that an Access or Unchecked_Access attribute with a prefix
2741 -- which is the current instance type can only be applied when the type
2744 procedure Check_No_Parts_Violations
2745 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
) with
2746 Pre
=> Aspect_No_Parts
in
2747 Aspect_No_Controlled_Parts | Aspect_No_Task_Parts
;
2748 -- Check that Typ does not violate the semantics of the specified
2749 -- Aspect_No_Parts (No_Controlled_Parts or No_Task_Parts) when it is
2750 -- specified on Typ or one of its ancestors.
2752 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
);
2753 -- Give a warning for pragma Convention with language C or C++ applied
2754 -- to a discriminated record type. This is suppressed for the unchecked
2755 -- union case, since the whole point in this case is interface C. We
2756 -- also do not generate this within instantiations, since we will have
2757 -- generated a message on the template.
2759 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
2760 -- Give warning for modulus of 8, 16, 32, 64 or 128 given as an explicit
2761 -- integer literal without an explicit corresponding size clause. The
2762 -- caller has checked that Utype is a modular integer type.
2764 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
2765 -- Freeze array type, including freezing index and component types
2767 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
2768 -- Perform checks and generate freeze node if needed for a constant or
2769 -- variable declared by an object declaration.
2771 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
2772 -- Create Freeze_Generic_Entity nodes for types declared in a generic
2773 -- package. Recurse on inner generic packages.
2775 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
2776 -- Freeze formals and return type of subprogram. If some type in the
2777 -- profile is incomplete and we are in an instance, freezing of the
2778 -- entity will take place elsewhere, and the function returns False.
2780 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
2781 -- Freeze record type, including freezing component types, and freezing
2782 -- primitive operations if this is a tagged type.
2784 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
2785 -- Determine whether an arbitrary entity is subject to Boolean aspect
2786 -- Import and its value is specified as True.
2788 procedure Inherit_Freeze_Node
2791 -- Set type Typ's freeze node to refer to Fnode. This routine ensures
2792 -- that any attributes attached to Typ's original node are preserved.
2794 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
2795 -- If E is an entity for an imported subprogram with pre/post-conditions
2796 -- then this procedure will create a wrapper to ensure that proper run-
2797 -- time checking of the pre/postconditions. See body for details.
2803 procedure Add_To_Result
(Fnod
: Node_Id
) is
2805 Append_New_To
(Result
, Fnod
);
2808 ----------------------------
2809 -- After_Last_Declaration --
2810 ----------------------------
2812 function After_Last_Declaration
return Boolean is
2813 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2816 if Nkind
(Spec
) = N_Package_Specification
then
2817 if Present
(Private_Declarations
(Spec
)) then
2818 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2819 elsif Present
(Visible_Declarations
(Spec
)) then
2820 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2828 end After_Last_Declaration
;
2830 ----------------------------
2831 -- Check_Current_Instance --
2832 ----------------------------
2834 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2836 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2837 -- Determine whether Typ is compatible with the rules for aliased
2838 -- views of types as defined in RM 3.10 in the various dialects.
2840 function Process
(N
: Node_Id
) return Traverse_Result
;
2841 -- Process routine to apply check to given node
2843 -----------------------------
2844 -- Is_Aliased_View_Of_Type --
2845 -----------------------------
2847 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
2848 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
2853 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
2854 and then Limited_Present
(Type_Definition
(Typ_Decl
))
2858 -- The following paragraphs describe what a legal aliased view of
2859 -- a type is in the various dialects of Ada.
2863 -- The current instance of a limited type, and a formal parameter
2864 -- or generic formal object of a tagged type.
2866 -- Ada 95 limited type
2867 -- * Type with reserved word "limited"
2868 -- * A protected or task type
2869 -- * A composite type with limited component
2871 elsif Ada_Version
<= Ada_95
then
2872 return Is_Limited_Type
(Typ
);
2876 -- The current instance of a limited tagged type, a protected
2877 -- type, a task type, or a type that has the reserved word
2878 -- "limited" in its full definition ... a formal parameter or
2879 -- generic formal object of a tagged type.
2881 -- Ada 2005 limited type
2882 -- * Type with reserved word "limited", "synchronized", "task"
2884 -- * A composite type with limited component
2885 -- * A derived type whose parent is a non-interface limited type
2887 elsif Ada_Version
= Ada_2005
then
2889 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2891 (Is_Derived_Type
(Typ
)
2892 and then not Is_Interface
(Etype
(Typ
))
2893 and then Is_Limited_Type
(Etype
(Typ
)));
2895 -- Ada 2012 and beyond
2897 -- The current instance of an immutably limited type ... a formal
2898 -- parameter or generic formal object of a tagged type.
2900 -- Ada 2012 limited type
2901 -- * Type with reserved word "limited", "synchronized", "task"
2903 -- * A composite type with limited component
2904 -- * A derived type whose parent is a non-interface limited type
2905 -- * An incomplete view
2907 -- Ada 2012 immutably limited type
2908 -- * Explicitly limited record type
2909 -- * Record extension with "limited" present
2910 -- * Non-formal limited private type that is either tagged
2911 -- or has at least one access discriminant with a default
2913 -- * Task type, protected type or synchronized interface
2914 -- * Type derived from immutably limited type
2918 Is_Immutably_Limited_Type
(Typ
)
2919 or else Is_Incomplete_Type
(Typ
);
2921 end Is_Aliased_View_Of_Type
;
2927 function Process
(N
: Node_Id
) return Traverse_Result
is
2930 when N_Attribute_Reference
=>
2931 if Attribute_Name
(N
) in Name_Access | Name_Unchecked_Access
2932 and then Is_Entity_Name
(Prefix
(N
))
2933 and then Is_Type
(Entity
(Prefix
(N
)))
2934 and then Entity
(Prefix
(N
)) = E
2936 if Ada_Version
< Ada_2012
then
2938 ("current instance must be a limited type",
2942 ("current instance must be an immutably limited "
2943 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2957 procedure Traverse
is new Traverse_Proc
(Process
);
2961 Rec_Type
: constant Entity_Id
:=
2962 Scope
(Defining_Identifier
(Comp_Decl
));
2964 -- Start of processing for Check_Current_Instance
2967 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2968 Traverse
(Comp_Decl
);
2970 end Check_Current_Instance
;
2972 -------------------------------
2973 -- Check_No_Parts_Violations --
2974 -------------------------------
2976 procedure Check_No_Parts_Violations
2977 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
)
2980 function Find_Aspect_No_Parts
2981 (Typ
: Entity_Id
) return Node_Id
;
2982 -- Search for Aspect_No_Parts on a given type. When
2983 -- the aspect is not explicity specified Empty is returned.
2985 function Get_Aspect_No_Parts_Value
2986 (Typ
: Entity_Id
) return Entity_Id
;
2987 -- Obtain the value for the Aspect_No_Parts on a given
2988 -- type. When the aspect is not explicitly specified Empty is
2991 function Has_Aspect_No_Parts
2992 (Typ
: Entity_Id
) return Boolean;
2993 -- Predicate function which identifies whether No_Parts
2994 -- is explicitly specified on a given type.
2996 -------------------------------------
2997 -- Find_Aspect_No_Parts --
2998 -------------------------------------
3000 function Find_Aspect_No_Parts
3001 (Typ
: Entity_Id
) return Node_Id
3003 Partial_View
: constant Entity_Id
:=
3004 Incomplete_Or_Partial_View
(Typ
);
3006 Aspect_Spec
: Entity_Id
:=
3007 Find_Aspect
(Typ
, Aspect_No_Parts
);
3008 Curr_Aspect_Spec
: Entity_Id
;
3011 -- Examine Typ's associated node, when present, since aspect
3012 -- specifications do not get transferred when nodes get rewritten.
3014 -- For example, this can happen in the expansion of array types
3017 and then Present
(Associated_Node_For_Itype
(Typ
))
3018 and then Nkind
(Associated_Node_For_Itype
(Typ
))
3019 = N_Full_Type_Declaration
3023 (Id
=> Defining_Identifier
3024 (Associated_Node_For_Itype
(Typ
)),
3025 A
=> Aspect_No_Parts
);
3028 -- Examine aspects specifications on private type declarations
3030 -- Should Find_Aspect be improved to handle this case ???
3033 and then Present
(Partial_View
)
3035 (Aspect_Specifications
3041 (Aspect_Specifications
3045 -- Search through aspects present on the private type
3047 while Present
(Curr_Aspect_Spec
) loop
3048 if Get_Aspect_Id
(Curr_Aspect_Spec
)
3051 Aspect_Spec
:= Curr_Aspect_Spec
;
3055 Next
(Curr_Aspect_Spec
);
3060 -- When errors are posted on the aspect return Empty
3062 if Error_Posted
(Aspect_Spec
) then
3067 end Find_Aspect_No_Parts
;
3069 ------------------------------------------
3070 -- Get_Aspect_No_Parts_Value --
3071 ------------------------------------------
3073 function Get_Aspect_No_Parts_Value
3074 (Typ
: Entity_Id
) return Entity_Id
3076 Aspect_Spec
: constant Entity_Id
:=
3077 Find_Aspect_No_Parts
(Typ
);
3080 -- Return the value of the aspect when present
3082 if Present
(Aspect_Spec
) then
3084 -- No expression is the same as True
3086 if No
(Expression
(Aspect_Spec
)) then
3087 return Standard_True
;
3090 -- Assume its expression has already been constant folded into
3091 -- a Boolean value and return its value.
3093 return Entity
(Expression
(Aspect_Spec
));
3096 -- Otherwise, the aspect is not specified - so return Empty
3099 end Get_Aspect_No_Parts_Value
;
3101 ------------------------------------
3102 -- Has_Aspect_No_Parts --
3103 ------------------------------------
3105 function Has_Aspect_No_Parts
3106 (Typ
: Entity_Id
) return Boolean
3107 is (Present
(Find_Aspect_No_Parts
(Typ
)));
3109 -- Generic instances
3111 -------------------------------------------
3112 -- Get_Generic_Formal_Types_In_Hierarchy --
3113 -------------------------------------------
3115 function Get_Generic_Formal_Types_In_Hierarchy
3116 is new Collect_Types_In_Hierarchy
(Predicate
=> Is_Generic_Formal
);
3117 -- Return a list of all types within a given type's hierarchy which
3118 -- are generic formals.
3120 ----------------------------------------
3121 -- Get_Types_With_Aspect_In_Hierarchy --
3122 ----------------------------------------
3124 function Get_Types_With_Aspect_In_Hierarchy
3125 is new Collect_Types_In_Hierarchy
3126 (Predicate
=> Has_Aspect_No_Parts
);
3127 -- Returns a list of all types within a given type's hierarchy which
3128 -- have the Aspect_No_Parts specified.
3130 -- Local declarations
3132 Aspect_Value
: Entity_Id
;
3133 Curr_Value
: Entity_Id
;
3134 Curr_Typ_Elmt
: Elmt_Id
;
3135 Curr_Body_Elmt
: Elmt_Id
;
3136 Curr_Formal_Elmt
: Elmt_Id
;
3137 Gen_Bodies
: Elist_Id
;
3138 Gen_Formals
: Elist_Id
;
3140 Types_With_Aspect
: Elist_Id
;
3142 -- Start of processing for Check_No_Parts_Violations
3145 -- Nothing to check if the type is elementary or artificial
3147 if Is_Elementary_Type
(Typ
) or else not Comes_From_Source
(Typ
) then
3151 Types_With_Aspect
:= Get_Types_With_Aspect_In_Hierarchy
(Typ
);
3153 -- Nothing to check if there are no types with No_Parts specified
3155 if Is_Empty_Elmt_List
(Types_With_Aspect
) then
3159 -- Set name for all errors below
3161 Error_Msg_Name_1
:= Aspect_Names
(Aspect_No_Parts
);
3163 -- Obtain the aspect value for No_Parts for comparison
3166 Get_Aspect_No_Parts_Value
3167 (Node
(First_Elmt
(Types_With_Aspect
)));
3169 -- When the value is True and there are controlled/task parts or the
3170 -- type itself is controlled/task, trigger the appropriate error.
3172 if Aspect_Value
= Standard_True
then
3173 if Aspect_No_Parts
= Aspect_No_Controlled_Parts
then
3174 if Is_Controlled
(Typ
) or else Has_Controlled_Component
(Typ
)
3177 ("aspect % applied to controlled type &", Typ
);
3180 elsif Aspect_No_Parts
= Aspect_No_Task_Parts
then
3181 if Has_Task
(Typ
) then
3183 ("aspect % applied to task type &", Typ
);
3185 ("\replace task components with access-to-task-type "
3186 & "components??", Typ
);
3190 raise Program_Error
;
3194 -- Move through Types_With_Aspect - checking that the value specified
3195 -- for their corresponding Aspect_No_Parts do not override each
3198 Curr_Typ_Elmt
:= First_Elmt
(Types_With_Aspect
);
3199 while Present
(Curr_Typ_Elmt
) loop
3201 Get_Aspect_No_Parts_Value
(Node
(Curr_Typ_Elmt
));
3203 -- Compare the aspect value against the current type
3205 if Curr_Value
/= Aspect_Value
then
3207 ("cannot override aspect % of "
3208 & "ancestor type &", Typ
, Node
(Curr_Typ_Elmt
));
3212 Next_Elmt
(Curr_Typ_Elmt
);
3215 -- Issue an error if the aspect applies to a type declared inside a
3216 -- generic body and if said type derives from or has a component
3217 -- of ageneric formal type - since those are considered to have
3218 -- controlled/task parts and have Aspect_No_Parts specified as
3219 -- False by default (RM H.4.1(4/5) is about the language-defined
3220 -- No_Controlled_Parts aspect, and we are using the same rules for
3223 -- We do not check tagged types since deriving from a formal type
3224 -- within an enclosing generic unit is already illegal
3225 -- (RM 3.9.1 (4/2)).
3227 if Aspect_Value
= Standard_True
3228 and then In_Generic_Body
(Typ
)
3229 and then not Is_Tagged_Type
(Typ
)
3231 Gen_Bodies
:= New_Elmt_List
;
3233 Get_Generic_Formal_Types_In_Hierarchy
3235 Examine_Components
=> True);
3237 -- Climb scopes collecting generic bodies
3239 Scop
:= Scope
(Typ
);
3240 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
3242 -- Generic package body
3244 if Ekind
(Scop
) = E_Generic_Package
3245 and then In_Package_Body
(Scop
)
3247 Append_Elmt
(Scop
, Gen_Bodies
);
3249 -- Generic subprogram body
3251 elsif Is_Generic_Subprogram
(Scop
) then
3252 Append_Elmt
(Scop
, Gen_Bodies
);
3255 Scop
:= Scope
(Scop
);
3258 -- Warn about the improper use of Aspect_No_Parts on a type
3259 -- declaration deriving from or that has a component of a generic
3260 -- formal type within the formal type's corresponding generic
3261 -- body by moving through all formal types in Typ's hierarchy and
3262 -- checking if they are formals in any of the enclosing generic
3265 -- However, a special exception gets made for formal types which
3266 -- derive from a type which has Aspect_No_Parts True.
3271 -- type Form is private;
3273 -- type Type_A is new Form with No_Controlled_Parts; -- OK
3276 -- package body G is
3277 -- type Type_B is new Form with No_Controlled_Parts; -- ERROR
3281 -- type Form is private;
3283 -- type Type_A is record C : Form; end record
3284 -- with No_Controlled_Parts; -- OK
3287 -- package body G is
3288 -- type Type_B is record C : Form; end record
3289 -- with No_Controlled_Parts; -- ERROR
3292 -- type Root is tagged null record with No_Controlled_Parts;
3295 -- type Form is new Root with private;
3297 -- type Type_A is record C : Form; end record
3298 -- with No_Controlled_Parts; -- OK
3301 -- package body G is
3302 -- type Type_B is record C : Form; end record
3303 -- with No_Controlled_Parts; -- OK
3306 Curr_Formal_Elmt
:= First_Elmt
(Gen_Formals
);
3307 while Present
(Curr_Formal_Elmt
) loop
3309 Curr_Body_Elmt
:= First_Elmt
(Gen_Bodies
);
3310 while Present
(Curr_Body_Elmt
) loop
3312 -- Obtain types in the formal type's hierarchy which have
3313 -- the aspect specified.
3315 Types_With_Aspect
:=
3316 Get_Types_With_Aspect_In_Hierarchy
3317 (Node
(Curr_Formal_Elmt
));
3319 -- We found a type declaration in a generic body where both
3320 -- Aspect_No_Parts is true and one of its ancestors is a
3321 -- generic formal type.
3323 if Scope
(Node
(Curr_Formal_Elmt
)) =
3324 Node
(Curr_Body_Elmt
)
3326 -- Check that no ancestors of the formal type have
3327 -- Aspect_No_Parts True before issuing the error.
3329 and then (Is_Empty_Elmt_List
(Types_With_Aspect
)
3331 Get_Aspect_No_Parts_Value
3332 (Node
(First_Elmt
(Types_With_Aspect
)))
3335 Error_Msg_Node_1
:= Typ
;
3336 Error_Msg_Node_2
:= Node
(Curr_Formal_Elmt
);
3338 ("aspect % cannot be applied to "
3339 & "type & which has an ancestor or component of "
3340 & "formal type & within the formal type's "
3341 & "corresponding generic body", Sloc
(Typ
));
3344 Next_Elmt
(Curr_Body_Elmt
);
3347 Next_Elmt
(Curr_Formal_Elmt
);
3350 end Check_No_Parts_Violations
;
3352 ---------------------------------
3353 -- Check_Suspicious_Convention --
3354 ---------------------------------
3356 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
) is
3358 if Has_Discriminants
(Rec_Type
)
3359 and then Is_Base_Type
(Rec_Type
)
3360 and then not Is_Unchecked_Union
(Rec_Type
)
3361 and then (Convention
(Rec_Type
) = Convention_C
3363 Convention
(Rec_Type
) = Convention_CPP
)
3364 and then Comes_From_Source
(Rec_Type
)
3365 and then not In_Instance
3366 and then not Has_Warnings_Off
(Rec_Type
)
3369 Cprag
: constant Node_Id
:=
3370 Get_Rep_Pragma
(Rec_Type
, Name_Convention
);
3374 if Present
(Cprag
) then
3375 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3377 if Convention
(Rec_Type
) = Convention_C
then
3379 ("?x?discriminated record has no direct equivalent in "
3383 ("?x?discriminated record has no direct equivalent in "
3388 ("\?x?use of convention for type& is dubious",
3393 end Check_Suspicious_Convention
;
3395 ------------------------------
3396 -- Check_Suspicious_Modulus --
3397 ------------------------------
3399 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
3400 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
3403 if not Warn_On_Suspicious_Modulus_Value
then
3407 if Nkind
(Decl
) = N_Full_Type_Declaration
then
3409 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
3412 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
3414 Modulus
: constant Node_Id
:=
3415 Original_Node
(Expression
(Tdef
));
3418 if Nkind
(Modulus
) = N_Integer_Literal
then
3420 Modv
: constant Uint
:= Intval
(Modulus
);
3421 Sizv
: constant Uint
:= RM_Size
(Utype
);
3424 -- First case, modulus and size are the same. This
3425 -- happens if you have something like mod 32, with
3426 -- an explicit size of 32, this is for sure a case
3427 -- where the warning is given, since it is seems
3428 -- very unlikely that someone would want e.g. a
3429 -- five bit type stored in 32 bits. It is much
3430 -- more likely they wanted a 32-bit type.
3435 -- Second case, the modulus is 32 or 64 and no
3436 -- size clause is present. This is a less clear
3437 -- case for giving the warning, but in the case
3438 -- of 32/64 (5-bit or 6-bit types) these seem rare
3439 -- enough that it is a likely error (and in any
3440 -- case using 2**5 or 2**6 in these cases seems
3441 -- clearer. We don't include 8 or 16 here, simply
3442 -- because in practice 3-bit and 4-bit types are
3443 -- more common and too many false positives if
3444 -- we warn in these cases.
3446 elsif not Has_Size_Clause
(Utype
)
3447 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
3451 -- No warning needed
3457 -- If we fall through, give warning
3459 Error_Msg_Uint_1
:= Modv
;
3461 ("?.m?2 '*'*^' may have been intended here",
3469 end Check_Suspicious_Modulus
;
3471 -----------------------
3472 -- Freeze_Array_Type --
3473 -----------------------
3475 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
3476 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
3477 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
3480 Non_Standard_Enum
: Boolean := False;
3481 -- Set true if any of the index types is an enumeration type with a
3482 -- non-standard representation.
3485 Freeze_And_Append
(Ctyp
, N
, Result
);
3487 Indx
:= First_Index
(Arr
);
3488 while Present
(Indx
) loop
3489 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
3491 if Is_Enumeration_Type
(Etype
(Indx
))
3492 and then Has_Non_Standard_Rep
(Etype
(Indx
))
3494 Non_Standard_Enum
:= True;
3500 -- Processing that is done only for base types
3502 if Ekind
(Arr
) = E_Array_Type
then
3504 -- Deal with default setting of reverse storage order
3506 Set_SSO_From_Default
(Arr
);
3508 -- Propagate flags for component type
3510 if Is_Controlled
(Ctyp
)
3511 or else Has_Controlled_Component
(Ctyp
)
3513 Set_Has_Controlled_Component
(Arr
);
3516 if Has_Unchecked_Union
(Ctyp
) then
3517 Set_Has_Unchecked_Union
(Arr
);
3520 -- The array type requires its own invariant procedure in order to
3521 -- verify the component invariant over all elements. In GNATprove
3522 -- mode, the component invariants are checked by other means. They
3523 -- should not be added to the array type invariant procedure, so
3524 -- that the procedure can be used to check the array type
3525 -- invariants if any.
3527 if Has_Invariants
(Ctyp
)
3528 and then not GNATprove_Mode
3530 Set_Has_Own_Invariants
(Arr
);
3533 -- Warn for pragma Pack overriding foreign convention
3535 if Has_Foreign_Convention
(Ctyp
)
3536 and then Has_Pragma_Pack
(Arr
)
3539 CN
: constant Name_Id
:=
3540 Get_Convention_Name
(Convention
(Ctyp
));
3541 PP
: constant Node_Id
:=
3542 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
3544 if Present
(PP
) then
3545 Error_Msg_Name_1
:= CN
;
3546 Error_Msg_Sloc
:= Sloc
(Arr
);
3548 ("pragma Pack affects convention % components #??", PP
);
3549 Error_Msg_Name_1
:= CN
;
3551 ("\array components may not have % compatible "
3552 & "representation??", PP
);
3557 -- Check for Aliased or Atomic_Components or Full Access with
3558 -- unsuitable packing or explicit component size clause given.
3560 if (Has_Aliased_Components
(Arr
)
3561 or else Has_Atomic_Components
(Arr
)
3562 or else Is_Full_Access
(Ctyp
))
3564 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
3566 Alias_Atomic_Check
: declare
3568 procedure Complain_CS
(T
: String);
3569 -- Outputs error messages for incorrect CS clause or pragma
3570 -- Pack for aliased or full access components (T is either
3571 -- "aliased" or "atomic" or "volatile full access");
3577 procedure Complain_CS
(T
: String) is
3579 if Has_Component_Size_Clause
(Arr
) then
3581 Get_Attribute_Definition_Clause
3582 (FS
, Attribute_Component_Size
);
3585 ("incorrect component size for "
3586 & T
& " components", Clause
);
3587 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3589 ("\only allowed value is^", Clause
);
3593 ("?cannot pack " & T
& " components (RM 13.2(7))",
3594 Get_Rep_Pragma
(FS
, Name_Pack
));
3595 Set_Is_Packed
(Arr
, False);
3599 -- Start of processing for Alias_Atomic_Check
3602 -- If object size of component type isn't known, we cannot
3603 -- be sure so we defer to the back end.
3605 if not Known_Static_Esize
(Ctyp
) then
3608 -- Case where component size has no effect. First check for
3609 -- object size of component type multiple of the storage
3612 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
3614 -- OK in both packing case and component size case if RM
3615 -- size is known and static and same as the object size.
3618 ((Known_Static_RM_Size
(Ctyp
)
3619 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
3621 -- Or if we have an explicit component size clause and
3622 -- the component size and object size are equal.
3625 (Has_Component_Size_Clause
(Arr
)
3626 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
3630 elsif Has_Aliased_Components
(Arr
) then
3631 Complain_CS
("aliased");
3633 elsif Has_Atomic_Components
(Arr
)
3634 or else Is_Atomic
(Ctyp
)
3636 Complain_CS
("atomic");
3638 elsif Is_Volatile_Full_Access
(Ctyp
) then
3639 Complain_CS
("volatile full access");
3641 end Alias_Atomic_Check
;
3644 -- Check for Independent_Components/Independent with unsuitable
3645 -- packing or explicit component size clause given.
3647 if (Has_Independent_Components
(Arr
) or else Is_Independent
(Ctyp
))
3649 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
3652 -- If object size of component type isn't known, we cannot
3653 -- be sure so we defer to the back end.
3655 if not Known_Static_Esize
(Ctyp
) then
3658 -- Case where component size has no effect. First check for
3659 -- object size of component type multiple of the storage
3662 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
3664 -- OK in both packing case and component size case if RM
3665 -- size is known and multiple of the storage unit size.
3668 ((Known_Static_RM_Size
(Ctyp
)
3669 and then RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
3671 -- Or if we have an explicit component size clause and
3672 -- the component size is larger than the object size.
3675 (Has_Component_Size_Clause
(Arr
)
3676 and then Component_Size
(Arr
) >= Esize
(Ctyp
)))
3681 if Has_Component_Size_Clause
(Arr
) then
3683 Get_Attribute_Definition_Clause
3684 (FS
, Attribute_Component_Size
);
3687 ("incorrect component size for "
3688 & "independent components", Clause
);
3689 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3691 ("\minimum allowed is^", Clause
);
3695 ("?cannot pack independent components (RM 13.2(7))",
3696 Get_Rep_Pragma
(FS
, Name_Pack
));
3697 Set_Is_Packed
(Arr
, False);
3703 -- If packing was requested or if the component size was
3704 -- set explicitly, then see if bit packing is required. This
3705 -- processing is only done for base types, since all of the
3706 -- representation aspects involved are type-related.
3708 -- This is not just an optimization, if we start processing the
3709 -- subtypes, they interfere with the settings on the base type
3710 -- (this is because Is_Packed has a slightly different meaning
3711 -- before and after freezing).
3719 and then Known_Static_RM_Size
(Ctyp
)
3720 and then not Has_Component_Size_Clause
(Arr
)
3722 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
3724 elsif Known_Component_Size
(Arr
) then
3725 Csiz
:= Component_Size
(Arr
);
3727 elsif not Known_Static_Esize
(Ctyp
) then
3731 Esiz
:= Esize
(Ctyp
);
3733 -- We can set the component size if it is less than 16,
3734 -- rounding it up to the next storage unit size.
3738 elsif Esiz
<= 16 then
3744 -- Set component size up to match alignment if it would
3745 -- otherwise be less than the alignment. This deals with
3746 -- cases of types whose alignment exceeds their size (the
3747 -- padded type cases).
3749 if Csiz
/= 0 and then Known_Alignment
(Ctyp
) then
3751 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
3760 -- Case of component size that may result in bit packing
3762 if 1 <= Csiz
and then Csiz
<= System_Max_Integer_Size
then
3764 Ent
: constant Entity_Id
:=
3765 First_Subtype
(Arr
);
3766 Pack_Pragma
: constant Node_Id
:=
3767 Get_Rep_Pragma
(Ent
, Name_Pack
);
3768 Comp_Size_C
: constant Node_Id
:=
3769 Get_Attribute_Definition_Clause
3770 (Ent
, Attribute_Component_Size
);
3773 -- Warn if we have pack and component size so that the
3776 -- Note: here we must check for the presence of a
3777 -- component size before checking for a Pack pragma to
3778 -- deal with the case where the array type is a derived
3779 -- type whose parent is currently private.
3781 if Present
(Comp_Size_C
)
3782 and then Has_Pragma_Pack
(Ent
)
3783 and then Warn_On_Redundant_Constructs
3785 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
3787 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
3789 ("\?r?explicit component size given#!", Pack_Pragma
);
3790 Set_Is_Packed
(Base_Type
(Ent
), False);
3791 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
3794 -- Set component size if not already set by a component
3797 if No
(Comp_Size_C
) then
3798 Set_Component_Size
(Arr
, Csiz
);
3801 -- Check for base type of 8, 16, 32 bits, where an
3802 -- unsigned subtype has a length one less than the
3803 -- base type (e.g. Natural subtype of Integer).
3805 -- In such cases, if a component size was not set
3806 -- explicitly, then generate a warning.
3808 if Has_Pragma_Pack
(Arr
)
3809 and then No
(Comp_Size_C
)
3810 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
3811 and then Known_Esize
(Base_Type
(Ctyp
))
3812 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
3814 Error_Msg_Uint_1
:= Csiz
;
3816 if Present
(Pack_Pragma
) then
3818 ("??pragma Pack causes component size to be ^!",
3821 ("\??use Component_Size to set desired value!",
3826 -- Bit packing is never needed for 8, 16, 32, 64 or 128
3828 if Addressable
(Csiz
) then
3830 -- If the Esize of the component is known and equal to
3831 -- the component size then even packing is not needed.
3833 if Known_Static_Esize
(Ctyp
)
3834 and then Esize
(Ctyp
) = Csiz
3836 -- Here the array was requested to be packed, but
3837 -- the packing request had no effect whatsoever,
3838 -- so flag Is_Packed is reset.
3840 -- Note: semantically this means that we lose track
3841 -- of the fact that a derived type inherited pragma
3842 -- Pack that was non-effective, but that is fine.
3844 -- We regard a Pack pragma as a request to set a
3845 -- representation characteristic, and this request
3848 Set_Is_Packed
(Base_Type
(Arr
), False);
3849 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
3851 Set_Is_Packed
(Base_Type
(Arr
), True);
3852 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3855 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3857 -- Bit packing is not needed for multiples of the storage
3858 -- unit if the type is composite because the back end can
3859 -- byte pack composite types efficiently. That's not true
3860 -- for discrete types because every read would generate a
3861 -- lot of instructions, so we keep using the manipulation
3862 -- routines of the runtime for them.
3864 elsif Csiz
mod System_Storage_Unit
= 0
3865 and then Is_Composite_Type
(Ctyp
)
3867 Set_Is_Packed
(Base_Type
(Arr
), True);
3868 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3869 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3871 -- In all other cases, bit packing is needed
3874 Set_Is_Packed
(Base_Type
(Arr
), True);
3875 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3876 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
3882 -- Warn for case of atomic type
3884 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
3887 and then not Addressable
(Component_Size
(FS
))
3890 ("non-atomic components of type& may not be "
3891 & "accessible by separate tasks??", Clause
, Arr
);
3893 if Has_Component_Size_Clause
(Arr
) then
3894 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
3895 (FS
, Attribute_Component_Size
));
3896 Error_Msg_N
("\because of component size clause#??", Clause
);
3898 elsif Has_Pragma_Pack
(Arr
) then
3899 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
3900 Error_Msg_N
("\because of pragma Pack#??", Clause
);
3904 -- Check for scalar storage order
3909 Check_Component_Storage_Order
3912 ADC
=> Get_Attribute_Definition_Clause
3913 (First_Subtype
(Arr
),
3914 Attribute_Scalar_Storage_Order
),
3915 Comp_ADC_Present
=> Dummy
);
3918 -- Processing that is done only for subtypes
3921 -- Acquire alignment from base type. Known_Alignment of the base
3922 -- type is False for Wide_String, for example.
3924 if not Known_Alignment
(Arr
)
3925 and then Known_Alignment
(Base_Type
(Arr
))
3927 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
3928 Adjust_Esize_Alignment
(Arr
);
3932 -- Specific checks for bit-packed arrays
3934 if Is_Bit_Packed_Array
(Arr
) then
3936 -- Check number of elements for bit-packed arrays that come from
3937 -- source and have compile time known ranges. The bit-packed
3938 -- arrays circuitry does not support arrays with more than
3939 -- Integer'Last + 1 elements, and when this restriction is
3940 -- violated, causes incorrect data access.
3942 -- For the case where this is not compile time known, a run-time
3943 -- check should be generated???
3945 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
3954 Index
:= First_Index
(Arr
);
3955 while Present
(Index
) loop
3956 Ityp
:= Etype
(Index
);
3958 -- Never generate an error if any index is of a generic
3959 -- type. We will check this in instances.
3961 if Is_Generic_Type
(Ityp
) then
3967 Make_Attribute_Reference
(Loc
,
3968 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
3969 Attribute_Name
=> Name_Range_Length
);
3970 Analyze_And_Resolve
(Ilen
);
3972 -- No attempt is made to check number of elements if not
3973 -- compile time known.
3975 if Nkind
(Ilen
) /= N_Integer_Literal
then
3980 Elmts
:= Elmts
* Intval
(Ilen
);
3984 if Elmts
> Intval
(High_Bound
3985 (Scalar_Range
(Standard_Integer
))) + 1
3988 ("bit packed array type may not have "
3989 & "more than Integer''Last+1 elements", Arr
);
3996 if Known_RM_Size
(Arr
) then
3998 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
4002 -- It is not clear if it is possible to have no size clause
4003 -- at this stage, but it is not worth worrying about. Post
4004 -- error on the entity name in the size clause if present,
4005 -- else on the type entity itself.
4007 if Present
(SizC
) then
4008 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
4010 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
4016 -- If any of the index types was an enumeration type with a non-
4017 -- standard rep clause, then we indicate that the array type is
4018 -- always packed (even if it is not bit-packed).
4020 if Non_Standard_Enum
then
4021 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
4022 Set_Is_Packed
(Base_Type
(Arr
));
4025 Set_Component_Alignment_If_Not_Set
(Arr
);
4027 -- If the array is packed and bit-packed or packed to eliminate holes
4028 -- in the non-contiguous enumeration index types, we must create the
4029 -- packed array type to be used to actually implement the type. This
4030 -- is only needed for real array types (not for string literal types,
4031 -- since they are present only for the front end).
4034 and then (Is_Bit_Packed_Array
(Arr
) or else Non_Standard_Enum
)
4035 and then Ekind
(Arr
) /= E_String_Literal_Subtype
4037 Create_Packed_Array_Impl_Type
(Arr
);
4038 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
4040 -- Make sure that we have the necessary routines to implement the
4041 -- packing, and complain now if not. Note that we only test this
4042 -- for constrained array types.
4044 if Is_Constrained
(Arr
)
4045 and then Is_Bit_Packed_Array
(Arr
)
4046 and then Present
(Packed_Array_Impl_Type
(Arr
))
4047 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
4050 CS
: constant Uint
:= Component_Size
(Arr
);
4051 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
4055 and then not RTE_Available
(RE
)
4058 ("packing of " & UI_Image
(CS
) & "-bit components",
4059 First_Subtype
(Etype
(Arr
)));
4061 -- Cancel the packing
4063 Set_Is_Packed
(Base_Type
(Arr
), False);
4064 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
4065 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
4071 -- Size information of packed array type is copied to the array
4072 -- type, since this is really the representation. But do not
4073 -- override explicit existing size values. If the ancestor subtype
4074 -- is constrained the Packed_Array_Impl_Type will be inherited
4075 -- from it, but the size may have been provided already, and
4076 -- must not be overridden either.
4078 if not Has_Size_Clause
(Arr
)
4080 (No
(Ancestor_Subtype
(Arr
))
4081 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
4083 Copy_Esize
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4084 Copy_RM_Size
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4087 if not Has_Alignment_Clause
(Arr
) then
4089 (To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4095 -- A Ghost type cannot have a component of protected or task type
4096 -- (SPARK RM 6.9(19)).
4098 if Is_Ghost_Entity
(Arr
) and then Is_Concurrent_Type
(Ctyp
) then
4100 ("ghost array type & cannot have concurrent component type",
4103 end Freeze_Array_Type
;
4105 -------------------------------
4106 -- Freeze_Object_Declaration --
4107 -------------------------------
4109 procedure Freeze_Object_Declaration
(E
: Entity_Id
) is
4110 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
);
4111 -- Check that the size of array type Typ can be computed without
4112 -- overflow, and generates a Storage_Error otherwise. This is only
4113 -- relevant for array types whose index is a modular type with
4114 -- Standard_Long_Long_Integer_Size bits: wrap-around arithmetic
4115 -- might yield a meaningless value for the length of the array,
4116 -- or its corresponding attribute.
4118 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
);
4119 -- Ensure that the initialization state of variable Var_Id subject
4120 -- to pragma Thread_Local_Storage agrees with the semantics of the
4123 function Has_Default_Initialization
4124 (Obj_Id
: Entity_Id
) return Boolean;
4125 -- Determine whether object Obj_Id default initialized
4127 -------------------------------
4128 -- Check_Large_Modular_Array --
4129 -------------------------------
4131 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
) is
4132 Obj_Loc
: constant Source_Ptr
:= Sloc
(E
);
4133 Idx_Typ
: Entity_Id
;
4136 -- Nothing to do when expansion is disabled because this routine
4137 -- generates a runtime check.
4139 if not Expander_Active
then
4142 -- Nothing to do for String literal subtypes because their index
4143 -- cannot be a modular type.
4145 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
4148 -- Nothing to do for an imported object because the object will
4149 -- be created on the exporting side.
4151 elsif Is_Imported
(E
) then
4154 -- Nothing to do for unconstrained array types. This case arises
4155 -- when the object declaration is illegal.
4157 elsif not Is_Constrained
(Typ
) then
4161 Idx_Typ
:= Etype
(First_Index
(Typ
));
4163 -- To prevent arithmetic overflow with large values, we raise
4164 -- Storage_Error under the following guard:
4166 -- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
4168 -- This takes care of the boundary case, but it is preferable to
4169 -- use a smaller limit, because even on 64-bit architectures an
4170 -- array of more than 2 ** 30 bytes is likely to raise
4173 if Is_Modular_Integer_Type
(Idx_Typ
)
4174 and then RM_Size
(Idx_Typ
) = Standard_Long_Long_Integer_Size
4176 -- Ensure that the type of the object is elaborated before
4177 -- the check itself is emitted to avoid elaboration issues
4178 -- in the code generator at the library level.
4180 if Is_Itype
(Etype
(E
))
4181 and then In_Open_Scopes
(Scope
(Etype
(E
)))
4184 Ref_Node
: constant Node_Id
:=
4185 Make_Itype_Reference
(Obj_Loc
);
4187 Set_Itype
(Ref_Node
, Etype
(E
));
4188 Insert_Action
(Declaration_Node
(E
), Ref_Node
);
4192 Insert_Action
(Declaration_Node
(E
),
4193 Make_Raise_Storage_Error
(Obj_Loc
,
4195 Make_Op_Ge
(Obj_Loc
,
4197 Make_Op_Subtract
(Obj_Loc
,
4199 Make_Op_Divide
(Obj_Loc
,
4201 Make_Attribute_Reference
(Obj_Loc
,
4203 New_Occurrence_Of
(Typ
, Obj_Loc
),
4204 Attribute_Name
=> Name_Last
),
4206 Make_Integer_Literal
(Obj_Loc
, Uint_2
)),
4208 Make_Op_Divide
(Obj_Loc
,
4210 Make_Attribute_Reference
(Obj_Loc
,
4212 New_Occurrence_Of
(Typ
, Obj_Loc
),
4213 Attribute_Name
=> Name_First
),
4215 Make_Integer_Literal
(Obj_Loc
, Uint_2
))),
4217 Make_Integer_Literal
(Obj_Loc
, (Uint_2
** 30))),
4218 Reason
=> SE_Object_Too_Large
));
4220 end Check_Large_Modular_Array
;
4222 ---------------------------------------
4223 -- Check_Pragma_Thread_Local_Storage --
4224 ---------------------------------------
4226 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
) is
4227 function Has_Incompatible_Initialization
4228 (Var_Decl
: Node_Id
) return Boolean;
4229 -- Determine whether variable Var_Id with declaration Var_Decl is
4230 -- initialized with a value that violates the semantics of pragma
4231 -- Thread_Local_Storage.
4233 -------------------------------------
4234 -- Has_Incompatible_Initialization --
4235 -------------------------------------
4237 function Has_Incompatible_Initialization
4238 (Var_Decl
: Node_Id
) return Boolean
4240 Init_Expr
: constant Node_Id
:= Expression
(Var_Decl
);
4243 -- The variable is default-initialized. This directly violates
4244 -- the semantics of the pragma.
4246 if Has_Default_Initialization
(Var_Id
) then
4249 -- The variable has explicit initialization. In this case only
4250 -- a handful of values satisfy the semantics of the pragma.
4252 elsif Has_Init_Expression
(Var_Decl
)
4253 and then Present
(Init_Expr
)
4255 -- "null" is a legal form of initialization
4257 if Nkind
(Init_Expr
) = N_Null
then
4260 -- A static expression is a legal form of initialization
4262 elsif Is_Static_Expression
(Init_Expr
) then
4265 -- A static aggregate is a legal form of initialization
4267 elsif Nkind
(Init_Expr
) = N_Aggregate
4268 and then Compile_Time_Known_Aggregate
(Init_Expr
)
4272 -- All other initialization expressions violate the semantic
4279 -- The variable lacks any kind of initialization, which agrees
4280 -- with the semantics of the pragma.
4285 end Has_Incompatible_Initialization
;
4287 -- Local declarations
4289 Var_Decl
: constant Node_Id
:= Declaration_Node
(Var_Id
);
4291 -- Start of processing for Check_Pragma_Thread_Local_Storage
4294 -- A variable whose initialization is suppressed lacks any kind of
4297 if Suppress_Initialization
(Var_Id
) then
4300 -- The variable has default initialization, or is explicitly
4301 -- initialized to a value other than null, static expression,
4302 -- or a static aggregate.
4304 elsif Has_Incompatible_Initialization
(Var_Decl
) then
4306 ("Thread_Local_Storage variable& is improperly initialized",
4309 ("\only allowed initialization is explicit NULL, static "
4310 & "expression or static aggregate", Var_Decl
, Var_Id
);
4312 end Check_Pragma_Thread_Local_Storage
;
4314 --------------------------------
4315 -- Has_Default_Initialization --
4316 --------------------------------
4318 function Has_Default_Initialization
4319 (Obj_Id
: Entity_Id
) return Boolean
4321 Obj_Decl
: constant Node_Id
:= Declaration_Node
(Obj_Id
);
4322 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
4326 Comes_From_Source
(Obj_Id
)
4327 and then not Is_Imported
(Obj_Id
)
4328 and then not Has_Init_Expression
(Obj_Decl
)
4330 ((Has_Non_Null_Base_Init_Proc
(Obj_Typ
)
4331 and then not No_Initialization
(Obj_Decl
)
4332 and then not Initialization_Suppressed
(Obj_Typ
))
4334 (Needs_Simple_Initialization
(Obj_Typ
)
4335 and then not Is_Internal
(Obj_Id
)));
4336 end Has_Default_Initialization
;
4340 Typ
: constant Entity_Id
:= Etype
(E
);
4343 -- Start of processing for Freeze_Object_Declaration
4346 -- Abstract type allowed only for C++ imported variables or constants
4348 -- Note: we inhibit this check for objects that do not come from
4349 -- source because there is at least one case (the expansion of
4350 -- x'Class'Input where x is abstract) where we legitimately
4351 -- generate an abstract object.
4353 if Is_Abstract_Type
(Typ
)
4354 and then Comes_From_Source
(Parent
(E
))
4355 and then not (Is_Imported
(E
) and then Is_CPP_Class
(Typ
))
4357 Def
:= Object_Definition
(Parent
(E
));
4359 Error_Msg_N
("type of object cannot be abstract", Def
);
4361 if Is_CPP_Class
(Etype
(E
)) then
4362 Error_Msg_NE
("\} may need a cpp_constructor", Def
, Typ
);
4364 elsif Present
(Expression
(Parent
(E
))) then
4365 Error_Msg_N
-- CODEFIX
4366 ("\maybe a class-wide type was meant", Def
);
4370 -- For object created by object declaration, perform required
4371 -- categorization (preelaborate and pure) checks. Defer these
4372 -- checks to freeze time since pragma Import inhibits default
4373 -- initialization and thus pragma Import affects these checks.
4375 Validate_Object_Declaration
(Declaration_Node
(E
));
4377 -- If there is an address clause, check that it is valid and if need
4378 -- be move initialization to the freeze node.
4380 Check_Address_Clause
(E
);
4382 -- Similar processing is needed for aspects that may affect object
4383 -- layout, like Address, if there is an initialization expression.
4384 -- We don't do this if there is a pragma Linker_Section, because it
4385 -- would prevent the back end from statically initializing the
4386 -- object; we don't want elaboration code in that case.
4388 if Has_Delayed_Aspects
(E
)
4389 and then Expander_Active
4390 and then Is_Array_Type
(Typ
)
4391 and then Present
(Expression
(Declaration_Node
(E
)))
4392 and then No
(Linker_Section_Pragma
(E
))
4395 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4396 Lhs
: constant Node_Id
:= New_Occurrence_Of
(E
, Loc
);
4399 -- Capture initialization value at point of declaration, and
4400 -- make explicit assignment legal, because object may be a
4403 Remove_Side_Effects
(Expression
(Decl
));
4404 Set_Assignment_OK
(Lhs
);
4406 -- Move initialization to freeze actions
4408 Append_Freeze_Action
(E
,
4409 Make_Assignment_Statement
(Loc
,
4411 Expression
=> Expression
(Decl
)));
4413 Set_No_Initialization
(Decl
);
4414 -- Set_Is_Frozen (E, False);
4418 -- Reset Is_True_Constant for non-constant aliased object. We
4419 -- consider that the fact that a non-constant object is aliased may
4420 -- indicate that some funny business is going on, e.g. an aliased
4421 -- object is passed by reference to a procedure which captures the
4422 -- address of the object, which is later used to assign a new value,
4423 -- even though the compiler thinks that it is not modified. Such
4424 -- code is highly dubious, but we choose to make it "work" for
4425 -- non-constant aliased objects.
4427 -- Note that we used to do this for all aliased objects, whether or
4428 -- not constant, but this caused anomalies down the line because we
4429 -- ended up with static objects that were not Is_True_Constant. Not
4430 -- resetting Is_True_Constant for (aliased) constant objects ensures
4431 -- that this anomaly never occurs.
4433 -- However, we don't do that for internal entities. We figure that if
4434 -- we deliberately set Is_True_Constant for an internal entity, e.g.
4435 -- a dispatch table entry, then we mean it.
4437 if Ekind
(E
) /= E_Constant
4438 and then (Is_Aliased
(E
) or else Is_Aliased
(Typ
))
4439 and then not Is_Internal_Name
(Chars
(E
))
4441 Set_Is_True_Constant
(E
, False);
4444 -- If the object needs any kind of default initialization, an error
4445 -- must be issued if No_Default_Initialization applies. The check
4446 -- doesn't apply to imported objects, which are not ever default
4447 -- initialized, and is why the check is deferred until freezing, at
4448 -- which point we know if Import applies. Deferred constants are also
4449 -- exempted from this test because their completion is explicit, or
4450 -- through an import pragma.
4452 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
4455 elsif Has_Default_Initialization
(E
) then
4457 (No_Default_Initialization
, Declaration_Node
(E
));
4460 -- Ensure that a variable subject to pragma Thread_Local_Storage
4462 -- * Lacks default initialization, or
4464 -- * The initialization expression is either "null", a static
4465 -- constant, or a compile-time known aggregate.
4467 if Has_Pragma_Thread_Local_Storage
(E
) then
4468 Check_Pragma_Thread_Local_Storage
(E
);
4471 -- For imported objects, set Is_Public unless there is also an
4472 -- address clause, which means that there is no external symbol
4473 -- needed for the Import (Is_Public may still be set for other
4474 -- unrelated reasons). Note that we delayed this processing
4475 -- till freeze time so that we can be sure not to set the flag
4476 -- if there is an address clause. If there is such a clause,
4477 -- then the only purpose of the Import pragma is to suppress
4478 -- implicit initialization.
4480 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4484 -- For source objects that are not Imported and are library level, if
4485 -- no linker section pragma was given inherit the appropriate linker
4486 -- section from the corresponding type.
4488 if Comes_From_Source
(E
)
4489 and then not Is_Imported
(E
)
4490 and then Is_Library_Level_Entity
(E
)
4491 and then No
(Linker_Section_Pragma
(E
))
4493 Set_Linker_Section_Pragma
(E
, Linker_Section_Pragma
(Typ
));
4496 -- For convention C objects of an enumeration type, warn if the size
4497 -- is not integer size and no explicit size given. Skip warning for
4498 -- Boolean and Character, and assume programmer expects 8-bit sizes
4501 if (Convention
(E
) = Convention_C
4503 Convention
(E
) = Convention_CPP
)
4504 and then Is_Enumeration_Type
(Typ
)
4505 and then not Is_Character_Type
(Typ
)
4506 and then not Is_Boolean_Type
(Typ
)
4507 and then Esize
(Typ
) < Standard_Integer_Size
4508 and then not Has_Size_Clause
(E
)
4510 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4512 ("??convention C enumeration object has size less than ^", E
);
4513 Error_Msg_N
("\??use explicit size clause to set size", E
);
4516 -- Declaring too big an array in disabled ghost code is OK
4518 if Is_Array_Type
(Typ
) and then not Is_Ignored_Ghost_Entity
(E
) then
4519 Check_Large_Modular_Array
(Typ
);
4521 end Freeze_Object_Declaration
;
4523 -----------------------------
4524 -- Freeze_Generic_Entities --
4525 -----------------------------
4527 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
4534 E
:= First_Entity
(Pack
);
4535 while Present
(E
) loop
4536 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
4537 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
4539 Append_To
(Flist
, F
);
4541 elsif Ekind
(E
) = E_Generic_Package
then
4542 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
4549 end Freeze_Generic_Entities
;
4551 --------------------
4552 -- Freeze_Profile --
4553 --------------------
4555 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
4558 Warn_Node
: Node_Id
;
4561 -- Loop through formals
4563 Formal
:= First_Formal
(E
);
4564 while Present
(Formal
) loop
4565 F_Type
:= Etype
(Formal
);
4567 -- AI05-0151: incomplete types can appear in a profile. By the
4568 -- time the entity is frozen, the full view must be available,
4569 -- unless it is a limited view.
4571 if Is_Incomplete_Type
(F_Type
)
4572 and then Present
(Full_View
(F_Type
))
4573 and then not From_Limited_With
(F_Type
)
4575 F_Type
:= Full_View
(F_Type
);
4576 Set_Etype
(Formal
, F_Type
);
4579 if not From_Limited_With
(F_Type
)
4580 and then Should_Freeze_Type
(F_Type
, E
, N
)
4582 Freeze_And_Append
(F_Type
, N
, Result
);
4585 if Is_Private_Type
(F_Type
)
4586 and then Is_Private_Type
(Base_Type
(F_Type
))
4587 and then No
(Full_View
(Base_Type
(F_Type
)))
4588 and then not Is_Generic_Type
(F_Type
)
4589 and then not Is_Derived_Type
(F_Type
)
4591 -- If the type of a formal is incomplete, subprogram is being
4592 -- frozen prematurely. Within an instance (but not within a
4593 -- wrapper package) this is an artifact of our need to regard
4594 -- the end of an instantiation as a freeze point. Otherwise it
4595 -- is a definite error.
4598 Set_Is_Frozen
(E
, False);
4602 elsif not After_Last_Declaration
then
4604 ("type & must be fully defined before this point",
4610 -- Check suspicious parameter for C function. These tests apply
4611 -- only to exported/imported subprograms.
4613 if Warn_On_Export_Import
4614 and then Comes_From_Source
(E
)
4615 and then Convention
(E
) in Convention_C_Family
4616 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4617 and then Convention
(E
) /= Convention
(Formal
)
4618 and then not Has_Warnings_Off
(E
)
4619 and then not Has_Warnings_Off
(F_Type
)
4620 and then not Has_Warnings_Off
(Formal
)
4622 -- Qualify mention of formals with subprogram name
4624 Error_Msg_Qual_Level
:= 1;
4626 -- Check suspicious use of fat C pointer, but do not emit
4627 -- a warning on an access to subprogram when unnesting is
4630 if Is_Access_Type
(F_Type
)
4631 and then Known_Esize
(F_Type
)
4632 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
4633 and then (not Unnest_Subprogram_Mode
4634 or else not Is_Access_Subprogram_Type
(F_Type
))
4637 ("?x?type of & does not correspond to C pointer!", Formal
);
4639 -- Check suspicious return of boolean
4641 elsif Root_Type
(F_Type
) = Standard_Boolean
4642 and then Convention
(F_Type
) = Convention_Ada
4643 and then not Has_Warnings_Off
(F_Type
)
4644 and then not Has_Size_Clause
(F_Type
)
4647 ("& is an 8-bit Ada Boolean?x?", Formal
);
4649 ("\use appropriate corresponding type in C "
4650 & "(e.g. char)?x?", Formal
);
4652 -- Check suspicious tagged type
4654 elsif (Is_Tagged_Type
(F_Type
)
4656 (Is_Access_Type
(F_Type
)
4657 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
4658 and then Convention
(E
) = Convention_C
4661 ("?x?& involves a tagged type which does not "
4662 & "correspond to any C type!", Formal
);
4664 -- Check wrong convention subprogram pointer
4666 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
4667 and then not Has_Foreign_Convention
(F_Type
)
4670 ("?x?subprogram pointer & should "
4671 & "have foreign convention!", Formal
);
4672 Error_Msg_Sloc
:= Sloc
(F_Type
);
4674 ("\?x?add Convention pragma to declaration of &#",
4678 -- Turn off name qualification after message output
4680 Error_Msg_Qual_Level
:= 0;
4683 -- Check for unconstrained array in exported foreign convention
4686 if Has_Foreign_Convention
(E
)
4687 and then not Is_Imported
(E
)
4688 and then Is_Array_Type
(F_Type
)
4689 and then not Is_Constrained
(F_Type
)
4690 and then Warn_On_Export_Import
4692 Error_Msg_Qual_Level
:= 1;
4694 -- If this is an inherited operation, place the warning on
4695 -- the derived type declaration, rather than on the original
4698 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
4700 Warn_Node
:= Parent
(E
);
4702 if Formal
= First_Formal
(E
) then
4703 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
4706 Warn_Node
:= Formal
;
4709 Error_Msg_NE
("?x?type of argument& is unconstrained array",
4711 Error_Msg_N
("\?x?foreign caller must pass bounds explicitly",
4713 Error_Msg_Qual_Level
:= 0;
4716 if not From_Limited_With
(F_Type
) then
4717 if Is_Access_Type
(F_Type
) then
4718 F_Type
:= Designated_Type
(F_Type
);
4722 Next_Formal
(Formal
);
4725 -- Case of function: similar checks on return type
4727 if Ekind
(E
) = E_Function
then
4729 -- Freeze return type
4731 R_Type
:= Etype
(E
);
4733 -- AI05-0151: the return type may have been incomplete at the
4734 -- point of declaration. Replace it with the full view, unless the
4735 -- current type is a limited view. In that case the full view is
4736 -- in a different unit, and gigi finds the non-limited view after
4737 -- the other unit is elaborated.
4739 if Ekind
(R_Type
) = E_Incomplete_Type
4740 and then Present
(Full_View
(R_Type
))
4741 and then not From_Limited_With
(R_Type
)
4743 R_Type
:= Full_View
(R_Type
);
4744 Set_Etype
(E
, R_Type
);
4747 if Should_Freeze_Type
(R_Type
, E
, N
) then
4748 Freeze_And_Append
(R_Type
, N
, Result
);
4751 -- Check suspicious return type for C function
4753 if Warn_On_Export_Import
4754 and then Comes_From_Source
(E
)
4755 and then Convention
(E
) in Convention_C_Family
4756 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4758 -- Check suspicious return of fat C pointer
4760 if Is_Access_Type
(R_Type
)
4761 and then Known_Esize
(R_Type
)
4762 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
4763 and then not Has_Warnings_Off
(E
)
4764 and then not Has_Warnings_Off
(R_Type
)
4767 ("?x?return type of& does not correspond to C pointer!",
4770 -- Check suspicious return of boolean
4772 elsif Root_Type
(R_Type
) = Standard_Boolean
4773 and then Convention
(R_Type
) = Convention_Ada
4774 and then not Has_Warnings_Off
(E
)
4775 and then not Has_Warnings_Off
(R_Type
)
4776 and then not Has_Size_Clause
(R_Type
)
4779 N
: constant Node_Id
:=
4780 Result_Definition
(Declaration_Node
(E
));
4783 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
4785 ("\use appropriate corresponding type in C "
4786 & "(e.g. char)?x?", N
, E
);
4789 -- Check suspicious return tagged type
4791 elsif (Is_Tagged_Type
(R_Type
)
4792 or else (Is_Access_Type
(R_Type
)
4795 (Designated_Type
(R_Type
))))
4796 and then Convention
(E
) = Convention_C
4797 and then not Has_Warnings_Off
(E
)
4798 and then not Has_Warnings_Off
(R_Type
)
4800 Error_Msg_N
("?x?return type of & does not "
4801 & "correspond to C type!", E
);
4803 -- Check return of wrong convention subprogram pointer
4805 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
4806 and then not Has_Foreign_Convention
(R_Type
)
4807 and then not Has_Warnings_Off
(E
)
4808 and then not Has_Warnings_Off
(R_Type
)
4810 Error_Msg_N
("?x?& should return a foreign "
4811 & "convention subprogram pointer", E
);
4812 Error_Msg_Sloc
:= Sloc
(R_Type
);
4814 ("\?x?add Convention pragma to declaration of& #",
4819 -- Give warning for suspicious return of a result of an
4820 -- unconstrained array type in a foreign convention function.
4822 if Has_Foreign_Convention
(E
)
4824 -- We are looking for a return of unconstrained array
4826 and then Is_Array_Type
(R_Type
)
4827 and then not Is_Constrained
(R_Type
)
4829 -- Exclude imported routines, the warning does not belong on
4830 -- the import, but rather on the routine definition.
4832 and then not Is_Imported
(E
)
4834 -- Check that general warning is enabled, and that it is not
4835 -- suppressed for this particular case.
4837 and then Warn_On_Export_Import
4838 and then not Has_Warnings_Off
(E
)
4839 and then not Has_Warnings_Off
(R_Type
)
4842 ("?x?foreign convention function& should not return "
4843 & "unconstrained array!", E
);
4847 -- Check suspicious use of Import in pure unit (cases where the RM
4848 -- allows calls to be omitted).
4852 -- It might be suspicious if the compilation unit has the Pure
4855 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
4857 -- The RM allows omission of calls only in the case of
4858 -- library-level subprograms (see RM-10.2.1(18)).
4860 and then Is_Library_Level_Entity
(E
)
4862 -- Ignore internally generated entity. This happens in some cases
4863 -- of subprograms in specs, where we generate an implied body.
4865 and then Comes_From_Source
(Import_Pragma
(E
))
4867 -- Assume run-time knows what it is doing
4869 and then not GNAT_Mode
4871 -- Assume explicit Pure_Function means import is pure
4873 and then not Has_Pragma_Pure_Function
(E
)
4875 -- Don't need warning in relaxed semantics mode
4877 and then not Relaxed_RM_Semantics
4879 -- Assume convention Intrinsic is OK, since this is specialized.
4880 -- This deals with the DEC unit current_exception.ads
4882 and then Convention
(E
) /= Convention_Intrinsic
4884 -- Assume that ASM interface knows what it is doing
4886 and then Convention
(E
) /= Convention_Assembler
4889 ("pragma Import in Pure unit??", Import_Pragma
(E
));
4891 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
4892 Import_Pragma
(E
), E
);
4898 ------------------------
4899 -- Freeze_Record_Type --
4900 ------------------------
4902 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
4909 pragma Warnings
(Off
, Junk
);
4911 Aliased_Component
: Boolean := False;
4912 -- Set True if we find at least one component which is aliased. This
4913 -- is used to prevent Implicit_Packing of the record, since packing
4914 -- cannot modify the size of alignment of an aliased component.
4916 All_Elem_Components
: Boolean := True;
4917 -- True if all components are of a type whose underlying type is
4920 All_Sized_Components
: Boolean := True;
4921 -- True if all components have a known RM_Size
4923 All_Storage_Unit_Components
: Boolean := True;
4924 -- True if all components have an RM_Size that is a multiple of the
4927 Elem_Component_Total_Esize
: Uint
:= Uint_0
;
4928 -- Accumulates total Esize values of all elementary components. Used
4929 -- for processing of Implicit_Packing.
4931 Placed_Component
: Boolean := False;
4932 -- Set True if we find at least one component with a component
4933 -- clause (used to warn about useless Bit_Order pragmas, and also
4934 -- to detect cases where Implicit_Packing may have an effect).
4936 Sized_Component_Total_RM_Size
: Uint
:= Uint_0
;
4937 -- Accumulates total RM_Size values of all sized components. Used
4938 -- for processing of Implicit_Packing.
4940 Sized_Component_Total_Round_RM_Size
: Uint
:= Uint_0
;
4941 -- Accumulates total RM_Size values of all sized components, rounded
4942 -- individually to a multiple of the storage unit.
4945 -- Scalar_Storage_Order attribute definition clause for the record
4947 SSO_ADC_Component
: Boolean := False;
4948 -- Set True if we find at least one component whose type has a
4949 -- Scalar_Storage_Order attribute definition clause.
4951 Unplaced_Component
: Boolean := False;
4952 -- Set True if we find at least one component with no component
4953 -- clause (used to warn about useless Pack pragmas).
4955 procedure Check_Itype
(Typ
: Entity_Id
);
4956 -- If the component subtype is an access to a constrained subtype of
4957 -- an already frozen type, make the subtype frozen as well. It might
4958 -- otherwise be frozen in the wrong scope, and a freeze node on
4959 -- subtype has no effect. Similarly, if the component subtype is a
4960 -- regular (not protected) access to subprogram, set the anonymous
4961 -- subprogram type to frozen as well, to prevent an out-of-scope
4962 -- freeze node at some eventual point of call. Protected operations
4963 -- are handled elsewhere.
4965 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
4966 -- Make sure that all types mentioned in Discrete_Choices of the
4967 -- variants referenceed by the Variant_Part VP are frozen. This is
4968 -- a recursive routine to deal with nested variants.
4974 procedure Check_Itype
(Typ
: Entity_Id
) is
4975 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
4978 if not Is_Frozen
(Desig
)
4979 and then Is_Frozen
(Base_Type
(Desig
))
4981 Set_Is_Frozen
(Desig
);
4983 -- In addition, add an Itype_Reference to ensure that the
4984 -- access subtype is elaborated early enough. This cannot be
4985 -- done if the subtype may depend on discriminants.
4987 if Ekind
(Comp
) = E_Component
4988 and then Is_Itype
(Etype
(Comp
))
4989 and then not Has_Discriminants
(Rec
)
4991 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
4992 Set_Itype
(IR
, Desig
);
4996 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
4997 and then Convention
(Desig
) /= Convention_Protected
4999 Set_Is_Frozen
(Desig
);
5000 Create_Extra_Formals
(Desig
);
5004 ------------------------------------
5005 -- Freeze_Choices_In_Variant_Part --
5006 ------------------------------------
5008 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
5009 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
5016 -- Loop through variants
5018 Variant
:= First_Non_Pragma
(Variants
(VP
));
5019 while Present
(Variant
) loop
5021 -- Loop through choices, checking that all types are frozen
5023 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
5024 while Present
(Choice
) loop
5025 if Nkind
(Choice
) in N_Has_Etype
5026 and then Present
(Etype
(Choice
))
5028 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
5031 Next_Non_Pragma
(Choice
);
5034 -- Check for nested variant part to process
5036 CL
:= Component_List
(Variant
);
5038 if not Null_Present
(CL
) then
5039 if Present
(Variant_Part
(CL
)) then
5040 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
5044 Next_Non_Pragma
(Variant
);
5046 end Freeze_Choices_In_Variant_Part
;
5048 -- Start of processing for Freeze_Record_Type
5051 -- Freeze components and embedded subtypes
5053 Comp
:= First_Entity
(Rec
);
5055 while Present
(Comp
) loop
5056 if Is_Aliased
(Comp
) then
5057 Aliased_Component
:= True;
5060 -- Handle the component and discriminant case
5062 if Ekind
(Comp
) in E_Component | E_Discriminant
then
5064 CC
: constant Node_Id
:= Component_Clause
(Comp
);
5067 -- Freezing a record type freezes the type of each of its
5068 -- components. However, if the type of the component is
5069 -- part of this record, we do not want or need a separate
5070 -- Freeze_Node. Note that Is_Itype is wrong because that's
5071 -- also set in private type cases. We also can't check for
5072 -- the Scope being exactly Rec because of private types and
5073 -- record extensions.
5075 if Is_Itype
(Etype
(Comp
))
5076 and then Is_Record_Type
(Underlying_Type
5077 (Scope
(Etype
(Comp
))))
5079 Undelay_Type
(Etype
(Comp
));
5082 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5084 -- Warn for pragma Pack overriding foreign convention
5086 if Has_Foreign_Convention
(Etype
(Comp
))
5087 and then Has_Pragma_Pack
(Rec
)
5089 -- Don't warn for aliased components, since override
5090 -- cannot happen in that case.
5092 and then not Is_Aliased
(Comp
)
5095 CN
: constant Name_Id
:=
5096 Get_Convention_Name
(Convention
(Etype
(Comp
)));
5097 PP
: constant Node_Id
:=
5098 Get_Pragma
(Rec
, Pragma_Pack
);
5100 if Present
(PP
) then
5101 Error_Msg_Name_1
:= CN
;
5102 Error_Msg_Sloc
:= Sloc
(Comp
);
5104 ("pragma Pack affects convention % component#??",
5106 Error_Msg_Name_1
:= CN
;
5108 ("\component & may not have % compatible "
5109 & "representation??", PP
, Comp
);
5114 -- Check for error of component clause given for variable
5115 -- sized type. We have to delay this test till this point,
5116 -- since the component type has to be frozen for us to know
5117 -- if it is variable length.
5119 if Present
(CC
) then
5120 Placed_Component
:= True;
5122 -- We omit this test in a generic context, it will be
5123 -- applied at instantiation time.
5125 if Inside_A_Generic
then
5128 -- Also omit this test in CodePeer mode, since we do not
5129 -- have sufficient info on size and rep clauses.
5131 elsif CodePeer_Mode
then
5137 Size_Known_At_Compile_Time
5138 (Underlying_Type
(Etype
(Comp
)))
5141 ("component clause not allowed for variable " &
5142 "length component", CC
);
5146 Unplaced_Component
:= True;
5149 -- Case of component requires byte alignment
5151 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
5153 -- Set the enclosing record to also require byte align
5155 Set_Must_Be_On_Byte_Boundary
(Rec
);
5157 -- Check for component clause that is inconsistent with
5158 -- the required byte boundary alignment.
5161 and then Normalized_First_Bit
(Comp
) mod
5162 System_Storage_Unit
/= 0
5165 ("component & must be byte aligned",
5166 Component_Name
(Component_Clause
(Comp
)));
5172 -- Gather data for possible Implicit_Packing later. Note that at
5173 -- this stage we might be dealing with a real component, or with
5174 -- an implicit subtype declaration.
5176 if Known_Static_RM_Size
(Etype
(Comp
)) then
5178 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
5179 Comp_Size
: constant Uint
:= RM_Size
(Comp_Type
);
5180 SSU
: constant Int
:= Ttypes
.System_Storage_Unit
;
5183 Sized_Component_Total_RM_Size
:=
5184 Sized_Component_Total_RM_Size
+ Comp_Size
;
5186 Sized_Component_Total_Round_RM_Size
:=
5187 Sized_Component_Total_Round_RM_Size
+
5188 (Comp_Size
+ SSU
- 1) / SSU
* SSU
;
5190 if Present
(Underlying_Type
(Comp_Type
))
5191 and then Is_Elementary_Type
(Underlying_Type
(Comp_Type
))
5193 Elem_Component_Total_Esize
:=
5194 Elem_Component_Total_Esize
+ Esize
(Comp_Type
);
5196 All_Elem_Components
:= False;
5198 if Comp_Size
mod SSU
/= 0 then
5199 All_Storage_Unit_Components
:= False;
5204 All_Sized_Components
:= False;
5207 -- If the component is an Itype with Delayed_Freeze and is either
5208 -- a record or array subtype and its base type has not yet been
5209 -- frozen, we must remove this from the entity list of this record
5210 -- and put it on the entity list of the scope of its base type.
5211 -- Note that we know that this is not the type of a component
5212 -- since we cleared Has_Delayed_Freeze for it in the previous
5213 -- loop. Thus this must be the Designated_Type of an access type,
5214 -- which is the type of a component.
5217 and then Is_Type
(Scope
(Comp
))
5218 and then Is_Composite_Type
(Comp
)
5219 and then Base_Type
(Comp
) /= Comp
5220 and then Has_Delayed_Freeze
(Comp
)
5221 and then not Is_Frozen
(Base_Type
(Comp
))
5224 Will_Be_Frozen
: Boolean := False;
5228 -- We have a difficult case to handle here. Suppose Rec is
5229 -- subtype being defined in a subprogram that's created as
5230 -- part of the freezing of Rec'Base. In that case, we know
5231 -- that Comp'Base must have already been frozen by the time
5232 -- we get to elaborate this because Gigi doesn't elaborate
5233 -- any bodies until it has elaborated all of the declarative
5234 -- part. But Is_Frozen will not be set at this point because
5235 -- we are processing code in lexical order.
5237 -- We detect this case by going up the Scope chain of Rec
5238 -- and seeing if we have a subprogram scope before reaching
5239 -- the top of the scope chain or that of Comp'Base. If we
5240 -- do, then mark that Comp'Base will actually be frozen. If
5241 -- so, we merely undelay it.
5244 while Present
(S
) loop
5245 if Is_Subprogram
(S
) then
5246 Will_Be_Frozen
:= True;
5248 elsif S
= Scope
(Base_Type
(Comp
)) then
5255 if Will_Be_Frozen
then
5256 Undelay_Type
(Comp
);
5259 if Present
(Prev
) then
5260 Link_Entities
(Prev
, Next_Entity
(Comp
));
5262 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
5265 -- Insert in entity list of scope of base type (which
5266 -- must be an enclosing scope, because still unfrozen).
5268 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
5272 -- If the component is an access type with an allocator as default
5273 -- value, the designated type will be frozen by the corresponding
5274 -- expression in init_proc. In order to place the freeze node for
5275 -- the designated type before that for the current record type,
5278 -- Same process if the component is an array of access types,
5279 -- initialized with an aggregate. If the designated type is
5280 -- private, it cannot contain allocators, and it is premature
5281 -- to freeze the type, so we check for this as well.
5283 elsif Is_Access_Type
(Etype
(Comp
))
5284 and then Present
(Parent
(Comp
))
5286 Nkind
(Parent
(Comp
))
5287 in N_Component_Declaration | N_Discriminant_Specification
5288 and then Present
(Expression
(Parent
(Comp
)))
5291 Alloc
: constant Node_Id
:=
5292 Unqualify
(Expression
(Parent
(Comp
)));
5295 if Nkind
(Alloc
) = N_Allocator
then
5297 -- If component is pointer to a class-wide type, freeze
5298 -- the specific type in the expression being allocated.
5299 -- The expression may be a subtype indication, in which
5300 -- case freeze the subtype mark.
5302 if Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp
)))
5304 if Is_Entity_Name
(Expression
(Alloc
)) then
5306 (Entity
(Expression
(Alloc
)), N
, Result
);
5308 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
5311 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
5314 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
5315 Check_Itype
(Etype
(Comp
));
5318 (Designated_Type
(Etype
(Comp
)), N
, Result
);
5322 elsif Is_Access_Type
(Etype
(Comp
))
5323 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
5325 Check_Itype
(Etype
(Comp
));
5327 -- Freeze the designated type when initializing a component with
5328 -- an aggregate in case the aggregate contains allocators.
5331 -- type T_Ptr is access all T;
5332 -- type T_Array is array ... of T_Ptr;
5334 -- type Rec is record
5335 -- Comp : T_Array := (others => ...);
5338 elsif Is_Array_Type
(Etype
(Comp
))
5339 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
5342 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
5343 Desig_Typ
: constant Entity_Id
:=
5345 (Component_Type
(Etype
(Comp
)));
5348 -- The only case when this sort of freezing is not done is
5349 -- when the designated type is class-wide and the root type
5350 -- is the record owning the component. This scenario results
5351 -- in a circularity because the class-wide type requires
5352 -- primitives that have not been created yet as the root
5353 -- type is in the process of being frozen.
5355 -- type Rec is tagged;
5356 -- type Rec_Ptr is access all Rec'Class;
5357 -- type Rec_Array is array ... of Rec_Ptr;
5359 -- type Rec is record
5360 -- Comp : Rec_Array := (others => ...);
5363 if Is_Class_Wide_Type
(Desig_Typ
)
5364 and then Root_Type
(Desig_Typ
) = Rec
5368 elsif Is_Fully_Defined
(Desig_Typ
)
5369 and then Present
(Comp_Par
)
5370 and then Nkind
(Comp_Par
) = N_Component_Declaration
5371 and then Present
(Expression
(Comp_Par
))
5372 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
5374 Freeze_And_Append
(Desig_Typ
, N
, Result
);
5384 Get_Attribute_Definition_Clause
5385 (Rec
, Attribute_Scalar_Storage_Order
);
5387 -- If the record type has Complex_Representation, then it is treated
5388 -- as a scalar in the back end so the storage order is irrelevant.
5390 if Has_Complex_Representation
(Rec
) then
5391 if Present
(SSO_ADC
) then
5393 ("??storage order has no effect with Complex_Representation",
5398 -- Deal with default setting of reverse storage order
5400 Set_SSO_From_Default
(Rec
);
5402 -- Check consistent attribute setting on component types
5405 Comp_ADC_Present
: Boolean;
5407 Comp
:= First_Component
(Rec
);
5408 while Present
(Comp
) loop
5409 Check_Component_Storage_Order
5413 Comp_ADC_Present
=> Comp_ADC_Present
);
5414 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
5415 Next_Component
(Comp
);
5419 -- Now deal with reverse storage order/bit order issues
5421 if Present
(SSO_ADC
) then
5423 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
5424 -- if the former is specified.
5426 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
5428 -- Note: report error on Rec, not on SSO_ADC, as ADC may
5429 -- apply to some ancestor type.
5431 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
5433 ("scalar storage order for& specified# inconsistent with "
5434 & "bit order", Rec
);
5437 -- Warn if there is a Scalar_Storage_Order attribute definition
5438 -- clause but no component clause, no component that itself has
5439 -- such an attribute definition, and no pragma Pack.
5441 if not (Placed_Component
5448 ("??scalar storage order specified but no component "
5449 & "clause", SSO_ADC
);
5454 -- Deal with Bit_Order aspect
5456 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
5458 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
5459 if not (Placed_Component
5460 or else Present
(SSO_ADC
)
5461 or else Is_Packed
(Rec
))
5463 -- Warn if clause has no effect when no component clause is
5464 -- present, but suppress warning if the Bit_Order is required
5465 -- due to the presence of a Scalar_Storage_Order attribute.
5468 ("??bit order specification has no effect", ADC
);
5470 ("\??since no component clauses were specified", ADC
);
5472 -- Here is where we do the processing to adjust component clauses
5473 -- for reversed bit order, when not using reverse SSO. If an error
5474 -- has been reported on Rec already (such as SSO incompatible with
5475 -- bit order), don't bother adjusting as this may generate extra
5478 elsif Reverse_Bit_Order
(Rec
)
5479 and then not Reverse_Storage_Order
(Rec
)
5480 and then not Error_Posted
(Rec
)
5482 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
5484 -- Case where we have both an explicit Bit_Order and the same
5485 -- Scalar_Storage_Order: leave record untouched, the back-end
5486 -- will take care of required layout conversions.
5494 -- Check for useless pragma Pack when all components placed. We only
5495 -- do this check for record types, not subtypes, since a subtype may
5496 -- have all its components placed, and it still makes perfectly good
5497 -- sense to pack other subtypes or the parent type. We do not give
5498 -- this warning if Optimize_Alignment is set to Space, since the
5499 -- pragma Pack does have an effect in this case (it always resets
5500 -- the alignment to one).
5502 if Ekind
(Rec
) = E_Record_Type
5503 and then Is_Packed
(Rec
)
5504 and then not Unplaced_Component
5505 and then Optimize_Alignment
/= 'S'
5507 -- Reset packed status. Probably not necessary, but we do it so
5508 -- that there is no chance of the back end doing something strange
5509 -- with this redundant indication of packing.
5511 Set_Is_Packed
(Rec
, False);
5513 -- Give warning if redundant constructs warnings on
5515 if Warn_On_Redundant_Constructs
then
5516 Error_Msg_N
-- CODEFIX
5517 ("?r?pragma Pack has no effect, no unplaced components",
5518 Get_Rep_Pragma
(Rec
, Name_Pack
));
5522 -- If this is the record corresponding to a remote type, freeze the
5523 -- remote type here since that is what we are semantically freezing.
5524 -- This prevents the freeze node for that type in an inner scope.
5526 if Ekind
(Rec
) = E_Record_Type
then
5527 if Present
(Corresponding_Remote_Type
(Rec
)) then
5528 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
5531 -- Check for controlled components, unchecked unions, and type
5534 Comp
:= First_Component
(Rec
);
5535 while Present
(Comp
) loop
5537 -- Do not set Has_Controlled_Component on a class-wide
5538 -- equivalent type. See Make_CW_Equivalent_Type.
5540 if not Is_Class_Wide_Equivalent_Type
(Rec
)
5542 (Has_Controlled_Component
(Etype
(Comp
))
5544 (Chars
(Comp
) /= Name_uParent
5545 and then Is_Controlled
(Etype
(Comp
)))
5547 (Is_Protected_Type
(Etype
(Comp
))
5549 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
5551 Has_Controlled_Component
5552 (Corresponding_Record_Type
(Etype
(Comp
)))))
5554 Set_Has_Controlled_Component
(Rec
);
5557 if Has_Unchecked_Union
(Etype
(Comp
)) then
5558 Set_Has_Unchecked_Union
(Rec
);
5561 -- The record type requires its own invariant procedure in
5562 -- order to verify the invariant of each individual component.
5563 -- Do not consider internal components such as _parent because
5564 -- parent class-wide invariants are always inherited.
5565 -- In GNATprove mode, the component invariants are checked by
5566 -- other means. They should not be added to the record type
5567 -- invariant procedure, so that the procedure can be used to
5568 -- check the recordy type invariants if any.
5570 if Comes_From_Source
(Comp
)
5571 and then Has_Invariants
(Etype
(Comp
))
5572 and then not GNATprove_Mode
5574 Set_Has_Own_Invariants
(Rec
);
5577 -- Scan component declaration for likely misuses of current
5578 -- instance, either in a constraint or a default expression.
5580 if Has_Per_Object_Constraint
(Comp
) then
5581 Check_Current_Instance
(Parent
(Comp
));
5584 Next_Component
(Comp
);
5588 -- Enforce the restriction that access attributes with a current
5589 -- instance prefix can only apply to limited types. This comment
5590 -- is floating here, but does not seem to belong here???
5592 -- Set component alignment if not otherwise already set
5594 Set_Component_Alignment_If_Not_Set
(Rec
);
5596 -- For first subtypes, check if there are any fixed-point fields with
5597 -- component clauses, where we must check the size. This is not done
5598 -- till the freeze point since for fixed-point types, we do not know
5599 -- the size until the type is frozen. Similar processing applies to
5600 -- bit-packed arrays.
5602 if Is_First_Subtype
(Rec
) then
5603 Comp
:= First_Component
(Rec
);
5604 while Present
(Comp
) loop
5605 if Present
(Component_Clause
(Comp
))
5606 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
5607 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
5610 (Component_Name
(Component_Clause
(Comp
)),
5616 Next_Component
(Comp
);
5620 -- See if Size is too small as is (and implicit packing might help)
5622 if not Is_Packed
(Rec
)
5624 -- No implicit packing if even one component is explicitly placed
5626 and then not Placed_Component
5628 -- Or even one component is aliased
5630 and then not Aliased_Component
5632 -- Must have size clause and all sized components
5634 and then Has_Size_Clause
(Rec
)
5635 and then All_Sized_Components
5637 -- Do not try implicit packing on records with discriminants, too
5638 -- complicated, especially in the variant record case.
5640 and then not Has_Discriminants
(Rec
)
5642 -- We want to implicitly pack if the specified size of the record
5643 -- is less than the sum of the object sizes (no point in packing
5644 -- if this is not the case), if we can compute it, i.e. if we have
5645 -- only elementary components. Otherwise, we have at least one
5646 -- composite component and we want to implicitly pack only if bit
5647 -- packing is required for it, as we are sure in this case that
5648 -- the back end cannot do the expected layout without packing.
5651 ((All_Elem_Components
5652 and then RM_Size
(Rec
) < Elem_Component_Total_Esize
)
5654 (not All_Elem_Components
5655 and then not All_Storage_Unit_Components
5656 and then RM_Size
(Rec
) < Sized_Component_Total_Round_RM_Size
))
5658 -- And the total RM size cannot be greater than the specified size
5659 -- since otherwise packing will not get us where we have to be.
5661 and then Sized_Component_Total_RM_Size
<= RM_Size
(Rec
)
5663 -- Never do implicit packing in CodePeer or SPARK modes since
5664 -- we don't do any packing in these modes, since this generates
5665 -- over-complex code that confuses static analysis, and in
5666 -- general, neither CodePeer not GNATprove care about the
5667 -- internal representation of objects.
5669 and then not (CodePeer_Mode
or GNATprove_Mode
)
5671 -- If implicit packing enabled, do it
5673 if Implicit_Packing
then
5674 Set_Is_Packed
(Rec
);
5676 -- Otherwise flag the size clause
5680 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
5682 Error_Msg_NE
-- CODEFIX
5683 ("size given for& too small", Sz
, Rec
);
5684 Error_Msg_N
-- CODEFIX
5685 ("\use explicit pragma Pack "
5686 & "or use pragma Implicit_Packing", Sz
);
5691 -- The following checks are relevant only when SPARK_Mode is on as
5692 -- they are not standard Ada legality rules.
5694 if SPARK_Mode
= On
then
5696 -- A discriminated type cannot be effectively volatile
5697 -- (SPARK RM 7.1.3(5)).
5699 if Is_Effectively_Volatile
(Rec
) then
5700 if Has_Discriminants
(Rec
) then
5701 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
5704 -- A non-effectively volatile record type cannot contain
5705 -- effectively volatile components (SPARK RM 7.1.3(6)).
5708 Comp
:= First_Component
(Rec
);
5709 while Present
(Comp
) loop
5710 if Comes_From_Source
(Comp
)
5711 and then Is_Effectively_Volatile
(Etype
(Comp
))
5713 Error_Msg_Name_1
:= Chars
(Rec
);
5715 ("component & of non-volatile type % cannot be "
5716 & "volatile", Comp
);
5719 Next_Component
(Comp
);
5723 -- A type which does not yield a synchronized object cannot have
5724 -- a component that yields a synchronized object (SPARK RM 9.5).
5726 if not Yields_Synchronized_Object
(Rec
) then
5727 Comp
:= First_Component
(Rec
);
5728 while Present
(Comp
) loop
5729 if Comes_From_Source
(Comp
)
5730 and then Yields_Synchronized_Object
(Etype
(Comp
))
5732 Error_Msg_Name_1
:= Chars
(Rec
);
5734 ("component & of non-synchronized type % cannot be "
5735 & "synchronized", Comp
);
5738 Next_Component
(Comp
);
5742 -- A Ghost type cannot have a component of protected or task type
5743 -- (SPARK RM 6.9(19)).
5745 if Is_Ghost_Entity
(Rec
) then
5746 Comp
:= First_Component
(Rec
);
5747 while Present
(Comp
) loop
5748 if Comes_From_Source
(Comp
)
5749 and then Is_Concurrent_Type
(Etype
(Comp
))
5751 Error_Msg_Name_1
:= Chars
(Rec
);
5753 ("component & of ghost type % cannot be concurrent",
5757 Next_Component
(Comp
);
5762 -- Make sure that if we have an iterator aspect, then we have
5763 -- either Constant_Indexing or Variable_Indexing.
5766 Iterator_Aspect
: Node_Id
;
5769 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
5771 if No
(Iterator_Aspect
) then
5772 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
5775 if Present
(Iterator_Aspect
) then
5776 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
5778 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
5783 ("Iterator_Element requires indexing aspect",
5789 -- All done if not a full record definition
5791 if Ekind
(Rec
) /= E_Record_Type
then
5795 -- Finally we need to check the variant part to make sure that
5796 -- all types within choices are properly frozen as part of the
5797 -- freezing of the record type.
5799 Check_Variant_Part
: declare
5800 D
: constant Node_Id
:= Declaration_Node
(Rec
);
5805 -- Find component list
5809 if Nkind
(D
) = N_Full_Type_Declaration
then
5810 T
:= Type_Definition
(D
);
5812 if Nkind
(T
) = N_Record_Definition
then
5813 C
:= Component_List
(T
);
5815 elsif Nkind
(T
) = N_Derived_Type_Definition
5816 and then Present
(Record_Extension_Part
(T
))
5818 C
:= Component_List
(Record_Extension_Part
(T
));
5822 -- Case of variant part present
5824 if Present
(C
) and then Present
(Variant_Part
(C
)) then
5825 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
5828 -- Note: we used to call Check_Choices here, but it is too early,
5829 -- since predicated subtypes are frozen here, but their freezing
5830 -- actions are in Analyze_Freeze_Entity, which has not been called
5831 -- yet for entities frozen within this procedure, so we moved that
5832 -- call to the Analyze_Freeze_Entity for the record type.
5834 end Check_Variant_Part
;
5836 -- Check that all the primitives of an interface type are abstract
5837 -- or null procedures.
5839 if Is_Interface
(Rec
)
5840 and then not Error_Posted
(Parent
(Rec
))
5847 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
5848 while Present
(Elmt
) loop
5849 Subp
:= Node
(Elmt
);
5851 if not Is_Abstract_Subprogram
(Subp
)
5853 -- Avoid reporting the error on inherited primitives
5855 and then Comes_From_Source
(Subp
)
5857 Error_Msg_Name_1
:= Chars
(Subp
);
5859 if Ekind
(Subp
) = E_Procedure
then
5860 if not Null_Present
(Parent
(Subp
)) then
5862 ("interface procedure % must be abstract or null",
5867 ("interface function % must be abstract",
5877 -- For a derived tagged type, check whether inherited primitives
5878 -- might require a wrapper to handle class-wide conditions.
5880 if Is_Tagged_Type
(Rec
) and then Is_Derived_Type
(Rec
) then
5881 Check_Inherited_Conditions
(Rec
);
5883 end Freeze_Record_Type
;
5885 -------------------------------
5886 -- Has_Boolean_Aspect_Import --
5887 -------------------------------
5889 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
5890 Decl
: constant Node_Id
:= Declaration_Node
(E
);
5895 if Has_Aspects
(Decl
) then
5896 Asp
:= First
(Aspect_Specifications
(Decl
));
5897 while Present
(Asp
) loop
5898 Expr
:= Expression
(Asp
);
5900 -- The value of aspect Import is True when the expression is
5901 -- either missing or it is explicitly set to True.
5903 if Get_Aspect_Id
(Asp
) = Aspect_Import
5905 or else (Compile_Time_Known_Value
(Expr
)
5906 and then Is_True
(Expr_Value
(Expr
))))
5916 end Has_Boolean_Aspect_Import
;
5918 -------------------------
5919 -- Inherit_Freeze_Node --
5920 -------------------------
5922 procedure Inherit_Freeze_Node
5926 Typ_Fnod
: constant Node_Id
:= Freeze_Node
(Typ
);
5929 Set_Freeze_Node
(Typ
, Fnod
);
5930 Set_Entity
(Fnod
, Typ
);
5932 -- The input type had an existing node. Propagate relevant attributes
5933 -- from the old freeze node to the inherited freeze node.
5935 -- ??? if both freeze nodes have attributes, would they differ?
5937 if Present
(Typ_Fnod
) then
5939 -- Attribute Access_Types_To_Process
5941 if Present
(Access_Types_To_Process
(Typ_Fnod
))
5942 and then No
(Access_Types_To_Process
(Fnod
))
5944 Set_Access_Types_To_Process
(Fnod
,
5945 Access_Types_To_Process
(Typ_Fnod
));
5948 -- Attribute Actions
5950 if Present
(Actions
(Typ_Fnod
)) and then No
(Actions
(Fnod
)) then
5951 Set_Actions
(Fnod
, Actions
(Typ_Fnod
));
5954 -- Attribute First_Subtype_Link
5956 if Present
(First_Subtype_Link
(Typ_Fnod
))
5957 and then No
(First_Subtype_Link
(Fnod
))
5959 Set_First_Subtype_Link
(Fnod
, First_Subtype_Link
(Typ_Fnod
));
5962 -- Attribute TSS_Elist
5964 if Present
(TSS_Elist
(Typ_Fnod
))
5965 and then No
(TSS_Elist
(Fnod
))
5967 Set_TSS_Elist
(Fnod
, TSS_Elist
(Typ_Fnod
));
5970 end Inherit_Freeze_Node
;
5972 ------------------------------
5973 -- Wrap_Imported_Subprogram --
5974 ------------------------------
5976 -- The issue here is that our normal approach of checking preconditions
5977 -- and postconditions does not work for imported procedures, since we
5978 -- are not generating code for the body. To get around this we create
5979 -- a wrapper, as shown by the following example:
5981 -- procedure K (A : Integer);
5982 -- pragma Import (C, K);
5984 -- The spec is rewritten by removing the effects of pragma Import, but
5985 -- leaving the convention unchanged, as though the source had said:
5987 -- procedure K (A : Integer);
5988 -- pragma Convention (C, K);
5990 -- and we create a body, added to the entity K freeze actions, which
5993 -- procedure K (A : Integer) is
5994 -- procedure K (A : Integer);
5995 -- pragma Import (C, K);
6000 -- Now the contract applies in the normal way to the outer procedure,
6001 -- and the inner procedure has no contracts, so there is no problem
6002 -- in just calling it to get the original effect.
6004 -- In the case of a function, we create an appropriate return statement
6005 -- for the subprogram body that calls the inner procedure.
6007 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
6008 function Copy_Import_Pragma
return Node_Id
;
6009 -- Obtain a copy of the Import_Pragma which belongs to subprogram E
6011 ------------------------
6012 -- Copy_Import_Pragma --
6013 ------------------------
6015 function Copy_Import_Pragma
return Node_Id
is
6017 -- The subprogram should have an import pragma, otherwise it does
6020 Prag
: constant Node_Id
:= Import_Pragma
(E
);
6021 pragma Assert
(Present
(Prag
));
6023 -- Save all semantic fields of the pragma
6025 Save_Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
6026 Save_From
: constant Boolean := From_Aspect_Specification
(Prag
);
6027 Save_Prag
: constant Node_Id
:= Next_Pragma
(Prag
);
6028 Save_Rep
: constant Node_Id
:= Next_Rep_Item
(Prag
);
6033 -- Reset all semantic fields. This avoids a potential infinite
6034 -- loop when the pragma comes from an aspect as the duplication
6035 -- will copy the aspect, then copy the corresponding pragma and
6038 Set_Corresponding_Aspect
(Prag
, Empty
);
6039 Set_From_Aspect_Specification
(Prag
, False);
6040 Set_Next_Pragma
(Prag
, Empty
);
6041 Set_Next_Rep_Item
(Prag
, Empty
);
6043 Result
:= Copy_Separate_Tree
(Prag
);
6045 -- Restore the original semantic fields
6047 Set_Corresponding_Aspect
(Prag
, Save_Asp
);
6048 Set_From_Aspect_Specification
(Prag
, Save_From
);
6049 Set_Next_Pragma
(Prag
, Save_Prag
);
6050 Set_Next_Rep_Item
(Prag
, Save_Rep
);
6053 end Copy_Import_Pragma
;
6057 Loc
: constant Source_Ptr
:= Sloc
(E
);
6058 CE
: constant Name_Id
:= Chars
(E
);
6066 -- Start of processing for Wrap_Imported_Subprogram
6069 -- Nothing to do if not imported
6071 if not Is_Imported
(E
) then
6074 -- Test enabling conditions for wrapping
6076 elsif Is_Subprogram
(E
)
6077 and then Present
(Contract
(E
))
6078 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
6079 and then not GNATprove_Mode
6081 -- Here we do the wrap
6083 Prag
:= Copy_Import_Pragma
;
6085 -- Fix up spec so it is no longer imported and has convention Ada
6087 Set_Has_Completion
(E
, False);
6088 Set_Import_Pragma
(E
, Empty
);
6089 Set_Interface_Name
(E
, Empty
);
6090 Set_Is_Imported
(E
, False);
6091 Set_Convention
(E
, Convention_Ada
);
6093 -- Grab the subprogram declaration and specification
6095 Spec
:= Declaration_Node
(E
);
6097 -- Build parameter list that we need
6100 Forml
:= First_Formal
(E
);
6101 while Present
(Forml
) loop
6102 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
6103 Next_Formal
(Forml
);
6108 -- An imported function whose result type is anonymous access
6109 -- creates a new anonymous access type when it is relocated into
6110 -- the declarations of the body generated below. As a result, the
6111 -- accessibility level of these two anonymous access types may not
6112 -- be compatible even though they are essentially the same type.
6113 -- Use an unchecked type conversion to reconcile this case. Note
6114 -- that the conversion is safe because in the named access type
6115 -- case, both the body and imported function utilize the same
6118 if Ekind
(E
) in E_Function | E_Generic_Function
then
6120 Make_Simple_Return_Statement
(Loc
,
6122 Unchecked_Convert_To
(Etype
(E
),
6123 Make_Function_Call
(Loc
,
6124 Name
=> Make_Identifier
(Loc
, CE
),
6125 Parameter_Associations
=> Parms
)));
6129 Make_Procedure_Call_Statement
(Loc
,
6130 Name
=> Make_Identifier
(Loc
, CE
),
6131 Parameter_Associations
=> Parms
);
6134 -- Now build the body
6137 Make_Subprogram_Body
(Loc
,
6138 Specification
=> Copy_Subprogram_Spec
(Spec
),
6139 Declarations
=> New_List
(
6140 Make_Subprogram_Declaration
(Loc
,
6141 Specification
=> Copy_Subprogram_Spec
(Spec
)),
6143 Handled_Statement_Sequence
=>
6144 Make_Handled_Sequence_Of_Statements
(Loc
,
6145 Statements
=> New_List
(Stmt
),
6146 End_Label
=> Make_Identifier
(Loc
, CE
)));
6148 -- Append the body to freeze result
6150 Add_To_Result
(Bod
);
6153 -- Case of imported subprogram that does not get wrapped
6156 -- Set Is_Public. All imported entities need an external symbol
6157 -- created for them since they are always referenced from another
6158 -- object file. Note this used to be set when we set Is_Imported
6159 -- back in Sem_Prag, but now we delay it to this point, since we
6160 -- don't want to set this flag if we wrap an imported subprogram.
6164 end Wrap_Imported_Subprogram
;
6166 -- Start of processing for Freeze_Entity
6169 -- The entity being frozen may be subject to pragma Ghost. Set the mode
6170 -- now to ensure that any nodes generated during freezing are properly
6171 -- flagged as Ghost.
6175 -- We are going to test for various reasons why this entity need not be
6176 -- frozen here, but in the case of an Itype that's defined within a
6177 -- record, that test actually applies to the record.
6179 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
6180 Test_E
:= Scope
(E
);
6182 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
6183 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
6185 Test_E
:= Underlying_Type
(Scope
(E
));
6188 -- Do not freeze if already frozen since we only need one freeze node
6190 if Is_Frozen
(E
) then
6194 -- Do not freeze if we are preanalyzing without freezing
6196 elsif Inside_Preanalysis_Without_Freezing
> 0 then
6200 elsif Ekind
(E
) = E_Generic_Package
then
6201 Result
:= Freeze_Generic_Entities
(E
);
6204 -- It is improper to freeze an external entity within a generic because
6205 -- its freeze node will appear in a non-valid context. The entity will
6206 -- be frozen in the proper scope after the current generic is analyzed.
6207 -- However, aspects must be analyzed because they may be queried later
6208 -- within the generic itself, and the corresponding pragma or attribute
6209 -- definition has not been analyzed yet. After this, indicate that the
6210 -- entity has no further delayed aspects, to prevent a later aspect
6211 -- analysis out of the scope of the generic.
6213 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
6214 if Has_Delayed_Aspects
(E
) then
6215 Analyze_Aspects_At_Freeze_Point
(E
);
6216 Set_Has_Delayed_Aspects
(E
, False);
6222 -- AI05-0213: A formal incomplete type does not freeze the actual. In
6223 -- the instance, the same applies to the subtype renaming the actual.
6225 elsif Is_Private_Type
(E
)
6226 and then Is_Generic_Actual_Type
(E
)
6227 and then No
(Full_View
(Base_Type
(E
)))
6228 and then Ada_Version
>= Ada_2012
6233 -- Formal subprograms are never frozen
6235 elsif Is_Formal_Subprogram
(E
) then
6239 -- Generic types are never frozen as they lack delayed semantic checks
6241 elsif Is_Generic_Type
(E
) then
6245 -- Do not freeze a global entity within an inner scope created during
6246 -- expansion. A call to subprogram E within some internal procedure
6247 -- (a stream attribute for example) might require freezing E, but the
6248 -- freeze node must appear in the same declarative part as E itself.
6249 -- The two-pass elaboration mechanism in gigi guarantees that E will
6250 -- be frozen before the inner call is elaborated. We exclude constants
6251 -- from this test, because deferred constants may be frozen early, and
6252 -- must be diagnosed (e.g. in the case of a deferred constant being used
6253 -- in a default expression). If the enclosing subprogram comes from
6254 -- source, or is a generic instance, then the freeze point is the one
6255 -- mandated by the language, and we freeze the entity. A subprogram that
6256 -- is a child unit body that acts as a spec does not have a spec that
6257 -- comes from source, but can only come from source.
6259 elsif In_Open_Scopes
(Scope
(Test_E
))
6260 and then Scope
(Test_E
) /= Current_Scope
6261 and then Ekind
(Test_E
) /= E_Constant
6263 -- Here we deal with the special case of the expansion of
6264 -- postconditions. Previously this was handled by the loop below,
6265 -- since these postcondition checks got isolated to a separate,
6266 -- internally generated, subprogram. Now, however, the postcondition
6267 -- checks get contained within their corresponding subprogram
6270 if not Comes_From_Source
(N
)
6271 and then Nkind
(N
) = N_Pragma
6272 and then From_Aspect_Specification
(N
)
6273 and then Is_Valid_Assertion_Kind
(Original_Aspect_Pragma_Name
(N
))
6275 -- Now, verify the placement of the pragma is within an expanded
6276 -- subprogram which contains postcondition expansion - detected
6277 -- through the presence of the "Wrapped_Statements" field.
6279 and then Present
(Enclosing_Subprogram
(Current_Scope
))
6280 and then Present
(Wrapped_Statements
6281 (Enclosing_Subprogram
(Current_Scope
)))
6286 -- Otherwise, loop through scopes checking if an enclosing scope
6287 -- comes from source or is a generic. Note that, for the purpose
6288 -- of this test, we need to consider that the internally generated
6289 -- subprogram described above comes from source too if the original
6290 -- subprogram itself does.
6297 while Present
(S
) loop
6298 if Is_Overloadable
(S
) then
6299 if Comes_From_Source
(S
)
6300 or else (Chars
(S
) = Name_uWrapped_Statements
6301 and then Comes_From_Source
(Scope
(S
)))
6302 or else Is_Generic_Instance
(S
)
6303 or else Is_Child_Unit
(S
)
6316 -- Similarly, an inlined instance body may make reference to global
6317 -- entities, but these references cannot be the proper freezing point
6318 -- for them, and in the absence of inlining freezing will take place in
6319 -- their own scope. Normally instance bodies are analyzed after the
6320 -- enclosing compilation, and everything has been frozen at the proper
6321 -- place, but with front-end inlining an instance body is compiled
6322 -- before the end of the enclosing scope, and as a result out-of-order
6323 -- freezing must be prevented.
6325 elsif Front_End_Inlining
6326 and then In_Instance_Body
6327 and then Present
(Scope
(Test_E
))
6333 S
:= Scope
(Test_E
);
6334 while Present
(S
) loop
6335 if Is_Generic_Instance
(S
) then
6349 -- Add checks to detect proper initialization of scalars that may appear
6350 -- as subprogram parameters.
6352 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
6353 Apply_Parameter_Validity_Checks
(E
);
6356 -- Deal with delayed aspect specifications. The analysis of the aspect
6357 -- is required to be delayed to the freeze point, thus we analyze the
6358 -- pragma or attribute definition clause in the tree at this point. We
6359 -- also analyze the aspect specification node at the freeze point when
6360 -- the aspect doesn't correspond to pragma/attribute definition clause.
6361 -- In addition, a derived type may have inherited aspects that were
6362 -- delayed in the parent, so these must also be captured now.
6364 -- For a record type, we deal with the delayed aspect specifications on
6365 -- components first, which is consistent with the non-delayed case and
6366 -- makes it possible to have a single processing to detect conflicts.
6368 if Is_Record_Type
(E
) then
6372 Rec_Pushed
: Boolean := False;
6373 -- Set True if the record type E has been pushed on the scope
6374 -- stack. Needed for the analysis of delayed aspects specified
6375 -- to the components of Rec.
6378 Comp
:= First_Component
(E
);
6379 while Present
(Comp
) loop
6380 if Has_Delayed_Aspects
(Comp
) then
6381 if not Rec_Pushed
then
6385 -- The visibility to the discriminants must be restored
6386 -- in order to properly analyze the aspects.
6388 if Has_Discriminants
(E
) then
6389 Install_Discriminants
(E
);
6393 Analyze_Aspects_At_Freeze_Point
(Comp
);
6396 Next_Component
(Comp
);
6399 -- Pop the scope if Rec scope has been pushed on the scope stack
6400 -- during the delayed aspect analysis process.
6403 if Has_Discriminants
(E
) then
6404 Uninstall_Discriminants
(E
);
6412 if Has_Delayed_Aspects
(E
) then
6413 Analyze_Aspects_At_Freeze_Point
(E
);
6416 -- Here to freeze the entity
6420 -- Case of entity being frozen is other than a type
6422 if not Is_Type
(E
) then
6424 -- If entity is exported or imported and does not have an external
6425 -- name, now is the time to provide the appropriate default name.
6426 -- Skip this if the entity is stubbed, since we don't need a name
6427 -- for any stubbed routine. For the case on intrinsics, if no
6428 -- external name is specified, then calls will be handled in
6429 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
6430 -- external name is provided, then Expand_Intrinsic_Call leaves
6431 -- calls in place for expansion by GIGI.
6433 if (Is_Imported
(E
) or else Is_Exported
(E
))
6434 and then No
(Interface_Name
(E
))
6435 and then Convention
(E
) /= Convention_Stubbed
6436 and then Convention
(E
) /= Convention_Intrinsic
6438 Set_Encoded_Interface_Name
6439 (E
, Get_Default_External_Name
(E
));
6444 if Is_Subprogram
(E
) then
6446 -- Check for needing to wrap imported subprogram
6448 if not Inside_A_Generic
then
6449 Wrap_Imported_Subprogram
(E
);
6452 -- Freeze all parameter types and the return type (RM 13.14(14)).
6453 -- However skip this for internal subprograms. This is also where
6454 -- any extra formal parameters are created since we now know
6455 -- whether the subprogram will use a foreign convention.
6457 -- In Ada 2012, freezing a subprogram does not always freeze the
6458 -- corresponding profile (see AI05-019). An attribute reference
6459 -- is not a freezing point of the profile. Similarly, we do not
6460 -- freeze the profile of primitives of a library-level tagged type
6461 -- when we are building its dispatch table. Flag Do_Freeze_Profile
6462 -- indicates whether the profile should be frozen now.
6464 -- This processing doesn't apply to internal entities (see below)
6466 if not Is_Internal
(E
) and then Do_Freeze_Profile
then
6467 if not Freeze_Profile
(E
) then
6472 -- Must freeze its parent first if it is a derived subprogram
6474 if Present
(Alias
(E
)) then
6475 Freeze_And_Append
(Alias
(E
), N
, Result
);
6478 -- We don't freeze internal subprograms, because we don't normally
6479 -- want addition of extra formals or mechanism setting to happen
6480 -- for those. However we do pass through predefined dispatching
6481 -- cases, since extra formals may be needed in some cases, such as
6482 -- for the stream 'Input function (build-in-place formals).
6484 if not Is_Internal
(E
)
6485 or else Is_Predefined_Dispatching_Operation
(E
)
6487 Freeze_Subprogram
(E
);
6490 -- If warning on suspicious contracts then check for the case of
6491 -- a postcondition other than False for a No_Return subprogram.
6494 and then Warn_On_Suspicious_Contract
6495 and then Present
(Contract
(E
))
6498 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
6502 while Present
(Prag
) loop
6503 if Pragma_Name_Unmapped
(Prag
) in Name_Post
6504 | Name_Postcondition
6509 (First
(Pragma_Argument_Associations
(Prag
)));
6511 if Nkind
(Exp
) /= N_Identifier
6512 or else Chars
(Exp
) /= Name_False
6515 ("useless postcondition, & is marked "
6516 & "No_Return?.t?", Exp
, E
);
6520 Prag
:= Next_Pragma
(Prag
);
6525 -- Here for other than a subprogram or type
6528 -- If entity has a type declared in the current scope, and it is
6529 -- not a generic unit, then freeze it first.
6531 if Present
(Etype
(E
))
6532 and then Ekind
(E
) /= E_Generic_Function
6533 and then Within_Scope
(Etype
(E
), Current_Scope
)
6535 Freeze_And_Append
(Etype
(E
), N
, Result
);
6537 -- For an object of an anonymous array type, aspects on the
6538 -- object declaration apply to the type itself. This is the
6539 -- case for Atomic_Components, Volatile_Components, and
6540 -- Independent_Components. In these cases analysis of the
6541 -- generated pragma will mark the anonymous types accordingly,
6542 -- and the object itself does not require a freeze node.
6544 if Ekind
(E
) = E_Variable
6545 and then Is_Itype
(Etype
(E
))
6546 and then Is_Array_Type
(Etype
(E
))
6547 and then Has_Delayed_Aspects
(E
)
6549 Set_Has_Delayed_Aspects
(E
, False);
6550 Set_Has_Delayed_Freeze
(E
, False);
6551 Set_Freeze_Node
(E
, Empty
);
6555 -- Special processing for objects created by object declaration;
6556 -- we protect the call to Declaration_Node against entities of
6557 -- expressions replaced by the frontend with an N_Raise_CE node.
6559 if Ekind
(E
) in E_Constant | E_Variable
6560 and then Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
6562 Freeze_Object_Declaration
(E
);
6565 -- Check that a constant which has a pragma Volatile[_Components]
6566 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
6568 -- Note: Atomic[_Components] also sets Volatile[_Components]
6570 if Ekind
(E
) = E_Constant
6571 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
6572 and then not Is_Imported
(E
)
6573 and then not Has_Boolean_Aspect_Import
(E
)
6575 -- Make sure we actually have a pragma, and have not merely
6576 -- inherited the indication from elsewhere (e.g. an address
6577 -- clause, which is not good enough in RM terms).
6579 if Has_Rep_Pragma
(E
, Name_Atomic
)
6581 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
6584 ("standalone atomic constant must be " &
6585 "imported (RM C.6(13))", E
);
6587 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
6589 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
6592 ("standalone volatile constant must be " &
6593 "imported (RM C.6(13))", E
);
6597 -- Static objects require special handling
6599 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
6600 and then Is_Statically_Allocated
(E
)
6602 Freeze_Static_Object
(E
);
6605 -- Remaining step is to layout objects
6607 if Ekind
(E
) in E_Variable | E_Constant | E_Loop_Parameter
6608 or else Is_Formal
(E
)
6613 -- For an object that does not have delayed freezing, and whose
6614 -- initialization actions have been captured in a compound
6615 -- statement, move them back now directly within the enclosing
6616 -- statement sequence.
6618 if Ekind
(E
) in E_Constant | E_Variable
6619 and then not Has_Delayed_Freeze
(E
)
6621 Explode_Initialization_Compound_Statement
(E
);
6624 -- Do not generate a freeze node for a generic unit
6626 if Is_Generic_Unit
(E
) then
6632 -- Case of a type or subtype being frozen
6635 -- Verify several SPARK legality rules related to Ghost types now
6636 -- that the type is frozen.
6638 Check_Ghost_Type
(E
);
6640 -- We used to check here that a full type must have preelaborable
6641 -- initialization if it completes a private type specified with
6642 -- pragma Preelaborable_Initialization, but that missed cases where
6643 -- the types occur within a generic package, since the freezing
6644 -- that occurs within a containing scope generally skips traversal
6645 -- of a generic unit's declarations (those will be frozen within
6646 -- instances). This check was moved to Analyze_Package_Specification.
6648 -- The type may be defined in a generic unit. This can occur when
6649 -- freezing a generic function that returns the type (which is
6650 -- defined in a parent unit). It is clearly meaningless to freeze
6651 -- this type. However, if it is a subtype, its size may be determi-
6652 -- nable and used in subsequent checks, so might as well try to
6655 -- In Ada 2012, Freeze_Entities is also used in the front end to
6656 -- trigger the analysis of aspect expressions, so in this case we
6657 -- want to continue the freezing process.
6659 -- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead
6660 -- In_Generic_Scope (E)???
6662 if Present
(Scope
(E
))
6663 and then Is_Generic_Unit
(Scope
(E
))
6665 (not Has_Predicates
(E
)
6666 and then not Has_Delayed_Freeze
(E
))
6668 Check_Compile_Time_Size
(E
);
6673 -- Check for error of Type_Invariant'Class applied to an untagged
6674 -- type (check delayed to freeze time when full type is available).
6677 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
6680 and then Class_Present
(Prag
)
6681 and then not Is_Tagged_Type
(E
)
6684 ("Type_Invariant''Class cannot be specified for &", Prag
, E
);
6686 ("\can only be specified for a tagged type", Prag
);
6690 -- Deal with special cases of freezing for subtype
6692 if E
/= Base_Type
(E
) then
6694 -- Before we do anything else, a specific test for the case of a
6695 -- size given for an array where the array would need to be packed
6696 -- in order for the size to be honored, but is not. This is the
6697 -- case where implicit packing may apply. The reason we do this so
6698 -- early is that, if we have implicit packing, the layout of the
6699 -- base type is affected, so we must do this before we freeze the
6702 -- We could do this processing only if implicit packing is enabled
6703 -- since in all other cases, the error would be caught by the back
6704 -- end. However, we choose to do the check even if we do not have
6705 -- implicit packing enabled, since this allows us to give a more
6706 -- useful error message (advising use of pragma Implicit_Packing
6709 if Is_Array_Type
(E
) then
6711 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
6712 Rsiz
: constant Uint
:=
6713 (if Known_RM_Size
(Ctyp
) then RM_Size
(Ctyp
) else Uint_0
);
6714 SZ
: constant Node_Id
:= Size_Clause
(E
);
6715 Btyp
: constant Entity_Id
:= Base_Type
(E
);
6722 Num_Elmts
: Uint
:= Uint_1
;
6723 -- Number of elements in array
6726 -- Check enabling conditions. These are straightforward
6727 -- except for the test for a limited composite type. This
6728 -- eliminates the rare case of a array of limited components
6729 -- where there are issues of whether or not we can go ahead
6730 -- and pack the array (since we can't freely pack and unpack
6731 -- arrays if they are limited).
6733 -- Note that we check the root type explicitly because the
6734 -- whole point is we are doing this test before we have had
6735 -- a chance to freeze the base type (and it is that freeze
6736 -- action that causes stuff to be inherited).
6738 -- The conditions on the size are identical to those used in
6739 -- Freeze_Array_Type to set the Is_Packed flag.
6741 if Has_Size_Clause
(E
)
6742 and then Known_Static_RM_Size
(E
)
6743 and then not Is_Packed
(E
)
6744 and then not Has_Pragma_Pack
(E
)
6745 and then not Has_Component_Size_Clause
(E
)
6746 and then Known_Static_RM_Size
(Ctyp
)
6747 and then Rsiz
<= System_Max_Integer_Size
6748 and then not (Addressable
(Rsiz
)
6749 and then Known_Static_Esize
(Ctyp
)
6750 and then Esize
(Ctyp
) = Rsiz
)
6751 and then not (Rsiz
mod System_Storage_Unit
= 0
6752 and then Is_Composite_Type
(Ctyp
))
6753 and then not Is_Limited_Composite
(E
)
6754 and then not Is_Packed
(Root_Type
(E
))
6755 and then not Has_Component_Size_Clause
(Root_Type
(E
))
6756 and then not (CodePeer_Mode
or GNATprove_Mode
)
6758 -- Compute number of elements in array
6760 Indx
:= First_Index
(E
);
6761 while Present
(Indx
) loop
6762 Get_Index_Bounds
(Indx
, Lo
, Hi
);
6764 if not (Compile_Time_Known_Value
(Lo
)
6766 Compile_Time_Known_Value
(Hi
))
6768 goto No_Implicit_Packing
;
6771 Dim
:= Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1;
6773 if Dim
> Uint_0
then
6774 Num_Elmts
:= Num_Elmts
* Dim
;
6776 Num_Elmts
:= Uint_0
;
6782 -- What we are looking for here is the situation where
6783 -- the RM_Size given would be exactly right if there was
6784 -- a pragma Pack, resulting in the component size being
6785 -- the RM_Size of the component type.
6787 if RM_Size
(E
) = Num_Elmts
* Rsiz
then
6789 -- For implicit packing mode, just set the component
6790 -- size and Freeze_Array_Type will do the rest.
6792 if Implicit_Packing
then
6793 Set_Component_Size
(Btyp
, Rsiz
);
6795 -- Otherwise give an error message, except that if the
6796 -- specified Size is zero, there is no need for pragma
6797 -- Pack. Note that size zero is not considered
6800 elsif RM_Size
(E
) /= Uint_0
then
6802 ("size given for& too small", SZ
, E
);
6803 Error_Msg_N
-- CODEFIX
6804 ("\use explicit pragma Pack or use pragma "
6805 & "Implicit_Packing", SZ
);
6812 <<No_Implicit_Packing
>>
6814 -- If ancestor subtype present, freeze that first. Note that this
6815 -- will also get the base type frozen. Need RM reference ???
6817 Atype
:= Ancestor_Subtype
(E
);
6819 if Present
(Atype
) then
6820 Freeze_And_Append
(Atype
, N
, Result
);
6822 -- No ancestor subtype present
6825 -- See if we have a nearest ancestor that has a predicate.
6826 -- That catches the case of derived type with a predicate.
6827 -- Need RM reference here ???
6829 Atype
:= Nearest_Ancestor
(E
);
6831 if Present
(Atype
) and then Has_Predicates
(Atype
) then
6832 Freeze_And_Append
(Atype
, N
, Result
);
6835 -- Freeze base type before freezing the entity (RM 13.14(15))
6837 if E
/= Base_Type
(E
) then
6838 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
6842 -- A subtype inherits all the type-related representation aspects
6843 -- from its parents (RM 13.1(8)).
6845 if May_Inherit_Delayed_Rep_Aspects
(E
) then
6846 Inherit_Delayed_Rep_Aspects
(E
);
6849 Inherit_Aspects_At_Freeze_Point
(E
);
6851 -- For a derived type, freeze its parent type first (RM 13.14(15))
6853 elsif Is_Derived_Type
(E
) then
6854 Freeze_And_Append
(Etype
(E
), N
, Result
);
6856 -- A derived type inherits each type-related representation aspect
6857 -- of its parent type that was directly specified before the
6858 -- declaration of the derived type (RM 13.1(15)).
6860 if May_Inherit_Delayed_Rep_Aspects
(E
) then
6861 Inherit_Delayed_Rep_Aspects
(E
);
6864 Inherit_Aspects_At_Freeze_Point
(E
);
6867 -- Case of array type
6869 if Is_Array_Type
(E
) then
6870 Freeze_Array_Type
(E
);
6873 -- Check for incompatible size and alignment for array/record type
6875 if Warn_On_Size_Alignment
6876 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
6877 and then Has_Size_Clause
(E
)
6878 and then Has_Alignment_Clause
(E
)
6880 -- If explicit Object_Size clause given assume that the programmer
6881 -- knows what he is doing, and expects the compiler behavior.
6883 and then not Has_Object_Size_Clause
(E
)
6885 -- It does not really make sense to warn for the minimum alignment
6886 -- since the programmer could not get rid of the warning.
6888 and then Alignment
(E
) > 1
6890 -- Check for size not a multiple of alignment
6892 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
6895 SC
: constant Node_Id
:= Size_Clause
(E
);
6896 AC
: constant Node_Id
:= Alignment_Clause
(E
);
6898 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
6901 if Present
(SC
) and then Present
(AC
) then
6905 if Sloc
(SC
) > Sloc
(AC
) then
6908 ("?.z?size is not a multiple of alignment for &",
6910 Error_Msg_Sloc
:= Sloc
(AC
);
6911 Error_Msg_Uint_1
:= Alignment
(E
);
6912 Error_Msg_N
("\?.z?alignment of ^ specified #", Loc
);
6917 ("?.z?size is not a multiple of alignment for &",
6919 Error_Msg_Sloc
:= Sloc
(SC
);
6920 Error_Msg_Uint_1
:= RM_Size
(E
);
6921 Error_Msg_N
("\?.z?size of ^ specified #", Loc
);
6924 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
6925 Error_Msg_N
("\?.z?Object_Size will be increased to ^", Loc
);
6930 -- For a class-wide type, the corresponding specific type is
6931 -- frozen as well (RM 13.14(15))
6933 if Is_Class_Wide_Type
(E
) then
6934 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
6936 -- If the base type of the class-wide type is still incomplete,
6937 -- the class-wide remains unfrozen as well. This is legal when
6938 -- E is the formal of a primitive operation of some other type
6939 -- which is being frozen.
6941 if not Is_Frozen
(Root_Type
(E
)) then
6942 Set_Is_Frozen
(E
, False);
6946 -- The equivalent type associated with a class-wide subtype needs
6947 -- to be frozen to ensure that its layout is done.
6949 if Ekind
(E
) = E_Class_Wide_Subtype
6950 and then Present
(Equivalent_Type
(E
))
6952 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
6955 -- Generate an itype reference for a library-level class-wide type
6956 -- at the freeze point. Otherwise the first explicit reference to
6957 -- the type may appear in an inner scope which will be rejected by
6961 and then Is_Compilation_Unit
(Scope
(E
))
6964 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
6969 -- From a gigi point of view, a class-wide subtype derives
6970 -- from its record equivalent type. As a result, the itype
6971 -- reference must appear after the freeze node of the
6972 -- equivalent type or gigi will reject the reference.
6974 if Ekind
(E
) = E_Class_Wide_Subtype
6975 and then Present
(Equivalent_Type
(E
))
6977 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
6979 Add_To_Result
(Ref
);
6984 -- For a record type or record subtype, freeze all component types
6985 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
6986 -- using Is_Record_Type, because we don't want to attempt the freeze
6987 -- for the case of a private type with record extension (we will do
6988 -- that later when the full type is frozen).
6990 elsif Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
6991 if not In_Generic_Scope
(E
) then
6992 Freeze_Record_Type
(E
);
6995 -- Report a warning if a discriminated record base type has a
6996 -- convention with language C or C++ applied to it. This check is
6997 -- done even within generic scopes (but not in instantiations),
6998 -- which is why we don't do it as part of Freeze_Record_Type.
7000 Check_Suspicious_Convention
(E
);
7002 -- For a concurrent type, freeze corresponding record type. This does
7003 -- not correspond to any specific rule in the RM, but the record type
7004 -- is essentially part of the concurrent type. Also freeze all local
7005 -- entities. This includes record types created for entry parameter
7006 -- blocks and whatever local entities may appear in the private part.
7008 elsif Is_Concurrent_Type
(E
) then
7009 if Present
(Corresponding_Record_Type
(E
)) then
7010 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
7013 Comp
:= First_Entity
(E
);
7014 while Present
(Comp
) loop
7015 if Is_Type
(Comp
) then
7016 Freeze_And_Append
(Comp
, N
, Result
);
7018 elsif (Ekind
(Comp
)) /= E_Function
then
7020 -- The guard on the presence of the Etype seems to be needed
7021 -- for some CodePeer (-gnatcC) cases, but not clear why???
7023 if Present
(Etype
(Comp
)) then
7024 if Is_Itype
(Etype
(Comp
))
7025 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
7027 Undelay_Type
(Etype
(Comp
));
7030 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
7037 -- Private types are required to point to the same freeze node as
7038 -- their corresponding full views. The freeze node itself has to
7039 -- point to the partial view of the entity (because from the partial
7040 -- view, we can retrieve the full view, but not the reverse).
7041 -- However, in order to freeze correctly, we need to freeze the full
7042 -- view. If we are freezing at the end of a scope (or within the
7043 -- scope) of the private type, the partial and full views will have
7044 -- been swapped, the full view appears first in the entity chain and
7045 -- the swapping mechanism ensures that the pointers are properly set
7048 -- If we encounter the partial view before the full view (e.g. when
7049 -- freezing from another scope), we freeze the full view, and then
7050 -- set the pointers appropriately since we cannot rely on swapping to
7051 -- fix things up (subtypes in an outer scope might not get swapped).
7053 -- If the full view is itself private, the above requirements apply
7054 -- to the underlying full view instead of the full view. But there is
7055 -- no swapping mechanism for the underlying full view so we need to
7056 -- set the pointers appropriately in both cases.
7058 elsif Is_Incomplete_Or_Private_Type
(E
)
7059 and then not Is_Generic_Type
(E
)
7061 -- The construction of the dispatch table associated with library
7062 -- level tagged types forces freezing of all the primitives of the
7063 -- type, which may cause premature freezing of the partial view.
7067 -- type T is tagged private;
7068 -- type DT is new T with private;
7069 -- procedure Prim (X : in out T; Y : in out DT'Class);
7071 -- type T is tagged null record;
7073 -- type DT is new T with null record;
7076 -- In this case the type will be frozen later by the usual
7077 -- mechanism: an object declaration, an instantiation, or the
7078 -- end of a declarative part.
7080 if Is_Library_Level_Tagged_Type
(E
)
7081 and then No
(Full_View
(E
))
7083 Set_Is_Frozen
(E
, False);
7086 -- Case of full view present
7088 elsif Present
(Full_View
(E
)) then
7090 -- If full view has already been frozen, then no further
7091 -- processing is required
7093 if Is_Frozen
(Full_View
(E
)) then
7094 Set_Has_Delayed_Freeze
(E
, False);
7095 Set_Freeze_Node
(E
, Empty
);
7097 -- Otherwise freeze full view and patch the pointers so that
7098 -- the freeze node will elaborate both views in the back end.
7099 -- However, if full view is itself private, freeze underlying
7100 -- full view instead and patch the pointers so that the freeze
7101 -- node will elaborate the three views in the back end.
7105 Full
: Entity_Id
:= Full_View
(E
);
7108 if Is_Private_Type
(Full
)
7109 and then Present
(Underlying_Full_View
(Full
))
7111 Full
:= Underlying_Full_View
(Full
);
7114 Freeze_And_Append
(Full
, N
, Result
);
7116 if Full
/= Full_View
(E
)
7117 and then Has_Delayed_Freeze
(Full_View
(E
))
7119 F_Node
:= Freeze_Node
(Full
);
7121 if Present
(F_Node
) then
7123 (Fnod
=> F_Node
, Typ
=> Full_View
(E
));
7125 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
7126 Set_Freeze_Node
(Full_View
(E
), Empty
);
7130 if Has_Delayed_Freeze
(E
) then
7131 F_Node
:= Freeze_Node
(Full_View
(E
));
7133 if Present
(F_Node
) then
7134 Inherit_Freeze_Node
(Fnod
=> F_Node
, Typ
=> E
);
7136 -- {Incomplete,Private}_Subtypes with Full_Views
7137 -- constrained by discriminants.
7139 Set_Has_Delayed_Freeze
(E
, False);
7140 Set_Freeze_Node
(E
, Empty
);
7146 Check_Debug_Info_Needed
(E
);
7148 -- AI95-117 requires that the convention of a partial view be
7149 -- the same as the convention of the full view. Note that this
7150 -- is a recognized breach of privacy, but it's essential for
7151 -- logical consistency of representation, and the lack of a
7152 -- rule in RM95 was an oversight.
7154 Set_Convention
(E
, Convention
(Full_View
(E
)));
7156 Set_Size_Known_At_Compile_Time
(E
,
7157 Size_Known_At_Compile_Time
(Full_View
(E
)));
7159 -- Size information is copied from the full view to the
7160 -- incomplete or private view for consistency.
7162 -- We skip this is the full view is not a type. This is very
7163 -- strange of course, and can only happen as a result of
7164 -- certain illegalities, such as a premature attempt to derive
7165 -- from an incomplete type.
7167 if Is_Type
(Full_View
(E
)) then
7168 Set_Size_Info
(E
, Full_View
(E
));
7169 Copy_RM_Size
(To
=> E
, From
=> Full_View
(E
));
7174 -- Case of underlying full view present
7176 elsif Is_Private_Type
(E
)
7177 and then Present
(Underlying_Full_View
(E
))
7179 if not Is_Frozen
(Underlying_Full_View
(E
)) then
7180 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
7183 -- Patch the pointers so that the freeze node will elaborate
7184 -- both views in the back end.
7186 if Has_Delayed_Freeze
(E
) then
7187 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
7189 if Present
(F_Node
) then
7194 Set_Has_Delayed_Freeze
(E
, False);
7195 Set_Freeze_Node
(E
, Empty
);
7199 Check_Debug_Info_Needed
(E
);
7203 -- Case of no full view present. If entity is subtype or derived,
7204 -- it is safe to freeze, correctness depends on the frozen status
7205 -- of parent. Otherwise it is either premature usage, or a Taft
7206 -- amendment type, so diagnosis is at the point of use and the
7207 -- type might be frozen later.
7209 elsif E
/= Base_Type
(E
) then
7211 Btyp
: constant Entity_Id
:= Base_Type
(E
);
7214 -- However, if the base type is itself private and has no
7215 -- (underlying) full view either, wait until the full type
7216 -- declaration is seen and all the full views are created.
7218 if Is_Private_Type
(Btyp
)
7219 and then No
(Full_View
(Btyp
))
7220 and then No
(Underlying_Full_View
(Btyp
))
7221 and then Has_Delayed_Freeze
(Btyp
)
7222 and then No
(Freeze_Node
(Btyp
))
7224 Set_Is_Frozen
(E
, False);
7230 elsif Is_Derived_Type
(E
) then
7234 Set_Is_Frozen
(E
, False);
7239 -- For access subprogram, freeze types of all formals, the return
7240 -- type was already frozen, since it is the Etype of the function.
7241 -- Formal types can be tagged Taft amendment types, but otherwise
7242 -- they cannot be incomplete.
7244 elsif Ekind
(E
) = E_Subprogram_Type
then
7245 Formal
:= First_Formal
(E
);
7246 while Present
(Formal
) loop
7247 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
7248 and then No
(Full_View
(Etype
(Formal
)))
7250 if Is_Tagged_Type
(Etype
(Formal
)) then
7253 -- AI05-151: Incomplete types are allowed in access to
7254 -- subprogram specifications.
7256 elsif Ada_Version
< Ada_2012
then
7258 ("invalid use of incomplete type&", E
, Etype
(Formal
));
7262 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
7263 Next_Formal
(Formal
);
7266 Freeze_Subprogram
(E
);
7268 -- For access to a protected subprogram, freeze the equivalent type
7269 -- (however this is not set if we are not generating code or if this
7270 -- is an anonymous type used just for resolution).
7272 elsif Is_Access_Protected_Subprogram_Type
(E
) then
7273 if Present
(Equivalent_Type
(E
)) then
7274 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
7278 -- Generic types are never seen by the back-end, and are also not
7279 -- processed by the expander (since the expander is turned off for
7280 -- generic processing), so we never need freeze nodes for them.
7282 if Is_Generic_Type
(E
) then
7286 -- Some special processing for non-generic types to complete
7287 -- representation details not known till the freeze point.
7289 if Is_Fixed_Point_Type
(E
) then
7290 Freeze_Fixed_Point_Type
(E
);
7292 elsif Is_Enumeration_Type
(E
) then
7293 Freeze_Enumeration_Type
(E
);
7295 elsif Is_Integer_Type
(E
) then
7296 Adjust_Esize_For_Alignment
(E
);
7298 if Is_Modular_Integer_Type
(E
) then
7299 -- Standard_Address has been built with the assumption that its
7300 -- modulus was System_Address_Size, but this is not a universal
7301 -- property and may need to be corrected.
7303 if Is_RTE
(E
, RE_Address
) then
7304 Set_Modulus
(Standard_Address
, Modulus
(E
));
7306 (High_Bound
(Scalar_Range
(Standard_Address
)),
7309 elsif Warn_On_Suspicious_Modulus_Value
then
7310 Check_Suspicious_Modulus
(E
);
7314 -- The pool applies to named and anonymous access types, but not
7315 -- to subprogram and to internal types generated for 'Access
7318 elsif Is_Access_Object_Type
(E
)
7319 and then Ekind
(E
) /= E_Access_Attribute_Type
7321 -- If a pragma Default_Storage_Pool applies, and this type has no
7322 -- Storage_Pool or Storage_Size clause (which must have occurred
7323 -- before the freezing point), then use the default. This applies
7324 -- only to base types.
7326 -- None of this applies to access to subprograms, for which there
7327 -- are clearly no pools.
7329 if Present
(Default_Pool
)
7330 and then Is_Base_Type
(E
)
7331 and then not Has_Storage_Size_Clause
(E
)
7332 and then No
(Associated_Storage_Pool
(E
))
7334 -- Case of pragma Default_Storage_Pool (null)
7336 if Nkind
(Default_Pool
) = N_Null
then
7337 Set_No_Pool_Assigned
(E
);
7339 -- Case of pragma Default_Storage_Pool (Standard)
7341 elsif Entity
(Default_Pool
) = Standard_Standard
then
7342 Set_Associated_Storage_Pool
(E
, RTE
(RE_Global_Pool_Object
));
7344 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
7347 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
7351 -- Check restriction for standard storage pool
7353 if No
(Associated_Storage_Pool
(E
)) then
7354 Check_Restriction
(No_Standard_Storage_Pools
, E
);
7357 -- Deal with error message for pure access type. This is not an
7358 -- error in Ada 2005 if there is no pool (see AI-366).
7360 if Is_Pure_Unit_Access_Type
(E
)
7361 and then (Ada_Version
< Ada_2005
7362 or else not No_Pool_Assigned
(E
))
7363 and then not Is_Generic_Unit
(Scope
(E
))
7365 Error_Msg_N
("named access type not allowed in pure unit", E
);
7367 if Ada_Version
>= Ada_2005
then
7369 ("\would be legal if Storage_Size of 0 given??", E
);
7371 elsif No_Pool_Assigned
(E
) then
7373 ("\would be legal in Ada 2005??", E
);
7377 ("\would be legal in Ada 2005 if "
7378 & "Storage_Size of 0 given??", E
);
7383 -- Case of composite types
7385 if Is_Composite_Type
(E
) then
7387 -- AI95-117 requires that all new primitives of a tagged type must
7388 -- inherit the convention of the full view of the type. Inherited
7389 -- and overriding operations are defined to inherit the convention
7390 -- of their parent or overridden subprogram (also specified in
7391 -- AI-117), which will have occurred earlier (in Derive_Subprogram
7392 -- and New_Overloaded_Entity). Here we set the convention of
7393 -- primitives that are still convention Ada, which will ensure
7394 -- that any new primitives inherit the type's convention. Class-
7395 -- wide types can have a foreign convention inherited from their
7396 -- specific type, but are excluded from this since they don't have
7397 -- any associated primitives.
7399 if Is_Tagged_Type
(E
)
7400 and then not Is_Class_Wide_Type
(E
)
7401 and then Convention
(E
) /= Convention_Ada
7404 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
7408 Prim
:= First_Elmt
(Prim_List
);
7409 while Present
(Prim
) loop
7410 if Convention
(Node
(Prim
)) = Convention_Ada
then
7411 Set_Convention
(Node
(Prim
), Convention
(E
));
7419 -- If the type is a simple storage pool type, then this is where
7420 -- we attempt to locate and validate its Allocate, Deallocate, and
7421 -- Storage_Size operations (the first is required, and the latter
7422 -- two are optional). We also verify that the full type for a
7423 -- private type is allowed to be a simple storage pool type.
7425 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
7426 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
7428 -- If the type is marked Has_Private_Declaration, then this is
7429 -- a full type for a private type that was specified with the
7430 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
7431 -- pragma is allowed for the full type (for example, it can't
7432 -- be an array type, or a nonlimited record type).
7434 if Has_Private_Declaration
(E
) then
7435 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
7436 and then not Is_Private_Type
(E
)
7438 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
7440 ("pragma% can only apply to full type that is an " &
7441 "explicitly limited type", E
);
7445 Validate_Simple_Pool_Ops
: declare
7446 Pool_Type
: Entity_Id
renames E
;
7447 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
7448 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
7450 procedure Validate_Simple_Pool_Op_Formal
7451 (Pool_Op
: Entity_Id
;
7452 Pool_Op_Formal
: in out Entity_Id
;
7453 Expected_Mode
: Formal_Kind
;
7454 Expected_Type
: Entity_Id
;
7455 Formal_Name
: String;
7456 OK_Formal
: in out Boolean);
7457 -- Validate one formal Pool_Op_Formal of the candidate pool
7458 -- operation Pool_Op. The formal must be of Expected_Type
7459 -- and have mode Expected_Mode. OK_Formal will be set to
7460 -- False if the formal doesn't match. If OK_Formal is False
7461 -- on entry, then the formal will effectively be ignored
7462 -- (because validation of the pool op has already failed).
7463 -- Upon return, Pool_Op_Formal will be updated to the next
7466 procedure Validate_Simple_Pool_Operation
7467 (Op_Name
: Name_Id
);
7468 -- Search for and validate a simple pool operation with the
7469 -- name Op_Name. If the name is Allocate, then there must be
7470 -- exactly one such primitive operation for the simple pool
7471 -- type. If the name is Deallocate or Storage_Size, then
7472 -- there can be at most one such primitive operation. The
7473 -- profile of the located primitive must conform to what
7474 -- is expected for each operation.
7476 ------------------------------------
7477 -- Validate_Simple_Pool_Op_Formal --
7478 ------------------------------------
7480 procedure Validate_Simple_Pool_Op_Formal
7481 (Pool_Op
: Entity_Id
;
7482 Pool_Op_Formal
: in out Entity_Id
;
7483 Expected_Mode
: Formal_Kind
;
7484 Expected_Type
: Entity_Id
;
7485 Formal_Name
: String;
7486 OK_Formal
: in out Boolean)
7489 -- If OK_Formal is False on entry, then simply ignore
7490 -- the formal, because an earlier formal has already
7493 if not OK_Formal
then
7496 -- If no formal is passed in, then issue an error for a
7499 elsif No
(Pool_Op_Formal
) then
7501 ("simple storage pool op missing formal " &
7502 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
7508 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
7510 -- If the pool type was expected for this formal, then
7511 -- this will not be considered a candidate operation
7512 -- for the simple pool, so we unset OK_Formal so that
7513 -- the op and any later formals will be ignored.
7515 if Expected_Type
= Pool_Type
then
7522 ("wrong type for formal " & Formal_Name
&
7523 " of simple storage pool op; expected type&",
7524 Pool_Op_Formal
, Expected_Type
);
7528 -- Issue error if formal's mode is not the expected one
7530 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
7532 ("wrong mode for formal of simple storage pool op",
7536 -- Advance to the next formal
7538 Next_Formal
(Pool_Op_Formal
);
7539 end Validate_Simple_Pool_Op_Formal
;
7541 ------------------------------------
7542 -- Validate_Simple_Pool_Operation --
7543 ------------------------------------
7545 procedure Validate_Simple_Pool_Operation
7549 Found_Op
: Entity_Id
:= Empty
;
7555 (Op_Name
in Name_Allocate
7557 | Name_Storage_Size
);
7559 Error_Msg_Name_1
:= Op_Name
;
7561 -- For each homonym declared immediately in the scope
7562 -- of the simple storage pool type, determine whether
7563 -- the homonym is an operation of the pool type, and,
7564 -- if so, check that its profile is as expected for
7565 -- a simple pool operation of that name.
7567 Op
:= Get_Name_Entity_Id
(Op_Name
);
7568 while Present
(Op
) loop
7569 if Ekind
(Op
) in E_Function | E_Procedure
7570 and then Scope
(Op
) = Current_Scope
7572 Formal
:= First_Entity
(Op
);
7576 -- The first parameter must be of the pool type
7577 -- in order for the operation to qualify.
7579 if Op_Name
= Name_Storage_Size
then
7580 Validate_Simple_Pool_Op_Formal
7581 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
7584 Validate_Simple_Pool_Op_Formal
7585 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
7589 -- If another operation with this name has already
7590 -- been located for the type, then flag an error,
7591 -- since we only allow the type to have a single
7594 if Present
(Found_Op
) and then Is_OK
then
7596 ("only one % operation allowed for " &
7597 "simple storage pool type&", Op
, Pool_Type
);
7600 -- In the case of Allocate and Deallocate, a formal
7601 -- of type System.Address is required.
7603 if Op_Name
= Name_Allocate
then
7604 Validate_Simple_Pool_Op_Formal
7605 (Op
, Formal
, E_Out_Parameter
,
7606 Address_Type
, "Storage_Address", Is_OK
);
7608 elsif Op_Name
= Name_Deallocate
then
7609 Validate_Simple_Pool_Op_Formal
7610 (Op
, Formal
, E_In_Parameter
,
7611 Address_Type
, "Storage_Address", Is_OK
);
7614 -- In the case of Allocate and Deallocate, formals
7615 -- of type Storage_Count are required as the third
7616 -- and fourth parameters.
7618 if Op_Name
/= Name_Storage_Size
then
7619 Validate_Simple_Pool_Op_Formal
7620 (Op
, Formal
, E_In_Parameter
,
7621 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
7622 Validate_Simple_Pool_Op_Formal
7623 (Op
, Formal
, E_In_Parameter
,
7624 Stg_Cnt_Type
, "Alignment", Is_OK
);
7627 -- If no mismatched formals have been found (Is_OK)
7628 -- and no excess formals are present, then this
7629 -- operation has been validated, so record it.
7631 if No
(Formal
) and then Is_OK
then
7639 -- There must be a valid Allocate operation for the type,
7640 -- so issue an error if none was found.
7642 if Op_Name
= Name_Allocate
7643 and then No
(Found_Op
)
7645 Error_Msg_N
("missing % operation for simple " &
7646 "storage pool type", Pool_Type
);
7648 elsif Present
(Found_Op
) then
7650 -- Simple pool operations can't be abstract
7652 if Is_Abstract_Subprogram
(Found_Op
) then
7654 ("simple storage pool operation must not be " &
7655 "abstract", Found_Op
);
7658 -- The Storage_Size operation must be a function with
7659 -- Storage_Count as its result type.
7661 if Op_Name
= Name_Storage_Size
then
7662 if Ekind
(Found_Op
) = E_Procedure
then
7664 ("% operation must be a function", Found_Op
);
7666 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
7668 ("wrong result type for%, expected type&",
7669 Found_Op
, Stg_Cnt_Type
);
7672 -- Allocate and Deallocate must be procedures
7674 elsif Ekind
(Found_Op
) = E_Function
then
7676 ("% operation must be a procedure", Found_Op
);
7679 end Validate_Simple_Pool_Operation
;
7681 -- Start of processing for Validate_Simple_Pool_Ops
7684 Validate_Simple_Pool_Operation
(Name_Allocate
);
7685 Validate_Simple_Pool_Operation
(Name_Deallocate
);
7686 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
7687 end Validate_Simple_Pool_Ops
;
7691 -- Now that all types from which E may depend are frozen, see if
7692 -- strict alignment is required, a component clause on a record
7693 -- is correct, the size is known at compile time and if it must
7694 -- be unsigned, in that order.
7696 if Base_Type
(E
) = E
then
7697 Check_Strict_Alignment
(E
);
7700 if Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
7702 RC
: constant Node_Id
:= Get_Record_Representation_Clause
(E
);
7704 if Present
(RC
) then
7705 Check_Record_Representation_Clause
(RC
);
7710 Check_Compile_Time_Size
(E
);
7712 Check_Unsigned_Type
(E
);
7714 -- Do not allow a size clause for a type which does not have a size
7715 -- that is known at compile time
7717 if (Has_Size_Clause
(E
) or else Has_Object_Size_Clause
(E
))
7718 and then not Size_Known_At_Compile_Time
(E
)
7720 -- Suppress this message if errors posted on E, even if we are
7721 -- in all errors mode, since this is often a junk message
7723 if not Error_Posted
(E
) then
7725 ("size clause not allowed for variable length type",
7730 -- Now we set/verify the representation information, in particular
7731 -- the size and alignment values. This processing is not required for
7732 -- generic types, since generic types do not play any part in code
7733 -- generation, and so the size and alignment values for such types
7734 -- are irrelevant. Ditto for types declared within a generic unit,
7735 -- which may have components that depend on generic parameters, and
7736 -- that will be recreated in an instance.
7738 if Inside_A_Generic
then
7741 -- Otherwise we call the layout procedure
7747 -- If this is an access to subprogram whose designated type is itself
7748 -- a subprogram type, the return type of this anonymous subprogram
7749 -- type must be decorated as well.
7751 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
7752 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
7754 Layout_Type
(Etype
(Designated_Type
(E
)));
7757 -- If the type has a Defaut_Value/Default_Component_Value aspect,
7758 -- this is where we analyze the expression (after the type is frozen,
7759 -- since in the case of Default_Value, we are analyzing with the
7760 -- type itself, and we treat Default_Component_Value similarly for
7761 -- the sake of uniformity).
7763 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
7770 if Is_Scalar_Type
(E
) then
7771 Nam
:= Name_Default_Value
;
7773 Exp
:= Default_Aspect_Value
(Typ
);
7775 Nam
:= Name_Default_Component_Value
;
7776 Typ
:= Component_Type
(E
);
7777 Exp
:= Default_Aspect_Component_Value
(E
);
7780 Analyze_And_Resolve
(Exp
, Typ
);
7782 if Etype
(Exp
) /= Any_Type
then
7783 if not Is_OK_Static_Expression
(Exp
) then
7784 Error_Msg_Name_1
:= Nam
;
7785 Flag_Non_Static_Expr
7786 ("aspect% requires static expression", Exp
);
7792 -- Verify at this point that No_Controlled_Parts and No_Task_Parts,
7793 -- when specified on the current type or one of its ancestors, has
7794 -- not been overridden and that no violation of the aspect has
7797 -- It is important that we perform the checks here after the type has
7798 -- been processed because if said type depended on a private type it
7799 -- will not have been marked controlled or having tasks.
7801 Check_No_Parts_Violations
(E
, Aspect_No_Controlled_Parts
);
7802 Check_No_Parts_Violations
(E
, Aspect_No_Task_Parts
);
7804 -- End of freeze processing for type entities
7807 -- Here is where we logically freeze the current entity. If it has a
7808 -- freeze node, then this is the point at which the freeze node is
7809 -- linked into the result list.
7811 if Has_Delayed_Freeze
(E
) then
7813 -- If a freeze node is already allocated, use it, otherwise allocate
7814 -- a new one. The preallocation happens in the case of anonymous base
7815 -- types, where we preallocate so that we can set First_Subtype_Link.
7816 -- Note that we reset the Sloc to the current freeze location.
7818 if Present
(Freeze_Node
(E
)) then
7819 F_Node
:= Freeze_Node
(E
);
7820 Set_Sloc
(F_Node
, Loc
);
7823 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
7824 Set_Freeze_Node
(E
, F_Node
);
7825 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
7826 Set_TSS_Elist
(F_Node
, No_Elist
);
7827 Set_Actions
(F_Node
, No_List
);
7830 Set_Entity
(F_Node
, E
);
7831 Add_To_Result
(F_Node
);
7833 -- A final pass over record types with discriminants. If the type
7834 -- has an incomplete declaration, there may be constrained access
7835 -- subtypes declared elsewhere, which do not depend on the discrimi-
7836 -- nants of the type, and which are used as component types (i.e.
7837 -- the full view is a recursive type). The designated types of these
7838 -- subtypes can only be elaborated after the type itself, and they
7839 -- need an itype reference.
7841 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
7848 Comp
:= First_Component
(E
);
7849 while Present
(Comp
) loop
7850 Typ
:= Etype
(Comp
);
7852 if Is_Access_Type
(Typ
)
7853 and then Scope
(Typ
) /= E
7854 and then Base_Type
(Designated_Type
(Typ
)) = E
7855 and then Is_Itype
(Designated_Type
(Typ
))
7857 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
7858 Set_Itype
(IR
, Designated_Type
(Typ
));
7859 Append
(IR
, Result
);
7862 Next_Component
(Comp
);
7868 -- When a type is frozen, the first subtype of the type is frozen as
7869 -- well (RM 13.14(15)). This has to be done after freezing the type,
7870 -- since obviously the first subtype depends on its own base type.
7873 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
7875 -- If we just froze a tagged non-class-wide record, then freeze the
7876 -- corresponding class-wide type. This must be done after the tagged
7877 -- type itself is frozen, because the class-wide type refers to the
7878 -- tagged type which generates the class.
7880 -- For a tagged type, freeze explicitly those primitive operations
7881 -- that are expression functions, which otherwise have no clear
7882 -- freeze point: these have to be frozen before the dispatch table
7883 -- for the type is built, and before any explicit call to the
7884 -- primitive, which would otherwise be the freeze point for it.
7886 if Is_Tagged_Type
(E
)
7887 and then not Is_Class_Wide_Type
(E
)
7888 and then Present
(Class_Wide_Type
(E
))
7890 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
7893 Ops
: constant Elist_Id
:= Primitive_Operations
(E
);
7899 if Ops
/= No_Elist
then
7900 Elmt
:= First_Elmt
(Ops
);
7901 while Present
(Elmt
) loop
7902 Subp
:= Node
(Elmt
);
7903 if Is_Expression_Function
(Subp
) then
7904 Freeze_And_Append
(Subp
, N
, Result
);
7914 Check_Debug_Info_Needed
(E
);
7916 -- If subprogram has address clause then reset Is_Public flag, since we
7917 -- do not want the backend to generate external references.
7919 if Is_Subprogram
(E
)
7920 and then Present
(Address_Clause
(E
))
7921 and then not Is_Library_Level_Entity
(E
)
7923 Set_Is_Public
(E
, False);
7926 -- The Ghost mode of the enclosing context is ignored, while the
7927 -- entity being frozen is living. Insert the freezing action prior
7928 -- to the start of the enclosing ignored Ghost region. As a result
7929 -- the freezeing action will be preserved when the ignored Ghost
7930 -- context is eliminated. The insertion must take place even when
7931 -- the context is a spec expression, otherwise "Handling of Default
7932 -- and Per-Object Expressions" will suppress the insertion, and the
7933 -- freeze node will be dropped on the floor.
7935 if Saved_GM
= Ignore
7936 and then Ghost_Mode
/= Ignore
7937 and then Present
(Ignored_Ghost_Region
)
7940 (Assoc_Node
=> Ignored_Ghost_Region
,
7941 Ins_Actions
=> Result
,
7942 Spec_Expr_OK
=> True);
7948 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
7953 -----------------------------
7954 -- Freeze_Enumeration_Type --
7955 -----------------------------
7957 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
7959 -- By default, if no size clause is present, an enumeration type with
7960 -- Convention C is assumed to interface to a C enum and has integer
7961 -- size, except for a boolean type because it is assumed to interface
7962 -- to _Bool introduced in C99. This applies to types. For subtypes,
7963 -- verify that its base type has no size clause either. Treat other
7964 -- foreign conventions in the same way, and also make sure alignment
7967 if Has_Foreign_Convention
(Typ
)
7968 and then not Is_Boolean_Type
(Typ
)
7969 and then not Has_Size_Clause
(Typ
)
7970 and then not Has_Size_Clause
(Base_Type
(Typ
))
7971 and then Esize
(Typ
) < Standard_Integer_Size
7973 -- Don't do this if Short_Enums on target
7975 and then not Target_Short_Enums
7977 Set_Esize
(Typ
, UI_From_Int
(Standard_Integer_Size
));
7978 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
7980 -- Normal Ada case or size clause present or not Long_C_Enums on target
7983 -- If the enumeration type interfaces to C, and it has a size clause
7984 -- that is smaller than the size of int, it warrants a warning. The
7985 -- user may intend the C type to be a boolean or a char, so this is
7986 -- not by itself an error that the Ada compiler can detect, but it
7987 -- is worth a heads-up. For Boolean and Character types we
7988 -- assume that the programmer has the proper C type in mind.
7989 -- For explicit sizes larger than int, assume the user knows what
7990 -- he is doing and that the code is intentional.
7992 if Convention
(Typ
) = Convention_C
7993 and then Has_Size_Clause
(Typ
)
7994 and then Esize
(Typ
) < Standard_Integer_Size
7995 and then not Is_Boolean_Type
(Typ
)
7996 and then not Is_Character_Type
(Typ
)
7998 -- Don't do this if Short_Enums on target
8000 and then not Target_Short_Enums
8003 ("??the size of enums in C is implementation-defined",
8006 ("\??check that the C counterpart has size of " &
8007 UI_Image
(Esize
(Typ
)),
8011 Adjust_Esize_For_Alignment
(Typ
);
8013 end Freeze_Enumeration_Type
;
8015 -----------------------
8016 -- Freeze_Expression --
8017 -----------------------
8019 procedure Freeze_Expression
(N
: Node_Id
) is
8021 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
8022 -- If the expression is an array aggregate, the type of the component
8023 -- expressions is also frozen. If the component type is an access type
8024 -- and the expressions include allocators, the designed type is frozen
8027 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
8028 -- Given an N_Handled_Sequence_Of_Statements node, determines whether it
8029 -- is the statement sequence of an expander-generated subprogram: body
8030 -- created for an expression function, for a predicate function, an init
8031 -- proc, a stream subprogram, or a renaming as body. If so, this is not
8032 -- a freezing context and the entity will be frozen at a later point.
8034 function Has_Decl_In_List
8037 L
: List_Id
) return Boolean;
8038 -- Determines whether an entity E referenced in node N is declared in
8041 -----------------------------------------
8042 -- Find_Aggregate_Component_Desig_Type --
8043 -----------------------------------------
8045 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
8050 if Present
(Expressions
(N
)) then
8051 Exp
:= First
(Expressions
(N
));
8052 while Present
(Exp
) loop
8053 if Nkind
(Exp
) = N_Allocator
then
8054 return Designated_Type
(Component_Type
(Etype
(N
)));
8061 if Present
(Component_Associations
(N
)) then
8062 Assoc
:= First
(Component_Associations
(N
));
8063 while Present
(Assoc
) loop
8064 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
8065 return Designated_Type
(Component_Type
(Etype
(N
)));
8073 end Find_Aggregate_Component_Desig_Type
;
8075 ----------------------
8076 -- In_Expanded_Body --
8077 ----------------------
8079 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
8080 P
: constant Node_Id
:= Parent
(N
);
8084 if Nkind
(P
) /= N_Subprogram_Body
then
8087 -- AI12-0157: An expression function that is a completion is a freeze
8088 -- point. If the body is the result of expansion, it is not.
8090 elsif Was_Expression_Function
(P
) then
8091 return not Comes_From_Source
(P
);
8093 -- This is the body of a generated predicate function
8095 elsif Present
(Corresponding_Spec
(P
))
8096 and then Is_Predicate_Function
(Corresponding_Spec
(P
))
8101 Id
:= Defining_Unit_Name
(Specification
(P
));
8103 -- The following are expander-created bodies, or bodies that
8104 -- are not freeze points.
8106 if Nkind
(Id
) = N_Defining_Identifier
8107 and then (Is_Init_Proc
(Id
)
8108 or else Is_TSS
(Id
, TSS_Stream_Input
)
8109 or else Is_TSS
(Id
, TSS_Stream_Output
)
8110 or else Is_TSS
(Id
, TSS_Stream_Read
)
8111 or else Is_TSS
(Id
, TSS_Stream_Write
)
8112 or else Is_TSS
(Id
, TSS_Put_Image
)
8113 or else Nkind
(Original_Node
(P
)) =
8114 N_Subprogram_Renaming_Declaration
)
8121 end In_Expanded_Body
;
8123 ----------------------
8124 -- Has_Decl_In_List --
8125 ----------------------
8127 function Has_Decl_In_List
8130 L
: List_Id
) return Boolean
8132 Decl_Node
: Node_Id
;
8135 -- If E is an itype, pretend that it is declared in N
8137 if Is_Itype
(E
) then
8140 Decl_Node
:= Declaration_Node
(E
);
8143 return Is_List_Member
(Decl_Node
)
8144 and then List_Containing
(Decl_Node
) = L
;
8145 end Has_Decl_In_List
;
8149 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
8151 Desig_Typ
: Entity_Id
;
8157 Allocator_Typ
: Entity_Id
:= Empty
;
8159 Freeze_Outside
: Boolean := False;
8160 -- This flag is set true if the entity must be frozen outside the
8161 -- current subprogram. This happens in the case of expander generated
8162 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
8163 -- not freeze all entities like other bodies, but which nevertheless
8164 -- may reference entities that have to be frozen before the body and
8165 -- obviously cannot be frozen inside the body.
8167 Freeze_Outside_Subp
: Entity_Id
:= Empty
;
8168 -- This entity is set if we are inside a subprogram body and the frozen
8169 -- entity is defined in the enclosing scope of this subprogram. In such
8170 -- case we must skip the subprogram body when climbing the parents chain
8171 -- to locate the correct placement for the freezing node.
8173 -- Start of processing for Freeze_Expression
8176 -- Immediate return if freezing is inhibited. This flag is set by the
8177 -- analyzer to stop freezing on generated expressions that would cause
8178 -- freezing if they were in the source program, but which are not
8179 -- supposed to freeze, since they are created.
8181 if Must_Not_Freeze
(N
) then
8185 -- If expression is non-static, then it does not freeze in a default
8186 -- expression, see section "Handling of Default Expressions" in the
8187 -- spec of package Sem for further details. Note that we have to make
8188 -- sure that we actually have a real expression (if we have a subtype
8189 -- indication, we can't test Is_OK_Static_Expression). However, we
8190 -- exclude the case of the prefix of an attribute of a static scalar
8191 -- subtype from this early return, because static subtype attributes
8192 -- should always cause freezing, even in default expressions, but
8193 -- the attribute may not have been marked as static yet (because in
8194 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
8195 -- Freeze_Expression on the prefix).
8198 and then Nkind
(N
) in N_Subexpr
8199 and then not Is_OK_Static_Expression
(N
)
8200 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
8201 or else not (Is_Entity_Name
(N
)
8202 and then Is_Type
(Entity
(N
))
8203 and then Is_OK_Static_Subtype
(Entity
(N
))))
8208 -- Freeze type of expression if not frozen already
8212 if Nkind
(N
) in N_Has_Etype
and then Present
(Etype
(N
)) then
8213 if not Is_Frozen
(Etype
(N
)) then
8216 -- Base type may be an derived numeric type that is frozen at the
8217 -- point of declaration, but first_subtype is still unfrozen.
8219 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
8220 Typ
:= First_Subtype
(Etype
(N
));
8224 -- For entity name, freeze entity if not frozen already. A special
8225 -- exception occurs for an identifier that did not come from source.
8226 -- We don't let such identifiers freeze a non-internal entity, i.e.
8227 -- an entity that did come from source, since such an identifier was
8228 -- generated by the expander, and cannot have any semantic effect on
8229 -- the freezing semantics. For example, this stops the parameter of
8230 -- an initialization procedure from freezing the variable.
8232 if Is_Entity_Name
(N
)
8233 and then Present
(Entity
(N
))
8234 and then not Is_Frozen
(Entity
(N
))
8235 and then (Nkind
(N
) /= N_Identifier
8236 or else Comes_From_Source
(N
)
8237 or else not Comes_From_Source
(Entity
(N
)))
8241 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
8242 Check_Expression_Function
(N
, Nam
);
8249 -- For an allocator freeze designated type if not frozen already
8251 -- For an aggregate whose component type is an access type, freeze the
8252 -- designated type now, so that its freeze does not appear within the
8253 -- loop that might be created in the expansion of the aggregate. If the
8254 -- designated type is a private type without full view, the expression
8255 -- cannot contain an allocator, so the type is not frozen.
8257 -- For a function, we freeze the entity when the subprogram declaration
8258 -- is frozen, but a function call may appear in an initialization proc.
8259 -- before the declaration is frozen. We need to generate the extra
8260 -- formals, if any, to ensure that the expansion of the call includes
8261 -- the proper actuals. This only applies to Ada subprograms, not to
8268 Desig_Typ
:= Designated_Type
(Etype
(N
));
8270 if Nkind
(Expression
(N
)) = N_Qualified_Expression
then
8271 Allocator_Typ
:= Entity
(Subtype_Mark
(Expression
(N
)));
8275 if Is_Array_Type
(Etype
(N
))
8276 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
8278 -- Check whether aggregate includes allocators
8280 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
8283 when N_Indexed_Component
8284 | N_Selected_Component
8287 if Is_Access_Type
(Etype
(Prefix
(N
))) then
8288 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
8291 when N_Identifier
=>
8293 and then Ekind
(Nam
) = E_Function
8294 and then Nkind
(Parent
(N
)) = N_Function_Call
8295 and then not Has_Foreign_Convention
(Nam
)
8297 Create_Extra_Formals
(Nam
);
8304 if Desig_Typ
/= Empty
8305 and then (Is_Frozen
(Desig_Typ
)
8306 or else not Is_Fully_Defined
(Desig_Typ
))
8311 -- All done if nothing needs freezing
8315 and then No
(Desig_Typ
)
8316 and then No
(Allocator_Typ
)
8321 -- Check if we are inside a subprogram body and the frozen entity is
8322 -- defined in the enclosing scope of this subprogram. In such case we
8323 -- must skip the subprogram when climbing the parents chain to locate
8324 -- the correct placement for the freezing node.
8326 -- This is not needed for default expressions and other spec expressions
8327 -- in generic units since the Move_Freeze_Nodes mechanism (sem_ch12.adb)
8328 -- takes care of placing them at the proper place, after the generic
8332 and then Scope
(Nam
) /= Current_Scope
8333 and then not (In_Spec_Exp
and then Inside_A_Generic
)
8336 S
: Entity_Id
:= Current_Scope
;
8340 and then In_Same_Source_Unit
(Nam
, S
)
8342 if Scope
(S
) = Scope
(Nam
) then
8343 if Is_Subprogram
(S
) and then Has_Completion
(S
) then
8344 Freeze_Outside_Subp
:= S
;
8355 -- Examine the enclosing context by climbing the parent chain
8357 -- If we identified that we must freeze the entity outside of a given
8358 -- subprogram then we just climb up to that subprogram checking if some
8359 -- enclosing node is marked as Must_Not_Freeze (since in such case we
8360 -- must not freeze yet this entity).
8364 if Present
(Freeze_Outside_Subp
) then
8366 -- Do not freeze the current expression if another expression in
8367 -- the chain of parents must not be frozen.
8369 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8373 Parent_P
:= Parent
(P
);
8375 -- If we don't have a parent, then we are not in a well-formed
8376 -- tree. This is an unusual case, but there are some legitimate
8377 -- situations in which this occurs, notably when the expressions
8378 -- in the range of a type declaration are resolved. We simply
8379 -- ignore the freeze request in this case.
8381 if No
(Parent_P
) then
8385 -- If the parent is a subprogram body, the candidate insertion
8386 -- point is just ahead of it.
8388 if Nkind
(Parent_P
) = N_Subprogram_Body
8389 and then Unique_Defining_Entity
(Parent_P
) =
8399 -- Otherwise the traversal serves two purposes - to detect scenarios
8400 -- where freezeing is not needed and to find the proper insertion point
8401 -- for the freeze nodes. Although somewhat similar to Insert_Actions,
8402 -- this traversal is freezing semantics-sensitive. Inserting freeze
8403 -- nodes blindly in the tree may result in types being frozen too early.
8407 -- Do not freeze the current expression if another expression in
8408 -- the chain of parents must not be frozen.
8410 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8414 Parent_P
:= Parent
(P
);
8416 -- If we don't have a parent, then we are not in a well-formed
8417 -- tree. This is an unusual case, but there are some legitimate
8418 -- situations in which this occurs, notably when the expressions
8419 -- in the range of a type declaration are resolved. We simply
8420 -- ignore the freeze request in this case.
8422 if No
(Parent_P
) then
8426 -- See if we have got to an appropriate point in the tree
8428 case Nkind
(Parent_P
) is
8430 -- A special test for the exception of (RM 13.14(8)) for the
8431 -- case of per-object expressions (RM 3.8(18)) occurring in
8432 -- component definition or a discrete subtype definition. Note
8433 -- that we test for a component declaration which includes both
8434 -- cases we are interested in, and furthermore the tree does
8435 -- not have explicit nodes for either of these two constructs.
8437 when N_Component_Declaration
=>
8439 -- The case we want to test for here is an identifier that
8440 -- is a per-object expression, this is either a discriminant
8441 -- that appears in a context other than the component
8442 -- declaration or it is a reference to the type of the
8443 -- enclosing construct.
8445 -- For either of these cases, we skip the freezing
8447 if not In_Spec_Expression
8448 and then Nkind
(N
) = N_Identifier
8449 and then Present
(Entity
(N
))
8451 -- We recognize the discriminant case by just looking for
8452 -- a reference to a discriminant. It can only be one for
8453 -- the enclosing construct. Skip freezing in this case.
8455 if Ekind
(Entity
(N
)) = E_Discriminant
then
8458 -- For the case of a reference to the enclosing record,
8459 -- (or task or protected type), we look for a type that
8460 -- matches the current scope.
8462 elsif Entity
(N
) = Current_Scope
then
8467 -- If we have an enumeration literal that appears as the choice
8468 -- in the aggregate of an enumeration representation clause,
8469 -- then freezing does not occur (RM 13.14(10)).
8471 when N_Enumeration_Representation_Clause
=>
8473 -- The case we are looking for is an enumeration literal
8475 if Nkind
(N
) in N_Identifier | N_Character_Literal
8476 and then Is_Enumeration_Type
(Etype
(N
))
8478 -- If enumeration literal appears directly as the choice,
8479 -- do not freeze (this is the normal non-overloaded case)
8481 if Nkind
(Parent
(N
)) = N_Component_Association
8482 and then First
(Choices
(Parent
(N
))) = N
8486 -- If enumeration literal appears as the name of function
8487 -- which is the choice, then also do not freeze. This
8488 -- happens in the overloaded literal case, where the
8489 -- enumeration literal is temporarily changed to a
8490 -- function call for overloading analysis purposes.
8492 elsif Nkind
(Parent
(N
)) = N_Function_Call
8493 and then Nkind
(Parent
(Parent
(N
))) =
8494 N_Component_Association
8495 and then First
(Choices
(Parent
(Parent
(N
)))) =
8502 -- Normally if the parent is a handled sequence of statements,
8503 -- then the current node must be a statement, and that is an
8504 -- appropriate place to insert a freeze node.
8506 when N_Handled_Sequence_Of_Statements
=>
8508 -- An exception occurs when the sequence of statements is
8509 -- for an expander generated body that did not do the usual
8510 -- freeze all operation. In this case we usually want to
8511 -- freeze outside this body, not inside it, and we skip
8512 -- past the subprogram body that we are inside.
8514 if In_Expanded_Body
(Parent_P
) then
8516 Subp_Body
: constant Node_Id
:= Parent
(Parent_P
);
8517 Spec_Id
: Entity_Id
;
8520 -- Freeze the entity only when it is declared inside
8521 -- the body of the expander generated procedure. This
8522 -- case is recognized by the subprogram scope of the
8523 -- entity or its type, which is either the spec of an
8524 -- enclosing body, or (in the case of init_procs for
8525 -- which there is no separate spec) the current scope.
8527 if Nkind
(Subp_Body
) = N_Subprogram_Body
then
8532 Spec_Id
:= Corresponding_Spec
(Subp_Body
);
8534 if Present
(Typ
) then
8536 elsif Present
(Nam
) then
8539 S
:= Standard_Standard
;
8542 while S
/= Standard_Standard
8543 and then not Is_Subprogram
(S
)
8552 and then Scope
(Typ
) = Current_Scope
8554 Defining_Entity
(Subp_Body
) = Current_Scope
8561 -- If the entity is not frozen by an expression
8562 -- function that is not a completion, continue
8563 -- climbing the tree.
8565 if Nkind
(Subp_Body
) = N_Subprogram_Body
8566 and then Was_Expression_Function
(Subp_Body
)
8570 -- Freeze outside the body
8573 Parent_P
:= Parent
(Parent_P
);
8574 Freeze_Outside
:= True;
8578 -- Here if normal case where we are in handled statement
8579 -- sequence and want to do the insertion right there.
8585 -- If parent is a body or a spec or a block, then the current
8586 -- node is a statement or declaration and we can insert the
8587 -- freeze node before it.
8589 when N_Block_Statement
8592 | N_Package_Specification
8599 -- The expander is allowed to define types in any statements
8600 -- list, so any of the following parent nodes also mark a
8601 -- freezing point if the actual node is in a list of
8602 -- statements or declarations.
8604 when N_Abortable_Part
8605 | N_Accept_Alternative
8606 | N_Case_Statement_Alternative
8607 | N_Compilation_Unit_Aux
8608 | N_Conditional_Entry_Call
8609 | N_Delay_Alternative
8611 | N_Entry_Call_Alternative
8612 | N_Exception_Handler
8613 | N_Extended_Return_Statement
8616 | N_Selective_Accept
8617 | N_Triggering_Alternative
8619 exit when Is_List_Member
(P
);
8621 -- The freeze nodes produced by an expression coming from the
8622 -- Actions list of an N_Expression_With_Actions, short-circuit
8623 -- expression or N_Case_Expression_Alternative node must remain
8624 -- within the Actions list if they freeze an entity declared in
8625 -- this list, as inserting the freeze nodes further up the tree
8626 -- may lead to use before declaration issues for the entity.
8628 when N_Case_Expression_Alternative
8629 | N_Expression_With_Actions
8632 exit when (Present
(Nam
)
8634 Has_Decl_In_List
(Nam
, P
, Actions
(Parent_P
)))
8635 or else (Present
(Typ
)
8637 Has_Decl_In_List
(Typ
, P
, Actions
(Parent_P
)));
8639 -- Likewise for an N_If_Expression and its two Actions list
8641 when N_If_Expression
=>
8643 L1
: constant List_Id
:= Then_Actions
(Parent_P
);
8644 L2
: constant List_Id
:= Else_Actions
(Parent_P
);
8647 exit when (Present
(Nam
)
8649 Has_Decl_In_List
(Nam
, P
, L1
))
8650 or else (Present
(Typ
)
8652 Has_Decl_In_List
(Typ
, P
, L1
))
8653 or else (Present
(Nam
)
8655 Has_Decl_In_List
(Nam
, P
, L2
))
8656 or else (Present
(Typ
)
8658 Has_Decl_In_List
(Typ
, P
, L2
));
8661 -- N_Loop_Statement is a special case: a type that appears in
8662 -- the source can never be frozen in a loop (this occurs only
8663 -- because of a loop expanded by the expander), so we keep on
8664 -- going. Otherwise we terminate the search. Same is true of
8665 -- any entity which comes from source (if it has a predefined
8666 -- type, this type does not appear to come from source, but the
8667 -- entity should not be frozen here).
8669 when N_Loop_Statement
=>
8670 exit when not Comes_From_Source
(Etype
(N
))
8671 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
8673 -- For all other cases, keep looking at parents
8679 -- We fall through the case if we did not yet find the proper
8680 -- place in the tree for inserting the freeze node, so climb.
8686 -- If the expression appears in a record or an initialization procedure,
8687 -- the freeze nodes are collected and attached to the current scope, to
8688 -- be inserted and analyzed on exit from the scope, to insure that
8689 -- generated entities appear in the correct scope. If the expression is
8690 -- a default for a discriminant specification, the scope is still void.
8691 -- The expression can also appear in the discriminant part of a private
8692 -- or concurrent type.
8694 -- If the expression appears in a constrained subcomponent of an
8695 -- enclosing record declaration, the freeze nodes must be attached to
8696 -- the outer record type so they can eventually be placed in the
8697 -- enclosing declaration list.
8699 -- The other case requiring this special handling is if we are in a
8700 -- default expression, since in that case we are about to freeze a
8701 -- static type, and the freeze scope needs to be the outer scope, not
8702 -- the scope of the subprogram with the default parameter.
8704 -- For default expressions and other spec expressions in generic units,
8705 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
8706 -- placing them at the proper place, after the generic unit.
8708 if (In_Spec_Exp
and not Inside_A_Generic
)
8709 or else Freeze_Outside
8710 or else (Is_Type
(Current_Scope
)
8711 and then (not Is_Concurrent_Type
(Current_Scope
)
8712 or else not Has_Completion
(Current_Scope
)))
8713 or else Ekind
(Current_Scope
) = E_Void
8716 Freeze_Nodes
: List_Id
:= No_List
;
8717 Pos
: Int
:= Scope_Stack
.Last
;
8720 if Present
(Desig_Typ
) then
8721 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
8724 if Present
(Typ
) then
8725 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
8728 if Present
(Nam
) then
8729 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
8732 -- The current scope may be that of a constrained component of
8733 -- an enclosing record declaration, or of a loop of an enclosing
8734 -- quantified expression or aggregate with an iterated component
8735 -- in Ada 2022, which is above the current scope in the scope
8736 -- stack. Indeed in the context of a quantified expression or
8737 -- an aggregate with an iterated component, an internal scope is
8738 -- created and pushed above the current scope in order to emulate
8739 -- the loop-like behavior of the construct.
8740 -- If the expression is within a top-level pragma, as for a pre-
8741 -- condition on a library-level subprogram, nothing to do.
8743 if not Is_Compilation_Unit
(Current_Scope
)
8744 and then (Is_Record_Type
(Scope
(Current_Scope
))
8745 or else (Ekind
(Current_Scope
) = E_Loop
8746 and then Is_Internal
(Current_Scope
)))
8751 if Is_Non_Empty_List
(Freeze_Nodes
) then
8753 -- When the current scope is transient, insert the freeze nodes
8754 -- prior to the expression that produced them. Transient scopes
8755 -- may create additional declarations when finalizing objects
8756 -- or managing the secondary stack. Inserting the freeze nodes
8757 -- of those constructs prior to the scope would result in a
8758 -- freeze-before-declaration, therefore the freeze node must
8759 -- remain interleaved with their constructs.
8761 if Scope_Is_Transient
then
8762 Insert_Actions
(N
, Freeze_Nodes
);
8764 elsif No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
8765 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
8768 Append_List
(Freeze_Nodes
,
8769 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
8777 -- Now we have the right place to do the freezing. First, a special
8778 -- adjustment, if we are in spec-expression analysis mode, these freeze
8779 -- actions must not be thrown away (normally all inserted actions are
8780 -- thrown away in this mode. However, the freeze actions are from static
8781 -- expressions and one of the important reasons we are doing this
8782 -- special analysis is to get these freeze actions. Therefore we turn
8783 -- off the In_Spec_Expression mode to propagate these freeze actions.
8784 -- This also means they get properly analyzed and expanded.
8786 In_Spec_Expression
:= False;
8788 -- Freeze the subtype mark before a qualified expression on an
8789 -- allocator as per AARM 13.14(4.a). This is needed in particular to
8790 -- generate predicate functions.
8792 if Present
(Allocator_Typ
) then
8793 Freeze_Before
(P
, Allocator_Typ
);
8796 -- Freeze the designated type of an allocator (RM 13.14(13))
8798 if Present
(Desig_Typ
) then
8799 Freeze_Before
(P
, Desig_Typ
);
8802 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
8803 -- the enumeration representation clause exception in the loop above.
8805 if Present
(Typ
) then
8806 Freeze_Before
(P
, Typ
);
8809 -- Freeze name if one is present (RM 13.14(11))
8811 if Present
(Nam
) then
8812 Freeze_Before
(P
, Nam
);
8815 -- Restore In_Spec_Expression flag
8817 In_Spec_Expression
:= In_Spec_Exp
;
8818 end Freeze_Expression
;
8820 -----------------------
8821 -- Freeze_Expr_Types --
8822 -----------------------
8824 procedure Freeze_Expr_Types
8825 (Def_Id
: Entity_Id
;
8830 function Cloned_Expression
return Node_Id
;
8831 -- Build a duplicate of the expression of the return statement that has
8832 -- no defining entities shared with the original expression.
8834 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
8835 -- Freeze all types referenced in the subtree rooted at Node
8837 -----------------------
8838 -- Cloned_Expression --
8839 -----------------------
8841 function Cloned_Expression
return Node_Id
is
8842 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
8843 -- Tree traversal routine that clones the defining identifier of
8844 -- iterator and loop parameter specification nodes.
8850 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
8853 N_Iterator_Specification | N_Loop_Parameter_Specification
8855 Set_Defining_Identifier
8856 (Node
, New_Copy
(Defining_Identifier
(Node
)));
8862 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
8866 Dup_Expr
: constant Node_Id
:= New_Copy_Tree
(Expr
);
8868 -- Start of processing for Cloned_Expression
8871 -- We must duplicate the expression with semantic information to
8872 -- inherit the decoration of global entities in generic instances.
8873 -- Set the parent of the new node to be the parent of the original
8874 -- to get the proper context, which is needed for complete error
8875 -- reporting and for semantic analysis.
8877 Set_Parent
(Dup_Expr
, Parent
(Expr
));
8879 -- Replace the defining identifier of iterators and loop param
8880 -- specifications by a clone to ensure that the cloned expression
8881 -- and the original expression don't have shared identifiers;
8882 -- otherwise, as part of the preanalysis of the expression, these
8883 -- shared identifiers may be left decorated with itypes which
8884 -- will not be available in the tree passed to the backend.
8886 Clone_Def_Ids
(Dup_Expr
);
8889 end Cloned_Expression
;
8891 ----------------------
8892 -- Freeze_Type_Refs --
8893 ----------------------
8895 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
8896 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
);
8897 -- Check that Typ is fully declared and freeze it if so
8899 ---------------------------
8900 -- Check_And_Freeze_Type --
8901 ---------------------------
8903 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
) is
8905 -- Skip Itypes created by the preanalysis, and itypes whose
8906 -- scope is another type (i.e. component subtypes that depend
8907 -- on a discriminant),
8910 and then (Scope_Within_Or_Same
(Scope
(Typ
), Def_Id
)
8911 or else Is_Type
(Scope
(Typ
)))
8916 -- This provides a better error message than generating primitives
8917 -- whose compilation fails much later. Refine the error message if
8920 Check_Fully_Declared
(Typ
, Node
);
8922 if Error_Posted
(Node
) then
8923 if Has_Private_Component
(Typ
)
8924 and then not Is_Private_Type
(Typ
)
8926 Error_Msg_NE
("\type& has private component", Node
, Typ
);
8930 Freeze_Before
(N
, Typ
);
8932 end Check_And_Freeze_Type
;
8934 -- Start of processing for Freeze_Type_Refs
8937 -- Check that a type referenced by an entity can be frozen
8939 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
8940 -- The entity itself may be a type, as in a membership test
8941 -- or an attribute reference. Freezing its own type would be
8942 -- incomplete if the entity is derived or an extension.
8944 if Is_Type
(Entity
(Node
)) then
8945 Check_And_Freeze_Type
(Entity
(Node
));
8948 Check_And_Freeze_Type
(Etype
(Entity
(Node
)));
8951 -- Check that the enclosing record type can be frozen
8953 if Ekind
(Entity
(Node
)) in E_Component | E_Discriminant
then
8954 Check_And_Freeze_Type
(Scope
(Entity
(Node
)));
8957 -- Freezing an access type does not freeze the designated type, but
8958 -- freezing conversions between access to interfaces requires that
8959 -- the interface types themselves be frozen, so that dispatch table
8960 -- entities are properly created.
8962 -- Unclear whether a more general rule is needed ???
8964 elsif Nkind
(Node
) = N_Type_Conversion
8965 and then Is_Access_Type
(Etype
(Node
))
8966 and then Is_Interface
(Designated_Type
(Etype
(Node
)))
8968 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
8971 -- An implicit dereference freezes the designated type. In the case
8972 -- of a dispatching call whose controlling argument is an access
8973 -- type, the dereference is not made explicit, so we must check for
8974 -- such a call and freeze the designated type.
8976 if Nkind
(Node
) in N_Has_Etype
8977 and then Present
(Etype
(Node
))
8978 and then Is_Access_Type
(Etype
(Node
))
8980 if Nkind
(Parent
(Node
)) = N_Function_Call
8981 and then Node
= Controlling_Argument
(Parent
(Node
))
8983 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
8985 -- An explicit dereference freezes the designated type as well,
8986 -- even though that type is not attached to an entity in the
8989 elsif Nkind
(Parent
(Node
)) = N_Explicit_Dereference
then
8990 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
8993 -- An iterator specification freezes the iterator type, even though
8994 -- that type is not attached to an entity in the construct.
8996 elsif Nkind
(Node
) in N_Has_Etype
8997 and then Nkind
(Parent
(Node
)) = N_Iterator_Specification
8998 and then Node
= Name
(Parent
(Node
))
9001 Iter
: constant Node_Id
:=
9002 Find_Value_Of_Aspect
(Etype
(Node
), Aspect_Default_Iterator
);
9005 if Present
(Iter
) then
9006 Check_And_Freeze_Type
(Etype
(Iter
));
9011 -- No point in posting several errors on the same expression
9013 if Serious_Errors_Detected
> 0 then
9018 end Freeze_Type_Refs
;
9020 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
9024 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Def_Id
);
9025 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Def_Id
);
9026 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
9028 -- Start of processing for Freeze_Expr_Types
9031 -- Preanalyze a duplicate of the expression to have available the
9032 -- minimum decoration needed to locate referenced unfrozen types
9033 -- without adding any decoration to the function expression.
9035 -- This routine is also applied to expressions in the contract for
9036 -- the subprogram. If that happens when expanding the code for
9037 -- pre/postconditions during expansion of the subprogram body, the
9038 -- subprogram is already installed.
9040 if Def_Id
/= Current_Scope
then
9041 Push_Scope
(Def_Id
);
9042 Install_Formals
(Def_Id
);
9044 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
9047 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
9050 -- Restore certain attributes of Def_Id since the preanalysis may
9051 -- have introduced itypes to this scope, thus modifying attributes
9052 -- First_Entity and Last_Entity.
9054 Set_First_Entity
(Def_Id
, Saved_First_Entity
);
9055 Set_Last_Entity
(Def_Id
, Saved_Last_Entity
);
9057 if Present
(Last_Entity
(Def_Id
)) then
9058 Set_Next_Entity
(Last_Entity
(Def_Id
), Empty
);
9061 -- Freeze all types referenced in the expression
9063 Freeze_References
(Dup_Expr
);
9064 end Freeze_Expr_Types
;
9066 -----------------------------
9067 -- Freeze_Fixed_Point_Type --
9068 -----------------------------
9070 -- Certain fixed-point types and subtypes, including implicit base types
9071 -- and declared first subtypes, have not yet set up a range. This is
9072 -- because the range cannot be set until the Small and Size values are
9073 -- known, and these are not known till the type is frozen.
9075 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
9076 -- whose bounds are unanalyzed real literals. This routine will recognize
9077 -- this case, and transform this range node into a properly typed range
9078 -- with properly analyzed and resolved values.
9080 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
9081 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
9082 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
9083 Hi
: constant Node_Id
:= High_Bound
(Rng
);
9084 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9085 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
9086 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
9087 BHi
: constant Node_Id
:= High_Bound
(Brng
);
9088 Ftyp
: constant Entity_Id
:= Underlying_Type
(First_Subtype
(Typ
));
9097 -- Save original bounds (for shaving tests)
9100 -- Actual size chosen
9102 function Fsize
(Lov
, Hiv
: Ureal
) return Int
;
9103 -- Returns size of type with given bounds. Also leaves these
9104 -- bounds set as the current bounds of the Typ.
9106 function Larger
(A
, B
: Ureal
) return Boolean;
9107 -- Returns true if A > B with a margin of Typ'Small
9109 function Smaller
(A
, B
: Ureal
) return Boolean;
9110 -- Returns true if A < B with a margin of Typ'Small
9116 function Fsize
(Lov
, Hiv
: Ureal
) return Int
is
9118 Set_Realval
(Lo
, Lov
);
9119 Set_Realval
(Hi
, Hiv
);
9120 return Minimum_Size
(Typ
);
9127 function Larger
(A
, B
: Ureal
) return Boolean is
9129 return A
> B
and then A
- Small_Value
(Typ
) > B
;
9136 function Smaller
(A
, B
: Ureal
) return Boolean is
9138 return A
< B
and then A
+ Small_Value
(Typ
) < B
;
9141 -- Start of processing for Freeze_Fixed_Point_Type
9144 -- The type, or its first subtype if we are freezing the anonymous
9145 -- base, may have a delayed Small aspect. It must be analyzed now,
9146 -- so that all characteristics of the type (size, bounds) can be
9147 -- computed and validated in the call to Minimum_Size that follows.
9149 if Has_Delayed_Aspects
(Ftyp
) then
9150 Analyze_Aspects_At_Freeze_Point
(Ftyp
);
9151 Set_Has_Delayed_Aspects
(Ftyp
, False);
9154 if May_Inherit_Delayed_Rep_Aspects
(Ftyp
) then
9155 Inherit_Delayed_Rep_Aspects
(Ftyp
);
9156 Set_May_Inherit_Delayed_Rep_Aspects
(Ftyp
, False);
9159 -- Inherit the Small value from the first subtype in any case
9162 Set_Small_Value
(Typ
, Small_Value
(Ftyp
));
9165 -- If Esize of a subtype has not previously been set, set it now
9167 if not Known_Esize
(Typ
) then
9168 Atype
:= Ancestor_Subtype
(Typ
);
9170 if Present
(Atype
) then
9171 Set_Esize
(Typ
, Esize
(Atype
));
9173 Copy_Esize
(To
=> Typ
, From
=> Btyp
);
9177 -- Immediate return if the range is already analyzed. This means that
9178 -- the range is already set, and does not need to be computed by this
9181 if Analyzed
(Rng
) then
9185 -- Immediate return if either of the bounds raises Constraint_Error
9187 if Raises_Constraint_Error
(Lo
)
9188 or else Raises_Constraint_Error
(Hi
)
9193 Small
:= Small_Value
(Typ
);
9194 Loval
:= Realval
(Lo
);
9195 Hival
:= Realval
(Hi
);
9200 -- Ordinary fixed-point case
9202 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
9204 -- For the ordinary fixed-point case, we are allowed to fudge the
9205 -- end-points up or down by small. Generally we prefer to fudge up,
9206 -- i.e. widen the bounds for non-model numbers so that the end points
9207 -- are included. However there are cases in which this cannot be
9208 -- done, and indeed cases in which we may need to narrow the bounds.
9209 -- The following circuit makes the decision.
9211 -- Note: our terminology here is that Incl_EP means that the bounds
9212 -- are widened by Small if necessary to include the end points, and
9213 -- Excl_EP means that the bounds are narrowed by Small to exclude the
9214 -- end-points if this reduces the size.
9216 -- Note that in the Incl case, all we care about is including the
9217 -- end-points. In the Excl case, we want to narrow the bounds as
9218 -- much as permitted by the RM, to give the smallest possible size.
9221 Loval_Incl_EP
: Ureal
;
9222 Hival_Incl_EP
: Ureal
;
9224 Loval_Excl_EP
: Ureal
;
9225 Hival_Excl_EP
: Ureal
;
9235 -- First step. Base types are required to be symmetrical. Right
9236 -- now, the base type range is a copy of the first subtype range.
9237 -- This will be corrected before we are done, but right away we
9238 -- need to deal with the case where both bounds are non-negative.
9239 -- In this case, we set the low bound to the negative of the high
9240 -- bound, to make sure that the size is computed to include the
9241 -- required sign. Note that we do not need to worry about the
9242 -- case of both bounds negative, because the sign will be dealt
9243 -- with anyway. Furthermore we can't just go making such a bound
9244 -- symmetrical, since in a twos-complement system, there is an
9245 -- extra negative value which could not be accommodated on the
9249 and then not UR_Is_Negative
(Loval
)
9250 and then Hival
> Loval
9253 Set_Realval
(Lo
, Loval
);
9256 -- Compute the fudged bounds. If the bound is a model number, (or
9257 -- greater if given low bound, smaller if high bound) then we do
9258 -- nothing to include it, but we are allowed to backoff to the
9259 -- next adjacent model number when we exclude it. If it is not a
9260 -- model number then we straddle the two values with the model
9261 -- numbers on either side.
9263 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
9265 if UR_Ge
(Loval
, Model_Num
) then
9266 Loval_Incl_EP
:= Model_Num
;
9268 Loval_Incl_EP
:= Model_Num
- Small
;
9271 -- The low value excluding the end point is Small greater, but
9272 -- we do not do this exclusion if the low value is positive,
9273 -- since it can't help the size and could actually hurt by
9274 -- crossing the high bound.
9276 if UR_Is_Negative
(Loval_Incl_EP
) then
9277 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
9279 -- If the value went from negative to zero, then we have the
9280 -- case where Loval_Incl_EP is the model number just below
9281 -- zero, so we want to stick to the negative value for the
9282 -- base type to maintain the condition that the size will
9283 -- include signed values.
9286 and then UR_Is_Zero
(Loval_Excl_EP
)
9288 Loval_Excl_EP
:= Loval_Incl_EP
;
9292 Loval_Excl_EP
:= Loval_Incl_EP
;
9295 -- Similar processing for upper bound and high value
9297 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
9299 if UR_Le
(Hival
, Model_Num
) then
9300 Hival_Incl_EP
:= Model_Num
;
9302 Hival_Incl_EP
:= Model_Num
+ Small
;
9305 if UR_Is_Positive
(Hival_Incl_EP
) then
9306 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
9308 Hival_Excl_EP
:= Hival_Incl_EP
;
9311 -- One further adjustment is needed. In the case of subtypes, we
9312 -- cannot go outside the range of the base type, or we get
9313 -- peculiarities, and the base type range is already set. This
9314 -- only applies to the Incl values, since clearly the Excl values
9315 -- are already as restricted as they are allowed to be.
9318 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
9319 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
9322 -- Get size including and excluding end points
9324 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
9325 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
9327 -- No need to exclude end-points if it does not reduce size
9329 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
9330 Loval_Excl_EP
:= Loval_Incl_EP
;
9333 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
9334 Hival_Excl_EP
:= Hival_Incl_EP
;
9337 -- Now we set the actual size to be used. We want to use the
9338 -- bounds fudged up to include the end-points but only if this
9339 -- can be done without violating a specifically given size
9340 -- size clause or causing an unacceptable increase in size.
9342 -- Case of size clause given
9344 if Has_Size_Clause
(Typ
) then
9346 -- Use the inclusive size only if it is consistent with
9347 -- the explicitly specified size.
9349 if Size_Incl_EP
<= RM_Size
(Typ
) then
9350 Actual_Lo
:= Loval_Incl_EP
;
9351 Actual_Hi
:= Hival_Incl_EP
;
9352 Actual_Size
:= Size_Incl_EP
;
9354 -- If the inclusive size is too large, we try excluding
9355 -- the end-points (will be caught later if does not work).
9358 Actual_Lo
:= Loval_Excl_EP
;
9359 Actual_Hi
:= Hival_Excl_EP
;
9360 Actual_Size
:= Size_Excl_EP
;
9363 -- Case of size clause not given
9366 -- If we have a base type whose corresponding first subtype
9367 -- has an explicit size that is large enough to include our
9368 -- end-points, then do so. There is no point in working hard
9369 -- to get a base type whose size is smaller than the specified
9370 -- size of the first subtype.
9372 if Has_Size_Clause
(Ftyp
)
9373 and then Size_Incl_EP
<= Esize
(Ftyp
)
9375 Actual_Size
:= Size_Incl_EP
;
9376 Actual_Lo
:= Loval_Incl_EP
;
9377 Actual_Hi
:= Hival_Incl_EP
;
9379 -- If excluding the end-points makes the size smaller and
9380 -- results in a size of 8,16,32,64, then we take the smaller
9381 -- size. For the 64 case, this is compulsory. For the other
9382 -- cases, it seems reasonable. We like to include end points
9383 -- if we can, but not at the expense of moving to the next
9384 -- natural boundary of size.
9386 elsif Size_Incl_EP
/= Size_Excl_EP
9387 and then Addressable
(Size_Excl_EP
)
9389 Actual_Size
:= Size_Excl_EP
;
9390 Actual_Lo
:= Loval_Excl_EP
;
9391 Actual_Hi
:= Hival_Excl_EP
;
9393 -- Otherwise we can definitely include the end points
9396 Actual_Size
:= Size_Incl_EP
;
9397 Actual_Lo
:= Loval_Incl_EP
;
9398 Actual_Hi
:= Hival_Incl_EP
;
9401 -- One pathological case: normally we never fudge a low bound
9402 -- down, since it would seem to increase the size (if it has
9403 -- any effect), but for ranges containing single value, or no
9404 -- values, the high bound can be small too large. Consider:
9406 -- type t is delta 2.0**(-14)
9407 -- range 131072.0 .. 0;
9409 -- That lower bound is *just* outside the range of 32 bits, and
9410 -- does need fudging down in this case. Note that the bounds
9411 -- will always have crossed here, since the high bound will be
9412 -- fudged down if necessary, as in the case of:
9414 -- type t is delta 2.0**(-14)
9415 -- range 131072.0 .. 131072.0;
9417 -- So we detect the situation by looking for crossed bounds,
9418 -- and if the bounds are crossed, and the low bound is greater
9419 -- than zero, we will always back it off by small, since this
9420 -- is completely harmless.
9422 if Actual_Lo
> Actual_Hi
then
9423 if UR_Is_Positive
(Actual_Lo
) then
9424 Actual_Lo
:= Loval_Incl_EP
- Small
;
9425 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9427 -- And of course, we need to do exactly the same parallel
9428 -- fudge for flat ranges in the negative region.
9430 elsif UR_Is_Negative
(Actual_Hi
) then
9431 Actual_Hi
:= Hival_Incl_EP
+ Small
;
9432 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9437 Set_Realval
(Lo
, Actual_Lo
);
9438 Set_Realval
(Hi
, Actual_Hi
);
9441 -- Enforce some limitations for ordinary fixed-point types. They come
9442 -- from an exact algorithm used to implement Text_IO.Fixed_IO and the
9443 -- Fore, Image and Value attributes. The requirement on the Small is
9444 -- to lie in the range 2**(-(Siz - 1)) .. 2**(Siz - 1) for a type of
9445 -- Siz bits (Siz=32,64,128) and the requirement on the bounds is to
9446 -- be smaller in magnitude than 10.0**N * 2**(Siz - 1), where N is
9447 -- given by the formula N = floor ((Siz - 1) * log 2 / log 10).
9449 -- If the bounds of a 32-bit type are too large, force 64-bit type
9451 if Actual_Size
<= 32
9452 and then Small
<= Ureal_2_31
9453 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_2_10_18
)
9454 or else Larger
(Expr_Value_R
(Hi
), Ureal_2_10_18
))
9459 -- If the bounds of a 64-bit type are too large, force 128-bit type
9461 if System_Max_Integer_Size
= 128
9462 and then Actual_Size
<= 64
9463 and then Small
<= Ureal_2_63
9464 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
)
9465 or else Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
))
9470 -- Give error messages for first subtypes and not base types, as the
9471 -- bounds of base types are always maximum for their size, see below.
9473 if System_Max_Integer_Size
< 128 and then Typ
/= Btyp
then
9475 -- See the 128-bit case below for the reason why we cannot test
9476 -- against the 2**(-63) .. 2**63 range. This quirk should have
9477 -- been kludged around as in the 128-bit case below, but it was
9478 -- not and we end up with a ludicrous range as a result???
9480 if Small
< Ureal_2_M_80
then
9481 Error_Msg_Name_1
:= Name_Small
;
9483 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", Typ
);
9485 elsif Small
> Ureal_2_80
then
9486 Error_Msg_Name_1
:= Name_Small
;
9488 ("`&''%` too large, maximum allowed is 2.0'*'*80", Typ
);
9491 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
) then
9492 Error_Msg_Name_1
:= Name_First
;
9494 ("`&''%` too small, minimum allowed is -9.0E+36", Typ
);
9497 if Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
) then
9498 Error_Msg_Name_1
:= Name_Last
;
9500 ("`&''%` too large, maximum allowed is 9.0E+36", Typ
);
9503 elsif System_Max_Integer_Size
= 128 and then Typ
/= Btyp
then
9505 -- ACATS c35902d tests a delta equal to 2**(-(Max_Mantissa + 1))
9506 -- but we cannot really support anything smaller than Fine_Delta
9507 -- because of the way we implement I/O for fixed point types???
9509 if Small
= Ureal_2_M_128
then
9512 elsif Small
< Ureal_2_M_127
then
9513 Error_Msg_Name_1
:= Name_Small
;
9515 ("`&''%` too small, minimum allowed is 2.0'*'*(-127)", Typ
);
9517 elsif Small
> Ureal_2_127
then
9518 Error_Msg_Name_1
:= Name_Small
;
9520 ("`&''%` too large, maximum allowed is 2.0'*'*127", Typ
);
9524 and then (Norm_Num
(Small
) > Uint_2
** 127
9525 or else Norm_Den
(Small
) > Uint_2
** 127)
9526 and then Small
/= Ureal_2_M_128
9528 Error_Msg_Name_1
:= Name_Small
;
9530 ("`&''%` not the ratio of two 128-bit integers", Typ
);
9533 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_10_76
) then
9534 Error_Msg_Name_1
:= Name_First
;
9536 ("`&''%` too small, minimum allowed is -1.0E+76", Typ
);
9539 if Larger
(Expr_Value_R
(Hi
), Ureal_10_76
) then
9540 Error_Msg_Name_1
:= Name_Last
;
9542 ("`&''%` too large, maximum allowed is 1.0E+76", Typ
);
9546 -- For the decimal case, none of this fudging is required, since there
9547 -- are no end-point problems in the decimal case (the end-points are
9548 -- always included).
9551 Actual_Size
:= Fsize
(Loval
, Hival
);
9554 -- At this stage, the actual size has been calculated and the proper
9555 -- required bounds are stored in the low and high bounds.
9557 if Actual_Size
> System_Max_Integer_Size
then
9558 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
9559 Error_Msg_Uint_2
:= UI_From_Int
(System_Max_Integer_Size
);
9561 ("size required (^) for type& too large, maximum allowed is ^",
9563 Actual_Size
:= System_Max_Integer_Size
;
9566 -- Check size against explicit given size
9568 if Has_Size_Clause
(Typ
) then
9569 if Actual_Size
> RM_Size
(Typ
) then
9570 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9571 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
9573 ("size given (^) for type& too small, minimum allowed is ^",
9574 Size_Clause
(Typ
), Typ
);
9577 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
9580 -- Increase size to next natural boundary if no size clause given
9583 if Actual_Size
<= 8 then
9585 elsif Actual_Size
<= 16 then
9587 elsif Actual_Size
<= 32 then
9589 elsif Actual_Size
<= 64 then
9595 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9596 Adjust_Esize_For_Alignment
(Typ
);
9599 -- If we have a base type, then expand the bounds so that they extend to
9600 -- the full width of the allocated size in bits, to avoid junk range
9601 -- checks on intermediate computations.
9604 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
9605 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
9608 -- Final step is to reanalyze the bounds using the proper type
9609 -- and set the Corresponding_Integer_Value fields of the literals.
9611 Set_Etype
(Lo
, Empty
);
9612 Set_Analyzed
(Lo
, False);
9615 -- Resolve with universal fixed if the base type, and with the base
9616 -- type if we are freezing a subtype. Note we can't resolve the base
9617 -- type with itself, that would be a reference before definition.
9618 -- The resolution of the bounds of a subtype, if they are given by real
9619 -- literals, includes the setting of the Corresponding_Integer_Value,
9620 -- as for other literals of a fixed-point type.
9623 Resolve
(Lo
, Universal_Fixed
);
9624 Set_Corresponding_Integer_Value
9625 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
9630 -- Similar processing for high bound
9632 Set_Etype
(Hi
, Empty
);
9633 Set_Analyzed
(Hi
, False);
9637 Resolve
(Hi
, Universal_Fixed
);
9638 Set_Corresponding_Integer_Value
9639 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
9644 -- Set type of range to correspond to bounds
9646 Set_Etype
(Rng
, Etype
(Lo
));
9648 -- Set Esize to calculated size if not set already
9650 if not Known_Esize
(Typ
) then
9651 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9654 -- Set RM_Size if not already set. If already set, check value
9657 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
9660 if Known_RM_Size
(Typ
) then
9661 if RM_Size
(Typ
) < Minsiz
then
9662 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9663 Error_Msg_Uint_2
:= Minsiz
;
9665 ("size given (^) for type& too small, minimum allowed is ^",
9666 Size_Clause
(Typ
), Typ
);
9670 Set_RM_Size
(Typ
, Minsiz
);
9674 -- Check for shaving
9676 if Comes_From_Source
(Typ
) then
9678 -- In SPARK mode the given bounds must be strictly representable
9680 if SPARK_Mode
= On
then
9681 if Orig_Lo
< Expr_Value_R
(Lo
) then
9683 ("declared low bound of type & is outside type range",
9687 if Orig_Hi
> Expr_Value_R
(Hi
) then
9689 ("declared high bound of type & is outside type range",
9694 if Orig_Lo
< Expr_Value_R
(Lo
) then
9696 ("declared low bound of type & is outside type range??", Typ
);
9698 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
9701 if Orig_Hi
> Expr_Value_R
(Hi
) then
9703 ("declared high bound of type & is outside type range??",
9706 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
9710 end Freeze_Fixed_Point_Type
;
9716 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
9720 Set_Has_Delayed_Freeze
(T
);
9721 L
:= Freeze_Entity
(T
, N
);
9723 Insert_Actions
(N
, L
);
9726 --------------------------
9727 -- Freeze_Static_Object --
9728 --------------------------
9730 procedure Freeze_Static_Object
(E
: Entity_Id
) is
9732 Cannot_Be_Static
: exception;
9733 -- Exception raised if the type of a static object cannot be made
9734 -- static. This happens if the type depends on non-global objects.
9736 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
9737 -- Called to ensure that an expression used as part of a type definition
9738 -- is statically allocatable, which means that the expression type is
9739 -- statically allocatable, and the expression is either static, or a
9740 -- reference to a library level constant.
9742 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
9743 -- Called to mark a type as static, checking that it is possible
9744 -- to set the type as static. If it is not possible, then the
9745 -- exception Cannot_Be_Static is raised.
9747 -----------------------------
9748 -- Ensure_Expression_Is_SA --
9749 -----------------------------
9751 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
9755 Ensure_Type_Is_SA
(Etype
(N
));
9757 if Is_OK_Static_Expression
(N
) then
9760 elsif Nkind
(N
) = N_Identifier
then
9764 and then Ekind
(Ent
) = E_Constant
9765 and then Is_Library_Level_Entity
(Ent
)
9771 raise Cannot_Be_Static
;
9772 end Ensure_Expression_Is_SA
;
9774 -----------------------
9775 -- Ensure_Type_Is_SA --
9776 -----------------------
9778 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
9783 -- If type is library level, we are all set
9785 if Is_Library_Level_Entity
(Typ
) then
9789 -- We are also OK if the type already marked as statically allocated,
9790 -- which means we processed it before.
9792 if Is_Statically_Allocated
(Typ
) then
9796 -- Mark type as statically allocated
9798 Set_Is_Statically_Allocated
(Typ
);
9800 -- Check that it is safe to statically allocate this type
9802 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
9803 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
9804 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
9806 elsif Is_Array_Type
(Typ
) then
9807 N
:= First_Index
(Typ
);
9808 while Present
(N
) loop
9809 Ensure_Type_Is_SA
(Etype
(N
));
9813 Ensure_Type_Is_SA
(Component_Type
(Typ
));
9815 elsif Is_Access_Type
(Typ
) then
9816 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
9820 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
9823 if T
/= Standard_Void_Type
then
9824 Ensure_Type_Is_SA
(T
);
9827 F
:= First_Formal
(Designated_Type
(Typ
));
9828 while Present
(F
) loop
9829 Ensure_Type_Is_SA
(Etype
(F
));
9835 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
9838 elsif Is_Record_Type
(Typ
) then
9839 C
:= First_Entity
(Typ
);
9840 while Present
(C
) loop
9841 if Ekind
(C
) = E_Discriminant
9842 or else Ekind
(C
) = E_Component
9844 Ensure_Type_Is_SA
(Etype
(C
));
9846 elsif Is_Type
(C
) then
9847 Ensure_Type_Is_SA
(C
);
9853 elsif Ekind
(Typ
) = E_Subprogram_Type
then
9854 Ensure_Type_Is_SA
(Etype
(Typ
));
9856 C
:= First_Formal
(Typ
);
9857 while Present
(C
) loop
9858 Ensure_Type_Is_SA
(Etype
(C
));
9863 raise Cannot_Be_Static
;
9865 end Ensure_Type_Is_SA
;
9867 -- Start of processing for Freeze_Static_Object
9870 Ensure_Type_Is_SA
(Etype
(E
));
9873 when Cannot_Be_Static
=>
9875 -- If the object that cannot be static is imported or exported, then
9876 -- issue an error message saying that this object cannot be imported
9877 -- or exported. If it has an address clause it is an overlay in the
9878 -- current partition and the static requirement is not relevant.
9879 -- Do not issue any error message when ignoring rep clauses.
9881 if Ignore_Rep_Clauses
then
9884 elsif Is_Imported
(E
) then
9885 if No
(Address_Clause
(E
)) then
9887 ("& cannot be imported (local type is not constant)", E
);
9890 -- Otherwise must be exported, something is wrong if compiler
9891 -- is marking something as statically allocated which cannot be).
9893 else pragma Assert
(Is_Exported
(E
));
9895 ("& cannot be exported (local type is not constant)", E
);
9897 end Freeze_Static_Object
;
9899 -----------------------
9900 -- Freeze_Subprogram --
9901 -----------------------
9903 procedure Freeze_Subprogram
(E
: Entity_Id
) is
9905 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
);
9906 -- Set the conventions of all anonymous access-to-subprogram formals and
9907 -- result subtype of subprogram Subp_Id to the convention of Subp_Id.
9909 ----------------------------
9910 -- Set_Profile_Convention --
9911 ----------------------------
9913 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
) is
9914 Conv
: constant Convention_Id
:= Convention
(Subp_Id
);
9916 procedure Set_Type_Convention
(Typ
: Entity_Id
);
9917 -- Set the convention of anonymous access-to-subprogram type Typ and
9918 -- its designated type to Conv.
9920 -------------------------
9921 -- Set_Type_Convention --
9922 -------------------------
9924 procedure Set_Type_Convention
(Typ
: Entity_Id
) is
9926 -- Set the convention on both the anonymous access-to-subprogram
9927 -- type and the subprogram type it points to because both types
9928 -- participate in conformance-related checks.
9930 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
9931 Set_Convention
(Typ
, Conv
);
9932 Set_Convention
(Designated_Type
(Typ
), Conv
);
9934 end Set_Type_Convention
;
9940 -- Start of processing for Set_Profile_Convention
9943 Formal
:= First_Formal
(Subp_Id
);
9944 while Present
(Formal
) loop
9945 Set_Type_Convention
(Etype
(Formal
));
9946 Next_Formal
(Formal
);
9949 if Ekind
(Subp_Id
) = E_Function
then
9950 Set_Type_Convention
(Etype
(Subp_Id
));
9952 end Set_Profile_Convention
;
9959 -- Start of processing for Freeze_Subprogram
9962 -- Subprogram may not have an address clause unless it is imported
9964 if Present
(Address_Clause
(E
)) then
9965 if not Is_Imported
(E
) then
9967 ("address clause can only be given for imported subprogram",
9968 Name
(Address_Clause
(E
)));
9972 -- Reset the Pure indication on an imported subprogram unless an
9973 -- explicit Pure_Function pragma was present or the subprogram is an
9974 -- intrinsic. We do this because otherwise it is an insidious error
9975 -- to call a non-pure function from pure unit and have calls
9976 -- mysteriously optimized away. What happens here is that the Import
9977 -- can bypass the normal check to ensure that pure units call only pure
9980 -- The reason for the intrinsic exception is that in general, intrinsic
9981 -- functions (such as shifts) are pure anyway. The only exceptions are
9982 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
9983 -- in any case, so no problem arises.
9986 and then Is_Pure
(E
)
9987 and then not Has_Pragma_Pure_Function
(E
)
9988 and then not Is_Intrinsic_Subprogram
(E
)
9990 Set_Is_Pure
(E
, False);
9993 -- For C++ constructors check that their external name has been given
9994 -- (either in pragma CPP_Constructor or in a pragma import).
9996 if Is_Constructor
(E
)
9997 and then Convention
(E
) = Convention_CPP
9999 (No
(Interface_Name
(E
))
10000 or else String_Equal
10001 (L
=> Strval
(Interface_Name
(E
)),
10002 R
=> Strval
(Get_Default_External_Name
(E
))))
10005 ("'C++ constructor must have external name or link name", E
);
10008 -- We also reset the Pure indication on a subprogram with an Address
10009 -- parameter, because the parameter may be used as a pointer and the
10010 -- referenced data may change even if the address value does not.
10012 -- Note that if the programmer gave an explicit Pure_Function pragma,
10013 -- then we believe the programmer, and leave the subprogram Pure. We
10014 -- also suppress this check on run-time files.
10017 and then Is_Subprogram
(E
)
10018 and then not Has_Pragma_Pure_Function
(E
)
10019 and then not Is_Internal_Unit
(Current_Sem_Unit
)
10021 Check_Function_With_Address_Parameter
(E
);
10024 -- Ensure that all anonymous access-to-subprogram types inherit the
10025 -- convention of their related subprogram (RM 6.3.1(13.1/5)). This is
10026 -- not done for a defaulted convention Ada because those types also
10027 -- default to Ada. Convention Protected must not be propagated when
10028 -- the subprogram is an entry because this would be illegal. The only
10029 -- way to force convention Protected on these kinds of types is to
10030 -- include keyword "protected" in the access definition. Conventions
10031 -- Entry and Intrinsic are also not propagated (specified by AI12-0207).
10033 if Convention
(E
) /= Convention_Ada
10034 and then Convention
(E
) /= Convention_Protected
10035 and then Convention
(E
) /= Convention_Entry
10036 and then Convention
(E
) /= Convention_Intrinsic
10038 Set_Profile_Convention
(E
);
10041 -- For non-foreign convention subprograms, this is where we create
10042 -- the extra formals (for accessibility level and constrained bit
10043 -- information). We delay this till the freeze point precisely so
10044 -- that we know the convention.
10046 if not Has_Foreign_Convention
(E
) then
10048 -- Extra formals of dispatching operations are added later by
10049 -- Expand_Freeze_Record_Type, which also adds extra formals to
10050 -- internal entities built to handle interface types.
10052 if not Is_Dispatching_Operation
(E
) then
10053 Create_Extra_Formals
(E
);
10056 ((Ekind
(E
) = E_Subprogram_Type
10057 and then Extra_Formals_OK
(E
))
10060 and then Extra_Formals_OK
(E
)
10062 (No
(Overridden_Operation
(E
))
10063 or else Extra_Formals_Match_OK
(E
,
10064 Ultimate_Alias
(Overridden_Operation
(E
))))));
10067 Set_Mechanisms
(E
);
10069 -- If this is convention Ada and a Valued_Procedure, that's odd
10071 if Ekind
(E
) = E_Procedure
10072 and then Is_Valued_Procedure
(E
)
10073 and then Convention
(E
) = Convention_Ada
10074 and then Warn_On_Export_Import
10077 ("??Valued_Procedure has no effect for convention Ada", E
);
10078 Set_Is_Valued_Procedure
(E
, False);
10081 -- Case of foreign convention
10084 Set_Mechanisms
(E
);
10086 -- For foreign conventions, warn about return of unconstrained array
10088 if Ekind
(E
) = E_Function
then
10089 Retype
:= Underlying_Type
(Etype
(E
));
10091 -- If no return type, probably some other error, e.g. a
10092 -- missing full declaration, so ignore.
10094 if No
(Retype
) then
10097 -- If the return type is generic, we have emitted a warning
10098 -- earlier on, and there is nothing else to check here. Specific
10099 -- instantiations may lead to erroneous behavior.
10101 elsif Is_Generic_Type
(Etype
(E
)) then
10104 -- Display warning if returning unconstrained array
10106 elsif Is_Array_Type
(Retype
)
10107 and then not Is_Constrained
(Retype
)
10109 -- Check appropriate warning is enabled (should we check for
10110 -- Warnings (Off) on specific entities here, probably so???)
10112 and then Warn_On_Export_Import
10115 ("?x?foreign convention function& should not return " &
10116 "unconstrained array", E
);
10121 -- If any of the formals for an exported foreign convention
10122 -- subprogram have defaults, then emit an appropriate warning since
10123 -- this is odd (default cannot be used from non-Ada code)
10125 if Is_Exported
(E
) then
10126 F
:= First_Formal
(E
);
10127 while Present
(F
) loop
10128 if Warn_On_Export_Import
10129 and then Present
(Default_Value
(F
))
10132 ("?x?parameter cannot be defaulted in non-Ada call",
10133 Default_Value
(F
));
10141 -- Pragma Inline_Always is disallowed for dispatching subprograms
10142 -- because the address of such subprograms is saved in the dispatch
10143 -- table to support dispatching calls, and dispatching calls cannot
10144 -- be inlined. This is consistent with the restriction against using
10145 -- 'Access or 'Address on an Inline_Always subprogram.
10147 if Is_Dispatching_Operation
(E
)
10148 and then Has_Pragma_Inline_Always
(E
)
10151 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
10154 -- Because of the implicit representation of inherited predefined
10155 -- operators in the front-end, the overriding status of the operation
10156 -- may be affected when a full view of a type is analyzed, and this is
10157 -- not captured by the analysis of the corresponding type declaration.
10158 -- Therefore the correctness of a not-overriding indicator must be
10159 -- rechecked when the subprogram is frozen.
10161 if Nkind
(E
) = N_Defining_Operator_Symbol
10162 and then not Error_Posted
(Parent
(E
))
10164 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
10167 Retype
:= Get_Fullest_View
(Etype
(E
));
10169 if Transform_Function_Array
10170 and then Nkind
(Parent
(E
)) = N_Function_Specification
10171 and then Is_Array_Type
(Retype
)
10172 and then Is_Constrained
(Retype
)
10173 and then not Is_Unchecked_Conversion_Instance
(E
)
10174 and then not Rewritten_For_C
(E
)
10176 Build_Procedure_Form
(Unit_Declaration_Node
(E
));
10178 end Freeze_Subprogram
;
10180 ----------------------
10181 -- Is_Fully_Defined --
10182 ----------------------
10184 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
10186 if Ekind
(T
) = E_Class_Wide_Type
then
10187 return Is_Fully_Defined
(Etype
(T
));
10189 elsif Is_Array_Type
(T
) then
10190 return Is_Fully_Defined
(Component_Type
(T
));
10192 elsif Is_Record_Type
(T
)
10193 and not Is_Private_Type
(T
)
10195 -- Verify that the record type has no components with private types
10196 -- without completion.
10202 Comp
:= First_Component
(T
);
10203 while Present
(Comp
) loop
10204 if not Is_Fully_Defined
(Etype
(Comp
)) then
10208 Next_Component
(Comp
);
10213 -- For the designated type of an access to subprogram, all types in
10214 -- the profile must be fully defined.
10216 elsif Ekind
(T
) = E_Subprogram_Type
then
10221 F
:= First_Formal
(T
);
10222 while Present
(F
) loop
10223 if not Is_Fully_Defined
(Etype
(F
)) then
10230 return Is_Fully_Defined
(Etype
(T
));
10234 return not Is_Private_Type
(T
)
10235 or else Present
(Full_View
(Base_Type
(T
)));
10237 end Is_Fully_Defined
;
10239 ---------------------------------
10240 -- Process_Default_Expressions --
10241 ---------------------------------
10243 procedure Process_Default_Expressions
10245 After
: in out Node_Id
)
10247 Loc
: constant Source_Ptr
:= Sloc
(E
);
10254 Set_Default_Expressions_Processed
(E
);
10256 -- A subprogram instance and its associated anonymous subprogram share
10257 -- their signature. The default expression functions are defined in the
10258 -- wrapper packages for the anonymous subprogram, and should not be
10259 -- generated again for the instance.
10261 if Is_Generic_Instance
(E
)
10262 and then Present
(Alias
(E
))
10263 and then Default_Expressions_Processed
(Alias
(E
))
10268 Formal
:= First_Formal
(E
);
10269 while Present
(Formal
) loop
10270 if Present
(Default_Value
(Formal
)) then
10272 -- We work with a copy of the default expression because we
10273 -- do not want to disturb the original, since this would mess
10274 -- up the conformance checking.
10276 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
10278 -- The analysis of the expression may generate insert actions,
10279 -- which of course must not be executed. We wrap those actions
10280 -- in a procedure that is not called, and later on eliminated.
10281 -- The following cases have no side effects, and are analyzed
10284 if Nkind
(Dcopy
) = N_Identifier
10285 or else Nkind
(Dcopy
) in N_Expanded_Name
10286 | N_Integer_Literal
10287 | N_Character_Literal
10290 or else (Nkind
(Dcopy
) = N_Attribute_Reference
10291 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
10292 or else Known_Null
(Dcopy
)
10294 -- If there is no default function, we must still do a full
10295 -- analyze call on the default value, to ensure that all error
10296 -- checks are performed, e.g. those associated with static
10297 -- evaluation. Note: this branch will always be taken if the
10298 -- analyzer is turned off (but we still need the error checks).
10300 -- Note: the setting of parent here is to meet the requirement
10301 -- that we can only analyze the expression while attached to
10302 -- the tree. Really the requirement is that the parent chain
10303 -- be set, we don't actually need to be in the tree.
10305 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
10308 -- Default expressions are resolved with their own type if the
10309 -- context is generic, to avoid anomalies with private types.
10311 if Ekind
(Scope
(E
)) = E_Generic_Package
then
10314 Resolve
(Dcopy
, Etype
(Formal
));
10317 -- If that resolved expression will raise constraint error,
10318 -- then flag the default value as raising constraint error.
10319 -- This allows a proper error message on the calls.
10321 if Raises_Constraint_Error
(Dcopy
) then
10322 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
10325 -- If the default is a parameterless call, we use the name of
10326 -- the called function directly, and there is no body to build.
10328 elsif Nkind
(Dcopy
) = N_Function_Call
10329 and then No
(Parameter_Associations
(Dcopy
))
10333 -- Else construct and analyze the body of a wrapper procedure
10334 -- that contains an object declaration to hold the expression.
10335 -- Given that this is done only to complete the analysis, it is
10336 -- simpler to build a procedure than a function which might
10337 -- involve secondary stack expansion.
10340 Dnam
:= Make_Temporary
(Loc
, 'D');
10343 Make_Subprogram_Body
(Loc
,
10345 Make_Procedure_Specification
(Loc
,
10346 Defining_Unit_Name
=> Dnam
),
10348 Declarations
=> New_List
(
10349 Make_Object_Declaration
(Loc
,
10350 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
10351 Object_Definition
=>
10352 New_Occurrence_Of
(Etype
(Formal
), Loc
),
10353 Expression
=> New_Copy_Tree
(Dcopy
))),
10355 Handled_Statement_Sequence
=>
10356 Make_Handled_Sequence_Of_Statements
(Loc
,
10357 Statements
=> Empty_List
));
10359 Set_Scope
(Dnam
, Scope
(E
));
10360 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
10361 Set_Is_Eliminated
(Dnam
);
10362 Insert_After
(After
, Dbody
);
10368 Next_Formal
(Formal
);
10370 end Process_Default_Expressions
;
10372 ----------------------------------------
10373 -- Set_Component_Alignment_If_Not_Set --
10374 ----------------------------------------
10376 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
10378 -- Ignore if not base type, subtypes don't need anything
10380 if Typ
/= Base_Type
(Typ
) then
10384 -- Do not override existing representation
10386 if Is_Packed
(Typ
) then
10389 elsif Has_Specified_Layout
(Typ
) then
10392 elsif Component_Alignment
(Typ
) /= Calign_Default
then
10396 Set_Component_Alignment
10397 (Typ
, Scope_Stack
.Table
10398 (Scope_Stack
.Last
).Component_Alignment_Default
);
10400 end Set_Component_Alignment_If_Not_Set
;
10402 --------------------------
10403 -- Set_SSO_From_Default --
10404 --------------------------
10406 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
10407 Reversed
: Boolean;
10410 -- Set default SSO for an array or record base type, except in case of
10411 -- a type extension (which always inherits the SSO of its parent type).
10413 if Is_Base_Type
(T
)
10414 and then (Is_Array_Type
(T
)
10415 or else (Is_Record_Type
(T
)
10416 and then not (Is_Tagged_Type
(T
)
10417 and then Is_Derived_Type
(T
))))
10420 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
10422 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
10424 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
10426 -- For a record type, if bit order is specified explicitly,
10427 -- then do not set SSO from default if not consistent. Note that
10428 -- we do not want to look at a Bit_Order attribute definition
10429 -- for a parent: if we were to inherit Bit_Order, then both
10430 -- SSO_Set_*_By_Default flags would have been cleared already
10431 -- (by Inherit_Aspects_At_Freeze_Point).
10434 (Is_Record_Type
(T
)
10436 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
10437 and then Reverse_Bit_Order
(T
) /= Reversed
)
10439 -- If flags cause reverse storage order, then set the result. Note
10440 -- that we would have ignored the pragma setting the non default
10441 -- storage order in any case, hence the assertion at this point.
10444 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
10446 Set_Reverse_Storage_Order
(T
, Reversed
);
10448 -- For a record type, also set reversed bit order. Note: if a bit
10449 -- order has been specified explicitly, then this is a no-op.
10451 if Is_Record_Type
(T
) then
10452 Set_Reverse_Bit_Order
(T
, Reversed
);
10456 end Set_SSO_From_Default
;
10462 procedure Undelay_Type
(T
: Entity_Id
) is
10464 Set_Has_Delayed_Freeze
(T
, False);
10465 Set_Freeze_Node
(T
, Empty
);
10467 -- Since we don't want T to have a Freeze_Node, we don't want its
10468 -- Full_View or Corresponding_Record_Type to have one either.
10470 -- ??? Fundamentally, this whole handling is unpleasant. What we really
10471 -- want is to be sure that for an Itype that's part of record R and is a
10472 -- subtype of type T, that it's frozen after the later of the freeze
10473 -- points of R and T. We have no way of doing that directly, so what we
10474 -- do is force most such Itypes to be frozen as part of freezing R via
10475 -- this procedure and only delay the ones that need to be delayed
10476 -- (mostly the designated types of access types that are defined as part
10479 if Is_Private_Type
(T
)
10480 and then Present
(Full_View
(T
))
10481 and then Is_Itype
(Full_View
(T
))
10482 and then Is_Record_Type
(Scope
(Full_View
(T
)))
10484 Undelay_Type
(Full_View
(T
));
10487 if Is_Concurrent_Type
(T
)
10488 and then Present
(Corresponding_Record_Type
(T
))
10489 and then Is_Itype
(Corresponding_Record_Type
(T
))
10490 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
10492 Undelay_Type
(Corresponding_Record_Type
(T
));
10500 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
) is
10501 Ent
: constant Entity_Id
:= Entity
(Nam
);
10502 -- The object to which the address clause applies
10505 Old
: Entity_Id
:= Empty
;
10509 -- No warning if address clause overlay warnings are off
10511 if not Address_Clause_Overlay_Warnings
then
10515 -- No warning if there is an explicit initialization
10517 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
10519 if Present
(Init
) and then Comes_From_Source
(Init
) then
10523 -- We only give the warning for non-imported entities of a type for
10524 -- which a non-null base init proc is defined, or for objects of access
10525 -- types with implicit null initialization, or when Normalize_Scalars
10526 -- applies and the type is scalar or a string type (the latter being
10527 -- tested for because predefined String types are initialized by inline
10528 -- code rather than by an init_proc). Note that we do not give the
10529 -- warning for Initialize_Scalars, since we suppressed initialization
10530 -- in this case. Also, do not warn if Suppress_Initialization is set
10531 -- either on the type, or on the object via pragma or aspect.
10534 and then not Is_Imported
(Ent
)
10535 and then not Initialization_Suppressed
(Typ
)
10536 and then not (Ekind
(Ent
) = E_Variable
10537 and then Initialization_Suppressed
(Ent
))
10538 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
10539 or else Is_Access_Type
(Typ
)
10540 or else (Normalize_Scalars
10541 and then (Is_Scalar_Type
(Typ
)
10542 or else Is_String_Type
(Typ
))))
10544 if Nkind
(Expr
) = N_Attribute_Reference
10545 and then Is_Entity_Name
(Prefix
(Expr
))
10547 Old
:= Entity
(Prefix
(Expr
));
10549 elsif Is_Entity_Name
(Expr
)
10550 and then Ekind
(Entity
(Expr
)) = E_Constant
10552 Decl
:= Declaration_Node
(Entity
(Expr
));
10554 if Nkind
(Decl
) = N_Object_Declaration
10555 and then Present
(Expression
(Decl
))
10556 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
10557 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
10559 Old
:= Entity
(Prefix
(Expression
(Decl
)));
10561 elsif Nkind
(Expr
) = N_Function_Call
then
10565 -- A function call (most likely to To_Address) is probably not an
10566 -- overlay, so skip warning. Ditto if the function call was inlined
10567 -- and transformed into an entity.
10569 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
10573 -- If a pragma Import follows, we assume that it is for the current
10574 -- target of the address clause, and skip the warning. There may be
10575 -- a source pragma or an aspect that specifies import and generates
10576 -- the corresponding pragma. These will indicate that the entity is
10577 -- imported and that is checked above so that the spurious warning
10578 -- (generated when the entity is frozen) will be suppressed. The
10579 -- pragma may be attached to the aspect, so it is not yet a list
10582 if Is_List_Member
(Parent
(Expr
)) then
10583 Decl
:= Next
(Parent
(Expr
));
10586 and then Nkind
(Decl
) = N_Pragma
10587 and then Pragma_Name
(Decl
) = Name_Import
10593 -- Otherwise give warning message
10595 if Present
(Old
) then
10596 Error_Msg_Node_2
:= Old
;
10598 ("default initialization of & may modify &?o?",
10602 ("default initialization of & may modify overlaid storage?o?",
10606 -- Add friendly warning if initialization comes from a packed array
10609 if Is_Record_Type
(Typ
) then
10614 Comp
:= First_Component
(Typ
);
10615 while Present
(Comp
) loop
10616 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
10617 and then Present
(Expression
(Parent
(Comp
)))
10620 elsif Is_Array_Type
(Etype
(Comp
))
10621 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
10624 ("\packed array component& " &
10625 "will be initialized to zero??",
10629 Next_Component
(Comp
);
10636 ("\use pragma Import for & to " &
10637 "suppress initialization (RM B.1(24))??",