1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Contracts
; use Contracts
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Exp_Ch3
; use Exp_Ch3
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Exp_Pakd
; use Exp_Pakd
;
37 with Exp_Util
; use Exp_Util
;
38 with Exp_Tss
; use Exp_Tss
;
39 with Ghost
; use Ghost
;
40 with Layout
; use Layout
;
42 with Namet
; use Namet
;
43 with Nlists
; use Nlists
;
44 with Nmake
; use Nmake
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Aux
; use Sem_Aux
;
51 with Sem_Cat
; use Sem_Cat
;
52 with Sem_Ch3
; use Sem_Ch3
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch7
; use Sem_Ch7
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Ch13
; use Sem_Ch13
;
57 with Sem_Eval
; use Sem_Eval
;
58 with Sem_Mech
; use Sem_Mech
;
59 with Sem_Prag
; use Sem_Prag
;
60 with Sem_Res
; use Sem_Res
;
61 with Sem_Util
; use Sem_Util
;
62 with Sinfo
; use Sinfo
;
63 with Snames
; use Snames
;
64 with Stand
; use Stand
;
65 with Targparm
; use Targparm
;
66 with Tbuild
; use Tbuild
;
67 with Ttypes
; use Ttypes
;
68 with Uintp
; use Uintp
;
69 with Urealp
; use Urealp
;
70 with Warnsw
; use Warnsw
;
72 package body Freeze
is
74 -----------------------
75 -- Local Subprograms --
76 -----------------------
78 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
79 -- Typ is a type that is being frozen. If no size clause is given,
80 -- but a default Esize has been computed, then this default Esize is
81 -- adjusted up if necessary to be consistent with a given alignment,
82 -- but never to a value greater than Long_Long_Integer'Size. This
83 -- is used for all discrete types and for fixed-point types.
85 procedure Build_And_Analyze_Renamed_Body
88 After
: in out Node_Id
);
89 -- Build body for a renaming declaration, insert in tree and analyze
91 procedure Check_Address_Clause
(E
: Entity_Id
);
92 -- Apply legality checks to address clauses for object declarations,
93 -- at the point the object is frozen. Also ensure any initialization is
94 -- performed only after the object has been frozen.
96 procedure Check_Component_Storage_Order
97 (Encl_Type
: Entity_Id
;
100 Comp_ADC_Present
: out Boolean);
101 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
102 -- clause, verify that the component type has an explicit and compatible
103 -- attribute/aspect. For arrays, Comp is Empty; for records, it is the
104 -- entity of the component under consideration. For an Encl_Type that
105 -- does not have a Scalar_Storage_Order attribute definition clause,
106 -- verify that the component also does not have such a clause.
107 -- ADC is the attribute definition clause if present (or Empty). On return,
108 -- Comp_ADC_Present is set True if the component has a Scalar_Storage_Order
109 -- attribute definition clause.
111 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
112 -- As each entity is frozen, this routine is called to deal with the
113 -- setting of Debug_Info_Needed for the entity. This flag is set if
114 -- the entity comes from source, or if we are in Debug_Generated_Code
115 -- mode or if the -gnatdV debug flag is set. However, it never sets
116 -- the flag if Debug_Info_Off is set. This procedure also ensures that
117 -- subsidiary entities have the flag set as required.
119 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
);
120 -- When an expression function is frozen by a use of it, the expression
121 -- itself is frozen. Check that the expression does not include references
122 -- to deferred constants without completion. We report this at the freeze
123 -- point of the function, to provide a better error message.
125 -- In most cases the expression itself is frozen by the time the function
126 -- itself is frozen, because the formals will be frozen by then. However,
127 -- Attribute references to outer types are freeze points for those types;
128 -- this routine generates the required freeze nodes for them.
130 procedure Check_Inherited_Conditions
(R
: Entity_Id
);
131 -- For a tagged derived type, create wrappers for inherited operations
132 -- that have a class-wide condition, so it can be properly rewritten if
133 -- it involves calls to other overriding primitives.
135 procedure Check_Strict_Alignment
(E
: Entity_Id
);
136 -- E is a base type. If E is tagged or has a component that is aliased
137 -- or tagged or contains something this is aliased or tagged, set
140 procedure Check_Unsigned_Type
(E
: Entity_Id
);
141 pragma Inline
(Check_Unsigned_Type
);
142 -- If E is a fixed-point or discrete type, then all the necessary work
143 -- to freeze it is completed except for possible setting of the flag
144 -- Is_Unsigned_Type, which is done by this procedure. The call has no
145 -- effect if the entity E is not a discrete or fixed-point type.
147 procedure Freeze_And_Append
150 Result
: in out List_Id
);
151 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
152 -- nodes to Result, modifying Result from No_List if necessary. N has
153 -- the same usage as in Freeze_Entity.
155 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
156 -- Freeze enumeration type. The Esize field is set as processing
157 -- proceeds (i.e. set by default when the type is declared and then
158 -- adjusted by rep clauses. What this procedure does is to make sure
159 -- that if a foreign convention is specified, and no specific size
160 -- is given, then the size must be at least Integer'Size.
162 procedure Freeze_Static_Object
(E
: Entity_Id
);
163 -- If an object is frozen which has Is_Statically_Allocated set, then
164 -- all referenced types must also be marked with this flag. This routine
165 -- is in charge of meeting this requirement for the object entity E.
167 procedure Freeze_Subprogram
(E
: Entity_Id
);
168 -- Perform freezing actions for a subprogram (create extra formals,
169 -- and set proper default mechanism values). Note that this routine
170 -- is not called for internal subprograms, for which neither of these
171 -- actions is needed (or desirable, we do not want for example to have
172 -- these extra formals present in initialization procedures, where they
173 -- would serve no purpose). In this call E is either a subprogram or
174 -- a subprogram type (i.e. an access to a subprogram).
176 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
177 -- True if T is not private and has no private components, or has a full
178 -- view. Used to determine whether the designated type of an access type
179 -- should be frozen when the access type is frozen. This is done when an
180 -- allocator is frozen, or an expression that may involve attributes of
181 -- the designated type. Otherwise freezing the access type does not freeze
182 -- the designated type.
184 procedure Process_Default_Expressions
186 After
: in out Node_Id
);
187 -- This procedure is called for each subprogram to complete processing of
188 -- default expressions at the point where all types are known to be frozen.
189 -- The expressions must be analyzed in full, to make sure that all error
190 -- processing is done (they have only been preanalyzed). If the expression
191 -- is not an entity or literal, its analysis may generate code which must
192 -- not be executed. In that case we build a function body to hold that
193 -- code. This wrapper function serves no other purpose (it used to be
194 -- called to evaluate the default, but now the default is inlined at each
197 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
198 -- Typ is a record or array type that is being frozen. This routine sets
199 -- the default component alignment from the scope stack values if the
200 -- alignment is otherwise not specified.
202 procedure Set_SSO_From_Default
(T
: Entity_Id
);
203 -- T is a record or array type that is being frozen. If it is a base type,
204 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
205 -- will be set appropriately. Note that an explicit occurrence of aspect
206 -- Scalar_Storage_Order or an explicit setting of this aspect with an
207 -- attribute definition clause occurs, then these two flags are reset in
208 -- any case, so call will have no effect.
210 procedure Undelay_Type
(T
: Entity_Id
);
211 -- T is a type of a component that we know to be an Itype. We don't want
212 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
213 -- Full_View or Corresponding_Record_Type.
215 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
);
216 -- Expr is the expression for an address clause for entity Nam whose type
217 -- is Typ. If Typ has a default initialization, and there is no explicit
218 -- initialization in the source declaration, check whether the address
219 -- clause might cause overlaying of an entity, and emit a warning on the
220 -- side effect that the initialization will cause.
222 -------------------------------
223 -- Adjust_Esize_For_Alignment --
224 -------------------------------
226 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
230 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
231 Align
:= Alignment_In_Bits
(Typ
);
233 if Align
> Esize
(Typ
)
234 and then Align
<= Standard_Long_Long_Integer_Size
236 Set_Esize
(Typ
, Align
);
239 end Adjust_Esize_For_Alignment
;
241 ------------------------------------
242 -- Build_And_Analyze_Renamed_Body --
243 ------------------------------------
245 procedure Build_And_Analyze_Renamed_Body
248 After
: in out Node_Id
)
250 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
251 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
253 Renamed_Subp
: Entity_Id
;
256 -- If the renamed subprogram is intrinsic, there is no need for a
257 -- wrapper body: we set the alias that will be called and expanded which
258 -- completes the declaration. This transformation is only legal if the
259 -- renamed entity has already been elaborated.
261 -- Note that it is legal for a renaming_as_body to rename an intrinsic
262 -- subprogram, as long as the renaming occurs before the new entity
263 -- is frozen (RM 8.5.4 (5)).
265 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
266 and then Is_Entity_Name
(Name
(Body_Decl
))
268 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
270 Renamed_Subp
:= Empty
;
273 if Present
(Renamed_Subp
)
274 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
276 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
277 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
279 -- We can make the renaming entity intrinsic if the renamed function
280 -- has an interface name, or if it is one of the shift/rotate
281 -- operations known to the compiler.
284 (Present
(Interface_Name
(Renamed_Subp
))
285 or else Nam_In
(Chars
(Renamed_Subp
), Name_Rotate_Left
,
289 Name_Shift_Right_Arithmetic
))
291 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
293 if Present
(Alias
(Renamed_Subp
)) then
294 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
296 Set_Alias
(Ent
, Renamed_Subp
);
299 Set_Is_Intrinsic_Subprogram
(Ent
);
300 Set_Has_Completion
(Ent
);
303 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
304 Insert_After
(After
, Body_Node
);
305 Mark_Rewrite_Insertion
(Body_Node
);
309 end Build_And_Analyze_Renamed_Body
;
311 ------------------------
312 -- Build_Renamed_Body --
313 ------------------------
315 function Build_Renamed_Body
317 New_S
: Entity_Id
) return Node_Id
319 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
320 -- We use for the source location of the renamed body, the location of
321 -- the spec entity. It might seem more natural to use the location of
322 -- the renaming declaration itself, but that would be wrong, since then
323 -- the body we create would look as though it was created far too late,
324 -- and this could cause problems with elaboration order analysis,
325 -- particularly in connection with instantiations.
327 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
328 Nam
: constant Node_Id
:= Name
(N
);
330 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
331 Actuals
: List_Id
:= No_List
;
336 O_Formal
: Entity_Id
;
337 Param_Spec
: Node_Id
;
339 Pref
: Node_Id
:= Empty
;
340 -- If the renamed entity is a primitive operation given in prefix form,
341 -- the prefix is the target object and it has to be added as the first
342 -- actual in the generated call.
345 -- Determine the entity being renamed, which is the target of the call
346 -- statement. If the name is an explicit dereference, this is a renaming
347 -- of a subprogram type rather than a subprogram. The name itself is
350 if Nkind
(Nam
) = N_Selected_Component
then
351 Old_S
:= Entity
(Selector_Name
(Nam
));
353 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
354 Old_S
:= Etype
(Nam
);
356 elsif Nkind
(Nam
) = N_Indexed_Component
then
357 if Is_Entity_Name
(Prefix
(Nam
)) then
358 Old_S
:= Entity
(Prefix
(Nam
));
360 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
363 elsif Nkind
(Nam
) = N_Character_Literal
then
364 Old_S
:= Etype
(New_S
);
367 Old_S
:= Entity
(Nam
);
370 if Is_Entity_Name
(Nam
) then
372 -- If the renamed entity is a predefined operator, retain full name
373 -- to ensure its visibility.
375 if Ekind
(Old_S
) = E_Operator
376 and then Nkind
(Nam
) = N_Expanded_Name
378 Call_Name
:= New_Copy
(Name
(N
));
380 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
384 if Nkind
(Nam
) = N_Selected_Component
385 and then Present
(First_Formal
(Old_S
))
387 (Is_Controlling_Formal
(First_Formal
(Old_S
))
388 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
391 -- Retrieve the target object, to be added as a first actual
394 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
395 Pref
:= Prefix
(Nam
);
398 Call_Name
:= New_Copy
(Name
(N
));
401 -- Original name may have been overloaded, but is fully resolved now
403 Set_Is_Overloaded
(Call_Name
, False);
406 -- For simple renamings, subsequent calls can be expanded directly as
407 -- calls to the renamed entity. The body must be generated in any case
408 -- for calls that may appear elsewhere. This is not done in the case
409 -- where the subprogram is an instantiation because the actual proper
410 -- body has not been built yet.
412 if Ekind_In
(Old_S
, E_Function
, E_Procedure
)
413 and then Nkind
(Decl
) = N_Subprogram_Declaration
414 and then not Is_Generic_Instance
(Old_S
)
416 Set_Body_To_Inline
(Decl
, Old_S
);
419 -- Check whether the return type is a limited view. If the subprogram
420 -- is already frozen the generated body may have a non-limited view
421 -- of the type, that must be used, because it is the one in the spec
422 -- of the renaming declaration.
424 if Ekind
(Old_S
) = E_Function
425 and then Is_Entity_Name
(Result_Definition
(Spec
))
428 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
430 if Has_Non_Limited_View
(Ret_Type
) then
431 Set_Result_Definition
432 (Spec
, New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
437 -- The body generated for this renaming is an internal artifact, and
438 -- does not constitute a freeze point for the called entity.
440 Set_Must_Not_Freeze
(Call_Name
);
442 Formal
:= First_Formal
(Defining_Entity
(Decl
));
444 if Present
(Pref
) then
446 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
447 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
450 -- The controlling formal may be an access parameter, or the
451 -- actual may be an access value, so adjust accordingly.
453 if Is_Access_Type
(Pref_Type
)
454 and then not Is_Access_Type
(Form_Type
)
457 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
459 elsif Is_Access_Type
(Form_Type
)
460 and then not Is_Access_Type
(Pref
)
464 Make_Attribute_Reference
(Loc
,
465 Attribute_Name
=> Name_Access
,
466 Prefix
=> Relocate_Node
(Pref
)));
468 Actuals
:= New_List
(Pref
);
472 elsif Present
(Formal
) then
479 if Present
(Formal
) then
480 while Present
(Formal
) loop
481 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
482 Next_Formal
(Formal
);
486 -- If the renamed entity is an entry, inherit its profile. For other
487 -- renamings as bodies, both profiles must be subtype conformant, so it
488 -- is not necessary to replace the profile given in the declaration.
489 -- However, default values that are aggregates are rewritten when
490 -- partially analyzed, so we recover the original aggregate to insure
491 -- that subsequent conformity checking works. Similarly, if the default
492 -- expression was constant-folded, recover the original expression.
494 Formal
:= First_Formal
(Defining_Entity
(Decl
));
496 if Present
(Formal
) then
497 O_Formal
:= First_Formal
(Old_S
);
498 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
499 while Present
(Formal
) loop
500 if Is_Entry
(Old_S
) then
501 if Nkind
(Parameter_Type
(Param_Spec
)) /=
504 Set_Etype
(Formal
, Etype
(O_Formal
));
505 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
508 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
509 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
510 Nkind
(Default_Value
(O_Formal
))
512 Set_Expression
(Param_Spec
,
513 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
516 Next_Formal
(Formal
);
517 Next_Formal
(O_Formal
);
522 -- If the renamed entity is a function, the generated body contains a
523 -- return statement. Otherwise, build a procedure call. If the entity is
524 -- an entry, subsequent analysis of the call will transform it into the
525 -- proper entry or protected operation call. If the renamed entity is
526 -- a character literal, return it directly.
528 if Ekind
(Old_S
) = E_Function
529 or else Ekind
(Old_S
) = E_Operator
530 or else (Ekind
(Old_S
) = E_Subprogram_Type
531 and then Etype
(Old_S
) /= Standard_Void_Type
)
534 Make_Simple_Return_Statement
(Loc
,
536 Make_Function_Call
(Loc
,
538 Parameter_Associations
=> Actuals
));
540 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
542 Make_Simple_Return_Statement
(Loc
,
543 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
545 elsif Nkind
(Nam
) = N_Character_Literal
then
547 Make_Simple_Return_Statement
(Loc
, Expression
=> Call_Name
);
551 Make_Procedure_Call_Statement
(Loc
,
553 Parameter_Associations
=> Actuals
);
556 -- Create entities for subprogram body and formals
558 Set_Defining_Unit_Name
(Spec
,
559 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
561 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
562 while Present
(Param_Spec
) loop
563 Set_Defining_Identifier
(Param_Spec
,
564 Make_Defining_Identifier
(Loc
,
565 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
570 Make_Subprogram_Body
(Loc
,
571 Specification
=> Spec
,
572 Declarations
=> New_List
,
573 Handled_Statement_Sequence
=>
574 Make_Handled_Sequence_Of_Statements
(Loc
,
575 Statements
=> New_List
(Call_Node
)));
577 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
579 Make_Subprogram_Declaration
(Loc
,
580 Specification
=> Specification
(N
)));
583 -- Link the body to the entity whose declaration it completes. If
584 -- the body is analyzed when the renamed entity is frozen, it may
585 -- be necessary to restore the proper scope (see package Exp_Ch13).
587 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
588 and then Present
(Corresponding_Spec
(N
))
590 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
592 Set_Corresponding_Spec
(Body_Node
, New_S
);
596 end Build_Renamed_Body
;
598 --------------------------
599 -- Check_Address_Clause --
600 --------------------------
602 procedure Check_Address_Clause
(E
: Entity_Id
) is
603 Addr
: constant Node_Id
:= Address_Clause
(E
);
604 Typ
: constant Entity_Id
:= Etype
(E
);
609 Tag_Assign
: Node_Id
;
612 if Present
(Addr
) then
614 -- For a deferred constant, the initialization value is on full view
616 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
617 Decl
:= Declaration_Node
(Full_View
(E
));
619 Decl
:= Declaration_Node
(E
);
622 Expr
:= Expression
(Addr
);
624 if Needs_Constant_Address
(Decl
, Typ
) then
625 Check_Constant_Address_Clause
(Expr
, E
);
627 -- Has_Delayed_Freeze was set on E when the address clause was
628 -- analyzed, and must remain set because we want the address
629 -- clause to be elaborated only after any entity it references
630 -- has been elaborated.
633 -- If Rep_Clauses are to be ignored, remove address clause from
634 -- list attached to entity, because it may be illegal for gigi,
635 -- for example by breaking order of elaboration..
637 if Ignore_Rep_Clauses
then
642 Rep
:= First_Rep_Item
(E
);
645 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
649 and then Next_Rep_Item
(Rep
) /= Addr
651 Rep
:= Next_Rep_Item
(Rep
);
655 if Present
(Rep
) then
656 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
660 -- And now remove the address clause
662 Kill_Rep_Clause
(Addr
);
664 elsif not Error_Posted
(Expr
)
665 and then not Needs_Finalization
(Typ
)
667 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
670 Init
:= Expression
(Decl
);
672 -- If a variable, or a non-imported constant, overlays a constant
673 -- object and has an initialization value, then the initialization
674 -- may end up writing into read-only memory. Detect the cases of
675 -- statically identical values and remove the initialization. In
676 -- the other cases, give a warning. We will give other warnings
677 -- later for the variable if it is assigned.
679 if (Ekind
(E
) = E_Variable
680 or else (Ekind
(E
) = E_Constant
681 and then not Is_Imported
(E
)))
682 and then Overlays_Constant
(E
)
683 and then Present
(Init
)
690 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
692 if Ekind
(O_Ent
) = E_Constant
693 and then Etype
(O_Ent
) = Typ
694 and then Present
(Constant_Value
(O_Ent
))
695 and then Compile_Time_Compare
697 Constant_Value
(O_Ent
),
698 Assume_Valid
=> True) = EQ
700 Set_No_Initialization
(Decl
);
703 elsif Comes_From_Source
(Init
)
704 and then Address_Clause_Overlay_Warnings
706 Error_Msg_Sloc
:= Sloc
(Addr
);
708 ("??constant& may be modified via address clause#",
714 -- Remove side effects from initial expression, except in the case of
715 -- limited build-in-place calls and aggregates, which have their own
716 -- expansion elsewhere. This exception is necessary to avoid copying
719 if Present
(Init
) and then not Is_Limited_View
(Typ
) then
721 -- Capture initialization value at point of declaration, and make
722 -- explicit assignment legal, because object may be a constant.
724 Remove_Side_Effects
(Init
);
725 Lhs
:= New_Occurrence_Of
(E
, Sloc
(Decl
));
726 Set_Assignment_OK
(Lhs
);
728 -- Move initialization to freeze actions, once the object has
729 -- been frozen and the address clause alignment check has been
732 Append_Freeze_Action
(E
,
733 Make_Assignment_Statement
(Sloc
(Decl
),
735 Expression
=> Expression
(Decl
)));
737 Set_No_Initialization
(Decl
);
739 -- If the object is tagged, check whether the tag must be
740 -- reassigned explicitly.
742 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
743 if Present
(Tag_Assign
) then
744 Append_Freeze_Action
(E
, Tag_Assign
);
748 end Check_Address_Clause
;
750 -----------------------------
751 -- Check_Compile_Time_Size --
752 -----------------------------
754 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
756 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
757 -- Sets the compile time known size (64 bits or less) in the RM_Size
758 -- field of T, checking for a size clause that was given which attempts
759 -- to give a smaller size.
761 function Size_Known
(T
: Entity_Id
) return Boolean;
762 -- Recursive function that does all the work
764 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
765 -- If T is a constrained subtype, its size is not known if any of its
766 -- discriminant constraints is not static and it is not a null record.
767 -- The test is conservative and doesn't check that the components are
768 -- in fact constrained by non-static discriminant values. Could be made
775 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
780 -- Check for bad size clause given
782 elsif Has_Size_Clause
(T
) then
783 if RM_Size
(T
) < S
then
784 Error_Msg_Uint_1
:= S
;
786 ("size for& too small, minimum allowed is ^",
790 -- Set size if not set already
792 elsif Unknown_RM_Size
(T
) then
801 function Size_Known
(T
: Entity_Id
) return Boolean is
809 if Size_Known_At_Compile_Time
(T
) then
812 -- Always True for elementary types, even generic formal elementary
813 -- types. We used to return False in the latter case, but the size
814 -- is known at compile time, even in the template, we just do not
815 -- know the exact size but that's not the point of this routine.
817 elsif Is_Elementary_Type
(T
) or else Is_Task_Type
(T
) then
822 elsif Is_Array_Type
(T
) then
824 -- String literals always have known size, and we can set it
826 if Ekind
(T
) = E_String_Literal_Subtype
then
828 (T
, Component_Size
(T
) * String_Literal_Length
(T
));
831 -- Unconstrained types never have known at compile time size
833 elsif not Is_Constrained
(T
) then
836 -- Don't do any recursion on type with error posted, since we may
837 -- have a malformed type that leads us into a loop.
839 elsif Error_Posted
(T
) then
842 -- Otherwise if component size unknown, then array size unknown
844 elsif not Size_Known
(Component_Type
(T
)) then
848 -- Check for all indexes static, and also compute possible size
849 -- (in case it is not greater than 64 and may be packable).
852 Size
: Uint
:= Component_Size
(T
);
856 Index
:= First_Index
(T
);
857 while Present
(Index
) loop
858 if Nkind
(Index
) = N_Range
then
859 Get_Index_Bounds
(Index
, Low
, High
);
861 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
865 Low
:= Type_Low_Bound
(Etype
(Index
));
866 High
:= Type_High_Bound
(Etype
(Index
));
869 if not Compile_Time_Known_Value
(Low
)
870 or else not Compile_Time_Known_Value
(High
)
871 or else Etype
(Index
) = Any_Type
876 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
888 Set_Small_Size
(T
, Size
);
892 -- For non-generic private types, go to underlying type if present
894 elsif Is_Private_Type
(T
)
895 and then not Is_Generic_Type
(T
)
896 and then Present
(Underlying_Type
(T
))
898 -- Don't do any recursion on type with error posted, since we may
899 -- have a malformed type that leads us into a loop.
901 if Error_Posted
(T
) then
904 return Size_Known
(Underlying_Type
(T
));
909 elsif Is_Record_Type
(T
) then
911 -- A class-wide type is never considered to have a known size
913 if Is_Class_Wide_Type
(T
) then
916 -- A subtype of a variant record must not have non-static
917 -- discriminated components.
919 elsif T
/= Base_Type
(T
)
920 and then not Static_Discriminated_Components
(T
)
924 -- Don't do any recursion on type with error posted, since we may
925 -- have a malformed type that leads us into a loop.
927 elsif Error_Posted
(T
) then
931 -- Now look at the components of the record
934 -- The following two variables are used to keep track of the
935 -- size of packed records if we can tell the size of the packed
936 -- record in the front end. Packed_Size_Known is True if so far
937 -- we can figure out the size. It is initialized to True for a
938 -- packed record, unless the record has discriminants or atomic
939 -- components or independent components.
941 -- The reason we eliminate the discriminated case is that
942 -- we don't know the way the back end lays out discriminated
943 -- packed records. If Packed_Size_Known is True, then
944 -- Packed_Size is the size in bits so far.
946 Packed_Size_Known
: Boolean :=
948 and then not Has_Discriminants
(T
)
949 and then not Has_Atomic_Components
(T
)
950 and then not Has_Independent_Components
(T
);
952 Packed_Size
: Uint
:= Uint_0
;
953 -- Size in bits so far
956 -- Test for variant part present
958 if Has_Discriminants
(T
)
959 and then Present
(Parent
(T
))
960 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
961 and then Nkind
(Type_Definition
(Parent
(T
))) =
963 and then not Null_Present
(Type_Definition
(Parent
(T
)))
965 Present
(Variant_Part
966 (Component_List
(Type_Definition
(Parent
(T
)))))
968 -- If variant part is present, and type is unconstrained,
969 -- then we must have defaulted discriminants, or a size
970 -- clause must be present for the type, or else the size
971 -- is definitely not known at compile time.
973 if not Is_Constrained
(T
)
975 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
976 and then Unknown_RM_Size
(T
)
982 -- Loop through components
984 Comp
:= First_Component_Or_Discriminant
(T
);
985 while Present
(Comp
) loop
986 Ctyp
:= Etype
(Comp
);
988 -- We do not know the packed size if there is a component
989 -- clause present (we possibly could, but this would only
990 -- help in the case of a record with partial rep clauses.
991 -- That's because in the case of full rep clauses, the
992 -- size gets figured out anyway by a different circuit).
994 if Present
(Component_Clause
(Comp
)) then
995 Packed_Size_Known
:= False;
998 -- We do not know the packed size for an atomic/VFA type
999 -- or component, or an independent type or component, or a
1000 -- by-reference type or aliased component (because packing
1001 -- does not touch these).
1003 if Is_Atomic_Or_VFA
(Ctyp
)
1004 or else Is_Atomic_Or_VFA
(Comp
)
1005 or else Is_Independent
(Ctyp
)
1006 or else Is_Independent
(Comp
)
1007 or else Is_By_Reference_Type
(Ctyp
)
1008 or else Is_Aliased
(Comp
)
1010 Packed_Size_Known
:= False;
1013 -- We need to identify a component that is an array where
1014 -- the index type is an enumeration type with non-standard
1015 -- representation, and some bound of the type depends on a
1018 -- This is because gigi computes the size by doing a
1019 -- substitution of the appropriate discriminant value in
1020 -- the size expression for the base type, and gigi is not
1021 -- clever enough to evaluate the resulting expression (which
1022 -- involves a call to rep_to_pos) at compile time.
1024 -- It would be nice if gigi would either recognize that
1025 -- this expression can be computed at compile time, or
1026 -- alternatively figured out the size from the subtype
1027 -- directly, where all the information is at hand ???
1029 if Is_Array_Type
(Etype
(Comp
))
1030 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1033 Ocomp
: constant Entity_Id
:=
1034 Original_Record_Component
(Comp
);
1035 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1041 Ind
:= First_Index
(OCtyp
);
1042 while Present
(Ind
) loop
1043 Indtyp
:= Etype
(Ind
);
1045 if Is_Enumeration_Type
(Indtyp
)
1046 and then Has_Non_Standard_Rep
(Indtyp
)
1048 Lo
:= Type_Low_Bound
(Indtyp
);
1049 Hi
:= Type_High_Bound
(Indtyp
);
1051 if Is_Entity_Name
(Lo
)
1052 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1056 elsif Is_Entity_Name
(Hi
)
1057 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1068 -- Clearly size of record is not known if the size of one of
1069 -- the components is not known.
1071 if not Size_Known
(Ctyp
) then
1075 -- Accumulate packed size if possible
1077 if Packed_Size_Known
then
1079 -- We can deal with elementary types, small packed arrays
1080 -- if the representation is a modular type and also small
1081 -- record types (if the size is not greater than 64, but
1082 -- the condition is checked by Set_Small_Size).
1084 if Is_Elementary_Type
(Ctyp
)
1085 or else (Is_Array_Type
(Ctyp
)
1087 (Packed_Array_Impl_Type
(Ctyp
))
1088 and then Is_Modular_Integer_Type
1089 (Packed_Array_Impl_Type
(Ctyp
)))
1090 or else Is_Record_Type
(Ctyp
)
1092 -- If RM_Size is known and static, then we can keep
1093 -- accumulating the packed size.
1095 if Known_Static_RM_Size
(Ctyp
) then
1097 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1099 -- If we have a field whose RM_Size is not known then
1100 -- we can't figure out the packed size here.
1103 Packed_Size_Known
:= False;
1106 -- For other types we can't figure out the packed size
1109 Packed_Size_Known
:= False;
1113 Next_Component_Or_Discriminant
(Comp
);
1116 if Packed_Size_Known
then
1117 Set_Small_Size
(T
, Packed_Size
);
1123 -- All other cases, size not known at compile time
1130 -------------------------------------
1131 -- Static_Discriminated_Components --
1132 -------------------------------------
1134 function Static_Discriminated_Components
1135 (T
: Entity_Id
) return Boolean
1137 Constraint
: Elmt_Id
;
1140 if Has_Discriminants
(T
)
1141 and then Present
(Discriminant_Constraint
(T
))
1142 and then Present
(First_Component
(T
))
1144 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1145 while Present
(Constraint
) loop
1146 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1150 Next_Elmt
(Constraint
);
1155 end Static_Discriminated_Components
;
1157 -- Start of processing for Check_Compile_Time_Size
1160 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1161 end Check_Compile_Time_Size
;
1163 -----------------------------------
1164 -- Check_Component_Storage_Order --
1165 -----------------------------------
1167 procedure Check_Component_Storage_Order
1168 (Encl_Type
: Entity_Id
;
1171 Comp_ADC_Present
: out Boolean)
1173 Comp_Base
: Entity_Id
;
1175 Encl_Base
: Entity_Id
;
1178 Component_Aliased
: Boolean;
1180 Comp_Byte_Aligned
: Boolean := False;
1181 -- Set for the record case, True if Comp is aligned on byte boundaries
1182 -- (in which case it is allowed to have different storage order).
1184 Comp_SSO_Differs
: Boolean;
1185 -- Set True when the component is a nested composite, and it does not
1186 -- have the same scalar storage order as Encl_Type.
1191 if Present
(Comp
) then
1193 Comp_Base
:= Etype
(Comp
);
1195 if Is_Tag
(Comp
) then
1196 Comp_Byte_Aligned
:= True;
1197 Component_Aliased
:= False;
1200 -- If a component clause is present, check if the component starts
1201 -- and ends on byte boundaries. Otherwise conservatively assume it
1202 -- does so only in the case where the record is not packed.
1204 if Present
(Component_Clause
(Comp
)) then
1205 Comp_Byte_Aligned
:=
1206 (Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0)
1208 (Esize
(Comp
) mod System_Storage_Unit
= 0);
1210 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1213 Component_Aliased
:= Is_Aliased
(Comp
);
1219 Err_Node
:= Encl_Type
;
1220 Comp_Base
:= Component_Type
(Encl_Type
);
1222 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1225 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1226 -- the attribute definition clause is attached to the first subtype.
1227 -- Also, if the base type is incomplete or private, go to full view
1230 Encl_Base
:= Base_Type
(Encl_Type
);
1231 if Present
(Underlying_Type
(Encl_Base
)) then
1232 Encl_Base
:= Underlying_Type
(Encl_Base
);
1235 Comp_Base
:= Base_Type
(Comp_Base
);
1236 if Present
(Underlying_Type
(Comp_Base
)) then
1237 Comp_Base
:= Underlying_Type
(Comp_Base
);
1241 Get_Attribute_Definition_Clause
1242 (First_Subtype
(Comp_Base
), Attribute_Scalar_Storage_Order
);
1243 Comp_ADC_Present
:= Present
(Comp_ADC
);
1245 -- Case of record or array component: check storage order compatibility.
1246 -- But, if the record has Complex_Representation, then it is treated as
1247 -- a scalar in the back end so the storage order is irrelevant.
1249 if (Is_Record_Type
(Comp_Base
)
1250 and then not Has_Complex_Representation
(Comp_Base
))
1251 or else Is_Array_Type
(Comp_Base
)
1254 Reverse_Storage_Order
(Encl_Base
) /=
1255 Reverse_Storage_Order
(Comp_Base
);
1257 -- Parent and extension must have same storage order
1259 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1260 if Comp_SSO_Differs
then
1262 ("record extension must have same scalar storage order as "
1263 & "parent", Err_Node
);
1266 -- If component and composite SSO differs, check that component
1267 -- falls on byte boundaries and isn't bit packed.
1269 elsif Comp_SSO_Differs
then
1271 -- Component SSO differs from enclosing composite:
1273 -- Reject if composite is a bit-packed array, as it is rewritten
1274 -- into an array of scalars.
1276 if Is_Bit_Packed_Array
(Encl_Base
) then
1278 ("type of packed array must have same scalar storage order "
1279 & "as component", Err_Node
);
1281 -- Reject if not byte aligned
1283 elsif Is_Record_Type
(Encl_Base
)
1284 and then not Comp_Byte_Aligned
1287 ("type of non-byte-aligned component must have same scalar "
1288 & "storage order as enclosing composite", Err_Node
);
1290 -- Warn if specified only for the outer composite
1292 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1294 ("scalar storage order specified for & does not apply to "
1295 & "component?", Err_Node
, Encl_Base
);
1299 -- Enclosing type has explicit SSO: non-composite component must not
1302 elsif Present
(ADC
) and then Component_Aliased
then
1304 ("aliased component not permitted for type with explicit "
1305 & "Scalar_Storage_Order", Err_Node
);
1307 end Check_Component_Storage_Order
;
1309 -----------------------------
1310 -- Check_Debug_Info_Needed --
1311 -----------------------------
1313 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1315 if Debug_Info_Off
(T
) then
1318 elsif Comes_From_Source
(T
)
1319 or else Debug_Generated_Code
1320 or else Debug_Flag_VV
1321 or else Needs_Debug_Info
(T
)
1323 Set_Debug_Info_Needed
(T
);
1325 end Check_Debug_Info_Needed
;
1327 -------------------------------
1328 -- Check_Expression_Function --
1329 -------------------------------
1331 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1332 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1333 -- Function to search for deferred constant
1339 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1341 -- When a constant is initialized with the result of a dispatching
1342 -- call, the constant declaration is rewritten as a renaming of the
1343 -- displaced function result. This scenario is not a premature use of
1344 -- a constant even though the Has_Completion flag is not set.
1346 if Is_Entity_Name
(Nod
)
1347 and then Present
(Entity
(Nod
))
1348 and then Ekind
(Entity
(Nod
)) = E_Constant
1349 and then Scope
(Entity
(Nod
)) = Current_Scope
1350 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1351 N_Object_Declaration
1352 and then not Is_Imported
(Entity
(Nod
))
1353 and then not Has_Completion
(Entity
(Nod
))
1354 and then not Is_Frozen
(Entity
(Nod
))
1357 ("premature use of& in call or instance", N
, Entity
(Nod
));
1359 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1360 Analyze
(Prefix
(Nod
));
1362 if Is_Entity_Name
(Prefix
(Nod
))
1363 and then Is_Type
(Entity
(Prefix
(Nod
)))
1365 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1372 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1378 -- Start of processing for Check_Expression_Function
1381 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1383 -- The subprogram body created for the expression function is not
1384 -- itself a freeze point.
1386 if Scope
(Nam
) = Current_Scope
1387 and then Nkind
(Decl
) = N_Expression_Function
1388 and then Nkind
(N
) /= N_Subprogram_Body
1390 Check_Deferred
(Expression
(Decl
));
1392 end Check_Expression_Function
;
1394 --------------------------------
1395 -- Check_Inherited_Conditions --
1396 --------------------------------
1398 procedure Check_Inherited_Conditions
(R
: Entity_Id
) is
1399 Prim_Ops
: constant Elist_Id
:= Primitive_Operations
(R
);
1401 Needs_Wrapper
: Boolean;
1403 Par_Prim
: Entity_Id
;
1406 procedure Build_Inherited_Condition_Pragmas
(Subp
: Entity_Id
);
1407 -- Build corresponding pragmas for an operation whose ancestor has
1408 -- class-wide pre/postconditions. If the operation is inherited, the
1409 -- pragmas force the creation of a wrapper for the inherited operation.
1410 -- If the ancestor is being overridden, the pragmas are constructed only
1411 -- to verify their legality, in case they contain calls to other
1412 -- primitives that may haven been overridden.
1414 ---------------------------------------
1415 -- Build_Inherited_Condition_Pragmas --
1416 ---------------------------------------
1418 procedure Build_Inherited_Condition_Pragmas
(Subp
: Entity_Id
) is
1424 A_Pre
:= Get_Class_Wide_Pragma
(Par_Prim
, Pragma_Precondition
);
1426 if Present
(A_Pre
) then
1427 New_Prag
:= New_Copy_Tree
(A_Pre
);
1428 Build_Class_Wide_Expression
1431 Par_Subp
=> Par_Prim
,
1432 Adjust_Sloc
=> False,
1433 Needs_Wrapper
=> Needs_Wrapper
);
1436 and then not Comes_From_Source
(Subp
)
1437 and then Expander_Active
1439 Append
(New_Prag
, Decls
);
1443 A_Post
:= Get_Class_Wide_Pragma
(Par_Prim
, Pragma_Postcondition
);
1445 if Present
(A_Post
) then
1446 New_Prag
:= New_Copy_Tree
(A_Post
);
1447 Build_Class_Wide_Expression
1450 Par_Subp
=> Par_Prim
,
1451 Adjust_Sloc
=> False,
1452 Needs_Wrapper
=> Needs_Wrapper
);
1455 and then not Comes_From_Source
(Subp
)
1456 and then Expander_Active
1458 Append
(New_Prag
, Decls
);
1461 end Build_Inherited_Condition_Pragmas
;
1463 -- Start of processing for Check_Inherited_Conditions
1466 Op_Node
:= First_Elmt
(Prim_Ops
);
1467 while Present
(Op_Node
) loop
1468 Prim
:= Node
(Op_Node
);
1470 -- Map the overridden primitive to the overriding one. This takes
1471 -- care of all overridings and is done only once.
1473 if Present
(Overridden_Operation
(Prim
))
1474 and then Comes_From_Source
(Prim
)
1476 Par_Prim
:= Overridden_Operation
(Prim
);
1477 Update_Primitives_Mapping
(Par_Prim
, Prim
);
1480 Next_Elmt
(Op_Node
);
1483 -- Perform validity checks on the inherited conditions of overriding
1484 -- operations, for conformance with LSP, and apply SPARK-specific
1485 -- restrictions on inherited conditions.
1487 Op_Node
:= First_Elmt
(Prim_Ops
);
1488 while Present
(Op_Node
) loop
1489 Prim
:= Node
(Op_Node
);
1491 if Present
(Overridden_Operation
(Prim
))
1492 and then Comes_From_Source
(Prim
)
1494 Par_Prim
:= Overridden_Operation
(Prim
);
1496 -- Analyze the contract items of the overridden operation, before
1497 -- they are rewritten as pragmas.
1499 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1501 -- In GNATprove mode this is where we can collect the inherited
1502 -- conditions, because we do not create the Check pragmas that
1503 -- normally convey the the modified class-wide conditions on
1504 -- overriding operations.
1506 if GNATprove_Mode
then
1507 Collect_Inherited_Class_Wide_Conditions
(Prim
);
1509 -- Otherwise build the corresponding pragmas to check for legality
1510 -- of the inherited condition.
1513 Build_Inherited_Condition_Pragmas
(Prim
);
1517 Next_Elmt
(Op_Node
);
1520 -- Now examine the inherited operations to check whether they require
1521 -- a wrapper to handle inherited conditions that call other primitives,
1522 -- so that LSP can be verified/enforced.
1524 Op_Node
:= First_Elmt
(Prim_Ops
);
1525 Needs_Wrapper
:= False;
1527 while Present
(Op_Node
) loop
1528 Decls
:= Empty_List
;
1529 Prim
:= Node
(Op_Node
);
1531 if not Comes_From_Source
(Prim
) and then Present
(Alias
(Prim
)) then
1532 Par_Prim
:= Alias
(Prim
);
1534 -- Analyze the contract items of the parent operation, and
1535 -- determine whether a wrapper is needed. This is determined
1536 -- when the condition is rewritten in sem_prag, using the
1537 -- mapping between overridden and overriding operations built
1538 -- in the loop above.
1540 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1541 Build_Inherited_Condition_Pragmas
(Prim
);
1545 and then not Is_Abstract_Subprogram
(Par_Prim
)
1546 and then Expander_Active
1548 -- We need to build a new primitive that overrides the inherited
1549 -- one, and whose inherited expression has been updated above.
1550 -- These expressions are the arguments of pragmas that are part
1551 -- of the declarations of the wrapper. The wrapper holds a single
1552 -- statement that is a call to the class-wide clone, where the
1553 -- controlling actuals are conversions to the corresponding type
1554 -- in the parent primitive:
1556 -- procedure New_Prim (F1 : T1; ...);
1557 -- procedure New_Prim (F1 : T1; ...) is
1558 -- pragma Check (Precondition, Expr);
1560 -- Par_Prim_Clone (Par_Type (F1), ...);
1563 -- If the primitive is a function the statement is a return
1564 -- statement with a call.
1567 Loc
: constant Source_Ptr
:= Sloc
(R
);
1568 Par_R
: constant Node_Id
:= Parent
(R
);
1574 New_Spec
:= Build_Overriding_Spec
(Par_Prim
, R
);
1576 Make_Subprogram_Declaration
(Loc
,
1577 Specification
=> New_Spec
);
1579 -- Insert the declaration and the body of the wrapper after
1580 -- type declaration that generates inherited operation. For
1581 -- a null procedure, the declaration implies a null body.
1583 if Nkind
(New_Spec
) = N_Procedure_Specification
1584 and then Null_Present
(New_Spec
)
1586 Insert_After_And_Analyze
(Par_R
, New_Decl
);
1589 -- Build body as wrapper to a call to the already built
1590 -- class-wide clone.
1593 Build_Class_Wide_Clone_Call
1594 (Loc
, Decls
, Par_Prim
, New_Spec
);
1596 Insert_List_After_And_Analyze
1597 (Par_R
, New_List
(New_Decl
, New_Body
));
1601 Needs_Wrapper
:= False;
1604 Next_Elmt
(Op_Node
);
1606 end Check_Inherited_Conditions
;
1608 ----------------------------
1609 -- Check_Strict_Alignment --
1610 ----------------------------
1612 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1616 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1617 Set_Strict_Alignment
(E
);
1619 elsif Is_Array_Type
(E
) then
1620 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1622 elsif Is_Record_Type
(E
) then
1623 if Is_Limited_Record
(E
) then
1624 Set_Strict_Alignment
(E
);
1628 Comp
:= First_Component
(E
);
1629 while Present
(Comp
) loop
1630 if not Is_Type
(Comp
)
1631 and then (Strict_Alignment
(Etype
(Comp
))
1632 or else Is_Aliased
(Comp
))
1634 Set_Strict_Alignment
(E
);
1638 Next_Component
(Comp
);
1641 end Check_Strict_Alignment
;
1643 -------------------------
1644 -- Check_Unsigned_Type --
1645 -------------------------
1647 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1648 Ancestor
: Entity_Id
;
1653 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1657 -- Do not attempt to analyze case where range was in error
1659 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
1663 -- The situation that is nontrivial is something like:
1665 -- subtype x1 is integer range -10 .. +10;
1666 -- subtype x2 is x1 range 0 .. V1;
1667 -- subtype x3 is x2 range V2 .. V3;
1668 -- subtype x4 is x3 range V4 .. V5;
1670 -- where Vn are variables. Here the base type is signed, but we still
1671 -- know that x4 is unsigned because of the lower bound of x2.
1673 -- The only way to deal with this is to look up the ancestor chain
1677 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1681 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1683 if Compile_Time_Known_Value
(Lo_Bound
) then
1684 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1685 Set_Is_Unsigned_Type
(E
, True);
1691 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1693 -- If no ancestor had a static lower bound, go to base type
1695 if No
(Ancestor
) then
1697 -- Note: the reason we still check for a compile time known
1698 -- value for the base type is that at least in the case of
1699 -- generic formals, we can have bounds that fail this test,
1700 -- and there may be other cases in error situations.
1702 Btyp
:= Base_Type
(E
);
1704 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1708 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1710 if Compile_Time_Known_Value
(Lo_Bound
)
1711 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1713 Set_Is_Unsigned_Type
(E
, True);
1720 end Check_Unsigned_Type
;
1722 -----------------------------
1723 -- Is_Atomic_VFA_Aggregate --
1724 -----------------------------
1726 function Is_Atomic_VFA_Aggregate
(N
: Node_Id
) return Boolean is
1727 Loc
: constant Source_Ptr
:= Sloc
(N
);
1736 -- Array may be qualified, so find outer context
1738 if Nkind
(Par
) = N_Qualified_Expression
then
1739 Par
:= Parent
(Par
);
1742 if not Comes_From_Source
(Par
) then
1747 when N_Assignment_Statement
=>
1748 Typ
:= Etype
(Name
(Par
));
1750 if not Is_Atomic_Or_VFA
(Typ
)
1751 and then not (Is_Entity_Name
(Name
(Par
))
1752 and then Is_Atomic_Or_VFA
(Entity
(Name
(Par
))))
1757 when N_Object_Declaration
=>
1758 Typ
:= Etype
(Defining_Identifier
(Par
));
1760 if not Is_Atomic_Or_VFA
(Typ
)
1761 and then not Is_Atomic_Or_VFA
(Defining_Identifier
(Par
))
1770 Temp
:= Make_Temporary
(Loc
, 'T', N
);
1772 Make_Object_Declaration
(Loc
,
1773 Defining_Identifier
=> Temp
,
1774 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1775 Expression
=> Relocate_Node
(N
));
1776 Insert_Before
(Par
, New_N
);
1779 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1781 end Is_Atomic_VFA_Aggregate
;
1783 -----------------------------------------------
1784 -- Explode_Initialization_Compound_Statement --
1785 -----------------------------------------------
1787 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
1788 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
1791 if Present
(Init_Stmts
)
1792 and then Nkind
(Init_Stmts
) = N_Compound_Statement
1794 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
1796 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
1797 -- just removing it, because Freeze_All may rely on this particular
1798 -- Node_Id still being present in the enclosing list to know where to
1801 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
1803 Set_Initialization_Statements
(E
, Empty
);
1805 end Explode_Initialization_Compound_Statement
;
1811 -- Note: the easy coding for this procedure would be to just build a
1812 -- single list of freeze nodes and then insert them and analyze them
1813 -- all at once. This won't work, because the analysis of earlier freeze
1814 -- nodes may recursively freeze types which would otherwise appear later
1815 -- on in the freeze list. So we must analyze and expand the freeze nodes
1816 -- as they are generated.
1818 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1819 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1820 -- This is the internal recursive routine that does freezing of entities
1821 -- (but NOT the analysis of default expressions, which should not be
1822 -- recursive, we don't want to analyze those till we are sure that ALL
1823 -- the types are frozen).
1825 --------------------
1826 -- Freeze_All_Ent --
1827 --------------------
1829 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1834 procedure Process_Flist
;
1835 -- If freeze nodes are present, insert and analyze, and reset cursor
1836 -- for next insertion.
1842 procedure Process_Flist
is
1844 if Is_Non_Empty_List
(Flist
) then
1845 Lastn
:= Next
(After
);
1846 Insert_List_After_And_Analyze
(After
, Flist
);
1848 if Present
(Lastn
) then
1849 After
:= Prev
(Lastn
);
1851 After
:= Last
(List_Containing
(After
));
1856 -- Start of processing for Freeze_All_Ent
1860 while Present
(E
) loop
1862 -- If the entity is an inner package which is not a package
1863 -- renaming, then its entities must be frozen at this point. Note
1864 -- that such entities do NOT get frozen at the end of the nested
1865 -- package itself (only library packages freeze).
1867 -- Same is true for task declarations, where anonymous records
1868 -- created for entry parameters must be frozen.
1870 if Ekind
(E
) = E_Package
1871 and then No
(Renamed_Object
(E
))
1872 and then not Is_Child_Unit
(E
)
1873 and then not Is_Frozen
(E
)
1877 Install_Visible_Declarations
(E
);
1878 Install_Private_Declarations
(E
);
1879 Freeze_All
(First_Entity
(E
), After
);
1881 End_Package_Scope
(E
);
1883 if Is_Generic_Instance
(E
)
1884 and then Has_Delayed_Freeze
(E
)
1886 Set_Has_Delayed_Freeze
(E
, False);
1887 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1890 elsif Ekind
(E
) in Task_Kind
1891 and then Nkind_In
(Parent
(E
), N_Single_Task_Declaration
,
1892 N_Task_Type_Declaration
)
1895 Freeze_All
(First_Entity
(E
), After
);
1898 -- For a derived tagged type, we must ensure that all the
1899 -- primitive operations of the parent have been frozen, so that
1900 -- their addresses will be in the parent's dispatch table at the
1901 -- point it is inherited.
1903 elsif Ekind
(E
) = E_Record_Type
1904 and then Is_Tagged_Type
(E
)
1905 and then Is_Tagged_Type
(Etype
(E
))
1906 and then Is_Derived_Type
(E
)
1909 Prim_List
: constant Elist_Id
:=
1910 Primitive_Operations
(Etype
(E
));
1916 Prim
:= First_Elmt
(Prim_List
);
1917 while Present
(Prim
) loop
1918 Subp
:= Node
(Prim
);
1920 if Comes_From_Source
(Subp
)
1921 and then not Is_Frozen
(Subp
)
1923 Flist
:= Freeze_Entity
(Subp
, After
);
1932 if not Is_Frozen
(E
) then
1933 Flist
:= Freeze_Entity
(E
, After
);
1936 -- If already frozen, and there are delayed aspects, this is where
1937 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1938 -- for a description of how we handle aspect visibility).
1940 elsif Has_Delayed_Aspects
(E
) then
1942 -- Retrieve the visibility to the discriminants in order to
1943 -- analyze properly the aspects.
1945 Push_Scope_And_Install_Discriminants
(E
);
1951 Ritem
:= First_Rep_Item
(E
);
1952 while Present
(Ritem
) loop
1953 if Nkind
(Ritem
) = N_Aspect_Specification
1954 and then Entity
(Ritem
) = E
1955 and then Is_Delayed_Aspect
(Ritem
)
1957 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1960 Ritem
:= Next_Rep_Item
(Ritem
);
1964 Uninstall_Discriminants_And_Pop_Scope
(E
);
1967 -- If an incomplete type is still not frozen, this may be a
1968 -- premature freezing because of a body declaration that follows.
1969 -- Indicate where the freezing took place. Freezing will happen
1970 -- if the body comes from source, but not if it is internally
1971 -- generated, for example as the body of a type invariant.
1973 -- If the freezing is caused by the end of the current declarative
1974 -- part, it is a Taft Amendment type, and there is no error.
1976 if not Is_Frozen
(E
)
1977 and then Ekind
(E
) = E_Incomplete_Type
1980 Bod
: constant Node_Id
:= Next
(After
);
1983 -- The presence of a body freezes all entities previously
1984 -- declared in the current list of declarations, but this
1985 -- does not apply if the body does not come from source.
1986 -- A type invariant is transformed into a subprogram body
1987 -- which is placed at the end of the private part of the
1988 -- current package, but this body does not freeze incomplete
1989 -- types that may be declared in this private part.
1991 if (Nkind_In
(Bod
, N_Entry_Body
,
1996 or else Nkind
(Bod
) in N_Body_Stub
)
1998 List_Containing
(After
) = List_Containing
(Parent
(E
))
1999 and then Comes_From_Source
(Bod
)
2001 Error_Msg_Sloc
:= Sloc
(Next
(After
));
2003 ("type& is frozen# before its full declaration",
2019 -- Start of processing for Freeze_All
2022 Freeze_All_Ent
(From
, After
);
2024 -- Now that all types are frozen, we can deal with default expressions
2025 -- that require us to build a default expression functions. This is the
2026 -- point at which such functions are constructed (after all types that
2027 -- might be used in such expressions have been frozen).
2029 -- For subprograms that are renaming_as_body, we create the wrapper
2030 -- bodies as needed.
2032 -- We also add finalization chains to access types whose designated
2033 -- types are controlled. This is normally done when freezing the type,
2034 -- but this misses recursive type definitions where the later members
2035 -- of the recursion introduce controlled components.
2037 -- Loop through entities
2040 while Present
(E
) loop
2041 if Is_Subprogram
(E
) then
2042 if not Default_Expressions_Processed
(E
) then
2043 Process_Default_Expressions
(E
, After
);
2046 if not Has_Completion
(E
) then
2047 Decl
:= Unit_Declaration_Node
(E
);
2049 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
2050 if Error_Posted
(Decl
) then
2051 Set_Has_Completion
(E
);
2053 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
2056 elsif Nkind
(Decl
) = N_Subprogram_Declaration
2057 and then Present
(Corresponding_Body
(Decl
))
2059 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
2060 N_Subprogram_Renaming_Declaration
2062 Build_And_Analyze_Renamed_Body
2063 (Decl
, Corresponding_Body
(Decl
), After
);
2067 -- Freeze the default expressions of entries, entry families, and
2068 -- protected subprograms.
2070 elsif Is_Concurrent_Type
(E
) then
2071 Item
:= First_Entity
(E
);
2072 while Present
(Item
) loop
2073 if (Is_Entry
(Item
) or else Is_Subprogram
(Item
))
2074 and then not Default_Expressions_Processed
(Item
)
2076 Process_Default_Expressions
(Item
, After
);
2083 -- Historical note: We used to create a finalization master for an
2084 -- access type whose designated type is not controlled, but contains
2085 -- private controlled compoments. This form of postprocessing is no
2086 -- longer needed because the finalization master is now created when
2087 -- the access type is frozen (see Exp_Ch3.Freeze_Type).
2093 -----------------------
2094 -- Freeze_And_Append --
2095 -----------------------
2097 procedure Freeze_And_Append
2100 Result
: in out List_Id
)
2102 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
2104 if Is_Non_Empty_List
(L
) then
2105 if Result
= No_List
then
2108 Append_List
(L
, Result
);
2111 end Freeze_And_Append
;
2117 procedure Freeze_Before
2120 Do_Freeze_Profile
: Boolean := True)
2122 -- Freeze T, then insert the generated Freeze nodes before the node N.
2123 -- Flag Freeze_Profile is used when T is an overloadable entity, and
2124 -- indicates whether its profile should be frozen at the same time.
2126 Freeze_Nodes
: constant List_Id
:=
2127 Freeze_Entity
(T
, N
, Do_Freeze_Profile
);
2128 Pack
: constant Entity_Id
:= Scope
(T
);
2131 if Ekind
(T
) = E_Function
then
2132 Check_Expression_Function
(N
, T
);
2135 if Is_Non_Empty_List
(Freeze_Nodes
) then
2137 -- If the entity is a type declared in an inner package, it may be
2138 -- frozen by an outer declaration before the package itself is
2139 -- frozen. Install the package scope to analyze the freeze nodes,
2140 -- which may include generated subprograms such as predicate
2143 if Is_Type
(T
) and then From_Nested_Package
(T
) then
2145 Install_Visible_Declarations
(Pack
);
2146 Install_Private_Declarations
(Pack
);
2147 Insert_Actions
(N
, Freeze_Nodes
);
2148 End_Package_Scope
(Pack
);
2151 Insert_Actions
(N
, Freeze_Nodes
);
2160 -- WARNING: This routine manages Ghost regions. Return statements must be
2161 -- replaced by gotos which jump to the end of the routine and restore the
2164 function Freeze_Entity
2167 Do_Freeze_Profile
: Boolean := True) return List_Id
2169 Loc
: constant Source_Ptr
:= Sloc
(N
);
2171 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2172 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
2173 -- Save the Ghost-related attributes to restore on exit
2181 Has_Default_Initialization
: Boolean := False;
2182 -- This flag gets set to true for a variable with default initialization
2184 Result
: List_Id
:= No_List
;
2185 -- List of freezing actions, left at No_List if none
2187 Test_E
: Entity_Id
:= E
;
2188 -- This could use a comment ???
2190 procedure Add_To_Result
(Fnod
: Node_Id
);
2191 -- Add freeze action Fnod to list Result
2193 function After_Last_Declaration
return Boolean;
2194 -- If Loc is a freeze_entity that appears after the last declaration
2195 -- in the scope, inhibit error messages on late completion.
2197 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
2198 -- Check that an Access or Unchecked_Access attribute with a prefix
2199 -- which is the current instance type can only be applied when the type
2202 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
);
2203 -- Give a warning for pragma Convention with language C or C++ applied
2204 -- to a discriminated record type. This is suppressed for the unchecked
2205 -- union case, since the whole point in this case is interface C. We
2206 -- also do not generate this within instantiations, since we will have
2207 -- generated a message on the template.
2209 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
2210 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
2211 -- integer literal without an explicit corresponding size clause. The
2212 -- caller has checked that Utype is a modular integer type.
2214 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
2215 -- Freeze array type, including freezing index and component types
2217 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
2218 -- Perform checks and generate freeze node if needed for a constant or
2219 -- variable declared by an object declaration.
2221 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
2222 -- Create Freeze_Generic_Entity nodes for types declared in a generic
2223 -- package. Recurse on inner generic packages.
2225 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
2226 -- Freeze formals and return type of subprogram. If some type in the
2227 -- profile is incomplete and we are in an instance, freezing of the
2228 -- entity will take place elsewhere, and the function returns False.
2230 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
2231 -- Freeze record type, including freezing component types, and freezing
2232 -- primitive operations if this is a tagged type.
2234 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
2235 -- Determine whether an arbitrary entity is subject to Boolean aspect
2236 -- Import and its value is specified as True.
2238 procedure Inherit_Freeze_Node
2241 -- Set type Typ's freeze node to refer to Fnode. This routine ensures
2242 -- that any attributes attached to Typ's original node are preserved.
2244 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
2245 -- If E is an entity for an imported subprogram with pre/post-conditions
2246 -- then this procedure will create a wrapper to ensure that proper run-
2247 -- time checking of the pre/postconditions. See body for details.
2253 procedure Add_To_Result
(Fnod
: Node_Id
) is
2255 -- The Ghost mode of the enclosing context is ignored, while the
2256 -- entity being frozen is living. Insert the freezing action prior
2257 -- to the start of the enclosing ignored Ghost region. As a result
2258 -- the freezeing action will be preserved when the ignored Ghost
2259 -- context is eliminated.
2261 if Saved_GM
= Ignore
2262 and then Ghost_Mode
/= Ignore
2263 and then Present
(Ignored_Ghost_Region
)
2265 Insert_Action
(Ignored_Ghost_Region
, Fnod
);
2267 -- Otherwise add the freezing action to the result list
2270 Append_New_To
(Result
, Fnod
);
2274 ----------------------------
2275 -- After_Last_Declaration --
2276 ----------------------------
2278 function After_Last_Declaration
return Boolean is
2279 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2282 if Nkind
(Spec
) = N_Package_Specification
then
2283 if Present
(Private_Declarations
(Spec
)) then
2284 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2285 elsif Present
(Visible_Declarations
(Spec
)) then
2286 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2294 end After_Last_Declaration
;
2296 ----------------------------
2297 -- Check_Current_Instance --
2298 ----------------------------
2300 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2302 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2303 -- Determine whether Typ is compatible with the rules for aliased
2304 -- views of types as defined in RM 3.10 in the various dialects.
2306 function Process
(N
: Node_Id
) return Traverse_Result
;
2307 -- Process routine to apply check to given node
2309 -----------------------------
2310 -- Is_Aliased_View_Of_Type --
2311 -----------------------------
2313 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
2314 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
2319 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
2320 and then Limited_Present
(Type_Definition
(Typ_Decl
))
2324 -- The following paragraphs describe what a legal aliased view of
2325 -- a type is in the various dialects of Ada.
2329 -- The current instance of a limited type, and a formal parameter
2330 -- or generic formal object of a tagged type.
2332 -- Ada 95 limited type
2333 -- * Type with reserved word "limited"
2334 -- * A protected or task type
2335 -- * A composite type with limited component
2337 elsif Ada_Version
<= Ada_95
then
2338 return Is_Limited_Type
(Typ
);
2342 -- The current instance of a limited tagged type, a protected
2343 -- type, a task type, or a type that has the reserved word
2344 -- "limited" in its full definition ... a formal parameter or
2345 -- generic formal object of a tagged type.
2347 -- Ada 2005 limited type
2348 -- * Type with reserved word "limited", "synchronized", "task"
2350 -- * A composite type with limited component
2351 -- * A derived type whose parent is a non-interface limited type
2353 elsif Ada_Version
= Ada_2005
then
2355 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2357 (Is_Derived_Type
(Typ
)
2358 and then not Is_Interface
(Etype
(Typ
))
2359 and then Is_Limited_Type
(Etype
(Typ
)));
2361 -- Ada 2012 and beyond
2363 -- The current instance of an immutably limited type ... a formal
2364 -- parameter or generic formal object of a tagged type.
2366 -- Ada 2012 limited type
2367 -- * Type with reserved word "limited", "synchronized", "task"
2369 -- * A composite type with limited component
2370 -- * A derived type whose parent is a non-interface limited type
2371 -- * An incomplete view
2373 -- Ada 2012 immutably limited type
2374 -- * Explicitly limited record type
2375 -- * Record extension with "limited" present
2376 -- * Non-formal limited private type that is either tagged
2377 -- or has at least one access discriminant with a default
2379 -- * Task type, protected type or synchronized interface
2380 -- * Type derived from immutably limited type
2384 Is_Immutably_Limited_Type
(Typ
)
2385 or else Is_Incomplete_Type
(Typ
);
2387 end Is_Aliased_View_Of_Type
;
2393 function Process
(N
: Node_Id
) return Traverse_Result
is
2396 when N_Attribute_Reference
=>
2397 if Nam_In
(Attribute_Name
(N
), Name_Access
,
2398 Name_Unchecked_Access
)
2399 and then Is_Entity_Name
(Prefix
(N
))
2400 and then Is_Type
(Entity
(Prefix
(N
)))
2401 and then Entity
(Prefix
(N
)) = E
2403 if Ada_Version
< Ada_2012
then
2405 ("current instance must be a limited type",
2409 ("current instance must be an immutably limited "
2410 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2424 procedure Traverse
is new Traverse_Proc
(Process
);
2428 Rec_Type
: constant Entity_Id
:=
2429 Scope
(Defining_Identifier
(Comp_Decl
));
2431 -- Start of processing for Check_Current_Instance
2434 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2435 Traverse
(Comp_Decl
);
2437 end Check_Current_Instance
;
2439 ---------------------------------
2440 -- Check_Suspicious_Convention --
2441 ---------------------------------
2443 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
) is
2445 if Has_Discriminants
(Rec_Type
)
2446 and then Is_Base_Type
(Rec_Type
)
2447 and then not Is_Unchecked_Union
(Rec_Type
)
2448 and then (Convention
(Rec_Type
) = Convention_C
2450 Convention
(Rec_Type
) = Convention_CPP
)
2451 and then Comes_From_Source
(Rec_Type
)
2452 and then not In_Instance
2453 and then not Has_Warnings_Off
(Rec_Type
)
2456 Cprag
: constant Node_Id
:=
2457 Get_Rep_Pragma
(Rec_Type
, Name_Convention
);
2461 if Present
(Cprag
) then
2462 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
2464 if Convention
(Rec_Type
) = Convention_C
then
2466 ("?x?discriminated record has no direct equivalent in "
2470 ("?x?discriminated record has no direct equivalent in "
2475 ("\?x?use of convention for type& is dubious",
2480 end Check_Suspicious_Convention
;
2482 ------------------------------
2483 -- Check_Suspicious_Modulus --
2484 ------------------------------
2486 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
2487 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
2490 if not Warn_On_Suspicious_Modulus_Value
then
2494 if Nkind
(Decl
) = N_Full_Type_Declaration
then
2496 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
2499 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
2501 Modulus
: constant Node_Id
:=
2502 Original_Node
(Expression
(Tdef
));
2505 if Nkind
(Modulus
) = N_Integer_Literal
then
2507 Modv
: constant Uint
:= Intval
(Modulus
);
2508 Sizv
: constant Uint
:= RM_Size
(Utype
);
2511 -- First case, modulus and size are the same. This
2512 -- happens if you have something like mod 32, with
2513 -- an explicit size of 32, this is for sure a case
2514 -- where the warning is given, since it is seems
2515 -- very unlikely that someone would want e.g. a
2516 -- five bit type stored in 32 bits. It is much
2517 -- more likely they wanted a 32-bit type.
2522 -- Second case, the modulus is 32 or 64 and no
2523 -- size clause is present. This is a less clear
2524 -- case for giving the warning, but in the case
2525 -- of 32/64 (5-bit or 6-bit types) these seem rare
2526 -- enough that it is a likely error (and in any
2527 -- case using 2**5 or 2**6 in these cases seems
2528 -- clearer. We don't include 8 or 16 here, simply
2529 -- because in practice 3-bit and 4-bit types are
2530 -- more common and too many false positives if
2531 -- we warn in these cases.
2533 elsif not Has_Size_Clause
(Utype
)
2534 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
2538 -- No warning needed
2544 -- If we fall through, give warning
2546 Error_Msg_Uint_1
:= Modv
;
2548 ("?M?2 '*'*^' may have been intended here",
2556 end Check_Suspicious_Modulus
;
2558 -----------------------
2559 -- Freeze_Array_Type --
2560 -----------------------
2562 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2563 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2564 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2567 Non_Standard_Enum
: Boolean := False;
2568 -- Set true if any of the index types is an enumeration type with a
2569 -- non-standard representation.
2572 Freeze_And_Append
(Ctyp
, N
, Result
);
2574 Indx
:= First_Index
(Arr
);
2575 while Present
(Indx
) loop
2576 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2578 if Is_Enumeration_Type
(Etype
(Indx
))
2579 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2581 Non_Standard_Enum
:= True;
2587 -- Processing that is done only for base types
2589 if Ekind
(Arr
) = E_Array_Type
then
2591 -- Deal with default setting of reverse storage order
2593 Set_SSO_From_Default
(Arr
);
2595 -- Propagate flags for component type
2597 if Is_Controlled
(Component_Type
(Arr
))
2598 or else Has_Controlled_Component
(Ctyp
)
2600 Set_Has_Controlled_Component
(Arr
);
2603 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2604 Set_Has_Unchecked_Union
(Arr
);
2607 -- The array type requires its own invariant procedure in order to
2608 -- verify the component invariant over all elements. In GNATprove
2609 -- mode, the component invariants are checked by other means. They
2610 -- should not be added to the array type invariant procedure, so
2611 -- that the procedure can be used to check the array type
2612 -- invariants if any.
2614 if Has_Invariants
(Component_Type
(Arr
))
2615 and then not GNATprove_Mode
2617 Set_Has_Own_Invariants
(Arr
);
2619 -- The array type is an implementation base type. Propagate the
2620 -- same property to the first subtype.
2622 if Is_Itype
(Arr
) then
2623 Set_Has_Own_Invariants
(First_Subtype
(Arr
));
2627 -- Warn for pragma Pack overriding foreign convention
2629 if Has_Foreign_Convention
(Ctyp
)
2630 and then Has_Pragma_Pack
(Arr
)
2633 CN
: constant Name_Id
:=
2634 Get_Convention_Name
(Convention
(Ctyp
));
2635 PP
: constant Node_Id
:=
2636 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2638 if Present
(PP
) then
2639 Error_Msg_Name_1
:= CN
;
2640 Error_Msg_Sloc
:= Sloc
(Arr
);
2642 ("pragma Pack affects convention % components #??", PP
);
2643 Error_Msg_Name_1
:= CN
;
2645 ("\array components may not have % compatible "
2646 & "representation??", PP
);
2651 -- If packing was requested or if the component size was
2652 -- set explicitly, then see if bit packing is required. This
2653 -- processing is only done for base types, since all of the
2654 -- representation aspects involved are type-related.
2656 -- This is not just an optimization, if we start processing the
2657 -- subtypes, they interfere with the settings on the base type
2658 -- (this is because Is_Packed has a slightly different meaning
2659 -- before and after freezing).
2666 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2667 and then Known_Static_RM_Size
(Ctyp
)
2668 and then not Has_Component_Size_Clause
(Arr
)
2670 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2672 elsif Known_Component_Size
(Arr
) then
2673 Csiz
:= Component_Size
(Arr
);
2675 elsif not Known_Static_Esize
(Ctyp
) then
2679 Esiz
:= Esize
(Ctyp
);
2681 -- We can set the component size if it is less than 16,
2682 -- rounding it up to the next storage unit size.
2686 elsif Esiz
<= 16 then
2692 -- Set component size up to match alignment if it would
2693 -- otherwise be less than the alignment. This deals with
2694 -- cases of types whose alignment exceeds their size (the
2695 -- padded type cases).
2699 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2708 -- Case of component size that may result in bit packing
2710 if 1 <= Csiz
and then Csiz
<= 64 then
2712 Ent
: constant Entity_Id
:=
2713 First_Subtype
(Arr
);
2714 Pack_Pragma
: constant Node_Id
:=
2715 Get_Rep_Pragma
(Ent
, Name_Pack
);
2716 Comp_Size_C
: constant Node_Id
:=
2717 Get_Attribute_Definition_Clause
2718 (Ent
, Attribute_Component_Size
);
2721 -- Warn if we have pack and component size so that the
2724 -- Note: here we must check for the presence of a
2725 -- component size before checking for a Pack pragma to
2726 -- deal with the case where the array type is a derived
2727 -- type whose parent is currently private.
2729 if Present
(Comp_Size_C
)
2730 and then Has_Pragma_Pack
(Ent
)
2731 and then Warn_On_Redundant_Constructs
2733 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2735 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2737 ("\?r?explicit component size given#!", Pack_Pragma
);
2738 Set_Is_Packed
(Base_Type
(Ent
), False);
2739 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2742 -- Set component size if not already set by a component
2745 if not Present
(Comp_Size_C
) then
2746 Set_Component_Size
(Arr
, Csiz
);
2749 -- Check for base type of 8, 16, 32 bits, where an
2750 -- unsigned subtype has a length one less than the
2751 -- base type (e.g. Natural subtype of Integer).
2753 -- In such cases, if a component size was not set
2754 -- explicitly, then generate a warning.
2756 if Has_Pragma_Pack
(Arr
)
2757 and then not Present
(Comp_Size_C
)
2758 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2759 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2761 Error_Msg_Uint_1
:= Csiz
;
2763 if Present
(Pack_Pragma
) then
2765 ("??pragma Pack causes component size to be ^!",
2768 ("\??use Component_Size to set desired value!",
2773 -- Bit packing is never needed for 8, 16, 32, 64
2775 if Addressable
(Csiz
) then
2777 -- If the Esize of the component is known and equal to
2778 -- the component size then even packing is not needed.
2780 if Known_Static_Esize
(Component_Type
(Arr
))
2781 and then Esize
(Component_Type
(Arr
)) = Csiz
2783 -- Here the array was requested to be packed, but
2784 -- the packing request had no effect whatsoever,
2785 -- so flag Is_Packed is reset.
2787 -- Note: semantically this means that we lose track
2788 -- of the fact that a derived type inherited pragma
2789 -- Pack that was non-effective, but that is fine.
2791 -- We regard a Pack pragma as a request to set a
2792 -- representation characteristic, and this request
2795 Set_Is_Packed
(Base_Type
(Arr
), False);
2796 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
2798 Set_Is_Packed
(Base_Type
(Arr
), True);
2799 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2802 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2804 -- Bit packing is not needed for multiples of the storage
2805 -- unit if the type is composite because the back end can
2806 -- byte pack composite types.
2808 elsif Csiz
mod System_Storage_Unit
= 0
2809 and then Is_Composite_Type
(Ctyp
)
2811 Set_Is_Packed
(Base_Type
(Arr
), True);
2812 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2813 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2815 -- In all other cases, bit packing is needed
2818 Set_Is_Packed
(Base_Type
(Arr
), True);
2819 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2820 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2826 -- Check for Aliased or Atomic_Components/Atomic/VFA with
2827 -- unsuitable packing or explicit component size clause given.
2829 if (Has_Aliased_Components
(Arr
)
2830 or else Has_Atomic_Components
(Arr
)
2831 or else Is_Atomic_Or_VFA
(Ctyp
))
2833 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2835 Alias_Atomic_Check
: declare
2837 procedure Complain_CS
(T
: String);
2838 -- Outputs error messages for incorrect CS clause or pragma
2839 -- Pack for aliased or atomic/VFA components (T is "aliased"
2840 -- or "atomic/vfa");
2846 procedure Complain_CS
(T
: String) is
2848 if Has_Component_Size_Clause
(Arr
) then
2850 Get_Attribute_Definition_Clause
2851 (FS
, Attribute_Component_Size
);
2854 ("incorrect component size for "
2855 & T
& " components", Clause
);
2856 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2858 ("\only allowed value is^", Clause
);
2862 ("cannot pack " & T
& " components",
2863 Get_Rep_Pragma
(FS
, Name_Pack
));
2867 -- Start of processing for Alias_Atomic_Check
2870 -- If object size of component type isn't known, we cannot
2871 -- be sure so we defer to the back end.
2873 if not Known_Static_Esize
(Ctyp
) then
2876 -- Case where component size has no effect. First check for
2877 -- object size of component type multiple of the storage
2880 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2882 -- OK in both packing case and component size case if RM
2883 -- size is known and static and same as the object size.
2886 ((Known_Static_RM_Size
(Ctyp
)
2887 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2889 -- Or if we have an explicit component size clause and
2890 -- the component size and object size are equal.
2893 (Has_Component_Size_Clause
(Arr
)
2894 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2898 elsif Has_Aliased_Components
(Arr
) then
2899 Complain_CS
("aliased");
2901 elsif Has_Atomic_Components
(Arr
)
2902 or else Is_Atomic
(Ctyp
)
2904 Complain_CS
("atomic");
2906 elsif Is_Volatile_Full_Access
(Ctyp
) then
2907 Complain_CS
("volatile full access");
2909 end Alias_Atomic_Check
;
2912 -- Check for Independent_Components/Independent with unsuitable
2913 -- packing or explicit component size clause given.
2915 if (Has_Independent_Components
(Arr
) or else Is_Independent
(Ctyp
))
2917 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2920 -- If object size of component type isn't known, we cannot
2921 -- be sure so we defer to the back end.
2923 if not Known_Static_Esize
(Ctyp
) then
2926 -- Case where component size has no effect. First check for
2927 -- object size of component type multiple of the storage
2930 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2932 -- OK in both packing case and component size case if RM
2933 -- size is known and multiple of the storage unit size.
2936 ((Known_Static_RM_Size
(Ctyp
)
2937 and then RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
2939 -- Or if we have an explicit component size clause and
2940 -- the component size is larger than the object size.
2943 (Has_Component_Size_Clause
(Arr
)
2944 and then Component_Size
(Arr
) >= Esize
(Ctyp
)))
2949 if Has_Component_Size_Clause
(Arr
) then
2951 Get_Attribute_Definition_Clause
2952 (FS
, Attribute_Component_Size
);
2955 ("incorrect component size for "
2956 & "independent components", Clause
);
2957 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2959 ("\minimum allowed is^", Clause
);
2963 ("cannot pack independent components",
2964 Get_Rep_Pragma
(FS
, Name_Pack
));
2970 -- Warn for case of atomic type
2972 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2975 and then not Addressable
(Component_Size
(FS
))
2978 ("non-atomic components of type& may not be "
2979 & "accessible by separate tasks??", Clause
, Arr
);
2981 if Has_Component_Size_Clause
(Arr
) then
2982 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2983 (FS
, Attribute_Component_Size
));
2984 Error_Msg_N
("\because of component size clause#??", Clause
);
2986 elsif Has_Pragma_Pack
(Arr
) then
2987 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2988 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2992 -- Check for scalar storage order
2997 Check_Component_Storage_Order
3000 ADC
=> Get_Attribute_Definition_Clause
3001 (First_Subtype
(Arr
),
3002 Attribute_Scalar_Storage_Order
),
3003 Comp_ADC_Present
=> Dummy
);
3006 -- Processing that is done only for subtypes
3009 -- Acquire alignment from base type
3011 if Unknown_Alignment
(Arr
) then
3012 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
3013 Adjust_Esize_Alignment
(Arr
);
3017 -- Specific checks for bit-packed arrays
3019 if Is_Bit_Packed_Array
(Arr
) then
3021 -- Check number of elements for bit-packed arrays that come from
3022 -- source and have compile time known ranges. The bit-packed
3023 -- arrays circuitry does not support arrays with more than
3024 -- Integer'Last + 1 elements, and when this restriction is
3025 -- violated, causes incorrect data access.
3027 -- For the case where this is not compile time known, a run-time
3028 -- check should be generated???
3030 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
3039 Index
:= First_Index
(Arr
);
3040 while Present
(Index
) loop
3041 Ityp
:= Etype
(Index
);
3043 -- Never generate an error if any index is of a generic
3044 -- type. We will check this in instances.
3046 if Is_Generic_Type
(Ityp
) then
3052 Make_Attribute_Reference
(Loc
,
3053 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
3054 Attribute_Name
=> Name_Range_Length
);
3055 Analyze_And_Resolve
(Ilen
);
3057 -- No attempt is made to check number of elements if not
3058 -- compile time known.
3060 if Nkind
(Ilen
) /= N_Integer_Literal
then
3065 Elmts
:= Elmts
* Intval
(Ilen
);
3069 if Elmts
> Intval
(High_Bound
3070 (Scalar_Range
(Standard_Integer
))) + 1
3073 ("bit packed array type may not have "
3074 & "more than Integer''Last+1 elements", Arr
);
3081 if Known_RM_Size
(Arr
) then
3083 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
3087 -- It is not clear if it is possible to have no size clause
3088 -- at this stage, but it is not worth worrying about. Post
3089 -- error on the entity name in the size clause if present,
3090 -- else on the type entity itself.
3092 if Present
(SizC
) then
3093 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
3095 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
3101 -- If any of the index types was an enumeration type with a non-
3102 -- standard rep clause, then we indicate that the array type is
3103 -- always packed (even if it is not bit-packed).
3105 if Non_Standard_Enum
then
3106 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
3107 Set_Is_Packed
(Base_Type
(Arr
));
3110 Set_Component_Alignment_If_Not_Set
(Arr
);
3112 -- If the array is packed and bit-packed or packed to eliminate holes
3113 -- in the non-contiguous enumeration index types, we must create the
3114 -- packed array type to be used to actually implement the type. This
3115 -- is only needed for real array types (not for string literal types,
3116 -- since they are present only for the front end).
3119 and then (Is_Bit_Packed_Array
(Arr
) or else Non_Standard_Enum
)
3120 and then Ekind
(Arr
) /= E_String_Literal_Subtype
3122 Create_Packed_Array_Impl_Type
(Arr
);
3123 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
3125 -- Make sure that we have the necessary routines to implement the
3126 -- packing, and complain now if not. Note that we only test this
3127 -- for constrained array types.
3129 if Is_Constrained
(Arr
)
3130 and then Is_Bit_Packed_Array
(Arr
)
3131 and then Present
(Packed_Array_Impl_Type
(Arr
))
3132 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
3135 CS
: constant Uint
:= Component_Size
(Arr
);
3136 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
3140 and then not RTE_Available
(RE
)
3143 ("packing of " & UI_Image
(CS
) & "-bit components",
3144 First_Subtype
(Etype
(Arr
)));
3146 -- Cancel the packing
3148 Set_Is_Packed
(Base_Type
(Arr
), False);
3149 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
3150 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
3156 -- Size information of packed array type is copied to the array
3157 -- type, since this is really the representation. But do not
3158 -- override explicit existing size values. If the ancestor subtype
3159 -- is constrained the Packed_Array_Impl_Type will be inherited
3160 -- from it, but the size may have been provided already, and
3161 -- must not be overridden either.
3163 if not Has_Size_Clause
(Arr
)
3165 (No
(Ancestor_Subtype
(Arr
))
3166 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
3168 Set_Esize
(Arr
, Esize
(Packed_Array_Impl_Type
(Arr
)));
3169 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Impl_Type
(Arr
)));
3172 if not Has_Alignment_Clause
(Arr
) then
3173 Set_Alignment
(Arr
, Alignment
(Packed_Array_Impl_Type
(Arr
)));
3179 -- For non-packed arrays set the alignment of the array to the
3180 -- alignment of the component type if it is unknown. Skip this
3181 -- in atomic/VFA case (atomic/VFA arrays may need larger alignments).
3183 if not Is_Packed
(Arr
)
3184 and then Unknown_Alignment
(Arr
)
3185 and then Known_Alignment
(Ctyp
)
3186 and then Known_Static_Component_Size
(Arr
)
3187 and then Known_Static_Esize
(Ctyp
)
3188 and then Esize
(Ctyp
) = Component_Size
(Arr
)
3189 and then not Is_Atomic_Or_VFA
(Arr
)
3191 Set_Alignment
(Arr
, Alignment
(Component_Type
(Arr
)));
3194 -- A Ghost type cannot have a component of protected or task type
3195 -- (SPARK RM 6.9(19)).
3197 if Is_Ghost_Entity
(Arr
) and then Is_Concurrent_Type
(Ctyp
) then
3199 ("ghost array type & cannot have concurrent component type",
3202 end Freeze_Array_Type
;
3204 -------------------------------
3205 -- Freeze_Object_Declaration --
3206 -------------------------------
3208 procedure Freeze_Object_Declaration
(E
: Entity_Id
) is
3209 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
);
3210 -- Check that the size of array type Typ can be computed without
3211 -- overflow, and generates a Storage_Error otherwise. This is only
3212 -- relevant for array types whose index is a (mod 2**64) type, where
3213 -- wrap-around arithmetic might yield a meaningless value for the
3214 -- length of the array, or its corresponding attribute.
3216 -------------------------------
3217 -- Check_Large_Modular_Array --
3218 -------------------------------
3220 procedure Check_Large_Modular_Array
(Typ
: Entity_Id
) is
3221 Obj_Loc
: constant Source_Ptr
:= Sloc
(E
);
3222 Idx_Typ
: Entity_Id
;
3225 -- Nothing to do when expansion is disabled because this routine
3226 -- generates a runtime check.
3228 if not Expander_Active
then
3231 -- Nothing to do for String literal subtypes because their index
3232 -- cannot be a modular type.
3234 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
3237 -- Nothing to do for an imported object because the object will
3238 -- be created on the exporting side.
3240 elsif Is_Imported
(E
) then
3243 -- Nothing to do for unconstrained array types. This case arises
3244 -- when the object declaration is illegal.
3246 elsif not Is_Constrained
(Typ
) then
3250 Idx_Typ
:= Etype
(First_Index
(Typ
));
3252 -- To prevent arithmetic overflow with large values, we raise
3253 -- Storage_Error under the following guard:
3255 -- (Arr'Last / 2 - Arr'First / 2) > (2 ** 30)
3257 -- This takes care of the boundary case, but it is preferable to
3258 -- use a smaller limit, because even on 64-bit architectures an
3259 -- array of more than 2 ** 30 bytes is likely to raise
3262 if Is_Modular_Integer_Type
(Idx_Typ
)
3263 and then RM_Size
(Idx_Typ
) = RM_Size
(Standard_Long_Long_Integer
)
3265 Insert_Action
(Declaration_Node
(E
),
3266 Make_Raise_Storage_Error
(Obj_Loc
,
3268 Make_Op_Ge
(Obj_Loc
,
3270 Make_Op_Subtract
(Obj_Loc
,
3272 Make_Op_Divide
(Obj_Loc
,
3274 Make_Attribute_Reference
(Obj_Loc
,
3276 New_Occurrence_Of
(Typ
, Obj_Loc
),
3277 Attribute_Name
=> Name_Last
),
3279 Make_Integer_Literal
(Obj_Loc
, Uint_2
)),
3281 Make_Op_Divide
(Obj_Loc
,
3283 Make_Attribute_Reference
(Obj_Loc
,
3285 New_Occurrence_Of
(Typ
, Obj_Loc
),
3286 Attribute_Name
=> Name_First
),
3288 Make_Integer_Literal
(Obj_Loc
, Uint_2
))),
3290 Make_Integer_Literal
(Obj_Loc
, (Uint_2
** 30))),
3291 Reason
=> SE_Object_Too_Large
));
3293 end Check_Large_Modular_Array
;
3297 Typ
: constant Entity_Id
:= Etype
(E
);
3300 -- Start of processing for Freeze_Object_Declaration
3303 -- Abstract type allowed only for C++ imported variables or constants
3305 -- Note: we inhibit this check for objects that do not come from
3306 -- source because there is at least one case (the expansion of
3307 -- x'Class'Input where x is abstract) where we legitimately
3308 -- generate an abstract object.
3310 if Is_Abstract_Type
(Typ
)
3311 and then Comes_From_Source
(Parent
(E
))
3312 and then not (Is_Imported
(E
) and then Is_CPP_Class
(Typ
))
3314 Def
:= Object_Definition
(Parent
(E
));
3316 Error_Msg_N
("type of object cannot be abstract", Def
);
3318 if Is_CPP_Class
(Etype
(E
)) then
3319 Error_Msg_NE
("\} may need a cpp_constructor", Def
, Typ
);
3321 elsif Present
(Expression
(Parent
(E
))) then
3322 Error_Msg_N
-- CODEFIX
3323 ("\maybe a class-wide type was meant", Def
);
3327 -- For object created by object declaration, perform required
3328 -- categorization (preelaborate and pure) checks. Defer these
3329 -- checks to freeze time since pragma Import inhibits default
3330 -- initialization and thus pragma Import affects these checks.
3332 Validate_Object_Declaration
(Declaration_Node
(E
));
3334 -- If there is an address clause, check that it is valid and if need
3335 -- be move initialization to the freeze node.
3337 Check_Address_Clause
(E
);
3339 -- Similar processing is needed for aspects that may affect object
3340 -- layout, like Alignment, if there is an initialization expression.
3341 -- We don't do this if there is a pragma Linker_Section, because it
3342 -- would prevent the back end from statically initializing the
3343 -- object; we don't want elaboration code in that case.
3345 if Has_Delayed_Aspects
(E
)
3346 and then Expander_Active
3347 and then Is_Array_Type
(Typ
)
3348 and then Present
(Expression
(Parent
(E
)))
3349 and then No
(Linker_Section_Pragma
(E
))
3352 Decl
: constant Node_Id
:= Parent
(E
);
3353 Lhs
: constant Node_Id
:= New_Occurrence_Of
(E
, Loc
);
3356 -- Capture initialization value at point of declaration, and
3357 -- make explicit assignment legal, because object may be a
3360 Remove_Side_Effects
(Expression
(Decl
));
3361 Set_Assignment_OK
(Lhs
);
3363 -- Move initialization to freeze actions
3365 Append_Freeze_Action
(E
,
3366 Make_Assignment_Statement
(Loc
,
3368 Expression
=> Expression
(Decl
)));
3370 Set_No_Initialization
(Decl
);
3371 -- Set_Is_Frozen (E, False);
3375 -- Reset Is_True_Constant for non-constant aliased object. We
3376 -- consider that the fact that a non-constant object is aliased may
3377 -- indicate that some funny business is going on, e.g. an aliased
3378 -- object is passed by reference to a procedure which captures the
3379 -- address of the object, which is later used to assign a new value,
3380 -- even though the compiler thinks that it is not modified. Such
3381 -- code is highly dubious, but we choose to make it "work" for
3382 -- non-constant aliased objects.
3384 -- Note that we used to do this for all aliased objects, whether or
3385 -- not constant, but this caused anomalies down the line because we
3386 -- ended up with static objects that were not Is_True_Constant. Not
3387 -- resetting Is_True_Constant for (aliased) constant objects ensures
3388 -- that this anomaly never occurs.
3390 -- However, we don't do that for internal entities. We figure that if
3391 -- we deliberately set Is_True_Constant for an internal entity, e.g.
3392 -- a dispatch table entry, then we mean it.
3394 if Ekind
(E
) /= E_Constant
3395 and then (Is_Aliased
(E
) or else Is_Aliased
(Typ
))
3396 and then not Is_Internal_Name
(Chars
(E
))
3398 Set_Is_True_Constant
(E
, False);
3401 -- If the object needs any kind of default initialization, an error
3402 -- must be issued if No_Default_Initialization applies. The check
3403 -- doesn't apply to imported objects, which are not ever default
3404 -- initialized, and is why the check is deferred until freezing, at
3405 -- which point we know if Import applies. Deferred constants are also
3406 -- exempted from this test because their completion is explicit, or
3407 -- through an import pragma.
3409 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
3412 elsif Comes_From_Source
(E
)
3413 and then not Is_Imported
(E
)
3414 and then not Has_Init_Expression
(Declaration_Node
(E
))
3416 ((Has_Non_Null_Base_Init_Proc
(Typ
)
3417 and then not No_Initialization
(Declaration_Node
(E
))
3418 and then not Initialization_Suppressed
(Typ
))
3420 (Needs_Simple_Initialization
(Typ
)
3421 and then not Is_Internal
(E
)))
3423 Has_Default_Initialization
:= True;
3425 (No_Default_Initialization
, Declaration_Node
(E
));
3428 -- Check that a Thread_Local_Storage variable does not have default
3429 -- initialization, and any explicit initialization must either be the
3430 -- null constant or a static constant.
3432 if Has_Pragma_Thread_Local_Storage
(E
) then
3434 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3436 if Has_Default_Initialization
3438 (Has_Init_Expression
(Decl
)
3440 (No
(Expression
(Decl
))
3442 (Is_OK_Static_Expression
(Expression
(Decl
))
3443 or else Nkind
(Expression
(Decl
)) = N_Null
)))
3445 if Nkind
(Expression
(Decl
)) = N_Aggregate
3446 and then Compile_Time_Known_Aggregate
(Expression
(Decl
))
3451 ("Thread_Local_Storage variable& is improperly "
3452 & "initialized", Decl
, E
);
3454 ("\only allowed initialization is explicit NULL, "
3455 & "static expression or static aggregate", Decl
, E
);
3461 -- For imported objects, set Is_Public unless there is also an
3462 -- address clause, which means that there is no external symbol
3463 -- needed for the Import (Is_Public may still be set for other
3464 -- unrelated reasons). Note that we delayed this processing
3465 -- till freeze time so that we can be sure not to set the flag
3466 -- if there is an address clause. If there is such a clause,
3467 -- then the only purpose of the Import pragma is to suppress
3468 -- implicit initialization.
3470 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
3474 -- For source objects that are not Imported and are library level, if
3475 -- no linker section pragma was given inherit the appropriate linker
3476 -- section from the corresponding type.
3478 if Comes_From_Source
(E
)
3479 and then not Is_Imported
(E
)
3480 and then Is_Library_Level_Entity
(E
)
3481 and then No
(Linker_Section_Pragma
(E
))
3483 Set_Linker_Section_Pragma
(E
, Linker_Section_Pragma
(Typ
));
3486 -- For convention C objects of an enumeration type, warn if the size
3487 -- is not integer size and no explicit size given. Skip warning for
3488 -- Boolean and Character, and assume programmer expects 8-bit sizes
3491 if (Convention
(E
) = Convention_C
3493 Convention
(E
) = Convention_CPP
)
3494 and then Is_Enumeration_Type
(Typ
)
3495 and then not Is_Character_Type
(Typ
)
3496 and then not Is_Boolean_Type
(Typ
)
3497 and then Esize
(Typ
) < Standard_Integer_Size
3498 and then not Has_Size_Clause
(E
)
3500 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
3502 ("??convention C enumeration object has size less than ^", E
);
3503 Error_Msg_N
("\??use explicit size clause to set size", E
);
3506 if Is_Array_Type
(Typ
) then
3507 Check_Large_Modular_Array
(Typ
);
3509 end Freeze_Object_Declaration
;
3511 -----------------------------
3512 -- Freeze_Generic_Entities --
3513 -----------------------------
3515 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
3522 E
:= First_Entity
(Pack
);
3523 while Present
(E
) loop
3524 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
3525 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
3527 Append_To
(Flist
, F
);
3529 elsif Ekind
(E
) = E_Generic_Package
then
3530 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
3537 end Freeze_Generic_Entities
;
3539 --------------------
3540 -- Freeze_Profile --
3541 --------------------
3543 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
3546 Warn_Node
: Node_Id
;
3549 -- Loop through formals
3551 Formal
:= First_Formal
(E
);
3552 while Present
(Formal
) loop
3553 F_Type
:= Etype
(Formal
);
3555 -- AI05-0151: incomplete types can appear in a profile. By the
3556 -- time the entity is frozen, the full view must be available,
3557 -- unless it is a limited view.
3559 if Is_Incomplete_Type
(F_Type
)
3560 and then Present
(Full_View
(F_Type
))
3561 and then not From_Limited_With
(F_Type
)
3563 F_Type
:= Full_View
(F_Type
);
3564 Set_Etype
(Formal
, F_Type
);
3567 if not From_Limited_With
(F_Type
) then
3568 Freeze_And_Append
(F_Type
, N
, Result
);
3571 if Is_Private_Type
(F_Type
)
3572 and then Is_Private_Type
(Base_Type
(F_Type
))
3573 and then No
(Full_View
(Base_Type
(F_Type
)))
3574 and then not Is_Generic_Type
(F_Type
)
3575 and then not Is_Derived_Type
(F_Type
)
3577 -- If the type of a formal is incomplete, subprogram is being
3578 -- frozen prematurely. Within an instance (but not within a
3579 -- wrapper package) this is an artifact of our need to regard
3580 -- the end of an instantiation as a freeze point. Otherwise it
3581 -- is a definite error.
3584 Set_Is_Frozen
(E
, False);
3588 elsif not After_Last_Declaration
3589 and then not Freezing_Library_Level_Tagged_Type
3591 Error_Msg_Node_1
:= F_Type
;
3593 ("type & must be fully defined before this point", Loc
);
3597 -- Check suspicious parameter for C function. These tests apply
3598 -- only to exported/imported subprograms.
3600 if Warn_On_Export_Import
3601 and then Comes_From_Source
(E
)
3602 and then (Convention
(E
) = Convention_C
3604 Convention
(E
) = Convention_CPP
)
3605 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3606 and then Convention
(E
) /= Convention
(Formal
)
3607 and then not Has_Warnings_Off
(E
)
3608 and then not Has_Warnings_Off
(F_Type
)
3609 and then not Has_Warnings_Off
(Formal
)
3611 -- Qualify mention of formals with subprogram name
3613 Error_Msg_Qual_Level
:= 1;
3615 -- Check suspicious use of fat C pointer, but do not emit
3616 -- a warning on an access to subprogram when unnesting is
3619 if Is_Access_Type
(F_Type
)
3620 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
3621 and then (not Unnest_Subprogram_Mode
3622 or else not Is_Access_Subprogram_Type
(F_Type
))
3625 ("?x?type of & does not correspond to C pointer!", Formal
);
3627 -- Check suspicious return of boolean
3629 elsif Root_Type
(F_Type
) = Standard_Boolean
3630 and then Convention
(F_Type
) = Convention_Ada
3631 and then not Has_Warnings_Off
(F_Type
)
3632 and then not Has_Size_Clause
(F_Type
)
3635 ("& is an 8-bit Ada Boolean?x?", Formal
);
3637 ("\use appropriate corresponding type in C "
3638 & "(e.g. char)?x?", Formal
);
3640 -- Check suspicious tagged type
3642 elsif (Is_Tagged_Type
(F_Type
)
3644 (Is_Access_Type
(F_Type
)
3645 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
3646 and then Convention
(E
) = Convention_C
3649 ("?x?& involves a tagged type which does not "
3650 & "correspond to any C type!", Formal
);
3652 -- Check wrong convention subprogram pointer
3654 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
3655 and then not Has_Foreign_Convention
(F_Type
)
3658 ("?x?subprogram pointer & should "
3659 & "have foreign convention!", Formal
);
3660 Error_Msg_Sloc
:= Sloc
(F_Type
);
3662 ("\?x?add Convention pragma to declaration of &#",
3666 -- Turn off name qualification after message output
3668 Error_Msg_Qual_Level
:= 0;
3671 -- Check for unconstrained array in exported foreign convention
3674 if Has_Foreign_Convention
(E
)
3675 and then not Is_Imported
(E
)
3676 and then Is_Array_Type
(F_Type
)
3677 and then not Is_Constrained
(F_Type
)
3678 and then Warn_On_Export_Import
3680 Error_Msg_Qual_Level
:= 1;
3682 -- If this is an inherited operation, place the warning on
3683 -- the derived type declaration, rather than on the original
3686 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
3688 Warn_Node
:= Parent
(E
);
3690 if Formal
= First_Formal
(E
) then
3691 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
3694 Warn_Node
:= Formal
;
3697 Error_Msg_NE
("?x?type of argument& is unconstrained array",
3699 Error_Msg_NE
("?x?foreign caller must pass bounds explicitly",
3701 Error_Msg_Qual_Level
:= 0;
3704 if not From_Limited_With
(F_Type
) then
3705 if Is_Access_Type
(F_Type
) then
3706 F_Type
:= Designated_Type
(F_Type
);
3709 -- If the formal is an anonymous_access_to_subprogram
3710 -- freeze the subprogram type as well, to prevent
3711 -- scope anomalies in gigi, because there is no other
3712 -- clear point at which it could be frozen.
3714 if Is_Itype
(Etype
(Formal
))
3715 and then Ekind
(F_Type
) = E_Subprogram_Type
3717 Freeze_And_Append
(F_Type
, N
, Result
);
3721 Next_Formal
(Formal
);
3724 -- Case of function: similar checks on return type
3726 if Ekind
(E
) = E_Function
then
3728 -- Freeze return type
3730 R_Type
:= Etype
(E
);
3732 -- AI05-0151: the return type may have been incomplete at the
3733 -- point of declaration. Replace it with the full view, unless the
3734 -- current type is a limited view. In that case the full view is
3735 -- in a different unit, and gigi finds the non-limited view after
3736 -- the other unit is elaborated.
3738 if Ekind
(R_Type
) = E_Incomplete_Type
3739 and then Present
(Full_View
(R_Type
))
3740 and then not From_Limited_With
(R_Type
)
3742 R_Type
:= Full_View
(R_Type
);
3743 Set_Etype
(E
, R_Type
);
3746 Freeze_And_Append
(R_Type
, N
, Result
);
3748 -- Check suspicious return type for C function
3750 if Warn_On_Export_Import
3751 and then (Convention
(E
) = Convention_C
3753 Convention
(E
) = Convention_CPP
)
3754 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3756 -- Check suspicious return of fat C pointer
3758 if Is_Access_Type
(R_Type
)
3759 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
3760 and then not Has_Warnings_Off
(E
)
3761 and then not Has_Warnings_Off
(R_Type
)
3764 ("?x?return type of& does not correspond to C pointer!",
3767 -- Check suspicious return of boolean
3769 elsif Root_Type
(R_Type
) = Standard_Boolean
3770 and then Convention
(R_Type
) = Convention_Ada
3771 and then not Has_Warnings_Off
(E
)
3772 and then not Has_Warnings_Off
(R_Type
)
3773 and then not Has_Size_Clause
(R_Type
)
3776 N
: constant Node_Id
:=
3777 Result_Definition
(Declaration_Node
(E
));
3780 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
3782 ("\use appropriate corresponding type in C "
3783 & "(e.g. char)?x?", N
, E
);
3786 -- Check suspicious return tagged type
3788 elsif (Is_Tagged_Type
(R_Type
)
3789 or else (Is_Access_Type
(R_Type
)
3792 (Designated_Type
(R_Type
))))
3793 and then Convention
(E
) = Convention_C
3794 and then not Has_Warnings_Off
(E
)
3795 and then not Has_Warnings_Off
(R_Type
)
3797 Error_Msg_N
("?x?return type of & does not "
3798 & "correspond to C type!", E
);
3800 -- Check return of wrong convention subprogram pointer
3802 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3803 and then not Has_Foreign_Convention
(R_Type
)
3804 and then not Has_Warnings_Off
(E
)
3805 and then not Has_Warnings_Off
(R_Type
)
3807 Error_Msg_N
("?x?& should return a foreign "
3808 & "convention subprogram pointer", E
);
3809 Error_Msg_Sloc
:= Sloc
(R_Type
);
3811 ("\?x?add Convention pragma to declaration of& #",
3816 -- Give warning for suspicious return of a result of an
3817 -- unconstrained array type in a foreign convention function.
3819 if Has_Foreign_Convention
(E
)
3821 -- We are looking for a return of unconstrained array
3823 and then Is_Array_Type
(R_Type
)
3824 and then not Is_Constrained
(R_Type
)
3826 -- Exclude imported routines, the warning does not belong on
3827 -- the import, but rather on the routine definition.
3829 and then not Is_Imported
(E
)
3831 -- Check that general warning is enabled, and that it is not
3832 -- suppressed for this particular case.
3834 and then Warn_On_Export_Import
3835 and then not Has_Warnings_Off
(E
)
3836 and then not Has_Warnings_Off
(R_Type
)
3839 ("?x?foreign convention function& should not return "
3840 & "unconstrained array!", E
);
3844 -- Check suspicious use of Import in pure unit (cases where the RM
3845 -- allows calls to be omitted).
3849 -- It might be suspicious if the compilation unit has the Pure
3852 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
3854 -- The RM allows omission of calls only in the case of
3855 -- library-level subprograms (see RM-10.2.1(18)).
3857 and then Is_Library_Level_Entity
(E
)
3859 -- Ignore internally generated entity. This happens in some cases
3860 -- of subprograms in specs, where we generate an implied body.
3862 and then Comes_From_Source
(Import_Pragma
(E
))
3864 -- Assume run-time knows what it is doing
3866 and then not GNAT_Mode
3868 -- Assume explicit Pure_Function means import is pure
3870 and then not Has_Pragma_Pure_Function
(E
)
3872 -- Don't need warning in relaxed semantics mode
3874 and then not Relaxed_RM_Semantics
3876 -- Assume convention Intrinsic is OK, since this is specialized.
3877 -- This deals with the DEC unit current_exception.ads
3879 and then Convention
(E
) /= Convention_Intrinsic
3881 -- Assume that ASM interface knows what it is doing. This deals
3882 -- with e.g. unsigned.ads in the AAMP back end.
3884 and then Convention
(E
) /= Convention_Assembler
3887 ("pragma Import in Pure unit??", Import_Pragma
(E
));
3889 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
3890 Import_Pragma
(E
), E
);
3896 ------------------------
3897 -- Freeze_Record_Type --
3898 ------------------------
3900 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
3907 pragma Warnings
(Off
, Junk
);
3909 Aliased_Component
: Boolean := False;
3910 -- Set True if we find at least one component which is aliased. This
3911 -- is used to prevent Implicit_Packing of the record, since packing
3912 -- cannot modify the size of alignment of an aliased component.
3914 All_Elem_Components
: Boolean := True;
3915 -- True if all components are of a type whose underlying type is
3918 All_Sized_Components
: Boolean := True;
3919 -- True if all components have a known RM_Size
3921 All_Storage_Unit_Components
: Boolean := True;
3922 -- True if all components have an RM_Size that is a multiple of the
3925 Elem_Component_Total_Esize
: Uint
:= Uint_0
;
3926 -- Accumulates total Esize values of all elementary components. Used
3927 -- for processing of Implicit_Packing.
3929 Placed_Component
: Boolean := False;
3930 -- Set True if we find at least one component with a component
3931 -- clause (used to warn about useless Bit_Order pragmas, and also
3932 -- to detect cases where Implicit_Packing may have an effect).
3934 Rec_Pushed
: Boolean := False;
3935 -- Set True if the record type scope Rec has been pushed on the scope
3936 -- stack. Needed for the analysis of delayed aspects specified to the
3937 -- components of Rec.
3939 Sized_Component_Total_RM_Size
: Uint
:= Uint_0
;
3940 -- Accumulates total RM_Size values of all sized components. Used
3941 -- for processing of Implicit_Packing.
3943 Sized_Component_Total_Round_RM_Size
: Uint
:= Uint_0
;
3944 -- Accumulates total RM_Size values of all sized components, rounded
3945 -- individually to a multiple of the storage unit.
3948 -- Scalar_Storage_Order attribute definition clause for the record
3950 SSO_ADC_Component
: Boolean := False;
3951 -- Set True if we find at least one component whose type has a
3952 -- Scalar_Storage_Order attribute definition clause.
3954 Unplaced_Component
: Boolean := False;
3955 -- Set True if we find at least one component with no component
3956 -- clause (used to warn about useless Pack pragmas).
3958 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
3959 -- If N is an allocator, possibly wrapped in one or more level of
3960 -- qualified expression(s), return the inner allocator node, else
3963 procedure Check_Itype
(Typ
: Entity_Id
);
3964 -- If the component subtype is an access to a constrained subtype of
3965 -- an already frozen type, make the subtype frozen as well. It might
3966 -- otherwise be frozen in the wrong scope, and a freeze node on
3967 -- subtype has no effect. Similarly, if the component subtype is a
3968 -- regular (not protected) access to subprogram, set the anonymous
3969 -- subprogram type to frozen as well, to prevent an out-of-scope
3970 -- freeze node at some eventual point of call. Protected operations
3971 -- are handled elsewhere.
3973 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
3974 -- Make sure that all types mentioned in Discrete_Choices of the
3975 -- variants referenceed by the Variant_Part VP are frozen. This is
3976 -- a recursive routine to deal with nested variants.
3978 ---------------------
3979 -- Check_Allocator --
3980 ---------------------
3982 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
3987 if Nkind
(Inner
) = N_Allocator
then
3989 elsif Nkind
(Inner
) = N_Qualified_Expression
then
3990 Inner
:= Expression
(Inner
);
3995 end Check_Allocator
;
4001 procedure Check_Itype
(Typ
: Entity_Id
) is
4002 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
4005 if not Is_Frozen
(Desig
)
4006 and then Is_Frozen
(Base_Type
(Desig
))
4008 Set_Is_Frozen
(Desig
);
4010 -- In addition, add an Itype_Reference to ensure that the
4011 -- access subtype is elaborated early enough. This cannot be
4012 -- done if the subtype may depend on discriminants.
4014 if Ekind
(Comp
) = E_Component
4015 and then Is_Itype
(Etype
(Comp
))
4016 and then not Has_Discriminants
(Rec
)
4018 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
4019 Set_Itype
(IR
, Desig
);
4023 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
4024 and then Convention
(Desig
) /= Convention_Protected
4026 Set_Is_Frozen
(Desig
);
4030 ------------------------------------
4031 -- Freeze_Choices_In_Variant_Part --
4032 ------------------------------------
4034 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
4035 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
4042 -- Loop through variants
4044 Variant
:= First_Non_Pragma
(Variants
(VP
));
4045 while Present
(Variant
) loop
4047 -- Loop through choices, checking that all types are frozen
4049 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
4050 while Present
(Choice
) loop
4051 if Nkind
(Choice
) in N_Has_Etype
4052 and then Present
(Etype
(Choice
))
4054 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
4057 Next_Non_Pragma
(Choice
);
4060 -- Check for nested variant part to process
4062 CL
:= Component_List
(Variant
);
4064 if not Null_Present
(CL
) then
4065 if Present
(Variant_Part
(CL
)) then
4066 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
4070 Next_Non_Pragma
(Variant
);
4072 end Freeze_Choices_In_Variant_Part
;
4074 -- Start of processing for Freeze_Record_Type
4077 -- Deal with delayed aspect specifications for components. The
4078 -- analysis of the aspect is required to be delayed to the freeze
4079 -- point, thus we analyze the pragma or attribute definition
4080 -- clause in the tree at this point. We also analyze the aspect
4081 -- specification node at the freeze point when the aspect doesn't
4082 -- correspond to pragma/attribute definition clause.
4084 Comp
:= First_Entity
(Rec
);
4085 while Present
(Comp
) loop
4086 if Ekind
(Comp
) = E_Component
4087 and then Has_Delayed_Aspects
(Comp
)
4089 if not Rec_Pushed
then
4093 -- The visibility to the discriminants must be restored in
4094 -- order to properly analyze the aspects.
4096 if Has_Discriminants
(Rec
) then
4097 Install_Discriminants
(Rec
);
4101 Analyze_Aspects_At_Freeze_Point
(Comp
);
4107 -- Pop the scope if Rec scope has been pushed on the scope stack
4108 -- during the delayed aspect analysis process.
4111 if Has_Discriminants
(Rec
) then
4112 Uninstall_Discriminants
(Rec
);
4118 -- Freeze components and embedded subtypes
4120 Comp
:= First_Entity
(Rec
);
4122 while Present
(Comp
) loop
4123 if Is_Aliased
(Comp
) then
4124 Aliased_Component
:= True;
4127 -- Handle the component and discriminant case
4129 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
4131 CC
: constant Node_Id
:= Component_Clause
(Comp
);
4134 -- Freezing a record type freezes the type of each of its
4135 -- components. However, if the type of the component is
4136 -- part of this record, we do not want or need a separate
4137 -- Freeze_Node. Note that Is_Itype is wrong because that's
4138 -- also set in private type cases. We also can't check for
4139 -- the Scope being exactly Rec because of private types and
4140 -- record extensions.
4142 if Is_Itype
(Etype
(Comp
))
4143 and then Is_Record_Type
(Underlying_Type
4144 (Scope
(Etype
(Comp
))))
4146 Undelay_Type
(Etype
(Comp
));
4149 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
4151 -- Warn for pragma Pack overriding foreign convention
4153 if Has_Foreign_Convention
(Etype
(Comp
))
4154 and then Has_Pragma_Pack
(Rec
)
4156 -- Don't warn for aliased components, since override
4157 -- cannot happen in that case.
4159 and then not Is_Aliased
(Comp
)
4162 CN
: constant Name_Id
:=
4163 Get_Convention_Name
(Convention
(Etype
(Comp
)));
4164 PP
: constant Node_Id
:=
4165 Get_Pragma
(Rec
, Pragma_Pack
);
4167 if Present
(PP
) then
4168 Error_Msg_Name_1
:= CN
;
4169 Error_Msg_Sloc
:= Sloc
(Comp
);
4171 ("pragma Pack affects convention % component#??",
4173 Error_Msg_Name_1
:= CN
;
4175 ("\component & may not have % compatible "
4176 & "representation??", PP
, Comp
);
4181 -- Check for error of component clause given for variable
4182 -- sized type. We have to delay this test till this point,
4183 -- since the component type has to be frozen for us to know
4184 -- if it is variable length.
4186 if Present
(CC
) then
4187 Placed_Component
:= True;
4189 -- We omit this test in a generic context, it will be
4190 -- applied at instantiation time.
4192 if Inside_A_Generic
then
4195 -- Also omit this test in CodePeer mode, since we do not
4196 -- have sufficient info on size and rep clauses.
4198 elsif CodePeer_Mode
then
4201 -- Omit check if component has a generic type. This can
4202 -- happen in an instantiation within a generic in ASIS
4203 -- mode, where we force freeze actions without full
4206 elsif Is_Generic_Type
(Etype
(Comp
)) then
4212 Size_Known_At_Compile_Time
4213 (Underlying_Type
(Etype
(Comp
)))
4216 ("component clause not allowed for variable " &
4217 "length component", CC
);
4221 Unplaced_Component
:= True;
4224 -- Case of component requires byte alignment
4226 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
4228 -- Set the enclosing record to also require byte align
4230 Set_Must_Be_On_Byte_Boundary
(Rec
);
4232 -- Check for component clause that is inconsistent with
4233 -- the required byte boundary alignment.
4236 and then Normalized_First_Bit
(Comp
) mod
4237 System_Storage_Unit
/= 0
4240 ("component & must be byte aligned",
4241 Component_Name
(Component_Clause
(Comp
)));
4247 -- Gather data for possible Implicit_Packing later. Note that at
4248 -- this stage we might be dealing with a real component, or with
4249 -- an implicit subtype declaration.
4251 if Known_Static_RM_Size
(Etype
(Comp
)) then
4253 Comp_Type
: constant Entity_Id
:= Etype
(Comp
);
4254 Comp_Size
: constant Uint
:= RM_Size
(Comp_Type
);
4255 SSU
: constant Int
:= Ttypes
.System_Storage_Unit
;
4258 Sized_Component_Total_RM_Size
:=
4259 Sized_Component_Total_RM_Size
+ Comp_Size
;
4261 Sized_Component_Total_Round_RM_Size
:=
4262 Sized_Component_Total_Round_RM_Size
+
4263 (Comp_Size
+ SSU
- 1) / SSU
* SSU
;
4265 if Present
(Underlying_Type
(Comp_Type
))
4266 and then Is_Elementary_Type
(Underlying_Type
(Comp_Type
))
4268 Elem_Component_Total_Esize
:=
4269 Elem_Component_Total_Esize
+ Esize
(Comp_Type
);
4271 All_Elem_Components
:= False;
4273 if Comp_Size
mod SSU
/= 0 then
4274 All_Storage_Unit_Components
:= False;
4279 All_Sized_Components
:= False;
4282 -- If the component is an Itype with Delayed_Freeze and is either
4283 -- a record or array subtype and its base type has not yet been
4284 -- frozen, we must remove this from the entity list of this record
4285 -- and put it on the entity list of the scope of its base type.
4286 -- Note that we know that this is not the type of a component
4287 -- since we cleared Has_Delayed_Freeze for it in the previous
4288 -- loop. Thus this must be the Designated_Type of an access type,
4289 -- which is the type of a component.
4292 and then Is_Type
(Scope
(Comp
))
4293 and then Is_Composite_Type
(Comp
)
4294 and then Base_Type
(Comp
) /= Comp
4295 and then Has_Delayed_Freeze
(Comp
)
4296 and then not Is_Frozen
(Base_Type
(Comp
))
4299 Will_Be_Frozen
: Boolean := False;
4303 -- We have a difficult case to handle here. Suppose Rec is
4304 -- subtype being defined in a subprogram that's created as
4305 -- part of the freezing of Rec'Base. In that case, we know
4306 -- that Comp'Base must have already been frozen by the time
4307 -- we get to elaborate this because Gigi doesn't elaborate
4308 -- any bodies until it has elaborated all of the declarative
4309 -- part. But Is_Frozen will not be set at this point because
4310 -- we are processing code in lexical order.
4312 -- We detect this case by going up the Scope chain of Rec
4313 -- and seeing if we have a subprogram scope before reaching
4314 -- the top of the scope chain or that of Comp'Base. If we
4315 -- do, then mark that Comp'Base will actually be frozen. If
4316 -- so, we merely undelay it.
4319 while Present
(S
) loop
4320 if Is_Subprogram
(S
) then
4321 Will_Be_Frozen
:= True;
4323 elsif S
= Scope
(Base_Type
(Comp
)) then
4330 if Will_Be_Frozen
then
4331 Undelay_Type
(Comp
);
4334 if Present
(Prev
) then
4335 Link_Entities
(Prev
, Next_Entity
(Comp
));
4337 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
4340 -- Insert in entity list of scope of base type (which
4341 -- must be an enclosing scope, because still unfrozen).
4343 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
4347 -- If the component is an access type with an allocator as default
4348 -- value, the designated type will be frozen by the corresponding
4349 -- expression in init_proc. In order to place the freeze node for
4350 -- the designated type before that for the current record type,
4353 -- Same process if the component is an array of access types,
4354 -- initialized with an aggregate. If the designated type is
4355 -- private, it cannot contain allocators, and it is premature
4356 -- to freeze the type, so we check for this as well.
4358 elsif Is_Access_Type
(Etype
(Comp
))
4359 and then Present
(Parent
(Comp
))
4360 and then Present
(Expression
(Parent
(Comp
)))
4363 Alloc
: constant Node_Id
:=
4364 Check_Allocator
(Expression
(Parent
(Comp
)));
4367 if Present
(Alloc
) then
4369 -- If component is pointer to a class-wide type, freeze
4370 -- the specific type in the expression being allocated.
4371 -- The expression may be a subtype indication, in which
4372 -- case freeze the subtype mark.
4374 if Is_Class_Wide_Type
4375 (Designated_Type
(Etype
(Comp
)))
4377 if Is_Entity_Name
(Expression
(Alloc
)) then
4379 (Entity
(Expression
(Alloc
)), N
, Result
);
4381 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
4384 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
4388 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
4389 Check_Itype
(Etype
(Comp
));
4393 (Designated_Type
(Etype
(Comp
)), N
, Result
);
4398 elsif Is_Access_Type
(Etype
(Comp
))
4399 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
4401 Check_Itype
(Etype
(Comp
));
4403 -- Freeze the designated type when initializing a component with
4404 -- an aggregate in case the aggregate contains allocators.
4407 -- type T_Ptr is access all T;
4408 -- type T_Array is array ... of T_Ptr;
4410 -- type Rec is record
4411 -- Comp : T_Array := (others => ...);
4414 elsif Is_Array_Type
(Etype
(Comp
))
4415 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
4418 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
4419 Desig_Typ
: constant Entity_Id
:=
4421 (Component_Type
(Etype
(Comp
)));
4424 -- The only case when this sort of freezing is not done is
4425 -- when the designated type is class-wide and the root type
4426 -- is the record owning the component. This scenario results
4427 -- in a circularity because the class-wide type requires
4428 -- primitives that have not been created yet as the root
4429 -- type is in the process of being frozen.
4431 -- type Rec is tagged;
4432 -- type Rec_Ptr is access all Rec'Class;
4433 -- type Rec_Array is array ... of Rec_Ptr;
4435 -- type Rec is record
4436 -- Comp : Rec_Array := (others => ...);
4439 if Is_Class_Wide_Type
(Desig_Typ
)
4440 and then Root_Type
(Desig_Typ
) = Rec
4444 elsif Is_Fully_Defined
(Desig_Typ
)
4445 and then Present
(Comp_Par
)
4446 and then Nkind
(Comp_Par
) = N_Component_Declaration
4447 and then Present
(Expression
(Comp_Par
))
4448 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
4450 Freeze_And_Append
(Desig_Typ
, N
, Result
);
4460 Get_Attribute_Definition_Clause
4461 (Rec
, Attribute_Scalar_Storage_Order
);
4463 -- If the record type has Complex_Representation, then it is treated
4464 -- as a scalar in the back end so the storage order is irrelevant.
4466 if Has_Complex_Representation
(Rec
) then
4467 if Present
(SSO_ADC
) then
4469 ("??storage order has no effect with Complex_Representation",
4474 -- Deal with default setting of reverse storage order
4476 Set_SSO_From_Default
(Rec
);
4478 -- Check consistent attribute setting on component types
4481 Comp_ADC_Present
: Boolean;
4483 Comp
:= First_Component
(Rec
);
4484 while Present
(Comp
) loop
4485 Check_Component_Storage_Order
4489 Comp_ADC_Present
=> Comp_ADC_Present
);
4490 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
4491 Next_Component
(Comp
);
4495 -- Now deal with reverse storage order/bit order issues
4497 if Present
(SSO_ADC
) then
4499 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
4500 -- if the former is specified.
4502 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
4504 -- Note: report error on Rec, not on SSO_ADC, as ADC may
4505 -- apply to some ancestor type.
4507 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
4509 ("scalar storage order for& specified# inconsistent with "
4510 & "bit order", Rec
);
4513 -- Warn if there is a Scalar_Storage_Order attribute definition
4514 -- clause but no component clause, no component that itself has
4515 -- such an attribute definition, and no pragma Pack.
4517 if not (Placed_Component
4524 ("??scalar storage order specified but no component "
4525 & "clause", SSO_ADC
);
4530 -- Deal with Bit_Order aspect
4532 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
4534 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
4535 if not (Placed_Component
4536 or else Present
(SSO_ADC
)
4537 or else Is_Packed
(Rec
))
4539 -- Warn if clause has no effect when no component clause is
4540 -- present, but suppress warning if the Bit_Order is required
4541 -- due to the presence of a Scalar_Storage_Order attribute.
4544 ("??bit order specification has no effect", ADC
);
4546 ("\??since no component clauses were specified", ADC
);
4548 -- Here is where we do the processing to adjust component clauses
4549 -- for reversed bit order, when not using reverse SSO. If an error
4550 -- has been reported on Rec already (such as SSO incompatible with
4551 -- bit order), don't bother adjusting as this may generate extra
4554 elsif Reverse_Bit_Order
(Rec
)
4555 and then not Reverse_Storage_Order
(Rec
)
4556 and then not Error_Posted
(Rec
)
4558 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
4560 -- Case where we have both an explicit Bit_Order and the same
4561 -- Scalar_Storage_Order: leave record untouched, the back-end
4562 -- will take care of required layout conversions.
4570 -- Complete error checking on record representation clause (e.g.
4571 -- overlap of components). This is called after adjusting the
4572 -- record for reverse bit order.
4575 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
4577 if Present
(RRC
) then
4578 Check_Record_Representation_Clause
(RRC
);
4582 -- Check for useless pragma Pack when all components placed. We only
4583 -- do this check for record types, not subtypes, since a subtype may
4584 -- have all its components placed, and it still makes perfectly good
4585 -- sense to pack other subtypes or the parent type. We do not give
4586 -- this warning if Optimize_Alignment is set to Space, since the
4587 -- pragma Pack does have an effect in this case (it always resets
4588 -- the alignment to one).
4590 if Ekind
(Rec
) = E_Record_Type
4591 and then Is_Packed
(Rec
)
4592 and then not Unplaced_Component
4593 and then Optimize_Alignment
/= 'S'
4595 -- Reset packed status. Probably not necessary, but we do it so
4596 -- that there is no chance of the back end doing something strange
4597 -- with this redundant indication of packing.
4599 Set_Is_Packed
(Rec
, False);
4601 -- Give warning if redundant constructs warnings on
4603 if Warn_On_Redundant_Constructs
then
4604 Error_Msg_N
-- CODEFIX
4605 ("??pragma Pack has no effect, no unplaced components",
4606 Get_Rep_Pragma
(Rec
, Name_Pack
));
4610 -- If this is the record corresponding to a remote type, freeze the
4611 -- remote type here since that is what we are semantically freezing.
4612 -- This prevents the freeze node for that type in an inner scope.
4614 if Ekind
(Rec
) = E_Record_Type
then
4615 if Present
(Corresponding_Remote_Type
(Rec
)) then
4616 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
4619 -- Check for controlled components, unchecked unions, and type
4622 Comp
:= First_Component
(Rec
);
4623 while Present
(Comp
) loop
4625 -- Do not set Has_Controlled_Component on a class-wide
4626 -- equivalent type. See Make_CW_Equivalent_Type.
4628 if not Is_Class_Wide_Equivalent_Type
(Rec
)
4630 (Has_Controlled_Component
(Etype
(Comp
))
4632 (Chars
(Comp
) /= Name_uParent
4633 and then Is_Controlled
(Etype
(Comp
)))
4635 (Is_Protected_Type
(Etype
(Comp
))
4637 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
4639 Has_Controlled_Component
4640 (Corresponding_Record_Type
(Etype
(Comp
)))))
4642 Set_Has_Controlled_Component
(Rec
);
4645 if Has_Unchecked_Union
(Etype
(Comp
)) then
4646 Set_Has_Unchecked_Union
(Rec
);
4649 -- The record type requires its own invariant procedure in
4650 -- order to verify the invariant of each individual component.
4651 -- Do not consider internal components such as _parent because
4652 -- parent class-wide invariants are always inherited.
4653 -- In GNATprove mode, the component invariants are checked by
4654 -- other means. They should not be added to the record type
4655 -- invariant procedure, so that the procedure can be used to
4656 -- check the recordy type invariants if any.
4658 if Comes_From_Source
(Comp
)
4659 and then Has_Invariants
(Etype
(Comp
))
4660 and then not GNATprove_Mode
4662 Set_Has_Own_Invariants
(Rec
);
4665 -- Scan component declaration for likely misuses of current
4666 -- instance, either in a constraint or a default expression.
4668 if Has_Per_Object_Constraint
(Comp
) then
4669 Check_Current_Instance
(Parent
(Comp
));
4672 Next_Component
(Comp
);
4676 -- Enforce the restriction that access attributes with a current
4677 -- instance prefix can only apply to limited types. This comment
4678 -- is floating here, but does not seem to belong here???
4680 -- Set component alignment if not otherwise already set
4682 Set_Component_Alignment_If_Not_Set
(Rec
);
4684 -- For first subtypes, check if there are any fixed-point fields with
4685 -- component clauses, where we must check the size. This is not done
4686 -- till the freeze point since for fixed-point types, we do not know
4687 -- the size until the type is frozen. Similar processing applies to
4688 -- bit-packed arrays.
4690 if Is_First_Subtype
(Rec
) then
4691 Comp
:= First_Component
(Rec
);
4692 while Present
(Comp
) loop
4693 if Present
(Component_Clause
(Comp
))
4694 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
4695 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
4698 (Component_Name
(Component_Clause
(Comp
)),
4704 Next_Component
(Comp
);
4708 -- See if Size is too small as is (and implicit packing might help)
4710 if not Is_Packed
(Rec
)
4712 -- No implicit packing if even one component is explicitly placed
4714 and then not Placed_Component
4716 -- Or even one component is aliased
4718 and then not Aliased_Component
4720 -- Must have size clause and all sized components
4722 and then Has_Size_Clause
(Rec
)
4723 and then All_Sized_Components
4725 -- Do not try implicit packing on records with discriminants, too
4726 -- complicated, especially in the variant record case.
4728 and then not Has_Discriminants
(Rec
)
4730 -- We want to implicitly pack if the specified size of the record
4731 -- is less than the sum of the object sizes (no point in packing
4732 -- if this is not the case), if we can compute it, i.e. if we have
4733 -- only elementary components. Otherwise, we have at least one
4734 -- composite component and we want to implicitly pack only if bit
4735 -- packing is required for it, as we are sure in this case that
4736 -- the back end cannot do the expected layout without packing.
4739 ((All_Elem_Components
4740 and then RM_Size
(Rec
) < Elem_Component_Total_Esize
)
4742 (not All_Elem_Components
4743 and then not All_Storage_Unit_Components
4744 and then RM_Size
(Rec
) < Sized_Component_Total_Round_RM_Size
))
4746 -- And the total RM size cannot be greater than the specified size
4747 -- since otherwise packing will not get us where we have to be.
4749 and then Sized_Component_Total_RM_Size
<= RM_Size
(Rec
)
4751 -- Never do implicit packing in CodePeer or SPARK modes since
4752 -- we don't do any packing in these modes, since this generates
4753 -- over-complex code that confuses static analysis, and in
4754 -- general, neither CodePeer not GNATprove care about the
4755 -- internal representation of objects.
4757 and then not (CodePeer_Mode
or GNATprove_Mode
)
4759 -- If implicit packing enabled, do it
4761 if Implicit_Packing
then
4762 Set_Is_Packed
(Rec
);
4764 -- Otherwise flag the size clause
4768 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
4770 Error_Msg_NE
-- CODEFIX
4771 ("size given for& too small", Sz
, Rec
);
4772 Error_Msg_N
-- CODEFIX
4773 ("\use explicit pragma Pack "
4774 & "or use pragma Implicit_Packing", Sz
);
4779 -- The following checks are relevant only when SPARK_Mode is on as
4780 -- they are not standard Ada legality rules.
4782 if SPARK_Mode
= On
then
4784 -- A discriminated type cannot be effectively volatile
4785 -- (SPARK RM 7.1.3(5)).
4787 if Is_Effectively_Volatile
(Rec
) then
4788 if Has_Discriminants
(Rec
) then
4789 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
4792 -- A non-effectively volatile record type cannot contain
4793 -- effectively volatile components (SPARK RM 7.1.3(6)).
4796 Comp
:= First_Component
(Rec
);
4797 while Present
(Comp
) loop
4798 if Comes_From_Source
(Comp
)
4799 and then Is_Effectively_Volatile
(Etype
(Comp
))
4801 Error_Msg_Name_1
:= Chars
(Rec
);
4803 ("component & of non-volatile type % cannot be "
4804 & "volatile", Comp
);
4807 Next_Component
(Comp
);
4811 -- A type which does not yield a synchronized object cannot have
4812 -- a component that yields a synchronized object (SPARK RM 9.5).
4814 if not Yields_Synchronized_Object
(Rec
) then
4815 Comp
:= First_Component
(Rec
);
4816 while Present
(Comp
) loop
4817 if Comes_From_Source
(Comp
)
4818 and then Yields_Synchronized_Object
(Etype
(Comp
))
4820 Error_Msg_Name_1
:= Chars
(Rec
);
4822 ("component & of non-synchronized type % cannot be "
4823 & "synchronized", Comp
);
4826 Next_Component
(Comp
);
4830 -- A Ghost type cannot have a component of protected or task type
4831 -- (SPARK RM 6.9(19)).
4833 if Is_Ghost_Entity
(Rec
) then
4834 Comp
:= First_Component
(Rec
);
4835 while Present
(Comp
) loop
4836 if Comes_From_Source
(Comp
)
4837 and then Is_Concurrent_Type
(Etype
(Comp
))
4839 Error_Msg_Name_1
:= Chars
(Rec
);
4841 ("component & of ghost type % cannot be concurrent",
4845 Next_Component
(Comp
);
4850 -- Make sure that if we have an iterator aspect, then we have
4851 -- either Constant_Indexing or Variable_Indexing.
4854 Iterator_Aspect
: Node_Id
;
4857 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
4859 if No
(Iterator_Aspect
) then
4860 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
4863 if Present
(Iterator_Aspect
) then
4864 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
4866 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
4871 ("Iterator_Element requires indexing aspect",
4877 -- All done if not a full record definition
4879 if Ekind
(Rec
) /= E_Record_Type
then
4883 -- Finally we need to check the variant part to make sure that
4884 -- all types within choices are properly frozen as part of the
4885 -- freezing of the record type.
4887 Check_Variant_Part
: declare
4888 D
: constant Node_Id
:= Declaration_Node
(Rec
);
4893 -- Find component list
4897 if Nkind
(D
) = N_Full_Type_Declaration
then
4898 T
:= Type_Definition
(D
);
4900 if Nkind
(T
) = N_Record_Definition
then
4901 C
:= Component_List
(T
);
4903 elsif Nkind
(T
) = N_Derived_Type_Definition
4904 and then Present
(Record_Extension_Part
(T
))
4906 C
:= Component_List
(Record_Extension_Part
(T
));
4910 -- Case of variant part present
4912 if Present
(C
) and then Present
(Variant_Part
(C
)) then
4913 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
4916 -- Note: we used to call Check_Choices here, but it is too early,
4917 -- since predicated subtypes are frozen here, but their freezing
4918 -- actions are in Analyze_Freeze_Entity, which has not been called
4919 -- yet for entities frozen within this procedure, so we moved that
4920 -- call to the Analyze_Freeze_Entity for the record type.
4922 end Check_Variant_Part
;
4924 -- Check that all the primitives of an interface type are abstract
4925 -- or null procedures.
4927 if Is_Interface
(Rec
)
4928 and then not Error_Posted
(Parent
(Rec
))
4935 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
4936 while Present
(Elmt
) loop
4937 Subp
:= Node
(Elmt
);
4939 if not Is_Abstract_Subprogram
(Subp
)
4941 -- Avoid reporting the error on inherited primitives
4943 and then Comes_From_Source
(Subp
)
4945 Error_Msg_Name_1
:= Chars
(Subp
);
4947 if Ekind
(Subp
) = E_Procedure
then
4948 if not Null_Present
(Parent
(Subp
)) then
4950 ("interface procedure % must be abstract or null",
4955 ("interface function % must be abstract",
4965 -- For a derived tagged type, check whether inherited primitives
4966 -- might require a wrapper to handle class-wide conditions.
4968 if Is_Tagged_Type
(Rec
) and then Is_Derived_Type
(Rec
) then
4969 Check_Inherited_Conditions
(Rec
);
4971 end Freeze_Record_Type
;
4973 -------------------------------
4974 -- Has_Boolean_Aspect_Import --
4975 -------------------------------
4977 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
4978 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4983 if Has_Aspects
(Decl
) then
4984 Asp
:= First
(Aspect_Specifications
(Decl
));
4985 while Present
(Asp
) loop
4986 Expr
:= Expression
(Asp
);
4988 -- The value of aspect Import is True when the expression is
4989 -- either missing or it is explicitly set to True.
4991 if Get_Aspect_Id
(Asp
) = Aspect_Import
4993 or else (Compile_Time_Known_Value
(Expr
)
4994 and then Is_True
(Expr_Value
(Expr
))))
5004 end Has_Boolean_Aspect_Import
;
5006 -------------------------
5007 -- Inherit_Freeze_Node --
5008 -------------------------
5010 procedure Inherit_Freeze_Node
5014 Typ_Fnod
: constant Node_Id
:= Freeze_Node
(Typ
);
5017 Set_Freeze_Node
(Typ
, Fnod
);
5018 Set_Entity
(Fnod
, Typ
);
5020 -- The input type had an existing node. Propagate relevant attributes
5021 -- from the old freeze node to the inherited freeze node.
5023 -- ??? if both freeze nodes have attributes, would they differ?
5025 if Present
(Typ_Fnod
) then
5027 -- Attribute Access_Types_To_Process
5029 if Present
(Access_Types_To_Process
(Typ_Fnod
))
5030 and then No
(Access_Types_To_Process
(Fnod
))
5032 Set_Access_Types_To_Process
(Fnod
,
5033 Access_Types_To_Process
(Typ_Fnod
));
5036 -- Attribute Actions
5038 if Present
(Actions
(Typ_Fnod
)) and then No
(Actions
(Fnod
)) then
5039 Set_Actions
(Fnod
, Actions
(Typ_Fnod
));
5042 -- Attribute First_Subtype_Link
5044 if Present
(First_Subtype_Link
(Typ_Fnod
))
5045 and then No
(First_Subtype_Link
(Fnod
))
5047 Set_First_Subtype_Link
(Fnod
, First_Subtype_Link
(Typ_Fnod
));
5050 -- Attribute TSS_Elist
5052 if Present
(TSS_Elist
(Typ_Fnod
))
5053 and then No
(TSS_Elist
(Fnod
))
5055 Set_TSS_Elist
(Fnod
, TSS_Elist
(Typ_Fnod
));
5058 end Inherit_Freeze_Node
;
5060 ------------------------------
5061 -- Wrap_Imported_Subprogram --
5062 ------------------------------
5064 -- The issue here is that our normal approach of checking preconditions
5065 -- and postconditions does not work for imported procedures, since we
5066 -- are not generating code for the body. To get around this we create
5067 -- a wrapper, as shown by the following example:
5069 -- procedure K (A : Integer);
5070 -- pragma Import (C, K);
5072 -- The spec is rewritten by removing the effects of pragma Import, but
5073 -- leaving the convention unchanged, as though the source had said:
5075 -- procedure K (A : Integer);
5076 -- pragma Convention (C, K);
5078 -- and we create a body, added to the entity K freeze actions, which
5081 -- procedure K (A : Integer) is
5082 -- procedure K (A : Integer);
5083 -- pragma Import (C, K);
5088 -- Now the contract applies in the normal way to the outer procedure,
5089 -- and the inner procedure has no contracts, so there is no problem
5090 -- in just calling it to get the original effect.
5092 -- In the case of a function, we create an appropriate return statement
5093 -- for the subprogram body that calls the inner procedure.
5095 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
5096 function Copy_Import_Pragma
return Node_Id
;
5097 -- Obtain a copy of the Import_Pragma which belongs to subprogram E
5099 ------------------------
5100 -- Copy_Import_Pragma --
5101 ------------------------
5103 function Copy_Import_Pragma
return Node_Id
is
5105 -- The subprogram should have an import pragma, otherwise it does
5108 Prag
: constant Node_Id
:= Import_Pragma
(E
);
5109 pragma Assert
(Present
(Prag
));
5111 -- Save all semantic fields of the pragma
5113 Save_Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
5114 Save_From
: constant Boolean := From_Aspect_Specification
(Prag
);
5115 Save_Prag
: constant Node_Id
:= Next_Pragma
(Prag
);
5116 Save_Rep
: constant Node_Id
:= Next_Rep_Item
(Prag
);
5121 -- Reset all semantic fields. This avoids a potential infinite
5122 -- loop when the pragma comes from an aspect as the duplication
5123 -- will copy the aspect, then copy the corresponding pragma and
5126 Set_Corresponding_Aspect
(Prag
, Empty
);
5127 Set_From_Aspect_Specification
(Prag
, False);
5128 Set_Next_Pragma
(Prag
, Empty
);
5129 Set_Next_Rep_Item
(Prag
, Empty
);
5131 Result
:= Copy_Separate_Tree
(Prag
);
5133 -- Restore the original semantic fields
5135 Set_Corresponding_Aspect
(Prag
, Save_Asp
);
5136 Set_From_Aspect_Specification
(Prag
, Save_From
);
5137 Set_Next_Pragma
(Prag
, Save_Prag
);
5138 Set_Next_Rep_Item
(Prag
, Save_Rep
);
5141 end Copy_Import_Pragma
;
5145 Loc
: constant Source_Ptr
:= Sloc
(E
);
5146 CE
: constant Name_Id
:= Chars
(E
);
5154 -- Start of processing for Wrap_Imported_Subprogram
5157 -- Nothing to do if not imported
5159 if not Is_Imported
(E
) then
5162 -- Test enabling conditions for wrapping
5164 elsif Is_Subprogram
(E
)
5165 and then Present
(Contract
(E
))
5166 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
5167 and then not GNATprove_Mode
5169 -- Here we do the wrap
5171 -- Note on calls to Copy_Separate_Tree. The trees we are copying
5172 -- here are fully analyzed, but we definitely want fully syntactic
5173 -- unanalyzed trees in the body we construct, so that the analysis
5174 -- generates the right visibility, and that is exactly what the
5175 -- calls to Copy_Separate_Tree give us.
5177 Prag
:= Copy_Import_Pragma
;
5179 -- Fix up spec so it is no longer imported and has convention Ada
5181 Set_Has_Completion
(E
, False);
5182 Set_Import_Pragma
(E
, Empty
);
5183 Set_Interface_Name
(E
, Empty
);
5184 Set_Is_Imported
(E
, False);
5185 Set_Convention
(E
, Convention_Ada
);
5187 -- Grab the subprogram declaration and specification
5189 Spec
:= Declaration_Node
(E
);
5191 -- Build parameter list that we need
5194 Forml
:= First_Formal
(E
);
5195 while Present
(Forml
) loop
5196 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
5197 Next_Formal
(Forml
);
5202 -- An imported function whose result type is anonymous access
5203 -- creates a new anonymous access type when it is relocated into
5204 -- the declarations of the body generated below. As a result, the
5205 -- accessibility level of these two anonymous access types may not
5206 -- be compatible even though they are essentially the same type.
5207 -- Use an unchecked type conversion to reconcile this case. Note
5208 -- that the conversion is safe because in the named access type
5209 -- case, both the body and imported function utilize the same
5212 if Ekind_In
(E
, E_Function
, E_Generic_Function
) then
5214 Make_Simple_Return_Statement
(Loc
,
5216 Unchecked_Convert_To
(Etype
(E
),
5217 Make_Function_Call
(Loc
,
5218 Name
=> Make_Identifier
(Loc
, CE
),
5219 Parameter_Associations
=> Parms
)));
5223 Make_Procedure_Call_Statement
(Loc
,
5224 Name
=> Make_Identifier
(Loc
, CE
),
5225 Parameter_Associations
=> Parms
);
5228 -- Now build the body
5231 Make_Subprogram_Body
(Loc
,
5233 Copy_Separate_Tree
(Spec
),
5234 Declarations
=> New_List
(
5235 Make_Subprogram_Declaration
(Loc
,
5236 Specification
=> Copy_Separate_Tree
(Spec
)),
5238 Handled_Statement_Sequence
=>
5239 Make_Handled_Sequence_Of_Statements
(Loc
,
5240 Statements
=> New_List
(Stmt
),
5241 End_Label
=> Make_Identifier
(Loc
, CE
)));
5243 -- Append the body to freeze result
5245 Add_To_Result
(Bod
);
5248 -- Case of imported subprogram that does not get wrapped
5251 -- Set Is_Public. All imported entities need an external symbol
5252 -- created for them since they are always referenced from another
5253 -- object file. Note this used to be set when we set Is_Imported
5254 -- back in Sem_Prag, but now we delay it to this point, since we
5255 -- don't want to set this flag if we wrap an imported subprogram.
5259 end Wrap_Imported_Subprogram
;
5261 -- Start of processing for Freeze_Entity
5264 -- The entity being frozen may be subject to pragma Ghost. Set the mode
5265 -- now to ensure that any nodes generated during freezing are properly
5266 -- flagged as Ghost.
5270 -- We are going to test for various reasons why this entity need not be
5271 -- frozen here, but in the case of an Itype that's defined within a
5272 -- record, that test actually applies to the record.
5274 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
5275 Test_E
:= Scope
(E
);
5276 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
5277 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
5279 Test_E
:= Underlying_Type
(Scope
(E
));
5282 -- Do not freeze if already frozen since we only need one freeze node
5284 if Is_Frozen
(E
) then
5288 -- Do not freeze if we are preanalyzing without freezing
5290 elsif Inside_Preanalysis_Without_Freezing
> 0 then
5294 elsif Ekind
(E
) = E_Generic_Package
then
5295 Result
:= Freeze_Generic_Entities
(E
);
5298 -- It is improper to freeze an external entity within a generic because
5299 -- its freeze node will appear in a non-valid context. The entity will
5300 -- be frozen in the proper scope after the current generic is analyzed.
5301 -- However, aspects must be analyzed because they may be queried later
5302 -- within the generic itself, and the corresponding pragma or attribute
5303 -- definition has not been analyzed yet. After this, indicate that the
5304 -- entity has no further delayed aspects, to prevent a later aspect
5305 -- analysis out of the scope of the generic.
5307 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
5308 if Has_Delayed_Aspects
(E
) then
5309 Analyze_Aspects_At_Freeze_Point
(E
);
5310 Set_Has_Delayed_Aspects
(E
, False);
5316 -- AI05-0213: A formal incomplete type does not freeze the actual. In
5317 -- the instance, the same applies to the subtype renaming the actual.
5319 elsif Is_Private_Type
(E
)
5320 and then Is_Generic_Actual_Type
(E
)
5321 and then No
(Full_View
(Base_Type
(E
)))
5322 and then Ada_Version
>= Ada_2012
5327 -- Formal subprograms are never frozen
5329 elsif Is_Formal_Subprogram
(E
) then
5333 -- Generic types are never frozen as they lack delayed semantic checks
5335 elsif Is_Generic_Type
(E
) then
5339 -- Do not freeze a global entity within an inner scope created during
5340 -- expansion. A call to subprogram E within some internal procedure
5341 -- (a stream attribute for example) might require freezing E, but the
5342 -- freeze node must appear in the same declarative part as E itself.
5343 -- The two-pass elaboration mechanism in gigi guarantees that E will
5344 -- be frozen before the inner call is elaborated. We exclude constants
5345 -- from this test, because deferred constants may be frozen early, and
5346 -- must be diagnosed (e.g. in the case of a deferred constant being used
5347 -- in a default expression). If the enclosing subprogram comes from
5348 -- source, or is a generic instance, then the freeze point is the one
5349 -- mandated by the language, and we freeze the entity. A subprogram that
5350 -- is a child unit body that acts as a spec does not have a spec that
5351 -- comes from source, but can only come from source.
5353 elsif In_Open_Scopes
(Scope
(Test_E
))
5354 and then Scope
(Test_E
) /= Current_Scope
5355 and then Ekind
(Test_E
) /= E_Constant
5362 while Present
(S
) loop
5363 if Is_Overloadable
(S
) then
5364 if Comes_From_Source
(S
)
5365 or else Is_Generic_Instance
(S
)
5366 or else Is_Child_Unit
(S
)
5379 -- Similarly, an inlined instance body may make reference to global
5380 -- entities, but these references cannot be the proper freezing point
5381 -- for them, and in the absence of inlining freezing will take place in
5382 -- their own scope. Normally instance bodies are analyzed after the
5383 -- enclosing compilation, and everything has been frozen at the proper
5384 -- place, but with front-end inlining an instance body is compiled
5385 -- before the end of the enclosing scope, and as a result out-of-order
5386 -- freezing must be prevented.
5388 elsif Front_End_Inlining
5389 and then In_Instance_Body
5390 and then Present
(Scope
(Test_E
))
5396 S
:= Scope
(Test_E
);
5397 while Present
(S
) loop
5398 if Is_Generic_Instance
(S
) then
5412 -- Add checks to detect proper initialization of scalars that may appear
5413 -- as subprogram parameters.
5415 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
5416 Apply_Parameter_Validity_Checks
(E
);
5419 -- Deal with delayed aspect specifications. The analysis of the aspect
5420 -- is required to be delayed to the freeze point, thus we analyze the
5421 -- pragma or attribute definition clause in the tree at this point. We
5422 -- also analyze the aspect specification node at the freeze point when
5423 -- the aspect doesn't correspond to pragma/attribute definition clause.
5424 -- In addition, a derived type may have inherited aspects that were
5425 -- delayed in the parent, so these must also be captured now.
5427 if Has_Delayed_Aspects
(E
)
5428 or else May_Inherit_Delayed_Rep_Aspects
(E
)
5430 Analyze_Aspects_At_Freeze_Point
(E
);
5433 -- Here to freeze the entity
5437 -- Case of entity being frozen is other than a type
5439 if not Is_Type
(E
) then
5441 -- If entity is exported or imported and does not have an external
5442 -- name, now is the time to provide the appropriate default name.
5443 -- Skip this if the entity is stubbed, since we don't need a name
5444 -- for any stubbed routine. For the case on intrinsics, if no
5445 -- external name is specified, then calls will be handled in
5446 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
5447 -- external name is provided, then Expand_Intrinsic_Call leaves
5448 -- calls in place for expansion by GIGI.
5450 if (Is_Imported
(E
) or else Is_Exported
(E
))
5451 and then No
(Interface_Name
(E
))
5452 and then Convention
(E
) /= Convention_Stubbed
5453 and then Convention
(E
) /= Convention_Intrinsic
5455 Set_Encoded_Interface_Name
5456 (E
, Get_Default_External_Name
(E
));
5458 -- If entity is an atomic object appearing in a declaration and
5459 -- the expression is an aggregate, assign it to a temporary to
5460 -- ensure that the actual assignment is done atomically rather
5461 -- than component-wise (the assignment to the temp may be done
5462 -- component-wise, but that is harmless).
5464 elsif Is_Atomic_Or_VFA
(E
)
5465 and then Nkind
(Parent
(E
)) = N_Object_Declaration
5466 and then Present
(Expression
(Parent
(E
)))
5467 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
5468 and then Is_Atomic_VFA_Aggregate
(Expression
(Parent
(E
)))
5475 if Is_Subprogram
(E
) then
5477 -- Check for needing to wrap imported subprogram
5479 Wrap_Imported_Subprogram
(E
);
5481 -- Freeze all parameter types and the return type (RM 13.14(14)).
5482 -- However skip this for internal subprograms. This is also where
5483 -- any extra formal parameters are created since we now know
5484 -- whether the subprogram will use a foreign convention.
5486 -- In Ada 2012, freezing a subprogram does not always freeze the
5487 -- corresponding profile (see AI05-019). An attribute reference
5488 -- is not a freezing point of the profile. Flag Do_Freeze_Profile
5489 -- indicates whether the profile should be frozen now.
5490 -- Other constructs that should not freeze ???
5492 -- This processing doesn't apply to internal entities (see below)
5494 if not Is_Internal
(E
) and then Do_Freeze_Profile
then
5495 if not Freeze_Profile
(E
) then
5500 -- Must freeze its parent first if it is a derived subprogram
5502 if Present
(Alias
(E
)) then
5503 Freeze_And_Append
(Alias
(E
), N
, Result
);
5506 -- We don't freeze internal subprograms, because we don't normally
5507 -- want addition of extra formals or mechanism setting to happen
5508 -- for those. However we do pass through predefined dispatching
5509 -- cases, since extra formals may be needed in some cases, such as
5510 -- for the stream 'Input function (build-in-place formals).
5512 if not Is_Internal
(E
)
5513 or else Is_Predefined_Dispatching_Operation
(E
)
5515 Freeze_Subprogram
(E
);
5518 -- If warning on suspicious contracts then check for the case of
5519 -- a postcondition other than False for a No_Return subprogram.
5522 and then Warn_On_Suspicious_Contract
5523 and then Present
(Contract
(E
))
5526 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
5530 while Present
(Prag
) loop
5531 if Nam_In
(Pragma_Name_Unmapped
(Prag
),
5538 (First
(Pragma_Argument_Associations
(Prag
)));
5540 if Nkind
(Exp
) /= N_Identifier
5541 or else Chars
(Exp
) /= Name_False
5544 ("useless postcondition, & is marked "
5545 & "No_Return?T?", Exp
, E
);
5549 Prag
:= Next_Pragma
(Prag
);
5554 -- Here for other than a subprogram or type
5557 -- If entity has a type, and it is not a generic unit, then
5558 -- freeze it first (RM 13.14(10)).
5560 if Present
(Etype
(E
))
5561 and then Ekind
(E
) /= E_Generic_Function
5563 Freeze_And_Append
(Etype
(E
), N
, Result
);
5565 -- For an object of an anonymous array type, aspects on the
5566 -- object declaration apply to the type itself. This is the
5567 -- case for Atomic_Components, Volatile_Components, and
5568 -- Independent_Components. In these cases analysis of the
5569 -- generated pragma will mark the anonymous types accordingly,
5570 -- and the object itself does not require a freeze node.
5572 if Ekind
(E
) = E_Variable
5573 and then Is_Itype
(Etype
(E
))
5574 and then Is_Array_Type
(Etype
(E
))
5575 and then Has_Delayed_Aspects
(E
)
5577 Set_Has_Delayed_Aspects
(E
, False);
5578 Set_Has_Delayed_Freeze
(E
, False);
5579 Set_Freeze_Node
(E
, Empty
);
5583 -- Special processing for objects created by object declaration
5585 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
5586 Freeze_Object_Declaration
(E
);
5589 -- Check that a constant which has a pragma Volatile[_Components]
5590 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
5592 -- Note: Atomic[_Components] also sets Volatile[_Components]
5594 if Ekind
(E
) = E_Constant
5595 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
5596 and then not Is_Imported
(E
)
5597 and then not Has_Boolean_Aspect_Import
(E
)
5599 -- Make sure we actually have a pragma, and have not merely
5600 -- inherited the indication from elsewhere (e.g. an address
5601 -- clause, which is not good enough in RM terms).
5603 if Has_Rep_Pragma
(E
, Name_Atomic
)
5605 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
5608 ("stand alone atomic constant must be " &
5609 "imported (RM C.6(13))", E
);
5611 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
5613 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
5616 ("stand alone volatile constant must be " &
5617 "imported (RM C.6(13))", E
);
5621 -- Static objects require special handling
5623 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
5624 and then Is_Statically_Allocated
(E
)
5626 Freeze_Static_Object
(E
);
5629 -- Remaining step is to layout objects
5631 if Ekind_In
(E
, E_Variable
, E_Constant
, E_Loop_Parameter
)
5632 or else Is_Formal
(E
)
5637 -- For an object that does not have delayed freezing, and whose
5638 -- initialization actions have been captured in a compound
5639 -- statement, move them back now directly within the enclosing
5640 -- statement sequence.
5642 if Ekind_In
(E
, E_Constant
, E_Variable
)
5643 and then not Has_Delayed_Freeze
(E
)
5645 Explode_Initialization_Compound_Statement
(E
);
5648 -- Do not generate a freeze node for a generic unit
5650 if Is_Generic_Unit
(E
) then
5656 -- Case of a type or subtype being frozen
5659 -- Verify several SPARK legality rules related to Ghost types now
5660 -- that the type is frozen.
5662 Check_Ghost_Type
(E
);
5664 -- We used to check here that a full type must have preelaborable
5665 -- initialization if it completes a private type specified with
5666 -- pragma Preelaborable_Initialization, but that missed cases where
5667 -- the types occur within a generic package, since the freezing
5668 -- that occurs within a containing scope generally skips traversal
5669 -- of a generic unit's declarations (those will be frozen within
5670 -- instances). This check was moved to Analyze_Package_Specification.
5672 -- The type may be defined in a generic unit. This can occur when
5673 -- freezing a generic function that returns the type (which is
5674 -- defined in a parent unit). It is clearly meaningless to freeze
5675 -- this type. However, if it is a subtype, its size may be determi-
5676 -- nable and used in subsequent checks, so might as well try to
5679 -- In Ada 2012, Freeze_Entities is also used in the front end to
5680 -- trigger the analysis of aspect expressions, so in this case we
5681 -- want to continue the freezing process.
5683 -- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead
5684 -- In_Generic_Scope (E)???
5686 if Present
(Scope
(E
))
5687 and then Is_Generic_Unit
(Scope
(E
))
5689 (not Has_Predicates
(E
)
5690 and then not Has_Delayed_Freeze
(E
))
5692 Check_Compile_Time_Size
(E
);
5697 -- Check for error of Type_Invariant'Class applied to an untagged
5698 -- type (check delayed to freeze time when full type is available).
5701 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
5704 and then Class_Present
(Prag
)
5705 and then not Is_Tagged_Type
(E
)
5708 ("Type_Invariant''Class cannot be specified for &", Prag
, E
);
5710 ("\can only be specified for a tagged type", Prag
);
5714 -- Deal with special cases of freezing for subtype
5716 if E
/= Base_Type
(E
) then
5718 -- Before we do anything else, a specific test for the case of a
5719 -- size given for an array where the array would need to be packed
5720 -- in order for the size to be honored, but is not. This is the
5721 -- case where implicit packing may apply. The reason we do this so
5722 -- early is that, if we have implicit packing, the layout of the
5723 -- base type is affected, so we must do this before we freeze the
5726 -- We could do this processing only if implicit packing is enabled
5727 -- since in all other cases, the error would be caught by the back
5728 -- end. However, we choose to do the check even if we do not have
5729 -- implicit packing enabled, since this allows us to give a more
5730 -- useful error message (advising use of pragma Implicit_Packing
5733 if Is_Array_Type
(E
) then
5735 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
5736 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
5737 SZ
: constant Node_Id
:= Size_Clause
(E
);
5738 Btyp
: constant Entity_Id
:= Base_Type
(E
);
5745 Num_Elmts
: Uint
:= Uint_1
;
5746 -- Number of elements in array
5749 -- Check enabling conditions. These are straightforward
5750 -- except for the test for a limited composite type. This
5751 -- eliminates the rare case of a array of limited components
5752 -- where there are issues of whether or not we can go ahead
5753 -- and pack the array (since we can't freely pack and unpack
5754 -- arrays if they are limited).
5756 -- Note that we check the root type explicitly because the
5757 -- whole point is we are doing this test before we have had
5758 -- a chance to freeze the base type (and it is that freeze
5759 -- action that causes stuff to be inherited).
5761 -- The conditions on the size are identical to those used in
5762 -- Freeze_Array_Type to set the Is_Packed flag.
5764 if Has_Size_Clause
(E
)
5765 and then Known_Static_RM_Size
(E
)
5766 and then not Is_Packed
(E
)
5767 and then not Has_Pragma_Pack
(E
)
5768 and then not Has_Component_Size_Clause
(E
)
5769 and then Known_Static_RM_Size
(Ctyp
)
5771 and then not (Addressable
(Rsiz
)
5772 and then Known_Static_Esize
(Ctyp
)
5773 and then Esize
(Ctyp
) = Rsiz
)
5774 and then not (Rsiz
mod System_Storage_Unit
= 0
5775 and then Is_Composite_Type
(Ctyp
))
5776 and then not Is_Limited_Composite
(E
)
5777 and then not Is_Packed
(Root_Type
(E
))
5778 and then not Has_Component_Size_Clause
(Root_Type
(E
))
5779 and then not (CodePeer_Mode
or GNATprove_Mode
)
5781 -- Compute number of elements in array
5783 Indx
:= First_Index
(E
);
5784 while Present
(Indx
) loop
5785 Get_Index_Bounds
(Indx
, Lo
, Hi
);
5787 if not (Compile_Time_Known_Value
(Lo
)
5789 Compile_Time_Known_Value
(Hi
))
5791 goto No_Implicit_Packing
;
5794 Dim
:= Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1;
5797 Num_Elmts
:= Num_Elmts
* Dim
;
5799 Num_Elmts
:= Uint_0
;
5805 -- What we are looking for here is the situation where
5806 -- the RM_Size given would be exactly right if there was
5807 -- a pragma Pack, resulting in the component size being
5808 -- the RM_Size of the component type.
5810 if RM_Size
(E
) = Num_Elmts
* Rsiz
then
5812 -- For implicit packing mode, just set the component
5813 -- size and Freeze_Array_Type will do the rest.
5815 if Implicit_Packing
then
5816 Set_Component_Size
(Btyp
, Rsiz
);
5818 -- Otherwise give an error message
5822 ("size given for& too small", SZ
, E
);
5823 Error_Msg_N
-- CODEFIX
5824 ("\use explicit pragma Pack or use pragma "
5825 & "Implicit_Packing", SZ
);
5832 <<No_Implicit_Packing
>>
5834 -- If ancestor subtype present, freeze that first. Note that this
5835 -- will also get the base type frozen. Need RM reference ???
5837 Atype
:= Ancestor_Subtype
(E
);
5839 if Present
(Atype
) then
5840 Freeze_And_Append
(Atype
, N
, Result
);
5842 -- No ancestor subtype present
5845 -- See if we have a nearest ancestor that has a predicate.
5846 -- That catches the case of derived type with a predicate.
5847 -- Need RM reference here ???
5849 Atype
:= Nearest_Ancestor
(E
);
5851 if Present
(Atype
) and then Has_Predicates
(Atype
) then
5852 Freeze_And_Append
(Atype
, N
, Result
);
5855 -- Freeze base type before freezing the entity (RM 13.14(15))
5857 if E
/= Base_Type
(E
) then
5858 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
5862 -- A subtype inherits all the type-related representation aspects
5863 -- from its parents (RM 13.1(8)).
5865 Inherit_Aspects_At_Freeze_Point
(E
);
5867 -- For a derived type, freeze its parent type first (RM 13.14(15))
5869 elsif Is_Derived_Type
(E
) then
5870 Freeze_And_Append
(Etype
(E
), N
, Result
);
5871 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
5873 -- A derived type inherits each type-related representation aspect
5874 -- of its parent type that was directly specified before the
5875 -- declaration of the derived type (RM 13.1(15)).
5877 Inherit_Aspects_At_Freeze_Point
(E
);
5880 -- Check for incompatible size and alignment for record type
5882 if Warn_On_Size_Alignment
5883 and then Is_Record_Type
(E
)
5884 and then Has_Size_Clause
(E
) and then Has_Alignment_Clause
(E
)
5886 -- If explicit Object_Size clause given assume that the programmer
5887 -- knows what he is doing, and expects the compiler behavior.
5889 and then not Has_Object_Size_Clause
(E
)
5891 -- Check for size not a multiple of alignment
5893 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
5896 SC
: constant Node_Id
:= Size_Clause
(E
);
5897 AC
: constant Node_Id
:= Alignment_Clause
(E
);
5899 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
5902 if Present
(SC
) and then Present
(AC
) then
5906 if Sloc
(SC
) > Sloc
(AC
) then
5909 ("?Z?size is not a multiple of alignment for &",
5911 Error_Msg_Sloc
:= Sloc
(AC
);
5912 Error_Msg_Uint_1
:= Alignment
(E
);
5913 Error_Msg_N
("\?Z?alignment of ^ specified #", Loc
);
5918 ("?Z?size is not a multiple of alignment for &",
5920 Error_Msg_Sloc
:= Sloc
(SC
);
5921 Error_Msg_Uint_1
:= RM_Size
(E
);
5922 Error_Msg_N
("\?Z?size of ^ specified #", Loc
);
5925 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
5926 Error_Msg_N
("\?Z?Object_Size will be increased to ^", Loc
);
5933 if Is_Array_Type
(E
) then
5934 Freeze_Array_Type
(E
);
5936 -- For a class-wide type, the corresponding specific type is
5937 -- frozen as well (RM 13.14(15))
5939 elsif Is_Class_Wide_Type
(E
) then
5940 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
5942 -- If the base type of the class-wide type is still incomplete,
5943 -- the class-wide remains unfrozen as well. This is legal when
5944 -- E is the formal of a primitive operation of some other type
5945 -- which is being frozen.
5947 if not Is_Frozen
(Root_Type
(E
)) then
5948 Set_Is_Frozen
(E
, False);
5952 -- The equivalent type associated with a class-wide subtype needs
5953 -- to be frozen to ensure that its layout is done.
5955 if Ekind
(E
) = E_Class_Wide_Subtype
5956 and then Present
(Equivalent_Type
(E
))
5958 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5961 -- Generate an itype reference for a library-level class-wide type
5962 -- at the freeze point. Otherwise the first explicit reference to
5963 -- the type may appear in an inner scope which will be rejected by
5967 and then Is_Compilation_Unit
(Scope
(E
))
5970 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
5975 -- From a gigi point of view, a class-wide subtype derives
5976 -- from its record equivalent type. As a result, the itype
5977 -- reference must appear after the freeze node of the
5978 -- equivalent type or gigi will reject the reference.
5980 if Ekind
(E
) = E_Class_Wide_Subtype
5981 and then Present
(Equivalent_Type
(E
))
5983 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
5985 Add_To_Result
(Ref
);
5990 -- For a record type or record subtype, freeze all component types
5991 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
5992 -- using Is_Record_Type, because we don't want to attempt the freeze
5993 -- for the case of a private type with record extension (we will do
5994 -- that later when the full type is frozen).
5996 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
) then
5997 if not In_Generic_Scope
(E
) then
5998 Freeze_Record_Type
(E
);
6001 -- Report a warning if a discriminated record base type has a
6002 -- convention with language C or C++ applied to it. This check is
6003 -- done even within generic scopes (but not in instantiations),
6004 -- which is why we don't do it as part of Freeze_Record_Type.
6006 Check_Suspicious_Convention
(E
);
6008 -- For a concurrent type, freeze corresponding record type. This does
6009 -- not correspond to any specific rule in the RM, but the record type
6010 -- is essentially part of the concurrent type. Also freeze all local
6011 -- entities. This includes record types created for entry parameter
6012 -- blocks and whatever local entities may appear in the private part.
6014 elsif Is_Concurrent_Type
(E
) then
6015 if Present
(Corresponding_Record_Type
(E
)) then
6016 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
6019 Comp
:= First_Entity
(E
);
6020 while Present
(Comp
) loop
6021 if Is_Type
(Comp
) then
6022 Freeze_And_Append
(Comp
, N
, Result
);
6024 elsif (Ekind
(Comp
)) /= E_Function
then
6026 -- The guard on the presence of the Etype seems to be needed
6027 -- for some CodePeer (-gnatcC) cases, but not clear why???
6029 if Present
(Etype
(Comp
)) then
6030 if Is_Itype
(Etype
(Comp
))
6031 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
6033 Undelay_Type
(Etype
(Comp
));
6036 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
6043 -- Private types are required to point to the same freeze node as
6044 -- their corresponding full views. The freeze node itself has to
6045 -- point to the partial view of the entity (because from the partial
6046 -- view, we can retrieve the full view, but not the reverse).
6047 -- However, in order to freeze correctly, we need to freeze the full
6048 -- view. If we are freezing at the end of a scope (or within the
6049 -- scope) of the private type, the partial and full views will have
6050 -- been swapped, the full view appears first in the entity chain and
6051 -- the swapping mechanism ensures that the pointers are properly set
6054 -- If we encounter the partial view before the full view (e.g. when
6055 -- freezing from another scope), we freeze the full view, and then
6056 -- set the pointers appropriately since we cannot rely on swapping to
6057 -- fix things up (subtypes in an outer scope might not get swapped).
6059 -- If the full view is itself private, the above requirements apply
6060 -- to the underlying full view instead of the full view. But there is
6061 -- no swapping mechanism for the underlying full view so we need to
6062 -- set the pointers appropriately in both cases.
6064 elsif Is_Incomplete_Or_Private_Type
(E
)
6065 and then not Is_Generic_Type
(E
)
6067 -- The construction of the dispatch table associated with library
6068 -- level tagged types forces freezing of all the primitives of the
6069 -- type, which may cause premature freezing of the partial view.
6073 -- type T is tagged private;
6074 -- type DT is new T with private;
6075 -- procedure Prim (X : in out T; Y : in out DT'Class);
6077 -- type T is tagged null record;
6079 -- type DT is new T with null record;
6082 -- In this case the type will be frozen later by the usual
6083 -- mechanism: an object declaration, an instantiation, or the
6084 -- end of a declarative part.
6086 if Is_Library_Level_Tagged_Type
(E
)
6087 and then not Present
(Full_View
(E
))
6089 Set_Is_Frozen
(E
, False);
6092 -- Case of full view present
6094 elsif Present
(Full_View
(E
)) then
6096 -- If full view has already been frozen, then no further
6097 -- processing is required
6099 if Is_Frozen
(Full_View
(E
)) then
6100 Set_Has_Delayed_Freeze
(E
, False);
6101 Set_Freeze_Node
(E
, Empty
);
6103 -- Otherwise freeze full view and patch the pointers so that
6104 -- the freeze node will elaborate both views in the back end.
6105 -- However, if full view is itself private, freeze underlying
6106 -- full view instead and patch the pointers so that the freeze
6107 -- node will elaborate the three views in the back end.
6111 Full
: Entity_Id
:= Full_View
(E
);
6114 if Is_Private_Type
(Full
)
6115 and then Present
(Underlying_Full_View
(Full
))
6117 Full
:= Underlying_Full_View
(Full
);
6120 Freeze_And_Append
(Full
, N
, Result
);
6122 if Full
/= Full_View
(E
)
6123 and then Has_Delayed_Freeze
(Full_View
(E
))
6125 F_Node
:= Freeze_Node
(Full
);
6127 if Present
(F_Node
) then
6130 Typ
=> Full_View
(E
));
6132 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
6133 Set_Freeze_Node
(Full_View
(E
), Empty
);
6137 if Has_Delayed_Freeze
(E
) then
6138 F_Node
:= Freeze_Node
(Full_View
(E
));
6140 if Present
(F_Node
) then
6145 -- {Incomplete,Private}_Subtypes with Full_Views
6146 -- constrained by discriminants.
6148 Set_Has_Delayed_Freeze
(E
, False);
6149 Set_Freeze_Node
(E
, Empty
);
6155 Check_Debug_Info_Needed
(E
);
6157 -- AI-117 requires that the convention of a partial view be the
6158 -- same as the convention of the full view. Note that this is a
6159 -- recognized breach of privacy, but it's essential for logical
6160 -- consistency of representation, and the lack of a rule in
6161 -- RM95 was an oversight.
6163 Set_Convention
(E
, Convention
(Full_View
(E
)));
6165 Set_Size_Known_At_Compile_Time
(E
,
6166 Size_Known_At_Compile_Time
(Full_View
(E
)));
6168 -- Size information is copied from the full view to the
6169 -- incomplete or private view for consistency.
6171 -- We skip this is the full view is not a type. This is very
6172 -- strange of course, and can only happen as a result of
6173 -- certain illegalities, such as a premature attempt to derive
6174 -- from an incomplete type.
6176 if Is_Type
(Full_View
(E
)) then
6177 Set_Size_Info
(E
, Full_View
(E
));
6178 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
6183 -- Case of underlying full view present
6185 elsif Is_Private_Type
(E
)
6186 and then Present
(Underlying_Full_View
(E
))
6188 if not Is_Frozen
(Underlying_Full_View
(E
)) then
6189 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
6192 -- Patch the pointers so that the freeze node will elaborate
6193 -- both views in the back end.
6195 if Has_Delayed_Freeze
(E
) then
6196 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
6198 if Present
(F_Node
) then
6203 Set_Has_Delayed_Freeze
(E
, False);
6204 Set_Freeze_Node
(E
, Empty
);
6208 Check_Debug_Info_Needed
(E
);
6212 -- Case of no full view present. If entity is derived or subtype,
6213 -- it is safe to freeze, correctness depends on the frozen status
6214 -- of parent. Otherwise it is either premature usage, or a Taft
6215 -- amendment type, so diagnosis is at the point of use and the
6216 -- type might be frozen later.
6218 elsif E
/= Base_Type
(E
) or else Is_Derived_Type
(E
) then
6222 Set_Is_Frozen
(E
, False);
6227 -- For access subprogram, freeze types of all formals, the return
6228 -- type was already frozen, since it is the Etype of the function.
6229 -- Formal types can be tagged Taft amendment types, but otherwise
6230 -- they cannot be incomplete.
6232 elsif Ekind
(E
) = E_Subprogram_Type
then
6233 Formal
:= First_Formal
(E
);
6234 while Present
(Formal
) loop
6235 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
6236 and then No
(Full_View
(Etype
(Formal
)))
6238 if Is_Tagged_Type
(Etype
(Formal
)) then
6241 -- AI05-151: Incomplete types are allowed in access to
6242 -- subprogram specifications.
6244 elsif Ada_Version
< Ada_2012
then
6246 ("invalid use of incomplete type&", E
, Etype
(Formal
));
6250 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
6251 Next_Formal
(Formal
);
6254 Freeze_Subprogram
(E
);
6256 -- For access to a protected subprogram, freeze the equivalent type
6257 -- (however this is not set if we are not generating code or if this
6258 -- is an anonymous type used just for resolution).
6260 elsif Is_Access_Protected_Subprogram_Type
(E
) then
6261 if Present
(Equivalent_Type
(E
)) then
6262 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
6266 -- Generic types are never seen by the back-end, and are also not
6267 -- processed by the expander (since the expander is turned off for
6268 -- generic processing), so we never need freeze nodes for them.
6270 if Is_Generic_Type
(E
) then
6274 -- Some special processing for non-generic types to complete
6275 -- representation details not known till the freeze point.
6277 if Is_Fixed_Point_Type
(E
) then
6278 Freeze_Fixed_Point_Type
(E
);
6280 -- Some error checks required for ordinary fixed-point type. Defer
6281 -- these till the freeze-point since we need the small and range
6282 -- values. We only do these checks for base types
6284 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
6285 if Small_Value
(E
) < Ureal_2_M_80
then
6286 Error_Msg_Name_1
:= Name_Small
;
6288 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
6290 elsif Small_Value
(E
) > Ureal_2_80
then
6291 Error_Msg_Name_1
:= Name_Small
;
6293 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
6296 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
6297 Error_Msg_Name_1
:= Name_First
;
6299 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
6302 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
6303 Error_Msg_Name_1
:= Name_Last
;
6305 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
6309 elsif Is_Enumeration_Type
(E
) then
6310 Freeze_Enumeration_Type
(E
);
6312 elsif Is_Integer_Type
(E
) then
6313 Adjust_Esize_For_Alignment
(E
);
6315 if Is_Modular_Integer_Type
(E
)
6316 and then Warn_On_Suspicious_Modulus_Value
6318 Check_Suspicious_Modulus
(E
);
6321 -- The pool applies to named and anonymous access types, but not
6322 -- to subprogram and to internal types generated for 'Access
6325 elsif Is_Access_Type
(E
)
6326 and then not Is_Access_Subprogram_Type
(E
)
6327 and then Ekind
(E
) /= E_Access_Attribute_Type
6329 -- If a pragma Default_Storage_Pool applies, and this type has no
6330 -- Storage_Pool or Storage_Size clause (which must have occurred
6331 -- before the freezing point), then use the default. This applies
6332 -- only to base types.
6334 -- None of this applies to access to subprograms, for which there
6335 -- are clearly no pools.
6337 if Present
(Default_Pool
)
6338 and then Is_Base_Type
(E
)
6339 and then not Has_Storage_Size_Clause
(E
)
6340 and then No
(Associated_Storage_Pool
(E
))
6342 -- Case of pragma Default_Storage_Pool (null)
6344 if Nkind
(Default_Pool
) = N_Null
then
6345 Set_No_Pool_Assigned
(E
);
6347 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
6350 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
6354 -- Check restriction for standard storage pool
6356 if No
(Associated_Storage_Pool
(E
)) then
6357 Check_Restriction
(No_Standard_Storage_Pools
, E
);
6360 -- Deal with error message for pure access type. This is not an
6361 -- error in Ada 2005 if there is no pool (see AI-366).
6363 if Is_Pure_Unit_Access_Type
(E
)
6364 and then (Ada_Version
< Ada_2005
6365 or else not No_Pool_Assigned
(E
))
6366 and then not Is_Generic_Unit
(Scope
(E
))
6368 Error_Msg_N
("named access type not allowed in pure unit", E
);
6370 if Ada_Version
>= Ada_2005
then
6372 ("\would be legal if Storage_Size of 0 given??", E
);
6374 elsif No_Pool_Assigned
(E
) then
6376 ("\would be legal in Ada 2005??", E
);
6380 ("\would be legal in Ada 2005 if "
6381 & "Storage_Size of 0 given??", E
);
6386 -- Case of composite types
6388 if Is_Composite_Type
(E
) then
6390 -- AI-117 requires that all new primitives of a tagged type must
6391 -- inherit the convention of the full view of the type. Inherited
6392 -- and overriding operations are defined to inherit the convention
6393 -- of their parent or overridden subprogram (also specified in
6394 -- AI-117), which will have occurred earlier (in Derive_Subprogram
6395 -- and New_Overloaded_Entity). Here we set the convention of
6396 -- primitives that are still convention Ada, which will ensure
6397 -- that any new primitives inherit the type's convention. Class-
6398 -- wide types can have a foreign convention inherited from their
6399 -- specific type, but are excluded from this since they don't have
6400 -- any associated primitives.
6402 if Is_Tagged_Type
(E
)
6403 and then not Is_Class_Wide_Type
(E
)
6404 and then Convention
(E
) /= Convention_Ada
6407 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
6411 Prim
:= First_Elmt
(Prim_List
);
6412 while Present
(Prim
) loop
6413 if Convention
(Node
(Prim
)) = Convention_Ada
then
6414 Set_Convention
(Node
(Prim
), Convention
(E
));
6422 -- If the type is a simple storage pool type, then this is where
6423 -- we attempt to locate and validate its Allocate, Deallocate, and
6424 -- Storage_Size operations (the first is required, and the latter
6425 -- two are optional). We also verify that the full type for a
6426 -- private type is allowed to be a simple storage pool type.
6428 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
6429 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
6431 -- If the type is marked Has_Private_Declaration, then this is
6432 -- a full type for a private type that was specified with the
6433 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
6434 -- pragma is allowed for the full type (for example, it can't
6435 -- be an array type, or a nonlimited record type).
6437 if Has_Private_Declaration
(E
) then
6438 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
6439 and then not Is_Private_Type
(E
)
6441 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
6443 ("pragma% can only apply to full type that is an " &
6444 "explicitly limited type", E
);
6448 Validate_Simple_Pool_Ops
: declare
6449 Pool_Type
: Entity_Id
renames E
;
6450 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
6451 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
6453 procedure Validate_Simple_Pool_Op_Formal
6454 (Pool_Op
: Entity_Id
;
6455 Pool_Op_Formal
: in out Entity_Id
;
6456 Expected_Mode
: Formal_Kind
;
6457 Expected_Type
: Entity_Id
;
6458 Formal_Name
: String;
6459 OK_Formal
: in out Boolean);
6460 -- Validate one formal Pool_Op_Formal of the candidate pool
6461 -- operation Pool_Op. The formal must be of Expected_Type
6462 -- and have mode Expected_Mode. OK_Formal will be set to
6463 -- False if the formal doesn't match. If OK_Formal is False
6464 -- on entry, then the formal will effectively be ignored
6465 -- (because validation of the pool op has already failed).
6466 -- Upon return, Pool_Op_Formal will be updated to the next
6469 procedure Validate_Simple_Pool_Operation
6470 (Op_Name
: Name_Id
);
6471 -- Search for and validate a simple pool operation with the
6472 -- name Op_Name. If the name is Allocate, then there must be
6473 -- exactly one such primitive operation for the simple pool
6474 -- type. If the name is Deallocate or Storage_Size, then
6475 -- there can be at most one such primitive operation. The
6476 -- profile of the located primitive must conform to what
6477 -- is expected for each operation.
6479 ------------------------------------
6480 -- Validate_Simple_Pool_Op_Formal --
6481 ------------------------------------
6483 procedure Validate_Simple_Pool_Op_Formal
6484 (Pool_Op
: Entity_Id
;
6485 Pool_Op_Formal
: in out Entity_Id
;
6486 Expected_Mode
: Formal_Kind
;
6487 Expected_Type
: Entity_Id
;
6488 Formal_Name
: String;
6489 OK_Formal
: in out Boolean)
6492 -- If OK_Formal is False on entry, then simply ignore
6493 -- the formal, because an earlier formal has already
6496 if not OK_Formal
then
6499 -- If no formal is passed in, then issue an error for a
6502 elsif not Present
(Pool_Op_Formal
) then
6504 ("simple storage pool op missing formal " &
6505 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
6511 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
6513 -- If the pool type was expected for this formal, then
6514 -- this will not be considered a candidate operation
6515 -- for the simple pool, so we unset OK_Formal so that
6516 -- the op and any later formals will be ignored.
6518 if Expected_Type
= Pool_Type
then
6525 ("wrong type for formal " & Formal_Name
&
6526 " of simple storage pool op; expected type&",
6527 Pool_Op_Formal
, Expected_Type
);
6531 -- Issue error if formal's mode is not the expected one
6533 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
6535 ("wrong mode for formal of simple storage pool op",
6539 -- Advance to the next formal
6541 Next_Formal
(Pool_Op_Formal
);
6542 end Validate_Simple_Pool_Op_Formal
;
6544 ------------------------------------
6545 -- Validate_Simple_Pool_Operation --
6546 ------------------------------------
6548 procedure Validate_Simple_Pool_Operation
6552 Found_Op
: Entity_Id
:= Empty
;
6558 (Nam_In
(Op_Name
, Name_Allocate
,
6560 Name_Storage_Size
));
6562 Error_Msg_Name_1
:= Op_Name
;
6564 -- For each homonym declared immediately in the scope
6565 -- of the simple storage pool type, determine whether
6566 -- the homonym is an operation of the pool type, and,
6567 -- if so, check that its profile is as expected for
6568 -- a simple pool operation of that name.
6570 Op
:= Get_Name_Entity_Id
(Op_Name
);
6571 while Present
(Op
) loop
6572 if Ekind_In
(Op
, E_Function
, E_Procedure
)
6573 and then Scope
(Op
) = Current_Scope
6575 Formal
:= First_Entity
(Op
);
6579 -- The first parameter must be of the pool type
6580 -- in order for the operation to qualify.
6582 if Op_Name
= Name_Storage_Size
then
6583 Validate_Simple_Pool_Op_Formal
6584 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
6587 Validate_Simple_Pool_Op_Formal
6588 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
6592 -- If another operation with this name has already
6593 -- been located for the type, then flag an error,
6594 -- since we only allow the type to have a single
6597 if Present
(Found_Op
) and then Is_OK
then
6599 ("only one % operation allowed for " &
6600 "simple storage pool type&", Op
, Pool_Type
);
6603 -- In the case of Allocate and Deallocate, a formal
6604 -- of type System.Address is required.
6606 if Op_Name
= Name_Allocate
then
6607 Validate_Simple_Pool_Op_Formal
6608 (Op
, Formal
, E_Out_Parameter
,
6609 Address_Type
, "Storage_Address", Is_OK
);
6611 elsif Op_Name
= Name_Deallocate
then
6612 Validate_Simple_Pool_Op_Formal
6613 (Op
, Formal
, E_In_Parameter
,
6614 Address_Type
, "Storage_Address", Is_OK
);
6617 -- In the case of Allocate and Deallocate, formals
6618 -- of type Storage_Count are required as the third
6619 -- and fourth parameters.
6621 if Op_Name
/= Name_Storage_Size
then
6622 Validate_Simple_Pool_Op_Formal
6623 (Op
, Formal
, E_In_Parameter
,
6624 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
6625 Validate_Simple_Pool_Op_Formal
6626 (Op
, Formal
, E_In_Parameter
,
6627 Stg_Cnt_Type
, "Alignment", Is_OK
);
6630 -- If no mismatched formals have been found (Is_OK)
6631 -- and no excess formals are present, then this
6632 -- operation has been validated, so record it.
6634 if not Present
(Formal
) and then Is_OK
then
6642 -- There must be a valid Allocate operation for the type,
6643 -- so issue an error if none was found.
6645 if Op_Name
= Name_Allocate
6646 and then not Present
(Found_Op
)
6648 Error_Msg_N
("missing % operation for simple " &
6649 "storage pool type", Pool_Type
);
6651 elsif Present
(Found_Op
) then
6653 -- Simple pool operations can't be abstract
6655 if Is_Abstract_Subprogram
(Found_Op
) then
6657 ("simple storage pool operation must not be " &
6658 "abstract", Found_Op
);
6661 -- The Storage_Size operation must be a function with
6662 -- Storage_Count as its result type.
6664 if Op_Name
= Name_Storage_Size
then
6665 if Ekind
(Found_Op
) = E_Procedure
then
6667 ("% operation must be a function", Found_Op
);
6669 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
6671 ("wrong result type for%, expected type&",
6672 Found_Op
, Stg_Cnt_Type
);
6675 -- Allocate and Deallocate must be procedures
6677 elsif Ekind
(Found_Op
) = E_Function
then
6679 ("% operation must be a procedure", Found_Op
);
6682 end Validate_Simple_Pool_Operation
;
6684 -- Start of processing for Validate_Simple_Pool_Ops
6687 Validate_Simple_Pool_Operation
(Name_Allocate
);
6688 Validate_Simple_Pool_Operation
(Name_Deallocate
);
6689 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
6690 end Validate_Simple_Pool_Ops
;
6694 -- Now that all types from which E may depend are frozen, see if the
6695 -- size is known at compile time, if it must be unsigned, or if
6696 -- strict alignment is required
6698 Check_Compile_Time_Size
(E
);
6699 Check_Unsigned_Type
(E
);
6701 if Base_Type
(E
) = E
then
6702 Check_Strict_Alignment
(E
);
6705 -- Do not allow a size clause for a type which does not have a size
6706 -- that is known at compile time
6708 if Has_Size_Clause
(E
)
6709 and then not Size_Known_At_Compile_Time
(E
)
6711 -- Suppress this message if errors posted on E, even if we are
6712 -- in all errors mode, since this is often a junk message
6714 if not Error_Posted
(E
) then
6716 ("size clause not allowed for variable length type",
6721 -- Now we set/verify the representation information, in particular
6722 -- the size and alignment values. This processing is not required for
6723 -- generic types, since generic types do not play any part in code
6724 -- generation, and so the size and alignment values for such types
6725 -- are irrelevant. Ditto for types declared within a generic unit,
6726 -- which may have components that depend on generic parameters, and
6727 -- that will be recreated in an instance.
6729 if Inside_A_Generic
then
6732 -- Otherwise we call the layout procedure
6738 -- If this is an access to subprogram whose designated type is itself
6739 -- a subprogram type, the return type of this anonymous subprogram
6740 -- type must be decorated as well.
6742 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
6743 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
6745 Layout_Type
(Etype
(Designated_Type
(E
)));
6748 -- If the type has a Defaut_Value/Default_Component_Value aspect,
6749 -- this is where we analye the expression (after the type is frozen,
6750 -- since in the case of Default_Value, we are analyzing with the
6751 -- type itself, and we treat Default_Component_Value similarly for
6752 -- the sake of uniformity).
6754 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
6761 if Is_Scalar_Type
(E
) then
6762 Nam
:= Name_Default_Value
;
6764 Exp
:= Default_Aspect_Value
(Typ
);
6766 Nam
:= Name_Default_Component_Value
;
6767 Typ
:= Component_Type
(E
);
6768 Exp
:= Default_Aspect_Component_Value
(E
);
6771 Analyze_And_Resolve
(Exp
, Typ
);
6773 if Etype
(Exp
) /= Any_Type
then
6774 if not Is_OK_Static_Expression
(Exp
) then
6775 Error_Msg_Name_1
:= Nam
;
6776 Flag_Non_Static_Expr
6777 ("aspect% requires static expression", Exp
);
6783 -- End of freeze processing for type entities
6786 -- Here is where we logically freeze the current entity. If it has a
6787 -- freeze node, then this is the point at which the freeze node is
6788 -- linked into the result list.
6790 if Has_Delayed_Freeze
(E
) then
6792 -- If a freeze node is already allocated, use it, otherwise allocate
6793 -- a new one. The preallocation happens in the case of anonymous base
6794 -- types, where we preallocate so that we can set First_Subtype_Link.
6795 -- Note that we reset the Sloc to the current freeze location.
6797 if Present
(Freeze_Node
(E
)) then
6798 F_Node
:= Freeze_Node
(E
);
6799 Set_Sloc
(F_Node
, Loc
);
6802 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
6803 Set_Freeze_Node
(E
, F_Node
);
6804 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
6805 Set_TSS_Elist
(F_Node
, No_Elist
);
6806 Set_Actions
(F_Node
, No_List
);
6809 Set_Entity
(F_Node
, E
);
6810 Add_To_Result
(F_Node
);
6812 -- A final pass over record types with discriminants. If the type
6813 -- has an incomplete declaration, there may be constrained access
6814 -- subtypes declared elsewhere, which do not depend on the discrimi-
6815 -- nants of the type, and which are used as component types (i.e.
6816 -- the full view is a recursive type). The designated types of these
6817 -- subtypes can only be elaborated after the type itself, and they
6818 -- need an itype reference.
6820 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
6827 Comp
:= First_Component
(E
);
6828 while Present
(Comp
) loop
6829 Typ
:= Etype
(Comp
);
6831 if Ekind
(Comp
) = E_Component
6832 and then Is_Access_Type
(Typ
)
6833 and then Scope
(Typ
) /= E
6834 and then Base_Type
(Designated_Type
(Typ
)) = E
6835 and then Is_Itype
(Designated_Type
(Typ
))
6837 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
6838 Set_Itype
(IR
, Designated_Type
(Typ
));
6839 Append
(IR
, Result
);
6842 Next_Component
(Comp
);
6848 -- When a type is frozen, the first subtype of the type is frozen as
6849 -- well (RM 13.14(15)). This has to be done after freezing the type,
6850 -- since obviously the first subtype depends on its own base type.
6853 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
6855 -- If we just froze a tagged non-class wide record, then freeze the
6856 -- corresponding class-wide type. This must be done after the tagged
6857 -- type itself is frozen, because the class-wide type refers to the
6858 -- tagged type which generates the class.
6860 if Is_Tagged_Type
(E
)
6861 and then not Is_Class_Wide_Type
(E
)
6862 and then Present
(Class_Wide_Type
(E
))
6864 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
6868 Check_Debug_Info_Needed
(E
);
6870 -- Special handling for subprograms
6872 if Is_Subprogram
(E
) then
6874 -- If subprogram has address clause then reset Is_Public flag, since
6875 -- we do not want the backend to generate external references.
6877 if Present
(Address_Clause
(E
))
6878 and then not Is_Library_Level_Entity
(E
)
6880 Set_Is_Public
(E
, False);
6885 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
6890 -----------------------------
6891 -- Freeze_Enumeration_Type --
6892 -----------------------------
6894 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
6896 -- By default, if no size clause is present, an enumeration type with
6897 -- Convention C is assumed to interface to a C enum and has integer
6898 -- size, except for a boolean type because it is assumed to interface
6899 -- to _Bool introduced in C99. This applies to types. For subtypes,
6900 -- verify that its base type has no size clause either. Treat other
6901 -- foreign conventions in the same way, and also make sure alignment
6904 if Has_Foreign_Convention
(Typ
)
6905 and then not Is_Boolean_Type
(Typ
)
6906 and then not Has_Size_Clause
(Typ
)
6907 and then not Has_Size_Clause
(Base_Type
(Typ
))
6908 and then Esize
(Typ
) < Standard_Integer_Size
6910 -- Don't do this if Short_Enums on target
6912 and then not Target_Short_Enums
6914 Init_Esize
(Typ
, Standard_Integer_Size
);
6915 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
6917 -- Normal Ada case or size clause present or not Long_C_Enums on target
6920 -- If the enumeration type interfaces to C, and it has a size clause
6921 -- that specifies less than int size, it warrants a warning. The
6922 -- user may intend the C type to be an enum or a char, so this is
6923 -- not by itself an error that the Ada compiler can detect, but it
6924 -- it is a worth a heads-up. For Boolean and Character types we
6925 -- assume that the programmer has the proper C type in mind.
6927 if Convention
(Typ
) = Convention_C
6928 and then Has_Size_Clause
(Typ
)
6929 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
6930 and then not Is_Boolean_Type
(Typ
)
6931 and then not Is_Character_Type
(Typ
)
6933 -- Don't do this if Short_Enums on target
6935 and then not Target_Short_Enums
6938 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
6941 Adjust_Esize_For_Alignment
(Typ
);
6943 end Freeze_Enumeration_Type
;
6945 -----------------------
6946 -- Freeze_Expression --
6947 -----------------------
6949 procedure Freeze_Expression
(N
: Node_Id
) is
6951 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
6952 -- If the expression is an array aggregate, the type of the component
6953 -- expressions is also frozen. If the component type is an access type
6954 -- and the expressions include allocators, the designed type is frozen
6957 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
6958 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
6959 -- it is the handled statement sequence of an expander-generated
6960 -- subprogram (init proc, stream subprogram, or renaming as body).
6961 -- If so, this is not a freezing context.
6963 -----------------------------------------
6964 -- Find_Aggregate_Component_Desig_Type --
6965 -----------------------------------------
6967 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
6972 if Present
(Expressions
(N
)) then
6973 Exp
:= First
(Expressions
(N
));
6974 while Present
(Exp
) loop
6975 if Nkind
(Exp
) = N_Allocator
then
6976 return Designated_Type
(Component_Type
(Etype
(N
)));
6983 if Present
(Component_Associations
(N
)) then
6984 Assoc
:= First
(Component_Associations
(N
));
6985 while Present
(Assoc
) loop
6986 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
6987 return Designated_Type
(Component_Type
(Etype
(N
)));
6995 end Find_Aggregate_Component_Desig_Type
;
6997 ----------------------
6998 -- In_Expanded_Body --
6999 ----------------------
7001 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
7006 if Nkind
(N
) = N_Subprogram_Body
then
7012 if Nkind
(P
) /= N_Subprogram_Body
then
7016 Id
:= Defining_Unit_Name
(Specification
(P
));
7018 -- The following are expander-created bodies, or bodies that
7019 -- are not freeze points.
7021 if Nkind
(Id
) = N_Defining_Identifier
7022 and then (Is_Init_Proc
(Id
)
7023 or else Is_TSS
(Id
, TSS_Stream_Input
)
7024 or else Is_TSS
(Id
, TSS_Stream_Output
)
7025 or else Is_TSS
(Id
, TSS_Stream_Read
)
7026 or else Is_TSS
(Id
, TSS_Stream_Write
)
7027 or else Nkind_In
(Original_Node
(P
),
7028 N_Subprogram_Renaming_Declaration
,
7029 N_Expression_Function
))
7036 end In_Expanded_Body
;
7040 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
7042 Desig_Typ
: Entity_Id
;
7048 Freeze_Outside
: Boolean := False;
7049 -- This flag is set true if the entity must be frozen outside the
7050 -- current subprogram. This happens in the case of expander generated
7051 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
7052 -- not freeze all entities like other bodies, but which nevertheless
7053 -- may reference entities that have to be frozen before the body and
7054 -- obviously cannot be frozen inside the body.
7056 Freeze_Outside_Subp
: Entity_Id
:= Empty
;
7057 -- This entity is set if we are inside a subprogram body and the frozen
7058 -- entity is defined in the enclosing scope of this subprogram. In such
7059 -- case we must skip the subprogram body when climbing the parents chain
7060 -- to locate the correct placement for the freezing node.
7062 -- Start of processing for Freeze_Expression
7065 -- Immediate return if freezing is inhibited. This flag is set by the
7066 -- analyzer to stop freezing on generated expressions that would cause
7067 -- freezing if they were in the source program, but which are not
7068 -- supposed to freeze, since they are created.
7070 if Must_Not_Freeze
(N
) then
7074 -- If expression is non-static, then it does not freeze in a default
7075 -- expression, see section "Handling of Default Expressions" in the
7076 -- spec of package Sem for further details. Note that we have to make
7077 -- sure that we actually have a real expression (if we have a subtype
7078 -- indication, we can't test Is_OK_Static_Expression). However, we
7079 -- exclude the case of the prefix of an attribute of a static scalar
7080 -- subtype from this early return, because static subtype attributes
7081 -- should always cause freezing, even in default expressions, but
7082 -- the attribute may not have been marked as static yet (because in
7083 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
7084 -- Freeze_Expression on the prefix).
7087 and then Nkind
(N
) in N_Subexpr
7088 and then not Is_OK_Static_Expression
(N
)
7089 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
7090 or else not (Is_Entity_Name
(N
)
7091 and then Is_Type
(Entity
(N
))
7092 and then Is_OK_Static_Subtype
(Entity
(N
))))
7097 -- Freeze type of expression if not frozen already
7101 if Nkind
(N
) in N_Has_Etype
then
7102 if not Is_Frozen
(Etype
(N
)) then
7105 -- Base type may be an derived numeric type that is frozen at the
7106 -- point of declaration, but first_subtype is still unfrozen.
7108 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
7109 Typ
:= First_Subtype
(Etype
(N
));
7113 -- For entity name, freeze entity if not frozen already. A special
7114 -- exception occurs for an identifier that did not come from source.
7115 -- We don't let such identifiers freeze a non-internal entity, i.e.
7116 -- an entity that did come from source, since such an identifier was
7117 -- generated by the expander, and cannot have any semantic effect on
7118 -- the freezing semantics. For example, this stops the parameter of
7119 -- an initialization procedure from freezing the variable.
7121 if Is_Entity_Name
(N
)
7122 and then not Is_Frozen
(Entity
(N
))
7123 and then (Nkind
(N
) /= N_Identifier
7124 or else Comes_From_Source
(N
)
7125 or else not Comes_From_Source
(Entity
(N
)))
7129 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
7130 Check_Expression_Function
(N
, Nam
);
7137 -- For an allocator freeze designated type if not frozen already
7139 -- For an aggregate whose component type is an access type, freeze the
7140 -- designated type now, so that its freeze does not appear within the
7141 -- loop that might be created in the expansion of the aggregate. If the
7142 -- designated type is a private type without full view, the expression
7143 -- cannot contain an allocator, so the type is not frozen.
7145 -- For a function, we freeze the entity when the subprogram declaration
7146 -- is frozen, but a function call may appear in an initialization proc.
7147 -- before the declaration is frozen. We need to generate the extra
7148 -- formals, if any, to ensure that the expansion of the call includes
7149 -- the proper actuals. This only applies to Ada subprograms, not to
7156 Desig_Typ
:= Designated_Type
(Etype
(N
));
7159 if Is_Array_Type
(Etype
(N
))
7160 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
7162 -- Check whether aggregate includes allocators
7164 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
7167 when N_Indexed_Component
7168 | N_Selected_Component
7171 if Is_Access_Type
(Etype
(Prefix
(N
))) then
7172 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
7175 when N_Identifier
=>
7177 and then Ekind
(Nam
) = E_Function
7178 and then Nkind
(Parent
(N
)) = N_Function_Call
7179 and then Convention
(Nam
) = Convention_Ada
7181 Create_Extra_Formals
(Nam
);
7188 if Desig_Typ
/= Empty
7189 and then (Is_Frozen
(Desig_Typ
)
7190 or else (not Is_Fully_Defined
(Desig_Typ
)))
7195 -- All done if nothing needs freezing
7199 and then No
(Desig_Typ
)
7204 -- Check if we are inside a subprogram body and the frozen entity is
7205 -- defined in the enclosing scope of this subprogram. In such case we
7206 -- must skip the subprogram when climbing the parents chain to locate
7207 -- the correct placement for the freezing node.
7209 -- This is not needed for default expressions and other spec expressions
7210 -- in generic units since the Move_Freeze_Nodes mechanism (sem_ch12.adb)
7211 -- takes care of placing them at the proper place, after the generic
7215 and then Scope
(Nam
) /= Current_Scope
7216 and then not (In_Spec_Exp
and then Inside_A_Generic
)
7219 S
: Entity_Id
:= Current_Scope
;
7223 and then In_Same_Source_Unit
(Nam
, S
)
7225 if Scope
(S
) = Scope
(Nam
) then
7226 if Is_Subprogram
(S
) and then Has_Completion
(S
) then
7227 Freeze_Outside_Subp
:= S
;
7238 -- Examine the enclosing context by climbing the parent chain
7240 -- If we identified that we must freeze the entity outside of a given
7241 -- subprogram then we just climb up to that subprogram checking if some
7242 -- enclosing node is marked as Must_Not_Freeze (since in such case we
7243 -- must not freeze yet this entity).
7247 if Present
(Freeze_Outside_Subp
) then
7249 -- Do not freeze the current expression if another expression in
7250 -- the chain of parents must not be frozen.
7252 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
7256 Parent_P
:= Parent
(P
);
7258 -- If we don't have a parent, then we are not in a well-formed
7259 -- tree. This is an unusual case, but there are some legitimate
7260 -- situations in which this occurs, notably when the expressions
7261 -- in the range of a type declaration are resolved. We simply
7262 -- ignore the freeze request in this case.
7264 if No
(Parent_P
) then
7269 Nkind
(Parent_P
) = N_Subprogram_Body
7270 and then Unique_Defining_Entity
(Parent_P
) =
7271 Freeze_Outside_Subp
;
7276 -- Otherwise the traversal serves two purposes - to detect scenarios
7277 -- where freezeing is not needed and to find the proper insertion point
7278 -- for the freeze nodes. Although somewhat similar to Insert_Actions,
7279 -- this traversal is freezing semantics-sensitive. Inserting freeze
7280 -- nodes blindly in the tree may result in types being frozen too early.
7284 -- Do not freeze the current expression if another expression in
7285 -- the chain of parents must not be frozen.
7287 if Nkind
(P
) in N_Subexpr
and then Must_Not_Freeze
(P
) then
7291 Parent_P
:= Parent
(P
);
7293 -- If we don't have a parent, then we are not in a well-formed
7294 -- tree. This is an unusual case, but there are some legitimate
7295 -- situations in which this occurs, notably when the expressions
7296 -- in the range of a type declaration are resolved. We simply
7297 -- ignore the freeze request in this case. Is this right ???
7299 if No
(Parent_P
) then
7303 -- See if we have got to an appropriate point in the tree
7305 case Nkind
(Parent_P
) is
7307 -- A special test for the exception of (RM 13.14(8)) for the
7308 -- case of per-object expressions (RM 3.8(18)) occurring in
7309 -- component definition or a discrete subtype definition. Note
7310 -- that we test for a component declaration which includes both
7311 -- cases we are interested in, and furthermore the tree does
7312 -- not have explicit nodes for either of these two constructs.
7314 when N_Component_Declaration
=>
7316 -- The case we want to test for here is an identifier that
7317 -- is a per-object expression, this is either a discriminant
7318 -- that appears in a context other than the component
7319 -- declaration or it is a reference to the type of the
7320 -- enclosing construct.
7322 -- For either of these cases, we skip the freezing
7324 if not In_Spec_Expression
7325 and then Nkind
(N
) = N_Identifier
7326 and then (Present
(Entity
(N
)))
7328 -- We recognize the discriminant case by just looking for
7329 -- a reference to a discriminant. It can only be one for
7330 -- the enclosing construct. Skip freezing in this case.
7332 if Ekind
(Entity
(N
)) = E_Discriminant
then
7335 -- For the case of a reference to the enclosing record,
7336 -- (or task or protected type), we look for a type that
7337 -- matches the current scope.
7339 elsif Entity
(N
) = Current_Scope
then
7344 -- If we have an enumeration literal that appears as the choice
7345 -- in the aggregate of an enumeration representation clause,
7346 -- then freezing does not occur (RM 13.14(10)).
7348 when N_Enumeration_Representation_Clause
=>
7350 -- The case we are looking for is an enumeration literal
7352 if Nkind_In
(N
, N_Identifier
, N_Character_Literal
)
7353 and then Is_Enumeration_Type
(Etype
(N
))
7355 -- If enumeration literal appears directly as the choice,
7356 -- do not freeze (this is the normal non-overloaded case)
7358 if Nkind
(Parent
(N
)) = N_Component_Association
7359 and then First
(Choices
(Parent
(N
))) = N
7363 -- If enumeration literal appears as the name of function
7364 -- which is the choice, then also do not freeze. This
7365 -- happens in the overloaded literal case, where the
7366 -- enumeration literal is temporarily changed to a
7367 -- function call for overloading analysis purposes.
7369 elsif Nkind
(Parent
(N
)) = N_Function_Call
7370 and then Nkind
(Parent
(Parent
(N
))) =
7371 N_Component_Association
7372 and then First
(Choices
(Parent
(Parent
(N
)))) =
7379 -- Normally if the parent is a handled sequence of statements,
7380 -- then the current node must be a statement, and that is an
7381 -- appropriate place to insert a freeze node.
7383 when N_Handled_Sequence_Of_Statements
=>
7385 -- An exception occurs when the sequence of statements is
7386 -- for an expander generated body that did not do the usual
7387 -- freeze all operation. In this case we usually want to
7388 -- freeze outside this body, not inside it, and we skip
7389 -- past the subprogram body that we are inside.
7391 if In_Expanded_Body
(Parent_P
) then
7393 Subp
: constant Node_Id
:= Parent
(Parent_P
);
7397 -- Freeze the entity only when it is declared inside
7398 -- the body of the expander generated procedure.
7399 -- This case is recognized by the scope of the entity
7400 -- or its type, which is either the spec for some
7401 -- enclosing body, or (in the case of init_procs,
7402 -- for which there are no separate specs) the current
7405 if Nkind
(Subp
) = N_Subprogram_Body
then
7406 Spec
:= Corresponding_Spec
(Subp
);
7408 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
7410 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
7415 and then Scope
(Typ
) = Current_Scope
7416 and then Defining_Entity
(Subp
) = Current_Scope
7422 -- An expression function may act as a completion of
7423 -- a function declaration. As such, it can reference
7424 -- entities declared between the two views:
7427 -- function F return ...;
7429 -- function Hidden return ...;
7430 -- function F return ... is (Hidden); -- 2
7432 -- Refering to the example above, freezing the
7433 -- expression of F (2) would place Hidden's freeze
7434 -- node (1) in the wrong place. Avoid explicit
7435 -- freezing and let the usual scenarios do the job
7436 -- (for example, reaching the end of the private
7437 -- declarations, or a call to F.)
7439 if Nkind
(Original_Node
(Subp
)) = N_Expression_Function
7443 -- Freeze outside the body
7446 Parent_P
:= Parent
(Parent_P
);
7447 Freeze_Outside
:= True;
7451 -- Here if normal case where we are in handled statement
7452 -- sequence and want to do the insertion right there.
7458 -- If parent is a body or a spec or a block, then the current
7459 -- node is a statement or declaration and we can insert the
7460 -- freeze node before it.
7462 when N_Block_Statement
7465 | N_Package_Specification
7472 -- The expander is allowed to define types in any statements
7473 -- list, so any of the following parent nodes also mark a
7474 -- freezing point if the actual node is in a list of
7475 -- statements or declarations.
7477 when N_Abortable_Part
7478 | N_Accept_Alternative
7480 | N_Case_Statement_Alternative
7481 | N_Compilation_Unit_Aux
7482 | N_Conditional_Entry_Call
7483 | N_Delay_Alternative
7485 | N_Entry_Call_Alternative
7486 | N_Exception_Handler
7487 | N_Extended_Return_Statement
7491 | N_Selective_Accept
7492 | N_Triggering_Alternative
7494 exit when Is_List_Member
(P
);
7496 -- Freeze nodes produced by an expression coming from the
7497 -- Actions list of a N_Expression_With_Actions node must remain
7498 -- within the Actions list. Inserting the freeze nodes further
7499 -- up the tree may lead to use before declaration issues in the
7500 -- case of array types.
7502 when N_Expression_With_Actions
=>
7503 if Is_List_Member
(P
)
7504 and then List_Containing
(P
) = Actions
(Parent_P
)
7509 -- Note: N_Loop_Statement is a special case. A type that
7510 -- appears in the source can never be frozen in a loop (this
7511 -- occurs only because of a loop expanded by the expander), so
7512 -- we keep on going. Otherwise we terminate the search. Same
7513 -- is true of any entity which comes from source. (if they
7514 -- have predefined type, that type does not appear to come
7515 -- from source, but the entity should not be frozen here).
7517 when N_Loop_Statement
=>
7518 exit when not Comes_From_Source
(Etype
(N
))
7519 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
7521 -- For all other cases, keep looking at parents
7527 -- We fall through the case if we did not yet find the proper
7528 -- place in the free for inserting the freeze node, so climb.
7534 -- If the expression appears in a record or an initialization procedure,
7535 -- the freeze nodes are collected and attached to the current scope, to
7536 -- be inserted and analyzed on exit from the scope, to insure that
7537 -- generated entities appear in the correct scope. If the expression is
7538 -- a default for a discriminant specification, the scope is still void.
7539 -- The expression can also appear in the discriminant part of a private
7540 -- or concurrent type.
7542 -- If the expression appears in a constrained subcomponent of an
7543 -- enclosing record declaration, the freeze nodes must be attached to
7544 -- the outer record type so they can eventually be placed in the
7545 -- enclosing declaration list.
7547 -- The other case requiring this special handling is if we are in a
7548 -- default expression, since in that case we are about to freeze a
7549 -- static type, and the freeze scope needs to be the outer scope, not
7550 -- the scope of the subprogram with the default parameter.
7552 -- For default expressions and other spec expressions in generic units,
7553 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
7554 -- placing them at the proper place, after the generic unit.
7556 if (In_Spec_Exp
and not Inside_A_Generic
)
7557 or else Freeze_Outside
7558 or else (Is_Type
(Current_Scope
)
7559 and then (not Is_Concurrent_Type
(Current_Scope
)
7560 or else not Has_Completion
(Current_Scope
)))
7561 or else Ekind
(Current_Scope
) = E_Void
7564 N
: constant Node_Id
:= Current_Scope
;
7565 Freeze_Nodes
: List_Id
:= No_List
;
7566 Pos
: Int
:= Scope_Stack
.Last
;
7569 if Present
(Desig_Typ
) then
7570 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
7573 if Present
(Typ
) then
7574 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
7577 if Present
(Nam
) then
7578 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
7581 -- The current scope may be that of a constrained component of
7582 -- an enclosing record declaration, or of a loop of an enclosing
7583 -- quantified expression, which is above the current scope in the
7584 -- scope stack. Indeed in the context of a quantified expression,
7585 -- a scope is created and pushed above the current scope in order
7586 -- to emulate the loop-like behavior of the quantified expression.
7587 -- If the expression is within a top-level pragma, as for a pre-
7588 -- condition on a library-level subprogram, nothing to do.
7590 if not Is_Compilation_Unit
(Current_Scope
)
7591 and then (Is_Record_Type
(Scope
(Current_Scope
))
7592 or else Nkind
(Parent
(Current_Scope
)) =
7593 N_Quantified_Expression
)
7598 if Is_Non_Empty_List
(Freeze_Nodes
) then
7599 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
7600 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
7603 Append_List
(Freeze_Nodes
,
7604 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
7612 -- Now we have the right place to do the freezing. First, a special
7613 -- adjustment, if we are in spec-expression analysis mode, these freeze
7614 -- actions must not be thrown away (normally all inserted actions are
7615 -- thrown away in this mode. However, the freeze actions are from static
7616 -- expressions and one of the important reasons we are doing this
7617 -- special analysis is to get these freeze actions. Therefore we turn
7618 -- off the In_Spec_Expression mode to propagate these freeze actions.
7619 -- This also means they get properly analyzed and expanded.
7621 In_Spec_Expression
:= False;
7623 -- Freeze the designated type of an allocator (RM 13.14(13))
7625 if Present
(Desig_Typ
) then
7626 Freeze_Before
(P
, Desig_Typ
);
7629 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
7630 -- the enumeration representation clause exception in the loop above.
7632 if Present
(Typ
) then
7633 Freeze_Before
(P
, Typ
);
7636 -- Freeze name if one is present (RM 13.14(11))
7638 if Present
(Nam
) then
7639 Freeze_Before
(P
, Nam
);
7642 -- Restore In_Spec_Expression flag
7644 In_Spec_Expression
:= In_Spec_Exp
;
7645 end Freeze_Expression
;
7647 -----------------------
7648 -- Freeze_Expr_Types --
7649 -----------------------
7651 procedure Freeze_Expr_Types
7652 (Def_Id
: Entity_Id
;
7657 function Cloned_Expression
return Node_Id
;
7658 -- Build a duplicate of the expression of the return statement that has
7659 -- no defining entities shared with the original expression.
7661 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
7662 -- Freeze all types referenced in the subtree rooted at Node
7664 -----------------------
7665 -- Cloned_Expression --
7666 -----------------------
7668 function Cloned_Expression
return Node_Id
is
7669 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
7670 -- Tree traversal routine that clones the defining identifier of
7671 -- iterator and loop parameter specification nodes.
7677 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
7679 if Nkind_In
(Node
, N_Iterator_Specification
,
7680 N_Loop_Parameter_Specification
)
7682 Set_Defining_Identifier
7683 (Node
, New_Copy
(Defining_Identifier
(Node
)));
7689 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
7693 Dup_Expr
: constant Node_Id
:= New_Copy_Tree
(Expr
);
7695 -- Start of processing for Cloned_Expression
7698 -- We must duplicate the expression with semantic information to
7699 -- inherit the decoration of global entities in generic instances.
7700 -- Set the parent of the new node to be the parent of the original
7701 -- to get the proper context, which is needed for complete error
7702 -- reporting and for semantic analysis.
7704 Set_Parent
(Dup_Expr
, Parent
(Expr
));
7706 -- Replace the defining identifier of iterators and loop param
7707 -- specifications by a clone to ensure that the cloned expression
7708 -- and the original expression don't have shared identifiers;
7709 -- otherwise, as part of the preanalysis of the expression, these
7710 -- shared identifiers may be left decorated with itypes which
7711 -- will not be available in the tree passed to the backend.
7713 Clone_Def_Ids
(Dup_Expr
);
7716 end Cloned_Expression
;
7718 ----------------------
7719 -- Freeze_Type_Refs --
7720 ----------------------
7722 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
7723 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
);
7724 -- Check that Typ is fully declared and freeze it if so
7726 ---------------------------
7727 -- Check_And_Freeze_Type --
7728 ---------------------------
7730 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
) is
7732 -- Skip Itypes created by the preanalysis, and itypes whose
7733 -- scope is another type (i.e. component subtypes that depend
7734 -- on a discriminant),
7737 and then (Scope_Within_Or_Same
(Scope
(Typ
), Def_Id
)
7738 or else Is_Type
(Scope
(Typ
)))
7743 -- This provides a better error message than generating primitives
7744 -- whose compilation fails much later. Refine the error message if
7747 Check_Fully_Declared
(Typ
, Node
);
7749 if Error_Posted
(Node
) then
7750 if Has_Private_Component
(Typ
)
7751 and then not Is_Private_Type
(Typ
)
7753 Error_Msg_NE
("\type& has private component", Node
, Typ
);
7757 Freeze_Before
(N
, Typ
);
7759 end Check_And_Freeze_Type
;
7761 -- Start of processing for Freeze_Type_Refs
7764 -- Check that a type referenced by an entity can be frozen
7766 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
7767 Check_And_Freeze_Type
(Etype
(Entity
(Node
)));
7769 -- Check that the enclosing record type can be frozen
7771 if Ekind_In
(Entity
(Node
), E_Component
, E_Discriminant
) then
7772 Check_And_Freeze_Type
(Scope
(Entity
(Node
)));
7775 -- Freezing an access type does not freeze the designated type, but
7776 -- freezing conversions between access to interfaces requires that
7777 -- the interface types themselves be frozen, so that dispatch table
7778 -- entities are properly created.
7780 -- Unclear whether a more general rule is needed ???
7782 elsif Nkind
(Node
) = N_Type_Conversion
7783 and then Is_Access_Type
(Etype
(Node
))
7784 and then Is_Interface
(Designated_Type
(Etype
(Node
)))
7786 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
7789 -- An implicit dereference freezes the designated type. In the case
7790 -- of a dispatching call whose controlling argument is an access
7791 -- type, the dereference is not made explicit, so we must check for
7792 -- such a call and freeze the designated type.
7794 if Nkind
(Node
) in N_Has_Etype
7795 and then Present
(Etype
(Node
))
7796 and then Is_Access_Type
(Etype
(Node
))
7797 and then Nkind
(Parent
(Node
)) = N_Function_Call
7798 and then Node
= Controlling_Argument
(Parent
(Node
))
7800 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
7803 -- No point in posting several errors on the same expression
7805 if Serious_Errors_Detected
> 0 then
7810 end Freeze_Type_Refs
;
7812 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
7816 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Def_Id
);
7817 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Def_Id
);
7818 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
7820 -- Start of processing for Freeze_Expr_Types
7823 -- Preanalyze a duplicate of the expression to have available the
7824 -- minimum decoration needed to locate referenced unfrozen types
7825 -- without adding any decoration to the function expression.
7827 Push_Scope
(Def_Id
);
7828 Install_Formals
(Def_Id
);
7830 Preanalyze_Spec_Expression
(Dup_Expr
, Typ
);
7833 -- Restore certain attributes of Def_Id since the preanalysis may
7834 -- have introduced itypes to this scope, thus modifying attributes
7835 -- First_Entity and Last_Entity.
7837 Set_First_Entity
(Def_Id
, Saved_First_Entity
);
7838 Set_Last_Entity
(Def_Id
, Saved_Last_Entity
);
7840 if Present
(Last_Entity
(Def_Id
)) then
7841 Set_Next_Entity
(Last_Entity
(Def_Id
), Empty
);
7844 -- Freeze all types referenced in the expression
7846 Freeze_References
(Dup_Expr
);
7847 end Freeze_Expr_Types
;
7849 -----------------------------
7850 -- Freeze_Fixed_Point_Type --
7851 -----------------------------
7853 -- Certain fixed-point types and subtypes, including implicit base types
7854 -- and declared first subtypes, have not yet set up a range. This is
7855 -- because the range cannot be set until the Small and Size values are
7856 -- known, and these are not known till the type is frozen.
7858 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
7859 -- whose bounds are unanalyzed real literals. This routine will recognize
7860 -- this case, and transform this range node into a properly typed range
7861 -- with properly analyzed and resolved values.
7863 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
7864 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
7865 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
7866 Hi
: constant Node_Id
:= High_Bound
(Rng
);
7867 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7868 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
7869 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
7870 BHi
: constant Node_Id
:= High_Bound
(Brng
);
7871 Small
: constant Ureal
:= Small_Value
(Typ
);
7878 -- Save original bounds (for shaving tests)
7881 -- Actual size chosen
7883 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
7884 -- Returns size of type with given bounds. Also leaves these
7885 -- bounds set as the current bounds of the Typ.
7891 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
7893 Set_Realval
(Lo
, Lov
);
7894 Set_Realval
(Hi
, Hiv
);
7895 return Minimum_Size
(Typ
);
7898 -- Start of processing for Freeze_Fixed_Point_Type
7901 -- The type, or its first subtype if we are freezing the anonymous
7902 -- base, may have a delayed Small aspect. It must be analyzed now,
7903 -- so that all characteristics of the type (size, bounds) can be
7904 -- computed and validated in the call to Minimum_Size that follows.
7906 if Has_Delayed_Aspects
(First_Subtype
(Typ
)) then
7907 Analyze_Aspects_At_Freeze_Point
(First_Subtype
(Typ
));
7908 Set_Has_Delayed_Aspects
(First_Subtype
(Typ
), False);
7911 -- If Esize of a subtype has not previously been set, set it now
7913 if Unknown_Esize
(Typ
) then
7914 Atype
:= Ancestor_Subtype
(Typ
);
7916 if Present
(Atype
) then
7917 Set_Esize
(Typ
, Esize
(Atype
));
7919 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
7923 -- Immediate return if the range is already analyzed. This means that
7924 -- the range is already set, and does not need to be computed by this
7927 if Analyzed
(Rng
) then
7931 -- Immediate return if either of the bounds raises Constraint_Error
7933 if Raises_Constraint_Error
(Lo
)
7934 or else Raises_Constraint_Error
(Hi
)
7939 Loval
:= Realval
(Lo
);
7940 Hival
:= Realval
(Hi
);
7945 -- Ordinary fixed-point case
7947 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
7949 -- For the ordinary fixed-point case, we are allowed to fudge the
7950 -- end-points up or down by small. Generally we prefer to fudge up,
7951 -- i.e. widen the bounds for non-model numbers so that the end points
7952 -- are included. However there are cases in which this cannot be
7953 -- done, and indeed cases in which we may need to narrow the bounds.
7954 -- The following circuit makes the decision.
7956 -- Note: our terminology here is that Incl_EP means that the bounds
7957 -- are widened by Small if necessary to include the end points, and
7958 -- Excl_EP means that the bounds are narrowed by Small to exclude the
7959 -- end-points if this reduces the size.
7961 -- Note that in the Incl case, all we care about is including the
7962 -- end-points. In the Excl case, we want to narrow the bounds as
7963 -- much as permitted by the RM, to give the smallest possible size.
7966 Loval_Incl_EP
: Ureal
;
7967 Hival_Incl_EP
: Ureal
;
7969 Loval_Excl_EP
: Ureal
;
7970 Hival_Excl_EP
: Ureal
;
7976 First_Subt
: Entity_Id
;
7981 -- First step. Base types are required to be symmetrical. Right
7982 -- now, the base type range is a copy of the first subtype range.
7983 -- This will be corrected before we are done, but right away we
7984 -- need to deal with the case where both bounds are non-negative.
7985 -- In this case, we set the low bound to the negative of the high
7986 -- bound, to make sure that the size is computed to include the
7987 -- required sign. Note that we do not need to worry about the
7988 -- case of both bounds negative, because the sign will be dealt
7989 -- with anyway. Furthermore we can't just go making such a bound
7990 -- symmetrical, since in a twos-complement system, there is an
7991 -- extra negative value which could not be accommodated on the
7995 and then not UR_Is_Negative
(Loval
)
7996 and then Hival
> Loval
7999 Set_Realval
(Lo
, Loval
);
8002 -- Compute the fudged bounds. If the number is a model number,
8003 -- then we do nothing to include it, but we are allowed to backoff
8004 -- to the next adjacent model number when we exclude it. If it is
8005 -- not a model number then we straddle the two values with the
8006 -- model numbers on either side.
8008 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
8010 if Loval
= Model_Num
then
8011 Loval_Incl_EP
:= Model_Num
;
8013 Loval_Incl_EP
:= Model_Num
- Small
;
8016 -- The low value excluding the end point is Small greater, but
8017 -- we do not do this exclusion if the low value is positive,
8018 -- since it can't help the size and could actually hurt by
8019 -- crossing the high bound.
8021 if UR_Is_Negative
(Loval_Incl_EP
) then
8022 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
8024 -- If the value went from negative to zero, then we have the
8025 -- case where Loval_Incl_EP is the model number just below
8026 -- zero, so we want to stick to the negative value for the
8027 -- base type to maintain the condition that the size will
8028 -- include signed values.
8031 and then UR_Is_Zero
(Loval_Excl_EP
)
8033 Loval_Excl_EP
:= Loval_Incl_EP
;
8037 Loval_Excl_EP
:= Loval_Incl_EP
;
8040 -- Similar processing for upper bound and high value
8042 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
8044 if Hival
= Model_Num
then
8045 Hival_Incl_EP
:= Model_Num
;
8047 Hival_Incl_EP
:= Model_Num
+ Small
;
8050 if UR_Is_Positive
(Hival_Incl_EP
) then
8051 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
8053 Hival_Excl_EP
:= Hival_Incl_EP
;
8056 -- One further adjustment is needed. In the case of subtypes, we
8057 -- cannot go outside the range of the base type, or we get
8058 -- peculiarities, and the base type range is already set. This
8059 -- only applies to the Incl values, since clearly the Excl values
8060 -- are already as restricted as they are allowed to be.
8063 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
8064 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
8067 -- Get size including and excluding end points
8069 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
8070 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
8072 -- No need to exclude end-points if it does not reduce size
8074 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
8075 Loval_Excl_EP
:= Loval_Incl_EP
;
8078 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
8079 Hival_Excl_EP
:= Hival_Incl_EP
;
8082 -- Now we set the actual size to be used. We want to use the
8083 -- bounds fudged up to include the end-points but only if this
8084 -- can be done without violating a specifically given size
8085 -- size clause or causing an unacceptable increase in size.
8087 -- Case of size clause given
8089 if Has_Size_Clause
(Typ
) then
8091 -- Use the inclusive size only if it is consistent with
8092 -- the explicitly specified size.
8094 if Size_Incl_EP
<= RM_Size
(Typ
) then
8095 Actual_Lo
:= Loval_Incl_EP
;
8096 Actual_Hi
:= Hival_Incl_EP
;
8097 Actual_Size
:= Size_Incl_EP
;
8099 -- If the inclusive size is too large, we try excluding
8100 -- the end-points (will be caught later if does not work).
8103 Actual_Lo
:= Loval_Excl_EP
;
8104 Actual_Hi
:= Hival_Excl_EP
;
8105 Actual_Size
:= Size_Excl_EP
;
8108 -- Case of size clause not given
8111 -- If we have a base type whose corresponding first subtype
8112 -- has an explicit size that is large enough to include our
8113 -- end-points, then do so. There is no point in working hard
8114 -- to get a base type whose size is smaller than the specified
8115 -- size of the first subtype.
8117 First_Subt
:= First_Subtype
(Typ
);
8119 if Has_Size_Clause
(First_Subt
)
8120 and then Size_Incl_EP
<= Esize
(First_Subt
)
8122 Actual_Size
:= Size_Incl_EP
;
8123 Actual_Lo
:= Loval_Incl_EP
;
8124 Actual_Hi
:= Hival_Incl_EP
;
8126 -- If excluding the end-points makes the size smaller and
8127 -- results in a size of 8,16,32,64, then we take the smaller
8128 -- size. For the 64 case, this is compulsory. For the other
8129 -- cases, it seems reasonable. We like to include end points
8130 -- if we can, but not at the expense of moving to the next
8131 -- natural boundary of size.
8133 elsif Size_Incl_EP
/= Size_Excl_EP
8134 and then Addressable
(Size_Excl_EP
)
8136 Actual_Size
:= Size_Excl_EP
;
8137 Actual_Lo
:= Loval_Excl_EP
;
8138 Actual_Hi
:= Hival_Excl_EP
;
8140 -- Otherwise we can definitely include the end points
8143 Actual_Size
:= Size_Incl_EP
;
8144 Actual_Lo
:= Loval_Incl_EP
;
8145 Actual_Hi
:= Hival_Incl_EP
;
8148 -- One pathological case: normally we never fudge a low bound
8149 -- down, since it would seem to increase the size (if it has
8150 -- any effect), but for ranges containing single value, or no
8151 -- values, the high bound can be small too large. Consider:
8153 -- type t is delta 2.0**(-14)
8154 -- range 131072.0 .. 0;
8156 -- That lower bound is *just* outside the range of 32 bits, and
8157 -- does need fudging down in this case. Note that the bounds
8158 -- will always have crossed here, since the high bound will be
8159 -- fudged down if necessary, as in the case of:
8161 -- type t is delta 2.0**(-14)
8162 -- range 131072.0 .. 131072.0;
8164 -- So we detect the situation by looking for crossed bounds,
8165 -- and if the bounds are crossed, and the low bound is greater
8166 -- than zero, we will always back it off by small, since this
8167 -- is completely harmless.
8169 if Actual_Lo
> Actual_Hi
then
8170 if UR_Is_Positive
(Actual_Lo
) then
8171 Actual_Lo
:= Loval_Incl_EP
- Small
;
8172 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
8174 -- And of course, we need to do exactly the same parallel
8175 -- fudge for flat ranges in the negative region.
8177 elsif UR_Is_Negative
(Actual_Hi
) then
8178 Actual_Hi
:= Hival_Incl_EP
+ Small
;
8179 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
8184 Set_Realval
(Lo
, Actual_Lo
);
8185 Set_Realval
(Hi
, Actual_Hi
);
8188 -- For the decimal case, none of this fudging is required, since there
8189 -- are no end-point problems in the decimal case (the end-points are
8190 -- always included).
8193 Actual_Size
:= Fsize
(Loval
, Hival
);
8196 -- At this stage, the actual size has been calculated and the proper
8197 -- required bounds are stored in the low and high bounds.
8199 if Actual_Size
> 64 then
8200 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
8202 ("size required (^) for type& too large, maximum allowed is 64",
8207 -- Check size against explicit given size
8209 if Has_Size_Clause
(Typ
) then
8210 if Actual_Size
> RM_Size
(Typ
) then
8211 Error_Msg_Uint_1
:= RM_Size
(Typ
);
8212 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
8214 ("size given (^) for type& too small, minimum allowed is ^",
8215 Size_Clause
(Typ
), Typ
);
8218 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
8221 -- Increase size to next natural boundary if no size clause given
8224 if Actual_Size
<= 8 then
8226 elsif Actual_Size
<= 16 then
8228 elsif Actual_Size
<= 32 then
8234 Init_Esize
(Typ
, Actual_Size
);
8235 Adjust_Esize_For_Alignment
(Typ
);
8238 -- If we have a base type, then expand the bounds so that they extend to
8239 -- the full width of the allocated size in bits, to avoid junk range
8240 -- checks on intermediate computations.
8242 if Base_Type
(Typ
) = Typ
then
8243 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
8244 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
8247 -- Final step is to reanalyze the bounds using the proper type
8248 -- and set the Corresponding_Integer_Value fields of the literals.
8250 Set_Etype
(Lo
, Empty
);
8251 Set_Analyzed
(Lo
, False);
8254 -- Resolve with universal fixed if the base type, and the base type if
8255 -- it is a subtype. Note we can't resolve the base type with itself,
8256 -- that would be a reference before definition.
8259 Resolve
(Lo
, Universal_Fixed
);
8264 -- Set corresponding integer value for bound
8266 Set_Corresponding_Integer_Value
8267 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
8269 -- Similar processing for high bound
8271 Set_Etype
(Hi
, Empty
);
8272 Set_Analyzed
(Hi
, False);
8276 Resolve
(Hi
, Universal_Fixed
);
8281 Set_Corresponding_Integer_Value
8282 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
8284 -- Set type of range to correspond to bounds
8286 Set_Etype
(Rng
, Etype
(Lo
));
8288 -- Set Esize to calculated size if not set already
8290 if Unknown_Esize
(Typ
) then
8291 Init_Esize
(Typ
, Actual_Size
);
8294 -- Set RM_Size if not already set. If already set, check value
8297 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
8300 if RM_Size
(Typ
) /= Uint_0
then
8301 if RM_Size
(Typ
) < Minsiz
then
8302 Error_Msg_Uint_1
:= RM_Size
(Typ
);
8303 Error_Msg_Uint_2
:= Minsiz
;
8305 ("size given (^) for type& too small, minimum allowed is ^",
8306 Size_Clause
(Typ
), Typ
);
8310 Set_RM_Size
(Typ
, Minsiz
);
8314 -- Check for shaving
8316 if Comes_From_Source
(Typ
) then
8318 -- In SPARK mode the given bounds must be strictly representable
8320 if SPARK_Mode
= On
then
8321 if Orig_Lo
< Expr_Value_R
(Lo
) then
8323 ("declared low bound of type & is outside type range",
8327 if Orig_Hi
> Expr_Value_R
(Hi
) then
8329 ("declared high bound of type & is outside type range",
8334 if Orig_Lo
< Expr_Value_R
(Lo
) then
8336 ("declared low bound of type & is outside type range??", Typ
);
8338 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
8341 if Orig_Hi
> Expr_Value_R
(Hi
) then
8343 ("declared high bound of type & is outside type range??",
8346 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
8350 end Freeze_Fixed_Point_Type
;
8356 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
8360 Set_Has_Delayed_Freeze
(T
);
8361 L
:= Freeze_Entity
(T
, N
);
8363 if Is_Non_Empty_List
(L
) then
8364 Insert_Actions
(N
, L
);
8368 --------------------------
8369 -- Freeze_Static_Object --
8370 --------------------------
8372 procedure Freeze_Static_Object
(E
: Entity_Id
) is
8374 Cannot_Be_Static
: exception;
8375 -- Exception raised if the type of a static object cannot be made
8376 -- static. This happens if the type depends on non-global objects.
8378 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
8379 -- Called to ensure that an expression used as part of a type definition
8380 -- is statically allocatable, which means that the expression type is
8381 -- statically allocatable, and the expression is either static, or a
8382 -- reference to a library level constant.
8384 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
8385 -- Called to mark a type as static, checking that it is possible
8386 -- to set the type as static. If it is not possible, then the
8387 -- exception Cannot_Be_Static is raised.
8389 -----------------------------
8390 -- Ensure_Expression_Is_SA --
8391 -----------------------------
8393 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
8397 Ensure_Type_Is_SA
(Etype
(N
));
8399 if Is_OK_Static_Expression
(N
) then
8402 elsif Nkind
(N
) = N_Identifier
then
8406 and then Ekind
(Ent
) = E_Constant
8407 and then Is_Library_Level_Entity
(Ent
)
8413 raise Cannot_Be_Static
;
8414 end Ensure_Expression_Is_SA
;
8416 -----------------------
8417 -- Ensure_Type_Is_SA --
8418 -----------------------
8420 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
8425 -- If type is library level, we are all set
8427 if Is_Library_Level_Entity
(Typ
) then
8431 -- We are also OK if the type already marked as statically allocated,
8432 -- which means we processed it before.
8434 if Is_Statically_Allocated
(Typ
) then
8438 -- Mark type as statically allocated
8440 Set_Is_Statically_Allocated
(Typ
);
8442 -- Check that it is safe to statically allocate this type
8444 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
8445 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
8446 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
8448 elsif Is_Array_Type
(Typ
) then
8449 N
:= First_Index
(Typ
);
8450 while Present
(N
) loop
8451 Ensure_Type_Is_SA
(Etype
(N
));
8455 Ensure_Type_Is_SA
(Component_Type
(Typ
));
8457 elsif Is_Access_Type
(Typ
) then
8458 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
8462 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
8465 if T
/= Standard_Void_Type
then
8466 Ensure_Type_Is_SA
(T
);
8469 F
:= First_Formal
(Designated_Type
(Typ
));
8470 while Present
(F
) loop
8471 Ensure_Type_Is_SA
(Etype
(F
));
8477 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
8480 elsif Is_Record_Type
(Typ
) then
8481 C
:= First_Entity
(Typ
);
8482 while Present
(C
) loop
8483 if Ekind
(C
) = E_Discriminant
8484 or else Ekind
(C
) = E_Component
8486 Ensure_Type_Is_SA
(Etype
(C
));
8488 elsif Is_Type
(C
) then
8489 Ensure_Type_Is_SA
(C
);
8495 elsif Ekind
(Typ
) = E_Subprogram_Type
then
8496 Ensure_Type_Is_SA
(Etype
(Typ
));
8498 C
:= First_Formal
(Typ
);
8499 while Present
(C
) loop
8500 Ensure_Type_Is_SA
(Etype
(C
));
8505 raise Cannot_Be_Static
;
8507 end Ensure_Type_Is_SA
;
8509 -- Start of processing for Freeze_Static_Object
8512 Ensure_Type_Is_SA
(Etype
(E
));
8515 when Cannot_Be_Static
=>
8517 -- If the object that cannot be static is imported or exported, then
8518 -- issue an error message saying that this object cannot be imported
8519 -- or exported. If it has an address clause it is an overlay in the
8520 -- current partition and the static requirement is not relevant.
8521 -- Do not issue any error message when ignoring rep clauses.
8523 if Ignore_Rep_Clauses
then
8526 elsif Is_Imported
(E
) then
8527 if No
(Address_Clause
(E
)) then
8529 ("& cannot be imported (local type is not constant)", E
);
8532 -- Otherwise must be exported, something is wrong if compiler
8533 -- is marking something as statically allocated which cannot be).
8535 else pragma Assert
(Is_Exported
(E
));
8537 ("& cannot be exported (local type is not constant)", E
);
8539 end Freeze_Static_Object
;
8541 -----------------------
8542 -- Freeze_Subprogram --
8543 -----------------------
8545 procedure Freeze_Subprogram
(E
: Entity_Id
) is
8546 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
);
8547 -- Set the conventions of all anonymous access-to-subprogram formals and
8548 -- result subtype of subprogram Subp_Id to the convention of Subp_Id.
8550 ----------------------------
8551 -- Set_Profile_Convention --
8552 ----------------------------
8554 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
) is
8555 Conv
: constant Convention_Id
:= Convention
(Subp_Id
);
8557 procedure Set_Type_Convention
(Typ
: Entity_Id
);
8558 -- Set the convention of anonymous access-to-subprogram type Typ and
8559 -- its designated type to Conv.
8561 -------------------------
8562 -- Set_Type_Convention --
8563 -------------------------
8565 procedure Set_Type_Convention
(Typ
: Entity_Id
) is
8567 -- Set the convention on both the anonymous access-to-subprogram
8568 -- type and the subprogram type it points to because both types
8569 -- participate in conformance-related checks.
8571 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
8572 Set_Convention
(Typ
, Conv
);
8573 Set_Convention
(Designated_Type
(Typ
), Conv
);
8575 end Set_Type_Convention
;
8581 -- Start of processing for Set_Profile_Convention
8584 Formal
:= First_Formal
(Subp_Id
);
8585 while Present
(Formal
) loop
8586 Set_Type_Convention
(Etype
(Formal
));
8587 Next_Formal
(Formal
);
8590 if Ekind
(Subp_Id
) = E_Function
then
8591 Set_Type_Convention
(Etype
(Subp_Id
));
8593 end Set_Profile_Convention
;
8600 -- Start of processing for Freeze_Subprogram
8603 -- Subprogram may not have an address clause unless it is imported
8605 if Present
(Address_Clause
(E
)) then
8606 if not Is_Imported
(E
) then
8608 ("address clause can only be given for imported subprogram",
8609 Name
(Address_Clause
(E
)));
8613 -- Reset the Pure indication on an imported subprogram unless an
8614 -- explicit Pure_Function pragma was present or the subprogram is an
8615 -- intrinsic. We do this because otherwise it is an insidious error
8616 -- to call a non-pure function from pure unit and have calls
8617 -- mysteriously optimized away. What happens here is that the Import
8618 -- can bypass the normal check to ensure that pure units call only pure
8621 -- The reason for the intrinsic exception is that in general, intrinsic
8622 -- functions (such as shifts) are pure anyway. The only exceptions are
8623 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
8624 -- in any case, so no problem arises.
8627 and then Is_Pure
(E
)
8628 and then not Has_Pragma_Pure_Function
(E
)
8629 and then not Is_Intrinsic_Subprogram
(E
)
8631 Set_Is_Pure
(E
, False);
8634 -- We also reset the Pure indication on a subprogram with an Address
8635 -- parameter, because the parameter may be used as a pointer and the
8636 -- referenced data may change even if the address value does not.
8638 -- Note that if the programmer gave an explicit Pure_Function pragma,
8639 -- then we believe the programmer, and leave the subprogram Pure. We
8640 -- also suppress this check on run-time files.
8643 and then Is_Subprogram
(E
)
8644 and then not Has_Pragma_Pure_Function
(E
)
8645 and then not Is_Internal_Unit
(Current_Sem_Unit
)
8647 Check_Function_With_Address_Parameter
(E
);
8650 -- Ensure that all anonymous access-to-subprogram types inherit the
8651 -- convention of their related subprogram (RM 6.3.1 13.1/3). This is
8652 -- not done for a defaulted convention Ada because those types also
8653 -- default to Ada. Convention Protected must not be propagated when
8654 -- the subprogram is an entry because this would be illegal. The only
8655 -- way to force convention Protected on these kinds of types is to
8656 -- include keyword "protected" in the access definition.
8658 if Convention
(E
) /= Convention_Ada
8659 and then Convention
(E
) /= Convention_Protected
8661 Set_Profile_Convention
(E
);
8664 -- For non-foreign convention subprograms, this is where we create
8665 -- the extra formals (for accessibility level and constrained bit
8666 -- information). We delay this till the freeze point precisely so
8667 -- that we know the convention.
8669 if not Has_Foreign_Convention
(E
) then
8670 if No
(Extra_Formals
(E
)) then
8671 Create_Extra_Formals
(E
);
8676 -- If this is convention Ada and a Valued_Procedure, that's odd
8678 if Ekind
(E
) = E_Procedure
8679 and then Is_Valued_Procedure
(E
)
8680 and then Convention
(E
) = Convention_Ada
8681 and then Warn_On_Export_Import
8684 ("??Valued_Procedure has no effect for convention Ada", E
);
8685 Set_Is_Valued_Procedure
(E
, False);
8688 -- Case of foreign convention
8693 -- For foreign conventions, warn about return of unconstrained array
8695 if Ekind
(E
) = E_Function
then
8696 Retype
:= Underlying_Type
(Etype
(E
));
8698 -- If no return type, probably some other error, e.g. a
8699 -- missing full declaration, so ignore.
8704 -- If the return type is generic, we have emitted a warning
8705 -- earlier on, and there is nothing else to check here. Specific
8706 -- instantiations may lead to erroneous behavior.
8708 elsif Is_Generic_Type
(Etype
(E
)) then
8711 -- Display warning if returning unconstrained array
8713 elsif Is_Array_Type
(Retype
)
8714 and then not Is_Constrained
(Retype
)
8716 -- Check appropriate warning is enabled (should we check for
8717 -- Warnings (Off) on specific entities here, probably so???)
8719 and then Warn_On_Export_Import
8722 ("?x?foreign convention function& should not return " &
8723 "unconstrained array", E
);
8728 -- If any of the formals for an exported foreign convention
8729 -- subprogram have defaults, then emit an appropriate warning since
8730 -- this is odd (default cannot be used from non-Ada code)
8732 if Is_Exported
(E
) then
8733 F
:= First_Formal
(E
);
8734 while Present
(F
) loop
8735 if Warn_On_Export_Import
8736 and then Present
(Default_Value
(F
))
8739 ("?x?parameter cannot be defaulted in non-Ada call",
8748 -- Pragma Inline_Always is disallowed for dispatching subprograms
8749 -- because the address of such subprograms is saved in the dispatch
8750 -- table to support dispatching calls, and dispatching calls cannot
8751 -- be inlined. This is consistent with the restriction against using
8752 -- 'Access or 'Address on an Inline_Always subprogram.
8754 if Is_Dispatching_Operation
(E
)
8755 and then Has_Pragma_Inline_Always
(E
)
8758 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
8761 -- Because of the implicit representation of inherited predefined
8762 -- operators in the front-end, the overriding status of the operation
8763 -- may be affected when a full view of a type is analyzed, and this is
8764 -- not captured by the analysis of the corresponding type declaration.
8765 -- Therefore the correctness of a not-overriding indicator must be
8766 -- rechecked when the subprogram is frozen.
8768 if Nkind
(E
) = N_Defining_Operator_Symbol
8769 and then not Error_Posted
(Parent
(E
))
8771 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
8774 if Modify_Tree_For_C
8775 and then Nkind
(Parent
(E
)) = N_Function_Specification
8776 and then Is_Array_Type
(Etype
(E
))
8777 and then Is_Constrained
(Etype
(E
))
8778 and then not Is_Unchecked_Conversion_Instance
(E
)
8779 and then not Rewritten_For_C
(E
)
8781 Build_Procedure_Form
(Unit_Declaration_Node
(E
));
8783 end Freeze_Subprogram
;
8785 ----------------------
8786 -- Is_Fully_Defined --
8787 ----------------------
8789 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
8791 if Ekind
(T
) = E_Class_Wide_Type
then
8792 return Is_Fully_Defined
(Etype
(T
));
8794 elsif Is_Array_Type
(T
) then
8795 return Is_Fully_Defined
(Component_Type
(T
));
8797 elsif Is_Record_Type
(T
)
8798 and not Is_Private_Type
(T
)
8800 -- Verify that the record type has no components with private types
8801 -- without completion.
8807 Comp
:= First_Component
(T
);
8808 while Present
(Comp
) loop
8809 if not Is_Fully_Defined
(Etype
(Comp
)) then
8813 Next_Component
(Comp
);
8818 -- For the designated type of an access to subprogram, all types in
8819 -- the profile must be fully defined.
8821 elsif Ekind
(T
) = E_Subprogram_Type
then
8826 F
:= First_Formal
(T
);
8827 while Present
(F
) loop
8828 if not Is_Fully_Defined
(Etype
(F
)) then
8835 return Is_Fully_Defined
(Etype
(T
));
8839 return not Is_Private_Type
(T
)
8840 or else Present
(Full_View
(Base_Type
(T
)));
8842 end Is_Fully_Defined
;
8844 ---------------------------------
8845 -- Process_Default_Expressions --
8846 ---------------------------------
8848 procedure Process_Default_Expressions
8850 After
: in out Node_Id
)
8852 Loc
: constant Source_Ptr
:= Sloc
(E
);
8859 Set_Default_Expressions_Processed
(E
);
8861 -- A subprogram instance and its associated anonymous subprogram share
8862 -- their signature. The default expression functions are defined in the
8863 -- wrapper packages for the anonymous subprogram, and should not be
8864 -- generated again for the instance.
8866 if Is_Generic_Instance
(E
)
8867 and then Present
(Alias
(E
))
8868 and then Default_Expressions_Processed
(Alias
(E
))
8873 Formal
:= First_Formal
(E
);
8874 while Present
(Formal
) loop
8875 if Present
(Default_Value
(Formal
)) then
8877 -- We work with a copy of the default expression because we
8878 -- do not want to disturb the original, since this would mess
8879 -- up the conformance checking.
8881 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
8883 -- The analysis of the expression may generate insert actions,
8884 -- which of course must not be executed. We wrap those actions
8885 -- in a procedure that is not called, and later on eliminated.
8886 -- The following cases have no side effects, and are analyzed
8889 if Nkind
(Dcopy
) = N_Identifier
8890 or else Nkind_In
(Dcopy
, N_Expanded_Name
,
8892 N_Character_Literal
,
8895 or else (Nkind
(Dcopy
) = N_Attribute_Reference
8896 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
8897 or else Known_Null
(Dcopy
)
8899 -- If there is no default function, we must still do a full
8900 -- analyze call on the default value, to ensure that all error
8901 -- checks are performed, e.g. those associated with static
8902 -- evaluation. Note: this branch will always be taken if the
8903 -- analyzer is turned off (but we still need the error checks).
8905 -- Note: the setting of parent here is to meet the requirement
8906 -- that we can only analyze the expression while attached to
8907 -- the tree. Really the requirement is that the parent chain
8908 -- be set, we don't actually need to be in the tree.
8910 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
8913 -- Default expressions are resolved with their own type if the
8914 -- context is generic, to avoid anomalies with private types.
8916 if Ekind
(Scope
(E
)) = E_Generic_Package
then
8919 Resolve
(Dcopy
, Etype
(Formal
));
8922 -- If that resolved expression will raise constraint error,
8923 -- then flag the default value as raising constraint error.
8924 -- This allows a proper error message on the calls.
8926 if Raises_Constraint_Error
(Dcopy
) then
8927 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
8930 -- If the default is a parameterless call, we use the name of
8931 -- the called function directly, and there is no body to build.
8933 elsif Nkind
(Dcopy
) = N_Function_Call
8934 and then No
(Parameter_Associations
(Dcopy
))
8938 -- Else construct and analyze the body of a wrapper procedure
8939 -- that contains an object declaration to hold the expression.
8940 -- Given that this is done only to complete the analysis, it is
8941 -- simpler to build a procedure than a function which might
8942 -- involve secondary stack expansion.
8945 Dnam
:= Make_Temporary
(Loc
, 'D');
8948 Make_Subprogram_Body
(Loc
,
8950 Make_Procedure_Specification
(Loc
,
8951 Defining_Unit_Name
=> Dnam
),
8953 Declarations
=> New_List
(
8954 Make_Object_Declaration
(Loc
,
8955 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
8956 Object_Definition
=>
8957 New_Occurrence_Of
(Etype
(Formal
), Loc
),
8958 Expression
=> New_Copy_Tree
(Dcopy
))),
8960 Handled_Statement_Sequence
=>
8961 Make_Handled_Sequence_Of_Statements
(Loc
,
8962 Statements
=> Empty_List
));
8964 Set_Scope
(Dnam
, Scope
(E
));
8965 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
8966 Set_Is_Eliminated
(Dnam
);
8967 Insert_After
(After
, Dbody
);
8973 Next_Formal
(Formal
);
8975 end Process_Default_Expressions
;
8977 ----------------------------------------
8978 -- Set_Component_Alignment_If_Not_Set --
8979 ----------------------------------------
8981 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
8983 -- Ignore if not base type, subtypes don't need anything
8985 if Typ
/= Base_Type
(Typ
) then
8989 -- Do not override existing representation
8991 if Is_Packed
(Typ
) then
8994 elsif Has_Specified_Layout
(Typ
) then
8997 elsif Component_Alignment
(Typ
) /= Calign_Default
then
9001 Set_Component_Alignment
9002 (Typ
, Scope_Stack
.Table
9003 (Scope_Stack
.Last
).Component_Alignment_Default
);
9005 end Set_Component_Alignment_If_Not_Set
;
9007 --------------------------
9008 -- Set_SSO_From_Default --
9009 --------------------------
9011 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
9015 -- Set default SSO for an array or record base type, except in case of
9016 -- a type extension (which always inherits the SSO of its parent type).
9019 and then (Is_Array_Type
(T
)
9020 or else (Is_Record_Type
(T
)
9021 and then not (Is_Tagged_Type
(T
)
9022 and then Is_Derived_Type
(T
))))
9025 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
9027 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
9029 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
9031 -- For a record type, if bit order is specified explicitly,
9032 -- then do not set SSO from default if not consistent. Note that
9033 -- we do not want to look at a Bit_Order attribute definition
9034 -- for a parent: if we were to inherit Bit_Order, then both
9035 -- SSO_Set_*_By_Default flags would have been cleared already
9036 -- (by Inherit_Aspects_At_Freeze_Point).
9041 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
9042 and then Reverse_Bit_Order
(T
) /= Reversed
)
9044 -- If flags cause reverse storage order, then set the result. Note
9045 -- that we would have ignored the pragma setting the non default
9046 -- storage order in any case, hence the assertion at this point.
9049 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
9051 Set_Reverse_Storage_Order
(T
, Reversed
);
9053 -- For a record type, also set reversed bit order. Note: if a bit
9054 -- order has been specified explicitly, then this is a no-op.
9056 if Is_Record_Type
(T
) then
9057 Set_Reverse_Bit_Order
(T
, Reversed
);
9061 end Set_SSO_From_Default
;
9067 procedure Undelay_Type
(T
: Entity_Id
) is
9069 Set_Has_Delayed_Freeze
(T
, False);
9070 Set_Freeze_Node
(T
, Empty
);
9072 -- Since we don't want T to have a Freeze_Node, we don't want its
9073 -- Full_View or Corresponding_Record_Type to have one either.
9075 -- ??? Fundamentally, this whole handling is unpleasant. What we really
9076 -- want is to be sure that for an Itype that's part of record R and is a
9077 -- subtype of type T, that it's frozen after the later of the freeze
9078 -- points of R and T. We have no way of doing that directly, so what we
9079 -- do is force most such Itypes to be frozen as part of freezing R via
9080 -- this procedure and only delay the ones that need to be delayed
9081 -- (mostly the designated types of access types that are defined as part
9084 if Is_Private_Type
(T
)
9085 and then Present
(Full_View
(T
))
9086 and then Is_Itype
(Full_View
(T
))
9087 and then Is_Record_Type
(Scope
(Full_View
(T
)))
9089 Undelay_Type
(Full_View
(T
));
9092 if Is_Concurrent_Type
(T
)
9093 and then Present
(Corresponding_Record_Type
(T
))
9094 and then Is_Itype
(Corresponding_Record_Type
(T
))
9095 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
9097 Undelay_Type
(Corresponding_Record_Type
(T
));
9105 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Entity_Id
) is
9106 Ent
: constant Entity_Id
:= Entity
(Nam
);
9107 -- The object to which the address clause applies
9110 Old
: Entity_Id
:= Empty
;
9114 -- No warning if address clause overlay warnings are off
9116 if not Address_Clause_Overlay_Warnings
then
9120 -- No warning if there is an explicit initialization
9122 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
9124 if Present
(Init
) and then Comes_From_Source
(Init
) then
9128 -- We only give the warning for non-imported entities of a type for
9129 -- which a non-null base init proc is defined, or for objects of access
9130 -- types with implicit null initialization, or when Normalize_Scalars
9131 -- applies and the type is scalar or a string type (the latter being
9132 -- tested for because predefined String types are initialized by inline
9133 -- code rather than by an init_proc). Note that we do not give the
9134 -- warning for Initialize_Scalars, since we suppressed initialization
9135 -- in this case. Also, do not warn if Suppress_Initialization is set
9136 -- either on the type, or on the object via pragma or aspect.
9139 and then not Is_Imported
(Ent
)
9140 and then not Initialization_Suppressed
(Typ
)
9141 and then not (Ekind
(Ent
) = E_Variable
9142 and then Initialization_Suppressed
(Ent
))
9143 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
9144 or else Is_Access_Type
(Typ
)
9145 or else (Normalize_Scalars
9146 and then (Is_Scalar_Type
(Typ
)
9147 or else Is_String_Type
(Typ
))))
9149 if Nkind
(Expr
) = N_Attribute_Reference
9150 and then Is_Entity_Name
(Prefix
(Expr
))
9152 Old
:= Entity
(Prefix
(Expr
));
9154 elsif Is_Entity_Name
(Expr
)
9155 and then Ekind
(Entity
(Expr
)) = E_Constant
9157 Decl
:= Declaration_Node
(Entity
(Expr
));
9159 if Nkind
(Decl
) = N_Object_Declaration
9160 and then Present
(Expression
(Decl
))
9161 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
9162 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
9164 Old
:= Entity
(Prefix
(Expression
(Decl
)));
9166 elsif Nkind
(Expr
) = N_Function_Call
then
9170 -- A function call (most likely to To_Address) is probably not an
9171 -- overlay, so skip warning. Ditto if the function call was inlined
9172 -- and transformed into an entity.
9174 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
9178 -- If a pragma Import follows, we assume that it is for the current
9179 -- target of the address clause, and skip the warning. There may be
9180 -- a source pragma or an aspect that specifies import and generates
9181 -- the corresponding pragma. These will indicate that the entity is
9182 -- imported and that is checked above so that the spurious warning
9183 -- (generated when the entity is frozen) will be suppressed. The
9184 -- pragma may be attached to the aspect, so it is not yet a list
9187 if Is_List_Member
(Parent
(Expr
)) then
9188 Decl
:= Next
(Parent
(Expr
));
9191 and then Nkind
(Decl
) = N_Pragma
9192 and then Pragma_Name
(Decl
) = Name_Import
9198 -- Otherwise give warning message
9200 if Present
(Old
) then
9201 Error_Msg_Node_2
:= Old
;
9203 ("default initialization of & may modify &??",
9207 ("default initialization of & may modify overlaid storage??",
9211 -- Add friendly warning if initialization comes from a packed array
9214 if Is_Record_Type
(Typ
) then
9219 Comp
:= First_Component
(Typ
);
9220 while Present
(Comp
) loop
9221 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
9222 and then Present
(Expression
(Parent
(Comp
)))
9225 elsif Is_Array_Type
(Etype
(Comp
))
9226 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
9229 ("\packed array component& " &
9230 "will be initialized to zero??",
9234 Next_Component
(Comp
);
9241 ("\use pragma Import for & to " &
9242 "suppress initialization (RM B.1(24))??",