1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- Extensive contributions were provided by Ada Core Technologies Inc. --
27 ------------------------------------------------------------------------------
29 with Atree
; use Atree
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Exp_Ch7
; use Exp_Ch7
;
35 with Exp_Ch11
; use Exp_Ch11
;
36 with Exp_Pakd
; use Exp_Pakd
;
37 with Exp_Util
; use Exp_Util
;
38 with Layout
; use Layout
;
39 with Nlists
; use Nlists
;
40 with Nmake
; use Nmake
;
42 with Restrict
; use Restrict
;
44 with Sem_Cat
; use Sem_Cat
;
45 with Sem_Ch6
; use Sem_Ch6
;
46 with Sem_Ch7
; use Sem_Ch7
;
47 with Sem_Ch8
; use Sem_Ch8
;
48 with Sem_Ch13
; use Sem_Ch13
;
49 with Sem_Eval
; use Sem_Eval
;
50 with Sem_Mech
; use Sem_Mech
;
51 with Sem_Prag
; use Sem_Prag
;
52 with Sem_Res
; use Sem_Res
;
53 with Sem_Util
; use Sem_Util
;
54 with Sinfo
; use Sinfo
;
55 with Snames
; use Snames
;
56 with Stand
; use Stand
;
57 with Targparm
; use Targparm
;
58 with Tbuild
; use Tbuild
;
59 with Ttypes
; use Ttypes
;
60 with Uintp
; use Uintp
;
61 with Urealp
; use Urealp
;
63 package body Freeze
is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
70 -- Typ is a type that is being frozen. If no size clause is given,
71 -- but a default Esize has been computed, then this default Esize is
72 -- adjusted up if necessary to be consistent with a given alignment,
73 -- but never to a value greater than Long_Long_Integer'Size. This
74 -- is used for all discrete types and for fixed-point types.
76 procedure Build_And_Analyze_Renamed_Body
79 After
: in out Node_Id
);
80 -- Build body for a renaming declaration, insert in tree and analyze.
82 procedure Check_Strict_Alignment
(E
: Entity_Id
);
83 -- E is a base type. If E is tagged or has a component that is aliased
84 -- or tagged or contains something this is aliased or tagged, set
87 procedure Check_Unsigned_Type
(E
: Entity_Id
);
88 pragma Inline
(Check_Unsigned_Type
);
89 -- If E is a fixed-point or discrete type, then all the necessary work
90 -- to freeze it is completed except for possible setting of the flag
91 -- Is_Unsigned_Type, which is done by this procedure. The call has no
92 -- effect if the entity E is not a discrete or fixed-point type.
94 procedure Freeze_And_Append
97 Result
: in out List_Id
);
98 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
99 -- nodes to Result, modifying Result from No_List if necessary.
101 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
102 -- Freeze enumeration type. The Esize field is set as processing
103 -- proceeds (i.e. set by default when the type is declared and then
104 -- adjusted by rep clauses. What this procedure does is to make sure
105 -- that if a foreign convention is specified, and no specific size
106 -- is given, then the size must be at least Integer'Size.
108 procedure Freeze_Static_Object
(E
: Entity_Id
);
109 -- If an object is frozen which has Is_Statically_Allocated set, then
110 -- all referenced types must also be marked with this flag. This routine
111 -- is in charge of meeting this requirement for the object entity E.
113 procedure Freeze_Subprogram
(E
: Entity_Id
);
114 -- Perform freezing actions for a subprogram (create extra formals,
115 -- and set proper default mechanism values). Note that this routine
116 -- is not called for internal subprograms, for which neither of these
117 -- actions is needed (or desirable, we do not want for example to have
118 -- these extra formals present in initialization procedures, where they
119 -- would serve no purpose). In this call E is either a subprogram or
120 -- a subprogram type (i.e. an access to a subprogram).
122 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
123 -- true if T is not private, or has a full view.
125 procedure Process_Default_Expressions
127 After
: in out Node_Id
);
128 -- This procedure is called for each subprogram to complete processing
129 -- of default expressions at the point where all types are known to be
130 -- frozen. The expressions must be analyzed in full, to make sure that
131 -- all error processing is done (they have only been pre-analyzed). If
132 -- the expression is not an entity or literal, its analysis may generate
133 -- code which must not be executed. In that case we build a function
134 -- body to hold that code. This wrapper function serves no other purpose
135 -- (it used to be called to evaluate the default, but now the default is
136 -- inlined at each point of call).
138 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
139 -- Typ is a record or array type that is being frozen. This routine
140 -- sets the default component alignment from the scope stack values
141 -- if the alignment is otherwise not specified.
143 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
144 -- As each entity is frozen, this routine is called to deal with the
145 -- setting of Debug_Info_Needed for the entity. This flag is set if
146 -- the entity comes from source, or if we are in Debug_Generated_Code
147 -- mode or if the -gnatdV debug flag is set. However, it never sets
148 -- the flag if Debug_Info_Off is set.
150 procedure Set_Debug_Info_Needed
(T
: Entity_Id
);
151 -- Sets the Debug_Info_Needed flag on entity T if not already set, and
152 -- also on any entities that are needed by T (for an object, the type
153 -- of the object is needed, and for a type, the subsidiary types are
154 -- needed -- see body for details). Never has any effect on T if the
155 -- Debug_Info_Off flag is set.
157 -------------------------------
158 -- Adjust_Esize_For_Alignment --
159 -------------------------------
161 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
165 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
166 Align
:= Alignment_In_Bits
(Typ
);
168 if Align
> Esize
(Typ
)
169 and then Align
<= Standard_Long_Long_Integer_Size
171 Set_Esize
(Typ
, Align
);
174 end Adjust_Esize_For_Alignment
;
176 ------------------------------------
177 -- Build_And_Analyze_Renamed_Body --
178 ------------------------------------
180 procedure Build_And_Analyze_Renamed_Body
183 After
: in out Node_Id
)
185 Body_Node
: constant Node_Id
:= Build_Renamed_Body
(Decl
, New_S
);
188 Insert_After
(After
, Body_Node
);
189 Mark_Rewrite_Insertion
(Body_Node
);
192 end Build_And_Analyze_Renamed_Body
;
194 ------------------------
195 -- Build_Renamed_Body --
196 ------------------------
198 function Build_Renamed_Body
203 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
204 -- We use for the source location of the renamed body, the location
205 -- of the spec entity. It might seem more natural to use the location
206 -- of the renaming declaration itself, but that would be wrong, since
207 -- then the body we create would look as though it was created far
208 -- too late, and this could cause problems with elaboration order
209 -- analysis, particularly in connection with instantiations.
211 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
212 Nam
: constant Node_Id
:= Name
(N
);
214 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
215 Actuals
: List_Id
:= No_List
;
220 O_Formal
: Entity_Id
;
221 Param_Spec
: Node_Id
;
224 -- Determine the entity being renamed, which is the target of the
225 -- call statement. If the name is an explicit dereference, this is
226 -- a renaming of a subprogram type rather than a subprogram. The
227 -- name itself is fully analyzed.
229 if Nkind
(Nam
) = N_Selected_Component
then
230 Old_S
:= Entity
(Selector_Name
(Nam
));
232 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
233 Old_S
:= Etype
(Nam
);
235 elsif Nkind
(Nam
) = N_Indexed_Component
then
237 if Is_Entity_Name
(Prefix
(Nam
)) then
238 Old_S
:= Entity
(Prefix
(Nam
));
240 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
243 elsif Nkind
(Nam
) = N_Character_Literal
then
244 Old_S
:= Etype
(New_S
);
247 Old_S
:= Entity
(Nam
);
250 if Is_Entity_Name
(Nam
) then
251 Call_Name
:= New_Reference_To
(Old_S
, Loc
);
253 Call_Name
:= New_Copy
(Name
(N
));
255 -- The original name may have been overloaded, but
256 -- is fully resolved now.
258 Set_Is_Overloaded
(Call_Name
, False);
261 -- For simple renamings, subsequent calls can be expanded directly
262 -- as called to the renamed entity. The body must be generated in
263 -- any case for calls they may appear elsewhere.
265 if (Ekind
(Old_S
) = E_Function
266 or else Ekind
(Old_S
) = E_Procedure
)
267 and then Nkind
(Decl
) = N_Subprogram_Declaration
269 Set_Body_To_Inline
(Decl
, Old_S
);
272 -- The body generated for this renaming is an internal artifact, and
273 -- does not constitute a freeze point for the called entity.
275 Set_Must_Not_Freeze
(Call_Name
);
277 Formal
:= First_Formal
(Defining_Entity
(Decl
));
279 if Present
(Formal
) then
282 while Present
(Formal
) loop
283 Append
(New_Reference_To
(Formal
, Loc
), Actuals
);
284 Next_Formal
(Formal
);
288 -- If the renamed entity is an entry, inherit its profile. For
289 -- other renamings as bodies, both profiles must be subtype
290 -- conformant, so it is not necessary to replace the profile given
291 -- in the declaration. However, default values that are aggregates
292 -- are rewritten when partially analyzed, so we recover the original
293 -- aggregate to insure that subsequent conformity checking works.
295 Formal
:= First_Formal
(Defining_Entity
(Decl
));
297 if Present
(Formal
) then
298 O_Formal
:= First_Formal
(Old_S
);
299 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
301 while Present
(Formal
) loop
302 if Is_Entry
(Old_S
) then
304 if Nkind
(Parameter_Type
(Param_Spec
)) /=
307 Set_Etype
(Formal
, Etype
(O_Formal
));
308 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
311 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
then
312 Set_Expression
(Param_Spec
,
313 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
316 Next_Formal
(Formal
);
317 Next_Formal
(O_Formal
);
322 -- If the renamed entity is a function, the generated body contains a
323 -- return statement. Otherwise, build a procedure call. If the entity is
324 -- an entry, subsequent analysis of the call will transform it into the
325 -- proper entry or protected operation call. If the renamed entity is
326 -- a character literal, return it directly.
328 if Ekind
(Old_S
) = E_Function
329 or else Ekind
(Old_S
) = E_Operator
330 or else (Ekind
(Old_S
) = E_Subprogram_Type
331 and then Etype
(Old_S
) /= Standard_Void_Type
)
334 Make_Return_Statement
(Loc
,
336 Make_Function_Call
(Loc
,
338 Parameter_Associations
=> Actuals
));
340 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
342 Make_Return_Statement
(Loc
,
343 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
345 elsif Nkind
(Nam
) = N_Character_Literal
then
347 Make_Return_Statement
(Loc
,
348 Expression
=> Call_Name
);
352 Make_Procedure_Call_Statement
(Loc
,
354 Parameter_Associations
=> Actuals
);
357 -- Create entities for subprogram body and formals.
359 Set_Defining_Unit_Name
(Spec
,
360 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
362 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
364 while Present
(Param_Spec
) loop
365 Set_Defining_Identifier
(Param_Spec
,
366 Make_Defining_Identifier
(Loc
,
367 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
372 Make_Subprogram_Body
(Loc
,
373 Specification
=> Spec
,
374 Declarations
=> New_List
,
375 Handled_Statement_Sequence
=>
376 Make_Handled_Sequence_Of_Statements
(Loc
,
377 Statements
=> New_List
(Call_Node
)));
379 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
381 Make_Subprogram_Declaration
(Loc
,
382 Specification
=> Specification
(N
)));
385 -- Link the body to the entity whose declaration it completes. If
386 -- the body is analyzed when the renamed entity is frozen, it may be
387 -- necessary to restore the proper scope (see package Exp_Ch13).
389 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
390 and then Present
(Corresponding_Spec
(N
))
392 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
394 Set_Corresponding_Spec
(Body_Node
, New_S
);
398 end Build_Renamed_Body
;
400 -----------------------------
401 -- Check_Compile_Time_Size --
402 -----------------------------
404 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
406 procedure Set_Small_Size
(S
: Uint
);
407 -- Sets the compile time known size (32 bits or less) in the Esize
408 -- field, checking for a size clause that was given which attempts
409 -- to give a smaller size.
411 function Size_Known
(T
: Entity_Id
) return Boolean;
412 -- Recursive function that does all the work.
413 -- Is this right??? isn't recursive case already handled???
414 -- certainly yes for normal call, but what about bogus sem_res call???
416 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
417 -- If T is a constrained subtype, its size is not known if any of its
418 -- discriminant constraints is not static and it is not a null record.
419 -- The test is conservative and doesn't check that the components are
420 -- in fact constrained by non-static discriminant values. Could be made
427 procedure Set_Small_Size
(S
: Uint
) is
432 elsif Has_Size_Clause
(T
) then
433 if RM_Size
(T
) < S
then
434 Error_Msg_Uint_1
:= S
;
436 ("size for & is too small, minimum is ^",
439 elsif Unknown_Esize
(T
) then
443 -- Set sizes if not set already
446 if Unknown_Esize
(T
) then
450 if Unknown_RM_Size
(T
) then
460 function Size_Known
(T
: Entity_Id
) return Boolean is
468 if Size_Known_At_Compile_Time
(T
) then
471 elsif Error_Posted
(T
) then
474 elsif Is_Scalar_Type
(T
)
475 or else Is_Task_Type
(T
)
477 return not Is_Generic_Type
(T
);
479 elsif Is_Array_Type
(T
) then
481 if Ekind
(T
) = E_String_Literal_Subtype
then
482 Set_Small_Size
(Component_Size
(T
) * String_Literal_Length
(T
));
485 elsif not Is_Constrained
(T
) then
488 elsif not Size_Known
(Component_Type
(T
)) then
492 -- Check for all indexes static, and also compute possible
493 -- size (in case it is less than 32 and may be packable).
496 Esiz
: Uint
:= Component_Size
(T
);
500 Index
:= First_Index
(T
);
502 while Present
(Index
) loop
503 if Nkind
(Index
) = N_Range
then
504 Get_Index_Bounds
(Index
, Low
, High
);
506 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
510 Low
:= Type_Low_Bound
(Etype
(Index
));
511 High
:= Type_High_Bound
(Etype
(Index
));
514 if not Compile_Time_Known_Value
(Low
)
515 or else not Compile_Time_Known_Value
(High
)
516 or else Etype
(Index
) = Any_Type
521 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
533 Set_Small_Size
(Esiz
);
537 elsif Is_Access_Type
(T
) then
540 elsif Is_Private_Type
(T
)
541 and then not Is_Generic_Type
(T
)
542 and then Present
(Underlying_Type
(T
))
544 return Size_Known
(Underlying_Type
(T
));
546 elsif Is_Record_Type
(T
) then
547 if Is_Class_Wide_Type
(T
) then
550 elsif T
/= Base_Type
(T
) then
551 return Size_Known_At_Compile_Time
(Base_Type
(T
))
552 and then Static_Discriminated_Components
(T
);
556 Packed_Size_Known
: Boolean := Is_Packed
(T
);
557 Packed_Size
: Uint
:= Uint_0
;
560 -- Test for variant part present
562 if Has_Discriminants
(T
)
563 and then Present
(Parent
(T
))
564 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
565 and then Nkind
(Type_Definition
(Parent
(T
))) =
567 and then not Null_Present
(Type_Definition
(Parent
(T
)))
568 and then Present
(Variant_Part
569 (Component_List
(Type_Definition
(Parent
(T
)))))
571 -- If variant part is present, and type is unconstrained,
572 -- then we must have defaulted discriminants, or a size
573 -- clause must be present for the type, or else the size
574 -- is definitely not known at compile time.
576 if not Is_Constrained
(T
)
578 No
(Discriminant_Default_Value
579 (First_Discriminant
(T
)))
580 and then Unknown_Esize
(T
)
584 -- We do not know the packed size, it is too much
585 -- trouble to figure it out.
587 Packed_Size_Known
:= False;
591 Comp
:= First_Entity
(T
);
593 while Present
(Comp
) loop
594 if Ekind
(Comp
) = E_Component
596 Ekind
(Comp
) = E_Discriminant
598 Ctyp
:= Etype
(Comp
);
600 if Present
(Component_Clause
(Comp
)) then
601 Packed_Size_Known
:= False;
604 if not Size_Known
(Ctyp
) then
607 elsif Packed_Size_Known
then
609 -- If RM_Size is known and static, then we can
610 -- keep accumulating the packed size.
612 if Known_Static_RM_Size
(Ctyp
) then
614 -- A little glitch, to be removed sometime ???
615 -- gigi does not understand zero sizes yet.
617 if RM_Size
(Ctyp
) = Uint_0
then
618 Packed_Size_Known
:= False;
622 Packed_Size
+ RM_Size
(Ctyp
);
624 -- If we have a field whose RM_Size is not known
625 -- then we can't figure out the packed size here.
628 Packed_Size_Known
:= False;
636 if Packed_Size_Known
then
637 Set_Small_Size
(Packed_Size
);
649 -------------------------------------
650 -- Static_Discriminated_Components --
651 -------------------------------------
653 function Static_Discriminated_Components
657 Constraint
: Elmt_Id
;
660 if Has_Discriminants
(T
)
661 and then Present
(Discriminant_Constraint
(T
))
662 and then Present
(First_Component
(T
))
664 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
666 while Present
(Constraint
) loop
667 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
671 Next_Elmt
(Constraint
);
676 end Static_Discriminated_Components
;
678 -- Start of processing for Check_Compile_Time_Size
681 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
682 end Check_Compile_Time_Size
;
684 -----------------------------
685 -- Check_Debug_Info_Needed --
686 -----------------------------
688 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
690 if Needs_Debug_Info
(T
) or else Debug_Info_Off
(T
) then
693 elsif Comes_From_Source
(T
)
694 or else Debug_Generated_Code
695 or else Debug_Flag_VV
697 Set_Debug_Info_Needed
(T
);
699 end Check_Debug_Info_Needed
;
701 ----------------------------
702 -- Check_Strict_Alignment --
703 ----------------------------
705 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
709 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
710 Set_Strict_Alignment
(E
);
712 elsif Is_Array_Type
(E
) then
713 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
715 elsif Is_Record_Type
(E
) then
716 if Is_Limited_Record
(E
) then
717 Set_Strict_Alignment
(E
);
721 Comp
:= First_Component
(E
);
723 while Present
(Comp
) loop
724 if not Is_Type
(Comp
)
725 and then (Strict_Alignment
(Etype
(Comp
))
726 or else Is_Aliased
(Comp
))
728 Set_Strict_Alignment
(E
);
732 Next_Component
(Comp
);
735 end Check_Strict_Alignment
;
737 -------------------------
738 -- Check_Unsigned_Type --
739 -------------------------
741 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
742 Ancestor
: Entity_Id
;
747 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
751 -- Do not attempt to analyze case where range was in error
753 if Error_Posted
(Scalar_Range
(E
)) then
757 -- The situation that is non trivial is something like
759 -- subtype x1 is integer range -10 .. +10;
760 -- subtype x2 is x1 range 0 .. V1;
761 -- subtype x3 is x2 range V2 .. V3;
762 -- subtype x4 is x3 range V4 .. V5;
764 -- where Vn are variables. Here the base type is signed, but we still
765 -- know that x4 is unsigned because of the lower bound of x2.
767 -- The only way to deal with this is to look up the ancestor chain
771 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
775 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
777 if Compile_Time_Known_Value
(Lo_Bound
) then
779 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
780 Set_Is_Unsigned_Type
(E
, True);
786 Ancestor
:= Ancestor_Subtype
(Ancestor
);
788 -- If no ancestor had a static lower bound, go to base type
790 if No
(Ancestor
) then
792 -- Note: the reason we still check for a compile time known
793 -- value for the base type is that at least in the case of
794 -- generic formals, we can have bounds that fail this test,
795 -- and there may be other cases in error situations.
797 Btyp
:= Base_Type
(E
);
799 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
803 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
805 if Compile_Time_Known_Value
(Lo_Bound
)
806 and then Expr_Rep_Value
(Lo_Bound
) >= 0
808 Set_Is_Unsigned_Type
(E
, True);
816 end Check_Unsigned_Type
;
822 -- Note: the easy coding for this procedure would be to just build a
823 -- single list of freeze nodes and then insert them and analyze them
824 -- all at once. This won't work, because the analysis of earlier freeze
825 -- nodes may recursively freeze types which would otherwise appear later
826 -- on in the freeze list. So we must analyze and expand the freeze nodes
827 -- as they are generated.
829 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
830 Loc
: constant Source_Ptr
:= Sloc
(After
);
834 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
835 -- This is the internal recursive routine that does freezing of
836 -- entities (but NOT the analysis of default expressions, which
837 -- should not be recursive, we don't want to analyze those till
838 -- we are sure that ALL the types are frozen).
840 procedure Freeze_All_Ent
842 After
: in out Node_Id
)
848 procedure Process_Flist
;
849 -- If freeze nodes are present, insert and analyze, and reset
850 -- cursor for next insertion.
852 procedure Process_Flist
is
854 if Is_Non_Empty_List
(Flist
) then
855 Lastn
:= Next
(After
);
856 Insert_List_After_And_Analyze
(After
, Flist
);
858 if Present
(Lastn
) then
859 After
:= Prev
(Lastn
);
861 After
:= Last
(List_Containing
(After
));
868 while Present
(E
) loop
870 -- If the entity is an inner package which is not a package
871 -- renaming, then its entities must be frozen at this point.
872 -- Note that such entities do NOT get frozen at the end of
873 -- the nested package itself (only library packages freeze).
875 -- Same is true for task declarations, where anonymous records
876 -- created for entry parameters must be frozen.
878 if Ekind
(E
) = E_Package
879 and then No
(Renamed_Object
(E
))
880 and then not Is_Child_Unit
(E
)
881 and then not Is_Frozen
(E
)
884 Install_Visible_Declarations
(E
);
885 Install_Private_Declarations
(E
);
887 Freeze_All
(First_Entity
(E
), After
);
889 End_Package_Scope
(E
);
891 elsif Ekind
(E
) in Task_Kind
893 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
895 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
898 Freeze_All
(First_Entity
(E
), After
);
901 -- For a derived tagged type, we must ensure that all the
902 -- primitive operations of the parent have been frozen, so
903 -- that their addresses will be in the parent's dispatch table
904 -- at the point it is inherited.
906 elsif Ekind
(E
) = E_Record_Type
907 and then Is_Tagged_Type
(E
)
908 and then Is_Tagged_Type
(Etype
(E
))
909 and then Is_Derived_Type
(E
)
912 Prim_List
: constant Elist_Id
:=
913 Primitive_Operations
(Etype
(E
));
918 Prim
:= First_Elmt
(Prim_List
);
920 while Present
(Prim
) loop
923 if Comes_From_Source
(Subp
)
924 and then not Is_Frozen
(Subp
)
926 Flist
:= Freeze_Entity
(Subp
, Loc
);
935 if not Is_Frozen
(E
) then
936 Flist
:= Freeze_Entity
(E
, Loc
);
944 -- Start of processing for Freeze_All
947 Freeze_All_Ent
(From
, After
);
949 -- Now that all types are frozen, we can deal with default expressions
950 -- that require us to build a default expression functions. This is the
951 -- point at which such functions are constructed (after all types that
952 -- might be used in such expressions have been frozen).
953 -- We also add finalization chains to access types whose designated
954 -- types are controlled. This is normally done when freezing the type,
955 -- but this misses recursive type definitions where the later members
956 -- of the recursion introduce controlled components (e.g. 5624-001).
958 -- Loop through entities
961 while Present
(E
) loop
963 if Is_Subprogram
(E
) then
965 if not Default_Expressions_Processed
(E
) then
966 Process_Default_Expressions
(E
, After
);
969 if not Has_Completion
(E
) then
970 Decl
:= Unit_Declaration_Node
(E
);
972 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
973 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
975 elsif Nkind
(Decl
) = N_Subprogram_Declaration
976 and then Present
(Corresponding_Body
(Decl
))
978 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
979 = N_Subprogram_Renaming_Declaration
981 Build_And_Analyze_Renamed_Body
982 (Decl
, Corresponding_Body
(Decl
), After
);
986 elsif Ekind
(E
) in Task_Kind
988 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
990 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
996 Ent
:= First_Entity
(E
);
998 while Present
(Ent
) loop
1001 and then not Default_Expressions_Processed
(Ent
)
1003 Process_Default_Expressions
(Ent
, After
);
1010 elsif Is_Access_Type
(E
)
1011 and then Comes_From_Source
(E
)
1012 and then Ekind
(Directly_Designated_Type
(E
)) = E_Incomplete_Type
1013 and then Controlled_Type
(Designated_Type
(E
))
1014 and then No
(Associated_Final_Chain
(E
))
1016 Build_Final_List
(Parent
(E
), E
);
1024 -----------------------
1025 -- Freeze_And_Append --
1026 -----------------------
1028 procedure Freeze_And_Append
1031 Result
: in out List_Id
)
1033 L
: constant List_Id
:= Freeze_Entity
(Ent
, Loc
);
1036 if Is_Non_Empty_List
(L
) then
1037 if Result
= No_List
then
1040 Append_List
(L
, Result
);
1043 end Freeze_And_Append
;
1049 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1050 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, Sloc
(N
));
1054 if Is_Non_Empty_List
(Freeze_Nodes
) then
1055 F
:= First
(Freeze_Nodes
);
1058 Insert_Actions
(N
, Freeze_Nodes
);
1067 function Freeze_Entity
(E
: Entity_Id
; Loc
: Source_Ptr
) return List_Id
is
1075 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1076 -- Check that an Access or Unchecked_Access attribute with
1077 -- a prefix which is the current instance type can only be
1078 -- applied when the type is limited.
1080 function After_Last_Declaration
return Boolean;
1081 -- If Loc is a freeze_entity that appears after the last declaration
1082 -- in the scope, inhibit error messages on late completion.
1084 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1085 -- Freeze each component, handle some representation clauses, and
1086 -- freeze primitive operations if this is a tagged type.
1088 ----------------------------
1089 -- After_Last_Declaration --
1090 ----------------------------
1092 function After_Last_Declaration
return Boolean is
1093 Spec
: Node_Id
:= Parent
(Current_Scope
);
1096 if Nkind
(Spec
) = N_Package_Specification
then
1097 if Present
(Private_Declarations
(Spec
)) then
1098 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1100 elsif Present
(Visible_Declarations
(Spec
)) then
1101 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1109 end After_Last_Declaration
;
1111 ----------------------------
1112 -- Check_Current_Instance --
1113 ----------------------------
1115 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1117 function Process
(N
: Node_Id
) return Traverse_Result
;
1118 -- Process routine to apply check to given node.
1120 function Process
(N
: Node_Id
) return Traverse_Result
is
1123 when N_Attribute_Reference
=>
1124 if (Attribute_Name
(N
) = Name_Access
1126 Attribute_Name
(N
) = Name_Unchecked_Access
)
1127 and then Is_Entity_Name
(Prefix
(N
))
1128 and then Is_Type
(Entity
(Prefix
(N
)))
1129 and then Entity
(Prefix
(N
)) = E
1132 ("current instance must be a limited type", Prefix
(N
));
1138 when others => return OK
;
1142 procedure Traverse
is new Traverse_Proc
(Process
);
1144 -- Start of processing for Check_Current_Instance
1147 Traverse
(Comp_Decl
);
1148 end Check_Current_Instance
;
1150 ------------------------
1151 -- Freeze_Record_Type --
1152 ------------------------
1154 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
1159 Unplaced_Component
: Boolean := False;
1160 -- Set True if we find at least one component with no component
1161 -- clause (used to warn about useless Pack pragmas).
1163 Placed_Component
: Boolean := False;
1164 -- Set True if we find at least one component with a component
1165 -- clause (used to warn about useless Bit_Order pragmas).
1168 -- Freeze components and embedded subtypes
1170 Comp
:= First_Entity
(Rec
);
1172 while Present
(Comp
) loop
1174 if not Is_Type
(Comp
) then
1175 Freeze_And_Append
(Etype
(Comp
), Loc
, Result
);
1178 -- If the component is an access type with an allocator
1179 -- as default value, the designated type will be frozen
1180 -- by the corresponding expression in init_proc. In order
1181 -- to place the freeze node for the designated type before
1182 -- that for the current record type, freeze it now.
1184 -- Same process if the component is an array of access types,
1185 -- initialized with an aggregate. If the designated type is
1186 -- private, it cannot contain allocators, and it is premature
1187 -- to freeze the type, so we check for this as well.
1189 if Is_Access_Type
(Etype
(Comp
))
1190 and then Present
(Parent
(Comp
))
1191 and then Present
(Expression
(Parent
(Comp
)))
1192 and then Nkind
(Expression
(Parent
(Comp
))) = N_Allocator
1195 Alloc
: constant Node_Id
:= Expression
(Parent
(Comp
));
1198 -- If component is pointer to a classwide type, freeze
1199 -- the specific type in the expression being allocated.
1200 -- The expression may be a subtype indication, in which
1201 -- case freeze the subtype mark.
1203 if Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp
))) then
1205 if Is_Entity_Name
(Expression
(Alloc
)) then
1207 (Entity
(Expression
(Alloc
)), Loc
, Result
);
1209 Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
1212 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
1217 (Designated_Type
(Etype
(Comp
)), Loc
, Result
);
1221 elsif Is_Array_Type
(Etype
(Comp
))
1222 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
1223 and then Present
(Parent
(Comp
))
1224 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
1225 and then Present
(Expression
(Parent
(Comp
)))
1226 and then Nkind
(Expression
(Parent
(Comp
))) = N_Aggregate
1227 and then Is_Fully_Defined
1228 (Designated_Type
(Component_Type
(Etype
(Comp
))))
1232 (Component_Type
(Etype
(Comp
))), Loc
, Result
);
1235 -- Processing for real components (exclude anonymous subtypes)
1237 if Ekind
(Comp
) = E_Component
1238 or else Ekind
(Comp
) = E_Discriminant
1240 -- Check for error of component clause given for variable
1241 -- sized type. We have to delay this test till this point,
1242 -- since the component type has to be frozen for us to know
1243 -- if it is variable length. We omit this test in a generic
1244 -- context, it will be applied at instantiation time.
1247 CC
: constant Node_Id
:= Component_Clause
(Comp
);
1250 if Present
(CC
) then
1251 Placed_Component
:= True;
1253 if not Size_Known_At_Compile_Time
1254 (Underlying_Type
(Etype
(Comp
)))
1255 and then not Inside_A_Generic
1258 ("component clause not allowed for variable " &
1259 "length component", CC
);
1263 Unplaced_Component
:= True;
1267 -- If component clause is present, then deal with the
1268 -- non-default bit order case. We cannot do this before
1269 -- the freeze point, because there is no required order
1270 -- for the component clause and the bit_order clause.
1272 -- We only do this processing for the base type, and in
1273 -- fact that's important, since otherwise if there are
1274 -- record subtypes, we could reverse the bits once for
1275 -- each subtype, which would be incorrect.
1277 if Present
(Component_Clause
(Comp
))
1278 and then Reverse_Bit_Order
(Rec
)
1279 and then Ekind
(E
) = E_Record_Type
1282 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
1283 CSZ
: constant Uint
:= Esize
(Comp
);
1284 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
1285 Pos
: constant Node_Id
:= Position
(CLC
);
1286 FB
: constant Node_Id
:= First_Bit
(CLC
);
1288 Storage_Unit_Offset
: constant Uint
:=
1289 CFB
/ System_Storage_Unit
;
1291 Start_Bit
: constant Uint
:=
1292 CFB
mod System_Storage_Unit
;
1295 -- Cases where field goes over storage unit boundary
1297 if Start_Bit
+ CSZ
> System_Storage_Unit
then
1299 -- Allow multi-byte field but generate warning
1301 if Start_Bit
mod System_Storage_Unit
= 0
1302 and then CSZ
mod System_Storage_Unit
= 0
1305 ("multi-byte field specified with non-standard"
1306 & " Bit_Order?", CLC
);
1308 if Bytes_Big_Endian
then
1310 ("bytes are not reversed "
1311 & "(component is big-endian)?", CLC
);
1314 ("bytes are not reversed "
1315 & "(component is little-endian)?", CLC
);
1318 -- Do not allow non-contiguous field
1322 ("attempt to specify non-contiguous field"
1323 & " not permitted", CLC
);
1325 ("\(caused by non-standard Bit_Order "
1326 & "specified)", CLC
);
1329 -- Case where field fits in one storage unit
1332 -- Give warning if suspicious component clause
1334 if Intval
(FB
) >= System_Storage_Unit
then
1336 ("?Bit_Order clause does not affect " &
1337 "byte ordering", Pos
);
1339 Intval
(Pos
) + Intval
(FB
) / System_Storage_Unit
;
1341 ("?position normalized to ^ before bit " &
1342 "order interpreted", Pos
);
1345 -- Here is where we fix up the Component_Bit_Offset
1346 -- value to account for the reverse bit order.
1347 -- Some examples of what needs to be done are:
1349 -- First_Bit .. Last_Bit Component_Bit_Offset
1352 -- 0 .. 0 7 .. 7 0 7
1353 -- 0 .. 1 6 .. 7 0 6
1354 -- 0 .. 2 5 .. 7 0 5
1355 -- 0 .. 7 0 .. 7 0 4
1357 -- 1 .. 1 6 .. 6 1 6
1358 -- 1 .. 4 3 .. 6 1 3
1359 -- 4 .. 7 0 .. 3 4 0
1361 -- The general rule is that the first bit is
1362 -- is obtained by subtracting the old ending bit
1363 -- from storage_unit - 1.
1365 Set_Component_Bit_Offset
(Comp
,
1366 (Storage_Unit_Offset
* System_Storage_Unit
)
1367 + (System_Storage_Unit
- 1)
1368 - (Start_Bit
+ CSZ
- 1));
1370 Set_Normalized_First_Bit
(Comp
,
1371 Component_Bit_Offset
(Comp
) mod System_Storage_Unit
);
1380 -- Check for useless pragma Bit_Order
1382 if not Placed_Component
and then Reverse_Bit_Order
(Rec
) then
1383 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
1384 Error_Msg_N
("?Bit_Order specification has no effect", ADC
);
1385 Error_Msg_N
("\?since no component clauses were specified", ADC
);
1388 -- Check for useless pragma Pack when all components placed
1391 and then not Unplaced_Component
1392 and then Warn_On_Redundant_Constructs
1395 ("?pragma Pack has no effect, no unplaced components",
1396 Get_Rep_Pragma
(Rec
, Name_Pack
));
1397 Set_Is_Packed
(Rec
, False);
1400 -- If this is the record corresponding to a remote type,
1401 -- freeze the remote type here since that is what we are
1402 -- semantically freeing. This prevents having the freeze node
1403 -- for that type in an inner scope.
1405 -- Also, Check for controlled components and unchecked unions.
1406 -- Finally, enforce the restriction that access attributes with
1407 -- a current instance prefix can only apply to limited types.
1409 if Ekind
(Rec
) = E_Record_Type
then
1411 if Present
(Corresponding_Remote_Type
(Rec
)) then
1413 (Corresponding_Remote_Type
(Rec
), Loc
, Result
);
1416 Comp
:= First_Component
(Rec
);
1418 while Present
(Comp
) loop
1419 if Has_Controlled_Component
(Etype
(Comp
))
1420 or else (Chars
(Comp
) /= Name_uParent
1421 and then Is_Controlled
(Etype
(Comp
)))
1422 or else (Is_Protected_Type
(Etype
(Comp
))
1424 (Corresponding_Record_Type
(Etype
(Comp
)))
1425 and then Has_Controlled_Component
1426 (Corresponding_Record_Type
(Etype
(Comp
))))
1428 Set_Has_Controlled_Component
(Rec
);
1432 if Has_Unchecked_Union
(Etype
(Comp
)) then
1433 Set_Has_Unchecked_Union
(Rec
);
1436 if Has_Per_Object_Constraint
(Comp
)
1437 and then not Is_Limited_Type
(Rec
)
1439 -- Scan component declaration for likely misuses of
1440 -- current instance, either in a constraint or in a
1441 -- default expression.
1443 Check_Current_Instance
(Parent
(Comp
));
1446 Next_Component
(Comp
);
1450 Set_Component_Alignment_If_Not_Set
(Rec
);
1452 -- For first subtypes, check if there are any fixed-point
1453 -- fields with component clauses, where we must check the size.
1454 -- This is not done till the freeze point, since for fixed-point
1455 -- types, we do not know the size until the type is frozen.
1457 if Is_First_Subtype
(Rec
) then
1458 Comp
:= First_Component
(Rec
);
1460 while Present
(Comp
) loop
1461 if Present
(Component_Clause
(Comp
))
1462 and then Is_Fixed_Point_Type
(Etype
(Comp
))
1465 (Component_Clause
(Comp
),
1471 Next_Component
(Comp
);
1474 end Freeze_Record_Type
;
1476 -- Start of processing for Freeze_Entity
1479 -- Do not freeze if already frozen since we only need one freeze node.
1481 if Is_Frozen
(E
) then
1484 -- It is improper to freeze an external entity within a generic
1485 -- because its freeze node will appear in a non-valid context.
1486 -- ??? We should probably freeze the entity at that point and insert
1487 -- the freeze node in a proper place but this proper place is not
1488 -- easy to find, and the proper scope is not easy to restore. For
1489 -- now, just wait to get out of the generic to freeze ???
1491 elsif Inside_A_Generic
and then External_Ref_In_Generic
(E
) then
1494 -- Do not freeze a global entity within an inner scope created during
1495 -- expansion. A call to subprogram E within some internal procedure
1496 -- (a stream attribute for example) might require freezing E, but the
1497 -- freeze node must appear in the same declarative part as E itself.
1498 -- The two-pass elaboration mechanism in gigi guarantees that E will
1499 -- be frozen before the inner call is elaborated. We exclude constants
1500 -- from this test, because deferred constants may be frozen early, and
1501 -- must be diagnosed (see e.g. 1522-005). If the enclosing subprogram
1502 -- comes from source, or is a generic instance, then the freeze point
1503 -- is the one mandated by the language. and we freze the entity.
1505 elsif In_Open_Scopes
(Scope
(E
))
1506 and then Scope
(E
) /= Current_Scope
1507 and then Ekind
(E
) /= E_Constant
1510 S
: Entity_Id
:= Current_Scope
;
1513 while Present
(S
) loop
1514 if Is_Overloadable
(S
) then
1515 if Comes_From_Source
(S
)
1516 or else Is_Generic_Instance
(S
)
1529 -- Here to freeze the entity
1534 -- Case of entity being frozen is other than a type
1536 if not Is_Type
(E
) then
1538 -- If entity is exported or imported and does not have an external
1539 -- name, now is the time to provide the appropriate default name.
1540 -- Skip this if the entity is stubbed, since we don't need a name
1541 -- for any stubbed routine.
1543 if (Is_Imported
(E
) or else Is_Exported
(E
))
1544 and then No
(Interface_Name
(E
))
1545 and then Convention
(E
) /= Convention_Stubbed
1547 Set_Encoded_Interface_Name
1548 (E
, Get_Default_External_Name
(E
));
1551 -- For a subprogram, freeze all parameter types and also the return
1552 -- type (RM 13.14(13)). However skip this for internal subprograms.
1553 -- This is also the point where any extra formal parameters are
1554 -- created since we now know whether the subprogram will use
1555 -- a foreign convention.
1557 if Is_Subprogram
(E
) then
1559 if not Is_Internal
(E
) then
1564 function Is_Fat_C_Ptr_Type
(T
: Entity_Id
) return Boolean;
1565 -- Determines if given type entity is a fat pointer type
1566 -- used as an argument type or return type to a subprogram
1567 -- with C or C++ convention set.
1569 --------------------------
1570 -- Is_Fat_C_Access_Type --
1571 --------------------------
1573 function Is_Fat_C_Ptr_Type
(T
: Entity_Id
) return Boolean is
1575 return (Convention
(E
) = Convention_C
1577 Convention
(E
) = Convention_CPP
)
1578 and then Is_Access_Type
(T
)
1579 and then Esize
(T
) > Ttypes
.System_Address_Size
;
1580 end Is_Fat_C_Ptr_Type
;
1583 -- Loop through formals
1585 Formal
:= First_Formal
(E
);
1587 while Present
(Formal
) loop
1589 F_Type
:= Etype
(Formal
);
1590 Freeze_And_Append
(F_Type
, Loc
, Result
);
1592 if Is_Private_Type
(F_Type
)
1593 and then Is_Private_Type
(Base_Type
(F_Type
))
1594 and then No
(Full_View
(Base_Type
(F_Type
)))
1595 and then not Is_Generic_Type
(F_Type
)
1596 and then not Is_Derived_Type
(F_Type
)
1598 -- If the type of a formal is incomplete, subprogram
1599 -- is being frozen prematurely. Within an instance
1600 -- (but not within a wrapper package) this is an
1601 -- an artifact of our need to regard the end of an
1602 -- instantiation as a freeze point. Otherwise it is
1603 -- a definite error.
1604 -- and then not Is_Wrapper_Package (Current_Scope) ???
1607 Set_Is_Frozen
(E
, False);
1610 elsif not After_Last_Declaration
then
1611 Error_Msg_Node_1
:= F_Type
;
1613 ("type& must be fully defined before this point",
1618 -- Check bad use of fat C pointer
1620 if Is_Fat_C_Ptr_Type
(F_Type
) then
1621 Error_Msg_Qual_Level
:= 1;
1623 ("?type of & does not correspond to C pointer",
1625 Error_Msg_Qual_Level
:= 0;
1628 -- Check for unconstrained array in exported foreign
1631 if Convention
(E
) in Foreign_Convention
1632 and then not Is_Imported
(E
)
1633 and then Is_Array_Type
(F_Type
)
1634 and then not Is_Constrained
(F_Type
)
1636 Error_Msg_Qual_Level
:= 1;
1638 ("?type of argument& is unconstrained array",
1641 ("?foreign caller must pass bounds explicitly",
1643 Error_Msg_Qual_Level
:= 0;
1646 Next_Formal
(Formal
);
1649 -- Check return type
1651 if Ekind
(E
) = E_Function
then
1652 Freeze_And_Append
(Etype
(E
), Loc
, Result
);
1654 if Is_Fat_C_Ptr_Type
(Etype
(E
)) then
1656 ("?return type of& does not correspond to C pointer",
1659 elsif Is_Array_Type
(Etype
(E
))
1660 and then not Is_Constrained
(Etype
(E
))
1661 and then not Is_Imported
(E
)
1662 and then Convention
(E
) in Foreign_Convention
1665 ("foreign convention function may not " &
1666 "return unconstrained array", E
);
1672 -- Must freeze its parent first if it is a derived subprogram
1674 if Present
(Alias
(E
)) then
1675 Freeze_And_Append
(Alias
(E
), Loc
, Result
);
1678 -- If the return type requires a transient scope, and we are on
1679 -- a target allowing functions to return with a depressed stack
1680 -- pointer, then we mark the function as requiring this treatment.
1682 if Ekind
(E
) = E_Function
1683 and then Functions_Return_By_DSP_On_Target
1684 and then Requires_Transient_Scope
(Etype
(E
))
1686 Set_Function_Returns_With_DSP
(E
);
1689 if not Is_Internal
(E
) then
1690 Freeze_Subprogram
(E
);
1693 -- Here for other than a subprogram or type
1696 -- If entity has a type, and it is not a generic unit, then
1697 -- freeze it first (RM 13.14(10))
1699 if Present
(Etype
(E
))
1700 and then Ekind
(E
) /= E_Generic_Function
1702 Freeze_And_Append
(Etype
(E
), Loc
, Result
);
1705 -- For object created by object declaration, perform required
1706 -- categorization (preelaborate and pure) checks. Defer these
1707 -- checks to freeze time since pragma Import inhibits default
1708 -- initialization and thus pragma Import affects these checks.
1710 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
1711 Validate_Object_Declaration
(Declaration_Node
(E
));
1714 -- Check that a constant which has a pragma Volatile[_Components]
1715 -- or Atomic[_Components] also has a pragma Import (RM C.6(13))
1717 -- Note: Atomic[_Components] also sets Volatile[_Components]
1719 if Ekind
(E
) = E_Constant
1720 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
1721 and then not Is_Imported
(E
)
1723 -- Make sure we actually have a pragma, and have not merely
1724 -- inherited the indication from elsewhere (e.g. an address
1725 -- clause, which is not good enough in RM terms!)
1727 if Present
(Get_Rep_Pragma
(E
, Name_Atomic
)) or else
1728 Present
(Get_Rep_Pragma
(E
, Name_Atomic_Components
)) or else
1729 Present
(Get_Rep_Pragma
(E
, Name_Volatile
)) or else
1730 Present
(Get_Rep_Pragma
(E
, Name_Volatile_Components
))
1733 ("stand alone atomic/volatile constant must be imported",
1738 -- Static objects require special handling
1740 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
1741 and then Is_Statically_Allocated
(E
)
1743 Freeze_Static_Object
(E
);
1746 -- Remaining step is to layout objects
1748 if Ekind
(E
) = E_Variable
1750 Ekind
(E
) = E_Constant
1752 Ekind
(E
) = E_Loop_Parameter
1760 -- Case of a type or subtype being frozen
1763 -- The type may be defined in a generic unit. This can occur when
1764 -- freezing a generic function that returns the type (which is
1765 -- defined in a parent unit). It is clearly meaningless to freeze
1766 -- this type. However, if it is a subtype, its size may be determi-
1767 -- nable and used in subsequent checks, so might as well try to
1770 if Present
(Scope
(E
))
1771 and then Is_Generic_Unit
(Scope
(E
))
1773 Check_Compile_Time_Size
(E
);
1777 -- Deal with special cases of freezing for subtype
1779 if E
/= Base_Type
(E
) then
1781 -- If ancestor subtype present, freeze that first.
1782 -- Note that this will also get the base type frozen.
1784 Atype
:= Ancestor_Subtype
(E
);
1786 if Present
(Atype
) then
1787 Freeze_And_Append
(Atype
, Loc
, Result
);
1789 -- Otherwise freeze the base type of the entity before
1790 -- freezing the entity itself, (RM 13.14(14)).
1792 elsif E
/= Base_Type
(E
) then
1793 Freeze_And_Append
(Base_Type
(E
), Loc
, Result
);
1796 -- For a derived type, freeze its parent type first (RM 13.14(14))
1798 elsif Is_Derived_Type
(E
) then
1799 Freeze_And_Append
(Etype
(E
), Loc
, Result
);
1800 Freeze_And_Append
(First_Subtype
(Etype
(E
)), Loc
, Result
);
1803 -- For array type, freeze index types and component type first
1804 -- before freezing the array (RM 13.14(14)).
1806 if Is_Array_Type
(E
) then
1808 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
1810 Non_Standard_Enum
: Boolean := False;
1811 -- Set true if any of the index types is an enumeration
1812 -- type with a non-standard representation.
1815 Freeze_And_Append
(Ctyp
, Loc
, Result
);
1817 Indx
:= First_Index
(E
);
1818 while Present
(Indx
) loop
1819 Freeze_And_Append
(Etype
(Indx
), Loc
, Result
);
1821 if Is_Enumeration_Type
(Etype
(Indx
))
1822 and then Has_Non_Standard_Rep
(Etype
(Indx
))
1824 Non_Standard_Enum
:= True;
1830 -- For base type, propagate flags for component type
1832 if Ekind
(E
) = E_Array_Type
then
1833 if Is_Controlled
(Component_Type
(E
))
1834 or else Has_Controlled_Component
(Ctyp
)
1836 Set_Has_Controlled_Component
(E
);
1839 if Has_Unchecked_Union
(Component_Type
(E
)) then
1840 Set_Has_Unchecked_Union
(E
);
1844 -- If packing was requested or if the component size was set
1845 -- explicitly, then see if bit packing is required. This
1846 -- processing is only done for base types, since all the
1847 -- representation aspects involved are type-related. This
1848 -- is not just an optimization, if we start processing the
1849 -- subtypes, they intefere with the settings on the base
1850 -- type (this is because Is_Packed has a slightly different
1851 -- meaning before and after freezing).
1853 if E
= Base_Type
(E
) then
1859 if (Is_Packed
(E
) or else Has_Pragma_Pack
(E
))
1860 and then not Has_Atomic_Components
(E
)
1861 and then Known_Static_RM_Size
(Ctyp
)
1863 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
1865 elsif Known_Component_Size
(E
) then
1866 Csiz
:= Component_Size
(E
);
1868 elsif not Known_Static_Esize
(Ctyp
) then
1872 Esiz
:= Esize
(Ctyp
);
1874 -- We can set the component size if it is less than
1875 -- 16, rounding it up to the next storage unit size.
1879 elsif Esiz
<= 16 then
1885 -- Set component size up to match alignment if
1886 -- it would otherwise be less than the alignment.
1887 -- This deals with cases of types whose alignment
1888 -- exceeds their sizes (padded types).
1892 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
1903 if 1 <= Csiz
and then Csiz
<= 64 then
1905 -- We set the component size for all cases 1-64
1907 Set_Component_Size
(Base_Type
(E
), Csiz
);
1909 -- Actual packing is not needed for 8,16,32,64
1910 -- Also not needed for 24 if alignment is 1
1916 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
1918 -- Here the array was requested to be packed, but
1919 -- the packing request had no effect, so Is_Packed
1922 -- Note: semantically this means that we lose
1923 -- track of the fact that a derived type inherited
1924 -- a pack pragma that was non-effective, but that
1927 -- We regard a Pack pragma as a request to set a
1928 -- representation characteristic, and this request
1931 Set_Is_Packed
(Base_Type
(E
), False);
1933 -- In all other cases, packing is indeed needed
1936 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
1937 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
1938 Set_Is_Packed
(Base_Type
(E
));
1944 -- If any of the index types was an enumeration type with
1945 -- a non-standard rep clause, then we indicate that the
1946 -- array type is always packed (even if it is not bit packed).
1948 if Non_Standard_Enum
then
1949 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
1950 Set_Is_Packed
(Base_Type
(E
));
1954 Set_Component_Alignment_If_Not_Set
(E
);
1956 -- If the array is packed, we must create the packed array
1957 -- type to be used to actually implement the type. This is
1958 -- only needed for real array types (not for string literal
1959 -- types, since they are present only for the front end).
1962 and then Ekind
(E
) /= E_String_Literal_Subtype
1964 Create_Packed_Array_Type
(E
);
1965 Freeze_And_Append
(Packed_Array_Type
(E
), Loc
, Result
);
1967 -- Size information of packed array type is copied to the
1968 -- array type, since this is really the representation.
1970 Set_Size_Info
(E
, Packed_Array_Type
(E
));
1971 Set_RM_Size
(E
, RM_Size
(Packed_Array_Type
(E
)));
1974 -- For a class wide type, the corresponding specific type is
1975 -- frozen as well (RM 13.14(14))
1977 elsif Is_Class_Wide_Type
(E
) then
1978 Freeze_And_Append
(Root_Type
(E
), Loc
, Result
);
1980 -- If the Class_Wide_Type is an Itype (when type is the anonymous
1981 -- parent of a derived type) and it is a library-level entity,
1982 -- generate an itype reference for it. Otherwise, its first
1983 -- explicit reference may be in an inner scope, which will be
1984 -- rejected by the back-end.
1987 and then Is_Compilation_Unit
(Scope
(E
))
1991 Ref
: Node_Id
:= Make_Itype_Reference
(Loc
);
1996 Result
:= New_List
(Ref
);
1998 Append
(Ref
, Result
);
2003 -- For record (sub)type, freeze all the component types (RM
2004 -- 13.14(14). We test for E_Record_(sub)Type here, rather than
2005 -- using Is_Record_Type, because we don't want to attempt the
2006 -- freeze for the case of a private type with record extension
2007 -- (we will do that later when the full type is frozen).
2009 elsif Ekind
(E
) = E_Record_Type
2010 or else Ekind
(E
) = E_Record_Subtype
2012 Freeze_Record_Type
(E
);
2014 -- For a concurrent type, freeze corresponding record type. This
2015 -- does not correpond to any specific rule in the RM, but the
2016 -- record type is essentially part of the concurrent type.
2017 -- Freeze as well all local entities. This includes record types
2018 -- created for entry parameter blocks, and whatever local entities
2019 -- may appear in the private part.
2021 elsif Is_Concurrent_Type
(E
) then
2022 if Present
(Corresponding_Record_Type
(E
)) then
2024 (Corresponding_Record_Type
(E
), Loc
, Result
);
2027 Comp
:= First_Entity
(E
);
2029 while Present
(Comp
) loop
2030 if Is_Type
(Comp
) then
2031 Freeze_And_Append
(Comp
, Loc
, Result
);
2033 elsif (Ekind
(Comp
)) /= E_Function
then
2034 Freeze_And_Append
(Etype
(Comp
), Loc
, Result
);
2040 -- Private types are required to point to the same freeze node
2041 -- as their corresponding full views. The freeze node itself
2042 -- has to point to the partial view of the entity (because
2043 -- from the partial view, we can retrieve the full view, but
2044 -- not the reverse). However, in order to freeze correctly,
2045 -- we need to freeze the full view. If we are freezing at the
2046 -- end of a scope (or within the scope of the private type),
2047 -- the partial and full views will have been swapped, the
2048 -- full view appears first in the entity chain and the swapping
2049 -- mechanism enusres that the pointers are properly set (on
2052 -- If we encounter the partial view before the full view
2053 -- (e.g. when freezing from another scope), we freeze the
2054 -- full view, and then set the pointers appropriately since
2055 -- we cannot rely on swapping to fix things up (subtypes in an
2056 -- outer scope might not get swapped).
2058 elsif Is_Incomplete_Or_Private_Type
(E
)
2059 and then not Is_Generic_Type
(E
)
2061 -- Case of full view present
2063 if Present
(Full_View
(E
)) then
2065 -- If full view has already been frozen, then no
2066 -- further processing is required
2068 if Is_Frozen
(Full_View
(E
)) then
2070 Set_Has_Delayed_Freeze
(E
, False);
2071 Set_Freeze_Node
(E
, Empty
);
2072 Check_Debug_Info_Needed
(E
);
2074 -- Otherwise freeze full view and patch the pointers
2077 if Is_Private_Type
(Full_View
(E
))
2078 and then Present
(Underlying_Full_View
(Full_View
(E
)))
2081 (Underlying_Full_View
(Full_View
(E
)), Loc
, Result
);
2084 Freeze_And_Append
(Full_View
(E
), Loc
, Result
);
2086 if Has_Delayed_Freeze
(E
) then
2087 F_Node
:= Freeze_Node
(Full_View
(E
));
2089 if Present
(F_Node
) then
2090 Set_Freeze_Node
(E
, F_Node
);
2091 Set_Entity
(F_Node
, E
);
2093 -- {Incomplete,Private}_Subtypes
2094 -- with Full_Views constrained by discriminants
2096 Set_Has_Delayed_Freeze
(E
, False);
2097 Set_Freeze_Node
(E
, Empty
);
2101 Check_Debug_Info_Needed
(E
);
2104 -- AI-117 requires that the convention of a partial view
2105 -- be the same as the convention of the full view. Note
2106 -- that this is a recognized breach of privacy, but it's
2107 -- essential for logical consistency of representation,
2108 -- and the lack of a rule in RM95 was an oversight.
2110 Set_Convention
(E
, Convention
(Full_View
(E
)));
2112 Set_Size_Known_At_Compile_Time
(E
,
2113 Size_Known_At_Compile_Time
(Full_View
(E
)));
2115 -- Size information is copied from the full view to the
2116 -- incomplete or private view for consistency
2118 -- We skip this is the full view is not a type. This is
2119 -- very strange of course, and can only happen as a result
2120 -- of certain illegalities, such as a premature attempt to
2121 -- derive from an incomplete type.
2123 if Is_Type
(Full_View
(E
)) then
2124 Set_Size_Info
(E
, Full_View
(E
));
2125 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
2130 -- Case of no full view present. If entity is derived or subtype,
2131 -- it is safe to freeze, correctness depends on the frozen status
2132 -- of parent. Otherwise it is either premature usage, or a Taft
2133 -- amendment type, so diagnosis is at the point of use and the
2134 -- type might be frozen later.
2136 elsif E
/= Base_Type
(E
)
2137 or else Is_Derived_Type
(E
)
2142 Set_Is_Frozen
(E
, False);
2146 -- For access subprogram, freeze types of all formals, the return
2147 -- type was already frozen, since it is the Etype of the function.
2149 elsif Ekind
(E
) = E_Subprogram_Type
then
2150 Formal
:= First_Formal
(E
);
2151 while Present
(Formal
) loop
2152 Freeze_And_Append
(Etype
(Formal
), Loc
, Result
);
2153 Next_Formal
(Formal
);
2156 -- If the return type requires a transient scope, and we are on
2157 -- a target allowing functions to return with a depressed stack
2158 -- pointer, then we mark the function as requiring this treatment.
2160 if Functions_Return_By_DSP_On_Target
2161 and then Requires_Transient_Scope
(Etype
(E
))
2163 Set_Function_Returns_With_DSP
(E
);
2166 Freeze_Subprogram
(E
);
2168 -- For access to a protected subprogram, freeze the equivalent
2169 -- type (however this is not set if we are not generating code)
2170 -- or if this is an anonymous type used just for resolution).
2172 elsif Ekind
(E
) = E_Access_Protected_Subprogram_Type
2173 and then Operating_Mode
= Generate_Code
2174 and then Present
(Equivalent_Type
(E
))
2176 Freeze_And_Append
(Equivalent_Type
(E
), Loc
, Result
);
2179 -- Generic types are never seen by the back-end, and are also not
2180 -- processed by the expander (since the expander is turned off for
2181 -- generic processing), so we never need freeze nodes for them.
2183 if Is_Generic_Type
(E
) then
2187 -- Some special processing for non-generic types to complete
2188 -- representation details not known till the freeze point.
2190 if Is_Fixed_Point_Type
(E
) then
2191 Freeze_Fixed_Point_Type
(E
);
2193 elsif Is_Enumeration_Type
(E
) then
2194 Freeze_Enumeration_Type
(E
);
2196 elsif Is_Integer_Type
(E
) then
2197 Adjust_Esize_For_Alignment
(E
);
2199 elsif Is_Access_Type
(E
)
2200 and then No
(Associated_Storage_Pool
(E
))
2202 Check_Restriction
(No_Standard_Storage_Pools
, E
);
2205 -- If the current entity is an array or record subtype and has
2206 -- discriminants used to constrain it, it must not freeze, because
2207 -- Freeze_Entity nodes force Gigi to process the frozen type.
2209 if Is_Composite_Type
(E
) then
2211 if Is_Array_Type
(E
) then
2214 Index
: Node_Id
:= First_Index
(E
);
2219 while Present
(Index
) loop
2220 if Etype
(Index
) /= Any_Type
then
2221 Get_Index_Bounds
(Index
, Expr1
, Expr2
);
2223 for J
in 1 .. 2 loop
2224 if Nkind
(Expr1
) = N_Identifier
2225 and then Ekind
(Entity
(Expr1
)) = E_Discriminant
2227 Set_Has_Delayed_Freeze
(E
, False);
2228 Set_Freeze_Node
(E
, Empty
);
2229 Check_Debug_Info_Needed
(E
);
2241 elsif Has_Discriminants
(E
)
2242 and Is_Constrained
(E
)
2246 Constraint
: Elmt_Id
;
2249 Constraint
:= First_Elmt
(Discriminant_Constraint
(E
));
2251 while Present
(Constraint
) loop
2253 Expr
:= Node
(Constraint
);
2254 if Nkind
(Expr
) = N_Identifier
2255 and then Ekind
(Entity
(Expr
)) = E_Discriminant
2257 Set_Has_Delayed_Freeze
(E
, False);
2258 Set_Freeze_Node
(E
, Empty
);
2259 Check_Debug_Info_Needed
(E
);
2263 Next_Elmt
(Constraint
);
2269 -- AI-117 requires that all new primitives of a tagged type
2270 -- must inherit the convention of the full view of the type.
2271 -- Inherited and overriding operations are defined to inherit
2272 -- the convention of their parent or overridden subprogram
2273 -- (also specified in AI-117), and that will have occurred
2274 -- earlier (in Derive_Subprogram and New_Overloaded_Entity).
2275 -- Here we set the convention of primitives that are still
2276 -- convention Ada, which will ensure that any new primitives
2277 -- inherit the type's convention. Class-wide types can have
2278 -- a foreign convention inherited from their specific type,
2279 -- but are excluded from this since they don't have any
2280 -- associated primitives.
2282 if Is_Tagged_Type
(E
)
2283 and then not Is_Class_Wide_Type
(E
)
2284 and then Convention
(E
) /= Convention_Ada
2287 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
2288 Prim
: Elmt_Id
:= First_Elmt
(Prim_List
);
2291 while Present
(Prim
) loop
2292 if Convention
(Node
(Prim
)) = Convention_Ada
then
2293 Set_Convention
(Node
(Prim
), Convention
(E
));
2302 -- Now that all types from which E may depend are frozen, see
2303 -- if the size is known at compile time, if it must be unsigned,
2304 -- or if strict alignent is required
2306 Check_Compile_Time_Size
(E
);
2307 Check_Unsigned_Type
(E
);
2309 if Base_Type
(E
) = E
then
2310 Check_Strict_Alignment
(E
);
2313 -- Do not allow a size clause for a type which does not have a size
2314 -- that is known at compile time
2316 if Has_Size_Clause
(E
)
2317 and then not Size_Known_At_Compile_Time
(E
)
2320 ("size clause not allowed for variable length type",
2324 -- Remaining process is to set/verify the representation information,
2325 -- in particular the size and alignment values. This processing is
2326 -- not required for generic types, since generic types do not play
2327 -- any part in code generation, and so the size and alignment values
2328 -- for suhc types are irrelevant.
2330 if Is_Generic_Type
(E
) then
2333 -- Otherwise we call the layout procedure
2339 -- End of freeze processing for type entities
2342 -- Here is where we logically freeze the current entity. If it has a
2343 -- freeze node, then this is the point at which the freeze node is
2344 -- linked into the result list.
2346 if Has_Delayed_Freeze
(E
) then
2348 -- If a freeze node is already allocated, use it, otherwise allocate
2349 -- a new one. The preallocation happens in the case of anonymous base
2350 -- types, where we preallocate so that we can set First_Subtype_Link.
2351 -- Note that we reset the Sloc to the current freeze location.
2353 if Present
(Freeze_Node
(E
)) then
2354 F_Node
:= Freeze_Node
(E
);
2355 Set_Sloc
(F_Node
, Loc
);
2358 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
2359 Set_Freeze_Node
(E
, F_Node
);
2360 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
2361 Set_TSS_Elist
(F_Node
, No_Elist
);
2362 Set_Actions
(F_Node
, No_List
);
2365 Set_Entity
(F_Node
, E
);
2367 if Result
= No_List
then
2368 Result
:= New_List
(F_Node
);
2370 Append
(F_Node
, Result
);
2375 -- When a type is frozen, the first subtype of the type is frozen as
2376 -- well (RM 13.14(15)). This has to be done after freezing the type,
2377 -- since obviously the first subtype depends on its own base type.
2380 Freeze_And_Append
(First_Subtype
(E
), Loc
, Result
);
2382 -- If we just froze a tagged non-class wide record, then freeze the
2383 -- corresponding class-wide type. This must be done after the tagged
2384 -- type itself is frozen, because the class-wide type refers to the
2385 -- tagged type which generates the class.
2387 if Is_Tagged_Type
(E
)
2388 and then not Is_Class_Wide_Type
(E
)
2389 and then Present
(Class_Wide_Type
(E
))
2391 Freeze_And_Append
(Class_Wide_Type
(E
), Loc
, Result
);
2395 Check_Debug_Info_Needed
(E
);
2397 -- Special handling for subprograms
2399 if Is_Subprogram
(E
) then
2401 -- If subprogram has address clause then reset Is_Public flag, since
2402 -- we do not want the backend to generate external references.
2404 if Present
(Address_Clause
(E
))
2405 and then not Is_Library_Level_Entity
(E
)
2407 Set_Is_Public
(E
, False);
2409 -- If no address clause and not intrinsic, then for imported
2410 -- subprogram in main unit, generate descriptor if we are in
2411 -- Propagate_Exceptions mode.
2413 elsif Propagate_Exceptions
2414 and then Is_Imported
(E
)
2415 and then not Is_Intrinsic_Subprogram
(E
)
2416 and then Convention
(E
) /= Convention_Stubbed
2418 if Result
= No_List
then
2419 Result
:= Empty_List
;
2422 Generate_Subprogram_Descriptor_For_Imported_Subprogram
2431 -----------------------------
2432 -- Freeze_Enumeration_Type --
2433 -----------------------------
2435 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
2437 if Has_Foreign_Convention
(Typ
)
2438 and then not Has_Size_Clause
(Typ
)
2439 and then Esize
(Typ
) < Standard_Integer_Size
2441 Init_Esize
(Typ
, Standard_Integer_Size
);
2444 Adjust_Esize_For_Alignment
(Typ
);
2446 end Freeze_Enumeration_Type
;
2448 -----------------------
2449 -- Freeze_Expression --
2450 -----------------------
2452 procedure Freeze_Expression
(N
: Node_Id
) is
2453 In_Def_Exp
: constant Boolean := In_Default_Expression
;
2456 Desig_Typ
: Entity_Id
;
2460 Freeze_Outside
: Boolean := False;
2461 -- This flag is set true if the entity must be frozen outside the
2462 -- current subprogram. This happens in the case of expander generated
2463 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
2464 -- not freeze all entities like other bodies, but which nevertheless
2465 -- may reference entities that have to be frozen before the body and
2466 -- obviously cannot be frozen inside the body.
2468 function In_Exp_Body
(N
: Node_Id
) return Boolean;
2469 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
2470 -- it is the handled statement sequence of an expander generated
2471 -- subprogram (init proc, or stream subprogram). If so, it returns
2472 -- True, otherwise False.
2474 function In_Exp_Body
(N
: Node_Id
) return Boolean is
2478 if Nkind
(N
) = N_Subprogram_Body
then
2484 if Nkind
(P
) /= N_Subprogram_Body
then
2488 P
:= Defining_Unit_Name
(Specification
(P
));
2490 if Nkind
(P
) = N_Defining_Identifier
2491 and then (Chars
(P
) = Name_uInit_Proc
or else
2492 Chars
(P
) = Name_uInput
or else
2493 Chars
(P
) = Name_uOutput
or else
2494 Chars
(P
) = Name_uRead
or else
2495 Chars
(P
) = Name_uWrite
)
2505 -- Start of processing for Freeze_Expression
2508 -- Immediate return if freezing is inhibited. This flag is set by
2509 -- the analyzer to stop freezing on generated expressions that would
2510 -- cause freezing if they were in the source program, but which are
2511 -- not supposed to freeze, since they are created.
2513 if Must_Not_Freeze
(N
) then
2517 -- If expression is non-static, then it does not freeze in a default
2518 -- expression, see section "Handling of Default Expressions" in the
2519 -- spec of package Sem for further details. Note that we have to
2520 -- make sure that we actually have a real expression (if we have
2521 -- a subtype indication, we can't test Is_Static_Expression!)
2524 and then Nkind
(N
) in N_Subexpr
2525 and then not Is_Static_Expression
(N
)
2530 -- Freeze type of expression if not frozen already
2532 if Nkind
(N
) in N_Has_Etype
2533 and then not Is_Frozen
(Etype
(N
))
2540 -- For entity name, freeze entity if not frozen already. A special
2541 -- exception occurs for an identifier that did not come from source.
2542 -- We don't let such identifiers freeze a non-internal entity, i.e.
2543 -- an entity that did come from source, since such an identifier was
2544 -- generated by the expander, and cannot have any semantic effect on
2545 -- the freezing semantics. For example, this stops the parameter of
2546 -- an initialization procedure from freezing the variable.
2548 if Is_Entity_Name
(N
)
2549 and then not Is_Frozen
(Entity
(N
))
2550 and then (Nkind
(N
) /= N_Identifier
2551 or else Comes_From_Source
(N
)
2552 or else not Comes_From_Source
(Entity
(N
)))
2560 -- For an allocator freeze designated type if not frozen already.
2562 -- For an aggregate whose component type is an access type, freeze
2563 -- the designated type now, so that its freeze does not appear within
2564 -- the loop that might be created in the expansion of the aggregate.
2565 -- If the designated type is a private type without full view, the
2566 -- expression cannot contain an allocator, so the type is not frozen.
2572 Desig_Typ
:= Designated_Type
(Etype
(N
));
2575 if Is_Array_Type
(Etype
(N
))
2576 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
2578 Desig_Typ
:= Designated_Type
(Component_Type
(Etype
(N
)));
2581 when N_Selected_Component |
2582 N_Indexed_Component |
2585 if Is_Access_Type
(Etype
(Prefix
(N
))) then
2586 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
2594 if Desig_Typ
/= Empty
2595 and then (Is_Frozen
(Desig_Typ
)
2596 or else (not Is_Fully_Defined
(Desig_Typ
)))
2601 -- All done if nothing needs freezing
2605 and then No
(Desig_Typ
)
2610 -- Loop for looking at the right place to insert the freeze nodes
2611 -- exiting from the loop when it is appropriate to insert the freeze
2612 -- node before the current node P.
2614 -- Also checks some special exceptions to the freezing rules. These
2615 -- cases result in a direct return, bypassing the freeze action.
2619 Parent_P
:= Parent
(P
);
2621 -- If we don't have a parent, then we are not in a well-formed
2622 -- tree. This is an unusual case, but there are some legitimate
2623 -- situations in which this occurs, notably when the expressions
2624 -- in the range of a type declaration are resolved. We simply
2625 -- ignore the freeze request in this case. Is this right ???
2627 if No
(Parent_P
) then
2631 -- See if we have got to an appropriate point in the tree
2633 case Nkind
(Parent_P
) is
2635 -- A special test for the exception of (RM 13.14(8)) for the
2636 -- case of per-object expressions (RM 3.8(18)) occurring in a
2637 -- component definition or a discrete subtype definition. Note
2638 -- that we test for a component declaration which includes both
2639 -- cases we are interested in, and furthermore the tree does not
2640 -- have explicit nodes for either of these two constructs.
2642 when N_Component_Declaration
=>
2644 -- The case we want to test for here is an identifier that is
2645 -- a per-object expression, this is either a discriminant that
2646 -- appears in a context other than the component declaration
2647 -- or it is a reference to the type of the enclosing construct.
2649 -- For either of these cases, we skip the freezing
2651 if not In_Default_Expression
2652 and then Nkind
(N
) = N_Identifier
2653 and then (Present
(Entity
(N
)))
2655 -- We recognize the discriminant case by just looking for
2656 -- a reference to a discriminant. It can only be one for
2657 -- the enclosing construct. Skip freezing in this case.
2659 if Ekind
(Entity
(N
)) = E_Discriminant
then
2662 -- For the case of a reference to the enclosing record,
2663 -- (or task or protected type), we look for a type that
2664 -- matches the current scope.
2666 elsif Entity
(N
) = Current_Scope
then
2671 -- If we have an enumeration literal that appears as the
2672 -- choice in the aggregate of an enumeration representation
2673 -- clause, then freezing does not occur (RM 13.14(9)).
2675 when N_Enumeration_Representation_Clause
=>
2677 -- The case we are looking for is an enumeration literal
2679 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
2680 and then Is_Enumeration_Type
(Etype
(N
))
2682 -- If enumeration literal appears directly as the choice,
2683 -- do not freeze (this is the normal non-overloade case)
2685 if Nkind
(Parent
(N
)) = N_Component_Association
2686 and then First
(Choices
(Parent
(N
))) = N
2690 -- If enumeration literal appears as the name of a
2691 -- function which is the choice, then also do not freeze.
2692 -- This happens in the overloaded literal case, where the
2693 -- enumeration literal is temporarily changed to a function
2694 -- call for overloading analysis purposes.
2696 elsif Nkind
(Parent
(N
)) = N_Function_Call
2698 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
2700 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
2706 -- Normally if the parent is a handled sequence of statements,
2707 -- then the current node must be a statement, and that is an
2708 -- appropriate place to insert a freeze node.
2710 when N_Handled_Sequence_Of_Statements
=>
2712 -- An exception occurs when the sequence of statements is
2713 -- for an expander generated body that did not do the usual
2714 -- freeze all operation. In this case we usually want to
2715 -- freeze outside this body, not inside it, and we skip
2716 -- past the subprogram body that we are inside.
2718 if In_Exp_Body
(Parent_P
) then
2720 -- However, we *do* want to freeze at this point if we have
2721 -- an entity to freeze, and that entity is declared *inside*
2722 -- the body of the expander generated procedure. This case
2723 -- is recognized by the scope of the type, which is either
2724 -- the spec for some enclosing body, or (in the case of
2725 -- init_procs, for which there are no separate specs) the
2729 Subp
: constant Node_Id
:= Parent
(Parent_P
);
2733 if Nkind
(Subp
) = N_Subprogram_Body
then
2734 Cspc
:= Corresponding_Spec
(Subp
);
2736 if (Present
(Typ
) and then Scope
(Typ
) = Cspc
)
2738 (Present
(Nam
) and then Scope
(Nam
) = Cspc
)
2743 and then Scope
(Typ
) = Current_Scope
2744 and then Current_Scope
= Defining_Entity
(Subp
)
2751 -- If not that exception to the exception, then this is
2752 -- where we delay the freeze till outside the body.
2754 Parent_P
:= Parent
(Parent_P
);
2755 Freeze_Outside
:= True;
2757 -- Here if normal case where we are in handled statement
2758 -- sequence and want to do the insertion right there.
2764 -- If parent is a body or a spec or a block, then the current
2765 -- node is a statement or declaration and we can insert the
2766 -- freeze node before it.
2768 when N_Package_Specification |
2774 N_Block_Statement
=> exit;
2776 -- The expander is allowed to define types in any statements list,
2777 -- so any of the following parent nodes also mark a freezing point
2778 -- if the actual node is in a list of statements or declarations.
2780 when N_Exception_Handler |
2783 N_Case_Statement_Alternative |
2784 N_Compilation_Unit_Aux |
2785 N_Selective_Accept |
2786 N_Accept_Alternative |
2787 N_Delay_Alternative |
2788 N_Conditional_Entry_Call |
2789 N_Entry_Call_Alternative |
2790 N_Triggering_Alternative |
2794 exit when Is_List_Member
(P
);
2796 -- Note: The N_Loop_Statement is a special case. A type that
2797 -- appears in the source can never be frozen in a loop (this
2798 -- occurs only because of a loop expanded by the expander),
2799 -- so we keep on going. Otherwise we terminate the search.
2800 -- Same is true of any entity which comes from source. (if they
2801 -- have a predefined type, that type does not appear to come
2802 -- from source, but the entity should not be frozen here).
2804 when N_Loop_Statement
=>
2805 exit when not Comes_From_Source
(Etype
(N
))
2806 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
2808 -- For all other cases, keep looking at parents
2814 -- We fall through the case if we did not yet find the proper
2815 -- place in the free for inserting the freeze node, so climb!
2820 -- If the expression appears in a record or an initialization
2821 -- procedure, the freeze nodes are collected and attached to
2822 -- the current scope, to be inserted and analyzed on exit from
2823 -- the scope, to insure that generated entities appear in the
2824 -- correct scope. If the expression is a default for a discriminant
2825 -- specification, the scope is still void. The expression can also
2826 -- appear in the discriminant part of a private or concurrent type.
2828 -- The other case requiring this special handling is if we are in
2829 -- a default expression, since in that case we are about to freeze
2830 -- a static type, and the freeze scope needs to be the outer scope,
2831 -- not the scope of the subprogram with the default parameter.
2833 -- For default expressions in generic units, the Move_Freeze_Nodes
2834 -- mechanism (see sem_ch12.adb) takes care of placing them at the
2835 -- proper place, after the generic unit.
2837 if (In_Def_Exp
and not Inside_A_Generic
)
2838 or else Freeze_Outside
2839 or else (Is_Type
(Current_Scope
)
2840 and then (not Is_Concurrent_Type
(Current_Scope
)
2841 or else not Has_Completion
(Current_Scope
)))
2842 or else Ekind
(Current_Scope
) = E_Void
2845 Loc
: constant Source_Ptr
:= Sloc
(Current_Scope
);
2846 Freeze_Nodes
: List_Id
:= No_List
;
2849 if Present
(Desig_Typ
) then
2850 Freeze_And_Append
(Desig_Typ
, Loc
, Freeze_Nodes
);
2853 if Present
(Typ
) then
2854 Freeze_And_Append
(Typ
, Loc
, Freeze_Nodes
);
2857 if Present
(Nam
) then
2858 Freeze_And_Append
(Nam
, Loc
, Freeze_Nodes
);
2861 if Is_Non_Empty_List
(Freeze_Nodes
) then
2863 if No
(Scope_Stack
.Table
2864 (Scope_Stack
.Last
).Pending_Freeze_Actions
)
2867 (Scope_Stack
.Last
).Pending_Freeze_Actions
:=
2870 Append_List
(Freeze_Nodes
, Scope_Stack
.Table
2871 (Scope_Stack
.Last
).Pending_Freeze_Actions
);
2879 -- Now we have the right place to do the freezing. First, a special
2880 -- adjustment, if we are in default expression analysis mode, these
2881 -- freeze actions must not be thrown away (normally all inserted
2882 -- actions are thrown away in this mode. However, the freeze actions
2883 -- are from static expressions and one of the important reasons we
2884 -- are doing this special analysis is to get these freeze actions.
2885 -- Therefore we turn off the In_Default_Expression mode to propagate
2886 -- these freeze actions. This also means they get properly analyzed
2889 In_Default_Expression
:= False;
2891 -- Freeze the designated type of an allocator (RM 13.14(12))
2893 if Present
(Desig_Typ
) then
2894 Freeze_Before
(P
, Desig_Typ
);
2897 -- Freeze type of expression (RM 13.14(9)). Note that we took care of
2898 -- the enumeration representation clause exception in the loop above.
2900 if Present
(Typ
) then
2901 Freeze_Before
(P
, Typ
);
2904 -- Freeze name if one is present (RM 13.14(10))
2906 if Present
(Nam
) then
2907 Freeze_Before
(P
, Nam
);
2910 In_Default_Expression
:= In_Def_Exp
;
2911 end Freeze_Expression
;
2913 -----------------------------
2914 -- Freeze_Fixed_Point_Type --
2915 -----------------------------
2917 -- Certain fixed-point types and subtypes, including implicit base
2918 -- types and declared first subtypes, have not yet set up a range.
2919 -- This is because the range cannot be set until the Small and Size
2920 -- values are known, and these are not known till the type is frozen.
2922 -- To signal this case, Scalar_Range contains an unanalyzed syntactic
2923 -- range whose bounds are unanalyzed real literals. This routine will
2924 -- recognize this case, and transform this range node into a properly
2925 -- typed range with properly analyzed and resolved values.
2927 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
2928 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
2929 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
2930 Hi
: constant Node_Id
:= High_Bound
(Rng
);
2931 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
2932 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
2933 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
2934 BHi
: constant Node_Id
:= High_Bound
(Brng
);
2935 Small
: constant Ureal
:= Small_Value
(Typ
);
2942 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
2943 -- Returns size of type with given bounds. Also leaves these
2944 -- bounds set as the current bounds of the Typ.
2946 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
2948 Set_Realval
(Lo
, Lov
);
2949 Set_Realval
(Hi
, Hiv
);
2950 return Minimum_Size
(Typ
);
2953 -- Start of processing for Freeze_Fixed_Point_Type;
2956 -- If Esize of a subtype has not previously been set, set it now
2958 if Unknown_Esize
(Typ
) then
2959 Atype
:= Ancestor_Subtype
(Typ
);
2961 if Present
(Atype
) then
2962 Set_Size_Info
(Typ
, Atype
);
2964 Set_Size_Info
(Typ
, Base_Type
(Typ
));
2968 -- Immediate return if the range is already analyzed. This means
2969 -- that the range is already set, and does not need to be computed
2972 if Analyzed
(Rng
) then
2976 -- Immediate return if either of the bounds raises Constraint_Error
2978 if Raises_Constraint_Error
(Lo
)
2979 or else Raises_Constraint_Error
(Hi
)
2984 Loval
:= Realval
(Lo
);
2985 Hival
:= Realval
(Hi
);
2987 -- Ordinary fixed-point case
2989 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
2991 -- For the ordinary fixed-point case, we are allowed to fudge the
2992 -- end-points up or down by small. Generally we prefer to fudge
2993 -- up, i.e. widen the bounds for non-model numbers so that the
2994 -- end points are included. However there are cases in which this
2995 -- cannot be done, and indeed cases in which we may need to narrow
2996 -- the bounds. The following circuit makes the decision.
2998 -- Note: our terminology here is that Incl_EP means that the
2999 -- bounds are widened by Small if necessary to include the end
3000 -- points, and Excl_EP means that the bounds are narrowed by
3001 -- Small to exclude the end-points if this reduces the size.
3003 -- Note that in the Incl case, all we care about is including the
3004 -- end-points. In the Excl case, we want to narrow the bounds as
3005 -- much as permitted by the RM, to give the smallest possible size.
3008 Loval_Incl_EP
: Ureal
;
3009 Hival_Incl_EP
: Ureal
;
3011 Loval_Excl_EP
: Ureal
;
3012 Hival_Excl_EP
: Ureal
;
3018 First_Subt
: Entity_Id
;
3023 -- First step. Base types are required to be symmetrical. Right
3024 -- now, the base type range is a copy of the first subtype range.
3025 -- This will be corrected before we are done, but right away we
3026 -- need to deal with the case where both bounds are non-negative.
3027 -- In this case, we set the low bound to the negative of the high
3028 -- bound, to make sure that the size is computed to include the
3029 -- required sign. Note that we do not need to worry about the
3030 -- case of both bounds negative, because the sign will be dealt
3031 -- with anyway. Furthermore we can't just go making such a bound
3032 -- symmetrical, since in a twos-complement system, there is an
3033 -- extra negative value which could not be accomodated on the
3037 and then not UR_Is_Negative
(Loval
)
3038 and then Hival
> Loval
3041 Set_Realval
(Lo
, Loval
);
3044 -- Compute the fudged bounds. If the number is a model number,
3045 -- then we do nothing to include it, but we are allowed to
3046 -- backoff to the next adjacent model number when we exclude
3047 -- it. If it is not a model number then we straddle the two
3048 -- values with the model numbers on either side.
3050 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
3052 if Loval
= Model_Num
then
3053 Loval_Incl_EP
:= Model_Num
;
3055 Loval_Incl_EP
:= Model_Num
- Small
;
3058 -- The low value excluding the end point is Small greater, but
3059 -- we do not do this exclusion if the low value is positive,
3060 -- since it can't help the size and could actually hurt by
3061 -- crossing the high bound.
3063 if UR_Is_Negative
(Loval_Incl_EP
) then
3064 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
3066 Loval_Excl_EP
:= Loval_Incl_EP
;
3069 -- Similar processing for upper bound and high value
3071 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
3073 if Hival
= Model_Num
then
3074 Hival_Incl_EP
:= Model_Num
;
3076 Hival_Incl_EP
:= Model_Num
+ Small
;
3079 if UR_Is_Positive
(Hival_Incl_EP
) then
3080 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
3082 Hival_Excl_EP
:= Hival_Incl_EP
;
3085 -- One further adjustment is needed. In the case of subtypes,
3086 -- we cannot go outside the range of the base type, or we get
3087 -- peculiarities, and the base type range is already set. This
3088 -- only applies to the Incl values, since clearly the Excl
3089 -- values are already as restricted as they are allowed to be.
3092 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
3093 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
3096 -- Get size including and excluding end points
3098 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
3099 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
3101 -- No need to exclude end-points if it does not reduce size
3103 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
3104 Loval_Excl_EP
:= Loval_Incl_EP
;
3107 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
3108 Hival_Excl_EP
:= Hival_Incl_EP
;
3111 -- Now we set the actual size to be used. We want to use the
3112 -- bounds fudged up to include the end-points but only if this
3113 -- can be done without violating a specifically given size
3114 -- size clause or causing an unacceptable increase in size.
3116 -- Case of size clause given
3118 if Has_Size_Clause
(Typ
) then
3120 -- Use the inclusive size only if it is consistent with
3121 -- the explicitly specified size.
3123 if Size_Incl_EP
<= RM_Size
(Typ
) then
3124 Actual_Lo
:= Loval_Incl_EP
;
3125 Actual_Hi
:= Hival_Incl_EP
;
3126 Actual_Size
:= Size_Incl_EP
;
3128 -- If the inclusive size is too large, we try excluding
3129 -- the end-points (will be caught later if does not work).
3132 Actual_Lo
:= Loval_Excl_EP
;
3133 Actual_Hi
:= Hival_Excl_EP
;
3134 Actual_Size
:= Size_Excl_EP
;
3137 -- Case of size clause not given
3140 -- If we have a base type whose corresponding first subtype
3141 -- has an explicit size that is large enough to include our
3142 -- end-points, then do so. There is no point in working hard
3143 -- to get a base type whose size is smaller than the specified
3144 -- size of the first subtype.
3146 First_Subt
:= First_Subtype
(Typ
);
3148 if Has_Size_Clause
(First_Subt
)
3149 and then Size_Incl_EP
<= Esize
(First_Subt
)
3151 Actual_Size
:= Size_Incl_EP
;
3152 Actual_Lo
:= Loval_Incl_EP
;
3153 Actual_Hi
:= Hival_Incl_EP
;
3155 -- If excluding the end-points makes the size smaller and
3156 -- results in a size of 8,16,32,64, then we take the smaller
3157 -- size. For the 64 case, this is compulsory. For the other
3158 -- cases, it seems reasonable. We like to include end points
3159 -- if we can, but not at the expense of moving to the next
3160 -- natural boundary of size.
3162 elsif Size_Incl_EP
/= Size_Excl_EP
3164 (Size_Excl_EP
= 8 or else
3165 Size_Excl_EP
= 16 or else
3166 Size_Excl_EP
= 32 or else
3169 Actual_Size
:= Size_Excl_EP
;
3170 Actual_Lo
:= Loval_Excl_EP
;
3171 Actual_Hi
:= Hival_Excl_EP
;
3173 -- Otherwise we can definitely include the end points
3176 Actual_Size
:= Size_Incl_EP
;
3177 Actual_Lo
:= Loval_Incl_EP
;
3178 Actual_Hi
:= Hival_Incl_EP
;
3181 -- One pathological case: normally we never fudge a low
3182 -- bound down, since it would seem to increase the size
3183 -- (if it has any effect), but for ranges containing a
3184 -- single value, or no values, the high bound can be
3185 -- small too large. Consider:
3187 -- type t is delta 2.0**(-14)
3188 -- range 131072.0 .. 0;
3190 -- That lower bound is *just* outside the range of 32
3191 -- bits, and does need fudging down in this case. Note
3192 -- that the bounds will always have crossed here, since
3193 -- the high bound will be fudged down if necessary, as
3196 -- type t is delta 2.0**(-14)
3197 -- range 131072.0 .. 131072.0;
3199 -- So we can detect the situation by looking for crossed
3200 -- bounds, and if the bounds are crossed, and the low
3201 -- bound is greater than zero, we will always back it
3202 -- off by small, since this is completely harmless.
3204 if Actual_Lo
> Actual_Hi
then
3205 if UR_Is_Positive
(Actual_Lo
) then
3206 Actual_Lo
:= Loval_Incl_EP
- Small
;
3207 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
3209 -- And of course, we need to do exactly the same parallel
3210 -- fudge for flat ranges in the negative region.
3212 elsif UR_Is_Negative
(Actual_Hi
) then
3213 Actual_Hi
:= Hival_Incl_EP
+ Small
;
3214 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
3219 Set_Realval
(Lo
, Actual_Lo
);
3220 Set_Realval
(Hi
, Actual_Hi
);
3223 -- For the decimal case, none of this fudging is required, since there
3224 -- are no end-point problems in the decimal case (the end-points are
3225 -- always included).
3228 Actual_Size
:= Fsize
(Loval
, Hival
);
3231 -- At this stage, the actual size has been calculated and the proper
3232 -- required bounds are stored in the low and high bounds.
3234 if Actual_Size
> 64 then
3235 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
3237 ("size required (^) for type& too large, maximum is 64", Typ
);
3241 -- Check size against explicit given size
3243 if Has_Size_Clause
(Typ
) then
3244 if Actual_Size
> RM_Size
(Typ
) then
3245 Error_Msg_Uint_1
:= RM_Size
(Typ
);
3246 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
3248 ("size given (^) for type& too small, minimum is ^",
3249 Size_Clause
(Typ
), Typ
);
3252 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
3255 -- Increase size to next natural boundary if no size clause given
3258 if Actual_Size
<= 8 then
3260 elsif Actual_Size
<= 16 then
3262 elsif Actual_Size
<= 32 then
3268 Init_Esize
(Typ
, Actual_Size
);
3269 Adjust_Esize_For_Alignment
(Typ
);
3272 -- If we have a base type, then expand the bounds so that they
3273 -- extend to the full width of the allocated size in bits, to
3274 -- avoid junk range checks on intermediate computations.
3276 if Base_Type
(Typ
) = Typ
then
3277 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
3278 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
3281 -- Final step is to reanalyze the bounds using the proper type
3282 -- and set the Corresponding_Integer_Value fields of the literals.
3284 Set_Etype
(Lo
, Empty
);
3285 Set_Analyzed
(Lo
, False);
3288 -- Resolve with universal fixed if the base type, and the base
3289 -- type if it is a subtype. Note we can't resolve the base type
3290 -- with itself, that would be a reference before definition.
3293 Resolve
(Lo
, Universal_Fixed
);
3298 -- Set corresponding integer value for bound
3300 Set_Corresponding_Integer_Value
3301 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
3303 -- Similar processing for high bound
3305 Set_Etype
(Hi
, Empty
);
3306 Set_Analyzed
(Hi
, False);
3310 Resolve
(Hi
, Universal_Fixed
);
3315 Set_Corresponding_Integer_Value
3316 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
3318 -- Set type of range to correspond to bounds
3320 Set_Etype
(Rng
, Etype
(Lo
));
3322 -- Set Esize to calculated size and also set RM_Size
3324 Init_Esize
(Typ
, Actual_Size
);
3326 -- Set RM_Size if not already set. If already set, check value
3329 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
3332 if RM_Size
(Typ
) /= Uint_0
then
3333 if RM_Size
(Typ
) < Minsiz
then
3334 Error_Msg_Uint_1
:= RM_Size
(Typ
);
3335 Error_Msg_Uint_2
:= Minsiz
;
3337 ("size given (^) for type& too small, minimum is ^",
3338 Size_Clause
(Typ
), Typ
);
3342 Set_RM_Size
(Typ
, Minsiz
);
3346 end Freeze_Fixed_Point_Type
;
3352 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
3356 Set_Has_Delayed_Freeze
(T
);
3357 L
:= Freeze_Entity
(T
, Sloc
(N
));
3359 if Is_Non_Empty_List
(L
) then
3360 Insert_Actions
(N
, L
);
3364 --------------------------
3365 -- Freeze_Static_Object --
3366 --------------------------
3368 procedure Freeze_Static_Object
(E
: Entity_Id
) is
3370 Cannot_Be_Static
: exception;
3371 -- Exception raised if the type of a static object cannot be made
3372 -- static. This happens if the type depends on non-global objects.
3374 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
3375 -- Called to ensure that an expression used as part of a type
3376 -- definition is statically allocatable, which means that the type
3377 -- of the expression is statically allocatable, and the expression
3378 -- is either static, or a reference to a library level constant.
3380 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
3381 -- Called to mark a type as static, checking that it is possible
3382 -- to set the type as static. If it is not possible, then the
3383 -- exception Cannot_Be_Static is raised.
3385 -----------------------------
3386 -- Ensure_Expression_Is_SA --
3387 -----------------------------
3389 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
3393 Ensure_Type_Is_SA
(Etype
(N
));
3395 if Is_Static_Expression
(N
) then
3398 elsif Nkind
(N
) = N_Identifier
then
3402 and then Ekind
(Ent
) = E_Constant
3403 and then Is_Library_Level_Entity
(Ent
)
3409 raise Cannot_Be_Static
;
3410 end Ensure_Expression_Is_SA
;
3412 -----------------------
3413 -- Ensure_Type_Is_SA --
3414 -----------------------
3416 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
3421 -- If type is library level, we are all set
3423 if Is_Library_Level_Entity
(Typ
) then
3427 -- We are also OK if the type is already marked as statically
3428 -- allocated, which means we processed it before.
3430 if Is_Statically_Allocated
(Typ
) then
3434 -- Mark type as statically allocated
3436 Set_Is_Statically_Allocated
(Typ
);
3438 -- Check that it is safe to statically allocate this type
3440 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
3441 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
3442 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
3444 elsif Is_Array_Type
(Typ
) then
3445 N
:= First_Index
(Typ
);
3446 while Present
(N
) loop
3447 Ensure_Type_Is_SA
(Etype
(N
));
3451 Ensure_Type_Is_SA
(Component_Type
(Typ
));
3453 elsif Is_Access_Type
(Typ
) then
3454 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
3458 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
3461 if T
/= Standard_Void_Type
then
3462 Ensure_Type_Is_SA
(T
);
3465 F
:= First_Formal
(Designated_Type
(Typ
));
3467 while Present
(F
) loop
3468 Ensure_Type_Is_SA
(Etype
(F
));
3474 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
3477 elsif Is_Record_Type
(Typ
) then
3478 C
:= First_Entity
(Typ
);
3480 while Present
(C
) loop
3481 if Ekind
(C
) = E_Discriminant
3482 or else Ekind
(C
) = E_Component
3484 Ensure_Type_Is_SA
(Etype
(C
));
3486 elsif Is_Type
(C
) then
3487 Ensure_Type_Is_SA
(C
);
3493 elsif Ekind
(Typ
) = E_Subprogram_Type
then
3494 Ensure_Type_Is_SA
(Etype
(Typ
));
3496 C
:= First_Formal
(Typ
);
3497 while Present
(C
) loop
3498 Ensure_Type_Is_SA
(Etype
(C
));
3503 raise Cannot_Be_Static
;
3505 end Ensure_Type_Is_SA
;
3507 -- Start of processing for Freeze_Static_Object
3510 Ensure_Type_Is_SA
(Etype
(E
));
3513 when Cannot_Be_Static
=>
3515 -- If the object that cannot be static is imported or exported,
3516 -- then we give an error message saying that this object cannot
3517 -- be imported or exported.
3519 if Is_Imported
(E
) then
3521 ("& cannot be imported (local type is not constant)", E
);
3523 -- Otherwise must be exported, something is wrong if compiler
3524 -- is marking something as statically allocated which cannot be).
3526 else pragma Assert
(Is_Exported
(E
));
3528 ("& cannot be exported (local type is not constant)", E
);
3530 end Freeze_Static_Object
;
3532 -----------------------
3533 -- Freeze_Subprogram --
3534 -----------------------
3536 procedure Freeze_Subprogram
(E
: Entity_Id
) is
3541 -- Subprogram may not have an address clause unless it is imported
3543 if Present
(Address_Clause
(E
)) then
3544 if not Is_Imported
(E
) then
3546 ("address clause can only be given " &
3547 "for imported subprogram",
3548 Name
(Address_Clause
(E
)));
3552 -- For non-foreign convention subprograms, this is where we create
3553 -- the extra formals (for accessibility level and constrained bit
3554 -- information). We delay this till the freeze point precisely so
3555 -- that we know the convention!
3557 if not Has_Foreign_Convention
(E
) then
3558 Create_Extra_Formals
(E
);
3561 -- If this is convention Ada and a Valued_Procedure, that's odd
3563 if Ekind
(E
) = E_Procedure
3564 and then Is_Valued_Procedure
(E
)
3565 and then Convention
(E
) = Convention_Ada
3568 ("?Valued_Procedure has no effect for convention Ada", E
);
3569 Set_Is_Valued_Procedure
(E
, False);
3572 -- Case of foreign convention
3577 -- For foreign conventions, do not permit return of an
3578 -- unconstrained array.
3580 -- Note: we *do* allow a return by descriptor for the VMS case,
3581 -- though here there is probably more to be done ???
3583 if Ekind
(E
) = E_Function
then
3584 Retype
:= Underlying_Type
(Etype
(E
));
3586 -- If no return type, probably some other error, e.g. a
3587 -- missing full declaration, so ignore.
3592 -- If the return type is generic, we have emitted a warning
3593 -- earlier on, and there is nothing else to check here.
3594 -- Specific instantiations may lead to erroneous behavior.
3596 elsif Is_Generic_Type
(Etype
(E
)) then
3599 elsif Is_Array_Type
(Retype
)
3600 and then not Is_Constrained
(Retype
)
3601 and then Mechanism
(E
) not in Descriptor_Codes
3604 ("convention for& does not permit returning " &
3605 "unconstrained array type", E
, E
);
3610 -- If any of the formals for an exported foreign convention
3611 -- subprogram have defaults, then emit an appropriate warning
3612 -- since this is odd (default cannot be used from non-Ada code)
3614 if Is_Exported
(E
) then
3615 F
:= First_Formal
(E
);
3616 while Present
(F
) loop
3617 if Present
(Default_Value
(F
)) then
3619 ("?parameter cannot be defaulted in non-Ada call",
3628 -- For VMS, descriptor mechanisms for parameters are allowed only
3629 -- for imported subprograms.
3631 if OpenVMS_On_Target
then
3632 if not Is_Imported
(E
) then
3633 F
:= First_Formal
(E
);
3634 while Present
(F
) loop
3635 if Mechanism
(F
) in Descriptor_Codes
then
3637 ("descriptor mechanism for parameter not permitted", F
);
3639 ("\can only be used for imported subprogram", F
);
3647 end Freeze_Subprogram
;
3649 -----------------------
3650 -- Is_Fully_Defined --
3651 -----------------------
3653 -- Should this be in Sem_Util ???
3655 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
3657 if Ekind
(T
) = E_Class_Wide_Type
then
3658 return Is_Fully_Defined
(Etype
(T
));
3660 return not Is_Private_Type
(T
)
3661 or else Present
(Full_View
(Base_Type
(T
)));
3663 end Is_Fully_Defined
;
3665 ---------------------------------
3666 -- Process_Default_Expressions --
3667 ---------------------------------
3669 procedure Process_Default_Expressions
3671 After
: in out Node_Id
)
3673 Loc
: constant Source_Ptr
:= Sloc
(E
);
3680 Set_Default_Expressions_Processed
(E
);
3682 -- A subprogram instance and its associated anonymous subprogram
3683 -- share their signature. The default expression functions are defined
3684 -- in the wrapper packages for the anonymous subprogram, and should
3685 -- not be generated again for the instance.
3687 if Is_Generic_Instance
(E
)
3688 and then Present
(Alias
(E
))
3689 and then Default_Expressions_Processed
(Alias
(E
))
3694 Formal
:= First_Formal
(E
);
3696 while Present
(Formal
) loop
3697 if Present
(Default_Value
(Formal
)) then
3699 -- We work with a copy of the default expression because we
3700 -- do not want to disturb the original, since this would mess
3701 -- up the conformance checking.
3703 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
3705 -- The analysis of the expression may generate insert actions,
3706 -- which of course must not be executed. We wrap those actions
3707 -- in a procedure that is not called, and later on eliminated.
3708 -- The following cases have no side-effects, and are analyzed
3711 if Nkind
(Dcopy
) = N_Identifier
3712 or else Nkind
(Dcopy
) = N_Expanded_Name
3713 or else Nkind
(Dcopy
) = N_Integer_Literal
3714 or else (Nkind
(Dcopy
) = N_Real_Literal
3715 and then not Vax_Float
(Etype
(Dcopy
)))
3716 or else Nkind
(Dcopy
) = N_Character_Literal
3717 or else Nkind
(Dcopy
) = N_String_Literal
3718 or else Nkind
(Dcopy
) = N_Null
3719 or else (Nkind
(Dcopy
) = N_Attribute_Reference
3721 Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
3725 -- If there is no default function, we must still do a full
3726 -- analyze call on the default value, to ensure that all
3727 -- error checks are performed, e.g. those associated with
3728 -- static evaluation. Note that this branch will always be
3729 -- taken if the analyzer is turned off (but we still need the
3732 -- Note: the setting of parent here is to meet the requirement
3733 -- that we can only analyze the expression while attached to
3734 -- the tree. Really the requirement is that the parent chain
3735 -- be set, we don't actually need to be in the tree.
3737 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
3740 -- Default expressions are resolved with their own type if the
3741 -- context is generic, to avoid anomalies with private types.
3743 if Ekind
(Scope
(E
)) = E_Generic_Package
then
3744 Resolve
(Dcopy
, Etype
(Dcopy
));
3746 Resolve
(Dcopy
, Etype
(Formal
));
3749 -- If that resolved expression will raise constraint error,
3750 -- then flag the default value as raising constraint error.
3751 -- This allows a proper error message on the calls.
3753 if Raises_Constraint_Error
(Dcopy
) then
3754 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
3757 -- If the default is a parameterless call, we use the name of
3758 -- the called function directly, and there is no body to build.
3760 elsif Nkind
(Dcopy
) = N_Function_Call
3761 and then No
(Parameter_Associations
(Dcopy
))
3765 -- Else construct and analyze the body of a wrapper procedure
3766 -- that contains an object declaration to hold the expression.
3767 -- Given that this is done only to complete the analysis, it
3768 -- simpler to build a procedure than a function which might
3769 -- involve secondary stack expansion.
3773 Make_Defining_Identifier
(Loc
, New_Internal_Name
('D'));
3776 Make_Subprogram_Body
(Loc
,
3778 Make_Procedure_Specification
(Loc
,
3779 Defining_Unit_Name
=> Dnam
),
3781 Declarations
=> New_List
(
3782 Make_Object_Declaration
(Loc
,
3783 Defining_Identifier
=>
3784 Make_Defining_Identifier
(Loc
,
3785 New_Internal_Name
('T')),
3786 Object_Definition
=>
3787 New_Occurrence_Of
(Etype
(Formal
), Loc
),
3788 Expression
=> New_Copy_Tree
(Dcopy
))),
3790 Handled_Statement_Sequence
=>
3791 Make_Handled_Sequence_Of_Statements
(Loc
,
3792 Statements
=> New_List
));
3794 Set_Scope
(Dnam
, Scope
(E
));
3795 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
3796 Set_Is_Eliminated
(Dnam
);
3797 Insert_After
(After
, Dbody
);
3803 Next_Formal
(Formal
);
3806 end Process_Default_Expressions
;
3808 ----------------------------------------
3809 -- Set_Component_Alignment_If_Not_Set --
3810 ----------------------------------------
3812 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
3814 -- Ignore if not base type, subtypes don't need anything
3816 if Typ
/= Base_Type
(Typ
) then
3820 -- Do not override existing representation
3822 if Is_Packed
(Typ
) then
3825 elsif Has_Specified_Layout
(Typ
) then
3828 elsif Component_Alignment
(Typ
) /= Calign_Default
then
3832 Set_Component_Alignment
3833 (Typ
, Scope_Stack
.Table
3834 (Scope_Stack
.Last
).Component_Alignment_Default
);
3836 end Set_Component_Alignment_If_Not_Set
;
3838 ---------------------------
3839 -- Set_Debug_Info_Needed --
3840 ---------------------------
3842 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
3845 or else Needs_Debug_Info
(T
)
3846 or else Debug_Info_Off
(T
)
3850 Set_Needs_Debug_Info
(T
);
3853 if Is_Object
(T
) then
3854 Set_Debug_Info_Needed
(Etype
(T
));
3856 elsif Is_Type
(T
) then
3857 Set_Debug_Info_Needed
(Etype
(T
));
3859 if Is_Record_Type
(T
) then
3861 Ent
: Entity_Id
:= First_Entity
(T
);
3863 while Present
(Ent
) loop
3864 Set_Debug_Info_Needed
(Ent
);
3869 elsif Is_Array_Type
(T
) then
3870 Set_Debug_Info_Needed
(Component_Type
(T
));
3873 Indx
: Node_Id
:= First_Index
(T
);
3875 while Present
(Indx
) loop
3876 Set_Debug_Info_Needed
(Etype
(Indx
));
3877 Indx
:= Next_Index
(Indx
);
3881 if Is_Packed
(T
) then
3882 Set_Debug_Info_Needed
(Packed_Array_Type
(T
));
3885 elsif Is_Access_Type
(T
) then
3886 Set_Debug_Info_Needed
(Directly_Designated_Type
(T
));
3888 elsif Is_Private_Type
(T
) then
3889 Set_Debug_Info_Needed
(Full_View
(T
));
3891 elsif Is_Protected_Type
(T
) then
3892 Set_Debug_Info_Needed
(Corresponding_Record_Type
(T
));
3896 end Set_Debug_Info_Needed
;