1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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 Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Ch3
; use Exp_Ch3
;
34 with Exp_Ch7
; use Exp_Ch7
;
35 with Exp_Disp
; use Exp_Disp
;
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_Ch6
; use Sem_Ch6
;
53 with Sem_Ch7
; use Sem_Ch7
;
54 with Sem_Ch8
; use Sem_Ch8
;
55 with Sem_Ch13
; use Sem_Ch13
;
56 with Sem_Eval
; use Sem_Eval
;
57 with Sem_Mech
; use Sem_Mech
;
58 with Sem_Prag
; use Sem_Prag
;
59 with Sem_Res
; use Sem_Res
;
60 with Sem_Util
; use Sem_Util
;
61 with Sinfo
; use Sinfo
;
62 with Snames
; use Snames
;
63 with Stand
; use Stand
;
64 with Targparm
; use Targparm
;
65 with Tbuild
; use Tbuild
;
66 with Ttypes
; use Ttypes
;
67 with Uintp
; use Uintp
;
68 with Urealp
; use Urealp
;
69 with Warnsw
; use Warnsw
;
71 package body Freeze
is
73 -----------------------
74 -- Local Subprograms --
75 -----------------------
77 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
78 -- Typ is a type that is being frozen. If no size clause is given,
79 -- but a default Esize has been computed, then this default Esize is
80 -- adjusted up if necessary to be consistent with a given alignment,
81 -- but never to a value greater than Long_Long_Integer'Size. This
82 -- is used for all discrete types and for fixed-point types.
84 procedure Build_And_Analyze_Renamed_Body
87 After
: in out Node_Id
);
88 -- Build body for a renaming declaration, insert in tree and analyze
90 procedure Check_Address_Clause
(E
: Entity_Id
);
91 -- Apply legality checks to address clauses for object declarations,
92 -- at the point the object is frozen. Also ensure any initialization is
93 -- performed only after the object has been frozen.
95 procedure Check_Component_Storage_Order
96 (Encl_Type
: Entity_Id
;
99 Comp_ADC_Present
: out Boolean);
100 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
101 -- clause, verify that the component type has an explicit and compatible
102 -- attribute/aspect. For arrays, Comp is Empty; for records, it is the
103 -- entity of the component under consideration. For an Encl_Type that
104 -- does not have a Scalar_Storage_Order attribute definition clause,
105 -- verify that the component also does not have such a clause.
106 -- ADC is the attribute definition clause if present (or Empty). On return,
107 -- Comp_ADC_Present is set True if the component has a Scalar_Storage_Order
108 -- attribute definition clause.
110 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
);
111 -- When an expression function is frozen by a use of it, the expression
112 -- itself is frozen. Check that the expression does not include references
113 -- to deferred constants without completion. We report this at the freeze
114 -- point of the function, to provide a better error message.
116 -- In most cases the expression itself is frozen by the time the function
117 -- itself is frozen, because the formals will be frozen by then. However,
118 -- Attribute references to outer types are freeze points for those types;
119 -- this routine generates the required freeze nodes for them.
121 procedure Check_Strict_Alignment
(E
: Entity_Id
);
122 -- E is a base type. If E is tagged or has a component that is aliased
123 -- or tagged or contains something this is aliased or tagged, set
126 procedure Check_Unsigned_Type
(E
: Entity_Id
);
127 pragma Inline
(Check_Unsigned_Type
);
128 -- If E is a fixed-point or discrete type, then all the necessary work
129 -- to freeze it is completed except for possible setting of the flag
130 -- Is_Unsigned_Type, which is done by this procedure. The call has no
131 -- effect if the entity E is not a discrete or fixed-point type.
133 procedure Freeze_And_Append
136 Result
: in out List_Id
);
137 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
138 -- nodes to Result, modifying Result from No_List if necessary. N has
139 -- the same usage as in Freeze_Entity.
141 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
142 -- Freeze enumeration type. The Esize field is set as processing
143 -- proceeds (i.e. set by default when the type is declared and then
144 -- adjusted by rep clauses. What this procedure does is to make sure
145 -- that if a foreign convention is specified, and no specific size
146 -- is given, then the size must be at least Integer'Size.
148 procedure Freeze_Static_Object
(E
: Entity_Id
);
149 -- If an object is frozen which has Is_Statically_Allocated set, then
150 -- all referenced types must also be marked with this flag. This routine
151 -- is in charge of meeting this requirement for the object entity E.
153 procedure Freeze_Subprogram
(E
: Entity_Id
);
154 -- Perform freezing actions for a subprogram (create extra formals,
155 -- and set proper default mechanism values). Note that this routine
156 -- is not called for internal subprograms, for which neither of these
157 -- actions is needed (or desirable, we do not want for example to have
158 -- these extra formals present in initialization procedures, where they
159 -- would serve no purpose). In this call E is either a subprogram or
160 -- a subprogram type (i.e. an access to a subprogram).
162 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
163 -- True if T is not private and has no private components, or has a full
164 -- view. Used to determine whether the designated type of an access type
165 -- should be frozen when the access type is frozen. This is done when an
166 -- allocator is frozen, or an expression that may involve attributes of
167 -- the designated type. Otherwise freezing the access type does not freeze
168 -- the designated type.
170 procedure Process_Default_Expressions
172 After
: in out Node_Id
);
173 -- This procedure is called for each subprogram to complete processing of
174 -- default expressions at the point where all types are known to be frozen.
175 -- The expressions must be analyzed in full, to make sure that all error
176 -- processing is done (they have only been pre-analyzed). If the expression
177 -- is not an entity or literal, its analysis may generate code which must
178 -- not be executed. In that case we build a function body to hold that
179 -- code. This wrapper function serves no other purpose (it used to be
180 -- called to evaluate the default, but now the default is inlined at each
183 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
184 -- Typ is a record or array type that is being frozen. This routine sets
185 -- the default component alignment from the scope stack values if the
186 -- alignment is otherwise not specified.
188 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
189 -- As each entity is frozen, this routine is called to deal with the
190 -- setting of Debug_Info_Needed for the entity. This flag is set if
191 -- the entity comes from source, or if we are in Debug_Generated_Code
192 -- mode or if the -gnatdV debug flag is set. However, it never sets
193 -- the flag if Debug_Info_Off is set. This procedure also ensures that
194 -- subsidiary entities have the flag set as required.
196 procedure Set_SSO_From_Default
(T
: Entity_Id
);
197 -- T is a record or array type that is being frozen. If it is a base type,
198 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
199 -- will be set appropriately. Note that an explicit occurrence of aspect
200 -- Scalar_Storage_Order or an explicit setting of this aspect with an
201 -- attribute definition clause occurs, then these two flags are reset in
202 -- any case, so call will have no effect.
204 procedure Undelay_Type
(T
: Entity_Id
);
205 -- T is a type of a component that we know to be an Itype. We don't want
206 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
207 -- Full_View or Corresponding_Record_Type.
209 procedure Warn_Overlay
213 -- Expr is the expression for an address clause for entity Nam whose type
214 -- is Typ. If Typ has a default initialization, and there is no explicit
215 -- initialization in the source declaration, check whether the address
216 -- clause might cause overlaying of an entity, and emit a warning on the
217 -- side effect that the initialization will cause.
219 -------------------------------
220 -- Adjust_Esize_For_Alignment --
221 -------------------------------
223 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
227 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
228 Align
:= Alignment_In_Bits
(Typ
);
230 if Align
> Esize
(Typ
)
231 and then Align
<= Standard_Long_Long_Integer_Size
233 Set_Esize
(Typ
, Align
);
236 end Adjust_Esize_For_Alignment
;
238 ------------------------------------
239 -- Build_And_Analyze_Renamed_Body --
240 ------------------------------------
242 procedure Build_And_Analyze_Renamed_Body
245 After
: in out Node_Id
)
247 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
248 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
250 Renamed_Subp
: Entity_Id
;
253 -- If the renamed subprogram is intrinsic, there is no need for a
254 -- wrapper body: we set the alias that will be called and expanded which
255 -- completes the declaration. This transformation is only legal if the
256 -- renamed entity has already been elaborated.
258 -- Note that it is legal for a renaming_as_body to rename an intrinsic
259 -- subprogram, as long as the renaming occurs before the new entity
260 -- is frozen (RM 8.5.4 (5)).
262 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
263 and then Is_Entity_Name
(Name
(Body_Decl
))
265 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
267 Renamed_Subp
:= Empty
;
270 if Present
(Renamed_Subp
)
271 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
273 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
274 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
276 -- We can make the renaming entity intrinsic if the renamed function
277 -- has an interface name, or if it is one of the shift/rotate
278 -- operations known to the compiler.
281 (Present
(Interface_Name
(Renamed_Subp
))
282 or else Nam_In
(Chars
(Renamed_Subp
), Name_Rotate_Left
,
286 Name_Shift_Right_Arithmetic
))
288 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
290 if Present
(Alias
(Renamed_Subp
)) then
291 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
293 Set_Alias
(Ent
, Renamed_Subp
);
296 Set_Is_Intrinsic_Subprogram
(Ent
);
297 Set_Has_Completion
(Ent
);
300 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
301 Insert_After
(After
, Body_Node
);
302 Mark_Rewrite_Insertion
(Body_Node
);
306 end Build_And_Analyze_Renamed_Body
;
308 ------------------------
309 -- Build_Renamed_Body --
310 ------------------------
312 function Build_Renamed_Body
314 New_S
: Entity_Id
) return Node_Id
316 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
317 -- We use for the source location of the renamed body, the location of
318 -- the spec entity. It might seem more natural to use the location of
319 -- the renaming declaration itself, but that would be wrong, since then
320 -- the body we create would look as though it was created far too late,
321 -- and this could cause problems with elaboration order analysis,
322 -- particularly in connection with instantiations.
324 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
325 Nam
: constant Node_Id
:= Name
(N
);
327 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
328 Actuals
: List_Id
:= No_List
;
333 O_Formal
: Entity_Id
;
334 Param_Spec
: Node_Id
;
336 Pref
: Node_Id
:= Empty
;
337 -- If the renamed entity is a primitive operation given in prefix form,
338 -- the prefix is the target object and it has to be added as the first
339 -- actual in the generated call.
342 -- Determine the entity being renamed, which is the target of the call
343 -- statement. If the name is an explicit dereference, this is a renaming
344 -- of a subprogram type rather than a subprogram. The name itself is
347 if Nkind
(Nam
) = N_Selected_Component
then
348 Old_S
:= Entity
(Selector_Name
(Nam
));
350 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
351 Old_S
:= Etype
(Nam
);
353 elsif Nkind
(Nam
) = N_Indexed_Component
then
354 if Is_Entity_Name
(Prefix
(Nam
)) then
355 Old_S
:= Entity
(Prefix
(Nam
));
357 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
360 elsif Nkind
(Nam
) = N_Character_Literal
then
361 Old_S
:= Etype
(New_S
);
364 Old_S
:= Entity
(Nam
);
367 if Is_Entity_Name
(Nam
) then
369 -- If the renamed entity is a predefined operator, retain full name
370 -- to ensure its visibility.
372 if Ekind
(Old_S
) = E_Operator
373 and then Nkind
(Nam
) = N_Expanded_Name
375 Call_Name
:= New_Copy
(Name
(N
));
377 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
381 if Nkind
(Nam
) = N_Selected_Component
382 and then Present
(First_Formal
(Old_S
))
384 (Is_Controlling_Formal
(First_Formal
(Old_S
))
385 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
388 -- Retrieve the target object, to be added as a first actual
391 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
392 Pref
:= Prefix
(Nam
);
395 Call_Name
:= New_Copy
(Name
(N
));
398 -- Original name may have been overloaded, but is fully resolved now
400 Set_Is_Overloaded
(Call_Name
, False);
403 -- For simple renamings, subsequent calls can be expanded directly as
404 -- calls to the renamed entity. The body must be generated in any case
405 -- for calls that may appear elsewhere. This is not done in the case
406 -- where the subprogram is an instantiation because the actual proper
407 -- body has not been built yet.
409 if Ekind_In
(Old_S
, E_Function
, E_Procedure
)
410 and then Nkind
(Decl
) = N_Subprogram_Declaration
411 and then not Is_Generic_Instance
(Old_S
)
413 Set_Body_To_Inline
(Decl
, Old_S
);
416 -- Check whether the return type is a limited view. If the subprogram
417 -- is already frozen the generated body may have a non-limited view
418 -- of the type, that must be used, because it is the one in the spec
419 -- of the renaming declaration.
421 if Ekind
(Old_S
) = E_Function
422 and then Is_Entity_Name
(Result_Definition
(Spec
))
425 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
427 if Ekind
(Ret_Type
) = E_Incomplete_Type
428 and then Present
(Non_Limited_View
(Ret_Type
))
430 Set_Result_Definition
(Spec
,
431 New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
436 -- The body generated for this renaming is an internal artifact, and
437 -- does not constitute a freeze point for the called entity.
439 Set_Must_Not_Freeze
(Call_Name
);
441 Formal
:= First_Formal
(Defining_Entity
(Decl
));
443 if Present
(Pref
) then
445 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
446 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
449 -- The controlling formal may be an access parameter, or the
450 -- actual may be an access value, so adjust accordingly.
452 if Is_Access_Type
(Pref_Type
)
453 and then not Is_Access_Type
(Form_Type
)
456 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
458 elsif Is_Access_Type
(Form_Type
)
459 and then not Is_Access_Type
(Pref
)
462 (Make_Attribute_Reference
(Loc
,
463 Attribute_Name
=> Name_Access
,
464 Prefix
=> Relocate_Node
(Pref
)));
466 Actuals
:= New_List
(Pref
);
470 elsif Present
(Formal
) then
477 if Present
(Formal
) then
478 while Present
(Formal
) loop
479 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
480 Next_Formal
(Formal
);
484 -- If the renamed entity is an entry, inherit its profile. For other
485 -- renamings as bodies, both profiles must be subtype conformant, so it
486 -- is not necessary to replace the profile given in the declaration.
487 -- However, default values that are aggregates are rewritten when
488 -- partially analyzed, so we recover the original aggregate to insure
489 -- that subsequent conformity checking works. Similarly, if the default
490 -- expression was constant-folded, recover the original expression.
492 Formal
:= First_Formal
(Defining_Entity
(Decl
));
494 if Present
(Formal
) then
495 O_Formal
:= First_Formal
(Old_S
);
496 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
497 while Present
(Formal
) loop
498 if Is_Entry
(Old_S
) then
499 if Nkind
(Parameter_Type
(Param_Spec
)) /=
502 Set_Etype
(Formal
, Etype
(O_Formal
));
503 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
506 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
507 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
508 Nkind
(Default_Value
(O_Formal
))
510 Set_Expression
(Param_Spec
,
511 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
514 Next_Formal
(Formal
);
515 Next_Formal
(O_Formal
);
520 -- If the renamed entity is a function, the generated body contains a
521 -- return statement. Otherwise, build a procedure call. If the entity is
522 -- an entry, subsequent analysis of the call will transform it into the
523 -- proper entry or protected operation call. If the renamed entity is
524 -- a character literal, return it directly.
526 if Ekind
(Old_S
) = E_Function
527 or else Ekind
(Old_S
) = E_Operator
528 or else (Ekind
(Old_S
) = E_Subprogram_Type
529 and then Etype
(Old_S
) /= Standard_Void_Type
)
532 Make_Simple_Return_Statement
(Loc
,
534 Make_Function_Call
(Loc
,
536 Parameter_Associations
=> Actuals
));
538 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
540 Make_Simple_Return_Statement
(Loc
,
541 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
543 elsif Nkind
(Nam
) = N_Character_Literal
then
545 Make_Simple_Return_Statement
(Loc
,
546 Expression
=> Call_Name
);
550 Make_Procedure_Call_Statement
(Loc
,
552 Parameter_Associations
=> Actuals
);
555 -- Create entities for subprogram body and formals
557 Set_Defining_Unit_Name
(Spec
,
558 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
560 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
561 while Present
(Param_Spec
) loop
562 Set_Defining_Identifier
(Param_Spec
,
563 Make_Defining_Identifier
(Loc
,
564 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
569 Make_Subprogram_Body
(Loc
,
570 Specification
=> Spec
,
571 Declarations
=> New_List
,
572 Handled_Statement_Sequence
=>
573 Make_Handled_Sequence_Of_Statements
(Loc
,
574 Statements
=> New_List
(Call_Node
)));
576 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
578 Make_Subprogram_Declaration
(Loc
,
579 Specification
=> Specification
(N
)));
582 -- Link the body to the entity whose declaration it completes. If
583 -- the body is analyzed when the renamed entity is frozen, it may
584 -- be necessary to restore the proper scope (see package Exp_Ch13).
586 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
587 and then Present
(Corresponding_Spec
(N
))
589 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
591 Set_Corresponding_Spec
(Body_Node
, New_S
);
595 end Build_Renamed_Body
;
597 --------------------------
598 -- Check_Address_Clause --
599 --------------------------
601 procedure Check_Address_Clause
(E
: Entity_Id
) is
602 Addr
: constant Node_Id
:= Address_Clause
(E
);
604 Decl
: constant Node_Id
:= Declaration_Node
(E
);
605 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
606 Typ
: constant Entity_Id
:= Etype
(E
);
608 Tag_Assign
: Node_Id
;
611 if Present
(Addr
) then
612 Expr
:= Expression
(Addr
);
614 if Needs_Constant_Address
(Decl
, Typ
) then
615 Check_Constant_Address_Clause
(Expr
, E
);
617 -- Has_Delayed_Freeze was set on E when the address clause was
618 -- analyzed, and must remain set because we want the address
619 -- clause to be elaborated only after any entity it references
620 -- has been elaborated.
623 -- If Rep_Clauses are to be ignored, remove address clause from
624 -- list attached to entity, because it may be illegal for gigi,
625 -- for example by breaking order of elaboration..
627 if Ignore_Rep_Clauses
then
632 Rep
:= First_Rep_Item
(E
);
635 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
639 and then Next_Rep_Item
(Rep
) /= Addr
641 Rep
:= Next_Rep_Item
(Rep
);
645 if Present
(Rep
) then
646 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
650 -- And now remove the address clause
652 Kill_Rep_Clause
(Addr
);
654 elsif not Error_Posted
(Expr
)
655 and then not Needs_Finalization
(Typ
)
657 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
660 if Present
(Expression
(Decl
)) then
662 -- Capture initialization value at point of declaration,
663 -- and make explicit assignment legal, because object may
666 Remove_Side_Effects
(Expression
(Decl
));
667 Lhs
:= New_Occurrence_Of
(E
, Loc
);
668 Set_Assignment_OK
(Lhs
);
670 -- Move initialization to freeze actions (once the object has
671 -- been frozen, and the address clause alignment check has been
674 Append_Freeze_Action
(E
,
675 Make_Assignment_Statement
(Loc
,
677 Expression
=> Expression
(Decl
)));
679 Set_No_Initialization
(Decl
);
681 -- If the objet is tagged, check whether the tag must be
682 -- reassigned expliitly.
684 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
685 if Present
(Tag_Assign
) then
686 Append_Freeze_Action
(E
, Tag_Assign
);
690 end Check_Address_Clause
;
692 -----------------------------
693 -- Check_Compile_Time_Size --
694 -----------------------------
696 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
698 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
699 -- Sets the compile time known size (32 bits or less) in the Esize
700 -- field, of T checking for a size clause that was given which attempts
701 -- to give a smaller size, and also checking for an alignment clause.
703 function Size_Known
(T
: Entity_Id
) return Boolean;
704 -- Recursive function that does all the work
706 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
707 -- If T is a constrained subtype, its size is not known if any of its
708 -- discriminant constraints is not static and it is not a null record.
709 -- The test is conservative and doesn't check that the components are
710 -- in fact constrained by non-static discriminant values. Could be made
717 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
722 -- Check for bad size clause given
724 elsif Has_Size_Clause
(T
) then
725 if RM_Size
(T
) < S
then
726 Error_Msg_Uint_1
:= S
;
728 ("size for& too small, minimum allowed is ^",
732 -- Set size if not set already
734 elsif Unknown_RM_Size
(T
) then
743 function Size_Known
(T
: Entity_Id
) return Boolean is
751 if Size_Known_At_Compile_Time
(T
) then
754 -- Always True for scalar types. This is true even for generic formal
755 -- scalar types. We used to return False in the latter case, but the
756 -- size is known at compile time, even in the template, we just do
757 -- not know the exact size but that's not the point of this routine.
759 elsif Is_Scalar_Type
(T
)
760 or else Is_Task_Type
(T
)
766 elsif Is_Array_Type
(T
) then
768 -- String literals always have known size, and we can set it
770 if Ekind
(T
) = E_String_Literal_Subtype
then
771 Set_Small_Size
(T
, Component_Size
(T
)
772 * String_Literal_Length
(T
));
775 -- Unconstrained types never have known at compile time size
777 elsif not Is_Constrained
(T
) then
780 -- Don't do any recursion on type with error posted, since we may
781 -- have a malformed type that leads us into a loop.
783 elsif Error_Posted
(T
) then
786 -- Otherwise if component size unknown, then array size unknown
788 elsif not Size_Known
(Component_Type
(T
)) then
792 -- Check for all indexes static, and also compute possible size
793 -- (in case it is less than 32 and may be packable).
796 Esiz
: Uint
:= Component_Size
(T
);
800 Index
:= First_Index
(T
);
801 while Present
(Index
) loop
802 if Nkind
(Index
) = N_Range
then
803 Get_Index_Bounds
(Index
, Low
, High
);
805 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
809 Low
:= Type_Low_Bound
(Etype
(Index
));
810 High
:= Type_High_Bound
(Etype
(Index
));
813 if not Compile_Time_Known_Value
(Low
)
814 or else not Compile_Time_Known_Value
(High
)
815 or else Etype
(Index
) = Any_Type
820 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
832 Set_Small_Size
(T
, Esiz
);
836 -- Access types always have known at compile time sizes
838 elsif Is_Access_Type
(T
) then
841 -- For non-generic private types, go to underlying type if present
843 elsif Is_Private_Type
(T
)
844 and then not Is_Generic_Type
(T
)
845 and then Present
(Underlying_Type
(T
))
847 -- Don't do any recursion on type with error posted, since we may
848 -- have a malformed type that leads us into a loop.
850 if Error_Posted
(T
) then
853 return Size_Known
(Underlying_Type
(T
));
858 elsif Is_Record_Type
(T
) then
860 -- A class-wide type is never considered to have a known size
862 if Is_Class_Wide_Type
(T
) then
865 -- A subtype of a variant record must not have non-static
866 -- discriminated components.
868 elsif T
/= Base_Type
(T
)
869 and then not Static_Discriminated_Components
(T
)
873 -- Don't do any recursion on type with error posted, since we may
874 -- have a malformed type that leads us into a loop.
876 elsif Error_Posted
(T
) then
880 -- Now look at the components of the record
883 -- The following two variables are used to keep track of the
884 -- size of packed records if we can tell the size of the packed
885 -- record in the front end. Packed_Size_Known is True if so far
886 -- we can figure out the size. It is initialized to True for a
887 -- packed record, unless the record has discriminants or atomic
888 -- components or independent components.
890 -- The reason we eliminate the discriminated case is that
891 -- we don't know the way the back end lays out discriminated
892 -- packed records. If Packed_Size_Known is True, then
893 -- Packed_Size is the size in bits so far.
895 Packed_Size_Known
: Boolean :=
897 and then not Has_Discriminants
(T
)
898 and then not Has_Atomic_Components
(T
)
899 and then not Has_Independent_Components
(T
);
901 Packed_Size
: Uint
:= Uint_0
;
902 -- Size in bits so far
905 -- Test for variant part present
907 if Has_Discriminants
(T
)
908 and then Present
(Parent
(T
))
909 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
910 and then Nkind
(Type_Definition
(Parent
(T
))) =
912 and then not Null_Present
(Type_Definition
(Parent
(T
)))
914 Present
(Variant_Part
915 (Component_List
(Type_Definition
(Parent
(T
)))))
917 -- If variant part is present, and type is unconstrained,
918 -- then we must have defaulted discriminants, or a size
919 -- clause must be present for the type, or else the size
920 -- is definitely not known at compile time.
922 if not Is_Constrained
(T
)
924 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
925 and then Unknown_RM_Size
(T
)
931 -- Loop through components
933 Comp
:= First_Component_Or_Discriminant
(T
);
934 while Present
(Comp
) loop
935 Ctyp
:= Etype
(Comp
);
937 -- We do not know the packed size if there is a component
938 -- clause present (we possibly could, but this would only
939 -- help in the case of a record with partial rep clauses.
940 -- That's because in the case of full rep clauses, the
941 -- size gets figured out anyway by a different circuit).
943 if Present
(Component_Clause
(Comp
)) then
944 Packed_Size_Known
:= False;
947 -- We do not know the packed size if we have an atomic type
948 -- or component, or an independent type or component, or a
949 -- by reference type or aliased component (because packing
950 -- does not touch these).
953 or else Is_Atomic
(Comp
)
954 or else Is_Independent
(Ctyp
)
955 or else Is_Independent
(Comp
)
956 or else Is_By_Reference_Type
(Ctyp
)
957 or else Is_Aliased
(Comp
)
959 Packed_Size_Known
:= False;
962 -- We need to identify a component that is an array where
963 -- the index type is an enumeration type with non-standard
964 -- representation, and some bound of the type depends on a
967 -- This is because gigi computes the size by doing a
968 -- substitution of the appropriate discriminant value in
969 -- the size expression for the base type, and gigi is not
970 -- clever enough to evaluate the resulting expression (which
971 -- involves a call to rep_to_pos) at compile time.
973 -- It would be nice if gigi would either recognize that
974 -- this expression can be computed at compile time, or
975 -- alternatively figured out the size from the subtype
976 -- directly, where all the information is at hand ???
978 if Is_Array_Type
(Etype
(Comp
))
979 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
982 Ocomp
: constant Entity_Id
:=
983 Original_Record_Component
(Comp
);
984 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
990 Ind
:= First_Index
(OCtyp
);
991 while Present
(Ind
) loop
992 Indtyp
:= Etype
(Ind
);
994 if Is_Enumeration_Type
(Indtyp
)
995 and then Has_Non_Standard_Rep
(Indtyp
)
997 Lo
:= Type_Low_Bound
(Indtyp
);
998 Hi
:= Type_High_Bound
(Indtyp
);
1000 if Is_Entity_Name
(Lo
)
1001 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1005 elsif Is_Entity_Name
(Hi
)
1006 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1017 -- Clearly size of record is not known if the size of one of
1018 -- the components is not known.
1020 if not Size_Known
(Ctyp
) then
1024 -- Accumulate packed size if possible
1026 if Packed_Size_Known
then
1028 -- We can only deal with elementary types, since for
1029 -- non-elementary components, alignment enters into the
1030 -- picture, and we don't know enough to handle proper
1031 -- alignment in this context. Packed arrays count as
1032 -- elementary if the representation is a modular type.
1034 if Is_Elementary_Type
(Ctyp
)
1035 or else (Is_Array_Type
(Ctyp
)
1037 (Packed_Array_Impl_Type
(Ctyp
))
1038 and then Is_Modular_Integer_Type
1039 (Packed_Array_Impl_Type
(Ctyp
)))
1041 -- Packed size unknown if we have an atomic type
1042 -- or a by reference type, since the back end
1043 -- knows how these are layed out.
1046 or else Is_By_Reference_Type
(Ctyp
)
1048 Packed_Size_Known
:= False;
1050 -- If RM_Size is known and static, then we can keep
1051 -- accumulating the packed size
1053 elsif Known_Static_RM_Size
(Ctyp
) then
1055 -- A little glitch, to be removed sometime ???
1056 -- gigi does not understand zero sizes yet.
1058 if RM_Size
(Ctyp
) = Uint_0
then
1059 Packed_Size_Known
:= False;
1061 -- Normal case where we can keep accumulating the
1062 -- packed array size.
1065 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1068 -- If we have a field whose RM_Size is not known then
1069 -- we can't figure out the packed size here.
1072 Packed_Size_Known
:= False;
1075 -- If we have a non-elementary type we can't figure out
1076 -- the packed array size (alignment issues).
1079 Packed_Size_Known
:= False;
1083 Next_Component_Or_Discriminant
(Comp
);
1086 if Packed_Size_Known
then
1087 Set_Small_Size
(T
, Packed_Size
);
1093 -- All other cases, size not known at compile time
1100 -------------------------------------
1101 -- Static_Discriminated_Components --
1102 -------------------------------------
1104 function Static_Discriminated_Components
1105 (T
: Entity_Id
) return Boolean
1107 Constraint
: Elmt_Id
;
1110 if Has_Discriminants
(T
)
1111 and then Present
(Discriminant_Constraint
(T
))
1112 and then Present
(First_Component
(T
))
1114 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1115 while Present
(Constraint
) loop
1116 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1120 Next_Elmt
(Constraint
);
1125 end Static_Discriminated_Components
;
1127 -- Start of processing for Check_Compile_Time_Size
1130 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1131 end Check_Compile_Time_Size
;
1133 -----------------------------------
1134 -- Check_Component_Storage_Order --
1135 -----------------------------------
1137 procedure Check_Component_Storage_Order
1138 (Encl_Type
: Entity_Id
;
1141 Comp_ADC_Present
: out Boolean)
1143 Comp_Type
: Entity_Id
;
1147 Comp_Byte_Aligned
: Boolean;
1148 -- Set for the record case, True if Comp starts on a byte boundary
1149 -- (in which case it is allowed to have different storage order).
1151 Comp_SSO_Differs
: Boolean;
1152 -- Set True when the component is a nested composite, and it does not
1153 -- have the same scalar storage order as Encl_Type.
1155 Component_Aliased
: Boolean;
1160 if Present
(Comp
) then
1162 Comp_Type
:= Etype
(Comp
);
1164 if Is_Tag
(Comp
) then
1165 Comp_Byte_Aligned
:= True;
1166 Component_Aliased
:= False;
1169 -- If a component clause is present, check if the component starts
1170 -- on a storage element boundary. Otherwise conservatively assume
1171 -- it does so only in the case where the record is not packed.
1173 if Present
(Component_Clause
(Comp
)) then
1174 Comp_Byte_Aligned
:=
1175 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1177 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1180 Component_Aliased
:= Is_Aliased
(Comp
);
1186 Err_Node
:= Encl_Type
;
1187 Comp_Type
:= Component_Type
(Encl_Type
);
1189 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1192 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1193 -- the attribute definition clause is attached to the first subtype.
1195 Comp_Type
:= Base_Type
(Comp_Type
);
1196 Comp_ADC
:= Get_Attribute_Definition_Clause
1197 (First_Subtype
(Comp_Type
),
1198 Attribute_Scalar_Storage_Order
);
1199 Comp_ADC_Present
:= Present
(Comp_ADC
);
1201 -- Case of record or array component: check storage order compatibility
1203 if Is_Record_Type
(Comp_Type
) or else Is_Array_Type
(Comp_Type
) then
1205 Reverse_Storage_Order
(Encl_Type
)
1207 Reverse_Storage_Order
(Comp_Type
);
1209 -- Parent and extension must have same storage order
1211 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1212 if Comp_SSO_Differs
then
1214 ("record extension must have same scalar storage order as "
1215 & "parent", Err_Node
);
1218 -- If enclosing composite has explicit SSO then nested composite must
1219 -- have explicit SSO as well.
1221 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1222 Error_Msg_N
("nested composite must have explicit scalar "
1223 & "storage order", Err_Node
);
1225 -- If component and composite SSO differs, check that component
1226 -- falls on byte boundaries and isn't packed.
1228 elsif Comp_SSO_Differs
then
1230 -- Component SSO differs from enclosing composite:
1232 -- Reject if component is a packed array, as it may be represented
1233 -- as a scalar internally.
1235 if Is_Packed_Array
(Comp_Type
) then
1237 ("type of packed component must have same scalar "
1238 & "storage order as enclosing composite", Err_Node
);
1240 -- Reject if composite is a packed array, as it may be rewritten
1241 -- into an array of scalars.
1243 elsif Is_Packed_Array
(Encl_Type
) then
1244 Error_Msg_N
("type of packed array must have same scalar "
1245 & "storage order as component", Err_Node
);
1247 -- Reject if not byte aligned
1249 elsif Is_Record_Type
(Encl_Type
)
1250 and then not Comp_Byte_Aligned
1253 ("type of non-byte-aligned component must have same scalar "
1254 & "storage order as enclosing composite", Err_Node
);
1258 -- Enclosing type has explicit SSO: non-composite component must not
1261 elsif Present
(ADC
) and then Component_Aliased
then
1263 ("aliased component not permitted for type with "
1264 & "explicit Scalar_Storage_Order", Err_Node
);
1266 end Check_Component_Storage_Order
;
1268 -----------------------------
1269 -- Check_Debug_Info_Needed --
1270 -----------------------------
1272 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1274 if Debug_Info_Off
(T
) then
1277 elsif Comes_From_Source
(T
)
1278 or else Debug_Generated_Code
1279 or else Debug_Flag_VV
1280 or else Needs_Debug_Info
(T
)
1282 Set_Debug_Info_Needed
(T
);
1284 end Check_Debug_Info_Needed
;
1286 -------------------------------
1287 -- Check_Expression_Function --
1288 -------------------------------
1290 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1293 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1294 -- Function to search for deferred constant
1300 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1302 -- When a constant is initialized with the result of a dispatching
1303 -- call, the constant declaration is rewritten as a renaming of the
1304 -- displaced function result. This scenario is not a premature use of
1305 -- a constant even though the Has_Completion flag is not set.
1307 if Is_Entity_Name
(Nod
)
1308 and then Present
(Entity
(Nod
))
1309 and then Ekind
(Entity
(Nod
)) = E_Constant
1310 and then Scope
(Entity
(Nod
)) = Current_Scope
1311 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1312 N_Object_Declaration
1313 and then not Is_Imported
(Entity
(Nod
))
1314 and then not Has_Completion
(Entity
(Nod
))
1317 ("premature use of& in call or instance", N
, Entity
(Nod
));
1319 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1320 Analyze
(Prefix
(Nod
));
1322 if Is_Entity_Name
(Prefix
(Nod
))
1323 and then Is_Type
(Entity
(Prefix
(Nod
)))
1325 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1332 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1334 -- Start of processing for Check_Expression_Function
1337 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1339 if Scope
(Nam
) = Current_Scope
1340 and then Nkind
(Decl
) = N_Expression_Function
1342 Check_Deferred
(Expression
(Decl
));
1344 end Check_Expression_Function
;
1346 ----------------------------
1347 -- Check_Strict_Alignment --
1348 ----------------------------
1350 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1354 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1355 Set_Strict_Alignment
(E
);
1357 elsif Is_Array_Type
(E
) then
1358 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1360 elsif Is_Record_Type
(E
) then
1361 if Is_Limited_Record
(E
) then
1362 Set_Strict_Alignment
(E
);
1366 Comp
:= First_Component
(E
);
1367 while Present
(Comp
) loop
1368 if not Is_Type
(Comp
)
1369 and then (Strict_Alignment
(Etype
(Comp
))
1370 or else Is_Aliased
(Comp
))
1372 Set_Strict_Alignment
(E
);
1376 Next_Component
(Comp
);
1379 end Check_Strict_Alignment
;
1381 -------------------------
1382 -- Check_Unsigned_Type --
1383 -------------------------
1385 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1386 Ancestor
: Entity_Id
;
1391 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1395 -- Do not attempt to analyze case where range was in error
1397 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
1401 -- The situation that is non trivial is something like
1403 -- subtype x1 is integer range -10 .. +10;
1404 -- subtype x2 is x1 range 0 .. V1;
1405 -- subtype x3 is x2 range V2 .. V3;
1406 -- subtype x4 is x3 range V4 .. V5;
1408 -- where Vn are variables. Here the base type is signed, but we still
1409 -- know that x4 is unsigned because of the lower bound of x2.
1411 -- The only way to deal with this is to look up the ancestor chain
1415 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1419 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1421 if Compile_Time_Known_Value
(Lo_Bound
) then
1422 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1423 Set_Is_Unsigned_Type
(E
, True);
1429 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1431 -- If no ancestor had a static lower bound, go to base type
1433 if No
(Ancestor
) then
1435 -- Note: the reason we still check for a compile time known
1436 -- value for the base type is that at least in the case of
1437 -- generic formals, we can have bounds that fail this test,
1438 -- and there may be other cases in error situations.
1440 Btyp
:= Base_Type
(E
);
1442 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1446 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1448 if Compile_Time_Known_Value
(Lo_Bound
)
1449 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1451 Set_Is_Unsigned_Type
(E
, True);
1458 end Check_Unsigned_Type
;
1460 -------------------------
1461 -- Is_Atomic_Aggregate --
1462 -------------------------
1464 function Is_Atomic_Aggregate
1466 Typ
: Entity_Id
) return Boolean
1468 Loc
: constant Source_Ptr
:= Sloc
(E
);
1476 -- Array may be qualified, so find outer context
1478 if Nkind
(Par
) = N_Qualified_Expression
then
1479 Par
:= Parent
(Par
);
1482 if Nkind_In
(Par
, N_Object_Declaration
, N_Assignment_Statement
)
1483 and then Comes_From_Source
(Par
)
1485 Temp
:= Make_Temporary
(Loc
, 'T', E
);
1487 Make_Object_Declaration
(Loc
,
1488 Defining_Identifier
=> Temp
,
1489 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1490 Expression
=> Relocate_Node
(E
));
1491 Insert_Before
(Par
, New_N
);
1494 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1500 end Is_Atomic_Aggregate
;
1502 -----------------------------------------------
1503 -- Explode_Initialization_Compound_Statement --
1504 -----------------------------------------------
1506 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
1507 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
1510 if Present
(Init_Stmts
)
1511 and then Nkind
(Init_Stmts
) = N_Compound_Statement
1513 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
1515 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
1516 -- just removing it, because Freeze_All may rely on this particular
1517 -- Node_Id still being present in the enclosing list to know where to
1520 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
1522 Set_Initialization_Statements
(E
, Empty
);
1524 end Explode_Initialization_Compound_Statement
;
1530 -- Note: the easy coding for this procedure would be to just build a
1531 -- single list of freeze nodes and then insert them and analyze them
1532 -- all at once. This won't work, because the analysis of earlier freeze
1533 -- nodes may recursively freeze types which would otherwise appear later
1534 -- on in the freeze list. So we must analyze and expand the freeze nodes
1535 -- as they are generated.
1537 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1541 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1542 -- This is the internal recursive routine that does freezing of entities
1543 -- (but NOT the analysis of default expressions, which should not be
1544 -- recursive, we don't want to analyze those till we are sure that ALL
1545 -- the types are frozen).
1547 --------------------
1548 -- Freeze_All_Ent --
1549 --------------------
1551 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1556 procedure Process_Flist
;
1557 -- If freeze nodes are present, insert and analyze, and reset cursor
1558 -- for next insertion.
1564 procedure Process_Flist
is
1566 if Is_Non_Empty_List
(Flist
) then
1567 Lastn
:= Next
(After
);
1568 Insert_List_After_And_Analyze
(After
, Flist
);
1570 if Present
(Lastn
) then
1571 After
:= Prev
(Lastn
);
1573 After
:= Last
(List_Containing
(After
));
1578 -- Start or processing for Freeze_All_Ent
1582 while Present
(E
) loop
1584 -- If the entity is an inner package which is not a package
1585 -- renaming, then its entities must be frozen at this point. Note
1586 -- that such entities do NOT get frozen at the end of the nested
1587 -- package itself (only library packages freeze).
1589 -- Same is true for task declarations, where anonymous records
1590 -- created for entry parameters must be frozen.
1592 if Ekind
(E
) = E_Package
1593 and then No
(Renamed_Object
(E
))
1594 and then not Is_Child_Unit
(E
)
1595 and then not Is_Frozen
(E
)
1598 Install_Visible_Declarations
(E
);
1599 Install_Private_Declarations
(E
);
1601 Freeze_All
(First_Entity
(E
), After
);
1603 End_Package_Scope
(E
);
1605 if Is_Generic_Instance
(E
)
1606 and then Has_Delayed_Freeze
(E
)
1608 Set_Has_Delayed_Freeze
(E
, False);
1609 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1612 elsif Ekind
(E
) in Task_Kind
1613 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1614 N_Single_Task_Declaration
)
1617 Freeze_All
(First_Entity
(E
), After
);
1620 -- For a derived tagged type, we must ensure that all the
1621 -- primitive operations of the parent have been frozen, so that
1622 -- their addresses will be in the parent's dispatch table at the
1623 -- point it is inherited.
1625 elsif Ekind
(E
) = E_Record_Type
1626 and then Is_Tagged_Type
(E
)
1627 and then Is_Tagged_Type
(Etype
(E
))
1628 and then Is_Derived_Type
(E
)
1631 Prim_List
: constant Elist_Id
:=
1632 Primitive_Operations
(Etype
(E
));
1638 Prim
:= First_Elmt
(Prim_List
);
1639 while Present
(Prim
) loop
1640 Subp
:= Node
(Prim
);
1642 if Comes_From_Source
(Subp
)
1643 and then not Is_Frozen
(Subp
)
1645 Flist
:= Freeze_Entity
(Subp
, After
);
1654 if not Is_Frozen
(E
) then
1655 Flist
:= Freeze_Entity
(E
, After
);
1658 -- If already frozen, and there are delayed aspects, this is where
1659 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1660 -- for a description of how we handle aspect visibility).
1662 elsif Has_Delayed_Aspects
(E
) then
1664 -- Retrieve the visibility to the discriminants in order to
1665 -- analyze properly the aspects.
1667 Push_Scope_And_Install_Discriminants
(E
);
1673 Ritem
:= First_Rep_Item
(E
);
1674 while Present
(Ritem
) loop
1675 if Nkind
(Ritem
) = N_Aspect_Specification
1676 and then Entity
(Ritem
) = E
1677 and then Is_Delayed_Aspect
(Ritem
)
1679 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1682 Ritem
:= Next_Rep_Item
(Ritem
);
1686 Uninstall_Discriminants_And_Pop_Scope
(E
);
1689 -- If an incomplete type is still not frozen, this may be a
1690 -- premature freezing because of a body declaration that follows.
1691 -- Indicate where the freezing took place. Freezing will happen
1692 -- if the body comes from source, but not if it is internally
1693 -- generated, for example as the body of a type invariant.
1695 -- If the freezing is caused by the end of the current declarative
1696 -- part, it is a Taft Amendment type, and there is no error.
1698 if not Is_Frozen
(E
)
1699 and then Ekind
(E
) = E_Incomplete_Type
1702 Bod
: constant Node_Id
:= Next
(After
);
1705 -- The presence of a body freezes all entities previously
1706 -- declared in the current list of declarations, but this
1707 -- does not apply if the body does not come from source.
1708 -- A type invariant is transformed into a subprogram body
1709 -- which is placed at the end of the private part of the
1710 -- current package, but this body does not freeze incomplete
1711 -- types that may be declared in this private part.
1713 if (Nkind_In
(Bod
, N_Subprogram_Body
,
1718 or else Nkind
(Bod
) in N_Body_Stub
)
1720 List_Containing
(After
) = List_Containing
(Parent
(E
))
1721 and then Comes_From_Source
(Bod
)
1723 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1725 ("type& is frozen# before its full declaration",
1735 -- Start of processing for Freeze_All
1738 Freeze_All_Ent
(From
, After
);
1740 -- Now that all types are frozen, we can deal with default expressions
1741 -- that require us to build a default expression functions. This is the
1742 -- point at which such functions are constructed (after all types that
1743 -- might be used in such expressions have been frozen).
1745 -- For subprograms that are renaming_as_body, we create the wrapper
1746 -- bodies as needed.
1748 -- We also add finalization chains to access types whose designated
1749 -- types are controlled. This is normally done when freezing the type,
1750 -- but this misses recursive type definitions where the later members
1751 -- of the recursion introduce controlled components.
1753 -- Loop through entities
1756 while Present
(E
) loop
1757 if Is_Subprogram
(E
) then
1758 if not Default_Expressions_Processed
(E
) then
1759 Process_Default_Expressions
(E
, After
);
1762 if not Has_Completion
(E
) then
1763 Decl
:= Unit_Declaration_Node
(E
);
1765 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1766 if Error_Posted
(Decl
) then
1767 Set_Has_Completion
(E
);
1769 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1772 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1773 and then Present
(Corresponding_Body
(Decl
))
1775 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1776 = N_Subprogram_Renaming_Declaration
1778 Build_And_Analyze_Renamed_Body
1779 (Decl
, Corresponding_Body
(Decl
), After
);
1783 elsif Ekind
(E
) in Task_Kind
1784 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1785 N_Single_Task_Declaration
)
1791 Ent
:= First_Entity
(E
);
1792 while Present
(Ent
) loop
1794 and then not Default_Expressions_Processed
(Ent
)
1796 Process_Default_Expressions
(Ent
, After
);
1804 -- Historical note: We used to create a finalization master for an
1805 -- access type whose designated type is not controlled, but contains
1806 -- private controlled compoments. This form of postprocessing is no
1807 -- longer needed because the finalization master is now created when
1808 -- the access type is frozen (see Exp_Ch3.Freeze_Type).
1814 -----------------------
1815 -- Freeze_And_Append --
1816 -----------------------
1818 procedure Freeze_And_Append
1821 Result
: in out List_Id
)
1823 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1825 if Is_Non_Empty_List
(L
) then
1826 if Result
= No_List
then
1829 Append_List
(L
, Result
);
1832 end Freeze_And_Append
;
1838 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1839 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, N
);
1842 if Ekind
(T
) = E_Function
then
1843 Check_Expression_Function
(N
, T
);
1846 if Is_Non_Empty_List
(Freeze_Nodes
) then
1847 Insert_Actions
(N
, Freeze_Nodes
);
1855 function Freeze_Entity
(E
: Entity_Id
; N
: Node_Id
) return List_Id
is
1856 GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
1857 -- Save the current Ghost mode in effect in case the entity being frozen
1858 -- sets a different mode.
1860 Loc
: constant Source_Ptr
:= Sloc
(N
);
1867 Test_E
: Entity_Id
:= E
;
1868 -- This could use a comment ???
1870 Late_Freezing
: Boolean := False;
1871 -- Used to detect attempt to freeze function declared in another unit
1873 Result
: List_Id
:= No_List
;
1874 -- List of freezing actions, left at No_List if none
1876 Has_Default_Initialization
: Boolean := False;
1877 -- This flag gets set to true for a variable with default initialization
1879 procedure Add_To_Result
(N
: Node_Id
);
1880 -- N is a freezing action to be appended to the Result
1882 function After_Last_Declaration
return Boolean;
1883 -- If Loc is a freeze_entity that appears after the last declaration
1884 -- in the scope, inhibit error messages on late completion.
1886 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1887 -- Check that an Access or Unchecked_Access attribute with a prefix
1888 -- which is the current instance type can only be applied when the type
1891 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1892 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1893 -- integer literal without an explicit corresponding size clause. The
1894 -- caller has checked that Utype is a modular integer type.
1896 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
1897 -- Freeze array type, including freezing index and component types
1899 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
1900 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1901 -- package. Recurse on inner generic packages.
1903 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
1904 -- Freeze formals and return type of subprogram. If some type in the
1905 -- profile is a limited view, freezing of the entity will take place
1906 -- elsewhere, and the function returns False. This routine will be
1907 -- modified if and when we can implement AI05-019 efficiently ???
1909 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1910 -- Freeze record type, including freezing component types, and freezing
1911 -- primitive operations if this is a tagged type.
1913 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
1914 -- Determine whether an arbitrary entity is subject to Boolean aspect
1915 -- Import and its value is specified as True.
1917 procedure Late_Freeze_Subprogram
(E
: Entity_Id
);
1918 -- Following AI05-151, a function can return a limited view of a type
1919 -- declared elsewhere. In that case the function cannot be frozen at
1920 -- the end of its enclosing package. If its first use is in a different
1921 -- unit, it cannot be frozen there, but if the call is legal the full
1922 -- view of the return type is available and the subprogram can now be
1923 -- frozen. However the freeze node cannot be inserted at the point of
1924 -- call, but rather must go in the package holding the function, so that
1925 -- the backend can process it in the proper context.
1927 procedure Restore_Globals
;
1928 -- Restore the values of all saved global variables
1930 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
1931 -- If E is an entity for an imported subprogram with pre/post-conditions
1932 -- then this procedure will create a wrapper to ensure that proper run-
1933 -- time checking of the pre/postconditions. See body for details.
1939 procedure Add_To_Result
(N
: Node_Id
) is
1942 Result
:= New_List
(N
);
1948 ----------------------------
1949 -- After_Last_Declaration --
1950 ----------------------------
1952 function After_Last_Declaration
return Boolean is
1953 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
1956 if Nkind
(Spec
) = N_Package_Specification
then
1957 if Present
(Private_Declarations
(Spec
)) then
1958 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1959 elsif Present
(Visible_Declarations
(Spec
)) then
1960 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1968 end After_Last_Declaration
;
1970 ----------------------------
1971 -- Check_Current_Instance --
1972 ----------------------------
1974 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1976 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
1977 -- Determine whether Typ is compatible with the rules for aliased
1978 -- views of types as defined in RM 3.10 in the various dialects.
1980 function Process
(N
: Node_Id
) return Traverse_Result
;
1981 -- Process routine to apply check to given node
1983 -----------------------------
1984 -- Is_Aliased_View_Of_Type --
1985 -----------------------------
1987 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
1988 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
1993 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
1994 and then Limited_Present
(Type_Definition
(Typ_Decl
))
1998 -- The following paragraphs describe what a legal aliased view of
1999 -- a type is in the various dialects of Ada.
2003 -- The current instance of a limited type, and a formal parameter
2004 -- or generic formal object of a tagged type.
2006 -- Ada 95 limited type
2007 -- * Type with reserved word "limited"
2008 -- * A protected or task type
2009 -- * A composite type with limited component
2011 elsif Ada_Version
<= Ada_95
then
2012 return Is_Limited_Type
(Typ
);
2016 -- The current instance of a limited tagged type, a protected
2017 -- type, a task type, or a type that has the reserved word
2018 -- "limited" in its full definition ... a formal parameter or
2019 -- generic formal object of a tagged type.
2021 -- Ada 2005 limited type
2022 -- * Type with reserved word "limited", "synchronized", "task"
2024 -- * A composite type with limited component
2025 -- * A derived type whose parent is a non-interface limited type
2027 elsif Ada_Version
= Ada_2005
then
2029 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2031 (Is_Derived_Type
(Typ
)
2032 and then not Is_Interface
(Etype
(Typ
))
2033 and then Is_Limited_Type
(Etype
(Typ
)));
2035 -- Ada 2012 and beyond
2037 -- The current instance of an immutably limited type ... a formal
2038 -- parameter or generic formal object of a tagged type.
2040 -- Ada 2012 limited type
2041 -- * Type with reserved word "limited", "synchronized", "task"
2043 -- * A composite type with limited component
2044 -- * A derived type whose parent is a non-interface limited type
2045 -- * An incomplete view
2047 -- Ada 2012 immutably limited type
2048 -- * Explicitly limited record type
2049 -- * Record extension with "limited" present
2050 -- * Non-formal limited private type that is either tagged
2051 -- or has at least one access discriminant with a default
2053 -- * Task type, protected type or synchronized interface
2054 -- * Type derived from immutably limited type
2058 Is_Immutably_Limited_Type
(Typ
)
2059 or else Is_Incomplete_Type
(Typ
);
2061 end Is_Aliased_View_Of_Type
;
2067 function Process
(N
: Node_Id
) return Traverse_Result
is
2070 when N_Attribute_Reference
=>
2071 if Nam_In
(Attribute_Name
(N
), Name_Access
,
2072 Name_Unchecked_Access
)
2073 and then Is_Entity_Name
(Prefix
(N
))
2074 and then Is_Type
(Entity
(Prefix
(N
)))
2075 and then Entity
(Prefix
(N
)) = E
2077 if Ada_Version
< Ada_2012
then
2079 ("current instance must be a limited type",
2083 ("current instance must be an immutably limited "
2084 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2093 when others => return OK
;
2097 procedure Traverse
is new Traverse_Proc
(Process
);
2101 Rec_Type
: constant Entity_Id
:=
2102 Scope
(Defining_Identifier
(Comp_Decl
));
2104 -- Start of processing for Check_Current_Instance
2107 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2108 Traverse
(Comp_Decl
);
2110 end Check_Current_Instance
;
2112 ------------------------------
2113 -- Check_Suspicious_Modulus --
2114 ------------------------------
2116 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
2117 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
2120 if not Warn_On_Suspicious_Modulus_Value
then
2124 if Nkind
(Decl
) = N_Full_Type_Declaration
then
2126 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
2129 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
2131 Modulus
: constant Node_Id
:=
2132 Original_Node
(Expression
(Tdef
));
2135 if Nkind
(Modulus
) = N_Integer_Literal
then
2137 Modv
: constant Uint
:= Intval
(Modulus
);
2138 Sizv
: constant Uint
:= RM_Size
(Utype
);
2141 -- First case, modulus and size are the same. This
2142 -- happens if you have something like mod 32, with
2143 -- an explicit size of 32, this is for sure a case
2144 -- where the warning is given, since it is seems
2145 -- very unlikely that someone would want e.g. a
2146 -- five bit type stored in 32 bits. It is much
2147 -- more likely they wanted a 32-bit type.
2152 -- Second case, the modulus is 32 or 64 and no
2153 -- size clause is present. This is a less clear
2154 -- case for giving the warning, but in the case
2155 -- of 32/64 (5-bit or 6-bit types) these seem rare
2156 -- enough that it is a likely error (and in any
2157 -- case using 2**5 or 2**6 in these cases seems
2158 -- clearer. We don't include 8 or 16 here, simply
2159 -- because in practice 3-bit and 4-bit types are
2160 -- more common and too many false positives if
2161 -- we warn in these cases.
2163 elsif not Has_Size_Clause
(Utype
)
2164 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
2168 -- No warning needed
2174 -- If we fall through, give warning
2176 Error_Msg_Uint_1
:= Modv
;
2178 ("?M?2 '*'*^' may have been intended here",
2186 end Check_Suspicious_Modulus
;
2188 -----------------------
2189 -- Freeze_Array_Type --
2190 -----------------------
2192 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2193 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2194 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2197 Non_Standard_Enum
: Boolean := False;
2198 -- Set true if any of the index types is an enumeration type with a
2199 -- non-standard representation.
2202 Freeze_And_Append
(Ctyp
, N
, Result
);
2204 Indx
:= First_Index
(Arr
);
2205 while Present
(Indx
) loop
2206 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2208 if Is_Enumeration_Type
(Etype
(Indx
))
2209 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2211 Non_Standard_Enum
:= True;
2217 -- Processing that is done only for base types
2219 if Ekind
(Arr
) = E_Array_Type
then
2221 -- Deal with default setting of reverse storage order
2223 Set_SSO_From_Default
(Arr
);
2225 -- Propagate flags for component type
2227 if Is_Controlled
(Component_Type
(Arr
))
2228 or else Has_Controlled_Component
(Ctyp
)
2230 Set_Has_Controlled_Component
(Arr
);
2233 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2234 Set_Has_Unchecked_Union
(Arr
);
2237 -- Warn for pragma Pack overriding foreign convention
2239 if Has_Foreign_Convention
(Ctyp
)
2240 and then Has_Pragma_Pack
(Arr
)
2243 CN
: constant Name_Id
:=
2244 Get_Convention_Name
(Convention
(Ctyp
));
2245 PP
: constant Node_Id
:=
2246 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2248 if Present
(PP
) then
2249 Error_Msg_Name_1
:= CN
;
2250 Error_Msg_Sloc
:= Sloc
(Arr
);
2252 ("pragma Pack affects convention % components #??", PP
);
2253 Error_Msg_Name_1
:= CN
;
2255 ("\array components may not have % compatible "
2256 & "representation??", PP
);
2261 -- If packing was requested or if the component size was
2262 -- set explicitly, then see if bit packing is required. This
2263 -- processing is only done for base types, since all of the
2264 -- representation aspects involved are type-related.
2266 -- This is not just an optimization, if we start processing the
2267 -- subtypes, they interfere with the settings on the base type
2268 -- (this is because Is_Packed has a slightly different meaning
2269 -- before and after freezing).
2276 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2277 and then Known_Static_RM_Size
(Ctyp
)
2278 and then not Has_Component_Size_Clause
(Arr
)
2280 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2282 elsif Known_Component_Size
(Arr
) then
2283 Csiz
:= Component_Size
(Arr
);
2285 elsif not Known_Static_Esize
(Ctyp
) then
2289 Esiz
:= Esize
(Ctyp
);
2291 -- We can set the component size if it is less than 16,
2292 -- rounding it up to the next storage unit size.
2296 elsif Esiz
<= 16 then
2302 -- Set component size up to match alignment if it would
2303 -- otherwise be less than the alignment. This deals with
2304 -- cases of types whose alignment exceeds their size (the
2305 -- padded type cases).
2309 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2318 -- Case of component size that may result in packing
2320 if 1 <= Csiz
and then Csiz
<= 64 then
2322 Ent
: constant Entity_Id
:=
2323 First_Subtype
(Arr
);
2324 Pack_Pragma
: constant Node_Id
:=
2325 Get_Rep_Pragma
(Ent
, Name_Pack
);
2326 Comp_Size_C
: constant Node_Id
:=
2327 Get_Attribute_Definition_Clause
2328 (Ent
, Attribute_Component_Size
);
2331 -- Warn if we have pack and component size so that the
2334 -- Note: here we must check for the presence of a
2335 -- component size before checking for a Pack pragma to
2336 -- deal with the case where the array type is a derived
2337 -- type whose parent is currently private.
2339 if Present
(Comp_Size_C
)
2340 and then Has_Pragma_Pack
(Ent
)
2341 and then Warn_On_Redundant_Constructs
2343 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2345 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2347 ("\?r?explicit component size given#!", Pack_Pragma
);
2348 Set_Is_Packed
(Base_Type
(Ent
), False);
2349 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2352 -- Set component size if not already set by a component
2355 if not Present
(Comp_Size_C
) then
2356 Set_Component_Size
(Arr
, Csiz
);
2359 -- Check for base type of 8, 16, 32 bits, where an
2360 -- unsigned subtype has a length one less than the
2361 -- base type (e.g. Natural subtype of Integer).
2363 -- In such cases, if a component size was not set
2364 -- explicitly, then generate a warning.
2366 if Has_Pragma_Pack
(Arr
)
2367 and then not Present
(Comp_Size_C
)
2368 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2369 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2371 Error_Msg_Uint_1
:= Csiz
;
2373 if Present
(Pack_Pragma
) then
2375 ("??pragma Pack causes component size to be ^!",
2378 ("\??use Component_Size to set desired value!",
2383 -- Actual packing is not needed for 8, 16, 32, 64. Also
2384 -- not needed for 24 if alignment is 1.
2390 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
2392 -- Here the array was requested to be packed, but
2393 -- the packing request had no effect, so Is_Packed
2396 -- Note: semantically this means that we lose track
2397 -- of the fact that a derived type inherited a pragma
2398 -- Pack that was non- effective, but that seems fine.
2400 -- We regard a Pack pragma as a request to set a
2401 -- representation characteristic, and this request
2404 Set_Is_Packed
(Base_Type
(Arr
), False);
2405 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2407 if Known_Static_Esize
(Component_Type
(Arr
))
2408 and then Esize
(Component_Type
(Arr
)) = Csiz
2410 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
2413 -- In all other cases, packing is indeed needed
2416 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2417 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2418 Set_Is_Packed
(Base_Type
(Arr
), True);
2424 -- Check for Aliased or Atomic_Components/Atomic with unsuitable
2425 -- packing or explicit component size clause given.
2427 if (Has_Aliased_Components
(Arr
)
2428 or else Has_Atomic_Components
(Arr
)
2429 or else Is_Atomic
(Ctyp
))
2431 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2433 Alias_Atomic_Check
: declare
2435 procedure Complain_CS
(T
: String);
2436 -- Outputs error messages for incorrect CS clause or pragma
2437 -- Pack for aliased or atomic components (T is "aliased" or
2444 procedure Complain_CS
(T
: String) is
2446 if Has_Component_Size_Clause
(Arr
) then
2448 Get_Attribute_Definition_Clause
2449 (FS
, Attribute_Component_Size
);
2452 ("incorrect component size for "
2453 & T
& " components", Clause
);
2454 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2456 ("\only allowed value is^", Clause
);
2460 ("cannot pack " & T
& " components",
2461 Get_Rep_Pragma
(FS
, Name_Pack
));
2465 -- Start of processing for Alias_Atomic_Check
2468 -- If object size of component type isn't known, we cannot
2469 -- be sure so we defer to the back end.
2471 if not Known_Static_Esize
(Ctyp
) then
2474 -- Case where component size has no effect. First check for
2475 -- object size of component type multiple of the storage
2478 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2480 -- OK in both packing case and component size case if RM
2481 -- size is known and static and same as the object size.
2484 ((Known_Static_RM_Size
(Ctyp
)
2485 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2487 -- Or if we have an explicit component size clause and
2488 -- the component size and object size are equal.
2491 (Has_Component_Size_Clause
(Arr
)
2492 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2496 elsif Has_Aliased_Components
(Arr
) then
2497 Complain_CS
("aliased");
2499 elsif Has_Atomic_Components
(Arr
) or else Is_Atomic
(Ctyp
)
2501 Complain_CS
("atomic");
2503 end Alias_Atomic_Check
;
2506 -- Check for Independent_Components/Independent with unsuitable
2507 -- packing or explicit component size clause given.
2509 if (Has_Independent_Components
(Arr
) or else Is_Independent
(Ctyp
))
2511 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2514 -- If object size of component type isn't known, we cannot
2515 -- be sure so we defer to the back end.
2517 if not Known_Static_Esize
(Ctyp
) then
2520 -- Case where component size has no effect. First check for
2521 -- object size of component type multiple of the storage
2524 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2526 -- OK in both packing case and component size case if RM
2527 -- size is known and multiple of the storage unit size.
2530 ((Known_Static_RM_Size
(Ctyp
)
2531 and then RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
2533 -- Or if we have an explicit component size clause and
2534 -- the component size is larger than the object size.
2537 (Has_Component_Size_Clause
(Arr
)
2538 and then Component_Size
(Arr
) >= Esize
(Ctyp
)))
2543 if Has_Component_Size_Clause
(Arr
) then
2545 Get_Attribute_Definition_Clause
2546 (FS
, Attribute_Component_Size
);
2549 ("incorrect component size for "
2550 & "independent components", Clause
);
2551 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2553 ("\minimum allowed is^", Clause
);
2557 ("cannot pack independent components",
2558 Get_Rep_Pragma
(FS
, Name_Pack
));
2564 -- Warn for case of atomic type
2566 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2569 and then not Addressable
(Component_Size
(FS
))
2572 ("non-atomic components of type& may not be "
2573 & "accessible by separate tasks??", Clause
, Arr
);
2575 if Has_Component_Size_Clause
(Arr
) then
2576 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2577 (FS
, Attribute_Component_Size
));
2578 Error_Msg_N
("\because of component size clause#??", Clause
);
2580 elsif Has_Pragma_Pack
(Arr
) then
2581 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2582 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2586 -- Check for scalar storage order
2591 Check_Component_Storage_Order
2594 ADC
=> Get_Attribute_Definition_Clause
2595 (First_Subtype
(Arr
),
2596 Attribute_Scalar_Storage_Order
),
2597 Comp_ADC_Present
=> Dummy
);
2600 -- Processing that is done only for subtypes
2603 -- Acquire alignment from base type
2605 if Unknown_Alignment
(Arr
) then
2606 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2607 Adjust_Esize_Alignment
(Arr
);
2611 -- Specific checks for bit-packed arrays
2613 if Is_Bit_Packed_Array
(Arr
) then
2615 -- Check number of elements for bit packed arrays that come from
2616 -- source and have compile time known ranges. The bit-packed
2617 -- arrays circuitry does not support arrays with more than
2618 -- Integer'Last + 1 elements, and when this restriction is
2619 -- violated, causes incorrect data access.
2621 -- For the case where this is not compile time known, a run-time
2622 -- check should be generated???
2624 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
2633 Index
:= First_Index
(Arr
);
2634 while Present
(Index
) loop
2635 Ityp
:= Etype
(Index
);
2637 -- Never generate an error if any index is of a generic
2638 -- type. We will check this in instances.
2640 if Is_Generic_Type
(Ityp
) then
2646 Make_Attribute_Reference
(Loc
,
2647 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2648 Attribute_Name
=> Name_Range_Length
);
2649 Analyze_And_Resolve
(Ilen
);
2651 -- No attempt is made to check number of elements if not
2652 -- compile time known.
2654 if Nkind
(Ilen
) /= N_Integer_Literal
then
2659 Elmts
:= Elmts
* Intval
(Ilen
);
2663 if Elmts
> Intval
(High_Bound
2664 (Scalar_Range
(Standard_Integer
))) + 1
2667 ("bit packed array type may not have "
2668 & "more than Integer''Last+1 elements", Arr
);
2675 if Known_RM_Size
(Arr
) then
2677 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
2681 -- It is not clear if it is possible to have no size clause
2682 -- at this stage, but it is not worth worrying about. Post
2683 -- error on the entity name in the size clause if present,
2684 -- else on the type entity itself.
2686 if Present
(SizC
) then
2687 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
2689 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
2695 -- If any of the index types was an enumeration type with a non-
2696 -- standard rep clause, then we indicate that the array type is
2697 -- always packed (even if it is not bit packed).
2699 if Non_Standard_Enum
then
2700 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
2701 Set_Is_Packed
(Base_Type
(Arr
));
2704 Set_Component_Alignment_If_Not_Set
(Arr
);
2706 -- If the array is packed, we must create the packed array type to be
2707 -- used to actually implement the type. This is only needed for real
2708 -- array types (not for string literal types, since they are present
2709 -- only for the front end).
2712 and then Ekind
(Arr
) /= E_String_Literal_Subtype
2714 Create_Packed_Array_Impl_Type
(Arr
);
2715 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
2717 -- Make sure that we have the necessary routines to implement the
2718 -- packing, and complain now if not. Note that we only test this
2719 -- for constrained array types.
2721 if Is_Constrained
(Arr
)
2722 and then Is_Bit_Packed_Array
(Arr
)
2723 and then Present
(Packed_Array_Impl_Type
(Arr
))
2724 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
2727 CS
: constant Uint
:= Component_Size
(Arr
);
2728 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
2732 and then not RTE_Available
(RE
)
2735 ("packing of " & UI_Image
(CS
) & "-bit components",
2736 First_Subtype
(Etype
(Arr
)));
2738 -- Cancel the packing
2740 Set_Is_Packed
(Base_Type
(Arr
), False);
2741 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2742 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
2748 -- Size information of packed array type is copied to the array
2749 -- type, since this is really the representation. But do not
2750 -- override explicit existing size values. If the ancestor subtype
2751 -- is constrained the Packed_Array_Impl_Type will be inherited
2752 -- from it, but the size may have been provided already, and
2753 -- must not be overridden either.
2755 if not Has_Size_Clause
(Arr
)
2757 (No
(Ancestor_Subtype
(Arr
))
2758 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
2760 Set_Esize
(Arr
, Esize
(Packed_Array_Impl_Type
(Arr
)));
2761 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Impl_Type
(Arr
)));
2764 if not Has_Alignment_Clause
(Arr
) then
2765 Set_Alignment
(Arr
, Alignment
(Packed_Array_Impl_Type
(Arr
)));
2771 -- For non-packed arrays set the alignment of the array to the
2772 -- alignment of the component type if it is unknown. Skip this
2773 -- in atomic case (atomic arrays may need larger alignments).
2775 if not Is_Packed
(Arr
)
2776 and then Unknown_Alignment
(Arr
)
2777 and then Known_Alignment
(Ctyp
)
2778 and then Known_Static_Component_Size
(Arr
)
2779 and then Known_Static_Esize
(Ctyp
)
2780 and then Esize
(Ctyp
) = Component_Size
(Arr
)
2781 and then not Is_Atomic
(Arr
)
2783 Set_Alignment
(Arr
, Alignment
(Component_Type
(Arr
)));
2785 end Freeze_Array_Type
;
2787 -----------------------------
2788 -- Freeze_Generic_Entities --
2789 -----------------------------
2791 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
2798 E
:= First_Entity
(Pack
);
2799 while Present
(E
) loop
2800 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
2801 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
2803 Append_To
(Flist
, F
);
2805 elsif Ekind
(E
) = E_Generic_Package
then
2806 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
2813 end Freeze_Generic_Entities
;
2815 --------------------
2816 -- Freeze_Profile --
2817 --------------------
2819 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
2822 Warn_Node
: Node_Id
;
2825 -- Loop through formals
2827 Formal
:= First_Formal
(E
);
2828 while Present
(Formal
) loop
2829 F_Type
:= Etype
(Formal
);
2831 -- AI05-0151: incomplete types can appear in a profile. By the
2832 -- time the entity is frozen, the full view must be available,
2833 -- unless it is a limited view.
2835 if Is_Incomplete_Type
(F_Type
)
2836 and then Present
(Full_View
(F_Type
))
2837 and then not From_Limited_With
(F_Type
)
2839 F_Type
:= Full_View
(F_Type
);
2840 Set_Etype
(Formal
, F_Type
);
2843 Freeze_And_Append
(F_Type
, N
, Result
);
2845 if Is_Private_Type
(F_Type
)
2846 and then Is_Private_Type
(Base_Type
(F_Type
))
2847 and then No
(Full_View
(Base_Type
(F_Type
)))
2848 and then not Is_Generic_Type
(F_Type
)
2849 and then not Is_Derived_Type
(F_Type
)
2851 -- If the type of a formal is incomplete, subprogram is being
2852 -- frozen prematurely. Within an instance (but not within a
2853 -- wrapper package) this is an artifact of our need to regard
2854 -- the end of an instantiation as a freeze point. Otherwise it
2855 -- is a definite error.
2858 Set_Is_Frozen
(E
, False);
2862 elsif not After_Last_Declaration
2863 and then not Freezing_Library_Level_Tagged_Type
2865 Error_Msg_Node_1
:= F_Type
;
2867 ("type & must be fully defined before this point", Loc
);
2871 -- Check suspicious parameter for C function. These tests apply
2872 -- only to exported/imported subprograms.
2874 if Warn_On_Export_Import
2875 and then Comes_From_Source
(E
)
2876 and then (Convention
(E
) = Convention_C
2878 Convention
(E
) = Convention_CPP
)
2879 and then (Is_Imported
(E
) or else Is_Exported
(E
))
2880 and then Convention
(E
) /= Convention
(Formal
)
2881 and then not Has_Warnings_Off
(E
)
2882 and then not Has_Warnings_Off
(F_Type
)
2883 and then not Has_Warnings_Off
(Formal
)
2885 -- Qualify mention of formals with subprogram name
2887 Error_Msg_Qual_Level
:= 1;
2889 -- Check suspicious use of fat C pointer
2891 if Is_Access_Type
(F_Type
)
2892 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
2895 ("?x?type of & does not correspond to C pointer!", Formal
);
2897 -- Check suspicious return of boolean
2899 elsif Root_Type
(F_Type
) = Standard_Boolean
2900 and then Convention
(F_Type
) = Convention_Ada
2901 and then not Has_Warnings_Off
(F_Type
)
2902 and then not Has_Size_Clause
(F_Type
)
2903 and then VM_Target
= No_VM
2906 ("& is an 8-bit Ada Boolean?x?", Formal
);
2908 ("\use appropriate corresponding type in C "
2909 & "(e.g. char)?x?", Formal
);
2911 -- Check suspicious tagged type
2913 elsif (Is_Tagged_Type
(F_Type
)
2915 (Is_Access_Type
(F_Type
)
2916 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
2917 and then Convention
(E
) = Convention_C
2920 ("?x?& involves a tagged type which does not "
2921 & "correspond to any C type!", Formal
);
2923 -- Check wrong convention subprogram pointer
2925 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
2926 and then not Has_Foreign_Convention
(F_Type
)
2929 ("?x?subprogram pointer & should "
2930 & "have foreign convention!", Formal
);
2931 Error_Msg_Sloc
:= Sloc
(F_Type
);
2933 ("\?x?add Convention pragma to declaration of &#",
2937 -- Turn off name qualification after message output
2939 Error_Msg_Qual_Level
:= 0;
2942 -- Check for unconstrained array in exported foreign convention
2945 if Has_Foreign_Convention
(E
)
2946 and then not Is_Imported
(E
)
2947 and then Is_Array_Type
(F_Type
)
2948 and then not Is_Constrained
(F_Type
)
2949 and then Warn_On_Export_Import
2951 -- Exclude VM case, since both .NET and JVM can handle
2952 -- unconstrained arrays without a problem.
2954 and then VM_Target
= No_VM
2956 Error_Msg_Qual_Level
:= 1;
2958 -- If this is an inherited operation, place the warning on
2959 -- the derived type declaration, rather than on the original
2962 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
2964 Warn_Node
:= Parent
(E
);
2966 if Formal
= First_Formal
(E
) then
2967 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
2970 Warn_Node
:= Formal
;
2973 Error_Msg_NE
("?x?type of argument& is unconstrained array",
2975 Error_Msg_NE
("?x?foreign caller must pass bounds explicitly",
2977 Error_Msg_Qual_Level
:= 0;
2980 if not From_Limited_With
(F_Type
) then
2981 if Is_Access_Type
(F_Type
) then
2982 F_Type
:= Designated_Type
(F_Type
);
2985 -- If the formal is an anonymous_access_to_subprogram
2986 -- freeze the subprogram type as well, to prevent
2987 -- scope anomalies in gigi, because there is no other
2988 -- clear point at which it could be frozen.
2990 if Is_Itype
(Etype
(Formal
))
2991 and then Ekind
(F_Type
) = E_Subprogram_Type
2993 Freeze_And_Append
(F_Type
, N
, Result
);
2997 Next_Formal
(Formal
);
3000 -- Case of function: similar checks on return type
3002 if Ekind
(E
) = E_Function
then
3004 -- Check whether function is declared elsewhere.
3007 Get_Source_Unit
(E
) /= Get_Source_Unit
(N
)
3008 and then Returns_Limited_View
(E
)
3009 and then not In_Open_Scopes
(Scope
(E
));
3011 -- Freeze return type
3013 R_Type
:= Etype
(E
);
3015 -- AI05-0151: the return type may have been incomplete
3016 -- at the point of declaration. Replace it with the full
3017 -- view, unless the current type is a limited view. In
3018 -- that case the full view is in a different unit, and
3019 -- gigi finds the non-limited view after the other unit
3022 if Ekind
(R_Type
) = E_Incomplete_Type
3023 and then Present
(Full_View
(R_Type
))
3024 and then not From_Limited_With
(R_Type
)
3026 R_Type
:= Full_View
(R_Type
);
3027 Set_Etype
(E
, R_Type
);
3029 -- If the return type is a limited view and the non-
3030 -- limited view is still incomplete, the function has
3031 -- to be frozen at a later time.
3033 elsif Ekind
(R_Type
) = E_Incomplete_Type
3034 and then From_Limited_With
(R_Type
)
3036 Ekind
(Non_Limited_View
(R_Type
)) = E_Incomplete_Type
3038 Set_Is_Frozen
(E
, False);
3039 Set_Returns_Limited_View
(E
);
3043 Freeze_And_Append
(R_Type
, N
, Result
);
3045 -- Check suspicious return type for C function
3047 if Warn_On_Export_Import
3048 and then (Convention
(E
) = Convention_C
3050 Convention
(E
) = Convention_CPP
)
3051 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3053 -- Check suspicious return of fat C pointer
3055 if Is_Access_Type
(R_Type
)
3056 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
3057 and then not Has_Warnings_Off
(E
)
3058 and then not Has_Warnings_Off
(R_Type
)
3060 Error_Msg_N
("?x?return type of& does not "
3061 & "correspond to C pointer!", E
);
3063 -- Check suspicious return of boolean
3065 elsif Root_Type
(R_Type
) = Standard_Boolean
3066 and then Convention
(R_Type
) = Convention_Ada
3067 and then VM_Target
= No_VM
3068 and then not Has_Warnings_Off
(E
)
3069 and then not Has_Warnings_Off
(R_Type
)
3070 and then not Has_Size_Clause
(R_Type
)
3073 N
: constant Node_Id
:=
3074 Result_Definition
(Declaration_Node
(E
));
3077 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
3079 ("\use appropriate corresponding type in C "
3080 & "(e.g. char)?x?", N
, E
);
3083 -- Check suspicious return tagged type
3085 elsif (Is_Tagged_Type
(R_Type
)
3086 or else (Is_Access_Type
(R_Type
)
3089 (Designated_Type
(R_Type
))))
3090 and then Convention
(E
) = Convention_C
3091 and then not Has_Warnings_Off
(E
)
3092 and then not Has_Warnings_Off
(R_Type
)
3094 Error_Msg_N
("?x?return type of & does not "
3095 & "correspond to C type!", E
);
3097 -- Check return of wrong convention subprogram pointer
3099 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3100 and then not Has_Foreign_Convention
(R_Type
)
3101 and then not Has_Warnings_Off
(E
)
3102 and then not Has_Warnings_Off
(R_Type
)
3104 Error_Msg_N
("?x?& should return a foreign "
3105 & "convention subprogram pointer", E
);
3106 Error_Msg_Sloc
:= Sloc
(R_Type
);
3108 ("\?x?add Convention pragma to declaration of& #",
3113 -- Give warning for suspicious return of a result of an
3114 -- unconstrained array type in a foreign convention function.
3116 if Has_Foreign_Convention
(E
)
3118 -- We are looking for a return of unconstrained array
3120 and then Is_Array_Type
(R_Type
)
3121 and then not Is_Constrained
(R_Type
)
3123 -- Exclude imported routines, the warning does not belong on
3124 -- the import, but rather on the routine definition.
3126 and then not Is_Imported
(E
)
3128 -- Exclude VM case, since both .NET and JVM can handle return
3129 -- of unconstrained arrays without a problem.
3131 and then VM_Target
= No_VM
3133 -- Check that general warning is enabled, and that it is not
3134 -- suppressed for this particular case.
3136 and then Warn_On_Export_Import
3137 and then not Has_Warnings_Off
(E
)
3138 and then not Has_Warnings_Off
(R_Type
)
3140 Error_Msg_N
("?x?foreign convention function& should not " &
3141 "return unconstrained array!", E
);
3145 -- Check suspicious use of Import in pure unit
3147 if Is_Imported
(E
) and then Is_Pure
(Cunit_Entity
(Current_Sem_Unit
))
3149 -- Ignore internally generated entity. This happens in some cases
3150 -- of subprograms in specs, where we generate an implied body.
3152 and then Comes_From_Source
(Import_Pragma
(E
))
3154 -- Assume run-time knows what it is doing
3156 and then not GNAT_Mode
3158 -- Assume explicit Pure_Function means import is pure
3160 and then not Has_Pragma_Pure_Function
(E
)
3162 -- Don't need warning in relaxed semantics mode
3164 and then not Relaxed_RM_Semantics
3166 -- Assume convention Intrinsic is OK, since this is specialized.
3167 -- This deals with the DEC unit current_exception.ads
3169 and then Convention
(E
) /= Convention_Intrinsic
3171 -- Assume that ASM interface knows what it is doing. This deals
3172 -- with unsigned.ads in the AAMP back end.
3174 and then Convention
(E
) /= Convention_Assembler
3177 ("pragma Import in Pure unit??", Import_Pragma
(E
));
3179 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
3180 Import_Pragma
(E
), E
);
3186 ------------------------
3187 -- Freeze_Record_Type --
3188 ------------------------
3190 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
3197 pragma Warnings
(Off
, Junk
);
3199 Rec_Pushed
: Boolean := False;
3200 -- Set True if the record type scope Rec has been pushed on the scope
3201 -- stack. Needed for the analysis of delayed aspects specified to the
3202 -- components of Rec.
3205 -- Scalar_Storage_Order attribute definition clause for the record
3207 Unplaced_Component
: Boolean := False;
3208 -- Set True if we find at least one component with no component
3209 -- clause (used to warn about useless Pack pragmas).
3211 Placed_Component
: Boolean := False;
3212 -- Set True if we find at least one component with a component
3213 -- clause (used to warn about useless Bit_Order pragmas, and also
3214 -- to detect cases where Implicit_Packing may have an effect).
3216 Aliased_Component
: Boolean := False;
3217 -- Set True if we find at least one component which is aliased. This
3218 -- is used to prevent Implicit_Packing of the record, since packing
3219 -- cannot modify the size of alignment of an aliased component.
3221 SSO_ADC_Component
: Boolean := False;
3222 -- Set True if we find at least one component whose type has a
3223 -- Scalar_Storage_Order attribute definition clause.
3225 All_Scalar_Components
: Boolean := True;
3226 -- Set False if we encounter a component of a non-scalar type
3228 Scalar_Component_Total_RM_Size
: Uint
:= Uint_0
;
3229 Scalar_Component_Total_Esize
: Uint
:= Uint_0
;
3230 -- Accumulates total RM_Size values and total Esize values of all
3231 -- scalar components. Used for processing of Implicit_Packing.
3233 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
3234 -- If N is an allocator, possibly wrapped in one or more level of
3235 -- qualified expression(s), return the inner allocator node, else
3238 procedure Check_Itype
(Typ
: Entity_Id
);
3239 -- If the component subtype is an access to a constrained subtype of
3240 -- an already frozen type, make the subtype frozen as well. It might
3241 -- otherwise be frozen in the wrong scope, and a freeze node on
3242 -- subtype has no effect. Similarly, if the component subtype is a
3243 -- regular (not protected) access to subprogram, set the anonymous
3244 -- subprogram type to frozen as well, to prevent an out-of-scope
3245 -- freeze node at some eventual point of call. Protected operations
3246 -- are handled elsewhere.
3248 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
3249 -- Make sure that all types mentioned in Discrete_Choices of the
3250 -- variants referenceed by the Variant_Part VP are frozen. This is
3251 -- a recursive routine to deal with nested variants.
3253 ---------------------
3254 -- Check_Allocator --
3255 ---------------------
3257 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
3262 if Nkind
(Inner
) = N_Allocator
then
3264 elsif Nkind
(Inner
) = N_Qualified_Expression
then
3265 Inner
:= Expression
(Inner
);
3270 end Check_Allocator
;
3276 procedure Check_Itype
(Typ
: Entity_Id
) is
3277 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
3280 if not Is_Frozen
(Desig
)
3281 and then Is_Frozen
(Base_Type
(Desig
))
3283 Set_Is_Frozen
(Desig
);
3285 -- In addition, add an Itype_Reference to ensure that the
3286 -- access subtype is elaborated early enough. This cannot be
3287 -- done if the subtype may depend on discriminants.
3289 if Ekind
(Comp
) = E_Component
3290 and then Is_Itype
(Etype
(Comp
))
3291 and then not Has_Discriminants
(Rec
)
3293 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
3294 Set_Itype
(IR
, Desig
);
3298 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
3299 and then Convention
(Desig
) /= Convention_Protected
3301 Set_Is_Frozen
(Desig
);
3305 ------------------------------------
3306 -- Freeze_Choices_In_Variant_Part --
3307 ------------------------------------
3309 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
3310 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
3317 -- Loop through variants
3319 Variant
:= First_Non_Pragma
(Variants
(VP
));
3320 while Present
(Variant
) loop
3322 -- Loop through choices, checking that all types are frozen
3324 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
3325 while Present
(Choice
) loop
3326 if Nkind
(Choice
) in N_Has_Etype
3327 and then Present
(Etype
(Choice
))
3329 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
3332 Next_Non_Pragma
(Choice
);
3335 -- Check for nested variant part to process
3337 CL
:= Component_List
(Variant
);
3339 if not Null_Present
(CL
) then
3340 if Present
(Variant_Part
(CL
)) then
3341 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
3345 Next_Non_Pragma
(Variant
);
3347 end Freeze_Choices_In_Variant_Part
;
3349 -- Start of processing for Freeze_Record_Type
3352 -- Deal with delayed aspect specifications for components. The
3353 -- analysis of the aspect is required to be delayed to the freeze
3354 -- point, thus we analyze the pragma or attribute definition
3355 -- clause in the tree at this point. We also analyze the aspect
3356 -- specification node at the freeze point when the aspect doesn't
3357 -- correspond to pragma/attribute definition clause.
3359 Comp
:= First_Entity
(Rec
);
3360 while Present
(Comp
) loop
3361 if Ekind
(Comp
) = E_Component
3362 and then Has_Delayed_Aspects
(Comp
)
3364 if not Rec_Pushed
then
3368 -- The visibility to the discriminants must be restored in
3369 -- order to properly analyze the aspects.
3371 if Has_Discriminants
(Rec
) then
3372 Install_Discriminants
(Rec
);
3376 Analyze_Aspects_At_Freeze_Point
(Comp
);
3382 -- Pop the scope if Rec scope has been pushed on the scope stack
3383 -- during the delayed aspect analysis process.
3386 if Has_Discriminants
(Rec
) then
3387 Uninstall_Discriminants
(Rec
);
3393 -- Freeze components and embedded subtypes
3395 Comp
:= First_Entity
(Rec
);
3397 while Present
(Comp
) loop
3398 if Is_Aliased
(Comp
) then
3399 Aliased_Component
:= True;
3402 -- Handle the component and discriminant case
3404 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
3406 CC
: constant Node_Id
:= Component_Clause
(Comp
);
3409 -- Freezing a record type freezes the type of each of its
3410 -- components. However, if the type of the component is
3411 -- part of this record, we do not want or need a separate
3412 -- Freeze_Node. Note that Is_Itype is wrong because that's
3413 -- also set in private type cases. We also can't check for
3414 -- the Scope being exactly Rec because of private types and
3415 -- record extensions.
3417 if Is_Itype
(Etype
(Comp
))
3418 and then Is_Record_Type
(Underlying_Type
3419 (Scope
(Etype
(Comp
))))
3421 Undelay_Type
(Etype
(Comp
));
3424 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
3426 -- Warn for pragma Pack overriding foreign convention
3428 if Has_Foreign_Convention
(Etype
(Comp
))
3429 and then Has_Pragma_Pack
(Rec
)
3431 -- Don't warn for aliased components, since override
3432 -- cannot happen in that case.
3434 and then not Is_Aliased
(Comp
)
3437 CN
: constant Name_Id
:=
3438 Get_Convention_Name
(Convention
(Etype
(Comp
)));
3439 PP
: constant Node_Id
:=
3440 Get_Pragma
(Rec
, Pragma_Pack
);
3442 if Present
(PP
) then
3443 Error_Msg_Name_1
:= CN
;
3444 Error_Msg_Sloc
:= Sloc
(Comp
);
3446 ("pragma Pack affects convention % component#??",
3448 Error_Msg_Name_1
:= CN
;
3450 ("\component & may not have % compatible "
3451 & "representation??", PP
, Comp
);
3456 -- Check for error of component clause given for variable
3457 -- sized type. We have to delay this test till this point,
3458 -- since the component type has to be frozen for us to know
3459 -- if it is variable length.
3461 if Present
(CC
) then
3462 Placed_Component
:= True;
3464 -- We omit this test in a generic context, it will be
3465 -- applied at instantiation time.
3467 if Inside_A_Generic
then
3470 -- Also omit this test in CodePeer mode, since we do not
3471 -- have sufficient info on size and rep clauses.
3473 elsif CodePeer_Mode
then
3476 -- Omit check if component has a generic type. This can
3477 -- happen in an instantiation within a generic in ASIS
3478 -- mode, where we force freeze actions without full
3481 elsif Is_Generic_Type
(Etype
(Comp
)) then
3487 Size_Known_At_Compile_Time
3488 (Underlying_Type
(Etype
(Comp
)))
3491 ("component clause not allowed for variable " &
3492 "length component", CC
);
3496 Unplaced_Component
:= True;
3499 -- Case of component requires byte alignment
3501 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
3503 -- Set the enclosing record to also require byte align
3505 Set_Must_Be_On_Byte_Boundary
(Rec
);
3507 -- Check for component clause that is inconsistent with
3508 -- the required byte boundary alignment.
3511 and then Normalized_First_Bit
(Comp
) mod
3512 System_Storage_Unit
/= 0
3515 ("component & must be byte aligned",
3516 Component_Name
(Component_Clause
(Comp
)));
3522 -- Gather data for possible Implicit_Packing later. Note that at
3523 -- this stage we might be dealing with a real component, or with
3524 -- an implicit subtype declaration.
3526 if not Is_Scalar_Type
(Etype
(Comp
)) then
3527 All_Scalar_Components
:= False;
3529 Scalar_Component_Total_RM_Size
:=
3530 Scalar_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
3531 Scalar_Component_Total_Esize
:=
3532 Scalar_Component_Total_Esize
+ Esize
(Etype
(Comp
));
3535 -- If the component is an Itype with Delayed_Freeze and is either
3536 -- a record or array subtype and its base type has not yet been
3537 -- frozen, we must remove this from the entity list of this record
3538 -- and put it on the entity list of the scope of its base type.
3539 -- Note that we know that this is not the type of a component
3540 -- since we cleared Has_Delayed_Freeze for it in the previous
3541 -- loop. Thus this must be the Designated_Type of an access type,
3542 -- which is the type of a component.
3545 and then Is_Type
(Scope
(Comp
))
3546 and then Is_Composite_Type
(Comp
)
3547 and then Base_Type
(Comp
) /= Comp
3548 and then Has_Delayed_Freeze
(Comp
)
3549 and then not Is_Frozen
(Base_Type
(Comp
))
3552 Will_Be_Frozen
: Boolean := False;
3556 -- We have a difficult case to handle here. Suppose Rec is
3557 -- subtype being defined in a subprogram that's created as
3558 -- part of the freezing of Rec'Base. In that case, we know
3559 -- that Comp'Base must have already been frozen by the time
3560 -- we get to elaborate this because Gigi doesn't elaborate
3561 -- any bodies until it has elaborated all of the declarative
3562 -- part. But Is_Frozen will not be set at this point because
3563 -- we are processing code in lexical order.
3565 -- We detect this case by going up the Scope chain of Rec
3566 -- and seeing if we have a subprogram scope before reaching
3567 -- the top of the scope chain or that of Comp'Base. If we
3568 -- do, then mark that Comp'Base will actually be frozen. If
3569 -- so, we merely undelay it.
3572 while Present
(S
) loop
3573 if Is_Subprogram
(S
) then
3574 Will_Be_Frozen
:= True;
3576 elsif S
= Scope
(Base_Type
(Comp
)) then
3583 if Will_Be_Frozen
then
3584 Undelay_Type
(Comp
);
3587 if Present
(Prev
) then
3588 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
3590 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
3593 -- Insert in entity list of scope of base type (which
3594 -- must be an enclosing scope, because still unfrozen).
3596 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
3600 -- If the component is an access type with an allocator as default
3601 -- value, the designated type will be frozen by the corresponding
3602 -- expression in init_proc. In order to place the freeze node for
3603 -- the designated type before that for the current record type,
3606 -- Same process if the component is an array of access types,
3607 -- initialized with an aggregate. If the designated type is
3608 -- private, it cannot contain allocators, and it is premature
3609 -- to freeze the type, so we check for this as well.
3611 elsif Is_Access_Type
(Etype
(Comp
))
3612 and then Present
(Parent
(Comp
))
3613 and then Present
(Expression
(Parent
(Comp
)))
3616 Alloc
: constant Node_Id
:=
3617 Check_Allocator
(Expression
(Parent
(Comp
)));
3620 if Present
(Alloc
) then
3622 -- If component is pointer to a class-wide type, freeze
3623 -- the specific type in the expression being allocated.
3624 -- The expression may be a subtype indication, in which
3625 -- case freeze the subtype mark.
3627 if Is_Class_Wide_Type
3628 (Designated_Type
(Etype
(Comp
)))
3630 if Is_Entity_Name
(Expression
(Alloc
)) then
3632 (Entity
(Expression
(Alloc
)), N
, Result
);
3634 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
3637 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
3641 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
3642 Check_Itype
(Etype
(Comp
));
3646 (Designated_Type
(Etype
(Comp
)), N
, Result
);
3651 elsif Is_Access_Type
(Etype
(Comp
))
3652 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
3654 Check_Itype
(Etype
(Comp
));
3656 -- Freeze the designated type when initializing a component with
3657 -- an aggregate in case the aggregate contains allocators.
3660 -- type T_Ptr is access all T;
3661 -- type T_Array is array ... of T_Ptr;
3663 -- type Rec is record
3664 -- Comp : T_Array := (others => ...);
3667 elsif Is_Array_Type
(Etype
(Comp
))
3668 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
3671 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
3672 Desig_Typ
: constant Entity_Id
:=
3674 (Component_Type
(Etype
(Comp
)));
3677 -- The only case when this sort of freezing is not done is
3678 -- when the designated type is class-wide and the root type
3679 -- is the record owning the component. This scenario results
3680 -- in a circularity because the class-wide type requires
3681 -- primitives that have not been created yet as the root
3682 -- type is in the process of being frozen.
3684 -- type Rec is tagged;
3685 -- type Rec_Ptr is access all Rec'Class;
3686 -- type Rec_Array is array ... of Rec_Ptr;
3688 -- type Rec is record
3689 -- Comp : Rec_Array := (others => ...);
3692 if Is_Class_Wide_Type
(Desig_Typ
)
3693 and then Root_Type
(Desig_Typ
) = Rec
3697 elsif Is_Fully_Defined
(Desig_Typ
)
3698 and then Present
(Comp_Par
)
3699 and then Nkind
(Comp_Par
) = N_Component_Declaration
3700 and then Present
(Expression
(Comp_Par
))
3701 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
3703 Freeze_And_Append
(Desig_Typ
, N
, Result
);
3712 -- Deal with default setting of reverse storage order
3714 Set_SSO_From_Default
(Rec
);
3716 -- Check consistent attribute setting on component types
3718 SSO_ADC
:= Get_Attribute_Definition_Clause
3719 (Rec
, Attribute_Scalar_Storage_Order
);
3722 Comp_ADC_Present
: Boolean;
3724 Comp
:= First_Component
(Rec
);
3725 while Present
(Comp
) loop
3726 Check_Component_Storage_Order
3730 Comp_ADC_Present
=> Comp_ADC_Present
);
3731 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
3732 Next_Component
(Comp
);
3736 -- Now deal with reverse storage order/bit order issues
3738 if Present
(SSO_ADC
) then
3740 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
3741 -- the former is specified.
3743 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
3745 -- Note: report error on Rec, not on SSO_ADC, as ADC may apply
3746 -- to some ancestor type.
3748 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
3750 ("scalar storage order for& specified# inconsistent with "
3751 & "bit order", Rec
);
3754 -- Warn if there is an Scalar_Storage_Order attribute definition
3755 -- clause but no component clause, no component that itself has
3756 -- such an attribute definition, and no pragma Pack.
3758 if not (Placed_Component
3765 ("??scalar storage order specified but no component clause",
3770 -- Deal with Bit_Order aspect
3772 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
3774 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
3775 if not (Placed_Component
3776 or else Present
(SSO_ADC
)
3777 or else Is_Packed
(Rec
))
3779 -- Warn if clause has no effect when no component clause is
3780 -- present, but suppress warning if the Bit_Order is required
3781 -- due to the presence of a Scalar_Storage_Order attribute.
3784 ("??bit order specification has no effect", ADC
);
3786 ("\??since no component clauses were specified", ADC
);
3788 -- Here is where we do the processing to adjust component clauses
3789 -- for reversed bit order, when not using reverse SSO.
3791 elsif Reverse_Bit_Order
(Rec
)
3792 and then not Reverse_Storage_Order
(Rec
)
3794 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
3796 -- Case where we have both an explicit Bit_Order and the same
3797 -- Scalar_Storage_Order: leave record untouched, the back-end
3798 -- will take care of required layout conversions.
3806 -- Complete error checking on record representation clause (e.g.
3807 -- overlap of components). This is called after adjusting the
3808 -- record for reverse bit order.
3811 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
3813 if Present
(RRC
) then
3814 Check_Record_Representation_Clause
(RRC
);
3818 -- Set OK_To_Reorder_Components depending on debug flags
3820 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
3821 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
3823 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
3825 Set_OK_To_Reorder_Components
(Rec
);
3829 -- Check for useless pragma Pack when all components placed. We only
3830 -- do this check for record types, not subtypes, since a subtype may
3831 -- have all its components placed, and it still makes perfectly good
3832 -- sense to pack other subtypes or the parent type. We do not give
3833 -- this warning if Optimize_Alignment is set to Space, since the
3834 -- pragma Pack does have an effect in this case (it always resets
3835 -- the alignment to one).
3837 if Ekind
(Rec
) = E_Record_Type
3838 and then Is_Packed
(Rec
)
3839 and then not Unplaced_Component
3840 and then Optimize_Alignment
/= 'S'
3842 -- Reset packed status. Probably not necessary, but we do it so
3843 -- that there is no chance of the back end doing something strange
3844 -- with this redundant indication of packing.
3846 Set_Is_Packed
(Rec
, False);
3848 -- Give warning if redundant constructs warnings on
3850 if Warn_On_Redundant_Constructs
then
3851 Error_Msg_N
-- CODEFIX
3852 ("??pragma Pack has no effect, no unplaced components",
3853 Get_Rep_Pragma
(Rec
, Name_Pack
));
3857 -- If this is the record corresponding to a remote type, freeze the
3858 -- remote type here since that is what we are semantically freezing.
3859 -- This prevents the freeze node for that type in an inner scope.
3861 if Ekind
(Rec
) = E_Record_Type
then
3862 if Present
(Corresponding_Remote_Type
(Rec
)) then
3863 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
3866 -- Check for controlled components and unchecked unions.
3868 Comp
:= First_Component
(Rec
);
3869 while Present
(Comp
) loop
3871 -- Do not set Has_Controlled_Component on a class-wide
3872 -- equivalent type. See Make_CW_Equivalent_Type.
3874 if not Is_Class_Wide_Equivalent_Type
(Rec
)
3876 (Has_Controlled_Component
(Etype
(Comp
))
3878 (Chars
(Comp
) /= Name_uParent
3879 and then Is_Controlled
(Etype
(Comp
)))
3881 (Is_Protected_Type
(Etype
(Comp
))
3883 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
3885 Has_Controlled_Component
3886 (Corresponding_Record_Type
(Etype
(Comp
)))))
3888 Set_Has_Controlled_Component
(Rec
);
3891 if Has_Unchecked_Union
(Etype
(Comp
)) then
3892 Set_Has_Unchecked_Union
(Rec
);
3895 -- Scan component declaration for likely misuses of current
3896 -- instance, either in a constraint or a default expression.
3898 if Has_Per_Object_Constraint
(Comp
) then
3899 Check_Current_Instance
(Parent
(Comp
));
3902 Next_Component
(Comp
);
3906 -- Enforce the restriction that access attributes with a current
3907 -- instance prefix can only apply to limited types. This comment
3908 -- is floating here, but does not seem to belong here???
3910 -- Set component alignment if not otherwise already set
3912 Set_Component_Alignment_If_Not_Set
(Rec
);
3914 -- For first subtypes, check if there are any fixed-point fields with
3915 -- component clauses, where we must check the size. This is not done
3916 -- till the freeze point since for fixed-point types, we do not know
3917 -- the size until the type is frozen. Similar processing applies to
3918 -- bit packed arrays.
3920 if Is_First_Subtype
(Rec
) then
3921 Comp
:= First_Component
(Rec
);
3922 while Present
(Comp
) loop
3923 if Present
(Component_Clause
(Comp
))
3924 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
3925 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
3928 (Component_Name
(Component_Clause
(Comp
)),
3934 Next_Component
(Comp
);
3938 -- Generate warning for applying C or C++ convention to a record
3939 -- with discriminants. This is suppressed for the unchecked union
3940 -- case, since the whole point in this case is interface C. We also
3941 -- do not generate this within instantiations, since we will have
3942 -- generated a message on the template.
3944 if Has_Discriminants
(E
)
3945 and then not Is_Unchecked_Union
(E
)
3946 and then (Convention
(E
) = Convention_C
3948 Convention
(E
) = Convention_CPP
)
3949 and then Comes_From_Source
(E
)
3950 and then not In_Instance
3951 and then not Has_Warnings_Off
(E
)
3952 and then not Has_Warnings_Off
(Base_Type
(E
))
3955 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
3959 if Present
(Cprag
) then
3960 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3962 if Convention
(E
) = Convention_C
then
3964 ("?x?variant record has no direct equivalent in C",
3968 ("?x?variant record has no direct equivalent in C++",
3973 ("\?x?use of convention for type& is dubious", A2
, E
);
3978 -- See if Size is too small as is (and implicit packing might help)
3980 if not Is_Packed
(Rec
)
3982 -- No implicit packing if even one component is explicitly placed
3984 and then not Placed_Component
3986 -- Or even one component is aliased
3988 and then not Aliased_Component
3990 -- Must have size clause and all scalar components
3992 and then Has_Size_Clause
(Rec
)
3993 and then All_Scalar_Components
3995 -- Do not try implicit packing on records with discriminants, too
3996 -- complicated, especially in the variant record case.
3998 and then not Has_Discriminants
(Rec
)
4000 -- We can implicitly pack if the specified size of the record is
4001 -- less than the sum of the object sizes (no point in packing if
4002 -- this is not the case).
4004 and then RM_Size
(Rec
) < Scalar_Component_Total_Esize
4006 -- And the total RM size cannot be greater than the specified size
4007 -- since otherwise packing will not get us where we have to be.
4009 and then RM_Size
(Rec
) >= Scalar_Component_Total_RM_Size
4011 -- Never do implicit packing in CodePeer or SPARK modes since
4012 -- we don't do any packing in these modes, since this generates
4013 -- over-complex code that confuses static analysis, and in
4014 -- general, neither CodePeer not GNATprove care about the
4015 -- internal representation of objects.
4017 and then not (CodePeer_Mode
or GNATprove_Mode
)
4019 -- If implicit packing enabled, do it
4021 if Implicit_Packing
then
4022 Set_Is_Packed
(Rec
);
4024 -- Otherwise flag the size clause
4028 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
4030 Error_Msg_NE
-- CODEFIX
4031 ("size given for& too small", Sz
, Rec
);
4032 Error_Msg_N
-- CODEFIX
4033 ("\use explicit pragma Pack "
4034 & "or use pragma Implicit_Packing", Sz
);
4039 -- The following checks are only relevant when SPARK_Mode is on as
4040 -- they are not standard Ada legality rules.
4042 if SPARK_Mode
= On
then
4043 if Is_Effectively_Volatile
(Rec
) then
4045 -- A discriminated type cannot be effectively volatile
4046 -- (SPARK RM C.6(4)).
4048 if Has_Discriminants
(Rec
) then
4049 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
4051 -- A tagged type cannot be effectively volatile
4052 -- (SPARK RM C.6(5)).
4054 elsif Is_Tagged_Type
(Rec
) then
4055 Error_Msg_N
("tagged type & cannot be volatile", Rec
);
4058 -- A non-effectively volatile record type cannot contain
4059 -- effectively volatile components (SPARK RM C.6(2)).
4062 Comp
:= First_Component
(Rec
);
4063 while Present
(Comp
) loop
4064 if Comes_From_Source
(Comp
)
4065 and then Is_Effectively_Volatile
(Etype
(Comp
))
4067 Error_Msg_Name_1
:= Chars
(Rec
);
4069 ("component & of non-volatile type % cannot be "
4070 & "volatile", Comp
);
4073 Next_Component
(Comp
);
4078 -- All done if not a full record definition
4080 if Ekind
(Rec
) /= E_Record_Type
then
4084 -- Finally we need to check the variant part to make sure that
4085 -- all types within choices are properly frozen as part of the
4086 -- freezing of the record type.
4088 Check_Variant_Part
: declare
4089 D
: constant Node_Id
:= Declaration_Node
(Rec
);
4094 -- Find component list
4098 if Nkind
(D
) = N_Full_Type_Declaration
then
4099 T
:= Type_Definition
(D
);
4101 if Nkind
(T
) = N_Record_Definition
then
4102 C
:= Component_List
(T
);
4104 elsif Nkind
(T
) = N_Derived_Type_Definition
4105 and then Present
(Record_Extension_Part
(T
))
4107 C
:= Component_List
(Record_Extension_Part
(T
));
4111 -- Case of variant part present
4113 if Present
(C
) and then Present
(Variant_Part
(C
)) then
4114 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
4117 -- Note: we used to call Check_Choices here, but it is too early,
4118 -- since predicated subtypes are frozen here, but their freezing
4119 -- actions are in Analyze_Freeze_Entity, which has not been called
4120 -- yet for entities frozen within this procedure, so we moved that
4121 -- call to the Analyze_Freeze_Entity for the record type.
4123 end Check_Variant_Part
;
4125 -- Check that all the primitives of an interface type are abstract
4126 -- or null procedures.
4128 if Is_Interface
(Rec
)
4129 and then not Error_Posted
(Parent
(Rec
))
4136 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
4137 while Present
(Elmt
) loop
4138 Subp
:= Node
(Elmt
);
4140 if not Is_Abstract_Subprogram
(Subp
)
4142 -- Avoid reporting the error on inherited primitives
4144 and then Comes_From_Source
(Subp
)
4146 Error_Msg_Name_1
:= Chars
(Subp
);
4148 if Ekind
(Subp
) = E_Procedure
then
4149 if not Null_Present
(Parent
(Subp
)) then
4151 ("interface procedure % must be abstract or null",
4156 ("interface function % must be abstract",
4165 end Freeze_Record_Type
;
4167 -------------------------------
4168 -- Has_Boolean_Aspect_Import --
4169 -------------------------------
4171 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
4172 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4177 if Has_Aspects
(Decl
) then
4178 Asp
:= First
(Aspect_Specifications
(Decl
));
4179 while Present
(Asp
) loop
4180 Expr
:= Expression
(Asp
);
4182 -- The value of aspect Import is True when the expression is
4183 -- either missing or it is explicitly set to True.
4185 if Get_Aspect_Id
(Asp
) = Aspect_Import
4187 or else (Compile_Time_Known_Value
(Expr
)
4188 and then Is_True
(Expr_Value
(Expr
))))
4198 end Has_Boolean_Aspect_Import
;
4200 ----------------------------
4201 -- Late_Freeze_Subprogram --
4202 ----------------------------
4204 procedure Late_Freeze_Subprogram
(E
: Entity_Id
) is
4205 Spec
: constant Node_Id
:=
4206 Specification
(Unit_Declaration_Node
(Scope
(E
)));
4210 if Present
(Private_Declarations
(Spec
)) then
4211 Decls
:= Private_Declarations
(Spec
);
4213 Decls
:= Visible_Declarations
(Spec
);
4216 Append_List
(Result
, Decls
);
4217 end Late_Freeze_Subprogram
;
4219 ---------------------
4220 -- Restore_Globals --
4221 ---------------------
4223 procedure Restore_Globals
is
4226 end Restore_Globals
;
4228 ------------------------------
4229 -- Wrap_Imported_Subprogram --
4230 ------------------------------
4232 -- The issue here is that our normal approach of checking preconditions
4233 -- and postconditions does not work for imported procedures, since we
4234 -- are not generating code for the body. To get around this we create
4235 -- a wrapper, as shown by the following example:
4237 -- procedure K (A : Integer);
4238 -- pragma Import (C, K);
4240 -- The spec is rewritten by removing the effects of pragma Import, but
4241 -- leaving the convention unchanged, as though the source had said:
4243 -- procedure K (A : Integer);
4244 -- pragma Convention (C, K);
4246 -- and we create a body, added to the entity K freeze actions, which
4249 -- procedure K (A : Integer) is
4250 -- procedure K (A : Integer);
4251 -- pragma Import (C, K);
4256 -- Now the contract applies in the normal way to the outer procedure,
4257 -- and the inner procedure has no contracts, so there is no problem
4258 -- in just calling it to get the original effect.
4260 -- In the case of a function, we create an appropriate return statement
4261 -- for the subprogram body that calls the inner procedure.
4263 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
4264 Loc
: constant Source_Ptr
:= Sloc
(E
);
4265 CE
: constant Name_Id
:= Chars
(E
);
4274 -- Nothing to do if not imported
4276 if not Is_Imported
(E
) then
4279 -- Test enabling conditions for wrapping
4281 elsif Is_Subprogram
(E
)
4282 and then Present
(Contract
(E
))
4283 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
4284 and then not GNATprove_Mode
4286 -- Here we do the wrap
4288 -- Note on calls to Copy_Separate_Tree. The trees we are copying
4289 -- here are fully analyzed, but we definitely want fully syntactic
4290 -- unanalyzed trees in the body we construct, so that the analysis
4291 -- generates the right visibility, and that is exactly what the
4292 -- calls to Copy_Separate_Tree give us.
4294 -- Acquire copy of Inline pragma, and indicate that it does not
4295 -- come from an aspect, as it applies to an internal entity.
4297 Iprag
:= Copy_Separate_Tree
(Import_Pragma
(E
));
4298 Set_From_Aspect_Specification
(Iprag
, False);
4300 -- Fix up spec to be not imported any more
4302 Set_Is_Imported
(E
, False);
4303 Set_Interface_Name
(E
, Empty
);
4304 Set_Has_Completion
(E
, False);
4305 Set_Import_Pragma
(E
, Empty
);
4307 -- Grab the subprogram declaration and specification
4309 Spec
:= Declaration_Node
(E
);
4311 -- Build parameter list that we need
4314 Forml
:= First_Formal
(E
);
4315 while Present
(Forml
) loop
4316 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
4317 Next_Formal
(Forml
);
4322 if Ekind_In
(E
, E_Function
, E_Generic_Function
) then
4324 Make_Simple_Return_Statement
(Loc
,
4326 Make_Function_Call
(Loc
,
4327 Name
=> Make_Identifier
(Loc
, CE
),
4328 Parameter_Associations
=> Parms
));
4332 Make_Procedure_Call_Statement
(Loc
,
4333 Name
=> Make_Identifier
(Loc
, CE
),
4334 Parameter_Associations
=> Parms
);
4337 -- Now build the body
4340 Make_Subprogram_Body
(Loc
,
4342 Copy_Separate_Tree
(Spec
),
4343 Declarations
=> New_List
(
4344 Make_Subprogram_Declaration
(Loc
,
4346 Copy_Separate_Tree
(Spec
)),
4348 Handled_Statement_Sequence
=>
4349 Make_Handled_Sequence_Of_Statements
(Loc
,
4350 Statements
=> New_List
(Stmt
),
4351 End_Label
=> Make_Identifier
(Loc
, CE
)));
4353 -- Append the body to freeze result
4355 Add_To_Result
(Bod
);
4358 -- Case of imported subprogram that does not get wrapped
4361 -- Set Is_Public. All imported entities need an external symbol
4362 -- created for them since they are always referenced from another
4363 -- object file. Note this used to be set when we set Is_Imported
4364 -- back in Sem_Prag, but now we delay it to this point, since we
4365 -- don't want to set this flag if we wrap an imported subprogram.
4369 end Wrap_Imported_Subprogram
;
4371 -- Start of processing for Freeze_Entity
4374 -- The entity being frozen may be subject to pragma Ghost with policy
4375 -- Ignore. Set the mode now to ensure that any nodes generated during
4376 -- freezing are properly flagged as ignored Ghost.
4378 Set_Ghost_Mode_For_Freeze
(E
, N
);
4380 -- We are going to test for various reasons why this entity need not be
4381 -- frozen here, but in the case of an Itype that's defined within a
4382 -- record, that test actually applies to the record.
4384 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
4385 Test_E
:= Scope
(E
);
4386 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
4387 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
4389 Test_E
:= Underlying_Type
(Scope
(E
));
4392 -- Do not freeze if already frozen since we only need one freeze node
4394 if Is_Frozen
(E
) then
4398 -- It is improper to freeze an external entity within a generic because
4399 -- its freeze node will appear in a non-valid context. The entity will
4400 -- be frozen in the proper scope after the current generic is analyzed.
4401 -- However, aspects must be analyzed because they may be queried later
4402 -- within the generic itself, and the corresponding pragma or attribute
4403 -- definition has not been analyzed yet.
4405 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
4406 if Has_Delayed_Aspects
(E
) then
4407 Analyze_Aspects_At_Freeze_Point
(E
);
4413 -- AI05-0213: A formal incomplete type does not freeze the actual. In
4414 -- the instance, the same applies to the subtype renaming the actual.
4416 elsif Is_Private_Type
(E
)
4417 and then Is_Generic_Actual_Type
(E
)
4418 and then No
(Full_View
(Base_Type
(E
)))
4419 and then Ada_Version
>= Ada_2012
4424 -- Formal subprograms are never frozen
4426 elsif Is_Formal_Subprogram
(E
) then
4430 -- Generic types are never frozen as they lack delayed semantic checks
4432 elsif Is_Generic_Type
(E
) then
4436 -- Do not freeze a global entity within an inner scope created during
4437 -- expansion. A call to subprogram E within some internal procedure
4438 -- (a stream attribute for example) might require freezing E, but the
4439 -- freeze node must appear in the same declarative part as E itself.
4440 -- The two-pass elaboration mechanism in gigi guarantees that E will
4441 -- be frozen before the inner call is elaborated. We exclude constants
4442 -- from this test, because deferred constants may be frozen early, and
4443 -- must be diagnosed (e.g. in the case of a deferred constant being used
4444 -- in a default expression). If the enclosing subprogram comes from
4445 -- source, or is a generic instance, then the freeze point is the one
4446 -- mandated by the language, and we freeze the entity. A subprogram that
4447 -- is a child unit body that acts as a spec does not have a spec that
4448 -- comes from source, but can only come from source.
4450 elsif In_Open_Scopes
(Scope
(Test_E
))
4451 and then Scope
(Test_E
) /= Current_Scope
4452 and then Ekind
(Test_E
) /= E_Constant
4459 while Present
(S
) loop
4460 if Is_Overloadable
(S
) then
4461 if Comes_From_Source
(S
)
4462 or else Is_Generic_Instance
(S
)
4463 or else Is_Child_Unit
(S
)
4476 -- Similarly, an inlined instance body may make reference to global
4477 -- entities, but these references cannot be the proper freezing point
4478 -- for them, and in the absence of inlining freezing will take place in
4479 -- their own scope. Normally instance bodies are analyzed after the
4480 -- enclosing compilation, and everything has been frozen at the proper
4481 -- place, but with front-end inlining an instance body is compiled
4482 -- before the end of the enclosing scope, and as a result out-of-order
4483 -- freezing must be prevented.
4485 elsif Front_End_Inlining
4486 and then In_Instance_Body
4487 and then Present
(Scope
(Test_E
))
4493 S
:= Scope
(Test_E
);
4494 while Present
(S
) loop
4495 if Is_Generic_Instance
(S
) then
4508 elsif Ekind
(E
) = E_Generic_Package
then
4509 Result
:= Freeze_Generic_Entities
(E
);
4515 -- Add checks to detect proper initialization of scalars that may appear
4516 -- as subprogram parameters.
4518 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
4519 Apply_Parameter_Validity_Checks
(E
);
4522 -- Deal with delayed aspect specifications. The analysis of the aspect
4523 -- is required to be delayed to the freeze point, thus we analyze the
4524 -- pragma or attribute definition clause in the tree at this point. We
4525 -- also analyze the aspect specification node at the freeze point when
4526 -- the aspect doesn't correspond to pragma/attribute definition clause.
4528 if Has_Delayed_Aspects
(E
) then
4529 Analyze_Aspects_At_Freeze_Point
(E
);
4532 -- Here to freeze the entity
4536 -- Case of entity being frozen is other than a type
4538 if not Is_Type
(E
) then
4540 -- If entity is exported or imported and does not have an external
4541 -- name, now is the time to provide the appropriate default name.
4542 -- Skip this if the entity is stubbed, since we don't need a name
4543 -- for any stubbed routine. For the case on intrinsics, if no
4544 -- external name is specified, then calls will be handled in
4545 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
4546 -- external name is provided, then Expand_Intrinsic_Call leaves
4547 -- calls in place for expansion by GIGI.
4549 if (Is_Imported
(E
) or else Is_Exported
(E
))
4550 and then No
(Interface_Name
(E
))
4551 and then Convention
(E
) /= Convention_Stubbed
4552 and then Convention
(E
) /= Convention_Intrinsic
4554 Set_Encoded_Interface_Name
4555 (E
, Get_Default_External_Name
(E
));
4557 -- If entity is an atomic object appearing in a declaration and
4558 -- the expression is an aggregate, assign it to a temporary to
4559 -- ensure that the actual assignment is done atomically rather
4560 -- than component-wise (the assignment to the temp may be done
4561 -- component-wise, but that is harmless).
4564 and then Nkind
(Parent
(E
)) = N_Object_Declaration
4565 and then Present
(Expression
(Parent
(E
)))
4566 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
4567 and then Is_Atomic_Aggregate
(Expression
(Parent
(E
)), Etype
(E
))
4574 if Is_Subprogram
(E
) then
4576 -- Check for needing to wrap imported subprogram
4578 Wrap_Imported_Subprogram
(E
);
4580 -- Freeze all parameter types and the return type (RM 13.14(14)).
4581 -- However skip this for internal subprograms. This is also where
4582 -- any extra formal parameters are created since we now know
4583 -- whether the subprogram will use a foreign convention.
4585 -- In Ada 2012, freezing a subprogram does not always freeze
4586 -- the corresponding profile (see AI05-019). An attribute
4587 -- reference is not a freezing point of the profile.
4588 -- Other constructs that should not freeze ???
4590 -- This processing doesn't apply to internal entities (see below)
4592 if not Is_Internal
(E
) then
4593 if not Freeze_Profile
(E
) then
4599 -- Must freeze its parent first if it is a derived subprogram
4601 if Present
(Alias
(E
)) then
4602 Freeze_And_Append
(Alias
(E
), N
, Result
);
4605 -- We don't freeze internal subprograms, because we don't normally
4606 -- want addition of extra formals or mechanism setting to happen
4607 -- for those. However we do pass through predefined dispatching
4608 -- cases, since extra formals may be needed in some cases, such as
4609 -- for the stream 'Input function (build-in-place formals).
4611 if not Is_Internal
(E
)
4612 or else Is_Predefined_Dispatching_Operation
(E
)
4614 Freeze_Subprogram
(E
);
4617 if Late_Freezing
then
4618 Late_Freeze_Subprogram
(E
);
4623 -- If warning on suspicious contracts then check for the case of
4624 -- a postcondition other than False for a No_Return subprogram.
4627 and then Warn_On_Suspicious_Contract
4628 and then Present
(Contract
(E
))
4631 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
4635 while Present
(Prag
) loop
4636 if Nam_In
(Pragma_Name
(Prag
), Name_Post
,
4642 (First
(Pragma_Argument_Associations
(Prag
)));
4644 if Nkind
(Exp
) /= N_Identifier
4645 or else Chars
(Exp
) /= Name_False
4648 ("useless postcondition, & is marked "
4649 & "No_Return?T?", Exp
, E
);
4653 Prag
:= Next_Pragma
(Prag
);
4658 -- Here for other than a subprogram or type
4661 -- If entity has a type, and it is not a generic unit, then
4662 -- freeze it first (RM 13.14(10)).
4664 if Present
(Etype
(E
))
4665 and then Ekind
(E
) /= E_Generic_Function
4667 Freeze_And_Append
(Etype
(E
), N
, Result
);
4669 -- For an object of an anonymous array type, aspects on the
4670 -- object declaration apply to the type itself. This is the
4671 -- case for Atomic_Components, Volatile_Components, and
4672 -- Independent_Components. In these cases analysis of the
4673 -- generated pragma will mark the anonymous types accordingly,
4674 -- and the object itself does not require a freeze node.
4676 if Ekind
(E
) = E_Variable
4677 and then Is_Itype
(Etype
(E
))
4678 and then Is_Array_Type
(Etype
(E
))
4679 and then Has_Delayed_Aspects
(E
)
4681 Set_Has_Delayed_Aspects
(E
, False);
4682 Set_Has_Delayed_Freeze
(E
, False);
4683 Set_Freeze_Node
(E
, Empty
);
4687 -- Special processing for objects created by object declaration
4689 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
4691 -- Abstract type allowed only for C++ imported variables or
4694 -- Note: we inhibit this check for objects that do not come
4695 -- from source because there is at least one case (the
4696 -- expansion of x'Class'Input where x is abstract) where we
4697 -- legitimately generate an abstract object.
4699 if Is_Abstract_Type
(Etype
(E
))
4700 and then Comes_From_Source
(Parent
(E
))
4701 and then not (Is_Imported
(E
)
4702 and then Is_CPP_Class
(Etype
(E
)))
4704 Error_Msg_N
("type of object cannot be abstract",
4705 Object_Definition
(Parent
(E
)));
4707 if Is_CPP_Class
(Etype
(E
)) then
4709 ("\} may need a cpp_constructor",
4710 Object_Definition
(Parent
(E
)), Etype
(E
));
4712 elsif Present
(Expression
(Parent
(E
))) then
4713 Error_Msg_N
-- CODEFIX
4714 ("\maybe a class-wide type was meant",
4715 Object_Definition
(Parent
(E
)));
4719 -- For object created by object declaration, perform required
4720 -- categorization (preelaborate and pure) checks. Defer these
4721 -- checks to freeze time since pragma Import inhibits default
4722 -- initialization and thus pragma Import affects these checks.
4724 Validate_Object_Declaration
(Declaration_Node
(E
));
4726 -- If there is an address clause, check that it is valid
4728 Check_Address_Clause
(E
);
4730 -- Reset Is_True_Constant for non-constant aliased object. We
4731 -- consider that the fact that a non-constant object is aliased
4732 -- may indicate that some funny business is going on, e.g. an
4733 -- aliased object is passed by reference to a procedure which
4734 -- captures the address of the object, which is later used to
4735 -- assign a new value, even though the compiler thinks that
4736 -- it is not modified. Such code is highly dubious, but we
4737 -- choose to make it "work" for non-constant aliased objects.
4738 -- Note that we used to do this for all aliased objects,
4739 -- whether or not constant, but this caused anomalies down
4740 -- the line because we ended up with static objects that
4741 -- were not Is_True_Constant. Not resetting Is_True_Constant
4742 -- for (aliased) constant objects ensures that this anomaly
4745 -- However, we don't do that for internal entities. We figure
4746 -- that if we deliberately set Is_True_Constant for an internal
4747 -- entity, e.g. a dispatch table entry, then we mean it.
4749 if Ekind
(E
) /= E_Constant
4750 and then (Is_Aliased
(E
) or else Is_Aliased
(Etype
(E
)))
4751 and then not Is_Internal_Name
(Chars
(E
))
4753 Set_Is_True_Constant
(E
, False);
4756 -- If the object needs any kind of default initialization, an
4757 -- error must be issued if No_Default_Initialization applies.
4758 -- The check doesn't apply to imported objects, which are not
4759 -- ever default initialized, and is why the check is deferred
4760 -- until freezing, at which point we know if Import applies.
4761 -- Deferred constants are also exempted from this test because
4762 -- their completion is explicit, or through an import pragma.
4764 if Ekind
(E
) = E_Constant
4765 and then Present
(Full_View
(E
))
4769 elsif Comes_From_Source
(E
)
4770 and then not Is_Imported
(E
)
4771 and then not Has_Init_Expression
(Declaration_Node
(E
))
4773 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
4774 and then not No_Initialization
(Declaration_Node
(E
))
4775 and then not Is_Value_Type
(Etype
(E
))
4776 and then not Initialization_Suppressed
(Etype
(E
)))
4778 (Needs_Simple_Initialization
(Etype
(E
))
4779 and then not Is_Internal
(E
)))
4781 Has_Default_Initialization
:= True;
4783 (No_Default_Initialization
, Declaration_Node
(E
));
4786 -- Check that a Thread_Local_Storage variable does not have
4787 -- default initialization, and any explicit initialization must
4788 -- either be the null constant or a static constant.
4790 if Has_Pragma_Thread_Local_Storage
(E
) then
4792 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4794 if Has_Default_Initialization
4796 (Has_Init_Expression
(Decl
)
4798 (No
(Expression
(Decl
))
4800 (Is_OK_Static_Expression
(Expression
(Decl
))
4802 Nkind
(Expression
(Decl
)) = N_Null
)))
4805 ("Thread_Local_Storage variable& is "
4806 & "improperly initialized", Decl
, E
);
4808 ("\only allowed initialization is explicit "
4809 & "NULL or static expression", Decl
, E
);
4814 -- For imported objects, set Is_Public unless there is also an
4815 -- address clause, which means that there is no external symbol
4816 -- needed for the Import (Is_Public may still be set for other
4817 -- unrelated reasons). Note that we delayed this processing
4818 -- till freeze time so that we can be sure not to set the flag
4819 -- if there is an address clause. If there is such a clause,
4820 -- then the only purpose of the Import pragma is to suppress
4821 -- implicit initialization.
4823 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4827 -- For source objects that are not Imported and are library
4828 -- level, if no linker section pragma was given inherit the
4829 -- appropriate linker section from the corresponding type.
4831 if Comes_From_Source
(E
)
4832 and then not Is_Imported
(E
)
4833 and then Is_Library_Level_Entity
(E
)
4834 and then No
(Linker_Section_Pragma
(E
))
4836 Set_Linker_Section_Pragma
4837 (E
, Linker_Section_Pragma
(Etype
(E
)));
4840 -- For convention C objects of an enumeration type, warn if
4841 -- the size is not integer size and no explicit size given.
4842 -- Skip warning for Boolean, and Character, assume programmer
4843 -- expects 8-bit sizes for these cases.
4845 if (Convention
(E
) = Convention_C
4847 Convention
(E
) = Convention_CPP
)
4848 and then Is_Enumeration_Type
(Etype
(E
))
4849 and then not Is_Character_Type
(Etype
(E
))
4850 and then not Is_Boolean_Type
(Etype
(E
))
4851 and then Esize
(Etype
(E
)) < Standard_Integer_Size
4852 and then not Has_Size_Clause
(E
)
4854 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4856 ("??convention C enumeration object has size less than ^",
4858 Error_Msg_N
("\??use explicit size clause to set size", E
);
4862 -- Check that a constant which has a pragma Volatile[_Components]
4863 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
4865 -- Note: Atomic[_Components] also sets Volatile[_Components]
4867 if Ekind
(E
) = E_Constant
4868 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
4869 and then not Is_Imported
(E
)
4870 and then not Has_Boolean_Aspect_Import
(E
)
4872 -- Make sure we actually have a pragma, and have not merely
4873 -- inherited the indication from elsewhere (e.g. an address
4874 -- clause, which is not good enough in RM terms).
4876 if Has_Rep_Pragma
(E
, Name_Atomic
)
4878 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
4881 ("stand alone atomic constant must be " &
4882 "imported (RM C.6(13))", E
);
4884 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
4886 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
4889 ("stand alone volatile constant must be " &
4890 "imported (RM C.6(13))", E
);
4894 -- Static objects require special handling
4896 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
4897 and then Is_Statically_Allocated
(E
)
4899 Freeze_Static_Object
(E
);
4902 -- Remaining step is to layout objects
4904 if Ekind_In
(E
, E_Variable
, E_Constant
, E_Loop_Parameter
)
4905 or else Is_Formal
(E
)
4910 -- For an object that does not have delayed freezing, and whose
4911 -- initialization actions have been captured in a compound
4912 -- statement, move them back now directly within the enclosing
4913 -- statement sequence.
4915 if Ekind_In
(E
, E_Constant
, E_Variable
)
4916 and then not Has_Delayed_Freeze
(E
)
4918 Explode_Initialization_Compound_Statement
(E
);
4922 -- Case of a type or subtype being frozen
4925 -- We used to check here that a full type must have preelaborable
4926 -- initialization if it completes a private type specified with
4927 -- pragma Preelaborable_Initialization, but that missed cases where
4928 -- the types occur within a generic package, since the freezing
4929 -- that occurs within a containing scope generally skips traversal
4930 -- of a generic unit's declarations (those will be frozen within
4931 -- instances). This check was moved to Analyze_Package_Specification.
4933 -- The type may be defined in a generic unit. This can occur when
4934 -- freezing a generic function that returns the type (which is
4935 -- defined in a parent unit). It is clearly meaningless to freeze
4936 -- this type. However, if it is a subtype, its size may be determi-
4937 -- nable and used in subsequent checks, so might as well try to
4940 -- In Ada 2012, Freeze_Entities is also used in the front end to
4941 -- trigger the analysis of aspect expressions, so in this case we
4942 -- want to continue the freezing process.
4944 if Present
(Scope
(E
))
4945 and then Is_Generic_Unit
(Scope
(E
))
4947 (not Has_Predicates
(E
)
4948 and then not Has_Delayed_Freeze
(E
))
4950 Check_Compile_Time_Size
(E
);
4955 -- Check for error of Type_Invariant'Class applied to an untagged
4956 -- type (check delayed to freeze time when full type is available).
4959 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
4962 and then Class_Present
(Prag
)
4963 and then not Is_Tagged_Type
(E
)
4966 ("Type_Invariant''Class cannot be specified for &",
4969 ("\can only be specified for a tagged type", Prag
);
4973 -- A Ghost type cannot be effectively volatile (SPARK RM 6.9(8))
4975 if Is_Ghost_Entity
(E
)
4976 and then Is_Effectively_Volatile
(E
)
4978 Error_Msg_N
("ghost type & cannot be volatile", E
);
4981 -- Deal with special cases of freezing for subtype
4983 if E
/= Base_Type
(E
) then
4985 -- Before we do anything else, a specialized test for the case of
4986 -- a size given for an array where the array needs to be packed,
4987 -- but was not so the size cannot be honored. This is the case
4988 -- where implicit packing may apply. The reason we do this so
4989 -- early is that if we have implicit packing, the layout of the
4990 -- base type is affected, so we must do this before we freeze
4993 -- We could do this processing only if implicit packing is enabled
4994 -- since in all other cases, the error would be caught by the back
4995 -- end. However, we choose to do the check even if we do not have
4996 -- implicit packing enabled, since this allows us to give a more
4997 -- useful error message (advising use of pragmas Implicit_Packing
5000 if Is_Array_Type
(E
) then
5002 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
5003 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
5004 SZ
: constant Node_Id
:= Size_Clause
(E
);
5005 Btyp
: constant Entity_Id
:= Base_Type
(E
);
5012 -- Number of elements in array
5015 -- Check enabling conditions. These are straightforward
5016 -- except for the test for a limited composite type. This
5017 -- eliminates the rare case of a array of limited components
5018 -- where there are issues of whether or not we can go ahead
5019 -- and pack the array (since we can't freely pack and unpack
5020 -- arrays if they are limited).
5022 -- Note that we check the root type explicitly because the
5023 -- whole point is we are doing this test before we have had
5024 -- a chance to freeze the base type (and it is that freeze
5025 -- action that causes stuff to be inherited).
5027 if Has_Size_Clause
(E
)
5028 and then Known_Static_RM_Size
(E
)
5029 and then not Is_Packed
(E
)
5030 and then not Has_Pragma_Pack
(E
)
5031 and then not Has_Component_Size_Clause
(E
)
5032 and then Known_Static_RM_Size
(Ctyp
)
5033 and then RM_Size
(Ctyp
) < 64
5034 and then not Is_Limited_Composite
(E
)
5035 and then not Is_Packed
(Root_Type
(E
))
5036 and then not Has_Component_Size_Clause
(Root_Type
(E
))
5037 and then not (CodePeer_Mode
or GNATprove_Mode
)
5039 -- Compute number of elements in array
5041 Num_Elmts
:= Uint_1
;
5042 Indx
:= First_Index
(E
);
5043 while Present
(Indx
) loop
5044 Get_Index_Bounds
(Indx
, Lo
, Hi
);
5046 if not (Compile_Time_Known_Value
(Lo
)
5048 Compile_Time_Known_Value
(Hi
))
5050 goto No_Implicit_Packing
;
5056 Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1);
5060 -- What we are looking for here is the situation where
5061 -- the RM_Size given would be exactly right if there was
5062 -- a pragma Pack (resulting in the component size being
5063 -- the same as the RM_Size). Furthermore, the component
5064 -- type size must be an odd size (not a multiple of
5065 -- storage unit). If the component RM size is an exact
5066 -- number of storage units that is a power of two, the
5067 -- array is not packed and has a standard representation.
5069 if RM_Size
(E
) = Num_Elmts
* Rsiz
5070 and then Rsiz
mod System_Storage_Unit
/= 0
5072 -- For implicit packing mode, just set the component
5075 if Implicit_Packing
then
5076 Set_Component_Size
(Btyp
, Rsiz
);
5077 Set_Is_Bit_Packed_Array
(Btyp
);
5078 Set_Is_Packed
(Btyp
);
5079 Set_Has_Non_Standard_Rep
(Btyp
);
5081 -- Otherwise give an error message
5085 ("size given for& too small", SZ
, E
);
5086 Error_Msg_N
-- CODEFIX
5087 ("\use explicit pragma Pack "
5088 & "or use pragma Implicit_Packing", SZ
);
5091 elsif RM_Size
(E
) = Num_Elmts
* Rsiz
5092 and then Implicit_Packing
5094 (Rsiz
/ System_Storage_Unit
= 1
5096 Rsiz
/ System_Storage_Unit
= 2
5098 Rsiz
/ System_Storage_Unit
= 4)
5100 -- Not a packed array, but indicate the desired
5101 -- component size, for the back-end.
5103 Set_Component_Size
(Btyp
, Rsiz
);
5109 <<No_Implicit_Packing
>>
5111 -- If ancestor subtype present, freeze that first. Note that this
5112 -- will also get the base type frozen. Need RM reference ???
5114 Atype
:= Ancestor_Subtype
(E
);
5116 if Present
(Atype
) then
5117 Freeze_And_Append
(Atype
, N
, Result
);
5119 -- No ancestor subtype present
5122 -- See if we have a nearest ancestor that has a predicate.
5123 -- That catches the case of derived type with a predicate.
5124 -- Need RM reference here ???
5126 Atype
:= Nearest_Ancestor
(E
);
5128 if Present
(Atype
) and then Has_Predicates
(Atype
) then
5129 Freeze_And_Append
(Atype
, N
, Result
);
5132 -- Freeze base type before freezing the entity (RM 13.14(15))
5134 if E
/= Base_Type
(E
) then
5135 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
5139 -- A subtype inherits all the type-related representation aspects
5140 -- from its parents (RM 13.1(8)).
5142 Inherit_Aspects_At_Freeze_Point
(E
);
5144 -- For a derived type, freeze its parent type first (RM 13.14(15))
5146 elsif Is_Derived_Type
(E
) then
5147 Freeze_And_Append
(Etype
(E
), N
, Result
);
5148 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
5150 -- A derived type inherits each type-related representation aspect
5151 -- of its parent type that was directly specified before the
5152 -- declaration of the derived type (RM 13.1(15)).
5154 Inherit_Aspects_At_Freeze_Point
(E
);
5157 -- Check for incompatible size and alignment for record type
5159 if Warn_On_Size_Alignment
5160 and then Is_Record_Type
(E
)
5161 and then Has_Size_Clause
(E
) and then Has_Alignment_Clause
(E
)
5163 -- If explicit Object_Size clause given assume that the programmer
5164 -- knows what he is doing, and expects the compiler behavior.
5166 and then not Has_Object_Size_Clause
(E
)
5168 -- Check for size not a multiple of alignment
5170 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
5173 SC
: constant Node_Id
:= Size_Clause
(E
);
5174 AC
: constant Node_Id
:= Alignment_Clause
(E
);
5176 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
5179 if Present
(SC
) and then Present
(AC
) then
5183 if Sloc
(SC
) > Sloc
(AC
) then
5186 ("??size is not a multiple of alignment for &", Loc
, E
);
5187 Error_Msg_Sloc
:= Sloc
(AC
);
5188 Error_Msg_Uint_1
:= Alignment
(E
);
5189 Error_Msg_N
("\??alignment of ^ specified #", Loc
);
5194 ("??size is not a multiple of alignment for &", Loc
, E
);
5195 Error_Msg_Sloc
:= Sloc
(SC
);
5196 Error_Msg_Uint_1
:= RM_Size
(E
);
5197 Error_Msg_N
("\??size of ^ specified #", Loc
);
5200 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
5201 Error_Msg_N
("\??Object_Size will be increased to ^", Loc
);
5208 if Is_Array_Type
(E
) then
5209 Freeze_Array_Type
(E
);
5211 -- For a class-wide type, the corresponding specific type is
5212 -- frozen as well (RM 13.14(15))
5214 elsif Is_Class_Wide_Type
(E
) then
5215 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
5217 -- If the base type of the class-wide type is still incomplete,
5218 -- the class-wide remains unfrozen as well. This is legal when
5219 -- E is the formal of a primitive operation of some other type
5220 -- which is being frozen.
5222 if not Is_Frozen
(Root_Type
(E
)) then
5223 Set_Is_Frozen
(E
, False);
5228 -- The equivalent type associated with a class-wide subtype needs
5229 -- to be frozen to ensure that its layout is done.
5231 if Ekind
(E
) = E_Class_Wide_Subtype
5232 and then Present
(Equivalent_Type
(E
))
5234 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5237 -- Generate an itype reference for a library-level class-wide type
5238 -- at the freeze point. Otherwise the first explicit reference to
5239 -- the type may appear in an inner scope which will be rejected by
5243 and then Is_Compilation_Unit
(Scope
(E
))
5246 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
5251 -- From a gigi point of view, a class-wide subtype derives
5252 -- from its record equivalent type. As a result, the itype
5253 -- reference must appear after the freeze node of the
5254 -- equivalent type or gigi will reject the reference.
5256 if Ekind
(E
) = E_Class_Wide_Subtype
5257 and then Present
(Equivalent_Type
(E
))
5259 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
5261 Add_To_Result
(Ref
);
5266 -- For a record type or record subtype, freeze all component types
5267 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
5268 -- using Is_Record_Type, because we don't want to attempt the freeze
5269 -- for the case of a private type with record extension (we will do
5270 -- that later when the full type is frozen).
5272 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
)
5273 and then not (Present
(Scope
(E
))
5274 and then Is_Generic_Unit
(Scope
(E
)))
5276 Freeze_Record_Type
(E
);
5278 -- For a concurrent type, freeze corresponding record type. This does
5279 -- not correspond to any specific rule in the RM, but the record type
5280 -- is essentially part of the concurrent type. Also freeze all local
5281 -- entities. This includes record types created for entry parameter
5282 -- blocks and whatever local entities may appear in the private part.
5284 elsif Is_Concurrent_Type
(E
) then
5285 if Present
(Corresponding_Record_Type
(E
)) then
5286 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
5289 Comp
:= First_Entity
(E
);
5290 while Present
(Comp
) loop
5291 if Is_Type
(Comp
) then
5292 Freeze_And_Append
(Comp
, N
, Result
);
5294 elsif (Ekind
(Comp
)) /= E_Function
then
5296 -- The guard on the presence of the Etype seems to be needed
5297 -- for some CodePeer (-gnatcC) cases, but not clear why???
5299 if Present
(Etype
(Comp
)) then
5300 if Is_Itype
(Etype
(Comp
))
5301 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
5303 Undelay_Type
(Etype
(Comp
));
5306 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5313 -- Private types are required to point to the same freeze node as
5314 -- their corresponding full views. The freeze node itself has to
5315 -- point to the partial view of the entity (because from the partial
5316 -- view, we can retrieve the full view, but not the reverse).
5317 -- However, in order to freeze correctly, we need to freeze the full
5318 -- view. If we are freezing at the end of a scope (or within the
5319 -- scope) of the private type, the partial and full views will have
5320 -- been swapped, the full view appears first in the entity chain and
5321 -- the swapping mechanism ensures that the pointers are properly set
5324 -- If we encounter the partial view before the full view (e.g. when
5325 -- freezing from another scope), we freeze the full view, and then
5326 -- set the pointers appropriately since we cannot rely on swapping to
5327 -- fix things up (subtypes in an outer scope might not get swapped).
5329 -- If the full view is itself private, the above requirements apply
5330 -- to the underlying full view instead of the full view. But there is
5331 -- no swapping mechanism for the underlying full view so we need to
5332 -- set the pointers appropriately in both cases.
5334 elsif Is_Incomplete_Or_Private_Type
(E
)
5335 and then not Is_Generic_Type
(E
)
5337 -- The construction of the dispatch table associated with library
5338 -- level tagged types forces freezing of all the primitives of the
5339 -- type, which may cause premature freezing of the partial view.
5343 -- type T is tagged private;
5344 -- type DT is new T with private;
5345 -- procedure Prim (X : in out T; Y : in out DT'Class);
5347 -- type T is tagged null record;
5349 -- type DT is new T with null record;
5352 -- In this case the type will be frozen later by the usual
5353 -- mechanism: an object declaration, an instantiation, or the
5354 -- end of a declarative part.
5356 if Is_Library_Level_Tagged_Type
(E
)
5357 and then not Present
(Full_View
(E
))
5359 Set_Is_Frozen
(E
, False);
5363 -- Case of full view present
5365 elsif Present
(Full_View
(E
)) then
5367 -- If full view has already been frozen, then no further
5368 -- processing is required
5370 if Is_Frozen
(Full_View
(E
)) then
5371 Set_Has_Delayed_Freeze
(E
, False);
5372 Set_Freeze_Node
(E
, Empty
);
5374 -- Otherwise freeze full view and patch the pointers so that
5375 -- the freeze node will elaborate both views in the back end.
5376 -- However, if full view is itself private, freeze underlying
5377 -- full view instead and patch the pointers so that the freeze
5378 -- node will elaborate the three views in the back end.
5382 Full
: Entity_Id
:= Full_View
(E
);
5385 if Is_Private_Type
(Full
)
5386 and then Present
(Underlying_Full_View
(Full
))
5388 Full
:= Underlying_Full_View
(Full
);
5391 Freeze_And_Append
(Full
, N
, Result
);
5393 if Full
/= Full_View
(E
)
5394 and then Has_Delayed_Freeze
(Full_View
(E
))
5396 F_Node
:= Freeze_Node
(Full
);
5398 if Present
(F_Node
) then
5399 Set_Freeze_Node
(Full_View
(E
), F_Node
);
5400 Set_Entity
(F_Node
, Full_View
(E
));
5403 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
5404 Set_Freeze_Node
(Full_View
(E
), Empty
);
5408 if Has_Delayed_Freeze
(E
) then
5409 F_Node
:= Freeze_Node
(Full_View
(E
));
5411 if Present
(F_Node
) then
5412 Set_Freeze_Node
(E
, F_Node
);
5413 Set_Entity
(F_Node
, E
);
5416 -- {Incomplete,Private}_Subtypes with Full_Views
5417 -- constrained by discriminants.
5419 Set_Has_Delayed_Freeze
(E
, False);
5420 Set_Freeze_Node
(E
, Empty
);
5426 Check_Debug_Info_Needed
(E
);
5428 -- AI-117 requires that the convention of a partial view be the
5429 -- same as the convention of the full view. Note that this is a
5430 -- recognized breach of privacy, but it's essential for logical
5431 -- consistency of representation, and the lack of a rule in
5432 -- RM95 was an oversight.
5434 Set_Convention
(E
, Convention
(Full_View
(E
)));
5436 Set_Size_Known_At_Compile_Time
(E
,
5437 Size_Known_At_Compile_Time
(Full_View
(E
)));
5439 -- Size information is copied from the full view to the
5440 -- incomplete or private view for consistency.
5442 -- We skip this is the full view is not a type. This is very
5443 -- strange of course, and can only happen as a result of
5444 -- certain illegalities, such as a premature attempt to derive
5445 -- from an incomplete type.
5447 if Is_Type
(Full_View
(E
)) then
5448 Set_Size_Info
(E
, Full_View
(E
));
5449 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
5455 -- Case of underlying full view present
5457 elsif Is_Private_Type
(E
)
5458 and then Present
(Underlying_Full_View
(E
))
5460 if not Is_Frozen
(Underlying_Full_View
(E
)) then
5461 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
5464 -- Patch the pointers so that the freeze node will elaborate
5465 -- both views in the back end.
5467 if Has_Delayed_Freeze
(E
) then
5468 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
5470 if Present
(F_Node
) then
5471 Set_Freeze_Node
(E
, F_Node
);
5472 Set_Entity
(F_Node
, E
);
5475 Set_Has_Delayed_Freeze
(E
, False);
5476 Set_Freeze_Node
(E
, Empty
);
5480 Check_Debug_Info_Needed
(E
);
5485 -- Case of no full view present. If entity is derived or subtype,
5486 -- it is safe to freeze, correctness depends on the frozen status
5487 -- of parent. Otherwise it is either premature usage, or a Taft
5488 -- amendment type, so diagnosis is at the point of use and the
5489 -- type might be frozen later.
5491 elsif E
/= Base_Type
(E
) or else Is_Derived_Type
(E
) then
5495 Set_Is_Frozen
(E
, False);
5500 -- For access subprogram, freeze types of all formals, the return
5501 -- type was already frozen, since it is the Etype of the function.
5502 -- Formal types can be tagged Taft amendment types, but otherwise
5503 -- they cannot be incomplete.
5505 elsif Ekind
(E
) = E_Subprogram_Type
then
5506 Formal
:= First_Formal
(E
);
5507 while Present
(Formal
) loop
5508 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
5509 and then No
(Full_View
(Etype
(Formal
)))
5510 and then not Is_Value_Type
(Etype
(Formal
))
5512 if Is_Tagged_Type
(Etype
(Formal
)) then
5515 -- AI05-151: Incomplete types are allowed in access to
5516 -- subprogram specifications.
5518 elsif Ada_Version
< Ada_2012
then
5520 ("invalid use of incomplete type&", E
, Etype
(Formal
));
5524 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
5525 Next_Formal
(Formal
);
5528 Freeze_Subprogram
(E
);
5530 -- For access to a protected subprogram, freeze the equivalent type
5531 -- (however this is not set if we are not generating code or if this
5532 -- is an anonymous type used just for resolution).
5534 elsif Is_Access_Protected_Subprogram_Type
(E
) then
5535 if Present
(Equivalent_Type
(E
)) then
5536 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5540 -- Generic types are never seen by the back-end, and are also not
5541 -- processed by the expander (since the expander is turned off for
5542 -- generic processing), so we never need freeze nodes for them.
5544 if Is_Generic_Type
(E
) then
5549 -- Some special processing for non-generic types to complete
5550 -- representation details not known till the freeze point.
5552 if Is_Fixed_Point_Type
(E
) then
5553 Freeze_Fixed_Point_Type
(E
);
5555 -- Some error checks required for ordinary fixed-point type. Defer
5556 -- these till the freeze-point since we need the small and range
5557 -- values. We only do these checks for base types
5559 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
5560 if Small_Value
(E
) < Ureal_2_M_80
then
5561 Error_Msg_Name_1
:= Name_Small
;
5563 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
5565 elsif Small_Value
(E
) > Ureal_2_80
then
5566 Error_Msg_Name_1
:= Name_Small
;
5568 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
5571 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
5572 Error_Msg_Name_1
:= Name_First
;
5574 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
5577 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
5578 Error_Msg_Name_1
:= Name_Last
;
5580 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
5584 elsif Is_Enumeration_Type
(E
) then
5585 Freeze_Enumeration_Type
(E
);
5587 elsif Is_Integer_Type
(E
) then
5588 Adjust_Esize_For_Alignment
(E
);
5590 if Is_Modular_Integer_Type
(E
)
5591 and then Warn_On_Suspicious_Modulus_Value
5593 Check_Suspicious_Modulus
(E
);
5596 -- The pool applies to named and anonymous access types, but not
5597 -- to subprogram and to internal types generated for 'Access
5600 elsif Is_Access_Type
(E
)
5601 and then not Is_Access_Subprogram_Type
(E
)
5602 and then Ekind
(E
) /= E_Access_Attribute_Type
5604 -- If a pragma Default_Storage_Pool applies, and this type has no
5605 -- Storage_Pool or Storage_Size clause (which must have occurred
5606 -- before the freezing point), then use the default. This applies
5607 -- only to base types.
5609 -- None of this applies to access to subprograms, for which there
5610 -- are clearly no pools.
5612 if Present
(Default_Pool
)
5613 and then Is_Base_Type
(E
)
5614 and then not Has_Storage_Size_Clause
(E
)
5615 and then No
(Associated_Storage_Pool
(E
))
5617 -- Case of pragma Default_Storage_Pool (null)
5619 if Nkind
(Default_Pool
) = N_Null
then
5620 Set_No_Pool_Assigned
(E
);
5622 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
5625 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
5629 -- Check restriction for standard storage pool
5631 if No
(Associated_Storage_Pool
(E
)) then
5632 Check_Restriction
(No_Standard_Storage_Pools
, E
);
5635 -- Deal with error message for pure access type. This is not an
5636 -- error in Ada 2005 if there is no pool (see AI-366).
5638 if Is_Pure_Unit_Access_Type
(E
)
5639 and then (Ada_Version
< Ada_2005
5640 or else not No_Pool_Assigned
(E
))
5641 and then not Is_Generic_Unit
(Scope
(E
))
5643 Error_Msg_N
("named access type not allowed in pure unit", E
);
5645 if Ada_Version
>= Ada_2005
then
5647 ("\would be legal if Storage_Size of 0 given??", E
);
5649 elsif No_Pool_Assigned
(E
) then
5651 ("\would be legal in Ada 2005??", E
);
5655 ("\would be legal in Ada 2005 if "
5656 & "Storage_Size of 0 given??", E
);
5661 -- Case of composite types
5663 if Is_Composite_Type
(E
) then
5665 -- AI-117 requires that all new primitives of a tagged type must
5666 -- inherit the convention of the full view of the type. Inherited
5667 -- and overriding operations are defined to inherit the convention
5668 -- of their parent or overridden subprogram (also specified in
5669 -- AI-117), which will have occurred earlier (in Derive_Subprogram
5670 -- and New_Overloaded_Entity). Here we set the convention of
5671 -- primitives that are still convention Ada, which will ensure
5672 -- that any new primitives inherit the type's convention. Class-
5673 -- wide types can have a foreign convention inherited from their
5674 -- specific type, but are excluded from this since they don't have
5675 -- any associated primitives.
5677 if Is_Tagged_Type
(E
)
5678 and then not Is_Class_Wide_Type
(E
)
5679 and then Convention
(E
) /= Convention_Ada
5682 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
5686 Prim
:= First_Elmt
(Prim_List
);
5687 while Present
(Prim
) loop
5688 if Convention
(Node
(Prim
)) = Convention_Ada
then
5689 Set_Convention
(Node
(Prim
), Convention
(E
));
5697 -- If the type is a simple storage pool type, then this is where
5698 -- we attempt to locate and validate its Allocate, Deallocate, and
5699 -- Storage_Size operations (the first is required, and the latter
5700 -- two are optional). We also verify that the full type for a
5701 -- private type is allowed to be a simple storage pool type.
5703 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
5704 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
5706 -- If the type is marked Has_Private_Declaration, then this is
5707 -- a full type for a private type that was specified with the
5708 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
5709 -- pragma is allowed for the full type (for example, it can't
5710 -- be an array type, or a nonlimited record type).
5712 if Has_Private_Declaration
(E
) then
5713 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
5714 and then not Is_Private_Type
(E
)
5716 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
5718 ("pragma% can only apply to full type that is an " &
5719 "explicitly limited type", E
);
5723 Validate_Simple_Pool_Ops
: declare
5724 Pool_Type
: Entity_Id
renames E
;
5725 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
5726 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
5728 procedure Validate_Simple_Pool_Op_Formal
5729 (Pool_Op
: Entity_Id
;
5730 Pool_Op_Formal
: in out Entity_Id
;
5731 Expected_Mode
: Formal_Kind
;
5732 Expected_Type
: Entity_Id
;
5733 Formal_Name
: String;
5734 OK_Formal
: in out Boolean);
5735 -- Validate one formal Pool_Op_Formal of the candidate pool
5736 -- operation Pool_Op. The formal must be of Expected_Type
5737 -- and have mode Expected_Mode. OK_Formal will be set to
5738 -- False if the formal doesn't match. If OK_Formal is False
5739 -- on entry, then the formal will effectively be ignored
5740 -- (because validation of the pool op has already failed).
5741 -- Upon return, Pool_Op_Formal will be updated to the next
5744 procedure Validate_Simple_Pool_Operation
5745 (Op_Name
: Name_Id
);
5746 -- Search for and validate a simple pool operation with the
5747 -- name Op_Name. If the name is Allocate, then there must be
5748 -- exactly one such primitive operation for the simple pool
5749 -- type. If the name is Deallocate or Storage_Size, then
5750 -- there can be at most one such primitive operation. The
5751 -- profile of the located primitive must conform to what
5752 -- is expected for each operation.
5754 ------------------------------------
5755 -- Validate_Simple_Pool_Op_Formal --
5756 ------------------------------------
5758 procedure Validate_Simple_Pool_Op_Formal
5759 (Pool_Op
: Entity_Id
;
5760 Pool_Op_Formal
: in out Entity_Id
;
5761 Expected_Mode
: Formal_Kind
;
5762 Expected_Type
: Entity_Id
;
5763 Formal_Name
: String;
5764 OK_Formal
: in out Boolean)
5767 -- If OK_Formal is False on entry, then simply ignore
5768 -- the formal, because an earlier formal has already
5771 if not OK_Formal
then
5774 -- If no formal is passed in, then issue an error for a
5777 elsif not Present
(Pool_Op_Formal
) then
5779 ("simple storage pool op missing formal " &
5780 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
5786 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
5788 -- If the pool type was expected for this formal, then
5789 -- this will not be considered a candidate operation
5790 -- for the simple pool, so we unset OK_Formal so that
5791 -- the op and any later formals will be ignored.
5793 if Expected_Type
= Pool_Type
then
5800 ("wrong type for formal " & Formal_Name
&
5801 " of simple storage pool op; expected type&",
5802 Pool_Op_Formal
, Expected_Type
);
5806 -- Issue error if formal's mode is not the expected one
5808 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
5810 ("wrong mode for formal of simple storage pool op",
5814 -- Advance to the next formal
5816 Next_Formal
(Pool_Op_Formal
);
5817 end Validate_Simple_Pool_Op_Formal
;
5819 ------------------------------------
5820 -- Validate_Simple_Pool_Operation --
5821 ------------------------------------
5823 procedure Validate_Simple_Pool_Operation
5827 Found_Op
: Entity_Id
:= Empty
;
5833 (Nam_In
(Op_Name
, Name_Allocate
,
5835 Name_Storage_Size
));
5837 Error_Msg_Name_1
:= Op_Name
;
5839 -- For each homonym declared immediately in the scope
5840 -- of the simple storage pool type, determine whether
5841 -- the homonym is an operation of the pool type, and,
5842 -- if so, check that its profile is as expected for
5843 -- a simple pool operation of that name.
5845 Op
:= Get_Name_Entity_Id
(Op_Name
);
5846 while Present
(Op
) loop
5847 if Ekind_In
(Op
, E_Function
, E_Procedure
)
5848 and then Scope
(Op
) = Current_Scope
5850 Formal
:= First_Entity
(Op
);
5854 -- The first parameter must be of the pool type
5855 -- in order for the operation to qualify.
5857 if Op_Name
= Name_Storage_Size
then
5858 Validate_Simple_Pool_Op_Formal
5859 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
5862 Validate_Simple_Pool_Op_Formal
5863 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
5867 -- If another operation with this name has already
5868 -- been located for the type, then flag an error,
5869 -- since we only allow the type to have a single
5872 if Present
(Found_Op
) and then Is_OK
then
5874 ("only one % operation allowed for " &
5875 "simple storage pool type&", Op
, Pool_Type
);
5878 -- In the case of Allocate and Deallocate, a formal
5879 -- of type System.Address is required.
5881 if Op_Name
= Name_Allocate
then
5882 Validate_Simple_Pool_Op_Formal
5883 (Op
, Formal
, E_Out_Parameter
,
5884 Address_Type
, "Storage_Address", Is_OK
);
5886 elsif Op_Name
= Name_Deallocate
then
5887 Validate_Simple_Pool_Op_Formal
5888 (Op
, Formal
, E_In_Parameter
,
5889 Address_Type
, "Storage_Address", Is_OK
);
5892 -- In the case of Allocate and Deallocate, formals
5893 -- of type Storage_Count are required as the third
5894 -- and fourth parameters.
5896 if Op_Name
/= Name_Storage_Size
then
5897 Validate_Simple_Pool_Op_Formal
5898 (Op
, Formal
, E_In_Parameter
,
5899 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
5900 Validate_Simple_Pool_Op_Formal
5901 (Op
, Formal
, E_In_Parameter
,
5902 Stg_Cnt_Type
, "Alignment", Is_OK
);
5905 -- If no mismatched formals have been found (Is_OK)
5906 -- and no excess formals are present, then this
5907 -- operation has been validated, so record it.
5909 if not Present
(Formal
) and then Is_OK
then
5917 -- There must be a valid Allocate operation for the type,
5918 -- so issue an error if none was found.
5920 if Op_Name
= Name_Allocate
5921 and then not Present
(Found_Op
)
5923 Error_Msg_N
("missing % operation for simple " &
5924 "storage pool type", Pool_Type
);
5926 elsif Present
(Found_Op
) then
5928 -- Simple pool operations can't be abstract
5930 if Is_Abstract_Subprogram
(Found_Op
) then
5932 ("simple storage pool operation must not be " &
5933 "abstract", Found_Op
);
5936 -- The Storage_Size operation must be a function with
5937 -- Storage_Count as its result type.
5939 if Op_Name
= Name_Storage_Size
then
5940 if Ekind
(Found_Op
) = E_Procedure
then
5942 ("% operation must be a function", Found_Op
);
5944 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
5946 ("wrong result type for%, expected type&",
5947 Found_Op
, Stg_Cnt_Type
);
5950 -- Allocate and Deallocate must be procedures
5952 elsif Ekind
(Found_Op
) = E_Function
then
5954 ("% operation must be a procedure", Found_Op
);
5957 end Validate_Simple_Pool_Operation
;
5959 -- Start of processing for Validate_Simple_Pool_Ops
5962 Validate_Simple_Pool_Operation
(Name_Allocate
);
5963 Validate_Simple_Pool_Operation
(Name_Deallocate
);
5964 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
5965 end Validate_Simple_Pool_Ops
;
5969 -- Now that all types from which E may depend are frozen, see if the
5970 -- size is known at compile time, if it must be unsigned, or if
5971 -- strict alignment is required
5973 Check_Compile_Time_Size
(E
);
5974 Check_Unsigned_Type
(E
);
5976 if Base_Type
(E
) = E
then
5977 Check_Strict_Alignment
(E
);
5980 -- Do not allow a size clause for a type which does not have a size
5981 -- that is known at compile time
5983 if Has_Size_Clause
(E
)
5984 and then not Size_Known_At_Compile_Time
(E
)
5986 -- Suppress this message if errors posted on E, even if we are
5987 -- in all errors mode, since this is often a junk message
5989 if not Error_Posted
(E
) then
5991 ("size clause not allowed for variable length type",
5996 -- Now we set/verify the representation information, in particular
5997 -- the size and alignment values. This processing is not required for
5998 -- generic types, since generic types do not play any part in code
5999 -- generation, and so the size and alignment values for such types
6000 -- are irrelevant. Ditto for types declared within a generic unit,
6001 -- which may have components that depend on generic parameters, and
6002 -- that will be recreated in an instance.
6004 if Inside_A_Generic
then
6007 -- Otherwise we call the layout procedure
6013 -- If this is an access to subprogram whose designated type is itself
6014 -- a subprogram type, the return type of this anonymous subprogram
6015 -- type must be decorated as well.
6017 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
6018 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
6020 Layout_Type
(Etype
(Designated_Type
(E
)));
6023 -- If the type has a Defaut_Value/Default_Component_Value aspect,
6024 -- this is where we analye the expression (after the type is frozen,
6025 -- since in the case of Default_Value, we are analyzing with the
6026 -- type itself, and we treat Default_Component_Value similarly for
6027 -- the sake of uniformity).
6029 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
6036 if Is_Scalar_Type
(E
) then
6037 Nam
:= Name_Default_Value
;
6039 Exp
:= Default_Aspect_Value
(Typ
);
6041 Nam
:= Name_Default_Component_Value
;
6042 Typ
:= Component_Type
(E
);
6043 Exp
:= Default_Aspect_Component_Value
(E
);
6046 Analyze_And_Resolve
(Exp
, Typ
);
6048 if Etype
(Exp
) /= Any_Type
then
6049 if not Is_OK_Static_Expression
(Exp
) then
6050 Error_Msg_Name_1
:= Nam
;
6051 Flag_Non_Static_Expr
6052 ("aspect% requires static expression", Exp
);
6058 -- End of freeze processing for type entities
6061 -- Here is where we logically freeze the current entity. If it has a
6062 -- freeze node, then this is the point at which the freeze node is
6063 -- linked into the result list.
6065 if Has_Delayed_Freeze
(E
) then
6067 -- If a freeze node is already allocated, use it, otherwise allocate
6068 -- a new one. The preallocation happens in the case of anonymous base
6069 -- types, where we preallocate so that we can set First_Subtype_Link.
6070 -- Note that we reset the Sloc to the current freeze location.
6072 if Present
(Freeze_Node
(E
)) then
6073 F_Node
:= Freeze_Node
(E
);
6074 Set_Sloc
(F_Node
, Loc
);
6077 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
6078 Set_Freeze_Node
(E
, F_Node
);
6079 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
6080 Set_TSS_Elist
(F_Node
, No_Elist
);
6081 Set_Actions
(F_Node
, No_List
);
6084 Set_Entity
(F_Node
, E
);
6085 Add_To_Result
(F_Node
);
6087 -- A final pass over record types with discriminants. If the type
6088 -- has an incomplete declaration, there may be constrained access
6089 -- subtypes declared elsewhere, which do not depend on the discrimi-
6090 -- nants of the type, and which are used as component types (i.e.
6091 -- the full view is a recursive type). The designated types of these
6092 -- subtypes can only be elaborated after the type itself, and they
6093 -- need an itype reference.
6095 if Ekind
(E
) = E_Record_Type
6096 and then Has_Discriminants
(E
)
6104 Comp
:= First_Component
(E
);
6105 while Present
(Comp
) loop
6106 Typ
:= Etype
(Comp
);
6108 if Ekind
(Comp
) = E_Component
6109 and then Is_Access_Type
(Typ
)
6110 and then Scope
(Typ
) /= E
6111 and then Base_Type
(Designated_Type
(Typ
)) = E
6112 and then Is_Itype
(Designated_Type
(Typ
))
6114 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
6115 Set_Itype
(IR
, Designated_Type
(Typ
));
6116 Append
(IR
, Result
);
6119 Next_Component
(Comp
);
6125 -- When a type is frozen, the first subtype of the type is frozen as
6126 -- well (RM 13.14(15)). This has to be done after freezing the type,
6127 -- since obviously the first subtype depends on its own base type.
6130 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
6132 -- If we just froze a tagged non-class wide record, then freeze the
6133 -- corresponding class-wide type. This must be done after the tagged
6134 -- type itself is frozen, because the class-wide type refers to the
6135 -- tagged type which generates the class.
6137 if Is_Tagged_Type
(E
)
6138 and then not Is_Class_Wide_Type
(E
)
6139 and then Present
(Class_Wide_Type
(E
))
6141 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
6145 Check_Debug_Info_Needed
(E
);
6147 -- Special handling for subprograms
6149 if Is_Subprogram
(E
) then
6151 -- If subprogram has address clause then reset Is_Public flag, since
6152 -- we do not want the backend to generate external references.
6154 if Present
(Address_Clause
(E
))
6155 and then not Is_Library_Level_Entity
(E
)
6157 Set_Is_Public
(E
, False);
6165 -----------------------------
6166 -- Freeze_Enumeration_Type --
6167 -----------------------------
6169 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
6171 -- By default, if no size clause is present, an enumeration type with
6172 -- Convention C is assumed to interface to a C enum, and has integer
6173 -- size. This applies to types. For subtypes, verify that its base
6174 -- type has no size clause either. Treat other foreign conventions
6175 -- in the same way, and also make sure alignment is set right.
6177 if Has_Foreign_Convention
(Typ
)
6178 and then not Has_Size_Clause
(Typ
)
6179 and then not Has_Size_Clause
(Base_Type
(Typ
))
6180 and then Esize
(Typ
) < Standard_Integer_Size
6182 -- Don't do this if Short_Enums on target
6184 and then not Target_Short_Enums
6186 Init_Esize
(Typ
, Standard_Integer_Size
);
6187 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
6189 -- Normal Ada case or size clause present or not Long_C_Enums on target
6192 -- If the enumeration type interfaces to C, and it has a size clause
6193 -- that specifies less than int size, it warrants a warning. The
6194 -- user may intend the C type to be an enum or a char, so this is
6195 -- not by itself an error that the Ada compiler can detect, but it
6196 -- it is a worth a heads-up. For Boolean and Character types we
6197 -- assume that the programmer has the proper C type in mind.
6199 if Convention
(Typ
) = Convention_C
6200 and then Has_Size_Clause
(Typ
)
6201 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
6202 and then not Is_Boolean_Type
(Typ
)
6203 and then not Is_Character_Type
(Typ
)
6205 -- Don't do this if Short_Enums on target
6207 and then not Target_Short_Enums
6210 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
6213 Adjust_Esize_For_Alignment
(Typ
);
6215 end Freeze_Enumeration_Type
;
6217 -----------------------
6218 -- Freeze_Expression --
6219 -----------------------
6221 procedure Freeze_Expression
(N
: Node_Id
) is
6222 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
6225 Desig_Typ
: Entity_Id
;
6229 Freeze_Outside
: Boolean := False;
6230 -- This flag is set true if the entity must be frozen outside the
6231 -- current subprogram. This happens in the case of expander generated
6232 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
6233 -- not freeze all entities like other bodies, but which nevertheless
6234 -- may reference entities that have to be frozen before the body and
6235 -- obviously cannot be frozen inside the body.
6237 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
6238 -- If the expression is an array aggregate, the type of the component
6239 -- expressions is also frozen. If the component type is an access type
6240 -- and the expressions include allocators, the designed type is frozen
6243 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
6244 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
6245 -- it is the handled statement sequence of an expander-generated
6246 -- subprogram (init proc, stream subprogram, or renaming as body).
6247 -- If so, this is not a freezing context.
6249 -----------------------------------------
6250 -- Find_Aggregate_Component_Desig_Type --
6251 -----------------------------------------
6253 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
6258 if Present
(Expressions
(N
)) then
6259 Exp
:= First
(Expressions
(N
));
6260 while Present
(Exp
) loop
6261 if Nkind
(Exp
) = N_Allocator
then
6262 return Designated_Type
(Component_Type
(Etype
(N
)));
6269 if Present
(Component_Associations
(N
)) then
6270 Assoc
:= First
(Component_Associations
(N
));
6271 while Present
(Assoc
) loop
6272 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
6273 return Designated_Type
(Component_Type
(Etype
(N
)));
6281 end Find_Aggregate_Component_Desig_Type
;
6283 ----------------------
6284 -- In_Expanded_Body --
6285 ----------------------
6287 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
6292 if Nkind
(N
) = N_Subprogram_Body
then
6298 if Nkind
(P
) /= N_Subprogram_Body
then
6302 Id
:= Defining_Unit_Name
(Specification
(P
));
6304 -- The following are expander-created bodies, or bodies that
6305 -- are not freeze points.
6307 if Nkind
(Id
) = N_Defining_Identifier
6308 and then (Is_Init_Proc
(Id
)
6309 or else Is_TSS
(Id
, TSS_Stream_Input
)
6310 or else Is_TSS
(Id
, TSS_Stream_Output
)
6311 or else Is_TSS
(Id
, TSS_Stream_Read
)
6312 or else Is_TSS
(Id
, TSS_Stream_Write
)
6313 or else Nkind_In
(Original_Node
(P
),
6314 N_Subprogram_Renaming_Declaration
,
6315 N_Expression_Function
))
6322 end In_Expanded_Body
;
6324 -- Start of processing for Freeze_Expression
6327 -- Immediate return if freezing is inhibited. This flag is set by the
6328 -- analyzer to stop freezing on generated expressions that would cause
6329 -- freezing if they were in the source program, but which are not
6330 -- supposed to freeze, since they are created.
6332 if Must_Not_Freeze
(N
) then
6336 -- If expression is non-static, then it does not freeze in a default
6337 -- expression, see section "Handling of Default Expressions" in the
6338 -- spec of package Sem for further details. Note that we have to make
6339 -- sure that we actually have a real expression (if we have a subtype
6340 -- indication, we can't test Is_OK_Static_Expression). However, we
6341 -- exclude the case of the prefix of an attribute of a static scalar
6342 -- subtype from this early return, because static subtype attributes
6343 -- should always cause freezing, even in default expressions, but
6344 -- the attribute may not have been marked as static yet (because in
6345 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
6346 -- Freeze_Expression on the prefix).
6349 and then Nkind
(N
) in N_Subexpr
6350 and then not Is_OK_Static_Expression
(N
)
6351 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
6352 or else not (Is_Entity_Name
(N
)
6353 and then Is_Type
(Entity
(N
))
6354 and then Is_OK_Static_Subtype
(Entity
(N
))))
6359 -- Freeze type of expression if not frozen already
6363 if Nkind
(N
) in N_Has_Etype
then
6364 if not Is_Frozen
(Etype
(N
)) then
6367 -- Base type may be an derived numeric type that is frozen at
6368 -- the point of declaration, but first_subtype is still unfrozen.
6370 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
6371 Typ
:= First_Subtype
(Etype
(N
));
6375 -- For entity name, freeze entity if not frozen already. A special
6376 -- exception occurs for an identifier that did not come from source.
6377 -- We don't let such identifiers freeze a non-internal entity, i.e.
6378 -- an entity that did come from source, since such an identifier was
6379 -- generated by the expander, and cannot have any semantic effect on
6380 -- the freezing semantics. For example, this stops the parameter of
6381 -- an initialization procedure from freezing the variable.
6383 if Is_Entity_Name
(N
)
6384 and then not Is_Frozen
(Entity
(N
))
6385 and then (Nkind
(N
) /= N_Identifier
6386 or else Comes_From_Source
(N
)
6387 or else not Comes_From_Source
(Entity
(N
)))
6391 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
6392 Check_Expression_Function
(N
, Nam
);
6399 -- For an allocator freeze designated type if not frozen already
6401 -- For an aggregate whose component type is an access type, freeze the
6402 -- designated type now, so that its freeze does not appear within the
6403 -- loop that might be created in the expansion of the aggregate. If the
6404 -- designated type is a private type without full view, the expression
6405 -- cannot contain an allocator, so the type is not frozen.
6407 -- For a function, we freeze the entity when the subprogram declaration
6408 -- is frozen, but a function call may appear in an initialization proc.
6409 -- before the declaration is frozen. We need to generate the extra
6410 -- formals, if any, to ensure that the expansion of the call includes
6411 -- the proper actuals. This only applies to Ada subprograms, not to
6418 Desig_Typ
:= Designated_Type
(Etype
(N
));
6421 if Is_Array_Type
(Etype
(N
))
6422 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
6425 -- Check whether aggregate includes allocators.
6427 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
6430 when N_Selected_Component |
6431 N_Indexed_Component |
6434 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6435 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
6438 when N_Identifier
=>
6440 and then Ekind
(Nam
) = E_Function
6441 and then Nkind
(Parent
(N
)) = N_Function_Call
6442 and then Convention
(Nam
) = Convention_Ada
6444 Create_Extra_Formals
(Nam
);
6451 if Desig_Typ
/= Empty
6452 and then (Is_Frozen
(Desig_Typ
)
6453 or else (not Is_Fully_Defined
(Desig_Typ
)))
6458 -- All done if nothing needs freezing
6462 and then No
(Desig_Typ
)
6467 -- Examine the enclosing context by climbing the parent chain. The
6468 -- traversal serves two purposes - to detect scenarios where freezeing
6469 -- is not needed and to find the proper insertion point for the freeze
6470 -- nodes. Although somewhat similar to Insert_Actions, this traversal
6471 -- is freezing semantics-sensitive. Inserting freeze nodes blindly in
6472 -- the tree may result in types being frozen too early.
6476 Parent_P
:= Parent
(P
);
6478 -- If we don't have a parent, then we are not in a well-formed tree.
6479 -- This is an unusual case, but there are some legitimate situations
6480 -- in which this occurs, notably when the expressions in the range of
6481 -- a type declaration are resolved. We simply ignore the freeze
6482 -- request in this case. Is this right ???
6484 if No
(Parent_P
) then
6488 -- See if we have got to an appropriate point in the tree
6490 case Nkind
(Parent_P
) is
6492 -- A special test for the exception of (RM 13.14(8)) for the case
6493 -- of per-object expressions (RM 3.8(18)) occurring in component
6494 -- definition or a discrete subtype definition. Note that we test
6495 -- for a component declaration which includes both cases we are
6496 -- interested in, and furthermore the tree does not have explicit
6497 -- nodes for either of these two constructs.
6499 when N_Component_Declaration
=>
6501 -- The case we want to test for here is an identifier that is
6502 -- a per-object expression, this is either a discriminant that
6503 -- appears in a context other than the component declaration
6504 -- or it is a reference to the type of the enclosing construct.
6506 -- For either of these cases, we skip the freezing
6508 if not In_Spec_Expression
6509 and then Nkind
(N
) = N_Identifier
6510 and then (Present
(Entity
(N
)))
6512 -- We recognize the discriminant case by just looking for
6513 -- a reference to a discriminant. It can only be one for
6514 -- the enclosing construct. Skip freezing in this case.
6516 if Ekind
(Entity
(N
)) = E_Discriminant
then
6519 -- For the case of a reference to the enclosing record,
6520 -- (or task or protected type), we look for a type that
6521 -- matches the current scope.
6523 elsif Entity
(N
) = Current_Scope
then
6528 -- If we have an enumeration literal that appears as the choice in
6529 -- the aggregate of an enumeration representation clause, then
6530 -- freezing does not occur (RM 13.14(10)).
6532 when N_Enumeration_Representation_Clause
=>
6534 -- The case we are looking for is an enumeration literal
6536 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
6537 and then Is_Enumeration_Type
(Etype
(N
))
6539 -- If enumeration literal appears directly as the choice,
6540 -- do not freeze (this is the normal non-overloaded case)
6542 if Nkind
(Parent
(N
)) = N_Component_Association
6543 and then First
(Choices
(Parent
(N
))) = N
6547 -- If enumeration literal appears as the name of function
6548 -- which is the choice, then also do not freeze. This
6549 -- happens in the overloaded literal case, where the
6550 -- enumeration literal is temporarily changed to a function
6551 -- call for overloading analysis purposes.
6553 elsif Nkind
(Parent
(N
)) = N_Function_Call
6555 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
6557 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
6563 -- Normally if the parent is a handled sequence of statements,
6564 -- then the current node must be a statement, and that is an
6565 -- appropriate place to insert a freeze node.
6567 when N_Handled_Sequence_Of_Statements
=>
6569 -- An exception occurs when the sequence of statements is for
6570 -- an expander generated body that did not do the usual freeze
6571 -- all operation. In this case we usually want to freeze
6572 -- outside this body, not inside it, and we skip past the
6573 -- subprogram body that we are inside.
6575 if In_Expanded_Body
(Parent_P
) then
6577 Subp
: constant Node_Id
:= Parent
(Parent_P
);
6581 -- Freeze the entity only when it is declared inside the
6582 -- body of the expander generated procedure. This case
6583 -- is recognized by the scope of the entity or its type,
6584 -- which is either the spec for some enclosing body, or
6585 -- (in the case of init_procs, for which there are no
6586 -- separate specs) the current scope.
6588 if Nkind
(Subp
) = N_Subprogram_Body
then
6589 Spec
:= Corresponding_Spec
(Subp
);
6591 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
6593 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
6598 and then Scope
(Typ
) = Current_Scope
6599 and then Defining_Entity
(Subp
) = Current_Scope
6605 -- An expression function may act as a completion of
6606 -- a function declaration. As such, it can reference
6607 -- entities declared between the two views:
6610 -- function F return ...;
6612 -- function Hidden return ...;
6613 -- function F return ... is (Hidden); -- 2
6615 -- Refering to the example above, freezing the expression
6616 -- of F (2) would place Hidden's freeze node (1) in the
6617 -- wrong place. Avoid explicit freezing and let the usual
6618 -- scenarios do the job - for example, reaching the end
6619 -- of the private declarations, or a call to F.
6621 if Nkind
(Original_Node
(Subp
)) =
6622 N_Expression_Function
6626 -- Freeze outside the body
6629 Parent_P
:= Parent
(Parent_P
);
6630 Freeze_Outside
:= True;
6634 -- Here if normal case where we are in handled statement
6635 -- sequence and want to do the insertion right there.
6641 -- If parent is a body or a spec or a block, then the current node
6642 -- is a statement or declaration and we can insert the freeze node
6645 when N_Block_Statement |
6648 N_Package_Specification |
6651 N_Task_Body
=> exit;
6653 -- The expander is allowed to define types in any statements list,
6654 -- so any of the following parent nodes also mark a freezing point
6655 -- if the actual node is in a list of statements or declarations.
6657 when N_Abortable_Part |
6658 N_Accept_Alternative |
6660 N_Case_Statement_Alternative |
6661 N_Compilation_Unit_Aux |
6662 N_Conditional_Entry_Call |
6663 N_Delay_Alternative |
6665 N_Entry_Call_Alternative |
6666 N_Exception_Handler |
6667 N_Extended_Return_Statement |
6671 N_Selective_Accept |
6672 N_Triggering_Alternative
=>
6674 exit when Is_List_Member
(P
);
6676 -- Freeze nodes produced by an expression coming from the Actions
6677 -- list of a N_Expression_With_Actions node must remain within the
6678 -- Actions list. Inserting the freeze nodes further up the tree
6679 -- may lead to use before declaration issues in the case of array
6682 when N_Expression_With_Actions
=>
6683 if Is_List_Member
(P
)
6684 and then List_Containing
(P
) = Actions
(Parent_P
)
6689 -- Note: N_Loop_Statement is a special case. A type that appears
6690 -- in the source can never be frozen in a loop (this occurs only
6691 -- because of a loop expanded by the expander), so we keep on
6692 -- going. Otherwise we terminate the search. Same is true of any
6693 -- entity which comes from source. (if they have predefined type,
6694 -- that type does not appear to come from source, but the entity
6695 -- should not be frozen here).
6697 when N_Loop_Statement
=>
6698 exit when not Comes_From_Source
(Etype
(N
))
6699 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
6701 -- For all other cases, keep looking at parents
6707 -- We fall through the case if we did not yet find the proper
6708 -- place in the free for inserting the freeze node, so climb.
6713 -- If the expression appears in a record or an initialization procedure,
6714 -- the freeze nodes are collected and attached to the current scope, to
6715 -- be inserted and analyzed on exit from the scope, to insure that
6716 -- generated entities appear in the correct scope. If the expression is
6717 -- a default for a discriminant specification, the scope is still void.
6718 -- The expression can also appear in the discriminant part of a private
6719 -- or concurrent type.
6721 -- If the expression appears in a constrained subcomponent of an
6722 -- enclosing record declaration, the freeze nodes must be attached to
6723 -- the outer record type so they can eventually be placed in the
6724 -- enclosing declaration list.
6726 -- The other case requiring this special handling is if we are in a
6727 -- default expression, since in that case we are about to freeze a
6728 -- static type, and the freeze scope needs to be the outer scope, not
6729 -- the scope of the subprogram with the default parameter.
6731 -- For default expressions and other spec expressions in generic units,
6732 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
6733 -- placing them at the proper place, after the generic unit.
6735 if (In_Spec_Exp
and not Inside_A_Generic
)
6736 or else Freeze_Outside
6737 or else (Is_Type
(Current_Scope
)
6738 and then (not Is_Concurrent_Type
(Current_Scope
)
6739 or else not Has_Completion
(Current_Scope
)))
6740 or else Ekind
(Current_Scope
) = E_Void
6743 N
: constant Node_Id
:= Current_Scope
;
6744 Freeze_Nodes
: List_Id
:= No_List
;
6745 Pos
: Int
:= Scope_Stack
.Last
;
6748 if Present
(Desig_Typ
) then
6749 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
6752 if Present
(Typ
) then
6753 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
6756 if Present
(Nam
) then
6757 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
6760 -- The current scope may be that of a constrained component of
6761 -- an enclosing record declaration, or of a loop of an enclosing
6762 -- quantified expression, which is above the current scope in the
6763 -- scope stack. Indeed in the context of a quantified expression,
6764 -- a scope is created and pushed above the current scope in order
6765 -- to emulate the loop-like behavior of the quantified expression.
6766 -- If the expression is within a top-level pragma, as for a pre-
6767 -- condition on a library-level subprogram, nothing to do.
6769 if not Is_Compilation_Unit
(Current_Scope
)
6770 and then (Is_Record_Type
(Scope
(Current_Scope
))
6771 or else Nkind
(Parent
(Current_Scope
)) =
6772 N_Quantified_Expression
)
6777 if Is_Non_Empty_List
(Freeze_Nodes
) then
6778 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
6779 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
6782 Append_List
(Freeze_Nodes
,
6783 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
6791 -- Now we have the right place to do the freezing. First, a special
6792 -- adjustment, if we are in spec-expression analysis mode, these freeze
6793 -- actions must not be thrown away (normally all inserted actions are
6794 -- thrown away in this mode. However, the freeze actions are from static
6795 -- expressions and one of the important reasons we are doing this
6796 -- special analysis is to get these freeze actions. Therefore we turn
6797 -- off the In_Spec_Expression mode to propagate these freeze actions.
6798 -- This also means they get properly analyzed and expanded.
6800 In_Spec_Expression
:= False;
6802 -- Freeze the designated type of an allocator (RM 13.14(13))
6804 if Present
(Desig_Typ
) then
6805 Freeze_Before
(P
, Desig_Typ
);
6808 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
6809 -- the enumeration representation clause exception in the loop above.
6811 if Present
(Typ
) then
6812 Freeze_Before
(P
, Typ
);
6815 -- Freeze name if one is present (RM 13.14(11))
6817 if Present
(Nam
) then
6818 Freeze_Before
(P
, Nam
);
6821 -- Restore In_Spec_Expression flag
6823 In_Spec_Expression
:= In_Spec_Exp
;
6824 end Freeze_Expression
;
6826 -----------------------------
6827 -- Freeze_Fixed_Point_Type --
6828 -----------------------------
6830 -- Certain fixed-point types and subtypes, including implicit base types
6831 -- and declared first subtypes, have not yet set up a range. This is
6832 -- because the range cannot be set until the Small and Size values are
6833 -- known, and these are not known till the type is frozen.
6835 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
6836 -- whose bounds are unanalyzed real literals. This routine will recognize
6837 -- this case, and transform this range node into a properly typed range
6838 -- with properly analyzed and resolved values.
6840 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
6841 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
6842 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
6843 Hi
: constant Node_Id
:= High_Bound
(Rng
);
6844 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6845 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
6846 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
6847 BHi
: constant Node_Id
:= High_Bound
(Brng
);
6848 Small
: constant Ureal
:= Small_Value
(Typ
);
6855 -- Save original bounds (for shaving tests)
6858 -- Actual size chosen
6860 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
6861 -- Returns size of type with given bounds. Also leaves these
6862 -- bounds set as the current bounds of the Typ.
6868 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
6870 Set_Realval
(Lo
, Lov
);
6871 Set_Realval
(Hi
, Hiv
);
6872 return Minimum_Size
(Typ
);
6875 -- Start of processing for Freeze_Fixed_Point_Type
6878 -- If Esize of a subtype has not previously been set, set it now
6880 if Unknown_Esize
(Typ
) then
6881 Atype
:= Ancestor_Subtype
(Typ
);
6883 if Present
(Atype
) then
6884 Set_Esize
(Typ
, Esize
(Atype
));
6886 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
6890 -- Immediate return if the range is already analyzed. This means that
6891 -- the range is already set, and does not need to be computed by this
6894 if Analyzed
(Rng
) then
6898 -- Immediate return if either of the bounds raises Constraint_Error
6900 if Raises_Constraint_Error
(Lo
)
6901 or else Raises_Constraint_Error
(Hi
)
6906 Loval
:= Realval
(Lo
);
6907 Hival
:= Realval
(Hi
);
6912 -- Ordinary fixed-point case
6914 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
6916 -- For the ordinary fixed-point case, we are allowed to fudge the
6917 -- end-points up or down by small. Generally we prefer to fudge up,
6918 -- i.e. widen the bounds for non-model numbers so that the end points
6919 -- are included. However there are cases in which this cannot be
6920 -- done, and indeed cases in which we may need to narrow the bounds.
6921 -- The following circuit makes the decision.
6923 -- Note: our terminology here is that Incl_EP means that the bounds
6924 -- are widened by Small if necessary to include the end points, and
6925 -- Excl_EP means that the bounds are narrowed by Small to exclude the
6926 -- end-points if this reduces the size.
6928 -- Note that in the Incl case, all we care about is including the
6929 -- end-points. In the Excl case, we want to narrow the bounds as
6930 -- much as permitted by the RM, to give the smallest possible size.
6933 Loval_Incl_EP
: Ureal
;
6934 Hival_Incl_EP
: Ureal
;
6936 Loval_Excl_EP
: Ureal
;
6937 Hival_Excl_EP
: Ureal
;
6943 First_Subt
: Entity_Id
;
6948 -- First step. Base types are required to be symmetrical. Right
6949 -- now, the base type range is a copy of the first subtype range.
6950 -- This will be corrected before we are done, but right away we
6951 -- need to deal with the case where both bounds are non-negative.
6952 -- In this case, we set the low bound to the negative of the high
6953 -- bound, to make sure that the size is computed to include the
6954 -- required sign. Note that we do not need to worry about the
6955 -- case of both bounds negative, because the sign will be dealt
6956 -- with anyway. Furthermore we can't just go making such a bound
6957 -- symmetrical, since in a twos-complement system, there is an
6958 -- extra negative value which could not be accommodated on the
6962 and then not UR_Is_Negative
(Loval
)
6963 and then Hival
> Loval
6966 Set_Realval
(Lo
, Loval
);
6969 -- Compute the fudged bounds. If the number is a model number,
6970 -- then we do nothing to include it, but we are allowed to backoff
6971 -- to the next adjacent model number when we exclude it. If it is
6972 -- not a model number then we straddle the two values with the
6973 -- model numbers on either side.
6975 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
6977 if Loval
= Model_Num
then
6978 Loval_Incl_EP
:= Model_Num
;
6980 Loval_Incl_EP
:= Model_Num
- Small
;
6983 -- The low value excluding the end point is Small greater, but
6984 -- we do not do this exclusion if the low value is positive,
6985 -- since it can't help the size and could actually hurt by
6986 -- crossing the high bound.
6988 if UR_Is_Negative
(Loval_Incl_EP
) then
6989 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
6991 -- If the value went from negative to zero, then we have the
6992 -- case where Loval_Incl_EP is the model number just below
6993 -- zero, so we want to stick to the negative value for the
6994 -- base type to maintain the condition that the size will
6995 -- include signed values.
6998 and then UR_Is_Zero
(Loval_Excl_EP
)
7000 Loval_Excl_EP
:= Loval_Incl_EP
;
7004 Loval_Excl_EP
:= Loval_Incl_EP
;
7007 -- Similar processing for upper bound and high value
7009 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
7011 if Hival
= Model_Num
then
7012 Hival_Incl_EP
:= Model_Num
;
7014 Hival_Incl_EP
:= Model_Num
+ Small
;
7017 if UR_Is_Positive
(Hival_Incl_EP
) then
7018 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
7020 Hival_Excl_EP
:= Hival_Incl_EP
;
7023 -- One further adjustment is needed. In the case of subtypes, we
7024 -- cannot go outside the range of the base type, or we get
7025 -- peculiarities, and the base type range is already set. This
7026 -- only applies to the Incl values, since clearly the Excl values
7027 -- are already as restricted as they are allowed to be.
7030 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
7031 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
7034 -- Get size including and excluding end points
7036 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
7037 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
7039 -- No need to exclude end-points if it does not reduce size
7041 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
7042 Loval_Excl_EP
:= Loval_Incl_EP
;
7045 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
7046 Hival_Excl_EP
:= Hival_Incl_EP
;
7049 -- Now we set the actual size to be used. We want to use the
7050 -- bounds fudged up to include the end-points but only if this
7051 -- can be done without violating a specifically given size
7052 -- size clause or causing an unacceptable increase in size.
7054 -- Case of size clause given
7056 if Has_Size_Clause
(Typ
) then
7058 -- Use the inclusive size only if it is consistent with
7059 -- the explicitly specified size.
7061 if Size_Incl_EP
<= RM_Size
(Typ
) then
7062 Actual_Lo
:= Loval_Incl_EP
;
7063 Actual_Hi
:= Hival_Incl_EP
;
7064 Actual_Size
:= Size_Incl_EP
;
7066 -- If the inclusive size is too large, we try excluding
7067 -- the end-points (will be caught later if does not work).
7070 Actual_Lo
:= Loval_Excl_EP
;
7071 Actual_Hi
:= Hival_Excl_EP
;
7072 Actual_Size
:= Size_Excl_EP
;
7075 -- Case of size clause not given
7078 -- If we have a base type whose corresponding first subtype
7079 -- has an explicit size that is large enough to include our
7080 -- end-points, then do so. There is no point in working hard
7081 -- to get a base type whose size is smaller than the specified
7082 -- size of the first subtype.
7084 First_Subt
:= First_Subtype
(Typ
);
7086 if Has_Size_Clause
(First_Subt
)
7087 and then Size_Incl_EP
<= Esize
(First_Subt
)
7089 Actual_Size
:= Size_Incl_EP
;
7090 Actual_Lo
:= Loval_Incl_EP
;
7091 Actual_Hi
:= Hival_Incl_EP
;
7093 -- If excluding the end-points makes the size smaller and
7094 -- results in a size of 8,16,32,64, then we take the smaller
7095 -- size. For the 64 case, this is compulsory. For the other
7096 -- cases, it seems reasonable. We like to include end points
7097 -- if we can, but not at the expense of moving to the next
7098 -- natural boundary of size.
7100 elsif Size_Incl_EP
/= Size_Excl_EP
7101 and then Addressable
(Size_Excl_EP
)
7103 Actual_Size
:= Size_Excl_EP
;
7104 Actual_Lo
:= Loval_Excl_EP
;
7105 Actual_Hi
:= Hival_Excl_EP
;
7107 -- Otherwise we can definitely include the end points
7110 Actual_Size
:= Size_Incl_EP
;
7111 Actual_Lo
:= Loval_Incl_EP
;
7112 Actual_Hi
:= Hival_Incl_EP
;
7115 -- One pathological case: normally we never fudge a low bound
7116 -- down, since it would seem to increase the size (if it has
7117 -- any effect), but for ranges containing single value, or no
7118 -- values, the high bound can be small too large. Consider:
7120 -- type t is delta 2.0**(-14)
7121 -- range 131072.0 .. 0;
7123 -- That lower bound is *just* outside the range of 32 bits, and
7124 -- does need fudging down in this case. Note that the bounds
7125 -- will always have crossed here, since the high bound will be
7126 -- fudged down if necessary, as in the case of:
7128 -- type t is delta 2.0**(-14)
7129 -- range 131072.0 .. 131072.0;
7131 -- So we detect the situation by looking for crossed bounds,
7132 -- and if the bounds are crossed, and the low bound is greater
7133 -- than zero, we will always back it off by small, since this
7134 -- is completely harmless.
7136 if Actual_Lo
> Actual_Hi
then
7137 if UR_Is_Positive
(Actual_Lo
) then
7138 Actual_Lo
:= Loval_Incl_EP
- Small
;
7139 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
7141 -- And of course, we need to do exactly the same parallel
7142 -- fudge for flat ranges in the negative region.
7144 elsif UR_Is_Negative
(Actual_Hi
) then
7145 Actual_Hi
:= Hival_Incl_EP
+ Small
;
7146 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
7151 Set_Realval
(Lo
, Actual_Lo
);
7152 Set_Realval
(Hi
, Actual_Hi
);
7155 -- For the decimal case, none of this fudging is required, since there
7156 -- are no end-point problems in the decimal case (the end-points are
7157 -- always included).
7160 Actual_Size
:= Fsize
(Loval
, Hival
);
7163 -- At this stage, the actual size has been calculated and the proper
7164 -- required bounds are stored in the low and high bounds.
7166 if Actual_Size
> 64 then
7167 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
7169 ("size required (^) for type& too large, maximum allowed is 64",
7174 -- Check size against explicit given size
7176 if Has_Size_Clause
(Typ
) then
7177 if Actual_Size
> RM_Size
(Typ
) then
7178 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7179 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
7181 ("size given (^) for type& too small, minimum allowed is ^",
7182 Size_Clause
(Typ
), Typ
);
7185 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
7188 -- Increase size to next natural boundary if no size clause given
7191 if Actual_Size
<= 8 then
7193 elsif Actual_Size
<= 16 then
7195 elsif Actual_Size
<= 32 then
7201 Init_Esize
(Typ
, Actual_Size
);
7202 Adjust_Esize_For_Alignment
(Typ
);
7205 -- If we have a base type, then expand the bounds so that they extend to
7206 -- the full width of the allocated size in bits, to avoid junk range
7207 -- checks on intermediate computations.
7209 if Base_Type
(Typ
) = Typ
then
7210 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
7211 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
7214 -- Final step is to reanalyze the bounds using the proper type
7215 -- and set the Corresponding_Integer_Value fields of the literals.
7217 Set_Etype
(Lo
, Empty
);
7218 Set_Analyzed
(Lo
, False);
7221 -- Resolve with universal fixed if the base type, and the base type if
7222 -- it is a subtype. Note we can't resolve the base type with itself,
7223 -- that would be a reference before definition.
7226 Resolve
(Lo
, Universal_Fixed
);
7231 -- Set corresponding integer value for bound
7233 Set_Corresponding_Integer_Value
7234 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
7236 -- Similar processing for high bound
7238 Set_Etype
(Hi
, Empty
);
7239 Set_Analyzed
(Hi
, False);
7243 Resolve
(Hi
, Universal_Fixed
);
7248 Set_Corresponding_Integer_Value
7249 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
7251 -- Set type of range to correspond to bounds
7253 Set_Etype
(Rng
, Etype
(Lo
));
7255 -- Set Esize to calculated size if not set already
7257 if Unknown_Esize
(Typ
) then
7258 Init_Esize
(Typ
, Actual_Size
);
7261 -- Set RM_Size if not already set. If already set, check value
7264 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
7267 if RM_Size
(Typ
) /= Uint_0
then
7268 if RM_Size
(Typ
) < Minsiz
then
7269 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7270 Error_Msg_Uint_2
:= Minsiz
;
7272 ("size given (^) for type& too small, minimum allowed is ^",
7273 Size_Clause
(Typ
), Typ
);
7277 Set_RM_Size
(Typ
, Minsiz
);
7281 -- Check for shaving
7283 if Comes_From_Source
(Typ
) then
7284 if Orig_Lo
< Expr_Value_R
(Lo
) then
7286 ("declared low bound of type & is outside type range??", Typ
);
7288 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
7291 if Orig_Hi
> Expr_Value_R
(Hi
) then
7293 ("declared high bound of type & is outside type range??", Typ
);
7295 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
7298 end Freeze_Fixed_Point_Type
;
7304 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
7308 Set_Has_Delayed_Freeze
(T
);
7309 L
:= Freeze_Entity
(T
, N
);
7311 if Is_Non_Empty_List
(L
) then
7312 Insert_Actions
(N
, L
);
7316 --------------------------
7317 -- Freeze_Static_Object --
7318 --------------------------
7320 procedure Freeze_Static_Object
(E
: Entity_Id
) is
7322 Cannot_Be_Static
: exception;
7323 -- Exception raised if the type of a static object cannot be made
7324 -- static. This happens if the type depends on non-global objects.
7326 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
7327 -- Called to ensure that an expression used as part of a type definition
7328 -- is statically allocatable, which means that the expression type is
7329 -- statically allocatable, and the expression is either static, or a
7330 -- reference to a library level constant.
7332 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
7333 -- Called to mark a type as static, checking that it is possible
7334 -- to set the type as static. If it is not possible, then the
7335 -- exception Cannot_Be_Static is raised.
7337 -----------------------------
7338 -- Ensure_Expression_Is_SA --
7339 -----------------------------
7341 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
7345 Ensure_Type_Is_SA
(Etype
(N
));
7347 if Is_OK_Static_Expression
(N
) then
7350 elsif Nkind
(N
) = N_Identifier
then
7354 and then Ekind
(Ent
) = E_Constant
7355 and then Is_Library_Level_Entity
(Ent
)
7361 raise Cannot_Be_Static
;
7362 end Ensure_Expression_Is_SA
;
7364 -----------------------
7365 -- Ensure_Type_Is_SA --
7366 -----------------------
7368 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
7373 -- If type is library level, we are all set
7375 if Is_Library_Level_Entity
(Typ
) then
7379 -- We are also OK if the type already marked as statically allocated,
7380 -- which means we processed it before.
7382 if Is_Statically_Allocated
(Typ
) then
7386 -- Mark type as statically allocated
7388 Set_Is_Statically_Allocated
(Typ
);
7390 -- Check that it is safe to statically allocate this type
7392 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
7393 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
7394 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
7396 elsif Is_Array_Type
(Typ
) then
7397 N
:= First_Index
(Typ
);
7398 while Present
(N
) loop
7399 Ensure_Type_Is_SA
(Etype
(N
));
7403 Ensure_Type_Is_SA
(Component_Type
(Typ
));
7405 elsif Is_Access_Type
(Typ
) then
7406 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
7410 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
7413 if T
/= Standard_Void_Type
then
7414 Ensure_Type_Is_SA
(T
);
7417 F
:= First_Formal
(Designated_Type
(Typ
));
7418 while Present
(F
) loop
7419 Ensure_Type_Is_SA
(Etype
(F
));
7425 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
7428 elsif Is_Record_Type
(Typ
) then
7429 C
:= First_Entity
(Typ
);
7430 while Present
(C
) loop
7431 if Ekind
(C
) = E_Discriminant
7432 or else Ekind
(C
) = E_Component
7434 Ensure_Type_Is_SA
(Etype
(C
));
7436 elsif Is_Type
(C
) then
7437 Ensure_Type_Is_SA
(C
);
7443 elsif Ekind
(Typ
) = E_Subprogram_Type
then
7444 Ensure_Type_Is_SA
(Etype
(Typ
));
7446 C
:= First_Formal
(Typ
);
7447 while Present
(C
) loop
7448 Ensure_Type_Is_SA
(Etype
(C
));
7453 raise Cannot_Be_Static
;
7455 end Ensure_Type_Is_SA
;
7457 -- Start of processing for Freeze_Static_Object
7460 Ensure_Type_Is_SA
(Etype
(E
));
7463 when Cannot_Be_Static
=>
7465 -- If the object that cannot be static is imported or exported, then
7466 -- issue an error message saying that this object cannot be imported
7467 -- or exported. If it has an address clause it is an overlay in the
7468 -- current partition and the static requirement is not relevant.
7469 -- Do not issue any error message when ignoring rep clauses.
7471 if Ignore_Rep_Clauses
then
7474 elsif Is_Imported
(E
) then
7475 if No
(Address_Clause
(E
)) then
7477 ("& cannot be imported (local type is not constant)", E
);
7480 -- Otherwise must be exported, something is wrong if compiler
7481 -- is marking something as statically allocated which cannot be).
7483 else pragma Assert
(Is_Exported
(E
));
7485 ("& cannot be exported (local type is not constant)", E
);
7487 end Freeze_Static_Object
;
7489 -----------------------
7490 -- Freeze_Subprogram --
7491 -----------------------
7493 procedure Freeze_Subprogram
(E
: Entity_Id
) is
7498 -- Subprogram may not have an address clause unless it is imported
7500 if Present
(Address_Clause
(E
)) then
7501 if not Is_Imported
(E
) then
7503 ("address clause can only be given " &
7504 "for imported subprogram",
7505 Name
(Address_Clause
(E
)));
7509 -- Reset the Pure indication on an imported subprogram unless an
7510 -- explicit Pure_Function pragma was present or the subprogram is an
7511 -- intrinsic. We do this because otherwise it is an insidious error
7512 -- to call a non-pure function from pure unit and have calls
7513 -- mysteriously optimized away. What happens here is that the Import
7514 -- can bypass the normal check to ensure that pure units call only pure
7517 -- The reason for the intrinsic exception is that in general, intrinsic
7518 -- functions (such as shifts) are pure anyway. The only exceptions are
7519 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
7520 -- in any case, so no problem arises.
7523 and then Is_Pure
(E
)
7524 and then not Has_Pragma_Pure_Function
(E
)
7525 and then not Is_Intrinsic_Subprogram
(E
)
7527 Set_Is_Pure
(E
, False);
7530 -- For non-foreign convention subprograms, this is where we create
7531 -- the extra formals (for accessibility level and constrained bit
7532 -- information). We delay this till the freeze point precisely so
7533 -- that we know the convention.
7535 if not Has_Foreign_Convention
(E
) then
7536 Create_Extra_Formals
(E
);
7539 -- If this is convention Ada and a Valued_Procedure, that's odd
7541 if Ekind
(E
) = E_Procedure
7542 and then Is_Valued_Procedure
(E
)
7543 and then Convention
(E
) = Convention_Ada
7544 and then Warn_On_Export_Import
7547 ("??Valued_Procedure has no effect for convention Ada", E
);
7548 Set_Is_Valued_Procedure
(E
, False);
7551 -- Case of foreign convention
7556 -- For foreign conventions, warn about return of unconstrained array
7558 if Ekind
(E
) = E_Function
then
7559 Retype
:= Underlying_Type
(Etype
(E
));
7561 -- If no return type, probably some other error, e.g. a
7562 -- missing full declaration, so ignore.
7567 -- If the return type is generic, we have emitted a warning
7568 -- earlier on, and there is nothing else to check here. Specific
7569 -- instantiations may lead to erroneous behavior.
7571 elsif Is_Generic_Type
(Etype
(E
)) then
7574 -- Display warning if returning unconstrained array
7576 elsif Is_Array_Type
(Retype
)
7577 and then not Is_Constrained
(Retype
)
7579 -- Check appropriate warning is enabled (should we check for
7580 -- Warnings (Off) on specific entities here, probably so???)
7582 and then Warn_On_Export_Import
7584 -- Exclude the VM case, since return of unconstrained arrays
7585 -- is properly handled in both the JVM and .NET cases.
7587 and then VM_Target
= No_VM
7590 ("?x?foreign convention function& should not return " &
7591 "unconstrained array", E
);
7596 -- If any of the formals for an exported foreign convention
7597 -- subprogram have defaults, then emit an appropriate warning since
7598 -- this is odd (default cannot be used from non-Ada code)
7600 if Is_Exported
(E
) then
7601 F
:= First_Formal
(E
);
7602 while Present
(F
) loop
7603 if Warn_On_Export_Import
7604 and then Present
(Default_Value
(F
))
7607 ("?x?parameter cannot be defaulted in non-Ada call",
7616 -- Pragma Inline_Always is disallowed for dispatching subprograms
7617 -- because the address of such subprograms is saved in the dispatch
7618 -- table to support dispatching calls, and dispatching calls cannot
7619 -- be inlined. This is consistent with the restriction against using
7620 -- 'Access or 'Address on an Inline_Always subprogram.
7622 if Is_Dispatching_Operation
(E
)
7623 and then Has_Pragma_Inline_Always
(E
)
7626 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
7629 -- Because of the implicit representation of inherited predefined
7630 -- operators in the front-end, the overriding status of the operation
7631 -- may be affected when a full view of a type is analyzed, and this is
7632 -- not captured by the analysis of the corresponding type declaration.
7633 -- Therefore the correctness of a not-overriding indicator must be
7634 -- rechecked when the subprogram is frozen.
7636 if Nkind
(E
) = N_Defining_Operator_Symbol
7637 and then not Error_Posted
(Parent
(E
))
7639 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
7641 end Freeze_Subprogram
;
7643 ----------------------
7644 -- Is_Fully_Defined --
7645 ----------------------
7647 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
7649 if Ekind
(T
) = E_Class_Wide_Type
then
7650 return Is_Fully_Defined
(Etype
(T
));
7652 elsif Is_Array_Type
(T
) then
7653 return Is_Fully_Defined
(Component_Type
(T
));
7655 elsif Is_Record_Type
(T
)
7656 and not Is_Private_Type
(T
)
7658 -- Verify that the record type has no components with private types
7659 -- without completion.
7665 Comp
:= First_Component
(T
);
7666 while Present
(Comp
) loop
7667 if not Is_Fully_Defined
(Etype
(Comp
)) then
7671 Next_Component
(Comp
);
7676 -- For the designated type of an access to subprogram, all types in
7677 -- the profile must be fully defined.
7679 elsif Ekind
(T
) = E_Subprogram_Type
then
7684 F
:= First_Formal
(T
);
7685 while Present
(F
) loop
7686 if not Is_Fully_Defined
(Etype
(F
)) then
7693 return Is_Fully_Defined
(Etype
(T
));
7697 return not Is_Private_Type
(T
)
7698 or else Present
(Full_View
(Base_Type
(T
)));
7700 end Is_Fully_Defined
;
7702 ---------------------------------
7703 -- Process_Default_Expressions --
7704 ---------------------------------
7706 procedure Process_Default_Expressions
7708 After
: in out Node_Id
)
7710 Loc
: constant Source_Ptr
:= Sloc
(E
);
7717 Set_Default_Expressions_Processed
(E
);
7719 -- A subprogram instance and its associated anonymous subprogram share
7720 -- their signature. The default expression functions are defined in the
7721 -- wrapper packages for the anonymous subprogram, and should not be
7722 -- generated again for the instance.
7724 if Is_Generic_Instance
(E
)
7725 and then Present
(Alias
(E
))
7726 and then Default_Expressions_Processed
(Alias
(E
))
7731 Formal
:= First_Formal
(E
);
7732 while Present
(Formal
) loop
7733 if Present
(Default_Value
(Formal
)) then
7735 -- We work with a copy of the default expression because we
7736 -- do not want to disturb the original, since this would mess
7737 -- up the conformance checking.
7739 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
7741 -- The analysis of the expression may generate insert actions,
7742 -- which of course must not be executed. We wrap those actions
7743 -- in a procedure that is not called, and later on eliminated.
7744 -- The following cases have no side-effects, and are analyzed
7747 if Nkind
(Dcopy
) = N_Identifier
7748 or else Nkind_In
(Dcopy
, N_Expanded_Name
,
7750 N_Character_Literal
,
7753 or else (Nkind
(Dcopy
) = N_Attribute_Reference
7754 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
7755 or else Known_Null
(Dcopy
)
7757 -- If there is no default function, we must still do a full
7758 -- analyze call on the default value, to ensure that all error
7759 -- checks are performed, e.g. those associated with static
7760 -- evaluation. Note: this branch will always be taken if the
7761 -- analyzer is turned off (but we still need the error checks).
7763 -- Note: the setting of parent here is to meet the requirement
7764 -- that we can only analyze the expression while attached to
7765 -- the tree. Really the requirement is that the parent chain
7766 -- be set, we don't actually need to be in the tree.
7768 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
7771 -- Default expressions are resolved with their own type if the
7772 -- context is generic, to avoid anomalies with private types.
7774 if Ekind
(Scope
(E
)) = E_Generic_Package
then
7777 Resolve
(Dcopy
, Etype
(Formal
));
7780 -- If that resolved expression will raise constraint error,
7781 -- then flag the default value as raising constraint error.
7782 -- This allows a proper error message on the calls.
7784 if Raises_Constraint_Error
(Dcopy
) then
7785 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
7788 -- If the default is a parameterless call, we use the name of
7789 -- the called function directly, and there is no body to build.
7791 elsif Nkind
(Dcopy
) = N_Function_Call
7792 and then No
(Parameter_Associations
(Dcopy
))
7796 -- Else construct and analyze the body of a wrapper procedure
7797 -- that contains an object declaration to hold the expression.
7798 -- Given that this is done only to complete the analysis, it
7799 -- simpler to build a procedure than a function which might
7800 -- involve secondary stack expansion.
7803 Dnam
:= Make_Temporary
(Loc
, 'D');
7806 Make_Subprogram_Body
(Loc
,
7808 Make_Procedure_Specification
(Loc
,
7809 Defining_Unit_Name
=> Dnam
),
7811 Declarations
=> New_List
(
7812 Make_Object_Declaration
(Loc
,
7813 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
7814 Object_Definition
=>
7815 New_Occurrence_Of
(Etype
(Formal
), Loc
),
7816 Expression
=> New_Copy_Tree
(Dcopy
))),
7818 Handled_Statement_Sequence
=>
7819 Make_Handled_Sequence_Of_Statements
(Loc
,
7820 Statements
=> Empty_List
));
7822 Set_Scope
(Dnam
, Scope
(E
));
7823 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
7824 Set_Is_Eliminated
(Dnam
);
7825 Insert_After
(After
, Dbody
);
7831 Next_Formal
(Formal
);
7833 end Process_Default_Expressions
;
7835 ----------------------------------------
7836 -- Set_Component_Alignment_If_Not_Set --
7837 ----------------------------------------
7839 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
7841 -- Ignore if not base type, subtypes don't need anything
7843 if Typ
/= Base_Type
(Typ
) then
7847 -- Do not override existing representation
7849 if Is_Packed
(Typ
) then
7852 elsif Has_Specified_Layout
(Typ
) then
7855 elsif Component_Alignment
(Typ
) /= Calign_Default
then
7859 Set_Component_Alignment
7860 (Typ
, Scope_Stack
.Table
7861 (Scope_Stack
.Last
).Component_Alignment_Default
);
7863 end Set_Component_Alignment_If_Not_Set
;
7865 --------------------------
7866 -- Set_SSO_From_Default --
7867 --------------------------
7869 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
7873 -- Set default SSO for an array or record base type, except in case of
7874 -- a type extension (which always inherits the SSO of its parent type).
7877 and then (Is_Array_Type
(T
)
7878 or else (Is_Record_Type
(T
)
7879 and then not (Is_Tagged_Type
(T
)
7880 and then Is_Derived_Type
(T
))))
7883 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
7885 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
7887 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
7889 -- For a record type, if bit order is specified explicitly,
7890 -- then do not set SSO from default if not consistent. Note that
7891 -- we do not want to look at a Bit_Order attribute definition
7892 -- for a parent: if we were to inherit Bit_Order, then both
7893 -- SSO_Set_*_By_Default flags would have been cleared already
7894 -- (by Inherit_Aspects_At_Freeze_Point).
7899 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
7900 and then Reverse_Bit_Order
(T
) /= Reversed
)
7902 -- If flags cause reverse storage order, then set the result. Note
7903 -- that we would have ignored the pragma setting the non default
7904 -- storage order in any case, hence the assertion at this point.
7907 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
7909 Set_Reverse_Storage_Order
(T
, Reversed
);
7911 -- For a record type, also set reversed bit order. Note: if a bit
7912 -- order has been specified explicitly, then this is a no-op.
7914 if Is_Record_Type
(T
) then
7915 Set_Reverse_Bit_Order
(T
, Reversed
);
7919 end Set_SSO_From_Default
;
7925 procedure Undelay_Type
(T
: Entity_Id
) is
7927 Set_Has_Delayed_Freeze
(T
, False);
7928 Set_Freeze_Node
(T
, Empty
);
7930 -- Since we don't want T to have a Freeze_Node, we don't want its
7931 -- Full_View or Corresponding_Record_Type to have one either.
7933 -- ??? Fundamentally, this whole handling is unpleasant. What we really
7934 -- want is to be sure that for an Itype that's part of record R and is a
7935 -- subtype of type T, that it's frozen after the later of the freeze
7936 -- points of R and T. We have no way of doing that directly, so what we
7937 -- do is force most such Itypes to be frozen as part of freezing R via
7938 -- this procedure and only delay the ones that need to be delayed
7939 -- (mostly the designated types of access types that are defined as part
7942 if Is_Private_Type
(T
)
7943 and then Present
(Full_View
(T
))
7944 and then Is_Itype
(Full_View
(T
))
7945 and then Is_Record_Type
(Scope
(Full_View
(T
)))
7947 Undelay_Type
(Full_View
(T
));
7950 if Is_Concurrent_Type
(T
)
7951 and then Present
(Corresponding_Record_Type
(T
))
7952 and then Is_Itype
(Corresponding_Record_Type
(T
))
7953 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
7955 Undelay_Type
(Corresponding_Record_Type
(T
));
7963 procedure Warn_Overlay
7968 Ent
: constant Entity_Id
:= Entity
(Nam
);
7969 -- The object to which the address clause applies
7972 Old
: Entity_Id
:= Empty
;
7976 -- No warning if address clause overlay warnings are off
7978 if not Address_Clause_Overlay_Warnings
then
7982 -- No warning if there is an explicit initialization
7984 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
7986 if Present
(Init
) and then Comes_From_Source
(Init
) then
7990 -- We only give the warning for non-imported entities of a type for
7991 -- which a non-null base init proc is defined, or for objects of access
7992 -- types with implicit null initialization, or when Normalize_Scalars
7993 -- applies and the type is scalar or a string type (the latter being
7994 -- tested for because predefined String types are initialized by inline
7995 -- code rather than by an init_proc). Note that we do not give the
7996 -- warning for Initialize_Scalars, since we suppressed initialization
7997 -- in this case. Also, do not warn if Suppress_Initialization is set.
8000 and then not Is_Imported
(Ent
)
8001 and then not Initialization_Suppressed
(Typ
)
8002 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
8003 or else Is_Access_Type
(Typ
)
8004 or else (Normalize_Scalars
8005 and then (Is_Scalar_Type
(Typ
)
8006 or else Is_String_Type
(Typ
))))
8008 if Nkind
(Expr
) = N_Attribute_Reference
8009 and then Is_Entity_Name
(Prefix
(Expr
))
8011 Old
:= Entity
(Prefix
(Expr
));
8013 elsif Is_Entity_Name
(Expr
)
8014 and then Ekind
(Entity
(Expr
)) = E_Constant
8016 Decl
:= Declaration_Node
(Entity
(Expr
));
8018 if Nkind
(Decl
) = N_Object_Declaration
8019 and then Present
(Expression
(Decl
))
8020 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
8021 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
8023 Old
:= Entity
(Prefix
(Expression
(Decl
)));
8025 elsif Nkind
(Expr
) = N_Function_Call
then
8029 -- A function call (most likely to To_Address) is probably not an
8030 -- overlay, so skip warning. Ditto if the function call was inlined
8031 -- and transformed into an entity.
8033 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
8037 -- If a pragma Import follows, we assume that it is for the current
8038 -- target of the address clause, and skip the warning. There may be
8039 -- a source pragma or an aspect that specifies import and generates
8040 -- the corresponding pragma. These will indicate that the entity is
8041 -- imported and that is checked above so that the spurious warning
8042 -- (generated when the entity is frozen) will be suppressed. The
8043 -- pragma may be attached to the aspect, so it is not yet a list
8046 if Is_List_Member
(Parent
(Expr
)) then
8047 Decl
:= Next
(Parent
(Expr
));
8050 and then Nkind
(Decl
) = N_Pragma
8051 and then Pragma_Name
(Decl
) = Name_Import
8057 -- Otherwise give warning message
8059 if Present
(Old
) then
8060 Error_Msg_Node_2
:= Old
;
8062 ("default initialization of & may modify &??",
8066 ("default initialization of & may modify overlaid storage??",
8070 -- Add friendly warning if initialization comes from a packed array
8073 if Is_Record_Type
(Typ
) then
8078 Comp
:= First_Component
(Typ
);
8079 while Present
(Comp
) loop
8080 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
8081 and then Present
(Expression
(Parent
(Comp
)))
8084 elsif Is_Array_Type
(Etype
(Comp
))
8085 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
8088 ("\packed array component& " &
8089 "will be initialized to zero??",
8093 Next_Component
(Comp
);
8100 ("\use pragma Import for & to " &
8101 "suppress initialization (RM B.1(24))??",