1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Ch3
; use Exp_Ch3
;
34 with Exp_Ch7
; use Exp_Ch7
;
35 with Exp_Disp
; use Exp_Disp
;
36 with Exp_Pakd
; use Exp_Pakd
;
37 with Exp_Util
; use Exp_Util
;
38 with Exp_Tss
; use Exp_Tss
;
39 with Layout
; use Layout
;
41 with Namet
; use Namet
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
49 with Sem_Aux
; use Sem_Aux
;
50 with Sem_Cat
; use Sem_Cat
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch7
; use Sem_Ch7
;
53 with Sem_Ch8
; use Sem_Ch8
;
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
;
68 with Warnsw
; use Warnsw
;
70 package body Freeze
is
72 -----------------------
73 -- Local Subprograms --
74 -----------------------
76 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
);
77 -- Typ is a type that is being frozen. If no size clause is given,
78 -- but a default Esize has been computed, then this default Esize is
79 -- adjusted up if necessary to be consistent with a given alignment,
80 -- but never to a value greater than Long_Long_Integer'Size. This
81 -- is used for all discrete types and for fixed-point types.
83 procedure Build_And_Analyze_Renamed_Body
86 After
: in out Node_Id
);
87 -- Build body for a renaming declaration, insert in tree and analyze
89 procedure Check_Address_Clause
(E
: Entity_Id
);
90 -- Apply legality checks to address clauses for object declarations,
91 -- at the point the object is frozen. Also ensure any initialization is
92 -- performed only after the object has been frozen.
94 procedure Check_Component_Storage_Order
95 (Encl_Type
: Entity_Id
;
98 Comp_ADC_Present
: out Boolean);
99 -- For an Encl_Type that has a Scalar_Storage_Order attribute definition
100 -- clause, verify that the component type has an explicit and compatible
101 -- attribute/aspect. For arrays, Comp is Empty; for records, it is the
102 -- entity of the component under consideration. For an Encl_Type that
103 -- does not have a Scalar_Storage_Order attribute definition clause,
104 -- verify that the component also does not have such a clause.
105 -- ADC is the attribute definition clause if present (or Empty). On return,
106 -- Comp_ADC_Present is set True if the component has a Scalar_Storage_Order
107 -- attribute definition clause.
109 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
);
110 -- When an expression function is frozen by a use of it, the expression
111 -- itself is frozen. Check that the expression does not include references
112 -- to deferred constants without completion. We report this at the freeze
113 -- point of the function, to provide a better error message.
115 -- In most cases the expression itself is frozen by the time the function
116 -- itself is frozen, because the formals will be frozen by then. However,
117 -- Attribute references to outer types are freeze points for those types;
118 -- this routine generates the required freeze nodes for them.
120 procedure Check_Strict_Alignment
(E
: Entity_Id
);
121 -- E is a base type. If E is tagged or has a component that is aliased
122 -- or tagged or contains something this is aliased or tagged, set
125 procedure Check_Unsigned_Type
(E
: Entity_Id
);
126 pragma Inline
(Check_Unsigned_Type
);
127 -- If E is a fixed-point or discrete type, then all the necessary work
128 -- to freeze it is completed except for possible setting of the flag
129 -- Is_Unsigned_Type, which is done by this procedure. The call has no
130 -- effect if the entity E is not a discrete or fixed-point type.
132 procedure Freeze_And_Append
135 Result
: in out List_Id
);
136 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
137 -- nodes to Result, modifying Result from No_List if necessary. N has
138 -- the same usage as in Freeze_Entity.
140 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
141 -- Freeze enumeration type. The Esize field is set as processing
142 -- proceeds (i.e. set by default when the type is declared and then
143 -- adjusted by rep clauses. What this procedure does is to make sure
144 -- that if a foreign convention is specified, and no specific size
145 -- is given, then the size must be at least Integer'Size.
147 procedure Freeze_Static_Object
(E
: Entity_Id
);
148 -- If an object is frozen which has Is_Statically_Allocated set, then
149 -- all referenced types must also be marked with this flag. This routine
150 -- is in charge of meeting this requirement for the object entity E.
152 procedure Freeze_Subprogram
(E
: Entity_Id
);
153 -- Perform freezing actions for a subprogram (create extra formals,
154 -- and set proper default mechanism values). Note that this routine
155 -- is not called for internal subprograms, for which neither of these
156 -- actions is needed (or desirable, we do not want for example to have
157 -- these extra formals present in initialization procedures, where they
158 -- would serve no purpose). In this call E is either a subprogram or
159 -- a subprogram type (i.e. an access to a subprogram).
161 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
162 -- True if T is not private and has no private components, or has a full
163 -- view. Used to determine whether the designated type of an access type
164 -- should be frozen when the access type is frozen. This is done when an
165 -- allocator is frozen, or an expression that may involve attributes of
166 -- the designated type. Otherwise freezing the access type does not freeze
167 -- the designated type.
169 procedure Process_Default_Expressions
171 After
: in out Node_Id
);
172 -- This procedure is called for each subprogram to complete processing of
173 -- default expressions at the point where all types are known to be frozen.
174 -- The expressions must be analyzed in full, to make sure that all error
175 -- processing is done (they have only been pre-analyzed). If the expression
176 -- is not an entity or literal, its analysis may generate code which must
177 -- not be executed. In that case we build a function body to hold that
178 -- code. This wrapper function serves no other purpose (it used to be
179 -- called to evaluate the default, but now the default is inlined at each
182 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
183 -- Typ is a record or array type that is being frozen. This routine sets
184 -- the default component alignment from the scope stack values if the
185 -- alignment is otherwise not specified.
187 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
188 -- As each entity is frozen, this routine is called to deal with the
189 -- setting of Debug_Info_Needed for the entity. This flag is set if
190 -- the entity comes from source, or if we are in Debug_Generated_Code
191 -- mode or if the -gnatdV debug flag is set. However, it never sets
192 -- the flag if Debug_Info_Off is set. This procedure also ensures that
193 -- subsidiary entities have the flag set as required.
195 procedure Set_SSO_From_Default
(T
: Entity_Id
);
196 -- T is a record or array type that is being frozen. If it is a base type,
197 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
198 -- will be set appropriately. Note that an explicit occurrence of aspect
199 -- Scalar_Storage_Order or an explicit setting of this aspect with an
200 -- attribute definition clause occurs, then these two flags are reset in
201 -- any case, so call will have no effect.
203 procedure Undelay_Type
(T
: Entity_Id
);
204 -- T is a type of a component that we know to be an Itype. We don't want
205 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
206 -- Full_View or Corresponding_Record_Type.
208 procedure Warn_Overlay
212 -- Expr is the expression for an address clause for entity Nam whose type
213 -- is Typ. If Typ has a default initialization, and there is no explicit
214 -- initialization in the source declaration, check whether the address
215 -- clause might cause overlaying of an entity, and emit a warning on the
216 -- side effect that the initialization will cause.
218 -------------------------------
219 -- Adjust_Esize_For_Alignment --
220 -------------------------------
222 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
226 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
227 Align
:= Alignment_In_Bits
(Typ
);
229 if Align
> Esize
(Typ
)
230 and then Align
<= Standard_Long_Long_Integer_Size
232 Set_Esize
(Typ
, Align
);
235 end Adjust_Esize_For_Alignment
;
237 ------------------------------------
238 -- Build_And_Analyze_Renamed_Body --
239 ------------------------------------
241 procedure Build_And_Analyze_Renamed_Body
244 After
: in out Node_Id
)
246 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
247 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
249 Renamed_Subp
: Entity_Id
;
252 -- If the renamed subprogram is intrinsic, there is no need for a
253 -- wrapper body: we set the alias that will be called and expanded which
254 -- completes the declaration. This transformation is only legal if the
255 -- renamed entity has already been elaborated.
257 -- Note that it is legal for a renaming_as_body to rename an intrinsic
258 -- subprogram, as long as the renaming occurs before the new entity
259 -- is frozen (RM 8.5.4 (5)).
261 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
262 and then Is_Entity_Name
(Name
(Body_Decl
))
264 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
266 Renamed_Subp
:= Empty
;
269 if Present
(Renamed_Subp
)
270 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
272 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
273 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
275 -- We can make the renaming entity intrinsic if the renamed function
276 -- has an interface name, or if it is one of the shift/rotate
277 -- operations known to the compiler.
280 (Present
(Interface_Name
(Renamed_Subp
))
281 or else Nam_In
(Chars
(Renamed_Subp
), Name_Rotate_Left
,
285 Name_Shift_Right_Arithmetic
))
287 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
289 if Present
(Alias
(Renamed_Subp
)) then
290 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
292 Set_Alias
(Ent
, Renamed_Subp
);
295 Set_Is_Intrinsic_Subprogram
(Ent
);
296 Set_Has_Completion
(Ent
);
299 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
300 Insert_After
(After
, Body_Node
);
301 Mark_Rewrite_Insertion
(Body_Node
);
305 end Build_And_Analyze_Renamed_Body
;
307 ------------------------
308 -- Build_Renamed_Body --
309 ------------------------
311 function Build_Renamed_Body
313 New_S
: Entity_Id
) return Node_Id
315 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
316 -- We use for the source location of the renamed body, the location of
317 -- the spec entity. It might seem more natural to use the location of
318 -- the renaming declaration itself, but that would be wrong, since then
319 -- the body we create would look as though it was created far too late,
320 -- and this could cause problems with elaboration order analysis,
321 -- particularly in connection with instantiations.
323 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
324 Nam
: constant Node_Id
:= Name
(N
);
326 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
327 Actuals
: List_Id
:= No_List
;
332 O_Formal
: Entity_Id
;
333 Param_Spec
: Node_Id
;
335 Pref
: Node_Id
:= Empty
;
336 -- If the renamed entity is a primitive operation given in prefix form,
337 -- the prefix is the target object and it has to be added as the first
338 -- actual in the generated call.
341 -- Determine the entity being renamed, which is the target of the call
342 -- statement. If the name is an explicit dereference, this is a renaming
343 -- of a subprogram type rather than a subprogram. The name itself is
346 if Nkind
(Nam
) = N_Selected_Component
then
347 Old_S
:= Entity
(Selector_Name
(Nam
));
349 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
350 Old_S
:= Etype
(Nam
);
352 elsif Nkind
(Nam
) = N_Indexed_Component
then
353 if Is_Entity_Name
(Prefix
(Nam
)) then
354 Old_S
:= Entity
(Prefix
(Nam
));
356 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
359 elsif Nkind
(Nam
) = N_Character_Literal
then
360 Old_S
:= Etype
(New_S
);
363 Old_S
:= Entity
(Nam
);
366 if Is_Entity_Name
(Nam
) then
368 -- If the renamed entity is a predefined operator, retain full name
369 -- to ensure its visibility.
371 if Ekind
(Old_S
) = E_Operator
372 and then Nkind
(Nam
) = N_Expanded_Name
374 Call_Name
:= New_Copy
(Name
(N
));
376 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
380 if Nkind
(Nam
) = N_Selected_Component
381 and then Present
(First_Formal
(Old_S
))
383 (Is_Controlling_Formal
(First_Formal
(Old_S
))
384 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
387 -- Retrieve the target object, to be added as a first actual
390 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
391 Pref
:= Prefix
(Nam
);
394 Call_Name
:= New_Copy
(Name
(N
));
397 -- Original name may have been overloaded, but is fully resolved now
399 Set_Is_Overloaded
(Call_Name
, False);
402 -- For simple renamings, subsequent calls can be expanded directly as
403 -- calls to the renamed entity. The body must be generated in any case
404 -- for calls that may appear elsewhere. This is not done in the case
405 -- where the subprogram is an instantiation because the actual proper
406 -- body has not been built yet.
408 if Ekind_In
(Old_S
, E_Function
, E_Procedure
)
409 and then Nkind
(Decl
) = N_Subprogram_Declaration
410 and then not Is_Generic_Instance
(Old_S
)
412 Set_Body_To_Inline
(Decl
, Old_S
);
415 -- The body generated for this renaming is an internal artifact, and
416 -- does not constitute a freeze point for the called entity.
418 Set_Must_Not_Freeze
(Call_Name
);
420 Formal
:= First_Formal
(Defining_Entity
(Decl
));
422 if Present
(Pref
) then
424 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
425 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
428 -- The controlling formal may be an access parameter, or the
429 -- actual may be an access value, so adjust accordingly.
431 if Is_Access_Type
(Pref_Type
)
432 and then not Is_Access_Type
(Form_Type
)
435 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
437 elsif Is_Access_Type
(Form_Type
)
438 and then not Is_Access_Type
(Pref
)
441 (Make_Attribute_Reference
(Loc
,
442 Attribute_Name
=> Name_Access
,
443 Prefix
=> Relocate_Node
(Pref
)));
445 Actuals
:= New_List
(Pref
);
449 elsif Present
(Formal
) then
456 if Present
(Formal
) then
457 while Present
(Formal
) loop
458 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
459 Next_Formal
(Formal
);
463 -- If the renamed entity is an entry, inherit its profile. For other
464 -- renamings as bodies, both profiles must be subtype conformant, so it
465 -- is not necessary to replace the profile given in the declaration.
466 -- However, default values that are aggregates are rewritten when
467 -- partially analyzed, so we recover the original aggregate to insure
468 -- that subsequent conformity checking works. Similarly, if the default
469 -- expression was constant-folded, recover the original expression.
471 Formal
:= First_Formal
(Defining_Entity
(Decl
));
473 if Present
(Formal
) then
474 O_Formal
:= First_Formal
(Old_S
);
475 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
476 while Present
(Formal
) loop
477 if Is_Entry
(Old_S
) then
478 if Nkind
(Parameter_Type
(Param_Spec
)) /=
481 Set_Etype
(Formal
, Etype
(O_Formal
));
482 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
485 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
486 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
487 Nkind
(Default_Value
(O_Formal
))
489 Set_Expression
(Param_Spec
,
490 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
493 Next_Formal
(Formal
);
494 Next_Formal
(O_Formal
);
499 -- If the renamed entity is a function, the generated body contains a
500 -- return statement. Otherwise, build a procedure call. If the entity is
501 -- an entry, subsequent analysis of the call will transform it into the
502 -- proper entry or protected operation call. If the renamed entity is
503 -- a character literal, return it directly.
505 if Ekind
(Old_S
) = E_Function
506 or else Ekind
(Old_S
) = E_Operator
507 or else (Ekind
(Old_S
) = E_Subprogram_Type
508 and then Etype
(Old_S
) /= Standard_Void_Type
)
511 Make_Simple_Return_Statement
(Loc
,
513 Make_Function_Call
(Loc
,
515 Parameter_Associations
=> Actuals
));
517 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
519 Make_Simple_Return_Statement
(Loc
,
520 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
522 elsif Nkind
(Nam
) = N_Character_Literal
then
524 Make_Simple_Return_Statement
(Loc
,
525 Expression
=> Call_Name
);
529 Make_Procedure_Call_Statement
(Loc
,
531 Parameter_Associations
=> Actuals
);
534 -- Create entities for subprogram body and formals
536 Set_Defining_Unit_Name
(Spec
,
537 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
539 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
540 while Present
(Param_Spec
) loop
541 Set_Defining_Identifier
(Param_Spec
,
542 Make_Defining_Identifier
(Loc
,
543 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
548 Make_Subprogram_Body
(Loc
,
549 Specification
=> Spec
,
550 Declarations
=> New_List
,
551 Handled_Statement_Sequence
=>
552 Make_Handled_Sequence_Of_Statements
(Loc
,
553 Statements
=> New_List
(Call_Node
)));
555 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
557 Make_Subprogram_Declaration
(Loc
,
558 Specification
=> Specification
(N
)));
561 -- Link the body to the entity whose declaration it completes. If
562 -- the body is analyzed when the renamed entity is frozen, it may
563 -- be necessary to restore the proper scope (see package Exp_Ch13).
565 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
566 and then Present
(Corresponding_Spec
(N
))
568 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
570 Set_Corresponding_Spec
(Body_Node
, New_S
);
574 end Build_Renamed_Body
;
576 --------------------------
577 -- Check_Address_Clause --
578 --------------------------
580 procedure Check_Address_Clause
(E
: Entity_Id
) is
581 Addr
: constant Node_Id
:= Address_Clause
(E
);
583 Decl
: constant Node_Id
:= Declaration_Node
(E
);
584 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
585 Typ
: constant Entity_Id
:= Etype
(E
);
587 Tag_Assign
: Node_Id
;
590 if Present
(Addr
) then
591 Expr
:= Expression
(Addr
);
593 if Needs_Constant_Address
(Decl
, Typ
) then
594 Check_Constant_Address_Clause
(Expr
, E
);
596 -- Has_Delayed_Freeze was set on E when the address clause was
597 -- analyzed, and must remain set because we want the address
598 -- clause to be elaborated only after any entity it references
599 -- has been elaborated.
602 -- If Rep_Clauses are to be ignored, remove address clause from
603 -- list attached to entity, because it may be illegal for gigi,
604 -- for example by breaking order of elaboration..
606 if Ignore_Rep_Clauses
then
611 Rep
:= First_Rep_Item
(E
);
614 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
618 and then Next_Rep_Item
(Rep
) /= Addr
620 Rep
:= Next_Rep_Item
(Rep
);
624 if Present
(Rep
) then
625 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
629 -- And now remove the address clause
631 Kill_Rep_Clause
(Addr
);
633 elsif not Error_Posted
(Expr
)
634 and then not Needs_Finalization
(Typ
)
636 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
639 if Present
(Expression
(Decl
)) then
641 -- Capture initialization value at point of declaration,
642 -- and make explicit assignment legal, because object may
645 Remove_Side_Effects
(Expression
(Decl
));
646 Lhs
:= New_Occurrence_Of
(E
, Loc
);
647 Set_Assignment_OK
(Lhs
);
649 -- Move initialization to freeze actions (once the object has
650 -- been frozen, and the address clause alignment check has been
653 Append_Freeze_Action
(E
,
654 Make_Assignment_Statement
(Loc
,
656 Expression
=> Expression
(Decl
)));
658 Set_No_Initialization
(Decl
);
660 -- If the objet is tagged, check whether the tag must be
661 -- reassigned expliitly.
663 Tag_Assign
:= Make_Tag_Assignment
(Decl
);
664 if Present
(Tag_Assign
) then
665 Append_Freeze_Action
(E
, Tag_Assign
);
669 end Check_Address_Clause
;
671 -----------------------------
672 -- Check_Compile_Time_Size --
673 -----------------------------
675 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
677 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
678 -- Sets the compile time known size (32 bits or less) in the Esize
679 -- field, of T checking for a size clause that was given which attempts
680 -- to give a smaller size, and also checking for an alignment clause.
682 function Size_Known
(T
: Entity_Id
) return Boolean;
683 -- Recursive function that does all the work
685 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
686 -- If T is a constrained subtype, its size is not known if any of its
687 -- discriminant constraints is not static and it is not a null record.
688 -- The test is conservative and doesn't check that the components are
689 -- in fact constrained by non-static discriminant values. Could be made
696 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
701 -- Check for bad size clause given
703 elsif Has_Size_Clause
(T
) then
704 if RM_Size
(T
) < S
then
705 Error_Msg_Uint_1
:= S
;
707 ("size for& too small, minimum allowed is ^",
711 -- Set size if not set already
713 elsif Unknown_RM_Size
(T
) then
722 function Size_Known
(T
: Entity_Id
) return Boolean is
730 if Size_Known_At_Compile_Time
(T
) then
733 -- Always True for scalar types. This is true even for generic formal
734 -- scalar types. We used to return False in the latter case, but the
735 -- size is known at compile time, even in the template, we just do
736 -- not know the exact size but that's not the point of this routine.
738 elsif Is_Scalar_Type
(T
)
739 or else Is_Task_Type
(T
)
745 elsif Is_Array_Type
(T
) then
747 -- String literals always have known size, and we can set it
749 if Ekind
(T
) = E_String_Literal_Subtype
then
750 Set_Small_Size
(T
, Component_Size
(T
)
751 * String_Literal_Length
(T
));
754 -- Unconstrained types never have known at compile time size
756 elsif not Is_Constrained
(T
) then
759 -- Don't do any recursion on type with error posted, since we may
760 -- have a malformed type that leads us into a loop.
762 elsif Error_Posted
(T
) then
765 -- Otherwise if component size unknown, then array size unknown
767 elsif not Size_Known
(Component_Type
(T
)) then
771 -- Check for all indexes static, and also compute possible size
772 -- (in case it is less than 32 and may be packable).
775 Esiz
: Uint
:= Component_Size
(T
);
779 Index
:= First_Index
(T
);
780 while Present
(Index
) loop
781 if Nkind
(Index
) = N_Range
then
782 Get_Index_Bounds
(Index
, Low
, High
);
784 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
788 Low
:= Type_Low_Bound
(Etype
(Index
));
789 High
:= Type_High_Bound
(Etype
(Index
));
792 if not Compile_Time_Known_Value
(Low
)
793 or else not Compile_Time_Known_Value
(High
)
794 or else Etype
(Index
) = Any_Type
799 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
811 Set_Small_Size
(T
, Esiz
);
815 -- Access types always have known at compile time sizes
817 elsif Is_Access_Type
(T
) then
820 -- For non-generic private types, go to underlying type if present
822 elsif Is_Private_Type
(T
)
823 and then not Is_Generic_Type
(T
)
824 and then Present
(Underlying_Type
(T
))
826 -- Don't do any recursion on type with error posted, since we may
827 -- have a malformed type that leads us into a loop.
829 if Error_Posted
(T
) then
832 return Size_Known
(Underlying_Type
(T
));
837 elsif Is_Record_Type
(T
) then
839 -- A class-wide type is never considered to have a known size
841 if Is_Class_Wide_Type
(T
) then
844 -- A subtype of a variant record must not have non-static
845 -- discriminated components.
847 elsif T
/= Base_Type
(T
)
848 and then not Static_Discriminated_Components
(T
)
852 -- Don't do any recursion on type with error posted, since we may
853 -- have a malformed type that leads us into a loop.
855 elsif Error_Posted
(T
) then
859 -- Now look at the components of the record
862 -- The following two variables are used to keep track of the
863 -- size of packed records if we can tell the size of the packed
864 -- record in the front end. Packed_Size_Known is True if so far
865 -- we can figure out the size. It is initialized to True for a
866 -- packed record, unless the record has discriminants or atomic
867 -- components or independent components.
869 -- The reason we eliminate the discriminated case is that
870 -- we don't know the way the back end lays out discriminated
871 -- packed records. If Packed_Size_Known is True, then
872 -- Packed_Size is the size in bits so far.
874 Packed_Size_Known
: Boolean :=
876 and then not Has_Discriminants
(T
)
877 and then not Has_Atomic_Components
(T
)
878 and then not Has_Independent_Components
(T
);
880 Packed_Size
: Uint
:= Uint_0
;
881 -- Size in bits so far
884 -- Test for variant part present
886 if Has_Discriminants
(T
)
887 and then Present
(Parent
(T
))
888 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
889 and then Nkind
(Type_Definition
(Parent
(T
))) =
891 and then not Null_Present
(Type_Definition
(Parent
(T
)))
893 Present
(Variant_Part
894 (Component_List
(Type_Definition
(Parent
(T
)))))
896 -- If variant part is present, and type is unconstrained,
897 -- then we must have defaulted discriminants, or a size
898 -- clause must be present for the type, or else the size
899 -- is definitely not known at compile time.
901 if not Is_Constrained
(T
)
903 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
904 and then Unknown_RM_Size
(T
)
910 -- Loop through components
912 Comp
:= First_Component_Or_Discriminant
(T
);
913 while Present
(Comp
) loop
914 Ctyp
:= Etype
(Comp
);
916 -- We do not know the packed size if there is a component
917 -- clause present (we possibly could, but this would only
918 -- help in the case of a record with partial rep clauses.
919 -- That's because in the case of full rep clauses, the
920 -- size gets figured out anyway by a different circuit).
922 if Present
(Component_Clause
(Comp
)) then
923 Packed_Size_Known
:= False;
926 -- We do not know the packed size if we have a by reference
927 -- type, or an atomic type or an atomic component, or an
928 -- aliased component (because packing does not touch these).
931 or else Is_Atomic
(Comp
)
932 or else Is_By_Reference_Type
(Ctyp
)
933 or else Is_Aliased
(Comp
)
935 Packed_Size_Known
:= False;
938 -- We need to identify a component that is an array where
939 -- the index type is an enumeration type with non-standard
940 -- representation, and some bound of the type depends on a
943 -- This is because gigi computes the size by doing a
944 -- substitution of the appropriate discriminant value in
945 -- the size expression for the base type, and gigi is not
946 -- clever enough to evaluate the resulting expression (which
947 -- involves a call to rep_to_pos) at compile time.
949 -- It would be nice if gigi would either recognize that
950 -- this expression can be computed at compile time, or
951 -- alternatively figured out the size from the subtype
952 -- directly, where all the information is at hand ???
954 if Is_Array_Type
(Etype
(Comp
))
955 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
958 Ocomp
: constant Entity_Id
:=
959 Original_Record_Component
(Comp
);
960 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
966 Ind
:= First_Index
(OCtyp
);
967 while Present
(Ind
) loop
968 Indtyp
:= Etype
(Ind
);
970 if Is_Enumeration_Type
(Indtyp
)
971 and then Has_Non_Standard_Rep
(Indtyp
)
973 Lo
:= Type_Low_Bound
(Indtyp
);
974 Hi
:= Type_High_Bound
(Indtyp
);
976 if Is_Entity_Name
(Lo
)
977 and then Ekind
(Entity
(Lo
)) = E_Discriminant
981 elsif Is_Entity_Name
(Hi
)
982 and then Ekind
(Entity
(Hi
)) = E_Discriminant
993 -- Clearly size of record is not known if the size of one of
994 -- the components is not known.
996 if not Size_Known
(Ctyp
) then
1000 -- Accumulate packed size if possible
1002 if Packed_Size_Known
then
1004 -- We can only deal with elementary types, since for
1005 -- non-elementary components, alignment enters into the
1006 -- picture, and we don't know enough to handle proper
1007 -- alignment in this context. Packed arrays count as
1008 -- elementary if the representation is a modular type.
1010 if Is_Elementary_Type
(Ctyp
)
1011 or else (Is_Array_Type
(Ctyp
)
1013 (Packed_Array_Impl_Type
(Ctyp
))
1014 and then Is_Modular_Integer_Type
1015 (Packed_Array_Impl_Type
(Ctyp
)))
1017 -- Packed size unknown if we have an atomic type
1018 -- or a by reference type, since the back end
1019 -- knows how these are layed out.
1022 or else Is_By_Reference_Type
(Ctyp
)
1024 Packed_Size_Known
:= False;
1026 -- If RM_Size is known and static, then we can keep
1027 -- accumulating the packed size
1029 elsif Known_Static_RM_Size
(Ctyp
) then
1031 -- A little glitch, to be removed sometime ???
1032 -- gigi does not understand zero sizes yet.
1034 if RM_Size
(Ctyp
) = Uint_0
then
1035 Packed_Size_Known
:= False;
1037 -- Normal case where we can keep accumulating the
1038 -- packed array size.
1041 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1044 -- If we have a field whose RM_Size is not known then
1045 -- we can't figure out the packed size here.
1048 Packed_Size_Known
:= False;
1051 -- If we have a non-elementary type we can't figure out
1052 -- the packed array size (alignment issues).
1055 Packed_Size_Known
:= False;
1059 Next_Component_Or_Discriminant
(Comp
);
1062 if Packed_Size_Known
then
1063 Set_Small_Size
(T
, Packed_Size
);
1069 -- All other cases, size not known at compile time
1076 -------------------------------------
1077 -- Static_Discriminated_Components --
1078 -------------------------------------
1080 function Static_Discriminated_Components
1081 (T
: Entity_Id
) return Boolean
1083 Constraint
: Elmt_Id
;
1086 if Has_Discriminants
(T
)
1087 and then Present
(Discriminant_Constraint
(T
))
1088 and then Present
(First_Component
(T
))
1090 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1091 while Present
(Constraint
) loop
1092 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1096 Next_Elmt
(Constraint
);
1101 end Static_Discriminated_Components
;
1103 -- Start of processing for Check_Compile_Time_Size
1106 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1107 end Check_Compile_Time_Size
;
1109 -----------------------------------
1110 -- Check_Component_Storage_Order --
1111 -----------------------------------
1113 procedure Check_Component_Storage_Order
1114 (Encl_Type
: Entity_Id
;
1117 Comp_ADC_Present
: out Boolean)
1119 Comp_Type
: Entity_Id
;
1123 Comp_Byte_Aligned
: Boolean;
1124 -- Set for the record case, True if Comp starts on a byte boundary
1125 -- (in which case it is allowed to have different storage order).
1127 Comp_SSO_Differs
: Boolean;
1128 -- Set True when the component is a nested composite, and it does not
1129 -- have the same scalar storage order as Encl_Type.
1131 Component_Aliased
: Boolean;
1136 if Present
(Comp
) then
1138 Comp_Type
:= Etype
(Comp
);
1140 if Is_Tag
(Comp
) then
1141 Comp_Byte_Aligned
:= True;
1142 Component_Aliased
:= False;
1145 -- If a component clause is present, check if the component starts
1146 -- on a storage element boundary. Otherwise conservatively assume
1147 -- it does so only in the case where the record is not packed.
1149 if Present
(Component_Clause
(Comp
)) then
1150 Comp_Byte_Aligned
:=
1151 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1153 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1156 Component_Aliased
:= Is_Aliased
(Comp
);
1162 Err_Node
:= Encl_Type
;
1163 Comp_Type
:= Component_Type
(Encl_Type
);
1165 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1168 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1169 -- the attribute definition clause is attached to the first subtype.
1171 Comp_Type
:= Base_Type
(Comp_Type
);
1172 Comp_ADC
:= Get_Attribute_Definition_Clause
1173 (First_Subtype
(Comp_Type
),
1174 Attribute_Scalar_Storage_Order
);
1175 Comp_ADC_Present
:= Present
(Comp_ADC
);
1177 -- Case of record or array component: check storage order compatibility
1179 if Is_Record_Type
(Comp_Type
) or else Is_Array_Type
(Comp_Type
) then
1181 Reverse_Storage_Order
(Encl_Type
)
1183 Reverse_Storage_Order
(Comp_Type
);
1185 -- Parent and extension must have same storage order
1187 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1188 if Comp_SSO_Differs
then
1190 ("record extension must have same scalar storage order as "
1191 & "parent", Err_Node
);
1194 -- If enclosing composite has explicit SSO then nested composite must
1195 -- have explicit SSO as well.
1197 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1198 Error_Msg_N
("nested composite must have explicit scalar "
1199 & "storage order", Err_Node
);
1201 -- If component and composite SSO differs, check that component
1202 -- falls on byte boundaries and isn't packed.
1204 elsif Comp_SSO_Differs
then
1206 -- Component SSO differs from enclosing composite:
1208 -- Reject if component is a packed array, as it may be represented
1209 -- as a scalar internally.
1211 if Is_Packed_Array
(Comp_Type
) then
1213 ("type of packed component must have same scalar "
1214 & "storage order as enclosing composite", Err_Node
);
1216 -- Reject if composite is a packed array, as it may be rewritten
1217 -- into an array of scalars.
1219 elsif Is_Packed_Array
(Encl_Type
) then
1220 Error_Msg_N
("type of packed array must have same scalar "
1221 & "storage order as component", Err_Node
);
1223 -- Reject if not byte aligned
1225 elsif Is_Record_Type
(Encl_Type
)
1226 and then not Comp_Byte_Aligned
1229 ("type of non-byte-aligned component must have same scalar "
1230 & "storage order as enclosing composite", Err_Node
);
1234 -- Enclosing type has explicit SSO: non-composite component must not
1237 elsif Present
(ADC
) and then Component_Aliased
then
1239 ("aliased component not permitted for type with "
1240 & "explicit Scalar_Storage_Order", Err_Node
);
1242 end Check_Component_Storage_Order
;
1244 -----------------------------
1245 -- Check_Debug_Info_Needed --
1246 -----------------------------
1248 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1250 if Debug_Info_Off
(T
) then
1253 elsif Comes_From_Source
(T
)
1254 or else Debug_Generated_Code
1255 or else Debug_Flag_VV
1256 or else Needs_Debug_Info
(T
)
1258 Set_Debug_Info_Needed
(T
);
1260 end Check_Debug_Info_Needed
;
1262 -------------------------------
1263 -- Check_Expression_Function --
1264 -------------------------------
1266 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1269 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1270 -- Function to search for deferred constant
1276 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1278 -- When a constant is initialized with the result of a dispatching
1279 -- call, the constant declaration is rewritten as a renaming of the
1280 -- displaced function result. This scenario is not a premature use of
1281 -- a constant even though the Has_Completion flag is not set.
1283 if Is_Entity_Name
(Nod
)
1284 and then Present
(Entity
(Nod
))
1285 and then Ekind
(Entity
(Nod
)) = E_Constant
1286 and then Scope
(Entity
(Nod
)) = Current_Scope
1287 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1288 N_Object_Declaration
1289 and then not Is_Imported
(Entity
(Nod
))
1290 and then not Has_Completion
(Entity
(Nod
))
1293 ("premature use of& in call or instance", N
, Entity
(Nod
));
1295 elsif Nkind
(Nod
) = N_Attribute_Reference
then
1296 Analyze
(Prefix
(Nod
));
1298 if Is_Entity_Name
(Prefix
(Nod
))
1299 and then Is_Type
(Entity
(Prefix
(Nod
)))
1301 Freeze_Before
(N
, Entity
(Prefix
(Nod
)));
1308 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1310 -- Start of processing for Check_Expression_Function
1313 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1315 if Scope
(Nam
) = Current_Scope
1316 and then Nkind
(Decl
) = N_Expression_Function
1318 Check_Deferred
(Expression
(Decl
));
1320 end Check_Expression_Function
;
1322 ----------------------------
1323 -- Check_Strict_Alignment --
1324 ----------------------------
1326 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1330 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1331 Set_Strict_Alignment
(E
);
1333 elsif Is_Array_Type
(E
) then
1334 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1336 elsif Is_Record_Type
(E
) then
1337 if Is_Limited_Record
(E
) then
1338 Set_Strict_Alignment
(E
);
1342 Comp
:= First_Component
(E
);
1343 while Present
(Comp
) loop
1344 if not Is_Type
(Comp
)
1345 and then (Strict_Alignment
(Etype
(Comp
))
1346 or else Is_Aliased
(Comp
))
1348 Set_Strict_Alignment
(E
);
1352 Next_Component
(Comp
);
1355 end Check_Strict_Alignment
;
1357 -------------------------
1358 -- Check_Unsigned_Type --
1359 -------------------------
1361 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1362 Ancestor
: Entity_Id
;
1367 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1371 -- Do not attempt to analyze case where range was in error
1373 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
1377 -- The situation that is non trivial is something like
1379 -- subtype x1 is integer range -10 .. +10;
1380 -- subtype x2 is x1 range 0 .. V1;
1381 -- subtype x3 is x2 range V2 .. V3;
1382 -- subtype x4 is x3 range V4 .. V5;
1384 -- where Vn are variables. Here the base type is signed, but we still
1385 -- know that x4 is unsigned because of the lower bound of x2.
1387 -- The only way to deal with this is to look up the ancestor chain
1391 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1395 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1397 if Compile_Time_Known_Value
(Lo_Bound
) then
1398 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1399 Set_Is_Unsigned_Type
(E
, True);
1405 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1407 -- If no ancestor had a static lower bound, go to base type
1409 if No
(Ancestor
) then
1411 -- Note: the reason we still check for a compile time known
1412 -- value for the base type is that at least in the case of
1413 -- generic formals, we can have bounds that fail this test,
1414 -- and there may be other cases in error situations.
1416 Btyp
:= Base_Type
(E
);
1418 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1422 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1424 if Compile_Time_Known_Value
(Lo_Bound
)
1425 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1427 Set_Is_Unsigned_Type
(E
, True);
1434 end Check_Unsigned_Type
;
1436 -------------------------
1437 -- Is_Atomic_Aggregate --
1438 -------------------------
1440 function Is_Atomic_Aggregate
1442 Typ
: Entity_Id
) return Boolean
1444 Loc
: constant Source_Ptr
:= Sloc
(E
);
1452 -- Array may be qualified, so find outer context
1454 if Nkind
(Par
) = N_Qualified_Expression
then
1455 Par
:= Parent
(Par
);
1458 if Nkind_In
(Par
, N_Object_Declaration
, N_Assignment_Statement
)
1459 and then Comes_From_Source
(Par
)
1461 Temp
:= Make_Temporary
(Loc
, 'T', E
);
1463 Make_Object_Declaration
(Loc
,
1464 Defining_Identifier
=> Temp
,
1465 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1466 Expression
=> Relocate_Node
(E
));
1467 Insert_Before
(Par
, New_N
);
1470 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1476 end Is_Atomic_Aggregate
;
1478 -----------------------------------------------
1479 -- Explode_Initialization_Compound_Statement --
1480 -----------------------------------------------
1482 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
1483 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
1486 if Present
(Init_Stmts
)
1487 and then Nkind
(Init_Stmts
) = N_Compound_Statement
1489 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
1491 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
1492 -- just removing it, because Freeze_All may rely on this particular
1493 -- Node_Id still being present in the enclosing list to know where to
1496 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
1498 Set_Initialization_Statements
(E
, Empty
);
1500 end Explode_Initialization_Compound_Statement
;
1506 -- Note: the easy coding for this procedure would be to just build a
1507 -- single list of freeze nodes and then insert them and analyze them
1508 -- all at once. This won't work, because the analysis of earlier freeze
1509 -- nodes may recursively freeze types which would otherwise appear later
1510 -- on in the freeze list. So we must analyze and expand the freeze nodes
1511 -- as they are generated.
1513 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1517 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1518 -- This is the internal recursive routine that does freezing of entities
1519 -- (but NOT the analysis of default expressions, which should not be
1520 -- recursive, we don't want to analyze those till we are sure that ALL
1521 -- the types are frozen).
1523 --------------------
1524 -- Freeze_All_Ent --
1525 --------------------
1527 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1532 procedure Process_Flist
;
1533 -- If freeze nodes are present, insert and analyze, and reset cursor
1534 -- for next insertion.
1540 procedure Process_Flist
is
1542 if Is_Non_Empty_List
(Flist
) then
1543 Lastn
:= Next
(After
);
1544 Insert_List_After_And_Analyze
(After
, Flist
);
1546 if Present
(Lastn
) then
1547 After
:= Prev
(Lastn
);
1549 After
:= Last
(List_Containing
(After
));
1554 -- Start or processing for Freeze_All_Ent
1558 while Present
(E
) loop
1560 -- If the entity is an inner package which is not a package
1561 -- renaming, then its entities must be frozen at this point. Note
1562 -- that such entities do NOT get frozen at the end of the nested
1563 -- package itself (only library packages freeze).
1565 -- Same is true for task declarations, where anonymous records
1566 -- created for entry parameters must be frozen.
1568 if Ekind
(E
) = E_Package
1569 and then No
(Renamed_Object
(E
))
1570 and then not Is_Child_Unit
(E
)
1571 and then not Is_Frozen
(E
)
1574 Install_Visible_Declarations
(E
);
1575 Install_Private_Declarations
(E
);
1577 Freeze_All
(First_Entity
(E
), After
);
1579 End_Package_Scope
(E
);
1581 if Is_Generic_Instance
(E
)
1582 and then Has_Delayed_Freeze
(E
)
1584 Set_Has_Delayed_Freeze
(E
, False);
1585 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1588 elsif Ekind
(E
) in Task_Kind
1589 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1590 N_Single_Task_Declaration
)
1593 Freeze_All
(First_Entity
(E
), After
);
1596 -- For a derived tagged type, we must ensure that all the
1597 -- primitive operations of the parent have been frozen, so that
1598 -- their addresses will be in the parent's dispatch table at the
1599 -- point it is inherited.
1601 elsif Ekind
(E
) = E_Record_Type
1602 and then Is_Tagged_Type
(E
)
1603 and then Is_Tagged_Type
(Etype
(E
))
1604 and then Is_Derived_Type
(E
)
1607 Prim_List
: constant Elist_Id
:=
1608 Primitive_Operations
(Etype
(E
));
1614 Prim
:= First_Elmt
(Prim_List
);
1615 while Present
(Prim
) loop
1616 Subp
:= Node
(Prim
);
1618 if Comes_From_Source
(Subp
)
1619 and then not Is_Frozen
(Subp
)
1621 Flist
:= Freeze_Entity
(Subp
, After
);
1630 if not Is_Frozen
(E
) then
1631 Flist
:= Freeze_Entity
(E
, After
);
1634 -- If already frozen, and there are delayed aspects, this is where
1635 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1636 -- for a description of how we handle aspect visibility).
1638 elsif Has_Delayed_Aspects
(E
) then
1640 -- Retrieve the visibility to the discriminants in order to
1641 -- analyze properly the aspects.
1643 Push_Scope_And_Install_Discriminants
(E
);
1649 Ritem
:= First_Rep_Item
(E
);
1650 while Present
(Ritem
) loop
1651 if Nkind
(Ritem
) = N_Aspect_Specification
1652 and then Entity
(Ritem
) = E
1653 and then Is_Delayed_Aspect
(Ritem
)
1655 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1658 Ritem
:= Next_Rep_Item
(Ritem
);
1662 Uninstall_Discriminants_And_Pop_Scope
(E
);
1665 -- If an incomplete type is still not frozen, this may be a
1666 -- premature freezing because of a body declaration that follows.
1667 -- Indicate where the freezing took place. Freezing will happen
1668 -- if the body comes from source, but not if it is internally
1669 -- generated, for example as the body of a type invariant.
1671 -- If the freezing is caused by the end of the current declarative
1672 -- part, it is a Taft Amendment type, and there is no error.
1674 if not Is_Frozen
(E
)
1675 and then Ekind
(E
) = E_Incomplete_Type
1678 Bod
: constant Node_Id
:= Next
(After
);
1681 -- The presence of a body freezes all entities previously
1682 -- declared in the current list of declarations, but this
1683 -- does not apply if the body does not come from source.
1684 -- A type invariant is transformed into a subprogram body
1685 -- which is placed at the end of the private part of the
1686 -- current package, but this body does not freeze incomplete
1687 -- types that may be declared in this private part.
1689 if (Nkind_In
(Bod
, N_Subprogram_Body
,
1694 or else Nkind
(Bod
) in N_Body_Stub
)
1696 List_Containing
(After
) = List_Containing
(Parent
(E
))
1697 and then Comes_From_Source
(Bod
)
1699 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1701 ("type& is frozen# before its full declaration",
1711 -- Start of processing for Freeze_All
1714 Freeze_All_Ent
(From
, After
);
1716 -- Now that all types are frozen, we can deal with default expressions
1717 -- that require us to build a default expression functions. This is the
1718 -- point at which such functions are constructed (after all types that
1719 -- might be used in such expressions have been frozen).
1721 -- For subprograms that are renaming_as_body, we create the wrapper
1722 -- bodies as needed.
1724 -- We also add finalization chains to access types whose designated
1725 -- types are controlled. This is normally done when freezing the type,
1726 -- but this misses recursive type definitions where the later members
1727 -- of the recursion introduce controlled components.
1729 -- Loop through entities
1732 while Present
(E
) loop
1733 if Is_Subprogram
(E
) then
1734 if not Default_Expressions_Processed
(E
) then
1735 Process_Default_Expressions
(E
, After
);
1738 if not Has_Completion
(E
) then
1739 Decl
:= Unit_Declaration_Node
(E
);
1741 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1742 if Error_Posted
(Decl
) then
1743 Set_Has_Completion
(E
);
1745 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1748 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1749 and then Present
(Corresponding_Body
(Decl
))
1751 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1752 = N_Subprogram_Renaming_Declaration
1754 Build_And_Analyze_Renamed_Body
1755 (Decl
, Corresponding_Body
(Decl
), After
);
1759 elsif Ekind
(E
) in Task_Kind
1760 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1761 N_Single_Task_Declaration
)
1767 Ent
:= First_Entity
(E
);
1768 while Present
(Ent
) loop
1770 and then not Default_Expressions_Processed
(Ent
)
1772 Process_Default_Expressions
(Ent
, After
);
1779 -- We add finalization masters to access types whose designated types
1780 -- require finalization. This is normally done when freezing the
1781 -- type, but this misses recursive type definitions where the later
1782 -- members of the recursion introduce controlled components (such as
1783 -- can happen when incomplete types are involved), as well cases
1784 -- where a component type is private and the controlled full type
1785 -- occurs after the access type is frozen. Cases that don't need a
1786 -- finalization master are generic formal types (the actual type will
1787 -- have it) and types derived from them, and types with Java and CIL
1788 -- conventions, since those are used for API bindings.
1789 -- (Are there any other cases that should be excluded here???)
1791 elsif Is_Access_Type
(E
)
1792 and then Comes_From_Source
(E
)
1793 and then not Is_Generic_Type
(Root_Type
(E
))
1794 and then Needs_Finalization
(Designated_Type
(E
))
1796 Build_Finalization_Master
(E
);
1803 -----------------------
1804 -- Freeze_And_Append --
1805 -----------------------
1807 procedure Freeze_And_Append
1810 Result
: in out List_Id
)
1812 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1814 if Is_Non_Empty_List
(L
) then
1815 if Result
= No_List
then
1818 Append_List
(L
, Result
);
1821 end Freeze_And_Append
;
1827 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1828 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, N
);
1831 if Ekind
(T
) = E_Function
then
1832 Check_Expression_Function
(N
, T
);
1835 if Is_Non_Empty_List
(Freeze_Nodes
) then
1836 Insert_Actions
(N
, Freeze_Nodes
);
1844 function Freeze_Entity
(E
: Entity_Id
; N
: Node_Id
) return List_Id
is
1845 Loc
: constant Source_Ptr
:= Sloc
(N
);
1852 Test_E
: Entity_Id
:= E
;
1853 -- This could use a comment ???
1855 Late_Freezing
: Boolean := False;
1856 -- Used to detect attempt to freeze function declared in another unit
1858 Result
: List_Id
:= No_List
;
1859 -- List of freezing actions, left at No_List if none
1861 Has_Default_Initialization
: Boolean := False;
1862 -- This flag gets set to true for a variable with default initialization
1864 procedure Add_To_Result
(N
: Node_Id
);
1865 -- N is a freezing action to be appended to the Result
1867 function After_Last_Declaration
return Boolean;
1868 -- If Loc is a freeze_entity that appears after the last declaration
1869 -- in the scope, inhibit error messages on late completion.
1871 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1872 -- Check that an Access or Unchecked_Access attribute with a prefix
1873 -- which is the current instance type can only be applied when the type
1876 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1877 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1878 -- integer literal without an explicit corresponding size clause. The
1879 -- caller has checked that Utype is a modular integer type.
1881 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
1882 -- Freeze array type, including freezing index and component types
1884 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
1885 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1886 -- package. Recurse on inner generic packages.
1888 function Freeze_Profile
(E
: Entity_Id
) return Boolean;
1889 -- Freeze formals and return type of subprogram. If some type in the
1890 -- profile is a limited view, freezing of the entity will take place
1891 -- elsewhere, and the function returns False. This routine will be
1892 -- modified if and when we can implement AI05-019 efficiently ???
1894 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1895 -- Freeze record type, including freezing component types, and freezing
1896 -- primitive operations if this is a tagged type.
1898 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
1899 -- Determine whether an arbitrary entity is subject to Boolean aspect
1900 -- Import and its value is specified as True.
1902 procedure Late_Freeze_Subprogram
(E
: Entity_Id
);
1903 -- Following AI05-151, a function can return a limited view of a type
1904 -- declared elsewhere. In that case the function cannot be frozen at
1905 -- the end of its enclosing package. If its first use is in a different
1906 -- unit, it cannot be frozen there, but if the call is legal the full
1907 -- view of the return type is available and the subprogram can now be
1908 -- frozen. However the freeze node cannot be inserted at the point of
1909 -- call, but rather must go in the package holding the function, so that
1910 -- the backend can process it in the proper context.
1912 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
1913 -- If E is an entity for an imported subprogram with pre/post-conditions
1914 -- then this procedure will create a wrapper to ensure that proper run-
1915 -- time checking of the pre/postconditions. See body for details.
1921 procedure Add_To_Result
(N
: Node_Id
) is
1924 Result
:= New_List
(N
);
1930 ----------------------------
1931 -- After_Last_Declaration --
1932 ----------------------------
1934 function After_Last_Declaration
return Boolean is
1935 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
1938 if Nkind
(Spec
) = N_Package_Specification
then
1939 if Present
(Private_Declarations
(Spec
)) then
1940 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1941 elsif Present
(Visible_Declarations
(Spec
)) then
1942 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1950 end After_Last_Declaration
;
1952 ----------------------------
1953 -- Check_Current_Instance --
1954 ----------------------------
1956 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1958 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
1959 -- Determine whether Typ is compatible with the rules for aliased
1960 -- views of types as defined in RM 3.10 in the various dialects.
1962 function Process
(N
: Node_Id
) return Traverse_Result
;
1963 -- Process routine to apply check to given node
1965 -----------------------------
1966 -- Is_Aliased_View_Of_Type --
1967 -----------------------------
1969 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
1970 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
1975 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
1976 and then Limited_Present
(Type_Definition
(Typ_Decl
))
1980 -- The following paragraphs describe what a legal aliased view of
1981 -- a type is in the various dialects of Ada.
1985 -- The current instance of a limited type, and a formal parameter
1986 -- or generic formal object of a tagged type.
1988 -- Ada 95 limited type
1989 -- * Type with reserved word "limited"
1990 -- * A protected or task type
1991 -- * A composite type with limited component
1993 elsif Ada_Version
<= Ada_95
then
1994 return Is_Limited_Type
(Typ
);
1998 -- The current instance of a limited tagged type, a protected
1999 -- type, a task type, or a type that has the reserved word
2000 -- "limited" in its full definition ... a formal parameter or
2001 -- generic formal object of a tagged type.
2003 -- Ada 2005 limited type
2004 -- * Type with reserved word "limited", "synchronized", "task"
2006 -- * A composite type with limited component
2007 -- * A derived type whose parent is a non-interface limited type
2009 elsif Ada_Version
= Ada_2005
then
2011 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
2013 (Is_Derived_Type
(Typ
)
2014 and then not Is_Interface
(Etype
(Typ
))
2015 and then Is_Limited_Type
(Etype
(Typ
)));
2017 -- Ada 2012 and beyond
2019 -- The current instance of an immutably limited type ... a formal
2020 -- parameter or generic formal object of a tagged type.
2022 -- Ada 2012 limited type
2023 -- * Type with reserved word "limited", "synchronized", "task"
2025 -- * A composite type with limited component
2026 -- * A derived type whose parent is a non-interface limited type
2027 -- * An incomplete view
2029 -- Ada 2012 immutably limited type
2030 -- * Explicitly limited record type
2031 -- * Record extension with "limited" present
2032 -- * Non-formal limited private type that is either tagged
2033 -- or has at least one access discriminant with a default
2035 -- * Task type, protected type or synchronized interface
2036 -- * Type derived from immutably limited type
2040 Is_Immutably_Limited_Type
(Typ
)
2041 or else Is_Incomplete_Type
(Typ
);
2043 end Is_Aliased_View_Of_Type
;
2049 function Process
(N
: Node_Id
) return Traverse_Result
is
2052 when N_Attribute_Reference
=>
2053 if Nam_In
(Attribute_Name
(N
), Name_Access
,
2054 Name_Unchecked_Access
)
2055 and then Is_Entity_Name
(Prefix
(N
))
2056 and then Is_Type
(Entity
(Prefix
(N
)))
2057 and then Entity
(Prefix
(N
)) = E
2059 if Ada_Version
< Ada_2012
then
2061 ("current instance must be a limited type",
2065 ("current instance must be an immutably limited "
2066 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2075 when others => return OK
;
2079 procedure Traverse
is new Traverse_Proc
(Process
);
2083 Rec_Type
: constant Entity_Id
:=
2084 Scope
(Defining_Identifier
(Comp_Decl
));
2086 -- Start of processing for Check_Current_Instance
2089 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2090 Traverse
(Comp_Decl
);
2092 end Check_Current_Instance
;
2094 ------------------------------
2095 -- Check_Suspicious_Modulus --
2096 ------------------------------
2098 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
2099 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
2102 if not Warn_On_Suspicious_Modulus_Value
then
2106 if Nkind
(Decl
) = N_Full_Type_Declaration
then
2108 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
2111 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
2113 Modulus
: constant Node_Id
:=
2114 Original_Node
(Expression
(Tdef
));
2117 if Nkind
(Modulus
) = N_Integer_Literal
then
2119 Modv
: constant Uint
:= Intval
(Modulus
);
2120 Sizv
: constant Uint
:= RM_Size
(Utype
);
2123 -- First case, modulus and size are the same. This
2124 -- happens if you have something like mod 32, with
2125 -- an explicit size of 32, this is for sure a case
2126 -- where the warning is given, since it is seems
2127 -- very unlikely that someone would want e.g. a
2128 -- five bit type stored in 32 bits. It is much
2129 -- more likely they wanted a 32-bit type.
2134 -- Second case, the modulus is 32 or 64 and no
2135 -- size clause is present. This is a less clear
2136 -- case for giving the warning, but in the case
2137 -- of 32/64 (5-bit or 6-bit types) these seem rare
2138 -- enough that it is a likely error (and in any
2139 -- case using 2**5 or 2**6 in these cases seems
2140 -- clearer. We don't include 8 or 16 here, simply
2141 -- because in practice 3-bit and 4-bit types are
2142 -- more common and too many false positives if
2143 -- we warn in these cases.
2145 elsif not Has_Size_Clause
(Utype
)
2146 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
2150 -- No warning needed
2156 -- If we fall through, give warning
2158 Error_Msg_Uint_1
:= Modv
;
2160 ("?M?2 '*'*^' may have been intended here",
2168 end Check_Suspicious_Modulus
;
2170 -----------------------
2171 -- Freeze_Array_Type --
2172 -----------------------
2174 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2175 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2176 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2179 Non_Standard_Enum
: Boolean := False;
2180 -- Set true if any of the index types is an enumeration type with a
2181 -- non-standard representation.
2184 Freeze_And_Append
(Ctyp
, N
, Result
);
2186 Indx
:= First_Index
(Arr
);
2187 while Present
(Indx
) loop
2188 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2190 if Is_Enumeration_Type
(Etype
(Indx
))
2191 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2193 Non_Standard_Enum
:= True;
2199 -- Processing that is done only for base types
2201 if Ekind
(Arr
) = E_Array_Type
then
2203 -- Deal with default setting of reverse storage order
2205 Set_SSO_From_Default
(Arr
);
2207 -- Propagate flags for component type
2209 if Is_Controlled
(Component_Type
(Arr
))
2210 or else Has_Controlled_Component
(Ctyp
)
2212 Set_Has_Controlled_Component
(Arr
);
2215 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2216 Set_Has_Unchecked_Union
(Arr
);
2219 -- Warn for pragma Pack overriding foreign convention
2221 if Has_Foreign_Convention
(Ctyp
)
2222 and then Has_Pragma_Pack
(Arr
)
2225 CN
: constant Name_Id
:=
2226 Get_Convention_Name
(Convention
(Ctyp
));
2227 PP
: constant Node_Id
:=
2228 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2230 if Present
(PP
) then
2231 Error_Msg_Name_1
:= CN
;
2232 Error_Msg_Sloc
:= Sloc
(Arr
);
2234 ("pragma Pack affects convention % components #??", PP
);
2235 Error_Msg_Name_1
:= CN
;
2237 ("\array components may not have % compatible "
2238 & "representation??", PP
);
2243 -- If packing was requested or if the component size was
2244 -- set explicitly, then see if bit packing is required. This
2245 -- processing is only done for base types, since all of the
2246 -- representation aspects involved are type-related.
2248 -- This is not just an optimization, if we start processing the
2249 -- subtypes, they interfere with the settings on the base type
2250 -- (this is because Is_Packed has a slightly different meaning
2251 -- before and after freezing).
2258 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2259 and then Known_Static_RM_Size
(Ctyp
)
2260 and then not Has_Component_Size_Clause
(Arr
)
2262 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2264 elsif Known_Component_Size
(Arr
) then
2265 Csiz
:= Component_Size
(Arr
);
2267 elsif not Known_Static_Esize
(Ctyp
) then
2271 Esiz
:= Esize
(Ctyp
);
2273 -- We can set the component size if it is less than 16,
2274 -- rounding it up to the next storage unit size.
2278 elsif Esiz
<= 16 then
2284 -- Set component size up to match alignment if it would
2285 -- otherwise be less than the alignment. This deals with
2286 -- cases of types whose alignment exceeds their size (the
2287 -- padded type cases).
2291 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2300 -- Case of component size that may result in packing
2302 if 1 <= Csiz
and then Csiz
<= 64 then
2304 Ent
: constant Entity_Id
:=
2305 First_Subtype
(Arr
);
2306 Pack_Pragma
: constant Node_Id
:=
2307 Get_Rep_Pragma
(Ent
, Name_Pack
);
2308 Comp_Size_C
: constant Node_Id
:=
2309 Get_Attribute_Definition_Clause
2310 (Ent
, Attribute_Component_Size
);
2313 -- Warn if we have pack and component size so that the
2316 -- Note: here we must check for the presence of a
2317 -- component size before checking for a Pack pragma to
2318 -- deal with the case where the array type is a derived
2319 -- type whose parent is currently private.
2321 if Present
(Comp_Size_C
)
2322 and then Has_Pragma_Pack
(Ent
)
2323 and then Warn_On_Redundant_Constructs
2325 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2327 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2329 ("\?r?explicit component size given#!", Pack_Pragma
);
2330 Set_Is_Packed
(Base_Type
(Ent
), False);
2331 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2334 -- Set component size if not already set by a component
2337 if not Present
(Comp_Size_C
) then
2338 Set_Component_Size
(Arr
, Csiz
);
2341 -- Check for base type of 8, 16, 32 bits, where an
2342 -- unsigned subtype has a length one less than the
2343 -- base type (e.g. Natural subtype of Integer).
2345 -- In such cases, if a component size was not set
2346 -- explicitly, then generate a warning.
2348 if Has_Pragma_Pack
(Arr
)
2349 and then not Present
(Comp_Size_C
)
2350 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2351 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2353 Error_Msg_Uint_1
:= Csiz
;
2355 if Present
(Pack_Pragma
) then
2357 ("??pragma Pack causes component size to be ^!",
2360 ("\??use Component_Size to set desired value!",
2365 -- Actual packing is not needed for 8, 16, 32, 64. Also
2366 -- not needed for 24 if alignment is 1.
2372 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
2374 -- Here the array was requested to be packed, but
2375 -- the packing request had no effect, so Is_Packed
2378 -- Note: semantically this means that we lose track
2379 -- of the fact that a derived type inherited a pragma
2380 -- Pack that was non- effective, but that seems fine.
2382 -- We regard a Pack pragma as a request to set a
2383 -- representation characteristic, and this request
2386 Set_Is_Packed
(Base_Type
(Arr
), False);
2387 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2389 if Known_Static_Esize
(Component_Type
(Arr
))
2390 and then Esize
(Component_Type
(Arr
)) = Csiz
2392 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
2395 -- In all other cases, packing is indeed needed
2398 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2399 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2400 Set_Is_Packed
(Base_Type
(Arr
), True);
2406 -- Check for Atomic_Components or Aliased with unsuitable packing
2407 -- or explicit component size clause given.
2409 if (Has_Atomic_Components
(Arr
)
2411 Has_Aliased_Components
(Arr
))
2413 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2415 Alias_Atomic_Check
: declare
2417 procedure Complain_CS
(T
: String);
2418 -- Outputs error messages for incorrect CS clause or pragma
2419 -- Pack for aliased or atomic components (T is "aliased" or
2426 procedure Complain_CS
(T
: String) is
2428 if Has_Component_Size_Clause
(Arr
) then
2430 Get_Attribute_Definition_Clause
2431 (FS
, Attribute_Component_Size
);
2433 if Known_Static_Esize
(Ctyp
) then
2435 ("incorrect component size for "
2436 & T
& " components", Clause
);
2437 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2439 ("\only allowed value is^", Clause
);
2443 ("component size cannot be given for "
2444 & T
& " components", Clause
);
2449 ("cannot pack " & T
& " components",
2450 Get_Rep_Pragma
(FS
, Name_Pack
));
2456 -- Start of processing for Alias_Atomic_Check
2459 -- If object size of component type isn't known, we cannot
2460 -- be sure so we defer to the back end.
2462 if not Known_Static_Esize
(Ctyp
) then
2465 -- Case where component size has no effect. First check for
2466 -- object size of component type multiple of the storage
2469 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2471 -- OK in both packing case and component size case if RM
2472 -- size is known and static and same as the object size.
2475 ((Known_Static_RM_Size
(Ctyp
)
2476 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2478 -- Or if we have an explicit component size clause and
2479 -- the component size and object size are equal.
2482 (Has_Component_Size_Clause
(Arr
)
2483 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2487 elsif Has_Aliased_Components
(Arr
)
2488 or else Is_Aliased
(Ctyp
)
2490 Complain_CS
("aliased");
2492 elsif Has_Atomic_Components
(Arr
)
2493 or else Is_Atomic
(Ctyp
)
2495 Complain_CS
("atomic");
2497 end Alias_Atomic_Check
;
2500 -- Warn for case of atomic type
2502 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2505 and then not Addressable
(Component_Size
(FS
))
2508 ("non-atomic components of type& may not be "
2509 & "accessible by separate tasks??", Clause
, Arr
);
2511 if Has_Component_Size_Clause
(Arr
) then
2512 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2513 (FS
, Attribute_Component_Size
));
2514 Error_Msg_N
("\because of component size clause#??", Clause
);
2516 elsif Has_Pragma_Pack
(Arr
) then
2517 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2518 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2522 -- Check for scalar storage order
2527 Check_Component_Storage_Order
2530 ADC
=> Get_Attribute_Definition_Clause
2531 (First_Subtype
(Arr
),
2532 Attribute_Scalar_Storage_Order
),
2533 Comp_ADC_Present
=> Dummy
);
2536 -- Processing that is done only for subtypes
2539 -- Acquire alignment from base type
2541 if Unknown_Alignment
(Arr
) then
2542 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2543 Adjust_Esize_Alignment
(Arr
);
2547 -- Specific checks for bit-packed arrays
2549 if Is_Bit_Packed_Array
(Arr
) then
2551 -- Check number of elements for bit packed arrays that come from
2552 -- source and have compile time known ranges. The bit-packed
2553 -- arrays circuitry does not support arrays with more than
2554 -- Integer'Last + 1 elements, and when this restriction is
2555 -- violated, causes incorrect data access.
2557 -- For the case where this is not compile time known, a run-time
2558 -- check should be generated???
2560 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
2569 Index
:= First_Index
(Arr
);
2570 while Present
(Index
) loop
2571 Ityp
:= Etype
(Index
);
2573 -- Never generate an error if any index is of a generic
2574 -- type. We will check this in instances.
2576 if Is_Generic_Type
(Ityp
) then
2582 Make_Attribute_Reference
(Loc
,
2583 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2584 Attribute_Name
=> Name_Range_Length
);
2585 Analyze_And_Resolve
(Ilen
);
2587 -- No attempt is made to check number of elements if not
2588 -- compile time known.
2590 if Nkind
(Ilen
) /= N_Integer_Literal
then
2595 Elmts
:= Elmts
* Intval
(Ilen
);
2599 if Elmts
> Intval
(High_Bound
2600 (Scalar_Range
(Standard_Integer
))) + 1
2603 ("bit packed array type may not have "
2604 & "more than Integer''Last+1 elements", Arr
);
2611 if Known_RM_Size
(Arr
) then
2613 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
2617 -- It is not clear if it is possible to have no size clause
2618 -- at this stage, but it is not worth worrying about. Post
2619 -- error on the entity name in the size clause if present,
2620 -- else on the type entity itself.
2622 if Present
(SizC
) then
2623 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
2625 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
2631 -- If any of the index types was an enumeration type with a non-
2632 -- standard rep clause, then we indicate that the array type is
2633 -- always packed (even if it is not bit packed).
2635 if Non_Standard_Enum
then
2636 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
2637 Set_Is_Packed
(Base_Type
(Arr
));
2640 Set_Component_Alignment_If_Not_Set
(Arr
);
2642 -- If the array is packed, we must create the packed array type to be
2643 -- used to actually implement the type. This is only needed for real
2644 -- array types (not for string literal types, since they are present
2645 -- only for the front end).
2648 and then Ekind
(Arr
) /= E_String_Literal_Subtype
2650 Create_Packed_Array_Impl_Type
(Arr
);
2651 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
2653 -- Make sure that we have the necessary routines to implement the
2654 -- packing, and complain now if not. Note that we only test this
2655 -- for constrained array types.
2657 if Is_Constrained
(Arr
)
2658 and then Is_Bit_Packed_Array
(Arr
)
2659 and then Present
(Packed_Array_Impl_Type
(Arr
))
2660 and then Is_Array_Type
(Packed_Array_Impl_Type
(Arr
))
2663 CS
: constant Uint
:= Component_Size
(Arr
);
2664 RE
: constant RE_Id
:= Get_Id
(UI_To_Int
(CS
));
2668 and then not RTE_Available
(RE
)
2671 ("packing of " & UI_Image
(CS
) & "-bit components",
2672 First_Subtype
(Etype
(Arr
)));
2674 -- Cancel the packing
2676 Set_Is_Packed
(Base_Type
(Arr
), False);
2677 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2678 Set_Packed_Array_Impl_Type
(Arr
, Empty
);
2684 -- Size information of packed array type is copied to the array
2685 -- type, since this is really the representation. But do not
2686 -- override explicit existing size values. If the ancestor subtype
2687 -- is constrained the Packed_Array_Impl_Type will be inherited
2688 -- from it, but the size may have been provided already, and
2689 -- must not be overridden either.
2691 if not Has_Size_Clause
(Arr
)
2693 (No
(Ancestor_Subtype
(Arr
))
2694 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
2696 Set_Esize
(Arr
, Esize
(Packed_Array_Impl_Type
(Arr
)));
2697 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Impl_Type
(Arr
)));
2700 if not Has_Alignment_Clause
(Arr
) then
2701 Set_Alignment
(Arr
, Alignment
(Packed_Array_Impl_Type
(Arr
)));
2707 -- For non-packed arrays set the alignment of the array to the
2708 -- alignment of the component type if it is unknown. Skip this
2709 -- in atomic case (atomic arrays may need larger alignments).
2711 if not Is_Packed
(Arr
)
2712 and then Unknown_Alignment
(Arr
)
2713 and then Known_Alignment
(Ctyp
)
2714 and then Known_Static_Component_Size
(Arr
)
2715 and then Known_Static_Esize
(Ctyp
)
2716 and then Esize
(Ctyp
) = Component_Size
(Arr
)
2717 and then not Is_Atomic
(Arr
)
2719 Set_Alignment
(Arr
, Alignment
(Component_Type
(Arr
)));
2721 end Freeze_Array_Type
;
2723 -----------------------------
2724 -- Freeze_Generic_Entities --
2725 -----------------------------
2727 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
2734 E
:= First_Entity
(Pack
);
2735 while Present
(E
) loop
2736 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
2737 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
2739 Append_To
(Flist
, F
);
2741 elsif Ekind
(E
) = E_Generic_Package
then
2742 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
2749 end Freeze_Generic_Entities
;
2751 --------------------
2752 -- Freeze_Profile --
2753 --------------------
2755 function Freeze_Profile
(E
: Entity_Id
) return Boolean is
2758 Warn_Node
: Node_Id
;
2761 -- Loop through formals
2763 Formal
:= First_Formal
(E
);
2764 while Present
(Formal
) loop
2765 F_Type
:= Etype
(Formal
);
2767 -- AI05-0151: incomplete types can appear in a profile. By the
2768 -- time the entity is frozen, the full view must be available,
2769 -- unless it is a limited view.
2771 if Is_Incomplete_Type
(F_Type
)
2772 and then Present
(Full_View
(F_Type
))
2773 and then not From_Limited_With
(F_Type
)
2775 F_Type
:= Full_View
(F_Type
);
2776 Set_Etype
(Formal
, F_Type
);
2779 Freeze_And_Append
(F_Type
, N
, Result
);
2781 if Is_Private_Type
(F_Type
)
2782 and then Is_Private_Type
(Base_Type
(F_Type
))
2783 and then No
(Full_View
(Base_Type
(F_Type
)))
2784 and then not Is_Generic_Type
(F_Type
)
2785 and then not Is_Derived_Type
(F_Type
)
2787 -- If the type of a formal is incomplete, subprogram is being
2788 -- frozen prematurely. Within an instance (but not within a
2789 -- wrapper package) this is an artifact of our need to regard
2790 -- the end of an instantiation as a freeze point. Otherwise it
2791 -- is a definite error.
2794 Set_Is_Frozen
(E
, False);
2798 elsif not After_Last_Declaration
2799 and then not Freezing_Library_Level_Tagged_Type
2801 Error_Msg_Node_1
:= F_Type
;
2803 ("type & must be fully defined before this point", Loc
);
2807 -- Check suspicious parameter for C function. These tests apply
2808 -- only to exported/imported subprograms.
2810 if Warn_On_Export_Import
2811 and then Comes_From_Source
(E
)
2812 and then (Convention
(E
) = Convention_C
2814 Convention
(E
) = Convention_CPP
)
2815 and then (Is_Imported
(E
) or else Is_Exported
(E
))
2816 and then Convention
(E
) /= Convention
(Formal
)
2817 and then not Has_Warnings_Off
(E
)
2818 and then not Has_Warnings_Off
(F_Type
)
2819 and then not Has_Warnings_Off
(Formal
)
2821 -- Qualify mention of formals with subprogram name
2823 Error_Msg_Qual_Level
:= 1;
2825 -- Check suspicious use of fat C pointer
2827 if Is_Access_Type
(F_Type
)
2828 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
2831 ("?x?type of & does not correspond to C pointer!", Formal
);
2833 -- Check suspicious return of boolean
2835 elsif Root_Type
(F_Type
) = Standard_Boolean
2836 and then Convention
(F_Type
) = Convention_Ada
2837 and then not Has_Warnings_Off
(F_Type
)
2838 and then not Has_Size_Clause
(F_Type
)
2839 and then VM_Target
= No_VM
2842 ("& is an 8-bit Ada Boolean?x?", Formal
);
2844 ("\use appropriate corresponding type in C "
2845 & "(e.g. char)?x?", Formal
);
2847 -- Check suspicious tagged type
2849 elsif (Is_Tagged_Type
(F_Type
)
2851 (Is_Access_Type
(F_Type
)
2852 and then Is_Tagged_Type
(Designated_Type
(F_Type
))))
2853 and then Convention
(E
) = Convention_C
2856 ("?x?& involves a tagged type which does not "
2857 & "correspond to any C type!", Formal
);
2859 -- Check wrong convention subprogram pointer
2861 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
2862 and then not Has_Foreign_Convention
(F_Type
)
2865 ("?x?subprogram pointer & should "
2866 & "have foreign convention!", Formal
);
2867 Error_Msg_Sloc
:= Sloc
(F_Type
);
2869 ("\?x?add Convention pragma to declaration of &#",
2873 -- Turn off name qualification after message output
2875 Error_Msg_Qual_Level
:= 0;
2878 -- Check for unconstrained array in exported foreign convention
2881 if Has_Foreign_Convention
(E
)
2882 and then not Is_Imported
(E
)
2883 and then Is_Array_Type
(F_Type
)
2884 and then not Is_Constrained
(F_Type
)
2885 and then Warn_On_Export_Import
2887 -- Exclude VM case, since both .NET and JVM can handle
2888 -- unconstrained arrays without a problem.
2890 and then VM_Target
= No_VM
2892 Error_Msg_Qual_Level
:= 1;
2894 -- If this is an inherited operation, place the warning on
2895 -- the derived type declaration, rather than on the original
2898 if Nkind
(Original_Node
(Parent
(E
))) = N_Full_Type_Declaration
2900 Warn_Node
:= Parent
(E
);
2902 if Formal
= First_Formal
(E
) then
2903 Error_Msg_NE
("??in inherited operation&", Warn_Node
, E
);
2906 Warn_Node
:= Formal
;
2909 Error_Msg_NE
("?x?type of argument& is unconstrained array",
2911 Error_Msg_NE
("?x?foreign caller must pass bounds explicitly",
2913 Error_Msg_Qual_Level
:= 0;
2916 if not From_Limited_With
(F_Type
) then
2917 if Is_Access_Type
(F_Type
) then
2918 F_Type
:= Designated_Type
(F_Type
);
2921 -- If the formal is an anonymous_access_to_subprogram
2922 -- freeze the subprogram type as well, to prevent
2923 -- scope anomalies in gigi, because there is no other
2924 -- clear point at which it could be frozen.
2926 if Is_Itype
(Etype
(Formal
))
2927 and then Ekind
(F_Type
) = E_Subprogram_Type
2929 Freeze_And_Append
(F_Type
, N
, Result
);
2933 Next_Formal
(Formal
);
2936 -- Case of function: similar checks on return type
2938 if Ekind
(E
) = E_Function
then
2940 -- Check whether function is declared elsewhere.
2943 Get_Source_Unit
(E
) /= Get_Source_Unit
(N
)
2944 and then Returns_Limited_View
(E
)
2945 and then not In_Open_Scopes
(Scope
(E
));
2947 -- Freeze return type
2949 R_Type
:= Etype
(E
);
2951 -- AI05-0151: the return type may have been incomplete
2952 -- at the point of declaration. Replace it with the full
2953 -- view, unless the current type is a limited view. In
2954 -- that case the full view is in a different unit, and
2955 -- gigi finds the non-limited view after the other unit
2958 if Ekind
(R_Type
) = E_Incomplete_Type
2959 and then Present
(Full_View
(R_Type
))
2960 and then not From_Limited_With
(R_Type
)
2962 R_Type
:= Full_View
(R_Type
);
2963 Set_Etype
(E
, R_Type
);
2965 -- If the return type is a limited view and the non-
2966 -- limited view is still incomplete, the function has
2967 -- to be frozen at a later time.
2969 elsif Ekind
(R_Type
) = E_Incomplete_Type
2970 and then From_Limited_With
(R_Type
)
2972 Ekind
(Non_Limited_View
(R_Type
)) = E_Incomplete_Type
2974 Set_Is_Frozen
(E
, False);
2975 Set_Returns_Limited_View
(E
);
2979 Freeze_And_Append
(R_Type
, N
, Result
);
2981 -- Check suspicious return type for C function
2983 if Warn_On_Export_Import
2984 and then (Convention
(E
) = Convention_C
2986 Convention
(E
) = Convention_CPP
)
2987 and then (Is_Imported
(E
) or else Is_Exported
(E
))
2989 -- Check suspicious return of fat C pointer
2991 if Is_Access_Type
(R_Type
)
2992 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
2993 and then not Has_Warnings_Off
(E
)
2994 and then not Has_Warnings_Off
(R_Type
)
2996 Error_Msg_N
("?x?return type of& does not "
2997 & "correspond to C pointer!", E
);
2999 -- Check suspicious return of boolean
3001 elsif Root_Type
(R_Type
) = Standard_Boolean
3002 and then Convention
(R_Type
) = Convention_Ada
3003 and then VM_Target
= No_VM
3004 and then not Has_Warnings_Off
(E
)
3005 and then not Has_Warnings_Off
(R_Type
)
3006 and then not Has_Size_Clause
(R_Type
)
3009 N
: constant Node_Id
:=
3010 Result_Definition
(Declaration_Node
(E
));
3013 ("return type of & is an 8-bit Ada Boolean?x?", N
, E
);
3015 ("\use appropriate corresponding type in C "
3016 & "(e.g. char)?x?", N
, E
);
3019 -- Check suspicious return tagged type
3021 elsif (Is_Tagged_Type
(R_Type
)
3022 or else (Is_Access_Type
(R_Type
)
3025 (Designated_Type
(R_Type
))))
3026 and then Convention
(E
) = Convention_C
3027 and then not Has_Warnings_Off
(E
)
3028 and then not Has_Warnings_Off
(R_Type
)
3030 Error_Msg_N
("?x?return type of & does not "
3031 & "correspond to C type!", E
);
3033 -- Check return of wrong convention subprogram pointer
3035 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
3036 and then not Has_Foreign_Convention
(R_Type
)
3037 and then not Has_Warnings_Off
(E
)
3038 and then not Has_Warnings_Off
(R_Type
)
3040 Error_Msg_N
("?x?& should return a foreign "
3041 & "convention subprogram pointer", E
);
3042 Error_Msg_Sloc
:= Sloc
(R_Type
);
3044 ("\?x?add Convention pragma to declaration of& #",
3049 -- Give warning for suspicious return of a result of an
3050 -- unconstrained array type in a foreign convention function.
3052 if Has_Foreign_Convention
(E
)
3054 -- We are looking for a return of unconstrained array
3056 and then Is_Array_Type
(R_Type
)
3057 and then not Is_Constrained
(R_Type
)
3059 -- Exclude imported routines, the warning does not belong on
3060 -- the import, but rather on the routine definition.
3062 and then not Is_Imported
(E
)
3064 -- Exclude VM case, since both .NET and JVM can handle return
3065 -- of unconstrained arrays without a problem.
3067 and then VM_Target
= No_VM
3069 -- Check that general warning is enabled, and that it is not
3070 -- suppressed for this particular case.
3072 and then Warn_On_Export_Import
3073 and then not Has_Warnings_Off
(E
)
3074 and then not Has_Warnings_Off
(R_Type
)
3076 Error_Msg_N
("?x?foreign convention function& should not " &
3077 "return unconstrained array!", E
);
3084 ------------------------
3085 -- Freeze_Record_Type --
3086 ------------------------
3088 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
3095 pragma Warnings
(Off
, Junk
);
3097 Rec_Pushed
: Boolean := False;
3098 -- Set True if the record type scope Rec has been pushed on the scope
3099 -- stack. Needed for the analysis of delayed aspects specified to the
3100 -- components of Rec.
3103 -- Scalar_Storage_Order attribute definition clause for the record
3105 Unplaced_Component
: Boolean := False;
3106 -- Set True if we find at least one component with no component
3107 -- clause (used to warn about useless Pack pragmas).
3109 Placed_Component
: Boolean := False;
3110 -- Set True if we find at least one component with a component
3111 -- clause (used to warn about useless Bit_Order pragmas, and also
3112 -- to detect cases where Implicit_Packing may have an effect).
3114 Aliased_Component
: Boolean := False;
3115 -- Set True if we find at least one component which is aliased. This
3116 -- is used to prevent Implicit_Packing of the record, since packing
3117 -- cannot modify the size of alignment of an aliased component.
3119 SSO_ADC_Component
: Boolean := False;
3120 -- Set True if we find at least one component whose type has a
3121 -- Scalar_Storage_Order attribute definition clause.
3123 All_Scalar_Components
: Boolean := True;
3124 -- Set False if we encounter a component of a non-scalar type
3126 Scalar_Component_Total_RM_Size
: Uint
:= Uint_0
;
3127 Scalar_Component_Total_Esize
: Uint
:= Uint_0
;
3128 -- Accumulates total RM_Size values and total Esize values of all
3129 -- scalar components. Used for processing of Implicit_Packing.
3131 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
3132 -- If N is an allocator, possibly wrapped in one or more level of
3133 -- qualified expression(s), return the inner allocator node, else
3136 procedure Check_Itype
(Typ
: Entity_Id
);
3137 -- If the component subtype is an access to a constrained subtype of
3138 -- an already frozen type, make the subtype frozen as well. It might
3139 -- otherwise be frozen in the wrong scope, and a freeze node on
3140 -- subtype has no effect. Similarly, if the component subtype is a
3141 -- regular (not protected) access to subprogram, set the anonymous
3142 -- subprogram type to frozen as well, to prevent an out-of-scope
3143 -- freeze node at some eventual point of call. Protected operations
3144 -- are handled elsewhere.
3146 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
3147 -- Make sure that all types mentioned in Discrete_Choices of the
3148 -- variants referenceed by the Variant_Part VP are frozen. This is
3149 -- a recursive routine to deal with nested variants.
3151 ---------------------
3152 -- Check_Allocator --
3153 ---------------------
3155 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
3160 if Nkind
(Inner
) = N_Allocator
then
3162 elsif Nkind
(Inner
) = N_Qualified_Expression
then
3163 Inner
:= Expression
(Inner
);
3168 end Check_Allocator
;
3174 procedure Check_Itype
(Typ
: Entity_Id
) is
3175 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
3178 if not Is_Frozen
(Desig
)
3179 and then Is_Frozen
(Base_Type
(Desig
))
3181 Set_Is_Frozen
(Desig
);
3183 -- In addition, add an Itype_Reference to ensure that the
3184 -- access subtype is elaborated early enough. This cannot be
3185 -- done if the subtype may depend on discriminants.
3187 if Ekind
(Comp
) = E_Component
3188 and then Is_Itype
(Etype
(Comp
))
3189 and then not Has_Discriminants
(Rec
)
3191 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
3192 Set_Itype
(IR
, Desig
);
3196 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
3197 and then Convention
(Desig
) /= Convention_Protected
3199 Set_Is_Frozen
(Desig
);
3203 ------------------------------------
3204 -- Freeze_Choices_In_Variant_Part --
3205 ------------------------------------
3207 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
3208 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
3215 -- Loop through variants
3217 Variant
:= First_Non_Pragma
(Variants
(VP
));
3218 while Present
(Variant
) loop
3220 -- Loop through choices, checking that all types are frozen
3222 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
3223 while Present
(Choice
) loop
3224 if Nkind
(Choice
) in N_Has_Etype
3225 and then Present
(Etype
(Choice
))
3227 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
3230 Next_Non_Pragma
(Choice
);
3233 -- Check for nested variant part to process
3235 CL
:= Component_List
(Variant
);
3237 if not Null_Present
(CL
) then
3238 if Present
(Variant_Part
(CL
)) then
3239 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
3243 Next_Non_Pragma
(Variant
);
3245 end Freeze_Choices_In_Variant_Part
;
3247 -- Start of processing for Freeze_Record_Type
3250 -- Deal with delayed aspect specifications for components. The
3251 -- analysis of the aspect is required to be delayed to the freeze
3252 -- point, thus we analyze the pragma or attribute definition
3253 -- clause in the tree at this point. We also analyze the aspect
3254 -- specification node at the freeze point when the aspect doesn't
3255 -- correspond to pragma/attribute definition clause.
3257 Comp
:= First_Entity
(Rec
);
3258 while Present
(Comp
) loop
3259 if Ekind
(Comp
) = E_Component
3260 and then Has_Delayed_Aspects
(Comp
)
3262 if not Rec_Pushed
then
3266 -- The visibility to the discriminants must be restored in
3267 -- order to properly analyze the aspects.
3269 if Has_Discriminants
(Rec
) then
3270 Install_Discriminants
(Rec
);
3274 Analyze_Aspects_At_Freeze_Point
(Comp
);
3280 -- Pop the scope if Rec scope has been pushed on the scope stack
3281 -- during the delayed aspect analysis process.
3284 if Has_Discriminants
(Rec
) then
3285 Uninstall_Discriminants
(Rec
);
3291 -- Freeze components and embedded subtypes
3293 Comp
:= First_Entity
(Rec
);
3295 while Present
(Comp
) loop
3296 if Is_Aliased
(Comp
) then
3297 Aliased_Component
:= True;
3300 -- Handle the component and discriminant case
3302 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
3304 CC
: constant Node_Id
:= Component_Clause
(Comp
);
3307 -- Freezing a record type freezes the type of each of its
3308 -- components. However, if the type of the component is
3309 -- part of this record, we do not want or need a separate
3310 -- Freeze_Node. Note that Is_Itype is wrong because that's
3311 -- also set in private type cases. We also can't check for
3312 -- the Scope being exactly Rec because of private types and
3313 -- record extensions.
3315 if Is_Itype
(Etype
(Comp
))
3316 and then Is_Record_Type
(Underlying_Type
3317 (Scope
(Etype
(Comp
))))
3319 Undelay_Type
(Etype
(Comp
));
3322 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
3324 -- Warn for pragma Pack overriding foreign convention
3326 if Has_Foreign_Convention
(Etype
(Comp
))
3327 and then Has_Pragma_Pack
(Rec
)
3329 -- Don't warn for aliased components, since override
3330 -- cannot happen in that case.
3332 and then not Is_Aliased
(Comp
)
3335 CN
: constant Name_Id
:=
3336 Get_Convention_Name
(Convention
(Etype
(Comp
)));
3337 PP
: constant Node_Id
:=
3338 Get_Pragma
(Rec
, Pragma_Pack
);
3340 if Present
(PP
) then
3341 Error_Msg_Name_1
:= CN
;
3342 Error_Msg_Sloc
:= Sloc
(Comp
);
3344 ("pragma Pack affects convention % component#??",
3346 Error_Msg_Name_1
:= CN
;
3348 ("\component & may not have % compatible "
3349 & "representation??", PP
, Comp
);
3354 -- Check for error of component clause given for variable
3355 -- sized type. We have to delay this test till this point,
3356 -- since the component type has to be frozen for us to know
3357 -- if it is variable length.
3359 if Present
(CC
) then
3360 Placed_Component
:= True;
3362 -- We omit this test in a generic context, it will be
3363 -- applied at instantiation time.
3365 if Inside_A_Generic
then
3368 -- Also omit this test in CodePeer mode, since we do not
3369 -- have sufficient info on size and rep clauses.
3371 elsif CodePeer_Mode
then
3374 -- Omit check if component has a generic type. This can
3375 -- happen in an instantiation within a generic in ASIS
3376 -- mode, where we force freeze actions without full
3379 elsif Is_Generic_Type
(Etype
(Comp
)) then
3385 Size_Known_At_Compile_Time
3386 (Underlying_Type
(Etype
(Comp
)))
3389 ("component clause not allowed for variable " &
3390 "length component", CC
);
3394 Unplaced_Component
:= True;
3397 -- Case of component requires byte alignment
3399 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
3401 -- Set the enclosing record to also require byte align
3403 Set_Must_Be_On_Byte_Boundary
(Rec
);
3405 -- Check for component clause that is inconsistent with
3406 -- the required byte boundary alignment.
3409 and then Normalized_First_Bit
(Comp
) mod
3410 System_Storage_Unit
/= 0
3413 ("component & must be byte aligned",
3414 Component_Name
(Component_Clause
(Comp
)));
3420 -- Gather data for possible Implicit_Packing later. Note that at
3421 -- this stage we might be dealing with a real component, or with
3422 -- an implicit subtype declaration.
3424 if not Is_Scalar_Type
(Etype
(Comp
)) then
3425 All_Scalar_Components
:= False;
3427 Scalar_Component_Total_RM_Size
:=
3428 Scalar_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
3429 Scalar_Component_Total_Esize
:=
3430 Scalar_Component_Total_Esize
+ Esize
(Etype
(Comp
));
3433 -- If the component is an Itype with Delayed_Freeze and is either
3434 -- a record or array subtype and its base type has not yet been
3435 -- frozen, we must remove this from the entity list of this record
3436 -- and put it on the entity list of the scope of its base type.
3437 -- Note that we know that this is not the type of a component
3438 -- since we cleared Has_Delayed_Freeze for it in the previous
3439 -- loop. Thus this must be the Designated_Type of an access type,
3440 -- which is the type of a component.
3443 and then Is_Type
(Scope
(Comp
))
3444 and then Is_Composite_Type
(Comp
)
3445 and then Base_Type
(Comp
) /= Comp
3446 and then Has_Delayed_Freeze
(Comp
)
3447 and then not Is_Frozen
(Base_Type
(Comp
))
3450 Will_Be_Frozen
: Boolean := False;
3454 -- We have a difficult case to handle here. Suppose Rec is
3455 -- subtype being defined in a subprogram that's created as
3456 -- part of the freezing of Rec'Base. In that case, we know
3457 -- that Comp'Base must have already been frozen by the time
3458 -- we get to elaborate this because Gigi doesn't elaborate
3459 -- any bodies until it has elaborated all of the declarative
3460 -- part. But Is_Frozen will not be set at this point because
3461 -- we are processing code in lexical order.
3463 -- We detect this case by going up the Scope chain of Rec
3464 -- and seeing if we have a subprogram scope before reaching
3465 -- the top of the scope chain or that of Comp'Base. If we
3466 -- do, then mark that Comp'Base will actually be frozen. If
3467 -- so, we merely undelay it.
3470 while Present
(S
) loop
3471 if Is_Subprogram
(S
) then
3472 Will_Be_Frozen
:= True;
3474 elsif S
= Scope
(Base_Type
(Comp
)) then
3481 if Will_Be_Frozen
then
3482 Undelay_Type
(Comp
);
3485 if Present
(Prev
) then
3486 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
3488 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
3491 -- Insert in entity list of scope of base type (which
3492 -- must be an enclosing scope, because still unfrozen).
3494 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
3498 -- If the component is an access type with an allocator as default
3499 -- value, the designated type will be frozen by the corresponding
3500 -- expression in init_proc. In order to place the freeze node for
3501 -- the designated type before that for the current record type,
3504 -- Same process if the component is an array of access types,
3505 -- initialized with an aggregate. If the designated type is
3506 -- private, it cannot contain allocators, and it is premature
3507 -- to freeze the type, so we check for this as well.
3509 elsif Is_Access_Type
(Etype
(Comp
))
3510 and then Present
(Parent
(Comp
))
3511 and then Present
(Expression
(Parent
(Comp
)))
3514 Alloc
: constant Node_Id
:=
3515 Check_Allocator
(Expression
(Parent
(Comp
)));
3518 if Present
(Alloc
) then
3520 -- If component is pointer to a class-wide type, freeze
3521 -- the specific type in the expression being allocated.
3522 -- The expression may be a subtype indication, in which
3523 -- case freeze the subtype mark.
3525 if Is_Class_Wide_Type
3526 (Designated_Type
(Etype
(Comp
)))
3528 if Is_Entity_Name
(Expression
(Alloc
)) then
3530 (Entity
(Expression
(Alloc
)), N
, Result
);
3532 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
3535 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
3539 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
3540 Check_Itype
(Etype
(Comp
));
3544 (Designated_Type
(Etype
(Comp
)), N
, Result
);
3549 elsif Is_Access_Type
(Etype
(Comp
))
3550 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
3552 Check_Itype
(Etype
(Comp
));
3554 -- Freeze the designated type when initializing a component with
3555 -- an aggregate in case the aggregate contains allocators.
3558 -- type T_Ptr is access all T;
3559 -- type T_Array is array ... of T_Ptr;
3561 -- type Rec is record
3562 -- Comp : T_Array := (others => ...);
3565 elsif Is_Array_Type
(Etype
(Comp
))
3566 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
3569 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
3570 Desig_Typ
: constant Entity_Id
:=
3572 (Component_Type
(Etype
(Comp
)));
3575 -- The only case when this sort of freezing is not done is
3576 -- when the designated type is class-wide and the root type
3577 -- is the record owning the component. This scenario results
3578 -- in a circularity because the class-wide type requires
3579 -- primitives that have not been created yet as the root
3580 -- type is in the process of being frozen.
3582 -- type Rec is tagged;
3583 -- type Rec_Ptr is access all Rec'Class;
3584 -- type Rec_Array is array ... of Rec_Ptr;
3586 -- type Rec is record
3587 -- Comp : Rec_Array := (others => ...);
3590 if Is_Class_Wide_Type
(Desig_Typ
)
3591 and then Root_Type
(Desig_Typ
) = Rec
3595 elsif Is_Fully_Defined
(Desig_Typ
)
3596 and then Present
(Comp_Par
)
3597 and then Nkind
(Comp_Par
) = N_Component_Declaration
3598 and then Present
(Expression
(Comp_Par
))
3599 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
3601 Freeze_And_Append
(Desig_Typ
, N
, Result
);
3610 -- Deal with default setting of reverse storage order
3612 Set_SSO_From_Default
(Rec
);
3614 -- Check consistent attribute setting on component types
3616 SSO_ADC
:= Get_Attribute_Definition_Clause
3617 (Rec
, Attribute_Scalar_Storage_Order
);
3620 Comp_ADC_Present
: Boolean;
3622 Comp
:= First_Component
(Rec
);
3623 while Present
(Comp
) loop
3624 Check_Component_Storage_Order
3628 Comp_ADC_Present
=> Comp_ADC_Present
);
3629 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
3630 Next_Component
(Comp
);
3634 -- Now deal with reverse storage order/bit order issues
3636 if Present
(SSO_ADC
) then
3638 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
3639 -- the former is specified.
3641 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
3643 -- Note: report error on Rec, not on SSO_ADC, as ADC may apply
3644 -- to some ancestor type.
3646 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
3648 ("scalar storage order for& specified# inconsistent with "
3649 & "bit order", Rec
);
3652 -- Warn if there is an Scalar_Storage_Order attribute definition
3653 -- clause but no component clause, no component that itself has
3654 -- such an attribute definition, and no pragma Pack.
3656 if not (Placed_Component
3663 ("??scalar storage order specified but no component clause",
3668 -- Deal with Bit_Order aspect
3670 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
3672 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
3673 if not (Placed_Component
3674 or else Present
(SSO_ADC
)
3675 or else Is_Packed
(Rec
))
3677 -- Warn if clause has no effect when no component clause is
3678 -- present, but suppress warning if the Bit_Order is required
3679 -- due to the presence of a Scalar_Storage_Order attribute.
3682 ("??bit order specification has no effect", ADC
);
3684 ("\??since no component clauses were specified", ADC
);
3686 -- Here is where we do the processing to adjust component clauses
3687 -- for reversed bit order, when not using reverse SSO.
3689 elsif Reverse_Bit_Order
(Rec
)
3690 and then not Reverse_Storage_Order
(Rec
)
3692 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
3694 -- Case where we have both an explicit Bit_Order and the same
3695 -- Scalar_Storage_Order: leave record untouched, the back-end
3696 -- will take care of required layout conversions.
3704 -- Complete error checking on record representation clause (e.g.
3705 -- overlap of components). This is called after adjusting the
3706 -- record for reverse bit order.
3709 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
3711 if Present
(RRC
) then
3712 Check_Record_Representation_Clause
(RRC
);
3716 -- Set OK_To_Reorder_Components depending on debug flags
3718 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
3719 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
3721 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
3723 Set_OK_To_Reorder_Components
(Rec
);
3727 -- Check for useless pragma Pack when all components placed. We only
3728 -- do this check for record types, not subtypes, since a subtype may
3729 -- have all its components placed, and it still makes perfectly good
3730 -- sense to pack other subtypes or the parent type. We do not give
3731 -- this warning if Optimize_Alignment is set to Space, since the
3732 -- pragma Pack does have an effect in this case (it always resets
3733 -- the alignment to one).
3735 if Ekind
(Rec
) = E_Record_Type
3736 and then Is_Packed
(Rec
)
3737 and then not Unplaced_Component
3738 and then Optimize_Alignment
/= 'S'
3740 -- Reset packed status. Probably not necessary, but we do it so
3741 -- that there is no chance of the back end doing something strange
3742 -- with this redundant indication of packing.
3744 Set_Is_Packed
(Rec
, False);
3746 -- Give warning if redundant constructs warnings on
3748 if Warn_On_Redundant_Constructs
then
3749 Error_Msg_N
-- CODEFIX
3750 ("??pragma Pack has no effect, no unplaced components",
3751 Get_Rep_Pragma
(Rec
, Name_Pack
));
3755 -- If this is the record corresponding to a remote type, freeze the
3756 -- remote type here since that is what we are semantically freezing.
3757 -- This prevents the freeze node for that type in an inner scope.
3759 if Ekind
(Rec
) = E_Record_Type
then
3760 if Present
(Corresponding_Remote_Type
(Rec
)) then
3761 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
3764 -- Check for controlled components and unchecked unions.
3766 Comp
:= First_Component
(Rec
);
3767 while Present
(Comp
) loop
3769 -- Do not set Has_Controlled_Component on a class-wide
3770 -- equivalent type. See Make_CW_Equivalent_Type.
3772 if not Is_Class_Wide_Equivalent_Type
(Rec
)
3774 (Has_Controlled_Component
(Etype
(Comp
))
3776 (Chars
(Comp
) /= Name_uParent
3777 and then Is_Controlled
(Etype
(Comp
)))
3779 (Is_Protected_Type
(Etype
(Comp
))
3781 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
3783 Has_Controlled_Component
3784 (Corresponding_Record_Type
(Etype
(Comp
)))))
3786 Set_Has_Controlled_Component
(Rec
);
3789 if Has_Unchecked_Union
(Etype
(Comp
)) then
3790 Set_Has_Unchecked_Union
(Rec
);
3793 -- Scan component declaration for likely misuses of current
3794 -- instance, either in a constraint or a default expression.
3796 if Has_Per_Object_Constraint
(Comp
) then
3797 Check_Current_Instance
(Parent
(Comp
));
3800 Next_Component
(Comp
);
3804 -- Enforce the restriction that access attributes with a current
3805 -- instance prefix can only apply to limited types. This comment
3806 -- is floating here, but does not seem to belong here???
3808 -- Set component alignment if not otherwise already set
3810 Set_Component_Alignment_If_Not_Set
(Rec
);
3812 -- For first subtypes, check if there are any fixed-point fields with
3813 -- component clauses, where we must check the size. This is not done
3814 -- till the freeze point since for fixed-point types, we do not know
3815 -- the size until the type is frozen. Similar processing applies to
3816 -- bit packed arrays.
3818 if Is_First_Subtype
(Rec
) then
3819 Comp
:= First_Component
(Rec
);
3820 while Present
(Comp
) loop
3821 if Present
(Component_Clause
(Comp
))
3822 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
3823 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
3826 (Component_Name
(Component_Clause
(Comp
)),
3832 Next_Component
(Comp
);
3836 -- Generate warning for applying C or C++ convention to a record
3837 -- with discriminants. This is suppressed for the unchecked union
3838 -- case, since the whole point in this case is interface C. We also
3839 -- do not generate this within instantiations, since we will have
3840 -- generated a message on the template.
3842 if Has_Discriminants
(E
)
3843 and then not Is_Unchecked_Union
(E
)
3844 and then (Convention
(E
) = Convention_C
3846 Convention
(E
) = Convention_CPP
)
3847 and then Comes_From_Source
(E
)
3848 and then not In_Instance
3849 and then not Has_Warnings_Off
(E
)
3850 and then not Has_Warnings_Off
(Base_Type
(E
))
3853 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
3857 if Present
(Cprag
) then
3858 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3860 if Convention
(E
) = Convention_C
then
3862 ("?x?variant record has no direct equivalent in C",
3866 ("?x?variant record has no direct equivalent in C++",
3871 ("\?x?use of convention for type& is dubious", A2
, E
);
3876 -- See if Size is too small as is (and implicit packing might help)
3878 if not Is_Packed
(Rec
)
3880 -- No implicit packing if even one component is explicitly placed
3882 and then not Placed_Component
3884 -- Or even one component is aliased
3886 and then not Aliased_Component
3888 -- Must have size clause and all scalar components
3890 and then Has_Size_Clause
(Rec
)
3891 and then All_Scalar_Components
3893 -- Do not try implicit packing on records with discriminants, too
3894 -- complicated, especially in the variant record case.
3896 and then not Has_Discriminants
(Rec
)
3898 -- We can implicitly pack if the specified size of the record is
3899 -- less than the sum of the object sizes (no point in packing if
3900 -- this is not the case).
3902 and then RM_Size
(Rec
) < Scalar_Component_Total_Esize
3904 -- And the total RM size cannot be greater than the specified size
3905 -- since otherwise packing will not get us where we have to be.
3907 and then RM_Size
(Rec
) >= Scalar_Component_Total_RM_Size
3909 -- Never do implicit packing in CodePeer or SPARK modes since
3910 -- we don't do any packing in these modes, since this generates
3911 -- over-complex code that confuses static analysis, and in
3912 -- general, neither CodePeer not GNATprove care about the
3913 -- internal representation of objects.
3915 and then not (CodePeer_Mode
or GNATprove_Mode
)
3917 -- If implicit packing enabled, do it
3919 if Implicit_Packing
then
3920 Set_Is_Packed
(Rec
);
3922 -- Otherwise flag the size clause
3926 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
3928 Error_Msg_NE
-- CODEFIX
3929 ("size given for& too small", Sz
, Rec
);
3930 Error_Msg_N
-- CODEFIX
3931 ("\use explicit pragma Pack "
3932 & "or use pragma Implicit_Packing", Sz
);
3937 -- The following checks are only relevant when SPARK_Mode is on as
3938 -- they are not standard Ada legality rules.
3940 if SPARK_Mode
= On
then
3941 if Is_Effectively_Volatile
(Rec
) then
3943 -- A discriminated type cannot be effectively volatile
3944 -- (SPARK RM C.6(4)).
3946 if Has_Discriminants
(Rec
) then
3947 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
3949 -- A tagged type cannot be effectively volatile
3950 -- (SPARK RM C.6(5)).
3952 elsif Is_Tagged_Type
(Rec
) then
3953 Error_Msg_N
("tagged type & cannot be volatile", Rec
);
3956 -- A non-effectively volatile record type cannot contain
3957 -- effectively volatile components (SPARK RM C.6(2)).
3960 Comp
:= First_Component
(Rec
);
3961 while Present
(Comp
) loop
3962 if Comes_From_Source
(Comp
)
3963 and then Is_Effectively_Volatile
(Etype
(Comp
))
3965 Error_Msg_Name_1
:= Chars
(Rec
);
3967 ("component & of non-volatile type % cannot be "
3968 & "volatile", Comp
);
3971 Next_Component
(Comp
);
3976 -- All done if not a full record definition
3978 if Ekind
(Rec
) /= E_Record_Type
then
3982 -- Finally we need to check the variant part to make sure that
3983 -- all types within choices are properly frozen as part of the
3984 -- freezing of the record type.
3986 Check_Variant_Part
: declare
3987 D
: constant Node_Id
:= Declaration_Node
(Rec
);
3992 -- Find component list
3996 if Nkind
(D
) = N_Full_Type_Declaration
then
3997 T
:= Type_Definition
(D
);
3999 if Nkind
(T
) = N_Record_Definition
then
4000 C
:= Component_List
(T
);
4002 elsif Nkind
(T
) = N_Derived_Type_Definition
4003 and then Present
(Record_Extension_Part
(T
))
4005 C
:= Component_List
(Record_Extension_Part
(T
));
4009 -- Case of variant part present
4011 if Present
(C
) and then Present
(Variant_Part
(C
)) then
4012 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
4015 -- Note: we used to call Check_Choices here, but it is too early,
4016 -- since predicated subtypes are frozen here, but their freezing
4017 -- actions are in Analyze_Freeze_Entity, which has not been called
4018 -- yet for entities frozen within this procedure, so we moved that
4019 -- call to the Analyze_Freeze_Entity for the record type.
4021 end Check_Variant_Part
;
4023 -- Check that all the primitives of an interface type are abstract
4024 -- or null procedures.
4026 if Is_Interface
(Rec
)
4027 and then not Error_Posted
(Parent
(Rec
))
4034 Elmt
:= First_Elmt
(Primitive_Operations
(Rec
));
4035 while Present
(Elmt
) loop
4036 Subp
:= Node
(Elmt
);
4038 if not Is_Abstract_Subprogram
(Subp
)
4040 -- Avoid reporting the error on inherited primitives
4042 and then Comes_From_Source
(Subp
)
4044 Error_Msg_Name_1
:= Chars
(Subp
);
4046 if Ekind
(Subp
) = E_Procedure
then
4047 if not Null_Present
(Parent
(Subp
)) then
4049 ("interface procedure % must be abstract or null",
4054 ("interface function % must be abstract",
4063 end Freeze_Record_Type
;
4065 -------------------------------
4066 -- Has_Boolean_Aspect_Import --
4067 -------------------------------
4069 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
4070 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4075 if Has_Aspects
(Decl
) then
4076 Asp
:= First
(Aspect_Specifications
(Decl
));
4077 while Present
(Asp
) loop
4078 Expr
:= Expression
(Asp
);
4080 -- The value of aspect Import is True when the expression is
4081 -- either missing or it is explicitly set to True.
4083 if Get_Aspect_Id
(Asp
) = Aspect_Import
4085 or else (Compile_Time_Known_Value
(Expr
)
4086 and then Is_True
(Expr_Value
(Expr
))))
4096 end Has_Boolean_Aspect_Import
;
4098 ----------------------------
4099 -- Late_Freeze_Subprogram --
4100 ----------------------------
4102 procedure Late_Freeze_Subprogram
(E
: Entity_Id
) is
4103 Spec
: constant Node_Id
:=
4104 Specification
(Unit_Declaration_Node
(Scope
(E
)));
4108 if Present
(Private_Declarations
(Spec
)) then
4109 Decls
:= Private_Declarations
(Spec
);
4111 Decls
:= Visible_Declarations
(Spec
);
4114 Append_List
(Result
, Decls
);
4115 end Late_Freeze_Subprogram
;
4117 ------------------------------
4118 -- Wrap_Imported_Subprogram --
4119 ------------------------------
4121 -- The issue here is that our normal approach of checking preconditions
4122 -- and postconditions does not work for imported procedures, since we
4123 -- are not generating code for the body. To get around this we create
4124 -- a wrapper, as shown by the following example:
4126 -- procedure K (A : Integer);
4127 -- pragma Import (C, K);
4129 -- The spec is rewritten by removing the effects of pragma Import, but
4130 -- leaving the convention unchanged, as though the source had said:
4132 -- procedure K (A : Integer);
4133 -- pragma Convention (C, K);
4135 -- and we create a body, added to the entity K freeze actions, which
4138 -- procedure K (A : Integer) is
4139 -- procedure K (A : Integer);
4140 -- pragma Import (C, K);
4145 -- Now the contract applies in the normal way to the outer procedure,
4146 -- and the inner procedure has no contracts, so there is no problem
4147 -- in just calling it to get the original effect.
4149 -- In the case of a function, we create an appropriate return statement
4150 -- for the subprogram body that calls the inner procedure.
4152 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
4153 Loc
: constant Source_Ptr
:= Sloc
(E
);
4154 CE
: constant Name_Id
:= Chars
(E
);
4163 -- Nothing to do if not imported
4165 if not Is_Imported
(E
) then
4168 -- Test enabling conditions for wrapping
4170 elsif Is_Subprogram
(E
)
4171 and then Present
(Contract
(E
))
4172 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
4173 and then not GNATprove_Mode
4175 -- Here we do the wrap
4177 -- Note on calls to Copy_Separate_Tree. The trees we are copying
4178 -- here are fully analyzed, but we definitely want fully syntactic
4179 -- unanalyzed trees in the body we construct, so that the analysis
4180 -- generates the right visibility, and that is exactly what the
4181 -- calls to Copy_Separate_Tree give us.
4183 -- Acquire copy of Inline pragma
4185 Iprag
:= Copy_Separate_Tree
(Import_Pragma
(E
));
4187 -- Fix up spec to be not imported any more
4189 Set_Is_Imported
(E
, False);
4190 Set_Interface_Name
(E
, Empty
);
4191 Set_Has_Completion
(E
, False);
4192 Set_Import_Pragma
(E
, Empty
);
4194 -- Grab the subprogram declaration and specification
4196 Spec
:= Declaration_Node
(E
);
4198 -- Build parameter list that we need
4201 Forml
:= First_Formal
(E
);
4202 while Present
(Forml
) loop
4203 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
4204 Next_Formal
(Forml
);
4209 if Ekind_In
(E
, E_Function
, E_Generic_Function
) then
4211 Make_Simple_Return_Statement
(Loc
,
4213 Make_Function_Call
(Loc
,
4214 Name
=> Make_Identifier
(Loc
, CE
),
4215 Parameter_Associations
=> Parms
));
4219 Make_Procedure_Call_Statement
(Loc
,
4220 Name
=> Make_Identifier
(Loc
, CE
),
4221 Parameter_Associations
=> Parms
);
4224 -- Now build the body
4227 Make_Subprogram_Body
(Loc
,
4229 Copy_Separate_Tree
(Spec
),
4230 Declarations
=> New_List
(
4231 Make_Subprogram_Declaration
(Loc
,
4233 Copy_Separate_Tree
(Spec
)),
4235 Handled_Statement_Sequence
=>
4236 Make_Handled_Sequence_Of_Statements
(Loc
,
4237 Statements
=> New_List
(Stmt
),
4238 End_Label
=> Make_Identifier
(Loc
, CE
)));
4240 -- Append the body to freeze result
4242 Add_To_Result
(Bod
);
4245 -- Case of imported subprogram that does not get wrapped
4248 -- Set Is_Public. All imported entities need an external symbol
4249 -- created for them since they are always referenced from another
4250 -- object file. Note this used to be set when we set Is_Imported
4251 -- back in Sem_Prag, but now we delay it to this point, since we
4252 -- don't want to set this flag if we wrap an imported subprogram.
4256 end Wrap_Imported_Subprogram
;
4258 -- Start of processing for Freeze_Entity
4261 -- We are going to test for various reasons why this entity need not be
4262 -- frozen here, but in the case of an Itype that's defined within a
4263 -- record, that test actually applies to the record.
4265 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
4266 Test_E
:= Scope
(E
);
4267 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
4268 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
4270 Test_E
:= Underlying_Type
(Scope
(E
));
4273 -- Do not freeze if already frozen since we only need one freeze node
4275 if Is_Frozen
(E
) then
4278 -- It is improper to freeze an external entity within a generic because
4279 -- its freeze node will appear in a non-valid context. The entity will
4280 -- be frozen in the proper scope after the current generic is analyzed.
4281 -- However, aspects must be analyzed because they may be queried later
4282 -- within the generic itself, and the corresponding pragma or attribute
4283 -- definition has not been analyzed yet.
4285 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
4286 if Has_Delayed_Aspects
(E
) then
4287 Analyze_Aspects_At_Freeze_Point
(E
);
4292 -- AI05-0213: A formal incomplete type does not freeze the actual. In
4293 -- the instance, the same applies to the subtype renaming the actual.
4295 elsif Is_Private_Type
(E
)
4296 and then Is_Generic_Actual_Type
(E
)
4297 and then No
(Full_View
(Base_Type
(E
)))
4298 and then Ada_Version
>= Ada_2012
4302 -- Formal subprograms are never frozen
4304 elsif Is_Formal_Subprogram
(E
) then
4307 -- Generic types are never frozen as they lack delayed semantic checks
4309 elsif Is_Generic_Type
(E
) then
4312 -- Do not freeze a global entity within an inner scope created during
4313 -- expansion. A call to subprogram E within some internal procedure
4314 -- (a stream attribute for example) might require freezing E, but the
4315 -- freeze node must appear in the same declarative part as E itself.
4316 -- The two-pass elaboration mechanism in gigi guarantees that E will
4317 -- be frozen before the inner call is elaborated. We exclude constants
4318 -- from this test, because deferred constants may be frozen early, and
4319 -- must be diagnosed (e.g. in the case of a deferred constant being used
4320 -- in a default expression). If the enclosing subprogram comes from
4321 -- source, or is a generic instance, then the freeze point is the one
4322 -- mandated by the language, and we freeze the entity. A subprogram that
4323 -- is a child unit body that acts as a spec does not have a spec that
4324 -- comes from source, but can only come from source.
4326 elsif In_Open_Scopes
(Scope
(Test_E
))
4327 and then Scope
(Test_E
) /= Current_Scope
4328 and then Ekind
(Test_E
) /= E_Constant
4335 while Present
(S
) loop
4336 if Is_Overloadable
(S
) then
4337 if Comes_From_Source
(S
)
4338 or else Is_Generic_Instance
(S
)
4339 or else Is_Child_Unit
(S
)
4351 -- Similarly, an inlined instance body may make reference to global
4352 -- entities, but these references cannot be the proper freezing point
4353 -- for them, and in the absence of inlining freezing will take place in
4354 -- their own scope. Normally instance bodies are analyzed after the
4355 -- enclosing compilation, and everything has been frozen at the proper
4356 -- place, but with front-end inlining an instance body is compiled
4357 -- before the end of the enclosing scope, and as a result out-of-order
4358 -- freezing must be prevented.
4360 elsif Front_End_Inlining
4361 and then In_Instance_Body
4362 and then Present
(Scope
(Test_E
))
4368 S
:= Scope
(Test_E
);
4369 while Present
(S
) loop
4370 if Is_Generic_Instance
(S
) then
4382 elsif Ekind
(E
) = E_Generic_Package
then
4383 return Freeze_Generic_Entities
(E
);
4386 -- Add checks to detect proper initialization of scalars that may appear
4387 -- as subprogram parameters.
4389 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
4390 Apply_Parameter_Validity_Checks
(E
);
4393 -- Deal with delayed aspect specifications. The analysis of the aspect
4394 -- is required to be delayed to the freeze point, thus we analyze the
4395 -- pragma or attribute definition clause in the tree at this point. We
4396 -- also analyze the aspect specification node at the freeze point when
4397 -- the aspect doesn't correspond to pragma/attribute definition clause.
4399 if Has_Delayed_Aspects
(E
) then
4400 Analyze_Aspects_At_Freeze_Point
(E
);
4403 -- Here to freeze the entity
4407 -- Case of entity being frozen is other than a type
4409 if not Is_Type
(E
) then
4411 -- If entity is exported or imported and does not have an external
4412 -- name, now is the time to provide the appropriate default name.
4413 -- Skip this if the entity is stubbed, since we don't need a name
4414 -- for any stubbed routine. For the case on intrinsics, if no
4415 -- external name is specified, then calls will be handled in
4416 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
4417 -- external name is provided, then Expand_Intrinsic_Call leaves
4418 -- calls in place for expansion by GIGI.
4420 if (Is_Imported
(E
) or else Is_Exported
(E
))
4421 and then No
(Interface_Name
(E
))
4422 and then Convention
(E
) /= Convention_Stubbed
4423 and then Convention
(E
) /= Convention_Intrinsic
4425 Set_Encoded_Interface_Name
4426 (E
, Get_Default_External_Name
(E
));
4428 -- If entity is an atomic object appearing in a declaration and
4429 -- the expression is an aggregate, assign it to a temporary to
4430 -- ensure that the actual assignment is done atomically rather
4431 -- than component-wise (the assignment to the temp may be done
4432 -- component-wise, but that is harmless).
4435 and then Nkind
(Parent
(E
)) = N_Object_Declaration
4436 and then Present
(Expression
(Parent
(E
)))
4437 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
4438 and then Is_Atomic_Aggregate
(Expression
(Parent
(E
)), Etype
(E
))
4445 if Is_Subprogram
(E
) then
4447 -- Check for needing to wrap imported subprogram
4449 Wrap_Imported_Subprogram
(E
);
4451 -- Freeze all parameter types and the return type (RM 13.14(14)).
4452 -- However skip this for internal subprograms. This is also where
4453 -- any extra formal parameters are created since we now know
4454 -- whether the subprogram will use a foreign convention.
4456 -- In Ada 2012, freezing a subprogram does not always freeze
4457 -- the corresponding profile (see AI05-019). An attribute
4458 -- reference is not a freezing point of the profile.
4459 -- Other constructs that should not freeze ???
4461 -- This processing doesn't apply to internal entities (see below)
4463 if not Is_Internal
(E
) then
4464 if not Freeze_Profile
(E
) then
4469 -- Must freeze its parent first if it is a derived subprogram
4471 if Present
(Alias
(E
)) then
4472 Freeze_And_Append
(Alias
(E
), N
, Result
);
4475 -- We don't freeze internal subprograms, because we don't normally
4476 -- want addition of extra formals or mechanism setting to happen
4477 -- for those. However we do pass through predefined dispatching
4478 -- cases, since extra formals may be needed in some cases, such as
4479 -- for the stream 'Input function (build-in-place formals).
4481 if not Is_Internal
(E
)
4482 or else Is_Predefined_Dispatching_Operation
(E
)
4484 Freeze_Subprogram
(E
);
4487 if Late_Freezing
then
4488 Late_Freeze_Subprogram
(E
);
4492 -- If warning on suspicious contracts then check for the case of
4493 -- a postcondition other than False for a No_Return subprogram.
4496 and then Warn_On_Suspicious_Contract
4497 and then Present
(Contract
(E
))
4500 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
4504 while Present
(Prag
) loop
4505 if Nam_In
(Pragma_Name
(Prag
), Name_Post
,
4511 (First
(Pragma_Argument_Associations
(Prag
)));
4513 if Nkind
(Exp
) /= N_Identifier
4514 or else Chars
(Exp
) /= Name_False
4517 ("useless postcondition, & is marked "
4518 & "No_Return?T?", Exp
, E
);
4522 Prag
:= Next_Pragma
(Prag
);
4527 -- Here for other than a subprogram or type
4530 -- If entity has a type, and it is not a generic unit, then
4531 -- freeze it first (RM 13.14(10)).
4533 if Present
(Etype
(E
))
4534 and then Ekind
(E
) /= E_Generic_Function
4536 Freeze_And_Append
(Etype
(E
), N
, Result
);
4538 -- For an object of an anonymous array type, aspects on the
4539 -- object declaration apply to the type itself. This is the
4540 -- case for Atomic_Components, Volatile_Components, and
4541 -- Independent_Components. In these cases analysis of the
4542 -- generated pragma will mark the anonymous types accordingly,
4543 -- and the object itself does not require a freeze node.
4545 if Ekind
(E
) = E_Variable
4546 and then Is_Itype
(Etype
(E
))
4547 and then Is_Array_Type
(Etype
(E
))
4548 and then Has_Delayed_Aspects
(E
)
4550 Set_Has_Delayed_Aspects
(E
, False);
4551 Set_Has_Delayed_Freeze
(E
, False);
4552 Set_Freeze_Node
(E
, Empty
);
4556 -- Special processing for objects created by object declaration
4558 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
4560 -- Abstract type allowed only for C++ imported variables or
4563 -- Note: we inhibit this check for objects that do not come
4564 -- from source because there is at least one case (the
4565 -- expansion of x'Class'Input where x is abstract) where we
4566 -- legitimately generate an abstract object.
4568 if Is_Abstract_Type
(Etype
(E
))
4569 and then Comes_From_Source
(Parent
(E
))
4570 and then not (Is_Imported
(E
)
4571 and then Is_CPP_Class
(Etype
(E
)))
4573 Error_Msg_N
("type of object cannot be abstract",
4574 Object_Definition
(Parent
(E
)));
4576 if Is_CPP_Class
(Etype
(E
)) then
4578 ("\} may need a cpp_constructor",
4579 Object_Definition
(Parent
(E
)), Etype
(E
));
4581 elsif Present
(Expression
(Parent
(E
))) then
4582 Error_Msg_N
-- CODEFIX
4583 ("\maybe a class-wide type was meant",
4584 Object_Definition
(Parent
(E
)));
4588 -- For object created by object declaration, perform required
4589 -- categorization (preelaborate and pure) checks. Defer these
4590 -- checks to freeze time since pragma Import inhibits default
4591 -- initialization and thus pragma Import affects these checks.
4593 Validate_Object_Declaration
(Declaration_Node
(E
));
4595 -- If there is an address clause, check that it is valid
4597 Check_Address_Clause
(E
);
4599 -- Reset Is_True_Constant for non-constant aliased object. We
4600 -- consider that the fact that a non-constant object is aliased
4601 -- may indicate that some funny business is going on, e.g. an
4602 -- aliased object is passed by reference to a procedure which
4603 -- captures the address of the object, which is later used to
4604 -- assign a new value, even though the compiler thinks that
4605 -- it is not modified. Such code is highly dubious, but we
4606 -- choose to make it "work" for non-constant aliased objects.
4607 -- Note that we used to do this for all aliased objects,
4608 -- whether or not constant, but this caused anomalies down
4609 -- the line because we ended up with static objects that
4610 -- were not Is_True_Constant. Not resetting Is_True_Constant
4611 -- for (aliased) constant objects ensures that this anomaly
4614 -- However, we don't do that for internal entities. We figure
4615 -- that if we deliberately set Is_True_Constant for an internal
4616 -- entity, e.g. a dispatch table entry, then we mean it.
4618 if Ekind
(E
) /= E_Constant
4619 and then (Is_Aliased
(E
) or else Is_Aliased
(Etype
(E
)))
4620 and then not Is_Internal_Name
(Chars
(E
))
4622 Set_Is_True_Constant
(E
, False);
4625 -- If the object needs any kind of default initialization, an
4626 -- error must be issued if No_Default_Initialization applies.
4627 -- The check doesn't apply to imported objects, which are not
4628 -- ever default initialized, and is why the check is deferred
4629 -- until freezing, at which point we know if Import applies.
4630 -- Deferred constants are also exempted from this test because
4631 -- their completion is explicit, or through an import pragma.
4633 if Ekind
(E
) = E_Constant
4634 and then Present
(Full_View
(E
))
4638 elsif Comes_From_Source
(E
)
4639 and then not Is_Imported
(E
)
4640 and then not Has_Init_Expression
(Declaration_Node
(E
))
4642 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
4643 and then not No_Initialization
(Declaration_Node
(E
))
4644 and then not Is_Value_Type
(Etype
(E
))
4645 and then not Initialization_Suppressed
(Etype
(E
)))
4647 (Needs_Simple_Initialization
(Etype
(E
))
4648 and then not Is_Internal
(E
)))
4650 Has_Default_Initialization
:= True;
4652 (No_Default_Initialization
, Declaration_Node
(E
));
4655 -- Check that a Thread_Local_Storage variable does not have
4656 -- default initialization, and any explicit initialization must
4657 -- either be the null constant or a static constant.
4659 if Has_Pragma_Thread_Local_Storage
(E
) then
4661 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4663 if Has_Default_Initialization
4665 (Has_Init_Expression
(Decl
)
4667 (No
(Expression
(Decl
))
4669 (Is_OK_Static_Expression
(Expression
(Decl
))
4671 Nkind
(Expression
(Decl
)) = N_Null
)))
4674 ("Thread_Local_Storage variable& is "
4675 & "improperly initialized", Decl
, E
);
4677 ("\only allowed initialization is explicit "
4678 & "NULL or static expression", Decl
, E
);
4683 -- For imported objects, set Is_Public unless there is also an
4684 -- address clause, which means that there is no external symbol
4685 -- needed for the Import (Is_Public may still be set for other
4686 -- unrelated reasons). Note that we delayed this processing
4687 -- till freeze time so that we can be sure not to set the flag
4688 -- if there is an address clause. If there is such a clause,
4689 -- then the only purpose of the Import pragma is to suppress
4690 -- implicit initialization.
4692 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4696 -- For source objects that are not Imported and are library
4697 -- level, if no linker section pragma was given inherit the
4698 -- appropriate linker section from the corresponding type.
4700 if Comes_From_Source
(E
)
4701 and then not Is_Imported
(E
)
4702 and then Is_Library_Level_Entity
(E
)
4703 and then No
(Linker_Section_Pragma
(E
))
4705 Set_Linker_Section_Pragma
4706 (E
, Linker_Section_Pragma
(Etype
(E
)));
4709 -- For convention C objects of an enumeration type, warn if
4710 -- the size is not integer size and no explicit size given.
4711 -- Skip warning for Boolean, and Character, assume programmer
4712 -- expects 8-bit sizes for these cases.
4714 if (Convention
(E
) = Convention_C
4716 Convention
(E
) = Convention_CPP
)
4717 and then Is_Enumeration_Type
(Etype
(E
))
4718 and then not Is_Character_Type
(Etype
(E
))
4719 and then not Is_Boolean_Type
(Etype
(E
))
4720 and then Esize
(Etype
(E
)) < Standard_Integer_Size
4721 and then not Has_Size_Clause
(E
)
4723 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4725 ("??convention C enumeration object has size less than ^",
4727 Error_Msg_N
("\??use explicit size clause to set size", E
);
4731 -- Check that a constant which has a pragma Volatile[_Components]
4732 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
4734 -- Note: Atomic[_Components] also sets Volatile[_Components]
4736 if Ekind
(E
) = E_Constant
4737 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
4738 and then not Is_Imported
(E
)
4739 and then not Has_Boolean_Aspect_Import
(E
)
4741 -- Make sure we actually have a pragma, and have not merely
4742 -- inherited the indication from elsewhere (e.g. an address
4743 -- clause, which is not good enough in RM terms).
4745 if Has_Rep_Pragma
(E
, Name_Atomic
)
4747 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
4750 ("stand alone atomic constant must be " &
4751 "imported (RM C.6(13))", E
);
4753 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
4755 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
4758 ("stand alone volatile constant must be " &
4759 "imported (RM C.6(13))", E
);
4763 -- Static objects require special handling
4765 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
4766 and then Is_Statically_Allocated
(E
)
4768 Freeze_Static_Object
(E
);
4771 -- Remaining step is to layout objects
4773 if Ekind_In
(E
, E_Variable
, E_Constant
, E_Loop_Parameter
)
4774 or else Is_Formal
(E
)
4779 -- For an object that does not have delayed freezing, and whose
4780 -- initialization actions have been captured in a compound
4781 -- statement, move them back now directly within the enclosing
4782 -- statement sequence.
4784 if Ekind_In
(E
, E_Constant
, E_Variable
)
4785 and then not Has_Delayed_Freeze
(E
)
4787 Explode_Initialization_Compound_Statement
(E
);
4791 -- Case of a type or subtype being frozen
4794 -- We used to check here that a full type must have preelaborable
4795 -- initialization if it completes a private type specified with
4796 -- pragma Preelaborable_Initialization, but that missed cases where
4797 -- the types occur within a generic package, since the freezing
4798 -- that occurs within a containing scope generally skips traversal
4799 -- of a generic unit's declarations (those will be frozen within
4800 -- instances). This check was moved to Analyze_Package_Specification.
4802 -- The type may be defined in a generic unit. This can occur when
4803 -- freezing a generic function that returns the type (which is
4804 -- defined in a parent unit). It is clearly meaningless to freeze
4805 -- this type. However, if it is a subtype, its size may be determi-
4806 -- nable and used in subsequent checks, so might as well try to
4809 -- In Ada 2012, Freeze_Entities is also used in the front end to
4810 -- trigger the analysis of aspect expressions, so in this case we
4811 -- want to continue the freezing process.
4813 if Present
(Scope
(E
))
4814 and then Is_Generic_Unit
(Scope
(E
))
4816 (not Has_Predicates
(E
)
4817 and then not Has_Delayed_Freeze
(E
))
4819 Check_Compile_Time_Size
(E
);
4823 -- Check for error of Type_Invariant'Class applied to an untagged
4824 -- type (check delayed to freeze time when full type is available).
4827 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
4830 and then Class_Present
(Prag
)
4831 and then not Is_Tagged_Type
(E
)
4834 ("Type_Invariant''Class cannot be specified for &",
4837 ("\can only be specified for a tagged type", Prag
);
4841 -- A Ghost type cannot be effectively volatile (SPARK RM 6.9(8))
4843 if Is_Ghost_Entity
(E
)
4844 and then Is_Effectively_Volatile
(E
)
4846 Error_Msg_N
("ghost type & cannot be volatile", E
);
4849 -- Deal with special cases of freezing for subtype
4851 if E
/= Base_Type
(E
) then
4853 -- Before we do anything else, a specialized test for the case of
4854 -- a size given for an array where the array needs to be packed,
4855 -- but was not so the size cannot be honored. This is the case
4856 -- where implicit packing may apply. The reason we do this so
4857 -- early is that if we have implicit packing, the layout of the
4858 -- base type is affected, so we must do this before we freeze
4861 -- We could do this processing only if implicit packing is enabled
4862 -- since in all other cases, the error would be caught by the back
4863 -- end. However, we choose to do the check even if we do not have
4864 -- implicit packing enabled, since this allows us to give a more
4865 -- useful error message (advising use of pragmas Implicit_Packing
4868 if Is_Array_Type
(E
) then
4870 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
4871 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
4872 SZ
: constant Node_Id
:= Size_Clause
(E
);
4873 Btyp
: constant Entity_Id
:= Base_Type
(E
);
4880 -- Number of elements in array
4883 -- Check enabling conditions. These are straightforward
4884 -- except for the test for a limited composite type. This
4885 -- eliminates the rare case of a array of limited components
4886 -- where there are issues of whether or not we can go ahead
4887 -- and pack the array (since we can't freely pack and unpack
4888 -- arrays if they are limited).
4890 -- Note that we check the root type explicitly because the
4891 -- whole point is we are doing this test before we have had
4892 -- a chance to freeze the base type (and it is that freeze
4893 -- action that causes stuff to be inherited).
4895 if Has_Size_Clause
(E
)
4896 and then Known_Static_RM_Size
(E
)
4897 and then not Is_Packed
(E
)
4898 and then not Has_Pragma_Pack
(E
)
4899 and then not Has_Component_Size_Clause
(E
)
4900 and then Known_Static_RM_Size
(Ctyp
)
4901 and then RM_Size
(Ctyp
) < 64
4902 and then not Is_Limited_Composite
(E
)
4903 and then not Is_Packed
(Root_Type
(E
))
4904 and then not Has_Component_Size_Clause
(Root_Type
(E
))
4905 and then not (CodePeer_Mode
or GNATprove_Mode
)
4907 -- Compute number of elements in array
4909 Num_Elmts
:= Uint_1
;
4910 Indx
:= First_Index
(E
);
4911 while Present
(Indx
) loop
4912 Get_Index_Bounds
(Indx
, Lo
, Hi
);
4914 if not (Compile_Time_Known_Value
(Lo
)
4916 Compile_Time_Known_Value
(Hi
))
4918 goto No_Implicit_Packing
;
4924 Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1);
4928 -- What we are looking for here is the situation where
4929 -- the RM_Size given would be exactly right if there was
4930 -- a pragma Pack (resulting in the component size being
4931 -- the same as the RM_Size). Furthermore, the component
4932 -- type size must be an odd size (not a multiple of
4933 -- storage unit). If the component RM size is an exact
4934 -- number of storage units that is a power of two, the
4935 -- array is not packed and has a standard representation.
4937 if RM_Size
(E
) = Num_Elmts
* Rsiz
4938 and then Rsiz
mod System_Storage_Unit
/= 0
4940 -- For implicit packing mode, just set the component
4943 if Implicit_Packing
then
4944 Set_Component_Size
(Btyp
, Rsiz
);
4945 Set_Is_Bit_Packed_Array
(Btyp
);
4946 Set_Is_Packed
(Btyp
);
4947 Set_Has_Non_Standard_Rep
(Btyp
);
4949 -- Otherwise give an error message
4953 ("size given for& too small", SZ
, E
);
4954 Error_Msg_N
-- CODEFIX
4955 ("\use explicit pragma Pack "
4956 & "or use pragma Implicit_Packing", SZ
);
4959 elsif RM_Size
(E
) = Num_Elmts
* Rsiz
4960 and then Implicit_Packing
4962 (Rsiz
/ System_Storage_Unit
= 1
4964 Rsiz
/ System_Storage_Unit
= 2
4966 Rsiz
/ System_Storage_Unit
= 4)
4968 -- Not a packed array, but indicate the desired
4969 -- component size, for the back-end.
4971 Set_Component_Size
(Btyp
, Rsiz
);
4977 <<No_Implicit_Packing
>>
4979 -- If ancestor subtype present, freeze that first. Note that this
4980 -- will also get the base type frozen. Need RM reference ???
4982 Atype
:= Ancestor_Subtype
(E
);
4984 if Present
(Atype
) then
4985 Freeze_And_Append
(Atype
, N
, Result
);
4987 -- No ancestor subtype present
4990 -- See if we have a nearest ancestor that has a predicate.
4991 -- That catches the case of derived type with a predicate.
4992 -- Need RM reference here ???
4994 Atype
:= Nearest_Ancestor
(E
);
4996 if Present
(Atype
) and then Has_Predicates
(Atype
) then
4997 Freeze_And_Append
(Atype
, N
, Result
);
5000 -- Freeze base type before freezing the entity (RM 13.14(15))
5002 if E
/= Base_Type
(E
) then
5003 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
5007 -- A subtype inherits all the type-related representation aspects
5008 -- from its parents (RM 13.1(8)).
5010 Inherit_Aspects_At_Freeze_Point
(E
);
5012 -- For a derived type, freeze its parent type first (RM 13.14(15))
5014 elsif Is_Derived_Type
(E
) then
5015 Freeze_And_Append
(Etype
(E
), N
, Result
);
5016 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
5018 -- A derived type inherits each type-related representation aspect
5019 -- of its parent type that was directly specified before the
5020 -- declaration of the derived type (RM 13.1(15)).
5022 Inherit_Aspects_At_Freeze_Point
(E
);
5025 -- Check for incompatible size and alignment for record type
5027 if Warn_On_Size_Alignment
5028 and then Is_Record_Type
(E
)
5029 and then Has_Size_Clause
(E
) and then Has_Alignment_Clause
(E
)
5031 -- If explicit Object_Size clause given assume that the programmer
5032 -- knows what he is doing, and expects the compiler behavior.
5034 and then not Has_Object_Size_Clause
(E
)
5036 -- Check for size not a multiple of alignment
5038 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
5041 SC
: constant Node_Id
:= Size_Clause
(E
);
5042 AC
: constant Node_Id
:= Alignment_Clause
(E
);
5044 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
5047 if Present
(SC
) and then Present
(AC
) then
5051 if Sloc
(SC
) > Sloc
(AC
) then
5054 ("??size is not a multiple of alignment for &", Loc
, E
);
5055 Error_Msg_Sloc
:= Sloc
(AC
);
5056 Error_Msg_Uint_1
:= Alignment
(E
);
5057 Error_Msg_N
("\??alignment of ^ specified #", Loc
);
5062 ("??size is not a multiple of alignment for &", Loc
, E
);
5063 Error_Msg_Sloc
:= Sloc
(SC
);
5064 Error_Msg_Uint_1
:= RM_Size
(E
);
5065 Error_Msg_N
("\??size of ^ specified #", Loc
);
5068 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
5069 Error_Msg_N
("\??Object_Size will be increased to ^", Loc
);
5076 if Is_Array_Type
(E
) then
5077 Freeze_Array_Type
(E
);
5079 -- For a class-wide type, the corresponding specific type is
5080 -- frozen as well (RM 13.14(15))
5082 elsif Is_Class_Wide_Type
(E
) then
5083 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
5085 -- If the base type of the class-wide type is still incomplete,
5086 -- the class-wide remains unfrozen as well. This is legal when
5087 -- E is the formal of a primitive operation of some other type
5088 -- which is being frozen.
5090 if not Is_Frozen
(Root_Type
(E
)) then
5091 Set_Is_Frozen
(E
, False);
5095 -- The equivalent type associated with a class-wide subtype needs
5096 -- to be frozen to ensure that its layout is done.
5098 if Ekind
(E
) = E_Class_Wide_Subtype
5099 and then Present
(Equivalent_Type
(E
))
5101 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5104 -- Generate an itype reference for a library-level class-wide type
5105 -- at the freeze point. Otherwise the first explicit reference to
5106 -- the type may appear in an inner scope which will be rejected by
5110 and then Is_Compilation_Unit
(Scope
(E
))
5113 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
5118 -- From a gigi point of view, a class-wide subtype derives
5119 -- from its record equivalent type. As a result, the itype
5120 -- reference must appear after the freeze node of the
5121 -- equivalent type or gigi will reject the reference.
5123 if Ekind
(E
) = E_Class_Wide_Subtype
5124 and then Present
(Equivalent_Type
(E
))
5126 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
5128 Add_To_Result
(Ref
);
5133 -- For a record type or record subtype, freeze all component types
5134 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
5135 -- using Is_Record_Type, because we don't want to attempt the freeze
5136 -- for the case of a private type with record extension (we will do
5137 -- that later when the full type is frozen).
5139 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
)
5140 and then not (Present
(Scope
(E
))
5141 and then Is_Generic_Unit
(Scope
(E
)))
5143 Freeze_Record_Type
(E
);
5145 -- For a concurrent type, freeze corresponding record type. This does
5146 -- not correspond to any specific rule in the RM, but the record type
5147 -- is essentially part of the concurrent type. Also freeze all local
5148 -- entities. This includes record types created for entry parameter
5149 -- blocks and whatever local entities may appear in the private part.
5151 elsif Is_Concurrent_Type
(E
) then
5152 if Present
(Corresponding_Record_Type
(E
)) then
5153 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
5156 Comp
:= First_Entity
(E
);
5157 while Present
(Comp
) loop
5158 if Is_Type
(Comp
) then
5159 Freeze_And_Append
(Comp
, N
, Result
);
5161 elsif (Ekind
(Comp
)) /= E_Function
then
5163 -- The guard on the presence of the Etype seems to be needed
5164 -- for some CodePeer (-gnatcC) cases, but not clear why???
5166 if Present
(Etype
(Comp
)) then
5167 if Is_Itype
(Etype
(Comp
))
5168 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
5170 Undelay_Type
(Etype
(Comp
));
5173 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5180 -- Private types are required to point to the same freeze node as
5181 -- their corresponding full views. The freeze node itself has to
5182 -- point to the partial view of the entity (because from the partial
5183 -- view, we can retrieve the full view, but not the reverse).
5184 -- However, in order to freeze correctly, we need to freeze the full
5185 -- view. If we are freezing at the end of a scope (or within the
5186 -- scope) of the private type, the partial and full views will have
5187 -- been swapped, the full view appears first in the entity chain and
5188 -- the swapping mechanism ensures that the pointers are properly set
5191 -- If we encounter the partial view before the full view (e.g. when
5192 -- freezing from another scope), we freeze the full view, and then
5193 -- set the pointers appropriately since we cannot rely on swapping to
5194 -- fix things up (subtypes in an outer scope might not get swapped).
5196 -- If the full view is itself private, the above requirements apply
5197 -- to the underlying full view instead of the full view. But there is
5198 -- no swapping mechanism for the underlying full view so we need to
5199 -- set the pointers appropriately in both cases.
5201 elsif Is_Incomplete_Or_Private_Type
(E
)
5202 and then not Is_Generic_Type
(E
)
5204 -- The construction of the dispatch table associated with library
5205 -- level tagged types forces freezing of all the primitives of the
5206 -- type, which may cause premature freezing of the partial view.
5210 -- type T is tagged private;
5211 -- type DT is new T with private;
5212 -- procedure Prim (X : in out T; Y : in out DT'Class);
5214 -- type T is tagged null record;
5216 -- type DT is new T with null record;
5219 -- In this case the type will be frozen later by the usual
5220 -- mechanism: an object declaration, an instantiation, or the
5221 -- end of a declarative part.
5223 if Is_Library_Level_Tagged_Type
(E
)
5224 and then not Present
(Full_View
(E
))
5226 Set_Is_Frozen
(E
, False);
5229 -- Case of full view present
5231 elsif Present
(Full_View
(E
)) then
5233 -- If full view has already been frozen, then no further
5234 -- processing is required
5236 if Is_Frozen
(Full_View
(E
)) then
5237 Set_Has_Delayed_Freeze
(E
, False);
5238 Set_Freeze_Node
(E
, Empty
);
5240 -- Otherwise freeze full view and patch the pointers so that
5241 -- the freeze node will elaborate both views in the back end.
5242 -- However, if full view is itself private, freeze underlying
5243 -- full view instead and patch the pointers so that the freeze
5244 -- node will elaborate the three views in the back end.
5248 Full
: Entity_Id
:= Full_View
(E
);
5251 if Is_Private_Type
(Full
)
5252 and then Present
(Underlying_Full_View
(Full
))
5254 Full
:= Underlying_Full_View
(Full
);
5257 Freeze_And_Append
(Full
, N
, Result
);
5259 if Full
/= Full_View
(E
)
5260 and then Has_Delayed_Freeze
(Full_View
(E
))
5262 F_Node
:= Freeze_Node
(Full
);
5264 if Present
(F_Node
) then
5265 Set_Freeze_Node
(Full_View
(E
), F_Node
);
5266 Set_Entity
(F_Node
, Full_View
(E
));
5269 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
5270 Set_Freeze_Node
(Full_View
(E
), Empty
);
5274 if Has_Delayed_Freeze
(E
) then
5275 F_Node
:= Freeze_Node
(Full_View
(E
));
5277 if Present
(F_Node
) then
5278 Set_Freeze_Node
(E
, F_Node
);
5279 Set_Entity
(F_Node
, E
);
5282 -- {Incomplete,Private}_Subtypes with Full_Views
5283 -- constrained by discriminants.
5285 Set_Has_Delayed_Freeze
(E
, False);
5286 Set_Freeze_Node
(E
, Empty
);
5292 Check_Debug_Info_Needed
(E
);
5294 -- AI-117 requires that the convention of a partial view be the
5295 -- same as the convention of the full view. Note that this is a
5296 -- recognized breach of privacy, but it's essential for logical
5297 -- consistency of representation, and the lack of a rule in
5298 -- RM95 was an oversight.
5300 Set_Convention
(E
, Convention
(Full_View
(E
)));
5302 Set_Size_Known_At_Compile_Time
(E
,
5303 Size_Known_At_Compile_Time
(Full_View
(E
)));
5305 -- Size information is copied from the full view to the
5306 -- incomplete or private view for consistency.
5308 -- We skip this is the full view is not a type. This is very
5309 -- strange of course, and can only happen as a result of
5310 -- certain illegalities, such as a premature attempt to derive
5311 -- from an incomplete type.
5313 if Is_Type
(Full_View
(E
)) then
5314 Set_Size_Info
(E
, Full_View
(E
));
5315 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
5320 -- Case of underlying full view present
5322 elsif Is_Private_Type
(E
)
5323 and then Present
(Underlying_Full_View
(E
))
5325 if not Is_Frozen
(Underlying_Full_View
(E
)) then
5326 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
5329 -- Patch the pointers so that the freeze node will elaborate
5330 -- both views in the back end.
5332 if Has_Delayed_Freeze
(E
) then
5333 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
5335 if Present
(F_Node
) then
5336 Set_Freeze_Node
(E
, F_Node
);
5337 Set_Entity
(F_Node
, E
);
5340 Set_Has_Delayed_Freeze
(E
, False);
5341 Set_Freeze_Node
(E
, Empty
);
5345 Check_Debug_Info_Needed
(E
);
5349 -- Case of no full view present. If entity is derived or subtype,
5350 -- it is safe to freeze, correctness depends on the frozen status
5351 -- of parent. Otherwise it is either premature usage, or a Taft
5352 -- amendment type, so diagnosis is at the point of use and the
5353 -- type might be frozen later.
5355 elsif E
/= Base_Type
(E
) or else Is_Derived_Type
(E
) then
5359 Set_Is_Frozen
(E
, False);
5363 -- For access subprogram, freeze types of all formals, the return
5364 -- type was already frozen, since it is the Etype of the function.
5365 -- Formal types can be tagged Taft amendment types, but otherwise
5366 -- they cannot be incomplete.
5368 elsif Ekind
(E
) = E_Subprogram_Type
then
5369 Formal
:= First_Formal
(E
);
5370 while Present
(Formal
) loop
5371 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
5372 and then No
(Full_View
(Etype
(Formal
)))
5373 and then not Is_Value_Type
(Etype
(Formal
))
5375 if Is_Tagged_Type
(Etype
(Formal
)) then
5378 -- AI05-151: Incomplete types are allowed in access to
5379 -- subprogram specifications.
5381 elsif Ada_Version
< Ada_2012
then
5383 ("invalid use of incomplete type&", E
, Etype
(Formal
));
5387 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
5388 Next_Formal
(Formal
);
5391 Freeze_Subprogram
(E
);
5393 -- For access to a protected subprogram, freeze the equivalent type
5394 -- (however this is not set if we are not generating code or if this
5395 -- is an anonymous type used just for resolution).
5397 elsif Is_Access_Protected_Subprogram_Type
(E
) then
5398 if Present
(Equivalent_Type
(E
)) then
5399 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5403 -- Generic types are never seen by the back-end, and are also not
5404 -- processed by the expander (since the expander is turned off for
5405 -- generic processing), so we never need freeze nodes for them.
5407 if Is_Generic_Type
(E
) then
5411 -- Some special processing for non-generic types to complete
5412 -- representation details not known till the freeze point.
5414 if Is_Fixed_Point_Type
(E
) then
5415 Freeze_Fixed_Point_Type
(E
);
5417 -- Some error checks required for ordinary fixed-point type. Defer
5418 -- these till the freeze-point since we need the small and range
5419 -- values. We only do these checks for base types
5421 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
5422 if Small_Value
(E
) < Ureal_2_M_80
then
5423 Error_Msg_Name_1
:= Name_Small
;
5425 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
5427 elsif Small_Value
(E
) > Ureal_2_80
then
5428 Error_Msg_Name_1
:= Name_Small
;
5430 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
5433 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
5434 Error_Msg_Name_1
:= Name_First
;
5436 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
5439 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
5440 Error_Msg_Name_1
:= Name_Last
;
5442 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
5446 elsif Is_Enumeration_Type
(E
) then
5447 Freeze_Enumeration_Type
(E
);
5449 elsif Is_Integer_Type
(E
) then
5450 Adjust_Esize_For_Alignment
(E
);
5452 if Is_Modular_Integer_Type
(E
)
5453 and then Warn_On_Suspicious_Modulus_Value
5455 Check_Suspicious_Modulus
(E
);
5458 -- The pool applies to named and anonymous access types, but not
5459 -- to subprogram and to internal types generated for 'Access
5462 elsif Is_Access_Type
(E
)
5463 and then not Is_Access_Subprogram_Type
(E
)
5464 and then Ekind
(E
) /= E_Access_Attribute_Type
5466 -- If a pragma Default_Storage_Pool applies, and this type has no
5467 -- Storage_Pool or Storage_Size clause (which must have occurred
5468 -- before the freezing point), then use the default. This applies
5469 -- only to base types.
5471 -- None of this applies to access to subprograms, for which there
5472 -- are clearly no pools.
5474 if Present
(Default_Pool
)
5475 and then Is_Base_Type
(E
)
5476 and then not Has_Storage_Size_Clause
(E
)
5477 and then No
(Associated_Storage_Pool
(E
))
5479 -- Case of pragma Default_Storage_Pool (null)
5481 if Nkind
(Default_Pool
) = N_Null
then
5482 Set_No_Pool_Assigned
(E
);
5484 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
5487 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
5491 -- Check restriction for standard storage pool
5493 if No
(Associated_Storage_Pool
(E
)) then
5494 Check_Restriction
(No_Standard_Storage_Pools
, E
);
5497 -- Deal with error message for pure access type. This is not an
5498 -- error in Ada 2005 if there is no pool (see AI-366).
5500 if Is_Pure_Unit_Access_Type
(E
)
5501 and then (Ada_Version
< Ada_2005
5502 or else not No_Pool_Assigned
(E
))
5503 and then not Is_Generic_Unit
(Scope
(E
))
5505 Error_Msg_N
("named access type not allowed in pure unit", E
);
5507 if Ada_Version
>= Ada_2005
then
5509 ("\would be legal if Storage_Size of 0 given??", E
);
5511 elsif No_Pool_Assigned
(E
) then
5513 ("\would be legal in Ada 2005??", E
);
5517 ("\would be legal in Ada 2005 if "
5518 & "Storage_Size of 0 given??", E
);
5523 -- Case of composite types
5525 if Is_Composite_Type
(E
) then
5527 -- AI-117 requires that all new primitives of a tagged type must
5528 -- inherit the convention of the full view of the type. Inherited
5529 -- and overriding operations are defined to inherit the convention
5530 -- of their parent or overridden subprogram (also specified in
5531 -- AI-117), which will have occurred earlier (in Derive_Subprogram
5532 -- and New_Overloaded_Entity). Here we set the convention of
5533 -- primitives that are still convention Ada, which will ensure
5534 -- that any new primitives inherit the type's convention. Class-
5535 -- wide types can have a foreign convention inherited from their
5536 -- specific type, but are excluded from this since they don't have
5537 -- any associated primitives.
5539 if Is_Tagged_Type
(E
)
5540 and then not Is_Class_Wide_Type
(E
)
5541 and then Convention
(E
) /= Convention_Ada
5544 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
5548 Prim
:= First_Elmt
(Prim_List
);
5549 while Present
(Prim
) loop
5550 if Convention
(Node
(Prim
)) = Convention_Ada
then
5551 Set_Convention
(Node
(Prim
), Convention
(E
));
5559 -- If the type is a simple storage pool type, then this is where
5560 -- we attempt to locate and validate its Allocate, Deallocate, and
5561 -- Storage_Size operations (the first is required, and the latter
5562 -- two are optional). We also verify that the full type for a
5563 -- private type is allowed to be a simple storage pool type.
5565 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
5566 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
5568 -- If the type is marked Has_Private_Declaration, then this is
5569 -- a full type for a private type that was specified with the
5570 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
5571 -- pragma is allowed for the full type (for example, it can't
5572 -- be an array type, or a nonlimited record type).
5574 if Has_Private_Declaration
(E
) then
5575 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
5576 and then not Is_Private_Type
(E
)
5578 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
5580 ("pragma% can only apply to full type that is an " &
5581 "explicitly limited type", E
);
5585 Validate_Simple_Pool_Ops
: declare
5586 Pool_Type
: Entity_Id
renames E
;
5587 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
5588 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
5590 procedure Validate_Simple_Pool_Op_Formal
5591 (Pool_Op
: Entity_Id
;
5592 Pool_Op_Formal
: in out Entity_Id
;
5593 Expected_Mode
: Formal_Kind
;
5594 Expected_Type
: Entity_Id
;
5595 Formal_Name
: String;
5596 OK_Formal
: in out Boolean);
5597 -- Validate one formal Pool_Op_Formal of the candidate pool
5598 -- operation Pool_Op. The formal must be of Expected_Type
5599 -- and have mode Expected_Mode. OK_Formal will be set to
5600 -- False if the formal doesn't match. If OK_Formal is False
5601 -- on entry, then the formal will effectively be ignored
5602 -- (because validation of the pool op has already failed).
5603 -- Upon return, Pool_Op_Formal will be updated to the next
5606 procedure Validate_Simple_Pool_Operation
5607 (Op_Name
: Name_Id
);
5608 -- Search for and validate a simple pool operation with the
5609 -- name Op_Name. If the name is Allocate, then there must be
5610 -- exactly one such primitive operation for the simple pool
5611 -- type. If the name is Deallocate or Storage_Size, then
5612 -- there can be at most one such primitive operation. The
5613 -- profile of the located primitive must conform to what
5614 -- is expected for each operation.
5616 ------------------------------------
5617 -- Validate_Simple_Pool_Op_Formal --
5618 ------------------------------------
5620 procedure Validate_Simple_Pool_Op_Formal
5621 (Pool_Op
: Entity_Id
;
5622 Pool_Op_Formal
: in out Entity_Id
;
5623 Expected_Mode
: Formal_Kind
;
5624 Expected_Type
: Entity_Id
;
5625 Formal_Name
: String;
5626 OK_Formal
: in out Boolean)
5629 -- If OK_Formal is False on entry, then simply ignore
5630 -- the formal, because an earlier formal has already
5633 if not OK_Formal
then
5636 -- If no formal is passed in, then issue an error for a
5639 elsif not Present
(Pool_Op_Formal
) then
5641 ("simple storage pool op missing formal " &
5642 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
5648 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
5650 -- If the pool type was expected for this formal, then
5651 -- this will not be considered a candidate operation
5652 -- for the simple pool, so we unset OK_Formal so that
5653 -- the op and any later formals will be ignored.
5655 if Expected_Type
= Pool_Type
then
5662 ("wrong type for formal " & Formal_Name
&
5663 " of simple storage pool op; expected type&",
5664 Pool_Op_Formal
, Expected_Type
);
5668 -- Issue error if formal's mode is not the expected one
5670 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
5672 ("wrong mode for formal of simple storage pool op",
5676 -- Advance to the next formal
5678 Next_Formal
(Pool_Op_Formal
);
5679 end Validate_Simple_Pool_Op_Formal
;
5681 ------------------------------------
5682 -- Validate_Simple_Pool_Operation --
5683 ------------------------------------
5685 procedure Validate_Simple_Pool_Operation
5689 Found_Op
: Entity_Id
:= Empty
;
5695 (Nam_In
(Op_Name
, Name_Allocate
,
5697 Name_Storage_Size
));
5699 Error_Msg_Name_1
:= Op_Name
;
5701 -- For each homonym declared immediately in the scope
5702 -- of the simple storage pool type, determine whether
5703 -- the homonym is an operation of the pool type, and,
5704 -- if so, check that its profile is as expected for
5705 -- a simple pool operation of that name.
5707 Op
:= Get_Name_Entity_Id
(Op_Name
);
5708 while Present
(Op
) loop
5709 if Ekind_In
(Op
, E_Function
, E_Procedure
)
5710 and then Scope
(Op
) = Current_Scope
5712 Formal
:= First_Entity
(Op
);
5716 -- The first parameter must be of the pool type
5717 -- in order for the operation to qualify.
5719 if Op_Name
= Name_Storage_Size
then
5720 Validate_Simple_Pool_Op_Formal
5721 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
5724 Validate_Simple_Pool_Op_Formal
5725 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
5729 -- If another operation with this name has already
5730 -- been located for the type, then flag an error,
5731 -- since we only allow the type to have a single
5734 if Present
(Found_Op
) and then Is_OK
then
5736 ("only one % operation allowed for " &
5737 "simple storage pool type&", Op
, Pool_Type
);
5740 -- In the case of Allocate and Deallocate, a formal
5741 -- of type System.Address is required.
5743 if Op_Name
= Name_Allocate
then
5744 Validate_Simple_Pool_Op_Formal
5745 (Op
, Formal
, E_Out_Parameter
,
5746 Address_Type
, "Storage_Address", Is_OK
);
5748 elsif Op_Name
= Name_Deallocate
then
5749 Validate_Simple_Pool_Op_Formal
5750 (Op
, Formal
, E_In_Parameter
,
5751 Address_Type
, "Storage_Address", Is_OK
);
5754 -- In the case of Allocate and Deallocate, formals
5755 -- of type Storage_Count are required as the third
5756 -- and fourth parameters.
5758 if Op_Name
/= Name_Storage_Size
then
5759 Validate_Simple_Pool_Op_Formal
5760 (Op
, Formal
, E_In_Parameter
,
5761 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
5762 Validate_Simple_Pool_Op_Formal
5763 (Op
, Formal
, E_In_Parameter
,
5764 Stg_Cnt_Type
, "Alignment", Is_OK
);
5767 -- If no mismatched formals have been found (Is_OK)
5768 -- and no excess formals are present, then this
5769 -- operation has been validated, so record it.
5771 if not Present
(Formal
) and then Is_OK
then
5779 -- There must be a valid Allocate operation for the type,
5780 -- so issue an error if none was found.
5782 if Op_Name
= Name_Allocate
5783 and then not Present
(Found_Op
)
5785 Error_Msg_N
("missing % operation for simple " &
5786 "storage pool type", Pool_Type
);
5788 elsif Present
(Found_Op
) then
5790 -- Simple pool operations can't be abstract
5792 if Is_Abstract_Subprogram
(Found_Op
) then
5794 ("simple storage pool operation must not be " &
5795 "abstract", Found_Op
);
5798 -- The Storage_Size operation must be a function with
5799 -- Storage_Count as its result type.
5801 if Op_Name
= Name_Storage_Size
then
5802 if Ekind
(Found_Op
) = E_Procedure
then
5804 ("% operation must be a function", Found_Op
);
5806 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
5808 ("wrong result type for%, expected type&",
5809 Found_Op
, Stg_Cnt_Type
);
5812 -- Allocate and Deallocate must be procedures
5814 elsif Ekind
(Found_Op
) = E_Function
then
5816 ("% operation must be a procedure", Found_Op
);
5819 end Validate_Simple_Pool_Operation
;
5821 -- Start of processing for Validate_Simple_Pool_Ops
5824 Validate_Simple_Pool_Operation
(Name_Allocate
);
5825 Validate_Simple_Pool_Operation
(Name_Deallocate
);
5826 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
5827 end Validate_Simple_Pool_Ops
;
5831 -- Now that all types from which E may depend are frozen, see if the
5832 -- size is known at compile time, if it must be unsigned, or if
5833 -- strict alignment is required
5835 Check_Compile_Time_Size
(E
);
5836 Check_Unsigned_Type
(E
);
5838 if Base_Type
(E
) = E
then
5839 Check_Strict_Alignment
(E
);
5842 -- Do not allow a size clause for a type which does not have a size
5843 -- that is known at compile time
5845 if Has_Size_Clause
(E
)
5846 and then not Size_Known_At_Compile_Time
(E
)
5848 -- Suppress this message if errors posted on E, even if we are
5849 -- in all errors mode, since this is often a junk message
5851 if not Error_Posted
(E
) then
5853 ("size clause not allowed for variable length type",
5858 -- Now we set/verify the representation information, in particular
5859 -- the size and alignment values. This processing is not required for
5860 -- generic types, since generic types do not play any part in code
5861 -- generation, and so the size and alignment values for such types
5862 -- are irrelevant. Ditto for types declared within a generic unit,
5863 -- which may have components that depend on generic parameters, and
5864 -- that will be recreated in an instance.
5866 if Inside_A_Generic
then
5869 -- Otherwise we call the layout procedure
5875 -- If this is an access to subprogram whose designated type is itself
5876 -- a subprogram type, the return type of this anonymous subprogram
5877 -- type must be decorated as well.
5879 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
5880 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
5882 Layout_Type
(Etype
(Designated_Type
(E
)));
5885 -- If the type has a Defaut_Value/Default_Component_Value aspect,
5886 -- this is where we analye the expression (after the type is frozen,
5887 -- since in the case of Default_Value, we are analyzing with the
5888 -- type itself, and we treat Default_Component_Value similarly for
5889 -- the sake of uniformity).
5891 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
5898 if Is_Scalar_Type
(E
) then
5899 Nam
:= Name_Default_Value
;
5901 Exp
:= Default_Aspect_Value
(Typ
);
5903 Nam
:= Name_Default_Component_Value
;
5904 Typ
:= Component_Type
(E
);
5905 Exp
:= Default_Aspect_Component_Value
(E
);
5908 Analyze_And_Resolve
(Exp
, Typ
);
5910 if Etype
(Exp
) /= Any_Type
then
5911 if not Is_OK_Static_Expression
(Exp
) then
5912 Error_Msg_Name_1
:= Nam
;
5913 Flag_Non_Static_Expr
5914 ("aspect% requires static expression", Exp
);
5920 -- End of freeze processing for type entities
5923 -- Here is where we logically freeze the current entity. If it has a
5924 -- freeze node, then this is the point at which the freeze node is
5925 -- linked into the result list.
5927 if Has_Delayed_Freeze
(E
) then
5929 -- If a freeze node is already allocated, use it, otherwise allocate
5930 -- a new one. The preallocation happens in the case of anonymous base
5931 -- types, where we preallocate so that we can set First_Subtype_Link.
5932 -- Note that we reset the Sloc to the current freeze location.
5934 if Present
(Freeze_Node
(E
)) then
5935 F_Node
:= Freeze_Node
(E
);
5936 Set_Sloc
(F_Node
, Loc
);
5939 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
5940 Set_Freeze_Node
(E
, F_Node
);
5941 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
5942 Set_TSS_Elist
(F_Node
, No_Elist
);
5943 Set_Actions
(F_Node
, No_List
);
5946 Set_Entity
(F_Node
, E
);
5947 Add_To_Result
(F_Node
);
5949 -- A final pass over record types with discriminants. If the type
5950 -- has an incomplete declaration, there may be constrained access
5951 -- subtypes declared elsewhere, which do not depend on the discrimi-
5952 -- nants of the type, and which are used as component types (i.e.
5953 -- the full view is a recursive type). The designated types of these
5954 -- subtypes can only be elaborated after the type itself, and they
5955 -- need an itype reference.
5957 if Ekind
(E
) = E_Record_Type
5958 and then Has_Discriminants
(E
)
5966 Comp
:= First_Component
(E
);
5967 while Present
(Comp
) loop
5968 Typ
:= Etype
(Comp
);
5970 if Ekind
(Comp
) = E_Component
5971 and then Is_Access_Type
(Typ
)
5972 and then Scope
(Typ
) /= E
5973 and then Base_Type
(Designated_Type
(Typ
)) = E
5974 and then Is_Itype
(Designated_Type
(Typ
))
5976 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
5977 Set_Itype
(IR
, Designated_Type
(Typ
));
5978 Append
(IR
, Result
);
5981 Next_Component
(Comp
);
5987 -- When a type is frozen, the first subtype of the type is frozen as
5988 -- well (RM 13.14(15)). This has to be done after freezing the type,
5989 -- since obviously the first subtype depends on its own base type.
5992 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
5994 -- If we just froze a tagged non-class wide record, then freeze the
5995 -- corresponding class-wide type. This must be done after the tagged
5996 -- type itself is frozen, because the class-wide type refers to the
5997 -- tagged type which generates the class.
5999 if Is_Tagged_Type
(E
)
6000 and then not Is_Class_Wide_Type
(E
)
6001 and then Present
(Class_Wide_Type
(E
))
6003 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
6007 Check_Debug_Info_Needed
(E
);
6009 -- Special handling for subprograms
6011 if Is_Subprogram
(E
) then
6013 -- If subprogram has address clause then reset Is_Public flag, since
6014 -- we do not want the backend to generate external references.
6016 if Present
(Address_Clause
(E
))
6017 and then not Is_Library_Level_Entity
(E
)
6019 Set_Is_Public
(E
, False);
6026 -----------------------------
6027 -- Freeze_Enumeration_Type --
6028 -----------------------------
6030 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
6032 -- By default, if no size clause is present, an enumeration type with
6033 -- Convention C is assumed to interface to a C enum, and has integer
6034 -- size. This applies to types. For subtypes, verify that its base
6035 -- type has no size clause either. Treat other foreign conventions
6036 -- in the same way, and also make sure alignment is set right.
6038 if Has_Foreign_Convention
(Typ
)
6039 and then not Has_Size_Clause
(Typ
)
6040 and then not Has_Size_Clause
(Base_Type
(Typ
))
6041 and then Esize
(Typ
) < Standard_Integer_Size
6043 -- Don't do this if Short_Enums on target
6045 and then not Target_Short_Enums
6047 Init_Esize
(Typ
, Standard_Integer_Size
);
6048 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
6050 -- Normal Ada case or size clause present or not Long_C_Enums on target
6053 -- If the enumeration type interfaces to C, and it has a size clause
6054 -- that specifies less than int size, it warrants a warning. The
6055 -- user may intend the C type to be an enum or a char, so this is
6056 -- not by itself an error that the Ada compiler can detect, but it
6057 -- it is a worth a heads-up. For Boolean and Character types we
6058 -- assume that the programmer has the proper C type in mind.
6060 if Convention
(Typ
) = Convention_C
6061 and then Has_Size_Clause
(Typ
)
6062 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
6063 and then not Is_Boolean_Type
(Typ
)
6064 and then not Is_Character_Type
(Typ
)
6066 -- Don't do this if Short_Enums on target
6068 and then not Target_Short_Enums
6071 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
6074 Adjust_Esize_For_Alignment
(Typ
);
6076 end Freeze_Enumeration_Type
;
6078 -----------------------
6079 -- Freeze_Expression --
6080 -----------------------
6082 procedure Freeze_Expression
(N
: Node_Id
) is
6083 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
6086 Desig_Typ
: Entity_Id
;
6090 Freeze_Outside
: Boolean := False;
6091 -- This flag is set true if the entity must be frozen outside the
6092 -- current subprogram. This happens in the case of expander generated
6093 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
6094 -- not freeze all entities like other bodies, but which nevertheless
6095 -- may reference entities that have to be frozen before the body and
6096 -- obviously cannot be frozen inside the body.
6098 function Find_Aggregate_Component_Desig_Type
return Entity_Id
;
6099 -- If the expression is an array aggregate, the type of the component
6100 -- expressions is also frozen. If the component type is an access type
6101 -- and the expressions include allocators, the designed type is frozen
6104 function In_Expanded_Body
(N
: Node_Id
) return Boolean;
6105 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
6106 -- it is the handled statement sequence of an expander-generated
6107 -- subprogram (init proc, stream subprogram, or renaming as body).
6108 -- If so, this is not a freezing context.
6110 -----------------------------------------
6111 -- Find_Aggregate_Component_Desig_Type --
6112 -----------------------------------------
6114 function Find_Aggregate_Component_Desig_Type
return Entity_Id
is
6119 if Present
(Expressions
(N
)) then
6120 Exp
:= First
(Expressions
(N
));
6121 while Present
(Exp
) loop
6122 if Nkind
(Exp
) = N_Allocator
then
6123 return Designated_Type
(Component_Type
(Etype
(N
)));
6130 if Present
(Component_Associations
(N
)) then
6131 Assoc
:= First
(Component_Associations
(N
));
6132 while Present
(Assoc
) loop
6133 if Nkind
(Expression
(Assoc
)) = N_Allocator
then
6134 return Designated_Type
(Component_Type
(Etype
(N
)));
6142 end Find_Aggregate_Component_Desig_Type
;
6144 ----------------------
6145 -- In_Expanded_Body --
6146 ----------------------
6148 function In_Expanded_Body
(N
: Node_Id
) return Boolean is
6153 if Nkind
(N
) = N_Subprogram_Body
then
6159 if Nkind
(P
) /= N_Subprogram_Body
then
6163 Id
:= Defining_Unit_Name
(Specification
(P
));
6165 -- The following are expander-created bodies, or bodies that
6166 -- are not freeze points.
6168 if Nkind
(Id
) = N_Defining_Identifier
6169 and then (Is_Init_Proc
(Id
)
6170 or else Is_TSS
(Id
, TSS_Stream_Input
)
6171 or else Is_TSS
(Id
, TSS_Stream_Output
)
6172 or else Is_TSS
(Id
, TSS_Stream_Read
)
6173 or else Is_TSS
(Id
, TSS_Stream_Write
)
6174 or else Nkind_In
(Original_Node
(P
),
6175 N_Subprogram_Renaming_Declaration
,
6176 N_Expression_Function
))
6183 end In_Expanded_Body
;
6185 -- Start of processing for Freeze_Expression
6188 -- Immediate return if freezing is inhibited. This flag is set by the
6189 -- analyzer to stop freezing on generated expressions that would cause
6190 -- freezing if they were in the source program, but which are not
6191 -- supposed to freeze, since they are created.
6193 if Must_Not_Freeze
(N
) then
6197 -- If expression is non-static, then it does not freeze in a default
6198 -- expression, see section "Handling of Default Expressions" in the
6199 -- spec of package Sem for further details. Note that we have to make
6200 -- sure that we actually have a real expression (if we have a subtype
6201 -- indication, we can't test Is_OK_Static_Expression). However, we
6202 -- exclude the case of the prefix of an attribute of a static scalar
6203 -- subtype from this early return, because static subtype attributes
6204 -- should always cause freezing, even in default expressions, but
6205 -- the attribute may not have been marked as static yet (because in
6206 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
6207 -- Freeze_Expression on the prefix).
6210 and then Nkind
(N
) in N_Subexpr
6211 and then not Is_OK_Static_Expression
(N
)
6212 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
6213 or else not (Is_Entity_Name
(N
)
6214 and then Is_Type
(Entity
(N
))
6215 and then Is_OK_Static_Subtype
(Entity
(N
))))
6220 -- Freeze type of expression if not frozen already
6224 if Nkind
(N
) in N_Has_Etype
then
6225 if not Is_Frozen
(Etype
(N
)) then
6228 -- Base type may be an derived numeric type that is frozen at
6229 -- the point of declaration, but first_subtype is still unfrozen.
6231 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
6232 Typ
:= First_Subtype
(Etype
(N
));
6236 -- For entity name, freeze entity if not frozen already. A special
6237 -- exception occurs for an identifier that did not come from source.
6238 -- We don't let such identifiers freeze a non-internal entity, i.e.
6239 -- an entity that did come from source, since such an identifier was
6240 -- generated by the expander, and cannot have any semantic effect on
6241 -- the freezing semantics. For example, this stops the parameter of
6242 -- an initialization procedure from freezing the variable.
6244 if Is_Entity_Name
(N
)
6245 and then not Is_Frozen
(Entity
(N
))
6246 and then (Nkind
(N
) /= N_Identifier
6247 or else Comes_From_Source
(N
)
6248 or else not Comes_From_Source
(Entity
(N
)))
6252 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
6253 Check_Expression_Function
(N
, Nam
);
6260 -- For an allocator freeze designated type if not frozen already
6262 -- For an aggregate whose component type is an access type, freeze the
6263 -- designated type now, so that its freeze does not appear within the
6264 -- loop that might be created in the expansion of the aggregate. If the
6265 -- designated type is a private type without full view, the expression
6266 -- cannot contain an allocator, so the type is not frozen.
6268 -- For a function, we freeze the entity when the subprogram declaration
6269 -- is frozen, but a function call may appear in an initialization proc.
6270 -- before the declaration is frozen. We need to generate the extra
6271 -- formals, if any, to ensure that the expansion of the call includes
6272 -- the proper actuals. This only applies to Ada subprograms, not to
6279 Desig_Typ
:= Designated_Type
(Etype
(N
));
6282 if Is_Array_Type
(Etype
(N
))
6283 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
6286 -- Check whether aggregate includes allocators.
6288 Desig_Typ
:= Find_Aggregate_Component_Desig_Type
;
6291 when N_Selected_Component |
6292 N_Indexed_Component |
6295 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6296 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
6299 when N_Identifier
=>
6301 and then Ekind
(Nam
) = E_Function
6302 and then Nkind
(Parent
(N
)) = N_Function_Call
6303 and then Convention
(Nam
) = Convention_Ada
6305 Create_Extra_Formals
(Nam
);
6312 if Desig_Typ
/= Empty
6313 and then (Is_Frozen
(Desig_Typ
)
6314 or else (not Is_Fully_Defined
(Desig_Typ
)))
6319 -- All done if nothing needs freezing
6323 and then No
(Desig_Typ
)
6328 -- Examine the enclosing context by climbing the parent chain. The
6329 -- traversal serves two purposes - to detect scenarios where freezeing
6330 -- is not needed and to find the proper insertion point for the freeze
6331 -- nodes. Although somewhat similar to Insert_Actions, this traversal
6332 -- is freezing semantics-sensitive. Inserting freeze nodes blindly in
6333 -- the tree may result in types being frozen too early.
6337 Parent_P
:= Parent
(P
);
6339 -- If we don't have a parent, then we are not in a well-formed tree.
6340 -- This is an unusual case, but there are some legitimate situations
6341 -- in which this occurs, notably when the expressions in the range of
6342 -- a type declaration are resolved. We simply ignore the freeze
6343 -- request in this case. Is this right ???
6345 if No
(Parent_P
) then
6349 -- See if we have got to an appropriate point in the tree
6351 case Nkind
(Parent_P
) is
6353 -- A special test for the exception of (RM 13.14(8)) for the case
6354 -- of per-object expressions (RM 3.8(18)) occurring in component
6355 -- definition or a discrete subtype definition. Note that we test
6356 -- for a component declaration which includes both cases we are
6357 -- interested in, and furthermore the tree does not have explicit
6358 -- nodes for either of these two constructs.
6360 when N_Component_Declaration
=>
6362 -- The case we want to test for here is an identifier that is
6363 -- a per-object expression, this is either a discriminant that
6364 -- appears in a context other than the component declaration
6365 -- or it is a reference to the type of the enclosing construct.
6367 -- For either of these cases, we skip the freezing
6369 if not In_Spec_Expression
6370 and then Nkind
(N
) = N_Identifier
6371 and then (Present
(Entity
(N
)))
6373 -- We recognize the discriminant case by just looking for
6374 -- a reference to a discriminant. It can only be one for
6375 -- the enclosing construct. Skip freezing in this case.
6377 if Ekind
(Entity
(N
)) = E_Discriminant
then
6380 -- For the case of a reference to the enclosing record,
6381 -- (or task or protected type), we look for a type that
6382 -- matches the current scope.
6384 elsif Entity
(N
) = Current_Scope
then
6389 -- If we have an enumeration literal that appears as the choice in
6390 -- the aggregate of an enumeration representation clause, then
6391 -- freezing does not occur (RM 13.14(10)).
6393 when N_Enumeration_Representation_Clause
=>
6395 -- The case we are looking for is an enumeration literal
6397 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
6398 and then Is_Enumeration_Type
(Etype
(N
))
6400 -- If enumeration literal appears directly as the choice,
6401 -- do not freeze (this is the normal non-overloaded case)
6403 if Nkind
(Parent
(N
)) = N_Component_Association
6404 and then First
(Choices
(Parent
(N
))) = N
6408 -- If enumeration literal appears as the name of function
6409 -- which is the choice, then also do not freeze. This
6410 -- happens in the overloaded literal case, where the
6411 -- enumeration literal is temporarily changed to a function
6412 -- call for overloading analysis purposes.
6414 elsif Nkind
(Parent
(N
)) = N_Function_Call
6416 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
6418 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
6424 -- Normally if the parent is a handled sequence of statements,
6425 -- then the current node must be a statement, and that is an
6426 -- appropriate place to insert a freeze node.
6428 when N_Handled_Sequence_Of_Statements
=>
6430 -- An exception occurs when the sequence of statements is for
6431 -- an expander generated body that did not do the usual freeze
6432 -- all operation. In this case we usually want to freeze
6433 -- outside this body, not inside it, and we skip past the
6434 -- subprogram body that we are inside.
6436 if In_Expanded_Body
(Parent_P
) then
6438 Subp
: constant Node_Id
:= Parent
(Parent_P
);
6442 -- Freeze the entity only when it is declared inside the
6443 -- body of the expander generated procedure. This case
6444 -- is recognized by the scope of the entity or its type,
6445 -- which is either the spec for some enclosing body, or
6446 -- (in the case of init_procs, for which there are no
6447 -- separate specs) the current scope.
6449 if Nkind
(Subp
) = N_Subprogram_Body
then
6450 Spec
:= Corresponding_Spec
(Subp
);
6452 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
6454 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
6459 and then Scope
(Typ
) = Current_Scope
6460 and then Defining_Entity
(Subp
) = Current_Scope
6466 -- An expression function may act as a completion of
6467 -- a function declaration. As such, it can reference
6468 -- entities declared between the two views:
6471 -- function F return ...;
6473 -- function Hidden return ...;
6474 -- function F return ... is (Hidden); -- 2
6476 -- Refering to the example above, freezing the expression
6477 -- of F (2) would place Hidden's freeze node (1) in the
6478 -- wrong place. Avoid explicit freezing and let the usual
6479 -- scenarios do the job - for example, reaching the end
6480 -- of the private declarations, or a call to F.
6482 if Nkind
(Original_Node
(Subp
)) =
6483 N_Expression_Function
6487 -- Freeze outside the body
6490 Parent_P
:= Parent
(Parent_P
);
6491 Freeze_Outside
:= True;
6495 -- Here if normal case where we are in handled statement
6496 -- sequence and want to do the insertion right there.
6502 -- If parent is a body or a spec or a block, then the current node
6503 -- is a statement or declaration and we can insert the freeze node
6506 when N_Block_Statement |
6509 N_Package_Specification |
6512 N_Task_Body
=> exit;
6514 -- The expander is allowed to define types in any statements list,
6515 -- so any of the following parent nodes also mark a freezing point
6516 -- if the actual node is in a list of statements or declarations.
6518 when N_Abortable_Part |
6519 N_Accept_Alternative |
6521 N_Case_Statement_Alternative |
6522 N_Compilation_Unit_Aux |
6523 N_Conditional_Entry_Call |
6524 N_Delay_Alternative |
6526 N_Entry_Call_Alternative |
6527 N_Exception_Handler |
6528 N_Extended_Return_Statement |
6532 N_Selective_Accept |
6533 N_Triggering_Alternative
=>
6535 exit when Is_List_Member
(P
);
6537 -- Freeze nodes produced by an expression coming from the Actions
6538 -- list of a N_Expression_With_Actions node must remain within the
6539 -- Actions list. Inserting the freeze nodes further up the tree
6540 -- may lead to use before declaration issues in the case of array
6543 when N_Expression_With_Actions
=>
6544 if Is_List_Member
(P
)
6545 and then List_Containing
(P
) = Actions
(Parent_P
)
6550 -- Note: N_Loop_Statement is a special case. A type that appears
6551 -- in the source can never be frozen in a loop (this occurs only
6552 -- because of a loop expanded by the expander), so we keep on
6553 -- going. Otherwise we terminate the search. Same is true of any
6554 -- entity which comes from source. (if they have predefined type,
6555 -- that type does not appear to come from source, but the entity
6556 -- should not be frozen here).
6558 when N_Loop_Statement
=>
6559 exit when not Comes_From_Source
(Etype
(N
))
6560 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
6562 -- For all other cases, keep looking at parents
6568 -- We fall through the case if we did not yet find the proper
6569 -- place in the free for inserting the freeze node, so climb.
6574 -- If the expression appears in a record or an initialization procedure,
6575 -- the freeze nodes are collected and attached to the current scope, to
6576 -- be inserted and analyzed on exit from the scope, to insure that
6577 -- generated entities appear in the correct scope. If the expression is
6578 -- a default for a discriminant specification, the scope is still void.
6579 -- The expression can also appear in the discriminant part of a private
6580 -- or concurrent type.
6582 -- If the expression appears in a constrained subcomponent of an
6583 -- enclosing record declaration, the freeze nodes must be attached to
6584 -- the outer record type so they can eventually be placed in the
6585 -- enclosing declaration list.
6587 -- The other case requiring this special handling is if we are in a
6588 -- default expression, since in that case we are about to freeze a
6589 -- static type, and the freeze scope needs to be the outer scope, not
6590 -- the scope of the subprogram with the default parameter.
6592 -- For default expressions and other spec expressions in generic units,
6593 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
6594 -- placing them at the proper place, after the generic unit.
6596 if (In_Spec_Exp
and not Inside_A_Generic
)
6597 or else Freeze_Outside
6598 or else (Is_Type
(Current_Scope
)
6599 and then (not Is_Concurrent_Type
(Current_Scope
)
6600 or else not Has_Completion
(Current_Scope
)))
6601 or else Ekind
(Current_Scope
) = E_Void
6604 N
: constant Node_Id
:= Current_Scope
;
6605 Freeze_Nodes
: List_Id
:= No_List
;
6606 Pos
: Int
:= Scope_Stack
.Last
;
6609 if Present
(Desig_Typ
) then
6610 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
6613 if Present
(Typ
) then
6614 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
6617 if Present
(Nam
) then
6618 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
6621 -- The current scope may be that of a constrained component of
6622 -- an enclosing record declaration, or of a loop of an enclosing
6623 -- quantified expression, which is above the current scope in the
6624 -- scope stack. Indeed in the context of a quantified expression,
6625 -- a scope is created and pushed above the current scope in order
6626 -- to emulate the loop-like behavior of the quantified expression.
6627 -- If the expression is within a top-level pragma, as for a pre-
6628 -- condition on a library-level subprogram, nothing to do.
6630 if not Is_Compilation_Unit
(Current_Scope
)
6631 and then (Is_Record_Type
(Scope
(Current_Scope
))
6632 or else Nkind
(Parent
(Current_Scope
)) =
6633 N_Quantified_Expression
)
6638 if Is_Non_Empty_List
(Freeze_Nodes
) then
6639 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
6640 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
6643 Append_List
(Freeze_Nodes
,
6644 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
6652 -- Now we have the right place to do the freezing. First, a special
6653 -- adjustment, if we are in spec-expression analysis mode, these freeze
6654 -- actions must not be thrown away (normally all inserted actions are
6655 -- thrown away in this mode. However, the freeze actions are from static
6656 -- expressions and one of the important reasons we are doing this
6657 -- special analysis is to get these freeze actions. Therefore we turn
6658 -- off the In_Spec_Expression mode to propagate these freeze actions.
6659 -- This also means they get properly analyzed and expanded.
6661 In_Spec_Expression
:= False;
6663 -- Freeze the designated type of an allocator (RM 13.14(13))
6665 if Present
(Desig_Typ
) then
6666 Freeze_Before
(P
, Desig_Typ
);
6669 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
6670 -- the enumeration representation clause exception in the loop above.
6672 if Present
(Typ
) then
6673 Freeze_Before
(P
, Typ
);
6676 -- Freeze name if one is present (RM 13.14(11))
6678 if Present
(Nam
) then
6679 Freeze_Before
(P
, Nam
);
6682 -- Restore In_Spec_Expression flag
6684 In_Spec_Expression
:= In_Spec_Exp
;
6685 end Freeze_Expression
;
6687 -----------------------------
6688 -- Freeze_Fixed_Point_Type --
6689 -----------------------------
6691 -- Certain fixed-point types and subtypes, including implicit base types
6692 -- and declared first subtypes, have not yet set up a range. This is
6693 -- because the range cannot be set until the Small and Size values are
6694 -- known, and these are not known till the type is frozen.
6696 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
6697 -- whose bounds are unanalyzed real literals. This routine will recognize
6698 -- this case, and transform this range node into a properly typed range
6699 -- with properly analyzed and resolved values.
6701 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
6702 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
6703 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
6704 Hi
: constant Node_Id
:= High_Bound
(Rng
);
6705 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6706 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
6707 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
6708 BHi
: constant Node_Id
:= High_Bound
(Brng
);
6709 Small
: constant Ureal
:= Small_Value
(Typ
);
6716 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
6717 -- Returns size of type with given bounds. Also leaves these
6718 -- bounds set as the current bounds of the Typ.
6724 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
6726 Set_Realval
(Lo
, Lov
);
6727 Set_Realval
(Hi
, Hiv
);
6728 return Minimum_Size
(Typ
);
6731 -- Start of processing for Freeze_Fixed_Point_Type
6734 -- If Esize of a subtype has not previously been set, set it now
6736 if Unknown_Esize
(Typ
) then
6737 Atype
:= Ancestor_Subtype
(Typ
);
6739 if Present
(Atype
) then
6740 Set_Esize
(Typ
, Esize
(Atype
));
6742 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
6746 -- Immediate return if the range is already analyzed. This means that
6747 -- the range is already set, and does not need to be computed by this
6750 if Analyzed
(Rng
) then
6754 -- Immediate return if either of the bounds raises Constraint_Error
6756 if Raises_Constraint_Error
(Lo
)
6757 or else Raises_Constraint_Error
(Hi
)
6762 Loval
:= Realval
(Lo
);
6763 Hival
:= Realval
(Hi
);
6765 -- Ordinary fixed-point case
6767 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
6769 -- For the ordinary fixed-point case, we are allowed to fudge the
6770 -- end-points up or down by small. Generally we prefer to fudge up,
6771 -- i.e. widen the bounds for non-model numbers so that the end points
6772 -- are included. However there are cases in which this cannot be
6773 -- done, and indeed cases in which we may need to narrow the bounds.
6774 -- The following circuit makes the decision.
6776 -- Note: our terminology here is that Incl_EP means that the bounds
6777 -- are widened by Small if necessary to include the end points, and
6778 -- Excl_EP means that the bounds are narrowed by Small to exclude the
6779 -- end-points if this reduces the size.
6781 -- Note that in the Incl case, all we care about is including the
6782 -- end-points. In the Excl case, we want to narrow the bounds as
6783 -- much as permitted by the RM, to give the smallest possible size.
6786 Loval_Incl_EP
: Ureal
;
6787 Hival_Incl_EP
: Ureal
;
6789 Loval_Excl_EP
: Ureal
;
6790 Hival_Excl_EP
: Ureal
;
6796 First_Subt
: Entity_Id
;
6801 -- First step. Base types are required to be symmetrical. Right
6802 -- now, the base type range is a copy of the first subtype range.
6803 -- This will be corrected before we are done, but right away we
6804 -- need to deal with the case where both bounds are non-negative.
6805 -- In this case, we set the low bound to the negative of the high
6806 -- bound, to make sure that the size is computed to include the
6807 -- required sign. Note that we do not need to worry about the
6808 -- case of both bounds negative, because the sign will be dealt
6809 -- with anyway. Furthermore we can't just go making such a bound
6810 -- symmetrical, since in a twos-complement system, there is an
6811 -- extra negative value which could not be accommodated on the
6815 and then not UR_Is_Negative
(Loval
)
6816 and then Hival
> Loval
6819 Set_Realval
(Lo
, Loval
);
6822 -- Compute the fudged bounds. If the number is a model number,
6823 -- then we do nothing to include it, but we are allowed to backoff
6824 -- to the next adjacent model number when we exclude it. If it is
6825 -- not a model number then we straddle the two values with the
6826 -- model numbers on either side.
6828 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
6830 if Loval
= Model_Num
then
6831 Loval_Incl_EP
:= Model_Num
;
6833 Loval_Incl_EP
:= Model_Num
- Small
;
6836 -- The low value excluding the end point is Small greater, but
6837 -- we do not do this exclusion if the low value is positive,
6838 -- since it can't help the size and could actually hurt by
6839 -- crossing the high bound.
6841 if UR_Is_Negative
(Loval_Incl_EP
) then
6842 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
6844 -- If the value went from negative to zero, then we have the
6845 -- case where Loval_Incl_EP is the model number just below
6846 -- zero, so we want to stick to the negative value for the
6847 -- base type to maintain the condition that the size will
6848 -- include signed values.
6851 and then UR_Is_Zero
(Loval_Excl_EP
)
6853 Loval_Excl_EP
:= Loval_Incl_EP
;
6857 Loval_Excl_EP
:= Loval_Incl_EP
;
6860 -- Similar processing for upper bound and high value
6862 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
6864 if Hival
= Model_Num
then
6865 Hival_Incl_EP
:= Model_Num
;
6867 Hival_Incl_EP
:= Model_Num
+ Small
;
6870 if UR_Is_Positive
(Hival_Incl_EP
) then
6871 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
6873 Hival_Excl_EP
:= Hival_Incl_EP
;
6876 -- One further adjustment is needed. In the case of subtypes, we
6877 -- cannot go outside the range of the base type, or we get
6878 -- peculiarities, and the base type range is already set. This
6879 -- only applies to the Incl values, since clearly the Excl values
6880 -- are already as restricted as they are allowed to be.
6883 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
6884 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
6887 -- Get size including and excluding end points
6889 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
6890 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
6892 -- No need to exclude end-points if it does not reduce size
6894 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
6895 Loval_Excl_EP
:= Loval_Incl_EP
;
6898 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
6899 Hival_Excl_EP
:= Hival_Incl_EP
;
6902 -- Now we set the actual size to be used. We want to use the
6903 -- bounds fudged up to include the end-points but only if this
6904 -- can be done without violating a specifically given size
6905 -- size clause or causing an unacceptable increase in size.
6907 -- Case of size clause given
6909 if Has_Size_Clause
(Typ
) then
6911 -- Use the inclusive size only if it is consistent with
6912 -- the explicitly specified size.
6914 if Size_Incl_EP
<= RM_Size
(Typ
) then
6915 Actual_Lo
:= Loval_Incl_EP
;
6916 Actual_Hi
:= Hival_Incl_EP
;
6917 Actual_Size
:= Size_Incl_EP
;
6919 -- If the inclusive size is too large, we try excluding
6920 -- the end-points (will be caught later if does not work).
6923 Actual_Lo
:= Loval_Excl_EP
;
6924 Actual_Hi
:= Hival_Excl_EP
;
6925 Actual_Size
:= Size_Excl_EP
;
6928 -- Case of size clause not given
6931 -- If we have a base type whose corresponding first subtype
6932 -- has an explicit size that is large enough to include our
6933 -- end-points, then do so. There is no point in working hard
6934 -- to get a base type whose size is smaller than the specified
6935 -- size of the first subtype.
6937 First_Subt
:= First_Subtype
(Typ
);
6939 if Has_Size_Clause
(First_Subt
)
6940 and then Size_Incl_EP
<= Esize
(First_Subt
)
6942 Actual_Size
:= Size_Incl_EP
;
6943 Actual_Lo
:= Loval_Incl_EP
;
6944 Actual_Hi
:= Hival_Incl_EP
;
6946 -- If excluding the end-points makes the size smaller and
6947 -- results in a size of 8,16,32,64, then we take the smaller
6948 -- size. For the 64 case, this is compulsory. For the other
6949 -- cases, it seems reasonable. We like to include end points
6950 -- if we can, but not at the expense of moving to the next
6951 -- natural boundary of size.
6953 elsif Size_Incl_EP
/= Size_Excl_EP
6954 and then Addressable
(Size_Excl_EP
)
6956 Actual_Size
:= Size_Excl_EP
;
6957 Actual_Lo
:= Loval_Excl_EP
;
6958 Actual_Hi
:= Hival_Excl_EP
;
6960 -- Otherwise we can definitely include the end points
6963 Actual_Size
:= Size_Incl_EP
;
6964 Actual_Lo
:= Loval_Incl_EP
;
6965 Actual_Hi
:= Hival_Incl_EP
;
6968 -- One pathological case: normally we never fudge a low bound
6969 -- down, since it would seem to increase the size (if it has
6970 -- any effect), but for ranges containing single value, or no
6971 -- values, the high bound can be small too large. Consider:
6973 -- type t is delta 2.0**(-14)
6974 -- range 131072.0 .. 0;
6976 -- That lower bound is *just* outside the range of 32 bits, and
6977 -- does need fudging down in this case. Note that the bounds
6978 -- will always have crossed here, since the high bound will be
6979 -- fudged down if necessary, as in the case of:
6981 -- type t is delta 2.0**(-14)
6982 -- range 131072.0 .. 131072.0;
6984 -- So we detect the situation by looking for crossed bounds,
6985 -- and if the bounds are crossed, and the low bound is greater
6986 -- than zero, we will always back it off by small, since this
6987 -- is completely harmless.
6989 if Actual_Lo
> Actual_Hi
then
6990 if UR_Is_Positive
(Actual_Lo
) then
6991 Actual_Lo
:= Loval_Incl_EP
- Small
;
6992 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
6994 -- And of course, we need to do exactly the same parallel
6995 -- fudge for flat ranges in the negative region.
6997 elsif UR_Is_Negative
(Actual_Hi
) then
6998 Actual_Hi
:= Hival_Incl_EP
+ Small
;
6999 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
7004 Set_Realval
(Lo
, Actual_Lo
);
7005 Set_Realval
(Hi
, Actual_Hi
);
7008 -- For the decimal case, none of this fudging is required, since there
7009 -- are no end-point problems in the decimal case (the end-points are
7010 -- always included).
7013 Actual_Size
:= Fsize
(Loval
, Hival
);
7016 -- At this stage, the actual size has been calculated and the proper
7017 -- required bounds are stored in the low and high bounds.
7019 if Actual_Size
> 64 then
7020 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
7022 ("size required (^) for type& too large, maximum allowed is 64",
7027 -- Check size against explicit given size
7029 if Has_Size_Clause
(Typ
) then
7030 if Actual_Size
> RM_Size
(Typ
) then
7031 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7032 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
7034 ("size given (^) for type& too small, minimum allowed is ^",
7035 Size_Clause
(Typ
), Typ
);
7038 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
7041 -- Increase size to next natural boundary if no size clause given
7044 if Actual_Size
<= 8 then
7046 elsif Actual_Size
<= 16 then
7048 elsif Actual_Size
<= 32 then
7054 Init_Esize
(Typ
, Actual_Size
);
7055 Adjust_Esize_For_Alignment
(Typ
);
7058 -- If we have a base type, then expand the bounds so that they extend to
7059 -- the full width of the allocated size in bits, to avoid junk range
7060 -- checks on intermediate computations.
7062 if Base_Type
(Typ
) = Typ
then
7063 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
7064 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
7067 -- Final step is to reanalyze the bounds using the proper type
7068 -- and set the Corresponding_Integer_Value fields of the literals.
7070 Set_Etype
(Lo
, Empty
);
7071 Set_Analyzed
(Lo
, False);
7074 -- Resolve with universal fixed if the base type, and the base type if
7075 -- it is a subtype. Note we can't resolve the base type with itself,
7076 -- that would be a reference before definition.
7079 Resolve
(Lo
, Universal_Fixed
);
7084 -- Set corresponding integer value for bound
7086 Set_Corresponding_Integer_Value
7087 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
7089 -- Similar processing for high bound
7091 Set_Etype
(Hi
, Empty
);
7092 Set_Analyzed
(Hi
, False);
7096 Resolve
(Hi
, Universal_Fixed
);
7101 Set_Corresponding_Integer_Value
7102 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
7104 -- Set type of range to correspond to bounds
7106 Set_Etype
(Rng
, Etype
(Lo
));
7108 -- Set Esize to calculated size if not set already
7110 if Unknown_Esize
(Typ
) then
7111 Init_Esize
(Typ
, Actual_Size
);
7114 -- Set RM_Size if not already set. If already set, check value
7117 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
7120 if RM_Size
(Typ
) /= Uint_0
then
7121 if RM_Size
(Typ
) < Minsiz
then
7122 Error_Msg_Uint_1
:= RM_Size
(Typ
);
7123 Error_Msg_Uint_2
:= Minsiz
;
7125 ("size given (^) for type& too small, minimum allowed is ^",
7126 Size_Clause
(Typ
), Typ
);
7130 Set_RM_Size
(Typ
, Minsiz
);
7133 end Freeze_Fixed_Point_Type
;
7139 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
7143 Set_Has_Delayed_Freeze
(T
);
7144 L
:= Freeze_Entity
(T
, N
);
7146 if Is_Non_Empty_List
(L
) then
7147 Insert_Actions
(N
, L
);
7151 --------------------------
7152 -- Freeze_Static_Object --
7153 --------------------------
7155 procedure Freeze_Static_Object
(E
: Entity_Id
) is
7157 Cannot_Be_Static
: exception;
7158 -- Exception raised if the type of a static object cannot be made
7159 -- static. This happens if the type depends on non-global objects.
7161 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
7162 -- Called to ensure that an expression used as part of a type definition
7163 -- is statically allocatable, which means that the expression type is
7164 -- statically allocatable, and the expression is either static, or a
7165 -- reference to a library level constant.
7167 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
7168 -- Called to mark a type as static, checking that it is possible
7169 -- to set the type as static. If it is not possible, then the
7170 -- exception Cannot_Be_Static is raised.
7172 -----------------------------
7173 -- Ensure_Expression_Is_SA --
7174 -----------------------------
7176 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
7180 Ensure_Type_Is_SA
(Etype
(N
));
7182 if Is_OK_Static_Expression
(N
) then
7185 elsif Nkind
(N
) = N_Identifier
then
7189 and then Ekind
(Ent
) = E_Constant
7190 and then Is_Library_Level_Entity
(Ent
)
7196 raise Cannot_Be_Static
;
7197 end Ensure_Expression_Is_SA
;
7199 -----------------------
7200 -- Ensure_Type_Is_SA --
7201 -----------------------
7203 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
7208 -- If type is library level, we are all set
7210 if Is_Library_Level_Entity
(Typ
) then
7214 -- We are also OK if the type already marked as statically allocated,
7215 -- which means we processed it before.
7217 if Is_Statically_Allocated
(Typ
) then
7221 -- Mark type as statically allocated
7223 Set_Is_Statically_Allocated
(Typ
);
7225 -- Check that it is safe to statically allocate this type
7227 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
7228 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
7229 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
7231 elsif Is_Array_Type
(Typ
) then
7232 N
:= First_Index
(Typ
);
7233 while Present
(N
) loop
7234 Ensure_Type_Is_SA
(Etype
(N
));
7238 Ensure_Type_Is_SA
(Component_Type
(Typ
));
7240 elsif Is_Access_Type
(Typ
) then
7241 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
7245 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
7248 if T
/= Standard_Void_Type
then
7249 Ensure_Type_Is_SA
(T
);
7252 F
:= First_Formal
(Designated_Type
(Typ
));
7253 while Present
(F
) loop
7254 Ensure_Type_Is_SA
(Etype
(F
));
7260 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
7263 elsif Is_Record_Type
(Typ
) then
7264 C
:= First_Entity
(Typ
);
7265 while Present
(C
) loop
7266 if Ekind
(C
) = E_Discriminant
7267 or else Ekind
(C
) = E_Component
7269 Ensure_Type_Is_SA
(Etype
(C
));
7271 elsif Is_Type
(C
) then
7272 Ensure_Type_Is_SA
(C
);
7278 elsif Ekind
(Typ
) = E_Subprogram_Type
then
7279 Ensure_Type_Is_SA
(Etype
(Typ
));
7281 C
:= First_Formal
(Typ
);
7282 while Present
(C
) loop
7283 Ensure_Type_Is_SA
(Etype
(C
));
7288 raise Cannot_Be_Static
;
7290 end Ensure_Type_Is_SA
;
7292 -- Start of processing for Freeze_Static_Object
7295 Ensure_Type_Is_SA
(Etype
(E
));
7298 when Cannot_Be_Static
=>
7300 -- If the object that cannot be static is imported or exported, then
7301 -- issue an error message saying that this object cannot be imported
7302 -- or exported. If it has an address clause it is an overlay in the
7303 -- current partition and the static requirement is not relevant.
7304 -- Do not issue any error message when ignoring rep clauses.
7306 if Ignore_Rep_Clauses
then
7309 elsif Is_Imported
(E
) then
7310 if No
(Address_Clause
(E
)) then
7312 ("& cannot be imported (local type is not constant)", E
);
7315 -- Otherwise must be exported, something is wrong if compiler
7316 -- is marking something as statically allocated which cannot be).
7318 else pragma Assert
(Is_Exported
(E
));
7320 ("& cannot be exported (local type is not constant)", E
);
7322 end Freeze_Static_Object
;
7324 -----------------------
7325 -- Freeze_Subprogram --
7326 -----------------------
7328 procedure Freeze_Subprogram
(E
: Entity_Id
) is
7333 -- Subprogram may not have an address clause unless it is imported
7335 if Present
(Address_Clause
(E
)) then
7336 if not Is_Imported
(E
) then
7338 ("address clause can only be given " &
7339 "for imported subprogram",
7340 Name
(Address_Clause
(E
)));
7344 -- Reset the Pure indication on an imported subprogram unless an
7345 -- explicit Pure_Function pragma was present or the subprogram is an
7346 -- intrinsic. We do this because otherwise it is an insidious error
7347 -- to call a non-pure function from pure unit and have calls
7348 -- mysteriously optimized away. What happens here is that the Import
7349 -- can bypass the normal check to ensure that pure units call only pure
7352 -- The reason for the intrinsic exception is that in general, intrinsic
7353 -- functions (such as shifts) are pure anyway. The only exceptions are
7354 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
7355 -- in any case, so no problem arises.
7358 and then Is_Pure
(E
)
7359 and then not Has_Pragma_Pure_Function
(E
)
7360 and then not Is_Intrinsic_Subprogram
(E
)
7362 Set_Is_Pure
(E
, False);
7365 -- For non-foreign convention subprograms, this is where we create
7366 -- the extra formals (for accessibility level and constrained bit
7367 -- information). We delay this till the freeze point precisely so
7368 -- that we know the convention.
7370 if not Has_Foreign_Convention
(E
) then
7371 Create_Extra_Formals
(E
);
7374 -- If this is convention Ada and a Valued_Procedure, that's odd
7376 if Ekind
(E
) = E_Procedure
7377 and then Is_Valued_Procedure
(E
)
7378 and then Convention
(E
) = Convention_Ada
7379 and then Warn_On_Export_Import
7382 ("??Valued_Procedure has no effect for convention Ada", E
);
7383 Set_Is_Valued_Procedure
(E
, False);
7386 -- Case of foreign convention
7391 -- For foreign conventions, warn about return of unconstrained array
7393 if Ekind
(E
) = E_Function
then
7394 Retype
:= Underlying_Type
(Etype
(E
));
7396 -- If no return type, probably some other error, e.g. a
7397 -- missing full declaration, so ignore.
7402 -- If the return type is generic, we have emitted a warning
7403 -- earlier on, and there is nothing else to check here. Specific
7404 -- instantiations may lead to erroneous behavior.
7406 elsif Is_Generic_Type
(Etype
(E
)) then
7409 -- Display warning if returning unconstrained array
7411 elsif Is_Array_Type
(Retype
)
7412 and then not Is_Constrained
(Retype
)
7414 -- Check appropriate warning is enabled (should we check for
7415 -- Warnings (Off) on specific entities here, probably so???)
7417 and then Warn_On_Export_Import
7419 -- Exclude the VM case, since return of unconstrained arrays
7420 -- is properly handled in both the JVM and .NET cases.
7422 and then VM_Target
= No_VM
7425 ("?x?foreign convention function& should not return " &
7426 "unconstrained array", E
);
7431 -- If any of the formals for an exported foreign convention
7432 -- subprogram have defaults, then emit an appropriate warning since
7433 -- this is odd (default cannot be used from non-Ada code)
7435 if Is_Exported
(E
) then
7436 F
:= First_Formal
(E
);
7437 while Present
(F
) loop
7438 if Warn_On_Export_Import
7439 and then Present
(Default_Value
(F
))
7442 ("?x?parameter cannot be defaulted in non-Ada call",
7451 -- Pragma Inline_Always is disallowed for dispatching subprograms
7452 -- because the address of such subprograms is saved in the dispatch
7453 -- table to support dispatching calls, and dispatching calls cannot
7454 -- be inlined. This is consistent with the restriction against using
7455 -- 'Access or 'Address on an Inline_Always subprogram.
7457 if Is_Dispatching_Operation
(E
)
7458 and then Has_Pragma_Inline_Always
(E
)
7461 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
7464 -- Because of the implicit representation of inherited predefined
7465 -- operators in the front-end, the overriding status of the operation
7466 -- may be affected when a full view of a type is analyzed, and this is
7467 -- not captured by the analysis of the corresponding type declaration.
7468 -- Therefore the correctness of a not-overriding indicator must be
7469 -- rechecked when the subprogram is frozen.
7471 if Nkind
(E
) = N_Defining_Operator_Symbol
7472 and then not Error_Posted
(Parent
(E
))
7474 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
7476 end Freeze_Subprogram
;
7478 ----------------------
7479 -- Is_Fully_Defined --
7480 ----------------------
7482 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
7484 if Ekind
(T
) = E_Class_Wide_Type
then
7485 return Is_Fully_Defined
(Etype
(T
));
7487 elsif Is_Array_Type
(T
) then
7488 return Is_Fully_Defined
(Component_Type
(T
));
7490 elsif Is_Record_Type
(T
)
7491 and not Is_Private_Type
(T
)
7493 -- Verify that the record type has no components with private types
7494 -- without completion.
7500 Comp
:= First_Component
(T
);
7501 while Present
(Comp
) loop
7502 if not Is_Fully_Defined
(Etype
(Comp
)) then
7506 Next_Component
(Comp
);
7511 -- For the designated type of an access to subprogram, all types in
7512 -- the profile must be fully defined.
7514 elsif Ekind
(T
) = E_Subprogram_Type
then
7519 F
:= First_Formal
(T
);
7520 while Present
(F
) loop
7521 if not Is_Fully_Defined
(Etype
(F
)) then
7528 return Is_Fully_Defined
(Etype
(T
));
7532 return not Is_Private_Type
(T
)
7533 or else Present
(Full_View
(Base_Type
(T
)));
7535 end Is_Fully_Defined
;
7537 ---------------------------------
7538 -- Process_Default_Expressions --
7539 ---------------------------------
7541 procedure Process_Default_Expressions
7543 After
: in out Node_Id
)
7545 Loc
: constant Source_Ptr
:= Sloc
(E
);
7552 Set_Default_Expressions_Processed
(E
);
7554 -- A subprogram instance and its associated anonymous subprogram share
7555 -- their signature. The default expression functions are defined in the
7556 -- wrapper packages for the anonymous subprogram, and should not be
7557 -- generated again for the instance.
7559 if Is_Generic_Instance
(E
)
7560 and then Present
(Alias
(E
))
7561 and then Default_Expressions_Processed
(Alias
(E
))
7566 Formal
:= First_Formal
(E
);
7567 while Present
(Formal
) loop
7568 if Present
(Default_Value
(Formal
)) then
7570 -- We work with a copy of the default expression because we
7571 -- do not want to disturb the original, since this would mess
7572 -- up the conformance checking.
7574 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
7576 -- The analysis of the expression may generate insert actions,
7577 -- which of course must not be executed. We wrap those actions
7578 -- in a procedure that is not called, and later on eliminated.
7579 -- The following cases have no side-effects, and are analyzed
7582 if Nkind
(Dcopy
) = N_Identifier
7583 or else Nkind_In
(Dcopy
, N_Expanded_Name
,
7585 N_Character_Literal
,
7588 or else (Nkind
(Dcopy
) = N_Attribute_Reference
7589 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
7590 or else Known_Null
(Dcopy
)
7592 -- If there is no default function, we must still do a full
7593 -- analyze call on the default value, to ensure that all error
7594 -- checks are performed, e.g. those associated with static
7595 -- evaluation. Note: this branch will always be taken if the
7596 -- analyzer is turned off (but we still need the error checks).
7598 -- Note: the setting of parent here is to meet the requirement
7599 -- that we can only analyze the expression while attached to
7600 -- the tree. Really the requirement is that the parent chain
7601 -- be set, we don't actually need to be in the tree.
7603 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
7606 -- Default expressions are resolved with their own type if the
7607 -- context is generic, to avoid anomalies with private types.
7609 if Ekind
(Scope
(E
)) = E_Generic_Package
then
7612 Resolve
(Dcopy
, Etype
(Formal
));
7615 -- If that resolved expression will raise constraint error,
7616 -- then flag the default value as raising constraint error.
7617 -- This allows a proper error message on the calls.
7619 if Raises_Constraint_Error
(Dcopy
) then
7620 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
7623 -- If the default is a parameterless call, we use the name of
7624 -- the called function directly, and there is no body to build.
7626 elsif Nkind
(Dcopy
) = N_Function_Call
7627 and then No
(Parameter_Associations
(Dcopy
))
7631 -- Else construct and analyze the body of a wrapper procedure
7632 -- that contains an object declaration to hold the expression.
7633 -- Given that this is done only to complete the analysis, it
7634 -- simpler to build a procedure than a function which might
7635 -- involve secondary stack expansion.
7638 Dnam
:= Make_Temporary
(Loc
, 'D');
7641 Make_Subprogram_Body
(Loc
,
7643 Make_Procedure_Specification
(Loc
,
7644 Defining_Unit_Name
=> Dnam
),
7646 Declarations
=> New_List
(
7647 Make_Object_Declaration
(Loc
,
7648 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
7649 Object_Definition
=>
7650 New_Occurrence_Of
(Etype
(Formal
), Loc
),
7651 Expression
=> New_Copy_Tree
(Dcopy
))),
7653 Handled_Statement_Sequence
=>
7654 Make_Handled_Sequence_Of_Statements
(Loc
,
7655 Statements
=> Empty_List
));
7657 Set_Scope
(Dnam
, Scope
(E
));
7658 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
7659 Set_Is_Eliminated
(Dnam
);
7660 Insert_After
(After
, Dbody
);
7666 Next_Formal
(Formal
);
7668 end Process_Default_Expressions
;
7670 ----------------------------------------
7671 -- Set_Component_Alignment_If_Not_Set --
7672 ----------------------------------------
7674 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
7676 -- Ignore if not base type, subtypes don't need anything
7678 if Typ
/= Base_Type
(Typ
) then
7682 -- Do not override existing representation
7684 if Is_Packed
(Typ
) then
7687 elsif Has_Specified_Layout
(Typ
) then
7690 elsif Component_Alignment
(Typ
) /= Calign_Default
then
7694 Set_Component_Alignment
7695 (Typ
, Scope_Stack
.Table
7696 (Scope_Stack
.Last
).Component_Alignment_Default
);
7698 end Set_Component_Alignment_If_Not_Set
;
7700 --------------------------
7701 -- Set_SSO_From_Default --
7702 --------------------------
7704 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
7706 -- Set default SSO for an array or record base type, except in case of
7707 -- a type extension (which always inherits the SSO of its parent type).
7710 and then (Is_Array_Type
(T
)
7711 or else (Is_Record_Type
(T
)
7712 and then not (Is_Tagged_Type
(T
)
7713 and then Is_Derived_Type
(T
))))
7715 if ((Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
7717 ((not Bytes_Big_Endian
) and then SSO_Set_High_By_Default
(T
)))
7719 -- For a record type, if native bit order is specified explicitly,
7720 -- then never set reverse SSO from default.
7724 and then Has_Rep_Item
(T
, Name_Bit_Order
)
7725 and then not Reverse_Bit_Order
(T
))
7727 -- If flags cause reverse storage order, then set the result. Note
7728 -- that we would have ignored the pragma setting the non default
7729 -- storage order in any case, hence the assertion at this point.
7731 pragma Assert
(Support_Nondefault_SSO_On_Target
);
7732 Set_Reverse_Storage_Order
(T
);
7734 -- For a record type, also set reversed bit order. Note that if
7735 -- a bit order has been specified explicitly, then this is a
7736 -- no-op, as per the guard above.
7738 if Is_Record_Type
(T
) then
7739 Set_Reverse_Bit_Order
(T
);
7743 end Set_SSO_From_Default
;
7749 procedure Undelay_Type
(T
: Entity_Id
) is
7751 Set_Has_Delayed_Freeze
(T
, False);
7752 Set_Freeze_Node
(T
, Empty
);
7754 -- Since we don't want T to have a Freeze_Node, we don't want its
7755 -- Full_View or Corresponding_Record_Type to have one either.
7757 -- ??? Fundamentally, this whole handling is unpleasant. What we really
7758 -- want is to be sure that for an Itype that's part of record R and is a
7759 -- subtype of type T, that it's frozen after the later of the freeze
7760 -- points of R and T. We have no way of doing that directly, so what we
7761 -- do is force most such Itypes to be frozen as part of freezing R via
7762 -- this procedure and only delay the ones that need to be delayed
7763 -- (mostly the designated types of access types that are defined as part
7766 if Is_Private_Type
(T
)
7767 and then Present
(Full_View
(T
))
7768 and then Is_Itype
(Full_View
(T
))
7769 and then Is_Record_Type
(Scope
(Full_View
(T
)))
7771 Undelay_Type
(Full_View
(T
));
7774 if Is_Concurrent_Type
(T
)
7775 and then Present
(Corresponding_Record_Type
(T
))
7776 and then Is_Itype
(Corresponding_Record_Type
(T
))
7777 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
7779 Undelay_Type
(Corresponding_Record_Type
(T
));
7787 procedure Warn_Overlay
7792 Ent
: constant Entity_Id
:= Entity
(Nam
);
7793 -- The object to which the address clause applies
7796 Old
: Entity_Id
:= Empty
;
7800 -- No warning if address clause overlay warnings are off
7802 if not Address_Clause_Overlay_Warnings
then
7806 -- No warning if there is an explicit initialization
7808 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
7810 if Present
(Init
) and then Comes_From_Source
(Init
) then
7814 -- We only give the warning for non-imported entities of a type for
7815 -- which a non-null base init proc is defined, or for objects of access
7816 -- types with implicit null initialization, or when Normalize_Scalars
7817 -- applies and the type is scalar or a string type (the latter being
7818 -- tested for because predefined String types are initialized by inline
7819 -- code rather than by an init_proc). Note that we do not give the
7820 -- warning for Initialize_Scalars, since we suppressed initialization
7821 -- in this case. Also, do not warn if Suppress_Initialization is set.
7824 and then not Is_Imported
(Ent
)
7825 and then not Initialization_Suppressed
(Typ
)
7826 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
7827 or else Is_Access_Type
(Typ
)
7828 or else (Normalize_Scalars
7829 and then (Is_Scalar_Type
(Typ
)
7830 or else Is_String_Type
(Typ
))))
7832 if Nkind
(Expr
) = N_Attribute_Reference
7833 and then Is_Entity_Name
(Prefix
(Expr
))
7835 Old
:= Entity
(Prefix
(Expr
));
7837 elsif Is_Entity_Name
(Expr
)
7838 and then Ekind
(Entity
(Expr
)) = E_Constant
7840 Decl
:= Declaration_Node
(Entity
(Expr
));
7842 if Nkind
(Decl
) = N_Object_Declaration
7843 and then Present
(Expression
(Decl
))
7844 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
7845 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
7847 Old
:= Entity
(Prefix
(Expression
(Decl
)));
7849 elsif Nkind
(Expr
) = N_Function_Call
then
7853 -- A function call (most likely to To_Address) is probably not an
7854 -- overlay, so skip warning. Ditto if the function call was inlined
7855 -- and transformed into an entity.
7857 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
7861 Decl
:= Next
(Parent
(Expr
));
7863 -- If a pragma Import follows, we assume that it is for the current
7864 -- target of the address clause, and skip the warning.
7867 and then Nkind
(Decl
) = N_Pragma
7868 and then Pragma_Name
(Decl
) = Name_Import
7873 if Present
(Old
) then
7874 Error_Msg_Node_2
:= Old
;
7876 ("default initialization of & may modify &??",
7880 ("default initialization of & may modify overlaid storage??",
7884 -- Add friendly warning if initialization comes from a packed array
7887 if Is_Record_Type
(Typ
) then
7892 Comp
:= First_Component
(Typ
);
7893 while Present
(Comp
) loop
7894 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
7895 and then Present
(Expression
(Parent
(Comp
)))
7898 elsif Is_Array_Type
(Etype
(Comp
))
7899 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
7902 ("\packed array component& " &
7903 "will be initialized to zero??",
7907 Next_Component
(Comp
);
7914 ("\use pragma Import for & to " &
7915 "suppress initialization (RM B.1(24))??",