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
;
96 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
97 -- clause, verify that the component type is compatible. For arrays,
98 -- Comp is Empty; for records, it is the entity of the component under
101 procedure Check_Strict_Alignment
(E
: Entity_Id
);
102 -- E is a base type. If E is tagged or has a component that is aliased
103 -- or tagged or contains something this is aliased or tagged, set
106 procedure Check_Unsigned_Type
(E
: Entity_Id
);
107 pragma Inline
(Check_Unsigned_Type
);
108 -- If E is a fixed-point or discrete type, then all the necessary work
109 -- to freeze it is completed except for possible setting of the flag
110 -- Is_Unsigned_Type, which is done by this procedure. The call has no
111 -- effect if the entity E is not a discrete or fixed-point type.
113 procedure Freeze_And_Append
116 Result
: in out List_Id
);
117 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
118 -- nodes to Result, modifying Result from No_List if necessary. N has
119 -- the same usage as in Freeze_Entity.
121 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
122 -- Freeze enumeration type. The Esize field is set as processing
123 -- proceeds (i.e. set by default when the type is declared and then
124 -- adjusted by rep clauses. What this procedure does is to make sure
125 -- that if a foreign convention is specified, and no specific size
126 -- is given, then the size must be at least Integer'Size.
128 procedure Freeze_Static_Object
(E
: Entity_Id
);
129 -- If an object is frozen which has Is_Statically_Allocated set, then
130 -- all referenced types must also be marked with this flag. This routine
131 -- is in charge of meeting this requirement for the object entity E.
133 procedure Freeze_Subprogram
(E
: Entity_Id
);
134 -- Perform freezing actions for a subprogram (create extra formals,
135 -- and set proper default mechanism values). Note that this routine
136 -- is not called for internal subprograms, for which neither of these
137 -- actions is needed (or desirable, we do not want for example to have
138 -- these extra formals present in initialization procedures, where they
139 -- would serve no purpose). In this call E is either a subprogram or
140 -- a subprogram type (i.e. an access to a subprogram).
142 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
143 -- True if T is not private and has no private components, or has a full
144 -- view. Used to determine whether the designated type of an access type
145 -- should be frozen when the access type is frozen. This is done when an
146 -- allocator is frozen, or an expression that may involve attributes of
147 -- the designated type. Otherwise freezing the access type does not freeze
148 -- the designated type.
150 procedure Process_Default_Expressions
152 After
: in out Node_Id
);
153 -- This procedure is called for each subprogram to complete processing of
154 -- default expressions at the point where all types are known to be frozen.
155 -- The expressions must be analyzed in full, to make sure that all error
156 -- processing is done (they have only been pre-analyzed). If the expression
157 -- is not an entity or literal, its analysis may generate code which must
158 -- not be executed. In that case we build a function body to hold that
159 -- code. This wrapper function serves no other purpose (it used to be
160 -- called to evaluate the default, but now the default is inlined at each
163 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
164 -- Typ is a record or array type that is being frozen. This routine sets
165 -- the default component alignment from the scope stack values if the
166 -- alignment is otherwise not specified.
168 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
169 -- As each entity is frozen, this routine is called to deal with the
170 -- setting of Debug_Info_Needed for the entity. This flag is set if
171 -- the entity comes from source, or if we are in Debug_Generated_Code
172 -- mode or if the -gnatdV debug flag is set. However, it never sets
173 -- the flag if Debug_Info_Off is set. This procedure also ensures that
174 -- subsidiary entities have the flag set as required.
176 procedure Undelay_Type
(T
: Entity_Id
);
177 -- T is a type of a component that we know to be an Itype. We don't want
178 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
179 -- Full_View or Corresponding_Record_Type.
181 procedure Warn_Overlay
185 -- Expr is the expression for an address clause for entity Nam whose type
186 -- is Typ. If Typ has a default initialization, and there is no explicit
187 -- initialization in the source declaration, check whether the address
188 -- clause might cause overlaying of an entity, and emit a warning on the
189 -- side effect that the initialization will cause.
191 -------------------------------
192 -- Adjust_Esize_For_Alignment --
193 -------------------------------
195 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
199 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
200 Align
:= Alignment_In_Bits
(Typ
);
202 if Align
> Esize
(Typ
)
203 and then Align
<= Standard_Long_Long_Integer_Size
205 Set_Esize
(Typ
, Align
);
208 end Adjust_Esize_For_Alignment
;
210 ------------------------------------
211 -- Build_And_Analyze_Renamed_Body --
212 ------------------------------------
214 procedure Build_And_Analyze_Renamed_Body
217 After
: in out Node_Id
)
219 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
220 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
222 Renamed_Subp
: Entity_Id
;
225 -- If the renamed subprogram is intrinsic, there is no need for a
226 -- wrapper body: we set the alias that will be called and expanded which
227 -- completes the declaration. This transformation is only legal if the
228 -- renamed entity has already been elaborated.
230 -- Note that it is legal for a renaming_as_body to rename an intrinsic
231 -- subprogram, as long as the renaming occurs before the new entity
232 -- is frozen. See RM 8.5.4 (5).
234 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
235 and then Is_Entity_Name
(Name
(Body_Decl
))
237 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
239 Renamed_Subp
:= Empty
;
242 if Present
(Renamed_Subp
)
243 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
245 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
246 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
248 -- We can make the renaming entity intrinsic if the renamed function
249 -- has an interface name, or if it is one of the shift/rotate
250 -- operations known to the compiler.
253 (Present
(Interface_Name
(Renamed_Subp
))
254 or else Nam_In
(Chars
(Renamed_Subp
), Name_Rotate_Left
,
258 Name_Shift_Right_Arithmetic
))
260 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
262 if Present
(Alias
(Renamed_Subp
)) then
263 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
265 Set_Alias
(Ent
, Renamed_Subp
);
268 Set_Is_Intrinsic_Subprogram
(Ent
);
269 Set_Has_Completion
(Ent
);
272 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
273 Insert_After
(After
, Body_Node
);
274 Mark_Rewrite_Insertion
(Body_Node
);
278 end Build_And_Analyze_Renamed_Body
;
280 ------------------------
281 -- Build_Renamed_Body --
282 ------------------------
284 function Build_Renamed_Body
286 New_S
: Entity_Id
) return Node_Id
288 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
289 -- We use for the source location of the renamed body, the location of
290 -- the spec entity. It might seem more natural to use the location of
291 -- the renaming declaration itself, but that would be wrong, since then
292 -- the body we create would look as though it was created far too late,
293 -- and this could cause problems with elaboration order analysis,
294 -- particularly in connection with instantiations.
296 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
297 Nam
: constant Node_Id
:= Name
(N
);
299 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
300 Actuals
: List_Id
:= No_List
;
305 O_Formal
: Entity_Id
;
306 Param_Spec
: Node_Id
;
308 Pref
: Node_Id
:= Empty
;
309 -- If the renamed entity is a primitive operation given in prefix form,
310 -- the prefix is the target object and it has to be added as the first
311 -- actual in the generated call.
314 -- Determine the entity being renamed, which is the target of the call
315 -- statement. If the name is an explicit dereference, this is a renaming
316 -- of a subprogram type rather than a subprogram. The name itself is
319 if Nkind
(Nam
) = N_Selected_Component
then
320 Old_S
:= Entity
(Selector_Name
(Nam
));
322 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
323 Old_S
:= Etype
(Nam
);
325 elsif Nkind
(Nam
) = N_Indexed_Component
then
326 if Is_Entity_Name
(Prefix
(Nam
)) then
327 Old_S
:= Entity
(Prefix
(Nam
));
329 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
332 elsif Nkind
(Nam
) = N_Character_Literal
then
333 Old_S
:= Etype
(New_S
);
336 Old_S
:= Entity
(Nam
);
339 if Is_Entity_Name
(Nam
) then
341 -- If the renamed entity is a predefined operator, retain full name
342 -- to ensure its visibility.
344 if Ekind
(Old_S
) = E_Operator
345 and then Nkind
(Nam
) = N_Expanded_Name
347 Call_Name
:= New_Copy
(Name
(N
));
349 Call_Name
:= New_Reference_To
(Old_S
, Loc
);
353 if Nkind
(Nam
) = N_Selected_Component
354 and then Present
(First_Formal
(Old_S
))
356 (Is_Controlling_Formal
(First_Formal
(Old_S
))
357 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
360 -- Retrieve the target object, to be added as a first actual
363 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
364 Pref
:= Prefix
(Nam
);
367 Call_Name
:= New_Copy
(Name
(N
));
370 -- Original name may have been overloaded, but is fully resolved now
372 Set_Is_Overloaded
(Call_Name
, False);
375 -- For simple renamings, subsequent calls can be expanded directly as
376 -- calls to the renamed entity. The body must be generated in any case
377 -- for calls that may appear elsewhere. This is not done in the case
378 -- where the subprogram is an instantiation because the actual proper
379 -- body has not been built yet.
381 if Ekind_In
(Old_S
, E_Function
, E_Procedure
)
382 and then Nkind
(Decl
) = N_Subprogram_Declaration
383 and then not Is_Generic_Instance
(Old_S
)
385 Set_Body_To_Inline
(Decl
, Old_S
);
388 -- The body generated for this renaming is an internal artifact, and
389 -- does not constitute a freeze point for the called entity.
391 Set_Must_Not_Freeze
(Call_Name
);
393 Formal
:= First_Formal
(Defining_Entity
(Decl
));
395 if Present
(Pref
) then
397 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
398 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
401 -- The controlling formal may be an access parameter, or the
402 -- actual may be an access value, so adjust accordingly.
404 if Is_Access_Type
(Pref_Type
)
405 and then not Is_Access_Type
(Form_Type
)
408 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
410 elsif Is_Access_Type
(Form_Type
)
411 and then not Is_Access_Type
(Pref
)
414 (Make_Attribute_Reference
(Loc
,
415 Attribute_Name
=> Name_Access
,
416 Prefix
=> Relocate_Node
(Pref
)));
418 Actuals
:= New_List
(Pref
);
422 elsif Present
(Formal
) then
429 if Present
(Formal
) then
430 while Present
(Formal
) loop
431 Append
(New_Reference_To
(Formal
, Loc
), Actuals
);
432 Next_Formal
(Formal
);
436 -- If the renamed entity is an entry, inherit its profile. For other
437 -- renamings as bodies, both profiles must be subtype conformant, so it
438 -- is not necessary to replace the profile given in the declaration.
439 -- However, default values that are aggregates are rewritten when
440 -- partially analyzed, so we recover the original aggregate to insure
441 -- that subsequent conformity checking works. Similarly, if the default
442 -- expression was constant-folded, recover the original expression.
444 Formal
:= First_Formal
(Defining_Entity
(Decl
));
446 if Present
(Formal
) then
447 O_Formal
:= First_Formal
(Old_S
);
448 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
449 while Present
(Formal
) loop
450 if Is_Entry
(Old_S
) then
451 if Nkind
(Parameter_Type
(Param_Spec
)) /=
454 Set_Etype
(Formal
, Etype
(O_Formal
));
455 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
458 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
459 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
460 Nkind
(Default_Value
(O_Formal
))
462 Set_Expression
(Param_Spec
,
463 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
466 Next_Formal
(Formal
);
467 Next_Formal
(O_Formal
);
472 -- If the renamed entity is a function, the generated body contains a
473 -- return statement. Otherwise, build a procedure call. If the entity is
474 -- an entry, subsequent analysis of the call will transform it into the
475 -- proper entry or protected operation call. If the renamed entity is
476 -- a character literal, return it directly.
478 if Ekind
(Old_S
) = E_Function
479 or else Ekind
(Old_S
) = E_Operator
480 or else (Ekind
(Old_S
) = E_Subprogram_Type
481 and then Etype
(Old_S
) /= Standard_Void_Type
)
484 Make_Simple_Return_Statement
(Loc
,
486 Make_Function_Call
(Loc
,
488 Parameter_Associations
=> Actuals
));
490 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
492 Make_Simple_Return_Statement
(Loc
,
493 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
495 elsif Nkind
(Nam
) = N_Character_Literal
then
497 Make_Simple_Return_Statement
(Loc
,
498 Expression
=> Call_Name
);
502 Make_Procedure_Call_Statement
(Loc
,
504 Parameter_Associations
=> Actuals
);
507 -- Create entities for subprogram body and formals
509 Set_Defining_Unit_Name
(Spec
,
510 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
512 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
513 while Present
(Param_Spec
) loop
514 Set_Defining_Identifier
(Param_Spec
,
515 Make_Defining_Identifier
(Loc
,
516 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
521 Make_Subprogram_Body
(Loc
,
522 Specification
=> Spec
,
523 Declarations
=> New_List
,
524 Handled_Statement_Sequence
=>
525 Make_Handled_Sequence_Of_Statements
(Loc
,
526 Statements
=> New_List
(Call_Node
)));
528 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
530 Make_Subprogram_Declaration
(Loc
,
531 Specification
=> Specification
(N
)));
534 -- Link the body to the entity whose declaration it completes. If
535 -- the body is analyzed when the renamed entity is frozen, it may
536 -- be necessary to restore the proper scope (see package Exp_Ch13).
538 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
539 and then Present
(Corresponding_Spec
(N
))
541 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
543 Set_Corresponding_Spec
(Body_Node
, New_S
);
547 end Build_Renamed_Body
;
549 --------------------------
550 -- Check_Address_Clause --
551 --------------------------
553 procedure Check_Address_Clause
(E
: Entity_Id
) is
554 Addr
: constant Node_Id
:= Address_Clause
(E
);
556 Decl
: constant Node_Id
:= Declaration_Node
(E
);
557 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
558 Typ
: constant Entity_Id
:= Etype
(E
);
561 if Present
(Addr
) then
562 Expr
:= Expression
(Addr
);
564 if Needs_Constant_Address
(Decl
, Typ
) then
565 Check_Constant_Address_Clause
(Expr
, E
);
567 -- Has_Delayed_Freeze was set on E when the address clause was
568 -- analyzed, and must remain set because we want the address
569 -- clause to be elaborated only after any entity it references
570 -- has been elaborated.
573 -- If Rep_Clauses are to be ignored, remove address clause from
574 -- list attached to entity, because it may be illegal for gigi,
575 -- for example by breaking order of elaboration..
577 if Ignore_Rep_Clauses
then
582 Rep
:= First_Rep_Item
(E
);
585 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
589 and then Next_Rep_Item
(Rep
) /= Addr
591 Rep
:= Next_Rep_Item
(Rep
);
595 if Present
(Rep
) then
596 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
600 Rewrite
(Addr
, Make_Null_Statement
(Sloc
(E
)));
602 elsif not Error_Posted
(Expr
)
603 and then not Needs_Finalization
(Typ
)
605 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
608 if Present
(Expression
(Decl
)) then
610 -- Capture initialization value at point of declaration
612 Remove_Side_Effects
(Expression
(Decl
));
614 -- Move initialization to freeze actions (once the object has
615 -- been frozen, and the address clause alignment check has been
618 Append_Freeze_Action
(E
,
619 Make_Assignment_Statement
(Loc
,
620 Name
=> New_Occurrence_Of
(E
, Loc
),
621 Expression
=> Expression
(Decl
)));
623 Set_No_Initialization
(Decl
);
626 end Check_Address_Clause
;
628 -----------------------------
629 -- Check_Compile_Time_Size --
630 -----------------------------
632 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
634 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
635 -- Sets the compile time known size (32 bits or less) in the Esize
636 -- field, of T checking for a size clause that was given which attempts
637 -- to give a smaller size, and also checking for an alignment clause.
639 function Size_Known
(T
: Entity_Id
) return Boolean;
640 -- Recursive function that does all the work
642 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
643 -- If T is a constrained subtype, its size is not known if any of its
644 -- discriminant constraints is not static and it is not a null record.
645 -- The test is conservative and doesn't check that the components are
646 -- in fact constrained by non-static discriminant values. Could be made
653 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
658 -- Check for bad size clause given
660 elsif Has_Size_Clause
(T
) then
661 if RM_Size
(T
) < S
then
662 Error_Msg_Uint_1
:= S
;
664 ("size for& too small, minimum allowed is ^",
668 -- Set size if not set already
670 elsif Unknown_RM_Size
(T
) then
679 function Size_Known
(T
: Entity_Id
) return Boolean is
687 if Size_Known_At_Compile_Time
(T
) then
690 -- Always True for scalar types. This is true even for generic formal
691 -- scalar types. We used to return False in the latter case, but the
692 -- size is known at compile time, even in the template, we just do
693 -- not know the exact size but that's not the point of this routine.
695 elsif Is_Scalar_Type
(T
)
696 or else Is_Task_Type
(T
)
702 elsif Is_Array_Type
(T
) then
704 -- String literals always have known size, and we can set it
706 if Ekind
(T
) = E_String_Literal_Subtype
then
707 Set_Small_Size
(T
, Component_Size
(T
)
708 * String_Literal_Length
(T
));
711 -- Unconstrained types never have known at compile time size
713 elsif not Is_Constrained
(T
) then
716 -- Don't do any recursion on type with error posted, since we may
717 -- have a malformed type that leads us into a loop.
719 elsif Error_Posted
(T
) then
722 -- Otherwise if component size unknown, then array size unknown
724 elsif not Size_Known
(Component_Type
(T
)) then
728 -- Check for all indexes static, and also compute possible size
729 -- (in case it is less than 32 and may be packable).
732 Esiz
: Uint
:= Component_Size
(T
);
736 Index
:= First_Index
(T
);
737 while Present
(Index
) loop
738 if Nkind
(Index
) = N_Range
then
739 Get_Index_Bounds
(Index
, Low
, High
);
741 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
745 Low
:= Type_Low_Bound
(Etype
(Index
));
746 High
:= Type_High_Bound
(Etype
(Index
));
749 if not Compile_Time_Known_Value
(Low
)
750 or else not Compile_Time_Known_Value
(High
)
751 or else Etype
(Index
) = Any_Type
756 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
768 Set_Small_Size
(T
, Esiz
);
772 -- Access types always have known at compile time sizes
774 elsif Is_Access_Type
(T
) then
777 -- For non-generic private types, go to underlying type if present
779 elsif Is_Private_Type
(T
)
780 and then not Is_Generic_Type
(T
)
781 and then Present
(Underlying_Type
(T
))
783 -- Don't do any recursion on type with error posted, since we may
784 -- have a malformed type that leads us into a loop.
786 if Error_Posted
(T
) then
789 return Size_Known
(Underlying_Type
(T
));
794 elsif Is_Record_Type
(T
) then
796 -- A class-wide type is never considered to have a known size
798 if Is_Class_Wide_Type
(T
) then
801 -- A subtype of a variant record must not have non-static
802 -- discriminated components.
804 elsif T
/= Base_Type
(T
)
805 and then not Static_Discriminated_Components
(T
)
809 -- Don't do any recursion on type with error posted, since we may
810 -- have a malformed type that leads us into a loop.
812 elsif Error_Posted
(T
) then
816 -- Now look at the components of the record
819 -- The following two variables are used to keep track of the
820 -- size of packed records if we can tell the size of the packed
821 -- record in the front end. Packed_Size_Known is True if so far
822 -- we can figure out the size. It is initialized to True for a
823 -- packed record, unless the record has discriminants or atomic
824 -- components or independent components.
826 -- The reason we eliminate the discriminated case is that
827 -- we don't know the way the back end lays out discriminated
828 -- packed records. If Packed_Size_Known is True, then
829 -- Packed_Size is the size in bits so far.
831 Packed_Size_Known
: Boolean :=
833 and then not Has_Discriminants
(T
)
834 and then not Has_Atomic_Components
(T
)
835 and then not Has_Independent_Components
(T
);
837 Packed_Size
: Uint
:= Uint_0
;
838 -- SIze in bis so far
841 -- Test for variant part present
843 if Has_Discriminants
(T
)
844 and then Present
(Parent
(T
))
845 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
846 and then Nkind
(Type_Definition
(Parent
(T
))) =
848 and then not Null_Present
(Type_Definition
(Parent
(T
)))
849 and then Present
(Variant_Part
850 (Component_List
(Type_Definition
(Parent
(T
)))))
852 -- If variant part is present, and type is unconstrained,
853 -- then we must have defaulted discriminants, or a size
854 -- clause must be present for the type, or else the size
855 -- is definitely not known at compile time.
857 if not Is_Constrained
(T
)
859 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
860 and then Unknown_RM_Size
(T
)
866 -- Loop through components
868 Comp
:= First_Component_Or_Discriminant
(T
);
869 while Present
(Comp
) loop
870 Ctyp
:= Etype
(Comp
);
872 -- We do not know the packed size if there is a component
873 -- clause present (we possibly could, but this would only
874 -- help in the case of a record with partial rep clauses.
875 -- That's because in the case of full rep clauses, the
876 -- size gets figured out anyway by a different circuit).
878 if Present
(Component_Clause
(Comp
)) then
879 Packed_Size_Known
:= False;
882 -- We do not know the packed size if we have a by reference
883 -- type, or an atomic type or an atomic component.
886 or else Is_Atomic
(Comp
)
887 or else Is_By_Reference_Type
(Ctyp
)
889 Packed_Size_Known
:= False;
892 -- We need to identify a component that is an array where
893 -- the index type is an enumeration type with non-standard
894 -- representation, and some bound of the type depends on a
897 -- This is because gigi computes the size by doing a
898 -- substitution of the appropriate discriminant value in
899 -- the size expression for the base type, and gigi is not
900 -- clever enough to evaluate the resulting expression (which
901 -- involves a call to rep_to_pos) at compile time.
903 -- It would be nice if gigi would either recognize that
904 -- this expression can be computed at compile time, or
905 -- alternatively figured out the size from the subtype
906 -- directly, where all the information is at hand ???
908 if Is_Array_Type
(Etype
(Comp
))
909 and then Present
(Packed_Array_Type
(Etype
(Comp
)))
912 Ocomp
: constant Entity_Id
:=
913 Original_Record_Component
(Comp
);
914 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
920 Ind
:= First_Index
(OCtyp
);
921 while Present
(Ind
) loop
922 Indtyp
:= Etype
(Ind
);
924 if Is_Enumeration_Type
(Indtyp
)
925 and then Has_Non_Standard_Rep
(Indtyp
)
927 Lo
:= Type_Low_Bound
(Indtyp
);
928 Hi
:= Type_High_Bound
(Indtyp
);
930 if Is_Entity_Name
(Lo
)
931 and then Ekind
(Entity
(Lo
)) = E_Discriminant
935 elsif Is_Entity_Name
(Hi
)
936 and then Ekind
(Entity
(Hi
)) = E_Discriminant
947 -- Clearly size of record is not known if the size of one of
948 -- the components is not known.
950 if not Size_Known
(Ctyp
) then
954 -- Accumulate packed size if possible
956 if Packed_Size_Known
then
958 -- We can only deal with elementary types, since for
959 -- non-elementary components, alignment enters into the
960 -- picture, and we don't know enough to handle proper
961 -- alignment in this context. Packed arrays count as
962 -- elementary if the representation is a modular type.
964 if Is_Elementary_Type
(Ctyp
)
965 or else (Is_Array_Type
(Ctyp
)
966 and then Present
(Packed_Array_Type
(Ctyp
))
967 and then Is_Modular_Integer_Type
968 (Packed_Array_Type
(Ctyp
)))
970 -- Packed size unknown if we have an atomic type
971 -- or a by reference type, since the back end
972 -- knows how these are layed out.
975 or else Is_By_Reference_Type
(Ctyp
)
977 Packed_Size_Known
:= False;
979 -- If RM_Size is known and static, then we can keep
980 -- accumulating the packed size
982 elsif Known_Static_RM_Size
(Ctyp
) then
984 -- A little glitch, to be removed sometime ???
985 -- gigi does not understand zero sizes yet.
987 if RM_Size
(Ctyp
) = Uint_0
then
988 Packed_Size_Known
:= False;
990 -- Normal case where we can keep accumulating the
991 -- packed array size.
994 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
997 -- If we have a field whose RM_Size is not known then
998 -- we can't figure out the packed size here.
1001 Packed_Size_Known
:= False;
1004 -- If we have a non-elementary type we can't figure out
1005 -- the packed array size (alignment issues).
1008 Packed_Size_Known
:= False;
1012 Next_Component_Or_Discriminant
(Comp
);
1015 if Packed_Size_Known
then
1016 Set_Small_Size
(T
, Packed_Size
);
1022 -- All other cases, size not known at compile time
1029 -------------------------------------
1030 -- Static_Discriminated_Components --
1031 -------------------------------------
1033 function Static_Discriminated_Components
1034 (T
: Entity_Id
) return Boolean
1036 Constraint
: Elmt_Id
;
1039 if Has_Discriminants
(T
)
1040 and then Present
(Discriminant_Constraint
(T
))
1041 and then Present
(First_Component
(T
))
1043 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1044 while Present
(Constraint
) loop
1045 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1049 Next_Elmt
(Constraint
);
1054 end Static_Discriminated_Components
;
1056 -- Start of processing for Check_Compile_Time_Size
1059 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1060 end Check_Compile_Time_Size
;
1062 -----------------------------------
1063 -- Check_Component_Storage_Order --
1064 -----------------------------------
1066 procedure Check_Component_Storage_Order
1067 (Encl_Type
: Entity_Id
;
1070 Comp_Type
: Entity_Id
;
1075 Comp_Byte_Aligned
: Boolean;
1076 -- Set True for the record case, when Comp starts on a byte boundary
1077 -- (in which case it is allowed to have different storage order).
1082 if Present
(Comp
) then
1084 Comp_Type
:= Etype
(Comp
);
1086 if Is_Tag
(Comp
) then
1088 Comp_Byte_Aligned
:= True;
1091 Comp_Def
:= Component_Definition
(Parent
(Comp
));
1092 Comp_Byte_Aligned
:=
1093 Present
(Component_Clause
(Comp
))
1095 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1101 Err_Node
:= Encl_Type
;
1102 Comp_Type
:= Component_Type
(Encl_Type
);
1103 Comp_Def
:= Component_Definition
1104 (Type_Definition
(Declaration_Node
(Encl_Type
)));
1106 Comp_Byte_Aligned
:= False;
1109 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1110 -- the attribute definition clause is attached to the first subtype.
1112 Comp_Type
:= Base_Type
(Comp_Type
);
1113 ADC
:= Get_Attribute_Definition_Clause
1114 (First_Subtype
(Comp_Type
),
1115 Attribute_Scalar_Storage_Order
);
1117 if Is_Record_Type
(Comp_Type
) or else Is_Array_Type
(Comp_Type
) then
1118 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1119 if Reverse_Storage_Order
(Encl_Type
)
1121 Reverse_Storage_Order
(Comp_Type
)
1124 ("record extension must have same scalar storage order as "
1125 & "parent", Err_Node
);
1129 Error_Msg_N
("nested composite must have explicit scalar "
1130 & "storage order", Err_Node
);
1132 elsif (Reverse_Storage_Order
(Encl_Type
)
1134 Reverse_Storage_Order
(Comp_Type
))
1135 and then not Comp_Byte_Aligned
1138 ("type of non-byte-aligned component must have same scalar "
1139 & "storage order as enclosing composite", Err_Node
);
1142 elsif Present
(Comp_Def
) and then Aliased_Present
(Comp_Def
) then
1144 ("aliased component not permitted for type with "
1145 & "explicit Scalar_Storage_Order", Err_Node
);
1147 end Check_Component_Storage_Order
;
1149 -----------------------------
1150 -- Check_Debug_Info_Needed --
1151 -----------------------------
1153 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1155 if Debug_Info_Off
(T
) then
1158 elsif Comes_From_Source
(T
)
1159 or else Debug_Generated_Code
1160 or else Debug_Flag_VV
1161 or else Needs_Debug_Info
(T
)
1163 Set_Debug_Info_Needed
(T
);
1165 end Check_Debug_Info_Needed
;
1167 ----------------------------
1168 -- Check_Strict_Alignment --
1169 ----------------------------
1171 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1175 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1176 Set_Strict_Alignment
(E
);
1178 elsif Is_Array_Type
(E
) then
1179 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1181 elsif Is_Record_Type
(E
) then
1182 if Is_Limited_Record
(E
) then
1183 Set_Strict_Alignment
(E
);
1187 Comp
:= First_Component
(E
);
1188 while Present
(Comp
) loop
1189 if not Is_Type
(Comp
)
1190 and then (Strict_Alignment
(Etype
(Comp
))
1191 or else Is_Aliased
(Comp
))
1193 Set_Strict_Alignment
(E
);
1197 Next_Component
(Comp
);
1200 end Check_Strict_Alignment
;
1202 -------------------------
1203 -- Check_Unsigned_Type --
1204 -------------------------
1206 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1207 Ancestor
: Entity_Id
;
1212 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1216 -- Do not attempt to analyze case where range was in error
1218 if No
(Scalar_Range
(E
))
1219 or else Error_Posted
(Scalar_Range
(E
))
1224 -- The situation that is non trivial is something like
1226 -- subtype x1 is integer range -10 .. +10;
1227 -- subtype x2 is x1 range 0 .. V1;
1228 -- subtype x3 is x2 range V2 .. V3;
1229 -- subtype x4 is x3 range V4 .. V5;
1231 -- where Vn are variables. Here the base type is signed, but we still
1232 -- know that x4 is unsigned because of the lower bound of x2.
1234 -- The only way to deal with this is to look up the ancestor chain
1238 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1242 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1244 if Compile_Time_Known_Value
(Lo_Bound
) then
1246 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1247 Set_Is_Unsigned_Type
(E
, True);
1253 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1255 -- If no ancestor had a static lower bound, go to base type
1257 if No
(Ancestor
) then
1259 -- Note: the reason we still check for a compile time known
1260 -- value for the base type is that at least in the case of
1261 -- generic formals, we can have bounds that fail this test,
1262 -- and there may be other cases in error situations.
1264 Btyp
:= Base_Type
(E
);
1266 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1270 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1272 if Compile_Time_Known_Value
(Lo_Bound
)
1273 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1275 Set_Is_Unsigned_Type
(E
, True);
1282 end Check_Unsigned_Type
;
1284 -------------------------
1285 -- Is_Atomic_Aggregate --
1286 -------------------------
1288 function Is_Atomic_Aggregate
1290 Typ
: Entity_Id
) return Boolean
1292 Loc
: constant Source_Ptr
:= Sloc
(E
);
1300 -- Array may be qualified, so find outer context
1302 if Nkind
(Par
) = N_Qualified_Expression
then
1303 Par
:= Parent
(Par
);
1306 if Nkind_In
(Par
, N_Object_Declaration
, N_Assignment_Statement
)
1307 and then Comes_From_Source
(Par
)
1309 Temp
:= Make_Temporary
(Loc
, 'T', E
);
1311 Make_Object_Declaration
(Loc
,
1312 Defining_Identifier
=> Temp
,
1313 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1314 Expression
=> Relocate_Node
(E
));
1315 Insert_Before
(Par
, New_N
);
1318 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1324 end Is_Atomic_Aggregate
;
1330 -- Note: the easy coding for this procedure would be to just build a
1331 -- single list of freeze nodes and then insert them and analyze them
1332 -- all at once. This won't work, because the analysis of earlier freeze
1333 -- nodes may recursively freeze types which would otherwise appear later
1334 -- on in the freeze list. So we must analyze and expand the freeze nodes
1335 -- as they are generated.
1337 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1341 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1342 -- This is the internal recursive routine that does freezing of entities
1343 -- (but NOT the analysis of default expressions, which should not be
1344 -- recursive, we don't want to analyze those till we are sure that ALL
1345 -- the types are frozen).
1347 --------------------
1348 -- Freeze_All_Ent --
1349 --------------------
1351 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1356 procedure Process_Flist
;
1357 -- If freeze nodes are present, insert and analyze, and reset cursor
1358 -- for next insertion.
1364 procedure Process_Flist
is
1366 if Is_Non_Empty_List
(Flist
) then
1367 Lastn
:= Next
(After
);
1368 Insert_List_After_And_Analyze
(After
, Flist
);
1370 if Present
(Lastn
) then
1371 After
:= Prev
(Lastn
);
1373 After
:= Last
(List_Containing
(After
));
1378 -- Start or processing for Freeze_All_Ent
1382 while Present
(E
) loop
1384 -- If the entity is an inner package which is not a package
1385 -- renaming, then its entities must be frozen at this point. Note
1386 -- that such entities do NOT get frozen at the end of the nested
1387 -- package itself (only library packages freeze).
1389 -- Same is true for task declarations, where anonymous records
1390 -- created for entry parameters must be frozen.
1392 if Ekind
(E
) = E_Package
1393 and then No
(Renamed_Object
(E
))
1394 and then not Is_Child_Unit
(E
)
1395 and then not Is_Frozen
(E
)
1398 Install_Visible_Declarations
(E
);
1399 Install_Private_Declarations
(E
);
1401 Freeze_All
(First_Entity
(E
), After
);
1403 End_Package_Scope
(E
);
1405 if Is_Generic_Instance
(E
)
1406 and then Has_Delayed_Freeze
(E
)
1408 Set_Has_Delayed_Freeze
(E
, False);
1409 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1412 elsif Ekind
(E
) in Task_Kind
1414 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
1416 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
1419 Freeze_All
(First_Entity
(E
), After
);
1422 -- For a derived tagged type, we must ensure that all the
1423 -- primitive operations of the parent have been frozen, so that
1424 -- their addresses will be in the parent's dispatch table at the
1425 -- point it is inherited.
1427 elsif Ekind
(E
) = E_Record_Type
1428 and then Is_Tagged_Type
(E
)
1429 and then Is_Tagged_Type
(Etype
(E
))
1430 and then Is_Derived_Type
(E
)
1433 Prim_List
: constant Elist_Id
:=
1434 Primitive_Operations
(Etype
(E
));
1440 Prim
:= First_Elmt
(Prim_List
);
1441 while Present
(Prim
) loop
1442 Subp
:= Node
(Prim
);
1444 if Comes_From_Source
(Subp
)
1445 and then not Is_Frozen
(Subp
)
1447 Flist
:= Freeze_Entity
(Subp
, After
);
1456 if not Is_Frozen
(E
) then
1457 Flist
:= Freeze_Entity
(E
, After
);
1460 -- If already frozen, and there are delayed aspects, this is where
1461 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1462 -- for a description of how we handle aspect visibility).
1464 elsif Has_Delayed_Aspects
(E
) then
1466 -- Retrieve the visibility to the discriminants in order to
1467 -- analyze properly the aspects.
1469 Push_Scope_And_Install_Discriminants
(E
);
1475 Ritem
:= First_Rep_Item
(E
);
1476 while Present
(Ritem
) loop
1477 if Nkind
(Ritem
) = N_Aspect_Specification
1478 and then Entity
(Ritem
) = E
1479 and then Is_Delayed_Aspect
(Ritem
)
1481 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1484 Ritem
:= Next_Rep_Item
(Ritem
);
1488 Uninstall_Discriminants_And_Pop_Scope
(E
);
1491 -- If an incomplete type is still not frozen, this may be a
1492 -- premature freezing because of a body declaration that follows.
1493 -- Indicate where the freezing took place. Freezing will happen
1494 -- if the body comes from source, but not if it is internally
1495 -- generated, for example as the body of a type invariant.
1497 -- If the freezing is caused by the end of the current declarative
1498 -- part, it is a Taft Amendment type, and there is no error.
1500 if not Is_Frozen
(E
)
1501 and then Ekind
(E
) = E_Incomplete_Type
1504 Bod
: constant Node_Id
:= Next
(After
);
1507 -- The presence of a body freezes all entities previously
1508 -- declared in the current list of declarations, but this
1509 -- does not apply if the body does not come from source.
1510 -- A type invariant is transformed into a subprogram body
1511 -- which is placed at the end of the private part of the
1512 -- current package, but this body does not freeze incomplete
1513 -- types that may be declared in this private part.
1515 if (Nkind_In
(Bod
, N_Subprogram_Body
,
1520 or else Nkind
(Bod
) in N_Body_Stub
)
1522 List_Containing
(After
) = List_Containing
(Parent
(E
))
1523 and then Comes_From_Source
(Bod
)
1525 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1527 ("type& is frozen# before its full declaration",
1537 -- Start of processing for Freeze_All
1540 Freeze_All_Ent
(From
, After
);
1542 -- Now that all types are frozen, we can deal with default expressions
1543 -- that require us to build a default expression functions. This is the
1544 -- point at which such functions are constructed (after all types that
1545 -- might be used in such expressions have been frozen).
1547 -- For subprograms that are renaming_as_body, we create the wrapper
1548 -- bodies as needed.
1550 -- We also add finalization chains to access types whose designated
1551 -- types are controlled. This is normally done when freezing the type,
1552 -- but this misses recursive type definitions where the later members
1553 -- of the recursion introduce controlled components.
1555 -- Loop through entities
1558 while Present
(E
) loop
1559 if Is_Subprogram
(E
) then
1561 if not Default_Expressions_Processed
(E
) then
1562 Process_Default_Expressions
(E
, After
);
1565 if not Has_Completion
(E
) then
1566 Decl
:= Unit_Declaration_Node
(E
);
1568 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1569 if Error_Posted
(Decl
) then
1570 Set_Has_Completion
(E
);
1572 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1575 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1576 and then Present
(Corresponding_Body
(Decl
))
1578 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1579 = N_Subprogram_Renaming_Declaration
1581 Build_And_Analyze_Renamed_Body
1582 (Decl
, Corresponding_Body
(Decl
), After
);
1586 elsif Ekind
(E
) in Task_Kind
1588 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
1590 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
1596 Ent
:= First_Entity
(E
);
1597 while Present
(Ent
) loop
1599 and then not Default_Expressions_Processed
(Ent
)
1601 Process_Default_Expressions
(Ent
, After
);
1608 -- We add finalization masters to access types whose designated types
1609 -- require finalization. This is normally done when freezing the
1610 -- type, but this misses recursive type definitions where the later
1611 -- members of the recursion introduce controlled components (such as
1612 -- can happen when incomplete types are involved), as well cases
1613 -- where a component type is private and the controlled full type
1614 -- occurs after the access type is frozen. Cases that don't need a
1615 -- finalization master are generic formal types (the actual type will
1616 -- have it) and types with Java and CIL conventions, since those are
1617 -- used for API bindings. (Are there any other cases that should be
1618 -- excluded here???)
1620 elsif Is_Access_Type
(E
)
1621 and then Comes_From_Source
(E
)
1622 and then not Is_Generic_Type
(E
)
1623 and then Needs_Finalization
(Designated_Type
(E
))
1625 Build_Finalization_Master
(E
);
1632 -----------------------
1633 -- Freeze_And_Append --
1634 -----------------------
1636 procedure Freeze_And_Append
1639 Result
: in out List_Id
)
1641 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1643 if Is_Non_Empty_List
(L
) then
1644 if Result
= No_List
then
1647 Append_List
(L
, Result
);
1650 end Freeze_And_Append
;
1656 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1657 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, N
);
1659 if Is_Non_Empty_List
(Freeze_Nodes
) then
1660 Insert_Actions
(N
, Freeze_Nodes
);
1668 function Freeze_Entity
(E
: Entity_Id
; N
: Node_Id
) return List_Id
is
1669 Loc
: constant Source_Ptr
:= Sloc
(N
);
1670 Test_E
: Entity_Id
:= E
;
1677 Result
: List_Id
:= No_List
;
1678 -- List of freezing actions, left at No_List if none
1680 Has_Default_Initialization
: Boolean := False;
1681 -- This flag gets set to true for a variable with default initialization
1683 procedure Add_To_Result
(N
: Node_Id
);
1684 -- N is a freezing action to be appended to the Result
1686 function After_Last_Declaration
return Boolean;
1687 -- If Loc is a freeze_entity that appears after the last declaration
1688 -- in the scope, inhibit error messages on late completion.
1690 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1691 -- Check that an Access or Unchecked_Access attribute with a prefix
1692 -- which is the current instance type can only be applied when the type
1695 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1696 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1697 -- integer literal without an explicit corresponding size clause. The
1698 -- caller has checked that Utype is a modular integer type.
1700 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1701 -- Freeze each component, handle some representation clauses, and freeze
1702 -- primitive operations if this is a tagged type.
1708 procedure Add_To_Result
(N
: Node_Id
) is
1711 Result
:= New_List
(N
);
1717 ----------------------------
1718 -- After_Last_Declaration --
1719 ----------------------------
1721 function After_Last_Declaration
return Boolean is
1722 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
1724 if Nkind
(Spec
) = N_Package_Specification
then
1725 if Present
(Private_Declarations
(Spec
)) then
1726 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1727 elsif Present
(Visible_Declarations
(Spec
)) then
1728 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1735 end After_Last_Declaration
;
1737 ----------------------------
1738 -- Check_Current_Instance --
1739 ----------------------------
1741 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1743 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
1744 -- Determine whether Typ is compatible with the rules for aliased
1745 -- views of types as defined in RM 3.10 in the various dialects.
1747 function Process
(N
: Node_Id
) return Traverse_Result
;
1748 -- Process routine to apply check to given node
1750 -----------------------------
1751 -- Is_Aliased_View_Of_Type --
1752 -----------------------------
1754 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
1755 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
1760 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
1761 and then Limited_Present
(Type_Definition
(Typ_Decl
))
1765 -- The following paragraphs describe what a legal aliased view of
1766 -- a type is in the various dialects of Ada.
1770 -- The current instance of a limited type, and a formal parameter
1771 -- or generic formal object of a tagged type.
1773 -- Ada 95 limited type
1774 -- * Type with reserved word "limited"
1775 -- * A protected or task type
1776 -- * A composite type with limited component
1778 elsif Ada_Version
<= Ada_95
then
1779 return Is_Limited_Type
(Typ
);
1783 -- The current instance of a limited tagged type, a protected
1784 -- type, a task type, or a type that has the reserved word
1785 -- "limited" in its full definition ... a formal parameter or
1786 -- generic formal object of a tagged type.
1788 -- Ada 2005 limited type
1789 -- * Type with reserved word "limited", "synchronized", "task"
1791 -- * A composite type with limited component
1792 -- * A derived type whose parent is a non-interface limited type
1794 elsif Ada_Version
= Ada_2005
then
1796 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
1798 (Is_Derived_Type
(Typ
)
1799 and then not Is_Interface
(Etype
(Typ
))
1800 and then Is_Limited_Type
(Etype
(Typ
)));
1802 -- Ada 2012 and beyond
1804 -- The current instance of an immutably limited type ... a formal
1805 -- parameter or generic formal object of a tagged type.
1807 -- Ada 2012 limited type
1808 -- * Type with reserved word "limited", "synchronized", "task"
1810 -- * A composite type with limited component
1811 -- * A derived type whose parent is a non-interface limited type
1812 -- * An incomplete view
1814 -- Ada 2012 immutably limited type
1815 -- * Explicitly limited record type
1816 -- * Record extension with "limited" present
1817 -- * Non-formal limited private type that is either tagged
1818 -- or has at least one access discriminant with a default
1820 -- * Task type, protected type or synchronized interface
1821 -- * Type derived from immutably limited type
1825 Is_Immutably_Limited_Type
(Typ
)
1826 or else Is_Incomplete_Type
(Typ
);
1828 end Is_Aliased_View_Of_Type
;
1834 function Process
(N
: Node_Id
) return Traverse_Result
is
1837 when N_Attribute_Reference
=>
1838 if Nam_In
(Attribute_Name
(N
), Name_Access
,
1839 Name_Unchecked_Access
)
1840 and then Is_Entity_Name
(Prefix
(N
))
1841 and then Is_Type
(Entity
(Prefix
(N
)))
1842 and then Entity
(Prefix
(N
)) = E
1845 ("current instance must be a limited type", Prefix
(N
));
1851 when others => return OK
;
1855 procedure Traverse
is new Traverse_Proc
(Process
);
1859 Rec_Type
: constant Entity_Id
:=
1860 Scope
(Defining_Identifier
(Comp_Decl
));
1862 -- Start of processing for Check_Current_Instance
1865 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
1866 Traverse
(Comp_Decl
);
1868 end Check_Current_Instance
;
1870 ------------------------------
1871 -- Check_Suspicious_Modulus --
1872 ------------------------------
1874 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
1875 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
1878 if not Warn_On_Suspicious_Modulus_Value
then
1882 if Nkind
(Decl
) = N_Full_Type_Declaration
then
1884 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
1887 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
1889 Modulus
: constant Node_Id
:=
1890 Original_Node
(Expression
(Tdef
));
1893 if Nkind
(Modulus
) = N_Integer_Literal
then
1895 Modv
: constant Uint
:= Intval
(Modulus
);
1896 Sizv
: constant Uint
:= RM_Size
(Utype
);
1899 -- First case, modulus and size are the same. This
1900 -- happens if you have something like mod 32, with
1901 -- an explicit size of 32, this is for sure a case
1902 -- where the warning is given, since it is seems
1903 -- very unlikely that someone would want e.g. a
1904 -- five bit type stored in 32 bits. It is much
1905 -- more likely they wanted a 32-bit type.
1910 -- Second case, the modulus is 32 or 64 and no
1911 -- size clause is present. This is a less clear
1912 -- case for giving the warning, but in the case
1913 -- of 32/64 (5-bit or 6-bit types) these seem rare
1914 -- enough that it is a likely error (and in any
1915 -- case using 2**5 or 2**6 in these cases seems
1916 -- clearer. We don't include 8 or 16 here, simply
1917 -- because in practice 3-bit and 4-bit types are
1918 -- more common and too many false positives if
1919 -- we warn in these cases.
1921 elsif not Has_Size_Clause
(Utype
)
1922 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
1926 -- No warning needed
1932 -- If we fall through, give warning
1934 Error_Msg_Uint_1
:= Modv
;
1936 ("?M?2 '*'*^' may have been intended here",
1944 end Check_Suspicious_Modulus
;
1946 ------------------------
1947 -- Freeze_Record_Type --
1948 ------------------------
1950 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
1957 pragma Warnings
(Off
, Junk
);
1959 Rec_Pushed
: Boolean := False;
1960 -- Set True if the record type scope Rec has been pushed on the scope
1961 -- stack. Needed for the analysis of delayed aspects specified to the
1962 -- components of Rec.
1964 Unplaced_Component
: Boolean := False;
1965 -- Set True if we find at least one component with no component
1966 -- clause (used to warn about useless Pack pragmas).
1968 Placed_Component
: Boolean := False;
1969 -- Set True if we find at least one component with a component
1970 -- clause (used to warn about useless Bit_Order pragmas, and also
1971 -- to detect cases where Implicit_Packing may have an effect).
1973 All_Scalar_Components
: Boolean := True;
1974 -- Set False if we encounter a component of a non-scalar type
1976 Scalar_Component_Total_RM_Size
: Uint
:= Uint_0
;
1977 Scalar_Component_Total_Esize
: Uint
:= Uint_0
;
1978 -- Accumulates total RM_Size values and total Esize values of all
1979 -- scalar components. Used for processing of Implicit_Packing.
1981 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
1982 -- If N is an allocator, possibly wrapped in one or more level of
1983 -- qualified expression(s), return the inner allocator node, else
1986 procedure Check_Itype
(Typ
: Entity_Id
);
1987 -- If the component subtype is an access to a constrained subtype of
1988 -- an already frozen type, make the subtype frozen as well. It might
1989 -- otherwise be frozen in the wrong scope, and a freeze node on
1990 -- subtype has no effect. Similarly, if the component subtype is a
1991 -- regular (not protected) access to subprogram, set the anonymous
1992 -- subprogram type to frozen as well, to prevent an out-of-scope
1993 -- freeze node at some eventual point of call. Protected operations
1994 -- are handled elsewhere.
1996 ---------------------
1997 -- Check_Allocator --
1998 ---------------------
2000 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
2005 if Nkind
(Inner
) = N_Allocator
then
2007 elsif Nkind
(Inner
) = N_Qualified_Expression
then
2008 Inner
:= Expression
(Inner
);
2013 end Check_Allocator
;
2019 procedure Check_Itype
(Typ
: Entity_Id
) is
2020 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
2023 if not Is_Frozen
(Desig
)
2024 and then Is_Frozen
(Base_Type
(Desig
))
2026 Set_Is_Frozen
(Desig
);
2028 -- In addition, add an Itype_Reference to ensure that the
2029 -- access subtype is elaborated early enough. This cannot be
2030 -- done if the subtype may depend on discriminants.
2032 if Ekind
(Comp
) = E_Component
2033 and then Is_Itype
(Etype
(Comp
))
2034 and then not Has_Discriminants
(Rec
)
2036 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
2037 Set_Itype
(IR
, Desig
);
2041 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
2042 and then Convention
(Desig
) /= Convention_Protected
2044 Set_Is_Frozen
(Desig
);
2048 -- Start of processing for Freeze_Record_Type
2051 -- Deal with delayed aspect specifications for components. The
2052 -- analysis of the aspect is required to be delayed to the freeze
2053 -- point, thus we analyze the pragma or attribute definition
2054 -- clause in the tree at this point. We also analyze the aspect
2055 -- specification node at the freeze point when the aspect doesn't
2056 -- correspond to pragma/attribute definition clause.
2058 Comp
:= First_Entity
(Rec
);
2059 while Present
(Comp
) loop
2060 if Ekind
(Comp
) = E_Component
2061 and then Has_Delayed_Aspects
(Comp
)
2063 if not Rec_Pushed
then
2067 -- The visibility to the discriminants must be restored in
2068 -- order to properly analyze the aspects.
2070 if Has_Discriminants
(Rec
) then
2071 Install_Discriminants
(Rec
);
2075 Analyze_Aspects_At_Freeze_Point
(Comp
);
2081 -- Pop the scope if Rec scope has been pushed on the scope stack
2082 -- during the delayed aspect analysis process.
2085 if Has_Discriminants
(Rec
) then
2086 Uninstall_Discriminants
(Rec
);
2092 -- Freeze components and embedded subtypes
2094 Comp
:= First_Entity
(Rec
);
2096 while Present
(Comp
) loop
2098 -- Handle the component and discriminant case
2100 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
2102 CC
: constant Node_Id
:= Component_Clause
(Comp
);
2105 -- Freezing a record type freezes the type of each of its
2106 -- components. However, if the type of the component is
2107 -- part of this record, we do not want or need a separate
2108 -- Freeze_Node. Note that Is_Itype is wrong because that's
2109 -- also set in private type cases. We also can't check for
2110 -- the Scope being exactly Rec because of private types and
2111 -- record extensions.
2113 if Is_Itype
(Etype
(Comp
))
2114 and then Is_Record_Type
(Underlying_Type
2115 (Scope
(Etype
(Comp
))))
2117 Undelay_Type
(Etype
(Comp
));
2120 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
2122 -- Check for error of component clause given for variable
2123 -- sized type. We have to delay this test till this point,
2124 -- since the component type has to be frozen for us to know
2125 -- if it is variable length. We omit this test in a generic
2126 -- context, it will be applied at instantiation time.
2128 -- We also omit this test in CodePeer mode, since we do not
2129 -- have sufficient info on size and representation clauses.
2131 if Present
(CC
) then
2132 Placed_Component
:= True;
2134 if Inside_A_Generic
then
2137 elsif CodePeer_Mode
then
2141 Size_Known_At_Compile_Time
2142 (Underlying_Type
(Etype
(Comp
)))
2145 ("component clause not allowed for variable " &
2146 "length component", CC
);
2150 Unplaced_Component
:= True;
2153 -- Case of component requires byte alignment
2155 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
2157 -- Set the enclosing record to also require byte align
2159 Set_Must_Be_On_Byte_Boundary
(Rec
);
2161 -- Check for component clause that is inconsistent with
2162 -- the required byte boundary alignment.
2165 and then Normalized_First_Bit
(Comp
) mod
2166 System_Storage_Unit
/= 0
2169 ("component & must be byte aligned",
2170 Component_Name
(Component_Clause
(Comp
)));
2176 -- Gather data for possible Implicit_Packing later. Note that at
2177 -- this stage we might be dealing with a real component, or with
2178 -- an implicit subtype declaration.
2180 if not Is_Scalar_Type
(Etype
(Comp
)) then
2181 All_Scalar_Components
:= False;
2183 Scalar_Component_Total_RM_Size
:=
2184 Scalar_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
2185 Scalar_Component_Total_Esize
:=
2186 Scalar_Component_Total_Esize
+ Esize
(Etype
(Comp
));
2189 -- If the component is an Itype with Delayed_Freeze and is either
2190 -- a record or array subtype and its base type has not yet been
2191 -- frozen, we must remove this from the entity list of this record
2192 -- and put it on the entity list of the scope of its base type.
2193 -- Note that we know that this is not the type of a component
2194 -- since we cleared Has_Delayed_Freeze for it in the previous
2195 -- loop. Thus this must be the Designated_Type of an access type,
2196 -- which is the type of a component.
2199 and then Is_Type
(Scope
(Comp
))
2200 and then Is_Composite_Type
(Comp
)
2201 and then Base_Type
(Comp
) /= Comp
2202 and then Has_Delayed_Freeze
(Comp
)
2203 and then not Is_Frozen
(Base_Type
(Comp
))
2206 Will_Be_Frozen
: Boolean := False;
2210 -- We have a pretty bad kludge here. Suppose Rec is subtype
2211 -- being defined in a subprogram that's created as part of
2212 -- the freezing of Rec'Base. In that case, we know that
2213 -- Comp'Base must have already been frozen by the time we
2214 -- get to elaborate this because Gigi doesn't elaborate any
2215 -- bodies until it has elaborated all of the declarative
2216 -- part. But Is_Frozen will not be set at this point because
2217 -- we are processing code in lexical order.
2219 -- We detect this case by going up the Scope chain of Rec
2220 -- and seeing if we have a subprogram scope before reaching
2221 -- the top of the scope chain or that of Comp'Base. If we
2222 -- do, then mark that Comp'Base will actually be frozen. If
2223 -- so, we merely undelay it.
2226 while Present
(S
) loop
2227 if Is_Subprogram
(S
) then
2228 Will_Be_Frozen
:= True;
2230 elsif S
= Scope
(Base_Type
(Comp
)) then
2237 if Will_Be_Frozen
then
2238 Undelay_Type
(Comp
);
2240 if Present
(Prev
) then
2241 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
2243 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
2246 -- Insert in entity list of scope of base type (which
2247 -- must be an enclosing scope, because still unfrozen).
2249 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
2253 -- If the component is an access type with an allocator as default
2254 -- value, the designated type will be frozen by the corresponding
2255 -- expression in init_proc. In order to place the freeze node for
2256 -- the designated type before that for the current record type,
2259 -- Same process if the component is an array of access types,
2260 -- initialized with an aggregate. If the designated type is
2261 -- private, it cannot contain allocators, and it is premature
2262 -- to freeze the type, so we check for this as well.
2264 elsif Is_Access_Type
(Etype
(Comp
))
2265 and then Present
(Parent
(Comp
))
2266 and then Present
(Expression
(Parent
(Comp
)))
2269 Alloc
: constant Node_Id
:=
2270 Check_Allocator
(Expression
(Parent
(Comp
)));
2273 if Present
(Alloc
) then
2275 -- If component is pointer to a classwide type, freeze
2276 -- the specific type in the expression being allocated.
2277 -- The expression may be a subtype indication, in which
2278 -- case freeze the subtype mark.
2280 if Is_Class_Wide_Type
2281 (Designated_Type
(Etype
(Comp
)))
2283 if Is_Entity_Name
(Expression
(Alloc
)) then
2285 (Entity
(Expression
(Alloc
)), N
, Result
);
2287 Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
2290 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
2294 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
2295 Check_Itype
(Etype
(Comp
));
2299 (Designated_Type
(Etype
(Comp
)), N
, Result
);
2304 elsif Is_Access_Type
(Etype
(Comp
))
2305 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
2307 Check_Itype
(Etype
(Comp
));
2309 elsif Is_Array_Type
(Etype
(Comp
))
2310 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
2311 and then Present
(Parent
(Comp
))
2312 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
2313 and then Present
(Expression
(Parent
(Comp
)))
2314 and then Nkind
(Expression
(Parent
(Comp
))) = N_Aggregate
2315 and then Is_Fully_Defined
2316 (Designated_Type
(Component_Type
(Etype
(Comp
))))
2320 (Component_Type
(Etype
(Comp
))), N
, Result
);
2327 ADC
:= Get_Attribute_Definition_Clause
2328 (Rec
, Attribute_Scalar_Storage_Order
);
2330 if Present
(ADC
) then
2332 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
2333 -- the former is specified.
2335 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
2337 -- Note: report error on Rec, not on ADC, as ADC may apply to
2338 -- an ancestor type.
2340 Error_Msg_Sloc
:= Sloc
(ADC
);
2342 ("scalar storage order for& specified# inconsistent with "
2343 & "bit order", Rec
);
2346 -- Warn if there is a Scalar_Storage_Order but no component clause
2347 -- (or pragma Pack).
2349 if not (Placed_Component
or else Is_Packed
(Rec
)) then
2351 ("??scalar storage order specified but no component clause",
2355 -- Check attribute on component types
2357 Comp
:= First_Component
(Rec
);
2358 while Present
(Comp
) loop
2359 Check_Component_Storage_Order
(Rec
, Comp
);
2360 Next_Component
(Comp
);
2364 -- Deal with Bit_Order aspect specifying a non-default bit order
2366 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
2368 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
2369 if not (Placed_Component
or else Is_Packed
(Rec
)) then
2370 Error_Msg_N
("??bit order specification has no effect", ADC
);
2372 ("\??since no component clauses were specified", ADC
);
2374 -- Here is where we do the processing for reversed bit order
2376 elsif Reverse_Bit_Order
(Rec
)
2377 and then not Reverse_Storage_Order
(Rec
)
2379 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
2381 -- Case where we have both an explicit Bit_Order and the same
2382 -- Scalar_Storage_Order: leave record untouched, the back-end
2383 -- will take care of required layout conversions.
2391 -- Complete error checking on record representation clause (e.g.
2392 -- overlap of components). This is called after adjusting the
2393 -- record for reverse bit order.
2396 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
2398 if Present
(RRC
) then
2399 Check_Record_Representation_Clause
(RRC
);
2403 -- Set OK_To_Reorder_Components depending on debug flags
2405 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
2406 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
2408 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
2410 Set_OK_To_Reorder_Components
(Rec
);
2414 -- Check for useless pragma Pack when all components placed. We only
2415 -- do this check for record types, not subtypes, since a subtype may
2416 -- have all its components placed, and it still makes perfectly good
2417 -- sense to pack other subtypes or the parent type. We do not give
2418 -- this warning if Optimize_Alignment is set to Space, since the
2419 -- pragma Pack does have an effect in this case (it always resets
2420 -- the alignment to one).
2422 if Ekind
(Rec
) = E_Record_Type
2423 and then Is_Packed
(Rec
)
2424 and then not Unplaced_Component
2425 and then Optimize_Alignment
/= 'S'
2427 -- Reset packed status. Probably not necessary, but we do it so
2428 -- that there is no chance of the back end doing something strange
2429 -- with this redundant indication of packing.
2431 Set_Is_Packed
(Rec
, False);
2433 -- Give warning if redundant constructs warnings on
2435 if Warn_On_Redundant_Constructs
then
2436 Error_Msg_N
-- CODEFIX
2437 ("??pragma Pack has no effect, no unplaced components",
2438 Get_Rep_Pragma
(Rec
, Name_Pack
));
2442 -- If this is the record corresponding to a remote type, freeze the
2443 -- remote type here since that is what we are semantically freezing.
2444 -- This prevents the freeze node for that type in an inner scope.
2446 -- Also, Check for controlled components and unchecked unions.
2447 -- Finally, enforce the restriction that access attributes with a
2448 -- current instance prefix can only apply to limited types.
2450 if Ekind
(Rec
) = E_Record_Type
then
2451 if Present
(Corresponding_Remote_Type
(Rec
)) then
2452 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
2455 Comp
:= First_Component
(Rec
);
2456 while Present
(Comp
) loop
2458 -- Do not set Has_Controlled_Component on a class-wide
2459 -- equivalent type. See Make_CW_Equivalent_Type.
2461 if not Is_Class_Wide_Equivalent_Type
(Rec
)
2462 and then (Has_Controlled_Component
(Etype
(Comp
))
2463 or else (Chars
(Comp
) /= Name_uParent
2464 and then Is_Controlled
(Etype
(Comp
)))
2465 or else (Is_Protected_Type
(Etype
(Comp
))
2467 (Corresponding_Record_Type
2469 and then Has_Controlled_Component
2470 (Corresponding_Record_Type
2473 Set_Has_Controlled_Component
(Rec
);
2476 if Has_Unchecked_Union
(Etype
(Comp
)) then
2477 Set_Has_Unchecked_Union
(Rec
);
2480 -- Scan component declaration for likely misuses of current
2481 -- instance, either in a constraint or a default expression.
2483 if Has_Per_Object_Constraint
(Comp
) then
2484 Check_Current_Instance
(Parent
(Comp
));
2487 Next_Component
(Comp
);
2491 Set_Component_Alignment_If_Not_Set
(Rec
);
2493 -- For first subtypes, check if there are any fixed-point fields with
2494 -- component clauses, where we must check the size. This is not done
2495 -- till the freeze point, since for fixed-point types, we do not know
2496 -- the size until the type is frozen. Similar processing applies to
2497 -- bit packed arrays.
2499 if Is_First_Subtype
(Rec
) then
2500 Comp
:= First_Component
(Rec
);
2501 while Present
(Comp
) loop
2502 if Present
(Component_Clause
(Comp
))
2503 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
2505 Is_Bit_Packed_Array
(Etype
(Comp
)))
2508 (Component_Name
(Component_Clause
(Comp
)),
2514 Next_Component
(Comp
);
2518 -- Generate warning for applying C or C++ convention to a record
2519 -- with discriminants. This is suppressed for the unchecked union
2520 -- case, since the whole point in this case is interface C. We also
2521 -- do not generate this within instantiations, since we will have
2522 -- generated a message on the template.
2524 if Has_Discriminants
(E
)
2525 and then not Is_Unchecked_Union
(E
)
2526 and then (Convention
(E
) = Convention_C
2528 Convention
(E
) = Convention_CPP
)
2529 and then Comes_From_Source
(E
)
2530 and then not In_Instance
2531 and then not Has_Warnings_Off
(E
)
2532 and then not Has_Warnings_Off
(Base_Type
(E
))
2535 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
2539 if Present
(Cprag
) then
2540 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
2542 if Convention
(E
) = Convention_C
then
2544 ("?x?variant record has no direct equivalent in C",
2548 ("?x?variant record has no direct equivalent in C++",
2553 ("\?x?use of convention for type& is dubious", A2
, E
);
2558 -- See if Size is too small as is (and implicit packing might help)
2560 if not Is_Packed
(Rec
)
2562 -- No implicit packing if even one component is explicitly placed
2564 and then not Placed_Component
2566 -- Must have size clause and all scalar components
2568 and then Has_Size_Clause
(Rec
)
2569 and then All_Scalar_Components
2571 -- Do not try implicit packing on records with discriminants, too
2572 -- complicated, especially in the variant record case.
2574 and then not Has_Discriminants
(Rec
)
2576 -- We can implicitly pack if the specified size of the record is
2577 -- less than the sum of the object sizes (no point in packing if
2578 -- this is not the case).
2580 and then RM_Size
(Rec
) < Scalar_Component_Total_Esize
2582 -- And the total RM size cannot be greater than the specified size
2583 -- since otherwise packing will not get us where we have to be!
2585 and then RM_Size
(Rec
) >= Scalar_Component_Total_RM_Size
2587 -- Never do implicit packing in CodePeer or SPARK modes since
2588 -- we don't do any packing in these modes, since this generates
2589 -- over-complex code that confuses static analysis, and in
2590 -- general, neither CodePeer not GNATprove care about the
2591 -- internal representation of objects.
2593 and then not (CodePeer_Mode
or SPARK_Mode
)
2595 -- If implicit packing enabled, do it
2597 if Implicit_Packing
then
2598 Set_Is_Packed
(Rec
);
2600 -- Otherwise flag the size clause
2604 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
2606 Error_Msg_NE
-- CODEFIX
2607 ("size given for& too small", Sz
, Rec
);
2608 Error_Msg_N
-- CODEFIX
2609 ("\use explicit pragma Pack "
2610 & "or use pragma Implicit_Packing", Sz
);
2614 end Freeze_Record_Type
;
2616 -- Start of processing for Freeze_Entity
2619 -- We are going to test for various reasons why this entity need not be
2620 -- frozen here, but in the case of an Itype that's defined within a
2621 -- record, that test actually applies to the record.
2623 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
2624 Test_E
:= Scope
(E
);
2625 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
2626 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
2628 Test_E
:= Underlying_Type
(Scope
(E
));
2631 -- Do not freeze if already frozen since we only need one freeze node
2633 if Is_Frozen
(E
) then
2636 -- It is improper to freeze an external entity within a generic because
2637 -- its freeze node will appear in a non-valid context. The entity will
2638 -- be frozen in the proper scope after the current generic is analyzed.
2639 -- However, aspects must be analyzed because they may be queried later
2640 -- within the generic itself, and the corresponding pragma or attribute
2641 -- definition has not been analyzed yet.
2643 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
2644 if Has_Delayed_Aspects
(E
) then
2645 Analyze_Aspects_At_Freeze_Point
(E
);
2650 -- AI05-0213: A formal incomplete type does not freeze the actual. In
2651 -- the instance, the same applies to the subtype renaming the actual.
2653 elsif Is_Private_Type
(E
)
2654 and then Is_Generic_Actual_Type
(E
)
2655 and then No
(Full_View
(Base_Type
(E
)))
2656 and then Ada_Version
>= Ada_2012
2660 -- Do not freeze a global entity within an inner scope created during
2661 -- expansion. A call to subprogram E within some internal procedure
2662 -- (a stream attribute for example) might require freezing E, but the
2663 -- freeze node must appear in the same declarative part as E itself.
2664 -- The two-pass elaboration mechanism in gigi guarantees that E will
2665 -- be frozen before the inner call is elaborated. We exclude constants
2666 -- from this test, because deferred constants may be frozen early, and
2667 -- must be diagnosed (e.g. in the case of a deferred constant being used
2668 -- in a default expression). If the enclosing subprogram comes from
2669 -- source, or is a generic instance, then the freeze point is the one
2670 -- mandated by the language, and we freeze the entity. A subprogram that
2671 -- is a child unit body that acts as a spec does not have a spec that
2672 -- comes from source, but can only come from source.
2674 elsif In_Open_Scopes
(Scope
(Test_E
))
2675 and then Scope
(Test_E
) /= Current_Scope
2676 and then Ekind
(Test_E
) /= E_Constant
2683 while Present
(S
) loop
2684 if Is_Overloadable
(S
) then
2685 if Comes_From_Source
(S
)
2686 or else Is_Generic_Instance
(S
)
2687 or else Is_Child_Unit
(S
)
2699 -- Similarly, an inlined instance body may make reference to global
2700 -- entities, but these references cannot be the proper freezing point
2701 -- for them, and in the absence of inlining freezing will take place in
2702 -- their own scope. Normally instance bodies are analyzed after the
2703 -- enclosing compilation, and everything has been frozen at the proper
2704 -- place, but with front-end inlining an instance body is compiled
2705 -- before the end of the enclosing scope, and as a result out-of-order
2706 -- freezing must be prevented.
2708 elsif Front_End_Inlining
2709 and then In_Instance_Body
2710 and then Present
(Scope
(Test_E
))
2716 S
:= Scope
(Test_E
);
2717 while Present
(S
) loop
2718 if Is_Generic_Instance
(S
) then
2731 -- Add checks to detect proper initialization of scalars that may appear
2732 -- as subprogram parameters.
2734 if Is_Subprogram
(E
)
2735 and then Check_Validity_Of_Parameters
2737 Apply_Parameter_Validity_Checks
(E
);
2740 -- Deal with delayed aspect specifications. The analysis of the aspect
2741 -- is required to be delayed to the freeze point, thus we analyze the
2742 -- pragma or attribute definition clause in the tree at this point. We
2743 -- also analyze the aspect specification node at the freeze point when
2744 -- the aspect doesn't correspond to pragma/attribute definition clause.
2746 if Has_Delayed_Aspects
(E
) then
2747 Analyze_Aspects_At_Freeze_Point
(E
);
2750 -- Here to freeze the entity
2754 -- Case of entity being frozen is other than a type
2756 if not Is_Type
(E
) then
2758 -- If entity is exported or imported and does not have an external
2759 -- name, now is the time to provide the appropriate default name.
2760 -- Skip this if the entity is stubbed, since we don't need a name
2761 -- for any stubbed routine. For the case on intrinsics, if no
2762 -- external name is specified, then calls will be handled in
2763 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
2764 -- external name is provided, then Expand_Intrinsic_Call leaves
2765 -- calls in place for expansion by GIGI.
2767 if (Is_Imported
(E
) or else Is_Exported
(E
))
2768 and then No
(Interface_Name
(E
))
2769 and then Convention
(E
) /= Convention_Stubbed
2770 and then Convention
(E
) /= Convention_Intrinsic
2772 Set_Encoded_Interface_Name
2773 (E
, Get_Default_External_Name
(E
));
2775 -- If entity is an atomic object appearing in a declaration and
2776 -- the expression is an aggregate, assign it to a temporary to
2777 -- ensure that the actual assignment is done atomically rather
2778 -- than component-wise (the assignment to the temp may be done
2779 -- component-wise, but that is harmless).
2782 and then Nkind
(Parent
(E
)) = N_Object_Declaration
2783 and then Present
(Expression
(Parent
(E
)))
2784 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
2785 and then Is_Atomic_Aggregate
(Expression
(Parent
(E
)), Etype
(E
))
2790 -- For a subprogram, freeze all parameter types and also the return
2791 -- type (RM 13.14(14)). However skip this for internal subprograms.
2792 -- This is also the point where any extra formal parameters are
2793 -- created since we now know whether the subprogram will use a
2794 -- foreign convention.
2796 if Is_Subprogram
(E
) then
2797 if not Is_Internal
(E
) then
2801 Warn_Node
: Node_Id
;
2804 -- Loop through formals
2806 Formal
:= First_Formal
(E
);
2807 while Present
(Formal
) loop
2808 F_Type
:= Etype
(Formal
);
2810 -- AI05-0151 : incomplete types can appear in a profile.
2811 -- By the time the entity is frozen, the full view must
2812 -- be available, unless it is a limited view.
2814 if Is_Incomplete_Type
(F_Type
)
2815 and then Present
(Full_View
(F_Type
))
2817 F_Type
:= Full_View
(F_Type
);
2818 Set_Etype
(Formal
, F_Type
);
2821 Freeze_And_Append
(F_Type
, N
, Result
);
2823 if Is_Private_Type
(F_Type
)
2824 and then Is_Private_Type
(Base_Type
(F_Type
))
2825 and then No
(Full_View
(Base_Type
(F_Type
)))
2826 and then not Is_Generic_Type
(F_Type
)
2827 and then not Is_Derived_Type
(F_Type
)
2829 -- If the type of a formal is incomplete, subprogram
2830 -- is being frozen prematurely. Within an instance
2831 -- (but not within a wrapper package) this is an
2832 -- artifact of our need to regard the end of an
2833 -- instantiation as a freeze point. Otherwise it is
2834 -- a definite error.
2837 Set_Is_Frozen
(E
, False);
2840 elsif not After_Last_Declaration
2841 and then not Freezing_Library_Level_Tagged_Type
2843 Error_Msg_Node_1
:= F_Type
;
2845 ("type& must be fully defined before this point",
2850 -- Check suspicious parameter for C function. These tests
2851 -- apply only to exported/imported subprograms.
2853 if Warn_On_Export_Import
2854 and then Comes_From_Source
(E
)
2855 and then (Convention
(E
) = Convention_C
2857 Convention
(E
) = Convention_CPP
)
2858 and then (Is_Imported
(E
) or else Is_Exported
(E
))
2859 and then Convention
(E
) /= Convention
(Formal
)
2860 and then not Has_Warnings_Off
(E
)
2861 and then not Has_Warnings_Off
(F_Type
)
2862 and then not Has_Warnings_Off
(Formal
)
2864 -- Qualify mention of formals with subprogram name
2866 Error_Msg_Qual_Level
:= 1;
2868 -- Check suspicious use of fat C pointer
2870 if Is_Access_Type
(F_Type
)
2871 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
2874 ("?x?type of & does not correspond to C pointer!",
2877 -- Check suspicious return of boolean
2879 elsif Root_Type
(F_Type
) = Standard_Boolean
2880 and then Convention
(F_Type
) = Convention_Ada
2881 and then not Has_Warnings_Off
(F_Type
)
2882 and then not Has_Size_Clause
(F_Type
)
2883 and then VM_Target
= No_VM
2886 ("& is an 8-bit Ada Boolean?x?", Formal
);
2888 ("\use appropriate corresponding type in C "
2889 & "(e.g. char)?x?", Formal
);
2891 -- Check suspicious tagged type
2893 elsif (Is_Tagged_Type
(F_Type
)
2894 or else (Is_Access_Type
(F_Type
)
2897 (Designated_Type
(F_Type
))))
2898 and then Convention
(E
) = Convention_C
2901 ("?x?& involves a tagged type which does not "
2902 & "correspond to any C type!", Formal
);
2904 -- Check wrong convention subprogram pointer
2906 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
2907 and then not Has_Foreign_Convention
(F_Type
)
2910 ("?x?subprogram pointer & should "
2911 & "have foreign convention!", Formal
);
2912 Error_Msg_Sloc
:= Sloc
(F_Type
);
2914 ("\?x?add Convention pragma to declaration of &#",
2918 -- Turn off name qualification after message output
2920 Error_Msg_Qual_Level
:= 0;
2923 -- Check for unconstrained array in exported foreign
2926 if Has_Foreign_Convention
(E
)
2927 and then not Is_Imported
(E
)
2928 and then Is_Array_Type
(F_Type
)
2929 and then not Is_Constrained
(F_Type
)
2930 and then Warn_On_Export_Import
2932 -- Exclude VM case, since both .NET and JVM can handle
2933 -- unconstrained arrays without a problem.
2935 and then VM_Target
= No_VM
2937 Error_Msg_Qual_Level
:= 1;
2939 -- If this is an inherited operation, place the
2940 -- warning on the derived type declaration, rather
2941 -- than on the original subprogram.
2943 if Nkind
(Original_Node
(Parent
(E
))) =
2944 N_Full_Type_Declaration
2946 Warn_Node
:= Parent
(E
);
2948 if Formal
= First_Formal
(E
) then
2950 ("??in inherited operation&", Warn_Node
, E
);
2953 Warn_Node
:= Formal
;
2957 ("?x?type of argument& is unconstrained array",
2960 ("?x?foreign caller must pass bounds explicitly",
2962 Error_Msg_Qual_Level
:= 0;
2965 if not From_With_Type
(F_Type
) then
2966 if Is_Access_Type
(F_Type
) then
2967 F_Type
:= Designated_Type
(F_Type
);
2970 -- If the formal is an anonymous_access_to_subprogram
2971 -- freeze the subprogram type as well, to prevent
2972 -- scope anomalies in gigi, because there is no other
2973 -- clear point at which it could be frozen.
2975 if Is_Itype
(Etype
(Formal
))
2976 and then Ekind
(F_Type
) = E_Subprogram_Type
2978 Freeze_And_Append
(F_Type
, N
, Result
);
2982 Next_Formal
(Formal
);
2985 -- Case of function: similar checks on return type
2987 if Ekind
(E
) = E_Function
then
2989 -- Freeze return type
2991 R_Type
:= Etype
(E
);
2993 -- AI05-0151: the return type may have been incomplete
2994 -- at the point of declaration.
2996 if Ekind
(R_Type
) = E_Incomplete_Type
2997 and then Present
(Full_View
(R_Type
))
2999 R_Type
:= Full_View
(R_Type
);
3000 Set_Etype
(E
, R_Type
);
3003 Freeze_And_Append
(R_Type
, N
, Result
);
3005 -- Check suspicious return type for C function
3007 if Warn_On_Export_Import
3008 and then (Convention
(E
) = Convention_C
3010 Convention
(E
) = Convention_CPP
)
3011 and then (Is_Imported
(E
) or else Is_Exported
(E
))
3013 -- Check suspicious return of fat C pointer
3015 if Is_Access_Type
(R_Type
)
3016 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
3017 and then not Has_Warnings_Off
(E
)
3018 and then not Has_Warnings_Off
(R_Type
)
3021 ("?x?return type of& does not "
3022 & "correspond to C pointer!", E
);
3024 -- Check suspicious return of boolean
3026 elsif Root_Type
(R_Type
) = Standard_Boolean
3027 and then Convention
(R_Type
) = Convention_Ada
3028 and then VM_Target
= No_VM
3029 and then not Has_Warnings_Off
(E
)
3030 and then not Has_Warnings_Off
(R_Type
)
3031 and then not Has_Size_Clause
(R_Type
)
3034 N
: constant Node_Id
:=
3035 Result_Definition
(Declaration_Node
(E
));
3038 ("return type of & is an 8-bit Ada Boolean?x?",
3041 ("\use appropriate corresponding type in C "
3042 & "(e.g. char)?x?", N
, E
);
3045 -- Check suspicious return tagged type
3047 elsif (Is_Tagged_Type
(R_Type
)
3048 or else (Is_Access_Type
(R_Type
)
3051 (Designated_Type
(R_Type
))))
3052 and then Convention
(E
) = Convention_C
3053 and then not Has_Warnings_Off
(E
)
3054 and then not Has_Warnings_Off
(R_Type
)
3057 ("?x?return type of & does not "
3058 & "correspond to C type!", E
);
3060 -- Check return of wrong convention subprogram pointer
3062 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3063 and then not Has_Foreign_Convention
(R_Type
)
3064 and then not Has_Warnings_Off
(E
)
3065 and then not Has_Warnings_Off
(R_Type
)
3068 ("?x?& should return a foreign "
3069 & "convention subprogram pointer", E
);
3070 Error_Msg_Sloc
:= Sloc
(R_Type
);
3072 ("\?x?add Convention pragma to declaration of& #",
3077 -- Give warning for suspicious return of a result of an
3078 -- unconstrained array type in a foreign convention
3081 if Has_Foreign_Convention
(E
)
3083 -- We are looking for a return of unconstrained array
3085 and then Is_Array_Type
(R_Type
)
3086 and then not Is_Constrained
(R_Type
)
3088 -- Exclude imported routines, the warning does not
3089 -- belong on the import, but rather on the routine
3092 and then not Is_Imported
(E
)
3094 -- Exclude VM case, since both .NET and JVM can handle
3095 -- return of unconstrained arrays without a problem.
3097 and then VM_Target
= No_VM
3099 -- Check that general warning is enabled, and that it
3100 -- is not suppressed for this particular case.
3102 and then Warn_On_Export_Import
3103 and then not Has_Warnings_Off
(E
)
3104 and then not Has_Warnings_Off
(R_Type
)
3107 ("?x?foreign convention function& should not " &
3108 "return unconstrained array!", E
);
3113 -- Pre/post conditions are implemented through a subprogram in
3114 -- the corresponding body, and therefore are not checked on an
3115 -- imported subprogram for which the body is not available.
3117 -- Could consider generating a wrapper to take care of this???
3119 if Is_Subprogram
(E
)
3120 and then Is_Imported
(E
)
3121 and then Present
(Contract
(E
))
3122 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
3125 ("pre/post conditions on imported subprogram are not "
3126 & "enforced??", E
, Pre_Post_Conditions
(Contract
(E
)));
3131 -- Must freeze its parent first if it is a derived subprogram
3133 if Present
(Alias
(E
)) then
3134 Freeze_And_Append
(Alias
(E
), N
, Result
);
3137 -- We don't freeze internal subprograms, because we don't normally
3138 -- want addition of extra formals or mechanism setting to happen
3139 -- for those. However we do pass through predefined dispatching
3140 -- cases, since extra formals may be needed in some cases, such as
3141 -- for the stream 'Input function (build-in-place formals).
3143 if not Is_Internal
(E
)
3144 or else Is_Predefined_Dispatching_Operation
(E
)
3146 Freeze_Subprogram
(E
);
3149 -- Here for other than a subprogram or type
3152 -- If entity has a type, and it is not a generic unit, then
3153 -- freeze it first (RM 13.14(10)).
3155 if Present
(Etype
(E
))
3156 and then Ekind
(E
) /= E_Generic_Function
3158 Freeze_And_Append
(Etype
(E
), N
, Result
);
3161 -- Special processing for objects created by object declaration
3163 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
3165 -- Abstract type allowed only for C++ imported variables or
3168 -- Note: we inhibit this check for objects that do not come
3169 -- from source because there is at least one case (the
3170 -- expansion of x'Class'Input where x is abstract) where we
3171 -- legitimately generate an abstract object.
3173 if Is_Abstract_Type
(Etype
(E
))
3174 and then Comes_From_Source
(Parent
(E
))
3175 and then not (Is_Imported
(E
)
3176 and then Is_CPP_Class
(Etype
(E
)))
3178 Error_Msg_N
("type of object cannot be abstract",
3179 Object_Definition
(Parent
(E
)));
3181 if Is_CPP_Class
(Etype
(E
)) then
3183 ("\} may need a cpp_constructor",
3184 Object_Definition
(Parent
(E
)), Etype
(E
));
3188 -- For object created by object declaration, perform required
3189 -- categorization (preelaborate and pure) checks. Defer these
3190 -- checks to freeze time since pragma Import inhibits default
3191 -- initialization and thus pragma Import affects these checks.
3193 Validate_Object_Declaration
(Declaration_Node
(E
));
3195 -- If there is an address clause, check that it is valid
3197 Check_Address_Clause
(E
);
3199 -- If the object needs any kind of default initialization, an
3200 -- error must be issued if No_Default_Initialization applies.
3201 -- The check doesn't apply to imported objects, which are not
3202 -- ever default initialized, and is why the check is deferred
3203 -- until freezing, at which point we know if Import applies.
3204 -- Deferred constants are also exempted from this test because
3205 -- their completion is explicit, or through an import pragma.
3207 if Ekind
(E
) = E_Constant
3208 and then Present
(Full_View
(E
))
3212 elsif Comes_From_Source
(E
)
3213 and then not Is_Imported
(E
)
3214 and then not Has_Init_Expression
(Declaration_Node
(E
))
3216 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
3217 and then not No_Initialization
(Declaration_Node
(E
))
3218 and then not Is_Value_Type
(Etype
(E
))
3219 and then not Initialization_Suppressed
(Etype
(E
)))
3221 (Needs_Simple_Initialization
(Etype
(E
))
3222 and then not Is_Internal
(E
)))
3224 Has_Default_Initialization
:= True;
3226 (No_Default_Initialization
, Declaration_Node
(E
));
3229 -- Check that a Thread_Local_Storage variable does not have
3230 -- default initialization, and any explicit initialization must
3231 -- either be the null constant or a static constant.
3233 if Has_Pragma_Thread_Local_Storage
(E
) then
3235 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3237 if Has_Default_Initialization
3239 (Has_Init_Expression
(Decl
)
3241 (No
(Expression
(Decl
))
3243 (Is_Static_Expression
(Expression
(Decl
))
3245 Nkind
(Expression
(Decl
)) = N_Null
)))
3248 ("Thread_Local_Storage variable& is "
3249 & "improperly initialized", Decl
, E
);
3251 ("\only allowed initialization is explicit "
3252 & "NULL or static expression", Decl
, E
);
3257 -- For imported objects, set Is_Public unless there is also an
3258 -- address clause, which means that there is no external symbol
3259 -- needed for the Import (Is_Public may still be set for other
3260 -- unrelated reasons). Note that we delayed this processing
3261 -- till freeze time so that we can be sure not to set the flag
3262 -- if there is an address clause. If there is such a clause,
3263 -- then the only purpose of the Import pragma is to suppress
3264 -- implicit initialization.
3267 and then No
(Address_Clause
(E
))
3272 -- For convention C objects of an enumeration type, warn if
3273 -- the size is not integer size and no explicit size given.
3274 -- Skip warning for Boolean, and Character, assume programmer
3275 -- expects 8-bit sizes for these cases.
3277 if (Convention
(E
) = Convention_C
3279 Convention
(E
) = Convention_CPP
)
3280 and then Is_Enumeration_Type
(Etype
(E
))
3281 and then not Is_Character_Type
(Etype
(E
))
3282 and then not Is_Boolean_Type
(Etype
(E
))
3283 and then Esize
(Etype
(E
)) < Standard_Integer_Size
3284 and then not Has_Size_Clause
(E
)
3286 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
3288 ("??convention C enumeration object has size less than ^",
3290 Error_Msg_N
("\?use explicit size clause to set size", E
);
3294 -- Check that a constant which has a pragma Volatile[_Components]
3295 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
3297 -- Note: Atomic[_Components] also sets Volatile[_Components]
3299 if Ekind
(E
) = E_Constant
3300 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
3301 and then not Is_Imported
(E
)
3303 -- Make sure we actually have a pragma, and have not merely
3304 -- inherited the indication from elsewhere (e.g. an address
3305 -- clause, which is not good enough in RM terms!)
3307 if Has_Rep_Pragma
(E
, Name_Atomic
)
3309 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
3312 ("stand alone atomic constant must be " &
3313 "imported (RM C.6(13))", E
);
3315 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
3317 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
3320 ("stand alone volatile constant must be " &
3321 "imported (RM C.6(13))", E
);
3325 -- Static objects require special handling
3327 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
3328 and then Is_Statically_Allocated
(E
)
3330 Freeze_Static_Object
(E
);
3333 -- Remaining step is to layout objects
3335 if Ekind
(E
) = E_Variable
3337 Ekind
(E
) = E_Constant
3339 Ekind
(E
) = E_Loop_Parameter
3346 -- If initialization statements were captured in an expression
3347 -- with actions with null expression, and the object does not
3348 -- have delayed freezing, move them back now directly within the
3349 -- enclosing statement sequence.
3351 if Ekind_In
(E
, E_Constant
, E_Variable
)
3352 and then not Has_Delayed_Freeze
(E
)
3355 Init_Stmts
: constant Node_Id
:=
3356 Initialization_Statements
(E
);
3358 if Present
(Init_Stmts
)
3359 and then Nkind
(Init_Stmts
) = N_Expression_With_Actions
3360 and then Nkind
(Expression
(Init_Stmts
)) = N_Null_Statement
3362 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
3364 -- Note that we rewrite Init_Stmts into a NULL statement,
3365 -- rather than just removing it, because Freeze_All may
3366 -- depend on this particular Node_Id still being present
3367 -- in the enclosing list to signal where to stop
3370 Rewrite
(Init_Stmts
,
3371 Make_Null_Statement
(Sloc
(Init_Stmts
)));
3373 Set_Initialization_Statements
(E
, Empty
);
3380 -- Case of a type or subtype being frozen
3383 -- We used to check here that a full type must have preelaborable
3384 -- initialization if it completes a private type specified with
3385 -- pragma Preelaborable_Initialization, but that missed cases where
3386 -- the types occur within a generic package, since the freezing
3387 -- that occurs within a containing scope generally skips traversal
3388 -- of a generic unit's declarations (those will be frozen within
3389 -- instances). This check was moved to Analyze_Package_Specification.
3391 -- The type may be defined in a generic unit. This can occur when
3392 -- freezing a generic function that returns the type (which is
3393 -- defined in a parent unit). It is clearly meaningless to freeze
3394 -- this type. However, if it is a subtype, its size may be determi-
3395 -- nable and used in subsequent checks, so might as well try to
3398 -- In Ada 2012, Freeze_Entities is also used in the front end to
3399 -- trigger the analysis of aspect expressions, so in this case we
3400 -- want to continue the freezing process.
3402 if Present
(Scope
(E
))
3403 and then Is_Generic_Unit
(Scope
(E
))
3404 and then not Has_Predicates
(E
)
3406 Check_Compile_Time_Size
(E
);
3410 -- Deal with special cases of freezing for subtype
3412 if E
/= Base_Type
(E
) then
3414 -- Before we do anything else, a specialized test for the case of
3415 -- a size given for an array where the array needs to be packed,
3416 -- but was not so the size cannot be honored. This is the case
3417 -- where implicit packing may apply. The reason we do this so
3418 -- early is that if we have implicit packing, the layout of the
3419 -- base type is affected, so we must do this before we freeze
3422 -- We could do this processing only if implicit packing is enabled
3423 -- since in all other cases, the error would be caught by the back
3424 -- end. However, we choose to do the check even if we do not have
3425 -- implicit packing enabled, since this allows us to give a more
3426 -- useful error message (advising use of pragmas Implicit_Packing
3429 if Is_Array_Type
(E
) then
3431 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
3432 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
3433 SZ
: constant Node_Id
:= Size_Clause
(E
);
3434 Btyp
: constant Entity_Id
:= Base_Type
(E
);
3441 -- Number of elements in array
3444 -- Check enabling conditions. These are straightforward
3445 -- except for the test for a limited composite type. This
3446 -- eliminates the rare case of a array of limited components
3447 -- where there are issues of whether or not we can go ahead
3448 -- and pack the array (since we can't freely pack and unpack
3449 -- arrays if they are limited).
3451 -- Note that we check the root type explicitly because the
3452 -- whole point is we are doing this test before we have had
3453 -- a chance to freeze the base type (and it is that freeze
3454 -- action that causes stuff to be inherited).
3456 if Has_Size_Clause
(E
)
3457 and then Known_Static_RM_Size
(E
)
3458 and then not Is_Packed
(E
)
3459 and then not Has_Pragma_Pack
(E
)
3460 and then not Has_Component_Size_Clause
(E
)
3461 and then Known_Static_RM_Size
(Ctyp
)
3462 and then RM_Size
(Ctyp
) < 64
3463 and then not Is_Limited_Composite
(E
)
3464 and then not Is_Packed
(Root_Type
(E
))
3465 and then not Has_Component_Size_Clause
(Root_Type
(E
))
3466 and then not (CodePeer_Mode
or SPARK_Mode
)
3468 -- Compute number of elements in array
3470 Num_Elmts
:= Uint_1
;
3471 Indx
:= First_Index
(E
);
3472 while Present
(Indx
) loop
3473 Get_Index_Bounds
(Indx
, Lo
, Hi
);
3475 if not (Compile_Time_Known_Value
(Lo
)
3477 Compile_Time_Known_Value
(Hi
))
3479 goto No_Implicit_Packing
;
3485 Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1);
3489 -- What we are looking for here is the situation where
3490 -- the RM_Size given would be exactly right if there was
3491 -- a pragma Pack (resulting in the component size being
3492 -- the same as the RM_Size). Furthermore, the component
3493 -- type size must be an odd size (not a multiple of
3494 -- storage unit). If the component RM size is an exact
3495 -- number of storage units that is a power of two, the
3496 -- array is not packed and has a standard representation.
3498 if RM_Size
(E
) = Num_Elmts
* Rsiz
3499 and then Rsiz
mod System_Storage_Unit
/= 0
3501 -- For implicit packing mode, just set the component
3504 if Implicit_Packing
then
3505 Set_Component_Size
(Btyp
, Rsiz
);
3506 Set_Is_Bit_Packed_Array
(Btyp
);
3507 Set_Is_Packed
(Btyp
);
3508 Set_Has_Non_Standard_Rep
(Btyp
);
3510 -- Otherwise give an error message
3514 ("size given for& too small", SZ
, E
);
3515 Error_Msg_N
-- CODEFIX
3516 ("\use explicit pragma Pack "
3517 & "or use pragma Implicit_Packing", SZ
);
3520 elsif RM_Size
(E
) = Num_Elmts
* Rsiz
3521 and then Implicit_Packing
3523 (Rsiz
/ System_Storage_Unit
= 1
3525 Rsiz
/ System_Storage_Unit
= 2
3527 Rsiz
/ System_Storage_Unit
= 4)
3529 -- Not a packed array, but indicate the desired
3530 -- component size, for the back-end.
3532 Set_Component_Size
(Btyp
, Rsiz
);
3538 <<No_Implicit_Packing
>>
3540 -- If ancestor subtype present, freeze that first. Note that this
3541 -- will also get the base type frozen. Need RM reference ???
3543 Atype
:= Ancestor_Subtype
(E
);
3545 if Present
(Atype
) then
3546 Freeze_And_Append
(Atype
, N
, Result
);
3548 -- No ancestor subtype present
3551 -- See if we have a nearest ancestor that has a predicate.
3552 -- That catches the case of derived type with a predicate.
3553 -- Need RM reference here ???
3555 Atype
:= Nearest_Ancestor
(E
);
3557 if Present
(Atype
) and then Has_Predicates
(Atype
) then
3558 Freeze_And_Append
(Atype
, N
, Result
);
3561 -- Freeze base type before freezing the entity (RM 13.14(15))
3563 if E
/= Base_Type
(E
) then
3564 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
3568 -- A subtype inherits all the type-related representation aspects
3569 -- from its parents (RM 13.1(8)).
3571 Inherit_Aspects_At_Freeze_Point
(E
);
3573 -- For a derived type, freeze its parent type first (RM 13.14(15))
3575 elsif Is_Derived_Type
(E
) then
3576 Freeze_And_Append
(Etype
(E
), N
, Result
);
3577 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
3579 -- A derived type inherits each type-related representation aspect
3580 -- of its parent type that was directly specified before the
3581 -- declaration of the derived type (RM 13.1(15)).
3583 Inherit_Aspects_At_Freeze_Point
(E
);
3586 -- For array type, freeze index types and component type first
3587 -- before freezing the array (RM 13.14(15)).
3589 if Is_Array_Type
(E
) then
3591 FS
: constant Entity_Id
:= First_Subtype
(E
);
3592 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
3595 Non_Standard_Enum
: Boolean := False;
3596 -- Set true if any of the index types is an enumeration type
3597 -- with a non-standard representation.
3600 Freeze_And_Append
(Ctyp
, N
, Result
);
3602 Indx
:= First_Index
(E
);
3603 while Present
(Indx
) loop
3604 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
3606 if Is_Enumeration_Type
(Etype
(Indx
))
3607 and then Has_Non_Standard_Rep
(Etype
(Indx
))
3609 Non_Standard_Enum
:= True;
3615 -- Processing that is done only for base types
3617 if Ekind
(E
) = E_Array_Type
then
3619 -- Propagate flags for component type
3621 if Is_Controlled
(Component_Type
(E
))
3622 or else Has_Controlled_Component
(Ctyp
)
3624 Set_Has_Controlled_Component
(E
);
3627 if Has_Unchecked_Union
(Component_Type
(E
)) then
3628 Set_Has_Unchecked_Union
(E
);
3631 -- If packing was requested or if the component size was set
3632 -- explicitly, then see if bit packing is required. This
3633 -- processing is only done for base types, since all the
3634 -- representation aspects involved are type-related. This
3635 -- is not just an optimization, if we start processing the
3636 -- subtypes, they interfere with the settings on the base
3637 -- type (this is because Is_Packed has a slightly different
3638 -- meaning before and after freezing).
3645 if (Is_Packed
(E
) or else Has_Pragma_Pack
(E
))
3646 and then Known_Static_RM_Size
(Ctyp
)
3647 and then not Has_Component_Size_Clause
(E
)
3649 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
3651 elsif Known_Component_Size
(E
) then
3652 Csiz
:= Component_Size
(E
);
3654 elsif not Known_Static_Esize
(Ctyp
) then
3658 Esiz
:= Esize
(Ctyp
);
3660 -- We can set the component size if it is less than
3661 -- 16, rounding it up to the next storage unit size.
3665 elsif Esiz
<= 16 then
3671 -- Set component size up to match alignment if it
3672 -- would otherwise be less than the alignment. This
3673 -- deals with cases of types whose alignment exceeds
3674 -- their size (padded types).
3678 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
3687 -- Case of component size that may result in packing
3689 if 1 <= Csiz
and then Csiz
<= 64 then
3691 Ent
: constant Entity_Id
:=
3693 Pack_Pragma
: constant Node_Id
:=
3694 Get_Rep_Pragma
(Ent
, Name_Pack
);
3695 Comp_Size_C
: constant Node_Id
:=
3696 Get_Attribute_Definition_Clause
3697 (Ent
, Attribute_Component_Size
);
3699 -- Warn if we have pack and component size so that
3700 -- the pack is ignored.
3702 -- Note: here we must check for the presence of a
3703 -- component size before checking for a Pack pragma
3704 -- to deal with the case where the array type is a
3705 -- derived type whose parent is currently private.
3707 if Present
(Comp_Size_C
)
3708 and then Has_Pragma_Pack
(Ent
)
3709 and then Warn_On_Redundant_Constructs
3711 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
3713 ("?r?pragma Pack for& ignored!",
3716 ("\?r?explicit component size given#!",
3718 Set_Is_Packed
(Base_Type
(Ent
), False);
3719 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
3722 -- Set component size if not already set by a
3723 -- component size clause.
3725 if not Present
(Comp_Size_C
) then
3726 Set_Component_Size
(E
, Csiz
);
3729 -- Check for base type of 8, 16, 32 bits, where an
3730 -- unsigned subtype has a length one less than the
3731 -- base type (e.g. Natural subtype of Integer).
3733 -- In such cases, if a component size was not set
3734 -- explicitly, then generate a warning.
3736 if Has_Pragma_Pack
(E
)
3737 and then not Present
(Comp_Size_C
)
3739 (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
3740 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
3742 Error_Msg_Uint_1
:= Csiz
;
3744 if Present
(Pack_Pragma
) then
3746 ("??pragma Pack causes component size "
3747 & "to be ^!", Pack_Pragma
);
3749 ("\??use Component_Size to set "
3750 & "desired value!", Pack_Pragma
);
3754 -- Actual packing is not needed for 8, 16, 32, 64.
3755 -- Also not needed for 24 if alignment is 1.
3761 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
3763 -- Here the array was requested to be packed,
3764 -- but the packing request had no effect, so
3765 -- Is_Packed is reset.
3767 -- Note: semantically this means that we lose
3768 -- track of the fact that a derived type
3769 -- inherited a pragma Pack that was non-
3770 -- effective, but that seems fine.
3772 -- We regard a Pack pragma as a request to set
3773 -- a representation characteristic, and this
3774 -- request may be ignored.
3776 Set_Is_Packed
(Base_Type
(E
), False);
3777 Set_Is_Bit_Packed_Array
(Base_Type
(E
), False);
3779 if Known_Static_Esize
(Component_Type
(E
))
3780 and then Esize
(Component_Type
(E
)) = Csiz
3782 Set_Has_Non_Standard_Rep
3783 (Base_Type
(E
), False);
3786 -- In all other cases, packing is indeed needed
3789 Set_Has_Non_Standard_Rep
(Base_Type
(E
), True);
3790 Set_Is_Bit_Packed_Array
(Base_Type
(E
), True);
3791 Set_Is_Packed
(Base_Type
(E
), True);
3797 -- Check for Atomic_Components or Aliased with unsuitable
3798 -- packing or explicit component size clause given.
3800 if (Has_Atomic_Components
(E
)
3801 or else Has_Aliased_Components
(E
))
3802 and then (Has_Component_Size_Clause
(E
)
3803 or else Is_Packed
(E
))
3805 Alias_Atomic_Check
: declare
3807 procedure Complain_CS
(T
: String);
3808 -- Outputs error messages for incorrect CS clause or
3809 -- pragma Pack for aliased or atomic components (T is
3810 -- "aliased" or "atomic");
3816 procedure Complain_CS
(T
: String) is
3818 if Has_Component_Size_Clause
(E
) then
3820 Get_Attribute_Definition_Clause
3821 (FS
, Attribute_Component_Size
);
3823 if Known_Static_Esize
(Ctyp
) then
3825 ("incorrect component size for "
3826 & T
& " components", Clause
);
3827 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3829 ("\only allowed value is^", Clause
);
3833 ("component size cannot be given for "
3834 & T
& " components", Clause
);
3839 ("cannot pack " & T
& " components",
3840 Get_Rep_Pragma
(FS
, Name_Pack
));
3846 -- Start of processing for Alias_Atomic_Check
3850 -- If object size of component type isn't known, we
3851 -- cannot be sure so we defer to the back end.
3853 if not Known_Static_Esize
(Ctyp
) then
3856 -- Case where component size has no effect. First
3857 -- check for object size of component type multiple
3858 -- of the storage unit size.
3860 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
3862 -- OK in both packing case and component size case
3863 -- if RM size is known and static and the same as
3867 ((Known_Static_RM_Size
(Ctyp
)
3868 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
3870 -- Or if we have an explicit component size
3871 -- clause and the component size and object size
3875 (Has_Component_Size_Clause
(E
)
3876 and then Component_Size
(E
) = Esize
(Ctyp
)))
3880 elsif Has_Aliased_Components
(E
)
3881 or else Is_Aliased
(Ctyp
)
3883 Complain_CS
("aliased");
3885 elsif Has_Atomic_Components
(E
)
3886 or else Is_Atomic
(Ctyp
)
3888 Complain_CS
("atomic");
3890 end Alias_Atomic_Check
;
3893 -- Warn for case of atomic type
3895 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
3898 and then not Addressable
(Component_Size
(FS
))
3901 ("non-atomic components of type& may not be "
3902 & "accessible by separate tasks??", Clause
, E
);
3904 if Has_Component_Size_Clause
(E
) then
3907 (Get_Attribute_Definition_Clause
3908 (FS
, Attribute_Component_Size
));
3910 ("\because of component size clause#??",
3913 elsif Has_Pragma_Pack
(E
) then
3915 Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
3917 ("\because of pragma Pack#??", Clause
);
3921 -- Check for scalar storage order
3923 if Present
(Get_Attribute_Definition_Clause
3924 (E
, Attribute_Scalar_Storage_Order
))
3926 Check_Component_Storage_Order
(E
, Empty
);
3929 -- Processing that is done only for subtypes
3932 -- Acquire alignment from base type
3934 if Unknown_Alignment
(E
) then
3935 Set_Alignment
(E
, Alignment
(Base_Type
(E
)));
3936 Adjust_Esize_Alignment
(E
);
3940 -- Specific checks for bit-packed arrays
3942 if Is_Bit_Packed_Array
(E
) then
3944 -- Check number of elements for bit packed arrays that come
3945 -- from source and have compile time known ranges. The
3946 -- bit-packed arrays circuitry does not support arrays
3947 -- with more than Integer'Last + 1 elements, and when this
3948 -- restriction is violated, causes incorrect data access.
3950 -- For the case where this is not compile time known, a
3951 -- run-time check should be generated???
3953 if Comes_From_Source
(E
) and then Is_Constrained
(E
) then
3962 Index
:= First_Index
(E
);
3963 while Present
(Index
) loop
3964 Ityp
:= Etype
(Index
);
3966 -- Never generate an error if any index is of a
3967 -- generic type. We will check this in instances.
3969 if Is_Generic_Type
(Ityp
) then
3975 Make_Attribute_Reference
(Loc
,
3977 New_Occurrence_Of
(Ityp
, Loc
),
3978 Attribute_Name
=> Name_Range_Length
);
3979 Analyze_And_Resolve
(Ilen
);
3981 -- No attempt is made to check number of elements
3982 -- if not compile time known.
3984 if Nkind
(Ilen
) /= N_Integer_Literal
then
3989 Elmts
:= Elmts
* Intval
(Ilen
);
3993 if Elmts
> Intval
(High_Bound
3995 (Standard_Integer
))) + 1
3998 ("bit packed array type may not have "
3999 & "more than Integer''Last+1 elements", E
);
4006 if Known_RM_Size
(E
) then
4008 SizC
: constant Node_Id
:= Size_Clause
(E
);
4011 pragma Warnings
(Off
, Discard
);
4014 -- It is not clear if it is possible to have no size
4015 -- clause at this stage, but it is not worth worrying
4016 -- about. Post error on the entity name in the size
4017 -- clause if present, else on the type entity itself.
4019 if Present
(SizC
) then
4020 Check_Size
(Name
(SizC
), E
, RM_Size
(E
), Discard
);
4022 Check_Size
(E
, E
, RM_Size
(E
), Discard
);
4028 -- If any of the index types was an enumeration type with a
4029 -- non-standard rep clause, then we indicate that the array
4030 -- type is always packed (even if it is not bit packed).
4032 if Non_Standard_Enum
then
4033 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
4034 Set_Is_Packed
(Base_Type
(E
));
4037 Set_Component_Alignment_If_Not_Set
(E
);
4039 -- If the array is packed, we must create the packed array
4040 -- type to be used to actually implement the type. This is
4041 -- only needed for real array types (not for string literal
4042 -- types, since they are present only for the front end).
4045 and then Ekind
(E
) /= E_String_Literal_Subtype
4047 Create_Packed_Array_Type
(E
);
4048 Freeze_And_Append
(Packed_Array_Type
(E
), N
, Result
);
4050 -- Size information of packed array type is copied to the
4051 -- array type, since this is really the representation. But
4052 -- do not override explicit existing size values. If the
4053 -- ancestor subtype is constrained the packed_array_type
4054 -- will be inherited from it, but the size may have been
4055 -- provided already, and must not be overridden either.
4057 if not Has_Size_Clause
(E
)
4059 (No
(Ancestor_Subtype
(E
))
4060 or else not Has_Size_Clause
(Ancestor_Subtype
(E
)))
4062 Set_Esize
(E
, Esize
(Packed_Array_Type
(E
)));
4063 Set_RM_Size
(E
, RM_Size
(Packed_Array_Type
(E
)));
4066 if not Has_Alignment_Clause
(E
) then
4067 Set_Alignment
(E
, Alignment
(Packed_Array_Type
(E
)));
4071 -- For non-packed arrays set the alignment of the array to the
4072 -- alignment of the component type if it is unknown. Skip this
4073 -- in atomic case (atomic arrays may need larger alignments).
4075 if not Is_Packed
(E
)
4076 and then Unknown_Alignment
(E
)
4077 and then Known_Alignment
(Ctyp
)
4078 and then Known_Static_Component_Size
(E
)
4079 and then Known_Static_Esize
(Ctyp
)
4080 and then Esize
(Ctyp
) = Component_Size
(E
)
4081 and then not Is_Atomic
(E
)
4083 Set_Alignment
(E
, Alignment
(Component_Type
(E
)));
4087 -- For a class-wide type, the corresponding specific type is
4088 -- frozen as well (RM 13.14(15))
4090 elsif Is_Class_Wide_Type
(E
) then
4091 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
4093 -- If the base type of the class-wide type is still incomplete,
4094 -- the class-wide remains unfrozen as well. This is legal when
4095 -- E is the formal of a primitive operation of some other type
4096 -- which is being frozen.
4098 if not Is_Frozen
(Root_Type
(E
)) then
4099 Set_Is_Frozen
(E
, False);
4103 -- The equivalent type associated with a class-wide subtype needs
4104 -- to be frozen to ensure that its layout is done.
4106 if Ekind
(E
) = E_Class_Wide_Subtype
4107 and then Present
(Equivalent_Type
(E
))
4109 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
4112 -- Generate an itype reference for a library-level class-wide type
4113 -- at the freeze point. Otherwise the first explicit reference to
4114 -- the type may appear in an inner scope which will be rejected by
4118 and then Is_Compilation_Unit
(Scope
(E
))
4121 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
4126 -- From a gigi point of view, a class-wide subtype derives
4127 -- from its record equivalent type. As a result, the itype
4128 -- reference must appear after the freeze node of the
4129 -- equivalent type or gigi will reject the reference.
4131 if Ekind
(E
) = E_Class_Wide_Subtype
4132 and then Present
(Equivalent_Type
(E
))
4134 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
4136 Add_To_Result
(Ref
);
4141 -- For a record type or record subtype, freeze all component types
4142 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
4143 -- using Is_Record_Type, because we don't want to attempt the freeze
4144 -- for the case of a private type with record extension (we will do
4145 -- that later when the full type is frozen).
4147 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
) then
4148 Freeze_Record_Type
(E
);
4150 -- For a concurrent type, freeze corresponding record type. This
4151 -- does not correspond to any specific rule in the RM, but the
4152 -- record type is essentially part of the concurrent type.
4153 -- Freeze as well all local entities. This includes record types
4154 -- created for entry parameter blocks, and whatever local entities
4155 -- may appear in the private part.
4157 elsif Is_Concurrent_Type
(E
) then
4158 if Present
(Corresponding_Record_Type
(E
)) then
4160 (Corresponding_Record_Type
(E
), N
, Result
);
4163 Comp
:= First_Entity
(E
);
4164 while Present
(Comp
) loop
4165 if Is_Type
(Comp
) then
4166 Freeze_And_Append
(Comp
, N
, Result
);
4168 elsif (Ekind
(Comp
)) /= E_Function
then
4169 if Is_Itype
(Etype
(Comp
))
4170 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
4172 Undelay_Type
(Etype
(Comp
));
4175 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
4181 -- Private types are required to point to the same freeze node as
4182 -- their corresponding full views. The freeze node itself has to
4183 -- point to the partial view of the entity (because from the partial
4184 -- view, we can retrieve the full view, but not the reverse).
4185 -- However, in order to freeze correctly, we need to freeze the full
4186 -- view. If we are freezing at the end of a scope (or within the
4187 -- scope of the private type), the partial and full views will have
4188 -- been swapped, the full view appears first in the entity chain and
4189 -- the swapping mechanism ensures that the pointers are properly set
4192 -- If we encounter the partial view before the full view (e.g. when
4193 -- freezing from another scope), we freeze the full view, and then
4194 -- set the pointers appropriately since we cannot rely on swapping to
4195 -- fix things up (subtypes in an outer scope might not get swapped).
4197 elsif Is_Incomplete_Or_Private_Type
(E
)
4198 and then not Is_Generic_Type
(E
)
4200 -- The construction of the dispatch table associated with library
4201 -- level tagged types forces freezing of all the primitives of the
4202 -- type, which may cause premature freezing of the partial view.
4206 -- type T is tagged private;
4207 -- type DT is new T with private;
4208 -- procedure Prim (X : in out T; Y : in out DT'Class);
4210 -- type T is tagged null record;
4212 -- type DT is new T with null record;
4215 -- In this case the type will be frozen later by the usual
4216 -- mechanism: an object declaration, an instantiation, or the
4217 -- end of a declarative part.
4219 if Is_Library_Level_Tagged_Type
(E
)
4220 and then not Present
(Full_View
(E
))
4222 Set_Is_Frozen
(E
, False);
4225 -- Case of full view present
4227 elsif Present
(Full_View
(E
)) then
4229 -- If full view has already been frozen, then no further
4230 -- processing is required
4232 if Is_Frozen
(Full_View
(E
)) then
4233 Set_Has_Delayed_Freeze
(E
, False);
4234 Set_Freeze_Node
(E
, Empty
);
4235 Check_Debug_Info_Needed
(E
);
4237 -- Otherwise freeze full view and patch the pointers so that
4238 -- the freeze node will elaborate both views in the back-end.
4242 Full
: constant Entity_Id
:= Full_View
(E
);
4245 if Is_Private_Type
(Full
)
4246 and then Present
(Underlying_Full_View
(Full
))
4249 (Underlying_Full_View
(Full
), N
, Result
);
4252 Freeze_And_Append
(Full
, N
, Result
);
4254 if Has_Delayed_Freeze
(E
) then
4255 F_Node
:= Freeze_Node
(Full
);
4257 if Present
(F_Node
) then
4258 Set_Freeze_Node
(E
, F_Node
);
4259 Set_Entity
(F_Node
, E
);
4262 -- {Incomplete,Private}_Subtypes with Full_Views
4263 -- constrained by discriminants.
4265 Set_Has_Delayed_Freeze
(E
, False);
4266 Set_Freeze_Node
(E
, Empty
);
4271 Check_Debug_Info_Needed
(E
);
4274 -- AI-117 requires that the convention of a partial view be the
4275 -- same as the convention of the full view. Note that this is a
4276 -- recognized breach of privacy, but it's essential for logical
4277 -- consistency of representation, and the lack of a rule in
4278 -- RM95 was an oversight.
4280 Set_Convention
(E
, Convention
(Full_View
(E
)));
4282 Set_Size_Known_At_Compile_Time
(E
,
4283 Size_Known_At_Compile_Time
(Full_View
(E
)));
4285 -- Size information is copied from the full view to the
4286 -- incomplete or private view for consistency.
4288 -- We skip this is the full view is not a type. This is very
4289 -- strange of course, and can only happen as a result of
4290 -- certain illegalities, such as a premature attempt to derive
4291 -- from an incomplete type.
4293 if Is_Type
(Full_View
(E
)) then
4294 Set_Size_Info
(E
, Full_View
(E
));
4295 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
4300 -- Case of no full view present. If entity is derived or subtype,
4301 -- it is safe to freeze, correctness depends on the frozen status
4302 -- of parent. Otherwise it is either premature usage, or a Taft
4303 -- amendment type, so diagnosis is at the point of use and the
4304 -- type might be frozen later.
4306 elsif E
/= Base_Type
(E
)
4307 or else Is_Derived_Type
(E
)
4312 Set_Is_Frozen
(E
, False);
4316 -- For access subprogram, freeze types of all formals, the return
4317 -- type was already frozen, since it is the Etype of the function.
4318 -- Formal types can be tagged Taft amendment types, but otherwise
4319 -- they cannot be incomplete.
4321 elsif Ekind
(E
) = E_Subprogram_Type
then
4322 Formal
:= First_Formal
(E
);
4323 while Present
(Formal
) loop
4324 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
4325 and then No
(Full_View
(Etype
(Formal
)))
4326 and then not Is_Value_Type
(Etype
(Formal
))
4328 if Is_Tagged_Type
(Etype
(Formal
)) then
4331 -- AI05-151: Incomplete types are allowed in access to
4332 -- subprogram specifications.
4334 elsif Ada_Version
< Ada_2012
then
4336 ("invalid use of incomplete type&", E
, Etype
(Formal
));
4340 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
4341 Next_Formal
(Formal
);
4344 Freeze_Subprogram
(E
);
4346 -- For access to a protected subprogram, freeze the equivalent type
4347 -- (however this is not set if we are not generating code or if this
4348 -- is an anonymous type used just for resolution).
4350 elsif Is_Access_Protected_Subprogram_Type
(E
) then
4351 if Present
(Equivalent_Type
(E
)) then
4352 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
4356 -- Generic types are never seen by the back-end, and are also not
4357 -- processed by the expander (since the expander is turned off for
4358 -- generic processing), so we never need freeze nodes for them.
4360 if Is_Generic_Type
(E
) then
4364 -- Some special processing for non-generic types to complete
4365 -- representation details not known till the freeze point.
4367 if Is_Fixed_Point_Type
(E
) then
4368 Freeze_Fixed_Point_Type
(E
);
4370 -- Some error checks required for ordinary fixed-point type. Defer
4371 -- these till the freeze-point since we need the small and range
4372 -- values. We only do these checks for base types
4374 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
4375 if Small_Value
(E
) < Ureal_2_M_80
then
4376 Error_Msg_Name_1
:= Name_Small
;
4378 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
4380 elsif Small_Value
(E
) > Ureal_2_80
then
4381 Error_Msg_Name_1
:= Name_Small
;
4383 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
4386 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
4387 Error_Msg_Name_1
:= Name_First
;
4389 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
4392 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
4393 Error_Msg_Name_1
:= Name_Last
;
4395 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
4399 elsif Is_Enumeration_Type
(E
) then
4400 Freeze_Enumeration_Type
(E
);
4402 elsif Is_Integer_Type
(E
) then
4403 Adjust_Esize_For_Alignment
(E
);
4405 if Is_Modular_Integer_Type
(E
)
4406 and then Warn_On_Suspicious_Modulus_Value
4408 Check_Suspicious_Modulus
(E
);
4411 elsif Is_Access_Type
(E
)
4412 and then not Is_Access_Subprogram_Type
(E
)
4414 -- If a pragma Default_Storage_Pool applies, and this type has no
4415 -- Storage_Pool or Storage_Size clause (which must have occurred
4416 -- before the freezing point), then use the default. This applies
4417 -- only to base types.
4419 -- None of this applies to access to subprograms, for which there
4420 -- are clearly no pools.
4422 if Present
(Default_Pool
)
4423 and then Is_Base_Type
(E
)
4424 and then not Has_Storage_Size_Clause
(E
)
4425 and then No
(Associated_Storage_Pool
(E
))
4427 -- Case of pragma Default_Storage_Pool (null)
4429 if Nkind
(Default_Pool
) = N_Null
then
4430 Set_No_Pool_Assigned
(E
);
4432 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
4435 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
4439 -- Check restriction for standard storage pool
4441 if No
(Associated_Storage_Pool
(E
)) then
4442 Check_Restriction
(No_Standard_Storage_Pools
, E
);
4445 -- Deal with error message for pure access type. This is not an
4446 -- error in Ada 2005 if there is no pool (see AI-366).
4448 if Is_Pure_Unit_Access_Type
(E
)
4449 and then (Ada_Version
< Ada_2005
4450 or else not No_Pool_Assigned
(E
))
4452 Error_Msg_N
("named access type not allowed in pure unit", E
);
4454 if Ada_Version
>= Ada_2005
then
4456 ("\would be legal if Storage_Size of 0 given??", E
);
4458 elsif No_Pool_Assigned
(E
) then
4460 ("\would be legal in Ada 2005??", E
);
4464 ("\would be legal in Ada 2005 if "
4465 & "Storage_Size of 0 given??", E
);
4470 -- Case of composite types
4472 if Is_Composite_Type
(E
) then
4474 -- AI-117 requires that all new primitives of a tagged type must
4475 -- inherit the convention of the full view of the type. Inherited
4476 -- and overriding operations are defined to inherit the convention
4477 -- of their parent or overridden subprogram (also specified in
4478 -- AI-117), which will have occurred earlier (in Derive_Subprogram
4479 -- and New_Overloaded_Entity). Here we set the convention of
4480 -- primitives that are still convention Ada, which will ensure
4481 -- that any new primitives inherit the type's convention. Class-
4482 -- wide types can have a foreign convention inherited from their
4483 -- specific type, but are excluded from this since they don't have
4484 -- any associated primitives.
4486 if Is_Tagged_Type
(E
)
4487 and then not Is_Class_Wide_Type
(E
)
4488 and then Convention
(E
) /= Convention_Ada
4491 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
4495 Prim
:= First_Elmt
(Prim_List
);
4496 while Present
(Prim
) loop
4497 if Convention
(Node
(Prim
)) = Convention_Ada
then
4498 Set_Convention
(Node
(Prim
), Convention
(E
));
4506 -- If the type is a simple storage pool type, then this is where
4507 -- we attempt to locate and validate its Allocate, Deallocate, and
4508 -- Storage_Size operations (the first is required, and the latter
4509 -- two are optional). We also verify that the full type for a
4510 -- private type is allowed to be a simple storage pool type.
4512 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
4513 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
4515 -- If the type is marked Has_Private_Declaration, then this is
4516 -- a full type for a private type that was specified with the
4517 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
4518 -- pragma is allowed for the full type (for example, it can't
4519 -- be an array type, or a nonlimited record type).
4521 if Has_Private_Declaration
(E
) then
4522 if (not Is_Record_Type
(E
)
4523 or else not Is_Immutably_Limited_Type
(E
))
4524 and then not Is_Private_Type
(E
)
4526 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
4528 ("pragma% can only apply to full type that is an " &
4529 "explicitly limited type", E
);
4533 Validate_Simple_Pool_Ops
: declare
4534 Pool_Type
: Entity_Id
renames E
;
4535 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
4536 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
4538 procedure Validate_Simple_Pool_Op_Formal
4539 (Pool_Op
: Entity_Id
;
4540 Pool_Op_Formal
: in out Entity_Id
;
4541 Expected_Mode
: Formal_Kind
;
4542 Expected_Type
: Entity_Id
;
4543 Formal_Name
: String;
4544 OK_Formal
: in out Boolean);
4545 -- Validate one formal Pool_Op_Formal of the candidate pool
4546 -- operation Pool_Op. The formal must be of Expected_Type
4547 -- and have mode Expected_Mode. OK_Formal will be set to
4548 -- False if the formal doesn't match. If OK_Formal is False
4549 -- on entry, then the formal will effectively be ignored
4550 -- (because validation of the pool op has already failed).
4551 -- Upon return, Pool_Op_Formal will be updated to the next
4554 procedure Validate_Simple_Pool_Operation
(Op_Name
: Name_Id
);
4555 -- Search for and validate a simple pool operation with the
4556 -- name Op_Name. If the name is Allocate, then there must be
4557 -- exactly one such primitive operation for the simple pool
4558 -- type. If the name is Deallocate or Storage_Size, then
4559 -- there can be at most one such primitive operation. The
4560 -- profile of the located primitive must conform to what
4561 -- is expected for each operation.
4563 ------------------------------------
4564 -- Validate_Simple_Pool_Op_Formal --
4565 ------------------------------------
4567 procedure Validate_Simple_Pool_Op_Formal
4568 (Pool_Op
: Entity_Id
;
4569 Pool_Op_Formal
: in out Entity_Id
;
4570 Expected_Mode
: Formal_Kind
;
4571 Expected_Type
: Entity_Id
;
4572 Formal_Name
: String;
4573 OK_Formal
: in out Boolean)
4576 -- If OK_Formal is False on entry, then simply ignore
4577 -- the formal, because an earlier formal has already
4580 if not OK_Formal
then
4583 -- If no formal is passed in, then issue an error for a
4586 elsif not Present
(Pool_Op_Formal
) then
4588 ("simple storage pool op missing formal " &
4589 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
4595 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
4597 -- If the pool type was expected for this formal, then
4598 -- this will not be considered a candidate operation
4599 -- for the simple pool, so we unset OK_Formal so that
4600 -- the op and any later formals will be ignored.
4602 if Expected_Type
= Pool_Type
then
4609 ("wrong type for formal " & Formal_Name
&
4610 " of simple storage pool op; expected type&",
4611 Pool_Op_Formal
, Expected_Type
);
4615 -- Issue error if formal's mode is not the expected one
4617 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
4619 ("wrong mode for formal of simple storage pool op",
4623 -- Advance to the next formal
4625 Next_Formal
(Pool_Op_Formal
);
4626 end Validate_Simple_Pool_Op_Formal
;
4628 ------------------------------------
4629 -- Validate_Simple_Pool_Operation --
4630 ------------------------------------
4632 procedure Validate_Simple_Pool_Operation
4636 Found_Op
: Entity_Id
:= Empty
;
4642 (Nam_In
(Op_Name
, Name_Allocate
,
4644 Name_Storage_Size
));
4646 Error_Msg_Name_1
:= Op_Name
;
4648 -- For each homonym declared immediately in the scope
4649 -- of the simple storage pool type, determine whether
4650 -- the homonym is an operation of the pool type, and,
4651 -- if so, check that its profile is as expected for
4652 -- a simple pool operation of that name.
4654 Op
:= Get_Name_Entity_Id
(Op_Name
);
4655 while Present
(Op
) loop
4656 if Ekind_In
(Op
, E_Function
, E_Procedure
)
4657 and then Scope
(Op
) = Current_Scope
4659 Formal
:= First_Entity
(Op
);
4663 -- The first parameter must be of the pool type
4664 -- in order for the operation to qualify.
4666 if Op_Name
= Name_Storage_Size
then
4667 Validate_Simple_Pool_Op_Formal
4668 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
4671 Validate_Simple_Pool_Op_Formal
4672 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
4676 -- If another operation with this name has already
4677 -- been located for the type, then flag an error,
4678 -- since we only allow the type to have a single
4681 if Present
(Found_Op
) and then Is_OK
then
4683 ("only one % operation allowed for " &
4684 "simple storage pool type&", Op
, Pool_Type
);
4687 -- In the case of Allocate and Deallocate, a formal
4688 -- of type System.Address is required.
4690 if Op_Name
= Name_Allocate
then
4691 Validate_Simple_Pool_Op_Formal
4692 (Op
, Formal
, E_Out_Parameter
,
4693 Address_Type
, "Storage_Address", Is_OK
);
4695 elsif Op_Name
= Name_Deallocate
then
4696 Validate_Simple_Pool_Op_Formal
4697 (Op
, Formal
, E_In_Parameter
,
4698 Address_Type
, "Storage_Address", Is_OK
);
4701 -- In the case of Allocate and Deallocate, formals
4702 -- of type Storage_Count are required as the third
4703 -- and fourth parameters.
4705 if Op_Name
/= Name_Storage_Size
then
4706 Validate_Simple_Pool_Op_Formal
4707 (Op
, Formal
, E_In_Parameter
,
4708 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
4709 Validate_Simple_Pool_Op_Formal
4710 (Op
, Formal
, E_In_Parameter
,
4711 Stg_Cnt_Type
, "Alignment", Is_OK
);
4714 -- If no mismatched formals have been found (Is_OK)
4715 -- and no excess formals are present, then this
4716 -- operation has been validated, so record it.
4718 if not Present
(Formal
) and then Is_OK
then
4726 -- There must be a valid Allocate operation for the type,
4727 -- so issue an error if none was found.
4729 if Op_Name
= Name_Allocate
4730 and then not Present
(Found_Op
)
4732 Error_Msg_N
("missing % operation for simple " &
4733 "storage pool type", Pool_Type
);
4735 elsif Present
(Found_Op
) then
4737 -- Simple pool operations can't be abstract
4739 if Is_Abstract_Subprogram
(Found_Op
) then
4741 ("simple storage pool operation must not be " &
4742 "abstract", Found_Op
);
4745 -- The Storage_Size operation must be a function with
4746 -- Storage_Count as its result type.
4748 if Op_Name
= Name_Storage_Size
then
4749 if Ekind
(Found_Op
) = E_Procedure
then
4751 ("% operation must be a function", Found_Op
);
4753 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
4755 ("wrong result type for%, expected type&",
4756 Found_Op
, Stg_Cnt_Type
);
4759 -- Allocate and Deallocate must be procedures
4761 elsif Ekind
(Found_Op
) = E_Function
then
4763 ("% operation must be a procedure", Found_Op
);
4766 end Validate_Simple_Pool_Operation
;
4768 -- Start of processing for Validate_Simple_Pool_Ops
4771 Validate_Simple_Pool_Operation
(Name_Allocate
);
4772 Validate_Simple_Pool_Operation
(Name_Deallocate
);
4773 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
4774 end Validate_Simple_Pool_Ops
;
4778 -- Now that all types from which E may depend are frozen, see if the
4779 -- size is known at compile time, if it must be unsigned, or if
4780 -- strict alignment is required
4782 Check_Compile_Time_Size
(E
);
4783 Check_Unsigned_Type
(E
);
4785 if Base_Type
(E
) = E
then
4786 Check_Strict_Alignment
(E
);
4789 -- Do not allow a size clause for a type which does not have a size
4790 -- that is known at compile time
4792 if Has_Size_Clause
(E
)
4793 and then not Size_Known_At_Compile_Time
(E
)
4795 -- Suppress this message if errors posted on E, even if we are
4796 -- in all errors mode, since this is often a junk message
4798 if not Error_Posted
(E
) then
4800 ("size clause not allowed for variable length type",
4805 -- Now we set/verify the representation information, in particular
4806 -- the size and alignment values. This processing is not required for
4807 -- generic types, since generic types do not play any part in code
4808 -- generation, and so the size and alignment values for such types
4809 -- are irrelevant. Ditto for types declared within a generic unit,
4810 -- which may have components that depend on generic parameters, and
4811 -- that will be recreated in an instance.
4813 if Inside_A_Generic
then
4816 -- Otherwise we call the layout procedure
4822 -- If this is an access to subprogram whose designated type is itself
4823 -- a subprogram type, the return type of this anonymous subprogram
4824 -- type must be decorated as well.
4826 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
4827 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
4829 Layout_Type
(Etype
(Designated_Type
(E
)));
4832 -- If the type has a Defaut_Value/Default_Component_Value aspect,
4833 -- this is where we analye the expression (after the type is frozen,
4834 -- since in the case of Default_Value, we are analyzing with the
4835 -- type itself, and we treat Default_Component_Value similarly for
4836 -- the sake of uniformity).
4838 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
4845 if Is_Scalar_Type
(E
) then
4846 Nam
:= Name_Default_Value
;
4848 Exp
:= Default_Aspect_Value
(Typ
);
4850 Nam
:= Name_Default_Component_Value
;
4851 Typ
:= Component_Type
(E
);
4852 Exp
:= Default_Aspect_Component_Value
(E
);
4855 Analyze_And_Resolve
(Exp
, Typ
);
4857 if Etype
(Exp
) /= Any_Type
then
4858 if not Is_Static_Expression
(Exp
) then
4859 Error_Msg_Name_1
:= Nam
;
4860 Flag_Non_Static_Expr
4861 ("aspect% requires static expression", Exp
);
4867 -- End of freeze processing for type entities
4870 -- Here is where we logically freeze the current entity. If it has a
4871 -- freeze node, then this is the point at which the freeze node is
4872 -- linked into the result list.
4874 if Has_Delayed_Freeze
(E
) then
4876 -- If a freeze node is already allocated, use it, otherwise allocate
4877 -- a new one. The preallocation happens in the case of anonymous base
4878 -- types, where we preallocate so that we can set First_Subtype_Link.
4879 -- Note that we reset the Sloc to the current freeze location.
4881 if Present
(Freeze_Node
(E
)) then
4882 F_Node
:= Freeze_Node
(E
);
4883 Set_Sloc
(F_Node
, Loc
);
4886 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
4887 Set_Freeze_Node
(E
, F_Node
);
4888 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
4889 Set_TSS_Elist
(F_Node
, No_Elist
);
4890 Set_Actions
(F_Node
, No_List
);
4893 Set_Entity
(F_Node
, E
);
4894 Add_To_Result
(F_Node
);
4896 -- A final pass over record types with discriminants. If the type
4897 -- has an incomplete declaration, there may be constrained access
4898 -- subtypes declared elsewhere, which do not depend on the discrimi-
4899 -- nants of the type, and which are used as component types (i.e.
4900 -- the full view is a recursive type). The designated types of these
4901 -- subtypes can only be elaborated after the type itself, and they
4902 -- need an itype reference.
4904 if Ekind
(E
) = E_Record_Type
4905 and then Has_Discriminants
(E
)
4913 Comp
:= First_Component
(E
);
4914 while Present
(Comp
) loop
4915 Typ
:= Etype
(Comp
);
4917 if Ekind
(Comp
) = E_Component
4918 and then Is_Access_Type
(Typ
)
4919 and then Scope
(Typ
) /= E
4920 and then Base_Type
(Designated_Type
(Typ
)) = E
4921 and then Is_Itype
(Designated_Type
(Typ
))
4923 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
4924 Set_Itype
(IR
, Designated_Type
(Typ
));
4925 Append
(IR
, Result
);
4928 Next_Component
(Comp
);
4934 -- When a type is frozen, the first subtype of the type is frozen as
4935 -- well (RM 13.14(15)). This has to be done after freezing the type,
4936 -- since obviously the first subtype depends on its own base type.
4939 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
4941 -- If we just froze a tagged non-class wide record, then freeze the
4942 -- corresponding class-wide type. This must be done after the tagged
4943 -- type itself is frozen, because the class-wide type refers to the
4944 -- tagged type which generates the class.
4946 if Is_Tagged_Type
(E
)
4947 and then not Is_Class_Wide_Type
(E
)
4948 and then Present
(Class_Wide_Type
(E
))
4950 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
4954 Check_Debug_Info_Needed
(E
);
4956 -- Special handling for subprograms
4958 if Is_Subprogram
(E
) then
4960 -- If subprogram has address clause then reset Is_Public flag, since
4961 -- we do not want the backend to generate external references.
4963 if Present
(Address_Clause
(E
))
4964 and then not Is_Library_Level_Entity
(E
)
4966 Set_Is_Public
(E
, False);
4973 -----------------------------
4974 -- Freeze_Enumeration_Type --
4975 -----------------------------
4977 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
4979 -- By default, if no size clause is present, an enumeration type with
4980 -- Convention C is assumed to interface to a C enum, and has integer
4981 -- size. This applies to types. For subtypes, verify that its base
4982 -- type has no size clause either. Treat other foreign conventions
4983 -- in the same way, and also make sure alignment is set right.
4985 if Has_Foreign_Convention
(Typ
)
4986 and then not Has_Size_Clause
(Typ
)
4987 and then not Has_Size_Clause
(Base_Type
(Typ
))
4988 and then Esize
(Typ
) < Standard_Integer_Size
4990 Init_Esize
(Typ
, Standard_Integer_Size
);
4991 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
4994 -- If the enumeration type interfaces to C, and it has a size clause
4995 -- that specifies less than int size, it warrants a warning. The
4996 -- user may intend the C type to be an enum or a char, so this is
4997 -- not by itself an error that the Ada compiler can detect, but it
4998 -- it is a worth a heads-up. For Boolean and Character types we
4999 -- assume that the programmer has the proper C type in mind.
5001 if Convention
(Typ
) = Convention_C
5002 and then Has_Size_Clause
(Typ
)
5003 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
5004 and then not Is_Boolean_Type
(Typ
)
5005 and then not Is_Character_Type
(Typ
)
5008 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
5011 Adjust_Esize_For_Alignment
(Typ
);
5013 end Freeze_Enumeration_Type
;
5015 -----------------------
5016 -- Freeze_Expression --
5017 -----------------------
5019 procedure Freeze_Expression
(N
: Node_Id
) is
5020 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
5023 Desig_Typ
: Entity_Id
;
5027 Freeze_Outside
: Boolean := False;
5028 -- This flag is set true if the entity must be frozen outside the
5029 -- current subprogram. This happens in the case of expander generated
5030 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
5031 -- not freeze all entities like other bodies, but which nevertheless
5032 -- may reference entities that have to be frozen before the body and
5033 -- obviously cannot be frozen inside the body.
5035 function In_Exp_Body
(N
: Node_Id
) return Boolean;
5036 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
5037 -- it is the handled statement sequence of an expander-generated
5038 -- subprogram (init proc, stream subprogram, or renaming as body).
5039 -- If so, this is not a freezing context.
5045 function In_Exp_Body
(N
: Node_Id
) return Boolean is
5050 if Nkind
(N
) = N_Subprogram_Body
then
5056 if Nkind
(P
) /= N_Subprogram_Body
then
5060 Id
:= Defining_Unit_Name
(Specification
(P
));
5062 -- Following complex conditional could use comments ???
5064 if Nkind
(Id
) = N_Defining_Identifier
5065 and then (Is_Init_Proc
(Id
)
5066 or else Is_TSS
(Id
, TSS_Stream_Input
)
5067 or else Is_TSS
(Id
, TSS_Stream_Output
)
5068 or else Is_TSS
(Id
, TSS_Stream_Read
)
5069 or else Is_TSS
(Id
, TSS_Stream_Write
)
5070 or else Nkind_In
(Original_Node
(P
),
5071 N_Subprogram_Renaming_Declaration
,
5072 N_Expression_Function
))
5081 -- Start of processing for Freeze_Expression
5084 -- Immediate return if freezing is inhibited. This flag is set by the
5085 -- analyzer to stop freezing on generated expressions that would cause
5086 -- freezing if they were in the source program, but which are not
5087 -- supposed to freeze, since they are created.
5089 if Must_Not_Freeze
(N
) then
5093 -- If expression is non-static, then it does not freeze in a default
5094 -- expression, see section "Handling of Default Expressions" in the
5095 -- spec of package Sem for further details. Note that we have to make
5096 -- sure that we actually have a real expression (if we have a subtype
5097 -- indication, we can't test Is_Static_Expression!) However, we exclude
5098 -- the case of the prefix of an attribute of a static scalar subtype
5099 -- from this early return, because static subtype attributes should
5100 -- always cause freezing, even in default expressions, but the attribute
5101 -- may not have been marked as static yet (because in Resolve_Attribute,
5102 -- the call to Eval_Attribute follows the call of Freeze_Expression on
5106 and then Nkind
(N
) in N_Subexpr
5107 and then not Is_Static_Expression
(N
)
5108 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
5109 or else not (Is_Entity_Name
(N
)
5110 and then Is_Type
(Entity
(N
))
5111 and then Is_Static_Subtype
(Entity
(N
))))
5116 -- Freeze type of expression if not frozen already
5120 if Nkind
(N
) in N_Has_Etype
then
5121 if not Is_Frozen
(Etype
(N
)) then
5124 -- Base type may be an derived numeric type that is frozen at
5125 -- the point of declaration, but first_subtype is still unfrozen.
5127 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
5128 Typ
:= First_Subtype
(Etype
(N
));
5132 -- For entity name, freeze entity if not frozen already. A special
5133 -- exception occurs for an identifier that did not come from source.
5134 -- We don't let such identifiers freeze a non-internal entity, i.e.
5135 -- an entity that did come from source, since such an identifier was
5136 -- generated by the expander, and cannot have any semantic effect on
5137 -- the freezing semantics. For example, this stops the parameter of
5138 -- an initialization procedure from freezing the variable.
5140 if Is_Entity_Name
(N
)
5141 and then not Is_Frozen
(Entity
(N
))
5142 and then (Nkind
(N
) /= N_Identifier
5143 or else Comes_From_Source
(N
)
5144 or else not Comes_From_Source
(Entity
(N
)))
5151 -- For an allocator freeze designated type if not frozen already
5153 -- For an aggregate whose component type is an access type, freeze the
5154 -- designated type now, so that its freeze does not appear within the
5155 -- loop that might be created in the expansion of the aggregate. If the
5156 -- designated type is a private type without full view, the expression
5157 -- cannot contain an allocator, so the type is not frozen.
5159 -- For a function, we freeze the entity when the subprogram declaration
5160 -- is frozen, but a function call may appear in an initialization proc.
5161 -- before the declaration is frozen. We need to generate the extra
5162 -- formals, if any, to ensure that the expansion of the call includes
5163 -- the proper actuals. This only applies to Ada subprograms, not to
5170 Desig_Typ
:= Designated_Type
(Etype
(N
));
5173 if Is_Array_Type
(Etype
(N
))
5174 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
5176 Desig_Typ
:= Designated_Type
(Component_Type
(Etype
(N
)));
5179 when N_Selected_Component |
5180 N_Indexed_Component |
5183 if Is_Access_Type
(Etype
(Prefix
(N
))) then
5184 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
5187 when N_Identifier
=>
5189 and then Ekind
(Nam
) = E_Function
5190 and then Nkind
(Parent
(N
)) = N_Function_Call
5191 and then Convention
(Nam
) = Convention_Ada
5193 Create_Extra_Formals
(Nam
);
5200 if Desig_Typ
/= Empty
5201 and then (Is_Frozen
(Desig_Typ
)
5202 or else (not Is_Fully_Defined
(Desig_Typ
)))
5207 -- All done if nothing needs freezing
5211 and then No
(Desig_Typ
)
5216 -- Loop for looking at the right place to insert the freeze nodes,
5217 -- exiting from the loop when it is appropriate to insert the freeze
5218 -- node before the current node P.
5220 -- Also checks some special exceptions to the freezing rules. These
5221 -- cases result in a direct return, bypassing the freeze action.
5225 Parent_P
:= Parent
(P
);
5227 -- If we don't have a parent, then we are not in a well-formed tree.
5228 -- This is an unusual case, but there are some legitimate situations
5229 -- in which this occurs, notably when the expressions in the range of
5230 -- a type declaration are resolved. We simply ignore the freeze
5231 -- request in this case. Is this right ???
5233 if No
(Parent_P
) then
5237 -- See if we have got to an appropriate point in the tree
5239 case Nkind
(Parent_P
) is
5241 -- A special test for the exception of (RM 13.14(8)) for the case
5242 -- of per-object expressions (RM 3.8(18)) occurring in component
5243 -- definition or a discrete subtype definition. Note that we test
5244 -- for a component declaration which includes both cases we are
5245 -- interested in, and furthermore the tree does not have explicit
5246 -- nodes for either of these two constructs.
5248 when N_Component_Declaration
=>
5250 -- The case we want to test for here is an identifier that is
5251 -- a per-object expression, this is either a discriminant that
5252 -- appears in a context other than the component declaration
5253 -- or it is a reference to the type of the enclosing construct.
5255 -- For either of these cases, we skip the freezing
5257 if not In_Spec_Expression
5258 and then Nkind
(N
) = N_Identifier
5259 and then (Present
(Entity
(N
)))
5261 -- We recognize the discriminant case by just looking for
5262 -- a reference to a discriminant. It can only be one for
5263 -- the enclosing construct. Skip freezing in this case.
5265 if Ekind
(Entity
(N
)) = E_Discriminant
then
5268 -- For the case of a reference to the enclosing record,
5269 -- (or task or protected type), we look for a type that
5270 -- matches the current scope.
5272 elsif Entity
(N
) = Current_Scope
then
5277 -- If we have an enumeration literal that appears as the choice in
5278 -- the aggregate of an enumeration representation clause, then
5279 -- freezing does not occur (RM 13.14(10)).
5281 when N_Enumeration_Representation_Clause
=>
5283 -- The case we are looking for is an enumeration literal
5285 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
5286 and then Is_Enumeration_Type
(Etype
(N
))
5288 -- If enumeration literal appears directly as the choice,
5289 -- do not freeze (this is the normal non-overloaded case)
5291 if Nkind
(Parent
(N
)) = N_Component_Association
5292 and then First
(Choices
(Parent
(N
))) = N
5296 -- If enumeration literal appears as the name of function
5297 -- which is the choice, then also do not freeze. This
5298 -- happens in the overloaded literal case, where the
5299 -- enumeration literal is temporarily changed to a function
5300 -- call for overloading analysis purposes.
5302 elsif Nkind
(Parent
(N
)) = N_Function_Call
5304 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
5306 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
5312 -- Normally if the parent is a handled sequence of statements,
5313 -- then the current node must be a statement, and that is an
5314 -- appropriate place to insert a freeze node.
5316 when N_Handled_Sequence_Of_Statements
=>
5318 -- An exception occurs when the sequence of statements is for
5319 -- an expander generated body that did not do the usual freeze
5320 -- all operation. In this case we usually want to freeze
5321 -- outside this body, not inside it, and we skip past the
5322 -- subprogram body that we are inside.
5324 if In_Exp_Body
(Parent_P
) then
5326 Subp
: constant Node_Id
:= Parent
(Parent_P
);
5330 -- Freeze the entity only when it is declared inside the
5331 -- body of the expander generated procedure. This case
5332 -- is recognized by the scope of the entity or its type,
5333 -- which is either the spec for some enclosing body, or
5334 -- (in the case of init_procs, for which there are no
5335 -- separate specs) the current scope.
5337 if Nkind
(Subp
) = N_Subprogram_Body
then
5338 Spec
:= Corresponding_Spec
(Subp
);
5340 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
5342 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
5347 and then Scope
(Typ
) = Current_Scope
5348 and then Defining_Entity
(Subp
) = Current_Scope
5354 -- An expression function may act as a completion of
5355 -- a function declaration. As such, it can reference
5356 -- entities declared between the two views:
5359 -- function F return ...;
5361 -- function Hidden return ...;
5362 -- function F return ... is (Hidden); -- 2
5364 -- Refering to the example above, freezing the expression
5365 -- of F (2) would place Hidden's freeze node (1) in the
5366 -- wrong place. Avoid explicit freezing and let the usual
5367 -- scenarios do the job - for example, reaching the end
5368 -- of the private declarations.
5370 if Nkind
(Original_Node
(Subp
)) =
5371 N_Expression_Function
5375 -- Freeze outside the body
5378 Parent_P
:= Parent
(Parent_P
);
5379 Freeze_Outside
:= True;
5383 -- Here if normal case where we are in handled statement
5384 -- sequence and want to do the insertion right there.
5390 -- If parent is a body or a spec or a block, then the current node
5391 -- is a statement or declaration and we can insert the freeze node
5394 when N_Block_Statement |
5397 N_Package_Specification |
5400 N_Task_Body
=> exit;
5402 -- The expander is allowed to define types in any statements list,
5403 -- so any of the following parent nodes also mark a freezing point
5404 -- if the actual node is in a list of statements or declarations.
5406 when N_Abortable_Part |
5407 N_Accept_Alternative |
5409 N_Case_Statement_Alternative |
5410 N_Compilation_Unit_Aux |
5411 N_Conditional_Entry_Call |
5412 N_Delay_Alternative |
5414 N_Entry_Call_Alternative |
5415 N_Exception_Handler |
5416 N_Extended_Return_Statement |
5420 N_Selective_Accept |
5421 N_Triggering_Alternative
=>
5423 exit when Is_List_Member
(P
);
5425 -- Note: The N_Loop_Statement is a special case. A type that
5426 -- appears in the source can never be frozen in a loop (this
5427 -- occurs only because of a loop expanded by the expander), so we
5428 -- keep on going. Otherwise we terminate the search. Same is true
5429 -- of any entity which comes from source. (if they have predefined
5430 -- type, that type does not appear to come from source, but the
5431 -- entity should not be frozen here).
5433 when N_Loop_Statement
=>
5434 exit when not Comes_From_Source
(Etype
(N
))
5435 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
5437 -- For all other cases, keep looking at parents
5443 -- We fall through the case if we did not yet find the proper
5444 -- place in the free for inserting the freeze node, so climb!
5449 -- If the expression appears in a record or an initialization procedure,
5450 -- the freeze nodes are collected and attached to the current scope, to
5451 -- be inserted and analyzed on exit from the scope, to insure that
5452 -- generated entities appear in the correct scope. If the expression is
5453 -- a default for a discriminant specification, the scope is still void.
5454 -- The expression can also appear in the discriminant part of a private
5455 -- or concurrent type.
5457 -- If the expression appears in a constrained subcomponent of an
5458 -- enclosing record declaration, the freeze nodes must be attached to
5459 -- the outer record type so they can eventually be placed in the
5460 -- enclosing declaration list.
5462 -- The other case requiring this special handling is if we are in a
5463 -- default expression, since in that case we are about to freeze a
5464 -- static type, and the freeze scope needs to be the outer scope, not
5465 -- the scope of the subprogram with the default parameter.
5467 -- For default expressions and other spec expressions in generic units,
5468 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
5469 -- placing them at the proper place, after the generic unit.
5471 if (In_Spec_Exp
and not Inside_A_Generic
)
5472 or else Freeze_Outside
5473 or else (Is_Type
(Current_Scope
)
5474 and then (not Is_Concurrent_Type
(Current_Scope
)
5475 or else not Has_Completion
(Current_Scope
)))
5476 or else Ekind
(Current_Scope
) = E_Void
5479 N
: constant Node_Id
:= Current_Scope
;
5480 Freeze_Nodes
: List_Id
:= No_List
;
5481 Pos
: Int
:= Scope_Stack
.Last
;
5484 if Present
(Desig_Typ
) then
5485 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
5488 if Present
(Typ
) then
5489 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
5492 if Present
(Nam
) then
5493 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
5496 -- The current scope may be that of a constrained component of
5497 -- an enclosing record declaration, or of a loop of an enclosing
5498 -- quantified expression, which is above the current scope in the
5499 -- scope stack. Indeed in the context of a quantified expression,
5500 -- a scope is created and pushed above the current scope in order
5501 -- to emulate the loop-like behavior of the quantified expression.
5502 -- If the expression is within a top-level pragma, as for a pre-
5503 -- condition on a library-level subprogram, nothing to do.
5505 if not Is_Compilation_Unit
(Current_Scope
)
5506 and then (Is_Record_Type
(Scope
(Current_Scope
))
5507 or else Nkind
(Parent
(Current_Scope
)) =
5508 N_Quantified_Expression
)
5513 if Is_Non_Empty_List
(Freeze_Nodes
) then
5514 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
5515 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
5518 Append_List
(Freeze_Nodes
,
5519 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
5527 -- Now we have the right place to do the freezing. First, a special
5528 -- adjustment, if we are in spec-expression analysis mode, these freeze
5529 -- actions must not be thrown away (normally all inserted actions are
5530 -- thrown away in this mode. However, the freeze actions are from static
5531 -- expressions and one of the important reasons we are doing this
5532 -- special analysis is to get these freeze actions. Therefore we turn
5533 -- off the In_Spec_Expression mode to propagate these freeze actions.
5534 -- This also means they get properly analyzed and expanded.
5536 In_Spec_Expression
:= False;
5538 -- Freeze the designated type of an allocator (RM 13.14(13))
5540 if Present
(Desig_Typ
) then
5541 Freeze_Before
(P
, Desig_Typ
);
5544 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
5545 -- the enumeration representation clause exception in the loop above.
5547 if Present
(Typ
) then
5548 Freeze_Before
(P
, Typ
);
5551 -- Freeze name if one is present (RM 13.14(11))
5553 if Present
(Nam
) then
5554 Freeze_Before
(P
, Nam
);
5557 -- Restore In_Spec_Expression flag
5559 In_Spec_Expression
:= In_Spec_Exp
;
5560 end Freeze_Expression
;
5562 -----------------------------
5563 -- Freeze_Fixed_Point_Type --
5564 -----------------------------
5566 -- Certain fixed-point types and subtypes, including implicit base types
5567 -- and declared first subtypes, have not yet set up a range. This is
5568 -- because the range cannot be set until the Small and Size values are
5569 -- known, and these are not known till the type is frozen.
5571 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
5572 -- whose bounds are unanalyzed real literals. This routine will recognize
5573 -- this case, and transform this range node into a properly typed range
5574 -- with properly analyzed and resolved values.
5576 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
5577 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
5578 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
5579 Hi
: constant Node_Id
:= High_Bound
(Rng
);
5580 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
5581 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
5582 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
5583 BHi
: constant Node_Id
:= High_Bound
(Brng
);
5584 Small
: constant Ureal
:= Small_Value
(Typ
);
5591 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
5592 -- Returns size of type with given bounds. Also leaves these
5593 -- bounds set as the current bounds of the Typ.
5599 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
5601 Set_Realval
(Lo
, Lov
);
5602 Set_Realval
(Hi
, Hiv
);
5603 return Minimum_Size
(Typ
);
5606 -- Start of processing for Freeze_Fixed_Point_Type
5609 -- If Esize of a subtype has not previously been set, set it now
5611 if Unknown_Esize
(Typ
) then
5612 Atype
:= Ancestor_Subtype
(Typ
);
5614 if Present
(Atype
) then
5615 Set_Esize
(Typ
, Esize
(Atype
));
5617 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
5621 -- Immediate return if the range is already analyzed. This means that
5622 -- the range is already set, and does not need to be computed by this
5625 if Analyzed
(Rng
) then
5629 -- Immediate return if either of the bounds raises Constraint_Error
5631 if Raises_Constraint_Error
(Lo
)
5632 or else Raises_Constraint_Error
(Hi
)
5637 Loval
:= Realval
(Lo
);
5638 Hival
:= Realval
(Hi
);
5640 -- Ordinary fixed-point case
5642 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
5644 -- For the ordinary fixed-point case, we are allowed to fudge the
5645 -- end-points up or down by small. Generally we prefer to fudge up,
5646 -- i.e. widen the bounds for non-model numbers so that the end points
5647 -- are included. However there are cases in which this cannot be
5648 -- done, and indeed cases in which we may need to narrow the bounds.
5649 -- The following circuit makes the decision.
5651 -- Note: our terminology here is that Incl_EP means that the bounds
5652 -- are widened by Small if necessary to include the end points, and
5653 -- Excl_EP means that the bounds are narrowed by Small to exclude the
5654 -- end-points if this reduces the size.
5656 -- Note that in the Incl case, all we care about is including the
5657 -- end-points. In the Excl case, we want to narrow the bounds as
5658 -- much as permitted by the RM, to give the smallest possible size.
5661 Loval_Incl_EP
: Ureal
;
5662 Hival_Incl_EP
: Ureal
;
5664 Loval_Excl_EP
: Ureal
;
5665 Hival_Excl_EP
: Ureal
;
5671 First_Subt
: Entity_Id
;
5676 -- First step. Base types are required to be symmetrical. Right
5677 -- now, the base type range is a copy of the first subtype range.
5678 -- This will be corrected before we are done, but right away we
5679 -- need to deal with the case where both bounds are non-negative.
5680 -- In this case, we set the low bound to the negative of the high
5681 -- bound, to make sure that the size is computed to include the
5682 -- required sign. Note that we do not need to worry about the
5683 -- case of both bounds negative, because the sign will be dealt
5684 -- with anyway. Furthermore we can't just go making such a bound
5685 -- symmetrical, since in a twos-complement system, there is an
5686 -- extra negative value which could not be accommodated on the
5690 and then not UR_Is_Negative
(Loval
)
5691 and then Hival
> Loval
5694 Set_Realval
(Lo
, Loval
);
5697 -- Compute the fudged bounds. If the number is a model number,
5698 -- then we do nothing to include it, but we are allowed to backoff
5699 -- to the next adjacent model number when we exclude it. If it is
5700 -- not a model number then we straddle the two values with the
5701 -- model numbers on either side.
5703 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
5705 if Loval
= Model_Num
then
5706 Loval_Incl_EP
:= Model_Num
;
5708 Loval_Incl_EP
:= Model_Num
- Small
;
5711 -- The low value excluding the end point is Small greater, but
5712 -- we do not do this exclusion if the low value is positive,
5713 -- since it can't help the size and could actually hurt by
5714 -- crossing the high bound.
5716 if UR_Is_Negative
(Loval_Incl_EP
) then
5717 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
5719 -- If the value went from negative to zero, then we have the
5720 -- case where Loval_Incl_EP is the model number just below
5721 -- zero, so we want to stick to the negative value for the
5722 -- base type to maintain the condition that the size will
5723 -- include signed values.
5726 and then UR_Is_Zero
(Loval_Excl_EP
)
5728 Loval_Excl_EP
:= Loval_Incl_EP
;
5732 Loval_Excl_EP
:= Loval_Incl_EP
;
5735 -- Similar processing for upper bound and high value
5737 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
5739 if Hival
= Model_Num
then
5740 Hival_Incl_EP
:= Model_Num
;
5742 Hival_Incl_EP
:= Model_Num
+ Small
;
5745 if UR_Is_Positive
(Hival_Incl_EP
) then
5746 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
5748 Hival_Excl_EP
:= Hival_Incl_EP
;
5751 -- One further adjustment is needed. In the case of subtypes, we
5752 -- cannot go outside the range of the base type, or we get
5753 -- peculiarities, and the base type range is already set. This
5754 -- only applies to the Incl values, since clearly the Excl values
5755 -- are already as restricted as they are allowed to be.
5758 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
5759 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
5762 -- Get size including and excluding end points
5764 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
5765 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
5767 -- No need to exclude end-points if it does not reduce size
5769 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
5770 Loval_Excl_EP
:= Loval_Incl_EP
;
5773 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
5774 Hival_Excl_EP
:= Hival_Incl_EP
;
5777 -- Now we set the actual size to be used. We want to use the
5778 -- bounds fudged up to include the end-points but only if this
5779 -- can be done without violating a specifically given size
5780 -- size clause or causing an unacceptable increase in size.
5782 -- Case of size clause given
5784 if Has_Size_Clause
(Typ
) then
5786 -- Use the inclusive size only if it is consistent with
5787 -- the explicitly specified size.
5789 if Size_Incl_EP
<= RM_Size
(Typ
) then
5790 Actual_Lo
:= Loval_Incl_EP
;
5791 Actual_Hi
:= Hival_Incl_EP
;
5792 Actual_Size
:= Size_Incl_EP
;
5794 -- If the inclusive size is too large, we try excluding
5795 -- the end-points (will be caught later if does not work).
5798 Actual_Lo
:= Loval_Excl_EP
;
5799 Actual_Hi
:= Hival_Excl_EP
;
5800 Actual_Size
:= Size_Excl_EP
;
5803 -- Case of size clause not given
5806 -- If we have a base type whose corresponding first subtype
5807 -- has an explicit size that is large enough to include our
5808 -- end-points, then do so. There is no point in working hard
5809 -- to get a base type whose size is smaller than the specified
5810 -- size of the first subtype.
5812 First_Subt
:= First_Subtype
(Typ
);
5814 if Has_Size_Clause
(First_Subt
)
5815 and then Size_Incl_EP
<= Esize
(First_Subt
)
5817 Actual_Size
:= Size_Incl_EP
;
5818 Actual_Lo
:= Loval_Incl_EP
;
5819 Actual_Hi
:= Hival_Incl_EP
;
5821 -- If excluding the end-points makes the size smaller and
5822 -- results in a size of 8,16,32,64, then we take the smaller
5823 -- size. For the 64 case, this is compulsory. For the other
5824 -- cases, it seems reasonable. We like to include end points
5825 -- if we can, but not at the expense of moving to the next
5826 -- natural boundary of size.
5828 elsif Size_Incl_EP
/= Size_Excl_EP
5829 and then Addressable
(Size_Excl_EP
)
5831 Actual_Size
:= Size_Excl_EP
;
5832 Actual_Lo
:= Loval_Excl_EP
;
5833 Actual_Hi
:= Hival_Excl_EP
;
5835 -- Otherwise we can definitely include the end points
5838 Actual_Size
:= Size_Incl_EP
;
5839 Actual_Lo
:= Loval_Incl_EP
;
5840 Actual_Hi
:= Hival_Incl_EP
;
5843 -- One pathological case: normally we never fudge a low bound
5844 -- down, since it would seem to increase the size (if it has
5845 -- any effect), but for ranges containing single value, or no
5846 -- values, the high bound can be small too large. Consider:
5848 -- type t is delta 2.0**(-14)
5849 -- range 131072.0 .. 0;
5851 -- That lower bound is *just* outside the range of 32 bits, and
5852 -- does need fudging down in this case. Note that the bounds
5853 -- will always have crossed here, since the high bound will be
5854 -- fudged down if necessary, as in the case of:
5856 -- type t is delta 2.0**(-14)
5857 -- range 131072.0 .. 131072.0;
5859 -- So we detect the situation by looking for crossed bounds,
5860 -- and if the bounds are crossed, and the low bound is greater
5861 -- than zero, we will always back it off by small, since this
5862 -- is completely harmless.
5864 if Actual_Lo
> Actual_Hi
then
5865 if UR_Is_Positive
(Actual_Lo
) then
5866 Actual_Lo
:= Loval_Incl_EP
- Small
;
5867 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
5869 -- And of course, we need to do exactly the same parallel
5870 -- fudge for flat ranges in the negative region.
5872 elsif UR_Is_Negative
(Actual_Hi
) then
5873 Actual_Hi
:= Hival_Incl_EP
+ Small
;
5874 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
5879 Set_Realval
(Lo
, Actual_Lo
);
5880 Set_Realval
(Hi
, Actual_Hi
);
5883 -- For the decimal case, none of this fudging is required, since there
5884 -- are no end-point problems in the decimal case (the end-points are
5885 -- always included).
5888 Actual_Size
:= Fsize
(Loval
, Hival
);
5891 -- At this stage, the actual size has been calculated and the proper
5892 -- required bounds are stored in the low and high bounds.
5894 if Actual_Size
> 64 then
5895 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
5897 ("size required (^) for type& too large, maximum allowed is 64",
5902 -- Check size against explicit given size
5904 if Has_Size_Clause
(Typ
) then
5905 if Actual_Size
> RM_Size
(Typ
) then
5906 Error_Msg_Uint_1
:= RM_Size
(Typ
);
5907 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
5909 ("size given (^) for type& too small, minimum allowed is ^",
5910 Size_Clause
(Typ
), Typ
);
5913 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
5916 -- Increase size to next natural boundary if no size clause given
5919 if Actual_Size
<= 8 then
5921 elsif Actual_Size
<= 16 then
5923 elsif Actual_Size
<= 32 then
5929 Init_Esize
(Typ
, Actual_Size
);
5930 Adjust_Esize_For_Alignment
(Typ
);
5933 -- If we have a base type, then expand the bounds so that they extend to
5934 -- the full width of the allocated size in bits, to avoid junk range
5935 -- checks on intermediate computations.
5937 if Base_Type
(Typ
) = Typ
then
5938 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
5939 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
5942 -- Final step is to reanalyze the bounds using the proper type
5943 -- and set the Corresponding_Integer_Value fields of the literals.
5945 Set_Etype
(Lo
, Empty
);
5946 Set_Analyzed
(Lo
, False);
5949 -- Resolve with universal fixed if the base type, and the base type if
5950 -- it is a subtype. Note we can't resolve the base type with itself,
5951 -- that would be a reference before definition.
5954 Resolve
(Lo
, Universal_Fixed
);
5959 -- Set corresponding integer value for bound
5961 Set_Corresponding_Integer_Value
5962 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
5964 -- Similar processing for high bound
5966 Set_Etype
(Hi
, Empty
);
5967 Set_Analyzed
(Hi
, False);
5971 Resolve
(Hi
, Universal_Fixed
);
5976 Set_Corresponding_Integer_Value
5977 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
5979 -- Set type of range to correspond to bounds
5981 Set_Etype
(Rng
, Etype
(Lo
));
5983 -- Set Esize to calculated size if not set already
5985 if Unknown_Esize
(Typ
) then
5986 Init_Esize
(Typ
, Actual_Size
);
5989 -- Set RM_Size if not already set. If already set, check value
5992 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
5995 if RM_Size
(Typ
) /= Uint_0
then
5996 if RM_Size
(Typ
) < Minsiz
then
5997 Error_Msg_Uint_1
:= RM_Size
(Typ
);
5998 Error_Msg_Uint_2
:= Minsiz
;
6000 ("size given (^) for type& too small, minimum allowed is ^",
6001 Size_Clause
(Typ
), Typ
);
6005 Set_RM_Size
(Typ
, Minsiz
);
6008 end Freeze_Fixed_Point_Type
;
6014 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
6018 Set_Has_Delayed_Freeze
(T
);
6019 L
:= Freeze_Entity
(T
, N
);
6021 if Is_Non_Empty_List
(L
) then
6022 Insert_Actions
(N
, L
);
6026 --------------------------
6027 -- Freeze_Static_Object --
6028 --------------------------
6030 procedure Freeze_Static_Object
(E
: Entity_Id
) is
6032 Cannot_Be_Static
: exception;
6033 -- Exception raised if the type of a static object cannot be made
6034 -- static. This happens if the type depends on non-global objects.
6036 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
6037 -- Called to ensure that an expression used as part of a type definition
6038 -- is statically allocatable, which means that the expression type is
6039 -- statically allocatable, and the expression is either static, or a
6040 -- reference to a library level constant.
6042 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
6043 -- Called to mark a type as static, checking that it is possible
6044 -- to set the type as static. If it is not possible, then the
6045 -- exception Cannot_Be_Static is raised.
6047 -----------------------------
6048 -- Ensure_Expression_Is_SA --
6049 -----------------------------
6051 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
6055 Ensure_Type_Is_SA
(Etype
(N
));
6057 if Is_Static_Expression
(N
) then
6060 elsif Nkind
(N
) = N_Identifier
then
6064 and then Ekind
(Ent
) = E_Constant
6065 and then Is_Library_Level_Entity
(Ent
)
6071 raise Cannot_Be_Static
;
6072 end Ensure_Expression_Is_SA
;
6074 -----------------------
6075 -- Ensure_Type_Is_SA --
6076 -----------------------
6078 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
6083 -- If type is library level, we are all set
6085 if Is_Library_Level_Entity
(Typ
) then
6089 -- We are also OK if the type already marked as statically allocated,
6090 -- which means we processed it before.
6092 if Is_Statically_Allocated
(Typ
) then
6096 -- Mark type as statically allocated
6098 Set_Is_Statically_Allocated
(Typ
);
6100 -- Check that it is safe to statically allocate this type
6102 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
6103 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
6104 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
6106 elsif Is_Array_Type
(Typ
) then
6107 N
:= First_Index
(Typ
);
6108 while Present
(N
) loop
6109 Ensure_Type_Is_SA
(Etype
(N
));
6113 Ensure_Type_Is_SA
(Component_Type
(Typ
));
6115 elsif Is_Access_Type
(Typ
) then
6116 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
6120 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
6123 if T
/= Standard_Void_Type
then
6124 Ensure_Type_Is_SA
(T
);
6127 F
:= First_Formal
(Designated_Type
(Typ
));
6128 while Present
(F
) loop
6129 Ensure_Type_Is_SA
(Etype
(F
));
6135 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
6138 elsif Is_Record_Type
(Typ
) then
6139 C
:= First_Entity
(Typ
);
6140 while Present
(C
) loop
6141 if Ekind
(C
) = E_Discriminant
6142 or else Ekind
(C
) = E_Component
6144 Ensure_Type_Is_SA
(Etype
(C
));
6146 elsif Is_Type
(C
) then
6147 Ensure_Type_Is_SA
(C
);
6153 elsif Ekind
(Typ
) = E_Subprogram_Type
then
6154 Ensure_Type_Is_SA
(Etype
(Typ
));
6156 C
:= First_Formal
(Typ
);
6157 while Present
(C
) loop
6158 Ensure_Type_Is_SA
(Etype
(C
));
6163 raise Cannot_Be_Static
;
6165 end Ensure_Type_Is_SA
;
6167 -- Start of processing for Freeze_Static_Object
6170 Ensure_Type_Is_SA
(Etype
(E
));
6173 when Cannot_Be_Static
=>
6175 -- If the object that cannot be static is imported or exported, then
6176 -- issue an error message saying that this object cannot be imported
6177 -- or exported. If it has an address clause it is an overlay in the
6178 -- current partition and the static requirement is not relevant.
6179 -- Do not issue any error message when ignoring rep clauses.
6181 if Ignore_Rep_Clauses
then
6184 elsif Is_Imported
(E
) then
6185 if No
(Address_Clause
(E
)) then
6187 ("& cannot be imported (local type is not constant)", E
);
6190 -- Otherwise must be exported, something is wrong if compiler
6191 -- is marking something as statically allocated which cannot be).
6193 else pragma Assert
(Is_Exported
(E
));
6195 ("& cannot be exported (local type is not constant)", E
);
6197 end Freeze_Static_Object
;
6199 -----------------------
6200 -- Freeze_Subprogram --
6201 -----------------------
6203 procedure Freeze_Subprogram
(E
: Entity_Id
) is
6208 -- Subprogram may not have an address clause unless it is imported
6210 if Present
(Address_Clause
(E
)) then
6211 if not Is_Imported
(E
) then
6213 ("address clause can only be given " &
6214 "for imported subprogram",
6215 Name
(Address_Clause
(E
)));
6219 -- Reset the Pure indication on an imported subprogram unless an
6220 -- explicit Pure_Function pragma was present. We do this because
6221 -- otherwise it is an insidious error to call a non-pure function from
6222 -- pure unit and have calls mysteriously optimized away. What happens
6223 -- here is that the Import can bypass the normal check to ensure that
6224 -- pure units call only pure subprograms.
6227 and then Is_Pure
(E
)
6228 and then not Has_Pragma_Pure_Function
(E
)
6230 Set_Is_Pure
(E
, False);
6233 -- For non-foreign convention subprograms, this is where we create
6234 -- the extra formals (for accessibility level and constrained bit
6235 -- information). We delay this till the freeze point precisely so
6236 -- that we know the convention!
6238 if not Has_Foreign_Convention
(E
) then
6239 Create_Extra_Formals
(E
);
6242 -- If this is convention Ada and a Valued_Procedure, that's odd
6244 if Ekind
(E
) = E_Procedure
6245 and then Is_Valued_Procedure
(E
)
6246 and then Convention
(E
) = Convention_Ada
6247 and then Warn_On_Export_Import
6250 ("??Valued_Procedure has no effect for convention Ada", E
);
6251 Set_Is_Valued_Procedure
(E
, False);
6254 -- Case of foreign convention
6259 -- For foreign conventions, warn about return of an
6260 -- unconstrained array.
6262 -- Note: we *do* allow a return by descriptor for the VMS case,
6263 -- though here there is probably more to be done ???
6265 if Ekind
(E
) = E_Function
then
6266 Retype
:= Underlying_Type
(Etype
(E
));
6268 -- If no return type, probably some other error, e.g. a
6269 -- missing full declaration, so ignore.
6274 -- If the return type is generic, we have emitted a warning
6275 -- earlier on, and there is nothing else to check here. Specific
6276 -- instantiations may lead to erroneous behavior.
6278 elsif Is_Generic_Type
(Etype
(E
)) then
6281 -- Display warning if returning unconstrained array
6283 elsif Is_Array_Type
(Retype
)
6284 and then not Is_Constrained
(Retype
)
6286 -- Exclude cases where descriptor mechanism is set, since the
6287 -- VMS descriptor mechanisms allow such unconstrained returns.
6289 and then Mechanism
(E
) not in Descriptor_Codes
6291 -- Check appropriate warning is enabled (should we check for
6292 -- Warnings (Off) on specific entities here, probably so???)
6294 and then Warn_On_Export_Import
6296 -- Exclude the VM case, since return of unconstrained arrays
6297 -- is properly handled in both the JVM and .NET cases.
6299 and then VM_Target
= No_VM
6302 ("?x?foreign convention function& should not return " &
6303 "unconstrained array", E
);
6308 -- If any of the formals for an exported foreign convention
6309 -- subprogram have defaults, then emit an appropriate warning since
6310 -- this is odd (default cannot be used from non-Ada code)
6312 if Is_Exported
(E
) then
6313 F
:= First_Formal
(E
);
6314 while Present
(F
) loop
6315 if Warn_On_Export_Import
6316 and then Present
(Default_Value
(F
))
6319 ("?x?parameter cannot be defaulted in non-Ada call",
6328 -- For VMS, descriptor mechanisms for parameters are allowed only for
6329 -- imported/exported subprograms. Moreover, the NCA descriptor is not
6330 -- allowed for parameters of exported subprograms.
6332 if OpenVMS_On_Target
then
6333 if Is_Exported
(E
) then
6334 F
:= First_Formal
(E
);
6335 while Present
(F
) loop
6336 if Mechanism
(F
) = By_Descriptor_NCA
then
6338 ("'N'C'A' descriptor for parameter not permitted", F
);
6340 ("\can only be used for imported subprogram", F
);
6346 elsif not Is_Imported
(E
) then
6347 F
:= First_Formal
(E
);
6348 while Present
(F
) loop
6349 if Mechanism
(F
) in Descriptor_Codes
then
6351 ("descriptor mechanism for parameter not permitted", F
);
6353 ("\can only be used for imported/exported subprogram", F
);
6361 -- Pragma Inline_Always is disallowed for dispatching subprograms
6362 -- because the address of such subprograms is saved in the dispatch
6363 -- table to support dispatching calls, and dispatching calls cannot
6364 -- be inlined. This is consistent with the restriction against using
6365 -- 'Access or 'Address on an Inline_Always subprogram.
6367 if Is_Dispatching_Operation
(E
)
6368 and then Has_Pragma_Inline_Always
(E
)
6371 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
6374 -- Because of the implicit representation of inherited predefined
6375 -- operators in the front-end, the overriding status of the operation
6376 -- may be affected when a full view of a type is analyzed, and this is
6377 -- not captured by the analysis of the corresponding type declaration.
6378 -- Therefore the correctness of a not-overriding indicator must be
6379 -- rechecked when the subprogram is frozen.
6381 if Nkind
(E
) = N_Defining_Operator_Symbol
6382 and then not Error_Posted
(Parent
(E
))
6384 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
6386 end Freeze_Subprogram
;
6388 ----------------------
6389 -- Is_Fully_Defined --
6390 ----------------------
6392 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
6394 if Ekind
(T
) = E_Class_Wide_Type
then
6395 return Is_Fully_Defined
(Etype
(T
));
6397 elsif Is_Array_Type
(T
) then
6398 return Is_Fully_Defined
(Component_Type
(T
));
6400 elsif Is_Record_Type
(T
)
6401 and not Is_Private_Type
(T
)
6403 -- Verify that the record type has no components with private types
6404 -- without completion.
6410 Comp
:= First_Component
(T
);
6411 while Present
(Comp
) loop
6412 if not Is_Fully_Defined
(Etype
(Comp
)) then
6416 Next_Component
(Comp
);
6421 -- For the designated type of an access to subprogram, all types in
6422 -- the profile must be fully defined.
6424 elsif Ekind
(T
) = E_Subprogram_Type
then
6429 F
:= First_Formal
(T
);
6430 while Present
(F
) loop
6431 if not Is_Fully_Defined
(Etype
(F
)) then
6438 return Is_Fully_Defined
(Etype
(T
));
6442 return not Is_Private_Type
(T
)
6443 or else Present
(Full_View
(Base_Type
(T
)));
6445 end Is_Fully_Defined
;
6447 ---------------------------------
6448 -- Process_Default_Expressions --
6449 ---------------------------------
6451 procedure Process_Default_Expressions
6453 After
: in out Node_Id
)
6455 Loc
: constant Source_Ptr
:= Sloc
(E
);
6462 Set_Default_Expressions_Processed
(E
);
6464 -- A subprogram instance and its associated anonymous subprogram share
6465 -- their signature. The default expression functions are defined in the
6466 -- wrapper packages for the anonymous subprogram, and should not be
6467 -- generated again for the instance.
6469 if Is_Generic_Instance
(E
)
6470 and then Present
(Alias
(E
))
6471 and then Default_Expressions_Processed
(Alias
(E
))
6476 Formal
:= First_Formal
(E
);
6477 while Present
(Formal
) loop
6478 if Present
(Default_Value
(Formal
)) then
6480 -- We work with a copy of the default expression because we
6481 -- do not want to disturb the original, since this would mess
6482 -- up the conformance checking.
6484 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
6486 -- The analysis of the expression may generate insert actions,
6487 -- which of course must not be executed. We wrap those actions
6488 -- in a procedure that is not called, and later on eliminated.
6489 -- The following cases have no side-effects, and are analyzed
6492 if Nkind
(Dcopy
) = N_Identifier
6493 or else Nkind
(Dcopy
) = N_Expanded_Name
6494 or else Nkind
(Dcopy
) = N_Integer_Literal
6495 or else (Nkind
(Dcopy
) = N_Real_Literal
6496 and then not Vax_Float
(Etype
(Dcopy
)))
6497 or else Nkind
(Dcopy
) = N_Character_Literal
6498 or else Nkind
(Dcopy
) = N_String_Literal
6499 or else Known_Null
(Dcopy
)
6500 or else (Nkind
(Dcopy
) = N_Attribute_Reference
6502 Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
6505 -- If there is no default function, we must still do a full
6506 -- analyze call on the default value, to ensure that all error
6507 -- checks are performed, e.g. those associated with static
6508 -- evaluation. Note: this branch will always be taken if the
6509 -- analyzer is turned off (but we still need the error checks).
6511 -- Note: the setting of parent here is to meet the requirement
6512 -- that we can only analyze the expression while attached to
6513 -- the tree. Really the requirement is that the parent chain
6514 -- be set, we don't actually need to be in the tree.
6516 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
6519 -- Default expressions are resolved with their own type if the
6520 -- context is generic, to avoid anomalies with private types.
6522 if Ekind
(Scope
(E
)) = E_Generic_Package
then
6525 Resolve
(Dcopy
, Etype
(Formal
));
6528 -- If that resolved expression will raise constraint error,
6529 -- then flag the default value as raising constraint error.
6530 -- This allows a proper error message on the calls.
6532 if Raises_Constraint_Error
(Dcopy
) then
6533 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
6536 -- If the default is a parameterless call, we use the name of
6537 -- the called function directly, and there is no body to build.
6539 elsif Nkind
(Dcopy
) = N_Function_Call
6540 and then No
(Parameter_Associations
(Dcopy
))
6544 -- Else construct and analyze the body of a wrapper procedure
6545 -- that contains an object declaration to hold the expression.
6546 -- Given that this is done only to complete the analysis, it
6547 -- simpler to build a procedure than a function which might
6548 -- involve secondary stack expansion.
6551 Dnam
:= Make_Temporary
(Loc
, 'D');
6554 Make_Subprogram_Body
(Loc
,
6556 Make_Procedure_Specification
(Loc
,
6557 Defining_Unit_Name
=> Dnam
),
6559 Declarations
=> New_List
(
6560 Make_Object_Declaration
(Loc
,
6561 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
6562 Object_Definition
=>
6563 New_Occurrence_Of
(Etype
(Formal
), Loc
),
6564 Expression
=> New_Copy_Tree
(Dcopy
))),
6566 Handled_Statement_Sequence
=>
6567 Make_Handled_Sequence_Of_Statements
(Loc
,
6568 Statements
=> Empty_List
));
6570 Set_Scope
(Dnam
, Scope
(E
));
6571 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
6572 Set_Is_Eliminated
(Dnam
);
6573 Insert_After
(After
, Dbody
);
6579 Next_Formal
(Formal
);
6581 end Process_Default_Expressions
;
6583 ----------------------------------------
6584 -- Set_Component_Alignment_If_Not_Set --
6585 ----------------------------------------
6587 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
6589 -- Ignore if not base type, subtypes don't need anything
6591 if Typ
/= Base_Type
(Typ
) then
6595 -- Do not override existing representation
6597 if Is_Packed
(Typ
) then
6600 elsif Has_Specified_Layout
(Typ
) then
6603 elsif Component_Alignment
(Typ
) /= Calign_Default
then
6607 Set_Component_Alignment
6608 (Typ
, Scope_Stack
.Table
6609 (Scope_Stack
.Last
).Component_Alignment_Default
);
6611 end Set_Component_Alignment_If_Not_Set
;
6617 procedure Undelay_Type
(T
: Entity_Id
) is
6619 Set_Has_Delayed_Freeze
(T
, False);
6620 Set_Freeze_Node
(T
, Empty
);
6622 -- Since we don't want T to have a Freeze_Node, we don't want its
6623 -- Full_View or Corresponding_Record_Type to have one either.
6625 -- ??? Fundamentally, this whole handling is a kludge. What we really
6626 -- want is to be sure that for an Itype that's part of record R and is a
6627 -- subtype of type T, that it's frozen after the later of the freeze
6628 -- points of R and T. We have no way of doing that directly, so what we
6629 -- do is force most such Itypes to be frozen as part of freezing R via
6630 -- this procedure and only delay the ones that need to be delayed
6631 -- (mostly the designated types of access types that are defined as part
6634 if Is_Private_Type
(T
)
6635 and then Present
(Full_View
(T
))
6636 and then Is_Itype
(Full_View
(T
))
6637 and then Is_Record_Type
(Scope
(Full_View
(T
)))
6639 Undelay_Type
(Full_View
(T
));
6642 if Is_Concurrent_Type
(T
)
6643 and then Present
(Corresponding_Record_Type
(T
))
6644 and then Is_Itype
(Corresponding_Record_Type
(T
))
6645 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
6647 Undelay_Type
(Corresponding_Record_Type
(T
));
6655 procedure Warn_Overlay
6660 Ent
: constant Entity_Id
:= Entity
(Nam
);
6661 -- The object to which the address clause applies
6664 Old
: Entity_Id
:= Empty
;
6668 -- No warning if address clause overlay warnings are off
6670 if not Address_Clause_Overlay_Warnings
then
6674 -- No warning if there is an explicit initialization
6676 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
6678 if Present
(Init
) and then Comes_From_Source
(Init
) then
6682 -- We only give the warning for non-imported entities of a type for
6683 -- which a non-null base init proc is defined, or for objects of access
6684 -- types with implicit null initialization, or when Normalize_Scalars
6685 -- applies and the type is scalar or a string type (the latter being
6686 -- tested for because predefined String types are initialized by inline
6687 -- code rather than by an init_proc). Note that we do not give the
6688 -- warning for Initialize_Scalars, since we suppressed initialization
6689 -- in this case. Also, do not warn if Suppress_Initialization is set.
6692 and then not Is_Imported
(Ent
)
6693 and then not Initialization_Suppressed
(Typ
)
6694 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
6695 or else Is_Access_Type
(Typ
)
6696 or else (Normalize_Scalars
6697 and then (Is_Scalar_Type
(Typ
)
6698 or else Is_String_Type
(Typ
))))
6700 if Nkind
(Expr
) = N_Attribute_Reference
6701 and then Is_Entity_Name
(Prefix
(Expr
))
6703 Old
:= Entity
(Prefix
(Expr
));
6705 elsif Is_Entity_Name
(Expr
)
6706 and then Ekind
(Entity
(Expr
)) = E_Constant
6708 Decl
:= Declaration_Node
(Entity
(Expr
));
6710 if Nkind
(Decl
) = N_Object_Declaration
6711 and then Present
(Expression
(Decl
))
6712 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
6713 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
6715 Old
:= Entity
(Prefix
(Expression
(Decl
)));
6717 elsif Nkind
(Expr
) = N_Function_Call
then
6721 -- A function call (most likely to To_Address) is probably not an
6722 -- overlay, so skip warning. Ditto if the function call was inlined
6723 -- and transformed into an entity.
6725 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
6729 Decl
:= Next
(Parent
(Expr
));
6731 -- If a pragma Import follows, we assume that it is for the current
6732 -- target of the address clause, and skip the warning.
6735 and then Nkind
(Decl
) = N_Pragma
6736 and then Pragma_Name
(Decl
) = Name_Import
6741 if Present
(Old
) then
6742 Error_Msg_Node_2
:= Old
;
6744 ("default initialization of & may modify &??",
6748 ("default initialization of & may modify overlaid storage??",
6752 -- Add friendly warning if initialization comes from a packed array
6755 if Is_Record_Type
(Typ
) then
6760 Comp
:= First_Component
(Typ
);
6761 while Present
(Comp
) loop
6762 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
6763 and then Present
(Expression
(Parent
(Comp
)))
6766 elsif Is_Array_Type
(Etype
(Comp
))
6767 and then Present
(Packed_Array_Type
(Etype
(Comp
)))
6770 ("\packed array component& " &
6771 "will be initialized to zero??",
6775 Next_Component
(Comp
);
6782 ("\use pragma Import for & to " &
6783 "suppress initialization (RM B.1(24))??",