1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Ch3
; use Exp_Ch3
;
34 with Exp_Ch7
; use Exp_Ch7
;
35 with Exp_Disp
; use Exp_Disp
;
36 with Exp_Pakd
; use Exp_Pakd
;
37 with Exp_Util
; use Exp_Util
;
38 with Exp_Tss
; use Exp_Tss
;
39 with 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 (32 bits or less) in the Esize
749 -- field, of T checking for a size clause that was given which attempts
750 -- to give a smaller size, and also checking for an alignment clause.
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 scalar types. This is true even for generic formal
804 -- scalar types. We used to return False in the latter case, but the
805 -- size is known at compile time, even in the template, we just do
806 -- not know the exact size but that's not the point of this routine.
808 elsif Is_Scalar_Type
(T
)
809 or else Is_Task_Type
(T
)
815 elsif Is_Array_Type
(T
) then
817 -- String literals always have known size, and we can set it
819 if Ekind
(T
) = E_String_Literal_Subtype
then
820 Set_Small_Size
(T
, Component_Size
(T
)
821 * String_Literal_Length
(T
));
824 -- Unconstrained types never have known at compile time size
826 elsif not Is_Constrained
(T
) then
829 -- Don't do any recursion on type with error posted, since we may
830 -- have a malformed type that leads us into a loop.
832 elsif Error_Posted
(T
) then
835 -- Otherwise if component size unknown, then array size unknown
837 elsif not Size_Known
(Component_Type
(T
)) then
841 -- Check for all indexes static, and also compute possible size
842 -- (in case it is less than 32 and may be packable).
845 Esiz
: Uint
:= Component_Size
(T
);
849 Index
:= First_Index
(T
);
850 while Present
(Index
) loop
851 if Nkind
(Index
) = N_Range
then
852 Get_Index_Bounds
(Index
, Low
, High
);
854 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
858 Low
:= Type_Low_Bound
(Etype
(Index
));
859 High
:= Type_High_Bound
(Etype
(Index
));
862 if not Compile_Time_Known_Value
(Low
)
863 or else not Compile_Time_Known_Value
(High
)
864 or else Etype
(Index
) = Any_Type
869 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
881 Set_Small_Size
(T
, Esiz
);
885 -- Access types always have known at compile time sizes
887 elsif Is_Access_Type
(T
) then
890 -- For non-generic private types, go to underlying type if present
892 elsif Is_Private_Type
(T
)
893 and then not Is_Generic_Type
(T
)
894 and then Present
(Underlying_Type
(T
))
896 -- Don't do any recursion on type with error posted, since we may
897 -- have a malformed type that leads us into a loop.
899 if Error_Posted
(T
) then
902 return Size_Known
(Underlying_Type
(T
));
907 elsif Is_Record_Type
(T
) then
909 -- A class-wide type is never considered to have a known size
911 if Is_Class_Wide_Type
(T
) then
914 -- A subtype of a variant record must not have non-static
915 -- discriminated components.
917 elsif T
/= Base_Type
(T
)
918 and then not Static_Discriminated_Components
(T
)
922 -- Don't do any recursion on type with error posted, since we may
923 -- have a malformed type that leads us into a loop.
925 elsif Error_Posted
(T
) then
929 -- Now look at the components of the record
932 -- The following two variables are used to keep track of the
933 -- size of packed records if we can tell the size of the packed
934 -- record in the front end. Packed_Size_Known is True if so far
935 -- we can figure out the size. It is initialized to True for a
936 -- packed record, unless the record has discriminants or atomic
937 -- components or independent components.
939 -- The reason we eliminate the discriminated case is that
940 -- we don't know the way the back end lays out discriminated
941 -- packed records. If Packed_Size_Known is True, then
942 -- Packed_Size is the size in bits so far.
944 Packed_Size_Known
: Boolean :=
946 and then not Has_Discriminants
(T
)
947 and then not Has_Atomic_Components
(T
)
948 and then not Has_Independent_Components
(T
);
950 Packed_Size
: Uint
:= Uint_0
;
951 -- Size in bits so far
954 -- Test for variant part present
956 if Has_Discriminants
(T
)
957 and then Present
(Parent
(T
))
958 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
959 and then Nkind
(Type_Definition
(Parent
(T
))) =
961 and then not Null_Present
(Type_Definition
(Parent
(T
)))
963 Present
(Variant_Part
964 (Component_List
(Type_Definition
(Parent
(T
)))))
966 -- If variant part is present, and type is unconstrained,
967 -- then we must have defaulted discriminants, or a size
968 -- clause must be present for the type, or else the size
969 -- is definitely not known at compile time.
971 if not Is_Constrained
(T
)
973 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
974 and then Unknown_RM_Size
(T
)
980 -- Loop through components
982 Comp
:= First_Component_Or_Discriminant
(T
);
983 while Present
(Comp
) loop
984 Ctyp
:= Etype
(Comp
);
986 -- We do not know the packed size if there is a component
987 -- clause present (we possibly could, but this would only
988 -- help in the case of a record with partial rep clauses.
989 -- That's because in the case of full rep clauses, the
990 -- size gets figured out anyway by a different circuit).
992 if Present
(Component_Clause
(Comp
)) then
993 Packed_Size_Known
:= False;
996 -- We do not know the packed size for an atomic/VFA type
997 -- or component, or an independent type or component, or a
998 -- by-reference type or aliased component (because packing
999 -- does not touch these).
1001 if Is_Atomic_Or_VFA
(Ctyp
)
1002 or else Is_Atomic_Or_VFA
(Comp
)
1003 or else Is_Independent
(Ctyp
)
1004 or else Is_Independent
(Comp
)
1005 or else Is_By_Reference_Type
(Ctyp
)
1006 or else Is_Aliased
(Comp
)
1008 Packed_Size_Known
:= False;
1011 -- We need to identify a component that is an array where
1012 -- the index type is an enumeration type with non-standard
1013 -- representation, and some bound of the type depends on a
1016 -- This is because gigi computes the size by doing a
1017 -- substitution of the appropriate discriminant value in
1018 -- the size expression for the base type, and gigi is not
1019 -- clever enough to evaluate the resulting expression (which
1020 -- involves a call to rep_to_pos) at compile time.
1022 -- It would be nice if gigi would either recognize that
1023 -- this expression can be computed at compile time, or
1024 -- alternatively figured out the size from the subtype
1025 -- directly, where all the information is at hand ???
1027 if Is_Array_Type
(Etype
(Comp
))
1028 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1031 Ocomp
: constant Entity_Id
:=
1032 Original_Record_Component
(Comp
);
1033 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1039 Ind
:= First_Index
(OCtyp
);
1040 while Present
(Ind
) loop
1041 Indtyp
:= Etype
(Ind
);
1043 if Is_Enumeration_Type
(Indtyp
)
1044 and then Has_Non_Standard_Rep
(Indtyp
)
1046 Lo
:= Type_Low_Bound
(Indtyp
);
1047 Hi
:= Type_High_Bound
(Indtyp
);
1049 if Is_Entity_Name
(Lo
)
1050 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1054 elsif Is_Entity_Name
(Hi
)
1055 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1066 -- Clearly size of record is not known if the size of one of
1067 -- the components is not known.
1069 if not Size_Known
(Ctyp
) then
1073 -- Accumulate packed size if possible
1075 if Packed_Size_Known
then
1077 -- We can only deal with elementary types, since for
1078 -- non-elementary components, alignment enters into the
1079 -- picture, and we don't know enough to handle proper
1080 -- alignment in this context. Packed arrays count as
1081 -- elementary if the representation is a modular type.
1083 if Is_Elementary_Type
(Ctyp
)
1084 or else (Is_Array_Type
(Ctyp
)
1086 (Packed_Array_Impl_Type
(Ctyp
))
1087 and then Is_Modular_Integer_Type
1088 (Packed_Array_Impl_Type
(Ctyp
)))
1090 -- Packed size unknown if we have an atomic/VFA type
1091 -- or a by-reference type, since the back end knows
1092 -- how these are layed out.
1094 if Is_Atomic_Or_VFA
(Ctyp
)
1095 or else Is_By_Reference_Type
(Ctyp
)
1097 Packed_Size_Known
:= False;
1099 -- If RM_Size is known and static, then we can keep
1100 -- accumulating the packed size
1102 elsif Known_Static_RM_Size
(Ctyp
) then
1104 -- A little glitch, to be removed sometime ???
1105 -- gigi does not understand zero sizes yet.
1107 if RM_Size
(Ctyp
) = Uint_0
then
1108 Packed_Size_Known
:= False;
1110 -- Normal case where we can keep accumulating the
1111 -- packed array size.
1114 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1117 -- If we have a field whose RM_Size is not known then
1118 -- we can't figure out the packed size here.
1121 Packed_Size_Known
:= False;
1124 -- If we have a non-elementary type we can't figure out
1125 -- the packed array size (alignment issues).
1128 Packed_Size_Known
:= False;
1132 Next_Component_Or_Discriminant
(Comp
);
1135 if Packed_Size_Known
then
1136 Set_Small_Size
(T
, Packed_Size
);
1142 -- All other cases, size not known at compile time
1149 -------------------------------------
1150 -- Static_Discriminated_Components --
1151 -------------------------------------
1153 function Static_Discriminated_Components
1154 (T
: Entity_Id
) return Boolean
1156 Constraint
: Elmt_Id
;
1159 if Has_Discriminants
(T
)
1160 and then Present
(Discriminant_Constraint
(T
))
1161 and then Present
(First_Component
(T
))
1163 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1164 while Present
(Constraint
) loop
1165 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1169 Next_Elmt
(Constraint
);
1174 end Static_Discriminated_Components
;
1176 -- Start of processing for Check_Compile_Time_Size
1179 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1180 end Check_Compile_Time_Size
;
1182 -----------------------------------
1183 -- Check_Component_Storage_Order --
1184 -----------------------------------
1186 procedure Check_Component_Storage_Order
1187 (Encl_Type
: Entity_Id
;
1190 Comp_ADC_Present
: out Boolean)
1192 Comp_Type
: Entity_Id
;
1196 Comp_Byte_Aligned
: Boolean;
1197 -- Set for the record case, True if Comp starts on a byte boundary
1198 -- (in which case it is allowed to have different storage order).
1200 Comp_SSO_Differs
: Boolean;
1201 -- Set True when the component is a nested composite, and it does not
1202 -- have the same scalar storage order as Encl_Type.
1204 Component_Aliased
: Boolean;
1209 if Present
(Comp
) then
1211 Comp_Type
:= Etype
(Comp
);
1213 if Is_Tag
(Comp
) then
1214 Comp_Byte_Aligned
:= True;
1215 Component_Aliased
:= False;
1218 -- If a component clause is present, check if the component starts
1219 -- on a storage element boundary. Otherwise conservatively assume
1220 -- it does so only in the case where the record is not packed.
1222 if Present
(Component_Clause
(Comp
)) then
1223 Comp_Byte_Aligned
:=
1224 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1226 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1229 Component_Aliased
:= Is_Aliased
(Comp
);
1235 Err_Node
:= Encl_Type
;
1236 Comp_Type
:= Component_Type
(Encl_Type
);
1238 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1241 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1242 -- the attribute definition clause is attached to the first subtype.
1244 Comp_Type
:= Base_Type
(Comp_Type
);
1245 Comp_ADC
:= Get_Attribute_Definition_Clause
1246 (First_Subtype
(Comp_Type
),
1247 Attribute_Scalar_Storage_Order
);
1248 Comp_ADC_Present
:= Present
(Comp_ADC
);
1250 -- Case of record or array component: check storage order compatibility.
1251 -- But, if the record has Complex_Representation, then it is treated as
1252 -- a scalar in the back end so the storage order is irrelevant.
1254 if (Is_Record_Type
(Comp_Type
)
1255 and then not Has_Complex_Representation
(Comp_Type
))
1256 or else Is_Array_Type
(Comp_Type
)
1259 Reverse_Storage_Order
(Encl_Type
)
1261 Reverse_Storage_Order
(Comp_Type
);
1263 -- Parent and extension must have same storage order
1265 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1266 if Comp_SSO_Differs
then
1268 ("record extension must have same scalar storage order as "
1269 & "parent", Err_Node
);
1272 -- If enclosing composite has explicit SSO then nested composite must
1273 -- have explicit SSO as well.
1275 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1276 Error_Msg_N
("nested composite must have explicit scalar "
1277 & "storage order", Err_Node
);
1279 -- If component and composite SSO differs, check that component
1280 -- falls on byte boundaries and isn't packed.
1282 elsif Comp_SSO_Differs
then
1284 -- Component SSO differs from enclosing composite:
1286 -- Reject if component is a packed array, as it may be represented
1287 -- as a scalar internally.
1289 if Is_Packed_Array
(Comp_Type
) then
1291 ("type of packed component must have same scalar "
1292 & "storage order as enclosing composite", Err_Node
);
1294 -- Reject if composite is a packed array, as it may be rewritten
1295 -- into an array of scalars.
1297 elsif Is_Packed_Array
(Encl_Type
) then
1298 Error_Msg_N
("type of packed array must have same scalar "
1299 & "storage order as component", Err_Node
);
1301 -- Reject if not byte aligned
1303 elsif Is_Record_Type
(Encl_Type
)
1304 and then not Comp_Byte_Aligned
1307 ("type of non-byte-aligned component must have same scalar "
1308 & "storage order as enclosing composite", Err_Node
);
1312 -- Enclosing type has explicit SSO: non-composite component must not
1315 elsif Present
(ADC
) and then Component_Aliased
then
1317 ("aliased component not permitted for type with "
1318 & "explicit Scalar_Storage_Order", Err_Node
);
1320 end Check_Component_Storage_Order
;
1322 -----------------------------
1323 -- Check_Debug_Info_Needed --
1324 -----------------------------
1326 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1328 if Debug_Info_Off
(T
) then
1331 elsif Comes_From_Source
(T
)
1332 or else Debug_Generated_Code
1333 or else Debug_Flag_VV
1334 or else Needs_Debug_Info
(T
)
1336 Set_Debug_Info_Needed
(T
);
1338 end Check_Debug_Info_Needed
;
1340 -------------------------------
1341 -- Check_Expression_Function --
1342 -------------------------------
1344 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1347 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1348 -- Function to search for deferred constant
1354 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1356 -- When a constant is initialized with the result of a dispatching
1357 -- call, the constant declaration is rewritten as a renaming of the
1358 -- displaced function result. This scenario is not a premature use of
1359 -- a constant even though the Has_Completion flag is not set.
1361 if Is_Entity_Name
(Nod
)
1362 and then Present
(Entity
(Nod
))
1363 and then Ekind
(Entity
(Nod
)) = E_Constant
1364 and then Scope
(Entity
(Nod
)) = Current_Scope
1365 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1366 N_Object_Declaration
1367 and then not Is_Imported
(Entity
(Nod
))
1368 and then not Has_Completion
(Entity
(Nod
))
1371 ("premature use of& in call or instance", N
, Entity
(Nod
));
1373 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1374 Analyze
(Prefix
(Nod
));
1376 if Is_Entity_Name
(Prefix
(Nod
))
1377 and then Is_Type
(Entity
(Prefix
(Nod
)))
1379 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1386 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1388 -- Start of processing for Check_Expression_Function
1391 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1393 if Scope
(Nam
) = Current_Scope
1394 and then Nkind
(Decl
) = N_Expression_Function
1396 Check_Deferred
(Expression
(Decl
));
1398 end Check_Expression_Function
;
1400 ----------------------------
1401 -- Check_Strict_Alignment --
1402 ----------------------------
1404 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1408 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1409 Set_Strict_Alignment
(E
);
1411 elsif Is_Array_Type
(E
) then
1412 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1414 elsif Is_Record_Type
(E
) then
1415 if Is_Limited_Record
(E
) then
1416 Set_Strict_Alignment
(E
);
1420 Comp
:= First_Component
(E
);
1421 while Present
(Comp
) loop
1422 if not Is_Type
(Comp
)
1423 and then (Strict_Alignment
(Etype
(Comp
))
1424 or else Is_Aliased
(Comp
))
1426 Set_Strict_Alignment
(E
);
1430 Next_Component
(Comp
);
1433 end Check_Strict_Alignment
;
1435 -------------------------
1436 -- Check_Unsigned_Type --
1437 -------------------------
1439 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1440 Ancestor
: Entity_Id
;
1445 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1449 -- Do not attempt to analyze case where range was in error
1451 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
1455 -- The situation that is nontrivial is something like:
1457 -- subtype x1 is integer range -10 .. +10;
1458 -- subtype x2 is x1 range 0 .. V1;
1459 -- subtype x3 is x2 range V2 .. V3;
1460 -- subtype x4 is x3 range V4 .. V5;
1462 -- where Vn are variables. Here the base type is signed, but we still
1463 -- know that x4 is unsigned because of the lower bound of x2.
1465 -- The only way to deal with this is to look up the ancestor chain
1469 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1473 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1475 if Compile_Time_Known_Value
(Lo_Bound
) then
1476 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1477 Set_Is_Unsigned_Type
(E
, True);
1483 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1485 -- If no ancestor had a static lower bound, go to base type
1487 if No
(Ancestor
) then
1489 -- Note: the reason we still check for a compile time known
1490 -- value for the base type is that at least in the case of
1491 -- generic formals, we can have bounds that fail this test,
1492 -- and there may be other cases in error situations.
1494 Btyp
:= Base_Type
(E
);
1496 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1500 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1502 if Compile_Time_Known_Value
(Lo_Bound
)
1503 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1505 Set_Is_Unsigned_Type
(E
, True);
1512 end Check_Unsigned_Type
;
1514 -----------------------------
1515 -- Is_Atomic_VFA_Aggregate --
1516 -----------------------------
1518 function Is_Atomic_VFA_Aggregate
(N
: Node_Id
) return Boolean is
1519 Loc
: constant Source_Ptr
:= Sloc
(N
);
1528 -- Array may be qualified, so find outer context
1530 if Nkind
(Par
) = N_Qualified_Expression
then
1531 Par
:= Parent
(Par
);
1534 if not Comes_From_Source
(Par
) then
1539 when N_Assignment_Statement
=>
1540 Typ
:= Etype
(Name
(Par
));
1542 if not Is_Atomic_Or_VFA
(Typ
)
1543 and then not (Is_Entity_Name
(Name
(Par
))
1544 and then Is_Atomic_Or_VFA
(Entity
(Name
(Par
))))
1549 when N_Object_Declaration
=>
1550 Typ
:= Etype
(Defining_Identifier
(Par
));
1552 if not Is_Atomic_Or_VFA
(Typ
)
1553 and then not Is_Atomic_Or_VFA
(Defining_Identifier
(Par
))
1562 Temp
:= Make_Temporary
(Loc
, 'T', N
);
1564 Make_Object_Declaration
(Loc
,
1565 Defining_Identifier
=> Temp
,
1566 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1567 Expression
=> Relocate_Node
(N
));
1568 Insert_Before
(Par
, New_N
);
1571 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1573 end Is_Atomic_VFA_Aggregate
;
1575 -----------------------------------------------
1576 -- Explode_Initialization_Compound_Statement --
1577 -----------------------------------------------
1579 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
1580 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
1583 if Present
(Init_Stmts
)
1584 and then Nkind
(Init_Stmts
) = N_Compound_Statement
1586 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
1588 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
1589 -- just removing it, because Freeze_All may rely on this particular
1590 -- Node_Id still being present in the enclosing list to know where to
1593 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
1595 Set_Initialization_Statements
(E
, Empty
);
1597 end Explode_Initialization_Compound_Statement
;
1603 -- Note: the easy coding for this procedure would be to just build a
1604 -- single list of freeze nodes and then insert them and analyze them
1605 -- all at once. This won't work, because the analysis of earlier freeze
1606 -- nodes may recursively freeze types which would otherwise appear later
1607 -- on in the freeze list. So we must analyze and expand the freeze nodes
1608 -- as they are generated.
1610 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1614 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1615 -- This is the internal recursive routine that does freezing of entities
1616 -- (but NOT the analysis of default expressions, which should not be
1617 -- recursive, we don't want to analyze those till we are sure that ALL
1618 -- the types are frozen).
1620 --------------------
1621 -- Freeze_All_Ent --
1622 --------------------
1624 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1629 procedure Process_Flist
;
1630 -- If freeze nodes are present, insert and analyze, and reset cursor
1631 -- for next insertion.
1637 procedure Process_Flist
is
1639 if Is_Non_Empty_List
(Flist
) then
1640 Lastn
:= Next
(After
);
1641 Insert_List_After_And_Analyze
(After
, Flist
);
1643 if Present
(Lastn
) then
1644 After
:= Prev
(Lastn
);
1646 After
:= Last
(List_Containing
(After
));
1651 -- Start of processing for Freeze_All_Ent
1655 while Present
(E
) loop
1657 -- If the entity is an inner package which is not a package
1658 -- renaming, then its entities must be frozen at this point. Note
1659 -- that such entities do NOT get frozen at the end of the nested
1660 -- package itself (only library packages freeze).
1662 -- Same is true for task declarations, where anonymous records
1663 -- created for entry parameters must be frozen.
1665 if Ekind
(E
) = E_Package
1666 and then No
(Renamed_Object
(E
))
1667 and then not Is_Child_Unit
(E
)
1668 and then not Is_Frozen
(E
)
1671 Install_Visible_Declarations
(E
);
1672 Install_Private_Declarations
(E
);
1674 Freeze_All
(First_Entity
(E
), After
);
1676 End_Package_Scope
(E
);
1678 if Is_Generic_Instance
(E
)
1679 and then Has_Delayed_Freeze
(E
)
1681 Set_Has_Delayed_Freeze
(E
, False);
1682 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1685 elsif Ekind
(E
) in Task_Kind
1686 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1687 N_Single_Task_Declaration
)
1690 Freeze_All
(First_Entity
(E
), After
);
1693 -- For a derived tagged type, we must ensure that all the
1694 -- primitive operations of the parent have been frozen, so that
1695 -- their addresses will be in the parent's dispatch table at the
1696 -- point it is inherited.
1698 elsif Ekind
(E
) = E_Record_Type
1699 and then Is_Tagged_Type
(E
)
1700 and then Is_Tagged_Type
(Etype
(E
))
1701 and then Is_Derived_Type
(E
)
1704 Prim_List
: constant Elist_Id
:=
1705 Primitive_Operations
(Etype
(E
));
1711 Prim
:= First_Elmt
(Prim_List
);
1712 while Present
(Prim
) loop
1713 Subp
:= Node
(Prim
);
1715 if Comes_From_Source
(Subp
)
1716 and then not Is_Frozen
(Subp
)
1718 Flist
:= Freeze_Entity
(Subp
, After
);
1727 if not Is_Frozen
(E
) then
1728 Flist
:= Freeze_Entity
(E
, After
);
1731 -- If already frozen, and there are delayed aspects, this is where
1732 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1733 -- for a description of how we handle aspect visibility).
1735 elsif Has_Delayed_Aspects
(E
) then
1737 -- Retrieve the visibility to the discriminants in order to
1738 -- analyze properly the aspects.
1740 Push_Scope_And_Install_Discriminants
(E
);
1746 Ritem
:= First_Rep_Item
(E
);
1747 while Present
(Ritem
) loop
1748 if Nkind
(Ritem
) = N_Aspect_Specification
1749 and then Entity
(Ritem
) = E
1750 and then Is_Delayed_Aspect
(Ritem
)
1752 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1755 Ritem
:= Next_Rep_Item
(Ritem
);
1759 Uninstall_Discriminants_And_Pop_Scope
(E
);
1762 -- If an incomplete type is still not frozen, this may be a
1763 -- premature freezing because of a body declaration that follows.
1764 -- Indicate where the freezing took place. Freezing will happen
1765 -- if the body comes from source, but not if it is internally
1766 -- generated, for example as the body of a type invariant.
1768 -- If the freezing is caused by the end of the current declarative
1769 -- part, it is a Taft Amendment type, and there is no error.
1771 if not Is_Frozen
(E
)
1772 and then Ekind
(E
) = E_Incomplete_Type
1775 Bod
: constant Node_Id
:= Next
(After
);
1778 -- The presence of a body freezes all entities previously
1779 -- declared in the current list of declarations, but this
1780 -- does not apply if the body does not come from source.
1781 -- A type invariant is transformed into a subprogram body
1782 -- which is placed at the end of the private part of the
1783 -- current package, but this body does not freeze incomplete
1784 -- types that may be declared in this private part.
1786 if (Nkind_In
(Bod
, N_Subprogram_Body
,
1791 or else Nkind
(Bod
) in N_Body_Stub
)
1793 List_Containing
(After
) = List_Containing
(Parent
(E
))
1794 and then Comes_From_Source
(Bod
)
1796 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1798 ("type& is frozen# before its full declaration",
1808 -- Start of processing for Freeze_All
1811 Freeze_All_Ent
(From
, After
);
1813 -- Now that all types are frozen, we can deal with default expressions
1814 -- that require us to build a default expression functions. This is the
1815 -- point at which such functions are constructed (after all types that
1816 -- might be used in such expressions have been frozen).
1818 -- For subprograms that are renaming_as_body, we create the wrapper
1819 -- bodies as needed.
1821 -- We also add finalization chains to access types whose designated
1822 -- types are controlled. This is normally done when freezing the type,
1823 -- but this misses recursive type definitions where the later members
1824 -- of the recursion introduce controlled components.
1826 -- Loop through entities
1829 while Present
(E
) loop
1830 if Is_Subprogram
(E
) then
1831 if not Default_Expressions_Processed
(E
) then
1832 Process_Default_Expressions
(E
, After
);
1835 if not Has_Completion
(E
) then
1836 Decl
:= Unit_Declaration_Node
(E
);
1838 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1839 if Error_Posted
(Decl
) then
1840 Set_Has_Completion
(E
);
1842 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1845 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1846 and then Present
(Corresponding_Body
(Decl
))
1848 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1849 = N_Subprogram_Renaming_Declaration
1851 Build_And_Analyze_Renamed_Body
1852 (Decl
, Corresponding_Body
(Decl
), After
);
1856 elsif Ekind
(E
) in Task_Kind
1857 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1858 N_Single_Task_Declaration
)
1864 Ent
:= First_Entity
(E
);
1865 while Present
(Ent
) loop
1867 and then not Default_Expressions_Processed
(Ent
)
1869 Process_Default_Expressions
(Ent
, After
);
1877 -- Historical note: We used to create a finalization master for an
1878 -- access type whose designated type is not controlled, but contains
1879 -- private controlled compoments. This form of postprocessing is no
1880 -- longer needed because the finalization master is now created when
1881 -- the access type is frozen (see Exp_Ch3.Freeze_Type).
1887 -----------------------
1888 -- Freeze_And_Append --
1889 -----------------------
1891 procedure Freeze_And_Append
1894 Result
: in out List_Id
)
1896 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1898 if Is_Non_Empty_List
(L
) then
1899 if Result
= No_List
then
1902 Append_List
(L
, Result
);
1905 end Freeze_And_Append
;
1911 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1912 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, N
);
1915 if Ekind
(T
) = E_Function
then
1916 Check_Expression_Function
(N
, T
);
1919 if Is_Non_Empty_List
(Freeze_Nodes
) then
1920 Insert_Actions
(N
, Freeze_Nodes
);
1928 function Freeze_Entity
(E
: Entity_Id
; N
: Node_Id
) return List_Id
is
1929 Loc
: constant Source_Ptr
:= Sloc
(N
);
1936 Has_Default_Initialization
: Boolean := False;
1937 -- This flag gets set to true for a variable with default initialization
1939 Late_Freezing
: Boolean := False;
1940 -- Used to detect attempt to freeze function declared in another unit
1942 Result
: List_Id
:= No_List
;
1943 -- List of freezing actions, left at No_List if none
1945 Test_E
: Entity_Id
:= E
;
1946 -- This could use a comment ???
1948 procedure Add_To_Result
(N
: Node_Id
);
1949 -- N is a freezing action to be appended to the Result
1951 function After_Last_Declaration
return Boolean;
1952 -- If Loc is a freeze_entity that appears after the last declaration
1953 -- in the scope, inhibit error messages on late completion.
1955 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1956 -- Check that an Access or Unchecked_Access attribute with a prefix
1957 -- which is the current instance type can only be applied when the type
1960 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1961 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1962 -- integer literal without an explicit corresponding size clause. The
1963 -- caller has checked that Utype is a modular integer type.
1965 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
1966 -- Freeze array type, including freezing index and component types
1968 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
1969 -- Perform checks and generate freeze node if needed for a constant or
1970 -- variable declared by an object declaration.
1972 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
1973 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1974 -- package. Recurse on inner generic packages.
1976 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
1977 -- Freeze formals and return type of subprogram. If some type in the
1978 -- profile is a limited view, freezing of the entity will take place
1979 -- elsewhere, and the function returns False. This routine will be
1980 -- modified if and when we can implement AI05-019 efficiently ???
1982 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1983 -- Freeze record type, including freezing component types, and freezing
1984 -- primitive operations if this is a tagged type.
1986 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
1987 -- Determine whether an arbitrary entity is subject to Boolean aspect
1988 -- Import and its value is specified as True.
1990 procedure Late_Freeze_Subprogram
(E
: Entity_Id
);
1991 -- Following AI05-151, a function can return a limited view of a type
1992 -- declared elsewhere. In that case the function cannot be frozen at
1993 -- the end of its enclosing package. If its first use is in a different
1994 -- unit, it cannot be frozen there, but if the call is legal the full
1995 -- view of the return type is available and the subprogram can now be
1996 -- frozen. However the freeze node cannot be inserted at the point of
1997 -- call, but rather must go in the package holding the function, so that
1998 -- the backend can process it in the proper context.
2000 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
2001 -- If E is an entity for an imported subprogram with pre/post-conditions
2002 -- then this procedure will create a wrapper to ensure that proper run-
2003 -- time checking of the pre/postconditions. See body for details.
2009 procedure Add_To_Result
(N
: Node_Id
) is
2012 Result
:= New_List
(N
);
2018 ----------------------------
2019 -- After_Last_Declaration --
2020 ----------------------------
2022 function After_Last_Declaration
return Boolean is
2023 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2026 if Nkind
(Spec
) = N_Package_Specification
then
2027 if Present
(Private_Declarations
(Spec
)) then
2028 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2029 elsif Present
(Visible_Declarations
(Spec
)) then
2030 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2038 end After_Last_Declaration
;
2040 ----------------------------
2041 -- Check_Current_Instance --
2042 ----------------------------
2044 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2046 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2047 -- Determine whether Typ is compatible with the rules for aliased
2048 -- views of types as defined in RM 3.10 in the various dialects.
2050 function Process
(N
: Node_Id
) return Traverse_Result
;
2051 -- Process routine to apply check to given node
2053 -----------------------------
2054 -- Is_Aliased_View_Of_Type --
2055 -----------------------------
2057 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
2058 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
2063 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
2064 and then Limited_Present
(Type_Definition
(Typ_Decl
))
2068 -- The following paragraphs describe what a legal aliased view of
2069 -- a type is in the various dialects of Ada.
2073 -- The current instance of a limited type, and a formal parameter
2074 -- or generic formal object of a tagged type.
2076 -- Ada 95 limited type
2077 -- * Type with reserved word "limited"
2078 -- * A protected or task type
2079 -- * A composite type with limited component
2081 elsif Ada_Version
<= Ada_95
then
2082 return Is_Limited_Type
(Typ
);
2086 -- The current instance of a limited tagged type, a protected
2087 -- type, a task type, or a type that has the reserved word
2088 -- "limited" in its full definition ... a formal parameter or
2089 -- generic formal object of a tagged type.
2091 -- Ada 2005 limited type
2092 -- * Type with reserved word "limited", "synchronized", "task"
2094 -- * A composite type with limited component
2095 -- * A derived type whose parent is a non-interface limited type
2097 elsif Ada_Version
= Ada_2005
then
2099 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2101 (Is_Derived_Type
(Typ
)
2102 and then not Is_Interface
(Etype
(Typ
))
2103 and then Is_Limited_Type
(Etype
(Typ
)));
2105 -- Ada 2012 and beyond
2107 -- The current instance of an immutably limited type ... a formal
2108 -- parameter or generic formal object of a tagged type.
2110 -- Ada 2012 limited type
2111 -- * Type with reserved word "limited", "synchronized", "task"
2113 -- * A composite type with limited component
2114 -- * A derived type whose parent is a non-interface limited type
2115 -- * An incomplete view
2117 -- Ada 2012 immutably limited type
2118 -- * Explicitly limited record type
2119 -- * Record extension with "limited" present
2120 -- * Non-formal limited private type that is either tagged
2121 -- or has at least one access discriminant with a default
2123 -- * Task type, protected type or synchronized interface
2124 -- * Type derived from immutably limited type
2128 Is_Immutably_Limited_Type
(Typ
)
2129 or else Is_Incomplete_Type
(Typ
);
2131 end Is_Aliased_View_Of_Type
;
2137 function Process
(N
: Node_Id
) return Traverse_Result
is
2140 when N_Attribute_Reference
=>
2141 if Nam_In
(Attribute_Name
(N
), Name_Access
,
2142 Name_Unchecked_Access
)
2143 and then Is_Entity_Name
(Prefix
(N
))
2144 and then Is_Type
(Entity
(Prefix
(N
)))
2145 and then Entity
(Prefix
(N
)) = E
2147 if Ada_Version
< Ada_2012
then
2149 ("current instance must be a limited type",
2153 ("current instance must be an immutably limited "
2154 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2163 when others => return OK
;
2167 procedure Traverse
is new Traverse_Proc
(Process
);
2171 Rec_Type
: constant Entity_Id
:=
2172 Scope
(Defining_Identifier
(Comp_Decl
));
2174 -- Start of processing for Check_Current_Instance
2177 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2178 Traverse
(Comp_Decl
);
2180 end Check_Current_Instance
;
2182 ------------------------------
2183 -- Check_Suspicious_Modulus --
2184 ------------------------------
2186 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
2187 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
2190 if not Warn_On_Suspicious_Modulus_Value
then
2194 if Nkind
(Decl
) = N_Full_Type_Declaration
then
2196 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
2199 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
2201 Modulus
: constant Node_Id
:=
2202 Original_Node
(Expression
(Tdef
));
2205 if Nkind
(Modulus
) = N_Integer_Literal
then
2207 Modv
: constant Uint
:= Intval
(Modulus
);
2208 Sizv
: constant Uint
:= RM_Size
(Utype
);
2211 -- First case, modulus and size are the same. This
2212 -- happens if you have something like mod 32, with
2213 -- an explicit size of 32, this is for sure a case
2214 -- where the warning is given, since it is seems
2215 -- very unlikely that someone would want e.g. a
2216 -- five bit type stored in 32 bits. It is much
2217 -- more likely they wanted a 32-bit type.
2222 -- Second case, the modulus is 32 or 64 and no
2223 -- size clause is present. This is a less clear
2224 -- case for giving the warning, but in the case
2225 -- of 32/64 (5-bit or 6-bit types) these seem rare
2226 -- enough that it is a likely error (and in any
2227 -- case using 2**5 or 2**6 in these cases seems
2228 -- clearer. We don't include 8 or 16 here, simply
2229 -- because in practice 3-bit and 4-bit types are
2230 -- more common and too many false positives if
2231 -- we warn in these cases.
2233 elsif not Has_Size_Clause
(Utype
)
2234 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
2238 -- No warning needed
2244 -- If we fall through, give warning
2246 Error_Msg_Uint_1
:= Modv
;
2248 ("?M?2 '*'*^' may have been intended here",
2256 end Check_Suspicious_Modulus
;
2258 -----------------------
2259 -- Freeze_Array_Type --
2260 -----------------------
2262 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2263 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2264 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2267 Non_Standard_Enum
: Boolean := False;
2268 -- Set true if any of the index types is an enumeration type with a
2269 -- non-standard representation.
2272 Freeze_And_Append
(Ctyp
, N
, Result
);
2274 Indx
:= First_Index
(Arr
);
2275 while Present
(Indx
) loop
2276 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2278 if Is_Enumeration_Type
(Etype
(Indx
))
2279 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2281 Non_Standard_Enum
:= True;
2287 -- Processing that is done only for base types
2289 if Ekind
(Arr
) = E_Array_Type
then
2291 -- Deal with default setting of reverse storage order
2293 Set_SSO_From_Default
(Arr
);
2295 -- Propagate flags for component type
2297 if Is_Controlled_Active
(Component_Type
(Arr
))
2298 or else Has_Controlled_Component
(Ctyp
)
2300 Set_Has_Controlled_Component
(Arr
);
2303 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2304 Set_Has_Unchecked_Union
(Arr
);
2307 -- Warn for pragma Pack overriding foreign convention
2309 if Has_Foreign_Convention
(Ctyp
)
2310 and then Has_Pragma_Pack
(Arr
)
2313 CN
: constant Name_Id
:=
2314 Get_Convention_Name
(Convention
(Ctyp
));
2315 PP
: constant Node_Id
:=
2316 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2318 if Present
(PP
) then
2319 Error_Msg_Name_1
:= CN
;
2320 Error_Msg_Sloc
:= Sloc
(Arr
);
2322 ("pragma Pack affects convention % components #??", PP
);
2323 Error_Msg_Name_1
:= CN
;
2325 ("\array components may not have % compatible "
2326 & "representation??", PP
);
2331 -- If packing was requested or if the component size was
2332 -- set explicitly, then see if bit packing is required. This
2333 -- processing is only done for base types, since all of the
2334 -- representation aspects involved are type-related.
2336 -- This is not just an optimization, if we start processing the
2337 -- subtypes, they interfere with the settings on the base type
2338 -- (this is because Is_Packed has a slightly different meaning
2339 -- before and after freezing).
2346 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2347 and then Known_Static_RM_Size
(Ctyp
)
2348 and then not Has_Component_Size_Clause
(Arr
)
2350 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2352 elsif Known_Component_Size
(Arr
) then
2353 Csiz
:= Component_Size
(Arr
);
2355 elsif not Known_Static_Esize
(Ctyp
) then
2359 Esiz
:= Esize
(Ctyp
);
2361 -- We can set the component size if it is less than 16,
2362 -- rounding it up to the next storage unit size.
2366 elsif Esiz
<= 16 then
2372 -- Set component size up to match alignment if it would
2373 -- otherwise be less than the alignment. This deals with
2374 -- cases of types whose alignment exceeds their size (the
2375 -- padded type cases).
2379 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2388 -- Case of component size that may result in packing
2390 if 1 <= Csiz
and then Csiz
<= 64 then
2392 Ent
: constant Entity_Id
:=
2393 First_Subtype
(Arr
);
2394 Pack_Pragma
: constant Node_Id
:=
2395 Get_Rep_Pragma
(Ent
, Name_Pack
);
2396 Comp_Size_C
: constant Node_Id
:=
2397 Get_Attribute_Definition_Clause
2398 (Ent
, Attribute_Component_Size
);
2401 -- Warn if we have pack and component size so that the
2404 -- Note: here we must check for the presence of a
2405 -- component size before checking for a Pack pragma to
2406 -- deal with the case where the array type is a derived
2407 -- type whose parent is currently private.
2409 if Present
(Comp_Size_C
)
2410 and then Has_Pragma_Pack
(Ent
)
2411 and then Warn_On_Redundant_Constructs
2413 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2415 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2417 ("\?r?explicit component size given#!", Pack_Pragma
);
2418 Set_Is_Packed
(Base_Type
(Ent
), False);
2419 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2422 -- Set component size if not already set by a component
2425 if not Present
(Comp_Size_C
) then
2426 Set_Component_Size
(Arr
, Csiz
);
2429 -- Check for base type of 8, 16, 32 bits, where an
2430 -- unsigned subtype has a length one less than the
2431 -- base type (e.g. Natural subtype of Integer).
2433 -- In such cases, if a component size was not set
2434 -- explicitly, then generate a warning.
2436 if Has_Pragma_Pack
(Arr
)
2437 and then not Present
(Comp_Size_C
)
2438 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2439 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2441 Error_Msg_Uint_1
:= Csiz
;
2443 if Present
(Pack_Pragma
) then
2445 ("??pragma Pack causes component size to be ^!",
2448 ("\??use Component_Size to set desired value!",
2453 -- Actual packing is not needed for 8, 16, 32, 64. Also
2454 -- not needed for 24 if alignment is 1.
2460 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
2462 -- Here the array was requested to be packed, but
2463 -- the packing request had no effect, so Is_Packed
2466 -- Note: semantically this means that we lose track
2467 -- of the fact that a derived type inherited a pragma
2468 -- Pack that was non- effective, but that seems fine.
2470 -- We regard a Pack pragma as a request to set a
2471 -- representation characteristic, and this request
2474 Set_Is_Packed
(Base_Type
(Arr
), False);
2475 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2477 if Known_Static_Esize
(Component_Type
(Arr
))
2478 and then Esize
(Component_Type
(Arr
)) = Csiz
2480 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
2483 -- In all other cases, packing is indeed needed
2486 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2487 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2488 Set_Is_Packed
(Base_Type
(Arr
), True);
2494 -- Check for Aliased or Atomic_Components/Atomic/VFA with
2495 -- unsuitable packing or explicit component size clause given.
2497 if (Has_Aliased_Components
(Arr
)
2498 or else Has_Atomic_Components
(Arr
)
2499 or else Is_Atomic_Or_VFA
(Ctyp
))
2501 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2503 Alias_Atomic_Check
: declare
2505 procedure Complain_CS
(T
: String);
2506 -- Outputs error messages for incorrect CS clause or pragma
2507 -- Pack for aliased or atomic/VFA components (T is "aliased"
2508 -- or "atomic/vfa");
2514 procedure Complain_CS
(T
: String) is
2516 if Has_Component_Size_Clause
(Arr
) then
2518 Get_Attribute_Definition_Clause
2519 (FS
, Attribute_Component_Size
);
2522 ("incorrect component size for "
2523 & T
& " components", Clause
);
2524 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2526 ("\only allowed value is^", Clause
);
2530 ("cannot pack " & T
& " components",
2531 Get_Rep_Pragma
(FS
, Name_Pack
));
2535 -- Start of processing for Alias_Atomic_Check
2538 -- If object size of component type isn't known, we cannot
2539 -- be sure so we defer to the back end.
2541 if not Known_Static_Esize
(Ctyp
) then
2544 -- Case where component size has no effect. First check for
2545 -- object size of component type multiple of the storage
2548 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2550 -- OK in both packing case and component size case if RM
2551 -- size is known and static and same as the object size.
2554 ((Known_Static_RM_Size
(Ctyp
)
2555 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2557 -- Or if we have an explicit component size clause and
2558 -- the component size and object size are equal.
2561 (Has_Component_Size_Clause
(Arr
)
2562 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2566 elsif Has_Aliased_Components
(Arr
) then
2567 Complain_CS
("aliased");
2569 elsif Has_Atomic_Components
(Arr
)
2570 or else Is_Atomic
(Ctyp
)
2572 Complain_CS
("atomic");
2574 elsif Is_Volatile_Full_Access
(Ctyp
) then
2575 Complain_CS
("volatile full access");
2577 end Alias_Atomic_Check
;
2580 -- Check for Independent_Components/Independent with unsuitable
2581 -- packing or explicit component size clause given.
2583 if (Has_Independent_Components
(Arr
) or else Is_Independent
(Ctyp
))
2585 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2588 -- If object size of component type isn't known, we cannot
2589 -- be sure so we defer to the back end.
2591 if not Known_Static_Esize
(Ctyp
) then
2594 -- Case where component size has no effect. First check for
2595 -- object size of component type multiple of the storage
2598 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2600 -- OK in both packing case and component size case if RM
2601 -- size is known and multiple of the storage unit size.
2604 ((Known_Static_RM_Size
(Ctyp
)
2605 and then RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
2607 -- Or if we have an explicit component size clause and
2608 -- the component size is larger than the object size.
2611 (Has_Component_Size_Clause
(Arr
)
2612 and then Component_Size
(Arr
) >= Esize
(Ctyp
)))
2617 if Has_Component_Size_Clause
(Arr
) then
2619 Get_Attribute_Definition_Clause
2620 (FS
, Attribute_Component_Size
);
2623 ("incorrect component size for "
2624 & "independent components", Clause
);
2625 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2627 ("\minimum allowed is^", Clause
);
2631 ("cannot pack independent components",
2632 Get_Rep_Pragma
(FS
, Name_Pack
));
2638 -- Warn for case of atomic type
2640 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2643 and then not Addressable
(Component_Size
(FS
))
2646 ("non-atomic components of type& may not be "
2647 & "accessible by separate tasks??", Clause
, Arr
);
2649 if Has_Component_Size_Clause
(Arr
) then
2650 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2651 (FS
, Attribute_Component_Size
));
2652 Error_Msg_N
("\because of component size clause#??", Clause
);
2654 elsif Has_Pragma_Pack
(Arr
) then
2655 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2656 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2660 -- Check for scalar storage order
2665 Check_Component_Storage_Order
2668 ADC
=> Get_Attribute_Definition_Clause
2669 (First_Subtype
(Arr
),
2670 Attribute_Scalar_Storage_Order
),
2671 Comp_ADC_Present
=> Dummy
);
2674 -- Processing that is done only for subtypes
2677 -- Acquire alignment from base type
2679 if Unknown_Alignment
(Arr
) then
2680 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2681 Adjust_Esize_Alignment
(Arr
);
2685 -- Specific checks for bit-packed arrays
2687 if Is_Bit_Packed_Array
(Arr
) then
2689 -- Check number of elements for bit packed arrays that come from
2690 -- source and have compile time known ranges. The bit-packed
2691 -- arrays circuitry does not support arrays with more than
2692 -- Integer'Last + 1 elements, and when this restriction is
2693 -- violated, causes incorrect data access.
2695 -- For the case where this is not compile time known, a run-time
2696 -- check should be generated???
2698 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
2707 Index
:= First_Index
(Arr
);
2708 while Present
(Index
) loop
2709 Ityp
:= Etype
(Index
);
2711 -- Never generate an error if any index is of a generic
2712 -- type. We will check this in instances.
2714 if Is_Generic_Type
(Ityp
) then
2720 Make_Attribute_Reference
(Loc
,
2721 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2722 Attribute_Name
=> Name_Range_Length
);
2723 Analyze_And_Resolve
(Ilen
);
2725 -- No attempt is made to check number of elements if not
2726 -- compile time known.
2728 if Nkind
(Ilen
) /= N_Integer_Literal
then
2733 Elmts
:= Elmts
* Intval
(Ilen
);
2737 if Elmts
> Intval
(High_Bound
2738 (Scalar_Range
(Standard_Integer
))) + 1
2741 ("bit packed array type may not have "
2742 & "more than Integer''Last+1 elements", Arr
);
2749 if Known_RM_Size
(Arr
) then
2751 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
2755 -- It is not clear if it is possible to have no size clause
2756 -- at this stage, but it is not worth worrying about. Post
2757 -- error on the entity name in the size clause if present,
2758 -- else on the type entity itself.
2760 if Present
(SizC
) then
2761 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
2763 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
2769 -- If any of the index types was an enumeration type with a non-
2770 -- standard rep clause, then we indicate that the array type is
2771 -- always packed (even if it is not bit packed).
2773 if Non_Standard_Enum
then
2774 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
2775 Set_Is_Packed
(Base_Type
(Arr
));
2778 Set_Component_Alignment_If_Not_Set
(Arr
);
2780 -- If the array is packed, we must create the packed array type to be
2781 -- used to actually implement the type. This is only needed for real
2782 -- array types (not for string literal types, since they are present
2783 -- only for the front end).
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 -- Check whether function is declared elsewhere.
3291 Get_Source_Unit
(E
) /= Get_Source_Unit
(N
)
3292 and then Returns_Limited_View
(E
)
3293 and then not In_Open_Scopes
(Scope
(E
));
3295 -- Freeze return type
3297 R_Type
:= Etype
(E
);
3299 -- AI05-0151: the return type may have been incomplete
3300 -- at the point of declaration. Replace it with the full
3301 -- view, unless the current type is a limited view. In
3302 -- that case the full view is in a different unit, and
3303 -- gigi finds the non-limited view after the other unit
3306 if Ekind
(R_Type
) = E_Incomplete_Type
3307 and then Present
(Full_View
(R_Type
))
3308 and then not From_Limited_With
(R_Type
)
3310 R_Type
:= Full_View
(R_Type
);
3311 Set_Etype
(E
, R_Type
);
3313 -- If the return type is a limited view and the non-limited
3314 -- view is still incomplete, the function has to be frozen at a
3315 -- later time. If the function is abstract there is no place at
3316 -- which the full view will become available, and no code to be
3317 -- generated for it, so mark type as frozen.
3319 elsif Ekind
(R_Type
) = E_Incomplete_Type
3320 and then From_Limited_With
(R_Type
)
3321 and then Ekind
(Non_Limited_View
(R_Type
)) = E_Incomplete_Type
3323 if Is_Abstract_Subprogram
(E
) then
3326 Set_Is_Frozen
(E
, False);
3327 Set_Returns_Limited_View
(E
);
3332 Freeze_And_Append
(R_Type
, N
, Result
);
3334 -- Check suspicious return type for C function
3336 if Warn_On_Export_Import
3337 and then (Convention
(E
) = Convention_C
3339 Convention
(E
) = Convention_CPP
)
3340 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3342 -- Check suspicious return of fat C pointer
3344 if Is_Access_Type
(R_Type
)
3345 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
3346 and then not Has_Warnings_Off
(E
)
3347 and then not Has_Warnings_Off
(R_Type
)
3349 Error_Msg_N
("?x?return type of& does not "
3350 & "correspond to C pointer!", E
);
3352 -- Check suspicious return of boolean
3354 elsif Root_Type
(R_Type
) = Standard_Boolean
3355 and then Convention
(R_Type
) = Convention_Ada
3356 and then not Has_Warnings_Off
(E
)
3357 and then not Has_Warnings_Off
(R_Type
)
3358 and then not Has_Size_Clause
(R_Type
)
3361 N
: constant Node_Id
:=
3362 Result_Definition
(Declaration_Node
(E
));
3365 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
3367 ("\use appropriate corresponding type in C "
3368 & "(e.g. char)?x?", N
, E
);
3371 -- Check suspicious return tagged type
3373 elsif (Is_Tagged_Type
(R_Type
)
3374 or else (Is_Access_Type
(R_Type
)
3377 (Designated_Type
(R_Type
))))
3378 and then Convention
(E
) = Convention_C
3379 and then not Has_Warnings_Off
(E
)
3380 and then not Has_Warnings_Off
(R_Type
)
3382 Error_Msg_N
("?x?return type of & does not "
3383 & "correspond to C type!", E
);
3385 -- Check return of wrong convention subprogram pointer
3387 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3388 and then not Has_Foreign_Convention
(R_Type
)
3389 and then not Has_Warnings_Off
(E
)
3390 and then not Has_Warnings_Off
(R_Type
)
3392 Error_Msg_N
("?x?& should return a foreign "
3393 & "convention subprogram pointer", E
);
3394 Error_Msg_Sloc
:= Sloc
(R_Type
);
3396 ("\?x?add Convention pragma to declaration of& #",
3401 -- Give warning for suspicious return of a result of an
3402 -- unconstrained array type in a foreign convention function.
3404 if Has_Foreign_Convention
(E
)
3406 -- We are looking for a return of unconstrained array
3408 and then Is_Array_Type
(R_Type
)
3409 and then not Is_Constrained
(R_Type
)
3411 -- Exclude imported routines, the warning does not belong on
3412 -- the import, but rather on the routine definition.
3414 and then not Is_Imported
(E
)
3416 -- Check that general warning is enabled, and that it is not
3417 -- suppressed for this particular case.
3419 and then Warn_On_Export_Import
3420 and then not Has_Warnings_Off
(E
)
3421 and then not Has_Warnings_Off
(R_Type
)
3424 ("?x?foreign convention function& should not return "
3425 & "unconstrained array!", E
);
3429 -- Check suspicious use of Import in pure unit (cases where the RM
3430 -- allows calls to be omitted).
3434 -- It might be suspicious if the compilation unit has the Pure
3437 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
3439 -- The RM allows omission of calls only in the case of
3440 -- library-level subprograms (see RM-10.2.1(18)).
3442 and then Is_Library_Level_Entity
(E
)
3444 -- Ignore internally generated entity. This happens in some cases
3445 -- of subprograms in specs, where we generate an implied body.
3447 and then Comes_From_Source
(Import_Pragma
(E
))
3449 -- Assume run-time knows what it is doing
3451 and then not GNAT_Mode
3453 -- Assume explicit Pure_Function means import is pure
3455 and then not Has_Pragma_Pure_Function
(E
)
3457 -- Don't need warning in relaxed semantics mode
3459 and then not Relaxed_RM_Semantics
3461 -- Assume convention Intrinsic is OK, since this is specialized.
3462 -- This deals with the DEC unit current_exception.ads
3464 and then Convention
(E
) /= Convention_Intrinsic
3466 -- Assume that ASM interface knows what it is doing. This deals
3467 -- with unsigned.ads in the AAMP back end.
3469 and then Convention
(E
) /= Convention_Assembler
3472 ("pragma Import in Pure unit??", Import_Pragma
(E
));
3474 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
3475 Import_Pragma
(E
), E
);
3481 ------------------------
3482 -- Freeze_Record_Type --
3483 ------------------------
3485 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
3492 pragma Warnings
(Off
, Junk
);
3494 Rec_Pushed
: Boolean := False;
3495 -- Set True if the record type scope Rec has been pushed on the scope
3496 -- stack. Needed for the analysis of delayed aspects specified to the
3497 -- components of Rec.
3500 -- Scalar_Storage_Order attribute definition clause for the record
3502 Unplaced_Component
: Boolean := False;
3503 -- Set True if we find at least one component with no component
3504 -- clause (used to warn about useless Pack pragmas).
3506 Placed_Component
: Boolean := False;
3507 -- Set True if we find at least one component with a component
3508 -- clause (used to warn about useless Bit_Order pragmas, and also
3509 -- to detect cases where Implicit_Packing may have an effect).
3511 Aliased_Component
: Boolean := False;
3512 -- Set True if we find at least one component which is aliased. This
3513 -- is used to prevent Implicit_Packing of the record, since packing
3514 -- cannot modify the size of alignment of an aliased component.
3516 SSO_ADC_Component
: Boolean := False;
3517 -- Set True if we find at least one component whose type has a
3518 -- Scalar_Storage_Order attribute definition clause.
3520 All_Scalar_Components
: Boolean := True;
3521 -- Set False if we encounter a component of a non-scalar type
3523 Scalar_Component_Total_RM_Size
: Uint
:= Uint_0
;
3524 Scalar_Component_Total_Esize
: Uint
:= Uint_0
;
3525 -- Accumulates total RM_Size values and total Esize values of all
3526 -- scalar components. Used for processing of Implicit_Packing.
3528 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
3529 -- If N is an allocator, possibly wrapped in one or more level of
3530 -- qualified expression(s), return the inner allocator node, else
3533 procedure Check_Itype
(Typ
: Entity_Id
);
3534 -- If the component subtype is an access to a constrained subtype of
3535 -- an already frozen type, make the subtype frozen as well. It might
3536 -- otherwise be frozen in the wrong scope, and a freeze node on
3537 -- subtype has no effect. Similarly, if the component subtype is a
3538 -- regular (not protected) access to subprogram, set the anonymous
3539 -- subprogram type to frozen as well, to prevent an out-of-scope
3540 -- freeze node at some eventual point of call. Protected operations
3541 -- are handled elsewhere.
3543 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
3544 -- Make sure that all types mentioned in Discrete_Choices of the
3545 -- variants referenceed by the Variant_Part VP are frozen. This is
3546 -- a recursive routine to deal with nested variants.
3548 ---------------------
3549 -- Check_Allocator --
3550 ---------------------
3552 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
3557 if Nkind
(Inner
) = N_Allocator
then
3559 elsif Nkind
(Inner
) = N_Qualified_Expression
then
3560 Inner
:= Expression
(Inner
);
3565 end Check_Allocator
;
3571 procedure Check_Itype
(Typ
: Entity_Id
) is
3572 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
3575 if not Is_Frozen
(Desig
)
3576 and then Is_Frozen
(Base_Type
(Desig
))
3578 Set_Is_Frozen
(Desig
);
3580 -- In addition, add an Itype_Reference to ensure that the
3581 -- access subtype is elaborated early enough. This cannot be
3582 -- done if the subtype may depend on discriminants.
3584 if Ekind
(Comp
) = E_Component
3585 and then Is_Itype
(Etype
(Comp
))
3586 and then not Has_Discriminants
(Rec
)
3588 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
3589 Set_Itype
(IR
, Desig
);
3593 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
3594 and then Convention
(Desig
) /= Convention_Protected
3596 Set_Is_Frozen
(Desig
);
3600 ------------------------------------
3601 -- Freeze_Choices_In_Variant_Part --
3602 ------------------------------------
3604 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
3605 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
3612 -- Loop through variants
3614 Variant
:= First_Non_Pragma
(Variants
(VP
));
3615 while Present
(Variant
) loop
3617 -- Loop through choices, checking that all types are frozen
3619 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
3620 while Present
(Choice
) loop
3621 if Nkind
(Choice
) in N_Has_Etype
3622 and then Present
(Etype
(Choice
))
3624 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
3627 Next_Non_Pragma
(Choice
);
3630 -- Check for nested variant part to process
3632 CL
:= Component_List
(Variant
);
3634 if not Null_Present
(CL
) then
3635 if Present
(Variant_Part
(CL
)) then
3636 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
3640 Next_Non_Pragma
(Variant
);
3642 end Freeze_Choices_In_Variant_Part
;
3644 -- Start of processing for Freeze_Record_Type
3647 -- Deal with delayed aspect specifications for components. The
3648 -- analysis of the aspect is required to be delayed to the freeze
3649 -- point, thus we analyze the pragma or attribute definition
3650 -- clause in the tree at this point. We also analyze the aspect
3651 -- specification node at the freeze point when the aspect doesn't
3652 -- correspond to pragma/attribute definition clause.
3654 Comp
:= First_Entity
(Rec
);
3655 while Present
(Comp
) loop
3656 if Ekind
(Comp
) = E_Component
3657 and then Has_Delayed_Aspects
(Comp
)
3659 if not Rec_Pushed
then
3663 -- The visibility to the discriminants must be restored in
3664 -- order to properly analyze the aspects.
3666 if Has_Discriminants
(Rec
) then
3667 Install_Discriminants
(Rec
);
3671 Analyze_Aspects_At_Freeze_Point
(Comp
);
3677 -- Pop the scope if Rec scope has been pushed on the scope stack
3678 -- during the delayed aspect analysis process.
3681 if Has_Discriminants
(Rec
) then
3682 Uninstall_Discriminants
(Rec
);
3688 -- Freeze components and embedded subtypes
3690 Comp
:= First_Entity
(Rec
);
3692 while Present
(Comp
) loop
3693 if Is_Aliased
(Comp
) then
3694 Aliased_Component
:= True;
3697 -- Handle the component and discriminant case
3699 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
3701 CC
: constant Node_Id
:= Component_Clause
(Comp
);
3704 -- Freezing a record type freezes the type of each of its
3705 -- components. However, if the type of the component is
3706 -- part of this record, we do not want or need a separate
3707 -- Freeze_Node. Note that Is_Itype is wrong because that's
3708 -- also set in private type cases. We also can't check for
3709 -- the Scope being exactly Rec because of private types and
3710 -- record extensions.
3712 if Is_Itype
(Etype
(Comp
))
3713 and then Is_Record_Type
(Underlying_Type
3714 (Scope
(Etype
(Comp
))))
3716 Undelay_Type
(Etype
(Comp
));
3719 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
3721 -- Warn for pragma Pack overriding foreign convention
3723 if Has_Foreign_Convention
(Etype
(Comp
))
3724 and then Has_Pragma_Pack
(Rec
)
3726 -- Don't warn for aliased components, since override
3727 -- cannot happen in that case.
3729 and then not Is_Aliased
(Comp
)
3732 CN
: constant Name_Id
:=
3733 Get_Convention_Name
(Convention
(Etype
(Comp
)));
3734 PP
: constant Node_Id
:=
3735 Get_Pragma
(Rec
, Pragma_Pack
);
3737 if Present
(PP
) then
3738 Error_Msg_Name_1
:= CN
;
3739 Error_Msg_Sloc
:= Sloc
(Comp
);
3741 ("pragma Pack affects convention % component#??",
3743 Error_Msg_Name_1
:= CN
;
3745 ("\component & may not have % compatible "
3746 & "representation??", PP
, Comp
);
3751 -- Check for error of component clause given for variable
3752 -- sized type. We have to delay this test till this point,
3753 -- since the component type has to be frozen for us to know
3754 -- if it is variable length.
3756 if Present
(CC
) then
3757 Placed_Component
:= True;
3759 -- We omit this test in a generic context, it will be
3760 -- applied at instantiation time.
3762 if Inside_A_Generic
then
3765 -- Also omit this test in CodePeer mode, since we do not
3766 -- have sufficient info on size and rep clauses.
3768 elsif CodePeer_Mode
then
3771 -- Omit check if component has a generic type. This can
3772 -- happen in an instantiation within a generic in ASIS
3773 -- mode, where we force freeze actions without full
3776 elsif Is_Generic_Type
(Etype
(Comp
)) then
3782 Size_Known_At_Compile_Time
3783 (Underlying_Type
(Etype
(Comp
)))
3786 ("component clause not allowed for variable " &
3787 "length component", CC
);
3791 Unplaced_Component
:= True;
3794 -- Case of component requires byte alignment
3796 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
3798 -- Set the enclosing record to also require byte align
3800 Set_Must_Be_On_Byte_Boundary
(Rec
);
3802 -- Check for component clause that is inconsistent with
3803 -- the required byte boundary alignment.
3806 and then Normalized_First_Bit
(Comp
) mod
3807 System_Storage_Unit
/= 0
3810 ("component & must be byte aligned",
3811 Component_Name
(Component_Clause
(Comp
)));
3817 -- Gather data for possible Implicit_Packing later. Note that at
3818 -- this stage we might be dealing with a real component, or with
3819 -- an implicit subtype declaration.
3821 if not Is_Scalar_Type
(Etype
(Comp
)) then
3822 All_Scalar_Components
:= False;
3824 Scalar_Component_Total_RM_Size
:=
3825 Scalar_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
3826 Scalar_Component_Total_Esize
:=
3827 Scalar_Component_Total_Esize
+ Esize
(Etype
(Comp
));
3830 -- If the component is an Itype with Delayed_Freeze and is either
3831 -- a record or array subtype and its base type has not yet been
3832 -- frozen, we must remove this from the entity list of this record
3833 -- and put it on the entity list of the scope of its base type.
3834 -- Note that we know that this is not the type of a component
3835 -- since we cleared Has_Delayed_Freeze for it in the previous
3836 -- loop. Thus this must be the Designated_Type of an access type,
3837 -- which is the type of a component.
3840 and then Is_Type
(Scope
(Comp
))
3841 and then Is_Composite_Type
(Comp
)
3842 and then Base_Type
(Comp
) /= Comp
3843 and then Has_Delayed_Freeze
(Comp
)
3844 and then not Is_Frozen
(Base_Type
(Comp
))
3847 Will_Be_Frozen
: Boolean := False;
3851 -- We have a difficult case to handle here. Suppose Rec is
3852 -- subtype being defined in a subprogram that's created as
3853 -- part of the freezing of Rec'Base. In that case, we know
3854 -- that Comp'Base must have already been frozen by the time
3855 -- we get to elaborate this because Gigi doesn't elaborate
3856 -- any bodies until it has elaborated all of the declarative
3857 -- part. But Is_Frozen will not be set at this point because
3858 -- we are processing code in lexical order.
3860 -- We detect this case by going up the Scope chain of Rec
3861 -- and seeing if we have a subprogram scope before reaching
3862 -- the top of the scope chain or that of Comp'Base. If we
3863 -- do, then mark that Comp'Base will actually be frozen. If
3864 -- so, we merely undelay it.
3867 while Present
(S
) loop
3868 if Is_Subprogram
(S
) then
3869 Will_Be_Frozen
:= True;
3871 elsif S
= Scope
(Base_Type
(Comp
)) then
3878 if Will_Be_Frozen
then
3879 Undelay_Type
(Comp
);
3882 if Present
(Prev
) then
3883 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
3885 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
3888 -- Insert in entity list of scope of base type (which
3889 -- must be an enclosing scope, because still unfrozen).
3891 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
3895 -- If the component is an access type with an allocator as default
3896 -- value, the designated type will be frozen by the corresponding
3897 -- expression in init_proc. In order to place the freeze node for
3898 -- the designated type before that for the current record type,
3901 -- Same process if the component is an array of access types,
3902 -- initialized with an aggregate. If the designated type is
3903 -- private, it cannot contain allocators, and it is premature
3904 -- to freeze the type, so we check for this as well.
3906 elsif Is_Access_Type
(Etype
(Comp
))
3907 and then Present
(Parent
(Comp
))
3908 and then Present
(Expression
(Parent
(Comp
)))
3911 Alloc
: constant Node_Id
:=
3912 Check_Allocator
(Expression
(Parent
(Comp
)));
3915 if Present
(Alloc
) then
3917 -- If component is pointer to a class-wide type, freeze
3918 -- the specific type in the expression being allocated.
3919 -- The expression may be a subtype indication, in which
3920 -- case freeze the subtype mark.
3922 if Is_Class_Wide_Type
3923 (Designated_Type
(Etype
(Comp
)))
3925 if Is_Entity_Name
(Expression
(Alloc
)) then
3927 (Entity
(Expression
(Alloc
)), N
, Result
);
3929 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
3932 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
3936 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
3937 Check_Itype
(Etype
(Comp
));
3941 (Designated_Type
(Etype
(Comp
)), N
, Result
);
3946 elsif Is_Access_Type
(Etype
(Comp
))
3947 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
3949 Check_Itype
(Etype
(Comp
));
3951 -- Freeze the designated type when initializing a component with
3952 -- an aggregate in case the aggregate contains allocators.
3955 -- type T_Ptr is access all T;
3956 -- type T_Array is array ... of T_Ptr;
3958 -- type Rec is record
3959 -- Comp : T_Array := (others => ...);
3962 elsif Is_Array_Type
(Etype
(Comp
))
3963 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
3966 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
3967 Desig_Typ
: constant Entity_Id
:=
3969 (Component_Type
(Etype
(Comp
)));
3972 -- The only case when this sort of freezing is not done is
3973 -- when the designated type is class-wide and the root type
3974 -- is the record owning the component. This scenario results
3975 -- in a circularity because the class-wide type requires
3976 -- primitives that have not been created yet as the root
3977 -- type is in the process of being frozen.
3979 -- type Rec is tagged;
3980 -- type Rec_Ptr is access all Rec'Class;
3981 -- type Rec_Array is array ... of Rec_Ptr;
3983 -- type Rec is record
3984 -- Comp : Rec_Array := (others => ...);
3987 if Is_Class_Wide_Type
(Desig_Typ
)
3988 and then Root_Type
(Desig_Typ
) = Rec
3992 elsif Is_Fully_Defined
(Desig_Typ
)
3993 and then Present
(Comp_Par
)
3994 and then Nkind
(Comp_Par
) = N_Component_Declaration
3995 and then Present
(Expression
(Comp_Par
))
3996 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
3998 Freeze_And_Append
(Desig_Typ
, N
, Result
);
4008 Get_Attribute_Definition_Clause
4009 (Rec
, Attribute_Scalar_Storage_Order
);
4011 -- If the record type has Complex_Representation, then it is treated
4012 -- as a scalar in the back end so the storage order is irrelevant.
4014 if Has_Complex_Representation
(Rec
) then
4015 if Present
(SSO_ADC
) then
4017 ("??storage order has no effect with Complex_Representation",
4022 -- Deal with default setting of reverse storage order
4024 Set_SSO_From_Default
(Rec
);
4026 -- Check consistent attribute setting on component types
4029 Comp_ADC_Present
: Boolean;
4031 Comp
:= First_Component
(Rec
);
4032 while Present
(Comp
) loop
4033 Check_Component_Storage_Order
4037 Comp_ADC_Present
=> Comp_ADC_Present
);
4038 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
4039 Next_Component
(Comp
);
4043 -- Now deal with reverse storage order/bit order issues
4045 if Present
(SSO_ADC
) then
4047 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
4048 -- if the former is specified.
4050 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
4052 -- Note: report error on Rec, not on SSO_ADC, as ADC may
4053 -- apply to some ancestor type.
4055 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
4057 ("scalar storage order for& specified# inconsistent with "
4058 & "bit order", Rec
);
4061 -- Warn if there is a Scalar_Storage_Order attribute definition
4062 -- clause but no component clause, no component that itself has
4063 -- such an attribute definition, and no pragma Pack.
4065 if not (Placed_Component
4072 ("??scalar storage order specified but no component "
4073 & "clause", SSO_ADC
);
4078 -- Deal with Bit_Order aspect
4080 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
4082 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
4083 if not (Placed_Component
4084 or else Present
(SSO_ADC
)
4085 or else Is_Packed
(Rec
))
4087 -- Warn if clause has no effect when no component clause is
4088 -- present, but suppress warning if the Bit_Order is required
4089 -- due to the presence of a Scalar_Storage_Order attribute.
4092 ("??bit order specification has no effect", ADC
);
4094 ("\??since no component clauses were specified", ADC
);
4096 -- Here is where we do the processing to adjust component clauses
4097 -- for reversed bit order, when not using reverse SSO.
4099 elsif Reverse_Bit_Order
(Rec
)
4100 and then not Reverse_Storage_Order
(Rec
)
4102 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
4104 -- Case where we have both an explicit Bit_Order and the same
4105 -- Scalar_Storage_Order: leave record untouched, the back-end
4106 -- will take care of required layout conversions.
4114 -- Complete error checking on record representation clause (e.g.
4115 -- overlap of components). This is called after adjusting the
4116 -- record for reverse bit order.
4119 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
4121 if Present
(RRC
) then
4122 Check_Record_Representation_Clause
(RRC
);
4126 -- Set OK_To_Reorder_Components depending on debug flags
4128 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
4129 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
4131 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
4133 Set_OK_To_Reorder_Components
(Rec
);
4137 -- Check for useless pragma Pack when all components placed. We only
4138 -- do this check for record types, not subtypes, since a subtype may
4139 -- have all its components placed, and it still makes perfectly good
4140 -- sense to pack other subtypes or the parent type. We do not give
4141 -- this warning if Optimize_Alignment is set to Space, since the
4142 -- pragma Pack does have an effect in this case (it always resets
4143 -- the alignment to one).
4145 if Ekind
(Rec
) = E_Record_Type
4146 and then Is_Packed
(Rec
)
4147 and then not Unplaced_Component
4148 and then Optimize_Alignment
/= 'S'
4150 -- Reset packed status. Probably not necessary, but we do it so
4151 -- that there is no chance of the back end doing something strange
4152 -- with this redundant indication of packing.
4154 Set_Is_Packed
(Rec
, False);
4156 -- Give warning if redundant constructs warnings on
4158 if Warn_On_Redundant_Constructs
then
4159 Error_Msg_N
-- CODEFIX
4160 ("??pragma Pack has no effect, no unplaced components",
4161 Get_Rep_Pragma
(Rec
, Name_Pack
));
4165 -- If this is the record corresponding to a remote type, freeze the
4166 -- remote type here since that is what we are semantically freezing.
4167 -- This prevents the freeze node for that type in an inner scope.
4169 if Ekind
(Rec
) = E_Record_Type
then
4170 if Present
(Corresponding_Remote_Type
(Rec
)) then
4171 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
4174 -- Check for controlled components and unchecked unions.
4176 Comp
:= First_Component
(Rec
);
4177 while Present
(Comp
) loop
4179 -- Do not set Has_Controlled_Component on a class-wide
4180 -- equivalent type. See Make_CW_Equivalent_Type.
4182 if not Is_Class_Wide_Equivalent_Type
(Rec
)
4184 (Has_Controlled_Component
(Etype
(Comp
))
4186 (Chars
(Comp
) /= Name_uParent
4187 and then Is_Controlled_Active
(Etype
(Comp
)))
4189 (Is_Protected_Type
(Etype
(Comp
))
4191 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
4193 Has_Controlled_Component
4194 (Corresponding_Record_Type
(Etype
(Comp
)))))
4196 Set_Has_Controlled_Component
(Rec
);
4199 if Has_Unchecked_Union
(Etype
(Comp
)) then
4200 Set_Has_Unchecked_Union
(Rec
);
4203 -- Scan component declaration for likely misuses of current
4204 -- instance, either in a constraint or a default expression.
4206 if Has_Per_Object_Constraint
(Comp
) then
4207 Check_Current_Instance
(Parent
(Comp
));
4210 Next_Component
(Comp
);
4214 -- Enforce the restriction that access attributes with a current
4215 -- instance prefix can only apply to limited types. This comment
4216 -- is floating here, but does not seem to belong here???
4218 -- Set component alignment if not otherwise already set
4220 Set_Component_Alignment_If_Not_Set
(Rec
);
4222 -- For first subtypes, check if there are any fixed-point fields with
4223 -- component clauses, where we must check the size. This is not done
4224 -- till the freeze point since for fixed-point types, we do not know
4225 -- the size until the type is frozen. Similar processing applies to
4226 -- bit packed arrays.
4228 if Is_First_Subtype
(Rec
) then
4229 Comp
:= First_Component
(Rec
);
4230 while Present
(Comp
) loop
4231 if Present
(Component_Clause
(Comp
))
4232 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
4233 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
4236 (Component_Name
(Component_Clause
(Comp
)),
4242 Next_Component
(Comp
);
4246 -- Generate warning for applying C or C++ convention to a record
4247 -- with discriminants. This is suppressed for the unchecked union
4248 -- case, since the whole point in this case is interface C. We also
4249 -- do not generate this within instantiations, since we will have
4250 -- generated a message on the template.
4252 if Has_Discriminants
(E
)
4253 and then not Is_Unchecked_Union
(E
)
4254 and then (Convention
(E
) = Convention_C
4256 Convention
(E
) = Convention_CPP
)
4257 and then Comes_From_Source
(E
)
4258 and then not In_Instance
4259 and then not Has_Warnings_Off
(E
)
4260 and then not Has_Warnings_Off
(Base_Type
(E
))
4263 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
4267 if Present
(Cprag
) then
4268 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
4270 if Convention
(E
) = Convention_C
then
4272 ("?x?variant record has no direct equivalent in C",
4276 ("?x?variant record has no direct equivalent in C++",
4281 ("\?x?use of convention for type& is dubious", A2
, E
);
4286 -- See if Size is too small as is (and implicit packing might help)
4288 if not Is_Packed
(Rec
)
4290 -- No implicit packing if even one component is explicitly placed
4292 and then not Placed_Component
4294 -- Or even one component is aliased
4296 and then not Aliased_Component
4298 -- Must have size clause and all scalar components
4300 and then Has_Size_Clause
(Rec
)
4301 and then All_Scalar_Components
4303 -- Do not try implicit packing on records with discriminants, too
4304 -- complicated, especially in the variant record case.
4306 and then not Has_Discriminants
(Rec
)
4308 -- We can implicitly pack if the specified size of the record is
4309 -- less than the sum of the object sizes (no point in packing if
4310 -- this is not the case).
4312 and then RM_Size
(Rec
) < Scalar_Component_Total_Esize
4314 -- And the total RM size cannot be greater than the specified size
4315 -- since otherwise packing will not get us where we have to be.
4317 and then RM_Size
(Rec
) >= Scalar_Component_Total_RM_Size
4319 -- Never do implicit packing in CodePeer or SPARK modes since
4320 -- we don't do any packing in these modes, since this generates
4321 -- over-complex code that confuses static analysis, and in
4322 -- general, neither CodePeer not GNATprove care about the
4323 -- internal representation of objects.
4325 and then not (CodePeer_Mode
or GNATprove_Mode
)
4327 -- If implicit packing enabled, do it
4329 if Implicit_Packing
then
4330 Set_Is_Packed
(Rec
);
4332 -- Otherwise flag the size clause
4336 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
4338 Error_Msg_NE
-- CODEFIX
4339 ("size given for& too small", Sz
, Rec
);
4340 Error_Msg_N
-- CODEFIX
4341 ("\use explicit pragma Pack "
4342 & "or use pragma Implicit_Packing", Sz
);
4347 -- The following checks are relevant only when SPARK_Mode is on as
4348 -- they are not standard Ada legality rules.
4350 if SPARK_Mode
= On
then
4351 if Is_Effectively_Volatile
(Rec
) then
4353 -- A discriminated type cannot be effectively volatile
4354 -- (SPARK RM C.6(4)).
4356 if Has_Discriminants
(Rec
) then
4357 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
4359 -- A tagged type cannot be effectively volatile
4360 -- (SPARK RM C.6(5)).
4362 elsif Is_Tagged_Type
(Rec
) then
4363 Error_Msg_N
("tagged type & cannot be volatile", Rec
);
4366 -- A non-effectively volatile record type cannot contain
4367 -- effectively volatile components (SPARK RM C.6(2)).
4370 Comp
:= First_Component
(Rec
);
4371 while Present
(Comp
) loop
4372 if Comes_From_Source
(Comp
)
4373 and then Is_Effectively_Volatile
(Etype
(Comp
))
4375 Error_Msg_Name_1
:= Chars
(Rec
);
4377 ("component & of non-volatile type % cannot be "
4378 & "volatile", Comp
);
4381 Next_Component
(Comp
);
4385 -- A type which does not yield a synchronized object cannot have
4386 -- a component that yields a synchronized object (SPARK RM 9.5).
4388 if not Yields_Synchronized_Object
(Rec
) then
4389 Comp
:= First_Component
(Rec
);
4390 while Present
(Comp
) loop
4391 if Comes_From_Source
(Comp
)
4392 and then Yields_Synchronized_Object
(Etype
(Comp
))
4394 Error_Msg_Name_1
:= Chars
(Rec
);
4396 ("component & of non-synchronized type % cannot be "
4397 & "synchronized", Comp
);
4400 Next_Component
(Comp
);
4404 -- A Ghost type cannot have a component of protected or task type
4405 -- (SPARK RM 6.9(19)).
4407 if Is_Ghost_Entity
(Rec
) then
4408 Comp
:= First_Component
(Rec
);
4409 while Present
(Comp
) loop
4410 if Comes_From_Source
(Comp
)
4411 and then Is_Concurrent_Type
(Etype
(Comp
))
4413 Error_Msg_Name_1
:= Chars
(Rec
);
4415 ("component & of ghost type % cannot be concurrent",
4419 Next_Component
(Comp
);
4424 -- Make sure that if we have an iterator aspect, then we have
4425 -- either Constant_Indexing or Variable_Indexing.
4428 Iterator_Aspect
: Node_Id
;
4431 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
4433 if No
(Iterator_Aspect
) then
4434 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
4437 if Present
(Iterator_Aspect
) then
4438 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
4440 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
4445 ("Iterator_Element requires indexing aspect",
4451 -- All done if not a full record definition
4453 if Ekind
(Rec
) /= E_Record_Type
then
4457 -- Finally we need to check the variant part to make sure that
4458 -- all types within choices are properly frozen as part of the
4459 -- freezing of the record type.
4461 Check_Variant_Part
: declare
4462 D
: constant Node_Id
:= Declaration_Node
(Rec
);
4467 -- Find component list
4471 if Nkind
(D
) = N_Full_Type_Declaration
then
4472 T
:= Type_Definition
(D
);
4474 if Nkind
(T
) = N_Record_Definition
then
4475 C
:= Component_List
(T
);
4477 elsif Nkind
(T
) = N_Derived_Type_Definition
4478 and then Present
(Record_Extension_Part
(T
))
4480 C
:= Component_List
(Record_Extension_Part
(T
));
4484 -- Case of variant part present
4486 if Present
(C
) and then Present
(Variant_Part
(C
)) then
4487 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
4490 -- Note: we used to call Check_Choices here, but it is too early,
4491 -- since predicated subtypes are frozen here, but their freezing
4492 -- actions are in Analyze_Freeze_Entity, which has not been called
4493 -- yet for entities frozen within this procedure, so we moved that
4494 -- call to the Analyze_Freeze_Entity for the record type.
4496 end Check_Variant_Part
;
4498 -- Check that all the primitives of an interface type are abstract
4499 -- or null procedures.
4501 if Is_Interface
(Rec
)
4502 and then not Error_Posted
(Parent
(Rec
))
4509 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
4510 while Present
(Elmt
) loop
4511 Subp
:= Node
(Elmt
);
4513 if not Is_Abstract_Subprogram
(Subp
)
4515 -- Avoid reporting the error on inherited primitives
4517 and then Comes_From_Source
(Subp
)
4519 Error_Msg_Name_1
:= Chars
(Subp
);
4521 if Ekind
(Subp
) = E_Procedure
then
4522 if not Null_Present
(Parent
(Subp
)) then
4524 ("interface procedure % must be abstract or null",
4529 ("interface function % must be abstract",
4538 end Freeze_Record_Type
;
4540 -------------------------------
4541 -- Has_Boolean_Aspect_Import --
4542 -------------------------------
4544 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
4545 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4550 if Has_Aspects
(Decl
) then
4551 Asp
:= First
(Aspect_Specifications
(Decl
));
4552 while Present
(Asp
) loop
4553 Expr
:= Expression
(Asp
);
4555 -- The value of aspect Import is True when the expression is
4556 -- either missing or it is explicitly set to True.
4558 if Get_Aspect_Id
(Asp
) = Aspect_Import
4560 or else (Compile_Time_Known_Value
(Expr
)
4561 and then Is_True
(Expr_Value
(Expr
))))
4571 end Has_Boolean_Aspect_Import
;
4573 ----------------------------
4574 -- Late_Freeze_Subprogram --
4575 ----------------------------
4577 procedure Late_Freeze_Subprogram
(E
: Entity_Id
) is
4578 Spec
: constant Node_Id
:=
4579 Specification
(Unit_Declaration_Node
(Scope
(E
)));
4583 if Present
(Private_Declarations
(Spec
)) then
4584 Decls
:= Private_Declarations
(Spec
);
4586 Decls
:= Visible_Declarations
(Spec
);
4589 Append_List
(Result
, Decls
);
4590 end Late_Freeze_Subprogram
;
4592 ------------------------------
4593 -- Wrap_Imported_Subprogram --
4594 ------------------------------
4596 -- The issue here is that our normal approach of checking preconditions
4597 -- and postconditions does not work for imported procedures, since we
4598 -- are not generating code for the body. To get around this we create
4599 -- a wrapper, as shown by the following example:
4601 -- procedure K (A : Integer);
4602 -- pragma Import (C, K);
4604 -- The spec is rewritten by removing the effects of pragma Import, but
4605 -- leaving the convention unchanged, as though the source had said:
4607 -- procedure K (A : Integer);
4608 -- pragma Convention (C, K);
4610 -- and we create a body, added to the entity K freeze actions, which
4613 -- procedure K (A : Integer) is
4614 -- procedure K (A : Integer);
4615 -- pragma Import (C, K);
4620 -- Now the contract applies in the normal way to the outer procedure,
4621 -- and the inner procedure has no contracts, so there is no problem
4622 -- in just calling it to get the original effect.
4624 -- In the case of a function, we create an appropriate return statement
4625 -- for the subprogram body that calls the inner procedure.
4627 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
4628 Loc
: constant Source_Ptr
:= Sloc
(E
);
4629 CE
: constant Name_Id
:= Chars
(E
);
4638 -- Nothing to do if not imported
4640 if not Is_Imported
(E
) then
4643 -- Test enabling conditions for wrapping
4645 elsif Is_Subprogram
(E
)
4646 and then Present
(Contract
(E
))
4647 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
4648 and then not GNATprove_Mode
4650 -- Here we do the wrap
4652 -- Note on calls to Copy_Separate_Tree. The trees we are copying
4653 -- here are fully analyzed, but we definitely want fully syntactic
4654 -- unanalyzed trees in the body we construct, so that the analysis
4655 -- generates the right visibility, and that is exactly what the
4656 -- calls to Copy_Separate_Tree give us.
4658 -- Acquire copy of Inline pragma, and indicate that it does not
4659 -- come from an aspect, as it applies to an internal entity.
4661 Iprag
:= Copy_Separate_Tree
(Import_Pragma
(E
));
4662 Set_From_Aspect_Specification
(Iprag
, False);
4664 -- Fix up spec to be not imported any more
4666 Set_Is_Imported
(E
, False);
4667 Set_Interface_Name
(E
, Empty
);
4668 Set_Has_Completion
(E
, False);
4669 Set_Import_Pragma
(E
, Empty
);
4671 -- Grab the subprogram declaration and specification
4673 Spec
:= Declaration_Node
(E
);
4675 -- Build parameter list that we need
4678 Forml
:= First_Formal
(E
);
4679 while Present
(Forml
) loop
4680 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
4681 Next_Formal
(Forml
);
4686 if Ekind_In
(E
, E_Function
, E_Generic_Function
) then
4688 Make_Simple_Return_Statement
(Loc
,
4690 Make_Function_Call
(Loc
,
4691 Name
=> Make_Identifier
(Loc
, CE
),
4692 Parameter_Associations
=> Parms
));
4696 Make_Procedure_Call_Statement
(Loc
,
4697 Name
=> Make_Identifier
(Loc
, CE
),
4698 Parameter_Associations
=> Parms
);
4701 -- Now build the body
4704 Make_Subprogram_Body
(Loc
,
4706 Copy_Separate_Tree
(Spec
),
4707 Declarations
=> New_List
(
4708 Make_Subprogram_Declaration
(Loc
,
4710 Copy_Separate_Tree
(Spec
)),
4712 Handled_Statement_Sequence
=>
4713 Make_Handled_Sequence_Of_Statements
(Loc
,
4714 Statements
=> New_List
(Stmt
),
4715 End_Label
=> Make_Identifier
(Loc
, CE
)));
4717 -- Append the body to freeze result
4719 Add_To_Result
(Bod
);
4722 -- Case of imported subprogram that does not get wrapped
4725 -- Set Is_Public. All imported entities need an external symbol
4726 -- created for them since they are always referenced from another
4727 -- object file. Note this used to be set when we set Is_Imported
4728 -- back in Sem_Prag, but now we delay it to this point, since we
4729 -- don't want to set this flag if we wrap an imported subprogram.
4733 end Wrap_Imported_Subprogram
;
4737 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4739 -- Start of processing for Freeze_Entity
4742 -- The entity being frozen may be subject to pragma Ghost. Set the mode
4743 -- now to ensure that any nodes generated during freezing are properly
4744 -- flagged as Ghost.
4746 Set_Ghost_Mode_From_Entity
(E
);
4748 -- We are going to test for various reasons why this entity need not be
4749 -- frozen here, but in the case of an Itype that's defined within a
4750 -- record, that test actually applies to the record.
4752 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
4753 Test_E
:= Scope
(E
);
4754 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
4755 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
4757 Test_E
:= Underlying_Type
(Scope
(E
));
4760 -- Do not freeze if already frozen since we only need one freeze node
4762 if Is_Frozen
(E
) then
4763 Ghost_Mode
:= Save_Ghost_Mode
;
4766 -- It is improper to freeze an external entity within a generic because
4767 -- its freeze node will appear in a non-valid context. The entity will
4768 -- be frozen in the proper scope after the current generic is analyzed.
4769 -- However, aspects must be analyzed because they may be queried later
4770 -- within the generic itself, and the corresponding pragma or attribute
4771 -- definition has not been analyzed yet.
4773 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
4774 if Has_Delayed_Aspects
(E
) then
4775 Analyze_Aspects_At_Freeze_Point
(E
);
4778 Ghost_Mode
:= Save_Ghost_Mode
;
4781 -- AI05-0213: A formal incomplete type does not freeze the actual. In
4782 -- the instance, the same applies to the subtype renaming the actual.
4784 elsif Is_Private_Type
(E
)
4785 and then Is_Generic_Actual_Type
(E
)
4786 and then No
(Full_View
(Base_Type
(E
)))
4787 and then Ada_Version
>= Ada_2012
4789 Ghost_Mode
:= Save_Ghost_Mode
;
4792 -- Formal subprograms are never frozen
4794 elsif Is_Formal_Subprogram
(E
) then
4795 Ghost_Mode
:= Save_Ghost_Mode
;
4798 -- Generic types are never frozen as they lack delayed semantic checks
4800 elsif Is_Generic_Type
(E
) then
4801 Ghost_Mode
:= Save_Ghost_Mode
;
4804 -- Do not freeze a global entity within an inner scope created during
4805 -- expansion. A call to subprogram E within some internal procedure
4806 -- (a stream attribute for example) might require freezing E, but the
4807 -- freeze node must appear in the same declarative part as E itself.
4808 -- The two-pass elaboration mechanism in gigi guarantees that E will
4809 -- be frozen before the inner call is elaborated. We exclude constants
4810 -- from this test, because deferred constants may be frozen early, and
4811 -- must be diagnosed (e.g. in the case of a deferred constant being used
4812 -- in a default expression). If the enclosing subprogram comes from
4813 -- source, or is a generic instance, then the freeze point is the one
4814 -- mandated by the language, and we freeze the entity. A subprogram that
4815 -- is a child unit body that acts as a spec does not have a spec that
4816 -- comes from source, but can only come from source.
4818 elsif In_Open_Scopes
(Scope
(Test_E
))
4819 and then Scope
(Test_E
) /= Current_Scope
4820 and then Ekind
(Test_E
) /= E_Constant
4827 while Present
(S
) loop
4828 if Is_Overloadable
(S
) then
4829 if Comes_From_Source
(S
)
4830 or else Is_Generic_Instance
(S
)
4831 or else Is_Child_Unit
(S
)
4835 Ghost_Mode
:= Save_Ghost_Mode
;
4844 -- Similarly, an inlined instance body may make reference to global
4845 -- entities, but these references cannot be the proper freezing point
4846 -- for them, and in the absence of inlining freezing will take place in
4847 -- their own scope. Normally instance bodies are analyzed after the
4848 -- enclosing compilation, and everything has been frozen at the proper
4849 -- place, but with front-end inlining an instance body is compiled
4850 -- before the end of the enclosing scope, and as a result out-of-order
4851 -- freezing must be prevented.
4853 elsif Front_End_Inlining
4854 and then In_Instance_Body
4855 and then Present
(Scope
(Test_E
))
4861 S
:= Scope
(Test_E
);
4862 while Present
(S
) loop
4863 if Is_Generic_Instance
(S
) then
4871 Ghost_Mode
:= Save_Ghost_Mode
;
4876 elsif Ekind
(E
) = E_Generic_Package
then
4877 Result
:= Freeze_Generic_Entities
(E
);
4879 Ghost_Mode
:= Save_Ghost_Mode
;
4883 -- Add checks to detect proper initialization of scalars that may appear
4884 -- as subprogram parameters.
4886 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
4887 Apply_Parameter_Validity_Checks
(E
);
4890 -- Deal with delayed aspect specifications. The analysis of the aspect
4891 -- is required to be delayed to the freeze point, thus we analyze the
4892 -- pragma or attribute definition clause in the tree at this point. We
4893 -- also analyze the aspect specification node at the freeze point when
4894 -- the aspect doesn't correspond to pragma/attribute definition clause.
4896 if Has_Delayed_Aspects
(E
) then
4897 Analyze_Aspects_At_Freeze_Point
(E
);
4900 -- Here to freeze the entity
4904 -- Case of entity being frozen is other than a type
4906 if not Is_Type
(E
) then
4908 -- If entity is exported or imported and does not have an external
4909 -- name, now is the time to provide the appropriate default name.
4910 -- Skip this if the entity is stubbed, since we don't need a name
4911 -- for any stubbed routine. For the case on intrinsics, if no
4912 -- external name is specified, then calls will be handled in
4913 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
4914 -- external name is provided, then Expand_Intrinsic_Call leaves
4915 -- calls in place for expansion by GIGI.
4917 if (Is_Imported
(E
) or else Is_Exported
(E
))
4918 and then No
(Interface_Name
(E
))
4919 and then Convention
(E
) /= Convention_Stubbed
4920 and then Convention
(E
) /= Convention_Intrinsic
4922 Set_Encoded_Interface_Name
4923 (E
, Get_Default_External_Name
(E
));
4925 -- If entity is an atomic object appearing in a declaration and
4926 -- the expression is an aggregate, assign it to a temporary to
4927 -- ensure that the actual assignment is done atomically rather
4928 -- than component-wise (the assignment to the temp may be done
4929 -- component-wise, but that is harmless).
4931 elsif Is_Atomic_Or_VFA
(E
)
4932 and then Nkind
(Parent
(E
)) = N_Object_Declaration
4933 and then Present
(Expression
(Parent
(E
)))
4934 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
4935 and then Is_Atomic_VFA_Aggregate
(Expression
(Parent
(E
)))
4942 if Is_Subprogram
(E
) then
4944 -- Check for needing to wrap imported subprogram
4946 Wrap_Imported_Subprogram
(E
);
4948 -- Freeze all parameter types and the return type (RM 13.14(14)).
4949 -- However skip this for internal subprograms. This is also where
4950 -- any extra formal parameters are created since we now know
4951 -- whether the subprogram will use a foreign convention.
4953 -- In Ada 2012, freezing a subprogram does not always freeze
4954 -- the corresponding profile (see AI05-019). An attribute
4955 -- reference is not a freezing point of the profile.
4956 -- Other constructs that should not freeze ???
4958 -- This processing doesn't apply to internal entities (see below)
4960 if not Is_Internal
(E
) then
4961 if not Freeze_Profile
(E
) then
4962 Ghost_Mode
:= Save_Ghost_Mode
;
4967 -- Must freeze its parent first if it is a derived subprogram
4969 if Present
(Alias
(E
)) then
4970 Freeze_And_Append
(Alias
(E
), N
, Result
);
4973 -- We don't freeze internal subprograms, because we don't normally
4974 -- want addition of extra formals or mechanism setting to happen
4975 -- for those. However we do pass through predefined dispatching
4976 -- cases, since extra formals may be needed in some cases, such as
4977 -- for the stream 'Input function (build-in-place formals).
4979 if not Is_Internal
(E
)
4980 or else Is_Predefined_Dispatching_Operation
(E
)
4982 Freeze_Subprogram
(E
);
4985 if Late_Freezing
then
4986 Late_Freeze_Subprogram
(E
);
4987 Ghost_Mode
:= Save_Ghost_Mode
;
4991 -- If warning on suspicious contracts then check for the case of
4992 -- a postcondition other than False for a No_Return subprogram.
4995 and then Warn_On_Suspicious_Contract
4996 and then Present
(Contract
(E
))
4999 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
5003 while Present
(Prag
) loop
5004 if Nam_In
(Pragma_Name
(Prag
), Name_Post
,
5010 (First
(Pragma_Argument_Associations
(Prag
)));
5012 if Nkind
(Exp
) /= N_Identifier
5013 or else Chars
(Exp
) /= Name_False
5016 ("useless postcondition, & is marked "
5017 & "No_Return?T?", Exp
, E
);
5021 Prag
:= Next_Pragma
(Prag
);
5026 -- Here for other than a subprogram or type
5029 -- If entity has a type, and it is not a generic unit, then
5030 -- freeze it first (RM 13.14(10)).
5032 if Present
(Etype
(E
))
5033 and then Ekind
(E
) /= E_Generic_Function
5035 Freeze_And_Append
(Etype
(E
), N
, Result
);
5037 -- For an object of an anonymous array type, aspects on the
5038 -- object declaration apply to the type itself. This is the
5039 -- case for Atomic_Components, Volatile_Components, and
5040 -- Independent_Components. In these cases analysis of the
5041 -- generated pragma will mark the anonymous types accordingly,
5042 -- and the object itself does not require a freeze node.
5044 if Ekind
(E
) = E_Variable
5045 and then Is_Itype
(Etype
(E
))
5046 and then Is_Array_Type
(Etype
(E
))
5047 and then Has_Delayed_Aspects
(E
)
5049 Set_Has_Delayed_Aspects
(E
, False);
5050 Set_Has_Delayed_Freeze
(E
, False);
5051 Set_Freeze_Node
(E
, Empty
);
5055 -- Special processing for objects created by object declaration
5057 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
5058 Freeze_Object_Declaration
(E
);
5061 -- Check that a constant which has a pragma Volatile[_Components]
5062 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
5064 -- Note: Atomic[_Components] also sets Volatile[_Components]
5066 if Ekind
(E
) = E_Constant
5067 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
5068 and then not Is_Imported
(E
)
5069 and then not Has_Boolean_Aspect_Import
(E
)
5071 -- Make sure we actually have a pragma, and have not merely
5072 -- inherited the indication from elsewhere (e.g. an address
5073 -- clause, which is not good enough in RM terms).
5075 if Has_Rep_Pragma
(E
, Name_Atomic
)
5077 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
5080 ("stand alone atomic constant must be " &
5081 "imported (RM C.6(13))", E
);
5083 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
5085 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
5088 ("stand alone volatile constant must be " &
5089 "imported (RM C.6(13))", E
);
5093 -- Static objects require special handling
5095 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
5096 and then Is_Statically_Allocated
(E
)
5098 Freeze_Static_Object
(E
);
5101 -- Remaining step is to layout objects
5103 if Ekind_In
(E
, E_Variable
, E_Constant
, E_Loop_Parameter
)
5104 or else Is_Formal
(E
)
5109 -- For an object that does not have delayed freezing, and whose
5110 -- initialization actions have been captured in a compound
5111 -- statement, move them back now directly within the enclosing
5112 -- statement sequence.
5114 if Ekind_In
(E
, E_Constant
, E_Variable
)
5115 and then not Has_Delayed_Freeze
(E
)
5117 Explode_Initialization_Compound_Statement
(E
);
5121 -- Case of a type or subtype being frozen
5124 -- We used to check here that a full type must have preelaborable
5125 -- initialization if it completes a private type specified with
5126 -- pragma Preelaborable_Initialization, but that missed cases where
5127 -- the types occur within a generic package, since the freezing
5128 -- that occurs within a containing scope generally skips traversal
5129 -- of a generic unit's declarations (those will be frozen within
5130 -- instances). This check was moved to Analyze_Package_Specification.
5132 -- The type may be defined in a generic unit. This can occur when
5133 -- freezing a generic function that returns the type (which is
5134 -- defined in a parent unit). It is clearly meaningless to freeze
5135 -- this type. However, if it is a subtype, its size may be determi-
5136 -- nable and used in subsequent checks, so might as well try to
5139 -- In Ada 2012, Freeze_Entities is also used in the front end to
5140 -- trigger the analysis of aspect expressions, so in this case we
5141 -- want to continue the freezing process.
5143 if Present
(Scope
(E
))
5144 and then Is_Generic_Unit
(Scope
(E
))
5146 (not Has_Predicates
(E
)
5147 and then not Has_Delayed_Freeze
(E
))
5149 Check_Compile_Time_Size
(E
);
5150 Ghost_Mode
:= Save_Ghost_Mode
;
5154 -- Check for error of Type_Invariant'Class applied to an untagged
5155 -- type (check delayed to freeze time when full type is available).
5158 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
5161 and then Class_Present
(Prag
)
5162 and then not Is_Tagged_Type
(E
)
5165 ("Type_Invariant''Class cannot be specified for &",
5168 ("\can only be specified for a tagged type", Prag
);
5172 if Is_Ghost_Entity
(E
) then
5174 -- A Ghost type cannot be concurrent (SPARK RM 6.9(19)). Verify
5175 -- this legality rule first to five a finer-grained diagnostic.
5177 if Is_Concurrent_Type
(E
) then
5178 Error_Msg_N
("ghost type & cannot be concurrent", E
);
5180 -- A Ghost type cannot be effectively volatile (SPARK RM 6.9(8))
5182 elsif Is_Effectively_Volatile
(E
) then
5183 Error_Msg_N
("ghost type & cannot be volatile", E
);
5187 -- Deal with special cases of freezing for subtype
5189 if E
/= Base_Type
(E
) then
5191 -- Before we do anything else, a specialized test for the case of
5192 -- a size given for an array where the array needs to be packed,
5193 -- but was not so the size cannot be honored. This is the case
5194 -- where implicit packing may apply. The reason we do this so
5195 -- early is that if we have implicit packing, the layout of the
5196 -- base type is affected, so we must do this before we freeze
5199 -- We could do this processing only if implicit packing is enabled
5200 -- since in all other cases, the error would be caught by the back
5201 -- end. However, we choose to do the check even if we do not have
5202 -- implicit packing enabled, since this allows us to give a more
5203 -- useful error message (advising use of pragmas Implicit_Packing
5206 if Is_Array_Type
(E
) then
5208 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
5209 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
5210 SZ
: constant Node_Id
:= Size_Clause
(E
);
5211 Btyp
: constant Entity_Id
:= Base_Type
(E
);
5218 -- Number of elements in array
5221 -- Check enabling conditions. These are straightforward
5222 -- except for the test for a limited composite type. This
5223 -- eliminates the rare case of a array of limited components
5224 -- where there are issues of whether or not we can go ahead
5225 -- and pack the array (since we can't freely pack and unpack
5226 -- arrays if they are limited).
5228 -- Note that we check the root type explicitly because the
5229 -- whole point is we are doing this test before we have had
5230 -- a chance to freeze the base type (and it is that freeze
5231 -- action that causes stuff to be inherited).
5233 if Has_Size_Clause
(E
)
5234 and then Known_Static_RM_Size
(E
)
5235 and then not Is_Packed
(E
)
5236 and then not Has_Pragma_Pack
(E
)
5237 and then not Has_Component_Size_Clause
(E
)
5238 and then Known_Static_RM_Size
(Ctyp
)
5239 and then RM_Size
(Ctyp
) < 64
5240 and then not Is_Limited_Composite
(E
)
5241 and then not Is_Packed
(Root_Type
(E
))
5242 and then not Has_Component_Size_Clause
(Root_Type
(E
))
5243 and then not (CodePeer_Mode
or GNATprove_Mode
)
5245 -- Compute number of elements in array
5247 Num_Elmts
:= Uint_1
;
5248 Indx
:= First_Index
(E
);
5249 while Present
(Indx
) loop
5250 Get_Index_Bounds
(Indx
, Lo
, Hi
);
5252 if not (Compile_Time_Known_Value
(Lo
)
5254 Compile_Time_Known_Value
(Hi
))
5256 goto No_Implicit_Packing
;
5262 Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1);
5266 -- What we are looking for here is the situation where
5267 -- the RM_Size given would be exactly right if there was
5268 -- a pragma Pack (resulting in the component size being
5269 -- the same as the RM_Size). Furthermore, the component
5270 -- type size must be an odd size (not a multiple of
5271 -- storage unit). If the component RM size is an exact
5272 -- number of storage units that is a power of two, the
5273 -- array is not packed and has a standard representation.
5275 if RM_Size
(E
) = Num_Elmts
* Rsiz
5276 and then Rsiz
mod System_Storage_Unit
/= 0
5278 -- For implicit packing mode, just set the component
5281 if Implicit_Packing
then
5282 Set_Component_Size
(Btyp
, Rsiz
);
5283 Set_Is_Bit_Packed_Array
(Btyp
);
5284 Set_Is_Packed
(Btyp
);
5285 Set_Has_Non_Standard_Rep
(Btyp
);
5287 -- Otherwise give an error message
5291 ("size given for& too small", SZ
, E
);
5292 Error_Msg_N
-- CODEFIX
5293 ("\use explicit pragma Pack "
5294 & "or use pragma Implicit_Packing", SZ
);
5297 elsif RM_Size
(E
) = Num_Elmts
* Rsiz
5298 and then Implicit_Packing
5300 (Rsiz
/ System_Storage_Unit
= 1
5302 Rsiz
/ System_Storage_Unit
= 2
5304 Rsiz
/ System_Storage_Unit
= 4)
5306 -- Not a packed array, but indicate the desired
5307 -- component size, for the back-end.
5309 Set_Component_Size
(Btyp
, Rsiz
);
5315 <<No_Implicit_Packing
>>
5317 -- If ancestor subtype present, freeze that first. Note that this
5318 -- will also get the base type frozen. Need RM reference ???
5320 Atype
:= Ancestor_Subtype
(E
);
5322 if Present
(Atype
) then
5323 Freeze_And_Append
(Atype
, N
, Result
);
5325 -- No ancestor subtype present
5328 -- See if we have a nearest ancestor that has a predicate.
5329 -- That catches the case of derived type with a predicate.
5330 -- Need RM reference here ???
5332 Atype
:= Nearest_Ancestor
(E
);
5334 if Present
(Atype
) and then Has_Predicates
(Atype
) then
5335 Freeze_And_Append
(Atype
, N
, Result
);
5338 -- Freeze base type before freezing the entity (RM 13.14(15))
5340 if E
/= Base_Type
(E
) then
5341 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
5345 -- A subtype inherits all the type-related representation aspects
5346 -- from its parents (RM 13.1(8)).
5348 Inherit_Aspects_At_Freeze_Point
(E
);
5350 -- For a derived type, freeze its parent type first (RM 13.14(15))
5352 elsif Is_Derived_Type
(E
) then
5353 Freeze_And_Append
(Etype
(E
), N
, Result
);
5354 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
5356 -- A derived type inherits each type-related representation aspect
5357 -- of its parent type that was directly specified before the
5358 -- declaration of the derived type (RM 13.1(15)).
5360 Inherit_Aspects_At_Freeze_Point
(E
);
5363 -- Check for incompatible size and alignment for record type
5365 if Warn_On_Size_Alignment
5366 and then Is_Record_Type
(E
)
5367 and then Has_Size_Clause
(E
) and then Has_Alignment_Clause
(E
)
5369 -- If explicit Object_Size clause given assume that the programmer
5370 -- knows what he is doing, and expects the compiler behavior.
5372 and then not Has_Object_Size_Clause
(E
)
5374 -- Check for size not a multiple of alignment
5376 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
5379 SC
: constant Node_Id
:= Size_Clause
(E
);
5380 AC
: constant Node_Id
:= Alignment_Clause
(E
);
5382 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
5385 if Present
(SC
) and then Present
(AC
) then
5389 if Sloc
(SC
) > Sloc
(AC
) then
5392 ("?Z?size is not a multiple of alignment for &",
5394 Error_Msg_Sloc
:= Sloc
(AC
);
5395 Error_Msg_Uint_1
:= Alignment
(E
);
5396 Error_Msg_N
("\?Z?alignment of ^ specified #", Loc
);
5401 ("?Z?size is not a multiple of alignment for &",
5403 Error_Msg_Sloc
:= Sloc
(SC
);
5404 Error_Msg_Uint_1
:= RM_Size
(E
);
5405 Error_Msg_N
("\?Z?size of ^ specified #", Loc
);
5408 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
5409 Error_Msg_N
("\?Z?Object_Size will be increased to ^", Loc
);
5416 if Is_Array_Type
(E
) then
5417 Freeze_Array_Type
(E
);
5419 -- For a class-wide type, the corresponding specific type is
5420 -- frozen as well (RM 13.14(15))
5422 elsif Is_Class_Wide_Type
(E
) then
5423 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
5425 -- If the base type of the class-wide type is still incomplete,
5426 -- the class-wide remains unfrozen as well. This is legal when
5427 -- E is the formal of a primitive operation of some other type
5428 -- which is being frozen.
5430 if not Is_Frozen
(Root_Type
(E
)) then
5431 Set_Is_Frozen
(E
, False);
5432 Ghost_Mode
:= Save_Ghost_Mode
;
5436 -- The equivalent type associated with a class-wide subtype needs
5437 -- to be frozen to ensure that its layout is done.
5439 if Ekind
(E
) = E_Class_Wide_Subtype
5440 and then Present
(Equivalent_Type
(E
))
5442 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5445 -- Generate an itype reference for a library-level class-wide type
5446 -- at the freeze point. Otherwise the first explicit reference to
5447 -- the type may appear in an inner scope which will be rejected by
5451 and then Is_Compilation_Unit
(Scope
(E
))
5454 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
5459 -- From a gigi point of view, a class-wide subtype derives
5460 -- from its record equivalent type. As a result, the itype
5461 -- reference must appear after the freeze node of the
5462 -- equivalent type or gigi will reject the reference.
5464 if Ekind
(E
) = E_Class_Wide_Subtype
5465 and then Present
(Equivalent_Type
(E
))
5467 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
5469 Add_To_Result
(Ref
);
5474 -- For a record type or record subtype, freeze all component types
5475 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
5476 -- using Is_Record_Type, because we don't want to attempt the freeze
5477 -- for the case of a private type with record extension (we will do
5478 -- that later when the full type is frozen).
5480 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
)
5481 and then not (Present
(Scope
(E
))
5482 and then Is_Generic_Unit
(Scope
(E
)))
5484 Freeze_Record_Type
(E
);
5486 -- For a concurrent type, freeze corresponding record type. This does
5487 -- not correspond to any specific rule in the RM, but the record type
5488 -- is essentially part of the concurrent type. Also freeze all local
5489 -- entities. This includes record types created for entry parameter
5490 -- blocks and whatever local entities may appear in the private part.
5492 elsif Is_Concurrent_Type
(E
) then
5493 if Present
(Corresponding_Record_Type
(E
)) then
5494 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
5497 Comp
:= First_Entity
(E
);
5498 while Present
(Comp
) loop
5499 if Is_Type
(Comp
) then
5500 Freeze_And_Append
(Comp
, N
, Result
);
5502 elsif (Ekind
(Comp
)) /= E_Function
then
5504 -- The guard on the presence of the Etype seems to be needed
5505 -- for some CodePeer (-gnatcC) cases, but not clear why???
5507 if Present
(Etype
(Comp
)) then
5508 if Is_Itype
(Etype
(Comp
))
5509 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
5511 Undelay_Type
(Etype
(Comp
));
5514 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5521 -- Private types are required to point to the same freeze node as
5522 -- their corresponding full views. The freeze node itself has to
5523 -- point to the partial view of the entity (because from the partial
5524 -- view, we can retrieve the full view, but not the reverse).
5525 -- However, in order to freeze correctly, we need to freeze the full
5526 -- view. If we are freezing at the end of a scope (or within the
5527 -- scope) of the private type, the partial and full views will have
5528 -- been swapped, the full view appears first in the entity chain and
5529 -- the swapping mechanism ensures that the pointers are properly set
5532 -- If we encounter the partial view before the full view (e.g. when
5533 -- freezing from another scope), we freeze the full view, and then
5534 -- set the pointers appropriately since we cannot rely on swapping to
5535 -- fix things up (subtypes in an outer scope might not get swapped).
5537 -- If the full view is itself private, the above requirements apply
5538 -- to the underlying full view instead of the full view. But there is
5539 -- no swapping mechanism for the underlying full view so we need to
5540 -- set the pointers appropriately in both cases.
5542 elsif Is_Incomplete_Or_Private_Type
(E
)
5543 and then not Is_Generic_Type
(E
)
5545 -- The construction of the dispatch table associated with library
5546 -- level tagged types forces freezing of all the primitives of the
5547 -- type, which may cause premature freezing of the partial view.
5551 -- type T is tagged private;
5552 -- type DT is new T with private;
5553 -- procedure Prim (X : in out T; Y : in out DT'Class);
5555 -- type T is tagged null record;
5557 -- type DT is new T with null record;
5560 -- In this case the type will be frozen later by the usual
5561 -- mechanism: an object declaration, an instantiation, or the
5562 -- end of a declarative part.
5564 if Is_Library_Level_Tagged_Type
(E
)
5565 and then not Present
(Full_View
(E
))
5567 Set_Is_Frozen
(E
, False);
5568 Ghost_Mode
:= Save_Ghost_Mode
;
5571 -- Case of full view present
5573 elsif Present
(Full_View
(E
)) then
5575 -- If full view has already been frozen, then no further
5576 -- processing is required
5578 if Is_Frozen
(Full_View
(E
)) then
5579 Set_Has_Delayed_Freeze
(E
, False);
5580 Set_Freeze_Node
(E
, Empty
);
5582 -- Otherwise freeze full view and patch the pointers so that
5583 -- the freeze node will elaborate both views in the back end.
5584 -- However, if full view is itself private, freeze underlying
5585 -- full view instead and patch the pointers so that the freeze
5586 -- node will elaborate the three views in the back end.
5590 Full
: Entity_Id
:= Full_View
(E
);
5593 if Is_Private_Type
(Full
)
5594 and then Present
(Underlying_Full_View
(Full
))
5596 Full
:= Underlying_Full_View
(Full
);
5599 Freeze_And_Append
(Full
, N
, Result
);
5601 if Full
/= Full_View
(E
)
5602 and then Has_Delayed_Freeze
(Full_View
(E
))
5604 F_Node
:= Freeze_Node
(Full
);
5606 if Present
(F_Node
) then
5607 Set_Freeze_Node
(Full_View
(E
), F_Node
);
5608 Set_Entity
(F_Node
, Full_View
(E
));
5611 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
5612 Set_Freeze_Node
(Full_View
(E
), Empty
);
5616 if Has_Delayed_Freeze
(E
) then
5617 F_Node
:= Freeze_Node
(Full_View
(E
));
5619 if Present
(F_Node
) then
5620 Set_Freeze_Node
(E
, F_Node
);
5621 Set_Entity
(F_Node
, E
);
5624 -- {Incomplete,Private}_Subtypes with Full_Views
5625 -- constrained by discriminants.
5627 Set_Has_Delayed_Freeze
(E
, False);
5628 Set_Freeze_Node
(E
, Empty
);
5634 Check_Debug_Info_Needed
(E
);
5636 -- AI-117 requires that the convention of a partial view be the
5637 -- same as the convention of the full view. Note that this is a
5638 -- recognized breach of privacy, but it's essential for logical
5639 -- consistency of representation, and the lack of a rule in
5640 -- RM95 was an oversight.
5642 Set_Convention
(E
, Convention
(Full_View
(E
)));
5644 Set_Size_Known_At_Compile_Time
(E
,
5645 Size_Known_At_Compile_Time
(Full_View
(E
)));
5647 -- Size information is copied from the full view to the
5648 -- incomplete or private view for consistency.
5650 -- We skip this is the full view is not a type. This is very
5651 -- strange of course, and can only happen as a result of
5652 -- certain illegalities, such as a premature attempt to derive
5653 -- from an incomplete type.
5655 if Is_Type
(Full_View
(E
)) then
5656 Set_Size_Info
(E
, Full_View
(E
));
5657 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
5660 Ghost_Mode
:= Save_Ghost_Mode
;
5663 -- Case of underlying full view present
5665 elsif Is_Private_Type
(E
)
5666 and then Present
(Underlying_Full_View
(E
))
5668 if not Is_Frozen
(Underlying_Full_View
(E
)) then
5669 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
5672 -- Patch the pointers so that the freeze node will elaborate
5673 -- both views in the back end.
5675 if Has_Delayed_Freeze
(E
) then
5676 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
5678 if Present
(F_Node
) then
5679 Set_Freeze_Node
(E
, F_Node
);
5680 Set_Entity
(F_Node
, E
);
5683 Set_Has_Delayed_Freeze
(E
, False);
5684 Set_Freeze_Node
(E
, Empty
);
5688 Check_Debug_Info_Needed
(E
);
5690 Ghost_Mode
:= Save_Ghost_Mode
;
5693 -- Case of no full view present. If entity is derived or subtype,
5694 -- it is safe to freeze, correctness depends on the frozen status
5695 -- of parent. Otherwise it is either premature usage, or a Taft
5696 -- amendment type, so diagnosis is at the point of use and the
5697 -- type might be frozen later.
5699 elsif E
/= Base_Type
(E
) or else Is_Derived_Type
(E
) then
5703 Set_Is_Frozen
(E
, False);
5704 Ghost_Mode
:= Save_Ghost_Mode
;
5708 -- For access subprogram, freeze types of all formals, the return
5709 -- type was already frozen, since it is the Etype of the function.
5710 -- Formal types can be tagged Taft amendment types, but otherwise
5711 -- they cannot be incomplete.
5713 elsif Ekind
(E
) = E_Subprogram_Type
then
5714 Formal
:= First_Formal
(E
);
5715 while Present
(Formal
) loop
5716 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
5717 and then No
(Full_View
(Etype
(Formal
)))
5719 if Is_Tagged_Type
(Etype
(Formal
)) then
5722 -- AI05-151: Incomplete types are allowed in access to
5723 -- subprogram specifications.
5725 elsif Ada_Version
< Ada_2012
then
5727 ("invalid use of incomplete type&", E
, Etype
(Formal
));
5731 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
5732 Next_Formal
(Formal
);
5735 Freeze_Subprogram
(E
);
5737 -- For access to a protected subprogram, freeze the equivalent type
5738 -- (however this is not set if we are not generating code or if this
5739 -- is an anonymous type used just for resolution).
5741 elsif Is_Access_Protected_Subprogram_Type
(E
) then
5742 if Present
(Equivalent_Type
(E
)) then
5743 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5747 -- Generic types are never seen by the back-end, and are also not
5748 -- processed by the expander (since the expander is turned off for
5749 -- generic processing), so we never need freeze nodes for them.
5751 if Is_Generic_Type
(E
) then
5752 Ghost_Mode
:= Save_Ghost_Mode
;
5756 -- Some special processing for non-generic types to complete
5757 -- representation details not known till the freeze point.
5759 if Is_Fixed_Point_Type
(E
) then
5760 Freeze_Fixed_Point_Type
(E
);
5762 -- Some error checks required for ordinary fixed-point type. Defer
5763 -- these till the freeze-point since we need the small and range
5764 -- values. We only do these checks for base types
5766 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
5767 if Small_Value
(E
) < Ureal_2_M_80
then
5768 Error_Msg_Name_1
:= Name_Small
;
5770 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
5772 elsif Small_Value
(E
) > Ureal_2_80
then
5773 Error_Msg_Name_1
:= Name_Small
;
5775 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
5778 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
5779 Error_Msg_Name_1
:= Name_First
;
5781 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
5784 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
5785 Error_Msg_Name_1
:= Name_Last
;
5787 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
5791 elsif Is_Enumeration_Type
(E
) then
5792 Freeze_Enumeration_Type
(E
);
5794 elsif Is_Integer_Type
(E
) then
5795 Adjust_Esize_For_Alignment
(E
);
5797 if Is_Modular_Integer_Type
(E
)
5798 and then Warn_On_Suspicious_Modulus_Value
5800 Check_Suspicious_Modulus
(E
);
5803 -- The pool applies to named and anonymous access types, but not
5804 -- to subprogram and to internal types generated for 'Access
5807 elsif Is_Access_Type
(E
)
5808 and then not Is_Access_Subprogram_Type
(E
)
5809 and then Ekind
(E
) /= E_Access_Attribute_Type
5811 -- If a pragma Default_Storage_Pool applies, and this type has no
5812 -- Storage_Pool or Storage_Size clause (which must have occurred
5813 -- before the freezing point), then use the default. This applies
5814 -- only to base types.
5816 -- None of this applies to access to subprograms, for which there
5817 -- are clearly no pools.
5819 if Present
(Default_Pool
)
5820 and then Is_Base_Type
(E
)
5821 and then not Has_Storage_Size_Clause
(E
)
5822 and then No
(Associated_Storage_Pool
(E
))
5824 -- Case of pragma Default_Storage_Pool (null)
5826 if Nkind
(Default_Pool
) = N_Null
then
5827 Set_No_Pool_Assigned
(E
);
5829 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
5832 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
5836 -- Check restriction for standard storage pool
5838 if No
(Associated_Storage_Pool
(E
)) then
5839 Check_Restriction
(No_Standard_Storage_Pools
, E
);
5842 -- Deal with error message for pure access type. This is not an
5843 -- error in Ada 2005 if there is no pool (see AI-366).
5845 if Is_Pure_Unit_Access_Type
(E
)
5846 and then (Ada_Version
< Ada_2005
5847 or else not No_Pool_Assigned
(E
))
5848 and then not Is_Generic_Unit
(Scope
(E
))
5850 Error_Msg_N
("named access type not allowed in pure unit", E
);
5852 if Ada_Version
>= Ada_2005
then
5854 ("\would be legal if Storage_Size of 0 given??", E
);
5856 elsif No_Pool_Assigned
(E
) then
5858 ("\would be legal in Ada 2005??", E
);
5862 ("\would be legal in Ada 2005 if "
5863 & "Storage_Size of 0 given??", E
);
5868 -- Case of composite types
5870 if Is_Composite_Type
(E
) then
5872 -- AI-117 requires that all new primitives of a tagged type must
5873 -- inherit the convention of the full view of the type. Inherited
5874 -- and overriding operations are defined to inherit the convention
5875 -- of their parent or overridden subprogram (also specified in
5876 -- AI-117), which will have occurred earlier (in Derive_Subprogram
5877 -- and New_Overloaded_Entity). Here we set the convention of
5878 -- primitives that are still convention Ada, which will ensure
5879 -- that any new primitives inherit the type's convention. Class-
5880 -- wide types can have a foreign convention inherited from their
5881 -- specific type, but are excluded from this since they don't have
5882 -- any associated primitives.
5884 if Is_Tagged_Type
(E
)
5885 and then not Is_Class_Wide_Type
(E
)
5886 and then Convention
(E
) /= Convention_Ada
5889 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
5893 Prim
:= First_Elmt
(Prim_List
);
5894 while Present
(Prim
) loop
5895 if Convention
(Node
(Prim
)) = Convention_Ada
then
5896 Set_Convention
(Node
(Prim
), Convention
(E
));
5904 -- If the type is a simple storage pool type, then this is where
5905 -- we attempt to locate and validate its Allocate, Deallocate, and
5906 -- Storage_Size operations (the first is required, and the latter
5907 -- two are optional). We also verify that the full type for a
5908 -- private type is allowed to be a simple storage pool type.
5910 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
5911 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
5913 -- If the type is marked Has_Private_Declaration, then this is
5914 -- a full type for a private type that was specified with the
5915 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
5916 -- pragma is allowed for the full type (for example, it can't
5917 -- be an array type, or a nonlimited record type).
5919 if Has_Private_Declaration
(E
) then
5920 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
5921 and then not Is_Private_Type
(E
)
5923 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
5925 ("pragma% can only apply to full type that is an " &
5926 "explicitly limited type", E
);
5930 Validate_Simple_Pool_Ops
: declare
5931 Pool_Type
: Entity_Id
renames E
;
5932 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
5933 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
5935 procedure Validate_Simple_Pool_Op_Formal
5936 (Pool_Op
: Entity_Id
;
5937 Pool_Op_Formal
: in out Entity_Id
;
5938 Expected_Mode
: Formal_Kind
;
5939 Expected_Type
: Entity_Id
;
5940 Formal_Name
: String;
5941 OK_Formal
: in out Boolean);
5942 -- Validate one formal Pool_Op_Formal of the candidate pool
5943 -- operation Pool_Op. The formal must be of Expected_Type
5944 -- and have mode Expected_Mode. OK_Formal will be set to
5945 -- False if the formal doesn't match. If OK_Formal is False
5946 -- on entry, then the formal will effectively be ignored
5947 -- (because validation of the pool op has already failed).
5948 -- Upon return, Pool_Op_Formal will be updated to the next
5951 procedure Validate_Simple_Pool_Operation
5952 (Op_Name
: Name_Id
);
5953 -- Search for and validate a simple pool operation with the
5954 -- name Op_Name. If the name is Allocate, then there must be
5955 -- exactly one such primitive operation for the simple pool
5956 -- type. If the name is Deallocate or Storage_Size, then
5957 -- there can be at most one such primitive operation. The
5958 -- profile of the located primitive must conform to what
5959 -- is expected for each operation.
5961 ------------------------------------
5962 -- Validate_Simple_Pool_Op_Formal --
5963 ------------------------------------
5965 procedure Validate_Simple_Pool_Op_Formal
5966 (Pool_Op
: Entity_Id
;
5967 Pool_Op_Formal
: in out Entity_Id
;
5968 Expected_Mode
: Formal_Kind
;
5969 Expected_Type
: Entity_Id
;
5970 Formal_Name
: String;
5971 OK_Formal
: in out Boolean)
5974 -- If OK_Formal is False on entry, then simply ignore
5975 -- the formal, because an earlier formal has already
5978 if not OK_Formal
then
5981 -- If no formal is passed in, then issue an error for a
5984 elsif not Present
(Pool_Op_Formal
) then
5986 ("simple storage pool op missing formal " &
5987 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
5993 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
5995 -- If the pool type was expected for this formal, then
5996 -- this will not be considered a candidate operation
5997 -- for the simple pool, so we unset OK_Formal so that
5998 -- the op and any later formals will be ignored.
6000 if Expected_Type
= Pool_Type
then
6007 ("wrong type for formal " & Formal_Name
&
6008 " of simple storage pool op; expected type&",
6009 Pool_Op_Formal
, Expected_Type
);
6013 -- Issue error if formal's mode is not the expected one
6015 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
6017 ("wrong mode for formal of simple storage pool op",
6021 -- Advance to the next formal
6023 Next_Formal
(Pool_Op_Formal
);
6024 end Validate_Simple_Pool_Op_Formal
;
6026 ------------------------------------
6027 -- Validate_Simple_Pool_Operation --
6028 ------------------------------------
6030 procedure Validate_Simple_Pool_Operation
6034 Found_Op
: Entity_Id
:= Empty
;
6040 (Nam_In
(Op_Name
, Name_Allocate
,
6042 Name_Storage_Size
));
6044 Error_Msg_Name_1
:= Op_Name
;
6046 -- For each homonym declared immediately in the scope
6047 -- of the simple storage pool type, determine whether
6048 -- the homonym is an operation of the pool type, and,
6049 -- if so, check that its profile is as expected for
6050 -- a simple pool operation of that name.
6052 Op
:= Get_Name_Entity_Id
(Op_Name
);
6053 while Present
(Op
) loop
6054 if Ekind_In
(Op
, E_Function
, E_Procedure
)
6055 and then Scope
(Op
) = Current_Scope
6057 Formal
:= First_Entity
(Op
);
6061 -- The first parameter must be of the pool type
6062 -- in order for the operation to qualify.
6064 if Op_Name
= Name_Storage_Size
then
6065 Validate_Simple_Pool_Op_Formal
6066 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
6069 Validate_Simple_Pool_Op_Formal
6070 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
6074 -- If another operation with this name has already
6075 -- been located for the type, then flag an error,
6076 -- since we only allow the type to have a single
6079 if Present
(Found_Op
) and then Is_OK
then
6081 ("only one % operation allowed for " &
6082 "simple storage pool type&", Op
, Pool_Type
);
6085 -- In the case of Allocate and Deallocate, a formal
6086 -- of type System.Address is required.
6088 if Op_Name
= Name_Allocate
then
6089 Validate_Simple_Pool_Op_Formal
6090 (Op
, Formal
, E_Out_Parameter
,
6091 Address_Type
, "Storage_Address", Is_OK
);
6093 elsif Op_Name
= Name_Deallocate
then
6094 Validate_Simple_Pool_Op_Formal
6095 (Op
, Formal
, E_In_Parameter
,
6096 Address_Type
, "Storage_Address", Is_OK
);
6099 -- In the case of Allocate and Deallocate, formals
6100 -- of type Storage_Count are required as the third
6101 -- and fourth parameters.
6103 if Op_Name
/= Name_Storage_Size
then
6104 Validate_Simple_Pool_Op_Formal
6105 (Op
, Formal
, E_In_Parameter
,
6106 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
6107 Validate_Simple_Pool_Op_Formal
6108 (Op
, Formal
, E_In_Parameter
,
6109 Stg_Cnt_Type
, "Alignment", Is_OK
);
6112 -- If no mismatched formals have been found (Is_OK)
6113 -- and no excess formals are present, then this
6114 -- operation has been validated, so record it.
6116 if not Present
(Formal
) and then Is_OK
then
6124 -- There must be a valid Allocate operation for the type,
6125 -- so issue an error if none was found.
6127 if Op_Name
= Name_Allocate
6128 and then not Present
(Found_Op
)
6130 Error_Msg_N
("missing % operation for simple " &
6131 "storage pool type", Pool_Type
);
6133 elsif Present
(Found_Op
) then
6135 -- Simple pool operations can't be abstract
6137 if Is_Abstract_Subprogram
(Found_Op
) then
6139 ("simple storage pool operation must not be " &
6140 "abstract", Found_Op
);
6143 -- The Storage_Size operation must be a function with
6144 -- Storage_Count as its result type.
6146 if Op_Name
= Name_Storage_Size
then
6147 if Ekind
(Found_Op
) = E_Procedure
then
6149 ("% operation must be a function", Found_Op
);
6151 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
6153 ("wrong result type for%, expected type&",
6154 Found_Op
, Stg_Cnt_Type
);
6157 -- Allocate and Deallocate must be procedures
6159 elsif Ekind
(Found_Op
) = E_Function
then
6161 ("% operation must be a procedure", Found_Op
);
6164 end Validate_Simple_Pool_Operation
;
6166 -- Start of processing for Validate_Simple_Pool_Ops
6169 Validate_Simple_Pool_Operation
(Name_Allocate
);
6170 Validate_Simple_Pool_Operation
(Name_Deallocate
);
6171 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
6172 end Validate_Simple_Pool_Ops
;
6176 -- Now that all types from which E may depend are frozen, see if the
6177 -- size is known at compile time, if it must be unsigned, or if
6178 -- strict alignment is required
6180 Check_Compile_Time_Size
(E
);
6181 Check_Unsigned_Type
(E
);
6183 if Base_Type
(E
) = E
then
6184 Check_Strict_Alignment
(E
);
6187 -- Do not allow a size clause for a type which does not have a size
6188 -- that is known at compile time
6190 if Has_Size_Clause
(E
)
6191 and then not Size_Known_At_Compile_Time
(E
)
6193 -- Suppress this message if errors posted on E, even if we are
6194 -- in all errors mode, since this is often a junk message
6196 if not Error_Posted
(E
) then
6198 ("size clause not allowed for variable length type",
6203 -- Now we set/verify the representation information, in particular
6204 -- the size and alignment values. This processing is not required for
6205 -- generic types, since generic types do not play any part in code
6206 -- generation, and so the size and alignment values for such types
6207 -- are irrelevant. Ditto for types declared within a generic unit,
6208 -- which may have components that depend on generic parameters, and
6209 -- that will be recreated in an instance.
6211 if Inside_A_Generic
then
6214 -- Otherwise we call the layout procedure
6220 -- If this is an access to subprogram whose designated type is itself
6221 -- a subprogram type, the return type of this anonymous subprogram
6222 -- type must be decorated as well.
6224 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
6225 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
6227 Layout_Type
(Etype
(Designated_Type
(E
)));
6230 -- If the type has a Defaut_Value/Default_Component_Value aspect,
6231 -- this is where we analye the expression (after the type is frozen,
6232 -- since in the case of Default_Value, we are analyzing with the
6233 -- type itself, and we treat Default_Component_Value similarly for
6234 -- the sake of uniformity).
6236 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
6243 if Is_Scalar_Type
(E
) then
6244 Nam
:= Name_Default_Value
;
6246 Exp
:= Default_Aspect_Value
(Typ
);
6248 Nam
:= Name_Default_Component_Value
;
6249 Typ
:= Component_Type
(E
);
6250 Exp
:= Default_Aspect_Component_Value
(E
);
6253 Analyze_And_Resolve
(Exp
, Typ
);
6255 if Etype
(Exp
) /= Any_Type
then
6256 if not Is_OK_Static_Expression
(Exp
) then
6257 Error_Msg_Name_1
:= Nam
;
6258 Flag_Non_Static_Expr
6259 ("aspect% requires static expression", Exp
);
6265 -- End of freeze processing for type entities
6268 -- Here is where we logically freeze the current entity. If it has a
6269 -- freeze node, then this is the point at which the freeze node is
6270 -- linked into the result list.
6272 if Has_Delayed_Freeze
(E
) then
6274 -- If a freeze node is already allocated, use it, otherwise allocate
6275 -- a new one. The preallocation happens in the case of anonymous base
6276 -- types, where we preallocate so that we can set First_Subtype_Link.
6277 -- Note that we reset the Sloc to the current freeze location.
6279 if Present
(Freeze_Node
(E
)) then
6280 F_Node
:= Freeze_Node
(E
);
6281 Set_Sloc
(F_Node
, Loc
);
6284 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
6285 Set_Freeze_Node
(E
, F_Node
);
6286 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
6287 Set_TSS_Elist
(F_Node
, No_Elist
);
6288 Set_Actions
(F_Node
, No_List
);
6291 Set_Entity
(F_Node
, E
);
6292 Add_To_Result
(F_Node
);
6294 -- A final pass over record types with discriminants. If the type
6295 -- has an incomplete declaration, there may be constrained access
6296 -- subtypes declared elsewhere, which do not depend on the discrimi-
6297 -- nants of the type, and which are used as component types (i.e.
6298 -- the full view is a recursive type). The designated types of these
6299 -- subtypes can only be elaborated after the type itself, and they
6300 -- need an itype reference.
6302 if Ekind
(E
) = E_Record_Type
6303 and then Has_Discriminants
(E
)
6311 Comp
:= First_Component
(E
);
6312 while Present
(Comp
) loop
6313 Typ
:= Etype
(Comp
);
6315 if Ekind
(Comp
) = E_Component
6316 and then Is_Access_Type
(Typ
)
6317 and then Scope
(Typ
) /= E
6318 and then Base_Type
(Designated_Type
(Typ
)) = E
6319 and then Is_Itype
(Designated_Type
(Typ
))
6321 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
6322 Set_Itype
(IR
, Designated_Type
(Typ
));
6323 Append
(IR
, Result
);
6326 Next_Component
(Comp
);
6332 -- When a type is frozen, the first subtype of the type is frozen as
6333 -- well (RM 13.14(15)). This has to be done after freezing the type,
6334 -- since obviously the first subtype depends on its own base type.
6337 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
6339 -- If we just froze a tagged non-class wide record, then freeze the
6340 -- corresponding class-wide type. This must be done after the tagged
6341 -- type itself is frozen, because the class-wide type refers to the
6342 -- tagged type which generates the class.
6344 if Is_Tagged_Type
(E
)
6345 and then not Is_Class_Wide_Type
(E
)
6346 and then Present
(Class_Wide_Type
(E
))
6348 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
6352 Check_Debug_Info_Needed
(E
);
6354 -- Special handling for subprograms
6356 if Is_Subprogram
(E
) then
6358 -- If subprogram has address clause then reset Is_Public flag, since
6359 -- we do not want the backend to generate external references.
6361 if Present
(Address_Clause
(E
))
6362 and then not Is_Library_Level_Entity
(E
)
6364 Set_Is_Public
(E
, False);
6368 Ghost_Mode
:= Save_Ghost_Mode
;
6372 -----------------------------
6373 -- Freeze_Enumeration_Type --
6374 -----------------------------
6376 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
6378 -- By default, if no size clause is present, an enumeration type with
6379 -- Convention C is assumed to interface to a C enum, and has integer
6380 -- size. This applies to types. For subtypes, verify that its base
6381 -- type has no size clause either. Treat other foreign conventions
6382 -- in the same way, and also make sure alignment is set right.
6384 if Has_Foreign_Convention
(Typ
)
6385 and then not Has_Size_Clause
(Typ
)
6386 and then not Has_Size_Clause
(Base_Type
(Typ
))
6387 and then Esize
(Typ
) < Standard_Integer_Size
6389 -- Don't do this if Short_Enums on target
6391 and then not Target_Short_Enums
6393 Init_Esize
(Typ
, Standard_Integer_Size
);
6394 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
6396 -- Normal Ada case or size clause present or not Long_C_Enums on target
6399 -- If the enumeration type interfaces to C, and it has a size clause
6400 -- that specifies less than int size, it warrants a warning. The
6401 -- user may intend the C type to be an enum or a char, so this is
6402 -- not by itself an error that the Ada compiler can detect, but it
6403 -- it is a worth a heads-up. For Boolean and Character types we
6404 -- assume that the programmer has the proper C type in mind.
6406 if Convention
(Typ
) = Convention_C
6407 and then Has_Size_Clause
(Typ
)
6408 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
6409 and then not Is_Boolean_Type
(Typ
)
6410 and then not Is_Character_Type
(Typ
)
6412 -- Don't do this if Short_Enums on target
6414 and then not Target_Short_Enums
6417 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
6420 Adjust_Esize_For_Alignment
(Typ
);
6422 end Freeze_Enumeration_Type
;
6424 -----------------------
6425 -- Freeze_Expression --
6426 -----------------------
6428 procedure Freeze_Expression
(N
: Node_Id
) is
6429 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
6432 Desig_Typ
: Entity_Id
;
6436 Freeze_Outside
: Boolean := False;
6437 -- This flag is set true if the entity must be frozen outside the
6438 -- current subprogram. This happens in the case of expander generated
6439 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
6440 -- not freeze all entities like other bodies, but which nevertheless
6441 -- may reference entities that have to be frozen before the body and
6442 -- obviously cannot be frozen inside the body.
6444 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
6445 -- If the expression is an array aggregate, the type of the component
6446 -- expressions is also frozen. If the component type is an access type
6447 -- and the expressions include allocators, the designed type is frozen
6450 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
6451 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
6452 -- it is the handled statement sequence of an expander-generated
6453 -- subprogram (init proc, stream subprogram, or renaming as body).
6454 -- If so, this is not a freezing context.
6456 -----------------------------------------
6457 -- Find_Aggregate_Component_Desig_Type --
6458 -----------------------------------------
6460 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
6465 if Present
(Expressions
(N
)) then
6466 Exp
:= First
(Expressions
(N
));
6467 while Present
(Exp
) loop
6468 if Nkind
(Exp
) = N_Allocator
then
6469 return Designated_Type
(Component_Type
(Etype
(N
)));
6476 if Present
(Component_Associations
(N
)) then
6477 Assoc
:= First
(Component_Associations
(N
));
6478 while Present
(Assoc
) loop
6479 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
6480 return Designated_Type
(Component_Type
(Etype
(N
)));
6488 end Find_Aggregate_Component_Desig_Type
;
6490 ----------------------
6491 -- In_Expanded_Body --
6492 ----------------------
6494 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
6499 if Nkind
(N
) = N_Subprogram_Body
then
6505 if Nkind
(P
) /= N_Subprogram_Body
then
6509 Id
:= Defining_Unit_Name
(Specification
(P
));
6511 -- The following are expander-created bodies, or bodies that
6512 -- are not freeze points.
6514 if Nkind
(Id
) = N_Defining_Identifier
6515 and then (Is_Init_Proc
(Id
)
6516 or else Is_TSS
(Id
, TSS_Stream_Input
)
6517 or else Is_TSS
(Id
, TSS_Stream_Output
)
6518 or else Is_TSS
(Id
, TSS_Stream_Read
)
6519 or else Is_TSS
(Id
, TSS_Stream_Write
)
6520 or else Nkind_In
(Original_Node
(P
),
6521 N_Subprogram_Renaming_Declaration
,
6522 N_Expression_Function
))
6529 end In_Expanded_Body
;
6531 -- Start of processing for Freeze_Expression
6534 -- Immediate return if freezing is inhibited. This flag is set by the
6535 -- analyzer to stop freezing on generated expressions that would cause
6536 -- freezing if they were in the source program, but which are not
6537 -- supposed to freeze, since they are created.
6539 if Must_Not_Freeze
(N
) then
6543 -- If expression is non-static, then it does not freeze in a default
6544 -- expression, see section "Handling of Default Expressions" in the
6545 -- spec of package Sem for further details. Note that we have to make
6546 -- sure that we actually have a real expression (if we have a subtype
6547 -- indication, we can't test Is_OK_Static_Expression). However, we
6548 -- exclude the case of the prefix of an attribute of a static scalar
6549 -- subtype from this early return, because static subtype attributes
6550 -- should always cause freezing, even in default expressions, but
6551 -- the attribute may not have been marked as static yet (because in
6552 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
6553 -- Freeze_Expression on the prefix).
6556 and then Nkind
(N
) in N_Subexpr
6557 and then not Is_OK_Static_Expression
(N
)
6558 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
6559 or else not (Is_Entity_Name
(N
)
6560 and then Is_Type
(Entity
(N
))
6561 and then Is_OK_Static_Subtype
(Entity
(N
))))
6566 -- Freeze type of expression if not frozen already
6570 if Nkind
(N
) in N_Has_Etype
then
6571 if not Is_Frozen
(Etype
(N
)) then
6574 -- Base type may be an derived numeric type that is frozen at
6575 -- the point of declaration, but first_subtype is still unfrozen.
6577 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
6578 Typ
:= First_Subtype
(Etype
(N
));
6582 -- For entity name, freeze entity if not frozen already. A special
6583 -- exception occurs for an identifier that did not come from source.
6584 -- We don't let such identifiers freeze a non-internal entity, i.e.
6585 -- an entity that did come from source, since such an identifier was
6586 -- generated by the expander, and cannot have any semantic effect on
6587 -- the freezing semantics. For example, this stops the parameter of
6588 -- an initialization procedure from freezing the variable.
6590 if Is_Entity_Name
(N
)
6591 and then not Is_Frozen
(Entity
(N
))
6592 and then (Nkind
(N
) /= N_Identifier
6593 or else Comes_From_Source
(N
)
6594 or else not Comes_From_Source
(Entity
(N
)))
6598 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
6599 Check_Expression_Function
(N
, Nam
);
6606 -- For an allocator freeze designated type if not frozen already
6608 -- For an aggregate whose component type is an access type, freeze the
6609 -- designated type now, so that its freeze does not appear within the
6610 -- loop that might be created in the expansion of the aggregate. If the
6611 -- designated type is a private type without full view, the expression
6612 -- cannot contain an allocator, so the type is not frozen.
6614 -- For a function, we freeze the entity when the subprogram declaration
6615 -- is frozen, but a function call may appear in an initialization proc.
6616 -- before the declaration is frozen. We need to generate the extra
6617 -- formals, if any, to ensure that the expansion of the call includes
6618 -- the proper actuals. This only applies to Ada subprograms, not to
6625 Desig_Typ
:= Designated_Type
(Etype
(N
));
6628 if Is_Array_Type
(Etype
(N
))
6629 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
6632 -- Check whether aggregate includes allocators.
6634 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
6637 when N_Selected_Component |
6638 N_Indexed_Component |
6641 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6642 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
6645 when N_Identifier
=>
6647 and then Ekind
(Nam
) = E_Function
6648 and then Nkind
(Parent
(N
)) = N_Function_Call
6649 and then Convention
(Nam
) = Convention_Ada
6651 Create_Extra_Formals
(Nam
);
6658 if Desig_Typ
/= Empty
6659 and then (Is_Frozen
(Desig_Typ
)
6660 or else (not Is_Fully_Defined
(Desig_Typ
)))
6665 -- All done if nothing needs freezing
6669 and then No
(Desig_Typ
)
6674 -- Examine the enclosing context by climbing the parent chain. The
6675 -- traversal serves two purposes - to detect scenarios where freezeing
6676 -- is not needed and to find the proper insertion point for the freeze
6677 -- nodes. Although somewhat similar to Insert_Actions, this traversal
6678 -- is freezing semantics-sensitive. Inserting freeze nodes blindly in
6679 -- the tree may result in types being frozen too early.
6683 Parent_P
:= Parent
(P
);
6685 -- If we don't have a parent, then we are not in a well-formed tree.
6686 -- This is an unusual case, but there are some legitimate situations
6687 -- in which this occurs, notably when the expressions in the range of
6688 -- a type declaration are resolved. We simply ignore the freeze
6689 -- request in this case. Is this right ???
6691 if No
(Parent_P
) then
6695 -- See if we have got to an appropriate point in the tree
6697 case Nkind
(Parent_P
) is
6699 -- A special test for the exception of (RM 13.14(8)) for the case
6700 -- of per-object expressions (RM 3.8(18)) occurring in component
6701 -- definition or a discrete subtype definition. Note that we test
6702 -- for a component declaration which includes both cases we are
6703 -- interested in, and furthermore the tree does not have explicit
6704 -- nodes for either of these two constructs.
6706 when N_Component_Declaration
=>
6708 -- The case we want to test for here is an identifier that is
6709 -- a per-object expression, this is either a discriminant that
6710 -- appears in a context other than the component declaration
6711 -- or it is a reference to the type of the enclosing construct.
6713 -- For either of these cases, we skip the freezing
6715 if not In_Spec_Expression
6716 and then Nkind
(N
) = N_Identifier
6717 and then (Present
(Entity
(N
)))
6719 -- We recognize the discriminant case by just looking for
6720 -- a reference to a discriminant. It can only be one for
6721 -- the enclosing construct. Skip freezing in this case.
6723 if Ekind
(Entity
(N
)) = E_Discriminant
then
6726 -- For the case of a reference to the enclosing record,
6727 -- (or task or protected type), we look for a type that
6728 -- matches the current scope.
6730 elsif Entity
(N
) = Current_Scope
then
6735 -- If we have an enumeration literal that appears as the choice in
6736 -- the aggregate of an enumeration representation clause, then
6737 -- freezing does not occur (RM 13.14(10)).
6739 when N_Enumeration_Representation_Clause
=>
6741 -- The case we are looking for is an enumeration literal
6743 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
6744 and then Is_Enumeration_Type
(Etype
(N
))
6746 -- If enumeration literal appears directly as the choice,
6747 -- do not freeze (this is the normal non-overloaded case)
6749 if Nkind
(Parent
(N
)) = N_Component_Association
6750 and then First
(Choices
(Parent
(N
))) = N
6754 -- If enumeration literal appears as the name of function
6755 -- which is the choice, then also do not freeze. This
6756 -- happens in the overloaded literal case, where the
6757 -- enumeration literal is temporarily changed to a function
6758 -- call for overloading analysis purposes.
6760 elsif Nkind
(Parent
(N
)) = N_Function_Call
6762 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
6764 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
6770 -- Normally if the parent is a handled sequence of statements,
6771 -- then the current node must be a statement, and that is an
6772 -- appropriate place to insert a freeze node.
6774 when N_Handled_Sequence_Of_Statements
=>
6776 -- An exception occurs when the sequence of statements is for
6777 -- an expander generated body that did not do the usual freeze
6778 -- all operation. In this case we usually want to freeze
6779 -- outside this body, not inside it, and we skip past the
6780 -- subprogram body that we are inside.
6782 if In_Expanded_Body
(Parent_P
) then
6784 Subp
: constant Node_Id
:= Parent
(Parent_P
);
6788 -- Freeze the entity only when it is declared inside the
6789 -- body of the expander generated procedure. This case
6790 -- is recognized by the scope of the entity or its type,
6791 -- which is either the spec for some enclosing body, or
6792 -- (in the case of init_procs, for which there are no
6793 -- separate specs) the current scope.
6795 if Nkind
(Subp
) = N_Subprogram_Body
then
6796 Spec
:= Corresponding_Spec
(Subp
);
6798 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
6800 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
6805 and then Scope
(Typ
) = Current_Scope
6806 and then Defining_Entity
(Subp
) = Current_Scope
6812 -- An expression function may act as a completion of
6813 -- a function declaration. As such, it can reference
6814 -- entities declared between the two views:
6817 -- function F return ...;
6819 -- function Hidden return ...;
6820 -- function F return ... is (Hidden); -- 2
6822 -- Refering to the example above, freezing the expression
6823 -- of F (2) would place Hidden's freeze node (1) in the
6824 -- wrong place. Avoid explicit freezing and let the usual
6825 -- scenarios do the job - for example, reaching the end
6826 -- of the private declarations, or a call to F.
6828 if Nkind
(Original_Node
(Subp
)) =
6829 N_Expression_Function
6833 -- Freeze outside the body
6836 Parent_P
:= Parent
(Parent_P
);
6837 Freeze_Outside
:= True;
6841 -- Here if normal case where we are in handled statement
6842 -- sequence and want to do the insertion right there.
6848 -- If parent is a body or a spec or a block, then the current node
6849 -- is a statement or declaration and we can insert the freeze node
6852 when N_Block_Statement |
6855 N_Package_Specification |
6858 N_Task_Body
=> exit;
6860 -- The expander is allowed to define types in any statements list,
6861 -- so any of the following parent nodes also mark a freezing point
6862 -- if the actual node is in a list of statements or declarations.
6864 when N_Abortable_Part |
6865 N_Accept_Alternative |
6867 N_Case_Statement_Alternative |
6868 N_Compilation_Unit_Aux |
6869 N_Conditional_Entry_Call |
6870 N_Delay_Alternative |
6872 N_Entry_Call_Alternative |
6873 N_Exception_Handler |
6874 N_Extended_Return_Statement |
6878 N_Selective_Accept |
6879 N_Triggering_Alternative
=>
6881 exit when Is_List_Member
(P
);
6883 -- Freeze nodes produced by an expression coming from the Actions
6884 -- list of a N_Expression_With_Actions node must remain within the
6885 -- Actions list. Inserting the freeze nodes further up the tree
6886 -- may lead to use before declaration issues in the case of array
6889 when N_Expression_With_Actions
=>
6890 if Is_List_Member
(P
)
6891 and then List_Containing
(P
) = Actions
(Parent_P
)
6896 -- Note: N_Loop_Statement is a special case. A type that appears
6897 -- in the source can never be frozen in a loop (this occurs only
6898 -- because of a loop expanded by the expander), so we keep on
6899 -- going. Otherwise we terminate the search. Same is true of any
6900 -- entity which comes from source. (if they have predefined type,
6901 -- that type does not appear to come from source, but the entity
6902 -- should not be frozen here).
6904 when N_Loop_Statement
=>
6905 exit when not Comes_From_Source
(Etype
(N
))
6906 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
6908 -- For all other cases, keep looking at parents
6914 -- We fall through the case if we did not yet find the proper
6915 -- place in the free for inserting the freeze node, so climb.
6920 -- If the expression appears in a record or an initialization procedure,
6921 -- the freeze nodes are collected and attached to the current scope, to
6922 -- be inserted and analyzed on exit from the scope, to insure that
6923 -- generated entities appear in the correct scope. If the expression is
6924 -- a default for a discriminant specification, the scope is still void.
6925 -- The expression can also appear in the discriminant part of a private
6926 -- or concurrent type.
6928 -- If the expression appears in a constrained subcomponent of an
6929 -- enclosing record declaration, the freeze nodes must be attached to
6930 -- the outer record type so they can eventually be placed in the
6931 -- enclosing declaration list.
6933 -- The other case requiring this special handling is if we are in a
6934 -- default expression, since in that case we are about to freeze a
6935 -- static type, and the freeze scope needs to be the outer scope, not
6936 -- the scope of the subprogram with the default parameter.
6938 -- For default expressions and other spec expressions in generic units,
6939 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
6940 -- placing them at the proper place, after the generic unit.
6942 if (In_Spec_Exp
and not Inside_A_Generic
)
6943 or else Freeze_Outside
6944 or else (Is_Type
(Current_Scope
)
6945 and then (not Is_Concurrent_Type
(Current_Scope
)
6946 or else not Has_Completion
(Current_Scope
)))
6947 or else Ekind
(Current_Scope
) = E_Void
6950 N
: constant Node_Id
:= Current_Scope
;
6951 Freeze_Nodes
: List_Id
:= No_List
;
6952 Pos
: Int
:= Scope_Stack
.Last
;
6955 if Present
(Desig_Typ
) then
6956 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
6959 if Present
(Typ
) then
6960 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
6963 if Present
(Nam
) then
6964 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
6967 -- The current scope may be that of a constrained component of
6968 -- an enclosing record declaration, or of a loop of an enclosing
6969 -- quantified expression, which is above the current scope in the
6970 -- scope stack. Indeed in the context of a quantified expression,
6971 -- a scope is created and pushed above the current scope in order
6972 -- to emulate the loop-like behavior of the quantified expression.
6973 -- If the expression is within a top-level pragma, as for a pre-
6974 -- condition on a library-level subprogram, nothing to do.
6976 if not Is_Compilation_Unit
(Current_Scope
)
6977 and then (Is_Record_Type
(Scope
(Current_Scope
))
6978 or else Nkind
(Parent
(Current_Scope
)) =
6979 N_Quantified_Expression
)
6984 if Is_Non_Empty_List
(Freeze_Nodes
) then
6985 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
6986 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
6989 Append_List
(Freeze_Nodes
,
6990 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
6998 -- Now we have the right place to do the freezing. First, a special
6999 -- adjustment, if we are in spec-expression analysis mode, these freeze
7000 -- actions must not be thrown away (normally all inserted actions are
7001 -- thrown away in this mode. However, the freeze actions are from static
7002 -- expressions and one of the important reasons we are doing this
7003 -- special analysis is to get these freeze actions. Therefore we turn
7004 -- off the In_Spec_Expression mode to propagate these freeze actions.
7005 -- This also means they get properly analyzed and expanded.
7007 In_Spec_Expression
:= False;
7009 -- Freeze the designated type of an allocator (RM 13.14(13))
7011 if Present
(Desig_Typ
) then
7012 Freeze_Before
(P
, Desig_Typ
);
7015 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
7016 -- the enumeration representation clause exception in the loop above.
7018 if Present
(Typ
) then
7019 Freeze_Before
(P
, Typ
);
7022 -- Freeze name if one is present (RM 13.14(11))
7024 if Present
(Nam
) then
7025 Freeze_Before
(P
, Nam
);
7028 -- Restore In_Spec_Expression flag
7030 In_Spec_Expression
:= In_Spec_Exp
;
7031 end Freeze_Expression
;
7033 -----------------------------
7034 -- Freeze_Fixed_Point_Type --
7035 -----------------------------
7037 -- Certain fixed-point types and subtypes, including implicit base types
7038 -- and declared first subtypes, have not yet set up a range. This is
7039 -- because the range cannot be set until the Small and Size values are
7040 -- known, and these are not known till the type is frozen.
7042 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
7043 -- whose bounds are unanalyzed real literals. This routine will recognize
7044 -- this case, and transform this range node into a properly typed range
7045 -- with properly analyzed and resolved values.
7047 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
7048 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
7049 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
7050 Hi
: constant Node_Id
:= High_Bound
(Rng
);
7051 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7052 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
7053 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
7054 BHi
: constant Node_Id
:= High_Bound
(Brng
);
7055 Small
: constant Ureal
:= Small_Value
(Typ
);
7062 -- Save original bounds (for shaving tests)
7065 -- Actual size chosen
7067 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
7068 -- Returns size of type with given bounds. Also leaves these
7069 -- bounds set as the current bounds of the Typ.
7075 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
7077 Set_Realval
(Lo
, Lov
);
7078 Set_Realval
(Hi
, Hiv
);
7079 return Minimum_Size
(Typ
);
7082 -- Start of processing for Freeze_Fixed_Point_Type
7085 -- If Esize of a subtype has not previously been set, set it now
7087 if Unknown_Esize
(Typ
) then
7088 Atype
:= Ancestor_Subtype
(Typ
);
7090 if Present
(Atype
) then
7091 Set_Esize
(Typ
, Esize
(Atype
));
7093 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
7097 -- Immediate return if the range is already analyzed. This means that
7098 -- the range is already set, and does not need to be computed by this
7101 if Analyzed
(Rng
) then
7105 -- Immediate return if either of the bounds raises Constraint_Error
7107 if Raises_Constraint_Error
(Lo
)
7108 or else Raises_Constraint_Error
(Hi
)
7113 Loval
:= Realval
(Lo
);
7114 Hival
:= Realval
(Hi
);
7119 -- Ordinary fixed-point case
7121 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
7123 -- For the ordinary fixed-point case, we are allowed to fudge the
7124 -- end-points up or down by small. Generally we prefer to fudge up,
7125 -- i.e. widen the bounds for non-model numbers so that the end points
7126 -- are included. However there are cases in which this cannot be
7127 -- done, and indeed cases in which we may need to narrow the bounds.
7128 -- The following circuit makes the decision.
7130 -- Note: our terminology here is that Incl_EP means that the bounds
7131 -- are widened by Small if necessary to include the end points, and
7132 -- Excl_EP means that the bounds are narrowed by Small to exclude the
7133 -- end-points if this reduces the size.
7135 -- Note that in the Incl case, all we care about is including the
7136 -- end-points. In the Excl case, we want to narrow the bounds as
7137 -- much as permitted by the RM, to give the smallest possible size.
7140 Loval_Incl_EP
: Ureal
;
7141 Hival_Incl_EP
: Ureal
;
7143 Loval_Excl_EP
: Ureal
;
7144 Hival_Excl_EP
: Ureal
;
7150 First_Subt
: Entity_Id
;
7155 -- First step. Base types are required to be symmetrical. Right
7156 -- now, the base type range is a copy of the first subtype range.
7157 -- This will be corrected before we are done, but right away we
7158 -- need to deal with the case where both bounds are non-negative.
7159 -- In this case, we set the low bound to the negative of the high
7160 -- bound, to make sure that the size is computed to include the
7161 -- required sign. Note that we do not need to worry about the
7162 -- case of both bounds negative, because the sign will be dealt
7163 -- with anyway. Furthermore we can't just go making such a bound
7164 -- symmetrical, since in a twos-complement system, there is an
7165 -- extra negative value which could not be accommodated on the
7169 and then not UR_Is_Negative
(Loval
)
7170 and then Hival
> Loval
7173 Set_Realval
(Lo
, Loval
);
7176 -- Compute the fudged bounds. If the number is a model number,
7177 -- then we do nothing to include it, but we are allowed to backoff
7178 -- to the next adjacent model number when we exclude it. If it is
7179 -- not a model number then we straddle the two values with the
7180 -- model numbers on either side.
7182 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
7184 if Loval
= Model_Num
then
7185 Loval_Incl_EP
:= Model_Num
;
7187 Loval_Incl_EP
:= Model_Num
- Small
;
7190 -- The low value excluding the end point is Small greater, but
7191 -- we do not do this exclusion if the low value is positive,
7192 -- since it can't help the size and could actually hurt by
7193 -- crossing the high bound.
7195 if UR_Is_Negative
(Loval_Incl_EP
) then
7196 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
7198 -- If the value went from negative to zero, then we have the
7199 -- case where Loval_Incl_EP is the model number just below
7200 -- zero, so we want to stick to the negative value for the
7201 -- base type to maintain the condition that the size will
7202 -- include signed values.
7205 and then UR_Is_Zero
(Loval_Excl_EP
)
7207 Loval_Excl_EP
:= Loval_Incl_EP
;
7211 Loval_Excl_EP
:= Loval_Incl_EP
;
7214 -- Similar processing for upper bound and high value
7216 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
7218 if Hival
= Model_Num
then
7219 Hival_Incl_EP
:= Model_Num
;
7221 Hival_Incl_EP
:= Model_Num
+ Small
;
7224 if UR_Is_Positive
(Hival_Incl_EP
) then
7225 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
7227 Hival_Excl_EP
:= Hival_Incl_EP
;
7230 -- One further adjustment is needed. In the case of subtypes, we
7231 -- cannot go outside the range of the base type, or we get
7232 -- peculiarities, and the base type range is already set. This
7233 -- only applies to the Incl values, since clearly the Excl values
7234 -- are already as restricted as they are allowed to be.
7237 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
7238 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
7241 -- Get size including and excluding end points
7243 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
7244 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
7246 -- No need to exclude end-points if it does not reduce size
7248 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
7249 Loval_Excl_EP
:= Loval_Incl_EP
;
7252 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
7253 Hival_Excl_EP
:= Hival_Incl_EP
;
7256 -- Now we set the actual size to be used. We want to use the
7257 -- bounds fudged up to include the end-points but only if this
7258 -- can be done without violating a specifically given size
7259 -- size clause or causing an unacceptable increase in size.
7261 -- Case of size clause given
7263 if Has_Size_Clause
(Typ
) then
7265 -- Use the inclusive size only if it is consistent with
7266 -- the explicitly specified size.
7268 if Size_Incl_EP
<= RM_Size
(Typ
) then
7269 Actual_Lo
:= Loval_Incl_EP
;
7270 Actual_Hi
:= Hival_Incl_EP
;
7271 Actual_Size
:= Size_Incl_EP
;
7273 -- If the inclusive size is too large, we try excluding
7274 -- the end-points (will be caught later if does not work).
7277 Actual_Lo
:= Loval_Excl_EP
;
7278 Actual_Hi
:= Hival_Excl_EP
;
7279 Actual_Size
:= Size_Excl_EP
;
7282 -- Case of size clause not given
7285 -- If we have a base type whose corresponding first subtype
7286 -- has an explicit size that is large enough to include our
7287 -- end-points, then do so. There is no point in working hard
7288 -- to get a base type whose size is smaller than the specified
7289 -- size of the first subtype.
7291 First_Subt
:= First_Subtype
(Typ
);
7293 if Has_Size_Clause
(First_Subt
)
7294 and then Size_Incl_EP
<= Esize
(First_Subt
)
7296 Actual_Size
:= Size_Incl_EP
;
7297 Actual_Lo
:= Loval_Incl_EP
;
7298 Actual_Hi
:= Hival_Incl_EP
;
7300 -- If excluding the end-points makes the size smaller and
7301 -- results in a size of 8,16,32,64, then we take the smaller
7302 -- size. For the 64 case, this is compulsory. For the other
7303 -- cases, it seems reasonable. We like to include end points
7304 -- if we can, but not at the expense of moving to the next
7305 -- natural boundary of size.
7307 elsif Size_Incl_EP
/= Size_Excl_EP
7308 and then Addressable
(Size_Excl_EP
)
7310 Actual_Size
:= Size_Excl_EP
;
7311 Actual_Lo
:= Loval_Excl_EP
;
7312 Actual_Hi
:= Hival_Excl_EP
;
7314 -- Otherwise we can definitely include the end points
7317 Actual_Size
:= Size_Incl_EP
;
7318 Actual_Lo
:= Loval_Incl_EP
;
7319 Actual_Hi
:= Hival_Incl_EP
;
7322 -- One pathological case: normally we never fudge a low bound
7323 -- down, since it would seem to increase the size (if it has
7324 -- any effect), but for ranges containing single value, or no
7325 -- values, the high bound can be small too large. Consider:
7327 -- type t is delta 2.0**(-14)
7328 -- range 131072.0 .. 0;
7330 -- That lower bound is *just* outside the range of 32 bits, and
7331 -- does need fudging down in this case. Note that the bounds
7332 -- will always have crossed here, since the high bound will be
7333 -- fudged down if necessary, as in the case of:
7335 -- type t is delta 2.0**(-14)
7336 -- range 131072.0 .. 131072.0;
7338 -- So we detect the situation by looking for crossed bounds,
7339 -- and if the bounds are crossed, and the low bound is greater
7340 -- than zero, we will always back it off by small, since this
7341 -- is completely harmless.
7343 if Actual_Lo
> Actual_Hi
then
7344 if UR_Is_Positive
(Actual_Lo
) then
7345 Actual_Lo
:= Loval_Incl_EP
- Small
;
7346 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
7348 -- And of course, we need to do exactly the same parallel
7349 -- fudge for flat ranges in the negative region.
7351 elsif UR_Is_Negative
(Actual_Hi
) then
7352 Actual_Hi
:= Hival_Incl_EP
+ Small
;
7353 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
7358 Set_Realval
(Lo
, Actual_Lo
);
7359 Set_Realval
(Hi
, Actual_Hi
);
7362 -- For the decimal case, none of this fudging is required, since there
7363 -- are no end-point problems in the decimal case (the end-points are
7364 -- always included).
7367 Actual_Size
:= Fsize
(Loval
, Hival
);
7370 -- At this stage, the actual size has been calculated and the proper
7371 -- required bounds are stored in the low and high bounds.
7373 if Actual_Size
> 64 then
7374 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
7376 ("size required (^) for type& too large, maximum allowed is 64",
7381 -- Check size against explicit given size
7383 if Has_Size_Clause
(Typ
) then
7384 if Actual_Size
> RM_Size
(Typ
) then
7385 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7386 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
7388 ("size given (^) for type& too small, minimum allowed is ^",
7389 Size_Clause
(Typ
), Typ
);
7392 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
7395 -- Increase size to next natural boundary if no size clause given
7398 if Actual_Size
<= 8 then
7400 elsif Actual_Size
<= 16 then
7402 elsif Actual_Size
<= 32 then
7408 Init_Esize
(Typ
, Actual_Size
);
7409 Adjust_Esize_For_Alignment
(Typ
);
7412 -- If we have a base type, then expand the bounds so that they extend to
7413 -- the full width of the allocated size in bits, to avoid junk range
7414 -- checks on intermediate computations.
7416 if Base_Type
(Typ
) = Typ
then
7417 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
7418 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
7421 -- Final step is to reanalyze the bounds using the proper type
7422 -- and set the Corresponding_Integer_Value fields of the literals.
7424 Set_Etype
(Lo
, Empty
);
7425 Set_Analyzed
(Lo
, False);
7428 -- Resolve with universal fixed if the base type, and the base type if
7429 -- it is a subtype. Note we can't resolve the base type with itself,
7430 -- that would be a reference before definition.
7433 Resolve
(Lo
, Universal_Fixed
);
7438 -- Set corresponding integer value for bound
7440 Set_Corresponding_Integer_Value
7441 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
7443 -- Similar processing for high bound
7445 Set_Etype
(Hi
, Empty
);
7446 Set_Analyzed
(Hi
, False);
7450 Resolve
(Hi
, Universal_Fixed
);
7455 Set_Corresponding_Integer_Value
7456 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
7458 -- Set type of range to correspond to bounds
7460 Set_Etype
(Rng
, Etype
(Lo
));
7462 -- Set Esize to calculated size if not set already
7464 if Unknown_Esize
(Typ
) then
7465 Init_Esize
(Typ
, Actual_Size
);
7468 -- Set RM_Size if not already set. If already set, check value
7471 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
7474 if RM_Size
(Typ
) /= Uint_0
then
7475 if RM_Size
(Typ
) < Minsiz
then
7476 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7477 Error_Msg_Uint_2
:= Minsiz
;
7479 ("size given (^) for type& too small, minimum allowed is ^",
7480 Size_Clause
(Typ
), Typ
);
7484 Set_RM_Size
(Typ
, Minsiz
);
7488 -- Check for shaving
7490 if Comes_From_Source
(Typ
) then
7491 if Orig_Lo
< Expr_Value_R
(Lo
) then
7493 ("declared low bound of type & is outside type range??", Typ
);
7495 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
7498 if Orig_Hi
> Expr_Value_R
(Hi
) then
7500 ("declared high bound of type & is outside type range??", Typ
);
7502 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
7505 end Freeze_Fixed_Point_Type
;
7511 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
7515 Set_Has_Delayed_Freeze
(T
);
7516 L
:= Freeze_Entity
(T
, N
);
7518 if Is_Non_Empty_List
(L
) then
7519 Insert_Actions
(N
, L
);
7523 --------------------------
7524 -- Freeze_Static_Object --
7525 --------------------------
7527 procedure Freeze_Static_Object
(E
: Entity_Id
) is
7529 Cannot_Be_Static
: exception;
7530 -- Exception raised if the type of a static object cannot be made
7531 -- static. This happens if the type depends on non-global objects.
7533 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
7534 -- Called to ensure that an expression used as part of a type definition
7535 -- is statically allocatable, which means that the expression type is
7536 -- statically allocatable, and the expression is either static, or a
7537 -- reference to a library level constant.
7539 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
7540 -- Called to mark a type as static, checking that it is possible
7541 -- to set the type as static. If it is not possible, then the
7542 -- exception Cannot_Be_Static is raised.
7544 -----------------------------
7545 -- Ensure_Expression_Is_SA --
7546 -----------------------------
7548 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
7552 Ensure_Type_Is_SA
(Etype
(N
));
7554 if Is_OK_Static_Expression
(N
) then
7557 elsif Nkind
(N
) = N_Identifier
then
7561 and then Ekind
(Ent
) = E_Constant
7562 and then Is_Library_Level_Entity
(Ent
)
7568 raise Cannot_Be_Static
;
7569 end Ensure_Expression_Is_SA
;
7571 -----------------------
7572 -- Ensure_Type_Is_SA --
7573 -----------------------
7575 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
7580 -- If type is library level, we are all set
7582 if Is_Library_Level_Entity
(Typ
) then
7586 -- We are also OK if the type already marked as statically allocated,
7587 -- which means we processed it before.
7589 if Is_Statically_Allocated
(Typ
) then
7593 -- Mark type as statically allocated
7595 Set_Is_Statically_Allocated
(Typ
);
7597 -- Check that it is safe to statically allocate this type
7599 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
7600 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
7601 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
7603 elsif Is_Array_Type
(Typ
) then
7604 N
:= First_Index
(Typ
);
7605 while Present
(N
) loop
7606 Ensure_Type_Is_SA
(Etype
(N
));
7610 Ensure_Type_Is_SA
(Component_Type
(Typ
));
7612 elsif Is_Access_Type
(Typ
) then
7613 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
7617 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
7620 if T
/= Standard_Void_Type
then
7621 Ensure_Type_Is_SA
(T
);
7624 F
:= First_Formal
(Designated_Type
(Typ
));
7625 while Present
(F
) loop
7626 Ensure_Type_Is_SA
(Etype
(F
));
7632 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
7635 elsif Is_Record_Type
(Typ
) then
7636 C
:= First_Entity
(Typ
);
7637 while Present
(C
) loop
7638 if Ekind
(C
) = E_Discriminant
7639 or else Ekind
(C
) = E_Component
7641 Ensure_Type_Is_SA
(Etype
(C
));
7643 elsif Is_Type
(C
) then
7644 Ensure_Type_Is_SA
(C
);
7650 elsif Ekind
(Typ
) = E_Subprogram_Type
then
7651 Ensure_Type_Is_SA
(Etype
(Typ
));
7653 C
:= First_Formal
(Typ
);
7654 while Present
(C
) loop
7655 Ensure_Type_Is_SA
(Etype
(C
));
7660 raise Cannot_Be_Static
;
7662 end Ensure_Type_Is_SA
;
7664 -- Start of processing for Freeze_Static_Object
7667 Ensure_Type_Is_SA
(Etype
(E
));
7670 when Cannot_Be_Static
=>
7672 -- If the object that cannot be static is imported or exported, then
7673 -- issue an error message saying that this object cannot be imported
7674 -- or exported. If it has an address clause it is an overlay in the
7675 -- current partition and the static requirement is not relevant.
7676 -- Do not issue any error message when ignoring rep clauses.
7678 if Ignore_Rep_Clauses
then
7681 elsif Is_Imported
(E
) then
7682 if No
(Address_Clause
(E
)) then
7684 ("& cannot be imported (local type is not constant)", E
);
7687 -- Otherwise must be exported, something is wrong if compiler
7688 -- is marking something as statically allocated which cannot be).
7690 else pragma Assert
(Is_Exported
(E
));
7692 ("& cannot be exported (local type is not constant)", E
);
7694 end Freeze_Static_Object
;
7696 -----------------------
7697 -- Freeze_Subprogram --
7698 -----------------------
7700 procedure Freeze_Subprogram
(E
: Entity_Id
) is
7705 -- Subprogram may not have an address clause unless it is imported
7707 if Present
(Address_Clause
(E
)) then
7708 if not Is_Imported
(E
) then
7710 ("address clause can only be given " &
7711 "for imported subprogram",
7712 Name
(Address_Clause
(E
)));
7716 -- Reset the Pure indication on an imported subprogram unless an
7717 -- explicit Pure_Function pragma was present or the subprogram is an
7718 -- intrinsic. We do this because otherwise it is an insidious error
7719 -- to call a non-pure function from pure unit and have calls
7720 -- mysteriously optimized away. What happens here is that the Import
7721 -- can bypass the normal check to ensure that pure units call only pure
7724 -- The reason for the intrinsic exception is that in general, intrinsic
7725 -- functions (such as shifts) are pure anyway. The only exceptions are
7726 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
7727 -- in any case, so no problem arises.
7730 and then Is_Pure
(E
)
7731 and then not Has_Pragma_Pure_Function
(E
)
7732 and then not Is_Intrinsic_Subprogram
(E
)
7734 Set_Is_Pure
(E
, False);
7737 -- We also reset the Pure indication on a subprogram with an Address
7738 -- parameter, because the parameter may be used as a pointer and the
7739 -- referenced data may change even if the address value does not.
7741 -- Note that if the programmer gave an explicit Pure_Function pragma,
7742 -- then we believe the programmer, and leave the subprogram Pure.
7743 -- We also suppress this check on run-time files.
7746 and then Is_Subprogram
(E
)
7747 and then not Has_Pragma_Pure_Function
(E
)
7748 and then not Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
7750 Check_Function_With_Address_Parameter
(E
);
7753 -- For non-foreign convention subprograms, this is where we create
7754 -- the extra formals (for accessibility level and constrained bit
7755 -- information). We delay this till the freeze point precisely so
7756 -- that we know the convention.
7758 if not Has_Foreign_Convention
(E
) then
7759 Create_Extra_Formals
(E
);
7762 -- If this is convention Ada and a Valued_Procedure, that's odd
7764 if Ekind
(E
) = E_Procedure
7765 and then Is_Valued_Procedure
(E
)
7766 and then Convention
(E
) = Convention_Ada
7767 and then Warn_On_Export_Import
7770 ("??Valued_Procedure has no effect for convention Ada", E
);
7771 Set_Is_Valued_Procedure
(E
, False);
7774 -- Case of foreign convention
7779 -- For foreign conventions, warn about return of unconstrained array
7781 if Ekind
(E
) = E_Function
then
7782 Retype
:= Underlying_Type
(Etype
(E
));
7784 -- If no return type, probably some other error, e.g. a
7785 -- missing full declaration, so ignore.
7790 -- If the return type is generic, we have emitted a warning
7791 -- earlier on, and there is nothing else to check here. Specific
7792 -- instantiations may lead to erroneous behavior.
7794 elsif Is_Generic_Type
(Etype
(E
)) then
7797 -- Display warning if returning unconstrained array
7799 elsif Is_Array_Type
(Retype
)
7800 and then not Is_Constrained
(Retype
)
7802 -- Check appropriate warning is enabled (should we check for
7803 -- Warnings (Off) on specific entities here, probably so???)
7805 and then Warn_On_Export_Import
7808 ("?x?foreign convention function& should not return " &
7809 "unconstrained array", E
);
7814 -- If any of the formals for an exported foreign convention
7815 -- subprogram have defaults, then emit an appropriate warning since
7816 -- this is odd (default cannot be used from non-Ada code)
7818 if Is_Exported
(E
) then
7819 F
:= First_Formal
(E
);
7820 while Present
(F
) loop
7821 if Warn_On_Export_Import
7822 and then Present
(Default_Value
(F
))
7825 ("?x?parameter cannot be defaulted in non-Ada call",
7834 -- Pragma Inline_Always is disallowed for dispatching subprograms
7835 -- because the address of such subprograms is saved in the dispatch
7836 -- table to support dispatching calls, and dispatching calls cannot
7837 -- be inlined. This is consistent with the restriction against using
7838 -- 'Access or 'Address on an Inline_Always subprogram.
7840 if Is_Dispatching_Operation
(E
)
7841 and then Has_Pragma_Inline_Always
(E
)
7844 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
7847 -- Because of the implicit representation of inherited predefined
7848 -- operators in the front-end, the overriding status of the operation
7849 -- may be affected when a full view of a type is analyzed, and this is
7850 -- not captured by the analysis of the corresponding type declaration.
7851 -- Therefore the correctness of a not-overriding indicator must be
7852 -- rechecked when the subprogram is frozen.
7854 if Nkind
(E
) = N_Defining_Operator_Symbol
7855 and then not Error_Posted
(Parent
(E
))
7857 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
7859 end Freeze_Subprogram
;
7861 ----------------------
7862 -- Is_Fully_Defined --
7863 ----------------------
7865 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
7867 if Ekind
(T
) = E_Class_Wide_Type
then
7868 return Is_Fully_Defined
(Etype
(T
));
7870 elsif Is_Array_Type
(T
) then
7871 return Is_Fully_Defined
(Component_Type
(T
));
7873 elsif Is_Record_Type
(T
)
7874 and not Is_Private_Type
(T
)
7876 -- Verify that the record type has no components with private types
7877 -- without completion.
7883 Comp
:= First_Component
(T
);
7884 while Present
(Comp
) loop
7885 if not Is_Fully_Defined
(Etype
(Comp
)) then
7889 Next_Component
(Comp
);
7894 -- For the designated type of an access to subprogram, all types in
7895 -- the profile must be fully defined.
7897 elsif Ekind
(T
) = E_Subprogram_Type
then
7902 F
:= First_Formal
(T
);
7903 while Present
(F
) loop
7904 if not Is_Fully_Defined
(Etype
(F
)) then
7911 return Is_Fully_Defined
(Etype
(T
));
7915 return not Is_Private_Type
(T
)
7916 or else Present
(Full_View
(Base_Type
(T
)));
7918 end Is_Fully_Defined
;
7920 ---------------------------------
7921 -- Process_Default_Expressions --
7922 ---------------------------------
7924 procedure Process_Default_Expressions
7926 After
: in out Node_Id
)
7928 Loc
: constant Source_Ptr
:= Sloc
(E
);
7935 Set_Default_Expressions_Processed
(E
);
7937 -- A subprogram instance and its associated anonymous subprogram share
7938 -- their signature. The default expression functions are defined in the
7939 -- wrapper packages for the anonymous subprogram, and should not be
7940 -- generated again for the instance.
7942 if Is_Generic_Instance
(E
)
7943 and then Present
(Alias
(E
))
7944 and then Default_Expressions_Processed
(Alias
(E
))
7949 Formal
:= First_Formal
(E
);
7950 while Present
(Formal
) loop
7951 if Present
(Default_Value
(Formal
)) then
7953 -- We work with a copy of the default expression because we
7954 -- do not want to disturb the original, since this would mess
7955 -- up the conformance checking.
7957 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
7959 -- The analysis of the expression may generate insert actions,
7960 -- which of course must not be executed. We wrap those actions
7961 -- in a procedure that is not called, and later on eliminated.
7962 -- The following cases have no side-effects, and are analyzed
7965 if Nkind
(Dcopy
) = N_Identifier
7966 or else Nkind_In
(Dcopy
, N_Expanded_Name
,
7968 N_Character_Literal
,
7971 or else (Nkind
(Dcopy
) = N_Attribute_Reference
7972 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
7973 or else Known_Null
(Dcopy
)
7975 -- If there is no default function, we must still do a full
7976 -- analyze call on the default value, to ensure that all error
7977 -- checks are performed, e.g. those associated with static
7978 -- evaluation. Note: this branch will always be taken if the
7979 -- analyzer is turned off (but we still need the error checks).
7981 -- Note: the setting of parent here is to meet the requirement
7982 -- that we can only analyze the expression while attached to
7983 -- the tree. Really the requirement is that the parent chain
7984 -- be set, we don't actually need to be in the tree.
7986 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
7989 -- Default expressions are resolved with their own type if the
7990 -- context is generic, to avoid anomalies with private types.
7992 if Ekind
(Scope
(E
)) = E_Generic_Package
then
7995 Resolve
(Dcopy
, Etype
(Formal
));
7998 -- If that resolved expression will raise constraint error,
7999 -- then flag the default value as raising constraint error.
8000 -- This allows a proper error message on the calls.
8002 if Raises_Constraint_Error
(Dcopy
) then
8003 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
8006 -- If the default is a parameterless call, we use the name of
8007 -- the called function directly, and there is no body to build.
8009 elsif Nkind
(Dcopy
) = N_Function_Call
8010 and then No
(Parameter_Associations
(Dcopy
))
8014 -- Else construct and analyze the body of a wrapper procedure
8015 -- that contains an object declaration to hold the expression.
8016 -- Given that this is done only to complete the analysis, it
8017 -- simpler to build a procedure than a function which might
8018 -- involve secondary stack expansion.
8021 Dnam
:= Make_Temporary
(Loc
, 'D');
8024 Make_Subprogram_Body
(Loc
,
8026 Make_Procedure_Specification
(Loc
,
8027 Defining_Unit_Name
=> Dnam
),
8029 Declarations
=> New_List
(
8030 Make_Object_Declaration
(Loc
,
8031 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
8032 Object_Definition
=>
8033 New_Occurrence_Of
(Etype
(Formal
), Loc
),
8034 Expression
=> New_Copy_Tree
(Dcopy
))),
8036 Handled_Statement_Sequence
=>
8037 Make_Handled_Sequence_Of_Statements
(Loc
,
8038 Statements
=> Empty_List
));
8040 Set_Scope
(Dnam
, Scope
(E
));
8041 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
8042 Set_Is_Eliminated
(Dnam
);
8043 Insert_After
(After
, Dbody
);
8049 Next_Formal
(Formal
);
8051 end Process_Default_Expressions
;
8053 ----------------------------------------
8054 -- Set_Component_Alignment_If_Not_Set --
8055 ----------------------------------------
8057 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
8059 -- Ignore if not base type, subtypes don't need anything
8061 if Typ
/= Base_Type
(Typ
) then
8065 -- Do not override existing representation
8067 if Is_Packed
(Typ
) then
8070 elsif Has_Specified_Layout
(Typ
) then
8073 elsif Component_Alignment
(Typ
) /= Calign_Default
then
8077 Set_Component_Alignment
8078 (Typ
, Scope_Stack
.Table
8079 (Scope_Stack
.Last
).Component_Alignment_Default
);
8081 end Set_Component_Alignment_If_Not_Set
;
8083 --------------------------
8084 -- Set_SSO_From_Default --
8085 --------------------------
8087 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
8091 -- Set default SSO for an array or record base type, except in case of
8092 -- a type extension (which always inherits the SSO of its parent type).
8095 and then (Is_Array_Type
(T
)
8096 or else (Is_Record_Type
(T
)
8097 and then not (Is_Tagged_Type
(T
)
8098 and then Is_Derived_Type
(T
))))
8101 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
8103 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
8105 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
8107 -- For a record type, if bit order is specified explicitly,
8108 -- then do not set SSO from default if not consistent. Note that
8109 -- we do not want to look at a Bit_Order attribute definition
8110 -- for a parent: if we were to inherit Bit_Order, then both
8111 -- SSO_Set_*_By_Default flags would have been cleared already
8112 -- (by Inherit_Aspects_At_Freeze_Point).
8117 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
8118 and then Reverse_Bit_Order
(T
) /= Reversed
)
8120 -- If flags cause reverse storage order, then set the result. Note
8121 -- that we would have ignored the pragma setting the non default
8122 -- storage order in any case, hence the assertion at this point.
8125 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
8127 Set_Reverse_Storage_Order
(T
, Reversed
);
8129 -- For a record type, also set reversed bit order. Note: if a bit
8130 -- order has been specified explicitly, then this is a no-op.
8132 if Is_Record_Type
(T
) then
8133 Set_Reverse_Bit_Order
(T
, Reversed
);
8137 end Set_SSO_From_Default
;
8143 procedure Undelay_Type
(T
: Entity_Id
) is
8145 Set_Has_Delayed_Freeze
(T
, False);
8146 Set_Freeze_Node
(T
, Empty
);
8148 -- Since we don't want T to have a Freeze_Node, we don't want its
8149 -- Full_View or Corresponding_Record_Type to have one either.
8151 -- ??? Fundamentally, this whole handling is unpleasant. What we really
8152 -- want is to be sure that for an Itype that's part of record R and is a
8153 -- subtype of type T, that it's frozen after the later of the freeze
8154 -- points of R and T. We have no way of doing that directly, so what we
8155 -- do is force most such Itypes to be frozen as part of freezing R via
8156 -- this procedure and only delay the ones that need to be delayed
8157 -- (mostly the designated types of access types that are defined as part
8160 if Is_Private_Type
(T
)
8161 and then Present
(Full_View
(T
))
8162 and then Is_Itype
(Full_View
(T
))
8163 and then Is_Record_Type
(Scope
(Full_View
(T
)))
8165 Undelay_Type
(Full_View
(T
));
8168 if Is_Concurrent_Type
(T
)
8169 and then Present
(Corresponding_Record_Type
(T
))
8170 and then Is_Itype
(Corresponding_Record_Type
(T
))
8171 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
8173 Undelay_Type
(Corresponding_Record_Type
(T
));
8181 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Entity_Id
) is
8182 Ent
: constant Entity_Id
:= Entity
(Nam
);
8183 -- The object to which the address clause applies
8186 Old
: Entity_Id
:= Empty
;
8190 -- No warning if address clause overlay warnings are off
8192 if not Address_Clause_Overlay_Warnings
then
8196 -- No warning if there is an explicit initialization
8198 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
8200 if Present
(Init
) and then Comes_From_Source
(Init
) then
8204 -- We only give the warning for non-imported entities of a type for
8205 -- which a non-null base init proc is defined, or for objects of access
8206 -- types with implicit null initialization, or when Normalize_Scalars
8207 -- applies and the type is scalar or a string type (the latter being
8208 -- tested for because predefined String types are initialized by inline
8209 -- code rather than by an init_proc). Note that we do not give the
8210 -- warning for Initialize_Scalars, since we suppressed initialization
8211 -- in this case. Also, do not warn if Suppress_Initialization is set.
8214 and then not Is_Imported
(Ent
)
8215 and then not Initialization_Suppressed
(Typ
)
8216 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
8217 or else Is_Access_Type
(Typ
)
8218 or else (Normalize_Scalars
8219 and then (Is_Scalar_Type
(Typ
)
8220 or else Is_String_Type
(Typ
))))
8222 if Nkind
(Expr
) = N_Attribute_Reference
8223 and then Is_Entity_Name
(Prefix
(Expr
))
8225 Old
:= Entity
(Prefix
(Expr
));
8227 elsif Is_Entity_Name
(Expr
)
8228 and then Ekind
(Entity
(Expr
)) = E_Constant
8230 Decl
:= Declaration_Node
(Entity
(Expr
));
8232 if Nkind
(Decl
) = N_Object_Declaration
8233 and then Present
(Expression
(Decl
))
8234 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
8235 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
8237 Old
:= Entity
(Prefix
(Expression
(Decl
)));
8239 elsif Nkind
(Expr
) = N_Function_Call
then
8243 -- A function call (most likely to To_Address) is probably not an
8244 -- overlay, so skip warning. Ditto if the function call was inlined
8245 -- and transformed into an entity.
8247 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
8251 -- If a pragma Import follows, we assume that it is for the current
8252 -- target of the address clause, and skip the warning. There may be
8253 -- a source pragma or an aspect that specifies import and generates
8254 -- the corresponding pragma. These will indicate that the entity is
8255 -- imported and that is checked above so that the spurious warning
8256 -- (generated when the entity is frozen) will be suppressed. The
8257 -- pragma may be attached to the aspect, so it is not yet a list
8260 if Is_List_Member
(Parent
(Expr
)) then
8261 Decl
:= Next
(Parent
(Expr
));
8264 and then Nkind
(Decl
) = N_Pragma
8265 and then Pragma_Name
(Decl
) = Name_Import
8271 -- Otherwise give warning message
8273 if Present
(Old
) then
8274 Error_Msg_Node_2
:= Old
;
8276 ("default initialization of & may modify &??",
8280 ("default initialization of & may modify overlaid storage??",
8284 -- Add friendly warning if initialization comes from a packed array
8287 if Is_Record_Type
(Typ
) then
8292 Comp
:= First_Component
(Typ
);
8293 while Present
(Comp
) loop
8294 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
8295 and then Present
(Expression
(Parent
(Comp
)))
8298 elsif Is_Array_Type
(Etype
(Comp
))
8299 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
8302 ("\packed array component& " &
8303 "will be initialized to zero??",
8307 Next_Component
(Comp
);
8314 ("\use pragma Import for & to " &
8315 "suppress initialization (RM B.1(24))??",