1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Ch3
; use Exp_Ch3
;
34 with Exp_Ch7
; use Exp_Ch7
;
35 with Exp_Disp
; use Exp_Disp
;
36 with Exp_Pakd
; use Exp_Pakd
;
37 with Exp_Util
; use Exp_Util
;
38 with Exp_Tss
; use Exp_Tss
;
39 with Fname
; use Fname
;
40 with Ghost
; use Ghost
;
41 with Layout
; use Layout
;
43 with Namet
; use Namet
;
44 with Nlists
; use Nlists
;
45 with Nmake
; use Nmake
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
51 with Sem_Aux
; use Sem_Aux
;
52 with Sem_Cat
; use Sem_Cat
;
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_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
);
112 -- When an expression function is frozen by a use of it, the expression
113 -- itself is frozen. Check that the expression does not include references
114 -- to deferred constants without completion. We report this at the freeze
115 -- point of the function, to provide a better error message.
117 -- In most cases the expression itself is frozen by the time the function
118 -- itself is frozen, because the formals will be frozen by then. However,
119 -- Attribute references to outer types are freeze points for those types;
120 -- this routine generates the required freeze nodes for them.
122 procedure Check_Strict_Alignment
(E
: Entity_Id
);
123 -- E is a base type. If E is tagged or has a component that is aliased
124 -- or tagged or contains something this is aliased or tagged, set
127 procedure Check_Unsigned_Type
(E
: Entity_Id
);
128 pragma Inline
(Check_Unsigned_Type
);
129 -- If E is a fixed-point or discrete type, then all the necessary work
130 -- to freeze it is completed except for possible setting of the flag
131 -- Is_Unsigned_Type, which is done by this procedure. The call has no
132 -- effect if the entity E is not a discrete or fixed-point type.
134 procedure Freeze_And_Append
137 Result
: in out List_Id
);
138 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
139 -- nodes to Result, modifying Result from No_List if necessary. N has
140 -- the same usage as in Freeze_Entity.
142 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
143 -- Freeze enumeration type. The Esize field is set as processing
144 -- proceeds (i.e. set by default when the type is declared and then
145 -- adjusted by rep clauses. What this procedure does is to make sure
146 -- that if a foreign convention is specified, and no specific size
147 -- is given, then the size must be at least Integer'Size.
149 procedure Freeze_Static_Object
(E
: Entity_Id
);
150 -- If an object is frozen which has Is_Statically_Allocated set, then
151 -- all referenced types must also be marked with this flag. This routine
152 -- is in charge of meeting this requirement for the object entity E.
154 procedure Freeze_Subprogram
(E
: Entity_Id
);
155 -- Perform freezing actions for a subprogram (create extra formals,
156 -- and set proper default mechanism values). Note that this routine
157 -- is not called for internal subprograms, for which neither of these
158 -- actions is needed (or desirable, we do not want for example to have
159 -- these extra formals present in initialization procedures, where they
160 -- would serve no purpose). In this call E is either a subprogram or
161 -- a subprogram type (i.e. an access to a subprogram).
163 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
164 -- True if T is not private and has no private components, or has a full
165 -- view. Used to determine whether the designated type of an access type
166 -- should be frozen when the access type is frozen. This is done when an
167 -- allocator is frozen, or an expression that may involve attributes of
168 -- the designated type. Otherwise freezing the access type does not freeze
169 -- the designated type.
171 procedure Process_Default_Expressions
173 After
: in out Node_Id
);
174 -- This procedure is called for each subprogram to complete processing of
175 -- default expressions at the point where all types are known to be frozen.
176 -- The expressions must be analyzed in full, to make sure that all error
177 -- processing is done (they have only been pre-analyzed). If the expression
178 -- is not an entity or literal, its analysis may generate code which must
179 -- not be executed. In that case we build a function body to hold that
180 -- code. This wrapper function serves no other purpose (it used to be
181 -- called to evaluate the default, but now the default is inlined at each
184 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
185 -- Typ is a record or array type that is being frozen. This routine sets
186 -- the default component alignment from the scope stack values if the
187 -- alignment is otherwise not specified.
189 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
190 -- As each entity is frozen, this routine is called to deal with the
191 -- setting of Debug_Info_Needed for the entity. This flag is set if
192 -- the entity comes from source, or if we are in Debug_Generated_Code
193 -- mode or if the -gnatdV debug flag is set. However, it never sets
194 -- the flag if Debug_Info_Off is set. This procedure also ensures that
195 -- subsidiary entities have the flag set as required.
197 procedure Set_SSO_From_Default
(T
: Entity_Id
);
198 -- T is a record or array type that is being frozen. If it is a base type,
199 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
200 -- will be set appropriately. Note that an explicit occurrence of aspect
201 -- Scalar_Storage_Order or an explicit setting of this aspect with an
202 -- attribute definition clause occurs, then these two flags are reset in
203 -- any case, so call will have no effect.
205 procedure Undelay_Type
(T
: Entity_Id
);
206 -- T is a type of a component that we know to be an Itype. We don't want
207 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
208 -- Full_View or Corresponding_Record_Type.
210 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
);
211 -- Expr is the expression for an address clause for entity Nam whose type
212 -- is Typ. If Typ has a default initialization, and there is no explicit
213 -- initialization in the source declaration, check whether the address
214 -- clause might cause overlaying of an entity, and emit a warning on the
215 -- side effect that the initialization will cause.
217 -------------------------------
218 -- Adjust_Esize_For_Alignment --
219 -------------------------------
221 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
225 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
226 Align
:= Alignment_In_Bits
(Typ
);
228 if Align
> Esize
(Typ
)
229 and then Align
<= Standard_Long_Long_Integer_Size
231 Set_Esize
(Typ
, Align
);
234 end Adjust_Esize_For_Alignment
;
236 ------------------------------------
237 -- Build_And_Analyze_Renamed_Body --
238 ------------------------------------
240 procedure Build_And_Analyze_Renamed_Body
243 After
: in out Node_Id
)
245 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
246 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
248 Renamed_Subp
: Entity_Id
;
251 -- If the renamed subprogram is intrinsic, there is no need for a
252 -- wrapper body: we set the alias that will be called and expanded which
253 -- completes the declaration. This transformation is only legal if the
254 -- renamed entity has already been elaborated.
256 -- Note that it is legal for a renaming_as_body to rename an intrinsic
257 -- subprogram, as long as the renaming occurs before the new entity
258 -- is frozen (RM 8.5.4 (5)).
260 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
261 and then Is_Entity_Name
(Name
(Body_Decl
))
263 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
265 Renamed_Subp
:= Empty
;
268 if Present
(Renamed_Subp
)
269 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
271 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
272 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
274 -- We can make the renaming entity intrinsic if the renamed function
275 -- has an interface name, or if it is one of the shift/rotate
276 -- operations known to the compiler.
279 (Present
(Interface_Name
(Renamed_Subp
))
280 or else Nam_In
(Chars
(Renamed_Subp
), Name_Rotate_Left
,
284 Name_Shift_Right_Arithmetic
))
286 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
288 if Present
(Alias
(Renamed_Subp
)) then
289 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
291 Set_Alias
(Ent
, Renamed_Subp
);
294 Set_Is_Intrinsic_Subprogram
(Ent
);
295 Set_Has_Completion
(Ent
);
298 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
299 Insert_After
(After
, Body_Node
);
300 Mark_Rewrite_Insertion
(Body_Node
);
304 end Build_And_Analyze_Renamed_Body
;
306 ------------------------
307 -- Build_Renamed_Body --
308 ------------------------
310 function Build_Renamed_Body
312 New_S
: Entity_Id
) return Node_Id
314 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
315 -- We use for the source location of the renamed body, the location of
316 -- the spec entity. It might seem more natural to use the location of
317 -- the renaming declaration itself, but that would be wrong, since then
318 -- the body we create would look as though it was created far too late,
319 -- and this could cause problems with elaboration order analysis,
320 -- particularly in connection with instantiations.
322 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
323 Nam
: constant Node_Id
:= Name
(N
);
325 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
326 Actuals
: List_Id
:= No_List
;
331 O_Formal
: Entity_Id
;
332 Param_Spec
: Node_Id
;
334 Pref
: Node_Id
:= Empty
;
335 -- If the renamed entity is a primitive operation given in prefix form,
336 -- the prefix is the target object and it has to be added as the first
337 -- actual in the generated call.
340 -- Determine the entity being renamed, which is the target of the call
341 -- statement. If the name is an explicit dereference, this is a renaming
342 -- of a subprogram type rather than a subprogram. The name itself is
345 if Nkind
(Nam
) = N_Selected_Component
then
346 Old_S
:= Entity
(Selector_Name
(Nam
));
348 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
349 Old_S
:= Etype
(Nam
);
351 elsif Nkind
(Nam
) = N_Indexed_Component
then
352 if Is_Entity_Name
(Prefix
(Nam
)) then
353 Old_S
:= Entity
(Prefix
(Nam
));
355 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
358 elsif Nkind
(Nam
) = N_Character_Literal
then
359 Old_S
:= Etype
(New_S
);
362 Old_S
:= Entity
(Nam
);
365 if Is_Entity_Name
(Nam
) then
367 -- If the renamed entity is a predefined operator, retain full name
368 -- to ensure its visibility.
370 if Ekind
(Old_S
) = E_Operator
371 and then Nkind
(Nam
) = N_Expanded_Name
373 Call_Name
:= New_Copy
(Name
(N
));
375 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
379 if Nkind
(Nam
) = N_Selected_Component
380 and then Present
(First_Formal
(Old_S
))
382 (Is_Controlling_Formal
(First_Formal
(Old_S
))
383 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
386 -- Retrieve the target object, to be added as a first actual
389 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
390 Pref
:= Prefix
(Nam
);
393 Call_Name
:= New_Copy
(Name
(N
));
396 -- Original name may have been overloaded, but is fully resolved now
398 Set_Is_Overloaded
(Call_Name
, False);
401 -- For simple renamings, subsequent calls can be expanded directly as
402 -- calls to the renamed entity. The body must be generated in any case
403 -- for calls that may appear elsewhere. This is not done in the case
404 -- where the subprogram is an instantiation because the actual proper
405 -- body has not been built yet.
407 if Ekind_In
(Old_S
, E_Function
, E_Procedure
)
408 and then Nkind
(Decl
) = N_Subprogram_Declaration
409 and then not Is_Generic_Instance
(Old_S
)
411 Set_Body_To_Inline
(Decl
, Old_S
);
414 -- Check whether the return type is a limited view. If the subprogram
415 -- is already frozen the generated body may have a non-limited view
416 -- of the type, that must be used, because it is the one in the spec
417 -- of the renaming declaration.
419 if Ekind
(Old_S
) = E_Function
420 and then Is_Entity_Name
(Result_Definition
(Spec
))
423 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
425 if Has_Non_Limited_View
(Ret_Type
) then
426 Set_Result_Definition
427 (Spec
, New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
432 -- The body generated for this renaming is an internal artifact, and
433 -- does not constitute a freeze point for the called entity.
435 Set_Must_Not_Freeze
(Call_Name
);
437 Formal
:= First_Formal
(Defining_Entity
(Decl
));
439 if Present
(Pref
) then
441 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
442 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
445 -- The controlling formal may be an access parameter, or the
446 -- actual may be an access value, so adjust accordingly.
448 if Is_Access_Type
(Pref_Type
)
449 and then not Is_Access_Type
(Form_Type
)
452 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
454 elsif Is_Access_Type
(Form_Type
)
455 and then not Is_Access_Type
(Pref
)
459 Make_Attribute_Reference
(Loc
,
460 Attribute_Name
=> Name_Access
,
461 Prefix
=> Relocate_Node
(Pref
)));
463 Actuals
:= New_List
(Pref
);
467 elsif Present
(Formal
) then
474 if Present
(Formal
) then
475 while Present
(Formal
) loop
476 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
477 Next_Formal
(Formal
);
481 -- If the renamed entity is an entry, inherit its profile. For other
482 -- renamings as bodies, both profiles must be subtype conformant, so it
483 -- is not necessary to replace the profile given in the declaration.
484 -- However, default values that are aggregates are rewritten when
485 -- partially analyzed, so we recover the original aggregate to insure
486 -- that subsequent conformity checking works. Similarly, if the default
487 -- expression was constant-folded, recover the original expression.
489 Formal
:= First_Formal
(Defining_Entity
(Decl
));
491 if Present
(Formal
) then
492 O_Formal
:= First_Formal
(Old_S
);
493 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
494 while Present
(Formal
) loop
495 if Is_Entry
(Old_S
) then
496 if Nkind
(Parameter_Type
(Param_Spec
)) /=
499 Set_Etype
(Formal
, Etype
(O_Formal
));
500 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
503 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
504 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
505 Nkind
(Default_Value
(O_Formal
))
507 Set_Expression
(Param_Spec
,
508 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
511 Next_Formal
(Formal
);
512 Next_Formal
(O_Formal
);
517 -- If the renamed entity is a function, the generated body contains a
518 -- return statement. Otherwise, build a procedure call. If the entity is
519 -- an entry, subsequent analysis of the call will transform it into the
520 -- proper entry or protected operation call. If the renamed entity is
521 -- a character literal, return it directly.
523 if Ekind
(Old_S
) = E_Function
524 or else Ekind
(Old_S
) = E_Operator
525 or else (Ekind
(Old_S
) = E_Subprogram_Type
526 and then Etype
(Old_S
) /= Standard_Void_Type
)
529 Make_Simple_Return_Statement
(Loc
,
531 Make_Function_Call
(Loc
,
533 Parameter_Associations
=> Actuals
));
535 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
537 Make_Simple_Return_Statement
(Loc
,
538 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
540 elsif Nkind
(Nam
) = N_Character_Literal
then
542 Make_Simple_Return_Statement
(Loc
, Expression
=> Call_Name
);
546 Make_Procedure_Call_Statement
(Loc
,
548 Parameter_Associations
=> Actuals
);
551 -- Create entities for subprogram body and formals
553 Set_Defining_Unit_Name
(Spec
,
554 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
556 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
557 while Present
(Param_Spec
) loop
558 Set_Defining_Identifier
(Param_Spec
,
559 Make_Defining_Identifier
(Loc
,
560 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
565 Make_Subprogram_Body
(Loc
,
566 Specification
=> Spec
,
567 Declarations
=> New_List
,
568 Handled_Statement_Sequence
=>
569 Make_Handled_Sequence_Of_Statements
(Loc
,
570 Statements
=> New_List
(Call_Node
)));
572 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
574 Make_Subprogram_Declaration
(Loc
,
575 Specification
=> Specification
(N
)));
578 -- Link the body to the entity whose declaration it completes. If
579 -- the body is analyzed when the renamed entity is frozen, it may
580 -- be necessary to restore the proper scope (see package Exp_Ch13).
582 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
583 and then Present
(Corresponding_Spec
(N
))
585 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
587 Set_Corresponding_Spec
(Body_Node
, New_S
);
591 end Build_Renamed_Body
;
593 --------------------------
594 -- Check_Address_Clause --
595 --------------------------
597 procedure Check_Address_Clause
(E
: Entity_Id
) is
598 Addr
: constant Node_Id
:= Address_Clause
(E
);
599 Typ
: constant Entity_Id
:= Etype
(E
);
604 Tag_Assign
: Node_Id
;
607 if Present
(Addr
) then
609 -- For a deferred constant, the initialization value is on full view
611 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
612 Decl
:= Declaration_Node
(Full_View
(E
));
614 Decl
:= Declaration_Node
(E
);
617 Expr
:= Expression
(Addr
);
619 if Needs_Constant_Address
(Decl
, Typ
) then
620 Check_Constant_Address_Clause
(Expr
, E
);
622 -- Has_Delayed_Freeze was set on E when the address clause was
623 -- analyzed, and must remain set because we want the address
624 -- clause to be elaborated only after any entity it references
625 -- has been elaborated.
628 -- If Rep_Clauses are to be ignored, remove address clause from
629 -- list attached to entity, because it may be illegal for gigi,
630 -- for example by breaking order of elaboration..
632 if Ignore_Rep_Clauses
then
637 Rep
:= First_Rep_Item
(E
);
640 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
644 and then Next_Rep_Item
(Rep
) /= Addr
646 Rep
:= Next_Rep_Item
(Rep
);
650 if Present
(Rep
) then
651 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
655 -- And now remove the address clause
657 Kill_Rep_Clause
(Addr
);
659 elsif not Error_Posted
(Expr
)
660 and then not Needs_Finalization
(Typ
)
662 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
665 Init
:= Expression
(Decl
);
667 -- If a variable, or a non-imported constant, overlays a constant
668 -- object and has an initialization value, then the initialization
669 -- may end up writing into read-only memory. Detect the cases of
670 -- statically identical values and remove the initialization. In
671 -- the other cases, give a warning. We will give other warnings
672 -- later for the variable if it is assigned.
674 if (Ekind
(E
) = E_Variable
675 or else (Ekind
(E
) = E_Constant
676 and then not Is_Imported
(E
)))
677 and then Overlays_Constant
(E
)
678 and then Present
(Init
)
685 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
687 if Ekind
(O_Ent
) = E_Constant
688 and then Etype
(O_Ent
) = Typ
689 and then Present
(Constant_Value
(O_Ent
))
690 and then Compile_Time_Compare
692 Constant_Value
(O_Ent
),
693 Assume_Valid
=> True) = EQ
695 Set_No_Initialization
(Decl
);
698 elsif Comes_From_Source
(Init
)
699 and then Address_Clause_Overlay_Warnings
701 Error_Msg_Sloc
:= Sloc
(Addr
);
703 ("??constant& may be modified via address clause#",
709 if Present
(Init
) then
711 -- Capture initialization value at point of declaration,
712 -- and make explicit assignment legal, because object may
715 Remove_Side_Effects
(Init
);
716 Lhs
:= New_Occurrence_Of
(E
, Sloc
(Decl
));
717 Set_Assignment_OK
(Lhs
);
719 -- Move initialization to freeze actions, once the object has
720 -- been frozen and the address clause alignment check has been
723 Append_Freeze_Action
(E
,
724 Make_Assignment_Statement
(Sloc
(Decl
),
726 Expression
=> Expression
(Decl
)));
728 Set_No_Initialization
(Decl
);
730 -- If the objet is tagged, check whether the tag must be
731 -- reassigned explicitly.
733 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
734 if Present
(Tag_Assign
) then
735 Append_Freeze_Action
(E
, Tag_Assign
);
739 end Check_Address_Clause
;
741 -----------------------------
742 -- Check_Compile_Time_Size --
743 -----------------------------
745 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
747 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
748 -- Sets the compile time known size (64 bits or less) in the RM_Size
749 -- field of T, checking for a size clause that was given which attempts
750 -- to give a smaller size.
752 function Size_Known
(T
: Entity_Id
) return Boolean;
753 -- Recursive function that does all the work
755 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
756 -- If T is a constrained subtype, its size is not known if any of its
757 -- discriminant constraints is not static and it is not a null record.
758 -- The test is conservative and doesn't check that the components are
759 -- in fact constrained by non-static discriminant values. Could be made
766 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
771 -- Check for bad size clause given
773 elsif Has_Size_Clause
(T
) then
774 if RM_Size
(T
) < S
then
775 Error_Msg_Uint_1
:= S
;
777 ("size for& too small, minimum allowed is ^",
781 -- Set size if not set already
783 elsif Unknown_RM_Size
(T
) then
792 function Size_Known
(T
: Entity_Id
) return Boolean is
800 if Size_Known_At_Compile_Time
(T
) then
803 -- Always True for elementary types, even generic formal elementary
804 -- types. We used to return False in the latter case, but the size
805 -- is known at compile time, even in the template, we just do not
806 -- know the exact size but that's not the point of this routine.
808 elsif Is_Elementary_Type
(T
) or else Is_Task_Type
(T
) then
813 elsif Is_Array_Type
(T
) then
815 -- String literals always have known size, and we can set it
817 if Ekind
(T
) = E_String_Literal_Subtype
then
819 (T
, Component_Size
(T
) * String_Literal_Length
(T
));
822 -- Unconstrained types never have known at compile time size
824 elsif not Is_Constrained
(T
) then
827 -- Don't do any recursion on type with error posted, since we may
828 -- have a malformed type that leads us into a loop.
830 elsif Error_Posted
(T
) then
833 -- Otherwise if component size unknown, then array size unknown
835 elsif not Size_Known
(Component_Type
(T
)) then
839 -- Check for all indexes static, and also compute possible size
840 -- (in case it is not greater than 64 and may be packable).
843 Size
: Uint
:= Component_Size
(T
);
847 Index
:= First_Index
(T
);
848 while Present
(Index
) loop
849 if Nkind
(Index
) = N_Range
then
850 Get_Index_Bounds
(Index
, Low
, High
);
852 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
856 Low
:= Type_Low_Bound
(Etype
(Index
));
857 High
:= Type_High_Bound
(Etype
(Index
));
860 if not Compile_Time_Known_Value
(Low
)
861 or else not Compile_Time_Known_Value
(High
)
862 or else Etype
(Index
) = Any_Type
867 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
879 Set_Small_Size
(T
, Size
);
883 -- For non-generic private types, go to underlying type if present
885 elsif Is_Private_Type
(T
)
886 and then not Is_Generic_Type
(T
)
887 and then Present
(Underlying_Type
(T
))
889 -- Don't do any recursion on type with error posted, since we may
890 -- have a malformed type that leads us into a loop.
892 if Error_Posted
(T
) then
895 return Size_Known
(Underlying_Type
(T
));
900 elsif Is_Record_Type
(T
) then
902 -- A class-wide type is never considered to have a known size
904 if Is_Class_Wide_Type
(T
) then
907 -- A subtype of a variant record must not have non-static
908 -- discriminated components.
910 elsif T
/= Base_Type
(T
)
911 and then not Static_Discriminated_Components
(T
)
915 -- Don't do any recursion on type with error posted, since we may
916 -- have a malformed type that leads us into a loop.
918 elsif Error_Posted
(T
) then
922 -- Now look at the components of the record
925 -- The following two variables are used to keep track of the
926 -- size of packed records if we can tell the size of the packed
927 -- record in the front end. Packed_Size_Known is True if so far
928 -- we can figure out the size. It is initialized to True for a
929 -- packed record, unless the record has discriminants or atomic
930 -- components or independent components.
932 -- The reason we eliminate the discriminated case is that
933 -- we don't know the way the back end lays out discriminated
934 -- packed records. If Packed_Size_Known is True, then
935 -- Packed_Size is the size in bits so far.
937 Packed_Size_Known
: Boolean :=
939 and then not Has_Discriminants
(T
)
940 and then not Has_Atomic_Components
(T
)
941 and then not Has_Independent_Components
(T
);
943 Packed_Size
: Uint
:= Uint_0
;
944 -- Size in bits so far
947 -- Test for variant part present
949 if Has_Discriminants
(T
)
950 and then Present
(Parent
(T
))
951 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
952 and then Nkind
(Type_Definition
(Parent
(T
))) =
954 and then not Null_Present
(Type_Definition
(Parent
(T
)))
956 Present
(Variant_Part
957 (Component_List
(Type_Definition
(Parent
(T
)))))
959 -- If variant part is present, and type is unconstrained,
960 -- then we must have defaulted discriminants, or a size
961 -- clause must be present for the type, or else the size
962 -- is definitely not known at compile time.
964 if not Is_Constrained
(T
)
966 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
967 and then Unknown_RM_Size
(T
)
973 -- Loop through components
975 Comp
:= First_Component_Or_Discriminant
(T
);
976 while Present
(Comp
) loop
977 Ctyp
:= Etype
(Comp
);
979 -- We do not know the packed size if there is a component
980 -- clause present (we possibly could, but this would only
981 -- help in the case of a record with partial rep clauses.
982 -- That's because in the case of full rep clauses, the
983 -- size gets figured out anyway by a different circuit).
985 if Present
(Component_Clause
(Comp
)) then
986 Packed_Size_Known
:= False;
989 -- We do not know the packed size for an atomic/VFA type
990 -- or component, or an independent type or component, or a
991 -- by-reference type or aliased component (because packing
992 -- does not touch these).
994 if Is_Atomic_Or_VFA
(Ctyp
)
995 or else Is_Atomic_Or_VFA
(Comp
)
996 or else Is_Independent
(Ctyp
)
997 or else Is_Independent
(Comp
)
998 or else Is_By_Reference_Type
(Ctyp
)
999 or else Is_Aliased
(Comp
)
1001 Packed_Size_Known
:= False;
1004 -- We need to identify a component that is an array where
1005 -- the index type is an enumeration type with non-standard
1006 -- representation, and some bound of the type depends on a
1009 -- This is because gigi computes the size by doing a
1010 -- substitution of the appropriate discriminant value in
1011 -- the size expression for the base type, and gigi is not
1012 -- clever enough to evaluate the resulting expression (which
1013 -- involves a call to rep_to_pos) at compile time.
1015 -- It would be nice if gigi would either recognize that
1016 -- this expression can be computed at compile time, or
1017 -- alternatively figured out the size from the subtype
1018 -- directly, where all the information is at hand ???
1020 if Is_Array_Type
(Etype
(Comp
))
1021 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1024 Ocomp
: constant Entity_Id
:=
1025 Original_Record_Component
(Comp
);
1026 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1032 Ind
:= First_Index
(OCtyp
);
1033 while Present
(Ind
) loop
1034 Indtyp
:= Etype
(Ind
);
1036 if Is_Enumeration_Type
(Indtyp
)
1037 and then Has_Non_Standard_Rep
(Indtyp
)
1039 Lo
:= Type_Low_Bound
(Indtyp
);
1040 Hi
:= Type_High_Bound
(Indtyp
);
1042 if Is_Entity_Name
(Lo
)
1043 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1047 elsif Is_Entity_Name
(Hi
)
1048 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1059 -- Clearly size of record is not known if the size of one of
1060 -- the components is not known.
1062 if not Size_Known
(Ctyp
) then
1066 -- Accumulate packed size if possible
1068 if Packed_Size_Known
then
1070 -- We can deal with elementary types, small packed arrays
1071 -- if the representation is a modular type and also small
1072 -- record types (if the size is not greater than 64, but
1073 -- the condition is checked by Set_Small_Size).
1075 if Is_Elementary_Type
(Ctyp
)
1076 or else (Is_Array_Type
(Ctyp
)
1078 (Packed_Array_Impl_Type
(Ctyp
))
1079 and then Is_Modular_Integer_Type
1080 (Packed_Array_Impl_Type
(Ctyp
)))
1081 or else Is_Record_Type
(Ctyp
)
1083 -- If RM_Size is known and static, then we can keep
1084 -- accumulating the packed size.
1086 if Known_Static_RM_Size
(Ctyp
) then
1088 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1090 -- If we have a field whose RM_Size is not known then
1091 -- we can't figure out the packed size here.
1094 Packed_Size_Known
:= False;
1097 -- For other types we can't figure out the packed size
1100 Packed_Size_Known
:= False;
1104 Next_Component_Or_Discriminant
(Comp
);
1107 if Packed_Size_Known
then
1108 Set_Small_Size
(T
, Packed_Size
);
1114 -- All other cases, size not known at compile time
1121 -------------------------------------
1122 -- Static_Discriminated_Components --
1123 -------------------------------------
1125 function Static_Discriminated_Components
1126 (T
: Entity_Id
) return Boolean
1128 Constraint
: Elmt_Id
;
1131 if Has_Discriminants
(T
)
1132 and then Present
(Discriminant_Constraint
(T
))
1133 and then Present
(First_Component
(T
))
1135 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1136 while Present
(Constraint
) loop
1137 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1141 Next_Elmt
(Constraint
);
1146 end Static_Discriminated_Components
;
1148 -- Start of processing for Check_Compile_Time_Size
1151 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1152 end Check_Compile_Time_Size
;
1154 -----------------------------------
1155 -- Check_Component_Storage_Order --
1156 -----------------------------------
1158 procedure Check_Component_Storage_Order
1159 (Encl_Type
: Entity_Id
;
1162 Comp_ADC_Present
: out Boolean)
1164 Comp_Base
: Entity_Id
;
1166 Encl_Base
: Entity_Id
;
1169 Component_Aliased
: Boolean;
1171 Comp_Byte_Aligned
: Boolean;
1172 -- Set for the record case, True if Comp starts on a byte boundary
1173 -- (in which case it is allowed to have different storage order).
1175 Comp_SSO_Differs
: Boolean;
1176 -- Set True when the component is a nested composite, and it does not
1177 -- have the same scalar storage order as Encl_Type.
1182 if Present
(Comp
) then
1184 Comp_Base
:= Etype
(Comp
);
1186 if Is_Tag
(Comp
) then
1187 Comp_Byte_Aligned
:= True;
1188 Component_Aliased
:= False;
1191 -- If a component clause is present, check if the component starts
1192 -- on a storage element boundary. Otherwise conservatively assume
1193 -- it does so only in the case where the record is not packed.
1195 if Present
(Component_Clause
(Comp
)) then
1196 Comp_Byte_Aligned
:=
1197 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1199 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1202 Component_Aliased
:= Is_Aliased
(Comp
);
1208 Err_Node
:= Encl_Type
;
1209 Comp_Base
:= Component_Type
(Encl_Type
);
1211 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1214 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1215 -- the attribute definition clause is attached to the first subtype.
1216 -- Also, if the base type is incomplete or private, go to full view
1219 Encl_Base
:= Base_Type
(Encl_Type
);
1220 if Present
(Underlying_Type
(Encl_Base
)) then
1221 Encl_Base
:= Underlying_Type
(Encl_Base
);
1224 Comp_Base
:= Base_Type
(Comp_Base
);
1225 if Present
(Underlying_Type
(Comp_Base
)) then
1226 Comp_Base
:= Underlying_Type
(Comp_Base
);
1230 Get_Attribute_Definition_Clause
1231 (First_Subtype
(Comp_Base
), Attribute_Scalar_Storage_Order
);
1232 Comp_ADC_Present
:= Present
(Comp_ADC
);
1234 -- Case of record or array component: check storage order compatibility.
1235 -- But, if the record has Complex_Representation, then it is treated as
1236 -- a scalar in the back end so the storage order is irrelevant.
1238 if (Is_Record_Type
(Comp_Base
)
1239 and then not Has_Complex_Representation
(Comp_Base
))
1240 or else Is_Array_Type
(Comp_Base
)
1243 Reverse_Storage_Order
(Encl_Base
) /=
1244 Reverse_Storage_Order
(Comp_Base
);
1246 -- Parent and extension must have same storage order
1248 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1249 if Comp_SSO_Differs
then
1251 ("record extension must have same scalar storage order as "
1252 & "parent", Err_Node
);
1255 -- If component and composite SSO differs, check that component
1256 -- falls on byte boundaries and isn't bit packed.
1258 elsif Comp_SSO_Differs
then
1260 -- Component SSO differs from enclosing composite:
1262 -- Reject if component is a bit-packed array, as it is represented
1263 -- as a scalar internally.
1265 if Is_Bit_Packed_Array
(Comp_Base
) then
1267 ("type of packed component must have same scalar storage "
1268 & "order as enclosing composite", Err_Node
);
1270 -- Reject if composite is a bit-packed array, as it is rewritten
1271 -- into an array of scalars.
1273 elsif Is_Bit_Packed_Array
(Encl_Base
) then
1275 ("type of packed array must have same scalar storage order "
1276 & "as component", Err_Node
);
1278 -- Reject if not byte aligned
1280 elsif Is_Record_Type
(Encl_Base
)
1281 and then not Comp_Byte_Aligned
1284 ("type of non-byte-aligned component must have same scalar "
1285 & "storage order as enclosing composite", Err_Node
);
1287 -- Warn if specified only for the outer composite
1289 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1291 ("scalar storage order specified for & does not apply to "
1292 & "component?", Err_Node
, Encl_Base
);
1296 -- Enclosing type has explicit SSO: non-composite component must not
1299 elsif Present
(ADC
) and then Component_Aliased
then
1301 ("aliased component not permitted for type with explicit "
1302 & "Scalar_Storage_Order", Err_Node
);
1304 end Check_Component_Storage_Order
;
1306 -----------------------------
1307 -- Check_Debug_Info_Needed --
1308 -----------------------------
1310 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1312 if Debug_Info_Off
(T
) then
1315 elsif Comes_From_Source
(T
)
1316 or else Debug_Generated_Code
1317 or else Debug_Flag_VV
1318 or else Needs_Debug_Info
(T
)
1320 Set_Debug_Info_Needed
(T
);
1322 end Check_Debug_Info_Needed
;
1324 -------------------------------
1325 -- Check_Expression_Function --
1326 -------------------------------
1328 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1331 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1332 -- Function to search for deferred constant
1338 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1340 -- When a constant is initialized with the result of a dispatching
1341 -- call, the constant declaration is rewritten as a renaming of the
1342 -- displaced function result. This scenario is not a premature use of
1343 -- a constant even though the Has_Completion flag is not set.
1345 if Is_Entity_Name
(Nod
)
1346 and then Present
(Entity
(Nod
))
1347 and then Ekind
(Entity
(Nod
)) = E_Constant
1348 and then Scope
(Entity
(Nod
)) = Current_Scope
1349 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1350 N_Object_Declaration
1351 and then not Is_Imported
(Entity
(Nod
))
1352 and then not Has_Completion
(Entity
(Nod
))
1355 ("premature use of& in call or instance", N
, Entity
(Nod
));
1357 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1358 Analyze
(Prefix
(Nod
));
1360 if Is_Entity_Name
(Prefix
(Nod
))
1361 and then Is_Type
(Entity
(Prefix
(Nod
)))
1363 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1370 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1372 -- Start of processing for Check_Expression_Function
1375 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1377 if Scope
(Nam
) = Current_Scope
1378 and then Nkind
(Decl
) = N_Expression_Function
1380 Check_Deferred
(Expression
(Decl
));
1382 end Check_Expression_Function
;
1384 ----------------------------
1385 -- Check_Strict_Alignment --
1386 ----------------------------
1388 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1392 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1393 Set_Strict_Alignment
(E
);
1395 elsif Is_Array_Type
(E
) then
1396 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1398 elsif Is_Record_Type
(E
) then
1399 if Is_Limited_Record
(E
) then
1400 Set_Strict_Alignment
(E
);
1404 Comp
:= First_Component
(E
);
1405 while Present
(Comp
) loop
1406 if not Is_Type
(Comp
)
1407 and then (Strict_Alignment
(Etype
(Comp
))
1408 or else Is_Aliased
(Comp
))
1410 Set_Strict_Alignment
(E
);
1414 Next_Component
(Comp
);
1417 end Check_Strict_Alignment
;
1419 -------------------------
1420 -- Check_Unsigned_Type --
1421 -------------------------
1423 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1424 Ancestor
: Entity_Id
;
1429 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1433 -- Do not attempt to analyze case where range was in error
1435 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
1439 -- The situation that is nontrivial is something like:
1441 -- subtype x1 is integer range -10 .. +10;
1442 -- subtype x2 is x1 range 0 .. V1;
1443 -- subtype x3 is x2 range V2 .. V3;
1444 -- subtype x4 is x3 range V4 .. V5;
1446 -- where Vn are variables. Here the base type is signed, but we still
1447 -- know that x4 is unsigned because of the lower bound of x2.
1449 -- The only way to deal with this is to look up the ancestor chain
1453 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1457 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1459 if Compile_Time_Known_Value
(Lo_Bound
) then
1460 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1461 Set_Is_Unsigned_Type
(E
, True);
1467 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1469 -- If no ancestor had a static lower bound, go to base type
1471 if No
(Ancestor
) then
1473 -- Note: the reason we still check for a compile time known
1474 -- value for the base type is that at least in the case of
1475 -- generic formals, we can have bounds that fail this test,
1476 -- and there may be other cases in error situations.
1478 Btyp
:= Base_Type
(E
);
1480 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1484 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1486 if Compile_Time_Known_Value
(Lo_Bound
)
1487 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1489 Set_Is_Unsigned_Type
(E
, True);
1496 end Check_Unsigned_Type
;
1498 -----------------------------
1499 -- Is_Atomic_VFA_Aggregate --
1500 -----------------------------
1502 function Is_Atomic_VFA_Aggregate
(N
: Node_Id
) return Boolean is
1503 Loc
: constant Source_Ptr
:= Sloc
(N
);
1512 -- Array may be qualified, so find outer context
1514 if Nkind
(Par
) = N_Qualified_Expression
then
1515 Par
:= Parent
(Par
);
1518 if not Comes_From_Source
(Par
) then
1523 when N_Assignment_Statement
=>
1524 Typ
:= Etype
(Name
(Par
));
1526 if not Is_Atomic_Or_VFA
(Typ
)
1527 and then not (Is_Entity_Name
(Name
(Par
))
1528 and then Is_Atomic_Or_VFA
(Entity
(Name
(Par
))))
1533 when N_Object_Declaration
=>
1534 Typ
:= Etype
(Defining_Identifier
(Par
));
1536 if not Is_Atomic_Or_VFA
(Typ
)
1537 and then not Is_Atomic_Or_VFA
(Defining_Identifier
(Par
))
1546 Temp
:= Make_Temporary
(Loc
, 'T', N
);
1548 Make_Object_Declaration
(Loc
,
1549 Defining_Identifier
=> Temp
,
1550 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1551 Expression
=> Relocate_Node
(N
));
1552 Insert_Before
(Par
, New_N
);
1555 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1557 end Is_Atomic_VFA_Aggregate
;
1559 -----------------------------------------------
1560 -- Explode_Initialization_Compound_Statement --
1561 -----------------------------------------------
1563 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
1564 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
1567 if Present
(Init_Stmts
)
1568 and then Nkind
(Init_Stmts
) = N_Compound_Statement
1570 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
1572 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
1573 -- just removing it, because Freeze_All may rely on this particular
1574 -- Node_Id still being present in the enclosing list to know where to
1577 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
1579 Set_Initialization_Statements
(E
, Empty
);
1581 end Explode_Initialization_Compound_Statement
;
1587 -- Note: the easy coding for this procedure would be to just build a
1588 -- single list of freeze nodes and then insert them and analyze them
1589 -- all at once. This won't work, because the analysis of earlier freeze
1590 -- nodes may recursively freeze types which would otherwise appear later
1591 -- on in the freeze list. So we must analyze and expand the freeze nodes
1592 -- as they are generated.
1594 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1598 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1599 -- This is the internal recursive routine that does freezing of entities
1600 -- (but NOT the analysis of default expressions, which should not be
1601 -- recursive, we don't want to analyze those till we are sure that ALL
1602 -- the types are frozen).
1604 --------------------
1605 -- Freeze_All_Ent --
1606 --------------------
1608 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1613 procedure Process_Flist
;
1614 -- If freeze nodes are present, insert and analyze, and reset cursor
1615 -- for next insertion.
1621 procedure Process_Flist
is
1623 if Is_Non_Empty_List
(Flist
) then
1624 Lastn
:= Next
(After
);
1625 Insert_List_After_And_Analyze
(After
, Flist
);
1627 if Present
(Lastn
) then
1628 After
:= Prev
(Lastn
);
1630 After
:= Last
(List_Containing
(After
));
1635 -- Start of processing for Freeze_All_Ent
1639 while Present
(E
) loop
1641 -- If the entity is an inner package which is not a package
1642 -- renaming, then its entities must be frozen at this point. Note
1643 -- that such entities do NOT get frozen at the end of the nested
1644 -- package itself (only library packages freeze).
1646 -- Same is true for task declarations, where anonymous records
1647 -- created for entry parameters must be frozen.
1649 if Ekind
(E
) = E_Package
1650 and then No
(Renamed_Object
(E
))
1651 and then not Is_Child_Unit
(E
)
1652 and then not Is_Frozen
(E
)
1655 Install_Visible_Declarations
(E
);
1656 Install_Private_Declarations
(E
);
1658 Freeze_All
(First_Entity
(E
), After
);
1660 End_Package_Scope
(E
);
1662 if Is_Generic_Instance
(E
)
1663 and then Has_Delayed_Freeze
(E
)
1665 Set_Has_Delayed_Freeze
(E
, False);
1666 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1669 elsif Ekind
(E
) in Task_Kind
1670 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1671 N_Single_Task_Declaration
)
1674 Freeze_All
(First_Entity
(E
), After
);
1677 -- For a derived tagged type, we must ensure that all the
1678 -- primitive operations of the parent have been frozen, so that
1679 -- their addresses will be in the parent's dispatch table at the
1680 -- point it is inherited.
1682 elsif Ekind
(E
) = E_Record_Type
1683 and then Is_Tagged_Type
(E
)
1684 and then Is_Tagged_Type
(Etype
(E
))
1685 and then Is_Derived_Type
(E
)
1688 Prim_List
: constant Elist_Id
:=
1689 Primitive_Operations
(Etype
(E
));
1695 Prim
:= First_Elmt
(Prim_List
);
1696 while Present
(Prim
) loop
1697 Subp
:= Node
(Prim
);
1699 if Comes_From_Source
(Subp
)
1700 and then not Is_Frozen
(Subp
)
1702 Flist
:= Freeze_Entity
(Subp
, After
);
1711 if not Is_Frozen
(E
) then
1712 Flist
:= Freeze_Entity
(E
, After
);
1715 -- If already frozen, and there are delayed aspects, this is where
1716 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1717 -- for a description of how we handle aspect visibility).
1719 elsif Has_Delayed_Aspects
(E
) then
1721 -- Retrieve the visibility to the discriminants in order to
1722 -- analyze properly the aspects.
1724 Push_Scope_And_Install_Discriminants
(E
);
1730 Ritem
:= First_Rep_Item
(E
);
1731 while Present
(Ritem
) loop
1732 if Nkind
(Ritem
) = N_Aspect_Specification
1733 and then Entity
(Ritem
) = E
1734 and then Is_Delayed_Aspect
(Ritem
)
1736 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1739 Ritem
:= Next_Rep_Item
(Ritem
);
1743 Uninstall_Discriminants_And_Pop_Scope
(E
);
1746 -- If an incomplete type is still not frozen, this may be a
1747 -- premature freezing because of a body declaration that follows.
1748 -- Indicate where the freezing took place. Freezing will happen
1749 -- if the body comes from source, but not if it is internally
1750 -- generated, for example as the body of a type invariant.
1752 -- If the freezing is caused by the end of the current declarative
1753 -- part, it is a Taft Amendment type, and there is no error.
1755 if not Is_Frozen
(E
)
1756 and then Ekind
(E
) = E_Incomplete_Type
1759 Bod
: constant Node_Id
:= Next
(After
);
1762 -- The presence of a body freezes all entities previously
1763 -- declared in the current list of declarations, but this
1764 -- does not apply if the body does not come from source.
1765 -- A type invariant is transformed into a subprogram body
1766 -- which is placed at the end of the private part of the
1767 -- current package, but this body does not freeze incomplete
1768 -- types that may be declared in this private part.
1770 if (Nkind_In
(Bod
, N_Subprogram_Body
,
1775 or else Nkind
(Bod
) in N_Body_Stub
)
1777 List_Containing
(After
) = List_Containing
(Parent
(E
))
1778 and then Comes_From_Source
(Bod
)
1780 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1782 ("type& is frozen# before its full declaration",
1792 -- Start of processing for Freeze_All
1795 Freeze_All_Ent
(From
, After
);
1797 -- Now that all types are frozen, we can deal with default expressions
1798 -- that require us to build a default expression functions. This is the
1799 -- point at which such functions are constructed (after all types that
1800 -- might be used in such expressions have been frozen).
1802 -- For subprograms that are renaming_as_body, we create the wrapper
1803 -- bodies as needed.
1805 -- We also add finalization chains to access types whose designated
1806 -- types are controlled. This is normally done when freezing the type,
1807 -- but this misses recursive type definitions where the later members
1808 -- of the recursion introduce controlled components.
1810 -- Loop through entities
1813 while Present
(E
) loop
1814 if Is_Subprogram
(E
) then
1815 if not Default_Expressions_Processed
(E
) then
1816 Process_Default_Expressions
(E
, After
);
1819 if not Has_Completion
(E
) then
1820 Decl
:= Unit_Declaration_Node
(E
);
1822 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1823 if Error_Posted
(Decl
) then
1824 Set_Has_Completion
(E
);
1826 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1829 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1830 and then Present
(Corresponding_Body
(Decl
))
1832 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1833 = N_Subprogram_Renaming_Declaration
1835 Build_And_Analyze_Renamed_Body
1836 (Decl
, Corresponding_Body
(Decl
), After
);
1840 elsif Ekind
(E
) in Task_Kind
1841 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1842 N_Single_Task_Declaration
)
1848 Ent
:= First_Entity
(E
);
1849 while Present
(Ent
) loop
1851 and then not Default_Expressions_Processed
(Ent
)
1853 Process_Default_Expressions
(Ent
, After
);
1861 -- Historical note: We used to create a finalization master for an
1862 -- access type whose designated type is not controlled, but contains
1863 -- private controlled compoments. This form of postprocessing is no
1864 -- longer needed because the finalization master is now created when
1865 -- the access type is frozen (see Exp_Ch3.Freeze_Type).
1871 -----------------------
1872 -- Freeze_And_Append --
1873 -----------------------
1875 procedure Freeze_And_Append
1878 Result
: in out List_Id
)
1880 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1882 if Is_Non_Empty_List
(L
) then
1883 if Result
= No_List
then
1886 Append_List
(L
, Result
);
1889 end Freeze_And_Append
;
1895 procedure Freeze_Before
1898 Do_Freeze_Profile
: Boolean := True)
1900 -- Freeze T, then insert the generated Freeze nodes before the node N.
1901 -- Flag Freeze_Profile is used when T is an overloadable entity, and
1902 -- indicates whether its profile should be frozen at the same time.
1904 Freeze_Nodes
: constant List_Id
:=
1905 Freeze_Entity
(T
, N
, Do_Freeze_Profile
);
1908 if Ekind
(T
) = E_Function
then
1909 Check_Expression_Function
(N
, T
);
1912 if Is_Non_Empty_List
(Freeze_Nodes
) then
1913 Insert_Actions
(N
, Freeze_Nodes
);
1921 function Freeze_Entity
1924 Do_Freeze_Profile
: Boolean := True) return List_Id
1926 Loc
: constant Source_Ptr
:= Sloc
(N
);
1933 Has_Default_Initialization
: Boolean := False;
1934 -- This flag gets set to true for a variable with default initialization
1936 Result
: List_Id
:= No_List
;
1937 -- List of freezing actions, left at No_List if none
1939 Test_E
: Entity_Id
:= E
;
1940 -- This could use a comment ???
1942 procedure Add_To_Result
(N
: Node_Id
);
1943 -- N is a freezing action to be appended to the Result
1945 function After_Last_Declaration
return Boolean;
1946 -- If Loc is a freeze_entity that appears after the last declaration
1947 -- in the scope, inhibit error messages on late completion.
1949 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1950 -- Check that an Access or Unchecked_Access attribute with a prefix
1951 -- which is the current instance type can only be applied when the type
1954 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1955 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1956 -- integer literal without an explicit corresponding size clause. The
1957 -- caller has checked that Utype is a modular integer type.
1959 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
1960 -- Freeze array type, including freezing index and component types
1962 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
1963 -- Perform checks and generate freeze node if needed for a constant or
1964 -- variable declared by an object declaration.
1966 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
1967 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1968 -- package. Recurse on inner generic packages.
1970 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
1971 -- Freeze formals and return type of subprogram. If some type in the
1972 -- profile is incomplete and we are in an instance, freezing of the
1973 -- entity will take place elsewhere, and the function returns False.
1975 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1976 -- Freeze record type, including freezing component types, and freezing
1977 -- primitive operations if this is a tagged type.
1979 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
1980 -- Determine whether an arbitrary entity is subject to Boolean aspect
1981 -- Import and its value is specified as True.
1983 function New_Freeze_Node
return Node_Id
;
1984 -- Create a new freeze node for entity E
1986 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
1987 -- If E is an entity for an imported subprogram with pre/post-conditions
1988 -- then this procedure will create a wrapper to ensure that proper run-
1989 -- time checking of the pre/postconditions. See body for details.
1995 procedure Add_To_Result
(N
: Node_Id
) is
1998 Result
:= New_List
(N
);
2004 ----------------------------
2005 -- After_Last_Declaration --
2006 ----------------------------
2008 function After_Last_Declaration
return Boolean is
2009 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2012 if Nkind
(Spec
) = N_Package_Specification
then
2013 if Present
(Private_Declarations
(Spec
)) then
2014 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2015 elsif Present
(Visible_Declarations
(Spec
)) then
2016 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2024 end After_Last_Declaration
;
2026 ----------------------------
2027 -- Check_Current_Instance --
2028 ----------------------------
2030 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2032 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2033 -- Determine whether Typ is compatible with the rules for aliased
2034 -- views of types as defined in RM 3.10 in the various dialects.
2036 function Process
(N
: Node_Id
) return Traverse_Result
;
2037 -- Process routine to apply check to given node
2039 -----------------------------
2040 -- Is_Aliased_View_Of_Type --
2041 -----------------------------
2043 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
2044 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
2049 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
2050 and then Limited_Present
(Type_Definition
(Typ_Decl
))
2054 -- The following paragraphs describe what a legal aliased view of
2055 -- a type is in the various dialects of Ada.
2059 -- The current instance of a limited type, and a formal parameter
2060 -- or generic formal object of a tagged type.
2062 -- Ada 95 limited type
2063 -- * Type with reserved word "limited"
2064 -- * A protected or task type
2065 -- * A composite type with limited component
2067 elsif Ada_Version
<= Ada_95
then
2068 return Is_Limited_Type
(Typ
);
2072 -- The current instance of a limited tagged type, a protected
2073 -- type, a task type, or a type that has the reserved word
2074 -- "limited" in its full definition ... a formal parameter or
2075 -- generic formal object of a tagged type.
2077 -- Ada 2005 limited type
2078 -- * Type with reserved word "limited", "synchronized", "task"
2080 -- * A composite type with limited component
2081 -- * A derived type whose parent is a non-interface limited type
2083 elsif Ada_Version
= Ada_2005
then
2085 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2087 (Is_Derived_Type
(Typ
)
2088 and then not Is_Interface
(Etype
(Typ
))
2089 and then Is_Limited_Type
(Etype
(Typ
)));
2091 -- Ada 2012 and beyond
2093 -- The current instance of an immutably limited type ... a formal
2094 -- parameter or generic formal object of a tagged type.
2096 -- Ada 2012 limited type
2097 -- * Type with reserved word "limited", "synchronized", "task"
2099 -- * A composite type with limited component
2100 -- * A derived type whose parent is a non-interface limited type
2101 -- * An incomplete view
2103 -- Ada 2012 immutably limited type
2104 -- * Explicitly limited record type
2105 -- * Record extension with "limited" present
2106 -- * Non-formal limited private type that is either tagged
2107 -- or has at least one access discriminant with a default
2109 -- * Task type, protected type or synchronized interface
2110 -- * Type derived from immutably limited type
2114 Is_Immutably_Limited_Type
(Typ
)
2115 or else Is_Incomplete_Type
(Typ
);
2117 end Is_Aliased_View_Of_Type
;
2123 function Process
(N
: Node_Id
) return Traverse_Result
is
2126 when N_Attribute_Reference
=>
2127 if Nam_In
(Attribute_Name
(N
), Name_Access
,
2128 Name_Unchecked_Access
)
2129 and then Is_Entity_Name
(Prefix
(N
))
2130 and then Is_Type
(Entity
(Prefix
(N
)))
2131 and then Entity
(Prefix
(N
)) = E
2133 if Ada_Version
< Ada_2012
then
2135 ("current instance must be a limited type",
2139 ("current instance must be an immutably limited "
2140 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2149 when others => return OK
;
2153 procedure Traverse
is new Traverse_Proc
(Process
);
2157 Rec_Type
: constant Entity_Id
:=
2158 Scope
(Defining_Identifier
(Comp_Decl
));
2160 -- Start of processing for Check_Current_Instance
2163 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2164 Traverse
(Comp_Decl
);
2166 end Check_Current_Instance
;
2168 ------------------------------
2169 -- Check_Suspicious_Modulus --
2170 ------------------------------
2172 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
2173 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
2176 if not Warn_On_Suspicious_Modulus_Value
then
2180 if Nkind
(Decl
) = N_Full_Type_Declaration
then
2182 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
2185 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
2187 Modulus
: constant Node_Id
:=
2188 Original_Node
(Expression
(Tdef
));
2191 if Nkind
(Modulus
) = N_Integer_Literal
then
2193 Modv
: constant Uint
:= Intval
(Modulus
);
2194 Sizv
: constant Uint
:= RM_Size
(Utype
);
2197 -- First case, modulus and size are the same. This
2198 -- happens if you have something like mod 32, with
2199 -- an explicit size of 32, this is for sure a case
2200 -- where the warning is given, since it is seems
2201 -- very unlikely that someone would want e.g. a
2202 -- five bit type stored in 32 bits. It is much
2203 -- more likely they wanted a 32-bit type.
2208 -- Second case, the modulus is 32 or 64 and no
2209 -- size clause is present. This is a less clear
2210 -- case for giving the warning, but in the case
2211 -- of 32/64 (5-bit or 6-bit types) these seem rare
2212 -- enough that it is a likely error (and in any
2213 -- case using 2**5 or 2**6 in these cases seems
2214 -- clearer. We don't include 8 or 16 here, simply
2215 -- because in practice 3-bit and 4-bit types are
2216 -- more common and too many false positives if
2217 -- we warn in these cases.
2219 elsif not Has_Size_Clause
(Utype
)
2220 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
2224 -- No warning needed
2230 -- If we fall through, give warning
2232 Error_Msg_Uint_1
:= Modv
;
2234 ("?M?2 '*'*^' may have been intended here",
2242 end Check_Suspicious_Modulus
;
2244 -----------------------
2245 -- Freeze_Array_Type --
2246 -----------------------
2248 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2249 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2250 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2253 Non_Standard_Enum
: Boolean := False;
2254 -- Set true if any of the index types is an enumeration type with a
2255 -- non-standard representation.
2258 Freeze_And_Append
(Ctyp
, N
, Result
);
2260 Indx
:= First_Index
(Arr
);
2261 while Present
(Indx
) loop
2262 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2264 if Is_Enumeration_Type
(Etype
(Indx
))
2265 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2267 Non_Standard_Enum
:= True;
2273 -- Processing that is done only for base types
2275 if Ekind
(Arr
) = E_Array_Type
then
2277 -- Deal with default setting of reverse storage order
2279 Set_SSO_From_Default
(Arr
);
2281 -- Propagate flags for component type
2283 if Is_Controlled_Active
(Component_Type
(Arr
))
2284 or else Has_Controlled_Component
(Ctyp
)
2286 Set_Has_Controlled_Component
(Arr
);
2289 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2290 Set_Has_Unchecked_Union
(Arr
);
2293 -- Warn for pragma Pack overriding foreign convention
2295 if Has_Foreign_Convention
(Ctyp
)
2296 and then Has_Pragma_Pack
(Arr
)
2299 CN
: constant Name_Id
:=
2300 Get_Convention_Name
(Convention
(Ctyp
));
2301 PP
: constant Node_Id
:=
2302 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2304 if Present
(PP
) then
2305 Error_Msg_Name_1
:= CN
;
2306 Error_Msg_Sloc
:= Sloc
(Arr
);
2308 ("pragma Pack affects convention % components #??", PP
);
2309 Error_Msg_Name_1
:= CN
;
2311 ("\array components may not have % compatible "
2312 & "representation??", PP
);
2317 -- If packing was requested or if the component size was
2318 -- set explicitly, then see if bit packing is required. This
2319 -- processing is only done for base types, since all of the
2320 -- representation aspects involved are type-related.
2322 -- This is not just an optimization, if we start processing the
2323 -- subtypes, they interfere with the settings on the base type
2324 -- (this is because Is_Packed has a slightly different meaning
2325 -- before and after freezing).
2332 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2333 and then Known_Static_RM_Size
(Ctyp
)
2334 and then not Has_Component_Size_Clause
(Arr
)
2336 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2338 elsif Known_Component_Size
(Arr
) then
2339 Csiz
:= Component_Size
(Arr
);
2341 elsif not Known_Static_Esize
(Ctyp
) then
2345 Esiz
:= Esize
(Ctyp
);
2347 -- We can set the component size if it is less than 16,
2348 -- rounding it up to the next storage unit size.
2352 elsif Esiz
<= 16 then
2358 -- Set component size up to match alignment if it would
2359 -- otherwise be less than the alignment. This deals with
2360 -- cases of types whose alignment exceeds their size (the
2361 -- padded type cases).
2365 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2374 -- Case of component size that may result in bit packing
2376 if 1 <= Csiz
and then Csiz
<= 64 then
2378 Ent
: constant Entity_Id
:=
2379 First_Subtype
(Arr
);
2380 Pack_Pragma
: constant Node_Id
:=
2381 Get_Rep_Pragma
(Ent
, Name_Pack
);
2382 Comp_Size_C
: constant Node_Id
:=
2383 Get_Attribute_Definition_Clause
2384 (Ent
, Attribute_Component_Size
);
2387 -- Warn if we have pack and component size so that the
2390 -- Note: here we must check for the presence of a
2391 -- component size before checking for a Pack pragma to
2392 -- deal with the case where the array type is a derived
2393 -- type whose parent is currently private.
2395 if Present
(Comp_Size_C
)
2396 and then Has_Pragma_Pack
(Ent
)
2397 and then Warn_On_Redundant_Constructs
2399 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2401 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2403 ("\?r?explicit component size given#!", Pack_Pragma
);
2404 Set_Is_Packed
(Base_Type
(Ent
), False);
2405 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2408 -- Set component size if not already set by a component
2411 if not Present
(Comp_Size_C
) then
2412 Set_Component_Size
(Arr
, Csiz
);
2415 -- Check for base type of 8, 16, 32 bits, where an
2416 -- unsigned subtype has a length one less than the
2417 -- base type (e.g. Natural subtype of Integer).
2419 -- In such cases, if a component size was not set
2420 -- explicitly, then generate a warning.
2422 if Has_Pragma_Pack
(Arr
)
2423 and then not Present
(Comp_Size_C
)
2424 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2425 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2427 Error_Msg_Uint_1
:= Csiz
;
2429 if Present
(Pack_Pragma
) then
2431 ("??pragma Pack causes component size to be ^!",
2434 ("\??use Component_Size to set desired value!",
2439 -- Bit packing is never needed for 8, 16, 32, 64
2441 if Addressable
(Csiz
) then
2442 -- If the Esize of the component is known and equal to
2443 -- the component size then even packing is not needed.
2445 if Known_Static_Esize
(Component_Type
(Arr
))
2446 and then Esize
(Component_Type
(Arr
)) = Csiz
2448 -- Here the array was requested to be packed, but
2449 -- the packing request had no effect whatsoever,
2450 -- so flag Is_Packed is reset.
2452 -- Note: semantically this means that we lose track
2453 -- of the fact that a derived type inherited pragma
2454 -- Pack that was non-effective, but that is fine.
2456 -- We regard a Pack pragma as a request to set a
2457 -- representation characteristic, and this request
2460 Set_Is_Packed
(Base_Type
(Arr
), False);
2461 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
2463 Set_Is_Packed
(Base_Type
(Arr
), True);
2464 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2467 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2469 -- Bit packing is not needed for multiples of the storage
2470 -- unit if the type is composite because the back end can
2471 -- byte pack composite types.
2473 elsif Csiz
mod System_Storage_Unit
= 0
2474 and then Is_Composite_Type
(Ctyp
)
2477 Set_Is_Packed
(Base_Type
(Arr
), True);
2478 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2479 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2481 -- In all other cases, bit packing is needed
2484 Set_Is_Packed
(Base_Type
(Arr
), True);
2485 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2486 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2492 -- Check for Aliased or Atomic_Components/Atomic/VFA with
2493 -- unsuitable packing or explicit component size clause given.
2495 if (Has_Aliased_Components
(Arr
)
2496 or else Has_Atomic_Components
(Arr
)
2497 or else Is_Atomic_Or_VFA
(Ctyp
))
2499 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2501 Alias_Atomic_Check
: declare
2503 procedure Complain_CS
(T
: String);
2504 -- Outputs error messages for incorrect CS clause or pragma
2505 -- Pack for aliased or atomic/VFA components (T is "aliased"
2506 -- or "atomic/vfa");
2512 procedure Complain_CS
(T
: String) is
2514 if Has_Component_Size_Clause
(Arr
) then
2516 Get_Attribute_Definition_Clause
2517 (FS
, Attribute_Component_Size
);
2520 ("incorrect component size for "
2521 & T
& " components", Clause
);
2522 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2524 ("\only allowed value is^", Clause
);
2528 ("cannot pack " & T
& " components",
2529 Get_Rep_Pragma
(FS
, Name_Pack
));
2533 -- Start of processing for Alias_Atomic_Check
2536 -- If object size of component type isn't known, we cannot
2537 -- be sure so we defer to the back end.
2539 if not Known_Static_Esize
(Ctyp
) then
2542 -- Case where component size has no effect. First check for
2543 -- object size of component type multiple of the storage
2546 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2548 -- OK in both packing case and component size case if RM
2549 -- size is known and static and same as the object size.
2552 ((Known_Static_RM_Size
(Ctyp
)
2553 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2555 -- Or if we have an explicit component size clause and
2556 -- the component size and object size are equal.
2559 (Has_Component_Size_Clause
(Arr
)
2560 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2564 elsif Has_Aliased_Components
(Arr
) then
2565 Complain_CS
("aliased");
2567 elsif Has_Atomic_Components
(Arr
)
2568 or else Is_Atomic
(Ctyp
)
2570 Complain_CS
("atomic");
2572 elsif Is_Volatile_Full_Access
(Ctyp
) then
2573 Complain_CS
("volatile full access");
2575 end Alias_Atomic_Check
;
2578 -- Check for Independent_Components/Independent with unsuitable
2579 -- packing or explicit component size clause given.
2581 if (Has_Independent_Components
(Arr
) or else Is_Independent
(Ctyp
))
2583 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2586 -- If object size of component type isn't known, we cannot
2587 -- be sure so we defer to the back end.
2589 if not Known_Static_Esize
(Ctyp
) then
2592 -- Case where component size has no effect. First check for
2593 -- object size of component type multiple of the storage
2596 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2598 -- OK in both packing case and component size case if RM
2599 -- size is known and multiple of the storage unit size.
2602 ((Known_Static_RM_Size
(Ctyp
)
2603 and then RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
2605 -- Or if we have an explicit component size clause and
2606 -- the component size is larger than the object size.
2609 (Has_Component_Size_Clause
(Arr
)
2610 and then Component_Size
(Arr
) >= Esize
(Ctyp
)))
2615 if Has_Component_Size_Clause
(Arr
) then
2617 Get_Attribute_Definition_Clause
2618 (FS
, Attribute_Component_Size
);
2621 ("incorrect component size for "
2622 & "independent components", Clause
);
2623 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2625 ("\minimum allowed is^", Clause
);
2629 ("cannot pack independent components",
2630 Get_Rep_Pragma
(FS
, Name_Pack
));
2636 -- Warn for case of atomic type
2638 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2641 and then not Addressable
(Component_Size
(FS
))
2644 ("non-atomic components of type& may not be "
2645 & "accessible by separate tasks??", Clause
, Arr
);
2647 if Has_Component_Size_Clause
(Arr
) then
2648 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2649 (FS
, Attribute_Component_Size
));
2650 Error_Msg_N
("\because of component size clause#??", Clause
);
2652 elsif Has_Pragma_Pack
(Arr
) then
2653 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2654 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2658 -- Check for scalar storage order
2663 Check_Component_Storage_Order
2666 ADC
=> Get_Attribute_Definition_Clause
2667 (First_Subtype
(Arr
),
2668 Attribute_Scalar_Storage_Order
),
2669 Comp_ADC_Present
=> Dummy
);
2672 -- Processing that is done only for subtypes
2675 -- Acquire alignment from base type
2677 if Unknown_Alignment
(Arr
) then
2678 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2679 Adjust_Esize_Alignment
(Arr
);
2683 -- Specific checks for bit-packed arrays
2685 if Is_Bit_Packed_Array
(Arr
) then
2687 -- Check number of elements for bit packed arrays that come from
2688 -- source and have compile time known ranges. The bit-packed
2689 -- arrays circuitry does not support arrays with more than
2690 -- Integer'Last + 1 elements, and when this restriction is
2691 -- violated, causes incorrect data access.
2693 -- For the case where this is not compile time known, a run-time
2694 -- check should be generated???
2696 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
2705 Index
:= First_Index
(Arr
);
2706 while Present
(Index
) loop
2707 Ityp
:= Etype
(Index
);
2709 -- Never generate an error if any index is of a generic
2710 -- type. We will check this in instances.
2712 if Is_Generic_Type
(Ityp
) then
2718 Make_Attribute_Reference
(Loc
,
2719 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2720 Attribute_Name
=> Name_Range_Length
);
2721 Analyze_And_Resolve
(Ilen
);
2723 -- No attempt is made to check number of elements if not
2724 -- compile time known.
2726 if Nkind
(Ilen
) /= N_Integer_Literal
then
2731 Elmts
:= Elmts
* Intval
(Ilen
);
2735 if Elmts
> Intval
(High_Bound
2736 (Scalar_Range
(Standard_Integer
))) + 1
2739 ("bit packed array type may not have "
2740 & "more than Integer''Last+1 elements", Arr
);
2747 if Known_RM_Size
(Arr
) then
2749 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
2753 -- It is not clear if it is possible to have no size clause
2754 -- at this stage, but it is not worth worrying about. Post
2755 -- error on the entity name in the size clause if present,
2756 -- else on the type entity itself.
2758 if Present
(SizC
) then
2759 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
2761 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
2767 -- If any of the index types was an enumeration type with a non-
2768 -- standard rep clause, then we indicate that the array type is
2769 -- always packed (even if it is not bit packed).
2771 if Non_Standard_Enum
then
2772 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
2773 Set_Is_Packed
(Base_Type
(Arr
));
2776 Set_Component_Alignment_If_Not_Set
(Arr
);
2778 -- If the array is packed and bit packed or packed to eliminate holes
2779 -- in the non-contiguous enumeration index types, we must create the
2780 -- packed array type to be used to actually implement the type. This
2781 -- is only needed for real array types (not for string literal types,
2782 -- since they are present only for the front end).
2785 and then (Is_Bit_Packed_Array
(Arr
) or else Non_Standard_Enum
)
2786 and then Ekind
(Arr
) /= E_String_Literal_Subtype
2788 Create_Packed_Array_Impl_Type
(Arr
);
2789 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
2791 -- Make sure that we have the necessary routines to implement the
2792 -- packing, and complain now if not. Note that we only test this
2793 -- for constrained array types.
2795 if Is_Constrained
(Arr
)
2796 and then Is_Bit_Packed_Array
(Arr
)
2797 and then Present
(Packed_Array_Impl_Type
(Arr
))
2798 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
2801 CS
: constant Uint
:= Component_Size
(Arr
);
2802 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
2806 and then not RTE_Available
(RE
)
2809 ("packing of " & UI_Image
(CS
) & "-bit components",
2810 First_Subtype
(Etype
(Arr
)));
2812 -- Cancel the packing
2814 Set_Is_Packed
(Base_Type
(Arr
), False);
2815 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2816 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
2822 -- Size information of packed array type is copied to the array
2823 -- type, since this is really the representation. But do not
2824 -- override explicit existing size values. If the ancestor subtype
2825 -- is constrained the Packed_Array_Impl_Type will be inherited
2826 -- from it, but the size may have been provided already, and
2827 -- must not be overridden either.
2829 if not Has_Size_Clause
(Arr
)
2831 (No
(Ancestor_Subtype
(Arr
))
2832 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
2834 Set_Esize
(Arr
, Esize
(Packed_Array_Impl_Type
(Arr
)));
2835 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Impl_Type
(Arr
)));
2838 if not Has_Alignment_Clause
(Arr
) then
2839 Set_Alignment
(Arr
, Alignment
(Packed_Array_Impl_Type
(Arr
)));
2845 -- For non-packed arrays set the alignment of the array to the
2846 -- alignment of the component type if it is unknown. Skip this
2847 -- in atomic/VFA case (atomic/VFA arrays may need larger alignments).
2849 if not Is_Packed
(Arr
)
2850 and then Unknown_Alignment
(Arr
)
2851 and then Known_Alignment
(Ctyp
)
2852 and then Known_Static_Component_Size
(Arr
)
2853 and then Known_Static_Esize
(Ctyp
)
2854 and then Esize
(Ctyp
) = Component_Size
(Arr
)
2855 and then not Is_Atomic_Or_VFA
(Arr
)
2857 Set_Alignment
(Arr
, Alignment
(Component_Type
(Arr
)));
2860 -- A Ghost type cannot have a component of protected or task type
2861 -- (SPARK RM 6.9(19)).
2863 if Is_Ghost_Entity
(Arr
) and then Is_Concurrent_Type
(Ctyp
) then
2865 ("ghost array type & cannot have concurrent component type",
2868 end Freeze_Array_Type
;
2870 -------------------------------
2871 -- Freeze_Object_Declaration --
2872 -------------------------------
2874 procedure Freeze_Object_Declaration
(E
: Entity_Id
) is
2876 -- Abstract type allowed only for C++ imported variables or constants
2878 -- Note: we inhibit this check for objects that do not come from
2879 -- source because there is at least one case (the expansion of
2880 -- x'Class'Input where x is abstract) where we legitimately
2881 -- generate an abstract object.
2883 if Is_Abstract_Type
(Etype
(E
))
2884 and then Comes_From_Source
(Parent
(E
))
2885 and then not (Is_Imported
(E
) and then Is_CPP_Class
(Etype
(E
)))
2887 Error_Msg_N
("type of object cannot be abstract",
2888 Object_Definition
(Parent
(E
)));
2890 if Is_CPP_Class
(Etype
(E
)) then
2892 ("\} may need a cpp_constructor",
2893 Object_Definition
(Parent
(E
)), Etype
(E
));
2895 elsif Present
(Expression
(Parent
(E
))) then
2896 Error_Msg_N
-- CODEFIX
2897 ("\maybe a class-wide type was meant",
2898 Object_Definition
(Parent
(E
)));
2902 -- For object created by object declaration, perform required
2903 -- categorization (preelaborate and pure) checks. Defer these
2904 -- checks to freeze time since pragma Import inhibits default
2905 -- initialization and thus pragma Import affects these checks.
2907 Validate_Object_Declaration
(Declaration_Node
(E
));
2909 -- If there is an address clause, check that it is valid
2910 -- and if need be move initialization to the freeze node.
2912 Check_Address_Clause
(E
);
2914 -- Similar processing is needed for aspects that may affect
2915 -- object layout, like Alignment, if there is an initialization
2918 if Has_Delayed_Aspects
(E
)
2919 and then Expander_Active
2920 and then Is_Array_Type
(Etype
(E
))
2921 and then Present
(Expression
(Parent
(E
)))
2924 Decl
: constant Node_Id
:= Parent
(E
);
2925 Lhs
: constant Node_Id
:= New_Occurrence_Of
(E
, Loc
);
2929 -- Capture initialization value at point of declaration, and
2930 -- make explicit assignment legal, because object may be a
2933 Remove_Side_Effects
(Expression
(Decl
));
2934 Set_Assignment_OK
(Lhs
);
2936 -- Move initialization to freeze actions.
2938 Append_Freeze_Action
(E
,
2939 Make_Assignment_Statement
(Loc
,
2941 Expression
=> Expression
(Decl
)));
2943 Set_No_Initialization
(Decl
);
2944 -- Set_Is_Frozen (E, False);
2948 -- Reset Is_True_Constant for non-constant aliased object. We
2949 -- consider that the fact that a non-constant object is aliased may
2950 -- indicate that some funny business is going on, e.g. an aliased
2951 -- object is passed by reference to a procedure which captures the
2952 -- address of the object, which is later used to assign a new value,
2953 -- even though the compiler thinks that it is not modified. Such
2954 -- code is highly dubious, but we choose to make it "work" for
2955 -- non-constant aliased objects.
2957 -- Note that we used to do this for all aliased objects, whether or
2958 -- not constant, but this caused anomalies down the line because we
2959 -- ended up with static objects that were not Is_True_Constant. Not
2960 -- resetting Is_True_Constant for (aliased) constant objects ensures
2961 -- that this anomaly never occurs.
2963 -- However, we don't do that for internal entities. We figure that if
2964 -- we deliberately set Is_True_Constant for an internal entity, e.g.
2965 -- a dispatch table entry, then we mean it.
2967 if Ekind
(E
) /= E_Constant
2968 and then (Is_Aliased
(E
) or else Is_Aliased
(Etype
(E
)))
2969 and then not Is_Internal_Name
(Chars
(E
))
2971 Set_Is_True_Constant
(E
, False);
2974 -- If the object needs any kind of default initialization, an error
2975 -- must be issued if No_Default_Initialization applies. The check
2976 -- doesn't apply to imported objects, which are not ever default
2977 -- initialized, and is why the check is deferred until freezing, at
2978 -- which point we know if Import applies. Deferred constants are also
2979 -- exempted from this test because their completion is explicit, or
2980 -- through an import pragma.
2982 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
2985 elsif Comes_From_Source
(E
)
2986 and then not Is_Imported
(E
)
2987 and then not Has_Init_Expression
(Declaration_Node
(E
))
2989 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
2990 and then not No_Initialization
(Declaration_Node
(E
))
2991 and then not Initialization_Suppressed
(Etype
(E
)))
2993 (Needs_Simple_Initialization
(Etype
(E
))
2994 and then not Is_Internal
(E
)))
2996 Has_Default_Initialization
:= True;
2998 (No_Default_Initialization
, Declaration_Node
(E
));
3001 -- Check that a Thread_Local_Storage variable does not have
3002 -- default initialization, and any explicit initialization must
3003 -- either be the null constant or a static constant.
3005 if Has_Pragma_Thread_Local_Storage
(E
) then
3007 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3009 if Has_Default_Initialization
3011 (Has_Init_Expression
(Decl
)
3013 (No
(Expression
(Decl
))
3015 (Is_OK_Static_Expression
(Expression
(Decl
))
3016 or else Nkind
(Expression
(Decl
)) = N_Null
)))
3019 ("Thread_Local_Storage variable& is "
3020 & "improperly initialized", Decl
, E
);
3022 ("\only allowed initialization is explicit "
3023 & "NULL or static expression", Decl
, E
);
3028 -- For imported objects, set Is_Public unless there is also an
3029 -- address clause, which means that there is no external symbol
3030 -- needed for the Import (Is_Public may still be set for other
3031 -- unrelated reasons). Note that we delayed this processing
3032 -- till freeze time so that we can be sure not to set the flag
3033 -- if there is an address clause. If there is such a clause,
3034 -- then the only purpose of the Import pragma is to suppress
3035 -- implicit initialization.
3037 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
3041 -- For source objects that are not Imported and are library
3042 -- level, if no linker section pragma was given inherit the
3043 -- appropriate linker section from the corresponding type.
3045 if Comes_From_Source
(E
)
3046 and then not Is_Imported
(E
)
3047 and then Is_Library_Level_Entity
(E
)
3048 and then No
(Linker_Section_Pragma
(E
))
3050 Set_Linker_Section_Pragma
3051 (E
, Linker_Section_Pragma
(Etype
(E
)));
3054 -- For convention C objects of an enumeration type, warn if the
3055 -- size is not integer size and no explicit size given. Skip
3056 -- warning for Boolean, and Character, assume programmer expects
3057 -- 8-bit sizes for these cases.
3059 if (Convention
(E
) = Convention_C
3061 Convention
(E
) = Convention_CPP
)
3062 and then Is_Enumeration_Type
(Etype
(E
))
3063 and then not Is_Character_Type
(Etype
(E
))
3064 and then not Is_Boolean_Type
(Etype
(E
))
3065 and then Esize
(Etype
(E
)) < Standard_Integer_Size
3066 and then not Has_Size_Clause
(E
)
3068 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
3070 ("??convention C enumeration object has size less than ^", E
);
3071 Error_Msg_N
("\??use explicit size clause to set size", E
);
3073 end Freeze_Object_Declaration
;
3075 -----------------------------
3076 -- Freeze_Generic_Entities --
3077 -----------------------------
3079 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
3086 E
:= First_Entity
(Pack
);
3087 while Present
(E
) loop
3088 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
3089 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
3091 Append_To
(Flist
, F
);
3093 elsif Ekind
(E
) = E_Generic_Package
then
3094 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
3101 end Freeze_Generic_Entities
;
3103 --------------------
3104 -- Freeze_Profile --
3105 --------------------
3107 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
3110 Warn_Node
: Node_Id
;
3113 -- Loop through formals
3115 Formal
:= First_Formal
(E
);
3116 while Present
(Formal
) loop
3117 F_Type
:= Etype
(Formal
);
3119 -- AI05-0151: incomplete types can appear in a profile. By the
3120 -- time the entity is frozen, the full view must be available,
3121 -- unless it is a limited view.
3123 if Is_Incomplete_Type
(F_Type
)
3124 and then Present
(Full_View
(F_Type
))
3125 and then not From_Limited_With
(F_Type
)
3127 F_Type
:= Full_View
(F_Type
);
3128 Set_Etype
(Formal
, F_Type
);
3131 if not From_Limited_With
(F_Type
) then
3132 Freeze_And_Append
(F_Type
, N
, Result
);
3135 if Is_Private_Type
(F_Type
)
3136 and then Is_Private_Type
(Base_Type
(F_Type
))
3137 and then No
(Full_View
(Base_Type
(F_Type
)))
3138 and then not Is_Generic_Type
(F_Type
)
3139 and then not Is_Derived_Type
(F_Type
)
3141 -- If the type of a formal is incomplete, subprogram is being
3142 -- frozen prematurely. Within an instance (but not within a
3143 -- wrapper package) this is an artifact of our need to regard
3144 -- the end of an instantiation as a freeze point. Otherwise it
3145 -- is a definite error.
3148 Set_Is_Frozen
(E
, False);
3152 elsif not After_Last_Declaration
3153 and then not Freezing_Library_Level_Tagged_Type
3155 Error_Msg_Node_1
:= F_Type
;
3157 ("type & must be fully defined before this point", Loc
);
3161 -- Check suspicious parameter for C function. These tests apply
3162 -- only to exported/imported subprograms.
3164 if Warn_On_Export_Import
3165 and then Comes_From_Source
(E
)
3166 and then (Convention
(E
) = Convention_C
3168 Convention
(E
) = Convention_CPP
)
3169 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3170 and then Convention
(E
) /= Convention
(Formal
)
3171 and then not Has_Warnings_Off
(E
)
3172 and then not Has_Warnings_Off
(F_Type
)
3173 and then not Has_Warnings_Off
(Formal
)
3175 -- Qualify mention of formals with subprogram name
3177 Error_Msg_Qual_Level
:= 1;
3179 -- Check suspicious use of fat C pointer
3181 if Is_Access_Type
(F_Type
)
3182 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
3185 ("?x?type of & does not correspond to C pointer!", Formal
);
3187 -- Check suspicious return of boolean
3189 elsif Root_Type
(F_Type
) = Standard_Boolean
3190 and then Convention
(F_Type
) = Convention_Ada
3191 and then not Has_Warnings_Off
(F_Type
)
3192 and then not Has_Size_Clause
(F_Type
)
3195 ("& is an 8-bit Ada Boolean?x?", Formal
);
3197 ("\use appropriate corresponding type in C "
3198 & "(e.g. char)?x?", Formal
);
3200 -- Check suspicious tagged type
3202 elsif (Is_Tagged_Type
(F_Type
)
3204 (Is_Access_Type
(F_Type
)
3205 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
3206 and then Convention
(E
) = Convention_C
3209 ("?x?& involves a tagged type which does not "
3210 & "correspond to any C type!", Formal
);
3212 -- Check wrong convention subprogram pointer
3214 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
3215 and then not Has_Foreign_Convention
(F_Type
)
3218 ("?x?subprogram pointer & should "
3219 & "have foreign convention!", Formal
);
3220 Error_Msg_Sloc
:= Sloc
(F_Type
);
3222 ("\?x?add Convention pragma to declaration of &#",
3226 -- Turn off name qualification after message output
3228 Error_Msg_Qual_Level
:= 0;
3231 -- Check for unconstrained array in exported foreign convention
3234 if Has_Foreign_Convention
(E
)
3235 and then not Is_Imported
(E
)
3236 and then Is_Array_Type
(F_Type
)
3237 and then not Is_Constrained
(F_Type
)
3238 and then Warn_On_Export_Import
3240 Error_Msg_Qual_Level
:= 1;
3242 -- If this is an inherited operation, place the warning on
3243 -- the derived type declaration, rather than on the original
3246 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
3248 Warn_Node
:= Parent
(E
);
3250 if Formal
= First_Formal
(E
) then
3251 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
3254 Warn_Node
:= Formal
;
3257 Error_Msg_NE
("?x?type of argument& is unconstrained array",
3259 Error_Msg_NE
("?x?foreign caller must pass bounds explicitly",
3261 Error_Msg_Qual_Level
:= 0;
3264 if not From_Limited_With
(F_Type
) then
3265 if Is_Access_Type
(F_Type
) then
3266 F_Type
:= Designated_Type
(F_Type
);
3269 -- If the formal is an anonymous_access_to_subprogram
3270 -- freeze the subprogram type as well, to prevent
3271 -- scope anomalies in gigi, because there is no other
3272 -- clear point at which it could be frozen.
3274 if Is_Itype
(Etype
(Formal
))
3275 and then Ekind
(F_Type
) = E_Subprogram_Type
3277 Freeze_And_Append
(F_Type
, N
, Result
);
3281 Next_Formal
(Formal
);
3284 -- Case of function: similar checks on return type
3286 if Ekind
(E
) = E_Function
then
3288 -- Freeze return type
3290 R_Type
:= Etype
(E
);
3292 -- AI05-0151: the return type may have been incomplete
3293 -- at the point of declaration. Replace it with the full
3294 -- view, unless the current type is a limited view. In
3295 -- that case the full view is in a different unit, and
3296 -- gigi finds the non-limited view after the other unit
3299 if Ekind
(R_Type
) = E_Incomplete_Type
3300 and then Present
(Full_View
(R_Type
))
3301 and then not From_Limited_With
(R_Type
)
3303 R_Type
:= Full_View
(R_Type
);
3304 Set_Etype
(E
, R_Type
);
3307 Freeze_And_Append
(R_Type
, N
, Result
);
3309 -- Check suspicious return type for C function
3311 if Warn_On_Export_Import
3312 and then (Convention
(E
) = Convention_C
3314 Convention
(E
) = Convention_CPP
)
3315 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3317 -- Check suspicious return of fat C pointer
3319 if Is_Access_Type
(R_Type
)
3320 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
3321 and then not Has_Warnings_Off
(E
)
3322 and then not Has_Warnings_Off
(R_Type
)
3324 Error_Msg_N
("?x?return type of& does not "
3325 & "correspond to C pointer!", E
);
3327 -- Check suspicious return of boolean
3329 elsif Root_Type
(R_Type
) = Standard_Boolean
3330 and then Convention
(R_Type
) = Convention_Ada
3331 and then not Has_Warnings_Off
(E
)
3332 and then not Has_Warnings_Off
(R_Type
)
3333 and then not Has_Size_Clause
(R_Type
)
3336 N
: constant Node_Id
:=
3337 Result_Definition
(Declaration_Node
(E
));
3340 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
3342 ("\use appropriate corresponding type in C "
3343 & "(e.g. char)?x?", N
, E
);
3346 -- Check suspicious return tagged type
3348 elsif (Is_Tagged_Type
(R_Type
)
3349 or else (Is_Access_Type
(R_Type
)
3352 (Designated_Type
(R_Type
))))
3353 and then Convention
(E
) = Convention_C
3354 and then not Has_Warnings_Off
(E
)
3355 and then not Has_Warnings_Off
(R_Type
)
3357 Error_Msg_N
("?x?return type of & does not "
3358 & "correspond to C type!", E
);
3360 -- Check return of wrong convention subprogram pointer
3362 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3363 and then not Has_Foreign_Convention
(R_Type
)
3364 and then not Has_Warnings_Off
(E
)
3365 and then not Has_Warnings_Off
(R_Type
)
3367 Error_Msg_N
("?x?& should return a foreign "
3368 & "convention subprogram pointer", E
);
3369 Error_Msg_Sloc
:= Sloc
(R_Type
);
3371 ("\?x?add Convention pragma to declaration of& #",
3376 -- Give warning for suspicious return of a result of an
3377 -- unconstrained array type in a foreign convention function.
3379 if Has_Foreign_Convention
(E
)
3381 -- We are looking for a return of unconstrained array
3383 and then Is_Array_Type
(R_Type
)
3384 and then not Is_Constrained
(R_Type
)
3386 -- Exclude imported routines, the warning does not belong on
3387 -- the import, but rather on the routine definition.
3389 and then not Is_Imported
(E
)
3391 -- Check that general warning is enabled, and that it is not
3392 -- suppressed for this particular case.
3394 and then Warn_On_Export_Import
3395 and then not Has_Warnings_Off
(E
)
3396 and then not Has_Warnings_Off
(R_Type
)
3399 ("?x?foreign convention function& should not return "
3400 & "unconstrained array!", E
);
3404 -- Check suspicious use of Import in pure unit (cases where the RM
3405 -- allows calls to be omitted).
3409 -- It might be suspicious if the compilation unit has the Pure
3412 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
3414 -- The RM allows omission of calls only in the case of
3415 -- library-level subprograms (see RM-10.2.1(18)).
3417 and then Is_Library_Level_Entity
(E
)
3419 -- Ignore internally generated entity. This happens in some cases
3420 -- of subprograms in specs, where we generate an implied body.
3422 and then Comes_From_Source
(Import_Pragma
(E
))
3424 -- Assume run-time knows what it is doing
3426 and then not GNAT_Mode
3428 -- Assume explicit Pure_Function means import is pure
3430 and then not Has_Pragma_Pure_Function
(E
)
3432 -- Don't need warning in relaxed semantics mode
3434 and then not Relaxed_RM_Semantics
3436 -- Assume convention Intrinsic is OK, since this is specialized.
3437 -- This deals with the DEC unit current_exception.ads
3439 and then Convention
(E
) /= Convention_Intrinsic
3441 -- Assume that ASM interface knows what it is doing. This deals
3442 -- with e.g. unsigned.ads in the AAMP back end.
3444 and then Convention
(E
) /= Convention_Assembler
3447 ("pragma Import in Pure unit??", Import_Pragma
(E
));
3449 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
3450 Import_Pragma
(E
), E
);
3456 ------------------------
3457 -- Freeze_Record_Type --
3458 ------------------------
3460 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
3467 pragma Warnings
(Off
, Junk
);
3469 Rec_Pushed
: Boolean := False;
3470 -- Set True if the record type scope Rec has been pushed on the scope
3471 -- stack. Needed for the analysis of delayed aspects specified to the
3472 -- components of Rec.
3475 -- Scalar_Storage_Order attribute definition clause for the record
3477 Unplaced_Component
: Boolean := False;
3478 -- Set True if we find at least one component with no component
3479 -- clause (used to warn about useless Pack pragmas).
3481 Placed_Component
: Boolean := False;
3482 -- Set True if we find at least one component with a component
3483 -- clause (used to warn about useless Bit_Order pragmas, and also
3484 -- to detect cases where Implicit_Packing may have an effect).
3486 Aliased_Component
: Boolean := False;
3487 -- Set True if we find at least one component which is aliased. This
3488 -- is used to prevent Implicit_Packing of the record, since packing
3489 -- cannot modify the size of alignment of an aliased component.
3491 SSO_ADC_Component
: Boolean := False;
3492 -- Set True if we find at least one component whose type has a
3493 -- Scalar_Storage_Order attribute definition clause.
3495 All_Elem_Components
: Boolean := True;
3496 -- Set False if we encounter a component of a composite type
3498 All_Sized_Components
: Boolean := True;
3499 -- Set False if we encounter a component with unknown RM_Size
3501 All_Storage_Unit_Components
: Boolean := True;
3502 -- Set False if we encounter a component of a composite type whose
3503 -- RM_Size is not a multiple of the storage unit.
3505 Elem_Component_Total_Esize
: Uint
:= Uint_0
;
3506 -- Accumulates total Esize values of all elementary components. Used
3507 -- for processing of Implicit_Packing.
3509 Sized_Component_Total_RM_Size
: Uint
:= Uint_0
;
3510 -- Accumulates total RM_Size values of all sized components. Used
3511 -- for processing of Implicit_Packing.
3513 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
3514 -- If N is an allocator, possibly wrapped in one or more level of
3515 -- qualified expression(s), return the inner allocator node, else
3518 procedure Check_Itype
(Typ
: Entity_Id
);
3519 -- If the component subtype is an access to a constrained subtype of
3520 -- an already frozen type, make the subtype frozen as well. It might
3521 -- otherwise be frozen in the wrong scope, and a freeze node on
3522 -- subtype has no effect. Similarly, if the component subtype is a
3523 -- regular (not protected) access to subprogram, set the anonymous
3524 -- subprogram type to frozen as well, to prevent an out-of-scope
3525 -- freeze node at some eventual point of call. Protected operations
3526 -- are handled elsewhere.
3528 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
3529 -- Make sure that all types mentioned in Discrete_Choices of the
3530 -- variants referenceed by the Variant_Part VP are frozen. This is
3531 -- a recursive routine to deal with nested variants.
3533 ---------------------
3534 -- Check_Allocator --
3535 ---------------------
3537 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
3542 if Nkind
(Inner
) = N_Allocator
then
3544 elsif Nkind
(Inner
) = N_Qualified_Expression
then
3545 Inner
:= Expression
(Inner
);
3550 end Check_Allocator
;
3556 procedure Check_Itype
(Typ
: Entity_Id
) is
3557 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
3560 if not Is_Frozen
(Desig
)
3561 and then Is_Frozen
(Base_Type
(Desig
))
3563 Set_Is_Frozen
(Desig
);
3565 -- In addition, add an Itype_Reference to ensure that the
3566 -- access subtype is elaborated early enough. This cannot be
3567 -- done if the subtype may depend on discriminants.
3569 if Ekind
(Comp
) = E_Component
3570 and then Is_Itype
(Etype
(Comp
))
3571 and then not Has_Discriminants
(Rec
)
3573 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
3574 Set_Itype
(IR
, Desig
);
3578 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
3579 and then Convention
(Desig
) /= Convention_Protected
3581 Set_Is_Frozen
(Desig
);
3585 ------------------------------------
3586 -- Freeze_Choices_In_Variant_Part --
3587 ------------------------------------
3589 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
3590 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
3597 -- Loop through variants
3599 Variant
:= First_Non_Pragma
(Variants
(VP
));
3600 while Present
(Variant
) loop
3602 -- Loop through choices, checking that all types are frozen
3604 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
3605 while Present
(Choice
) loop
3606 if Nkind
(Choice
) in N_Has_Etype
3607 and then Present
(Etype
(Choice
))
3609 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
3612 Next_Non_Pragma
(Choice
);
3615 -- Check for nested variant part to process
3617 CL
:= Component_List
(Variant
);
3619 if not Null_Present
(CL
) then
3620 if Present
(Variant_Part
(CL
)) then
3621 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
3625 Next_Non_Pragma
(Variant
);
3627 end Freeze_Choices_In_Variant_Part
;
3629 -- Start of processing for Freeze_Record_Type
3632 -- Deal with delayed aspect specifications for components. The
3633 -- analysis of the aspect is required to be delayed to the freeze
3634 -- point, thus we analyze the pragma or attribute definition
3635 -- clause in the tree at this point. We also analyze the aspect
3636 -- specification node at the freeze point when the aspect doesn't
3637 -- correspond to pragma/attribute definition clause.
3639 Comp
:= First_Entity
(Rec
);
3640 while Present
(Comp
) loop
3641 if Ekind
(Comp
) = E_Component
3642 and then Has_Delayed_Aspects
(Comp
)
3644 if not Rec_Pushed
then
3648 -- The visibility to the discriminants must be restored in
3649 -- order to properly analyze the aspects.
3651 if Has_Discriminants
(Rec
) then
3652 Install_Discriminants
(Rec
);
3656 Analyze_Aspects_At_Freeze_Point
(Comp
);
3662 -- Pop the scope if Rec scope has been pushed on the scope stack
3663 -- during the delayed aspect analysis process.
3666 if Has_Discriminants
(Rec
) then
3667 Uninstall_Discriminants
(Rec
);
3673 -- Freeze components and embedded subtypes
3675 Comp
:= First_Entity
(Rec
);
3677 while Present
(Comp
) loop
3678 if Is_Aliased
(Comp
) then
3679 Aliased_Component
:= True;
3682 -- Handle the component and discriminant case
3684 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
3686 CC
: constant Node_Id
:= Component_Clause
(Comp
);
3689 -- Freezing a record type freezes the type of each of its
3690 -- components. However, if the type of the component is
3691 -- part of this record, we do not want or need a separate
3692 -- Freeze_Node. Note that Is_Itype is wrong because that's
3693 -- also set in private type cases. We also can't check for
3694 -- the Scope being exactly Rec because of private types and
3695 -- record extensions.
3697 if Is_Itype
(Etype
(Comp
))
3698 and then Is_Record_Type
(Underlying_Type
3699 (Scope
(Etype
(Comp
))))
3701 Undelay_Type
(Etype
(Comp
));
3704 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
3706 -- Warn for pragma Pack overriding foreign convention
3708 if Has_Foreign_Convention
(Etype
(Comp
))
3709 and then Has_Pragma_Pack
(Rec
)
3711 -- Don't warn for aliased components, since override
3712 -- cannot happen in that case.
3714 and then not Is_Aliased
(Comp
)
3717 CN
: constant Name_Id
:=
3718 Get_Convention_Name
(Convention
(Etype
(Comp
)));
3719 PP
: constant Node_Id
:=
3720 Get_Pragma
(Rec
, Pragma_Pack
);
3722 if Present
(PP
) then
3723 Error_Msg_Name_1
:= CN
;
3724 Error_Msg_Sloc
:= Sloc
(Comp
);
3726 ("pragma Pack affects convention % component#??",
3728 Error_Msg_Name_1
:= CN
;
3730 ("\component & may not have % compatible "
3731 & "representation??", PP
, Comp
);
3736 -- Check for error of component clause given for variable
3737 -- sized type. We have to delay this test till this point,
3738 -- since the component type has to be frozen for us to know
3739 -- if it is variable length.
3741 if Present
(CC
) then
3742 Placed_Component
:= True;
3744 -- We omit this test in a generic context, it will be
3745 -- applied at instantiation time.
3747 if Inside_A_Generic
then
3750 -- Also omit this test in CodePeer mode, since we do not
3751 -- have sufficient info on size and rep clauses.
3753 elsif CodePeer_Mode
then
3756 -- Omit check if component has a generic type. This can
3757 -- happen in an instantiation within a generic in ASIS
3758 -- mode, where we force freeze actions without full
3761 elsif Is_Generic_Type
(Etype
(Comp
)) then
3767 Size_Known_At_Compile_Time
3768 (Underlying_Type
(Etype
(Comp
)))
3771 ("component clause not allowed for variable " &
3772 "length component", CC
);
3776 Unplaced_Component
:= True;
3779 -- Case of component requires byte alignment
3781 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
3783 -- Set the enclosing record to also require byte align
3785 Set_Must_Be_On_Byte_Boundary
(Rec
);
3787 -- Check for component clause that is inconsistent with
3788 -- the required byte boundary alignment.
3791 and then Normalized_First_Bit
(Comp
) mod
3792 System_Storage_Unit
/= 0
3795 ("component & must be byte aligned",
3796 Component_Name
(Component_Clause
(Comp
)));
3802 -- Gather data for possible Implicit_Packing later. Note that at
3803 -- this stage we might be dealing with a real component, or with
3804 -- an implicit subtype declaration.
3806 if Known_Static_RM_Size
(Etype
(Comp
)) then
3807 Sized_Component_Total_RM_Size
:=
3808 Sized_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
3810 if Is_Elementary_Type
(Etype
(Comp
)) then
3811 Elem_Component_Total_Esize
:=
3812 Elem_Component_Total_Esize
+ Esize
(Etype
(Comp
));
3814 All_Elem_Components
:= False;
3816 if RM_Size
(Etype
(Comp
)) mod System_Storage_Unit
/= 0 then
3817 All_Storage_Unit_Components
:= False;
3821 All_Sized_Components
:= False;
3824 -- If the component is an Itype with Delayed_Freeze and is either
3825 -- a record or array subtype and its base type has not yet been
3826 -- frozen, we must remove this from the entity list of this record
3827 -- and put it on the entity list of the scope of its base type.
3828 -- Note that we know that this is not the type of a component
3829 -- since we cleared Has_Delayed_Freeze for it in the previous
3830 -- loop. Thus this must be the Designated_Type of an access type,
3831 -- which is the type of a component.
3834 and then Is_Type
(Scope
(Comp
))
3835 and then Is_Composite_Type
(Comp
)
3836 and then Base_Type
(Comp
) /= Comp
3837 and then Has_Delayed_Freeze
(Comp
)
3838 and then not Is_Frozen
(Base_Type
(Comp
))
3841 Will_Be_Frozen
: Boolean := False;
3845 -- We have a difficult case to handle here. Suppose Rec is
3846 -- subtype being defined in a subprogram that's created as
3847 -- part of the freezing of Rec'Base. In that case, we know
3848 -- that Comp'Base must have already been frozen by the time
3849 -- we get to elaborate this because Gigi doesn't elaborate
3850 -- any bodies until it has elaborated all of the declarative
3851 -- part. But Is_Frozen will not be set at this point because
3852 -- we are processing code in lexical order.
3854 -- We detect this case by going up the Scope chain of Rec
3855 -- and seeing if we have a subprogram scope before reaching
3856 -- the top of the scope chain or that of Comp'Base. If we
3857 -- do, then mark that Comp'Base will actually be frozen. If
3858 -- so, we merely undelay it.
3861 while Present
(S
) loop
3862 if Is_Subprogram
(S
) then
3863 Will_Be_Frozen
:= True;
3865 elsif S
= Scope
(Base_Type
(Comp
)) then
3872 if Will_Be_Frozen
then
3873 Undelay_Type
(Comp
);
3876 if Present
(Prev
) then
3877 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
3879 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
3882 -- Insert in entity list of scope of base type (which
3883 -- must be an enclosing scope, because still unfrozen).
3885 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
3889 -- If the component is an access type with an allocator as default
3890 -- value, the designated type will be frozen by the corresponding
3891 -- expression in init_proc. In order to place the freeze node for
3892 -- the designated type before that for the current record type,
3895 -- Same process if the component is an array of access types,
3896 -- initialized with an aggregate. If the designated type is
3897 -- private, it cannot contain allocators, and it is premature
3898 -- to freeze the type, so we check for this as well.
3900 elsif Is_Access_Type
(Etype
(Comp
))
3901 and then Present
(Parent
(Comp
))
3902 and then Present
(Expression
(Parent
(Comp
)))
3905 Alloc
: constant Node_Id
:=
3906 Check_Allocator
(Expression
(Parent
(Comp
)));
3909 if Present
(Alloc
) then
3911 -- If component is pointer to a class-wide type, freeze
3912 -- the specific type in the expression being allocated.
3913 -- The expression may be a subtype indication, in which
3914 -- case freeze the subtype mark.
3916 if Is_Class_Wide_Type
3917 (Designated_Type
(Etype
(Comp
)))
3919 if Is_Entity_Name
(Expression
(Alloc
)) then
3921 (Entity
(Expression
(Alloc
)), N
, Result
);
3923 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
3926 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
3930 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
3931 Check_Itype
(Etype
(Comp
));
3935 (Designated_Type
(Etype
(Comp
)), N
, Result
);
3940 elsif Is_Access_Type
(Etype
(Comp
))
3941 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
3943 Check_Itype
(Etype
(Comp
));
3945 -- Freeze the designated type when initializing a component with
3946 -- an aggregate in case the aggregate contains allocators.
3949 -- type T_Ptr is access all T;
3950 -- type T_Array is array ... of T_Ptr;
3952 -- type Rec is record
3953 -- Comp : T_Array := (others => ...);
3956 elsif Is_Array_Type
(Etype
(Comp
))
3957 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
3960 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
3961 Desig_Typ
: constant Entity_Id
:=
3963 (Component_Type
(Etype
(Comp
)));
3966 -- The only case when this sort of freezing is not done is
3967 -- when the designated type is class-wide and the root type
3968 -- is the record owning the component. This scenario results
3969 -- in a circularity because the class-wide type requires
3970 -- primitives that have not been created yet as the root
3971 -- type is in the process of being frozen.
3973 -- type Rec is tagged;
3974 -- type Rec_Ptr is access all Rec'Class;
3975 -- type Rec_Array is array ... of Rec_Ptr;
3977 -- type Rec is record
3978 -- Comp : Rec_Array := (others => ...);
3981 if Is_Class_Wide_Type
(Desig_Typ
)
3982 and then Root_Type
(Desig_Typ
) = Rec
3986 elsif Is_Fully_Defined
(Desig_Typ
)
3987 and then Present
(Comp_Par
)
3988 and then Nkind
(Comp_Par
) = N_Component_Declaration
3989 and then Present
(Expression
(Comp_Par
))
3990 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
3992 Freeze_And_Append
(Desig_Typ
, N
, Result
);
4002 Get_Attribute_Definition_Clause
4003 (Rec
, Attribute_Scalar_Storage_Order
);
4005 -- If the record type has Complex_Representation, then it is treated
4006 -- as a scalar in the back end so the storage order is irrelevant.
4008 if Has_Complex_Representation
(Rec
) then
4009 if Present
(SSO_ADC
) then
4011 ("??storage order has no effect with Complex_Representation",
4016 -- Deal with default setting of reverse storage order
4018 Set_SSO_From_Default
(Rec
);
4020 -- Check consistent attribute setting on component types
4023 Comp_ADC_Present
: Boolean;
4025 Comp
:= First_Component
(Rec
);
4026 while Present
(Comp
) loop
4027 Check_Component_Storage_Order
4031 Comp_ADC_Present
=> Comp_ADC_Present
);
4032 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
4033 Next_Component
(Comp
);
4037 -- Now deal with reverse storage order/bit order issues
4039 if Present
(SSO_ADC
) then
4041 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
4042 -- if the former is specified.
4044 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
4046 -- Note: report error on Rec, not on SSO_ADC, as ADC may
4047 -- apply to some ancestor type.
4049 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
4051 ("scalar storage order for& specified# inconsistent with "
4052 & "bit order", Rec
);
4055 -- Warn if there is a Scalar_Storage_Order attribute definition
4056 -- clause but no component clause, no component that itself has
4057 -- such an attribute definition, and no pragma Pack.
4059 if not (Placed_Component
4066 ("??scalar storage order specified but no component "
4067 & "clause", SSO_ADC
);
4072 -- Deal with Bit_Order aspect
4074 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
4076 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
4077 if not (Placed_Component
4078 or else Present
(SSO_ADC
)
4079 or else Is_Packed
(Rec
))
4081 -- Warn if clause has no effect when no component clause is
4082 -- present, but suppress warning if the Bit_Order is required
4083 -- due to the presence of a Scalar_Storage_Order attribute.
4086 ("??bit order specification has no effect", ADC
);
4088 ("\??since no component clauses were specified", ADC
);
4090 -- Here is where we do the processing to adjust component clauses
4091 -- for reversed bit order, when not using reverse SSO.
4093 elsif Reverse_Bit_Order
(Rec
)
4094 and then not Reverse_Storage_Order
(Rec
)
4096 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
4098 -- Case where we have both an explicit Bit_Order and the same
4099 -- Scalar_Storage_Order: leave record untouched, the back-end
4100 -- will take care of required layout conversions.
4108 -- Complete error checking on record representation clause (e.g.
4109 -- overlap of components). This is called after adjusting the
4110 -- record for reverse bit order.
4113 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
4115 if Present
(RRC
) then
4116 Check_Record_Representation_Clause
(RRC
);
4120 -- Set OK_To_Reorder_Components depending on debug flags
4122 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
4123 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
4125 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
4127 Set_OK_To_Reorder_Components
(Rec
);
4131 -- Check for useless pragma Pack when all components placed. We only
4132 -- do this check for record types, not subtypes, since a subtype may
4133 -- have all its components placed, and it still makes perfectly good
4134 -- sense to pack other subtypes or the parent type. We do not give
4135 -- this warning if Optimize_Alignment is set to Space, since the
4136 -- pragma Pack does have an effect in this case (it always resets
4137 -- the alignment to one).
4139 if Ekind
(Rec
) = E_Record_Type
4140 and then Is_Packed
(Rec
)
4141 and then not Unplaced_Component
4142 and then Optimize_Alignment
/= 'S'
4144 -- Reset packed status. Probably not necessary, but we do it so
4145 -- that there is no chance of the back end doing something strange
4146 -- with this redundant indication of packing.
4148 Set_Is_Packed
(Rec
, False);
4150 -- Give warning if redundant constructs warnings on
4152 if Warn_On_Redundant_Constructs
then
4153 Error_Msg_N
-- CODEFIX
4154 ("??pragma Pack has no effect, no unplaced components",
4155 Get_Rep_Pragma
(Rec
, Name_Pack
));
4159 -- If this is the record corresponding to a remote type, freeze the
4160 -- remote type here since that is what we are semantically freezing.
4161 -- This prevents the freeze node for that type in an inner scope.
4163 if Ekind
(Rec
) = E_Record_Type
then
4164 if Present
(Corresponding_Remote_Type
(Rec
)) then
4165 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
4168 -- Check for controlled components and unchecked unions.
4170 Comp
:= First_Component
(Rec
);
4171 while Present
(Comp
) loop
4173 -- Do not set Has_Controlled_Component on a class-wide
4174 -- equivalent type. See Make_CW_Equivalent_Type.
4176 if not Is_Class_Wide_Equivalent_Type
(Rec
)
4178 (Has_Controlled_Component
(Etype
(Comp
))
4180 (Chars
(Comp
) /= Name_uParent
4181 and then Is_Controlled_Active
(Etype
(Comp
)))
4183 (Is_Protected_Type
(Etype
(Comp
))
4185 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
4187 Has_Controlled_Component
4188 (Corresponding_Record_Type
(Etype
(Comp
)))))
4190 Set_Has_Controlled_Component
(Rec
);
4193 if Has_Unchecked_Union
(Etype
(Comp
)) then
4194 Set_Has_Unchecked_Union
(Rec
);
4197 -- Scan component declaration for likely misuses of current
4198 -- instance, either in a constraint or a default expression.
4200 if Has_Per_Object_Constraint
(Comp
) then
4201 Check_Current_Instance
(Parent
(Comp
));
4204 Next_Component
(Comp
);
4208 -- Enforce the restriction that access attributes with a current
4209 -- instance prefix can only apply to limited types. This comment
4210 -- is floating here, but does not seem to belong here???
4212 -- Set component alignment if not otherwise already set
4214 Set_Component_Alignment_If_Not_Set
(Rec
);
4216 -- For first subtypes, check if there are any fixed-point fields with
4217 -- component clauses, where we must check the size. This is not done
4218 -- till the freeze point since for fixed-point types, we do not know
4219 -- the size until the type is frozen. Similar processing applies to
4220 -- bit packed arrays.
4222 if Is_First_Subtype
(Rec
) then
4223 Comp
:= First_Component
(Rec
);
4224 while Present
(Comp
) loop
4225 if Present
(Component_Clause
(Comp
))
4226 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
4227 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
4230 (Component_Name
(Component_Clause
(Comp
)),
4236 Next_Component
(Comp
);
4240 -- Generate warning for applying C or C++ convention to a record
4241 -- with discriminants. This is suppressed for the unchecked union
4242 -- case, since the whole point in this case is interface C. We also
4243 -- do not generate this within instantiations, since we will have
4244 -- generated a message on the template.
4246 if Has_Discriminants
(E
)
4247 and then not Is_Unchecked_Union
(E
)
4248 and then (Convention
(E
) = Convention_C
4250 Convention
(E
) = Convention_CPP
)
4251 and then Comes_From_Source
(E
)
4252 and then not In_Instance
4253 and then not Has_Warnings_Off
(E
)
4254 and then not Has_Warnings_Off
(Base_Type
(E
))
4257 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
4261 if Present
(Cprag
) then
4262 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
4264 if Convention
(E
) = Convention_C
then
4266 ("?x?variant record has no direct equivalent in C",
4270 ("?x?variant record has no direct equivalent in C++",
4275 ("\?x?use of convention for type& is dubious", A2
, E
);
4280 -- See if Size is too small as is (and implicit packing might help)
4282 if not Is_Packed
(Rec
)
4284 -- No implicit packing if even one component is explicitly placed
4286 and then not Placed_Component
4288 -- Or even one component is aliased
4290 and then not Aliased_Component
4292 -- Must have size clause and all sized components
4294 and then Has_Size_Clause
(Rec
)
4295 and then All_Sized_Components
4297 -- Do not try implicit packing on records with discriminants, too
4298 -- complicated, especially in the variant record case.
4300 and then not Has_Discriminants
(Rec
)
4302 -- We want to implicitly pack if the specified size of the record
4303 -- is less than the sum of the object sizes (no point in packing
4304 -- if this is not the case) if we can compute it, i.e. if we have
4305 -- only elementary components. Otherwise, we have at least one
4306 -- composite component and we want to implicit pack only if bit
4307 -- packing is required for it, as we are sure in this case that
4308 -- the back end cannot do the expected layout without packing.
4310 and then ((All_Elem_Components
4311 and then RM_Size
(Rec
) < Elem_Component_Total_Esize
)
4312 or else (not All_Elem_Components
4313 and then not All_Storage_Unit_Components
))
4315 -- And the total RM size cannot be greater than the specified size
4316 -- since otherwise packing will not get us where we have to be.
4318 and then RM_Size
(Rec
) >= Sized_Component_Total_RM_Size
4320 -- Never do implicit packing in CodePeer or SPARK modes since
4321 -- we don't do any packing in these modes, since this generates
4322 -- over-complex code that confuses static analysis, and in
4323 -- general, neither CodePeer not GNATprove care about the
4324 -- internal representation of objects.
4326 and then not (CodePeer_Mode
or GNATprove_Mode
)
4328 -- If implicit packing enabled, do it
4330 if Implicit_Packing
then
4331 Set_Is_Packed
(Rec
);
4333 -- Otherwise flag the size clause
4337 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
4339 Error_Msg_NE
-- CODEFIX
4340 ("size given for& too small", Sz
, Rec
);
4341 Error_Msg_N
-- CODEFIX
4342 ("\use explicit pragma Pack "
4343 & "or use pragma Implicit_Packing", Sz
);
4348 -- The following checks are relevant only when SPARK_Mode is on as
4349 -- they are not standard Ada legality rules.
4351 if SPARK_Mode
= On
then
4352 if Is_Effectively_Volatile
(Rec
) then
4354 -- A discriminated type cannot be effectively volatile
4355 -- (SPARK RM C.6(4)).
4357 if Has_Discriminants
(Rec
) then
4358 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
4360 -- A tagged type cannot be effectively volatile
4361 -- (SPARK RM C.6(5)).
4363 elsif Is_Tagged_Type
(Rec
) then
4364 Error_Msg_N
("tagged type & cannot be volatile", Rec
);
4367 -- A non-effectively volatile record type cannot contain
4368 -- effectively volatile components (SPARK RM C.6(2)).
4371 Comp
:= First_Component
(Rec
);
4372 while Present
(Comp
) loop
4373 if Comes_From_Source
(Comp
)
4374 and then Is_Effectively_Volatile
(Etype
(Comp
))
4376 Error_Msg_Name_1
:= Chars
(Rec
);
4378 ("component & of non-volatile type % cannot be "
4379 & "volatile", Comp
);
4382 Next_Component
(Comp
);
4386 -- A type which does not yield a synchronized object cannot have
4387 -- a component that yields a synchronized object (SPARK RM 9.5).
4389 if not Yields_Synchronized_Object
(Rec
) then
4390 Comp
:= First_Component
(Rec
);
4391 while Present
(Comp
) loop
4392 if Comes_From_Source
(Comp
)
4393 and then Yields_Synchronized_Object
(Etype
(Comp
))
4395 Error_Msg_Name_1
:= Chars
(Rec
);
4397 ("component & of non-synchronized type % cannot be "
4398 & "synchronized", Comp
);
4401 Next_Component
(Comp
);
4405 -- A Ghost type cannot have a component of protected or task type
4406 -- (SPARK RM 6.9(19)).
4408 if Is_Ghost_Entity
(Rec
) then
4409 Comp
:= First_Component
(Rec
);
4410 while Present
(Comp
) loop
4411 if Comes_From_Source
(Comp
)
4412 and then Is_Concurrent_Type
(Etype
(Comp
))
4414 Error_Msg_Name_1
:= Chars
(Rec
);
4416 ("component & of ghost type % cannot be concurrent",
4420 Next_Component
(Comp
);
4425 -- Make sure that if we have an iterator aspect, then we have
4426 -- either Constant_Indexing or Variable_Indexing.
4429 Iterator_Aspect
: Node_Id
;
4432 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
4434 if No
(Iterator_Aspect
) then
4435 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
4438 if Present
(Iterator_Aspect
) then
4439 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
4441 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
4446 ("Iterator_Element requires indexing aspect",
4452 -- All done if not a full record definition
4454 if Ekind
(Rec
) /= E_Record_Type
then
4458 -- Finally we need to check the variant part to make sure that
4459 -- all types within choices are properly frozen as part of the
4460 -- freezing of the record type.
4462 Check_Variant_Part
: declare
4463 D
: constant Node_Id
:= Declaration_Node
(Rec
);
4468 -- Find component list
4472 if Nkind
(D
) = N_Full_Type_Declaration
then
4473 T
:= Type_Definition
(D
);
4475 if Nkind
(T
) = N_Record_Definition
then
4476 C
:= Component_List
(T
);
4478 elsif Nkind
(T
) = N_Derived_Type_Definition
4479 and then Present
(Record_Extension_Part
(T
))
4481 C
:= Component_List
(Record_Extension_Part
(T
));
4485 -- Case of variant part present
4487 if Present
(C
) and then Present
(Variant_Part
(C
)) then
4488 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
4491 -- Note: we used to call Check_Choices here, but it is too early,
4492 -- since predicated subtypes are frozen here, but their freezing
4493 -- actions are in Analyze_Freeze_Entity, which has not been called
4494 -- yet for entities frozen within this procedure, so we moved that
4495 -- call to the Analyze_Freeze_Entity for the record type.
4497 end Check_Variant_Part
;
4499 -- Check that all the primitives of an interface type are abstract
4500 -- or null procedures.
4502 if Is_Interface
(Rec
)
4503 and then not Error_Posted
(Parent
(Rec
))
4510 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
4511 while Present
(Elmt
) loop
4512 Subp
:= Node
(Elmt
);
4514 if not Is_Abstract_Subprogram
(Subp
)
4516 -- Avoid reporting the error on inherited primitives
4518 and then Comes_From_Source
(Subp
)
4520 Error_Msg_Name_1
:= Chars
(Subp
);
4522 if Ekind
(Subp
) = E_Procedure
then
4523 if not Null_Present
(Parent
(Subp
)) then
4525 ("interface procedure % must be abstract or null",
4530 ("interface function % must be abstract",
4539 end Freeze_Record_Type
;
4541 -------------------------------
4542 -- Has_Boolean_Aspect_Import --
4543 -------------------------------
4545 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
4546 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4551 if Has_Aspects
(Decl
) then
4552 Asp
:= First
(Aspect_Specifications
(Decl
));
4553 while Present
(Asp
) loop
4554 Expr
:= Expression
(Asp
);
4556 -- The value of aspect Import is True when the expression is
4557 -- either missing or it is explicitly set to True.
4559 if Get_Aspect_Id
(Asp
) = Aspect_Import
4561 or else (Compile_Time_Known_Value
(Expr
)
4562 and then Is_True
(Expr_Value
(Expr
))))
4572 end Has_Boolean_Aspect_Import
;
4574 ---------------------
4575 -- New_Freeze_Node --
4576 ---------------------
4578 function New_Freeze_Node
return Node_Id
is
4579 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4583 -- Handle the case where an ignored Ghost subprogram freezes the type
4584 -- of one of its formals. The type can either be non-Ghost or checked
4585 -- Ghost. Since the freeze node for the type is generated in the
4586 -- context of the subprogram, the node will be incorrectly flagged as
4587 -- ignored Ghost and erroneously removed from the tree.
4590 -- procedure Ignored_Ghost_Proc (Formal : Typ) with Ghost;
4592 -- Reset the Ghost mode to "none". This preserves the freeze node.
4594 if Ghost_Mode
= Ignore
4595 and then not Is_Ignored_Ghost_Entity
(E
)
4596 and then not Is_Ignored_Ghost_Node
(E
)
4601 Result
:= New_Node
(N_Freeze_Entity
, Loc
);
4603 Ghost_Mode
:= Save_Ghost_Mode
;
4605 end New_Freeze_Node
;
4607 ------------------------------
4608 -- Wrap_Imported_Subprogram --
4609 ------------------------------
4611 -- The issue here is that our normal approach of checking preconditions
4612 -- and postconditions does not work for imported procedures, since we
4613 -- are not generating code for the body. To get around this we create
4614 -- a wrapper, as shown by the following example:
4616 -- procedure K (A : Integer);
4617 -- pragma Import (C, K);
4619 -- The spec is rewritten by removing the effects of pragma Import, but
4620 -- leaving the convention unchanged, as though the source had said:
4622 -- procedure K (A : Integer);
4623 -- pragma Convention (C, K);
4625 -- and we create a body, added to the entity K freeze actions, which
4628 -- procedure K (A : Integer) is
4629 -- procedure K (A : Integer);
4630 -- pragma Import (C, K);
4635 -- Now the contract applies in the normal way to the outer procedure,
4636 -- and the inner procedure has no contracts, so there is no problem
4637 -- in just calling it to get the original effect.
4639 -- In the case of a function, we create an appropriate return statement
4640 -- for the subprogram body that calls the inner procedure.
4642 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
4643 function Copy_Import_Pragma
return Node_Id
;
4644 -- Obtain a copy of the Import_Pragma which belongs to subprogram E
4646 ------------------------
4647 -- Copy_Import_Pragma --
4648 ------------------------
4650 function Copy_Import_Pragma
return Node_Id
is
4652 -- The subprogram should have an import pragma, otherwise it does
4655 Prag
: constant Node_Id
:= Import_Pragma
(E
);
4656 pragma Assert
(Present
(Prag
));
4658 -- Save all semantic fields of the pragma
4660 Save_Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
4661 Save_From
: constant Boolean := From_Aspect_Specification
(Prag
);
4662 Save_Prag
: constant Node_Id
:= Next_Pragma
(Prag
);
4663 Save_Rep
: constant Node_Id
:= Next_Rep_Item
(Prag
);
4668 -- Reset all semantic fields. This avoids a potential infinite
4669 -- loop when the pragma comes from an aspect as the duplication
4670 -- will copy the aspect, then copy the corresponding pragma and
4673 Set_Corresponding_Aspect
(Prag
, Empty
);
4674 Set_From_Aspect_Specification
(Prag
, False);
4675 Set_Next_Pragma
(Prag
, Empty
);
4676 Set_Next_Rep_Item
(Prag
, Empty
);
4678 Result
:= Copy_Separate_Tree
(Prag
);
4680 -- Restore the original semantic fields
4682 Set_Corresponding_Aspect
(Prag
, Save_Asp
);
4683 Set_From_Aspect_Specification
(Prag
, Save_From
);
4684 Set_Next_Pragma
(Prag
, Save_Prag
);
4685 Set_Next_Rep_Item
(Prag
, Save_Rep
);
4688 end Copy_Import_Pragma
;
4692 Loc
: constant Source_Ptr
:= Sloc
(E
);
4693 CE
: constant Name_Id
:= Chars
(E
);
4701 -- Start of processing for Wrap_Imported_Subprogram
4704 -- Nothing to do if not imported
4706 if not Is_Imported
(E
) then
4709 -- Test enabling conditions for wrapping
4711 elsif Is_Subprogram
(E
)
4712 and then Present
(Contract
(E
))
4713 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
4714 and then not GNATprove_Mode
4716 -- Here we do the wrap
4718 -- Note on calls to Copy_Separate_Tree. The trees we are copying
4719 -- here are fully analyzed, but we definitely want fully syntactic
4720 -- unanalyzed trees in the body we construct, so that the analysis
4721 -- generates the right visibility, and that is exactly what the
4722 -- calls to Copy_Separate_Tree give us.
4724 Prag
:= Copy_Import_Pragma
;
4726 -- Fix up spec to be not imported any more
4728 Set_Has_Completion
(E
, False);
4729 Set_Import_Pragma
(E
, Empty
);
4730 Set_Interface_Name
(E
, Empty
);
4731 Set_Is_Imported
(E
, False);
4733 -- Grab the subprogram declaration and specification
4735 Spec
:= Declaration_Node
(E
);
4737 -- Build parameter list that we need
4740 Forml
:= First_Formal
(E
);
4741 while Present
(Forml
) loop
4742 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
4743 Next_Formal
(Forml
);
4748 if Ekind_In
(E
, E_Function
, E_Generic_Function
) then
4750 Make_Simple_Return_Statement
(Loc
,
4752 Make_Function_Call
(Loc
,
4753 Name
=> Make_Identifier
(Loc
, CE
),
4754 Parameter_Associations
=> Parms
));
4758 Make_Procedure_Call_Statement
(Loc
,
4759 Name
=> Make_Identifier
(Loc
, CE
),
4760 Parameter_Associations
=> Parms
);
4763 -- Now build the body
4766 Make_Subprogram_Body
(Loc
,
4768 Copy_Separate_Tree
(Spec
),
4769 Declarations
=> New_List
(
4770 Make_Subprogram_Declaration
(Loc
,
4771 Specification
=> Copy_Separate_Tree
(Spec
)),
4773 Handled_Statement_Sequence
=>
4774 Make_Handled_Sequence_Of_Statements
(Loc
,
4775 Statements
=> New_List
(Stmt
),
4776 End_Label
=> Make_Identifier
(Loc
, CE
)));
4778 -- Append the body to freeze result
4780 Add_To_Result
(Bod
);
4783 -- Case of imported subprogram that does not get wrapped
4786 -- Set Is_Public. All imported entities need an external symbol
4787 -- created for them since they are always referenced from another
4788 -- object file. Note this used to be set when we set Is_Imported
4789 -- back in Sem_Prag, but now we delay it to this point, since we
4790 -- don't want to set this flag if we wrap an imported subprogram.
4794 end Wrap_Imported_Subprogram
;
4798 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4800 -- Start of processing for Freeze_Entity
4803 -- The entity being frozen may be subject to pragma Ghost. Set the mode
4804 -- now to ensure that any nodes generated during freezing are properly
4805 -- flagged as Ghost.
4807 Set_Ghost_Mode_From_Entity
(E
);
4809 -- We are going to test for various reasons why this entity need not be
4810 -- frozen here, but in the case of an Itype that's defined within a
4811 -- record, that test actually applies to the record.
4813 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
4814 Test_E
:= Scope
(E
);
4815 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
4816 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
4818 Test_E
:= Underlying_Type
(Scope
(E
));
4821 -- Do not freeze if already frozen since we only need one freeze node
4823 if Is_Frozen
(E
) then
4824 Ghost_Mode
:= Save_Ghost_Mode
;
4827 -- It is improper to freeze an external entity within a generic because
4828 -- its freeze node will appear in a non-valid context. The entity will
4829 -- be frozen in the proper scope after the current generic is analyzed.
4830 -- However, aspects must be analyzed because they may be queried later
4831 -- within the generic itself, and the corresponding pragma or attribute
4832 -- definition has not been analyzed yet.
4834 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
4835 if Has_Delayed_Aspects
(E
) then
4836 Analyze_Aspects_At_Freeze_Point
(E
);
4839 Ghost_Mode
:= Save_Ghost_Mode
;
4842 -- AI05-0213: A formal incomplete type does not freeze the actual. In
4843 -- the instance, the same applies to the subtype renaming the actual.
4845 elsif Is_Private_Type
(E
)
4846 and then Is_Generic_Actual_Type
(E
)
4847 and then No
(Full_View
(Base_Type
(E
)))
4848 and then Ada_Version
>= Ada_2012
4850 Ghost_Mode
:= Save_Ghost_Mode
;
4853 -- Formal subprograms are never frozen
4855 elsif Is_Formal_Subprogram
(E
) then
4856 Ghost_Mode
:= Save_Ghost_Mode
;
4859 -- Generic types are never frozen as they lack delayed semantic checks
4861 elsif Is_Generic_Type
(E
) then
4862 Ghost_Mode
:= Save_Ghost_Mode
;
4865 -- Do not freeze a global entity within an inner scope created during
4866 -- expansion. A call to subprogram E within some internal procedure
4867 -- (a stream attribute for example) might require freezing E, but the
4868 -- freeze node must appear in the same declarative part as E itself.
4869 -- The two-pass elaboration mechanism in gigi guarantees that E will
4870 -- be frozen before the inner call is elaborated. We exclude constants
4871 -- from this test, because deferred constants may be frozen early, and
4872 -- must be diagnosed (e.g. in the case of a deferred constant being used
4873 -- in a default expression). If the enclosing subprogram comes from
4874 -- source, or is a generic instance, then the freeze point is the one
4875 -- mandated by the language, and we freeze the entity. A subprogram that
4876 -- is a child unit body that acts as a spec does not have a spec that
4877 -- comes from source, but can only come from source.
4879 elsif In_Open_Scopes
(Scope
(Test_E
))
4880 and then Scope
(Test_E
) /= Current_Scope
4881 and then Ekind
(Test_E
) /= E_Constant
4888 while Present
(S
) loop
4889 if Is_Overloadable
(S
) then
4890 if Comes_From_Source
(S
)
4891 or else Is_Generic_Instance
(S
)
4892 or else Is_Child_Unit
(S
)
4896 Ghost_Mode
:= Save_Ghost_Mode
;
4905 -- Similarly, an inlined instance body may make reference to global
4906 -- entities, but these references cannot be the proper freezing point
4907 -- for them, and in the absence of inlining freezing will take place in
4908 -- their own scope. Normally instance bodies are analyzed after the
4909 -- enclosing compilation, and everything has been frozen at the proper
4910 -- place, but with front-end inlining an instance body is compiled
4911 -- before the end of the enclosing scope, and as a result out-of-order
4912 -- freezing must be prevented.
4914 elsif Front_End_Inlining
4915 and then In_Instance_Body
4916 and then Present
(Scope
(Test_E
))
4922 S
:= Scope
(Test_E
);
4923 while Present
(S
) loop
4924 if Is_Generic_Instance
(S
) then
4932 Ghost_Mode
:= Save_Ghost_Mode
;
4937 elsif Ekind
(E
) = E_Generic_Package
then
4938 Result
:= Freeze_Generic_Entities
(E
);
4940 Ghost_Mode
:= Save_Ghost_Mode
;
4944 -- Add checks to detect proper initialization of scalars that may appear
4945 -- as subprogram parameters.
4947 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
4948 Apply_Parameter_Validity_Checks
(E
);
4951 -- Deal with delayed aspect specifications. The analysis of the aspect
4952 -- is required to be delayed to the freeze point, thus we analyze the
4953 -- pragma or attribute definition clause in the tree at this point. We
4954 -- also analyze the aspect specification node at the freeze point when
4955 -- the aspect doesn't correspond to pragma/attribute definition clause.
4957 if Has_Delayed_Aspects
(E
) then
4958 Analyze_Aspects_At_Freeze_Point
(E
);
4961 -- Here to freeze the entity
4965 -- Case of entity being frozen is other than a type
4967 if not Is_Type
(E
) then
4969 -- If entity is exported or imported and does not have an external
4970 -- name, now is the time to provide the appropriate default name.
4971 -- Skip this if the entity is stubbed, since we don't need a name
4972 -- for any stubbed routine. For the case on intrinsics, if no
4973 -- external name is specified, then calls will be handled in
4974 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
4975 -- external name is provided, then Expand_Intrinsic_Call leaves
4976 -- calls in place for expansion by GIGI.
4978 if (Is_Imported
(E
) or else Is_Exported
(E
))
4979 and then No
(Interface_Name
(E
))
4980 and then Convention
(E
) /= Convention_Stubbed
4981 and then Convention
(E
) /= Convention_Intrinsic
4983 Set_Encoded_Interface_Name
4984 (E
, Get_Default_External_Name
(E
));
4986 -- If entity is an atomic object appearing in a declaration and
4987 -- the expression is an aggregate, assign it to a temporary to
4988 -- ensure that the actual assignment is done atomically rather
4989 -- than component-wise (the assignment to the temp may be done
4990 -- component-wise, but that is harmless).
4992 elsif Is_Atomic_Or_VFA
(E
)
4993 and then Nkind
(Parent
(E
)) = N_Object_Declaration
4994 and then Present
(Expression
(Parent
(E
)))
4995 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
4996 and then Is_Atomic_VFA_Aggregate
(Expression
(Parent
(E
)))
5003 if Is_Subprogram
(E
) then
5005 -- Check for needing to wrap imported subprogram
5007 Wrap_Imported_Subprogram
(E
);
5009 -- Freeze all parameter types and the return type (RM 13.14(14)).
5010 -- However skip this for internal subprograms. This is also where
5011 -- any extra formal parameters are created since we now know
5012 -- whether the subprogram will use a foreign convention.
5014 -- In Ada 2012, freezing a subprogram does not always freeze the
5015 -- corresponding profile (see AI05-019). An attribute reference
5016 -- is not a freezing point of the profile. Flag Do_Freeze_Profile
5017 -- indicates whether the profile should be frozen now.
5018 -- Other constructs that should not freeze ???
5020 -- This processing doesn't apply to internal entities (see below)
5022 -- Disable this mechanism for now, to fix regressions in ASIS and
5023 -- various ACATS tests. Implementation of AI05-019 remains
5026 if not Is_Internal
(E
)
5027 and then (Do_Freeze_Profile
or else True)
5029 if not Freeze_Profile
(E
) then
5030 Ghost_Mode
:= Save_Ghost_Mode
;
5035 -- Must freeze its parent first if it is a derived subprogram
5037 if Present
(Alias
(E
)) then
5038 Freeze_And_Append
(Alias
(E
), N
, Result
);
5041 -- We don't freeze internal subprograms, because we don't normally
5042 -- want addition of extra formals or mechanism setting to happen
5043 -- for those. However we do pass through predefined dispatching
5044 -- cases, since extra formals may be needed in some cases, such as
5045 -- for the stream 'Input function (build-in-place formals).
5047 if not Is_Internal
(E
)
5048 or else Is_Predefined_Dispatching_Operation
(E
)
5050 Freeze_Subprogram
(E
);
5053 -- If warning on suspicious contracts then check for the case of
5054 -- a postcondition other than False for a No_Return subprogram.
5057 and then Warn_On_Suspicious_Contract
5058 and then Present
(Contract
(E
))
5061 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
5065 while Present
(Prag
) loop
5066 if Nam_In
(Pragma_Name
(Prag
), Name_Post
,
5072 (First
(Pragma_Argument_Associations
(Prag
)));
5074 if Nkind
(Exp
) /= N_Identifier
5075 or else Chars
(Exp
) /= Name_False
5078 ("useless postcondition, & is marked "
5079 & "No_Return?T?", Exp
, E
);
5083 Prag
:= Next_Pragma
(Prag
);
5088 -- Here for other than a subprogram or type
5091 -- If entity has a type, and it is not a generic unit, then
5092 -- freeze it first (RM 13.14(10)).
5094 if Present
(Etype
(E
))
5095 and then Ekind
(E
) /= E_Generic_Function
5097 Freeze_And_Append
(Etype
(E
), N
, Result
);
5099 -- For an object of an anonymous array type, aspects on the
5100 -- object declaration apply to the type itself. This is the
5101 -- case for Atomic_Components, Volatile_Components, and
5102 -- Independent_Components. In these cases analysis of the
5103 -- generated pragma will mark the anonymous types accordingly,
5104 -- and the object itself does not require a freeze node.
5106 if Ekind
(E
) = E_Variable
5107 and then Is_Itype
(Etype
(E
))
5108 and then Is_Array_Type
(Etype
(E
))
5109 and then Has_Delayed_Aspects
(E
)
5111 Set_Has_Delayed_Aspects
(E
, False);
5112 Set_Has_Delayed_Freeze
(E
, False);
5113 Set_Freeze_Node
(E
, Empty
);
5117 -- Special processing for objects created by object declaration
5119 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
5120 Freeze_Object_Declaration
(E
);
5123 -- Check that a constant which has a pragma Volatile[_Components]
5124 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
5126 -- Note: Atomic[_Components] also sets Volatile[_Components]
5128 if Ekind
(E
) = E_Constant
5129 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
5130 and then not Is_Imported
(E
)
5131 and then not Has_Boolean_Aspect_Import
(E
)
5133 -- Make sure we actually have a pragma, and have not merely
5134 -- inherited the indication from elsewhere (e.g. an address
5135 -- clause, which is not good enough in RM terms).
5137 if Has_Rep_Pragma
(E
, Name_Atomic
)
5139 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
5142 ("stand alone atomic constant must be " &
5143 "imported (RM C.6(13))", E
);
5145 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
5147 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
5150 ("stand alone volatile constant must be " &
5151 "imported (RM C.6(13))", E
);
5155 -- Static objects require special handling
5157 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
5158 and then Is_Statically_Allocated
(E
)
5160 Freeze_Static_Object
(E
);
5163 -- Remaining step is to layout objects
5165 if Ekind_In
(E
, E_Variable
, E_Constant
, E_Loop_Parameter
)
5166 or else Is_Formal
(E
)
5171 -- For an object that does not have delayed freezing, and whose
5172 -- initialization actions have been captured in a compound
5173 -- statement, move them back now directly within the enclosing
5174 -- statement sequence.
5176 if Ekind_In
(E
, E_Constant
, E_Variable
)
5177 and then not Has_Delayed_Freeze
(E
)
5179 Explode_Initialization_Compound_Statement
(E
);
5183 -- Case of a type or subtype being frozen
5186 -- We used to check here that a full type must have preelaborable
5187 -- initialization if it completes a private type specified with
5188 -- pragma Preelaborable_Initialization, but that missed cases where
5189 -- the types occur within a generic package, since the freezing
5190 -- that occurs within a containing scope generally skips traversal
5191 -- of a generic unit's declarations (those will be frozen within
5192 -- instances). This check was moved to Analyze_Package_Specification.
5194 -- The type may be defined in a generic unit. This can occur when
5195 -- freezing a generic function that returns the type (which is
5196 -- defined in a parent unit). It is clearly meaningless to freeze
5197 -- this type. However, if it is a subtype, its size may be determi-
5198 -- nable and used in subsequent checks, so might as well try to
5201 -- In Ada 2012, Freeze_Entities is also used in the front end to
5202 -- trigger the analysis of aspect expressions, so in this case we
5203 -- want to continue the freezing process.
5205 if Present
(Scope
(E
))
5206 and then Is_Generic_Unit
(Scope
(E
))
5208 (not Has_Predicates
(E
)
5209 and then not Has_Delayed_Freeze
(E
))
5211 Check_Compile_Time_Size
(E
);
5212 Ghost_Mode
:= Save_Ghost_Mode
;
5216 -- Check for error of Type_Invariant'Class applied to an untagged
5217 -- type (check delayed to freeze time when full type is available).
5220 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
5223 and then Class_Present
(Prag
)
5224 and then not Is_Tagged_Type
(E
)
5227 ("Type_Invariant''Class cannot be specified for &",
5230 ("\can only be specified for a tagged type", Prag
);
5234 if Is_Ghost_Entity
(E
) then
5236 -- A Ghost type cannot be concurrent (SPARK RM 6.9(19)). Verify
5237 -- this legality rule first to five a finer-grained diagnostic.
5239 if Is_Concurrent_Type
(E
) then
5240 Error_Msg_N
("ghost type & cannot be concurrent", E
);
5242 -- A Ghost type cannot be effectively volatile (SPARK RM 6.9(7))
5244 elsif Is_Effectively_Volatile
(E
) then
5245 Error_Msg_N
("ghost type & cannot be volatile", E
);
5249 -- Deal with special cases of freezing for subtype
5251 if E
/= Base_Type
(E
) then
5253 -- Before we do anything else, a specific test for the case of a
5254 -- size given for an array where the array would need to be packed
5255 -- in order for the size to be honored, but is not. This is the
5256 -- case where implicit packing may apply. The reason we do this so
5257 -- early is that, if we have implicit packing, the layout of the
5258 -- base type is affected, so we must do this before we freeze the
5261 -- We could do this processing only if implicit packing is enabled
5262 -- since in all other cases, the error would be caught by the back
5263 -- end. However, we choose to do the check even if we do not have
5264 -- implicit packing enabled, since this allows us to give a more
5265 -- useful error message (advising use of pragma Implicit_Packing
5268 if Is_Array_Type
(E
) then
5270 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
5271 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
5272 SZ
: constant Node_Id
:= Size_Clause
(E
);
5273 Btyp
: constant Entity_Id
:= Base_Type
(E
);
5280 Num_Elmts
: Uint
:= Uint_1
;
5281 -- Number of elements in array
5284 -- Check enabling conditions. These are straightforward
5285 -- except for the test for a limited composite type. This
5286 -- eliminates the rare case of a array of limited components
5287 -- where there are issues of whether or not we can go ahead
5288 -- and pack the array (since we can't freely pack and unpack
5289 -- arrays if they are limited).
5291 -- Note that we check the root type explicitly because the
5292 -- whole point is we are doing this test before we have had
5293 -- a chance to freeze the base type (and it is that freeze
5294 -- action that causes stuff to be inherited).
5296 -- The conditions on the size are identical to those used in
5297 -- Freeze_Array_Type to set the Is_Packed flag.
5299 if Has_Size_Clause
(E
)
5300 and then Known_Static_RM_Size
(E
)
5301 and then not Is_Packed
(E
)
5302 and then not Has_Pragma_Pack
(E
)
5303 and then not Has_Component_Size_Clause
(E
)
5304 and then Known_Static_RM_Size
(Ctyp
)
5306 and then not (Addressable
(Rsiz
)
5307 and then Known_Static_Esize
(Ctyp
)
5308 and then Esize
(Ctyp
) = Rsiz
)
5309 and then not (Rsiz
mod System_Storage_Unit
= 0
5310 and then Is_Composite_Type
(Ctyp
))
5311 and then not Is_Limited_Composite
(E
)
5312 and then not Is_Packed
(Root_Type
(E
))
5313 and then not Has_Component_Size_Clause
(Root_Type
(E
))
5314 and then not (CodePeer_Mode
or GNATprove_Mode
)
5316 -- Compute number of elements in array
5318 Indx
:= First_Index
(E
);
5319 while Present
(Indx
) loop
5320 Get_Index_Bounds
(Indx
, Lo
, Hi
);
5322 if not (Compile_Time_Known_Value
(Lo
)
5324 Compile_Time_Known_Value
(Hi
))
5326 goto No_Implicit_Packing
;
5329 Dim
:= Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1;
5332 Num_Elmts
:= Num_Elmts
* Dim
;
5334 Num_Elmts
:= Uint_0
;
5340 -- What we are looking for here is the situation where
5341 -- the RM_Size given would be exactly right if there was
5342 -- a pragma Pack, resulting in the component size being
5343 -- the RM_Size of the component type.
5345 if RM_Size
(E
) = Num_Elmts
* Rsiz
then
5346 -- For implicit packing mode, just set the component
5347 -- size and Freeze_Array_Type will do the rest.
5349 if Implicit_Packing
then
5350 Set_Component_Size
(Btyp
, Rsiz
);
5352 -- Otherwise give an error message
5356 ("size given for& too small", SZ
, E
);
5357 Error_Msg_N
-- CODEFIX
5358 ("\use explicit pragma Pack "
5359 & "or use pragma Implicit_Packing", SZ
);
5366 <<No_Implicit_Packing
>>
5368 -- If ancestor subtype present, freeze that first. Note that this
5369 -- will also get the base type frozen. Need RM reference ???
5371 Atype
:= Ancestor_Subtype
(E
);
5373 if Present
(Atype
) then
5374 Freeze_And_Append
(Atype
, N
, Result
);
5376 -- No ancestor subtype present
5379 -- See if we have a nearest ancestor that has a predicate.
5380 -- That catches the case of derived type with a predicate.
5381 -- Need RM reference here ???
5383 Atype
:= Nearest_Ancestor
(E
);
5385 if Present
(Atype
) and then Has_Predicates
(Atype
) then
5386 Freeze_And_Append
(Atype
, N
, Result
);
5389 -- Freeze base type before freezing the entity (RM 13.14(15))
5391 if E
/= Base_Type
(E
) then
5392 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
5396 -- A subtype inherits all the type-related representation aspects
5397 -- from its parents (RM 13.1(8)).
5399 Inherit_Aspects_At_Freeze_Point
(E
);
5401 -- For a derived type, freeze its parent type first (RM 13.14(15))
5403 elsif Is_Derived_Type
(E
) then
5404 Freeze_And_Append
(Etype
(E
), N
, Result
);
5405 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
5407 -- A derived type inherits each type-related representation aspect
5408 -- of its parent type that was directly specified before the
5409 -- declaration of the derived type (RM 13.1(15)).
5411 Inherit_Aspects_At_Freeze_Point
(E
);
5414 -- Check for incompatible size and alignment for record type
5416 if Warn_On_Size_Alignment
5417 and then Is_Record_Type
(E
)
5418 and then Has_Size_Clause
(E
) and then Has_Alignment_Clause
(E
)
5420 -- If explicit Object_Size clause given assume that the programmer
5421 -- knows what he is doing, and expects the compiler behavior.
5423 and then not Has_Object_Size_Clause
(E
)
5425 -- Check for size not a multiple of alignment
5427 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
5430 SC
: constant Node_Id
:= Size_Clause
(E
);
5431 AC
: constant Node_Id
:= Alignment_Clause
(E
);
5433 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
5436 if Present
(SC
) and then Present
(AC
) then
5440 if Sloc
(SC
) > Sloc
(AC
) then
5443 ("?Z?size is not a multiple of alignment for &",
5445 Error_Msg_Sloc
:= Sloc
(AC
);
5446 Error_Msg_Uint_1
:= Alignment
(E
);
5447 Error_Msg_N
("\?Z?alignment of ^ specified #", Loc
);
5452 ("?Z?size is not a multiple of alignment for &",
5454 Error_Msg_Sloc
:= Sloc
(SC
);
5455 Error_Msg_Uint_1
:= RM_Size
(E
);
5456 Error_Msg_N
("\?Z?size of ^ specified #", Loc
);
5459 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
5460 Error_Msg_N
("\?Z?Object_Size will be increased to ^", Loc
);
5467 if Is_Array_Type
(E
) then
5468 Freeze_Array_Type
(E
);
5470 -- For a class-wide type, the corresponding specific type is
5471 -- frozen as well (RM 13.14(15))
5473 elsif Is_Class_Wide_Type
(E
) then
5474 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
5476 -- If the base type of the class-wide type is still incomplete,
5477 -- the class-wide remains unfrozen as well. This is legal when
5478 -- E is the formal of a primitive operation of some other type
5479 -- which is being frozen.
5481 if not Is_Frozen
(Root_Type
(E
)) then
5482 Set_Is_Frozen
(E
, False);
5483 Ghost_Mode
:= Save_Ghost_Mode
;
5487 -- The equivalent type associated with a class-wide subtype needs
5488 -- to be frozen to ensure that its layout is done.
5490 if Ekind
(E
) = E_Class_Wide_Subtype
5491 and then Present
(Equivalent_Type
(E
))
5493 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5496 -- Generate an itype reference for a library-level class-wide type
5497 -- at the freeze point. Otherwise the first explicit reference to
5498 -- the type may appear in an inner scope which will be rejected by
5502 and then Is_Compilation_Unit
(Scope
(E
))
5505 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
5510 -- From a gigi point of view, a class-wide subtype derives
5511 -- from its record equivalent type. As a result, the itype
5512 -- reference must appear after the freeze node of the
5513 -- equivalent type or gigi will reject the reference.
5515 if Ekind
(E
) = E_Class_Wide_Subtype
5516 and then Present
(Equivalent_Type
(E
))
5518 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
5520 Add_To_Result
(Ref
);
5525 -- For a record type or record subtype, freeze all component types
5526 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
5527 -- using Is_Record_Type, because we don't want to attempt the freeze
5528 -- for the case of a private type with record extension (we will do
5529 -- that later when the full type is frozen).
5531 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
)
5532 and then not (Present
(Scope
(E
))
5533 and then Is_Generic_Unit
(Scope
(E
)))
5535 Freeze_Record_Type
(E
);
5537 -- For a concurrent type, freeze corresponding record type. This does
5538 -- not correspond to any specific rule in the RM, but the record type
5539 -- is essentially part of the concurrent type. Also freeze all local
5540 -- entities. This includes record types created for entry parameter
5541 -- blocks and whatever local entities may appear in the private part.
5543 elsif Is_Concurrent_Type
(E
) then
5544 if Present
(Corresponding_Record_Type
(E
)) then
5545 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
5548 Comp
:= First_Entity
(E
);
5549 while Present
(Comp
) loop
5550 if Is_Type
(Comp
) then
5551 Freeze_And_Append
(Comp
, N
, Result
);
5553 elsif (Ekind
(Comp
)) /= E_Function
then
5555 -- The guard on the presence of the Etype seems to be needed
5556 -- for some CodePeer (-gnatcC) cases, but not clear why???
5558 if Present
(Etype
(Comp
)) then
5559 if Is_Itype
(Etype
(Comp
))
5560 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
5562 Undelay_Type
(Etype
(Comp
));
5565 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5572 -- Private types are required to point to the same freeze node as
5573 -- their corresponding full views. The freeze node itself has to
5574 -- point to the partial view of the entity (because from the partial
5575 -- view, we can retrieve the full view, but not the reverse).
5576 -- However, in order to freeze correctly, we need to freeze the full
5577 -- view. If we are freezing at the end of a scope (or within the
5578 -- scope) of the private type, the partial and full views will have
5579 -- been swapped, the full view appears first in the entity chain and
5580 -- the swapping mechanism ensures that the pointers are properly set
5583 -- If we encounter the partial view before the full view (e.g. when
5584 -- freezing from another scope), we freeze the full view, and then
5585 -- set the pointers appropriately since we cannot rely on swapping to
5586 -- fix things up (subtypes in an outer scope might not get swapped).
5588 -- If the full view is itself private, the above requirements apply
5589 -- to the underlying full view instead of the full view. But there is
5590 -- no swapping mechanism for the underlying full view so we need to
5591 -- set the pointers appropriately in both cases.
5593 elsif Is_Incomplete_Or_Private_Type
(E
)
5594 and then not Is_Generic_Type
(E
)
5596 -- The construction of the dispatch table associated with library
5597 -- level tagged types forces freezing of all the primitives of the
5598 -- type, which may cause premature freezing of the partial view.
5602 -- type T is tagged private;
5603 -- type DT is new T with private;
5604 -- procedure Prim (X : in out T; Y : in out DT'Class);
5606 -- type T is tagged null record;
5608 -- type DT is new T with null record;
5611 -- In this case the type will be frozen later by the usual
5612 -- mechanism: an object declaration, an instantiation, or the
5613 -- end of a declarative part.
5615 if Is_Library_Level_Tagged_Type
(E
)
5616 and then not Present
(Full_View
(E
))
5618 Set_Is_Frozen
(E
, False);
5619 Ghost_Mode
:= Save_Ghost_Mode
;
5622 -- Case of full view present
5624 elsif Present
(Full_View
(E
)) then
5626 -- If full view has already been frozen, then no further
5627 -- processing is required
5629 if Is_Frozen
(Full_View
(E
)) then
5630 Set_Has_Delayed_Freeze
(E
, False);
5631 Set_Freeze_Node
(E
, Empty
);
5633 -- Otherwise freeze full view and patch the pointers so that
5634 -- the freeze node will elaborate both views in the back end.
5635 -- However, if full view is itself private, freeze underlying
5636 -- full view instead and patch the pointers so that the freeze
5637 -- node will elaborate the three views in the back end.
5641 Full
: Entity_Id
:= Full_View
(E
);
5644 if Is_Private_Type
(Full
)
5645 and then Present
(Underlying_Full_View
(Full
))
5647 Full
:= Underlying_Full_View
(Full
);
5650 Freeze_And_Append
(Full
, N
, Result
);
5652 if Full
/= Full_View
(E
)
5653 and then Has_Delayed_Freeze
(Full_View
(E
))
5655 F_Node
:= Freeze_Node
(Full
);
5657 if Present
(F_Node
) then
5658 Set_Freeze_Node
(Full_View
(E
), F_Node
);
5659 Set_Entity
(F_Node
, Full_View
(E
));
5662 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
5663 Set_Freeze_Node
(Full_View
(E
), Empty
);
5667 if Has_Delayed_Freeze
(E
) then
5668 F_Node
:= Freeze_Node
(Full_View
(E
));
5670 if Present
(F_Node
) then
5671 Set_Freeze_Node
(E
, F_Node
);
5672 Set_Entity
(F_Node
, E
);
5675 -- {Incomplete,Private}_Subtypes with Full_Views
5676 -- constrained by discriminants.
5678 Set_Has_Delayed_Freeze
(E
, False);
5679 Set_Freeze_Node
(E
, Empty
);
5685 Check_Debug_Info_Needed
(E
);
5687 -- AI-117 requires that the convention of a partial view be the
5688 -- same as the convention of the full view. Note that this is a
5689 -- recognized breach of privacy, but it's essential for logical
5690 -- consistency of representation, and the lack of a rule in
5691 -- RM95 was an oversight.
5693 Set_Convention
(E
, Convention
(Full_View
(E
)));
5695 Set_Size_Known_At_Compile_Time
(E
,
5696 Size_Known_At_Compile_Time
(Full_View
(E
)));
5698 -- Size information is copied from the full view to the
5699 -- incomplete or private view for consistency.
5701 -- We skip this is the full view is not a type. This is very
5702 -- strange of course, and can only happen as a result of
5703 -- certain illegalities, such as a premature attempt to derive
5704 -- from an incomplete type.
5706 if Is_Type
(Full_View
(E
)) then
5707 Set_Size_Info
(E
, Full_View
(E
));
5708 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
5711 Ghost_Mode
:= Save_Ghost_Mode
;
5714 -- Case of underlying full view present
5716 elsif Is_Private_Type
(E
)
5717 and then Present
(Underlying_Full_View
(E
))
5719 if not Is_Frozen
(Underlying_Full_View
(E
)) then
5720 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
5723 -- Patch the pointers so that the freeze node will elaborate
5724 -- both views in the back end.
5726 if Has_Delayed_Freeze
(E
) then
5727 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
5729 if Present
(F_Node
) then
5730 Set_Freeze_Node
(E
, F_Node
);
5731 Set_Entity
(F_Node
, E
);
5734 Set_Has_Delayed_Freeze
(E
, False);
5735 Set_Freeze_Node
(E
, Empty
);
5739 Check_Debug_Info_Needed
(E
);
5741 Ghost_Mode
:= Save_Ghost_Mode
;
5744 -- Case of no full view present. If entity is derived or subtype,
5745 -- it is safe to freeze, correctness depends on the frozen status
5746 -- of parent. Otherwise it is either premature usage, or a Taft
5747 -- amendment type, so diagnosis is at the point of use and the
5748 -- type might be frozen later.
5750 elsif E
/= Base_Type
(E
) or else Is_Derived_Type
(E
) then
5754 Set_Is_Frozen
(E
, False);
5755 Ghost_Mode
:= Save_Ghost_Mode
;
5759 -- For access subprogram, freeze types of all formals, the return
5760 -- type was already frozen, since it is the Etype of the function.
5761 -- Formal types can be tagged Taft amendment types, but otherwise
5762 -- they cannot be incomplete.
5764 elsif Ekind
(E
) = E_Subprogram_Type
then
5765 Formal
:= First_Formal
(E
);
5766 while Present
(Formal
) loop
5767 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
5768 and then No
(Full_View
(Etype
(Formal
)))
5770 if Is_Tagged_Type
(Etype
(Formal
)) then
5773 -- AI05-151: Incomplete types are allowed in access to
5774 -- subprogram specifications.
5776 elsif Ada_Version
< Ada_2012
then
5778 ("invalid use of incomplete type&", E
, Etype
(Formal
));
5782 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
5783 Next_Formal
(Formal
);
5786 Freeze_Subprogram
(E
);
5788 -- For access to a protected subprogram, freeze the equivalent type
5789 -- (however this is not set if we are not generating code or if this
5790 -- is an anonymous type used just for resolution).
5792 elsif Is_Access_Protected_Subprogram_Type
(E
) then
5793 if Present
(Equivalent_Type
(E
)) then
5794 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5798 -- Generic types are never seen by the back-end, and are also not
5799 -- processed by the expander (since the expander is turned off for
5800 -- generic processing), so we never need freeze nodes for them.
5802 if Is_Generic_Type
(E
) then
5803 Ghost_Mode
:= Save_Ghost_Mode
;
5807 -- Some special processing for non-generic types to complete
5808 -- representation details not known till the freeze point.
5810 if Is_Fixed_Point_Type
(E
) then
5811 Freeze_Fixed_Point_Type
(E
);
5813 -- Some error checks required for ordinary fixed-point type. Defer
5814 -- these till the freeze-point since we need the small and range
5815 -- values. We only do these checks for base types
5817 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
5818 if Small_Value
(E
) < Ureal_2_M_80
then
5819 Error_Msg_Name_1
:= Name_Small
;
5821 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
5823 elsif Small_Value
(E
) > Ureal_2_80
then
5824 Error_Msg_Name_1
:= Name_Small
;
5826 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
5829 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
5830 Error_Msg_Name_1
:= Name_First
;
5832 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
5835 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
5836 Error_Msg_Name_1
:= Name_Last
;
5838 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
5842 elsif Is_Enumeration_Type
(E
) then
5843 Freeze_Enumeration_Type
(E
);
5845 elsif Is_Integer_Type
(E
) then
5846 Adjust_Esize_For_Alignment
(E
);
5848 if Is_Modular_Integer_Type
(E
)
5849 and then Warn_On_Suspicious_Modulus_Value
5851 Check_Suspicious_Modulus
(E
);
5854 -- The pool applies to named and anonymous access types, but not
5855 -- to subprogram and to internal types generated for 'Access
5858 elsif Is_Access_Type
(E
)
5859 and then not Is_Access_Subprogram_Type
(E
)
5860 and then Ekind
(E
) /= E_Access_Attribute_Type
5862 -- If a pragma Default_Storage_Pool applies, and this type has no
5863 -- Storage_Pool or Storage_Size clause (which must have occurred
5864 -- before the freezing point), then use the default. This applies
5865 -- only to base types.
5867 -- None of this applies to access to subprograms, for which there
5868 -- are clearly no pools.
5870 if Present
(Default_Pool
)
5871 and then Is_Base_Type
(E
)
5872 and then not Has_Storage_Size_Clause
(E
)
5873 and then No
(Associated_Storage_Pool
(E
))
5875 -- Case of pragma Default_Storage_Pool (null)
5877 if Nkind
(Default_Pool
) = N_Null
then
5878 Set_No_Pool_Assigned
(E
);
5880 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
5883 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
5887 -- Check restriction for standard storage pool
5889 if No
(Associated_Storage_Pool
(E
)) then
5890 Check_Restriction
(No_Standard_Storage_Pools
, E
);
5893 -- Deal with error message for pure access type. This is not an
5894 -- error in Ada 2005 if there is no pool (see AI-366).
5896 if Is_Pure_Unit_Access_Type
(E
)
5897 and then (Ada_Version
< Ada_2005
5898 or else not No_Pool_Assigned
(E
))
5899 and then not Is_Generic_Unit
(Scope
(E
))
5901 Error_Msg_N
("named access type not allowed in pure unit", E
);
5903 if Ada_Version
>= Ada_2005
then
5905 ("\would be legal if Storage_Size of 0 given??", E
);
5907 elsif No_Pool_Assigned
(E
) then
5909 ("\would be legal in Ada 2005??", E
);
5913 ("\would be legal in Ada 2005 if "
5914 & "Storage_Size of 0 given??", E
);
5919 -- Case of composite types
5921 if Is_Composite_Type
(E
) then
5923 -- AI-117 requires that all new primitives of a tagged type must
5924 -- inherit the convention of the full view of the type. Inherited
5925 -- and overriding operations are defined to inherit the convention
5926 -- of their parent or overridden subprogram (also specified in
5927 -- AI-117), which will have occurred earlier (in Derive_Subprogram
5928 -- and New_Overloaded_Entity). Here we set the convention of
5929 -- primitives that are still convention Ada, which will ensure
5930 -- that any new primitives inherit the type's convention. Class-
5931 -- wide types can have a foreign convention inherited from their
5932 -- specific type, but are excluded from this since they don't have
5933 -- any associated primitives.
5935 if Is_Tagged_Type
(E
)
5936 and then not Is_Class_Wide_Type
(E
)
5937 and then Convention
(E
) /= Convention_Ada
5940 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
5944 Prim
:= First_Elmt
(Prim_List
);
5945 while Present
(Prim
) loop
5946 if Convention
(Node
(Prim
)) = Convention_Ada
then
5947 Set_Convention
(Node
(Prim
), Convention
(E
));
5955 -- If the type is a simple storage pool type, then this is where
5956 -- we attempt to locate and validate its Allocate, Deallocate, and
5957 -- Storage_Size operations (the first is required, and the latter
5958 -- two are optional). We also verify that the full type for a
5959 -- private type is allowed to be a simple storage pool type.
5961 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
5962 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
5964 -- If the type is marked Has_Private_Declaration, then this is
5965 -- a full type for a private type that was specified with the
5966 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
5967 -- pragma is allowed for the full type (for example, it can't
5968 -- be an array type, or a nonlimited record type).
5970 if Has_Private_Declaration
(E
) then
5971 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
5972 and then not Is_Private_Type
(E
)
5974 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
5976 ("pragma% can only apply to full type that is an " &
5977 "explicitly limited type", E
);
5981 Validate_Simple_Pool_Ops
: declare
5982 Pool_Type
: Entity_Id
renames E
;
5983 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
5984 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
5986 procedure Validate_Simple_Pool_Op_Formal
5987 (Pool_Op
: Entity_Id
;
5988 Pool_Op_Formal
: in out Entity_Id
;
5989 Expected_Mode
: Formal_Kind
;
5990 Expected_Type
: Entity_Id
;
5991 Formal_Name
: String;
5992 OK_Formal
: in out Boolean);
5993 -- Validate one formal Pool_Op_Formal of the candidate pool
5994 -- operation Pool_Op. The formal must be of Expected_Type
5995 -- and have mode Expected_Mode. OK_Formal will be set to
5996 -- False if the formal doesn't match. If OK_Formal is False
5997 -- on entry, then the formal will effectively be ignored
5998 -- (because validation of the pool op has already failed).
5999 -- Upon return, Pool_Op_Formal will be updated to the next
6002 procedure Validate_Simple_Pool_Operation
6003 (Op_Name
: Name_Id
);
6004 -- Search for and validate a simple pool operation with the
6005 -- name Op_Name. If the name is Allocate, then there must be
6006 -- exactly one such primitive operation for the simple pool
6007 -- type. If the name is Deallocate or Storage_Size, then
6008 -- there can be at most one such primitive operation. The
6009 -- profile of the located primitive must conform to what
6010 -- is expected for each operation.
6012 ------------------------------------
6013 -- Validate_Simple_Pool_Op_Formal --
6014 ------------------------------------
6016 procedure Validate_Simple_Pool_Op_Formal
6017 (Pool_Op
: Entity_Id
;
6018 Pool_Op_Formal
: in out Entity_Id
;
6019 Expected_Mode
: Formal_Kind
;
6020 Expected_Type
: Entity_Id
;
6021 Formal_Name
: String;
6022 OK_Formal
: in out Boolean)
6025 -- If OK_Formal is False on entry, then simply ignore
6026 -- the formal, because an earlier formal has already
6029 if not OK_Formal
then
6032 -- If no formal is passed in, then issue an error for a
6035 elsif not Present
(Pool_Op_Formal
) then
6037 ("simple storage pool op missing formal " &
6038 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
6044 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
6046 -- If the pool type was expected for this formal, then
6047 -- this will not be considered a candidate operation
6048 -- for the simple pool, so we unset OK_Formal so that
6049 -- the op and any later formals will be ignored.
6051 if Expected_Type
= Pool_Type
then
6058 ("wrong type for formal " & Formal_Name
&
6059 " of simple storage pool op; expected type&",
6060 Pool_Op_Formal
, Expected_Type
);
6064 -- Issue error if formal's mode is not the expected one
6066 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
6068 ("wrong mode for formal of simple storage pool op",
6072 -- Advance to the next formal
6074 Next_Formal
(Pool_Op_Formal
);
6075 end Validate_Simple_Pool_Op_Formal
;
6077 ------------------------------------
6078 -- Validate_Simple_Pool_Operation --
6079 ------------------------------------
6081 procedure Validate_Simple_Pool_Operation
6085 Found_Op
: Entity_Id
:= Empty
;
6091 (Nam_In
(Op_Name
, Name_Allocate
,
6093 Name_Storage_Size
));
6095 Error_Msg_Name_1
:= Op_Name
;
6097 -- For each homonym declared immediately in the scope
6098 -- of the simple storage pool type, determine whether
6099 -- the homonym is an operation of the pool type, and,
6100 -- if so, check that its profile is as expected for
6101 -- a simple pool operation of that name.
6103 Op
:= Get_Name_Entity_Id
(Op_Name
);
6104 while Present
(Op
) loop
6105 if Ekind_In
(Op
, E_Function
, E_Procedure
)
6106 and then Scope
(Op
) = Current_Scope
6108 Formal
:= First_Entity
(Op
);
6112 -- The first parameter must be of the pool type
6113 -- in order for the operation to qualify.
6115 if Op_Name
= Name_Storage_Size
then
6116 Validate_Simple_Pool_Op_Formal
6117 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
6120 Validate_Simple_Pool_Op_Formal
6121 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
6125 -- If another operation with this name has already
6126 -- been located for the type, then flag an error,
6127 -- since we only allow the type to have a single
6130 if Present
(Found_Op
) and then Is_OK
then
6132 ("only one % operation allowed for " &
6133 "simple storage pool type&", Op
, Pool_Type
);
6136 -- In the case of Allocate and Deallocate, a formal
6137 -- of type System.Address is required.
6139 if Op_Name
= Name_Allocate
then
6140 Validate_Simple_Pool_Op_Formal
6141 (Op
, Formal
, E_Out_Parameter
,
6142 Address_Type
, "Storage_Address", Is_OK
);
6144 elsif Op_Name
= Name_Deallocate
then
6145 Validate_Simple_Pool_Op_Formal
6146 (Op
, Formal
, E_In_Parameter
,
6147 Address_Type
, "Storage_Address", Is_OK
);
6150 -- In the case of Allocate and Deallocate, formals
6151 -- of type Storage_Count are required as the third
6152 -- and fourth parameters.
6154 if Op_Name
/= Name_Storage_Size
then
6155 Validate_Simple_Pool_Op_Formal
6156 (Op
, Formal
, E_In_Parameter
,
6157 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
6158 Validate_Simple_Pool_Op_Formal
6159 (Op
, Formal
, E_In_Parameter
,
6160 Stg_Cnt_Type
, "Alignment", Is_OK
);
6163 -- If no mismatched formals have been found (Is_OK)
6164 -- and no excess formals are present, then this
6165 -- operation has been validated, so record it.
6167 if not Present
(Formal
) and then Is_OK
then
6175 -- There must be a valid Allocate operation for the type,
6176 -- so issue an error if none was found.
6178 if Op_Name
= Name_Allocate
6179 and then not Present
(Found_Op
)
6181 Error_Msg_N
("missing % operation for simple " &
6182 "storage pool type", Pool_Type
);
6184 elsif Present
(Found_Op
) then
6186 -- Simple pool operations can't be abstract
6188 if Is_Abstract_Subprogram
(Found_Op
) then
6190 ("simple storage pool operation must not be " &
6191 "abstract", Found_Op
);
6194 -- The Storage_Size operation must be a function with
6195 -- Storage_Count as its result type.
6197 if Op_Name
= Name_Storage_Size
then
6198 if Ekind
(Found_Op
) = E_Procedure
then
6200 ("% operation must be a function", Found_Op
);
6202 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
6204 ("wrong result type for%, expected type&",
6205 Found_Op
, Stg_Cnt_Type
);
6208 -- Allocate and Deallocate must be procedures
6210 elsif Ekind
(Found_Op
) = E_Function
then
6212 ("% operation must be a procedure", Found_Op
);
6215 end Validate_Simple_Pool_Operation
;
6217 -- Start of processing for Validate_Simple_Pool_Ops
6220 Validate_Simple_Pool_Operation
(Name_Allocate
);
6221 Validate_Simple_Pool_Operation
(Name_Deallocate
);
6222 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
6223 end Validate_Simple_Pool_Ops
;
6227 -- Now that all types from which E may depend are frozen, see if the
6228 -- size is known at compile time, if it must be unsigned, or if
6229 -- strict alignment is required
6231 Check_Compile_Time_Size
(E
);
6232 Check_Unsigned_Type
(E
);
6234 if Base_Type
(E
) = E
then
6235 Check_Strict_Alignment
(E
);
6238 -- Do not allow a size clause for a type which does not have a size
6239 -- that is known at compile time
6241 if Has_Size_Clause
(E
)
6242 and then not Size_Known_At_Compile_Time
(E
)
6244 -- Suppress this message if errors posted on E, even if we are
6245 -- in all errors mode, since this is often a junk message
6247 if not Error_Posted
(E
) then
6249 ("size clause not allowed for variable length type",
6254 -- Now we set/verify the representation information, in particular
6255 -- the size and alignment values. This processing is not required for
6256 -- generic types, since generic types do not play any part in code
6257 -- generation, and so the size and alignment values for such types
6258 -- are irrelevant. Ditto for types declared within a generic unit,
6259 -- which may have components that depend on generic parameters, and
6260 -- that will be recreated in an instance.
6262 if Inside_A_Generic
then
6265 -- Otherwise we call the layout procedure
6271 -- If this is an access to subprogram whose designated type is itself
6272 -- a subprogram type, the return type of this anonymous subprogram
6273 -- type must be decorated as well.
6275 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
6276 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
6278 Layout_Type
(Etype
(Designated_Type
(E
)));
6281 -- If the type has a Defaut_Value/Default_Component_Value aspect,
6282 -- this is where we analye the expression (after the type is frozen,
6283 -- since in the case of Default_Value, we are analyzing with the
6284 -- type itself, and we treat Default_Component_Value similarly for
6285 -- the sake of uniformity).
6287 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
6294 if Is_Scalar_Type
(E
) then
6295 Nam
:= Name_Default_Value
;
6297 Exp
:= Default_Aspect_Value
(Typ
);
6299 Nam
:= Name_Default_Component_Value
;
6300 Typ
:= Component_Type
(E
);
6301 Exp
:= Default_Aspect_Component_Value
(E
);
6304 Analyze_And_Resolve
(Exp
, Typ
);
6306 if Etype
(Exp
) /= Any_Type
then
6307 if not Is_OK_Static_Expression
(Exp
) then
6308 Error_Msg_Name_1
:= Nam
;
6309 Flag_Non_Static_Expr
6310 ("aspect% requires static expression", Exp
);
6316 -- End of freeze processing for type entities
6319 -- Here is where we logically freeze the current entity. If it has a
6320 -- freeze node, then this is the point at which the freeze node is
6321 -- linked into the result list.
6323 if Has_Delayed_Freeze
(E
) then
6325 -- If a freeze node is already allocated, use it, otherwise allocate
6326 -- a new one. The preallocation happens in the case of anonymous base
6327 -- types, where we preallocate so that we can set First_Subtype_Link.
6328 -- Note that we reset the Sloc to the current freeze location.
6330 if Present
(Freeze_Node
(E
)) then
6331 F_Node
:= Freeze_Node
(E
);
6332 Set_Sloc
(F_Node
, Loc
);
6335 F_Node
:= New_Freeze_Node
;
6336 Set_Freeze_Node
(E
, F_Node
);
6337 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
6338 Set_TSS_Elist
(F_Node
, No_Elist
);
6339 Set_Actions
(F_Node
, No_List
);
6342 Set_Entity
(F_Node
, E
);
6343 Add_To_Result
(F_Node
);
6345 -- A final pass over record types with discriminants. If the type
6346 -- has an incomplete declaration, there may be constrained access
6347 -- subtypes declared elsewhere, which do not depend on the discrimi-
6348 -- nants of the type, and which are used as component types (i.e.
6349 -- the full view is a recursive type). The designated types of these
6350 -- subtypes can only be elaborated after the type itself, and they
6351 -- need an itype reference.
6353 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
6360 Comp
:= First_Component
(E
);
6361 while Present
(Comp
) loop
6362 Typ
:= Etype
(Comp
);
6364 if Ekind
(Comp
) = E_Component
6365 and then Is_Access_Type
(Typ
)
6366 and then Scope
(Typ
) /= E
6367 and then Base_Type
(Designated_Type
(Typ
)) = E
6368 and then Is_Itype
(Designated_Type
(Typ
))
6370 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
6371 Set_Itype
(IR
, Designated_Type
(Typ
));
6372 Append
(IR
, Result
);
6375 Next_Component
(Comp
);
6381 -- When a type is frozen, the first subtype of the type is frozen as
6382 -- well (RM 13.14(15)). This has to be done after freezing the type,
6383 -- since obviously the first subtype depends on its own base type.
6386 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
6388 -- If we just froze a tagged non-class wide record, then freeze the
6389 -- corresponding class-wide type. This must be done after the tagged
6390 -- type itself is frozen, because the class-wide type refers to the
6391 -- tagged type which generates the class.
6393 if Is_Tagged_Type
(E
)
6394 and then not Is_Class_Wide_Type
(E
)
6395 and then Present
(Class_Wide_Type
(E
))
6397 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
6401 Check_Debug_Info_Needed
(E
);
6403 -- Special handling for subprograms
6405 if Is_Subprogram
(E
) then
6407 -- If subprogram has address clause then reset Is_Public flag, since
6408 -- we do not want the backend to generate external references.
6410 if Present
(Address_Clause
(E
))
6411 and then not Is_Library_Level_Entity
(E
)
6413 Set_Is_Public
(E
, False);
6417 Ghost_Mode
:= Save_Ghost_Mode
;
6421 -----------------------------
6422 -- Freeze_Enumeration_Type --
6423 -----------------------------
6425 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
6427 -- By default, if no size clause is present, an enumeration type with
6428 -- Convention C is assumed to interface to a C enum, and has integer
6429 -- size. This applies to types. For subtypes, verify that its base
6430 -- type has no size clause either. Treat other foreign conventions
6431 -- in the same way, and also make sure alignment is set right.
6433 if Has_Foreign_Convention
(Typ
)
6434 and then not Has_Size_Clause
(Typ
)
6435 and then not Has_Size_Clause
(Base_Type
(Typ
))
6436 and then Esize
(Typ
) < Standard_Integer_Size
6438 -- Don't do this if Short_Enums on target
6440 and then not Target_Short_Enums
6442 Init_Esize
(Typ
, Standard_Integer_Size
);
6443 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
6445 -- Normal Ada case or size clause present or not Long_C_Enums on target
6448 -- If the enumeration type interfaces to C, and it has a size clause
6449 -- that specifies less than int size, it warrants a warning. The
6450 -- user may intend the C type to be an enum or a char, so this is
6451 -- not by itself an error that the Ada compiler can detect, but it
6452 -- it is a worth a heads-up. For Boolean and Character types we
6453 -- assume that the programmer has the proper C type in mind.
6455 if Convention
(Typ
) = Convention_C
6456 and then Has_Size_Clause
(Typ
)
6457 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
6458 and then not Is_Boolean_Type
(Typ
)
6459 and then not Is_Character_Type
(Typ
)
6461 -- Don't do this if Short_Enums on target
6463 and then not Target_Short_Enums
6466 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
6469 Adjust_Esize_For_Alignment
(Typ
);
6471 end Freeze_Enumeration_Type
;
6473 -----------------------
6474 -- Freeze_Expression --
6475 -----------------------
6477 procedure Freeze_Expression
(N
: Node_Id
) is
6478 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
6481 Desig_Typ
: Entity_Id
;
6485 Freeze_Outside
: Boolean := False;
6486 -- This flag is set true if the entity must be frozen outside the
6487 -- current subprogram. This happens in the case of expander generated
6488 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
6489 -- not freeze all entities like other bodies, but which nevertheless
6490 -- may reference entities that have to be frozen before the body and
6491 -- obviously cannot be frozen inside the body.
6493 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
6494 -- If the expression is an array aggregate, the type of the component
6495 -- expressions is also frozen. If the component type is an access type
6496 -- and the expressions include allocators, the designed type is frozen
6499 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
6500 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
6501 -- it is the handled statement sequence of an expander-generated
6502 -- subprogram (init proc, stream subprogram, or renaming as body).
6503 -- If so, this is not a freezing context.
6505 -----------------------------------------
6506 -- Find_Aggregate_Component_Desig_Type --
6507 -----------------------------------------
6509 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
6514 if Present
(Expressions
(N
)) then
6515 Exp
:= First
(Expressions
(N
));
6516 while Present
(Exp
) loop
6517 if Nkind
(Exp
) = N_Allocator
then
6518 return Designated_Type
(Component_Type
(Etype
(N
)));
6525 if Present
(Component_Associations
(N
)) then
6526 Assoc
:= First
(Component_Associations
(N
));
6527 while Present
(Assoc
) loop
6528 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
6529 return Designated_Type
(Component_Type
(Etype
(N
)));
6537 end Find_Aggregate_Component_Desig_Type
;
6539 ----------------------
6540 -- In_Expanded_Body --
6541 ----------------------
6543 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
6548 if Nkind
(N
) = N_Subprogram_Body
then
6554 if Nkind
(P
) /= N_Subprogram_Body
then
6558 Id
:= Defining_Unit_Name
(Specification
(P
));
6560 -- The following are expander-created bodies, or bodies that
6561 -- are not freeze points.
6563 if Nkind
(Id
) = N_Defining_Identifier
6564 and then (Is_Init_Proc
(Id
)
6565 or else Is_TSS
(Id
, TSS_Stream_Input
)
6566 or else Is_TSS
(Id
, TSS_Stream_Output
)
6567 or else Is_TSS
(Id
, TSS_Stream_Read
)
6568 or else Is_TSS
(Id
, TSS_Stream_Write
)
6569 or else Nkind_In
(Original_Node
(P
),
6570 N_Subprogram_Renaming_Declaration
,
6571 N_Expression_Function
))
6578 end In_Expanded_Body
;
6580 -- Start of processing for Freeze_Expression
6583 -- Immediate return if freezing is inhibited. This flag is set by the
6584 -- analyzer to stop freezing on generated expressions that would cause
6585 -- freezing if they were in the source program, but which are not
6586 -- supposed to freeze, since they are created.
6588 if Must_Not_Freeze
(N
) then
6592 -- If expression is non-static, then it does not freeze in a default
6593 -- expression, see section "Handling of Default Expressions" in the
6594 -- spec of package Sem for further details. Note that we have to make
6595 -- sure that we actually have a real expression (if we have a subtype
6596 -- indication, we can't test Is_OK_Static_Expression). However, we
6597 -- exclude the case of the prefix of an attribute of a static scalar
6598 -- subtype from this early return, because static subtype attributes
6599 -- should always cause freezing, even in default expressions, but
6600 -- the attribute may not have been marked as static yet (because in
6601 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
6602 -- Freeze_Expression on the prefix).
6605 and then Nkind
(N
) in N_Subexpr
6606 and then not Is_OK_Static_Expression
(N
)
6607 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
6608 or else not (Is_Entity_Name
(N
)
6609 and then Is_Type
(Entity
(N
))
6610 and then Is_OK_Static_Subtype
(Entity
(N
))))
6615 -- Freeze type of expression if not frozen already
6619 if Nkind
(N
) in N_Has_Etype
then
6620 if not Is_Frozen
(Etype
(N
)) then
6623 -- Base type may be an derived numeric type that is frozen at
6624 -- the point of declaration, but first_subtype is still unfrozen.
6626 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
6627 Typ
:= First_Subtype
(Etype
(N
));
6631 -- For entity name, freeze entity if not frozen already. A special
6632 -- exception occurs for an identifier that did not come from source.
6633 -- We don't let such identifiers freeze a non-internal entity, i.e.
6634 -- an entity that did come from source, since such an identifier was
6635 -- generated by the expander, and cannot have any semantic effect on
6636 -- the freezing semantics. For example, this stops the parameter of
6637 -- an initialization procedure from freezing the variable.
6639 if Is_Entity_Name
(N
)
6640 and then not Is_Frozen
(Entity
(N
))
6641 and then (Nkind
(N
) /= N_Identifier
6642 or else Comes_From_Source
(N
)
6643 or else not Comes_From_Source
(Entity
(N
)))
6647 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
6648 Check_Expression_Function
(N
, Nam
);
6655 -- For an allocator freeze designated type if not frozen already
6657 -- For an aggregate whose component type is an access type, freeze the
6658 -- designated type now, so that its freeze does not appear within the
6659 -- loop that might be created in the expansion of the aggregate. If the
6660 -- designated type is a private type without full view, the expression
6661 -- cannot contain an allocator, so the type is not frozen.
6663 -- For a function, we freeze the entity when the subprogram declaration
6664 -- is frozen, but a function call may appear in an initialization proc.
6665 -- before the declaration is frozen. We need to generate the extra
6666 -- formals, if any, to ensure that the expansion of the call includes
6667 -- the proper actuals. This only applies to Ada subprograms, not to
6674 Desig_Typ
:= Designated_Type
(Etype
(N
));
6677 if Is_Array_Type
(Etype
(N
))
6678 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
6681 -- Check whether aggregate includes allocators.
6683 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
6686 when N_Selected_Component |
6687 N_Indexed_Component |
6690 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6691 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
6694 when N_Identifier
=>
6696 and then Ekind
(Nam
) = E_Function
6697 and then Nkind
(Parent
(N
)) = N_Function_Call
6698 and then Convention
(Nam
) = Convention_Ada
6700 Create_Extra_Formals
(Nam
);
6707 if Desig_Typ
/= Empty
6708 and then (Is_Frozen
(Desig_Typ
)
6709 or else (not Is_Fully_Defined
(Desig_Typ
)))
6714 -- All done if nothing needs freezing
6718 and then No
(Desig_Typ
)
6723 -- Examine the enclosing context by climbing the parent chain. The
6724 -- traversal serves two purposes - to detect scenarios where freezeing
6725 -- is not needed and to find the proper insertion point for the freeze
6726 -- nodes. Although somewhat similar to Insert_Actions, this traversal
6727 -- is freezing semantics-sensitive. Inserting freeze nodes blindly in
6728 -- the tree may result in types being frozen too early.
6732 Parent_P
:= Parent
(P
);
6734 -- If we don't have a parent, then we are not in a well-formed tree.
6735 -- This is an unusual case, but there are some legitimate situations
6736 -- in which this occurs, notably when the expressions in the range of
6737 -- a type declaration are resolved. We simply ignore the freeze
6738 -- request in this case. Is this right ???
6740 if No
(Parent_P
) then
6744 -- See if we have got to an appropriate point in the tree
6746 case Nkind
(Parent_P
) is
6748 -- A special test for the exception of (RM 13.14(8)) for the case
6749 -- of per-object expressions (RM 3.8(18)) occurring in component
6750 -- definition or a discrete subtype definition. Note that we test
6751 -- for a component declaration which includes both cases we are
6752 -- interested in, and furthermore the tree does not have explicit
6753 -- nodes for either of these two constructs.
6755 when N_Component_Declaration
=>
6757 -- The case we want to test for here is an identifier that is
6758 -- a per-object expression, this is either a discriminant that
6759 -- appears in a context other than the component declaration
6760 -- or it is a reference to the type of the enclosing construct.
6762 -- For either of these cases, we skip the freezing
6764 if not In_Spec_Expression
6765 and then Nkind
(N
) = N_Identifier
6766 and then (Present
(Entity
(N
)))
6768 -- We recognize the discriminant case by just looking for
6769 -- a reference to a discriminant. It can only be one for
6770 -- the enclosing construct. Skip freezing in this case.
6772 if Ekind
(Entity
(N
)) = E_Discriminant
then
6775 -- For the case of a reference to the enclosing record,
6776 -- (or task or protected type), we look for a type that
6777 -- matches the current scope.
6779 elsif Entity
(N
) = Current_Scope
then
6784 -- If we have an enumeration literal that appears as the choice in
6785 -- the aggregate of an enumeration representation clause, then
6786 -- freezing does not occur (RM 13.14(10)).
6788 when N_Enumeration_Representation_Clause
=>
6790 -- The case we are looking for is an enumeration literal
6792 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
6793 and then Is_Enumeration_Type
(Etype
(N
))
6795 -- If enumeration literal appears directly as the choice,
6796 -- do not freeze (this is the normal non-overloaded case)
6798 if Nkind
(Parent
(N
)) = N_Component_Association
6799 and then First
(Choices
(Parent
(N
))) = N
6803 -- If enumeration literal appears as the name of function
6804 -- which is the choice, then also do not freeze. This
6805 -- happens in the overloaded literal case, where the
6806 -- enumeration literal is temporarily changed to a function
6807 -- call for overloading analysis purposes.
6809 elsif Nkind
(Parent
(N
)) = N_Function_Call
6811 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
6813 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
6819 -- Normally if the parent is a handled sequence of statements,
6820 -- then the current node must be a statement, and that is an
6821 -- appropriate place to insert a freeze node.
6823 when N_Handled_Sequence_Of_Statements
=>
6825 -- An exception occurs when the sequence of statements is for
6826 -- an expander generated body that did not do the usual freeze
6827 -- all operation. In this case we usually want to freeze
6828 -- outside this body, not inside it, and we skip past the
6829 -- subprogram body that we are inside.
6831 if In_Expanded_Body
(Parent_P
) then
6833 Subp
: constant Node_Id
:= Parent
(Parent_P
);
6837 -- Freeze the entity only when it is declared inside the
6838 -- body of the expander generated procedure. This case
6839 -- is recognized by the scope of the entity or its type,
6840 -- which is either the spec for some enclosing body, or
6841 -- (in the case of init_procs, for which there are no
6842 -- separate specs) the current scope.
6844 if Nkind
(Subp
) = N_Subprogram_Body
then
6845 Spec
:= Corresponding_Spec
(Subp
);
6847 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
6849 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
6854 and then Scope
(Typ
) = Current_Scope
6855 and then Defining_Entity
(Subp
) = Current_Scope
6861 -- An expression function may act as a completion of
6862 -- a function declaration. As such, it can reference
6863 -- entities declared between the two views:
6866 -- function F return ...;
6868 -- function Hidden return ...;
6869 -- function F return ... is (Hidden); -- 2
6871 -- Refering to the example above, freezing the expression
6872 -- of F (2) would place Hidden's freeze node (1) in the
6873 -- wrong place. Avoid explicit freezing and let the usual
6874 -- scenarios do the job - for example, reaching the end
6875 -- of the private declarations, or a call to F.
6877 if Nkind
(Original_Node
(Subp
)) =
6878 N_Expression_Function
6882 -- Freeze outside the body
6885 Parent_P
:= Parent
(Parent_P
);
6886 Freeze_Outside
:= True;
6890 -- Here if normal case where we are in handled statement
6891 -- sequence and want to do the insertion right there.
6897 -- If parent is a body or a spec or a block, then the current node
6898 -- is a statement or declaration and we can insert the freeze node
6901 when N_Block_Statement |
6904 N_Package_Specification |
6907 N_Task_Body
=> exit;
6909 -- The expander is allowed to define types in any statements list,
6910 -- so any of the following parent nodes also mark a freezing point
6911 -- if the actual node is in a list of statements or declarations.
6913 when N_Abortable_Part |
6914 N_Accept_Alternative |
6916 N_Case_Statement_Alternative |
6917 N_Compilation_Unit_Aux |
6918 N_Conditional_Entry_Call |
6919 N_Delay_Alternative |
6921 N_Entry_Call_Alternative |
6922 N_Exception_Handler |
6923 N_Extended_Return_Statement |
6927 N_Selective_Accept |
6928 N_Triggering_Alternative
=>
6930 exit when Is_List_Member
(P
);
6932 -- Freeze nodes produced by an expression coming from the Actions
6933 -- list of a N_Expression_With_Actions node must remain within the
6934 -- Actions list. Inserting the freeze nodes further up the tree
6935 -- may lead to use before declaration issues in the case of array
6938 when N_Expression_With_Actions
=>
6939 if Is_List_Member
(P
)
6940 and then List_Containing
(P
) = Actions
(Parent_P
)
6945 -- Note: N_Loop_Statement is a special case. A type that appears
6946 -- in the source can never be frozen in a loop (this occurs only
6947 -- because of a loop expanded by the expander), so we keep on
6948 -- going. Otherwise we terminate the search. Same is true of any
6949 -- entity which comes from source. (if they have predefined type,
6950 -- that type does not appear to come from source, but the entity
6951 -- should not be frozen here).
6953 when N_Loop_Statement
=>
6954 exit when not Comes_From_Source
(Etype
(N
))
6955 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
6957 -- For all other cases, keep looking at parents
6963 -- We fall through the case if we did not yet find the proper
6964 -- place in the free for inserting the freeze node, so climb.
6969 -- If the expression appears in a record or an initialization procedure,
6970 -- the freeze nodes are collected and attached to the current scope, to
6971 -- be inserted and analyzed on exit from the scope, to insure that
6972 -- generated entities appear in the correct scope. If the expression is
6973 -- a default for a discriminant specification, the scope is still void.
6974 -- The expression can also appear in the discriminant part of a private
6975 -- or concurrent type.
6977 -- If the expression appears in a constrained subcomponent of an
6978 -- enclosing record declaration, the freeze nodes must be attached to
6979 -- the outer record type so they can eventually be placed in the
6980 -- enclosing declaration list.
6982 -- The other case requiring this special handling is if we are in a
6983 -- default expression, since in that case we are about to freeze a
6984 -- static type, and the freeze scope needs to be the outer scope, not
6985 -- the scope of the subprogram with the default parameter.
6987 -- For default expressions and other spec expressions in generic units,
6988 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
6989 -- placing them at the proper place, after the generic unit.
6991 if (In_Spec_Exp
and not Inside_A_Generic
)
6992 or else Freeze_Outside
6993 or else (Is_Type
(Current_Scope
)
6994 and then (not Is_Concurrent_Type
(Current_Scope
)
6995 or else not Has_Completion
(Current_Scope
)))
6996 or else Ekind
(Current_Scope
) = E_Void
6999 N
: constant Node_Id
:= Current_Scope
;
7000 Freeze_Nodes
: List_Id
:= No_List
;
7001 Pos
: Int
:= Scope_Stack
.Last
;
7004 if Present
(Desig_Typ
) then
7005 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
7008 if Present
(Typ
) then
7009 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
7012 if Present
(Nam
) then
7013 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
7016 -- The current scope may be that of a constrained component of
7017 -- an enclosing record declaration, or of a loop of an enclosing
7018 -- quantified expression, which is above the current scope in the
7019 -- scope stack. Indeed in the context of a quantified expression,
7020 -- a scope is created and pushed above the current scope in order
7021 -- to emulate the loop-like behavior of the quantified expression.
7022 -- If the expression is within a top-level pragma, as for a pre-
7023 -- condition on a library-level subprogram, nothing to do.
7025 if not Is_Compilation_Unit
(Current_Scope
)
7026 and then (Is_Record_Type
(Scope
(Current_Scope
))
7027 or else Nkind
(Parent
(Current_Scope
)) =
7028 N_Quantified_Expression
)
7033 if Is_Non_Empty_List
(Freeze_Nodes
) then
7034 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
7035 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
7038 Append_List
(Freeze_Nodes
,
7039 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
7047 -- Now we have the right place to do the freezing. First, a special
7048 -- adjustment, if we are in spec-expression analysis mode, these freeze
7049 -- actions must not be thrown away (normally all inserted actions are
7050 -- thrown away in this mode. However, the freeze actions are from static
7051 -- expressions and one of the important reasons we are doing this
7052 -- special analysis is to get these freeze actions. Therefore we turn
7053 -- off the In_Spec_Expression mode to propagate these freeze actions.
7054 -- This also means they get properly analyzed and expanded.
7056 In_Spec_Expression
:= False;
7058 -- Freeze the designated type of an allocator (RM 13.14(13))
7060 if Present
(Desig_Typ
) then
7061 Freeze_Before
(P
, Desig_Typ
);
7064 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
7065 -- the enumeration representation clause exception in the loop above.
7067 if Present
(Typ
) then
7068 Freeze_Before
(P
, Typ
);
7071 -- Freeze name if one is present (RM 13.14(11))
7073 if Present
(Nam
) then
7074 Freeze_Before
(P
, Nam
);
7077 -- Restore In_Spec_Expression flag
7079 In_Spec_Expression
:= In_Spec_Exp
;
7080 end Freeze_Expression
;
7082 -----------------------------
7083 -- Freeze_Fixed_Point_Type --
7084 -----------------------------
7086 -- Certain fixed-point types and subtypes, including implicit base types
7087 -- and declared first subtypes, have not yet set up a range. This is
7088 -- because the range cannot be set until the Small and Size values are
7089 -- known, and these are not known till the type is frozen.
7091 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
7092 -- whose bounds are unanalyzed real literals. This routine will recognize
7093 -- this case, and transform this range node into a properly typed range
7094 -- with properly analyzed and resolved values.
7096 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
7097 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
7098 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
7099 Hi
: constant Node_Id
:= High_Bound
(Rng
);
7100 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7101 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
7102 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
7103 BHi
: constant Node_Id
:= High_Bound
(Brng
);
7104 Small
: constant Ureal
:= Small_Value
(Typ
);
7111 -- Save original bounds (for shaving tests)
7114 -- Actual size chosen
7116 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
7117 -- Returns size of type with given bounds. Also leaves these
7118 -- bounds set as the current bounds of the Typ.
7124 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
7126 Set_Realval
(Lo
, Lov
);
7127 Set_Realval
(Hi
, Hiv
);
7128 return Minimum_Size
(Typ
);
7131 -- Start of processing for Freeze_Fixed_Point_Type
7134 -- If Esize of a subtype has not previously been set, set it now
7136 if Unknown_Esize
(Typ
) then
7137 Atype
:= Ancestor_Subtype
(Typ
);
7139 if Present
(Atype
) then
7140 Set_Esize
(Typ
, Esize
(Atype
));
7142 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
7146 -- Immediate return if the range is already analyzed. This means that
7147 -- the range is already set, and does not need to be computed by this
7150 if Analyzed
(Rng
) then
7154 -- Immediate return if either of the bounds raises Constraint_Error
7156 if Raises_Constraint_Error
(Lo
)
7157 or else Raises_Constraint_Error
(Hi
)
7162 Loval
:= Realval
(Lo
);
7163 Hival
:= Realval
(Hi
);
7168 -- Ordinary fixed-point case
7170 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
7172 -- For the ordinary fixed-point case, we are allowed to fudge the
7173 -- end-points up or down by small. Generally we prefer to fudge up,
7174 -- i.e. widen the bounds for non-model numbers so that the end points
7175 -- are included. However there are cases in which this cannot be
7176 -- done, and indeed cases in which we may need to narrow the bounds.
7177 -- The following circuit makes the decision.
7179 -- Note: our terminology here is that Incl_EP means that the bounds
7180 -- are widened by Small if necessary to include the end points, and
7181 -- Excl_EP means that the bounds are narrowed by Small to exclude the
7182 -- end-points if this reduces the size.
7184 -- Note that in the Incl case, all we care about is including the
7185 -- end-points. In the Excl case, we want to narrow the bounds as
7186 -- much as permitted by the RM, to give the smallest possible size.
7189 Loval_Incl_EP
: Ureal
;
7190 Hival_Incl_EP
: Ureal
;
7192 Loval_Excl_EP
: Ureal
;
7193 Hival_Excl_EP
: Ureal
;
7199 First_Subt
: Entity_Id
;
7204 -- First step. Base types are required to be symmetrical. Right
7205 -- now, the base type range is a copy of the first subtype range.
7206 -- This will be corrected before we are done, but right away we
7207 -- need to deal with the case where both bounds are non-negative.
7208 -- In this case, we set the low bound to the negative of the high
7209 -- bound, to make sure that the size is computed to include the
7210 -- required sign. Note that we do not need to worry about the
7211 -- case of both bounds negative, because the sign will be dealt
7212 -- with anyway. Furthermore we can't just go making such a bound
7213 -- symmetrical, since in a twos-complement system, there is an
7214 -- extra negative value which could not be accommodated on the
7218 and then not UR_Is_Negative
(Loval
)
7219 and then Hival
> Loval
7222 Set_Realval
(Lo
, Loval
);
7225 -- Compute the fudged bounds. If the number is a model number,
7226 -- then we do nothing to include it, but we are allowed to backoff
7227 -- to the next adjacent model number when we exclude it. If it is
7228 -- not a model number then we straddle the two values with the
7229 -- model numbers on either side.
7231 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
7233 if Loval
= Model_Num
then
7234 Loval_Incl_EP
:= Model_Num
;
7236 Loval_Incl_EP
:= Model_Num
- Small
;
7239 -- The low value excluding the end point is Small greater, but
7240 -- we do not do this exclusion if the low value is positive,
7241 -- since it can't help the size and could actually hurt by
7242 -- crossing the high bound.
7244 if UR_Is_Negative
(Loval_Incl_EP
) then
7245 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
7247 -- If the value went from negative to zero, then we have the
7248 -- case where Loval_Incl_EP is the model number just below
7249 -- zero, so we want to stick to the negative value for the
7250 -- base type to maintain the condition that the size will
7251 -- include signed values.
7254 and then UR_Is_Zero
(Loval_Excl_EP
)
7256 Loval_Excl_EP
:= Loval_Incl_EP
;
7260 Loval_Excl_EP
:= Loval_Incl_EP
;
7263 -- Similar processing for upper bound and high value
7265 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
7267 if Hival
= Model_Num
then
7268 Hival_Incl_EP
:= Model_Num
;
7270 Hival_Incl_EP
:= Model_Num
+ Small
;
7273 if UR_Is_Positive
(Hival_Incl_EP
) then
7274 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
7276 Hival_Excl_EP
:= Hival_Incl_EP
;
7279 -- One further adjustment is needed. In the case of subtypes, we
7280 -- cannot go outside the range of the base type, or we get
7281 -- peculiarities, and the base type range is already set. This
7282 -- only applies to the Incl values, since clearly the Excl values
7283 -- are already as restricted as they are allowed to be.
7286 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
7287 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
7290 -- Get size including and excluding end points
7292 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
7293 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
7295 -- No need to exclude end-points if it does not reduce size
7297 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
7298 Loval_Excl_EP
:= Loval_Incl_EP
;
7301 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
7302 Hival_Excl_EP
:= Hival_Incl_EP
;
7305 -- Now we set the actual size to be used. We want to use the
7306 -- bounds fudged up to include the end-points but only if this
7307 -- can be done without violating a specifically given size
7308 -- size clause or causing an unacceptable increase in size.
7310 -- Case of size clause given
7312 if Has_Size_Clause
(Typ
) then
7314 -- Use the inclusive size only if it is consistent with
7315 -- the explicitly specified size.
7317 if Size_Incl_EP
<= RM_Size
(Typ
) then
7318 Actual_Lo
:= Loval_Incl_EP
;
7319 Actual_Hi
:= Hival_Incl_EP
;
7320 Actual_Size
:= Size_Incl_EP
;
7322 -- If the inclusive size is too large, we try excluding
7323 -- the end-points (will be caught later if does not work).
7326 Actual_Lo
:= Loval_Excl_EP
;
7327 Actual_Hi
:= Hival_Excl_EP
;
7328 Actual_Size
:= Size_Excl_EP
;
7331 -- Case of size clause not given
7334 -- If we have a base type whose corresponding first subtype
7335 -- has an explicit size that is large enough to include our
7336 -- end-points, then do so. There is no point in working hard
7337 -- to get a base type whose size is smaller than the specified
7338 -- size of the first subtype.
7340 First_Subt
:= First_Subtype
(Typ
);
7342 if Has_Size_Clause
(First_Subt
)
7343 and then Size_Incl_EP
<= Esize
(First_Subt
)
7345 Actual_Size
:= Size_Incl_EP
;
7346 Actual_Lo
:= Loval_Incl_EP
;
7347 Actual_Hi
:= Hival_Incl_EP
;
7349 -- If excluding the end-points makes the size smaller and
7350 -- results in a size of 8,16,32,64, then we take the smaller
7351 -- size. For the 64 case, this is compulsory. For the other
7352 -- cases, it seems reasonable. We like to include end points
7353 -- if we can, but not at the expense of moving to the next
7354 -- natural boundary of size.
7356 elsif Size_Incl_EP
/= Size_Excl_EP
7357 and then Addressable
(Size_Excl_EP
)
7359 Actual_Size
:= Size_Excl_EP
;
7360 Actual_Lo
:= Loval_Excl_EP
;
7361 Actual_Hi
:= Hival_Excl_EP
;
7363 -- Otherwise we can definitely include the end points
7366 Actual_Size
:= Size_Incl_EP
;
7367 Actual_Lo
:= Loval_Incl_EP
;
7368 Actual_Hi
:= Hival_Incl_EP
;
7371 -- One pathological case: normally we never fudge a low bound
7372 -- down, since it would seem to increase the size (if it has
7373 -- any effect), but for ranges containing single value, or no
7374 -- values, the high bound can be small too large. Consider:
7376 -- type t is delta 2.0**(-14)
7377 -- range 131072.0 .. 0;
7379 -- That lower bound is *just* outside the range of 32 bits, and
7380 -- does need fudging down in this case. Note that the bounds
7381 -- will always have crossed here, since the high bound will be
7382 -- fudged down if necessary, as in the case of:
7384 -- type t is delta 2.0**(-14)
7385 -- range 131072.0 .. 131072.0;
7387 -- So we detect the situation by looking for crossed bounds,
7388 -- and if the bounds are crossed, and the low bound is greater
7389 -- than zero, we will always back it off by small, since this
7390 -- is completely harmless.
7392 if Actual_Lo
> Actual_Hi
then
7393 if UR_Is_Positive
(Actual_Lo
) then
7394 Actual_Lo
:= Loval_Incl_EP
- Small
;
7395 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
7397 -- And of course, we need to do exactly the same parallel
7398 -- fudge for flat ranges in the negative region.
7400 elsif UR_Is_Negative
(Actual_Hi
) then
7401 Actual_Hi
:= Hival_Incl_EP
+ Small
;
7402 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
7407 Set_Realval
(Lo
, Actual_Lo
);
7408 Set_Realval
(Hi
, Actual_Hi
);
7411 -- For the decimal case, none of this fudging is required, since there
7412 -- are no end-point problems in the decimal case (the end-points are
7413 -- always included).
7416 Actual_Size
:= Fsize
(Loval
, Hival
);
7419 -- At this stage, the actual size has been calculated and the proper
7420 -- required bounds are stored in the low and high bounds.
7422 if Actual_Size
> 64 then
7423 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
7425 ("size required (^) for type& too large, maximum allowed is 64",
7430 -- Check size against explicit given size
7432 if Has_Size_Clause
(Typ
) then
7433 if Actual_Size
> RM_Size
(Typ
) then
7434 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7435 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
7437 ("size given (^) for type& too small, minimum allowed is ^",
7438 Size_Clause
(Typ
), Typ
);
7441 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
7444 -- Increase size to next natural boundary if no size clause given
7447 if Actual_Size
<= 8 then
7449 elsif Actual_Size
<= 16 then
7451 elsif Actual_Size
<= 32 then
7457 Init_Esize
(Typ
, Actual_Size
);
7458 Adjust_Esize_For_Alignment
(Typ
);
7461 -- If we have a base type, then expand the bounds so that they extend to
7462 -- the full width of the allocated size in bits, to avoid junk range
7463 -- checks on intermediate computations.
7465 if Base_Type
(Typ
) = Typ
then
7466 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
7467 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
7470 -- Final step is to reanalyze the bounds using the proper type
7471 -- and set the Corresponding_Integer_Value fields of the literals.
7473 Set_Etype
(Lo
, Empty
);
7474 Set_Analyzed
(Lo
, False);
7477 -- Resolve with universal fixed if the base type, and the base type if
7478 -- it is a subtype. Note we can't resolve the base type with itself,
7479 -- that would be a reference before definition.
7482 Resolve
(Lo
, Universal_Fixed
);
7487 -- Set corresponding integer value for bound
7489 Set_Corresponding_Integer_Value
7490 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
7492 -- Similar processing for high bound
7494 Set_Etype
(Hi
, Empty
);
7495 Set_Analyzed
(Hi
, False);
7499 Resolve
(Hi
, Universal_Fixed
);
7504 Set_Corresponding_Integer_Value
7505 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
7507 -- Set type of range to correspond to bounds
7509 Set_Etype
(Rng
, Etype
(Lo
));
7511 -- Set Esize to calculated size if not set already
7513 if Unknown_Esize
(Typ
) then
7514 Init_Esize
(Typ
, Actual_Size
);
7517 -- Set RM_Size if not already set. If already set, check value
7520 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
7523 if RM_Size
(Typ
) /= Uint_0
then
7524 if RM_Size
(Typ
) < Minsiz
then
7525 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7526 Error_Msg_Uint_2
:= Minsiz
;
7528 ("size given (^) for type& too small, minimum allowed is ^",
7529 Size_Clause
(Typ
), Typ
);
7533 Set_RM_Size
(Typ
, Minsiz
);
7537 -- Check for shaving
7539 if Comes_From_Source
(Typ
) then
7540 if Orig_Lo
< Expr_Value_R
(Lo
) then
7542 ("declared low bound of type & is outside type range??", Typ
);
7544 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
7547 if Orig_Hi
> Expr_Value_R
(Hi
) then
7549 ("declared high bound of type & is outside type range??", Typ
);
7551 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
7554 end Freeze_Fixed_Point_Type
;
7560 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
7564 Set_Has_Delayed_Freeze
(T
);
7565 L
:= Freeze_Entity
(T
, N
);
7567 if Is_Non_Empty_List
(L
) then
7568 Insert_Actions
(N
, L
);
7572 --------------------------
7573 -- Freeze_Static_Object --
7574 --------------------------
7576 procedure Freeze_Static_Object
(E
: Entity_Id
) is
7578 Cannot_Be_Static
: exception;
7579 -- Exception raised if the type of a static object cannot be made
7580 -- static. This happens if the type depends on non-global objects.
7582 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
7583 -- Called to ensure that an expression used as part of a type definition
7584 -- is statically allocatable, which means that the expression type is
7585 -- statically allocatable, and the expression is either static, or a
7586 -- reference to a library level constant.
7588 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
7589 -- Called to mark a type as static, checking that it is possible
7590 -- to set the type as static. If it is not possible, then the
7591 -- exception Cannot_Be_Static is raised.
7593 -----------------------------
7594 -- Ensure_Expression_Is_SA --
7595 -----------------------------
7597 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
7601 Ensure_Type_Is_SA
(Etype
(N
));
7603 if Is_OK_Static_Expression
(N
) then
7606 elsif Nkind
(N
) = N_Identifier
then
7610 and then Ekind
(Ent
) = E_Constant
7611 and then Is_Library_Level_Entity
(Ent
)
7617 raise Cannot_Be_Static
;
7618 end Ensure_Expression_Is_SA
;
7620 -----------------------
7621 -- Ensure_Type_Is_SA --
7622 -----------------------
7624 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
7629 -- If type is library level, we are all set
7631 if Is_Library_Level_Entity
(Typ
) then
7635 -- We are also OK if the type already marked as statically allocated,
7636 -- which means we processed it before.
7638 if Is_Statically_Allocated
(Typ
) then
7642 -- Mark type as statically allocated
7644 Set_Is_Statically_Allocated
(Typ
);
7646 -- Check that it is safe to statically allocate this type
7648 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
7649 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
7650 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
7652 elsif Is_Array_Type
(Typ
) then
7653 N
:= First_Index
(Typ
);
7654 while Present
(N
) loop
7655 Ensure_Type_Is_SA
(Etype
(N
));
7659 Ensure_Type_Is_SA
(Component_Type
(Typ
));
7661 elsif Is_Access_Type
(Typ
) then
7662 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
7666 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
7669 if T
/= Standard_Void_Type
then
7670 Ensure_Type_Is_SA
(T
);
7673 F
:= First_Formal
(Designated_Type
(Typ
));
7674 while Present
(F
) loop
7675 Ensure_Type_Is_SA
(Etype
(F
));
7681 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
7684 elsif Is_Record_Type
(Typ
) then
7685 C
:= First_Entity
(Typ
);
7686 while Present
(C
) loop
7687 if Ekind
(C
) = E_Discriminant
7688 or else Ekind
(C
) = E_Component
7690 Ensure_Type_Is_SA
(Etype
(C
));
7692 elsif Is_Type
(C
) then
7693 Ensure_Type_Is_SA
(C
);
7699 elsif Ekind
(Typ
) = E_Subprogram_Type
then
7700 Ensure_Type_Is_SA
(Etype
(Typ
));
7702 C
:= First_Formal
(Typ
);
7703 while Present
(C
) loop
7704 Ensure_Type_Is_SA
(Etype
(C
));
7709 raise Cannot_Be_Static
;
7711 end Ensure_Type_Is_SA
;
7713 -- Start of processing for Freeze_Static_Object
7716 Ensure_Type_Is_SA
(Etype
(E
));
7719 when Cannot_Be_Static
=>
7721 -- If the object that cannot be static is imported or exported, then
7722 -- issue an error message saying that this object cannot be imported
7723 -- or exported. If it has an address clause it is an overlay in the
7724 -- current partition and the static requirement is not relevant.
7725 -- Do not issue any error message when ignoring rep clauses.
7727 if Ignore_Rep_Clauses
then
7730 elsif Is_Imported
(E
) then
7731 if No
(Address_Clause
(E
)) then
7733 ("& cannot be imported (local type is not constant)", E
);
7736 -- Otherwise must be exported, something is wrong if compiler
7737 -- is marking something as statically allocated which cannot be).
7739 else pragma Assert
(Is_Exported
(E
));
7741 ("& cannot be exported (local type is not constant)", E
);
7743 end Freeze_Static_Object
;
7745 -----------------------
7746 -- Freeze_Subprogram --
7747 -----------------------
7749 procedure Freeze_Subprogram
(E
: Entity_Id
) is
7754 -- Subprogram may not have an address clause unless it is imported
7756 if Present
(Address_Clause
(E
)) then
7757 if not Is_Imported
(E
) then
7759 ("address clause can only be given " &
7760 "for imported subprogram",
7761 Name
(Address_Clause
(E
)));
7765 -- Reset the Pure indication on an imported subprogram unless an
7766 -- explicit Pure_Function pragma was present or the subprogram is an
7767 -- intrinsic. We do this because otherwise it is an insidious error
7768 -- to call a non-pure function from pure unit and have calls
7769 -- mysteriously optimized away. What happens here is that the Import
7770 -- can bypass the normal check to ensure that pure units call only pure
7773 -- The reason for the intrinsic exception is that in general, intrinsic
7774 -- functions (such as shifts) are pure anyway. The only exceptions are
7775 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
7776 -- in any case, so no problem arises.
7779 and then Is_Pure
(E
)
7780 and then not Has_Pragma_Pure_Function
(E
)
7781 and then not Is_Intrinsic_Subprogram
(E
)
7783 Set_Is_Pure
(E
, False);
7786 -- We also reset the Pure indication on a subprogram with an Address
7787 -- parameter, because the parameter may be used as a pointer and the
7788 -- referenced data may change even if the address value does not.
7790 -- Note that if the programmer gave an explicit Pure_Function pragma,
7791 -- then we believe the programmer, and leave the subprogram Pure.
7792 -- We also suppress this check on run-time files.
7795 and then Is_Subprogram
(E
)
7796 and then not Has_Pragma_Pure_Function
(E
)
7797 and then not Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
7799 Check_Function_With_Address_Parameter
(E
);
7802 -- For non-foreign convention subprograms, this is where we create
7803 -- the extra formals (for accessibility level and constrained bit
7804 -- information). We delay this till the freeze point precisely so
7805 -- that we know the convention.
7807 if not Has_Foreign_Convention
(E
) then
7808 Create_Extra_Formals
(E
);
7811 -- If this is convention Ada and a Valued_Procedure, that's odd
7813 if Ekind
(E
) = E_Procedure
7814 and then Is_Valued_Procedure
(E
)
7815 and then Convention
(E
) = Convention_Ada
7816 and then Warn_On_Export_Import
7819 ("??Valued_Procedure has no effect for convention Ada", E
);
7820 Set_Is_Valued_Procedure
(E
, False);
7823 -- Case of foreign convention
7828 -- For foreign conventions, warn about return of unconstrained array
7830 if Ekind
(E
) = E_Function
then
7831 Retype
:= Underlying_Type
(Etype
(E
));
7833 -- If no return type, probably some other error, e.g. a
7834 -- missing full declaration, so ignore.
7839 -- If the return type is generic, we have emitted a warning
7840 -- earlier on, and there is nothing else to check here. Specific
7841 -- instantiations may lead to erroneous behavior.
7843 elsif Is_Generic_Type
(Etype
(E
)) then
7846 -- Display warning if returning unconstrained array
7848 elsif Is_Array_Type
(Retype
)
7849 and then not Is_Constrained
(Retype
)
7851 -- Check appropriate warning is enabled (should we check for
7852 -- Warnings (Off) on specific entities here, probably so???)
7854 and then Warn_On_Export_Import
7857 ("?x?foreign convention function& should not return " &
7858 "unconstrained array", E
);
7863 -- If any of the formals for an exported foreign convention
7864 -- subprogram have defaults, then emit an appropriate warning since
7865 -- this is odd (default cannot be used from non-Ada code)
7867 if Is_Exported
(E
) then
7868 F
:= First_Formal
(E
);
7869 while Present
(F
) loop
7870 if Warn_On_Export_Import
7871 and then Present
(Default_Value
(F
))
7874 ("?x?parameter cannot be defaulted in non-Ada call",
7883 -- Pragma Inline_Always is disallowed for dispatching subprograms
7884 -- because the address of such subprograms is saved in the dispatch
7885 -- table to support dispatching calls, and dispatching calls cannot
7886 -- be inlined. This is consistent with the restriction against using
7887 -- 'Access or 'Address on an Inline_Always subprogram.
7889 if Is_Dispatching_Operation
(E
)
7890 and then Has_Pragma_Inline_Always
(E
)
7893 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
7896 -- Because of the implicit representation of inherited predefined
7897 -- operators in the front-end, the overriding status of the operation
7898 -- may be affected when a full view of a type is analyzed, and this is
7899 -- not captured by the analysis of the corresponding type declaration.
7900 -- Therefore the correctness of a not-overriding indicator must be
7901 -- rechecked when the subprogram is frozen.
7903 if Nkind
(E
) = N_Defining_Operator_Symbol
7904 and then not Error_Posted
(Parent
(E
))
7906 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
7909 if Modify_Tree_For_C
7910 and then Nkind
(Parent
(E
)) = N_Function_Specification
7911 and then Is_Array_Type
(Etype
(E
))
7912 and then Is_Constrained
(Etype
(E
))
7913 and then not Is_Unchecked_Conversion_Instance
(E
)
7914 and then not Rewritten_For_C
(E
)
7916 Build_Procedure_Form
(Unit_Declaration_Node
(E
));
7918 end Freeze_Subprogram
;
7920 ----------------------
7921 -- Is_Fully_Defined --
7922 ----------------------
7924 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
7926 if Ekind
(T
) = E_Class_Wide_Type
then
7927 return Is_Fully_Defined
(Etype
(T
));
7929 elsif Is_Array_Type
(T
) then
7930 return Is_Fully_Defined
(Component_Type
(T
));
7932 elsif Is_Record_Type
(T
)
7933 and not Is_Private_Type
(T
)
7935 -- Verify that the record type has no components with private types
7936 -- without completion.
7942 Comp
:= First_Component
(T
);
7943 while Present
(Comp
) loop
7944 if not Is_Fully_Defined
(Etype
(Comp
)) then
7948 Next_Component
(Comp
);
7953 -- For the designated type of an access to subprogram, all types in
7954 -- the profile must be fully defined.
7956 elsif Ekind
(T
) = E_Subprogram_Type
then
7961 F
:= First_Formal
(T
);
7962 while Present
(F
) loop
7963 if not Is_Fully_Defined
(Etype
(F
)) then
7970 return Is_Fully_Defined
(Etype
(T
));
7974 return not Is_Private_Type
(T
)
7975 or else Present
(Full_View
(Base_Type
(T
)));
7977 end Is_Fully_Defined
;
7979 ---------------------------------
7980 -- Process_Default_Expressions --
7981 ---------------------------------
7983 procedure Process_Default_Expressions
7985 After
: in out Node_Id
)
7987 Loc
: constant Source_Ptr
:= Sloc
(E
);
7994 Set_Default_Expressions_Processed
(E
);
7996 -- A subprogram instance and its associated anonymous subprogram share
7997 -- their signature. The default expression functions are defined in the
7998 -- wrapper packages for the anonymous subprogram, and should not be
7999 -- generated again for the instance.
8001 if Is_Generic_Instance
(E
)
8002 and then Present
(Alias
(E
))
8003 and then Default_Expressions_Processed
(Alias
(E
))
8008 Formal
:= First_Formal
(E
);
8009 while Present
(Formal
) loop
8010 if Present
(Default_Value
(Formal
)) then
8012 -- We work with a copy of the default expression because we
8013 -- do not want to disturb the original, since this would mess
8014 -- up the conformance checking.
8016 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
8018 -- The analysis of the expression may generate insert actions,
8019 -- which of course must not be executed. We wrap those actions
8020 -- in a procedure that is not called, and later on eliminated.
8021 -- The following cases have no side-effects, and are analyzed
8024 if Nkind
(Dcopy
) = N_Identifier
8025 or else Nkind_In
(Dcopy
, N_Expanded_Name
,
8027 N_Character_Literal
,
8030 or else (Nkind
(Dcopy
) = N_Attribute_Reference
8031 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
8032 or else Known_Null
(Dcopy
)
8034 -- If there is no default function, we must still do a full
8035 -- analyze call on the default value, to ensure that all error
8036 -- checks are performed, e.g. those associated with static
8037 -- evaluation. Note: this branch will always be taken if the
8038 -- analyzer is turned off (but we still need the error checks).
8040 -- Note: the setting of parent here is to meet the requirement
8041 -- that we can only analyze the expression while attached to
8042 -- the tree. Really the requirement is that the parent chain
8043 -- be set, we don't actually need to be in the tree.
8045 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
8048 -- Default expressions are resolved with their own type if the
8049 -- context is generic, to avoid anomalies with private types.
8051 if Ekind
(Scope
(E
)) = E_Generic_Package
then
8054 Resolve
(Dcopy
, Etype
(Formal
));
8057 -- If that resolved expression will raise constraint error,
8058 -- then flag the default value as raising constraint error.
8059 -- This allows a proper error message on the calls.
8061 if Raises_Constraint_Error
(Dcopy
) then
8062 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
8065 -- If the default is a parameterless call, we use the name of
8066 -- the called function directly, and there is no body to build.
8068 elsif Nkind
(Dcopy
) = N_Function_Call
8069 and then No
(Parameter_Associations
(Dcopy
))
8073 -- Else construct and analyze the body of a wrapper procedure
8074 -- that contains an object declaration to hold the expression.
8075 -- Given that this is done only to complete the analysis, it is
8076 -- simpler to build a procedure than a function which might
8077 -- involve secondary stack expansion.
8080 Dnam
:= Make_Temporary
(Loc
, 'D');
8083 Make_Subprogram_Body
(Loc
,
8085 Make_Procedure_Specification
(Loc
,
8086 Defining_Unit_Name
=> Dnam
),
8088 Declarations
=> New_List
(
8089 Make_Object_Declaration
(Loc
,
8090 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
8091 Object_Definition
=>
8092 New_Occurrence_Of
(Etype
(Formal
), Loc
),
8093 Expression
=> New_Copy_Tree
(Dcopy
))),
8095 Handled_Statement_Sequence
=>
8096 Make_Handled_Sequence_Of_Statements
(Loc
,
8097 Statements
=> Empty_List
));
8099 Set_Scope
(Dnam
, Scope
(E
));
8100 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
8101 Set_Is_Eliminated
(Dnam
);
8102 Insert_After
(After
, Dbody
);
8108 Next_Formal
(Formal
);
8110 end Process_Default_Expressions
;
8112 ----------------------------------------
8113 -- Set_Component_Alignment_If_Not_Set --
8114 ----------------------------------------
8116 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
8118 -- Ignore if not base type, subtypes don't need anything
8120 if Typ
/= Base_Type
(Typ
) then
8124 -- Do not override existing representation
8126 if Is_Packed
(Typ
) then
8129 elsif Has_Specified_Layout
(Typ
) then
8132 elsif Component_Alignment
(Typ
) /= Calign_Default
then
8136 Set_Component_Alignment
8137 (Typ
, Scope_Stack
.Table
8138 (Scope_Stack
.Last
).Component_Alignment_Default
);
8140 end Set_Component_Alignment_If_Not_Set
;
8142 --------------------------
8143 -- Set_SSO_From_Default --
8144 --------------------------
8146 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
8150 -- Set default SSO for an array or record base type, except in case of
8151 -- a type extension (which always inherits the SSO of its parent type).
8154 and then (Is_Array_Type
(T
)
8155 or else (Is_Record_Type
(T
)
8156 and then not (Is_Tagged_Type
(T
)
8157 and then Is_Derived_Type
(T
))))
8160 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
8162 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
8164 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
8166 -- For a record type, if bit order is specified explicitly,
8167 -- then do not set SSO from default if not consistent. Note that
8168 -- we do not want to look at a Bit_Order attribute definition
8169 -- for a parent: if we were to inherit Bit_Order, then both
8170 -- SSO_Set_*_By_Default flags would have been cleared already
8171 -- (by Inherit_Aspects_At_Freeze_Point).
8176 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
8177 and then Reverse_Bit_Order
(T
) /= Reversed
)
8179 -- If flags cause reverse storage order, then set the result. Note
8180 -- that we would have ignored the pragma setting the non default
8181 -- storage order in any case, hence the assertion at this point.
8184 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
8186 Set_Reverse_Storage_Order
(T
, Reversed
);
8188 -- For a record type, also set reversed bit order. Note: if a bit
8189 -- order has been specified explicitly, then this is a no-op.
8191 if Is_Record_Type
(T
) then
8192 Set_Reverse_Bit_Order
(T
, Reversed
);
8196 end Set_SSO_From_Default
;
8202 procedure Undelay_Type
(T
: Entity_Id
) is
8204 Set_Has_Delayed_Freeze
(T
, False);
8205 Set_Freeze_Node
(T
, Empty
);
8207 -- Since we don't want T to have a Freeze_Node, we don't want its
8208 -- Full_View or Corresponding_Record_Type to have one either.
8210 -- ??? Fundamentally, this whole handling is unpleasant. What we really
8211 -- want is to be sure that for an Itype that's part of record R and is a
8212 -- subtype of type T, that it's frozen after the later of the freeze
8213 -- points of R and T. We have no way of doing that directly, so what we
8214 -- do is force most such Itypes to be frozen as part of freezing R via
8215 -- this procedure and only delay the ones that need to be delayed
8216 -- (mostly the designated types of access types that are defined as part
8219 if Is_Private_Type
(T
)
8220 and then Present
(Full_View
(T
))
8221 and then Is_Itype
(Full_View
(T
))
8222 and then Is_Record_Type
(Scope
(Full_View
(T
)))
8224 Undelay_Type
(Full_View
(T
));
8227 if Is_Concurrent_Type
(T
)
8228 and then Present
(Corresponding_Record_Type
(T
))
8229 and then Is_Itype
(Corresponding_Record_Type
(T
))
8230 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
8232 Undelay_Type
(Corresponding_Record_Type
(T
));
8240 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Entity_Id
) is
8241 Ent
: constant Entity_Id
:= Entity
(Nam
);
8242 -- The object to which the address clause applies
8245 Old
: Entity_Id
:= Empty
;
8249 -- No warning if address clause overlay warnings are off
8251 if not Address_Clause_Overlay_Warnings
then
8255 -- No warning if there is an explicit initialization
8257 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
8259 if Present
(Init
) and then Comes_From_Source
(Init
) then
8263 -- We only give the warning for non-imported entities of a type for
8264 -- which a non-null base init proc is defined, or for objects of access
8265 -- types with implicit null initialization, or when Normalize_Scalars
8266 -- applies and the type is scalar or a string type (the latter being
8267 -- tested for because predefined String types are initialized by inline
8268 -- code rather than by an init_proc). Note that we do not give the
8269 -- warning for Initialize_Scalars, since we suppressed initialization
8270 -- in this case. Also, do not warn if Suppress_Initialization is set.
8273 and then not Is_Imported
(Ent
)
8274 and then not Initialization_Suppressed
(Typ
)
8275 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
8276 or else Is_Access_Type
(Typ
)
8277 or else (Normalize_Scalars
8278 and then (Is_Scalar_Type
(Typ
)
8279 or else Is_String_Type
(Typ
))))
8281 if Nkind
(Expr
) = N_Attribute_Reference
8282 and then Is_Entity_Name
(Prefix
(Expr
))
8284 Old
:= Entity
(Prefix
(Expr
));
8286 elsif Is_Entity_Name
(Expr
)
8287 and then Ekind
(Entity
(Expr
)) = E_Constant
8289 Decl
:= Declaration_Node
(Entity
(Expr
));
8291 if Nkind
(Decl
) = N_Object_Declaration
8292 and then Present
(Expression
(Decl
))
8293 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
8294 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
8296 Old
:= Entity
(Prefix
(Expression
(Decl
)));
8298 elsif Nkind
(Expr
) = N_Function_Call
then
8302 -- A function call (most likely to To_Address) is probably not an
8303 -- overlay, so skip warning. Ditto if the function call was inlined
8304 -- and transformed into an entity.
8306 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
8310 -- If a pragma Import follows, we assume that it is for the current
8311 -- target of the address clause, and skip the warning. There may be
8312 -- a source pragma or an aspect that specifies import and generates
8313 -- the corresponding pragma. These will indicate that the entity is
8314 -- imported and that is checked above so that the spurious warning
8315 -- (generated when the entity is frozen) will be suppressed. The
8316 -- pragma may be attached to the aspect, so it is not yet a list
8319 if Is_List_Member
(Parent
(Expr
)) then
8320 Decl
:= Next
(Parent
(Expr
));
8323 and then Nkind
(Decl
) = N_Pragma
8324 and then Pragma_Name
(Decl
) = Name_Import
8330 -- Otherwise give warning message
8332 if Present
(Old
) then
8333 Error_Msg_Node_2
:= Old
;
8335 ("default initialization of & may modify &??",
8339 ("default initialization of & may modify overlaid storage??",
8343 -- Add friendly warning if initialization comes from a packed array
8346 if Is_Record_Type
(Typ
) then
8351 Comp
:= First_Component
(Typ
);
8352 while Present
(Comp
) loop
8353 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
8354 and then Present
(Expression
(Parent
(Comp
)))
8357 elsif Is_Array_Type
(Etype
(Comp
))
8358 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
8361 ("\packed array component& " &
8362 "will be initialized to zero??",
8366 Next_Component
(Comp
);
8373 ("\use pragma Import for & to " &
8374 "suppress initialization (RM B.1(24))??",