1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Ch3
; use Exp_Ch3
;
33 with Exp_Ch7
; use Exp_Ch7
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Pakd
; use Exp_Pakd
;
36 with Exp_Util
; use Exp_Util
;
37 with Exp_Tss
; use Exp_Tss
;
38 with Layout
; use Layout
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Cat
; use Sem_Cat
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch7
; use Sem_Ch7
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Ch9
; use Sem_Ch9
;
54 with Sem_Ch13
; use Sem_Ch13
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Mech
; use Sem_Mech
;
57 with Sem_Prag
; use Sem_Prag
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Util
; use Sem_Util
;
60 with Sinfo
; use Sinfo
;
61 with Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Targparm
; use Targparm
;
64 with Tbuild
; use Tbuild
;
65 with Ttypes
; use Ttypes
;
66 with Uintp
; use Uintp
;
67 with Urealp
; use Urealp
;
69 package body Freeze
is
71 -----------------------
72 -- Local Subprograms --
73 -----------------------
75 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
76 -- Typ is a type that is being frozen. If no size clause is given,
77 -- but a default Esize has been computed, then this default Esize is
78 -- adjusted up if necessary to be consistent with a given alignment,
79 -- but never to a value greater than Long_Long_Integer'Size. This
80 -- is used for all discrete types and for fixed-point types.
82 procedure Build_And_Analyze_Renamed_Body
85 After
: in out Node_Id
);
86 -- Build body for a renaming declaration, insert in tree and analyze
88 procedure Check_Address_Clause
(E
: Entity_Id
);
89 -- Apply legality checks to address clauses for object declarations,
90 -- at the point the object is frozen.
92 procedure Check_Component_Storage_Order
93 (Encl_Type
: Entity_Id
;
95 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
96 -- clause, verify that the component type is compatible. For arrays,
97 -- Comp is Empty; for records, it is the entity of the component under
100 procedure Check_Strict_Alignment
(E
: Entity_Id
);
101 -- E is a base type. If E is tagged or has a component that is aliased
102 -- or tagged or contains something this is aliased or tagged, set
105 procedure Check_Unsigned_Type
(E
: Entity_Id
);
106 pragma Inline
(Check_Unsigned_Type
);
107 -- If E is a fixed-point or discrete type, then all the necessary work
108 -- to freeze it is completed except for possible setting of the flag
109 -- Is_Unsigned_Type, which is done by this procedure. The call has no
110 -- effect if the entity E is not a discrete or fixed-point type.
112 procedure Freeze_And_Append
115 Result
: in out List_Id
);
116 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
117 -- nodes to Result, modifying Result from No_List if necessary. N has
118 -- the same usage as in Freeze_Entity.
120 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
121 -- Freeze enumeration type. The Esize field is set as processing
122 -- proceeds (i.e. set by default when the type is declared and then
123 -- adjusted by rep clauses. What this procedure does is to make sure
124 -- that if a foreign convention is specified, and no specific size
125 -- is given, then the size must be at least Integer'Size.
127 procedure Freeze_Static_Object
(E
: Entity_Id
);
128 -- If an object is frozen which has Is_Statically_Allocated set, then
129 -- all referenced types must also be marked with this flag. This routine
130 -- is in charge of meeting this requirement for the object entity E.
132 procedure Freeze_Subprogram
(E
: Entity_Id
);
133 -- Perform freezing actions for a subprogram (create extra formals,
134 -- and set proper default mechanism values). Note that this routine
135 -- is not called for internal subprograms, for which neither of these
136 -- actions is needed (or desirable, we do not want for example to have
137 -- these extra formals present in initialization procedures, where they
138 -- would serve no purpose). In this call E is either a subprogram or
139 -- a subprogram type (i.e. an access to a subprogram).
141 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
142 -- True if T is not private and has no private components, or has a full
143 -- view. Used to determine whether the designated type of an access type
144 -- should be frozen when the access type is frozen. This is done when an
145 -- allocator is frozen, or an expression that may involve attributes of
146 -- the designated type. Otherwise freezing the access type does not freeze
147 -- the designated type.
149 procedure Process_Default_Expressions
151 After
: in out Node_Id
);
152 -- This procedure is called for each subprogram to complete processing of
153 -- default expressions at the point where all types are known to be frozen.
154 -- The expressions must be analyzed in full, to make sure that all error
155 -- processing is done (they have only been pre-analyzed). If the expression
156 -- is not an entity or literal, its analysis may generate code which must
157 -- not be executed. In that case we build a function body to hold that
158 -- code. This wrapper function serves no other purpose (it used to be
159 -- called to evaluate the default, but now the default is inlined at each
162 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
163 -- Typ is a record or array type that is being frozen. This routine sets
164 -- the default component alignment from the scope stack values if the
165 -- alignment is otherwise not specified.
167 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
168 -- As each entity is frozen, this routine is called to deal with the
169 -- setting of Debug_Info_Needed for the entity. This flag is set if
170 -- the entity comes from source, or if we are in Debug_Generated_Code
171 -- mode or if the -gnatdV debug flag is set. However, it never sets
172 -- the flag if Debug_Info_Off is set. This procedure also ensures that
173 -- subsidiary entities have the flag set as required.
175 procedure Undelay_Type
(T
: Entity_Id
);
176 -- T is a type of a component that we know to be an Itype. We don't want
177 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
178 -- Full_View or Corresponding_Record_Type.
180 procedure Warn_Overlay
184 -- Expr is the expression for an address clause for entity Nam whose type
185 -- is Typ. If Typ has a default initialization, and there is no explicit
186 -- initialization in the source declaration, check whether the address
187 -- clause might cause overlaying of an entity, and emit a warning on the
188 -- side effect that the initialization will cause.
190 -------------------------------
191 -- Adjust_Esize_For_Alignment --
192 -------------------------------
194 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
198 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
199 Align
:= Alignment_In_Bits
(Typ
);
201 if Align
> Esize
(Typ
)
202 and then Align
<= Standard_Long_Long_Integer_Size
204 Set_Esize
(Typ
, Align
);
207 end Adjust_Esize_For_Alignment
;
209 ------------------------------------
210 -- Build_And_Analyze_Renamed_Body --
211 ------------------------------------
213 procedure Build_And_Analyze_Renamed_Body
216 After
: in out Node_Id
)
218 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
219 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
221 Renamed_Subp
: Entity_Id
;
224 -- If the renamed subprogram is intrinsic, there is no need for a
225 -- wrapper body: we set the alias that will be called and expanded which
226 -- completes the declaration. This transformation is only legal if the
227 -- renamed entity has already been elaborated.
229 -- Note that it is legal for a renaming_as_body to rename an intrinsic
230 -- subprogram, as long as the renaming occurs before the new entity
231 -- is frozen. See RM 8.5.4 (5).
233 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
234 and then Is_Entity_Name
(Name
(Body_Decl
))
236 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
238 Renamed_Subp
:= Empty
;
241 if Present
(Renamed_Subp
)
242 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
244 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
245 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
247 -- We can make the renaming entity intrinsic if the renamed function
248 -- has an interface name, or if it is one of the shift/rotate
249 -- operations known to the compiler.
251 and then (Present
(Interface_Name
(Renamed_Subp
))
252 or else Chars
(Renamed_Subp
) = Name_Rotate_Left
253 or else Chars
(Renamed_Subp
) = Name_Rotate_Right
254 or else Chars
(Renamed_Subp
) = Name_Shift_Left
255 or else Chars
(Renamed_Subp
) = Name_Shift_Right
256 or else Chars
(Renamed_Subp
) = Name_Shift_Right_Arithmetic
)
258 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
260 if Present
(Alias
(Renamed_Subp
)) then
261 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
263 Set_Alias
(Ent
, Renamed_Subp
);
266 Set_Is_Intrinsic_Subprogram
(Ent
);
267 Set_Has_Completion
(Ent
);
270 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
271 Insert_After
(After
, Body_Node
);
272 Mark_Rewrite_Insertion
(Body_Node
);
276 end Build_And_Analyze_Renamed_Body
;
278 ------------------------
279 -- Build_Renamed_Body --
280 ------------------------
282 function Build_Renamed_Body
284 New_S
: Entity_Id
) return Node_Id
286 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
287 -- We use for the source location of the renamed body, the location of
288 -- the spec entity. It might seem more natural to use the location of
289 -- the renaming declaration itself, but that would be wrong, since then
290 -- the body we create would look as though it was created far too late,
291 -- and this could cause problems with elaboration order analysis,
292 -- particularly in connection with instantiations.
294 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
295 Nam
: constant Node_Id
:= Name
(N
);
297 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
298 Actuals
: List_Id
:= No_List
;
303 O_Formal
: Entity_Id
;
304 Param_Spec
: Node_Id
;
306 Pref
: Node_Id
:= Empty
;
307 -- If the renamed entity is a primitive operation given in prefix form,
308 -- the prefix is the target object and it has to be added as the first
309 -- actual in the generated call.
312 -- Determine the entity being renamed, which is the target of the call
313 -- statement. If the name is an explicit dereference, this is a renaming
314 -- of a subprogram type rather than a subprogram. The name itself is
317 if Nkind
(Nam
) = N_Selected_Component
then
318 Old_S
:= Entity
(Selector_Name
(Nam
));
320 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
321 Old_S
:= Etype
(Nam
);
323 elsif Nkind
(Nam
) = N_Indexed_Component
then
324 if Is_Entity_Name
(Prefix
(Nam
)) then
325 Old_S
:= Entity
(Prefix
(Nam
));
327 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
330 elsif Nkind
(Nam
) = N_Character_Literal
then
331 Old_S
:= Etype
(New_S
);
334 Old_S
:= Entity
(Nam
);
337 if Is_Entity_Name
(Nam
) then
339 -- If the renamed entity is a predefined operator, retain full name
340 -- to ensure its visibility.
342 if Ekind
(Old_S
) = E_Operator
343 and then Nkind
(Nam
) = N_Expanded_Name
345 Call_Name
:= New_Copy
(Name
(N
));
347 Call_Name
:= New_Reference_To
(Old_S
, Loc
);
351 if Nkind
(Nam
) = N_Selected_Component
352 and then Present
(First_Formal
(Old_S
))
354 (Is_Controlling_Formal
(First_Formal
(Old_S
))
355 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
358 -- Retrieve the target object, to be added as a first actual
361 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
362 Pref
:= Prefix
(Nam
);
365 Call_Name
:= New_Copy
(Name
(N
));
368 -- Original name may have been overloaded, but is fully resolved now
370 Set_Is_Overloaded
(Call_Name
, False);
373 -- For simple renamings, subsequent calls can be expanded directly as
374 -- calls to the renamed entity. The body must be generated in any case
375 -- for calls that may appear elsewhere. This is not done in the case
376 -- where the subprogram is an instantiation because the actual proper
377 -- body has not been built yet.
379 if Ekind_In
(Old_S
, E_Function
, E_Procedure
)
380 and then Nkind
(Decl
) = N_Subprogram_Declaration
381 and then not Is_Generic_Instance
(Old_S
)
383 Set_Body_To_Inline
(Decl
, Old_S
);
386 -- The body generated for this renaming is an internal artifact, and
387 -- does not constitute a freeze point for the called entity.
389 Set_Must_Not_Freeze
(Call_Name
);
391 Formal
:= First_Formal
(Defining_Entity
(Decl
));
393 if Present
(Pref
) then
395 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
396 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
399 -- The controlling formal may be an access parameter, or the
400 -- actual may be an access value, so adjust accordingly.
402 if Is_Access_Type
(Pref_Type
)
403 and then not Is_Access_Type
(Form_Type
)
406 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
408 elsif Is_Access_Type
(Form_Type
)
409 and then not Is_Access_Type
(Pref
)
412 (Make_Attribute_Reference
(Loc
,
413 Attribute_Name
=> Name_Access
,
414 Prefix
=> Relocate_Node
(Pref
)));
416 Actuals
:= New_List
(Pref
);
420 elsif Present
(Formal
) then
427 if Present
(Formal
) then
428 while Present
(Formal
) loop
429 Append
(New_Reference_To
(Formal
, Loc
), Actuals
);
430 Next_Formal
(Formal
);
434 -- If the renamed entity is an entry, inherit its profile. For other
435 -- renamings as bodies, both profiles must be subtype conformant, so it
436 -- is not necessary to replace the profile given in the declaration.
437 -- However, default values that are aggregates are rewritten when
438 -- partially analyzed, so we recover the original aggregate to insure
439 -- that subsequent conformity checking works. Similarly, if the default
440 -- expression was constant-folded, recover the original expression.
442 Formal
:= First_Formal
(Defining_Entity
(Decl
));
444 if Present
(Formal
) then
445 O_Formal
:= First_Formal
(Old_S
);
446 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
447 while Present
(Formal
) loop
448 if Is_Entry
(Old_S
) then
449 if Nkind
(Parameter_Type
(Param_Spec
)) /=
452 Set_Etype
(Formal
, Etype
(O_Formal
));
453 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
456 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
457 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
458 Nkind
(Default_Value
(O_Formal
))
460 Set_Expression
(Param_Spec
,
461 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
464 Next_Formal
(Formal
);
465 Next_Formal
(O_Formal
);
470 -- If the renamed entity is a function, the generated body contains a
471 -- return statement. Otherwise, build a procedure call. If the entity is
472 -- an entry, subsequent analysis of the call will transform it into the
473 -- proper entry or protected operation call. If the renamed entity is
474 -- a character literal, return it directly.
476 if Ekind
(Old_S
) = E_Function
477 or else Ekind
(Old_S
) = E_Operator
478 or else (Ekind
(Old_S
) = E_Subprogram_Type
479 and then Etype
(Old_S
) /= Standard_Void_Type
)
482 Make_Simple_Return_Statement
(Loc
,
484 Make_Function_Call
(Loc
,
486 Parameter_Associations
=> Actuals
));
488 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
490 Make_Simple_Return_Statement
(Loc
,
491 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
493 elsif Nkind
(Nam
) = N_Character_Literal
then
495 Make_Simple_Return_Statement
(Loc
,
496 Expression
=> Call_Name
);
500 Make_Procedure_Call_Statement
(Loc
,
502 Parameter_Associations
=> Actuals
);
505 -- Create entities for subprogram body and formals
507 Set_Defining_Unit_Name
(Spec
,
508 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
510 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
511 while Present
(Param_Spec
) loop
512 Set_Defining_Identifier
(Param_Spec
,
513 Make_Defining_Identifier
(Loc
,
514 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
519 Make_Subprogram_Body
(Loc
,
520 Specification
=> Spec
,
521 Declarations
=> New_List
,
522 Handled_Statement_Sequence
=>
523 Make_Handled_Sequence_Of_Statements
(Loc
,
524 Statements
=> New_List
(Call_Node
)));
526 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
528 Make_Subprogram_Declaration
(Loc
,
529 Specification
=> Specification
(N
)));
532 -- Link the body to the entity whose declaration it completes. If
533 -- the body is analyzed when the renamed entity is frozen, it may
534 -- be necessary to restore the proper scope (see package Exp_Ch13).
536 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
537 and then Present
(Corresponding_Spec
(N
))
539 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
541 Set_Corresponding_Spec
(Body_Node
, New_S
);
545 end Build_Renamed_Body
;
547 --------------------------
548 -- Check_Address_Clause --
549 --------------------------
551 procedure Check_Address_Clause
(E
: Entity_Id
) is
552 Addr
: constant Node_Id
:= Address_Clause
(E
);
554 Decl
: constant Node_Id
:= Declaration_Node
(E
);
555 Typ
: constant Entity_Id
:= Etype
(E
);
558 if Present
(Addr
) then
559 Expr
:= Expression
(Addr
);
561 if Needs_Constant_Address
(Decl
, Typ
) then
562 Check_Constant_Address_Clause
(Expr
, E
);
564 -- Has_Delayed_Freeze was set on E when the address clause was
565 -- analyzed. Reset the flag now unless freeze actions were
566 -- attached to it in the mean time.
568 if No
(Freeze_Node
(E
)) then
569 Set_Has_Delayed_Freeze
(E
, False);
573 -- If Rep_Clauses are to be ignored, remove address clause from
574 -- list attached to entity, because it may be illegal for gigi,
575 -- for example by breaking order of elaboration..
577 if Ignore_Rep_Clauses
then
582 Rep
:= First_Rep_Item
(E
);
585 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
589 and then Next_Rep_Item
(Rep
) /= Addr
591 Rep
:= Next_Rep_Item
(Rep
);
595 if Present
(Rep
) then
596 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
600 Rewrite
(Addr
, Make_Null_Statement
(Sloc
(E
)));
602 elsif not Error_Posted
(Expr
)
603 and then not Needs_Finalization
(Typ
)
605 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
608 end Check_Address_Clause
;
610 -----------------------------
611 -- Check_Compile_Time_Size --
612 -----------------------------
614 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
616 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
617 -- Sets the compile time known size (32 bits or less) in the Esize
618 -- field, of T checking for a size clause that was given which attempts
619 -- to give a smaller size, and also checking for an alignment clause.
621 function Size_Known
(T
: Entity_Id
) return Boolean;
622 -- Recursive function that does all the work
624 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
625 -- If T is a constrained subtype, its size is not known if any of its
626 -- discriminant constraints is not static and it is not a null record.
627 -- The test is conservative and doesn't check that the components are
628 -- in fact constrained by non-static discriminant values. Could be made
635 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
640 -- Check for bad size clause given
642 elsif Has_Size_Clause
(T
) then
643 if RM_Size
(T
) < S
then
644 Error_Msg_Uint_1
:= S
;
646 ("size for& too small, minimum allowed is ^",
650 -- Set size if not set already
652 elsif Unknown_RM_Size
(T
) then
661 function Size_Known
(T
: Entity_Id
) return Boolean is
669 if Size_Known_At_Compile_Time
(T
) then
672 -- Always True for scalar types. This is true even for generic formal
673 -- scalar types. We used to return False in the latter case, but the
674 -- size is known at compile time, even in the template, we just do
675 -- not know the exact size but that's not the point of this routine.
677 elsif Is_Scalar_Type
(T
)
678 or else Is_Task_Type
(T
)
684 elsif Is_Array_Type
(T
) then
686 -- String literals always have known size, and we can set it
688 if Ekind
(T
) = E_String_Literal_Subtype
then
689 Set_Small_Size
(T
, Component_Size
(T
)
690 * String_Literal_Length
(T
));
693 -- Unconstrained types never have known at compile time size
695 elsif not Is_Constrained
(T
) then
698 -- Don't do any recursion on type with error posted, since we may
699 -- have a malformed type that leads us into a loop.
701 elsif Error_Posted
(T
) then
704 -- Otherwise if component size unknown, then array size unknown
706 elsif not Size_Known
(Component_Type
(T
)) then
710 -- Check for all indexes static, and also compute possible size
711 -- (in case it is less than 32 and may be packable).
714 Esiz
: Uint
:= Component_Size
(T
);
718 Index
:= First_Index
(T
);
719 while Present
(Index
) loop
720 if Nkind
(Index
) = N_Range
then
721 Get_Index_Bounds
(Index
, Low
, High
);
723 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
727 Low
:= Type_Low_Bound
(Etype
(Index
));
728 High
:= Type_High_Bound
(Etype
(Index
));
731 if not Compile_Time_Known_Value
(Low
)
732 or else not Compile_Time_Known_Value
(High
)
733 or else Etype
(Index
) = Any_Type
738 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
750 Set_Small_Size
(T
, Esiz
);
754 -- Access types always have known at compile time sizes
756 elsif Is_Access_Type
(T
) then
759 -- For non-generic private types, go to underlying type if present
761 elsif Is_Private_Type
(T
)
762 and then not Is_Generic_Type
(T
)
763 and then Present
(Underlying_Type
(T
))
765 -- Don't do any recursion on type with error posted, since we may
766 -- have a malformed type that leads us into a loop.
768 if Error_Posted
(T
) then
771 return Size_Known
(Underlying_Type
(T
));
776 elsif Is_Record_Type
(T
) then
778 -- A class-wide type is never considered to have a known size
780 if Is_Class_Wide_Type
(T
) then
783 -- A subtype of a variant record must not have non-static
784 -- discriminated components.
786 elsif T
/= Base_Type
(T
)
787 and then not Static_Discriminated_Components
(T
)
791 -- Don't do any recursion on type with error posted, since we may
792 -- have a malformed type that leads us into a loop.
794 elsif Error_Posted
(T
) then
798 -- Now look at the components of the record
801 -- The following two variables are used to keep track of the
802 -- size of packed records if we can tell the size of the packed
803 -- record in the front end. Packed_Size_Known is True if so far
804 -- we can figure out the size. It is initialized to True for a
805 -- packed record, unless the record has discriminants. The
806 -- reason we eliminate the discriminated case is that we don't
807 -- know the way the back end lays out discriminated packed
808 -- records. If Packed_Size_Known is True, then Packed_Size is
809 -- the size in bits so far.
811 Packed_Size_Known
: Boolean :=
813 and then not Has_Discriminants
(T
);
815 Packed_Size
: Uint
:= Uint_0
;
818 -- Test for variant part present
820 if Has_Discriminants
(T
)
821 and then Present
(Parent
(T
))
822 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
823 and then Nkind
(Type_Definition
(Parent
(T
))) =
825 and then not Null_Present
(Type_Definition
(Parent
(T
)))
826 and then Present
(Variant_Part
827 (Component_List
(Type_Definition
(Parent
(T
)))))
829 -- If variant part is present, and type is unconstrained,
830 -- then we must have defaulted discriminants, or a size
831 -- clause must be present for the type, or else the size
832 -- is definitely not known at compile time.
834 if not Is_Constrained
(T
)
836 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
837 and then Unknown_RM_Size
(T
)
843 -- Loop through components
845 Comp
:= First_Component_Or_Discriminant
(T
);
846 while Present
(Comp
) loop
847 Ctyp
:= Etype
(Comp
);
849 -- We do not know the packed size if there is a component
850 -- clause present (we possibly could, but this would only
851 -- help in the case of a record with partial rep clauses.
852 -- That's because in the case of full rep clauses, the
853 -- size gets figured out anyway by a different circuit).
855 if Present
(Component_Clause
(Comp
)) then
856 Packed_Size_Known
:= False;
859 -- We need to identify a component that is an array where
860 -- the index type is an enumeration type with non-standard
861 -- representation, and some bound of the type depends on a
864 -- This is because gigi computes the size by doing a
865 -- substitution of the appropriate discriminant value in
866 -- the size expression for the base type, and gigi is not
867 -- clever enough to evaluate the resulting expression (which
868 -- involves a call to rep_to_pos) at compile time.
870 -- It would be nice if gigi would either recognize that
871 -- this expression can be computed at compile time, or
872 -- alternatively figured out the size from the subtype
873 -- directly, where all the information is at hand ???
875 if Is_Array_Type
(Etype
(Comp
))
876 and then Present
(Packed_Array_Type
(Etype
(Comp
)))
879 Ocomp
: constant Entity_Id
:=
880 Original_Record_Component
(Comp
);
881 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
887 Ind
:= First_Index
(OCtyp
);
888 while Present
(Ind
) loop
889 Indtyp
:= Etype
(Ind
);
891 if Is_Enumeration_Type
(Indtyp
)
892 and then Has_Non_Standard_Rep
(Indtyp
)
894 Lo
:= Type_Low_Bound
(Indtyp
);
895 Hi
:= Type_High_Bound
(Indtyp
);
897 if Is_Entity_Name
(Lo
)
898 and then Ekind
(Entity
(Lo
)) = E_Discriminant
902 elsif Is_Entity_Name
(Hi
)
903 and then Ekind
(Entity
(Hi
)) = E_Discriminant
914 -- Clearly size of record is not known if the size of one of
915 -- the components is not known.
917 if not Size_Known
(Ctyp
) then
921 -- Accumulate packed size if possible
923 if Packed_Size_Known
then
925 -- We can only deal with elementary types, since for
926 -- non-elementary components, alignment enters into the
927 -- picture, and we don't know enough to handle proper
928 -- alignment in this context. Packed arrays count as
929 -- elementary if the representation is a modular type.
931 if Is_Elementary_Type
(Ctyp
)
932 or else (Is_Array_Type
(Ctyp
)
933 and then Present
(Packed_Array_Type
(Ctyp
))
934 and then Is_Modular_Integer_Type
935 (Packed_Array_Type
(Ctyp
)))
937 -- If RM_Size is known and static, then we can keep
938 -- accumulating the packed size.
940 if Known_Static_RM_Size
(Ctyp
) then
942 -- A little glitch, to be removed sometime ???
943 -- gigi does not understand zero sizes yet.
945 if RM_Size
(Ctyp
) = Uint_0
then
946 Packed_Size_Known
:= False;
948 -- Normal case where we can keep accumulating the
949 -- packed array size.
952 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
955 -- If we have a field whose RM_Size is not known then
956 -- we can't figure out the packed size here.
959 Packed_Size_Known
:= False;
962 -- If we have a non-elementary type we can't figure out
963 -- the packed array size (alignment issues).
966 Packed_Size_Known
:= False;
970 Next_Component_Or_Discriminant
(Comp
);
973 if Packed_Size_Known
then
974 Set_Small_Size
(T
, Packed_Size
);
980 -- All other cases, size not known at compile time
987 -------------------------------------
988 -- Static_Discriminated_Components --
989 -------------------------------------
991 function Static_Discriminated_Components
992 (T
: Entity_Id
) return Boolean
994 Constraint
: Elmt_Id
;
997 if Has_Discriminants
(T
)
998 and then Present
(Discriminant_Constraint
(T
))
999 and then Present
(First_Component
(T
))
1001 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1002 while Present
(Constraint
) loop
1003 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1007 Next_Elmt
(Constraint
);
1012 end Static_Discriminated_Components
;
1014 -- Start of processing for Check_Compile_Time_Size
1017 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1018 end Check_Compile_Time_Size
;
1020 -----------------------------------
1021 -- Check_Component_Storage_Order --
1022 -----------------------------------
1024 procedure Check_Component_Storage_Order
1025 (Encl_Type
: Entity_Id
;
1028 Comp_Type
: Entity_Id
;
1033 Comp_Byte_Aligned
: Boolean;
1034 -- Set True for the record case, when Comp starts on a byte boundary
1035 -- (in which case it is allowed to have different storage order).
1040 if Present
(Comp
) then
1042 Comp_Type
:= Etype
(Comp
);
1043 Comp_Def
:= Component_Definition
(Parent
(Comp
));
1045 Comp_Byte_Aligned
:=
1046 Present
(Component_Clause
(Comp
))
1047 and then Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1052 Err_Node
:= Encl_Type
;
1053 Comp_Type
:= Component_Type
(Encl_Type
);
1054 Comp_Def
:= Component_Definition
1055 (Type_Definition
(Declaration_Node
(Encl_Type
)));
1057 Comp_Byte_Aligned
:= False;
1060 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1061 -- the attribute definition clause is attached to the first subtype.
1063 Comp_Type
:= Base_Type
(Comp_Type
);
1064 ADC
:= Get_Attribute_Definition_Clause
1065 (First_Subtype
(Comp_Type
),
1066 Attribute_Scalar_Storage_Order
);
1068 if Is_Record_Type
(Comp_Type
) or else Is_Array_Type
(Comp_Type
) then
1070 Error_Msg_N
("nested composite must have explicit scalar "
1071 & "storage order", Err_Node
);
1073 elsif (Reverse_Storage_Order
(Encl_Type
)
1075 Reverse_Storage_Order
(Etype
(Comp_Type
)))
1076 and then not Comp_Byte_Aligned
1079 ("type of non-byte-aligned component must have same scalar "
1080 & "storage order as enclosing composite", Err_Node
);
1083 elsif Aliased_Present
(Comp_Def
) then
1085 ("aliased component not permitted for type with "
1086 & "explicit Scalar_Storage_Order", Err_Node
);
1088 end Check_Component_Storage_Order
;
1090 -----------------------------
1091 -- Check_Debug_Info_Needed --
1092 -----------------------------
1094 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1096 if Debug_Info_Off
(T
) then
1099 elsif Comes_From_Source
(T
)
1100 or else Debug_Generated_Code
1101 or else Debug_Flag_VV
1102 or else Needs_Debug_Info
(T
)
1104 Set_Debug_Info_Needed
(T
);
1106 end Check_Debug_Info_Needed
;
1108 ----------------------------
1109 -- Check_Strict_Alignment --
1110 ----------------------------
1112 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1116 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1117 Set_Strict_Alignment
(E
);
1119 elsif Is_Array_Type
(E
) then
1120 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1122 elsif Is_Record_Type
(E
) then
1123 if Is_Limited_Record
(E
) then
1124 Set_Strict_Alignment
(E
);
1128 Comp
:= First_Component
(E
);
1129 while Present
(Comp
) loop
1130 if not Is_Type
(Comp
)
1131 and then (Strict_Alignment
(Etype
(Comp
))
1132 or else Is_Aliased
(Comp
))
1134 Set_Strict_Alignment
(E
);
1138 Next_Component
(Comp
);
1141 end Check_Strict_Alignment
;
1143 -------------------------
1144 -- Check_Unsigned_Type --
1145 -------------------------
1147 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1148 Ancestor
: Entity_Id
;
1153 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1157 -- Do not attempt to analyze case where range was in error
1159 if No
(Scalar_Range
(E
))
1160 or else Error_Posted
(Scalar_Range
(E
))
1165 -- The situation that is non trivial is something like
1167 -- subtype x1 is integer range -10 .. +10;
1168 -- subtype x2 is x1 range 0 .. V1;
1169 -- subtype x3 is x2 range V2 .. V3;
1170 -- subtype x4 is x3 range V4 .. V5;
1172 -- where Vn are variables. Here the base type is signed, but we still
1173 -- know that x4 is unsigned because of the lower bound of x2.
1175 -- The only way to deal with this is to look up the ancestor chain
1179 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1183 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1185 if Compile_Time_Known_Value
(Lo_Bound
) then
1187 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1188 Set_Is_Unsigned_Type
(E
, True);
1194 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1196 -- If no ancestor had a static lower bound, go to base type
1198 if No
(Ancestor
) then
1200 -- Note: the reason we still check for a compile time known
1201 -- value for the base type is that at least in the case of
1202 -- generic formals, we can have bounds that fail this test,
1203 -- and there may be other cases in error situations.
1205 Btyp
:= Base_Type
(E
);
1207 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1211 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1213 if Compile_Time_Known_Value
(Lo_Bound
)
1214 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1216 Set_Is_Unsigned_Type
(E
, True);
1223 end Check_Unsigned_Type
;
1225 -------------------------
1226 -- Is_Atomic_Aggregate --
1227 -------------------------
1229 function Is_Atomic_Aggregate
1231 Typ
: Entity_Id
) return Boolean
1233 Loc
: constant Source_Ptr
:= Sloc
(E
);
1241 -- Array may be qualified, so find outer context
1243 if Nkind
(Par
) = N_Qualified_Expression
then
1244 Par
:= Parent
(Par
);
1247 if Nkind_In
(Par
, N_Object_Declaration
, N_Assignment_Statement
)
1248 and then Comes_From_Source
(Par
)
1250 Temp
:= Make_Temporary
(Loc
, 'T', E
);
1252 Make_Object_Declaration
(Loc
,
1253 Defining_Identifier
=> Temp
,
1254 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1255 Expression
=> Relocate_Node
(E
));
1256 Insert_Before
(Par
, New_N
);
1259 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1265 end Is_Atomic_Aggregate
;
1271 -- Note: the easy coding for this procedure would be to just build a
1272 -- single list of freeze nodes and then insert them and analyze them
1273 -- all at once. This won't work, because the analysis of earlier freeze
1274 -- nodes may recursively freeze types which would otherwise appear later
1275 -- on in the freeze list. So we must analyze and expand the freeze nodes
1276 -- as they are generated.
1278 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1282 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1283 -- This is the internal recursive routine that does freezing of entities
1284 -- (but NOT the analysis of default expressions, which should not be
1285 -- recursive, we don't want to analyze those till we are sure that ALL
1286 -- the types are frozen).
1288 --------------------
1289 -- Freeze_All_Ent --
1290 --------------------
1292 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1297 procedure Process_Flist
;
1298 -- If freeze nodes are present, insert and analyze, and reset cursor
1299 -- for next insertion.
1305 procedure Process_Flist
is
1307 if Is_Non_Empty_List
(Flist
) then
1308 Lastn
:= Next
(After
);
1309 Insert_List_After_And_Analyze
(After
, Flist
);
1311 if Present
(Lastn
) then
1312 After
:= Prev
(Lastn
);
1314 After
:= Last
(List_Containing
(After
));
1319 -- Start or processing for Freeze_All_Ent
1323 while Present
(E
) loop
1325 -- If the entity is an inner package which is not a package
1326 -- renaming, then its entities must be frozen at this point. Note
1327 -- that such entities do NOT get frozen at the end of the nested
1328 -- package itself (only library packages freeze).
1330 -- Same is true for task declarations, where anonymous records
1331 -- created for entry parameters must be frozen.
1333 if Ekind
(E
) = E_Package
1334 and then No
(Renamed_Object
(E
))
1335 and then not Is_Child_Unit
(E
)
1336 and then not Is_Frozen
(E
)
1339 Install_Visible_Declarations
(E
);
1340 Install_Private_Declarations
(E
);
1342 Freeze_All
(First_Entity
(E
), After
);
1344 End_Package_Scope
(E
);
1346 if Is_Generic_Instance
(E
)
1347 and then Has_Delayed_Freeze
(E
)
1349 Set_Has_Delayed_Freeze
(E
, False);
1350 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1353 elsif Ekind
(E
) in Task_Kind
1355 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
1357 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
1360 Freeze_All
(First_Entity
(E
), After
);
1363 -- For a derived tagged type, we must ensure that all the
1364 -- primitive operations of the parent have been frozen, so that
1365 -- their addresses will be in the parent's dispatch table at the
1366 -- point it is inherited.
1368 elsif Ekind
(E
) = E_Record_Type
1369 and then Is_Tagged_Type
(E
)
1370 and then Is_Tagged_Type
(Etype
(E
))
1371 and then Is_Derived_Type
(E
)
1374 Prim_List
: constant Elist_Id
:=
1375 Primitive_Operations
(Etype
(E
));
1381 Prim
:= First_Elmt
(Prim_List
);
1382 while Present
(Prim
) loop
1383 Subp
:= Node
(Prim
);
1385 if Comes_From_Source
(Subp
)
1386 and then not Is_Frozen
(Subp
)
1388 Flist
:= Freeze_Entity
(Subp
, After
);
1397 if not Is_Frozen
(E
) then
1398 Flist
:= Freeze_Entity
(E
, After
);
1401 -- If already frozen, and there are delayed aspects, this is where
1402 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1403 -- for a description of how we handle aspect visibility).
1405 elsif Has_Delayed_Aspects
(E
) then
1407 -- Retrieve the visibility to the discriminants in order to
1408 -- analyze properly the aspects.
1410 Push_Scope_And_Install_Discriminants
(E
);
1416 Ritem
:= First_Rep_Item
(E
);
1417 while Present
(Ritem
) loop
1418 if Nkind
(Ritem
) = N_Aspect_Specification
1419 and then Entity
(Ritem
) = E
1420 and then Is_Delayed_Aspect
(Ritem
)
1422 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1425 Ritem
:= Next_Rep_Item
(Ritem
);
1429 Uninstall_Discriminants_And_Pop_Scope
(E
);
1432 -- If an incomplete type is still not frozen, this may be a
1433 -- premature freezing because of a body declaration that follows.
1434 -- Indicate where the freezing took place. Freezing will happen
1435 -- if the body comes from source, but not if it is internally
1436 -- generated, for example as the body of a type invariant.
1438 -- If the freezing is caused by the end of the current declarative
1439 -- part, it is a Taft Amendment type, and there is no error.
1441 if not Is_Frozen
(E
)
1442 and then Ekind
(E
) = E_Incomplete_Type
1445 Bod
: constant Node_Id
:= Next
(After
);
1448 -- The presence of a body freezes all entities previously
1449 -- declared in the current list of declarations, but this
1450 -- does not apply if the body does not come from source.
1451 -- A type invariant is transformed into a subprogram body
1452 -- which is placed at the end of the private part of the
1453 -- current package, but this body does not freeze incomplete
1454 -- types that may be declared in this private part.
1456 if (Nkind_In
(Bod
, N_Subprogram_Body
,
1461 or else Nkind
(Bod
) in N_Body_Stub
)
1463 List_Containing
(After
) = List_Containing
(Parent
(E
))
1464 and then Comes_From_Source
(Bod
)
1466 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1468 ("type& is frozen# before its full declaration",
1478 -- Start of processing for Freeze_All
1481 Freeze_All_Ent
(From
, After
);
1483 -- Now that all types are frozen, we can deal with default expressions
1484 -- that require us to build a default expression functions. This is the
1485 -- point at which such functions are constructed (after all types that
1486 -- might be used in such expressions have been frozen).
1488 -- For subprograms that are renaming_as_body, we create the wrapper
1489 -- bodies as needed.
1491 -- We also add finalization chains to access types whose designated
1492 -- types are controlled. This is normally done when freezing the type,
1493 -- but this misses recursive type definitions where the later members
1494 -- of the recursion introduce controlled components.
1496 -- Loop through entities
1499 while Present
(E
) loop
1500 if Is_Subprogram
(E
) then
1502 if not Default_Expressions_Processed
(E
) then
1503 Process_Default_Expressions
(E
, After
);
1506 if not Has_Completion
(E
) then
1507 Decl
:= Unit_Declaration_Node
(E
);
1509 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1510 if Error_Posted
(Decl
) then
1511 Set_Has_Completion
(E
);
1513 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1516 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1517 and then Present
(Corresponding_Body
(Decl
))
1519 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1520 = N_Subprogram_Renaming_Declaration
1522 Build_And_Analyze_Renamed_Body
1523 (Decl
, Corresponding_Body
(Decl
), After
);
1527 elsif Ekind
(E
) in Task_Kind
1529 (Nkind
(Parent
(E
)) = N_Task_Type_Declaration
1531 Nkind
(Parent
(E
)) = N_Single_Task_Declaration
)
1537 Ent
:= First_Entity
(E
);
1538 while Present
(Ent
) loop
1540 and then not Default_Expressions_Processed
(Ent
)
1542 Process_Default_Expressions
(Ent
, After
);
1549 -- We add finalization masters to access types whose designated types
1550 -- require finalization. This is normally done when freezing the
1551 -- type, but this misses recursive type definitions where the later
1552 -- members of the recursion introduce controlled components (such as
1553 -- can happen when incomplete types are involved), as well cases
1554 -- where a component type is private and the controlled full type
1555 -- occurs after the access type is frozen. Cases that don't need a
1556 -- finalization master are generic formal types (the actual type will
1557 -- have it) and types with Java and CIL conventions, since those are
1558 -- used for API bindings. (Are there any other cases that should be
1559 -- excluded here???)
1561 elsif Is_Access_Type
(E
)
1562 and then Comes_From_Source
(E
)
1563 and then not Is_Generic_Type
(E
)
1564 and then Needs_Finalization
(Designated_Type
(E
))
1566 Build_Finalization_Master
(E
);
1573 -----------------------
1574 -- Freeze_And_Append --
1575 -----------------------
1577 procedure Freeze_And_Append
1580 Result
: in out List_Id
)
1582 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1584 if Is_Non_Empty_List
(L
) then
1585 if Result
= No_List
then
1588 Append_List
(L
, Result
);
1591 end Freeze_And_Append
;
1597 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1598 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, N
);
1600 if Is_Non_Empty_List
(Freeze_Nodes
) then
1601 Insert_Actions
(N
, Freeze_Nodes
);
1609 function Freeze_Entity
(E
: Entity_Id
; N
: Node_Id
) return List_Id
is
1610 Loc
: constant Source_Ptr
:= Sloc
(N
);
1611 Test_E
: Entity_Id
:= E
;
1618 Result
: List_Id
:= No_List
;
1619 -- List of freezing actions, left at No_List if none
1621 Has_Default_Initialization
: Boolean := False;
1622 -- This flag gets set to true for a variable with default initialization
1624 procedure Add_To_Result
(N
: Node_Id
);
1625 -- N is a freezing action to be appended to the Result
1627 function After_Last_Declaration
return Boolean;
1628 -- If Loc is a freeze_entity that appears after the last declaration
1629 -- in the scope, inhibit error messages on late completion.
1631 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1632 -- Check that an Access or Unchecked_Access attribute with a prefix
1633 -- which is the current instance type can only be applied when the type
1636 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1637 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1638 -- integer literal without an explicit corresponding size clause. The
1639 -- caller has checked that Utype is a modular integer type.
1641 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1642 -- Freeze each component, handle some representation clauses, and freeze
1643 -- primitive operations if this is a tagged type.
1649 procedure Add_To_Result
(N
: Node_Id
) is
1652 Result
:= New_List
(N
);
1658 ----------------------------
1659 -- After_Last_Declaration --
1660 ----------------------------
1662 function After_Last_Declaration
return Boolean is
1663 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
1665 if Nkind
(Spec
) = N_Package_Specification
then
1666 if Present
(Private_Declarations
(Spec
)) then
1667 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1668 elsif Present
(Visible_Declarations
(Spec
)) then
1669 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1676 end After_Last_Declaration
;
1678 ----------------------------
1679 -- Check_Current_Instance --
1680 ----------------------------
1682 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1684 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
1685 -- Determine whether Typ is compatible with the rules for aliased
1686 -- views of types as defined in RM 3.10 in the various dialects.
1688 function Process
(N
: Node_Id
) return Traverse_Result
;
1689 -- Process routine to apply check to given node
1691 -----------------------------
1692 -- Is_Aliased_View_Of_Type --
1693 -----------------------------
1695 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
1696 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
1701 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
1702 and then Limited_Present
(Type_Definition
(Typ_Decl
))
1706 -- The following paragraphs describe what a legal aliased view of
1707 -- a type is in the various dialects of Ada.
1711 -- The current instance of a limited type, and a formal parameter
1712 -- or generic formal object of a tagged type.
1714 -- Ada 95 limited type
1715 -- * Type with reserved word "limited"
1716 -- * A protected or task type
1717 -- * A composite type with limited component
1719 elsif Ada_Version
<= Ada_95
then
1720 return Is_Limited_Type
(Typ
);
1724 -- The current instance of a limited tagged type, a protected
1725 -- type, a task type, or a type that has the reserved word
1726 -- "limited" in its full definition ... a formal parameter or
1727 -- generic formal object of a tagged type.
1729 -- Ada 2005 limited type
1730 -- * Type with reserved word "limited", "synchronized", "task"
1732 -- * A composite type with limited component
1733 -- * A derived type whose parent is a non-interface limited type
1735 elsif Ada_Version
= Ada_2005
then
1737 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
1739 (Is_Derived_Type
(Typ
)
1740 and then not Is_Interface
(Etype
(Typ
))
1741 and then Is_Limited_Type
(Etype
(Typ
)));
1743 -- Ada 2012 and beyond
1745 -- The current instance of an immutably limited type ... a formal
1746 -- parameter or generic formal object of a tagged type.
1748 -- Ada 2012 limited type
1749 -- * Type with reserved word "limited", "synchronized", "task"
1751 -- * A composite type with limited component
1752 -- * A derived type whose parent is a non-interface limited type
1753 -- * An incomplete view
1755 -- Ada 2012 immutably limited type
1756 -- * Explicitly limited record type
1757 -- * Record extension with "limited" present
1758 -- * Non-formal limited private type that is either tagged
1759 -- or has at least one access discriminant with a default
1761 -- * Task type, protected type or synchronized interface
1762 -- * Type derived from immutably limited type
1766 Is_Immutably_Limited_Type
(Typ
)
1767 or else Is_Incomplete_Type
(Typ
);
1769 end Is_Aliased_View_Of_Type
;
1775 function Process
(N
: Node_Id
) return Traverse_Result
is
1778 when N_Attribute_Reference
=>
1779 if (Attribute_Name
(N
) = Name_Access
1781 Attribute_Name
(N
) = Name_Unchecked_Access
)
1782 and then Is_Entity_Name
(Prefix
(N
))
1783 and then Is_Type
(Entity
(Prefix
(N
)))
1784 and then Entity
(Prefix
(N
)) = E
1787 ("current instance must be a limited type", Prefix
(N
));
1793 when others => return OK
;
1797 procedure Traverse
is new Traverse_Proc
(Process
);
1801 Rec_Type
: constant Entity_Id
:=
1802 Scope
(Defining_Identifier
(Comp_Decl
));
1804 -- Start of processing for Check_Current_Instance
1807 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
1808 Traverse
(Comp_Decl
);
1810 end Check_Current_Instance
;
1812 ------------------------------
1813 -- Check_Suspicious_Modulus --
1814 ------------------------------
1816 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
1817 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
1820 if Nkind
(Decl
) = N_Full_Type_Declaration
then
1822 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
1825 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
1827 Modulus
: constant Node_Id
:=
1828 Original_Node
(Expression
(Tdef
));
1830 if Nkind
(Modulus
) = N_Integer_Literal
then
1832 Modv
: constant Uint
:= Intval
(Modulus
);
1833 Sizv
: constant Uint
:= RM_Size
(Utype
);
1836 -- First case, modulus and size are the same. This
1837 -- happens if you have something like mod 32, with
1838 -- an explicit size of 32, this is for sure a case
1839 -- where the warning is given, since it is seems
1840 -- very unlikely that someone would want e.g. a
1841 -- five bit type stored in 32 bits. It is much
1842 -- more likely they wanted a 32-bit type.
1847 -- Second case, the modulus is 32 or 64 and no
1848 -- size clause is present. This is a less clear
1849 -- case for giving the warning, but in the case
1850 -- of 32/64 (5-bit or 6-bit types) these seem rare
1851 -- enough that it is a likely error (and in any
1852 -- case using 2**5 or 2**6 in these cases seems
1853 -- clearer. We don't include 8 or 16 here, simply
1854 -- because in practice 3-bit and 4-bit types are
1855 -- more common and too many false positives if
1856 -- we warn in these cases.
1858 elsif not Has_Size_Clause
(Utype
)
1859 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
1863 -- No warning needed
1869 -- If we fall through, give warning
1871 Error_Msg_Uint_1
:= Modv
;
1873 ("?2 '*'*^' may have been intended here",
1881 end Check_Suspicious_Modulus
;
1883 ------------------------
1884 -- Freeze_Record_Type --
1885 ------------------------
1887 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
1894 pragma Warnings
(Off
, Junk
);
1896 Rec_Pushed
: Boolean := False;
1897 -- Set True if the record type scope Rec has been pushed on the scope
1898 -- stack. Needed for the analysis of delayed aspects specified to the
1899 -- components of Rec.
1901 Unplaced_Component
: Boolean := False;
1902 -- Set True if we find at least one component with no component
1903 -- clause (used to warn about useless Pack pragmas).
1905 Placed_Component
: Boolean := False;
1906 -- Set True if we find at least one component with a component
1907 -- clause (used to warn about useless Bit_Order pragmas, and also
1908 -- to detect cases where Implicit_Packing may have an effect).
1910 All_Scalar_Components
: Boolean := True;
1911 -- Set False if we encounter a component of a non-scalar type
1913 Scalar_Component_Total_RM_Size
: Uint
:= Uint_0
;
1914 Scalar_Component_Total_Esize
: Uint
:= Uint_0
;
1915 -- Accumulates total RM_Size values and total Esize values of all
1916 -- scalar components. Used for processing of Implicit_Packing.
1918 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
1919 -- If N is an allocator, possibly wrapped in one or more level of
1920 -- qualified expression(s), return the inner allocator node, else
1923 procedure Check_Itype
(Typ
: Entity_Id
);
1924 -- If the component subtype is an access to a constrained subtype of
1925 -- an already frozen type, make the subtype frozen as well. It might
1926 -- otherwise be frozen in the wrong scope, and a freeze node on
1927 -- subtype has no effect. Similarly, if the component subtype is a
1928 -- regular (not protected) access to subprogram, set the anonymous
1929 -- subprogram type to frozen as well, to prevent an out-of-scope
1930 -- freeze node at some eventual point of call. Protected operations
1931 -- are handled elsewhere.
1933 ---------------------
1934 -- Check_Allocator --
1935 ---------------------
1937 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
1942 if Nkind
(Inner
) = N_Allocator
then
1944 elsif Nkind
(Inner
) = N_Qualified_Expression
then
1945 Inner
:= Expression
(Inner
);
1950 end Check_Allocator
;
1956 procedure Check_Itype
(Typ
: Entity_Id
) is
1957 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
1960 if not Is_Frozen
(Desig
)
1961 and then Is_Frozen
(Base_Type
(Desig
))
1963 Set_Is_Frozen
(Desig
);
1965 -- In addition, add an Itype_Reference to ensure that the
1966 -- access subtype is elaborated early enough. This cannot be
1967 -- done if the subtype may depend on discriminants.
1969 if Ekind
(Comp
) = E_Component
1970 and then Is_Itype
(Etype
(Comp
))
1971 and then not Has_Discriminants
(Rec
)
1973 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
1974 Set_Itype
(IR
, Desig
);
1978 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
1979 and then Convention
(Desig
) /= Convention_Protected
1981 Set_Is_Frozen
(Desig
);
1985 -- Start of processing for Freeze_Record_Type
1988 -- Deal with delayed aspect specifications for components. The
1989 -- analysis of the aspect is required to be delayed to the freeze
1990 -- point, thus we analyze the pragma or attribute definition
1991 -- clause in the tree at this point. We also analyze the aspect
1992 -- specification node at the freeze point when the aspect doesn't
1993 -- correspond to pragma/attribute definition clause.
1995 Comp
:= First_Entity
(Rec
);
1996 while Present
(Comp
) loop
1997 if Ekind
(Comp
) = E_Component
1998 and then Has_Delayed_Aspects
(Comp
)
2000 if not Rec_Pushed
then
2004 -- The visibility to the discriminants must be restored in
2005 -- order to properly analyze the aspects.
2007 if Has_Discriminants
(Rec
) then
2008 Install_Discriminants
(Rec
);
2012 Analyze_Aspects_At_Freeze_Point
(Comp
);
2018 -- Pop the scope if Rec scope has been pushed on the scope stack
2019 -- during the delayed aspect analysis process.
2022 if Has_Discriminants
(Rec
) then
2023 Uninstall_Discriminants
(Rec
);
2029 -- Freeze components and embedded subtypes
2031 Comp
:= First_Entity
(Rec
);
2033 while Present
(Comp
) loop
2035 -- Handle the component and discriminant case
2037 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
2039 CC
: constant Node_Id
:= Component_Clause
(Comp
);
2042 -- Freezing a record type freezes the type of each of its
2043 -- components. However, if the type of the component is
2044 -- part of this record, we do not want or need a separate
2045 -- Freeze_Node. Note that Is_Itype is wrong because that's
2046 -- also set in private type cases. We also can't check for
2047 -- the Scope being exactly Rec because of private types and
2048 -- record extensions.
2050 if Is_Itype
(Etype
(Comp
))
2051 and then Is_Record_Type
(Underlying_Type
2052 (Scope
(Etype
(Comp
))))
2054 Undelay_Type
(Etype
(Comp
));
2057 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
2059 -- Check for error of component clause given for variable
2060 -- sized type. We have to delay this test till this point,
2061 -- since the component type has to be frozen for us to know
2062 -- if it is variable length. We omit this test in a generic
2063 -- context, it will be applied at instantiation time.
2065 -- We also omit this test in CodePeer mode, since we do not
2066 -- have sufficient info on size and representation clauses.
2068 if Present
(CC
) then
2069 Placed_Component
:= True;
2071 if Inside_A_Generic
then
2074 elsif CodePeer_Mode
then
2078 Size_Known_At_Compile_Time
2079 (Underlying_Type
(Etype
(Comp
)))
2082 ("component clause not allowed for variable " &
2083 "length component", CC
);
2087 Unplaced_Component
:= True;
2090 -- Case of component requires byte alignment
2092 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
2094 -- Set the enclosing record to also require byte align
2096 Set_Must_Be_On_Byte_Boundary
(Rec
);
2098 -- Check for component clause that is inconsistent with
2099 -- the required byte boundary alignment.
2102 and then Normalized_First_Bit
(Comp
) mod
2103 System_Storage_Unit
/= 0
2106 ("component & must be byte aligned",
2107 Component_Name
(Component_Clause
(Comp
)));
2113 -- Gather data for possible Implicit_Packing later. Note that at
2114 -- this stage we might be dealing with a real component, or with
2115 -- an implicit subtype declaration.
2117 if not Is_Scalar_Type
(Etype
(Comp
)) then
2118 All_Scalar_Components
:= False;
2120 Scalar_Component_Total_RM_Size
:=
2121 Scalar_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
2122 Scalar_Component_Total_Esize
:=
2123 Scalar_Component_Total_Esize
+ Esize
(Etype
(Comp
));
2126 -- If the component is an Itype with Delayed_Freeze and is either
2127 -- a record or array subtype and its base type has not yet been
2128 -- frozen, we must remove this from the entity list of this record
2129 -- and put it on the entity list of the scope of its base type.
2130 -- Note that we know that this is not the type of a component
2131 -- since we cleared Has_Delayed_Freeze for it in the previous
2132 -- loop. Thus this must be the Designated_Type of an access type,
2133 -- which is the type of a component.
2136 and then Is_Type
(Scope
(Comp
))
2137 and then Is_Composite_Type
(Comp
)
2138 and then Base_Type
(Comp
) /= Comp
2139 and then Has_Delayed_Freeze
(Comp
)
2140 and then not Is_Frozen
(Base_Type
(Comp
))
2143 Will_Be_Frozen
: Boolean := False;
2147 -- We have a pretty bad kludge here. Suppose Rec is subtype
2148 -- being defined in a subprogram that's created as part of
2149 -- the freezing of Rec'Base. In that case, we know that
2150 -- Comp'Base must have already been frozen by the time we
2151 -- get to elaborate this because Gigi doesn't elaborate any
2152 -- bodies until it has elaborated all of the declarative
2153 -- part. But Is_Frozen will not be set at this point because
2154 -- we are processing code in lexical order.
2156 -- We detect this case by going up the Scope chain of Rec
2157 -- and seeing if we have a subprogram scope before reaching
2158 -- the top of the scope chain or that of Comp'Base. If we
2159 -- do, then mark that Comp'Base will actually be frozen. If
2160 -- so, we merely undelay it.
2163 while Present
(S
) loop
2164 if Is_Subprogram
(S
) then
2165 Will_Be_Frozen
:= True;
2167 elsif S
= Scope
(Base_Type
(Comp
)) then
2174 if Will_Be_Frozen
then
2175 Undelay_Type
(Comp
);
2177 if Present
(Prev
) then
2178 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
2180 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
2183 -- Insert in entity list of scope of base type (which
2184 -- must be an enclosing scope, because still unfrozen).
2186 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
2190 -- If the component is an access type with an allocator as default
2191 -- value, the designated type will be frozen by the corresponding
2192 -- expression in init_proc. In order to place the freeze node for
2193 -- the designated type before that for the current record type,
2196 -- Same process if the component is an array of access types,
2197 -- initialized with an aggregate. If the designated type is
2198 -- private, it cannot contain allocators, and it is premature
2199 -- to freeze the type, so we check for this as well.
2201 elsif Is_Access_Type
(Etype
(Comp
))
2202 and then Present
(Parent
(Comp
))
2203 and then Present
(Expression
(Parent
(Comp
)))
2206 Alloc
: constant Node_Id
:=
2207 Check_Allocator
(Expression
(Parent
(Comp
)));
2210 if Present
(Alloc
) then
2212 -- If component is pointer to a classwide type, freeze
2213 -- the specific type in the expression being allocated.
2214 -- The expression may be a subtype indication, in which
2215 -- case freeze the subtype mark.
2217 if Is_Class_Wide_Type
2218 (Designated_Type
(Etype
(Comp
)))
2220 if Is_Entity_Name
(Expression
(Alloc
)) then
2222 (Entity
(Expression
(Alloc
)), N
, Result
);
2224 Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
2227 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
2231 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
2232 Check_Itype
(Etype
(Comp
));
2236 (Designated_Type
(Etype
(Comp
)), N
, Result
);
2241 elsif Is_Access_Type
(Etype
(Comp
))
2242 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
2244 Check_Itype
(Etype
(Comp
));
2246 elsif Is_Array_Type
(Etype
(Comp
))
2247 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
2248 and then Present
(Parent
(Comp
))
2249 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
2250 and then Present
(Expression
(Parent
(Comp
)))
2251 and then Nkind
(Expression
(Parent
(Comp
))) = N_Aggregate
2252 and then Is_Fully_Defined
2253 (Designated_Type
(Component_Type
(Etype
(Comp
))))
2257 (Component_Type
(Etype
(Comp
))), N
, Result
);
2264 ADC
:= Get_Attribute_Definition_Clause
2265 (Rec
, Attribute_Scalar_Storage_Order
);
2267 if Present
(ADC
) then
2269 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
2270 -- the former is specified.
2272 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
2274 -- Note: report error on Rec, not on ADC, as ADC may apply to
2275 -- an ancestor type.
2277 Error_Msg_Sloc
:= Sloc
(ADC
);
2279 ("scalar storage order for& specified# inconsistent with "
2280 & "bit order", Rec
);
2283 -- Warn if there is a Scalar_Storage_Order but no component clause
2284 -- (or pragma Pack).
2286 if not (Placed_Component
or else Is_Packed
(Rec
)) then
2288 ("?scalar storage order specified but no component clause",
2292 -- Check attribute on component types
2294 Comp
:= First_Component
(Rec
);
2295 while Present
(Comp
) loop
2296 Check_Component_Storage_Order
(Rec
, Comp
);
2297 Next_Component
(Comp
);
2301 -- Deal with Bit_Order aspect specifying a non-default bit order
2303 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
2305 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
2306 if not (Placed_Component
or else Is_Packed
(Rec
)) then
2307 Error_Msg_N
("?bit order specification has no effect", ADC
);
2309 ("\?since no component clauses were specified", ADC
);
2311 -- Here is where we do the processing for reversed bit order
2313 elsif Reverse_Bit_Order
(Rec
)
2314 and then not Reverse_Storage_Order
(Rec
)
2316 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
2318 -- Case where we have both an explicit Bit_Order and the same
2319 -- Scalar_Storage_Order: leave record untouched, the back-end
2320 -- will take care of required layout conversions.
2328 -- Complete error checking on record representation clause (e.g.
2329 -- overlap of components). This is called after adjusting the
2330 -- record for reverse bit order.
2333 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
2335 if Present
(RRC
) then
2336 Check_Record_Representation_Clause
(RRC
);
2340 -- Set OK_To_Reorder_Components depending on debug flags
2342 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
2343 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
2345 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
2347 Set_OK_To_Reorder_Components
(Rec
);
2351 -- Check for useless pragma Pack when all components placed. We only
2352 -- do this check for record types, not subtypes, since a subtype may
2353 -- have all its components placed, and it still makes perfectly good
2354 -- sense to pack other subtypes or the parent type. We do not give
2355 -- this warning if Optimize_Alignment is set to Space, since the
2356 -- pragma Pack does have an effect in this case (it always resets
2357 -- the alignment to one).
2359 if Ekind
(Rec
) = E_Record_Type
2360 and then Is_Packed
(Rec
)
2361 and then not Unplaced_Component
2362 and then Optimize_Alignment
/= 'S'
2364 -- Reset packed status. Probably not necessary, but we do it so
2365 -- that there is no chance of the back end doing something strange
2366 -- with this redundant indication of packing.
2368 Set_Is_Packed
(Rec
, False);
2370 -- Give warning if redundant constructs warnings on
2372 if Warn_On_Redundant_Constructs
then
2373 Error_Msg_N
-- CODEFIX
2374 ("?pragma Pack has no effect, no unplaced components",
2375 Get_Rep_Pragma
(Rec
, Name_Pack
));
2379 -- If this is the record corresponding to a remote type, freeze the
2380 -- remote type here since that is what we are semantically freezing.
2381 -- This prevents the freeze node for that type in an inner scope.
2383 -- Also, Check for controlled components and unchecked unions.
2384 -- Finally, enforce the restriction that access attributes with a
2385 -- current instance prefix can only apply to limited types.
2387 if Ekind
(Rec
) = E_Record_Type
then
2388 if Present
(Corresponding_Remote_Type
(Rec
)) then
2389 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
2392 Comp
:= First_Component
(Rec
);
2393 while Present
(Comp
) loop
2395 -- Do not set Has_Controlled_Component on a class-wide
2396 -- equivalent type. See Make_CW_Equivalent_Type.
2398 if not Is_Class_Wide_Equivalent_Type
(Rec
)
2399 and then (Has_Controlled_Component
(Etype
(Comp
))
2400 or else (Chars
(Comp
) /= Name_uParent
2401 and then Is_Controlled
(Etype
(Comp
)))
2402 or else (Is_Protected_Type
(Etype
(Comp
))
2404 (Corresponding_Record_Type
2406 and then Has_Controlled_Component
2407 (Corresponding_Record_Type
2410 Set_Has_Controlled_Component
(Rec
);
2413 if Has_Unchecked_Union
(Etype
(Comp
)) then
2414 Set_Has_Unchecked_Union
(Rec
);
2417 -- Scan component declaration for likely misuses of current
2418 -- instance, either in a constraint or a default expression.
2420 if Has_Per_Object_Constraint
(Comp
) then
2421 Check_Current_Instance
(Parent
(Comp
));
2424 Next_Component
(Comp
);
2428 Set_Component_Alignment_If_Not_Set
(Rec
);
2430 -- For first subtypes, check if there are any fixed-point fields with
2431 -- component clauses, where we must check the size. This is not done
2432 -- till the freeze point, since for fixed-point types, we do not know
2433 -- the size until the type is frozen. Similar processing applies to
2434 -- bit packed arrays.
2436 if Is_First_Subtype
(Rec
) then
2437 Comp
:= First_Component
(Rec
);
2438 while Present
(Comp
) loop
2439 if Present
(Component_Clause
(Comp
))
2440 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
2442 Is_Bit_Packed_Array
(Etype
(Comp
)))
2445 (Component_Name
(Component_Clause
(Comp
)),
2451 Next_Component
(Comp
);
2455 -- Generate warning for applying C or C++ convention to a record
2456 -- with discriminants. This is suppressed for the unchecked union
2457 -- case, since the whole point in this case is interface C. We also
2458 -- do not generate this within instantiations, since we will have
2459 -- generated a message on the template.
2461 if Has_Discriminants
(E
)
2462 and then not Is_Unchecked_Union
(E
)
2463 and then (Convention
(E
) = Convention_C
2465 Convention
(E
) = Convention_CPP
)
2466 and then Comes_From_Source
(E
)
2467 and then not In_Instance
2468 and then not Has_Warnings_Off
(E
)
2469 and then not Has_Warnings_Off
(Base_Type
(E
))
2472 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
2476 if Present
(Cprag
) then
2477 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
2479 if Convention
(E
) = Convention_C
then
2481 ("?variant record has no direct equivalent in C", A2
);
2484 ("?variant record has no direct equivalent in C++", A2
);
2488 ("\?use of convention for type& is dubious", A2
, E
);
2493 -- See if Size is too small as is (and implicit packing might help)
2495 if not Is_Packed
(Rec
)
2497 -- No implicit packing if even one component is explicitly placed
2499 and then not Placed_Component
2501 -- Must have size clause and all scalar components
2503 and then Has_Size_Clause
(Rec
)
2504 and then All_Scalar_Components
2506 -- Do not try implicit packing on records with discriminants, too
2507 -- complicated, especially in the variant record case.
2509 and then not Has_Discriminants
(Rec
)
2511 -- We can implicitly pack if the specified size of the record is
2512 -- less than the sum of the object sizes (no point in packing if
2513 -- this is not the case).
2515 and then RM_Size
(Rec
) < Scalar_Component_Total_Esize
2517 -- And the total RM size cannot be greater than the specified size
2518 -- since otherwise packing will not get us where we have to be!
2520 and then RM_Size
(Rec
) >= Scalar_Component_Total_RM_Size
2522 -- Never do implicit packing in CodePeer or Alfa modes since
2523 -- we don't do any packing in these modes, since this generates
2524 -- over-complex code that confuses static analysis, and in
2525 -- general, neither CodePeer not GNATprove care about the
2526 -- internal representation of objects.
2528 and then not (CodePeer_Mode
or Alfa_Mode
)
2530 -- If implicit packing enabled, do it
2532 if Implicit_Packing
then
2533 Set_Is_Packed
(Rec
);
2535 -- Otherwise flag the size clause
2539 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
2541 Error_Msg_NE
-- CODEFIX
2542 ("size given for& too small", Sz
, Rec
);
2543 Error_Msg_N
-- CODEFIX
2544 ("\use explicit pragma Pack "
2545 & "or use pragma Implicit_Packing", Sz
);
2549 end Freeze_Record_Type
;
2551 -- Start of processing for Freeze_Entity
2554 -- We are going to test for various reasons why this entity need not be
2555 -- frozen here, but in the case of an Itype that's defined within a
2556 -- record, that test actually applies to the record.
2558 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
2559 Test_E
:= Scope
(E
);
2560 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
2561 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
2563 Test_E
:= Underlying_Type
(Scope
(E
));
2566 -- Do not freeze if already frozen since we only need one freeze node
2568 if Is_Frozen
(E
) then
2571 -- It is improper to freeze an external entity within a generic because
2572 -- its freeze node will appear in a non-valid context. The entity will
2573 -- be frozen in the proper scope after the current generic is analyzed.
2574 -- However, aspects must be analyzed because they may be queried later
2575 -- within the generic itself, and the corresponding pragma or attribute
2576 -- definition has not been analyzed yet.
2578 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
2579 if Has_Delayed_Aspects
(E
) then
2580 Analyze_Aspects_At_Freeze_Point
(E
);
2585 -- AI05-0213: A formal incomplete type does not freeze the actual. In
2586 -- the instance, the same applies to the subtype renaming the actual.
2588 elsif Is_Private_Type
(E
)
2589 and then Is_Generic_Actual_Type
(E
)
2590 and then No
(Full_View
(Base_Type
(E
)))
2591 and then Ada_Version
>= Ada_2012
2595 -- Do not freeze a global entity within an inner scope created during
2596 -- expansion. A call to subprogram E within some internal procedure
2597 -- (a stream attribute for example) might require freezing E, but the
2598 -- freeze node must appear in the same declarative part as E itself.
2599 -- The two-pass elaboration mechanism in gigi guarantees that E will
2600 -- be frozen before the inner call is elaborated. We exclude constants
2601 -- from this test, because deferred constants may be frozen early, and
2602 -- must be diagnosed (e.g. in the case of a deferred constant being used
2603 -- in a default expression). If the enclosing subprogram comes from
2604 -- source, or is a generic instance, then the freeze point is the one
2605 -- mandated by the language, and we freeze the entity. A subprogram that
2606 -- is a child unit body that acts as a spec does not have a spec that
2607 -- comes from source, but can only come from source.
2609 elsif In_Open_Scopes
(Scope
(Test_E
))
2610 and then Scope
(Test_E
) /= Current_Scope
2611 and then Ekind
(Test_E
) /= E_Constant
2618 while Present
(S
) loop
2619 if Is_Overloadable
(S
) then
2620 if Comes_From_Source
(S
)
2621 or else Is_Generic_Instance
(S
)
2622 or else Is_Child_Unit
(S
)
2634 -- Similarly, an inlined instance body may make reference to global
2635 -- entities, but these references cannot be the proper freezing point
2636 -- for them, and in the absence of inlining freezing will take place in
2637 -- their own scope. Normally instance bodies are analyzed after the
2638 -- enclosing compilation, and everything has been frozen at the proper
2639 -- place, but with front-end inlining an instance body is compiled
2640 -- before the end of the enclosing scope, and as a result out-of-order
2641 -- freezing must be prevented.
2643 elsif Front_End_Inlining
2644 and then In_Instance_Body
2645 and then Present
(Scope
(Test_E
))
2651 S
:= Scope
(Test_E
);
2652 while Present
(S
) loop
2653 if Is_Generic_Instance
(S
) then
2666 -- Add checks to detect proper initialization of scalars that may appear
2667 -- as subprogram parameters.
2669 if Is_Subprogram
(E
)
2670 and then Check_Validity_Of_Parameters
2672 Apply_Parameter_Validity_Checks
(E
);
2675 -- Deal with delayed aspect specifications. The analysis of the aspect
2676 -- is required to be delayed to the freeze point, thus we analyze the
2677 -- pragma or attribute definition clause in the tree at this point. We
2678 -- also analyze the aspect specification node at the freeze point when
2679 -- the aspect doesn't correspond to pragma/attribute definition clause.
2681 if Has_Delayed_Aspects
(E
) then
2682 Analyze_Aspects_At_Freeze_Point
(E
);
2685 -- Here to freeze the entity
2689 -- Case of entity being frozen is other than a type
2691 if not Is_Type
(E
) then
2692 -- If entity is exported or imported and does not have an external
2693 -- name, now is the time to provide the appropriate default name.
2694 -- Skip this if the entity is stubbed, since we don't need a name
2695 -- for any stubbed routine. For the case on intrinsics, if no
2696 -- external name is specified, then calls will be handled in
2697 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
2698 -- external name is provided, then Expand_Intrinsic_Call leaves
2699 -- calls in place for expansion by GIGI.
2701 if (Is_Imported
(E
) or else Is_Exported
(E
))
2702 and then No
(Interface_Name
(E
))
2703 and then Convention
(E
) /= Convention_Stubbed
2704 and then Convention
(E
) /= Convention_Intrinsic
2706 Set_Encoded_Interface_Name
2707 (E
, Get_Default_External_Name
(E
));
2709 -- If entity is an atomic object appearing in a declaration and
2710 -- the expression is an aggregate, assign it to a temporary to
2711 -- ensure that the actual assignment is done atomically rather
2712 -- than component-wise (the assignment to the temp may be done
2713 -- component-wise, but that is harmless).
2716 and then Nkind
(Parent
(E
)) = N_Object_Declaration
2717 and then Present
(Expression
(Parent
(E
)))
2718 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
2719 and then Is_Atomic_Aggregate
(Expression
(Parent
(E
)), Etype
(E
))
2724 -- For a subprogram, freeze all parameter types and also the return
2725 -- type (RM 13.14(14)). However skip this for internal subprograms.
2726 -- This is also the point where any extra formal parameters are
2727 -- created since we now know whether the subprogram will use a
2728 -- foreign convention.
2730 if Is_Subprogram
(E
) then
2731 if not Is_Internal
(E
) then
2735 Warn_Node
: Node_Id
;
2738 -- Loop through formals
2740 Formal
:= First_Formal
(E
);
2741 while Present
(Formal
) loop
2742 F_Type
:= Etype
(Formal
);
2744 -- AI05-0151 : incomplete types can appear in a profile.
2745 -- By the time the entity is frozen, the full view must
2746 -- be available, unless it is a limited view.
2748 if Is_Incomplete_Type
(F_Type
)
2749 and then Present
(Full_View
(F_Type
))
2751 F_Type
:= Full_View
(F_Type
);
2752 Set_Etype
(Formal
, F_Type
);
2755 Freeze_And_Append
(F_Type
, N
, Result
);
2757 if Is_Private_Type
(F_Type
)
2758 and then Is_Private_Type
(Base_Type
(F_Type
))
2759 and then No
(Full_View
(Base_Type
(F_Type
)))
2760 and then not Is_Generic_Type
(F_Type
)
2761 and then not Is_Derived_Type
(F_Type
)
2763 -- If the type of a formal is incomplete, subprogram
2764 -- is being frozen prematurely. Within an instance
2765 -- (but not within a wrapper package) this is an
2766 -- artifact of our need to regard the end of an
2767 -- instantiation as a freeze point. Otherwise it is
2768 -- a definite error.
2771 Set_Is_Frozen
(E
, False);
2774 elsif not After_Last_Declaration
2775 and then not Freezing_Library_Level_Tagged_Type
2777 Error_Msg_Node_1
:= F_Type
;
2779 ("type& must be fully defined before this point",
2784 -- Check suspicious parameter for C function. These tests
2785 -- apply only to exported/imported subprograms.
2787 if Warn_On_Export_Import
2788 and then Comes_From_Source
(E
)
2789 and then (Convention
(E
) = Convention_C
2791 Convention
(E
) = Convention_CPP
)
2792 and then (Is_Imported
(E
) or else Is_Exported
(E
))
2793 and then Convention
(E
) /= Convention
(Formal
)
2794 and then not Has_Warnings_Off
(E
)
2795 and then not Has_Warnings_Off
(F_Type
)
2796 and then not Has_Warnings_Off
(Formal
)
2798 -- Qualify mention of formals with subprogram name
2800 Error_Msg_Qual_Level
:= 1;
2802 -- Check suspicious use of fat C pointer
2804 if Is_Access_Type
(F_Type
)
2805 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
2808 ("?type of & does not correspond to C pointer!",
2811 -- Check suspicious return of boolean
2813 elsif Root_Type
(F_Type
) = Standard_Boolean
2814 and then Convention
(F_Type
) = Convention_Ada
2815 and then not Has_Warnings_Off
(F_Type
)
2816 and then not Has_Size_Clause
(F_Type
)
2817 and then VM_Target
= No_VM
2819 Error_Msg_N
("& is an 8-bit Ada Boolean?", Formal
);
2821 ("\use appropriate corresponding type in C "
2822 & "(e.g. char)?", Formal
);
2824 -- Check suspicious tagged type
2826 elsif (Is_Tagged_Type
(F_Type
)
2827 or else (Is_Access_Type
(F_Type
)
2830 (Designated_Type
(F_Type
))))
2831 and then Convention
(E
) = Convention_C
2834 ("?& involves a tagged type which does not "
2835 & "correspond to any C type!", Formal
);
2837 -- Check wrong convention subprogram pointer
2839 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
2840 and then not Has_Foreign_Convention
(F_Type
)
2843 ("?subprogram pointer & should "
2844 & "have foreign convention!", Formal
);
2845 Error_Msg_Sloc
:= Sloc
(F_Type
);
2847 ("\?add Convention pragma to declaration of &#",
2851 -- Turn off name qualification after message output
2853 Error_Msg_Qual_Level
:= 0;
2856 -- Check for unconstrained array in exported foreign
2859 if Has_Foreign_Convention
(E
)
2860 and then not Is_Imported
(E
)
2861 and then Is_Array_Type
(F_Type
)
2862 and then not Is_Constrained
(F_Type
)
2863 and then Warn_On_Export_Import
2865 -- Exclude VM case, since both .NET and JVM can handle
2866 -- unconstrained arrays without a problem.
2868 and then VM_Target
= No_VM
2870 Error_Msg_Qual_Level
:= 1;
2872 -- If this is an inherited operation, place the
2873 -- warning on the derived type declaration, rather
2874 -- than on the original subprogram.
2876 if Nkind
(Original_Node
(Parent
(E
))) =
2877 N_Full_Type_Declaration
2879 Warn_Node
:= Parent
(E
);
2881 if Formal
= First_Formal
(E
) then
2883 ("?in inherited operation&", Warn_Node
, E
);
2886 Warn_Node
:= Formal
;
2890 ("?type of argument& is unconstrained array",
2893 ("?foreign caller must pass bounds explicitly",
2895 Error_Msg_Qual_Level
:= 0;
2898 if not From_With_Type
(F_Type
) then
2899 if Is_Access_Type
(F_Type
) then
2900 F_Type
:= Designated_Type
(F_Type
);
2903 -- If the formal is an anonymous_access_to_subprogram
2904 -- freeze the subprogram type as well, to prevent
2905 -- scope anomalies in gigi, because there is no other
2906 -- clear point at which it could be frozen.
2908 if Is_Itype
(Etype
(Formal
))
2909 and then Ekind
(F_Type
) = E_Subprogram_Type
2911 Freeze_And_Append
(F_Type
, N
, Result
);
2915 Next_Formal
(Formal
);
2918 -- Case of function: similar checks on return type
2920 if Ekind
(E
) = E_Function
then
2922 -- Freeze return type
2924 R_Type
:= Etype
(E
);
2926 -- AI05-0151: the return type may have been incomplete
2927 -- at the point of declaration.
2929 if Ekind
(R_Type
) = E_Incomplete_Type
2930 and then Present
(Full_View
(R_Type
))
2932 R_Type
:= Full_View
(R_Type
);
2933 Set_Etype
(E
, R_Type
);
2936 Freeze_And_Append
(R_Type
, N
, Result
);
2938 -- Check suspicious return type for C function
2940 if Warn_On_Export_Import
2941 and then (Convention
(E
) = Convention_C
2943 Convention
(E
) = Convention_CPP
)
2944 and then (Is_Imported
(E
) or else Is_Exported
(E
))
2946 -- Check suspicious return of fat C pointer
2948 if Is_Access_Type
(R_Type
)
2949 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
2950 and then not Has_Warnings_Off
(E
)
2951 and then not Has_Warnings_Off
(R_Type
)
2954 ("?return type of& does not "
2955 & "correspond to C pointer!", E
);
2957 -- Check suspicious return of boolean
2959 elsif Root_Type
(R_Type
) = Standard_Boolean
2960 and then Convention
(R_Type
) = Convention_Ada
2961 and then VM_Target
= No_VM
2962 and then not Has_Warnings_Off
(E
)
2963 and then not Has_Warnings_Off
(R_Type
)
2964 and then not Has_Size_Clause
(R_Type
)
2967 N
: constant Node_Id
:=
2968 Result_Definition
(Declaration_Node
(E
));
2971 ("return type of & is an 8-bit Ada Boolean?",
2974 ("\use appropriate corresponding type in C "
2975 & "(e.g. char)?", N
, E
);
2978 -- Check suspicious return tagged type
2980 elsif (Is_Tagged_Type
(R_Type
)
2981 or else (Is_Access_Type
(R_Type
)
2984 (Designated_Type
(R_Type
))))
2985 and then Convention
(E
) = Convention_C
2986 and then not Has_Warnings_Off
(E
)
2987 and then not Has_Warnings_Off
(R_Type
)
2990 ("?return type of & does not "
2991 & "correspond to C type!", E
);
2993 -- Check return of wrong convention subprogram pointer
2995 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
2996 and then not Has_Foreign_Convention
(R_Type
)
2997 and then not Has_Warnings_Off
(E
)
2998 and then not Has_Warnings_Off
(R_Type
)
3001 ("?& should return a foreign "
3002 & "convention subprogram pointer", E
);
3003 Error_Msg_Sloc
:= Sloc
(R_Type
);
3005 ("\?add Convention pragma to declaration of& #",
3010 -- Give warning for suspicious return of a result of an
3011 -- unconstrained array type in a foreign convention
3014 if Has_Foreign_Convention
(E
)
3016 -- We are looking for a return of unconstrained array
3018 and then Is_Array_Type
(R_Type
)
3019 and then not Is_Constrained
(R_Type
)
3021 -- Exclude imported routines, the warning does not
3022 -- belong on the import, but rather on the routine
3025 and then not Is_Imported
(E
)
3027 -- Exclude VM case, since both .NET and JVM can handle
3028 -- return of unconstrained arrays without a problem.
3030 and then VM_Target
= No_VM
3032 -- Check that general warning is enabled, and that it
3033 -- is not suppressed for this particular case.
3035 and then Warn_On_Export_Import
3036 and then not Has_Warnings_Off
(E
)
3037 and then not Has_Warnings_Off
(R_Type
)
3040 ("?foreign convention function& should not " &
3041 "return unconstrained array!", E
);
3046 -- Pre/post conditions are implemented through a subprogram in
3047 -- the corresponding body, and therefore are not checked on an
3048 -- imported subprogram for which the body is not available.
3050 -- Could consider generating a wrapper to take care of this???
3052 if Is_Subprogram
(E
)
3053 and then Is_Imported
(E
)
3054 and then Present
(Contract
(E
))
3055 and then Present
(Spec_PPC_List
(Contract
(E
)))
3057 Error_Msg_NE
("pre/post conditions on imported subprogram "
3058 & "are not enforced?",
3059 E
, Spec_PPC_List
(Contract
(E
)));
3064 -- Must freeze its parent first if it is a derived subprogram
3066 if Present
(Alias
(E
)) then
3067 Freeze_And_Append
(Alias
(E
), N
, Result
);
3070 -- We don't freeze internal subprograms, because we don't normally
3071 -- want addition of extra formals or mechanism setting to happen
3072 -- for those. However we do pass through predefined dispatching
3073 -- cases, since extra formals may be needed in some cases, such as
3074 -- for the stream 'Input function (build-in-place formals).
3076 if not Is_Internal
(E
)
3077 or else Is_Predefined_Dispatching_Operation
(E
)
3079 Freeze_Subprogram
(E
);
3082 -- Here for other than a subprogram or type
3085 -- If entity has a type, and it is not a generic unit, then
3086 -- freeze it first (RM 13.14(10)).
3088 if Present
(Etype
(E
))
3089 and then Ekind
(E
) /= E_Generic_Function
3091 Freeze_And_Append
(Etype
(E
), N
, Result
);
3094 -- Special processing for objects created by object declaration
3096 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
3098 -- Abstract type allowed only for C++ imported variables or
3101 -- Note: we inhibit this check for objects that do not come
3102 -- from source because there is at least one case (the
3103 -- expansion of x'Class'Input where x is abstract) where we
3104 -- legitimately generate an abstract object.
3106 if Is_Abstract_Type
(Etype
(E
))
3107 and then Comes_From_Source
(Parent
(E
))
3108 and then not (Is_Imported
(E
)
3109 and then Is_CPP_Class
(Etype
(E
)))
3111 Error_Msg_N
("type of object cannot be abstract",
3112 Object_Definition
(Parent
(E
)));
3114 if Is_CPP_Class
(Etype
(E
)) then
3116 ("\} may need a cpp_constructor",
3117 Object_Definition
(Parent
(E
)), Etype
(E
));
3121 -- For object created by object declaration, perform required
3122 -- categorization (preelaborate and pure) checks. Defer these
3123 -- checks to freeze time since pragma Import inhibits default
3124 -- initialization and thus pragma Import affects these checks.
3126 Validate_Object_Declaration
(Declaration_Node
(E
));
3128 -- If there is an address clause, check that it is valid
3130 Check_Address_Clause
(E
);
3132 -- If the object needs any kind of default initialization, an
3133 -- error must be issued if No_Default_Initialization applies.
3134 -- The check doesn't apply to imported objects, which are not
3135 -- ever default initialized, and is why the check is deferred
3136 -- until freezing, at which point we know if Import applies.
3137 -- Deferred constants are also exempted from this test because
3138 -- their completion is explicit, or through an import pragma.
3140 if Ekind
(E
) = E_Constant
3141 and then Present
(Full_View
(E
))
3145 elsif Comes_From_Source
(E
)
3146 and then not Is_Imported
(E
)
3147 and then not Has_Init_Expression
(Declaration_Node
(E
))
3149 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
3150 and then not No_Initialization
(Declaration_Node
(E
))
3151 and then not Is_Value_Type
(Etype
(E
))
3152 and then not Initialization_Suppressed
(Etype
(E
)))
3154 (Needs_Simple_Initialization
(Etype
(E
))
3155 and then not Is_Internal
(E
)))
3157 Has_Default_Initialization
:= True;
3159 (No_Default_Initialization
, Declaration_Node
(E
));
3162 -- Check that a Thread_Local_Storage variable does not have
3163 -- default initialization, and any explicit initialization must
3164 -- either be the null constant or a static constant.
3166 if Has_Pragma_Thread_Local_Storage
(E
) then
3168 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3170 if Has_Default_Initialization
3172 (Has_Init_Expression
(Decl
)
3174 (No
(Expression
(Decl
))
3176 (Is_Static_Expression
(Expression
(Decl
))
3178 Nkind
(Expression
(Decl
)) = N_Null
)))
3181 ("Thread_Local_Storage variable& is "
3182 & "improperly initialized", Decl
, E
);
3184 ("\only allowed initialization is explicit "
3185 & "NULL or static expression", Decl
, E
);
3190 -- For imported objects, set Is_Public unless there is also an
3191 -- address clause, which means that there is no external symbol
3192 -- needed for the Import (Is_Public may still be set for other
3193 -- unrelated reasons). Note that we delayed this processing
3194 -- till freeze time so that we can be sure not to set the flag
3195 -- if there is an address clause. If there is such a clause,
3196 -- then the only purpose of the Import pragma is to suppress
3197 -- implicit initialization.
3200 and then No
(Address_Clause
(E
))
3205 -- For convention C objects of an enumeration type, warn if
3206 -- the size is not integer size and no explicit size given.
3207 -- Skip warning for Boolean, and Character, assume programmer
3208 -- expects 8-bit sizes for these cases.
3210 if (Convention
(E
) = Convention_C
3212 Convention
(E
) = Convention_CPP
)
3213 and then Is_Enumeration_Type
(Etype
(E
))
3214 and then not Is_Character_Type
(Etype
(E
))
3215 and then not Is_Boolean_Type
(Etype
(E
))
3216 and then Esize
(Etype
(E
)) < Standard_Integer_Size
3217 and then not Has_Size_Clause
(E
)
3219 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
3221 ("?convention C enumeration object has size less than ^",
3223 Error_Msg_N
("\?use explicit size clause to set size", E
);
3227 -- Check that a constant which has a pragma Volatile[_Components]
3228 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
3230 -- Note: Atomic[_Components] also sets Volatile[_Components]
3232 if Ekind
(E
) = E_Constant
3233 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
3234 and then not Is_Imported
(E
)
3236 -- Make sure we actually have a pragma, and have not merely
3237 -- inherited the indication from elsewhere (e.g. an address
3238 -- clause, which is not good enough in RM terms!)
3240 if Has_Rep_Pragma
(E
, Name_Atomic
)
3242 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
3245 ("stand alone atomic constant must be " &
3246 "imported (RM C.6(13))", E
);
3248 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
3250 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
3253 ("stand alone volatile constant must be " &
3254 "imported (RM C.6(13))", E
);
3258 -- Static objects require special handling
3260 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
3261 and then Is_Statically_Allocated
(E
)
3263 Freeze_Static_Object
(E
);
3266 -- Remaining step is to layout objects
3268 if Ekind
(E
) = E_Variable
3270 Ekind
(E
) = E_Constant
3272 Ekind
(E
) = E_Loop_Parameter
3280 -- Case of a type or subtype being frozen
3283 -- We used to check here that a full type must have preelaborable
3284 -- initialization if it completes a private type specified with
3285 -- pragma Preelaborable_Initialization, but that missed cases where
3286 -- the types occur within a generic package, since the freezing
3287 -- that occurs within a containing scope generally skips traversal
3288 -- of a generic unit's declarations (those will be frozen within
3289 -- instances). This check was moved to Analyze_Package_Specification.
3291 -- The type may be defined in a generic unit. This can occur when
3292 -- freezing a generic function that returns the type (which is
3293 -- defined in a parent unit). It is clearly meaningless to freeze
3294 -- this type. However, if it is a subtype, its size may be determi-
3295 -- nable and used in subsequent checks, so might as well try to
3298 -- In Ada 2012, Freeze_Entities is also used in the front end to
3299 -- trigger the analysis of aspect expressions, so in this case we
3300 -- want to continue the freezing process.
3302 if Present
(Scope
(E
))
3303 and then Is_Generic_Unit
(Scope
(E
))
3304 and then not Has_Predicates
(E
)
3306 Check_Compile_Time_Size
(E
);
3310 -- Deal with special cases of freezing for subtype
3312 if E
/= Base_Type
(E
) then
3314 -- Before we do anything else, a specialized test for the case of
3315 -- a size given for an array where the array needs to be packed,
3316 -- but was not so the size cannot be honored. This would of course
3317 -- be caught by the backend, and indeed we don't catch all cases.
3318 -- The point is that we can give a better error message in those
3319 -- cases that we do catch with the circuitry here. Also if pragma
3320 -- Implicit_Packing is set, this is where the packing occurs.
3322 -- The reason we do this so early is that the processing in the
3323 -- automatic packing case affects the layout of the base type, so
3324 -- it must be done before we freeze the base type.
3326 if Is_Array_Type
(E
) then
3329 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
3332 -- Check enabling conditions. These are straightforward
3333 -- except for the test for a limited composite type. This
3334 -- eliminates the rare case of a array of limited components
3335 -- where there are issues of whether or not we can go ahead
3336 -- and pack the array (since we can't freely pack and unpack
3337 -- arrays if they are limited).
3339 -- Note that we check the root type explicitly because the
3340 -- whole point is we are doing this test before we have had
3341 -- a chance to freeze the base type (and it is that freeze
3342 -- action that causes stuff to be inherited).
3344 if Present
(Size_Clause
(E
))
3345 and then Known_Static_RM_Size
(E
)
3346 and then not Is_Packed
(E
)
3347 and then not Has_Pragma_Pack
(E
)
3348 and then Number_Dimensions
(E
) = 1
3349 and then not Has_Component_Size_Clause
(E
)
3350 and then Known_Static_RM_Size
(Ctyp
)
3351 and then not Is_Limited_Composite
(E
)
3352 and then not Is_Packed
(Root_Type
(E
))
3353 and then not Has_Component_Size_Clause
(Root_Type
(E
))
3354 and then not (CodePeer_Mode
or Alfa_Mode
)
3356 Get_Index_Bounds
(First_Index
(E
), Lo
, Hi
);
3358 if Compile_Time_Known_Value
(Lo
)
3359 and then Compile_Time_Known_Value
(Hi
)
3360 and then Known_Static_RM_Size
(Ctyp
)
3361 and then RM_Size
(Ctyp
) < 64
3364 Lov
: constant Uint
:= Expr_Value
(Lo
);
3365 Hiv
: constant Uint
:= Expr_Value
(Hi
);
3366 Len
: constant Uint
:= UI_Max
3369 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
3370 SZ
: constant Node_Id
:= Size_Clause
(E
);
3371 Btyp
: constant Entity_Id
:= Base_Type
(E
);
3373 -- What we are looking for here is the situation where
3374 -- the RM_Size given would be exactly right if there
3375 -- was a pragma Pack (resulting in the component size
3376 -- being the same as the RM_Size). Furthermore, the
3377 -- component type size must be an odd size (not a
3378 -- multiple of storage unit). If the component RM size
3379 -- is an exact number of storage units that is a power
3380 -- of two, the array is not packed and has a standard
3384 if RM_Size
(E
) = Len
* Rsiz
3385 and then Rsiz
mod System_Storage_Unit
/= 0
3387 -- For implicit packing mode, just set the
3388 -- component size silently.
3390 if Implicit_Packing
then
3391 Set_Component_Size
(Btyp
, Rsiz
);
3392 Set_Is_Bit_Packed_Array
(Btyp
);
3393 Set_Is_Packed
(Btyp
);
3394 Set_Has_Non_Standard_Rep
(Btyp
);
3396 -- Otherwise give an error message
3400 ("size given for& too small", SZ
, E
);
3401 Error_Msg_N
-- CODEFIX
3402 ("\use explicit pragma Pack "
3403 & "or use pragma Implicit_Packing", SZ
);
3406 elsif RM_Size
(E
) = Len
* Rsiz
3407 and then Implicit_Packing
3409 (Rsiz
/ System_Storage_Unit
= 1
3410 or else Rsiz
/ System_Storage_Unit
= 2
3411 or else Rsiz
/ System_Storage_Unit
= 4)
3414 -- Not a packed array, but indicate the desired
3415 -- component size, for the back-end.
3417 Set_Component_Size
(Btyp
, Rsiz
);
3425 -- If ancestor subtype present, freeze that first. Note that this
3426 -- will also get the base type frozen. Need RM reference ???
3428 Atype
:= Ancestor_Subtype
(E
);
3430 if Present
(Atype
) then
3431 Freeze_And_Append
(Atype
, N
, Result
);
3433 -- No ancestor subtype present
3436 -- See if we have a nearest ancestor that has a predicate.
3437 -- That catches the case of derived type with a predicate.
3438 -- Need RM reference here ???
3440 Atype
:= Nearest_Ancestor
(E
);
3442 if Present
(Atype
) and then Has_Predicates
(Atype
) then
3443 Freeze_And_Append
(Atype
, N
, Result
);
3446 -- Freeze base type before freezing the entity (RM 13.14(15))
3448 if E
/= Base_Type
(E
) then
3449 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
3453 -- A subtype inherits all the type-related representation aspects
3454 -- from its parents (RM 13.1(8)).
3456 Inherit_Aspects_At_Freeze_Point
(E
);
3458 -- For a derived type, freeze its parent type first (RM 13.14(15))
3460 elsif Is_Derived_Type
(E
) then
3461 Freeze_And_Append
(Etype
(E
), N
, Result
);
3462 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
3464 -- A derived type inherits each type-related representation aspect
3465 -- of its parent type that was directly specified before the
3466 -- declaration of the derived type (RM 13.1(15)).
3468 Inherit_Aspects_At_Freeze_Point
(E
);
3471 -- For array type, freeze index types and component type first
3472 -- before freezing the array (RM 13.14(15)).
3474 if Is_Array_Type
(E
) then
3476 FS
: constant Entity_Id
:= First_Subtype
(E
);
3477 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
3480 Non_Standard_Enum
: Boolean := False;
3481 -- Set true if any of the index types is an enumeration type
3482 -- with a non-standard representation.
3485 Freeze_And_Append
(Ctyp
, N
, Result
);
3487 Indx
:= First_Index
(E
);
3488 while Present
(Indx
) loop
3489 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
3491 if Is_Enumeration_Type
(Etype
(Indx
))
3492 and then Has_Non_Standard_Rep
(Etype
(Indx
))
3494 Non_Standard_Enum
:= True;
3500 -- Processing that is done only for base types
3502 if Ekind
(E
) = E_Array_Type
then
3504 -- Propagate flags for component type
3506 if Is_Controlled
(Component_Type
(E
))
3507 or else Has_Controlled_Component
(Ctyp
)
3509 Set_Has_Controlled_Component
(E
);
3512 if Has_Unchecked_Union
(Component_Type
(E
)) then
3513 Set_Has_Unchecked_Union
(E
);
3516 -- If packing was requested or if the component size was set
3517 -- explicitly, then see if bit packing is required. This
3518 -- processing is only done for base types, since all the
3519 -- representation aspects involved are type-related. This
3520 -- is not just an optimization, if we start processing the
3521 -- subtypes, they interfere with the settings on the base
3522 -- type (this is because Is_Packed has a slightly different
3523 -- meaning before and after freezing).
3530 if (Is_Packed
(E
) or else Has_Pragma_Pack
(E
))
3531 and then Known_Static_RM_Size
(Ctyp
)
3532 and then not Has_Component_Size_Clause
(E
)
3534 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
3536 elsif Known_Component_Size
(E
) then
3537 Csiz
:= Component_Size
(E
);
3539 elsif not Known_Static_Esize
(Ctyp
) then
3543 Esiz
:= Esize
(Ctyp
);
3545 -- We can set the component size if it is less than
3546 -- 16, rounding it up to the next storage unit size.
3550 elsif Esiz
<= 16 then
3556 -- Set component size up to match alignment if it
3557 -- would otherwise be less than the alignment. This
3558 -- deals with cases of types whose alignment exceeds
3559 -- their size (padded types).
3563 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
3572 -- Case of component size that may result in packing
3574 if 1 <= Csiz
and then Csiz
<= 64 then
3576 Ent
: constant Entity_Id
:=
3578 Pack_Pragma
: constant Node_Id
:=
3579 Get_Rep_Pragma
(Ent
, Name_Pack
);
3580 Comp_Size_C
: constant Node_Id
:=
3581 Get_Attribute_Definition_Clause
3582 (Ent
, Attribute_Component_Size
);
3584 -- Warn if we have pack and component size so that
3585 -- the pack is ignored.
3587 -- Note: here we must check for the presence of a
3588 -- component size before checking for a Pack pragma
3589 -- to deal with the case where the array type is a
3590 -- derived type whose parent is currently private.
3592 if Present
(Comp_Size_C
)
3593 and then Has_Pragma_Pack
(Ent
)
3594 and then Warn_On_Redundant_Constructs
3596 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
3598 ("?pragma Pack for& ignored!",
3601 ("\?explicit component size given#!",
3603 Set_Is_Packed
(Base_Type
(Ent
), False);
3604 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
3607 -- Set component size if not already set by a
3608 -- component size clause.
3610 if not Present
(Comp_Size_C
) then
3611 Set_Component_Size
(E
, Csiz
);
3614 -- Check for base type of 8, 16, 32 bits, where an
3615 -- unsigned subtype has a length one less than the
3616 -- base type (e.g. Natural subtype of Integer).
3618 -- In such cases, if a component size was not set
3619 -- explicitly, then generate a warning.
3621 if Has_Pragma_Pack
(E
)
3622 and then not Present
(Comp_Size_C
)
3624 (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
3625 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
3627 Error_Msg_Uint_1
:= Csiz
;
3629 if Present
(Pack_Pragma
) then
3631 ("?pragma Pack causes component size "
3632 & "to be ^!", Pack_Pragma
);
3634 ("\?use Component_Size to set "
3635 & "desired value!", Pack_Pragma
);
3639 -- Actual packing is not needed for 8, 16, 32, 64.
3640 -- Also not needed for 24 if alignment is 1.
3646 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
3648 -- Here the array was requested to be packed,
3649 -- but the packing request had no effect, so
3650 -- Is_Packed is reset.
3652 -- Note: semantically this means that we lose
3653 -- track of the fact that a derived type
3654 -- inherited a pragma Pack that was non-
3655 -- effective, but that seems fine.
3657 -- We regard a Pack pragma as a request to set
3658 -- a representation characteristic, and this
3659 -- request may be ignored.
3661 Set_Is_Packed
(Base_Type
(E
), False);
3662 Set_Is_Bit_Packed_Array
(Base_Type
(E
), False);
3664 if Known_Static_Esize
(Component_Type
(E
))
3665 and then Esize
(Component_Type
(E
)) = Csiz
3667 Set_Has_Non_Standard_Rep
3668 (Base_Type
(E
), False);
3671 -- In all other cases, packing is indeed needed
3674 Set_Has_Non_Standard_Rep
(Base_Type
(E
), True);
3675 Set_Is_Bit_Packed_Array
(Base_Type
(E
), True);
3676 Set_Is_Packed
(Base_Type
(E
), True);
3682 -- Check for Atomic_Components or Aliased with unsuitable
3683 -- packing or explicit component size clause given.
3685 if (Has_Atomic_Components
(E
)
3686 or else Has_Aliased_Components
(E
))
3687 and then (Has_Component_Size_Clause
(E
)
3688 or else Is_Packed
(E
))
3690 Alias_Atomic_Check
: declare
3692 procedure Complain_CS
(T
: String);
3693 -- Outputs error messages for incorrect CS clause or
3694 -- pragma Pack for aliased or atomic components (T is
3695 -- "aliased" or "atomic");
3701 procedure Complain_CS
(T
: String) is
3703 if Has_Component_Size_Clause
(E
) then
3705 Get_Attribute_Definition_Clause
3706 (FS
, Attribute_Component_Size
);
3708 if Known_Static_Esize
(Ctyp
) then
3710 ("incorrect component size for "
3711 & T
& " components", Clause
);
3712 Error_Msg_Uint_1
:= Esize
(Ctyp
);
3714 ("\only allowed value is^", Clause
);
3718 ("component size cannot be given for "
3719 & T
& " components", Clause
);
3724 ("cannot pack " & T
& " components",
3725 Get_Rep_Pragma
(FS
, Name_Pack
));
3731 -- Start of processing for Alias_Atomic_Check
3735 -- If object size of component type isn't known, we
3736 -- cannot be sure so we defer to the back end.
3738 if not Known_Static_Esize
(Ctyp
) then
3741 -- Case where component size has no effect. First
3742 -- check for object size of component type multiple
3743 -- of the storage unit size.
3745 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
3747 -- OK in both packing case and component size case
3748 -- if RM size is known and static and the same as
3752 ((Known_Static_RM_Size
(Ctyp
)
3753 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
3755 -- Or if we have an explicit component size
3756 -- clause and the component size and object size
3760 (Has_Component_Size_Clause
(E
)
3761 and then Component_Size
(E
) = Esize
(Ctyp
)))
3765 elsif Has_Aliased_Components
(E
)
3766 or else Is_Aliased
(Ctyp
)
3768 Complain_CS
("aliased");
3770 elsif Has_Atomic_Components
(E
)
3771 or else Is_Atomic
(Ctyp
)
3773 Complain_CS
("atomic");
3775 end Alias_Atomic_Check
;
3778 -- Warn for case of atomic type
3780 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
3783 and then not Addressable
(Component_Size
(FS
))
3786 ("non-atomic components of type& may not be "
3787 & "accessible by separate tasks?", Clause
, E
);
3789 if Has_Component_Size_Clause
(E
) then
3792 (Get_Attribute_Definition_Clause
3793 (FS
, Attribute_Component_Size
));
3795 ("\because of component size clause#?",
3798 elsif Has_Pragma_Pack
(E
) then
3800 Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
3802 ("\because of pragma Pack#?", Clause
);
3806 -- Check for scalar storage order
3808 if Present
(Get_Attribute_Definition_Clause
3809 (E
, Attribute_Scalar_Storage_Order
))
3811 Check_Component_Storage_Order
(E
, Empty
);
3814 -- Processing that is done only for subtypes
3817 -- Acquire alignment from base type
3819 if Unknown_Alignment
(E
) then
3820 Set_Alignment
(E
, Alignment
(Base_Type
(E
)));
3821 Adjust_Esize_Alignment
(E
);
3825 -- For bit-packed arrays, check the size
3827 if Is_Bit_Packed_Array
(E
) and then Known_RM_Size
(E
) then
3829 SizC
: constant Node_Id
:= Size_Clause
(E
);
3832 pragma Warnings
(Off
, Discard
);
3835 -- It is not clear if it is possible to have no size
3836 -- clause at this stage, but it is not worth worrying
3837 -- about. Post error on the entity name in the size
3838 -- clause if present, else on the type entity itself.
3840 if Present
(SizC
) then
3841 Check_Size
(Name
(SizC
), E
, RM_Size
(E
), Discard
);
3843 Check_Size
(E
, E
, RM_Size
(E
), Discard
);
3848 -- If any of the index types was an enumeration type with a
3849 -- non-standard rep clause, then we indicate that the array
3850 -- type is always packed (even if it is not bit packed).
3852 if Non_Standard_Enum
then
3853 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
3854 Set_Is_Packed
(Base_Type
(E
));
3857 Set_Component_Alignment_If_Not_Set
(E
);
3859 -- If the array is packed, we must create the packed array
3860 -- type to be used to actually implement the type. This is
3861 -- only needed for real array types (not for string literal
3862 -- types, since they are present only for the front end).
3865 and then Ekind
(E
) /= E_String_Literal_Subtype
3867 Create_Packed_Array_Type
(E
);
3868 Freeze_And_Append
(Packed_Array_Type
(E
), N
, Result
);
3870 -- Size information of packed array type is copied to the
3871 -- array type, since this is really the representation. But
3872 -- do not override explicit existing size values. If the
3873 -- ancestor subtype is constrained the packed_array_type
3874 -- will be inherited from it, but the size may have been
3875 -- provided already, and must not be overridden either.
3877 if not Has_Size_Clause
(E
)
3879 (No
(Ancestor_Subtype
(E
))
3880 or else not Has_Size_Clause
(Ancestor_Subtype
(E
)))
3882 Set_Esize
(E
, Esize
(Packed_Array_Type
(E
)));
3883 Set_RM_Size
(E
, RM_Size
(Packed_Array_Type
(E
)));
3886 if not Has_Alignment_Clause
(E
) then
3887 Set_Alignment
(E
, Alignment
(Packed_Array_Type
(E
)));
3891 -- For non-packed arrays set the alignment of the array to the
3892 -- alignment of the component type if it is unknown. Skip this
3893 -- in atomic case (atomic arrays may need larger alignments).
3895 if not Is_Packed
(E
)
3896 and then Unknown_Alignment
(E
)
3897 and then Known_Alignment
(Ctyp
)
3898 and then Known_Static_Component_Size
(E
)
3899 and then Known_Static_Esize
(Ctyp
)
3900 and then Esize
(Ctyp
) = Component_Size
(E
)
3901 and then not Is_Atomic
(E
)
3903 Set_Alignment
(E
, Alignment
(Component_Type
(E
)));
3907 -- For a class-wide type, the corresponding specific type is
3908 -- frozen as well (RM 13.14(15))
3910 elsif Is_Class_Wide_Type
(E
) then
3911 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
3913 -- If the base type of the class-wide type is still incomplete,
3914 -- the class-wide remains unfrozen as well. This is legal when
3915 -- E is the formal of a primitive operation of some other type
3916 -- which is being frozen.
3918 if not Is_Frozen
(Root_Type
(E
)) then
3919 Set_Is_Frozen
(E
, False);
3923 -- The equivalent type associated with a class-wide subtype needs
3924 -- to be frozen to ensure that its layout is done.
3926 if Ekind
(E
) = E_Class_Wide_Subtype
3927 and then Present
(Equivalent_Type
(E
))
3929 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
3932 -- Generate an itype reference for a library-level class-wide type
3933 -- at the freeze point. Otherwise the first explicit reference to
3934 -- the type may appear in an inner scope which will be rejected by
3938 and then Is_Compilation_Unit
(Scope
(E
))
3941 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
3946 -- From a gigi point of view, a class-wide subtype derives
3947 -- from its record equivalent type. As a result, the itype
3948 -- reference must appear after the freeze node of the
3949 -- equivalent type or gigi will reject the reference.
3951 if Ekind
(E
) = E_Class_Wide_Subtype
3952 and then Present
(Equivalent_Type
(E
))
3954 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
3956 Add_To_Result
(Ref
);
3961 -- For a record type or record subtype, freeze all component types
3962 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
3963 -- using Is_Record_Type, because we don't want to attempt the freeze
3964 -- for the case of a private type with record extension (we will do
3965 -- that later when the full type is frozen).
3967 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
) then
3968 Freeze_Record_Type
(E
);
3970 -- For a concurrent type, freeze corresponding record type. This
3971 -- does not correspond to any specific rule in the RM, but the
3972 -- record type is essentially part of the concurrent type.
3973 -- Freeze as well all local entities. This includes record types
3974 -- created for entry parameter blocks, and whatever local entities
3975 -- may appear in the private part.
3977 elsif Is_Concurrent_Type
(E
) then
3978 if Present
(Corresponding_Record_Type
(E
)) then
3980 (Corresponding_Record_Type
(E
), N
, Result
);
3983 Comp
:= First_Entity
(E
);
3984 while Present
(Comp
) loop
3985 if Is_Type
(Comp
) then
3986 Freeze_And_Append
(Comp
, N
, Result
);
3988 elsif (Ekind
(Comp
)) /= E_Function
then
3989 if Is_Itype
(Etype
(Comp
))
3990 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
3992 Undelay_Type
(Etype
(Comp
));
3995 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
4001 -- Private types are required to point to the same freeze node as
4002 -- their corresponding full views. The freeze node itself has to
4003 -- point to the partial view of the entity (because from the partial
4004 -- view, we can retrieve the full view, but not the reverse).
4005 -- However, in order to freeze correctly, we need to freeze the full
4006 -- view. If we are freezing at the end of a scope (or within the
4007 -- scope of the private type), the partial and full views will have
4008 -- been swapped, the full view appears first in the entity chain and
4009 -- the swapping mechanism ensures that the pointers are properly set
4012 -- If we encounter the partial view before the full view (e.g. when
4013 -- freezing from another scope), we freeze the full view, and then
4014 -- set the pointers appropriately since we cannot rely on swapping to
4015 -- fix things up (subtypes in an outer scope might not get swapped).
4017 elsif Is_Incomplete_Or_Private_Type
(E
)
4018 and then not Is_Generic_Type
(E
)
4020 -- The construction of the dispatch table associated with library
4021 -- level tagged types forces freezing of all the primitives of the
4022 -- type, which may cause premature freezing of the partial view.
4026 -- type T is tagged private;
4027 -- type DT is new T with private;
4028 -- procedure Prim (X : in out T; Y : in out DT'Class);
4030 -- type T is tagged null record;
4032 -- type DT is new T with null record;
4035 -- In this case the type will be frozen later by the usual
4036 -- mechanism: an object declaration, an instantiation, or the
4037 -- end of a declarative part.
4039 if Is_Library_Level_Tagged_Type
(E
)
4040 and then not Present
(Full_View
(E
))
4042 Set_Is_Frozen
(E
, False);
4045 -- Case of full view present
4047 elsif Present
(Full_View
(E
)) then
4049 -- If full view has already been frozen, then no further
4050 -- processing is required
4052 if Is_Frozen
(Full_View
(E
)) then
4053 Set_Has_Delayed_Freeze
(E
, False);
4054 Set_Freeze_Node
(E
, Empty
);
4055 Check_Debug_Info_Needed
(E
);
4057 -- Otherwise freeze full view and patch the pointers so that
4058 -- the freeze node will elaborate both views in the back-end.
4062 Full
: constant Entity_Id
:= Full_View
(E
);
4065 if Is_Private_Type
(Full
)
4066 and then Present
(Underlying_Full_View
(Full
))
4069 (Underlying_Full_View
(Full
), N
, Result
);
4072 Freeze_And_Append
(Full
, N
, Result
);
4074 if Has_Delayed_Freeze
(E
) then
4075 F_Node
:= Freeze_Node
(Full
);
4077 if Present
(F_Node
) then
4078 Set_Freeze_Node
(E
, F_Node
);
4079 Set_Entity
(F_Node
, E
);
4082 -- {Incomplete,Private}_Subtypes with Full_Views
4083 -- constrained by discriminants.
4085 Set_Has_Delayed_Freeze
(E
, False);
4086 Set_Freeze_Node
(E
, Empty
);
4091 Check_Debug_Info_Needed
(E
);
4094 -- AI-117 requires that the convention of a partial view be the
4095 -- same as the convention of the full view. Note that this is a
4096 -- recognized breach of privacy, but it's essential for logical
4097 -- consistency of representation, and the lack of a rule in
4098 -- RM95 was an oversight.
4100 Set_Convention
(E
, Convention
(Full_View
(E
)));
4102 Set_Size_Known_At_Compile_Time
(E
,
4103 Size_Known_At_Compile_Time
(Full_View
(E
)));
4105 -- Size information is copied from the full view to the
4106 -- incomplete or private view for consistency.
4108 -- We skip this is the full view is not a type. This is very
4109 -- strange of course, and can only happen as a result of
4110 -- certain illegalities, such as a premature attempt to derive
4111 -- from an incomplete type.
4113 if Is_Type
(Full_View
(E
)) then
4114 Set_Size_Info
(E
, Full_View
(E
));
4115 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
4120 -- Case of no full view present. If entity is derived or subtype,
4121 -- it is safe to freeze, correctness depends on the frozen status
4122 -- of parent. Otherwise it is either premature usage, or a Taft
4123 -- amendment type, so diagnosis is at the point of use and the
4124 -- type might be frozen later.
4126 elsif E
/= Base_Type
(E
)
4127 or else Is_Derived_Type
(E
)
4132 Set_Is_Frozen
(E
, False);
4136 -- For access subprogram, freeze types of all formals, the return
4137 -- type was already frozen, since it is the Etype of the function.
4138 -- Formal types can be tagged Taft amendment types, but otherwise
4139 -- they cannot be incomplete.
4141 elsif Ekind
(E
) = E_Subprogram_Type
then
4142 Formal
:= First_Formal
(E
);
4143 while Present
(Formal
) loop
4144 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
4145 and then No
(Full_View
(Etype
(Formal
)))
4146 and then not Is_Value_Type
(Etype
(Formal
))
4148 if Is_Tagged_Type
(Etype
(Formal
)) then
4151 -- AI05-151: Incomplete types are allowed in access to
4152 -- subprogram specifications.
4154 elsif Ada_Version
< Ada_2012
then
4156 ("invalid use of incomplete type&", E
, Etype
(Formal
));
4160 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
4161 Next_Formal
(Formal
);
4164 Freeze_Subprogram
(E
);
4166 -- For access to a protected subprogram, freeze the equivalent type
4167 -- (however this is not set if we are not generating code or if this
4168 -- is an anonymous type used just for resolution).
4170 elsif Is_Access_Protected_Subprogram_Type
(E
) then
4171 if Present
(Equivalent_Type
(E
)) then
4172 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
4176 -- Generic types are never seen by the back-end, and are also not
4177 -- processed by the expander (since the expander is turned off for
4178 -- generic processing), so we never need freeze nodes for them.
4180 if Is_Generic_Type
(E
) then
4184 -- Some special processing for non-generic types to complete
4185 -- representation details not known till the freeze point.
4187 if Is_Fixed_Point_Type
(E
) then
4188 Freeze_Fixed_Point_Type
(E
);
4190 -- Some error checks required for ordinary fixed-point type. Defer
4191 -- these till the freeze-point since we need the small and range
4192 -- values. We only do these checks for base types
4194 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
4195 if Small_Value
(E
) < Ureal_2_M_80
then
4196 Error_Msg_Name_1
:= Name_Small
;
4198 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
4200 elsif Small_Value
(E
) > Ureal_2_80
then
4201 Error_Msg_Name_1
:= Name_Small
;
4203 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
4206 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
4207 Error_Msg_Name_1
:= Name_First
;
4209 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
4212 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
4213 Error_Msg_Name_1
:= Name_Last
;
4215 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
4219 elsif Is_Enumeration_Type
(E
) then
4220 Freeze_Enumeration_Type
(E
);
4222 elsif Is_Integer_Type
(E
) then
4223 Adjust_Esize_For_Alignment
(E
);
4225 if Is_Modular_Integer_Type
(E
)
4226 and then Warn_On_Suspicious_Modulus_Value
4228 Check_Suspicious_Modulus
(E
);
4231 elsif Is_Access_Type
(E
)
4232 and then not Is_Access_Subprogram_Type
(E
)
4234 -- If a pragma Default_Storage_Pool applies, and this type has no
4235 -- Storage_Pool or Storage_Size clause (which must have occurred
4236 -- before the freezing point), then use the default. This applies
4237 -- only to base types.
4239 -- None of this applies to access to subprograms, for which there
4240 -- are clearly no pools.
4242 if Present
(Default_Pool
)
4243 and then Is_Base_Type
(E
)
4244 and then not Has_Storage_Size_Clause
(E
)
4245 and then No
(Associated_Storage_Pool
(E
))
4247 -- Case of pragma Default_Storage_Pool (null)
4249 if Nkind
(Default_Pool
) = N_Null
then
4250 Set_No_Pool_Assigned
(E
);
4252 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
4255 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
4259 -- Check restriction for standard storage pool
4261 if No
(Associated_Storage_Pool
(E
)) then
4262 Check_Restriction
(No_Standard_Storage_Pools
, E
);
4265 -- Deal with error message for pure access type. This is not an
4266 -- error in Ada 2005 if there is no pool (see AI-366).
4268 if Is_Pure_Unit_Access_Type
(E
)
4269 and then (Ada_Version
< Ada_2005
4270 or else not No_Pool_Assigned
(E
))
4272 Error_Msg_N
("named access type not allowed in pure unit", E
);
4274 if Ada_Version
>= Ada_2005
then
4276 ("\would be legal if Storage_Size of 0 given?", E
);
4278 elsif No_Pool_Assigned
(E
) then
4280 ("\would be legal in Ada 2005?", E
);
4284 ("\would be legal in Ada 2005 if "
4285 & "Storage_Size of 0 given?", E
);
4290 -- Case of composite types
4292 if Is_Composite_Type
(E
) then
4294 -- AI-117 requires that all new primitives of a tagged type must
4295 -- inherit the convention of the full view of the type. Inherited
4296 -- and overriding operations are defined to inherit the convention
4297 -- of their parent or overridden subprogram (also specified in
4298 -- AI-117), which will have occurred earlier (in Derive_Subprogram
4299 -- and New_Overloaded_Entity). Here we set the convention of
4300 -- primitives that are still convention Ada, which will ensure
4301 -- that any new primitives inherit the type's convention. Class-
4302 -- wide types can have a foreign convention inherited from their
4303 -- specific type, but are excluded from this since they don't have
4304 -- any associated primitives.
4306 if Is_Tagged_Type
(E
)
4307 and then not Is_Class_Wide_Type
(E
)
4308 and then Convention
(E
) /= Convention_Ada
4311 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
4315 Prim
:= First_Elmt
(Prim_List
);
4316 while Present
(Prim
) loop
4317 if Convention
(Node
(Prim
)) = Convention_Ada
then
4318 Set_Convention
(Node
(Prim
), Convention
(E
));
4326 -- If the type is a simple storage pool type, then this is where
4327 -- we attempt to locate and validate its Allocate, Deallocate, and
4328 -- Storage_Size operations (the first is required, and the latter
4329 -- two are optional). We also verify that the full type for a
4330 -- private type is allowed to be a simple storage pool type.
4332 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
4333 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
4335 -- If the type is marked Has_Private_Declaration, then this is
4336 -- a full type for a private type that was specified with the
4337 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
4338 -- pragma is allowed for the full type (for example, it can't
4339 -- be an array type, or a nonlimited record type).
4341 if Has_Private_Declaration
(E
) then
4342 if (not Is_Record_Type
(E
)
4343 or else not Is_Immutably_Limited_Type
(E
))
4344 and then not Is_Private_Type
(E
)
4346 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
4348 ("pragma% can only apply to full type that is an " &
4349 "explicitly limited type", E
);
4353 Validate_Simple_Pool_Ops
: declare
4354 Pool_Type
: Entity_Id
renames E
;
4355 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
4356 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
4358 procedure Validate_Simple_Pool_Op_Formal
4359 (Pool_Op
: Entity_Id
;
4360 Pool_Op_Formal
: in out Entity_Id
;
4361 Expected_Mode
: Formal_Kind
;
4362 Expected_Type
: Entity_Id
;
4363 Formal_Name
: String;
4364 OK_Formal
: in out Boolean);
4365 -- Validate one formal Pool_Op_Formal of the candidate pool
4366 -- operation Pool_Op. The formal must be of Expected_Type
4367 -- and have mode Expected_Mode. OK_Formal will be set to
4368 -- False if the formal doesn't match. If OK_Formal is False
4369 -- on entry, then the formal will effectively be ignored
4370 -- (because validation of the pool op has already failed).
4371 -- Upon return, Pool_Op_Formal will be updated to the next
4374 procedure Validate_Simple_Pool_Operation
(Op_Name
: Name_Id
);
4375 -- Search for and validate a simple pool operation with the
4376 -- name Op_Name. If the name is Allocate, then there must be
4377 -- exactly one such primitive operation for the simple pool
4378 -- type. If the name is Deallocate or Storage_Size, then
4379 -- there can be at most one such primitive operation. The
4380 -- profile of the located primitive must conform to what
4381 -- is expected for each operation.
4383 ------------------------------------
4384 -- Validate_Simple_Pool_Op_Formal --
4385 ------------------------------------
4387 procedure Validate_Simple_Pool_Op_Formal
4388 (Pool_Op
: Entity_Id
;
4389 Pool_Op_Formal
: in out Entity_Id
;
4390 Expected_Mode
: Formal_Kind
;
4391 Expected_Type
: Entity_Id
;
4392 Formal_Name
: String;
4393 OK_Formal
: in out Boolean)
4396 -- If OK_Formal is False on entry, then simply ignore
4397 -- the formal, because an earlier formal has already
4400 if not OK_Formal
then
4403 -- If no formal is passed in, then issue an error for a
4406 elsif not Present
(Pool_Op_Formal
) then
4408 ("simple storage pool op missing formal " &
4409 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
4415 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
4417 -- If the pool type was expected for this formal, then
4418 -- this will not be considered a candidate operation
4419 -- for the simple pool, so we unset OK_Formal so that
4420 -- the op and any later formals will be ignored.
4422 if Expected_Type
= Pool_Type
then
4429 ("wrong type for formal " & Formal_Name
&
4430 " of simple storage pool op; expected type&",
4431 Pool_Op_Formal
, Expected_Type
);
4435 -- Issue error if formal's mode is not the expected one
4437 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
4439 ("wrong mode for formal of simple storage pool op",
4443 -- Advance to the next formal
4445 Next_Formal
(Pool_Op_Formal
);
4446 end Validate_Simple_Pool_Op_Formal
;
4448 ------------------------------------
4449 -- Validate_Simple_Pool_Operation --
4450 ------------------------------------
4452 procedure Validate_Simple_Pool_Operation
4456 Found_Op
: Entity_Id
:= Empty
;
4462 (Op_Name
= Name_Allocate
4463 or else Op_Name
= Name_Deallocate
4464 or else Op_Name
= Name_Storage_Size
);
4466 Error_Msg_Name_1
:= Op_Name
;
4468 -- For each homonym declared immediately in the scope
4469 -- of the simple storage pool type, determine whether
4470 -- the homonym is an operation of the pool type, and,
4471 -- if so, check that its profile is as expected for
4472 -- a simple pool operation of that name.
4474 Op
:= Get_Name_Entity_Id
(Op_Name
);
4475 while Present
(Op
) loop
4476 if Ekind_In
(Op
, E_Function
, E_Procedure
)
4477 and then Scope
(Op
) = Current_Scope
4479 Formal
:= First_Entity
(Op
);
4483 -- The first parameter must be of the pool type
4484 -- in order for the operation to qualify.
4486 if Op_Name
= Name_Storage_Size
then
4487 Validate_Simple_Pool_Op_Formal
4488 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
4491 Validate_Simple_Pool_Op_Formal
4492 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
4496 -- If another operation with this name has already
4497 -- been located for the type, then flag an error,
4498 -- since we only allow the type to have a single
4501 if Present
(Found_Op
) and then Is_OK
then
4503 ("only one % operation allowed for " &
4504 "simple storage pool type&", Op
, Pool_Type
);
4507 -- In the case of Allocate and Deallocate, a formal
4508 -- of type System.Address is required.
4510 if Op_Name
= Name_Allocate
then
4511 Validate_Simple_Pool_Op_Formal
4512 (Op
, Formal
, E_Out_Parameter
,
4513 Address_Type
, "Storage_Address", Is_OK
);
4514 elsif Op_Name
= Name_Deallocate
then
4515 Validate_Simple_Pool_Op_Formal
4516 (Op
, Formal
, E_In_Parameter
,
4517 Address_Type
, "Storage_Address", Is_OK
);
4520 -- In the case of Allocate and Deallocate, formals
4521 -- of type Storage_Count are required as the third
4522 -- and fourth parameters.
4524 if Op_Name
/= Name_Storage_Size
then
4525 Validate_Simple_Pool_Op_Formal
4526 (Op
, Formal
, E_In_Parameter
,
4527 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
4528 Validate_Simple_Pool_Op_Formal
4529 (Op
, Formal
, E_In_Parameter
,
4530 Stg_Cnt_Type
, "Alignment", Is_OK
);
4533 -- If no mismatched formals have been found (Is_OK)
4534 -- and no excess formals are present, then this
4535 -- operation has been validated, so record it.
4537 if not Present
(Formal
) and then Is_OK
then
4545 -- There must be a valid Allocate operation for the type,
4546 -- so issue an error if none was found.
4548 if Op_Name
= Name_Allocate
4549 and then not Present
(Found_Op
)
4551 Error_Msg_N
("missing % operation for simple " &
4552 "storage pool type", Pool_Type
);
4554 elsif Present
(Found_Op
) then
4556 -- Simple pool operations can't be abstract
4558 if Is_Abstract_Subprogram
(Found_Op
) then
4560 ("simple storage pool operation must not be " &
4561 "abstract", Found_Op
);
4564 -- The Storage_Size operation must be a function with
4565 -- Storage_Count as its result type.
4567 if Op_Name
= Name_Storage_Size
then
4568 if Ekind
(Found_Op
) = E_Procedure
then
4570 ("% operation must be a function", Found_Op
);
4572 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
4574 ("wrong result type for%, expected type&",
4575 Found_Op
, Stg_Cnt_Type
);
4578 -- Allocate and Deallocate must be procedures
4580 elsif Ekind
(Found_Op
) = E_Function
then
4582 ("% operation must be a procedure", Found_Op
);
4585 end Validate_Simple_Pool_Operation
;
4587 -- Start of processing for Validate_Simple_Pool_Ops
4590 Validate_Simple_Pool_Operation
(Name_Allocate
);
4591 Validate_Simple_Pool_Operation
(Name_Deallocate
);
4592 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
4593 end Validate_Simple_Pool_Ops
;
4597 -- Now that all types from which E may depend are frozen, see if the
4598 -- size is known at compile time, if it must be unsigned, or if
4599 -- strict alignment is required
4601 Check_Compile_Time_Size
(E
);
4602 Check_Unsigned_Type
(E
);
4604 if Base_Type
(E
) = E
then
4605 Check_Strict_Alignment
(E
);
4608 -- Do not allow a size clause for a type which does not have a size
4609 -- that is known at compile time
4611 if Has_Size_Clause
(E
)
4612 and then not Size_Known_At_Compile_Time
(E
)
4614 -- Suppress this message if errors posted on E, even if we are
4615 -- in all errors mode, since this is often a junk message
4617 if not Error_Posted
(E
) then
4619 ("size clause not allowed for variable length type",
4624 -- Now we set/verify the representation information, in particular
4625 -- the size and alignment values. This processing is not required for
4626 -- generic types, since generic types do not play any part in code
4627 -- generation, and so the size and alignment values for such types
4628 -- are irrelevant. Ditto for types declared within a generic unit,
4629 -- which may have components that depend on generic parameters, and
4630 -- that will be recreated in an instance.
4632 if Inside_A_Generic
then
4635 -- Otherwise we call the layout procedure
4641 -- If this is an access to subprogram whose designated type is itself
4642 -- a subprogram type, the return type of this anonymous subprogram
4643 -- type must be decorated as well.
4645 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
4646 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
4648 Layout_Type
(Etype
(Designated_Type
(E
)));
4651 -- If the type has a Defaut_Value/Default_Component_Value aspect,
4652 -- this is where we analye the expression (after the type is frozen,
4653 -- since in the case of Default_Value, we are analyzing with the
4654 -- type itself, and we treat Default_Component_Value similarly for
4655 -- the sake of uniformity.
4657 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
4664 if Is_Scalar_Type
(E
) then
4665 Nam
:= Name_Default_Value
;
4667 Exp
:= Default_Aspect_Value
(Typ
);
4669 Nam
:= Name_Default_Component_Value
;
4670 Typ
:= Component_Type
(E
);
4671 Exp
:= Default_Aspect_Component_Value
(E
);
4674 Analyze_And_Resolve
(Exp
, Typ
);
4676 if Etype
(Exp
) /= Any_Type
then
4677 if not Is_Static_Expression
(Exp
) then
4678 Error_Msg_Name_1
:= Nam
;
4679 Flag_Non_Static_Expr
4680 ("aspect% requires static expression", Exp
);
4686 -- End of freeze processing for type entities
4689 -- Here is where we logically freeze the current entity. If it has a
4690 -- freeze node, then this is the point at which the freeze node is
4691 -- linked into the result list.
4693 if Has_Delayed_Freeze
(E
) then
4695 -- If a freeze node is already allocated, use it, otherwise allocate
4696 -- a new one. The preallocation happens in the case of anonymous base
4697 -- types, where we preallocate so that we can set First_Subtype_Link.
4698 -- Note that we reset the Sloc to the current freeze location.
4700 if Present
(Freeze_Node
(E
)) then
4701 F_Node
:= Freeze_Node
(E
);
4702 Set_Sloc
(F_Node
, Loc
);
4705 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
4706 Set_Freeze_Node
(E
, F_Node
);
4707 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
4708 Set_TSS_Elist
(F_Node
, No_Elist
);
4709 Set_Actions
(F_Node
, No_List
);
4712 Set_Entity
(F_Node
, E
);
4713 Add_To_Result
(F_Node
);
4715 -- A final pass over record types with discriminants. If the type
4716 -- has an incomplete declaration, there may be constrained access
4717 -- subtypes declared elsewhere, which do not depend on the discrimi-
4718 -- nants of the type, and which are used as component types (i.e.
4719 -- the full view is a recursive type). The designated types of these
4720 -- subtypes can only be elaborated after the type itself, and they
4721 -- need an itype reference.
4723 if Ekind
(E
) = E_Record_Type
4724 and then Has_Discriminants
(E
)
4732 Comp
:= First_Component
(E
);
4733 while Present
(Comp
) loop
4734 Typ
:= Etype
(Comp
);
4736 if Ekind
(Comp
) = E_Component
4737 and then Is_Access_Type
(Typ
)
4738 and then Scope
(Typ
) /= E
4739 and then Base_Type
(Designated_Type
(Typ
)) = E
4740 and then Is_Itype
(Designated_Type
(Typ
))
4742 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
4743 Set_Itype
(IR
, Designated_Type
(Typ
));
4744 Append
(IR
, Result
);
4747 Next_Component
(Comp
);
4753 -- When a type is frozen, the first subtype of the type is frozen as
4754 -- well (RM 13.14(15)). This has to be done after freezing the type,
4755 -- since obviously the first subtype depends on its own base type.
4758 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
4760 -- If we just froze a tagged non-class wide record, then freeze the
4761 -- corresponding class-wide type. This must be done after the tagged
4762 -- type itself is frozen, because the class-wide type refers to the
4763 -- tagged type which generates the class.
4765 if Is_Tagged_Type
(E
)
4766 and then not Is_Class_Wide_Type
(E
)
4767 and then Present
(Class_Wide_Type
(E
))
4769 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
4773 Check_Debug_Info_Needed
(E
);
4775 -- Special handling for subprograms
4777 if Is_Subprogram
(E
) then
4779 -- If subprogram has address clause then reset Is_Public flag, since
4780 -- we do not want the backend to generate external references.
4782 if Present
(Address_Clause
(E
))
4783 and then not Is_Library_Level_Entity
(E
)
4785 Set_Is_Public
(E
, False);
4787 -- If no address clause and not intrinsic, then for imported
4788 -- subprogram in main unit, generate descriptor if we are in
4789 -- Propagate_Exceptions mode.
4791 -- This is very odd code, it makes a null result, why ???
4793 elsif Propagate_Exceptions
4794 and then Is_Imported
(E
)
4795 and then not Is_Intrinsic_Subprogram
(E
)
4796 and then Convention
(E
) /= Convention_Stubbed
4798 if Result
= No_List
then
4799 Result
:= Empty_List
;
4807 -----------------------------
4808 -- Freeze_Enumeration_Type --
4809 -----------------------------
4811 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
4813 -- By default, if no size clause is present, an enumeration type with
4814 -- Convention C is assumed to interface to a C enum, and has integer
4815 -- size. This applies to types. For subtypes, verify that its base
4816 -- type has no size clause either. Treat other foreign conventions
4817 -- in the same way, and also make sure alignment is set right.
4819 if Has_Foreign_Convention
(Typ
)
4820 and then not Has_Size_Clause
(Typ
)
4821 and then not Has_Size_Clause
(Base_Type
(Typ
))
4822 and then Esize
(Typ
) < Standard_Integer_Size
4824 Init_Esize
(Typ
, Standard_Integer_Size
);
4825 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
4828 -- If the enumeration type interfaces to C, and it has a size clause
4829 -- that specifies less than int size, it warrants a warning. The
4830 -- user may intend the C type to be an enum or a char, so this is
4831 -- not by itself an error that the Ada compiler can detect, but it
4832 -- it is a worth a heads-up. For Boolean and Character types we
4833 -- assume that the programmer has the proper C type in mind.
4835 if Convention
(Typ
) = Convention_C
4836 and then Has_Size_Clause
(Typ
)
4837 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
4838 and then not Is_Boolean_Type
(Typ
)
4839 and then not Is_Character_Type
(Typ
)
4842 ("C enum types have the size of a C int?", Size_Clause
(Typ
));
4845 Adjust_Esize_For_Alignment
(Typ
);
4847 end Freeze_Enumeration_Type
;
4849 -----------------------
4850 -- Freeze_Expression --
4851 -----------------------
4853 procedure Freeze_Expression
(N
: Node_Id
) is
4854 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
4857 Desig_Typ
: Entity_Id
;
4861 Freeze_Outside
: Boolean := False;
4862 -- This flag is set true if the entity must be frozen outside the
4863 -- current subprogram. This happens in the case of expander generated
4864 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
4865 -- not freeze all entities like other bodies, but which nevertheless
4866 -- may reference entities that have to be frozen before the body and
4867 -- obviously cannot be frozen inside the body.
4869 function In_Exp_Body
(N
: Node_Id
) return Boolean;
4870 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
4871 -- it is the handled statement sequence of an expander-generated
4872 -- subprogram (init proc, stream subprogram, or renaming as body).
4873 -- If so, this is not a freezing context.
4879 function In_Exp_Body
(N
: Node_Id
) return Boolean is
4884 if Nkind
(N
) = N_Subprogram_Body
then
4890 if Nkind
(P
) /= N_Subprogram_Body
then
4894 Id
:= Defining_Unit_Name
(Specification
(P
));
4896 -- Following complex conditional could use comments ???
4898 if Nkind
(Id
) = N_Defining_Identifier
4899 and then (Is_Init_Proc
(Id
)
4900 or else Is_TSS
(Id
, TSS_Stream_Input
)
4901 or else Is_TSS
(Id
, TSS_Stream_Output
)
4902 or else Is_TSS
(Id
, TSS_Stream_Read
)
4903 or else Is_TSS
(Id
, TSS_Stream_Write
)
4904 or else Nkind_In
(Original_Node
(P
),
4905 N_Subprogram_Renaming_Declaration
,
4906 N_Expression_Function
))
4915 -- Start of processing for Freeze_Expression
4918 -- Immediate return if freezing is inhibited. This flag is set by the
4919 -- analyzer to stop freezing on generated expressions that would cause
4920 -- freezing if they were in the source program, but which are not
4921 -- supposed to freeze, since they are created.
4923 if Must_Not_Freeze
(N
) then
4927 -- If expression is non-static, then it does not freeze in a default
4928 -- expression, see section "Handling of Default Expressions" in the
4929 -- spec of package Sem for further details. Note that we have to make
4930 -- sure that we actually have a real expression (if we have a subtype
4931 -- indication, we can't test Is_Static_Expression!) However, we exclude
4932 -- the case of the prefix of an attribute of a static scalar subtype
4933 -- from this early return, because static subtype attributes should
4934 -- always cause freezing, even in default expressions, but the attribute
4935 -- may not have been marked as static yet (because in Resolve_Attribute,
4936 -- the call to Eval_Attribute follows the call of Freeze_Expression on
4940 and then Nkind
(N
) in N_Subexpr
4941 and then not Is_Static_Expression
(N
)
4942 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
4943 or else not (Is_Entity_Name
(N
)
4944 and then Is_Type
(Entity
(N
))
4945 and then Is_Static_Subtype
(Entity
(N
))))
4950 -- Freeze type of expression if not frozen already
4954 if Nkind
(N
) in N_Has_Etype
then
4955 if not Is_Frozen
(Etype
(N
)) then
4958 -- Base type may be an derived numeric type that is frozen at
4959 -- the point of declaration, but first_subtype is still unfrozen.
4961 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
4962 Typ
:= First_Subtype
(Etype
(N
));
4966 -- For entity name, freeze entity if not frozen already. A special
4967 -- exception occurs for an identifier that did not come from source.
4968 -- We don't let such identifiers freeze a non-internal entity, i.e.
4969 -- an entity that did come from source, since such an identifier was
4970 -- generated by the expander, and cannot have any semantic effect on
4971 -- the freezing semantics. For example, this stops the parameter of
4972 -- an initialization procedure from freezing the variable.
4974 if Is_Entity_Name
(N
)
4975 and then not Is_Frozen
(Entity
(N
))
4976 and then (Nkind
(N
) /= N_Identifier
4977 or else Comes_From_Source
(N
)
4978 or else not Comes_From_Source
(Entity
(N
)))
4985 -- For an allocator freeze designated type if not frozen already
4987 -- For an aggregate whose component type is an access type, freeze the
4988 -- designated type now, so that its freeze does not appear within the
4989 -- loop that might be created in the expansion of the aggregate. If the
4990 -- designated type is a private type without full view, the expression
4991 -- cannot contain an allocator, so the type is not frozen.
4993 -- For a function, we freeze the entity when the subprogram declaration
4994 -- is frozen, but a function call may appear in an initialization proc.
4995 -- before the declaration is frozen. We need to generate the extra
4996 -- formals, if any, to ensure that the expansion of the call includes
4997 -- the proper actuals. This only applies to Ada subprograms, not to
5004 Desig_Typ
:= Designated_Type
(Etype
(N
));
5007 if Is_Array_Type
(Etype
(N
))
5008 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
5010 Desig_Typ
:= Designated_Type
(Component_Type
(Etype
(N
)));
5013 when N_Selected_Component |
5014 N_Indexed_Component |
5017 if Is_Access_Type
(Etype
(Prefix
(N
))) then
5018 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
5021 when N_Identifier
=>
5023 and then Ekind
(Nam
) = E_Function
5024 and then Nkind
(Parent
(N
)) = N_Function_Call
5025 and then Convention
(Nam
) = Convention_Ada
5027 Create_Extra_Formals
(Nam
);
5034 if Desig_Typ
/= Empty
5035 and then (Is_Frozen
(Desig_Typ
)
5036 or else (not Is_Fully_Defined
(Desig_Typ
)))
5041 -- All done if nothing needs freezing
5045 and then No
(Desig_Typ
)
5050 -- Loop for looking at the right place to insert the freeze nodes,
5051 -- exiting from the loop when it is appropriate to insert the freeze
5052 -- node before the current node P.
5054 -- Also checks some special exceptions to the freezing rules. These
5055 -- cases result in a direct return, bypassing the freeze action.
5059 Parent_P
:= Parent
(P
);
5061 -- If we don't have a parent, then we are not in a well-formed tree.
5062 -- This is an unusual case, but there are some legitimate situations
5063 -- in which this occurs, notably when the expressions in the range of
5064 -- a type declaration are resolved. We simply ignore the freeze
5065 -- request in this case. Is this right ???
5067 if No
(Parent_P
) then
5071 -- See if we have got to an appropriate point in the tree
5073 case Nkind
(Parent_P
) is
5075 -- A special test for the exception of (RM 13.14(8)) for the case
5076 -- of per-object expressions (RM 3.8(18)) occurring in component
5077 -- definition or a discrete subtype definition. Note that we test
5078 -- for a component declaration which includes both cases we are
5079 -- interested in, and furthermore the tree does not have explicit
5080 -- nodes for either of these two constructs.
5082 when N_Component_Declaration
=>
5084 -- The case we want to test for here is an identifier that is
5085 -- a per-object expression, this is either a discriminant that
5086 -- appears in a context other than the component declaration
5087 -- or it is a reference to the type of the enclosing construct.
5089 -- For either of these cases, we skip the freezing
5091 if not In_Spec_Expression
5092 and then Nkind
(N
) = N_Identifier
5093 and then (Present
(Entity
(N
)))
5095 -- We recognize the discriminant case by just looking for
5096 -- a reference to a discriminant. It can only be one for
5097 -- the enclosing construct. Skip freezing in this case.
5099 if Ekind
(Entity
(N
)) = E_Discriminant
then
5102 -- For the case of a reference to the enclosing record,
5103 -- (or task or protected type), we look for a type that
5104 -- matches the current scope.
5106 elsif Entity
(N
) = Current_Scope
then
5111 -- If we have an enumeration literal that appears as the choice in
5112 -- the aggregate of an enumeration representation clause, then
5113 -- freezing does not occur (RM 13.14(10)).
5115 when N_Enumeration_Representation_Clause
=>
5117 -- The case we are looking for is an enumeration literal
5119 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
5120 and then Is_Enumeration_Type
(Etype
(N
))
5122 -- If enumeration literal appears directly as the choice,
5123 -- do not freeze (this is the normal non-overloaded case)
5125 if Nkind
(Parent
(N
)) = N_Component_Association
5126 and then First
(Choices
(Parent
(N
))) = N
5130 -- If enumeration literal appears as the name of function
5131 -- which is the choice, then also do not freeze. This
5132 -- happens in the overloaded literal case, where the
5133 -- enumeration literal is temporarily changed to a function
5134 -- call for overloading analysis purposes.
5136 elsif Nkind
(Parent
(N
)) = N_Function_Call
5138 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
5140 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
5146 -- Normally if the parent is a handled sequence of statements,
5147 -- then the current node must be a statement, and that is an
5148 -- appropriate place to insert a freeze node.
5150 when N_Handled_Sequence_Of_Statements
=>
5152 -- An exception occurs when the sequence of statements is for
5153 -- an expander generated body that did not do the usual freeze
5154 -- all operation. In this case we usually want to freeze
5155 -- outside this body, not inside it, and we skip past the
5156 -- subprogram body that we are inside.
5158 if In_Exp_Body
(Parent_P
) then
5160 Subp
: constant Node_Id
:= Parent
(Parent_P
);
5164 -- Freeze the entity only when it is declared inside the
5165 -- body of the expander generated procedure. This case
5166 -- is recognized by the scope of the entity or its type,
5167 -- which is either the spec for some enclosing body, or
5168 -- (in the case of init_procs, for which there are no
5169 -- separate specs) the current scope.
5171 if Nkind
(Subp
) = N_Subprogram_Body
then
5172 Spec
:= Corresponding_Spec
(Subp
);
5174 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
5176 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
5181 and then Scope
(Typ
) = Current_Scope
5182 and then Defining_Entity
(Subp
) = Current_Scope
5188 -- An expression function may act as a completion of
5189 -- a function declaration. As such, it can reference
5190 -- entities declared between the two views:
5193 -- function F return ...;
5195 -- function Hidden return ...;
5196 -- function F return ... is (Hidden); -- 2
5198 -- Refering to the example above, freezing the expression
5199 -- of F (2) would place Hidden's freeze node (1) in the
5200 -- wrong place. Avoid explicit freezing and let the usual
5201 -- scenarios do the job - for example, reaching the end
5202 -- of the private declarations.
5204 if Nkind
(Original_Node
(Subp
)) =
5205 N_Expression_Function
5209 -- Freeze outside the body
5212 Parent_P
:= Parent
(Parent_P
);
5213 Freeze_Outside
:= True;
5217 -- Here if normal case where we are in handled statement
5218 -- sequence and want to do the insertion right there.
5224 -- If parent is a body or a spec or a block, then the current node
5225 -- is a statement or declaration and we can insert the freeze node
5228 when N_Block_Statement |
5231 N_Package_Specification |
5234 N_Task_Body
=> exit;
5236 -- The expander is allowed to define types in any statements list,
5237 -- so any of the following parent nodes also mark a freezing point
5238 -- if the actual node is in a list of statements or declarations.
5240 when N_Abortable_Part |
5241 N_Accept_Alternative |
5243 N_Case_Statement_Alternative |
5244 N_Compilation_Unit_Aux |
5245 N_Conditional_Entry_Call |
5246 N_Delay_Alternative |
5248 N_Entry_Call_Alternative |
5249 N_Exception_Handler |
5250 N_Extended_Return_Statement |
5254 N_Selective_Accept |
5255 N_Triggering_Alternative
=>
5257 exit when Is_List_Member
(P
);
5259 -- Note: The N_Loop_Statement is a special case. A type that
5260 -- appears in the source can never be frozen in a loop (this
5261 -- occurs only because of a loop expanded by the expander), so we
5262 -- keep on going. Otherwise we terminate the search. Same is true
5263 -- of any entity which comes from source. (if they have predefined
5264 -- type, that type does not appear to come from source, but the
5265 -- entity should not be frozen here).
5267 when N_Loop_Statement
=>
5268 exit when not Comes_From_Source
(Etype
(N
))
5269 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
5271 -- For all other cases, keep looking at parents
5277 -- We fall through the case if we did not yet find the proper
5278 -- place in the free for inserting the freeze node, so climb!
5283 -- If the expression appears in a record or an initialization procedure,
5284 -- the freeze nodes are collected and attached to the current scope, to
5285 -- be inserted and analyzed on exit from the scope, to insure that
5286 -- generated entities appear in the correct scope. If the expression is
5287 -- a default for a discriminant specification, the scope is still void.
5288 -- The expression can also appear in the discriminant part of a private
5289 -- or concurrent type.
5291 -- If the expression appears in a constrained subcomponent of an
5292 -- enclosing record declaration, the freeze nodes must be attached to
5293 -- the outer record type so they can eventually be placed in the
5294 -- enclosing declaration list.
5296 -- The other case requiring this special handling is if we are in a
5297 -- default expression, since in that case we are about to freeze a
5298 -- static type, and the freeze scope needs to be the outer scope, not
5299 -- the scope of the subprogram with the default parameter.
5301 -- For default expressions and other spec expressions in generic units,
5302 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
5303 -- placing them at the proper place, after the generic unit.
5305 if (In_Spec_Exp
and not Inside_A_Generic
)
5306 or else Freeze_Outside
5307 or else (Is_Type
(Current_Scope
)
5308 and then (not Is_Concurrent_Type
(Current_Scope
)
5309 or else not Has_Completion
(Current_Scope
)))
5310 or else Ekind
(Current_Scope
) = E_Void
5313 N
: constant Node_Id
:= Current_Scope
;
5314 Freeze_Nodes
: List_Id
:= No_List
;
5315 Pos
: Int
:= Scope_Stack
.Last
;
5318 if Present
(Desig_Typ
) then
5319 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
5322 if Present
(Typ
) then
5323 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
5326 if Present
(Nam
) then
5327 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
5330 -- The current scope may be that of a constrained component of
5331 -- an enclosing record declaration, or of a loop of an enclosing
5332 -- quantified expression, which is above the current scope in the
5333 -- scope stack. Indeed in the context of a quantified expression,
5334 -- a scope is created and pushed above the current scope in order
5335 -- to emulate the loop-like behavior of the quantified expression.
5336 -- If the expression is within a top-level pragma, as for a pre-
5337 -- condition on a library-level subprogram, nothing to do.
5339 if not Is_Compilation_Unit
(Current_Scope
)
5340 and then (Is_Record_Type
(Scope
(Current_Scope
))
5341 or else Nkind
(Parent
(Current_Scope
)) =
5342 N_Quantified_Expression
)
5347 if Is_Non_Empty_List
(Freeze_Nodes
) then
5348 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
5349 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
5352 Append_List
(Freeze_Nodes
,
5353 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
5361 -- Now we have the right place to do the freezing. First, a special
5362 -- adjustment, if we are in spec-expression analysis mode, these freeze
5363 -- actions must not be thrown away (normally all inserted actions are
5364 -- thrown away in this mode. However, the freeze actions are from static
5365 -- expressions and one of the important reasons we are doing this
5366 -- special analysis is to get these freeze actions. Therefore we turn
5367 -- off the In_Spec_Expression mode to propagate these freeze actions.
5368 -- This also means they get properly analyzed and expanded.
5370 In_Spec_Expression
:= False;
5372 -- Freeze the designated type of an allocator (RM 13.14(13))
5374 if Present
(Desig_Typ
) then
5375 Freeze_Before
(P
, Desig_Typ
);
5378 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
5379 -- the enumeration representation clause exception in the loop above.
5381 if Present
(Typ
) then
5382 Freeze_Before
(P
, Typ
);
5385 -- Freeze name if one is present (RM 13.14(11))
5387 if Present
(Nam
) then
5388 Freeze_Before
(P
, Nam
);
5391 -- Restore In_Spec_Expression flag
5393 In_Spec_Expression
:= In_Spec_Exp
;
5394 end Freeze_Expression
;
5396 -----------------------------
5397 -- Freeze_Fixed_Point_Type --
5398 -----------------------------
5400 -- Certain fixed-point types and subtypes, including implicit base types
5401 -- and declared first subtypes, have not yet set up a range. This is
5402 -- because the range cannot be set until the Small and Size values are
5403 -- known, and these are not known till the type is frozen.
5405 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
5406 -- whose bounds are unanalyzed real literals. This routine will recognize
5407 -- this case, and transform this range node into a properly typed range
5408 -- with properly analyzed and resolved values.
5410 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
5411 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
5412 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
5413 Hi
: constant Node_Id
:= High_Bound
(Rng
);
5414 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
5415 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
5416 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
5417 BHi
: constant Node_Id
:= High_Bound
(Brng
);
5418 Small
: constant Ureal
:= Small_Value
(Typ
);
5425 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
5426 -- Returns size of type with given bounds. Also leaves these
5427 -- bounds set as the current bounds of the Typ.
5433 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
5435 Set_Realval
(Lo
, Lov
);
5436 Set_Realval
(Hi
, Hiv
);
5437 return Minimum_Size
(Typ
);
5440 -- Start of processing for Freeze_Fixed_Point_Type
5443 -- If Esize of a subtype has not previously been set, set it now
5445 if Unknown_Esize
(Typ
) then
5446 Atype
:= Ancestor_Subtype
(Typ
);
5448 if Present
(Atype
) then
5449 Set_Esize
(Typ
, Esize
(Atype
));
5451 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
5455 -- Immediate return if the range is already analyzed. This means that
5456 -- the range is already set, and does not need to be computed by this
5459 if Analyzed
(Rng
) then
5463 -- Immediate return if either of the bounds raises Constraint_Error
5465 if Raises_Constraint_Error
(Lo
)
5466 or else Raises_Constraint_Error
(Hi
)
5471 Loval
:= Realval
(Lo
);
5472 Hival
:= Realval
(Hi
);
5474 -- Ordinary fixed-point case
5476 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
5478 -- For the ordinary fixed-point case, we are allowed to fudge the
5479 -- end-points up or down by small. Generally we prefer to fudge up,
5480 -- i.e. widen the bounds for non-model numbers so that the end points
5481 -- are included. However there are cases in which this cannot be
5482 -- done, and indeed cases in which we may need to narrow the bounds.
5483 -- The following circuit makes the decision.
5485 -- Note: our terminology here is that Incl_EP means that the bounds
5486 -- are widened by Small if necessary to include the end points, and
5487 -- Excl_EP means that the bounds are narrowed by Small to exclude the
5488 -- end-points if this reduces the size.
5490 -- Note that in the Incl case, all we care about is including the
5491 -- end-points. In the Excl case, we want to narrow the bounds as
5492 -- much as permitted by the RM, to give the smallest possible size.
5495 Loval_Incl_EP
: Ureal
;
5496 Hival_Incl_EP
: Ureal
;
5498 Loval_Excl_EP
: Ureal
;
5499 Hival_Excl_EP
: Ureal
;
5505 First_Subt
: Entity_Id
;
5510 -- First step. Base types are required to be symmetrical. Right
5511 -- now, the base type range is a copy of the first subtype range.
5512 -- This will be corrected before we are done, but right away we
5513 -- need to deal with the case where both bounds are non-negative.
5514 -- In this case, we set the low bound to the negative of the high
5515 -- bound, to make sure that the size is computed to include the
5516 -- required sign. Note that we do not need to worry about the
5517 -- case of both bounds negative, because the sign will be dealt
5518 -- with anyway. Furthermore we can't just go making such a bound
5519 -- symmetrical, since in a twos-complement system, there is an
5520 -- extra negative value which could not be accommodated on the
5524 and then not UR_Is_Negative
(Loval
)
5525 and then Hival
> Loval
5528 Set_Realval
(Lo
, Loval
);
5531 -- Compute the fudged bounds. If the number is a model number,
5532 -- then we do nothing to include it, but we are allowed to backoff
5533 -- to the next adjacent model number when we exclude it. If it is
5534 -- not a model number then we straddle the two values with the
5535 -- model numbers on either side.
5537 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
5539 if Loval
= Model_Num
then
5540 Loval_Incl_EP
:= Model_Num
;
5542 Loval_Incl_EP
:= Model_Num
- Small
;
5545 -- The low value excluding the end point is Small greater, but
5546 -- we do not do this exclusion if the low value is positive,
5547 -- since it can't help the size and could actually hurt by
5548 -- crossing the high bound.
5550 if UR_Is_Negative
(Loval_Incl_EP
) then
5551 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
5553 -- If the value went from negative to zero, then we have the
5554 -- case where Loval_Incl_EP is the model number just below
5555 -- zero, so we want to stick to the negative value for the
5556 -- base type to maintain the condition that the size will
5557 -- include signed values.
5560 and then UR_Is_Zero
(Loval_Excl_EP
)
5562 Loval_Excl_EP
:= Loval_Incl_EP
;
5566 Loval_Excl_EP
:= Loval_Incl_EP
;
5569 -- Similar processing for upper bound and high value
5571 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
5573 if Hival
= Model_Num
then
5574 Hival_Incl_EP
:= Model_Num
;
5576 Hival_Incl_EP
:= Model_Num
+ Small
;
5579 if UR_Is_Positive
(Hival_Incl_EP
) then
5580 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
5582 Hival_Excl_EP
:= Hival_Incl_EP
;
5585 -- One further adjustment is needed. In the case of subtypes, we
5586 -- cannot go outside the range of the base type, or we get
5587 -- peculiarities, and the base type range is already set. This
5588 -- only applies to the Incl values, since clearly the Excl values
5589 -- are already as restricted as they are allowed to be.
5592 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
5593 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
5596 -- Get size including and excluding end points
5598 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
5599 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
5601 -- No need to exclude end-points if it does not reduce size
5603 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
5604 Loval_Excl_EP
:= Loval_Incl_EP
;
5607 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
5608 Hival_Excl_EP
:= Hival_Incl_EP
;
5611 -- Now we set the actual size to be used. We want to use the
5612 -- bounds fudged up to include the end-points but only if this
5613 -- can be done without violating a specifically given size
5614 -- size clause or causing an unacceptable increase in size.
5616 -- Case of size clause given
5618 if Has_Size_Clause
(Typ
) then
5620 -- Use the inclusive size only if it is consistent with
5621 -- the explicitly specified size.
5623 if Size_Incl_EP
<= RM_Size
(Typ
) then
5624 Actual_Lo
:= Loval_Incl_EP
;
5625 Actual_Hi
:= Hival_Incl_EP
;
5626 Actual_Size
:= Size_Incl_EP
;
5628 -- If the inclusive size is too large, we try excluding
5629 -- the end-points (will be caught later if does not work).
5632 Actual_Lo
:= Loval_Excl_EP
;
5633 Actual_Hi
:= Hival_Excl_EP
;
5634 Actual_Size
:= Size_Excl_EP
;
5637 -- Case of size clause not given
5640 -- If we have a base type whose corresponding first subtype
5641 -- has an explicit size that is large enough to include our
5642 -- end-points, then do so. There is no point in working hard
5643 -- to get a base type whose size is smaller than the specified
5644 -- size of the first subtype.
5646 First_Subt
:= First_Subtype
(Typ
);
5648 if Has_Size_Clause
(First_Subt
)
5649 and then Size_Incl_EP
<= Esize
(First_Subt
)
5651 Actual_Size
:= Size_Incl_EP
;
5652 Actual_Lo
:= Loval_Incl_EP
;
5653 Actual_Hi
:= Hival_Incl_EP
;
5655 -- If excluding the end-points makes the size smaller and
5656 -- results in a size of 8,16,32,64, then we take the smaller
5657 -- size. For the 64 case, this is compulsory. For the other
5658 -- cases, it seems reasonable. We like to include end points
5659 -- if we can, but not at the expense of moving to the next
5660 -- natural boundary of size.
5662 elsif Size_Incl_EP
/= Size_Excl_EP
5663 and then Addressable
(Size_Excl_EP
)
5665 Actual_Size
:= Size_Excl_EP
;
5666 Actual_Lo
:= Loval_Excl_EP
;
5667 Actual_Hi
:= Hival_Excl_EP
;
5669 -- Otherwise we can definitely include the end points
5672 Actual_Size
:= Size_Incl_EP
;
5673 Actual_Lo
:= Loval_Incl_EP
;
5674 Actual_Hi
:= Hival_Incl_EP
;
5677 -- One pathological case: normally we never fudge a low bound
5678 -- down, since it would seem to increase the size (if it has
5679 -- any effect), but for ranges containing single value, or no
5680 -- values, the high bound can be small too large. Consider:
5682 -- type t is delta 2.0**(-14)
5683 -- range 131072.0 .. 0;
5685 -- That lower bound is *just* outside the range of 32 bits, and
5686 -- does need fudging down in this case. Note that the bounds
5687 -- will always have crossed here, since the high bound will be
5688 -- fudged down if necessary, as in the case of:
5690 -- type t is delta 2.0**(-14)
5691 -- range 131072.0 .. 131072.0;
5693 -- So we detect the situation by looking for crossed bounds,
5694 -- and if the bounds are crossed, and the low bound is greater
5695 -- than zero, we will always back it off by small, since this
5696 -- is completely harmless.
5698 if Actual_Lo
> Actual_Hi
then
5699 if UR_Is_Positive
(Actual_Lo
) then
5700 Actual_Lo
:= Loval_Incl_EP
- Small
;
5701 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
5703 -- And of course, we need to do exactly the same parallel
5704 -- fudge for flat ranges in the negative region.
5706 elsif UR_Is_Negative
(Actual_Hi
) then
5707 Actual_Hi
:= Hival_Incl_EP
+ Small
;
5708 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
5713 Set_Realval
(Lo
, Actual_Lo
);
5714 Set_Realval
(Hi
, Actual_Hi
);
5717 -- For the decimal case, none of this fudging is required, since there
5718 -- are no end-point problems in the decimal case (the end-points are
5719 -- always included).
5722 Actual_Size
:= Fsize
(Loval
, Hival
);
5725 -- At this stage, the actual size has been calculated and the proper
5726 -- required bounds are stored in the low and high bounds.
5728 if Actual_Size
> 64 then
5729 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
5731 ("size required (^) for type& too large, maximum allowed is 64",
5736 -- Check size against explicit given size
5738 if Has_Size_Clause
(Typ
) then
5739 if Actual_Size
> RM_Size
(Typ
) then
5740 Error_Msg_Uint_1
:= RM_Size
(Typ
);
5741 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
5743 ("size given (^) for type& too small, minimum allowed is ^",
5744 Size_Clause
(Typ
), Typ
);
5747 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
5750 -- Increase size to next natural boundary if no size clause given
5753 if Actual_Size
<= 8 then
5755 elsif Actual_Size
<= 16 then
5757 elsif Actual_Size
<= 32 then
5763 Init_Esize
(Typ
, Actual_Size
);
5764 Adjust_Esize_For_Alignment
(Typ
);
5767 -- If we have a base type, then expand the bounds so that they extend to
5768 -- the full width of the allocated size in bits, to avoid junk range
5769 -- checks on intermediate computations.
5771 if Base_Type
(Typ
) = Typ
then
5772 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
5773 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
5776 -- Final step is to reanalyze the bounds using the proper type
5777 -- and set the Corresponding_Integer_Value fields of the literals.
5779 Set_Etype
(Lo
, Empty
);
5780 Set_Analyzed
(Lo
, False);
5783 -- Resolve with universal fixed if the base type, and the base type if
5784 -- it is a subtype. Note we can't resolve the base type with itself,
5785 -- that would be a reference before definition.
5788 Resolve
(Lo
, Universal_Fixed
);
5793 -- Set corresponding integer value for bound
5795 Set_Corresponding_Integer_Value
5796 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
5798 -- Similar processing for high bound
5800 Set_Etype
(Hi
, Empty
);
5801 Set_Analyzed
(Hi
, False);
5805 Resolve
(Hi
, Universal_Fixed
);
5810 Set_Corresponding_Integer_Value
5811 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
5813 -- Set type of range to correspond to bounds
5815 Set_Etype
(Rng
, Etype
(Lo
));
5817 -- Set Esize to calculated size if not set already
5819 if Unknown_Esize
(Typ
) then
5820 Init_Esize
(Typ
, Actual_Size
);
5823 -- Set RM_Size if not already set. If already set, check value
5826 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
5829 if RM_Size
(Typ
) /= Uint_0
then
5830 if RM_Size
(Typ
) < Minsiz
then
5831 Error_Msg_Uint_1
:= RM_Size
(Typ
);
5832 Error_Msg_Uint_2
:= Minsiz
;
5834 ("size given (^) for type& too small, minimum allowed is ^",
5835 Size_Clause
(Typ
), Typ
);
5839 Set_RM_Size
(Typ
, Minsiz
);
5842 end Freeze_Fixed_Point_Type
;
5848 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
5852 Set_Has_Delayed_Freeze
(T
);
5853 L
:= Freeze_Entity
(T
, N
);
5855 if Is_Non_Empty_List
(L
) then
5856 Insert_Actions
(N
, L
);
5860 --------------------------
5861 -- Freeze_Static_Object --
5862 --------------------------
5864 procedure Freeze_Static_Object
(E
: Entity_Id
) is
5866 Cannot_Be_Static
: exception;
5867 -- Exception raised if the type of a static object cannot be made
5868 -- static. This happens if the type depends on non-global objects.
5870 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
5871 -- Called to ensure that an expression used as part of a type definition
5872 -- is statically allocatable, which means that the expression type is
5873 -- statically allocatable, and the expression is either static, or a
5874 -- reference to a library level constant.
5876 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
5877 -- Called to mark a type as static, checking that it is possible
5878 -- to set the type as static. If it is not possible, then the
5879 -- exception Cannot_Be_Static is raised.
5881 -----------------------------
5882 -- Ensure_Expression_Is_SA --
5883 -----------------------------
5885 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
5889 Ensure_Type_Is_SA
(Etype
(N
));
5891 if Is_Static_Expression
(N
) then
5894 elsif Nkind
(N
) = N_Identifier
then
5898 and then Ekind
(Ent
) = E_Constant
5899 and then Is_Library_Level_Entity
(Ent
)
5905 raise Cannot_Be_Static
;
5906 end Ensure_Expression_Is_SA
;
5908 -----------------------
5909 -- Ensure_Type_Is_SA --
5910 -----------------------
5912 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
5917 -- If type is library level, we are all set
5919 if Is_Library_Level_Entity
(Typ
) then
5923 -- We are also OK if the type already marked as statically allocated,
5924 -- which means we processed it before.
5926 if Is_Statically_Allocated
(Typ
) then
5930 -- Mark type as statically allocated
5932 Set_Is_Statically_Allocated
(Typ
);
5934 -- Check that it is safe to statically allocate this type
5936 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
5937 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
5938 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
5940 elsif Is_Array_Type
(Typ
) then
5941 N
:= First_Index
(Typ
);
5942 while Present
(N
) loop
5943 Ensure_Type_Is_SA
(Etype
(N
));
5947 Ensure_Type_Is_SA
(Component_Type
(Typ
));
5949 elsif Is_Access_Type
(Typ
) then
5950 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
5954 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
5957 if T
/= Standard_Void_Type
then
5958 Ensure_Type_Is_SA
(T
);
5961 F
:= First_Formal
(Designated_Type
(Typ
));
5962 while Present
(F
) loop
5963 Ensure_Type_Is_SA
(Etype
(F
));
5969 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
5972 elsif Is_Record_Type
(Typ
) then
5973 C
:= First_Entity
(Typ
);
5974 while Present
(C
) loop
5975 if Ekind
(C
) = E_Discriminant
5976 or else Ekind
(C
) = E_Component
5978 Ensure_Type_Is_SA
(Etype
(C
));
5980 elsif Is_Type
(C
) then
5981 Ensure_Type_Is_SA
(C
);
5987 elsif Ekind
(Typ
) = E_Subprogram_Type
then
5988 Ensure_Type_Is_SA
(Etype
(Typ
));
5990 C
:= First_Formal
(Typ
);
5991 while Present
(C
) loop
5992 Ensure_Type_Is_SA
(Etype
(C
));
5997 raise Cannot_Be_Static
;
5999 end Ensure_Type_Is_SA
;
6001 -- Start of processing for Freeze_Static_Object
6004 Ensure_Type_Is_SA
(Etype
(E
));
6007 when Cannot_Be_Static
=>
6009 -- If the object that cannot be static is imported or exported, then
6010 -- issue an error message saying that this object cannot be imported
6011 -- or exported. If it has an address clause it is an overlay in the
6012 -- current partition and the static requirement is not relevant.
6013 -- Do not issue any error message when ignoring rep clauses.
6015 if Ignore_Rep_Clauses
then
6018 elsif Is_Imported
(E
) then
6019 if No
(Address_Clause
(E
)) then
6021 ("& cannot be imported (local type is not constant)", E
);
6024 -- Otherwise must be exported, something is wrong if compiler
6025 -- is marking something as statically allocated which cannot be).
6027 else pragma Assert
(Is_Exported
(E
));
6029 ("& cannot be exported (local type is not constant)", E
);
6031 end Freeze_Static_Object
;
6033 -----------------------
6034 -- Freeze_Subprogram --
6035 -----------------------
6037 procedure Freeze_Subprogram
(E
: Entity_Id
) is
6042 -- Subprogram may not have an address clause unless it is imported
6044 if Present
(Address_Clause
(E
)) then
6045 if not Is_Imported
(E
) then
6047 ("address clause can only be given " &
6048 "for imported subprogram",
6049 Name
(Address_Clause
(E
)));
6053 -- Reset the Pure indication on an imported subprogram unless an
6054 -- explicit Pure_Function pragma was present. We do this because
6055 -- otherwise it is an insidious error to call a non-pure function from
6056 -- pure unit and have calls mysteriously optimized away. What happens
6057 -- here is that the Import can bypass the normal check to ensure that
6058 -- pure units call only pure subprograms.
6061 and then Is_Pure
(E
)
6062 and then not Has_Pragma_Pure_Function
(E
)
6064 Set_Is_Pure
(E
, False);
6067 -- For non-foreign convention subprograms, this is where we create
6068 -- the extra formals (for accessibility level and constrained bit
6069 -- information). We delay this till the freeze point precisely so
6070 -- that we know the convention!
6072 if not Has_Foreign_Convention
(E
) then
6073 Create_Extra_Formals
(E
);
6076 -- If this is convention Ada and a Valued_Procedure, that's odd
6078 if Ekind
(E
) = E_Procedure
6079 and then Is_Valued_Procedure
(E
)
6080 and then Convention
(E
) = Convention_Ada
6081 and then Warn_On_Export_Import
6084 ("?Valued_Procedure has no effect for convention Ada", E
);
6085 Set_Is_Valued_Procedure
(E
, False);
6088 -- Case of foreign convention
6093 -- For foreign conventions, warn about return of an
6094 -- unconstrained array.
6096 -- Note: we *do* allow a return by descriptor for the VMS case,
6097 -- though here there is probably more to be done ???
6099 if Ekind
(E
) = E_Function
then
6100 Retype
:= Underlying_Type
(Etype
(E
));
6102 -- If no return type, probably some other error, e.g. a
6103 -- missing full declaration, so ignore.
6108 -- If the return type is generic, we have emitted a warning
6109 -- earlier on, and there is nothing else to check here. Specific
6110 -- instantiations may lead to erroneous behavior.
6112 elsif Is_Generic_Type
(Etype
(E
)) then
6115 -- Display warning if returning unconstrained array
6117 elsif Is_Array_Type
(Retype
)
6118 and then not Is_Constrained
(Retype
)
6120 -- Exclude cases where descriptor mechanism is set, since the
6121 -- VMS descriptor mechanisms allow such unconstrained returns.
6123 and then Mechanism
(E
) not in Descriptor_Codes
6125 -- Check appropriate warning is enabled (should we check for
6126 -- Warnings (Off) on specific entities here, probably so???)
6128 and then Warn_On_Export_Import
6130 -- Exclude the VM case, since return of unconstrained arrays
6131 -- is properly handled in both the JVM and .NET cases.
6133 and then VM_Target
= No_VM
6136 ("?foreign convention function& should not return " &
6137 "unconstrained array", E
);
6142 -- If any of the formals for an exported foreign convention
6143 -- subprogram have defaults, then emit an appropriate warning since
6144 -- this is odd (default cannot be used from non-Ada code)
6146 if Is_Exported
(E
) then
6147 F
:= First_Formal
(E
);
6148 while Present
(F
) loop
6149 if Warn_On_Export_Import
6150 and then Present
(Default_Value
(F
))
6153 ("?parameter cannot be defaulted in non-Ada call",
6162 -- For VMS, descriptor mechanisms for parameters are allowed only for
6163 -- imported/exported subprograms. Moreover, the NCA descriptor is not
6164 -- allowed for parameters of exported subprograms.
6166 if OpenVMS_On_Target
then
6167 if Is_Exported
(E
) then
6168 F
:= First_Formal
(E
);
6169 while Present
(F
) loop
6170 if Mechanism
(F
) = By_Descriptor_NCA
then
6172 ("'N'C'A' descriptor for parameter not permitted", F
);
6174 ("\can only be used for imported subprogram", F
);
6180 elsif not Is_Imported
(E
) then
6181 F
:= First_Formal
(E
);
6182 while Present
(F
) loop
6183 if Mechanism
(F
) in Descriptor_Codes
then
6185 ("descriptor mechanism for parameter not permitted", F
);
6187 ("\can only be used for imported/exported subprogram", F
);
6195 -- Pragma Inline_Always is disallowed for dispatching subprograms
6196 -- because the address of such subprograms is saved in the dispatch
6197 -- table to support dispatching calls, and dispatching calls cannot
6198 -- be inlined. This is consistent with the restriction against using
6199 -- 'Access or 'Address on an Inline_Always subprogram.
6201 if Is_Dispatching_Operation
(E
)
6202 and then Has_Pragma_Inline_Always
(E
)
6205 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
6208 -- Because of the implicit representation of inherited predefined
6209 -- operators in the front-end, the overriding status of the operation
6210 -- may be affected when a full view of a type is analyzed, and this is
6211 -- not captured by the analysis of the corresponding type declaration.
6212 -- Therefore the correctness of a not-overriding indicator must be
6213 -- rechecked when the subprogram is frozen.
6215 if Nkind
(E
) = N_Defining_Operator_Symbol
6216 and then not Error_Posted
(Parent
(E
))
6218 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
6220 end Freeze_Subprogram
;
6222 ----------------------
6223 -- Is_Fully_Defined --
6224 ----------------------
6226 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
6228 if Ekind
(T
) = E_Class_Wide_Type
then
6229 return Is_Fully_Defined
(Etype
(T
));
6231 elsif Is_Array_Type
(T
) then
6232 return Is_Fully_Defined
(Component_Type
(T
));
6234 elsif Is_Record_Type
(T
)
6235 and not Is_Private_Type
(T
)
6237 -- Verify that the record type has no components with private types
6238 -- without completion.
6244 Comp
:= First_Component
(T
);
6245 while Present
(Comp
) loop
6246 if not Is_Fully_Defined
(Etype
(Comp
)) then
6250 Next_Component
(Comp
);
6255 -- For the designated type of an access to subprogram, all types in
6256 -- the profile must be fully defined.
6258 elsif Ekind
(T
) = E_Subprogram_Type
then
6263 F
:= First_Formal
(T
);
6264 while Present
(F
) loop
6265 if not Is_Fully_Defined
(Etype
(F
)) then
6272 return Is_Fully_Defined
(Etype
(T
));
6276 return not Is_Private_Type
(T
)
6277 or else Present
(Full_View
(Base_Type
(T
)));
6279 end Is_Fully_Defined
;
6281 ---------------------------------
6282 -- Process_Default_Expressions --
6283 ---------------------------------
6285 procedure Process_Default_Expressions
6287 After
: in out Node_Id
)
6289 Loc
: constant Source_Ptr
:= Sloc
(E
);
6296 Set_Default_Expressions_Processed
(E
);
6298 -- A subprogram instance and its associated anonymous subprogram share
6299 -- their signature. The default expression functions are defined in the
6300 -- wrapper packages for the anonymous subprogram, and should not be
6301 -- generated again for the instance.
6303 if Is_Generic_Instance
(E
)
6304 and then Present
(Alias
(E
))
6305 and then Default_Expressions_Processed
(Alias
(E
))
6310 Formal
:= First_Formal
(E
);
6311 while Present
(Formal
) loop
6312 if Present
(Default_Value
(Formal
)) then
6314 -- We work with a copy of the default expression because we
6315 -- do not want to disturb the original, since this would mess
6316 -- up the conformance checking.
6318 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
6320 -- The analysis of the expression may generate insert actions,
6321 -- which of course must not be executed. We wrap those actions
6322 -- in a procedure that is not called, and later on eliminated.
6323 -- The following cases have no side-effects, and are analyzed
6326 if Nkind
(Dcopy
) = N_Identifier
6327 or else Nkind
(Dcopy
) = N_Expanded_Name
6328 or else Nkind
(Dcopy
) = N_Integer_Literal
6329 or else (Nkind
(Dcopy
) = N_Real_Literal
6330 and then not Vax_Float
(Etype
(Dcopy
)))
6331 or else Nkind
(Dcopy
) = N_Character_Literal
6332 or else Nkind
(Dcopy
) = N_String_Literal
6333 or else Known_Null
(Dcopy
)
6334 or else (Nkind
(Dcopy
) = N_Attribute_Reference
6336 Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
6339 -- If there is no default function, we must still do a full
6340 -- analyze call on the default value, to ensure that all error
6341 -- checks are performed, e.g. those associated with static
6342 -- evaluation. Note: this branch will always be taken if the
6343 -- analyzer is turned off (but we still need the error checks).
6345 -- Note: the setting of parent here is to meet the requirement
6346 -- that we can only analyze the expression while attached to
6347 -- the tree. Really the requirement is that the parent chain
6348 -- be set, we don't actually need to be in the tree.
6350 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
6353 -- Default expressions are resolved with their own type if the
6354 -- context is generic, to avoid anomalies with private types.
6356 if Ekind
(Scope
(E
)) = E_Generic_Package
then
6359 Resolve
(Dcopy
, Etype
(Formal
));
6362 -- If that resolved expression will raise constraint error,
6363 -- then flag the default value as raising constraint error.
6364 -- This allows a proper error message on the calls.
6366 if Raises_Constraint_Error
(Dcopy
) then
6367 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
6370 -- If the default is a parameterless call, we use the name of
6371 -- the called function directly, and there is no body to build.
6373 elsif Nkind
(Dcopy
) = N_Function_Call
6374 and then No
(Parameter_Associations
(Dcopy
))
6378 -- Else construct and analyze the body of a wrapper procedure
6379 -- that contains an object declaration to hold the expression.
6380 -- Given that this is done only to complete the analysis, it
6381 -- simpler to build a procedure than a function which might
6382 -- involve secondary stack expansion.
6385 Dnam
:= Make_Temporary
(Loc
, 'D');
6388 Make_Subprogram_Body
(Loc
,
6390 Make_Procedure_Specification
(Loc
,
6391 Defining_Unit_Name
=> Dnam
),
6393 Declarations
=> New_List
(
6394 Make_Object_Declaration
(Loc
,
6395 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
6396 Object_Definition
=>
6397 New_Occurrence_Of
(Etype
(Formal
), Loc
),
6398 Expression
=> New_Copy_Tree
(Dcopy
))),
6400 Handled_Statement_Sequence
=>
6401 Make_Handled_Sequence_Of_Statements
(Loc
,
6402 Statements
=> Empty_List
));
6404 Set_Scope
(Dnam
, Scope
(E
));
6405 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
6406 Set_Is_Eliminated
(Dnam
);
6407 Insert_After
(After
, Dbody
);
6413 Next_Formal
(Formal
);
6415 end Process_Default_Expressions
;
6417 ----------------------------------------
6418 -- Set_Component_Alignment_If_Not_Set --
6419 ----------------------------------------
6421 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
6423 -- Ignore if not base type, subtypes don't need anything
6425 if Typ
/= Base_Type
(Typ
) then
6429 -- Do not override existing representation
6431 if Is_Packed
(Typ
) then
6434 elsif Has_Specified_Layout
(Typ
) then
6437 elsif Component_Alignment
(Typ
) /= Calign_Default
then
6441 Set_Component_Alignment
6442 (Typ
, Scope_Stack
.Table
6443 (Scope_Stack
.Last
).Component_Alignment_Default
);
6445 end Set_Component_Alignment_If_Not_Set
;
6451 procedure Undelay_Type
(T
: Entity_Id
) is
6453 Set_Has_Delayed_Freeze
(T
, False);
6454 Set_Freeze_Node
(T
, Empty
);
6456 -- Since we don't want T to have a Freeze_Node, we don't want its
6457 -- Full_View or Corresponding_Record_Type to have one either.
6459 -- ??? Fundamentally, this whole handling is a kludge. What we really
6460 -- want is to be sure that for an Itype that's part of record R and is a
6461 -- subtype of type T, that it's frozen after the later of the freeze
6462 -- points of R and T. We have no way of doing that directly, so what we
6463 -- do is force most such Itypes to be frozen as part of freezing R via
6464 -- this procedure and only delay the ones that need to be delayed
6465 -- (mostly the designated types of access types that are defined as part
6468 if Is_Private_Type
(T
)
6469 and then Present
(Full_View
(T
))
6470 and then Is_Itype
(Full_View
(T
))
6471 and then Is_Record_Type
(Scope
(Full_View
(T
)))
6473 Undelay_Type
(Full_View
(T
));
6476 if Is_Concurrent_Type
(T
)
6477 and then Present
(Corresponding_Record_Type
(T
))
6478 and then Is_Itype
(Corresponding_Record_Type
(T
))
6479 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
6481 Undelay_Type
(Corresponding_Record_Type
(T
));
6489 procedure Warn_Overlay
6494 Ent
: constant Entity_Id
:= Entity
(Nam
);
6495 -- The object to which the address clause applies
6498 Old
: Entity_Id
:= Empty
;
6502 -- No warning if address clause overlay warnings are off
6504 if not Address_Clause_Overlay_Warnings
then
6508 -- No warning if there is an explicit initialization
6510 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
6512 if Present
(Init
) and then Comes_From_Source
(Init
) then
6516 -- We only give the warning for non-imported entities of a type for
6517 -- which a non-null base init proc is defined, or for objects of access
6518 -- types with implicit null initialization, or when Normalize_Scalars
6519 -- applies and the type is scalar or a string type (the latter being
6520 -- tested for because predefined String types are initialized by inline
6521 -- code rather than by an init_proc). Note that we do not give the
6522 -- warning for Initialize_Scalars, since we suppressed initialization
6523 -- in this case. Also, do not warn if Suppress_Initialization is set.
6526 and then not Is_Imported
(Ent
)
6527 and then not Initialization_Suppressed
(Typ
)
6528 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
6529 or else Is_Access_Type
(Typ
)
6530 or else (Normalize_Scalars
6531 and then (Is_Scalar_Type
(Typ
)
6532 or else Is_String_Type
(Typ
))))
6534 if Nkind
(Expr
) = N_Attribute_Reference
6535 and then Is_Entity_Name
(Prefix
(Expr
))
6537 Old
:= Entity
(Prefix
(Expr
));
6539 elsif Is_Entity_Name
(Expr
)
6540 and then Ekind
(Entity
(Expr
)) = E_Constant
6542 Decl
:= Declaration_Node
(Entity
(Expr
));
6544 if Nkind
(Decl
) = N_Object_Declaration
6545 and then Present
(Expression
(Decl
))
6546 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
6547 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
6549 Old
:= Entity
(Prefix
(Expression
(Decl
)));
6551 elsif Nkind
(Expr
) = N_Function_Call
then
6555 -- A function call (most likely to To_Address) is probably not an
6556 -- overlay, so skip warning. Ditto if the function call was inlined
6557 -- and transformed into an entity.
6559 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
6563 Decl
:= Next
(Parent
(Expr
));
6565 -- If a pragma Import follows, we assume that it is for the current
6566 -- target of the address clause, and skip the warning.
6569 and then Nkind
(Decl
) = N_Pragma
6570 and then Pragma_Name
(Decl
) = Name_Import
6575 if Present
(Old
) then
6576 Error_Msg_Node_2
:= Old
;
6578 ("default initialization of & may modify &?",
6582 ("default initialization of & may modify overlaid storage?",
6586 -- Add friendly warning if initialization comes from a packed array
6589 if Is_Record_Type
(Typ
) then
6594 Comp
:= First_Component
(Typ
);
6595 while Present
(Comp
) loop
6596 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
6597 and then Present
(Expression
(Parent
(Comp
)))
6600 elsif Is_Array_Type
(Etype
(Comp
))
6601 and then Present
(Packed_Array_Type
(Etype
(Comp
)))
6604 ("\packed array component& " &
6605 "will be initialized to zero?",
6609 Next_Component
(Comp
);
6616 ("\use pragma Import for & to " &
6617 "suppress initialization (RM B.1(24))?",