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 (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 Comp_SSO_Differs
: Boolean;
1087 -- Set True when the component is a nested composite, and it does not
1088 -- have the same scalar storage order as Encl_Type.
1090 Component_Aliased
: Boolean;
1095 if Present
(Comp
) then
1097 Comp_Type
:= Etype
(Comp
);
1099 if Is_Tag
(Comp
) then
1100 Comp_Byte_Aligned
:= True;
1101 Component_Aliased
:= False;
1104 Comp_Byte_Aligned
:=
1105 Present
(Component_Clause
(Comp
))
1107 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1108 Component_Aliased
:= Is_Aliased
(Comp
);
1114 Err_Node
:= Encl_Type
;
1115 Comp_Type
:= Component_Type
(Encl_Type
);
1117 Comp_Byte_Aligned
:= False;
1118 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1121 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1122 -- the attribute definition clause is attached to the first subtype.
1124 Comp_Type
:= Base_Type
(Comp_Type
);
1125 Comp_ADC
:= Get_Attribute_Definition_Clause
1126 (First_Subtype
(Comp_Type
),
1127 Attribute_Scalar_Storage_Order
);
1129 -- Case of enclosing type not having explicit SSO: component cannot
1133 if Present
(Comp_ADC
) then
1135 ("composite type must have explicit scalar storage order",
1139 -- Case of enclosing type having explicit SSO: check compatible
1140 -- attribute on Comp_Type if composite.
1142 elsif Is_Record_Type
(Comp_Type
) or else Is_Array_Type
(Comp_Type
) then
1144 Reverse_Storage_Order
(Encl_Type
)
1146 Reverse_Storage_Order
(Comp_Type
);
1148 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1149 if Comp_SSO_Differs
then
1151 ("record extension must have same scalar storage order as "
1152 & "parent", Err_Node
);
1155 elsif No
(Comp_ADC
) then
1156 Error_Msg_N
("nested composite must have explicit scalar "
1157 & "storage order", Err_Node
);
1159 elsif Comp_SSO_Differs
then
1161 -- Component SSO differs from enclosing composite:
1163 -- Reject if component is a packed array, as it may be represented
1164 -- as a scalar internally.
1166 if Is_Packed
(Comp_Type
) then
1168 ("type of packed component must have same scalar "
1169 & "storage order as enclosing composite", Err_Node
);
1171 -- Reject if not byte aligned
1173 elsif not Comp_Byte_Aligned
then
1175 ("type of non-byte-aligned component must have same scalar "
1176 & "storage order as enclosing composite", Err_Node
);
1180 -- Enclosing type has explicit SSO, non-composite component must not
1183 elsif Component_Aliased
then
1185 ("aliased component not permitted for type with "
1186 & "explicit Scalar_Storage_Order", Err_Node
);
1188 end Check_Component_Storage_Order
;
1190 -----------------------------
1191 -- Check_Debug_Info_Needed --
1192 -----------------------------
1194 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1196 if Debug_Info_Off
(T
) then
1199 elsif Comes_From_Source
(T
)
1200 or else Debug_Generated_Code
1201 or else Debug_Flag_VV
1202 or else Needs_Debug_Info
(T
)
1204 Set_Debug_Info_Needed
(T
);
1206 end Check_Debug_Info_Needed
;
1208 ----------------------------
1209 -- Check_Strict_Alignment --
1210 ----------------------------
1212 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1216 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1217 Set_Strict_Alignment
(E
);
1219 elsif Is_Array_Type
(E
) then
1220 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1222 elsif Is_Record_Type
(E
) then
1223 if Is_Limited_Record
(E
) then
1224 Set_Strict_Alignment
(E
);
1228 Comp
:= First_Component
(E
);
1229 while Present
(Comp
) loop
1230 if not Is_Type
(Comp
)
1231 and then (Strict_Alignment
(Etype
(Comp
))
1232 or else Is_Aliased
(Comp
))
1234 Set_Strict_Alignment
(E
);
1238 Next_Component
(Comp
);
1241 end Check_Strict_Alignment
;
1243 -------------------------
1244 -- Check_Unsigned_Type --
1245 -------------------------
1247 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1248 Ancestor
: Entity_Id
;
1253 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1257 -- Do not attempt to analyze case where range was in error
1259 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
1263 -- The situation that is non trivial is something like
1265 -- subtype x1 is integer range -10 .. +10;
1266 -- subtype x2 is x1 range 0 .. V1;
1267 -- subtype x3 is x2 range V2 .. V3;
1268 -- subtype x4 is x3 range V4 .. V5;
1270 -- where Vn are variables. Here the base type is signed, but we still
1271 -- know that x4 is unsigned because of the lower bound of x2.
1273 -- The only way to deal with this is to look up the ancestor chain
1277 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1281 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1283 if Compile_Time_Known_Value
(Lo_Bound
) then
1284 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1285 Set_Is_Unsigned_Type
(E
, True);
1291 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1293 -- If no ancestor had a static lower bound, go to base type
1295 if No
(Ancestor
) then
1297 -- Note: the reason we still check for a compile time known
1298 -- value for the base type is that at least in the case of
1299 -- generic formals, we can have bounds that fail this test,
1300 -- and there may be other cases in error situations.
1302 Btyp
:= Base_Type
(E
);
1304 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1308 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1310 if Compile_Time_Known_Value
(Lo_Bound
)
1311 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1313 Set_Is_Unsigned_Type
(E
, True);
1320 end Check_Unsigned_Type
;
1322 -------------------------
1323 -- Is_Atomic_Aggregate --
1324 -------------------------
1326 function Is_Atomic_Aggregate
1328 Typ
: Entity_Id
) return Boolean
1330 Loc
: constant Source_Ptr
:= Sloc
(E
);
1338 -- Array may be qualified, so find outer context
1340 if Nkind
(Par
) = N_Qualified_Expression
then
1341 Par
:= Parent
(Par
);
1344 if Nkind_In
(Par
, N_Object_Declaration
, N_Assignment_Statement
)
1345 and then Comes_From_Source
(Par
)
1347 Temp
:= Make_Temporary
(Loc
, 'T', E
);
1349 Make_Object_Declaration
(Loc
,
1350 Defining_Identifier
=> Temp
,
1351 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1352 Expression
=> Relocate_Node
(E
));
1353 Insert_Before
(Par
, New_N
);
1356 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1362 end Is_Atomic_Aggregate
;
1368 -- Note: the easy coding for this procedure would be to just build a
1369 -- single list of freeze nodes and then insert them and analyze them
1370 -- all at once. This won't work, because the analysis of earlier freeze
1371 -- nodes may recursively freeze types which would otherwise appear later
1372 -- on in the freeze list. So we must analyze and expand the freeze nodes
1373 -- as they are generated.
1375 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1379 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1380 -- This is the internal recursive routine that does freezing of entities
1381 -- (but NOT the analysis of default expressions, which should not be
1382 -- recursive, we don't want to analyze those till we are sure that ALL
1383 -- the types are frozen).
1385 --------------------
1386 -- Freeze_All_Ent --
1387 --------------------
1389 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1394 procedure Process_Flist
;
1395 -- If freeze nodes are present, insert and analyze, and reset cursor
1396 -- for next insertion.
1402 procedure Process_Flist
is
1404 if Is_Non_Empty_List
(Flist
) then
1405 Lastn
:= Next
(After
);
1406 Insert_List_After_And_Analyze
(After
, Flist
);
1408 if Present
(Lastn
) then
1409 After
:= Prev
(Lastn
);
1411 After
:= Last
(List_Containing
(After
));
1416 -- Start or processing for Freeze_All_Ent
1420 while Present
(E
) loop
1422 -- If the entity is an inner package which is not a package
1423 -- renaming, then its entities must be frozen at this point. Note
1424 -- that such entities do NOT get frozen at the end of the nested
1425 -- package itself (only library packages freeze).
1427 -- Same is true for task declarations, where anonymous records
1428 -- created for entry parameters must be frozen.
1430 if Ekind
(E
) = E_Package
1431 and then No
(Renamed_Object
(E
))
1432 and then not Is_Child_Unit
(E
)
1433 and then not Is_Frozen
(E
)
1436 Install_Visible_Declarations
(E
);
1437 Install_Private_Declarations
(E
);
1439 Freeze_All
(First_Entity
(E
), After
);
1441 End_Package_Scope
(E
);
1443 if Is_Generic_Instance
(E
)
1444 and then Has_Delayed_Freeze
(E
)
1446 Set_Has_Delayed_Freeze
(E
, False);
1447 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1450 elsif Ekind
(E
) in Task_Kind
1451 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1452 N_Single_Task_Declaration
)
1455 Freeze_All
(First_Entity
(E
), After
);
1458 -- For a derived tagged type, we must ensure that all the
1459 -- primitive operations of the parent have been frozen, so that
1460 -- their addresses will be in the parent's dispatch table at the
1461 -- point it is inherited.
1463 elsif Ekind
(E
) = E_Record_Type
1464 and then Is_Tagged_Type
(E
)
1465 and then Is_Tagged_Type
(Etype
(E
))
1466 and then Is_Derived_Type
(E
)
1469 Prim_List
: constant Elist_Id
:=
1470 Primitive_Operations
(Etype
(E
));
1476 Prim
:= First_Elmt
(Prim_List
);
1477 while Present
(Prim
) loop
1478 Subp
:= Node
(Prim
);
1480 if Comes_From_Source
(Subp
)
1481 and then not Is_Frozen
(Subp
)
1483 Flist
:= Freeze_Entity
(Subp
, After
);
1492 if not Is_Frozen
(E
) then
1493 Flist
:= Freeze_Entity
(E
, After
);
1496 -- If already frozen, and there are delayed aspects, this is where
1497 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1498 -- for a description of how we handle aspect visibility).
1500 elsif Has_Delayed_Aspects
(E
) then
1502 -- Retrieve the visibility to the discriminants in order to
1503 -- analyze properly the aspects.
1505 Push_Scope_And_Install_Discriminants
(E
);
1511 Ritem
:= First_Rep_Item
(E
);
1512 while Present
(Ritem
) loop
1513 if Nkind
(Ritem
) = N_Aspect_Specification
1514 and then Entity
(Ritem
) = E
1515 and then Is_Delayed_Aspect
(Ritem
)
1517 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1520 Ritem
:= Next_Rep_Item
(Ritem
);
1524 Uninstall_Discriminants_And_Pop_Scope
(E
);
1527 -- If an incomplete type is still not frozen, this may be a
1528 -- premature freezing because of a body declaration that follows.
1529 -- Indicate where the freezing took place. Freezing will happen
1530 -- if the body comes from source, but not if it is internally
1531 -- generated, for example as the body of a type invariant.
1533 -- If the freezing is caused by the end of the current declarative
1534 -- part, it is a Taft Amendment type, and there is no error.
1536 if not Is_Frozen
(E
)
1537 and then Ekind
(E
) = E_Incomplete_Type
1540 Bod
: constant Node_Id
:= Next
(After
);
1543 -- The presence of a body freezes all entities previously
1544 -- declared in the current list of declarations, but this
1545 -- does not apply if the body does not come from source.
1546 -- A type invariant is transformed into a subprogram body
1547 -- which is placed at the end of the private part of the
1548 -- current package, but this body does not freeze incomplete
1549 -- types that may be declared in this private part.
1551 if (Nkind_In
(Bod
, N_Subprogram_Body
,
1556 or else Nkind
(Bod
) in N_Body_Stub
)
1558 List_Containing
(After
) = List_Containing
(Parent
(E
))
1559 and then Comes_From_Source
(Bod
)
1561 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1563 ("type& is frozen# before its full declaration",
1573 -- Start of processing for Freeze_All
1576 Freeze_All_Ent
(From
, After
);
1578 -- Now that all types are frozen, we can deal with default expressions
1579 -- that require us to build a default expression functions. This is the
1580 -- point at which such functions are constructed (after all types that
1581 -- might be used in such expressions have been frozen).
1583 -- For subprograms that are renaming_as_body, we create the wrapper
1584 -- bodies as needed.
1586 -- We also add finalization chains to access types whose designated
1587 -- types are controlled. This is normally done when freezing the type,
1588 -- but this misses recursive type definitions where the later members
1589 -- of the recursion introduce controlled components.
1591 -- Loop through entities
1594 while Present
(E
) loop
1595 if Is_Subprogram
(E
) then
1597 if not Default_Expressions_Processed
(E
) then
1598 Process_Default_Expressions
(E
, After
);
1601 if not Has_Completion
(E
) then
1602 Decl
:= Unit_Declaration_Node
(E
);
1604 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1605 if Error_Posted
(Decl
) then
1606 Set_Has_Completion
(E
);
1608 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1611 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1612 and then Present
(Corresponding_Body
(Decl
))
1614 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1615 = N_Subprogram_Renaming_Declaration
1617 Build_And_Analyze_Renamed_Body
1618 (Decl
, Corresponding_Body
(Decl
), After
);
1622 elsif Ekind
(E
) in Task_Kind
1623 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1624 N_Single_Task_Declaration
)
1630 Ent
:= First_Entity
(E
);
1631 while Present
(Ent
) loop
1633 and then not Default_Expressions_Processed
(Ent
)
1635 Process_Default_Expressions
(Ent
, After
);
1642 -- We add finalization masters to access types whose designated types
1643 -- require finalization. This is normally done when freezing the
1644 -- type, but this misses recursive type definitions where the later
1645 -- members of the recursion introduce controlled components (such as
1646 -- can happen when incomplete types are involved), as well cases
1647 -- where a component type is private and the controlled full type
1648 -- occurs after the access type is frozen. Cases that don't need a
1649 -- finalization master are generic formal types (the actual type will
1650 -- have it) and types with Java and CIL conventions, since those are
1651 -- used for API bindings. (Are there any other cases that should be
1652 -- excluded here???)
1654 elsif Is_Access_Type
(E
)
1655 and then Comes_From_Source
(E
)
1656 and then not Is_Generic_Type
(E
)
1657 and then Needs_Finalization
(Designated_Type
(E
))
1659 Build_Finalization_Master
(E
);
1666 -----------------------
1667 -- Freeze_And_Append --
1668 -----------------------
1670 procedure Freeze_And_Append
1673 Result
: in out List_Id
)
1675 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1677 if Is_Non_Empty_List
(L
) then
1678 if Result
= No_List
then
1681 Append_List
(L
, Result
);
1684 end Freeze_And_Append
;
1690 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1691 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, N
);
1693 if Is_Non_Empty_List
(Freeze_Nodes
) then
1694 Insert_Actions
(N
, Freeze_Nodes
);
1702 function Freeze_Entity
(E
: Entity_Id
; N
: Node_Id
) return List_Id
is
1703 Loc
: constant Source_Ptr
:= Sloc
(N
);
1704 Test_E
: Entity_Id
:= E
;
1711 Result
: List_Id
:= No_List
;
1712 -- List of freezing actions, left at No_List if none
1714 Has_Default_Initialization
: Boolean := False;
1715 -- This flag gets set to true for a variable with default initialization
1717 procedure Add_To_Result
(N
: Node_Id
);
1718 -- N is a freezing action to be appended to the Result
1720 function After_Last_Declaration
return Boolean;
1721 -- If Loc is a freeze_entity that appears after the last declaration
1722 -- in the scope, inhibit error messages on late completion.
1724 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1725 -- Check that an Access or Unchecked_Access attribute with a prefix
1726 -- which is the current instance type can only be applied when the type
1729 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1730 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1731 -- integer literal without an explicit corresponding size clause. The
1732 -- caller has checked that Utype is a modular integer type.
1734 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
1735 -- Freeze array type, including freezing index and component types
1737 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
1738 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1739 -- package. Recurse on inner generic packages.
1741 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1742 -- Freeze record type, including freezing component types, and freezing
1743 -- primitive operations if this is a tagged type.
1749 procedure Add_To_Result
(N
: Node_Id
) is
1752 Result
:= New_List
(N
);
1758 ----------------------------
1759 -- After_Last_Declaration --
1760 ----------------------------
1762 function After_Last_Declaration
return Boolean is
1763 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
1765 if Nkind
(Spec
) = N_Package_Specification
then
1766 if Present
(Private_Declarations
(Spec
)) then
1767 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1768 elsif Present
(Visible_Declarations
(Spec
)) then
1769 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1776 end After_Last_Declaration
;
1778 ----------------------------
1779 -- Check_Current_Instance --
1780 ----------------------------
1782 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1784 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
1785 -- Determine whether Typ is compatible with the rules for aliased
1786 -- views of types as defined in RM 3.10 in the various dialects.
1788 function Process
(N
: Node_Id
) return Traverse_Result
;
1789 -- Process routine to apply check to given node
1791 -----------------------------
1792 -- Is_Aliased_View_Of_Type --
1793 -----------------------------
1795 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
1796 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
1801 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
1802 and then Limited_Present
(Type_Definition
(Typ_Decl
))
1806 -- The following paragraphs describe what a legal aliased view of
1807 -- a type is in the various dialects of Ada.
1811 -- The current instance of a limited type, and a formal parameter
1812 -- or generic formal object of a tagged type.
1814 -- Ada 95 limited type
1815 -- * Type with reserved word "limited"
1816 -- * A protected or task type
1817 -- * A composite type with limited component
1819 elsif Ada_Version
<= Ada_95
then
1820 return Is_Limited_Type
(Typ
);
1824 -- The current instance of a limited tagged type, a protected
1825 -- type, a task type, or a type that has the reserved word
1826 -- "limited" in its full definition ... a formal parameter or
1827 -- generic formal object of a tagged type.
1829 -- Ada 2005 limited type
1830 -- * Type with reserved word "limited", "synchronized", "task"
1832 -- * A composite type with limited component
1833 -- * A derived type whose parent is a non-interface limited type
1835 elsif Ada_Version
= Ada_2005
then
1837 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
1839 (Is_Derived_Type
(Typ
)
1840 and then not Is_Interface
(Etype
(Typ
))
1841 and then Is_Limited_Type
(Etype
(Typ
)));
1843 -- Ada 2012 and beyond
1845 -- The current instance of an immutably limited type ... a formal
1846 -- parameter or generic formal object of a tagged type.
1848 -- Ada 2012 limited type
1849 -- * Type with reserved word "limited", "synchronized", "task"
1851 -- * A composite type with limited component
1852 -- * A derived type whose parent is a non-interface limited type
1853 -- * An incomplete view
1855 -- Ada 2012 immutably limited type
1856 -- * Explicitly limited record type
1857 -- * Record extension with "limited" present
1858 -- * Non-formal limited private type that is either tagged
1859 -- or has at least one access discriminant with a default
1861 -- * Task type, protected type or synchronized interface
1862 -- * Type derived from immutably limited type
1866 Is_Immutably_Limited_Type
(Typ
)
1867 or else Is_Incomplete_Type
(Typ
);
1869 end Is_Aliased_View_Of_Type
;
1875 function Process
(N
: Node_Id
) return Traverse_Result
is
1878 when N_Attribute_Reference
=>
1879 if Nam_In
(Attribute_Name
(N
), Name_Access
,
1880 Name_Unchecked_Access
)
1881 and then Is_Entity_Name
(Prefix
(N
))
1882 and then Is_Type
(Entity
(Prefix
(N
)))
1883 and then Entity
(Prefix
(N
)) = E
1885 if Ada_Version
< Ada_2012
then
1887 ("current instance must be a limited type",
1891 ("current instance must be an immutably limited "
1892 & "type (RM-2012, 7.5 (8.1/3))",
1902 when others => return OK
;
1906 procedure Traverse
is new Traverse_Proc
(Process
);
1910 Rec_Type
: constant Entity_Id
:=
1911 Scope
(Defining_Identifier
(Comp_Decl
));
1913 -- Start of processing for Check_Current_Instance
1916 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
1917 Traverse
(Comp_Decl
);
1919 end Check_Current_Instance
;
1921 ------------------------------
1922 -- Check_Suspicious_Modulus --
1923 ------------------------------
1925 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
1926 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
1929 if not Warn_On_Suspicious_Modulus_Value
then
1933 if Nkind
(Decl
) = N_Full_Type_Declaration
then
1935 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
1938 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
1940 Modulus
: constant Node_Id
:=
1941 Original_Node
(Expression
(Tdef
));
1944 if Nkind
(Modulus
) = N_Integer_Literal
then
1946 Modv
: constant Uint
:= Intval
(Modulus
);
1947 Sizv
: constant Uint
:= RM_Size
(Utype
);
1950 -- First case, modulus and size are the same. This
1951 -- happens if you have something like mod 32, with
1952 -- an explicit size of 32, this is for sure a case
1953 -- where the warning is given, since it is seems
1954 -- very unlikely that someone would want e.g. a
1955 -- five bit type stored in 32 bits. It is much
1956 -- more likely they wanted a 32-bit type.
1961 -- Second case, the modulus is 32 or 64 and no
1962 -- size clause is present. This is a less clear
1963 -- case for giving the warning, but in the case
1964 -- of 32/64 (5-bit or 6-bit types) these seem rare
1965 -- enough that it is a likely error (and in any
1966 -- case using 2**5 or 2**6 in these cases seems
1967 -- clearer. We don't include 8 or 16 here, simply
1968 -- because in practice 3-bit and 4-bit types are
1969 -- more common and too many false positives if
1970 -- we warn in these cases.
1972 elsif not Has_Size_Clause
(Utype
)
1973 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
1977 -- No warning needed
1983 -- If we fall through, give warning
1985 Error_Msg_Uint_1
:= Modv
;
1987 ("?M?2 '*'*^' may have been intended here",
1995 end Check_Suspicious_Modulus
;
1997 -----------------------
1998 -- Freeze_Array_Type --
1999 -----------------------
2001 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2002 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2003 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2006 Non_Standard_Enum
: Boolean := False;
2007 -- Set true if any of the index types is an enumeration type with a
2008 -- non-standard representation.
2011 Freeze_And_Append
(Ctyp
, N
, Result
);
2013 Indx
:= First_Index
(Arr
);
2014 while Present
(Indx
) loop
2015 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2017 if Is_Enumeration_Type
(Etype
(Indx
))
2018 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2020 Non_Standard_Enum
:= True;
2026 -- Processing that is done only for base types
2028 if Ekind
(Arr
) = E_Array_Type
then
2030 -- Propagate flags for component type
2032 if Is_Controlled
(Component_Type
(Arr
))
2033 or else Has_Controlled_Component
(Ctyp
)
2035 Set_Has_Controlled_Component
(Arr
);
2038 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2039 Set_Has_Unchecked_Union
(Arr
);
2042 -- Warn for pragma Pack overriding foreign convention
2044 if Has_Foreign_Convention
(Ctyp
)
2045 and then Has_Pragma_Pack
(Arr
)
2048 CN
: constant Name_Id
:=
2049 Get_Convention_Name
(Convention
(Ctyp
));
2050 PP
: constant Node_Id
:=
2051 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2053 if Present
(PP
) then
2054 Error_Msg_Name_1
:= CN
;
2055 Error_Msg_Sloc
:= Sloc
(Arr
);
2057 ("pragma Pack affects convention % components #??",
2059 Error_Msg_Name_1
:= CN
;
2061 ("\array components may not have % compatible "
2062 & "representation??", PP
);
2067 -- If packing was requested or if the component size was
2068 -- set explicitly, then see if bit packing is required. This
2069 -- processing is only done for base types, since all of the
2070 -- representation aspects involved are type-related.
2072 -- This is not just an optimization, if we start processing the
2073 -- subtypes, they interfere with the settings on the base type
2074 -- (this is because Is_Packed has a slightly different meaning
2075 -- before and after freezing).
2082 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2083 and then Known_Static_RM_Size
(Ctyp
)
2084 and then not Has_Component_Size_Clause
(Arr
)
2086 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2088 elsif Known_Component_Size
(Arr
) then
2089 Csiz
:= Component_Size
(Arr
);
2091 elsif not Known_Static_Esize
(Ctyp
) then
2095 Esiz
:= Esize
(Ctyp
);
2097 -- We can set the component size if it is less than 16,
2098 -- rounding it up to the next storage unit size.
2102 elsif Esiz
<= 16 then
2108 -- Set component size up to match alignment if it would
2109 -- otherwise be less than the alignment. This deals with
2110 -- cases of types whose alignment exceeds their size (the
2111 -- padded type cases).
2115 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2124 -- Case of component size that may result in packing
2126 if 1 <= Csiz
and then Csiz
<= 64 then
2128 Ent
: constant Entity_Id
:=
2129 First_Subtype
(Arr
);
2130 Pack_Pragma
: constant Node_Id
:=
2131 Get_Rep_Pragma
(Ent
, Name_Pack
);
2132 Comp_Size_C
: constant Node_Id
:=
2133 Get_Attribute_Definition_Clause
2134 (Ent
, Attribute_Component_Size
);
2136 -- Warn if we have pack and component size so that the
2139 -- Note: here we must check for the presence of a
2140 -- component size before checking for a Pack pragma to
2141 -- deal with the case where the array type is a derived
2142 -- type whose parent is currently private.
2144 if Present
(Comp_Size_C
)
2145 and then Has_Pragma_Pack
(Ent
)
2146 and then Warn_On_Redundant_Constructs
2148 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2150 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2152 ("\?r?explicit component size given#!", Pack_Pragma
);
2153 Set_Is_Packed
(Base_Type
(Ent
), False);
2154 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2157 -- Set component size if not already set by a component
2160 if not Present
(Comp_Size_C
) then
2161 Set_Component_Size
(Arr
, Csiz
);
2164 -- Check for base type of 8, 16, 32 bits, where an
2165 -- unsigned subtype has a length one less than the
2166 -- base type (e.g. Natural subtype of Integer).
2168 -- In such cases, if a component size was not set
2169 -- explicitly, then generate a warning.
2171 if Has_Pragma_Pack
(Arr
)
2172 and then not Present
(Comp_Size_C
)
2174 (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2175 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2177 Error_Msg_Uint_1
:= Csiz
;
2179 if Present
(Pack_Pragma
) then
2181 ("??pragma Pack causes component size "
2182 & "to be ^!", Pack_Pragma
);
2184 ("\??use Component_Size to set "
2185 & "desired value!", Pack_Pragma
);
2189 -- Actual packing is not needed for 8, 16, 32, 64. Also
2190 -- not needed for 24 if alignment is 1.
2196 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
2198 -- Here the array was requested to be packed, but
2199 -- the packing request had no effect, so Is_Packed
2202 -- Note: semantically this means that we lose track
2203 -- of the fact that a derived type inherited a pragma
2204 -- Pack that was non- effective, but that seems fine.
2206 -- We regard a Pack pragma as a request to set a
2207 -- representation characteristic, and this request
2210 Set_Is_Packed
(Base_Type
(Arr
), False);
2211 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2213 if Known_Static_Esize
(Component_Type
(Arr
))
2214 and then Esize
(Component_Type
(Arr
)) = Csiz
2216 Set_Has_Non_Standard_Rep
2217 (Base_Type
(Arr
), False);
2220 -- In all other cases, packing is indeed needed
2223 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2224 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2225 Set_Is_Packed
(Base_Type
(Arr
), True);
2231 -- Check for Atomic_Components or Aliased with unsuitable packing
2232 -- or explicit component size clause given.
2234 if (Has_Atomic_Components
(Arr
)
2236 Has_Aliased_Components
(Arr
))
2238 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2240 Alias_Atomic_Check
: declare
2242 procedure Complain_CS
(T
: String);
2243 -- Outputs error messages for incorrect CS clause or pragma
2244 -- Pack for aliased or atomic components (T is "aliased" or
2251 procedure Complain_CS
(T
: String) is
2253 if Has_Component_Size_Clause
(Arr
) then
2255 Get_Attribute_Definition_Clause
2256 (FS
, Attribute_Component_Size
);
2258 if Known_Static_Esize
(Ctyp
) then
2260 ("incorrect component size for "
2261 & T
& " components", Clause
);
2262 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2264 ("\only allowed value is^", Clause
);
2268 ("component size cannot be given for "
2269 & T
& " components", Clause
);
2274 ("cannot pack " & T
& " components",
2275 Get_Rep_Pragma
(FS
, Name_Pack
));
2281 -- Start of processing for Alias_Atomic_Check
2284 -- If object size of component type isn't known, we cannot
2285 -- be sure so we defer to the back end.
2287 if not Known_Static_Esize
(Ctyp
) then
2290 -- Case where component size has no effect. First check for
2291 -- object size of component type multiple of the storage
2294 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2296 -- OK in both packing case and component size case if RM
2297 -- size is known and static and same as the object size.
2300 ((Known_Static_RM_Size
(Ctyp
)
2301 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2303 -- Or if we have an explicit component size clause and
2304 -- the component size and object size are equal.
2307 (Has_Component_Size_Clause
(Arr
)
2308 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2312 elsif Has_Aliased_Components
(Arr
)
2313 or else Is_Aliased
(Ctyp
)
2315 Complain_CS
("aliased");
2317 elsif Has_Atomic_Components
(Arr
)
2318 or else Is_Atomic
(Ctyp
)
2320 Complain_CS
("atomic");
2322 end Alias_Atomic_Check
;
2325 -- Warn for case of atomic type
2327 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2330 and then not Addressable
(Component_Size
(FS
))
2333 ("non-atomic components of type& may not be "
2334 & "accessible by separate tasks??", Clause
, Arr
);
2336 if Has_Component_Size_Clause
(Arr
) then
2337 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2338 (FS
, Attribute_Component_Size
));
2339 Error_Msg_N
("\because of component size clause#??", Clause
);
2341 elsif Has_Pragma_Pack
(Arr
) then
2342 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2343 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2347 -- Check for scalar storage order
2349 Check_Component_Storage_Order
2352 ADC
=> Get_Attribute_Definition_Clause
2353 (First_Subtype
(Arr
),
2354 Attribute_Scalar_Storage_Order
));
2356 -- Processing that is done only for subtypes
2359 -- Acquire alignment from base type
2361 if Unknown_Alignment
(Arr
) then
2362 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2363 Adjust_Esize_Alignment
(Arr
);
2367 -- Specific checks for bit-packed arrays
2369 if Is_Bit_Packed_Array
(Arr
) then
2371 -- Check number of elements for bit packed arrays that come from
2372 -- source and have compile time known ranges. The bit-packed
2373 -- arrays circuitry does not support arrays with more than
2374 -- Integer'Last + 1 elements, and when this restriction is
2375 -- violated, causes incorrect data access.
2377 -- For the case where this is not compile time known, a run-time
2378 -- check should be generated???
2380 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
2389 Index
:= First_Index
(Arr
);
2390 while Present
(Index
) loop
2391 Ityp
:= Etype
(Index
);
2393 -- Never generate an error if any index is of a generic
2394 -- type. We will check this in instances.
2396 if Is_Generic_Type
(Ityp
) then
2402 Make_Attribute_Reference
(Loc
,
2404 New_Occurrence_Of
(Ityp
, Loc
),
2405 Attribute_Name
=> Name_Range_Length
);
2406 Analyze_And_Resolve
(Ilen
);
2408 -- No attempt is made to check number of elements
2409 -- if not compile time known.
2411 if Nkind
(Ilen
) /= N_Integer_Literal
then
2416 Elmts
:= Elmts
* Intval
(Ilen
);
2420 if Elmts
> Intval
(High_Bound
2421 (Scalar_Range
(Standard_Integer
))) + 1
2424 ("bit packed array type may not have "
2425 & "more than Integer''Last+1 elements", Arr
);
2432 if Known_RM_Size
(Arr
) then
2434 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
2437 pragma Warnings
(Off
, Discard
);
2440 -- It is not clear if it is possible to have no size clause
2441 -- at this stage, but it is not worth worrying about. Post
2442 -- error on the entity name in the size clause if present,
2443 -- else on the type entity itself.
2445 if Present
(SizC
) then
2446 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
2448 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
2454 -- If any of the index types was an enumeration type with a
2455 -- non-standard rep clause, then we indicate that the array type
2456 -- is always packed (even if it is not bit packed).
2458 if Non_Standard_Enum
then
2459 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
2460 Set_Is_Packed
(Base_Type
(Arr
));
2463 Set_Component_Alignment_If_Not_Set
(Arr
);
2465 -- If the array is packed, we must create the packed array type to be
2466 -- used to actually implement the type. This is only needed for real
2467 -- array types (not for string literal types, since they are present
2468 -- only for the front end).
2471 and then Ekind
(Arr
) /= E_String_Literal_Subtype
2473 Create_Packed_Array_Type
(Arr
);
2474 Freeze_And_Append
(Packed_Array_Type
(Arr
), N
, Result
);
2476 -- Size information of packed array type is copied to the array
2477 -- type, since this is really the representation. But do not
2478 -- override explicit existing size values. If the ancestor subtype
2479 -- is constrained the packed_array_type will be inherited from it,
2480 -- but the size may have been provided already, and must not be
2481 -- overridden either.
2483 if not Has_Size_Clause
(Arr
)
2485 (No
(Ancestor_Subtype
(Arr
))
2486 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
2488 Set_Esize
(Arr
, Esize
(Packed_Array_Type
(Arr
)));
2489 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Type
(Arr
)));
2492 if not Has_Alignment_Clause
(Arr
) then
2493 Set_Alignment
(Arr
, Alignment
(Packed_Array_Type
(Arr
)));
2497 -- For non-packed arrays set the alignment of the array to the
2498 -- alignment of the component type if it is unknown. Skip this
2499 -- in atomic case (atomic arrays may need larger alignments).
2501 if not Is_Packed
(Arr
)
2502 and then Unknown_Alignment
(Arr
)
2503 and then Known_Alignment
(Ctyp
)
2504 and then Known_Static_Component_Size
(Arr
)
2505 and then Known_Static_Esize
(Ctyp
)
2506 and then Esize
(Ctyp
) = Component_Size
(Arr
)
2507 and then not Is_Atomic
(Arr
)
2509 Set_Alignment
(Arr
, Alignment
(Component_Type
(Arr
)));
2511 end Freeze_Array_Type
;
2513 -----------------------------
2514 -- Freeze_Generic_Entities --
2515 -----------------------------
2517 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
2524 E
:= First_Entity
(Pack
);
2525 while Present
(E
) loop
2526 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
2527 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
2529 Append_To
(Flist
, F
);
2531 elsif Ekind
(E
) = E_Generic_Package
then
2532 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
2539 end Freeze_Generic_Entities
;
2541 ------------------------
2542 -- Freeze_Record_Type --
2543 ------------------------
2545 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
2552 pragma Warnings
(Off
, Junk
);
2554 Rec_Pushed
: Boolean := False;
2555 -- Set True if the record type scope Rec has been pushed on the scope
2556 -- stack. Needed for the analysis of delayed aspects specified to the
2557 -- components of Rec.
2559 Unplaced_Component
: Boolean := False;
2560 -- Set True if we find at least one component with no component
2561 -- clause (used to warn about useless Pack pragmas).
2563 Placed_Component
: Boolean := False;
2564 -- Set True if we find at least one component with a component
2565 -- clause (used to warn about useless Bit_Order pragmas, and also
2566 -- to detect cases where Implicit_Packing may have an effect).
2568 Aliased_Component
: Boolean := False;
2569 -- Set True if we find at least one component which is aliased. This
2570 -- is used to prevent Implicit_Packing of the record, since packing
2571 -- cannot modify the size of alignment of an aliased component.
2573 All_Scalar_Components
: Boolean := True;
2574 -- Set False if we encounter a component of a non-scalar type
2576 Scalar_Component_Total_RM_Size
: Uint
:= Uint_0
;
2577 Scalar_Component_Total_Esize
: Uint
:= Uint_0
;
2578 -- Accumulates total RM_Size values and total Esize values of all
2579 -- scalar components. Used for processing of Implicit_Packing.
2581 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
2582 -- If N is an allocator, possibly wrapped in one or more level of
2583 -- qualified expression(s), return the inner allocator node, else
2586 procedure Check_Itype
(Typ
: Entity_Id
);
2587 -- If the component subtype is an access to a constrained subtype of
2588 -- an already frozen type, make the subtype frozen as well. It might
2589 -- otherwise be frozen in the wrong scope, and a freeze node on
2590 -- subtype has no effect. Similarly, if the component subtype is a
2591 -- regular (not protected) access to subprogram, set the anonymous
2592 -- subprogram type to frozen as well, to prevent an out-of-scope
2593 -- freeze node at some eventual point of call. Protected operations
2594 -- are handled elsewhere.
2596 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
2597 -- Make sure that all types mentioned in Discrete_Choices of the
2598 -- variants referenceed by the Variant_Part VP are frozen. This is
2599 -- a recursive routine to deal with nested variants.
2601 ---------------------
2602 -- Check_Allocator --
2603 ---------------------
2605 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
2610 if Nkind
(Inner
) = N_Allocator
then
2612 elsif Nkind
(Inner
) = N_Qualified_Expression
then
2613 Inner
:= Expression
(Inner
);
2618 end Check_Allocator
;
2624 procedure Check_Itype
(Typ
: Entity_Id
) is
2625 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
2628 if not Is_Frozen
(Desig
)
2629 and then Is_Frozen
(Base_Type
(Desig
))
2631 Set_Is_Frozen
(Desig
);
2633 -- In addition, add an Itype_Reference to ensure that the
2634 -- access subtype is elaborated early enough. This cannot be
2635 -- done if the subtype may depend on discriminants.
2637 if Ekind
(Comp
) = E_Component
2638 and then Is_Itype
(Etype
(Comp
))
2639 and then not Has_Discriminants
(Rec
)
2641 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
2642 Set_Itype
(IR
, Desig
);
2646 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
2647 and then Convention
(Desig
) /= Convention_Protected
2649 Set_Is_Frozen
(Desig
);
2653 ------------------------------------
2654 -- Freeze_Choices_In_Variant_Part --
2655 ------------------------------------
2657 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
2658 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
2665 -- Loop through variants
2667 Variant
:= First_Non_Pragma
(Variants
(VP
));
2668 while Present
(Variant
) loop
2670 -- Loop through choices, checking that all types are frozen
2672 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
2673 while Present
(Choice
) loop
2674 if Nkind
(Choice
) in N_Has_Etype
2675 and then Present
(Etype
(Choice
))
2677 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
2680 Next_Non_Pragma
(Choice
);
2683 -- Check for nested variant part to process
2685 CL
:= Component_List
(Variant
);
2687 if not Null_Present
(CL
) then
2688 if Present
(Variant_Part
(CL
)) then
2689 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
2693 Next_Non_Pragma
(Variant
);
2695 end Freeze_Choices_In_Variant_Part
;
2697 -- Start of processing for Freeze_Record_Type
2700 -- Deal with delayed aspect specifications for components. The
2701 -- analysis of the aspect is required to be delayed to the freeze
2702 -- point, thus we analyze the pragma or attribute definition
2703 -- clause in the tree at this point. We also analyze the aspect
2704 -- specification node at the freeze point when the aspect doesn't
2705 -- correspond to pragma/attribute definition clause.
2707 Comp
:= First_Entity
(Rec
);
2708 while Present
(Comp
) loop
2709 if Ekind
(Comp
) = E_Component
2710 and then Has_Delayed_Aspects
(Comp
)
2712 if not Rec_Pushed
then
2716 -- The visibility to the discriminants must be restored in
2717 -- order to properly analyze the aspects.
2719 if Has_Discriminants
(Rec
) then
2720 Install_Discriminants
(Rec
);
2724 Analyze_Aspects_At_Freeze_Point
(Comp
);
2730 -- Pop the scope if Rec scope has been pushed on the scope stack
2731 -- during the delayed aspect analysis process.
2734 if Has_Discriminants
(Rec
) then
2735 Uninstall_Discriminants
(Rec
);
2741 -- Freeze components and embedded subtypes
2743 Comp
:= First_Entity
(Rec
);
2745 while Present
(Comp
) loop
2746 if Is_Aliased
(Comp
) then
2747 Aliased_Component
:= True;
2750 -- Handle the component and discriminant case
2752 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
2754 CC
: constant Node_Id
:= Component_Clause
(Comp
);
2757 -- Freezing a record type freezes the type of each of its
2758 -- components. However, if the type of the component is
2759 -- part of this record, we do not want or need a separate
2760 -- Freeze_Node. Note that Is_Itype is wrong because that's
2761 -- also set in private type cases. We also can't check for
2762 -- the Scope being exactly Rec because of private types and
2763 -- record extensions.
2765 if Is_Itype
(Etype
(Comp
))
2766 and then Is_Record_Type
(Underlying_Type
2767 (Scope
(Etype
(Comp
))))
2769 Undelay_Type
(Etype
(Comp
));
2772 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
2774 -- Warn for pragma Pack overriding foreign convention
2776 if Has_Foreign_Convention
(Etype
(Comp
))
2777 and then Has_Pragma_Pack
(Rec
)
2779 -- Don't warn for aliased components, since override
2780 -- cannot happen in that case.
2782 and then not Is_Aliased
(Comp
)
2785 CN
: constant Name_Id
:=
2786 Get_Convention_Name
(Convention
(Etype
(Comp
)));
2787 PP
: constant Node_Id
:=
2788 Get_Pragma
(Rec
, Pragma_Pack
);
2790 if Present
(PP
) then
2791 Error_Msg_Name_1
:= CN
;
2792 Error_Msg_Sloc
:= Sloc
(Comp
);
2794 ("pragma Pack affects convention % component#??",
2796 Error_Msg_Name_1
:= CN
;
2798 ("\component & may not have % compatible "
2799 & "representation??", PP
, Comp
);
2804 -- Check for error of component clause given for variable
2805 -- sized type. We have to delay this test till this point,
2806 -- since the component type has to be frozen for us to know
2807 -- if it is variable length.
2809 if Present
(CC
) then
2810 Placed_Component
:= True;
2812 -- We omit this test in a generic context, it will be
2813 -- applied at instantiation time.
2815 if Inside_A_Generic
then
2818 -- Also omit this test in CodePeer mode, since we do not
2819 -- have sufficient info on size and rep clauses.
2821 elsif CodePeer_Mode
then
2827 Size_Known_At_Compile_Time
2828 (Underlying_Type
(Etype
(Comp
)))
2831 ("component clause not allowed for variable " &
2832 "length component", CC
);
2836 Unplaced_Component
:= True;
2839 -- Case of component requires byte alignment
2841 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
2843 -- Set the enclosing record to also require byte align
2845 Set_Must_Be_On_Byte_Boundary
(Rec
);
2847 -- Check for component clause that is inconsistent with
2848 -- the required byte boundary alignment.
2851 and then Normalized_First_Bit
(Comp
) mod
2852 System_Storage_Unit
/= 0
2855 ("component & must be byte aligned",
2856 Component_Name
(Component_Clause
(Comp
)));
2862 -- Gather data for possible Implicit_Packing later. Note that at
2863 -- this stage we might be dealing with a real component, or with
2864 -- an implicit subtype declaration.
2866 if not Is_Scalar_Type
(Etype
(Comp
)) then
2867 All_Scalar_Components
:= False;
2869 Scalar_Component_Total_RM_Size
:=
2870 Scalar_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
2871 Scalar_Component_Total_Esize
:=
2872 Scalar_Component_Total_Esize
+ Esize
(Etype
(Comp
));
2875 -- If the component is an Itype with Delayed_Freeze and is either
2876 -- a record or array subtype and its base type has not yet been
2877 -- frozen, we must remove this from the entity list of this record
2878 -- and put it on the entity list of the scope of its base type.
2879 -- Note that we know that this is not the type of a component
2880 -- since we cleared Has_Delayed_Freeze for it in the previous
2881 -- loop. Thus this must be the Designated_Type of an access type,
2882 -- which is the type of a component.
2885 and then Is_Type
(Scope
(Comp
))
2886 and then Is_Composite_Type
(Comp
)
2887 and then Base_Type
(Comp
) /= Comp
2888 and then Has_Delayed_Freeze
(Comp
)
2889 and then not Is_Frozen
(Base_Type
(Comp
))
2892 Will_Be_Frozen
: Boolean := False;
2896 -- We have a pretty bad kludge here. Suppose Rec is subtype
2897 -- being defined in a subprogram that's created as part of
2898 -- the freezing of Rec'Base. In that case, we know that
2899 -- Comp'Base must have already been frozen by the time we
2900 -- get to elaborate this because Gigi doesn't elaborate any
2901 -- bodies until it has elaborated all of the declarative
2902 -- part. But Is_Frozen will not be set at this point because
2903 -- we are processing code in lexical order.
2905 -- We detect this case by going up the Scope chain of Rec
2906 -- and seeing if we have a subprogram scope before reaching
2907 -- the top of the scope chain or that of Comp'Base. If we
2908 -- do, then mark that Comp'Base will actually be frozen. If
2909 -- so, we merely undelay it.
2912 while Present
(S
) loop
2913 if Is_Subprogram
(S
) then
2914 Will_Be_Frozen
:= True;
2916 elsif S
= Scope
(Base_Type
(Comp
)) then
2923 if Will_Be_Frozen
then
2924 Undelay_Type
(Comp
);
2926 if Present
(Prev
) then
2927 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
2929 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
2932 -- Insert in entity list of scope of base type (which
2933 -- must be an enclosing scope, because still unfrozen).
2935 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
2939 -- If the component is an access type with an allocator as default
2940 -- value, the designated type will be frozen by the corresponding
2941 -- expression in init_proc. In order to place the freeze node for
2942 -- the designated type before that for the current record type,
2945 -- Same process if the component is an array of access types,
2946 -- initialized with an aggregate. If the designated type is
2947 -- private, it cannot contain allocators, and it is premature
2948 -- to freeze the type, so we check for this as well.
2950 elsif Is_Access_Type
(Etype
(Comp
))
2951 and then Present
(Parent
(Comp
))
2952 and then Present
(Expression
(Parent
(Comp
)))
2955 Alloc
: constant Node_Id
:=
2956 Check_Allocator
(Expression
(Parent
(Comp
)));
2959 if Present
(Alloc
) then
2961 -- If component is pointer to a class-wide type, freeze
2962 -- the specific type in the expression being allocated.
2963 -- The expression may be a subtype indication, in which
2964 -- case freeze the subtype mark.
2966 if Is_Class_Wide_Type
2967 (Designated_Type
(Etype
(Comp
)))
2969 if Is_Entity_Name
(Expression
(Alloc
)) then
2971 (Entity
(Expression
(Alloc
)), N
, Result
);
2973 Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
2976 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
2980 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
2981 Check_Itype
(Etype
(Comp
));
2985 (Designated_Type
(Etype
(Comp
)), N
, Result
);
2990 elsif Is_Access_Type
(Etype
(Comp
))
2991 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
2993 Check_Itype
(Etype
(Comp
));
2995 elsif Is_Array_Type
(Etype
(Comp
))
2996 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
2997 and then Present
(Parent
(Comp
))
2998 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
2999 and then Present
(Expression
(Parent
(Comp
)))
3000 and then Nkind
(Expression
(Parent
(Comp
))) = N_Aggregate
3001 and then Is_Fully_Defined
3002 (Designated_Type
(Component_Type
(Etype
(Comp
))))
3006 (Component_Type
(Etype
(Comp
))), N
, Result
);
3013 ADC
:= Get_Attribute_Definition_Clause
3014 (Rec
, Attribute_Scalar_Storage_Order
);
3016 if Present
(ADC
) then
3018 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
3019 -- the former is specified.
3021 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
3023 -- Note: report error on Rec, not on ADC, as ADC may apply to
3024 -- an ancestor type.
3026 Error_Msg_Sloc
:= Sloc
(ADC
);
3028 ("scalar storage order for& specified# inconsistent with "
3029 & "bit order", Rec
);
3032 -- Warn if there is a Scalar_Storage_Order but no component clause
3033 -- (or pragma Pack).
3035 if not (Placed_Component
or else Is_Packed
(Rec
)) then
3037 ("??scalar storage order specified but no component clause",
3042 -- Check consistent attribute setting on component types
3044 Comp
:= First_Component
(Rec
);
3045 while Present
(Comp
) loop
3046 Check_Component_Storage_Order
3047 (Encl_Type
=> Rec
, Comp
=> Comp
, ADC
=> ADC
);
3048 Next_Component
(Comp
);
3051 -- Deal with Bit_Order aspect specifying a non-default bit order
3053 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
3055 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
3056 if not (Placed_Component
or else Is_Packed
(Rec
)) then
3058 ("??bit order specification has no effect", ADC
);
3060 ("\??since no component clauses were specified", ADC
);
3062 -- Here is where we do the processing for reversed bit order
3064 elsif Reverse_Bit_Order
(Rec
)
3065 and then not Reverse_Storage_Order
(Rec
)
3067 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
3069 -- Case where we have both an explicit Bit_Order and the same
3070 -- Scalar_Storage_Order: leave record untouched, the back-end
3071 -- will take care of required layout conversions.
3079 -- Complete error checking on record representation clause (e.g.
3080 -- overlap of components). This is called after adjusting the
3081 -- record for reverse bit order.
3084 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
3086 if Present
(RRC
) then
3087 Check_Record_Representation_Clause
(RRC
);
3091 -- Set OK_To_Reorder_Components depending on debug flags
3093 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
3094 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
3096 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
3098 Set_OK_To_Reorder_Components
(Rec
);
3102 -- Check for useless pragma Pack when all components placed. We only
3103 -- do this check for record types, not subtypes, since a subtype may
3104 -- have all its components placed, and it still makes perfectly good
3105 -- sense to pack other subtypes or the parent type. We do not give
3106 -- this warning if Optimize_Alignment is set to Space, since the
3107 -- pragma Pack does have an effect in this case (it always resets
3108 -- the alignment to one).
3110 if Ekind
(Rec
) = E_Record_Type
3111 and then Is_Packed
(Rec
)
3112 and then not Unplaced_Component
3113 and then Optimize_Alignment
/= 'S'
3115 -- Reset packed status. Probably not necessary, but we do it so
3116 -- that there is no chance of the back end doing something strange
3117 -- with this redundant indication of packing.
3119 Set_Is_Packed
(Rec
, False);
3121 -- Give warning if redundant constructs warnings on
3123 if Warn_On_Redundant_Constructs
then
3124 Error_Msg_N
-- CODEFIX
3125 ("??pragma Pack has no effect, no unplaced components",
3126 Get_Rep_Pragma
(Rec
, Name_Pack
));
3130 -- If this is the record corresponding to a remote type, freeze the
3131 -- remote type here since that is what we are semantically freezing.
3132 -- This prevents the freeze node for that type in an inner scope.
3134 if Ekind
(Rec
) = E_Record_Type
then
3135 if Present
(Corresponding_Remote_Type
(Rec
)) then
3136 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
3139 -- Check for controlled components and unchecked unions.
3141 Comp
:= First_Component
(Rec
);
3142 while Present
(Comp
) loop
3144 -- Do not set Has_Controlled_Component on a class-wide
3145 -- equivalent type. See Make_CW_Equivalent_Type.
3147 if not Is_Class_Wide_Equivalent_Type
(Rec
)
3149 (Has_Controlled_Component
(Etype
(Comp
))
3151 (Chars
(Comp
) /= Name_uParent
3152 and then Is_Controlled
(Etype
(Comp
)))
3154 (Is_Protected_Type
(Etype
(Comp
))
3156 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
3158 Has_Controlled_Component
3159 (Corresponding_Record_Type
(Etype
(Comp
)))))
3161 Set_Has_Controlled_Component
(Rec
);
3164 if Has_Unchecked_Union
(Etype
(Comp
)) then
3165 Set_Has_Unchecked_Union
(Rec
);
3168 -- Scan component declaration for likely misuses of current
3169 -- instance, either in a constraint or a default expression.
3171 if Has_Per_Object_Constraint
(Comp
) then
3172 Check_Current_Instance
(Parent
(Comp
));
3175 Next_Component
(Comp
);
3179 -- Enforce the restriction that access attributes with a current
3180 -- instance prefix can only apply to limited types. This comment
3181 -- is floating here, but does not seem to belong here???
3183 -- Set component alignment if not otherwise already set
3185 Set_Component_Alignment_If_Not_Set
(Rec
);
3187 -- For first subtypes, check if there are any fixed-point fields with
3188 -- component clauses, where we must check the size. This is not done
3189 -- till the freeze point since for fixed-point types, we do not know
3190 -- the size until the type is frozen. Similar processing applies to
3191 -- bit packed arrays.
3193 if Is_First_Subtype
(Rec
) then
3194 Comp
:= First_Component
(Rec
);
3195 while Present
(Comp
) loop
3196 if Present
(Component_Clause
(Comp
))
3197 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
3199 Is_Bit_Packed_Array
(Etype
(Comp
)))
3202 (Component_Name
(Component_Clause
(Comp
)),
3208 Next_Component
(Comp
);
3212 -- Generate warning for applying C or C++ convention to a record
3213 -- with discriminants. This is suppressed for the unchecked union
3214 -- case, since the whole point in this case is interface C. We also
3215 -- do not generate this within instantiations, since we will have
3216 -- generated a message on the template.
3218 if Has_Discriminants
(E
)
3219 and then not Is_Unchecked_Union
(E
)
3220 and then (Convention
(E
) = Convention_C
3222 Convention
(E
) = Convention_CPP
)
3223 and then Comes_From_Source
(E
)
3224 and then not In_Instance
3225 and then not Has_Warnings_Off
(E
)
3226 and then not Has_Warnings_Off
(Base_Type
(E
))
3229 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
3233 if Present
(Cprag
) then
3234 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3236 if Convention
(E
) = Convention_C
then
3238 ("?x?variant record has no direct equivalent in C",
3242 ("?x?variant record has no direct equivalent in C++",
3247 ("\?x?use of convention for type& is dubious", A2
, E
);
3252 -- See if Size is too small as is (and implicit packing might help)
3254 if not Is_Packed
(Rec
)
3256 -- No implicit packing if even one component is explicitly placed
3258 and then not Placed_Component
3260 -- Or even one component is aliased
3262 and then not Aliased_Component
3264 -- Must have size clause and all scalar components
3266 and then Has_Size_Clause
(Rec
)
3267 and then All_Scalar_Components
3269 -- Do not try implicit packing on records with discriminants, too
3270 -- complicated, especially in the variant record case.
3272 and then not Has_Discriminants
(Rec
)
3274 -- We can implicitly pack if the specified size of the record is
3275 -- less than the sum of the object sizes (no point in packing if
3276 -- this is not the case).
3278 and then RM_Size
(Rec
) < Scalar_Component_Total_Esize
3280 -- And the total RM size cannot be greater than the specified size
3281 -- since otherwise packing will not get us where we have to be.
3283 and then RM_Size
(Rec
) >= Scalar_Component_Total_RM_Size
3285 -- Never do implicit packing in CodePeer or SPARK modes since
3286 -- we don't do any packing in these modes, since this generates
3287 -- over-complex code that confuses static analysis, and in
3288 -- general, neither CodePeer not GNATprove care about the
3289 -- internal representation of objects.
3291 and then not (CodePeer_Mode
or GNATprove_Mode
)
3293 -- If implicit packing enabled, do it
3295 if Implicit_Packing
then
3296 Set_Is_Packed
(Rec
);
3298 -- Otherwise flag the size clause
3302 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
3304 Error_Msg_NE
-- CODEFIX
3305 ("size given for& too small", Sz
, Rec
);
3306 Error_Msg_N
-- CODEFIX
3307 ("\use explicit pragma Pack "
3308 & "or use pragma Implicit_Packing", Sz
);
3313 -- All done if not a full record definition
3315 if Ekind
(Rec
) /= E_Record_Type
then
3319 -- Finally we need to check the variant part to make sure that
3320 -- all types within choices are properly frozen as part of the
3321 -- freezing of the record type.
3323 Check_Variant_Part
: declare
3324 D
: constant Node_Id
:= Declaration_Node
(Rec
);
3329 -- Find component list
3333 if Nkind
(D
) = N_Full_Type_Declaration
then
3334 T
:= Type_Definition
(D
);
3336 if Nkind
(T
) = N_Record_Definition
then
3337 C
:= Component_List
(T
);
3339 elsif Nkind
(T
) = N_Derived_Type_Definition
3340 and then Present
(Record_Extension_Part
(T
))
3342 C
:= Component_List
(Record_Extension_Part
(T
));
3346 -- Case of variant part present
3348 if Present
(C
) and then Present
(Variant_Part
(C
)) then
3349 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
3352 -- Note: we used to call Check_Choices here, but it is too early,
3353 -- since predicated subtypes are frozen here, but their freezing
3354 -- actions are in Analyze_Freeze_Entity, which has not been called
3355 -- yet for entities frozen within this procedure, so we moved that
3356 -- call to the Analyze_Freeze_Entity for the record type.
3358 end Check_Variant_Part
;
3359 end Freeze_Record_Type
;
3361 -- Start of processing for Freeze_Entity
3364 -- We are going to test for various reasons why this entity need not be
3365 -- frozen here, but in the case of an Itype that's defined within a
3366 -- record, that test actually applies to the record.
3368 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
3369 Test_E
:= Scope
(E
);
3370 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
3371 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
3373 Test_E
:= Underlying_Type
(Scope
(E
));
3376 -- Do not freeze if already frozen since we only need one freeze node
3378 if Is_Frozen
(E
) then
3381 -- It is improper to freeze an external entity within a generic because
3382 -- its freeze node will appear in a non-valid context. The entity will
3383 -- be frozen in the proper scope after the current generic is analyzed.
3384 -- However, aspects must be analyzed because they may be queried later
3385 -- within the generic itself, and the corresponding pragma or attribute
3386 -- definition has not been analyzed yet.
3388 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
3389 if Has_Delayed_Aspects
(E
) then
3390 Analyze_Aspects_At_Freeze_Point
(E
);
3395 -- AI05-0213: A formal incomplete type does not freeze the actual. In
3396 -- the instance, the same applies to the subtype renaming the actual.
3398 elsif Is_Private_Type
(E
)
3399 and then Is_Generic_Actual_Type
(E
)
3400 and then No
(Full_View
(Base_Type
(E
)))
3401 and then Ada_Version
>= Ada_2012
3405 -- Generic types need no freeze node and have no delayed semantic
3408 elsif Is_Generic_Type
(E
) then
3411 -- Do not freeze a global entity within an inner scope created during
3412 -- expansion. A call to subprogram E within some internal procedure
3413 -- (a stream attribute for example) might require freezing E, but the
3414 -- freeze node must appear in the same declarative part as E itself.
3415 -- The two-pass elaboration mechanism in gigi guarantees that E will
3416 -- be frozen before the inner call is elaborated. We exclude constants
3417 -- from this test, because deferred constants may be frozen early, and
3418 -- must be diagnosed (e.g. in the case of a deferred constant being used
3419 -- in a default expression). If the enclosing subprogram comes from
3420 -- source, or is a generic instance, then the freeze point is the one
3421 -- mandated by the language, and we freeze the entity. A subprogram that
3422 -- is a child unit body that acts as a spec does not have a spec that
3423 -- comes from source, but can only come from source.
3425 elsif In_Open_Scopes
(Scope
(Test_E
))
3426 and then Scope
(Test_E
) /= Current_Scope
3427 and then Ekind
(Test_E
) /= E_Constant
3434 while Present
(S
) loop
3435 if Is_Overloadable
(S
) then
3436 if Comes_From_Source
(S
)
3437 or else Is_Generic_Instance
(S
)
3438 or else Is_Child_Unit
(S
)
3450 -- Similarly, an inlined instance body may make reference to global
3451 -- entities, but these references cannot be the proper freezing point
3452 -- for them, and in the absence of inlining freezing will take place in
3453 -- their own scope. Normally instance bodies are analyzed after the
3454 -- enclosing compilation, and everything has been frozen at the proper
3455 -- place, but with front-end inlining an instance body is compiled
3456 -- before the end of the enclosing scope, and as a result out-of-order
3457 -- freezing must be prevented.
3459 elsif Front_End_Inlining
3460 and then In_Instance_Body
3461 and then Present
(Scope
(Test_E
))
3467 S
:= Scope
(Test_E
);
3468 while Present
(S
) loop
3469 if Is_Generic_Instance
(S
) then
3481 elsif Ekind
(E
) = E_Generic_Package
then
3482 return Freeze_Generic_Entities
(E
);
3485 -- Add checks to detect proper initialization of scalars that may appear
3486 -- as subprogram parameters.
3488 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
3489 Apply_Parameter_Validity_Checks
(E
);
3492 -- Deal with delayed aspect specifications. The analysis of the aspect
3493 -- is required to be delayed to the freeze point, thus we analyze the
3494 -- pragma or attribute definition clause in the tree at this point. We
3495 -- also analyze the aspect specification node at the freeze point when
3496 -- the aspect doesn't correspond to pragma/attribute definition clause.
3498 if Has_Delayed_Aspects
(E
) then
3499 Analyze_Aspects_At_Freeze_Point
(E
);
3502 -- Here to freeze the entity
3506 -- Case of entity being frozen is other than a type
3508 if not Is_Type
(E
) then
3510 -- If entity is exported or imported and does not have an external
3511 -- name, now is the time to provide the appropriate default name.
3512 -- Skip this if the entity is stubbed, since we don't need a name
3513 -- for any stubbed routine. For the case on intrinsics, if no
3514 -- external name is specified, then calls will be handled in
3515 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
3516 -- external name is provided, then Expand_Intrinsic_Call leaves
3517 -- calls in place for expansion by GIGI.
3519 if (Is_Imported
(E
) or else Is_Exported
(E
))
3520 and then No
(Interface_Name
(E
))
3521 and then Convention
(E
) /= Convention_Stubbed
3522 and then Convention
(E
) /= Convention_Intrinsic
3524 Set_Encoded_Interface_Name
3525 (E
, Get_Default_External_Name
(E
));
3527 -- If entity is an atomic object appearing in a declaration and
3528 -- the expression is an aggregate, assign it to a temporary to
3529 -- ensure that the actual assignment is done atomically rather
3530 -- than component-wise (the assignment to the temp may be done
3531 -- component-wise, but that is harmless).
3534 and then Nkind
(Parent
(E
)) = N_Object_Declaration
3535 and then Present
(Expression
(Parent
(E
)))
3536 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
3537 and then Is_Atomic_Aggregate
(Expression
(Parent
(E
)), Etype
(E
))
3542 -- For a subprogram, freeze all parameter types and also the return
3543 -- type (RM 13.14(14)). However skip this for internal subprograms.
3544 -- This is also the point where any extra formal parameters are
3545 -- created since we now know whether the subprogram will use a
3546 -- foreign convention.
3548 if Is_Subprogram
(E
) then
3549 if not Is_Internal
(E
) then
3553 Warn_Node
: Node_Id
;
3556 -- Loop through formals
3558 Formal
:= First_Formal
(E
);
3559 while Present
(Formal
) loop
3560 F_Type
:= Etype
(Formal
);
3562 -- AI05-0151 : incomplete types can appear in a profile.
3563 -- By the time the entity is frozen, the full view must
3564 -- be available, unless it is a limited view.
3566 if Is_Incomplete_Type
(F_Type
)
3567 and then Present
(Full_View
(F_Type
))
3568 and then not From_Limited_With
(F_Type
)
3570 F_Type
:= Full_View
(F_Type
);
3571 Set_Etype
(Formal
, F_Type
);
3574 Freeze_And_Append
(F_Type
, N
, Result
);
3576 if Is_Private_Type
(F_Type
)
3577 and then Is_Private_Type
(Base_Type
(F_Type
))
3578 and then No
(Full_View
(Base_Type
(F_Type
)))
3579 and then not Is_Generic_Type
(F_Type
)
3580 and then not Is_Derived_Type
(F_Type
)
3582 -- If the type of a formal is incomplete, subprogram
3583 -- is being frozen prematurely. Within an instance
3584 -- (but not within a wrapper package) this is an
3585 -- artifact of our need to regard the end of an
3586 -- instantiation as a freeze point. Otherwise it is
3587 -- a definite error.
3590 Set_Is_Frozen
(E
, False);
3593 elsif not After_Last_Declaration
3594 and then not Freezing_Library_Level_Tagged_Type
3596 Error_Msg_Node_1
:= F_Type
;
3598 ("type& must be fully defined before this point",
3603 -- Check suspicious parameter for C function. These tests
3604 -- apply only to exported/imported subprograms.
3606 if Warn_On_Export_Import
3607 and then Comes_From_Source
(E
)
3608 and then (Convention
(E
) = Convention_C
3610 Convention
(E
) = Convention_CPP
)
3611 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3612 and then Convention
(E
) /= Convention
(Formal
)
3613 and then not Has_Warnings_Off
(E
)
3614 and then not Has_Warnings_Off
(F_Type
)
3615 and then not Has_Warnings_Off
(Formal
)
3617 -- Qualify mention of formals with subprogram name
3619 Error_Msg_Qual_Level
:= 1;
3621 -- Check suspicious use of fat C pointer
3623 if Is_Access_Type
(F_Type
)
3624 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
3627 ("?x?type of & does not correspond to C pointer!",
3630 -- Check suspicious return of boolean
3632 elsif Root_Type
(F_Type
) = Standard_Boolean
3633 and then Convention
(F_Type
) = Convention_Ada
3634 and then not Has_Warnings_Off
(F_Type
)
3635 and then not Has_Size_Clause
(F_Type
)
3636 and then VM_Target
= No_VM
3639 ("& is an 8-bit Ada Boolean?x?", Formal
);
3641 ("\use appropriate corresponding type in C "
3642 & "(e.g. char)?x?", Formal
);
3644 -- Check suspicious tagged type
3646 elsif (Is_Tagged_Type
(F_Type
)
3647 or else (Is_Access_Type
(F_Type
)
3650 (Designated_Type
(F_Type
))))
3651 and then Convention
(E
) = Convention_C
3654 ("?x?& involves a tagged type which does not "
3655 & "correspond to any C type!", Formal
);
3657 -- Check wrong convention subprogram pointer
3659 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
3660 and then not Has_Foreign_Convention
(F_Type
)
3663 ("?x?subprogram pointer & should "
3664 & "have foreign convention!", Formal
);
3665 Error_Msg_Sloc
:= Sloc
(F_Type
);
3667 ("\?x?add Convention pragma to declaration of &#",
3671 -- Turn off name qualification after message output
3673 Error_Msg_Qual_Level
:= 0;
3676 -- Check for unconstrained array in exported foreign
3679 if Has_Foreign_Convention
(E
)
3680 and then not Is_Imported
(E
)
3681 and then Is_Array_Type
(F_Type
)
3682 and then not Is_Constrained
(F_Type
)
3683 and then Warn_On_Export_Import
3685 -- Exclude VM case, since both .NET and JVM can handle
3686 -- unconstrained arrays without a problem.
3688 and then VM_Target
= No_VM
3690 Error_Msg_Qual_Level
:= 1;
3692 -- If this is an inherited operation, place the
3693 -- warning on the derived type declaration, rather
3694 -- than on the original subprogram.
3696 if Nkind
(Original_Node
(Parent
(E
))) =
3697 N_Full_Type_Declaration
3699 Warn_Node
:= Parent
(E
);
3701 if Formal
= First_Formal
(E
) then
3703 ("??in inherited operation&", Warn_Node
, E
);
3706 Warn_Node
:= Formal
;
3710 ("?x?type of argument& is unconstrained array",
3713 ("?x?foreign caller must pass bounds explicitly",
3715 Error_Msg_Qual_Level
:= 0;
3718 if not From_Limited_With
(F_Type
) then
3719 if Is_Access_Type
(F_Type
) then
3720 F_Type
:= Designated_Type
(F_Type
);
3723 -- If the formal is an anonymous_access_to_subprogram
3724 -- freeze the subprogram type as well, to prevent
3725 -- scope anomalies in gigi, because there is no other
3726 -- clear point at which it could be frozen.
3728 if Is_Itype
(Etype
(Formal
))
3729 and then Ekind
(F_Type
) = E_Subprogram_Type
3731 Freeze_And_Append
(F_Type
, N
, Result
);
3735 Next_Formal
(Formal
);
3738 -- Case of function: similar checks on return type
3740 if Ekind
(E
) = E_Function
then
3742 -- Freeze return type
3744 R_Type
:= Etype
(E
);
3746 -- AI05-0151: the return type may have been incomplete
3747 -- at the point of declaration. Replace it with the full
3748 -- view, unless the current type is a limited view. In
3749 -- that case the full view is in a different unit, and
3750 -- gigi finds the non-limited view after the other unit
3753 if Ekind
(R_Type
) = E_Incomplete_Type
3754 and then Present
(Full_View
(R_Type
))
3755 and then not From_Limited_With
(R_Type
)
3757 R_Type
:= Full_View
(R_Type
);
3758 Set_Etype
(E
, R_Type
);
3761 Freeze_And_Append
(R_Type
, N
, Result
);
3763 -- Check suspicious return type for C function
3765 if Warn_On_Export_Import
3766 and then (Convention
(E
) = Convention_C
3768 Convention
(E
) = Convention_CPP
)
3769 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3771 -- Check suspicious return of fat C pointer
3773 if Is_Access_Type
(R_Type
)
3774 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
3775 and then not Has_Warnings_Off
(E
)
3776 and then not Has_Warnings_Off
(R_Type
)
3779 ("?x?return type of& does not "
3780 & "correspond to C pointer!", E
);
3782 -- Check suspicious return of boolean
3784 elsif Root_Type
(R_Type
) = Standard_Boolean
3785 and then Convention
(R_Type
) = Convention_Ada
3786 and then VM_Target
= No_VM
3787 and then not Has_Warnings_Off
(E
)
3788 and then not Has_Warnings_Off
(R_Type
)
3789 and then not Has_Size_Clause
(R_Type
)
3792 N
: constant Node_Id
:=
3793 Result_Definition
(Declaration_Node
(E
));
3796 ("return type of & is an 8-bit Ada Boolean?x?",
3799 ("\use appropriate corresponding type in C "
3800 & "(e.g. char)?x?", N
, E
);
3803 -- Check suspicious return tagged type
3805 elsif (Is_Tagged_Type
(R_Type
)
3806 or else (Is_Access_Type
(R_Type
)
3809 (Designated_Type
(R_Type
))))
3810 and then Convention
(E
) = Convention_C
3811 and then not Has_Warnings_Off
(E
)
3812 and then not Has_Warnings_Off
(R_Type
)
3815 ("?x?return type of & does not "
3816 & "correspond to C type!", E
);
3818 -- Check return of wrong convention subprogram pointer
3820 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3821 and then not Has_Foreign_Convention
(R_Type
)
3822 and then not Has_Warnings_Off
(E
)
3823 and then not Has_Warnings_Off
(R_Type
)
3826 ("?x?& should return a foreign "
3827 & "convention subprogram pointer", E
);
3828 Error_Msg_Sloc
:= Sloc
(R_Type
);
3830 ("\?x?add Convention pragma to declaration of& #",
3835 -- Give warning for suspicious return of a result of an
3836 -- unconstrained array type in a foreign convention
3839 if Has_Foreign_Convention
(E
)
3841 -- We are looking for a return of unconstrained array
3843 and then Is_Array_Type
(R_Type
)
3844 and then not Is_Constrained
(R_Type
)
3846 -- Exclude imported routines, the warning does not
3847 -- belong on the import, but rather on the routine
3850 and then not Is_Imported
(E
)
3852 -- Exclude VM case, since both .NET and JVM can handle
3853 -- return of unconstrained arrays without a problem.
3855 and then VM_Target
= No_VM
3857 -- Check that general warning is enabled, and that it
3858 -- is not suppressed for this particular case.
3860 and then Warn_On_Export_Import
3861 and then not Has_Warnings_Off
(E
)
3862 and then not Has_Warnings_Off
(R_Type
)
3865 ("?x?foreign convention function& should not " &
3866 "return unconstrained array!", E
);
3871 -- Pre/post conditions are implemented through a subprogram in
3872 -- the corresponding body, and therefore are not checked on an
3873 -- imported subprogram for which the body is not available.
3875 -- Could consider generating a wrapper to take care of this???
3877 if Is_Subprogram
(E
)
3878 and then Is_Imported
(E
)
3879 and then Present
(Contract
(E
))
3880 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
3883 ("pre/post conditions on imported subprogram are not "
3884 & "enforced??", E
, Pre_Post_Conditions
(Contract
(E
)));
3889 -- Must freeze its parent first if it is a derived subprogram
3891 if Present
(Alias
(E
)) then
3892 Freeze_And_Append
(Alias
(E
), N
, Result
);
3895 -- We don't freeze internal subprograms, because we don't normally
3896 -- want addition of extra formals or mechanism setting to happen
3897 -- for those. However we do pass through predefined dispatching
3898 -- cases, since extra formals may be needed in some cases, such as
3899 -- for the stream 'Input function (build-in-place formals).
3901 if not Is_Internal
(E
)
3902 or else Is_Predefined_Dispatching_Operation
(E
)
3904 Freeze_Subprogram
(E
);
3907 -- Here for other than a subprogram or type
3910 -- If entity has a type, and it is not a generic unit, then
3911 -- freeze it first (RM 13.14(10)).
3913 if Present
(Etype
(E
))
3914 and then Ekind
(E
) /= E_Generic_Function
3916 Freeze_And_Append
(Etype
(E
), N
, Result
);
3919 -- Special processing for objects created by object declaration
3921 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
3923 -- Abstract type allowed only for C++ imported variables or
3926 -- Note: we inhibit this check for objects that do not come
3927 -- from source because there is at least one case (the
3928 -- expansion of x'Class'Input where x is abstract) where we
3929 -- legitimately generate an abstract object.
3931 if Is_Abstract_Type
(Etype
(E
))
3932 and then Comes_From_Source
(Parent
(E
))
3933 and then not (Is_Imported
(E
)
3934 and then Is_CPP_Class
(Etype
(E
)))
3936 Error_Msg_N
("type of object cannot be abstract",
3937 Object_Definition
(Parent
(E
)));
3939 if Is_CPP_Class
(Etype
(E
)) then
3941 ("\} may need a cpp_constructor",
3942 Object_Definition
(Parent
(E
)), Etype
(E
));
3946 -- For object created by object declaration, perform required
3947 -- categorization (preelaborate and pure) checks. Defer these
3948 -- checks to freeze time since pragma Import inhibits default
3949 -- initialization and thus pragma Import affects these checks.
3951 Validate_Object_Declaration
(Declaration_Node
(E
));
3953 -- If there is an address clause, check that it is valid
3955 Check_Address_Clause
(E
);
3957 -- Reset Is_True_Constant for aliased object. We consider that
3958 -- the fact that something is aliased may indicate that some
3959 -- funny business is going on, e.g. an aliased object is passed
3960 -- by reference to a procedure which captures the address of
3961 -- the object, which is later used to assign a new value. Such
3962 -- code is highly dubious, but we choose to make it "work" for
3965 -- However, we don't do that for internal entities. We figure
3966 -- that if we deliberately set Is_True_Constant for an internal
3967 -- entity, e.g. a dispatch table entry, then we mean it.
3969 if (Is_Aliased
(E
) or else Is_Aliased
(Etype
(E
)))
3970 and then not Is_Internal_Name
(Chars
(E
))
3972 Set_Is_True_Constant
(E
, False);
3975 -- If the object needs any kind of default initialization, an
3976 -- error must be issued if No_Default_Initialization applies.
3977 -- The check doesn't apply to imported objects, which are not
3978 -- ever default initialized, and is why the check is deferred
3979 -- until freezing, at which point we know if Import applies.
3980 -- Deferred constants are also exempted from this test because
3981 -- their completion is explicit, or through an import pragma.
3983 if Ekind
(E
) = E_Constant
3984 and then Present
(Full_View
(E
))
3988 elsif Comes_From_Source
(E
)
3989 and then not Is_Imported
(E
)
3990 and then not Has_Init_Expression
(Declaration_Node
(E
))
3992 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
3993 and then not No_Initialization
(Declaration_Node
(E
))
3994 and then not Is_Value_Type
(Etype
(E
))
3995 and then not Initialization_Suppressed
(Etype
(E
)))
3997 (Needs_Simple_Initialization
(Etype
(E
))
3998 and then not Is_Internal
(E
)))
4000 Has_Default_Initialization
:= True;
4002 (No_Default_Initialization
, Declaration_Node
(E
));
4005 -- Check that a Thread_Local_Storage variable does not have
4006 -- default initialization, and any explicit initialization must
4007 -- either be the null constant or a static constant.
4009 if Has_Pragma_Thread_Local_Storage
(E
) then
4011 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4013 if Has_Default_Initialization
4015 (Has_Init_Expression
(Decl
)
4017 (No
(Expression
(Decl
))
4019 (Is_Static_Expression
(Expression
(Decl
))
4021 Nkind
(Expression
(Decl
)) = N_Null
)))
4024 ("Thread_Local_Storage variable& is "
4025 & "improperly initialized", Decl
, E
);
4027 ("\only allowed initialization is explicit "
4028 & "NULL or static expression", Decl
, E
);
4033 -- For imported objects, set Is_Public unless there is also an
4034 -- address clause, which means that there is no external symbol
4035 -- needed for the Import (Is_Public may still be set for other
4036 -- unrelated reasons). Note that we delayed this processing
4037 -- till freeze time so that we can be sure not to set the flag
4038 -- if there is an address clause. If there is such a clause,
4039 -- then the only purpose of the Import pragma is to suppress
4040 -- implicit initialization.
4042 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4046 -- For source objects that are not Imported and are library
4047 -- level, if no linker section pragma was given inherit the
4048 -- appropriate linker section from the corresponding type.
4050 if Comes_From_Source
(E
)
4051 and then not Is_Imported
(E
)
4052 and then Is_Library_Level_Entity
(E
)
4053 and then No
(Linker_Section_Pragma
(E
))
4055 Set_Linker_Section_Pragma
4056 (E
, Linker_Section_Pragma
(Etype
(E
)));
4059 -- For convention C objects of an enumeration type, warn if
4060 -- the size is not integer size and no explicit size given.
4061 -- Skip warning for Boolean, and Character, assume programmer
4062 -- expects 8-bit sizes for these cases.
4064 if (Convention
(E
) = Convention_C
4066 Convention
(E
) = Convention_CPP
)
4067 and then Is_Enumeration_Type
(Etype
(E
))
4068 and then not Is_Character_Type
(Etype
(E
))
4069 and then not Is_Boolean_Type
(Etype
(E
))
4070 and then Esize
(Etype
(E
)) < Standard_Integer_Size
4071 and then not Has_Size_Clause
(E
)
4073 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4075 ("??convention C enumeration object has size less than ^",
4077 Error_Msg_N
("\?use explicit size clause to set size", E
);
4081 -- Check that a constant which has a pragma Volatile[_Components]
4082 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
4084 -- Note: Atomic[_Components] also sets Volatile[_Components]
4086 if Ekind
(E
) = E_Constant
4087 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
4088 and then not Is_Imported
(E
)
4090 -- Make sure we actually have a pragma, and have not merely
4091 -- inherited the indication from elsewhere (e.g. an address
4092 -- clause, which is not good enough in RM terms).
4094 if Has_Rep_Pragma
(E
, Name_Atomic
)
4096 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
4099 ("stand alone atomic constant must be " &
4100 "imported (RM C.6(13))", E
);
4102 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
4104 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
4107 ("stand alone volatile constant must be " &
4108 "imported (RM C.6(13))", E
);
4112 -- Static objects require special handling
4114 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
4115 and then Is_Statically_Allocated
(E
)
4117 Freeze_Static_Object
(E
);
4120 -- Remaining step is to layout objects
4122 if Ekind_In
(E
, E_Variable
, E_Constant
, E_Loop_Parameter
)
4123 or else Is_Formal
(E
)
4128 -- If initialization statements were captured in an expression
4129 -- with actions with null expression, and the object does not
4130 -- have delayed freezing, move them back now directly within the
4131 -- enclosing statement sequence.
4133 if Ekind_In
(E
, E_Constant
, E_Variable
)
4134 and then not Has_Delayed_Freeze
(E
)
4137 Init_Stmts
: constant Node_Id
:=
4138 Initialization_Statements
(E
);
4140 if Present
(Init_Stmts
)
4141 and then Nkind
(Init_Stmts
) = N_Expression_With_Actions
4142 and then Nkind
(Expression
(Init_Stmts
)) = N_Null_Statement
4144 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
4146 -- Note that we rewrite Init_Stmts into a NULL statement,
4147 -- rather than just removing it, because Freeze_All may
4148 -- depend on this particular Node_Id still being present
4149 -- in the enclosing list to signal where to stop
4152 Rewrite
(Init_Stmts
,
4153 Make_Null_Statement
(Sloc
(Init_Stmts
)));
4155 Set_Initialization_Statements
(E
, Empty
);
4161 -- Case of a type or subtype being frozen
4164 -- We used to check here that a full type must have preelaborable
4165 -- initialization if it completes a private type specified with
4166 -- pragma Preelaborable_Initialization, but that missed cases where
4167 -- the types occur within a generic package, since the freezing
4168 -- that occurs within a containing scope generally skips traversal
4169 -- of a generic unit's declarations (those will be frozen within
4170 -- instances). This check was moved to Analyze_Package_Specification.
4172 -- The type may be defined in a generic unit. This can occur when
4173 -- freezing a generic function that returns the type (which is
4174 -- defined in a parent unit). It is clearly meaningless to freeze
4175 -- this type. However, if it is a subtype, its size may be determi-
4176 -- nable and used in subsequent checks, so might as well try to
4179 -- In Ada 2012, Freeze_Entities is also used in the front end to
4180 -- trigger the analysis of aspect expressions, so in this case we
4181 -- want to continue the freezing process.
4183 if Present
(Scope
(E
))
4184 and then Is_Generic_Unit
(Scope
(E
))
4186 (not Has_Predicates
(E
)
4187 and then not Has_Delayed_Freeze
(E
))
4189 Check_Compile_Time_Size
(E
);
4193 -- Deal with special cases of freezing for subtype
4195 if E
/= Base_Type
(E
) then
4197 -- Before we do anything else, a specialized test for the case of
4198 -- a size given for an array where the array needs to be packed,
4199 -- but was not so the size cannot be honored. This is the case
4200 -- where implicit packing may apply. The reason we do this so
4201 -- early is that if we have implicit packing, the layout of the
4202 -- base type is affected, so we must do this before we freeze
4205 -- We could do this processing only if implicit packing is enabled
4206 -- since in all other cases, the error would be caught by the back
4207 -- end. However, we choose to do the check even if we do not have
4208 -- implicit packing enabled, since this allows us to give a more
4209 -- useful error message (advising use of pragmas Implicit_Packing
4212 if Is_Array_Type
(E
) then
4214 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
4215 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
4216 SZ
: constant Node_Id
:= Size_Clause
(E
);
4217 Btyp
: constant Entity_Id
:= Base_Type
(E
);
4224 -- Number of elements in array
4227 -- Check enabling conditions. These are straightforward
4228 -- except for the test for a limited composite type. This
4229 -- eliminates the rare case of a array of limited components
4230 -- where there are issues of whether or not we can go ahead
4231 -- and pack the array (since we can't freely pack and unpack
4232 -- arrays if they are limited).
4234 -- Note that we check the root type explicitly because the
4235 -- whole point is we are doing this test before we have had
4236 -- a chance to freeze the base type (and it is that freeze
4237 -- action that causes stuff to be inherited).
4239 if Has_Size_Clause
(E
)
4240 and then Known_Static_RM_Size
(E
)
4241 and then not Is_Packed
(E
)
4242 and then not Has_Pragma_Pack
(E
)
4243 and then not Has_Component_Size_Clause
(E
)
4244 and then Known_Static_RM_Size
(Ctyp
)
4245 and then RM_Size
(Ctyp
) < 64
4246 and then not Is_Limited_Composite
(E
)
4247 and then not Is_Packed
(Root_Type
(E
))
4248 and then not Has_Component_Size_Clause
(Root_Type
(E
))
4249 and then not (CodePeer_Mode
or GNATprove_Mode
)
4251 -- Compute number of elements in array
4253 Num_Elmts
:= Uint_1
;
4254 Indx
:= First_Index
(E
);
4255 while Present
(Indx
) loop
4256 Get_Index_Bounds
(Indx
, Lo
, Hi
);
4258 if not (Compile_Time_Known_Value
(Lo
)
4260 Compile_Time_Known_Value
(Hi
))
4262 goto No_Implicit_Packing
;
4268 Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1);
4272 -- What we are looking for here is the situation where
4273 -- the RM_Size given would be exactly right if there was
4274 -- a pragma Pack (resulting in the component size being
4275 -- the same as the RM_Size). Furthermore, the component
4276 -- type size must be an odd size (not a multiple of
4277 -- storage unit). If the component RM size is an exact
4278 -- number of storage units that is a power of two, the
4279 -- array is not packed and has a standard representation.
4281 if RM_Size
(E
) = Num_Elmts
* Rsiz
4282 and then Rsiz
mod System_Storage_Unit
/= 0
4284 -- For implicit packing mode, just set the component
4287 if Implicit_Packing
then
4288 Set_Component_Size
(Btyp
, Rsiz
);
4289 Set_Is_Bit_Packed_Array
(Btyp
);
4290 Set_Is_Packed
(Btyp
);
4291 Set_Has_Non_Standard_Rep
(Btyp
);
4293 -- Otherwise give an error message
4297 ("size given for& too small", SZ
, E
);
4298 Error_Msg_N
-- CODEFIX
4299 ("\use explicit pragma Pack "
4300 & "or use pragma Implicit_Packing", SZ
);
4303 elsif RM_Size
(E
) = Num_Elmts
* Rsiz
4304 and then Implicit_Packing
4306 (Rsiz
/ System_Storage_Unit
= 1
4308 Rsiz
/ System_Storage_Unit
= 2
4310 Rsiz
/ System_Storage_Unit
= 4)
4312 -- Not a packed array, but indicate the desired
4313 -- component size, for the back-end.
4315 Set_Component_Size
(Btyp
, Rsiz
);
4321 <<No_Implicit_Packing
>>
4323 -- If ancestor subtype present, freeze that first. Note that this
4324 -- will also get the base type frozen. Need RM reference ???
4326 Atype
:= Ancestor_Subtype
(E
);
4328 if Present
(Atype
) then
4329 Freeze_And_Append
(Atype
, N
, Result
);
4331 -- No ancestor subtype present
4334 -- See if we have a nearest ancestor that has a predicate.
4335 -- That catches the case of derived type with a predicate.
4336 -- Need RM reference here ???
4338 Atype
:= Nearest_Ancestor
(E
);
4340 if Present
(Atype
) and then Has_Predicates
(Atype
) then
4341 Freeze_And_Append
(Atype
, N
, Result
);
4344 -- Freeze base type before freezing the entity (RM 13.14(15))
4346 if E
/= Base_Type
(E
) then
4347 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
4351 -- A subtype inherits all the type-related representation aspects
4352 -- from its parents (RM 13.1(8)).
4354 Inherit_Aspects_At_Freeze_Point
(E
);
4356 -- For a derived type, freeze its parent type first (RM 13.14(15))
4358 elsif Is_Derived_Type
(E
) then
4359 Freeze_And_Append
(Etype
(E
), N
, Result
);
4360 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
4362 -- A derived type inherits each type-related representation aspect
4363 -- of its parent type that was directly specified before the
4364 -- declaration of the derived type (RM 13.1(15)).
4366 Inherit_Aspects_At_Freeze_Point
(E
);
4371 if Is_Array_Type
(E
) then
4372 Freeze_Array_Type
(E
);
4374 -- For a class-wide type, the corresponding specific type is
4375 -- frozen as well (RM 13.14(15))
4377 elsif Is_Class_Wide_Type
(E
) then
4378 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
4380 -- If the base type of the class-wide type is still incomplete,
4381 -- the class-wide remains unfrozen as well. This is legal when
4382 -- E is the formal of a primitive operation of some other type
4383 -- which is being frozen.
4385 if not Is_Frozen
(Root_Type
(E
)) then
4386 Set_Is_Frozen
(E
, False);
4390 -- The equivalent type associated with a class-wide subtype needs
4391 -- to be frozen to ensure that its layout is done.
4393 if Ekind
(E
) = E_Class_Wide_Subtype
4394 and then Present
(Equivalent_Type
(E
))
4396 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
4399 -- Generate an itype reference for a library-level class-wide type
4400 -- at the freeze point. Otherwise the first explicit reference to
4401 -- the type may appear in an inner scope which will be rejected by
4405 and then Is_Compilation_Unit
(Scope
(E
))
4408 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
4413 -- From a gigi point of view, a class-wide subtype derives
4414 -- from its record equivalent type. As a result, the itype
4415 -- reference must appear after the freeze node of the
4416 -- equivalent type or gigi will reject the reference.
4418 if Ekind
(E
) = E_Class_Wide_Subtype
4419 and then Present
(Equivalent_Type
(E
))
4421 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
4423 Add_To_Result
(Ref
);
4428 -- For a record type or record subtype, freeze all component types
4429 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
4430 -- using Is_Record_Type, because we don't want to attempt the freeze
4431 -- for the case of a private type with record extension (we will do
4432 -- that later when the full type is frozen).
4434 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
)
4435 and then not Is_Generic_Unit
(Scope
(E
))
4437 Freeze_Record_Type
(E
);
4439 -- For a concurrent type, freeze corresponding record type. This
4440 -- does not correspond to any specific rule in the RM, but the
4441 -- record type is essentially part of the concurrent type.
4442 -- Freeze as well all local entities. This includes record types
4443 -- created for entry parameter blocks, and whatever local entities
4444 -- may appear in the private part.
4446 elsif Is_Concurrent_Type
(E
) then
4447 if Present
(Corresponding_Record_Type
(E
)) then
4448 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
4451 Comp
:= First_Entity
(E
);
4452 while Present
(Comp
) loop
4453 if Is_Type
(Comp
) then
4454 Freeze_And_Append
(Comp
, N
, Result
);
4456 elsif (Ekind
(Comp
)) /= E_Function
then
4457 if Is_Itype
(Etype
(Comp
))
4458 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
4460 Undelay_Type
(Etype
(Comp
));
4463 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
4469 -- Private types are required to point to the same freeze node as
4470 -- their corresponding full views. The freeze node itself has to
4471 -- point to the partial view of the entity (because from the partial
4472 -- view, we can retrieve the full view, but not the reverse).
4473 -- However, in order to freeze correctly, we need to freeze the full
4474 -- view. If we are freezing at the end of a scope (or within the
4475 -- scope of the private type), the partial and full views will have
4476 -- been swapped, the full view appears first in the entity chain and
4477 -- the swapping mechanism ensures that the pointers are properly set
4480 -- If we encounter the partial view before the full view (e.g. when
4481 -- freezing from another scope), we freeze the full view, and then
4482 -- set the pointers appropriately since we cannot rely on swapping to
4483 -- fix things up (subtypes in an outer scope might not get swapped).
4485 elsif Is_Incomplete_Or_Private_Type
(E
)
4486 and then not Is_Generic_Type
(E
)
4488 -- The construction of the dispatch table associated with library
4489 -- level tagged types forces freezing of all the primitives of the
4490 -- type, which may cause premature freezing of the partial view.
4494 -- type T is tagged private;
4495 -- type DT is new T with private;
4496 -- procedure Prim (X : in out T; Y : in out DT'Class);
4498 -- type T is tagged null record;
4500 -- type DT is new T with null record;
4503 -- In this case the type will be frozen later by the usual
4504 -- mechanism: an object declaration, an instantiation, or the
4505 -- end of a declarative part.
4507 if Is_Library_Level_Tagged_Type
(E
)
4508 and then not Present
(Full_View
(E
))
4510 Set_Is_Frozen
(E
, False);
4513 -- Case of full view present
4515 elsif Present
(Full_View
(E
)) then
4517 -- If full view has already been frozen, then no further
4518 -- processing is required
4520 if Is_Frozen
(Full_View
(E
)) then
4521 Set_Has_Delayed_Freeze
(E
, False);
4522 Set_Freeze_Node
(E
, Empty
);
4523 Check_Debug_Info_Needed
(E
);
4525 -- Otherwise freeze full view and patch the pointers so that
4526 -- the freeze node will elaborate both views in the back-end.
4530 Full
: constant Entity_Id
:= Full_View
(E
);
4533 if Is_Private_Type
(Full
)
4534 and then Present
(Underlying_Full_View
(Full
))
4537 (Underlying_Full_View
(Full
), N
, Result
);
4540 Freeze_And_Append
(Full
, N
, Result
);
4542 if Has_Delayed_Freeze
(E
) then
4543 F_Node
:= Freeze_Node
(Full
);
4545 if Present
(F_Node
) then
4546 Set_Freeze_Node
(E
, F_Node
);
4547 Set_Entity
(F_Node
, E
);
4550 -- {Incomplete,Private}_Subtypes with Full_Views
4551 -- constrained by discriminants.
4553 Set_Has_Delayed_Freeze
(E
, False);
4554 Set_Freeze_Node
(E
, Empty
);
4559 Check_Debug_Info_Needed
(E
);
4562 -- AI-117 requires that the convention of a partial view be the
4563 -- same as the convention of the full view. Note that this is a
4564 -- recognized breach of privacy, but it's essential for logical
4565 -- consistency of representation, and the lack of a rule in
4566 -- RM95 was an oversight.
4568 Set_Convention
(E
, Convention
(Full_View
(E
)));
4570 Set_Size_Known_At_Compile_Time
(E
,
4571 Size_Known_At_Compile_Time
(Full_View
(E
)));
4573 -- Size information is copied from the full view to the
4574 -- incomplete or private view for consistency.
4576 -- We skip this is the full view is not a type. This is very
4577 -- strange of course, and can only happen as a result of
4578 -- certain illegalities, such as a premature attempt to derive
4579 -- from an incomplete type.
4581 if Is_Type
(Full_View
(E
)) then
4582 Set_Size_Info
(E
, Full_View
(E
));
4583 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
4588 -- Case of no full view present. If entity is derived or subtype,
4589 -- it is safe to freeze, correctness depends on the frozen status
4590 -- of parent. Otherwise it is either premature usage, or a Taft
4591 -- amendment type, so diagnosis is at the point of use and the
4592 -- type might be frozen later.
4594 elsif E
/= Base_Type
(E
) or else Is_Derived_Type
(E
) then
4598 Set_Is_Frozen
(E
, False);
4602 -- For access subprogram, freeze types of all formals, the return
4603 -- type was already frozen, since it is the Etype of the function.
4604 -- Formal types can be tagged Taft amendment types, but otherwise
4605 -- they cannot be incomplete.
4607 elsif Ekind
(E
) = E_Subprogram_Type
then
4608 Formal
:= First_Formal
(E
);
4609 while Present
(Formal
) loop
4610 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
4611 and then No
(Full_View
(Etype
(Formal
)))
4612 and then not Is_Value_Type
(Etype
(Formal
))
4614 if Is_Tagged_Type
(Etype
(Formal
)) then
4617 -- AI05-151: Incomplete types are allowed in access to
4618 -- subprogram specifications.
4620 elsif Ada_Version
< Ada_2012
then
4622 ("invalid use of incomplete type&", E
, Etype
(Formal
));
4626 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
4627 Next_Formal
(Formal
);
4630 Freeze_Subprogram
(E
);
4632 -- For access to a protected subprogram, freeze the equivalent type
4633 -- (however this is not set if we are not generating code or if this
4634 -- is an anonymous type used just for resolution).
4636 elsif Is_Access_Protected_Subprogram_Type
(E
) then
4637 if Present
(Equivalent_Type
(E
)) then
4638 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
4642 -- Generic types are never seen by the back-end, and are also not
4643 -- processed by the expander (since the expander is turned off for
4644 -- generic processing), so we never need freeze nodes for them.
4646 if Is_Generic_Type
(E
) then
4650 -- Some special processing for non-generic types to complete
4651 -- representation details not known till the freeze point.
4653 if Is_Fixed_Point_Type
(E
) then
4654 Freeze_Fixed_Point_Type
(E
);
4656 -- Some error checks required for ordinary fixed-point type. Defer
4657 -- these till the freeze-point since we need the small and range
4658 -- values. We only do these checks for base types
4660 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
4661 if Small_Value
(E
) < Ureal_2_M_80
then
4662 Error_Msg_Name_1
:= Name_Small
;
4664 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
4666 elsif Small_Value
(E
) > Ureal_2_80
then
4667 Error_Msg_Name_1
:= Name_Small
;
4669 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
4672 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
4673 Error_Msg_Name_1
:= Name_First
;
4675 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
4678 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
4679 Error_Msg_Name_1
:= Name_Last
;
4681 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
4685 elsif Is_Enumeration_Type
(E
) then
4686 Freeze_Enumeration_Type
(E
);
4688 elsif Is_Integer_Type
(E
) then
4689 Adjust_Esize_For_Alignment
(E
);
4691 if Is_Modular_Integer_Type
(E
)
4692 and then Warn_On_Suspicious_Modulus_Value
4694 Check_Suspicious_Modulus
(E
);
4697 elsif Is_Access_Type
(E
)
4698 and then not Is_Access_Subprogram_Type
(E
)
4700 -- If a pragma Default_Storage_Pool applies, and this type has no
4701 -- Storage_Pool or Storage_Size clause (which must have occurred
4702 -- before the freezing point), then use the default. This applies
4703 -- only to base types.
4705 -- None of this applies to access to subprograms, for which there
4706 -- are clearly no pools.
4708 if Present
(Default_Pool
)
4709 and then Is_Base_Type
(E
)
4710 and then not Has_Storage_Size_Clause
(E
)
4711 and then No
(Associated_Storage_Pool
(E
))
4713 -- Case of pragma Default_Storage_Pool (null)
4715 if Nkind
(Default_Pool
) = N_Null
then
4716 Set_No_Pool_Assigned
(E
);
4718 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
4721 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
4725 -- Check restriction for standard storage pool
4727 if No
(Associated_Storage_Pool
(E
)) then
4728 Check_Restriction
(No_Standard_Storage_Pools
, E
);
4731 -- Deal with error message for pure access type. This is not an
4732 -- error in Ada 2005 if there is no pool (see AI-366).
4734 if Is_Pure_Unit_Access_Type
(E
)
4735 and then (Ada_Version
< Ada_2005
4736 or else not No_Pool_Assigned
(E
))
4737 and then not Is_Generic_Unit
(Scope
(E
))
4739 Error_Msg_N
("named access type not allowed in pure unit", E
);
4741 if Ada_Version
>= Ada_2005
then
4743 ("\would be legal if Storage_Size of 0 given??", E
);
4745 elsif No_Pool_Assigned
(E
) then
4747 ("\would be legal in Ada 2005??", E
);
4751 ("\would be legal in Ada 2005 if "
4752 & "Storage_Size of 0 given??", E
);
4757 -- Case of composite types
4759 if Is_Composite_Type
(E
) then
4761 -- AI-117 requires that all new primitives of a tagged type must
4762 -- inherit the convention of the full view of the type. Inherited
4763 -- and overriding operations are defined to inherit the convention
4764 -- of their parent or overridden subprogram (also specified in
4765 -- AI-117), which will have occurred earlier (in Derive_Subprogram
4766 -- and New_Overloaded_Entity). Here we set the convention of
4767 -- primitives that are still convention Ada, which will ensure
4768 -- that any new primitives inherit the type's convention. Class-
4769 -- wide types can have a foreign convention inherited from their
4770 -- specific type, but are excluded from this since they don't have
4771 -- any associated primitives.
4773 if Is_Tagged_Type
(E
)
4774 and then not Is_Class_Wide_Type
(E
)
4775 and then Convention
(E
) /= Convention_Ada
4778 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
4782 Prim
:= First_Elmt
(Prim_List
);
4783 while Present
(Prim
) loop
4784 if Convention
(Node
(Prim
)) = Convention_Ada
then
4785 Set_Convention
(Node
(Prim
), Convention
(E
));
4793 -- If the type is a simple storage pool type, then this is where
4794 -- we attempt to locate and validate its Allocate, Deallocate, and
4795 -- Storage_Size operations (the first is required, and the latter
4796 -- two are optional). We also verify that the full type for a
4797 -- private type is allowed to be a simple storage pool type.
4799 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
4800 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
4802 -- If the type is marked Has_Private_Declaration, then this is
4803 -- a full type for a private type that was specified with the
4804 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
4805 -- pragma is allowed for the full type (for example, it can't
4806 -- be an array type, or a nonlimited record type).
4808 if Has_Private_Declaration
(E
) then
4809 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
4810 and then not Is_Private_Type
(E
)
4812 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
4814 ("pragma% can only apply to full type that is an " &
4815 "explicitly limited type", E
);
4819 Validate_Simple_Pool_Ops
: declare
4820 Pool_Type
: Entity_Id
renames E
;
4821 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
4822 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
4824 procedure Validate_Simple_Pool_Op_Formal
4825 (Pool_Op
: Entity_Id
;
4826 Pool_Op_Formal
: in out Entity_Id
;
4827 Expected_Mode
: Formal_Kind
;
4828 Expected_Type
: Entity_Id
;
4829 Formal_Name
: String;
4830 OK_Formal
: in out Boolean);
4831 -- Validate one formal Pool_Op_Formal of the candidate pool
4832 -- operation Pool_Op. The formal must be of Expected_Type
4833 -- and have mode Expected_Mode. OK_Formal will be set to
4834 -- False if the formal doesn't match. If OK_Formal is False
4835 -- on entry, then the formal will effectively be ignored
4836 -- (because validation of the pool op has already failed).
4837 -- Upon return, Pool_Op_Formal will be updated to the next
4840 procedure Validate_Simple_Pool_Operation
4841 (Op_Name
: Name_Id
);
4842 -- Search for and validate a simple pool operation with the
4843 -- name Op_Name. If the name is Allocate, then there must be
4844 -- exactly one such primitive operation for the simple pool
4845 -- type. If the name is Deallocate or Storage_Size, then
4846 -- there can be at most one such primitive operation. The
4847 -- profile of the located primitive must conform to what
4848 -- is expected for each operation.
4850 ------------------------------------
4851 -- Validate_Simple_Pool_Op_Formal --
4852 ------------------------------------
4854 procedure Validate_Simple_Pool_Op_Formal
4855 (Pool_Op
: Entity_Id
;
4856 Pool_Op_Formal
: in out Entity_Id
;
4857 Expected_Mode
: Formal_Kind
;
4858 Expected_Type
: Entity_Id
;
4859 Formal_Name
: String;
4860 OK_Formal
: in out Boolean)
4863 -- If OK_Formal is False on entry, then simply ignore
4864 -- the formal, because an earlier formal has already
4867 if not OK_Formal
then
4870 -- If no formal is passed in, then issue an error for a
4873 elsif not Present
(Pool_Op_Formal
) then
4875 ("simple storage pool op missing formal " &
4876 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
4882 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
4884 -- If the pool type was expected for this formal, then
4885 -- this will not be considered a candidate operation
4886 -- for the simple pool, so we unset OK_Formal so that
4887 -- the op and any later formals will be ignored.
4889 if Expected_Type
= Pool_Type
then
4896 ("wrong type for formal " & Formal_Name
&
4897 " of simple storage pool op; expected type&",
4898 Pool_Op_Formal
, Expected_Type
);
4902 -- Issue error if formal's mode is not the expected one
4904 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
4906 ("wrong mode for formal of simple storage pool op",
4910 -- Advance to the next formal
4912 Next_Formal
(Pool_Op_Formal
);
4913 end Validate_Simple_Pool_Op_Formal
;
4915 ------------------------------------
4916 -- Validate_Simple_Pool_Operation --
4917 ------------------------------------
4919 procedure Validate_Simple_Pool_Operation
4923 Found_Op
: Entity_Id
:= Empty
;
4929 (Nam_In
(Op_Name
, Name_Allocate
,
4931 Name_Storage_Size
));
4933 Error_Msg_Name_1
:= Op_Name
;
4935 -- For each homonym declared immediately in the scope
4936 -- of the simple storage pool type, determine whether
4937 -- the homonym is an operation of the pool type, and,
4938 -- if so, check that its profile is as expected for
4939 -- a simple pool operation of that name.
4941 Op
:= Get_Name_Entity_Id
(Op_Name
);
4942 while Present
(Op
) loop
4943 if Ekind_In
(Op
, E_Function
, E_Procedure
)
4944 and then Scope
(Op
) = Current_Scope
4946 Formal
:= First_Entity
(Op
);
4950 -- The first parameter must be of the pool type
4951 -- in order for the operation to qualify.
4953 if Op_Name
= Name_Storage_Size
then
4954 Validate_Simple_Pool_Op_Formal
4955 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
4958 Validate_Simple_Pool_Op_Formal
4959 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
4963 -- If another operation with this name has already
4964 -- been located for the type, then flag an error,
4965 -- since we only allow the type to have a single
4968 if Present
(Found_Op
) and then Is_OK
then
4970 ("only one % operation allowed for " &
4971 "simple storage pool type&", Op
, Pool_Type
);
4974 -- In the case of Allocate and Deallocate, a formal
4975 -- of type System.Address is required.
4977 if Op_Name
= Name_Allocate
then
4978 Validate_Simple_Pool_Op_Formal
4979 (Op
, Formal
, E_Out_Parameter
,
4980 Address_Type
, "Storage_Address", Is_OK
);
4982 elsif Op_Name
= Name_Deallocate
then
4983 Validate_Simple_Pool_Op_Formal
4984 (Op
, Formal
, E_In_Parameter
,
4985 Address_Type
, "Storage_Address", Is_OK
);
4988 -- In the case of Allocate and Deallocate, formals
4989 -- of type Storage_Count are required as the third
4990 -- and fourth parameters.
4992 if Op_Name
/= Name_Storage_Size
then
4993 Validate_Simple_Pool_Op_Formal
4994 (Op
, Formal
, E_In_Parameter
,
4995 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
4996 Validate_Simple_Pool_Op_Formal
4997 (Op
, Formal
, E_In_Parameter
,
4998 Stg_Cnt_Type
, "Alignment", Is_OK
);
5001 -- If no mismatched formals have been found (Is_OK)
5002 -- and no excess formals are present, then this
5003 -- operation has been validated, so record it.
5005 if not Present
(Formal
) and then Is_OK
then
5013 -- There must be a valid Allocate operation for the type,
5014 -- so issue an error if none was found.
5016 if Op_Name
= Name_Allocate
5017 and then not Present
(Found_Op
)
5019 Error_Msg_N
("missing % operation for simple " &
5020 "storage pool type", Pool_Type
);
5022 elsif Present
(Found_Op
) then
5024 -- Simple pool operations can't be abstract
5026 if Is_Abstract_Subprogram
(Found_Op
) then
5028 ("simple storage pool operation must not be " &
5029 "abstract", Found_Op
);
5032 -- The Storage_Size operation must be a function with
5033 -- Storage_Count as its result type.
5035 if Op_Name
= Name_Storage_Size
then
5036 if Ekind
(Found_Op
) = E_Procedure
then
5038 ("% operation must be a function", Found_Op
);
5040 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
5042 ("wrong result type for%, expected type&",
5043 Found_Op
, Stg_Cnt_Type
);
5046 -- Allocate and Deallocate must be procedures
5048 elsif Ekind
(Found_Op
) = E_Function
then
5050 ("% operation must be a procedure", Found_Op
);
5053 end Validate_Simple_Pool_Operation
;
5055 -- Start of processing for Validate_Simple_Pool_Ops
5058 Validate_Simple_Pool_Operation
(Name_Allocate
);
5059 Validate_Simple_Pool_Operation
(Name_Deallocate
);
5060 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
5061 end Validate_Simple_Pool_Ops
;
5065 -- Now that all types from which E may depend are frozen, see if the
5066 -- size is known at compile time, if it must be unsigned, or if
5067 -- strict alignment is required
5069 Check_Compile_Time_Size
(E
);
5070 Check_Unsigned_Type
(E
);
5072 if Base_Type
(E
) = E
then
5073 Check_Strict_Alignment
(E
);
5076 -- Do not allow a size clause for a type which does not have a size
5077 -- that is known at compile time
5079 if Has_Size_Clause
(E
)
5080 and then not Size_Known_At_Compile_Time
(E
)
5082 -- Suppress this message if errors posted on E, even if we are
5083 -- in all errors mode, since this is often a junk message
5085 if not Error_Posted
(E
) then
5087 ("size clause not allowed for variable length type",
5092 -- Now we set/verify the representation information, in particular
5093 -- the size and alignment values. This processing is not required for
5094 -- generic types, since generic types do not play any part in code
5095 -- generation, and so the size and alignment values for such types
5096 -- are irrelevant. Ditto for types declared within a generic unit,
5097 -- which may have components that depend on generic parameters, and
5098 -- that will be recreated in an instance.
5100 if Inside_A_Generic
then
5103 -- Otherwise we call the layout procedure
5109 -- If this is an access to subprogram whose designated type is itself
5110 -- a subprogram type, the return type of this anonymous subprogram
5111 -- type must be decorated as well.
5113 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
5114 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
5116 Layout_Type
(Etype
(Designated_Type
(E
)));
5119 -- If the type has a Defaut_Value/Default_Component_Value aspect,
5120 -- this is where we analye the expression (after the type is frozen,
5121 -- since in the case of Default_Value, we are analyzing with the
5122 -- type itself, and we treat Default_Component_Value similarly for
5123 -- the sake of uniformity).
5125 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
5132 if Is_Scalar_Type
(E
) then
5133 Nam
:= Name_Default_Value
;
5135 Exp
:= Default_Aspect_Value
(Typ
);
5137 Nam
:= Name_Default_Component_Value
;
5138 Typ
:= Component_Type
(E
);
5139 Exp
:= Default_Aspect_Component_Value
(E
);
5142 Analyze_And_Resolve
(Exp
, Typ
);
5144 if Etype
(Exp
) /= Any_Type
then
5145 if not Is_Static_Expression
(Exp
) then
5146 Error_Msg_Name_1
:= Nam
;
5147 Flag_Non_Static_Expr
5148 ("aspect% requires static expression", Exp
);
5154 -- End of freeze processing for type entities
5157 -- Here is where we logically freeze the current entity. If it has a
5158 -- freeze node, then this is the point at which the freeze node is
5159 -- linked into the result list.
5161 if Has_Delayed_Freeze
(E
) then
5163 -- If a freeze node is already allocated, use it, otherwise allocate
5164 -- a new one. The preallocation happens in the case of anonymous base
5165 -- types, where we preallocate so that we can set First_Subtype_Link.
5166 -- Note that we reset the Sloc to the current freeze location.
5168 if Present
(Freeze_Node
(E
)) then
5169 F_Node
:= Freeze_Node
(E
);
5170 Set_Sloc
(F_Node
, Loc
);
5173 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
5174 Set_Freeze_Node
(E
, F_Node
);
5175 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
5176 Set_TSS_Elist
(F_Node
, No_Elist
);
5177 Set_Actions
(F_Node
, No_List
);
5180 Set_Entity
(F_Node
, E
);
5181 Add_To_Result
(F_Node
);
5183 -- A final pass over record types with discriminants. If the type
5184 -- has an incomplete declaration, there may be constrained access
5185 -- subtypes declared elsewhere, which do not depend on the discrimi-
5186 -- nants of the type, and which are used as component types (i.e.
5187 -- the full view is a recursive type). The designated types of these
5188 -- subtypes can only be elaborated after the type itself, and they
5189 -- need an itype reference.
5191 if Ekind
(E
) = E_Record_Type
5192 and then Has_Discriminants
(E
)
5200 Comp
:= First_Component
(E
);
5201 while Present
(Comp
) loop
5202 Typ
:= Etype
(Comp
);
5204 if Ekind
(Comp
) = E_Component
5205 and then Is_Access_Type
(Typ
)
5206 and then Scope
(Typ
) /= E
5207 and then Base_Type
(Designated_Type
(Typ
)) = E
5208 and then Is_Itype
(Designated_Type
(Typ
))
5210 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
5211 Set_Itype
(IR
, Designated_Type
(Typ
));
5212 Append
(IR
, Result
);
5215 Next_Component
(Comp
);
5221 -- When a type is frozen, the first subtype of the type is frozen as
5222 -- well (RM 13.14(15)). This has to be done after freezing the type,
5223 -- since obviously the first subtype depends on its own base type.
5226 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
5228 -- If we just froze a tagged non-class wide record, then freeze the
5229 -- corresponding class-wide type. This must be done after the tagged
5230 -- type itself is frozen, because the class-wide type refers to the
5231 -- tagged type which generates the class.
5233 if Is_Tagged_Type
(E
)
5234 and then not Is_Class_Wide_Type
(E
)
5235 and then Present
(Class_Wide_Type
(E
))
5237 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
5241 Check_Debug_Info_Needed
(E
);
5243 -- Special handling for subprograms
5245 if Is_Subprogram
(E
) then
5247 -- If subprogram has address clause then reset Is_Public flag, since
5248 -- we do not want the backend to generate external references.
5250 if Present
(Address_Clause
(E
))
5251 and then not Is_Library_Level_Entity
(E
)
5253 Set_Is_Public
(E
, False);
5260 -----------------------------
5261 -- Freeze_Enumeration_Type --
5262 -----------------------------
5264 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
5266 -- By default, if no size clause is present, an enumeration type with
5267 -- Convention C is assumed to interface to a C enum, and has integer
5268 -- size. This applies to types. For subtypes, verify that its base
5269 -- type has no size clause either. Treat other foreign conventions
5270 -- in the same way, and also make sure alignment is set right.
5272 if Has_Foreign_Convention
(Typ
)
5273 and then not Has_Size_Clause
(Typ
)
5274 and then not Has_Size_Clause
(Base_Type
(Typ
))
5275 and then Esize
(Typ
) < Standard_Integer_Size
5277 -- Don't do this if Short_Enums on target
5279 and then not Target_Short_Enums
5281 Init_Esize
(Typ
, Standard_Integer_Size
);
5282 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
5284 -- Normal Ada case or size clause present or not Long_C_Enums on target
5287 -- If the enumeration type interfaces to C, and it has a size clause
5288 -- that specifies less than int size, it warrants a warning. The
5289 -- user may intend the C type to be an enum or a char, so this is
5290 -- not by itself an error that the Ada compiler can detect, but it
5291 -- it is a worth a heads-up. For Boolean and Character types we
5292 -- assume that the programmer has the proper C type in mind.
5294 if Convention
(Typ
) = Convention_C
5295 and then Has_Size_Clause
(Typ
)
5296 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
5297 and then not Is_Boolean_Type
(Typ
)
5298 and then not Is_Character_Type
(Typ
)
5300 -- Don't do this if Short_Enums on target
5302 and then not Target_Short_Enums
5305 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
5308 Adjust_Esize_For_Alignment
(Typ
);
5310 end Freeze_Enumeration_Type
;
5312 -----------------------
5313 -- Freeze_Expression --
5314 -----------------------
5316 procedure Freeze_Expression
(N
: Node_Id
) is
5317 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
5320 Desig_Typ
: Entity_Id
;
5324 Freeze_Outside
: Boolean := False;
5325 -- This flag is set true if the entity must be frozen outside the
5326 -- current subprogram. This happens in the case of expander generated
5327 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
5328 -- not freeze all entities like other bodies, but which nevertheless
5329 -- may reference entities that have to be frozen before the body and
5330 -- obviously cannot be frozen inside the body.
5332 function In_Exp_Body
(N
: Node_Id
) return Boolean;
5333 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
5334 -- it is the handled statement sequence of an expander-generated
5335 -- subprogram (init proc, stream subprogram, or renaming as body).
5336 -- If so, this is not a freezing context.
5342 function In_Exp_Body
(N
: Node_Id
) return Boolean is
5347 if Nkind
(N
) = N_Subprogram_Body
then
5353 if Nkind
(P
) /= N_Subprogram_Body
then
5357 Id
:= Defining_Unit_Name
(Specification
(P
));
5359 -- Following complex conditional could use comments ???
5361 if Nkind
(Id
) = N_Defining_Identifier
5362 and then (Is_Init_Proc
(Id
)
5363 or else Is_TSS
(Id
, TSS_Stream_Input
)
5364 or else Is_TSS
(Id
, TSS_Stream_Output
)
5365 or else Is_TSS
(Id
, TSS_Stream_Read
)
5366 or else Is_TSS
(Id
, TSS_Stream_Write
)
5367 or else Nkind_In
(Original_Node
(P
),
5368 N_Subprogram_Renaming_Declaration
,
5369 N_Expression_Function
))
5378 -- Start of processing for Freeze_Expression
5381 -- Immediate return if freezing is inhibited. This flag is set by the
5382 -- analyzer to stop freezing on generated expressions that would cause
5383 -- freezing if they were in the source program, but which are not
5384 -- supposed to freeze, since they are created.
5386 if Must_Not_Freeze
(N
) then
5390 -- If expression is non-static, then it does not freeze in a default
5391 -- expression, see section "Handling of Default Expressions" in the
5392 -- spec of package Sem for further details. Note that we have to make
5393 -- sure that we actually have a real expression (if we have a subtype
5394 -- indication, we can't test Is_Static_Expression). However, we exclude
5395 -- the case of the prefix of an attribute of a static scalar subtype
5396 -- from this early return, because static subtype attributes should
5397 -- always cause freezing, even in default expressions, but the attribute
5398 -- may not have been marked as static yet (because in Resolve_Attribute,
5399 -- the call to Eval_Attribute follows the call of Freeze_Expression on
5403 and then Nkind
(N
) in N_Subexpr
5404 and then not Is_Static_Expression
(N
)
5405 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
5406 or else not (Is_Entity_Name
(N
)
5407 and then Is_Type
(Entity
(N
))
5408 and then Is_Static_Subtype
(Entity
(N
))))
5413 -- Freeze type of expression if not frozen already
5417 if Nkind
(N
) in N_Has_Etype
then
5418 if not Is_Frozen
(Etype
(N
)) then
5421 -- Base type may be an derived numeric type that is frozen at
5422 -- the point of declaration, but first_subtype is still unfrozen.
5424 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
5425 Typ
:= First_Subtype
(Etype
(N
));
5429 -- For entity name, freeze entity if not frozen already. A special
5430 -- exception occurs for an identifier that did not come from source.
5431 -- We don't let such identifiers freeze a non-internal entity, i.e.
5432 -- an entity that did come from source, since such an identifier was
5433 -- generated by the expander, and cannot have any semantic effect on
5434 -- the freezing semantics. For example, this stops the parameter of
5435 -- an initialization procedure from freezing the variable.
5437 if Is_Entity_Name
(N
)
5438 and then not Is_Frozen
(Entity
(N
))
5439 and then (Nkind
(N
) /= N_Identifier
5440 or else Comes_From_Source
(N
)
5441 or else not Comes_From_Source
(Entity
(N
)))
5448 -- For an allocator freeze designated type if not frozen already
5450 -- For an aggregate whose component type is an access type, freeze the
5451 -- designated type now, so that its freeze does not appear within the
5452 -- loop that might be created in the expansion of the aggregate. If the
5453 -- designated type is a private type without full view, the expression
5454 -- cannot contain an allocator, so the type is not frozen.
5456 -- For a function, we freeze the entity when the subprogram declaration
5457 -- is frozen, but a function call may appear in an initialization proc.
5458 -- before the declaration is frozen. We need to generate the extra
5459 -- formals, if any, to ensure that the expansion of the call includes
5460 -- the proper actuals. This only applies to Ada subprograms, not to
5467 Desig_Typ
:= Designated_Type
(Etype
(N
));
5470 if Is_Array_Type
(Etype
(N
))
5471 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
5473 Desig_Typ
:= Designated_Type
(Component_Type
(Etype
(N
)));
5476 when N_Selected_Component |
5477 N_Indexed_Component |
5480 if Is_Access_Type
(Etype
(Prefix
(N
))) then
5481 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
5484 when N_Identifier
=>
5486 and then Ekind
(Nam
) = E_Function
5487 and then Nkind
(Parent
(N
)) = N_Function_Call
5488 and then Convention
(Nam
) = Convention_Ada
5490 Create_Extra_Formals
(Nam
);
5497 if Desig_Typ
/= Empty
5498 and then (Is_Frozen
(Desig_Typ
)
5499 or else (not Is_Fully_Defined
(Desig_Typ
)))
5504 -- All done if nothing needs freezing
5508 and then No
(Desig_Typ
)
5513 -- Loop for looking at the right place to insert the freeze nodes,
5514 -- exiting from the loop when it is appropriate to insert the freeze
5515 -- node before the current node P.
5517 -- Also checks some special exceptions to the freezing rules. These
5518 -- cases result in a direct return, bypassing the freeze action.
5522 Parent_P
:= Parent
(P
);
5524 -- If we don't have a parent, then we are not in a well-formed tree.
5525 -- This is an unusual case, but there are some legitimate situations
5526 -- in which this occurs, notably when the expressions in the range of
5527 -- a type declaration are resolved. We simply ignore the freeze
5528 -- request in this case. Is this right ???
5530 if No
(Parent_P
) then
5534 -- See if we have got to an appropriate point in the tree
5536 case Nkind
(Parent_P
) is
5538 -- A special test for the exception of (RM 13.14(8)) for the case
5539 -- of per-object expressions (RM 3.8(18)) occurring in component
5540 -- definition or a discrete subtype definition. Note that we test
5541 -- for a component declaration which includes both cases we are
5542 -- interested in, and furthermore the tree does not have explicit
5543 -- nodes for either of these two constructs.
5545 when N_Component_Declaration
=>
5547 -- The case we want to test for here is an identifier that is
5548 -- a per-object expression, this is either a discriminant that
5549 -- appears in a context other than the component declaration
5550 -- or it is a reference to the type of the enclosing construct.
5552 -- For either of these cases, we skip the freezing
5554 if not In_Spec_Expression
5555 and then Nkind
(N
) = N_Identifier
5556 and then (Present
(Entity
(N
)))
5558 -- We recognize the discriminant case by just looking for
5559 -- a reference to a discriminant. It can only be one for
5560 -- the enclosing construct. Skip freezing in this case.
5562 if Ekind
(Entity
(N
)) = E_Discriminant
then
5565 -- For the case of a reference to the enclosing record,
5566 -- (or task or protected type), we look for a type that
5567 -- matches the current scope.
5569 elsif Entity
(N
) = Current_Scope
then
5574 -- If we have an enumeration literal that appears as the choice in
5575 -- the aggregate of an enumeration representation clause, then
5576 -- freezing does not occur (RM 13.14(10)).
5578 when N_Enumeration_Representation_Clause
=>
5580 -- The case we are looking for is an enumeration literal
5582 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
5583 and then Is_Enumeration_Type
(Etype
(N
))
5585 -- If enumeration literal appears directly as the choice,
5586 -- do not freeze (this is the normal non-overloaded case)
5588 if Nkind
(Parent
(N
)) = N_Component_Association
5589 and then First
(Choices
(Parent
(N
))) = N
5593 -- If enumeration literal appears as the name of function
5594 -- which is the choice, then also do not freeze. This
5595 -- happens in the overloaded literal case, where the
5596 -- enumeration literal is temporarily changed to a function
5597 -- call for overloading analysis purposes.
5599 elsif Nkind
(Parent
(N
)) = N_Function_Call
5601 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
5603 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
5609 -- Normally if the parent is a handled sequence of statements,
5610 -- then the current node must be a statement, and that is an
5611 -- appropriate place to insert a freeze node.
5613 when N_Handled_Sequence_Of_Statements
=>
5615 -- An exception occurs when the sequence of statements is for
5616 -- an expander generated body that did not do the usual freeze
5617 -- all operation. In this case we usually want to freeze
5618 -- outside this body, not inside it, and we skip past the
5619 -- subprogram body that we are inside.
5621 if In_Exp_Body
(Parent_P
) then
5623 Subp
: constant Node_Id
:= Parent
(Parent_P
);
5627 -- Freeze the entity only when it is declared inside the
5628 -- body of the expander generated procedure. This case
5629 -- is recognized by the scope of the entity or its type,
5630 -- which is either the spec for some enclosing body, or
5631 -- (in the case of init_procs, for which there are no
5632 -- separate specs) the current scope.
5634 if Nkind
(Subp
) = N_Subprogram_Body
then
5635 Spec
:= Corresponding_Spec
(Subp
);
5637 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
5639 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
5644 and then Scope
(Typ
) = Current_Scope
5645 and then Defining_Entity
(Subp
) = Current_Scope
5651 -- An expression function may act as a completion of
5652 -- a function declaration. As such, it can reference
5653 -- entities declared between the two views:
5656 -- function F return ...;
5658 -- function Hidden return ...;
5659 -- function F return ... is (Hidden); -- 2
5661 -- Refering to the example above, freezing the expression
5662 -- of F (2) would place Hidden's freeze node (1) in the
5663 -- wrong place. Avoid explicit freezing and let the usual
5664 -- scenarios do the job - for example, reaching the end
5665 -- of the private declarations.
5667 if Nkind
(Original_Node
(Subp
)) =
5668 N_Expression_Function
5672 -- Freeze outside the body
5675 Parent_P
:= Parent
(Parent_P
);
5676 Freeze_Outside
:= True;
5680 -- Here if normal case where we are in handled statement
5681 -- sequence and want to do the insertion right there.
5687 -- If parent is a body or a spec or a block, then the current node
5688 -- is a statement or declaration and we can insert the freeze node
5691 when N_Block_Statement |
5694 N_Package_Specification |
5697 N_Task_Body
=> exit;
5699 -- The expander is allowed to define types in any statements list,
5700 -- so any of the following parent nodes also mark a freezing point
5701 -- if the actual node is in a list of statements or declarations.
5703 when N_Abortable_Part |
5704 N_Accept_Alternative |
5706 N_Case_Statement_Alternative |
5707 N_Compilation_Unit_Aux |
5708 N_Conditional_Entry_Call |
5709 N_Delay_Alternative |
5711 N_Entry_Call_Alternative |
5712 N_Exception_Handler |
5713 N_Extended_Return_Statement |
5717 N_Selective_Accept |
5718 N_Triggering_Alternative
=>
5720 exit when Is_List_Member
(P
);
5722 -- Note: The N_Loop_Statement is a special case. A type that
5723 -- appears in the source can never be frozen in a loop (this
5724 -- occurs only because of a loop expanded by the expander), so we
5725 -- keep on going. Otherwise we terminate the search. Same is true
5726 -- of any entity which comes from source. (if they have predefined
5727 -- type, that type does not appear to come from source, but the
5728 -- entity should not be frozen here).
5730 when N_Loop_Statement
=>
5731 exit when not Comes_From_Source
(Etype
(N
))
5732 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
5734 -- For all other cases, keep looking at parents
5740 -- We fall through the case if we did not yet find the proper
5741 -- place in the free for inserting the freeze node, so climb.
5746 -- If the expression appears in a record or an initialization procedure,
5747 -- the freeze nodes are collected and attached to the current scope, to
5748 -- be inserted and analyzed on exit from the scope, to insure that
5749 -- generated entities appear in the correct scope. If the expression is
5750 -- a default for a discriminant specification, the scope is still void.
5751 -- The expression can also appear in the discriminant part of a private
5752 -- or concurrent type.
5754 -- If the expression appears in a constrained subcomponent of an
5755 -- enclosing record declaration, the freeze nodes must be attached to
5756 -- the outer record type so they can eventually be placed in the
5757 -- enclosing declaration list.
5759 -- The other case requiring this special handling is if we are in a
5760 -- default expression, since in that case we are about to freeze a
5761 -- static type, and the freeze scope needs to be the outer scope, not
5762 -- the scope of the subprogram with the default parameter.
5764 -- For default expressions and other spec expressions in generic units,
5765 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
5766 -- placing them at the proper place, after the generic unit.
5768 if (In_Spec_Exp
and not Inside_A_Generic
)
5769 or else Freeze_Outside
5770 or else (Is_Type
(Current_Scope
)
5771 and then (not Is_Concurrent_Type
(Current_Scope
)
5772 or else not Has_Completion
(Current_Scope
)))
5773 or else Ekind
(Current_Scope
) = E_Void
5776 N
: constant Node_Id
:= Current_Scope
;
5777 Freeze_Nodes
: List_Id
:= No_List
;
5778 Pos
: Int
:= Scope_Stack
.Last
;
5781 if Present
(Desig_Typ
) then
5782 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
5785 if Present
(Typ
) then
5786 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
5789 if Present
(Nam
) then
5790 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
5793 -- The current scope may be that of a constrained component of
5794 -- an enclosing record declaration, or of a loop of an enclosing
5795 -- quantified expression, which is above the current scope in the
5796 -- scope stack. Indeed in the context of a quantified expression,
5797 -- a scope is created and pushed above the current scope in order
5798 -- to emulate the loop-like behavior of the quantified expression.
5799 -- If the expression is within a top-level pragma, as for a pre-
5800 -- condition on a library-level subprogram, nothing to do.
5802 if not Is_Compilation_Unit
(Current_Scope
)
5803 and then (Is_Record_Type
(Scope
(Current_Scope
))
5804 or else Nkind
(Parent
(Current_Scope
)) =
5805 N_Quantified_Expression
)
5810 if Is_Non_Empty_List
(Freeze_Nodes
) then
5811 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
5812 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
5815 Append_List
(Freeze_Nodes
,
5816 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
5824 -- Now we have the right place to do the freezing. First, a special
5825 -- adjustment, if we are in spec-expression analysis mode, these freeze
5826 -- actions must not be thrown away (normally all inserted actions are
5827 -- thrown away in this mode. However, the freeze actions are from static
5828 -- expressions and one of the important reasons we are doing this
5829 -- special analysis is to get these freeze actions. Therefore we turn
5830 -- off the In_Spec_Expression mode to propagate these freeze actions.
5831 -- This also means they get properly analyzed and expanded.
5833 In_Spec_Expression
:= False;
5835 -- Freeze the designated type of an allocator (RM 13.14(13))
5837 if Present
(Desig_Typ
) then
5838 Freeze_Before
(P
, Desig_Typ
);
5841 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
5842 -- the enumeration representation clause exception in the loop above.
5844 if Present
(Typ
) then
5845 Freeze_Before
(P
, Typ
);
5848 -- Freeze name if one is present (RM 13.14(11))
5850 if Present
(Nam
) then
5851 Freeze_Before
(P
, Nam
);
5854 -- Restore In_Spec_Expression flag
5856 In_Spec_Expression
:= In_Spec_Exp
;
5857 end Freeze_Expression
;
5859 -----------------------------
5860 -- Freeze_Fixed_Point_Type --
5861 -----------------------------
5863 -- Certain fixed-point types and subtypes, including implicit base types
5864 -- and declared first subtypes, have not yet set up a range. This is
5865 -- because the range cannot be set until the Small and Size values are
5866 -- known, and these are not known till the type is frozen.
5868 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
5869 -- whose bounds are unanalyzed real literals. This routine will recognize
5870 -- this case, and transform this range node into a properly typed range
5871 -- with properly analyzed and resolved values.
5873 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
5874 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
5875 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
5876 Hi
: constant Node_Id
:= High_Bound
(Rng
);
5877 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
5878 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
5879 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
5880 BHi
: constant Node_Id
:= High_Bound
(Brng
);
5881 Small
: constant Ureal
:= Small_Value
(Typ
);
5888 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
5889 -- Returns size of type with given bounds. Also leaves these
5890 -- bounds set as the current bounds of the Typ.
5896 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
5898 Set_Realval
(Lo
, Lov
);
5899 Set_Realval
(Hi
, Hiv
);
5900 return Minimum_Size
(Typ
);
5903 -- Start of processing for Freeze_Fixed_Point_Type
5906 -- If Esize of a subtype has not previously been set, set it now
5908 if Unknown_Esize
(Typ
) then
5909 Atype
:= Ancestor_Subtype
(Typ
);
5911 if Present
(Atype
) then
5912 Set_Esize
(Typ
, Esize
(Atype
));
5914 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
5918 -- Immediate return if the range is already analyzed. This means that
5919 -- the range is already set, and does not need to be computed by this
5922 if Analyzed
(Rng
) then
5926 -- Immediate return if either of the bounds raises Constraint_Error
5928 if Raises_Constraint_Error
(Lo
)
5929 or else Raises_Constraint_Error
(Hi
)
5934 Loval
:= Realval
(Lo
);
5935 Hival
:= Realval
(Hi
);
5937 -- Ordinary fixed-point case
5939 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
5941 -- For the ordinary fixed-point case, we are allowed to fudge the
5942 -- end-points up or down by small. Generally we prefer to fudge up,
5943 -- i.e. widen the bounds for non-model numbers so that the end points
5944 -- are included. However there are cases in which this cannot be
5945 -- done, and indeed cases in which we may need to narrow the bounds.
5946 -- The following circuit makes the decision.
5948 -- Note: our terminology here is that Incl_EP means that the bounds
5949 -- are widened by Small if necessary to include the end points, and
5950 -- Excl_EP means that the bounds are narrowed by Small to exclude the
5951 -- end-points if this reduces the size.
5953 -- Note that in the Incl case, all we care about is including the
5954 -- end-points. In the Excl case, we want to narrow the bounds as
5955 -- much as permitted by the RM, to give the smallest possible size.
5958 Loval_Incl_EP
: Ureal
;
5959 Hival_Incl_EP
: Ureal
;
5961 Loval_Excl_EP
: Ureal
;
5962 Hival_Excl_EP
: Ureal
;
5968 First_Subt
: Entity_Id
;
5973 -- First step. Base types are required to be symmetrical. Right
5974 -- now, the base type range is a copy of the first subtype range.
5975 -- This will be corrected before we are done, but right away we
5976 -- need to deal with the case where both bounds are non-negative.
5977 -- In this case, we set the low bound to the negative of the high
5978 -- bound, to make sure that the size is computed to include the
5979 -- required sign. Note that we do not need to worry about the
5980 -- case of both bounds negative, because the sign will be dealt
5981 -- with anyway. Furthermore we can't just go making such a bound
5982 -- symmetrical, since in a twos-complement system, there is an
5983 -- extra negative value which could not be accommodated on the
5987 and then not UR_Is_Negative
(Loval
)
5988 and then Hival
> Loval
5991 Set_Realval
(Lo
, Loval
);
5994 -- Compute the fudged bounds. If the number is a model number,
5995 -- then we do nothing to include it, but we are allowed to backoff
5996 -- to the next adjacent model number when we exclude it. If it is
5997 -- not a model number then we straddle the two values with the
5998 -- model numbers on either side.
6000 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
6002 if Loval
= Model_Num
then
6003 Loval_Incl_EP
:= Model_Num
;
6005 Loval_Incl_EP
:= Model_Num
- Small
;
6008 -- The low value excluding the end point is Small greater, but
6009 -- we do not do this exclusion if the low value is positive,
6010 -- since it can't help the size and could actually hurt by
6011 -- crossing the high bound.
6013 if UR_Is_Negative
(Loval_Incl_EP
) then
6014 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
6016 -- If the value went from negative to zero, then we have the
6017 -- case where Loval_Incl_EP is the model number just below
6018 -- zero, so we want to stick to the negative value for the
6019 -- base type to maintain the condition that the size will
6020 -- include signed values.
6023 and then UR_Is_Zero
(Loval_Excl_EP
)
6025 Loval_Excl_EP
:= Loval_Incl_EP
;
6029 Loval_Excl_EP
:= Loval_Incl_EP
;
6032 -- Similar processing for upper bound and high value
6034 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
6036 if Hival
= Model_Num
then
6037 Hival_Incl_EP
:= Model_Num
;
6039 Hival_Incl_EP
:= Model_Num
+ Small
;
6042 if UR_Is_Positive
(Hival_Incl_EP
) then
6043 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
6045 Hival_Excl_EP
:= Hival_Incl_EP
;
6048 -- One further adjustment is needed. In the case of subtypes, we
6049 -- cannot go outside the range of the base type, or we get
6050 -- peculiarities, and the base type range is already set. This
6051 -- only applies to the Incl values, since clearly the Excl values
6052 -- are already as restricted as they are allowed to be.
6055 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
6056 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
6059 -- Get size including and excluding end points
6061 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
6062 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
6064 -- No need to exclude end-points if it does not reduce size
6066 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
6067 Loval_Excl_EP
:= Loval_Incl_EP
;
6070 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
6071 Hival_Excl_EP
:= Hival_Incl_EP
;
6074 -- Now we set the actual size to be used. We want to use the
6075 -- bounds fudged up to include the end-points but only if this
6076 -- can be done without violating a specifically given size
6077 -- size clause or causing an unacceptable increase in size.
6079 -- Case of size clause given
6081 if Has_Size_Clause
(Typ
) then
6083 -- Use the inclusive size only if it is consistent with
6084 -- the explicitly specified size.
6086 if Size_Incl_EP
<= RM_Size
(Typ
) then
6087 Actual_Lo
:= Loval_Incl_EP
;
6088 Actual_Hi
:= Hival_Incl_EP
;
6089 Actual_Size
:= Size_Incl_EP
;
6091 -- If the inclusive size is too large, we try excluding
6092 -- the end-points (will be caught later if does not work).
6095 Actual_Lo
:= Loval_Excl_EP
;
6096 Actual_Hi
:= Hival_Excl_EP
;
6097 Actual_Size
:= Size_Excl_EP
;
6100 -- Case of size clause not given
6103 -- If we have a base type whose corresponding first subtype
6104 -- has an explicit size that is large enough to include our
6105 -- end-points, then do so. There is no point in working hard
6106 -- to get a base type whose size is smaller than the specified
6107 -- size of the first subtype.
6109 First_Subt
:= First_Subtype
(Typ
);
6111 if Has_Size_Clause
(First_Subt
)
6112 and then Size_Incl_EP
<= Esize
(First_Subt
)
6114 Actual_Size
:= Size_Incl_EP
;
6115 Actual_Lo
:= Loval_Incl_EP
;
6116 Actual_Hi
:= Hival_Incl_EP
;
6118 -- If excluding the end-points makes the size smaller and
6119 -- results in a size of 8,16,32,64, then we take the smaller
6120 -- size. For the 64 case, this is compulsory. For the other
6121 -- cases, it seems reasonable. We like to include end points
6122 -- if we can, but not at the expense of moving to the next
6123 -- natural boundary of size.
6125 elsif Size_Incl_EP
/= Size_Excl_EP
6126 and then Addressable
(Size_Excl_EP
)
6128 Actual_Size
:= Size_Excl_EP
;
6129 Actual_Lo
:= Loval_Excl_EP
;
6130 Actual_Hi
:= Hival_Excl_EP
;
6132 -- Otherwise we can definitely include the end points
6135 Actual_Size
:= Size_Incl_EP
;
6136 Actual_Lo
:= Loval_Incl_EP
;
6137 Actual_Hi
:= Hival_Incl_EP
;
6140 -- One pathological case: normally we never fudge a low bound
6141 -- down, since it would seem to increase the size (if it has
6142 -- any effect), but for ranges containing single value, or no
6143 -- values, the high bound can be small too large. Consider:
6145 -- type t is delta 2.0**(-14)
6146 -- range 131072.0 .. 0;
6148 -- That lower bound is *just* outside the range of 32 bits, and
6149 -- does need fudging down in this case. Note that the bounds
6150 -- will always have crossed here, since the high bound will be
6151 -- fudged down if necessary, as in the case of:
6153 -- type t is delta 2.0**(-14)
6154 -- range 131072.0 .. 131072.0;
6156 -- So we detect the situation by looking for crossed bounds,
6157 -- and if the bounds are crossed, and the low bound is greater
6158 -- than zero, we will always back it off by small, since this
6159 -- is completely harmless.
6161 if Actual_Lo
> Actual_Hi
then
6162 if UR_Is_Positive
(Actual_Lo
) then
6163 Actual_Lo
:= Loval_Incl_EP
- Small
;
6164 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
6166 -- And of course, we need to do exactly the same parallel
6167 -- fudge for flat ranges in the negative region.
6169 elsif UR_Is_Negative
(Actual_Hi
) then
6170 Actual_Hi
:= Hival_Incl_EP
+ Small
;
6171 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
6176 Set_Realval
(Lo
, Actual_Lo
);
6177 Set_Realval
(Hi
, Actual_Hi
);
6180 -- For the decimal case, none of this fudging is required, since there
6181 -- are no end-point problems in the decimal case (the end-points are
6182 -- always included).
6185 Actual_Size
:= Fsize
(Loval
, Hival
);
6188 -- At this stage, the actual size has been calculated and the proper
6189 -- required bounds are stored in the low and high bounds.
6191 if Actual_Size
> 64 then
6192 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
6194 ("size required (^) for type& too large, maximum allowed is 64",
6199 -- Check size against explicit given size
6201 if Has_Size_Clause
(Typ
) then
6202 if Actual_Size
> RM_Size
(Typ
) then
6203 Error_Msg_Uint_1
:= RM_Size
(Typ
);
6204 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
6206 ("size given (^) for type& too small, minimum allowed is ^",
6207 Size_Clause
(Typ
), Typ
);
6210 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
6213 -- Increase size to next natural boundary if no size clause given
6216 if Actual_Size
<= 8 then
6218 elsif Actual_Size
<= 16 then
6220 elsif Actual_Size
<= 32 then
6226 Init_Esize
(Typ
, Actual_Size
);
6227 Adjust_Esize_For_Alignment
(Typ
);
6230 -- If we have a base type, then expand the bounds so that they extend to
6231 -- the full width of the allocated size in bits, to avoid junk range
6232 -- checks on intermediate computations.
6234 if Base_Type
(Typ
) = Typ
then
6235 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
6236 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
6239 -- Final step is to reanalyze the bounds using the proper type
6240 -- and set the Corresponding_Integer_Value fields of the literals.
6242 Set_Etype
(Lo
, Empty
);
6243 Set_Analyzed
(Lo
, False);
6246 -- Resolve with universal fixed if the base type, and the base type if
6247 -- it is a subtype. Note we can't resolve the base type with itself,
6248 -- that would be a reference before definition.
6251 Resolve
(Lo
, Universal_Fixed
);
6256 -- Set corresponding integer value for bound
6258 Set_Corresponding_Integer_Value
6259 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
6261 -- Similar processing for high bound
6263 Set_Etype
(Hi
, Empty
);
6264 Set_Analyzed
(Hi
, False);
6268 Resolve
(Hi
, Universal_Fixed
);
6273 Set_Corresponding_Integer_Value
6274 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
6276 -- Set type of range to correspond to bounds
6278 Set_Etype
(Rng
, Etype
(Lo
));
6280 -- Set Esize to calculated size if not set already
6282 if Unknown_Esize
(Typ
) then
6283 Init_Esize
(Typ
, Actual_Size
);
6286 -- Set RM_Size if not already set. If already set, check value
6289 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
6292 if RM_Size
(Typ
) /= Uint_0
then
6293 if RM_Size
(Typ
) < Minsiz
then
6294 Error_Msg_Uint_1
:= RM_Size
(Typ
);
6295 Error_Msg_Uint_2
:= Minsiz
;
6297 ("size given (^) for type& too small, minimum allowed is ^",
6298 Size_Clause
(Typ
), Typ
);
6302 Set_RM_Size
(Typ
, Minsiz
);
6305 end Freeze_Fixed_Point_Type
;
6311 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
6315 Set_Has_Delayed_Freeze
(T
);
6316 L
:= Freeze_Entity
(T
, N
);
6318 if Is_Non_Empty_List
(L
) then
6319 Insert_Actions
(N
, L
);
6323 --------------------------
6324 -- Freeze_Static_Object --
6325 --------------------------
6327 procedure Freeze_Static_Object
(E
: Entity_Id
) is
6329 Cannot_Be_Static
: exception;
6330 -- Exception raised if the type of a static object cannot be made
6331 -- static. This happens if the type depends on non-global objects.
6333 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
6334 -- Called to ensure that an expression used as part of a type definition
6335 -- is statically allocatable, which means that the expression type is
6336 -- statically allocatable, and the expression is either static, or a
6337 -- reference to a library level constant.
6339 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
6340 -- Called to mark a type as static, checking that it is possible
6341 -- to set the type as static. If it is not possible, then the
6342 -- exception Cannot_Be_Static is raised.
6344 -----------------------------
6345 -- Ensure_Expression_Is_SA --
6346 -----------------------------
6348 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
6352 Ensure_Type_Is_SA
(Etype
(N
));
6354 if Is_Static_Expression
(N
) then
6357 elsif Nkind
(N
) = N_Identifier
then
6361 and then Ekind
(Ent
) = E_Constant
6362 and then Is_Library_Level_Entity
(Ent
)
6368 raise Cannot_Be_Static
;
6369 end Ensure_Expression_Is_SA
;
6371 -----------------------
6372 -- Ensure_Type_Is_SA --
6373 -----------------------
6375 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
6380 -- If type is library level, we are all set
6382 if Is_Library_Level_Entity
(Typ
) then
6386 -- We are also OK if the type already marked as statically allocated,
6387 -- which means we processed it before.
6389 if Is_Statically_Allocated
(Typ
) then
6393 -- Mark type as statically allocated
6395 Set_Is_Statically_Allocated
(Typ
);
6397 -- Check that it is safe to statically allocate this type
6399 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
6400 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
6401 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
6403 elsif Is_Array_Type
(Typ
) then
6404 N
:= First_Index
(Typ
);
6405 while Present
(N
) loop
6406 Ensure_Type_Is_SA
(Etype
(N
));
6410 Ensure_Type_Is_SA
(Component_Type
(Typ
));
6412 elsif Is_Access_Type
(Typ
) then
6413 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
6417 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
6420 if T
/= Standard_Void_Type
then
6421 Ensure_Type_Is_SA
(T
);
6424 F
:= First_Formal
(Designated_Type
(Typ
));
6425 while Present
(F
) loop
6426 Ensure_Type_Is_SA
(Etype
(F
));
6432 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
6435 elsif Is_Record_Type
(Typ
) then
6436 C
:= First_Entity
(Typ
);
6437 while Present
(C
) loop
6438 if Ekind
(C
) = E_Discriminant
6439 or else Ekind
(C
) = E_Component
6441 Ensure_Type_Is_SA
(Etype
(C
));
6443 elsif Is_Type
(C
) then
6444 Ensure_Type_Is_SA
(C
);
6450 elsif Ekind
(Typ
) = E_Subprogram_Type
then
6451 Ensure_Type_Is_SA
(Etype
(Typ
));
6453 C
:= First_Formal
(Typ
);
6454 while Present
(C
) loop
6455 Ensure_Type_Is_SA
(Etype
(C
));
6460 raise Cannot_Be_Static
;
6462 end Ensure_Type_Is_SA
;
6464 -- Start of processing for Freeze_Static_Object
6467 Ensure_Type_Is_SA
(Etype
(E
));
6470 when Cannot_Be_Static
=>
6472 -- If the object that cannot be static is imported or exported, then
6473 -- issue an error message saying that this object cannot be imported
6474 -- or exported. If it has an address clause it is an overlay in the
6475 -- current partition and the static requirement is not relevant.
6476 -- Do not issue any error message when ignoring rep clauses.
6478 if Ignore_Rep_Clauses
then
6481 elsif Is_Imported
(E
) then
6482 if No
(Address_Clause
(E
)) then
6484 ("& cannot be imported (local type is not constant)", E
);
6487 -- Otherwise must be exported, something is wrong if compiler
6488 -- is marking something as statically allocated which cannot be).
6490 else pragma Assert
(Is_Exported
(E
));
6492 ("& cannot be exported (local type is not constant)", E
);
6494 end Freeze_Static_Object
;
6496 -----------------------
6497 -- Freeze_Subprogram --
6498 -----------------------
6500 procedure Freeze_Subprogram
(E
: Entity_Id
) is
6505 -- Subprogram may not have an address clause unless it is imported
6507 if Present
(Address_Clause
(E
)) then
6508 if not Is_Imported
(E
) then
6510 ("address clause can only be given " &
6511 "for imported subprogram",
6512 Name
(Address_Clause
(E
)));
6516 -- Reset the Pure indication on an imported subprogram unless an
6517 -- explicit Pure_Function pragma was present. We do this because
6518 -- otherwise it is an insidious error to call a non-pure function from
6519 -- pure unit and have calls mysteriously optimized away. What happens
6520 -- here is that the Import can bypass the normal check to ensure that
6521 -- pure units call only pure subprograms.
6524 and then Is_Pure
(E
)
6525 and then not Has_Pragma_Pure_Function
(E
)
6527 Set_Is_Pure
(E
, False);
6530 -- For non-foreign convention subprograms, this is where we create
6531 -- the extra formals (for accessibility level and constrained bit
6532 -- information). We delay this till the freeze point precisely so
6533 -- that we know the convention.
6535 if not Has_Foreign_Convention
(E
) then
6536 Create_Extra_Formals
(E
);
6539 -- If this is convention Ada and a Valued_Procedure, that's odd
6541 if Ekind
(E
) = E_Procedure
6542 and then Is_Valued_Procedure
(E
)
6543 and then Convention
(E
) = Convention_Ada
6544 and then Warn_On_Export_Import
6547 ("??Valued_Procedure has no effect for convention Ada", E
);
6548 Set_Is_Valued_Procedure
(E
, False);
6551 -- Case of foreign convention
6556 -- For foreign conventions, warn about return of an
6557 -- unconstrained array.
6559 -- Note: we *do* allow a return by descriptor for the VMS case,
6560 -- though here there is probably more to be done ???
6562 if Ekind
(E
) = E_Function
then
6563 Retype
:= Underlying_Type
(Etype
(E
));
6565 -- If no return type, probably some other error, e.g. a
6566 -- missing full declaration, so ignore.
6571 -- If the return type is generic, we have emitted a warning
6572 -- earlier on, and there is nothing else to check here. Specific
6573 -- instantiations may lead to erroneous behavior.
6575 elsif Is_Generic_Type
(Etype
(E
)) then
6578 -- Display warning if returning unconstrained array
6580 elsif Is_Array_Type
(Retype
)
6581 and then not Is_Constrained
(Retype
)
6583 -- Exclude cases where descriptor mechanism is set, since the
6584 -- VMS descriptor mechanisms allow such unconstrained returns.
6586 and then Mechanism
(E
) not in Descriptor_Codes
6588 -- Check appropriate warning is enabled (should we check for
6589 -- Warnings (Off) on specific entities here, probably so???)
6591 and then Warn_On_Export_Import
6593 -- Exclude the VM case, since return of unconstrained arrays
6594 -- is properly handled in both the JVM and .NET cases.
6596 and then VM_Target
= No_VM
6599 ("?x?foreign convention function& should not return " &
6600 "unconstrained array", E
);
6605 -- If any of the formals for an exported foreign convention
6606 -- subprogram have defaults, then emit an appropriate warning since
6607 -- this is odd (default cannot be used from non-Ada code)
6609 if Is_Exported
(E
) then
6610 F
:= First_Formal
(E
);
6611 while Present
(F
) loop
6612 if Warn_On_Export_Import
6613 and then Present
(Default_Value
(F
))
6616 ("?x?parameter cannot be defaulted in non-Ada call",
6625 -- For VMS, descriptor mechanisms for parameters are allowed only for
6626 -- imported/exported subprograms. Moreover, the NCA descriptor is not
6627 -- allowed for parameters of exported subprograms.
6629 if OpenVMS_On_Target
then
6630 if Is_Exported
(E
) then
6631 F
:= First_Formal
(E
);
6632 while Present
(F
) loop
6633 if Mechanism
(F
) = By_Descriptor_NCA
then
6635 ("'N'C'A' descriptor for parameter not permitted", F
);
6637 ("\can only be used for imported subprogram", F
);
6643 elsif not Is_Imported
(E
) then
6644 F
:= First_Formal
(E
);
6645 while Present
(F
) loop
6646 if Mechanism
(F
) in Descriptor_Codes
then
6648 ("descriptor mechanism for parameter not permitted", F
);
6650 ("\can only be used for imported/exported subprogram", F
);
6658 -- Pragma Inline_Always is disallowed for dispatching subprograms
6659 -- because the address of such subprograms is saved in the dispatch
6660 -- table to support dispatching calls, and dispatching calls cannot
6661 -- be inlined. This is consistent with the restriction against using
6662 -- 'Access or 'Address on an Inline_Always subprogram.
6664 if Is_Dispatching_Operation
(E
)
6665 and then Has_Pragma_Inline_Always
(E
)
6668 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
6671 -- Because of the implicit representation of inherited predefined
6672 -- operators in the front-end, the overriding status of the operation
6673 -- may be affected when a full view of a type is analyzed, and this is
6674 -- not captured by the analysis of the corresponding type declaration.
6675 -- Therefore the correctness of a not-overriding indicator must be
6676 -- rechecked when the subprogram is frozen.
6678 if Nkind
(E
) = N_Defining_Operator_Symbol
6679 and then not Error_Posted
(Parent
(E
))
6681 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
6683 end Freeze_Subprogram
;
6685 ----------------------
6686 -- Is_Fully_Defined --
6687 ----------------------
6689 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
6691 if Ekind
(T
) = E_Class_Wide_Type
then
6692 return Is_Fully_Defined
(Etype
(T
));
6694 elsif Is_Array_Type
(T
) then
6695 return Is_Fully_Defined
(Component_Type
(T
));
6697 elsif Is_Record_Type
(T
)
6698 and not Is_Private_Type
(T
)
6700 -- Verify that the record type has no components with private types
6701 -- without completion.
6707 Comp
:= First_Component
(T
);
6708 while Present
(Comp
) loop
6709 if not Is_Fully_Defined
(Etype
(Comp
)) then
6713 Next_Component
(Comp
);
6718 -- For the designated type of an access to subprogram, all types in
6719 -- the profile must be fully defined.
6721 elsif Ekind
(T
) = E_Subprogram_Type
then
6726 F
:= First_Formal
(T
);
6727 while Present
(F
) loop
6728 if not Is_Fully_Defined
(Etype
(F
)) then
6735 return Is_Fully_Defined
(Etype
(T
));
6739 return not Is_Private_Type
(T
)
6740 or else Present
(Full_View
(Base_Type
(T
)));
6742 end Is_Fully_Defined
;
6744 ---------------------------------
6745 -- Process_Default_Expressions --
6746 ---------------------------------
6748 procedure Process_Default_Expressions
6750 After
: in out Node_Id
)
6752 Loc
: constant Source_Ptr
:= Sloc
(E
);
6759 Set_Default_Expressions_Processed
(E
);
6761 -- A subprogram instance and its associated anonymous subprogram share
6762 -- their signature. The default expression functions are defined in the
6763 -- wrapper packages for the anonymous subprogram, and should not be
6764 -- generated again for the instance.
6766 if Is_Generic_Instance
(E
)
6767 and then Present
(Alias
(E
))
6768 and then Default_Expressions_Processed
(Alias
(E
))
6773 Formal
:= First_Formal
(E
);
6774 while Present
(Formal
) loop
6775 if Present
(Default_Value
(Formal
)) then
6777 -- We work with a copy of the default expression because we
6778 -- do not want to disturb the original, since this would mess
6779 -- up the conformance checking.
6781 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
6783 -- The analysis of the expression may generate insert actions,
6784 -- which of course must not be executed. We wrap those actions
6785 -- in a procedure that is not called, and later on eliminated.
6786 -- The following cases have no side-effects, and are analyzed
6789 if Nkind
(Dcopy
) = N_Identifier
6790 or else Nkind_In
(Dcopy
, N_Expanded_Name
,
6792 N_Character_Literal
,
6794 or else (Nkind
(Dcopy
) = N_Real_Literal
6795 and then not Vax_Float
(Etype
(Dcopy
)))
6796 or else (Nkind
(Dcopy
) = N_Attribute_Reference
6797 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
6798 or else Known_Null
(Dcopy
)
6800 -- If there is no default function, we must still do a full
6801 -- analyze call on the default value, to ensure that all error
6802 -- checks are performed, e.g. those associated with static
6803 -- evaluation. Note: this branch will always be taken if the
6804 -- analyzer is turned off (but we still need the error checks).
6806 -- Note: the setting of parent here is to meet the requirement
6807 -- that we can only analyze the expression while attached to
6808 -- the tree. Really the requirement is that the parent chain
6809 -- be set, we don't actually need to be in the tree.
6811 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
6814 -- Default expressions are resolved with their own type if the
6815 -- context is generic, to avoid anomalies with private types.
6817 if Ekind
(Scope
(E
)) = E_Generic_Package
then
6820 Resolve
(Dcopy
, Etype
(Formal
));
6823 -- If that resolved expression will raise constraint error,
6824 -- then flag the default value as raising constraint error.
6825 -- This allows a proper error message on the calls.
6827 if Raises_Constraint_Error
(Dcopy
) then
6828 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
6831 -- If the default is a parameterless call, we use the name of
6832 -- the called function directly, and there is no body to build.
6834 elsif Nkind
(Dcopy
) = N_Function_Call
6835 and then No
(Parameter_Associations
(Dcopy
))
6839 -- Else construct and analyze the body of a wrapper procedure
6840 -- that contains an object declaration to hold the expression.
6841 -- Given that this is done only to complete the analysis, it
6842 -- simpler to build a procedure than a function which might
6843 -- involve secondary stack expansion.
6846 Dnam
:= Make_Temporary
(Loc
, 'D');
6849 Make_Subprogram_Body
(Loc
,
6851 Make_Procedure_Specification
(Loc
,
6852 Defining_Unit_Name
=> Dnam
),
6854 Declarations
=> New_List
(
6855 Make_Object_Declaration
(Loc
,
6856 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
6857 Object_Definition
=>
6858 New_Occurrence_Of
(Etype
(Formal
), Loc
),
6859 Expression
=> New_Copy_Tree
(Dcopy
))),
6861 Handled_Statement_Sequence
=>
6862 Make_Handled_Sequence_Of_Statements
(Loc
,
6863 Statements
=> Empty_List
));
6865 Set_Scope
(Dnam
, Scope
(E
));
6866 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
6867 Set_Is_Eliminated
(Dnam
);
6868 Insert_After
(After
, Dbody
);
6874 Next_Formal
(Formal
);
6876 end Process_Default_Expressions
;
6878 ----------------------------------------
6879 -- Set_Component_Alignment_If_Not_Set --
6880 ----------------------------------------
6882 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
6884 -- Ignore if not base type, subtypes don't need anything
6886 if Typ
/= Base_Type
(Typ
) then
6890 -- Do not override existing representation
6892 if Is_Packed
(Typ
) then
6895 elsif Has_Specified_Layout
(Typ
) then
6898 elsif Component_Alignment
(Typ
) /= Calign_Default
then
6902 Set_Component_Alignment
6903 (Typ
, Scope_Stack
.Table
6904 (Scope_Stack
.Last
).Component_Alignment_Default
);
6906 end Set_Component_Alignment_If_Not_Set
;
6912 procedure Undelay_Type
(T
: Entity_Id
) is
6914 Set_Has_Delayed_Freeze
(T
, False);
6915 Set_Freeze_Node
(T
, Empty
);
6917 -- Since we don't want T to have a Freeze_Node, we don't want its
6918 -- Full_View or Corresponding_Record_Type to have one either.
6920 -- ??? Fundamentally, this whole handling is a kludge. What we really
6921 -- want is to be sure that for an Itype that's part of record R and is a
6922 -- subtype of type T, that it's frozen after the later of the freeze
6923 -- points of R and T. We have no way of doing that directly, so what we
6924 -- do is force most such Itypes to be frozen as part of freezing R via
6925 -- this procedure and only delay the ones that need to be delayed
6926 -- (mostly the designated types of access types that are defined as part
6929 if Is_Private_Type
(T
)
6930 and then Present
(Full_View
(T
))
6931 and then Is_Itype
(Full_View
(T
))
6932 and then Is_Record_Type
(Scope
(Full_View
(T
)))
6934 Undelay_Type
(Full_View
(T
));
6937 if Is_Concurrent_Type
(T
)
6938 and then Present
(Corresponding_Record_Type
(T
))
6939 and then Is_Itype
(Corresponding_Record_Type
(T
))
6940 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
6942 Undelay_Type
(Corresponding_Record_Type
(T
));
6950 procedure Warn_Overlay
6955 Ent
: constant Entity_Id
:= Entity
(Nam
);
6956 -- The object to which the address clause applies
6959 Old
: Entity_Id
:= Empty
;
6963 -- No warning if address clause overlay warnings are off
6965 if not Address_Clause_Overlay_Warnings
then
6969 -- No warning if there is an explicit initialization
6971 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
6973 if Present
(Init
) and then Comes_From_Source
(Init
) then
6977 -- We only give the warning for non-imported entities of a type for
6978 -- which a non-null base init proc is defined, or for objects of access
6979 -- types with implicit null initialization, or when Normalize_Scalars
6980 -- applies and the type is scalar or a string type (the latter being
6981 -- tested for because predefined String types are initialized by inline
6982 -- code rather than by an init_proc). Note that we do not give the
6983 -- warning for Initialize_Scalars, since we suppressed initialization
6984 -- in this case. Also, do not warn if Suppress_Initialization is set.
6987 and then not Is_Imported
(Ent
)
6988 and then not Initialization_Suppressed
(Typ
)
6989 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
6990 or else Is_Access_Type
(Typ
)
6991 or else (Normalize_Scalars
6992 and then (Is_Scalar_Type
(Typ
)
6993 or else Is_String_Type
(Typ
))))
6995 if Nkind
(Expr
) = N_Attribute_Reference
6996 and then Is_Entity_Name
(Prefix
(Expr
))
6998 Old
:= Entity
(Prefix
(Expr
));
7000 elsif Is_Entity_Name
(Expr
)
7001 and then Ekind
(Entity
(Expr
)) = E_Constant
7003 Decl
:= Declaration_Node
(Entity
(Expr
));
7005 if Nkind
(Decl
) = N_Object_Declaration
7006 and then Present
(Expression
(Decl
))
7007 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
7008 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
7010 Old
:= Entity
(Prefix
(Expression
(Decl
)));
7012 elsif Nkind
(Expr
) = N_Function_Call
then
7016 -- A function call (most likely to To_Address) is probably not an
7017 -- overlay, so skip warning. Ditto if the function call was inlined
7018 -- and transformed into an entity.
7020 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
7024 Decl
:= Next
(Parent
(Expr
));
7026 -- If a pragma Import follows, we assume that it is for the current
7027 -- target of the address clause, and skip the warning.
7030 and then Nkind
(Decl
) = N_Pragma
7031 and then Pragma_Name
(Decl
) = Name_Import
7036 if Present
(Old
) then
7037 Error_Msg_Node_2
:= Old
;
7039 ("default initialization of & may modify &??",
7043 ("default initialization of & may modify overlaid storage??",
7047 -- Add friendly warning if initialization comes from a packed array
7050 if Is_Record_Type
(Typ
) then
7055 Comp
:= First_Component
(Typ
);
7056 while Present
(Comp
) loop
7057 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
7058 and then Present
(Expression
(Parent
(Comp
)))
7061 elsif Is_Array_Type
(Etype
(Comp
))
7062 and then Present
(Packed_Array_Type
(Etype
(Comp
)))
7065 ("\packed array component& " &
7066 "will be initialized to zero??",
7070 Next_Component
(Comp
);
7077 ("\use pragma Import for & to " &
7078 "suppress initialization (RM B.1(24))??",