1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Ch7
; use Exp_Ch7
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Pakd
; use Exp_Pakd
;
35 with Exp_Util
; use Exp_Util
;
36 with Exp_Tss
; use Exp_Tss
;
37 with Layout
; use Layout
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Nlists
; use Nlists
;
40 with Nmake
; use Nmake
;
42 with Restrict
; use Restrict
;
43 with Rident
; use Rident
;
45 with Sem_Cat
; use Sem_Cat
;
46 with Sem_Ch6
; use Sem_Ch6
;
47 with Sem_Ch7
; use Sem_Ch7
;
48 with Sem_Ch8
; use Sem_Ch8
;
49 with Sem_Ch13
; use Sem_Ch13
;
50 with Sem_Eval
; use Sem_Eval
;
51 with Sem_Mech
; use Sem_Mech
;
52 with Sem_Prag
; use Sem_Prag
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Util
; use Sem_Util
;
55 with Sinfo
; use Sinfo
;
56 with Snames
; use Snames
;
57 with Stand
; use Stand
;
58 with Targparm
; use Targparm
;
59 with Tbuild
; use Tbuild
;
60 with Ttypes
; use Ttypes
;
61 with Uintp
; use Uintp
;
62 with Urealp
; use Urealp
;
64 package body Freeze
is
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
71 -- Typ is a type that is being frozen. If no size clause is given,
72 -- but a default Esize has been computed, then this default Esize is
73 -- adjusted up if necessary to be consistent with a given alignment,
74 -- but never to a value greater than Long_Long_Integer'Size. This
75 -- is used for all discrete types and for fixed-point types.
77 procedure Build_And_Analyze_Renamed_Body
80 After
: in out Node_Id
);
81 -- Build body for a renaming declaration, insert in tree and analyze.
83 procedure Check_Address_Clause
(E
: Entity_Id
);
84 -- Apply legality checks to address clauses for object declarations,
85 -- at the point the object is frozen.
87 procedure Check_Strict_Alignment
(E
: Entity_Id
);
88 -- E is a base type. If E is tagged or has a component that is aliased
89 -- or tagged or contains something this is aliased or tagged, set
92 procedure Check_Unsigned_Type
(E
: Entity_Id
);
93 pragma Inline
(Check_Unsigned_Type
);
94 -- If E is a fixed-point or discrete type, then all the necessary work
95 -- to freeze it is completed except for possible setting of the flag
96 -- Is_Unsigned_Type, which is done by this procedure. The call has no
97 -- effect if the entity E is not a discrete or fixed-point type.
99 procedure Freeze_And_Append
102 Result
: in out List_Id
);
103 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
104 -- nodes to Result, modifying Result from No_List if necessary.
106 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
107 -- Freeze enumeration type. The Esize field is set as processing
108 -- proceeds (i.e. set by default when the type is declared and then
109 -- adjusted by rep clauses. What this procedure does is to make sure
110 -- that if a foreign convention is specified, and no specific size
111 -- is given, then the size must be at least Integer'Size.
113 procedure Freeze_Static_Object
(E
: Entity_Id
);
114 -- If an object is frozen which has Is_Statically_Allocated set, then
115 -- all referenced types must also be marked with this flag. This routine
116 -- is in charge of meeting this requirement for the object entity E.
118 procedure Freeze_Subprogram
(E
: Entity_Id
);
119 -- Perform freezing actions for a subprogram (create extra formals,
120 -- and set proper default mechanism values). Note that this routine
121 -- is not called for internal subprograms, for which neither of these
122 -- actions is needed (or desirable, we do not want for example to have
123 -- these extra formals present in initialization procedures, where they
124 -- would serve no purpose). In this call E is either a subprogram or
125 -- a subprogram type (i.e. an access to a subprogram).
127 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
128 -- True if T is not private and has no private components, or has a full
129 -- view. Used to determine whether the designated type of an access type
130 -- should be frozen when the access type is frozen. This is done when an
131 -- allocator is frozen, or an expression that may involve attributes of
132 -- the designated type. Otherwise freezing the access type does not freeze
133 -- the designated type.
135 procedure Process_Default_Expressions
137 After
: in out Node_Id
);
138 -- This procedure is called for each subprogram to complete processing
139 -- of default expressions at the point where all types are known to be
140 -- frozen. The expressions must be analyzed in full, to make sure that
141 -- all error processing is done (they have only been pre-analyzed). If
142 -- the expression is not an entity or literal, its analysis may generate
143 -- code which must not be executed. In that case we build a function
144 -- body to hold that code. This wrapper function serves no other purpose
145 -- (it used to be called to evaluate the default, but now the default is
146 -- inlined at each point of call).
148 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
149 -- Typ is a record or array type that is being frozen. This routine
150 -- sets the default component alignment from the scope stack values
151 -- if the alignment is otherwise not specified.
153 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
154 -- As each entity is frozen, this routine is called to deal with the
155 -- setting of Debug_Info_Needed for the entity. This flag is set if
156 -- the entity comes from source, or if we are in Debug_Generated_Code
157 -- mode or if the -gnatdV debug flag is set. However, it never sets
158 -- the flag if Debug_Info_Off is set.
160 procedure Set_Debug_Info_Needed
(T
: Entity_Id
);
161 -- Sets the Debug_Info_Needed flag on entity T if not already set, and
162 -- also on any entities that are needed by T (for an object, the type
163 -- of the object is needed, and for a type, the subsidiary types are
164 -- needed -- see body for details). Never has any effect on T if the
165 -- Debug_Info_Off flag is set.
167 procedure Undelay_Type
(T
: Entity_Id
);
168 -- T is a type of a component that we know to be an Itype.
169 -- We don't want this to have a Freeze_Node, so ensure it doesn't.
170 -- Do the same for any Full_View or Corresponding_Record_Type.
172 procedure Warn_Overlay
176 -- Expr is the expression for an address clause for entity Nam whose type
177 -- is Typ. If Typ has a default initialization, and there is no explicit
178 -- initialization in the source declaration, check whether the address
179 -- clause might cause overlaying of an entity, and emit a warning on the
180 -- side effect that the initialization will cause.
182 -------------------------------
183 -- Adjust_Esize_For_Alignment --
184 -------------------------------
186 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
190 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
191 Align
:= Alignment_In_Bits
(Typ
);
193 if Align
> Esize
(Typ
)
194 and then Align
<= Standard_Long_Long_Integer_Size
196 Set_Esize
(Typ
, Align
);
199 end Adjust_Esize_For_Alignment
;
201 ------------------------------------
202 -- Build_And_Analyze_Renamed_Body --
203 ------------------------------------
205 procedure Build_And_Analyze_Renamed_Body
208 After
: in out Node_Id
)
210 Body_Node
: constant Node_Id
:= Build_Renamed_Body
(Decl
, New_S
);
213 Insert_After
(After
, Body_Node
);
214 Mark_Rewrite_Insertion
(Body_Node
);
217 end Build_And_Analyze_Renamed_Body
;
219 ------------------------
220 -- Build_Renamed_Body --
221 ------------------------
223 function Build_Renamed_Body
225 New_S
: Entity_Id
) return Node_Id
227 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
228 -- We use for the source location of the renamed body, the location
229 -- of the spec entity. It might seem more natural to use the location
230 -- of the renaming declaration itself, but that would be wrong, since
231 -- then the body we create would look as though it was created far
232 -- too late, and this could cause problems with elaboration order
233 -- analysis, particularly in connection with instantiations.
235 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
236 Nam
: constant Node_Id
:= Name
(N
);
238 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
239 Actuals
: List_Id
:= No_List
;
244 O_Formal
: Entity_Id
;
245 Param_Spec
: Node_Id
;
248 -- Determine the entity being renamed, which is the target of the
249 -- call statement. If the name is an explicit dereference, this is
250 -- a renaming of a subprogram type rather than a subprogram. The
251 -- name itself is fully analyzed.
253 if Nkind
(Nam
) = N_Selected_Component
then
254 Old_S
:= Entity
(Selector_Name
(Nam
));
256 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
257 Old_S
:= Etype
(Nam
);
259 elsif Nkind
(Nam
) = N_Indexed_Component
then
260 if Is_Entity_Name
(Prefix
(Nam
)) then
261 Old_S
:= Entity
(Prefix
(Nam
));
263 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
266 elsif Nkind
(Nam
) = N_Character_Literal
then
267 Old_S
:= Etype
(New_S
);
270 Old_S
:= Entity
(Nam
);
273 if Is_Entity_Name
(Nam
) then
275 -- If the renamed entity is a predefined operator, retain full
276 -- name to ensure its visibility.
278 if Ekind
(Old_S
) = E_Operator
279 and then Nkind
(Nam
) = N_Expanded_Name
281 Call_Name
:= New_Copy
(Name
(N
));
283 Call_Name
:= New_Reference_To
(Old_S
, Loc
);
287 Call_Name
:= New_Copy
(Name
(N
));
289 -- The original name may have been overloaded, but
290 -- is fully resolved now.
292 Set_Is_Overloaded
(Call_Name
, False);
295 -- For simple renamings, subsequent calls can be expanded directly
296 -- as called to the renamed entity. The body must be generated in
297 -- any case for calls they may appear elsewhere.
299 if (Ekind
(Old_S
) = E_Function
300 or else Ekind
(Old_S
) = E_Procedure
)
301 and then Nkind
(Decl
) = N_Subprogram_Declaration
303 Set_Body_To_Inline
(Decl
, Old_S
);
306 -- The body generated for this renaming is an internal artifact, and
307 -- does not constitute a freeze point for the called entity.
309 Set_Must_Not_Freeze
(Call_Name
);
311 Formal
:= First_Formal
(Defining_Entity
(Decl
));
313 if Present
(Formal
) then
316 while Present
(Formal
) loop
317 Append
(New_Reference_To
(Formal
, Loc
), Actuals
);
318 Next_Formal
(Formal
);
322 -- If the renamed entity is an entry, inherit its profile. For
323 -- other renamings as bodies, both profiles must be subtype
324 -- conformant, so it is not necessary to replace the profile given
325 -- in the declaration. However, default values that are aggregates
326 -- are rewritten when partially analyzed, so we recover the original
327 -- aggregate to insure that subsequent conformity checking works.
328 -- Similarly, if the default expression was constant-folded, recover
329 -- the original expression.
331 Formal
:= First_Formal
(Defining_Entity
(Decl
));
333 if Present
(Formal
) then
334 O_Formal
:= First_Formal
(Old_S
);
335 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
337 while Present
(Formal
) loop
338 if Is_Entry
(Old_S
) then
340 if Nkind
(Parameter_Type
(Param_Spec
)) /=
343 Set_Etype
(Formal
, Etype
(O_Formal
));
344 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
347 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
348 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
349 Nkind
(Default_Value
(O_Formal
))
351 Set_Expression
(Param_Spec
,
352 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
355 Next_Formal
(Formal
);
356 Next_Formal
(O_Formal
);
361 -- If the renamed entity is a function, the generated body contains a
362 -- return statement. Otherwise, build a procedure call. If the entity is
363 -- an entry, subsequent analysis of the call will transform it into the
364 -- proper entry or protected operation call. If the renamed entity is
365 -- a character literal, return it directly.
367 if Ekind
(Old_S
) = E_Function
368 or else Ekind
(Old_S
) = E_Operator
369 or else (Ekind
(Old_S
) = E_Subprogram_Type
370 and then Etype
(Old_S
) /= Standard_Void_Type
)
373 Make_Return_Statement
(Loc
,
375 Make_Function_Call
(Loc
,
377 Parameter_Associations
=> Actuals
));
379 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
381 Make_Return_Statement
(Loc
,
382 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
384 elsif Nkind
(Nam
) = N_Character_Literal
then
386 Make_Return_Statement
(Loc
,
387 Expression
=> Call_Name
);
391 Make_Procedure_Call_Statement
(Loc
,
393 Parameter_Associations
=> Actuals
);
396 -- Create entities for subprogram body and formals.
398 Set_Defining_Unit_Name
(Spec
,
399 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
401 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
403 while Present
(Param_Spec
) loop
404 Set_Defining_Identifier
(Param_Spec
,
405 Make_Defining_Identifier
(Loc
,
406 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
411 Make_Subprogram_Body
(Loc
,
412 Specification
=> Spec
,
413 Declarations
=> New_List
,
414 Handled_Statement_Sequence
=>
415 Make_Handled_Sequence_Of_Statements
(Loc
,
416 Statements
=> New_List
(Call_Node
)));
418 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
420 Make_Subprogram_Declaration
(Loc
,
421 Specification
=> Specification
(N
)));
424 -- Link the body to the entity whose declaration it completes. If
425 -- the body is analyzed when the renamed entity is frozen, it may be
426 -- necessary to restore the proper scope (see package Exp_Ch13).
428 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
429 and then Present
(Corresponding_Spec
(N
))
431 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
433 Set_Corresponding_Spec
(Body_Node
, New_S
);
437 end Build_Renamed_Body
;
439 --------------------------
440 -- Check_Address_Clause --
441 --------------------------
443 procedure Check_Address_Clause
(E
: Entity_Id
) is
444 Addr
: constant Node_Id
:= Address_Clause
(E
);
446 Decl
: constant Node_Id
:= Declaration_Node
(E
);
447 Typ
: constant Entity_Id
:= Etype
(E
);
450 if Present
(Addr
) then
451 Expr
:= Expression
(Addr
);
453 -- If we have no initialization of any kind, then we don't
454 -- need to place any restrictions on the address clause, because
455 -- the object will be elaborated after the address clause is
456 -- evaluated. This happens if the declaration has no initial
457 -- expression, or the type has no implicit initialization, or
458 -- the object is imported.
460 -- The same holds for all initialized scalar types and all
461 -- access types. Packed bit arrays of size up to 64 are
462 -- represented using a modular type with an initialization
463 -- (to zero) and can be processed like other initialized
466 -- If the type is controlled, code to attach the object to a
467 -- finalization chain is generated at the point of declaration,
468 -- and therefore the elaboration of the object cannot be delayed:
469 -- the address expression must be a constant.
471 if (No
(Expression
(Decl
))
472 and then not Controlled_Type
(Typ
)
474 (not Has_Non_Null_Base_Init_Proc
(Typ
)
475 or else Is_Imported
(E
)))
478 (Present
(Expression
(Decl
))
479 and then Is_Scalar_Type
(Typ
))
485 (Is_Bit_Packed_Array
(Typ
)
487 Is_Modular_Integer_Type
(Packed_Array_Type
(Typ
)))
491 -- Otherwise, we require the address clause to be constant
492 -- because the call to the initialization procedure (or the
493 -- attach code) has to happen at the point of the declaration.
496 Check_Constant_Address_Clause
(Expr
, E
);
497 Set_Has_Delayed_Freeze
(E
, False);
500 if not Error_Posted
(Expr
)
501 and then not Controlled_Type
(Typ
)
503 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
506 end Check_Address_Clause
;
508 -----------------------------
509 -- Check_Compile_Time_Size --
510 -----------------------------
512 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
514 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
515 -- Sets the compile time known size (32 bits or less) in the Esize
516 -- field, of T checking for a size clause that was given which attempts
517 -- to give a smaller size.
519 function Size_Known
(T
: Entity_Id
) return Boolean;
520 -- Recursive function that does all the work
522 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
523 -- If T is a constrained subtype, its size is not known if any of its
524 -- discriminant constraints is not static and it is not a null record.
525 -- The test is conservative and doesn't check that the components are
526 -- in fact constrained by non-static discriminant values. Could be made
533 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
538 elsif Has_Size_Clause
(T
) then
539 if RM_Size
(T
) < S
then
540 Error_Msg_Uint_1
:= S
;
542 ("size for & is too small, minimum is ^",
545 elsif Unknown_Esize
(T
) then
549 -- Set sizes if not set already
552 if Unknown_Esize
(T
) then
556 if Unknown_RM_Size
(T
) then
566 function Size_Known
(T
: Entity_Id
) return Boolean is
574 if Size_Known_At_Compile_Time
(T
) then
577 elsif Is_Scalar_Type
(T
)
578 or else Is_Task_Type
(T
)
580 return not Is_Generic_Type
(T
);
582 elsif Is_Array_Type
(T
) then
583 if Ekind
(T
) = E_String_Literal_Subtype
then
584 Set_Small_Size
(T
, Component_Size
(T
)
585 * String_Literal_Length
(T
));
588 elsif not Is_Constrained
(T
) then
591 -- Don't do any recursion on type with error posted, since
592 -- we may have a malformed type that leads us into a loop
594 elsif Error_Posted
(T
) then
597 elsif not Size_Known
(Component_Type
(T
)) then
601 -- Check for all indexes static, and also compute possible
602 -- size (in case it is less than 32 and may be packable).
605 Esiz
: Uint
:= Component_Size
(T
);
609 Index
:= First_Index
(T
);
610 while Present
(Index
) loop
611 if Nkind
(Index
) = N_Range
then
612 Get_Index_Bounds
(Index
, Low
, High
);
614 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
618 Low
:= Type_Low_Bound
(Etype
(Index
));
619 High
:= Type_High_Bound
(Etype
(Index
));
622 if not Compile_Time_Known_Value
(Low
)
623 or else not Compile_Time_Known_Value
(High
)
624 or else Etype
(Index
) = Any_Type
629 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
641 Set_Small_Size
(T
, Esiz
);
645 elsif Is_Access_Type
(T
) then
648 elsif Is_Private_Type
(T
)
649 and then not Is_Generic_Type
(T
)
650 and then Present
(Underlying_Type
(T
))
652 -- Don't do any recursion on type with error posted, since
653 -- we may have a malformed type that leads us into a loop
655 if Error_Posted
(T
) then
658 return Size_Known
(Underlying_Type
(T
));
661 elsif Is_Record_Type
(T
) then
663 -- A class-wide type is never considered to have a known size
665 if Is_Class_Wide_Type
(T
) then
668 -- A subtype of a variant record must not have non-static
669 -- discriminanted components.
671 elsif T
/= Base_Type
(T
)
672 and then not Static_Discriminated_Components
(T
)
676 -- Don't do any recursion on type with error posted, since
677 -- we may have a malformed type that leads us into a loop
679 elsif Error_Posted
(T
) then
683 -- Now look at the components of the record
686 -- The following two variables are used to keep track of
687 -- the size of packed records if we can tell the size of
688 -- the packed record in the front end. Packed_Size_Known
689 -- is True if so far we can figure out the size. It is
690 -- initialized to True for a packed record, unless the
691 -- record has discriminants. The reason we eliminate the
692 -- discriminated case is that we don't know the way the
693 -- back end lays out discriminated packed records. If
694 -- Packed_Size_Known is True, then Packed_Size is the
695 -- size in bits so far.
697 Packed_Size_Known
: Boolean :=
699 and then not Has_Discriminants
(T
);
701 Packed_Size
: Uint
:= Uint_0
;
704 -- Test for variant part present
706 if Has_Discriminants
(T
)
707 and then Present
(Parent
(T
))
708 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
709 and then Nkind
(Type_Definition
(Parent
(T
))) =
711 and then not Null_Present
(Type_Definition
(Parent
(T
)))
712 and then Present
(Variant_Part
713 (Component_List
(Type_Definition
(Parent
(T
)))))
715 -- If variant part is present, and type is unconstrained,
716 -- then we must have defaulted discriminants, or a size
717 -- clause must be present for the type, or else the size
718 -- is definitely not known at compile time.
720 if not Is_Constrained
(T
)
722 No
(Discriminant_Default_Value
723 (First_Discriminant
(T
)))
724 and then Unknown_Esize
(T
)
730 -- Loop through components
732 Comp
:= First_Entity
(T
);
733 while Present
(Comp
) loop
734 if Ekind
(Comp
) = E_Component
736 Ekind
(Comp
) = E_Discriminant
738 Ctyp
:= Etype
(Comp
);
740 -- We do not know the packed size if there is a
741 -- component clause present (we possibly could,
742 -- but this would only help in the case of a record
743 -- with partial rep clauses. That's because in the
744 -- case of full rep clauses, the size gets figured
745 -- out anyway by a different circuit).
747 if Present
(Component_Clause
(Comp
)) then
748 Packed_Size_Known
:= False;
751 -- We need to identify a component that is an array
752 -- where the index type is an enumeration type with
753 -- non-standard representation, and some bound of the
754 -- type depends on a discriminant.
756 -- This is because gigi computes the size by doing a
757 -- substituation of the appropriate discriminant value
758 -- in the size expression for the base type, and gigi
759 -- is not clever enough to evaluate the resulting
760 -- expression (which involves a call to rep_to_pos)
763 -- It would be nice if gigi would either recognize that
764 -- this expression can be computed at compile time, or
765 -- alternatively figured out the size from the subtype
766 -- directly, where all the information is at hand ???
768 if Is_Array_Type
(Etype
(Comp
))
769 and then Present
(Packed_Array_Type
(Etype
(Comp
)))
772 Ocomp
: constant Entity_Id
:=
773 Original_Record_Component
(Comp
);
774 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
780 Ind
:= First_Index
(OCtyp
);
781 while Present
(Ind
) loop
782 Indtyp
:= Etype
(Ind
);
784 if Is_Enumeration_Type
(Indtyp
)
785 and then Has_Non_Standard_Rep
(Indtyp
)
787 Lo
:= Type_Low_Bound
(Indtyp
);
788 Hi
:= Type_High_Bound
(Indtyp
);
790 if Is_Entity_Name
(Lo
)
792 Ekind
(Entity
(Lo
)) = E_Discriminant
796 elsif Is_Entity_Name
(Hi
)
798 Ekind
(Entity
(Hi
)) = E_Discriminant
809 -- Clearly size of record is not known if the size of
810 -- one of the components is not known.
812 if not Size_Known
(Ctyp
) then
816 -- Accumulate packed size if possible
818 if Packed_Size_Known
then
820 -- We can only deal with elementary types, since for
821 -- non-elementary components, alignment enters into
822 -- the picture, and we don't know enough to handle
823 -- proper alignment in this context. Packed arrays
824 -- count as elementary if the representation is a
827 if Is_Elementary_Type
(Ctyp
)
828 or else (Is_Array_Type
(Ctyp
)
830 Present
(Packed_Array_Type
(Ctyp
))
832 Is_Modular_Integer_Type
833 (Packed_Array_Type
(Ctyp
)))
835 -- If RM_Size is known and static, then we can
836 -- keep accumulating the packed size.
838 if Known_Static_RM_Size
(Ctyp
) then
840 -- A little glitch, to be removed sometime ???
841 -- gigi does not understand zero sizes yet.
843 if RM_Size
(Ctyp
) = Uint_0
then
844 Packed_Size_Known
:= False;
846 -- Normal case where we can keep accumulating
847 -- the packed array size.
850 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
853 -- If we have a field whose RM_Size is not known
854 -- then we can't figure out the packed size here.
857 Packed_Size_Known
:= False;
860 -- If we have a non-elementary type we can't figure
861 -- out the packed array size (alignment issues).
864 Packed_Size_Known
:= False;
872 if Packed_Size_Known
then
873 Set_Small_Size
(T
, Packed_Size
);
884 -------------------------------------
885 -- Static_Discriminated_Components --
886 -------------------------------------
888 function Static_Discriminated_Components
889 (T
: Entity_Id
) return Boolean
891 Constraint
: Elmt_Id
;
894 if Has_Discriminants
(T
)
895 and then Present
(Discriminant_Constraint
(T
))
896 and then Present
(First_Component
(T
))
898 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
899 while Present
(Constraint
) loop
900 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
904 Next_Elmt
(Constraint
);
909 end Static_Discriminated_Components
;
911 -- Start of processing for Check_Compile_Time_Size
914 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
915 end Check_Compile_Time_Size
;
917 -----------------------------
918 -- Check_Debug_Info_Needed --
919 -----------------------------
921 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
923 if Needs_Debug_Info
(T
) or else Debug_Info_Off
(T
) then
926 elsif Comes_From_Source
(T
)
927 or else Debug_Generated_Code
928 or else Debug_Flag_VV
930 Set_Debug_Info_Needed
(T
);
932 end Check_Debug_Info_Needed
;
934 ----------------------------
935 -- Check_Strict_Alignment --
936 ----------------------------
938 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
942 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
943 Set_Strict_Alignment
(E
);
945 elsif Is_Array_Type
(E
) then
946 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
948 elsif Is_Record_Type
(E
) then
949 if Is_Limited_Record
(E
) then
950 Set_Strict_Alignment
(E
);
954 Comp
:= First_Component
(E
);
956 while Present
(Comp
) loop
957 if not Is_Type
(Comp
)
958 and then (Strict_Alignment
(Etype
(Comp
))
959 or else Is_Aliased
(Comp
))
961 Set_Strict_Alignment
(E
);
965 Next_Component
(Comp
);
968 end Check_Strict_Alignment
;
970 -------------------------
971 -- Check_Unsigned_Type --
972 -------------------------
974 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
975 Ancestor
: Entity_Id
;
980 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
984 -- Do not attempt to analyze case where range was in error
986 if Error_Posted
(Scalar_Range
(E
)) then
990 -- The situation that is non trivial is something like
992 -- subtype x1 is integer range -10 .. +10;
993 -- subtype x2 is x1 range 0 .. V1;
994 -- subtype x3 is x2 range V2 .. V3;
995 -- subtype x4 is x3 range V4 .. V5;
997 -- where Vn are variables. Here the base type is signed, but we still
998 -- know that x4 is unsigned because of the lower bound of x2.
1000 -- The only way to deal with this is to look up the ancestor chain
1004 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1008 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1010 if Compile_Time_Known_Value
(Lo_Bound
) then
1012 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1013 Set_Is_Unsigned_Type
(E
, True);
1019 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1021 -- If no ancestor had a static lower bound, go to base type
1023 if No
(Ancestor
) then
1025 -- Note: the reason we still check for a compile time known
1026 -- value for the base type is that at least in the case of
1027 -- generic formals, we can have bounds that fail this test,
1028 -- and there may be other cases in error situations.
1030 Btyp
:= Base_Type
(E
);
1032 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1036 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1038 if Compile_Time_Known_Value
(Lo_Bound
)
1039 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1041 Set_Is_Unsigned_Type
(E
, True);
1048 end Check_Unsigned_Type
;
1050 -----------------------------
1051 -- Expand_Atomic_Aggregate --
1052 -----------------------------
1054 procedure Expand_Atomic_Aggregate
(E
: Entity_Id
; Typ
: Entity_Id
) is
1055 Loc
: constant Source_Ptr
:= Sloc
(E
);
1060 if (Nkind
(Parent
(E
)) = N_Object_Declaration
1061 or else Nkind
(Parent
(E
)) = N_Assignment_Statement
)
1062 and then Comes_From_Source
(Parent
(E
))
1063 and then Nkind
(E
) = N_Aggregate
1066 Make_Defining_Identifier
(Loc
,
1067 New_Internal_Name
('T'));
1070 Make_Object_Declaration
(Loc
,
1071 Defining_Identifier
=> Temp
,
1072 Object_definition
=> New_Occurrence_Of
(Typ
, Loc
),
1073 Expression
=> Relocate_Node
(E
));
1074 Insert_Before
(Parent
(E
), New_N
);
1077 Set_Expression
(Parent
(E
), New_Occurrence_Of
(Temp
, Loc
));
1079 -- To prevent the temporary from being constant-folded (which
1080 -- would lead to the same piecemeal assignment on the original
1081 -- target) indicate to the back-end that the temporary is a
1082 -- variable with real storage. See description of this flag
1083 -- in Einfo, and the notes on N_Assignment_Statement and
1084 -- N_Object_Declaration in Sinfo.
1086 Set_Is_True_Constant
(Temp
, False);
1088 end Expand_Atomic_Aggregate
;
1094 -- Note: the easy coding for this procedure would be to just build a
1095 -- single list of freeze nodes and then insert them and analyze them
1096 -- all at once. This won't work, because the analysis of earlier freeze
1097 -- nodes may recursively freeze types which would otherwise appear later
1098 -- on in the freeze list. So we must analyze and expand the freeze nodes
1099 -- as they are generated.
1101 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1102 Loc
: constant Source_Ptr
:= Sloc
(After
);
1106 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1107 -- This is the internal recursive routine that does freezing of
1108 -- entities (but NOT the analysis of default expressions, which
1109 -- should not be recursive, we don't want to analyze those till
1110 -- we are sure that ALL the types are frozen).
1112 --------------------
1113 -- Freeze_All_Ent --
1114 --------------------
1116 procedure Freeze_All_Ent
1118 After
: in out Node_Id
)
1124 procedure Process_Flist
;
1125 -- If freeze nodes are present, insert and analyze, and reset
1126 -- cursor for next insertion.
1132 procedure Process_Flist
is
1134 if Is_Non_Empty_List
(Flist
) then
1135 Lastn
:= Next
(After
);
1136 Insert_List_After_And_Analyze
(After
, Flist
);
1138 if Present
(Lastn
) then
1139 After
:= Prev
(Lastn
);
1141 After
:= Last
(List_Containing
(After
));
1146 -- Start or processing for Freeze_All_Ent
1150 while Present
(E
) loop
1152 -- If the entity is an inner package which is not a package
1153 -- renaming, then its entities must be frozen at this point.
1154 -- Note that such entities do NOT get frozen at the end of
1155 -- the nested package itself (only library packages freeze).
1157 -- Same is true for task declarations, where anonymous records
1158 -- created for entry parameters must be frozen.
1160 if Ekind
(E
) = E_Package
1161 and then No
(Renamed_Object
(E
))
1162 and then not Is_Child_Unit
(E
)
1163 and then not Is_Frozen
(E
)
1166 Install_Visible_Declarations
(E
);
1167 Install_Private_Declarations
(E
);
1169 Freeze_All
(First_Entity
(E
), After
);
1171 End_Package_Scope
(E
);
1173 elsif Ekind
(E
) in Task_Kind
1175 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
1177 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
1180 Freeze_All
(First_Entity
(E
), After
);
1183 -- For a derived tagged type, we must ensure that all the
1184 -- primitive operations of the parent have been frozen, so
1185 -- that their addresses will be in the parent's dispatch table
1186 -- at the point it is inherited.
1188 elsif Ekind
(E
) = E_Record_Type
1189 and then Is_Tagged_Type
(E
)
1190 and then Is_Tagged_Type
(Etype
(E
))
1191 and then Is_Derived_Type
(E
)
1194 Prim_List
: constant Elist_Id
:=
1195 Primitive_Operations
(Etype
(E
));
1201 Prim
:= First_Elmt
(Prim_List
);
1203 while Present
(Prim
) loop
1204 Subp
:= Node
(Prim
);
1206 if Comes_From_Source
(Subp
)
1207 and then not Is_Frozen
(Subp
)
1209 Flist
:= Freeze_Entity
(Subp
, Loc
);
1218 if not Is_Frozen
(E
) then
1219 Flist
:= Freeze_Entity
(E
, Loc
);
1223 -- If an incomplete type is still not frozen, this may be
1224 -- a premature freezing because of a body declaration that
1225 -- follows. Indicate where the freezing took place.
1227 -- If the freezing is caused by the end of the current
1228 -- declarative part, it is a Taft Amendment type, and there
1231 if not Is_Frozen
(E
)
1232 and then Ekind
(E
) = E_Incomplete_Type
1235 Bod
: constant Node_Id
:= Next
(After
);
1238 if (Nkind
(Bod
) = N_Subprogram_Body
1239 or else Nkind
(Bod
) = N_Entry_Body
1240 or else Nkind
(Bod
) = N_Package_Body
1241 or else Nkind
(Bod
) = N_Protected_Body
1242 or else Nkind
(Bod
) = N_Task_Body
1243 or else Nkind
(Bod
) in N_Body_Stub
)
1245 List_Containing
(After
) = List_Containing
(Parent
(E
))
1247 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1249 ("type& is frozen# before its full declaration",
1259 -- Start of processing for Freeze_All
1262 Freeze_All_Ent
(From
, After
);
1264 -- Now that all types are frozen, we can deal with default expressions
1265 -- that require us to build a default expression functions. This is the
1266 -- point at which such functions are constructed (after all types that
1267 -- might be used in such expressions have been frozen).
1269 -- We also add finalization chains to access types whose designated
1270 -- types are controlled. This is normally done when freezing the type,
1271 -- but this misses recursive type definitions where the later members
1272 -- of the recursion introduce controlled components (e.g. 5624-001).
1274 -- Loop through entities
1277 while Present
(E
) loop
1278 if Is_Subprogram
(E
) then
1280 if not Default_Expressions_Processed
(E
) then
1281 Process_Default_Expressions
(E
, After
);
1284 if not Has_Completion
(E
) then
1285 Decl
:= Unit_Declaration_Node
(E
);
1287 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1288 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1290 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1291 and then Present
(Corresponding_Body
(Decl
))
1293 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1294 = N_Subprogram_Renaming_Declaration
1296 Build_And_Analyze_Renamed_Body
1297 (Decl
, Corresponding_Body
(Decl
), After
);
1301 elsif Ekind
(E
) in Task_Kind
1303 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
1305 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
1310 Ent
:= First_Entity
(E
);
1312 while Present
(Ent
) loop
1315 and then not Default_Expressions_Processed
(Ent
)
1317 Process_Default_Expressions
(Ent
, After
);
1324 elsif Is_Access_Type
(E
)
1325 and then Comes_From_Source
(E
)
1326 and then Ekind
(Directly_Designated_Type
(E
)) = E_Incomplete_Type
1327 and then Controlled_Type
(Designated_Type
(E
))
1328 and then No
(Associated_Final_Chain
(E
))
1330 Build_Final_List
(Parent
(E
), E
);
1337 -----------------------
1338 -- Freeze_And_Append --
1339 -----------------------
1341 procedure Freeze_And_Append
1344 Result
: in out List_Id
)
1346 L
: constant List_Id
:= Freeze_Entity
(Ent
, Loc
);
1348 if Is_Non_Empty_List
(L
) then
1349 if Result
= No_List
then
1352 Append_List
(L
, Result
);
1355 end Freeze_And_Append
;
1361 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1362 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, Sloc
(N
));
1364 if Is_Non_Empty_List
(Freeze_Nodes
) then
1365 Insert_Actions
(N
, Freeze_Nodes
);
1373 function Freeze_Entity
(E
: Entity_Id
; Loc
: Source_Ptr
) return List_Id
is
1374 Test_E
: Entity_Id
:= E
;
1382 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1383 -- Check that an Access or Unchecked_Access attribute with
1384 -- a prefix which is the current instance type can only be
1385 -- applied when the type is limited.
1387 function After_Last_Declaration
return Boolean;
1388 -- If Loc is a freeze_entity that appears after the last declaration
1389 -- in the scope, inhibit error messages on late completion.
1391 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1392 -- Freeze each component, handle some representation clauses, and
1393 -- freeze primitive operations if this is a tagged type.
1395 ----------------------------
1396 -- After_Last_Declaration --
1397 ----------------------------
1399 function After_Last_Declaration
return Boolean is
1400 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
1403 if Nkind
(Spec
) = N_Package_Specification
then
1404 if Present
(Private_Declarations
(Spec
)) then
1405 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1407 elsif Present
(Visible_Declarations
(Spec
)) then
1408 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1416 end After_Last_Declaration
;
1418 ----------------------------
1419 -- Check_Current_Instance --
1420 ----------------------------
1422 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1424 function Process
(N
: Node_Id
) return Traverse_Result
;
1425 -- Process routine to apply check to given node.
1431 function Process
(N
: Node_Id
) return Traverse_Result
is
1434 when N_Attribute_Reference
=>
1435 if (Attribute_Name
(N
) = Name_Access
1437 Attribute_Name
(N
) = Name_Unchecked_Access
)
1438 and then Is_Entity_Name
(Prefix
(N
))
1439 and then Is_Type
(Entity
(Prefix
(N
)))
1440 and then Entity
(Prefix
(N
)) = E
1443 ("current instance must be a limited type", Prefix
(N
));
1449 when others => return OK
;
1453 procedure Traverse
is new Traverse_Proc
(Process
);
1455 -- Start of processing for Check_Current_Instance
1458 Traverse
(Comp_Decl
);
1459 end Check_Current_Instance
;
1461 ------------------------
1462 -- Freeze_Record_Type --
1463 ------------------------
1465 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
1472 Unplaced_Component
: Boolean := False;
1473 -- Set True if we find at least one component with no component
1474 -- clause (used to warn about useless Pack pragmas).
1476 Placed_Component
: Boolean := False;
1477 -- Set True if we find at least one component with a component
1478 -- clause (used to warn about useless Bit_Order pragmas).
1480 procedure Check_Itype
(Desig
: Entity_Id
);
1481 -- If the component subtype is an access to a constrained subtype
1482 -- of an already frozen type, make the subtype frozen as well. It
1483 -- might otherwise be frozen in the wrong scope, and a freeze node
1484 -- on subtype has no effect.
1490 procedure Check_Itype
(Desig
: Entity_Id
) is
1492 if not Is_Frozen
(Desig
)
1493 and then Is_Frozen
(Base_Type
(Desig
))
1495 Set_Is_Frozen
(Desig
);
1497 -- In addition, add an Itype_Reference to ensure that the
1498 -- access subtype is elaborated early enough. This cannot
1499 -- be done if the subtype may depend on discriminants.
1501 if Ekind
(Comp
) = E_Component
1502 and then Is_Itype
(Etype
(Comp
))
1503 and then not Has_Discriminants
(Rec
)
1505 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
1506 Set_Itype
(IR
, Desig
);
1509 Result
:= New_List
(IR
);
1511 Append
(IR
, Result
);
1517 -- Start of processing for Freeze_Record_Type
1520 -- If this is a subtype of a controlled type, declared without
1521 -- a constraint, the _controller may not appear in the component
1522 -- list if the parent was not frozen at the point of subtype
1523 -- declaration. Inherit the _controller component now.
1525 if Rec
/= Base_Type
(Rec
)
1526 and then Has_Controlled_Component
(Rec
)
1528 if Nkind
(Parent
(Rec
)) = N_Subtype_Declaration
1529 and then Is_Entity_Name
(Subtype_Indication
(Parent
(Rec
)))
1531 Set_First_Entity
(Rec
, First_Entity
(Base_Type
(Rec
)));
1533 -- If this is an internal type without a declaration, as for a
1534 -- record component, the base type may not yet be frozen, and its
1535 -- controller has not been created. Add an explicit freeze node
1536 -- for the itype, so it will be frozen after the base type.
1538 elsif Is_Itype
(Rec
)
1539 and then Has_Delayed_Freeze
(Base_Type
(Rec
))
1541 Nkind
(Associated_Node_For_Itype
(Rec
)) =
1542 N_Component_Declaration
1544 Ensure_Freeze_Node
(Rec
);
1548 -- Freeze components and embedded subtypes.
1550 Comp
:= First_Entity
(Rec
);
1553 while Present
(Comp
) loop
1555 -- First handle the (real) component case.
1557 if Ekind
(Comp
) = E_Component
1558 or else Ekind
(Comp
) = E_Discriminant
1561 CC
: constant Node_Id
:= Component_Clause
(Comp
);
1564 -- Freezing a record type freezes the type of each of its
1565 -- components. However, if the type of the component is
1566 -- part of this record, we do not want or need a separate
1567 -- Freeze_Node. Note that Is_Itype is wrong because that's
1568 -- also set in private type cases. We also can't check for
1569 -- the Scope being exactly Rec because of private types and
1570 -- record extensions.
1572 if Is_Itype
(Etype
(Comp
))
1573 and then Is_Record_Type
(Underlying_Type
1574 (Scope
(Etype
(Comp
))))
1576 Undelay_Type
(Etype
(Comp
));
1579 Freeze_And_Append
(Etype
(Comp
), Loc
, Result
);
1581 -- Check for error of component clause given for variable
1582 -- sized type. We have to delay this test till this point,
1583 -- since the component type has to be frozen for us to know
1584 -- if it is variable length. We omit this test in a generic
1585 -- context, it will be applied at instantiation time.
1587 if Present
(CC
) then
1588 Placed_Component
:= True;
1590 if Inside_A_Generic
then
1593 elsif not Size_Known_At_Compile_Time
1594 (Underlying_Type
(Etype
(Comp
)))
1597 ("component clause not allowed for variable " &
1598 "length component", CC
);
1602 Unplaced_Component
:= True;
1605 -- Case of component requires byte alignment
1607 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
1609 -- Set the enclosing record to also require byte align
1611 Set_Must_Be_On_Byte_Boundary
(Rec
);
1613 -- Check for component clause that is inconsistent
1614 -- with the required byte boundary alignment.
1617 and then Normalized_First_Bit
(Comp
) mod
1618 System_Storage_Unit
/= 0
1621 ("component & must be byte aligned",
1622 Component_Name
(Component_Clause
(Comp
)));
1626 -- If component clause is present, then deal with the
1627 -- non-default bit order case. We cannot do this before
1628 -- the freeze point, because there is no required order
1629 -- for the component clause and the bit_order clause.
1631 -- We only do this processing for the base type, and in
1632 -- fact that's important, since otherwise if there are
1633 -- record subtypes, we could reverse the bits once for
1634 -- each subtype, which would be incorrect.
1637 and then Reverse_Bit_Order
(Rec
)
1638 and then Ekind
(E
) = E_Record_Type
1641 CFB
: constant Uint
:= Component_Bit_Offset
(Comp
);
1642 CSZ
: constant Uint
:= Esize
(Comp
);
1643 CLC
: constant Node_Id
:= Component_Clause
(Comp
);
1644 Pos
: constant Node_Id
:= Position
(CLC
);
1645 FB
: constant Node_Id
:= First_Bit
(CLC
);
1647 Storage_Unit_Offset
: constant Uint
:=
1648 CFB
/ System_Storage_Unit
;
1650 Start_Bit
: constant Uint
:=
1651 CFB
mod System_Storage_Unit
;
1654 -- Cases where field goes over storage unit boundary
1656 if Start_Bit
+ CSZ
> System_Storage_Unit
then
1658 -- Allow multi-byte field but generate warning
1660 if Start_Bit
mod System_Storage_Unit
= 0
1661 and then CSZ
mod System_Storage_Unit
= 0
1664 ("multi-byte field specified with non-standard"
1665 & " Bit_Order?", CLC
);
1667 if Bytes_Big_Endian
then
1669 ("bytes are not reversed "
1670 & "(component is big-endian)?", CLC
);
1673 ("bytes are not reversed "
1674 & "(component is little-endian)?", CLC
);
1677 -- Do not allow non-contiguous field
1681 ("attempt to specify non-contiguous field"
1682 & " not permitted", CLC
);
1684 ("\(caused by non-standard Bit_Order "
1685 & "specified)", CLC
);
1688 -- Case where field fits in one storage unit
1691 -- Give warning if suspicious component clause
1693 if Intval
(FB
) >= System_Storage_Unit
then
1695 ("?Bit_Order clause does not affect " &
1696 "byte ordering", Pos
);
1698 Intval
(Pos
) + Intval
(FB
) /
1699 System_Storage_Unit
;
1701 ("?position normalized to ^ before bit " &
1702 "order interpreted", Pos
);
1705 -- Here is where we fix up the Component_Bit_Offset
1706 -- value to account for the reverse bit order.
1707 -- Some examples of what needs to be done are:
1709 -- First_Bit .. Last_Bit Component_Bit_Offset
1712 -- 0 .. 0 7 .. 7 0 7
1713 -- 0 .. 1 6 .. 7 0 6
1714 -- 0 .. 2 5 .. 7 0 5
1715 -- 0 .. 7 0 .. 7 0 4
1717 -- 1 .. 1 6 .. 6 1 6
1718 -- 1 .. 4 3 .. 6 1 3
1719 -- 4 .. 7 0 .. 3 4 0
1721 -- The general rule is that the first bit is
1722 -- is obtained by subtracting the old ending bit
1723 -- from storage_unit - 1.
1725 Set_Component_Bit_Offset
1727 (Storage_Unit_Offset
* System_Storage_Unit
) +
1728 (System_Storage_Unit
- 1) -
1729 (Start_Bit
+ CSZ
- 1));
1731 Set_Normalized_First_Bit
1733 Component_Bit_Offset
(Comp
) mod
1734 System_Storage_Unit
);
1741 -- If the component is an Itype with Delayed_Freeze and is either
1742 -- a record or array subtype and its base type has not yet been
1743 -- frozen, we must remove this from the entity list of this
1744 -- record and put it on the entity list of the scope of its base
1745 -- type. Note that we know that this is not the type of a
1746 -- component since we cleared Has_Delayed_Freeze for it in the
1747 -- previous loop. Thus this must be the Designated_Type of an
1748 -- access type, which is the type of a component.
1751 and then Is_Type
(Scope
(Comp
))
1752 and then Is_Composite_Type
(Comp
)
1753 and then Base_Type
(Comp
) /= Comp
1754 and then Has_Delayed_Freeze
(Comp
)
1755 and then not Is_Frozen
(Base_Type
(Comp
))
1758 Will_Be_Frozen
: Boolean := False;
1759 S
: Entity_Id
:= Scope
(Rec
);
1762 -- We have a pretty bad kludge here. Suppose Rec is a
1763 -- subtype being defined in a subprogram that's created
1764 -- as part of the freezing of Rec'Base. In that case,
1765 -- we know that Comp'Base must have already been frozen by
1766 -- the time we get to elaborate this because Gigi doesn't
1767 -- elaborate any bodies until it has elaborated all of the
1768 -- declarative part. But Is_Frozen will not be set at this
1769 -- point because we are processing code in lexical order.
1771 -- We detect this case by going up the Scope chain of
1772 -- Rec and seeing if we have a subprogram scope before
1773 -- reaching the top of the scope chain or that of Comp'Base.
1774 -- If we do, then mark that Comp'Base will actually be
1775 -- frozen. If so, we merely undelay it.
1777 while Present
(S
) loop
1778 if Is_Subprogram
(S
) then
1779 Will_Be_Frozen
:= True;
1781 elsif S
= Scope
(Base_Type
(Comp
)) then
1788 if Will_Be_Frozen
then
1789 Undelay_Type
(Comp
);
1791 if Present
(Prev
) then
1792 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
1794 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
1797 -- Insert in entity list of scope of base type (which
1798 -- must be an enclosing scope, because still unfrozen).
1800 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
1804 -- If the component is an access type with an allocator as
1805 -- default value, the designated type will be frozen by the
1806 -- corresponding expression in init_proc. In order to place the
1807 -- freeze node for the designated type before that for the
1808 -- current record type, freeze it now.
1810 -- Same process if the component is an array of access types,
1811 -- initialized with an aggregate. If the designated type is
1812 -- private, it cannot contain allocators, and it is premature to
1813 -- freeze the type, so we check for this as well.
1815 elsif Is_Access_Type
(Etype
(Comp
))
1816 and then Present
(Parent
(Comp
))
1817 and then Present
(Expression
(Parent
(Comp
)))
1818 and then Nkind
(Expression
(Parent
(Comp
))) = N_Allocator
1821 Alloc
: constant Node_Id
:= Expression
(Parent
(Comp
));
1824 -- If component is pointer to a classwide type, freeze
1825 -- the specific type in the expression being allocated.
1826 -- The expression may be a subtype indication, in which
1827 -- case freeze the subtype mark.
1829 if Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp
))) then
1830 if Is_Entity_Name
(Expression
(Alloc
)) then
1832 (Entity
(Expression
(Alloc
)), Loc
, Result
);
1834 Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
1837 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
1841 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
1842 Check_Itype
(Designated_Type
(Etype
(Comp
)));
1846 (Designated_Type
(Etype
(Comp
)), Loc
, Result
);
1850 elsif Is_Access_Type
(Etype
(Comp
))
1851 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
1853 Check_Itype
(Designated_Type
(Etype
(Comp
)));
1855 elsif Is_Array_Type
(Etype
(Comp
))
1856 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
1857 and then Present
(Parent
(Comp
))
1858 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
1859 and then Present
(Expression
(Parent
(Comp
)))
1860 and then Nkind
(Expression
(Parent
(Comp
))) = N_Aggregate
1861 and then Is_Fully_Defined
1862 (Designated_Type
(Component_Type
(Etype
(Comp
))))
1866 (Component_Type
(Etype
(Comp
))), Loc
, Result
);
1873 -- Check for useless pragma Bit_Order
1875 if not Placed_Component
and then Reverse_Bit_Order
(Rec
) then
1876 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
1877 Error_Msg_N
("?Bit_Order specification has no effect", ADC
);
1878 Error_Msg_N
("\?since no component clauses were specified", ADC
);
1881 -- Check for useless pragma Pack when all components placed
1884 and then not Unplaced_Component
1885 and then Warn_On_Redundant_Constructs
1888 ("?pragma Pack has no effect, no unplaced components",
1889 Get_Rep_Pragma
(Rec
, Name_Pack
));
1890 Set_Is_Packed
(Rec
, False);
1893 -- If this is the record corresponding to a remote type,
1894 -- freeze the remote type here since that is what we are
1895 -- semantically freezing. This prevents having the freeze
1896 -- node for that type in an inner scope.
1898 -- Also, Check for controlled components and unchecked unions.
1899 -- Finally, enforce the restriction that access attributes with
1900 -- a current instance prefix can only apply to limited types.
1902 if Ekind
(Rec
) = E_Record_Type
then
1903 if Present
(Corresponding_Remote_Type
(Rec
)) then
1905 (Corresponding_Remote_Type
(Rec
), Loc
, Result
);
1908 Comp
:= First_Component
(Rec
);
1909 while Present
(Comp
) loop
1910 if Has_Controlled_Component
(Etype
(Comp
))
1911 or else (Chars
(Comp
) /= Name_uParent
1912 and then Is_Controlled
(Etype
(Comp
)))
1913 or else (Is_Protected_Type
(Etype
(Comp
))
1915 (Corresponding_Record_Type
(Etype
(Comp
)))
1916 and then Has_Controlled_Component
1917 (Corresponding_Record_Type
(Etype
(Comp
))))
1919 Set_Has_Controlled_Component
(Rec
);
1923 if Has_Unchecked_Union
(Etype
(Comp
)) then
1924 Set_Has_Unchecked_Union
(Rec
);
1927 if Has_Per_Object_Constraint
(Comp
)
1928 and then not Is_Limited_Type
(Rec
)
1930 -- Scan component declaration for likely misuses of
1931 -- current instance, either in a constraint or in a
1932 -- default expression.
1934 Check_Current_Instance
(Parent
(Comp
));
1937 Next_Component
(Comp
);
1941 Set_Component_Alignment_If_Not_Set
(Rec
);
1943 -- For first subtypes, check if there are any fixed-point
1944 -- fields with component clauses, where we must check the size.
1945 -- This is not done till the freeze point, since for fixed-point
1946 -- types, we do not know the size until the type is frozen.
1947 -- Similar processing applies to bit packed arrays.
1949 if Is_First_Subtype
(Rec
) then
1950 Comp
:= First_Component
(Rec
);
1952 while Present
(Comp
) loop
1953 if Present
(Component_Clause
(Comp
))
1954 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
1956 Is_Bit_Packed_Array
(Etype
(Comp
)))
1959 (Component_Name
(Component_Clause
(Comp
)),
1965 Next_Component
(Comp
);
1968 end Freeze_Record_Type
;
1970 -- Start of processing for Freeze_Entity
1973 -- We are going to test for various reasons why this entity need not be
1974 -- frozen here, but in the case of an Itype that's defined within a
1975 -- record, that test actually applies to the record.
1977 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
1978 Test_E
:= Scope
(E
);
1979 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
1980 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
1982 Test_E
:= Underlying_Type
(Scope
(E
));
1985 -- Do not freeze if already frozen since we only need one freeze node
1987 if Is_Frozen
(E
) then
1990 -- It is improper to freeze an external entity within a generic because
1991 -- its freeze node will appear in a non-valid context. The entity will
1992 -- be frozen in the proper scope after the current generic is analyzed.
1994 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
1997 -- Do not freeze a global entity within an inner scope created during
1998 -- expansion. A call to subprogram E within some internal procedure
1999 -- (a stream attribute for example) might require freezing E, but the
2000 -- freeze node must appear in the same declarative part as E itself.
2001 -- The two-pass elaboration mechanism in gigi guarantees that E will
2002 -- be frozen before the inner call is elaborated. We exclude constants
2003 -- from this test, because deferred constants may be frozen early, and
2004 -- must be diagnosed (see e.g. 1522-005). If the enclosing subprogram
2005 -- comes from source, or is a generic instance, then the freeze point
2006 -- is the one mandated by the language. and we freze the entity.
2008 elsif In_Open_Scopes
(Scope
(Test_E
))
2009 and then Scope
(Test_E
) /= Current_Scope
2010 and then Ekind
(Test_E
) /= E_Constant
2013 S
: Entity_Id
:= Current_Scope
;
2016 while Present
(S
) loop
2017 if Is_Overloadable
(S
) then
2018 if Comes_From_Source
(S
)
2019 or else Is_Generic_Instance
(S
)
2031 -- Similarly, an inlined instance body may make reference to global
2032 -- entities, but these references cannot be the proper freezing point
2033 -- for them, and the the absence of inlining freezing will take place
2034 -- in their own scope. Normally instance bodies are analyzed after
2035 -- the enclosing compilation, and everything has been frozen at the
2036 -- proper place, but with front-end inlining an instance body is
2037 -- compiled before the end of the enclosing scope, and as a result
2038 -- out-of-order freezing must be prevented.
2040 elsif Front_End_Inlining
2041 and then In_Instance_Body
2042 and then Present
(Scope
(Test_E
))
2045 S
: Entity_Id
:= Scope
(Test_E
);
2048 while Present
(S
) loop
2049 if Is_Generic_Instance
(S
) then
2062 -- Here to freeze the entity
2067 -- Case of entity being frozen is other than a type
2069 if not Is_Type
(E
) then
2071 -- If entity is exported or imported and does not have an external
2072 -- name, now is the time to provide the appropriate default name.
2073 -- Skip this if the entity is stubbed, since we don't need a name
2074 -- for any stubbed routine.
2076 if (Is_Imported
(E
) or else Is_Exported
(E
))
2077 and then No
(Interface_Name
(E
))
2078 and then Convention
(E
) /= Convention_Stubbed
2080 Set_Encoded_Interface_Name
2081 (E
, Get_Default_External_Name
(E
));
2083 -- Special processing for atomic objects appearing in object decls
2086 and then Nkind
(Parent
(E
)) = N_Object_Declaration
2087 and then Present
(Expression
(Parent
(E
)))
2090 Expr
: constant Node_Id
:= Expression
(Parent
(E
));
2093 -- If expression is an aggregate, assign to a temporary to
2094 -- ensure that the actual assignment is done atomically rather
2095 -- than component-wise (the assignment to the temp may be done
2096 -- component-wise, but that is harmless.
2098 if Nkind
(Expr
) = N_Aggregate
then
2099 Expand_Atomic_Aggregate
(Expr
, Etype
(E
));
2101 -- If the expression is a reference to a record or array
2102 -- object entity, then reset Is_True_Constant to False so
2103 -- that the compiler will not optimize away the intermediate
2104 -- object, which we need in this case for the same reason
2105 -- (to ensure that the actual assignment is atomic, rather
2106 -- than component-wise).
2108 elsif Is_Entity_Name
(Expr
)
2109 and then (Is_Record_Type
(Etype
(Expr
))
2111 Is_Array_Type
(Etype
(Expr
)))
2113 Set_Is_True_Constant
(Entity
(Expr
), False);
2118 -- For a subprogram, freeze all parameter types and also the return
2119 -- type (RM 13.14(14)). However skip this for internal subprograms.
2120 -- This is also the point where any extra formal parameters are
2121 -- created since we now know whether the subprogram will use
2122 -- a foreign convention.
2124 if Is_Subprogram
(E
) then
2125 if not Is_Internal
(E
) then
2128 Warn_Node
: Node_Id
;
2130 function Is_Fat_C_Ptr_Type
(T
: Entity_Id
) return Boolean;
2131 -- Determines if given type entity is a fat pointer type
2132 -- used as an argument type or return type to a subprogram
2133 -- with C or C++ convention set.
2135 --------------------------
2136 -- Is_Fat_C_Access_Type --
2137 --------------------------
2139 function Is_Fat_C_Ptr_Type
(T
: Entity_Id
) return Boolean is
2141 return (Convention
(E
) = Convention_C
2143 Convention
(E
) = Convention_CPP
)
2144 and then Is_Access_Type
(T
)
2145 and then Esize
(T
) > Ttypes
.System_Address_Size
;
2146 end Is_Fat_C_Ptr_Type
;
2149 -- Loop through formals
2151 Formal
:= First_Formal
(E
);
2152 while Present
(Formal
) loop
2153 F_Type
:= Etype
(Formal
);
2154 Freeze_And_Append
(F_Type
, Loc
, Result
);
2156 if Is_Private_Type
(F_Type
)
2157 and then Is_Private_Type
(Base_Type
(F_Type
))
2158 and then No
(Full_View
(Base_Type
(F_Type
)))
2159 and then not Is_Generic_Type
(F_Type
)
2160 and then not Is_Derived_Type
(F_Type
)
2162 -- If the type of a formal is incomplete, subprogram
2163 -- is being frozen prematurely. Within an instance
2164 -- (but not within a wrapper package) this is an
2165 -- an artifact of our need to regard the end of an
2166 -- instantiation as a freeze point. Otherwise it is
2167 -- a definite error.
2169 -- and then not Is_Wrapper_Package (Current_Scope) ???
2172 Set_Is_Frozen
(E
, False);
2175 elsif not After_Last_Declaration
then
2176 Error_Msg_Node_1
:= F_Type
;
2178 ("type& must be fully defined before this point",
2183 -- Check bad use of fat C pointer
2185 if Warn_On_Export_Import
and then
2186 Is_Fat_C_Ptr_Type
(F_Type
)
2188 Error_Msg_Qual_Level
:= 1;
2190 ("?type of & does not correspond to C pointer",
2192 Error_Msg_Qual_Level
:= 0;
2195 -- Check for unconstrained array in exported foreign
2198 if Convention
(E
) in Foreign_Convention
2199 and then not Is_Imported
(E
)
2200 and then Is_Array_Type
(F_Type
)
2201 and then not Is_Constrained
(F_Type
)
2202 and then Warn_On_Export_Import
2204 Error_Msg_Qual_Level
:= 1;
2206 -- If this is an inherited operation, place the
2207 -- warning on the derived type declaration, rather
2208 -- than on the original subprogram.
2210 if Nkind
(Original_Node
(Parent
(E
))) =
2211 N_Full_Type_Declaration
2213 Warn_Node
:= Parent
(E
);
2215 if Formal
= First_Formal
(E
) then
2217 ("?in inherited operation&!", Warn_Node
, E
);
2220 Warn_Node
:= Formal
;
2224 ("?type of argument& is unconstrained array",
2227 ("?foreign caller must pass bounds explicitly",
2229 Error_Msg_Qual_Level
:= 0;
2232 Next_Formal
(Formal
);
2235 -- Check return type
2237 if Ekind
(E
) = E_Function
then
2238 Freeze_And_Append
(Etype
(E
), Loc
, Result
);
2240 if Warn_On_Export_Import
2241 and then Is_Fat_C_Ptr_Type
(Etype
(E
))
2244 ("?return type of& does not correspond to C pointer",
2247 elsif Is_Array_Type
(Etype
(E
))
2248 and then not Is_Constrained
(Etype
(E
))
2249 and then not Is_Imported
(E
)
2250 and then Convention
(E
) in Foreign_Convention
2251 and then Warn_On_Export_Import
2254 ("?foreign convention function& should not " &
2255 "return unconstrained array", E
);
2261 -- Must freeze its parent first if it is a derived subprogram
2263 if Present
(Alias
(E
)) then
2264 Freeze_And_Append
(Alias
(E
), Loc
, Result
);
2267 -- If the return type requires a transient scope, and we are on
2268 -- a target allowing functions to return with a depressed stack
2269 -- pointer, then we mark the function as requiring this treatment.
2271 if Ekind
(E
) = E_Function
2272 and then Functions_Return_By_DSP_On_Target
2273 and then Requires_Transient_Scope
(Etype
(E
))
2275 Set_Function_Returns_With_DSP
(E
);
2278 if not Is_Internal
(E
) then
2279 Freeze_Subprogram
(E
);
2282 -- Here for other than a subprogram or type
2285 -- If entity has a type, and it is not a generic unit, then
2286 -- freeze it first (RM 13.14(10))
2288 if Present
(Etype
(E
))
2289 and then Ekind
(E
) /= E_Generic_Function
2291 Freeze_And_Append
(Etype
(E
), Loc
, Result
);
2294 -- Special processing for objects created by object declaration
2296 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
2298 -- For object created by object declaration, perform required
2299 -- categorization (preelaborate and pure) checks. Defer these
2300 -- checks to freeze time since pragma Import inhibits default
2301 -- initialization and thus pragma Import affects these checks.
2303 Validate_Object_Declaration
(Declaration_Node
(E
));
2305 -- If there is an address clause, check it is valid
2307 Check_Address_Clause
(E
);
2309 -- For imported objects, set Is_Public unless there is also
2310 -- an address clause, which means that there is no external
2311 -- symbol needed for the Import (Is_Public may still be set
2312 -- for other unrelated reasons). Note that we delayed this
2313 -- processing till freeze time so that we can be sure not
2314 -- to set the flag if there is an address clause. If there
2315 -- is such a clause, then the only purpose of the import
2316 -- pragma is to suppress implicit initialization.
2319 and then not Present
(Address_Clause
(E
))
2325 -- Check that a constant which has a pragma Volatile[_Components]
2326 -- or Atomic[_Components] also has a pragma Import (RM C.6(13))
2328 -- Note: Atomic[_Components] also sets Volatile[_Components]
2330 if Ekind
(E
) = E_Constant
2331 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
2332 and then not Is_Imported
(E
)
2334 -- Make sure we actually have a pragma, and have not merely
2335 -- inherited the indication from elsewhere (e.g. an address
2336 -- clause, which is not good enough in RM terms!)
2338 if Has_Rep_Pragma
(E
, Name_Atomic
)
2340 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
2343 ("stand alone atomic constant must be " &
2344 "imported ('R'M 'C.6(13))", E
);
2346 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
2348 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
2351 ("stand alone volatile constant must be " &
2352 "imported ('R'M 'C.6(13))", E
);
2356 -- Static objects require special handling
2358 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
2359 and then Is_Statically_Allocated
(E
)
2361 Freeze_Static_Object
(E
);
2364 -- Remaining step is to layout objects
2366 if Ekind
(E
) = E_Variable
2368 Ekind
(E
) = E_Constant
2370 Ekind
(E
) = E_Loop_Parameter
2378 -- Case of a type or subtype being frozen
2381 -- The type may be defined in a generic unit. This can occur when
2382 -- freezing a generic function that returns the type (which is
2383 -- defined in a parent unit). It is clearly meaningless to freeze
2384 -- this type. However, if it is a subtype, its size may be determi-
2385 -- nable and used in subsequent checks, so might as well try to
2388 if Present
(Scope
(E
))
2389 and then Is_Generic_Unit
(Scope
(E
))
2391 Check_Compile_Time_Size
(E
);
2395 -- Deal with special cases of freezing for subtype
2397 if E
/= Base_Type
(E
) then
2399 -- If ancestor subtype present, freeze that first.
2400 -- Note that this will also get the base type frozen.
2402 Atype
:= Ancestor_Subtype
(E
);
2404 if Present
(Atype
) then
2405 Freeze_And_Append
(Atype
, Loc
, Result
);
2407 -- Otherwise freeze the base type of the entity before
2408 -- freezing the entity itself, (RM 13.14(15)).
2410 elsif E
/= Base_Type
(E
) then
2411 Freeze_And_Append
(Base_Type
(E
), Loc
, Result
);
2414 -- For a derived type, freeze its parent type first (RM 13.14(15))
2416 elsif Is_Derived_Type
(E
) then
2417 Freeze_And_Append
(Etype
(E
), Loc
, Result
);
2418 Freeze_And_Append
(First_Subtype
(Etype
(E
)), Loc
, Result
);
2421 -- For array type, freeze index types and component type first
2422 -- before freezing the array (RM 13.14(15)).
2424 if Is_Array_Type
(E
) then
2426 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
2429 Non_Standard_Enum
: Boolean := False;
2430 -- Set true if any of the index types is an enumeration
2431 -- type with a non-standard representation.
2434 Freeze_And_Append
(Ctyp
, Loc
, Result
);
2436 Indx
:= First_Index
(E
);
2437 while Present
(Indx
) loop
2438 Freeze_And_Append
(Etype
(Indx
), Loc
, Result
);
2440 if Is_Enumeration_Type
(Etype
(Indx
))
2441 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2443 Non_Standard_Enum
:= True;
2449 -- Processing that is done only for base types
2451 if Ekind
(E
) = E_Array_Type
then
2453 -- Propagate flags for component type
2455 if Is_Controlled
(Component_Type
(E
))
2456 or else Has_Controlled_Component
(Ctyp
)
2458 Set_Has_Controlled_Component
(E
);
2461 if Has_Unchecked_Union
(Component_Type
(E
)) then
2462 Set_Has_Unchecked_Union
(E
);
2465 -- If packing was requested or if the component size was set
2466 -- explicitly, then see if bit packing is required. This
2467 -- processing is only done for base types, since all the
2468 -- representation aspects involved are type-related. This
2469 -- is not just an optimization, if we start processing the
2470 -- subtypes, they intefere with the settings on the base
2471 -- type (this is because Is_Packed has a slightly different
2472 -- meaning before and after freezing).
2479 if (Is_Packed
(E
) or else Has_Pragma_Pack
(E
))
2480 and then not Has_Atomic_Components
(E
)
2481 and then Known_Static_RM_Size
(Ctyp
)
2483 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2485 elsif Known_Component_Size
(E
) then
2486 Csiz
:= Component_Size
(E
);
2488 elsif not Known_Static_Esize
(Ctyp
) then
2492 Esiz
:= Esize
(Ctyp
);
2494 -- We can set the component size if it is less than
2495 -- 16, rounding it up to the next storage unit size.
2499 elsif Esiz
<= 16 then
2505 -- Set component size up to match alignment if
2506 -- it would otherwise be less than the alignment.
2507 -- This deals with cases of types whose alignment
2508 -- exceeds their sizes (padded types).
2512 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2523 if 1 <= Csiz
and then Csiz
<= 64 then
2525 -- We set the component size for all cases 1-64
2527 Set_Component_Size
(Base_Type
(E
), Csiz
);
2529 -- Check for base type of 8,16,32 bits, where the
2530 -- subtype has a length one less than the base type
2531 -- and is unsigned (e.g. Natural subtype of Integer)
2533 -- In such cases, if a component size was not set
2534 -- explicitly, then generate a warning.
2536 if Has_Pragma_Pack
(E
)
2537 and then not Has_Component_Size_Clause
(E
)
2539 (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2540 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2542 Error_Msg_Uint_1
:= Csiz
;
2544 Get_Rep_Pragma
(First_Subtype
(E
), Name_Pack
);
2546 if Present
(Pnod
) then
2548 ("pragma Pack causes component size to be ^?",
2551 ("\use Component_Size to set desired value",
2556 -- Actual packing is not needed for 8,16,32,64
2557 -- Also not needed for 24 if alignment is 1
2563 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
2565 -- Here the array was requested to be packed, but
2566 -- the packing request had no effect, so Is_Packed
2569 -- Note: semantically this means that we lose
2570 -- track of the fact that a derived type inherited
2571 -- a pack pragma that was non-effective, but that
2574 -- We regard a Pack pragma as a request to set a
2575 -- representation characteristic, and this request
2578 Set_Is_Packed
(Base_Type
(E
), False);
2580 -- In all other cases, packing is indeed needed
2583 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
2584 Set_Is_Bit_Packed_Array
(Base_Type
(E
));
2585 Set_Is_Packed
(Base_Type
(E
));
2590 -- Processing that is done only for subtypes
2593 -- Acquire alignment from base type
2595 if Unknown_Alignment
(E
) then
2596 Set_Alignment
(E
, Alignment
(Base_Type
(E
)));
2600 -- For bit-packed arrays, check the size
2602 if Is_Bit_Packed_Array
(E
)
2603 and then Known_Esize
(E
)
2607 SizC
: constant Node_Id
:= Size_Clause
(E
);
2610 -- It is not clear if it is possible to have no size
2611 -- clause at this stage, but this is not worth worrying
2612 -- about. Post the error on the entity name in the size
2613 -- clause if present, else on the type entity itself.
2615 if Present
(SizC
) then
2616 Check_Size
(Name
(SizC
), E
, Esize
(E
), Discard
);
2618 Check_Size
(E
, E
, Esize
(E
), Discard
);
2623 -- Check one common case of a size given where the array
2624 -- needs to be packed, but was not so the size cannot be
2625 -- honored. This would of course be caught by the backend,
2626 -- and indeed we don't catch all cases. The point is that
2627 -- we can give a better error message in those cases that
2628 -- we do catch with the circuitry here.
2632 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
2635 if Present
(Size_Clause
(E
))
2636 and then Known_Static_Esize
(E
)
2637 and then not Is_Bit_Packed_Array
(E
)
2638 and then not Has_Pragma_Pack
(E
)
2639 and then Number_Dimensions
(E
) = 1
2640 and then not Has_Component_Size_Clause
(E
)
2641 and then Known_Static_Esize
(Ctyp
)
2643 Get_Index_Bounds
(First_Index
(E
), Lo
, Hi
);
2645 if Compile_Time_Known_Value
(Lo
)
2646 and then Compile_Time_Known_Value
(Hi
)
2647 and then Known_Static_RM_Size
(Ctyp
)
2648 and then RM_Size
(Ctyp
) < 64
2651 Lov
: constant Uint
:= Expr_Value
(Lo
);
2652 Hiv
: constant Uint
:= Expr_Value
(Hi
);
2653 Len
: constant Uint
:=
2654 UI_Max
(Uint_0
, Hiv
- Lov
+ 1);
2655 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
2657 -- What we are looking for here is the situation
2658 -- where the Esize given would be exactly right
2659 -- if there was a pragma Pack (resulting in the
2660 -- component size being the same as the RM_Size).
2661 -- Furthermore, the component type size must be
2662 -- an odd size (not a multiple of storage unit)
2665 if Esize
(E
) = Len
* Rsiz
2666 and then Rsiz
mod System_Storage_Unit
/= 0
2669 ("size given for& too small",
2670 Size_Clause
(E
), E
);
2672 ("\explicit pragma Pack is required",
2680 -- If any of the index types was an enumeration type with
2681 -- a non-standard rep clause, then we indicate that the
2682 -- array type is always packed (even if it is not bit packed).
2684 if Non_Standard_Enum
then
2685 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
2686 Set_Is_Packed
(Base_Type
(E
));
2689 Set_Component_Alignment_If_Not_Set
(E
);
2691 -- If the array is packed, we must create the packed array
2692 -- type to be used to actually implement the type. This is
2693 -- only needed for real array types (not for string literal
2694 -- types, since they are present only for the front end).
2697 and then Ekind
(E
) /= E_String_Literal_Subtype
2699 Create_Packed_Array_Type
(E
);
2700 Freeze_And_Append
(Packed_Array_Type
(E
), Loc
, Result
);
2702 -- Size information of packed array type is copied to the
2703 -- array type, since this is really the representation.
2705 Set_Size_Info
(E
, Packed_Array_Type
(E
));
2706 Set_RM_Size
(E
, RM_Size
(Packed_Array_Type
(E
)));
2709 -- For non-packed arrays set the alignment of the array
2710 -- to the alignment of the component type if it is unknown.
2711 -- Skip this in the atomic case, since atomic arrays may
2712 -- need larger alignments.
2714 if not Is_Packed
(E
)
2715 and then Unknown_Alignment
(E
)
2716 and then Known_Alignment
(Ctyp
)
2717 and then Known_Static_Component_Size
(E
)
2718 and then Known_Static_Esize
(Ctyp
)
2719 and then Esize
(Ctyp
) = Component_Size
(E
)
2720 and then not Is_Atomic
(E
)
2722 Set_Alignment
(E
, Alignment
(Component_Type
(E
)));
2726 -- For a class-wide type, the corresponding specific type is
2727 -- frozen as well (RM 13.14(15))
2729 elsif Is_Class_Wide_Type
(E
) then
2730 Freeze_And_Append
(Root_Type
(E
), Loc
, Result
);
2732 -- If the Class_Wide_Type is an Itype (when type is the anonymous
2733 -- parent of a derived type) and it is a library-level entity,
2734 -- generate an itype reference for it. Otherwise, its first
2735 -- explicit reference may be in an inner scope, which will be
2736 -- rejected by the back-end.
2739 and then Is_Compilation_Unit
(Scope
(E
))
2742 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
2747 Result
:= New_List
(Ref
);
2749 Append
(Ref
, Result
);
2754 -- The equivalent type associated with a class-wide subtype
2755 -- needs to be frozen to ensure that its layout is done.
2756 -- Class-wide subtypes are currently only frozen on targets
2757 -- requiring front-end layout (see New_Class_Wide_Subtype
2758 -- and Make_CW_Equivalent_Type in exp_util.adb).
2760 if Ekind
(E
) = E_Class_Wide_Subtype
2761 and then Present
(Equivalent_Type
(E
))
2763 Freeze_And_Append
(Equivalent_Type
(E
), Loc
, Result
);
2766 -- For a record (sub)type, freeze all the component types (RM
2767 -- 13.14(15). We test for E_Record_(sub)Type here, rather than
2768 -- using Is_Record_Type, because we don't want to attempt the
2769 -- freeze for the case of a private type with record extension
2770 -- (we will do that later when the full type is frozen).
2772 elsif Ekind
(E
) = E_Record_Type
2773 or else Ekind
(E
) = E_Record_Subtype
2775 Freeze_Record_Type
(E
);
2777 -- For a concurrent type, freeze corresponding record type. This
2778 -- does not correpond to any specific rule in the RM, but the
2779 -- record type is essentially part of the concurrent type.
2780 -- Freeze as well all local entities. This includes record types
2781 -- created for entry parameter blocks, and whatever local entities
2782 -- may appear in the private part.
2784 elsif Is_Concurrent_Type
(E
) then
2785 if Present
(Corresponding_Record_Type
(E
)) then
2787 (Corresponding_Record_Type
(E
), Loc
, Result
);
2790 Comp
:= First_Entity
(E
);
2792 while Present
(Comp
) loop
2793 if Is_Type
(Comp
) then
2794 Freeze_And_Append
(Comp
, Loc
, Result
);
2796 elsif (Ekind
(Comp
)) /= E_Function
then
2797 if Is_Itype
(Etype
(Comp
))
2798 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
2800 Undelay_Type
(Etype
(Comp
));
2803 Freeze_And_Append
(Etype
(Comp
), Loc
, Result
);
2809 -- Private types are required to point to the same freeze node
2810 -- as their corresponding full views. The freeze node itself
2811 -- has to point to the partial view of the entity (because
2812 -- from the partial view, we can retrieve the full view, but
2813 -- not the reverse). However, in order to freeze correctly,
2814 -- we need to freeze the full view. If we are freezing at the
2815 -- end of a scope (or within the scope of the private type),
2816 -- the partial and full views will have been swapped, the
2817 -- full view appears first in the entity chain and the swapping
2818 -- mechanism ensures that the pointers are properly set (on
2821 -- If we encounter the partial view before the full view
2822 -- (e.g. when freezing from another scope), we freeze the
2823 -- full view, and then set the pointers appropriately since
2824 -- we cannot rely on swapping to fix things up (subtypes in an
2825 -- outer scope might not get swapped).
2827 elsif Is_Incomplete_Or_Private_Type
(E
)
2828 and then not Is_Generic_Type
(E
)
2830 -- Case of full view present
2832 if Present
(Full_View
(E
)) then
2834 -- If full view has already been frozen, then no
2835 -- further processing is required
2837 if Is_Frozen
(Full_View
(E
)) then
2839 Set_Has_Delayed_Freeze
(E
, False);
2840 Set_Freeze_Node
(E
, Empty
);
2841 Check_Debug_Info_Needed
(E
);
2843 -- Otherwise freeze full view and patch the pointers
2844 -- so that the freeze node will elaborate both views
2849 Full
: constant Entity_Id
:= Full_View
(E
);
2852 if Is_Private_Type
(Full
)
2853 and then Present
(Underlying_Full_View
(Full
))
2856 (Underlying_Full_View
(Full
), Loc
, Result
);
2859 Freeze_And_Append
(Full
, Loc
, Result
);
2861 if Has_Delayed_Freeze
(E
) then
2862 F_Node
:= Freeze_Node
(Full
);
2864 if Present
(F_Node
) then
2865 Set_Freeze_Node
(E
, F_Node
);
2866 Set_Entity
(F_Node
, E
);
2869 -- {Incomplete,Private}_Subtypes
2870 -- with Full_Views constrained by discriminants
2872 Set_Has_Delayed_Freeze
(E
, False);
2873 Set_Freeze_Node
(E
, Empty
);
2878 Check_Debug_Info_Needed
(E
);
2881 -- AI-117 requires that the convention of a partial view
2882 -- be the same as the convention of the full view. Note
2883 -- that this is a recognized breach of privacy, but it's
2884 -- essential for logical consistency of representation,
2885 -- and the lack of a rule in RM95 was an oversight.
2887 Set_Convention
(E
, Convention
(Full_View
(E
)));
2889 Set_Size_Known_At_Compile_Time
(E
,
2890 Size_Known_At_Compile_Time
(Full_View
(E
)));
2892 -- Size information is copied from the full view to the
2893 -- incomplete or private view for consistency
2895 -- We skip this is the full view is not a type. This is
2896 -- very strange of course, and can only happen as a result
2897 -- of certain illegalities, such as a premature attempt to
2898 -- derive from an incomplete type.
2900 if Is_Type
(Full_View
(E
)) then
2901 Set_Size_Info
(E
, Full_View
(E
));
2902 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
2907 -- Case of no full view present. If entity is derived or subtype,
2908 -- it is safe to freeze, correctness depends on the frozen status
2909 -- of parent. Otherwise it is either premature usage, or a Taft
2910 -- amendment type, so diagnosis is at the point of use and the
2911 -- type might be frozen later.
2913 elsif E
/= Base_Type
(E
)
2914 or else Is_Derived_Type
(E
)
2919 Set_Is_Frozen
(E
, False);
2923 -- For access subprogram, freeze types of all formals, the return
2924 -- type was already frozen, since it is the Etype of the function.
2926 elsif Ekind
(E
) = E_Subprogram_Type
then
2927 Formal
:= First_Formal
(E
);
2928 while Present
(Formal
) loop
2929 Freeze_And_Append
(Etype
(Formal
), Loc
, Result
);
2930 Next_Formal
(Formal
);
2933 -- If the return type requires a transient scope, and we are on
2934 -- a target allowing functions to return with a depressed stack
2935 -- pointer, then we mark the function as requiring this treatment.
2937 if Functions_Return_By_DSP_On_Target
2938 and then Requires_Transient_Scope
(Etype
(E
))
2940 Set_Function_Returns_With_DSP
(E
);
2943 Freeze_Subprogram
(E
);
2945 -- For access to a protected subprogram, freeze the equivalent
2946 -- type (however this is not set if we are not generating code)
2947 -- or if this is an anonymous type used just for resolution).
2949 elsif Ekind
(E
) = E_Access_Protected_Subprogram_Type
2950 and then Operating_Mode
= Generate_Code
2951 and then Present
(Equivalent_Type
(E
))
2953 Freeze_And_Append
(Equivalent_Type
(E
), Loc
, Result
);
2956 -- Generic types are never seen by the back-end, and are also not
2957 -- processed by the expander (since the expander is turned off for
2958 -- generic processing), so we never need freeze nodes for them.
2960 if Is_Generic_Type
(E
) then
2964 -- Some special processing for non-generic types to complete
2965 -- representation details not known till the freeze point.
2967 if Is_Fixed_Point_Type
(E
) then
2968 Freeze_Fixed_Point_Type
(E
);
2970 -- Some error checks required for ordinary fixed-point type.
2971 -- Defer these till the freeze-point since we need the small
2972 -- and range values. We only do these checks for base types
2974 if Is_Ordinary_Fixed_Point_Type
(E
)
2975 and then E
= Base_Type
(E
)
2977 if Small_Value
(E
) < Ureal_2_M_80
then
2978 Error_Msg_Name_1
:= Name_Small
;
2980 ("`&''%` is too small, minimum is 2.0'*'*(-80)", E
);
2982 elsif Small_Value
(E
) > Ureal_2_80
then
2983 Error_Msg_Name_1
:= Name_Small
;
2985 ("`&''%` is too large, maximum is 2.0'*'*80", E
);
2988 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
2989 Error_Msg_Name_1
:= Name_First
;
2991 ("`&''%` is too small, minimum is -10.0'*'*36", E
);
2994 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
2995 Error_Msg_Name_1
:= Name_Last
;
2997 ("`&''%` is too large, maximum is 10.0'*'*36", E
);
3001 elsif Is_Enumeration_Type
(E
) then
3002 Freeze_Enumeration_Type
(E
);
3004 elsif Is_Integer_Type
(E
) then
3005 Adjust_Esize_For_Alignment
(E
);
3007 elsif Is_Access_Type
(E
)
3008 and then No
(Associated_Storage_Pool
(E
))
3010 Check_Restriction
(No_Standard_Storage_Pools
, E
);
3013 if Is_Composite_Type
(E
) then
3015 -- AI-117 requires that all new primitives of a tagged type
3016 -- must inherit the convention of the full view of the type.
3017 -- Inherited and overriding operations are defined to inherit
3018 -- the convention of their parent or overridden subprogram
3019 -- (also specified in AI-117), and that will have occurred
3020 -- earlier (in Derive_Subprogram and New_Overloaded_Entity).
3021 -- Here we set the convention of primitives that are still
3022 -- convention Ada, which will ensure that any new primitives
3023 -- inherit the type's convention. Class-wide types can have
3024 -- a foreign convention inherited from their specific type,
3025 -- but are excluded from this since they don't have any
3026 -- associated primitives.
3028 if Is_Tagged_Type
(E
)
3029 and then not Is_Class_Wide_Type
(E
)
3030 and then Convention
(E
) /= Convention_Ada
3033 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
3036 Prim
:= First_Elmt
(Prim_List
);
3037 while Present
(Prim
) loop
3038 if Convention
(Node
(Prim
)) = Convention_Ada
then
3039 Set_Convention
(Node
(Prim
), Convention
(E
));
3048 -- Generate primitive operation references for a tagged type
3050 if Is_Tagged_Type
(E
)
3051 and then not Is_Class_Wide_Type
(E
)
3054 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
3059 Prim
:= First_Elmt
(Prim_List
);
3060 while Present
(Prim
) loop
3063 -- If the operation is derived, get the original for
3064 -- cross-reference purposes (it is the original for
3065 -- which we want the xref, and for which the comes
3066 -- from source test needs to be performed).
3068 while Present
(Alias
(Ent
)) loop
3072 Generate_Reference
(E
, Ent
, 'p', Set_Ref
=> False);
3076 -- If we get an exception, then something peculiar has happened
3077 -- probably as a result of a previous error. Since this is only
3078 -- for non-critical cross-references, ignore the error.
3081 when others => null;
3085 -- Now that all types from which E may depend are frozen, see
3086 -- if the size is known at compile time, if it must be unsigned,
3087 -- or if strict alignent is required
3089 Check_Compile_Time_Size
(E
);
3090 Check_Unsigned_Type
(E
);
3092 if Base_Type
(E
) = E
then
3093 Check_Strict_Alignment
(E
);
3096 -- Do not allow a size clause for a type which does not have a size
3097 -- that is known at compile time
3099 if Has_Size_Clause
(E
)
3100 and then not Size_Known_At_Compile_Time
(E
)
3102 -- Supress this message if errors posted on E, even if we are
3103 -- in all errors mode, since this is often a junk message
3105 if not Error_Posted
(E
) then
3107 ("size clause not allowed for variable length type",
3112 -- Remaining process is to set/verify the representation information,
3113 -- in particular the size and alignment values. This processing is
3114 -- not required for generic types, since generic types do not play
3115 -- any part in code generation, and so the size and alignment values
3116 -- for such types are irrelevant.
3118 if Is_Generic_Type
(E
) then
3121 -- Otherwise we call the layout procedure
3127 -- End of freeze processing for type entities
3130 -- Here is where we logically freeze the current entity. If it has a
3131 -- freeze node, then this is the point at which the freeze node is
3132 -- linked into the result list.
3134 if Has_Delayed_Freeze
(E
) then
3136 -- If a freeze node is already allocated, use it, otherwise allocate
3137 -- a new one. The preallocation happens in the case of anonymous base
3138 -- types, where we preallocate so that we can set First_Subtype_Link.
3139 -- Note that we reset the Sloc to the current freeze location.
3141 if Present
(Freeze_Node
(E
)) then
3142 F_Node
:= Freeze_Node
(E
);
3143 Set_Sloc
(F_Node
, Loc
);
3146 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
3147 Set_Freeze_Node
(E
, F_Node
);
3148 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
3149 Set_TSS_Elist
(F_Node
, No_Elist
);
3150 Set_Actions
(F_Node
, No_List
);
3153 Set_Entity
(F_Node
, E
);
3155 if Result
= No_List
then
3156 Result
:= New_List
(F_Node
);
3158 Append
(F_Node
, Result
);
3161 -- A final pass over record types with discriminants. If the type
3162 -- has an incomplete declaration, there may be constrained access
3163 -- subtypes declared elsewhere, which do not depend on the discrimi-
3164 -- nants of the type, and which are used as component types (i.e.
3165 -- the full view is a recursive type). The designated types of these
3166 -- subtypes can only be elaborated after the type itself, and they
3167 -- need an itype reference.
3169 if Ekind
(E
) = E_Record_Type
3170 and then Has_Discriminants
(E
)
3178 Comp
:= First_Component
(E
);
3180 while Present
(Comp
) loop
3181 Typ
:= Etype
(Comp
);
3183 if Ekind
(Comp
) = E_Component
3184 and then Is_Access_Type
(Typ
)
3185 and then Scope
(Typ
) /= E
3186 and then Base_Type
(Designated_Type
(Typ
)) = E
3187 and then Is_Itype
(Designated_Type
(Typ
))
3189 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
3190 Set_Itype
(IR
, Designated_Type
(Typ
));
3191 Append
(IR
, Result
);
3194 Next_Component
(Comp
);
3200 -- When a type is frozen, the first subtype of the type is frozen as
3201 -- well (RM 13.14(15)). This has to be done after freezing the type,
3202 -- since obviously the first subtype depends on its own base type.
3205 Freeze_And_Append
(First_Subtype
(E
), Loc
, Result
);
3207 -- If we just froze a tagged non-class wide record, then freeze the
3208 -- corresponding class-wide type. This must be done after the tagged
3209 -- type itself is frozen, because the class-wide type refers to the
3210 -- tagged type which generates the class.
3212 if Is_Tagged_Type
(E
)
3213 and then not Is_Class_Wide_Type
(E
)
3214 and then Present
(Class_Wide_Type
(E
))
3216 Freeze_And_Append
(Class_Wide_Type
(E
), Loc
, Result
);
3220 Check_Debug_Info_Needed
(E
);
3222 -- Special handling for subprograms
3224 if Is_Subprogram
(E
) then
3226 -- If subprogram has address clause then reset Is_Public flag, since
3227 -- we do not want the backend to generate external references.
3229 if Present
(Address_Clause
(E
))
3230 and then not Is_Library_Level_Entity
(E
)
3232 Set_Is_Public
(E
, False);
3234 -- If no address clause and not intrinsic, then for imported
3235 -- subprogram in main unit, generate descriptor if we are in
3236 -- Propagate_Exceptions mode.
3238 elsif Propagate_Exceptions
3239 and then Is_Imported
(E
)
3240 and then not Is_Intrinsic_Subprogram
(E
)
3241 and then Convention
(E
) /= Convention_Stubbed
3243 if Result
= No_List
then
3244 Result
:= Empty_List
;
3247 Generate_Subprogram_Descriptor_For_Imported_Subprogram
3255 -----------------------------
3256 -- Freeze_Enumeration_Type --
3257 -----------------------------
3259 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
3261 if Has_Foreign_Convention
(Typ
)
3262 and then not Has_Size_Clause
(Typ
)
3263 and then Esize
(Typ
) < Standard_Integer_Size
3265 Init_Esize
(Typ
, Standard_Integer_Size
);
3267 Adjust_Esize_For_Alignment
(Typ
);
3269 end Freeze_Enumeration_Type
;
3271 -----------------------
3272 -- Freeze_Expression --
3273 -----------------------
3275 procedure Freeze_Expression
(N
: Node_Id
) is
3276 In_Def_Exp
: constant Boolean := In_Default_Expression
;
3279 Desig_Typ
: Entity_Id
;
3283 Freeze_Outside
: Boolean := False;
3284 -- This flag is set true if the entity must be frozen outside the
3285 -- current subprogram. This happens in the case of expander generated
3286 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
3287 -- not freeze all entities like other bodies, but which nevertheless
3288 -- may reference entities that have to be frozen before the body and
3289 -- obviously cannot be frozen inside the body.
3291 function In_Exp_Body
(N
: Node_Id
) return Boolean;
3292 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
3293 -- it is the handled statement sequence of an expander-generated
3294 -- subprogram (init proc, or stream subprogram). If so, it returns
3295 -- True, otherwise False.
3301 function In_Exp_Body
(N
: Node_Id
) return Boolean is
3305 if Nkind
(N
) = N_Subprogram_Body
then
3311 if Nkind
(P
) /= N_Subprogram_Body
then
3315 P
:= Defining_Unit_Name
(Specification
(P
));
3317 if Nkind
(P
) = N_Defining_Identifier
3318 and then (Is_Init_Proc
(P
) or else
3319 Is_TSS
(P
, TSS_Stream_Input
) or else
3320 Is_TSS
(P
, TSS_Stream_Output
) or else
3321 Is_TSS
(P
, TSS_Stream_Read
) or else
3322 Is_TSS
(P
, TSS_Stream_Write
))
3331 -- Start of processing for Freeze_Expression
3334 -- Immediate return if freezing is inhibited. This flag is set by
3335 -- the analyzer to stop freezing on generated expressions that would
3336 -- cause freezing if they were in the source program, but which are
3337 -- not supposed to freeze, since they are created.
3339 if Must_Not_Freeze
(N
) then
3343 -- If expression is non-static, then it does not freeze in a default
3344 -- expression, see section "Handling of Default Expressions" in the
3345 -- spec of package Sem for further details. Note that we have to
3346 -- make sure that we actually have a real expression (if we have
3347 -- a subtype indication, we can't test Is_Static_Expression!)
3350 and then Nkind
(N
) in N_Subexpr
3351 and then not Is_Static_Expression
(N
)
3356 -- Freeze type of expression if not frozen already
3360 if Nkind
(N
) in N_Has_Etype
then
3361 if not Is_Frozen
(Etype
(N
)) then
3364 -- Base type may be an derived numeric type that is frozen at
3365 -- the point of declaration, but first_subtype is still unfrozen.
3367 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
3368 Typ
:= First_Subtype
(Etype
(N
));
3372 -- For entity name, freeze entity if not frozen already. A special
3373 -- exception occurs for an identifier that did not come from source.
3374 -- We don't let such identifiers freeze a non-internal entity, i.e.
3375 -- an entity that did come from source, since such an identifier was
3376 -- generated by the expander, and cannot have any semantic effect on
3377 -- the freezing semantics. For example, this stops the parameter of
3378 -- an initialization procedure from freezing the variable.
3380 if Is_Entity_Name
(N
)
3381 and then not Is_Frozen
(Entity
(N
))
3382 and then (Nkind
(N
) /= N_Identifier
3383 or else Comes_From_Source
(N
)
3384 or else not Comes_From_Source
(Entity
(N
)))
3391 -- For an allocator freeze designated type if not frozen already.
3393 -- For an aggregate whose component type is an access type, freeze
3394 -- the designated type now, so that its freeze does not appear within
3395 -- the loop that might be created in the expansion of the aggregate.
3396 -- If the designated type is a private type without full view, the
3397 -- expression cannot contain an allocator, so the type is not frozen.
3403 Desig_Typ
:= Designated_Type
(Etype
(N
));
3406 if Is_Array_Type
(Etype
(N
))
3407 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
3409 Desig_Typ
:= Designated_Type
(Component_Type
(Etype
(N
)));
3412 when N_Selected_Component |
3413 N_Indexed_Component |
3416 if Is_Access_Type
(Etype
(Prefix
(N
))) then
3417 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
3424 if Desig_Typ
/= Empty
3425 and then (Is_Frozen
(Desig_Typ
)
3426 or else (not Is_Fully_Defined
(Desig_Typ
)))
3431 -- All done if nothing needs freezing
3435 and then No
(Desig_Typ
)
3440 -- Loop for looking at the right place to insert the freeze nodes
3441 -- exiting from the loop when it is appropriate to insert the freeze
3442 -- node before the current node P.
3444 -- Also checks some special exceptions to the freezing rules. These
3445 -- cases result in a direct return, bypassing the freeze action.
3449 Parent_P
:= Parent
(P
);
3451 -- If we don't have a parent, then we are not in a well-formed
3452 -- tree. This is an unusual case, but there are some legitimate
3453 -- situations in which this occurs, notably when the expressions
3454 -- in the range of a type declaration are resolved. We simply
3455 -- ignore the freeze request in this case. Is this right ???
3457 if No
(Parent_P
) then
3461 -- See if we have got to an appropriate point in the tree
3463 case Nkind
(Parent_P
) is
3465 -- A special test for the exception of (RM 13.14(8)) for the
3466 -- case of per-object expressions (RM 3.8(18)) occurring in a
3467 -- component definition or a discrete subtype definition. Note
3468 -- that we test for a component declaration which includes both
3469 -- cases we are interested in, and furthermore the tree does not
3470 -- have explicit nodes for either of these two constructs.
3472 when N_Component_Declaration
=>
3474 -- The case we want to test for here is an identifier that is
3475 -- a per-object expression, this is either a discriminant that
3476 -- appears in a context other than the component declaration
3477 -- or it is a reference to the type of the enclosing construct.
3479 -- For either of these cases, we skip the freezing
3481 if not In_Default_Expression
3482 and then Nkind
(N
) = N_Identifier
3483 and then (Present
(Entity
(N
)))
3485 -- We recognize the discriminant case by just looking for
3486 -- a reference to a discriminant. It can only be one for
3487 -- the enclosing construct. Skip freezing in this case.
3489 if Ekind
(Entity
(N
)) = E_Discriminant
then
3492 -- For the case of a reference to the enclosing record,
3493 -- (or task or protected type), we look for a type that
3494 -- matches the current scope.
3496 elsif Entity
(N
) = Current_Scope
then
3501 -- If we have an enumeration literal that appears as the
3502 -- choice in the aggregate of an enumeration representation
3503 -- clause, then freezing does not occur (RM 13.14(10)).
3505 when N_Enumeration_Representation_Clause
=>
3507 -- The case we are looking for is an enumeration literal
3509 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
3510 and then Is_Enumeration_Type
(Etype
(N
))
3512 -- If enumeration literal appears directly as the choice,
3513 -- do not freeze (this is the normal non-overloade case)
3515 if Nkind
(Parent
(N
)) = N_Component_Association
3516 and then First
(Choices
(Parent
(N
))) = N
3520 -- If enumeration literal appears as the name of a
3521 -- function which is the choice, then also do not freeze.
3522 -- This happens in the overloaded literal case, where the
3523 -- enumeration literal is temporarily changed to a function
3524 -- call for overloading analysis purposes.
3526 elsif Nkind
(Parent
(N
)) = N_Function_Call
3528 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
3530 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
3536 -- Normally if the parent is a handled sequence of statements,
3537 -- then the current node must be a statement, and that is an
3538 -- appropriate place to insert a freeze node.
3540 when N_Handled_Sequence_Of_Statements
=>
3542 -- An exception occurs when the sequence of statements is
3543 -- for an expander generated body that did not do the usual
3544 -- freeze all operation. In this case we usually want to
3545 -- freeze outside this body, not inside it, and we skip
3546 -- past the subprogram body that we are inside.
3548 if In_Exp_Body
(Parent_P
) then
3550 -- However, we *do* want to freeze at this point if we have
3551 -- an entity to freeze, and that entity is declared *inside*
3552 -- the body of the expander generated procedure. This case
3553 -- is recognized by the scope of the type, which is either
3554 -- the spec for some enclosing body, or (in the case of
3555 -- init_procs, for which there are no separate specs) the
3559 Subp
: constant Node_Id
:= Parent
(Parent_P
);
3563 if Nkind
(Subp
) = N_Subprogram_Body
then
3564 Cspc
:= Corresponding_Spec
(Subp
);
3566 if (Present
(Typ
) and then Scope
(Typ
) = Cspc
)
3568 (Present
(Nam
) and then Scope
(Nam
) = Cspc
)
3573 and then Scope
(Typ
) = Current_Scope
3574 and then Current_Scope
= Defining_Entity
(Subp
)
3581 -- If not that exception to the exception, then this is
3582 -- where we delay the freeze till outside the body.
3584 Parent_P
:= Parent
(Parent_P
);
3585 Freeze_Outside
:= True;
3587 -- Here if normal case where we are in handled statement
3588 -- sequence and want to do the insertion right there.
3594 -- If parent is a body or a spec or a block, then the current
3595 -- node is a statement or declaration and we can insert the
3596 -- freeze node before it.
3598 when N_Package_Specification |
3604 N_Block_Statement
=> exit;
3606 -- The expander is allowed to define types in any statements list,
3607 -- so any of the following parent nodes also mark a freezing point
3608 -- if the actual node is in a list of statements or declarations.
3610 when N_Exception_Handler |
3613 N_Case_Statement_Alternative |
3614 N_Compilation_Unit_Aux |
3615 N_Selective_Accept |
3616 N_Accept_Alternative |
3617 N_Delay_Alternative |
3618 N_Conditional_Entry_Call |
3619 N_Entry_Call_Alternative |
3620 N_Triggering_Alternative |
3624 exit when Is_List_Member
(P
);
3626 -- Note: The N_Loop_Statement is a special case. A type that
3627 -- appears in the source can never be frozen in a loop (this
3628 -- occurs only because of a loop expanded by the expander),
3629 -- so we keep on going. Otherwise we terminate the search.
3630 -- Same is true of any entity which comes from source. (if they
3631 -- have a predefined type, that type does not appear to come
3632 -- from source, but the entity should not be frozen here).
3634 when N_Loop_Statement
=>
3635 exit when not Comes_From_Source
(Etype
(N
))
3636 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
3638 -- For all other cases, keep looking at parents
3644 -- We fall through the case if we did not yet find the proper
3645 -- place in the free for inserting the freeze node, so climb!
3650 -- If the expression appears in a record or an initialization
3651 -- procedure, the freeze nodes are collected and attached to
3652 -- the current scope, to be inserted and analyzed on exit from
3653 -- the scope, to insure that generated entities appear in the
3654 -- correct scope. If the expression is a default for a discriminant
3655 -- specification, the scope is still void. The expression can also
3656 -- appear in the discriminant part of a private or concurrent type.
3658 -- If the expression appears in a constrained subcomponent of an
3659 -- enclosing record declaration, the freeze nodes must be attached
3660 -- to the outer record type so they can eventually be placed in the
3661 -- enclosing declaration list.
3663 -- The other case requiring this special handling is if we are in
3664 -- a default expression, since in that case we are about to freeze
3665 -- a static type, and the freeze scope needs to be the outer scope,
3666 -- not the scope of the subprogram with the default parameter.
3668 -- For default expressions in generic units, the Move_Freeze_Nodes
3669 -- mechanism (see sem_ch12.adb) takes care of placing them at the
3670 -- proper place, after the generic unit.
3672 if (In_Def_Exp
and not Inside_A_Generic
)
3673 or else Freeze_Outside
3674 or else (Is_Type
(Current_Scope
)
3675 and then (not Is_Concurrent_Type
(Current_Scope
)
3676 or else not Has_Completion
(Current_Scope
)))
3677 or else Ekind
(Current_Scope
) = E_Void
3680 Loc
: constant Source_Ptr
:= Sloc
(Current_Scope
);
3681 Freeze_Nodes
: List_Id
:= No_List
;
3682 Pos
: Int
:= Scope_Stack
.Last
;
3685 if Present
(Desig_Typ
) then
3686 Freeze_And_Append
(Desig_Typ
, Loc
, Freeze_Nodes
);
3689 if Present
(Typ
) then
3690 Freeze_And_Append
(Typ
, Loc
, Freeze_Nodes
);
3693 if Present
(Nam
) then
3694 Freeze_And_Append
(Nam
, Loc
, Freeze_Nodes
);
3697 -- The current scope may be that of a constrained component of
3698 -- an enclosing record declaration, which is above the current
3699 -- scope in the scope stack.
3701 if Is_Record_Type
(Scope
(Current_Scope
)) then
3705 if Is_Non_Empty_List
(Freeze_Nodes
) then
3706 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
3707 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
3710 Append_List
(Freeze_Nodes
, Scope_Stack
.Table
3711 (Pos
).Pending_Freeze_Actions
);
3719 -- Now we have the right place to do the freezing. First, a special
3720 -- adjustment, if we are in default expression analysis mode, these
3721 -- freeze actions must not be thrown away (normally all inserted
3722 -- actions are thrown away in this mode. However, the freeze actions
3723 -- are from static expressions and one of the important reasons we
3724 -- are doing this special analysis is to get these freeze actions.
3725 -- Therefore we turn off the In_Default_Expression mode to propagate
3726 -- these freeze actions. This also means they get properly analyzed
3729 In_Default_Expression
:= False;
3731 -- Freeze the designated type of an allocator (RM 13.14(13))
3733 if Present
(Desig_Typ
) then
3734 Freeze_Before
(P
, Desig_Typ
);
3737 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
3738 -- the enumeration representation clause exception in the loop above.
3740 if Present
(Typ
) then
3741 Freeze_Before
(P
, Typ
);
3744 -- Freeze name if one is present (RM 13.14(11))
3746 if Present
(Nam
) then
3747 Freeze_Before
(P
, Nam
);
3750 In_Default_Expression
:= In_Def_Exp
;
3751 end Freeze_Expression
;
3753 -----------------------------
3754 -- Freeze_Fixed_Point_Type --
3755 -----------------------------
3757 -- Certain fixed-point types and subtypes, including implicit base
3758 -- types and declared first subtypes, have not yet set up a range.
3759 -- This is because the range cannot be set until the Small and Size
3760 -- values are known, and these are not known till the type is frozen.
3762 -- To signal this case, Scalar_Range contains an unanalyzed syntactic
3763 -- range whose bounds are unanalyzed real literals. This routine will
3764 -- recognize this case, and transform this range node into a properly
3765 -- typed range with properly analyzed and resolved values.
3767 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
3768 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
3769 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
3770 Hi
: constant Node_Id
:= High_Bound
(Rng
);
3771 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
3772 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
3773 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
3774 BHi
: constant Node_Id
:= High_Bound
(Brng
);
3775 Small
: constant Ureal
:= Small_Value
(Typ
);
3782 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
3783 -- Returns size of type with given bounds. Also leaves these
3784 -- bounds set as the current bounds of the Typ.
3790 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
3792 Set_Realval
(Lo
, Lov
);
3793 Set_Realval
(Hi
, Hiv
);
3794 return Minimum_Size
(Typ
);
3797 -- Start of processing for Freeze_Fixed_Point_Type
3800 -- If Esize of a subtype has not previously been set, set it now
3802 if Unknown_Esize
(Typ
) then
3803 Atype
:= Ancestor_Subtype
(Typ
);
3805 if Present
(Atype
) then
3806 Set_Esize
(Typ
, Esize
(Atype
));
3808 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
3812 -- Immediate return if the range is already analyzed. This means
3813 -- that the range is already set, and does not need to be computed
3816 if Analyzed
(Rng
) then
3820 -- Immediate return if either of the bounds raises Constraint_Error
3822 if Raises_Constraint_Error
(Lo
)
3823 or else Raises_Constraint_Error
(Hi
)
3828 Loval
:= Realval
(Lo
);
3829 Hival
:= Realval
(Hi
);
3831 -- Ordinary fixed-point case
3833 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
3835 -- For the ordinary fixed-point case, we are allowed to fudge the
3836 -- end-points up or down by small. Generally we prefer to fudge
3837 -- up, i.e. widen the bounds for non-model numbers so that the
3838 -- end points are included. However there are cases in which this
3839 -- cannot be done, and indeed cases in which we may need to narrow
3840 -- the bounds. The following circuit makes the decision.
3842 -- Note: our terminology here is that Incl_EP means that the
3843 -- bounds are widened by Small if necessary to include the end
3844 -- points, and Excl_EP means that the bounds are narrowed by
3845 -- Small to exclude the end-points if this reduces the size.
3847 -- Note that in the Incl case, all we care about is including the
3848 -- end-points. In the Excl case, we want to narrow the bounds as
3849 -- much as permitted by the RM, to give the smallest possible size.
3852 Loval_Incl_EP
: Ureal
;
3853 Hival_Incl_EP
: Ureal
;
3855 Loval_Excl_EP
: Ureal
;
3856 Hival_Excl_EP
: Ureal
;
3862 First_Subt
: Entity_Id
;
3867 -- First step. Base types are required to be symmetrical. Right
3868 -- now, the base type range is a copy of the first subtype range.
3869 -- This will be corrected before we are done, but right away we
3870 -- need to deal with the case where both bounds are non-negative.
3871 -- In this case, we set the low bound to the negative of the high
3872 -- bound, to make sure that the size is computed to include the
3873 -- required sign. Note that we do not need to worry about the
3874 -- case of both bounds negative, because the sign will be dealt
3875 -- with anyway. Furthermore we can't just go making such a bound
3876 -- symmetrical, since in a twos-complement system, there is an
3877 -- extra negative value which could not be accomodated on the
3881 and then not UR_Is_Negative
(Loval
)
3882 and then Hival
> Loval
3885 Set_Realval
(Lo
, Loval
);
3888 -- Compute the fudged bounds. If the number is a model number,
3889 -- then we do nothing to include it, but we are allowed to
3890 -- backoff to the next adjacent model number when we exclude
3891 -- it. If it is not a model number then we straddle the two
3892 -- values with the model numbers on either side.
3894 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
3896 if Loval
= Model_Num
then
3897 Loval_Incl_EP
:= Model_Num
;
3899 Loval_Incl_EP
:= Model_Num
- Small
;
3902 -- The low value excluding the end point is Small greater, but
3903 -- we do not do this exclusion if the low value is positive,
3904 -- since it can't help the size and could actually hurt by
3905 -- crossing the high bound.
3907 if UR_Is_Negative
(Loval_Incl_EP
) then
3908 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
3910 Loval_Excl_EP
:= Loval_Incl_EP
;
3913 -- Similar processing for upper bound and high value
3915 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
3917 if Hival
= Model_Num
then
3918 Hival_Incl_EP
:= Model_Num
;
3920 Hival_Incl_EP
:= Model_Num
+ Small
;
3923 if UR_Is_Positive
(Hival_Incl_EP
) then
3924 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
3926 Hival_Excl_EP
:= Hival_Incl_EP
;
3929 -- One further adjustment is needed. In the case of subtypes,
3930 -- we cannot go outside the range of the base type, or we get
3931 -- peculiarities, and the base type range is already set. This
3932 -- only applies to the Incl values, since clearly the Excl
3933 -- values are already as restricted as they are allowed to be.
3936 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
3937 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
3940 -- Get size including and excluding end points
3942 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
3943 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
3945 -- No need to exclude end-points if it does not reduce size
3947 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
3948 Loval_Excl_EP
:= Loval_Incl_EP
;
3951 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
3952 Hival_Excl_EP
:= Hival_Incl_EP
;
3955 -- Now we set the actual size to be used. We want to use the
3956 -- bounds fudged up to include the end-points but only if this
3957 -- can be done without violating a specifically given size
3958 -- size clause or causing an unacceptable increase in size.
3960 -- Case of size clause given
3962 if Has_Size_Clause
(Typ
) then
3964 -- Use the inclusive size only if it is consistent with
3965 -- the explicitly specified size.
3967 if Size_Incl_EP
<= RM_Size
(Typ
) then
3968 Actual_Lo
:= Loval_Incl_EP
;
3969 Actual_Hi
:= Hival_Incl_EP
;
3970 Actual_Size
:= Size_Incl_EP
;
3972 -- If the inclusive size is too large, we try excluding
3973 -- the end-points (will be caught later if does not work).
3976 Actual_Lo
:= Loval_Excl_EP
;
3977 Actual_Hi
:= Hival_Excl_EP
;
3978 Actual_Size
:= Size_Excl_EP
;
3981 -- Case of size clause not given
3984 -- If we have a base type whose corresponding first subtype
3985 -- has an explicit size that is large enough to include our
3986 -- end-points, then do so. There is no point in working hard
3987 -- to get a base type whose size is smaller than the specified
3988 -- size of the first subtype.
3990 First_Subt
:= First_Subtype
(Typ
);
3992 if Has_Size_Clause
(First_Subt
)
3993 and then Size_Incl_EP
<= Esize
(First_Subt
)
3995 Actual_Size
:= Size_Incl_EP
;
3996 Actual_Lo
:= Loval_Incl_EP
;
3997 Actual_Hi
:= Hival_Incl_EP
;
3999 -- If excluding the end-points makes the size smaller and
4000 -- results in a size of 8,16,32,64, then we take the smaller
4001 -- size. For the 64 case, this is compulsory. For the other
4002 -- cases, it seems reasonable. We like to include end points
4003 -- if we can, but not at the expense of moving to the next
4004 -- natural boundary of size.
4006 elsif Size_Incl_EP
/= Size_Excl_EP
4008 (Size_Excl_EP
= 8 or else
4009 Size_Excl_EP
= 16 or else
4010 Size_Excl_EP
= 32 or else
4013 Actual_Size
:= Size_Excl_EP
;
4014 Actual_Lo
:= Loval_Excl_EP
;
4015 Actual_Hi
:= Hival_Excl_EP
;
4017 -- Otherwise we can definitely include the end points
4020 Actual_Size
:= Size_Incl_EP
;
4021 Actual_Lo
:= Loval_Incl_EP
;
4022 Actual_Hi
:= Hival_Incl_EP
;
4025 -- One pathological case: normally we never fudge a low
4026 -- bound down, since it would seem to increase the size
4027 -- (if it has any effect), but for ranges containing a
4028 -- single value, or no values, the high bound can be
4029 -- small too large. Consider:
4031 -- type t is delta 2.0**(-14)
4032 -- range 131072.0 .. 0;
4034 -- That lower bound is *just* outside the range of 32
4035 -- bits, and does need fudging down in this case. Note
4036 -- that the bounds will always have crossed here, since
4037 -- the high bound will be fudged down if necessary, as
4040 -- type t is delta 2.0**(-14)
4041 -- range 131072.0 .. 131072.0;
4043 -- So we can detect the situation by looking for crossed
4044 -- bounds, and if the bounds are crossed, and the low
4045 -- bound is greater than zero, we will always back it
4046 -- off by small, since this is completely harmless.
4048 if Actual_Lo
> Actual_Hi
then
4049 if UR_Is_Positive
(Actual_Lo
) then
4050 Actual_Lo
:= Loval_Incl_EP
- Small
;
4051 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
4053 -- And of course, we need to do exactly the same parallel
4054 -- fudge for flat ranges in the negative region.
4056 elsif UR_Is_Negative
(Actual_Hi
) then
4057 Actual_Hi
:= Hival_Incl_EP
+ Small
;
4058 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
4063 Set_Realval
(Lo
, Actual_Lo
);
4064 Set_Realval
(Hi
, Actual_Hi
);
4067 -- For the decimal case, none of this fudging is required, since there
4068 -- are no end-point problems in the decimal case (the end-points are
4069 -- always included).
4072 Actual_Size
:= Fsize
(Loval
, Hival
);
4075 -- At this stage, the actual size has been calculated and the proper
4076 -- required bounds are stored in the low and high bounds.
4078 if Actual_Size
> 64 then
4079 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
4081 ("size required (^) for type& too large, maximum is 64", Typ
);
4085 -- Check size against explicit given size
4087 if Has_Size_Clause
(Typ
) then
4088 if Actual_Size
> RM_Size
(Typ
) then
4089 Error_Msg_Uint_1
:= RM_Size
(Typ
);
4090 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
4092 ("size given (^) for type& too small, minimum is ^",
4093 Size_Clause
(Typ
), Typ
);
4096 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
4099 -- Increase size to next natural boundary if no size clause given
4102 if Actual_Size
<= 8 then
4104 elsif Actual_Size
<= 16 then
4106 elsif Actual_Size
<= 32 then
4112 Init_Esize
(Typ
, Actual_Size
);
4113 Adjust_Esize_For_Alignment
(Typ
);
4116 -- If we have a base type, then expand the bounds so that they
4117 -- extend to the full width of the allocated size in bits, to
4118 -- avoid junk range checks on intermediate computations.
4120 if Base_Type
(Typ
) = Typ
then
4121 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
4122 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
4125 -- Final step is to reanalyze the bounds using the proper type
4126 -- and set the Corresponding_Integer_Value fields of the literals.
4128 Set_Etype
(Lo
, Empty
);
4129 Set_Analyzed
(Lo
, False);
4132 -- Resolve with universal fixed if the base type, and the base
4133 -- type if it is a subtype. Note we can't resolve the base type
4134 -- with itself, that would be a reference before definition.
4137 Resolve
(Lo
, Universal_Fixed
);
4142 -- Set corresponding integer value for bound
4144 Set_Corresponding_Integer_Value
4145 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
4147 -- Similar processing for high bound
4149 Set_Etype
(Hi
, Empty
);
4150 Set_Analyzed
(Hi
, False);
4154 Resolve
(Hi
, Universal_Fixed
);
4159 Set_Corresponding_Integer_Value
4160 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
4162 -- Set type of range to correspond to bounds
4164 Set_Etype
(Rng
, Etype
(Lo
));
4166 -- Set Esize to calculated size if not set already
4168 if Unknown_Esize
(Typ
) then
4169 Init_Esize
(Typ
, Actual_Size
);
4172 -- Set RM_Size if not already set. If already set, check value
4175 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
4178 if RM_Size
(Typ
) /= Uint_0
then
4179 if RM_Size
(Typ
) < Minsiz
then
4180 Error_Msg_Uint_1
:= RM_Size
(Typ
);
4181 Error_Msg_Uint_2
:= Minsiz
;
4183 ("size given (^) for type& too small, minimum is ^",
4184 Size_Clause
(Typ
), Typ
);
4188 Set_RM_Size
(Typ
, Minsiz
);
4191 end Freeze_Fixed_Point_Type
;
4197 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
4201 Set_Has_Delayed_Freeze
(T
);
4202 L
:= Freeze_Entity
(T
, Sloc
(N
));
4204 if Is_Non_Empty_List
(L
) then
4205 Insert_Actions
(N
, L
);
4209 --------------------------
4210 -- Freeze_Static_Object --
4211 --------------------------
4213 procedure Freeze_Static_Object
(E
: Entity_Id
) is
4215 Cannot_Be_Static
: exception;
4216 -- Exception raised if the type of a static object cannot be made
4217 -- static. This happens if the type depends on non-global objects.
4219 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
4220 -- Called to ensure that an expression used as part of a type
4221 -- definition is statically allocatable, which means that the type
4222 -- of the expression is statically allocatable, and the expression
4223 -- is either static, or a reference to a library level constant.
4225 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
4226 -- Called to mark a type as static, checking that it is possible
4227 -- to set the type as static. If it is not possible, then the
4228 -- exception Cannot_Be_Static is raised.
4230 -----------------------------
4231 -- Ensure_Expression_Is_SA --
4232 -----------------------------
4234 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
4238 Ensure_Type_Is_SA
(Etype
(N
));
4240 if Is_Static_Expression
(N
) then
4243 elsif Nkind
(N
) = N_Identifier
then
4247 and then Ekind
(Ent
) = E_Constant
4248 and then Is_Library_Level_Entity
(Ent
)
4254 raise Cannot_Be_Static
;
4255 end Ensure_Expression_Is_SA
;
4257 -----------------------
4258 -- Ensure_Type_Is_SA --
4259 -----------------------
4261 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
4266 -- If type is library level, we are all set
4268 if Is_Library_Level_Entity
(Typ
) then
4272 -- We are also OK if the type is already marked as statically
4273 -- allocated, which means we processed it before.
4275 if Is_Statically_Allocated
(Typ
) then
4279 -- Mark type as statically allocated
4281 Set_Is_Statically_Allocated
(Typ
);
4283 -- Check that it is safe to statically allocate this type
4285 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
4286 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
4287 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
4289 elsif Is_Array_Type
(Typ
) then
4290 N
:= First_Index
(Typ
);
4291 while Present
(N
) loop
4292 Ensure_Type_Is_SA
(Etype
(N
));
4296 Ensure_Type_Is_SA
(Component_Type
(Typ
));
4298 elsif Is_Access_Type
(Typ
) then
4299 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
4303 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
4306 if T
/= Standard_Void_Type
then
4307 Ensure_Type_Is_SA
(T
);
4310 F
:= First_Formal
(Designated_Type
(Typ
));
4312 while Present
(F
) loop
4313 Ensure_Type_Is_SA
(Etype
(F
));
4319 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
4322 elsif Is_Record_Type
(Typ
) then
4323 C
:= First_Entity
(Typ
);
4325 while Present
(C
) loop
4326 if Ekind
(C
) = E_Discriminant
4327 or else Ekind
(C
) = E_Component
4329 Ensure_Type_Is_SA
(Etype
(C
));
4331 elsif Is_Type
(C
) then
4332 Ensure_Type_Is_SA
(C
);
4338 elsif Ekind
(Typ
) = E_Subprogram_Type
then
4339 Ensure_Type_Is_SA
(Etype
(Typ
));
4341 C
:= First_Formal
(Typ
);
4342 while Present
(C
) loop
4343 Ensure_Type_Is_SA
(Etype
(C
));
4348 raise Cannot_Be_Static
;
4350 end Ensure_Type_Is_SA
;
4352 -- Start of processing for Freeze_Static_Object
4355 Ensure_Type_Is_SA
(Etype
(E
));
4357 -- Reset True_Constant flag, since something strange is going on
4358 -- with the scoping here, and our simple value tracing may not
4359 -- be sufficient for this indication to be reliable. We kill the
4360 -- Constant_Value indication for the same reason.
4362 Set_Is_True_Constant
(E
, False);
4363 Set_Current_Value
(E
, Empty
);
4366 when Cannot_Be_Static
=>
4368 -- If the object that cannot be static is imported or exported,
4369 -- then we give an error message saying that this object cannot
4370 -- be imported or exported.
4372 if Is_Imported
(E
) then
4374 ("& cannot be imported (local type is not constant)", E
);
4376 -- Otherwise must be exported, something is wrong if compiler
4377 -- is marking something as statically allocated which cannot be).
4379 else pragma Assert
(Is_Exported
(E
));
4381 ("& cannot be exported (local type is not constant)", E
);
4383 end Freeze_Static_Object
;
4385 -----------------------
4386 -- Freeze_Subprogram --
4387 -----------------------
4389 procedure Freeze_Subprogram
(E
: Entity_Id
) is
4394 -- Subprogram may not have an address clause unless it is imported
4396 if Present
(Address_Clause
(E
)) then
4397 if not Is_Imported
(E
) then
4399 ("address clause can only be given " &
4400 "for imported subprogram",
4401 Name
(Address_Clause
(E
)));
4405 -- Reset the Pure indication on an imported subprogram unless an
4406 -- explicit Pure_Function pragma was present. We do this because
4407 -- otherwise it is an insidious error to call a non-pure function
4408 -- from a pure unit and have calls mysteriously optimized away.
4409 -- What happens here is that the Import can bypass the normal
4410 -- check to ensure that pure units call only pure subprograms.
4413 and then Is_Pure
(E
)
4414 and then not Has_Pragma_Pure_Function
(E
)
4416 Set_Is_Pure
(E
, False);
4419 -- For non-foreign convention subprograms, this is where we create
4420 -- the extra formals (for accessibility level and constrained bit
4421 -- information). We delay this till the freeze point precisely so
4422 -- that we know the convention!
4424 if not Has_Foreign_Convention
(E
) then
4425 Create_Extra_Formals
(E
);
4428 -- If this is convention Ada and a Valued_Procedure, that's odd
4430 if Ekind
(E
) = E_Procedure
4431 and then Is_Valued_Procedure
(E
)
4432 and then Convention
(E
) = Convention_Ada
4433 and then Warn_On_Export_Import
4436 ("?Valued_Procedure has no effect for convention Ada", E
);
4437 Set_Is_Valued_Procedure
(E
, False);
4440 -- Case of foreign convention
4445 -- For foreign conventions, warn about return of an
4446 -- unconstrained array.
4448 -- Note: we *do* allow a return by descriptor for the VMS case,
4449 -- though here there is probably more to be done ???
4451 if Ekind
(E
) = E_Function
then
4452 Retype
:= Underlying_Type
(Etype
(E
));
4454 -- If no return type, probably some other error, e.g. a
4455 -- missing full declaration, so ignore.
4460 -- If the return type is generic, we have emitted a warning
4461 -- earlier on, and there is nothing else to check here.
4462 -- Specific instantiations may lead to erroneous behavior.
4464 elsif Is_Generic_Type
(Etype
(E
)) then
4467 elsif Is_Array_Type
(Retype
)
4468 and then not Is_Constrained
(Retype
)
4469 and then Mechanism
(E
) not in Descriptor_Codes
4470 and then Warn_On_Export_Import
4473 ("?foreign convention function& should not return " &
4474 "unconstrained array", E
);
4479 -- If any of the formals for an exported foreign convention
4480 -- subprogram have defaults, then emit an appropriate warning
4481 -- since this is odd (default cannot be used from non-Ada code)
4483 if Is_Exported
(E
) then
4484 F
:= First_Formal
(E
);
4485 while Present
(F
) loop
4486 if Warn_On_Export_Import
4487 and then Present
(Default_Value
(F
))
4490 ("?parameter cannot be defaulted in non-Ada call",
4499 -- For VMS, descriptor mechanisms for parameters are allowed only
4500 -- for imported subprograms.
4502 if OpenVMS_On_Target
then
4503 if not Is_Imported
(E
) then
4504 F
:= First_Formal
(E
);
4505 while Present
(F
) loop
4506 if Mechanism
(F
) in Descriptor_Codes
then
4508 ("descriptor mechanism for parameter not permitted", F
);
4510 ("\can only be used for imported subprogram", F
);
4517 end Freeze_Subprogram
;
4519 ----------------------
4520 -- Is_Fully_Defined --
4521 ----------------------
4523 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
4525 if Ekind
(T
) = E_Class_Wide_Type
then
4526 return Is_Fully_Defined
(Etype
(T
));
4528 elsif Is_Array_Type
(T
) then
4529 return Is_Fully_Defined
(Component_Type
(T
));
4531 elsif Is_Record_Type
(T
)
4532 and not Is_Private_Type
(T
)
4534 -- Verify that the record type has no components with
4535 -- private types without completion.
4541 Comp
:= First_Component
(T
);
4543 while Present
(Comp
) loop
4544 if not Is_Fully_Defined
(Etype
(Comp
)) then
4548 Next_Component
(Comp
);
4553 else return not Is_Private_Type
(T
)
4554 or else Present
(Full_View
(Base_Type
(T
)));
4556 end Is_Fully_Defined
;
4558 ---------------------------------
4559 -- Process_Default_Expressions --
4560 ---------------------------------
4562 procedure Process_Default_Expressions
4564 After
: in out Node_Id
)
4566 Loc
: constant Source_Ptr
:= Sloc
(E
);
4573 Set_Default_Expressions_Processed
(E
);
4575 -- A subprogram instance and its associated anonymous subprogram
4576 -- share their signature. The default expression functions are defined
4577 -- in the wrapper packages for the anonymous subprogram, and should
4578 -- not be generated again for the instance.
4580 if Is_Generic_Instance
(E
)
4581 and then Present
(Alias
(E
))
4582 and then Default_Expressions_Processed
(Alias
(E
))
4587 Formal
:= First_Formal
(E
);
4589 while Present
(Formal
) loop
4590 if Present
(Default_Value
(Formal
)) then
4592 -- We work with a copy of the default expression because we
4593 -- do not want to disturb the original, since this would mess
4594 -- up the conformance checking.
4596 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
4598 -- The analysis of the expression may generate insert actions,
4599 -- which of course must not be executed. We wrap those actions
4600 -- in a procedure that is not called, and later on eliminated.
4601 -- The following cases have no side-effects, and are analyzed
4604 if Nkind
(Dcopy
) = N_Identifier
4605 or else Nkind
(Dcopy
) = N_Expanded_Name
4606 or else Nkind
(Dcopy
) = N_Integer_Literal
4607 or else (Nkind
(Dcopy
) = N_Real_Literal
4608 and then not Vax_Float
(Etype
(Dcopy
)))
4609 or else Nkind
(Dcopy
) = N_Character_Literal
4610 or else Nkind
(Dcopy
) = N_String_Literal
4611 or else Nkind
(Dcopy
) = N_Null
4612 or else (Nkind
(Dcopy
) = N_Attribute_Reference
4614 Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
4617 -- If there is no default function, we must still do a full
4618 -- analyze call on the default value, to ensure that all
4619 -- error checks are performed, e.g. those associated with
4620 -- static evaluation. Note that this branch will always be
4621 -- taken if the analyzer is turned off (but we still need the
4624 -- Note: the setting of parent here is to meet the requirement
4625 -- that we can only analyze the expression while attached to
4626 -- the tree. Really the requirement is that the parent chain
4627 -- be set, we don't actually need to be in the tree.
4629 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
4632 -- Default expressions are resolved with their own type if the
4633 -- context is generic, to avoid anomalies with private types.
4635 if Ekind
(Scope
(E
)) = E_Generic_Package
then
4638 Resolve
(Dcopy
, Etype
(Formal
));
4641 -- If that resolved expression will raise constraint error,
4642 -- then flag the default value as raising constraint error.
4643 -- This allows a proper error message on the calls.
4645 if Raises_Constraint_Error
(Dcopy
) then
4646 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
4649 -- If the default is a parameterless call, we use the name of
4650 -- the called function directly, and there is no body to build.
4652 elsif Nkind
(Dcopy
) = N_Function_Call
4653 and then No
(Parameter_Associations
(Dcopy
))
4657 -- Else construct and analyze the body of a wrapper procedure
4658 -- that contains an object declaration to hold the expression.
4659 -- Given that this is done only to complete the analysis, it
4660 -- simpler to build a procedure than a function which might
4661 -- involve secondary stack expansion.
4665 Make_Defining_Identifier
(Loc
, New_Internal_Name
('D'));
4668 Make_Subprogram_Body
(Loc
,
4670 Make_Procedure_Specification
(Loc
,
4671 Defining_Unit_Name
=> Dnam
),
4673 Declarations
=> New_List
(
4674 Make_Object_Declaration
(Loc
,
4675 Defining_Identifier
=>
4676 Make_Defining_Identifier
(Loc
,
4677 New_Internal_Name
('T')),
4678 Object_Definition
=>
4679 New_Occurrence_Of
(Etype
(Formal
), Loc
),
4680 Expression
=> New_Copy_Tree
(Dcopy
))),
4682 Handled_Statement_Sequence
=>
4683 Make_Handled_Sequence_Of_Statements
(Loc
,
4684 Statements
=> New_List
));
4686 Set_Scope
(Dnam
, Scope
(E
));
4687 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
4688 Set_Is_Eliminated
(Dnam
);
4689 Insert_After
(After
, Dbody
);
4695 Next_Formal
(Formal
);
4698 end Process_Default_Expressions
;
4700 ----------------------------------------
4701 -- Set_Component_Alignment_If_Not_Set --
4702 ----------------------------------------
4704 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
4706 -- Ignore if not base type, subtypes don't need anything
4708 if Typ
/= Base_Type
(Typ
) then
4712 -- Do not override existing representation
4714 if Is_Packed
(Typ
) then
4717 elsif Has_Specified_Layout
(Typ
) then
4720 elsif Component_Alignment
(Typ
) /= Calign_Default
then
4724 Set_Component_Alignment
4725 (Typ
, Scope_Stack
.Table
4726 (Scope_Stack
.Last
).Component_Alignment_Default
);
4728 end Set_Component_Alignment_If_Not_Set
;
4730 ---------------------------
4731 -- Set_Debug_Info_Needed --
4732 ---------------------------
4734 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
4737 or else Needs_Debug_Info
(T
)
4738 or else Debug_Info_Off
(T
)
4742 Set_Needs_Debug_Info
(T
);
4745 if Is_Object
(T
) then
4746 Set_Debug_Info_Needed
(Etype
(T
));
4748 elsif Is_Type
(T
) then
4749 Set_Debug_Info_Needed
(Etype
(T
));
4751 if Is_Record_Type
(T
) then
4753 Ent
: Entity_Id
:= First_Entity
(T
);
4755 while Present
(Ent
) loop
4756 Set_Debug_Info_Needed
(Ent
);
4761 elsif Is_Array_Type
(T
) then
4762 Set_Debug_Info_Needed
(Component_Type
(T
));
4765 Indx
: Node_Id
:= First_Index
(T
);
4767 while Present
(Indx
) loop
4768 Set_Debug_Info_Needed
(Etype
(Indx
));
4769 Indx
:= Next_Index
(Indx
);
4773 if Is_Packed
(T
) then
4774 Set_Debug_Info_Needed
(Packed_Array_Type
(T
));
4777 elsif Is_Access_Type
(T
) then
4778 Set_Debug_Info_Needed
(Directly_Designated_Type
(T
));
4780 elsif Is_Private_Type
(T
) then
4781 Set_Debug_Info_Needed
(Full_View
(T
));
4783 elsif Is_Protected_Type
(T
) then
4784 Set_Debug_Info_Needed
(Corresponding_Record_Type
(T
));
4787 end Set_Debug_Info_Needed
;
4793 procedure Undelay_Type
(T
: Entity_Id
) is
4795 Set_Has_Delayed_Freeze
(T
, False);
4796 Set_Freeze_Node
(T
, Empty
);
4798 -- Since we don't want T to have a Freeze_Node, we don't want its
4799 -- Full_View or Corresponding_Record_Type to have one either.
4801 -- ??? Fundamentally, this whole handling is a kludge. What we really
4802 -- want is to be sure that for an Itype that's part of record R and is
4803 -- a subtype of type T, that it's frozen after the later of the freeze
4804 -- points of R and T. We have no way of doing that directly, so what we
4805 -- do is force most such Itypes to be frozen as part of freezing R via
4806 -- this procedure and only delay the ones that need to be delayed
4807 -- (mostly the designated types of access types that are defined as
4808 -- part of the record).
4810 if Is_Private_Type
(T
)
4811 and then Present
(Full_View
(T
))
4812 and then Is_Itype
(Full_View
(T
))
4813 and then Is_Record_Type
(Scope
(Full_View
(T
)))
4815 Undelay_Type
(Full_View
(T
));
4818 if Is_Concurrent_Type
(T
)
4819 and then Present
(Corresponding_Record_Type
(T
))
4820 and then Is_Itype
(Corresponding_Record_Type
(T
))
4821 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
4823 Undelay_Type
(Corresponding_Record_Type
(T
));
4831 procedure Warn_Overlay
4836 Ent
: constant Entity_Id
:= Entity
(Nam
);
4837 -- The object to which the address clause applies.
4840 Old
: Entity_Id
:= Empty
;
4844 -- No warning if address clause overlay warnings are off
4846 if not Address_Clause_Overlay_Warnings
then
4850 -- No warning if there is an explicit initialization
4852 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
4854 if Present
(Init
) and then Comes_From_Source
(Init
) then
4858 -- We only give the warning for non-imported entities of a type
4859 -- for which a non-null base init proc is defined (or for access
4860 -- types which have implicit null initialization).
4863 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
4864 or else Is_Access_Type
(Typ
))
4865 and then not Is_Imported
(Ent
)
4867 if Nkind
(Expr
) = N_Attribute_Reference
4868 and then Is_Entity_Name
(Prefix
(Expr
))
4870 Old
:= Entity
(Prefix
(Expr
));
4872 elsif Is_Entity_Name
(Expr
)
4873 and then Ekind
(Entity
(Expr
)) = E_Constant
4875 Decl
:= Declaration_Node
(Entity
(Expr
));
4877 if Nkind
(Decl
) = N_Object_Declaration
4878 and then Present
(Expression
(Decl
))
4879 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
4880 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
4882 Old
:= Entity
(Prefix
(Expression
(Decl
)));
4884 elsif Nkind
(Expr
) = N_Function_Call
then
4888 -- A function call (most likely to To_Address) is probably not
4889 -- an overlay, so skip warning. Ditto if the function call was
4890 -- inlined and transformed into an entity.
4892 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
4896 Decl
:= Next
(Parent
(Expr
));
4898 -- If a pragma Import follows, we assume that it is for the current
4899 -- target of the address clause, and skip the warning.
4902 and then Nkind
(Decl
) = N_Pragma
4903 and then Chars
(Decl
) = Name_Import
4908 if Present
(Old
) then
4909 Error_Msg_Node_2
:= Old
;
4911 ("default initialization of & may modify &?",
4915 ("default initialization of & may modify overlaid storage?",
4919 -- Add friendly warning if initialization comes from a packed array
4922 if Is_Record_Type
(Typ
) then
4927 Comp
:= First_Component
(Typ
);
4929 while Present
(Comp
) loop
4930 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
4931 and then Present
(Expression
(Parent
(Comp
)))
4934 elsif Is_Array_Type
(Etype
(Comp
))
4935 and then Present
(Packed_Array_Type
(Etype
(Comp
)))
4938 ("packed array component& will be initialized to zero?",
4942 Next_Component
(Comp
);
4949 ("use pragma Import for & to " &
4950 "suppress initialization ('R'M B.1(24))?",