1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Contracts
; use Contracts
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Exp_Ch3
; use Exp_Ch3
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Exp_Disp
; use Exp_Disp
;
37 with Exp_Pakd
; use Exp_Pakd
;
38 with Exp_Util
; use Exp_Util
;
39 with Exp_Tss
; use Exp_Tss
;
40 with Fname
; use Fname
;
41 with Ghost
; use Ghost
;
42 with Layout
; use Layout
;
44 with Namet
; use Namet
;
45 with Nlists
; use Nlists
;
46 with Nmake
; use Nmake
;
48 with Restrict
; use Restrict
;
49 with Rident
; use Rident
;
50 with Rtsfind
; use Rtsfind
;
52 with Sem_Aux
; use Sem_Aux
;
53 with Sem_Cat
; use Sem_Cat
;
54 with Sem_Ch6
; use Sem_Ch6
;
55 with Sem_Ch7
; use Sem_Ch7
;
56 with Sem_Ch8
; use Sem_Ch8
;
57 with Sem_Ch13
; use Sem_Ch13
;
58 with Sem_Eval
; use Sem_Eval
;
59 with Sem_Mech
; use Sem_Mech
;
60 with Sem_Prag
; use Sem_Prag
;
61 with Sem_Res
; use Sem_Res
;
62 with Sem_Util
; use Sem_Util
;
63 with Sinfo
; use Sinfo
;
64 with Snames
; use Snames
;
65 with Stand
; use Stand
;
66 with Targparm
; use Targparm
;
67 with Tbuild
; use Tbuild
;
68 with Ttypes
; use Ttypes
;
69 with Uintp
; use Uintp
;
70 with Urealp
; use Urealp
;
71 with Warnsw
; use Warnsw
;
73 package body Freeze
is
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
80 -- Typ is a type that is being frozen. If no size clause is given,
81 -- but a default Esize has been computed, then this default Esize is
82 -- adjusted up if necessary to be consistent with a given alignment,
83 -- but never to a value greater than Long_Long_Integer'Size. This
84 -- is used for all discrete types and for fixed-point types.
86 procedure Build_And_Analyze_Renamed_Body
89 After
: in out Node_Id
);
90 -- Build body for a renaming declaration, insert in tree and analyze
92 procedure Check_Address_Clause
(E
: Entity_Id
);
93 -- Apply legality checks to address clauses for object declarations,
94 -- at the point the object is frozen. Also ensure any initialization is
95 -- performed only after the object has been frozen.
97 procedure Check_Component_Storage_Order
98 (Encl_Type
: Entity_Id
;
101 Comp_ADC_Present
: out Boolean);
102 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
103 -- clause, verify that the component type has an explicit and compatible
104 -- attribute/aspect. For arrays, Comp is Empty; for records, it is the
105 -- entity of the component under consideration. For an Encl_Type that
106 -- does not have a Scalar_Storage_Order attribute definition clause,
107 -- verify that the component also does not have such a clause.
108 -- ADC is the attribute definition clause if present (or Empty). On return,
109 -- Comp_ADC_Present is set True if the component has a Scalar_Storage_Order
110 -- attribute definition clause.
112 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
113 -- As each entity is frozen, this routine is called to deal with the
114 -- setting of Debug_Info_Needed for the entity. This flag is set if
115 -- the entity comes from source, or if we are in Debug_Generated_Code
116 -- mode or if the -gnatdV debug flag is set. However, it never sets
117 -- the flag if Debug_Info_Off is set. This procedure also ensures that
118 -- subsidiary entities have the flag set as required.
120 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
);
121 -- When an expression function is frozen by a use of it, the expression
122 -- itself is frozen. Check that the expression does not include references
123 -- to deferred constants without completion. We report this at the freeze
124 -- point of the function, to provide a better error message.
126 -- In most cases the expression itself is frozen by the time the function
127 -- itself is frozen, because the formals will be frozen by then. However,
128 -- Attribute references to outer types are freeze points for those types;
129 -- this routine generates the required freeze nodes for them.
131 procedure Check_Inherited_Conditions
(R
: Entity_Id
);
132 -- For a tagged derived type, create wrappers for inherited operations
133 -- that have a class-wide condition, so it can be properly rewritten if
134 -- it involves calls to other overriding primitives.
136 procedure Check_Strict_Alignment
(E
: Entity_Id
);
137 -- E is a base type. If E is tagged or has a component that is aliased
138 -- or tagged or contains something this is aliased or tagged, set
141 procedure Check_Unsigned_Type
(E
: Entity_Id
);
142 pragma Inline
(Check_Unsigned_Type
);
143 -- If E is a fixed-point or discrete type, then all the necessary work
144 -- to freeze it is completed except for possible setting of the flag
145 -- Is_Unsigned_Type, which is done by this procedure. The call has no
146 -- effect if the entity E is not a discrete or fixed-point type.
148 procedure Freeze_And_Append
151 Result
: in out List_Id
);
152 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
153 -- nodes to Result, modifying Result from No_List if necessary. N has
154 -- the same usage as in Freeze_Entity.
156 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
157 -- Freeze enumeration type. The Esize field is set as processing
158 -- proceeds (i.e. set by default when the type is declared and then
159 -- adjusted by rep clauses. What this procedure does is to make sure
160 -- that if a foreign convention is specified, and no specific size
161 -- is given, then the size must be at least Integer'Size.
163 procedure Freeze_Static_Object
(E
: Entity_Id
);
164 -- If an object is frozen which has Is_Statically_Allocated set, then
165 -- all referenced types must also be marked with this flag. This routine
166 -- is in charge of meeting this requirement for the object entity E.
168 procedure Freeze_Subprogram
(E
: Entity_Id
);
169 -- Perform freezing actions for a subprogram (create extra formals,
170 -- and set proper default mechanism values). Note that this routine
171 -- is not called for internal subprograms, for which neither of these
172 -- actions is needed (or desirable, we do not want for example to have
173 -- these extra formals present in initialization procedures, where they
174 -- would serve no purpose). In this call E is either a subprogram or
175 -- a subprogram type (i.e. an access to a subprogram).
177 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
178 -- True if T is not private and has no private components, or has a full
179 -- view. Used to determine whether the designated type of an access type
180 -- should be frozen when the access type is frozen. This is done when an
181 -- allocator is frozen, or an expression that may involve attributes of
182 -- the designated type. Otherwise freezing the access type does not freeze
183 -- the designated type.
185 procedure Process_Default_Expressions
187 After
: in out Node_Id
);
188 -- This procedure is called for each subprogram to complete processing of
189 -- default expressions at the point where all types are known to be frozen.
190 -- The expressions must be analyzed in full, to make sure that all error
191 -- processing is done (they have only been pre-analyzed). If the expression
192 -- is not an entity or literal, its analysis may generate code which must
193 -- not be executed. In that case we build a function body to hold that
194 -- code. This wrapper function serves no other purpose (it used to be
195 -- called to evaluate the default, but now the default is inlined at each
198 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
199 -- Typ is a record or array type that is being frozen. This routine sets
200 -- the default component alignment from the scope stack values if the
201 -- alignment is otherwise not specified.
203 procedure Set_SSO_From_Default
(T
: Entity_Id
);
204 -- T is a record or array type that is being frozen. If it is a base type,
205 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
206 -- will be set appropriately. Note that an explicit occurrence of aspect
207 -- Scalar_Storage_Order or an explicit setting of this aspect with an
208 -- attribute definition clause occurs, then these two flags are reset in
209 -- any case, so call will have no effect.
211 procedure Undelay_Type
(T
: Entity_Id
);
212 -- T is a type of a component that we know to be an Itype. We don't want
213 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
214 -- Full_View or Corresponding_Record_Type.
216 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Node_Id
);
217 -- Expr is the expression for an address clause for entity Nam whose type
218 -- is Typ. If Typ has a default initialization, and there is no explicit
219 -- initialization in the source declaration, check whether the address
220 -- clause might cause overlaying of an entity, and emit a warning on the
221 -- side effect that the initialization will cause.
223 -------------------------------
224 -- Adjust_Esize_For_Alignment --
225 -------------------------------
227 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
231 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
232 Align
:= Alignment_In_Bits
(Typ
);
234 if Align
> Esize
(Typ
)
235 and then Align
<= Standard_Long_Long_Integer_Size
237 Set_Esize
(Typ
, Align
);
240 end Adjust_Esize_For_Alignment
;
242 ------------------------------------
243 -- Build_And_Analyze_Renamed_Body --
244 ------------------------------------
246 procedure Build_And_Analyze_Renamed_Body
249 After
: in out Node_Id
)
251 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
252 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
254 Renamed_Subp
: Entity_Id
;
257 -- If the renamed subprogram is intrinsic, there is no need for a
258 -- wrapper body: we set the alias that will be called and expanded which
259 -- completes the declaration. This transformation is only legal if the
260 -- renamed entity has already been elaborated.
262 -- Note that it is legal for a renaming_as_body to rename an intrinsic
263 -- subprogram, as long as the renaming occurs before the new entity
264 -- is frozen (RM 8.5.4 (5)).
266 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
267 and then Is_Entity_Name
(Name
(Body_Decl
))
269 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
271 Renamed_Subp
:= Empty
;
274 if Present
(Renamed_Subp
)
275 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
277 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
278 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
280 -- We can make the renaming entity intrinsic if the renamed function
281 -- has an interface name, or if it is one of the shift/rotate
282 -- operations known to the compiler.
285 (Present
(Interface_Name
(Renamed_Subp
))
286 or else Nam_In
(Chars
(Renamed_Subp
), Name_Rotate_Left
,
290 Name_Shift_Right_Arithmetic
))
292 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
294 if Present
(Alias
(Renamed_Subp
)) then
295 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
297 Set_Alias
(Ent
, Renamed_Subp
);
300 Set_Is_Intrinsic_Subprogram
(Ent
);
301 Set_Has_Completion
(Ent
);
304 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
305 Insert_After
(After
, Body_Node
);
306 Mark_Rewrite_Insertion
(Body_Node
);
310 end Build_And_Analyze_Renamed_Body
;
312 ------------------------
313 -- Build_Renamed_Body --
314 ------------------------
316 function Build_Renamed_Body
318 New_S
: Entity_Id
) return Node_Id
320 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
321 -- We use for the source location of the renamed body, the location of
322 -- the spec entity. It might seem more natural to use the location of
323 -- the renaming declaration itself, but that would be wrong, since then
324 -- the body we create would look as though it was created far too late,
325 -- and this could cause problems with elaboration order analysis,
326 -- particularly in connection with instantiations.
328 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
329 Nam
: constant Node_Id
:= Name
(N
);
331 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
332 Actuals
: List_Id
:= No_List
;
337 O_Formal
: Entity_Id
;
338 Param_Spec
: Node_Id
;
340 Pref
: Node_Id
:= Empty
;
341 -- If the renamed entity is a primitive operation given in prefix form,
342 -- the prefix is the target object and it has to be added as the first
343 -- actual in the generated call.
346 -- Determine the entity being renamed, which is the target of the call
347 -- statement. If the name is an explicit dereference, this is a renaming
348 -- of a subprogram type rather than a subprogram. The name itself is
351 if Nkind
(Nam
) = N_Selected_Component
then
352 Old_S
:= Entity
(Selector_Name
(Nam
));
354 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
355 Old_S
:= Etype
(Nam
);
357 elsif Nkind
(Nam
) = N_Indexed_Component
then
358 if Is_Entity_Name
(Prefix
(Nam
)) then
359 Old_S
:= Entity
(Prefix
(Nam
));
361 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
364 elsif Nkind
(Nam
) = N_Character_Literal
then
365 Old_S
:= Etype
(New_S
);
368 Old_S
:= Entity
(Nam
);
371 if Is_Entity_Name
(Nam
) then
373 -- If the renamed entity is a predefined operator, retain full name
374 -- to ensure its visibility.
376 if Ekind
(Old_S
) = E_Operator
377 and then Nkind
(Nam
) = N_Expanded_Name
379 Call_Name
:= New_Copy
(Name
(N
));
381 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
385 if Nkind
(Nam
) = N_Selected_Component
386 and then Present
(First_Formal
(Old_S
))
388 (Is_Controlling_Formal
(First_Formal
(Old_S
))
389 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
392 -- Retrieve the target object, to be added as a first actual
395 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
396 Pref
:= Prefix
(Nam
);
399 Call_Name
:= New_Copy
(Name
(N
));
402 -- Original name may have been overloaded, but is fully resolved now
404 Set_Is_Overloaded
(Call_Name
, False);
407 -- For simple renamings, subsequent calls can be expanded directly as
408 -- calls to the renamed entity. The body must be generated in any case
409 -- for calls that may appear elsewhere. This is not done in the case
410 -- where the subprogram is an instantiation because the actual proper
411 -- body has not been built yet.
413 if Ekind_In
(Old_S
, E_Function
, E_Procedure
)
414 and then Nkind
(Decl
) = N_Subprogram_Declaration
415 and then not Is_Generic_Instance
(Old_S
)
417 Set_Body_To_Inline
(Decl
, Old_S
);
420 -- Check whether the return type is a limited view. If the subprogram
421 -- is already frozen the generated body may have a non-limited view
422 -- of the type, that must be used, because it is the one in the spec
423 -- of the renaming declaration.
425 if Ekind
(Old_S
) = E_Function
426 and then Is_Entity_Name
(Result_Definition
(Spec
))
429 Ret_Type
: constant Entity_Id
:= Etype
(Result_Definition
(Spec
));
431 if Has_Non_Limited_View
(Ret_Type
) then
432 Set_Result_Definition
433 (Spec
, New_Occurrence_Of
(Non_Limited_View
(Ret_Type
), Loc
));
438 -- The body generated for this renaming is an internal artifact, and
439 -- does not constitute a freeze point for the called entity.
441 Set_Must_Not_Freeze
(Call_Name
);
443 Formal
:= First_Formal
(Defining_Entity
(Decl
));
445 if Present
(Pref
) then
447 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
448 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
451 -- The controlling formal may be an access parameter, or the
452 -- actual may be an access value, so adjust accordingly.
454 if Is_Access_Type
(Pref_Type
)
455 and then not Is_Access_Type
(Form_Type
)
458 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
460 elsif Is_Access_Type
(Form_Type
)
461 and then not Is_Access_Type
(Pref
)
465 Make_Attribute_Reference
(Loc
,
466 Attribute_Name
=> Name_Access
,
467 Prefix
=> Relocate_Node
(Pref
)));
469 Actuals
:= New_List
(Pref
);
473 elsif Present
(Formal
) then
480 if Present
(Formal
) then
481 while Present
(Formal
) loop
482 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
483 Next_Formal
(Formal
);
487 -- If the renamed entity is an entry, inherit its profile. For other
488 -- renamings as bodies, both profiles must be subtype conformant, so it
489 -- is not necessary to replace the profile given in the declaration.
490 -- However, default values that are aggregates are rewritten when
491 -- partially analyzed, so we recover the original aggregate to insure
492 -- that subsequent conformity checking works. Similarly, if the default
493 -- expression was constant-folded, recover the original expression.
495 Formal
:= First_Formal
(Defining_Entity
(Decl
));
497 if Present
(Formal
) then
498 O_Formal
:= First_Formal
(Old_S
);
499 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
500 while Present
(Formal
) loop
501 if Is_Entry
(Old_S
) then
502 if Nkind
(Parameter_Type
(Param_Spec
)) /=
505 Set_Etype
(Formal
, Etype
(O_Formal
));
506 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
509 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
510 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
511 Nkind
(Default_Value
(O_Formal
))
513 Set_Expression
(Param_Spec
,
514 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
517 Next_Formal
(Formal
);
518 Next_Formal
(O_Formal
);
523 -- If the renamed entity is a function, the generated body contains a
524 -- return statement. Otherwise, build a procedure call. If the entity is
525 -- an entry, subsequent analysis of the call will transform it into the
526 -- proper entry or protected operation call. If the renamed entity is
527 -- a character literal, return it directly.
529 if Ekind
(Old_S
) = E_Function
530 or else Ekind
(Old_S
) = E_Operator
531 or else (Ekind
(Old_S
) = E_Subprogram_Type
532 and then Etype
(Old_S
) /= Standard_Void_Type
)
535 Make_Simple_Return_Statement
(Loc
,
537 Make_Function_Call
(Loc
,
539 Parameter_Associations
=> Actuals
));
541 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
543 Make_Simple_Return_Statement
(Loc
,
544 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
546 elsif Nkind
(Nam
) = N_Character_Literal
then
548 Make_Simple_Return_Statement
(Loc
, Expression
=> Call_Name
);
552 Make_Procedure_Call_Statement
(Loc
,
554 Parameter_Associations
=> Actuals
);
557 -- Create entities for subprogram body and formals
559 Set_Defining_Unit_Name
(Spec
,
560 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
562 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
563 while Present
(Param_Spec
) loop
564 Set_Defining_Identifier
(Param_Spec
,
565 Make_Defining_Identifier
(Loc
,
566 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
571 Make_Subprogram_Body
(Loc
,
572 Specification
=> Spec
,
573 Declarations
=> New_List
,
574 Handled_Statement_Sequence
=>
575 Make_Handled_Sequence_Of_Statements
(Loc
,
576 Statements
=> New_List
(Call_Node
)));
578 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
580 Make_Subprogram_Declaration
(Loc
,
581 Specification
=> Specification
(N
)));
584 -- Link the body to the entity whose declaration it completes. If
585 -- the body is analyzed when the renamed entity is frozen, it may
586 -- be necessary to restore the proper scope (see package Exp_Ch13).
588 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
589 and then Present
(Corresponding_Spec
(N
))
591 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
593 Set_Corresponding_Spec
(Body_Node
, New_S
);
597 end Build_Renamed_Body
;
599 --------------------------
600 -- Check_Address_Clause --
601 --------------------------
603 procedure Check_Address_Clause
(E
: Entity_Id
) is
604 Addr
: constant Node_Id
:= Address_Clause
(E
);
605 Typ
: constant Entity_Id
:= Etype
(E
);
610 Tag_Assign
: Node_Id
;
613 if Present
(Addr
) then
615 -- For a deferred constant, the initialization value is on full view
617 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
618 Decl
:= Declaration_Node
(Full_View
(E
));
620 Decl
:= Declaration_Node
(E
);
623 Expr
:= Expression
(Addr
);
625 if Needs_Constant_Address
(Decl
, Typ
) then
626 Check_Constant_Address_Clause
(Expr
, E
);
628 -- Has_Delayed_Freeze was set on E when the address clause was
629 -- analyzed, and must remain set because we want the address
630 -- clause to be elaborated only after any entity it references
631 -- has been elaborated.
634 -- If Rep_Clauses are to be ignored, remove address clause from
635 -- list attached to entity, because it may be illegal for gigi,
636 -- for example by breaking order of elaboration..
638 if Ignore_Rep_Clauses
then
643 Rep
:= First_Rep_Item
(E
);
646 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
650 and then Next_Rep_Item
(Rep
) /= Addr
652 Rep
:= Next_Rep_Item
(Rep
);
656 if Present
(Rep
) then
657 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
661 -- And now remove the address clause
663 Kill_Rep_Clause
(Addr
);
665 elsif not Error_Posted
(Expr
)
666 and then not Needs_Finalization
(Typ
)
668 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
671 Init
:= Expression
(Decl
);
673 -- If a variable, or a non-imported constant, overlays a constant
674 -- object and has an initialization value, then the initialization
675 -- may end up writing into read-only memory. Detect the cases of
676 -- statically identical values and remove the initialization. In
677 -- the other cases, give a warning. We will give other warnings
678 -- later for the variable if it is assigned.
680 if (Ekind
(E
) = E_Variable
681 or else (Ekind
(E
) = E_Constant
682 and then not Is_Imported
(E
)))
683 and then Overlays_Constant
(E
)
684 and then Present
(Init
)
691 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
693 if Ekind
(O_Ent
) = E_Constant
694 and then Etype
(O_Ent
) = Typ
695 and then Present
(Constant_Value
(O_Ent
))
696 and then Compile_Time_Compare
698 Constant_Value
(O_Ent
),
699 Assume_Valid
=> True) = EQ
701 Set_No_Initialization
(Decl
);
704 elsif Comes_From_Source
(Init
)
705 and then Address_Clause_Overlay_Warnings
707 Error_Msg_Sloc
:= Sloc
(Addr
);
709 ("??constant& may be modified via address clause#",
715 if Present
(Init
) then
717 -- Capture initialization value at point of declaration,
718 -- and make explicit assignment legal, because object may
721 Remove_Side_Effects
(Init
);
722 Lhs
:= New_Occurrence_Of
(E
, Sloc
(Decl
));
723 Set_Assignment_OK
(Lhs
);
725 -- Move initialization to freeze actions, once the object has
726 -- been frozen and the address clause alignment check has been
729 Append_Freeze_Action
(E
,
730 Make_Assignment_Statement
(Sloc
(Decl
),
732 Expression
=> Expression
(Decl
)));
734 Set_No_Initialization
(Decl
);
736 -- If the objet is tagged, check whether the tag must be
737 -- reassigned explicitly.
739 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
740 if Present
(Tag_Assign
) then
741 Append_Freeze_Action
(E
, Tag_Assign
);
745 end Check_Address_Clause
;
747 -----------------------------
748 -- Check_Compile_Time_Size --
749 -----------------------------
751 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
753 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
754 -- Sets the compile time known size (64 bits or less) in the RM_Size
755 -- field of T, checking for a size clause that was given which attempts
756 -- to give a smaller size.
758 function Size_Known
(T
: Entity_Id
) return Boolean;
759 -- Recursive function that does all the work
761 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
762 -- If T is a constrained subtype, its size is not known if any of its
763 -- discriminant constraints is not static and it is not a null record.
764 -- The test is conservative and doesn't check that the components are
765 -- in fact constrained by non-static discriminant values. Could be made
772 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
777 -- Check for bad size clause given
779 elsif Has_Size_Clause
(T
) then
780 if RM_Size
(T
) < S
then
781 Error_Msg_Uint_1
:= S
;
783 ("size for& too small, minimum allowed is ^",
787 -- Set size if not set already
789 elsif Unknown_RM_Size
(T
) then
798 function Size_Known
(T
: Entity_Id
) return Boolean is
806 if Size_Known_At_Compile_Time
(T
) then
809 -- Always True for elementary types, even generic formal elementary
810 -- types. We used to return False in the latter case, but the size
811 -- is known at compile time, even in the template, we just do not
812 -- know the exact size but that's not the point of this routine.
814 elsif Is_Elementary_Type
(T
) or else Is_Task_Type
(T
) then
819 elsif Is_Array_Type
(T
) then
821 -- String literals always have known size, and we can set it
823 if Ekind
(T
) = E_String_Literal_Subtype
then
825 (T
, Component_Size
(T
) * String_Literal_Length
(T
));
828 -- Unconstrained types never have known at compile time size
830 elsif not Is_Constrained
(T
) then
833 -- Don't do any recursion on type with error posted, since we may
834 -- have a malformed type that leads us into a loop.
836 elsif Error_Posted
(T
) then
839 -- Otherwise if component size unknown, then array size unknown
841 elsif not Size_Known
(Component_Type
(T
)) then
845 -- Check for all indexes static, and also compute possible size
846 -- (in case it is not greater than 64 and may be packable).
849 Size
: Uint
:= Component_Size
(T
);
853 Index
:= First_Index
(T
);
854 while Present
(Index
) loop
855 if Nkind
(Index
) = N_Range
then
856 Get_Index_Bounds
(Index
, Low
, High
);
858 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
862 Low
:= Type_Low_Bound
(Etype
(Index
));
863 High
:= Type_High_Bound
(Etype
(Index
));
866 if not Compile_Time_Known_Value
(Low
)
867 or else not Compile_Time_Known_Value
(High
)
868 or else Etype
(Index
) = Any_Type
873 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
885 Set_Small_Size
(T
, Size
);
889 -- For non-generic private types, go to underlying type if present
891 elsif Is_Private_Type
(T
)
892 and then not Is_Generic_Type
(T
)
893 and then Present
(Underlying_Type
(T
))
895 -- Don't do any recursion on type with error posted, since we may
896 -- have a malformed type that leads us into a loop.
898 if Error_Posted
(T
) then
901 return Size_Known
(Underlying_Type
(T
));
906 elsif Is_Record_Type
(T
) then
908 -- A class-wide type is never considered to have a known size
910 if Is_Class_Wide_Type
(T
) then
913 -- A subtype of a variant record must not have non-static
914 -- discriminated components.
916 elsif T
/= Base_Type
(T
)
917 and then not Static_Discriminated_Components
(T
)
921 -- Don't do any recursion on type with error posted, since we may
922 -- have a malformed type that leads us into a loop.
924 elsif Error_Posted
(T
) then
928 -- Now look at the components of the record
931 -- The following two variables are used to keep track of the
932 -- size of packed records if we can tell the size of the packed
933 -- record in the front end. Packed_Size_Known is True if so far
934 -- we can figure out the size. It is initialized to True for a
935 -- packed record, unless the record has discriminants or atomic
936 -- components or independent components.
938 -- The reason we eliminate the discriminated case is that
939 -- we don't know the way the back end lays out discriminated
940 -- packed records. If Packed_Size_Known is True, then
941 -- Packed_Size is the size in bits so far.
943 Packed_Size_Known
: Boolean :=
945 and then not Has_Discriminants
(T
)
946 and then not Has_Atomic_Components
(T
)
947 and then not Has_Independent_Components
(T
);
949 Packed_Size
: Uint
:= Uint_0
;
950 -- Size in bits so far
953 -- Test for variant part present
955 if Has_Discriminants
(T
)
956 and then Present
(Parent
(T
))
957 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
958 and then Nkind
(Type_Definition
(Parent
(T
))) =
960 and then not Null_Present
(Type_Definition
(Parent
(T
)))
962 Present
(Variant_Part
963 (Component_List
(Type_Definition
(Parent
(T
)))))
965 -- If variant part is present, and type is unconstrained,
966 -- then we must have defaulted discriminants, or a size
967 -- clause must be present for the type, or else the size
968 -- is definitely not known at compile time.
970 if not Is_Constrained
(T
)
972 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
973 and then Unknown_RM_Size
(T
)
979 -- Loop through components
981 Comp
:= First_Component_Or_Discriminant
(T
);
982 while Present
(Comp
) loop
983 Ctyp
:= Etype
(Comp
);
985 -- We do not know the packed size if there is a component
986 -- clause present (we possibly could, but this would only
987 -- help in the case of a record with partial rep clauses.
988 -- That's because in the case of full rep clauses, the
989 -- size gets figured out anyway by a different circuit).
991 if Present
(Component_Clause
(Comp
)) then
992 Packed_Size_Known
:= False;
995 -- We do not know the packed size for an atomic/VFA type
996 -- or component, or an independent type or component, or a
997 -- by-reference type or aliased component (because packing
998 -- does not touch these).
1000 if Is_Atomic_Or_VFA
(Ctyp
)
1001 or else Is_Atomic_Or_VFA
(Comp
)
1002 or else Is_Independent
(Ctyp
)
1003 or else Is_Independent
(Comp
)
1004 or else Is_By_Reference_Type
(Ctyp
)
1005 or else Is_Aliased
(Comp
)
1007 Packed_Size_Known
:= False;
1010 -- We need to identify a component that is an array where
1011 -- the index type is an enumeration type with non-standard
1012 -- representation, and some bound of the type depends on a
1015 -- This is because gigi computes the size by doing a
1016 -- substitution of the appropriate discriminant value in
1017 -- the size expression for the base type, and gigi is not
1018 -- clever enough to evaluate the resulting expression (which
1019 -- involves a call to rep_to_pos) at compile time.
1021 -- It would be nice if gigi would either recognize that
1022 -- this expression can be computed at compile time, or
1023 -- alternatively figured out the size from the subtype
1024 -- directly, where all the information is at hand ???
1026 if Is_Array_Type
(Etype
(Comp
))
1027 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
1030 Ocomp
: constant Entity_Id
:=
1031 Original_Record_Component
(Comp
);
1032 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
1038 Ind
:= First_Index
(OCtyp
);
1039 while Present
(Ind
) loop
1040 Indtyp
:= Etype
(Ind
);
1042 if Is_Enumeration_Type
(Indtyp
)
1043 and then Has_Non_Standard_Rep
(Indtyp
)
1045 Lo
:= Type_Low_Bound
(Indtyp
);
1046 Hi
:= Type_High_Bound
(Indtyp
);
1048 if Is_Entity_Name
(Lo
)
1049 and then Ekind
(Entity
(Lo
)) = E_Discriminant
1053 elsif Is_Entity_Name
(Hi
)
1054 and then Ekind
(Entity
(Hi
)) = E_Discriminant
1065 -- Clearly size of record is not known if the size of one of
1066 -- the components is not known.
1068 if not Size_Known
(Ctyp
) then
1072 -- Accumulate packed size if possible
1074 if Packed_Size_Known
then
1076 -- We can deal with elementary types, small packed arrays
1077 -- if the representation is a modular type and also small
1078 -- record types (if the size is not greater than 64, but
1079 -- the condition is checked by Set_Small_Size).
1081 if Is_Elementary_Type
(Ctyp
)
1082 or else (Is_Array_Type
(Ctyp
)
1084 (Packed_Array_Impl_Type
(Ctyp
))
1085 and then Is_Modular_Integer_Type
1086 (Packed_Array_Impl_Type
(Ctyp
)))
1087 or else Is_Record_Type
(Ctyp
)
1089 -- If RM_Size is known and static, then we can keep
1090 -- accumulating the packed size.
1092 if Known_Static_RM_Size
(Ctyp
) then
1094 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1096 -- If we have a field whose RM_Size is not known then
1097 -- we can't figure out the packed size here.
1100 Packed_Size_Known
:= False;
1103 -- For other types we can't figure out the packed size
1106 Packed_Size_Known
:= False;
1110 Next_Component_Or_Discriminant
(Comp
);
1113 if Packed_Size_Known
then
1114 Set_Small_Size
(T
, Packed_Size
);
1120 -- All other cases, size not known at compile time
1127 -------------------------------------
1128 -- Static_Discriminated_Components --
1129 -------------------------------------
1131 function Static_Discriminated_Components
1132 (T
: Entity_Id
) return Boolean
1134 Constraint
: Elmt_Id
;
1137 if Has_Discriminants
(T
)
1138 and then Present
(Discriminant_Constraint
(T
))
1139 and then Present
(First_Component
(T
))
1141 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1142 while Present
(Constraint
) loop
1143 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1147 Next_Elmt
(Constraint
);
1152 end Static_Discriminated_Components
;
1154 -- Start of processing for Check_Compile_Time_Size
1157 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1158 end Check_Compile_Time_Size
;
1160 -----------------------------------
1161 -- Check_Component_Storage_Order --
1162 -----------------------------------
1164 procedure Check_Component_Storage_Order
1165 (Encl_Type
: Entity_Id
;
1168 Comp_ADC_Present
: out Boolean)
1170 Comp_Base
: Entity_Id
;
1172 Encl_Base
: Entity_Id
;
1175 Component_Aliased
: Boolean;
1177 Comp_Byte_Aligned
: Boolean;
1178 -- Set for the record case, True if Comp starts on a byte boundary
1179 -- (in which case it is allowed to have different storage order).
1181 Comp_SSO_Differs
: Boolean;
1182 -- Set True when the component is a nested composite, and it does not
1183 -- have the same scalar storage order as Encl_Type.
1188 if Present
(Comp
) then
1190 Comp_Base
:= Etype
(Comp
);
1192 if Is_Tag
(Comp
) then
1193 Comp_Byte_Aligned
:= True;
1194 Component_Aliased
:= False;
1197 -- If a component clause is present, check if the component starts
1198 -- on a storage element boundary. Otherwise conservatively assume
1199 -- it does so only in the case where the record is not packed.
1201 if Present
(Component_Clause
(Comp
)) then
1202 Comp_Byte_Aligned
:=
1203 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1205 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1208 Component_Aliased
:= Is_Aliased
(Comp
);
1214 Err_Node
:= Encl_Type
;
1215 Comp_Base
:= Component_Type
(Encl_Type
);
1217 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1220 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1221 -- the attribute definition clause is attached to the first subtype.
1222 -- Also, if the base type is incomplete or private, go to full view
1225 Encl_Base
:= Base_Type
(Encl_Type
);
1226 if Present
(Underlying_Type
(Encl_Base
)) then
1227 Encl_Base
:= Underlying_Type
(Encl_Base
);
1230 Comp_Base
:= Base_Type
(Comp_Base
);
1231 if Present
(Underlying_Type
(Comp_Base
)) then
1232 Comp_Base
:= Underlying_Type
(Comp_Base
);
1236 Get_Attribute_Definition_Clause
1237 (First_Subtype
(Comp_Base
), Attribute_Scalar_Storage_Order
);
1238 Comp_ADC_Present
:= Present
(Comp_ADC
);
1240 -- Case of record or array component: check storage order compatibility.
1241 -- But, if the record has Complex_Representation, then it is treated as
1242 -- a scalar in the back end so the storage order is irrelevant.
1244 if (Is_Record_Type
(Comp_Base
)
1245 and then not Has_Complex_Representation
(Comp_Base
))
1246 or else Is_Array_Type
(Comp_Base
)
1249 Reverse_Storage_Order
(Encl_Base
) /=
1250 Reverse_Storage_Order
(Comp_Base
);
1252 -- Parent and extension must have same storage order
1254 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1255 if Comp_SSO_Differs
then
1257 ("record extension must have same scalar storage order as "
1258 & "parent", Err_Node
);
1261 -- If component and composite SSO differs, check that component
1262 -- falls on byte boundaries and isn't bit packed.
1264 elsif Comp_SSO_Differs
then
1266 -- Component SSO differs from enclosing composite:
1268 -- Reject if component is a bit-packed array, as it is represented
1269 -- as a scalar internally.
1271 if Is_Bit_Packed_Array
(Comp_Base
) then
1273 ("type of packed component must have same scalar storage "
1274 & "order as enclosing composite", Err_Node
);
1276 -- Reject if composite is a bit-packed array, as it is rewritten
1277 -- into an array of scalars.
1279 elsif Is_Bit_Packed_Array
(Encl_Base
) then
1281 ("type of packed array must have same scalar storage order "
1282 & "as component", Err_Node
);
1284 -- Reject if not byte aligned
1286 elsif Is_Record_Type
(Encl_Base
)
1287 and then not Comp_Byte_Aligned
1290 ("type of non-byte-aligned component must have same scalar "
1291 & "storage order as enclosing composite", Err_Node
);
1293 -- Warn if specified only for the outer composite
1295 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1297 ("scalar storage order specified for & does not apply to "
1298 & "component?", Err_Node
, Encl_Base
);
1302 -- Enclosing type has explicit SSO: non-composite component must not
1305 elsif Present
(ADC
) and then Component_Aliased
then
1307 ("aliased component not permitted for type with explicit "
1308 & "Scalar_Storage_Order", Err_Node
);
1310 end Check_Component_Storage_Order
;
1312 -----------------------------
1313 -- Check_Debug_Info_Needed --
1314 -----------------------------
1316 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1318 if Debug_Info_Off
(T
) then
1321 elsif Comes_From_Source
(T
)
1322 or else Debug_Generated_Code
1323 or else Debug_Flag_VV
1324 or else Needs_Debug_Info
(T
)
1326 Set_Debug_Info_Needed
(T
);
1328 end Check_Debug_Info_Needed
;
1330 -------------------------------
1331 -- Check_Expression_Function --
1332 -------------------------------
1334 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1335 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1336 -- Function to search for deferred constant
1342 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1344 -- When a constant is initialized with the result of a dispatching
1345 -- call, the constant declaration is rewritten as a renaming of the
1346 -- displaced function result. This scenario is not a premature use of
1347 -- a constant even though the Has_Completion flag is not set.
1349 if Is_Entity_Name
(Nod
)
1350 and then Present
(Entity
(Nod
))
1351 and then Ekind
(Entity
(Nod
)) = E_Constant
1352 and then Scope
(Entity
(Nod
)) = Current_Scope
1353 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1354 N_Object_Declaration
1355 and then not Is_Imported
(Entity
(Nod
))
1356 and then not Has_Completion
(Entity
(Nod
))
1357 and then not Is_Frozen
(Entity
(Nod
))
1360 ("premature use of& in call or instance", N
, Entity
(Nod
));
1362 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1363 Analyze
(Prefix
(Nod
));
1365 if Is_Entity_Name
(Prefix
(Nod
))
1366 and then Is_Type
(Entity
(Prefix
(Nod
)))
1368 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1375 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1381 -- Start of processing for Check_Expression_Function
1384 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1386 if Scope
(Nam
) = Current_Scope
1387 and then Nkind
(Decl
) = N_Expression_Function
1389 Check_Deferred
(Expression
(Decl
));
1391 end Check_Expression_Function
;
1393 --------------------------------
1394 -- Check_Inherited_Conditions --
1395 --------------------------------
1397 procedure Check_Inherited_Conditions
(R
: Entity_Id
) is
1398 Prim_Ops
: constant Elist_Id
:= Primitive_Operations
(R
);
1402 Par_Prim
: Entity_Id
;
1406 Op_Node
:= First_Elmt
(Prim_Ops
);
1407 while Present
(Op_Node
) loop
1408 Prim
:= Node
(Op_Node
);
1410 -- Map the overridden primitive to the overriding one. This takes
1411 -- care of all overridings and is done only once.
1413 if Present
(Overridden_Operation
(Prim
))
1414 and then Comes_From_Source
(Prim
)
1416 Update_Primitives_Mapping
(Overridden_Operation
(Prim
), Prim
);
1418 -- In SPARK mode this is where we can collect the inherited
1419 -- conditions, because we do not create the Check pragmas that
1420 -- normally convey the the modified class-wide conditions on
1421 -- overriding operations.
1423 if SPARK_Mode
= On
then
1425 -- Analyze the contract items of the parent operation, before
1426 -- they are rewritten when inherited.
1428 Analyze_Entry_Or_Subprogram_Contract
1429 (Overridden_Operation
(Prim
));
1431 -- Now verify the legality of inherited contracts for LSP
1434 Collect_Inherited_Class_Wide_Conditions
(Prim
);
1438 Next_Elmt
(Op_Node
);
1441 -- In all cases, we examine inherited operations to check whether they
1442 -- require a wrapper to handle inherited conditions that call other
1443 -- primitives, so that LSP can be verified/enforced.
1445 -- Wrapper construction TBD.
1447 Op_Node
:= First_Elmt
(Prim_Ops
);
1448 while Present
(Op_Node
) loop
1449 Prim
:= Node
(Op_Node
);
1450 if not Comes_From_Source
(Prim
) and then Present
(Alias
(Prim
)) then
1451 Par_Prim
:= Alias
(Prim
);
1453 -- Analyze the contract items of the parent operation, before
1454 -- they are rewritten when inherited.
1456 Analyze_Entry_Or_Subprogram_Contract
(Par_Prim
);
1458 A_Pre
:= Get_Pragma
(Par_Prim
, Pragma_Precondition
);
1460 if Present
(A_Pre
) and then Class_Present
(A_Pre
) then
1461 Build_Class_Wide_Expression
1462 (Prag
=> New_Copy_Tree
(A_Pre
),
1464 Par_Subp
=> Par_Prim
,
1465 Adjust_Sloc
=> False);
1468 A_Post
:= Get_Pragma
(Par_Prim
, Pragma_Postcondition
);
1470 if Present
(A_Post
) and then Class_Present
(A_Post
) then
1471 Build_Class_Wide_Expression
1472 (Prag
=> New_Copy_Tree
(A_Post
),
1474 Par_Subp
=> Par_Prim
,
1475 Adjust_Sloc
=> False);
1479 Next_Elmt
(Op_Node
);
1481 end Check_Inherited_Conditions
;
1483 ----------------------------
1484 -- Check_Strict_Alignment --
1485 ----------------------------
1487 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1491 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1492 Set_Strict_Alignment
(E
);
1494 elsif Is_Array_Type
(E
) then
1495 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1497 elsif Is_Record_Type
(E
) then
1498 if Is_Limited_Record
(E
) then
1499 Set_Strict_Alignment
(E
);
1503 Comp
:= First_Component
(E
);
1504 while Present
(Comp
) loop
1505 if not Is_Type
(Comp
)
1506 and then (Strict_Alignment
(Etype
(Comp
))
1507 or else Is_Aliased
(Comp
))
1509 Set_Strict_Alignment
(E
);
1513 Next_Component
(Comp
);
1516 end Check_Strict_Alignment
;
1518 -------------------------
1519 -- Check_Unsigned_Type --
1520 -------------------------
1522 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1523 Ancestor
: Entity_Id
;
1528 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1532 -- Do not attempt to analyze case where range was in error
1534 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
1538 -- The situation that is nontrivial is something like:
1540 -- subtype x1 is integer range -10 .. +10;
1541 -- subtype x2 is x1 range 0 .. V1;
1542 -- subtype x3 is x2 range V2 .. V3;
1543 -- subtype x4 is x3 range V4 .. V5;
1545 -- where Vn are variables. Here the base type is signed, but we still
1546 -- know that x4 is unsigned because of the lower bound of x2.
1548 -- The only way to deal with this is to look up the ancestor chain
1552 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1556 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1558 if Compile_Time_Known_Value
(Lo_Bound
) then
1559 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1560 Set_Is_Unsigned_Type
(E
, True);
1566 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1568 -- If no ancestor had a static lower bound, go to base type
1570 if No
(Ancestor
) then
1572 -- Note: the reason we still check for a compile time known
1573 -- value for the base type is that at least in the case of
1574 -- generic formals, we can have bounds that fail this test,
1575 -- and there may be other cases in error situations.
1577 Btyp
:= Base_Type
(E
);
1579 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1583 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1585 if Compile_Time_Known_Value
(Lo_Bound
)
1586 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1588 Set_Is_Unsigned_Type
(E
, True);
1595 end Check_Unsigned_Type
;
1597 -----------------------------
1598 -- Is_Atomic_VFA_Aggregate --
1599 -----------------------------
1601 function Is_Atomic_VFA_Aggregate
(N
: Node_Id
) return Boolean is
1602 Loc
: constant Source_Ptr
:= Sloc
(N
);
1611 -- Array may be qualified, so find outer context
1613 if Nkind
(Par
) = N_Qualified_Expression
then
1614 Par
:= Parent
(Par
);
1617 if not Comes_From_Source
(Par
) then
1622 when N_Assignment_Statement
=>
1623 Typ
:= Etype
(Name
(Par
));
1625 if not Is_Atomic_Or_VFA
(Typ
)
1626 and then not (Is_Entity_Name
(Name
(Par
))
1627 and then Is_Atomic_Or_VFA
(Entity
(Name
(Par
))))
1632 when N_Object_Declaration
=>
1633 Typ
:= Etype
(Defining_Identifier
(Par
));
1635 if not Is_Atomic_Or_VFA
(Typ
)
1636 and then not Is_Atomic_Or_VFA
(Defining_Identifier
(Par
))
1645 Temp
:= Make_Temporary
(Loc
, 'T', N
);
1647 Make_Object_Declaration
(Loc
,
1648 Defining_Identifier
=> Temp
,
1649 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1650 Expression
=> Relocate_Node
(N
));
1651 Insert_Before
(Par
, New_N
);
1654 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1656 end Is_Atomic_VFA_Aggregate
;
1658 -----------------------------------------------
1659 -- Explode_Initialization_Compound_Statement --
1660 -----------------------------------------------
1662 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
1663 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
1666 if Present
(Init_Stmts
)
1667 and then Nkind
(Init_Stmts
) = N_Compound_Statement
1669 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
1671 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
1672 -- just removing it, because Freeze_All may rely on this particular
1673 -- Node_Id still being present in the enclosing list to know where to
1676 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
1678 Set_Initialization_Statements
(E
, Empty
);
1680 end Explode_Initialization_Compound_Statement
;
1686 -- Note: the easy coding for this procedure would be to just build a
1687 -- single list of freeze nodes and then insert them and analyze them
1688 -- all at once. This won't work, because the analysis of earlier freeze
1689 -- nodes may recursively freeze types which would otherwise appear later
1690 -- on in the freeze list. So we must analyze and expand the freeze nodes
1691 -- as they are generated.
1693 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1694 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1695 -- This is the internal recursive routine that does freezing of entities
1696 -- (but NOT the analysis of default expressions, which should not be
1697 -- recursive, we don't want to analyze those till we are sure that ALL
1698 -- the types are frozen).
1700 --------------------
1701 -- Freeze_All_Ent --
1702 --------------------
1704 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1709 procedure Process_Flist
;
1710 -- If freeze nodes are present, insert and analyze, and reset cursor
1711 -- for next insertion.
1717 procedure Process_Flist
is
1719 if Is_Non_Empty_List
(Flist
) then
1720 Lastn
:= Next
(After
);
1721 Insert_List_After_And_Analyze
(After
, Flist
);
1723 if Present
(Lastn
) then
1724 After
:= Prev
(Lastn
);
1726 After
:= Last
(List_Containing
(After
));
1731 -- Start of processing for Freeze_All_Ent
1735 while Present
(E
) loop
1737 -- If the entity is an inner package which is not a package
1738 -- renaming, then its entities must be frozen at this point. Note
1739 -- that such entities do NOT get frozen at the end of the nested
1740 -- package itself (only library packages freeze).
1742 -- Same is true for task declarations, where anonymous records
1743 -- created for entry parameters must be frozen.
1745 if Ekind
(E
) = E_Package
1746 and then No
(Renamed_Object
(E
))
1747 and then not Is_Child_Unit
(E
)
1748 and then not Is_Frozen
(E
)
1752 Install_Visible_Declarations
(E
);
1753 Install_Private_Declarations
(E
);
1754 Freeze_All
(First_Entity
(E
), After
);
1756 End_Package_Scope
(E
);
1758 if Is_Generic_Instance
(E
)
1759 and then Has_Delayed_Freeze
(E
)
1761 Set_Has_Delayed_Freeze
(E
, False);
1762 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1765 elsif Ekind
(E
) in Task_Kind
1766 and then Nkind_In
(Parent
(E
), N_Single_Task_Declaration
,
1767 N_Task_Type_Declaration
)
1770 Freeze_All
(First_Entity
(E
), After
);
1773 -- For a derived tagged type, we must ensure that all the
1774 -- primitive operations of the parent have been frozen, so that
1775 -- their addresses will be in the parent's dispatch table at the
1776 -- point it is inherited.
1778 elsif Ekind
(E
) = E_Record_Type
1779 and then Is_Tagged_Type
(E
)
1780 and then Is_Tagged_Type
(Etype
(E
))
1781 and then Is_Derived_Type
(E
)
1784 Prim_List
: constant Elist_Id
:=
1785 Primitive_Operations
(Etype
(E
));
1791 Prim
:= First_Elmt
(Prim_List
);
1792 while Present
(Prim
) loop
1793 Subp
:= Node
(Prim
);
1795 if Comes_From_Source
(Subp
)
1796 and then not Is_Frozen
(Subp
)
1798 Flist
:= Freeze_Entity
(Subp
, After
);
1807 if not Is_Frozen
(E
) then
1808 Flist
:= Freeze_Entity
(E
, After
);
1811 -- If already frozen, and there are delayed aspects, this is where
1812 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1813 -- for a description of how we handle aspect visibility).
1815 elsif Has_Delayed_Aspects
(E
) then
1817 -- Retrieve the visibility to the discriminants in order to
1818 -- analyze properly the aspects.
1820 Push_Scope_And_Install_Discriminants
(E
);
1826 Ritem
:= First_Rep_Item
(E
);
1827 while Present
(Ritem
) loop
1828 if Nkind
(Ritem
) = N_Aspect_Specification
1829 and then Entity
(Ritem
) = E
1830 and then Is_Delayed_Aspect
(Ritem
)
1832 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1835 Ritem
:= Next_Rep_Item
(Ritem
);
1839 Uninstall_Discriminants_And_Pop_Scope
(E
);
1842 -- If an incomplete type is still not frozen, this may be a
1843 -- premature freezing because of a body declaration that follows.
1844 -- Indicate where the freezing took place. Freezing will happen
1845 -- if the body comes from source, but not if it is internally
1846 -- generated, for example as the body of a type invariant.
1848 -- If the freezing is caused by the end of the current declarative
1849 -- part, it is a Taft Amendment type, and there is no error.
1851 if not Is_Frozen
(E
)
1852 and then Ekind
(E
) = E_Incomplete_Type
1855 Bod
: constant Node_Id
:= Next
(After
);
1858 -- The presence of a body freezes all entities previously
1859 -- declared in the current list of declarations, but this
1860 -- does not apply if the body does not come from source.
1861 -- A type invariant is transformed into a subprogram body
1862 -- which is placed at the end of the private part of the
1863 -- current package, but this body does not freeze incomplete
1864 -- types that may be declared in this private part.
1866 if (Nkind_In
(Bod
, N_Entry_Body
,
1871 or else Nkind
(Bod
) in N_Body_Stub
)
1873 List_Containing
(After
) = List_Containing
(Parent
(E
))
1874 and then Comes_From_Source
(Bod
)
1876 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1878 ("type& is frozen# before its full declaration",
1894 -- Start of processing for Freeze_All
1897 Freeze_All_Ent
(From
, After
);
1899 -- Now that all types are frozen, we can deal with default expressions
1900 -- that require us to build a default expression functions. This is the
1901 -- point at which such functions are constructed (after all types that
1902 -- might be used in such expressions have been frozen).
1904 -- For subprograms that are renaming_as_body, we create the wrapper
1905 -- bodies as needed.
1907 -- We also add finalization chains to access types whose designated
1908 -- types are controlled. This is normally done when freezing the type,
1909 -- but this misses recursive type definitions where the later members
1910 -- of the recursion introduce controlled components.
1912 -- Loop through entities
1915 while Present
(E
) loop
1916 if Is_Subprogram
(E
) then
1917 if not Default_Expressions_Processed
(E
) then
1918 Process_Default_Expressions
(E
, After
);
1921 if not Has_Completion
(E
) then
1922 Decl
:= Unit_Declaration_Node
(E
);
1924 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1925 if Error_Posted
(Decl
) then
1926 Set_Has_Completion
(E
);
1928 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1931 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1932 and then Present
(Corresponding_Body
(Decl
))
1934 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
1935 N_Subprogram_Renaming_Declaration
1937 Build_And_Analyze_Renamed_Body
1938 (Decl
, Corresponding_Body
(Decl
), After
);
1942 -- Freeze the default expressions of entries, entry families, and
1943 -- protected subprograms.
1945 elsif Is_Concurrent_Type
(E
) then
1946 Item
:= First_Entity
(E
);
1947 while Present
(Item
) loop
1948 if (Is_Entry
(Item
) or else Is_Subprogram
(Item
))
1949 and then not Default_Expressions_Processed
(Item
)
1951 Process_Default_Expressions
(Item
, After
);
1958 -- Historical note: We used to create a finalization master for an
1959 -- access type whose designated type is not controlled, but contains
1960 -- private controlled compoments. This form of postprocessing is no
1961 -- longer needed because the finalization master is now created when
1962 -- the access type is frozen (see Exp_Ch3.Freeze_Type).
1968 -----------------------
1969 -- Freeze_And_Append --
1970 -----------------------
1972 procedure Freeze_And_Append
1975 Result
: in out List_Id
)
1977 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1979 if Is_Non_Empty_List
(L
) then
1980 if Result
= No_List
then
1983 Append_List
(L
, Result
);
1986 end Freeze_And_Append
;
1992 procedure Freeze_Before
1995 Do_Freeze_Profile
: Boolean := True)
1997 -- Freeze T, then insert the generated Freeze nodes before the node N.
1998 -- Flag Freeze_Profile is used when T is an overloadable entity, and
1999 -- indicates whether its profile should be frozen at the same time.
2001 Freeze_Nodes
: constant List_Id
:=
2002 Freeze_Entity
(T
, N
, Do_Freeze_Profile
);
2005 if Ekind
(T
) = E_Function
then
2006 Check_Expression_Function
(N
, T
);
2009 if Is_Non_Empty_List
(Freeze_Nodes
) then
2010 Insert_Actions
(N
, Freeze_Nodes
);
2018 -- WARNING: This routine manages Ghost regions. Return statements must be
2019 -- replaced by gotos which jump to the end of the routine and restore the
2022 function Freeze_Entity
2025 Do_Freeze_Profile
: Boolean := True) return List_Id
2027 Loc
: constant Source_Ptr
:= Sloc
(N
);
2034 Has_Default_Initialization
: Boolean := False;
2035 -- This flag gets set to true for a variable with default initialization
2037 Result
: List_Id
:= No_List
;
2038 -- List of freezing actions, left at No_List if none
2040 Test_E
: Entity_Id
:= E
;
2041 -- This could use a comment ???
2043 procedure Add_To_Result
(N
: Node_Id
);
2044 -- N is a freezing action to be appended to the Result
2046 function After_Last_Declaration
return Boolean;
2047 -- If Loc is a freeze_entity that appears after the last declaration
2048 -- in the scope, inhibit error messages on late completion.
2050 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
2051 -- Check that an Access or Unchecked_Access attribute with a prefix
2052 -- which is the current instance type can only be applied when the type
2055 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
);
2056 -- Give a warning for pragma Convention with language C or C++ applied
2057 -- to a discriminated record type. This is suppressed for the unchecked
2058 -- union case, since the whole point in this case is interface C. We
2059 -- also do not generate this within instantiations, since we will have
2060 -- generated a message on the template.
2062 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
2063 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
2064 -- integer literal without an explicit corresponding size clause. The
2065 -- caller has checked that Utype is a modular integer type.
2067 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
2068 -- Freeze array type, including freezing index and component types
2070 procedure Freeze_Object_Declaration
(E
: Entity_Id
);
2071 -- Perform checks and generate freeze node if needed for a constant or
2072 -- variable declared by an object declaration.
2074 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
2075 -- Create Freeze_Generic_Entity nodes for types declared in a generic
2076 -- package. Recurse on inner generic packages.
2078 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
2079 -- Freeze formals and return type of subprogram. If some type in the
2080 -- profile is incomplete and we are in an instance, freezing of the
2081 -- entity will take place elsewhere, and the function returns False.
2083 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
2084 -- Freeze record type, including freezing component types, and freezing
2085 -- primitive operations if this is a tagged type.
2087 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
2088 -- Determine whether an arbitrary entity is subject to Boolean aspect
2089 -- Import and its value is specified as True.
2091 procedure Inherit_Freeze_Node
2094 -- Set type Typ's freeze node to refer to Fnode. This routine ensures
2095 -- that any attributes attached to Typ's original node are preserved.
2097 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
2098 -- If E is an entity for an imported subprogram with pre/post-conditions
2099 -- then this procedure will create a wrapper to ensure that proper run-
2100 -- time checking of the pre/postconditions. See body for details.
2106 procedure Add_To_Result
(N
: Node_Id
) is
2109 Result
:= New_List
(N
);
2115 ----------------------------
2116 -- After_Last_Declaration --
2117 ----------------------------
2119 function After_Last_Declaration
return Boolean is
2120 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
2123 if Nkind
(Spec
) = N_Package_Specification
then
2124 if Present
(Private_Declarations
(Spec
)) then
2125 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
2126 elsif Present
(Visible_Declarations
(Spec
)) then
2127 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
2135 end After_Last_Declaration
;
2137 ----------------------------
2138 -- Check_Current_Instance --
2139 ----------------------------
2141 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
2143 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
2144 -- Determine whether Typ is compatible with the rules for aliased
2145 -- views of types as defined in RM 3.10 in the various dialects.
2147 function Process
(N
: Node_Id
) return Traverse_Result
;
2148 -- Process routine to apply check to given node
2150 -----------------------------
2151 -- Is_Aliased_View_Of_Type --
2152 -----------------------------
2154 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
2155 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
2160 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
2161 and then Limited_Present
(Type_Definition
(Typ_Decl
))
2165 -- The following paragraphs describe what a legal aliased view of
2166 -- a type is in the various dialects of Ada.
2170 -- The current instance of a limited type, and a formal parameter
2171 -- or generic formal object of a tagged type.
2173 -- Ada 95 limited type
2174 -- * Type with reserved word "limited"
2175 -- * A protected or task type
2176 -- * A composite type with limited component
2178 elsif Ada_Version
<= Ada_95
then
2179 return Is_Limited_Type
(Typ
);
2183 -- The current instance of a limited tagged type, a protected
2184 -- type, a task type, or a type that has the reserved word
2185 -- "limited" in its full definition ... a formal parameter or
2186 -- generic formal object of a tagged type.
2188 -- Ada 2005 limited type
2189 -- * Type with reserved word "limited", "synchronized", "task"
2191 -- * A composite type with limited component
2192 -- * A derived type whose parent is a non-interface limited type
2194 elsif Ada_Version
= Ada_2005
then
2196 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2198 (Is_Derived_Type
(Typ
)
2199 and then not Is_Interface
(Etype
(Typ
))
2200 and then Is_Limited_Type
(Etype
(Typ
)));
2202 -- Ada 2012 and beyond
2204 -- The current instance of an immutably limited type ... a formal
2205 -- parameter or generic formal object of a tagged type.
2207 -- Ada 2012 limited type
2208 -- * Type with reserved word "limited", "synchronized", "task"
2210 -- * A composite type with limited component
2211 -- * A derived type whose parent is a non-interface limited type
2212 -- * An incomplete view
2214 -- Ada 2012 immutably limited type
2215 -- * Explicitly limited record type
2216 -- * Record extension with "limited" present
2217 -- * Non-formal limited private type that is either tagged
2218 -- or has at least one access discriminant with a default
2220 -- * Task type, protected type or synchronized interface
2221 -- * Type derived from immutably limited type
2225 Is_Immutably_Limited_Type
(Typ
)
2226 or else Is_Incomplete_Type
(Typ
);
2228 end Is_Aliased_View_Of_Type
;
2234 function Process
(N
: Node_Id
) return Traverse_Result
is
2237 when N_Attribute_Reference
=>
2238 if Nam_In
(Attribute_Name
(N
), Name_Access
,
2239 Name_Unchecked_Access
)
2240 and then Is_Entity_Name
(Prefix
(N
))
2241 and then Is_Type
(Entity
(Prefix
(N
)))
2242 and then Entity
(Prefix
(N
)) = E
2244 if Ada_Version
< Ada_2012
then
2246 ("current instance must be a limited type",
2250 ("current instance must be an immutably limited "
2251 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2265 procedure Traverse
is new Traverse_Proc
(Process
);
2269 Rec_Type
: constant Entity_Id
:=
2270 Scope
(Defining_Identifier
(Comp_Decl
));
2272 -- Start of processing for Check_Current_Instance
2275 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2276 Traverse
(Comp_Decl
);
2278 end Check_Current_Instance
;
2280 ---------------------------------
2281 -- Check_Suspicious_Convention --
2282 ---------------------------------
2284 procedure Check_Suspicious_Convention
(Rec_Type
: Entity_Id
) is
2286 if Has_Discriminants
(Rec_Type
)
2287 and then Is_Base_Type
(Rec_Type
)
2288 and then not Is_Unchecked_Union
(Rec_Type
)
2289 and then (Convention
(Rec_Type
) = Convention_C
2291 Convention
(Rec_Type
) = Convention_CPP
)
2292 and then Comes_From_Source
(Rec_Type
)
2293 and then not In_Instance
2294 and then not Has_Warnings_Off
(Rec_Type
)
2297 Cprag
: constant Node_Id
:=
2298 Get_Rep_Pragma
(Rec_Type
, Name_Convention
);
2302 if Present
(Cprag
) then
2303 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
2305 if Convention
(Rec_Type
) = Convention_C
then
2307 ("?x?discriminated record has no direct equivalent in "
2311 ("?x?discriminated record has no direct equivalent in "
2316 ("\?x?use of convention for type& is dubious",
2321 end Check_Suspicious_Convention
;
2323 ------------------------------
2324 -- Check_Suspicious_Modulus --
2325 ------------------------------
2327 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
2328 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
2331 if not Warn_On_Suspicious_Modulus_Value
then
2335 if Nkind
(Decl
) = N_Full_Type_Declaration
then
2337 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
2340 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
2342 Modulus
: constant Node_Id
:=
2343 Original_Node
(Expression
(Tdef
));
2346 if Nkind
(Modulus
) = N_Integer_Literal
then
2348 Modv
: constant Uint
:= Intval
(Modulus
);
2349 Sizv
: constant Uint
:= RM_Size
(Utype
);
2352 -- First case, modulus and size are the same. This
2353 -- happens if you have something like mod 32, with
2354 -- an explicit size of 32, this is for sure a case
2355 -- where the warning is given, since it is seems
2356 -- very unlikely that someone would want e.g. a
2357 -- five bit type stored in 32 bits. It is much
2358 -- more likely they wanted a 32-bit type.
2363 -- Second case, the modulus is 32 or 64 and no
2364 -- size clause is present. This is a less clear
2365 -- case for giving the warning, but in the case
2366 -- of 32/64 (5-bit or 6-bit types) these seem rare
2367 -- enough that it is a likely error (and in any
2368 -- case using 2**5 or 2**6 in these cases seems
2369 -- clearer. We don't include 8 or 16 here, simply
2370 -- because in practice 3-bit and 4-bit types are
2371 -- more common and too many false positives if
2372 -- we warn in these cases.
2374 elsif not Has_Size_Clause
(Utype
)
2375 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
2379 -- No warning needed
2385 -- If we fall through, give warning
2387 Error_Msg_Uint_1
:= Modv
;
2389 ("?M?2 '*'*^' may have been intended here",
2397 end Check_Suspicious_Modulus
;
2399 -----------------------
2400 -- Freeze_Array_Type --
2401 -----------------------
2403 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2404 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2405 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2408 Non_Standard_Enum
: Boolean := False;
2409 -- Set true if any of the index types is an enumeration type with a
2410 -- non-standard representation.
2413 Freeze_And_Append
(Ctyp
, N
, Result
);
2415 Indx
:= First_Index
(Arr
);
2416 while Present
(Indx
) loop
2417 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2419 if Is_Enumeration_Type
(Etype
(Indx
))
2420 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2422 Non_Standard_Enum
:= True;
2428 -- Processing that is done only for base types
2430 if Ekind
(Arr
) = E_Array_Type
then
2432 -- Deal with default setting of reverse storage order
2434 Set_SSO_From_Default
(Arr
);
2436 -- Propagate flags for component type
2438 if Is_Controlled_Active
(Component_Type
(Arr
))
2439 or else Has_Controlled_Component
(Ctyp
)
2441 Set_Has_Controlled_Component
(Arr
);
2444 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2445 Set_Has_Unchecked_Union
(Arr
);
2448 -- The array type requires its own invariant procedure in order to
2449 -- verify the component invariant over all elements. In GNATprove
2450 -- mode, the component invariants are checked by other means. They
2451 -- should not be added to the array type invariant procedure, so
2452 -- that the procedure can be used to check the array type
2453 -- invariants if any.
2455 if Has_Invariants
(Component_Type
(Arr
))
2456 and then not GNATprove_Mode
2458 Set_Has_Own_Invariants
(Arr
);
2460 -- The array type is an implementation base type. Propagate the
2461 -- same property to the first subtype.
2463 if Is_Itype
(Arr
) then
2464 Set_Has_Own_Invariants
(First_Subtype
(Arr
));
2468 -- Warn for pragma Pack overriding foreign convention
2470 if Has_Foreign_Convention
(Ctyp
)
2471 and then Has_Pragma_Pack
(Arr
)
2474 CN
: constant Name_Id
:=
2475 Get_Convention_Name
(Convention
(Ctyp
));
2476 PP
: constant Node_Id
:=
2477 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2479 if Present
(PP
) then
2480 Error_Msg_Name_1
:= CN
;
2481 Error_Msg_Sloc
:= Sloc
(Arr
);
2483 ("pragma Pack affects convention % components #??", PP
);
2484 Error_Msg_Name_1
:= CN
;
2486 ("\array components may not have % compatible "
2487 & "representation??", PP
);
2492 -- If packing was requested or if the component size was
2493 -- set explicitly, then see if bit packing is required. This
2494 -- processing is only done for base types, since all of the
2495 -- representation aspects involved are type-related.
2497 -- This is not just an optimization, if we start processing the
2498 -- subtypes, they interfere with the settings on the base type
2499 -- (this is because Is_Packed has a slightly different meaning
2500 -- before and after freezing).
2507 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2508 and then Known_Static_RM_Size
(Ctyp
)
2509 and then not Has_Component_Size_Clause
(Arr
)
2511 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2513 elsif Known_Component_Size
(Arr
) then
2514 Csiz
:= Component_Size
(Arr
);
2516 elsif not Known_Static_Esize
(Ctyp
) then
2520 Esiz
:= Esize
(Ctyp
);
2522 -- We can set the component size if it is less than 16,
2523 -- rounding it up to the next storage unit size.
2527 elsif Esiz
<= 16 then
2533 -- Set component size up to match alignment if it would
2534 -- otherwise be less than the alignment. This deals with
2535 -- cases of types whose alignment exceeds their size (the
2536 -- padded type cases).
2540 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2549 -- Case of component size that may result in bit packing
2551 if 1 <= Csiz
and then Csiz
<= 64 then
2553 Ent
: constant Entity_Id
:=
2554 First_Subtype
(Arr
);
2555 Pack_Pragma
: constant Node_Id
:=
2556 Get_Rep_Pragma
(Ent
, Name_Pack
);
2557 Comp_Size_C
: constant Node_Id
:=
2558 Get_Attribute_Definition_Clause
2559 (Ent
, Attribute_Component_Size
);
2562 -- Warn if we have pack and component size so that the
2565 -- Note: here we must check for the presence of a
2566 -- component size before checking for a Pack pragma to
2567 -- deal with the case where the array type is a derived
2568 -- type whose parent is currently private.
2570 if Present
(Comp_Size_C
)
2571 and then Has_Pragma_Pack
(Ent
)
2572 and then Warn_On_Redundant_Constructs
2574 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2576 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2578 ("\?r?explicit component size given#!", Pack_Pragma
);
2579 Set_Is_Packed
(Base_Type
(Ent
), False);
2580 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2583 -- Set component size if not already set by a component
2586 if not Present
(Comp_Size_C
) then
2587 Set_Component_Size
(Arr
, Csiz
);
2590 -- Check for base type of 8, 16, 32 bits, where an
2591 -- unsigned subtype has a length one less than the
2592 -- base type (e.g. Natural subtype of Integer).
2594 -- In such cases, if a component size was not set
2595 -- explicitly, then generate a warning.
2597 if Has_Pragma_Pack
(Arr
)
2598 and then not Present
(Comp_Size_C
)
2599 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2600 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2602 Error_Msg_Uint_1
:= Csiz
;
2604 if Present
(Pack_Pragma
) then
2606 ("??pragma Pack causes component size to be ^!",
2609 ("\??use Component_Size to set desired value!",
2614 -- Bit packing is never needed for 8, 16, 32, 64
2616 if Addressable
(Csiz
) then
2618 -- If the Esize of the component is known and equal to
2619 -- the component size then even packing is not needed.
2621 if Known_Static_Esize
(Component_Type
(Arr
))
2622 and then Esize
(Component_Type
(Arr
)) = Csiz
2624 -- Here the array was requested to be packed, but
2625 -- the packing request had no effect whatsoever,
2626 -- so flag Is_Packed is reset.
2628 -- Note: semantically this means that we lose track
2629 -- of the fact that a derived type inherited pragma
2630 -- Pack that was non-effective, but that is fine.
2632 -- We regard a Pack pragma as a request to set a
2633 -- representation characteristic, and this request
2636 Set_Is_Packed
(Base_Type
(Arr
), False);
2637 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
2639 Set_Is_Packed
(Base_Type
(Arr
), True);
2640 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2643 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2645 -- Bit packing is not needed for multiples of the storage
2646 -- unit if the type is composite because the back end can
2647 -- byte pack composite types.
2649 elsif Csiz
mod System_Storage_Unit
= 0
2650 and then Is_Composite_Type
(Ctyp
)
2653 Set_Is_Packed
(Base_Type
(Arr
), True);
2654 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2655 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2657 -- In all other cases, bit packing is needed
2660 Set_Is_Packed
(Base_Type
(Arr
), True);
2661 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2662 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2668 -- Check for Aliased or Atomic_Components/Atomic/VFA with
2669 -- unsuitable packing or explicit component size clause given.
2671 if (Has_Aliased_Components
(Arr
)
2672 or else Has_Atomic_Components
(Arr
)
2673 or else Is_Atomic_Or_VFA
(Ctyp
))
2675 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2677 Alias_Atomic_Check
: declare
2679 procedure Complain_CS
(T
: String);
2680 -- Outputs error messages for incorrect CS clause or pragma
2681 -- Pack for aliased or atomic/VFA components (T is "aliased"
2682 -- or "atomic/vfa");
2688 procedure Complain_CS
(T
: String) is
2690 if Has_Component_Size_Clause
(Arr
) then
2692 Get_Attribute_Definition_Clause
2693 (FS
, Attribute_Component_Size
);
2696 ("incorrect component size for "
2697 & T
& " components", Clause
);
2698 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2700 ("\only allowed value is^", Clause
);
2704 ("cannot pack " & T
& " components",
2705 Get_Rep_Pragma
(FS
, Name_Pack
));
2709 -- Start of processing for Alias_Atomic_Check
2712 -- If object size of component type isn't known, we cannot
2713 -- be sure so we defer to the back end.
2715 if not Known_Static_Esize
(Ctyp
) then
2718 -- Case where component size has no effect. First check for
2719 -- object size of component type multiple of the storage
2722 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2724 -- OK in both packing case and component size case if RM
2725 -- size is known and static and same as the object size.
2728 ((Known_Static_RM_Size
(Ctyp
)
2729 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2731 -- Or if we have an explicit component size clause and
2732 -- the component size and object size are equal.
2735 (Has_Component_Size_Clause
(Arr
)
2736 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2740 elsif Has_Aliased_Components
(Arr
) then
2741 Complain_CS
("aliased");
2743 elsif Has_Atomic_Components
(Arr
)
2744 or else Is_Atomic
(Ctyp
)
2746 Complain_CS
("atomic");
2748 elsif Is_Volatile_Full_Access
(Ctyp
) then
2749 Complain_CS
("volatile full access");
2751 end Alias_Atomic_Check
;
2754 -- Check for Independent_Components/Independent with unsuitable
2755 -- packing or explicit component size clause given.
2757 if (Has_Independent_Components
(Arr
) or else Is_Independent
(Ctyp
))
2759 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2762 -- If object size of component type isn't known, we cannot
2763 -- be sure so we defer to the back end.
2765 if not Known_Static_Esize
(Ctyp
) then
2768 -- Case where component size has no effect. First check for
2769 -- object size of component type multiple of the storage
2772 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2774 -- OK in both packing case and component size case if RM
2775 -- size is known and multiple of the storage unit size.
2778 ((Known_Static_RM_Size
(Ctyp
)
2779 and then RM_Size
(Ctyp
) mod System_Storage_Unit
= 0)
2781 -- Or if we have an explicit component size clause and
2782 -- the component size is larger than the object size.
2785 (Has_Component_Size_Clause
(Arr
)
2786 and then Component_Size
(Arr
) >= Esize
(Ctyp
)))
2791 if Has_Component_Size_Clause
(Arr
) then
2793 Get_Attribute_Definition_Clause
2794 (FS
, Attribute_Component_Size
);
2797 ("incorrect component size for "
2798 & "independent components", Clause
);
2799 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2801 ("\minimum allowed is^", Clause
);
2805 ("cannot pack independent components",
2806 Get_Rep_Pragma
(FS
, Name_Pack
));
2812 -- Warn for case of atomic type
2814 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2817 and then not Addressable
(Component_Size
(FS
))
2820 ("non-atomic components of type& may not be "
2821 & "accessible by separate tasks??", Clause
, Arr
);
2823 if Has_Component_Size_Clause
(Arr
) then
2824 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2825 (FS
, Attribute_Component_Size
));
2826 Error_Msg_N
("\because of component size clause#??", Clause
);
2828 elsif Has_Pragma_Pack
(Arr
) then
2829 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2830 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2834 -- Check for scalar storage order
2839 Check_Component_Storage_Order
2842 ADC
=> Get_Attribute_Definition_Clause
2843 (First_Subtype
(Arr
),
2844 Attribute_Scalar_Storage_Order
),
2845 Comp_ADC_Present
=> Dummy
);
2848 -- Processing that is done only for subtypes
2851 -- Acquire alignment from base type
2853 if Unknown_Alignment
(Arr
) then
2854 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2855 Adjust_Esize_Alignment
(Arr
);
2859 -- Specific checks for bit-packed arrays
2861 if Is_Bit_Packed_Array
(Arr
) then
2863 -- Check number of elements for bit-packed arrays that come from
2864 -- source and have compile time known ranges. The bit-packed
2865 -- arrays circuitry does not support arrays with more than
2866 -- Integer'Last + 1 elements, and when this restriction is
2867 -- violated, causes incorrect data access.
2869 -- For the case where this is not compile time known, a run-time
2870 -- check should be generated???
2872 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
2881 Index
:= First_Index
(Arr
);
2882 while Present
(Index
) loop
2883 Ityp
:= Etype
(Index
);
2885 -- Never generate an error if any index is of a generic
2886 -- type. We will check this in instances.
2888 if Is_Generic_Type
(Ityp
) then
2894 Make_Attribute_Reference
(Loc
,
2895 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2896 Attribute_Name
=> Name_Range_Length
);
2897 Analyze_And_Resolve
(Ilen
);
2899 -- No attempt is made to check number of elements if not
2900 -- compile time known.
2902 if Nkind
(Ilen
) /= N_Integer_Literal
then
2907 Elmts
:= Elmts
* Intval
(Ilen
);
2911 if Elmts
> Intval
(High_Bound
2912 (Scalar_Range
(Standard_Integer
))) + 1
2915 ("bit packed array type may not have "
2916 & "more than Integer''Last+1 elements", Arr
);
2923 if Known_RM_Size
(Arr
) then
2925 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
2929 -- It is not clear if it is possible to have no size clause
2930 -- at this stage, but it is not worth worrying about. Post
2931 -- error on the entity name in the size clause if present,
2932 -- else on the type entity itself.
2934 if Present
(SizC
) then
2935 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
2937 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
2943 -- If any of the index types was an enumeration type with a non-
2944 -- standard rep clause, then we indicate that the array type is
2945 -- always packed (even if it is not bit-packed).
2947 if Non_Standard_Enum
then
2948 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
2949 Set_Is_Packed
(Base_Type
(Arr
));
2952 Set_Component_Alignment_If_Not_Set
(Arr
);
2954 -- If the array is packed and bit-packed or packed to eliminate holes
2955 -- in the non-contiguous enumeration index types, we must create the
2956 -- packed array type to be used to actually implement the type. This
2957 -- is only needed for real array types (not for string literal types,
2958 -- since they are present only for the front end).
2961 and then (Is_Bit_Packed_Array
(Arr
) or else Non_Standard_Enum
)
2962 and then Ekind
(Arr
) /= E_String_Literal_Subtype
2964 Create_Packed_Array_Impl_Type
(Arr
);
2965 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
2967 -- Make sure that we have the necessary routines to implement the
2968 -- packing, and complain now if not. Note that we only test this
2969 -- for constrained array types.
2971 if Is_Constrained
(Arr
)
2972 and then Is_Bit_Packed_Array
(Arr
)
2973 and then Present
(Packed_Array_Impl_Type
(Arr
))
2974 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
2977 CS
: constant Uint
:= Component_Size
(Arr
);
2978 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
2982 and then not RTE_Available
(RE
)
2985 ("packing of " & UI_Image
(CS
) & "-bit components",
2986 First_Subtype
(Etype
(Arr
)));
2988 -- Cancel the packing
2990 Set_Is_Packed
(Base_Type
(Arr
), False);
2991 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2992 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
2998 -- Size information of packed array type is copied to the array
2999 -- type, since this is really the representation. But do not
3000 -- override explicit existing size values. If the ancestor subtype
3001 -- is constrained the Packed_Array_Impl_Type will be inherited
3002 -- from it, but the size may have been provided already, and
3003 -- must not be overridden either.
3005 if not Has_Size_Clause
(Arr
)
3007 (No
(Ancestor_Subtype
(Arr
))
3008 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
3010 Set_Esize
(Arr
, Esize
(Packed_Array_Impl_Type
(Arr
)));
3011 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Impl_Type
(Arr
)));
3014 if not Has_Alignment_Clause
(Arr
) then
3015 Set_Alignment
(Arr
, Alignment
(Packed_Array_Impl_Type
(Arr
)));
3021 -- For non-packed arrays set the alignment of the array to the
3022 -- alignment of the component type if it is unknown. Skip this
3023 -- in atomic/VFA case (atomic/VFA arrays may need larger alignments).
3025 if not Is_Packed
(Arr
)
3026 and then Unknown_Alignment
(Arr
)
3027 and then Known_Alignment
(Ctyp
)
3028 and then Known_Static_Component_Size
(Arr
)
3029 and then Known_Static_Esize
(Ctyp
)
3030 and then Esize
(Ctyp
) = Component_Size
(Arr
)
3031 and then not Is_Atomic_Or_VFA
(Arr
)
3033 Set_Alignment
(Arr
, Alignment
(Component_Type
(Arr
)));
3036 -- A Ghost type cannot have a component of protected or task type
3037 -- (SPARK RM 6.9(19)).
3039 if Is_Ghost_Entity
(Arr
) and then Is_Concurrent_Type
(Ctyp
) then
3041 ("ghost array type & cannot have concurrent component type",
3044 end Freeze_Array_Type
;
3046 -------------------------------
3047 -- Freeze_Object_Declaration --
3048 -------------------------------
3050 procedure Freeze_Object_Declaration
(E
: Entity_Id
) is
3052 -- Abstract type allowed only for C++ imported variables or constants
3054 -- Note: we inhibit this check for objects that do not come from
3055 -- source because there is at least one case (the expansion of
3056 -- x'Class'Input where x is abstract) where we legitimately
3057 -- generate an abstract object.
3059 if Is_Abstract_Type
(Etype
(E
))
3060 and then Comes_From_Source
(Parent
(E
))
3061 and then not (Is_Imported
(E
) and then Is_CPP_Class
(Etype
(E
)))
3063 Error_Msg_N
("type of object cannot be abstract",
3064 Object_Definition
(Parent
(E
)));
3066 if Is_CPP_Class
(Etype
(E
)) then
3068 ("\} may need a cpp_constructor",
3069 Object_Definition
(Parent
(E
)), Etype
(E
));
3071 elsif Present
(Expression
(Parent
(E
))) then
3072 Error_Msg_N
-- CODEFIX
3073 ("\maybe a class-wide type was meant",
3074 Object_Definition
(Parent
(E
)));
3078 -- For object created by object declaration, perform required
3079 -- categorization (preelaborate and pure) checks. Defer these
3080 -- checks to freeze time since pragma Import inhibits default
3081 -- initialization and thus pragma Import affects these checks.
3083 Validate_Object_Declaration
(Declaration_Node
(E
));
3085 -- If there is an address clause, check that it is valid
3086 -- and if need be move initialization to the freeze node.
3088 Check_Address_Clause
(E
);
3090 -- Similar processing is needed for aspects that may affect
3091 -- object layout, like Alignment, if there is an initialization
3094 if Has_Delayed_Aspects
(E
)
3095 and then Expander_Active
3096 and then Is_Array_Type
(Etype
(E
))
3097 and then Present
(Expression
(Parent
(E
)))
3100 Decl
: constant Node_Id
:= Parent
(E
);
3101 Lhs
: constant Node_Id
:= New_Occurrence_Of
(E
, Loc
);
3105 -- Capture initialization value at point of declaration, and
3106 -- make explicit assignment legal, because object may be a
3109 Remove_Side_Effects
(Expression
(Decl
));
3110 Set_Assignment_OK
(Lhs
);
3112 -- Move initialization to freeze actions.
3114 Append_Freeze_Action
(E
,
3115 Make_Assignment_Statement
(Loc
,
3117 Expression
=> Expression
(Decl
)));
3119 Set_No_Initialization
(Decl
);
3120 -- Set_Is_Frozen (E, False);
3124 -- Reset Is_True_Constant for non-constant aliased object. We
3125 -- consider that the fact that a non-constant object is aliased may
3126 -- indicate that some funny business is going on, e.g. an aliased
3127 -- object is passed by reference to a procedure which captures the
3128 -- address of the object, which is later used to assign a new value,
3129 -- even though the compiler thinks that it is not modified. Such
3130 -- code is highly dubious, but we choose to make it "work" for
3131 -- non-constant aliased objects.
3133 -- Note that we used to do this for all aliased objects, whether or
3134 -- not constant, but this caused anomalies down the line because we
3135 -- ended up with static objects that were not Is_True_Constant. Not
3136 -- resetting Is_True_Constant for (aliased) constant objects ensures
3137 -- that this anomaly never occurs.
3139 -- However, we don't do that for internal entities. We figure that if
3140 -- we deliberately set Is_True_Constant for an internal entity, e.g.
3141 -- a dispatch table entry, then we mean it.
3143 if Ekind
(E
) /= E_Constant
3144 and then (Is_Aliased
(E
) or else Is_Aliased
(Etype
(E
)))
3145 and then not Is_Internal_Name
(Chars
(E
))
3147 Set_Is_True_Constant
(E
, False);
3150 -- If the object needs any kind of default initialization, an error
3151 -- must be issued if No_Default_Initialization applies. The check
3152 -- doesn't apply to imported objects, which are not ever default
3153 -- initialized, and is why the check is deferred until freezing, at
3154 -- which point we know if Import applies. Deferred constants are also
3155 -- exempted from this test because their completion is explicit, or
3156 -- through an import pragma.
3158 if Ekind
(E
) = E_Constant
and then Present
(Full_View
(E
)) then
3161 elsif Comes_From_Source
(E
)
3162 and then not Is_Imported
(E
)
3163 and then not Has_Init_Expression
(Declaration_Node
(E
))
3165 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
3166 and then not No_Initialization
(Declaration_Node
(E
))
3167 and then not Initialization_Suppressed
(Etype
(E
)))
3169 (Needs_Simple_Initialization
(Etype
(E
))
3170 and then not Is_Internal
(E
)))
3172 Has_Default_Initialization
:= True;
3174 (No_Default_Initialization
, Declaration_Node
(E
));
3177 -- Check that a Thread_Local_Storage variable does not have
3178 -- default initialization, and any explicit initialization must
3179 -- either be the null constant or a static constant.
3181 if Has_Pragma_Thread_Local_Storage
(E
) then
3183 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3185 if Has_Default_Initialization
3187 (Has_Init_Expression
(Decl
)
3189 (No
(Expression
(Decl
))
3191 (Is_OK_Static_Expression
(Expression
(Decl
))
3192 or else Nkind
(Expression
(Decl
)) = N_Null
)))
3195 ("Thread_Local_Storage variable& is "
3196 & "improperly initialized", Decl
, E
);
3198 ("\only allowed initialization is explicit "
3199 & "NULL or static expression", Decl
, E
);
3204 -- For imported objects, set Is_Public unless there is also an
3205 -- address clause, which means that there is no external symbol
3206 -- needed for the Import (Is_Public may still be set for other
3207 -- unrelated reasons). Note that we delayed this processing
3208 -- till freeze time so that we can be sure not to set the flag
3209 -- if there is an address clause. If there is such a clause,
3210 -- then the only purpose of the Import pragma is to suppress
3211 -- implicit initialization.
3213 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
3217 -- For source objects that are not Imported and are library
3218 -- level, if no linker section pragma was given inherit the
3219 -- appropriate linker section from the corresponding type.
3221 if Comes_From_Source
(E
)
3222 and then not Is_Imported
(E
)
3223 and then Is_Library_Level_Entity
(E
)
3224 and then No
(Linker_Section_Pragma
(E
))
3226 Set_Linker_Section_Pragma
3227 (E
, Linker_Section_Pragma
(Etype
(E
)));
3230 -- For convention C objects of an enumeration type, warn if the
3231 -- size is not integer size and no explicit size given. Skip
3232 -- warning for Boolean, and Character, assume programmer expects
3233 -- 8-bit sizes for these cases.
3235 if (Convention
(E
) = Convention_C
3237 Convention
(E
) = Convention_CPP
)
3238 and then Is_Enumeration_Type
(Etype
(E
))
3239 and then not Is_Character_Type
(Etype
(E
))
3240 and then not Is_Boolean_Type
(Etype
(E
))
3241 and then Esize
(Etype
(E
)) < Standard_Integer_Size
3242 and then not Has_Size_Clause
(E
)
3244 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
3246 ("??convention C enumeration object has size less than ^", E
);
3247 Error_Msg_N
("\??use explicit size clause to set size", E
);
3249 end Freeze_Object_Declaration
;
3251 -----------------------------
3252 -- Freeze_Generic_Entities --
3253 -----------------------------
3255 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
3262 E
:= First_Entity
(Pack
);
3263 while Present
(E
) loop
3264 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
3265 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
3267 Append_To
(Flist
, F
);
3269 elsif Ekind
(E
) = E_Generic_Package
then
3270 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
3277 end Freeze_Generic_Entities
;
3279 --------------------
3280 -- Freeze_Profile --
3281 --------------------
3283 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
3286 Warn_Node
: Node_Id
;
3289 -- Loop through formals
3291 Formal
:= First_Formal
(E
);
3292 while Present
(Formal
) loop
3293 F_Type
:= Etype
(Formal
);
3295 -- AI05-0151: incomplete types can appear in a profile. By the
3296 -- time the entity is frozen, the full view must be available,
3297 -- unless it is a limited view.
3299 if Is_Incomplete_Type
(F_Type
)
3300 and then Present
(Full_View
(F_Type
))
3301 and then not From_Limited_With
(F_Type
)
3303 F_Type
:= Full_View
(F_Type
);
3304 Set_Etype
(Formal
, F_Type
);
3307 if not From_Limited_With
(F_Type
) then
3308 Freeze_And_Append
(F_Type
, N
, Result
);
3311 if Is_Private_Type
(F_Type
)
3312 and then Is_Private_Type
(Base_Type
(F_Type
))
3313 and then No
(Full_View
(Base_Type
(F_Type
)))
3314 and then not Is_Generic_Type
(F_Type
)
3315 and then not Is_Derived_Type
(F_Type
)
3317 -- If the type of a formal is incomplete, subprogram is being
3318 -- frozen prematurely. Within an instance (but not within a
3319 -- wrapper package) this is an artifact of our need to regard
3320 -- the end of an instantiation as a freeze point. Otherwise it
3321 -- is a definite error.
3324 Set_Is_Frozen
(E
, False);
3328 elsif not After_Last_Declaration
3329 and then not Freezing_Library_Level_Tagged_Type
3331 Error_Msg_Node_1
:= F_Type
;
3333 ("type & must be fully defined before this point", Loc
);
3337 -- Check suspicious parameter for C function. These tests apply
3338 -- only to exported/imported subprograms.
3340 if Warn_On_Export_Import
3341 and then Comes_From_Source
(E
)
3342 and then (Convention
(E
) = Convention_C
3344 Convention
(E
) = Convention_CPP
)
3345 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3346 and then Convention
(E
) /= Convention
(Formal
)
3347 and then not Has_Warnings_Off
(E
)
3348 and then not Has_Warnings_Off
(F_Type
)
3349 and then not Has_Warnings_Off
(Formal
)
3351 -- Qualify mention of formals with subprogram name
3353 Error_Msg_Qual_Level
:= 1;
3355 -- Check suspicious use of fat C pointer
3357 if Is_Access_Type
(F_Type
)
3358 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
3361 ("?x?type of & does not correspond to C pointer!", Formal
);
3363 -- Check suspicious return of boolean
3365 elsif Root_Type
(F_Type
) = Standard_Boolean
3366 and then Convention
(F_Type
) = Convention_Ada
3367 and then not Has_Warnings_Off
(F_Type
)
3368 and then not Has_Size_Clause
(F_Type
)
3371 ("& is an 8-bit Ada Boolean?x?", Formal
);
3373 ("\use appropriate corresponding type in C "
3374 & "(e.g. char)?x?", Formal
);
3376 -- Check suspicious tagged type
3378 elsif (Is_Tagged_Type
(F_Type
)
3380 (Is_Access_Type
(F_Type
)
3381 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
3382 and then Convention
(E
) = Convention_C
3385 ("?x?& involves a tagged type which does not "
3386 & "correspond to any C type!", Formal
);
3388 -- Check wrong convention subprogram pointer
3390 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
3391 and then not Has_Foreign_Convention
(F_Type
)
3394 ("?x?subprogram pointer & should "
3395 & "have foreign convention!", Formal
);
3396 Error_Msg_Sloc
:= Sloc
(F_Type
);
3398 ("\?x?add Convention pragma to declaration of &#",
3402 -- Turn off name qualification after message output
3404 Error_Msg_Qual_Level
:= 0;
3407 -- Check for unconstrained array in exported foreign convention
3410 if Has_Foreign_Convention
(E
)
3411 and then not Is_Imported
(E
)
3412 and then Is_Array_Type
(F_Type
)
3413 and then not Is_Constrained
(F_Type
)
3414 and then Warn_On_Export_Import
3416 Error_Msg_Qual_Level
:= 1;
3418 -- If this is an inherited operation, place the warning on
3419 -- the derived type declaration, rather than on the original
3422 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
3424 Warn_Node
:= Parent
(E
);
3426 if Formal
= First_Formal
(E
) then
3427 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
3430 Warn_Node
:= Formal
;
3433 Error_Msg_NE
("?x?type of argument& is unconstrained array",
3435 Error_Msg_NE
("?x?foreign caller must pass bounds explicitly",
3437 Error_Msg_Qual_Level
:= 0;
3440 if not From_Limited_With
(F_Type
) then
3441 if Is_Access_Type
(F_Type
) then
3442 F_Type
:= Designated_Type
(F_Type
);
3445 -- If the formal is an anonymous_access_to_subprogram
3446 -- freeze the subprogram type as well, to prevent
3447 -- scope anomalies in gigi, because there is no other
3448 -- clear point at which it could be frozen.
3450 if Is_Itype
(Etype
(Formal
))
3451 and then Ekind
(F_Type
) = E_Subprogram_Type
3453 Freeze_And_Append
(F_Type
, N
, Result
);
3457 Next_Formal
(Formal
);
3460 -- Case of function: similar checks on return type
3462 if Ekind
(E
) = E_Function
then
3464 -- Freeze return type
3466 R_Type
:= Etype
(E
);
3468 -- AI05-0151: the return type may have been incomplete at the
3469 -- point of declaration. Replace it with the full view, unless the
3470 -- current type is a limited view. In that case the full view is
3471 -- in a different unit, and gigi finds the non-limited view after
3472 -- the other unit is elaborated.
3474 if Ekind
(R_Type
) = E_Incomplete_Type
3475 and then Present
(Full_View
(R_Type
))
3476 and then not From_Limited_With
(R_Type
)
3478 R_Type
:= Full_View
(R_Type
);
3479 Set_Etype
(E
, R_Type
);
3482 Freeze_And_Append
(R_Type
, N
, Result
);
3484 -- Check suspicious return type for C function
3486 if Warn_On_Export_Import
3487 and then (Convention
(E
) = Convention_C
3489 Convention
(E
) = Convention_CPP
)
3490 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3492 -- Check suspicious return of fat C pointer
3494 if Is_Access_Type
(R_Type
)
3495 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
3496 and then not Has_Warnings_Off
(E
)
3497 and then not Has_Warnings_Off
(R_Type
)
3500 ("?x?return type of& does not correspond to C pointer!",
3503 -- Check suspicious return of boolean
3505 elsif Root_Type
(R_Type
) = Standard_Boolean
3506 and then Convention
(R_Type
) = Convention_Ada
3507 and then not Has_Warnings_Off
(E
)
3508 and then not Has_Warnings_Off
(R_Type
)
3509 and then not Has_Size_Clause
(R_Type
)
3512 N
: constant Node_Id
:=
3513 Result_Definition
(Declaration_Node
(E
));
3516 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
3518 ("\use appropriate corresponding type in C "
3519 & "(e.g. char)?x?", N
, E
);
3522 -- Check suspicious return tagged type
3524 elsif (Is_Tagged_Type
(R_Type
)
3525 or else (Is_Access_Type
(R_Type
)
3528 (Designated_Type
(R_Type
))))
3529 and then Convention
(E
) = Convention_C
3530 and then not Has_Warnings_Off
(E
)
3531 and then not Has_Warnings_Off
(R_Type
)
3533 Error_Msg_N
("?x?return type of & does not "
3534 & "correspond to C type!", E
);
3536 -- Check return of wrong convention subprogram pointer
3538 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3539 and then not Has_Foreign_Convention
(R_Type
)
3540 and then not Has_Warnings_Off
(E
)
3541 and then not Has_Warnings_Off
(R_Type
)
3543 Error_Msg_N
("?x?& should return a foreign "
3544 & "convention subprogram pointer", E
);
3545 Error_Msg_Sloc
:= Sloc
(R_Type
);
3547 ("\?x?add Convention pragma to declaration of& #",
3552 -- Give warning for suspicious return of a result of an
3553 -- unconstrained array type in a foreign convention function.
3555 if Has_Foreign_Convention
(E
)
3557 -- We are looking for a return of unconstrained array
3559 and then Is_Array_Type
(R_Type
)
3560 and then not Is_Constrained
(R_Type
)
3562 -- Exclude imported routines, the warning does not belong on
3563 -- the import, but rather on the routine definition.
3565 and then not Is_Imported
(E
)
3567 -- Check that general warning is enabled, and that it is not
3568 -- suppressed for this particular case.
3570 and then Warn_On_Export_Import
3571 and then not Has_Warnings_Off
(E
)
3572 and then not Has_Warnings_Off
(R_Type
)
3575 ("?x?foreign convention function& should not return "
3576 & "unconstrained array!", E
);
3580 -- Check suspicious use of Import in pure unit (cases where the RM
3581 -- allows calls to be omitted).
3585 -- It might be suspicious if the compilation unit has the Pure
3588 and then Has_Pragma_Pure
(Cunit_Entity
(Current_Sem_Unit
))
3590 -- The RM allows omission of calls only in the case of
3591 -- library-level subprograms (see RM-10.2.1(18)).
3593 and then Is_Library_Level_Entity
(E
)
3595 -- Ignore internally generated entity. This happens in some cases
3596 -- of subprograms in specs, where we generate an implied body.
3598 and then Comes_From_Source
(Import_Pragma
(E
))
3600 -- Assume run-time knows what it is doing
3602 and then not GNAT_Mode
3604 -- Assume explicit Pure_Function means import is pure
3606 and then not Has_Pragma_Pure_Function
(E
)
3608 -- Don't need warning in relaxed semantics mode
3610 and then not Relaxed_RM_Semantics
3612 -- Assume convention Intrinsic is OK, since this is specialized.
3613 -- This deals with the DEC unit current_exception.ads
3615 and then Convention
(E
) /= Convention_Intrinsic
3617 -- Assume that ASM interface knows what it is doing. This deals
3618 -- with e.g. unsigned.ads in the AAMP back end.
3620 and then Convention
(E
) /= Convention_Assembler
3623 ("pragma Import in Pure unit??", Import_Pragma
(E
));
3625 ("\calls to & may be omitted (RM 10.2.1(18/3))??",
3626 Import_Pragma
(E
), E
);
3632 ------------------------
3633 -- Freeze_Record_Type --
3634 ------------------------
3636 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
3643 pragma Warnings
(Off
, Junk
);
3645 Aliased_Component
: Boolean := False;
3646 -- Set True if we find at least one component which is aliased. This
3647 -- is used to prevent Implicit_Packing of the record, since packing
3648 -- cannot modify the size of alignment of an aliased component.
3650 All_Elem_Components
: Boolean := True;
3651 -- Set False if we encounter a component of a composite type
3653 All_Sized_Components
: Boolean := True;
3654 -- Set False if we encounter a component with unknown RM_Size
3656 All_Storage_Unit_Components
: Boolean := True;
3657 -- Set False if we encounter a component of a composite type whose
3658 -- RM_Size is not a multiple of the storage unit.
3660 Elem_Component_Total_Esize
: Uint
:= Uint_0
;
3661 -- Accumulates total Esize values of all elementary components. Used
3662 -- for processing of Implicit_Packing.
3664 Placed_Component
: Boolean := False;
3665 -- Set True if we find at least one component with a component
3666 -- clause (used to warn about useless Bit_Order pragmas, and also
3667 -- to detect cases where Implicit_Packing may have an effect).
3669 Rec_Pushed
: Boolean := False;
3670 -- Set True if the record type scope Rec has been pushed on the scope
3671 -- stack. Needed for the analysis of delayed aspects specified to the
3672 -- components of Rec.
3674 Sized_Component_Total_RM_Size
: Uint
:= Uint_0
;
3675 -- Accumulates total RM_Size values of all sized components. Used
3676 -- for processing of Implicit_Packing.
3679 -- Scalar_Storage_Order attribute definition clause for the record
3681 SSO_ADC_Component
: Boolean := False;
3682 -- Set True if we find at least one component whose type has a
3683 -- Scalar_Storage_Order attribute definition clause.
3685 Unplaced_Component
: Boolean := False;
3686 -- Set True if we find at least one component with no component
3687 -- clause (used to warn about useless Pack pragmas).
3689 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
3690 -- If N is an allocator, possibly wrapped in one or more level of
3691 -- qualified expression(s), return the inner allocator node, else
3694 procedure Check_Itype
(Typ
: Entity_Id
);
3695 -- If the component subtype is an access to a constrained subtype of
3696 -- an already frozen type, make the subtype frozen as well. It might
3697 -- otherwise be frozen in the wrong scope, and a freeze node on
3698 -- subtype has no effect. Similarly, if the component subtype is a
3699 -- regular (not protected) access to subprogram, set the anonymous
3700 -- subprogram type to frozen as well, to prevent an out-of-scope
3701 -- freeze node at some eventual point of call. Protected operations
3702 -- are handled elsewhere.
3704 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
3705 -- Make sure that all types mentioned in Discrete_Choices of the
3706 -- variants referenceed by the Variant_Part VP are frozen. This is
3707 -- a recursive routine to deal with nested variants.
3709 ---------------------
3710 -- Check_Allocator --
3711 ---------------------
3713 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
3718 if Nkind
(Inner
) = N_Allocator
then
3720 elsif Nkind
(Inner
) = N_Qualified_Expression
then
3721 Inner
:= Expression
(Inner
);
3726 end Check_Allocator
;
3732 procedure Check_Itype
(Typ
: Entity_Id
) is
3733 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
3736 if not Is_Frozen
(Desig
)
3737 and then Is_Frozen
(Base_Type
(Desig
))
3739 Set_Is_Frozen
(Desig
);
3741 -- In addition, add an Itype_Reference to ensure that the
3742 -- access subtype is elaborated early enough. This cannot be
3743 -- done if the subtype may depend on discriminants.
3745 if Ekind
(Comp
) = E_Component
3746 and then Is_Itype
(Etype
(Comp
))
3747 and then not Has_Discriminants
(Rec
)
3749 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
3750 Set_Itype
(IR
, Desig
);
3754 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
3755 and then Convention
(Desig
) /= Convention_Protected
3757 Set_Is_Frozen
(Desig
);
3761 ------------------------------------
3762 -- Freeze_Choices_In_Variant_Part --
3763 ------------------------------------
3765 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
3766 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
3773 -- Loop through variants
3775 Variant
:= First_Non_Pragma
(Variants
(VP
));
3776 while Present
(Variant
) loop
3778 -- Loop through choices, checking that all types are frozen
3780 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
3781 while Present
(Choice
) loop
3782 if Nkind
(Choice
) in N_Has_Etype
3783 and then Present
(Etype
(Choice
))
3785 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
3788 Next_Non_Pragma
(Choice
);
3791 -- Check for nested variant part to process
3793 CL
:= Component_List
(Variant
);
3795 if not Null_Present
(CL
) then
3796 if Present
(Variant_Part
(CL
)) then
3797 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
3801 Next_Non_Pragma
(Variant
);
3803 end Freeze_Choices_In_Variant_Part
;
3805 -- Start of processing for Freeze_Record_Type
3808 -- Deal with delayed aspect specifications for components. The
3809 -- analysis of the aspect is required to be delayed to the freeze
3810 -- point, thus we analyze the pragma or attribute definition
3811 -- clause in the tree at this point. We also analyze the aspect
3812 -- specification node at the freeze point when the aspect doesn't
3813 -- correspond to pragma/attribute definition clause.
3815 Comp
:= First_Entity
(Rec
);
3816 while Present
(Comp
) loop
3817 if Ekind
(Comp
) = E_Component
3818 and then Has_Delayed_Aspects
(Comp
)
3820 if not Rec_Pushed
then
3824 -- The visibility to the discriminants must be restored in
3825 -- order to properly analyze the aspects.
3827 if Has_Discriminants
(Rec
) then
3828 Install_Discriminants
(Rec
);
3832 Analyze_Aspects_At_Freeze_Point
(Comp
);
3838 -- Pop the scope if Rec scope has been pushed on the scope stack
3839 -- during the delayed aspect analysis process.
3842 if Has_Discriminants
(Rec
) then
3843 Uninstall_Discriminants
(Rec
);
3849 -- Freeze components and embedded subtypes
3851 Comp
:= First_Entity
(Rec
);
3853 while Present
(Comp
) loop
3854 if Is_Aliased
(Comp
) then
3855 Aliased_Component
:= True;
3858 -- Handle the component and discriminant case
3860 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
3862 CC
: constant Node_Id
:= Component_Clause
(Comp
);
3865 -- Freezing a record type freezes the type of each of its
3866 -- components. However, if the type of the component is
3867 -- part of this record, we do not want or need a separate
3868 -- Freeze_Node. Note that Is_Itype is wrong because that's
3869 -- also set in private type cases. We also can't check for
3870 -- the Scope being exactly Rec because of private types and
3871 -- record extensions.
3873 if Is_Itype
(Etype
(Comp
))
3874 and then Is_Record_Type
(Underlying_Type
3875 (Scope
(Etype
(Comp
))))
3877 Undelay_Type
(Etype
(Comp
));
3880 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
3882 -- Warn for pragma Pack overriding foreign convention
3884 if Has_Foreign_Convention
(Etype
(Comp
))
3885 and then Has_Pragma_Pack
(Rec
)
3887 -- Don't warn for aliased components, since override
3888 -- cannot happen in that case.
3890 and then not Is_Aliased
(Comp
)
3893 CN
: constant Name_Id
:=
3894 Get_Convention_Name
(Convention
(Etype
(Comp
)));
3895 PP
: constant Node_Id
:=
3896 Get_Pragma
(Rec
, Pragma_Pack
);
3898 if Present
(PP
) then
3899 Error_Msg_Name_1
:= CN
;
3900 Error_Msg_Sloc
:= Sloc
(Comp
);
3902 ("pragma Pack affects convention % component#??",
3904 Error_Msg_Name_1
:= CN
;
3906 ("\component & may not have % compatible "
3907 & "representation??", PP
, Comp
);
3912 -- Check for error of component clause given for variable
3913 -- sized type. We have to delay this test till this point,
3914 -- since the component type has to be frozen for us to know
3915 -- if it is variable length.
3917 if Present
(CC
) then
3918 Placed_Component
:= True;
3920 -- We omit this test in a generic context, it will be
3921 -- applied at instantiation time.
3923 if Inside_A_Generic
then
3926 -- Also omit this test in CodePeer mode, since we do not
3927 -- have sufficient info on size and rep clauses.
3929 elsif CodePeer_Mode
then
3932 -- Omit check if component has a generic type. This can
3933 -- happen in an instantiation within a generic in ASIS
3934 -- mode, where we force freeze actions without full
3937 elsif Is_Generic_Type
(Etype
(Comp
)) then
3943 Size_Known_At_Compile_Time
3944 (Underlying_Type
(Etype
(Comp
)))
3947 ("component clause not allowed for variable " &
3948 "length component", CC
);
3952 Unplaced_Component
:= True;
3955 -- Case of component requires byte alignment
3957 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
3959 -- Set the enclosing record to also require byte align
3961 Set_Must_Be_On_Byte_Boundary
(Rec
);
3963 -- Check for component clause that is inconsistent with
3964 -- the required byte boundary alignment.
3967 and then Normalized_First_Bit
(Comp
) mod
3968 System_Storage_Unit
/= 0
3971 ("component & must be byte aligned",
3972 Component_Name
(Component_Clause
(Comp
)));
3978 -- Gather data for possible Implicit_Packing later. Note that at
3979 -- this stage we might be dealing with a real component, or with
3980 -- an implicit subtype declaration.
3982 if Known_Static_RM_Size
(Etype
(Comp
)) then
3983 Sized_Component_Total_RM_Size
:=
3984 Sized_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
3986 if Is_Elementary_Type
(Etype
(Comp
)) then
3987 Elem_Component_Total_Esize
:=
3988 Elem_Component_Total_Esize
+ Esize
(Etype
(Comp
));
3990 All_Elem_Components
:= False;
3992 if RM_Size
(Etype
(Comp
)) mod System_Storage_Unit
/= 0 then
3993 All_Storage_Unit_Components
:= False;
3997 All_Sized_Components
:= False;
4000 -- If the component is an Itype with Delayed_Freeze and is either
4001 -- a record or array subtype and its base type has not yet been
4002 -- frozen, we must remove this from the entity list of this record
4003 -- and put it on the entity list of the scope of its base type.
4004 -- Note that we know that this is not the type of a component
4005 -- since we cleared Has_Delayed_Freeze for it in the previous
4006 -- loop. Thus this must be the Designated_Type of an access type,
4007 -- which is the type of a component.
4010 and then Is_Type
(Scope
(Comp
))
4011 and then Is_Composite_Type
(Comp
)
4012 and then Base_Type
(Comp
) /= Comp
4013 and then Has_Delayed_Freeze
(Comp
)
4014 and then not Is_Frozen
(Base_Type
(Comp
))
4017 Will_Be_Frozen
: Boolean := False;
4021 -- We have a difficult case to handle here. Suppose Rec is
4022 -- subtype being defined in a subprogram that's created as
4023 -- part of the freezing of Rec'Base. In that case, we know
4024 -- that Comp'Base must have already been frozen by the time
4025 -- we get to elaborate this because Gigi doesn't elaborate
4026 -- any bodies until it has elaborated all of the declarative
4027 -- part. But Is_Frozen will not be set at this point because
4028 -- we are processing code in lexical order.
4030 -- We detect this case by going up the Scope chain of Rec
4031 -- and seeing if we have a subprogram scope before reaching
4032 -- the top of the scope chain or that of Comp'Base. If we
4033 -- do, then mark that Comp'Base will actually be frozen. If
4034 -- so, we merely undelay it.
4037 while Present
(S
) loop
4038 if Is_Subprogram
(S
) then
4039 Will_Be_Frozen
:= True;
4041 elsif S
= Scope
(Base_Type
(Comp
)) then
4048 if Will_Be_Frozen
then
4049 Undelay_Type
(Comp
);
4052 if Present
(Prev
) then
4053 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
4055 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
4058 -- Insert in entity list of scope of base type (which
4059 -- must be an enclosing scope, because still unfrozen).
4061 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
4065 -- If the component is an access type with an allocator as default
4066 -- value, the designated type will be frozen by the corresponding
4067 -- expression in init_proc. In order to place the freeze node for
4068 -- the designated type before that for the current record type,
4071 -- Same process if the component is an array of access types,
4072 -- initialized with an aggregate. If the designated type is
4073 -- private, it cannot contain allocators, and it is premature
4074 -- to freeze the type, so we check for this as well.
4076 elsif Is_Access_Type
(Etype
(Comp
))
4077 and then Present
(Parent
(Comp
))
4078 and then Present
(Expression
(Parent
(Comp
)))
4081 Alloc
: constant Node_Id
:=
4082 Check_Allocator
(Expression
(Parent
(Comp
)));
4085 if Present
(Alloc
) then
4087 -- If component is pointer to a class-wide type, freeze
4088 -- the specific type in the expression being allocated.
4089 -- The expression may be a subtype indication, in which
4090 -- case freeze the subtype mark.
4092 if Is_Class_Wide_Type
4093 (Designated_Type
(Etype
(Comp
)))
4095 if Is_Entity_Name
(Expression
(Alloc
)) then
4097 (Entity
(Expression
(Alloc
)), N
, Result
);
4099 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
4102 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
4106 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
4107 Check_Itype
(Etype
(Comp
));
4111 (Designated_Type
(Etype
(Comp
)), N
, Result
);
4116 elsif Is_Access_Type
(Etype
(Comp
))
4117 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
4119 Check_Itype
(Etype
(Comp
));
4121 -- Freeze the designated type when initializing a component with
4122 -- an aggregate in case the aggregate contains allocators.
4125 -- type T_Ptr is access all T;
4126 -- type T_Array is array ... of T_Ptr;
4128 -- type Rec is record
4129 -- Comp : T_Array := (others => ...);
4132 elsif Is_Array_Type
(Etype
(Comp
))
4133 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
4136 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
4137 Desig_Typ
: constant Entity_Id
:=
4139 (Component_Type
(Etype
(Comp
)));
4142 -- The only case when this sort of freezing is not done is
4143 -- when the designated type is class-wide and the root type
4144 -- is the record owning the component. This scenario results
4145 -- in a circularity because the class-wide type requires
4146 -- primitives that have not been created yet as the root
4147 -- type is in the process of being frozen.
4149 -- type Rec is tagged;
4150 -- type Rec_Ptr is access all Rec'Class;
4151 -- type Rec_Array is array ... of Rec_Ptr;
4153 -- type Rec is record
4154 -- Comp : Rec_Array := (others => ...);
4157 if Is_Class_Wide_Type
(Desig_Typ
)
4158 and then Root_Type
(Desig_Typ
) = Rec
4162 elsif Is_Fully_Defined
(Desig_Typ
)
4163 and then Present
(Comp_Par
)
4164 and then Nkind
(Comp_Par
) = N_Component_Declaration
4165 and then Present
(Expression
(Comp_Par
))
4166 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
4168 Freeze_And_Append
(Desig_Typ
, N
, Result
);
4178 Get_Attribute_Definition_Clause
4179 (Rec
, Attribute_Scalar_Storage_Order
);
4181 -- If the record type has Complex_Representation, then it is treated
4182 -- as a scalar in the back end so the storage order is irrelevant.
4184 if Has_Complex_Representation
(Rec
) then
4185 if Present
(SSO_ADC
) then
4187 ("??storage order has no effect with Complex_Representation",
4192 -- Deal with default setting of reverse storage order
4194 Set_SSO_From_Default
(Rec
);
4196 -- Check consistent attribute setting on component types
4199 Comp_ADC_Present
: Boolean;
4201 Comp
:= First_Component
(Rec
);
4202 while Present
(Comp
) loop
4203 Check_Component_Storage_Order
4207 Comp_ADC_Present
=> Comp_ADC_Present
);
4208 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
4209 Next_Component
(Comp
);
4213 -- Now deal with reverse storage order/bit order issues
4215 if Present
(SSO_ADC
) then
4217 -- Check compatibility of Scalar_Storage_Order with Bit_Order,
4218 -- if the former is specified.
4220 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
4222 -- Note: report error on Rec, not on SSO_ADC, as ADC may
4223 -- apply to some ancestor type.
4225 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
4227 ("scalar storage order for& specified# inconsistent with "
4228 & "bit order", Rec
);
4231 -- Warn if there is a Scalar_Storage_Order attribute definition
4232 -- clause but no component clause, no component that itself has
4233 -- such an attribute definition, and no pragma Pack.
4235 if not (Placed_Component
4242 ("??scalar storage order specified but no component "
4243 & "clause", SSO_ADC
);
4248 -- Deal with Bit_Order aspect
4250 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
4252 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
4253 if not (Placed_Component
4254 or else Present
(SSO_ADC
)
4255 or else Is_Packed
(Rec
))
4257 -- Warn if clause has no effect when no component clause is
4258 -- present, but suppress warning if the Bit_Order is required
4259 -- due to the presence of a Scalar_Storage_Order attribute.
4262 ("??bit order specification has no effect", ADC
);
4264 ("\??since no component clauses were specified", ADC
);
4266 -- Here is where we do the processing to adjust component clauses
4267 -- for reversed bit order, when not using reverse SSO. If an error
4268 -- has been reported on Rec already (such as SSO incompatible with
4269 -- bit order), don't bother adjusting as this may generate extra
4272 elsif Reverse_Bit_Order
(Rec
)
4273 and then not Reverse_Storage_Order
(Rec
)
4274 and then not Error_Posted
(Rec
)
4276 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
4278 -- Case where we have both an explicit Bit_Order and the same
4279 -- Scalar_Storage_Order: leave record untouched, the back-end
4280 -- will take care of required layout conversions.
4288 -- Complete error checking on record representation clause (e.g.
4289 -- overlap of components). This is called after adjusting the
4290 -- record for reverse bit order.
4293 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
4295 if Present
(RRC
) then
4296 Check_Record_Representation_Clause
(RRC
);
4300 -- Set OK_To_Reorder_Components depending on debug flags
4302 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
4303 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
4305 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
4307 Set_OK_To_Reorder_Components
(Rec
);
4311 -- Check for useless pragma Pack when all components placed. We only
4312 -- do this check for record types, not subtypes, since a subtype may
4313 -- have all its components placed, and it still makes perfectly good
4314 -- sense to pack other subtypes or the parent type. We do not give
4315 -- this warning if Optimize_Alignment is set to Space, since the
4316 -- pragma Pack does have an effect in this case (it always resets
4317 -- the alignment to one).
4319 if Ekind
(Rec
) = E_Record_Type
4320 and then Is_Packed
(Rec
)
4321 and then not Unplaced_Component
4322 and then Optimize_Alignment
/= 'S'
4324 -- Reset packed status. Probably not necessary, but we do it so
4325 -- that there is no chance of the back end doing something strange
4326 -- with this redundant indication of packing.
4328 Set_Is_Packed
(Rec
, False);
4330 -- Give warning if redundant constructs warnings on
4332 if Warn_On_Redundant_Constructs
then
4333 Error_Msg_N
-- CODEFIX
4334 ("??pragma Pack has no effect, no unplaced components",
4335 Get_Rep_Pragma
(Rec
, Name_Pack
));
4339 -- If this is the record corresponding to a remote type, freeze the
4340 -- remote type here since that is what we are semantically freezing.
4341 -- This prevents the freeze node for that type in an inner scope.
4343 if Ekind
(Rec
) = E_Record_Type
then
4344 if Present
(Corresponding_Remote_Type
(Rec
)) then
4345 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
4348 -- Check for controlled components, unchecked unions, and type
4351 Comp
:= First_Component
(Rec
);
4352 while Present
(Comp
) loop
4354 -- Do not set Has_Controlled_Component on a class-wide
4355 -- equivalent type. See Make_CW_Equivalent_Type.
4357 if not Is_Class_Wide_Equivalent_Type
(Rec
)
4359 (Has_Controlled_Component
(Etype
(Comp
))
4361 (Chars
(Comp
) /= Name_uParent
4362 and then Is_Controlled_Active
(Etype
(Comp
)))
4364 (Is_Protected_Type
(Etype
(Comp
))
4366 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
4368 Has_Controlled_Component
4369 (Corresponding_Record_Type
(Etype
(Comp
)))))
4371 Set_Has_Controlled_Component
(Rec
);
4374 if Has_Unchecked_Union
(Etype
(Comp
)) then
4375 Set_Has_Unchecked_Union
(Rec
);
4378 -- The record type requires its own invariant procedure in
4379 -- order to verify the invariant of each individual component.
4380 -- Do not consider internal components such as _parent because
4381 -- parent class-wide invariants are always inherited.
4382 -- In GNATprove mode, the component invariants are checked by
4383 -- other means. They should not be added to the record type
4384 -- invariant procedure, so that the procedure can be used to
4385 -- check the recordy type invariants if any.
4387 if Comes_From_Source
(Comp
)
4388 and then Has_Invariants
(Etype
(Comp
))
4389 and then not GNATprove_Mode
4391 Set_Has_Own_Invariants
(Rec
);
4394 -- Scan component declaration for likely misuses of current
4395 -- instance, either in a constraint or a default expression.
4397 if Has_Per_Object_Constraint
(Comp
) then
4398 Check_Current_Instance
(Parent
(Comp
));
4401 Next_Component
(Comp
);
4405 -- Enforce the restriction that access attributes with a current
4406 -- instance prefix can only apply to limited types. This comment
4407 -- is floating here, but does not seem to belong here???
4409 -- Set component alignment if not otherwise already set
4411 Set_Component_Alignment_If_Not_Set
(Rec
);
4413 -- For first subtypes, check if there are any fixed-point fields with
4414 -- component clauses, where we must check the size. This is not done
4415 -- till the freeze point since for fixed-point types, we do not know
4416 -- the size until the type is frozen. Similar processing applies to
4417 -- bit-packed arrays.
4419 if Is_First_Subtype
(Rec
) then
4420 Comp
:= First_Component
(Rec
);
4421 while Present
(Comp
) loop
4422 if Present
(Component_Clause
(Comp
))
4423 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
4424 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
4427 (Component_Name
(Component_Clause
(Comp
)),
4433 Next_Component
(Comp
);
4437 -- See if Size is too small as is (and implicit packing might help)
4439 if not Is_Packed
(Rec
)
4441 -- No implicit packing if even one component is explicitly placed
4443 and then not Placed_Component
4445 -- Or even one component is aliased
4447 and then not Aliased_Component
4449 -- Must have size clause and all sized components
4451 and then Has_Size_Clause
(Rec
)
4452 and then All_Sized_Components
4454 -- Do not try implicit packing on records with discriminants, too
4455 -- complicated, especially in the variant record case.
4457 and then not Has_Discriminants
(Rec
)
4459 -- We want to implicitly pack if the specified size of the record
4460 -- is less than the sum of the object sizes (no point in packing
4461 -- if this is not the case), if we can compute it, i.e. if we have
4462 -- only elementary components. Otherwise, we have at least one
4463 -- composite component and we want to implicitly pack only if bit
4464 -- packing is required for it, as we are sure in this case that
4465 -- the back end cannot do the expected layout without packing.
4468 ((All_Elem_Components
4469 and then RM_Size
(Rec
) < Elem_Component_Total_Esize
)
4471 (not All_Elem_Components
4472 and then not All_Storage_Unit_Components
))
4474 -- And the total RM size cannot be greater than the specified size
4475 -- since otherwise packing will not get us where we have to be.
4477 and then RM_Size
(Rec
) >= Sized_Component_Total_RM_Size
4479 -- Never do implicit packing in CodePeer or SPARK modes since
4480 -- we don't do any packing in these modes, since this generates
4481 -- over-complex code that confuses static analysis, and in
4482 -- general, neither CodePeer not GNATprove care about the
4483 -- internal representation of objects.
4485 and then not (CodePeer_Mode
or GNATprove_Mode
)
4487 -- If implicit packing enabled, do it
4489 if Implicit_Packing
then
4490 Set_Is_Packed
(Rec
);
4492 -- Otherwise flag the size clause
4496 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
4498 Error_Msg_NE
-- CODEFIX
4499 ("size given for& too small", Sz
, Rec
);
4500 Error_Msg_N
-- CODEFIX
4501 ("\use explicit pragma Pack "
4502 & "or use pragma Implicit_Packing", Sz
);
4507 -- The following checks are relevant only when SPARK_Mode is on as
4508 -- they are not standard Ada legality rules.
4510 if SPARK_Mode
= On
then
4511 if Is_Effectively_Volatile
(Rec
) then
4513 -- A discriminated type cannot be effectively volatile
4514 -- (SPARK RM C.6(4)).
4516 if Has_Discriminants
(Rec
) then
4517 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
4519 -- A tagged type cannot be effectively volatile
4520 -- (SPARK RM C.6(5)).
4522 elsif Is_Tagged_Type
(Rec
) then
4523 Error_Msg_N
("tagged type & cannot be volatile", Rec
);
4526 -- A non-effectively volatile record type cannot contain
4527 -- effectively volatile components (SPARK RM C.6(2)).
4530 Comp
:= First_Component
(Rec
);
4531 while Present
(Comp
) loop
4532 if Comes_From_Source
(Comp
)
4533 and then Is_Effectively_Volatile
(Etype
(Comp
))
4535 Error_Msg_Name_1
:= Chars
(Rec
);
4537 ("component & of non-volatile type % cannot be "
4538 & "volatile", Comp
);
4541 Next_Component
(Comp
);
4545 -- A type which does not yield a synchronized object cannot have
4546 -- a component that yields a synchronized object (SPARK RM 9.5).
4548 if not Yields_Synchronized_Object
(Rec
) then
4549 Comp
:= First_Component
(Rec
);
4550 while Present
(Comp
) loop
4551 if Comes_From_Source
(Comp
)
4552 and then Yields_Synchronized_Object
(Etype
(Comp
))
4554 Error_Msg_Name_1
:= Chars
(Rec
);
4556 ("component & of non-synchronized type % cannot be "
4557 & "synchronized", Comp
);
4560 Next_Component
(Comp
);
4564 -- A Ghost type cannot have a component of protected or task type
4565 -- (SPARK RM 6.9(19)).
4567 if Is_Ghost_Entity
(Rec
) then
4568 Comp
:= First_Component
(Rec
);
4569 while Present
(Comp
) loop
4570 if Comes_From_Source
(Comp
)
4571 and then Is_Concurrent_Type
(Etype
(Comp
))
4573 Error_Msg_Name_1
:= Chars
(Rec
);
4575 ("component & of ghost type % cannot be concurrent",
4579 Next_Component
(Comp
);
4584 -- Make sure that if we have an iterator aspect, then we have
4585 -- either Constant_Indexing or Variable_Indexing.
4588 Iterator_Aspect
: Node_Id
;
4591 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Iterator_Element
);
4593 if No
(Iterator_Aspect
) then
4594 Iterator_Aspect
:= Find_Aspect
(Rec
, Aspect_Default_Iterator
);
4597 if Present
(Iterator_Aspect
) then
4598 if Has_Aspect
(Rec
, Aspect_Constant_Indexing
)
4600 Has_Aspect
(Rec
, Aspect_Variable_Indexing
)
4605 ("Iterator_Element requires indexing aspect",
4611 -- All done if not a full record definition
4613 if Ekind
(Rec
) /= E_Record_Type
then
4617 -- Finally we need to check the variant part to make sure that
4618 -- all types within choices are properly frozen as part of the
4619 -- freezing of the record type.
4621 Check_Variant_Part
: declare
4622 D
: constant Node_Id
:= Declaration_Node
(Rec
);
4627 -- Find component list
4631 if Nkind
(D
) = N_Full_Type_Declaration
then
4632 T
:= Type_Definition
(D
);
4634 if Nkind
(T
) = N_Record_Definition
then
4635 C
:= Component_List
(T
);
4637 elsif Nkind
(T
) = N_Derived_Type_Definition
4638 and then Present
(Record_Extension_Part
(T
))
4640 C
:= Component_List
(Record_Extension_Part
(T
));
4644 -- Case of variant part present
4646 if Present
(C
) and then Present
(Variant_Part
(C
)) then
4647 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
4650 -- Note: we used to call Check_Choices here, but it is too early,
4651 -- since predicated subtypes are frozen here, but their freezing
4652 -- actions are in Analyze_Freeze_Entity, which has not been called
4653 -- yet for entities frozen within this procedure, so we moved that
4654 -- call to the Analyze_Freeze_Entity for the record type.
4656 end Check_Variant_Part
;
4658 -- Check that all the primitives of an interface type are abstract
4659 -- or null procedures.
4661 if Is_Interface
(Rec
)
4662 and then not Error_Posted
(Parent
(Rec
))
4669 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
4670 while Present
(Elmt
) loop
4671 Subp
:= Node
(Elmt
);
4673 if not Is_Abstract_Subprogram
(Subp
)
4675 -- Avoid reporting the error on inherited primitives
4677 and then Comes_From_Source
(Subp
)
4679 Error_Msg_Name_1
:= Chars
(Subp
);
4681 if Ekind
(Subp
) = E_Procedure
then
4682 if not Null_Present
(Parent
(Subp
)) then
4684 ("interface procedure % must be abstract or null",
4689 ("interface function % must be abstract",
4699 -- For a derived tagged type, check whether inherited primitives
4700 -- might require a wrapper to handle class-wide conditions.
4702 if Is_Tagged_Type
(Rec
) and then Is_Derived_Type
(Rec
) then
4703 Check_Inherited_Conditions
(Rec
);
4705 end Freeze_Record_Type
;
4707 -------------------------------
4708 -- Has_Boolean_Aspect_Import --
4709 -------------------------------
4711 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
4712 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4717 if Has_Aspects
(Decl
) then
4718 Asp
:= First
(Aspect_Specifications
(Decl
));
4719 while Present
(Asp
) loop
4720 Expr
:= Expression
(Asp
);
4722 -- The value of aspect Import is True when the expression is
4723 -- either missing or it is explicitly set to True.
4725 if Get_Aspect_Id
(Asp
) = Aspect_Import
4727 or else (Compile_Time_Known_Value
(Expr
)
4728 and then Is_True
(Expr_Value
(Expr
))))
4738 end Has_Boolean_Aspect_Import
;
4740 -------------------------
4741 -- Inherit_Freeze_Node --
4742 -------------------------
4744 procedure Inherit_Freeze_Node
4748 Typ_Fnod
: constant Node_Id
:= Freeze_Node
(Typ
);
4751 Set_Freeze_Node
(Typ
, Fnod
);
4752 Set_Entity
(Fnod
, Typ
);
4754 -- The input type had an existing node. Propagate relevant attributes
4755 -- from the old freeze node to the inherited freeze node.
4757 -- ??? if both freeze nodes have attributes, would they differ?
4759 if Present
(Typ_Fnod
) then
4761 -- Attribute Access_Types_To_Process
4763 if Present
(Access_Types_To_Process
(Typ_Fnod
))
4764 and then No
(Access_Types_To_Process
(Fnod
))
4766 Set_Access_Types_To_Process
(Fnod
,
4767 Access_Types_To_Process
(Typ_Fnod
));
4770 -- Attribute Actions
4772 if Present
(Actions
(Typ_Fnod
)) and then No
(Actions
(Fnod
)) then
4773 Set_Actions
(Fnod
, Actions
(Typ_Fnod
));
4776 -- Attribute First_Subtype_Link
4778 if Present
(First_Subtype_Link
(Typ_Fnod
))
4779 and then No
(First_Subtype_Link
(Fnod
))
4781 Set_First_Subtype_Link
(Fnod
, First_Subtype_Link
(Typ_Fnod
));
4784 -- Attribute TSS_Elist
4786 if Present
(TSS_Elist
(Typ_Fnod
))
4787 and then No
(TSS_Elist
(Fnod
))
4789 Set_TSS_Elist
(Fnod
, TSS_Elist
(Typ_Fnod
));
4792 end Inherit_Freeze_Node
;
4794 ------------------------------
4795 -- Wrap_Imported_Subprogram --
4796 ------------------------------
4798 -- The issue here is that our normal approach of checking preconditions
4799 -- and postconditions does not work for imported procedures, since we
4800 -- are not generating code for the body. To get around this we create
4801 -- a wrapper, as shown by the following example:
4803 -- procedure K (A : Integer);
4804 -- pragma Import (C, K);
4806 -- The spec is rewritten by removing the effects of pragma Import, but
4807 -- leaving the convention unchanged, as though the source had said:
4809 -- procedure K (A : Integer);
4810 -- pragma Convention (C, K);
4812 -- and we create a body, added to the entity K freeze actions, which
4815 -- procedure K (A : Integer) is
4816 -- procedure K (A : Integer);
4817 -- pragma Import (C, K);
4822 -- Now the contract applies in the normal way to the outer procedure,
4823 -- and the inner procedure has no contracts, so there is no problem
4824 -- in just calling it to get the original effect.
4826 -- In the case of a function, we create an appropriate return statement
4827 -- for the subprogram body that calls the inner procedure.
4829 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
4830 function Copy_Import_Pragma
return Node_Id
;
4831 -- Obtain a copy of the Import_Pragma which belongs to subprogram E
4833 ------------------------
4834 -- Copy_Import_Pragma --
4835 ------------------------
4837 function Copy_Import_Pragma
return Node_Id
is
4839 -- The subprogram should have an import pragma, otherwise it does
4842 Prag
: constant Node_Id
:= Import_Pragma
(E
);
4843 pragma Assert
(Present
(Prag
));
4845 -- Save all semantic fields of the pragma
4847 Save_Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
4848 Save_From
: constant Boolean := From_Aspect_Specification
(Prag
);
4849 Save_Prag
: constant Node_Id
:= Next_Pragma
(Prag
);
4850 Save_Rep
: constant Node_Id
:= Next_Rep_Item
(Prag
);
4855 -- Reset all semantic fields. This avoids a potential infinite
4856 -- loop when the pragma comes from an aspect as the duplication
4857 -- will copy the aspect, then copy the corresponding pragma and
4860 Set_Corresponding_Aspect
(Prag
, Empty
);
4861 Set_From_Aspect_Specification
(Prag
, False);
4862 Set_Next_Pragma
(Prag
, Empty
);
4863 Set_Next_Rep_Item
(Prag
, Empty
);
4865 Result
:= Copy_Separate_Tree
(Prag
);
4867 -- Restore the original semantic fields
4869 Set_Corresponding_Aspect
(Prag
, Save_Asp
);
4870 Set_From_Aspect_Specification
(Prag
, Save_From
);
4871 Set_Next_Pragma
(Prag
, Save_Prag
);
4872 Set_Next_Rep_Item
(Prag
, Save_Rep
);
4875 end Copy_Import_Pragma
;
4879 Loc
: constant Source_Ptr
:= Sloc
(E
);
4880 CE
: constant Name_Id
:= Chars
(E
);
4888 -- Start of processing for Wrap_Imported_Subprogram
4891 -- Nothing to do if not imported
4893 if not Is_Imported
(E
) then
4896 -- Test enabling conditions for wrapping
4898 elsif Is_Subprogram
(E
)
4899 and then Present
(Contract
(E
))
4900 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
4901 and then not GNATprove_Mode
4903 -- Here we do the wrap
4905 -- Note on calls to Copy_Separate_Tree. The trees we are copying
4906 -- here are fully analyzed, but we definitely want fully syntactic
4907 -- unanalyzed trees in the body we construct, so that the analysis
4908 -- generates the right visibility, and that is exactly what the
4909 -- calls to Copy_Separate_Tree give us.
4911 Prag
:= Copy_Import_Pragma
;
4913 -- Fix up spec to be not imported any more
4915 Set_Has_Completion
(E
, False);
4916 Set_Import_Pragma
(E
, Empty
);
4917 Set_Interface_Name
(E
, Empty
);
4918 Set_Is_Imported
(E
, False);
4920 -- Grab the subprogram declaration and specification
4922 Spec
:= Declaration_Node
(E
);
4924 -- Build parameter list that we need
4927 Forml
:= First_Formal
(E
);
4928 while Present
(Forml
) loop
4929 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
4930 Next_Formal
(Forml
);
4935 if Ekind_In
(E
, E_Function
, E_Generic_Function
) then
4937 Make_Simple_Return_Statement
(Loc
,
4939 Make_Function_Call
(Loc
,
4940 Name
=> Make_Identifier
(Loc
, CE
),
4941 Parameter_Associations
=> Parms
));
4945 Make_Procedure_Call_Statement
(Loc
,
4946 Name
=> Make_Identifier
(Loc
, CE
),
4947 Parameter_Associations
=> Parms
);
4950 -- Now build the body
4953 Make_Subprogram_Body
(Loc
,
4955 Copy_Separate_Tree
(Spec
),
4956 Declarations
=> New_List
(
4957 Make_Subprogram_Declaration
(Loc
,
4958 Specification
=> Copy_Separate_Tree
(Spec
)),
4960 Handled_Statement_Sequence
=>
4961 Make_Handled_Sequence_Of_Statements
(Loc
,
4962 Statements
=> New_List
(Stmt
),
4963 End_Label
=> Make_Identifier
(Loc
, CE
)));
4965 -- Append the body to freeze result
4967 Add_To_Result
(Bod
);
4970 -- Case of imported subprogram that does not get wrapped
4973 -- Set Is_Public. All imported entities need an external symbol
4974 -- created for them since they are always referenced from another
4975 -- object file. Note this used to be set when we set Is_Imported
4976 -- back in Sem_Prag, but now we delay it to this point, since we
4977 -- don't want to set this flag if we wrap an imported subprogram.
4981 end Wrap_Imported_Subprogram
;
4985 Mode
: Ghost_Mode_Type
;
4987 -- Start of processing for Freeze_Entity
4990 -- The entity being frozen may be subject to pragma Ghost. Set the mode
4991 -- now to ensure that any nodes generated during freezing are properly
4992 -- flagged as Ghost.
4994 Set_Ghost_Mode
(E
, Mode
);
4996 -- We are going to test for various reasons why this entity need not be
4997 -- frozen here, but in the case of an Itype that's defined within a
4998 -- record, that test actually applies to the record.
5000 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
5001 Test_E
:= Scope
(E
);
5002 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
5003 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
5005 Test_E
:= Underlying_Type
(Scope
(E
));
5008 -- Do not freeze if already frozen since we only need one freeze node
5010 if Is_Frozen
(E
) then
5014 elsif Ekind
(E
) = E_Generic_Package
then
5015 Result
:= Freeze_Generic_Entities
(E
);
5018 -- It is improper to freeze an external entity within a generic because
5019 -- its freeze node will appear in a non-valid context. The entity will
5020 -- be frozen in the proper scope after the current generic is analyzed.
5021 -- However, aspects must be analyzed because they may be queried later
5022 -- within the generic itself, and the corresponding pragma or attribute
5023 -- definition has not been analyzed yet.
5025 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
5026 if Has_Delayed_Aspects
(E
) then
5027 Analyze_Aspects_At_Freeze_Point
(E
);
5033 -- AI05-0213: A formal incomplete type does not freeze the actual. In
5034 -- the instance, the same applies to the subtype renaming the actual.
5036 elsif Is_Private_Type
(E
)
5037 and then Is_Generic_Actual_Type
(E
)
5038 and then No
(Full_View
(Base_Type
(E
)))
5039 and then Ada_Version
>= Ada_2012
5044 -- Formal subprograms are never frozen
5046 elsif Is_Formal_Subprogram
(E
) then
5050 -- Generic types are never frozen as they lack delayed semantic checks
5052 elsif Is_Generic_Type
(E
) then
5056 -- Do not freeze a global entity within an inner scope created during
5057 -- expansion. A call to subprogram E within some internal procedure
5058 -- (a stream attribute for example) might require freezing E, but the
5059 -- freeze node must appear in the same declarative part as E itself.
5060 -- The two-pass elaboration mechanism in gigi guarantees that E will
5061 -- be frozen before the inner call is elaborated. We exclude constants
5062 -- from this test, because deferred constants may be frozen early, and
5063 -- must be diagnosed (e.g. in the case of a deferred constant being used
5064 -- in a default expression). If the enclosing subprogram comes from
5065 -- source, or is a generic instance, then the freeze point is the one
5066 -- mandated by the language, and we freeze the entity. A subprogram that
5067 -- is a child unit body that acts as a spec does not have a spec that
5068 -- comes from source, but can only come from source.
5070 elsif In_Open_Scopes
(Scope
(Test_E
))
5071 and then Scope
(Test_E
) /= Current_Scope
5072 and then Ekind
(Test_E
) /= E_Constant
5079 while Present
(S
) loop
5080 if Is_Overloadable
(S
) then
5081 if Comes_From_Source
(S
)
5082 or else Is_Generic_Instance
(S
)
5083 or else Is_Child_Unit
(S
)
5096 -- Similarly, an inlined instance body may make reference to global
5097 -- entities, but these references cannot be the proper freezing point
5098 -- for them, and in the absence of inlining freezing will take place in
5099 -- their own scope. Normally instance bodies are analyzed after the
5100 -- enclosing compilation, and everything has been frozen at the proper
5101 -- place, but with front-end inlining an instance body is compiled
5102 -- before the end of the enclosing scope, and as a result out-of-order
5103 -- freezing must be prevented.
5105 elsif Front_End_Inlining
5106 and then In_Instance_Body
5107 and then Present
(Scope
(Test_E
))
5113 S
:= Scope
(Test_E
);
5114 while Present
(S
) loop
5115 if Is_Generic_Instance
(S
) then
5129 -- Add checks to detect proper initialization of scalars that may appear
5130 -- as subprogram parameters.
5132 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
5133 Apply_Parameter_Validity_Checks
(E
);
5136 -- Deal with delayed aspect specifications. The analysis of the aspect
5137 -- is required to be delayed to the freeze point, thus we analyze the
5138 -- pragma or attribute definition clause in the tree at this point. We
5139 -- also analyze the aspect specification node at the freeze point when
5140 -- the aspect doesn't correspond to pragma/attribute definition clause.
5142 if Has_Delayed_Aspects
(E
) then
5143 Analyze_Aspects_At_Freeze_Point
(E
);
5146 -- Here to freeze the entity
5150 -- Case of entity being frozen is other than a type
5152 if not Is_Type
(E
) then
5154 -- If entity is exported or imported and does not have an external
5155 -- name, now is the time to provide the appropriate default name.
5156 -- Skip this if the entity is stubbed, since we don't need a name
5157 -- for any stubbed routine. For the case on intrinsics, if no
5158 -- external name is specified, then calls will be handled in
5159 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
5160 -- external name is provided, then Expand_Intrinsic_Call leaves
5161 -- calls in place for expansion by GIGI.
5163 if (Is_Imported
(E
) or else Is_Exported
(E
))
5164 and then No
(Interface_Name
(E
))
5165 and then Convention
(E
) /= Convention_Stubbed
5166 and then Convention
(E
) /= Convention_Intrinsic
5168 Set_Encoded_Interface_Name
5169 (E
, Get_Default_External_Name
(E
));
5171 -- If entity is an atomic object appearing in a declaration and
5172 -- the expression is an aggregate, assign it to a temporary to
5173 -- ensure that the actual assignment is done atomically rather
5174 -- than component-wise (the assignment to the temp may be done
5175 -- component-wise, but that is harmless).
5177 elsif Is_Atomic_Or_VFA
(E
)
5178 and then Nkind
(Parent
(E
)) = N_Object_Declaration
5179 and then Present
(Expression
(Parent
(E
)))
5180 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
5181 and then Is_Atomic_VFA_Aggregate
(Expression
(Parent
(E
)))
5188 if Is_Subprogram
(E
) then
5190 -- Check for needing to wrap imported subprogram
5192 Wrap_Imported_Subprogram
(E
);
5194 -- Freeze all parameter types and the return type (RM 13.14(14)).
5195 -- However skip this for internal subprograms. This is also where
5196 -- any extra formal parameters are created since we now know
5197 -- whether the subprogram will use a foreign convention.
5199 -- In Ada 2012, freezing a subprogram does not always freeze the
5200 -- corresponding profile (see AI05-019). An attribute reference
5201 -- is not a freezing point of the profile. Flag Do_Freeze_Profile
5202 -- indicates whether the profile should be frozen now.
5203 -- Other constructs that should not freeze ???
5205 -- This processing doesn't apply to internal entities (see below)
5207 if not Is_Internal
(E
) and then Do_Freeze_Profile
then
5208 if not Freeze_Profile
(E
) then
5213 -- Must freeze its parent first if it is a derived subprogram
5215 if Present
(Alias
(E
)) then
5216 Freeze_And_Append
(Alias
(E
), N
, Result
);
5219 -- We don't freeze internal subprograms, because we don't normally
5220 -- want addition of extra formals or mechanism setting to happen
5221 -- for those. However we do pass through predefined dispatching
5222 -- cases, since extra formals may be needed in some cases, such as
5223 -- for the stream 'Input function (build-in-place formals).
5225 if not Is_Internal
(E
)
5226 or else Is_Predefined_Dispatching_Operation
(E
)
5228 Freeze_Subprogram
(E
);
5231 -- If warning on suspicious contracts then check for the case of
5232 -- a postcondition other than False for a No_Return subprogram.
5235 and then Warn_On_Suspicious_Contract
5236 and then Present
(Contract
(E
))
5239 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
5243 while Present
(Prag
) loop
5244 if Nam_In
(Pragma_Name_Unmapped
(Prag
),
5251 (First
(Pragma_Argument_Associations
(Prag
)));
5253 if Nkind
(Exp
) /= N_Identifier
5254 or else Chars
(Exp
) /= Name_False
5257 ("useless postcondition, & is marked "
5258 & "No_Return?T?", Exp
, E
);
5262 Prag
:= Next_Pragma
(Prag
);
5267 -- Here for other than a subprogram or type
5270 -- If entity has a type, and it is not a generic unit, then
5271 -- freeze it first (RM 13.14(10)).
5273 if Present
(Etype
(E
))
5274 and then Ekind
(E
) /= E_Generic_Function
5276 Freeze_And_Append
(Etype
(E
), N
, Result
);
5278 -- For an object of an anonymous array type, aspects on the
5279 -- object declaration apply to the type itself. This is the
5280 -- case for Atomic_Components, Volatile_Components, and
5281 -- Independent_Components. In these cases analysis of the
5282 -- generated pragma will mark the anonymous types accordingly,
5283 -- and the object itself does not require a freeze node.
5285 if Ekind
(E
) = E_Variable
5286 and then Is_Itype
(Etype
(E
))
5287 and then Is_Array_Type
(Etype
(E
))
5288 and then Has_Delayed_Aspects
(E
)
5290 Set_Has_Delayed_Aspects
(E
, False);
5291 Set_Has_Delayed_Freeze
(E
, False);
5292 Set_Freeze_Node
(E
, Empty
);
5296 -- Special processing for objects created by object declaration
5298 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
5299 Freeze_Object_Declaration
(E
);
5302 -- Check that a constant which has a pragma Volatile[_Components]
5303 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
5305 -- Note: Atomic[_Components] also sets Volatile[_Components]
5307 if Ekind
(E
) = E_Constant
5308 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
5309 and then not Is_Imported
(E
)
5310 and then not Has_Boolean_Aspect_Import
(E
)
5312 -- Make sure we actually have a pragma, and have not merely
5313 -- inherited the indication from elsewhere (e.g. an address
5314 -- clause, which is not good enough in RM terms).
5316 if Has_Rep_Pragma
(E
, Name_Atomic
)
5318 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
5321 ("stand alone atomic constant must be " &
5322 "imported (RM C.6(13))", E
);
5324 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
5326 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
5329 ("stand alone volatile constant must be " &
5330 "imported (RM C.6(13))", E
);
5334 -- Static objects require special handling
5336 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
5337 and then Is_Statically_Allocated
(E
)
5339 Freeze_Static_Object
(E
);
5342 -- Remaining step is to layout objects
5344 if Ekind_In
(E
, E_Variable
, E_Constant
, E_Loop_Parameter
)
5345 or else Is_Formal
(E
)
5350 -- For an object that does not have delayed freezing, and whose
5351 -- initialization actions have been captured in a compound
5352 -- statement, move them back now directly within the enclosing
5353 -- statement sequence.
5355 if Ekind_In
(E
, E_Constant
, E_Variable
)
5356 and then not Has_Delayed_Freeze
(E
)
5358 Explode_Initialization_Compound_Statement
(E
);
5362 -- Case of a type or subtype being frozen
5365 -- We used to check here that a full type must have preelaborable
5366 -- initialization if it completes a private type specified with
5367 -- pragma Preelaborable_Initialization, but that missed cases where
5368 -- the types occur within a generic package, since the freezing
5369 -- that occurs within a containing scope generally skips traversal
5370 -- of a generic unit's declarations (those will be frozen within
5371 -- instances). This check was moved to Analyze_Package_Specification.
5373 -- The type may be defined in a generic unit. This can occur when
5374 -- freezing a generic function that returns the type (which is
5375 -- defined in a parent unit). It is clearly meaningless to freeze
5376 -- this type. However, if it is a subtype, its size may be determi-
5377 -- nable and used in subsequent checks, so might as well try to
5380 -- In Ada 2012, Freeze_Entities is also used in the front end to
5381 -- trigger the analysis of aspect expressions, so in this case we
5382 -- want to continue the freezing process.
5384 -- Is_Generic_Unit (Scope (E)) is dubious here, do we want instead
5385 -- In_Generic_Scope (E)???
5387 if Present
(Scope
(E
))
5388 and then Is_Generic_Unit
(Scope
(E
))
5390 (not Has_Predicates
(E
)
5391 and then not Has_Delayed_Freeze
(E
))
5393 Check_Compile_Time_Size
(E
);
5398 -- Check for error of Type_Invariant'Class applied to an untagged
5399 -- type (check delayed to freeze time when full type is available).
5402 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
5405 and then Class_Present
(Prag
)
5406 and then not Is_Tagged_Type
(E
)
5409 ("Type_Invariant''Class cannot be specified for &", Prag
, E
);
5411 ("\can only be specified for a tagged type", Prag
);
5415 if Is_Ghost_Entity
(E
) then
5417 -- A Ghost type cannot be concurrent (SPARK RM 6.9(19)). Verify
5418 -- this legality rule first to five a finer-grained diagnostic.
5420 if Is_Concurrent_Type
(E
) then
5421 Error_Msg_N
("ghost type & cannot be concurrent", E
);
5423 -- A Ghost type cannot be effectively volatile (SPARK RM 6.9(7))
5425 elsif Is_Effectively_Volatile
(E
) then
5426 Error_Msg_N
("ghost type & cannot be volatile", E
);
5430 -- Deal with special cases of freezing for subtype
5432 if E
/= Base_Type
(E
) then
5434 -- Before we do anything else, a specific test for the case of a
5435 -- size given for an array where the array would need to be packed
5436 -- in order for the size to be honored, but is not. This is the
5437 -- case where implicit packing may apply. The reason we do this so
5438 -- early is that, if we have implicit packing, the layout of the
5439 -- base type is affected, so we must do this before we freeze the
5442 -- We could do this processing only if implicit packing is enabled
5443 -- since in all other cases, the error would be caught by the back
5444 -- end. However, we choose to do the check even if we do not have
5445 -- implicit packing enabled, since this allows us to give a more
5446 -- useful error message (advising use of pragma Implicit_Packing
5449 if Is_Array_Type
(E
) then
5451 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
5452 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
5453 SZ
: constant Node_Id
:= Size_Clause
(E
);
5454 Btyp
: constant Entity_Id
:= Base_Type
(E
);
5461 Num_Elmts
: Uint
:= Uint_1
;
5462 -- Number of elements in array
5465 -- Check enabling conditions. These are straightforward
5466 -- except for the test for a limited composite type. This
5467 -- eliminates the rare case of a array of limited components
5468 -- where there are issues of whether or not we can go ahead
5469 -- and pack the array (since we can't freely pack and unpack
5470 -- arrays if they are limited).
5472 -- Note that we check the root type explicitly because the
5473 -- whole point is we are doing this test before we have had
5474 -- a chance to freeze the base type (and it is that freeze
5475 -- action that causes stuff to be inherited).
5477 -- The conditions on the size are identical to those used in
5478 -- Freeze_Array_Type to set the Is_Packed flag.
5480 if Has_Size_Clause
(E
)
5481 and then Known_Static_RM_Size
(E
)
5482 and then not Is_Packed
(E
)
5483 and then not Has_Pragma_Pack
(E
)
5484 and then not Has_Component_Size_Clause
(E
)
5485 and then Known_Static_RM_Size
(Ctyp
)
5487 and then not (Addressable
(Rsiz
)
5488 and then Known_Static_Esize
(Ctyp
)
5489 and then Esize
(Ctyp
) = Rsiz
)
5490 and then not (Rsiz
mod System_Storage_Unit
= 0
5491 and then Is_Composite_Type
(Ctyp
))
5492 and then not Is_Limited_Composite
(E
)
5493 and then not Is_Packed
(Root_Type
(E
))
5494 and then not Has_Component_Size_Clause
(Root_Type
(E
))
5495 and then not (CodePeer_Mode
or GNATprove_Mode
)
5497 -- Compute number of elements in array
5499 Indx
:= First_Index
(E
);
5500 while Present
(Indx
) loop
5501 Get_Index_Bounds
(Indx
, Lo
, Hi
);
5503 if not (Compile_Time_Known_Value
(Lo
)
5505 Compile_Time_Known_Value
(Hi
))
5507 goto No_Implicit_Packing
;
5510 Dim
:= Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1;
5513 Num_Elmts
:= Num_Elmts
* Dim
;
5515 Num_Elmts
:= Uint_0
;
5521 -- What we are looking for here is the situation where
5522 -- the RM_Size given would be exactly right if there was
5523 -- a pragma Pack, resulting in the component size being
5524 -- the RM_Size of the component type.
5526 if RM_Size
(E
) = Num_Elmts
* Rsiz
then
5528 -- For implicit packing mode, just set the component
5529 -- size and Freeze_Array_Type will do the rest.
5531 if Implicit_Packing
then
5532 Set_Component_Size
(Btyp
, Rsiz
);
5534 -- Otherwise give an error message
5538 ("size given for& too small", SZ
, E
);
5539 Error_Msg_N
-- CODEFIX
5540 ("\use explicit pragma Pack or use pragma "
5541 & "Implicit_Packing", SZ
);
5548 <<No_Implicit_Packing
>>
5550 -- If ancestor subtype present, freeze that first. Note that this
5551 -- will also get the base type frozen. Need RM reference ???
5553 Atype
:= Ancestor_Subtype
(E
);
5555 if Present
(Atype
) then
5556 Freeze_And_Append
(Atype
, N
, Result
);
5558 -- No ancestor subtype present
5561 -- See if we have a nearest ancestor that has a predicate.
5562 -- That catches the case of derived type with a predicate.
5563 -- Need RM reference here ???
5565 Atype
:= Nearest_Ancestor
(E
);
5567 if Present
(Atype
) and then Has_Predicates
(Atype
) then
5568 Freeze_And_Append
(Atype
, N
, Result
);
5571 -- Freeze base type before freezing the entity (RM 13.14(15))
5573 if E
/= Base_Type
(E
) then
5574 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
5578 -- A subtype inherits all the type-related representation aspects
5579 -- from its parents (RM 13.1(8)).
5581 Inherit_Aspects_At_Freeze_Point
(E
);
5583 -- For a derived type, freeze its parent type first (RM 13.14(15))
5585 elsif Is_Derived_Type
(E
) then
5586 Freeze_And_Append
(Etype
(E
), N
, Result
);
5587 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
5589 -- A derived type inherits each type-related representation aspect
5590 -- of its parent type that was directly specified before the
5591 -- declaration of the derived type (RM 13.1(15)).
5593 Inherit_Aspects_At_Freeze_Point
(E
);
5596 -- Check for incompatible size and alignment for record type
5598 if Warn_On_Size_Alignment
5599 and then Is_Record_Type
(E
)
5600 and then Has_Size_Clause
(E
) and then Has_Alignment_Clause
(E
)
5602 -- If explicit Object_Size clause given assume that the programmer
5603 -- knows what he is doing, and expects the compiler behavior.
5605 and then not Has_Object_Size_Clause
(E
)
5607 -- Check for size not a multiple of alignment
5609 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
5612 SC
: constant Node_Id
:= Size_Clause
(E
);
5613 AC
: constant Node_Id
:= Alignment_Clause
(E
);
5615 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
5618 if Present
(SC
) and then Present
(AC
) then
5622 if Sloc
(SC
) > Sloc
(AC
) then
5625 ("?Z?size is not a multiple of alignment for &",
5627 Error_Msg_Sloc
:= Sloc
(AC
);
5628 Error_Msg_Uint_1
:= Alignment
(E
);
5629 Error_Msg_N
("\?Z?alignment of ^ specified #", Loc
);
5634 ("?Z?size is not a multiple of alignment for &",
5636 Error_Msg_Sloc
:= Sloc
(SC
);
5637 Error_Msg_Uint_1
:= RM_Size
(E
);
5638 Error_Msg_N
("\?Z?size of ^ specified #", Loc
);
5641 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
5642 Error_Msg_N
("\?Z?Object_Size will be increased to ^", Loc
);
5649 if Is_Array_Type
(E
) then
5650 Freeze_Array_Type
(E
);
5652 -- For a class-wide type, the corresponding specific type is
5653 -- frozen as well (RM 13.14(15))
5655 elsif Is_Class_Wide_Type
(E
) then
5656 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
5658 -- If the base type of the class-wide type is still incomplete,
5659 -- the class-wide remains unfrozen as well. This is legal when
5660 -- E is the formal of a primitive operation of some other type
5661 -- which is being frozen.
5663 if not Is_Frozen
(Root_Type
(E
)) then
5664 Set_Is_Frozen
(E
, False);
5668 -- The equivalent type associated with a class-wide subtype needs
5669 -- to be frozen to ensure that its layout is done.
5671 if Ekind
(E
) = E_Class_Wide_Subtype
5672 and then Present
(Equivalent_Type
(E
))
5674 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5677 -- Generate an itype reference for a library-level class-wide type
5678 -- at the freeze point. Otherwise the first explicit reference to
5679 -- the type may appear in an inner scope which will be rejected by
5683 and then Is_Compilation_Unit
(Scope
(E
))
5686 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
5691 -- From a gigi point of view, a class-wide subtype derives
5692 -- from its record equivalent type. As a result, the itype
5693 -- reference must appear after the freeze node of the
5694 -- equivalent type or gigi will reject the reference.
5696 if Ekind
(E
) = E_Class_Wide_Subtype
5697 and then Present
(Equivalent_Type
(E
))
5699 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
5701 Add_To_Result
(Ref
);
5706 -- For a record type or record subtype, freeze all component types
5707 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
5708 -- using Is_Record_Type, because we don't want to attempt the freeze
5709 -- for the case of a private type with record extension (we will do
5710 -- that later when the full type is frozen).
5712 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
) then
5713 if not In_Generic_Scope
(E
) then
5714 Freeze_Record_Type
(E
);
5717 -- Report a warning if a discriminated record base type has a
5718 -- convention with language C or C++ applied to it. This check is
5719 -- done even within generic scopes (but not in instantiations),
5720 -- which is why we don't do it as part of Freeze_Record_Type.
5722 Check_Suspicious_Convention
(E
);
5724 -- For a concurrent type, freeze corresponding record type. This does
5725 -- not correspond to any specific rule in the RM, but the record type
5726 -- is essentially part of the concurrent type. Also freeze all local
5727 -- entities. This includes record types created for entry parameter
5728 -- blocks and whatever local entities may appear in the private part.
5730 elsif Is_Concurrent_Type
(E
) then
5731 if Present
(Corresponding_Record_Type
(E
)) then
5732 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
5735 Comp
:= First_Entity
(E
);
5736 while Present
(Comp
) loop
5737 if Is_Type
(Comp
) then
5738 Freeze_And_Append
(Comp
, N
, Result
);
5740 elsif (Ekind
(Comp
)) /= E_Function
then
5742 -- The guard on the presence of the Etype seems to be needed
5743 -- for some CodePeer (-gnatcC) cases, but not clear why???
5745 if Present
(Etype
(Comp
)) then
5746 if Is_Itype
(Etype
(Comp
))
5747 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
5749 Undelay_Type
(Etype
(Comp
));
5752 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5759 -- Private types are required to point to the same freeze node as
5760 -- their corresponding full views. The freeze node itself has to
5761 -- point to the partial view of the entity (because from the partial
5762 -- view, we can retrieve the full view, but not the reverse).
5763 -- However, in order to freeze correctly, we need to freeze the full
5764 -- view. If we are freezing at the end of a scope (or within the
5765 -- scope) of the private type, the partial and full views will have
5766 -- been swapped, the full view appears first in the entity chain and
5767 -- the swapping mechanism ensures that the pointers are properly set
5770 -- If we encounter the partial view before the full view (e.g. when
5771 -- freezing from another scope), we freeze the full view, and then
5772 -- set the pointers appropriately since we cannot rely on swapping to
5773 -- fix things up (subtypes in an outer scope might not get swapped).
5775 -- If the full view is itself private, the above requirements apply
5776 -- to the underlying full view instead of the full view. But there is
5777 -- no swapping mechanism for the underlying full view so we need to
5778 -- set the pointers appropriately in both cases.
5780 elsif Is_Incomplete_Or_Private_Type
(E
)
5781 and then not Is_Generic_Type
(E
)
5783 -- The construction of the dispatch table associated with library
5784 -- level tagged types forces freezing of all the primitives of the
5785 -- type, which may cause premature freezing of the partial view.
5789 -- type T is tagged private;
5790 -- type DT is new T with private;
5791 -- procedure Prim (X : in out T; Y : in out DT'Class);
5793 -- type T is tagged null record;
5795 -- type DT is new T with null record;
5798 -- In this case the type will be frozen later by the usual
5799 -- mechanism: an object declaration, an instantiation, or the
5800 -- end of a declarative part.
5802 if Is_Library_Level_Tagged_Type
(E
)
5803 and then not Present
(Full_View
(E
))
5805 Set_Is_Frozen
(E
, False);
5808 -- Case of full view present
5810 elsif Present
(Full_View
(E
)) then
5812 -- If full view has already been frozen, then no further
5813 -- processing is required
5815 if Is_Frozen
(Full_View
(E
)) then
5816 Set_Has_Delayed_Freeze
(E
, False);
5817 Set_Freeze_Node
(E
, Empty
);
5819 -- Otherwise freeze full view and patch the pointers so that
5820 -- the freeze node will elaborate both views in the back end.
5821 -- However, if full view is itself private, freeze underlying
5822 -- full view instead and patch the pointers so that the freeze
5823 -- node will elaborate the three views in the back end.
5827 Full
: Entity_Id
:= Full_View
(E
);
5830 if Is_Private_Type
(Full
)
5831 and then Present
(Underlying_Full_View
(Full
))
5833 Full
:= Underlying_Full_View
(Full
);
5836 Freeze_And_Append
(Full
, N
, Result
);
5838 if Full
/= Full_View
(E
)
5839 and then Has_Delayed_Freeze
(Full_View
(E
))
5841 F_Node
:= Freeze_Node
(Full
);
5843 if Present
(F_Node
) then
5846 Typ
=> Full_View
(E
));
5848 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
5849 Set_Freeze_Node
(Full_View
(E
), Empty
);
5853 if Has_Delayed_Freeze
(E
) then
5854 F_Node
:= Freeze_Node
(Full_View
(E
));
5856 if Present
(F_Node
) then
5861 -- {Incomplete,Private}_Subtypes with Full_Views
5862 -- constrained by discriminants.
5864 Set_Has_Delayed_Freeze
(E
, False);
5865 Set_Freeze_Node
(E
, Empty
);
5871 Check_Debug_Info_Needed
(E
);
5873 -- AI-117 requires that the convention of a partial view be the
5874 -- same as the convention of the full view. Note that this is a
5875 -- recognized breach of privacy, but it's essential for logical
5876 -- consistency of representation, and the lack of a rule in
5877 -- RM95 was an oversight.
5879 Set_Convention
(E
, Convention
(Full_View
(E
)));
5881 Set_Size_Known_At_Compile_Time
(E
,
5882 Size_Known_At_Compile_Time
(Full_View
(E
)));
5884 -- Size information is copied from the full view to the
5885 -- incomplete or private view for consistency.
5887 -- We skip this is the full view is not a type. This is very
5888 -- strange of course, and can only happen as a result of
5889 -- certain illegalities, such as a premature attempt to derive
5890 -- from an incomplete type.
5892 if Is_Type
(Full_View
(E
)) then
5893 Set_Size_Info
(E
, Full_View
(E
));
5894 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
5899 -- Case of underlying full view present
5901 elsif Is_Private_Type
(E
)
5902 and then Present
(Underlying_Full_View
(E
))
5904 if not Is_Frozen
(Underlying_Full_View
(E
)) then
5905 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
5908 -- Patch the pointers so that the freeze node will elaborate
5909 -- both views in the back end.
5911 if Has_Delayed_Freeze
(E
) then
5912 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
5914 if Present
(F_Node
) then
5919 Set_Has_Delayed_Freeze
(E
, False);
5920 Set_Freeze_Node
(E
, Empty
);
5924 Check_Debug_Info_Needed
(E
);
5928 -- Case of no full view present. If entity is derived or subtype,
5929 -- it is safe to freeze, correctness depends on the frozen status
5930 -- of parent. Otherwise it is either premature usage, or a Taft
5931 -- amendment type, so diagnosis is at the point of use and the
5932 -- type might be frozen later.
5934 elsif E
/= Base_Type
(E
) or else Is_Derived_Type
(E
) then
5938 Set_Is_Frozen
(E
, False);
5943 -- For access subprogram, freeze types of all formals, the return
5944 -- type was already frozen, since it is the Etype of the function.
5945 -- Formal types can be tagged Taft amendment types, but otherwise
5946 -- they cannot be incomplete.
5948 elsif Ekind
(E
) = E_Subprogram_Type
then
5949 Formal
:= First_Formal
(E
);
5950 while Present
(Formal
) loop
5951 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
5952 and then No
(Full_View
(Etype
(Formal
)))
5954 if Is_Tagged_Type
(Etype
(Formal
)) then
5957 -- AI05-151: Incomplete types are allowed in access to
5958 -- subprogram specifications.
5960 elsif Ada_Version
< Ada_2012
then
5962 ("invalid use of incomplete type&", E
, Etype
(Formal
));
5966 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
5967 Next_Formal
(Formal
);
5970 Freeze_Subprogram
(E
);
5972 -- For access to a protected subprogram, freeze the equivalent type
5973 -- (however this is not set if we are not generating code or if this
5974 -- is an anonymous type used just for resolution).
5976 elsif Is_Access_Protected_Subprogram_Type
(E
) then
5977 if Present
(Equivalent_Type
(E
)) then
5978 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5982 -- Generic types are never seen by the back-end, and are also not
5983 -- processed by the expander (since the expander is turned off for
5984 -- generic processing), so we never need freeze nodes for them.
5986 if Is_Generic_Type
(E
) then
5990 -- Some special processing for non-generic types to complete
5991 -- representation details not known till the freeze point.
5993 if Is_Fixed_Point_Type
(E
) then
5994 Freeze_Fixed_Point_Type
(E
);
5996 -- Some error checks required for ordinary fixed-point type. Defer
5997 -- these till the freeze-point since we need the small and range
5998 -- values. We only do these checks for base types
6000 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
6001 if Small_Value
(E
) < Ureal_2_M_80
then
6002 Error_Msg_Name_1
:= Name_Small
;
6004 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
6006 elsif Small_Value
(E
) > Ureal_2_80
then
6007 Error_Msg_Name_1
:= Name_Small
;
6009 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
6012 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
6013 Error_Msg_Name_1
:= Name_First
;
6015 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
6018 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
6019 Error_Msg_Name_1
:= Name_Last
;
6021 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
6025 elsif Is_Enumeration_Type
(E
) then
6026 Freeze_Enumeration_Type
(E
);
6028 elsif Is_Integer_Type
(E
) then
6029 Adjust_Esize_For_Alignment
(E
);
6031 if Is_Modular_Integer_Type
(E
)
6032 and then Warn_On_Suspicious_Modulus_Value
6034 Check_Suspicious_Modulus
(E
);
6037 -- The pool applies to named and anonymous access types, but not
6038 -- to subprogram and to internal types generated for 'Access
6041 elsif Is_Access_Type
(E
)
6042 and then not Is_Access_Subprogram_Type
(E
)
6043 and then Ekind
(E
) /= E_Access_Attribute_Type
6045 -- If a pragma Default_Storage_Pool applies, and this type has no
6046 -- Storage_Pool or Storage_Size clause (which must have occurred
6047 -- before the freezing point), then use the default. This applies
6048 -- only to base types.
6050 -- None of this applies to access to subprograms, for which there
6051 -- are clearly no pools.
6053 if Present
(Default_Pool
)
6054 and then Is_Base_Type
(E
)
6055 and then not Has_Storage_Size_Clause
(E
)
6056 and then No
(Associated_Storage_Pool
(E
))
6058 -- Case of pragma Default_Storage_Pool (null)
6060 if Nkind
(Default_Pool
) = N_Null
then
6061 Set_No_Pool_Assigned
(E
);
6063 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
6066 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
6070 -- Check restriction for standard storage pool
6072 if No
(Associated_Storage_Pool
(E
)) then
6073 Check_Restriction
(No_Standard_Storage_Pools
, E
);
6076 -- Deal with error message for pure access type. This is not an
6077 -- error in Ada 2005 if there is no pool (see AI-366).
6079 if Is_Pure_Unit_Access_Type
(E
)
6080 and then (Ada_Version
< Ada_2005
6081 or else not No_Pool_Assigned
(E
))
6082 and then not Is_Generic_Unit
(Scope
(E
))
6084 Error_Msg_N
("named access type not allowed in pure unit", E
);
6086 if Ada_Version
>= Ada_2005
then
6088 ("\would be legal if Storage_Size of 0 given??", E
);
6090 elsif No_Pool_Assigned
(E
) then
6092 ("\would be legal in Ada 2005??", E
);
6096 ("\would be legal in Ada 2005 if "
6097 & "Storage_Size of 0 given??", E
);
6102 -- Case of composite types
6104 if Is_Composite_Type
(E
) then
6106 -- AI-117 requires that all new primitives of a tagged type must
6107 -- inherit the convention of the full view of the type. Inherited
6108 -- and overriding operations are defined to inherit the convention
6109 -- of their parent or overridden subprogram (also specified in
6110 -- AI-117), which will have occurred earlier (in Derive_Subprogram
6111 -- and New_Overloaded_Entity). Here we set the convention of
6112 -- primitives that are still convention Ada, which will ensure
6113 -- that any new primitives inherit the type's convention. Class-
6114 -- wide types can have a foreign convention inherited from their
6115 -- specific type, but are excluded from this since they don't have
6116 -- any associated primitives.
6118 if Is_Tagged_Type
(E
)
6119 and then not Is_Class_Wide_Type
(E
)
6120 and then Convention
(E
) /= Convention_Ada
6123 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
6127 Prim
:= First_Elmt
(Prim_List
);
6128 while Present
(Prim
) loop
6129 if Convention
(Node
(Prim
)) = Convention_Ada
then
6130 Set_Convention
(Node
(Prim
), Convention
(E
));
6138 -- If the type is a simple storage pool type, then this is where
6139 -- we attempt to locate and validate its Allocate, Deallocate, and
6140 -- Storage_Size operations (the first is required, and the latter
6141 -- two are optional). We also verify that the full type for a
6142 -- private type is allowed to be a simple storage pool type.
6144 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
6145 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
6147 -- If the type is marked Has_Private_Declaration, then this is
6148 -- a full type for a private type that was specified with the
6149 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
6150 -- pragma is allowed for the full type (for example, it can't
6151 -- be an array type, or a nonlimited record type).
6153 if Has_Private_Declaration
(E
) then
6154 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
6155 and then not Is_Private_Type
(E
)
6157 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
6159 ("pragma% can only apply to full type that is an " &
6160 "explicitly limited type", E
);
6164 Validate_Simple_Pool_Ops
: declare
6165 Pool_Type
: Entity_Id
renames E
;
6166 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
6167 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
6169 procedure Validate_Simple_Pool_Op_Formal
6170 (Pool_Op
: Entity_Id
;
6171 Pool_Op_Formal
: in out Entity_Id
;
6172 Expected_Mode
: Formal_Kind
;
6173 Expected_Type
: Entity_Id
;
6174 Formal_Name
: String;
6175 OK_Formal
: in out Boolean);
6176 -- Validate one formal Pool_Op_Formal of the candidate pool
6177 -- operation Pool_Op. The formal must be of Expected_Type
6178 -- and have mode Expected_Mode. OK_Formal will be set to
6179 -- False if the formal doesn't match. If OK_Formal is False
6180 -- on entry, then the formal will effectively be ignored
6181 -- (because validation of the pool op has already failed).
6182 -- Upon return, Pool_Op_Formal will be updated to the next
6185 procedure Validate_Simple_Pool_Operation
6186 (Op_Name
: Name_Id
);
6187 -- Search for and validate a simple pool operation with the
6188 -- name Op_Name. If the name is Allocate, then there must be
6189 -- exactly one such primitive operation for the simple pool
6190 -- type. If the name is Deallocate or Storage_Size, then
6191 -- there can be at most one such primitive operation. The
6192 -- profile of the located primitive must conform to what
6193 -- is expected for each operation.
6195 ------------------------------------
6196 -- Validate_Simple_Pool_Op_Formal --
6197 ------------------------------------
6199 procedure Validate_Simple_Pool_Op_Formal
6200 (Pool_Op
: Entity_Id
;
6201 Pool_Op_Formal
: in out Entity_Id
;
6202 Expected_Mode
: Formal_Kind
;
6203 Expected_Type
: Entity_Id
;
6204 Formal_Name
: String;
6205 OK_Formal
: in out Boolean)
6208 -- If OK_Formal is False on entry, then simply ignore
6209 -- the formal, because an earlier formal has already
6212 if not OK_Formal
then
6215 -- If no formal is passed in, then issue an error for a
6218 elsif not Present
(Pool_Op_Formal
) then
6220 ("simple storage pool op missing formal " &
6221 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
6227 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
6229 -- If the pool type was expected for this formal, then
6230 -- this will not be considered a candidate operation
6231 -- for the simple pool, so we unset OK_Formal so that
6232 -- the op and any later formals will be ignored.
6234 if Expected_Type
= Pool_Type
then
6241 ("wrong type for formal " & Formal_Name
&
6242 " of simple storage pool op; expected type&",
6243 Pool_Op_Formal
, Expected_Type
);
6247 -- Issue error if formal's mode is not the expected one
6249 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
6251 ("wrong mode for formal of simple storage pool op",
6255 -- Advance to the next formal
6257 Next_Formal
(Pool_Op_Formal
);
6258 end Validate_Simple_Pool_Op_Formal
;
6260 ------------------------------------
6261 -- Validate_Simple_Pool_Operation --
6262 ------------------------------------
6264 procedure Validate_Simple_Pool_Operation
6268 Found_Op
: Entity_Id
:= Empty
;
6274 (Nam_In
(Op_Name
, Name_Allocate
,
6276 Name_Storage_Size
));
6278 Error_Msg_Name_1
:= Op_Name
;
6280 -- For each homonym declared immediately in the scope
6281 -- of the simple storage pool type, determine whether
6282 -- the homonym is an operation of the pool type, and,
6283 -- if so, check that its profile is as expected for
6284 -- a simple pool operation of that name.
6286 Op
:= Get_Name_Entity_Id
(Op_Name
);
6287 while Present
(Op
) loop
6288 if Ekind_In
(Op
, E_Function
, E_Procedure
)
6289 and then Scope
(Op
) = Current_Scope
6291 Formal
:= First_Entity
(Op
);
6295 -- The first parameter must be of the pool type
6296 -- in order for the operation to qualify.
6298 if Op_Name
= Name_Storage_Size
then
6299 Validate_Simple_Pool_Op_Formal
6300 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
6303 Validate_Simple_Pool_Op_Formal
6304 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
6308 -- If another operation with this name has already
6309 -- been located for the type, then flag an error,
6310 -- since we only allow the type to have a single
6313 if Present
(Found_Op
) and then Is_OK
then
6315 ("only one % operation allowed for " &
6316 "simple storage pool type&", Op
, Pool_Type
);
6319 -- In the case of Allocate and Deallocate, a formal
6320 -- of type System.Address is required.
6322 if Op_Name
= Name_Allocate
then
6323 Validate_Simple_Pool_Op_Formal
6324 (Op
, Formal
, E_Out_Parameter
,
6325 Address_Type
, "Storage_Address", Is_OK
);
6327 elsif Op_Name
= Name_Deallocate
then
6328 Validate_Simple_Pool_Op_Formal
6329 (Op
, Formal
, E_In_Parameter
,
6330 Address_Type
, "Storage_Address", Is_OK
);
6333 -- In the case of Allocate and Deallocate, formals
6334 -- of type Storage_Count are required as the third
6335 -- and fourth parameters.
6337 if Op_Name
/= Name_Storage_Size
then
6338 Validate_Simple_Pool_Op_Formal
6339 (Op
, Formal
, E_In_Parameter
,
6340 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
6341 Validate_Simple_Pool_Op_Formal
6342 (Op
, Formal
, E_In_Parameter
,
6343 Stg_Cnt_Type
, "Alignment", Is_OK
);
6346 -- If no mismatched formals have been found (Is_OK)
6347 -- and no excess formals are present, then this
6348 -- operation has been validated, so record it.
6350 if not Present
(Formal
) and then Is_OK
then
6358 -- There must be a valid Allocate operation for the type,
6359 -- so issue an error if none was found.
6361 if Op_Name
= Name_Allocate
6362 and then not Present
(Found_Op
)
6364 Error_Msg_N
("missing % operation for simple " &
6365 "storage pool type", Pool_Type
);
6367 elsif Present
(Found_Op
) then
6369 -- Simple pool operations can't be abstract
6371 if Is_Abstract_Subprogram
(Found_Op
) then
6373 ("simple storage pool operation must not be " &
6374 "abstract", Found_Op
);
6377 -- The Storage_Size operation must be a function with
6378 -- Storage_Count as its result type.
6380 if Op_Name
= Name_Storage_Size
then
6381 if Ekind
(Found_Op
) = E_Procedure
then
6383 ("% operation must be a function", Found_Op
);
6385 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
6387 ("wrong result type for%, expected type&",
6388 Found_Op
, Stg_Cnt_Type
);
6391 -- Allocate and Deallocate must be procedures
6393 elsif Ekind
(Found_Op
) = E_Function
then
6395 ("% operation must be a procedure", Found_Op
);
6398 end Validate_Simple_Pool_Operation
;
6400 -- Start of processing for Validate_Simple_Pool_Ops
6403 Validate_Simple_Pool_Operation
(Name_Allocate
);
6404 Validate_Simple_Pool_Operation
(Name_Deallocate
);
6405 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
6406 end Validate_Simple_Pool_Ops
;
6410 -- Now that all types from which E may depend are frozen, see if the
6411 -- size is known at compile time, if it must be unsigned, or if
6412 -- strict alignment is required
6414 Check_Compile_Time_Size
(E
);
6415 Check_Unsigned_Type
(E
);
6417 if Base_Type
(E
) = E
then
6418 Check_Strict_Alignment
(E
);
6421 -- Do not allow a size clause for a type which does not have a size
6422 -- that is known at compile time
6424 if Has_Size_Clause
(E
)
6425 and then not Size_Known_At_Compile_Time
(E
)
6427 -- Suppress this message if errors posted on E, even if we are
6428 -- in all errors mode, since this is often a junk message
6430 if not Error_Posted
(E
) then
6432 ("size clause not allowed for variable length type",
6437 -- Now we set/verify the representation information, in particular
6438 -- the size and alignment values. This processing is not required for
6439 -- generic types, since generic types do not play any part in code
6440 -- generation, and so the size and alignment values for such types
6441 -- are irrelevant. Ditto for types declared within a generic unit,
6442 -- which may have components that depend on generic parameters, and
6443 -- that will be recreated in an instance.
6445 if Inside_A_Generic
then
6448 -- Otherwise we call the layout procedure
6454 -- If this is an access to subprogram whose designated type is itself
6455 -- a subprogram type, the return type of this anonymous subprogram
6456 -- type must be decorated as well.
6458 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
6459 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
6461 Layout_Type
(Etype
(Designated_Type
(E
)));
6464 -- If the type has a Defaut_Value/Default_Component_Value aspect,
6465 -- this is where we analye the expression (after the type is frozen,
6466 -- since in the case of Default_Value, we are analyzing with the
6467 -- type itself, and we treat Default_Component_Value similarly for
6468 -- the sake of uniformity).
6470 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
6477 if Is_Scalar_Type
(E
) then
6478 Nam
:= Name_Default_Value
;
6480 Exp
:= Default_Aspect_Value
(Typ
);
6482 Nam
:= Name_Default_Component_Value
;
6483 Typ
:= Component_Type
(E
);
6484 Exp
:= Default_Aspect_Component_Value
(E
);
6487 Analyze_And_Resolve
(Exp
, Typ
);
6489 if Etype
(Exp
) /= Any_Type
then
6490 if not Is_OK_Static_Expression
(Exp
) then
6491 Error_Msg_Name_1
:= Nam
;
6492 Flag_Non_Static_Expr
6493 ("aspect% requires static expression", Exp
);
6499 -- End of freeze processing for type entities
6502 -- Here is where we logically freeze the current entity. If it has a
6503 -- freeze node, then this is the point at which the freeze node is
6504 -- linked into the result list.
6506 if Has_Delayed_Freeze
(E
) then
6508 -- If a freeze node is already allocated, use it, otherwise allocate
6509 -- a new one. The preallocation happens in the case of anonymous base
6510 -- types, where we preallocate so that we can set First_Subtype_Link.
6511 -- Note that we reset the Sloc to the current freeze location.
6513 if Present
(Freeze_Node
(E
)) then
6514 F_Node
:= Freeze_Node
(E
);
6515 Set_Sloc
(F_Node
, Loc
);
6518 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
6519 Set_Freeze_Node
(E
, F_Node
);
6520 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
6521 Set_TSS_Elist
(F_Node
, No_Elist
);
6522 Set_Actions
(F_Node
, No_List
);
6525 Set_Entity
(F_Node
, E
);
6526 Add_To_Result
(F_Node
);
6528 -- A final pass over record types with discriminants. If the type
6529 -- has an incomplete declaration, there may be constrained access
6530 -- subtypes declared elsewhere, which do not depend on the discrimi-
6531 -- nants of the type, and which are used as component types (i.e.
6532 -- the full view is a recursive type). The designated types of these
6533 -- subtypes can only be elaborated after the type itself, and they
6534 -- need an itype reference.
6536 if Ekind
(E
) = E_Record_Type
and then Has_Discriminants
(E
) then
6543 Comp
:= First_Component
(E
);
6544 while Present
(Comp
) loop
6545 Typ
:= Etype
(Comp
);
6547 if Ekind
(Comp
) = E_Component
6548 and then Is_Access_Type
(Typ
)
6549 and then Scope
(Typ
) /= E
6550 and then Base_Type
(Designated_Type
(Typ
)) = E
6551 and then Is_Itype
(Designated_Type
(Typ
))
6553 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
6554 Set_Itype
(IR
, Designated_Type
(Typ
));
6555 Append
(IR
, Result
);
6558 Next_Component
(Comp
);
6564 -- When a type is frozen, the first subtype of the type is frozen as
6565 -- well (RM 13.14(15)). This has to be done after freezing the type,
6566 -- since obviously the first subtype depends on its own base type.
6569 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
6571 -- If we just froze a tagged non-class wide record, then freeze the
6572 -- corresponding class-wide type. This must be done after the tagged
6573 -- type itself is frozen, because the class-wide type refers to the
6574 -- tagged type which generates the class.
6576 if Is_Tagged_Type
(E
)
6577 and then not Is_Class_Wide_Type
(E
)
6578 and then Present
(Class_Wide_Type
(E
))
6580 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
6584 Check_Debug_Info_Needed
(E
);
6586 -- Special handling for subprograms
6588 if Is_Subprogram
(E
) then
6590 -- If subprogram has address clause then reset Is_Public flag, since
6591 -- we do not want the backend to generate external references.
6593 if Present
(Address_Clause
(E
))
6594 and then not Is_Library_Level_Entity
(E
)
6596 Set_Is_Public
(E
, False);
6601 Restore_Ghost_Mode
(Mode
);
6605 -----------------------------
6606 -- Freeze_Enumeration_Type --
6607 -----------------------------
6609 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
6611 -- By default, if no size clause is present, an enumeration type with
6612 -- Convention C is assumed to interface to a C enum, and has integer
6613 -- size. This applies to types. For subtypes, verify that its base
6614 -- type has no size clause either. Treat other foreign conventions
6615 -- in the same way, and also make sure alignment is set right.
6617 if Has_Foreign_Convention
(Typ
)
6618 and then not Has_Size_Clause
(Typ
)
6619 and then not Has_Size_Clause
(Base_Type
(Typ
))
6620 and then Esize
(Typ
) < Standard_Integer_Size
6622 -- Don't do this if Short_Enums on target
6624 and then not Target_Short_Enums
6626 Init_Esize
(Typ
, Standard_Integer_Size
);
6627 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
6629 -- Normal Ada case or size clause present or not Long_C_Enums on target
6632 -- If the enumeration type interfaces to C, and it has a size clause
6633 -- that specifies less than int size, it warrants a warning. The
6634 -- user may intend the C type to be an enum or a char, so this is
6635 -- not by itself an error that the Ada compiler can detect, but it
6636 -- it is a worth a heads-up. For Boolean and Character types we
6637 -- assume that the programmer has the proper C type in mind.
6639 if Convention
(Typ
) = Convention_C
6640 and then Has_Size_Clause
(Typ
)
6641 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
6642 and then not Is_Boolean_Type
(Typ
)
6643 and then not Is_Character_Type
(Typ
)
6645 -- Don't do this if Short_Enums on target
6647 and then not Target_Short_Enums
6650 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
6653 Adjust_Esize_For_Alignment
(Typ
);
6655 end Freeze_Enumeration_Type
;
6657 -----------------------
6658 -- Freeze_Expression --
6659 -----------------------
6661 procedure Freeze_Expression
(N
: Node_Id
) is
6662 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
6665 Desig_Typ
: Entity_Id
;
6669 Freeze_Outside
: Boolean := False;
6670 -- This flag is set true if the entity must be frozen outside the
6671 -- current subprogram. This happens in the case of expander generated
6672 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
6673 -- not freeze all entities like other bodies, but which nevertheless
6674 -- may reference entities that have to be frozen before the body and
6675 -- obviously cannot be frozen inside the body.
6677 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
6678 -- If the expression is an array aggregate, the type of the component
6679 -- expressions is also frozen. If the component type is an access type
6680 -- and the expressions include allocators, the designed type is frozen
6683 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
6684 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
6685 -- it is the handled statement sequence of an expander-generated
6686 -- subprogram (init proc, stream subprogram, or renaming as body).
6687 -- If so, this is not a freezing context.
6689 -----------------------------------------
6690 -- Find_Aggregate_Component_Desig_Type --
6691 -----------------------------------------
6693 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
6698 if Present
(Expressions
(N
)) then
6699 Exp
:= First
(Expressions
(N
));
6700 while Present
(Exp
) loop
6701 if Nkind
(Exp
) = N_Allocator
then
6702 return Designated_Type
(Component_Type
(Etype
(N
)));
6709 if Present
(Component_Associations
(N
)) then
6710 Assoc
:= First
(Component_Associations
(N
));
6711 while Present
(Assoc
) loop
6712 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
6713 return Designated_Type
(Component_Type
(Etype
(N
)));
6721 end Find_Aggregate_Component_Desig_Type
;
6723 ----------------------
6724 -- In_Expanded_Body --
6725 ----------------------
6727 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
6732 if Nkind
(N
) = N_Subprogram_Body
then
6738 if Nkind
(P
) /= N_Subprogram_Body
then
6742 Id
:= Defining_Unit_Name
(Specification
(P
));
6744 -- The following are expander-created bodies, or bodies that
6745 -- are not freeze points.
6747 if Nkind
(Id
) = N_Defining_Identifier
6748 and then (Is_Init_Proc
(Id
)
6749 or else Is_TSS
(Id
, TSS_Stream_Input
)
6750 or else Is_TSS
(Id
, TSS_Stream_Output
)
6751 or else Is_TSS
(Id
, TSS_Stream_Read
)
6752 or else Is_TSS
(Id
, TSS_Stream_Write
)
6753 or else Nkind_In
(Original_Node
(P
),
6754 N_Subprogram_Renaming_Declaration
,
6755 N_Expression_Function
))
6762 end In_Expanded_Body
;
6764 -- Start of processing for Freeze_Expression
6767 -- Immediate return if freezing is inhibited. This flag is set by the
6768 -- analyzer to stop freezing on generated expressions that would cause
6769 -- freezing if they were in the source program, but which are not
6770 -- supposed to freeze, since they are created.
6772 if Must_Not_Freeze
(N
) then
6776 -- If expression is non-static, then it does not freeze in a default
6777 -- expression, see section "Handling of Default Expressions" in the
6778 -- spec of package Sem for further details. Note that we have to make
6779 -- sure that we actually have a real expression (if we have a subtype
6780 -- indication, we can't test Is_OK_Static_Expression). However, we
6781 -- exclude the case of the prefix of an attribute of a static scalar
6782 -- subtype from this early return, because static subtype attributes
6783 -- should always cause freezing, even in default expressions, but
6784 -- the attribute may not have been marked as static yet (because in
6785 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
6786 -- Freeze_Expression on the prefix).
6789 and then Nkind
(N
) in N_Subexpr
6790 and then not Is_OK_Static_Expression
(N
)
6791 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
6792 or else not (Is_Entity_Name
(N
)
6793 and then Is_Type
(Entity
(N
))
6794 and then Is_OK_Static_Subtype
(Entity
(N
))))
6799 -- Freeze type of expression if not frozen already
6803 if Nkind
(N
) in N_Has_Etype
then
6804 if not Is_Frozen
(Etype
(N
)) then
6807 -- Base type may be an derived numeric type that is frozen at
6808 -- the point of declaration, but first_subtype is still unfrozen.
6810 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
6811 Typ
:= First_Subtype
(Etype
(N
));
6815 -- For entity name, freeze entity if not frozen already. A special
6816 -- exception occurs for an identifier that did not come from source.
6817 -- We don't let such identifiers freeze a non-internal entity, i.e.
6818 -- an entity that did come from source, since such an identifier was
6819 -- generated by the expander, and cannot have any semantic effect on
6820 -- the freezing semantics. For example, this stops the parameter of
6821 -- an initialization procedure from freezing the variable.
6823 if Is_Entity_Name
(N
)
6824 and then not Is_Frozen
(Entity
(N
))
6825 and then (Nkind
(N
) /= N_Identifier
6826 or else Comes_From_Source
(N
)
6827 or else not Comes_From_Source
(Entity
(N
)))
6831 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
6832 Check_Expression_Function
(N
, Nam
);
6839 -- For an allocator freeze designated type if not frozen already
6841 -- For an aggregate whose component type is an access type, freeze the
6842 -- designated type now, so that its freeze does not appear within the
6843 -- loop that might be created in the expansion of the aggregate. If the
6844 -- designated type is a private type without full view, the expression
6845 -- cannot contain an allocator, so the type is not frozen.
6847 -- For a function, we freeze the entity when the subprogram declaration
6848 -- is frozen, but a function call may appear in an initialization proc.
6849 -- before the declaration is frozen. We need to generate the extra
6850 -- formals, if any, to ensure that the expansion of the call includes
6851 -- the proper actuals. This only applies to Ada subprograms, not to
6858 Desig_Typ
:= Designated_Type
(Etype
(N
));
6861 if Is_Array_Type
(Etype
(N
))
6862 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
6865 -- Check whether aggregate includes allocators.
6867 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
6870 when N_Indexed_Component
6871 | N_Selected_Component
6874 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6875 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
6878 when N_Identifier
=>
6880 and then Ekind
(Nam
) = E_Function
6881 and then Nkind
(Parent
(N
)) = N_Function_Call
6882 and then Convention
(Nam
) = Convention_Ada
6884 Create_Extra_Formals
(Nam
);
6891 if Desig_Typ
/= Empty
6892 and then (Is_Frozen
(Desig_Typ
)
6893 or else (not Is_Fully_Defined
(Desig_Typ
)))
6898 -- All done if nothing needs freezing
6902 and then No
(Desig_Typ
)
6907 -- Examine the enclosing context by climbing the parent chain. The
6908 -- traversal serves two purposes - to detect scenarios where freezeing
6909 -- is not needed and to find the proper insertion point for the freeze
6910 -- nodes. Although somewhat similar to Insert_Actions, this traversal
6911 -- is freezing semantics-sensitive. Inserting freeze nodes blindly in
6912 -- the tree may result in types being frozen too early.
6916 Parent_P
:= Parent
(P
);
6918 -- If we don't have a parent, then we are not in a well-formed tree.
6919 -- This is an unusual case, but there are some legitimate situations
6920 -- in which this occurs, notably when the expressions in the range of
6921 -- a type declaration are resolved. We simply ignore the freeze
6922 -- request in this case. Is this right ???
6924 if No
(Parent_P
) then
6928 -- See if we have got to an appropriate point in the tree
6930 case Nkind
(Parent_P
) is
6932 -- A special test for the exception of (RM 13.14(8)) for the case
6933 -- of per-object expressions (RM 3.8(18)) occurring in component
6934 -- definition or a discrete subtype definition. Note that we test
6935 -- for a component declaration which includes both cases we are
6936 -- interested in, and furthermore the tree does not have explicit
6937 -- nodes for either of these two constructs.
6939 when N_Component_Declaration
=>
6941 -- The case we want to test for here is an identifier that is
6942 -- a per-object expression, this is either a discriminant that
6943 -- appears in a context other than the component declaration
6944 -- or it is a reference to the type of the enclosing construct.
6946 -- For either of these cases, we skip the freezing
6948 if not In_Spec_Expression
6949 and then Nkind
(N
) = N_Identifier
6950 and then (Present
(Entity
(N
)))
6952 -- We recognize the discriminant case by just looking for
6953 -- a reference to a discriminant. It can only be one for
6954 -- the enclosing construct. Skip freezing in this case.
6956 if Ekind
(Entity
(N
)) = E_Discriminant
then
6959 -- For the case of a reference to the enclosing record,
6960 -- (or task or protected type), we look for a type that
6961 -- matches the current scope.
6963 elsif Entity
(N
) = Current_Scope
then
6968 -- If we have an enumeration literal that appears as the choice in
6969 -- the aggregate of an enumeration representation clause, then
6970 -- freezing does not occur (RM 13.14(10)).
6972 when N_Enumeration_Representation_Clause
=>
6974 -- The case we are looking for is an enumeration literal
6976 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
6977 and then Is_Enumeration_Type
(Etype
(N
))
6979 -- If enumeration literal appears directly as the choice,
6980 -- do not freeze (this is the normal non-overloaded case)
6982 if Nkind
(Parent
(N
)) = N_Component_Association
6983 and then First
(Choices
(Parent
(N
))) = N
6987 -- If enumeration literal appears as the name of function
6988 -- which is the choice, then also do not freeze. This
6989 -- happens in the overloaded literal case, where the
6990 -- enumeration literal is temporarily changed to a function
6991 -- call for overloading analysis purposes.
6993 elsif Nkind
(Parent
(N
)) = N_Function_Call
6995 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
6997 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
7003 -- Normally if the parent is a handled sequence of statements,
7004 -- then the current node must be a statement, and that is an
7005 -- appropriate place to insert a freeze node.
7007 when N_Handled_Sequence_Of_Statements
=>
7009 -- An exception occurs when the sequence of statements is for
7010 -- an expander generated body that did not do the usual freeze
7011 -- all operation. In this case we usually want to freeze
7012 -- outside this body, not inside it, and we skip past the
7013 -- subprogram body that we are inside.
7015 if In_Expanded_Body
(Parent_P
) then
7017 Subp
: constant Node_Id
:= Parent
(Parent_P
);
7021 -- Freeze the entity only when it is declared inside the
7022 -- body of the expander generated procedure. This case
7023 -- is recognized by the scope of the entity or its type,
7024 -- which is either the spec for some enclosing body, or
7025 -- (in the case of init_procs, for which there are no
7026 -- separate specs) the current scope.
7028 if Nkind
(Subp
) = N_Subprogram_Body
then
7029 Spec
:= Corresponding_Spec
(Subp
);
7031 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
7033 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
7038 and then Scope
(Typ
) = Current_Scope
7039 and then Defining_Entity
(Subp
) = Current_Scope
7045 -- An expression function may act as a completion of
7046 -- a function declaration. As such, it can reference
7047 -- entities declared between the two views:
7050 -- function F return ...;
7052 -- function Hidden return ...;
7053 -- function F return ... is (Hidden); -- 2
7055 -- Refering to the example above, freezing the expression
7056 -- of F (2) would place Hidden's freeze node (1) in the
7057 -- wrong place. Avoid explicit freezing and let the usual
7058 -- scenarios do the job - for example, reaching the end
7059 -- of the private declarations, or a call to F.
7061 if Nkind
(Original_Node
(Subp
)) =
7062 N_Expression_Function
7066 -- Freeze outside the body
7069 Parent_P
:= Parent
(Parent_P
);
7070 Freeze_Outside
:= True;
7074 -- Here if normal case where we are in handled statement
7075 -- sequence and want to do the insertion right there.
7081 -- If parent is a body or a spec or a block, then the current node
7082 -- is a statement or declaration and we can insert the freeze node
7085 when N_Block_Statement
7088 | N_Package_Specification
7095 -- The expander is allowed to define types in any statements list,
7096 -- so any of the following parent nodes also mark a freezing point
7097 -- if the actual node is in a list of statements or declarations.
7099 when N_Abortable_Part
7100 | N_Accept_Alternative
7102 | N_Case_Statement_Alternative
7103 | N_Compilation_Unit_Aux
7104 | N_Conditional_Entry_Call
7105 | N_Delay_Alternative
7107 | N_Entry_Call_Alternative
7108 | N_Exception_Handler
7109 | N_Extended_Return_Statement
7113 | N_Selective_Accept
7114 | N_Triggering_Alternative
7116 exit when Is_List_Member
(P
);
7118 -- Freeze nodes produced by an expression coming from the Actions
7119 -- list of a N_Expression_With_Actions node must remain within the
7120 -- Actions list. Inserting the freeze nodes further up the tree
7121 -- may lead to use before declaration issues in the case of array
7124 when N_Expression_With_Actions
=>
7125 if Is_List_Member
(P
)
7126 and then List_Containing
(P
) = Actions
(Parent_P
)
7131 -- Note: N_Loop_Statement is a special case. A type that appears
7132 -- in the source can never be frozen in a loop (this occurs only
7133 -- because of a loop expanded by the expander), so we keep on
7134 -- going. Otherwise we terminate the search. Same is true of any
7135 -- entity which comes from source. (if they have predefined type,
7136 -- that type does not appear to come from source, but the entity
7137 -- should not be frozen here).
7139 when N_Loop_Statement
=>
7140 exit when not Comes_From_Source
(Etype
(N
))
7141 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
7143 -- For all other cases, keep looking at parents
7149 -- We fall through the case if we did not yet find the proper
7150 -- place in the free for inserting the freeze node, so climb.
7155 -- If the expression appears in a record or an initialization procedure,
7156 -- the freeze nodes are collected and attached to the current scope, to
7157 -- be inserted and analyzed on exit from the scope, to insure that
7158 -- generated entities appear in the correct scope. If the expression is
7159 -- a default for a discriminant specification, the scope is still void.
7160 -- The expression can also appear in the discriminant part of a private
7161 -- or concurrent type.
7163 -- If the expression appears in a constrained subcomponent of an
7164 -- enclosing record declaration, the freeze nodes must be attached to
7165 -- the outer record type so they can eventually be placed in the
7166 -- enclosing declaration list.
7168 -- The other case requiring this special handling is if we are in a
7169 -- default expression, since in that case we are about to freeze a
7170 -- static type, and the freeze scope needs to be the outer scope, not
7171 -- the scope of the subprogram with the default parameter.
7173 -- For default expressions and other spec expressions in generic units,
7174 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
7175 -- placing them at the proper place, after the generic unit.
7177 if (In_Spec_Exp
and not Inside_A_Generic
)
7178 or else Freeze_Outside
7179 or else (Is_Type
(Current_Scope
)
7180 and then (not Is_Concurrent_Type
(Current_Scope
)
7181 or else not Has_Completion
(Current_Scope
)))
7182 or else Ekind
(Current_Scope
) = E_Void
7185 N
: constant Node_Id
:= Current_Scope
;
7186 Freeze_Nodes
: List_Id
:= No_List
;
7187 Pos
: Int
:= Scope_Stack
.Last
;
7190 if Present
(Desig_Typ
) then
7191 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
7194 if Present
(Typ
) then
7195 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
7198 if Present
(Nam
) then
7199 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
7202 -- The current scope may be that of a constrained component of
7203 -- an enclosing record declaration, or of a loop of an enclosing
7204 -- quantified expression, which is above the current scope in the
7205 -- scope stack. Indeed in the context of a quantified expression,
7206 -- a scope is created and pushed above the current scope in order
7207 -- to emulate the loop-like behavior of the quantified expression.
7208 -- If the expression is within a top-level pragma, as for a pre-
7209 -- condition on a library-level subprogram, nothing to do.
7211 if not Is_Compilation_Unit
(Current_Scope
)
7212 and then (Is_Record_Type
(Scope
(Current_Scope
))
7213 or else Nkind
(Parent
(Current_Scope
)) =
7214 N_Quantified_Expression
)
7219 if Is_Non_Empty_List
(Freeze_Nodes
) then
7220 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
7221 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
7224 Append_List
(Freeze_Nodes
,
7225 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
7233 -- Now we have the right place to do the freezing. First, a special
7234 -- adjustment, if we are in spec-expression analysis mode, these freeze
7235 -- actions must not be thrown away (normally all inserted actions are
7236 -- thrown away in this mode. However, the freeze actions are from static
7237 -- expressions and one of the important reasons we are doing this
7238 -- special analysis is to get these freeze actions. Therefore we turn
7239 -- off the In_Spec_Expression mode to propagate these freeze actions.
7240 -- This also means they get properly analyzed and expanded.
7242 In_Spec_Expression
:= False;
7244 -- Freeze the designated type of an allocator (RM 13.14(13))
7246 if Present
(Desig_Typ
) then
7247 Freeze_Before
(P
, Desig_Typ
);
7250 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
7251 -- the enumeration representation clause exception in the loop above.
7253 if Present
(Typ
) then
7254 Freeze_Before
(P
, Typ
);
7257 -- Freeze name if one is present (RM 13.14(11))
7259 if Present
(Nam
) then
7260 Freeze_Before
(P
, Nam
);
7263 -- Restore In_Spec_Expression flag
7265 In_Spec_Expression
:= In_Spec_Exp
;
7266 end Freeze_Expression
;
7268 -----------------------------
7269 -- Freeze_Fixed_Point_Type --
7270 -----------------------------
7272 -- Certain fixed-point types and subtypes, including implicit base types
7273 -- and declared first subtypes, have not yet set up a range. This is
7274 -- because the range cannot be set until the Small and Size values are
7275 -- known, and these are not known till the type is frozen.
7277 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
7278 -- whose bounds are unanalyzed real literals. This routine will recognize
7279 -- this case, and transform this range node into a properly typed range
7280 -- with properly analyzed and resolved values.
7282 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
7283 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
7284 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
7285 Hi
: constant Node_Id
:= High_Bound
(Rng
);
7286 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7287 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
7288 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
7289 BHi
: constant Node_Id
:= High_Bound
(Brng
);
7290 Small
: constant Ureal
:= Small_Value
(Typ
);
7297 -- Save original bounds (for shaving tests)
7300 -- Actual size chosen
7302 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
7303 -- Returns size of type with given bounds. Also leaves these
7304 -- bounds set as the current bounds of the Typ.
7310 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
7312 Set_Realval
(Lo
, Lov
);
7313 Set_Realval
(Hi
, Hiv
);
7314 return Minimum_Size
(Typ
);
7317 -- Start of processing for Freeze_Fixed_Point_Type
7320 -- If Esize of a subtype has not previously been set, set it now
7322 if Unknown_Esize
(Typ
) then
7323 Atype
:= Ancestor_Subtype
(Typ
);
7325 if Present
(Atype
) then
7326 Set_Esize
(Typ
, Esize
(Atype
));
7328 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
7332 -- Immediate return if the range is already analyzed. This means that
7333 -- the range is already set, and does not need to be computed by this
7336 if Analyzed
(Rng
) then
7340 -- Immediate return if either of the bounds raises Constraint_Error
7342 if Raises_Constraint_Error
(Lo
)
7343 or else Raises_Constraint_Error
(Hi
)
7348 Loval
:= Realval
(Lo
);
7349 Hival
:= Realval
(Hi
);
7354 -- Ordinary fixed-point case
7356 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
7358 -- For the ordinary fixed-point case, we are allowed to fudge the
7359 -- end-points up or down by small. Generally we prefer to fudge up,
7360 -- i.e. widen the bounds for non-model numbers so that the end points
7361 -- are included. However there are cases in which this cannot be
7362 -- done, and indeed cases in which we may need to narrow the bounds.
7363 -- The following circuit makes the decision.
7365 -- Note: our terminology here is that Incl_EP means that the bounds
7366 -- are widened by Small if necessary to include the end points, and
7367 -- Excl_EP means that the bounds are narrowed by Small to exclude the
7368 -- end-points if this reduces the size.
7370 -- Note that in the Incl case, all we care about is including the
7371 -- end-points. In the Excl case, we want to narrow the bounds as
7372 -- much as permitted by the RM, to give the smallest possible size.
7375 Loval_Incl_EP
: Ureal
;
7376 Hival_Incl_EP
: Ureal
;
7378 Loval_Excl_EP
: Ureal
;
7379 Hival_Excl_EP
: Ureal
;
7385 First_Subt
: Entity_Id
;
7390 -- First step. Base types are required to be symmetrical. Right
7391 -- now, the base type range is a copy of the first subtype range.
7392 -- This will be corrected before we are done, but right away we
7393 -- need to deal with the case where both bounds are non-negative.
7394 -- In this case, we set the low bound to the negative of the high
7395 -- bound, to make sure that the size is computed to include the
7396 -- required sign. Note that we do not need to worry about the
7397 -- case of both bounds negative, because the sign will be dealt
7398 -- with anyway. Furthermore we can't just go making such a bound
7399 -- symmetrical, since in a twos-complement system, there is an
7400 -- extra negative value which could not be accommodated on the
7404 and then not UR_Is_Negative
(Loval
)
7405 and then Hival
> Loval
7408 Set_Realval
(Lo
, Loval
);
7411 -- Compute the fudged bounds. If the number is a model number,
7412 -- then we do nothing to include it, but we are allowed to backoff
7413 -- to the next adjacent model number when we exclude it. If it is
7414 -- not a model number then we straddle the two values with the
7415 -- model numbers on either side.
7417 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
7419 if Loval
= Model_Num
then
7420 Loval_Incl_EP
:= Model_Num
;
7422 Loval_Incl_EP
:= Model_Num
- Small
;
7425 -- The low value excluding the end point is Small greater, but
7426 -- we do not do this exclusion if the low value is positive,
7427 -- since it can't help the size and could actually hurt by
7428 -- crossing the high bound.
7430 if UR_Is_Negative
(Loval_Incl_EP
) then
7431 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
7433 -- If the value went from negative to zero, then we have the
7434 -- case where Loval_Incl_EP is the model number just below
7435 -- zero, so we want to stick to the negative value for the
7436 -- base type to maintain the condition that the size will
7437 -- include signed values.
7440 and then UR_Is_Zero
(Loval_Excl_EP
)
7442 Loval_Excl_EP
:= Loval_Incl_EP
;
7446 Loval_Excl_EP
:= Loval_Incl_EP
;
7449 -- Similar processing for upper bound and high value
7451 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
7453 if Hival
= Model_Num
then
7454 Hival_Incl_EP
:= Model_Num
;
7456 Hival_Incl_EP
:= Model_Num
+ Small
;
7459 if UR_Is_Positive
(Hival_Incl_EP
) then
7460 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
7462 Hival_Excl_EP
:= Hival_Incl_EP
;
7465 -- One further adjustment is needed. In the case of subtypes, we
7466 -- cannot go outside the range of the base type, or we get
7467 -- peculiarities, and the base type range is already set. This
7468 -- only applies to the Incl values, since clearly the Excl values
7469 -- are already as restricted as they are allowed to be.
7472 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
7473 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
7476 -- Get size including and excluding end points
7478 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
7479 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
7481 -- No need to exclude end-points if it does not reduce size
7483 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
7484 Loval_Excl_EP
:= Loval_Incl_EP
;
7487 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
7488 Hival_Excl_EP
:= Hival_Incl_EP
;
7491 -- Now we set the actual size to be used. We want to use the
7492 -- bounds fudged up to include the end-points but only if this
7493 -- can be done without violating a specifically given size
7494 -- size clause or causing an unacceptable increase in size.
7496 -- Case of size clause given
7498 if Has_Size_Clause
(Typ
) then
7500 -- Use the inclusive size only if it is consistent with
7501 -- the explicitly specified size.
7503 if Size_Incl_EP
<= RM_Size
(Typ
) then
7504 Actual_Lo
:= Loval_Incl_EP
;
7505 Actual_Hi
:= Hival_Incl_EP
;
7506 Actual_Size
:= Size_Incl_EP
;
7508 -- If the inclusive size is too large, we try excluding
7509 -- the end-points (will be caught later if does not work).
7512 Actual_Lo
:= Loval_Excl_EP
;
7513 Actual_Hi
:= Hival_Excl_EP
;
7514 Actual_Size
:= Size_Excl_EP
;
7517 -- Case of size clause not given
7520 -- If we have a base type whose corresponding first subtype
7521 -- has an explicit size that is large enough to include our
7522 -- end-points, then do so. There is no point in working hard
7523 -- to get a base type whose size is smaller than the specified
7524 -- size of the first subtype.
7526 First_Subt
:= First_Subtype
(Typ
);
7528 if Has_Size_Clause
(First_Subt
)
7529 and then Size_Incl_EP
<= Esize
(First_Subt
)
7531 Actual_Size
:= Size_Incl_EP
;
7532 Actual_Lo
:= Loval_Incl_EP
;
7533 Actual_Hi
:= Hival_Incl_EP
;
7535 -- If excluding the end-points makes the size smaller and
7536 -- results in a size of 8,16,32,64, then we take the smaller
7537 -- size. For the 64 case, this is compulsory. For the other
7538 -- cases, it seems reasonable. We like to include end points
7539 -- if we can, but not at the expense of moving to the next
7540 -- natural boundary of size.
7542 elsif Size_Incl_EP
/= Size_Excl_EP
7543 and then Addressable
(Size_Excl_EP
)
7545 Actual_Size
:= Size_Excl_EP
;
7546 Actual_Lo
:= Loval_Excl_EP
;
7547 Actual_Hi
:= Hival_Excl_EP
;
7549 -- Otherwise we can definitely include the end points
7552 Actual_Size
:= Size_Incl_EP
;
7553 Actual_Lo
:= Loval_Incl_EP
;
7554 Actual_Hi
:= Hival_Incl_EP
;
7557 -- One pathological case: normally we never fudge a low bound
7558 -- down, since it would seem to increase the size (if it has
7559 -- any effect), but for ranges containing single value, or no
7560 -- values, the high bound can be small too large. Consider:
7562 -- type t is delta 2.0**(-14)
7563 -- range 131072.0 .. 0;
7565 -- That lower bound is *just* outside the range of 32 bits, and
7566 -- does need fudging down in this case. Note that the bounds
7567 -- will always have crossed here, since the high bound will be
7568 -- fudged down if necessary, as in the case of:
7570 -- type t is delta 2.0**(-14)
7571 -- range 131072.0 .. 131072.0;
7573 -- So we detect the situation by looking for crossed bounds,
7574 -- and if the bounds are crossed, and the low bound is greater
7575 -- than zero, we will always back it off by small, since this
7576 -- is completely harmless.
7578 if Actual_Lo
> Actual_Hi
then
7579 if UR_Is_Positive
(Actual_Lo
) then
7580 Actual_Lo
:= Loval_Incl_EP
- Small
;
7581 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
7583 -- And of course, we need to do exactly the same parallel
7584 -- fudge for flat ranges in the negative region.
7586 elsif UR_Is_Negative
(Actual_Hi
) then
7587 Actual_Hi
:= Hival_Incl_EP
+ Small
;
7588 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
7593 Set_Realval
(Lo
, Actual_Lo
);
7594 Set_Realval
(Hi
, Actual_Hi
);
7597 -- For the decimal case, none of this fudging is required, since there
7598 -- are no end-point problems in the decimal case (the end-points are
7599 -- always included).
7602 Actual_Size
:= Fsize
(Loval
, Hival
);
7605 -- At this stage, the actual size has been calculated and the proper
7606 -- required bounds are stored in the low and high bounds.
7608 if Actual_Size
> 64 then
7609 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
7611 ("size required (^) for type& too large, maximum allowed is 64",
7616 -- Check size against explicit given size
7618 if Has_Size_Clause
(Typ
) then
7619 if Actual_Size
> RM_Size
(Typ
) then
7620 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7621 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
7623 ("size given (^) for type& too small, minimum allowed is ^",
7624 Size_Clause
(Typ
), Typ
);
7627 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
7630 -- Increase size to next natural boundary if no size clause given
7633 if Actual_Size
<= 8 then
7635 elsif Actual_Size
<= 16 then
7637 elsif Actual_Size
<= 32 then
7643 Init_Esize
(Typ
, Actual_Size
);
7644 Adjust_Esize_For_Alignment
(Typ
);
7647 -- If we have a base type, then expand the bounds so that they extend to
7648 -- the full width of the allocated size in bits, to avoid junk range
7649 -- checks on intermediate computations.
7651 if Base_Type
(Typ
) = Typ
then
7652 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
7653 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
7656 -- Final step is to reanalyze the bounds using the proper type
7657 -- and set the Corresponding_Integer_Value fields of the literals.
7659 Set_Etype
(Lo
, Empty
);
7660 Set_Analyzed
(Lo
, False);
7663 -- Resolve with universal fixed if the base type, and the base type if
7664 -- it is a subtype. Note we can't resolve the base type with itself,
7665 -- that would be a reference before definition.
7668 Resolve
(Lo
, Universal_Fixed
);
7673 -- Set corresponding integer value for bound
7675 Set_Corresponding_Integer_Value
7676 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
7678 -- Similar processing for high bound
7680 Set_Etype
(Hi
, Empty
);
7681 Set_Analyzed
(Hi
, False);
7685 Resolve
(Hi
, Universal_Fixed
);
7690 Set_Corresponding_Integer_Value
7691 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
7693 -- Set type of range to correspond to bounds
7695 Set_Etype
(Rng
, Etype
(Lo
));
7697 -- Set Esize to calculated size if not set already
7699 if Unknown_Esize
(Typ
) then
7700 Init_Esize
(Typ
, Actual_Size
);
7703 -- Set RM_Size if not already set. If already set, check value
7706 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
7709 if RM_Size
(Typ
) /= Uint_0
then
7710 if RM_Size
(Typ
) < Minsiz
then
7711 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7712 Error_Msg_Uint_2
:= Minsiz
;
7714 ("size given (^) for type& too small, minimum allowed is ^",
7715 Size_Clause
(Typ
), Typ
);
7719 Set_RM_Size
(Typ
, Minsiz
);
7723 -- Check for shaving
7725 if Comes_From_Source
(Typ
) then
7727 -- In SPARK mode the given bounds must be strictly representable
7729 if SPARK_Mode
= On
then
7730 if Orig_Lo
< Expr_Value_R
(Lo
) then
7732 ("declared low bound of type & is outside type range",
7736 if Orig_Hi
> Expr_Value_R
(Hi
) then
7738 ("declared high bound of type & is outside type range",
7743 if Orig_Lo
< Expr_Value_R
(Lo
) then
7745 ("declared low bound of type & is outside type range??", Typ
);
7747 ("\low bound adjusted up by delta (RM 3.5.9(13))??", Typ
);
7750 if Orig_Hi
> Expr_Value_R
(Hi
) then
7752 ("declared high bound of type & is outside type range??",
7755 ("\high bound adjusted down by delta (RM 3.5.9(13))??", Typ
);
7759 end Freeze_Fixed_Point_Type
;
7765 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
7769 Set_Has_Delayed_Freeze
(T
);
7770 L
:= Freeze_Entity
(T
, N
);
7772 if Is_Non_Empty_List
(L
) then
7773 Insert_Actions
(N
, L
);
7777 --------------------------
7778 -- Freeze_Static_Object --
7779 --------------------------
7781 procedure Freeze_Static_Object
(E
: Entity_Id
) is
7783 Cannot_Be_Static
: exception;
7784 -- Exception raised if the type of a static object cannot be made
7785 -- static. This happens if the type depends on non-global objects.
7787 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
7788 -- Called to ensure that an expression used as part of a type definition
7789 -- is statically allocatable, which means that the expression type is
7790 -- statically allocatable, and the expression is either static, or a
7791 -- reference to a library level constant.
7793 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
7794 -- Called to mark a type as static, checking that it is possible
7795 -- to set the type as static. If it is not possible, then the
7796 -- exception Cannot_Be_Static is raised.
7798 -----------------------------
7799 -- Ensure_Expression_Is_SA --
7800 -----------------------------
7802 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
7806 Ensure_Type_Is_SA
(Etype
(N
));
7808 if Is_OK_Static_Expression
(N
) then
7811 elsif Nkind
(N
) = N_Identifier
then
7815 and then Ekind
(Ent
) = E_Constant
7816 and then Is_Library_Level_Entity
(Ent
)
7822 raise Cannot_Be_Static
;
7823 end Ensure_Expression_Is_SA
;
7825 -----------------------
7826 -- Ensure_Type_Is_SA --
7827 -----------------------
7829 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
7834 -- If type is library level, we are all set
7836 if Is_Library_Level_Entity
(Typ
) then
7840 -- We are also OK if the type already marked as statically allocated,
7841 -- which means we processed it before.
7843 if Is_Statically_Allocated
(Typ
) then
7847 -- Mark type as statically allocated
7849 Set_Is_Statically_Allocated
(Typ
);
7851 -- Check that it is safe to statically allocate this type
7853 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
7854 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
7855 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
7857 elsif Is_Array_Type
(Typ
) then
7858 N
:= First_Index
(Typ
);
7859 while Present
(N
) loop
7860 Ensure_Type_Is_SA
(Etype
(N
));
7864 Ensure_Type_Is_SA
(Component_Type
(Typ
));
7866 elsif Is_Access_Type
(Typ
) then
7867 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
7871 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
7874 if T
/= Standard_Void_Type
then
7875 Ensure_Type_Is_SA
(T
);
7878 F
:= First_Formal
(Designated_Type
(Typ
));
7879 while Present
(F
) loop
7880 Ensure_Type_Is_SA
(Etype
(F
));
7886 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
7889 elsif Is_Record_Type
(Typ
) then
7890 C
:= First_Entity
(Typ
);
7891 while Present
(C
) loop
7892 if Ekind
(C
) = E_Discriminant
7893 or else Ekind
(C
) = E_Component
7895 Ensure_Type_Is_SA
(Etype
(C
));
7897 elsif Is_Type
(C
) then
7898 Ensure_Type_Is_SA
(C
);
7904 elsif Ekind
(Typ
) = E_Subprogram_Type
then
7905 Ensure_Type_Is_SA
(Etype
(Typ
));
7907 C
:= First_Formal
(Typ
);
7908 while Present
(C
) loop
7909 Ensure_Type_Is_SA
(Etype
(C
));
7914 raise Cannot_Be_Static
;
7916 end Ensure_Type_Is_SA
;
7918 -- Start of processing for Freeze_Static_Object
7921 Ensure_Type_Is_SA
(Etype
(E
));
7924 when Cannot_Be_Static
=>
7926 -- If the object that cannot be static is imported or exported, then
7927 -- issue an error message saying that this object cannot be imported
7928 -- or exported. If it has an address clause it is an overlay in the
7929 -- current partition and the static requirement is not relevant.
7930 -- Do not issue any error message when ignoring rep clauses.
7932 if Ignore_Rep_Clauses
then
7935 elsif Is_Imported
(E
) then
7936 if No
(Address_Clause
(E
)) then
7938 ("& cannot be imported (local type is not constant)", E
);
7941 -- Otherwise must be exported, something is wrong if compiler
7942 -- is marking something as statically allocated which cannot be).
7944 else pragma Assert
(Is_Exported
(E
));
7946 ("& cannot be exported (local type is not constant)", E
);
7948 end Freeze_Static_Object
;
7950 -----------------------
7951 -- Freeze_Subprogram --
7952 -----------------------
7954 procedure Freeze_Subprogram
(E
: Entity_Id
) is
7955 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
);
7956 -- Set the conventions of all anonymous access-to-subprogram formals and
7957 -- result subtype of subprogram Subp_Id to the convention of Subp_Id.
7959 ----------------------------
7960 -- Set_Profile_Convention --
7961 ----------------------------
7963 procedure Set_Profile_Convention
(Subp_Id
: Entity_Id
) is
7964 Conv
: constant Convention_Id
:= Convention
(Subp_Id
);
7966 procedure Set_Type_Convention
(Typ
: Entity_Id
);
7967 -- Set the convention of anonymous access-to-subprogram type Typ and
7968 -- its designated type to Conv.
7970 -------------------------
7971 -- Set_Type_Convention --
7972 -------------------------
7974 procedure Set_Type_Convention
(Typ
: Entity_Id
) is
7976 -- Set the convention on both the anonymous access-to-subprogram
7977 -- type and the subprogram type it points to because both types
7978 -- participate in conformance-related checks.
7980 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
7981 Set_Convention
(Typ
, Conv
);
7982 Set_Convention
(Designated_Type
(Typ
), Conv
);
7984 end Set_Type_Convention
;
7990 -- Start of processing for Set_Profile_Convention
7993 Formal
:= First_Formal
(Subp_Id
);
7994 while Present
(Formal
) loop
7995 Set_Type_Convention
(Etype
(Formal
));
7996 Next_Formal
(Formal
);
7999 if Ekind
(Subp_Id
) = E_Function
then
8000 Set_Type_Convention
(Etype
(Subp_Id
));
8002 end Set_Profile_Convention
;
8009 -- Start of processing for Freeze_Subprogram
8012 -- Subprogram may not have an address clause unless it is imported
8014 if Present
(Address_Clause
(E
)) then
8015 if not Is_Imported
(E
) then
8017 ("address clause can only be given for imported subprogram",
8018 Name
(Address_Clause
(E
)));
8022 -- Reset the Pure indication on an imported subprogram unless an
8023 -- explicit Pure_Function pragma was present or the subprogram is an
8024 -- intrinsic. We do this because otherwise it is an insidious error
8025 -- to call a non-pure function from pure unit and have calls
8026 -- mysteriously optimized away. What happens here is that the Import
8027 -- can bypass the normal check to ensure that pure units call only pure
8030 -- The reason for the intrinsic exception is that in general, intrinsic
8031 -- functions (such as shifts) are pure anyway. The only exceptions are
8032 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
8033 -- in any case, so no problem arises.
8036 and then Is_Pure
(E
)
8037 and then not Has_Pragma_Pure_Function
(E
)
8038 and then not Is_Intrinsic_Subprogram
(E
)
8040 Set_Is_Pure
(E
, False);
8043 -- We also reset the Pure indication on a subprogram with an Address
8044 -- parameter, because the parameter may be used as a pointer and the
8045 -- referenced data may change even if the address value does not.
8047 -- Note that if the programmer gave an explicit Pure_Function pragma,
8048 -- then we believe the programmer, and leave the subprogram Pure. We
8049 -- also suppress this check on run-time files.
8052 and then Is_Subprogram
(E
)
8053 and then not Has_Pragma_Pure_Function
(E
)
8054 and then not Is_Internal_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
8056 Check_Function_With_Address_Parameter
(E
);
8059 -- Ensure that all anonymous access-to-subprogram types inherit the
8060 -- convention of their related subprogram (RM 6.3.1 13.1/3). This is
8061 -- not done for a defaulted convention Ada because those types also
8062 -- default to Ada. Convention Protected must not be propagated when
8063 -- the subprogram is an entry because this would be illegal. The only
8064 -- way to force convention Protected on these kinds of types is to
8065 -- include keyword "protected" in the access definition.
8067 if Convention
(E
) /= Convention_Ada
8068 and then Convention
(E
) /= Convention_Protected
8070 Set_Profile_Convention
(E
);
8073 -- For non-foreign convention subprograms, this is where we create
8074 -- the extra formals (for accessibility level and constrained bit
8075 -- information). We delay this till the freeze point precisely so
8076 -- that we know the convention.
8078 if not Has_Foreign_Convention
(E
) then
8079 Create_Extra_Formals
(E
);
8082 -- If this is convention Ada and a Valued_Procedure, that's odd
8084 if Ekind
(E
) = E_Procedure
8085 and then Is_Valued_Procedure
(E
)
8086 and then Convention
(E
) = Convention_Ada
8087 and then Warn_On_Export_Import
8090 ("??Valued_Procedure has no effect for convention Ada", E
);
8091 Set_Is_Valued_Procedure
(E
, False);
8094 -- Case of foreign convention
8099 -- For foreign conventions, warn about return of unconstrained array
8101 if Ekind
(E
) = E_Function
then
8102 Retype
:= Underlying_Type
(Etype
(E
));
8104 -- If no return type, probably some other error, e.g. a
8105 -- missing full declaration, so ignore.
8110 -- If the return type is generic, we have emitted a warning
8111 -- earlier on, and there is nothing else to check here. Specific
8112 -- instantiations may lead to erroneous behavior.
8114 elsif Is_Generic_Type
(Etype
(E
)) then
8117 -- Display warning if returning unconstrained array
8119 elsif Is_Array_Type
(Retype
)
8120 and then not Is_Constrained
(Retype
)
8122 -- Check appropriate warning is enabled (should we check for
8123 -- Warnings (Off) on specific entities here, probably so???)
8125 and then Warn_On_Export_Import
8128 ("?x?foreign convention function& should not return " &
8129 "unconstrained array", E
);
8134 -- If any of the formals for an exported foreign convention
8135 -- subprogram have defaults, then emit an appropriate warning since
8136 -- this is odd (default cannot be used from non-Ada code)
8138 if Is_Exported
(E
) then
8139 F
:= First_Formal
(E
);
8140 while Present
(F
) loop
8141 if Warn_On_Export_Import
8142 and then Present
(Default_Value
(F
))
8145 ("?x?parameter cannot be defaulted in non-Ada call",
8154 -- Pragma Inline_Always is disallowed for dispatching subprograms
8155 -- because the address of such subprograms is saved in the dispatch
8156 -- table to support dispatching calls, and dispatching calls cannot
8157 -- be inlined. This is consistent with the restriction against using
8158 -- 'Access or 'Address on an Inline_Always subprogram.
8160 if Is_Dispatching_Operation
(E
)
8161 and then Has_Pragma_Inline_Always
(E
)
8164 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
8167 -- Because of the implicit representation of inherited predefined
8168 -- operators in the front-end, the overriding status of the operation
8169 -- may be affected when a full view of a type is analyzed, and this is
8170 -- not captured by the analysis of the corresponding type declaration.
8171 -- Therefore the correctness of a not-overriding indicator must be
8172 -- rechecked when the subprogram is frozen.
8174 if Nkind
(E
) = N_Defining_Operator_Symbol
8175 and then not Error_Posted
(Parent
(E
))
8177 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
8180 if Modify_Tree_For_C
8181 and then Nkind
(Parent
(E
)) = N_Function_Specification
8182 and then Is_Array_Type
(Etype
(E
))
8183 and then Is_Constrained
(Etype
(E
))
8184 and then not Is_Unchecked_Conversion_Instance
(E
)
8185 and then not Rewritten_For_C
(E
)
8187 Build_Procedure_Form
(Unit_Declaration_Node
(E
));
8189 end Freeze_Subprogram
;
8191 ----------------------
8192 -- Is_Fully_Defined --
8193 ----------------------
8195 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
8197 if Ekind
(T
) = E_Class_Wide_Type
then
8198 return Is_Fully_Defined
(Etype
(T
));
8200 elsif Is_Array_Type
(T
) then
8201 return Is_Fully_Defined
(Component_Type
(T
));
8203 elsif Is_Record_Type
(T
)
8204 and not Is_Private_Type
(T
)
8206 -- Verify that the record type has no components with private types
8207 -- without completion.
8213 Comp
:= First_Component
(T
);
8214 while Present
(Comp
) loop
8215 if not Is_Fully_Defined
(Etype
(Comp
)) then
8219 Next_Component
(Comp
);
8224 -- For the designated type of an access to subprogram, all types in
8225 -- the profile must be fully defined.
8227 elsif Ekind
(T
) = E_Subprogram_Type
then
8232 F
:= First_Formal
(T
);
8233 while Present
(F
) loop
8234 if not Is_Fully_Defined
(Etype
(F
)) then
8241 return Is_Fully_Defined
(Etype
(T
));
8245 return not Is_Private_Type
(T
)
8246 or else Present
(Full_View
(Base_Type
(T
)));
8248 end Is_Fully_Defined
;
8250 ---------------------------------
8251 -- Process_Default_Expressions --
8252 ---------------------------------
8254 procedure Process_Default_Expressions
8256 After
: in out Node_Id
)
8258 Loc
: constant Source_Ptr
:= Sloc
(E
);
8265 Set_Default_Expressions_Processed
(E
);
8267 -- A subprogram instance and its associated anonymous subprogram share
8268 -- their signature. The default expression functions are defined in the
8269 -- wrapper packages for the anonymous subprogram, and should not be
8270 -- generated again for the instance.
8272 if Is_Generic_Instance
(E
)
8273 and then Present
(Alias
(E
))
8274 and then Default_Expressions_Processed
(Alias
(E
))
8279 Formal
:= First_Formal
(E
);
8280 while Present
(Formal
) loop
8281 if Present
(Default_Value
(Formal
)) then
8283 -- We work with a copy of the default expression because we
8284 -- do not want to disturb the original, since this would mess
8285 -- up the conformance checking.
8287 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
8289 -- The analysis of the expression may generate insert actions,
8290 -- which of course must not be executed. We wrap those actions
8291 -- in a procedure that is not called, and later on eliminated.
8292 -- The following cases have no side-effects, and are analyzed
8295 if Nkind
(Dcopy
) = N_Identifier
8296 or else Nkind_In
(Dcopy
, N_Expanded_Name
,
8298 N_Character_Literal
,
8301 or else (Nkind
(Dcopy
) = N_Attribute_Reference
8302 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
8303 or else Known_Null
(Dcopy
)
8305 -- If there is no default function, we must still do a full
8306 -- analyze call on the default value, to ensure that all error
8307 -- checks are performed, e.g. those associated with static
8308 -- evaluation. Note: this branch will always be taken if the
8309 -- analyzer is turned off (but we still need the error checks).
8311 -- Note: the setting of parent here is to meet the requirement
8312 -- that we can only analyze the expression while attached to
8313 -- the tree. Really the requirement is that the parent chain
8314 -- be set, we don't actually need to be in the tree.
8316 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
8319 -- Default expressions are resolved with their own type if the
8320 -- context is generic, to avoid anomalies with private types.
8322 if Ekind
(Scope
(E
)) = E_Generic_Package
then
8325 Resolve
(Dcopy
, Etype
(Formal
));
8328 -- If that resolved expression will raise constraint error,
8329 -- then flag the default value as raising constraint error.
8330 -- This allows a proper error message on the calls.
8332 if Raises_Constraint_Error
(Dcopy
) then
8333 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
8336 -- If the default is a parameterless call, we use the name of
8337 -- the called function directly, and there is no body to build.
8339 elsif Nkind
(Dcopy
) = N_Function_Call
8340 and then No
(Parameter_Associations
(Dcopy
))
8344 -- Else construct and analyze the body of a wrapper procedure
8345 -- that contains an object declaration to hold the expression.
8346 -- Given that this is done only to complete the analysis, it is
8347 -- simpler to build a procedure than a function which might
8348 -- involve secondary stack expansion.
8351 Dnam
:= Make_Temporary
(Loc
, 'D');
8354 Make_Subprogram_Body
(Loc
,
8356 Make_Procedure_Specification
(Loc
,
8357 Defining_Unit_Name
=> Dnam
),
8359 Declarations
=> New_List
(
8360 Make_Object_Declaration
(Loc
,
8361 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
8362 Object_Definition
=>
8363 New_Occurrence_Of
(Etype
(Formal
), Loc
),
8364 Expression
=> New_Copy_Tree
(Dcopy
))),
8366 Handled_Statement_Sequence
=>
8367 Make_Handled_Sequence_Of_Statements
(Loc
,
8368 Statements
=> Empty_List
));
8370 Set_Scope
(Dnam
, Scope
(E
));
8371 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
8372 Set_Is_Eliminated
(Dnam
);
8373 Insert_After
(After
, Dbody
);
8379 Next_Formal
(Formal
);
8381 end Process_Default_Expressions
;
8383 ----------------------------------------
8384 -- Set_Component_Alignment_If_Not_Set --
8385 ----------------------------------------
8387 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
8389 -- Ignore if not base type, subtypes don't need anything
8391 if Typ
/= Base_Type
(Typ
) then
8395 -- Do not override existing representation
8397 if Is_Packed
(Typ
) then
8400 elsif Has_Specified_Layout
(Typ
) then
8403 elsif Component_Alignment
(Typ
) /= Calign_Default
then
8407 Set_Component_Alignment
8408 (Typ
, Scope_Stack
.Table
8409 (Scope_Stack
.Last
).Component_Alignment_Default
);
8411 end Set_Component_Alignment_If_Not_Set
;
8413 --------------------------
8414 -- Set_SSO_From_Default --
8415 --------------------------
8417 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
8421 -- Set default SSO for an array or record base type, except in case of
8422 -- a type extension (which always inherits the SSO of its parent type).
8425 and then (Is_Array_Type
(T
)
8426 or else (Is_Record_Type
(T
)
8427 and then not (Is_Tagged_Type
(T
)
8428 and then Is_Derived_Type
(T
))))
8431 (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
8433 (not Bytes_Big_Endian
and then SSO_Set_High_By_Default
(T
));
8435 if (SSO_Set_Low_By_Default
(T
) or else SSO_Set_High_By_Default
(T
))
8437 -- For a record type, if bit order is specified explicitly,
8438 -- then do not set SSO from default if not consistent. Note that
8439 -- we do not want to look at a Bit_Order attribute definition
8440 -- for a parent: if we were to inherit Bit_Order, then both
8441 -- SSO_Set_*_By_Default flags would have been cleared already
8442 -- (by Inherit_Aspects_At_Freeze_Point).
8447 Has_Rep_Item
(T
, Name_Bit_Order
, Check_Parents
=> False)
8448 and then Reverse_Bit_Order
(T
) /= Reversed
)
8450 -- If flags cause reverse storage order, then set the result. Note
8451 -- that we would have ignored the pragma setting the non default
8452 -- storage order in any case, hence the assertion at this point.
8455 (not Reversed
or else Support_Nondefault_SSO_On_Target
);
8457 Set_Reverse_Storage_Order
(T
, Reversed
);
8459 -- For a record type, also set reversed bit order. Note: if a bit
8460 -- order has been specified explicitly, then this is a no-op.
8462 if Is_Record_Type
(T
) then
8463 Set_Reverse_Bit_Order
(T
, Reversed
);
8467 end Set_SSO_From_Default
;
8473 procedure Undelay_Type
(T
: Entity_Id
) is
8475 Set_Has_Delayed_Freeze
(T
, False);
8476 Set_Freeze_Node
(T
, Empty
);
8478 -- Since we don't want T to have a Freeze_Node, we don't want its
8479 -- Full_View or Corresponding_Record_Type to have one either.
8481 -- ??? Fundamentally, this whole handling is unpleasant. What we really
8482 -- want is to be sure that for an Itype that's part of record R and is a
8483 -- subtype of type T, that it's frozen after the later of the freeze
8484 -- points of R and T. We have no way of doing that directly, so what we
8485 -- do is force most such Itypes to be frozen as part of freezing R via
8486 -- this procedure and only delay the ones that need to be delayed
8487 -- (mostly the designated types of access types that are defined as part
8490 if Is_Private_Type
(T
)
8491 and then Present
(Full_View
(T
))
8492 and then Is_Itype
(Full_View
(T
))
8493 and then Is_Record_Type
(Scope
(Full_View
(T
)))
8495 Undelay_Type
(Full_View
(T
));
8498 if Is_Concurrent_Type
(T
)
8499 and then Present
(Corresponding_Record_Type
(T
))
8500 and then Is_Itype
(Corresponding_Record_Type
(T
))
8501 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
8503 Undelay_Type
(Corresponding_Record_Type
(T
));
8511 procedure Warn_Overlay
(Expr
: Node_Id
; Typ
: Entity_Id
; Nam
: Entity_Id
) is
8512 Ent
: constant Entity_Id
:= Entity
(Nam
);
8513 -- The object to which the address clause applies
8516 Old
: Entity_Id
:= Empty
;
8520 -- No warning if address clause overlay warnings are off
8522 if not Address_Clause_Overlay_Warnings
then
8526 -- No warning if there is an explicit initialization
8528 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
8530 if Present
(Init
) and then Comes_From_Source
(Init
) then
8534 -- We only give the warning for non-imported entities of a type for
8535 -- which a non-null base init proc is defined, or for objects of access
8536 -- types with implicit null initialization, or when Normalize_Scalars
8537 -- applies and the type is scalar or a string type (the latter being
8538 -- tested for because predefined String types are initialized by inline
8539 -- code rather than by an init_proc). Note that we do not give the
8540 -- warning for Initialize_Scalars, since we suppressed initialization
8541 -- in this case. Also, do not warn if Suppress_Initialization is set.
8544 and then not Is_Imported
(Ent
)
8545 and then not Initialization_Suppressed
(Typ
)
8546 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
8547 or else Is_Access_Type
(Typ
)
8548 or else (Normalize_Scalars
8549 and then (Is_Scalar_Type
(Typ
)
8550 or else Is_String_Type
(Typ
))))
8552 if Nkind
(Expr
) = N_Attribute_Reference
8553 and then Is_Entity_Name
(Prefix
(Expr
))
8555 Old
:= Entity
(Prefix
(Expr
));
8557 elsif Is_Entity_Name
(Expr
)
8558 and then Ekind
(Entity
(Expr
)) = E_Constant
8560 Decl
:= Declaration_Node
(Entity
(Expr
));
8562 if Nkind
(Decl
) = N_Object_Declaration
8563 and then Present
(Expression
(Decl
))
8564 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
8565 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
8567 Old
:= Entity
(Prefix
(Expression
(Decl
)));
8569 elsif Nkind
(Expr
) = N_Function_Call
then
8573 -- A function call (most likely to To_Address) is probably not an
8574 -- overlay, so skip warning. Ditto if the function call was inlined
8575 -- and transformed into an entity.
8577 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
8581 -- If a pragma Import follows, we assume that it is for the current
8582 -- target of the address clause, and skip the warning. There may be
8583 -- a source pragma or an aspect that specifies import and generates
8584 -- the corresponding pragma. These will indicate that the entity is
8585 -- imported and that is checked above so that the spurious warning
8586 -- (generated when the entity is frozen) will be suppressed. The
8587 -- pragma may be attached to the aspect, so it is not yet a list
8590 if Is_List_Member
(Parent
(Expr
)) then
8591 Decl
:= Next
(Parent
(Expr
));
8594 and then Nkind
(Decl
) = N_Pragma
8595 and then Pragma_Name
(Decl
) = Name_Import
8601 -- Otherwise give warning message
8603 if Present
(Old
) then
8604 Error_Msg_Node_2
:= Old
;
8606 ("default initialization of & may modify &??",
8610 ("default initialization of & may modify overlaid storage??",
8614 -- Add friendly warning if initialization comes from a packed array
8617 if Is_Record_Type
(Typ
) then
8622 Comp
:= First_Component
(Typ
);
8623 while Present
(Comp
) loop
8624 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
8625 and then Present
(Expression
(Parent
(Comp
)))
8628 elsif Is_Array_Type
(Etype
(Comp
))
8629 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
8632 ("\packed array component& " &
8633 "will be initialized to zero??",
8637 Next_Component
(Comp
);
8644 ("\use pragma Import for & to " &
8645 "suppress initialization (RM B.1(24))??",