1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2022, 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
));
401 Actuals
: List_Id
:= No_List
;
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 -- For simple renamings, subsequent calls can be expanded directly as
477 -- calls to the renamed entity. The body must be generated in any case
478 -- for calls that may appear elsewhere. This is not done in the case
479 -- where the subprogram is an instantiation because the actual proper
480 -- body has not been built yet. This is also not done in GNATprove mode
481 -- as we need to check other conditions for creating a body to inline
482 -- in that case, which are controlled in Analyze_Subprogram_Body_Helper.
484 if Ekind
(Old_S
) in E_Function | E_Procedure
485 and then Nkind
(Decl
) = N_Subprogram_Declaration
486 and then not Is_Generic_Instance
(Old_S
)
487 and then not GNATprove_Mode
489 Set_Body_To_Inline
(Decl
, Old_S
);
492 -- Check whether the return type is a limited view. If the subprogram
493 -- is already frozen the generated body may have a non-limited view
494 -- of the type, that must be used, because it is the one in the spec
495 -- of the renaming declaration.
497 if Ekind
(Old_S
) = E_Function
498 and then Is_Entity_Name
(Result_Definition
(Spec
))
501 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
503 if Has_Non_Limited_View
(Ret_Type
) then
504 Set_Result_Definition
505 (Spec
, New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
510 -- The body generated for this renaming is an internal artifact, and
511 -- does not constitute a freeze point for the called entity.
513 Set_Must_Not_Freeze
(Call_Name
);
515 Formal
:= First_Formal
(Defining_Entity
(Decl
));
517 if Present
(Pref
) then
519 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
520 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
523 -- The controlling formal may be an access parameter, or the
524 -- actual may be an access value, so adjust accordingly.
526 if Is_Access_Type
(Pref_Type
)
527 and then not Is_Access_Type
(Form_Type
)
530 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
532 elsif Is_Access_Type
(Form_Type
)
533 and then not Is_Access_Type
(Pref
)
537 Make_Attribute_Reference
(Loc
,
538 Attribute_Name
=> Name_Access
,
539 Prefix
=> Relocate_Node
(Pref
)));
541 Actuals
:= New_List
(Pref
);
545 elsif Present
(Formal
) then
552 while Present
(Formal
) loop
553 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
554 Next_Formal
(Formal
);
557 -- If the renamed entity is an entry, inherit its profile. For other
558 -- renamings as bodies, both profiles must be subtype conformant, so it
559 -- is not necessary to replace the profile given in the declaration.
560 -- However, default values that are aggregates are rewritten when
561 -- partially analyzed, so we recover the original aggregate to insure
562 -- that subsequent conformity checking works. Similarly, if the default
563 -- expression was constant-folded, recover the original expression.
565 Formal
:= First_Formal
(Defining_Entity
(Decl
));
567 if Present
(Formal
) then
568 O_Formal
:= First_Formal
(Old_S
);
569 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
570 while Present
(Formal
) loop
571 if Is_Entry
(Old_S
) then
572 if Nkind
(Parameter_Type
(Param_Spec
)) /=
575 Set_Etype
(Formal
, Etype
(O_Formal
));
576 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
579 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
580 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
581 Nkind
(Default_Value
(O_Formal
))
583 Set_Expression
(Param_Spec
,
584 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
587 Next_Formal
(Formal
);
588 Next_Formal
(O_Formal
);
593 -- If the renamed entity is a function, the generated body contains a
594 -- return statement. Otherwise, build a procedure call. If the entity is
595 -- an entry, subsequent analysis of the call will transform it into the
596 -- proper entry or protected operation call. If the renamed entity is
597 -- a character literal, return it directly.
599 if Ekind
(Old_S
) = E_Function
600 or else Ekind
(Old_S
) = E_Operator
601 or else (Ekind
(Old_S
) = E_Subprogram_Type
602 and then Etype
(Old_S
) /= Standard_Void_Type
)
605 Make_Simple_Return_Statement
(Loc
,
607 Make_Function_Call
(Loc
,
609 Parameter_Associations
=> Actuals
));
611 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
613 Make_Simple_Return_Statement
(Loc
,
614 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
616 elsif Nkind
(Nam
) = N_Character_Literal
then
618 Make_Simple_Return_Statement
(Loc
, Expression
=> Call_Name
);
622 Make_Procedure_Call_Statement
(Loc
,
624 Parameter_Associations
=> Actuals
);
627 -- Create entities for subprogram body and formals
629 Set_Defining_Unit_Name
(Spec
,
630 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
632 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
633 while Present
(Param_Spec
) loop
634 Set_Defining_Identifier
(Param_Spec
,
635 Make_Defining_Identifier
(Loc
,
636 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
640 -- In GNATprove, prefer to generate an expression function whenever
641 -- possible, to benefit from the more precise analysis in that case
642 -- (as if an implicit postcondition had been generated).
645 and then Nkind
(Call_Node
) = N_Simple_Return_Statement
648 Make_Expression_Function
(Loc
,
649 Specification
=> Spec
,
650 Expression
=> Expression
(Call_Node
));
653 Make_Subprogram_Body
(Loc
,
654 Specification
=> Spec
,
655 Declarations
=> New_List
,
656 Handled_Statement_Sequence
=>
657 Make_Handled_Sequence_Of_Statements
(Loc
,
658 Statements
=> New_List
(Call_Node
)));
661 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
663 Make_Subprogram_Declaration
(Loc
,
664 Specification
=> Specification
(N
)));
667 -- Link the body to the entity whose declaration it completes. If
668 -- the body is analyzed when the renamed entity is frozen, it may
669 -- be necessary to restore the proper scope (see package Exp_Ch13).
671 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
672 and then Present
(Corresponding_Spec
(N
))
674 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
676 Set_Corresponding_Spec
(Body_Node
, New_S
);
680 end Build_Renamed_Body
;
682 --------------------------
683 -- Check_Address_Clause --
684 --------------------------
686 procedure Check_Address_Clause
(E
: Entity_Id
) is
687 Addr
: constant Node_Id
:= Address_Clause
(E
);
688 Typ
: constant Entity_Id
:= Etype
(E
);
693 Tag_Assign
: Node_Id
;
696 if Present
(Addr
) then
698 -- For a deferred constant, the initialization value is on full view
700 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
701 Decl
:= Declaration_Node
(Full_View
(E
));
703 Decl
:= Declaration_Node
(E
);
706 Expr
:= Expression
(Addr
);
708 if Needs_Constant_Address
(Decl
, Typ
) then
709 Check_Constant_Address_Clause
(Expr
, E
);
711 -- Has_Delayed_Freeze was set on E when the address clause was
712 -- analyzed, and must remain set because we want the address
713 -- clause to be elaborated only after any entity it references
714 -- has been elaborated.
717 -- If Rep_Clauses are to be ignored, remove address clause from
718 -- list attached to entity, because it may be illegal for gigi,
719 -- for example by breaking order of elaboration.
721 if Ignore_Rep_Clauses
then
726 Rep
:= First_Rep_Item
(E
);
729 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
733 and then Next_Rep_Item
(Rep
) /= Addr
739 if Present
(Rep
) then
740 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
744 -- And now remove the address clause
746 Kill_Rep_Clause
(Addr
);
748 elsif not Error_Posted
(Expr
)
749 and then not Needs_Finalization
(Typ
)
751 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
754 Init
:= Expression
(Decl
);
756 -- If a variable, or a non-imported constant, overlays a constant
757 -- object and has an initialization value, then the initialization
758 -- may end up writing into read-only memory. Detect the cases of
759 -- statically identical values and remove the initialization. In
760 -- the other cases, give a warning. We will give other warnings
761 -- later for the variable if it is assigned.
763 if (Ekind
(E
) = E_Variable
764 or else (Ekind
(E
) = E_Constant
765 and then not Is_Imported
(E
)))
766 and then Overlays_Constant
(E
)
767 and then Present
(Init
)
774 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
776 if Ekind
(O_Ent
) = E_Constant
777 and then Etype
(O_Ent
) = Typ
778 and then Present
(Constant_Value
(O_Ent
))
779 and then Compile_Time_Compare
781 Constant_Value
(O_Ent
),
782 Assume_Valid
=> True) = EQ
784 Set_No_Initialization
(Decl
);
787 elsif Comes_From_Source
(Init
)
788 and then Address_Clause_Overlay_Warnings
790 Error_Msg_Sloc
:= Sloc
(Addr
);
792 ("?o?constant& may be modified via address clause#",
798 -- Remove side effects from initial expression, except in the case of
799 -- limited build-in-place calls and aggregates, which have their own
800 -- expansion elsewhere. This exception is necessary to avoid copying
804 and then not Is_Limited_View
(Typ
)
806 -- Capture initialization value at point of declaration, and make
807 -- explicit assignment legal, because object may be a constant.
809 Remove_Side_Effects
(Init
);
810 Lhs
:= New_Occurrence_Of
(E
, Sloc
(Decl
));
811 Set_Assignment_OK
(Lhs
);
813 -- Move initialization to freeze actions, once the object has
814 -- been frozen and the address clause alignment check has been
817 Append_Freeze_Action
(E
,
818 Make_Assignment_Statement
(Sloc
(Decl
),
820 Expression
=> Expression
(Decl
)));
822 Set_No_Initialization
(Decl
);
824 -- If the object is tagged, check whether the tag must be
825 -- reassigned explicitly.
827 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
828 if Present
(Tag_Assign
) then
829 Append_Freeze_Action
(E
, Tag_Assign
);
833 end Check_Address_Clause
;
835 -----------------------------
836 -- Check_Compile_Time_Size --
837 -----------------------------
839 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
841 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
842 -- Sets the compile time known size in the RM_Size field of T, checking
843 -- for a size clause that was given which attempts to give a small size.
845 function Size_Known
(T
: Entity_Id
) return Boolean;
846 -- Recursive function that does all the work
848 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
849 -- If T is a constrained subtype, its size is not known if any of its
850 -- discriminant constraints is not static and it is not a null record.
851 -- The test is conservative and doesn't check that the components are
852 -- in fact constrained by non-static discriminant values. Could be made
859 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
861 if S
> System_Max_Integer_Size
then
864 -- Check for bad size clause given
866 elsif Has_Size_Clause
(T
) then
867 if RM_Size
(T
) < S
then
868 Error_Msg_Uint_1
:= S
;
869 Error_Msg_NE
(Size_Too_Small_Message
, Size_Clause
(T
), T
);
872 -- Set size if not set already. Do not set it to Uint_0, because in
873 -- some cases (notably array-of-record), the Component_Size is
874 -- No_Uint, which causes S to be Uint_0. Presumably the RM_Size and
875 -- Component_Size will eventually be set correctly by the back end.
877 elsif not Known_RM_Size
(T
) and then S
/= Uint_0
then
886 function Size_Known
(T
: Entity_Id
) return Boolean is
891 if Size_Known_At_Compile_Time
(T
) then
894 -- Always True for elementary types, even generic formal elementary
895 -- types. We used to return False in the latter case, but the size
896 -- is known at compile time, even in the template, we just do not
897 -- know the exact size but that's not the point of this routine.
899 elsif Is_Elementary_Type
(T
) or else Is_Task_Type
(T
) then
904 elsif Is_Array_Type
(T
) then
906 -- String literals always have known size, and we can set it
908 if Ekind
(T
) = E_String_Literal_Subtype
then
909 if Known_Component_Size
(T
) then
911 (T
, Component_Size
(T
) * String_Literal_Length
(T
));
914 -- The following is wrong, but does what previous versions
915 -- did. The Component_Size is unknown for the string in a
917 Set_Small_Size
(T
, Uint_0
);
922 -- Unconstrained types never have known at compile time size
924 elsif not Is_Constrained
(T
) then
927 -- Don't do any recursion on type with error posted, since we may
928 -- have a malformed type that leads us into a loop.
930 elsif Error_Posted
(T
) then
933 -- Otherwise if component size unknown, then array size unknown
935 elsif not Size_Known
(Component_Type
(T
)) then
939 -- Check for all indexes static, and also compute possible size
940 -- (in case it is not greater than System_Max_Integer_Size and
941 -- thus may be packable).
947 Size
: Uint
:= Component_Size
(T
);
951 -- See comment in Set_Small_Size above
957 Index
:= First_Index
(T
);
958 while Present
(Index
) loop
959 if Nkind
(Index
) = N_Range
then
960 Get_Index_Bounds
(Index
, Low
, High
);
962 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
966 Low
:= Type_Low_Bound
(Etype
(Index
));
967 High
:= Type_High_Bound
(Etype
(Index
));
970 if not Compile_Time_Known_Value
(Low
)
971 or else not Compile_Time_Known_Value
(High
)
972 or else Etype
(Index
) = Any_Type
977 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
989 Set_Small_Size
(T
, Size
);
993 -- For non-generic private types, go to underlying type if present
995 elsif Is_Private_Type
(T
)
996 and then not Is_Generic_Type
(T
)
997 and then Present
(Underlying_Type
(T
))
999 -- Don't do any recursion on type with error posted, since we may
1000 -- have a malformed type that leads us into a loop.
1002 if Error_Posted
(T
) then
1005 return Size_Known
(Underlying_Type
(T
));
1010 elsif Is_Record_Type
(T
) then
1012 -- A class-wide type is never considered to have a known size
1014 if Is_Class_Wide_Type
(T
) then
1017 -- A subtype of a variant record must not have non-static
1018 -- discriminated components.
1020 elsif T
/= Base_Type
(T
)
1021 and then not Static_Discriminated_Components
(T
)
1025 -- Don't do any recursion on type with error posted, since we may
1026 -- have a malformed type that leads us into a loop.
1028 elsif Error_Posted
(T
) then
1032 -- Now look at the components of the record
1035 -- The following two variables are used to keep track of the
1036 -- size of packed records if we can tell the size of the packed
1037 -- record in the front end. Packed_Size_Known is True if so far
1038 -- we can figure out the size. It is initialized to True for a
1039 -- packed record, unless the record has either discriminants or
1040 -- independent components, or is a strict-alignment type, since
1041 -- it cannot be fully packed in this case.
1043 -- The reason we eliminate the discriminated case is that
1044 -- we don't know the way the back end lays out discriminated
1045 -- packed records. If Packed_Size_Known is True, then
1046 -- Packed_Size is the size in bits so far.
1048 Packed_Size_Known
: Boolean :=
1050 and then not Has_Discriminants
(T
)
1051 and then not Has_Independent_Components
(T
)
1052 and then not Strict_Alignment
(T
);
1054 Packed_Size
: Uint
:= Uint_0
;
1055 -- Size in bits so far
1058 -- Test for variant part present
1060 if Has_Discriminants
(T
)
1061 and then Present
(Parent
(T
))
1062 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
1063 and then Nkind
(Type_Definition
(Parent
(T
))) =
1065 and then not Null_Present
(Type_Definition
(Parent
(T
)))
1067 Present
(Variant_Part
1068 (Component_List
(Type_Definition
(Parent
(T
)))))
1070 -- If variant part is present, and type is unconstrained,
1071 -- then we must have defaulted discriminants, or a size
1072 -- clause must be present for the type, or else the size
1073 -- is definitely not known at compile time.
1075 if not Is_Constrained
(T
)
1077 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
1078 and then not Known_RM_Size
(T
)
1084 -- Loop through components
1086 Comp
:= First_Component_Or_Discriminant
(T
);
1087 while Present
(Comp
) loop
1088 Ctyp
:= Etype
(Comp
);
1090 -- We do not know the packed size if there is a component
1091 -- clause present (we possibly could, but this would only
1092 -- help in the case of a record with partial rep clauses.
1093 -- That's because in the case of full rep clauses, the
1094 -- size gets figured out anyway by a different circuit).
1096 if Present
(Component_Clause
(Comp
)) then
1097 Packed_Size_Known
:= False;
1100 -- We do not know the packed size for an independent
1101 -- component or if it is of a strict-alignment type,
1102 -- since packing does not touch these (RM 13.2(7)).
1104 if Is_Independent
(Comp
)
1105 or else Is_Independent
(Ctyp
)
1106 or else Strict_Alignment
(Ctyp
)
1108 Packed_Size_Known
:= False;
1111 -- We need to identify a component that is an array where
1112 -- the index type is an enumeration type with non-standard
1113 -- representation, and some bound of the type depends on a
1116 -- This is because gigi computes the size by doing a
1117 -- substitution of the appropriate discriminant value in
1118 -- the size expression for the base type, and gigi is not
1119 -- clever enough to evaluate the resulting expression (which
1120 -- involves a call to rep_to_pos) at compile time.
1122 -- It would be nice if gigi would either recognize that
1123 -- this expression can be computed at compile time, or
1124 -- alternatively figured out the size from the subtype
1125 -- directly, where all the information is at hand ???
1127 if Is_Array_Type
(Etype
(Comp
))
1128 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1131 Ocomp
: constant Entity_Id
:=
1132 Original_Record_Component
(Comp
);
1133 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1139 Ind
:= First_Index
(OCtyp
);
1140 while Present
(Ind
) loop
1141 Indtyp
:= Etype
(Ind
);
1143 if Is_Enumeration_Type
(Indtyp
)
1144 and then Has_Non_Standard_Rep
(Indtyp
)
1146 Lo
:= Type_Low_Bound
(Indtyp
);
1147 Hi
:= Type_High_Bound
(Indtyp
);
1149 if Is_Entity_Name
(Lo
)
1150 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1154 elsif Is_Entity_Name
(Hi
)
1155 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1166 -- Clearly size of record is not known if the size of one of
1167 -- the components is not known.
1169 if not Size_Known
(Ctyp
) then
1173 -- Accumulate packed size if possible
1175 if Packed_Size_Known
then
1177 -- We can deal with elementary types, small packed arrays
1178 -- if the representation is a modular type and also small
1179 -- record types as checked by Set_Small_Size.
1181 if Is_Elementary_Type
(Ctyp
)
1182 or else (Is_Array_Type
(Ctyp
)
1184 (Packed_Array_Impl_Type
(Ctyp
))
1185 and then Is_Modular_Integer_Type
1186 (Packed_Array_Impl_Type
(Ctyp
)))
1187 or else Is_Record_Type
(Ctyp
)
1189 -- If RM_Size is known and static, then we can keep
1190 -- accumulating the packed size.
1192 if Known_Static_RM_Size
(Ctyp
) then
1194 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1196 -- If we have a field whose RM_Size is not known then
1197 -- we can't figure out the packed size here.
1200 Packed_Size_Known
:= False;
1203 -- For other types we can't figure out the packed size
1206 Packed_Size_Known
:= False;
1210 Next_Component_Or_Discriminant
(Comp
);
1213 if Packed_Size_Known
then
1214 Set_Small_Size
(T
, Packed_Size
);
1220 -- All other cases, size not known at compile time
1227 -------------------------------------
1228 -- Static_Discriminated_Components --
1229 -------------------------------------
1231 function Static_Discriminated_Components
1232 (T
: Entity_Id
) return Boolean
1234 Constraint
: Elmt_Id
;
1237 if Has_Discriminants
(T
)
1238 and then Present
(Discriminant_Constraint
(T
))
1239 and then Present
(First_Component
(T
))
1241 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1242 while Present
(Constraint
) loop
1243 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1247 Next_Elmt
(Constraint
);
1252 end Static_Discriminated_Components
;
1254 -- Start of processing for Check_Compile_Time_Size
1257 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1258 end Check_Compile_Time_Size
;
1260 -----------------------------------
1261 -- Check_Component_Storage_Order --
1262 -----------------------------------
1264 procedure Check_Component_Storage_Order
1265 (Encl_Type
: Entity_Id
;
1268 Comp_ADC_Present
: out Boolean)
1270 Comp_Base
: Entity_Id
;
1272 Encl_Base
: Entity_Id
;
1275 Component_Aliased
: Boolean;
1277 Comp_Byte_Aligned
: Boolean := False;
1278 -- Set for the record case, True if Comp is aligned on byte boundaries
1279 -- (in which case it is allowed to have different storage order).
1281 Comp_SSO_Differs
: Boolean;
1282 -- Set True when the component is a nested composite, and it does not
1283 -- have the same scalar storage order as Encl_Type.
1288 if Present
(Comp
) then
1290 Comp_Base
:= Etype
(Comp
);
1292 if Is_Tag
(Comp
) then
1293 Comp_Byte_Aligned
:= True;
1294 Component_Aliased
:= False;
1297 -- If a component clause is present, check if the component starts
1298 -- and ends on byte boundaries. Otherwise conservatively assume it
1299 -- does so only in the case where the record is not packed.
1301 if Present
(Component_Clause
(Comp
)) then
1302 Comp_Byte_Aligned
:=
1303 Known_Normalized_First_Bit
(Comp
)
1307 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0
1309 Esize
(Comp
) mod System_Storage_Unit
= 0;
1311 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1314 Component_Aliased
:= Is_Aliased
(Comp
);
1320 Err_Node
:= Encl_Type
;
1321 Comp_Base
:= Component_Type
(Encl_Type
);
1323 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1326 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1327 -- the attribute definition clause is attached to the first subtype.
1328 -- Also, if the base type is incomplete or private, go to full view
1331 Encl_Base
:= Base_Type
(Encl_Type
);
1332 if Present
(Underlying_Type
(Encl_Base
)) then
1333 Encl_Base
:= Underlying_Type
(Encl_Base
);
1336 Comp_Base
:= Base_Type
(Comp_Base
);
1337 if Present
(Underlying_Type
(Comp_Base
)) then
1338 Comp_Base
:= Underlying_Type
(Comp_Base
);
1342 Get_Attribute_Definition_Clause
1343 (First_Subtype
(Comp_Base
), Attribute_Scalar_Storage_Order
);
1344 Comp_ADC_Present
:= Present
(Comp_ADC
);
1346 -- Case of record or array component: check storage order compatibility.
1347 -- But, if the record has Complex_Representation, then it is treated as
1348 -- a scalar in the back end so the storage order is irrelevant.
1350 if (Is_Record_Type
(Comp_Base
)
1351 and then not Has_Complex_Representation
(Comp_Base
))
1352 or else Is_Array_Type
(Comp_Base
)
1355 Reverse_Storage_Order
(Encl_Base
) /=
1356 Reverse_Storage_Order
(Comp_Base
);
1358 -- Parent and extension must have same storage order
1360 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1361 if Comp_SSO_Differs
then
1363 ("record extension must have same scalar storage order as "
1364 & "parent", Err_Node
);
1367 -- If component and composite SSO differs, check that component
1368 -- falls on byte boundaries and isn't bit packed.
1370 elsif Comp_SSO_Differs
then
1372 -- Component SSO differs from enclosing composite:
1374 -- Reject if composite is a bit-packed array, as it is rewritten
1375 -- into an array of scalars.
1377 if Is_Bit_Packed_Array
(Encl_Base
) then
1379 ("type of packed array must have same scalar storage order "
1380 & "as component", Err_Node
);
1382 -- Reject if not byte aligned
1384 elsif Is_Record_Type
(Encl_Base
)
1385 and then not Comp_Byte_Aligned
1387 if Present
(Component_Clause
(Comp
)) then
1389 ("type of non-byte-aligned component must have same scalar"
1390 & " storage order as enclosing record", Err_Node
);
1393 ("type of packed component must have same scalar"
1394 & " storage order as enclosing record", Err_Node
);
1397 -- Warn if specified only for the outer composite
1399 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1401 ("scalar storage order specified for & does not apply to "
1402 & "component?", Err_Node
, Encl_Base
);
1406 -- Enclosing type has explicit SSO: non-composite component must not
1409 elsif Present
(ADC
) and then Component_Aliased
then
1411 ("aliased component not permitted for type with explicit "
1412 & "Scalar_Storage_Order", Err_Node
);
1414 end Check_Component_Storage_Order
;
1416 -----------------------------
1417 -- Check_Debug_Info_Needed --
1418 -----------------------------
1420 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1422 if Debug_Info_Off
(T
) then
1425 elsif Comes_From_Source
(T
)
1426 or else Debug_Generated_Code
1427 or else Debug_Flag_VV
1428 or else Needs_Debug_Info
(T
)
1430 Set_Debug_Info_Needed
(T
);
1432 end Check_Debug_Info_Needed
;
1434 -------------------------------
1435 -- Check_Expression_Function --
1436 -------------------------------
1438 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1439 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1440 -- Function to search for deferred constant
1446 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1448 -- When a constant is initialized with the result of a dispatching
1449 -- call, the constant declaration is rewritten as a renaming of the
1450 -- displaced function result. This scenario is not a premature use of
1451 -- a constant even though the Has_Completion flag is not set.
1453 if Is_Entity_Name
(Nod
)
1454 and then Present
(Entity
(Nod
))
1455 and then Ekind
(Entity
(Nod
)) = E_Constant
1456 and then Scope
(Entity
(Nod
)) = Current_Scope
1457 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1458 N_Object_Declaration
1459 and then not Is_Imported
(Entity
(Nod
))
1460 and then not Has_Completion
(Entity
(Nod
))
1461 and then not (Present
(Full_View
(Entity
(Nod
)))
1462 and then Has_Completion
(Full_View
(Entity
(Nod
))))
1465 ("premature use of& in call or instance", N
, Entity
(Nod
));
1467 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1468 Analyze
(Prefix
(Nod
));
1470 if Is_Entity_Name
(Prefix
(Nod
))
1471 and then Is_Type
(Entity
(Prefix
(Nod
)))
1473 if Expander_Active
then
1474 Check_Fully_Declared
(Entity
(Prefix
(Nod
)), N
);
1477 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1484 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1490 -- Start of processing for Check_Expression_Function
1493 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1495 -- The subprogram body created for the expression function is not
1496 -- itself a freeze point.
1498 if Scope
(Nam
) = Current_Scope
1499 and then Nkind
(Decl
) = N_Expression_Function
1500 and then Nkind
(N
) /= N_Subprogram_Body
1502 Check_Deferred
(Expression
(Decl
));
1504 end Check_Expression_Function
;
1506 --------------------------------
1507 -- Check_Inherited_Conditions --
1508 --------------------------------
1510 procedure Check_Inherited_Conditions
1512 Late_Overriding
: Boolean := False)
1514 Prim_Ops
: constant Elist_Id
:= Primitive_Operations
(R
);
1517 Par_Prim
: Entity_Id
;
1519 Wrapper_Needed
: Boolean;
1521 function Build_DTW_Body
1524 DTW_Decls
: List_Id
;
1525 Par_Prim
: Entity_Id
;
1526 Wrapped_Subp
: Entity_Id
) return Node_Id
;
1527 -- Build the body of the dispatch table wrapper containing the given
1528 -- spec and declarations; the call to the wrapped subprogram includes
1529 -- the proper type conversion.
1531 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
;
1532 -- Build the spec of the dispatch table wrapper
1534 procedure Build_Inherited_Condition_Pragmas
1536 Wrapper_Needed
: out Boolean);
1537 -- Build corresponding pragmas for an operation whose ancestor has
1538 -- class-wide pre/postconditions. If the operation is inherited then
1539 -- Wrapper_Needed is returned True to force the creation of a wrapper
1540 -- for the inherited operation. If the ancestor is being overridden,
1541 -- the pragmas are constructed only to verify their legality, in case
1542 -- they contain calls to other primitives that may have been overridden.
1544 function Needs_Wrapper
1545 (Class_Cond
: Node_Id
;
1547 Par_Subp
: Entity_Id
) return Boolean;
1548 -- Checks whether the dispatch-table wrapper (DTW) for Subp must be
1549 -- built to evaluate the given class-wide condition.
1551 --------------------
1552 -- Build_DTW_Body --
1553 --------------------
1555 function Build_DTW_Body
1558 DTW_Decls
: List_Id
;
1559 Par_Prim
: Entity_Id
;
1560 Wrapped_Subp
: Entity_Id
) return Node_Id
1562 Par_Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Par_Prim
);
1563 Actuals
: constant List_Id
:= Empty_List
;
1565 Formal
: Entity_Id
:= First_Formal
(Par_Prim
);
1566 New_F_Spec
: Entity_Id
:= First
(Parameter_Specifications
(DTW_Spec
));
1567 New_Formal
: Entity_Id
;
1570 -- Build parameter association for call to wrapped subprogram
1572 while Present
(Formal
) loop
1573 New_Formal
:= Defining_Identifier
(New_F_Spec
);
1575 -- If the controlling argument is inherited, add conversion to
1576 -- parent type for the call.
1578 if Etype
(Formal
) = Par_Typ
1579 and then Is_Controlling_Formal
(Formal
)
1582 Make_Type_Conversion
(Loc
,
1583 New_Occurrence_Of
(Par_Typ
, Loc
),
1584 New_Occurrence_Of
(New_Formal
, Loc
)));
1586 Append_To
(Actuals
, New_Occurrence_Of
(New_Formal
, Loc
));
1589 Next_Formal
(Formal
);
1593 if Ekind
(Wrapped_Subp
) = E_Procedure
then
1595 Make_Procedure_Call_Statement
(Loc
,
1596 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1597 Parameter_Associations
=> Actuals
);
1600 Make_Simple_Return_Statement
(Loc
,
1602 Make_Function_Call
(Loc
,
1603 Name
=> New_Occurrence_Of
(Wrapped_Subp
, Loc
),
1604 Parameter_Associations
=> Actuals
));
1608 Make_Subprogram_Body
(Loc
,
1609 Specification
=> Copy_Subprogram_Spec
(DTW_Spec
),
1610 Declarations
=> DTW_Decls
,
1611 Handled_Statement_Sequence
=>
1612 Make_Handled_Sequence_Of_Statements
(Loc
,
1613 Statements
=> New_List
(Call
),
1614 End_Label
=> Make_Identifier
(Loc
,
1615 Chars
(Defining_Entity
(DTW_Spec
)))));
1618 --------------------
1619 -- Build_DTW_Spec --
1620 --------------------
1622 function Build_DTW_Spec
(Par_Prim
: Entity_Id
) return Node_Id
is
1627 DTW_Spec
:= Build_Overriding_Spec
(Par_Prim
, R
);
1628 DTW_Id
:= Defining_Entity
(DTW_Spec
);
1630 -- Clear the not-overriding indicator since the DTW wrapper overrides
1631 -- its wrapped subprogram; required because if present in the parent
1632 -- primitive, given that Build_Overriding_Spec inherits it, we report
1635 Set_Must_Not_Override
(DTW_Spec
, False);
1637 -- Add minimal decoration of fields
1639 Mutate_Ekind
(DTW_Id
, Ekind
(Par_Prim
));
1640 Set_LSP_Subprogram
(DTW_Id
, Par_Prim
);
1641 Set_Is_Dispatch_Table_Wrapper
(DTW_Id
);
1642 Set_Is_Wrapper
(DTW_Id
);
1644 -- The DTW wrapper is never a null procedure
1646 if Nkind
(DTW_Spec
) = N_Procedure_Specification
then
1647 Set_Null_Present
(DTW_Spec
, False);
1653 ---------------------------------------
1654 -- Build_Inherited_Condition_Pragmas --
1655 ---------------------------------------
1657 procedure Build_Inherited_Condition_Pragmas
1659 Wrapper_Needed
: out Boolean)
1661 Class_Pre
: constant Node_Id
:=
1662 Class_Preconditions
(Ultimate_Alias
(Subp
));
1663 Class_Post
: Node_Id
:= Class_Postconditions
(Par_Prim
);
1668 Wrapper_Needed
:= False;
1670 if No
(Class_Pre
) and then No
(Class_Post
) then
1674 -- For class-wide preconditions we just evaluate whether the wrapper
1675 -- is needed; there is no need to build the pragma since the check
1676 -- is performed on the caller side.
1678 if Present
(Class_Pre
)
1679 and then Needs_Wrapper
(Class_Pre
, Subp
, Par_Prim
)
1681 Wrapper_Needed
:= True;
1684 -- For class-wide postconditions we evaluate whether the wrapper is
1685 -- needed and we build the class-wide postcondition pragma to install
1686 -- it in the wrapper.
1688 if Present
(Class_Post
)
1689 and then Needs_Wrapper
(Class_Post
, Subp
, Par_Prim
)
1691 Wrapper_Needed
:= True;
1693 -- Update the class-wide postcondition
1695 Class_Post
:= New_Copy_Tree
(Class_Post
);
1696 Build_Class_Wide_Expression
1697 (Pragma_Or_Expr
=> Class_Post
,
1699 Par_Subp
=> Par_Prim
,
1700 Adjust_Sloc
=> False);
1702 -- Install the updated class-wide postcondition in a copy of the
1703 -- pragma postcondition defined for the nearest ancestor.
1705 A_Post
:= Get_Class_Wide_Pragma
(Par_Prim
,
1706 Pragma_Postcondition
);
1710 Subps
: constant Subprogram_List
:=
1711 Inherited_Subprograms
(Subp
);
1713 for Index
in Subps
'Range loop
1714 A_Post
:= Get_Class_Wide_Pragma
(Subps
(Index
),
1715 Pragma_Postcondition
);
1716 exit when Present
(A_Post
);
1721 New_Prag
:= New_Copy_Tree
(A_Post
);
1723 (Expression
(First
(Pragma_Argument_Associations
(New_Prag
))),
1725 Append
(New_Prag
, Decls
);
1727 end Build_Inherited_Condition_Pragmas
;
1733 function Needs_Wrapper
1734 (Class_Cond
: Node_Id
;
1736 Par_Subp
: Entity_Id
) return Boolean
1738 Result
: Boolean := False;
1740 function Check_Entity
(N
: Node_Id
) return Traverse_Result
;
1741 -- Check calls to overridden primitives
1743 --------------------
1744 -- Replace_Entity --
1745 --------------------
1747 function Check_Entity
(N
: Node_Id
) return Traverse_Result
is
1751 if Nkind
(N
) = N_Identifier
1752 and then Present
(Entity
(N
))
1754 (Is_Formal
(Entity
(N
)) or else Is_Subprogram
(Entity
(N
)))
1756 (Nkind
(Parent
(N
)) /= N_Attribute_Reference
1757 or else Attribute_Name
(Parent
(N
)) /= Name_Class
)
1759 -- Determine whether entity has a renaming
1761 New_E
:= Get_Mapped_Entity
(Entity
(N
));
1763 -- If the entity is an overridden primitive and we are not
1764 -- in GNATprove mode, we must build a wrapper for the current
1765 -- inherited operation. If the reference is the prefix of an
1766 -- attribute such as 'Result (or others ???) there is no need
1767 -- for a wrapper: the condition is just rewritten in terms of
1768 -- the inherited subprogram.
1771 and then Comes_From_Source
(New_E
)
1772 and then Is_Subprogram
(New_E
)
1773 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
1774 and then not GNATprove_Mode
1784 procedure Check_Condition_Entities
is
1785 new Traverse_Proc
(Check_Entity
);
1787 -- Start of processing for Needs_Wrapper
1790 Update_Primitives_Mapping
(Par_Subp
, Subp
);
1792 Map_Formals
(Par_Subp
, Subp
);
1793 Check_Condition_Entities
(Class_Cond
);
1798 Ifaces_List
: Elist_Id
:= No_Elist
;
1799 Ifaces_Listed
: Boolean := False;
1800 -- Cache the list of interface operations inherited by R
1802 Wrappers_List
: Elist_Id
:= No_Elist
;
1803 -- List containing identifiers of built wrappers. Used to defer building
1804 -- and analyzing their class-wide precondition subprograms.
1806 -- Start of processing for Check_Inherited_Conditions
1809 if Late_Overriding
then
1810 Op_Node
:= First_Elmt
(Prim_Ops
);
1811 while Present
(Op_Node
) loop
1812 Prim
:= Node
(Op_Node
);
1814 -- Map the overridden primitive to the overriding one
1816 if Present
(Overridden_Operation
(Prim
))
1817 and then Comes_From_Source
(Prim
)
1819 Par_Prim
:= Overridden_Operation
(Prim
);
1820 Update_Primitives_Mapping
(Par_Prim
, Prim
);
1822 -- Force discarding previous mappings of its formals
1824 Map_Formals
(Par_Prim
, Prim
, Force_Update
=> True);
1827 Next_Elmt
(Op_Node
);
1831 -- Perform validity checks on the inherited conditions of overriding
1832 -- operations, for conformance with LSP, and apply SPARK-specific
1833 -- restrictions on inherited conditions.
1835 Op_Node
:= First_Elmt
(Prim_Ops
);
1836 while Present
(Op_Node
) loop
1837 Prim
:= Node
(Op_Node
);
1839 Par_Prim
:= Overridden_Operation
(Prim
);
1840 if Present
(Par_Prim
)
1841 and then Comes_From_Source
(Prim
)
1843 -- When the primitive is an LSP wrapper we climb to the parent
1844 -- primitive that has the inherited contract.
1846 if Is_Wrapper
(Par_Prim
)
1847 and then Present
(LSP_Subprogram
(Par_Prim
))
1849 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
1852 -- Check that overrider and overridden operations have
1853 -- the same strub mode.
1855 Check_Same_Strub_Mode
(Prim
, Par_Prim
);
1857 -- Analyze the contract items of the overridden operation, before
1858 -- they are rewritten as pragmas.
1860 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1862 -- In GNATprove mode this is where we can collect the inherited
1863 -- conditions, because we do not create the Check pragmas that
1864 -- normally convey the modified class-wide conditions on
1865 -- overriding operations.
1867 if GNATprove_Mode
then
1868 Collect_Inherited_Class_Wide_Conditions
(Prim
);
1872 -- Go over operations inherited from interfaces and check
1873 -- them for strub mode compatibility as well.
1875 if Has_Interfaces
(R
)
1876 and then Is_Dispatching_Operation
(Prim
)
1877 and then Find_Dispatching_Type
(Prim
) = R
1881 Iface_Elmt
: Elmt_Id
;
1883 Iface_Prim
: Entity_Id
;
1886 -- Collect the interfaces only once. We haven't
1887 -- finished freezing yet, so we can't use the faster
1888 -- search from Sem_Disp.Covered_Interface_Primitives.
1890 if not Ifaces_Listed
then
1891 Collect_Interfaces
(R
, Ifaces_List
);
1892 Ifaces_Listed
:= True;
1895 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1896 while Present
(Iface_Elmt
) loop
1897 Iface
:= Node
(Iface_Elmt
);
1899 Elmt
:= First_Elmt
(Primitive_Operations
(Iface
));
1900 while Present
(Elmt
) loop
1901 Iface_Prim
:= Node
(Elmt
);
1903 if Iface_Prim
/= Par_Prim
1904 and then Chars
(Iface_Prim
) = Chars
(Prim
)
1905 and then Comes_From_Source
(Iface_Prim
)
1906 and then (Is_Interface_Conformant
1907 (R
, Iface_Prim
, Prim
))
1909 Check_Same_Strub_Mode
(Prim
, Iface_Prim
);
1915 Next_Elmt
(Iface_Elmt
);
1920 Next_Elmt
(Op_Node
);
1923 -- Now examine the inherited operations to check whether they require
1924 -- a wrapper to handle inherited conditions that call other primitives,
1925 -- so that LSP can be verified/enforced.
1927 Op_Node
:= First_Elmt
(Prim_Ops
);
1929 while Present
(Op_Node
) loop
1930 Decls
:= Empty_List
;
1931 Prim
:= Node
(Op_Node
);
1932 Wrapper_Needed
:= False;
1934 -- Skip internal entities built for mapping interface primitives
1936 if not Comes_From_Source
(Prim
)
1937 and then Present
(Alias
(Prim
))
1938 and then No
(Interface_Alias
(Prim
))
1940 Par_Prim
:= Ultimate_Alias
(Prim
);
1942 -- When the primitive is an LSP wrapper we climb to the parent
1943 -- primitive that has the inherited contract.
1945 if Is_Wrapper
(Par_Prim
)
1946 and then Present
(LSP_Subprogram
(Par_Prim
))
1948 Par_Prim
:= LSP_Subprogram
(Par_Prim
);
1951 -- Analyze the contract items of the parent operation, and
1952 -- determine whether a wrapper is needed. This is determined
1953 -- when the condition is rewritten in sem_prag, using the
1954 -- mapping between overridden and overriding operations built
1955 -- in the loop above.
1957 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1958 Build_Inherited_Condition_Pragmas
(Prim
, Wrapper_Needed
);
1962 and then not Is_Abstract_Subprogram
(Par_Prim
)
1963 and then Expander_Active
1965 -- Build the dispatch-table wrapper (DTW). The support for
1966 -- AI12-0195 relies on two kind of wrappers: one for indirect
1967 -- calls (also used for AI12-0220), and one for putting in the
1970 -- 1) "indirect-call wrapper" (ICW) is needed anytime there are
1971 -- class-wide preconditions. Prim'Access will point directly
1972 -- at the ICW if any, or at the "pristine" body if Prim has
1973 -- no class-wide preconditions.
1975 -- 2) "dispatch-table wrapper" (DTW) is needed anytime the class
1976 -- wide preconditions *or* the class-wide postconditions are
1977 -- affected by overriding.
1979 -- The DTW holds a single statement that is a single call where
1980 -- the controlling actuals are conversions to the corresponding
1981 -- type in the parent primitive. If the primitive is a function
1982 -- the statement is a return statement with a call.
1985 Alias_Id
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1986 Loc
: constant Source_Ptr
:= Sloc
(R
);
1992 Prim_Next_E
: constant Entity_Id
:= Next_Entity
(Prim
);
1993 Prim_Prev_E
: constant Entity_Id
:= Prev_Entity
(Prim
);
1996 DTW_Spec
:= Build_DTW_Spec
(Par_Prim
);
1997 DTW_Id
:= Defining_Entity
(DTW_Spec
);
1998 DTW_Decl
:= Make_Subprogram_Declaration
(Loc
,
1999 Specification
=> DTW_Spec
);
2001 -- The spec of the wrapper has been built using the source
2002 -- location of its parent primitive; we must update it now
2003 -- (with the source location of the internal primitive built
2004 -- by Derive_Subprogram that will override this wrapper) to
2005 -- avoid inlining conflicts between internally built helpers
2006 -- for class-wide pre/postconditions of the parent and the
2007 -- helpers built for this wrapper.
2009 Set_Sloc
(DTW_Id
, Sloc
(Prim
));
2011 -- For inherited class-wide preconditions the DTW wrapper
2012 -- reuses the ICW of the parent (which checks the parent
2013 -- interpretation of the class-wide preconditions); the
2014 -- interpretation of the class-wide preconditions for the
2015 -- inherited subprogram is checked at the caller side.
2017 -- When the subprogram inherits class-wide postconditions
2018 -- the DTW also checks the interpretation of the class-wide
2019 -- postconditions for the inherited subprogram, and the body
2020 -- of the parent checks its interpretation of the parent for
2021 -- the class-wide postconditions.
2023 -- procedure Prim (F1 : T1; ...) is
2024 -- [ pragma Check (Postcondition, Expr); ]
2026 -- Par_Prim_ICW (Par_Type (F1), ...);
2029 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2031 Build_DTW_Body
(Loc
,
2032 DTW_Spec
=> DTW_Spec
,
2034 Par_Prim
=> Par_Prim
,
2035 Wrapped_Subp
=> Indirect_Call_Wrapper
(Par_Prim
));
2037 -- For subprograms that only inherit class-wide postconditions
2038 -- the DTW wrapper calls the parent primitive (which on its
2039 -- body checks the interpretation of the class-wide post-
2040 -- conditions for the parent subprogram), and the DTW checks
2041 -- the interpretation of the class-wide postconditions for the
2042 -- inherited subprogram.
2044 -- procedure Prim (F1 : T1; ...) is
2045 -- pragma Check (Postcondition, Expr);
2047 -- Par_Prim (Par_Type (F1), ...);
2052 Build_DTW_Body
(Loc
,
2053 DTW_Spec
=> DTW_Spec
,
2055 Par_Prim
=> Par_Prim
,
2056 Wrapped_Subp
=> Par_Prim
);
2059 -- Insert the declaration of the wrapper before the freezing
2060 -- node of the record type declaration to ensure that it will
2061 -- override the internal primitive built by Derive_Subprogram.
2063 if Late_Overriding
then
2064 Ensure_Freeze_Node
(R
);
2065 Insert_Before_And_Analyze
(Freeze_Node
(R
), DTW_Decl
);
2067 Append_Freeze_Action
(R
, DTW_Decl
);
2071 -- The analyis of DTW_Decl has removed Prim from its scope
2072 -- chain and added DTW_Id at the end of the scope chain. Move
2073 -- DTW_Id to its correct place in the scope chain: the analysis
2074 -- of the wrapper declaration has just added DTW_Id at the end
2075 -- of the list of entities of its scope. However, given that
2076 -- this wrapper overrides Prim, we must move DTW_Id to the
2077 -- original place of Prim in its scope chain. This is required
2078 -- for wrappers of private type primitives to ensure their
2079 -- correct visibility since wrappers are built when the full
2080 -- tagged type declaration is frozen (in the private part of
2081 -- the package) but they may override primitives defined in the
2082 -- public part of the package.
2085 DTW_Prev_E
: constant Entity_Id
:= Prev_Entity
(DTW_Id
);
2088 pragma Assert
(Last_Entity
(Current_Scope
) = DTW_Id
);
2090 (Ekind
(Current_Scope
) not in E_Package | E_Generic_Package
2091 or else No
(First_Private_Entity
(Current_Scope
))
2092 or else First_Private_Entity
(Current_Scope
) /= DTW_Id
);
2094 -- Remove DTW_Id from the end of the doubly-linked list of
2095 -- entities of this scope; no need to handle removing it
2096 -- from the beginning of the chain since such case can never
2097 -- occur for this entity.
2099 Set_Last_Entity
(Current_Scope
, DTW_Prev_E
);
2100 Set_Next_Entity
(DTW_Prev_E
, Empty
);
2102 -- Place DTW_Id back in the original place of its wrapped
2103 -- primitive in the list of entities of this scope.
2105 Link_Entities
(Prim_Prev_E
, DTW_Id
);
2106 Link_Entities
(DTW_Id
, Prim_Next_E
);
2109 -- Insert the body of the wrapper in the freeze actions of
2110 -- its record type declaration to ensure that it is placed
2111 -- in the scope of its declaration but not too early to cause
2112 -- premature freezing of other entities.
2114 Append_Freeze_Action
(R
, DTW_Body
);
2117 -- Ensure correct decoration
2119 pragma Assert
(Is_Dispatching_Operation
(DTW_Id
));
2120 pragma Assert
(Present
(Overridden_Operation
(DTW_Id
)));
2121 pragma Assert
(Overridden_Operation
(DTW_Id
) = Alias_Id
);
2123 -- Inherit dispatch table slot
2125 Set_DTC_Entity_Value
(R
, DTW_Id
);
2126 Set_DT_Position
(DTW_Id
, DT_Position
(Alias_Id
));
2128 -- Register the wrapper in the dispatch table
2131 and then not Building_Static_DT
(R
)
2133 Insert_List_After_And_Analyze
(Freeze_Node
(R
),
2134 Register_Primitive
(Loc
, DTW_Id
));
2137 -- Defer building helpers and ICW for the DTW. Required to
2138 -- ensure uniqueness in their names because when building
2139 -- these wrappers for overlapped subprograms their homonym
2140 -- number is not definite until all these dispatch table
2141 -- wrappers of tagged type R have been analyzed.
2143 if Present
(Indirect_Call_Wrapper
(Par_Prim
)) then
2144 Append_New_Elmt
(DTW_Id
, Wrappers_List
);
2149 Next_Elmt
(Op_Node
);
2152 -- Build and analyze deferred class-wide precondition subprograms of
2155 if Present
(Wrappers_List
) then
2158 CW_Subp
: Entity_Id
;
2164 Elmt
:= First_Elmt
(Wrappers_List
);
2166 while Present
(Elmt
) loop
2167 DTW_Id
:= Node
(Elmt
);
2170 Merge_Class_Conditions
(DTW_Id
);
2171 Make_Class_Precondition_Subps
(DTW_Id
, Late_Overriding
);
2173 CW_Subp
:= Static_Call_Helper
(DTW_Id
);
2174 Decl_N
:= Unit_Declaration_Node
(CW_Subp
);
2177 -- If the DTW was built for a late-overriding primitive
2178 -- its body must be analyzed now (since the tagged type
2179 -- is already frozen).
2181 if Late_Overriding
then
2183 Unit_Declaration_Node
(Corresponding_Body
(Decl_N
));
2189 end Check_Inherited_Conditions
;
2191 ----------------------------
2192 -- Check_Strict_Alignment --
2193 ----------------------------
2195 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
2199 -- Bit-packed array types do not require strict alignment, even if they
2200 -- are by-reference types, because they are accessed in a special way.
2202 if Is_By_Reference_Type
(E
) and then not Is_Bit_Packed_Array
(E
) then
2203 Set_Strict_Alignment
(E
);
2205 elsif Is_Array_Type
(E
) then
2206 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
2208 -- ??? AI12-001: Any component of a packed type that contains an
2209 -- aliased part must be aligned according to the alignment of its
2210 -- subtype (RM 13.2(7)). This means that the following test:
2212 -- if Has_Aliased_Components (E) then
2213 -- Set_Strict_Alignment (E);
2216 -- should be implemented here. Unfortunately it would break Florist,
2217 -- which has the bad habit of overaligning all the types it declares
2218 -- on 32-bit platforms. Other legacy codebases could also be affected
2219 -- because this check has historically been missing in GNAT.
2221 elsif Is_Record_Type
(E
) then
2222 Comp
:= First_Component
(E
);
2223 while Present
(Comp
) loop
2224 if not Is_Type
(Comp
)
2225 and then (Is_Aliased
(Comp
)
2226 or else Strict_Alignment
(Etype
(Comp
)))
2228 Set_Strict_Alignment
(E
);
2232 Next_Component
(Comp
);
2235 end Check_Strict_Alignment
;
2237 -------------------------
2238 -- Check_Unsigned_Type --
2239 -------------------------
2241 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
2242 Ancestor
: Entity_Id
;
2247 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
2251 -- Do not attempt to analyze case where range was in error
2253 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
2257 -- The situation that is nontrivial is something like:
2259 -- subtype x1 is integer range -10 .. +10;
2260 -- subtype x2 is x1 range 0 .. V1;
2261 -- subtype x3 is x2 range V2 .. V3;
2262 -- subtype x4 is x3 range V4 .. V5;
2264 -- where Vn are variables. Here the base type is signed, but we still
2265 -- know that x4 is unsigned because of the lower bound of x2.
2267 -- The only way to deal with this is to look up the ancestor chain
2271 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
2275 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
2277 if Compile_Time_Known_Value
(Lo_Bound
) then
2278 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
2279 Set_Is_Unsigned_Type
(E
, True);
2285 Ancestor
:= Ancestor_Subtype
(Ancestor
);
2287 -- If no ancestor had a static lower bound, go to base type
2289 if No
(Ancestor
) then
2291 -- Note: the reason we still check for a compile time known
2292 -- value for the base type is that at least in the case of
2293 -- generic formals, we can have bounds that fail this test,
2294 -- and there may be other cases in error situations.
2296 Btyp
:= Base_Type
(E
);
2298 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
2302 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
2304 if Compile_Time_Known_Value
(Lo_Bound
)
2305 and then Expr_Rep_Value
(Lo_Bound
) >= 0
2307 Set_Is_Unsigned_Type
(E
, True);
2314 end Check_Unsigned_Type
;
2316 -----------------------------------------------
2317 -- Explode_Initialization_Compound_Statement --
2318 -----------------------------------------------
2320 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
2321 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
2324 if Present
(Init_Stmts
)
2325 and then Nkind
(Init_Stmts
) = N_Compound_Statement
2327 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
2329 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
2330 -- just removing it, because Freeze_All may rely on this particular
2331 -- Node_Id still being present in the enclosing list to know where to
2334 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
2336 Set_Initialization_Statements
(E
, Empty
);
2338 end Explode_Initialization_Compound_Statement
;
2344 -- Note: the easy coding for this procedure would be to just build a
2345 -- single list of freeze nodes and then insert them and analyze them
2346 -- all at once. This won't work, because the analysis of earlier freeze
2347 -- nodes may recursively freeze types which would otherwise appear later
2348 -- on in the freeze list. So we must analyze and expand the freeze nodes
2349 -- as they are generated.
2351 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
2352 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
2353 -- This is the internal recursive routine that does freezing of entities
2354 -- (but NOT the analysis of default expressions, which should not be
2355 -- recursive, we don't want to analyze those till we are sure that ALL
2356 -- the types are frozen).
2358 --------------------
2359 -- Freeze_All_Ent --
2360 --------------------
2362 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
2366 procedure Process_Flist
;
2367 -- If freeze nodes are present, insert and analyze, and reset cursor
2368 -- for next insertion.
2374 procedure Process_Flist
is
2377 if Is_Non_Empty_List
(Flist
) then
2378 Lastn
:= Next
(After
);
2379 Insert_List_After_And_Analyze
(After
, Flist
);
2381 if Present
(Lastn
) then
2382 After
:= Prev
(Lastn
);
2384 After
:= Last
(List_Containing
(After
));
2389 -- Start of processing for Freeze_All_Ent
2393 while Present
(E
) loop
2395 -- If the entity is an inner package which is not a package
2396 -- renaming, then its entities must be frozen at this point. Note
2397 -- that such entities do NOT get frozen at the end of the nested
2398 -- package itself (only library packages freeze).
2400 -- Same is true for task declarations, where anonymous records
2401 -- created for entry parameters must be frozen.
2403 if Ekind
(E
) = E_Package
2404 and then No
(Renamed_Entity
(E
))
2405 and then not Is_Child_Unit
(E
)
2406 and then not Is_Frozen
(E
)
2410 Install_Visible_Declarations
(E
);
2411 Install_Private_Declarations
(E
);
2412 Freeze_All
(First_Entity
(E
), After
);
2414 End_Package_Scope
(E
);
2416 if Is_Generic_Instance
(E
)
2417 and then Has_Delayed_Freeze
(E
)
2419 Set_Has_Delayed_Freeze
(E
, False);
2420 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
2423 elsif Ekind
(E
) in Task_Kind
2424 and then Nkind
(Parent
(E
)) in
2425 N_Single_Task_Declaration | N_Task_Type_Declaration
2428 Freeze_All
(First_Entity
(E
), After
);
2431 -- For a derived tagged type, we must ensure that all the
2432 -- primitive operations of the parent have been frozen, so that
2433 -- their addresses will be in the parent's dispatch table at the
2434 -- point it is inherited.
2436 elsif Ekind
(E
) = E_Record_Type
2437 and then Is_Tagged_Type
(E
)
2438 and then Is_Tagged_Type
(Etype
(E
))
2439 and then Is_Derived_Type
(E
)
2442 Prim_List
: constant Elist_Id
:=
2443 Primitive_Operations
(Etype
(E
));
2449 Prim
:= First_Elmt
(Prim_List
);
2450 while Present
(Prim
) loop
2451 Subp
:= Node
(Prim
);
2453 if Comes_From_Source
(Subp
)
2454 and then not Is_Frozen
(Subp
)
2456 Flist
:= Freeze_Entity
(Subp
, After
);
2465 if not Is_Frozen
(E
) then
2466 Flist
:= Freeze_Entity
(E
, After
);
2469 -- If already frozen, and there are delayed aspects, this is where
2470 -- we do the visibility check for these aspects (see Sem_Ch13 spec
2471 -- for a description of how we handle aspect visibility).
2473 elsif Has_Delayed_Aspects
(E
) then
2478 Ritem
:= First_Rep_Item
(E
);
2479 while Present
(Ritem
) loop
2480 if Nkind
(Ritem
) = N_Aspect_Specification
2481 and then Entity
(Ritem
) = E
2482 and then Is_Delayed_Aspect
(Ritem
)
2484 Check_Aspect_At_End_Of_Declarations
(Ritem
);
2487 Next_Rep_Item
(Ritem
);
2492 -- If an incomplete type is still not frozen, this may be a
2493 -- premature freezing because of a body declaration that follows.
2494 -- Indicate where the freezing took place. Freezing will happen
2495 -- if the body comes from source, but not if it is internally
2496 -- generated, for example as the body of a type invariant.
2498 -- If the freezing is caused by the end of the current declarative
2499 -- part, it is a Taft Amendment type, and there is no error.
2501 if not Is_Frozen
(E
)
2502 and then Ekind
(E
) = E_Incomplete_Type
2505 Bod
: constant Node_Id
:= Next
(After
);
2508 -- The presence of a body freezes all entities previously
2509 -- declared in the current list of declarations, but this
2510 -- does not apply if the body does not come from source.
2511 -- A type invariant is transformed into a subprogram body
2512 -- which is placed at the end of the private part of the
2513 -- current package, but this body does not freeze incomplete
2514 -- types that may be declared in this private part.
2516 if Comes_From_Source
(Bod
)
2517 and then Nkind
(Bod
) in N_Entry_Body
2524 In_Same_List
(After
, Parent
(E
))
2526 Error_Msg_Sloc
:= Sloc
(Next
(After
));
2528 ("type& is frozen# before its full declaration",
2544 -- Start of processing for Freeze_All
2547 Freeze_All_Ent
(From
, After
);
2549 -- Now that all types are frozen, we can deal with default expressions
2550 -- that require us to build a default expression functions. This is the
2551 -- point at which such functions are constructed (after all types that
2552 -- might be used in such expressions have been frozen).
2554 -- For subprograms that are renaming_as_body, we create the wrapper
2555 -- bodies as needed.
2557 -- We also add finalization chains to access types whose designated
2558 -- types are controlled. This is normally done when freezing the type,
2559 -- but this misses recursive type definitions where the later members
2560 -- of the recursion introduce controlled components.
2562 -- Loop through entities
2565 while Present
(E
) loop
2566 if Is_Subprogram
(E
) then
2567 if not Default_Expressions_Processed
(E
) then
2568 Process_Default_Expressions
(E
, After
);
2571 -- Check subprogram renamings for the same strub-mode.
2572 -- Avoid rechecking dispatching operations, that's taken
2573 -- care of in Check_Inherited_Conditions, that covers
2574 -- inherited interface operations.
2578 and then not Is_Dispatching_Operation
(E
)
2580 Check_Same_Strub_Mode
(E
, Item
);
2583 if not Has_Completion
(E
) then
2584 Decl
:= Unit_Declaration_Node
(E
);
2586 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
2587 if Error_Posted
(Decl
) then
2588 Set_Has_Completion
(E
);
2590 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
2593 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2594 and then Present
(Corresponding_Body
(Decl
))
2596 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
2597 N_Subprogram_Renaming_Declaration
2599 Build_And_Analyze_Renamed_Body
2600 (Decl
, Corresponding_Body
(Decl
), After
);
2604 -- Freeze the default expressions of entries, entry families, and
2605 -- protected subprograms.
2607 elsif Is_Concurrent_Type
(E
) then
2608 Item
:= First_Entity
(E
);
2609 while Present
(Item
) loop
2610 if Is_Subprogram_Or_Entry
(Item
)
2611 and then not Default_Expressions_Processed
(Item
)
2613 Process_Default_Expressions
(Item
, After
);
2620 -- Historical note: We used to create a finalization master for an
2621 -- access type whose designated type is not controlled, but contains
2622 -- private controlled compoments. This form of postprocessing is no
2623 -- longer needed because the finalization master is now created when
2624 -- the access type is frozen (see Exp_Ch3.Freeze_Type).
2630 -----------------------
2631 -- Freeze_And_Append --
2632 -----------------------
2634 procedure Freeze_And_Append
2637 Result
: in out List_Id
)
2639 -- Freezing an Expression_Function does not freeze its profile:
2640 -- the formals will have been frozen otherwise before the E_F
2643 L
: constant List_Id
:=
2645 (Ent
, N
, Do_Freeze_Profile
=> not Is_Expression_Function
(Ent
));
2647 if Is_Non_Empty_List
(L
) then
2648 if Result
= No_List
then
2651 Append_List
(L
, Result
);
2654 end Freeze_And_Append
;
2660 procedure Freeze_Before
2663 Do_Freeze_Profile
: Boolean := True)
2665 -- Freeze T, then insert the generated Freeze nodes before the node N.
2666 -- Flag Freeze_Profile is used when T is an overloadable entity, and
2667 -- indicates whether its profile should be frozen at the same time.
2669 Freeze_Nodes
: constant List_Id
:=
2670 Freeze_Entity
(T
, N
, Do_Freeze_Profile
);
2671 Pack
: constant Entity_Id
:= Scope
(T
);
2674 if Ekind
(T
) = E_Function
then
2675 Check_Expression_Function
(N
, T
);
2678 if Is_Non_Empty_List
(Freeze_Nodes
) then
2680 -- If the entity is a type declared in an inner package, it may be
2681 -- frozen by an outer declaration before the package itself is
2682 -- frozen. Install the package scope to analyze the freeze nodes,
2683 -- which may include generated subprograms such as predicate
2686 if Is_Type
(T
) and then From_Nested_Package
(T
) then
2688 Install_Visible_Declarations
(Pack
);
2689 Install_Private_Declarations
(Pack
);
2690 Insert_Actions
(N
, Freeze_Nodes
);
2691 End_Package_Scope
(Pack
);
2694 Insert_Actions
(N
, Freeze_Nodes
);
2703 -- WARNING: This routine manages Ghost regions. Return statements must be
2704 -- replaced by gotos which jump to the end of the routine and restore the
2707 function Freeze_Entity
2710 Do_Freeze_Profile
: Boolean := True) return List_Id
2712 Loc
: constant Source_Ptr
:= Sloc
(N
);
2714 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2715 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
2716 -- Save the Ghost-related attributes to restore on exit
2724 Result
: List_Id
:= No_List
;
2725 -- List of freezing actions, left at No_List if none
2727 Test_E
: Entity_Id
:= E
;
2728 -- A local temporary used to test if freezing is necessary for E, since
2729 -- its value can be set to something other than E in certain cases. For
2730 -- example, E cannot be used directly in cases such as when it is an
2731 -- Itype defined within a record - since it is the location of record
2734 procedure Add_To_Result
(Fnod
: Node_Id
);
2735 -- Add freeze action Fnod to list Result
2737 function After_Last_Declaration
return Boolean;
2738 -- If Loc is a freeze_entity that appears after the last declaration
2739 -- in the scope, inhibit error messages on late completion.
2741 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
2742 -- Check that an Access or Unchecked_Access attribute with a prefix
2743 -- which is the current instance type can only be applied when the type
2746 procedure Check_No_Parts_Violations
2747 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
) with
2748 Pre
=> Aspect_No_Parts
in
2749 Aspect_No_Controlled_Parts | Aspect_No_Task_Parts
;
2750 -- Check that Typ does not violate the semantics of the specified
2751 -- Aspect_No_Parts (No_Controlled_Parts or No_Task_Parts) when it is
2752 -- specified on Typ or one of its ancestors.
2754 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
);
2755 -- Give a warning for pragma Convention with language C or C++ applied
2756 -- to a discriminated record type. This is suppressed for the unchecked
2757 -- union case, since the whole point in this case is interface C. We
2758 -- also do not generate this within instantiations, since we will have
2759 -- generated a message on the template.
2761 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
2762 -- Give warning for modulus of 8, 16, 32, 64 or 128 given as an explicit
2763 -- integer literal without an explicit corresponding size clause. The
2764 -- caller has checked that Utype is a modular integer type.
2766 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
2767 -- Freeze array type, including freezing index and component types
2769 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
2770 -- Perform checks and generate freeze node if needed for a constant or
2771 -- variable declared by an object declaration.
2773 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
2774 -- Create Freeze_Generic_Entity nodes for types declared in a generic
2775 -- package. Recurse on inner generic packages.
2777 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
2778 -- Freeze formals and return type of subprogram. If some type in the
2779 -- profile is incomplete and we are in an instance, freezing of the
2780 -- entity will take place elsewhere, and the function returns False.
2782 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
2783 -- Freeze record type, including freezing component types, and freezing
2784 -- primitive operations if this is a tagged type.
2786 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
2787 -- Determine whether an arbitrary entity is subject to Boolean aspect
2788 -- Import and its value is specified as True.
2790 procedure Inherit_Freeze_Node
2793 -- Set type Typ's freeze node to refer to Fnode. This routine ensures
2794 -- that any attributes attached to Typ's original node are preserved.
2796 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
2797 -- If E is an entity for an imported subprogram with pre/post-conditions
2798 -- then this procedure will create a wrapper to ensure that proper run-
2799 -- time checking of the pre/postconditions. See body for details.
2805 procedure Add_To_Result
(Fnod
: Node_Id
) is
2807 Append_New_To
(Result
, Fnod
);
2810 ----------------------------
2811 -- After_Last_Declaration --
2812 ----------------------------
2814 function After_Last_Declaration
return Boolean is
2815 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2818 if Nkind
(Spec
) = N_Package_Specification
then
2819 if Present
(Private_Declarations
(Spec
)) then
2820 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2821 elsif Present
(Visible_Declarations
(Spec
)) then
2822 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2830 end After_Last_Declaration
;
2832 ----------------------------
2833 -- Check_Current_Instance --
2834 ----------------------------
2836 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2838 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2839 -- Determine whether Typ is compatible with the rules for aliased
2840 -- views of types as defined in RM 3.10 in the various dialects.
2842 function Process
(N
: Node_Id
) return Traverse_Result
;
2843 -- Process routine to apply check to given node
2845 -----------------------------
2846 -- Is_Aliased_View_Of_Type --
2847 -----------------------------
2849 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
2850 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
2855 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
2856 and then Limited_Present
(Type_Definition
(Typ_Decl
))
2860 -- The following paragraphs describe what a legal aliased view of
2861 -- a type is in the various dialects of Ada.
2865 -- The current instance of a limited type, and a formal parameter
2866 -- or generic formal object of a tagged type.
2868 -- Ada 95 limited type
2869 -- * Type with reserved word "limited"
2870 -- * A protected or task type
2871 -- * A composite type with limited component
2873 elsif Ada_Version
<= Ada_95
then
2874 return Is_Limited_Type
(Typ
);
2878 -- The current instance of a limited tagged type, a protected
2879 -- type, a task type, or a type that has the reserved word
2880 -- "limited" in its full definition ... a formal parameter or
2881 -- generic formal object of a tagged type.
2883 -- Ada 2005 limited type
2884 -- * Type with reserved word "limited", "synchronized", "task"
2886 -- * A composite type with limited component
2887 -- * A derived type whose parent is a non-interface limited type
2889 elsif Ada_Version
= Ada_2005
then
2891 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2893 (Is_Derived_Type
(Typ
)
2894 and then not Is_Interface
(Etype
(Typ
))
2895 and then Is_Limited_Type
(Etype
(Typ
)));
2897 -- Ada 2012 and beyond
2899 -- The current instance of an immutably limited type ... a formal
2900 -- parameter or generic formal object of a tagged type.
2902 -- Ada 2012 limited type
2903 -- * Type with reserved word "limited", "synchronized", "task"
2905 -- * A composite type with limited component
2906 -- * A derived type whose parent is a non-interface limited type
2907 -- * An incomplete view
2909 -- Ada 2012 immutably limited type
2910 -- * Explicitly limited record type
2911 -- * Record extension with "limited" present
2912 -- * Non-formal limited private type that is either tagged
2913 -- or has at least one access discriminant with a default
2915 -- * Task type, protected type or synchronized interface
2916 -- * Type derived from immutably limited type
2920 Is_Immutably_Limited_Type
(Typ
)
2921 or else Is_Incomplete_Type
(Typ
);
2923 end Is_Aliased_View_Of_Type
;
2929 function Process
(N
: Node_Id
) return Traverse_Result
is
2932 when N_Attribute_Reference
=>
2933 if Attribute_Name
(N
) in Name_Access | Name_Unchecked_Access
2934 and then Is_Entity_Name
(Prefix
(N
))
2935 and then Is_Type
(Entity
(Prefix
(N
)))
2936 and then Entity
(Prefix
(N
)) = E
2938 if Ada_Version
< Ada_2012
then
2940 ("current instance must be a limited type",
2944 ("current instance must be an immutably limited "
2945 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2959 procedure Traverse
is new Traverse_Proc
(Process
);
2963 Rec_Type
: constant Entity_Id
:=
2964 Scope
(Defining_Identifier
(Comp_Decl
));
2966 -- Start of processing for Check_Current_Instance
2969 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2970 Traverse
(Comp_Decl
);
2972 end Check_Current_Instance
;
2974 -------------------------------
2975 -- Check_No_Parts_Violations --
2976 -------------------------------
2978 procedure Check_No_Parts_Violations
2979 (Typ
: Entity_Id
; Aspect_No_Parts
: Aspect_Id
)
2982 function Find_Aspect_No_Parts
2983 (Typ
: Entity_Id
) return Node_Id
;
2984 -- Search for Aspect_No_Parts on a given type. When
2985 -- the aspect is not explicity specified Empty is returned.
2987 function Get_Aspect_No_Parts_Value
2988 (Typ
: Entity_Id
) return Entity_Id
;
2989 -- Obtain the value for the Aspect_No_Parts on a given
2990 -- type. When the aspect is not explicitly specified Empty is
2993 function Has_Aspect_No_Parts
2994 (Typ
: Entity_Id
) return Boolean;
2995 -- Predicate function which identifies whether No_Parts
2996 -- is explicitly specified on a given type.
2998 -------------------------------------
2999 -- Find_Aspect_No_Parts --
3000 -------------------------------------
3002 function Find_Aspect_No_Parts
3003 (Typ
: Entity_Id
) return Node_Id
3005 Partial_View
: constant Entity_Id
:=
3006 Incomplete_Or_Partial_View
(Typ
);
3008 Aspect_Spec
: Entity_Id
:=
3009 Find_Aspect
(Typ
, Aspect_No_Parts
);
3010 Curr_Aspect_Spec
: Entity_Id
;
3013 -- Examine Typ's associated node, when present, since aspect
3014 -- specifications do not get transferred when nodes get rewritten.
3016 -- For example, this can happen in the expansion of array types
3019 and then Present
(Associated_Node_For_Itype
(Typ
))
3020 and then Nkind
(Associated_Node_For_Itype
(Typ
))
3021 = N_Full_Type_Declaration
3025 (Id
=> Defining_Identifier
3026 (Associated_Node_For_Itype
(Typ
)),
3027 A
=> Aspect_No_Parts
);
3030 -- Examine aspects specifications on private type declarations
3032 -- Should Find_Aspect be improved to handle this case ???
3035 and then Present
(Partial_View
)
3037 (Aspect_Specifications
3043 (Aspect_Specifications
3047 -- Search through aspects present on the private type
3049 while Present
(Curr_Aspect_Spec
) loop
3050 if Get_Aspect_Id
(Curr_Aspect_Spec
)
3053 Aspect_Spec
:= Curr_Aspect_Spec
;
3057 Next
(Curr_Aspect_Spec
);
3062 -- When errors are posted on the aspect return Empty
3064 if Error_Posted
(Aspect_Spec
) then
3069 end Find_Aspect_No_Parts
;
3071 ------------------------------------------
3072 -- Get_Aspect_No_Parts_Value --
3073 ------------------------------------------
3075 function Get_Aspect_No_Parts_Value
3076 (Typ
: Entity_Id
) return Entity_Id
3078 Aspect_Spec
: constant Entity_Id
:=
3079 Find_Aspect_No_Parts
(Typ
);
3082 -- Return the value of the aspect when present
3084 if Present
(Aspect_Spec
) then
3086 -- No expression is the same as True
3088 if No
(Expression
(Aspect_Spec
)) then
3089 return Standard_True
;
3092 -- Assume its expression has already been constant folded into
3093 -- a Boolean value and return its value.
3095 return Entity
(Expression
(Aspect_Spec
));
3098 -- Otherwise, the aspect is not specified - so return Empty
3101 end Get_Aspect_No_Parts_Value
;
3103 ------------------------------------
3104 -- Has_Aspect_No_Parts --
3105 ------------------------------------
3107 function Has_Aspect_No_Parts
3108 (Typ
: Entity_Id
) return Boolean
3109 is (Present
(Find_Aspect_No_Parts
(Typ
)));
3111 -- Generic instances
3113 -------------------------------------------
3114 -- Get_Generic_Formal_Types_In_Hierarchy --
3115 -------------------------------------------
3117 function Get_Generic_Formal_Types_In_Hierarchy
3118 is new Collect_Types_In_Hierarchy
(Predicate
=> Is_Generic_Formal
);
3119 -- Return a list of all types within a given type's hierarchy which
3120 -- are generic formals.
3122 ----------------------------------------
3123 -- Get_Types_With_Aspect_In_Hierarchy --
3124 ----------------------------------------
3126 function Get_Types_With_Aspect_In_Hierarchy
3127 is new Collect_Types_In_Hierarchy
3128 (Predicate
=> Has_Aspect_No_Parts
);
3129 -- Returns a list of all types within a given type's hierarchy which
3130 -- have the Aspect_No_Parts specified.
3132 -- Local declarations
3134 Aspect_Value
: Entity_Id
;
3135 Curr_Value
: Entity_Id
;
3136 Curr_Typ_Elmt
: Elmt_Id
;
3137 Curr_Body_Elmt
: Elmt_Id
;
3138 Curr_Formal_Elmt
: Elmt_Id
;
3139 Gen_Bodies
: Elist_Id
;
3140 Gen_Formals
: Elist_Id
;
3142 Types_With_Aspect
: Elist_Id
;
3144 -- Start of processing for Check_No_Parts_Violations
3147 -- Nothing to check if the type is elementary or artificial
3149 if Is_Elementary_Type
(Typ
) or else not Comes_From_Source
(Typ
) then
3153 Types_With_Aspect
:= Get_Types_With_Aspect_In_Hierarchy
(Typ
);
3155 -- Nothing to check if there are no types with No_Parts specified
3157 if Is_Empty_Elmt_List
(Types_With_Aspect
) then
3161 -- Set name for all errors below
3163 Error_Msg_Name_1
:= Aspect_Names
(Aspect_No_Parts
);
3165 -- Obtain the aspect value for No_Parts for comparison
3168 Get_Aspect_No_Parts_Value
3169 (Node
(First_Elmt
(Types_With_Aspect
)));
3171 -- When the value is True and there are controlled/task parts or the
3172 -- type itself is controlled/task, trigger the appropriate error.
3174 if Aspect_Value
= Standard_True
then
3175 if Aspect_No_Parts
= Aspect_No_Controlled_Parts
then
3176 if Is_Controlled
(Typ
) or else Has_Controlled_Component
(Typ
)
3179 ("aspect % applied to controlled type &", Typ
);
3182 elsif Aspect_No_Parts
= Aspect_No_Task_Parts
then
3183 if Has_Task
(Typ
) then
3185 ("aspect % applied to task type &", Typ
);
3189 raise Program_Error
;
3193 -- Move through Types_With_Aspect - checking that the value specified
3194 -- for their corresponding Aspect_No_Parts do not override each
3197 Curr_Typ_Elmt
:= First_Elmt
(Types_With_Aspect
);
3198 while Present
(Curr_Typ_Elmt
) loop
3200 Get_Aspect_No_Parts_Value
(Node
(Curr_Typ_Elmt
));
3202 -- Compare the aspect value against the current type
3204 if Curr_Value
/= Aspect_Value
then
3206 ("cannot override aspect % of "
3207 & "ancestor type &", Typ
, Node
(Curr_Typ_Elmt
));
3211 Next_Elmt
(Curr_Typ_Elmt
);
3214 -- Issue an error if the aspect applies to a type declared inside a
3215 -- generic body and if said type derives from or has a component
3216 -- of ageneric formal type - since those are considered to have
3217 -- controlled/task parts and have Aspect_No_Parts specified as
3218 -- False by default (RM H.4.1(4/5) is about the language-defined
3219 -- No_Controlled_Parts aspect, and we are using the same rules for
3222 -- We do not check tagged types since deriving from a formal type
3223 -- within an enclosing generic unit is already illegal
3224 -- (RM 3.9.1 (4/2)).
3226 if Aspect_Value
= Standard_True
3227 and then In_Generic_Body
(Typ
)
3228 and then not Is_Tagged_Type
(Typ
)
3230 Gen_Bodies
:= New_Elmt_List
;
3232 Get_Generic_Formal_Types_In_Hierarchy
3234 Examine_Components
=> True);
3236 -- Climb scopes collecting generic bodies
3238 Scop
:= Scope
(Typ
);
3239 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
3241 -- Generic package body
3243 if Ekind
(Scop
) = E_Generic_Package
3244 and then In_Package_Body
(Scop
)
3246 Append_Elmt
(Scop
, Gen_Bodies
);
3248 -- Generic subprogram body
3250 elsif Is_Generic_Subprogram
(Scop
) then
3251 Append_Elmt
(Scop
, Gen_Bodies
);
3254 Scop
:= Scope
(Scop
);
3257 -- Warn about the improper use of Aspect_No_Parts on a type
3258 -- declaration deriving from or that has a component of a generic
3259 -- formal type within the formal type's corresponding generic
3260 -- body by moving through all formal types in Typ's hierarchy and
3261 -- checking if they are formals in any of the enclosing generic
3264 -- However, a special exception gets made for formal types which
3265 -- derive from a type which has Aspect_No_Parts True.
3270 -- type Form is private;
3272 -- type Type_A is new Form with No_Controlled_Parts; -- OK
3275 -- package body G is
3276 -- type Type_B is new Form with No_Controlled_Parts; -- ERROR
3280 -- type Form is private;
3282 -- type Type_A is record C : Form; end record
3283 -- with No_Controlled_Parts; -- OK
3286 -- package body G is
3287 -- type Type_B is record C : Form; end record
3288 -- with No_Controlled_Parts; -- ERROR
3291 -- type Root is tagged null record with No_Controlled_Parts;
3294 -- type Form is new Root with private;
3296 -- type Type_A is record C : Form; end record
3297 -- with No_Controlled_Parts; -- OK
3300 -- package body G is
3301 -- type Type_B is record C : Form; end record
3302 -- with No_Controlled_Parts; -- OK
3305 Curr_Formal_Elmt
:= First_Elmt
(Gen_Formals
);
3306 while Present
(Curr_Formal_Elmt
) loop
3308 Curr_Body_Elmt
:= First_Elmt
(Gen_Bodies
);
3309 while Present
(Curr_Body_Elmt
) loop
3311 -- Obtain types in the formal type's hierarchy which have
3312 -- the aspect specified.
3314 Types_With_Aspect
:=
3315 Get_Types_With_Aspect_In_Hierarchy
3316 (Node
(Curr_Formal_Elmt
));
3318 -- We found a type declaration in a generic body where both
3319 -- Aspect_No_Parts is true and one of its ancestors is a
3320 -- generic formal type.
3322 if Scope
(Node
(Curr_Formal_Elmt
)) =
3323 Node
(Curr_Body_Elmt
)
3325 -- Check that no ancestors of the formal type have
3326 -- Aspect_No_Parts True before issuing the error.
3328 and then (Is_Empty_Elmt_List
(Types_With_Aspect
)
3330 Get_Aspect_No_Parts_Value
3331 (Node
(First_Elmt
(Types_With_Aspect
)))
3334 Error_Msg_Node_1
:= Typ
;
3335 Error_Msg_Node_2
:= Node
(Curr_Formal_Elmt
);
3337 ("aspect % cannot be applied to "
3338 & "type & which has an ancestor or component of "
3339 & "formal type & within the formal type's "
3340 & "corresponding generic body", Sloc
(Typ
));
3343 Next_Elmt
(Curr_Body_Elmt
);
3346 Next_Elmt
(Curr_Formal_Elmt
);
3349 end Check_No_Parts_Violations
;
3351 ---------------------------------
3352 -- Check_Suspicious_Convention --
3353 ---------------------------------
3355 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
) is
3357 if Has_Discriminants
(Rec_Type
)
3358 and then Is_Base_Type
(Rec_Type
)
3359 and then not Is_Unchecked_Union
(Rec_Type
)
3360 and then (Convention
(Rec_Type
) = Convention_C
3362 Convention
(Rec_Type
) = Convention_CPP
)
3363 and then Comes_From_Source
(Rec_Type
)
3364 and then not In_Instance
3365 and then not Has_Warnings_Off
(Rec_Type
)
3368 Cprag
: constant Node_Id
:=
3369 Get_Rep_Pragma
(Rec_Type
, Name_Convention
);
3373 if Present
(Cprag
) then
3374 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3376 if Convention
(Rec_Type
) = Convention_C
then
3378 ("?x?discriminated record has no direct equivalent in "
3382 ("?x?discriminated record has no direct equivalent in "
3387 ("\?x?use of convention for type& is dubious",
3392 end Check_Suspicious_Convention
;
3394 ------------------------------
3395 -- Check_Suspicious_Modulus --
3396 ------------------------------
3398 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
3399 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
3402 if not Warn_On_Suspicious_Modulus_Value
then
3406 if Nkind
(Decl
) = N_Full_Type_Declaration
then
3408 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
3411 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
3413 Modulus
: constant Node_Id
:=
3414 Original_Node
(Expression
(Tdef
));
3417 if Nkind
(Modulus
) = N_Integer_Literal
then
3419 Modv
: constant Uint
:= Intval
(Modulus
);
3420 Sizv
: constant Uint
:= RM_Size
(Utype
);
3423 -- First case, modulus and size are the same. This
3424 -- happens if you have something like mod 32, with
3425 -- an explicit size of 32, this is for sure a case
3426 -- where the warning is given, since it is seems
3427 -- very unlikely that someone would want e.g. a
3428 -- five bit type stored in 32 bits. It is much
3429 -- more likely they wanted a 32-bit type.
3434 -- Second case, the modulus is 32 or 64 and no
3435 -- size clause is present. This is a less clear
3436 -- case for giving the warning, but in the case
3437 -- of 32/64 (5-bit or 6-bit types) these seem rare
3438 -- enough that it is a likely error (and in any
3439 -- case using 2**5 or 2**6 in these cases seems
3440 -- clearer. We don't include 8 or 16 here, simply
3441 -- because in practice 3-bit and 4-bit types are
3442 -- more common and too many false positives if
3443 -- we warn in these cases.
3445 elsif not Has_Size_Clause
(Utype
)
3446 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
3450 -- No warning needed
3456 -- If we fall through, give warning
3458 Error_Msg_Uint_1
:= Modv
;
3460 ("?.m?2 '*'*^' may have been intended here",
3468 end Check_Suspicious_Modulus
;
3470 -----------------------
3471 -- Freeze_Array_Type --
3472 -----------------------
3474 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
3475 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
3476 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
3479 Non_Standard_Enum
: Boolean := False;
3480 -- Set true if any of the index types is an enumeration type with a
3481 -- non-standard representation.
3484 Freeze_And_Append
(Ctyp
, N
, Result
);
3486 Indx
:= First_Index
(Arr
);
3487 while Present
(Indx
) loop
3488 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
3490 if Is_Enumeration_Type
(Etype
(Indx
))
3491 and then Has_Non_Standard_Rep
(Etype
(Indx
))
3493 Non_Standard_Enum
:= True;
3499 -- Processing that is done only for base types
3501 if Ekind
(Arr
) = E_Array_Type
then
3503 -- Deal with default setting of reverse storage order
3505 Set_SSO_From_Default
(Arr
);
3507 -- Propagate flags for component type
3509 if Is_Controlled
(Ctyp
)
3510 or else Has_Controlled_Component
(Ctyp
)
3512 Set_Has_Controlled_Component
(Arr
);
3515 if Has_Unchecked_Union
(Ctyp
) then
3516 Set_Has_Unchecked_Union
(Arr
);
3519 -- The array type requires its own invariant procedure in order to
3520 -- verify the component invariant over all elements. In GNATprove
3521 -- mode, the component invariants are checked by other means. They
3522 -- should not be added to the array type invariant procedure, so
3523 -- that the procedure can be used to check the array type
3524 -- invariants if any.
3526 if Has_Invariants
(Ctyp
)
3527 and then not GNATprove_Mode
3529 Set_Has_Own_Invariants
(Arr
);
3532 -- Warn for pragma Pack overriding foreign convention
3534 if Has_Foreign_Convention
(Ctyp
)
3535 and then Has_Pragma_Pack
(Arr
)
3538 CN
: constant Name_Id
:=
3539 Get_Convention_Name
(Convention
(Ctyp
));
3540 PP
: constant Node_Id
:=
3541 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
3543 if Present
(PP
) then
3544 Error_Msg_Name_1
:= CN
;
3545 Error_Msg_Sloc
:= Sloc
(Arr
);
3547 ("pragma Pack affects convention % components #??", PP
);
3548 Error_Msg_Name_1
:= CN
;
3550 ("\array components may not have % compatible "
3551 & "representation??", PP
);
3556 -- Check for Aliased or Atomic_Components or Full Access with
3557 -- unsuitable packing or explicit component size clause given.
3559 if (Has_Aliased_Components
(Arr
)
3560 or else Has_Atomic_Components
(Arr
)
3561 or else Is_Full_Access
(Ctyp
))
3563 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
3565 Alias_Atomic_Check
: declare
3567 procedure Complain_CS
(T
: String);
3568 -- Outputs error messages for incorrect CS clause or pragma
3569 -- Pack for aliased or full access components (T is either
3570 -- "aliased" or "atomic" or "volatile full access");
3576 procedure Complain_CS
(T
: String) is
3578 if Has_Component_Size_Clause
(Arr
) then
3580 Get_Attribute_Definition_Clause
3581 (FS
, Attribute_Component_Size
);
3584 ("incorrect component size for "
3585 & T
& " components", Clause
);
3586 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3588 ("\only allowed value is^", Clause
);
3592 ("?cannot pack " & T
& " components (RM 13.2(7))",
3593 Get_Rep_Pragma
(FS
, Name_Pack
));
3594 Set_Is_Packed
(Arr
, False);
3598 -- Start of processing for Alias_Atomic_Check
3601 -- If object size of component type isn't known, we cannot
3602 -- be sure so we defer to the back end.
3604 if not Known_Static_Esize
(Ctyp
) then
3607 -- Case where component size has no effect. First check for
3608 -- object size of component type multiple of the storage
3611 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
3613 -- OK in both packing case and component size case if RM
3614 -- size is known and static and same as the object size.
3617 ((Known_Static_RM_Size
(Ctyp
)
3618 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
3620 -- Or if we have an explicit component size clause and
3621 -- the component size and object size are equal.
3624 (Has_Component_Size_Clause
(Arr
)
3625 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
3629 elsif Has_Aliased_Components
(Arr
) then
3630 Complain_CS
("aliased");
3632 elsif Has_Atomic_Components
(Arr
)
3633 or else Is_Atomic
(Ctyp
)
3635 Complain_CS
("atomic");
3637 elsif Is_Volatile_Full_Access
(Ctyp
) then
3638 Complain_CS
("volatile full access");
3640 end Alias_Atomic_Check
;
3643 -- Check for Independent_Components/Independent with unsuitable
3644 -- packing or explicit component size clause given.
3646 if (Has_Independent_Components
(Arr
) or else Is_Independent
(Ctyp
))
3648 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
3651 -- If object size of component type isn't known, we cannot
3652 -- be sure so we defer to the back end.
3654 if not Known_Static_Esize
(Ctyp
) then
3657 -- Case where component size has no effect. First check for
3658 -- object size of component type multiple of the storage
3661 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
3663 -- OK in both packing case and component size case if RM
3664 -- size is known and multiple of the storage unit size.
3667 ((Known_Static_RM_Size
(Ctyp
)
3668 and then RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
3670 -- Or if we have an explicit component size clause and
3671 -- the component size is larger than the object size.
3674 (Has_Component_Size_Clause
(Arr
)
3675 and then Component_Size
(Arr
) >= Esize
(Ctyp
)))
3680 if Has_Component_Size_Clause
(Arr
) then
3682 Get_Attribute_Definition_Clause
3683 (FS
, Attribute_Component_Size
);
3686 ("incorrect component size for "
3687 & "independent components", Clause
);
3688 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3690 ("\minimum allowed is^", Clause
);
3694 ("?cannot pack independent components (RM 13.2(7))",
3695 Get_Rep_Pragma
(FS
, Name_Pack
));
3696 Set_Is_Packed
(Arr
, False);
3702 -- If packing was requested or if the component size was
3703 -- set explicitly, then see if bit packing is required. This
3704 -- processing is only done for base types, since all of the
3705 -- representation aspects involved are type-related.
3707 -- This is not just an optimization, if we start processing the
3708 -- subtypes, they interfere with the settings on the base type
3709 -- (this is because Is_Packed has a slightly different meaning
3710 -- before and after freezing).
3718 and then Known_Static_RM_Size
(Ctyp
)
3719 and then not Has_Component_Size_Clause
(Arr
)
3721 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
3723 elsif Known_Component_Size
(Arr
) then
3724 Csiz
:= Component_Size
(Arr
);
3726 elsif not Known_Static_Esize
(Ctyp
) then
3730 Esiz
:= Esize
(Ctyp
);
3732 -- We can set the component size if it is less than 16,
3733 -- rounding it up to the next storage unit size.
3737 elsif Esiz
<= 16 then
3743 -- Set component size up to match alignment if it would
3744 -- otherwise be less than the alignment. This deals with
3745 -- cases of types whose alignment exceeds their size (the
3746 -- padded type cases).
3748 if Csiz
/= 0 and then Known_Alignment
(Ctyp
) then
3750 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
3759 -- Case of component size that may result in bit packing
3761 if 1 <= Csiz
and then Csiz
<= System_Max_Integer_Size
then
3763 Ent
: constant Entity_Id
:=
3764 First_Subtype
(Arr
);
3765 Pack_Pragma
: constant Node_Id
:=
3766 Get_Rep_Pragma
(Ent
, Name_Pack
);
3767 Comp_Size_C
: constant Node_Id
:=
3768 Get_Attribute_Definition_Clause
3769 (Ent
, Attribute_Component_Size
);
3772 -- Warn if we have pack and component size so that the
3775 -- Note: here we must check for the presence of a
3776 -- component size before checking for a Pack pragma to
3777 -- deal with the case where the array type is a derived
3778 -- type whose parent is currently private.
3780 if Present
(Comp_Size_C
)
3781 and then Has_Pragma_Pack
(Ent
)
3782 and then Warn_On_Redundant_Constructs
3784 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
3786 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
3788 ("\?r?explicit component size given#!", Pack_Pragma
);
3789 Set_Is_Packed
(Base_Type
(Ent
), False);
3790 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
3793 -- Set component size if not already set by a component
3796 if not Present
(Comp_Size_C
) then
3797 Set_Component_Size
(Arr
, Csiz
);
3800 -- Check for base type of 8, 16, 32 bits, where an
3801 -- unsigned subtype has a length one less than the
3802 -- base type (e.g. Natural subtype of Integer).
3804 -- In such cases, if a component size was not set
3805 -- explicitly, then generate a warning.
3807 if Has_Pragma_Pack
(Arr
)
3808 and then not Present
(Comp_Size_C
)
3809 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
3810 and then Known_Esize
(Base_Type
(Ctyp
))
3811 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
3813 Error_Msg_Uint_1
:= Csiz
;
3815 if Present
(Pack_Pragma
) then
3817 ("??pragma Pack causes component size to be ^!",
3820 ("\??use Component_Size to set desired value!",
3825 -- Bit packing is never needed for 8, 16, 32, 64 or 128
3827 if Addressable
(Csiz
) then
3829 -- If the Esize of the component is known and equal to
3830 -- the component size then even packing is not needed.
3832 if Known_Static_Esize
(Ctyp
)
3833 and then Esize
(Ctyp
) = Csiz
3835 -- Here the array was requested to be packed, but
3836 -- the packing request had no effect whatsoever,
3837 -- so flag Is_Packed is reset.
3839 -- Note: semantically this means that we lose track
3840 -- of the fact that a derived type inherited pragma
3841 -- Pack that was non-effective, but that is fine.
3843 -- We regard a Pack pragma as a request to set a
3844 -- representation characteristic, and this request
3847 Set_Is_Packed
(Base_Type
(Arr
), False);
3848 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
3850 Set_Is_Packed
(Base_Type
(Arr
), True);
3851 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3854 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3856 -- Bit packing is not needed for multiples of the storage
3857 -- unit if the type is composite because the back end can
3858 -- byte pack composite types efficiently. That's not true
3859 -- for discrete types because every read would generate a
3860 -- lot of instructions, so we keep using the manipulation
3861 -- routines of the runtime for them.
3863 elsif Csiz
mod System_Storage_Unit
= 0
3864 and then Is_Composite_Type
(Ctyp
)
3866 Set_Is_Packed
(Base_Type
(Arr
), True);
3867 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3868 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3870 -- In all other cases, bit packing is needed
3873 Set_Is_Packed
(Base_Type
(Arr
), True);
3874 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
3875 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
3881 -- Warn for case of atomic type
3883 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
3886 and then not Addressable
(Component_Size
(FS
))
3889 ("non-atomic components of type& may not be "
3890 & "accessible by separate tasks??", Clause
, Arr
);
3892 if Has_Component_Size_Clause
(Arr
) then
3893 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
3894 (FS
, Attribute_Component_Size
));
3895 Error_Msg_N
("\because of component size clause#??", Clause
);
3897 elsif Has_Pragma_Pack
(Arr
) then
3898 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
3899 Error_Msg_N
("\because of pragma Pack#??", Clause
);
3903 -- Check for scalar storage order
3908 Check_Component_Storage_Order
3911 ADC
=> Get_Attribute_Definition_Clause
3912 (First_Subtype
(Arr
),
3913 Attribute_Scalar_Storage_Order
),
3914 Comp_ADC_Present
=> Dummy
);
3917 -- Processing that is done only for subtypes
3920 -- Acquire alignment from base type. Known_Alignment of the base
3921 -- type is False for Wide_String, for example.
3923 if not Known_Alignment
(Arr
)
3924 and then Known_Alignment
(Base_Type
(Arr
))
3926 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
3927 Adjust_Esize_Alignment
(Arr
);
3931 -- Specific checks for bit-packed arrays
3933 if Is_Bit_Packed_Array
(Arr
) then
3935 -- Check number of elements for bit-packed arrays that come from
3936 -- source and have compile time known ranges. The bit-packed
3937 -- arrays circuitry does not support arrays with more than
3938 -- Integer'Last + 1 elements, and when this restriction is
3939 -- violated, causes incorrect data access.
3941 -- For the case where this is not compile time known, a run-time
3942 -- check should be generated???
3944 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
3953 Index
:= First_Index
(Arr
);
3954 while Present
(Index
) loop
3955 Ityp
:= Etype
(Index
);
3957 -- Never generate an error if any index is of a generic
3958 -- type. We will check this in instances.
3960 if Is_Generic_Type
(Ityp
) then
3966 Make_Attribute_Reference
(Loc
,
3967 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
3968 Attribute_Name
=> Name_Range_Length
);
3969 Analyze_And_Resolve
(Ilen
);
3971 -- No attempt is made to check number of elements if not
3972 -- compile time known.
3974 if Nkind
(Ilen
) /= N_Integer_Literal
then
3979 Elmts
:= Elmts
* Intval
(Ilen
);
3983 if Elmts
> Intval
(High_Bound
3984 (Scalar_Range
(Standard_Integer
))) + 1
3987 ("bit packed array type may not have "
3988 & "more than Integer''Last+1 elements", Arr
);
3995 if Known_RM_Size
(Arr
) then
3997 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
4001 -- It is not clear if it is possible to have no size clause
4002 -- at this stage, but it is not worth worrying about. Post
4003 -- error on the entity name in the size clause if present,
4004 -- else on the type entity itself.
4006 if Present
(SizC
) then
4007 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
4009 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
4015 -- If any of the index types was an enumeration type with a non-
4016 -- standard rep clause, then we indicate that the array type is
4017 -- always packed (even if it is not bit-packed).
4019 if Non_Standard_Enum
then
4020 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
4021 Set_Is_Packed
(Base_Type
(Arr
));
4024 Set_Component_Alignment_If_Not_Set
(Arr
);
4026 -- If the array is packed and bit-packed or packed to eliminate holes
4027 -- in the non-contiguous enumeration index types, we must create the
4028 -- packed array type to be used to actually implement the type. This
4029 -- is only needed for real array types (not for string literal types,
4030 -- since they are present only for the front end).
4033 and then (Is_Bit_Packed_Array
(Arr
) or else Non_Standard_Enum
)
4034 and then Ekind
(Arr
) /= E_String_Literal_Subtype
4036 Create_Packed_Array_Impl_Type
(Arr
);
4037 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
4039 -- Make sure that we have the necessary routines to implement the
4040 -- packing, and complain now if not. Note that we only test this
4041 -- for constrained array types.
4043 if Is_Constrained
(Arr
)
4044 and then Is_Bit_Packed_Array
(Arr
)
4045 and then Present
(Packed_Array_Impl_Type
(Arr
))
4046 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
4049 CS
: constant Uint
:= Component_Size
(Arr
);
4050 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
4054 and then not RTE_Available
(RE
)
4057 ("packing of " & UI_Image
(CS
) & "-bit components",
4058 First_Subtype
(Etype
(Arr
)));
4060 -- Cancel the packing
4062 Set_Is_Packed
(Base_Type
(Arr
), False);
4063 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
4064 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
4070 -- Size information of packed array type is copied to the array
4071 -- type, since this is really the representation. But do not
4072 -- override explicit existing size values. If the ancestor subtype
4073 -- is constrained the Packed_Array_Impl_Type will be inherited
4074 -- from it, but the size may have been provided already, and
4075 -- must not be overridden either.
4077 if not Has_Size_Clause
(Arr
)
4079 (No
(Ancestor_Subtype
(Arr
))
4080 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
4082 Copy_Esize
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4083 Copy_RM_Size
(To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4086 if not Has_Alignment_Clause
(Arr
) then
4088 (To
=> Arr
, From
=> Packed_Array_Impl_Type
(Arr
));
4094 -- A Ghost type cannot have a component of protected or task type
4095 -- (SPARK RM 6.9(19)).
4097 if Is_Ghost_Entity
(Arr
) and then Is_Concurrent_Type
(Ctyp
) then
4099 ("ghost array type & cannot have concurrent component type",
4102 end Freeze_Array_Type
;
4104 -------------------------------
4105 -- Freeze_Object_Declaration --
4106 -------------------------------
4108 procedure Freeze_Object_Declaration
(E
: Entity_Id
) is
4109 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
);
4110 -- Check that the size of array type Typ can be computed without
4111 -- overflow, and generates a Storage_Error otherwise. This is only
4112 -- relevant for array types whose index has System_Max_Integer_Size
4113 -- bits, where wrap-around arithmetic might yield a meaningless value
4114 -- for the length of the array, or its corresponding attribute.
4116 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
);
4117 -- Ensure that the initialization state of variable Var_Id subject
4118 -- to pragma Thread_Local_Storage agrees with the semantics of the
4121 function Has_Default_Initialization
4122 (Obj_Id
: Entity_Id
) return Boolean;
4123 -- Determine whether object Obj_Id default initialized
4125 -------------------------------
4126 -- Check_Large_Modular_Array --
4127 -------------------------------
4129 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
) is
4130 Obj_Loc
: constant Source_Ptr
:= Sloc
(E
);
4131 Idx_Typ
: Entity_Id
;
4134 -- Nothing to do when expansion is disabled because this routine
4135 -- generates a runtime check.
4137 if not Expander_Active
then
4140 -- Nothing to do for String literal subtypes because their index
4141 -- cannot be a modular type.
4143 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
4146 -- Nothing to do for an imported object because the object will
4147 -- be created on the exporting side.
4149 elsif Is_Imported
(E
) then
4152 -- Nothing to do for unconstrained array types. This case arises
4153 -- when the object declaration is illegal.
4155 elsif not Is_Constrained
(Typ
) then
4159 Idx_Typ
:= Etype
(First_Index
(Typ
));
4161 -- To prevent arithmetic overflow with large values, we raise
4162 -- Storage_Error under the following guard:
4164 -- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
4166 -- This takes care of the boundary case, but it is preferable to
4167 -- use a smaller limit, because even on 64-bit architectures an
4168 -- array of more than 2 ** 30 bytes is likely to raise
4171 if Is_Modular_Integer_Type
(Idx_Typ
)
4172 and then RM_Size
(Idx_Typ
) = RM_Size
(Standard_Long_Long_Integer
)
4174 Insert_Action
(Declaration_Node
(E
),
4175 Make_Raise_Storage_Error
(Obj_Loc
,
4177 Make_Op_Ge
(Obj_Loc
,
4179 Make_Op_Subtract
(Obj_Loc
,
4181 Make_Op_Divide
(Obj_Loc
,
4183 Make_Attribute_Reference
(Obj_Loc
,
4185 New_Occurrence_Of
(Typ
, Obj_Loc
),
4186 Attribute_Name
=> Name_Last
),
4188 Make_Integer_Literal
(Obj_Loc
, Uint_2
)),
4190 Make_Op_Divide
(Obj_Loc
,
4192 Make_Attribute_Reference
(Obj_Loc
,
4194 New_Occurrence_Of
(Typ
, Obj_Loc
),
4195 Attribute_Name
=> Name_First
),
4197 Make_Integer_Literal
(Obj_Loc
, Uint_2
))),
4199 Make_Integer_Literal
(Obj_Loc
, (Uint_2
** 30))),
4200 Reason
=> SE_Object_Too_Large
));
4202 end Check_Large_Modular_Array
;
4204 ---------------------------------------
4205 -- Check_Pragma_Thread_Local_Storage --
4206 ---------------------------------------
4208 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
) is
4209 function Has_Incompatible_Initialization
4210 (Var_Decl
: Node_Id
) return Boolean;
4211 -- Determine whether variable Var_Id with declaration Var_Decl is
4212 -- initialized with a value that violates the semantics of pragma
4213 -- Thread_Local_Storage.
4215 -------------------------------------
4216 -- Has_Incompatible_Initialization --
4217 -------------------------------------
4219 function Has_Incompatible_Initialization
4220 (Var_Decl
: Node_Id
) return Boolean
4222 Init_Expr
: constant Node_Id
:= Expression
(Var_Decl
);
4225 -- The variable is default-initialized. This directly violates
4226 -- the semantics of the pragma.
4228 if Has_Default_Initialization
(Var_Id
) then
4231 -- The variable has explicit initialization. In this case only
4232 -- a handful of values satisfy the semantics of the pragma.
4234 elsif Has_Init_Expression
(Var_Decl
)
4235 and then Present
(Init_Expr
)
4237 -- "null" is a legal form of initialization
4239 if Nkind
(Init_Expr
) = N_Null
then
4242 -- A static expression is a legal form of initialization
4244 elsif Is_Static_Expression
(Init_Expr
) then
4247 -- A static aggregate is a legal form of initialization
4249 elsif Nkind
(Init_Expr
) = N_Aggregate
4250 and then Compile_Time_Known_Aggregate
(Init_Expr
)
4254 -- All other initialization expressions violate the semantic
4261 -- The variable lacks any kind of initialization, which agrees
4262 -- with the semantics of the pragma.
4267 end Has_Incompatible_Initialization
;
4269 -- Local declarations
4271 Var_Decl
: constant Node_Id
:= Declaration_Node
(Var_Id
);
4273 -- Start of processing for Check_Pragma_Thread_Local_Storage
4276 -- A variable whose initialization is suppressed lacks any kind of
4279 if Suppress_Initialization
(Var_Id
) then
4282 -- The variable has default initialization, or is explicitly
4283 -- initialized to a value other than null, static expression,
4284 -- or a static aggregate.
4286 elsif Has_Incompatible_Initialization
(Var_Decl
) then
4288 ("Thread_Local_Storage variable& is improperly initialized",
4291 ("\only allowed initialization is explicit NULL, static "
4292 & "expression or static aggregate", Var_Decl
, Var_Id
);
4294 end Check_Pragma_Thread_Local_Storage
;
4296 --------------------------------
4297 -- Has_Default_Initialization --
4298 --------------------------------
4300 function Has_Default_Initialization
4301 (Obj_Id
: Entity_Id
) return Boolean
4303 Obj_Decl
: constant Node_Id
:= Declaration_Node
(Obj_Id
);
4304 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
4308 Comes_From_Source
(Obj_Id
)
4309 and then not Is_Imported
(Obj_Id
)
4310 and then not Has_Init_Expression
(Obj_Decl
)
4312 ((Has_Non_Null_Base_Init_Proc
(Obj_Typ
)
4313 and then not No_Initialization
(Obj_Decl
)
4314 and then not Initialization_Suppressed
(Obj_Typ
))
4316 (Needs_Simple_Initialization
(Obj_Typ
)
4317 and then not Is_Internal
(Obj_Id
)));
4318 end Has_Default_Initialization
;
4322 Typ
: constant Entity_Id
:= Etype
(E
);
4325 -- Start of processing for Freeze_Object_Declaration
4328 -- Abstract type allowed only for C++ imported variables or constants
4330 -- Note: we inhibit this check for objects that do not come from
4331 -- source because there is at least one case (the expansion of
4332 -- x'Class'Input where x is abstract) where we legitimately
4333 -- generate an abstract object.
4335 if Is_Abstract_Type
(Typ
)
4336 and then Comes_From_Source
(Parent
(E
))
4337 and then not (Is_Imported
(E
) and then Is_CPP_Class
(Typ
))
4339 Def
:= Object_Definition
(Parent
(E
));
4341 Error_Msg_N
("type of object cannot be abstract", Def
);
4343 if Is_CPP_Class
(Etype
(E
)) then
4344 Error_Msg_NE
("\} may need a cpp_constructor", Def
, Typ
);
4346 elsif Present
(Expression
(Parent
(E
))) then
4347 Error_Msg_N
-- CODEFIX
4348 ("\maybe a class-wide type was meant", Def
);
4352 -- For object created by object declaration, perform required
4353 -- categorization (preelaborate and pure) checks. Defer these
4354 -- checks to freeze time since pragma Import inhibits default
4355 -- initialization and thus pragma Import affects these checks.
4357 Validate_Object_Declaration
(Declaration_Node
(E
));
4359 -- If there is an address clause, check that it is valid and if need
4360 -- be move initialization to the freeze node.
4362 Check_Address_Clause
(E
);
4364 -- Similar processing is needed for aspects that may affect object
4365 -- layout, like Address, if there is an initialization expression.
4366 -- We don't do this if there is a pragma Linker_Section, because it
4367 -- would prevent the back end from statically initializing the
4368 -- object; we don't want elaboration code in that case.
4370 if Has_Delayed_Aspects
(E
)
4371 and then Expander_Active
4372 and then Is_Array_Type
(Typ
)
4373 and then Present
(Expression
(Declaration_Node
(E
)))
4374 and then No
(Linker_Section_Pragma
(E
))
4377 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4378 Lhs
: constant Node_Id
:= New_Occurrence_Of
(E
, Loc
);
4381 -- Capture initialization value at point of declaration, and
4382 -- make explicit assignment legal, because object may be a
4385 Remove_Side_Effects
(Expression
(Decl
));
4386 Set_Assignment_OK
(Lhs
);
4388 -- Move initialization to freeze actions
4390 Append_Freeze_Action
(E
,
4391 Make_Assignment_Statement
(Loc
,
4393 Expression
=> Expression
(Decl
)));
4395 Set_No_Initialization
(Decl
);
4396 -- Set_Is_Frozen (E, False);
4400 -- Reset Is_True_Constant for non-constant aliased object. We
4401 -- consider that the fact that a non-constant object is aliased may
4402 -- indicate that some funny business is going on, e.g. an aliased
4403 -- object is passed by reference to a procedure which captures the
4404 -- address of the object, which is later used to assign a new value,
4405 -- even though the compiler thinks that it is not modified. Such
4406 -- code is highly dubious, but we choose to make it "work" for
4407 -- non-constant aliased objects.
4409 -- Note that we used to do this for all aliased objects, whether or
4410 -- not constant, but this caused anomalies down the line because we
4411 -- ended up with static objects that were not Is_True_Constant. Not
4412 -- resetting Is_True_Constant for (aliased) constant objects ensures
4413 -- that this anomaly never occurs.
4415 -- However, we don't do that for internal entities. We figure that if
4416 -- we deliberately set Is_True_Constant for an internal entity, e.g.
4417 -- a dispatch table entry, then we mean it.
4419 if Ekind
(E
) /= E_Constant
4420 and then (Is_Aliased
(E
) or else Is_Aliased
(Typ
))
4421 and then not Is_Internal_Name
(Chars
(E
))
4423 Set_Is_True_Constant
(E
, False);
4426 -- If the object needs any kind of default initialization, an error
4427 -- must be issued if No_Default_Initialization applies. The check
4428 -- doesn't apply to imported objects, which are not ever default
4429 -- initialized, and is why the check is deferred until freezing, at
4430 -- which point we know if Import applies. Deferred constants are also
4431 -- exempted from this test because their completion is explicit, or
4432 -- through an import pragma.
4434 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
4437 elsif Has_Default_Initialization
(E
) then
4439 (No_Default_Initialization
, Declaration_Node
(E
));
4442 -- Ensure that a variable subject to pragma Thread_Local_Storage
4444 -- * Lacks default initialization, or
4446 -- * The initialization expression is either "null", a static
4447 -- constant, or a compile-time known aggregate.
4449 if Has_Pragma_Thread_Local_Storage
(E
) then
4450 Check_Pragma_Thread_Local_Storage
(E
);
4453 -- For imported objects, set Is_Public unless there is also an
4454 -- address clause, which means that there is no external symbol
4455 -- needed for the Import (Is_Public may still be set for other
4456 -- unrelated reasons). Note that we delayed this processing
4457 -- till freeze time so that we can be sure not to set the flag
4458 -- if there is an address clause. If there is such a clause,
4459 -- then the only purpose of the Import pragma is to suppress
4460 -- implicit initialization.
4462 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4466 -- For source objects that are not Imported and are library level, if
4467 -- no linker section pragma was given inherit the appropriate linker
4468 -- section from the corresponding type.
4470 if Comes_From_Source
(E
)
4471 and then not Is_Imported
(E
)
4472 and then Is_Library_Level_Entity
(E
)
4473 and then No
(Linker_Section_Pragma
(E
))
4475 Set_Linker_Section_Pragma
(E
, Linker_Section_Pragma
(Typ
));
4478 -- For convention C objects of an enumeration type, warn if the size
4479 -- is not integer size and no explicit size given. Skip warning for
4480 -- Boolean and Character, and assume programmer expects 8-bit sizes
4483 if (Convention
(E
) = Convention_C
4485 Convention
(E
) = Convention_CPP
)
4486 and then Is_Enumeration_Type
(Typ
)
4487 and then not Is_Character_Type
(Typ
)
4488 and then not Is_Boolean_Type
(Typ
)
4489 and then Esize
(Typ
) < Standard_Integer_Size
4490 and then not Has_Size_Clause
(E
)
4492 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4494 ("??convention C enumeration object has size less than ^", E
);
4495 Error_Msg_N
("\??use explicit size clause to set size", E
);
4498 -- Declaring too big an array in disabled ghost code is OK
4500 if Is_Array_Type
(Typ
) and then not Is_Ignored_Ghost_Entity
(E
) then
4501 Check_Large_Modular_Array
(Typ
);
4503 end Freeze_Object_Declaration
;
4505 -----------------------------
4506 -- Freeze_Generic_Entities --
4507 -----------------------------
4509 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
4516 E
:= First_Entity
(Pack
);
4517 while Present
(E
) loop
4518 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
4519 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
4521 Append_To
(Flist
, F
);
4523 elsif Ekind
(E
) = E_Generic_Package
then
4524 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
4531 end Freeze_Generic_Entities
;
4533 --------------------
4534 -- Freeze_Profile --
4535 --------------------
4537 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
4540 Warn_Node
: Node_Id
;
4543 -- Loop through formals
4545 Formal
:= First_Formal
(E
);
4546 while Present
(Formal
) loop
4547 F_Type
:= Etype
(Formal
);
4549 -- AI05-0151: incomplete types can appear in a profile. By the
4550 -- time the entity is frozen, the full view must be available,
4551 -- unless it is a limited view.
4553 if Is_Incomplete_Type
(F_Type
)
4554 and then Present
(Full_View
(F_Type
))
4555 and then not From_Limited_With
(F_Type
)
4557 F_Type
:= Full_View
(F_Type
);
4558 Set_Etype
(Formal
, F_Type
);
4561 if not From_Limited_With
(F_Type
)
4562 and then Should_Freeze_Type
(F_Type
, E
, N
)
4564 Freeze_And_Append
(F_Type
, N
, Result
);
4567 if Is_Private_Type
(F_Type
)
4568 and then Is_Private_Type
(Base_Type
(F_Type
))
4569 and then No
(Full_View
(Base_Type
(F_Type
)))
4570 and then not Is_Generic_Type
(F_Type
)
4571 and then not Is_Derived_Type
(F_Type
)
4573 -- If the type of a formal is incomplete, subprogram is being
4574 -- frozen prematurely. Within an instance (but not within a
4575 -- wrapper package) this is an artifact of our need to regard
4576 -- the end of an instantiation as a freeze point. Otherwise it
4577 -- is a definite error.
4580 Set_Is_Frozen
(E
, False);
4584 elsif not After_Last_Declaration
then
4586 ("type & must be fully defined before this point",
4592 -- Check suspicious parameter for C function. These tests apply
4593 -- only to exported/imported subprograms.
4595 if Warn_On_Export_Import
4596 and then Comes_From_Source
(E
)
4597 and then Convention
(E
) in Convention_C_Family
4598 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4599 and then Convention
(E
) /= Convention
(Formal
)
4600 and then not Has_Warnings_Off
(E
)
4601 and then not Has_Warnings_Off
(F_Type
)
4602 and then not Has_Warnings_Off
(Formal
)
4604 -- Qualify mention of formals with subprogram name
4606 Error_Msg_Qual_Level
:= 1;
4608 -- Check suspicious use of fat C pointer, but do not emit
4609 -- a warning on an access to subprogram when unnesting is
4612 if Is_Access_Type
(F_Type
)
4613 and then Known_Esize
(F_Type
)
4614 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
4615 and then (not Unnest_Subprogram_Mode
4616 or else not Is_Access_Subprogram_Type
(F_Type
))
4619 ("?x?type of & does not correspond to C pointer!", Formal
);
4621 -- Check suspicious return of boolean
4623 elsif Root_Type
(F_Type
) = Standard_Boolean
4624 and then Convention
(F_Type
) = Convention_Ada
4625 and then not Has_Warnings_Off
(F_Type
)
4626 and then not Has_Size_Clause
(F_Type
)
4629 ("& is an 8-bit Ada Boolean?x?", Formal
);
4631 ("\use appropriate corresponding type in C "
4632 & "(e.g. char)?x?", Formal
);
4634 -- Check suspicious tagged type
4636 elsif (Is_Tagged_Type
(F_Type
)
4638 (Is_Access_Type
(F_Type
)
4639 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
4640 and then Convention
(E
) = Convention_C
4643 ("?x?& involves a tagged type which does not "
4644 & "correspond to any C type!", Formal
);
4646 -- Check wrong convention subprogram pointer
4648 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
4649 and then not Has_Foreign_Convention
(F_Type
)
4652 ("?x?subprogram pointer & should "
4653 & "have foreign convention!", Formal
);
4654 Error_Msg_Sloc
:= Sloc
(F_Type
);
4656 ("\?x?add Convention pragma to declaration of &#",
4660 -- Turn off name qualification after message output
4662 Error_Msg_Qual_Level
:= 0;
4665 -- Check for unconstrained array in exported foreign convention
4668 if Has_Foreign_Convention
(E
)
4669 and then not Is_Imported
(E
)
4670 and then Is_Array_Type
(F_Type
)
4671 and then not Is_Constrained
(F_Type
)
4672 and then Warn_On_Export_Import
4674 Error_Msg_Qual_Level
:= 1;
4676 -- If this is an inherited operation, place the warning on
4677 -- the derived type declaration, rather than on the original
4680 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
4682 Warn_Node
:= Parent
(E
);
4684 if Formal
= First_Formal
(E
) then
4685 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
4688 Warn_Node
:= Formal
;
4691 Error_Msg_NE
("?x?type of argument& is unconstrained array",
4693 Error_Msg_N
("\?x?foreign caller must pass bounds explicitly",
4695 Error_Msg_Qual_Level
:= 0;
4698 if not From_Limited_With
(F_Type
) then
4699 if Is_Access_Type
(F_Type
) then
4700 F_Type
:= Designated_Type
(F_Type
);
4704 Next_Formal
(Formal
);
4707 -- Case of function: similar checks on return type
4709 if Ekind
(E
) = E_Function
then
4711 -- Freeze return type
4713 R_Type
:= Etype
(E
);
4715 -- AI05-0151: the return type may have been incomplete at the
4716 -- point of declaration. Replace it with the full view, unless the
4717 -- current type is a limited view. In that case the full view is
4718 -- in a different unit, and gigi finds the non-limited view after
4719 -- the other unit is elaborated.
4721 if Ekind
(R_Type
) = E_Incomplete_Type
4722 and then Present
(Full_View
(R_Type
))
4723 and then not From_Limited_With
(R_Type
)
4725 R_Type
:= Full_View
(R_Type
);
4726 Set_Etype
(E
, R_Type
);
4729 if Should_Freeze_Type
(R_Type
, E
, N
) then
4730 Freeze_And_Append
(R_Type
, N
, Result
);
4733 -- Check suspicious return type for C function
4735 if Warn_On_Export_Import
4736 and then Comes_From_Source
(E
)
4737 and then Convention
(E
) in Convention_C_Family
4738 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4740 -- Check suspicious return of fat C pointer
4742 if Is_Access_Type
(R_Type
)
4743 and then Known_Esize
(R_Type
)
4744 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
4745 and then not Has_Warnings_Off
(E
)
4746 and then not Has_Warnings_Off
(R_Type
)
4749 ("?x?return type of& does not correspond to C pointer!",
4752 -- Check suspicious return of boolean
4754 elsif Root_Type
(R_Type
) = Standard_Boolean
4755 and then Convention
(R_Type
) = Convention_Ada
4756 and then not Has_Warnings_Off
(E
)
4757 and then not Has_Warnings_Off
(R_Type
)
4758 and then not Has_Size_Clause
(R_Type
)
4761 N
: constant Node_Id
:=
4762 Result_Definition
(Declaration_Node
(E
));
4765 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
4767 ("\use appropriate corresponding type in C "
4768 & "(e.g. char)?x?", N
, E
);
4771 -- Check suspicious return tagged type
4773 elsif (Is_Tagged_Type
(R_Type
)
4774 or else (Is_Access_Type
(R_Type
)
4777 (Designated_Type
(R_Type
))))
4778 and then Convention
(E
) = Convention_C
4779 and then not Has_Warnings_Off
(E
)
4780 and then not Has_Warnings_Off
(R_Type
)
4782 Error_Msg_N
("?x?return type of & does not "
4783 & "correspond to C type!", E
);
4785 -- Check return of wrong convention subprogram pointer
4787 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
4788 and then not Has_Foreign_Convention
(R_Type
)
4789 and then not Has_Warnings_Off
(E
)
4790 and then not Has_Warnings_Off
(R_Type
)
4792 Error_Msg_N
("?x?& should return a foreign "
4793 & "convention subprogram pointer", E
);
4794 Error_Msg_Sloc
:= Sloc
(R_Type
);
4796 ("\?x?add Convention pragma to declaration of& #",
4801 -- Give warning for suspicious return of a result of an
4802 -- unconstrained array type in a foreign convention function.
4804 if Has_Foreign_Convention
(E
)
4806 -- We are looking for a return of unconstrained array
4808 and then Is_Array_Type
(R_Type
)
4809 and then not Is_Constrained
(R_Type
)
4811 -- Exclude imported routines, the warning does not belong on
4812 -- the import, but rather on the routine definition.
4814 and then not Is_Imported
(E
)
4816 -- Check that general warning is enabled, and that it is not
4817 -- suppressed for this particular case.
4819 and then Warn_On_Export_Import
4820 and then not Has_Warnings_Off
(E
)
4821 and then not Has_Warnings_Off
(R_Type
)
4824 ("?x?foreign convention function& should not return "
4825 & "unconstrained array!", E
);
4829 -- Check suspicious use of Import in pure unit (cases where the RM
4830 -- allows calls to be omitted).
4834 -- It might be suspicious if the compilation unit has the Pure
4837 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
4839 -- The RM allows omission of calls only in the case of
4840 -- library-level subprograms (see RM-10.2.1(18)).
4842 and then Is_Library_Level_Entity
(E
)
4844 -- Ignore internally generated entity. This happens in some cases
4845 -- of subprograms in specs, where we generate an implied body.
4847 and then Comes_From_Source
(Import_Pragma
(E
))
4849 -- Assume run-time knows what it is doing
4851 and then not GNAT_Mode
4853 -- Assume explicit Pure_Function means import is pure
4855 and then not Has_Pragma_Pure_Function
(E
)
4857 -- Don't need warning in relaxed semantics mode
4859 and then not Relaxed_RM_Semantics
4861 -- Assume convention Intrinsic is OK, since this is specialized.
4862 -- This deals with the DEC unit current_exception.ads
4864 and then Convention
(E
) /= Convention_Intrinsic
4866 -- Assume that ASM interface knows what it is doing
4868 and then Convention
(E
) /= Convention_Assembler
4871 ("pragma Import in Pure unit??", Import_Pragma
(E
));
4873 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
4874 Import_Pragma
(E
), E
);
4880 ------------------------
4881 -- Freeze_Record_Type --
4882 ------------------------
4884 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
4891 pragma Warnings
(Off
, Junk
);
4893 Aliased_Component
: Boolean := False;
4894 -- Set True if we find at least one component which is aliased. This
4895 -- is used to prevent Implicit_Packing of the record, since packing
4896 -- cannot modify the size of alignment of an aliased component.
4898 All_Elem_Components
: Boolean := True;
4899 -- True if all components are of a type whose underlying type is
4902 All_Sized_Components
: Boolean := True;
4903 -- True if all components have a known RM_Size
4905 All_Storage_Unit_Components
: Boolean := True;
4906 -- True if all components have an RM_Size that is a multiple of the
4909 Elem_Component_Total_Esize
: Uint
:= Uint_0
;
4910 -- Accumulates total Esize values of all elementary components. Used
4911 -- for processing of Implicit_Packing.
4913 Placed_Component
: Boolean := False;
4914 -- Set True if we find at least one component with a component
4915 -- clause (used to warn about useless Bit_Order pragmas, and also
4916 -- to detect cases where Implicit_Packing may have an effect).
4918 Sized_Component_Total_RM_Size
: Uint
:= Uint_0
;
4919 -- Accumulates total RM_Size values of all sized components. Used
4920 -- for processing of Implicit_Packing.
4922 Sized_Component_Total_Round_RM_Size
: Uint
:= Uint_0
;
4923 -- Accumulates total RM_Size values of all sized components, rounded
4924 -- individually to a multiple of the storage unit.
4927 -- Scalar_Storage_Order attribute definition clause for the record
4929 SSO_ADC_Component
: Boolean := False;
4930 -- Set True if we find at least one component whose type has a
4931 -- Scalar_Storage_Order attribute definition clause.
4933 Unplaced_Component
: Boolean := False;
4934 -- Set True if we find at least one component with no component
4935 -- clause (used to warn about useless Pack pragmas).
4937 procedure Check_Itype
(Typ
: Entity_Id
);
4938 -- If the component subtype is an access to a constrained subtype of
4939 -- an already frozen type, make the subtype frozen as well. It might
4940 -- otherwise be frozen in the wrong scope, and a freeze node on
4941 -- subtype has no effect. Similarly, if the component subtype is a
4942 -- regular (not protected) access to subprogram, set the anonymous
4943 -- subprogram type to frozen as well, to prevent an out-of-scope
4944 -- freeze node at some eventual point of call. Protected operations
4945 -- are handled elsewhere.
4947 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
4948 -- Make sure that all types mentioned in Discrete_Choices of the
4949 -- variants referenceed by the Variant_Part VP are frozen. This is
4950 -- a recursive routine to deal with nested variants.
4956 procedure Check_Itype
(Typ
: Entity_Id
) is
4957 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
4960 if not Is_Frozen
(Desig
)
4961 and then Is_Frozen
(Base_Type
(Desig
))
4963 Set_Is_Frozen
(Desig
);
4965 -- In addition, add an Itype_Reference to ensure that the
4966 -- access subtype is elaborated early enough. This cannot be
4967 -- done if the subtype may depend on discriminants.
4969 if Ekind
(Comp
) = E_Component
4970 and then Is_Itype
(Etype
(Comp
))
4971 and then not Has_Discriminants
(Rec
)
4973 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
4974 Set_Itype
(IR
, Desig
);
4978 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
4979 and then Convention
(Desig
) /= Convention_Protected
4981 Set_Is_Frozen
(Desig
);
4985 ------------------------------------
4986 -- Freeze_Choices_In_Variant_Part --
4987 ------------------------------------
4989 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
4990 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
4997 -- Loop through variants
4999 Variant
:= First_Non_Pragma
(Variants
(VP
));
5000 while Present
(Variant
) loop
5002 -- Loop through choices, checking that all types are frozen
5004 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
5005 while Present
(Choice
) loop
5006 if Nkind
(Choice
) in N_Has_Etype
5007 and then Present
(Etype
(Choice
))
5009 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
5012 Next_Non_Pragma
(Choice
);
5015 -- Check for nested variant part to process
5017 CL
:= Component_List
(Variant
);
5019 if not Null_Present
(CL
) then
5020 if Present
(Variant_Part
(CL
)) then
5021 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
5025 Next_Non_Pragma
(Variant
);
5027 end Freeze_Choices_In_Variant_Part
;
5029 -- Start of processing for Freeze_Record_Type
5032 -- Freeze components and embedded subtypes
5034 Comp
:= First_Entity
(Rec
);
5036 while Present
(Comp
) loop
5037 if Is_Aliased
(Comp
) then
5038 Aliased_Component
:= True;
5041 -- Handle the component and discriminant case
5043 if Ekind
(Comp
) in E_Component | E_Discriminant
then
5045 CC
: constant Node_Id
:= Component_Clause
(Comp
);
5048 -- Freezing a record type freezes the type of each of its
5049 -- components. However, if the type of the component is
5050 -- part of this record, we do not want or need a separate
5051 -- Freeze_Node. Note that Is_Itype is wrong because that's
5052 -- also set in private type cases. We also can't check for
5053 -- the Scope being exactly Rec because of private types and
5054 -- record extensions.
5056 if Is_Itype
(Etype
(Comp
))
5057 and then Is_Record_Type
(Underlying_Type
5058 (Scope
(Etype
(Comp
))))
5060 Undelay_Type
(Etype
(Comp
));
5063 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5065 -- Warn for pragma Pack overriding foreign convention
5067 if Has_Foreign_Convention
(Etype
(Comp
))
5068 and then Has_Pragma_Pack
(Rec
)
5070 -- Don't warn for aliased components, since override
5071 -- cannot happen in that case.
5073 and then not Is_Aliased
(Comp
)
5076 CN
: constant Name_Id
:=
5077 Get_Convention_Name
(Convention
(Etype
(Comp
)));
5078 PP
: constant Node_Id
:=
5079 Get_Pragma
(Rec
, Pragma_Pack
);
5081 if Present
(PP
) then
5082 Error_Msg_Name_1
:= CN
;
5083 Error_Msg_Sloc
:= Sloc
(Comp
);
5085 ("pragma Pack affects convention % component#??",
5087 Error_Msg_Name_1
:= CN
;
5089 ("\component & may not have % compatible "
5090 & "representation??", PP
, Comp
);
5095 -- Check for error of component clause given for variable
5096 -- sized type. We have to delay this test till this point,
5097 -- since the component type has to be frozen for us to know
5098 -- if it is variable length.
5100 if Present
(CC
) then
5101 Placed_Component
:= True;
5103 -- We omit this test in a generic context, it will be
5104 -- applied at instantiation time.
5106 if Inside_A_Generic
then
5109 -- Also omit this test in CodePeer mode, since we do not
5110 -- have sufficient info on size and rep clauses.
5112 elsif CodePeer_Mode
then
5118 Size_Known_At_Compile_Time
5119 (Underlying_Type
(Etype
(Comp
)))
5122 ("component clause not allowed for variable " &
5123 "length component", CC
);
5127 Unplaced_Component
:= True;
5130 -- Case of component requires byte alignment
5132 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
5134 -- Set the enclosing record to also require byte align
5136 Set_Must_Be_On_Byte_Boundary
(Rec
);
5138 -- Check for component clause that is inconsistent with
5139 -- the required byte boundary alignment.
5142 and then Normalized_First_Bit
(Comp
) mod
5143 System_Storage_Unit
/= 0
5146 ("component & must be byte aligned",
5147 Component_Name
(Component_Clause
(Comp
)));
5153 -- Gather data for possible Implicit_Packing later. Note that at
5154 -- this stage we might be dealing with a real component, or with
5155 -- an implicit subtype declaration.
5157 if Known_Static_RM_Size
(Etype
(Comp
)) then
5159 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
5160 Comp_Size
: constant Uint
:= RM_Size
(Comp_Type
);
5161 SSU
: constant Int
:= Ttypes
.System_Storage_Unit
;
5164 Sized_Component_Total_RM_Size
:=
5165 Sized_Component_Total_RM_Size
+ Comp_Size
;
5167 Sized_Component_Total_Round_RM_Size
:=
5168 Sized_Component_Total_Round_RM_Size
+
5169 (Comp_Size
+ SSU
- 1) / SSU
* SSU
;
5171 if Present
(Underlying_Type
(Comp_Type
))
5172 and then Is_Elementary_Type
(Underlying_Type
(Comp_Type
))
5174 Elem_Component_Total_Esize
:=
5175 Elem_Component_Total_Esize
+ Esize
(Comp_Type
);
5177 All_Elem_Components
:= False;
5179 if Comp_Size
mod SSU
/= 0 then
5180 All_Storage_Unit_Components
:= False;
5185 All_Sized_Components
:= False;
5188 -- If the component is an Itype with Delayed_Freeze and is either
5189 -- a record or array subtype and its base type has not yet been
5190 -- frozen, we must remove this from the entity list of this record
5191 -- and put it on the entity list of the scope of its base type.
5192 -- Note that we know that this is not the type of a component
5193 -- since we cleared Has_Delayed_Freeze for it in the previous
5194 -- loop. Thus this must be the Designated_Type of an access type,
5195 -- which is the type of a component.
5198 and then Is_Type
(Scope
(Comp
))
5199 and then Is_Composite_Type
(Comp
)
5200 and then Base_Type
(Comp
) /= Comp
5201 and then Has_Delayed_Freeze
(Comp
)
5202 and then not Is_Frozen
(Base_Type
(Comp
))
5205 Will_Be_Frozen
: Boolean := False;
5209 -- We have a difficult case to handle here. Suppose Rec is
5210 -- subtype being defined in a subprogram that's created as
5211 -- part of the freezing of Rec'Base. In that case, we know
5212 -- that Comp'Base must have already been frozen by the time
5213 -- we get to elaborate this because Gigi doesn't elaborate
5214 -- any bodies until it has elaborated all of the declarative
5215 -- part. But Is_Frozen will not be set at this point because
5216 -- we are processing code in lexical order.
5218 -- We detect this case by going up the Scope chain of Rec
5219 -- and seeing if we have a subprogram scope before reaching
5220 -- the top of the scope chain or that of Comp'Base. If we
5221 -- do, then mark that Comp'Base will actually be frozen. If
5222 -- so, we merely undelay it.
5225 while Present
(S
) loop
5226 if Is_Subprogram
(S
) then
5227 Will_Be_Frozen
:= True;
5229 elsif S
= Scope
(Base_Type
(Comp
)) then
5236 if Will_Be_Frozen
then
5237 Undelay_Type
(Comp
);
5240 if Present
(Prev
) then
5241 Link_Entities
(Prev
, Next_Entity
(Comp
));
5243 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
5246 -- Insert in entity list of scope of base type (which
5247 -- must be an enclosing scope, because still unfrozen).
5249 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
5253 -- If the component is an access type with an allocator as default
5254 -- value, the designated type will be frozen by the corresponding
5255 -- expression in init_proc. In order to place the freeze node for
5256 -- the designated type before that for the current record type,
5259 -- Same process if the component is an array of access types,
5260 -- initialized with an aggregate. If the designated type is
5261 -- private, it cannot contain allocators, and it is premature
5262 -- to freeze the type, so we check for this as well.
5264 elsif Is_Access_Type
(Etype
(Comp
))
5265 and then Present
(Parent
(Comp
))
5267 Nkind
(Parent
(Comp
))
5268 in N_Component_Declaration | N_Discriminant_Specification
5269 and then Present
(Expression
(Parent
(Comp
)))
5272 Alloc
: constant Node_Id
:=
5273 Unqualify
(Expression
(Parent
(Comp
)));
5276 if Nkind
(Alloc
) = N_Allocator
then
5278 -- If component is pointer to a class-wide type, freeze
5279 -- the specific type in the expression being allocated.
5280 -- The expression may be a subtype indication, in which
5281 -- case freeze the subtype mark.
5283 if Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp
)))
5285 if Is_Entity_Name
(Expression
(Alloc
)) then
5287 (Entity
(Expression
(Alloc
)), N
, Result
);
5289 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
5292 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
5295 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
5296 Check_Itype
(Etype
(Comp
));
5299 (Designated_Type
(Etype
(Comp
)), N
, Result
);
5303 elsif Is_Access_Type
(Etype
(Comp
))
5304 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
5306 Check_Itype
(Etype
(Comp
));
5308 -- Freeze the designated type when initializing a component with
5309 -- an aggregate in case the aggregate contains allocators.
5312 -- type T_Ptr is access all T;
5313 -- type T_Array is array ... of T_Ptr;
5315 -- type Rec is record
5316 -- Comp : T_Array := (others => ...);
5319 elsif Is_Array_Type
(Etype
(Comp
))
5320 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
5323 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
5324 Desig_Typ
: constant Entity_Id
:=
5326 (Component_Type
(Etype
(Comp
)));
5329 -- The only case when this sort of freezing is not done is
5330 -- when the designated type is class-wide and the root type
5331 -- is the record owning the component. This scenario results
5332 -- in a circularity because the class-wide type requires
5333 -- primitives that have not been created yet as the root
5334 -- type is in the process of being frozen.
5336 -- type Rec is tagged;
5337 -- type Rec_Ptr is access all Rec'Class;
5338 -- type Rec_Array is array ... of Rec_Ptr;
5340 -- type Rec is record
5341 -- Comp : Rec_Array := (others => ...);
5344 if Is_Class_Wide_Type
(Desig_Typ
)
5345 and then Root_Type
(Desig_Typ
) = Rec
5349 elsif Is_Fully_Defined
(Desig_Typ
)
5350 and then Present
(Comp_Par
)
5351 and then Nkind
(Comp_Par
) = N_Component_Declaration
5352 and then Present
(Expression
(Comp_Par
))
5353 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
5355 Freeze_And_Append
(Desig_Typ
, N
, Result
);
5365 Get_Attribute_Definition_Clause
5366 (Rec
, Attribute_Scalar_Storage_Order
);
5368 -- If the record type has Complex_Representation, then it is treated
5369 -- as a scalar in the back end so the storage order is irrelevant.
5371 if Has_Complex_Representation
(Rec
) then
5372 if Present
(SSO_ADC
) then
5374 ("??storage order has no effect with Complex_Representation",
5379 -- Deal with default setting of reverse storage order
5381 Set_SSO_From_Default
(Rec
);
5383 -- Check consistent attribute setting on component types
5386 Comp_ADC_Present
: Boolean;
5388 Comp
:= First_Component
(Rec
);
5389 while Present
(Comp
) loop
5390 Check_Component_Storage_Order
5394 Comp_ADC_Present
=> Comp_ADC_Present
);
5395 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
5396 Next_Component
(Comp
);
5400 -- Now deal with reverse storage order/bit order issues
5402 if Present
(SSO_ADC
) then
5404 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
5405 -- if the former is specified.
5407 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
5409 -- Note: report error on Rec, not on SSO_ADC, as ADC may
5410 -- apply to some ancestor type.
5412 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
5414 ("scalar storage order for& specified# inconsistent with "
5415 & "bit order", Rec
);
5418 -- Warn if there is a Scalar_Storage_Order attribute definition
5419 -- clause but no component clause, no component that itself has
5420 -- such an attribute definition, and no pragma Pack.
5422 if not (Placed_Component
5429 ("??scalar storage order specified but no component "
5430 & "clause", SSO_ADC
);
5435 -- Deal with Bit_Order aspect
5437 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
5439 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
5440 if not (Placed_Component
5441 or else Present
(SSO_ADC
)
5442 or else Is_Packed
(Rec
))
5444 -- Warn if clause has no effect when no component clause is
5445 -- present, but suppress warning if the Bit_Order is required
5446 -- due to the presence of a Scalar_Storage_Order attribute.
5449 ("??bit order specification has no effect", ADC
);
5451 ("\??since no component clauses were specified", ADC
);
5453 -- Here is where we do the processing to adjust component clauses
5454 -- for reversed bit order, when not using reverse SSO. If an error
5455 -- has been reported on Rec already (such as SSO incompatible with
5456 -- bit order), don't bother adjusting as this may generate extra
5459 elsif Reverse_Bit_Order
(Rec
)
5460 and then not Reverse_Storage_Order
(Rec
)
5461 and then not Error_Posted
(Rec
)
5463 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
5465 -- Case where we have both an explicit Bit_Order and the same
5466 -- Scalar_Storage_Order: leave record untouched, the back-end
5467 -- will take care of required layout conversions.
5475 -- Check for useless pragma Pack when all components placed. We only
5476 -- do this check for record types, not subtypes, since a subtype may
5477 -- have all its components placed, and it still makes perfectly good
5478 -- sense to pack other subtypes or the parent type. We do not give
5479 -- this warning if Optimize_Alignment is set to Space, since the
5480 -- pragma Pack does have an effect in this case (it always resets
5481 -- the alignment to one).
5483 if Ekind
(Rec
) = E_Record_Type
5484 and then Is_Packed
(Rec
)
5485 and then not Unplaced_Component
5486 and then Optimize_Alignment
/= 'S'
5488 -- Reset packed status. Probably not necessary, but we do it so
5489 -- that there is no chance of the back end doing something strange
5490 -- with this redundant indication of packing.
5492 Set_Is_Packed
(Rec
, False);
5494 -- Give warning if redundant constructs warnings on
5496 if Warn_On_Redundant_Constructs
then
5497 Error_Msg_N
-- CODEFIX
5498 ("??pragma Pack has no effect, no unplaced components",
5499 Get_Rep_Pragma
(Rec
, Name_Pack
));
5503 -- If this is the record corresponding to a remote type, freeze the
5504 -- remote type here since that is what we are semantically freezing.
5505 -- This prevents the freeze node for that type in an inner scope.
5507 if Ekind
(Rec
) = E_Record_Type
then
5508 if Present
(Corresponding_Remote_Type
(Rec
)) then
5509 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
5512 -- Check for controlled components, unchecked unions, and type
5515 Comp
:= First_Component
(Rec
);
5516 while Present
(Comp
) loop
5518 -- Do not set Has_Controlled_Component on a class-wide
5519 -- equivalent type. See Make_CW_Equivalent_Type.
5521 if not Is_Class_Wide_Equivalent_Type
(Rec
)
5523 (Has_Controlled_Component
(Etype
(Comp
))
5525 (Chars
(Comp
) /= Name_uParent
5526 and then Is_Controlled
(Etype
(Comp
)))
5528 (Is_Protected_Type
(Etype
(Comp
))
5530 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
5532 Has_Controlled_Component
5533 (Corresponding_Record_Type
(Etype
(Comp
)))))
5535 Set_Has_Controlled_Component
(Rec
);
5538 if Has_Unchecked_Union
(Etype
(Comp
)) then
5539 Set_Has_Unchecked_Union
(Rec
);
5542 -- The record type requires its own invariant procedure in
5543 -- order to verify the invariant of each individual component.
5544 -- Do not consider internal components such as _parent because
5545 -- parent class-wide invariants are always inherited.
5546 -- In GNATprove mode, the component invariants are checked by
5547 -- other means. They should not be added to the record type
5548 -- invariant procedure, so that the procedure can be used to
5549 -- check the recordy type invariants if any.
5551 if Comes_From_Source
(Comp
)
5552 and then Has_Invariants
(Etype
(Comp
))
5553 and then not GNATprove_Mode
5555 Set_Has_Own_Invariants
(Rec
);
5558 -- Scan component declaration for likely misuses of current
5559 -- instance, either in a constraint or a default expression.
5561 if Has_Per_Object_Constraint
(Comp
) then
5562 Check_Current_Instance
(Parent
(Comp
));
5565 Next_Component
(Comp
);
5569 -- Enforce the restriction that access attributes with a current
5570 -- instance prefix can only apply to limited types. This comment
5571 -- is floating here, but does not seem to belong here???
5573 -- Set component alignment if not otherwise already set
5575 Set_Component_Alignment_If_Not_Set
(Rec
);
5577 -- For first subtypes, check if there are any fixed-point fields with
5578 -- component clauses, where we must check the size. This is not done
5579 -- till the freeze point since for fixed-point types, we do not know
5580 -- the size until the type is frozen. Similar processing applies to
5581 -- bit-packed arrays.
5583 if Is_First_Subtype
(Rec
) then
5584 Comp
:= First_Component
(Rec
);
5585 while Present
(Comp
) loop
5586 if Present
(Component_Clause
(Comp
))
5587 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
5588 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
5591 (Component_Name
(Component_Clause
(Comp
)),
5597 Next_Component
(Comp
);
5601 -- See if Size is too small as is (and implicit packing might help)
5603 if not Is_Packed
(Rec
)
5605 -- No implicit packing if even one component is explicitly placed
5607 and then not Placed_Component
5609 -- Or even one component is aliased
5611 and then not Aliased_Component
5613 -- Must have size clause and all sized components
5615 and then Has_Size_Clause
(Rec
)
5616 and then All_Sized_Components
5618 -- Do not try implicit packing on records with discriminants, too
5619 -- complicated, especially in the variant record case.
5621 and then not Has_Discriminants
(Rec
)
5623 -- We want to implicitly pack if the specified size of the record
5624 -- is less than the sum of the object sizes (no point in packing
5625 -- if this is not the case), if we can compute it, i.e. if we have
5626 -- only elementary components. Otherwise, we have at least one
5627 -- composite component and we want to implicitly pack only if bit
5628 -- packing is required for it, as we are sure in this case that
5629 -- the back end cannot do the expected layout without packing.
5632 ((All_Elem_Components
5633 and then RM_Size
(Rec
) < Elem_Component_Total_Esize
)
5635 (not All_Elem_Components
5636 and then not All_Storage_Unit_Components
5637 and then RM_Size
(Rec
) < Sized_Component_Total_Round_RM_Size
))
5639 -- And the total RM size cannot be greater than the specified size
5640 -- since otherwise packing will not get us where we have to be.
5642 and then Sized_Component_Total_RM_Size
<= RM_Size
(Rec
)
5644 -- Never do implicit packing in CodePeer or SPARK modes since
5645 -- we don't do any packing in these modes, since this generates
5646 -- over-complex code that confuses static analysis, and in
5647 -- general, neither CodePeer not GNATprove care about the
5648 -- internal representation of objects.
5650 and then not (CodePeer_Mode
or GNATprove_Mode
)
5652 -- If implicit packing enabled, do it
5654 if Implicit_Packing
then
5655 Set_Is_Packed
(Rec
);
5657 -- Otherwise flag the size clause
5661 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
5663 Error_Msg_NE
-- CODEFIX
5664 ("size given for& too small", Sz
, Rec
);
5665 Error_Msg_N
-- CODEFIX
5666 ("\use explicit pragma Pack "
5667 & "or use pragma Implicit_Packing", Sz
);
5672 -- The following checks are relevant only when SPARK_Mode is on as
5673 -- they are not standard Ada legality rules.
5675 if SPARK_Mode
= On
then
5677 -- A discriminated type cannot be effectively volatile
5678 -- (SPARK RM 7.1.3(5)).
5680 if Is_Effectively_Volatile
(Rec
) then
5681 if Has_Discriminants
(Rec
) then
5682 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
5685 -- A non-effectively volatile record type cannot contain
5686 -- effectively volatile components (SPARK RM 7.1.3(6)).
5689 Comp
:= First_Component
(Rec
);
5690 while Present
(Comp
) loop
5691 if Comes_From_Source
(Comp
)
5692 and then Is_Effectively_Volatile
(Etype
(Comp
))
5694 Error_Msg_Name_1
:= Chars
(Rec
);
5696 ("component & of non-volatile type % cannot be "
5697 & "volatile", Comp
);
5700 Next_Component
(Comp
);
5704 -- A type which does not yield a synchronized object cannot have
5705 -- a component that yields a synchronized object (SPARK RM 9.5).
5707 if not Yields_Synchronized_Object
(Rec
) then
5708 Comp
:= First_Component
(Rec
);
5709 while Present
(Comp
) loop
5710 if Comes_From_Source
(Comp
)
5711 and then Yields_Synchronized_Object
(Etype
(Comp
))
5713 Error_Msg_Name_1
:= Chars
(Rec
);
5715 ("component & of non-synchronized type % cannot be "
5716 & "synchronized", Comp
);
5719 Next_Component
(Comp
);
5723 -- A Ghost type cannot have a component of protected or task type
5724 -- (SPARK RM 6.9(19)).
5726 if Is_Ghost_Entity
(Rec
) then
5727 Comp
:= First_Component
(Rec
);
5728 while Present
(Comp
) loop
5729 if Comes_From_Source
(Comp
)
5730 and then Is_Concurrent_Type
(Etype
(Comp
))
5732 Error_Msg_Name_1
:= Chars
(Rec
);
5734 ("component & of ghost type % cannot be concurrent",
5738 Next_Component
(Comp
);
5743 -- Make sure that if we have an iterator aspect, then we have
5744 -- either Constant_Indexing or Variable_Indexing.
5747 Iterator_Aspect
: Node_Id
;
5750 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
5752 if No
(Iterator_Aspect
) then
5753 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
5756 if Present
(Iterator_Aspect
) then
5757 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
5759 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
5764 ("Iterator_Element requires indexing aspect",
5770 -- All done if not a full record definition
5772 if Ekind
(Rec
) /= E_Record_Type
then
5776 -- Finally we need to check the variant part to make sure that
5777 -- all types within choices are properly frozen as part of the
5778 -- freezing of the record type.
5780 Check_Variant_Part
: declare
5781 D
: constant Node_Id
:= Declaration_Node
(Rec
);
5786 -- Find component list
5790 if Nkind
(D
) = N_Full_Type_Declaration
then
5791 T
:= Type_Definition
(D
);
5793 if Nkind
(T
) = N_Record_Definition
then
5794 C
:= Component_List
(T
);
5796 elsif Nkind
(T
) = N_Derived_Type_Definition
5797 and then Present
(Record_Extension_Part
(T
))
5799 C
:= Component_List
(Record_Extension_Part
(T
));
5803 -- Case of variant part present
5805 if Present
(C
) and then Present
(Variant_Part
(C
)) then
5806 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
5809 -- Note: we used to call Check_Choices here, but it is too early,
5810 -- since predicated subtypes are frozen here, but their freezing
5811 -- actions are in Analyze_Freeze_Entity, which has not been called
5812 -- yet for entities frozen within this procedure, so we moved that
5813 -- call to the Analyze_Freeze_Entity for the record type.
5815 end Check_Variant_Part
;
5817 -- Check that all the primitives of an interface type are abstract
5818 -- or null procedures.
5820 if Is_Interface
(Rec
)
5821 and then not Error_Posted
(Parent
(Rec
))
5828 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
5829 while Present
(Elmt
) loop
5830 Subp
:= Node
(Elmt
);
5832 if not Is_Abstract_Subprogram
(Subp
)
5834 -- Avoid reporting the error on inherited primitives
5836 and then Comes_From_Source
(Subp
)
5838 Error_Msg_Name_1
:= Chars
(Subp
);
5840 if Ekind
(Subp
) = E_Procedure
then
5841 if not Null_Present
(Parent
(Subp
)) then
5843 ("interface procedure % must be abstract or null",
5848 ("interface function % must be abstract",
5858 -- For a derived tagged type, check whether inherited primitives
5859 -- might require a wrapper to handle class-wide conditions.
5861 if Is_Tagged_Type
(Rec
) and then Is_Derived_Type
(Rec
) then
5862 Check_Inherited_Conditions
(Rec
);
5864 end Freeze_Record_Type
;
5866 -------------------------------
5867 -- Has_Boolean_Aspect_Import --
5868 -------------------------------
5870 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
5871 Decl
: constant Node_Id
:= Declaration_Node
(E
);
5876 if Has_Aspects
(Decl
) then
5877 Asp
:= First
(Aspect_Specifications
(Decl
));
5878 while Present
(Asp
) loop
5879 Expr
:= Expression
(Asp
);
5881 -- The value of aspect Import is True when the expression is
5882 -- either missing or it is explicitly set to True.
5884 if Get_Aspect_Id
(Asp
) = Aspect_Import
5886 or else (Compile_Time_Known_Value
(Expr
)
5887 and then Is_True
(Expr_Value
(Expr
))))
5897 end Has_Boolean_Aspect_Import
;
5899 -------------------------
5900 -- Inherit_Freeze_Node --
5901 -------------------------
5903 procedure Inherit_Freeze_Node
5907 Typ_Fnod
: constant Node_Id
:= Freeze_Node
(Typ
);
5910 Set_Freeze_Node
(Typ
, Fnod
);
5911 Set_Entity
(Fnod
, Typ
);
5913 -- The input type had an existing node. Propagate relevant attributes
5914 -- from the old freeze node to the inherited freeze node.
5916 -- ??? if both freeze nodes have attributes, would they differ?
5918 if Present
(Typ_Fnod
) then
5920 -- Attribute Access_Types_To_Process
5922 if Present
(Access_Types_To_Process
(Typ_Fnod
))
5923 and then No
(Access_Types_To_Process
(Fnod
))
5925 Set_Access_Types_To_Process
(Fnod
,
5926 Access_Types_To_Process
(Typ_Fnod
));
5929 -- Attribute Actions
5931 if Present
(Actions
(Typ_Fnod
)) and then No
(Actions
(Fnod
)) then
5932 Set_Actions
(Fnod
, Actions
(Typ_Fnod
));
5935 -- Attribute First_Subtype_Link
5937 if Present
(First_Subtype_Link
(Typ_Fnod
))
5938 and then No
(First_Subtype_Link
(Fnod
))
5940 Set_First_Subtype_Link
(Fnod
, First_Subtype_Link
(Typ_Fnod
));
5943 -- Attribute TSS_Elist
5945 if Present
(TSS_Elist
(Typ_Fnod
))
5946 and then No
(TSS_Elist
(Fnod
))
5948 Set_TSS_Elist
(Fnod
, TSS_Elist
(Typ_Fnod
));
5951 end Inherit_Freeze_Node
;
5953 ------------------------------
5954 -- Wrap_Imported_Subprogram --
5955 ------------------------------
5957 -- The issue here is that our normal approach of checking preconditions
5958 -- and postconditions does not work for imported procedures, since we
5959 -- are not generating code for the body. To get around this we create
5960 -- a wrapper, as shown by the following example:
5962 -- procedure K (A : Integer);
5963 -- pragma Import (C, K);
5965 -- The spec is rewritten by removing the effects of pragma Import, but
5966 -- leaving the convention unchanged, as though the source had said:
5968 -- procedure K (A : Integer);
5969 -- pragma Convention (C, K);
5971 -- and we create a body, added to the entity K freeze actions, which
5974 -- procedure K (A : Integer) is
5975 -- procedure K (A : Integer);
5976 -- pragma Import (C, K);
5981 -- Now the contract applies in the normal way to the outer procedure,
5982 -- and the inner procedure has no contracts, so there is no problem
5983 -- in just calling it to get the original effect.
5985 -- In the case of a function, we create an appropriate return statement
5986 -- for the subprogram body that calls the inner procedure.
5988 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
5989 function Copy_Import_Pragma
return Node_Id
;
5990 -- Obtain a copy of the Import_Pragma which belongs to subprogram E
5992 ------------------------
5993 -- Copy_Import_Pragma --
5994 ------------------------
5996 function Copy_Import_Pragma
return Node_Id
is
5998 -- The subprogram should have an import pragma, otherwise it does
6001 Prag
: constant Node_Id
:= Import_Pragma
(E
);
6002 pragma Assert
(Present
(Prag
));
6004 -- Save all semantic fields of the pragma
6006 Save_Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
6007 Save_From
: constant Boolean := From_Aspect_Specification
(Prag
);
6008 Save_Prag
: constant Node_Id
:= Next_Pragma
(Prag
);
6009 Save_Rep
: constant Node_Id
:= Next_Rep_Item
(Prag
);
6014 -- Reset all semantic fields. This avoids a potential infinite
6015 -- loop when the pragma comes from an aspect as the duplication
6016 -- will copy the aspect, then copy the corresponding pragma and
6019 Set_Corresponding_Aspect
(Prag
, Empty
);
6020 Set_From_Aspect_Specification
(Prag
, False);
6021 Set_Next_Pragma
(Prag
, Empty
);
6022 Set_Next_Rep_Item
(Prag
, Empty
);
6024 Result
:= Copy_Separate_Tree
(Prag
);
6026 -- Restore the original semantic fields
6028 Set_Corresponding_Aspect
(Prag
, Save_Asp
);
6029 Set_From_Aspect_Specification
(Prag
, Save_From
);
6030 Set_Next_Pragma
(Prag
, Save_Prag
);
6031 Set_Next_Rep_Item
(Prag
, Save_Rep
);
6034 end Copy_Import_Pragma
;
6038 Loc
: constant Source_Ptr
:= Sloc
(E
);
6039 CE
: constant Name_Id
:= Chars
(E
);
6047 -- Start of processing for Wrap_Imported_Subprogram
6050 -- Nothing to do if not imported
6052 if not Is_Imported
(E
) then
6055 -- Test enabling conditions for wrapping
6057 elsif Is_Subprogram
(E
)
6058 and then Present
(Contract
(E
))
6059 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
6060 and then not GNATprove_Mode
6062 -- Here we do the wrap
6064 -- Note on calls to Copy_Separate_Tree. The trees we are copying
6065 -- here are fully analyzed, but we definitely want fully syntactic
6066 -- unanalyzed trees in the body we construct, so that the analysis
6067 -- generates the right visibility, and that is exactly what the
6068 -- calls to Copy_Separate_Tree give us.
6070 Prag
:= Copy_Import_Pragma
;
6072 -- Fix up spec so it is no longer imported and has convention Ada
6074 Set_Has_Completion
(E
, False);
6075 Set_Import_Pragma
(E
, Empty
);
6076 Set_Interface_Name
(E
, Empty
);
6077 Set_Is_Imported
(E
, False);
6078 Set_Convention
(E
, Convention_Ada
);
6080 -- Grab the subprogram declaration and specification
6082 Spec
:= Declaration_Node
(E
);
6084 -- Build parameter list that we need
6087 Forml
:= First_Formal
(E
);
6088 while Present
(Forml
) loop
6089 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
6090 Next_Formal
(Forml
);
6095 -- An imported function whose result type is anonymous access
6096 -- creates a new anonymous access type when it is relocated into
6097 -- the declarations of the body generated below. As a result, the
6098 -- accessibility level of these two anonymous access types may not
6099 -- be compatible even though they are essentially the same type.
6100 -- Use an unchecked type conversion to reconcile this case. Note
6101 -- that the conversion is safe because in the named access type
6102 -- case, both the body and imported function utilize the same
6105 if Ekind
(E
) in E_Function | E_Generic_Function
then
6107 Make_Simple_Return_Statement
(Loc
,
6109 Unchecked_Convert_To
(Etype
(E
),
6110 Make_Function_Call
(Loc
,
6111 Name
=> Make_Identifier
(Loc
, CE
),
6112 Parameter_Associations
=> Parms
)));
6116 Make_Procedure_Call_Statement
(Loc
,
6117 Name
=> Make_Identifier
(Loc
, CE
),
6118 Parameter_Associations
=> Parms
);
6121 -- Now build the body
6124 Make_Subprogram_Body
(Loc
,
6126 Copy_Separate_Tree
(Spec
),
6127 Declarations
=> New_List
(
6128 Make_Subprogram_Declaration
(Loc
,
6129 Specification
=> Copy_Separate_Tree
(Spec
)),
6131 Handled_Statement_Sequence
=>
6132 Make_Handled_Sequence_Of_Statements
(Loc
,
6133 Statements
=> New_List
(Stmt
),
6134 End_Label
=> Make_Identifier
(Loc
, CE
)));
6136 -- Append the body to freeze result
6138 Add_To_Result
(Bod
);
6141 -- Case of imported subprogram that does not get wrapped
6144 -- Set Is_Public. All imported entities need an external symbol
6145 -- created for them since they are always referenced from another
6146 -- object file. Note this used to be set when we set Is_Imported
6147 -- back in Sem_Prag, but now we delay it to this point, since we
6148 -- don't want to set this flag if we wrap an imported subprogram.
6152 end Wrap_Imported_Subprogram
;
6154 -- Start of processing for Freeze_Entity
6157 -- The entity being frozen may be subject to pragma Ghost. Set the mode
6158 -- now to ensure that any nodes generated during freezing are properly
6159 -- flagged as Ghost.
6163 -- We are going to test for various reasons why this entity need not be
6164 -- frozen here, but in the case of an Itype that's defined within a
6165 -- record, that test actually applies to the record.
6167 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
6168 Test_E
:= Scope
(E
);
6170 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
6171 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
6173 Test_E
:= Underlying_Type
(Scope
(E
));
6176 -- Do not freeze if already frozen since we only need one freeze node
6178 if Is_Frozen
(E
) then
6182 -- Do not freeze if we are preanalyzing without freezing
6184 elsif Inside_Preanalysis_Without_Freezing
> 0 then
6188 elsif Ekind
(E
) = E_Generic_Package
then
6189 Result
:= Freeze_Generic_Entities
(E
);
6192 -- It is improper to freeze an external entity within a generic because
6193 -- its freeze node will appear in a non-valid context. The entity will
6194 -- be frozen in the proper scope after the current generic is analyzed.
6195 -- However, aspects must be analyzed because they may be queried later
6196 -- within the generic itself, and the corresponding pragma or attribute
6197 -- definition has not been analyzed yet. After this, indicate that the
6198 -- entity has no further delayed aspects, to prevent a later aspect
6199 -- analysis out of the scope of the generic.
6201 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
6202 if Has_Delayed_Aspects
(E
) then
6203 Analyze_Aspects_At_Freeze_Point
(E
);
6204 Set_Has_Delayed_Aspects
(E
, False);
6210 -- AI05-0213: A formal incomplete type does not freeze the actual. In
6211 -- the instance, the same applies to the subtype renaming the actual.
6213 elsif Is_Private_Type
(E
)
6214 and then Is_Generic_Actual_Type
(E
)
6215 and then No
(Full_View
(Base_Type
(E
)))
6216 and then Ada_Version
>= Ada_2012
6221 -- Formal subprograms are never frozen
6223 elsif Is_Formal_Subprogram
(E
) then
6227 -- Generic types are never frozen as they lack delayed semantic checks
6229 elsif Is_Generic_Type
(E
) then
6233 -- Do not freeze a global entity within an inner scope created during
6234 -- expansion. A call to subprogram E within some internal procedure
6235 -- (a stream attribute for example) might require freezing E, but the
6236 -- freeze node must appear in the same declarative part as E itself.
6237 -- The two-pass elaboration mechanism in gigi guarantees that E will
6238 -- be frozen before the inner call is elaborated. We exclude constants
6239 -- from this test, because deferred constants may be frozen early, and
6240 -- must be diagnosed (e.g. in the case of a deferred constant being used
6241 -- in a default expression). If the enclosing subprogram comes from
6242 -- source, or is a generic instance, then the freeze point is the one
6243 -- mandated by the language, and we freeze the entity. A subprogram that
6244 -- is a child unit body that acts as a spec does not have a spec that
6245 -- comes from source, but can only come from source.
6247 elsif In_Open_Scopes
(Scope
(Test_E
))
6248 and then Scope
(Test_E
) /= Current_Scope
6249 and then Ekind
(Test_E
) /= E_Constant
6256 while Present
(S
) loop
6257 if Is_Overloadable
(S
) then
6258 if Comes_From_Source
(S
)
6259 or else Is_Generic_Instance
(S
)
6260 or else Is_Child_Unit
(S
)
6273 -- Similarly, an inlined instance body may make reference to global
6274 -- entities, but these references cannot be the proper freezing point
6275 -- for them, and in the absence of inlining freezing will take place in
6276 -- their own scope. Normally instance bodies are analyzed after the
6277 -- enclosing compilation, and everything has been frozen at the proper
6278 -- place, but with front-end inlining an instance body is compiled
6279 -- before the end of the enclosing scope, and as a result out-of-order
6280 -- freezing must be prevented.
6282 elsif Front_End_Inlining
6283 and then In_Instance_Body
6284 and then Present
(Scope
(Test_E
))
6290 S
:= Scope
(Test_E
);
6291 while Present
(S
) loop
6292 if Is_Generic_Instance
(S
) then
6306 -- Add checks to detect proper initialization of scalars that may appear
6307 -- as subprogram parameters.
6309 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
6310 Apply_Parameter_Validity_Checks
(E
);
6313 -- Deal with delayed aspect specifications. The analysis of the aspect
6314 -- is required to be delayed to the freeze point, thus we analyze the
6315 -- pragma or attribute definition clause in the tree at this point. We
6316 -- also analyze the aspect specification node at the freeze point when
6317 -- the aspect doesn't correspond to pragma/attribute definition clause.
6318 -- In addition, a derived type may have inherited aspects that were
6319 -- delayed in the parent, so these must also be captured now.
6321 -- For a record type, we deal with the delayed aspect specifications on
6322 -- components first, which is consistent with the non-delayed case and
6323 -- makes it possible to have a single processing to detect conflicts.
6325 if Is_Record_Type
(E
) then
6329 Rec_Pushed
: Boolean := False;
6330 -- Set True if the record type E has been pushed on the scope
6331 -- stack. Needed for the analysis of delayed aspects specified
6332 -- to the components of Rec.
6335 Comp
:= First_Component
(E
);
6336 while Present
(Comp
) loop
6337 if Has_Delayed_Aspects
(Comp
) then
6338 if not Rec_Pushed
then
6342 -- The visibility to the discriminants must be restored
6343 -- in order to properly analyze the aspects.
6345 if Has_Discriminants
(E
) then
6346 Install_Discriminants
(E
);
6350 Analyze_Aspects_At_Freeze_Point
(Comp
);
6353 Next_Component
(Comp
);
6356 -- Pop the scope if Rec scope has been pushed on the scope stack
6357 -- during the delayed aspect analysis process.
6360 if Has_Discriminants
(E
) then
6361 Uninstall_Discriminants
(E
);
6369 if Has_Delayed_Aspects
(E
)
6370 or else May_Inherit_Delayed_Rep_Aspects
(E
)
6372 Analyze_Aspects_At_Freeze_Point
(E
);
6375 -- Here to freeze the entity
6379 -- Case of entity being frozen is other than a type
6381 if not Is_Type
(E
) then
6383 -- If entity is exported or imported and does not have an external
6384 -- name, now is the time to provide the appropriate default name.
6385 -- Skip this if the entity is stubbed, since we don't need a name
6386 -- for any stubbed routine. For the case on intrinsics, if no
6387 -- external name is specified, then calls will be handled in
6388 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
6389 -- external name is provided, then Expand_Intrinsic_Call leaves
6390 -- calls in place for expansion by GIGI.
6392 if (Is_Imported
(E
) or else Is_Exported
(E
))
6393 and then No
(Interface_Name
(E
))
6394 and then Convention
(E
) /= Convention_Stubbed
6395 and then Convention
(E
) /= Convention_Intrinsic
6397 Set_Encoded_Interface_Name
6398 (E
, Get_Default_External_Name
(E
));
6403 if Is_Subprogram
(E
) then
6405 -- Check for needing to wrap imported subprogram
6407 Wrap_Imported_Subprogram
(E
);
6409 -- Freeze all parameter types and the return type (RM 13.14(14)).
6410 -- However skip this for internal subprograms. This is also where
6411 -- any extra formal parameters are created since we now know
6412 -- whether the subprogram will use a foreign convention.
6414 -- In Ada 2012, freezing a subprogram does not always freeze the
6415 -- corresponding profile (see AI05-019). An attribute reference
6416 -- is not a freezing point of the profile. Similarly, we do not
6417 -- freeze the profile of primitives of a library-level tagged type
6418 -- when we are building its dispatch table. Flag Do_Freeze_Profile
6419 -- indicates whether the profile should be frozen now.
6421 -- This processing doesn't apply to internal entities (see below)
6423 if not Is_Internal
(E
) and then Do_Freeze_Profile
then
6424 if not Freeze_Profile
(E
) then
6429 -- Must freeze its parent first if it is a derived subprogram
6431 if Present
(Alias
(E
)) then
6432 Freeze_And_Append
(Alias
(E
), N
, Result
);
6435 -- We don't freeze internal subprograms, because we don't normally
6436 -- want addition of extra formals or mechanism setting to happen
6437 -- for those. However we do pass through predefined dispatching
6438 -- cases, since extra formals may be needed in some cases, such as
6439 -- for the stream 'Input function (build-in-place formals).
6441 if not Is_Internal
(E
)
6442 or else Is_Predefined_Dispatching_Operation
(E
)
6444 Freeze_Subprogram
(E
);
6447 -- If warning on suspicious contracts then check for the case of
6448 -- a postcondition other than False for a No_Return subprogram.
6451 and then Warn_On_Suspicious_Contract
6452 and then Present
(Contract
(E
))
6455 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
6459 while Present
(Prag
) loop
6460 if Pragma_Name_Unmapped
(Prag
) in Name_Post
6461 | Name_Postcondition
6466 (First
(Pragma_Argument_Associations
(Prag
)));
6468 if Nkind
(Exp
) /= N_Identifier
6469 or else Chars
(Exp
) /= Name_False
6472 ("useless postcondition, & is marked "
6473 & "No_Return?.t?", Exp
, E
);
6477 Prag
:= Next_Pragma
(Prag
);
6482 -- Here for other than a subprogram or type
6485 -- If entity has a type declared in the current scope, and it is
6486 -- not a generic unit, then freeze it first.
6488 if Present
(Etype
(E
))
6489 and then Ekind
(E
) /= E_Generic_Function
6490 and then Within_Scope
(Etype
(E
), Current_Scope
)
6492 Freeze_And_Append
(Etype
(E
), N
, Result
);
6494 -- For an object of an anonymous array type, aspects on the
6495 -- object declaration apply to the type itself. This is the
6496 -- case for Atomic_Components, Volatile_Components, and
6497 -- Independent_Components. In these cases analysis of the
6498 -- generated pragma will mark the anonymous types accordingly,
6499 -- and the object itself does not require a freeze node.
6501 if Ekind
(E
) = E_Variable
6502 and then Is_Itype
(Etype
(E
))
6503 and then Is_Array_Type
(Etype
(E
))
6504 and then Has_Delayed_Aspects
(E
)
6506 Set_Has_Delayed_Aspects
(E
, False);
6507 Set_Has_Delayed_Freeze
(E
, False);
6508 Set_Freeze_Node
(E
, Empty
);
6512 -- Special processing for objects created by object declaration;
6513 -- we protect the call to Declaration_Node against entities of
6514 -- expressions replaced by the frontend with an N_Raise_CE node.
6516 if Ekind
(E
) in E_Constant | E_Variable
6517 and then Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
6519 Freeze_Object_Declaration
(E
);
6522 -- Check that a constant which has a pragma Volatile[_Components]
6523 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
6525 -- Note: Atomic[_Components] also sets Volatile[_Components]
6527 if Ekind
(E
) = E_Constant
6528 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
6529 and then not Is_Imported
(E
)
6530 and then not Has_Boolean_Aspect_Import
(E
)
6532 -- Make sure we actually have a pragma, and have not merely
6533 -- inherited the indication from elsewhere (e.g. an address
6534 -- clause, which is not good enough in RM terms).
6536 if Has_Rep_Pragma
(E
, Name_Atomic
)
6538 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
6541 ("standalone atomic constant must be " &
6542 "imported (RM C.6(13))", E
);
6544 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
6546 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
6549 ("standalone volatile constant must be " &
6550 "imported (RM C.6(13))", E
);
6554 -- Static objects require special handling
6556 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
6557 and then Is_Statically_Allocated
(E
)
6559 Freeze_Static_Object
(E
);
6562 -- Remaining step is to layout objects
6564 if Ekind
(E
) in E_Variable | E_Constant | E_Loop_Parameter
6565 or else Is_Formal
(E
)
6570 -- For an object that does not have delayed freezing, and whose
6571 -- initialization actions have been captured in a compound
6572 -- statement, move them back now directly within the enclosing
6573 -- statement sequence.
6575 if Ekind
(E
) in E_Constant | E_Variable
6576 and then not Has_Delayed_Freeze
(E
)
6578 Explode_Initialization_Compound_Statement
(E
);
6581 -- Do not generate a freeze node for a generic unit
6583 if Is_Generic_Unit
(E
) then
6589 -- Case of a type or subtype being frozen
6592 -- Verify several SPARK legality rules related to Ghost types now
6593 -- that the type is frozen.
6595 Check_Ghost_Type
(E
);
6597 -- We used to check here that a full type must have preelaborable
6598 -- initialization if it completes a private type specified with
6599 -- pragma Preelaborable_Initialization, but that missed cases where
6600 -- the types occur within a generic package, since the freezing
6601 -- that occurs within a containing scope generally skips traversal
6602 -- of a generic unit's declarations (those will be frozen within
6603 -- instances). This check was moved to Analyze_Package_Specification.
6605 -- The type may be defined in a generic unit. This can occur when
6606 -- freezing a generic function that returns the type (which is
6607 -- defined in a parent unit). It is clearly meaningless to freeze
6608 -- this type. However, if it is a subtype, its size may be determi-
6609 -- nable and used in subsequent checks, so might as well try to
6612 -- In Ada 2012, Freeze_Entities is also used in the front end to
6613 -- trigger the analysis of aspect expressions, so in this case we
6614 -- want to continue the freezing process.
6616 -- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead
6617 -- In_Generic_Scope (E)???
6619 if Present
(Scope
(E
))
6620 and then Is_Generic_Unit
(Scope
(E
))
6622 (not Has_Predicates
(E
)
6623 and then not Has_Delayed_Freeze
(E
))
6625 Check_Compile_Time_Size
(E
);
6630 -- Check for error of Type_Invariant'Class applied to an untagged
6631 -- type (check delayed to freeze time when full type is available).
6634 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
6637 and then Class_Present
(Prag
)
6638 and then not Is_Tagged_Type
(E
)
6641 ("Type_Invariant''Class cannot be specified for &", Prag
, E
);
6643 ("\can only be specified for a tagged type", Prag
);
6647 -- Deal with special cases of freezing for subtype
6649 if E
/= Base_Type
(E
) then
6651 -- Before we do anything else, a specific test for the case of a
6652 -- size given for an array where the array would need to be packed
6653 -- in order for the size to be honored, but is not. This is the
6654 -- case where implicit packing may apply. The reason we do this so
6655 -- early is that, if we have implicit packing, the layout of the
6656 -- base type is affected, so we must do this before we freeze the
6659 -- We could do this processing only if implicit packing is enabled
6660 -- since in all other cases, the error would be caught by the back
6661 -- end. However, we choose to do the check even if we do not have
6662 -- implicit packing enabled, since this allows us to give a more
6663 -- useful error message (advising use of pragma Implicit_Packing
6666 if Is_Array_Type
(E
) then
6668 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
6669 Rsiz
: constant Uint
:=
6670 (if Known_RM_Size
(Ctyp
) then RM_Size
(Ctyp
) else Uint_0
);
6671 SZ
: constant Node_Id
:= Size_Clause
(E
);
6672 Btyp
: constant Entity_Id
:= Base_Type
(E
);
6679 Num_Elmts
: Uint
:= Uint_1
;
6680 -- Number of elements in array
6683 -- Check enabling conditions. These are straightforward
6684 -- except for the test for a limited composite type. This
6685 -- eliminates the rare case of a array of limited components
6686 -- where there are issues of whether or not we can go ahead
6687 -- and pack the array (since we can't freely pack and unpack
6688 -- arrays if they are limited).
6690 -- Note that we check the root type explicitly because the
6691 -- whole point is we are doing this test before we have had
6692 -- a chance to freeze the base type (and it is that freeze
6693 -- action that causes stuff to be inherited).
6695 -- The conditions on the size are identical to those used in
6696 -- Freeze_Array_Type to set the Is_Packed flag.
6698 if Has_Size_Clause
(E
)
6699 and then Known_Static_RM_Size
(E
)
6700 and then not Is_Packed
(E
)
6701 and then not Has_Pragma_Pack
(E
)
6702 and then not Has_Component_Size_Clause
(E
)
6703 and then Known_Static_RM_Size
(Ctyp
)
6704 and then Rsiz
<= System_Max_Integer_Size
6705 and then not (Addressable
(Rsiz
)
6706 and then Known_Static_Esize
(Ctyp
)
6707 and then Esize
(Ctyp
) = Rsiz
)
6708 and then not (Rsiz
mod System_Storage_Unit
= 0
6709 and then Is_Composite_Type
(Ctyp
))
6710 and then not Is_Limited_Composite
(E
)
6711 and then not Is_Packed
(Root_Type
(E
))
6712 and then not Has_Component_Size_Clause
(Root_Type
(E
))
6713 and then not (CodePeer_Mode
or GNATprove_Mode
)
6715 -- Compute number of elements in array
6717 Indx
:= First_Index
(E
);
6718 while Present
(Indx
) loop
6719 Get_Index_Bounds
(Indx
, Lo
, Hi
);
6721 if not (Compile_Time_Known_Value
(Lo
)
6723 Compile_Time_Known_Value
(Hi
))
6725 goto No_Implicit_Packing
;
6728 Dim
:= Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1;
6730 if Dim
> Uint_0
then
6731 Num_Elmts
:= Num_Elmts
* Dim
;
6733 Num_Elmts
:= Uint_0
;
6739 -- What we are looking for here is the situation where
6740 -- the RM_Size given would be exactly right if there was
6741 -- a pragma Pack, resulting in the component size being
6742 -- the RM_Size of the component type.
6744 if RM_Size
(E
) = Num_Elmts
* Rsiz
then
6746 -- For implicit packing mode, just set the component
6747 -- size and Freeze_Array_Type will do the rest.
6749 if Implicit_Packing
then
6750 Set_Component_Size
(Btyp
, Rsiz
);
6752 -- Otherwise give an error message, except that if the
6753 -- specified Size is zero, there is no need for pragma
6754 -- Pack. Note that size zero is not considered
6757 elsif RM_Size
(E
) /= Uint_0
then
6759 ("size given for& too small", SZ
, E
);
6760 Error_Msg_N
-- CODEFIX
6761 ("\use explicit pragma Pack or use pragma "
6762 & "Implicit_Packing", SZ
);
6769 <<No_Implicit_Packing
>>
6771 -- If ancestor subtype present, freeze that first. Note that this
6772 -- will also get the base type frozen. Need RM reference ???
6774 Atype
:= Ancestor_Subtype
(E
);
6776 if Present
(Atype
) then
6777 Freeze_And_Append
(Atype
, N
, Result
);
6779 -- No ancestor subtype present
6782 -- See if we have a nearest ancestor that has a predicate.
6783 -- That catches the case of derived type with a predicate.
6784 -- Need RM reference here ???
6786 Atype
:= Nearest_Ancestor
(E
);
6788 if Present
(Atype
) and then Has_Predicates
(Atype
) then
6789 Freeze_And_Append
(Atype
, N
, Result
);
6792 -- Freeze base type before freezing the entity (RM 13.14(15))
6794 if E
/= Base_Type
(E
) then
6795 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
6799 -- A subtype inherits all the type-related representation aspects
6800 -- from its parents (RM 13.1(8)).
6802 Inherit_Aspects_At_Freeze_Point
(E
);
6804 -- For a derived type, freeze its parent type first (RM 13.14(15))
6806 elsif Is_Derived_Type
(E
) then
6807 Freeze_And_Append
(Etype
(E
), N
, Result
);
6808 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
6810 -- A derived type inherits each type-related representation aspect
6811 -- of its parent type that was directly specified before the
6812 -- declaration of the derived type (RM 13.1(15)).
6814 Inherit_Aspects_At_Freeze_Point
(E
);
6817 -- Case of array type
6819 if Is_Array_Type
(E
) then
6820 Freeze_Array_Type
(E
);
6823 -- Check for incompatible size and alignment for array/record type
6825 if Warn_On_Size_Alignment
6826 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
6827 and then Has_Size_Clause
(E
)
6828 and then Has_Alignment_Clause
(E
)
6830 -- If explicit Object_Size clause given assume that the programmer
6831 -- knows what he is doing, and expects the compiler behavior.
6833 and then not Has_Object_Size_Clause
(E
)
6835 -- It does not really make sense to warn for the minimum alignment
6836 -- since the programmer could not get rid of the warning.
6838 and then Alignment
(E
) > 1
6840 -- Check for size not a multiple of alignment
6842 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
6845 SC
: constant Node_Id
:= Size_Clause
(E
);
6846 AC
: constant Node_Id
:= Alignment_Clause
(E
);
6848 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
6851 if Present
(SC
) and then Present
(AC
) then
6855 if Sloc
(SC
) > Sloc
(AC
) then
6858 ("?.z?size is not a multiple of alignment for &",
6860 Error_Msg_Sloc
:= Sloc
(AC
);
6861 Error_Msg_Uint_1
:= Alignment
(E
);
6862 Error_Msg_N
("\?.z?alignment of ^ specified #", Loc
);
6867 ("?.z?size is not a multiple of alignment for &",
6869 Error_Msg_Sloc
:= Sloc
(SC
);
6870 Error_Msg_Uint_1
:= RM_Size
(E
);
6871 Error_Msg_N
("\?.z?size of ^ specified #", Loc
);
6874 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
6875 Error_Msg_N
("\?.z?Object_Size will be increased to ^", Loc
);
6880 -- For a class-wide type, the corresponding specific type is
6881 -- frozen as well (RM 13.14(15))
6883 if Is_Class_Wide_Type
(E
) then
6884 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
6886 -- If the base type of the class-wide type is still incomplete,
6887 -- the class-wide remains unfrozen as well. This is legal when
6888 -- E is the formal of a primitive operation of some other type
6889 -- which is being frozen.
6891 if not Is_Frozen
(Root_Type
(E
)) then
6892 Set_Is_Frozen
(E
, False);
6896 -- The equivalent type associated with a class-wide subtype needs
6897 -- to be frozen to ensure that its layout is done.
6899 if Ekind
(E
) = E_Class_Wide_Subtype
6900 and then Present
(Equivalent_Type
(E
))
6902 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
6905 -- Generate an itype reference for a library-level class-wide type
6906 -- at the freeze point. Otherwise the first explicit reference to
6907 -- the type may appear in an inner scope which will be rejected by
6911 and then Is_Compilation_Unit
(Scope
(E
))
6914 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
6919 -- From a gigi point of view, a class-wide subtype derives
6920 -- from its record equivalent type. As a result, the itype
6921 -- reference must appear after the freeze node of the
6922 -- equivalent type or gigi will reject the reference.
6924 if Ekind
(E
) = E_Class_Wide_Subtype
6925 and then Present
(Equivalent_Type
(E
))
6927 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
6929 Add_To_Result
(Ref
);
6934 -- For a record type or record subtype, freeze all component types
6935 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
6936 -- using Is_Record_Type, because we don't want to attempt the freeze
6937 -- for the case of a private type with record extension (we will do
6938 -- that later when the full type is frozen).
6940 elsif Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
6941 if not In_Generic_Scope
(E
) then
6942 Freeze_Record_Type
(E
);
6945 -- Report a warning if a discriminated record base type has a
6946 -- convention with language C or C++ applied to it. This check is
6947 -- done even within generic scopes (but not in instantiations),
6948 -- which is why we don't do it as part of Freeze_Record_Type.
6950 Check_Suspicious_Convention
(E
);
6952 -- For a concurrent type, freeze corresponding record type. This does
6953 -- not correspond to any specific rule in the RM, but the record type
6954 -- is essentially part of the concurrent type. Also freeze all local
6955 -- entities. This includes record types created for entry parameter
6956 -- blocks and whatever local entities may appear in the private part.
6958 elsif Is_Concurrent_Type
(E
) then
6959 if Present
(Corresponding_Record_Type
(E
)) then
6960 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
6963 Comp
:= First_Entity
(E
);
6964 while Present
(Comp
) loop
6965 if Is_Type
(Comp
) then
6966 Freeze_And_Append
(Comp
, N
, Result
);
6968 elsif (Ekind
(Comp
)) /= E_Function
then
6970 -- The guard on the presence of the Etype seems to be needed
6971 -- for some CodePeer (-gnatcC) cases, but not clear why???
6973 if Present
(Etype
(Comp
)) then
6974 if Is_Itype
(Etype
(Comp
))
6975 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
6977 Undelay_Type
(Etype
(Comp
));
6980 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
6987 -- Private types are required to point to the same freeze node as
6988 -- their corresponding full views. The freeze node itself has to
6989 -- point to the partial view of the entity (because from the partial
6990 -- view, we can retrieve the full view, but not the reverse).
6991 -- However, in order to freeze correctly, we need to freeze the full
6992 -- view. If we are freezing at the end of a scope (or within the
6993 -- scope) of the private type, the partial and full views will have
6994 -- been swapped, the full view appears first in the entity chain and
6995 -- the swapping mechanism ensures that the pointers are properly set
6998 -- If we encounter the partial view before the full view (e.g. when
6999 -- freezing from another scope), we freeze the full view, and then
7000 -- set the pointers appropriately since we cannot rely on swapping to
7001 -- fix things up (subtypes in an outer scope might not get swapped).
7003 -- If the full view is itself private, the above requirements apply
7004 -- to the underlying full view instead of the full view. But there is
7005 -- no swapping mechanism for the underlying full view so we need to
7006 -- set the pointers appropriately in both cases.
7008 elsif Is_Incomplete_Or_Private_Type
(E
)
7009 and then not Is_Generic_Type
(E
)
7011 -- The construction of the dispatch table associated with library
7012 -- level tagged types forces freezing of all the primitives of the
7013 -- type, which may cause premature freezing of the partial view.
7017 -- type T is tagged private;
7018 -- type DT is new T with private;
7019 -- procedure Prim (X : in out T; Y : in out DT'Class);
7021 -- type T is tagged null record;
7023 -- type DT is new T with null record;
7026 -- In this case the type will be frozen later by the usual
7027 -- mechanism: an object declaration, an instantiation, or the
7028 -- end of a declarative part.
7030 if Is_Library_Level_Tagged_Type
(E
)
7031 and then not Present
(Full_View
(E
))
7033 Set_Is_Frozen
(E
, False);
7036 -- Case of full view present
7038 elsif Present
(Full_View
(E
)) then
7040 -- If full view has already been frozen, then no further
7041 -- processing is required
7043 if Is_Frozen
(Full_View
(E
)) then
7044 Set_Has_Delayed_Freeze
(E
, False);
7045 Set_Freeze_Node
(E
, Empty
);
7047 -- Otherwise freeze full view and patch the pointers so that
7048 -- the freeze node will elaborate both views in the back end.
7049 -- However, if full view is itself private, freeze underlying
7050 -- full view instead and patch the pointers so that the freeze
7051 -- node will elaborate the three views in the back end.
7055 Full
: Entity_Id
:= Full_View
(E
);
7058 if Is_Private_Type
(Full
)
7059 and then Present
(Underlying_Full_View
(Full
))
7061 Full
:= Underlying_Full_View
(Full
);
7064 Freeze_And_Append
(Full
, N
, Result
);
7066 if Full
/= Full_View
(E
)
7067 and then Has_Delayed_Freeze
(Full_View
(E
))
7069 F_Node
:= Freeze_Node
(Full
);
7071 if Present
(F_Node
) then
7073 (Fnod
=> F_Node
, Typ
=> Full_View
(E
));
7075 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
7076 Set_Freeze_Node
(Full_View
(E
), Empty
);
7080 if Has_Delayed_Freeze
(E
) then
7081 F_Node
:= Freeze_Node
(Full_View
(E
));
7083 if Present
(F_Node
) then
7084 Inherit_Freeze_Node
(Fnod
=> F_Node
, Typ
=> E
);
7086 -- {Incomplete,Private}_Subtypes with Full_Views
7087 -- constrained by discriminants.
7089 Set_Has_Delayed_Freeze
(E
, False);
7090 Set_Freeze_Node
(E
, Empty
);
7096 Check_Debug_Info_Needed
(E
);
7098 -- AI-117 requires that the convention of a partial view be the
7099 -- same as the convention of the full view. Note that this is a
7100 -- recognized breach of privacy, but it's essential for logical
7101 -- consistency of representation, and the lack of a rule in
7102 -- RM95 was an oversight.
7104 Set_Convention
(E
, Convention
(Full_View
(E
)));
7106 Set_Size_Known_At_Compile_Time
(E
,
7107 Size_Known_At_Compile_Time
(Full_View
(E
)));
7109 -- Size information is copied from the full view to the
7110 -- incomplete or private view for consistency.
7112 -- We skip this is the full view is not a type. This is very
7113 -- strange of course, and can only happen as a result of
7114 -- certain illegalities, such as a premature attempt to derive
7115 -- from an incomplete type.
7117 if Is_Type
(Full_View
(E
)) then
7118 Set_Size_Info
(E
, Full_View
(E
));
7119 Copy_RM_Size
(To
=> E
, From
=> Full_View
(E
));
7124 -- Case of underlying full view present
7126 elsif Is_Private_Type
(E
)
7127 and then Present
(Underlying_Full_View
(E
))
7129 if not Is_Frozen
(Underlying_Full_View
(E
)) then
7130 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
7133 -- Patch the pointers so that the freeze node will elaborate
7134 -- both views in the back end.
7136 if Has_Delayed_Freeze
(E
) then
7137 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
7139 if Present
(F_Node
) then
7144 Set_Has_Delayed_Freeze
(E
, False);
7145 Set_Freeze_Node
(E
, Empty
);
7149 Check_Debug_Info_Needed
(E
);
7153 -- Case of no full view present. If entity is subtype or derived,
7154 -- it is safe to freeze, correctness depends on the frozen status
7155 -- of parent. Otherwise it is either premature usage, or a Taft
7156 -- amendment type, so diagnosis is at the point of use and the
7157 -- type might be frozen later.
7159 elsif E
/= Base_Type
(E
) then
7161 Btyp
: constant Entity_Id
:= Base_Type
(E
);
7164 -- However, if the base type is itself private and has no
7165 -- (underlying) full view either, wait until the full type
7166 -- declaration is seen and all the full views are created.
7168 if Is_Private_Type
(Btyp
)
7169 and then No
(Full_View
(Btyp
))
7170 and then No
(Underlying_Full_View
(Btyp
))
7171 and then Has_Delayed_Freeze
(Btyp
)
7172 and then No
(Freeze_Node
(Btyp
))
7174 Set_Is_Frozen
(E
, False);
7180 elsif Is_Derived_Type
(E
) then
7184 Set_Is_Frozen
(E
, False);
7189 -- For access subprogram, freeze types of all formals, the return
7190 -- type was already frozen, since it is the Etype of the function.
7191 -- Formal types can be tagged Taft amendment types, but otherwise
7192 -- they cannot be incomplete.
7194 elsif Ekind
(E
) = E_Subprogram_Type
then
7195 Formal
:= First_Formal
(E
);
7196 while Present
(Formal
) loop
7197 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
7198 and then No
(Full_View
(Etype
(Formal
)))
7200 if Is_Tagged_Type
(Etype
(Formal
)) then
7203 -- AI05-151: Incomplete types are allowed in access to
7204 -- subprogram specifications.
7206 elsif Ada_Version
< Ada_2012
then
7208 ("invalid use of incomplete type&", E
, Etype
(Formal
));
7212 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
7213 Next_Formal
(Formal
);
7216 Freeze_Subprogram
(E
);
7218 -- For access to a protected subprogram, freeze the equivalent type
7219 -- (however this is not set if we are not generating code or if this
7220 -- is an anonymous type used just for resolution).
7222 elsif Is_Access_Protected_Subprogram_Type
(E
) then
7223 if Present
(Equivalent_Type
(E
)) then
7224 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
7228 -- Generic types are never seen by the back-end, and are also not
7229 -- processed by the expander (since the expander is turned off for
7230 -- generic processing), so we never need freeze nodes for them.
7232 if Is_Generic_Type
(E
) then
7236 -- Some special processing for non-generic types to complete
7237 -- representation details not known till the freeze point.
7239 if Is_Fixed_Point_Type
(E
) then
7240 Freeze_Fixed_Point_Type
(E
);
7242 elsif Is_Enumeration_Type
(E
) then
7243 Freeze_Enumeration_Type
(E
);
7245 elsif Is_Integer_Type
(E
) then
7246 Adjust_Esize_For_Alignment
(E
);
7248 if Is_Modular_Integer_Type
(E
)
7249 and then Warn_On_Suspicious_Modulus_Value
7251 Check_Suspicious_Modulus
(E
);
7254 -- The pool applies to named and anonymous access types, but not
7255 -- to subprogram and to internal types generated for 'Access
7258 elsif Is_Access_Object_Type
(E
)
7259 and then Ekind
(E
) /= E_Access_Attribute_Type
7261 -- If a pragma Default_Storage_Pool applies, and this type has no
7262 -- Storage_Pool or Storage_Size clause (which must have occurred
7263 -- before the freezing point), then use the default. This applies
7264 -- only to base types.
7266 -- None of this applies to access to subprograms, for which there
7267 -- are clearly no pools.
7269 if Present
(Default_Pool
)
7270 and then Is_Base_Type
(E
)
7271 and then not Has_Storage_Size_Clause
(E
)
7272 and then No
(Associated_Storage_Pool
(E
))
7274 -- Case of pragma Default_Storage_Pool (null)
7276 if Nkind
(Default_Pool
) = N_Null
then
7277 Set_No_Pool_Assigned
(E
);
7279 -- Case of pragma Default_Storage_Pool (Standard)
7281 elsif Entity
(Default_Pool
) = Standard_Standard
then
7282 Set_Associated_Storage_Pool
(E
, RTE
(RE_Global_Pool_Object
));
7284 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
7287 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
7291 -- Check restriction for standard storage pool
7293 if No
(Associated_Storage_Pool
(E
)) then
7294 Check_Restriction
(No_Standard_Storage_Pools
, E
);
7297 -- Deal with error message for pure access type. This is not an
7298 -- error in Ada 2005 if there is no pool (see AI-366).
7300 if Is_Pure_Unit_Access_Type
(E
)
7301 and then (Ada_Version
< Ada_2005
7302 or else not No_Pool_Assigned
(E
))
7303 and then not Is_Generic_Unit
(Scope
(E
))
7305 Error_Msg_N
("named access type not allowed in pure unit", E
);
7307 if Ada_Version
>= Ada_2005
then
7309 ("\would be legal if Storage_Size of 0 given??", E
);
7311 elsif No_Pool_Assigned
(E
) then
7313 ("\would be legal in Ada 2005??", E
);
7317 ("\would be legal in Ada 2005 if "
7318 & "Storage_Size of 0 given??", E
);
7323 -- Case of composite types
7325 if Is_Composite_Type
(E
) then
7327 -- AI-117 requires that all new primitives of a tagged type must
7328 -- inherit the convention of the full view of the type. Inherited
7329 -- and overriding operations are defined to inherit the convention
7330 -- of their parent or overridden subprogram (also specified in
7331 -- AI-117), which will have occurred earlier (in Derive_Subprogram
7332 -- and New_Overloaded_Entity). Here we set the convention of
7333 -- primitives that are still convention Ada, which will ensure
7334 -- that any new primitives inherit the type's convention. Class-
7335 -- wide types can have a foreign convention inherited from their
7336 -- specific type, but are excluded from this since they don't have
7337 -- any associated primitives.
7339 if Is_Tagged_Type
(E
)
7340 and then not Is_Class_Wide_Type
(E
)
7341 and then Convention
(E
) /= Convention_Ada
7344 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
7348 Prim
:= First_Elmt
(Prim_List
);
7349 while Present
(Prim
) loop
7350 if Convention
(Node
(Prim
)) = Convention_Ada
then
7351 Set_Convention
(Node
(Prim
), Convention
(E
));
7359 -- If the type is a simple storage pool type, then this is where
7360 -- we attempt to locate and validate its Allocate, Deallocate, and
7361 -- Storage_Size operations (the first is required, and the latter
7362 -- two are optional). We also verify that the full type for a
7363 -- private type is allowed to be a simple storage pool type.
7365 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
7366 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
7368 -- If the type is marked Has_Private_Declaration, then this is
7369 -- a full type for a private type that was specified with the
7370 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
7371 -- pragma is allowed for the full type (for example, it can't
7372 -- be an array type, or a nonlimited record type).
7374 if Has_Private_Declaration
(E
) then
7375 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
7376 and then not Is_Private_Type
(E
)
7378 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
7380 ("pragma% can only apply to full type that is an " &
7381 "explicitly limited type", E
);
7385 Validate_Simple_Pool_Ops
: declare
7386 Pool_Type
: Entity_Id
renames E
;
7387 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
7388 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
7390 procedure Validate_Simple_Pool_Op_Formal
7391 (Pool_Op
: Entity_Id
;
7392 Pool_Op_Formal
: in out Entity_Id
;
7393 Expected_Mode
: Formal_Kind
;
7394 Expected_Type
: Entity_Id
;
7395 Formal_Name
: String;
7396 OK_Formal
: in out Boolean);
7397 -- Validate one formal Pool_Op_Formal of the candidate pool
7398 -- operation Pool_Op. The formal must be of Expected_Type
7399 -- and have mode Expected_Mode. OK_Formal will be set to
7400 -- False if the formal doesn't match. If OK_Formal is False
7401 -- on entry, then the formal will effectively be ignored
7402 -- (because validation of the pool op has already failed).
7403 -- Upon return, Pool_Op_Formal will be updated to the next
7406 procedure Validate_Simple_Pool_Operation
7407 (Op_Name
: Name_Id
);
7408 -- Search for and validate a simple pool operation with the
7409 -- name Op_Name. If the name is Allocate, then there must be
7410 -- exactly one such primitive operation for the simple pool
7411 -- type. If the name is Deallocate or Storage_Size, then
7412 -- there can be at most one such primitive operation. The
7413 -- profile of the located primitive must conform to what
7414 -- is expected for each operation.
7416 ------------------------------------
7417 -- Validate_Simple_Pool_Op_Formal --
7418 ------------------------------------
7420 procedure Validate_Simple_Pool_Op_Formal
7421 (Pool_Op
: Entity_Id
;
7422 Pool_Op_Formal
: in out Entity_Id
;
7423 Expected_Mode
: Formal_Kind
;
7424 Expected_Type
: Entity_Id
;
7425 Formal_Name
: String;
7426 OK_Formal
: in out Boolean)
7429 -- If OK_Formal is False on entry, then simply ignore
7430 -- the formal, because an earlier formal has already
7433 if not OK_Formal
then
7436 -- If no formal is passed in, then issue an error for a
7439 elsif not Present
(Pool_Op_Formal
) then
7441 ("simple storage pool op missing formal " &
7442 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
7448 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
7450 -- If the pool type was expected for this formal, then
7451 -- this will not be considered a candidate operation
7452 -- for the simple pool, so we unset OK_Formal so that
7453 -- the op and any later formals will be ignored.
7455 if Expected_Type
= Pool_Type
then
7462 ("wrong type for formal " & Formal_Name
&
7463 " of simple storage pool op; expected type&",
7464 Pool_Op_Formal
, Expected_Type
);
7468 -- Issue error if formal's mode is not the expected one
7470 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
7472 ("wrong mode for formal of simple storage pool op",
7476 -- Advance to the next formal
7478 Next_Formal
(Pool_Op_Formal
);
7479 end Validate_Simple_Pool_Op_Formal
;
7481 ------------------------------------
7482 -- Validate_Simple_Pool_Operation --
7483 ------------------------------------
7485 procedure Validate_Simple_Pool_Operation
7489 Found_Op
: Entity_Id
:= Empty
;
7495 (Op_Name
in Name_Allocate
7497 | Name_Storage_Size
);
7499 Error_Msg_Name_1
:= Op_Name
;
7501 -- For each homonym declared immediately in the scope
7502 -- of the simple storage pool type, determine whether
7503 -- the homonym is an operation of the pool type, and,
7504 -- if so, check that its profile is as expected for
7505 -- a simple pool operation of that name.
7507 Op
:= Get_Name_Entity_Id
(Op_Name
);
7508 while Present
(Op
) loop
7509 if Ekind
(Op
) in E_Function | E_Procedure
7510 and then Scope
(Op
) = Current_Scope
7512 Formal
:= First_Entity
(Op
);
7516 -- The first parameter must be of the pool type
7517 -- in order for the operation to qualify.
7519 if Op_Name
= Name_Storage_Size
then
7520 Validate_Simple_Pool_Op_Formal
7521 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
7524 Validate_Simple_Pool_Op_Formal
7525 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
7529 -- If another operation with this name has already
7530 -- been located for the type, then flag an error,
7531 -- since we only allow the type to have a single
7534 if Present
(Found_Op
) and then Is_OK
then
7536 ("only one % operation allowed for " &
7537 "simple storage pool type&", Op
, Pool_Type
);
7540 -- In the case of Allocate and Deallocate, a formal
7541 -- of type System.Address is required.
7543 if Op_Name
= Name_Allocate
then
7544 Validate_Simple_Pool_Op_Formal
7545 (Op
, Formal
, E_Out_Parameter
,
7546 Address_Type
, "Storage_Address", Is_OK
);
7548 elsif Op_Name
= Name_Deallocate
then
7549 Validate_Simple_Pool_Op_Formal
7550 (Op
, Formal
, E_In_Parameter
,
7551 Address_Type
, "Storage_Address", Is_OK
);
7554 -- In the case of Allocate and Deallocate, formals
7555 -- of type Storage_Count are required as the third
7556 -- and fourth parameters.
7558 if Op_Name
/= Name_Storage_Size
then
7559 Validate_Simple_Pool_Op_Formal
7560 (Op
, Formal
, E_In_Parameter
,
7561 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
7562 Validate_Simple_Pool_Op_Formal
7563 (Op
, Formal
, E_In_Parameter
,
7564 Stg_Cnt_Type
, "Alignment", Is_OK
);
7567 -- If no mismatched formals have been found (Is_OK)
7568 -- and no excess formals are present, then this
7569 -- operation has been validated, so record it.
7571 if not Present
(Formal
) and then Is_OK
then
7579 -- There must be a valid Allocate operation for the type,
7580 -- so issue an error if none was found.
7582 if Op_Name
= Name_Allocate
7583 and then not Present
(Found_Op
)
7585 Error_Msg_N
("missing % operation for simple " &
7586 "storage pool type", Pool_Type
);
7588 elsif Present
(Found_Op
) then
7590 -- Simple pool operations can't be abstract
7592 if Is_Abstract_Subprogram
(Found_Op
) then
7594 ("simple storage pool operation must not be " &
7595 "abstract", Found_Op
);
7598 -- The Storage_Size operation must be a function with
7599 -- Storage_Count as its result type.
7601 if Op_Name
= Name_Storage_Size
then
7602 if Ekind
(Found_Op
) = E_Procedure
then
7604 ("% operation must be a function", Found_Op
);
7606 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
7608 ("wrong result type for%, expected type&",
7609 Found_Op
, Stg_Cnt_Type
);
7612 -- Allocate and Deallocate must be procedures
7614 elsif Ekind
(Found_Op
) = E_Function
then
7616 ("% operation must be a procedure", Found_Op
);
7619 end Validate_Simple_Pool_Operation
;
7621 -- Start of processing for Validate_Simple_Pool_Ops
7624 Validate_Simple_Pool_Operation
(Name_Allocate
);
7625 Validate_Simple_Pool_Operation
(Name_Deallocate
);
7626 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
7627 end Validate_Simple_Pool_Ops
;
7631 -- Now that all types from which E may depend are frozen, see if
7632 -- strict alignment is required, a component clause on a record
7633 -- is correct, the size is known at compile time and if it must
7634 -- be unsigned, in that order.
7636 if Base_Type
(E
) = E
then
7637 Check_Strict_Alignment
(E
);
7640 if Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
7642 RC
: constant Node_Id
:= Get_Record_Representation_Clause
(E
);
7644 if Present
(RC
) then
7645 Check_Record_Representation_Clause
(RC
);
7650 Check_Compile_Time_Size
(E
);
7652 Check_Unsigned_Type
(E
);
7654 -- Do not allow a size clause for a type which does not have a size
7655 -- that is known at compile time
7657 if (Has_Size_Clause
(E
) or else Has_Object_Size_Clause
(E
))
7658 and then not Size_Known_At_Compile_Time
(E
)
7660 -- Suppress this message if errors posted on E, even if we are
7661 -- in all errors mode, since this is often a junk message
7663 if not Error_Posted
(E
) then
7665 ("size clause not allowed for variable length type",
7670 -- Now we set/verify the representation information, in particular
7671 -- the size and alignment values. This processing is not required for
7672 -- generic types, since generic types do not play any part in code
7673 -- generation, and so the size and alignment values for such types
7674 -- are irrelevant. Ditto for types declared within a generic unit,
7675 -- which may have components that depend on generic parameters, and
7676 -- that will be recreated in an instance.
7678 if Inside_A_Generic
then
7681 -- Otherwise we call the layout procedure
7687 -- If this is an access to subprogram whose designated type is itself
7688 -- a subprogram type, the return type of this anonymous subprogram
7689 -- type must be decorated as well.
7691 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
7692 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
7694 Layout_Type
(Etype
(Designated_Type
(E
)));
7697 -- If the type has a Defaut_Value/Default_Component_Value aspect,
7698 -- this is where we analyze the expression (after the type is frozen,
7699 -- since in the case of Default_Value, we are analyzing with the
7700 -- type itself, and we treat Default_Component_Value similarly for
7701 -- the sake of uniformity).
7703 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
7710 if Is_Scalar_Type
(E
) then
7711 Nam
:= Name_Default_Value
;
7713 Exp
:= Default_Aspect_Value
(Typ
);
7715 Nam
:= Name_Default_Component_Value
;
7716 Typ
:= Component_Type
(E
);
7717 Exp
:= Default_Aspect_Component_Value
(E
);
7720 Analyze_And_Resolve
(Exp
, Typ
);
7722 if Etype
(Exp
) /= Any_Type
then
7723 if not Is_OK_Static_Expression
(Exp
) then
7724 Error_Msg_Name_1
:= Nam
;
7725 Flag_Non_Static_Expr
7726 ("aspect% requires static expression", Exp
);
7732 -- Verify at this point that No_Controlled_Parts and No_Task_Parts,
7733 -- when specified on the current type or one of its ancestors, has
7734 -- not been overridden and that no violation of the aspect has
7737 -- It is important that we perform the checks here after the type has
7738 -- been processed because if said type depended on a private type it
7739 -- will not have been marked controlled or having tasks.
7741 Check_No_Parts_Violations
(E
, Aspect_No_Controlled_Parts
);
7742 Check_No_Parts_Violations
(E
, Aspect_No_Task_Parts
);
7744 -- End of freeze processing for type entities
7747 -- Here is where we logically freeze the current entity. If it has a
7748 -- freeze node, then this is the point at which the freeze node is
7749 -- linked into the result list.
7751 if Has_Delayed_Freeze
(E
) then
7753 -- If a freeze node is already allocated, use it, otherwise allocate
7754 -- a new one. The preallocation happens in the case of anonymous base
7755 -- types, where we preallocate so that we can set First_Subtype_Link.
7756 -- Note that we reset the Sloc to the current freeze location.
7758 if Present
(Freeze_Node
(E
)) then
7759 F_Node
:= Freeze_Node
(E
);
7760 Set_Sloc
(F_Node
, Loc
);
7763 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
7764 Set_Freeze_Node
(E
, F_Node
);
7765 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
7766 Set_TSS_Elist
(F_Node
, No_Elist
);
7767 Set_Actions
(F_Node
, No_List
);
7770 Set_Entity
(F_Node
, E
);
7771 Add_To_Result
(F_Node
);
7773 -- A final pass over record types with discriminants. If the type
7774 -- has an incomplete declaration, there may be constrained access
7775 -- subtypes declared elsewhere, which do not depend on the discrimi-
7776 -- nants of the type, and which are used as component types (i.e.
7777 -- the full view is a recursive type). The designated types of these
7778 -- subtypes can only be elaborated after the type itself, and they
7779 -- need an itype reference.
7781 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
7788 Comp
:= First_Component
(E
);
7789 while Present
(Comp
) loop
7790 Typ
:= Etype
(Comp
);
7792 if Is_Access_Type
(Typ
)
7793 and then Scope
(Typ
) /= E
7794 and then Base_Type
(Designated_Type
(Typ
)) = E
7795 and then Is_Itype
(Designated_Type
(Typ
))
7797 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
7798 Set_Itype
(IR
, Designated_Type
(Typ
));
7799 Append
(IR
, Result
);
7802 Next_Component
(Comp
);
7808 -- When a type is frozen, the first subtype of the type is frozen as
7809 -- well (RM 13.14(15)). This has to be done after freezing the type,
7810 -- since obviously the first subtype depends on its own base type.
7813 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
7815 -- If we just froze a tagged non-class-wide record, then freeze the
7816 -- corresponding class-wide type. This must be done after the tagged
7817 -- type itself is frozen, because the class-wide type refers to the
7818 -- tagged type which generates the class.
7820 -- For a tagged type, freeze explicitly those primitive operations
7821 -- that are expression functions, which otherwise have no clear
7822 -- freeze point: these have to be frozen before the dispatch table
7823 -- for the type is built, and before any explicit call to the
7824 -- primitive, which would otherwise be the freeze point for it.
7826 if Is_Tagged_Type
(E
)
7827 and then not Is_Class_Wide_Type
(E
)
7828 and then Present
(Class_Wide_Type
(E
))
7830 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
7833 Ops
: constant Elist_Id
:= Primitive_Operations
(E
);
7839 if Ops
/= No_Elist
then
7840 Elmt
:= First_Elmt
(Ops
);
7841 while Present
(Elmt
) loop
7842 Subp
:= Node
(Elmt
);
7843 if Is_Expression_Function
(Subp
) then
7844 Freeze_And_Append
(Subp
, N
, Result
);
7854 Check_Debug_Info_Needed
(E
);
7856 -- If subprogram has address clause then reset Is_Public flag, since we
7857 -- do not want the backend to generate external references.
7859 if Is_Subprogram
(E
)
7860 and then Present
(Address_Clause
(E
))
7861 and then not Is_Library_Level_Entity
(E
)
7863 Set_Is_Public
(E
, False);
7866 -- The Ghost mode of the enclosing context is ignored, while the
7867 -- entity being frozen is living. Insert the freezing action prior
7868 -- to the start of the enclosing ignored Ghost region. As a result
7869 -- the freezeing action will be preserved when the ignored Ghost
7870 -- context is eliminated. The insertion must take place even when
7871 -- the context is a spec expression, otherwise "Handling of Default
7872 -- and Per-Object Expressions" will suppress the insertion, and the
7873 -- freeze node will be dropped on the floor.
7875 if Saved_GM
= Ignore
7876 and then Ghost_Mode
/= Ignore
7877 and then Present
(Ignored_Ghost_Region
)
7880 (Assoc_Node
=> Ignored_Ghost_Region
,
7881 Ins_Actions
=> Result
,
7882 Spec_Expr_OK
=> True);
7888 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
7893 -----------------------------
7894 -- Freeze_Enumeration_Type --
7895 -----------------------------
7897 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
7899 -- By default, if no size clause is present, an enumeration type with
7900 -- Convention C is assumed to interface to a C enum and has integer
7901 -- size, except for a boolean type because it is assumed to interface
7902 -- to _Bool introduced in C99. This applies to types. For subtypes,
7903 -- verify that its base type has no size clause either. Treat other
7904 -- foreign conventions in the same way, and also make sure alignment
7907 if Has_Foreign_Convention
(Typ
)
7908 and then not Is_Boolean_Type
(Typ
)
7909 and then not Has_Size_Clause
(Typ
)
7910 and then not Has_Size_Clause
(Base_Type
(Typ
))
7911 and then Esize
(Typ
) < Standard_Integer_Size
7913 -- Don't do this if Short_Enums on target
7915 and then not Target_Short_Enums
7917 Set_Esize
(Typ
, UI_From_Int
(Standard_Integer_Size
));
7918 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
7920 -- Normal Ada case or size clause present or not Long_C_Enums on target
7923 -- If the enumeration type interfaces to C, and it has a size clause
7924 -- that is smaller than the size of int, it warrants a warning. The
7925 -- user may intend the C type to be a boolean or a char, so this is
7926 -- not by itself an error that the Ada compiler can detect, but it
7927 -- is worth a heads-up. For Boolean and Character types we
7928 -- assume that the programmer has the proper C type in mind.
7929 -- For explicit sizes larger than int, assume the user knows what
7930 -- he is doing and that the code is intentional.
7932 if Convention
(Typ
) = Convention_C
7933 and then Has_Size_Clause
(Typ
)
7934 and then Esize
(Typ
) < Standard_Integer_Size
7935 and then not Is_Boolean_Type
(Typ
)
7936 and then not Is_Character_Type
(Typ
)
7938 -- Don't do this if Short_Enums on target
7940 and then not Target_Short_Enums
7943 ("??the size of enums in C is implementation-defined",
7946 ("\??check that the C counterpart has size of " &
7947 UI_Image
(Esize
(Typ
)),
7951 Adjust_Esize_For_Alignment
(Typ
);
7953 end Freeze_Enumeration_Type
;
7955 -----------------------
7956 -- Freeze_Expression --
7957 -----------------------
7959 procedure Freeze_Expression
(N
: Node_Id
) is
7961 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
7962 -- If the expression is an array aggregate, the type of the component
7963 -- expressions is also frozen. If the component type is an access type
7964 -- and the expressions include allocators, the designed type is frozen
7967 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
7968 -- Given an N_Handled_Sequence_Of_Statements node, determines whether it
7969 -- is the statement sequence of an expander-generated subprogram: body
7970 -- created for an expression function, for a predicate function, an init
7971 -- proc, a stream subprogram, or a renaming as body. If so, this is not
7972 -- a freezing context and the entity will be frozen at a later point.
7974 function Has_Decl_In_List
7977 L
: List_Id
) return Boolean;
7978 -- Determines whether an entity E referenced in node N is declared in
7981 -----------------------------------------
7982 -- Find_Aggregate_Component_Desig_Type --
7983 -----------------------------------------
7985 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
7990 if Present
(Expressions
(N
)) then
7991 Exp
:= First
(Expressions
(N
));
7992 while Present
(Exp
) loop
7993 if Nkind
(Exp
) = N_Allocator
then
7994 return Designated_Type
(Component_Type
(Etype
(N
)));
8001 if Present
(Component_Associations
(N
)) then
8002 Assoc
:= First
(Component_Associations
(N
));
8003 while Present
(Assoc
) loop
8004 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
8005 return Designated_Type
(Component_Type
(Etype
(N
)));
8013 end Find_Aggregate_Component_Desig_Type
;
8015 ----------------------
8016 -- In_Expanded_Body --
8017 ----------------------
8019 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
8020 P
: constant Node_Id
:= Parent
(N
);
8024 if Nkind
(P
) /= N_Subprogram_Body
then
8027 -- AI12-0157: An expression function that is a completion is a freeze
8028 -- point. If the body is the result of expansion, it is not.
8030 elsif Was_Expression_Function
(P
) then
8031 return not Comes_From_Source
(P
);
8033 -- This is the body of a generated predicate function
8035 elsif Present
(Corresponding_Spec
(P
))
8036 and then Is_Predicate_Function
(Corresponding_Spec
(P
))
8041 Id
:= Defining_Unit_Name
(Specification
(P
));
8043 -- The following are expander-created bodies, or bodies that
8044 -- are not freeze points.
8046 if Nkind
(Id
) = N_Defining_Identifier
8047 and then (Is_Init_Proc
(Id
)
8048 or else Is_TSS
(Id
, TSS_Stream_Input
)
8049 or else Is_TSS
(Id
, TSS_Stream_Output
)
8050 or else Is_TSS
(Id
, TSS_Stream_Read
)
8051 or else Is_TSS
(Id
, TSS_Stream_Write
)
8052 or else Is_TSS
(Id
, TSS_Put_Image
)
8053 or else Nkind
(Original_Node
(P
)) =
8054 N_Subprogram_Renaming_Declaration
)
8061 end In_Expanded_Body
;
8063 ----------------------
8064 -- Has_Decl_In_List --
8065 ----------------------
8067 function Has_Decl_In_List
8070 L
: List_Id
) return Boolean
8072 Decl_Node
: Node_Id
;
8075 -- If E is an itype, pretend that it is declared in N
8077 if Is_Itype
(E
) then
8080 Decl_Node
:= Declaration_Node
(E
);
8083 return Is_List_Member
(Decl_Node
)
8084 and then List_Containing
(Decl_Node
) = L
;
8085 end Has_Decl_In_List
;
8089 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
8091 Desig_Typ
: Entity_Id
;
8097 Allocator_Typ
: Entity_Id
:= Empty
;
8099 Freeze_Outside
: Boolean := False;
8100 -- This flag is set true if the entity must be frozen outside the
8101 -- current subprogram. This happens in the case of expander generated
8102 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
8103 -- not freeze all entities like other bodies, but which nevertheless
8104 -- may reference entities that have to be frozen before the body and
8105 -- obviously cannot be frozen inside the body.
8107 Freeze_Outside_Subp
: Entity_Id
:= Empty
;
8108 -- This entity is set if we are inside a subprogram body and the frozen
8109 -- entity is defined in the enclosing scope of this subprogram. In such
8110 -- case we must skip the subprogram body when climbing the parents chain
8111 -- to locate the correct placement for the freezing node.
8113 -- Start of processing for Freeze_Expression
8116 -- Immediate return if freezing is inhibited. This flag is set by the
8117 -- analyzer to stop freezing on generated expressions that would cause
8118 -- freezing if they were in the source program, but which are not
8119 -- supposed to freeze, since they are created.
8121 if Must_Not_Freeze
(N
) then
8125 -- If expression is non-static, then it does not freeze in a default
8126 -- expression, see section "Handling of Default Expressions" in the
8127 -- spec of package Sem for further details. Note that we have to make
8128 -- sure that we actually have a real expression (if we have a subtype
8129 -- indication, we can't test Is_OK_Static_Expression). However, we
8130 -- exclude the case of the prefix of an attribute of a static scalar
8131 -- subtype from this early return, because static subtype attributes
8132 -- should always cause freezing, even in default expressions, but
8133 -- the attribute may not have been marked as static yet (because in
8134 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
8135 -- Freeze_Expression on the prefix).
8138 and then Nkind
(N
) in N_Subexpr
8139 and then not Is_OK_Static_Expression
(N
)
8140 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
8141 or else not (Is_Entity_Name
(N
)
8142 and then Is_Type
(Entity
(N
))
8143 and then Is_OK_Static_Subtype
(Entity
(N
))))
8148 -- Freeze type of expression if not frozen already
8152 if Nkind
(N
) in N_Has_Etype
and then Present
(Etype
(N
)) then
8153 if not Is_Frozen
(Etype
(N
)) then
8156 -- Base type may be an derived numeric type that is frozen at the
8157 -- point of declaration, but first_subtype is still unfrozen.
8159 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
8160 Typ
:= First_Subtype
(Etype
(N
));
8164 -- For entity name, freeze entity if not frozen already. A special
8165 -- exception occurs for an identifier that did not come from source.
8166 -- We don't let such identifiers freeze a non-internal entity, i.e.
8167 -- an entity that did come from source, since such an identifier was
8168 -- generated by the expander, and cannot have any semantic effect on
8169 -- the freezing semantics. For example, this stops the parameter of
8170 -- an initialization procedure from freezing the variable.
8172 if Is_Entity_Name
(N
)
8173 and then Present
(Entity
(N
))
8174 and then not Is_Frozen
(Entity
(N
))
8175 and then (Nkind
(N
) /= N_Identifier
8176 or else Comes_From_Source
(N
)
8177 or else not Comes_From_Source
(Entity
(N
)))
8181 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
8182 Check_Expression_Function
(N
, Nam
);
8189 -- For an allocator freeze designated type if not frozen already
8191 -- For an aggregate whose component type is an access type, freeze the
8192 -- designated type now, so that its freeze does not appear within the
8193 -- loop that might be created in the expansion of the aggregate. If the
8194 -- designated type is a private type without full view, the expression
8195 -- cannot contain an allocator, so the type is not frozen.
8197 -- For a function, we freeze the entity when the subprogram declaration
8198 -- is frozen, but a function call may appear in an initialization proc.
8199 -- before the declaration is frozen. We need to generate the extra
8200 -- formals, if any, to ensure that the expansion of the call includes
8201 -- the proper actuals. This only applies to Ada subprograms, not to
8208 Desig_Typ
:= Designated_Type
(Etype
(N
));
8210 if Nkind
(Expression
(N
)) = N_Qualified_Expression
then
8211 Allocator_Typ
:= Entity
(Subtype_Mark
(Expression
(N
)));
8215 if Is_Array_Type
(Etype
(N
))
8216 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
8218 -- Check whether aggregate includes allocators
8220 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
8223 when N_Indexed_Component
8224 | N_Selected_Component
8227 if Is_Access_Type
(Etype
(Prefix
(N
))) then
8228 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
8231 when N_Identifier
=>
8233 and then Ekind
(Nam
) = E_Function
8234 and then Nkind
(Parent
(N
)) = N_Function_Call
8235 and then Convention
(Nam
) = Convention_Ada
8237 Create_Extra_Formals
(Nam
);
8244 if Desig_Typ
/= Empty
8245 and then (Is_Frozen
(Desig_Typ
)
8246 or else (not Is_Fully_Defined
(Desig_Typ
)))
8251 -- All done if nothing needs freezing
8255 and then No
(Desig_Typ
)
8256 and then No
(Allocator_Typ
)
8261 -- Check if we are inside a subprogram body and the frozen entity is
8262 -- defined in the enclosing scope of this subprogram. In such case we
8263 -- must skip the subprogram when climbing the parents chain to locate
8264 -- the correct placement for the freezing node.
8266 -- This is not needed for default expressions and other spec expressions
8267 -- in generic units since the Move_Freeze_Nodes mechanism (sem_ch12.adb)
8268 -- takes care of placing them at the proper place, after the generic
8272 and then Scope
(Nam
) /= Current_Scope
8273 and then not (In_Spec_Exp
and then Inside_A_Generic
)
8276 S
: Entity_Id
:= Current_Scope
;
8280 and then In_Same_Source_Unit
(Nam
, S
)
8282 if Scope
(S
) = Scope
(Nam
) then
8283 if Is_Subprogram
(S
) and then Has_Completion
(S
) then
8284 Freeze_Outside_Subp
:= S
;
8295 -- Examine the enclosing context by climbing the parent chain
8297 -- If we identified that we must freeze the entity outside of a given
8298 -- subprogram then we just climb up to that subprogram checking if some
8299 -- enclosing node is marked as Must_Not_Freeze (since in such case we
8300 -- must not freeze yet this entity).
8304 if Present
(Freeze_Outside_Subp
) then
8306 -- Do not freeze the current expression if another expression in
8307 -- the chain of parents must not be frozen.
8309 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8313 Parent_P
:= Parent
(P
);
8315 -- If we don't have a parent, then we are not in a well-formed
8316 -- tree. This is an unusual case, but there are some legitimate
8317 -- situations in which this occurs, notably when the expressions
8318 -- in the range of a type declaration are resolved. We simply
8319 -- ignore the freeze request in this case.
8321 if No
(Parent_P
) then
8325 -- If the parent is a subprogram body, the candidate insertion
8326 -- point is just ahead of it.
8328 if Nkind
(Parent_P
) = N_Subprogram_Body
8329 and then Unique_Defining_Entity
(Parent_P
) =
8339 -- Otherwise the traversal serves two purposes - to detect scenarios
8340 -- where freezeing is not needed and to find the proper insertion point
8341 -- for the freeze nodes. Although somewhat similar to Insert_Actions,
8342 -- this traversal is freezing semantics-sensitive. Inserting freeze
8343 -- nodes blindly in the tree may result in types being frozen too early.
8347 -- Do not freeze the current expression if another expression in
8348 -- the chain of parents must not be frozen.
8350 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
8354 Parent_P
:= Parent
(P
);
8356 -- If we don't have a parent, then we are not in a well-formed
8357 -- tree. This is an unusual case, but there are some legitimate
8358 -- situations in which this occurs, notably when the expressions
8359 -- in the range of a type declaration are resolved. We simply
8360 -- ignore the freeze request in this case.
8362 if No
(Parent_P
) then
8366 -- See if we have got to an appropriate point in the tree
8368 case Nkind
(Parent_P
) is
8370 -- A special test for the exception of (RM 13.14(8)) for the
8371 -- case of per-object expressions (RM 3.8(18)) occurring in
8372 -- component definition or a discrete subtype definition. Note
8373 -- that we test for a component declaration which includes both
8374 -- cases we are interested in, and furthermore the tree does
8375 -- not have explicit nodes for either of these two constructs.
8377 when N_Component_Declaration
=>
8379 -- The case we want to test for here is an identifier that
8380 -- is a per-object expression, this is either a discriminant
8381 -- that appears in a context other than the component
8382 -- declaration or it is a reference to the type of the
8383 -- enclosing construct.
8385 -- For either of these cases, we skip the freezing
8387 if not In_Spec_Expression
8388 and then Nkind
(N
) = N_Identifier
8389 and then (Present
(Entity
(N
)))
8391 -- We recognize the discriminant case by just looking for
8392 -- a reference to a discriminant. It can only be one for
8393 -- the enclosing construct. Skip freezing in this case.
8395 if Ekind
(Entity
(N
)) = E_Discriminant
then
8398 -- For the case of a reference to the enclosing record,
8399 -- (or task or protected type), we look for a type that
8400 -- matches the current scope.
8402 elsif Entity
(N
) = Current_Scope
then
8407 -- If we have an enumeration literal that appears as the choice
8408 -- in the aggregate of an enumeration representation clause,
8409 -- then freezing does not occur (RM 13.14(10)).
8411 when N_Enumeration_Representation_Clause
=>
8413 -- The case we are looking for is an enumeration literal
8415 if Nkind
(N
) in N_Identifier | N_Character_Literal
8416 and then Is_Enumeration_Type
(Etype
(N
))
8418 -- If enumeration literal appears directly as the choice,
8419 -- do not freeze (this is the normal non-overloaded case)
8421 if Nkind
(Parent
(N
)) = N_Component_Association
8422 and then First
(Choices
(Parent
(N
))) = N
8426 -- If enumeration literal appears as the name of function
8427 -- which is the choice, then also do not freeze. This
8428 -- happens in the overloaded literal case, where the
8429 -- enumeration literal is temporarily changed to a
8430 -- function call for overloading analysis purposes.
8432 elsif Nkind
(Parent
(N
)) = N_Function_Call
8433 and then Nkind
(Parent
(Parent
(N
))) =
8434 N_Component_Association
8435 and then First
(Choices
(Parent
(Parent
(N
)))) =
8442 -- Normally if the parent is a handled sequence of statements,
8443 -- then the current node must be a statement, and that is an
8444 -- appropriate place to insert a freeze node.
8446 when N_Handled_Sequence_Of_Statements
=>
8448 -- An exception occurs when the sequence of statements is
8449 -- for an expander generated body that did not do the usual
8450 -- freeze all operation. In this case we usually want to
8451 -- freeze outside this body, not inside it, and we skip
8452 -- past the subprogram body that we are inside.
8454 if In_Expanded_Body
(Parent_P
) then
8456 Subp_Body
: constant Node_Id
:= Parent
(Parent_P
);
8457 Spec_Id
: Entity_Id
;
8460 -- Freeze the entity only when it is declared inside
8461 -- the body of the expander generated procedure. This
8462 -- case is recognized by the subprogram scope of the
8463 -- entity or its type, which is either the spec of an
8464 -- enclosing body, or (in the case of init_procs for
8465 -- which there is no separate spec) the current scope.
8467 if Nkind
(Subp_Body
) = N_Subprogram_Body
then
8472 Spec_Id
:= Corresponding_Spec
(Subp_Body
);
8474 if Present
(Typ
) then
8476 elsif Present
(Nam
) then
8479 S
:= Standard_Standard
;
8482 while S
/= Standard_Standard
8483 and then not Is_Subprogram
(S
)
8492 and then Scope
(Typ
) = Current_Scope
8494 Defining_Entity
(Subp_Body
) = Current_Scope
8501 -- If the entity is not frozen by an expression
8502 -- function that is not a completion, continue
8503 -- climbing the tree.
8505 if Nkind
(Subp_Body
) = N_Subprogram_Body
8506 and then Was_Expression_Function
(Subp_Body
)
8510 -- Freeze outside the body
8513 Parent_P
:= Parent
(Parent_P
);
8514 Freeze_Outside
:= True;
8518 -- Here if normal case where we are in handled statement
8519 -- sequence and want to do the insertion right there.
8525 -- If parent is a body or a spec or a block, then the current
8526 -- node is a statement or declaration and we can insert the
8527 -- freeze node before it.
8529 when N_Block_Statement
8532 | N_Package_Specification
8539 -- The expander is allowed to define types in any statements
8540 -- list, so any of the following parent nodes also mark a
8541 -- freezing point if the actual node is in a list of
8542 -- statements or declarations.
8544 when N_Abortable_Part
8545 | N_Accept_Alternative
8546 | N_Case_Statement_Alternative
8547 | N_Compilation_Unit_Aux
8548 | N_Conditional_Entry_Call
8549 | N_Delay_Alternative
8551 | N_Entry_Call_Alternative
8552 | N_Exception_Handler
8553 | N_Extended_Return_Statement
8556 | N_Selective_Accept
8557 | N_Triggering_Alternative
8559 exit when Is_List_Member
(P
);
8561 -- The freeze nodes produced by an expression coming from the
8562 -- Actions list of an N_Expression_With_Actions, short-circuit
8563 -- expression or N_Case_Expression_Alternative node must remain
8564 -- within the Actions list if they freeze an entity declared in
8565 -- this list, as inserting the freeze nodes further up the tree
8566 -- may lead to use before declaration issues for the entity.
8568 when N_Case_Expression_Alternative
8569 | N_Expression_With_Actions
8572 exit when (Present
(Nam
)
8574 Has_Decl_In_List
(Nam
, P
, Actions
(Parent_P
)))
8575 or else (Present
(Typ
)
8577 Has_Decl_In_List
(Typ
, P
, Actions
(Parent_P
)));
8579 -- Likewise for an N_If_Expression and its two Actions list
8581 when N_If_Expression
=>
8583 L1
: constant List_Id
:= Then_Actions
(Parent_P
);
8584 L2
: constant List_Id
:= Else_Actions
(Parent_P
);
8587 exit when (Present
(Nam
)
8589 Has_Decl_In_List
(Nam
, P
, L1
))
8590 or else (Present
(Typ
)
8592 Has_Decl_In_List
(Typ
, P
, L1
))
8593 or else (Present
(Nam
)
8595 Has_Decl_In_List
(Nam
, P
, L2
))
8596 or else (Present
(Typ
)
8598 Has_Decl_In_List
(Typ
, P
, L2
));
8601 -- N_Loop_Statement is a special case: a type that appears in
8602 -- the source can never be frozen in a loop (this occurs only
8603 -- because of a loop expanded by the expander), so we keep on
8604 -- going. Otherwise we terminate the search. Same is true of
8605 -- any entity which comes from source (if it has a predefined
8606 -- type, this type does not appear to come from source, but the
8607 -- entity should not be frozen here).
8609 when N_Loop_Statement
=>
8610 exit when not Comes_From_Source
(Etype
(N
))
8611 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
8613 -- For all other cases, keep looking at parents
8619 -- We fall through the case if we did not yet find the proper
8620 -- place in the tree for inserting the freeze node, so climb.
8626 -- If the expression appears in a record or an initialization procedure,
8627 -- the freeze nodes are collected and attached to the current scope, to
8628 -- be inserted and analyzed on exit from the scope, to insure that
8629 -- generated entities appear in the correct scope. If the expression is
8630 -- a default for a discriminant specification, the scope is still void.
8631 -- The expression can also appear in the discriminant part of a private
8632 -- or concurrent type.
8634 -- If the expression appears in a constrained subcomponent of an
8635 -- enclosing record declaration, the freeze nodes must be attached to
8636 -- the outer record type so they can eventually be placed in the
8637 -- enclosing declaration list.
8639 -- The other case requiring this special handling is if we are in a
8640 -- default expression, since in that case we are about to freeze a
8641 -- static type, and the freeze scope needs to be the outer scope, not
8642 -- the scope of the subprogram with the default parameter.
8644 -- For default expressions and other spec expressions in generic units,
8645 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
8646 -- placing them at the proper place, after the generic unit.
8648 if (In_Spec_Exp
and not Inside_A_Generic
)
8649 or else Freeze_Outside
8650 or else (Is_Type
(Current_Scope
)
8651 and then (not Is_Concurrent_Type
(Current_Scope
)
8652 or else not Has_Completion
(Current_Scope
)))
8653 or else Ekind
(Current_Scope
) = E_Void
8656 Freeze_Nodes
: List_Id
:= No_List
;
8657 Pos
: Int
:= Scope_Stack
.Last
;
8660 if Present
(Desig_Typ
) then
8661 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
8664 if Present
(Typ
) then
8665 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
8668 if Present
(Nam
) then
8669 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
8672 -- The current scope may be that of a constrained component of
8673 -- an enclosing record declaration, or of a loop of an enclosing
8674 -- quantified expression, which is above the current scope in the
8675 -- scope stack. Indeed in the context of a quantified expression,
8676 -- a scope is created and pushed above the current scope in order
8677 -- to emulate the loop-like behavior of the quantified expression.
8678 -- If the expression is within a top-level pragma, as for a pre-
8679 -- condition on a library-level subprogram, nothing to do.
8681 if not Is_Compilation_Unit
(Current_Scope
)
8682 and then (Is_Record_Type
(Scope
(Current_Scope
))
8683 or else Nkind
(Parent
(Current_Scope
)) =
8684 N_Quantified_Expression
)
8689 if Is_Non_Empty_List
(Freeze_Nodes
) then
8691 -- When the current scope is transient, insert the freeze nodes
8692 -- prior to the expression that produced them. Transient scopes
8693 -- may create additional declarations when finalizing objects
8694 -- or managing the secondary stack. Inserting the freeze nodes
8695 -- of those constructs prior to the scope would result in a
8696 -- freeze-before-declaration, therefore the freeze node must
8697 -- remain interleaved with their constructs.
8699 if Scope_Is_Transient
then
8700 Insert_Actions
(N
, Freeze_Nodes
);
8702 elsif No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
8703 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
8706 Append_List
(Freeze_Nodes
,
8707 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
8715 -- Now we have the right place to do the freezing. First, a special
8716 -- adjustment, if we are in spec-expression analysis mode, these freeze
8717 -- actions must not be thrown away (normally all inserted actions are
8718 -- thrown away in this mode. However, the freeze actions are from static
8719 -- expressions and one of the important reasons we are doing this
8720 -- special analysis is to get these freeze actions. Therefore we turn
8721 -- off the In_Spec_Expression mode to propagate these freeze actions.
8722 -- This also means they get properly analyzed and expanded.
8724 In_Spec_Expression
:= False;
8726 -- Freeze the subtype mark before a qualified expression on an
8727 -- allocator as per AARM 13.14(4.a). This is needed in particular to
8728 -- generate predicate functions.
8730 if Present
(Allocator_Typ
) then
8731 Freeze_Before
(P
, Allocator_Typ
);
8734 -- Freeze the designated type of an allocator (RM 13.14(13))
8736 if Present
(Desig_Typ
) then
8737 Freeze_Before
(P
, Desig_Typ
);
8740 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
8741 -- the enumeration representation clause exception in the loop above.
8743 if Present
(Typ
) then
8744 Freeze_Before
(P
, Typ
);
8747 -- Freeze name if one is present (RM 13.14(11))
8749 if Present
(Nam
) then
8750 Freeze_Before
(P
, Nam
);
8753 -- Restore In_Spec_Expression flag
8755 In_Spec_Expression
:= In_Spec_Exp
;
8756 end Freeze_Expression
;
8758 -----------------------
8759 -- Freeze_Expr_Types --
8760 -----------------------
8762 procedure Freeze_Expr_Types
8763 (Def_Id
: Entity_Id
;
8768 function Cloned_Expression
return Node_Id
;
8769 -- Build a duplicate of the expression of the return statement that has
8770 -- no defining entities shared with the original expression.
8772 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
8773 -- Freeze all types referenced in the subtree rooted at Node
8775 -----------------------
8776 -- Cloned_Expression --
8777 -----------------------
8779 function Cloned_Expression
return Node_Id
is
8780 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
8781 -- Tree traversal routine that clones the defining identifier of
8782 -- iterator and loop parameter specification nodes.
8788 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
8791 N_Iterator_Specification | N_Loop_Parameter_Specification
8793 Set_Defining_Identifier
8794 (Node
, New_Copy
(Defining_Identifier
(Node
)));
8800 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
8804 Dup_Expr
: constant Node_Id
:= New_Copy_Tree
(Expr
);
8806 -- Start of processing for Cloned_Expression
8809 -- We must duplicate the expression with semantic information to
8810 -- inherit the decoration of global entities in generic instances.
8811 -- Set the parent of the new node to be the parent of the original
8812 -- to get the proper context, which is needed for complete error
8813 -- reporting and for semantic analysis.
8815 Set_Parent
(Dup_Expr
, Parent
(Expr
));
8817 -- Replace the defining identifier of iterators and loop param
8818 -- specifications by a clone to ensure that the cloned expression
8819 -- and the original expression don't have shared identifiers;
8820 -- otherwise, as part of the preanalysis of the expression, these
8821 -- shared identifiers may be left decorated with itypes which
8822 -- will not be available in the tree passed to the backend.
8824 Clone_Def_Ids
(Dup_Expr
);
8827 end Cloned_Expression
;
8829 ----------------------
8830 -- Freeze_Type_Refs --
8831 ----------------------
8833 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
8834 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
);
8835 -- Check that Typ is fully declared and freeze it if so
8837 ---------------------------
8838 -- Check_And_Freeze_Type --
8839 ---------------------------
8841 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
) is
8843 -- Skip Itypes created by the preanalysis, and itypes whose
8844 -- scope is another type (i.e. component subtypes that depend
8845 -- on a discriminant),
8848 and then (Scope_Within_Or_Same
(Scope
(Typ
), Def_Id
)
8849 or else Is_Type
(Scope
(Typ
)))
8854 -- This provides a better error message than generating primitives
8855 -- whose compilation fails much later. Refine the error message if
8858 Check_Fully_Declared
(Typ
, Node
);
8860 if Error_Posted
(Node
) then
8861 if Has_Private_Component
(Typ
)
8862 and then not Is_Private_Type
(Typ
)
8864 Error_Msg_NE
("\type& has private component", Node
, Typ
);
8868 Freeze_Before
(N
, Typ
);
8870 end Check_And_Freeze_Type
;
8872 -- Start of processing for Freeze_Type_Refs
8875 -- Check that a type referenced by an entity can be frozen
8877 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
8878 -- The entity itself may be a type, as in a membership test
8879 -- or an attribute reference. Freezing its own type would be
8880 -- incomplete if the entity is derived or an extension.
8882 if Is_Type
(Entity
(Node
)) then
8883 Check_And_Freeze_Type
(Entity
(Node
));
8886 Check_And_Freeze_Type
(Etype
(Entity
(Node
)));
8889 -- Check that the enclosing record type can be frozen
8891 if Ekind
(Entity
(Node
)) in E_Component | E_Discriminant
then
8892 Check_And_Freeze_Type
(Scope
(Entity
(Node
)));
8895 -- Freezing an access type does not freeze the designated type, but
8896 -- freezing conversions between access to interfaces requires that
8897 -- the interface types themselves be frozen, so that dispatch table
8898 -- entities are properly created.
8900 -- Unclear whether a more general rule is needed ???
8902 elsif Nkind
(Node
) = N_Type_Conversion
8903 and then Is_Access_Type
(Etype
(Node
))
8904 and then Is_Interface
(Designated_Type
(Etype
(Node
)))
8906 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
8909 -- An implicit dereference freezes the designated type. In the case
8910 -- of a dispatching call whose controlling argument is an access
8911 -- type, the dereference is not made explicit, so we must check for
8912 -- such a call and freeze the designated type.
8914 if Nkind
(Node
) in N_Has_Etype
8915 and then Present
(Etype
(Node
))
8916 and then Is_Access_Type
(Etype
(Node
))
8918 if Nkind
(Parent
(Node
)) = N_Function_Call
8919 and then Node
= Controlling_Argument
(Parent
(Node
))
8921 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
8923 -- An explicit dereference freezes the designated type as well,
8924 -- even though that type is not attached to an entity in the
8927 elsif Nkind
(Parent
(Node
)) = N_Explicit_Dereference
then
8928 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
8931 -- An iterator specification freezes the iterator type, even though
8932 -- that type is not attached to an entity in the construct.
8934 elsif Nkind
(Node
) in N_Has_Etype
8935 and then Nkind
(Parent
(Node
)) = N_Iterator_Specification
8936 and then Node
= Name
(Parent
(Node
))
8939 Iter
: constant Node_Id
:=
8940 Find_Value_Of_Aspect
(Etype
(Node
), Aspect_Default_Iterator
);
8943 if Present
(Iter
) then
8944 Check_And_Freeze_Type
(Etype
(Iter
));
8949 -- No point in posting several errors on the same expression
8951 if Serious_Errors_Detected
> 0 then
8956 end Freeze_Type_Refs
;
8958 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
8962 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Def_Id
);
8963 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Def_Id
);
8964 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
8966 -- Start of processing for Freeze_Expr_Types
8969 -- Preanalyze a duplicate of the expression to have available the
8970 -- minimum decoration needed to locate referenced unfrozen types
8971 -- without adding any decoration to the function expression.
8973 -- This routine is also applied to expressions in the contract for
8974 -- the subprogram. If that happens when expanding the code for
8975 -- pre/postconditions during expansion of the subprogram body, the
8976 -- subprogram is already installed.
8978 if Def_Id
/= Current_Scope
then
8979 Push_Scope
(Def_Id
);
8980 Install_Formals
(Def_Id
);
8982 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
8985 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
8988 -- Restore certain attributes of Def_Id since the preanalysis may
8989 -- have introduced itypes to this scope, thus modifying attributes
8990 -- First_Entity and Last_Entity.
8992 Set_First_Entity
(Def_Id
, Saved_First_Entity
);
8993 Set_Last_Entity
(Def_Id
, Saved_Last_Entity
);
8995 if Present
(Last_Entity
(Def_Id
)) then
8996 Set_Next_Entity
(Last_Entity
(Def_Id
), Empty
);
8999 -- Freeze all types referenced in the expression
9001 Freeze_References
(Dup_Expr
);
9002 end Freeze_Expr_Types
;
9004 -----------------------------
9005 -- Freeze_Fixed_Point_Type --
9006 -----------------------------
9008 -- Certain fixed-point types and subtypes, including implicit base types
9009 -- and declared first subtypes, have not yet set up a range. This is
9010 -- because the range cannot be set until the Small and Size values are
9011 -- known, and these are not known till the type is frozen.
9013 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
9014 -- whose bounds are unanalyzed real literals. This routine will recognize
9015 -- this case, and transform this range node into a properly typed range
9016 -- with properly analyzed and resolved values.
9018 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
9019 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
9020 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
9021 Hi
: constant Node_Id
:= High_Bound
(Rng
);
9022 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
9023 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
9024 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
9025 BHi
: constant Node_Id
:= High_Bound
(Brng
);
9026 Ftyp
: constant Entity_Id
:= Underlying_Type
(First_Subtype
(Typ
));
9035 -- Save original bounds (for shaving tests)
9038 -- Actual size chosen
9040 function Fsize
(Lov
, Hiv
: Ureal
) return Int
;
9041 -- Returns size of type with given bounds. Also leaves these
9042 -- bounds set as the current bounds of the Typ.
9044 function Larger
(A
, B
: Ureal
) return Boolean;
9045 -- Returns true if A > B with a margin of Typ'Small
9047 function Smaller
(A
, B
: Ureal
) return Boolean;
9048 -- Returns true if A < B with a margin of Typ'Small
9054 function Fsize
(Lov
, Hiv
: Ureal
) return Int
is
9056 Set_Realval
(Lo
, Lov
);
9057 Set_Realval
(Hi
, Hiv
);
9058 return Minimum_Size
(Typ
);
9065 function Larger
(A
, B
: Ureal
) return Boolean is
9067 return A
> B
and then A
- Small_Value
(Typ
) > B
;
9074 function Smaller
(A
, B
: Ureal
) return Boolean is
9076 return A
< B
and then A
+ Small_Value
(Typ
) < B
;
9079 -- Start of processing for Freeze_Fixed_Point_Type
9082 -- The type, or its first subtype if we are freezing the anonymous
9083 -- base, may have a delayed Small aspect. It must be analyzed now,
9084 -- so that all characteristics of the type (size, bounds) can be
9085 -- computed and validated in the call to Minimum_Size that follows.
9087 if Has_Delayed_Aspects
(Ftyp
) then
9088 Analyze_Aspects_At_Freeze_Point
(Ftyp
);
9089 Set_Has_Delayed_Aspects
(Ftyp
, False);
9092 -- Inherit the Small value from the first subtype in any case
9095 Set_Small_Value
(Typ
, Small_Value
(Ftyp
));
9098 -- If Esize of a subtype has not previously been set, set it now
9100 if not Known_Esize
(Typ
) then
9101 Atype
:= Ancestor_Subtype
(Typ
);
9103 if Present
(Atype
) then
9104 Set_Esize
(Typ
, Esize
(Atype
));
9106 Copy_Esize
(To
=> Typ
, From
=> Btyp
);
9110 -- Immediate return if the range is already analyzed. This means that
9111 -- the range is already set, and does not need to be computed by this
9114 if Analyzed
(Rng
) then
9118 -- Immediate return if either of the bounds raises Constraint_Error
9120 if Raises_Constraint_Error
(Lo
)
9121 or else Raises_Constraint_Error
(Hi
)
9126 Small
:= Small_Value
(Typ
);
9127 Loval
:= Realval
(Lo
);
9128 Hival
:= Realval
(Hi
);
9133 -- Ordinary fixed-point case
9135 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
9137 -- For the ordinary fixed-point case, we are allowed to fudge the
9138 -- end-points up or down by small. Generally we prefer to fudge up,
9139 -- i.e. widen the bounds for non-model numbers so that the end points
9140 -- are included. However there are cases in which this cannot be
9141 -- done, and indeed cases in which we may need to narrow the bounds.
9142 -- The following circuit makes the decision.
9144 -- Note: our terminology here is that Incl_EP means that the bounds
9145 -- are widened by Small if necessary to include the end points, and
9146 -- Excl_EP means that the bounds are narrowed by Small to exclude the
9147 -- end-points if this reduces the size.
9149 -- Note that in the Incl case, all we care about is including the
9150 -- end-points. In the Excl case, we want to narrow the bounds as
9151 -- much as permitted by the RM, to give the smallest possible size.
9154 Loval_Incl_EP
: Ureal
;
9155 Hival_Incl_EP
: Ureal
;
9157 Loval_Excl_EP
: Ureal
;
9158 Hival_Excl_EP
: Ureal
;
9168 -- First step. Base types are required to be symmetrical. Right
9169 -- now, the base type range is a copy of the first subtype range.
9170 -- This will be corrected before we are done, but right away we
9171 -- need to deal with the case where both bounds are non-negative.
9172 -- In this case, we set the low bound to the negative of the high
9173 -- bound, to make sure that the size is computed to include the
9174 -- required sign. Note that we do not need to worry about the
9175 -- case of both bounds negative, because the sign will be dealt
9176 -- with anyway. Furthermore we can't just go making such a bound
9177 -- symmetrical, since in a twos-complement system, there is an
9178 -- extra negative value which could not be accommodated on the
9182 and then not UR_Is_Negative
(Loval
)
9183 and then Hival
> Loval
9186 Set_Realval
(Lo
, Loval
);
9189 -- Compute the fudged bounds. If the bound is a model number, (or
9190 -- greater if given low bound, smaller if high bound) then we do
9191 -- nothing to include it, but we are allowed to backoff to the
9192 -- next adjacent model number when we exclude it. If it is not a
9193 -- model number then we straddle the two values with the model
9194 -- numbers on either side.
9196 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
9198 if UR_Ge
(Loval
, Model_Num
) then
9199 Loval_Incl_EP
:= Model_Num
;
9201 Loval_Incl_EP
:= Model_Num
- Small
;
9204 -- The low value excluding the end point is Small greater, but
9205 -- we do not do this exclusion if the low value is positive,
9206 -- since it can't help the size and could actually hurt by
9207 -- crossing the high bound.
9209 if UR_Is_Negative
(Loval_Incl_EP
) then
9210 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
9212 -- If the value went from negative to zero, then we have the
9213 -- case where Loval_Incl_EP is the model number just below
9214 -- zero, so we want to stick to the negative value for the
9215 -- base type to maintain the condition that the size will
9216 -- include signed values.
9219 and then UR_Is_Zero
(Loval_Excl_EP
)
9221 Loval_Excl_EP
:= Loval_Incl_EP
;
9225 Loval_Excl_EP
:= Loval_Incl_EP
;
9228 -- Similar processing for upper bound and high value
9230 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
9232 if UR_Le
(Hival
, Model_Num
) then
9233 Hival_Incl_EP
:= Model_Num
;
9235 Hival_Incl_EP
:= Model_Num
+ Small
;
9238 if UR_Is_Positive
(Hival_Incl_EP
) then
9239 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
9241 Hival_Excl_EP
:= Hival_Incl_EP
;
9244 -- One further adjustment is needed. In the case of subtypes, we
9245 -- cannot go outside the range of the base type, or we get
9246 -- peculiarities, and the base type range is already set. This
9247 -- only applies to the Incl values, since clearly the Excl values
9248 -- are already as restricted as they are allowed to be.
9251 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
9252 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
9255 -- Get size including and excluding end points
9257 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
9258 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
9260 -- No need to exclude end-points if it does not reduce size
9262 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
9263 Loval_Excl_EP
:= Loval_Incl_EP
;
9266 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
9267 Hival_Excl_EP
:= Hival_Incl_EP
;
9270 -- Now we set the actual size to be used. We want to use the
9271 -- bounds fudged up to include the end-points but only if this
9272 -- can be done without violating a specifically given size
9273 -- size clause or causing an unacceptable increase in size.
9275 -- Case of size clause given
9277 if Has_Size_Clause
(Typ
) then
9279 -- Use the inclusive size only if it is consistent with
9280 -- the explicitly specified size.
9282 if Size_Incl_EP
<= RM_Size
(Typ
) then
9283 Actual_Lo
:= Loval_Incl_EP
;
9284 Actual_Hi
:= Hival_Incl_EP
;
9285 Actual_Size
:= Size_Incl_EP
;
9287 -- If the inclusive size is too large, we try excluding
9288 -- the end-points (will be caught later if does not work).
9291 Actual_Lo
:= Loval_Excl_EP
;
9292 Actual_Hi
:= Hival_Excl_EP
;
9293 Actual_Size
:= Size_Excl_EP
;
9296 -- Case of size clause not given
9299 -- If we have a base type whose corresponding first subtype
9300 -- has an explicit size that is large enough to include our
9301 -- end-points, then do so. There is no point in working hard
9302 -- to get a base type whose size is smaller than the specified
9303 -- size of the first subtype.
9305 if Has_Size_Clause
(Ftyp
)
9306 and then Size_Incl_EP
<= Esize
(Ftyp
)
9308 Actual_Size
:= Size_Incl_EP
;
9309 Actual_Lo
:= Loval_Incl_EP
;
9310 Actual_Hi
:= Hival_Incl_EP
;
9312 -- If excluding the end-points makes the size smaller and
9313 -- results in a size of 8,16,32,64, then we take the smaller
9314 -- size. For the 64 case, this is compulsory. For the other
9315 -- cases, it seems reasonable. We like to include end points
9316 -- if we can, but not at the expense of moving to the next
9317 -- natural boundary of size.
9319 elsif Size_Incl_EP
/= Size_Excl_EP
9320 and then Addressable
(Size_Excl_EP
)
9322 Actual_Size
:= Size_Excl_EP
;
9323 Actual_Lo
:= Loval_Excl_EP
;
9324 Actual_Hi
:= Hival_Excl_EP
;
9326 -- Otherwise we can definitely include the end points
9329 Actual_Size
:= Size_Incl_EP
;
9330 Actual_Lo
:= Loval_Incl_EP
;
9331 Actual_Hi
:= Hival_Incl_EP
;
9334 -- One pathological case: normally we never fudge a low bound
9335 -- down, since it would seem to increase the size (if it has
9336 -- any effect), but for ranges containing single value, or no
9337 -- values, the high bound can be small too large. Consider:
9339 -- type t is delta 2.0**(-14)
9340 -- range 131072.0 .. 0;
9342 -- That lower bound is *just* outside the range of 32 bits, and
9343 -- does need fudging down in this case. Note that the bounds
9344 -- will always have crossed here, since the high bound will be
9345 -- fudged down if necessary, as in the case of:
9347 -- type t is delta 2.0**(-14)
9348 -- range 131072.0 .. 131072.0;
9350 -- So we detect the situation by looking for crossed bounds,
9351 -- and if the bounds are crossed, and the low bound is greater
9352 -- than zero, we will always back it off by small, since this
9353 -- is completely harmless.
9355 if Actual_Lo
> Actual_Hi
then
9356 if UR_Is_Positive
(Actual_Lo
) then
9357 Actual_Lo
:= Loval_Incl_EP
- Small
;
9358 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9360 -- And of course, we need to do exactly the same parallel
9361 -- fudge for flat ranges in the negative region.
9363 elsif UR_Is_Negative
(Actual_Hi
) then
9364 Actual_Hi
:= Hival_Incl_EP
+ Small
;
9365 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
9370 Set_Realval
(Lo
, Actual_Lo
);
9371 Set_Realval
(Hi
, Actual_Hi
);
9374 -- Enforce some limitations for ordinary fixed-point types. They come
9375 -- from an exact algorithm used to implement Text_IO.Fixed_IO and the
9376 -- Fore, Image and Value attributes. The requirement on the Small is
9377 -- to lie in the range 2**(-(Siz - 1)) .. 2**(Siz - 1) for a type of
9378 -- Siz bits (Siz=32,64,128) and the requirement on the bounds is to
9379 -- be smaller in magnitude than 10.0**N * 2**(Siz - 1), where N is
9380 -- given by the formula N = floor ((Siz - 1) * log 2 / log 10).
9382 -- If the bounds of a 32-bit type are too large, force 64-bit type
9384 if Actual_Size
<= 32
9385 and then Small
<= Ureal_2_31
9386 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_2_10_18
)
9387 or else Larger
(Expr_Value_R
(Hi
), Ureal_2_10_18
))
9392 -- If the bounds of a 64-bit type are too large, force 128-bit type
9394 if System_Max_Integer_Size
= 128
9395 and then Actual_Size
<= 64
9396 and then Small
<= Ureal_2_63
9397 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
)
9398 or else Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
))
9403 -- Give error messages for first subtypes and not base types, as the
9404 -- bounds of base types are always maximum for their size, see below.
9406 if System_Max_Integer_Size
< 128 and then Typ
/= Btyp
then
9408 -- See the 128-bit case below for the reason why we cannot test
9409 -- against the 2**(-63) .. 2**63 range. This quirk should have
9410 -- been kludged around as in the 128-bit case below, but it was
9411 -- not and we end up with a ludicrous range as a result???
9413 if Small
< Ureal_2_M_80
then
9414 Error_Msg_Name_1
:= Name_Small
;
9416 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", Typ
);
9418 elsif Small
> Ureal_2_80
then
9419 Error_Msg_Name_1
:= Name_Small
;
9421 ("`&''%` too large, maximum allowed is 2.0'*'*80", Typ
);
9424 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
) then
9425 Error_Msg_Name_1
:= Name_First
;
9427 ("`&''%` too small, minimum allowed is -9.0E+36", Typ
);
9430 if Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
) then
9431 Error_Msg_Name_1
:= Name_Last
;
9433 ("`&''%` too large, maximum allowed is 9.0E+36", Typ
);
9436 elsif System_Max_Integer_Size
= 128 and then Typ
/= Btyp
then
9438 -- ACATS c35902d tests a delta equal to 2**(-(Max_Mantissa + 1))
9439 -- but we cannot really support anything smaller than Fine_Delta
9440 -- because of the way we implement I/O for fixed point types???
9442 if Small
= Ureal_2_M_128
then
9445 elsif Small
< Ureal_2_M_127
then
9446 Error_Msg_Name_1
:= Name_Small
;
9448 ("`&''%` too small, minimum allowed is 2.0'*'*(-127)", Typ
);
9450 elsif Small
> Ureal_2_127
then
9451 Error_Msg_Name_1
:= Name_Small
;
9453 ("`&''%` too large, maximum allowed is 2.0'*'*127", Typ
);
9457 and then (Norm_Num
(Small
) > Uint_2
** 127
9458 or else Norm_Den
(Small
) > Uint_2
** 127)
9459 and then Small
/= Ureal_2_M_128
9461 Error_Msg_Name_1
:= Name_Small
;
9463 ("`&''%` not the ratio of two 128-bit integers", Typ
);
9466 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_10_76
) then
9467 Error_Msg_Name_1
:= Name_First
;
9469 ("`&''%` too small, minimum allowed is -1.0E+76", Typ
);
9472 if Larger
(Expr_Value_R
(Hi
), Ureal_10_76
) then
9473 Error_Msg_Name_1
:= Name_Last
;
9475 ("`&''%` too large, maximum allowed is 1.0E+76", Typ
);
9479 -- For the decimal case, none of this fudging is required, since there
9480 -- are no end-point problems in the decimal case (the end-points are
9481 -- always included).
9484 Actual_Size
:= Fsize
(Loval
, Hival
);
9487 -- At this stage, the actual size has been calculated and the proper
9488 -- required bounds are stored in the low and high bounds.
9490 if Actual_Size
> System_Max_Integer_Size
then
9491 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
9492 Error_Msg_Uint_2
:= UI_From_Int
(System_Max_Integer_Size
);
9494 ("size required (^) for type& too large, maximum allowed is ^",
9496 Actual_Size
:= System_Max_Integer_Size
;
9499 -- Check size against explicit given size
9501 if Has_Size_Clause
(Typ
) then
9502 if Actual_Size
> RM_Size
(Typ
) then
9503 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9504 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
9506 ("size given (^) for type& too small, minimum allowed is ^",
9507 Size_Clause
(Typ
), Typ
);
9510 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
9513 -- Increase size to next natural boundary if no size clause given
9516 if Actual_Size
<= 8 then
9518 elsif Actual_Size
<= 16 then
9520 elsif Actual_Size
<= 32 then
9522 elsif Actual_Size
<= 64 then
9528 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9529 Adjust_Esize_For_Alignment
(Typ
);
9532 -- If we have a base type, then expand the bounds so that they extend to
9533 -- the full width of the allocated size in bits, to avoid junk range
9534 -- checks on intermediate computations.
9537 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
9538 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
9541 -- Final step is to reanalyze the bounds using the proper type
9542 -- and set the Corresponding_Integer_Value fields of the literals.
9544 Set_Etype
(Lo
, Empty
);
9545 Set_Analyzed
(Lo
, False);
9548 -- Resolve with universal fixed if the base type, and with the base
9549 -- type if we are freezing a subtype. Note we can't resolve the base
9550 -- type with itself, that would be a reference before definition.
9551 -- The resolution of the bounds of a subtype, if they are given by real
9552 -- literals, includes the setting of the Corresponding_Integer_Value,
9553 -- as for other literals of a fixed-point type.
9556 Resolve
(Lo
, Universal_Fixed
);
9557 Set_Corresponding_Integer_Value
9558 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
9563 -- Similar processing for high bound
9565 Set_Etype
(Hi
, Empty
);
9566 Set_Analyzed
(Hi
, False);
9570 Resolve
(Hi
, Universal_Fixed
);
9571 Set_Corresponding_Integer_Value
9572 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
9577 -- Set type of range to correspond to bounds
9579 Set_Etype
(Rng
, Etype
(Lo
));
9581 -- Set Esize to calculated size if not set already
9583 if not Known_Esize
(Typ
) then
9584 Set_Esize
(Typ
, UI_From_Int
(Actual_Size
));
9587 -- Set RM_Size if not already set. If already set, check value
9590 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
9593 if Known_RM_Size
(Typ
) then
9594 if RM_Size
(Typ
) < Minsiz
then
9595 Error_Msg_Uint_1
:= RM_Size
(Typ
);
9596 Error_Msg_Uint_2
:= Minsiz
;
9598 ("size given (^) for type& too small, minimum allowed is ^",
9599 Size_Clause
(Typ
), Typ
);
9603 Set_RM_Size
(Typ
, Minsiz
);
9607 -- Check for shaving
9609 if Comes_From_Source
(Typ
) then
9611 -- In SPARK mode the given bounds must be strictly representable
9613 if SPARK_Mode
= On
then
9614 if Orig_Lo
< Expr_Value_R
(Lo
) then
9616 ("declared low bound of type & is outside type range",
9620 if Orig_Hi
> Expr_Value_R
(Hi
) then
9622 ("declared high bound of type & is outside type range",
9627 if Orig_Lo
< Expr_Value_R
(Lo
) then
9629 ("declared low bound of type & is outside type range??", Typ
);
9631 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
9634 if Orig_Hi
> Expr_Value_R
(Hi
) then
9636 ("declared high bound of type & is outside type range??",
9639 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
9643 end Freeze_Fixed_Point_Type
;
9649 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
9653 Set_Has_Delayed_Freeze
(T
);
9654 L
:= Freeze_Entity
(T
, N
);
9656 if Is_Non_Empty_List
(L
) then
9657 Insert_Actions
(N
, L
);
9661 --------------------------
9662 -- Freeze_Static_Object --
9663 --------------------------
9665 procedure Freeze_Static_Object
(E
: Entity_Id
) is
9667 Cannot_Be_Static
: exception;
9668 -- Exception raised if the type of a static object cannot be made
9669 -- static. This happens if the type depends on non-global objects.
9671 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
9672 -- Called to ensure that an expression used as part of a type definition
9673 -- is statically allocatable, which means that the expression type is
9674 -- statically allocatable, and the expression is either static, or a
9675 -- reference to a library level constant.
9677 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
9678 -- Called to mark a type as static, checking that it is possible
9679 -- to set the type as static. If it is not possible, then the
9680 -- exception Cannot_Be_Static is raised.
9682 -----------------------------
9683 -- Ensure_Expression_Is_SA --
9684 -----------------------------
9686 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
9690 Ensure_Type_Is_SA
(Etype
(N
));
9692 if Is_OK_Static_Expression
(N
) then
9695 elsif Nkind
(N
) = N_Identifier
then
9699 and then Ekind
(Ent
) = E_Constant
9700 and then Is_Library_Level_Entity
(Ent
)
9706 raise Cannot_Be_Static
;
9707 end Ensure_Expression_Is_SA
;
9709 -----------------------
9710 -- Ensure_Type_Is_SA --
9711 -----------------------
9713 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
9718 -- If type is library level, we are all set
9720 if Is_Library_Level_Entity
(Typ
) then
9724 -- We are also OK if the type already marked as statically allocated,
9725 -- which means we processed it before.
9727 if Is_Statically_Allocated
(Typ
) then
9731 -- Mark type as statically allocated
9733 Set_Is_Statically_Allocated
(Typ
);
9735 -- Check that it is safe to statically allocate this type
9737 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
9738 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
9739 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
9741 elsif Is_Array_Type
(Typ
) then
9742 N
:= First_Index
(Typ
);
9743 while Present
(N
) loop
9744 Ensure_Type_Is_SA
(Etype
(N
));
9748 Ensure_Type_Is_SA
(Component_Type
(Typ
));
9750 elsif Is_Access_Type
(Typ
) then
9751 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
9755 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
9758 if T
/= Standard_Void_Type
then
9759 Ensure_Type_Is_SA
(T
);
9762 F
:= First_Formal
(Designated_Type
(Typ
));
9763 while Present
(F
) loop
9764 Ensure_Type_Is_SA
(Etype
(F
));
9770 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
9773 elsif Is_Record_Type
(Typ
) then
9774 C
:= First_Entity
(Typ
);
9775 while Present
(C
) loop
9776 if Ekind
(C
) = E_Discriminant
9777 or else Ekind
(C
) = E_Component
9779 Ensure_Type_Is_SA
(Etype
(C
));
9781 elsif Is_Type
(C
) then
9782 Ensure_Type_Is_SA
(C
);
9788 elsif Ekind
(Typ
) = E_Subprogram_Type
then
9789 Ensure_Type_Is_SA
(Etype
(Typ
));
9791 C
:= First_Formal
(Typ
);
9792 while Present
(C
) loop
9793 Ensure_Type_Is_SA
(Etype
(C
));
9798 raise Cannot_Be_Static
;
9800 end Ensure_Type_Is_SA
;
9802 -- Start of processing for Freeze_Static_Object
9805 Ensure_Type_Is_SA
(Etype
(E
));
9808 when Cannot_Be_Static
=>
9810 -- If the object that cannot be static is imported or exported, then
9811 -- issue an error message saying that this object cannot be imported
9812 -- or exported. If it has an address clause it is an overlay in the
9813 -- current partition and the static requirement is not relevant.
9814 -- Do not issue any error message when ignoring rep clauses.
9816 if Ignore_Rep_Clauses
then
9819 elsif Is_Imported
(E
) then
9820 if No
(Address_Clause
(E
)) then
9822 ("& cannot be imported (local type is not constant)", E
);
9825 -- Otherwise must be exported, something is wrong if compiler
9826 -- is marking something as statically allocated which cannot be).
9828 else pragma Assert
(Is_Exported
(E
));
9830 ("& cannot be exported (local type is not constant)", E
);
9832 end Freeze_Static_Object
;
9834 -----------------------
9835 -- Freeze_Subprogram --
9836 -----------------------
9838 procedure Freeze_Subprogram
(E
: Entity_Id
) is
9839 function Check_Extra_Formals
(E
: Entity_Id
) return Boolean;
9840 -- Return True if the decoration of the attributes associated with extra
9841 -- formals are properly set.
9843 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
);
9844 -- Set the conventions of all anonymous access-to-subprogram formals and
9845 -- result subtype of subprogram Subp_Id to the convention of Subp_Id.
9847 -------------------------
9848 -- Check_Extra_Formals --
9849 -------------------------
9851 function Check_Extra_Formals
(E
: Entity_Id
) return Boolean is
9852 Last_Formal
: Entity_Id
:= Empty
;
9854 Has_Extra_Formals
: Boolean := False;
9857 -- No check required if expansion is disabled because extra
9858 -- formals are only generated when we are generating code.
9859 -- See Create_Extra_Formals.
9861 if not Expander_Active
then
9865 -- Check attribute Extra_Formal: If available, it must be set only
9866 -- on the last formal of E.
9868 Formal
:= First_Formal
(E
);
9869 while Present
(Formal
) loop
9870 if Present
(Extra_Formal
(Formal
)) then
9871 if Has_Extra_Formals
then
9875 Has_Extra_Formals
:= True;
9878 Last_Formal
:= Formal
;
9879 Next_Formal
(Formal
);
9882 -- Check attribute Extra_Accessibility_Of_Result
9884 if Ekind
(E
) in E_Function | E_Subprogram_Type
9885 and then Needs_Result_Accessibility_Level
(E
)
9886 and then No
(Extra_Accessibility_Of_Result
(E
))
9891 -- Check attribute Extra_Formals: If E has extra formals, then this
9892 -- attribute must point to the first extra formal of E.
9894 if Has_Extra_Formals
then
9895 return Present
(Extra_Formals
(E
))
9896 and then Present
(Extra_Formal
(Last_Formal
))
9897 and then Extra_Formal
(Last_Formal
) = Extra_Formals
(E
);
9899 -- When E has no formals, the first extra formal is available through
9900 -- the Extra_Formals attribute.
9902 elsif Present
(Extra_Formals
(E
)) then
9903 return No
(First_Formal
(E
));
9908 end Check_Extra_Formals
;
9910 ----------------------------
9911 -- Set_Profile_Convention --
9912 ----------------------------
9914 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
) is
9915 Conv
: constant Convention_Id
:= Convention
(Subp_Id
);
9917 procedure Set_Type_Convention
(Typ
: Entity_Id
);
9918 -- Set the convention of anonymous access-to-subprogram type Typ and
9919 -- its designated type to Conv.
9921 -------------------------
9922 -- Set_Type_Convention --
9923 -------------------------
9925 procedure Set_Type_Convention
(Typ
: Entity_Id
) is
9927 -- Set the convention on both the anonymous access-to-subprogram
9928 -- type and the subprogram type it points to because both types
9929 -- participate in conformance-related checks.
9931 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
9932 Set_Convention
(Typ
, Conv
);
9933 Set_Convention
(Designated_Type
(Typ
), Conv
);
9935 end Set_Type_Convention
;
9941 -- Start of processing for Set_Profile_Convention
9944 Formal
:= First_Formal
(Subp_Id
);
9945 while Present
(Formal
) loop
9946 Set_Type_Convention
(Etype
(Formal
));
9947 Next_Formal
(Formal
);
9950 if Ekind
(Subp_Id
) = E_Function
then
9951 Set_Type_Convention
(Etype
(Subp_Id
));
9953 end Set_Profile_Convention
;
9960 -- Start of processing for Freeze_Subprogram
9963 -- Subprogram may not have an address clause unless it is imported
9965 if Present
(Address_Clause
(E
)) then
9966 if not Is_Imported
(E
) then
9968 ("address clause can only be given for imported subprogram",
9969 Name
(Address_Clause
(E
)));
9973 -- Reset the Pure indication on an imported subprogram unless an
9974 -- explicit Pure_Function pragma was present or the subprogram is an
9975 -- intrinsic. We do this because otherwise it is an insidious error
9976 -- to call a non-pure function from pure unit and have calls
9977 -- mysteriously optimized away. What happens here is that the Import
9978 -- can bypass the normal check to ensure that pure units call only pure
9981 -- The reason for the intrinsic exception is that in general, intrinsic
9982 -- functions (such as shifts) are pure anyway. The only exceptions are
9983 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
9984 -- in any case, so no problem arises.
9987 and then Is_Pure
(E
)
9988 and then not Has_Pragma_Pure_Function
(E
)
9989 and then not Is_Intrinsic_Subprogram
(E
)
9991 Set_Is_Pure
(E
, False);
9994 -- For C++ constructors check that their external name has been given
9995 -- (either in pragma CPP_Constructor or in a pragma import).
9997 if Is_Constructor
(E
)
9998 and then Convention
(E
) = Convention_CPP
10000 (No
(Interface_Name
(E
))
10001 or else String_Equal
10002 (L
=> Strval
(Interface_Name
(E
)),
10003 R
=> Strval
(Get_Default_External_Name
(E
))))
10006 ("'C++ constructor must have external name or link name", E
);
10009 -- We also reset the Pure indication on a subprogram with an Address
10010 -- parameter, because the parameter may be used as a pointer and the
10011 -- referenced data may change even if the address value does not.
10013 -- Note that if the programmer gave an explicit Pure_Function pragma,
10014 -- then we believe the programmer, and leave the subprogram Pure. We
10015 -- also suppress this check on run-time files.
10018 and then Is_Subprogram
(E
)
10019 and then not Has_Pragma_Pure_Function
(E
)
10020 and then not Is_Internal_Unit
(Current_Sem_Unit
)
10022 Check_Function_With_Address_Parameter
(E
);
10025 -- Ensure that all anonymous access-to-subprogram types inherit the
10026 -- convention of their related subprogram (RM 6.3.1(13.1/5)). This is
10027 -- not done for a defaulted convention Ada because those types also
10028 -- default to Ada. Convention Protected must not be propagated when
10029 -- the subprogram is an entry because this would be illegal. The only
10030 -- way to force convention Protected on these kinds of types is to
10031 -- include keyword "protected" in the access definition. Conventions
10032 -- Entry and Intrinsic are also not propagated (specified by AI12-0207).
10034 if Convention
(E
) /= Convention_Ada
10035 and then Convention
(E
) /= Convention_Protected
10036 and then Convention
(E
) /= Convention_Entry
10037 and then Convention
(E
) /= Convention_Intrinsic
10039 Set_Profile_Convention
(E
);
10042 -- For non-foreign convention subprograms, this is where we create
10043 -- the extra formals (for accessibility level and constrained bit
10044 -- information). We delay this till the freeze point precisely so
10045 -- that we know the convention.
10047 if not Has_Foreign_Convention
(E
) then
10048 if No
(Extra_Formals
(E
)) then
10050 -- Extra formals are shared by derived subprograms; therefore, if
10051 -- the ultimate alias of E has been frozen before E then the extra
10052 -- formals have been added, but the attribute Extra_Formals is
10053 -- still unset (and must be set now).
10055 if Present
(Alias
(E
))
10056 and then Is_Frozen
(Ultimate_Alias
(E
))
10057 and then Present
(Extra_Formals
(Ultimate_Alias
(E
)))
10058 and then Last_Formal
(Ultimate_Alias
(E
)) = Last_Formal
(E
)
10060 Set_Extra_Formals
(E
, Extra_Formals
(Ultimate_Alias
(E
)));
10062 if Ekind
(E
) = E_Function
then
10063 Set_Extra_Accessibility_Of_Result
(E
,
10064 Extra_Accessibility_Of_Result
(Ultimate_Alias
(E
)));
10067 Create_Extra_Formals
(E
);
10071 pragma Assert
(Check_Extra_Formals
(E
));
10072 Set_Mechanisms
(E
);
10074 -- If this is convention Ada and a Valued_Procedure, that's odd
10076 if Ekind
(E
) = E_Procedure
10077 and then Is_Valued_Procedure
(E
)
10078 and then Convention
(E
) = Convention_Ada
10079 and then Warn_On_Export_Import
10082 ("??Valued_Procedure has no effect for convention Ada", E
);
10083 Set_Is_Valued_Procedure
(E
, False);
10086 -- Case of foreign convention
10089 Set_Mechanisms
(E
);
10091 -- For foreign conventions, warn about return of unconstrained array
10093 if Ekind
(E
) = E_Function
then
10094 Retype
:= Underlying_Type
(Etype
(E
));
10096 -- If no return type, probably some other error, e.g. a
10097 -- missing full declaration, so ignore.
10099 if No
(Retype
) then
10102 -- If the return type is generic, we have emitted a warning
10103 -- earlier on, and there is nothing else to check here. Specific
10104 -- instantiations may lead to erroneous behavior.
10106 elsif Is_Generic_Type
(Etype
(E
)) then
10109 -- Display warning if returning unconstrained array
10111 elsif Is_Array_Type
(Retype
)
10112 and then not Is_Constrained
(Retype
)
10114 -- Check appropriate warning is enabled (should we check for
10115 -- Warnings (Off) on specific entities here, probably so???)
10117 and then Warn_On_Export_Import
10120 ("?x?foreign convention function& should not return " &
10121 "unconstrained array", E
);
10126 -- If any of the formals for an exported foreign convention
10127 -- subprogram have defaults, then emit an appropriate warning since
10128 -- this is odd (default cannot be used from non-Ada code)
10130 if Is_Exported
(E
) then
10131 F
:= First_Formal
(E
);
10132 while Present
(F
) loop
10133 if Warn_On_Export_Import
10134 and then Present
(Default_Value
(F
))
10137 ("?x?parameter cannot be defaulted in non-Ada call",
10138 Default_Value
(F
));
10146 -- Pragma Inline_Always is disallowed for dispatching subprograms
10147 -- because the address of such subprograms is saved in the dispatch
10148 -- table to support dispatching calls, and dispatching calls cannot
10149 -- be inlined. This is consistent with the restriction against using
10150 -- 'Access or 'Address on an Inline_Always subprogram.
10152 if Is_Dispatching_Operation
(E
)
10153 and then Has_Pragma_Inline_Always
(E
)
10156 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
10159 -- Because of the implicit representation of inherited predefined
10160 -- operators in the front-end, the overriding status of the operation
10161 -- may be affected when a full view of a type is analyzed, and this is
10162 -- not captured by the analysis of the corresponding type declaration.
10163 -- Therefore the correctness of a not-overriding indicator must be
10164 -- rechecked when the subprogram is frozen.
10166 if Nkind
(E
) = N_Defining_Operator_Symbol
10167 and then not Error_Posted
(Parent
(E
))
10169 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
10172 Retype
:= Get_Fullest_View
(Etype
(E
));
10174 if Transform_Function_Array
10175 and then Nkind
(Parent
(E
)) = N_Function_Specification
10176 and then Is_Array_Type
(Retype
)
10177 and then Is_Constrained
(Retype
)
10178 and then not Is_Unchecked_Conversion_Instance
(E
)
10179 and then not Rewritten_For_C
(E
)
10181 Build_Procedure_Form
(Unit_Declaration_Node
(E
));
10183 end Freeze_Subprogram
;
10185 ----------------------
10186 -- Is_Fully_Defined --
10187 ----------------------
10189 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
10191 if Ekind
(T
) = E_Class_Wide_Type
then
10192 return Is_Fully_Defined
(Etype
(T
));
10194 elsif Is_Array_Type
(T
) then
10195 return Is_Fully_Defined
(Component_Type
(T
));
10197 elsif Is_Record_Type
(T
)
10198 and not Is_Private_Type
(T
)
10200 -- Verify that the record type has no components with private types
10201 -- without completion.
10207 Comp
:= First_Component
(T
);
10208 while Present
(Comp
) loop
10209 if not Is_Fully_Defined
(Etype
(Comp
)) then
10213 Next_Component
(Comp
);
10218 -- For the designated type of an access to subprogram, all types in
10219 -- the profile must be fully defined.
10221 elsif Ekind
(T
) = E_Subprogram_Type
then
10226 F
:= First_Formal
(T
);
10227 while Present
(F
) loop
10228 if not Is_Fully_Defined
(Etype
(F
)) then
10235 return Is_Fully_Defined
(Etype
(T
));
10239 return not Is_Private_Type
(T
)
10240 or else Present
(Full_View
(Base_Type
(T
)));
10242 end Is_Fully_Defined
;
10244 ---------------------------------
10245 -- Process_Default_Expressions --
10246 ---------------------------------
10248 procedure Process_Default_Expressions
10250 After
: in out Node_Id
)
10252 Loc
: constant Source_Ptr
:= Sloc
(E
);
10259 Set_Default_Expressions_Processed
(E
);
10261 -- A subprogram instance and its associated anonymous subprogram share
10262 -- their signature. The default expression functions are defined in the
10263 -- wrapper packages for the anonymous subprogram, and should not be
10264 -- generated again for the instance.
10266 if Is_Generic_Instance
(E
)
10267 and then Present
(Alias
(E
))
10268 and then Default_Expressions_Processed
(Alias
(E
))
10273 Formal
:= First_Formal
(E
);
10274 while Present
(Formal
) loop
10275 if Present
(Default_Value
(Formal
)) then
10277 -- We work with a copy of the default expression because we
10278 -- do not want to disturb the original, since this would mess
10279 -- up the conformance checking.
10281 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
10283 -- The analysis of the expression may generate insert actions,
10284 -- which of course must not be executed. We wrap those actions
10285 -- in a procedure that is not called, and later on eliminated.
10286 -- The following cases have no side effects, and are analyzed
10289 if Nkind
(Dcopy
) = N_Identifier
10290 or else Nkind
(Dcopy
) in N_Expanded_Name
10291 | N_Integer_Literal
10292 | N_Character_Literal
10295 or else (Nkind
(Dcopy
) = N_Attribute_Reference
10296 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
10297 or else Known_Null
(Dcopy
)
10299 -- If there is no default function, we must still do a full
10300 -- analyze call on the default value, to ensure that all error
10301 -- checks are performed, e.g. those associated with static
10302 -- evaluation. Note: this branch will always be taken if the
10303 -- analyzer is turned off (but we still need the error checks).
10305 -- Note: the setting of parent here is to meet the requirement
10306 -- that we can only analyze the expression while attached to
10307 -- the tree. Really the requirement is that the parent chain
10308 -- be set, we don't actually need to be in the tree.
10310 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
10313 -- Default expressions are resolved with their own type if the
10314 -- context is generic, to avoid anomalies with private types.
10316 if Ekind
(Scope
(E
)) = E_Generic_Package
then
10319 Resolve
(Dcopy
, Etype
(Formal
));
10322 -- If that resolved expression will raise constraint error,
10323 -- then flag the default value as raising constraint error.
10324 -- This allows a proper error message on the calls.
10326 if Raises_Constraint_Error
(Dcopy
) then
10327 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
10330 -- If the default is a parameterless call, we use the name of
10331 -- the called function directly, and there is no body to build.
10333 elsif Nkind
(Dcopy
) = N_Function_Call
10334 and then No
(Parameter_Associations
(Dcopy
))
10338 -- Else construct and analyze the body of a wrapper procedure
10339 -- that contains an object declaration to hold the expression.
10340 -- Given that this is done only to complete the analysis, it is
10341 -- simpler to build a procedure than a function which might
10342 -- involve secondary stack expansion.
10345 Dnam
:= Make_Temporary
(Loc
, 'D');
10348 Make_Subprogram_Body
(Loc
,
10350 Make_Procedure_Specification
(Loc
,
10351 Defining_Unit_Name
=> Dnam
),
10353 Declarations
=> New_List
(
10354 Make_Object_Declaration
(Loc
,
10355 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
10356 Object_Definition
=>
10357 New_Occurrence_Of
(Etype
(Formal
), Loc
),
10358 Expression
=> New_Copy_Tree
(Dcopy
))),
10360 Handled_Statement_Sequence
=>
10361 Make_Handled_Sequence_Of_Statements
(Loc
,
10362 Statements
=> Empty_List
));
10364 Set_Scope
(Dnam
, Scope
(E
));
10365 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
10366 Set_Is_Eliminated
(Dnam
);
10367 Insert_After
(After
, Dbody
);
10373 Next_Formal
(Formal
);
10375 end Process_Default_Expressions
;
10377 ----------------------------------------
10378 -- Set_Component_Alignment_If_Not_Set --
10379 ----------------------------------------
10381 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
10383 -- Ignore if not base type, subtypes don't need anything
10385 if Typ
/= Base_Type
(Typ
) then
10389 -- Do not override existing representation
10391 if Is_Packed
(Typ
) then
10394 elsif Has_Specified_Layout
(Typ
) then
10397 elsif Component_Alignment
(Typ
) /= Calign_Default
then
10401 Set_Component_Alignment
10402 (Typ
, Scope_Stack
.Table
10403 (Scope_Stack
.Last
).Component_Alignment_Default
);
10405 end Set_Component_Alignment_If_Not_Set
;
10407 --------------------------
10408 -- Set_SSO_From_Default --
10409 --------------------------
10411 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
10412 Reversed
: Boolean;
10415 -- Set default SSO for an array or record base type, except in case of
10416 -- a type extension (which always inherits the SSO of its parent type).
10418 if Is_Base_Type
(T
)
10419 and then (Is_Array_Type
(T
)
10420 or else (Is_Record_Type
(T
)
10421 and then not (Is_Tagged_Type
(T
)
10422 and then Is_Derived_Type
(T
))))
10425 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
10427 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
10429 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
10431 -- For a record type, if bit order is specified explicitly,
10432 -- then do not set SSO from default if not consistent. Note that
10433 -- we do not want to look at a Bit_Order attribute definition
10434 -- for a parent: if we were to inherit Bit_Order, then both
10435 -- SSO_Set_*_By_Default flags would have been cleared already
10436 -- (by Inherit_Aspects_At_Freeze_Point).
10439 (Is_Record_Type
(T
)
10441 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
10442 and then Reverse_Bit_Order
(T
) /= Reversed
)
10444 -- If flags cause reverse storage order, then set the result. Note
10445 -- that we would have ignored the pragma setting the non default
10446 -- storage order in any case, hence the assertion at this point.
10449 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
10451 Set_Reverse_Storage_Order
(T
, Reversed
);
10453 -- For a record type, also set reversed bit order. Note: if a bit
10454 -- order has been specified explicitly, then this is a no-op.
10456 if Is_Record_Type
(T
) then
10457 Set_Reverse_Bit_Order
(T
, Reversed
);
10461 end Set_SSO_From_Default
;
10467 procedure Undelay_Type
(T
: Entity_Id
) is
10469 Set_Has_Delayed_Freeze
(T
, False);
10470 Set_Freeze_Node
(T
, Empty
);
10472 -- Since we don't want T to have a Freeze_Node, we don't want its
10473 -- Full_View or Corresponding_Record_Type to have one either.
10475 -- ??? Fundamentally, this whole handling is unpleasant. What we really
10476 -- want is to be sure that for an Itype that's part of record R and is a
10477 -- subtype of type T, that it's frozen after the later of the freeze
10478 -- points of R and T. We have no way of doing that directly, so what we
10479 -- do is force most such Itypes to be frozen as part of freezing R via
10480 -- this procedure and only delay the ones that need to be delayed
10481 -- (mostly the designated types of access types that are defined as part
10484 if Is_Private_Type
(T
)
10485 and then Present
(Full_View
(T
))
10486 and then Is_Itype
(Full_View
(T
))
10487 and then Is_Record_Type
(Scope
(Full_View
(T
)))
10489 Undelay_Type
(Full_View
(T
));
10492 if Is_Concurrent_Type
(T
)
10493 and then Present
(Corresponding_Record_Type
(T
))
10494 and then Is_Itype
(Corresponding_Record_Type
(T
))
10495 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
10497 Undelay_Type
(Corresponding_Record_Type
(T
));
10505 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
) is
10506 Ent
: constant Entity_Id
:= Entity
(Nam
);
10507 -- The object to which the address clause applies
10510 Old
: Entity_Id
:= Empty
;
10514 -- No warning if address clause overlay warnings are off
10516 if not Address_Clause_Overlay_Warnings
then
10520 -- No warning if there is an explicit initialization
10522 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
10524 if Present
(Init
) and then Comes_From_Source
(Init
) then
10528 -- We only give the warning for non-imported entities of a type for
10529 -- which a non-null base init proc is defined, or for objects of access
10530 -- types with implicit null initialization, or when Normalize_Scalars
10531 -- applies and the type is scalar or a string type (the latter being
10532 -- tested for because predefined String types are initialized by inline
10533 -- code rather than by an init_proc). Note that we do not give the
10534 -- warning for Initialize_Scalars, since we suppressed initialization
10535 -- in this case. Also, do not warn if Suppress_Initialization is set
10536 -- either on the type, or on the object via pragma or aspect.
10539 and then not Is_Imported
(Ent
)
10540 and then not Initialization_Suppressed
(Typ
)
10541 and then not (Ekind
(Ent
) = E_Variable
10542 and then Initialization_Suppressed
(Ent
))
10543 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
10544 or else Is_Access_Type
(Typ
)
10545 or else (Normalize_Scalars
10546 and then (Is_Scalar_Type
(Typ
)
10547 or else Is_String_Type
(Typ
))))
10549 if Nkind
(Expr
) = N_Attribute_Reference
10550 and then Is_Entity_Name
(Prefix
(Expr
))
10552 Old
:= Entity
(Prefix
(Expr
));
10554 elsif Is_Entity_Name
(Expr
)
10555 and then Ekind
(Entity
(Expr
)) = E_Constant
10557 Decl
:= Declaration_Node
(Entity
(Expr
));
10559 if Nkind
(Decl
) = N_Object_Declaration
10560 and then Present
(Expression
(Decl
))
10561 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
10562 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
10564 Old
:= Entity
(Prefix
(Expression
(Decl
)));
10566 elsif Nkind
(Expr
) = N_Function_Call
then
10570 -- A function call (most likely to To_Address) is probably not an
10571 -- overlay, so skip warning. Ditto if the function call was inlined
10572 -- and transformed into an entity.
10574 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
10578 -- If a pragma Import follows, we assume that it is for the current
10579 -- target of the address clause, and skip the warning. There may be
10580 -- a source pragma or an aspect that specifies import and generates
10581 -- the corresponding pragma. These will indicate that the entity is
10582 -- imported and that is checked above so that the spurious warning
10583 -- (generated when the entity is frozen) will be suppressed. The
10584 -- pragma may be attached to the aspect, so it is not yet a list
10587 if Is_List_Member
(Parent
(Expr
)) then
10588 Decl
:= Next
(Parent
(Expr
));
10591 and then Nkind
(Decl
) = N_Pragma
10592 and then Pragma_Name
(Decl
) = Name_Import
10598 -- Otherwise give warning message
10600 if Present
(Old
) then
10601 Error_Msg_Node_2
:= Old
;
10603 ("default initialization of & may modify &?o?",
10607 ("default initialization of & may modify overlaid storage?o?",
10611 -- Add friendly warning if initialization comes from a packed array
10614 if Is_Record_Type
(Typ
) then
10619 Comp
:= First_Component
(Typ
);
10620 while Present
(Comp
) loop
10621 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
10622 and then Present
(Expression
(Parent
(Comp
)))
10625 elsif Is_Array_Type
(Etype
(Comp
))
10626 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
10629 ("\packed array component& " &
10630 "will be initialized to zero??",
10634 Next_Component
(Comp
);
10641 ("\use pragma Import for & to " &
10642 "suppress initialization (RM B.1(24))??",