1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Ch3
; use Exp_Ch3
;
33 with Exp_Ch7
; use Exp_Ch7
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Pakd
; use Exp_Pakd
;
36 with Exp_Util
; use Exp_Util
;
37 with Exp_Tss
; use Exp_Tss
;
38 with Layout
; use Layout
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Cat
; use Sem_Cat
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch7
; use Sem_Ch7
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Ch9
; use Sem_Ch9
;
54 with Sem_Ch13
; use Sem_Ch13
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Mech
; use Sem_Mech
;
57 with Sem_Prag
; use Sem_Prag
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Util
; use Sem_Util
;
60 with Sinfo
; use Sinfo
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Targparm
; use Targparm
;
64 with Tbuild
; use Tbuild
;
65 with Ttypes
; use Ttypes
;
66 with Uintp
; use Uintp
;
67 with Urealp
; use Urealp
;
69 package body Freeze
is
71 -----------------------
72 -- Local Subprograms --
73 -----------------------
75 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
76 -- Typ is a type that is being frozen. If no size clause is given,
77 -- but a default Esize has been computed, then this default Esize is
78 -- adjusted up if necessary to be consistent with a given alignment,
79 -- but never to a value greater than Long_Long_Integer'Size. This
80 -- is used for all discrete types and for fixed-point types.
82 procedure Build_And_Analyze_Renamed_Body
85 After
: in out Node_Id
);
86 -- Build body for a renaming declaration, insert in tree and analyze
88 procedure Check_Address_Clause
(E
: Entity_Id
);
89 -- Apply legality checks to address clauses for object declarations,
90 -- at the point the object is frozen. Also ensure any initialization is
91 -- performed only after the object has been frozen.
93 procedure Check_Component_Storage_Order
94 (Encl_Type
: Entity_Id
;
97 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
98 -- clause, verify that the component type has an explicit and compatible
99 -- attribute/aspect. For arrays, Comp is Empty; for records, it is the
100 -- entity of the component under consideration. For an Encl_Type that
101 -- does not have a Scalar_Storage_Order attribute definition clause,
102 -- verify that the component also does not have such a clause.
103 -- ADC is the attribute definition clause if present (or Empty).
105 procedure Check_Strict_Alignment
(E
: Entity_Id
);
106 -- E is a base type. If E is tagged or has a component that is aliased
107 -- or tagged or contains something this is aliased or tagged, set
110 procedure Check_Unsigned_Type
(E
: Entity_Id
);
111 pragma Inline
(Check_Unsigned_Type
);
112 -- If E is a fixed-point or discrete type, then all the necessary work
113 -- to freeze it is completed except for possible setting of the flag
114 -- Is_Unsigned_Type, which is done by this procedure. The call has no
115 -- effect if the entity E is not a discrete or fixed-point type.
117 procedure Freeze_And_Append
120 Result
: in out List_Id
);
121 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
122 -- nodes to Result, modifying Result from No_List if necessary. N has
123 -- the same usage as in Freeze_Entity.
125 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
126 -- Freeze enumeration type. The Esize field is set as processing
127 -- proceeds (i.e. set by default when the type is declared and then
128 -- adjusted by rep clauses. What this procedure does is to make sure
129 -- that if a foreign convention is specified, and no specific size
130 -- is given, then the size must be at least Integer'Size.
132 procedure Freeze_Static_Object
(E
: Entity_Id
);
133 -- If an object is frozen which has Is_Statically_Allocated set, then
134 -- all referenced types must also be marked with this flag. This routine
135 -- is in charge of meeting this requirement for the object entity E.
137 procedure Freeze_Subprogram
(E
: Entity_Id
);
138 -- Perform freezing actions for a subprogram (create extra formals,
139 -- and set proper default mechanism values). Note that this routine
140 -- is not called for internal subprograms, for which neither of these
141 -- actions is needed (or desirable, we do not want for example to have
142 -- these extra formals present in initialization procedures, where they
143 -- would serve no purpose). In this call E is either a subprogram or
144 -- a subprogram type (i.e. an access to a subprogram).
146 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
147 -- True if T is not private and has no private components, or has a full
148 -- view. Used to determine whether the designated type of an access type
149 -- should be frozen when the access type is frozen. This is done when an
150 -- allocator is frozen, or an expression that may involve attributes of
151 -- the designated type. Otherwise freezing the access type does not freeze
152 -- the designated type.
154 procedure Process_Default_Expressions
156 After
: in out Node_Id
);
157 -- This procedure is called for each subprogram to complete processing of
158 -- default expressions at the point where all types are known to be frozen.
159 -- The expressions must be analyzed in full, to make sure that all error
160 -- processing is done (they have only been pre-analyzed). If the expression
161 -- is not an entity or literal, its analysis may generate code which must
162 -- not be executed. In that case we build a function body to hold that
163 -- code. This wrapper function serves no other purpose (it used to be
164 -- called to evaluate the default, but now the default is inlined at each
167 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
168 -- Typ is a record or array type that is being frozen. This routine sets
169 -- the default component alignment from the scope stack values if the
170 -- alignment is otherwise not specified.
172 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
173 -- As each entity is frozen, this routine is called to deal with the
174 -- setting of Debug_Info_Needed for the entity. This flag is set if
175 -- the entity comes from source, or if we are in Debug_Generated_Code
176 -- mode or if the -gnatdV debug flag is set. However, it never sets
177 -- the flag if Debug_Info_Off is set. This procedure also ensures that
178 -- subsidiary entities have the flag set as required.
180 procedure Undelay_Type
(T
: Entity_Id
);
181 -- T is a type of a component that we know to be an Itype. We don't want
182 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
183 -- Full_View or Corresponding_Record_Type.
185 procedure Warn_Overlay
189 -- Expr is the expression for an address clause for entity Nam whose type
190 -- is Typ. If Typ has a default initialization, and there is no explicit
191 -- initialization in the source declaration, check whether the address
192 -- clause might cause overlaying of an entity, and emit a warning on the
193 -- side effect that the initialization will cause.
195 -------------------------------
196 -- Adjust_Esize_For_Alignment --
197 -------------------------------
199 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
203 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
204 Align
:= Alignment_In_Bits
(Typ
);
206 if Align
> Esize
(Typ
)
207 and then Align
<= Standard_Long_Long_Integer_Size
209 Set_Esize
(Typ
, Align
);
212 end Adjust_Esize_For_Alignment
;
214 ------------------------------------
215 -- Build_And_Analyze_Renamed_Body --
216 ------------------------------------
218 procedure Build_And_Analyze_Renamed_Body
221 After
: in out Node_Id
)
223 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
224 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
226 Renamed_Subp
: Entity_Id
;
229 -- If the renamed subprogram is intrinsic, there is no need for a
230 -- wrapper body: we set the alias that will be called and expanded which
231 -- completes the declaration. This transformation is only legal if the
232 -- renamed entity has already been elaborated.
234 -- Note that it is legal for a renaming_as_body to rename an intrinsic
235 -- subprogram, as long as the renaming occurs before the new entity
236 -- is frozen. See RM 8.5.4 (5).
238 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
239 and then Is_Entity_Name
(Name
(Body_Decl
))
241 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
243 Renamed_Subp
:= Empty
;
246 if Present
(Renamed_Subp
)
247 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
249 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
250 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
252 -- We can make the renaming entity intrinsic if the renamed function
253 -- has an interface name, or if it is one of the shift/rotate
254 -- operations known to the compiler.
257 (Present
(Interface_Name
(Renamed_Subp
))
258 or else Nam_In
(Chars
(Renamed_Subp
), Name_Rotate_Left
,
262 Name_Shift_Right_Arithmetic
))
264 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
266 if Present
(Alias
(Renamed_Subp
)) then
267 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
269 Set_Alias
(Ent
, Renamed_Subp
);
272 Set_Is_Intrinsic_Subprogram
(Ent
);
273 Set_Has_Completion
(Ent
);
276 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
277 Insert_After
(After
, Body_Node
);
278 Mark_Rewrite_Insertion
(Body_Node
);
282 end Build_And_Analyze_Renamed_Body
;
284 ------------------------
285 -- Build_Renamed_Body --
286 ------------------------
288 function Build_Renamed_Body
290 New_S
: Entity_Id
) return Node_Id
292 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
293 -- We use for the source location of the renamed body, the location of
294 -- the spec entity. It might seem more natural to use the location of
295 -- the renaming declaration itself, but that would be wrong, since then
296 -- the body we create would look as though it was created far too late,
297 -- and this could cause problems with elaboration order analysis,
298 -- particularly in connection with instantiations.
300 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
301 Nam
: constant Node_Id
:= Name
(N
);
303 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
304 Actuals
: List_Id
:= No_List
;
309 O_Formal
: Entity_Id
;
310 Param_Spec
: Node_Id
;
312 Pref
: Node_Id
:= Empty
;
313 -- If the renamed entity is a primitive operation given in prefix form,
314 -- the prefix is the target object and it has to be added as the first
315 -- actual in the generated call.
318 -- Determine the entity being renamed, which is the target of the call
319 -- statement. If the name is an explicit dereference, this is a renaming
320 -- of a subprogram type rather than a subprogram. The name itself is
323 if Nkind
(Nam
) = N_Selected_Component
then
324 Old_S
:= Entity
(Selector_Name
(Nam
));
326 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
327 Old_S
:= Etype
(Nam
);
329 elsif Nkind
(Nam
) = N_Indexed_Component
then
330 if Is_Entity_Name
(Prefix
(Nam
)) then
331 Old_S
:= Entity
(Prefix
(Nam
));
333 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
336 elsif Nkind
(Nam
) = N_Character_Literal
then
337 Old_S
:= Etype
(New_S
);
340 Old_S
:= Entity
(Nam
);
343 if Is_Entity_Name
(Nam
) then
345 -- If the renamed entity is a predefined operator, retain full name
346 -- to ensure its visibility.
348 if Ekind
(Old_S
) = E_Operator
349 and then Nkind
(Nam
) = N_Expanded_Name
351 Call_Name
:= New_Copy
(Name
(N
));
353 Call_Name
:= New_Reference_To
(Old_S
, Loc
);
357 if Nkind
(Nam
) = N_Selected_Component
358 and then Present
(First_Formal
(Old_S
))
360 (Is_Controlling_Formal
(First_Formal
(Old_S
))
361 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
364 -- Retrieve the target object, to be added as a first actual
367 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
368 Pref
:= Prefix
(Nam
);
371 Call_Name
:= New_Copy
(Name
(N
));
374 -- Original name may have been overloaded, but is fully resolved now
376 Set_Is_Overloaded
(Call_Name
, False);
379 -- For simple renamings, subsequent calls can be expanded directly as
380 -- calls to the renamed entity. The body must be generated in any case
381 -- for calls that may appear elsewhere. This is not done in the case
382 -- where the subprogram is an instantiation because the actual proper
383 -- body has not been built yet.
385 if Ekind_In
(Old_S
, E_Function
, E_Procedure
)
386 and then Nkind
(Decl
) = N_Subprogram_Declaration
387 and then not Is_Generic_Instance
(Old_S
)
389 Set_Body_To_Inline
(Decl
, Old_S
);
392 -- The body generated for this renaming is an internal artifact, and
393 -- does not constitute a freeze point for the called entity.
395 Set_Must_Not_Freeze
(Call_Name
);
397 Formal
:= First_Formal
(Defining_Entity
(Decl
));
399 if Present
(Pref
) then
401 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
402 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
405 -- The controlling formal may be an access parameter, or the
406 -- actual may be an access value, so adjust accordingly.
408 if Is_Access_Type
(Pref_Type
)
409 and then not Is_Access_Type
(Form_Type
)
412 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
414 elsif Is_Access_Type
(Form_Type
)
415 and then not Is_Access_Type
(Pref
)
418 (Make_Attribute_Reference
(Loc
,
419 Attribute_Name
=> Name_Access
,
420 Prefix
=> Relocate_Node
(Pref
)));
422 Actuals
:= New_List
(Pref
);
426 elsif Present
(Formal
) then
433 if Present
(Formal
) then
434 while Present
(Formal
) loop
435 Append
(New_Reference_To
(Formal
, Loc
), Actuals
);
436 Next_Formal
(Formal
);
440 -- If the renamed entity is an entry, inherit its profile. For other
441 -- renamings as bodies, both profiles must be subtype conformant, so it
442 -- is not necessary to replace the profile given in the declaration.
443 -- However, default values that are aggregates are rewritten when
444 -- partially analyzed, so we recover the original aggregate to insure
445 -- that subsequent conformity checking works. Similarly, if the default
446 -- expression was constant-folded, recover the original expression.
448 Formal
:= First_Formal
(Defining_Entity
(Decl
));
450 if Present
(Formal
) then
451 O_Formal
:= First_Formal
(Old_S
);
452 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
453 while Present
(Formal
) loop
454 if Is_Entry
(Old_S
) then
455 if Nkind
(Parameter_Type
(Param_Spec
)) /=
458 Set_Etype
(Formal
, Etype
(O_Formal
));
459 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
462 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
463 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
464 Nkind
(Default_Value
(O_Formal
))
466 Set_Expression
(Param_Spec
,
467 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
470 Next_Formal
(Formal
);
471 Next_Formal
(O_Formal
);
476 -- If the renamed entity is a function, the generated body contains a
477 -- return statement. Otherwise, build a procedure call. If the entity is
478 -- an entry, subsequent analysis of the call will transform it into the
479 -- proper entry or protected operation call. If the renamed entity is
480 -- a character literal, return it directly.
482 if Ekind
(Old_S
) = E_Function
483 or else Ekind
(Old_S
) = E_Operator
484 or else (Ekind
(Old_S
) = E_Subprogram_Type
485 and then Etype
(Old_S
) /= Standard_Void_Type
)
488 Make_Simple_Return_Statement
(Loc
,
490 Make_Function_Call
(Loc
,
492 Parameter_Associations
=> Actuals
));
494 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
496 Make_Simple_Return_Statement
(Loc
,
497 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
499 elsif Nkind
(Nam
) = N_Character_Literal
then
501 Make_Simple_Return_Statement
(Loc
,
502 Expression
=> Call_Name
);
506 Make_Procedure_Call_Statement
(Loc
,
508 Parameter_Associations
=> Actuals
);
511 -- Create entities for subprogram body and formals
513 Set_Defining_Unit_Name
(Spec
,
514 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
516 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
517 while Present
(Param_Spec
) loop
518 Set_Defining_Identifier
(Param_Spec
,
519 Make_Defining_Identifier
(Loc
,
520 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
525 Make_Subprogram_Body
(Loc
,
526 Specification
=> Spec
,
527 Declarations
=> New_List
,
528 Handled_Statement_Sequence
=>
529 Make_Handled_Sequence_Of_Statements
(Loc
,
530 Statements
=> New_List
(Call_Node
)));
532 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
534 Make_Subprogram_Declaration
(Loc
,
535 Specification
=> Specification
(N
)));
538 -- Link the body to the entity whose declaration it completes. If
539 -- the body is analyzed when the renamed entity is frozen, it may
540 -- be necessary to restore the proper scope (see package Exp_Ch13).
542 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
543 and then Present
(Corresponding_Spec
(N
))
545 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
547 Set_Corresponding_Spec
(Body_Node
, New_S
);
551 end Build_Renamed_Body
;
553 --------------------------
554 -- Check_Address_Clause --
555 --------------------------
557 procedure Check_Address_Clause
(E
: Entity_Id
) is
558 Addr
: constant Node_Id
:= Address_Clause
(E
);
560 Decl
: constant Node_Id
:= Declaration_Node
(E
);
561 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
562 Typ
: constant Entity_Id
:= Etype
(E
);
565 if Present
(Addr
) then
566 Expr
:= Expression
(Addr
);
568 if Needs_Constant_Address
(Decl
, Typ
) then
569 Check_Constant_Address_Clause
(Expr
, E
);
571 -- Has_Delayed_Freeze was set on E when the address clause was
572 -- analyzed, and must remain set because we want the address
573 -- clause to be elaborated only after any entity it references
574 -- has been elaborated.
577 -- If Rep_Clauses are to be ignored, remove address clause from
578 -- list attached to entity, because it may be illegal for gigi,
579 -- for example by breaking order of elaboration..
581 if Ignore_Rep_Clauses
then
586 Rep
:= First_Rep_Item
(E
);
589 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
593 and then Next_Rep_Item
(Rep
) /= Addr
595 Rep
:= Next_Rep_Item
(Rep
);
599 if Present
(Rep
) then
600 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
604 Rewrite
(Addr
, Make_Null_Statement
(Sloc
(E
)));
606 elsif not Error_Posted
(Expr
)
607 and then not Needs_Finalization
(Typ
)
609 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
612 if Present
(Expression
(Decl
)) then
614 -- Capture initialization value at point of declaration
616 Remove_Side_Effects
(Expression
(Decl
));
618 -- Move initialization to freeze actions (once the object has
619 -- been frozen, and the address clause alignment check has been
622 Append_Freeze_Action
(E
,
623 Make_Assignment_Statement
(Loc
,
624 Name
=> New_Occurrence_Of
(E
, Loc
),
625 Expression
=> Expression
(Decl
)));
627 Set_No_Initialization
(Decl
);
630 end Check_Address_Clause
;
632 -----------------------------
633 -- Check_Compile_Time_Size --
634 -----------------------------
636 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
638 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
639 -- Sets the compile time known size (32 bits or less) in the Esize
640 -- field, of T checking for a size clause that was given which attempts
641 -- to give a smaller size, and also checking for an alignment clause.
643 function Size_Known
(T
: Entity_Id
) return Boolean;
644 -- Recursive function that does all the work
646 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
647 -- If T is a constrained subtype, its size is not known if any of its
648 -- discriminant constraints is not static and it is not a null record.
649 -- The test is conservative and doesn't check that the components are
650 -- in fact constrained by non-static discriminant values. Could be made
657 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
662 -- Check for bad size clause given
664 elsif Has_Size_Clause
(T
) then
665 if RM_Size
(T
) < S
then
666 Error_Msg_Uint_1
:= S
;
668 ("size for& too small, minimum allowed is ^",
672 -- Set size if not set already
674 elsif Unknown_RM_Size
(T
) then
683 function Size_Known
(T
: Entity_Id
) return Boolean is
691 if Size_Known_At_Compile_Time
(T
) then
694 -- Always True for scalar types. This is true even for generic formal
695 -- scalar types. We used to return False in the latter case, but the
696 -- size is known at compile time, even in the template, we just do
697 -- not know the exact size but that's not the point of this routine.
699 elsif Is_Scalar_Type
(T
)
700 or else Is_Task_Type
(T
)
706 elsif Is_Array_Type
(T
) then
708 -- String literals always have known size, and we can set it
710 if Ekind
(T
) = E_String_Literal_Subtype
then
711 Set_Small_Size
(T
, Component_Size
(T
)
712 * String_Literal_Length
(T
));
715 -- Unconstrained types never have known at compile time size
717 elsif not Is_Constrained
(T
) then
720 -- Don't do any recursion on type with error posted, since we may
721 -- have a malformed type that leads us into a loop.
723 elsif Error_Posted
(T
) then
726 -- Otherwise if component size unknown, then array size unknown
728 elsif not Size_Known
(Component_Type
(T
)) then
732 -- Check for all indexes static, and also compute possible size
733 -- (in case it is less than 32 and may be packable).
736 Esiz
: Uint
:= Component_Size
(T
);
740 Index
:= First_Index
(T
);
741 while Present
(Index
) loop
742 if Nkind
(Index
) = N_Range
then
743 Get_Index_Bounds
(Index
, Low
, High
);
745 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
749 Low
:= Type_Low_Bound
(Etype
(Index
));
750 High
:= Type_High_Bound
(Etype
(Index
));
753 if not Compile_Time_Known_Value
(Low
)
754 or else not Compile_Time_Known_Value
(High
)
755 or else Etype
(Index
) = Any_Type
760 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
772 Set_Small_Size
(T
, Esiz
);
776 -- Access types always have known at compile time sizes
778 elsif Is_Access_Type
(T
) then
781 -- For non-generic private types, go to underlying type if present
783 elsif Is_Private_Type
(T
)
784 and then not Is_Generic_Type
(T
)
785 and then Present
(Underlying_Type
(T
))
787 -- Don't do any recursion on type with error posted, since we may
788 -- have a malformed type that leads us into a loop.
790 if Error_Posted
(T
) then
793 return Size_Known
(Underlying_Type
(T
));
798 elsif Is_Record_Type
(T
) then
800 -- A class-wide type is never considered to have a known size
802 if Is_Class_Wide_Type
(T
) then
805 -- A subtype of a variant record must not have non-static
806 -- discriminated components.
808 elsif T
/= Base_Type
(T
)
809 and then not Static_Discriminated_Components
(T
)
813 -- Don't do any recursion on type with error posted, since we may
814 -- have a malformed type that leads us into a loop.
816 elsif Error_Posted
(T
) then
820 -- Now look at the components of the record
823 -- The following two variables are used to keep track of the
824 -- size of packed records if we can tell the size of the packed
825 -- record in the front end. Packed_Size_Known is True if so far
826 -- we can figure out the size. It is initialized to True for a
827 -- packed record, unless the record has discriminants or atomic
828 -- components or independent components.
830 -- The reason we eliminate the discriminated case is that
831 -- we don't know the way the back end lays out discriminated
832 -- packed records. If Packed_Size_Known is True, then
833 -- Packed_Size is the size in bits so far.
835 Packed_Size_Known
: Boolean :=
837 and then not Has_Discriminants
(T
)
838 and then not Has_Atomic_Components
(T
)
839 and then not Has_Independent_Components
(T
);
841 Packed_Size
: Uint
:= Uint_0
;
842 -- Size in bits so far
845 -- Test for variant part present
847 if Has_Discriminants
(T
)
848 and then Present
(Parent
(T
))
849 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
850 and then Nkind
(Type_Definition
(Parent
(T
))) =
852 and then not Null_Present
(Type_Definition
(Parent
(T
)))
854 Present
(Variant_Part
855 (Component_List
(Type_Definition
(Parent
(T
)))))
857 -- If variant part is present, and type is unconstrained,
858 -- then we must have defaulted discriminants, or a size
859 -- clause must be present for the type, or else the size
860 -- is definitely not known at compile time.
862 if not Is_Constrained
(T
)
864 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
865 and then Unknown_RM_Size
(T
)
871 -- Loop through components
873 Comp
:= First_Component_Or_Discriminant
(T
);
874 while Present
(Comp
) loop
875 Ctyp
:= Etype
(Comp
);
877 -- We do not know the packed size if there is a component
878 -- clause present (we possibly could, but this would only
879 -- help in the case of a record with partial rep clauses.
880 -- That's because in the case of full rep clauses, the
881 -- size gets figured out anyway by a different circuit).
883 if Present
(Component_Clause
(Comp
)) then
884 Packed_Size_Known
:= False;
887 -- We do not know the packed size if we have a by reference
888 -- type, or an atomic type or an atomic component, or an
889 -- aliased component (because packing does not touch these).
892 or else Is_Atomic
(Comp
)
893 or else Is_By_Reference_Type
(Ctyp
)
894 or else Is_Aliased
(Comp
)
896 Packed_Size_Known
:= False;
899 -- We need to identify a component that is an array where
900 -- the index type is an enumeration type with non-standard
901 -- representation, and some bound of the type depends on a
904 -- This is because gigi computes the size by doing a
905 -- substitution of the appropriate discriminant value in
906 -- the size expression for the base type, and gigi is not
907 -- clever enough to evaluate the resulting expression (which
908 -- involves a call to rep_to_pos) at compile time.
910 -- It would be nice if gigi would either recognize that
911 -- this expression can be computed at compile time, or
912 -- alternatively figured out the size from the subtype
913 -- directly, where all the information is at hand ???
915 if Is_Array_Type
(Etype
(Comp
))
916 and then Present
(Packed_Array_Type
(Etype
(Comp
)))
919 Ocomp
: constant Entity_Id
:=
920 Original_Record_Component
(Comp
);
921 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
927 Ind
:= First_Index
(OCtyp
);
928 while Present
(Ind
) loop
929 Indtyp
:= Etype
(Ind
);
931 if Is_Enumeration_Type
(Indtyp
)
932 and then Has_Non_Standard_Rep
(Indtyp
)
934 Lo
:= Type_Low_Bound
(Indtyp
);
935 Hi
:= Type_High_Bound
(Indtyp
);
937 if Is_Entity_Name
(Lo
)
938 and then Ekind
(Entity
(Lo
)) = E_Discriminant
942 elsif Is_Entity_Name
(Hi
)
943 and then Ekind
(Entity
(Hi
)) = E_Discriminant
954 -- Clearly size of record is not known if the size of one of
955 -- the components is not known.
957 if not Size_Known
(Ctyp
) then
961 -- Accumulate packed size if possible
963 if Packed_Size_Known
then
965 -- We can only deal with elementary types, since for
966 -- non-elementary components, alignment enters into the
967 -- picture, and we don't know enough to handle proper
968 -- alignment in this context. Packed arrays count as
969 -- elementary if the representation is a modular type.
971 if Is_Elementary_Type
(Ctyp
)
972 or else (Is_Array_Type
(Ctyp
)
973 and then Present
(Packed_Array_Type
(Ctyp
))
974 and then Is_Modular_Integer_Type
975 (Packed_Array_Type
(Ctyp
)))
977 -- Packed size unknown if we have an atomic type
978 -- or a by reference type, since the back end
979 -- knows how these are layed out.
982 or else Is_By_Reference_Type
(Ctyp
)
984 Packed_Size_Known
:= False;
986 -- If RM_Size is known and static, then we can keep
987 -- accumulating the packed size
989 elsif Known_Static_RM_Size
(Ctyp
) then
991 -- A little glitch, to be removed sometime ???
992 -- gigi does not understand zero sizes yet.
994 if RM_Size
(Ctyp
) = Uint_0
then
995 Packed_Size_Known
:= False;
997 -- Normal case where we can keep accumulating the
998 -- packed array size.
1001 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1004 -- If we have a field whose RM_Size is not known then
1005 -- we can't figure out the packed size here.
1008 Packed_Size_Known
:= False;
1011 -- If we have a non-elementary type we can't figure out
1012 -- the packed array size (alignment issues).
1015 Packed_Size_Known
:= False;
1019 Next_Component_Or_Discriminant
(Comp
);
1022 if Packed_Size_Known
then
1023 Set_Small_Size
(T
, Packed_Size
);
1029 -- All other cases, size not known at compile time
1036 -------------------------------------
1037 -- Static_Discriminated_Components --
1038 -------------------------------------
1040 function Static_Discriminated_Components
1041 (T
: Entity_Id
) return Boolean
1043 Constraint
: Elmt_Id
;
1046 if Has_Discriminants
(T
)
1047 and then Present
(Discriminant_Constraint
(T
))
1048 and then Present
(First_Component
(T
))
1050 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1051 while Present
(Constraint
) loop
1052 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1056 Next_Elmt
(Constraint
);
1061 end Static_Discriminated_Components
;
1063 -- Start of processing for Check_Compile_Time_Size
1066 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1067 end Check_Compile_Time_Size
;
1069 -----------------------------------
1070 -- Check_Component_Storage_Order --
1071 -----------------------------------
1073 procedure Check_Component_Storage_Order
1074 (Encl_Type
: Entity_Id
;
1078 Comp_Type
: Entity_Id
;
1082 Comp_Byte_Aligned
: Boolean;
1083 -- Set True for the record case, when Comp starts on a byte boundary
1084 -- (in which case it is allowed to have different storage order).
1086 Component_Aliased
: Boolean;
1091 if Present
(Comp
) then
1093 Comp_Type
:= Etype
(Comp
);
1095 if Is_Tag
(Comp
) then
1096 Comp_Byte_Aligned
:= True;
1097 Component_Aliased
:= False;
1100 Comp_Byte_Aligned
:=
1101 Present
(Component_Clause
(Comp
))
1103 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1104 Component_Aliased
:= Is_Aliased
(Comp
);
1110 Err_Node
:= Encl_Type
;
1111 Comp_Type
:= Component_Type
(Encl_Type
);
1113 Comp_Byte_Aligned
:= False;
1114 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1117 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1118 -- the attribute definition clause is attached to the first subtype.
1120 Comp_Type
:= Base_Type
(Comp_Type
);
1121 Comp_ADC
:= Get_Attribute_Definition_Clause
1122 (First_Subtype
(Comp_Type
),
1123 Attribute_Scalar_Storage_Order
);
1125 -- Case of enclosing type not having explicit SSO: component cannot
1129 if Present
(Comp_ADC
) then
1131 ("composite type must have explicit scalar storage order",
1135 -- Case of enclosing type having explicit SSO: check compatible
1136 -- attribute on Comp_Type if composite.
1138 elsif Is_Record_Type
(Comp_Type
) or else Is_Array_Type
(Comp_Type
) then
1139 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1140 if Reverse_Storage_Order
(Encl_Type
)
1142 Reverse_Storage_Order
(Comp_Type
)
1145 ("record extension must have same scalar storage order as "
1146 & "parent", Err_Node
);
1150 Error_Msg_N
("nested composite must have explicit scalar "
1151 & "storage order", Err_Node
);
1153 elsif (Reverse_Storage_Order
(Encl_Type
)
1155 Reverse_Storage_Order
(Comp_Type
))
1156 and then not Comp_Byte_Aligned
1159 ("type of non-byte-aligned component must have same scalar "
1160 & "storage order as enclosing composite", Err_Node
);
1163 -- Enclosing type has explicit SSO, non-composite component must not
1166 elsif Component_Aliased
then
1168 ("aliased component not permitted for type with "
1169 & "explicit Scalar_Storage_Order", Err_Node
);
1171 end Check_Component_Storage_Order
;
1173 -----------------------------
1174 -- Check_Debug_Info_Needed --
1175 -----------------------------
1177 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1179 if Debug_Info_Off
(T
) then
1182 elsif Comes_From_Source
(T
)
1183 or else Debug_Generated_Code
1184 or else Debug_Flag_VV
1185 or else Needs_Debug_Info
(T
)
1187 Set_Debug_Info_Needed
(T
);
1189 end Check_Debug_Info_Needed
;
1191 ----------------------------
1192 -- Check_Strict_Alignment --
1193 ----------------------------
1195 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1199 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1200 Set_Strict_Alignment
(E
);
1202 elsif Is_Array_Type
(E
) then
1203 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1205 elsif Is_Record_Type
(E
) then
1206 if Is_Limited_Record
(E
) then
1207 Set_Strict_Alignment
(E
);
1211 Comp
:= First_Component
(E
);
1212 while Present
(Comp
) loop
1213 if not Is_Type
(Comp
)
1214 and then (Strict_Alignment
(Etype
(Comp
))
1215 or else Is_Aliased
(Comp
))
1217 Set_Strict_Alignment
(E
);
1221 Next_Component
(Comp
);
1224 end Check_Strict_Alignment
;
1226 -------------------------
1227 -- Check_Unsigned_Type --
1228 -------------------------
1230 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1231 Ancestor
: Entity_Id
;
1236 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1240 -- Do not attempt to analyze case where range was in error
1242 if No
(Scalar_Range
(E
))
1243 or else Error_Posted
(Scalar_Range
(E
))
1248 -- The situation that is non trivial is something like
1250 -- subtype x1 is integer range -10 .. +10;
1251 -- subtype x2 is x1 range 0 .. V1;
1252 -- subtype x3 is x2 range V2 .. V3;
1253 -- subtype x4 is x3 range V4 .. V5;
1255 -- where Vn are variables. Here the base type is signed, but we still
1256 -- know that x4 is unsigned because of the lower bound of x2.
1258 -- The only way to deal with this is to look up the ancestor chain
1262 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1266 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1268 if Compile_Time_Known_Value
(Lo_Bound
) then
1270 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1271 Set_Is_Unsigned_Type
(E
, True);
1277 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1279 -- If no ancestor had a static lower bound, go to base type
1281 if No
(Ancestor
) then
1283 -- Note: the reason we still check for a compile time known
1284 -- value for the base type is that at least in the case of
1285 -- generic formals, we can have bounds that fail this test,
1286 -- and there may be other cases in error situations.
1288 Btyp
:= Base_Type
(E
);
1290 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1294 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1296 if Compile_Time_Known_Value
(Lo_Bound
)
1297 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1299 Set_Is_Unsigned_Type
(E
, True);
1306 end Check_Unsigned_Type
;
1308 -------------------------
1309 -- Is_Atomic_Aggregate --
1310 -------------------------
1312 function Is_Atomic_Aggregate
1314 Typ
: Entity_Id
) return Boolean
1316 Loc
: constant Source_Ptr
:= Sloc
(E
);
1324 -- Array may be qualified, so find outer context
1326 if Nkind
(Par
) = N_Qualified_Expression
then
1327 Par
:= Parent
(Par
);
1330 if Nkind_In
(Par
, N_Object_Declaration
, N_Assignment_Statement
)
1331 and then Comes_From_Source
(Par
)
1333 Temp
:= Make_Temporary
(Loc
, 'T', E
);
1335 Make_Object_Declaration
(Loc
,
1336 Defining_Identifier
=> Temp
,
1337 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1338 Expression
=> Relocate_Node
(E
));
1339 Insert_Before
(Par
, New_N
);
1342 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1348 end Is_Atomic_Aggregate
;
1354 -- Note: the easy coding for this procedure would be to just build a
1355 -- single list of freeze nodes and then insert them and analyze them
1356 -- all at once. This won't work, because the analysis of earlier freeze
1357 -- nodes may recursively freeze types which would otherwise appear later
1358 -- on in the freeze list. So we must analyze and expand the freeze nodes
1359 -- as they are generated.
1361 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1365 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1366 -- This is the internal recursive routine that does freezing of entities
1367 -- (but NOT the analysis of default expressions, which should not be
1368 -- recursive, we don't want to analyze those till we are sure that ALL
1369 -- the types are frozen).
1371 --------------------
1372 -- Freeze_All_Ent --
1373 --------------------
1375 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1380 procedure Process_Flist
;
1381 -- If freeze nodes are present, insert and analyze, and reset cursor
1382 -- for next insertion.
1388 procedure Process_Flist
is
1390 if Is_Non_Empty_List
(Flist
) then
1391 Lastn
:= Next
(After
);
1392 Insert_List_After_And_Analyze
(After
, Flist
);
1394 if Present
(Lastn
) then
1395 After
:= Prev
(Lastn
);
1397 After
:= Last
(List_Containing
(After
));
1402 -- Start or processing for Freeze_All_Ent
1406 while Present
(E
) loop
1408 -- If the entity is an inner package which is not a package
1409 -- renaming, then its entities must be frozen at this point. Note
1410 -- that such entities do NOT get frozen at the end of the nested
1411 -- package itself (only library packages freeze).
1413 -- Same is true for task declarations, where anonymous records
1414 -- created for entry parameters must be frozen.
1416 if Ekind
(E
) = E_Package
1417 and then No
(Renamed_Object
(E
))
1418 and then not Is_Child_Unit
(E
)
1419 and then not Is_Frozen
(E
)
1422 Install_Visible_Declarations
(E
);
1423 Install_Private_Declarations
(E
);
1425 Freeze_All
(First_Entity
(E
), After
);
1427 End_Package_Scope
(E
);
1429 if Is_Generic_Instance
(E
)
1430 and then Has_Delayed_Freeze
(E
)
1432 Set_Has_Delayed_Freeze
(E
, False);
1433 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1436 elsif Ekind
(E
) in Task_Kind
1438 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
1440 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
1443 Freeze_All
(First_Entity
(E
), After
);
1446 -- For a derived tagged type, we must ensure that all the
1447 -- primitive operations of the parent have been frozen, so that
1448 -- their addresses will be in the parent's dispatch table at the
1449 -- point it is inherited.
1451 elsif Ekind
(E
) = E_Record_Type
1452 and then Is_Tagged_Type
(E
)
1453 and then Is_Tagged_Type
(Etype
(E
))
1454 and then Is_Derived_Type
(E
)
1457 Prim_List
: constant Elist_Id
:=
1458 Primitive_Operations
(Etype
(E
));
1464 Prim
:= First_Elmt
(Prim_List
);
1465 while Present
(Prim
) loop
1466 Subp
:= Node
(Prim
);
1468 if Comes_From_Source
(Subp
)
1469 and then not Is_Frozen
(Subp
)
1471 Flist
:= Freeze_Entity
(Subp
, After
);
1480 if not Is_Frozen
(E
) then
1481 Flist
:= Freeze_Entity
(E
, After
);
1484 -- If already frozen, and there are delayed aspects, this is where
1485 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1486 -- for a description of how we handle aspect visibility).
1488 elsif Has_Delayed_Aspects
(E
) then
1490 -- Retrieve the visibility to the discriminants in order to
1491 -- analyze properly the aspects.
1493 Push_Scope_And_Install_Discriminants
(E
);
1499 Ritem
:= First_Rep_Item
(E
);
1500 while Present
(Ritem
) loop
1501 if Nkind
(Ritem
) = N_Aspect_Specification
1502 and then Entity
(Ritem
) = E
1503 and then Is_Delayed_Aspect
(Ritem
)
1505 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1508 Ritem
:= Next_Rep_Item
(Ritem
);
1512 Uninstall_Discriminants_And_Pop_Scope
(E
);
1515 -- If an incomplete type is still not frozen, this may be a
1516 -- premature freezing because of a body declaration that follows.
1517 -- Indicate where the freezing took place. Freezing will happen
1518 -- if the body comes from source, but not if it is internally
1519 -- generated, for example as the body of a type invariant.
1521 -- If the freezing is caused by the end of the current declarative
1522 -- part, it is a Taft Amendment type, and there is no error.
1524 if not Is_Frozen
(E
)
1525 and then Ekind
(E
) = E_Incomplete_Type
1528 Bod
: constant Node_Id
:= Next
(After
);
1531 -- The presence of a body freezes all entities previously
1532 -- declared in the current list of declarations, but this
1533 -- does not apply if the body does not come from source.
1534 -- A type invariant is transformed into a subprogram body
1535 -- which is placed at the end of the private part of the
1536 -- current package, but this body does not freeze incomplete
1537 -- types that may be declared in this private part.
1539 if (Nkind_In
(Bod
, N_Subprogram_Body
,
1544 or else Nkind
(Bod
) in N_Body_Stub
)
1546 List_Containing
(After
) = List_Containing
(Parent
(E
))
1547 and then Comes_From_Source
(Bod
)
1549 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1551 ("type& is frozen# before its full declaration",
1561 -- Start of processing for Freeze_All
1564 Freeze_All_Ent
(From
, After
);
1566 -- Now that all types are frozen, we can deal with default expressions
1567 -- that require us to build a default expression functions. This is the
1568 -- point at which such functions are constructed (after all types that
1569 -- might be used in such expressions have been frozen).
1571 -- For subprograms that are renaming_as_body, we create the wrapper
1572 -- bodies as needed.
1574 -- We also add finalization chains to access types whose designated
1575 -- types are controlled. This is normally done when freezing the type,
1576 -- but this misses recursive type definitions where the later members
1577 -- of the recursion introduce controlled components.
1579 -- Loop through entities
1582 while Present
(E
) loop
1583 if Is_Subprogram
(E
) then
1585 if not Default_Expressions_Processed
(E
) then
1586 Process_Default_Expressions
(E
, After
);
1589 if not Has_Completion
(E
) then
1590 Decl
:= Unit_Declaration_Node
(E
);
1592 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1593 if Error_Posted
(Decl
) then
1594 Set_Has_Completion
(E
);
1596 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1599 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1600 and then Present
(Corresponding_Body
(Decl
))
1602 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1603 = N_Subprogram_Renaming_Declaration
1605 Build_And_Analyze_Renamed_Body
1606 (Decl
, Corresponding_Body
(Decl
), After
);
1610 elsif Ekind
(E
) in Task_Kind
1612 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
1614 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
1620 Ent
:= First_Entity
(E
);
1621 while Present
(Ent
) loop
1623 and then not Default_Expressions_Processed
(Ent
)
1625 Process_Default_Expressions
(Ent
, After
);
1632 -- We add finalization masters to access types whose designated types
1633 -- require finalization. This is normally done when freezing the
1634 -- type, but this misses recursive type definitions where the later
1635 -- members of the recursion introduce controlled components (such as
1636 -- can happen when incomplete types are involved), as well cases
1637 -- where a component type is private and the controlled full type
1638 -- occurs after the access type is frozen. Cases that don't need a
1639 -- finalization master are generic formal types (the actual type will
1640 -- have it) and types with Java and CIL conventions, since those are
1641 -- used for API bindings. (Are there any other cases that should be
1642 -- excluded here???)
1644 elsif Is_Access_Type
(E
)
1645 and then Comes_From_Source
(E
)
1646 and then not Is_Generic_Type
(E
)
1647 and then Needs_Finalization
(Designated_Type
(E
))
1649 Build_Finalization_Master
(E
);
1656 -----------------------
1657 -- Freeze_And_Append --
1658 -----------------------
1660 procedure Freeze_And_Append
1663 Result
: in out List_Id
)
1665 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1667 if Is_Non_Empty_List
(L
) then
1668 if Result
= No_List
then
1671 Append_List
(L
, Result
);
1674 end Freeze_And_Append
;
1680 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1681 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, N
);
1683 if Is_Non_Empty_List
(Freeze_Nodes
) then
1684 Insert_Actions
(N
, Freeze_Nodes
);
1692 function Freeze_Entity
(E
: Entity_Id
; N
: Node_Id
) return List_Id
is
1693 Loc
: constant Source_Ptr
:= Sloc
(N
);
1694 Test_E
: Entity_Id
:= E
;
1701 Result
: List_Id
:= No_List
;
1702 -- List of freezing actions, left at No_List if none
1704 Has_Default_Initialization
: Boolean := False;
1705 -- This flag gets set to true for a variable with default initialization
1707 procedure Add_To_Result
(N
: Node_Id
);
1708 -- N is a freezing action to be appended to the Result
1710 function After_Last_Declaration
return Boolean;
1711 -- If Loc is a freeze_entity that appears after the last declaration
1712 -- in the scope, inhibit error messages on late completion.
1714 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1715 -- Check that an Access or Unchecked_Access attribute with a prefix
1716 -- which is the current instance type can only be applied when the type
1719 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1720 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1721 -- integer literal without an explicit corresponding size clause. The
1722 -- caller has checked that Utype is a modular integer type.
1724 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
1725 -- Freeze array type, including freezing index and component types
1727 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
1728 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1729 -- package. Recurse on inner generic packages.
1731 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1732 -- Freeze record type, including freezing component types, and freezing
1733 -- primitive operations if this is a tagged type.
1739 procedure Add_To_Result
(N
: Node_Id
) is
1742 Result
:= New_List
(N
);
1748 ----------------------------
1749 -- After_Last_Declaration --
1750 ----------------------------
1752 function After_Last_Declaration
return Boolean is
1753 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
1755 if Nkind
(Spec
) = N_Package_Specification
then
1756 if Present
(Private_Declarations
(Spec
)) then
1757 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1758 elsif Present
(Visible_Declarations
(Spec
)) then
1759 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1766 end After_Last_Declaration
;
1768 ----------------------------
1769 -- Check_Current_Instance --
1770 ----------------------------
1772 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1774 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
1775 -- Determine whether Typ is compatible with the rules for aliased
1776 -- views of types as defined in RM 3.10 in the various dialects.
1778 function Process
(N
: Node_Id
) return Traverse_Result
;
1779 -- Process routine to apply check to given node
1781 -----------------------------
1782 -- Is_Aliased_View_Of_Type --
1783 -----------------------------
1785 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
1786 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
1791 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
1792 and then Limited_Present
(Type_Definition
(Typ_Decl
))
1796 -- The following paragraphs describe what a legal aliased view of
1797 -- a type is in the various dialects of Ada.
1801 -- The current instance of a limited type, and a formal parameter
1802 -- or generic formal object of a tagged type.
1804 -- Ada 95 limited type
1805 -- * Type with reserved word "limited"
1806 -- * A protected or task type
1807 -- * A composite type with limited component
1809 elsif Ada_Version
<= Ada_95
then
1810 return Is_Limited_Type
(Typ
);
1814 -- The current instance of a limited tagged type, a protected
1815 -- type, a task type, or a type that has the reserved word
1816 -- "limited" in its full definition ... a formal parameter or
1817 -- generic formal object of a tagged type.
1819 -- Ada 2005 limited type
1820 -- * Type with reserved word "limited", "synchronized", "task"
1822 -- * A composite type with limited component
1823 -- * A derived type whose parent is a non-interface limited type
1825 elsif Ada_Version
= Ada_2005
then
1827 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
1829 (Is_Derived_Type
(Typ
)
1830 and then not Is_Interface
(Etype
(Typ
))
1831 and then Is_Limited_Type
(Etype
(Typ
)));
1833 -- Ada 2012 and beyond
1835 -- The current instance of an immutably limited type ... a formal
1836 -- parameter or generic formal object of a tagged type.
1838 -- Ada 2012 limited type
1839 -- * Type with reserved word "limited", "synchronized", "task"
1841 -- * A composite type with limited component
1842 -- * A derived type whose parent is a non-interface limited type
1843 -- * An incomplete view
1845 -- Ada 2012 immutably limited type
1846 -- * Explicitly limited record type
1847 -- * Record extension with "limited" present
1848 -- * Non-formal limited private type that is either tagged
1849 -- or has at least one access discriminant with a default
1851 -- * Task type, protected type or synchronized interface
1852 -- * Type derived from immutably limited type
1856 Is_Immutably_Limited_Type
(Typ
)
1857 or else Is_Incomplete_Type
(Typ
);
1859 end Is_Aliased_View_Of_Type
;
1865 function Process
(N
: Node_Id
) return Traverse_Result
is
1868 when N_Attribute_Reference
=>
1869 if Nam_In
(Attribute_Name
(N
), Name_Access
,
1870 Name_Unchecked_Access
)
1871 and then Is_Entity_Name
(Prefix
(N
))
1872 and then Is_Type
(Entity
(Prefix
(N
)))
1873 and then Entity
(Prefix
(N
)) = E
1875 if Ada_Version
< Ada_2012
then
1877 ("current instance must be a limited type",
1881 ("current instance must be an immutably limited " &
1882 "type (RM-2012, 7.5 (8.1/3))",
1890 when others => return OK
;
1894 procedure Traverse
is new Traverse_Proc
(Process
);
1898 Rec_Type
: constant Entity_Id
:=
1899 Scope
(Defining_Identifier
(Comp_Decl
));
1901 -- Start of processing for Check_Current_Instance
1904 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
1905 Traverse
(Comp_Decl
);
1907 end Check_Current_Instance
;
1909 ------------------------------
1910 -- Check_Suspicious_Modulus --
1911 ------------------------------
1913 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
1914 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
1917 if not Warn_On_Suspicious_Modulus_Value
then
1921 if Nkind
(Decl
) = N_Full_Type_Declaration
then
1923 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
1926 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
1928 Modulus
: constant Node_Id
:=
1929 Original_Node
(Expression
(Tdef
));
1932 if Nkind
(Modulus
) = N_Integer_Literal
then
1934 Modv
: constant Uint
:= Intval
(Modulus
);
1935 Sizv
: constant Uint
:= RM_Size
(Utype
);
1938 -- First case, modulus and size are the same. This
1939 -- happens if you have something like mod 32, with
1940 -- an explicit size of 32, this is for sure a case
1941 -- where the warning is given, since it is seems
1942 -- very unlikely that someone would want e.g. a
1943 -- five bit type stored in 32 bits. It is much
1944 -- more likely they wanted a 32-bit type.
1949 -- Second case, the modulus is 32 or 64 and no
1950 -- size clause is present. This is a less clear
1951 -- case for giving the warning, but in the case
1952 -- of 32/64 (5-bit or 6-bit types) these seem rare
1953 -- enough that it is a likely error (and in any
1954 -- case using 2**5 or 2**6 in these cases seems
1955 -- clearer. We don't include 8 or 16 here, simply
1956 -- because in practice 3-bit and 4-bit types are
1957 -- more common and too many false positives if
1958 -- we warn in these cases.
1960 elsif not Has_Size_Clause
(Utype
)
1961 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
1965 -- No warning needed
1971 -- If we fall through, give warning
1973 Error_Msg_Uint_1
:= Modv
;
1975 ("?M?2 '*'*^' may have been intended here",
1983 end Check_Suspicious_Modulus
;
1985 -----------------------
1986 -- Freeze_Array_Type --
1987 -----------------------
1989 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
1990 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
1991 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
1994 Non_Standard_Enum
: Boolean := False;
1995 -- Set true if any of the index types is an enumeration type with a
1996 -- non-standard representation.
1999 Freeze_And_Append
(Ctyp
, N
, Result
);
2001 Indx
:= First_Index
(Arr
);
2002 while Present
(Indx
) loop
2003 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2005 if Is_Enumeration_Type
(Etype
(Indx
))
2006 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2008 Non_Standard_Enum
:= True;
2014 -- Processing that is done only for base types
2016 if Ekind
(Arr
) = E_Array_Type
then
2018 -- Propagate flags for component type
2020 if Is_Controlled
(Component_Type
(Arr
))
2021 or else Has_Controlled_Component
(Ctyp
)
2023 Set_Has_Controlled_Component
(Arr
);
2026 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2027 Set_Has_Unchecked_Union
(Arr
);
2030 -- Warn for pragma Pack overriding foreign convention
2032 if Has_Foreign_Convention
(Ctyp
)
2033 and then Has_Pragma_Pack
(Arr
)
2036 CN
: constant Name_Id
:=
2037 Get_Convention_Name
(Convention
(Ctyp
));
2038 PP
: constant Node_Id
:=
2039 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2041 if Present
(PP
) then
2042 Error_Msg_Name_1
:= CN
;
2043 Error_Msg_Sloc
:= Sloc
(Arr
);
2045 ("pragma Pack affects convention % components #??",
2047 Error_Msg_Name_1
:= CN
;
2049 ("\array components may not have % compatible "
2050 & "representation??", PP
);
2055 -- If packing was requested or if the component size was
2056 -- set explicitly, then see if bit packing is required. This
2057 -- processing is only done for base types, since all of the
2058 -- representation aspects involved are type-related. This is not
2059 -- just an optimization, if we start processing the subtypes, they
2060 -- interfere with the settings on the base type (this is because
2061 -- Is_Packed has a slightly different meaning before and after
2069 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2070 and then Known_Static_RM_Size
(Ctyp
)
2071 and then not Has_Component_Size_Clause
(Arr
)
2073 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2075 elsif Known_Component_Size
(Arr
) then
2076 Csiz
:= Component_Size
(Arr
);
2078 elsif not Known_Static_Esize
(Ctyp
) then
2082 Esiz
:= Esize
(Ctyp
);
2084 -- We can set the component size if it is less than 16,
2085 -- rounding it up to the next storage unit size.
2089 elsif Esiz
<= 16 then
2095 -- Set component size up to match alignment if it would
2096 -- otherwise be less than the alignment. This deals with
2097 -- cases of types whose alignment exceeds their size (the
2098 -- padded type cases).
2102 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2111 -- Case of component size that may result in packing
2113 if 1 <= Csiz
and then Csiz
<= 64 then
2115 Ent
: constant Entity_Id
:=
2116 First_Subtype
(Arr
);
2117 Pack_Pragma
: constant Node_Id
:=
2118 Get_Rep_Pragma
(Ent
, Name_Pack
);
2119 Comp_Size_C
: constant Node_Id
:=
2120 Get_Attribute_Definition_Clause
2121 (Ent
, Attribute_Component_Size
);
2123 -- Warn if we have pack and component size so that the
2126 -- Note: here we must check for the presence of a
2127 -- component size before checking for a Pack pragma to
2128 -- deal with the case where the array type is a derived
2129 -- type whose parent is currently private.
2131 if Present
(Comp_Size_C
)
2132 and then Has_Pragma_Pack
(Ent
)
2133 and then Warn_On_Redundant_Constructs
2135 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2137 ("?r?pragma Pack for& ignored!",
2140 ("\?r?explicit component size given#!",
2142 Set_Is_Packed
(Base_Type
(Ent
), False);
2143 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2146 -- Set component size if not already set by a component
2149 if not Present
(Comp_Size_C
) then
2150 Set_Component_Size
(Arr
, Csiz
);
2153 -- Check for base type of 8, 16, 32 bits, where an
2154 -- unsigned subtype has a length one less than the
2155 -- base type (e.g. Natural subtype of Integer).
2157 -- In such cases, if a component size was not set
2158 -- explicitly, then generate a warning.
2160 if Has_Pragma_Pack
(Arr
)
2161 and then not Present
(Comp_Size_C
)
2163 (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2164 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2166 Error_Msg_Uint_1
:= Csiz
;
2168 if Present
(Pack_Pragma
) then
2170 ("??pragma Pack causes component size "
2171 & "to be ^!", Pack_Pragma
);
2173 ("\??use Component_Size to set "
2174 & "desired value!", Pack_Pragma
);
2178 -- Actual packing is not needed for 8, 16, 32, 64. Also
2179 -- not needed for 24 if alignment is 1.
2185 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
2187 -- Here the array was requested to be packed, but
2188 -- the packing request had no effect, so Is_Packed
2191 -- Note: semantically this means that we lose track
2192 -- of the fact that a derived type inherited a pragma
2193 -- Pack that was non- effective, but that seems fine.
2195 -- We regard a Pack pragma as a request to set a
2196 -- representation characteristic, and this request
2199 Set_Is_Packed
(Base_Type
(Arr
), False);
2200 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2202 if Known_Static_Esize
(Component_Type
(Arr
))
2203 and then Esize
(Component_Type
(Arr
)) = Csiz
2205 Set_Has_Non_Standard_Rep
2206 (Base_Type
(Arr
), False);
2209 -- In all other cases, packing is indeed needed
2212 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2213 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2214 Set_Is_Packed
(Base_Type
(Arr
), True);
2220 -- Check for Atomic_Components or Aliased with unsuitable packing
2221 -- or explicit component size clause given.
2223 if (Has_Atomic_Components
(Arr
)
2224 or else Has_Aliased_Components
(Arr
))
2225 and then (Has_Component_Size_Clause
(Arr
)
2226 or else Is_Packed
(Arr
))
2228 Alias_Atomic_Check
: declare
2230 procedure Complain_CS
(T
: String);
2231 -- Outputs error messages for incorrect CS clause or pragma
2232 -- Pack for aliased or atomic components (T is "aliased" or
2239 procedure Complain_CS
(T
: String) is
2241 if Has_Component_Size_Clause
(Arr
) then
2243 Get_Attribute_Definition_Clause
2244 (FS
, Attribute_Component_Size
);
2246 if Known_Static_Esize
(Ctyp
) then
2248 ("incorrect component size for "
2249 & T
& " components", Clause
);
2250 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2252 ("\only allowed value is^", Clause
);
2256 ("component size cannot be given for "
2257 & T
& " components", Clause
);
2262 ("cannot pack " & T
& " components",
2263 Get_Rep_Pragma
(FS
, Name_Pack
));
2269 -- Start of processing for Alias_Atomic_Check
2273 -- If object size of component type isn't known, we cannot
2274 -- be sure so we defer to the back end.
2276 if not Known_Static_Esize
(Ctyp
) then
2279 -- Case where component size has no effect. First check for
2280 -- object size of component type multiple of the storage
2283 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2285 -- OK in both packing case and component size case if RM
2286 -- size is known and static and same as the object size.
2289 ((Known_Static_RM_Size
(Ctyp
)
2290 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2292 -- Or if we have an explicit component size clause and
2293 -- the component size and object size are equal.
2296 (Has_Component_Size_Clause
(Arr
)
2297 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2301 elsif Has_Aliased_Components
(Arr
)
2302 or else Is_Aliased
(Ctyp
)
2304 Complain_CS
("aliased");
2306 elsif Has_Atomic_Components
(Arr
)
2307 or else Is_Atomic
(Ctyp
)
2309 Complain_CS
("atomic");
2311 end Alias_Atomic_Check
;
2314 -- Warn for case of atomic type
2316 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2319 and then not Addressable
(Component_Size
(FS
))
2322 ("non-atomic components of type& may not be "
2323 & "accessible by separate tasks??", Clause
, Arr
);
2325 if Has_Component_Size_Clause
(Arr
) then
2328 (Get_Attribute_Definition_Clause
2329 (FS
, Attribute_Component_Size
));
2331 ("\because of component size clause#??",
2334 elsif Has_Pragma_Pack
(Arr
) then
2336 Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2338 ("\because of pragma Pack#??", Clause
);
2342 -- Check for scalar storage order
2344 Check_Component_Storage_Order
2347 ADC
=> Get_Attribute_Definition_Clause
2348 (First_Subtype
(Arr
),
2349 Attribute_Scalar_Storage_Order
));
2351 -- Processing that is done only for subtypes
2354 -- Acquire alignment from base type
2356 if Unknown_Alignment
(Arr
) then
2357 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2358 Adjust_Esize_Alignment
(Arr
);
2362 -- Specific checks for bit-packed arrays
2364 if Is_Bit_Packed_Array
(Arr
) then
2366 -- Check number of elements for bit packed arrays that come from
2367 -- source and have compile time known ranges. The bit-packed
2368 -- arrays circuitry does not support arrays with more than
2369 -- Integer'Last + 1 elements, and when this restriction is
2370 -- violated, causes incorrect data access.
2372 -- For the case where this is not compile time known, a run-time
2373 -- check should be generated???
2375 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
2384 Index
:= First_Index
(Arr
);
2385 while Present
(Index
) loop
2386 Ityp
:= Etype
(Index
);
2388 -- Never generate an error if any index is of a generic
2389 -- type. We will check this in instances.
2391 if Is_Generic_Type
(Ityp
) then
2397 Make_Attribute_Reference
(Loc
,
2399 New_Occurrence_Of
(Ityp
, Loc
),
2400 Attribute_Name
=> Name_Range_Length
);
2401 Analyze_And_Resolve
(Ilen
);
2403 -- No attempt is made to check number of elements
2404 -- if not compile time known.
2406 if Nkind
(Ilen
) /= N_Integer_Literal
then
2411 Elmts
:= Elmts
* Intval
(Ilen
);
2415 if Elmts
> Intval
(High_Bound
2417 (Standard_Integer
))) + 1
2420 ("bit packed array type may not have "
2421 & "more than Integer''Last+1 elements", Arr
);
2428 if Known_RM_Size
(Arr
) then
2430 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
2433 pragma Warnings
(Off
, Discard
);
2436 -- It is not clear if it is possible to have no size clause
2437 -- at this stage, but it is not worth worrying about. Post
2438 -- error on the entity name in the size clause if present,
2439 -- else on the type entity itself.
2441 if Present
(SizC
) then
2442 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
2444 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
2450 -- If any of the index types was an enumeration type with a
2451 -- non-standard rep clause, then we indicate that the array type
2452 -- is always packed (even if it is not bit packed).
2454 if Non_Standard_Enum
then
2455 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
2456 Set_Is_Packed
(Base_Type
(Arr
));
2459 Set_Component_Alignment_If_Not_Set
(Arr
);
2461 -- If the array is packed, we must create the packed array type to be
2462 -- used to actually implement the type. This is only needed for real
2463 -- array types (not for string literal types, since they are present
2464 -- only for the front end).
2467 and then Ekind
(Arr
) /= E_String_Literal_Subtype
2469 Create_Packed_Array_Type
(Arr
);
2470 Freeze_And_Append
(Packed_Array_Type
(Arr
), N
, Result
);
2472 -- Size information of packed array type is copied to the array
2473 -- type, since this is really the representation. But do not
2474 -- override explicit existing size values. If the ancestor subtype
2475 -- is constrained the packed_array_type will be inherited from it,
2476 -- but the size may have been provided already, and must not be
2477 -- overridden either.
2479 if not Has_Size_Clause
(Arr
)
2481 (No
(Ancestor_Subtype
(Arr
))
2482 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
2484 Set_Esize
(Arr
, Esize
(Packed_Array_Type
(Arr
)));
2485 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Type
(Arr
)));
2488 if not Has_Alignment_Clause
(Arr
) then
2489 Set_Alignment
(Arr
, Alignment
(Packed_Array_Type
(Arr
)));
2493 -- For non-packed arrays set the alignment of the array to the
2494 -- alignment of the component type if it is unknown. Skip this
2495 -- in atomic case (atomic arrays may need larger alignments).
2497 if not Is_Packed
(Arr
)
2498 and then Unknown_Alignment
(Arr
)
2499 and then Known_Alignment
(Ctyp
)
2500 and then Known_Static_Component_Size
(Arr
)
2501 and then Known_Static_Esize
(Ctyp
)
2502 and then Esize
(Ctyp
) = Component_Size
(Arr
)
2503 and then not Is_Atomic
(Arr
)
2505 Set_Alignment
(Arr
, Alignment
(Component_Type
(Arr
)));
2507 end Freeze_Array_Type
;
2509 -----------------------------
2510 -- Freeze_Generic_Entities --
2511 -----------------------------
2513 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
2520 E
:= First_Entity
(Pack
);
2521 while Present
(E
) loop
2522 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
2523 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
2525 Append_To
(Flist
, F
);
2527 elsif Ekind
(E
) = E_Generic_Package
then
2528 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
2535 end Freeze_Generic_Entities
;
2537 ------------------------
2538 -- Freeze_Record_Type --
2539 ------------------------
2541 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
2548 pragma Warnings
(Off
, Junk
);
2550 Rec_Pushed
: Boolean := False;
2551 -- Set True if the record type scope Rec has been pushed on the scope
2552 -- stack. Needed for the analysis of delayed aspects specified to the
2553 -- components of Rec.
2555 Unplaced_Component
: Boolean := False;
2556 -- Set True if we find at least one component with no component
2557 -- clause (used to warn about useless Pack pragmas).
2559 Placed_Component
: Boolean := False;
2560 -- Set True if we find at least one component with a component
2561 -- clause (used to warn about useless Bit_Order pragmas, and also
2562 -- to detect cases where Implicit_Packing may have an effect).
2564 Aliased_Component
: Boolean := False;
2565 -- Set True if we find at least one component which is aliased. This
2566 -- is used to prevent Implicit_Packing of the record, since packing
2567 -- cannot modify the size of alignment of an aliased component.
2569 All_Scalar_Components
: Boolean := True;
2570 -- Set False if we encounter a component of a non-scalar type
2572 Scalar_Component_Total_RM_Size
: Uint
:= Uint_0
;
2573 Scalar_Component_Total_Esize
: Uint
:= Uint_0
;
2574 -- Accumulates total RM_Size values and total Esize values of all
2575 -- scalar components. Used for processing of Implicit_Packing.
2577 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
2578 -- If N is an allocator, possibly wrapped in one or more level of
2579 -- qualified expression(s), return the inner allocator node, else
2582 procedure Check_Itype
(Typ
: Entity_Id
);
2583 -- If the component subtype is an access to a constrained subtype of
2584 -- an already frozen type, make the subtype frozen as well. It might
2585 -- otherwise be frozen in the wrong scope, and a freeze node on
2586 -- subtype has no effect. Similarly, if the component subtype is a
2587 -- regular (not protected) access to subprogram, set the anonymous
2588 -- subprogram type to frozen as well, to prevent an out-of-scope
2589 -- freeze node at some eventual point of call. Protected operations
2590 -- are handled elsewhere.
2592 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
2593 -- Make sure that all types mentioned in Discrete_Choices of the
2594 -- variants referenceed by the Variant_Part VP are frozen. This is
2595 -- a recursive routine to deal with nested variants.
2597 ---------------------
2598 -- Check_Allocator --
2599 ---------------------
2601 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
2606 if Nkind
(Inner
) = N_Allocator
then
2608 elsif Nkind
(Inner
) = N_Qualified_Expression
then
2609 Inner
:= Expression
(Inner
);
2614 end Check_Allocator
;
2620 procedure Check_Itype
(Typ
: Entity_Id
) is
2621 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
2624 if not Is_Frozen
(Desig
)
2625 and then Is_Frozen
(Base_Type
(Desig
))
2627 Set_Is_Frozen
(Desig
);
2629 -- In addition, add an Itype_Reference to ensure that the
2630 -- access subtype is elaborated early enough. This cannot be
2631 -- done if the subtype may depend on discriminants.
2633 if Ekind
(Comp
) = E_Component
2634 and then Is_Itype
(Etype
(Comp
))
2635 and then not Has_Discriminants
(Rec
)
2637 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
2638 Set_Itype
(IR
, Desig
);
2642 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
2643 and then Convention
(Desig
) /= Convention_Protected
2645 Set_Is_Frozen
(Desig
);
2649 ------------------------------------
2650 -- Freeze_Choices_In_Variant_Part --
2651 ------------------------------------
2653 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
2654 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
2661 -- Loop through variants
2663 Variant
:= First_Non_Pragma
(Variants
(VP
));
2664 while Present
(Variant
) loop
2666 -- Loop through choices, checking that all types are frozen
2668 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
2669 while Present
(Choice
) loop
2670 if Nkind
(Choice
) in N_Has_Etype
2671 and then Present
(Etype
(Choice
))
2673 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
2676 Next_Non_Pragma
(Choice
);
2679 -- Check for nested variant part to process
2681 CL
:= Component_List
(Variant
);
2683 if not Null_Present
(CL
) then
2684 if Present
(Variant_Part
(CL
)) then
2685 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
2689 Next_Non_Pragma
(Variant
);
2691 end Freeze_Choices_In_Variant_Part
;
2693 -- Start of processing for Freeze_Record_Type
2696 -- Deal with delayed aspect specifications for components. The
2697 -- analysis of the aspect is required to be delayed to the freeze
2698 -- point, thus we analyze the pragma or attribute definition
2699 -- clause in the tree at this point. We also analyze the aspect
2700 -- specification node at the freeze point when the aspect doesn't
2701 -- correspond to pragma/attribute definition clause.
2703 Comp
:= First_Entity
(Rec
);
2704 while Present
(Comp
) loop
2705 if Ekind
(Comp
) = E_Component
2706 and then Has_Delayed_Aspects
(Comp
)
2708 if not Rec_Pushed
then
2712 -- The visibility to the discriminants must be restored in
2713 -- order to properly analyze the aspects.
2715 if Has_Discriminants
(Rec
) then
2716 Install_Discriminants
(Rec
);
2720 Analyze_Aspects_At_Freeze_Point
(Comp
);
2726 -- Pop the scope if Rec scope has been pushed on the scope stack
2727 -- during the delayed aspect analysis process.
2730 if Has_Discriminants
(Rec
) then
2731 Uninstall_Discriminants
(Rec
);
2737 -- Freeze components and embedded subtypes
2739 Comp
:= First_Entity
(Rec
);
2741 while Present
(Comp
) loop
2742 if Is_Aliased
(Comp
) then
2743 Aliased_Component
:= True;
2746 -- Handle the component and discriminant case
2748 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
2750 CC
: constant Node_Id
:= Component_Clause
(Comp
);
2753 -- Freezing a record type freezes the type of each of its
2754 -- components. However, if the type of the component is
2755 -- part of this record, we do not want or need a separate
2756 -- Freeze_Node. Note that Is_Itype is wrong because that's
2757 -- also set in private type cases. We also can't check for
2758 -- the Scope being exactly Rec because of private types and
2759 -- record extensions.
2761 if Is_Itype
(Etype
(Comp
))
2762 and then Is_Record_Type
(Underlying_Type
2763 (Scope
(Etype
(Comp
))))
2765 Undelay_Type
(Etype
(Comp
));
2768 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
2770 -- Warn for pragma Pack overriding foreign convention
2772 if Has_Foreign_Convention
(Etype
(Comp
))
2773 and then Has_Pragma_Pack
(Rec
)
2775 -- Don't warn for aliased components, since override
2776 -- cannot happen in that case.
2778 and then not Is_Aliased
(Comp
)
2781 CN
: constant Name_Id
:=
2782 Get_Convention_Name
(Convention
(Etype
(Comp
)));
2783 PP
: constant Node_Id
:=
2784 Get_Pragma
(Rec
, Pragma_Pack
);
2786 if Present
(PP
) then
2787 Error_Msg_Name_1
:= CN
;
2788 Error_Msg_Sloc
:= Sloc
(Comp
);
2790 ("pragma Pack affects convention % component#??",
2792 Error_Msg_Name_1
:= CN
;
2794 ("\component & may not have % compatible "
2795 & "representation??", PP
, Comp
);
2800 -- Check for error of component clause given for variable
2801 -- sized type. We have to delay this test till this point,
2802 -- since the component type has to be frozen for us to know
2803 -- if it is variable length. We omit this test in a generic
2804 -- context, it will be applied at instantiation time.
2806 -- We also omit this test in CodePeer mode, since we do not
2807 -- have sufficient info on size and representation clauses.
2809 if Present
(CC
) then
2810 Placed_Component
:= True;
2812 if Inside_A_Generic
then
2815 elsif CodePeer_Mode
then
2819 Size_Known_At_Compile_Time
2820 (Underlying_Type
(Etype
(Comp
)))
2823 ("component clause not allowed for variable " &
2824 "length component", CC
);
2828 Unplaced_Component
:= True;
2831 -- Case of component requires byte alignment
2833 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
2835 -- Set the enclosing record to also require byte align
2837 Set_Must_Be_On_Byte_Boundary
(Rec
);
2839 -- Check for component clause that is inconsistent with
2840 -- the required byte boundary alignment.
2843 and then Normalized_First_Bit
(Comp
) mod
2844 System_Storage_Unit
/= 0
2847 ("component & must be byte aligned",
2848 Component_Name
(Component_Clause
(Comp
)));
2854 -- Gather data for possible Implicit_Packing later. Note that at
2855 -- this stage we might be dealing with a real component, or with
2856 -- an implicit subtype declaration.
2858 if not Is_Scalar_Type
(Etype
(Comp
)) then
2859 All_Scalar_Components
:= False;
2861 Scalar_Component_Total_RM_Size
:=
2862 Scalar_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
2863 Scalar_Component_Total_Esize
:=
2864 Scalar_Component_Total_Esize
+ Esize
(Etype
(Comp
));
2867 -- If the component is an Itype with Delayed_Freeze and is either
2868 -- a record or array subtype and its base type has not yet been
2869 -- frozen, we must remove this from the entity list of this record
2870 -- and put it on the entity list of the scope of its base type.
2871 -- Note that we know that this is not the type of a component
2872 -- since we cleared Has_Delayed_Freeze for it in the previous
2873 -- loop. Thus this must be the Designated_Type of an access type,
2874 -- which is the type of a component.
2877 and then Is_Type
(Scope
(Comp
))
2878 and then Is_Composite_Type
(Comp
)
2879 and then Base_Type
(Comp
) /= Comp
2880 and then Has_Delayed_Freeze
(Comp
)
2881 and then not Is_Frozen
(Base_Type
(Comp
))
2884 Will_Be_Frozen
: Boolean := False;
2888 -- We have a pretty bad kludge here. Suppose Rec is subtype
2889 -- being defined in a subprogram that's created as part of
2890 -- the freezing of Rec'Base. In that case, we know that
2891 -- Comp'Base must have already been frozen by the time we
2892 -- get to elaborate this because Gigi doesn't elaborate any
2893 -- bodies until it has elaborated all of the declarative
2894 -- part. But Is_Frozen will not be set at this point because
2895 -- we are processing code in lexical order.
2897 -- We detect this case by going up the Scope chain of Rec
2898 -- and seeing if we have a subprogram scope before reaching
2899 -- the top of the scope chain or that of Comp'Base. If we
2900 -- do, then mark that Comp'Base will actually be frozen. If
2901 -- so, we merely undelay it.
2904 while Present
(S
) loop
2905 if Is_Subprogram
(S
) then
2906 Will_Be_Frozen
:= True;
2908 elsif S
= Scope
(Base_Type
(Comp
)) then
2915 if Will_Be_Frozen
then
2916 Undelay_Type
(Comp
);
2918 if Present
(Prev
) then
2919 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
2921 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
2924 -- Insert in entity list of scope of base type (which
2925 -- must be an enclosing scope, because still unfrozen).
2927 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
2931 -- If the component is an access type with an allocator as default
2932 -- value, the designated type will be frozen by the corresponding
2933 -- expression in init_proc. In order to place the freeze node for
2934 -- the designated type before that for the current record type,
2937 -- Same process if the component is an array of access types,
2938 -- initialized with an aggregate. If the designated type is
2939 -- private, it cannot contain allocators, and it is premature
2940 -- to freeze the type, so we check for this as well.
2942 elsif Is_Access_Type
(Etype
(Comp
))
2943 and then Present
(Parent
(Comp
))
2944 and then Present
(Expression
(Parent
(Comp
)))
2947 Alloc
: constant Node_Id
:=
2948 Check_Allocator
(Expression
(Parent
(Comp
)));
2951 if Present
(Alloc
) then
2953 -- If component is pointer to a class-wide type, freeze
2954 -- the specific type in the expression being allocated.
2955 -- The expression may be a subtype indication, in which
2956 -- case freeze the subtype mark.
2958 if Is_Class_Wide_Type
2959 (Designated_Type
(Etype
(Comp
)))
2961 if Is_Entity_Name
(Expression
(Alloc
)) then
2963 (Entity
(Expression
(Alloc
)), N
, Result
);
2965 Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
2968 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
2972 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
2973 Check_Itype
(Etype
(Comp
));
2977 (Designated_Type
(Etype
(Comp
)), N
, Result
);
2982 elsif Is_Access_Type
(Etype
(Comp
))
2983 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
2985 Check_Itype
(Etype
(Comp
));
2987 elsif Is_Array_Type
(Etype
(Comp
))
2988 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
2989 and then Present
(Parent
(Comp
))
2990 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
2991 and then Present
(Expression
(Parent
(Comp
)))
2992 and then Nkind
(Expression
(Parent
(Comp
))) = N_Aggregate
2993 and then Is_Fully_Defined
2994 (Designated_Type
(Component_Type
(Etype
(Comp
))))
2998 (Component_Type
(Etype
(Comp
))), N
, Result
);
3005 ADC
:= Get_Attribute_Definition_Clause
3006 (Rec
, Attribute_Scalar_Storage_Order
);
3008 if Present
(ADC
) then
3010 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
3011 -- the former is specified.
3013 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
3015 -- Note: report error on Rec, not on ADC, as ADC may apply to
3016 -- an ancestor type.
3018 Error_Msg_Sloc
:= Sloc
(ADC
);
3020 ("scalar storage order for& specified# inconsistent with "
3021 & "bit order", Rec
);
3024 -- Warn if there is a Scalar_Storage_Order but no component clause
3025 -- (or pragma Pack).
3027 if not (Placed_Component
or else Is_Packed
(Rec
)) then
3029 ("??scalar storage order specified but no component clause",
3034 -- Check consistent attribute setting on component types
3036 Comp
:= First_Component
(Rec
);
3037 while Present
(Comp
) loop
3038 Check_Component_Storage_Order
3039 (Encl_Type
=> Rec
, Comp
=> Comp
, ADC
=> ADC
);
3040 Next_Component
(Comp
);
3043 -- Deal with Bit_Order aspect specifying a non-default bit order
3045 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
3047 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
3048 if not (Placed_Component
or else Is_Packed
(Rec
)) then
3050 ("??bit order specification has no effect", ADC
);
3052 ("\??since no component clauses were specified", ADC
);
3054 -- Here is where we do the processing for reversed bit order
3056 elsif Reverse_Bit_Order
(Rec
)
3057 and then not Reverse_Storage_Order
(Rec
)
3059 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
3061 -- Case where we have both an explicit Bit_Order and the same
3062 -- Scalar_Storage_Order: leave record untouched, the back-end
3063 -- will take care of required layout conversions.
3071 -- Complete error checking on record representation clause (e.g.
3072 -- overlap of components). This is called after adjusting the
3073 -- record for reverse bit order.
3076 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
3078 if Present
(RRC
) then
3079 Check_Record_Representation_Clause
(RRC
);
3083 -- Set OK_To_Reorder_Components depending on debug flags
3085 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
3086 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
3088 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
3090 Set_OK_To_Reorder_Components
(Rec
);
3094 -- Check for useless pragma Pack when all components placed. We only
3095 -- do this check for record types, not subtypes, since a subtype may
3096 -- have all its components placed, and it still makes perfectly good
3097 -- sense to pack other subtypes or the parent type. We do not give
3098 -- this warning if Optimize_Alignment is set to Space, since the
3099 -- pragma Pack does have an effect in this case (it always resets
3100 -- the alignment to one).
3102 if Ekind
(Rec
) = E_Record_Type
3103 and then Is_Packed
(Rec
)
3104 and then not Unplaced_Component
3105 and then Optimize_Alignment
/= 'S'
3107 -- Reset packed status. Probably not necessary, but we do it so
3108 -- that there is no chance of the back end doing something strange
3109 -- with this redundant indication of packing.
3111 Set_Is_Packed
(Rec
, False);
3113 -- Give warning if redundant constructs warnings on
3115 if Warn_On_Redundant_Constructs
then
3116 Error_Msg_N
-- CODEFIX
3117 ("??pragma Pack has no effect, no unplaced components",
3118 Get_Rep_Pragma
(Rec
, Name_Pack
));
3122 -- If this is the record corresponding to a remote type, freeze the
3123 -- remote type here since that is what we are semantically freezing.
3124 -- This prevents the freeze node for that type in an inner scope.
3126 if Ekind
(Rec
) = E_Record_Type
then
3127 if Present
(Corresponding_Remote_Type
(Rec
)) then
3128 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
3131 -- Check for controlled components and unchecked unions.
3133 Comp
:= First_Component
(Rec
);
3134 while Present
(Comp
) loop
3136 -- Do not set Has_Controlled_Component on a class-wide
3137 -- equivalent type. See Make_CW_Equivalent_Type.
3139 if not Is_Class_Wide_Equivalent_Type
(Rec
)
3141 (Has_Controlled_Component
(Etype
(Comp
))
3143 (Chars
(Comp
) /= Name_uParent
3144 and then Is_Controlled
(Etype
(Comp
)))
3146 (Is_Protected_Type
(Etype
(Comp
))
3148 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
3150 Has_Controlled_Component
3151 (Corresponding_Record_Type
(Etype
(Comp
)))))
3153 Set_Has_Controlled_Component
(Rec
);
3156 if Has_Unchecked_Union
(Etype
(Comp
)) then
3157 Set_Has_Unchecked_Union
(Rec
);
3160 -- Scan component declaration for likely misuses of current
3161 -- instance, either in a constraint or a default expression.
3163 if Has_Per_Object_Constraint
(Comp
) then
3164 Check_Current_Instance
(Parent
(Comp
));
3167 Next_Component
(Comp
);
3171 -- Enforce the restriction that access attributes with a current
3172 -- instance prefix can only apply to limited types. This comment
3173 -- is floating here, but does not seem to belong here???
3175 -- Set component alignment if not otherwise already set
3177 Set_Component_Alignment_If_Not_Set
(Rec
);
3179 -- For first subtypes, check if there are any fixed-point fields with
3180 -- component clauses, where we must check the size. This is not done
3181 -- till the freeze point since for fixed-point types, we do not know
3182 -- the size until the type is frozen. Similar processing applies to
3183 -- bit packed arrays.
3185 if Is_First_Subtype
(Rec
) then
3186 Comp
:= First_Component
(Rec
);
3187 while Present
(Comp
) loop
3188 if Present
(Component_Clause
(Comp
))
3189 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
3191 Is_Bit_Packed_Array
(Etype
(Comp
)))
3194 (Component_Name
(Component_Clause
(Comp
)),
3200 Next_Component
(Comp
);
3204 -- Generate warning for applying C or C++ convention to a record
3205 -- with discriminants. This is suppressed for the unchecked union
3206 -- case, since the whole point in this case is interface C. We also
3207 -- do not generate this within instantiations, since we will have
3208 -- generated a message on the template.
3210 if Has_Discriminants
(E
)
3211 and then not Is_Unchecked_Union
(E
)
3212 and then (Convention
(E
) = Convention_C
3214 Convention
(E
) = Convention_CPP
)
3215 and then Comes_From_Source
(E
)
3216 and then not In_Instance
3217 and then not Has_Warnings_Off
(E
)
3218 and then not Has_Warnings_Off
(Base_Type
(E
))
3221 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
3225 if Present
(Cprag
) then
3226 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3228 if Convention
(E
) = Convention_C
then
3230 ("?x?variant record has no direct equivalent in C",
3234 ("?x?variant record has no direct equivalent in C++",
3239 ("\?x?use of convention for type& is dubious", A2
, E
);
3244 -- See if Size is too small as is (and implicit packing might help)
3246 if not Is_Packed
(Rec
)
3248 -- No implicit packing if even one component is explicitly placed
3250 and then not Placed_Component
3252 -- Or even one component is aliased
3254 and then not Aliased_Component
3256 -- Must have size clause and all scalar components
3258 and then Has_Size_Clause
(Rec
)
3259 and then All_Scalar_Components
3261 -- Do not try implicit packing on records with discriminants, too
3262 -- complicated, especially in the variant record case.
3264 and then not Has_Discriminants
(Rec
)
3266 -- We can implicitly pack if the specified size of the record is
3267 -- less than the sum of the object sizes (no point in packing if
3268 -- this is not the case).
3270 and then RM_Size
(Rec
) < Scalar_Component_Total_Esize
3272 -- And the total RM size cannot be greater than the specified size
3273 -- since otherwise packing will not get us where we have to be!
3275 and then RM_Size
(Rec
) >= Scalar_Component_Total_RM_Size
3277 -- Never do implicit packing in CodePeer or SPARK modes since
3278 -- we don't do any packing in these modes, since this generates
3279 -- over-complex code that confuses static analysis, and in
3280 -- general, neither CodePeer not GNATprove care about the
3281 -- internal representation of objects.
3283 and then not (CodePeer_Mode
or SPARK_Mode
)
3285 -- If implicit packing enabled, do it
3287 if Implicit_Packing
then
3288 Set_Is_Packed
(Rec
);
3290 -- Otherwise flag the size clause
3294 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
3296 Error_Msg_NE
-- CODEFIX
3297 ("size given for& too small", Sz
, Rec
);
3298 Error_Msg_N
-- CODEFIX
3299 ("\use explicit pragma Pack "
3300 & "or use pragma Implicit_Packing", Sz
);
3305 -- All done if not a full record definition
3307 if Ekind
(Rec
) /= E_Record_Type
then
3311 -- Finally we need to check the variant part to make sure that
3312 -- all types within choices are properly frozen as part of the
3313 -- freezing of the record type.
3315 Check_Variant_Part
: declare
3316 D
: constant Node_Id
:= Declaration_Node
(Rec
);
3321 -- Find component list
3325 if Nkind
(D
) = N_Full_Type_Declaration
then
3326 T
:= Type_Definition
(D
);
3328 if Nkind
(T
) = N_Record_Definition
then
3329 C
:= Component_List
(T
);
3331 elsif Nkind
(T
) = N_Derived_Type_Definition
3332 and then Present
(Record_Extension_Part
(T
))
3334 C
:= Component_List
(Record_Extension_Part
(T
));
3338 -- Case of variant part present
3340 if Present
(C
) and then Present
(Variant_Part
(C
)) then
3341 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
3344 -- Note: we used to call Check_Choices here, but it is too early,
3345 -- since predicated subtypes are frozen here, but their freezing
3346 -- actions are in Analyze_Freeze_Entity, which has not been called
3347 -- yet for entities frozen within this procedure, so we moved that
3348 -- call to the Analyze_Freeze_Entity for the record type.
3350 end Check_Variant_Part
;
3351 end Freeze_Record_Type
;
3353 -- Start of processing for Freeze_Entity
3356 -- We are going to test for various reasons why this entity need not be
3357 -- frozen here, but in the case of an Itype that's defined within a
3358 -- record, that test actually applies to the record.
3360 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
3361 Test_E
:= Scope
(E
);
3362 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
3363 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
3365 Test_E
:= Underlying_Type
(Scope
(E
));
3368 -- Do not freeze if already frozen since we only need one freeze node
3370 if Is_Frozen
(E
) then
3373 -- It is improper to freeze an external entity within a generic because
3374 -- its freeze node will appear in a non-valid context. The entity will
3375 -- be frozen in the proper scope after the current generic is analyzed.
3376 -- However, aspects must be analyzed because they may be queried later
3377 -- within the generic itself, and the corresponding pragma or attribute
3378 -- definition has not been analyzed yet.
3380 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
3381 if Has_Delayed_Aspects
(E
) then
3382 Analyze_Aspects_At_Freeze_Point
(E
);
3387 -- AI05-0213: A formal incomplete type does not freeze the actual. In
3388 -- the instance, the same applies to the subtype renaming the actual.
3390 elsif Is_Private_Type
(E
)
3391 and then Is_Generic_Actual_Type
(E
)
3392 and then No
(Full_View
(Base_Type
(E
)))
3393 and then Ada_Version
>= Ada_2012
3397 -- Generic types need no freeze node and have no delayed semantic
3400 elsif Is_Generic_Type
(E
) then
3403 -- Do not freeze a global entity within an inner scope created during
3404 -- expansion. A call to subprogram E within some internal procedure
3405 -- (a stream attribute for example) might require freezing E, but the
3406 -- freeze node must appear in the same declarative part as E itself.
3407 -- The two-pass elaboration mechanism in gigi guarantees that E will
3408 -- be frozen before the inner call is elaborated. We exclude constants
3409 -- from this test, because deferred constants may be frozen early, and
3410 -- must be diagnosed (e.g. in the case of a deferred constant being used
3411 -- in a default expression). If the enclosing subprogram comes from
3412 -- source, or is a generic instance, then the freeze point is the one
3413 -- mandated by the language, and we freeze the entity. A subprogram that
3414 -- is a child unit body that acts as a spec does not have a spec that
3415 -- comes from source, but can only come from source.
3417 elsif In_Open_Scopes
(Scope
(Test_E
))
3418 and then Scope
(Test_E
) /= Current_Scope
3419 and then Ekind
(Test_E
) /= E_Constant
3426 while Present
(S
) loop
3427 if Is_Overloadable
(S
) then
3428 if Comes_From_Source
(S
)
3429 or else Is_Generic_Instance
(S
)
3430 or else Is_Child_Unit
(S
)
3442 -- Similarly, an inlined instance body may make reference to global
3443 -- entities, but these references cannot be the proper freezing point
3444 -- for them, and in the absence of inlining freezing will take place in
3445 -- their own scope. Normally instance bodies are analyzed after the
3446 -- enclosing compilation, and everything has been frozen at the proper
3447 -- place, but with front-end inlining an instance body is compiled
3448 -- before the end of the enclosing scope, and as a result out-of-order
3449 -- freezing must be prevented.
3451 elsif Front_End_Inlining
3452 and then In_Instance_Body
3453 and then Present
(Scope
(Test_E
))
3459 S
:= Scope
(Test_E
);
3460 while Present
(S
) loop
3461 if Is_Generic_Instance
(S
) then
3473 elsif Ekind
(E
) = E_Generic_Package
then
3474 return Freeze_Generic_Entities
(E
);
3477 -- Add checks to detect proper initialization of scalars that may appear
3478 -- as subprogram parameters.
3480 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
3481 Apply_Parameter_Validity_Checks
(E
);
3484 -- Deal with delayed aspect specifications. The analysis of the aspect
3485 -- is required to be delayed to the freeze point, thus we analyze the
3486 -- pragma or attribute definition clause in the tree at this point. We
3487 -- also analyze the aspect specification node at the freeze point when
3488 -- the aspect doesn't correspond to pragma/attribute definition clause.
3490 if Has_Delayed_Aspects
(E
) then
3491 Analyze_Aspects_At_Freeze_Point
(E
);
3494 -- Here to freeze the entity
3498 -- Case of entity being frozen is other than a type
3500 if not Is_Type
(E
) then
3502 -- If entity is exported or imported and does not have an external
3503 -- name, now is the time to provide the appropriate default name.
3504 -- Skip this if the entity is stubbed, since we don't need a name
3505 -- for any stubbed routine. For the case on intrinsics, if no
3506 -- external name is specified, then calls will be handled in
3507 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
3508 -- external name is provided, then Expand_Intrinsic_Call leaves
3509 -- calls in place for expansion by GIGI.
3511 if (Is_Imported
(E
) or else Is_Exported
(E
))
3512 and then No
(Interface_Name
(E
))
3513 and then Convention
(E
) /= Convention_Stubbed
3514 and then Convention
(E
) /= Convention_Intrinsic
3516 Set_Encoded_Interface_Name
3517 (E
, Get_Default_External_Name
(E
));
3519 -- If entity is an atomic object appearing in a declaration and
3520 -- the expression is an aggregate, assign it to a temporary to
3521 -- ensure that the actual assignment is done atomically rather
3522 -- than component-wise (the assignment to the temp may be done
3523 -- component-wise, but that is harmless).
3526 and then Nkind
(Parent
(E
)) = N_Object_Declaration
3527 and then Present
(Expression
(Parent
(E
)))
3528 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
3529 and then Is_Atomic_Aggregate
(Expression
(Parent
(E
)), Etype
(E
))
3534 -- For a subprogram, freeze all parameter types and also the return
3535 -- type (RM 13.14(14)). However skip this for internal subprograms.
3536 -- This is also the point where any extra formal parameters are
3537 -- created since we now know whether the subprogram will use a
3538 -- foreign convention.
3540 if Is_Subprogram
(E
) then
3541 if not Is_Internal
(E
) then
3545 Warn_Node
: Node_Id
;
3548 -- Loop through formals
3550 Formal
:= First_Formal
(E
);
3551 while Present
(Formal
) loop
3552 F_Type
:= Etype
(Formal
);
3554 -- AI05-0151 : incomplete types can appear in a profile.
3555 -- By the time the entity is frozen, the full view must
3556 -- be available, unless it is a limited view.
3558 if Is_Incomplete_Type
(F_Type
)
3559 and then Present
(Full_View
(F_Type
))
3560 and then not From_Limited_With
(F_Type
)
3562 F_Type
:= Full_View
(F_Type
);
3563 Set_Etype
(Formal
, F_Type
);
3566 Freeze_And_Append
(F_Type
, N
, Result
);
3568 if Is_Private_Type
(F_Type
)
3569 and then Is_Private_Type
(Base_Type
(F_Type
))
3570 and then No
(Full_View
(Base_Type
(F_Type
)))
3571 and then not Is_Generic_Type
(F_Type
)
3572 and then not Is_Derived_Type
(F_Type
)
3574 -- If the type of a formal is incomplete, subprogram
3575 -- is being frozen prematurely. Within an instance
3576 -- (but not within a wrapper package) this is an
3577 -- artifact of our need to regard the end of an
3578 -- instantiation as a freeze point. Otherwise it is
3579 -- a definite error.
3582 Set_Is_Frozen
(E
, False);
3585 elsif not After_Last_Declaration
3586 and then not Freezing_Library_Level_Tagged_Type
3588 Error_Msg_Node_1
:= F_Type
;
3590 ("type& must be fully defined before this point",
3595 -- Check suspicious parameter for C function. These tests
3596 -- apply only to exported/imported subprograms.
3598 if Warn_On_Export_Import
3599 and then Comes_From_Source
(E
)
3600 and then (Convention
(E
) = Convention_C
3602 Convention
(E
) = Convention_CPP
)
3603 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3604 and then Convention
(E
) /= Convention
(Formal
)
3605 and then not Has_Warnings_Off
(E
)
3606 and then not Has_Warnings_Off
(F_Type
)
3607 and then not Has_Warnings_Off
(Formal
)
3609 -- Qualify mention of formals with subprogram name
3611 Error_Msg_Qual_Level
:= 1;
3613 -- Check suspicious use of fat C pointer
3615 if Is_Access_Type
(F_Type
)
3616 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
3619 ("?x?type of & does not correspond to C pointer!",
3622 -- Check suspicious return of boolean
3624 elsif Root_Type
(F_Type
) = Standard_Boolean
3625 and then Convention
(F_Type
) = Convention_Ada
3626 and then not Has_Warnings_Off
(F_Type
)
3627 and then not Has_Size_Clause
(F_Type
)
3628 and then VM_Target
= No_VM
3631 ("& is an 8-bit Ada Boolean?x?", Formal
);
3633 ("\use appropriate corresponding type in C "
3634 & "(e.g. char)?x?", Formal
);
3636 -- Check suspicious tagged type
3638 elsif (Is_Tagged_Type
(F_Type
)
3639 or else (Is_Access_Type
(F_Type
)
3642 (Designated_Type
(F_Type
))))
3643 and then Convention
(E
) = Convention_C
3646 ("?x?& involves a tagged type which does not "
3647 & "correspond to any C type!", Formal
);
3649 -- Check wrong convention subprogram pointer
3651 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
3652 and then not Has_Foreign_Convention
(F_Type
)
3655 ("?x?subprogram pointer & should "
3656 & "have foreign convention!", Formal
);
3657 Error_Msg_Sloc
:= Sloc
(F_Type
);
3659 ("\?x?add Convention pragma to declaration of &#",
3663 -- Turn off name qualification after message output
3665 Error_Msg_Qual_Level
:= 0;
3668 -- Check for unconstrained array in exported foreign
3671 if Has_Foreign_Convention
(E
)
3672 and then not Is_Imported
(E
)
3673 and then Is_Array_Type
(F_Type
)
3674 and then not Is_Constrained
(F_Type
)
3675 and then Warn_On_Export_Import
3677 -- Exclude VM case, since both .NET and JVM can handle
3678 -- unconstrained arrays without a problem.
3680 and then VM_Target
= No_VM
3682 Error_Msg_Qual_Level
:= 1;
3684 -- If this is an inherited operation, place the
3685 -- warning on the derived type declaration, rather
3686 -- than on the original subprogram.
3688 if Nkind
(Original_Node
(Parent
(E
))) =
3689 N_Full_Type_Declaration
3691 Warn_Node
:= Parent
(E
);
3693 if Formal
= First_Formal
(E
) then
3695 ("??in inherited operation&", Warn_Node
, E
);
3698 Warn_Node
:= Formal
;
3702 ("?x?type of argument& is unconstrained array",
3705 ("?x?foreign caller must pass bounds explicitly",
3707 Error_Msg_Qual_Level
:= 0;
3710 if not From_Limited_With
(F_Type
) then
3711 if Is_Access_Type
(F_Type
) then
3712 F_Type
:= Designated_Type
(F_Type
);
3715 -- If the formal is an anonymous_access_to_subprogram
3716 -- freeze the subprogram type as well, to prevent
3717 -- scope anomalies in gigi, because there is no other
3718 -- clear point at which it could be frozen.
3720 if Is_Itype
(Etype
(Formal
))
3721 and then Ekind
(F_Type
) = E_Subprogram_Type
3723 Freeze_And_Append
(F_Type
, N
, Result
);
3727 Next_Formal
(Formal
);
3730 -- Case of function: similar checks on return type
3732 if Ekind
(E
) = E_Function
then
3734 -- Freeze return type
3736 R_Type
:= Etype
(E
);
3738 -- AI05-0151: the return type may have been incomplete
3739 -- at the point of declaration. Replace it with the full
3740 -- view, unless the current type is a limited view. In
3741 -- that case the full view is in a different unit, and
3742 -- gigi finds the non-limited view after the other unit
3745 if Ekind
(R_Type
) = E_Incomplete_Type
3746 and then Present
(Full_View
(R_Type
))
3747 and then not From_Limited_With
(R_Type
)
3749 R_Type
:= Full_View
(R_Type
);
3750 Set_Etype
(E
, R_Type
);
3753 Freeze_And_Append
(R_Type
, N
, Result
);
3755 -- Check suspicious return type for C function
3757 if Warn_On_Export_Import
3758 and then (Convention
(E
) = Convention_C
3760 Convention
(E
) = Convention_CPP
)
3761 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3763 -- Check suspicious return of fat C pointer
3765 if Is_Access_Type
(R_Type
)
3766 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
3767 and then not Has_Warnings_Off
(E
)
3768 and then not Has_Warnings_Off
(R_Type
)
3771 ("?x?return type of& does not "
3772 & "correspond to C pointer!", E
);
3774 -- Check suspicious return of boolean
3776 elsif Root_Type
(R_Type
) = Standard_Boolean
3777 and then Convention
(R_Type
) = Convention_Ada
3778 and then VM_Target
= No_VM
3779 and then not Has_Warnings_Off
(E
)
3780 and then not Has_Warnings_Off
(R_Type
)
3781 and then not Has_Size_Clause
(R_Type
)
3784 N
: constant Node_Id
:=
3785 Result_Definition
(Declaration_Node
(E
));
3788 ("return type of & is an 8-bit Ada Boolean?x?",
3791 ("\use appropriate corresponding type in C "
3792 & "(e.g. char)?x?", N
, E
);
3795 -- Check suspicious return tagged type
3797 elsif (Is_Tagged_Type
(R_Type
)
3798 or else (Is_Access_Type
(R_Type
)
3801 (Designated_Type
(R_Type
))))
3802 and then Convention
(E
) = Convention_C
3803 and then not Has_Warnings_Off
(E
)
3804 and then not Has_Warnings_Off
(R_Type
)
3807 ("?x?return type of & does not "
3808 & "correspond to C type!", E
);
3810 -- Check return of wrong convention subprogram pointer
3812 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3813 and then not Has_Foreign_Convention
(R_Type
)
3814 and then not Has_Warnings_Off
(E
)
3815 and then not Has_Warnings_Off
(R_Type
)
3818 ("?x?& should return a foreign "
3819 & "convention subprogram pointer", E
);
3820 Error_Msg_Sloc
:= Sloc
(R_Type
);
3822 ("\?x?add Convention pragma to declaration of& #",
3827 -- Give warning for suspicious return of a result of an
3828 -- unconstrained array type in a foreign convention
3831 if Has_Foreign_Convention
(E
)
3833 -- We are looking for a return of unconstrained array
3835 and then Is_Array_Type
(R_Type
)
3836 and then not Is_Constrained
(R_Type
)
3838 -- Exclude imported routines, the warning does not
3839 -- belong on the import, but rather on the routine
3842 and then not Is_Imported
(E
)
3844 -- Exclude VM case, since both .NET and JVM can handle
3845 -- return of unconstrained arrays without a problem.
3847 and then VM_Target
= No_VM
3849 -- Check that general warning is enabled, and that it
3850 -- is not suppressed for this particular case.
3852 and then Warn_On_Export_Import
3853 and then not Has_Warnings_Off
(E
)
3854 and then not Has_Warnings_Off
(R_Type
)
3857 ("?x?foreign convention function& should not " &
3858 "return unconstrained array!", E
);
3863 -- Pre/post conditions are implemented through a subprogram in
3864 -- the corresponding body, and therefore are not checked on an
3865 -- imported subprogram for which the body is not available.
3867 -- Could consider generating a wrapper to take care of this???
3869 if Is_Subprogram
(E
)
3870 and then Is_Imported
(E
)
3871 and then Present
(Contract
(E
))
3872 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
3875 ("pre/post conditions on imported subprogram are not "
3876 & "enforced??", E
, Pre_Post_Conditions
(Contract
(E
)));
3881 -- Must freeze its parent first if it is a derived subprogram
3883 if Present
(Alias
(E
)) then
3884 Freeze_And_Append
(Alias
(E
), N
, Result
);
3887 -- We don't freeze internal subprograms, because we don't normally
3888 -- want addition of extra formals or mechanism setting to happen
3889 -- for those. However we do pass through predefined dispatching
3890 -- cases, since extra formals may be needed in some cases, such as
3891 -- for the stream 'Input function (build-in-place formals).
3893 if not Is_Internal
(E
)
3894 or else Is_Predefined_Dispatching_Operation
(E
)
3896 Freeze_Subprogram
(E
);
3899 -- Here for other than a subprogram or type
3902 -- If entity has a type, and it is not a generic unit, then
3903 -- freeze it first (RM 13.14(10)).
3905 if Present
(Etype
(E
))
3906 and then Ekind
(E
) /= E_Generic_Function
3908 Freeze_And_Append
(Etype
(E
), N
, Result
);
3911 -- Special processing for objects created by object declaration
3913 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
3915 -- Abstract type allowed only for C++ imported variables or
3918 -- Note: we inhibit this check for objects that do not come
3919 -- from source because there is at least one case (the
3920 -- expansion of x'Class'Input where x is abstract) where we
3921 -- legitimately generate an abstract object.
3923 if Is_Abstract_Type
(Etype
(E
))
3924 and then Comes_From_Source
(Parent
(E
))
3925 and then not (Is_Imported
(E
)
3926 and then Is_CPP_Class
(Etype
(E
)))
3928 Error_Msg_N
("type of object cannot be abstract",
3929 Object_Definition
(Parent
(E
)));
3931 if Is_CPP_Class
(Etype
(E
)) then
3933 ("\} may need a cpp_constructor",
3934 Object_Definition
(Parent
(E
)), Etype
(E
));
3938 -- For object created by object declaration, perform required
3939 -- categorization (preelaborate and pure) checks. Defer these
3940 -- checks to freeze time since pragma Import inhibits default
3941 -- initialization and thus pragma Import affects these checks.
3943 Validate_Object_Declaration
(Declaration_Node
(E
));
3945 -- If there is an address clause, check that it is valid
3947 Check_Address_Clause
(E
);
3949 -- Reset Is_True_Constant for aliased object. We consider that
3950 -- the fact that something is aliased may indicate that some
3951 -- funny business is going on, e.g. an aliased object is passed
3952 -- by reference to a procedure which captures the address of
3953 -- the object, which is later used to assign a new value. Such
3954 -- code is highly dubious, but we choose to make it "work" for
3957 -- However, we don't do that for internal entities. We figure
3958 -- that if we deliberately set Is_True_Constant for an internal
3959 -- entity, e.g. a dispatch table entry, then we mean it!
3961 if (Is_Aliased
(E
) or else Is_Aliased
(Etype
(E
)))
3962 and then not Is_Internal_Name
(Chars
(E
))
3964 Set_Is_True_Constant
(E
, False);
3967 -- If the object needs any kind of default initialization, an
3968 -- error must be issued if No_Default_Initialization applies.
3969 -- The check doesn't apply to imported objects, which are not
3970 -- ever default initialized, and is why the check is deferred
3971 -- until freezing, at which point we know if Import applies.
3972 -- Deferred constants are also exempted from this test because
3973 -- their completion is explicit, or through an import pragma.
3975 if Ekind
(E
) = E_Constant
3976 and then Present
(Full_View
(E
))
3980 elsif Comes_From_Source
(E
)
3981 and then not Is_Imported
(E
)
3982 and then not Has_Init_Expression
(Declaration_Node
(E
))
3984 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
3985 and then not No_Initialization
(Declaration_Node
(E
))
3986 and then not Is_Value_Type
(Etype
(E
))
3987 and then not Initialization_Suppressed
(Etype
(E
)))
3989 (Needs_Simple_Initialization
(Etype
(E
))
3990 and then not Is_Internal
(E
)))
3992 Has_Default_Initialization
:= True;
3994 (No_Default_Initialization
, Declaration_Node
(E
));
3997 -- Check that a Thread_Local_Storage variable does not have
3998 -- default initialization, and any explicit initialization must
3999 -- either be the null constant or a static constant.
4001 if Has_Pragma_Thread_Local_Storage
(E
) then
4003 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4005 if Has_Default_Initialization
4007 (Has_Init_Expression
(Decl
)
4009 (No
(Expression
(Decl
))
4011 (Is_Static_Expression
(Expression
(Decl
))
4013 Nkind
(Expression
(Decl
)) = N_Null
)))
4016 ("Thread_Local_Storage variable& is "
4017 & "improperly initialized", Decl
, E
);
4019 ("\only allowed initialization is explicit "
4020 & "NULL or static expression", Decl
, E
);
4025 -- For imported objects, set Is_Public unless there is also an
4026 -- address clause, which means that there is no external symbol
4027 -- needed for the Import (Is_Public may still be set for other
4028 -- unrelated reasons). Note that we delayed this processing
4029 -- till freeze time so that we can be sure not to set the flag
4030 -- if there is an address clause. If there is such a clause,
4031 -- then the only purpose of the Import pragma is to suppress
4032 -- implicit initialization.
4034 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4038 -- For convention C objects of an enumeration type, warn if
4039 -- the size is not integer size and no explicit size given.
4040 -- Skip warning for Boolean, and Character, assume programmer
4041 -- expects 8-bit sizes for these cases.
4043 if (Convention
(E
) = Convention_C
4045 Convention
(E
) = Convention_CPP
)
4046 and then Is_Enumeration_Type
(Etype
(E
))
4047 and then not Is_Character_Type
(Etype
(E
))
4048 and then not Is_Boolean_Type
(Etype
(E
))
4049 and then Esize
(Etype
(E
)) < Standard_Integer_Size
4050 and then not Has_Size_Clause
(E
)
4052 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4054 ("??convention C enumeration object has size less than ^",
4056 Error_Msg_N
("\?use explicit size clause to set size", E
);
4060 -- Check that a constant which has a pragma Volatile[_Components]
4061 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
4063 -- Note: Atomic[_Components] also sets Volatile[_Components]
4065 if Ekind
(E
) = E_Constant
4066 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
4067 and then not Is_Imported
(E
)
4069 -- Make sure we actually have a pragma, and have not merely
4070 -- inherited the indication from elsewhere (e.g. an address
4071 -- clause, which is not good enough in RM terms!)
4073 if Has_Rep_Pragma
(E
, Name_Atomic
)
4075 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
4078 ("stand alone atomic constant must be " &
4079 "imported (RM C.6(13))", E
);
4081 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
4083 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
4086 ("stand alone volatile constant must be " &
4087 "imported (RM C.6(13))", E
);
4091 -- Static objects require special handling
4093 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
4094 and then Is_Statically_Allocated
(E
)
4096 Freeze_Static_Object
(E
);
4099 -- Remaining step is to layout objects
4101 if Ekind
(E
) = E_Variable
4103 Ekind
(E
) = E_Constant
4105 Ekind
(E
) = E_Loop_Parameter
4112 -- If initialization statements were captured in an expression
4113 -- with actions with null expression, and the object does not
4114 -- have delayed freezing, move them back now directly within the
4115 -- enclosing statement sequence.
4117 if Ekind_In
(E
, E_Constant
, E_Variable
)
4118 and then not Has_Delayed_Freeze
(E
)
4121 Init_Stmts
: constant Node_Id
:=
4122 Initialization_Statements
(E
);
4124 if Present
(Init_Stmts
)
4125 and then Nkind
(Init_Stmts
) = N_Expression_With_Actions
4126 and then Nkind
(Expression
(Init_Stmts
)) = N_Null_Statement
4128 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
4130 -- Note that we rewrite Init_Stmts into a NULL statement,
4131 -- rather than just removing it, because Freeze_All may
4132 -- depend on this particular Node_Id still being present
4133 -- in the enclosing list to signal where to stop
4136 Rewrite
(Init_Stmts
,
4137 Make_Null_Statement
(Sloc
(Init_Stmts
)));
4139 Set_Initialization_Statements
(E
, Empty
);
4145 -- Case of a type or subtype being frozen
4148 -- We used to check here that a full type must have preelaborable
4149 -- initialization if it completes a private type specified with
4150 -- pragma Preelaborable_Initialization, but that missed cases where
4151 -- the types occur within a generic package, since the freezing
4152 -- that occurs within a containing scope generally skips traversal
4153 -- of a generic unit's declarations (those will be frozen within
4154 -- instances). This check was moved to Analyze_Package_Specification.
4156 -- The type may be defined in a generic unit. This can occur when
4157 -- freezing a generic function that returns the type (which is
4158 -- defined in a parent unit). It is clearly meaningless to freeze
4159 -- this type. However, if it is a subtype, its size may be determi-
4160 -- nable and used in subsequent checks, so might as well try to
4163 -- In Ada 2012, Freeze_Entities is also used in the front end to
4164 -- trigger the analysis of aspect expressions, so in this case we
4165 -- want to continue the freezing process.
4167 if Present
(Scope
(E
))
4168 and then Is_Generic_Unit
(Scope
(E
))
4170 (not Has_Predicates
(E
)
4171 and then not Has_Delayed_Freeze
(E
))
4173 Check_Compile_Time_Size
(E
);
4177 -- Deal with special cases of freezing for subtype
4179 if E
/= Base_Type
(E
) then
4181 -- Before we do anything else, a specialized test for the case of
4182 -- a size given for an array where the array needs to be packed,
4183 -- but was not so the size cannot be honored. This is the case
4184 -- where implicit packing may apply. The reason we do this so
4185 -- early is that if we have implicit packing, the layout of the
4186 -- base type is affected, so we must do this before we freeze
4189 -- We could do this processing only if implicit packing is enabled
4190 -- since in all other cases, the error would be caught by the back
4191 -- end. However, we choose to do the check even if we do not have
4192 -- implicit packing enabled, since this allows us to give a more
4193 -- useful error message (advising use of pragmas Implicit_Packing
4196 if Is_Array_Type
(E
) then
4198 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
4199 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
4200 SZ
: constant Node_Id
:= Size_Clause
(E
);
4201 Btyp
: constant Entity_Id
:= Base_Type
(E
);
4208 -- Number of elements in array
4211 -- Check enabling conditions. These are straightforward
4212 -- except for the test for a limited composite type. This
4213 -- eliminates the rare case of a array of limited components
4214 -- where there are issues of whether or not we can go ahead
4215 -- and pack the array (since we can't freely pack and unpack
4216 -- arrays if they are limited).
4218 -- Note that we check the root type explicitly because the
4219 -- whole point is we are doing this test before we have had
4220 -- a chance to freeze the base type (and it is that freeze
4221 -- action that causes stuff to be inherited).
4223 if Has_Size_Clause
(E
)
4224 and then Known_Static_RM_Size
(E
)
4225 and then not Is_Packed
(E
)
4226 and then not Has_Pragma_Pack
(E
)
4227 and then not Has_Component_Size_Clause
(E
)
4228 and then Known_Static_RM_Size
(Ctyp
)
4229 and then RM_Size
(Ctyp
) < 64
4230 and then not Is_Limited_Composite
(E
)
4231 and then not Is_Packed
(Root_Type
(E
))
4232 and then not Has_Component_Size_Clause
(Root_Type
(E
))
4233 and then not (CodePeer_Mode
or SPARK_Mode
)
4235 -- Compute number of elements in array
4237 Num_Elmts
:= Uint_1
;
4238 Indx
:= First_Index
(E
);
4239 while Present
(Indx
) loop
4240 Get_Index_Bounds
(Indx
, Lo
, Hi
);
4242 if not (Compile_Time_Known_Value
(Lo
)
4244 Compile_Time_Known_Value
(Hi
))
4246 goto No_Implicit_Packing
;
4252 Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1);
4256 -- What we are looking for here is the situation where
4257 -- the RM_Size given would be exactly right if there was
4258 -- a pragma Pack (resulting in the component size being
4259 -- the same as the RM_Size). Furthermore, the component
4260 -- type size must be an odd size (not a multiple of
4261 -- storage unit). If the component RM size is an exact
4262 -- number of storage units that is a power of two, the
4263 -- array is not packed and has a standard representation.
4265 if RM_Size
(E
) = Num_Elmts
* Rsiz
4266 and then Rsiz
mod System_Storage_Unit
/= 0
4268 -- For implicit packing mode, just set the component
4271 if Implicit_Packing
then
4272 Set_Component_Size
(Btyp
, Rsiz
);
4273 Set_Is_Bit_Packed_Array
(Btyp
);
4274 Set_Is_Packed
(Btyp
);
4275 Set_Has_Non_Standard_Rep
(Btyp
);
4277 -- Otherwise give an error message
4281 ("size given for& too small", SZ
, E
);
4282 Error_Msg_N
-- CODEFIX
4283 ("\use explicit pragma Pack "
4284 & "or use pragma Implicit_Packing", SZ
);
4287 elsif RM_Size
(E
) = Num_Elmts
* Rsiz
4288 and then Implicit_Packing
4290 (Rsiz
/ System_Storage_Unit
= 1
4292 Rsiz
/ System_Storage_Unit
= 2
4294 Rsiz
/ System_Storage_Unit
= 4)
4296 -- Not a packed array, but indicate the desired
4297 -- component size, for the back-end.
4299 Set_Component_Size
(Btyp
, Rsiz
);
4305 <<No_Implicit_Packing
>>
4307 -- If ancestor subtype present, freeze that first. Note that this
4308 -- will also get the base type frozen. Need RM reference ???
4310 Atype
:= Ancestor_Subtype
(E
);
4312 if Present
(Atype
) then
4313 Freeze_And_Append
(Atype
, N
, Result
);
4315 -- No ancestor subtype present
4318 -- See if we have a nearest ancestor that has a predicate.
4319 -- That catches the case of derived type with a predicate.
4320 -- Need RM reference here ???
4322 Atype
:= Nearest_Ancestor
(E
);
4324 if Present
(Atype
) and then Has_Predicates
(Atype
) then
4325 Freeze_And_Append
(Atype
, N
, Result
);
4328 -- Freeze base type before freezing the entity (RM 13.14(15))
4330 if E
/= Base_Type
(E
) then
4331 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
4335 -- A subtype inherits all the type-related representation aspects
4336 -- from its parents (RM 13.1(8)).
4338 Inherit_Aspects_At_Freeze_Point
(E
);
4340 -- For a derived type, freeze its parent type first (RM 13.14(15))
4342 elsif Is_Derived_Type
(E
) then
4343 Freeze_And_Append
(Etype
(E
), N
, Result
);
4344 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
4346 -- A derived type inherits each type-related representation aspect
4347 -- of its parent type that was directly specified before the
4348 -- declaration of the derived type (RM 13.1(15)).
4350 Inherit_Aspects_At_Freeze_Point
(E
);
4355 if Is_Array_Type
(E
) then
4356 Freeze_Array_Type
(E
);
4358 -- For a class-wide type, the corresponding specific type is
4359 -- frozen as well (RM 13.14(15))
4361 elsif Is_Class_Wide_Type
(E
) then
4362 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
4364 -- If the base type of the class-wide type is still incomplete,
4365 -- the class-wide remains unfrozen as well. This is legal when
4366 -- E is the formal of a primitive operation of some other type
4367 -- which is being frozen.
4369 if not Is_Frozen
(Root_Type
(E
)) then
4370 Set_Is_Frozen
(E
, False);
4374 -- The equivalent type associated with a class-wide subtype needs
4375 -- to be frozen to ensure that its layout is done.
4377 if Ekind
(E
) = E_Class_Wide_Subtype
4378 and then Present
(Equivalent_Type
(E
))
4380 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
4383 -- Generate an itype reference for a library-level class-wide type
4384 -- at the freeze point. Otherwise the first explicit reference to
4385 -- the type may appear in an inner scope which will be rejected by
4389 and then Is_Compilation_Unit
(Scope
(E
))
4392 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
4397 -- From a gigi point of view, a class-wide subtype derives
4398 -- from its record equivalent type. As a result, the itype
4399 -- reference must appear after the freeze node of the
4400 -- equivalent type or gigi will reject the reference.
4402 if Ekind
(E
) = E_Class_Wide_Subtype
4403 and then Present
(Equivalent_Type
(E
))
4405 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
4407 Add_To_Result
(Ref
);
4412 -- For a record type or record subtype, freeze all component types
4413 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
4414 -- using Is_Record_Type, because we don't want to attempt the freeze
4415 -- for the case of a private type with record extension (we will do
4416 -- that later when the full type is frozen).
4418 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
)
4419 and then not Is_Generic_Unit
(Scope
(E
))
4421 Freeze_Record_Type
(E
);
4423 -- For a concurrent type, freeze corresponding record type. This
4424 -- does not correspond to any specific rule in the RM, but the
4425 -- record type is essentially part of the concurrent type.
4426 -- Freeze as well all local entities. This includes record types
4427 -- created for entry parameter blocks, and whatever local entities
4428 -- may appear in the private part.
4430 elsif Is_Concurrent_Type
(E
) then
4431 if Present
(Corresponding_Record_Type
(E
)) then
4433 (Corresponding_Record_Type
(E
), N
, Result
);
4436 Comp
:= First_Entity
(E
);
4437 while Present
(Comp
) loop
4438 if Is_Type
(Comp
) then
4439 Freeze_And_Append
(Comp
, N
, Result
);
4441 elsif (Ekind
(Comp
)) /= E_Function
then
4442 if Is_Itype
(Etype
(Comp
))
4443 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
4445 Undelay_Type
(Etype
(Comp
));
4448 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
4454 -- Private types are required to point to the same freeze node as
4455 -- their corresponding full views. The freeze node itself has to
4456 -- point to the partial view of the entity (because from the partial
4457 -- view, we can retrieve the full view, but not the reverse).
4458 -- However, in order to freeze correctly, we need to freeze the full
4459 -- view. If we are freezing at the end of a scope (or within the
4460 -- scope of the private type), the partial and full views will have
4461 -- been swapped, the full view appears first in the entity chain and
4462 -- the swapping mechanism ensures that the pointers are properly set
4465 -- If we encounter the partial view before the full view (e.g. when
4466 -- freezing from another scope), we freeze the full view, and then
4467 -- set the pointers appropriately since we cannot rely on swapping to
4468 -- fix things up (subtypes in an outer scope might not get swapped).
4470 elsif Is_Incomplete_Or_Private_Type
(E
)
4471 and then not Is_Generic_Type
(E
)
4473 -- The construction of the dispatch table associated with library
4474 -- level tagged types forces freezing of all the primitives of the
4475 -- type, which may cause premature freezing of the partial view.
4479 -- type T is tagged private;
4480 -- type DT is new T with private;
4481 -- procedure Prim (X : in out T; Y : in out DT'Class);
4483 -- type T is tagged null record;
4485 -- type DT is new T with null record;
4488 -- In this case the type will be frozen later by the usual
4489 -- mechanism: an object declaration, an instantiation, or the
4490 -- end of a declarative part.
4492 if Is_Library_Level_Tagged_Type
(E
)
4493 and then not Present
(Full_View
(E
))
4495 Set_Is_Frozen
(E
, False);
4498 -- Case of full view present
4500 elsif Present
(Full_View
(E
)) then
4502 -- If full view has already been frozen, then no further
4503 -- processing is required
4505 if Is_Frozen
(Full_View
(E
)) then
4506 Set_Has_Delayed_Freeze
(E
, False);
4507 Set_Freeze_Node
(E
, Empty
);
4508 Check_Debug_Info_Needed
(E
);
4510 -- Otherwise freeze full view and patch the pointers so that
4511 -- the freeze node will elaborate both views in the back-end.
4515 Full
: constant Entity_Id
:= Full_View
(E
);
4518 if Is_Private_Type
(Full
)
4519 and then Present
(Underlying_Full_View
(Full
))
4522 (Underlying_Full_View
(Full
), N
, Result
);
4525 Freeze_And_Append
(Full
, N
, Result
);
4527 if Has_Delayed_Freeze
(E
) then
4528 F_Node
:= Freeze_Node
(Full
);
4530 if Present
(F_Node
) then
4531 Set_Freeze_Node
(E
, F_Node
);
4532 Set_Entity
(F_Node
, E
);
4535 -- {Incomplete,Private}_Subtypes with Full_Views
4536 -- constrained by discriminants.
4538 Set_Has_Delayed_Freeze
(E
, False);
4539 Set_Freeze_Node
(E
, Empty
);
4544 Check_Debug_Info_Needed
(E
);
4547 -- AI-117 requires that the convention of a partial view be the
4548 -- same as the convention of the full view. Note that this is a
4549 -- recognized breach of privacy, but it's essential for logical
4550 -- consistency of representation, and the lack of a rule in
4551 -- RM95 was an oversight.
4553 Set_Convention
(E
, Convention
(Full_View
(E
)));
4555 Set_Size_Known_At_Compile_Time
(E
,
4556 Size_Known_At_Compile_Time
(Full_View
(E
)));
4558 -- Size information is copied from the full view to the
4559 -- incomplete or private view for consistency.
4561 -- We skip this is the full view is not a type. This is very
4562 -- strange of course, and can only happen as a result of
4563 -- certain illegalities, such as a premature attempt to derive
4564 -- from an incomplete type.
4566 if Is_Type
(Full_View
(E
)) then
4567 Set_Size_Info
(E
, Full_View
(E
));
4568 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
4573 -- Case of no full view present. If entity is derived or subtype,
4574 -- it is safe to freeze, correctness depends on the frozen status
4575 -- of parent. Otherwise it is either premature usage, or a Taft
4576 -- amendment type, so diagnosis is at the point of use and the
4577 -- type might be frozen later.
4579 elsif E
/= Base_Type
(E
)
4580 or else Is_Derived_Type
(E
)
4585 Set_Is_Frozen
(E
, False);
4589 -- For access subprogram, freeze types of all formals, the return
4590 -- type was already frozen, since it is the Etype of the function.
4591 -- Formal types can be tagged Taft amendment types, but otherwise
4592 -- they cannot be incomplete.
4594 elsif Ekind
(E
) = E_Subprogram_Type
then
4595 Formal
:= First_Formal
(E
);
4596 while Present
(Formal
) loop
4597 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
4598 and then No
(Full_View
(Etype
(Formal
)))
4599 and then not Is_Value_Type
(Etype
(Formal
))
4601 if Is_Tagged_Type
(Etype
(Formal
)) then
4604 -- AI05-151: Incomplete types are allowed in access to
4605 -- subprogram specifications.
4607 elsif Ada_Version
< Ada_2012
then
4609 ("invalid use of incomplete type&", E
, Etype
(Formal
));
4613 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
4614 Next_Formal
(Formal
);
4617 Freeze_Subprogram
(E
);
4619 -- For access to a protected subprogram, freeze the equivalent type
4620 -- (however this is not set if we are not generating code or if this
4621 -- is an anonymous type used just for resolution).
4623 elsif Is_Access_Protected_Subprogram_Type
(E
) then
4624 if Present
(Equivalent_Type
(E
)) then
4625 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
4629 -- Generic types are never seen by the back-end, and are also not
4630 -- processed by the expander (since the expander is turned off for
4631 -- generic processing), so we never need freeze nodes for them.
4633 if Is_Generic_Type
(E
) then
4637 -- Some special processing for non-generic types to complete
4638 -- representation details not known till the freeze point.
4640 if Is_Fixed_Point_Type
(E
) then
4641 Freeze_Fixed_Point_Type
(E
);
4643 -- Some error checks required for ordinary fixed-point type. Defer
4644 -- these till the freeze-point since we need the small and range
4645 -- values. We only do these checks for base types
4647 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
4648 if Small_Value
(E
) < Ureal_2_M_80
then
4649 Error_Msg_Name_1
:= Name_Small
;
4651 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
4653 elsif Small_Value
(E
) > Ureal_2_80
then
4654 Error_Msg_Name_1
:= Name_Small
;
4656 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
4659 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
4660 Error_Msg_Name_1
:= Name_First
;
4662 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
4665 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
4666 Error_Msg_Name_1
:= Name_Last
;
4668 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
4672 elsif Is_Enumeration_Type
(E
) then
4673 Freeze_Enumeration_Type
(E
);
4675 elsif Is_Integer_Type
(E
) then
4676 Adjust_Esize_For_Alignment
(E
);
4678 if Is_Modular_Integer_Type
(E
)
4679 and then Warn_On_Suspicious_Modulus_Value
4681 Check_Suspicious_Modulus
(E
);
4684 elsif Is_Access_Type
(E
)
4685 and then not Is_Access_Subprogram_Type
(E
)
4687 -- If a pragma Default_Storage_Pool applies, and this type has no
4688 -- Storage_Pool or Storage_Size clause (which must have occurred
4689 -- before the freezing point), then use the default. This applies
4690 -- only to base types.
4692 -- None of this applies to access to subprograms, for which there
4693 -- are clearly no pools.
4695 if Present
(Default_Pool
)
4696 and then Is_Base_Type
(E
)
4697 and then not Has_Storage_Size_Clause
(E
)
4698 and then No
(Associated_Storage_Pool
(E
))
4700 -- Case of pragma Default_Storage_Pool (null)
4702 if Nkind
(Default_Pool
) = N_Null
then
4703 Set_No_Pool_Assigned
(E
);
4705 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
4708 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
4712 -- Check restriction for standard storage pool
4714 if No
(Associated_Storage_Pool
(E
)) then
4715 Check_Restriction
(No_Standard_Storage_Pools
, E
);
4718 -- Deal with error message for pure access type. This is not an
4719 -- error in Ada 2005 if there is no pool (see AI-366).
4721 if Is_Pure_Unit_Access_Type
(E
)
4722 and then (Ada_Version
< Ada_2005
4723 or else not No_Pool_Assigned
(E
))
4724 and then not Is_Generic_Unit
(Scope
(E
))
4726 Error_Msg_N
("named access type not allowed in pure unit", E
);
4728 if Ada_Version
>= Ada_2005
then
4730 ("\would be legal if Storage_Size of 0 given??", E
);
4732 elsif No_Pool_Assigned
(E
) then
4734 ("\would be legal in Ada 2005??", E
);
4738 ("\would be legal in Ada 2005 if "
4739 & "Storage_Size of 0 given??", E
);
4744 -- Case of composite types
4746 if Is_Composite_Type
(E
) then
4748 -- AI-117 requires that all new primitives of a tagged type must
4749 -- inherit the convention of the full view of the type. Inherited
4750 -- and overriding operations are defined to inherit the convention
4751 -- of their parent or overridden subprogram (also specified in
4752 -- AI-117), which will have occurred earlier (in Derive_Subprogram
4753 -- and New_Overloaded_Entity). Here we set the convention of
4754 -- primitives that are still convention Ada, which will ensure
4755 -- that any new primitives inherit the type's convention. Class-
4756 -- wide types can have a foreign convention inherited from their
4757 -- specific type, but are excluded from this since they don't have
4758 -- any associated primitives.
4760 if Is_Tagged_Type
(E
)
4761 and then not Is_Class_Wide_Type
(E
)
4762 and then Convention
(E
) /= Convention_Ada
4765 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
4769 Prim
:= First_Elmt
(Prim_List
);
4770 while Present
(Prim
) loop
4771 if Convention
(Node
(Prim
)) = Convention_Ada
then
4772 Set_Convention
(Node
(Prim
), Convention
(E
));
4780 -- If the type is a simple storage pool type, then this is where
4781 -- we attempt to locate and validate its Allocate, Deallocate, and
4782 -- Storage_Size operations (the first is required, and the latter
4783 -- two are optional). We also verify that the full type for a
4784 -- private type is allowed to be a simple storage pool type.
4786 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
4787 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
4789 -- If the type is marked Has_Private_Declaration, then this is
4790 -- a full type for a private type that was specified with the
4791 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
4792 -- pragma is allowed for the full type (for example, it can't
4793 -- be an array type, or a nonlimited record type).
4795 if Has_Private_Declaration
(E
) then
4796 if (not Is_Record_Type
(E
)
4797 or else not Is_Limited_View
(E
))
4798 and then not Is_Private_Type
(E
)
4800 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
4802 ("pragma% can only apply to full type that is an " &
4803 "explicitly limited type", E
);
4807 Validate_Simple_Pool_Ops
: declare
4808 Pool_Type
: Entity_Id
renames E
;
4809 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
4810 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
4812 procedure Validate_Simple_Pool_Op_Formal
4813 (Pool_Op
: Entity_Id
;
4814 Pool_Op_Formal
: in out Entity_Id
;
4815 Expected_Mode
: Formal_Kind
;
4816 Expected_Type
: Entity_Id
;
4817 Formal_Name
: String;
4818 OK_Formal
: in out Boolean);
4819 -- Validate one formal Pool_Op_Formal of the candidate pool
4820 -- operation Pool_Op. The formal must be of Expected_Type
4821 -- and have mode Expected_Mode. OK_Formal will be set to
4822 -- False if the formal doesn't match. If OK_Formal is False
4823 -- on entry, then the formal will effectively be ignored
4824 -- (because validation of the pool op has already failed).
4825 -- Upon return, Pool_Op_Formal will be updated to the next
4828 procedure Validate_Simple_Pool_Operation
(Op_Name
: Name_Id
);
4829 -- Search for and validate a simple pool operation with the
4830 -- name Op_Name. If the name is Allocate, then there must be
4831 -- exactly one such primitive operation for the simple pool
4832 -- type. If the name is Deallocate or Storage_Size, then
4833 -- there can be at most one such primitive operation. The
4834 -- profile of the located primitive must conform to what
4835 -- is expected for each operation.
4837 ------------------------------------
4838 -- Validate_Simple_Pool_Op_Formal --
4839 ------------------------------------
4841 procedure Validate_Simple_Pool_Op_Formal
4842 (Pool_Op
: Entity_Id
;
4843 Pool_Op_Formal
: in out Entity_Id
;
4844 Expected_Mode
: Formal_Kind
;
4845 Expected_Type
: Entity_Id
;
4846 Formal_Name
: String;
4847 OK_Formal
: in out Boolean)
4850 -- If OK_Formal is False on entry, then simply ignore
4851 -- the formal, because an earlier formal has already
4854 if not OK_Formal
then
4857 -- If no formal is passed in, then issue an error for a
4860 elsif not Present
(Pool_Op_Formal
) then
4862 ("simple storage pool op missing formal " &
4863 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
4869 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
4871 -- If the pool type was expected for this formal, then
4872 -- this will not be considered a candidate operation
4873 -- for the simple pool, so we unset OK_Formal so that
4874 -- the op and any later formals will be ignored.
4876 if Expected_Type
= Pool_Type
then
4883 ("wrong type for formal " & Formal_Name
&
4884 " of simple storage pool op; expected type&",
4885 Pool_Op_Formal
, Expected_Type
);
4889 -- Issue error if formal's mode is not the expected one
4891 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
4893 ("wrong mode for formal of simple storage pool op",
4897 -- Advance to the next formal
4899 Next_Formal
(Pool_Op_Formal
);
4900 end Validate_Simple_Pool_Op_Formal
;
4902 ------------------------------------
4903 -- Validate_Simple_Pool_Operation --
4904 ------------------------------------
4906 procedure Validate_Simple_Pool_Operation
4910 Found_Op
: Entity_Id
:= Empty
;
4916 (Nam_In
(Op_Name
, Name_Allocate
,
4918 Name_Storage_Size
));
4920 Error_Msg_Name_1
:= Op_Name
;
4922 -- For each homonym declared immediately in the scope
4923 -- of the simple storage pool type, determine whether
4924 -- the homonym is an operation of the pool type, and,
4925 -- if so, check that its profile is as expected for
4926 -- a simple pool operation of that name.
4928 Op
:= Get_Name_Entity_Id
(Op_Name
);
4929 while Present
(Op
) loop
4930 if Ekind_In
(Op
, E_Function
, E_Procedure
)
4931 and then Scope
(Op
) = Current_Scope
4933 Formal
:= First_Entity
(Op
);
4937 -- The first parameter must be of the pool type
4938 -- in order for the operation to qualify.
4940 if Op_Name
= Name_Storage_Size
then
4941 Validate_Simple_Pool_Op_Formal
4942 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
4945 Validate_Simple_Pool_Op_Formal
4946 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
4950 -- If another operation with this name has already
4951 -- been located for the type, then flag an error,
4952 -- since we only allow the type to have a single
4955 if Present
(Found_Op
) and then Is_OK
then
4957 ("only one % operation allowed for " &
4958 "simple storage pool type&", Op
, Pool_Type
);
4961 -- In the case of Allocate and Deallocate, a formal
4962 -- of type System.Address is required.
4964 if Op_Name
= Name_Allocate
then
4965 Validate_Simple_Pool_Op_Formal
4966 (Op
, Formal
, E_Out_Parameter
,
4967 Address_Type
, "Storage_Address", Is_OK
);
4969 elsif Op_Name
= Name_Deallocate
then
4970 Validate_Simple_Pool_Op_Formal
4971 (Op
, Formal
, E_In_Parameter
,
4972 Address_Type
, "Storage_Address", Is_OK
);
4975 -- In the case of Allocate and Deallocate, formals
4976 -- of type Storage_Count are required as the third
4977 -- and fourth parameters.
4979 if Op_Name
/= Name_Storage_Size
then
4980 Validate_Simple_Pool_Op_Formal
4981 (Op
, Formal
, E_In_Parameter
,
4982 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
4983 Validate_Simple_Pool_Op_Formal
4984 (Op
, Formal
, E_In_Parameter
,
4985 Stg_Cnt_Type
, "Alignment", Is_OK
);
4988 -- If no mismatched formals have been found (Is_OK)
4989 -- and no excess formals are present, then this
4990 -- operation has been validated, so record it.
4992 if not Present
(Formal
) and then Is_OK
then
5000 -- There must be a valid Allocate operation for the type,
5001 -- so issue an error if none was found.
5003 if Op_Name
= Name_Allocate
5004 and then not Present
(Found_Op
)
5006 Error_Msg_N
("missing % operation for simple " &
5007 "storage pool type", Pool_Type
);
5009 elsif Present
(Found_Op
) then
5011 -- Simple pool operations can't be abstract
5013 if Is_Abstract_Subprogram
(Found_Op
) then
5015 ("simple storage pool operation must not be " &
5016 "abstract", Found_Op
);
5019 -- The Storage_Size operation must be a function with
5020 -- Storage_Count as its result type.
5022 if Op_Name
= Name_Storage_Size
then
5023 if Ekind
(Found_Op
) = E_Procedure
then
5025 ("% operation must be a function", Found_Op
);
5027 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
5029 ("wrong result type for%, expected type&",
5030 Found_Op
, Stg_Cnt_Type
);
5033 -- Allocate and Deallocate must be procedures
5035 elsif Ekind
(Found_Op
) = E_Function
then
5037 ("% operation must be a procedure", Found_Op
);
5040 end Validate_Simple_Pool_Operation
;
5042 -- Start of processing for Validate_Simple_Pool_Ops
5045 Validate_Simple_Pool_Operation
(Name_Allocate
);
5046 Validate_Simple_Pool_Operation
(Name_Deallocate
);
5047 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
5048 end Validate_Simple_Pool_Ops
;
5052 -- Now that all types from which E may depend are frozen, see if the
5053 -- size is known at compile time, if it must be unsigned, or if
5054 -- strict alignment is required
5056 Check_Compile_Time_Size
(E
);
5057 Check_Unsigned_Type
(E
);
5059 if Base_Type
(E
) = E
then
5060 Check_Strict_Alignment
(E
);
5063 -- Do not allow a size clause for a type which does not have a size
5064 -- that is known at compile time
5066 if Has_Size_Clause
(E
)
5067 and then not Size_Known_At_Compile_Time
(E
)
5069 -- Suppress this message if errors posted on E, even if we are
5070 -- in all errors mode, since this is often a junk message
5072 if not Error_Posted
(E
) then
5074 ("size clause not allowed for variable length type",
5079 -- Now we set/verify the representation information, in particular
5080 -- the size and alignment values. This processing is not required for
5081 -- generic types, since generic types do not play any part in code
5082 -- generation, and so the size and alignment values for such types
5083 -- are irrelevant. Ditto for types declared within a generic unit,
5084 -- which may have components that depend on generic parameters, and
5085 -- that will be recreated in an instance.
5087 if Inside_A_Generic
then
5090 -- Otherwise we call the layout procedure
5096 -- If this is an access to subprogram whose designated type is itself
5097 -- a subprogram type, the return type of this anonymous subprogram
5098 -- type must be decorated as well.
5100 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
5101 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
5103 Layout_Type
(Etype
(Designated_Type
(E
)));
5106 -- If the type has a Defaut_Value/Default_Component_Value aspect,
5107 -- this is where we analye the expression (after the type is frozen,
5108 -- since in the case of Default_Value, we are analyzing with the
5109 -- type itself, and we treat Default_Component_Value similarly for
5110 -- the sake of uniformity).
5112 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
5119 if Is_Scalar_Type
(E
) then
5120 Nam
:= Name_Default_Value
;
5122 Exp
:= Default_Aspect_Value
(Typ
);
5124 Nam
:= Name_Default_Component_Value
;
5125 Typ
:= Component_Type
(E
);
5126 Exp
:= Default_Aspect_Component_Value
(E
);
5129 Analyze_And_Resolve
(Exp
, Typ
);
5131 if Etype
(Exp
) /= Any_Type
then
5132 if not Is_Static_Expression
(Exp
) then
5133 Error_Msg_Name_1
:= Nam
;
5134 Flag_Non_Static_Expr
5135 ("aspect% requires static expression", Exp
);
5141 -- End of freeze processing for type entities
5144 -- Here is where we logically freeze the current entity. If it has a
5145 -- freeze node, then this is the point at which the freeze node is
5146 -- linked into the result list.
5148 if Has_Delayed_Freeze
(E
) then
5150 -- If a freeze node is already allocated, use it, otherwise allocate
5151 -- a new one. The preallocation happens in the case of anonymous base
5152 -- types, where we preallocate so that we can set First_Subtype_Link.
5153 -- Note that we reset the Sloc to the current freeze location.
5155 if Present
(Freeze_Node
(E
)) then
5156 F_Node
:= Freeze_Node
(E
);
5157 Set_Sloc
(F_Node
, Loc
);
5160 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
5161 Set_Freeze_Node
(E
, F_Node
);
5162 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
5163 Set_TSS_Elist
(F_Node
, No_Elist
);
5164 Set_Actions
(F_Node
, No_List
);
5167 Set_Entity
(F_Node
, E
);
5168 Add_To_Result
(F_Node
);
5170 -- A final pass over record types with discriminants. If the type
5171 -- has an incomplete declaration, there may be constrained access
5172 -- subtypes declared elsewhere, which do not depend on the discrimi-
5173 -- nants of the type, and which are used as component types (i.e.
5174 -- the full view is a recursive type). The designated types of these
5175 -- subtypes can only be elaborated after the type itself, and they
5176 -- need an itype reference.
5178 if Ekind
(E
) = E_Record_Type
5179 and then Has_Discriminants
(E
)
5187 Comp
:= First_Component
(E
);
5188 while Present
(Comp
) loop
5189 Typ
:= Etype
(Comp
);
5191 if Ekind
(Comp
) = E_Component
5192 and then Is_Access_Type
(Typ
)
5193 and then Scope
(Typ
) /= E
5194 and then Base_Type
(Designated_Type
(Typ
)) = E
5195 and then Is_Itype
(Designated_Type
(Typ
))
5197 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
5198 Set_Itype
(IR
, Designated_Type
(Typ
));
5199 Append
(IR
, Result
);
5202 Next_Component
(Comp
);
5208 -- When a type is frozen, the first subtype of the type is frozen as
5209 -- well (RM 13.14(15)). This has to be done after freezing the type,
5210 -- since obviously the first subtype depends on its own base type.
5213 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
5215 -- If we just froze a tagged non-class wide record, then freeze the
5216 -- corresponding class-wide type. This must be done after the tagged
5217 -- type itself is frozen, because the class-wide type refers to the
5218 -- tagged type which generates the class.
5220 if Is_Tagged_Type
(E
)
5221 and then not Is_Class_Wide_Type
(E
)
5222 and then Present
(Class_Wide_Type
(E
))
5224 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
5228 Check_Debug_Info_Needed
(E
);
5230 -- Special handling for subprograms
5232 if Is_Subprogram
(E
) then
5234 -- If subprogram has address clause then reset Is_Public flag, since
5235 -- we do not want the backend to generate external references.
5237 if Present
(Address_Clause
(E
))
5238 and then not Is_Library_Level_Entity
(E
)
5240 Set_Is_Public
(E
, False);
5247 -----------------------------
5248 -- Freeze_Enumeration_Type --
5249 -----------------------------
5251 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
5253 -- By default, if no size clause is present, an enumeration type with
5254 -- Convention C is assumed to interface to a C enum, and has integer
5255 -- size. This applies to types. For subtypes, verify that its base
5256 -- type has no size clause either. Treat other foreign conventions
5257 -- in the same way, and also make sure alignment is set right.
5259 if Has_Foreign_Convention
(Typ
)
5260 and then not Has_Size_Clause
(Typ
)
5261 and then not Has_Size_Clause
(Base_Type
(Typ
))
5262 and then Esize
(Typ
) < Standard_Integer_Size
5264 Init_Esize
(Typ
, Standard_Integer_Size
);
5265 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
5268 -- If the enumeration type interfaces to C, and it has a size clause
5269 -- that specifies less than int size, it warrants a warning. The
5270 -- user may intend the C type to be an enum or a char, so this is
5271 -- not by itself an error that the Ada compiler can detect, but it
5272 -- it is a worth a heads-up. For Boolean and Character types we
5273 -- assume that the programmer has the proper C type in mind.
5275 if Convention
(Typ
) = Convention_C
5276 and then Has_Size_Clause
(Typ
)
5277 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
5278 and then not Is_Boolean_Type
(Typ
)
5279 and then not Is_Character_Type
(Typ
)
5282 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
5285 Adjust_Esize_For_Alignment
(Typ
);
5287 end Freeze_Enumeration_Type
;
5289 -----------------------
5290 -- Freeze_Expression --
5291 -----------------------
5293 procedure Freeze_Expression
(N
: Node_Id
) is
5294 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
5297 Desig_Typ
: Entity_Id
;
5301 Freeze_Outside
: Boolean := False;
5302 -- This flag is set true if the entity must be frozen outside the
5303 -- current subprogram. This happens in the case of expander generated
5304 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
5305 -- not freeze all entities like other bodies, but which nevertheless
5306 -- may reference entities that have to be frozen before the body and
5307 -- obviously cannot be frozen inside the body.
5309 function In_Exp_Body
(N
: Node_Id
) return Boolean;
5310 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
5311 -- it is the handled statement sequence of an expander-generated
5312 -- subprogram (init proc, stream subprogram, or renaming as body).
5313 -- If so, this is not a freezing context.
5319 function In_Exp_Body
(N
: Node_Id
) return Boolean is
5324 if Nkind
(N
) = N_Subprogram_Body
then
5330 if Nkind
(P
) /= N_Subprogram_Body
then
5334 Id
:= Defining_Unit_Name
(Specification
(P
));
5336 -- Following complex conditional could use comments ???
5338 if Nkind
(Id
) = N_Defining_Identifier
5339 and then (Is_Init_Proc
(Id
)
5340 or else Is_TSS
(Id
, TSS_Stream_Input
)
5341 or else Is_TSS
(Id
, TSS_Stream_Output
)
5342 or else Is_TSS
(Id
, TSS_Stream_Read
)
5343 or else Is_TSS
(Id
, TSS_Stream_Write
)
5344 or else Nkind_In
(Original_Node
(P
),
5345 N_Subprogram_Renaming_Declaration
,
5346 N_Expression_Function
))
5355 -- Start of processing for Freeze_Expression
5358 -- Immediate return if freezing is inhibited. This flag is set by the
5359 -- analyzer to stop freezing on generated expressions that would cause
5360 -- freezing if they were in the source program, but which are not
5361 -- supposed to freeze, since they are created.
5363 if Must_Not_Freeze
(N
) then
5367 -- If expression is non-static, then it does not freeze in a default
5368 -- expression, see section "Handling of Default Expressions" in the
5369 -- spec of package Sem for further details. Note that we have to make
5370 -- sure that we actually have a real expression (if we have a subtype
5371 -- indication, we can't test Is_Static_Expression!) However, we exclude
5372 -- the case of the prefix of an attribute of a static scalar subtype
5373 -- from this early return, because static subtype attributes should
5374 -- always cause freezing, even in default expressions, but the attribute
5375 -- may not have been marked as static yet (because in Resolve_Attribute,
5376 -- the call to Eval_Attribute follows the call of Freeze_Expression on
5380 and then Nkind
(N
) in N_Subexpr
5381 and then not Is_Static_Expression
(N
)
5382 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
5383 or else not (Is_Entity_Name
(N
)
5384 and then Is_Type
(Entity
(N
))
5385 and then Is_Static_Subtype
(Entity
(N
))))
5390 -- Freeze type of expression if not frozen already
5394 if Nkind
(N
) in N_Has_Etype
then
5395 if not Is_Frozen
(Etype
(N
)) then
5398 -- Base type may be an derived numeric type that is frozen at
5399 -- the point of declaration, but first_subtype is still unfrozen.
5401 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
5402 Typ
:= First_Subtype
(Etype
(N
));
5406 -- For entity name, freeze entity if not frozen already. A special
5407 -- exception occurs for an identifier that did not come from source.
5408 -- We don't let such identifiers freeze a non-internal entity, i.e.
5409 -- an entity that did come from source, since such an identifier was
5410 -- generated by the expander, and cannot have any semantic effect on
5411 -- the freezing semantics. For example, this stops the parameter of
5412 -- an initialization procedure from freezing the variable.
5414 if Is_Entity_Name
(N
)
5415 and then not Is_Frozen
(Entity
(N
))
5416 and then (Nkind
(N
) /= N_Identifier
5417 or else Comes_From_Source
(N
)
5418 or else not Comes_From_Source
(Entity
(N
)))
5425 -- For an allocator freeze designated type if not frozen already
5427 -- For an aggregate whose component type is an access type, freeze the
5428 -- designated type now, so that its freeze does not appear within the
5429 -- loop that might be created in the expansion of the aggregate. If the
5430 -- designated type is a private type without full view, the expression
5431 -- cannot contain an allocator, so the type is not frozen.
5433 -- For a function, we freeze the entity when the subprogram declaration
5434 -- is frozen, but a function call may appear in an initialization proc.
5435 -- before the declaration is frozen. We need to generate the extra
5436 -- formals, if any, to ensure that the expansion of the call includes
5437 -- the proper actuals. This only applies to Ada subprograms, not to
5444 Desig_Typ
:= Designated_Type
(Etype
(N
));
5447 if Is_Array_Type
(Etype
(N
))
5448 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
5450 Desig_Typ
:= Designated_Type
(Component_Type
(Etype
(N
)));
5453 when N_Selected_Component |
5454 N_Indexed_Component |
5457 if Is_Access_Type
(Etype
(Prefix
(N
))) then
5458 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
5461 when N_Identifier
=>
5463 and then Ekind
(Nam
) = E_Function
5464 and then Nkind
(Parent
(N
)) = N_Function_Call
5465 and then Convention
(Nam
) = Convention_Ada
5467 Create_Extra_Formals
(Nam
);
5474 if Desig_Typ
/= Empty
5475 and then (Is_Frozen
(Desig_Typ
)
5476 or else (not Is_Fully_Defined
(Desig_Typ
)))
5481 -- All done if nothing needs freezing
5485 and then No
(Desig_Typ
)
5490 -- Loop for looking at the right place to insert the freeze nodes,
5491 -- exiting from the loop when it is appropriate to insert the freeze
5492 -- node before the current node P.
5494 -- Also checks some special exceptions to the freezing rules. These
5495 -- cases result in a direct return, bypassing the freeze action.
5499 Parent_P
:= Parent
(P
);
5501 -- If we don't have a parent, then we are not in a well-formed tree.
5502 -- This is an unusual case, but there are some legitimate situations
5503 -- in which this occurs, notably when the expressions in the range of
5504 -- a type declaration are resolved. We simply ignore the freeze
5505 -- request in this case. Is this right ???
5507 if No
(Parent_P
) then
5511 -- See if we have got to an appropriate point in the tree
5513 case Nkind
(Parent_P
) is
5515 -- A special test for the exception of (RM 13.14(8)) for the case
5516 -- of per-object expressions (RM 3.8(18)) occurring in component
5517 -- definition or a discrete subtype definition. Note that we test
5518 -- for a component declaration which includes both cases we are
5519 -- interested in, and furthermore the tree does not have explicit
5520 -- nodes for either of these two constructs.
5522 when N_Component_Declaration
=>
5524 -- The case we want to test for here is an identifier that is
5525 -- a per-object expression, this is either a discriminant that
5526 -- appears in a context other than the component declaration
5527 -- or it is a reference to the type of the enclosing construct.
5529 -- For either of these cases, we skip the freezing
5531 if not In_Spec_Expression
5532 and then Nkind
(N
) = N_Identifier
5533 and then (Present
(Entity
(N
)))
5535 -- We recognize the discriminant case by just looking for
5536 -- a reference to a discriminant. It can only be one for
5537 -- the enclosing construct. Skip freezing in this case.
5539 if Ekind
(Entity
(N
)) = E_Discriminant
then
5542 -- For the case of a reference to the enclosing record,
5543 -- (or task or protected type), we look for a type that
5544 -- matches the current scope.
5546 elsif Entity
(N
) = Current_Scope
then
5551 -- If we have an enumeration literal that appears as the choice in
5552 -- the aggregate of an enumeration representation clause, then
5553 -- freezing does not occur (RM 13.14(10)).
5555 when N_Enumeration_Representation_Clause
=>
5557 -- The case we are looking for is an enumeration literal
5559 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
5560 and then Is_Enumeration_Type
(Etype
(N
))
5562 -- If enumeration literal appears directly as the choice,
5563 -- do not freeze (this is the normal non-overloaded case)
5565 if Nkind
(Parent
(N
)) = N_Component_Association
5566 and then First
(Choices
(Parent
(N
))) = N
5570 -- If enumeration literal appears as the name of function
5571 -- which is the choice, then also do not freeze. This
5572 -- happens in the overloaded literal case, where the
5573 -- enumeration literal is temporarily changed to a function
5574 -- call for overloading analysis purposes.
5576 elsif Nkind
(Parent
(N
)) = N_Function_Call
5578 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
5580 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
5586 -- Normally if the parent is a handled sequence of statements,
5587 -- then the current node must be a statement, and that is an
5588 -- appropriate place to insert a freeze node.
5590 when N_Handled_Sequence_Of_Statements
=>
5592 -- An exception occurs when the sequence of statements is for
5593 -- an expander generated body that did not do the usual freeze
5594 -- all operation. In this case we usually want to freeze
5595 -- outside this body, not inside it, and we skip past the
5596 -- subprogram body that we are inside.
5598 if In_Exp_Body
(Parent_P
) then
5600 Subp
: constant Node_Id
:= Parent
(Parent_P
);
5604 -- Freeze the entity only when it is declared inside the
5605 -- body of the expander generated procedure. This case
5606 -- is recognized by the scope of the entity or its type,
5607 -- which is either the spec for some enclosing body, or
5608 -- (in the case of init_procs, for which there are no
5609 -- separate specs) the current scope.
5611 if Nkind
(Subp
) = N_Subprogram_Body
then
5612 Spec
:= Corresponding_Spec
(Subp
);
5614 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
5616 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
5621 and then Scope
(Typ
) = Current_Scope
5622 and then Defining_Entity
(Subp
) = Current_Scope
5628 -- An expression function may act as a completion of
5629 -- a function declaration. As such, it can reference
5630 -- entities declared between the two views:
5633 -- function F return ...;
5635 -- function Hidden return ...;
5636 -- function F return ... is (Hidden); -- 2
5638 -- Refering to the example above, freezing the expression
5639 -- of F (2) would place Hidden's freeze node (1) in the
5640 -- wrong place. Avoid explicit freezing and let the usual
5641 -- scenarios do the job - for example, reaching the end
5642 -- of the private declarations.
5644 if Nkind
(Original_Node
(Subp
)) =
5645 N_Expression_Function
5649 -- Freeze outside the body
5652 Parent_P
:= Parent
(Parent_P
);
5653 Freeze_Outside
:= True;
5657 -- Here if normal case where we are in handled statement
5658 -- sequence and want to do the insertion right there.
5664 -- If parent is a body or a spec or a block, then the current node
5665 -- is a statement or declaration and we can insert the freeze node
5668 when N_Block_Statement |
5671 N_Package_Specification |
5674 N_Task_Body
=> exit;
5676 -- The expander is allowed to define types in any statements list,
5677 -- so any of the following parent nodes also mark a freezing point
5678 -- if the actual node is in a list of statements or declarations.
5680 when N_Abortable_Part |
5681 N_Accept_Alternative |
5683 N_Case_Statement_Alternative |
5684 N_Compilation_Unit_Aux |
5685 N_Conditional_Entry_Call |
5686 N_Delay_Alternative |
5688 N_Entry_Call_Alternative |
5689 N_Exception_Handler |
5690 N_Extended_Return_Statement |
5694 N_Selective_Accept |
5695 N_Triggering_Alternative
=>
5697 exit when Is_List_Member
(P
);
5699 -- Note: The N_Loop_Statement is a special case. A type that
5700 -- appears in the source can never be frozen in a loop (this
5701 -- occurs only because of a loop expanded by the expander), so we
5702 -- keep on going. Otherwise we terminate the search. Same is true
5703 -- of any entity which comes from source. (if they have predefined
5704 -- type, that type does not appear to come from source, but the
5705 -- entity should not be frozen here).
5707 when N_Loop_Statement
=>
5708 exit when not Comes_From_Source
(Etype
(N
))
5709 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
5711 -- For all other cases, keep looking at parents
5717 -- We fall through the case if we did not yet find the proper
5718 -- place in the free for inserting the freeze node, so climb!
5723 -- If the expression appears in a record or an initialization procedure,
5724 -- the freeze nodes are collected and attached to the current scope, to
5725 -- be inserted and analyzed on exit from the scope, to insure that
5726 -- generated entities appear in the correct scope. If the expression is
5727 -- a default for a discriminant specification, the scope is still void.
5728 -- The expression can also appear in the discriminant part of a private
5729 -- or concurrent type.
5731 -- If the expression appears in a constrained subcomponent of an
5732 -- enclosing record declaration, the freeze nodes must be attached to
5733 -- the outer record type so they can eventually be placed in the
5734 -- enclosing declaration list.
5736 -- The other case requiring this special handling is if we are in a
5737 -- default expression, since in that case we are about to freeze a
5738 -- static type, and the freeze scope needs to be the outer scope, not
5739 -- the scope of the subprogram with the default parameter.
5741 -- For default expressions and other spec expressions in generic units,
5742 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
5743 -- placing them at the proper place, after the generic unit.
5745 if (In_Spec_Exp
and not Inside_A_Generic
)
5746 or else Freeze_Outside
5747 or else (Is_Type
(Current_Scope
)
5748 and then (not Is_Concurrent_Type
(Current_Scope
)
5749 or else not Has_Completion
(Current_Scope
)))
5750 or else Ekind
(Current_Scope
) = E_Void
5753 N
: constant Node_Id
:= Current_Scope
;
5754 Freeze_Nodes
: List_Id
:= No_List
;
5755 Pos
: Int
:= Scope_Stack
.Last
;
5758 if Present
(Desig_Typ
) then
5759 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
5762 if Present
(Typ
) then
5763 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
5766 if Present
(Nam
) then
5767 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
5770 -- The current scope may be that of a constrained component of
5771 -- an enclosing record declaration, or of a loop of an enclosing
5772 -- quantified expression, which is above the current scope in the
5773 -- scope stack. Indeed in the context of a quantified expression,
5774 -- a scope is created and pushed above the current scope in order
5775 -- to emulate the loop-like behavior of the quantified expression.
5776 -- If the expression is within a top-level pragma, as for a pre-
5777 -- condition on a library-level subprogram, nothing to do.
5779 if not Is_Compilation_Unit
(Current_Scope
)
5780 and then (Is_Record_Type
(Scope
(Current_Scope
))
5781 or else Nkind
(Parent
(Current_Scope
)) =
5782 N_Quantified_Expression
)
5787 if Is_Non_Empty_List
(Freeze_Nodes
) then
5788 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
5789 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
5792 Append_List
(Freeze_Nodes
,
5793 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
5801 -- Now we have the right place to do the freezing. First, a special
5802 -- adjustment, if we are in spec-expression analysis mode, these freeze
5803 -- actions must not be thrown away (normally all inserted actions are
5804 -- thrown away in this mode. However, the freeze actions are from static
5805 -- expressions and one of the important reasons we are doing this
5806 -- special analysis is to get these freeze actions. Therefore we turn
5807 -- off the In_Spec_Expression mode to propagate these freeze actions.
5808 -- This also means they get properly analyzed and expanded.
5810 In_Spec_Expression
:= False;
5812 -- Freeze the designated type of an allocator (RM 13.14(13))
5814 if Present
(Desig_Typ
) then
5815 Freeze_Before
(P
, Desig_Typ
);
5818 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
5819 -- the enumeration representation clause exception in the loop above.
5821 if Present
(Typ
) then
5822 Freeze_Before
(P
, Typ
);
5825 -- Freeze name if one is present (RM 13.14(11))
5827 if Present
(Nam
) then
5828 Freeze_Before
(P
, Nam
);
5831 -- Restore In_Spec_Expression flag
5833 In_Spec_Expression
:= In_Spec_Exp
;
5834 end Freeze_Expression
;
5836 -----------------------------
5837 -- Freeze_Fixed_Point_Type --
5838 -----------------------------
5840 -- Certain fixed-point types and subtypes, including implicit base types
5841 -- and declared first subtypes, have not yet set up a range. This is
5842 -- because the range cannot be set until the Small and Size values are
5843 -- known, and these are not known till the type is frozen.
5845 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
5846 -- whose bounds are unanalyzed real literals. This routine will recognize
5847 -- this case, and transform this range node into a properly typed range
5848 -- with properly analyzed and resolved values.
5850 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
5851 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
5852 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
5853 Hi
: constant Node_Id
:= High_Bound
(Rng
);
5854 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
5855 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
5856 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
5857 BHi
: constant Node_Id
:= High_Bound
(Brng
);
5858 Small
: constant Ureal
:= Small_Value
(Typ
);
5865 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
5866 -- Returns size of type with given bounds. Also leaves these
5867 -- bounds set as the current bounds of the Typ.
5873 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
5875 Set_Realval
(Lo
, Lov
);
5876 Set_Realval
(Hi
, Hiv
);
5877 return Minimum_Size
(Typ
);
5880 -- Start of processing for Freeze_Fixed_Point_Type
5883 -- If Esize of a subtype has not previously been set, set it now
5885 if Unknown_Esize
(Typ
) then
5886 Atype
:= Ancestor_Subtype
(Typ
);
5888 if Present
(Atype
) then
5889 Set_Esize
(Typ
, Esize
(Atype
));
5891 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
5895 -- Immediate return if the range is already analyzed. This means that
5896 -- the range is already set, and does not need to be computed by this
5899 if Analyzed
(Rng
) then
5903 -- Immediate return if either of the bounds raises Constraint_Error
5905 if Raises_Constraint_Error
(Lo
)
5906 or else Raises_Constraint_Error
(Hi
)
5911 Loval
:= Realval
(Lo
);
5912 Hival
:= Realval
(Hi
);
5914 -- Ordinary fixed-point case
5916 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
5918 -- For the ordinary fixed-point case, we are allowed to fudge the
5919 -- end-points up or down by small. Generally we prefer to fudge up,
5920 -- i.e. widen the bounds for non-model numbers so that the end points
5921 -- are included. However there are cases in which this cannot be
5922 -- done, and indeed cases in which we may need to narrow the bounds.
5923 -- The following circuit makes the decision.
5925 -- Note: our terminology here is that Incl_EP means that the bounds
5926 -- are widened by Small if necessary to include the end points, and
5927 -- Excl_EP means that the bounds are narrowed by Small to exclude the
5928 -- end-points if this reduces the size.
5930 -- Note that in the Incl case, all we care about is including the
5931 -- end-points. In the Excl case, we want to narrow the bounds as
5932 -- much as permitted by the RM, to give the smallest possible size.
5935 Loval_Incl_EP
: Ureal
;
5936 Hival_Incl_EP
: Ureal
;
5938 Loval_Excl_EP
: Ureal
;
5939 Hival_Excl_EP
: Ureal
;
5945 First_Subt
: Entity_Id
;
5950 -- First step. Base types are required to be symmetrical. Right
5951 -- now, the base type range is a copy of the first subtype range.
5952 -- This will be corrected before we are done, but right away we
5953 -- need to deal with the case where both bounds are non-negative.
5954 -- In this case, we set the low bound to the negative of the high
5955 -- bound, to make sure that the size is computed to include the
5956 -- required sign. Note that we do not need to worry about the
5957 -- case of both bounds negative, because the sign will be dealt
5958 -- with anyway. Furthermore we can't just go making such a bound
5959 -- symmetrical, since in a twos-complement system, there is an
5960 -- extra negative value which could not be accommodated on the
5964 and then not UR_Is_Negative
(Loval
)
5965 and then Hival
> Loval
5968 Set_Realval
(Lo
, Loval
);
5971 -- Compute the fudged bounds. If the number is a model number,
5972 -- then we do nothing to include it, but we are allowed to backoff
5973 -- to the next adjacent model number when we exclude it. If it is
5974 -- not a model number then we straddle the two values with the
5975 -- model numbers on either side.
5977 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
5979 if Loval
= Model_Num
then
5980 Loval_Incl_EP
:= Model_Num
;
5982 Loval_Incl_EP
:= Model_Num
- Small
;
5985 -- The low value excluding the end point is Small greater, but
5986 -- we do not do this exclusion if the low value is positive,
5987 -- since it can't help the size and could actually hurt by
5988 -- crossing the high bound.
5990 if UR_Is_Negative
(Loval_Incl_EP
) then
5991 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
5993 -- If the value went from negative to zero, then we have the
5994 -- case where Loval_Incl_EP is the model number just below
5995 -- zero, so we want to stick to the negative value for the
5996 -- base type to maintain the condition that the size will
5997 -- include signed values.
6000 and then UR_Is_Zero
(Loval_Excl_EP
)
6002 Loval_Excl_EP
:= Loval_Incl_EP
;
6006 Loval_Excl_EP
:= Loval_Incl_EP
;
6009 -- Similar processing for upper bound and high value
6011 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
6013 if Hival
= Model_Num
then
6014 Hival_Incl_EP
:= Model_Num
;
6016 Hival_Incl_EP
:= Model_Num
+ Small
;
6019 if UR_Is_Positive
(Hival_Incl_EP
) then
6020 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
6022 Hival_Excl_EP
:= Hival_Incl_EP
;
6025 -- One further adjustment is needed. In the case of subtypes, we
6026 -- cannot go outside the range of the base type, or we get
6027 -- peculiarities, and the base type range is already set. This
6028 -- only applies to the Incl values, since clearly the Excl values
6029 -- are already as restricted as they are allowed to be.
6032 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
6033 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
6036 -- Get size including and excluding end points
6038 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
6039 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
6041 -- No need to exclude end-points if it does not reduce size
6043 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
6044 Loval_Excl_EP
:= Loval_Incl_EP
;
6047 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
6048 Hival_Excl_EP
:= Hival_Incl_EP
;
6051 -- Now we set the actual size to be used. We want to use the
6052 -- bounds fudged up to include the end-points but only if this
6053 -- can be done without violating a specifically given size
6054 -- size clause or causing an unacceptable increase in size.
6056 -- Case of size clause given
6058 if Has_Size_Clause
(Typ
) then
6060 -- Use the inclusive size only if it is consistent with
6061 -- the explicitly specified size.
6063 if Size_Incl_EP
<= RM_Size
(Typ
) then
6064 Actual_Lo
:= Loval_Incl_EP
;
6065 Actual_Hi
:= Hival_Incl_EP
;
6066 Actual_Size
:= Size_Incl_EP
;
6068 -- If the inclusive size is too large, we try excluding
6069 -- the end-points (will be caught later if does not work).
6072 Actual_Lo
:= Loval_Excl_EP
;
6073 Actual_Hi
:= Hival_Excl_EP
;
6074 Actual_Size
:= Size_Excl_EP
;
6077 -- Case of size clause not given
6080 -- If we have a base type whose corresponding first subtype
6081 -- has an explicit size that is large enough to include our
6082 -- end-points, then do so. There is no point in working hard
6083 -- to get a base type whose size is smaller than the specified
6084 -- size of the first subtype.
6086 First_Subt
:= First_Subtype
(Typ
);
6088 if Has_Size_Clause
(First_Subt
)
6089 and then Size_Incl_EP
<= Esize
(First_Subt
)
6091 Actual_Size
:= Size_Incl_EP
;
6092 Actual_Lo
:= Loval_Incl_EP
;
6093 Actual_Hi
:= Hival_Incl_EP
;
6095 -- If excluding the end-points makes the size smaller and
6096 -- results in a size of 8,16,32,64, then we take the smaller
6097 -- size. For the 64 case, this is compulsory. For the other
6098 -- cases, it seems reasonable. We like to include end points
6099 -- if we can, but not at the expense of moving to the next
6100 -- natural boundary of size.
6102 elsif Size_Incl_EP
/= Size_Excl_EP
6103 and then Addressable
(Size_Excl_EP
)
6105 Actual_Size
:= Size_Excl_EP
;
6106 Actual_Lo
:= Loval_Excl_EP
;
6107 Actual_Hi
:= Hival_Excl_EP
;
6109 -- Otherwise we can definitely include the end points
6112 Actual_Size
:= Size_Incl_EP
;
6113 Actual_Lo
:= Loval_Incl_EP
;
6114 Actual_Hi
:= Hival_Incl_EP
;
6117 -- One pathological case: normally we never fudge a low bound
6118 -- down, since it would seem to increase the size (if it has
6119 -- any effect), but for ranges containing single value, or no
6120 -- values, the high bound can be small too large. Consider:
6122 -- type t is delta 2.0**(-14)
6123 -- range 131072.0 .. 0;
6125 -- That lower bound is *just* outside the range of 32 bits, and
6126 -- does need fudging down in this case. Note that the bounds
6127 -- will always have crossed here, since the high bound will be
6128 -- fudged down if necessary, as in the case of:
6130 -- type t is delta 2.0**(-14)
6131 -- range 131072.0 .. 131072.0;
6133 -- So we detect the situation by looking for crossed bounds,
6134 -- and if the bounds are crossed, and the low bound is greater
6135 -- than zero, we will always back it off by small, since this
6136 -- is completely harmless.
6138 if Actual_Lo
> Actual_Hi
then
6139 if UR_Is_Positive
(Actual_Lo
) then
6140 Actual_Lo
:= Loval_Incl_EP
- Small
;
6141 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
6143 -- And of course, we need to do exactly the same parallel
6144 -- fudge for flat ranges in the negative region.
6146 elsif UR_Is_Negative
(Actual_Hi
) then
6147 Actual_Hi
:= Hival_Incl_EP
+ Small
;
6148 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
6153 Set_Realval
(Lo
, Actual_Lo
);
6154 Set_Realval
(Hi
, Actual_Hi
);
6157 -- For the decimal case, none of this fudging is required, since there
6158 -- are no end-point problems in the decimal case (the end-points are
6159 -- always included).
6162 Actual_Size
:= Fsize
(Loval
, Hival
);
6165 -- At this stage, the actual size has been calculated and the proper
6166 -- required bounds are stored in the low and high bounds.
6168 if Actual_Size
> 64 then
6169 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
6171 ("size required (^) for type& too large, maximum allowed is 64",
6176 -- Check size against explicit given size
6178 if Has_Size_Clause
(Typ
) then
6179 if Actual_Size
> RM_Size
(Typ
) then
6180 Error_Msg_Uint_1
:= RM_Size
(Typ
);
6181 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
6183 ("size given (^) for type& too small, minimum allowed is ^",
6184 Size_Clause
(Typ
), Typ
);
6187 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
6190 -- Increase size to next natural boundary if no size clause given
6193 if Actual_Size
<= 8 then
6195 elsif Actual_Size
<= 16 then
6197 elsif Actual_Size
<= 32 then
6203 Init_Esize
(Typ
, Actual_Size
);
6204 Adjust_Esize_For_Alignment
(Typ
);
6207 -- If we have a base type, then expand the bounds so that they extend to
6208 -- the full width of the allocated size in bits, to avoid junk range
6209 -- checks on intermediate computations.
6211 if Base_Type
(Typ
) = Typ
then
6212 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
6213 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
6216 -- Final step is to reanalyze the bounds using the proper type
6217 -- and set the Corresponding_Integer_Value fields of the literals.
6219 Set_Etype
(Lo
, Empty
);
6220 Set_Analyzed
(Lo
, False);
6223 -- Resolve with universal fixed if the base type, and the base type if
6224 -- it is a subtype. Note we can't resolve the base type with itself,
6225 -- that would be a reference before definition.
6228 Resolve
(Lo
, Universal_Fixed
);
6233 -- Set corresponding integer value for bound
6235 Set_Corresponding_Integer_Value
6236 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
6238 -- Similar processing for high bound
6240 Set_Etype
(Hi
, Empty
);
6241 Set_Analyzed
(Hi
, False);
6245 Resolve
(Hi
, Universal_Fixed
);
6250 Set_Corresponding_Integer_Value
6251 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
6253 -- Set type of range to correspond to bounds
6255 Set_Etype
(Rng
, Etype
(Lo
));
6257 -- Set Esize to calculated size if not set already
6259 if Unknown_Esize
(Typ
) then
6260 Init_Esize
(Typ
, Actual_Size
);
6263 -- Set RM_Size if not already set. If already set, check value
6266 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
6269 if RM_Size
(Typ
) /= Uint_0
then
6270 if RM_Size
(Typ
) < Minsiz
then
6271 Error_Msg_Uint_1
:= RM_Size
(Typ
);
6272 Error_Msg_Uint_2
:= Minsiz
;
6274 ("size given (^) for type& too small, minimum allowed is ^",
6275 Size_Clause
(Typ
), Typ
);
6279 Set_RM_Size
(Typ
, Minsiz
);
6282 end Freeze_Fixed_Point_Type
;
6288 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
6292 Set_Has_Delayed_Freeze
(T
);
6293 L
:= Freeze_Entity
(T
, N
);
6295 if Is_Non_Empty_List
(L
) then
6296 Insert_Actions
(N
, L
);
6300 --------------------------
6301 -- Freeze_Static_Object --
6302 --------------------------
6304 procedure Freeze_Static_Object
(E
: Entity_Id
) is
6306 Cannot_Be_Static
: exception;
6307 -- Exception raised if the type of a static object cannot be made
6308 -- static. This happens if the type depends on non-global objects.
6310 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
6311 -- Called to ensure that an expression used as part of a type definition
6312 -- is statically allocatable, which means that the expression type is
6313 -- statically allocatable, and the expression is either static, or a
6314 -- reference to a library level constant.
6316 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
6317 -- Called to mark a type as static, checking that it is possible
6318 -- to set the type as static. If it is not possible, then the
6319 -- exception Cannot_Be_Static is raised.
6321 -----------------------------
6322 -- Ensure_Expression_Is_SA --
6323 -----------------------------
6325 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
6329 Ensure_Type_Is_SA
(Etype
(N
));
6331 if Is_Static_Expression
(N
) then
6334 elsif Nkind
(N
) = N_Identifier
then
6338 and then Ekind
(Ent
) = E_Constant
6339 and then Is_Library_Level_Entity
(Ent
)
6345 raise Cannot_Be_Static
;
6346 end Ensure_Expression_Is_SA
;
6348 -----------------------
6349 -- Ensure_Type_Is_SA --
6350 -----------------------
6352 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
6357 -- If type is library level, we are all set
6359 if Is_Library_Level_Entity
(Typ
) then
6363 -- We are also OK if the type already marked as statically allocated,
6364 -- which means we processed it before.
6366 if Is_Statically_Allocated
(Typ
) then
6370 -- Mark type as statically allocated
6372 Set_Is_Statically_Allocated
(Typ
);
6374 -- Check that it is safe to statically allocate this type
6376 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
6377 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
6378 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
6380 elsif Is_Array_Type
(Typ
) then
6381 N
:= First_Index
(Typ
);
6382 while Present
(N
) loop
6383 Ensure_Type_Is_SA
(Etype
(N
));
6387 Ensure_Type_Is_SA
(Component_Type
(Typ
));
6389 elsif Is_Access_Type
(Typ
) then
6390 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
6394 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
6397 if T
/= Standard_Void_Type
then
6398 Ensure_Type_Is_SA
(T
);
6401 F
:= First_Formal
(Designated_Type
(Typ
));
6402 while Present
(F
) loop
6403 Ensure_Type_Is_SA
(Etype
(F
));
6409 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
6412 elsif Is_Record_Type
(Typ
) then
6413 C
:= First_Entity
(Typ
);
6414 while Present
(C
) loop
6415 if Ekind
(C
) = E_Discriminant
6416 or else Ekind
(C
) = E_Component
6418 Ensure_Type_Is_SA
(Etype
(C
));
6420 elsif Is_Type
(C
) then
6421 Ensure_Type_Is_SA
(C
);
6427 elsif Ekind
(Typ
) = E_Subprogram_Type
then
6428 Ensure_Type_Is_SA
(Etype
(Typ
));
6430 C
:= First_Formal
(Typ
);
6431 while Present
(C
) loop
6432 Ensure_Type_Is_SA
(Etype
(C
));
6437 raise Cannot_Be_Static
;
6439 end Ensure_Type_Is_SA
;
6441 -- Start of processing for Freeze_Static_Object
6444 Ensure_Type_Is_SA
(Etype
(E
));
6447 when Cannot_Be_Static
=>
6449 -- If the object that cannot be static is imported or exported, then
6450 -- issue an error message saying that this object cannot be imported
6451 -- or exported. If it has an address clause it is an overlay in the
6452 -- current partition and the static requirement is not relevant.
6453 -- Do not issue any error message when ignoring rep clauses.
6455 if Ignore_Rep_Clauses
then
6458 elsif Is_Imported
(E
) then
6459 if No
(Address_Clause
(E
)) then
6461 ("& cannot be imported (local type is not constant)", E
);
6464 -- Otherwise must be exported, something is wrong if compiler
6465 -- is marking something as statically allocated which cannot be).
6467 else pragma Assert
(Is_Exported
(E
));
6469 ("& cannot be exported (local type is not constant)", E
);
6471 end Freeze_Static_Object
;
6473 -----------------------
6474 -- Freeze_Subprogram --
6475 -----------------------
6477 procedure Freeze_Subprogram
(E
: Entity_Id
) is
6482 -- Subprogram may not have an address clause unless it is imported
6484 if Present
(Address_Clause
(E
)) then
6485 if not Is_Imported
(E
) then
6487 ("address clause can only be given " &
6488 "for imported subprogram",
6489 Name
(Address_Clause
(E
)));
6493 -- Reset the Pure indication on an imported subprogram unless an
6494 -- explicit Pure_Function pragma was present. We do this because
6495 -- otherwise it is an insidious error to call a non-pure function from
6496 -- pure unit and have calls mysteriously optimized away. What happens
6497 -- here is that the Import can bypass the normal check to ensure that
6498 -- pure units call only pure subprograms.
6501 and then Is_Pure
(E
)
6502 and then not Has_Pragma_Pure_Function
(E
)
6504 Set_Is_Pure
(E
, False);
6507 -- For non-foreign convention subprograms, this is where we create
6508 -- the extra formals (for accessibility level and constrained bit
6509 -- information). We delay this till the freeze point precisely so
6510 -- that we know the convention!
6512 if not Has_Foreign_Convention
(E
) then
6513 Create_Extra_Formals
(E
);
6516 -- If this is convention Ada and a Valued_Procedure, that's odd
6518 if Ekind
(E
) = E_Procedure
6519 and then Is_Valued_Procedure
(E
)
6520 and then Convention
(E
) = Convention_Ada
6521 and then Warn_On_Export_Import
6524 ("??Valued_Procedure has no effect for convention Ada", E
);
6525 Set_Is_Valued_Procedure
(E
, False);
6528 -- Case of foreign convention
6533 -- For foreign conventions, warn about return of an
6534 -- unconstrained array.
6536 -- Note: we *do* allow a return by descriptor for the VMS case,
6537 -- though here there is probably more to be done ???
6539 if Ekind
(E
) = E_Function
then
6540 Retype
:= Underlying_Type
(Etype
(E
));
6542 -- If no return type, probably some other error, e.g. a
6543 -- missing full declaration, so ignore.
6548 -- If the return type is generic, we have emitted a warning
6549 -- earlier on, and there is nothing else to check here. Specific
6550 -- instantiations may lead to erroneous behavior.
6552 elsif Is_Generic_Type
(Etype
(E
)) then
6555 -- Display warning if returning unconstrained array
6557 elsif Is_Array_Type
(Retype
)
6558 and then not Is_Constrained
(Retype
)
6560 -- Exclude cases where descriptor mechanism is set, since the
6561 -- VMS descriptor mechanisms allow such unconstrained returns.
6563 and then Mechanism
(E
) not in Descriptor_Codes
6565 -- Check appropriate warning is enabled (should we check for
6566 -- Warnings (Off) on specific entities here, probably so???)
6568 and then Warn_On_Export_Import
6570 -- Exclude the VM case, since return of unconstrained arrays
6571 -- is properly handled in both the JVM and .NET cases.
6573 and then VM_Target
= No_VM
6576 ("?x?foreign convention function& should not return " &
6577 "unconstrained array", E
);
6582 -- If any of the formals for an exported foreign convention
6583 -- subprogram have defaults, then emit an appropriate warning since
6584 -- this is odd (default cannot be used from non-Ada code)
6586 if Is_Exported
(E
) then
6587 F
:= First_Formal
(E
);
6588 while Present
(F
) loop
6589 if Warn_On_Export_Import
6590 and then Present
(Default_Value
(F
))
6593 ("?x?parameter cannot be defaulted in non-Ada call",
6602 -- For VMS, descriptor mechanisms for parameters are allowed only for
6603 -- imported/exported subprograms. Moreover, the NCA descriptor is not
6604 -- allowed for parameters of exported subprograms.
6606 if OpenVMS_On_Target
then
6607 if Is_Exported
(E
) then
6608 F
:= First_Formal
(E
);
6609 while Present
(F
) loop
6610 if Mechanism
(F
) = By_Descriptor_NCA
then
6612 ("'N'C'A' descriptor for parameter not permitted", F
);
6614 ("\can only be used for imported subprogram", F
);
6620 elsif not Is_Imported
(E
) then
6621 F
:= First_Formal
(E
);
6622 while Present
(F
) loop
6623 if Mechanism
(F
) in Descriptor_Codes
then
6625 ("descriptor mechanism for parameter not permitted", F
);
6627 ("\can only be used for imported/exported subprogram", F
);
6635 -- Pragma Inline_Always is disallowed for dispatching subprograms
6636 -- because the address of such subprograms is saved in the dispatch
6637 -- table to support dispatching calls, and dispatching calls cannot
6638 -- be inlined. This is consistent with the restriction against using
6639 -- 'Access or 'Address on an Inline_Always subprogram.
6641 if Is_Dispatching_Operation
(E
)
6642 and then Has_Pragma_Inline_Always
(E
)
6645 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
6648 -- Because of the implicit representation of inherited predefined
6649 -- operators in the front-end, the overriding status of the operation
6650 -- may be affected when a full view of a type is analyzed, and this is
6651 -- not captured by the analysis of the corresponding type declaration.
6652 -- Therefore the correctness of a not-overriding indicator must be
6653 -- rechecked when the subprogram is frozen.
6655 if Nkind
(E
) = N_Defining_Operator_Symbol
6656 and then not Error_Posted
(Parent
(E
))
6658 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
6660 end Freeze_Subprogram
;
6662 ----------------------
6663 -- Is_Fully_Defined --
6664 ----------------------
6666 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
6668 if Ekind
(T
) = E_Class_Wide_Type
then
6669 return Is_Fully_Defined
(Etype
(T
));
6671 elsif Is_Array_Type
(T
) then
6672 return Is_Fully_Defined
(Component_Type
(T
));
6674 elsif Is_Record_Type
(T
)
6675 and not Is_Private_Type
(T
)
6677 -- Verify that the record type has no components with private types
6678 -- without completion.
6684 Comp
:= First_Component
(T
);
6685 while Present
(Comp
) loop
6686 if not Is_Fully_Defined
(Etype
(Comp
)) then
6690 Next_Component
(Comp
);
6695 -- For the designated type of an access to subprogram, all types in
6696 -- the profile must be fully defined.
6698 elsif Ekind
(T
) = E_Subprogram_Type
then
6703 F
:= First_Formal
(T
);
6704 while Present
(F
) loop
6705 if not Is_Fully_Defined
(Etype
(F
)) then
6712 return Is_Fully_Defined
(Etype
(T
));
6716 return not Is_Private_Type
(T
)
6717 or else Present
(Full_View
(Base_Type
(T
)));
6719 end Is_Fully_Defined
;
6721 ---------------------------------
6722 -- Process_Default_Expressions --
6723 ---------------------------------
6725 procedure Process_Default_Expressions
6727 After
: in out Node_Id
)
6729 Loc
: constant Source_Ptr
:= Sloc
(E
);
6736 Set_Default_Expressions_Processed
(E
);
6738 -- A subprogram instance and its associated anonymous subprogram share
6739 -- their signature. The default expression functions are defined in the
6740 -- wrapper packages for the anonymous subprogram, and should not be
6741 -- generated again for the instance.
6743 if Is_Generic_Instance
(E
)
6744 and then Present
(Alias
(E
))
6745 and then Default_Expressions_Processed
(Alias
(E
))
6750 Formal
:= First_Formal
(E
);
6751 while Present
(Formal
) loop
6752 if Present
(Default_Value
(Formal
)) then
6754 -- We work with a copy of the default expression because we
6755 -- do not want to disturb the original, since this would mess
6756 -- up the conformance checking.
6758 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
6760 -- The analysis of the expression may generate insert actions,
6761 -- which of course must not be executed. We wrap those actions
6762 -- in a procedure that is not called, and later on eliminated.
6763 -- The following cases have no side-effects, and are analyzed
6766 if Nkind
(Dcopy
) = N_Identifier
6767 or else Nkind
(Dcopy
) = N_Expanded_Name
6768 or else Nkind
(Dcopy
) = N_Integer_Literal
6769 or else (Nkind
(Dcopy
) = N_Real_Literal
6770 and then not Vax_Float
(Etype
(Dcopy
)))
6771 or else Nkind
(Dcopy
) = N_Character_Literal
6772 or else Nkind
(Dcopy
) = N_String_Literal
6773 or else Known_Null
(Dcopy
)
6774 or else (Nkind
(Dcopy
) = N_Attribute_Reference
6776 Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
6779 -- If there is no default function, we must still do a full
6780 -- analyze call on the default value, to ensure that all error
6781 -- checks are performed, e.g. those associated with static
6782 -- evaluation. Note: this branch will always be taken if the
6783 -- analyzer is turned off (but we still need the error checks).
6785 -- Note: the setting of parent here is to meet the requirement
6786 -- that we can only analyze the expression while attached to
6787 -- the tree. Really the requirement is that the parent chain
6788 -- be set, we don't actually need to be in the tree.
6790 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
6793 -- Default expressions are resolved with their own type if the
6794 -- context is generic, to avoid anomalies with private types.
6796 if Ekind
(Scope
(E
)) = E_Generic_Package
then
6799 Resolve
(Dcopy
, Etype
(Formal
));
6802 -- If that resolved expression will raise constraint error,
6803 -- then flag the default value as raising constraint error.
6804 -- This allows a proper error message on the calls.
6806 if Raises_Constraint_Error
(Dcopy
) then
6807 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
6810 -- If the default is a parameterless call, we use the name of
6811 -- the called function directly, and there is no body to build.
6813 elsif Nkind
(Dcopy
) = N_Function_Call
6814 and then No
(Parameter_Associations
(Dcopy
))
6818 -- Else construct and analyze the body of a wrapper procedure
6819 -- that contains an object declaration to hold the expression.
6820 -- Given that this is done only to complete the analysis, it
6821 -- simpler to build a procedure than a function which might
6822 -- involve secondary stack expansion.
6825 Dnam
:= Make_Temporary
(Loc
, 'D');
6828 Make_Subprogram_Body
(Loc
,
6830 Make_Procedure_Specification
(Loc
,
6831 Defining_Unit_Name
=> Dnam
),
6833 Declarations
=> New_List
(
6834 Make_Object_Declaration
(Loc
,
6835 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
6836 Object_Definition
=>
6837 New_Occurrence_Of
(Etype
(Formal
), Loc
),
6838 Expression
=> New_Copy_Tree
(Dcopy
))),
6840 Handled_Statement_Sequence
=>
6841 Make_Handled_Sequence_Of_Statements
(Loc
,
6842 Statements
=> Empty_List
));
6844 Set_Scope
(Dnam
, Scope
(E
));
6845 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
6846 Set_Is_Eliminated
(Dnam
);
6847 Insert_After
(After
, Dbody
);
6853 Next_Formal
(Formal
);
6855 end Process_Default_Expressions
;
6857 ----------------------------------------
6858 -- Set_Component_Alignment_If_Not_Set --
6859 ----------------------------------------
6861 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
6863 -- Ignore if not base type, subtypes don't need anything
6865 if Typ
/= Base_Type
(Typ
) then
6869 -- Do not override existing representation
6871 if Is_Packed
(Typ
) then
6874 elsif Has_Specified_Layout
(Typ
) then
6877 elsif Component_Alignment
(Typ
) /= Calign_Default
then
6881 Set_Component_Alignment
6882 (Typ
, Scope_Stack
.Table
6883 (Scope_Stack
.Last
).Component_Alignment_Default
);
6885 end Set_Component_Alignment_If_Not_Set
;
6891 procedure Undelay_Type
(T
: Entity_Id
) is
6893 Set_Has_Delayed_Freeze
(T
, False);
6894 Set_Freeze_Node
(T
, Empty
);
6896 -- Since we don't want T to have a Freeze_Node, we don't want its
6897 -- Full_View or Corresponding_Record_Type to have one either.
6899 -- ??? Fundamentally, this whole handling is a kludge. What we really
6900 -- want is to be sure that for an Itype that's part of record R and is a
6901 -- subtype of type T, that it's frozen after the later of the freeze
6902 -- points of R and T. We have no way of doing that directly, so what we
6903 -- do is force most such Itypes to be frozen as part of freezing R via
6904 -- this procedure and only delay the ones that need to be delayed
6905 -- (mostly the designated types of access types that are defined as part
6908 if Is_Private_Type
(T
)
6909 and then Present
(Full_View
(T
))
6910 and then Is_Itype
(Full_View
(T
))
6911 and then Is_Record_Type
(Scope
(Full_View
(T
)))
6913 Undelay_Type
(Full_View
(T
));
6916 if Is_Concurrent_Type
(T
)
6917 and then Present
(Corresponding_Record_Type
(T
))
6918 and then Is_Itype
(Corresponding_Record_Type
(T
))
6919 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
6921 Undelay_Type
(Corresponding_Record_Type
(T
));
6929 procedure Warn_Overlay
6934 Ent
: constant Entity_Id
:= Entity
(Nam
);
6935 -- The object to which the address clause applies
6938 Old
: Entity_Id
:= Empty
;
6942 -- No warning if address clause overlay warnings are off
6944 if not Address_Clause_Overlay_Warnings
then
6948 -- No warning if there is an explicit initialization
6950 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
6952 if Present
(Init
) and then Comes_From_Source
(Init
) then
6956 -- We only give the warning for non-imported entities of a type for
6957 -- which a non-null base init proc is defined, or for objects of access
6958 -- types with implicit null initialization, or when Normalize_Scalars
6959 -- applies and the type is scalar or a string type (the latter being
6960 -- tested for because predefined String types are initialized by inline
6961 -- code rather than by an init_proc). Note that we do not give the
6962 -- warning for Initialize_Scalars, since we suppressed initialization
6963 -- in this case. Also, do not warn if Suppress_Initialization is set.
6966 and then not Is_Imported
(Ent
)
6967 and then not Initialization_Suppressed
(Typ
)
6968 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
6969 or else Is_Access_Type
(Typ
)
6970 or else (Normalize_Scalars
6971 and then (Is_Scalar_Type
(Typ
)
6972 or else Is_String_Type
(Typ
))))
6974 if Nkind
(Expr
) = N_Attribute_Reference
6975 and then Is_Entity_Name
(Prefix
(Expr
))
6977 Old
:= Entity
(Prefix
(Expr
));
6979 elsif Is_Entity_Name
(Expr
)
6980 and then Ekind
(Entity
(Expr
)) = E_Constant
6982 Decl
:= Declaration_Node
(Entity
(Expr
));
6984 if Nkind
(Decl
) = N_Object_Declaration
6985 and then Present
(Expression
(Decl
))
6986 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
6987 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
6989 Old
:= Entity
(Prefix
(Expression
(Decl
)));
6991 elsif Nkind
(Expr
) = N_Function_Call
then
6995 -- A function call (most likely to To_Address) is probably not an
6996 -- overlay, so skip warning. Ditto if the function call was inlined
6997 -- and transformed into an entity.
6999 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
7003 Decl
:= Next
(Parent
(Expr
));
7005 -- If a pragma Import follows, we assume that it is for the current
7006 -- target of the address clause, and skip the warning.
7009 and then Nkind
(Decl
) = N_Pragma
7010 and then Pragma_Name
(Decl
) = Name_Import
7015 if Present
(Old
) then
7016 Error_Msg_Node_2
:= Old
;
7018 ("default initialization of & may modify &??",
7022 ("default initialization of & may modify overlaid storage??",
7026 -- Add friendly warning if initialization comes from a packed array
7029 if Is_Record_Type
(Typ
) then
7034 Comp
:= First_Component
(Typ
);
7035 while Present
(Comp
) loop
7036 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
7037 and then Present
(Expression
(Parent
(Comp
)))
7040 elsif Is_Array_Type
(Etype
(Comp
))
7041 and then Present
(Packed_Array_Type
(Etype
(Comp
)))
7044 ("\packed array component& " &
7045 "will be initialized to zero??",
7049 Next_Component
(Comp
);
7056 ("\use pragma Import for & to " &
7057 "suppress initialization (RM B.1(24))??",