1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, 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 Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Exp_Ch3
; use Exp_Ch3
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Exp_Pakd
; use Exp_Pakd
;
37 with Exp_Util
; use Exp_Util
;
38 with Exp_Tss
; use Exp_Tss
;
39 with Ghost
; use Ghost
;
40 with Layout
; use Layout
;
42 with Namet
; use Namet
;
43 with Nlists
; use Nlists
;
44 with Nmake
; use Nmake
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Aux
; use Sem_Aux
;
51 with Sem_Cat
; use Sem_Cat
;
52 with Sem_Ch3
; use Sem_Ch3
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch7
; use Sem_Ch7
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Ch13
; use Sem_Ch13
;
57 with Sem_Eval
; use Sem_Eval
;
58 with Sem_Mech
; use Sem_Mech
;
59 with Sem_Prag
; use Sem_Prag
;
60 with Sem_Res
; use Sem_Res
;
61 with Sem_Util
; use Sem_Util
;
62 with Sinfo
; use Sinfo
;
63 with Snames
; use Snames
;
64 with Stand
; use Stand
;
65 with Stringt
; use Stringt
;
66 with Targparm
; use Targparm
;
67 with Tbuild
; use Tbuild
;
68 with Ttypes
; use Ttypes
;
69 with Uintp
; use Uintp
;
70 with Urealp
; use Urealp
;
71 with Warnsw
; use Warnsw
;
73 package body Freeze
is
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
80 -- Typ is a type that is being frozen. If no size clause is given,
81 -- but a default Esize has been computed, then this default Esize is
82 -- adjusted up if necessary to be consistent with a given alignment,
83 -- but never to a value greater than System_Max_Integer_Size. This is
84 -- used for all discrete types and for fixed-point types.
86 procedure Build_And_Analyze_Renamed_Body
89 After
: in out Node_Id
);
90 -- Build body for a renaming declaration, insert in tree and analyze
92 procedure Check_Address_Clause
(E
: Entity_Id
);
93 -- Apply legality checks to address clauses for object declarations,
94 -- at the point the object is frozen. Also ensure any initialization is
95 -- performed only after the object has been frozen.
97 procedure Check_Component_Storage_Order
98 (Encl_Type
: Entity_Id
;
101 Comp_ADC_Present
: out Boolean);
102 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
103 -- clause, verify that the component type has an explicit and compatible
104 -- attribute/aspect. For arrays, Comp is Empty; for records, it is the
105 -- entity of the component under consideration. For an Encl_Type that
106 -- does not have a Scalar_Storage_Order attribute definition clause,
107 -- verify that the component also does not have such a clause.
108 -- ADC is the attribute definition clause if present (or Empty). On return,
109 -- Comp_ADC_Present is set True if the component has a Scalar_Storage_Order
110 -- attribute definition clause.
112 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
113 -- As each entity is frozen, this routine is called to deal with the
114 -- setting of Debug_Info_Needed for the entity. This flag is set if
115 -- the entity comes from source, or if we are in Debug_Generated_Code
116 -- mode or if the -gnatdV debug flag is set. However, it never sets
117 -- the flag if Debug_Info_Off is set. This procedure also ensures that
118 -- subsidiary entities have the flag set as required.
120 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
);
121 -- When an expression function is frozen by a use of it, the expression
122 -- itself is frozen. Check that the expression does not include references
123 -- to deferred constants without completion. We report this at the freeze
124 -- point of the function, to provide a better error message.
126 -- In most cases the expression itself is frozen by the time the function
127 -- itself is frozen, because the formals will be frozen by then. However,
128 -- Attribute references to outer types are freeze points for those types;
129 -- this routine generates the required freeze nodes for them.
131 procedure Check_Inherited_Conditions
(R
: Entity_Id
);
132 -- For a tagged derived type, create wrappers for inherited operations
133 -- that have a class-wide condition, so it can be properly rewritten if
134 -- it involves calls to other overriding primitives.
136 procedure Check_Strict_Alignment
(E
: Entity_Id
);
137 -- E is a base type. If E is tagged or has a component that is aliased
138 -- or tagged or contains something this is aliased or tagged, set
141 procedure Check_Unsigned_Type
(E
: Entity_Id
);
142 pragma Inline
(Check_Unsigned_Type
);
143 -- If E is a fixed-point or discrete type, then all the necessary work
144 -- to freeze it is completed except for possible setting of the flag
145 -- Is_Unsigned_Type, which is done by this procedure. The call has no
146 -- effect if the entity E is not a discrete or fixed-point type.
148 procedure Freeze_And_Append
151 Result
: in out List_Id
);
152 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
153 -- nodes to Result, modifying Result from No_List if necessary. N has
154 -- the same usage as in Freeze_Entity.
156 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
157 -- Freeze enumeration type. The Esize field is set as processing
158 -- proceeds (i.e. set by default when the type is declared and then
159 -- adjusted by rep clauses. What this procedure does is to make sure
160 -- that if a foreign convention is specified, and no specific size
161 -- is given, then the size must be at least Integer'Size.
163 procedure Freeze_Static_Object
(E
: Entity_Id
);
164 -- If an object is frozen which has Is_Statically_Allocated set, then
165 -- all referenced types must also be marked with this flag. This routine
166 -- is in charge of meeting this requirement for the object entity E.
168 procedure Freeze_Subprogram
(E
: Entity_Id
);
169 -- Perform freezing actions for a subprogram (create extra formals,
170 -- and set proper default mechanism values). Note that this routine
171 -- is not called for internal subprograms, for which neither of these
172 -- actions is needed (or desirable, we do not want for example to have
173 -- these extra formals present in initialization procedures, where they
174 -- would serve no purpose). In this call E is either a subprogram or
175 -- a subprogram type (i.e. an access to a subprogram).
177 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
178 -- True if T is not private and has no private components, or has a full
179 -- view. Used to determine whether the designated type of an access type
180 -- should be frozen when the access type is frozen. This is done when an
181 -- allocator is frozen, or an expression that may involve attributes of
182 -- the designated type. Otherwise freezing the access type does not freeze
183 -- the designated type.
185 procedure Process_Default_Expressions
187 After
: in out Node_Id
);
188 -- This procedure is called for each subprogram to complete processing of
189 -- default expressions at the point where all types are known to be frozen.
190 -- The expressions must be analyzed in full, to make sure that all error
191 -- processing is done (they have only been preanalyzed). If the expression
192 -- is not an entity or literal, its analysis may generate code which must
193 -- not be executed. In that case we build a function body to hold that
194 -- code. This wrapper function serves no other purpose (it used to be
195 -- called to evaluate the default, but now the default is inlined at each
198 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
199 -- Typ is a record or array type that is being frozen. This routine sets
200 -- the default component alignment from the scope stack values if the
201 -- alignment is otherwise not specified.
203 procedure Set_SSO_From_Default
(T
: Entity_Id
);
204 -- T is a record or array type that is being frozen. If it is a base type,
205 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
206 -- will be set appropriately. Note that an explicit occurrence of aspect
207 -- Scalar_Storage_Order or an explicit setting of this aspect with an
208 -- attribute definition clause occurs, then these two flags are reset in
209 -- any case, so call will have no effect.
211 procedure Undelay_Type
(T
: Entity_Id
);
212 -- T is a type of a component that we know to be an Itype. We don't want
213 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
214 -- Full_View or Corresponding_Record_Type.
216 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
);
217 -- Expr is the expression for an address clause for entity Nam whose type
218 -- is Typ. If Typ has a default initialization, and there is no explicit
219 -- initialization in the source declaration, check whether the address
220 -- clause might cause overlaying of an entity, and emit a warning on the
221 -- side effect that the initialization will cause.
223 -------------------------------
224 -- Adjust_Esize_For_Alignment --
225 -------------------------------
227 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
231 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
232 Align
:= Alignment_In_Bits
(Typ
);
234 if Align
> Esize
(Typ
) and then Align
<= System_Max_Integer_Size
then
235 Set_Esize
(Typ
, Align
);
238 end Adjust_Esize_For_Alignment
;
240 ------------------------------------
241 -- Build_And_Analyze_Renamed_Body --
242 ------------------------------------
244 procedure Build_And_Analyze_Renamed_Body
247 After
: in out Node_Id
)
249 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
250 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
252 Renamed_Subp
: Entity_Id
;
255 -- If the renamed subprogram is intrinsic, there is no need for a
256 -- wrapper body: we set the alias that will be called and expanded which
257 -- completes the declaration. This transformation is only legal if the
258 -- renamed entity has already been elaborated.
260 -- Note that it is legal for a renaming_as_body to rename an intrinsic
261 -- subprogram, as long as the renaming occurs before the new entity
262 -- is frozen (RM 8.5.4 (5)).
264 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
265 and then Is_Entity_Name
(Name
(Body_Decl
))
267 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
269 Renamed_Subp
:= Empty
;
272 if Present
(Renamed_Subp
)
273 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
275 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
276 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
278 -- We can make the renaming entity intrinsic if the renamed function
279 -- has an interface name, or if it is one of the shift/rotate
280 -- operations known to the compiler.
283 (Present
(Interface_Name
(Renamed_Subp
))
284 or else Chars
(Renamed_Subp
) in Name_Rotate_Left
288 | Name_Shift_Right_Arithmetic
)
290 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
292 if Present
(Alias
(Renamed_Subp
)) then
293 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
295 Set_Alias
(Ent
, Renamed_Subp
);
298 Set_Is_Intrinsic_Subprogram
(Ent
);
299 Set_Has_Completion
(Ent
);
302 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
303 Insert_After
(After
, Body_Node
);
304 Mark_Rewrite_Insertion
(Body_Node
);
308 end Build_And_Analyze_Renamed_Body
;
310 ------------------------
311 -- Build_Renamed_Body --
312 ------------------------
314 function Build_Renamed_Body
316 New_S
: Entity_Id
) return Node_Id
318 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
319 -- We use for the source location of the renamed body, the location of
320 -- the spec entity. It might seem more natural to use the location of
321 -- the renaming declaration itself, but that would be wrong, since then
322 -- the body we create would look as though it was created far too late,
323 -- and this could cause problems with elaboration order analysis,
324 -- particularly in connection with instantiations.
326 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
327 Nam
: constant Node_Id
:= Name
(N
);
329 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
330 Actuals
: List_Id
:= No_List
;
335 O_Formal
: Entity_Id
;
336 Param_Spec
: Node_Id
;
338 Pref
: Node_Id
:= Empty
;
339 -- If the renamed entity is a primitive operation given in prefix form,
340 -- the prefix is the target object and it has to be added as the first
341 -- actual in the generated call.
344 -- Determine the entity being renamed, which is the target of the call
345 -- statement. If the name is an explicit dereference, this is a renaming
346 -- of a subprogram type rather than a subprogram. The name itself is
349 if Nkind
(Nam
) = N_Selected_Component
then
350 Old_S
:= Entity
(Selector_Name
(Nam
));
352 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
353 Old_S
:= Etype
(Nam
);
355 elsif Nkind
(Nam
) = N_Indexed_Component
then
356 if Is_Entity_Name
(Prefix
(Nam
)) then
357 Old_S
:= Entity
(Prefix
(Nam
));
359 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
362 elsif Nkind
(Nam
) = N_Character_Literal
then
363 Old_S
:= Etype
(New_S
);
366 Old_S
:= Entity
(Nam
);
369 if Is_Entity_Name
(Nam
) then
371 -- If the renamed entity is a predefined operator, retain full name
372 -- to ensure its visibility.
374 if Ekind
(Old_S
) = E_Operator
375 and then Nkind
(Nam
) = N_Expanded_Name
377 Call_Name
:= New_Copy
(Name
(N
));
379 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
383 if Nkind
(Nam
) = N_Selected_Component
384 and then Present
(First_Formal
(Old_S
))
386 (Is_Controlling_Formal
(First_Formal
(Old_S
))
387 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
390 -- Retrieve the target object, to be added as a first actual
393 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
394 Pref
:= Prefix
(Nam
);
397 Call_Name
:= New_Copy
(Name
(N
));
400 -- Original name may have been overloaded, but is fully resolved now
402 Set_Is_Overloaded
(Call_Name
, False);
405 -- For simple renamings, subsequent calls can be expanded directly as
406 -- calls to the renamed entity. The body must be generated in any case
407 -- for calls that may appear elsewhere. This is not done in the case
408 -- where the subprogram is an instantiation because the actual proper
409 -- body has not been built yet. This is also not done in GNATprove mode
410 -- as we need to check other conditions for creating a body to inline
411 -- in that case, which are controlled in Analyze_Subprogram_Body_Helper.
413 if Ekind
(Old_S
) in E_Function | E_Procedure
414 and then Nkind
(Decl
) = N_Subprogram_Declaration
415 and then not Is_Generic_Instance
(Old_S
)
416 and then not GNATprove_Mode
418 Set_Body_To_Inline
(Decl
, Old_S
);
421 -- Check whether the return type is a limited view. If the subprogram
422 -- is already frozen the generated body may have a non-limited view
423 -- of the type, that must be used, because it is the one in the spec
424 -- of the renaming declaration.
426 if Ekind
(Old_S
) = E_Function
427 and then Is_Entity_Name
(Result_Definition
(Spec
))
430 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
432 if Has_Non_Limited_View
(Ret_Type
) then
433 Set_Result_Definition
434 (Spec
, New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
439 -- The body generated for this renaming is an internal artifact, and
440 -- does not constitute a freeze point for the called entity.
442 Set_Must_Not_Freeze
(Call_Name
);
444 Formal
:= First_Formal
(Defining_Entity
(Decl
));
446 if Present
(Pref
) then
448 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
449 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
452 -- The controlling formal may be an access parameter, or the
453 -- actual may be an access value, so adjust accordingly.
455 if Is_Access_Type
(Pref_Type
)
456 and then not Is_Access_Type
(Form_Type
)
459 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
461 elsif Is_Access_Type
(Form_Type
)
462 and then not Is_Access_Type
(Pref
)
466 Make_Attribute_Reference
(Loc
,
467 Attribute_Name
=> Name_Access
,
468 Prefix
=> Relocate_Node
(Pref
)));
470 Actuals
:= New_List
(Pref
);
474 elsif Present
(Formal
) then
481 if Present
(Formal
) then
482 while Present
(Formal
) loop
483 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
484 Next_Formal
(Formal
);
488 -- If the renamed entity is an entry, inherit its profile. For other
489 -- renamings as bodies, both profiles must be subtype conformant, so it
490 -- is not necessary to replace the profile given in the declaration.
491 -- However, default values that are aggregates are rewritten when
492 -- partially analyzed, so we recover the original aggregate to insure
493 -- that subsequent conformity checking works. Similarly, if the default
494 -- expression was constant-folded, recover the original expression.
496 Formal
:= First_Formal
(Defining_Entity
(Decl
));
498 if Present
(Formal
) then
499 O_Formal
:= First_Formal
(Old_S
);
500 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
501 while Present
(Formal
) loop
502 if Is_Entry
(Old_S
) then
503 if Nkind
(Parameter_Type
(Param_Spec
)) /=
506 Set_Etype
(Formal
, Etype
(O_Formal
));
507 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
510 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
511 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
512 Nkind
(Default_Value
(O_Formal
))
514 Set_Expression
(Param_Spec
,
515 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
518 Next_Formal
(Formal
);
519 Next_Formal
(O_Formal
);
524 -- If the renamed entity is a function, the generated body contains a
525 -- return statement. Otherwise, build a procedure call. If the entity is
526 -- an entry, subsequent analysis of the call will transform it into the
527 -- proper entry or protected operation call. If the renamed entity is
528 -- a character literal, return it directly.
530 if Ekind
(Old_S
) = E_Function
531 or else Ekind
(Old_S
) = E_Operator
532 or else (Ekind
(Old_S
) = E_Subprogram_Type
533 and then Etype
(Old_S
) /= Standard_Void_Type
)
536 Make_Simple_Return_Statement
(Loc
,
538 Make_Function_Call
(Loc
,
540 Parameter_Associations
=> Actuals
));
542 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
544 Make_Simple_Return_Statement
(Loc
,
545 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
547 elsif Nkind
(Nam
) = N_Character_Literal
then
549 Make_Simple_Return_Statement
(Loc
, Expression
=> Call_Name
);
553 Make_Procedure_Call_Statement
(Loc
,
555 Parameter_Associations
=> Actuals
);
558 -- Create entities for subprogram body and formals
560 Set_Defining_Unit_Name
(Spec
,
561 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
563 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
564 while Present
(Param_Spec
) loop
565 Set_Defining_Identifier
(Param_Spec
,
566 Make_Defining_Identifier
(Loc
,
567 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
572 Make_Subprogram_Body
(Loc
,
573 Specification
=> Spec
,
574 Declarations
=> New_List
,
575 Handled_Statement_Sequence
=>
576 Make_Handled_Sequence_Of_Statements
(Loc
,
577 Statements
=> New_List
(Call_Node
)));
579 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
581 Make_Subprogram_Declaration
(Loc
,
582 Specification
=> Specification
(N
)));
585 -- Link the body to the entity whose declaration it completes. If
586 -- the body is analyzed when the renamed entity is frozen, it may
587 -- be necessary to restore the proper scope (see package Exp_Ch13).
589 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
590 and then Present
(Corresponding_Spec
(N
))
592 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
594 Set_Corresponding_Spec
(Body_Node
, New_S
);
598 end Build_Renamed_Body
;
600 --------------------------
601 -- Check_Address_Clause --
602 --------------------------
604 procedure Check_Address_Clause
(E
: Entity_Id
) is
605 Addr
: constant Node_Id
:= Address_Clause
(E
);
606 Typ
: constant Entity_Id
:= Etype
(E
);
611 Tag_Assign
: Node_Id
;
614 if Present
(Addr
) then
616 -- For a deferred constant, the initialization value is on full view
618 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
619 Decl
:= Declaration_Node
(Full_View
(E
));
621 Decl
:= Declaration_Node
(E
);
624 Expr
:= Expression
(Addr
);
626 if Needs_Constant_Address
(Decl
, Typ
) then
627 Check_Constant_Address_Clause
(Expr
, E
);
629 -- Has_Delayed_Freeze was set on E when the address clause was
630 -- analyzed, and must remain set because we want the address
631 -- clause to be elaborated only after any entity it references
632 -- has been elaborated.
635 -- If Rep_Clauses are to be ignored, remove address clause from
636 -- list attached to entity, because it may be illegal for gigi,
637 -- for example by breaking order of elaboration.
639 if Ignore_Rep_Clauses
then
644 Rep
:= First_Rep_Item
(E
);
647 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
651 and then Next_Rep_Item
(Rep
) /= Addr
657 if Present
(Rep
) then
658 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
662 -- And now remove the address clause
664 Kill_Rep_Clause
(Addr
);
666 elsif not Error_Posted
(Expr
)
667 and then not Needs_Finalization
(Typ
)
669 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
672 Init
:= Expression
(Decl
);
674 -- If a variable, or a non-imported constant, overlays a constant
675 -- object and has an initialization value, then the initialization
676 -- may end up writing into read-only memory. Detect the cases of
677 -- statically identical values and remove the initialization. In
678 -- the other cases, give a warning. We will give other warnings
679 -- later for the variable if it is assigned.
681 if (Ekind
(E
) = E_Variable
682 or else (Ekind
(E
) = E_Constant
683 and then not Is_Imported
(E
)))
684 and then Overlays_Constant
(E
)
685 and then Present
(Init
)
692 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
694 if Ekind
(O_Ent
) = E_Constant
695 and then Etype
(O_Ent
) = Typ
696 and then Present
(Constant_Value
(O_Ent
))
697 and then Compile_Time_Compare
699 Constant_Value
(O_Ent
),
700 Assume_Valid
=> True) = EQ
702 Set_No_Initialization
(Decl
);
705 elsif Comes_From_Source
(Init
)
706 and then Address_Clause_Overlay_Warnings
708 Error_Msg_Sloc
:= Sloc
(Addr
);
710 ("??constant& may be modified via address clause#",
716 -- Remove side effects from initial expression, except in the case of
717 -- limited build-in-place calls and aggregates, which have their own
718 -- expansion elsewhere. This exception is necessary to avoid copying
722 and then not Is_Limited_View
(Typ
)
724 -- Capture initialization value at point of declaration, and make
725 -- explicit assignment legal, because object may be a constant.
727 Remove_Side_Effects
(Init
);
728 Lhs
:= New_Occurrence_Of
(E
, Sloc
(Decl
));
729 Set_Assignment_OK
(Lhs
);
731 -- Move initialization to freeze actions, once the object has
732 -- been frozen and the address clause alignment check has been
735 Append_Freeze_Action
(E
,
736 Make_Assignment_Statement
(Sloc
(Decl
),
738 Expression
=> Expression
(Decl
)));
740 Set_No_Initialization
(Decl
);
742 -- If the object is tagged, check whether the tag must be
743 -- reassigned explicitly.
745 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
746 if Present
(Tag_Assign
) then
747 Append_Freeze_Action
(E
, Tag_Assign
);
751 end Check_Address_Clause
;
753 -----------------------------
754 -- Check_Compile_Time_Size --
755 -----------------------------
757 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
759 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
760 -- Sets the compile time known size in the RM_Size field of T, checking
761 -- for a size clause that was given which attempts to give a small size.
763 function Size_Known
(T
: Entity_Id
) return Boolean;
764 -- Recursive function that does all the work
766 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
767 -- If T is a constrained subtype, its size is not known if any of its
768 -- discriminant constraints is not static and it is not a null record.
769 -- The test is conservative and doesn't check that the components are
770 -- in fact constrained by non-static discriminant values. Could be made
777 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
779 if S
> System_Max_Integer_Size
then
782 -- Check for bad size clause given
784 elsif Has_Size_Clause
(T
) then
785 if RM_Size
(T
) < S
then
786 Error_Msg_Uint_1
:= S
;
787 Error_Msg_NE
(Size_Too_Small_Message
, Size_Clause
(T
), T
);
790 -- Set size if not set already
792 elsif Unknown_RM_Size
(T
) then
801 function Size_Known
(T
: Entity_Id
) return Boolean is
809 if Size_Known_At_Compile_Time
(T
) then
812 -- Always True for elementary types, even generic formal elementary
813 -- types. We used to return False in the latter case, but the size
814 -- is known at compile time, even in the template, we just do not
815 -- know the exact size but that's not the point of this routine.
817 elsif Is_Elementary_Type
(T
) or else Is_Task_Type
(T
) then
822 elsif Is_Array_Type
(T
) then
824 -- String literals always have known size, and we can set it
826 if Ekind
(T
) = E_String_Literal_Subtype
then
828 (T
, Component_Size
(T
) * String_Literal_Length
(T
));
831 -- Unconstrained types never have known at compile time size
833 elsif not Is_Constrained
(T
) then
836 -- Don't do any recursion on type with error posted, since we may
837 -- have a malformed type that leads us into a loop.
839 elsif Error_Posted
(T
) then
842 -- Otherwise if component size unknown, then array size unknown
844 elsif not Size_Known
(Component_Type
(T
)) then
848 -- Check for all indexes static, and also compute possible size
849 -- (in case it is not greater than System_Max_Integer_Size and
850 -- thus may be packable).
853 Size
: Uint
:= Component_Size
(T
);
857 Index
:= First_Index
(T
);
858 while Present
(Index
) loop
859 if Nkind
(Index
) = N_Range
then
860 Get_Index_Bounds
(Index
, Low
, High
);
862 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
866 Low
:= Type_Low_Bound
(Etype
(Index
));
867 High
:= Type_High_Bound
(Etype
(Index
));
870 if not Compile_Time_Known_Value
(Low
)
871 or else not Compile_Time_Known_Value
(High
)
872 or else Etype
(Index
) = Any_Type
877 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
889 Set_Small_Size
(T
, Size
);
893 -- For non-generic private types, go to underlying type if present
895 elsif Is_Private_Type
(T
)
896 and then not Is_Generic_Type
(T
)
897 and then Present
(Underlying_Type
(T
))
899 -- Don't do any recursion on type with error posted, since we may
900 -- have a malformed type that leads us into a loop.
902 if Error_Posted
(T
) then
905 return Size_Known
(Underlying_Type
(T
));
910 elsif Is_Record_Type
(T
) then
912 -- A class-wide type is never considered to have a known size
914 if Is_Class_Wide_Type
(T
) then
917 -- A subtype of a variant record must not have non-static
918 -- discriminated components.
920 elsif T
/= Base_Type
(T
)
921 and then not Static_Discriminated_Components
(T
)
925 -- Don't do any recursion on type with error posted, since we may
926 -- have a malformed type that leads us into a loop.
928 elsif Error_Posted
(T
) then
932 -- Now look at the components of the record
935 -- The following two variables are used to keep track of the
936 -- size of packed records if we can tell the size of the packed
937 -- record in the front end. Packed_Size_Known is True if so far
938 -- we can figure out the size. It is initialized to True for a
939 -- packed record, unless the record has either discriminants or
940 -- independent components, or is a strict-alignment type, since
941 -- it cannot be fully packed in this case.
943 -- The reason we eliminate the discriminated case is that
944 -- we don't know the way the back end lays out discriminated
945 -- packed records. If Packed_Size_Known is True, then
946 -- Packed_Size is the size in bits so far.
948 Packed_Size_Known
: Boolean :=
950 and then not Has_Discriminants
(T
)
951 and then not Has_Independent_Components
(T
)
952 and then not Strict_Alignment
(T
);
954 Packed_Size
: Uint
:= Uint_0
;
955 -- Size in bits so far
958 -- Test for variant part present
960 if Has_Discriminants
(T
)
961 and then Present
(Parent
(T
))
962 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
963 and then Nkind
(Type_Definition
(Parent
(T
))) =
965 and then not Null_Present
(Type_Definition
(Parent
(T
)))
967 Present
(Variant_Part
968 (Component_List
(Type_Definition
(Parent
(T
)))))
970 -- If variant part is present, and type is unconstrained,
971 -- then we must have defaulted discriminants, or a size
972 -- clause must be present for the type, or else the size
973 -- is definitely not known at compile time.
975 if not Is_Constrained
(T
)
977 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
978 and then Unknown_RM_Size
(T
)
984 -- Loop through components
986 Comp
:= First_Component_Or_Discriminant
(T
);
987 while Present
(Comp
) loop
988 Ctyp
:= Etype
(Comp
);
990 -- We do not know the packed size if there is a component
991 -- clause present (we possibly could, but this would only
992 -- help in the case of a record with partial rep clauses.
993 -- That's because in the case of full rep clauses, the
994 -- size gets figured out anyway by a different circuit).
996 if Present
(Component_Clause
(Comp
)) then
997 Packed_Size_Known
:= False;
1000 -- We do not know the packed size for an independent
1001 -- component or if it is of a strict-alignment type,
1002 -- since packing does not touch these (RM 13.2(7)).
1004 if Is_Independent
(Comp
)
1005 or else Is_Independent
(Ctyp
)
1006 or else Strict_Alignment
(Ctyp
)
1008 Packed_Size_Known
:= False;
1011 -- We need to identify a component that is an array where
1012 -- the index type is an enumeration type with non-standard
1013 -- representation, and some bound of the type depends on a
1016 -- This is because gigi computes the size by doing a
1017 -- substitution of the appropriate discriminant value in
1018 -- the size expression for the base type, and gigi is not
1019 -- clever enough to evaluate the resulting expression (which
1020 -- involves a call to rep_to_pos) at compile time.
1022 -- It would be nice if gigi would either recognize that
1023 -- this expression can be computed at compile time, or
1024 -- alternatively figured out the size from the subtype
1025 -- directly, where all the information is at hand ???
1027 if Is_Array_Type
(Etype
(Comp
))
1028 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1031 Ocomp
: constant Entity_Id
:=
1032 Original_Record_Component
(Comp
);
1033 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1039 Ind
:= First_Index
(OCtyp
);
1040 while Present
(Ind
) loop
1041 Indtyp
:= Etype
(Ind
);
1043 if Is_Enumeration_Type
(Indtyp
)
1044 and then Has_Non_Standard_Rep
(Indtyp
)
1046 Lo
:= Type_Low_Bound
(Indtyp
);
1047 Hi
:= Type_High_Bound
(Indtyp
);
1049 if Is_Entity_Name
(Lo
)
1050 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1054 elsif Is_Entity_Name
(Hi
)
1055 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1066 -- Clearly size of record is not known if the size of one of
1067 -- the components is not known.
1069 if not Size_Known
(Ctyp
) then
1073 -- Accumulate packed size if possible
1075 if Packed_Size_Known
then
1077 -- We can deal with elementary types, small packed arrays
1078 -- if the representation is a modular type and also small
1079 -- record types as checked by Set_Small_Size.
1081 if Is_Elementary_Type
(Ctyp
)
1082 or else (Is_Array_Type
(Ctyp
)
1084 (Packed_Array_Impl_Type
(Ctyp
))
1085 and then Is_Modular_Integer_Type
1086 (Packed_Array_Impl_Type
(Ctyp
)))
1087 or else Is_Record_Type
(Ctyp
)
1089 -- If RM_Size is known and static, then we can keep
1090 -- accumulating the packed size.
1092 if Known_Static_RM_Size
(Ctyp
) then
1094 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1096 -- If we have a field whose RM_Size is not known then
1097 -- we can't figure out the packed size here.
1100 Packed_Size_Known
:= False;
1103 -- For other types we can't figure out the packed size
1106 Packed_Size_Known
:= False;
1110 Next_Component_Or_Discriminant
(Comp
);
1113 if Packed_Size_Known
then
1114 Set_Small_Size
(T
, Packed_Size
);
1120 -- All other cases, size not known at compile time
1127 -------------------------------------
1128 -- Static_Discriminated_Components --
1129 -------------------------------------
1131 function Static_Discriminated_Components
1132 (T
: Entity_Id
) return Boolean
1134 Constraint
: Elmt_Id
;
1137 if Has_Discriminants
(T
)
1138 and then Present
(Discriminant_Constraint
(T
))
1139 and then Present
(First_Component
(T
))
1141 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1142 while Present
(Constraint
) loop
1143 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1147 Next_Elmt
(Constraint
);
1152 end Static_Discriminated_Components
;
1154 -- Start of processing for Check_Compile_Time_Size
1157 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1158 end Check_Compile_Time_Size
;
1160 -----------------------------------
1161 -- Check_Component_Storage_Order --
1162 -----------------------------------
1164 procedure Check_Component_Storage_Order
1165 (Encl_Type
: Entity_Id
;
1168 Comp_ADC_Present
: out Boolean)
1170 Comp_Base
: Entity_Id
;
1172 Encl_Base
: Entity_Id
;
1175 Component_Aliased
: Boolean;
1177 Comp_Byte_Aligned
: Boolean := False;
1178 -- Set for the record case, True if Comp is aligned on byte boundaries
1179 -- (in which case it is allowed to have different storage order).
1181 Comp_SSO_Differs
: Boolean;
1182 -- Set True when the component is a nested composite, and it does not
1183 -- have the same scalar storage order as Encl_Type.
1188 if Present
(Comp
) then
1190 Comp_Base
:= Etype
(Comp
);
1192 if Is_Tag
(Comp
) then
1193 Comp_Byte_Aligned
:= True;
1194 Component_Aliased
:= False;
1197 -- If a component clause is present, check if the component starts
1198 -- and ends on byte boundaries. Otherwise conservatively assume it
1199 -- does so only in the case where the record is not packed.
1201 if Present
(Component_Clause
(Comp
)) then
1202 Comp_Byte_Aligned
:=
1203 (Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0)
1205 (Esize
(Comp
) mod System_Storage_Unit
= 0);
1207 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1210 Component_Aliased
:= Is_Aliased
(Comp
);
1216 Err_Node
:= Encl_Type
;
1217 Comp_Base
:= Component_Type
(Encl_Type
);
1219 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1222 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1223 -- the attribute definition clause is attached to the first subtype.
1224 -- Also, if the base type is incomplete or private, go to full view
1227 Encl_Base
:= Base_Type
(Encl_Type
);
1228 if Present
(Underlying_Type
(Encl_Base
)) then
1229 Encl_Base
:= Underlying_Type
(Encl_Base
);
1232 Comp_Base
:= Base_Type
(Comp_Base
);
1233 if Present
(Underlying_Type
(Comp_Base
)) then
1234 Comp_Base
:= Underlying_Type
(Comp_Base
);
1238 Get_Attribute_Definition_Clause
1239 (First_Subtype
(Comp_Base
), Attribute_Scalar_Storage_Order
);
1240 Comp_ADC_Present
:= Present
(Comp_ADC
);
1242 -- Case of record or array component: check storage order compatibility.
1243 -- But, if the record has Complex_Representation, then it is treated as
1244 -- a scalar in the back end so the storage order is irrelevant.
1246 if (Is_Record_Type
(Comp_Base
)
1247 and then not Has_Complex_Representation
(Comp_Base
))
1248 or else Is_Array_Type
(Comp_Base
)
1251 Reverse_Storage_Order
(Encl_Base
) /=
1252 Reverse_Storage_Order
(Comp_Base
);
1254 -- Parent and extension must have same storage order
1256 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1257 if Comp_SSO_Differs
then
1259 ("record extension must have same scalar storage order as "
1260 & "parent", Err_Node
);
1263 -- If component and composite SSO differs, check that component
1264 -- falls on byte boundaries and isn't bit packed.
1266 elsif Comp_SSO_Differs
then
1268 -- Component SSO differs from enclosing composite:
1270 -- Reject if composite is a bit-packed array, as it is rewritten
1271 -- into an array of scalars.
1273 if Is_Bit_Packed_Array
(Encl_Base
) then
1275 ("type of packed array must have same scalar storage order "
1276 & "as component", Err_Node
);
1278 -- Reject if not byte aligned
1280 elsif Is_Record_Type
(Encl_Base
)
1281 and then not Comp_Byte_Aligned
1284 ("type of non-byte-aligned component must have same scalar "
1285 & "storage order as enclosing composite", Err_Node
);
1287 -- Warn if specified only for the outer composite
1289 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1291 ("scalar storage order specified for & does not apply to "
1292 & "component?", Err_Node
, Encl_Base
);
1296 -- Enclosing type has explicit SSO: non-composite component must not
1299 elsif Present
(ADC
) and then Component_Aliased
then
1301 ("aliased component not permitted for type with explicit "
1302 & "Scalar_Storage_Order", Err_Node
);
1304 end Check_Component_Storage_Order
;
1306 -----------------------------
1307 -- Check_Debug_Info_Needed --
1308 -----------------------------
1310 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1312 if Debug_Info_Off
(T
) then
1315 elsif Comes_From_Source
(T
)
1316 or else Debug_Generated_Code
1317 or else Debug_Flag_VV
1318 or else Needs_Debug_Info
(T
)
1320 Set_Debug_Info_Needed
(T
);
1322 end Check_Debug_Info_Needed
;
1324 -------------------------------
1325 -- Check_Expression_Function --
1326 -------------------------------
1328 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1329 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1330 -- Function to search for deferred constant
1336 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1338 -- When a constant is initialized with the result of a dispatching
1339 -- call, the constant declaration is rewritten as a renaming of the
1340 -- displaced function result. This scenario is not a premature use of
1341 -- a constant even though the Has_Completion flag is not set.
1343 if Is_Entity_Name
(Nod
)
1344 and then Present
(Entity
(Nod
))
1345 and then Ekind
(Entity
(Nod
)) = E_Constant
1346 and then Scope
(Entity
(Nod
)) = Current_Scope
1347 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1348 N_Object_Declaration
1349 and then not Is_Imported
(Entity
(Nod
))
1350 and then not Has_Completion
(Entity
(Nod
))
1351 and then not Is_Frozen
(Entity
(Nod
))
1354 ("premature use of& in call or instance", N
, Entity
(Nod
));
1356 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1357 Analyze
(Prefix
(Nod
));
1359 if Is_Entity_Name
(Prefix
(Nod
))
1360 and then Is_Type
(Entity
(Prefix
(Nod
)))
1362 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1369 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1375 -- Start of processing for Check_Expression_Function
1378 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1380 -- The subprogram body created for the expression function is not
1381 -- itself a freeze point.
1383 if Scope
(Nam
) = Current_Scope
1384 and then Nkind
(Decl
) = N_Expression_Function
1385 and then Nkind
(N
) /= N_Subprogram_Body
1387 Check_Deferred
(Expression
(Decl
));
1389 end Check_Expression_Function
;
1391 --------------------------------
1392 -- Check_Inherited_Conditions --
1393 --------------------------------
1395 procedure Check_Inherited_Conditions
(R
: Entity_Id
) is
1396 Prim_Ops
: constant Elist_Id
:= Primitive_Operations
(R
);
1398 Needs_Wrapper
: Boolean;
1400 Par_Prim
: Entity_Id
;
1403 procedure Build_Inherited_Condition_Pragmas
(Subp
: Entity_Id
);
1404 -- Build corresponding pragmas for an operation whose ancestor has
1405 -- class-wide pre/postconditions. If the operation is inherited, the
1406 -- pragmas force the creation of a wrapper for the inherited operation.
1407 -- If the ancestor is being overridden, the pragmas are constructed only
1408 -- to verify their legality, in case they contain calls to other
1409 -- primitives that may haven been overridden.
1411 ---------------------------------------
1412 -- Build_Inherited_Condition_Pragmas --
1413 ---------------------------------------
1415 procedure Build_Inherited_Condition_Pragmas
(Subp
: Entity_Id
) is
1421 A_Pre
:= Get_Class_Wide_Pragma
(Par_Prim
, Pragma_Precondition
);
1423 if Present
(A_Pre
) then
1424 New_Prag
:= New_Copy_Tree
(A_Pre
);
1425 Build_Class_Wide_Expression
1428 Par_Subp
=> Par_Prim
,
1429 Adjust_Sloc
=> False,
1430 Needs_Wrapper
=> Needs_Wrapper
);
1433 and then not Comes_From_Source
(Subp
)
1434 and then Expander_Active
1436 Append
(New_Prag
, Decls
);
1440 A_Post
:= Get_Class_Wide_Pragma
(Par_Prim
, Pragma_Postcondition
);
1442 if Present
(A_Post
) then
1443 New_Prag
:= New_Copy_Tree
(A_Post
);
1444 Build_Class_Wide_Expression
1447 Par_Subp
=> Par_Prim
,
1448 Adjust_Sloc
=> False,
1449 Needs_Wrapper
=> Needs_Wrapper
);
1452 and then not Comes_From_Source
(Subp
)
1453 and then Expander_Active
1455 Append
(New_Prag
, Decls
);
1458 end Build_Inherited_Condition_Pragmas
;
1460 -- Start of processing for Check_Inherited_Conditions
1463 Op_Node
:= First_Elmt
(Prim_Ops
);
1464 while Present
(Op_Node
) loop
1465 Prim
:= Node
(Op_Node
);
1467 -- Map the overridden primitive to the overriding one. This takes
1468 -- care of all overridings and is done only once.
1470 if Present
(Overridden_Operation
(Prim
))
1471 and then Comes_From_Source
(Prim
)
1473 Par_Prim
:= Overridden_Operation
(Prim
);
1474 Update_Primitives_Mapping
(Par_Prim
, Prim
);
1477 Next_Elmt
(Op_Node
);
1480 -- Perform validity checks on the inherited conditions of overriding
1481 -- operations, for conformance with LSP, and apply SPARK-specific
1482 -- restrictions on inherited conditions.
1484 Op_Node
:= First_Elmt
(Prim_Ops
);
1485 while Present
(Op_Node
) loop
1486 Prim
:= Node
(Op_Node
);
1488 if Present
(Overridden_Operation
(Prim
))
1489 and then Comes_From_Source
(Prim
)
1491 Par_Prim
:= Overridden_Operation
(Prim
);
1493 -- Analyze the contract items of the overridden operation, before
1494 -- they are rewritten as pragmas.
1496 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1498 -- In GNATprove mode this is where we can collect the inherited
1499 -- conditions, because we do not create the Check pragmas that
1500 -- normally convey the modified class-wide conditions on
1501 -- overriding operations.
1503 if GNATprove_Mode
then
1504 Collect_Inherited_Class_Wide_Conditions
(Prim
);
1506 -- Otherwise build the corresponding pragmas to check for legality
1507 -- of the inherited condition.
1510 Build_Inherited_Condition_Pragmas
(Prim
);
1514 Next_Elmt
(Op_Node
);
1517 -- Now examine the inherited operations to check whether they require
1518 -- a wrapper to handle inherited conditions that call other primitives,
1519 -- so that LSP can be verified/enforced.
1521 Op_Node
:= First_Elmt
(Prim_Ops
);
1523 while Present
(Op_Node
) loop
1524 Decls
:= Empty_List
;
1525 Prim
:= Node
(Op_Node
);
1526 Needs_Wrapper
:= False;
1528 if not Comes_From_Source
(Prim
) and then Present
(Alias
(Prim
)) then
1529 Par_Prim
:= Alias
(Prim
);
1531 -- Analyze the contract items of the parent operation, and
1532 -- determine whether a wrapper is needed. This is determined
1533 -- when the condition is rewritten in sem_prag, using the
1534 -- mapping between overridden and overriding operations built
1535 -- in the loop above.
1537 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1538 Build_Inherited_Condition_Pragmas
(Prim
);
1542 and then not Is_Abstract_Subprogram
(Par_Prim
)
1543 and then Expander_Active
1545 -- We need to build a new primitive that overrides the inherited
1546 -- one, and whose inherited expression has been updated above.
1547 -- These expressions are the arguments of pragmas that are part
1548 -- of the declarations of the wrapper. The wrapper holds a single
1549 -- statement that is a call to the class-wide clone, where the
1550 -- controlling actuals are conversions to the corresponding type
1551 -- in the parent primitive:
1553 -- procedure New_Prim (F1 : T1; ...);
1554 -- procedure New_Prim (F1 : T1; ...) is
1555 -- pragma Check (Precondition, Expr);
1557 -- Par_Prim_Clone (Par_Type (F1), ...);
1560 -- If the primitive is a function the statement is a return
1561 -- statement with a call.
1564 Loc
: constant Source_Ptr
:= Sloc
(R
);
1565 Par_R
: constant Node_Id
:= Parent
(R
);
1571 New_Spec
:= Build_Overriding_Spec
(Par_Prim
, R
);
1573 Make_Subprogram_Declaration
(Loc
,
1574 Specification
=> New_Spec
);
1576 -- Insert the declaration and the body of the wrapper after
1577 -- type declaration that generates inherited operation. For
1578 -- a null procedure, the declaration implies a null body.
1580 if Nkind
(New_Spec
) = N_Procedure_Specification
1581 and then Null_Present
(New_Spec
)
1583 Insert_After_And_Analyze
(Par_R
, New_Decl
);
1586 -- Build body as wrapper to a call to the already built
1587 -- class-wide clone.
1590 Build_Class_Wide_Clone_Call
1591 (Loc
, Decls
, Par_Prim
, New_Spec
);
1593 Insert_List_After_And_Analyze
1594 (Par_R
, New_List
(New_Decl
, New_Body
));
1599 Next_Elmt
(Op_Node
);
1601 end Check_Inherited_Conditions
;
1603 ----------------------------
1604 -- Check_Strict_Alignment --
1605 ----------------------------
1607 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1611 -- Bit-packed array types do not require strict alignment, even if they
1612 -- are by-reference types, because they are accessed in a special way.
1614 if Is_By_Reference_Type
(E
) and then not Is_Bit_Packed_Array
(E
) then
1615 Set_Strict_Alignment
(E
);
1617 elsif Is_Array_Type
(E
) then
1618 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1620 -- ??? AI12-001: Any component of a packed type that contains an
1621 -- aliased part must be aligned according to the alignment of its
1622 -- subtype (RM 13.2(7)). This means that the following test:
1624 -- if Has_Aliased_Components (E) then
1625 -- Set_Strict_Alignment (E);
1628 -- should be implemented here. Unfortunately it would break Florist,
1629 -- which has the bad habit of overaligning all the types it declares
1630 -- on 32-bit platforms. Other legacy codebases could also be affected
1631 -- because this check has historically been missing in GNAT.
1633 elsif Is_Record_Type
(E
) then
1634 Comp
:= First_Component
(E
);
1635 while Present
(Comp
) loop
1636 if not Is_Type
(Comp
)
1637 and then (Is_Aliased
(Comp
)
1638 or else Strict_Alignment
(Etype
(Comp
)))
1640 Set_Strict_Alignment
(E
);
1644 Next_Component
(Comp
);
1647 end Check_Strict_Alignment
;
1649 -------------------------
1650 -- Check_Unsigned_Type --
1651 -------------------------
1653 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1654 Ancestor
: Entity_Id
;
1659 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1663 -- Do not attempt to analyze case where range was in error
1665 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
1669 -- The situation that is nontrivial is something like:
1671 -- subtype x1 is integer range -10 .. +10;
1672 -- subtype x2 is x1 range 0 .. V1;
1673 -- subtype x3 is x2 range V2 .. V3;
1674 -- subtype x4 is x3 range V4 .. V5;
1676 -- where Vn are variables. Here the base type is signed, but we still
1677 -- know that x4 is unsigned because of the lower bound of x2.
1679 -- The only way to deal with this is to look up the ancestor chain
1683 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1687 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1689 if Compile_Time_Known_Value
(Lo_Bound
) then
1690 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1691 Set_Is_Unsigned_Type
(E
, True);
1697 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1699 -- If no ancestor had a static lower bound, go to base type
1701 if No
(Ancestor
) then
1703 -- Note: the reason we still check for a compile time known
1704 -- value for the base type is that at least in the case of
1705 -- generic formals, we can have bounds that fail this test,
1706 -- and there may be other cases in error situations.
1708 Btyp
:= Base_Type
(E
);
1710 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1714 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1716 if Compile_Time_Known_Value
(Lo_Bound
)
1717 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1719 Set_Is_Unsigned_Type
(E
, True);
1726 end Check_Unsigned_Type
;
1728 ------------------------------
1729 -- Is_Full_Access_Aggregate --
1730 ------------------------------
1732 function Is_Full_Access_Aggregate
(N
: Node_Id
) return Boolean is
1733 Loc
: constant Source_Ptr
:= Sloc
(N
);
1742 -- Array may be qualified, so find outer context
1744 if Nkind
(Par
) = N_Qualified_Expression
then
1745 Par
:= Parent
(Par
);
1748 if not Comes_From_Source
(Par
) then
1753 when N_Assignment_Statement
=>
1754 Typ
:= Etype
(Name
(Par
));
1756 if not Is_Full_Access
(Typ
)
1757 and then not (Is_Entity_Name
(Name
(Par
))
1758 and then Is_Full_Access
(Entity
(Name
(Par
))))
1763 when N_Object_Declaration
=>
1764 Typ
:= Etype
(Defining_Identifier
(Par
));
1766 if not Is_Full_Access
(Typ
)
1767 and then not Is_Full_Access
(Defining_Identifier
(Par
))
1776 Temp
:= Make_Temporary
(Loc
, 'T', N
);
1778 Make_Object_Declaration
(Loc
,
1779 Defining_Identifier
=> Temp
,
1780 Constant_Present
=> True,
1781 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1782 Expression
=> Relocate_Node
(N
));
1783 Insert_Before
(Par
, New_N
);
1786 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1788 end Is_Full_Access_Aggregate
;
1790 -----------------------------------------------
1791 -- Explode_Initialization_Compound_Statement --
1792 -----------------------------------------------
1794 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
1795 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
1798 if Present
(Init_Stmts
)
1799 and then Nkind
(Init_Stmts
) = N_Compound_Statement
1801 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
1803 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
1804 -- just removing it, because Freeze_All may rely on this particular
1805 -- Node_Id still being present in the enclosing list to know where to
1808 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
1810 Set_Initialization_Statements
(E
, Empty
);
1812 end Explode_Initialization_Compound_Statement
;
1818 -- Note: the easy coding for this procedure would be to just build a
1819 -- single list of freeze nodes and then insert them and analyze them
1820 -- all at once. This won't work, because the analysis of earlier freeze
1821 -- nodes may recursively freeze types which would otherwise appear later
1822 -- on in the freeze list. So we must analyze and expand the freeze nodes
1823 -- as they are generated.
1825 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1826 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1827 -- This is the internal recursive routine that does freezing of entities
1828 -- (but NOT the analysis of default expressions, which should not be
1829 -- recursive, we don't want to analyze those till we are sure that ALL
1830 -- the types are frozen).
1832 --------------------
1833 -- Freeze_All_Ent --
1834 --------------------
1836 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1841 procedure Process_Flist
;
1842 -- If freeze nodes are present, insert and analyze, and reset cursor
1843 -- for next insertion.
1849 procedure Process_Flist
is
1851 if Is_Non_Empty_List
(Flist
) then
1852 Lastn
:= Next
(After
);
1853 Insert_List_After_And_Analyze
(After
, Flist
);
1855 if Present
(Lastn
) then
1856 After
:= Prev
(Lastn
);
1858 After
:= Last
(List_Containing
(After
));
1863 -- Start of processing for Freeze_All_Ent
1867 while Present
(E
) loop
1869 -- If the entity is an inner package which is not a package
1870 -- renaming, then its entities must be frozen at this point. Note
1871 -- that such entities do NOT get frozen at the end of the nested
1872 -- package itself (only library packages freeze).
1874 -- Same is true for task declarations, where anonymous records
1875 -- created for entry parameters must be frozen.
1877 if Ekind
(E
) = E_Package
1878 and then No
(Renamed_Object
(E
))
1879 and then not Is_Child_Unit
(E
)
1880 and then not Is_Frozen
(E
)
1884 Install_Visible_Declarations
(E
);
1885 Install_Private_Declarations
(E
);
1886 Freeze_All
(First_Entity
(E
), After
);
1888 End_Package_Scope
(E
);
1890 if Is_Generic_Instance
(E
)
1891 and then Has_Delayed_Freeze
(E
)
1893 Set_Has_Delayed_Freeze
(E
, False);
1894 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1897 elsif Ekind
(E
) in Task_Kind
1898 and then Nkind
(Parent
(E
)) in
1899 N_Single_Task_Declaration | N_Task_Type_Declaration
1902 Freeze_All
(First_Entity
(E
), After
);
1905 -- For a derived tagged type, we must ensure that all the
1906 -- primitive operations of the parent have been frozen, so that
1907 -- their addresses will be in the parent's dispatch table at the
1908 -- point it is inherited.
1910 elsif Ekind
(E
) = E_Record_Type
1911 and then Is_Tagged_Type
(E
)
1912 and then Is_Tagged_Type
(Etype
(E
))
1913 and then Is_Derived_Type
(E
)
1916 Prim_List
: constant Elist_Id
:=
1917 Primitive_Operations
(Etype
(E
));
1923 Prim
:= First_Elmt
(Prim_List
);
1924 while Present
(Prim
) loop
1925 Subp
:= Node
(Prim
);
1927 if Comes_From_Source
(Subp
)
1928 and then not Is_Frozen
(Subp
)
1930 Flist
:= Freeze_Entity
(Subp
, After
);
1939 if not Is_Frozen
(E
) then
1940 Flist
:= Freeze_Entity
(E
, After
);
1943 -- If already frozen, and there are delayed aspects, this is where
1944 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1945 -- for a description of how we handle aspect visibility).
1947 elsif Has_Delayed_Aspects
(E
) then
1952 Ritem
:= First_Rep_Item
(E
);
1953 while Present
(Ritem
) loop
1954 if Nkind
(Ritem
) = N_Aspect_Specification
1955 and then Entity
(Ritem
) = E
1956 and then Is_Delayed_Aspect
(Ritem
)
1958 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1961 Next_Rep_Item
(Ritem
);
1966 -- If an incomplete type is still not frozen, this may be a
1967 -- premature freezing because of a body declaration that follows.
1968 -- Indicate where the freezing took place. Freezing will happen
1969 -- if the body comes from source, but not if it is internally
1970 -- generated, for example as the body of a type invariant.
1972 -- If the freezing is caused by the end of the current declarative
1973 -- part, it is a Taft Amendment type, and there is no error.
1975 if not Is_Frozen
(E
)
1976 and then Ekind
(E
) = E_Incomplete_Type
1979 Bod
: constant Node_Id
:= Next
(After
);
1982 -- The presence of a body freezes all entities previously
1983 -- declared in the current list of declarations, but this
1984 -- does not apply if the body does not come from source.
1985 -- A type invariant is transformed into a subprogram body
1986 -- which is placed at the end of the private part of the
1987 -- current package, but this body does not freeze incomplete
1988 -- types that may be declared in this private part.
1990 if Comes_From_Source
(Bod
)
1991 and then Nkind
(Bod
) in N_Entry_Body
1998 In_Same_List
(After
, Parent
(E
))
2000 Error_Msg_Sloc
:= Sloc
(Next
(After
));
2002 ("type& is frozen# before its full declaration",
2018 -- Start of processing for Freeze_All
2021 Freeze_All_Ent
(From
, After
);
2023 -- Now that all types are frozen, we can deal with default expressions
2024 -- that require us to build a default expression functions. This is the
2025 -- point at which such functions are constructed (after all types that
2026 -- might be used in such expressions have been frozen).
2028 -- For subprograms that are renaming_as_body, we create the wrapper
2029 -- bodies as needed.
2031 -- We also add finalization chains to access types whose designated
2032 -- types are controlled. This is normally done when freezing the type,
2033 -- but this misses recursive type definitions where the later members
2034 -- of the recursion introduce controlled components.
2036 -- Loop through entities
2039 while Present
(E
) loop
2040 if Is_Subprogram
(E
) then
2041 if not Default_Expressions_Processed
(E
) then
2042 Process_Default_Expressions
(E
, After
);
2045 if not Has_Completion
(E
) then
2046 Decl
:= Unit_Declaration_Node
(E
);
2048 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
2049 if Error_Posted
(Decl
) then
2050 Set_Has_Completion
(E
);
2052 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
2055 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2056 and then Present
(Corresponding_Body
(Decl
))
2058 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
2059 N_Subprogram_Renaming_Declaration
2061 Build_And_Analyze_Renamed_Body
2062 (Decl
, Corresponding_Body
(Decl
), After
);
2066 -- Freeze the default expressions of entries, entry families, and
2067 -- protected subprograms.
2069 elsif Is_Concurrent_Type
(E
) then
2070 Item
:= First_Entity
(E
);
2071 while Present
(Item
) loop
2072 if (Is_Entry
(Item
) or else Is_Subprogram
(Item
))
2073 and then not Default_Expressions_Processed
(Item
)
2075 Process_Default_Expressions
(Item
, After
);
2082 -- Historical note: We used to create a finalization master for an
2083 -- access type whose designated type is not controlled, but contains
2084 -- private controlled compoments. This form of postprocessing is no
2085 -- longer needed because the finalization master is now created when
2086 -- the access type is frozen (see Exp_Ch3.Freeze_Type).
2092 -----------------------
2093 -- Freeze_And_Append --
2094 -----------------------
2096 procedure Freeze_And_Append
2099 Result
: in out List_Id
)
2101 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
2103 if Is_Non_Empty_List
(L
) then
2104 if Result
= No_List
then
2107 Append_List
(L
, Result
);
2110 end Freeze_And_Append
;
2116 procedure Freeze_Before
2119 Do_Freeze_Profile
: Boolean := True)
2121 -- Freeze T, then insert the generated Freeze nodes before the node N.
2122 -- Flag Freeze_Profile is used when T is an overloadable entity, and
2123 -- indicates whether its profile should be frozen at the same time.
2125 Freeze_Nodes
: constant List_Id
:=
2126 Freeze_Entity
(T
, N
, Do_Freeze_Profile
);
2127 Pack
: constant Entity_Id
:= Scope
(T
);
2130 if Ekind
(T
) = E_Function
then
2131 Check_Expression_Function
(N
, T
);
2134 if Is_Non_Empty_List
(Freeze_Nodes
) then
2136 -- If the entity is a type declared in an inner package, it may be
2137 -- frozen by an outer declaration before the package itself is
2138 -- frozen. Install the package scope to analyze the freeze nodes,
2139 -- which may include generated subprograms such as predicate
2142 if Is_Type
(T
) and then From_Nested_Package
(T
) then
2144 Install_Visible_Declarations
(Pack
);
2145 Install_Private_Declarations
(Pack
);
2146 Insert_Actions
(N
, Freeze_Nodes
);
2147 End_Package_Scope
(Pack
);
2150 Insert_Actions
(N
, Freeze_Nodes
);
2159 -- WARNING: This routine manages Ghost regions. Return statements must be
2160 -- replaced by gotos which jump to the end of the routine and restore the
2163 function Freeze_Entity
2166 Do_Freeze_Profile
: Boolean := True) return List_Id
2168 Loc
: constant Source_Ptr
:= Sloc
(N
);
2170 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2171 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
2172 -- Save the Ghost-related attributes to restore on exit
2180 Result
: List_Id
:= No_List
;
2181 -- List of freezing actions, left at No_List if none
2183 Test_E
: Entity_Id
:= E
;
2184 -- This could use a comment ???
2186 procedure Add_To_Result
(Fnod
: Node_Id
);
2187 -- Add freeze action Fnod to list Result
2189 function After_Last_Declaration
return Boolean;
2190 -- If Loc is a freeze_entity that appears after the last declaration
2191 -- in the scope, inhibit error messages on late completion.
2193 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
2194 -- Check that an Access or Unchecked_Access attribute with a prefix
2195 -- which is the current instance type can only be applied when the type
2198 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
);
2199 -- Give a warning for pragma Convention with language C or C++ applied
2200 -- to a discriminated record type. This is suppressed for the unchecked
2201 -- union case, since the whole point in this case is interface C. We
2202 -- also do not generate this within instantiations, since we will have
2203 -- generated a message on the template.
2205 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
2206 -- Give warning for modulus of 8, 16, 32, 64 or 128 given as an explicit
2207 -- integer literal without an explicit corresponding size clause. The
2208 -- caller has checked that Utype is a modular integer type.
2210 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
2211 -- Freeze array type, including freezing index and component types
2213 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
2214 -- Perform checks and generate freeze node if needed for a constant or
2215 -- variable declared by an object declaration.
2217 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
2218 -- Create Freeze_Generic_Entity nodes for types declared in a generic
2219 -- package. Recurse on inner generic packages.
2221 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
2222 -- Freeze formals and return type of subprogram. If some type in the
2223 -- profile is incomplete and we are in an instance, freezing of the
2224 -- entity will take place elsewhere, and the function returns False.
2226 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
2227 -- Freeze record type, including freezing component types, and freezing
2228 -- primitive operations if this is a tagged type.
2230 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
2231 -- Determine whether an arbitrary entity is subject to Boolean aspect
2232 -- Import and its value is specified as True.
2234 procedure Inherit_Freeze_Node
2237 -- Set type Typ's freeze node to refer to Fnode. This routine ensures
2238 -- that any attributes attached to Typ's original node are preserved.
2240 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
2241 -- If E is an entity for an imported subprogram with pre/post-conditions
2242 -- then this procedure will create a wrapper to ensure that proper run-
2243 -- time checking of the pre/postconditions. See body for details.
2249 procedure Add_To_Result
(Fnod
: Node_Id
) is
2251 Append_New_To
(Result
, Fnod
);
2254 ----------------------------
2255 -- After_Last_Declaration --
2256 ----------------------------
2258 function After_Last_Declaration
return Boolean is
2259 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2262 if Nkind
(Spec
) = N_Package_Specification
then
2263 if Present
(Private_Declarations
(Spec
)) then
2264 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2265 elsif Present
(Visible_Declarations
(Spec
)) then
2266 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2274 end After_Last_Declaration
;
2276 ----------------------------
2277 -- Check_Current_Instance --
2278 ----------------------------
2280 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2282 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2283 -- Determine whether Typ is compatible with the rules for aliased
2284 -- views of types as defined in RM 3.10 in the various dialects.
2286 function Process
(N
: Node_Id
) return Traverse_Result
;
2287 -- Process routine to apply check to given node
2289 -----------------------------
2290 -- Is_Aliased_View_Of_Type --
2291 -----------------------------
2293 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
2294 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
2299 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
2300 and then Limited_Present
(Type_Definition
(Typ_Decl
))
2304 -- The following paragraphs describe what a legal aliased view of
2305 -- a type is in the various dialects of Ada.
2309 -- The current instance of a limited type, and a formal parameter
2310 -- or generic formal object of a tagged type.
2312 -- Ada 95 limited type
2313 -- * Type with reserved word "limited"
2314 -- * A protected or task type
2315 -- * A composite type with limited component
2317 elsif Ada_Version
<= Ada_95
then
2318 return Is_Limited_Type
(Typ
);
2322 -- The current instance of a limited tagged type, a protected
2323 -- type, a task type, or a type that has the reserved word
2324 -- "limited" in its full definition ... a formal parameter or
2325 -- generic formal object of a tagged type.
2327 -- Ada 2005 limited type
2328 -- * Type with reserved word "limited", "synchronized", "task"
2330 -- * A composite type with limited component
2331 -- * A derived type whose parent is a non-interface limited type
2333 elsif Ada_Version
= Ada_2005
then
2335 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2337 (Is_Derived_Type
(Typ
)
2338 and then not Is_Interface
(Etype
(Typ
))
2339 and then Is_Limited_Type
(Etype
(Typ
)));
2341 -- Ada 2012 and beyond
2343 -- The current instance of an immutably limited type ... a formal
2344 -- parameter or generic formal object of a tagged type.
2346 -- Ada 2012 limited type
2347 -- * Type with reserved word "limited", "synchronized", "task"
2349 -- * A composite type with limited component
2350 -- * A derived type whose parent is a non-interface limited type
2351 -- * An incomplete view
2353 -- Ada 2012 immutably limited type
2354 -- * Explicitly limited record type
2355 -- * Record extension with "limited" present
2356 -- * Non-formal limited private type that is either tagged
2357 -- or has at least one access discriminant with a default
2359 -- * Task type, protected type or synchronized interface
2360 -- * Type derived from immutably limited type
2364 Is_Immutably_Limited_Type
(Typ
)
2365 or else Is_Incomplete_Type
(Typ
);
2367 end Is_Aliased_View_Of_Type
;
2373 function Process
(N
: Node_Id
) return Traverse_Result
is
2376 when N_Attribute_Reference
=>
2377 if Attribute_Name
(N
) in Name_Access | Name_Unchecked_Access
2378 and then Is_Entity_Name
(Prefix
(N
))
2379 and then Is_Type
(Entity
(Prefix
(N
)))
2380 and then Entity
(Prefix
(N
)) = E
2382 if Ada_Version
< Ada_2012
then
2384 ("current instance must be a limited type",
2388 ("current instance must be an immutably limited "
2389 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2403 procedure Traverse
is new Traverse_Proc
(Process
);
2407 Rec_Type
: constant Entity_Id
:=
2408 Scope
(Defining_Identifier
(Comp_Decl
));
2410 -- Start of processing for Check_Current_Instance
2413 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2414 Traverse
(Comp_Decl
);
2416 end Check_Current_Instance
;
2418 ---------------------------------
2419 -- Check_Suspicious_Convention --
2420 ---------------------------------
2422 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
) is
2424 if Has_Discriminants
(Rec_Type
)
2425 and then Is_Base_Type
(Rec_Type
)
2426 and then not Is_Unchecked_Union
(Rec_Type
)
2427 and then (Convention
(Rec_Type
) = Convention_C
2429 Convention
(Rec_Type
) = Convention_CPP
)
2430 and then Comes_From_Source
(Rec_Type
)
2431 and then not In_Instance
2432 and then not Has_Warnings_Off
(Rec_Type
)
2435 Cprag
: constant Node_Id
:=
2436 Get_Rep_Pragma
(Rec_Type
, Name_Convention
);
2440 if Present
(Cprag
) then
2441 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
2443 if Convention
(Rec_Type
) = Convention_C
then
2445 ("?x?discriminated record has no direct equivalent in "
2449 ("?x?discriminated record has no direct equivalent in "
2454 ("\?x?use of convention for type& is dubious",
2459 end Check_Suspicious_Convention
;
2461 ------------------------------
2462 -- Check_Suspicious_Modulus --
2463 ------------------------------
2465 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
2466 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
2469 if not Warn_On_Suspicious_Modulus_Value
then
2473 if Nkind
(Decl
) = N_Full_Type_Declaration
then
2475 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
2478 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
2480 Modulus
: constant Node_Id
:=
2481 Original_Node
(Expression
(Tdef
));
2484 if Nkind
(Modulus
) = N_Integer_Literal
then
2486 Modv
: constant Uint
:= Intval
(Modulus
);
2487 Sizv
: constant Uint
:= RM_Size
(Utype
);
2490 -- First case, modulus and size are the same. This
2491 -- happens if you have something like mod 32, with
2492 -- an explicit size of 32, this is for sure a case
2493 -- where the warning is given, since it is seems
2494 -- very unlikely that someone would want e.g. a
2495 -- five bit type stored in 32 bits. It is much
2496 -- more likely they wanted a 32-bit type.
2501 -- Second case, the modulus is 32 or 64 and no
2502 -- size clause is present. This is a less clear
2503 -- case for giving the warning, but in the case
2504 -- of 32/64 (5-bit or 6-bit types) these seem rare
2505 -- enough that it is a likely error (and in any
2506 -- case using 2**5 or 2**6 in these cases seems
2507 -- clearer. We don't include 8 or 16 here, simply
2508 -- because in practice 3-bit and 4-bit types are
2509 -- more common and too many false positives if
2510 -- we warn in these cases.
2512 elsif not Has_Size_Clause
(Utype
)
2513 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
2517 -- No warning needed
2523 -- If we fall through, give warning
2525 Error_Msg_Uint_1
:= Modv
;
2527 ("?M?2 '*'*^' may have been intended here",
2535 end Check_Suspicious_Modulus
;
2537 -----------------------
2538 -- Freeze_Array_Type --
2539 -----------------------
2541 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2542 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2543 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2546 Non_Standard_Enum
: Boolean := False;
2547 -- Set true if any of the index types is an enumeration type with a
2548 -- non-standard representation.
2551 Freeze_And_Append
(Ctyp
, N
, Result
);
2553 Indx
:= First_Index
(Arr
);
2554 while Present
(Indx
) loop
2555 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2557 if Is_Enumeration_Type
(Etype
(Indx
))
2558 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2560 Non_Standard_Enum
:= True;
2566 -- Processing that is done only for base types
2568 if Ekind
(Arr
) = E_Array_Type
then
2570 -- Deal with default setting of reverse storage order
2572 Set_SSO_From_Default
(Arr
);
2574 -- Propagate flags for component type
2576 if Is_Controlled
(Ctyp
)
2577 or else Has_Controlled_Component
(Ctyp
)
2579 Set_Has_Controlled_Component
(Arr
);
2582 if Has_Unchecked_Union
(Ctyp
) then
2583 Set_Has_Unchecked_Union
(Arr
);
2586 -- The array type requires its own invariant procedure in order to
2587 -- verify the component invariant over all elements. In GNATprove
2588 -- mode, the component invariants are checked by other means. They
2589 -- should not be added to the array type invariant procedure, so
2590 -- that the procedure can be used to check the array type
2591 -- invariants if any.
2593 if Has_Invariants
(Ctyp
)
2594 and then not GNATprove_Mode
2596 Set_Has_Own_Invariants
(Arr
);
2599 -- Warn for pragma Pack overriding foreign convention
2601 if Has_Foreign_Convention
(Ctyp
)
2602 and then Has_Pragma_Pack
(Arr
)
2605 CN
: constant Name_Id
:=
2606 Get_Convention_Name
(Convention
(Ctyp
));
2607 PP
: constant Node_Id
:=
2608 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2610 if Present
(PP
) then
2611 Error_Msg_Name_1
:= CN
;
2612 Error_Msg_Sloc
:= Sloc
(Arr
);
2614 ("pragma Pack affects convention % components #??", PP
);
2615 Error_Msg_Name_1
:= CN
;
2617 ("\array components may not have % compatible "
2618 & "representation??", PP
);
2623 -- Check for Aliased or Atomic_Components or Full Access with
2624 -- unsuitable packing or explicit component size clause given.
2626 if (Has_Aliased_Components
(Arr
)
2627 or else Has_Atomic_Components
(Arr
)
2628 or else Is_Full_Access
(Ctyp
))
2630 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2632 Alias_Atomic_Check
: declare
2634 procedure Complain_CS
(T
: String);
2635 -- Outputs error messages for incorrect CS clause or pragma
2636 -- Pack for aliased or full access components (T is either
2637 -- "aliased" or "atomic" or "volatile full access");
2643 procedure Complain_CS
(T
: String) is
2645 if Has_Component_Size_Clause
(Arr
) then
2647 Get_Attribute_Definition_Clause
2648 (FS
, Attribute_Component_Size
);
2651 ("incorrect component size for "
2652 & T
& " components", Clause
);
2653 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2655 ("\only allowed value is^", Clause
);
2659 ("?cannot pack " & T
& " components (RM 13.2(7))",
2660 Get_Rep_Pragma
(FS
, Name_Pack
));
2661 Set_Is_Packed
(Arr
, False);
2665 -- Start of processing for Alias_Atomic_Check
2668 -- If object size of component type isn't known, we cannot
2669 -- be sure so we defer to the back end.
2671 if not Known_Static_Esize
(Ctyp
) then
2674 -- Case where component size has no effect. First check for
2675 -- object size of component type multiple of the storage
2678 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2680 -- OK in both packing case and component size case if RM
2681 -- size is known and static and same as the object size.
2684 ((Known_Static_RM_Size
(Ctyp
)
2685 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2687 -- Or if we have an explicit component size clause and
2688 -- the component size and object size are equal.
2691 (Has_Component_Size_Clause
(Arr
)
2692 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2696 elsif Has_Aliased_Components
(Arr
) then
2697 Complain_CS
("aliased");
2699 elsif Has_Atomic_Components
(Arr
)
2700 or else Is_Atomic
(Ctyp
)
2702 Complain_CS
("atomic");
2704 elsif Is_Volatile_Full_Access
(Ctyp
) then
2705 Complain_CS
("volatile full access");
2707 end Alias_Atomic_Check
;
2710 -- Check for Independent_Components/Independent with unsuitable
2711 -- packing or explicit component size clause given.
2713 if (Has_Independent_Components
(Arr
) or else Is_Independent
(Ctyp
))
2715 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2718 -- If object size of component type isn't known, we cannot
2719 -- be sure so we defer to the back end.
2721 if not Known_Static_Esize
(Ctyp
) then
2724 -- Case where component size has no effect. First check for
2725 -- object size of component type multiple of the storage
2728 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2730 -- OK in both packing case and component size case if RM
2731 -- size is known and multiple of the storage unit size.
2734 ((Known_Static_RM_Size
(Ctyp
)
2735 and then RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
2737 -- Or if we have an explicit component size clause and
2738 -- the component size is larger than the object size.
2741 (Has_Component_Size_Clause
(Arr
)
2742 and then Component_Size
(Arr
) >= Esize
(Ctyp
)))
2747 if Has_Component_Size_Clause
(Arr
) then
2749 Get_Attribute_Definition_Clause
2750 (FS
, Attribute_Component_Size
);
2753 ("incorrect component size for "
2754 & "independent components", Clause
);
2755 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2757 ("\minimum allowed is^", Clause
);
2761 ("?cannot pack independent components (RM 13.2(7))",
2762 Get_Rep_Pragma
(FS
, Name_Pack
));
2763 Set_Is_Packed
(Arr
, False);
2769 -- If packing was requested or if the component size was
2770 -- set explicitly, then see if bit packing is required. This
2771 -- processing is only done for base types, since all of the
2772 -- representation aspects involved are type-related.
2774 -- This is not just an optimization, if we start processing the
2775 -- subtypes, they interfere with the settings on the base type
2776 -- (this is because Is_Packed has a slightly different meaning
2777 -- before and after freezing).
2785 and then Known_Static_RM_Size
(Ctyp
)
2786 and then not Has_Component_Size_Clause
(Arr
)
2788 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2790 elsif Known_Component_Size
(Arr
) then
2791 Csiz
:= Component_Size
(Arr
);
2793 elsif not Known_Static_Esize
(Ctyp
) then
2797 Esiz
:= Esize
(Ctyp
);
2799 -- We can set the component size if it is less than 16,
2800 -- rounding it up to the next storage unit size.
2804 elsif Esiz
<= 16 then
2810 -- Set component size up to match alignment if it would
2811 -- otherwise be less than the alignment. This deals with
2812 -- cases of types whose alignment exceeds their size (the
2813 -- padded type cases).
2817 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2826 -- Case of component size that may result in bit packing
2828 if 1 <= Csiz
and then Csiz
<= System_Max_Integer_Size
then
2830 Ent
: constant Entity_Id
:=
2831 First_Subtype
(Arr
);
2832 Pack_Pragma
: constant Node_Id
:=
2833 Get_Rep_Pragma
(Ent
, Name_Pack
);
2834 Comp_Size_C
: constant Node_Id
:=
2835 Get_Attribute_Definition_Clause
2836 (Ent
, Attribute_Component_Size
);
2839 -- Warn if we have pack and component size so that the
2842 -- Note: here we must check for the presence of a
2843 -- component size before checking for a Pack pragma to
2844 -- deal with the case where the array type is a derived
2845 -- type whose parent is currently private.
2847 if Present
(Comp_Size_C
)
2848 and then Has_Pragma_Pack
(Ent
)
2849 and then Warn_On_Redundant_Constructs
2851 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2853 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2855 ("\?r?explicit component size given#!", Pack_Pragma
);
2856 Set_Is_Packed
(Base_Type
(Ent
), False);
2857 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2860 -- Set component size if not already set by a component
2863 if not Present
(Comp_Size_C
) then
2864 Set_Component_Size
(Arr
, Csiz
);
2867 -- Check for base type of 8, 16, 32 bits, where an
2868 -- unsigned subtype has a length one less than the
2869 -- base type (e.g. Natural subtype of Integer).
2871 -- In such cases, if a component size was not set
2872 -- explicitly, then generate a warning.
2874 if Has_Pragma_Pack
(Arr
)
2875 and then not Present
(Comp_Size_C
)
2876 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2877 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2879 Error_Msg_Uint_1
:= Csiz
;
2881 if Present
(Pack_Pragma
) then
2883 ("??pragma Pack causes component size to be ^!",
2886 ("\??use Component_Size to set desired value!",
2891 -- Bit packing is never needed for 8, 16, 32, 64 or 128
2893 if Addressable
(Csiz
) then
2895 -- If the Esize of the component is known and equal to
2896 -- the component size then even packing is not needed.
2898 if Known_Static_Esize
(Ctyp
)
2899 and then Esize
(Ctyp
) = Csiz
2901 -- Here the array was requested to be packed, but
2902 -- the packing request had no effect whatsoever,
2903 -- so flag Is_Packed is reset.
2905 -- Note: semantically this means that we lose track
2906 -- of the fact that a derived type inherited pragma
2907 -- Pack that was non-effective, but that is fine.
2909 -- We regard a Pack pragma as a request to set a
2910 -- representation characteristic, and this request
2913 Set_Is_Packed
(Base_Type
(Arr
), False);
2914 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
2916 Set_Is_Packed
(Base_Type
(Arr
), True);
2917 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2920 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2922 -- Bit packing is not needed for multiples of the storage
2923 -- unit if the type is composite because the back end can
2924 -- byte pack composite types efficiently. That's not true
2925 -- for discrete types because every read would generate a
2926 -- lot of instructions, so we keep using the manipulation
2927 -- routines of the runtime for them.
2929 elsif Csiz
mod System_Storage_Unit
= 0
2930 and then Is_Composite_Type
(Ctyp
)
2932 Set_Is_Packed
(Base_Type
(Arr
), True);
2933 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2934 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2936 -- In all other cases, bit packing is needed
2939 Set_Is_Packed
(Base_Type
(Arr
), True);
2940 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2941 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2947 -- Warn for case of atomic type
2949 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2952 and then not Addressable
(Component_Size
(FS
))
2955 ("non-atomic components of type& may not be "
2956 & "accessible by separate tasks??", Clause
, Arr
);
2958 if Has_Component_Size_Clause
(Arr
) then
2959 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2960 (FS
, Attribute_Component_Size
));
2961 Error_Msg_N
("\because of component size clause#??", Clause
);
2963 elsif Has_Pragma_Pack
(Arr
) then
2964 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2965 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2969 -- Check for scalar storage order
2974 Check_Component_Storage_Order
2977 ADC
=> Get_Attribute_Definition_Clause
2978 (First_Subtype
(Arr
),
2979 Attribute_Scalar_Storage_Order
),
2980 Comp_ADC_Present
=> Dummy
);
2983 -- Processing that is done only for subtypes
2986 -- Acquire alignment from base type
2988 if Unknown_Alignment
(Arr
) then
2989 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2990 Adjust_Esize_Alignment
(Arr
);
2994 -- Specific checks for bit-packed arrays
2996 if Is_Bit_Packed_Array
(Arr
) then
2998 -- Check number of elements for bit-packed arrays that come from
2999 -- source and have compile time known ranges. The bit-packed
3000 -- arrays circuitry does not support arrays with more than
3001 -- Integer'Last + 1 elements, and when this restriction is
3002 -- violated, causes incorrect data access.
3004 -- For the case where this is not compile time known, a run-time
3005 -- check should be generated???
3007 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
3016 Index
:= First_Index
(Arr
);
3017 while Present
(Index
) loop
3018 Ityp
:= Etype
(Index
);
3020 -- Never generate an error if any index is of a generic
3021 -- type. We will check this in instances.
3023 if Is_Generic_Type
(Ityp
) then
3029 Make_Attribute_Reference
(Loc
,
3030 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
3031 Attribute_Name
=> Name_Range_Length
);
3032 Analyze_And_Resolve
(Ilen
);
3034 -- No attempt is made to check number of elements if not
3035 -- compile time known.
3037 if Nkind
(Ilen
) /= N_Integer_Literal
then
3042 Elmts
:= Elmts
* Intval
(Ilen
);
3046 if Elmts
> Intval
(High_Bound
3047 (Scalar_Range
(Standard_Integer
))) + 1
3050 ("bit packed array type may not have "
3051 & "more than Integer''Last+1 elements", Arr
);
3058 if Known_RM_Size
(Arr
) then
3060 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
3064 -- It is not clear if it is possible to have no size clause
3065 -- at this stage, but it is not worth worrying about. Post
3066 -- error on the entity name in the size clause if present,
3067 -- else on the type entity itself.
3069 if Present
(SizC
) then
3070 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
3072 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
3078 -- If any of the index types was an enumeration type with a non-
3079 -- standard rep clause, then we indicate that the array type is
3080 -- always packed (even if it is not bit-packed).
3082 if Non_Standard_Enum
then
3083 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
3084 Set_Is_Packed
(Base_Type
(Arr
));
3087 Set_Component_Alignment_If_Not_Set
(Arr
);
3089 -- If the array is packed and bit-packed or packed to eliminate holes
3090 -- in the non-contiguous enumeration index types, we must create the
3091 -- packed array type to be used to actually implement the type. This
3092 -- is only needed for real array types (not for string literal types,
3093 -- since they are present only for the front end).
3096 and then (Is_Bit_Packed_Array
(Arr
) or else Non_Standard_Enum
)
3097 and then Ekind
(Arr
) /= E_String_Literal_Subtype
3099 Create_Packed_Array_Impl_Type
(Arr
);
3100 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
3102 -- Make sure that we have the necessary routines to implement the
3103 -- packing, and complain now if not. Note that we only test this
3104 -- for constrained array types.
3106 if Is_Constrained
(Arr
)
3107 and then Is_Bit_Packed_Array
(Arr
)
3108 and then Present
(Packed_Array_Impl_Type
(Arr
))
3109 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
3112 CS
: constant Uint
:= Component_Size
(Arr
);
3113 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
3117 and then not RTE_Available
(RE
)
3120 ("packing of " & UI_Image
(CS
) & "-bit components",
3121 First_Subtype
(Etype
(Arr
)));
3123 -- Cancel the packing
3125 Set_Is_Packed
(Base_Type
(Arr
), False);
3126 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3127 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
3133 -- Size information of packed array type is copied to the array
3134 -- type, since this is really the representation. But do not
3135 -- override explicit existing size values. If the ancestor subtype
3136 -- is constrained the Packed_Array_Impl_Type will be inherited
3137 -- from it, but the size may have been provided already, and
3138 -- must not be overridden either.
3140 if not Has_Size_Clause
(Arr
)
3142 (No
(Ancestor_Subtype
(Arr
))
3143 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
3145 Set_Esize
(Arr
, Esize
(Packed_Array_Impl_Type
(Arr
)));
3146 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Impl_Type
(Arr
)));
3149 if not Has_Alignment_Clause
(Arr
) then
3150 Set_Alignment
(Arr
, Alignment
(Packed_Array_Impl_Type
(Arr
)));
3156 -- A Ghost type cannot have a component of protected or task type
3157 -- (SPARK RM 6.9(19)).
3159 if Is_Ghost_Entity
(Arr
) and then Is_Concurrent_Type
(Ctyp
) then
3161 ("ghost array type & cannot have concurrent component type",
3164 end Freeze_Array_Type
;
3166 -------------------------------
3167 -- Freeze_Object_Declaration --
3168 -------------------------------
3170 procedure Freeze_Object_Declaration
(E
: Entity_Id
) is
3171 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
);
3172 -- Check that the size of array type Typ can be computed without
3173 -- overflow, and generates a Storage_Error otherwise. This is only
3174 -- relevant for array types whose index has System_Max_Integer_Size
3175 -- bits, where wrap-around arithmetic might yield a meaningless value
3176 -- for the length of the array, or its corresponding attribute.
3178 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
);
3179 -- Ensure that the initialization state of variable Var_Id subject
3180 -- to pragma Thread_Local_Storage agrees with the semantics of the
3183 function Has_Default_Initialization
3184 (Obj_Id
: Entity_Id
) return Boolean;
3185 -- Determine whether object Obj_Id default initialized
3187 -------------------------------
3188 -- Check_Large_Modular_Array --
3189 -------------------------------
3191 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
) is
3192 Obj_Loc
: constant Source_Ptr
:= Sloc
(E
);
3193 Idx_Typ
: Entity_Id
;
3196 -- Nothing to do when expansion is disabled because this routine
3197 -- generates a runtime check.
3199 if not Expander_Active
then
3202 -- Nothing to do for String literal subtypes because their index
3203 -- cannot be a modular type.
3205 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
3208 -- Nothing to do for an imported object because the object will
3209 -- be created on the exporting side.
3211 elsif Is_Imported
(E
) then
3214 -- Nothing to do for unconstrained array types. This case arises
3215 -- when the object declaration is illegal.
3217 elsif not Is_Constrained
(Typ
) then
3221 Idx_Typ
:= Etype
(First_Index
(Typ
));
3223 -- To prevent arithmetic overflow with large values, we raise
3224 -- Storage_Error under the following guard:
3226 -- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
3228 -- This takes care of the boundary case, but it is preferable to
3229 -- use a smaller limit, because even on 64-bit architectures an
3230 -- array of more than 2 ** 30 bytes is likely to raise
3233 if Is_Modular_Integer_Type
(Idx_Typ
)
3234 and then RM_Size
(Idx_Typ
) = RM_Size
(Standard_Long_Long_Integer
)
3236 Insert_Action
(Declaration_Node
(E
),
3237 Make_Raise_Storage_Error
(Obj_Loc
,
3239 Make_Op_Ge
(Obj_Loc
,
3241 Make_Op_Subtract
(Obj_Loc
,
3243 Make_Op_Divide
(Obj_Loc
,
3245 Make_Attribute_Reference
(Obj_Loc
,
3247 New_Occurrence_Of
(Typ
, Obj_Loc
),
3248 Attribute_Name
=> Name_Last
),
3250 Make_Integer_Literal
(Obj_Loc
, Uint_2
)),
3252 Make_Op_Divide
(Obj_Loc
,
3254 Make_Attribute_Reference
(Obj_Loc
,
3256 New_Occurrence_Of
(Typ
, Obj_Loc
),
3257 Attribute_Name
=> Name_First
),
3259 Make_Integer_Literal
(Obj_Loc
, Uint_2
))),
3261 Make_Integer_Literal
(Obj_Loc
, (Uint_2
** 30))),
3262 Reason
=> SE_Object_Too_Large
));
3264 end Check_Large_Modular_Array
;
3266 ---------------------------------------
3267 -- Check_Pragma_Thread_Local_Storage --
3268 ---------------------------------------
3270 procedure Check_Pragma_Thread_Local_Storage
(Var_Id
: Entity_Id
) is
3271 function Has_Incompatible_Initialization
3272 (Var_Decl
: Node_Id
) return Boolean;
3273 -- Determine whether variable Var_Id with declaration Var_Decl is
3274 -- initialized with a value that violates the semantics of pragma
3275 -- Thread_Local_Storage.
3277 -------------------------------------
3278 -- Has_Incompatible_Initialization --
3279 -------------------------------------
3281 function Has_Incompatible_Initialization
3282 (Var_Decl
: Node_Id
) return Boolean
3284 Init_Expr
: constant Node_Id
:= Expression
(Var_Decl
);
3287 -- The variable is default-initialized. This directly violates
3288 -- the semantics of the pragma.
3290 if Has_Default_Initialization
(Var_Id
) then
3293 -- The variable has explicit initialization. In this case only
3294 -- a handful of values satisfy the semantics of the pragma.
3296 elsif Has_Init_Expression
(Var_Decl
)
3297 and then Present
(Init_Expr
)
3299 -- "null" is a legal form of initialization
3301 if Nkind
(Init_Expr
) = N_Null
then
3304 -- A static expression is a legal form of initialization
3306 elsif Is_Static_Expression
(Init_Expr
) then
3309 -- A static aggregate is a legal form of initialization
3311 elsif Nkind
(Init_Expr
) = N_Aggregate
3312 and then Compile_Time_Known_Aggregate
(Init_Expr
)
3316 -- All other initialization expressions violate the semantic
3323 -- The variable lacks any kind of initialization, which agrees
3324 -- with the semantics of the pragma.
3329 end Has_Incompatible_Initialization
;
3331 -- Local declarations
3333 Var_Decl
: constant Node_Id
:= Declaration_Node
(Var_Id
);
3335 -- Start of processing for Check_Pragma_Thread_Local_Storage
3338 -- A variable whose initialization is suppressed lacks any kind of
3341 if Suppress_Initialization
(Var_Id
) then
3344 -- The variable has default initialization, or is explicitly
3345 -- initialized to a value other than null, static expression,
3346 -- or a static aggregate.
3348 elsif Has_Incompatible_Initialization
(Var_Decl
) then
3350 ("Thread_Local_Storage variable& is improperly initialized",
3353 ("\only allowed initialization is explicit NULL, static "
3354 & "expression or static aggregate", Var_Decl
, Var_Id
);
3356 end Check_Pragma_Thread_Local_Storage
;
3358 --------------------------------
3359 -- Has_Default_Initialization --
3360 --------------------------------
3362 function Has_Default_Initialization
3363 (Obj_Id
: Entity_Id
) return Boolean
3365 Obj_Decl
: constant Node_Id
:= Declaration_Node
(Obj_Id
);
3366 Obj_Typ
: constant Entity_Id
:= Etype
(Obj_Id
);
3370 Comes_From_Source
(Obj_Id
)
3371 and then not Is_Imported
(Obj_Id
)
3372 and then not Has_Init_Expression
(Obj_Decl
)
3374 ((Has_Non_Null_Base_Init_Proc
(Obj_Typ
)
3375 and then not No_Initialization
(Obj_Decl
)
3376 and then not Initialization_Suppressed
(Obj_Typ
))
3378 (Needs_Simple_Initialization
(Obj_Typ
)
3379 and then not Is_Internal
(Obj_Id
)));
3380 end Has_Default_Initialization
;
3384 Typ
: constant Entity_Id
:= Etype
(E
);
3387 -- Start of processing for Freeze_Object_Declaration
3390 -- Abstract type allowed only for C++ imported variables or constants
3392 -- Note: we inhibit this check for objects that do not come from
3393 -- source because there is at least one case (the expansion of
3394 -- x'Class'Input where x is abstract) where we legitimately
3395 -- generate an abstract object.
3397 if Is_Abstract_Type
(Typ
)
3398 and then Comes_From_Source
(Parent
(E
))
3399 and then not (Is_Imported
(E
) and then Is_CPP_Class
(Typ
))
3401 Def
:= Object_Definition
(Parent
(E
));
3403 Error_Msg_N
("type of object cannot be abstract", Def
);
3405 if Is_CPP_Class
(Etype
(E
)) then
3406 Error_Msg_NE
("\} may need a cpp_constructor", Def
, Typ
);
3408 elsif Present
(Expression
(Parent
(E
))) then
3409 Error_Msg_N
-- CODEFIX
3410 ("\maybe a class-wide type was meant", Def
);
3414 -- For object created by object declaration, perform required
3415 -- categorization (preelaborate and pure) checks. Defer these
3416 -- checks to freeze time since pragma Import inhibits default
3417 -- initialization and thus pragma Import affects these checks.
3419 Validate_Object_Declaration
(Declaration_Node
(E
));
3421 -- If there is an address clause, check that it is valid and if need
3422 -- be move initialization to the freeze node.
3424 Check_Address_Clause
(E
);
3426 -- Similar processing is needed for aspects that may affect object
3427 -- layout, like Address, if there is an initialization expression.
3428 -- We don't do this if there is a pragma Linker_Section, because it
3429 -- would prevent the back end from statically initializing the
3430 -- object; we don't want elaboration code in that case.
3432 if Has_Delayed_Aspects
(E
)
3433 and then Expander_Active
3434 and then Is_Array_Type
(Typ
)
3435 and then Present
(Expression
(Declaration_Node
(E
)))
3436 and then No
(Linker_Section_Pragma
(E
))
3439 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3440 Lhs
: constant Node_Id
:= New_Occurrence_Of
(E
, Loc
);
3443 -- Capture initialization value at point of declaration, and
3444 -- make explicit assignment legal, because object may be a
3447 Remove_Side_Effects
(Expression
(Decl
));
3448 Set_Assignment_OK
(Lhs
);
3450 -- Move initialization to freeze actions
3452 Append_Freeze_Action
(E
,
3453 Make_Assignment_Statement
(Loc
,
3455 Expression
=> Expression
(Decl
)));
3457 Set_No_Initialization
(Decl
);
3458 -- Set_Is_Frozen (E, False);
3462 -- Reset Is_True_Constant for non-constant aliased object. We
3463 -- consider that the fact that a non-constant object is aliased may
3464 -- indicate that some funny business is going on, e.g. an aliased
3465 -- object is passed by reference to a procedure which captures the
3466 -- address of the object, which is later used to assign a new value,
3467 -- even though the compiler thinks that it is not modified. Such
3468 -- code is highly dubious, but we choose to make it "work" for
3469 -- non-constant aliased objects.
3471 -- Note that we used to do this for all aliased objects, whether or
3472 -- not constant, but this caused anomalies down the line because we
3473 -- ended up with static objects that were not Is_True_Constant. Not
3474 -- resetting Is_True_Constant for (aliased) constant objects ensures
3475 -- that this anomaly never occurs.
3477 -- However, we don't do that for internal entities. We figure that if
3478 -- we deliberately set Is_True_Constant for an internal entity, e.g.
3479 -- a dispatch table entry, then we mean it.
3481 if Ekind
(E
) /= E_Constant
3482 and then (Is_Aliased
(E
) or else Is_Aliased
(Typ
))
3483 and then not Is_Internal_Name
(Chars
(E
))
3485 Set_Is_True_Constant
(E
, False);
3488 -- If the object needs any kind of default initialization, an error
3489 -- must be issued if No_Default_Initialization applies. The check
3490 -- doesn't apply to imported objects, which are not ever default
3491 -- initialized, and is why the check is deferred until freezing, at
3492 -- which point we know if Import applies. Deferred constants are also
3493 -- exempted from this test because their completion is explicit, or
3494 -- through an import pragma.
3496 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
3499 elsif Has_Default_Initialization
(E
) then
3501 (No_Default_Initialization
, Declaration_Node
(E
));
3504 -- Ensure that a variable subject to pragma Thread_Local_Storage
3506 -- * Lacks default initialization, or
3508 -- * The initialization expression is either "null", a static
3509 -- constant, or a compile-time known aggregate.
3511 if Has_Pragma_Thread_Local_Storage
(E
) then
3512 Check_Pragma_Thread_Local_Storage
(E
);
3515 -- For imported objects, set Is_Public unless there is also an
3516 -- address clause, which means that there is no external symbol
3517 -- needed for the Import (Is_Public may still be set for other
3518 -- unrelated reasons). Note that we delayed this processing
3519 -- till freeze time so that we can be sure not to set the flag
3520 -- if there is an address clause. If there is such a clause,
3521 -- then the only purpose of the Import pragma is to suppress
3522 -- implicit initialization.
3524 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
3528 -- For source objects that are not Imported and are library level, if
3529 -- no linker section pragma was given inherit the appropriate linker
3530 -- section from the corresponding type.
3532 if Comes_From_Source
(E
)
3533 and then not Is_Imported
(E
)
3534 and then Is_Library_Level_Entity
(E
)
3535 and then No
(Linker_Section_Pragma
(E
))
3537 Set_Linker_Section_Pragma
(E
, Linker_Section_Pragma
(Typ
));
3540 -- For convention C objects of an enumeration type, warn if the size
3541 -- is not integer size and no explicit size given. Skip warning for
3542 -- Boolean and Character, and assume programmer expects 8-bit sizes
3545 if (Convention
(E
) = Convention_C
3547 Convention
(E
) = Convention_CPP
)
3548 and then Is_Enumeration_Type
(Typ
)
3549 and then not Is_Character_Type
(Typ
)
3550 and then not Is_Boolean_Type
(Typ
)
3551 and then Esize
(Typ
) < Standard_Integer_Size
3552 and then not Has_Size_Clause
(E
)
3554 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
3556 ("??convention C enumeration object has size less than ^", E
);
3557 Error_Msg_N
("\??use explicit size clause to set size", E
);
3560 -- Declaring too big an array in disabled ghost code is OK
3562 if Is_Array_Type
(Typ
) and then not Is_Ignored_Ghost_Entity
(E
) then
3563 Check_Large_Modular_Array
(Typ
);
3565 end Freeze_Object_Declaration
;
3567 -----------------------------
3568 -- Freeze_Generic_Entities --
3569 -----------------------------
3571 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
3578 E
:= First_Entity
(Pack
);
3579 while Present
(E
) loop
3580 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
3581 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
3583 Append_To
(Flist
, F
);
3585 elsif Ekind
(E
) = E_Generic_Package
then
3586 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
3593 end Freeze_Generic_Entities
;
3595 --------------------
3596 -- Freeze_Profile --
3597 --------------------
3599 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
3602 Warn_Node
: Node_Id
;
3605 -- Loop through formals
3607 Formal
:= First_Formal
(E
);
3608 while Present
(Formal
) loop
3609 F_Type
:= Etype
(Formal
);
3611 -- AI05-0151: incomplete types can appear in a profile. By the
3612 -- time the entity is frozen, the full view must be available,
3613 -- unless it is a limited view.
3615 if Is_Incomplete_Type
(F_Type
)
3616 and then Present
(Full_View
(F_Type
))
3617 and then not From_Limited_With
(F_Type
)
3619 F_Type
:= Full_View
(F_Type
);
3620 Set_Etype
(Formal
, F_Type
);
3623 if not From_Limited_With
(F_Type
) then
3624 Freeze_And_Append
(F_Type
, N
, Result
);
3627 if Is_Private_Type
(F_Type
)
3628 and then Is_Private_Type
(Base_Type
(F_Type
))
3629 and then No
(Full_View
(Base_Type
(F_Type
)))
3630 and then not Is_Generic_Type
(F_Type
)
3631 and then not Is_Derived_Type
(F_Type
)
3633 -- If the type of a formal is incomplete, subprogram is being
3634 -- frozen prematurely. Within an instance (but not within a
3635 -- wrapper package) this is an artifact of our need to regard
3636 -- the end of an instantiation as a freeze point. Otherwise it
3637 -- is a definite error.
3640 Set_Is_Frozen
(E
, False);
3644 elsif not After_Last_Declaration
3645 and then not Freezing_Library_Level_Tagged_Type
3647 Error_Msg_Node_1
:= F_Type
;
3649 ("type & must be fully defined before this point", Loc
);
3653 -- Check suspicious parameter for C function. These tests apply
3654 -- only to exported/imported subprograms.
3656 if Warn_On_Export_Import
3657 and then Comes_From_Source
(E
)
3658 and then Convention
(E
) in Convention_C_Family
3659 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3660 and then Convention
(E
) /= Convention
(Formal
)
3661 and then not Has_Warnings_Off
(E
)
3662 and then not Has_Warnings_Off
(F_Type
)
3663 and then not Has_Warnings_Off
(Formal
)
3665 -- Qualify mention of formals with subprogram name
3667 Error_Msg_Qual_Level
:= 1;
3669 -- Check suspicious use of fat C pointer, but do not emit
3670 -- a warning on an access to subprogram when unnesting is
3673 if Is_Access_Type
(F_Type
)
3674 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
3675 and then (not Unnest_Subprogram_Mode
3676 or else not Is_Access_Subprogram_Type
(F_Type
))
3679 ("?x?type of & does not correspond to C pointer!", Formal
);
3681 -- Check suspicious return of boolean
3683 elsif Root_Type
(F_Type
) = Standard_Boolean
3684 and then Convention
(F_Type
) = Convention_Ada
3685 and then not Has_Warnings_Off
(F_Type
)
3686 and then not Has_Size_Clause
(F_Type
)
3689 ("& is an 8-bit Ada Boolean?x?", Formal
);
3691 ("\use appropriate corresponding type in C "
3692 & "(e.g. char)?x?", Formal
);
3694 -- Check suspicious tagged type
3696 elsif (Is_Tagged_Type
(F_Type
)
3698 (Is_Access_Type
(F_Type
)
3699 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
3700 and then Convention
(E
) = Convention_C
3703 ("?x?& involves a tagged type which does not "
3704 & "correspond to any C type!", Formal
);
3706 -- Check wrong convention subprogram pointer
3708 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
3709 and then not Has_Foreign_Convention
(F_Type
)
3712 ("?x?subprogram pointer & should "
3713 & "have foreign convention!", Formal
);
3714 Error_Msg_Sloc
:= Sloc
(F_Type
);
3716 ("\?x?add Convention pragma to declaration of &#",
3720 -- Turn off name qualification after message output
3722 Error_Msg_Qual_Level
:= 0;
3725 -- Check for unconstrained array in exported foreign convention
3728 if Has_Foreign_Convention
(E
)
3729 and then not Is_Imported
(E
)
3730 and then Is_Array_Type
(F_Type
)
3731 and then not Is_Constrained
(F_Type
)
3732 and then Warn_On_Export_Import
3734 Error_Msg_Qual_Level
:= 1;
3736 -- If this is an inherited operation, place the warning on
3737 -- the derived type declaration, rather than on the original
3740 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
3742 Warn_Node
:= Parent
(E
);
3744 if Formal
= First_Formal
(E
) then
3745 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
3748 Warn_Node
:= Formal
;
3751 Error_Msg_NE
("?x?type of argument& is unconstrained array",
3753 Error_Msg_NE
("?x?foreign caller must pass bounds explicitly",
3755 Error_Msg_Qual_Level
:= 0;
3758 if not From_Limited_With
(F_Type
) then
3759 if Is_Access_Type
(F_Type
) then
3760 F_Type
:= Designated_Type
(F_Type
);
3763 -- If the formal is an anonymous_access_to_subprogram
3764 -- freeze the subprogram type as well, to prevent
3765 -- scope anomalies in gigi, because there is no other
3766 -- clear point at which it could be frozen.
3768 if Is_Itype
(Etype
(Formal
))
3769 and then Ekind
(F_Type
) = E_Subprogram_Type
3771 Freeze_And_Append
(F_Type
, N
, Result
);
3775 Next_Formal
(Formal
);
3778 -- Case of function: similar checks on return type
3780 if Ekind
(E
) = E_Function
then
3782 -- Freeze return type
3784 R_Type
:= Etype
(E
);
3786 -- AI05-0151: the return type may have been incomplete at the
3787 -- point of declaration. Replace it with the full view, unless the
3788 -- current type is a limited view. In that case the full view is
3789 -- in a different unit, and gigi finds the non-limited view after
3790 -- the other unit is elaborated.
3792 if Ekind
(R_Type
) = E_Incomplete_Type
3793 and then Present
(Full_View
(R_Type
))
3794 and then not From_Limited_With
(R_Type
)
3796 R_Type
:= Full_View
(R_Type
);
3797 Set_Etype
(E
, R_Type
);
3800 Freeze_And_Append
(R_Type
, N
, Result
);
3802 -- Check suspicious return type for C function
3804 if Warn_On_Export_Import
3805 and then Comes_From_Source
(E
)
3806 and then Convention
(E
) in Convention_C_Family
3807 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3809 -- Check suspicious return of fat C pointer
3811 if Is_Access_Type
(R_Type
)
3812 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
3813 and then not Has_Warnings_Off
(E
)
3814 and then not Has_Warnings_Off
(R_Type
)
3817 ("?x?return type of& does not correspond to C pointer!",
3820 -- Check suspicious return of boolean
3822 elsif Root_Type
(R_Type
) = Standard_Boolean
3823 and then Convention
(R_Type
) = Convention_Ada
3824 and then not Has_Warnings_Off
(E
)
3825 and then not Has_Warnings_Off
(R_Type
)
3826 and then not Has_Size_Clause
(R_Type
)
3829 N
: constant Node_Id
:=
3830 Result_Definition
(Declaration_Node
(E
));
3833 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
3835 ("\use appropriate corresponding type in C "
3836 & "(e.g. char)?x?", N
, E
);
3839 -- Check suspicious return tagged type
3841 elsif (Is_Tagged_Type
(R_Type
)
3842 or else (Is_Access_Type
(R_Type
)
3845 (Designated_Type
(R_Type
))))
3846 and then Convention
(E
) = Convention_C
3847 and then not Has_Warnings_Off
(E
)
3848 and then not Has_Warnings_Off
(R_Type
)
3850 Error_Msg_N
("?x?return type of & does not "
3851 & "correspond to C type!", E
);
3853 -- Check return of wrong convention subprogram pointer
3855 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3856 and then not Has_Foreign_Convention
(R_Type
)
3857 and then not Has_Warnings_Off
(E
)
3858 and then not Has_Warnings_Off
(R_Type
)
3860 Error_Msg_N
("?x?& should return a foreign "
3861 & "convention subprogram pointer", E
);
3862 Error_Msg_Sloc
:= Sloc
(R_Type
);
3864 ("\?x?add Convention pragma to declaration of& #",
3869 -- Give warning for suspicious return of a result of an
3870 -- unconstrained array type in a foreign convention function.
3872 if Has_Foreign_Convention
(E
)
3874 -- We are looking for a return of unconstrained array
3876 and then Is_Array_Type
(R_Type
)
3877 and then not Is_Constrained
(R_Type
)
3879 -- Exclude imported routines, the warning does not belong on
3880 -- the import, but rather on the routine definition.
3882 and then not Is_Imported
(E
)
3884 -- Check that general warning is enabled, and that it is not
3885 -- suppressed for this particular case.
3887 and then Warn_On_Export_Import
3888 and then not Has_Warnings_Off
(E
)
3889 and then not Has_Warnings_Off
(R_Type
)
3892 ("?x?foreign convention function& should not return "
3893 & "unconstrained array!", E
);
3897 -- Check suspicious use of Import in pure unit (cases where the RM
3898 -- allows calls to be omitted).
3902 -- It might be suspicious if the compilation unit has the Pure
3905 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
3907 -- The RM allows omission of calls only in the case of
3908 -- library-level subprograms (see RM-10.2.1(18)).
3910 and then Is_Library_Level_Entity
(E
)
3912 -- Ignore internally generated entity. This happens in some cases
3913 -- of subprograms in specs, where we generate an implied body.
3915 and then Comes_From_Source
(Import_Pragma
(E
))
3917 -- Assume run-time knows what it is doing
3919 and then not GNAT_Mode
3921 -- Assume explicit Pure_Function means import is pure
3923 and then not Has_Pragma_Pure_Function
(E
)
3925 -- Don't need warning in relaxed semantics mode
3927 and then not Relaxed_RM_Semantics
3929 -- Assume convention Intrinsic is OK, since this is specialized.
3930 -- This deals with the DEC unit current_exception.ads
3932 and then Convention
(E
) /= Convention_Intrinsic
3934 -- Assume that ASM interface knows what it is doing. This deals
3935 -- with e.g. unsigned.ads in the AAMP back end.
3937 and then Convention
(E
) /= Convention_Assembler
3940 ("pragma Import in Pure unit??", Import_Pragma
(E
));
3942 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
3943 Import_Pragma
(E
), E
);
3949 ------------------------
3950 -- Freeze_Record_Type --
3951 ------------------------
3953 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
3960 pragma Warnings
(Off
, Junk
);
3962 Aliased_Component
: Boolean := False;
3963 -- Set True if we find at least one component which is aliased. This
3964 -- is used to prevent Implicit_Packing of the record, since packing
3965 -- cannot modify the size of alignment of an aliased component.
3967 All_Elem_Components
: Boolean := True;
3968 -- True if all components are of a type whose underlying type is
3971 All_Sized_Components
: Boolean := True;
3972 -- True if all components have a known RM_Size
3974 All_Storage_Unit_Components
: Boolean := True;
3975 -- True if all components have an RM_Size that is a multiple of the
3978 Elem_Component_Total_Esize
: Uint
:= Uint_0
;
3979 -- Accumulates total Esize values of all elementary components. Used
3980 -- for processing of Implicit_Packing.
3982 Placed_Component
: Boolean := False;
3983 -- Set True if we find at least one component with a component
3984 -- clause (used to warn about useless Bit_Order pragmas, and also
3985 -- to detect cases where Implicit_Packing may have an effect).
3987 Sized_Component_Total_RM_Size
: Uint
:= Uint_0
;
3988 -- Accumulates total RM_Size values of all sized components. Used
3989 -- for processing of Implicit_Packing.
3991 Sized_Component_Total_Round_RM_Size
: Uint
:= Uint_0
;
3992 -- Accumulates total RM_Size values of all sized components, rounded
3993 -- individually to a multiple of the storage unit.
3996 -- Scalar_Storage_Order attribute definition clause for the record
3998 SSO_ADC_Component
: Boolean := False;
3999 -- Set True if we find at least one component whose type has a
4000 -- Scalar_Storage_Order attribute definition clause.
4002 Unplaced_Component
: Boolean := False;
4003 -- Set True if we find at least one component with no component
4004 -- clause (used to warn about useless Pack pragmas).
4006 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
4007 -- If N is an allocator, possibly wrapped in one or more level of
4008 -- qualified expression(s), return the inner allocator node, else
4011 procedure Check_Itype
(Typ
: Entity_Id
);
4012 -- If the component subtype is an access to a constrained subtype of
4013 -- an already frozen type, make the subtype frozen as well. It might
4014 -- otherwise be frozen in the wrong scope, and a freeze node on
4015 -- subtype has no effect. Similarly, if the component subtype is a
4016 -- regular (not protected) access to subprogram, set the anonymous
4017 -- subprogram type to frozen as well, to prevent an out-of-scope
4018 -- freeze node at some eventual point of call. Protected operations
4019 -- are handled elsewhere.
4021 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
4022 -- Make sure that all types mentioned in Discrete_Choices of the
4023 -- variants referenceed by the Variant_Part VP are frozen. This is
4024 -- a recursive routine to deal with nested variants.
4026 ---------------------
4027 -- Check_Allocator --
4028 ---------------------
4030 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
4035 if Nkind
(Inner
) = N_Allocator
then
4037 elsif Nkind
(Inner
) = N_Qualified_Expression
then
4038 Inner
:= Expression
(Inner
);
4043 end Check_Allocator
;
4049 procedure Check_Itype
(Typ
: Entity_Id
) is
4050 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
4053 if not Is_Frozen
(Desig
)
4054 and then Is_Frozen
(Base_Type
(Desig
))
4056 Set_Is_Frozen
(Desig
);
4058 -- In addition, add an Itype_Reference to ensure that the
4059 -- access subtype is elaborated early enough. This cannot be
4060 -- done if the subtype may depend on discriminants.
4062 if Ekind
(Comp
) = E_Component
4063 and then Is_Itype
(Etype
(Comp
))
4064 and then not Has_Discriminants
(Rec
)
4066 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
4067 Set_Itype
(IR
, Desig
);
4071 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
4072 and then Convention
(Desig
) /= Convention_Protected
4074 Set_Is_Frozen
(Desig
);
4078 ------------------------------------
4079 -- Freeze_Choices_In_Variant_Part --
4080 ------------------------------------
4082 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
4083 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
4090 -- Loop through variants
4092 Variant
:= First_Non_Pragma
(Variants
(VP
));
4093 while Present
(Variant
) loop
4095 -- Loop through choices, checking that all types are frozen
4097 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
4098 while Present
(Choice
) loop
4099 if Nkind
(Choice
) in N_Has_Etype
4100 and then Present
(Etype
(Choice
))
4102 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
4105 Next_Non_Pragma
(Choice
);
4108 -- Check for nested variant part to process
4110 CL
:= Component_List
(Variant
);
4112 if not Null_Present
(CL
) then
4113 if Present
(Variant_Part
(CL
)) then
4114 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
4118 Next_Non_Pragma
(Variant
);
4120 end Freeze_Choices_In_Variant_Part
;
4122 -- Start of processing for Freeze_Record_Type
4125 -- Freeze components and embedded subtypes
4127 Comp
:= First_Entity
(Rec
);
4129 while Present
(Comp
) loop
4130 if Is_Aliased
(Comp
) then
4131 Aliased_Component
:= True;
4134 -- Handle the component and discriminant case
4136 if Ekind
(Comp
) in E_Component | E_Discriminant
then
4138 CC
: constant Node_Id
:= Component_Clause
(Comp
);
4141 -- Freezing a record type freezes the type of each of its
4142 -- components. However, if the type of the component is
4143 -- part of this record, we do not want or need a separate
4144 -- Freeze_Node. Note that Is_Itype is wrong because that's
4145 -- also set in private type cases. We also can't check for
4146 -- the Scope being exactly Rec because of private types and
4147 -- record extensions.
4149 if Is_Itype
(Etype
(Comp
))
4150 and then Is_Record_Type
(Underlying_Type
4151 (Scope
(Etype
(Comp
))))
4153 Undelay_Type
(Etype
(Comp
));
4156 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
4158 -- Warn for pragma Pack overriding foreign convention
4160 if Has_Foreign_Convention
(Etype
(Comp
))
4161 and then Has_Pragma_Pack
(Rec
)
4163 -- Don't warn for aliased components, since override
4164 -- cannot happen in that case.
4166 and then not Is_Aliased
(Comp
)
4169 CN
: constant Name_Id
:=
4170 Get_Convention_Name
(Convention
(Etype
(Comp
)));
4171 PP
: constant Node_Id
:=
4172 Get_Pragma
(Rec
, Pragma_Pack
);
4174 if Present
(PP
) then
4175 Error_Msg_Name_1
:= CN
;
4176 Error_Msg_Sloc
:= Sloc
(Comp
);
4178 ("pragma Pack affects convention % component#??",
4180 Error_Msg_Name_1
:= CN
;
4182 ("\component & may not have % compatible "
4183 & "representation??", PP
, Comp
);
4188 -- Check for error of component clause given for variable
4189 -- sized type. We have to delay this test till this point,
4190 -- since the component type has to be frozen for us to know
4191 -- if it is variable length.
4193 if Present
(CC
) then
4194 Placed_Component
:= True;
4196 -- We omit this test in a generic context, it will be
4197 -- applied at instantiation time.
4199 if Inside_A_Generic
then
4202 -- Also omit this test in CodePeer mode, since we do not
4203 -- have sufficient info on size and rep clauses.
4205 elsif CodePeer_Mode
then
4211 Size_Known_At_Compile_Time
4212 (Underlying_Type
(Etype
(Comp
)))
4215 ("component clause not allowed for variable " &
4216 "length component", CC
);
4220 Unplaced_Component
:= True;
4223 -- Case of component requires byte alignment
4225 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
4227 -- Set the enclosing record to also require byte align
4229 Set_Must_Be_On_Byte_Boundary
(Rec
);
4231 -- Check for component clause that is inconsistent with
4232 -- the required byte boundary alignment.
4235 and then Normalized_First_Bit
(Comp
) mod
4236 System_Storage_Unit
/= 0
4239 ("component & must be byte aligned",
4240 Component_Name
(Component_Clause
(Comp
)));
4246 -- Gather data for possible Implicit_Packing later. Note that at
4247 -- this stage we might be dealing with a real component, or with
4248 -- an implicit subtype declaration.
4250 if Known_Static_RM_Size
(Etype
(Comp
)) then
4252 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
4253 Comp_Size
: constant Uint
:= RM_Size
(Comp_Type
);
4254 SSU
: constant Int
:= Ttypes
.System_Storage_Unit
;
4257 Sized_Component_Total_RM_Size
:=
4258 Sized_Component_Total_RM_Size
+ Comp_Size
;
4260 Sized_Component_Total_Round_RM_Size
:=
4261 Sized_Component_Total_Round_RM_Size
+
4262 (Comp_Size
+ SSU
- 1) / SSU
* SSU
;
4264 if Present
(Underlying_Type
(Comp_Type
))
4265 and then Is_Elementary_Type
(Underlying_Type
(Comp_Type
))
4267 Elem_Component_Total_Esize
:=
4268 Elem_Component_Total_Esize
+ Esize
(Comp_Type
);
4270 All_Elem_Components
:= False;
4272 if Comp_Size
mod SSU
/= 0 then
4273 All_Storage_Unit_Components
:= False;
4278 All_Sized_Components
:= False;
4281 -- If the component is an Itype with Delayed_Freeze and is either
4282 -- a record or array subtype and its base type has not yet been
4283 -- frozen, we must remove this from the entity list of this record
4284 -- and put it on the entity list of the scope of its base type.
4285 -- Note that we know that this is not the type of a component
4286 -- since we cleared Has_Delayed_Freeze for it in the previous
4287 -- loop. Thus this must be the Designated_Type of an access type,
4288 -- which is the type of a component.
4291 and then Is_Type
(Scope
(Comp
))
4292 and then Is_Composite_Type
(Comp
)
4293 and then Base_Type
(Comp
) /= Comp
4294 and then Has_Delayed_Freeze
(Comp
)
4295 and then not Is_Frozen
(Base_Type
(Comp
))
4298 Will_Be_Frozen
: Boolean := False;
4302 -- We have a difficult case to handle here. Suppose Rec is
4303 -- subtype being defined in a subprogram that's created as
4304 -- part of the freezing of Rec'Base. In that case, we know
4305 -- that Comp'Base must have already been frozen by the time
4306 -- we get to elaborate this because Gigi doesn't elaborate
4307 -- any bodies until it has elaborated all of the declarative
4308 -- part. But Is_Frozen will not be set at this point because
4309 -- we are processing code in lexical order.
4311 -- We detect this case by going up the Scope chain of Rec
4312 -- and seeing if we have a subprogram scope before reaching
4313 -- the top of the scope chain or that of Comp'Base. If we
4314 -- do, then mark that Comp'Base will actually be frozen. If
4315 -- so, we merely undelay it.
4318 while Present
(S
) loop
4319 if Is_Subprogram
(S
) then
4320 Will_Be_Frozen
:= True;
4322 elsif S
= Scope
(Base_Type
(Comp
)) then
4329 if Will_Be_Frozen
then
4330 Undelay_Type
(Comp
);
4333 if Present
(Prev
) then
4334 Link_Entities
(Prev
, Next_Entity
(Comp
));
4336 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
4339 -- Insert in entity list of scope of base type (which
4340 -- must be an enclosing scope, because still unfrozen).
4342 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
4346 -- If the component is an access type with an allocator as default
4347 -- value, the designated type will be frozen by the corresponding
4348 -- expression in init_proc. In order to place the freeze node for
4349 -- the designated type before that for the current record type,
4352 -- Same process if the component is an array of access types,
4353 -- initialized with an aggregate. If the designated type is
4354 -- private, it cannot contain allocators, and it is premature
4355 -- to freeze the type, so we check for this as well.
4357 elsif Is_Access_Type
(Etype
(Comp
))
4358 and then Present
(Parent
(Comp
))
4359 and then Present
(Expression
(Parent
(Comp
)))
4362 Alloc
: constant Node_Id
:=
4363 Check_Allocator
(Expression
(Parent
(Comp
)));
4366 if Present
(Alloc
) then
4368 -- If component is pointer to a class-wide type, freeze
4369 -- the specific type in the expression being allocated.
4370 -- The expression may be a subtype indication, in which
4371 -- case freeze the subtype mark.
4373 if Is_Class_Wide_Type
4374 (Designated_Type
(Etype
(Comp
)))
4376 if Is_Entity_Name
(Expression
(Alloc
)) then
4378 (Entity
(Expression
(Alloc
)), N
, Result
);
4380 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
4383 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
4387 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
4388 Check_Itype
(Etype
(Comp
));
4392 (Designated_Type
(Etype
(Comp
)), N
, Result
);
4397 elsif Is_Access_Type
(Etype
(Comp
))
4398 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
4400 Check_Itype
(Etype
(Comp
));
4402 -- Freeze the designated type when initializing a component with
4403 -- an aggregate in case the aggregate contains allocators.
4406 -- type T_Ptr is access all T;
4407 -- type T_Array is array ... of T_Ptr;
4409 -- type Rec is record
4410 -- Comp : T_Array := (others => ...);
4413 elsif Is_Array_Type
(Etype
(Comp
))
4414 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
4417 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
4418 Desig_Typ
: constant Entity_Id
:=
4420 (Component_Type
(Etype
(Comp
)));
4423 -- The only case when this sort of freezing is not done is
4424 -- when the designated type is class-wide and the root type
4425 -- is the record owning the component. This scenario results
4426 -- in a circularity because the class-wide type requires
4427 -- primitives that have not been created yet as the root
4428 -- type is in the process of being frozen.
4430 -- type Rec is tagged;
4431 -- type Rec_Ptr is access all Rec'Class;
4432 -- type Rec_Array is array ... of Rec_Ptr;
4434 -- type Rec is record
4435 -- Comp : Rec_Array := (others => ...);
4438 if Is_Class_Wide_Type
(Desig_Typ
)
4439 and then Root_Type
(Desig_Typ
) = Rec
4443 elsif Is_Fully_Defined
(Desig_Typ
)
4444 and then Present
(Comp_Par
)
4445 and then Nkind
(Comp_Par
) = N_Component_Declaration
4446 and then Present
(Expression
(Comp_Par
))
4447 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
4449 Freeze_And_Append
(Desig_Typ
, N
, Result
);
4459 Get_Attribute_Definition_Clause
4460 (Rec
, Attribute_Scalar_Storage_Order
);
4462 -- If the record type has Complex_Representation, then it is treated
4463 -- as a scalar in the back end so the storage order is irrelevant.
4465 if Has_Complex_Representation
(Rec
) then
4466 if Present
(SSO_ADC
) then
4468 ("??storage order has no effect with Complex_Representation",
4473 -- Deal with default setting of reverse storage order
4475 Set_SSO_From_Default
(Rec
);
4477 -- Check consistent attribute setting on component types
4480 Comp_ADC_Present
: Boolean;
4482 Comp
:= First_Component
(Rec
);
4483 while Present
(Comp
) loop
4484 Check_Component_Storage_Order
4488 Comp_ADC_Present
=> Comp_ADC_Present
);
4489 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
4490 Next_Component
(Comp
);
4494 -- Now deal with reverse storage order/bit order issues
4496 if Present
(SSO_ADC
) then
4498 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
4499 -- if the former is specified.
4501 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
4503 -- Note: report error on Rec, not on SSO_ADC, as ADC may
4504 -- apply to some ancestor type.
4506 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
4508 ("scalar storage order for& specified# inconsistent with "
4509 & "bit order", Rec
);
4512 -- Warn if there is a Scalar_Storage_Order attribute definition
4513 -- clause but no component clause, no component that itself has
4514 -- such an attribute definition, and no pragma Pack.
4516 if not (Placed_Component
4523 ("??scalar storage order specified but no component "
4524 & "clause", SSO_ADC
);
4529 -- Deal with Bit_Order aspect
4531 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
4533 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
4534 if not (Placed_Component
4535 or else Present
(SSO_ADC
)
4536 or else Is_Packed
(Rec
))
4538 -- Warn if clause has no effect when no component clause is
4539 -- present, but suppress warning if the Bit_Order is required
4540 -- due to the presence of a Scalar_Storage_Order attribute.
4543 ("??bit order specification has no effect", ADC
);
4545 ("\??since no component clauses were specified", ADC
);
4547 -- Here is where we do the processing to adjust component clauses
4548 -- for reversed bit order, when not using reverse SSO. If an error
4549 -- has been reported on Rec already (such as SSO incompatible with
4550 -- bit order), don't bother adjusting as this may generate extra
4553 elsif Reverse_Bit_Order
(Rec
)
4554 and then not Reverse_Storage_Order
(Rec
)
4555 and then not Error_Posted
(Rec
)
4557 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
4559 -- Case where we have both an explicit Bit_Order and the same
4560 -- Scalar_Storage_Order: leave record untouched, the back-end
4561 -- will take care of required layout conversions.
4569 -- Check for useless pragma Pack when all components placed. We only
4570 -- do this check for record types, not subtypes, since a subtype may
4571 -- have all its components placed, and it still makes perfectly good
4572 -- sense to pack other subtypes or the parent type. We do not give
4573 -- this warning if Optimize_Alignment is set to Space, since the
4574 -- pragma Pack does have an effect in this case (it always resets
4575 -- the alignment to one).
4577 if Ekind
(Rec
) = E_Record_Type
4578 and then Is_Packed
(Rec
)
4579 and then not Unplaced_Component
4580 and then Optimize_Alignment
/= 'S'
4582 -- Reset packed status. Probably not necessary, but we do it so
4583 -- that there is no chance of the back end doing something strange
4584 -- with this redundant indication of packing.
4586 Set_Is_Packed
(Rec
, False);
4588 -- Give warning if redundant constructs warnings on
4590 if Warn_On_Redundant_Constructs
then
4591 Error_Msg_N
-- CODEFIX
4592 ("??pragma Pack has no effect, no unplaced components",
4593 Get_Rep_Pragma
(Rec
, Name_Pack
));
4597 -- If this is the record corresponding to a remote type, freeze the
4598 -- remote type here since that is what we are semantically freezing.
4599 -- This prevents the freeze node for that type in an inner scope.
4601 if Ekind
(Rec
) = E_Record_Type
then
4602 if Present
(Corresponding_Remote_Type
(Rec
)) then
4603 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
4606 -- Check for controlled components, unchecked unions, and type
4609 Comp
:= First_Component
(Rec
);
4610 while Present
(Comp
) loop
4612 -- Do not set Has_Controlled_Component on a class-wide
4613 -- equivalent type. See Make_CW_Equivalent_Type.
4615 if not Is_Class_Wide_Equivalent_Type
(Rec
)
4617 (Has_Controlled_Component
(Etype
(Comp
))
4619 (Chars
(Comp
) /= Name_uParent
4620 and then Is_Controlled
(Etype
(Comp
)))
4622 (Is_Protected_Type
(Etype
(Comp
))
4624 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
4626 Has_Controlled_Component
4627 (Corresponding_Record_Type
(Etype
(Comp
)))))
4629 Set_Has_Controlled_Component
(Rec
);
4632 if Has_Unchecked_Union
(Etype
(Comp
)) then
4633 Set_Has_Unchecked_Union
(Rec
);
4636 -- The record type requires its own invariant procedure in
4637 -- order to verify the invariant of each individual component.
4638 -- Do not consider internal components such as _parent because
4639 -- parent class-wide invariants are always inherited.
4640 -- In GNATprove mode, the component invariants are checked by
4641 -- other means. They should not be added to the record type
4642 -- invariant procedure, so that the procedure can be used to
4643 -- check the recordy type invariants if any.
4645 if Comes_From_Source
(Comp
)
4646 and then Has_Invariants
(Etype
(Comp
))
4647 and then not GNATprove_Mode
4649 Set_Has_Own_Invariants
(Rec
);
4652 -- Scan component declaration for likely misuses of current
4653 -- instance, either in a constraint or a default expression.
4655 if Has_Per_Object_Constraint
(Comp
) then
4656 Check_Current_Instance
(Parent
(Comp
));
4659 Next_Component
(Comp
);
4663 -- Enforce the restriction that access attributes with a current
4664 -- instance prefix can only apply to limited types. This comment
4665 -- is floating here, but does not seem to belong here???
4667 -- Set component alignment if not otherwise already set
4669 Set_Component_Alignment_If_Not_Set
(Rec
);
4671 -- For first subtypes, check if there are any fixed-point fields with
4672 -- component clauses, where we must check the size. This is not done
4673 -- till the freeze point since for fixed-point types, we do not know
4674 -- the size until the type is frozen. Similar processing applies to
4675 -- bit-packed arrays.
4677 if Is_First_Subtype
(Rec
) then
4678 Comp
:= First_Component
(Rec
);
4679 while Present
(Comp
) loop
4680 if Present
(Component_Clause
(Comp
))
4681 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
4682 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
4685 (Component_Name
(Component_Clause
(Comp
)),
4691 Next_Component
(Comp
);
4695 -- See if Size is too small as is (and implicit packing might help)
4697 if not Is_Packed
(Rec
)
4699 -- No implicit packing if even one component is explicitly placed
4701 and then not Placed_Component
4703 -- Or even one component is aliased
4705 and then not Aliased_Component
4707 -- Must have size clause and all sized components
4709 and then Has_Size_Clause
(Rec
)
4710 and then All_Sized_Components
4712 -- Do not try implicit packing on records with discriminants, too
4713 -- complicated, especially in the variant record case.
4715 and then not Has_Discriminants
(Rec
)
4717 -- We want to implicitly pack if the specified size of the record
4718 -- is less than the sum of the object sizes (no point in packing
4719 -- if this is not the case), if we can compute it, i.e. if we have
4720 -- only elementary components. Otherwise, we have at least one
4721 -- composite component and we want to implicitly pack only if bit
4722 -- packing is required for it, as we are sure in this case that
4723 -- the back end cannot do the expected layout without packing.
4726 ((All_Elem_Components
4727 and then RM_Size
(Rec
) < Elem_Component_Total_Esize
)
4729 (not All_Elem_Components
4730 and then not All_Storage_Unit_Components
4731 and then RM_Size
(Rec
) < Sized_Component_Total_Round_RM_Size
))
4733 -- And the total RM size cannot be greater than the specified size
4734 -- since otherwise packing will not get us where we have to be.
4736 and then Sized_Component_Total_RM_Size
<= RM_Size
(Rec
)
4738 -- Never do implicit packing in CodePeer or SPARK modes since
4739 -- we don't do any packing in these modes, since this generates
4740 -- over-complex code that confuses static analysis, and in
4741 -- general, neither CodePeer not GNATprove care about the
4742 -- internal representation of objects.
4744 and then not (CodePeer_Mode
or GNATprove_Mode
)
4746 -- If implicit packing enabled, do it
4748 if Implicit_Packing
then
4749 Set_Is_Packed
(Rec
);
4751 -- Otherwise flag the size clause
4755 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
4757 Error_Msg_NE
-- CODEFIX
4758 ("size given for& too small", Sz
, Rec
);
4759 Error_Msg_N
-- CODEFIX
4760 ("\use explicit pragma Pack "
4761 & "or use pragma Implicit_Packing", Sz
);
4766 -- The following checks are relevant only when SPARK_Mode is on as
4767 -- they are not standard Ada legality rules.
4769 if SPARK_Mode
= On
then
4771 -- A discriminated type cannot be effectively volatile
4772 -- (SPARK RM 7.1.3(5)).
4774 if Is_Effectively_Volatile
(Rec
) then
4775 if Has_Discriminants
(Rec
) then
4776 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
4779 -- A non-effectively volatile record type cannot contain
4780 -- effectively volatile components (SPARK RM 7.1.3(6)).
4783 Comp
:= First_Component
(Rec
);
4784 while Present
(Comp
) loop
4785 if Comes_From_Source
(Comp
)
4786 and then Is_Effectively_Volatile
(Etype
(Comp
))
4788 Error_Msg_Name_1
:= Chars
(Rec
);
4790 ("component & of non-volatile type % cannot be "
4791 & "volatile", Comp
);
4794 Next_Component
(Comp
);
4798 -- A type which does not yield a synchronized object cannot have
4799 -- a component that yields a synchronized object (SPARK RM 9.5).
4801 if not Yields_Synchronized_Object
(Rec
) then
4802 Comp
:= First_Component
(Rec
);
4803 while Present
(Comp
) loop
4804 if Comes_From_Source
(Comp
)
4805 and then Yields_Synchronized_Object
(Etype
(Comp
))
4807 Error_Msg_Name_1
:= Chars
(Rec
);
4809 ("component & of non-synchronized type % cannot be "
4810 & "synchronized", Comp
);
4813 Next_Component
(Comp
);
4817 -- A Ghost type cannot have a component of protected or task type
4818 -- (SPARK RM 6.9(19)).
4820 if Is_Ghost_Entity
(Rec
) then
4821 Comp
:= First_Component
(Rec
);
4822 while Present
(Comp
) loop
4823 if Comes_From_Source
(Comp
)
4824 and then Is_Concurrent_Type
(Etype
(Comp
))
4826 Error_Msg_Name_1
:= Chars
(Rec
);
4828 ("component & of ghost type % cannot be concurrent",
4832 Next_Component
(Comp
);
4837 -- Make sure that if we have an iterator aspect, then we have
4838 -- either Constant_Indexing or Variable_Indexing.
4841 Iterator_Aspect
: Node_Id
;
4844 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
4846 if No
(Iterator_Aspect
) then
4847 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
4850 if Present
(Iterator_Aspect
) then
4851 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
4853 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
4858 ("Iterator_Element requires indexing aspect",
4864 -- All done if not a full record definition
4866 if Ekind
(Rec
) /= E_Record_Type
then
4870 -- Finally we need to check the variant part to make sure that
4871 -- all types within choices are properly frozen as part of the
4872 -- freezing of the record type.
4874 Check_Variant_Part
: declare
4875 D
: constant Node_Id
:= Declaration_Node
(Rec
);
4880 -- Find component list
4884 if Nkind
(D
) = N_Full_Type_Declaration
then
4885 T
:= Type_Definition
(D
);
4887 if Nkind
(T
) = N_Record_Definition
then
4888 C
:= Component_List
(T
);
4890 elsif Nkind
(T
) = N_Derived_Type_Definition
4891 and then Present
(Record_Extension_Part
(T
))
4893 C
:= Component_List
(Record_Extension_Part
(T
));
4897 -- Case of variant part present
4899 if Present
(C
) and then Present
(Variant_Part
(C
)) then
4900 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
4903 -- Note: we used to call Check_Choices here, but it is too early,
4904 -- since predicated subtypes are frozen here, but their freezing
4905 -- actions are in Analyze_Freeze_Entity, which has not been called
4906 -- yet for entities frozen within this procedure, so we moved that
4907 -- call to the Analyze_Freeze_Entity for the record type.
4909 end Check_Variant_Part
;
4911 -- Check that all the primitives of an interface type are abstract
4912 -- or null procedures.
4914 if Is_Interface
(Rec
)
4915 and then not Error_Posted
(Parent
(Rec
))
4922 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
4923 while Present
(Elmt
) loop
4924 Subp
:= Node
(Elmt
);
4926 if not Is_Abstract_Subprogram
(Subp
)
4928 -- Avoid reporting the error on inherited primitives
4930 and then Comes_From_Source
(Subp
)
4932 Error_Msg_Name_1
:= Chars
(Subp
);
4934 if Ekind
(Subp
) = E_Procedure
then
4935 if not Null_Present
(Parent
(Subp
)) then
4937 ("interface procedure % must be abstract or null",
4942 ("interface function % must be abstract",
4952 -- For a derived tagged type, check whether inherited primitives
4953 -- might require a wrapper to handle class-wide conditions.
4955 if Is_Tagged_Type
(Rec
) and then Is_Derived_Type
(Rec
) then
4956 Check_Inherited_Conditions
(Rec
);
4958 end Freeze_Record_Type
;
4960 -------------------------------
4961 -- Has_Boolean_Aspect_Import --
4962 -------------------------------
4964 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
4965 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4970 if Has_Aspects
(Decl
) then
4971 Asp
:= First
(Aspect_Specifications
(Decl
));
4972 while Present
(Asp
) loop
4973 Expr
:= Expression
(Asp
);
4975 -- The value of aspect Import is True when the expression is
4976 -- either missing or it is explicitly set to True.
4978 if Get_Aspect_Id
(Asp
) = Aspect_Import
4980 or else (Compile_Time_Known_Value
(Expr
)
4981 and then Is_True
(Expr_Value
(Expr
))))
4991 end Has_Boolean_Aspect_Import
;
4993 -------------------------
4994 -- Inherit_Freeze_Node --
4995 -------------------------
4997 procedure Inherit_Freeze_Node
5001 Typ_Fnod
: constant Node_Id
:= Freeze_Node
(Typ
);
5004 Set_Freeze_Node
(Typ
, Fnod
);
5005 Set_Entity
(Fnod
, Typ
);
5007 -- The input type had an existing node. Propagate relevant attributes
5008 -- from the old freeze node to the inherited freeze node.
5010 -- ??? if both freeze nodes have attributes, would they differ?
5012 if Present
(Typ_Fnod
) then
5014 -- Attribute Access_Types_To_Process
5016 if Present
(Access_Types_To_Process
(Typ_Fnod
))
5017 and then No
(Access_Types_To_Process
(Fnod
))
5019 Set_Access_Types_To_Process
(Fnod
,
5020 Access_Types_To_Process
(Typ_Fnod
));
5023 -- Attribute Actions
5025 if Present
(Actions
(Typ_Fnod
)) and then No
(Actions
(Fnod
)) then
5026 Set_Actions
(Fnod
, Actions
(Typ_Fnod
));
5029 -- Attribute First_Subtype_Link
5031 if Present
(First_Subtype_Link
(Typ_Fnod
))
5032 and then No
(First_Subtype_Link
(Fnod
))
5034 Set_First_Subtype_Link
(Fnod
, First_Subtype_Link
(Typ_Fnod
));
5037 -- Attribute TSS_Elist
5039 if Present
(TSS_Elist
(Typ_Fnod
))
5040 and then No
(TSS_Elist
(Fnod
))
5042 Set_TSS_Elist
(Fnod
, TSS_Elist
(Typ_Fnod
));
5045 end Inherit_Freeze_Node
;
5047 ------------------------------
5048 -- Wrap_Imported_Subprogram --
5049 ------------------------------
5051 -- The issue here is that our normal approach of checking preconditions
5052 -- and postconditions does not work for imported procedures, since we
5053 -- are not generating code for the body. To get around this we create
5054 -- a wrapper, as shown by the following example:
5056 -- procedure K (A : Integer);
5057 -- pragma Import (C, K);
5059 -- The spec is rewritten by removing the effects of pragma Import, but
5060 -- leaving the convention unchanged, as though the source had said:
5062 -- procedure K (A : Integer);
5063 -- pragma Convention (C, K);
5065 -- and we create a body, added to the entity K freeze actions, which
5068 -- procedure K (A : Integer) is
5069 -- procedure K (A : Integer);
5070 -- pragma Import (C, K);
5075 -- Now the contract applies in the normal way to the outer procedure,
5076 -- and the inner procedure has no contracts, so there is no problem
5077 -- in just calling it to get the original effect.
5079 -- In the case of a function, we create an appropriate return statement
5080 -- for the subprogram body that calls the inner procedure.
5082 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
5083 function Copy_Import_Pragma
return Node_Id
;
5084 -- Obtain a copy of the Import_Pragma which belongs to subprogram E
5086 ------------------------
5087 -- Copy_Import_Pragma --
5088 ------------------------
5090 function Copy_Import_Pragma
return Node_Id
is
5092 -- The subprogram should have an import pragma, otherwise it does
5095 Prag
: constant Node_Id
:= Import_Pragma
(E
);
5096 pragma Assert
(Present
(Prag
));
5098 -- Save all semantic fields of the pragma
5100 Save_Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
5101 Save_From
: constant Boolean := From_Aspect_Specification
(Prag
);
5102 Save_Prag
: constant Node_Id
:= Next_Pragma
(Prag
);
5103 Save_Rep
: constant Node_Id
:= Next_Rep_Item
(Prag
);
5108 -- Reset all semantic fields. This avoids a potential infinite
5109 -- loop when the pragma comes from an aspect as the duplication
5110 -- will copy the aspect, then copy the corresponding pragma and
5113 Set_Corresponding_Aspect
(Prag
, Empty
);
5114 Set_From_Aspect_Specification
(Prag
, False);
5115 Set_Next_Pragma
(Prag
, Empty
);
5116 Set_Next_Rep_Item
(Prag
, Empty
);
5118 Result
:= Copy_Separate_Tree
(Prag
);
5120 -- Restore the original semantic fields
5122 Set_Corresponding_Aspect
(Prag
, Save_Asp
);
5123 Set_From_Aspect_Specification
(Prag
, Save_From
);
5124 Set_Next_Pragma
(Prag
, Save_Prag
);
5125 Set_Next_Rep_Item
(Prag
, Save_Rep
);
5128 end Copy_Import_Pragma
;
5132 Loc
: constant Source_Ptr
:= Sloc
(E
);
5133 CE
: constant Name_Id
:= Chars
(E
);
5141 -- Start of processing for Wrap_Imported_Subprogram
5144 -- Nothing to do if not imported
5146 if not Is_Imported
(E
) then
5149 -- Test enabling conditions for wrapping
5151 elsif Is_Subprogram
(E
)
5152 and then Present
(Contract
(E
))
5153 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
5154 and then not GNATprove_Mode
5156 -- Here we do the wrap
5158 -- Note on calls to Copy_Separate_Tree. The trees we are copying
5159 -- here are fully analyzed, but we definitely want fully syntactic
5160 -- unanalyzed trees in the body we construct, so that the analysis
5161 -- generates the right visibility, and that is exactly what the
5162 -- calls to Copy_Separate_Tree give us.
5164 Prag
:= Copy_Import_Pragma
;
5166 -- Fix up spec so it is no longer imported and has convention Ada
5168 Set_Has_Completion
(E
, False);
5169 Set_Import_Pragma
(E
, Empty
);
5170 Set_Interface_Name
(E
, Empty
);
5171 Set_Is_Imported
(E
, False);
5172 Set_Convention
(E
, Convention_Ada
);
5174 -- Grab the subprogram declaration and specification
5176 Spec
:= Declaration_Node
(E
);
5178 -- Build parameter list that we need
5181 Forml
:= First_Formal
(E
);
5182 while Present
(Forml
) loop
5183 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
5184 Next_Formal
(Forml
);
5189 -- An imported function whose result type is anonymous access
5190 -- creates a new anonymous access type when it is relocated into
5191 -- the declarations of the body generated below. As a result, the
5192 -- accessibility level of these two anonymous access types may not
5193 -- be compatible even though they are essentially the same type.
5194 -- Use an unchecked type conversion to reconcile this case. Note
5195 -- that the conversion is safe because in the named access type
5196 -- case, both the body and imported function utilize the same
5199 if Ekind
(E
) in E_Function | E_Generic_Function
then
5201 Make_Simple_Return_Statement
(Loc
,
5203 Unchecked_Convert_To
(Etype
(E
),
5204 Make_Function_Call
(Loc
,
5205 Name
=> Make_Identifier
(Loc
, CE
),
5206 Parameter_Associations
=> Parms
)));
5210 Make_Procedure_Call_Statement
(Loc
,
5211 Name
=> Make_Identifier
(Loc
, CE
),
5212 Parameter_Associations
=> Parms
);
5215 -- Now build the body
5218 Make_Subprogram_Body
(Loc
,
5220 Copy_Separate_Tree
(Spec
),
5221 Declarations
=> New_List
(
5222 Make_Subprogram_Declaration
(Loc
,
5223 Specification
=> Copy_Separate_Tree
(Spec
)),
5225 Handled_Statement_Sequence
=>
5226 Make_Handled_Sequence_Of_Statements
(Loc
,
5227 Statements
=> New_List
(Stmt
),
5228 End_Label
=> Make_Identifier
(Loc
, CE
)));
5230 -- Append the body to freeze result
5232 Add_To_Result
(Bod
);
5235 -- Case of imported subprogram that does not get wrapped
5238 -- Set Is_Public. All imported entities need an external symbol
5239 -- created for them since they are always referenced from another
5240 -- object file. Note this used to be set when we set Is_Imported
5241 -- back in Sem_Prag, but now we delay it to this point, since we
5242 -- don't want to set this flag if we wrap an imported subprogram.
5246 end Wrap_Imported_Subprogram
;
5248 -- Start of processing for Freeze_Entity
5251 -- The entity being frozen may be subject to pragma Ghost. Set the mode
5252 -- now to ensure that any nodes generated during freezing are properly
5253 -- flagged as Ghost.
5257 -- We are going to test for various reasons why this entity need not be
5258 -- frozen here, but in the case of an Itype that's defined within a
5259 -- record, that test actually applies to the record.
5261 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
5262 Test_E
:= Scope
(E
);
5264 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
5265 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
5267 Test_E
:= Underlying_Type
(Scope
(E
));
5270 -- Do not freeze if already frozen since we only need one freeze node
5272 if Is_Frozen
(E
) then
5276 -- Do not freeze if we are preanalyzing without freezing
5278 elsif Inside_Preanalysis_Without_Freezing
> 0 then
5282 elsif Ekind
(E
) = E_Generic_Package
then
5283 Result
:= Freeze_Generic_Entities
(E
);
5286 -- It is improper to freeze an external entity within a generic because
5287 -- its freeze node will appear in a non-valid context. The entity will
5288 -- be frozen in the proper scope after the current generic is analyzed.
5289 -- However, aspects must be analyzed because they may be queried later
5290 -- within the generic itself, and the corresponding pragma or attribute
5291 -- definition has not been analyzed yet. After this, indicate that the
5292 -- entity has no further delayed aspects, to prevent a later aspect
5293 -- analysis out of the scope of the generic.
5295 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
5296 if Has_Delayed_Aspects
(E
) then
5297 Analyze_Aspects_At_Freeze_Point
(E
);
5298 Set_Has_Delayed_Aspects
(E
, False);
5304 -- AI05-0213: A formal incomplete type does not freeze the actual. In
5305 -- the instance, the same applies to the subtype renaming the actual.
5307 elsif Is_Private_Type
(E
)
5308 and then Is_Generic_Actual_Type
(E
)
5309 and then No
(Full_View
(Base_Type
(E
)))
5310 and then Ada_Version
>= Ada_2012
5315 -- Formal subprograms are never frozen
5317 elsif Is_Formal_Subprogram
(E
) then
5321 -- Generic types are never frozen as they lack delayed semantic checks
5323 elsif Is_Generic_Type
(E
) then
5327 -- Do not freeze a global entity within an inner scope created during
5328 -- expansion. A call to subprogram E within some internal procedure
5329 -- (a stream attribute for example) might require freezing E, but the
5330 -- freeze node must appear in the same declarative part as E itself.
5331 -- The two-pass elaboration mechanism in gigi guarantees that E will
5332 -- be frozen before the inner call is elaborated. We exclude constants
5333 -- from this test, because deferred constants may be frozen early, and
5334 -- must be diagnosed (e.g. in the case of a deferred constant being used
5335 -- in a default expression). If the enclosing subprogram comes from
5336 -- source, or is a generic instance, then the freeze point is the one
5337 -- mandated by the language, and we freeze the entity. A subprogram that
5338 -- is a child unit body that acts as a spec does not have a spec that
5339 -- comes from source, but can only come from source.
5341 elsif In_Open_Scopes
(Scope
(Test_E
))
5342 and then Scope
(Test_E
) /= Current_Scope
5343 and then Ekind
(Test_E
) /= E_Constant
5350 while Present
(S
) loop
5351 if Is_Overloadable
(S
) then
5352 if Comes_From_Source
(S
)
5353 or else Is_Generic_Instance
(S
)
5354 or else Is_Child_Unit
(S
)
5367 -- Similarly, an inlined instance body may make reference to global
5368 -- entities, but these references cannot be the proper freezing point
5369 -- for them, and in the absence of inlining freezing will take place in
5370 -- their own scope. Normally instance bodies are analyzed after the
5371 -- enclosing compilation, and everything has been frozen at the proper
5372 -- place, but with front-end inlining an instance body is compiled
5373 -- before the end of the enclosing scope, and as a result out-of-order
5374 -- freezing must be prevented.
5376 elsif Front_End_Inlining
5377 and then In_Instance_Body
5378 and then Present
(Scope
(Test_E
))
5384 S
:= Scope
(Test_E
);
5385 while Present
(S
) loop
5386 if Is_Generic_Instance
(S
) then
5400 -- Add checks to detect proper initialization of scalars that may appear
5401 -- as subprogram parameters.
5403 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
5404 Apply_Parameter_Validity_Checks
(E
);
5407 -- Deal with delayed aspect specifications. The analysis of the aspect
5408 -- is required to be delayed to the freeze point, thus we analyze the
5409 -- pragma or attribute definition clause in the tree at this point. We
5410 -- also analyze the aspect specification node at the freeze point when
5411 -- the aspect doesn't correspond to pragma/attribute definition clause.
5412 -- In addition, a derived type may have inherited aspects that were
5413 -- delayed in the parent, so these must also be captured now.
5415 -- For a record type, we deal with the delayed aspect specifications on
5416 -- components first, which is consistent with the non-delayed case and
5417 -- makes it possible to have a single processing to detect conflicts.
5419 if Is_Record_Type
(E
) then
5423 Rec_Pushed
: Boolean := False;
5424 -- Set True if the record type E has been pushed on the scope
5425 -- stack. Needed for the analysis of delayed aspects specified
5426 -- to the components of Rec.
5429 Comp
:= First_Entity
(E
);
5430 while Present
(Comp
) loop
5431 if Ekind
(Comp
) = E_Component
5432 and then Has_Delayed_Aspects
(Comp
)
5434 if not Rec_Pushed
then
5438 -- The visibility to the discriminants must be restored
5439 -- in order to properly analyze the aspects.
5441 if Has_Discriminants
(E
) then
5442 Install_Discriminants
(E
);
5446 Analyze_Aspects_At_Freeze_Point
(Comp
);
5452 -- Pop the scope if Rec scope has been pushed on the scope stack
5453 -- during the delayed aspect analysis process.
5456 if Has_Discriminants
(E
) then
5457 Uninstall_Discriminants
(E
);
5465 if Has_Delayed_Aspects
(E
)
5466 or else May_Inherit_Delayed_Rep_Aspects
(E
)
5468 Analyze_Aspects_At_Freeze_Point
(E
);
5471 -- Here to freeze the entity
5475 -- Case of entity being frozen is other than a type
5477 if not Is_Type
(E
) then
5479 -- If entity is exported or imported and does not have an external
5480 -- name, now is the time to provide the appropriate default name.
5481 -- Skip this if the entity is stubbed, since we don't need a name
5482 -- for any stubbed routine. For the case on intrinsics, if no
5483 -- external name is specified, then calls will be handled in
5484 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
5485 -- external name is provided, then Expand_Intrinsic_Call leaves
5486 -- calls in place for expansion by GIGI.
5488 if (Is_Imported
(E
) or else Is_Exported
(E
))
5489 and then No
(Interface_Name
(E
))
5490 and then Convention
(E
) /= Convention_Stubbed
5491 and then Convention
(E
) /= Convention_Intrinsic
5493 Set_Encoded_Interface_Name
5494 (E
, Get_Default_External_Name
(E
));
5496 -- If entity is an atomic object appearing in a declaration and
5497 -- the expression is an aggregate, assign it to a temporary to
5498 -- ensure that the actual assignment is done atomically rather
5499 -- than component-wise (the assignment to the temp may be done
5500 -- component-wise, but that is harmless).
5502 elsif Is_Full_Access
(E
)
5503 and then Nkind
(Parent
(E
)) = N_Object_Declaration
5504 and then Present
(Expression
(Parent
(E
)))
5505 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
5506 and then Is_Full_Access_Aggregate
(Expression
(Parent
(E
)))
5513 if Is_Subprogram
(E
) then
5515 -- Check for needing to wrap imported subprogram
5517 Wrap_Imported_Subprogram
(E
);
5519 -- Freeze all parameter types and the return type (RM 13.14(14)).
5520 -- However skip this for internal subprograms. This is also where
5521 -- any extra formal parameters are created since we now know
5522 -- whether the subprogram will use a foreign convention.
5524 -- In Ada 2012, freezing a subprogram does not always freeze the
5525 -- corresponding profile (see AI05-019). An attribute reference
5526 -- is not a freezing point of the profile. Flag Do_Freeze_Profile
5527 -- indicates whether the profile should be frozen now.
5528 -- Other constructs that should not freeze ???
5530 -- This processing doesn't apply to internal entities (see below)
5532 if not Is_Internal
(E
) and then Do_Freeze_Profile
then
5533 if not Freeze_Profile
(E
) then
5538 -- Must freeze its parent first if it is a derived subprogram
5540 if Present
(Alias
(E
)) then
5541 Freeze_And_Append
(Alias
(E
), N
, Result
);
5544 -- We don't freeze internal subprograms, because we don't normally
5545 -- want addition of extra formals or mechanism setting to happen
5546 -- for those. However we do pass through predefined dispatching
5547 -- cases, since extra formals may be needed in some cases, such as
5548 -- for the stream 'Input function (build-in-place formals).
5550 if not Is_Internal
(E
)
5551 or else Is_Predefined_Dispatching_Operation
(E
)
5553 Freeze_Subprogram
(E
);
5556 -- If warning on suspicious contracts then check for the case of
5557 -- a postcondition other than False for a No_Return subprogram.
5560 and then Warn_On_Suspicious_Contract
5561 and then Present
(Contract
(E
))
5564 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
5568 while Present
(Prag
) loop
5569 if Pragma_Name_Unmapped
(Prag
) in Name_Post
5570 | Name_Postcondition
5575 (First
(Pragma_Argument_Associations
(Prag
)));
5577 if Nkind
(Exp
) /= N_Identifier
5578 or else Chars
(Exp
) /= Name_False
5581 ("useless postcondition, & is marked "
5582 & "No_Return?T?", Exp
, E
);
5586 Prag
:= Next_Pragma
(Prag
);
5591 -- Here for other than a subprogram or type
5594 -- If entity has a type, and it is not a generic unit, then freeze
5595 -- it first (RM 13.14(10)).
5597 if Present
(Etype
(E
))
5598 and then Ekind
(E
) /= E_Generic_Function
5600 Freeze_And_Append
(Etype
(E
), N
, Result
);
5602 -- For an object of an anonymous array type, aspects on the
5603 -- object declaration apply to the type itself. This is the
5604 -- case for Atomic_Components, Volatile_Components, and
5605 -- Independent_Components. In these cases analysis of the
5606 -- generated pragma will mark the anonymous types accordingly,
5607 -- and the object itself does not require a freeze node.
5609 if Ekind
(E
) = E_Variable
5610 and then Is_Itype
(Etype
(E
))
5611 and then Is_Array_Type
(Etype
(E
))
5612 and then Has_Delayed_Aspects
(E
)
5614 Set_Has_Delayed_Aspects
(E
, False);
5615 Set_Has_Delayed_Freeze
(E
, False);
5616 Set_Freeze_Node
(E
, Empty
);
5620 -- Special processing for objects created by object declaration
5622 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
5623 Freeze_Object_Declaration
(E
);
5626 -- Check that a constant which has a pragma Volatile[_Components]
5627 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
5629 -- Note: Atomic[_Components] also sets Volatile[_Components]
5631 if Ekind
(E
) = E_Constant
5632 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
5633 and then not Is_Imported
(E
)
5634 and then not Has_Boolean_Aspect_Import
(E
)
5636 -- Make sure we actually have a pragma, and have not merely
5637 -- inherited the indication from elsewhere (e.g. an address
5638 -- clause, which is not good enough in RM terms).
5640 if Has_Rep_Pragma
(E
, Name_Atomic
)
5642 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
5645 ("standalone atomic constant must be " &
5646 "imported (RM C.6(13))", E
);
5648 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
5650 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
5653 ("standalone volatile constant must be " &
5654 "imported (RM C.6(13))", E
);
5658 -- Static objects require special handling
5660 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
5661 and then Is_Statically_Allocated
(E
)
5663 Freeze_Static_Object
(E
);
5666 -- Remaining step is to layout objects
5668 if Ekind
(E
) in E_Variable | E_Constant | E_Loop_Parameter
5669 or else Is_Formal
(E
)
5674 -- For an object that does not have delayed freezing, and whose
5675 -- initialization actions have been captured in a compound
5676 -- statement, move them back now directly within the enclosing
5677 -- statement sequence.
5679 if Ekind
(E
) in E_Constant | E_Variable
5680 and then not Has_Delayed_Freeze
(E
)
5682 Explode_Initialization_Compound_Statement
(E
);
5685 -- Do not generate a freeze node for a generic unit
5687 if Is_Generic_Unit
(E
) then
5693 -- Case of a type or subtype being frozen
5696 -- Verify several SPARK legality rules related to Ghost types now
5697 -- that the type is frozen.
5699 Check_Ghost_Type
(E
);
5701 -- We used to check here that a full type must have preelaborable
5702 -- initialization if it completes a private type specified with
5703 -- pragma Preelaborable_Initialization, but that missed cases where
5704 -- the types occur within a generic package, since the freezing
5705 -- that occurs within a containing scope generally skips traversal
5706 -- of a generic unit's declarations (those will be frozen within
5707 -- instances). This check was moved to Analyze_Package_Specification.
5709 -- The type may be defined in a generic unit. This can occur when
5710 -- freezing a generic function that returns the type (which is
5711 -- defined in a parent unit). It is clearly meaningless to freeze
5712 -- this type. However, if it is a subtype, its size may be determi-
5713 -- nable and used in subsequent checks, so might as well try to
5716 -- In Ada 2012, Freeze_Entities is also used in the front end to
5717 -- trigger the analysis of aspect expressions, so in this case we
5718 -- want to continue the freezing process.
5720 -- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead
5721 -- In_Generic_Scope (E)???
5723 if Present
(Scope
(E
))
5724 and then Is_Generic_Unit
(Scope
(E
))
5726 (not Has_Predicates
(E
)
5727 and then not Has_Delayed_Freeze
(E
))
5729 Check_Compile_Time_Size
(E
);
5734 -- Check for error of Type_Invariant'Class applied to an untagged
5735 -- type (check delayed to freeze time when full type is available).
5738 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
5741 and then Class_Present
(Prag
)
5742 and then not Is_Tagged_Type
(E
)
5745 ("Type_Invariant''Class cannot be specified for &", Prag
, E
);
5747 ("\can only be specified for a tagged type", Prag
);
5751 -- Deal with special cases of freezing for subtype
5753 if E
/= Base_Type
(E
) then
5755 -- Before we do anything else, a specific test for the case of a
5756 -- size given for an array where the array would need to be packed
5757 -- in order for the size to be honored, but is not. This is the
5758 -- case where implicit packing may apply. The reason we do this so
5759 -- early is that, if we have implicit packing, the layout of the
5760 -- base type is affected, so we must do this before we freeze the
5763 -- We could do this processing only if implicit packing is enabled
5764 -- since in all other cases, the error would be caught by the back
5765 -- end. However, we choose to do the check even if we do not have
5766 -- implicit packing enabled, since this allows us to give a more
5767 -- useful error message (advising use of pragma Implicit_Packing
5770 if Is_Array_Type
(E
) then
5772 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
5773 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
5774 SZ
: constant Node_Id
:= Size_Clause
(E
);
5775 Btyp
: constant Entity_Id
:= Base_Type
(E
);
5782 Num_Elmts
: Uint
:= Uint_1
;
5783 -- Number of elements in array
5786 -- Check enabling conditions. These are straightforward
5787 -- except for the test for a limited composite type. This
5788 -- eliminates the rare case of a array of limited components
5789 -- where there are issues of whether or not we can go ahead
5790 -- and pack the array (since we can't freely pack and unpack
5791 -- arrays if they are limited).
5793 -- Note that we check the root type explicitly because the
5794 -- whole point is we are doing this test before we have had
5795 -- a chance to freeze the base type (and it is that freeze
5796 -- action that causes stuff to be inherited).
5798 -- The conditions on the size are identical to those used in
5799 -- Freeze_Array_Type to set the Is_Packed flag.
5801 if Has_Size_Clause
(E
)
5802 and then Known_Static_RM_Size
(E
)
5803 and then not Is_Packed
(E
)
5804 and then not Has_Pragma_Pack
(E
)
5805 and then not Has_Component_Size_Clause
(E
)
5806 and then Known_Static_RM_Size
(Ctyp
)
5807 and then Rsiz
<= System_Max_Integer_Size
5808 and then not (Addressable
(Rsiz
)
5809 and then Known_Static_Esize
(Ctyp
)
5810 and then Esize
(Ctyp
) = Rsiz
)
5811 and then not (Rsiz
mod System_Storage_Unit
= 0
5812 and then Is_Composite_Type
(Ctyp
))
5813 and then not Is_Limited_Composite
(E
)
5814 and then not Is_Packed
(Root_Type
(E
))
5815 and then not Has_Component_Size_Clause
(Root_Type
(E
))
5816 and then not (CodePeer_Mode
or GNATprove_Mode
)
5818 -- Compute number of elements in array
5820 Indx
:= First_Index
(E
);
5821 while Present
(Indx
) loop
5822 Get_Index_Bounds
(Indx
, Lo
, Hi
);
5824 if not (Compile_Time_Known_Value
(Lo
)
5826 Compile_Time_Known_Value
(Hi
))
5828 goto No_Implicit_Packing
;
5831 Dim
:= Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1;
5834 Num_Elmts
:= Num_Elmts
* Dim
;
5836 Num_Elmts
:= Uint_0
;
5842 -- What we are looking for here is the situation where
5843 -- the RM_Size given would be exactly right if there was
5844 -- a pragma Pack, resulting in the component size being
5845 -- the RM_Size of the component type.
5847 if RM_Size
(E
) = Num_Elmts
* Rsiz
then
5849 -- For implicit packing mode, just set the component
5850 -- size and Freeze_Array_Type will do the rest.
5852 if Implicit_Packing
then
5853 Set_Component_Size
(Btyp
, Rsiz
);
5855 -- Otherwise give an error message
5859 ("size given for& too small", SZ
, E
);
5860 Error_Msg_N
-- CODEFIX
5861 ("\use explicit pragma Pack or use pragma "
5862 & "Implicit_Packing", SZ
);
5869 <<No_Implicit_Packing
>>
5871 -- If ancestor subtype present, freeze that first. Note that this
5872 -- will also get the base type frozen. Need RM reference ???
5874 Atype
:= Ancestor_Subtype
(E
);
5876 if Present
(Atype
) then
5877 Freeze_And_Append
(Atype
, N
, Result
);
5879 -- No ancestor subtype present
5882 -- See if we have a nearest ancestor that has a predicate.
5883 -- That catches the case of derived type with a predicate.
5884 -- Need RM reference here ???
5886 Atype
:= Nearest_Ancestor
(E
);
5888 if Present
(Atype
) and then Has_Predicates
(Atype
) then
5889 Freeze_And_Append
(Atype
, N
, Result
);
5892 -- Freeze base type before freezing the entity (RM 13.14(15))
5894 if E
/= Base_Type
(E
) then
5895 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
5899 -- A subtype inherits all the type-related representation aspects
5900 -- from its parents (RM 13.1(8)).
5902 Inherit_Aspects_At_Freeze_Point
(E
);
5904 -- For a derived type, freeze its parent type first (RM 13.14(15))
5906 elsif Is_Derived_Type
(E
) then
5907 Freeze_And_Append
(Etype
(E
), N
, Result
);
5908 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
5910 -- A derived type inherits each type-related representation aspect
5911 -- of its parent type that was directly specified before the
5912 -- declaration of the derived type (RM 13.1(15)).
5914 Inherit_Aspects_At_Freeze_Point
(E
);
5917 -- Case of array type
5919 if Is_Array_Type
(E
) then
5920 Freeze_Array_Type
(E
);
5923 -- Check for incompatible size and alignment for array/record type
5925 if Warn_On_Size_Alignment
5926 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
5927 and then Has_Size_Clause
(E
)
5928 and then Has_Alignment_Clause
(E
)
5930 -- If explicit Object_Size clause given assume that the programmer
5931 -- knows what he is doing, and expects the compiler behavior.
5933 and then not Has_Object_Size_Clause
(E
)
5935 -- It does not really make sense to warn for the minimum alignment
5936 -- since the programmer could not get rid of the warning.
5938 and then Alignment
(E
) > 1
5940 -- Check for size not a multiple of alignment
5942 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
5945 SC
: constant Node_Id
:= Size_Clause
(E
);
5946 AC
: constant Node_Id
:= Alignment_Clause
(E
);
5948 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
5951 if Present
(SC
) and then Present
(AC
) then
5955 if Sloc
(SC
) > Sloc
(AC
) then
5958 ("?Z?size is not a multiple of alignment for &",
5960 Error_Msg_Sloc
:= Sloc
(AC
);
5961 Error_Msg_Uint_1
:= Alignment
(E
);
5962 Error_Msg_N
("\?Z?alignment of ^ specified #", Loc
);
5967 ("?Z?size is not a multiple of alignment for &",
5969 Error_Msg_Sloc
:= Sloc
(SC
);
5970 Error_Msg_Uint_1
:= RM_Size
(E
);
5971 Error_Msg_N
("\?Z?size of ^ specified #", Loc
);
5974 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
5975 Error_Msg_N
("\?Z?Object_Size will be increased to ^", Loc
);
5980 -- For a class-wide type, the corresponding specific type is
5981 -- frozen as well (RM 13.14(15))
5983 if Is_Class_Wide_Type
(E
) then
5984 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
5986 -- If the base type of the class-wide type is still incomplete,
5987 -- the class-wide remains unfrozen as well. This is legal when
5988 -- E is the formal of a primitive operation of some other type
5989 -- which is being frozen.
5991 if not Is_Frozen
(Root_Type
(E
)) then
5992 Set_Is_Frozen
(E
, False);
5996 -- The equivalent type associated with a class-wide subtype needs
5997 -- to be frozen to ensure that its layout is done.
5999 if Ekind
(E
) = E_Class_Wide_Subtype
6000 and then Present
(Equivalent_Type
(E
))
6002 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
6005 -- Generate an itype reference for a library-level class-wide type
6006 -- at the freeze point. Otherwise the first explicit reference to
6007 -- the type may appear in an inner scope which will be rejected by
6011 and then Is_Compilation_Unit
(Scope
(E
))
6014 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
6019 -- From a gigi point of view, a class-wide subtype derives
6020 -- from its record equivalent type. As a result, the itype
6021 -- reference must appear after the freeze node of the
6022 -- equivalent type or gigi will reject the reference.
6024 if Ekind
(E
) = E_Class_Wide_Subtype
6025 and then Present
(Equivalent_Type
(E
))
6027 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
6029 Add_To_Result
(Ref
);
6034 -- For a record type or record subtype, freeze all component types
6035 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
6036 -- using Is_Record_Type, because we don't want to attempt the freeze
6037 -- for the case of a private type with record extension (we will do
6038 -- that later when the full type is frozen).
6040 elsif Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
6041 if not In_Generic_Scope
(E
) then
6042 Freeze_Record_Type
(E
);
6045 -- Report a warning if a discriminated record base type has a
6046 -- convention with language C or C++ applied to it. This check is
6047 -- done even within generic scopes (but not in instantiations),
6048 -- which is why we don't do it as part of Freeze_Record_Type.
6050 Check_Suspicious_Convention
(E
);
6052 -- For a concurrent type, freeze corresponding record type. This does
6053 -- not correspond to any specific rule in the RM, but the record type
6054 -- is essentially part of the concurrent type. Also freeze all local
6055 -- entities. This includes record types created for entry parameter
6056 -- blocks and whatever local entities may appear in the private part.
6058 elsif Is_Concurrent_Type
(E
) then
6059 if Present
(Corresponding_Record_Type
(E
)) then
6060 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
6063 Comp
:= First_Entity
(E
);
6064 while Present
(Comp
) loop
6065 if Is_Type
(Comp
) then
6066 Freeze_And_Append
(Comp
, N
, Result
);
6068 elsif (Ekind
(Comp
)) /= E_Function
then
6070 -- The guard on the presence of the Etype seems to be needed
6071 -- for some CodePeer (-gnatcC) cases, but not clear why???
6073 if Present
(Etype
(Comp
)) then
6074 if Is_Itype
(Etype
(Comp
))
6075 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
6077 Undelay_Type
(Etype
(Comp
));
6080 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
6087 -- Private types are required to point to the same freeze node as
6088 -- their corresponding full views. The freeze node itself has to
6089 -- point to the partial view of the entity (because from the partial
6090 -- view, we can retrieve the full view, but not the reverse).
6091 -- However, in order to freeze correctly, we need to freeze the full
6092 -- view. If we are freezing at the end of a scope (or within the
6093 -- scope) of the private type, the partial and full views will have
6094 -- been swapped, the full view appears first in the entity chain and
6095 -- the swapping mechanism ensures that the pointers are properly set
6098 -- If we encounter the partial view before the full view (e.g. when
6099 -- freezing from another scope), we freeze the full view, and then
6100 -- set the pointers appropriately since we cannot rely on swapping to
6101 -- fix things up (subtypes in an outer scope might not get swapped).
6103 -- If the full view is itself private, the above requirements apply
6104 -- to the underlying full view instead of the full view. But there is
6105 -- no swapping mechanism for the underlying full view so we need to
6106 -- set the pointers appropriately in both cases.
6108 elsif Is_Incomplete_Or_Private_Type
(E
)
6109 and then not Is_Generic_Type
(E
)
6111 -- The construction of the dispatch table associated with library
6112 -- level tagged types forces freezing of all the primitives of the
6113 -- type, which may cause premature freezing of the partial view.
6117 -- type T is tagged private;
6118 -- type DT is new T with private;
6119 -- procedure Prim (X : in out T; Y : in out DT'Class);
6121 -- type T is tagged null record;
6123 -- type DT is new T with null record;
6126 -- In this case the type will be frozen later by the usual
6127 -- mechanism: an object declaration, an instantiation, or the
6128 -- end of a declarative part.
6130 if Is_Library_Level_Tagged_Type
(E
)
6131 and then not Present
(Full_View
(E
))
6133 Set_Is_Frozen
(E
, False);
6136 -- Case of full view present
6138 elsif Present
(Full_View
(E
)) then
6140 -- If full view has already been frozen, then no further
6141 -- processing is required
6143 if Is_Frozen
(Full_View
(E
)) then
6144 Set_Has_Delayed_Freeze
(E
, False);
6145 Set_Freeze_Node
(E
, Empty
);
6147 -- Otherwise freeze full view and patch the pointers so that
6148 -- the freeze node will elaborate both views in the back end.
6149 -- However, if full view is itself private, freeze underlying
6150 -- full view instead and patch the pointers so that the freeze
6151 -- node will elaborate the three views in the back end.
6155 Full
: Entity_Id
:= Full_View
(E
);
6158 if Is_Private_Type
(Full
)
6159 and then Present
(Underlying_Full_View
(Full
))
6161 Full
:= Underlying_Full_View
(Full
);
6164 Freeze_And_Append
(Full
, N
, Result
);
6166 if Full
/= Full_View
(E
)
6167 and then Has_Delayed_Freeze
(Full_View
(E
))
6169 F_Node
:= Freeze_Node
(Full
);
6171 if Present
(F_Node
) then
6173 (Fnod
=> F_Node
, Typ
=> Full_View
(E
));
6175 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
6176 Set_Freeze_Node
(Full_View
(E
), Empty
);
6180 if Has_Delayed_Freeze
(E
) then
6181 F_Node
:= Freeze_Node
(Full_View
(E
));
6183 if Present
(F_Node
) then
6184 Inherit_Freeze_Node
(Fnod
=> F_Node
, Typ
=> E
);
6186 -- {Incomplete,Private}_Subtypes with Full_Views
6187 -- constrained by discriminants.
6189 Set_Has_Delayed_Freeze
(E
, False);
6190 Set_Freeze_Node
(E
, Empty
);
6196 Check_Debug_Info_Needed
(E
);
6198 -- AI-117 requires that the convention of a partial view be the
6199 -- same as the convention of the full view. Note that this is a
6200 -- recognized breach of privacy, but it's essential for logical
6201 -- consistency of representation, and the lack of a rule in
6202 -- RM95 was an oversight.
6204 Set_Convention
(E
, Convention
(Full_View
(E
)));
6206 Set_Size_Known_At_Compile_Time
(E
,
6207 Size_Known_At_Compile_Time
(Full_View
(E
)));
6209 -- Size information is copied from the full view to the
6210 -- incomplete or private view for consistency.
6212 -- We skip this is the full view is not a type. This is very
6213 -- strange of course, and can only happen as a result of
6214 -- certain illegalities, such as a premature attempt to derive
6215 -- from an incomplete type.
6217 if Is_Type
(Full_View
(E
)) then
6218 Set_Size_Info
(E
, Full_View
(E
));
6219 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
6224 -- Case of underlying full view present
6226 elsif Is_Private_Type
(E
)
6227 and then Present
(Underlying_Full_View
(E
))
6229 if not Is_Frozen
(Underlying_Full_View
(E
)) then
6230 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
6233 -- Patch the pointers so that the freeze node will elaborate
6234 -- both views in the back end.
6236 if Has_Delayed_Freeze
(E
) then
6237 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
6239 if Present
(F_Node
) then
6244 Set_Has_Delayed_Freeze
(E
, False);
6245 Set_Freeze_Node
(E
, Empty
);
6249 Check_Debug_Info_Needed
(E
);
6253 -- Case of no full view present. If entity is subtype or derived,
6254 -- it is safe to freeze, correctness depends on the frozen status
6255 -- of parent. Otherwise it is either premature usage, or a Taft
6256 -- amendment type, so diagnosis is at the point of use and the
6257 -- type might be frozen later.
6259 elsif E
/= Base_Type
(E
) then
6261 Btyp
: constant Entity_Id
:= Base_Type
(E
);
6264 -- However, if the base type is itself private and has no
6265 -- (underlying) full view either, wait until the full type
6266 -- declaration is seen and all the full views are created.
6268 if Is_Private_Type
(Btyp
)
6269 and then No
(Full_View
(Btyp
))
6270 and then No
(Underlying_Full_View
(Btyp
))
6271 and then Has_Delayed_Freeze
(Btyp
)
6272 and then No
(Freeze_Node
(Btyp
))
6274 Set_Is_Frozen
(E
, False);
6280 elsif Is_Derived_Type
(E
) then
6284 Set_Is_Frozen
(E
, False);
6289 -- For access subprogram, freeze types of all formals, the return
6290 -- type was already frozen, since it is the Etype of the function.
6291 -- Formal types can be tagged Taft amendment types, but otherwise
6292 -- they cannot be incomplete.
6294 elsif Ekind
(E
) = E_Subprogram_Type
then
6295 Formal
:= First_Formal
(E
);
6296 while Present
(Formal
) loop
6297 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
6298 and then No
(Full_View
(Etype
(Formal
)))
6300 if Is_Tagged_Type
(Etype
(Formal
)) then
6303 -- AI05-151: Incomplete types are allowed in access to
6304 -- subprogram specifications.
6306 elsif Ada_Version
< Ada_2012
then
6308 ("invalid use of incomplete type&", E
, Etype
(Formal
));
6312 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
6313 Next_Formal
(Formal
);
6316 Freeze_Subprogram
(E
);
6318 -- For access to a protected subprogram, freeze the equivalent type
6319 -- (however this is not set if we are not generating code or if this
6320 -- is an anonymous type used just for resolution).
6322 elsif Is_Access_Protected_Subprogram_Type
(E
) then
6323 if Present
(Equivalent_Type
(E
)) then
6324 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
6328 -- Generic types are never seen by the back-end, and are also not
6329 -- processed by the expander (since the expander is turned off for
6330 -- generic processing), so we never need freeze nodes for them.
6332 if Is_Generic_Type
(E
) then
6336 -- Some special processing for non-generic types to complete
6337 -- representation details not known till the freeze point.
6339 if Is_Fixed_Point_Type
(E
) then
6340 Freeze_Fixed_Point_Type
(E
);
6342 elsif Is_Enumeration_Type
(E
) then
6343 Freeze_Enumeration_Type
(E
);
6345 elsif Is_Integer_Type
(E
) then
6346 Adjust_Esize_For_Alignment
(E
);
6348 if Is_Modular_Integer_Type
(E
)
6349 and then Warn_On_Suspicious_Modulus_Value
6351 Check_Suspicious_Modulus
(E
);
6354 -- The pool applies to named and anonymous access types, but not
6355 -- to subprogram and to internal types generated for 'Access
6358 elsif Is_Access_Object_Type
(E
)
6359 and then Ekind
(E
) /= E_Access_Attribute_Type
6361 -- If a pragma Default_Storage_Pool applies, and this type has no
6362 -- Storage_Pool or Storage_Size clause (which must have occurred
6363 -- before the freezing point), then use the default. This applies
6364 -- only to base types.
6366 -- None of this applies to access to subprograms, for which there
6367 -- are clearly no pools.
6369 if Present
(Default_Pool
)
6370 and then Is_Base_Type
(E
)
6371 and then not Has_Storage_Size_Clause
(E
)
6372 and then No
(Associated_Storage_Pool
(E
))
6374 -- Case of pragma Default_Storage_Pool (null)
6376 if Nkind
(Default_Pool
) = N_Null
then
6377 Set_No_Pool_Assigned
(E
);
6379 -- Case of pragma Default_Storage_Pool (Standard)
6381 elsif Entity
(Default_Pool
) = Standard_Standard
then
6382 Set_Associated_Storage_Pool
(E
, RTE
(RE_Global_Pool_Object
));
6384 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
6387 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
6391 -- Check restriction for standard storage pool
6393 if No
(Associated_Storage_Pool
(E
)) then
6394 Check_Restriction
(No_Standard_Storage_Pools
, E
);
6397 -- Deal with error message for pure access type. This is not an
6398 -- error in Ada 2005 if there is no pool (see AI-366).
6400 if Is_Pure_Unit_Access_Type
(E
)
6401 and then (Ada_Version
< Ada_2005
6402 or else not No_Pool_Assigned
(E
))
6403 and then not Is_Generic_Unit
(Scope
(E
))
6405 Error_Msg_N
("named access type not allowed in pure unit", E
);
6407 if Ada_Version
>= Ada_2005
then
6409 ("\would be legal if Storage_Size of 0 given??", E
);
6411 elsif No_Pool_Assigned
(E
) then
6413 ("\would be legal in Ada 2005??", E
);
6417 ("\would be legal in Ada 2005 if "
6418 & "Storage_Size of 0 given??", E
);
6423 -- Case of composite types
6425 if Is_Composite_Type
(E
) then
6427 -- AI-117 requires that all new primitives of a tagged type must
6428 -- inherit the convention of the full view of the type. Inherited
6429 -- and overriding operations are defined to inherit the convention
6430 -- of their parent or overridden subprogram (also specified in
6431 -- AI-117), which will have occurred earlier (in Derive_Subprogram
6432 -- and New_Overloaded_Entity). Here we set the convention of
6433 -- primitives that are still convention Ada, which will ensure
6434 -- that any new primitives inherit the type's convention. Class-
6435 -- wide types can have a foreign convention inherited from their
6436 -- specific type, but are excluded from this since they don't have
6437 -- any associated primitives.
6439 if Is_Tagged_Type
(E
)
6440 and then not Is_Class_Wide_Type
(E
)
6441 and then Convention
(E
) /= Convention_Ada
6444 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
6448 Prim
:= First_Elmt
(Prim_List
);
6449 while Present
(Prim
) loop
6450 if Convention
(Node
(Prim
)) = Convention_Ada
then
6451 Set_Convention
(Node
(Prim
), Convention
(E
));
6459 -- If the type is a simple storage pool type, then this is where
6460 -- we attempt to locate and validate its Allocate, Deallocate, and
6461 -- Storage_Size operations (the first is required, and the latter
6462 -- two are optional). We also verify that the full type for a
6463 -- private type is allowed to be a simple storage pool type.
6465 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
6466 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
6468 -- If the type is marked Has_Private_Declaration, then this is
6469 -- a full type for a private type that was specified with the
6470 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
6471 -- pragma is allowed for the full type (for example, it can't
6472 -- be an array type, or a nonlimited record type).
6474 if Has_Private_Declaration
(E
) then
6475 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
6476 and then not Is_Private_Type
(E
)
6478 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
6480 ("pragma% can only apply to full type that is an " &
6481 "explicitly limited type", E
);
6485 Validate_Simple_Pool_Ops
: declare
6486 Pool_Type
: Entity_Id
renames E
;
6487 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
6488 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
6490 procedure Validate_Simple_Pool_Op_Formal
6491 (Pool_Op
: Entity_Id
;
6492 Pool_Op_Formal
: in out Entity_Id
;
6493 Expected_Mode
: Formal_Kind
;
6494 Expected_Type
: Entity_Id
;
6495 Formal_Name
: String;
6496 OK_Formal
: in out Boolean);
6497 -- Validate one formal Pool_Op_Formal of the candidate pool
6498 -- operation Pool_Op. The formal must be of Expected_Type
6499 -- and have mode Expected_Mode. OK_Formal will be set to
6500 -- False if the formal doesn't match. If OK_Formal is False
6501 -- on entry, then the formal will effectively be ignored
6502 -- (because validation of the pool op has already failed).
6503 -- Upon return, Pool_Op_Formal will be updated to the next
6506 procedure Validate_Simple_Pool_Operation
6507 (Op_Name
: Name_Id
);
6508 -- Search for and validate a simple pool operation with the
6509 -- name Op_Name. If the name is Allocate, then there must be
6510 -- exactly one such primitive operation for the simple pool
6511 -- type. If the name is Deallocate or Storage_Size, then
6512 -- there can be at most one such primitive operation. The
6513 -- profile of the located primitive must conform to what
6514 -- is expected for each operation.
6516 ------------------------------------
6517 -- Validate_Simple_Pool_Op_Formal --
6518 ------------------------------------
6520 procedure Validate_Simple_Pool_Op_Formal
6521 (Pool_Op
: Entity_Id
;
6522 Pool_Op_Formal
: in out Entity_Id
;
6523 Expected_Mode
: Formal_Kind
;
6524 Expected_Type
: Entity_Id
;
6525 Formal_Name
: String;
6526 OK_Formal
: in out Boolean)
6529 -- If OK_Formal is False on entry, then simply ignore
6530 -- the formal, because an earlier formal has already
6533 if not OK_Formal
then
6536 -- If no formal is passed in, then issue an error for a
6539 elsif not Present
(Pool_Op_Formal
) then
6541 ("simple storage pool op missing formal " &
6542 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
6548 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
6550 -- If the pool type was expected for this formal, then
6551 -- this will not be considered a candidate operation
6552 -- for the simple pool, so we unset OK_Formal so that
6553 -- the op and any later formals will be ignored.
6555 if Expected_Type
= Pool_Type
then
6562 ("wrong type for formal " & Formal_Name
&
6563 " of simple storage pool op; expected type&",
6564 Pool_Op_Formal
, Expected_Type
);
6568 -- Issue error if formal's mode is not the expected one
6570 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
6572 ("wrong mode for formal of simple storage pool op",
6576 -- Advance to the next formal
6578 Next_Formal
(Pool_Op_Formal
);
6579 end Validate_Simple_Pool_Op_Formal
;
6581 ------------------------------------
6582 -- Validate_Simple_Pool_Operation --
6583 ------------------------------------
6585 procedure Validate_Simple_Pool_Operation
6589 Found_Op
: Entity_Id
:= Empty
;
6595 (Op_Name
in Name_Allocate
6597 | Name_Storage_Size
);
6599 Error_Msg_Name_1
:= Op_Name
;
6601 -- For each homonym declared immediately in the scope
6602 -- of the simple storage pool type, determine whether
6603 -- the homonym is an operation of the pool type, and,
6604 -- if so, check that its profile is as expected for
6605 -- a simple pool operation of that name.
6607 Op
:= Get_Name_Entity_Id
(Op_Name
);
6608 while Present
(Op
) loop
6609 if Ekind
(Op
) in E_Function | E_Procedure
6610 and then Scope
(Op
) = Current_Scope
6612 Formal
:= First_Entity
(Op
);
6616 -- The first parameter must be of the pool type
6617 -- in order for the operation to qualify.
6619 if Op_Name
= Name_Storage_Size
then
6620 Validate_Simple_Pool_Op_Formal
6621 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
6624 Validate_Simple_Pool_Op_Formal
6625 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
6629 -- If another operation with this name has already
6630 -- been located for the type, then flag an error,
6631 -- since we only allow the type to have a single
6634 if Present
(Found_Op
) and then Is_OK
then
6636 ("only one % operation allowed for " &
6637 "simple storage pool type&", Op
, Pool_Type
);
6640 -- In the case of Allocate and Deallocate, a formal
6641 -- of type System.Address is required.
6643 if Op_Name
= Name_Allocate
then
6644 Validate_Simple_Pool_Op_Formal
6645 (Op
, Formal
, E_Out_Parameter
,
6646 Address_Type
, "Storage_Address", Is_OK
);
6648 elsif Op_Name
= Name_Deallocate
then
6649 Validate_Simple_Pool_Op_Formal
6650 (Op
, Formal
, E_In_Parameter
,
6651 Address_Type
, "Storage_Address", Is_OK
);
6654 -- In the case of Allocate and Deallocate, formals
6655 -- of type Storage_Count are required as the third
6656 -- and fourth parameters.
6658 if Op_Name
/= Name_Storage_Size
then
6659 Validate_Simple_Pool_Op_Formal
6660 (Op
, Formal
, E_In_Parameter
,
6661 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
6662 Validate_Simple_Pool_Op_Formal
6663 (Op
, Formal
, E_In_Parameter
,
6664 Stg_Cnt_Type
, "Alignment", Is_OK
);
6667 -- If no mismatched formals have been found (Is_OK)
6668 -- and no excess formals are present, then this
6669 -- operation has been validated, so record it.
6671 if not Present
(Formal
) and then Is_OK
then
6679 -- There must be a valid Allocate operation for the type,
6680 -- so issue an error if none was found.
6682 if Op_Name
= Name_Allocate
6683 and then not Present
(Found_Op
)
6685 Error_Msg_N
("missing % operation for simple " &
6686 "storage pool type", Pool_Type
);
6688 elsif Present
(Found_Op
) then
6690 -- Simple pool operations can't be abstract
6692 if Is_Abstract_Subprogram
(Found_Op
) then
6694 ("simple storage pool operation must not be " &
6695 "abstract", Found_Op
);
6698 -- The Storage_Size operation must be a function with
6699 -- Storage_Count as its result type.
6701 if Op_Name
= Name_Storage_Size
then
6702 if Ekind
(Found_Op
) = E_Procedure
then
6704 ("% operation must be a function", Found_Op
);
6706 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
6708 ("wrong result type for%, expected type&",
6709 Found_Op
, Stg_Cnt_Type
);
6712 -- Allocate and Deallocate must be procedures
6714 elsif Ekind
(Found_Op
) = E_Function
then
6716 ("% operation must be a procedure", Found_Op
);
6719 end Validate_Simple_Pool_Operation
;
6721 -- Start of processing for Validate_Simple_Pool_Ops
6724 Validate_Simple_Pool_Operation
(Name_Allocate
);
6725 Validate_Simple_Pool_Operation
(Name_Deallocate
);
6726 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
6727 end Validate_Simple_Pool_Ops
;
6731 -- Now that all types from which E may depend are frozen, see if
6732 -- strict alignment is required, a component clause on a record
6733 -- is correct, the size is known at compile time and if it must
6734 -- be unsigned, in that order.
6736 if Base_Type
(E
) = E
then
6737 Check_Strict_Alignment
(E
);
6740 if Ekind
(E
) in E_Record_Type | E_Record_Subtype
then
6742 RC
: constant Node_Id
:= Get_Record_Representation_Clause
(E
);
6744 if Present
(RC
) then
6745 Check_Record_Representation_Clause
(RC
);
6750 Check_Compile_Time_Size
(E
);
6752 Check_Unsigned_Type
(E
);
6754 -- Do not allow a size clause for a type which does not have a size
6755 -- that is known at compile time
6757 if (Has_Size_Clause
(E
) or else Has_Object_Size_Clause
(E
))
6758 and then not Size_Known_At_Compile_Time
(E
)
6760 -- Suppress this message if errors posted on E, even if we are
6761 -- in all errors mode, since this is often a junk message
6763 if not Error_Posted
(E
) then
6765 ("size clause not allowed for variable length type",
6770 -- Now we set/verify the representation information, in particular
6771 -- the size and alignment values. This processing is not required for
6772 -- generic types, since generic types do not play any part in code
6773 -- generation, and so the size and alignment values for such types
6774 -- are irrelevant. Ditto for types declared within a generic unit,
6775 -- which may have components that depend on generic parameters, and
6776 -- that will be recreated in an instance.
6778 if Inside_A_Generic
then
6781 -- Otherwise we call the layout procedure
6787 -- If this is an access to subprogram whose designated type is itself
6788 -- a subprogram type, the return type of this anonymous subprogram
6789 -- type must be decorated as well.
6791 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
6792 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
6794 Layout_Type
(Etype
(Designated_Type
(E
)));
6797 -- If the type has a Defaut_Value/Default_Component_Value aspect,
6798 -- this is where we analyze the expression (after the type is frozen,
6799 -- since in the case of Default_Value, we are analyzing with the
6800 -- type itself, and we treat Default_Component_Value similarly for
6801 -- the sake of uniformity).
6803 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
6810 if Is_Scalar_Type
(E
) then
6811 Nam
:= Name_Default_Value
;
6813 Exp
:= Default_Aspect_Value
(Typ
);
6815 Nam
:= Name_Default_Component_Value
;
6816 Typ
:= Component_Type
(E
);
6817 Exp
:= Default_Aspect_Component_Value
(E
);
6820 Analyze_And_Resolve
(Exp
, Typ
);
6822 if Etype
(Exp
) /= Any_Type
then
6823 if not Is_OK_Static_Expression
(Exp
) then
6824 Error_Msg_Name_1
:= Nam
;
6825 Flag_Non_Static_Expr
6826 ("aspect% requires static expression", Exp
);
6832 -- End of freeze processing for type entities
6835 -- Here is where we logically freeze the current entity. If it has a
6836 -- freeze node, then this is the point at which the freeze node is
6837 -- linked into the result list.
6839 if Has_Delayed_Freeze
(E
) then
6841 -- If a freeze node is already allocated, use it, otherwise allocate
6842 -- a new one. The preallocation happens in the case of anonymous base
6843 -- types, where we preallocate so that we can set First_Subtype_Link.
6844 -- Note that we reset the Sloc to the current freeze location.
6846 if Present
(Freeze_Node
(E
)) then
6847 F_Node
:= Freeze_Node
(E
);
6848 Set_Sloc
(F_Node
, Loc
);
6851 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
6852 Set_Freeze_Node
(E
, F_Node
);
6853 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
6854 Set_TSS_Elist
(F_Node
, No_Elist
);
6855 Set_Actions
(F_Node
, No_List
);
6858 Set_Entity
(F_Node
, E
);
6859 Add_To_Result
(F_Node
);
6861 -- A final pass over record types with discriminants. If the type
6862 -- has an incomplete declaration, there may be constrained access
6863 -- subtypes declared elsewhere, which do not depend on the discrimi-
6864 -- nants of the type, and which are used as component types (i.e.
6865 -- the full view is a recursive type). The designated types of these
6866 -- subtypes can only be elaborated after the type itself, and they
6867 -- need an itype reference.
6869 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
6876 Comp
:= First_Component
(E
);
6877 while Present
(Comp
) loop
6878 Typ
:= Etype
(Comp
);
6880 if Ekind
(Comp
) = E_Component
6881 and then Is_Access_Type
(Typ
)
6882 and then Scope
(Typ
) /= E
6883 and then Base_Type
(Designated_Type
(Typ
)) = E
6884 and then Is_Itype
(Designated_Type
(Typ
))
6886 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
6887 Set_Itype
(IR
, Designated_Type
(Typ
));
6888 Append
(IR
, Result
);
6891 Next_Component
(Comp
);
6897 -- When a type is frozen, the first subtype of the type is frozen as
6898 -- well (RM 13.14(15)). This has to be done after freezing the type,
6899 -- since obviously the first subtype depends on its own base type.
6902 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
6904 -- If we just froze a tagged non-class wide record, then freeze the
6905 -- corresponding class-wide type. This must be done after the tagged
6906 -- type itself is frozen, because the class-wide type refers to the
6907 -- tagged type which generates the class.
6909 if Is_Tagged_Type
(E
)
6910 and then not Is_Class_Wide_Type
(E
)
6911 and then Present
(Class_Wide_Type
(E
))
6913 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
6917 Check_Debug_Info_Needed
(E
);
6919 -- If subprogram has address clause then reset Is_Public flag, since we
6920 -- do not want the backend to generate external references.
6922 if Is_Subprogram
(E
)
6923 and then Present
(Address_Clause
(E
))
6924 and then not Is_Library_Level_Entity
(E
)
6926 Set_Is_Public
(E
, False);
6929 -- The Ghost mode of the enclosing context is ignored, while the
6930 -- entity being frozen is living. Insert the freezing action prior
6931 -- to the start of the enclosing ignored Ghost region. As a result
6932 -- the freezeing action will be preserved when the ignored Ghost
6933 -- context is eliminated. The insertion must take place even when
6934 -- the context is a spec expression, otherwise "Handling of Default
6935 -- and Per-Object Expressions" will suppress the insertion, and the
6936 -- freeze node will be dropped on the floor.
6938 if Saved_GM
= Ignore
6939 and then Ghost_Mode
/= Ignore
6940 and then Present
(Ignored_Ghost_Region
)
6943 (Assoc_Node
=> Ignored_Ghost_Region
,
6944 Ins_Actions
=> Result
,
6945 Spec_Expr_OK
=> True);
6951 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
6956 -----------------------------
6957 -- Freeze_Enumeration_Type --
6958 -----------------------------
6960 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
6962 -- By default, if no size clause is present, an enumeration type with
6963 -- Convention C is assumed to interface to a C enum and has integer
6964 -- size, except for a boolean type because it is assumed to interface
6965 -- to _Bool introduced in C99. This applies to types. For subtypes,
6966 -- verify that its base type has no size clause either. Treat other
6967 -- foreign conventions in the same way, and also make sure alignment
6970 if Has_Foreign_Convention
(Typ
)
6971 and then not Is_Boolean_Type
(Typ
)
6972 and then not Has_Size_Clause
(Typ
)
6973 and then not Has_Size_Clause
(Base_Type
(Typ
))
6974 and then Esize
(Typ
) < Standard_Integer_Size
6976 -- Don't do this if Short_Enums on target
6978 and then not Target_Short_Enums
6980 Init_Esize
(Typ
, Standard_Integer_Size
);
6981 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
6983 -- Normal Ada case or size clause present or not Long_C_Enums on target
6986 -- If the enumeration type interfaces to C, and it has a size clause
6987 -- that specifies less than int size, it warrants a warning. The
6988 -- user may intend the C type to be an enum or a char, so this is
6989 -- not by itself an error that the Ada compiler can detect, but it
6990 -- it is a worth a heads-up. For Boolean and Character types we
6991 -- assume that the programmer has the proper C type in mind.
6993 if Convention
(Typ
) = Convention_C
6994 and then Has_Size_Clause
(Typ
)
6995 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
6996 and then not Is_Boolean_Type
(Typ
)
6997 and then not Is_Character_Type
(Typ
)
6999 -- Don't do this if Short_Enums on target
7001 and then not Target_Short_Enums
7004 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
7007 Adjust_Esize_For_Alignment
(Typ
);
7009 end Freeze_Enumeration_Type
;
7011 -----------------------
7012 -- Freeze_Expression --
7013 -----------------------
7015 procedure Freeze_Expression
(N
: Node_Id
) is
7017 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
7018 -- If the expression is an array aggregate, the type of the component
7019 -- expressions is also frozen. If the component type is an access type
7020 -- and the expressions include allocators, the designed type is frozen
7023 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
7024 -- Given an N_Handled_Sequence_Of_Statements node, determines whether it
7025 -- is the statement sequence of an expander-generated subprogram: body
7026 -- created for an expression function, for a predicate function, an init
7027 -- proc, a stream subprogram, or a renaming as body. If so, this is not
7028 -- a freezing context and the entity will be frozen at a later point.
7030 function Has_Decl_In_List
7033 L
: List_Id
) return Boolean;
7034 -- Determines whether an entity E referenced in node N is declared in
7037 -----------------------------------------
7038 -- Find_Aggregate_Component_Desig_Type --
7039 -----------------------------------------
7041 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
7046 if Present
(Expressions
(N
)) then
7047 Exp
:= First
(Expressions
(N
));
7048 while Present
(Exp
) loop
7049 if Nkind
(Exp
) = N_Allocator
then
7050 return Designated_Type
(Component_Type
(Etype
(N
)));
7057 if Present
(Component_Associations
(N
)) then
7058 Assoc
:= First
(Component_Associations
(N
));
7059 while Present
(Assoc
) loop
7060 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
7061 return Designated_Type
(Component_Type
(Etype
(N
)));
7069 end Find_Aggregate_Component_Desig_Type
;
7071 ----------------------
7072 -- In_Expanded_Body --
7073 ----------------------
7075 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
7076 P
: constant Node_Id
:= Parent
(N
);
7080 if Nkind
(P
) /= N_Subprogram_Body
then
7083 -- AI12-0157: An expression function that is a completion is a freeze
7084 -- point. If the body is the result of expansion, it is not.
7086 elsif Was_Expression_Function
(P
) then
7087 return not Comes_From_Source
(P
);
7089 -- This is the body of a generated predicate function
7091 elsif Present
(Corresponding_Spec
(P
))
7092 and then Is_Predicate_Function
(Corresponding_Spec
(P
))
7097 Id
:= Defining_Unit_Name
(Specification
(P
));
7099 -- The following are expander-created bodies, or bodies that
7100 -- are not freeze points.
7102 if Nkind
(Id
) = N_Defining_Identifier
7103 and then (Is_Init_Proc
(Id
)
7104 or else Is_TSS
(Id
, TSS_Stream_Input
)
7105 or else Is_TSS
(Id
, TSS_Stream_Output
)
7106 or else Is_TSS
(Id
, TSS_Stream_Read
)
7107 or else Is_TSS
(Id
, TSS_Stream_Write
)
7108 or else Nkind
(Original_Node
(P
)) =
7109 N_Subprogram_Renaming_Declaration
)
7116 end In_Expanded_Body
;
7118 ----------------------
7119 -- Has_Decl_In_List --
7120 ----------------------
7122 function Has_Decl_In_List
7125 L
: List_Id
) return Boolean
7127 Decl_Node
: Node_Id
;
7130 -- If E is an itype, pretend that it is declared in N
7132 if Is_Itype
(E
) then
7135 Decl_Node
:= Declaration_Node
(E
);
7138 return Is_List_Member
(Decl_Node
)
7139 and then List_Containing
(Decl_Node
) = L
;
7140 end Has_Decl_In_List
;
7144 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
7146 Desig_Typ
: Entity_Id
;
7152 Allocator_Typ
: Entity_Id
:= Empty
;
7154 Freeze_Outside
: Boolean := False;
7155 -- This flag is set true if the entity must be frozen outside the
7156 -- current subprogram. This happens in the case of expander generated
7157 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
7158 -- not freeze all entities like other bodies, but which nevertheless
7159 -- may reference entities that have to be frozen before the body and
7160 -- obviously cannot be frozen inside the body.
7162 Freeze_Outside_Subp
: Entity_Id
:= Empty
;
7163 -- This entity is set if we are inside a subprogram body and the frozen
7164 -- entity is defined in the enclosing scope of this subprogram. In such
7165 -- case we must skip the subprogram body when climbing the parents chain
7166 -- to locate the correct placement for the freezing node.
7168 -- Start of processing for Freeze_Expression
7171 -- Immediate return if freezing is inhibited. This flag is set by the
7172 -- analyzer to stop freezing on generated expressions that would cause
7173 -- freezing if they were in the source program, but which are not
7174 -- supposed to freeze, since they are created.
7176 if Must_Not_Freeze
(N
) then
7180 -- If expression is non-static, then it does not freeze in a default
7181 -- expression, see section "Handling of Default Expressions" in the
7182 -- spec of package Sem for further details. Note that we have to make
7183 -- sure that we actually have a real expression (if we have a subtype
7184 -- indication, we can't test Is_OK_Static_Expression). However, we
7185 -- exclude the case of the prefix of an attribute of a static scalar
7186 -- subtype from this early return, because static subtype attributes
7187 -- should always cause freezing, even in default expressions, but
7188 -- the attribute may not have been marked as static yet (because in
7189 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
7190 -- Freeze_Expression on the prefix).
7193 and then Nkind
(N
) in N_Subexpr
7194 and then not Is_OK_Static_Expression
(N
)
7195 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
7196 or else not (Is_Entity_Name
(N
)
7197 and then Is_Type
(Entity
(N
))
7198 and then Is_OK_Static_Subtype
(Entity
(N
))))
7203 -- Freeze type of expression if not frozen already
7207 if Nkind
(N
) in N_Has_Etype
then
7208 if not Is_Frozen
(Etype
(N
)) then
7211 -- Base type may be an derived numeric type that is frozen at the
7212 -- point of declaration, but first_subtype is still unfrozen.
7214 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
7215 Typ
:= First_Subtype
(Etype
(N
));
7219 -- For entity name, freeze entity if not frozen already. A special
7220 -- exception occurs for an identifier that did not come from source.
7221 -- We don't let such identifiers freeze a non-internal entity, i.e.
7222 -- an entity that did come from source, since such an identifier was
7223 -- generated by the expander, and cannot have any semantic effect on
7224 -- the freezing semantics. For example, this stops the parameter of
7225 -- an initialization procedure from freezing the variable.
7227 if Is_Entity_Name
(N
)
7228 and then not Is_Frozen
(Entity
(N
))
7229 and then (Nkind
(N
) /= N_Identifier
7230 or else Comes_From_Source
(N
)
7231 or else not Comes_From_Source
(Entity
(N
)))
7235 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
7236 Check_Expression_Function
(N
, Nam
);
7243 -- For an allocator freeze designated type if not frozen already
7245 -- For an aggregate whose component type is an access type, freeze the
7246 -- designated type now, so that its freeze does not appear within the
7247 -- loop that might be created in the expansion of the aggregate. If the
7248 -- designated type is a private type without full view, the expression
7249 -- cannot contain an allocator, so the type is not frozen.
7251 -- For a function, we freeze the entity when the subprogram declaration
7252 -- is frozen, but a function call may appear in an initialization proc.
7253 -- before the declaration is frozen. We need to generate the extra
7254 -- formals, if any, to ensure that the expansion of the call includes
7255 -- the proper actuals. This only applies to Ada subprograms, not to
7262 Desig_Typ
:= Designated_Type
(Etype
(N
));
7264 if Nkind
(Expression
(N
)) = N_Qualified_Expression
then
7265 Allocator_Typ
:= Entity
(Subtype_Mark
(Expression
(N
)));
7269 if Is_Array_Type
(Etype
(N
))
7270 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
7272 -- Check whether aggregate includes allocators
7274 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
7277 when N_Indexed_Component
7278 | N_Selected_Component
7281 if Is_Access_Type
(Etype
(Prefix
(N
))) then
7282 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
7285 when N_Identifier
=>
7287 and then Ekind
(Nam
) = E_Function
7288 and then Nkind
(Parent
(N
)) = N_Function_Call
7289 and then Convention
(Nam
) = Convention_Ada
7291 Create_Extra_Formals
(Nam
);
7298 if Desig_Typ
/= Empty
7299 and then (Is_Frozen
(Desig_Typ
)
7300 or else (not Is_Fully_Defined
(Desig_Typ
)))
7305 -- All done if nothing needs freezing
7309 and then No
(Desig_Typ
)
7310 and then No
(Allocator_Typ
)
7315 -- Check if we are inside a subprogram body and the frozen entity is
7316 -- defined in the enclosing scope of this subprogram. In such case we
7317 -- must skip the subprogram when climbing the parents chain to locate
7318 -- the correct placement for the freezing node.
7320 -- This is not needed for default expressions and other spec expressions
7321 -- in generic units since the Move_Freeze_Nodes mechanism (sem_ch12.adb)
7322 -- takes care of placing them at the proper place, after the generic
7326 and then Scope
(Nam
) /= Current_Scope
7327 and then not (In_Spec_Exp
and then Inside_A_Generic
)
7330 S
: Entity_Id
:= Current_Scope
;
7334 and then In_Same_Source_Unit
(Nam
, S
)
7336 if Scope
(S
) = Scope
(Nam
) then
7337 if Is_Subprogram
(S
) and then Has_Completion
(S
) then
7338 Freeze_Outside_Subp
:= S
;
7349 -- Examine the enclosing context by climbing the parent chain
7351 -- If we identified that we must freeze the entity outside of a given
7352 -- subprogram then we just climb up to that subprogram checking if some
7353 -- enclosing node is marked as Must_Not_Freeze (since in such case we
7354 -- must not freeze yet this entity).
7358 if Present
(Freeze_Outside_Subp
) then
7360 -- Do not freeze the current expression if another expression in
7361 -- the chain of parents must not be frozen.
7363 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
7367 Parent_P
:= Parent
(P
);
7369 -- If we don't have a parent, then we are not in a well-formed
7370 -- tree. This is an unusual case, but there are some legitimate
7371 -- situations in which this occurs, notably when the expressions
7372 -- in the range of a type declaration are resolved. We simply
7373 -- ignore the freeze request in this case.
7375 if No
(Parent_P
) then
7379 -- If the parent is a subprogram body, the candidate insertion
7380 -- point is just ahead of it.
7382 if Nkind
(Parent_P
) = N_Subprogram_Body
7383 and then Unique_Defining_Entity
(Parent_P
) =
7393 -- Otherwise the traversal serves two purposes - to detect scenarios
7394 -- where freezeing is not needed and to find the proper insertion point
7395 -- for the freeze nodes. Although somewhat similar to Insert_Actions,
7396 -- this traversal is freezing semantics-sensitive. Inserting freeze
7397 -- nodes blindly in the tree may result in types being frozen too early.
7401 -- Do not freeze the current expression if another expression in
7402 -- the chain of parents must not be frozen.
7404 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
7408 Parent_P
:= Parent
(P
);
7410 -- If we don't have a parent, then we are not in a well-formed
7411 -- tree. This is an unusual case, but there are some legitimate
7412 -- situations in which this occurs, notably when the expressions
7413 -- in the range of a type declaration are resolved. We simply
7414 -- ignore the freeze request in this case. Is this right ???
7416 if No
(Parent_P
) then
7420 -- See if we have got to an appropriate point in the tree
7422 case Nkind
(Parent_P
) is
7424 -- A special test for the exception of (RM 13.14(8)) for the
7425 -- case of per-object expressions (RM 3.8(18)) occurring in
7426 -- component definition or a discrete subtype definition. Note
7427 -- that we test for a component declaration which includes both
7428 -- cases we are interested in, and furthermore the tree does
7429 -- not have explicit nodes for either of these two constructs.
7431 when N_Component_Declaration
=>
7433 -- The case we want to test for here is an identifier that
7434 -- is a per-object expression, this is either a discriminant
7435 -- that appears in a context other than the component
7436 -- declaration or it is a reference to the type of the
7437 -- enclosing construct.
7439 -- For either of these cases, we skip the freezing
7441 if not In_Spec_Expression
7442 and then Nkind
(N
) = N_Identifier
7443 and then (Present
(Entity
(N
)))
7445 -- We recognize the discriminant case by just looking for
7446 -- a reference to a discriminant. It can only be one for
7447 -- the enclosing construct. Skip freezing in this case.
7449 if Ekind
(Entity
(N
)) = E_Discriminant
then
7452 -- For the case of a reference to the enclosing record,
7453 -- (or task or protected type), we look for a type that
7454 -- matches the current scope.
7456 elsif Entity
(N
) = Current_Scope
then
7461 -- If we have an enumeration literal that appears as the choice
7462 -- in the aggregate of an enumeration representation clause,
7463 -- then freezing does not occur (RM 13.14(10)).
7465 when N_Enumeration_Representation_Clause
=>
7467 -- The case we are looking for is an enumeration literal
7469 if Nkind
(N
) in N_Identifier | N_Character_Literal
7470 and then Is_Enumeration_Type
(Etype
(N
))
7472 -- If enumeration literal appears directly as the choice,
7473 -- do not freeze (this is the normal non-overloaded case)
7475 if Nkind
(Parent
(N
)) = N_Component_Association
7476 and then First
(Choices
(Parent
(N
))) = N
7480 -- If enumeration literal appears as the name of function
7481 -- which is the choice, then also do not freeze. This
7482 -- happens in the overloaded literal case, where the
7483 -- enumeration literal is temporarily changed to a
7484 -- function call for overloading analysis purposes.
7486 elsif Nkind
(Parent
(N
)) = N_Function_Call
7487 and then Nkind
(Parent
(Parent
(N
))) =
7488 N_Component_Association
7489 and then First
(Choices
(Parent
(Parent
(N
)))) =
7496 -- Normally if the parent is a handled sequence of statements,
7497 -- then the current node must be a statement, and that is an
7498 -- appropriate place to insert a freeze node.
7500 when N_Handled_Sequence_Of_Statements
=>
7502 -- An exception occurs when the sequence of statements is
7503 -- for an expander generated body that did not do the usual
7504 -- freeze all operation. In this case we usually want to
7505 -- freeze outside this body, not inside it, and we skip
7506 -- past the subprogram body that we are inside.
7508 if In_Expanded_Body
(Parent_P
) then
7510 Subp_Body
: constant Node_Id
:= Parent
(Parent_P
);
7511 Spec_Id
: Entity_Id
;
7514 -- Freeze the entity only when it is declared inside
7515 -- the body of the expander generated procedure. This
7516 -- case is recognized by the subprogram scope of the
7517 -- entity or its type, which is either the spec of an
7518 -- enclosing body, or (in the case of init_procs for
7519 -- which there is no separate spec) the current scope.
7521 if Nkind
(Subp_Body
) = N_Subprogram_Body
then
7526 Spec_Id
:= Corresponding_Spec
(Subp_Body
);
7528 if Present
(Typ
) then
7530 elsif Present
(Nam
) then
7533 S
:= Standard_Standard
;
7536 while S
/= Standard_Standard
7537 and then not Is_Subprogram
(S
)
7546 and then Scope
(Typ
) = Current_Scope
7548 Defining_Entity
(Subp_Body
) = Current_Scope
7555 -- If the entity is not frozen by an expression
7556 -- function that is not a completion, continue
7557 -- climbing the tree.
7559 if Nkind
(Subp_Body
) = N_Subprogram_Body
7560 and then Was_Expression_Function
(Subp_Body
)
7564 -- Freeze outside the body
7567 Parent_P
:= Parent
(Parent_P
);
7568 Freeze_Outside
:= True;
7572 -- Here if normal case where we are in handled statement
7573 -- sequence and want to do the insertion right there.
7579 -- If parent is a body or a spec or a block, then the current
7580 -- node is a statement or declaration and we can insert the
7581 -- freeze node before it.
7583 when N_Block_Statement
7586 | N_Package_Specification
7593 -- The expander is allowed to define types in any statements
7594 -- list, so any of the following parent nodes also mark a
7595 -- freezing point if the actual node is in a list of
7596 -- statements or declarations.
7598 when N_Abortable_Part
7599 | N_Accept_Alternative
7600 | N_Case_Statement_Alternative
7601 | N_Compilation_Unit_Aux
7602 | N_Conditional_Entry_Call
7603 | N_Delay_Alternative
7605 | N_Entry_Call_Alternative
7606 | N_Exception_Handler
7607 | N_Extended_Return_Statement
7610 | N_Selective_Accept
7611 | N_Triggering_Alternative
7613 exit when Is_List_Member
(P
);
7615 -- The freeze nodes produced by an expression coming from the
7616 -- Actions list of an N_Expression_With_Actions, short-circuit
7617 -- expression or N_Case_Expression_Alternative node must remain
7618 -- within the Actions list if they freeze an entity declared in
7619 -- this list, as inserting the freeze nodes further up the tree
7620 -- may lead to use before declaration issues for the entity.
7622 when N_Case_Expression_Alternative
7623 | N_Expression_With_Actions
7626 exit when (Present
(Nam
)
7628 Has_Decl_In_List
(Nam
, P
, Actions
(Parent_P
)))
7629 or else (Present
(Typ
)
7631 Has_Decl_In_List
(Typ
, P
, Actions
(Parent_P
)));
7633 -- Likewise for an N_If_Expression and its two Actions list
7635 when N_If_Expression
=>
7637 L1
: constant List_Id
:= Then_Actions
(Parent_P
);
7638 L2
: constant List_Id
:= Else_Actions
(Parent_P
);
7641 exit when (Present
(Nam
)
7643 Has_Decl_In_List
(Nam
, P
, L1
))
7644 or else (Present
(Typ
)
7646 Has_Decl_In_List
(Typ
, P
, L1
))
7647 or else (Present
(Nam
)
7649 Has_Decl_In_List
(Nam
, P
, L2
))
7650 or else (Present
(Typ
)
7652 Has_Decl_In_List
(Typ
, P
, L2
));
7655 -- N_Loop_Statement is a special case: a type that appears in
7656 -- the source can never be frozen in a loop (this occurs only
7657 -- because of a loop expanded by the expander), so we keep on
7658 -- going. Otherwise we terminate the search. Same is true of
7659 -- any entity which comes from source (if it has a predefined
7660 -- type, this type does not appear to come from source, but the
7661 -- entity should not be frozen here).
7663 when N_Loop_Statement
=>
7664 exit when not Comes_From_Source
(Etype
(N
))
7665 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
7667 -- For all other cases, keep looking at parents
7673 -- We fall through the case if we did not yet find the proper
7674 -- place in the free for inserting the freeze node, so climb.
7680 -- If the expression appears in a record or an initialization procedure,
7681 -- the freeze nodes are collected and attached to the current scope, to
7682 -- be inserted and analyzed on exit from the scope, to insure that
7683 -- generated entities appear in the correct scope. If the expression is
7684 -- a default for a discriminant specification, the scope is still void.
7685 -- The expression can also appear in the discriminant part of a private
7686 -- or concurrent type.
7688 -- If the expression appears in a constrained subcomponent of an
7689 -- enclosing record declaration, the freeze nodes must be attached to
7690 -- the outer record type so they can eventually be placed in the
7691 -- enclosing declaration list.
7693 -- The other case requiring this special handling is if we are in a
7694 -- default expression, since in that case we are about to freeze a
7695 -- static type, and the freeze scope needs to be the outer scope, not
7696 -- the scope of the subprogram with the default parameter.
7698 -- For default expressions and other spec expressions in generic units,
7699 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
7700 -- placing them at the proper place, after the generic unit.
7702 if (In_Spec_Exp
and not Inside_A_Generic
)
7703 or else Freeze_Outside
7704 or else (Is_Type
(Current_Scope
)
7705 and then (not Is_Concurrent_Type
(Current_Scope
)
7706 or else not Has_Completion
(Current_Scope
)))
7707 or else Ekind
(Current_Scope
) = E_Void
7710 Freeze_Nodes
: List_Id
:= No_List
;
7711 Pos
: Int
:= Scope_Stack
.Last
;
7714 if Present
(Desig_Typ
) then
7715 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
7718 if Present
(Typ
) then
7719 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
7722 if Present
(Nam
) then
7723 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
7726 -- The current scope may be that of a constrained component of
7727 -- an enclosing record declaration, or of a loop of an enclosing
7728 -- quantified expression, which is above the current scope in the
7729 -- scope stack. Indeed in the context of a quantified expression,
7730 -- a scope is created and pushed above the current scope in order
7731 -- to emulate the loop-like behavior of the quantified expression.
7732 -- If the expression is within a top-level pragma, as for a pre-
7733 -- condition on a library-level subprogram, nothing to do.
7735 if not Is_Compilation_Unit
(Current_Scope
)
7736 and then (Is_Record_Type
(Scope
(Current_Scope
))
7737 or else Nkind
(Parent
(Current_Scope
)) =
7738 N_Quantified_Expression
)
7743 if Is_Non_Empty_List
(Freeze_Nodes
) then
7745 -- When the current scope is transient, insert the freeze nodes
7746 -- prior to the expression that produced them. Transient scopes
7747 -- may create additional declarations when finalizing objects
7748 -- or managing the secondary stack. Inserting the freeze nodes
7749 -- of those constructs prior to the scope would result in a
7750 -- freeze-before-declaration, therefore the freeze node must
7751 -- remain interleaved with their constructs.
7753 if Scope_Is_Transient
then
7754 Insert_Actions
(N
, Freeze_Nodes
);
7756 elsif No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
7757 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
7760 Append_List
(Freeze_Nodes
,
7761 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
7769 -- Now we have the right place to do the freezing. First, a special
7770 -- adjustment, if we are in spec-expression analysis mode, these freeze
7771 -- actions must not be thrown away (normally all inserted actions are
7772 -- thrown away in this mode. However, the freeze actions are from static
7773 -- expressions and one of the important reasons we are doing this
7774 -- special analysis is to get these freeze actions. Therefore we turn
7775 -- off the In_Spec_Expression mode to propagate these freeze actions.
7776 -- This also means they get properly analyzed and expanded.
7778 In_Spec_Expression
:= False;
7780 -- Freeze the subtype mark before a qualified expression on an
7781 -- allocator as per AARM 13.14(4.a). This is needed in particular to
7782 -- generate predicate functions.
7784 if Present
(Allocator_Typ
) then
7785 Freeze_Before
(P
, Allocator_Typ
);
7788 -- Freeze the designated type of an allocator (RM 13.14(13))
7790 if Present
(Desig_Typ
) then
7791 Freeze_Before
(P
, Desig_Typ
);
7794 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
7795 -- the enumeration representation clause exception in the loop above.
7797 if Present
(Typ
) then
7798 Freeze_Before
(P
, Typ
);
7801 -- Freeze name if one is present (RM 13.14(11))
7803 if Present
(Nam
) then
7804 Freeze_Before
(P
, Nam
);
7807 -- Restore In_Spec_Expression flag
7809 In_Spec_Expression
:= In_Spec_Exp
;
7810 end Freeze_Expression
;
7812 -----------------------
7813 -- Freeze_Expr_Types --
7814 -----------------------
7816 procedure Freeze_Expr_Types
7817 (Def_Id
: Entity_Id
;
7822 function Cloned_Expression
return Node_Id
;
7823 -- Build a duplicate of the expression of the return statement that has
7824 -- no defining entities shared with the original expression.
7826 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
7827 -- Freeze all types referenced in the subtree rooted at Node
7829 -----------------------
7830 -- Cloned_Expression --
7831 -----------------------
7833 function Cloned_Expression
return Node_Id
is
7834 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
7835 -- Tree traversal routine that clones the defining identifier of
7836 -- iterator and loop parameter specification nodes.
7842 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
7845 N_Iterator_Specification | N_Loop_Parameter_Specification
7847 Set_Defining_Identifier
7848 (Node
, New_Copy
(Defining_Identifier
(Node
)));
7854 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
7858 Dup_Expr
: constant Node_Id
:= New_Copy_Tree
(Expr
);
7860 -- Start of processing for Cloned_Expression
7863 -- We must duplicate the expression with semantic information to
7864 -- inherit the decoration of global entities in generic instances.
7865 -- Set the parent of the new node to be the parent of the original
7866 -- to get the proper context, which is needed for complete error
7867 -- reporting and for semantic analysis.
7869 Set_Parent
(Dup_Expr
, Parent
(Expr
));
7871 -- Replace the defining identifier of iterators and loop param
7872 -- specifications by a clone to ensure that the cloned expression
7873 -- and the original expression don't have shared identifiers;
7874 -- otherwise, as part of the preanalysis of the expression, these
7875 -- shared identifiers may be left decorated with itypes which
7876 -- will not be available in the tree passed to the backend.
7878 Clone_Def_Ids
(Dup_Expr
);
7881 end Cloned_Expression
;
7883 ----------------------
7884 -- Freeze_Type_Refs --
7885 ----------------------
7887 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
7888 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
);
7889 -- Check that Typ is fully declared and freeze it if so
7891 ---------------------------
7892 -- Check_And_Freeze_Type --
7893 ---------------------------
7895 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
) is
7897 -- Skip Itypes created by the preanalysis, and itypes whose
7898 -- scope is another type (i.e. component subtypes that depend
7899 -- on a discriminant),
7902 and then (Scope_Within_Or_Same
(Scope
(Typ
), Def_Id
)
7903 or else Is_Type
(Scope
(Typ
)))
7908 -- This provides a better error message than generating primitives
7909 -- whose compilation fails much later. Refine the error message if
7912 Check_Fully_Declared
(Typ
, Node
);
7914 if Error_Posted
(Node
) then
7915 if Has_Private_Component
(Typ
)
7916 and then not Is_Private_Type
(Typ
)
7918 Error_Msg_NE
("\type& has private component", Node
, Typ
);
7922 Freeze_Before
(N
, Typ
);
7924 end Check_And_Freeze_Type
;
7926 -- Start of processing for Freeze_Type_Refs
7929 -- Check that a type referenced by an entity can be frozen
7931 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
7932 -- The entity itself may be a type, as in a membership test
7933 -- or an attribute reference. Freezing its own type would be
7934 -- incomplete if the entity is derived or an extension.
7936 if Is_Type
(Entity
(Node
)) then
7937 Check_And_Freeze_Type
(Entity
(Node
));
7940 Check_And_Freeze_Type
(Etype
(Entity
(Node
)));
7943 -- Check that the enclosing record type can be frozen
7945 if Ekind
(Entity
(Node
)) in E_Component | E_Discriminant
then
7946 Check_And_Freeze_Type
(Scope
(Entity
(Node
)));
7949 -- Freezing an access type does not freeze the designated type, but
7950 -- freezing conversions between access to interfaces requires that
7951 -- the interface types themselves be frozen, so that dispatch table
7952 -- entities are properly created.
7954 -- Unclear whether a more general rule is needed ???
7956 elsif Nkind
(Node
) = N_Type_Conversion
7957 and then Is_Access_Type
(Etype
(Node
))
7958 and then Is_Interface
(Designated_Type
(Etype
(Node
)))
7960 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
7963 -- An implicit dereference freezes the designated type. In the case
7964 -- of a dispatching call whose controlling argument is an access
7965 -- type, the dereference is not made explicit, so we must check for
7966 -- such a call and freeze the designated type.
7968 if Nkind
(Node
) in N_Has_Etype
7969 and then Present
(Etype
(Node
))
7970 and then Is_Access_Type
(Etype
(Node
))
7972 if Nkind
(Parent
(Node
)) = N_Function_Call
7973 and then Node
= Controlling_Argument
(Parent
(Node
))
7975 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
7977 -- An explicit dereference freezes the designated type as well,
7978 -- even though that type is not attached to an entity in the
7981 elsif Nkind
(Parent
(Node
)) = N_Explicit_Dereference
then
7982 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
7985 -- An iterator specification freezes the iterator type, even though
7986 -- that type is not attached to an entity in the construct.
7988 elsif Nkind
(Node
) in N_Has_Etype
7989 and then Nkind
(Parent
(Node
)) = N_Iterator_Specification
7990 and then Node
= Name
(Parent
(Node
))
7993 Iter
: constant Node_Id
:=
7994 Find_Value_Of_Aspect
(Etype
(Node
), Aspect_Default_Iterator
);
7997 if Present
(Iter
) then
7998 Check_And_Freeze_Type
(Etype
(Iter
));
8003 -- No point in posting several errors on the same expression
8005 if Serious_Errors_Detected
> 0 then
8010 end Freeze_Type_Refs
;
8012 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
8016 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Def_Id
);
8017 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Def_Id
);
8018 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
8020 -- Start of processing for Freeze_Expr_Types
8023 -- Preanalyze a duplicate of the expression to have available the
8024 -- minimum decoration needed to locate referenced unfrozen types
8025 -- without adding any decoration to the function expression.
8027 -- This routine is also applied to expressions in the contract for
8028 -- the subprogram. If that happens when expanding the code for
8029 -- pre/postconditions during expansion of the subprogram body, the
8030 -- subprogram is already installed.
8032 if Def_Id
/= Current_Scope
then
8033 Push_Scope
(Def_Id
);
8034 Install_Formals
(Def_Id
);
8036 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
8039 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
8042 -- Restore certain attributes of Def_Id since the preanalysis may
8043 -- have introduced itypes to this scope, thus modifying attributes
8044 -- First_Entity and Last_Entity.
8046 Set_First_Entity
(Def_Id
, Saved_First_Entity
);
8047 Set_Last_Entity
(Def_Id
, Saved_Last_Entity
);
8049 if Present
(Last_Entity
(Def_Id
)) then
8050 Set_Next_Entity
(Last_Entity
(Def_Id
), Empty
);
8053 -- Freeze all types referenced in the expression
8055 Freeze_References
(Dup_Expr
);
8056 end Freeze_Expr_Types
;
8058 -----------------------------
8059 -- Freeze_Fixed_Point_Type --
8060 -----------------------------
8062 -- Certain fixed-point types and subtypes, including implicit base types
8063 -- and declared first subtypes, have not yet set up a range. This is
8064 -- because the range cannot be set until the Small and Size values are
8065 -- known, and these are not known till the type is frozen.
8067 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
8068 -- whose bounds are unanalyzed real literals. This routine will recognize
8069 -- this case, and transform this range node into a properly typed range
8070 -- with properly analyzed and resolved values.
8072 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
8073 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
8074 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
8075 Hi
: constant Node_Id
:= High_Bound
(Rng
);
8076 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8077 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
8078 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
8079 BHi
: constant Node_Id
:= High_Bound
(Brng
);
8080 Par
: constant Entity_Id
:= First_Subtype
(Typ
);
8081 Small
: constant Ureal
:= Small_Value
(Typ
);
8088 -- Save original bounds (for shaving tests)
8091 -- Actual size chosen
8093 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
8094 -- Returns size of type with given bounds. Also leaves these
8095 -- bounds set as the current bounds of the Typ.
8097 function Larger
(A
, B
: Ureal
) return Boolean;
8098 -- Returns true if A > B with a margin of Typ'Small
8100 function Smaller
(A
, B
: Ureal
) return Boolean;
8101 -- Returns true if A < B with a margin of Typ'Small
8107 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
8109 Set_Realval
(Lo
, Lov
);
8110 Set_Realval
(Hi
, Hiv
);
8111 return Minimum_Size
(Typ
);
8118 function Larger
(A
, B
: Ureal
) return Boolean is
8120 return A
> B
and then A
- Small
> B
;
8127 function Smaller
(A
, B
: Ureal
) return Boolean is
8129 return A
< B
and then A
+ Small
< B
;
8132 -- Start of processing for Freeze_Fixed_Point_Type
8135 -- The type, or its first subtype if we are freezing the anonymous
8136 -- base, may have a delayed Small aspect. It must be analyzed now,
8137 -- so that all characteristics of the type (size, bounds) can be
8138 -- computed and validated in the call to Minimum_Size that follows.
8140 if Has_Delayed_Aspects
(First_Subtype
(Typ
)) then
8141 Analyze_Aspects_At_Freeze_Point
(First_Subtype
(Typ
));
8142 Set_Has_Delayed_Aspects
(First_Subtype
(Typ
), False);
8145 -- If Esize of a subtype has not previously been set, set it now
8147 if Unknown_Esize
(Typ
) then
8148 Atype
:= Ancestor_Subtype
(Typ
);
8150 if Present
(Atype
) then
8151 Set_Esize
(Typ
, Esize
(Atype
));
8153 Set_Esize
(Typ
, Esize
(Btyp
));
8157 -- The 'small attribute may have been specified with an aspect,
8158 -- in which case it is processed after a subtype declaration, so
8159 -- inherit now the specified value.
8162 and then Present
(Find_Aspect
(Par
, Aspect_Small
))
8164 Set_Small_Value
(Typ
, Small_Value
(Par
));
8167 -- Immediate return if the range is already analyzed. This means that
8168 -- the range is already set, and does not need to be computed by this
8171 if Analyzed
(Rng
) then
8175 -- Immediate return if either of the bounds raises Constraint_Error
8177 if Raises_Constraint_Error
(Lo
)
8178 or else Raises_Constraint_Error
(Hi
)
8183 Loval
:= Realval
(Lo
);
8184 Hival
:= Realval
(Hi
);
8189 -- Ordinary fixed-point case
8191 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
8193 -- For the ordinary fixed-point case, we are allowed to fudge the
8194 -- end-points up or down by small. Generally we prefer to fudge up,
8195 -- i.e. widen the bounds for non-model numbers so that the end points
8196 -- are included. However there are cases in which this cannot be
8197 -- done, and indeed cases in which we may need to narrow the bounds.
8198 -- The following circuit makes the decision.
8200 -- Note: our terminology here is that Incl_EP means that the bounds
8201 -- are widened by Small if necessary to include the end points, and
8202 -- Excl_EP means that the bounds are narrowed by Small to exclude the
8203 -- end-points if this reduces the size.
8205 -- Note that in the Incl case, all we care about is including the
8206 -- end-points. In the Excl case, we want to narrow the bounds as
8207 -- much as permitted by the RM, to give the smallest possible size.
8210 Loval_Incl_EP
: Ureal
;
8211 Hival_Incl_EP
: Ureal
;
8213 Loval_Excl_EP
: Ureal
;
8214 Hival_Excl_EP
: Ureal
;
8220 First_Subt
: Entity_Id
;
8225 -- First step. Base types are required to be symmetrical. Right
8226 -- now, the base type range is a copy of the first subtype range.
8227 -- This will be corrected before we are done, but right away we
8228 -- need to deal with the case where both bounds are non-negative.
8229 -- In this case, we set the low bound to the negative of the high
8230 -- bound, to make sure that the size is computed to include the
8231 -- required sign. Note that we do not need to worry about the
8232 -- case of both bounds negative, because the sign will be dealt
8233 -- with anyway. Furthermore we can't just go making such a bound
8234 -- symmetrical, since in a twos-complement system, there is an
8235 -- extra negative value which could not be accommodated on the
8239 and then not UR_Is_Negative
(Loval
)
8240 and then Hival
> Loval
8243 Set_Realval
(Lo
, Loval
);
8246 -- Compute the fudged bounds. If the bound is a model number, (or
8247 -- greater if given low bound, smaller if high bound) then we do
8248 -- nothing to include it, but we are allowed to backoff to the
8249 -- next adjacent model number when we exclude it. If it is not a
8250 -- model number then we straddle the two values with the model
8251 -- numbers on either side.
8253 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
8255 if UR_Ge
(Loval
, Model_Num
) then
8256 Loval_Incl_EP
:= Model_Num
;
8258 Loval_Incl_EP
:= Model_Num
- Small
;
8261 -- The low value excluding the end point is Small greater, but
8262 -- we do not do this exclusion if the low value is positive,
8263 -- since it can't help the size and could actually hurt by
8264 -- crossing the high bound.
8266 if UR_Is_Negative
(Loval_Incl_EP
) then
8267 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
8269 -- If the value went from negative to zero, then we have the
8270 -- case where Loval_Incl_EP is the model number just below
8271 -- zero, so we want to stick to the negative value for the
8272 -- base type to maintain the condition that the size will
8273 -- include signed values.
8276 and then UR_Is_Zero
(Loval_Excl_EP
)
8278 Loval_Excl_EP
:= Loval_Incl_EP
;
8282 Loval_Excl_EP
:= Loval_Incl_EP
;
8285 -- Similar processing for upper bound and high value
8287 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
8289 if UR_Le
(Hival
, Model_Num
) then
8290 Hival_Incl_EP
:= Model_Num
;
8292 Hival_Incl_EP
:= Model_Num
+ Small
;
8295 if UR_Is_Positive
(Hival_Incl_EP
) then
8296 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
8298 Hival_Excl_EP
:= Hival_Incl_EP
;
8301 -- One further adjustment is needed. In the case of subtypes, we
8302 -- cannot go outside the range of the base type, or we get
8303 -- peculiarities, and the base type range is already set. This
8304 -- only applies to the Incl values, since clearly the Excl values
8305 -- are already as restricted as they are allowed to be.
8308 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
8309 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
8312 -- Get size including and excluding end points
8314 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
8315 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
8317 -- No need to exclude end-points if it does not reduce size
8319 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
8320 Loval_Excl_EP
:= Loval_Incl_EP
;
8323 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
8324 Hival_Excl_EP
:= Hival_Incl_EP
;
8327 -- Now we set the actual size to be used. We want to use the
8328 -- bounds fudged up to include the end-points but only if this
8329 -- can be done without violating a specifically given size
8330 -- size clause or causing an unacceptable increase in size.
8332 -- Case of size clause given
8334 if Has_Size_Clause
(Typ
) then
8336 -- Use the inclusive size only if it is consistent with
8337 -- the explicitly specified size.
8339 if Size_Incl_EP
<= RM_Size
(Typ
) then
8340 Actual_Lo
:= Loval_Incl_EP
;
8341 Actual_Hi
:= Hival_Incl_EP
;
8342 Actual_Size
:= Size_Incl_EP
;
8344 -- If the inclusive size is too large, we try excluding
8345 -- the end-points (will be caught later if does not work).
8348 Actual_Lo
:= Loval_Excl_EP
;
8349 Actual_Hi
:= Hival_Excl_EP
;
8350 Actual_Size
:= Size_Excl_EP
;
8353 -- Case of size clause not given
8356 -- If we have a base type whose corresponding first subtype
8357 -- has an explicit size that is large enough to include our
8358 -- end-points, then do so. There is no point in working hard
8359 -- to get a base type whose size is smaller than the specified
8360 -- size of the first subtype.
8362 First_Subt
:= First_Subtype
(Typ
);
8364 if Has_Size_Clause
(First_Subt
)
8365 and then Size_Incl_EP
<= Esize
(First_Subt
)
8367 Actual_Size
:= Size_Incl_EP
;
8368 Actual_Lo
:= Loval_Incl_EP
;
8369 Actual_Hi
:= Hival_Incl_EP
;
8371 -- If excluding the end-points makes the size smaller and
8372 -- results in a size of 8,16,32,64, then we take the smaller
8373 -- size. For the 64 case, this is compulsory. For the other
8374 -- cases, it seems reasonable. We like to include end points
8375 -- if we can, but not at the expense of moving to the next
8376 -- natural boundary of size.
8378 elsif Size_Incl_EP
/= Size_Excl_EP
8379 and then Addressable
(Size_Excl_EP
)
8381 Actual_Size
:= Size_Excl_EP
;
8382 Actual_Lo
:= Loval_Excl_EP
;
8383 Actual_Hi
:= Hival_Excl_EP
;
8385 -- Otherwise we can definitely include the end points
8388 Actual_Size
:= Size_Incl_EP
;
8389 Actual_Lo
:= Loval_Incl_EP
;
8390 Actual_Hi
:= Hival_Incl_EP
;
8393 -- One pathological case: normally we never fudge a low bound
8394 -- down, since it would seem to increase the size (if it has
8395 -- any effect), but for ranges containing single value, or no
8396 -- values, the high bound can be small too large. Consider:
8398 -- type t is delta 2.0**(-14)
8399 -- range 131072.0 .. 0;
8401 -- That lower bound is *just* outside the range of 32 bits, and
8402 -- does need fudging down in this case. Note that the bounds
8403 -- will always have crossed here, since the high bound will be
8404 -- fudged down if necessary, as in the case of:
8406 -- type t is delta 2.0**(-14)
8407 -- range 131072.0 .. 131072.0;
8409 -- So we detect the situation by looking for crossed bounds,
8410 -- and if the bounds are crossed, and the low bound is greater
8411 -- than zero, we will always back it off by small, since this
8412 -- is completely harmless.
8414 if Actual_Lo
> Actual_Hi
then
8415 if UR_Is_Positive
(Actual_Lo
) then
8416 Actual_Lo
:= Loval_Incl_EP
- Small
;
8417 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
8419 -- And of course, we need to do exactly the same parallel
8420 -- fudge for flat ranges in the negative region.
8422 elsif UR_Is_Negative
(Actual_Hi
) then
8423 Actual_Hi
:= Hival_Incl_EP
+ Small
;
8424 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
8429 Set_Realval
(Lo
, Actual_Lo
);
8430 Set_Realval
(Hi
, Actual_Hi
);
8433 -- Enforce some limitations for ordinary fixed-point types. They come
8434 -- from an exact algorithm used to implement Text_IO.Fixed_IO and the
8435 -- Fore, Image and Value attributes. The requirement on the Small is
8436 -- to lie in the range 2**(-(Siz - 1)) .. 2**(Siz - 1) for a type of
8437 -- Siz bits (Siz=32,64,128) and the requirement on the bounds is to
8438 -- be smaller in magnitude than 10.0**N * 2**(Siz - 1), where N is
8439 -- given by the formula N = floor ((Siz - 1) * log 2 / log 10).
8441 -- If the bounds of a 32-bit type are too large, force 64-bit type
8443 if Actual_Size
<= 32
8444 and then Small
<= Ureal_2_31
8445 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_2_10_18
)
8446 or else Larger
(Expr_Value_R
(Hi
), Ureal_2_10_18
))
8451 -- If the bounds of a 64-bit type are too large, force 128-bit type
8453 if System_Max_Integer_Size
= 128
8454 and then Actual_Size
<= 64
8455 and then Small
<= Ureal_2_63
8456 and then (Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
)
8457 or else Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
))
8462 -- Give error messages for first subtypes and not base types, as the
8463 -- bounds of base types are always maximum for their size, see below.
8465 if System_Max_Integer_Size
< 128 and then Typ
/= Btyp
then
8467 -- See the 128-bit case below for the reason why we cannot test
8468 -- against the 2**(-63) .. 2**63 range. This quirk should have
8469 -- been kludged around as in the 128-bit case below, but it was
8470 -- not and we end up with a ludicrous range as a result???
8472 if Small
< Ureal_2_M_80
then
8473 Error_Msg_Name_1
:= Name_Small
;
8475 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", Typ
);
8477 elsif Small
> Ureal_2_80
then
8478 Error_Msg_Name_1
:= Name_Small
;
8480 ("`&''%` too large, maximum allowed is 2.0'*'*80", Typ
);
8483 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_9_10_36
) then
8484 Error_Msg_Name_1
:= Name_First
;
8486 ("`&''%` too small, minimum allowed is -9.0E+36", Typ
);
8489 if Larger
(Expr_Value_R
(Hi
), Ureal_9_10_36
) then
8490 Error_Msg_Name_1
:= Name_Last
;
8492 ("`&''%` too large, maximum allowed is 9.0E+36", Typ
);
8495 elsif System_Max_Integer_Size
= 128 and then Typ
/= Btyp
then
8497 -- ACATS c35902d tests a delta equal to 2**(-(Max_Mantissa + 1))
8498 -- but we cannot really support anything smaller than Fine_Delta
8499 -- because of the way we implement I/O for fixed point types???
8501 if Small
= Ureal_2_M_128
then
8504 elsif Small
< Ureal_2_M_127
then
8505 Error_Msg_Name_1
:= Name_Small
;
8507 ("`&''%` too small, minimum allowed is 2.0'*'*(-127)", Typ
);
8509 elsif Small
> Ureal_2_127
then
8510 Error_Msg_Name_1
:= Name_Small
;
8512 ("`&''%` too large, maximum allowed is 2.0'*'*127", Typ
);
8516 and then (Norm_Num
(Small
) > Uint_2
** 127
8517 or else Norm_Den
(Small
) > Uint_2
** 127)
8518 and then Small
/= Ureal_2_M_128
8520 Error_Msg_Name_1
:= Name_Small
;
8522 ("`&''%` not the ratio of two 128-bit integers", Typ
);
8525 if Smaller
(Expr_Value_R
(Lo
), Ureal_M_10_76
) then
8526 Error_Msg_Name_1
:= Name_First
;
8528 ("`&''%` too small, minimum allowed is -1.0E+76", Typ
);
8531 if Larger
(Expr_Value_R
(Hi
), Ureal_10_76
) then
8532 Error_Msg_Name_1
:= Name_Last
;
8534 ("`&''%` too large, maximum allowed is 1.0E+76", Typ
);
8538 -- For the decimal case, none of this fudging is required, since there
8539 -- are no end-point problems in the decimal case (the end-points are
8540 -- always included).
8543 Actual_Size
:= Fsize
(Loval
, Hival
);
8546 -- At this stage, the actual size has been calculated and the proper
8547 -- required bounds are stored in the low and high bounds.
8549 if Actual_Size
> System_Max_Integer_Size
then
8550 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
8551 Error_Msg_Uint_2
:= UI_From_Int
(System_Max_Integer_Size
);
8553 ("size required (^) for type& too large, maximum allowed is ^",
8555 Actual_Size
:= System_Max_Integer_Size
;
8558 -- Check size against explicit given size
8560 if Has_Size_Clause
(Typ
) then
8561 if Actual_Size
> RM_Size
(Typ
) then
8562 Error_Msg_Uint_1
:= RM_Size
(Typ
);
8563 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
8565 ("size given (^) for type& too small, minimum allowed is ^",
8566 Size_Clause
(Typ
), Typ
);
8569 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
8572 -- Increase size to next natural boundary if no size clause given
8575 if Actual_Size
<= 8 then
8577 elsif Actual_Size
<= 16 then
8579 elsif Actual_Size
<= 32 then
8581 elsif Actual_Size
<= 64 then
8587 Init_Esize
(Typ
, Actual_Size
);
8588 Adjust_Esize_For_Alignment
(Typ
);
8591 -- If we have a base type, then expand the bounds so that they extend to
8592 -- the full width of the allocated size in bits, to avoid junk range
8593 -- checks on intermediate computations.
8596 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
8597 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
8600 -- Final step is to reanalyze the bounds using the proper type
8601 -- and set the Corresponding_Integer_Value fields of the literals.
8603 Set_Etype
(Lo
, Empty
);
8604 Set_Analyzed
(Lo
, False);
8607 -- Resolve with universal fixed if the base type, and with the base
8608 -- type if we are freezing a subtype. Note we can't resolve the base
8609 -- type with itself, that would be a reference before definition.
8610 -- The resolution of the bounds of a subtype, if they are given by real
8611 -- literals, includes the setting of the Corresponding_Integer_Value,
8612 -- as for other literals of a fixed-point type.
8615 Resolve
(Lo
, Universal_Fixed
);
8616 Set_Corresponding_Integer_Value
8617 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
8622 -- Similar processing for high bound
8624 Set_Etype
(Hi
, Empty
);
8625 Set_Analyzed
(Hi
, False);
8629 Resolve
(Hi
, Universal_Fixed
);
8630 Set_Corresponding_Integer_Value
8631 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
8636 -- Set type of range to correspond to bounds
8638 Set_Etype
(Rng
, Etype
(Lo
));
8640 -- Set Esize to calculated size if not set already
8642 if Unknown_Esize
(Typ
) then
8643 Init_Esize
(Typ
, Actual_Size
);
8646 -- Set RM_Size if not already set. If already set, check value
8649 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
8652 if RM_Size
(Typ
) /= Uint_0
then
8653 if RM_Size
(Typ
) < Minsiz
then
8654 Error_Msg_Uint_1
:= RM_Size
(Typ
);
8655 Error_Msg_Uint_2
:= Minsiz
;
8657 ("size given (^) for type& too small, minimum allowed is ^",
8658 Size_Clause
(Typ
), Typ
);
8662 Set_RM_Size
(Typ
, Minsiz
);
8666 -- Check for shaving
8668 if Comes_From_Source
(Typ
) then
8670 -- In SPARK mode the given bounds must be strictly representable
8672 if SPARK_Mode
= On
then
8673 if Orig_Lo
< Expr_Value_R
(Lo
) then
8675 ("declared low bound of type & is outside type range",
8679 if Orig_Hi
> Expr_Value_R
(Hi
) then
8681 ("declared high bound of type & is outside type range",
8686 if Orig_Lo
< Expr_Value_R
(Lo
) then
8688 ("declared low bound of type & is outside type range??", Typ
);
8690 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
8693 if Orig_Hi
> Expr_Value_R
(Hi
) then
8695 ("declared high bound of type & is outside type range??",
8698 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
8702 end Freeze_Fixed_Point_Type
;
8708 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
8712 Set_Has_Delayed_Freeze
(T
);
8713 L
:= Freeze_Entity
(T
, N
);
8715 if Is_Non_Empty_List
(L
) then
8716 Insert_Actions
(N
, L
);
8720 --------------------------
8721 -- Freeze_Static_Object --
8722 --------------------------
8724 procedure Freeze_Static_Object
(E
: Entity_Id
) is
8726 Cannot_Be_Static
: exception;
8727 -- Exception raised if the type of a static object cannot be made
8728 -- static. This happens if the type depends on non-global objects.
8730 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
8731 -- Called to ensure that an expression used as part of a type definition
8732 -- is statically allocatable, which means that the expression type is
8733 -- statically allocatable, and the expression is either static, or a
8734 -- reference to a library level constant.
8736 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
8737 -- Called to mark a type as static, checking that it is possible
8738 -- to set the type as static. If it is not possible, then the
8739 -- exception Cannot_Be_Static is raised.
8741 -----------------------------
8742 -- Ensure_Expression_Is_SA --
8743 -----------------------------
8745 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
8749 Ensure_Type_Is_SA
(Etype
(N
));
8751 if Is_OK_Static_Expression
(N
) then
8754 elsif Nkind
(N
) = N_Identifier
then
8758 and then Ekind
(Ent
) = E_Constant
8759 and then Is_Library_Level_Entity
(Ent
)
8765 raise Cannot_Be_Static
;
8766 end Ensure_Expression_Is_SA
;
8768 -----------------------
8769 -- Ensure_Type_Is_SA --
8770 -----------------------
8772 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
8777 -- If type is library level, we are all set
8779 if Is_Library_Level_Entity
(Typ
) then
8783 -- We are also OK if the type already marked as statically allocated,
8784 -- which means we processed it before.
8786 if Is_Statically_Allocated
(Typ
) then
8790 -- Mark type as statically allocated
8792 Set_Is_Statically_Allocated
(Typ
);
8794 -- Check that it is safe to statically allocate this type
8796 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
8797 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
8798 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
8800 elsif Is_Array_Type
(Typ
) then
8801 N
:= First_Index
(Typ
);
8802 while Present
(N
) loop
8803 Ensure_Type_Is_SA
(Etype
(N
));
8807 Ensure_Type_Is_SA
(Component_Type
(Typ
));
8809 elsif Is_Access_Type
(Typ
) then
8810 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
8814 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
8817 if T
/= Standard_Void_Type
then
8818 Ensure_Type_Is_SA
(T
);
8821 F
:= First_Formal
(Designated_Type
(Typ
));
8822 while Present
(F
) loop
8823 Ensure_Type_Is_SA
(Etype
(F
));
8829 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
8832 elsif Is_Record_Type
(Typ
) then
8833 C
:= First_Entity
(Typ
);
8834 while Present
(C
) loop
8835 if Ekind
(C
) = E_Discriminant
8836 or else Ekind
(C
) = E_Component
8838 Ensure_Type_Is_SA
(Etype
(C
));
8840 elsif Is_Type
(C
) then
8841 Ensure_Type_Is_SA
(C
);
8847 elsif Ekind
(Typ
) = E_Subprogram_Type
then
8848 Ensure_Type_Is_SA
(Etype
(Typ
));
8850 C
:= First_Formal
(Typ
);
8851 while Present
(C
) loop
8852 Ensure_Type_Is_SA
(Etype
(C
));
8857 raise Cannot_Be_Static
;
8859 end Ensure_Type_Is_SA
;
8861 -- Start of processing for Freeze_Static_Object
8864 Ensure_Type_Is_SA
(Etype
(E
));
8867 when Cannot_Be_Static
=>
8869 -- If the object that cannot be static is imported or exported, then
8870 -- issue an error message saying that this object cannot be imported
8871 -- or exported. If it has an address clause it is an overlay in the
8872 -- current partition and the static requirement is not relevant.
8873 -- Do not issue any error message when ignoring rep clauses.
8875 if Ignore_Rep_Clauses
then
8878 elsif Is_Imported
(E
) then
8879 if No
(Address_Clause
(E
)) then
8881 ("& cannot be imported (local type is not constant)", E
);
8884 -- Otherwise must be exported, something is wrong if compiler
8885 -- is marking something as statically allocated which cannot be).
8887 else pragma Assert
(Is_Exported
(E
));
8889 ("& cannot be exported (local type is not constant)", E
);
8891 end Freeze_Static_Object
;
8893 -----------------------
8894 -- Freeze_Subprogram --
8895 -----------------------
8897 procedure Freeze_Subprogram
(E
: Entity_Id
) is
8898 function Check_Extra_Formals
(E
: Entity_Id
) return Boolean;
8899 -- Return True if the decoration of the attributes associated with extra
8900 -- formals are properly set.
8902 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
);
8903 -- Set the conventions of all anonymous access-to-subprogram formals and
8904 -- result subtype of subprogram Subp_Id to the convention of Subp_Id.
8906 -------------------------
8907 -- Check_Extra_Formals --
8908 -------------------------
8910 function Check_Extra_Formals
(E
: Entity_Id
) return Boolean is
8911 Last_Formal
: Entity_Id
:= Empty
;
8913 Has_Extra_Formals
: Boolean := False;
8916 -- No check required if expansion is disabled because extra
8917 -- formals are only generated when we are generating code.
8918 -- See Create_Extra_Formals.
8920 if not Expander_Active
then
8924 -- Check attribute Extra_Formal: If available, it must be set only
8925 -- on the last formal of E.
8927 Formal
:= First_Formal
(E
);
8928 while Present
(Formal
) loop
8929 if Present
(Extra_Formal
(Formal
)) then
8930 if Has_Extra_Formals
then
8934 Has_Extra_Formals
:= True;
8937 Last_Formal
:= Formal
;
8938 Next_Formal
(Formal
);
8941 -- Check attribute Extra_Accessibility_Of_Result
8943 if Ekind
(E
) in E_Function | E_Subprogram_Type
8944 and then Needs_Result_Accessibility_Level
(E
)
8945 and then No
(Extra_Accessibility_Of_Result
(E
))
8950 -- Check attribute Extra_Formals: If E has extra formals, then this
8951 -- attribute must point to the first extra formal of E.
8953 if Has_Extra_Formals
then
8954 return Present
(Extra_Formals
(E
))
8955 and then Present
(Extra_Formal
(Last_Formal
))
8956 and then Extra_Formal
(Last_Formal
) = Extra_Formals
(E
);
8958 -- When E has no formals, the first extra formal is available through
8959 -- the Extra_Formals attribute.
8961 elsif Present
(Extra_Formals
(E
)) then
8962 return No
(First_Formal
(E
));
8967 end Check_Extra_Formals
;
8969 ----------------------------
8970 -- Set_Profile_Convention --
8971 ----------------------------
8973 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
) is
8974 Conv
: constant Convention_Id
:= Convention
(Subp_Id
);
8976 procedure Set_Type_Convention
(Typ
: Entity_Id
);
8977 -- Set the convention of anonymous access-to-subprogram type Typ and
8978 -- its designated type to Conv.
8980 -------------------------
8981 -- Set_Type_Convention --
8982 -------------------------
8984 procedure Set_Type_Convention
(Typ
: Entity_Id
) is
8986 -- Set the convention on both the anonymous access-to-subprogram
8987 -- type and the subprogram type it points to because both types
8988 -- participate in conformance-related checks.
8990 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
8991 Set_Convention
(Typ
, Conv
);
8992 Set_Convention
(Designated_Type
(Typ
), Conv
);
8994 end Set_Type_Convention
;
9000 -- Start of processing for Set_Profile_Convention
9003 Formal
:= First_Formal
(Subp_Id
);
9004 while Present
(Formal
) loop
9005 Set_Type_Convention
(Etype
(Formal
));
9006 Next_Formal
(Formal
);
9009 if Ekind
(Subp_Id
) = E_Function
then
9010 Set_Type_Convention
(Etype
(Subp_Id
));
9012 end Set_Profile_Convention
;
9019 -- Start of processing for Freeze_Subprogram
9022 -- Subprogram may not have an address clause unless it is imported
9024 if Present
(Address_Clause
(E
)) then
9025 if not Is_Imported
(E
) then
9027 ("address clause can only be given for imported subprogram",
9028 Name
(Address_Clause
(E
)));
9032 -- Reset the Pure indication on an imported subprogram unless an
9033 -- explicit Pure_Function pragma was present or the subprogram is an
9034 -- intrinsic. We do this because otherwise it is an insidious error
9035 -- to call a non-pure function from pure unit and have calls
9036 -- mysteriously optimized away. What happens here is that the Import
9037 -- can bypass the normal check to ensure that pure units call only pure
9040 -- The reason for the intrinsic exception is that in general, intrinsic
9041 -- functions (such as shifts) are pure anyway. The only exceptions are
9042 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
9043 -- in any case, so no problem arises.
9046 and then Is_Pure
(E
)
9047 and then not Has_Pragma_Pure_Function
(E
)
9048 and then not Is_Intrinsic_Subprogram
(E
)
9050 Set_Is_Pure
(E
, False);
9053 -- For C++ constructors check that their external name has been given
9054 -- (either in pragma CPP_Constructor or in a pragma import).
9056 if Is_Constructor
(E
)
9057 and then Convention
(E
) = Convention_CPP
9059 (No
(Interface_Name
(E
))
9060 or else String_Equal
9061 (L
=> Strval
(Interface_Name
(E
)),
9062 R
=> Strval
(Get_Default_External_Name
(E
))))
9065 ("'C++ constructor must have external name or link name", E
);
9068 -- We also reset the Pure indication on a subprogram with an Address
9069 -- parameter, because the parameter may be used as a pointer and the
9070 -- referenced data may change even if the address value does not.
9072 -- Note that if the programmer gave an explicit Pure_Function pragma,
9073 -- then we believe the programmer, and leave the subprogram Pure. We
9074 -- also suppress this check on run-time files.
9077 and then Is_Subprogram
(E
)
9078 and then not Has_Pragma_Pure_Function
(E
)
9079 and then not Is_Internal_Unit
(Current_Sem_Unit
)
9081 Check_Function_With_Address_Parameter
(E
);
9084 -- Ensure that all anonymous access-to-subprogram types inherit the
9085 -- convention of their related subprogram (RM 6.3.1 13.1/3). This is
9086 -- not done for a defaulted convention Ada because those types also
9087 -- default to Ada. Convention Protected must not be propagated when
9088 -- the subprogram is an entry because this would be illegal. The only
9089 -- way to force convention Protected on these kinds of types is to
9090 -- include keyword "protected" in the access definition.
9092 if Convention
(E
) /= Convention_Ada
9093 and then Convention
(E
) /= Convention_Protected
9095 Set_Profile_Convention
(E
);
9098 -- For non-foreign convention subprograms, this is where we create
9099 -- the extra formals (for accessibility level and constrained bit
9100 -- information). We delay this till the freeze point precisely so
9101 -- that we know the convention.
9103 if not Has_Foreign_Convention
(E
) then
9104 if No
(Extra_Formals
(E
)) then
9106 -- Extra formals are shared by derived subprograms; therefore, if
9107 -- the ultimate alias of E has been frozen before E then the extra
9108 -- formals have been added, but the attribute Extra_Formals is
9109 -- still unset (and must be set now).
9111 if Present
(Alias
(E
))
9112 and then Is_Frozen
(Ultimate_Alias
(E
))
9113 and then Present
(Extra_Formals
(Ultimate_Alias
(E
)))
9114 and then Last_Formal
(Ultimate_Alias
(E
)) = Last_Formal
(E
)
9116 Set_Extra_Formals
(E
, Extra_Formals
(Ultimate_Alias
(E
)));
9118 if Ekind
(E
) = E_Function
then
9119 Set_Extra_Accessibility_Of_Result
(E
,
9120 Extra_Accessibility_Of_Result
(Ultimate_Alias
(E
)));
9123 Create_Extra_Formals
(E
);
9127 pragma Assert
(Check_Extra_Formals
(E
));
9130 -- If this is convention Ada and a Valued_Procedure, that's odd
9132 if Ekind
(E
) = E_Procedure
9133 and then Is_Valued_Procedure
(E
)
9134 and then Convention
(E
) = Convention_Ada
9135 and then Warn_On_Export_Import
9138 ("??Valued_Procedure has no effect for convention Ada", E
);
9139 Set_Is_Valued_Procedure
(E
, False);
9142 -- Case of foreign convention
9147 -- For foreign conventions, warn about return of unconstrained array
9149 if Ekind
(E
) = E_Function
then
9150 Retype
:= Underlying_Type
(Etype
(E
));
9152 -- If no return type, probably some other error, e.g. a
9153 -- missing full declaration, so ignore.
9158 -- If the return type is generic, we have emitted a warning
9159 -- earlier on, and there is nothing else to check here. Specific
9160 -- instantiations may lead to erroneous behavior.
9162 elsif Is_Generic_Type
(Etype
(E
)) then
9165 -- Display warning if returning unconstrained array
9167 elsif Is_Array_Type
(Retype
)
9168 and then not Is_Constrained
(Retype
)
9170 -- Check appropriate warning is enabled (should we check for
9171 -- Warnings (Off) on specific entities here, probably so???)
9173 and then Warn_On_Export_Import
9176 ("?x?foreign convention function& should not return " &
9177 "unconstrained array", E
);
9182 -- If any of the formals for an exported foreign convention
9183 -- subprogram have defaults, then emit an appropriate warning since
9184 -- this is odd (default cannot be used from non-Ada code)
9186 if Is_Exported
(E
) then
9187 F
:= First_Formal
(E
);
9188 while Present
(F
) loop
9189 if Warn_On_Export_Import
9190 and then Present
(Default_Value
(F
))
9193 ("?x?parameter cannot be defaulted in non-Ada call",
9202 -- Pragma Inline_Always is disallowed for dispatching subprograms
9203 -- because the address of such subprograms is saved in the dispatch
9204 -- table to support dispatching calls, and dispatching calls cannot
9205 -- be inlined. This is consistent with the restriction against using
9206 -- 'Access or 'Address on an Inline_Always subprogram.
9208 if Is_Dispatching_Operation
(E
)
9209 and then Has_Pragma_Inline_Always
(E
)
9212 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
9215 -- Because of the implicit representation of inherited predefined
9216 -- operators in the front-end, the overriding status of the operation
9217 -- may be affected when a full view of a type is analyzed, and this is
9218 -- not captured by the analysis of the corresponding type declaration.
9219 -- Therefore the correctness of a not-overriding indicator must be
9220 -- rechecked when the subprogram is frozen.
9222 if Nkind
(E
) = N_Defining_Operator_Symbol
9223 and then not Error_Posted
(Parent
(E
))
9225 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
9228 Retype
:= Get_Fullest_View
(Etype
(E
));
9230 if Transform_Function_Array
9231 and then Nkind
(Parent
(E
)) = N_Function_Specification
9232 and then Is_Array_Type
(Retype
)
9233 and then Is_Constrained
(Retype
)
9234 and then not Is_Unchecked_Conversion_Instance
(E
)
9235 and then not Rewritten_For_C
(E
)
9237 Build_Procedure_Form
(Unit_Declaration_Node
(E
));
9239 end Freeze_Subprogram
;
9241 ----------------------
9242 -- Is_Fully_Defined --
9243 ----------------------
9245 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
9247 if Ekind
(T
) = E_Class_Wide_Type
then
9248 return Is_Fully_Defined
(Etype
(T
));
9250 elsif Is_Array_Type
(T
) then
9251 return Is_Fully_Defined
(Component_Type
(T
));
9253 elsif Is_Record_Type
(T
)
9254 and not Is_Private_Type
(T
)
9256 -- Verify that the record type has no components with private types
9257 -- without completion.
9263 Comp
:= First_Component
(T
);
9264 while Present
(Comp
) loop
9265 if not Is_Fully_Defined
(Etype
(Comp
)) then
9269 Next_Component
(Comp
);
9274 -- For the designated type of an access to subprogram, all types in
9275 -- the profile must be fully defined.
9277 elsif Ekind
(T
) = E_Subprogram_Type
then
9282 F
:= First_Formal
(T
);
9283 while Present
(F
) loop
9284 if not Is_Fully_Defined
(Etype
(F
)) then
9291 return Is_Fully_Defined
(Etype
(T
));
9295 return not Is_Private_Type
(T
)
9296 or else Present
(Full_View
(Base_Type
(T
)));
9298 end Is_Fully_Defined
;
9300 ---------------------------------
9301 -- Process_Default_Expressions --
9302 ---------------------------------
9304 procedure Process_Default_Expressions
9306 After
: in out Node_Id
)
9308 Loc
: constant Source_Ptr
:= Sloc
(E
);
9315 Set_Default_Expressions_Processed
(E
);
9317 -- A subprogram instance and its associated anonymous subprogram share
9318 -- their signature. The default expression functions are defined in the
9319 -- wrapper packages for the anonymous subprogram, and should not be
9320 -- generated again for the instance.
9322 if Is_Generic_Instance
(E
)
9323 and then Present
(Alias
(E
))
9324 and then Default_Expressions_Processed
(Alias
(E
))
9329 Formal
:= First_Formal
(E
);
9330 while Present
(Formal
) loop
9331 if Present
(Default_Value
(Formal
)) then
9333 -- We work with a copy of the default expression because we
9334 -- do not want to disturb the original, since this would mess
9335 -- up the conformance checking.
9337 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
9339 -- The analysis of the expression may generate insert actions,
9340 -- which of course must not be executed. We wrap those actions
9341 -- in a procedure that is not called, and later on eliminated.
9342 -- The following cases have no side effects, and are analyzed
9345 if Nkind
(Dcopy
) = N_Identifier
9346 or else Nkind
(Dcopy
) in N_Expanded_Name
9348 | N_Character_Literal
9351 or else (Nkind
(Dcopy
) = N_Attribute_Reference
9352 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
9353 or else Known_Null
(Dcopy
)
9355 -- If there is no default function, we must still do a full
9356 -- analyze call on the default value, to ensure that all error
9357 -- checks are performed, e.g. those associated with static
9358 -- evaluation. Note: this branch will always be taken if the
9359 -- analyzer is turned off (but we still need the error checks).
9361 -- Note: the setting of parent here is to meet the requirement
9362 -- that we can only analyze the expression while attached to
9363 -- the tree. Really the requirement is that the parent chain
9364 -- be set, we don't actually need to be in the tree.
9366 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
9369 -- Default expressions are resolved with their own type if the
9370 -- context is generic, to avoid anomalies with private types.
9372 if Ekind
(Scope
(E
)) = E_Generic_Package
then
9375 Resolve
(Dcopy
, Etype
(Formal
));
9378 -- If that resolved expression will raise constraint error,
9379 -- then flag the default value as raising constraint error.
9380 -- This allows a proper error message on the calls.
9382 if Raises_Constraint_Error
(Dcopy
) then
9383 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
9386 -- If the default is a parameterless call, we use the name of
9387 -- the called function directly, and there is no body to build.
9389 elsif Nkind
(Dcopy
) = N_Function_Call
9390 and then No
(Parameter_Associations
(Dcopy
))
9394 -- Else construct and analyze the body of a wrapper procedure
9395 -- that contains an object declaration to hold the expression.
9396 -- Given that this is done only to complete the analysis, it is
9397 -- simpler to build a procedure than a function which might
9398 -- involve secondary stack expansion.
9401 Dnam
:= Make_Temporary
(Loc
, 'D');
9404 Make_Subprogram_Body
(Loc
,
9406 Make_Procedure_Specification
(Loc
,
9407 Defining_Unit_Name
=> Dnam
),
9409 Declarations
=> New_List
(
9410 Make_Object_Declaration
(Loc
,
9411 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
9412 Object_Definition
=>
9413 New_Occurrence_Of
(Etype
(Formal
), Loc
),
9414 Expression
=> New_Copy_Tree
(Dcopy
))),
9416 Handled_Statement_Sequence
=>
9417 Make_Handled_Sequence_Of_Statements
(Loc
,
9418 Statements
=> Empty_List
));
9420 Set_Scope
(Dnam
, Scope
(E
));
9421 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
9422 Set_Is_Eliminated
(Dnam
);
9423 Insert_After
(After
, Dbody
);
9429 Next_Formal
(Formal
);
9431 end Process_Default_Expressions
;
9433 ----------------------------------------
9434 -- Set_Component_Alignment_If_Not_Set --
9435 ----------------------------------------
9437 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
9439 -- Ignore if not base type, subtypes don't need anything
9441 if Typ
/= Base_Type
(Typ
) then
9445 -- Do not override existing representation
9447 if Is_Packed
(Typ
) then
9450 elsif Has_Specified_Layout
(Typ
) then
9453 elsif Component_Alignment
(Typ
) /= Calign_Default
then
9457 Set_Component_Alignment
9458 (Typ
, Scope_Stack
.Table
9459 (Scope_Stack
.Last
).Component_Alignment_Default
);
9461 end Set_Component_Alignment_If_Not_Set
;
9463 --------------------------
9464 -- Set_SSO_From_Default --
9465 --------------------------
9467 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
9471 -- Set default SSO for an array or record base type, except in case of
9472 -- a type extension (which always inherits the SSO of its parent type).
9475 and then (Is_Array_Type
(T
)
9476 or else (Is_Record_Type
(T
)
9477 and then not (Is_Tagged_Type
(T
)
9478 and then Is_Derived_Type
(T
))))
9481 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
9483 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
9485 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
9487 -- For a record type, if bit order is specified explicitly,
9488 -- then do not set SSO from default if not consistent. Note that
9489 -- we do not want to look at a Bit_Order attribute definition
9490 -- for a parent: if we were to inherit Bit_Order, then both
9491 -- SSO_Set_*_By_Default flags would have been cleared already
9492 -- (by Inherit_Aspects_At_Freeze_Point).
9497 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
9498 and then Reverse_Bit_Order
(T
) /= Reversed
)
9500 -- If flags cause reverse storage order, then set the result. Note
9501 -- that we would have ignored the pragma setting the non default
9502 -- storage order in any case, hence the assertion at this point.
9505 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
9507 Set_Reverse_Storage_Order
(T
, Reversed
);
9509 -- For a record type, also set reversed bit order. Note: if a bit
9510 -- order has been specified explicitly, then this is a no-op.
9512 if Is_Record_Type
(T
) then
9513 Set_Reverse_Bit_Order
(T
, Reversed
);
9517 end Set_SSO_From_Default
;
9523 procedure Undelay_Type
(T
: Entity_Id
) is
9525 Set_Has_Delayed_Freeze
(T
, False);
9526 Set_Freeze_Node
(T
, Empty
);
9528 -- Since we don't want T to have a Freeze_Node, we don't want its
9529 -- Full_View or Corresponding_Record_Type to have one either.
9531 -- ??? Fundamentally, this whole handling is unpleasant. What we really
9532 -- want is to be sure that for an Itype that's part of record R and is a
9533 -- subtype of type T, that it's frozen after the later of the freeze
9534 -- points of R and T. We have no way of doing that directly, so what we
9535 -- do is force most such Itypes to be frozen as part of freezing R via
9536 -- this procedure and only delay the ones that need to be delayed
9537 -- (mostly the designated types of access types that are defined as part
9540 if Is_Private_Type
(T
)
9541 and then Present
(Full_View
(T
))
9542 and then Is_Itype
(Full_View
(T
))
9543 and then Is_Record_Type
(Scope
(Full_View
(T
)))
9545 Undelay_Type
(Full_View
(T
));
9548 if Is_Concurrent_Type
(T
)
9549 and then Present
(Corresponding_Record_Type
(T
))
9550 and then Is_Itype
(Corresponding_Record_Type
(T
))
9551 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
9553 Undelay_Type
(Corresponding_Record_Type
(T
));
9561 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Entity_Id
) is
9562 Ent
: constant Entity_Id
:= Entity
(Nam
);
9563 -- The object to which the address clause applies
9566 Old
: Entity_Id
:= Empty
;
9570 -- No warning if address clause overlay warnings are off
9572 if not Address_Clause_Overlay_Warnings
then
9576 -- No warning if there is an explicit initialization
9578 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
9580 if Present
(Init
) and then Comes_From_Source
(Init
) then
9584 -- We only give the warning for non-imported entities of a type for
9585 -- which a non-null base init proc is defined, or for objects of access
9586 -- types with implicit null initialization, or when Normalize_Scalars
9587 -- applies and the type is scalar or a string type (the latter being
9588 -- tested for because predefined String types are initialized by inline
9589 -- code rather than by an init_proc). Note that we do not give the
9590 -- warning for Initialize_Scalars, since we suppressed initialization
9591 -- in this case. Also, do not warn if Suppress_Initialization is set
9592 -- either on the type, or on the object via pragma or aspect.
9595 and then not Is_Imported
(Ent
)
9596 and then not Initialization_Suppressed
(Typ
)
9597 and then not (Ekind
(Ent
) = E_Variable
9598 and then Initialization_Suppressed
(Ent
))
9599 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
9600 or else Is_Access_Type
(Typ
)
9601 or else (Normalize_Scalars
9602 and then (Is_Scalar_Type
(Typ
)
9603 or else Is_String_Type
(Typ
))))
9605 if Nkind
(Expr
) = N_Attribute_Reference
9606 and then Is_Entity_Name
(Prefix
(Expr
))
9608 Old
:= Entity
(Prefix
(Expr
));
9610 elsif Is_Entity_Name
(Expr
)
9611 and then Ekind
(Entity
(Expr
)) = E_Constant
9613 Decl
:= Declaration_Node
(Entity
(Expr
));
9615 if Nkind
(Decl
) = N_Object_Declaration
9616 and then Present
(Expression
(Decl
))
9617 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
9618 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
9620 Old
:= Entity
(Prefix
(Expression
(Decl
)));
9622 elsif Nkind
(Expr
) = N_Function_Call
then
9626 -- A function call (most likely to To_Address) is probably not an
9627 -- overlay, so skip warning. Ditto if the function call was inlined
9628 -- and transformed into an entity.
9630 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
9634 -- If a pragma Import follows, we assume that it is for the current
9635 -- target of the address clause, and skip the warning. There may be
9636 -- a source pragma or an aspect that specifies import and generates
9637 -- the corresponding pragma. These will indicate that the entity is
9638 -- imported and that is checked above so that the spurious warning
9639 -- (generated when the entity is frozen) will be suppressed. The
9640 -- pragma may be attached to the aspect, so it is not yet a list
9643 if Is_List_Member
(Parent
(Expr
)) then
9644 Decl
:= Next
(Parent
(Expr
));
9647 and then Nkind
(Decl
) = N_Pragma
9648 and then Pragma_Name
(Decl
) = Name_Import
9654 -- Otherwise give warning message
9656 if Present
(Old
) then
9657 Error_Msg_Node_2
:= Old
;
9659 ("default initialization of & may modify &??",
9663 ("default initialization of & may modify overlaid storage??",
9667 -- Add friendly warning if initialization comes from a packed array
9670 if Is_Record_Type
(Typ
) then
9675 Comp
:= First_Component
(Typ
);
9676 while Present
(Comp
) loop
9677 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
9678 and then Present
(Expression
(Parent
(Comp
)))
9681 elsif Is_Array_Type
(Etype
(Comp
))
9682 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
9685 ("\packed array component& " &
9686 "will be initialized to zero??",
9690 Next_Component
(Comp
);
9697 ("\use pragma Import for & to " &
9698 "suppress initialization (RM B.1(24))??",