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 procedure Check_Strict_Alignment
(E
: Entity_Id
);
116 -- E is a base type. If E is tagged or has a component that is aliased
117 -- or tagged or contains something this is aliased or tagged, set
120 procedure Check_Unsigned_Type
(E
: Entity_Id
);
121 pragma Inline
(Check_Unsigned_Type
);
122 -- If E is a fixed-point or discrete type, then all the necessary work
123 -- to freeze it is completed except for possible setting of the flag
124 -- Is_Unsigned_Type, which is done by this procedure. The call has no
125 -- effect if the entity E is not a discrete or fixed-point type.
127 procedure Freeze_And_Append
130 Result
: in out List_Id
);
131 -- Freezes Ent using Freeze_Entity, and appends the resulting list of
132 -- nodes to Result, modifying Result from No_List if necessary. N has
133 -- the same usage as in Freeze_Entity.
135 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
);
136 -- Freeze enumeration type. The Esize field is set as processing
137 -- proceeds (i.e. set by default when the type is declared and then
138 -- adjusted by rep clauses. What this procedure does is to make sure
139 -- that if a foreign convention is specified, and no specific size
140 -- is given, then the size must be at least Integer'Size.
142 procedure Freeze_Static_Object
(E
: Entity_Id
);
143 -- If an object is frozen which has Is_Statically_Allocated set, then
144 -- all referenced types must also be marked with this flag. This routine
145 -- is in charge of meeting this requirement for the object entity E.
147 procedure Freeze_Subprogram
(E
: Entity_Id
);
148 -- Perform freezing actions for a subprogram (create extra formals,
149 -- and set proper default mechanism values). Note that this routine
150 -- is not called for internal subprograms, for which neither of these
151 -- actions is needed (or desirable, we do not want for example to have
152 -- these extra formals present in initialization procedures, where they
153 -- would serve no purpose). In this call E is either a subprogram or
154 -- a subprogram type (i.e. an access to a subprogram).
156 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean;
157 -- True if T is not private and has no private components, or has a full
158 -- view. Used to determine whether the designated type of an access type
159 -- should be frozen when the access type is frozen. This is done when an
160 -- allocator is frozen, or an expression that may involve attributes of
161 -- the designated type. Otherwise freezing the access type does not freeze
162 -- the designated type.
164 procedure Process_Default_Expressions
166 After
: in out Node_Id
);
167 -- This procedure is called for each subprogram to complete processing of
168 -- default expressions at the point where all types are known to be frozen.
169 -- The expressions must be analyzed in full, to make sure that all error
170 -- processing is done (they have only been pre-analyzed). If the expression
171 -- is not an entity or literal, its analysis may generate code which must
172 -- not be executed. In that case we build a function body to hold that
173 -- code. This wrapper function serves no other purpose (it used to be
174 -- called to evaluate the default, but now the default is inlined at each
177 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
);
178 -- Typ is a record or array type that is being frozen. This routine sets
179 -- the default component alignment from the scope stack values if the
180 -- alignment is otherwise not specified.
182 procedure Check_Debug_Info_Needed
(T
: Entity_Id
);
183 -- As each entity is frozen, this routine is called to deal with the
184 -- setting of Debug_Info_Needed for the entity. This flag is set if
185 -- the entity comes from source, or if we are in Debug_Generated_Code
186 -- mode or if the -gnatdV debug flag is set. However, it never sets
187 -- the flag if Debug_Info_Off is set. This procedure also ensures that
188 -- subsidiary entities have the flag set as required.
190 procedure Set_SSO_From_Default
(T
: Entity_Id
);
191 -- T is a record or array type that is being frozen. If it is a base type,
192 -- and if SSO_Set_Low/High_By_Default is set, then Reverse_Storage order
193 -- will be set appropriately. Note that an explicit occurrence of aspect
194 -- Scalar_Storage_Order or an explicit setting of this aspect with an
195 -- attribute definition clause occurs, then these two flags are reset in
196 -- any case, so call will have no effect.
198 procedure Undelay_Type
(T
: Entity_Id
);
199 -- T is a type of a component that we know to be an Itype. We don't want
200 -- this to have a Freeze_Node, so ensure it doesn't. Do the same for any
201 -- Full_View or Corresponding_Record_Type.
203 procedure Warn_Overlay
207 -- Expr is the expression for an address clause for entity Nam whose type
208 -- is Typ. If Typ has a default initialization, and there is no explicit
209 -- initialization in the source declaration, check whether the address
210 -- clause might cause overlaying of an entity, and emit a warning on the
211 -- side effect that the initialization will cause.
213 -------------------------------
214 -- Adjust_Esize_For_Alignment --
215 -------------------------------
217 procedure Adjust_Esize_For_Alignment
(Typ
: Entity_Id
) is
221 if Known_Esize
(Typ
) and then Known_Alignment
(Typ
) then
222 Align
:= Alignment_In_Bits
(Typ
);
224 if Align
> Esize
(Typ
)
225 and then Align
<= Standard_Long_Long_Integer_Size
227 Set_Esize
(Typ
, Align
);
230 end Adjust_Esize_For_Alignment
;
232 ------------------------------------
233 -- Build_And_Analyze_Renamed_Body --
234 ------------------------------------
236 procedure Build_And_Analyze_Renamed_Body
239 After
: in out Node_Id
)
241 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
242 Ent
: constant Entity_Id
:= Defining_Entity
(Decl
);
244 Renamed_Subp
: Entity_Id
;
247 -- If the renamed subprogram is intrinsic, there is no need for a
248 -- wrapper body: we set the alias that will be called and expanded which
249 -- completes the declaration. This transformation is only legal if the
250 -- renamed entity has already been elaborated.
252 -- Note that it is legal for a renaming_as_body to rename an intrinsic
253 -- subprogram, as long as the renaming occurs before the new entity
254 -- is frozen (RM 8.5.4 (5)).
256 if Nkind
(Body_Decl
) = N_Subprogram_Renaming_Declaration
257 and then Is_Entity_Name
(Name
(Body_Decl
))
259 Renamed_Subp
:= Entity
(Name
(Body_Decl
));
261 Renamed_Subp
:= Empty
;
264 if Present
(Renamed_Subp
)
265 and then Is_Intrinsic_Subprogram
(Renamed_Subp
)
267 (not In_Same_Source_Unit
(Renamed_Subp
, Ent
)
268 or else Sloc
(Renamed_Subp
) < Sloc
(Ent
))
270 -- We can make the renaming entity intrinsic if the renamed function
271 -- has an interface name, or if it is one of the shift/rotate
272 -- operations known to the compiler.
275 (Present
(Interface_Name
(Renamed_Subp
))
276 or else Nam_In
(Chars
(Renamed_Subp
), Name_Rotate_Left
,
280 Name_Shift_Right_Arithmetic
))
282 Set_Interface_Name
(Ent
, Interface_Name
(Renamed_Subp
));
284 if Present
(Alias
(Renamed_Subp
)) then
285 Set_Alias
(Ent
, Alias
(Renamed_Subp
));
287 Set_Alias
(Ent
, Renamed_Subp
);
290 Set_Is_Intrinsic_Subprogram
(Ent
);
291 Set_Has_Completion
(Ent
);
294 Body_Node
:= Build_Renamed_Body
(Decl
, New_S
);
295 Insert_After
(After
, Body_Node
);
296 Mark_Rewrite_Insertion
(Body_Node
);
300 end Build_And_Analyze_Renamed_Body
;
302 ------------------------
303 -- Build_Renamed_Body --
304 ------------------------
306 function Build_Renamed_Body
308 New_S
: Entity_Id
) return Node_Id
310 Loc
: constant Source_Ptr
:= Sloc
(New_S
);
311 -- We use for the source location of the renamed body, the location of
312 -- the spec entity. It might seem more natural to use the location of
313 -- the renaming declaration itself, but that would be wrong, since then
314 -- the body we create would look as though it was created far too late,
315 -- and this could cause problems with elaboration order analysis,
316 -- particularly in connection with instantiations.
318 N
: constant Node_Id
:= Unit_Declaration_Node
(New_S
);
319 Nam
: constant Node_Id
:= Name
(N
);
321 Spec
: constant Node_Id
:= New_Copy_Tree
(Specification
(Decl
));
322 Actuals
: List_Id
:= No_List
;
327 O_Formal
: Entity_Id
;
328 Param_Spec
: Node_Id
;
330 Pref
: Node_Id
:= Empty
;
331 -- If the renamed entity is a primitive operation given in prefix form,
332 -- the prefix is the target object and it has to be added as the first
333 -- actual in the generated call.
336 -- Determine the entity being renamed, which is the target of the call
337 -- statement. If the name is an explicit dereference, this is a renaming
338 -- of a subprogram type rather than a subprogram. The name itself is
341 if Nkind
(Nam
) = N_Selected_Component
then
342 Old_S
:= Entity
(Selector_Name
(Nam
));
344 elsif Nkind
(Nam
) = N_Explicit_Dereference
then
345 Old_S
:= Etype
(Nam
);
347 elsif Nkind
(Nam
) = N_Indexed_Component
then
348 if Is_Entity_Name
(Prefix
(Nam
)) then
349 Old_S
:= Entity
(Prefix
(Nam
));
351 Old_S
:= Entity
(Selector_Name
(Prefix
(Nam
)));
354 elsif Nkind
(Nam
) = N_Character_Literal
then
355 Old_S
:= Etype
(New_S
);
358 Old_S
:= Entity
(Nam
);
361 if Is_Entity_Name
(Nam
) then
363 -- If the renamed entity is a predefined operator, retain full name
364 -- to ensure its visibility.
366 if Ekind
(Old_S
) = E_Operator
367 and then Nkind
(Nam
) = N_Expanded_Name
369 Call_Name
:= New_Copy
(Name
(N
));
371 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
375 if Nkind
(Nam
) = N_Selected_Component
376 and then Present
(First_Formal
(Old_S
))
378 (Is_Controlling_Formal
(First_Formal
(Old_S
))
379 or else Is_Class_Wide_Type
(Etype
(First_Formal
(Old_S
))))
382 -- Retrieve the target object, to be added as a first actual
385 Call_Name
:= New_Occurrence_Of
(Old_S
, Loc
);
386 Pref
:= Prefix
(Nam
);
389 Call_Name
:= New_Copy
(Name
(N
));
392 -- Original name may have been overloaded, but is fully resolved now
394 Set_Is_Overloaded
(Call_Name
, False);
397 -- For simple renamings, subsequent calls can be expanded directly as
398 -- calls to the renamed entity. The body must be generated in any case
399 -- for calls that may appear elsewhere. This is not done in the case
400 -- where the subprogram is an instantiation because the actual proper
401 -- body has not been built yet.
403 if Ekind_In
(Old_S
, E_Function
, E_Procedure
)
404 and then Nkind
(Decl
) = N_Subprogram_Declaration
405 and then not Is_Generic_Instance
(Old_S
)
407 Set_Body_To_Inline
(Decl
, Old_S
);
410 -- The body generated for this renaming is an internal artifact, and
411 -- does not constitute a freeze point for the called entity.
413 Set_Must_Not_Freeze
(Call_Name
);
415 Formal
:= First_Formal
(Defining_Entity
(Decl
));
417 if Present
(Pref
) then
419 Pref_Type
: constant Entity_Id
:= Etype
(Pref
);
420 Form_Type
: constant Entity_Id
:= Etype
(First_Formal
(Old_S
));
423 -- The controlling formal may be an access parameter, or the
424 -- actual may be an access value, so adjust accordingly.
426 if Is_Access_Type
(Pref_Type
)
427 and then not Is_Access_Type
(Form_Type
)
430 (Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
432 elsif Is_Access_Type
(Form_Type
)
433 and then not Is_Access_Type
(Pref
)
436 (Make_Attribute_Reference
(Loc
,
437 Attribute_Name
=> Name_Access
,
438 Prefix
=> Relocate_Node
(Pref
)));
440 Actuals
:= New_List
(Pref
);
444 elsif Present
(Formal
) then
451 if Present
(Formal
) then
452 while Present
(Formal
) loop
453 Append
(New_Occurrence_Of
(Formal
, Loc
), Actuals
);
454 Next_Formal
(Formal
);
458 -- If the renamed entity is an entry, inherit its profile. For other
459 -- renamings as bodies, both profiles must be subtype conformant, so it
460 -- is not necessary to replace the profile given in the declaration.
461 -- However, default values that are aggregates are rewritten when
462 -- partially analyzed, so we recover the original aggregate to insure
463 -- that subsequent conformity checking works. Similarly, if the default
464 -- expression was constant-folded, recover the original expression.
466 Formal
:= First_Formal
(Defining_Entity
(Decl
));
468 if Present
(Formal
) then
469 O_Formal
:= First_Formal
(Old_S
);
470 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
471 while Present
(Formal
) loop
472 if Is_Entry
(Old_S
) then
473 if Nkind
(Parameter_Type
(Param_Spec
)) /=
476 Set_Etype
(Formal
, Etype
(O_Formal
));
477 Set_Entity
(Parameter_Type
(Param_Spec
), Etype
(O_Formal
));
480 elsif Nkind
(Default_Value
(O_Formal
)) = N_Aggregate
481 or else Nkind
(Original_Node
(Default_Value
(O_Formal
))) /=
482 Nkind
(Default_Value
(O_Formal
))
484 Set_Expression
(Param_Spec
,
485 New_Copy_Tree
(Original_Node
(Default_Value
(O_Formal
))));
488 Next_Formal
(Formal
);
489 Next_Formal
(O_Formal
);
494 -- If the renamed entity is a function, the generated body contains a
495 -- return statement. Otherwise, build a procedure call. If the entity is
496 -- an entry, subsequent analysis of the call will transform it into the
497 -- proper entry or protected operation call. If the renamed entity is
498 -- a character literal, return it directly.
500 if Ekind
(Old_S
) = E_Function
501 or else Ekind
(Old_S
) = E_Operator
502 or else (Ekind
(Old_S
) = E_Subprogram_Type
503 and then Etype
(Old_S
) /= Standard_Void_Type
)
506 Make_Simple_Return_Statement
(Loc
,
508 Make_Function_Call
(Loc
,
510 Parameter_Associations
=> Actuals
));
512 elsif Ekind
(Old_S
) = E_Enumeration_Literal
then
514 Make_Simple_Return_Statement
(Loc
,
515 Expression
=> New_Occurrence_Of
(Old_S
, Loc
));
517 elsif Nkind
(Nam
) = N_Character_Literal
then
519 Make_Simple_Return_Statement
(Loc
,
520 Expression
=> Call_Name
);
524 Make_Procedure_Call_Statement
(Loc
,
526 Parameter_Associations
=> Actuals
);
529 -- Create entities for subprogram body and formals
531 Set_Defining_Unit_Name
(Spec
,
532 Make_Defining_Identifier
(Loc
, Chars
=> Chars
(New_S
)));
534 Param_Spec
:= First
(Parameter_Specifications
(Spec
));
535 while Present
(Param_Spec
) loop
536 Set_Defining_Identifier
(Param_Spec
,
537 Make_Defining_Identifier
(Loc
,
538 Chars
=> Chars
(Defining_Identifier
(Param_Spec
))));
543 Make_Subprogram_Body
(Loc
,
544 Specification
=> Spec
,
545 Declarations
=> New_List
,
546 Handled_Statement_Sequence
=>
547 Make_Handled_Sequence_Of_Statements
(Loc
,
548 Statements
=> New_List
(Call_Node
)));
550 if Nkind
(Decl
) /= N_Subprogram_Declaration
then
552 Make_Subprogram_Declaration
(Loc
,
553 Specification
=> Specification
(N
)));
556 -- Link the body to the entity whose declaration it completes. If
557 -- the body is analyzed when the renamed entity is frozen, it may
558 -- be necessary to restore the proper scope (see package Exp_Ch13).
560 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
561 and then Present
(Corresponding_Spec
(N
))
563 Set_Corresponding_Spec
(Body_Node
, Corresponding_Spec
(N
));
565 Set_Corresponding_Spec
(Body_Node
, New_S
);
569 end Build_Renamed_Body
;
571 --------------------------
572 -- Check_Address_Clause --
573 --------------------------
575 procedure Check_Address_Clause
(E
: Entity_Id
) is
576 Addr
: constant Node_Id
:= Address_Clause
(E
);
578 Decl
: constant Node_Id
:= Declaration_Node
(E
);
579 Loc
: constant Source_Ptr
:= Sloc
(Decl
);
580 Typ
: constant Entity_Id
:= Etype
(E
);
583 if Present
(Addr
) then
584 Expr
:= Expression
(Addr
);
586 if Needs_Constant_Address
(Decl
, Typ
) then
587 Check_Constant_Address_Clause
(Expr
, E
);
589 -- Has_Delayed_Freeze was set on E when the address clause was
590 -- analyzed, and must remain set because we want the address
591 -- clause to be elaborated only after any entity it references
592 -- has been elaborated.
595 -- If Rep_Clauses are to be ignored, remove address clause from
596 -- list attached to entity, because it may be illegal for gigi,
597 -- for example by breaking order of elaboration..
599 if Ignore_Rep_Clauses
then
604 Rep
:= First_Rep_Item
(E
);
607 Set_First_Rep_Item
(E
, Next_Rep_Item
(Addr
));
611 and then Next_Rep_Item
(Rep
) /= Addr
613 Rep
:= Next_Rep_Item
(Rep
);
617 if Present
(Rep
) then
618 Set_Next_Rep_Item
(Rep
, Next_Rep_Item
(Addr
));
622 -- And now remove the address clause
624 Kill_Rep_Clause
(Addr
);
626 elsif not Error_Posted
(Expr
)
627 and then not Needs_Finalization
(Typ
)
629 Warn_Overlay
(Expr
, Typ
, Name
(Addr
));
632 if Present
(Expression
(Decl
)) then
634 -- Capture initialization value at point of declaration
636 Remove_Side_Effects
(Expression
(Decl
));
638 -- Move initialization to freeze actions (once the object has
639 -- been frozen, and the address clause alignment check has been
642 Append_Freeze_Action
(E
,
643 Make_Assignment_Statement
(Loc
,
644 Name
=> New_Occurrence_Of
(E
, Loc
),
645 Expression
=> Expression
(Decl
)));
647 Set_No_Initialization
(Decl
);
650 end Check_Address_Clause
;
652 -----------------------------
653 -- Check_Compile_Time_Size --
654 -----------------------------
656 procedure Check_Compile_Time_Size
(T
: Entity_Id
) is
658 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
);
659 -- Sets the compile time known size (32 bits or less) in the Esize
660 -- field, of T checking for a size clause that was given which attempts
661 -- to give a smaller size, and also checking for an alignment clause.
663 function Size_Known
(T
: Entity_Id
) return Boolean;
664 -- Recursive function that does all the work
666 function Static_Discriminated_Components
(T
: Entity_Id
) return Boolean;
667 -- If T is a constrained subtype, its size is not known if any of its
668 -- discriminant constraints is not static and it is not a null record.
669 -- The test is conservative and doesn't check that the components are
670 -- in fact constrained by non-static discriminant values. Could be made
677 procedure Set_Small_Size
(T
: Entity_Id
; S
: Uint
) is
682 -- Check for bad size clause given
684 elsif Has_Size_Clause
(T
) then
685 if RM_Size
(T
) < S
then
686 Error_Msg_Uint_1
:= S
;
688 ("size for& too small, minimum allowed is ^",
692 -- Set size if not set already
694 elsif Unknown_RM_Size
(T
) then
703 function Size_Known
(T
: Entity_Id
) return Boolean is
711 if Size_Known_At_Compile_Time
(T
) then
714 -- Always True for scalar types. This is true even for generic formal
715 -- scalar types. We used to return False in the latter case, but the
716 -- size is known at compile time, even in the template, we just do
717 -- not know the exact size but that's not the point of this routine.
719 elsif Is_Scalar_Type
(T
)
720 or else Is_Task_Type
(T
)
726 elsif Is_Array_Type
(T
) then
728 -- String literals always have known size, and we can set it
730 if Ekind
(T
) = E_String_Literal_Subtype
then
731 Set_Small_Size
(T
, Component_Size
(T
)
732 * String_Literal_Length
(T
));
735 -- Unconstrained types never have known at compile time size
737 elsif not Is_Constrained
(T
) then
740 -- Don't do any recursion on type with error posted, since we may
741 -- have a malformed type that leads us into a loop.
743 elsif Error_Posted
(T
) then
746 -- Otherwise if component size unknown, then array size unknown
748 elsif not Size_Known
(Component_Type
(T
)) then
752 -- Check for all indexes static, and also compute possible size
753 -- (in case it is less than 32 and may be packable).
756 Esiz
: Uint
:= Component_Size
(T
);
760 Index
:= First_Index
(T
);
761 while Present
(Index
) loop
762 if Nkind
(Index
) = N_Range
then
763 Get_Index_Bounds
(Index
, Low
, High
);
765 elsif Error_Posted
(Scalar_Range
(Etype
(Index
))) then
769 Low
:= Type_Low_Bound
(Etype
(Index
));
770 High
:= Type_High_Bound
(Etype
(Index
));
773 if not Compile_Time_Known_Value
(Low
)
774 or else not Compile_Time_Known_Value
(High
)
775 or else Etype
(Index
) = Any_Type
780 Dim
:= Expr_Value
(High
) - Expr_Value
(Low
) + 1;
792 Set_Small_Size
(T
, Esiz
);
796 -- Access types always have known at compile time sizes
798 elsif Is_Access_Type
(T
) then
801 -- For non-generic private types, go to underlying type if present
803 elsif Is_Private_Type
(T
)
804 and then not Is_Generic_Type
(T
)
805 and then Present
(Underlying_Type
(T
))
807 -- Don't do any recursion on type with error posted, since we may
808 -- have a malformed type that leads us into a loop.
810 if Error_Posted
(T
) then
813 return Size_Known
(Underlying_Type
(T
));
818 elsif Is_Record_Type
(T
) then
820 -- A class-wide type is never considered to have a known size
822 if Is_Class_Wide_Type
(T
) then
825 -- A subtype of a variant record must not have non-static
826 -- discriminated components.
828 elsif T
/= Base_Type
(T
)
829 and then not Static_Discriminated_Components
(T
)
833 -- Don't do any recursion on type with error posted, since we may
834 -- have a malformed type that leads us into a loop.
836 elsif Error_Posted
(T
) then
840 -- Now look at the components of the record
843 -- The following two variables are used to keep track of the
844 -- size of packed records if we can tell the size of the packed
845 -- record in the front end. Packed_Size_Known is True if so far
846 -- we can figure out the size. It is initialized to True for a
847 -- packed record, unless the record has discriminants or atomic
848 -- components or independent components.
850 -- The reason we eliminate the discriminated case is that
851 -- we don't know the way the back end lays out discriminated
852 -- packed records. If Packed_Size_Known is True, then
853 -- Packed_Size is the size in bits so far.
855 Packed_Size_Known
: Boolean :=
857 and then not Has_Discriminants
(T
)
858 and then not Has_Atomic_Components
(T
)
859 and then not Has_Independent_Components
(T
);
861 Packed_Size
: Uint
:= Uint_0
;
862 -- Size in bits so far
865 -- Test for variant part present
867 if Has_Discriminants
(T
)
868 and then Present
(Parent
(T
))
869 and then Nkind
(Parent
(T
)) = N_Full_Type_Declaration
870 and then Nkind
(Type_Definition
(Parent
(T
))) =
872 and then not Null_Present
(Type_Definition
(Parent
(T
)))
874 Present
(Variant_Part
875 (Component_List
(Type_Definition
(Parent
(T
)))))
877 -- If variant part is present, and type is unconstrained,
878 -- then we must have defaulted discriminants, or a size
879 -- clause must be present for the type, or else the size
880 -- is definitely not known at compile time.
882 if not Is_Constrained
(T
)
884 No
(Discriminant_Default_Value
(First_Discriminant
(T
)))
885 and then Unknown_RM_Size
(T
)
891 -- Loop through components
893 Comp
:= First_Component_Or_Discriminant
(T
);
894 while Present
(Comp
) loop
895 Ctyp
:= Etype
(Comp
);
897 -- We do not know the packed size if there is a component
898 -- clause present (we possibly could, but this would only
899 -- help in the case of a record with partial rep clauses.
900 -- That's because in the case of full rep clauses, the
901 -- size gets figured out anyway by a different circuit).
903 if Present
(Component_Clause
(Comp
)) then
904 Packed_Size_Known
:= False;
907 -- We do not know the packed size if we have a by reference
908 -- type, or an atomic type or an atomic component, or an
909 -- aliased component (because packing does not touch these).
912 or else Is_Atomic
(Comp
)
913 or else Is_By_Reference_Type
(Ctyp
)
914 or else Is_Aliased
(Comp
)
916 Packed_Size_Known
:= False;
919 -- We need to identify a component that is an array where
920 -- the index type is an enumeration type with non-standard
921 -- representation, and some bound of the type depends on a
924 -- This is because gigi computes the size by doing a
925 -- substitution of the appropriate discriminant value in
926 -- the size expression for the base type, and gigi is not
927 -- clever enough to evaluate the resulting expression (which
928 -- involves a call to rep_to_pos) at compile time.
930 -- It would be nice if gigi would either recognize that
931 -- this expression can be computed at compile time, or
932 -- alternatively figured out the size from the subtype
933 -- directly, where all the information is at hand ???
935 if Is_Array_Type
(Etype
(Comp
))
936 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
939 Ocomp
: constant Entity_Id
:=
940 Original_Record_Component
(Comp
);
941 OCtyp
: constant Entity_Id
:= Etype
(Ocomp
);
947 Ind
:= First_Index
(OCtyp
);
948 while Present
(Ind
) loop
949 Indtyp
:= Etype
(Ind
);
951 if Is_Enumeration_Type
(Indtyp
)
952 and then Has_Non_Standard_Rep
(Indtyp
)
954 Lo
:= Type_Low_Bound
(Indtyp
);
955 Hi
:= Type_High_Bound
(Indtyp
);
957 if Is_Entity_Name
(Lo
)
958 and then Ekind
(Entity
(Lo
)) = E_Discriminant
962 elsif Is_Entity_Name
(Hi
)
963 and then Ekind
(Entity
(Hi
)) = E_Discriminant
974 -- Clearly size of record is not known if the size of one of
975 -- the components is not known.
977 if not Size_Known
(Ctyp
) then
981 -- Accumulate packed size if possible
983 if Packed_Size_Known
then
985 -- We can only deal with elementary types, since for
986 -- non-elementary components, alignment enters into the
987 -- picture, and we don't know enough to handle proper
988 -- alignment in this context. Packed arrays count as
989 -- elementary if the representation is a modular type.
991 if Is_Elementary_Type
(Ctyp
)
992 or else (Is_Array_Type
(Ctyp
)
994 (Packed_Array_Impl_Type
(Ctyp
))
995 and then Is_Modular_Integer_Type
996 (Packed_Array_Impl_Type
(Ctyp
)))
998 -- Packed size unknown if we have an atomic type
999 -- or a by reference type, since the back end
1000 -- knows how these are layed out.
1003 or else Is_By_Reference_Type
(Ctyp
)
1005 Packed_Size_Known
:= False;
1007 -- If RM_Size is known and static, then we can keep
1008 -- accumulating the packed size
1010 elsif Known_Static_RM_Size
(Ctyp
) then
1012 -- A little glitch, to be removed sometime ???
1013 -- gigi does not understand zero sizes yet.
1015 if RM_Size
(Ctyp
) = Uint_0
then
1016 Packed_Size_Known
:= False;
1018 -- Normal case where we can keep accumulating the
1019 -- packed array size.
1022 Packed_Size
:= Packed_Size
+ RM_Size
(Ctyp
);
1025 -- If we have a field whose RM_Size is not known then
1026 -- we can't figure out the packed size here.
1029 Packed_Size_Known
:= False;
1032 -- If we have a non-elementary type we can't figure out
1033 -- the packed array size (alignment issues).
1036 Packed_Size_Known
:= False;
1040 Next_Component_Or_Discriminant
(Comp
);
1043 if Packed_Size_Known
then
1044 Set_Small_Size
(T
, Packed_Size
);
1050 -- All other cases, size not known at compile time
1057 -------------------------------------
1058 -- Static_Discriminated_Components --
1059 -------------------------------------
1061 function Static_Discriminated_Components
1062 (T
: Entity_Id
) return Boolean
1064 Constraint
: Elmt_Id
;
1067 if Has_Discriminants
(T
)
1068 and then Present
(Discriminant_Constraint
(T
))
1069 and then Present
(First_Component
(T
))
1071 Constraint
:= First_Elmt
(Discriminant_Constraint
(T
));
1072 while Present
(Constraint
) loop
1073 if not Compile_Time_Known_Value
(Node
(Constraint
)) then
1077 Next_Elmt
(Constraint
);
1082 end Static_Discriminated_Components
;
1084 -- Start of processing for Check_Compile_Time_Size
1087 Set_Size_Known_At_Compile_Time
(T
, Size_Known
(T
));
1088 end Check_Compile_Time_Size
;
1090 -----------------------------------
1091 -- Check_Component_Storage_Order --
1092 -----------------------------------
1094 procedure Check_Component_Storage_Order
1095 (Encl_Type
: Entity_Id
;
1098 Comp_ADC_Present
: out Boolean)
1100 Comp_Type
: Entity_Id
;
1104 Comp_Byte_Aligned
: Boolean;
1105 -- Set for the record case, True if Comp starts on a byte boundary
1106 -- (in which case it is allowed to have different storage order).
1108 Comp_SSO_Differs
: Boolean;
1109 -- Set True when the component is a nested composite, and it does not
1110 -- have the same scalar storage order as Encl_Type.
1112 Component_Aliased
: Boolean;
1117 if Present
(Comp
) then
1119 Comp_Type
:= Etype
(Comp
);
1121 if Is_Tag
(Comp
) then
1122 Comp_Byte_Aligned
:= True;
1123 Component_Aliased
:= False;
1126 -- If a component clause is present, check if the component starts
1127 -- on a storage element boundary. Otherwise conservatively assume
1128 -- it does so only in the case where the record is not packed.
1130 if Present
(Component_Clause
(Comp
)) then
1131 Comp_Byte_Aligned
:=
1132 Normalized_First_Bit
(Comp
) mod System_Storage_Unit
= 0;
1134 Comp_Byte_Aligned
:= not Is_Packed
(Encl_Type
);
1137 Component_Aliased
:= Is_Aliased
(Comp
);
1143 Err_Node
:= Encl_Type
;
1144 Comp_Type
:= Component_Type
(Encl_Type
);
1146 Component_Aliased
:= Has_Aliased_Components
(Encl_Type
);
1149 -- Note: the Reverse_Storage_Order flag is set on the base type, but
1150 -- the attribute definition clause is attached to the first subtype.
1152 Comp_Type
:= Base_Type
(Comp_Type
);
1153 Comp_ADC
:= Get_Attribute_Definition_Clause
1154 (First_Subtype
(Comp_Type
),
1155 Attribute_Scalar_Storage_Order
);
1156 Comp_ADC_Present
:= Present
(Comp_ADC
);
1158 -- Case of record or array component: check storage order compatibility
1160 if Is_Record_Type
(Comp_Type
) or else Is_Array_Type
(Comp_Type
) then
1162 Reverse_Storage_Order
(Encl_Type
)
1164 Reverse_Storage_Order
(Comp_Type
);
1166 -- Parent and extension must have same storage order
1168 if Present
(Comp
) and then Chars
(Comp
) = Name_uParent
then
1169 if Comp_SSO_Differs
then
1171 ("record extension must have same scalar storage order as "
1172 & "parent", Err_Node
);
1175 -- If enclosing composite has explicit SSO then nested composite must
1176 -- have explicit SSO as well.
1178 elsif Present
(ADC
) and then No
(Comp_ADC
) then
1179 Error_Msg_N
("nested composite must have explicit scalar "
1180 & "storage order", Err_Node
);
1182 -- If component and composite SSO differs, check that component
1183 -- falls on byte boundaries and isn't packed.
1185 elsif Comp_SSO_Differs
then
1187 -- Component SSO differs from enclosing composite:
1189 -- Reject if component is a packed array, as it may be represented
1190 -- as a scalar internally.
1192 if Is_Packed_Array
(Comp_Type
) then
1194 ("type of packed component must have same scalar "
1195 & "storage order as enclosing composite", Err_Node
);
1197 -- Reject if composite is a packed array, as it may be rewritten
1198 -- into an array of scalars.
1200 elsif Is_Packed_Array
(Encl_Type
) then
1201 Error_Msg_N
("type of packed array must have same scalar "
1202 & "storage order as component", Err_Node
);
1204 -- Reject if not byte aligned
1206 elsif Is_Record_Type
(Encl_Type
)
1207 and then not Comp_Byte_Aligned
1210 ("type of non-byte-aligned component must have same scalar "
1211 & "storage order as enclosing composite", Err_Node
);
1215 -- Enclosing type has explicit SSO: non-composite component must not
1218 elsif Present
(ADC
) and then Component_Aliased
then
1220 ("aliased component not permitted for type with "
1221 & "explicit Scalar_Storage_Order", Err_Node
);
1223 end Check_Component_Storage_Order
;
1225 -----------------------------
1226 -- Check_Debug_Info_Needed --
1227 -----------------------------
1229 procedure Check_Debug_Info_Needed
(T
: Entity_Id
) is
1231 if Debug_Info_Off
(T
) then
1234 elsif Comes_From_Source
(T
)
1235 or else Debug_Generated_Code
1236 or else Debug_Flag_VV
1237 or else Needs_Debug_Info
(T
)
1239 Set_Debug_Info_Needed
(T
);
1241 end Check_Debug_Info_Needed
;
1243 -------------------------------
1244 -- Check_Expression_Function --
1245 -------------------------------
1247 procedure Check_Expression_Function
(N
: Node_Id
; Nam
: Entity_Id
) is
1250 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
;
1251 -- Function to search for deferred constant
1257 function Find_Constant
(Nod
: Node_Id
) return Traverse_Result
is
1259 -- When a constant is initialized with the result of a dispatching
1260 -- call, the constant declaration is rewritten as a renaming of the
1261 -- displaced function result. This scenario is not a premature use of
1262 -- a constant even though the Has_Completion flag is not set.
1264 if Is_Entity_Name
(Nod
)
1265 and then Present
(Entity
(Nod
))
1266 and then Ekind
(Entity
(Nod
)) = E_Constant
1267 and then Scope
(Entity
(Nod
)) = Current_Scope
1268 and then Nkind
(Declaration_Node
(Entity
(Nod
))) =
1269 N_Object_Declaration
1270 and then not Is_Imported
(Entity
(Nod
))
1271 and then not Has_Completion
(Entity
(Nod
))
1274 ("premature use of& in call or instance", N
, Entity
(Nod
));
1280 procedure Check_Deferred
is new Traverse_Proc
(Find_Constant
);
1282 -- Start of processing for Check_Expression_Function
1285 Decl
:= Original_Node
(Unit_Declaration_Node
(Nam
));
1287 if Scope
(Nam
) = Current_Scope
1288 and then Nkind
(Decl
) = N_Expression_Function
1290 Check_Deferred
(Expression
(Decl
));
1292 end Check_Expression_Function
;
1294 ----------------------------
1295 -- Check_Strict_Alignment --
1296 ----------------------------
1298 procedure Check_Strict_Alignment
(E
: Entity_Id
) is
1302 if Is_Tagged_Type
(E
) or else Is_Concurrent_Type
(E
) then
1303 Set_Strict_Alignment
(E
);
1305 elsif Is_Array_Type
(E
) then
1306 Set_Strict_Alignment
(E
, Strict_Alignment
(Component_Type
(E
)));
1308 elsif Is_Record_Type
(E
) then
1309 if Is_Limited_Record
(E
) then
1310 Set_Strict_Alignment
(E
);
1314 Comp
:= First_Component
(E
);
1315 while Present
(Comp
) loop
1316 if not Is_Type
(Comp
)
1317 and then (Strict_Alignment
(Etype
(Comp
))
1318 or else Is_Aliased
(Comp
))
1320 Set_Strict_Alignment
(E
);
1324 Next_Component
(Comp
);
1327 end Check_Strict_Alignment
;
1329 -------------------------
1330 -- Check_Unsigned_Type --
1331 -------------------------
1333 procedure Check_Unsigned_Type
(E
: Entity_Id
) is
1334 Ancestor
: Entity_Id
;
1339 if not Is_Discrete_Or_Fixed_Point_Type
(E
) then
1343 -- Do not attempt to analyze case where range was in error
1345 if No
(Scalar_Range
(E
)) or else Error_Posted
(Scalar_Range
(E
)) then
1349 -- The situation that is non trivial is something like
1351 -- subtype x1 is integer range -10 .. +10;
1352 -- subtype x2 is x1 range 0 .. V1;
1353 -- subtype x3 is x2 range V2 .. V3;
1354 -- subtype x4 is x3 range V4 .. V5;
1356 -- where Vn are variables. Here the base type is signed, but we still
1357 -- know that x4 is unsigned because of the lower bound of x2.
1359 -- The only way to deal with this is to look up the ancestor chain
1363 if Ancestor
= Any_Type
or else Etype
(Ancestor
) = Any_Type
then
1367 Lo_Bound
:= Type_Low_Bound
(Ancestor
);
1369 if Compile_Time_Known_Value
(Lo_Bound
) then
1370 if Expr_Rep_Value
(Lo_Bound
) >= 0 then
1371 Set_Is_Unsigned_Type
(E
, True);
1377 Ancestor
:= Ancestor_Subtype
(Ancestor
);
1379 -- If no ancestor had a static lower bound, go to base type
1381 if No
(Ancestor
) then
1383 -- Note: the reason we still check for a compile time known
1384 -- value for the base type is that at least in the case of
1385 -- generic formals, we can have bounds that fail this test,
1386 -- and there may be other cases in error situations.
1388 Btyp
:= Base_Type
(E
);
1390 if Btyp
= Any_Type
or else Etype
(Btyp
) = Any_Type
then
1394 Lo_Bound
:= Type_Low_Bound
(Base_Type
(E
));
1396 if Compile_Time_Known_Value
(Lo_Bound
)
1397 and then Expr_Rep_Value
(Lo_Bound
) >= 0
1399 Set_Is_Unsigned_Type
(E
, True);
1406 end Check_Unsigned_Type
;
1408 -------------------------
1409 -- Is_Atomic_Aggregate --
1410 -------------------------
1412 function Is_Atomic_Aggregate
1414 Typ
: Entity_Id
) return Boolean
1416 Loc
: constant Source_Ptr
:= Sloc
(E
);
1424 -- Array may be qualified, so find outer context
1426 if Nkind
(Par
) = N_Qualified_Expression
then
1427 Par
:= Parent
(Par
);
1430 if Nkind_In
(Par
, N_Object_Declaration
, N_Assignment_Statement
)
1431 and then Comes_From_Source
(Par
)
1433 Temp
:= Make_Temporary
(Loc
, 'T', E
);
1435 Make_Object_Declaration
(Loc
,
1436 Defining_Identifier
=> Temp
,
1437 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
1438 Expression
=> Relocate_Node
(E
));
1439 Insert_Before
(Par
, New_N
);
1442 Set_Expression
(Par
, New_Occurrence_Of
(Temp
, Loc
));
1448 end Is_Atomic_Aggregate
;
1450 -----------------------------------------------
1451 -- Explode_Initialization_Compound_Statement --
1452 -----------------------------------------------
1454 procedure Explode_Initialization_Compound_Statement
(E
: Entity_Id
) is
1455 Init_Stmts
: constant Node_Id
:= Initialization_Statements
(E
);
1458 if Present
(Init_Stmts
)
1459 and then Nkind
(Init_Stmts
) = N_Compound_Statement
1461 Insert_List_Before
(Init_Stmts
, Actions
(Init_Stmts
));
1463 -- Note that we rewrite Init_Stmts into a NULL statement, rather than
1464 -- just removing it, because Freeze_All may rely on this particular
1465 -- Node_Id still being present in the enclosing list to know where to
1468 Rewrite
(Init_Stmts
, Make_Null_Statement
(Sloc
(Init_Stmts
)));
1470 Set_Initialization_Statements
(E
, Empty
);
1472 end Explode_Initialization_Compound_Statement
;
1478 -- Note: the easy coding for this procedure would be to just build a
1479 -- single list of freeze nodes and then insert them and analyze them
1480 -- all at once. This won't work, because the analysis of earlier freeze
1481 -- nodes may recursively freeze types which would otherwise appear later
1482 -- on in the freeze list. So we must analyze and expand the freeze nodes
1483 -- as they are generated.
1485 procedure Freeze_All
(From
: Entity_Id
; After
: in out Node_Id
) is
1489 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
);
1490 -- This is the internal recursive routine that does freezing of entities
1491 -- (but NOT the analysis of default expressions, which should not be
1492 -- recursive, we don't want to analyze those till we are sure that ALL
1493 -- the types are frozen).
1495 --------------------
1496 -- Freeze_All_Ent --
1497 --------------------
1499 procedure Freeze_All_Ent
(From
: Entity_Id
; After
: in out Node_Id
) is
1504 procedure Process_Flist
;
1505 -- If freeze nodes are present, insert and analyze, and reset cursor
1506 -- for next insertion.
1512 procedure Process_Flist
is
1514 if Is_Non_Empty_List
(Flist
) then
1515 Lastn
:= Next
(After
);
1516 Insert_List_After_And_Analyze
(After
, Flist
);
1518 if Present
(Lastn
) then
1519 After
:= Prev
(Lastn
);
1521 After
:= Last
(List_Containing
(After
));
1526 -- Start or processing for Freeze_All_Ent
1530 while Present
(E
) loop
1532 -- If the entity is an inner package which is not a package
1533 -- renaming, then its entities must be frozen at this point. Note
1534 -- that such entities do NOT get frozen at the end of the nested
1535 -- package itself (only library packages freeze).
1537 -- Same is true for task declarations, where anonymous records
1538 -- created for entry parameters must be frozen.
1540 if Ekind
(E
) = E_Package
1541 and then No
(Renamed_Object
(E
))
1542 and then not Is_Child_Unit
(E
)
1543 and then not Is_Frozen
(E
)
1546 Install_Visible_Declarations
(E
);
1547 Install_Private_Declarations
(E
);
1549 Freeze_All
(First_Entity
(E
), After
);
1551 End_Package_Scope
(E
);
1553 if Is_Generic_Instance
(E
)
1554 and then Has_Delayed_Freeze
(E
)
1556 Set_Has_Delayed_Freeze
(E
, False);
1557 Expand_N_Package_Declaration
(Unit_Declaration_Node
(E
));
1560 elsif Ekind
(E
) in Task_Kind
1561 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1562 N_Single_Task_Declaration
)
1565 Freeze_All
(First_Entity
(E
), After
);
1568 -- For a derived tagged type, we must ensure that all the
1569 -- primitive operations of the parent have been frozen, so that
1570 -- their addresses will be in the parent's dispatch table at the
1571 -- point it is inherited.
1573 elsif Ekind
(E
) = E_Record_Type
1574 and then Is_Tagged_Type
(E
)
1575 and then Is_Tagged_Type
(Etype
(E
))
1576 and then Is_Derived_Type
(E
)
1579 Prim_List
: constant Elist_Id
:=
1580 Primitive_Operations
(Etype
(E
));
1586 Prim
:= First_Elmt
(Prim_List
);
1587 while Present
(Prim
) loop
1588 Subp
:= Node
(Prim
);
1590 if Comes_From_Source
(Subp
)
1591 and then not Is_Frozen
(Subp
)
1593 Flist
:= Freeze_Entity
(Subp
, After
);
1602 if not Is_Frozen
(E
) then
1603 Flist
:= Freeze_Entity
(E
, After
);
1606 -- If already frozen, and there are delayed aspects, this is where
1607 -- we do the visibility check for these aspects (see Sem_Ch13 spec
1608 -- for a description of how we handle aspect visibility).
1610 elsif Has_Delayed_Aspects
(E
) then
1612 -- Retrieve the visibility to the discriminants in order to
1613 -- analyze properly the aspects.
1615 Push_Scope_And_Install_Discriminants
(E
);
1621 Ritem
:= First_Rep_Item
(E
);
1622 while Present
(Ritem
) loop
1623 if Nkind
(Ritem
) = N_Aspect_Specification
1624 and then Entity
(Ritem
) = E
1625 and then Is_Delayed_Aspect
(Ritem
)
1627 Check_Aspect_At_End_Of_Declarations
(Ritem
);
1630 Ritem
:= Next_Rep_Item
(Ritem
);
1634 Uninstall_Discriminants_And_Pop_Scope
(E
);
1637 -- If an incomplete type is still not frozen, this may be a
1638 -- premature freezing because of a body declaration that follows.
1639 -- Indicate where the freezing took place. Freezing will happen
1640 -- if the body comes from source, but not if it is internally
1641 -- generated, for example as the body of a type invariant.
1643 -- If the freezing is caused by the end of the current declarative
1644 -- part, it is a Taft Amendment type, and there is no error.
1646 if not Is_Frozen
(E
)
1647 and then Ekind
(E
) = E_Incomplete_Type
1650 Bod
: constant Node_Id
:= Next
(After
);
1653 -- The presence of a body freezes all entities previously
1654 -- declared in the current list of declarations, but this
1655 -- does not apply if the body does not come from source.
1656 -- A type invariant is transformed into a subprogram body
1657 -- which is placed at the end of the private part of the
1658 -- current package, but this body does not freeze incomplete
1659 -- types that may be declared in this private part.
1661 if (Nkind_In
(Bod
, N_Subprogram_Body
,
1666 or else Nkind
(Bod
) in N_Body_Stub
)
1668 List_Containing
(After
) = List_Containing
(Parent
(E
))
1669 and then Comes_From_Source
(Bod
)
1671 Error_Msg_Sloc
:= Sloc
(Next
(After
));
1673 ("type& is frozen# before its full declaration",
1683 -- Start of processing for Freeze_All
1686 Freeze_All_Ent
(From
, After
);
1688 -- Now that all types are frozen, we can deal with default expressions
1689 -- that require us to build a default expression functions. This is the
1690 -- point at which such functions are constructed (after all types that
1691 -- might be used in such expressions have been frozen).
1693 -- For subprograms that are renaming_as_body, we create the wrapper
1694 -- bodies as needed.
1696 -- We also add finalization chains to access types whose designated
1697 -- types are controlled. This is normally done when freezing the type,
1698 -- but this misses recursive type definitions where the later members
1699 -- of the recursion introduce controlled components.
1701 -- Loop through entities
1704 while Present
(E
) loop
1705 if Is_Subprogram
(E
) then
1707 if not Default_Expressions_Processed
(E
) then
1708 Process_Default_Expressions
(E
, After
);
1711 if not Has_Completion
(E
) then
1712 Decl
:= Unit_Declaration_Node
(E
);
1714 if Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
1715 if Error_Posted
(Decl
) then
1716 Set_Has_Completion
(E
);
1718 Build_And_Analyze_Renamed_Body
(Decl
, E
, After
);
1721 elsif Nkind
(Decl
) = N_Subprogram_Declaration
1722 and then Present
(Corresponding_Body
(Decl
))
1724 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
)))
1725 = N_Subprogram_Renaming_Declaration
1727 Build_And_Analyze_Renamed_Body
1728 (Decl
, Corresponding_Body
(Decl
), After
);
1732 elsif Ekind
(E
) in Task_Kind
1733 and then Nkind_In
(Parent
(E
), N_Task_Type_Declaration
,
1734 N_Single_Task_Declaration
)
1740 Ent
:= First_Entity
(E
);
1741 while Present
(Ent
) loop
1743 and then not Default_Expressions_Processed
(Ent
)
1745 Process_Default_Expressions
(Ent
, After
);
1752 -- We add finalization masters to access types whose designated types
1753 -- require finalization. This is normally done when freezing the
1754 -- type, but this misses recursive type definitions where the later
1755 -- members of the recursion introduce controlled components (such as
1756 -- can happen when incomplete types are involved), as well cases
1757 -- where a component type is private and the controlled full type
1758 -- occurs after the access type is frozen. Cases that don't need a
1759 -- finalization master are generic formal types (the actual type will
1760 -- have it) and types derived from them, and types with Java and CIL
1761 -- conventions, since those are used for API bindings.
1762 -- (Are there any other cases that should be excluded here???)
1764 elsif Is_Access_Type
(E
)
1765 and then Comes_From_Source
(E
)
1766 and then not Is_Generic_Type
(Root_Type
(E
))
1767 and then Needs_Finalization
(Designated_Type
(E
))
1769 Build_Finalization_Master
(E
);
1776 -----------------------
1777 -- Freeze_And_Append --
1778 -----------------------
1780 procedure Freeze_And_Append
1783 Result
: in out List_Id
)
1785 L
: constant List_Id
:= Freeze_Entity
(Ent
, N
);
1787 if Is_Non_Empty_List
(L
) then
1788 if Result
= No_List
then
1791 Append_List
(L
, Result
);
1794 end Freeze_And_Append
;
1800 procedure Freeze_Before
(N
: Node_Id
; T
: Entity_Id
) is
1801 Freeze_Nodes
: constant List_Id
:= Freeze_Entity
(T
, N
);
1804 if Ekind
(T
) = E_Function
then
1805 Check_Expression_Function
(N
, T
);
1808 if Is_Non_Empty_List
(Freeze_Nodes
) then
1809 Insert_Actions
(N
, Freeze_Nodes
);
1817 function Freeze_Entity
(E
: Entity_Id
; N
: Node_Id
) return List_Id
is
1818 Loc
: constant Source_Ptr
:= Sloc
(N
);
1819 Test_E
: Entity_Id
:= E
;
1826 Result
: List_Id
:= No_List
;
1827 -- List of freezing actions, left at No_List if none
1829 Has_Default_Initialization
: Boolean := False;
1830 -- This flag gets set to true for a variable with default initialization
1832 procedure Add_To_Result
(N
: Node_Id
);
1833 -- N is a freezing action to be appended to the Result
1835 function After_Last_Declaration
return Boolean;
1836 -- If Loc is a freeze_entity that appears after the last declaration
1837 -- in the scope, inhibit error messages on late completion.
1839 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1840 -- Check that an Access or Unchecked_Access attribute with a prefix
1841 -- which is the current instance type can only be applied when the type
1844 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1845 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1846 -- integer literal without an explicit corresponding size clause. The
1847 -- caller has checked that Utype is a modular integer type.
1849 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
1850 -- Freeze array type, including freezing index and component types
1852 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
1853 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1854 -- package. Recurse on inner generic packages.
1856 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1857 -- Freeze record type, including freezing component types, and freezing
1858 -- primitive operations if this is a tagged type.
1860 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
1861 -- Determine whether an arbitrary entity is subject to Boolean aspect
1862 -- Import and its value is specified as True.
1864 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
1865 -- If E is an entity for an imported subprogram with pre/post-conditions
1866 -- then this procedure will create a wrapper to ensure that proper run-
1867 -- time checking of the pre/postconditions. See body for details.
1873 procedure Add_To_Result
(N
: Node_Id
) is
1876 Result
:= New_List
(N
);
1882 ----------------------------
1883 -- After_Last_Declaration --
1884 ----------------------------
1886 function After_Last_Declaration
return Boolean is
1887 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
1889 if Nkind
(Spec
) = N_Package_Specification
then
1890 if Present
(Private_Declarations
(Spec
)) then
1891 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1892 elsif Present
(Visible_Declarations
(Spec
)) then
1893 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1900 end After_Last_Declaration
;
1902 ----------------------------
1903 -- Check_Current_Instance --
1904 ----------------------------
1906 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1908 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
1909 -- Determine whether Typ is compatible with the rules for aliased
1910 -- views of types as defined in RM 3.10 in the various dialects.
1912 function Process
(N
: Node_Id
) return Traverse_Result
;
1913 -- Process routine to apply check to given node
1915 -----------------------------
1916 -- Is_Aliased_View_Of_Type --
1917 -----------------------------
1919 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
1920 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
1925 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
1926 and then Limited_Present
(Type_Definition
(Typ_Decl
))
1930 -- The following paragraphs describe what a legal aliased view of
1931 -- a type is in the various dialects of Ada.
1935 -- The current instance of a limited type, and a formal parameter
1936 -- or generic formal object of a tagged type.
1938 -- Ada 95 limited type
1939 -- * Type with reserved word "limited"
1940 -- * A protected or task type
1941 -- * A composite type with limited component
1943 elsif Ada_Version
<= Ada_95
then
1944 return Is_Limited_Type
(Typ
);
1948 -- The current instance of a limited tagged type, a protected
1949 -- type, a task type, or a type that has the reserved word
1950 -- "limited" in its full definition ... a formal parameter or
1951 -- generic formal object of a tagged type.
1953 -- Ada 2005 limited type
1954 -- * Type with reserved word "limited", "synchronized", "task"
1956 -- * A composite type with limited component
1957 -- * A derived type whose parent is a non-interface limited type
1959 elsif Ada_Version
= Ada_2005
then
1961 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
1963 (Is_Derived_Type
(Typ
)
1964 and then not Is_Interface
(Etype
(Typ
))
1965 and then Is_Limited_Type
(Etype
(Typ
)));
1967 -- Ada 2012 and beyond
1969 -- The current instance of an immutably limited type ... a formal
1970 -- parameter or generic formal object of a tagged type.
1972 -- Ada 2012 limited type
1973 -- * Type with reserved word "limited", "synchronized", "task"
1975 -- * A composite type with limited component
1976 -- * A derived type whose parent is a non-interface limited type
1977 -- * An incomplete view
1979 -- Ada 2012 immutably limited type
1980 -- * Explicitly limited record type
1981 -- * Record extension with "limited" present
1982 -- * Non-formal limited private type that is either tagged
1983 -- or has at least one access discriminant with a default
1985 -- * Task type, protected type or synchronized interface
1986 -- * Type derived from immutably limited type
1990 Is_Immutably_Limited_Type
(Typ
)
1991 or else Is_Incomplete_Type
(Typ
);
1993 end Is_Aliased_View_Of_Type
;
1999 function Process
(N
: Node_Id
) return Traverse_Result
is
2002 when N_Attribute_Reference
=>
2003 if Nam_In
(Attribute_Name
(N
), Name_Access
,
2004 Name_Unchecked_Access
)
2005 and then Is_Entity_Name
(Prefix
(N
))
2006 and then Is_Type
(Entity
(Prefix
(N
)))
2007 and then Entity
(Prefix
(N
)) = E
2009 if Ada_Version
< Ada_2012
then
2011 ("current instance must be a limited type",
2015 ("current instance must be an immutably limited "
2016 & "type (RM-2012, 7.5 (8.1/3))",
2026 when others => return OK
;
2030 procedure Traverse
is new Traverse_Proc
(Process
);
2034 Rec_Type
: constant Entity_Id
:=
2035 Scope
(Defining_Identifier
(Comp_Decl
));
2037 -- Start of processing for Check_Current_Instance
2040 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2041 Traverse
(Comp_Decl
);
2043 end Check_Current_Instance
;
2045 ------------------------------
2046 -- Check_Suspicious_Modulus --
2047 ------------------------------
2049 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
2050 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
2053 if not Warn_On_Suspicious_Modulus_Value
then
2057 if Nkind
(Decl
) = N_Full_Type_Declaration
then
2059 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
2062 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
2064 Modulus
: constant Node_Id
:=
2065 Original_Node
(Expression
(Tdef
));
2068 if Nkind
(Modulus
) = N_Integer_Literal
then
2070 Modv
: constant Uint
:= Intval
(Modulus
);
2071 Sizv
: constant Uint
:= RM_Size
(Utype
);
2074 -- First case, modulus and size are the same. This
2075 -- happens if you have something like mod 32, with
2076 -- an explicit size of 32, this is for sure a case
2077 -- where the warning is given, since it is seems
2078 -- very unlikely that someone would want e.g. a
2079 -- five bit type stored in 32 bits. It is much
2080 -- more likely they wanted a 32-bit type.
2085 -- Second case, the modulus is 32 or 64 and no
2086 -- size clause is present. This is a less clear
2087 -- case for giving the warning, but in the case
2088 -- of 32/64 (5-bit or 6-bit types) these seem rare
2089 -- enough that it is a likely error (and in any
2090 -- case using 2**5 or 2**6 in these cases seems
2091 -- clearer. We don't include 8 or 16 here, simply
2092 -- because in practice 3-bit and 4-bit types are
2093 -- more common and too many false positives if
2094 -- we warn in these cases.
2096 elsif not Has_Size_Clause
(Utype
)
2097 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
2101 -- No warning needed
2107 -- If we fall through, give warning
2109 Error_Msg_Uint_1
:= Modv
;
2111 ("?M?2 '*'*^' may have been intended here",
2119 end Check_Suspicious_Modulus
;
2121 -----------------------
2122 -- Freeze_Array_Type --
2123 -----------------------
2125 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2126 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2127 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2130 Non_Standard_Enum
: Boolean := False;
2131 -- Set true if any of the index types is an enumeration type with a
2132 -- non-standard representation.
2135 Freeze_And_Append
(Ctyp
, N
, Result
);
2137 Indx
:= First_Index
(Arr
);
2138 while Present
(Indx
) loop
2139 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2141 if Is_Enumeration_Type
(Etype
(Indx
))
2142 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2144 Non_Standard_Enum
:= True;
2150 -- Processing that is done only for base types
2152 if Ekind
(Arr
) = E_Array_Type
then
2154 -- Deal with default setting of reverse storage order
2156 Set_SSO_From_Default
(Arr
);
2158 -- Propagate flags for component type
2160 if Is_Controlled
(Component_Type
(Arr
))
2161 or else Has_Controlled_Component
(Ctyp
)
2163 Set_Has_Controlled_Component
(Arr
);
2166 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2167 Set_Has_Unchecked_Union
(Arr
);
2170 -- Warn for pragma Pack overriding foreign convention
2172 if Has_Foreign_Convention
(Ctyp
)
2173 and then Has_Pragma_Pack
(Arr
)
2176 CN
: constant Name_Id
:=
2177 Get_Convention_Name
(Convention
(Ctyp
));
2178 PP
: constant Node_Id
:=
2179 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2181 if Present
(PP
) then
2182 Error_Msg_Name_1
:= CN
;
2183 Error_Msg_Sloc
:= Sloc
(Arr
);
2185 ("pragma Pack affects convention % components #??",
2187 Error_Msg_Name_1
:= CN
;
2189 ("\array components may not have % compatible "
2190 & "representation??", PP
);
2195 -- If packing was requested or if the component size was
2196 -- set explicitly, then see if bit packing is required. This
2197 -- processing is only done for base types, since all of the
2198 -- representation aspects involved are type-related.
2200 -- This is not just an optimization, if we start processing the
2201 -- subtypes, they interfere with the settings on the base type
2202 -- (this is because Is_Packed has a slightly different meaning
2203 -- before and after freezing).
2210 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2211 and then Known_Static_RM_Size
(Ctyp
)
2212 and then not Has_Component_Size_Clause
(Arr
)
2214 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2216 elsif Known_Component_Size
(Arr
) then
2217 Csiz
:= Component_Size
(Arr
);
2219 elsif not Known_Static_Esize
(Ctyp
) then
2223 Esiz
:= Esize
(Ctyp
);
2225 -- We can set the component size if it is less than 16,
2226 -- rounding it up to the next storage unit size.
2230 elsif Esiz
<= 16 then
2236 -- Set component size up to match alignment if it would
2237 -- otherwise be less than the alignment. This deals with
2238 -- cases of types whose alignment exceeds their size (the
2239 -- padded type cases).
2243 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2252 -- Case of component size that may result in packing
2254 if 1 <= Csiz
and then Csiz
<= 64 then
2256 Ent
: constant Entity_Id
:=
2257 First_Subtype
(Arr
);
2258 Pack_Pragma
: constant Node_Id
:=
2259 Get_Rep_Pragma
(Ent
, Name_Pack
);
2260 Comp_Size_C
: constant Node_Id
:=
2261 Get_Attribute_Definition_Clause
2262 (Ent
, Attribute_Component_Size
);
2264 -- Warn if we have pack and component size so that the
2267 -- Note: here we must check for the presence of a
2268 -- component size before checking for a Pack pragma to
2269 -- deal with the case where the array type is a derived
2270 -- type whose parent is currently private.
2272 if Present
(Comp_Size_C
)
2273 and then Has_Pragma_Pack
(Ent
)
2274 and then Warn_On_Redundant_Constructs
2276 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2278 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2280 ("\?r?explicit component size given#!", Pack_Pragma
);
2281 Set_Is_Packed
(Base_Type
(Ent
), False);
2282 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2285 -- Set component size if not already set by a component
2288 if not Present
(Comp_Size_C
) then
2289 Set_Component_Size
(Arr
, Csiz
);
2292 -- Check for base type of 8, 16, 32 bits, where an
2293 -- unsigned subtype has a length one less than the
2294 -- base type (e.g. Natural subtype of Integer).
2296 -- In such cases, if a component size was not set
2297 -- explicitly, then generate a warning.
2299 if Has_Pragma_Pack
(Arr
)
2300 and then not Present
(Comp_Size_C
)
2301 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2302 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2304 Error_Msg_Uint_1
:= Csiz
;
2306 if Present
(Pack_Pragma
) then
2308 ("??pragma Pack causes component size "
2309 & "to be ^!", Pack_Pragma
);
2311 ("\??use Component_Size to set "
2312 & "desired value!", Pack_Pragma
);
2316 -- Actual packing is not needed for 8, 16, 32, 64. Also
2317 -- not needed for 24 if alignment is 1.
2323 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
2325 -- Here the array was requested to be packed, but
2326 -- the packing request had no effect, so Is_Packed
2329 -- Note: semantically this means that we lose track
2330 -- of the fact that a derived type inherited a pragma
2331 -- Pack that was non- effective, but that seems fine.
2333 -- We regard a Pack pragma as a request to set a
2334 -- representation characteristic, and this request
2337 Set_Is_Packed
(Base_Type
(Arr
), False);
2338 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2340 if Known_Static_Esize
(Component_Type
(Arr
))
2341 and then Esize
(Component_Type
(Arr
)) = Csiz
2343 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
2346 -- In all other cases, packing is indeed needed
2349 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2350 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2351 Set_Is_Packed
(Base_Type
(Arr
), True);
2357 -- Check for Atomic_Components or Aliased with unsuitable packing
2358 -- or explicit component size clause given.
2360 if (Has_Atomic_Components
(Arr
)
2362 Has_Aliased_Components
(Arr
))
2364 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2366 Alias_Atomic_Check
: declare
2368 procedure Complain_CS
(T
: String);
2369 -- Outputs error messages for incorrect CS clause or pragma
2370 -- Pack for aliased or atomic components (T is "aliased" or
2377 procedure Complain_CS
(T
: String) is
2379 if Has_Component_Size_Clause
(Arr
) then
2381 Get_Attribute_Definition_Clause
2382 (FS
, Attribute_Component_Size
);
2384 if Known_Static_Esize
(Ctyp
) then
2386 ("incorrect component size for "
2387 & T
& " components", Clause
);
2388 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2390 ("\only allowed value is^", Clause
);
2394 ("component size cannot be given for "
2395 & T
& " components", Clause
);
2400 ("cannot pack " & T
& " components",
2401 Get_Rep_Pragma
(FS
, Name_Pack
));
2407 -- Start of processing for Alias_Atomic_Check
2410 -- If object size of component type isn't known, we cannot
2411 -- be sure so we defer to the back end.
2413 if not Known_Static_Esize
(Ctyp
) then
2416 -- Case where component size has no effect. First check for
2417 -- object size of component type multiple of the storage
2420 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2422 -- OK in both packing case and component size case if RM
2423 -- size is known and static and same as the object size.
2426 ((Known_Static_RM_Size
(Ctyp
)
2427 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2429 -- Or if we have an explicit component size clause and
2430 -- the component size and object size are equal.
2433 (Has_Component_Size_Clause
(Arr
)
2434 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2438 elsif Has_Aliased_Components
(Arr
)
2439 or else Is_Aliased
(Ctyp
)
2441 Complain_CS
("aliased");
2443 elsif Has_Atomic_Components
(Arr
)
2444 or else Is_Atomic
(Ctyp
)
2446 Complain_CS
("atomic");
2448 end Alias_Atomic_Check
;
2451 -- Warn for case of atomic type
2453 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2456 and then not Addressable
(Component_Size
(FS
))
2459 ("non-atomic components of type& may not be "
2460 & "accessible by separate tasks??", Clause
, Arr
);
2462 if Has_Component_Size_Clause
(Arr
) then
2463 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2464 (FS
, Attribute_Component_Size
));
2465 Error_Msg_N
("\because of component size clause#??", Clause
);
2467 elsif Has_Pragma_Pack
(Arr
) then
2468 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2469 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2473 -- Check for scalar storage order
2478 Check_Component_Storage_Order
2481 ADC
=> Get_Attribute_Definition_Clause
2482 (First_Subtype
(Arr
),
2483 Attribute_Scalar_Storage_Order
),
2484 Comp_ADC_Present
=> Dummy
);
2487 -- Processing that is done only for subtypes
2490 -- Acquire alignment from base type
2492 if Unknown_Alignment
(Arr
) then
2493 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2494 Adjust_Esize_Alignment
(Arr
);
2498 -- Specific checks for bit-packed arrays
2500 if Is_Bit_Packed_Array
(Arr
) then
2502 -- Check number of elements for bit packed arrays that come from
2503 -- source and have compile time known ranges. The bit-packed
2504 -- arrays circuitry does not support arrays with more than
2505 -- Integer'Last + 1 elements, and when this restriction is
2506 -- violated, causes incorrect data access.
2508 -- For the case where this is not compile time known, a run-time
2509 -- check should be generated???
2511 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
2520 Index
:= First_Index
(Arr
);
2521 while Present
(Index
) loop
2522 Ityp
:= Etype
(Index
);
2524 -- Never generate an error if any index is of a generic
2525 -- type. We will check this in instances.
2527 if Is_Generic_Type
(Ityp
) then
2533 Make_Attribute_Reference
(Loc
,
2535 New_Occurrence_Of
(Ityp
, Loc
),
2536 Attribute_Name
=> Name_Range_Length
);
2537 Analyze_And_Resolve
(Ilen
);
2539 -- No attempt is made to check number of elements
2540 -- if not compile time known.
2542 if Nkind
(Ilen
) /= N_Integer_Literal
then
2547 Elmts
:= Elmts
* Intval
(Ilen
);
2551 if Elmts
> Intval
(High_Bound
2552 (Scalar_Range
(Standard_Integer
))) + 1
2555 ("bit packed array type may not have "
2556 & "more than Integer''Last+1 elements", Arr
);
2563 if Known_RM_Size
(Arr
) then
2565 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
2568 pragma Warnings
(Off
, Discard
);
2571 -- It is not clear if it is possible to have no size clause
2572 -- at this stage, but it is not worth worrying about. Post
2573 -- error on the entity name in the size clause if present,
2574 -- else on the type entity itself.
2576 if Present
(SizC
) then
2577 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
2579 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
2585 -- If any of the index types was an enumeration type with a
2586 -- non-standard rep clause, then we indicate that the array type
2587 -- is always packed (even if it is not bit packed).
2589 if Non_Standard_Enum
then
2590 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
2591 Set_Is_Packed
(Base_Type
(Arr
));
2594 Set_Component_Alignment_If_Not_Set
(Arr
);
2596 -- If the array is packed, we must create the packed array type to be
2597 -- used to actually implement the type. This is only needed for real
2598 -- array types (not for string literal types, since they are present
2599 -- only for the front end).
2602 and then Ekind
(Arr
) /= E_String_Literal_Subtype
2604 Create_Packed_Array_Impl_Type
(Arr
);
2605 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
2607 -- Size information of packed array type is copied to the array
2608 -- type, since this is really the representation. But do not
2609 -- override explicit existing size values. If the ancestor subtype
2610 -- is constrained the Packed_Array_Impl_Type will be inherited
2611 -- from it, but the size may have been provided already, and
2612 -- must not be overridden either.
2614 if not Has_Size_Clause
(Arr
)
2616 (No
(Ancestor_Subtype
(Arr
))
2617 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
2619 Set_Esize
(Arr
, Esize
(Packed_Array_Impl_Type
(Arr
)));
2620 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Impl_Type
(Arr
)));
2623 if not Has_Alignment_Clause
(Arr
) then
2624 Set_Alignment
(Arr
, Alignment
(Packed_Array_Impl_Type
(Arr
)));
2628 -- For non-packed arrays set the alignment of the array to the
2629 -- alignment of the component type if it is unknown. Skip this
2630 -- in atomic case (atomic arrays may need larger alignments).
2632 if not Is_Packed
(Arr
)
2633 and then Unknown_Alignment
(Arr
)
2634 and then Known_Alignment
(Ctyp
)
2635 and then Known_Static_Component_Size
(Arr
)
2636 and then Known_Static_Esize
(Ctyp
)
2637 and then Esize
(Ctyp
) = Component_Size
(Arr
)
2638 and then not Is_Atomic
(Arr
)
2640 Set_Alignment
(Arr
, Alignment
(Component_Type
(Arr
)));
2642 end Freeze_Array_Type
;
2644 -----------------------------
2645 -- Freeze_Generic_Entities --
2646 -----------------------------
2648 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
2655 E
:= First_Entity
(Pack
);
2656 while Present
(E
) loop
2657 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
2658 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
2660 Append_To
(Flist
, F
);
2662 elsif Ekind
(E
) = E_Generic_Package
then
2663 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
2670 end Freeze_Generic_Entities
;
2672 ------------------------
2673 -- Freeze_Record_Type --
2674 ------------------------
2676 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
2683 pragma Warnings
(Off
, Junk
);
2685 Rec_Pushed
: Boolean := False;
2686 -- Set True if the record type scope Rec has been pushed on the scope
2687 -- stack. Needed for the analysis of delayed aspects specified to the
2688 -- components of Rec.
2691 -- Scalar_Storage_Order attribute definition clause for the record
2693 Unplaced_Component
: Boolean := False;
2694 -- Set True if we find at least one component with no component
2695 -- clause (used to warn about useless Pack pragmas).
2697 Placed_Component
: Boolean := False;
2698 -- Set True if we find at least one component with a component
2699 -- clause (used to warn about useless Bit_Order pragmas, and also
2700 -- to detect cases where Implicit_Packing may have an effect).
2702 Aliased_Component
: Boolean := False;
2703 -- Set True if we find at least one component which is aliased. This
2704 -- is used to prevent Implicit_Packing of the record, since packing
2705 -- cannot modify the size of alignment of an aliased component.
2707 SSO_ADC_Component
: Boolean := False;
2708 -- Set True if we find at least one component whose type has a
2709 -- Scalar_Storage_Order attribute definition clause.
2711 All_Scalar_Components
: Boolean := True;
2712 -- Set False if we encounter a component of a non-scalar type
2714 Scalar_Component_Total_RM_Size
: Uint
:= Uint_0
;
2715 Scalar_Component_Total_Esize
: Uint
:= Uint_0
;
2716 -- Accumulates total RM_Size values and total Esize values of all
2717 -- scalar components. Used for processing of Implicit_Packing.
2719 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
2720 -- If N is an allocator, possibly wrapped in one or more level of
2721 -- qualified expression(s), return the inner allocator node, else
2724 procedure Check_Itype
(Typ
: Entity_Id
);
2725 -- If the component subtype is an access to a constrained subtype of
2726 -- an already frozen type, make the subtype frozen as well. It might
2727 -- otherwise be frozen in the wrong scope, and a freeze node on
2728 -- subtype has no effect. Similarly, if the component subtype is a
2729 -- regular (not protected) access to subprogram, set the anonymous
2730 -- subprogram type to frozen as well, to prevent an out-of-scope
2731 -- freeze node at some eventual point of call. Protected operations
2732 -- are handled elsewhere.
2734 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
2735 -- Make sure that all types mentioned in Discrete_Choices of the
2736 -- variants referenceed by the Variant_Part VP are frozen. This is
2737 -- a recursive routine to deal with nested variants.
2739 ---------------------
2740 -- Check_Allocator --
2741 ---------------------
2743 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
2748 if Nkind
(Inner
) = N_Allocator
then
2750 elsif Nkind
(Inner
) = N_Qualified_Expression
then
2751 Inner
:= Expression
(Inner
);
2756 end Check_Allocator
;
2762 procedure Check_Itype
(Typ
: Entity_Id
) is
2763 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
2766 if not Is_Frozen
(Desig
)
2767 and then Is_Frozen
(Base_Type
(Desig
))
2769 Set_Is_Frozen
(Desig
);
2771 -- In addition, add an Itype_Reference to ensure that the
2772 -- access subtype is elaborated early enough. This cannot be
2773 -- done if the subtype may depend on discriminants.
2775 if Ekind
(Comp
) = E_Component
2776 and then Is_Itype
(Etype
(Comp
))
2777 and then not Has_Discriminants
(Rec
)
2779 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
2780 Set_Itype
(IR
, Desig
);
2784 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
2785 and then Convention
(Desig
) /= Convention_Protected
2787 Set_Is_Frozen
(Desig
);
2791 ------------------------------------
2792 -- Freeze_Choices_In_Variant_Part --
2793 ------------------------------------
2795 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
2796 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
2803 -- Loop through variants
2805 Variant
:= First_Non_Pragma
(Variants
(VP
));
2806 while Present
(Variant
) loop
2808 -- Loop through choices, checking that all types are frozen
2810 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
2811 while Present
(Choice
) loop
2812 if Nkind
(Choice
) in N_Has_Etype
2813 and then Present
(Etype
(Choice
))
2815 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
2818 Next_Non_Pragma
(Choice
);
2821 -- Check for nested variant part to process
2823 CL
:= Component_List
(Variant
);
2825 if not Null_Present
(CL
) then
2826 if Present
(Variant_Part
(CL
)) then
2827 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
2831 Next_Non_Pragma
(Variant
);
2833 end Freeze_Choices_In_Variant_Part
;
2835 -- Start of processing for Freeze_Record_Type
2838 -- Deal with delayed aspect specifications for components. The
2839 -- analysis of the aspect is required to be delayed to the freeze
2840 -- point, thus we analyze the pragma or attribute definition
2841 -- clause in the tree at this point. We also analyze the aspect
2842 -- specification node at the freeze point when the aspect doesn't
2843 -- correspond to pragma/attribute definition clause.
2845 Comp
:= First_Entity
(Rec
);
2846 while Present
(Comp
) loop
2847 if Ekind
(Comp
) = E_Component
2848 and then Has_Delayed_Aspects
(Comp
)
2850 if not Rec_Pushed
then
2854 -- The visibility to the discriminants must be restored in
2855 -- order to properly analyze the aspects.
2857 if Has_Discriminants
(Rec
) then
2858 Install_Discriminants
(Rec
);
2862 Analyze_Aspects_At_Freeze_Point
(Comp
);
2868 -- Pop the scope if Rec scope has been pushed on the scope stack
2869 -- during the delayed aspect analysis process.
2872 if Has_Discriminants
(Rec
) then
2873 Uninstall_Discriminants
(Rec
);
2879 -- Freeze components and embedded subtypes
2881 Comp
:= First_Entity
(Rec
);
2883 while Present
(Comp
) loop
2884 if Is_Aliased
(Comp
) then
2885 Aliased_Component
:= True;
2888 -- Handle the component and discriminant case
2890 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
2892 CC
: constant Node_Id
:= Component_Clause
(Comp
);
2895 -- Freezing a record type freezes the type of each of its
2896 -- components. However, if the type of the component is
2897 -- part of this record, we do not want or need a separate
2898 -- Freeze_Node. Note that Is_Itype is wrong because that's
2899 -- also set in private type cases. We also can't check for
2900 -- the Scope being exactly Rec because of private types and
2901 -- record extensions.
2903 if Is_Itype
(Etype
(Comp
))
2904 and then Is_Record_Type
(Underlying_Type
2905 (Scope
(Etype
(Comp
))))
2907 Undelay_Type
(Etype
(Comp
));
2910 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
2912 -- Warn for pragma Pack overriding foreign convention
2914 if Has_Foreign_Convention
(Etype
(Comp
))
2915 and then Has_Pragma_Pack
(Rec
)
2917 -- Don't warn for aliased components, since override
2918 -- cannot happen in that case.
2920 and then not Is_Aliased
(Comp
)
2923 CN
: constant Name_Id
:=
2924 Get_Convention_Name
(Convention
(Etype
(Comp
)));
2925 PP
: constant Node_Id
:=
2926 Get_Pragma
(Rec
, Pragma_Pack
);
2928 if Present
(PP
) then
2929 Error_Msg_Name_1
:= CN
;
2930 Error_Msg_Sloc
:= Sloc
(Comp
);
2932 ("pragma Pack affects convention % component#??",
2934 Error_Msg_Name_1
:= CN
;
2936 ("\component & may not have % compatible "
2937 & "representation??", PP
, Comp
);
2942 -- Check for error of component clause given for variable
2943 -- sized type. We have to delay this test till this point,
2944 -- since the component type has to be frozen for us to know
2945 -- if it is variable length.
2947 if Present
(CC
) then
2948 Placed_Component
:= True;
2950 -- We omit this test in a generic context, it will be
2951 -- applied at instantiation time.
2953 if Inside_A_Generic
then
2956 -- Also omit this test in CodePeer mode, since we do not
2957 -- have sufficient info on size and rep clauses.
2959 elsif CodePeer_Mode
then
2965 Size_Known_At_Compile_Time
2966 (Underlying_Type
(Etype
(Comp
)))
2969 ("component clause not allowed for variable " &
2970 "length component", CC
);
2974 Unplaced_Component
:= True;
2977 -- Case of component requires byte alignment
2979 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
2981 -- Set the enclosing record to also require byte align
2983 Set_Must_Be_On_Byte_Boundary
(Rec
);
2985 -- Check for component clause that is inconsistent with
2986 -- the required byte boundary alignment.
2989 and then Normalized_First_Bit
(Comp
) mod
2990 System_Storage_Unit
/= 0
2993 ("component & must be byte aligned",
2994 Component_Name
(Component_Clause
(Comp
)));
3000 -- Gather data for possible Implicit_Packing later. Note that at
3001 -- this stage we might be dealing with a real component, or with
3002 -- an implicit subtype declaration.
3004 if not Is_Scalar_Type
(Etype
(Comp
)) then
3005 All_Scalar_Components
:= False;
3007 Scalar_Component_Total_RM_Size
:=
3008 Scalar_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
3009 Scalar_Component_Total_Esize
:=
3010 Scalar_Component_Total_Esize
+ Esize
(Etype
(Comp
));
3013 -- If the component is an Itype with Delayed_Freeze and is either
3014 -- a record or array subtype and its base type has not yet been
3015 -- frozen, we must remove this from the entity list of this record
3016 -- and put it on the entity list of the scope of its base type.
3017 -- Note that we know that this is not the type of a component
3018 -- since we cleared Has_Delayed_Freeze for it in the previous
3019 -- loop. Thus this must be the Designated_Type of an access type,
3020 -- which is the type of a component.
3023 and then Is_Type
(Scope
(Comp
))
3024 and then Is_Composite_Type
(Comp
)
3025 and then Base_Type
(Comp
) /= Comp
3026 and then Has_Delayed_Freeze
(Comp
)
3027 and then not Is_Frozen
(Base_Type
(Comp
))
3030 Will_Be_Frozen
: Boolean := False;
3034 -- We have a difficult case to handle here. Suppose Rec is
3035 -- subtype being defined in a subprogram that's created as
3036 -- part of the freezing of Rec'Base. In that case, we know
3037 -- that Comp'Base must have already been frozen by the time
3038 -- we get to elaborate this because Gigi doesn't elaborate
3039 -- any bodies until it has elaborated all of the declarative
3040 -- part. But Is_Frozen will not be set at this point because
3041 -- we are processing code in lexical order.
3043 -- We detect this case by going up the Scope chain of Rec
3044 -- and seeing if we have a subprogram scope before reaching
3045 -- the top of the scope chain or that of Comp'Base. If we
3046 -- do, then mark that Comp'Base will actually be frozen. If
3047 -- so, we merely undelay it.
3050 while Present
(S
) loop
3051 if Is_Subprogram
(S
) then
3052 Will_Be_Frozen
:= True;
3054 elsif S
= Scope
(Base_Type
(Comp
)) then
3061 if Will_Be_Frozen
then
3062 Undelay_Type
(Comp
);
3064 if Present
(Prev
) then
3065 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
3067 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
3070 -- Insert in entity list of scope of base type (which
3071 -- must be an enclosing scope, because still unfrozen).
3073 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
3077 -- If the component is an access type with an allocator as default
3078 -- value, the designated type will be frozen by the corresponding
3079 -- expression in init_proc. In order to place the freeze node for
3080 -- the designated type before that for the current record type,
3083 -- Same process if the component is an array of access types,
3084 -- initialized with an aggregate. If the designated type is
3085 -- private, it cannot contain allocators, and it is premature
3086 -- to freeze the type, so we check for this as well.
3088 elsif Is_Access_Type
(Etype
(Comp
))
3089 and then Present
(Parent
(Comp
))
3090 and then Present
(Expression
(Parent
(Comp
)))
3093 Alloc
: constant Node_Id
:=
3094 Check_Allocator
(Expression
(Parent
(Comp
)));
3097 if Present
(Alloc
) then
3099 -- If component is pointer to a class-wide type, freeze
3100 -- the specific type in the expression being allocated.
3101 -- The expression may be a subtype indication, in which
3102 -- case freeze the subtype mark.
3104 if Is_Class_Wide_Type
3105 (Designated_Type
(Etype
(Comp
)))
3107 if Is_Entity_Name
(Expression
(Alloc
)) then
3109 (Entity
(Expression
(Alloc
)), N
, Result
);
3111 Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
3114 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
3118 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
3119 Check_Itype
(Etype
(Comp
));
3123 (Designated_Type
(Etype
(Comp
)), N
, Result
);
3128 elsif Is_Access_Type
(Etype
(Comp
))
3129 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
3131 Check_Itype
(Etype
(Comp
));
3133 -- Freeze the designated type when initializing a component with
3134 -- an aggregate in case the aggregate contains allocators.
3137 -- type T_Ptr is access all T;
3138 -- type T_Array is array ... of T_Ptr;
3140 -- type Rec is record
3141 -- Comp : T_Array := (others => ...);
3144 elsif Is_Array_Type
(Etype
(Comp
))
3145 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
3148 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
3149 Desig_Typ
: constant Entity_Id
:=
3151 (Component_Type
(Etype
(Comp
)));
3154 -- The only case when this sort of freezing is not done is
3155 -- when the designated type is class-wide and the root type
3156 -- is the record owning the component. This scenario results
3157 -- in a circularity because the class-wide type requires
3158 -- primitives that have not been created yet as the root
3159 -- type is in the process of being frozen.
3161 -- type Rec is tagged;
3162 -- type Rec_Ptr is access all Rec'Class;
3163 -- type Rec_Array is array ... of Rec_Ptr;
3165 -- type Rec is record
3166 -- Comp : Rec_Array := (others => ...);
3169 if Is_Class_Wide_Type
(Desig_Typ
)
3170 and then Root_Type
(Desig_Typ
) = Rec
3174 elsif Is_Fully_Defined
(Desig_Typ
)
3175 and then Present
(Comp_Par
)
3176 and then Nkind
(Comp_Par
) = N_Component_Declaration
3177 and then Present
(Expression
(Comp_Par
))
3178 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
3180 Freeze_And_Append
(Desig_Typ
, N
, Result
);
3189 SSO_ADC
:= Get_Attribute_Definition_Clause
3190 (Rec
, Attribute_Scalar_Storage_Order
);
3192 -- Check consistent attribute setting on component types
3195 Comp_ADC_Present
: Boolean;
3197 Comp
:= First_Component
(Rec
);
3198 while Present
(Comp
) loop
3199 Check_Component_Storage_Order
3203 Comp_ADC_Present
=> Comp_ADC_Present
);
3204 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
3205 Next_Component
(Comp
);
3209 -- Deal with default setting of reverse storage order
3211 Set_SSO_From_Default
(Rec
);
3213 -- Now deal with reverse storage order/bit order issues
3215 if Present
(SSO_ADC
) then
3217 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
3218 -- the former is specified.
3220 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
3222 -- Note: report error on Rec, not on SSO_ADC, as ADC may apply
3223 -- to some ancestor type.
3225 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
3227 ("scalar storage order for& specified# inconsistent with "
3228 & "bit order", Rec
);
3231 -- Warn if there is an Scalar_Storage_Order attribute definition
3232 -- clause but no component clause, no component that itself has
3233 -- such an attribute definition, and no pragma Pack.
3235 if not (Placed_Component
3242 ("??scalar storage order specified but no component clause",
3247 -- Deal with Bit_Order aspect
3249 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
3251 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
3252 if not (Placed_Component
3253 or else Present
(SSO_ADC
)
3254 or else Is_Packed
(Rec
))
3256 -- Warn if clause has no effect when no component clause is
3257 -- present, but suppress warning if the Bit_Order is required
3258 -- due to the presence of a Scalar_Storage_Order attribute.
3261 ("??bit order specification has no effect", ADC
);
3263 ("\??since no component clauses were specified", ADC
);
3265 -- Here is where we do the processing to adjust component clauses
3266 -- for reversed bit order.
3268 elsif Reverse_Bit_Order
(Rec
)
3269 and then not Reverse_Storage_Order
(Rec
)
3271 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
3273 -- Case where we have both an explicit Bit_Order and the same
3274 -- Scalar_Storage_Order: leave record untouched, the back-end
3275 -- will take care of required layout conversions.
3283 -- Complete error checking on record representation clause (e.g.
3284 -- overlap of components). This is called after adjusting the
3285 -- record for reverse bit order.
3288 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
3290 if Present
(RRC
) then
3291 Check_Record_Representation_Clause
(RRC
);
3295 -- Set OK_To_Reorder_Components depending on debug flags
3297 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
3298 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
3300 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
3302 Set_OK_To_Reorder_Components
(Rec
);
3306 -- Check for useless pragma Pack when all components placed. We only
3307 -- do this check for record types, not subtypes, since a subtype may
3308 -- have all its components placed, and it still makes perfectly good
3309 -- sense to pack other subtypes or the parent type. We do not give
3310 -- this warning if Optimize_Alignment is set to Space, since the
3311 -- pragma Pack does have an effect in this case (it always resets
3312 -- the alignment to one).
3314 if Ekind
(Rec
) = E_Record_Type
3315 and then Is_Packed
(Rec
)
3316 and then not Unplaced_Component
3317 and then Optimize_Alignment
/= 'S'
3319 -- Reset packed status. Probably not necessary, but we do it so
3320 -- that there is no chance of the back end doing something strange
3321 -- with this redundant indication of packing.
3323 Set_Is_Packed
(Rec
, False);
3325 -- Give warning if redundant constructs warnings on
3327 if Warn_On_Redundant_Constructs
then
3328 Error_Msg_N
-- CODEFIX
3329 ("??pragma Pack has no effect, no unplaced components",
3330 Get_Rep_Pragma
(Rec
, Name_Pack
));
3334 -- If this is the record corresponding to a remote type, freeze the
3335 -- remote type here since that is what we are semantically freezing.
3336 -- This prevents the freeze node for that type in an inner scope.
3338 if Ekind
(Rec
) = E_Record_Type
then
3339 if Present
(Corresponding_Remote_Type
(Rec
)) then
3340 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
3343 -- Check for controlled components and unchecked unions.
3345 Comp
:= First_Component
(Rec
);
3346 while Present
(Comp
) loop
3348 -- Do not set Has_Controlled_Component on a class-wide
3349 -- equivalent type. See Make_CW_Equivalent_Type.
3351 if not Is_Class_Wide_Equivalent_Type
(Rec
)
3353 (Has_Controlled_Component
(Etype
(Comp
))
3355 (Chars
(Comp
) /= Name_uParent
3356 and then Is_Controlled
(Etype
(Comp
)))
3358 (Is_Protected_Type
(Etype
(Comp
))
3360 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
3362 Has_Controlled_Component
3363 (Corresponding_Record_Type
(Etype
(Comp
)))))
3365 Set_Has_Controlled_Component
(Rec
);
3368 if Has_Unchecked_Union
(Etype
(Comp
)) then
3369 Set_Has_Unchecked_Union
(Rec
);
3372 -- Scan component declaration for likely misuses of current
3373 -- instance, either in a constraint or a default expression.
3375 if Has_Per_Object_Constraint
(Comp
) then
3376 Check_Current_Instance
(Parent
(Comp
));
3379 Next_Component
(Comp
);
3383 -- Enforce the restriction that access attributes with a current
3384 -- instance prefix can only apply to limited types. This comment
3385 -- is floating here, but does not seem to belong here???
3387 -- Set component alignment if not otherwise already set
3389 Set_Component_Alignment_If_Not_Set
(Rec
);
3391 -- For first subtypes, check if there are any fixed-point fields with
3392 -- component clauses, where we must check the size. This is not done
3393 -- till the freeze point since for fixed-point types, we do not know
3394 -- the size until the type is frozen. Similar processing applies to
3395 -- bit packed arrays.
3397 if Is_First_Subtype
(Rec
) then
3398 Comp
:= First_Component
(Rec
);
3399 while Present
(Comp
) loop
3400 if Present
(Component_Clause
(Comp
))
3401 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
3402 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
3405 (Component_Name
(Component_Clause
(Comp
)),
3411 Next_Component
(Comp
);
3415 -- Generate warning for applying C or C++ convention to a record
3416 -- with discriminants. This is suppressed for the unchecked union
3417 -- case, since the whole point in this case is interface C. We also
3418 -- do not generate this within instantiations, since we will have
3419 -- generated a message on the template.
3421 if Has_Discriminants
(E
)
3422 and then not Is_Unchecked_Union
(E
)
3423 and then (Convention
(E
) = Convention_C
3425 Convention
(E
) = Convention_CPP
)
3426 and then Comes_From_Source
(E
)
3427 and then not In_Instance
3428 and then not Has_Warnings_Off
(E
)
3429 and then not Has_Warnings_Off
(Base_Type
(E
))
3432 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
3436 if Present
(Cprag
) then
3437 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3439 if Convention
(E
) = Convention_C
then
3441 ("?x?variant record has no direct equivalent in C",
3445 ("?x?variant record has no direct equivalent in C++",
3450 ("\?x?use of convention for type& is dubious", A2
, E
);
3455 -- See if Size is too small as is (and implicit packing might help)
3457 if not Is_Packed
(Rec
)
3459 -- No implicit packing if even one component is explicitly placed
3461 and then not Placed_Component
3463 -- Or even one component is aliased
3465 and then not Aliased_Component
3467 -- Must have size clause and all scalar components
3469 and then Has_Size_Clause
(Rec
)
3470 and then All_Scalar_Components
3472 -- Do not try implicit packing on records with discriminants, too
3473 -- complicated, especially in the variant record case.
3475 and then not Has_Discriminants
(Rec
)
3477 -- We can implicitly pack if the specified size of the record is
3478 -- less than the sum of the object sizes (no point in packing if
3479 -- this is not the case).
3481 and then RM_Size
(Rec
) < Scalar_Component_Total_Esize
3483 -- And the total RM size cannot be greater than the specified size
3484 -- since otherwise packing will not get us where we have to be.
3486 and then RM_Size
(Rec
) >= Scalar_Component_Total_RM_Size
3488 -- Never do implicit packing in CodePeer or SPARK modes since
3489 -- we don't do any packing in these modes, since this generates
3490 -- over-complex code that confuses static analysis, and in
3491 -- general, neither CodePeer not GNATprove care about the
3492 -- internal representation of objects.
3494 and then not (CodePeer_Mode
or GNATprove_Mode
)
3496 -- If implicit packing enabled, do it
3498 if Implicit_Packing
then
3499 Set_Is_Packed
(Rec
);
3501 -- Otherwise flag the size clause
3505 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
3507 Error_Msg_NE
-- CODEFIX
3508 ("size given for& too small", Sz
, Rec
);
3509 Error_Msg_N
-- CODEFIX
3510 ("\use explicit pragma Pack "
3511 & "or use pragma Implicit_Packing", Sz
);
3516 -- The following checks are only relevant when SPARK_Mode is on as
3517 -- they are not standard Ada legality rules.
3519 if SPARK_Mode
= On
then
3520 if Is_Effectively_Volatile
(Rec
) then
3522 -- A discriminated type cannot be effectively volatile
3523 -- (SPARK RM C.6(4)).
3525 if Has_Discriminants
(Rec
) then
3526 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
3528 -- A tagged type cannot be effectively volatile
3529 -- (SPARK RM C.6(5)).
3531 elsif Is_Tagged_Type
(Rec
) then
3532 Error_Msg_N
("tagged type & cannot be volatile", Rec
);
3535 -- A non-effectively volatile record type cannot contain
3536 -- effectively volatile components (SPARK RM C.6(2)).
3539 Comp
:= First_Component
(Rec
);
3540 while Present
(Comp
) loop
3541 if Comes_From_Source
(Comp
)
3542 and then Is_Effectively_Volatile
(Etype
(Comp
))
3544 Error_Msg_Name_1
:= Chars
(Rec
);
3546 ("component & of non-volatile type % cannot be "
3547 & "volatile", Comp
);
3550 Next_Component
(Comp
);
3555 -- All done if not a full record definition
3557 if Ekind
(Rec
) /= E_Record_Type
then
3561 -- Finally we need to check the variant part to make sure that
3562 -- all types within choices are properly frozen as part of the
3563 -- freezing of the record type.
3565 Check_Variant_Part
: declare
3566 D
: constant Node_Id
:= Declaration_Node
(Rec
);
3571 -- Find component list
3575 if Nkind
(D
) = N_Full_Type_Declaration
then
3576 T
:= Type_Definition
(D
);
3578 if Nkind
(T
) = N_Record_Definition
then
3579 C
:= Component_List
(T
);
3581 elsif Nkind
(T
) = N_Derived_Type_Definition
3582 and then Present
(Record_Extension_Part
(T
))
3584 C
:= Component_List
(Record_Extension_Part
(T
));
3588 -- Case of variant part present
3590 if Present
(C
) and then Present
(Variant_Part
(C
)) then
3591 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
3594 -- Note: we used to call Check_Choices here, but it is too early,
3595 -- since predicated subtypes are frozen here, but their freezing
3596 -- actions are in Analyze_Freeze_Entity, which has not been called
3597 -- yet for entities frozen within this procedure, so we moved that
3598 -- call to the Analyze_Freeze_Entity for the record type.
3600 end Check_Variant_Part
;
3601 end Freeze_Record_Type
;
3603 -------------------------------
3604 -- Has_Boolean_Aspect_Import --
3605 -------------------------------
3607 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
3608 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3613 if Has_Aspects
(Decl
) then
3614 Asp
:= First
(Aspect_Specifications
(Decl
));
3615 while Present
(Asp
) loop
3616 Expr
:= Expression
(Asp
);
3618 -- The value of aspect Import is True when the expression is
3619 -- either missing or it is explicitly set to True.
3621 if Get_Aspect_Id
(Asp
) = Aspect_Import
3623 or else (Compile_Time_Known_Value
(Expr
)
3624 and then Is_True
(Expr_Value
(Expr
))))
3634 end Has_Boolean_Aspect_Import
;
3636 ------------------------------
3637 -- Wrap_Imported_Subprogram --
3638 ------------------------------
3640 -- The issue here is that our normal approach of checking preconditions
3641 -- and postconditions does not work for imported procedures, since we
3642 -- are not generating code for the body. To get around this we create
3643 -- a wrapper, as shown by the following example:
3645 -- procedure K (A : Integer);
3646 -- pragma Import (C, K);
3648 -- The spec is rewritten by removing the effects of pragma Import, but
3649 -- leaving the convention unchanged, as though the source had said:
3651 -- procedure K (A : Integer);
3652 -- pragma Convention (C, K);
3654 -- and we create a body, added to the entity K freeze actions, which
3657 -- procedure K (A : Integer) is
3658 -- procedure K (A : Integer);
3659 -- pragma Import (C, K);
3664 -- Now the contract applies in the normal way to the outer procedure,
3665 -- and the inner procedure has no contracts, so there is no problem
3666 -- in just calling it to get the original effect.
3668 -- In the case of a function, we create an appropriate return statement
3669 -- for the subprogram body that calls the inner procedure.
3671 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
3672 Loc
: constant Source_Ptr
:= Sloc
(E
);
3673 CE
: constant Name_Id
:= Chars
(E
);
3682 -- Nothing to do if not imported
3684 if not Is_Imported
(E
) then
3687 -- Test enabling conditions for wrapping
3689 elsif Is_Subprogram
(E
)
3690 and then Present
(Contract
(E
))
3691 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
3692 and then not GNATprove_Mode
3694 -- Here we do the wrap
3696 -- Note on calls to Copy_Separate_Tree. The trees we are copying
3697 -- here are fully analyzed, but we definitely want fully syntactic
3698 -- unanalyzed trees in the body we construct, so that the analysis
3699 -- generates the right visibility, and that is exactly what the
3700 -- calls to Copy_Separate_Tree give us.
3702 -- Acquire copy of Inline pragma
3704 Iprag
:= Copy_Separate_Tree
(Import_Pragma
(E
));
3706 -- Fix up spec to be not imported any more
3708 Set_Is_Imported
(E
, False);
3709 Set_Interface_Name
(E
, Empty
);
3710 Set_Has_Completion
(E
, False);
3711 Set_Import_Pragma
(E
, Empty
);
3713 -- Grab the subprogram declaration and specification
3715 Spec
:= Declaration_Node
(E
);
3717 -- Build parameter list that we need
3720 Forml
:= First_Formal
(E
);
3721 while Present
(Forml
) loop
3722 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
3723 Next_Formal
(Forml
);
3728 if Ekind_In
(E
, E_Function
, E_Generic_Function
) then
3730 Make_Simple_Return_Statement
(Loc
,
3732 Make_Function_Call
(Loc
,
3733 Name
=> Make_Identifier
(Loc
, CE
),
3734 Parameter_Associations
=> Parms
));
3738 Make_Procedure_Call_Statement
(Loc
,
3739 Name
=> Make_Identifier
(Loc
, CE
),
3740 Parameter_Associations
=> Parms
);
3743 -- Now build the body
3746 Make_Subprogram_Body
(Loc
,
3748 Copy_Separate_Tree
(Spec
),
3749 Declarations
=> New_List
(
3750 Make_Subprogram_Declaration
(Loc
,
3752 Copy_Separate_Tree
(Spec
)),
3754 Handled_Statement_Sequence
=>
3755 Make_Handled_Sequence_Of_Statements
(Loc
,
3756 Statements
=> New_List
(Stmt
),
3757 End_Label
=> Make_Identifier
(Loc
, CE
)));
3759 -- Append the body to freeze result
3761 Add_To_Result
(Bod
);
3764 -- Case of imported subprogram that does not get wrapped
3767 -- Set Is_Public. All imported entities need an external symbol
3768 -- created for them since they are always referenced from another
3769 -- object file. Note this used to be set when we set Is_Imported
3770 -- back in Sem_Prag, but now we delay it to this point, since we
3771 -- don't want to set this flag if we wrap an imported subprogram.
3775 end Wrap_Imported_Subprogram
;
3777 -- Start of processing for Freeze_Entity
3780 -- We are going to test for various reasons why this entity need not be
3781 -- frozen here, but in the case of an Itype that's defined within a
3782 -- record, that test actually applies to the record.
3784 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
3785 Test_E
:= Scope
(E
);
3786 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
3787 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
3789 Test_E
:= Underlying_Type
(Scope
(E
));
3792 -- Do not freeze if already frozen since we only need one freeze node
3794 if Is_Frozen
(E
) then
3797 -- It is improper to freeze an external entity within a generic because
3798 -- its freeze node will appear in a non-valid context. The entity will
3799 -- be frozen in the proper scope after the current generic is analyzed.
3800 -- However, aspects must be analyzed because they may be queried later
3801 -- within the generic itself, and the corresponding pragma or attribute
3802 -- definition has not been analyzed yet.
3804 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
3805 if Has_Delayed_Aspects
(E
) then
3806 Analyze_Aspects_At_Freeze_Point
(E
);
3811 -- AI05-0213: A formal incomplete type does not freeze the actual. In
3812 -- the instance, the same applies to the subtype renaming the actual.
3814 elsif Is_Private_Type
(E
)
3815 and then Is_Generic_Actual_Type
(E
)
3816 and then No
(Full_View
(Base_Type
(E
)))
3817 and then Ada_Version
>= Ada_2012
3821 -- Generic types need no freeze node and have no delayed semantic
3824 elsif Is_Generic_Type
(E
) then
3827 -- Do not freeze a global entity within an inner scope created during
3828 -- expansion. A call to subprogram E within some internal procedure
3829 -- (a stream attribute for example) might require freezing E, but the
3830 -- freeze node must appear in the same declarative part as E itself.
3831 -- The two-pass elaboration mechanism in gigi guarantees that E will
3832 -- be frozen before the inner call is elaborated. We exclude constants
3833 -- from this test, because deferred constants may be frozen early, and
3834 -- must be diagnosed (e.g. in the case of a deferred constant being used
3835 -- in a default expression). If the enclosing subprogram comes from
3836 -- source, or is a generic instance, then the freeze point is the one
3837 -- mandated by the language, and we freeze the entity. A subprogram that
3838 -- is a child unit body that acts as a spec does not have a spec that
3839 -- comes from source, but can only come from source.
3841 elsif In_Open_Scopes
(Scope
(Test_E
))
3842 and then Scope
(Test_E
) /= Current_Scope
3843 and then Ekind
(Test_E
) /= E_Constant
3850 while Present
(S
) loop
3851 if Is_Overloadable
(S
) then
3852 if Comes_From_Source
(S
)
3853 or else Is_Generic_Instance
(S
)
3854 or else Is_Child_Unit
(S
)
3866 -- Similarly, an inlined instance body may make reference to global
3867 -- entities, but these references cannot be the proper freezing point
3868 -- for them, and in the absence of inlining freezing will take place in
3869 -- their own scope. Normally instance bodies are analyzed after the
3870 -- enclosing compilation, and everything has been frozen at the proper
3871 -- place, but with front-end inlining an instance body is compiled
3872 -- before the end of the enclosing scope, and as a result out-of-order
3873 -- freezing must be prevented.
3875 elsif Front_End_Inlining
3876 and then In_Instance_Body
3877 and then Present
(Scope
(Test_E
))
3883 S
:= Scope
(Test_E
);
3884 while Present
(S
) loop
3885 if Is_Generic_Instance
(S
) then
3897 elsif Ekind
(E
) = E_Generic_Package
then
3898 return Freeze_Generic_Entities
(E
);
3901 -- Add checks to detect proper initialization of scalars that may appear
3902 -- as subprogram parameters.
3904 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
3905 Apply_Parameter_Validity_Checks
(E
);
3908 -- Deal with delayed aspect specifications. The analysis of the aspect
3909 -- is required to be delayed to the freeze point, thus we analyze the
3910 -- pragma or attribute definition clause in the tree at this point. We
3911 -- also analyze the aspect specification node at the freeze point when
3912 -- the aspect doesn't correspond to pragma/attribute definition clause.
3914 if Has_Delayed_Aspects
(E
) then
3915 Analyze_Aspects_At_Freeze_Point
(E
);
3918 -- Here to freeze the entity
3922 -- Case of entity being frozen is other than a type
3924 if not Is_Type
(E
) then
3926 -- If entity is exported or imported and does not have an external
3927 -- name, now is the time to provide the appropriate default name.
3928 -- Skip this if the entity is stubbed, since we don't need a name
3929 -- for any stubbed routine. For the case on intrinsics, if no
3930 -- external name is specified, then calls will be handled in
3931 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
3932 -- external name is provided, then Expand_Intrinsic_Call leaves
3933 -- calls in place for expansion by GIGI.
3935 if (Is_Imported
(E
) or else Is_Exported
(E
))
3936 and then No
(Interface_Name
(E
))
3937 and then Convention
(E
) /= Convention_Stubbed
3938 and then Convention
(E
) /= Convention_Intrinsic
3940 Set_Encoded_Interface_Name
3941 (E
, Get_Default_External_Name
(E
));
3943 -- If entity is an atomic object appearing in a declaration and
3944 -- the expression is an aggregate, assign it to a temporary to
3945 -- ensure that the actual assignment is done atomically rather
3946 -- than component-wise (the assignment to the temp may be done
3947 -- component-wise, but that is harmless).
3950 and then Nkind
(Parent
(E
)) = N_Object_Declaration
3951 and then Present
(Expression
(Parent
(E
)))
3952 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
3953 and then Is_Atomic_Aggregate
(Expression
(Parent
(E
)), Etype
(E
))
3960 if Is_Subprogram
(E
) then
3962 -- Check for needing to wrap imported subprogram
3964 Wrap_Imported_Subprogram
(E
);
3966 -- Freeze all parameter types and the return type (RM 13.14(14)).
3967 -- However skip this for internal subprograms. This is also where
3968 -- any extra formal parameters are created since we now know
3969 -- whether the subprogram will use a foreign convention.
3971 if not Is_Internal
(E
) then
3975 Warn_Node
: Node_Id
;
3978 -- Loop through formals
3980 Formal
:= First_Formal
(E
);
3981 while Present
(Formal
) loop
3982 F_Type
:= Etype
(Formal
);
3984 -- AI05-0151 : incomplete types can appear in a profile.
3985 -- By the time the entity is frozen, the full view must
3986 -- be available, unless it is a limited view.
3988 if Is_Incomplete_Type
(F_Type
)
3989 and then Present
(Full_View
(F_Type
))
3990 and then not From_Limited_With
(F_Type
)
3992 F_Type
:= Full_View
(F_Type
);
3993 Set_Etype
(Formal
, F_Type
);
3996 Freeze_And_Append
(F_Type
, N
, Result
);
3998 if Is_Private_Type
(F_Type
)
3999 and then Is_Private_Type
(Base_Type
(F_Type
))
4000 and then No
(Full_View
(Base_Type
(F_Type
)))
4001 and then not Is_Generic_Type
(F_Type
)
4002 and then not Is_Derived_Type
(F_Type
)
4004 -- If the type of a formal is incomplete, subprogram
4005 -- is being frozen prematurely. Within an instance
4006 -- (but not within a wrapper package) this is an
4007 -- artifact of our need to regard the end of an
4008 -- instantiation as a freeze point. Otherwise it is
4009 -- a definite error.
4012 Set_Is_Frozen
(E
, False);
4015 elsif not After_Last_Declaration
4016 and then not Freezing_Library_Level_Tagged_Type
4018 Error_Msg_Node_1
:= F_Type
;
4020 ("type& must be fully defined before this point",
4025 -- Check suspicious parameter for C function. These tests
4026 -- apply only to exported/imported subprograms.
4028 if Warn_On_Export_Import
4029 and then Comes_From_Source
(E
)
4030 and then (Convention
(E
) = Convention_C
4032 Convention
(E
) = Convention_CPP
)
4033 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4034 and then Convention
(E
) /= Convention
(Formal
)
4035 and then not Has_Warnings_Off
(E
)
4036 and then not Has_Warnings_Off
(F_Type
)
4037 and then not Has_Warnings_Off
(Formal
)
4039 -- Qualify mention of formals with subprogram name
4041 Error_Msg_Qual_Level
:= 1;
4043 -- Check suspicious use of fat C pointer
4045 if Is_Access_Type
(F_Type
)
4046 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
4049 ("?x?type of & does not correspond to C pointer!",
4052 -- Check suspicious return of boolean
4054 elsif Root_Type
(F_Type
) = Standard_Boolean
4055 and then Convention
(F_Type
) = Convention_Ada
4056 and then not Has_Warnings_Off
(F_Type
)
4057 and then not Has_Size_Clause
(F_Type
)
4058 and then VM_Target
= No_VM
4061 ("& is an 8-bit Ada Boolean?x?", Formal
);
4063 ("\use appropriate corresponding type in C "
4064 & "(e.g. char)?x?", Formal
);
4066 -- Check suspicious tagged type
4068 elsif (Is_Tagged_Type
(F_Type
)
4069 or else (Is_Access_Type
(F_Type
)
4072 (Designated_Type
(F_Type
))))
4073 and then Convention
(E
) = Convention_C
4076 ("?x?& involves a tagged type which does not "
4077 & "correspond to any C type!", Formal
);
4079 -- Check wrong convention subprogram pointer
4081 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
4082 and then not Has_Foreign_Convention
(F_Type
)
4085 ("?x?subprogram pointer & should "
4086 & "have foreign convention!", Formal
);
4087 Error_Msg_Sloc
:= Sloc
(F_Type
);
4089 ("\?x?add Convention pragma to declaration of &#",
4093 -- Turn off name qualification after message output
4095 Error_Msg_Qual_Level
:= 0;
4098 -- Check for unconstrained array in exported foreign
4101 if Has_Foreign_Convention
(E
)
4102 and then not Is_Imported
(E
)
4103 and then Is_Array_Type
(F_Type
)
4104 and then not Is_Constrained
(F_Type
)
4105 and then Warn_On_Export_Import
4107 -- Exclude VM case, since both .NET and JVM can handle
4108 -- unconstrained arrays without a problem.
4110 and then VM_Target
= No_VM
4112 Error_Msg_Qual_Level
:= 1;
4114 -- If this is an inherited operation, place the
4115 -- warning on the derived type declaration, rather
4116 -- than on the original subprogram.
4118 if Nkind
(Original_Node
(Parent
(E
))) =
4119 N_Full_Type_Declaration
4121 Warn_Node
:= Parent
(E
);
4123 if Formal
= First_Formal
(E
) then
4125 ("??in inherited operation&", Warn_Node
, E
);
4128 Warn_Node
:= Formal
;
4132 ("?x?type of argument& is unconstrained array",
4135 ("?x?foreign caller must pass bounds explicitly",
4137 Error_Msg_Qual_Level
:= 0;
4140 if not From_Limited_With
(F_Type
) then
4141 if Is_Access_Type
(F_Type
) then
4142 F_Type
:= Designated_Type
(F_Type
);
4145 -- If the formal is an anonymous_access_to_subprogram
4146 -- freeze the subprogram type as well, to prevent
4147 -- scope anomalies in gigi, because there is no other
4148 -- clear point at which it could be frozen.
4150 if Is_Itype
(Etype
(Formal
))
4151 and then Ekind
(F_Type
) = E_Subprogram_Type
4153 Freeze_And_Append
(F_Type
, N
, Result
);
4157 Next_Formal
(Formal
);
4160 -- Case of function: similar checks on return type
4162 if Ekind
(E
) = E_Function
then
4164 -- Freeze return type
4166 R_Type
:= Etype
(E
);
4168 -- AI05-0151: the return type may have been incomplete
4169 -- at the point of declaration. Replace it with the full
4170 -- view, unless the current type is a limited view. In
4171 -- that case the full view is in a different unit, and
4172 -- gigi finds the non-limited view after the other unit
4175 if Ekind
(R_Type
) = E_Incomplete_Type
4176 and then Present
(Full_View
(R_Type
))
4177 and then not From_Limited_With
(R_Type
)
4179 R_Type
:= Full_View
(R_Type
);
4180 Set_Etype
(E
, R_Type
);
4182 -- If the return type is a limited view and the non-
4183 -- limited view is still incomplete, the function has
4184 -- to be frozen at a later time.
4186 elsif Ekind
(R_Type
) = E_Incomplete_Type
4187 and then From_Limited_With
(R_Type
)
4189 Ekind
(Non_Limited_View
(R_Type
)) = E_Incomplete_Type
4191 Set_Is_Frozen
(E
, False);
4195 Freeze_And_Append
(R_Type
, N
, Result
);
4197 -- Check suspicious return type for C function
4199 if Warn_On_Export_Import
4200 and then (Convention
(E
) = Convention_C
4202 Convention
(E
) = Convention_CPP
)
4203 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4205 -- Check suspicious return of fat C pointer
4207 if Is_Access_Type
(R_Type
)
4208 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
4209 and then not Has_Warnings_Off
(E
)
4210 and then not Has_Warnings_Off
(R_Type
)
4213 ("?x?return type of& does not "
4214 & "correspond to C pointer!", E
);
4216 -- Check suspicious return of boolean
4218 elsif Root_Type
(R_Type
) = Standard_Boolean
4219 and then Convention
(R_Type
) = Convention_Ada
4220 and then VM_Target
= No_VM
4221 and then not Has_Warnings_Off
(E
)
4222 and then not Has_Warnings_Off
(R_Type
)
4223 and then not Has_Size_Clause
(R_Type
)
4226 N
: constant Node_Id
:=
4227 Result_Definition
(Declaration_Node
(E
));
4230 ("return type of & is an 8-bit Ada Boolean?x?",
4233 ("\use appropriate corresponding type in C "
4234 & "(e.g. char)?x?", N
, E
);
4237 -- Check suspicious return tagged type
4239 elsif (Is_Tagged_Type
(R_Type
)
4240 or else (Is_Access_Type
(R_Type
)
4243 (Designated_Type
(R_Type
))))
4244 and then Convention
(E
) = Convention_C
4245 and then not Has_Warnings_Off
(E
)
4246 and then not Has_Warnings_Off
(R_Type
)
4249 ("?x?return type of & does not "
4250 & "correspond to C type!", E
);
4252 -- Check return of wrong convention subprogram pointer
4254 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
4255 and then not Has_Foreign_Convention
(R_Type
)
4256 and then not Has_Warnings_Off
(E
)
4257 and then not Has_Warnings_Off
(R_Type
)
4260 ("?x?& should return a foreign "
4261 & "convention subprogram pointer", E
);
4262 Error_Msg_Sloc
:= Sloc
(R_Type
);
4264 ("\?x?add Convention pragma to declaration of& #",
4269 -- Give warning for suspicious return of a result of an
4270 -- unconstrained array type in a foreign convention
4273 if Has_Foreign_Convention
(E
)
4275 -- We are looking for a return of unconstrained array
4277 and then Is_Array_Type
(R_Type
)
4278 and then not Is_Constrained
(R_Type
)
4280 -- Exclude imported routines, the warning does not
4281 -- belong on the import, but rather on the routine
4284 and then not Is_Imported
(E
)
4286 -- Exclude VM case, since both .NET and JVM can handle
4287 -- return of unconstrained arrays without a problem.
4289 and then VM_Target
= No_VM
4291 -- Check that general warning is enabled, and that it
4292 -- is not suppressed for this particular case.
4294 and then Warn_On_Export_Import
4295 and then not Has_Warnings_Off
(E
)
4296 and then not Has_Warnings_Off
(R_Type
)
4299 ("?x?foreign convention function& should not " &
4300 "return unconstrained array!", E
);
4306 -- Must freeze its parent first if it is a derived subprogram
4308 if Present
(Alias
(E
)) then
4309 Freeze_And_Append
(Alias
(E
), N
, Result
);
4312 -- We don't freeze internal subprograms, because we don't normally
4313 -- want addition of extra formals or mechanism setting to happen
4314 -- for those. However we do pass through predefined dispatching
4315 -- cases, since extra formals may be needed in some cases, such as
4316 -- for the stream 'Input function (build-in-place formals).
4318 if not Is_Internal
(E
)
4319 or else Is_Predefined_Dispatching_Operation
(E
)
4321 Freeze_Subprogram
(E
);
4324 -- If warning on suspicious contracts then check for the case of
4325 -- a postcondition other than False for a No_Return subprogram.
4328 and then Warn_On_Suspicious_Contract
4329 and then Present
(Contract
(E
))
4332 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
4336 while Present
(Prag
) loop
4337 if Nam_In
(Pragma_Name
(Prag
), Name_Post
,
4343 (First
(Pragma_Argument_Associations
(Prag
)));
4345 if Nkind
(Exp
) /= N_Identifier
4346 or else Chars
(Exp
) /= Name_False
4349 ("useless postcondition, & is marked "
4350 & "No_Return?T?", Exp
, E
);
4354 Prag
:= Next_Pragma
(Prag
);
4359 -- Here for other than a subprogram or type
4362 -- If entity has a type, and it is not a generic unit, then
4363 -- freeze it first (RM 13.14(10)).
4365 if Present
(Etype
(E
))
4366 and then Ekind
(E
) /= E_Generic_Function
4368 Freeze_And_Append
(Etype
(E
), N
, Result
);
4371 -- Special processing for objects created by object declaration
4373 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
4375 -- Abstract type allowed only for C++ imported variables or
4378 -- Note: we inhibit this check for objects that do not come
4379 -- from source because there is at least one case (the
4380 -- expansion of x'Class'Input where x is abstract) where we
4381 -- legitimately generate an abstract object.
4383 if Is_Abstract_Type
(Etype
(E
))
4384 and then Comes_From_Source
(Parent
(E
))
4385 and then not (Is_Imported
(E
)
4386 and then Is_CPP_Class
(Etype
(E
)))
4388 Error_Msg_N
("type of object cannot be abstract",
4389 Object_Definition
(Parent
(E
)));
4391 if Is_CPP_Class
(Etype
(E
)) then
4393 ("\} may need a cpp_constructor",
4394 Object_Definition
(Parent
(E
)), Etype
(E
));
4398 -- For object created by object declaration, perform required
4399 -- categorization (preelaborate and pure) checks. Defer these
4400 -- checks to freeze time since pragma Import inhibits default
4401 -- initialization and thus pragma Import affects these checks.
4403 Validate_Object_Declaration
(Declaration_Node
(E
));
4405 -- If there is an address clause, check that it is valid
4407 Check_Address_Clause
(E
);
4409 -- Reset Is_True_Constant for aliased object. We consider that
4410 -- the fact that something is aliased may indicate that some
4411 -- funny business is going on, e.g. an aliased object is passed
4412 -- by reference to a procedure which captures the address of
4413 -- the object, which is later used to assign a new value. Such
4414 -- code is highly dubious, but we choose to make it "work" for
4417 -- However, we don't do that for internal entities. We figure
4418 -- that if we deliberately set Is_True_Constant for an internal
4419 -- entity, e.g. a dispatch table entry, then we mean it.
4421 if (Is_Aliased
(E
) or else Is_Aliased
(Etype
(E
)))
4422 and then not Is_Internal_Name
(Chars
(E
))
4424 Set_Is_True_Constant
(E
, False);
4427 -- If the object needs any kind of default initialization, an
4428 -- error must be issued if No_Default_Initialization applies.
4429 -- The check doesn't apply to imported objects, which are not
4430 -- ever default initialized, and is why the check is deferred
4431 -- until freezing, at which point we know if Import applies.
4432 -- Deferred constants are also exempted from this test because
4433 -- their completion is explicit, or through an import pragma.
4435 if Ekind
(E
) = E_Constant
4436 and then Present
(Full_View
(E
))
4440 elsif Comes_From_Source
(E
)
4441 and then not Is_Imported
(E
)
4442 and then not Has_Init_Expression
(Declaration_Node
(E
))
4444 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
4445 and then not No_Initialization
(Declaration_Node
(E
))
4446 and then not Is_Value_Type
(Etype
(E
))
4447 and then not Initialization_Suppressed
(Etype
(E
)))
4449 (Needs_Simple_Initialization
(Etype
(E
))
4450 and then not Is_Internal
(E
)))
4452 Has_Default_Initialization
:= True;
4454 (No_Default_Initialization
, Declaration_Node
(E
));
4457 -- Check that a Thread_Local_Storage variable does not have
4458 -- default initialization, and any explicit initialization must
4459 -- either be the null constant or a static constant.
4461 if Has_Pragma_Thread_Local_Storage
(E
) then
4463 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4465 if Has_Default_Initialization
4467 (Has_Init_Expression
(Decl
)
4469 (No
(Expression
(Decl
))
4471 (Is_OK_Static_Expression
(Expression
(Decl
))
4473 Nkind
(Expression
(Decl
)) = N_Null
)))
4476 ("Thread_Local_Storage variable& is "
4477 & "improperly initialized", Decl
, E
);
4479 ("\only allowed initialization is explicit "
4480 & "NULL or static expression", Decl
, E
);
4485 -- For imported objects, set Is_Public unless there is also an
4486 -- address clause, which means that there is no external symbol
4487 -- needed for the Import (Is_Public may still be set for other
4488 -- unrelated reasons). Note that we delayed this processing
4489 -- till freeze time so that we can be sure not to set the flag
4490 -- if there is an address clause. If there is such a clause,
4491 -- then the only purpose of the Import pragma is to suppress
4492 -- implicit initialization.
4494 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4498 -- For source objects that are not Imported and are library
4499 -- level, if no linker section pragma was given inherit the
4500 -- appropriate linker section from the corresponding type.
4502 if Comes_From_Source
(E
)
4503 and then not Is_Imported
(E
)
4504 and then Is_Library_Level_Entity
(E
)
4505 and then No
(Linker_Section_Pragma
(E
))
4507 Set_Linker_Section_Pragma
4508 (E
, Linker_Section_Pragma
(Etype
(E
)));
4511 -- For convention C objects of an enumeration type, warn if
4512 -- the size is not integer size and no explicit size given.
4513 -- Skip warning for Boolean, and Character, assume programmer
4514 -- expects 8-bit sizes for these cases.
4516 if (Convention
(E
) = Convention_C
4518 Convention
(E
) = Convention_CPP
)
4519 and then Is_Enumeration_Type
(Etype
(E
))
4520 and then not Is_Character_Type
(Etype
(E
))
4521 and then not Is_Boolean_Type
(Etype
(E
))
4522 and then Esize
(Etype
(E
)) < Standard_Integer_Size
4523 and then not Has_Size_Clause
(E
)
4525 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4527 ("??convention C enumeration object has size less than ^",
4529 Error_Msg_N
("\??use explicit size clause to set size", E
);
4533 -- Check that a constant which has a pragma Volatile[_Components]
4534 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
4536 -- Note: Atomic[_Components] also sets Volatile[_Components]
4538 if Ekind
(E
) = E_Constant
4539 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
4540 and then not Is_Imported
(E
)
4541 and then not Has_Boolean_Aspect_Import
(E
)
4543 -- Make sure we actually have a pragma, and have not merely
4544 -- inherited the indication from elsewhere (e.g. an address
4545 -- clause, which is not good enough in RM terms).
4547 if Has_Rep_Pragma
(E
, Name_Atomic
)
4549 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
4552 ("stand alone atomic constant must be " &
4553 "imported (RM C.6(13))", E
);
4555 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
4557 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
4560 ("stand alone volatile constant must be " &
4561 "imported (RM C.6(13))", E
);
4565 -- Static objects require special handling
4567 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
4568 and then Is_Statically_Allocated
(E
)
4570 Freeze_Static_Object
(E
);
4573 -- Remaining step is to layout objects
4575 if Ekind_In
(E
, E_Variable
, E_Constant
, E_Loop_Parameter
)
4576 or else Is_Formal
(E
)
4581 -- For an object that does not have delayed freezing, and whose
4582 -- initialization actions have been captured in a compound
4583 -- statement, move them back now directly within the enclosing
4584 -- statement sequence.
4586 if Ekind_In
(E
, E_Constant
, E_Variable
)
4587 and then not Has_Delayed_Freeze
(E
)
4589 Explode_Initialization_Compound_Statement
(E
);
4593 -- Case of a type or subtype being frozen
4596 -- We used to check here that a full type must have preelaborable
4597 -- initialization if it completes a private type specified with
4598 -- pragma Preelaborable_Initialization, but that missed cases where
4599 -- the types occur within a generic package, since the freezing
4600 -- that occurs within a containing scope generally skips traversal
4601 -- of a generic unit's declarations (those will be frozen within
4602 -- instances). This check was moved to Analyze_Package_Specification.
4604 -- The type may be defined in a generic unit. This can occur when
4605 -- freezing a generic function that returns the type (which is
4606 -- defined in a parent unit). It is clearly meaningless to freeze
4607 -- this type. However, if it is a subtype, its size may be determi-
4608 -- nable and used in subsequent checks, so might as well try to
4611 -- In Ada 2012, Freeze_Entities is also used in the front end to
4612 -- trigger the analysis of aspect expressions, so in this case we
4613 -- want to continue the freezing process.
4615 if Present
(Scope
(E
))
4616 and then Is_Generic_Unit
(Scope
(E
))
4618 (not Has_Predicates
(E
)
4619 and then not Has_Delayed_Freeze
(E
))
4621 Check_Compile_Time_Size
(E
);
4625 -- Check for error of Type_Invariant'Class applied to an untagged
4626 -- type (check delayed to freeze time when full type is available).
4629 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
4632 and then Class_Present
(Prag
)
4633 and then not Is_Tagged_Type
(E
)
4636 ("Type_Invariant''Class cannot be specified for &",
4639 ("\can only be specified for a tagged type", Prag
);
4643 -- Deal with special cases of freezing for subtype
4645 if E
/= Base_Type
(E
) then
4647 -- Before we do anything else, a specialized test for the case of
4648 -- a size given for an array where the array needs to be packed,
4649 -- but was not so the size cannot be honored. This is the case
4650 -- where implicit packing may apply. The reason we do this so
4651 -- early is that if we have implicit packing, the layout of the
4652 -- base type is affected, so we must do this before we freeze
4655 -- We could do this processing only if implicit packing is enabled
4656 -- since in all other cases, the error would be caught by the back
4657 -- end. However, we choose to do the check even if we do not have
4658 -- implicit packing enabled, since this allows us to give a more
4659 -- useful error message (advising use of pragmas Implicit_Packing
4662 if Is_Array_Type
(E
) then
4664 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
4665 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
4666 SZ
: constant Node_Id
:= Size_Clause
(E
);
4667 Btyp
: constant Entity_Id
:= Base_Type
(E
);
4674 -- Number of elements in array
4677 -- Check enabling conditions. These are straightforward
4678 -- except for the test for a limited composite type. This
4679 -- eliminates the rare case of a array of limited components
4680 -- where there are issues of whether or not we can go ahead
4681 -- and pack the array (since we can't freely pack and unpack
4682 -- arrays if they are limited).
4684 -- Note that we check the root type explicitly because the
4685 -- whole point is we are doing this test before we have had
4686 -- a chance to freeze the base type (and it is that freeze
4687 -- action that causes stuff to be inherited).
4689 if Has_Size_Clause
(E
)
4690 and then Known_Static_RM_Size
(E
)
4691 and then not Is_Packed
(E
)
4692 and then not Has_Pragma_Pack
(E
)
4693 and then not Has_Component_Size_Clause
(E
)
4694 and then Known_Static_RM_Size
(Ctyp
)
4695 and then RM_Size
(Ctyp
) < 64
4696 and then not Is_Limited_Composite
(E
)
4697 and then not Is_Packed
(Root_Type
(E
))
4698 and then not Has_Component_Size_Clause
(Root_Type
(E
))
4699 and then not (CodePeer_Mode
or GNATprove_Mode
)
4701 -- Compute number of elements in array
4703 Num_Elmts
:= Uint_1
;
4704 Indx
:= First_Index
(E
);
4705 while Present
(Indx
) loop
4706 Get_Index_Bounds
(Indx
, Lo
, Hi
);
4708 if not (Compile_Time_Known_Value
(Lo
)
4710 Compile_Time_Known_Value
(Hi
))
4712 goto No_Implicit_Packing
;
4718 Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1);
4722 -- What we are looking for here is the situation where
4723 -- the RM_Size given would be exactly right if there was
4724 -- a pragma Pack (resulting in the component size being
4725 -- the same as the RM_Size). Furthermore, the component
4726 -- type size must be an odd size (not a multiple of
4727 -- storage unit). If the component RM size is an exact
4728 -- number of storage units that is a power of two, the
4729 -- array is not packed and has a standard representation.
4731 if RM_Size
(E
) = Num_Elmts
* Rsiz
4732 and then Rsiz
mod System_Storage_Unit
/= 0
4734 -- For implicit packing mode, just set the component
4737 if Implicit_Packing
then
4738 Set_Component_Size
(Btyp
, Rsiz
);
4739 Set_Is_Bit_Packed_Array
(Btyp
);
4740 Set_Is_Packed
(Btyp
);
4741 Set_Has_Non_Standard_Rep
(Btyp
);
4743 -- Otherwise give an error message
4747 ("size given for& too small", SZ
, E
);
4748 Error_Msg_N
-- CODEFIX
4749 ("\use explicit pragma Pack "
4750 & "or use pragma Implicit_Packing", SZ
);
4753 elsif RM_Size
(E
) = Num_Elmts
* Rsiz
4754 and then Implicit_Packing
4756 (Rsiz
/ System_Storage_Unit
= 1
4758 Rsiz
/ System_Storage_Unit
= 2
4760 Rsiz
/ System_Storage_Unit
= 4)
4762 -- Not a packed array, but indicate the desired
4763 -- component size, for the back-end.
4765 Set_Component_Size
(Btyp
, Rsiz
);
4771 <<No_Implicit_Packing
>>
4773 -- If ancestor subtype present, freeze that first. Note that this
4774 -- will also get the base type frozen. Need RM reference ???
4776 Atype
:= Ancestor_Subtype
(E
);
4778 if Present
(Atype
) then
4779 Freeze_And_Append
(Atype
, N
, Result
);
4781 -- No ancestor subtype present
4784 -- See if we have a nearest ancestor that has a predicate.
4785 -- That catches the case of derived type with a predicate.
4786 -- Need RM reference here ???
4788 Atype
:= Nearest_Ancestor
(E
);
4790 if Present
(Atype
) and then Has_Predicates
(Atype
) then
4791 Freeze_And_Append
(Atype
, N
, Result
);
4794 -- Freeze base type before freezing the entity (RM 13.14(15))
4796 if E
/= Base_Type
(E
) then
4797 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
4801 -- A subtype inherits all the type-related representation aspects
4802 -- from its parents (RM 13.1(8)).
4804 Inherit_Aspects_At_Freeze_Point
(E
);
4806 -- For a derived type, freeze its parent type first (RM 13.14(15))
4808 elsif Is_Derived_Type
(E
) then
4809 Freeze_And_Append
(Etype
(E
), N
, Result
);
4810 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
4812 -- A derived type inherits each type-related representation aspect
4813 -- of its parent type that was directly specified before the
4814 -- declaration of the derived type (RM 13.1(15)).
4816 Inherit_Aspects_At_Freeze_Point
(E
);
4819 -- Check for incompatible size and alignment for record type
4821 if Warn_On_Size_Alignment
4822 and then Is_Record_Type
(E
)
4823 and then Has_Size_Clause
(E
) and then Has_Alignment_Clause
(E
)
4825 -- If explicit Object_Size clause given assume that the programmer
4826 -- knows what he is doing, and expects the compiler behavior.
4828 and then not Has_Object_Size_Clause
(E
)
4830 -- Check for size not a multiple of alignment
4832 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
4835 SC
: constant Node_Id
:= Size_Clause
(E
);
4836 AC
: constant Node_Id
:= Alignment_Clause
(E
);
4838 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
4841 if Present
(SC
) and then Present
(AC
) then
4845 if Sloc
(SC
) > Sloc
(AC
) then
4848 ("??size is not a multiple of alignment for &", Loc
, E
);
4849 Error_Msg_Sloc
:= Sloc
(AC
);
4850 Error_Msg_Uint_1
:= Alignment
(E
);
4851 Error_Msg_N
("\??alignment of ^ specified #", Loc
);
4856 ("??size is not a multiple of alignment for &", Loc
, E
);
4857 Error_Msg_Sloc
:= Sloc
(SC
);
4858 Error_Msg_Uint_1
:= RM_Size
(E
);
4859 Error_Msg_N
("\??size of ^ specified #", Loc
);
4862 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
4863 Error_Msg_N
("\??Object_Size will be increased to ^", Loc
);
4870 if Is_Array_Type
(E
) then
4871 Freeze_Array_Type
(E
);
4873 -- For a class-wide type, the corresponding specific type is
4874 -- frozen as well (RM 13.14(15))
4876 elsif Is_Class_Wide_Type
(E
) then
4877 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
4879 -- If the base type of the class-wide type is still incomplete,
4880 -- the class-wide remains unfrozen as well. This is legal when
4881 -- E is the formal of a primitive operation of some other type
4882 -- which is being frozen.
4884 if not Is_Frozen
(Root_Type
(E
)) then
4885 Set_Is_Frozen
(E
, False);
4889 -- The equivalent type associated with a class-wide subtype needs
4890 -- to be frozen to ensure that its layout is done.
4892 if Ekind
(E
) = E_Class_Wide_Subtype
4893 and then Present
(Equivalent_Type
(E
))
4895 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
4898 -- Generate an itype reference for a library-level class-wide type
4899 -- at the freeze point. Otherwise the first explicit reference to
4900 -- the type may appear in an inner scope which will be rejected by
4904 and then Is_Compilation_Unit
(Scope
(E
))
4907 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
4912 -- From a gigi point of view, a class-wide subtype derives
4913 -- from its record equivalent type. As a result, the itype
4914 -- reference must appear after the freeze node of the
4915 -- equivalent type or gigi will reject the reference.
4917 if Ekind
(E
) = E_Class_Wide_Subtype
4918 and then Present
(Equivalent_Type
(E
))
4920 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
4922 Add_To_Result
(Ref
);
4927 -- For a record type or record subtype, freeze all component types
4928 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
4929 -- using Is_Record_Type, because we don't want to attempt the freeze
4930 -- for the case of a private type with record extension (we will do
4931 -- that later when the full type is frozen).
4933 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
)
4934 and then not Is_Generic_Unit
(Scope
(E
))
4936 Freeze_Record_Type
(E
);
4938 -- For a concurrent type, freeze corresponding record type. This does
4939 -- not correspond to any specific rule in the RM, but the record type
4940 -- is essentially part of the concurrent type. Also freeze all local
4941 -- entities. This includes record types created for entry parameter
4942 -- blocks and whatever local entities may appear in the private part.
4944 elsif Is_Concurrent_Type
(E
) then
4945 if Present
(Corresponding_Record_Type
(E
)) then
4946 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
4949 Comp
:= First_Entity
(E
);
4950 while Present
(Comp
) loop
4951 if Is_Type
(Comp
) then
4952 Freeze_And_Append
(Comp
, N
, Result
);
4954 elsif (Ekind
(Comp
)) /= E_Function
then
4956 -- The guard on the presence of the Etype seems to be needed
4957 -- for some CodePeer (-gnatcC) cases, but not clear why???
4959 if Present
(Etype
(Comp
)) then
4960 if Is_Itype
(Etype
(Comp
))
4961 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
4963 Undelay_Type
(Etype
(Comp
));
4966 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
4973 -- Private types are required to point to the same freeze node as
4974 -- their corresponding full views. The freeze node itself has to
4975 -- point to the partial view of the entity (because from the partial
4976 -- view, we can retrieve the full view, but not the reverse).
4977 -- However, in order to freeze correctly, we need to freeze the full
4978 -- view. If we are freezing at the end of a scope (or within the
4979 -- scope) of the private type, the partial and full views will have
4980 -- been swapped, the full view appears first in the entity chain and
4981 -- the swapping mechanism ensures that the pointers are properly set
4984 -- If we encounter the partial view before the full view (e.g. when
4985 -- freezing from another scope), we freeze the full view, and then
4986 -- set the pointers appropriately since we cannot rely on swapping to
4987 -- fix things up (subtypes in an outer scope might not get swapped).
4989 -- If the full view is itself private, the above requirements apply
4990 -- to the underlying full view instead of the full view. But there is
4991 -- no swapping mechanism for the underlying full view so we need to
4992 -- set the pointers appropriately in both cases.
4994 elsif Is_Incomplete_Or_Private_Type
(E
)
4995 and then not Is_Generic_Type
(E
)
4997 -- The construction of the dispatch table associated with library
4998 -- level tagged types forces freezing of all the primitives of the
4999 -- type, which may cause premature freezing of the partial view.
5003 -- type T is tagged private;
5004 -- type DT is new T with private;
5005 -- procedure Prim (X : in out T; Y : in out DT'Class);
5007 -- type T is tagged null record;
5009 -- type DT is new T with null record;
5012 -- In this case the type will be frozen later by the usual
5013 -- mechanism: an object declaration, an instantiation, or the
5014 -- end of a declarative part.
5016 if Is_Library_Level_Tagged_Type
(E
)
5017 and then not Present
(Full_View
(E
))
5019 Set_Is_Frozen
(E
, False);
5022 -- Case of full view present
5024 elsif Present
(Full_View
(E
)) then
5026 -- If full view has already been frozen, then no further
5027 -- processing is required
5029 if Is_Frozen
(Full_View
(E
)) then
5030 Set_Has_Delayed_Freeze
(E
, False);
5031 Set_Freeze_Node
(E
, Empty
);
5033 -- Otherwise freeze full view and patch the pointers so that
5034 -- the freeze node will elaborate both views in the back end.
5035 -- However, if full view is itself private, freeze underlying
5036 -- full view instead and patch the pointers so that the freeze
5037 -- node will elaborate the three views in the back end.
5041 Full
: Entity_Id
:= Full_View
(E
);
5044 if Is_Private_Type
(Full
)
5045 and then Present
(Underlying_Full_View
(Full
))
5047 Full
:= Underlying_Full_View
(Full
);
5050 Freeze_And_Append
(Full
, N
, Result
);
5052 if Full
/= Full_View
(E
)
5053 and then Has_Delayed_Freeze
(Full_View
(E
))
5055 F_Node
:= Freeze_Node
(Full
);
5057 if Present
(F_Node
) then
5058 Set_Freeze_Node
(Full_View
(E
), F_Node
);
5059 Set_Entity
(F_Node
, Full_View
(E
));
5062 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
5063 Set_Freeze_Node
(Full_View
(E
), Empty
);
5067 if Has_Delayed_Freeze
(E
) then
5068 F_Node
:= Freeze_Node
(Full_View
(E
));
5070 if Present
(F_Node
) then
5071 Set_Freeze_Node
(E
, F_Node
);
5072 Set_Entity
(F_Node
, E
);
5075 -- {Incomplete,Private}_Subtypes with Full_Views
5076 -- constrained by discriminants.
5078 Set_Has_Delayed_Freeze
(E
, False);
5079 Set_Freeze_Node
(E
, Empty
);
5085 Check_Debug_Info_Needed
(E
);
5087 -- AI-117 requires that the convention of a partial view be the
5088 -- same as the convention of the full view. Note that this is a
5089 -- recognized breach of privacy, but it's essential for logical
5090 -- consistency of representation, and the lack of a rule in
5091 -- RM95 was an oversight.
5093 Set_Convention
(E
, Convention
(Full_View
(E
)));
5095 Set_Size_Known_At_Compile_Time
(E
,
5096 Size_Known_At_Compile_Time
(Full_View
(E
)));
5098 -- Size information is copied from the full view to the
5099 -- incomplete or private view for consistency.
5101 -- We skip this is the full view is not a type. This is very
5102 -- strange of course, and can only happen as a result of
5103 -- certain illegalities, such as a premature attempt to derive
5104 -- from an incomplete type.
5106 if Is_Type
(Full_View
(E
)) then
5107 Set_Size_Info
(E
, Full_View
(E
));
5108 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
5113 -- Case of underlying full view present
5115 elsif Is_Private_Type
(E
)
5116 and then Present
(Underlying_Full_View
(E
))
5118 if not Is_Frozen
(Underlying_Full_View
(E
)) then
5119 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
5122 -- Patch the pointers so that the freeze node will elaborate
5123 -- both views in the back end.
5125 if Has_Delayed_Freeze
(E
) then
5126 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
5128 if Present
(F_Node
) then
5129 Set_Freeze_Node
(E
, F_Node
);
5130 Set_Entity
(F_Node
, E
);
5133 Set_Has_Delayed_Freeze
(E
, False);
5134 Set_Freeze_Node
(E
, Empty
);
5138 Check_Debug_Info_Needed
(E
);
5142 -- Case of no full view present. If entity is derived or subtype,
5143 -- it is safe to freeze, correctness depends on the frozen status
5144 -- of parent. Otherwise it is either premature usage, or a Taft
5145 -- amendment type, so diagnosis is at the point of use and the
5146 -- type might be frozen later.
5148 elsif E
/= Base_Type
(E
) or else Is_Derived_Type
(E
) then
5152 Set_Is_Frozen
(E
, False);
5156 -- For access subprogram, freeze types of all formals, the return
5157 -- type was already frozen, since it is the Etype of the function.
5158 -- Formal types can be tagged Taft amendment types, but otherwise
5159 -- they cannot be incomplete.
5161 elsif Ekind
(E
) = E_Subprogram_Type
then
5162 Formal
:= First_Formal
(E
);
5163 while Present
(Formal
) loop
5164 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
5165 and then No
(Full_View
(Etype
(Formal
)))
5166 and then not Is_Value_Type
(Etype
(Formal
))
5168 if Is_Tagged_Type
(Etype
(Formal
)) then
5171 -- AI05-151: Incomplete types are allowed in access to
5172 -- subprogram specifications.
5174 elsif Ada_Version
< Ada_2012
then
5176 ("invalid use of incomplete type&", E
, Etype
(Formal
));
5180 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
5181 Next_Formal
(Formal
);
5184 Freeze_Subprogram
(E
);
5186 -- For access to a protected subprogram, freeze the equivalent type
5187 -- (however this is not set if we are not generating code or if this
5188 -- is an anonymous type used just for resolution).
5190 elsif Is_Access_Protected_Subprogram_Type
(E
) then
5191 if Present
(Equivalent_Type
(E
)) then
5192 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5196 -- Generic types are never seen by the back-end, and are also not
5197 -- processed by the expander (since the expander is turned off for
5198 -- generic processing), so we never need freeze nodes for them.
5200 if Is_Generic_Type
(E
) then
5204 -- Some special processing for non-generic types to complete
5205 -- representation details not known till the freeze point.
5207 if Is_Fixed_Point_Type
(E
) then
5208 Freeze_Fixed_Point_Type
(E
);
5210 -- Some error checks required for ordinary fixed-point type. Defer
5211 -- these till the freeze-point since we need the small and range
5212 -- values. We only do these checks for base types
5214 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
5215 if Small_Value
(E
) < Ureal_2_M_80
then
5216 Error_Msg_Name_1
:= Name_Small
;
5218 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
5220 elsif Small_Value
(E
) > Ureal_2_80
then
5221 Error_Msg_Name_1
:= Name_Small
;
5223 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
5226 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
5227 Error_Msg_Name_1
:= Name_First
;
5229 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
5232 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
5233 Error_Msg_Name_1
:= Name_Last
;
5235 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
5239 elsif Is_Enumeration_Type
(E
) then
5240 Freeze_Enumeration_Type
(E
);
5242 elsif Is_Integer_Type
(E
) then
5243 Adjust_Esize_For_Alignment
(E
);
5245 if Is_Modular_Integer_Type
(E
)
5246 and then Warn_On_Suspicious_Modulus_Value
5248 Check_Suspicious_Modulus
(E
);
5251 elsif Is_Access_Type
(E
)
5252 and then not Is_Access_Subprogram_Type
(E
)
5254 -- If a pragma Default_Storage_Pool applies, and this type has no
5255 -- Storage_Pool or Storage_Size clause (which must have occurred
5256 -- before the freezing point), then use the default. This applies
5257 -- only to base types.
5259 -- None of this applies to access to subprograms, for which there
5260 -- are clearly no pools.
5262 if Present
(Default_Pool
)
5263 and then Is_Base_Type
(E
)
5264 and then not Has_Storage_Size_Clause
(E
)
5265 and then No
(Associated_Storage_Pool
(E
))
5267 -- Case of pragma Default_Storage_Pool (null)
5269 if Nkind
(Default_Pool
) = N_Null
then
5270 Set_No_Pool_Assigned
(E
);
5272 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
5275 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
5279 -- Check restriction for standard storage pool
5281 if No
(Associated_Storage_Pool
(E
)) then
5282 Check_Restriction
(No_Standard_Storage_Pools
, E
);
5285 -- Deal with error message for pure access type. This is not an
5286 -- error in Ada 2005 if there is no pool (see AI-366).
5288 if Is_Pure_Unit_Access_Type
(E
)
5289 and then (Ada_Version
< Ada_2005
5290 or else not No_Pool_Assigned
(E
))
5291 and then not Is_Generic_Unit
(Scope
(E
))
5293 Error_Msg_N
("named access type not allowed in pure unit", E
);
5295 if Ada_Version
>= Ada_2005
then
5297 ("\would be legal if Storage_Size of 0 given??", E
);
5299 elsif No_Pool_Assigned
(E
) then
5301 ("\would be legal in Ada 2005??", E
);
5305 ("\would be legal in Ada 2005 if "
5306 & "Storage_Size of 0 given??", E
);
5311 -- Case of composite types
5313 if Is_Composite_Type
(E
) then
5315 -- AI-117 requires that all new primitives of a tagged type must
5316 -- inherit the convention of the full view of the type. Inherited
5317 -- and overriding operations are defined to inherit the convention
5318 -- of their parent or overridden subprogram (also specified in
5319 -- AI-117), which will have occurred earlier (in Derive_Subprogram
5320 -- and New_Overloaded_Entity). Here we set the convention of
5321 -- primitives that are still convention Ada, which will ensure
5322 -- that any new primitives inherit the type's convention. Class-
5323 -- wide types can have a foreign convention inherited from their
5324 -- specific type, but are excluded from this since they don't have
5325 -- any associated primitives.
5327 if Is_Tagged_Type
(E
)
5328 and then not Is_Class_Wide_Type
(E
)
5329 and then Convention
(E
) /= Convention_Ada
5332 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
5336 Prim
:= First_Elmt
(Prim_List
);
5337 while Present
(Prim
) loop
5338 if Convention
(Node
(Prim
)) = Convention_Ada
then
5339 Set_Convention
(Node
(Prim
), Convention
(E
));
5347 -- If the type is a simple storage pool type, then this is where
5348 -- we attempt to locate and validate its Allocate, Deallocate, and
5349 -- Storage_Size operations (the first is required, and the latter
5350 -- two are optional). We also verify that the full type for a
5351 -- private type is allowed to be a simple storage pool type.
5353 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
5354 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
5356 -- If the type is marked Has_Private_Declaration, then this is
5357 -- a full type for a private type that was specified with the
5358 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
5359 -- pragma is allowed for the full type (for example, it can't
5360 -- be an array type, or a nonlimited record type).
5362 if Has_Private_Declaration
(E
) then
5363 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
5364 and then not Is_Private_Type
(E
)
5366 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
5368 ("pragma% can only apply to full type that is an " &
5369 "explicitly limited type", E
);
5373 Validate_Simple_Pool_Ops
: declare
5374 Pool_Type
: Entity_Id
renames E
;
5375 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
5376 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
5378 procedure Validate_Simple_Pool_Op_Formal
5379 (Pool_Op
: Entity_Id
;
5380 Pool_Op_Formal
: in out Entity_Id
;
5381 Expected_Mode
: Formal_Kind
;
5382 Expected_Type
: Entity_Id
;
5383 Formal_Name
: String;
5384 OK_Formal
: in out Boolean);
5385 -- Validate one formal Pool_Op_Formal of the candidate pool
5386 -- operation Pool_Op. The formal must be of Expected_Type
5387 -- and have mode Expected_Mode. OK_Formal will be set to
5388 -- False if the formal doesn't match. If OK_Formal is False
5389 -- on entry, then the formal will effectively be ignored
5390 -- (because validation of the pool op has already failed).
5391 -- Upon return, Pool_Op_Formal will be updated to the next
5394 procedure Validate_Simple_Pool_Operation
5395 (Op_Name
: Name_Id
);
5396 -- Search for and validate a simple pool operation with the
5397 -- name Op_Name. If the name is Allocate, then there must be
5398 -- exactly one such primitive operation for the simple pool
5399 -- type. If the name is Deallocate or Storage_Size, then
5400 -- there can be at most one such primitive operation. The
5401 -- profile of the located primitive must conform to what
5402 -- is expected for each operation.
5404 ------------------------------------
5405 -- Validate_Simple_Pool_Op_Formal --
5406 ------------------------------------
5408 procedure Validate_Simple_Pool_Op_Formal
5409 (Pool_Op
: Entity_Id
;
5410 Pool_Op_Formal
: in out Entity_Id
;
5411 Expected_Mode
: Formal_Kind
;
5412 Expected_Type
: Entity_Id
;
5413 Formal_Name
: String;
5414 OK_Formal
: in out Boolean)
5417 -- If OK_Formal is False on entry, then simply ignore
5418 -- the formal, because an earlier formal has already
5421 if not OK_Formal
then
5424 -- If no formal is passed in, then issue an error for a
5427 elsif not Present
(Pool_Op_Formal
) then
5429 ("simple storage pool op missing formal " &
5430 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
5436 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
5438 -- If the pool type was expected for this formal, then
5439 -- this will not be considered a candidate operation
5440 -- for the simple pool, so we unset OK_Formal so that
5441 -- the op and any later formals will be ignored.
5443 if Expected_Type
= Pool_Type
then
5450 ("wrong type for formal " & Formal_Name
&
5451 " of simple storage pool op; expected type&",
5452 Pool_Op_Formal
, Expected_Type
);
5456 -- Issue error if formal's mode is not the expected one
5458 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
5460 ("wrong mode for formal of simple storage pool op",
5464 -- Advance to the next formal
5466 Next_Formal
(Pool_Op_Formal
);
5467 end Validate_Simple_Pool_Op_Formal
;
5469 ------------------------------------
5470 -- Validate_Simple_Pool_Operation --
5471 ------------------------------------
5473 procedure Validate_Simple_Pool_Operation
5477 Found_Op
: Entity_Id
:= Empty
;
5483 (Nam_In
(Op_Name
, Name_Allocate
,
5485 Name_Storage_Size
));
5487 Error_Msg_Name_1
:= Op_Name
;
5489 -- For each homonym declared immediately in the scope
5490 -- of the simple storage pool type, determine whether
5491 -- the homonym is an operation of the pool type, and,
5492 -- if so, check that its profile is as expected for
5493 -- a simple pool operation of that name.
5495 Op
:= Get_Name_Entity_Id
(Op_Name
);
5496 while Present
(Op
) loop
5497 if Ekind_In
(Op
, E_Function
, E_Procedure
)
5498 and then Scope
(Op
) = Current_Scope
5500 Formal
:= First_Entity
(Op
);
5504 -- The first parameter must be of the pool type
5505 -- in order for the operation to qualify.
5507 if Op_Name
= Name_Storage_Size
then
5508 Validate_Simple_Pool_Op_Formal
5509 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
5512 Validate_Simple_Pool_Op_Formal
5513 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
5517 -- If another operation with this name has already
5518 -- been located for the type, then flag an error,
5519 -- since we only allow the type to have a single
5522 if Present
(Found_Op
) and then Is_OK
then
5524 ("only one % operation allowed for " &
5525 "simple storage pool type&", Op
, Pool_Type
);
5528 -- In the case of Allocate and Deallocate, a formal
5529 -- of type System.Address is required.
5531 if Op_Name
= Name_Allocate
then
5532 Validate_Simple_Pool_Op_Formal
5533 (Op
, Formal
, E_Out_Parameter
,
5534 Address_Type
, "Storage_Address", Is_OK
);
5536 elsif Op_Name
= Name_Deallocate
then
5537 Validate_Simple_Pool_Op_Formal
5538 (Op
, Formal
, E_In_Parameter
,
5539 Address_Type
, "Storage_Address", Is_OK
);
5542 -- In the case of Allocate and Deallocate, formals
5543 -- of type Storage_Count are required as the third
5544 -- and fourth parameters.
5546 if Op_Name
/= Name_Storage_Size
then
5547 Validate_Simple_Pool_Op_Formal
5548 (Op
, Formal
, E_In_Parameter
,
5549 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
5550 Validate_Simple_Pool_Op_Formal
5551 (Op
, Formal
, E_In_Parameter
,
5552 Stg_Cnt_Type
, "Alignment", Is_OK
);
5555 -- If no mismatched formals have been found (Is_OK)
5556 -- and no excess formals are present, then this
5557 -- operation has been validated, so record it.
5559 if not Present
(Formal
) and then Is_OK
then
5567 -- There must be a valid Allocate operation for the type,
5568 -- so issue an error if none was found.
5570 if Op_Name
= Name_Allocate
5571 and then not Present
(Found_Op
)
5573 Error_Msg_N
("missing % operation for simple " &
5574 "storage pool type", Pool_Type
);
5576 elsif Present
(Found_Op
) then
5578 -- Simple pool operations can't be abstract
5580 if Is_Abstract_Subprogram
(Found_Op
) then
5582 ("simple storage pool operation must not be " &
5583 "abstract", Found_Op
);
5586 -- The Storage_Size operation must be a function with
5587 -- Storage_Count as its result type.
5589 if Op_Name
= Name_Storage_Size
then
5590 if Ekind
(Found_Op
) = E_Procedure
then
5592 ("% operation must be a function", Found_Op
);
5594 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
5596 ("wrong result type for%, expected type&",
5597 Found_Op
, Stg_Cnt_Type
);
5600 -- Allocate and Deallocate must be procedures
5602 elsif Ekind
(Found_Op
) = E_Function
then
5604 ("% operation must be a procedure", Found_Op
);
5607 end Validate_Simple_Pool_Operation
;
5609 -- Start of processing for Validate_Simple_Pool_Ops
5612 Validate_Simple_Pool_Operation
(Name_Allocate
);
5613 Validate_Simple_Pool_Operation
(Name_Deallocate
);
5614 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
5615 end Validate_Simple_Pool_Ops
;
5619 -- Now that all types from which E may depend are frozen, see if the
5620 -- size is known at compile time, if it must be unsigned, or if
5621 -- strict alignment is required
5623 Check_Compile_Time_Size
(E
);
5624 Check_Unsigned_Type
(E
);
5626 if Base_Type
(E
) = E
then
5627 Check_Strict_Alignment
(E
);
5630 -- Do not allow a size clause for a type which does not have a size
5631 -- that is known at compile time
5633 if Has_Size_Clause
(E
)
5634 and then not Size_Known_At_Compile_Time
(E
)
5636 -- Suppress this message if errors posted on E, even if we are
5637 -- in all errors mode, since this is often a junk message
5639 if not Error_Posted
(E
) then
5641 ("size clause not allowed for variable length type",
5646 -- Now we set/verify the representation information, in particular
5647 -- the size and alignment values. This processing is not required for
5648 -- generic types, since generic types do not play any part in code
5649 -- generation, and so the size and alignment values for such types
5650 -- are irrelevant. Ditto for types declared within a generic unit,
5651 -- which may have components that depend on generic parameters, and
5652 -- that will be recreated in an instance.
5654 if Inside_A_Generic
then
5657 -- Otherwise we call the layout procedure
5663 -- If this is an access to subprogram whose designated type is itself
5664 -- a subprogram type, the return type of this anonymous subprogram
5665 -- type must be decorated as well.
5667 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
5668 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
5670 Layout_Type
(Etype
(Designated_Type
(E
)));
5673 -- If the type has a Defaut_Value/Default_Component_Value aspect,
5674 -- this is where we analye the expression (after the type is frozen,
5675 -- since in the case of Default_Value, we are analyzing with the
5676 -- type itself, and we treat Default_Component_Value similarly for
5677 -- the sake of uniformity).
5679 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
5686 if Is_Scalar_Type
(E
) then
5687 Nam
:= Name_Default_Value
;
5689 Exp
:= Default_Aspect_Value
(Typ
);
5691 Nam
:= Name_Default_Component_Value
;
5692 Typ
:= Component_Type
(E
);
5693 Exp
:= Default_Aspect_Component_Value
(E
);
5696 Analyze_And_Resolve
(Exp
, Typ
);
5698 if Etype
(Exp
) /= Any_Type
then
5699 if not Is_OK_Static_Expression
(Exp
) then
5700 Error_Msg_Name_1
:= Nam
;
5701 Flag_Non_Static_Expr
5702 ("aspect% requires static expression", Exp
);
5708 -- End of freeze processing for type entities
5711 -- Here is where we logically freeze the current entity. If it has a
5712 -- freeze node, then this is the point at which the freeze node is
5713 -- linked into the result list.
5715 if Has_Delayed_Freeze
(E
) then
5717 -- If a freeze node is already allocated, use it, otherwise allocate
5718 -- a new one. The preallocation happens in the case of anonymous base
5719 -- types, where we preallocate so that we can set First_Subtype_Link.
5720 -- Note that we reset the Sloc to the current freeze location.
5722 if Present
(Freeze_Node
(E
)) then
5723 F_Node
:= Freeze_Node
(E
);
5724 Set_Sloc
(F_Node
, Loc
);
5727 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
5728 Set_Freeze_Node
(E
, F_Node
);
5729 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
5730 Set_TSS_Elist
(F_Node
, No_Elist
);
5731 Set_Actions
(F_Node
, No_List
);
5734 Set_Entity
(F_Node
, E
);
5735 Add_To_Result
(F_Node
);
5737 -- A final pass over record types with discriminants. If the type
5738 -- has an incomplete declaration, there may be constrained access
5739 -- subtypes declared elsewhere, which do not depend on the discrimi-
5740 -- nants of the type, and which are used as component types (i.e.
5741 -- the full view is a recursive type). The designated types of these
5742 -- subtypes can only be elaborated after the type itself, and they
5743 -- need an itype reference.
5745 if Ekind
(E
) = E_Record_Type
5746 and then Has_Discriminants
(E
)
5754 Comp
:= First_Component
(E
);
5755 while Present
(Comp
) loop
5756 Typ
:= Etype
(Comp
);
5758 if Ekind
(Comp
) = E_Component
5759 and then Is_Access_Type
(Typ
)
5760 and then Scope
(Typ
) /= E
5761 and then Base_Type
(Designated_Type
(Typ
)) = E
5762 and then Is_Itype
(Designated_Type
(Typ
))
5764 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
5765 Set_Itype
(IR
, Designated_Type
(Typ
));
5766 Append
(IR
, Result
);
5769 Next_Component
(Comp
);
5775 -- When a type is frozen, the first subtype of the type is frozen as
5776 -- well (RM 13.14(15)). This has to be done after freezing the type,
5777 -- since obviously the first subtype depends on its own base type.
5780 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
5782 -- If we just froze a tagged non-class wide record, then freeze the
5783 -- corresponding class-wide type. This must be done after the tagged
5784 -- type itself is frozen, because the class-wide type refers to the
5785 -- tagged type which generates the class.
5787 if Is_Tagged_Type
(E
)
5788 and then not Is_Class_Wide_Type
(E
)
5789 and then Present
(Class_Wide_Type
(E
))
5791 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
5795 Check_Debug_Info_Needed
(E
);
5797 -- Special handling for subprograms
5799 if Is_Subprogram
(E
) then
5801 -- If subprogram has address clause then reset Is_Public flag, since
5802 -- we do not want the backend to generate external references.
5804 if Present
(Address_Clause
(E
))
5805 and then not Is_Library_Level_Entity
(E
)
5807 Set_Is_Public
(E
, False);
5814 -----------------------------
5815 -- Freeze_Enumeration_Type --
5816 -----------------------------
5818 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
5820 -- By default, if no size clause is present, an enumeration type with
5821 -- Convention C is assumed to interface to a C enum, and has integer
5822 -- size. This applies to types. For subtypes, verify that its base
5823 -- type has no size clause either. Treat other foreign conventions
5824 -- in the same way, and also make sure alignment is set right.
5826 if Has_Foreign_Convention
(Typ
)
5827 and then not Has_Size_Clause
(Typ
)
5828 and then not Has_Size_Clause
(Base_Type
(Typ
))
5829 and then Esize
(Typ
) < Standard_Integer_Size
5831 -- Don't do this if Short_Enums on target
5833 and then not Target_Short_Enums
5835 Init_Esize
(Typ
, Standard_Integer_Size
);
5836 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
5838 -- Normal Ada case or size clause present or not Long_C_Enums on target
5841 -- If the enumeration type interfaces to C, and it has a size clause
5842 -- that specifies less than int size, it warrants a warning. The
5843 -- user may intend the C type to be an enum or a char, so this is
5844 -- not by itself an error that the Ada compiler can detect, but it
5845 -- it is a worth a heads-up. For Boolean and Character types we
5846 -- assume that the programmer has the proper C type in mind.
5848 if Convention
(Typ
) = Convention_C
5849 and then Has_Size_Clause
(Typ
)
5850 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
5851 and then not Is_Boolean_Type
(Typ
)
5852 and then not Is_Character_Type
(Typ
)
5854 -- Don't do this if Short_Enums on target
5856 and then not Target_Short_Enums
5859 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
5862 Adjust_Esize_For_Alignment
(Typ
);
5864 end Freeze_Enumeration_Type
;
5866 -----------------------
5867 -- Freeze_Expression --
5868 -----------------------
5870 procedure Freeze_Expression
(N
: Node_Id
) is
5871 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
5874 Desig_Typ
: Entity_Id
;
5878 Freeze_Outside
: Boolean := False;
5879 -- This flag is set true if the entity must be frozen outside the
5880 -- current subprogram. This happens in the case of expander generated
5881 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
5882 -- not freeze all entities like other bodies, but which nevertheless
5883 -- may reference entities that have to be frozen before the body and
5884 -- obviously cannot be frozen inside the body.
5886 function In_Exp_Body
(N
: Node_Id
) return Boolean;
5887 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
5888 -- it is the handled statement sequence of an expander-generated
5889 -- subprogram (init proc, stream subprogram, or renaming as body).
5890 -- If so, this is not a freezing context.
5896 function In_Exp_Body
(N
: Node_Id
) return Boolean is
5901 if Nkind
(N
) = N_Subprogram_Body
then
5907 if Nkind
(P
) /= N_Subprogram_Body
then
5911 Id
:= Defining_Unit_Name
(Specification
(P
));
5913 -- Following complex conditional could use comments ???
5915 if Nkind
(Id
) = N_Defining_Identifier
5916 and then (Is_Init_Proc
(Id
)
5917 or else Is_TSS
(Id
, TSS_Stream_Input
)
5918 or else Is_TSS
(Id
, TSS_Stream_Output
)
5919 or else Is_TSS
(Id
, TSS_Stream_Read
)
5920 or else Is_TSS
(Id
, TSS_Stream_Write
)
5921 or else Nkind_In
(Original_Node
(P
),
5922 N_Subprogram_Renaming_Declaration
,
5923 N_Expression_Function
))
5932 -- Start of processing for Freeze_Expression
5935 -- Immediate return if freezing is inhibited. This flag is set by the
5936 -- analyzer to stop freezing on generated expressions that would cause
5937 -- freezing if they were in the source program, but which are not
5938 -- supposed to freeze, since they are created.
5940 if Must_Not_Freeze
(N
) then
5944 -- If expression is non-static, then it does not freeze in a default
5945 -- expression, see section "Handling of Default Expressions" in the
5946 -- spec of package Sem for further details. Note that we have to make
5947 -- sure that we actually have a real expression (if we have a subtype
5948 -- indication, we can't test Is_OK_Static_Expression). However, we
5949 -- exclude the case of the prefix of an attribute of a static scalar
5950 -- subtype from this early return, because static subtype attributes
5951 -- should always cause freezing, even in default expressions, but
5952 -- the attribute may not have been marked as static yet (because in
5953 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
5954 -- Freeze_Expression on the prefix).
5957 and then Nkind
(N
) in N_Subexpr
5958 and then not Is_OK_Static_Expression
(N
)
5959 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
5960 or else not (Is_Entity_Name
(N
)
5961 and then Is_Type
(Entity
(N
))
5962 and then Is_OK_Static_Subtype
(Entity
(N
))))
5967 -- Freeze type of expression if not frozen already
5971 if Nkind
(N
) in N_Has_Etype
then
5972 if not Is_Frozen
(Etype
(N
)) then
5975 -- Base type may be an derived numeric type that is frozen at
5976 -- the point of declaration, but first_subtype is still unfrozen.
5978 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
5979 Typ
:= First_Subtype
(Etype
(N
));
5983 -- For entity name, freeze entity if not frozen already. A special
5984 -- exception occurs for an identifier that did not come from source.
5985 -- We don't let such identifiers freeze a non-internal entity, i.e.
5986 -- an entity that did come from source, since such an identifier was
5987 -- generated by the expander, and cannot have any semantic effect on
5988 -- the freezing semantics. For example, this stops the parameter of
5989 -- an initialization procedure from freezing the variable.
5991 if Is_Entity_Name
(N
)
5992 and then not Is_Frozen
(Entity
(N
))
5993 and then (Nkind
(N
) /= N_Identifier
5994 or else Comes_From_Source
(N
)
5995 or else not Comes_From_Source
(Entity
(N
)))
5999 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
6000 Check_Expression_Function
(N
, Nam
);
6007 -- For an allocator freeze designated type if not frozen already
6009 -- For an aggregate whose component type is an access type, freeze the
6010 -- designated type now, so that its freeze does not appear within the
6011 -- loop that might be created in the expansion of the aggregate. If the
6012 -- designated type is a private type without full view, the expression
6013 -- cannot contain an allocator, so the type is not frozen.
6015 -- For a function, we freeze the entity when the subprogram declaration
6016 -- is frozen, but a function call may appear in an initialization proc.
6017 -- before the declaration is frozen. We need to generate the extra
6018 -- formals, if any, to ensure that the expansion of the call includes
6019 -- the proper actuals. This only applies to Ada subprograms, not to
6026 Desig_Typ
:= Designated_Type
(Etype
(N
));
6029 if Is_Array_Type
(Etype
(N
))
6030 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
6032 Desig_Typ
:= Designated_Type
(Component_Type
(Etype
(N
)));
6035 when N_Selected_Component |
6036 N_Indexed_Component |
6039 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6040 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
6043 when N_Identifier
=>
6045 and then Ekind
(Nam
) = E_Function
6046 and then Nkind
(Parent
(N
)) = N_Function_Call
6047 and then Convention
(Nam
) = Convention_Ada
6049 Create_Extra_Formals
(Nam
);
6056 if Desig_Typ
/= Empty
6057 and then (Is_Frozen
(Desig_Typ
)
6058 or else (not Is_Fully_Defined
(Desig_Typ
)))
6063 -- All done if nothing needs freezing
6067 and then No
(Desig_Typ
)
6072 -- Examine the enclosing context by climbing the parent chain. The
6073 -- traversal serves two purposes - to detect scenarios where freezeing
6074 -- is not needed and to find the proper insertion point for the freeze
6075 -- nodes. Although somewhat similar to Insert_Actions, this traversal
6076 -- is freezing semantics-sensitive. Inserting freeze nodes blindly in
6077 -- the tree may result in types being frozen too early.
6081 Parent_P
:= Parent
(P
);
6083 -- If we don't have a parent, then we are not in a well-formed tree.
6084 -- This is an unusual case, but there are some legitimate situations
6085 -- in which this occurs, notably when the expressions in the range of
6086 -- a type declaration are resolved. We simply ignore the freeze
6087 -- request in this case. Is this right ???
6089 if No
(Parent_P
) then
6093 -- See if we have got to an appropriate point in the tree
6095 case Nkind
(Parent_P
) is
6097 -- A special test for the exception of (RM 13.14(8)) for the case
6098 -- of per-object expressions (RM 3.8(18)) occurring in component
6099 -- definition or a discrete subtype definition. Note that we test
6100 -- for a component declaration which includes both cases we are
6101 -- interested in, and furthermore the tree does not have explicit
6102 -- nodes for either of these two constructs.
6104 when N_Component_Declaration
=>
6106 -- The case we want to test for here is an identifier that is
6107 -- a per-object expression, this is either a discriminant that
6108 -- appears in a context other than the component declaration
6109 -- or it is a reference to the type of the enclosing construct.
6111 -- For either of these cases, we skip the freezing
6113 if not In_Spec_Expression
6114 and then Nkind
(N
) = N_Identifier
6115 and then (Present
(Entity
(N
)))
6117 -- We recognize the discriminant case by just looking for
6118 -- a reference to a discriminant. It can only be one for
6119 -- the enclosing construct. Skip freezing in this case.
6121 if Ekind
(Entity
(N
)) = E_Discriminant
then
6124 -- For the case of a reference to the enclosing record,
6125 -- (or task or protected type), we look for a type that
6126 -- matches the current scope.
6128 elsif Entity
(N
) = Current_Scope
then
6133 -- If we have an enumeration literal that appears as the choice in
6134 -- the aggregate of an enumeration representation clause, then
6135 -- freezing does not occur (RM 13.14(10)).
6137 when N_Enumeration_Representation_Clause
=>
6139 -- The case we are looking for is an enumeration literal
6141 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
6142 and then Is_Enumeration_Type
(Etype
(N
))
6144 -- If enumeration literal appears directly as the choice,
6145 -- do not freeze (this is the normal non-overloaded case)
6147 if Nkind
(Parent
(N
)) = N_Component_Association
6148 and then First
(Choices
(Parent
(N
))) = N
6152 -- If enumeration literal appears as the name of function
6153 -- which is the choice, then also do not freeze. This
6154 -- happens in the overloaded literal case, where the
6155 -- enumeration literal is temporarily changed to a function
6156 -- call for overloading analysis purposes.
6158 elsif Nkind
(Parent
(N
)) = N_Function_Call
6160 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
6162 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
6168 -- Normally if the parent is a handled sequence of statements,
6169 -- then the current node must be a statement, and that is an
6170 -- appropriate place to insert a freeze node.
6172 when N_Handled_Sequence_Of_Statements
=>
6174 -- An exception occurs when the sequence of statements is for
6175 -- an expander generated body that did not do the usual freeze
6176 -- all operation. In this case we usually want to freeze
6177 -- outside this body, not inside it, and we skip past the
6178 -- subprogram body that we are inside.
6180 if In_Exp_Body
(Parent_P
) then
6182 Subp
: constant Node_Id
:= Parent
(Parent_P
);
6186 -- Freeze the entity only when it is declared inside the
6187 -- body of the expander generated procedure. This case
6188 -- is recognized by the scope of the entity or its type,
6189 -- which is either the spec for some enclosing body, or
6190 -- (in the case of init_procs, for which there are no
6191 -- separate specs) the current scope.
6193 if Nkind
(Subp
) = N_Subprogram_Body
then
6194 Spec
:= Corresponding_Spec
(Subp
);
6196 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
6198 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
6203 and then Scope
(Typ
) = Current_Scope
6204 and then Defining_Entity
(Subp
) = Current_Scope
6210 -- An expression function may act as a completion of
6211 -- a function declaration. As such, it can reference
6212 -- entities declared between the two views:
6215 -- function F return ...;
6217 -- function Hidden return ...;
6218 -- function F return ... is (Hidden); -- 2
6220 -- Refering to the example above, freezing the expression
6221 -- of F (2) would place Hidden's freeze node (1) in the
6222 -- wrong place. Avoid explicit freezing and let the usual
6223 -- scenarios do the job - for example, reaching the end
6224 -- of the private declarations.
6226 if Nkind
(Original_Node
(Subp
)) =
6227 N_Expression_Function
6231 -- Freeze outside the body
6234 Parent_P
:= Parent
(Parent_P
);
6235 Freeze_Outside
:= True;
6239 -- Here if normal case where we are in handled statement
6240 -- sequence and want to do the insertion right there.
6246 -- If parent is a body or a spec or a block, then the current node
6247 -- is a statement or declaration and we can insert the freeze node
6250 when N_Block_Statement |
6253 N_Package_Specification |
6256 N_Task_Body
=> exit;
6258 -- The expander is allowed to define types in any statements list,
6259 -- so any of the following parent nodes also mark a freezing point
6260 -- if the actual node is in a list of statements or declarations.
6262 when N_Abortable_Part |
6263 N_Accept_Alternative |
6265 N_Case_Statement_Alternative |
6266 N_Compilation_Unit_Aux |
6267 N_Conditional_Entry_Call |
6268 N_Delay_Alternative |
6270 N_Entry_Call_Alternative |
6271 N_Exception_Handler |
6272 N_Extended_Return_Statement |
6276 N_Selective_Accept |
6277 N_Triggering_Alternative
=>
6279 exit when Is_List_Member
(P
);
6281 -- Freeze nodes produced by an expression coming from the Actions
6282 -- list of a N_Expression_With_Actions node must remain within the
6283 -- Actions list. Inserting the freeze nodes further up the tree
6284 -- may lead to use before declaration issues in the case of array
6287 when N_Expression_With_Actions
=>
6288 if Is_List_Member
(P
)
6289 and then List_Containing
(P
) = Actions
(Parent_P
)
6294 -- Note: N_Loop_Statement is a special case. A type that appears
6295 -- in the source can never be frozen in a loop (this occurs only
6296 -- because of a loop expanded by the expander), so we keep on
6297 -- going. Otherwise we terminate the search. Same is true of any
6298 -- entity which comes from source. (if they have predefined type,
6299 -- that type does not appear to come from source, but the entity
6300 -- should not be frozen here).
6302 when N_Loop_Statement
=>
6303 exit when not Comes_From_Source
(Etype
(N
))
6304 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
6306 -- For all other cases, keep looking at parents
6312 -- We fall through the case if we did not yet find the proper
6313 -- place in the free for inserting the freeze node, so climb.
6318 -- If the expression appears in a record or an initialization procedure,
6319 -- the freeze nodes are collected and attached to the current scope, to
6320 -- be inserted and analyzed on exit from the scope, to insure that
6321 -- generated entities appear in the correct scope. If the expression is
6322 -- a default for a discriminant specification, the scope is still void.
6323 -- The expression can also appear in the discriminant part of a private
6324 -- or concurrent type.
6326 -- If the expression appears in a constrained subcomponent of an
6327 -- enclosing record declaration, the freeze nodes must be attached to
6328 -- the outer record type so they can eventually be placed in the
6329 -- enclosing declaration list.
6331 -- The other case requiring this special handling is if we are in a
6332 -- default expression, since in that case we are about to freeze a
6333 -- static type, and the freeze scope needs to be the outer scope, not
6334 -- the scope of the subprogram with the default parameter.
6336 -- For default expressions and other spec expressions in generic units,
6337 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
6338 -- placing them at the proper place, after the generic unit.
6340 if (In_Spec_Exp
and not Inside_A_Generic
)
6341 or else Freeze_Outside
6342 or else (Is_Type
(Current_Scope
)
6343 and then (not Is_Concurrent_Type
(Current_Scope
)
6344 or else not Has_Completion
(Current_Scope
)))
6345 or else Ekind
(Current_Scope
) = E_Void
6348 N
: constant Node_Id
:= Current_Scope
;
6349 Freeze_Nodes
: List_Id
:= No_List
;
6350 Pos
: Int
:= Scope_Stack
.Last
;
6353 if Present
(Desig_Typ
) then
6354 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
6357 if Present
(Typ
) then
6358 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
6361 if Present
(Nam
) then
6362 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
6365 -- The current scope may be that of a constrained component of
6366 -- an enclosing record declaration, or of a loop of an enclosing
6367 -- quantified expression, which is above the current scope in the
6368 -- scope stack. Indeed in the context of a quantified expression,
6369 -- a scope is created and pushed above the current scope in order
6370 -- to emulate the loop-like behavior of the quantified expression.
6371 -- If the expression is within a top-level pragma, as for a pre-
6372 -- condition on a library-level subprogram, nothing to do.
6374 if not Is_Compilation_Unit
(Current_Scope
)
6375 and then (Is_Record_Type
(Scope
(Current_Scope
))
6376 or else Nkind
(Parent
(Current_Scope
)) =
6377 N_Quantified_Expression
)
6382 if Is_Non_Empty_List
(Freeze_Nodes
) then
6383 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
6384 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
6387 Append_List
(Freeze_Nodes
,
6388 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
6396 -- Now we have the right place to do the freezing. First, a special
6397 -- adjustment, if we are in spec-expression analysis mode, these freeze
6398 -- actions must not be thrown away (normally all inserted actions are
6399 -- thrown away in this mode. However, the freeze actions are from static
6400 -- expressions and one of the important reasons we are doing this
6401 -- special analysis is to get these freeze actions. Therefore we turn
6402 -- off the In_Spec_Expression mode to propagate these freeze actions.
6403 -- This also means they get properly analyzed and expanded.
6405 In_Spec_Expression
:= False;
6407 -- Freeze the designated type of an allocator (RM 13.14(13))
6409 if Present
(Desig_Typ
) then
6410 Freeze_Before
(P
, Desig_Typ
);
6413 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
6414 -- the enumeration representation clause exception in the loop above.
6416 if Present
(Typ
) then
6417 Freeze_Before
(P
, Typ
);
6420 -- Freeze name if one is present (RM 13.14(11))
6422 if Present
(Nam
) then
6423 Freeze_Before
(P
, Nam
);
6426 -- Restore In_Spec_Expression flag
6428 In_Spec_Expression
:= In_Spec_Exp
;
6429 end Freeze_Expression
;
6431 -----------------------------
6432 -- Freeze_Fixed_Point_Type --
6433 -----------------------------
6435 -- Certain fixed-point types and subtypes, including implicit base types
6436 -- and declared first subtypes, have not yet set up a range. This is
6437 -- because the range cannot be set until the Small and Size values are
6438 -- known, and these are not known till the type is frozen.
6440 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
6441 -- whose bounds are unanalyzed real literals. This routine will recognize
6442 -- this case, and transform this range node into a properly typed range
6443 -- with properly analyzed and resolved values.
6445 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
6446 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
6447 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
6448 Hi
: constant Node_Id
:= High_Bound
(Rng
);
6449 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6450 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
6451 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
6452 BHi
: constant Node_Id
:= High_Bound
(Brng
);
6453 Small
: constant Ureal
:= Small_Value
(Typ
);
6460 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
6461 -- Returns size of type with given bounds. Also leaves these
6462 -- bounds set as the current bounds of the Typ.
6468 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
6470 Set_Realval
(Lo
, Lov
);
6471 Set_Realval
(Hi
, Hiv
);
6472 return Minimum_Size
(Typ
);
6475 -- Start of processing for Freeze_Fixed_Point_Type
6478 -- If Esize of a subtype has not previously been set, set it now
6480 if Unknown_Esize
(Typ
) then
6481 Atype
:= Ancestor_Subtype
(Typ
);
6483 if Present
(Atype
) then
6484 Set_Esize
(Typ
, Esize
(Atype
));
6486 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
6490 -- Immediate return if the range is already analyzed. This means that
6491 -- the range is already set, and does not need to be computed by this
6494 if Analyzed
(Rng
) then
6498 -- Immediate return if either of the bounds raises Constraint_Error
6500 if Raises_Constraint_Error
(Lo
)
6501 or else Raises_Constraint_Error
(Hi
)
6506 Loval
:= Realval
(Lo
);
6507 Hival
:= Realval
(Hi
);
6509 -- Ordinary fixed-point case
6511 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
6513 -- For the ordinary fixed-point case, we are allowed to fudge the
6514 -- end-points up or down by small. Generally we prefer to fudge up,
6515 -- i.e. widen the bounds for non-model numbers so that the end points
6516 -- are included. However there are cases in which this cannot be
6517 -- done, and indeed cases in which we may need to narrow the bounds.
6518 -- The following circuit makes the decision.
6520 -- Note: our terminology here is that Incl_EP means that the bounds
6521 -- are widened by Small if necessary to include the end points, and
6522 -- Excl_EP means that the bounds are narrowed by Small to exclude the
6523 -- end-points if this reduces the size.
6525 -- Note that in the Incl case, all we care about is including the
6526 -- end-points. In the Excl case, we want to narrow the bounds as
6527 -- much as permitted by the RM, to give the smallest possible size.
6530 Loval_Incl_EP
: Ureal
;
6531 Hival_Incl_EP
: Ureal
;
6533 Loval_Excl_EP
: Ureal
;
6534 Hival_Excl_EP
: Ureal
;
6540 First_Subt
: Entity_Id
;
6545 -- First step. Base types are required to be symmetrical. Right
6546 -- now, the base type range is a copy of the first subtype range.
6547 -- This will be corrected before we are done, but right away we
6548 -- need to deal with the case where both bounds are non-negative.
6549 -- In this case, we set the low bound to the negative of the high
6550 -- bound, to make sure that the size is computed to include the
6551 -- required sign. Note that we do not need to worry about the
6552 -- case of both bounds negative, because the sign will be dealt
6553 -- with anyway. Furthermore we can't just go making such a bound
6554 -- symmetrical, since in a twos-complement system, there is an
6555 -- extra negative value which could not be accommodated on the
6559 and then not UR_Is_Negative
(Loval
)
6560 and then Hival
> Loval
6563 Set_Realval
(Lo
, Loval
);
6566 -- Compute the fudged bounds. If the number is a model number,
6567 -- then we do nothing to include it, but we are allowed to backoff
6568 -- to the next adjacent model number when we exclude it. If it is
6569 -- not a model number then we straddle the two values with the
6570 -- model numbers on either side.
6572 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
6574 if Loval
= Model_Num
then
6575 Loval_Incl_EP
:= Model_Num
;
6577 Loval_Incl_EP
:= Model_Num
- Small
;
6580 -- The low value excluding the end point is Small greater, but
6581 -- we do not do this exclusion if the low value is positive,
6582 -- since it can't help the size and could actually hurt by
6583 -- crossing the high bound.
6585 if UR_Is_Negative
(Loval_Incl_EP
) then
6586 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
6588 -- If the value went from negative to zero, then we have the
6589 -- case where Loval_Incl_EP is the model number just below
6590 -- zero, so we want to stick to the negative value for the
6591 -- base type to maintain the condition that the size will
6592 -- include signed values.
6595 and then UR_Is_Zero
(Loval_Excl_EP
)
6597 Loval_Excl_EP
:= Loval_Incl_EP
;
6601 Loval_Excl_EP
:= Loval_Incl_EP
;
6604 -- Similar processing for upper bound and high value
6606 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
6608 if Hival
= Model_Num
then
6609 Hival_Incl_EP
:= Model_Num
;
6611 Hival_Incl_EP
:= Model_Num
+ Small
;
6614 if UR_Is_Positive
(Hival_Incl_EP
) then
6615 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
6617 Hival_Excl_EP
:= Hival_Incl_EP
;
6620 -- One further adjustment is needed. In the case of subtypes, we
6621 -- cannot go outside the range of the base type, or we get
6622 -- peculiarities, and the base type range is already set. This
6623 -- only applies to the Incl values, since clearly the Excl values
6624 -- are already as restricted as they are allowed to be.
6627 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
6628 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
6631 -- Get size including and excluding end points
6633 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
6634 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
6636 -- No need to exclude end-points if it does not reduce size
6638 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
6639 Loval_Excl_EP
:= Loval_Incl_EP
;
6642 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
6643 Hival_Excl_EP
:= Hival_Incl_EP
;
6646 -- Now we set the actual size to be used. We want to use the
6647 -- bounds fudged up to include the end-points but only if this
6648 -- can be done without violating a specifically given size
6649 -- size clause or causing an unacceptable increase in size.
6651 -- Case of size clause given
6653 if Has_Size_Clause
(Typ
) then
6655 -- Use the inclusive size only if it is consistent with
6656 -- the explicitly specified size.
6658 if Size_Incl_EP
<= RM_Size
(Typ
) then
6659 Actual_Lo
:= Loval_Incl_EP
;
6660 Actual_Hi
:= Hival_Incl_EP
;
6661 Actual_Size
:= Size_Incl_EP
;
6663 -- If the inclusive size is too large, we try excluding
6664 -- the end-points (will be caught later if does not work).
6667 Actual_Lo
:= Loval_Excl_EP
;
6668 Actual_Hi
:= Hival_Excl_EP
;
6669 Actual_Size
:= Size_Excl_EP
;
6672 -- Case of size clause not given
6675 -- If we have a base type whose corresponding first subtype
6676 -- has an explicit size that is large enough to include our
6677 -- end-points, then do so. There is no point in working hard
6678 -- to get a base type whose size is smaller than the specified
6679 -- size of the first subtype.
6681 First_Subt
:= First_Subtype
(Typ
);
6683 if Has_Size_Clause
(First_Subt
)
6684 and then Size_Incl_EP
<= Esize
(First_Subt
)
6686 Actual_Size
:= Size_Incl_EP
;
6687 Actual_Lo
:= Loval_Incl_EP
;
6688 Actual_Hi
:= Hival_Incl_EP
;
6690 -- If excluding the end-points makes the size smaller and
6691 -- results in a size of 8,16,32,64, then we take the smaller
6692 -- size. For the 64 case, this is compulsory. For the other
6693 -- cases, it seems reasonable. We like to include end points
6694 -- if we can, but not at the expense of moving to the next
6695 -- natural boundary of size.
6697 elsif Size_Incl_EP
/= Size_Excl_EP
6698 and then Addressable
(Size_Excl_EP
)
6700 Actual_Size
:= Size_Excl_EP
;
6701 Actual_Lo
:= Loval_Excl_EP
;
6702 Actual_Hi
:= Hival_Excl_EP
;
6704 -- Otherwise we can definitely include the end points
6707 Actual_Size
:= Size_Incl_EP
;
6708 Actual_Lo
:= Loval_Incl_EP
;
6709 Actual_Hi
:= Hival_Incl_EP
;
6712 -- One pathological case: normally we never fudge a low bound
6713 -- down, since it would seem to increase the size (if it has
6714 -- any effect), but for ranges containing single value, or no
6715 -- values, the high bound can be small too large. Consider:
6717 -- type t is delta 2.0**(-14)
6718 -- range 131072.0 .. 0;
6720 -- That lower bound is *just* outside the range of 32 bits, and
6721 -- does need fudging down in this case. Note that the bounds
6722 -- will always have crossed here, since the high bound will be
6723 -- fudged down if necessary, as in the case of:
6725 -- type t is delta 2.0**(-14)
6726 -- range 131072.0 .. 131072.0;
6728 -- So we detect the situation by looking for crossed bounds,
6729 -- and if the bounds are crossed, and the low bound is greater
6730 -- than zero, we will always back it off by small, since this
6731 -- is completely harmless.
6733 if Actual_Lo
> Actual_Hi
then
6734 if UR_Is_Positive
(Actual_Lo
) then
6735 Actual_Lo
:= Loval_Incl_EP
- Small
;
6736 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
6738 -- And of course, we need to do exactly the same parallel
6739 -- fudge for flat ranges in the negative region.
6741 elsif UR_Is_Negative
(Actual_Hi
) then
6742 Actual_Hi
:= Hival_Incl_EP
+ Small
;
6743 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
6748 Set_Realval
(Lo
, Actual_Lo
);
6749 Set_Realval
(Hi
, Actual_Hi
);
6752 -- For the decimal case, none of this fudging is required, since there
6753 -- are no end-point problems in the decimal case (the end-points are
6754 -- always included).
6757 Actual_Size
:= Fsize
(Loval
, Hival
);
6760 -- At this stage, the actual size has been calculated and the proper
6761 -- required bounds are stored in the low and high bounds.
6763 if Actual_Size
> 64 then
6764 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
6766 ("size required (^) for type& too large, maximum allowed is 64",
6771 -- Check size against explicit given size
6773 if Has_Size_Clause
(Typ
) then
6774 if Actual_Size
> RM_Size
(Typ
) then
6775 Error_Msg_Uint_1
:= RM_Size
(Typ
);
6776 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
6778 ("size given (^) for type& too small, minimum allowed is ^",
6779 Size_Clause
(Typ
), Typ
);
6782 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
6785 -- Increase size to next natural boundary if no size clause given
6788 if Actual_Size
<= 8 then
6790 elsif Actual_Size
<= 16 then
6792 elsif Actual_Size
<= 32 then
6798 Init_Esize
(Typ
, Actual_Size
);
6799 Adjust_Esize_For_Alignment
(Typ
);
6802 -- If we have a base type, then expand the bounds so that they extend to
6803 -- the full width of the allocated size in bits, to avoid junk range
6804 -- checks on intermediate computations.
6806 if Base_Type
(Typ
) = Typ
then
6807 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
6808 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
6811 -- Final step is to reanalyze the bounds using the proper type
6812 -- and set the Corresponding_Integer_Value fields of the literals.
6814 Set_Etype
(Lo
, Empty
);
6815 Set_Analyzed
(Lo
, False);
6818 -- Resolve with universal fixed if the base type, and the base type if
6819 -- it is a subtype. Note we can't resolve the base type with itself,
6820 -- that would be a reference before definition.
6823 Resolve
(Lo
, Universal_Fixed
);
6828 -- Set corresponding integer value for bound
6830 Set_Corresponding_Integer_Value
6831 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
6833 -- Similar processing for high bound
6835 Set_Etype
(Hi
, Empty
);
6836 Set_Analyzed
(Hi
, False);
6840 Resolve
(Hi
, Universal_Fixed
);
6845 Set_Corresponding_Integer_Value
6846 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
6848 -- Set type of range to correspond to bounds
6850 Set_Etype
(Rng
, Etype
(Lo
));
6852 -- Set Esize to calculated size if not set already
6854 if Unknown_Esize
(Typ
) then
6855 Init_Esize
(Typ
, Actual_Size
);
6858 -- Set RM_Size if not already set. If already set, check value
6861 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
6864 if RM_Size
(Typ
) /= Uint_0
then
6865 if RM_Size
(Typ
) < Minsiz
then
6866 Error_Msg_Uint_1
:= RM_Size
(Typ
);
6867 Error_Msg_Uint_2
:= Minsiz
;
6869 ("size given (^) for type& too small, minimum allowed is ^",
6870 Size_Clause
(Typ
), Typ
);
6874 Set_RM_Size
(Typ
, Minsiz
);
6877 end Freeze_Fixed_Point_Type
;
6883 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
6887 Set_Has_Delayed_Freeze
(T
);
6888 L
:= Freeze_Entity
(T
, N
);
6890 if Is_Non_Empty_List
(L
) then
6891 Insert_Actions
(N
, L
);
6895 --------------------------
6896 -- Freeze_Static_Object --
6897 --------------------------
6899 procedure Freeze_Static_Object
(E
: Entity_Id
) is
6901 Cannot_Be_Static
: exception;
6902 -- Exception raised if the type of a static object cannot be made
6903 -- static. This happens if the type depends on non-global objects.
6905 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
6906 -- Called to ensure that an expression used as part of a type definition
6907 -- is statically allocatable, which means that the expression type is
6908 -- statically allocatable, and the expression is either static, or a
6909 -- reference to a library level constant.
6911 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
6912 -- Called to mark a type as static, checking that it is possible
6913 -- to set the type as static. If it is not possible, then the
6914 -- exception Cannot_Be_Static is raised.
6916 -----------------------------
6917 -- Ensure_Expression_Is_SA --
6918 -----------------------------
6920 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
6924 Ensure_Type_Is_SA
(Etype
(N
));
6926 if Is_OK_Static_Expression
(N
) then
6929 elsif Nkind
(N
) = N_Identifier
then
6933 and then Ekind
(Ent
) = E_Constant
6934 and then Is_Library_Level_Entity
(Ent
)
6940 raise Cannot_Be_Static
;
6941 end Ensure_Expression_Is_SA
;
6943 -----------------------
6944 -- Ensure_Type_Is_SA --
6945 -----------------------
6947 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
6952 -- If type is library level, we are all set
6954 if Is_Library_Level_Entity
(Typ
) then
6958 -- We are also OK if the type already marked as statically allocated,
6959 -- which means we processed it before.
6961 if Is_Statically_Allocated
(Typ
) then
6965 -- Mark type as statically allocated
6967 Set_Is_Statically_Allocated
(Typ
);
6969 -- Check that it is safe to statically allocate this type
6971 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
6972 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
6973 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
6975 elsif Is_Array_Type
(Typ
) then
6976 N
:= First_Index
(Typ
);
6977 while Present
(N
) loop
6978 Ensure_Type_Is_SA
(Etype
(N
));
6982 Ensure_Type_Is_SA
(Component_Type
(Typ
));
6984 elsif Is_Access_Type
(Typ
) then
6985 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
6989 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
6992 if T
/= Standard_Void_Type
then
6993 Ensure_Type_Is_SA
(T
);
6996 F
:= First_Formal
(Designated_Type
(Typ
));
6997 while Present
(F
) loop
6998 Ensure_Type_Is_SA
(Etype
(F
));
7004 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
7007 elsif Is_Record_Type
(Typ
) then
7008 C
:= First_Entity
(Typ
);
7009 while Present
(C
) loop
7010 if Ekind
(C
) = E_Discriminant
7011 or else Ekind
(C
) = E_Component
7013 Ensure_Type_Is_SA
(Etype
(C
));
7015 elsif Is_Type
(C
) then
7016 Ensure_Type_Is_SA
(C
);
7022 elsif Ekind
(Typ
) = E_Subprogram_Type
then
7023 Ensure_Type_Is_SA
(Etype
(Typ
));
7025 C
:= First_Formal
(Typ
);
7026 while Present
(C
) loop
7027 Ensure_Type_Is_SA
(Etype
(C
));
7032 raise Cannot_Be_Static
;
7034 end Ensure_Type_Is_SA
;
7036 -- Start of processing for Freeze_Static_Object
7039 Ensure_Type_Is_SA
(Etype
(E
));
7042 when Cannot_Be_Static
=>
7044 -- If the object that cannot be static is imported or exported, then
7045 -- issue an error message saying that this object cannot be imported
7046 -- or exported. If it has an address clause it is an overlay in the
7047 -- current partition and the static requirement is not relevant.
7048 -- Do not issue any error message when ignoring rep clauses.
7050 if Ignore_Rep_Clauses
then
7053 elsif Is_Imported
(E
) then
7054 if No
(Address_Clause
(E
)) then
7056 ("& cannot be imported (local type is not constant)", E
);
7059 -- Otherwise must be exported, something is wrong if compiler
7060 -- is marking something as statically allocated which cannot be).
7062 else pragma Assert
(Is_Exported
(E
));
7064 ("& cannot be exported (local type is not constant)", E
);
7066 end Freeze_Static_Object
;
7068 -----------------------
7069 -- Freeze_Subprogram --
7070 -----------------------
7072 procedure Freeze_Subprogram
(E
: Entity_Id
) is
7077 -- Subprogram may not have an address clause unless it is imported
7079 if Present
(Address_Clause
(E
)) then
7080 if not Is_Imported
(E
) then
7082 ("address clause can only be given " &
7083 "for imported subprogram",
7084 Name
(Address_Clause
(E
)));
7088 -- Reset the Pure indication on an imported subprogram unless an
7089 -- explicit Pure_Function pragma was present or the subprogram is an
7090 -- intrinsic. We do this because otherwise it is an insidious error
7091 -- to call a non-pure function from pure unit and have calls
7092 -- mysteriously optimized away. What happens here is that the Import
7093 -- can bypass the normal check to ensure that pure units call only pure
7096 -- The reason for the intrinsic exception is that in general, intrinsic
7097 -- functions (such as shifts) are pure anyway. The only exceptions are
7098 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
7099 -- in any case, so no problem arises.
7102 and then Is_Pure
(E
)
7103 and then not Has_Pragma_Pure_Function
(E
)
7104 and then not Is_Intrinsic_Subprogram
(E
)
7106 Set_Is_Pure
(E
, False);
7109 -- For non-foreign convention subprograms, this is where we create
7110 -- the extra formals (for accessibility level and constrained bit
7111 -- information). We delay this till the freeze point precisely so
7112 -- that we know the convention.
7114 if not Has_Foreign_Convention
(E
) then
7115 Create_Extra_Formals
(E
);
7118 -- If this is convention Ada and a Valued_Procedure, that's odd
7120 if Ekind
(E
) = E_Procedure
7121 and then Is_Valued_Procedure
(E
)
7122 and then Convention
(E
) = Convention_Ada
7123 and then Warn_On_Export_Import
7126 ("??Valued_Procedure has no effect for convention Ada", E
);
7127 Set_Is_Valued_Procedure
(E
, False);
7130 -- Case of foreign convention
7135 -- For foreign conventions, warn about return of unconstrained array
7137 if Ekind
(E
) = E_Function
then
7138 Retype
:= Underlying_Type
(Etype
(E
));
7140 -- If no return type, probably some other error, e.g. a
7141 -- missing full declaration, so ignore.
7146 -- If the return type is generic, we have emitted a warning
7147 -- earlier on, and there is nothing else to check here. Specific
7148 -- instantiations may lead to erroneous behavior.
7150 elsif Is_Generic_Type
(Etype
(E
)) then
7153 -- Display warning if returning unconstrained array
7155 elsif Is_Array_Type
(Retype
)
7156 and then not Is_Constrained
(Retype
)
7158 -- Check appropriate warning is enabled (should we check for
7159 -- Warnings (Off) on specific entities here, probably so???)
7161 and then Warn_On_Export_Import
7163 -- Exclude the VM case, since return of unconstrained arrays
7164 -- is properly handled in both the JVM and .NET cases.
7166 and then VM_Target
= No_VM
7169 ("?x?foreign convention function& should not return " &
7170 "unconstrained array", E
);
7175 -- If any of the formals for an exported foreign convention
7176 -- subprogram have defaults, then emit an appropriate warning since
7177 -- this is odd (default cannot be used from non-Ada code)
7179 if Is_Exported
(E
) then
7180 F
:= First_Formal
(E
);
7181 while Present
(F
) loop
7182 if Warn_On_Export_Import
7183 and then Present
(Default_Value
(F
))
7186 ("?x?parameter cannot be defaulted in non-Ada call",
7195 -- Pragma Inline_Always is disallowed for dispatching subprograms
7196 -- because the address of such subprograms is saved in the dispatch
7197 -- table to support dispatching calls, and dispatching calls cannot
7198 -- be inlined. This is consistent with the restriction against using
7199 -- 'Access or 'Address on an Inline_Always subprogram.
7201 if Is_Dispatching_Operation
(E
)
7202 and then Has_Pragma_Inline_Always
(E
)
7205 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
7208 -- Because of the implicit representation of inherited predefined
7209 -- operators in the front-end, the overriding status of the operation
7210 -- may be affected when a full view of a type is analyzed, and this is
7211 -- not captured by the analysis of the corresponding type declaration.
7212 -- Therefore the correctness of a not-overriding indicator must be
7213 -- rechecked when the subprogram is frozen.
7215 if Nkind
(E
) = N_Defining_Operator_Symbol
7216 and then not Error_Posted
(Parent
(E
))
7218 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
7220 end Freeze_Subprogram
;
7222 ----------------------
7223 -- Is_Fully_Defined --
7224 ----------------------
7226 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
7228 if Ekind
(T
) = E_Class_Wide_Type
then
7229 return Is_Fully_Defined
(Etype
(T
));
7231 elsif Is_Array_Type
(T
) then
7232 return Is_Fully_Defined
(Component_Type
(T
));
7234 elsif Is_Record_Type
(T
)
7235 and not Is_Private_Type
(T
)
7237 -- Verify that the record type has no components with private types
7238 -- without completion.
7244 Comp
:= First_Component
(T
);
7245 while Present
(Comp
) loop
7246 if not Is_Fully_Defined
(Etype
(Comp
)) then
7250 Next_Component
(Comp
);
7255 -- For the designated type of an access to subprogram, all types in
7256 -- the profile must be fully defined.
7258 elsif Ekind
(T
) = E_Subprogram_Type
then
7263 F
:= First_Formal
(T
);
7264 while Present
(F
) loop
7265 if not Is_Fully_Defined
(Etype
(F
)) then
7272 return Is_Fully_Defined
(Etype
(T
));
7276 return not Is_Private_Type
(T
)
7277 or else Present
(Full_View
(Base_Type
(T
)));
7279 end Is_Fully_Defined
;
7281 ---------------------------------
7282 -- Process_Default_Expressions --
7283 ---------------------------------
7285 procedure Process_Default_Expressions
7287 After
: in out Node_Id
)
7289 Loc
: constant Source_Ptr
:= Sloc
(E
);
7296 Set_Default_Expressions_Processed
(E
);
7298 -- A subprogram instance and its associated anonymous subprogram share
7299 -- their signature. The default expression functions are defined in the
7300 -- wrapper packages for the anonymous subprogram, and should not be
7301 -- generated again for the instance.
7303 if Is_Generic_Instance
(E
)
7304 and then Present
(Alias
(E
))
7305 and then Default_Expressions_Processed
(Alias
(E
))
7310 Formal
:= First_Formal
(E
);
7311 while Present
(Formal
) loop
7312 if Present
(Default_Value
(Formal
)) then
7314 -- We work with a copy of the default expression because we
7315 -- do not want to disturb the original, since this would mess
7316 -- up the conformance checking.
7318 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
7320 -- The analysis of the expression may generate insert actions,
7321 -- which of course must not be executed. We wrap those actions
7322 -- in a procedure that is not called, and later on eliminated.
7323 -- The following cases have no side-effects, and are analyzed
7326 if Nkind
(Dcopy
) = N_Identifier
7327 or else Nkind_In
(Dcopy
, N_Expanded_Name
,
7329 N_Character_Literal
,
7332 or else (Nkind
(Dcopy
) = N_Attribute_Reference
7333 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
7334 or else Known_Null
(Dcopy
)
7336 -- If there is no default function, we must still do a full
7337 -- analyze call on the default value, to ensure that all error
7338 -- checks are performed, e.g. those associated with static
7339 -- evaluation. Note: this branch will always be taken if the
7340 -- analyzer is turned off (but we still need the error checks).
7342 -- Note: the setting of parent here is to meet the requirement
7343 -- that we can only analyze the expression while attached to
7344 -- the tree. Really the requirement is that the parent chain
7345 -- be set, we don't actually need to be in the tree.
7347 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
7350 -- Default expressions are resolved with their own type if the
7351 -- context is generic, to avoid anomalies with private types.
7353 if Ekind
(Scope
(E
)) = E_Generic_Package
then
7356 Resolve
(Dcopy
, Etype
(Formal
));
7359 -- If that resolved expression will raise constraint error,
7360 -- then flag the default value as raising constraint error.
7361 -- This allows a proper error message on the calls.
7363 if Raises_Constraint_Error
(Dcopy
) then
7364 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
7367 -- If the default is a parameterless call, we use the name of
7368 -- the called function directly, and there is no body to build.
7370 elsif Nkind
(Dcopy
) = N_Function_Call
7371 and then No
(Parameter_Associations
(Dcopy
))
7375 -- Else construct and analyze the body of a wrapper procedure
7376 -- that contains an object declaration to hold the expression.
7377 -- Given that this is done only to complete the analysis, it
7378 -- simpler to build a procedure than a function which might
7379 -- involve secondary stack expansion.
7382 Dnam
:= Make_Temporary
(Loc
, 'D');
7385 Make_Subprogram_Body
(Loc
,
7387 Make_Procedure_Specification
(Loc
,
7388 Defining_Unit_Name
=> Dnam
),
7390 Declarations
=> New_List
(
7391 Make_Object_Declaration
(Loc
,
7392 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
7393 Object_Definition
=>
7394 New_Occurrence_Of
(Etype
(Formal
), Loc
),
7395 Expression
=> New_Copy_Tree
(Dcopy
))),
7397 Handled_Statement_Sequence
=>
7398 Make_Handled_Sequence_Of_Statements
(Loc
,
7399 Statements
=> Empty_List
));
7401 Set_Scope
(Dnam
, Scope
(E
));
7402 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
7403 Set_Is_Eliminated
(Dnam
);
7404 Insert_After
(After
, Dbody
);
7410 Next_Formal
(Formal
);
7412 end Process_Default_Expressions
;
7414 ----------------------------------------
7415 -- Set_Component_Alignment_If_Not_Set --
7416 ----------------------------------------
7418 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
7420 -- Ignore if not base type, subtypes don't need anything
7422 if Typ
/= Base_Type
(Typ
) then
7426 -- Do not override existing representation
7428 if Is_Packed
(Typ
) then
7431 elsif Has_Specified_Layout
(Typ
) then
7434 elsif Component_Alignment
(Typ
) /= Calign_Default
then
7438 Set_Component_Alignment
7439 (Typ
, Scope_Stack
.Table
7440 (Scope_Stack
.Last
).Component_Alignment_Default
);
7442 end Set_Component_Alignment_If_Not_Set
;
7444 --------------------------
7445 -- Set_SSO_From_Default --
7446 --------------------------
7448 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
7450 if (Is_Record_Type
(T
) or else Is_Array_Type
(T
))
7451 and then Is_Base_Type
(T
)
7453 if (Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
7455 ((not Bytes_Big_Endian
) and then SSO_Set_High_By_Default
(T
))
7457 -- If flags cause reverse storage order, then set the result. Note
7458 -- that we would have ignored the pragma setting the non default
7459 -- storage order in any case, hence the assertion at this point.
7461 pragma Assert
(Support_Nondefault_SSO_On_Target
);
7462 Set_Reverse_Storage_Order
(T
);
7465 end Set_SSO_From_Default
;
7471 procedure Undelay_Type
(T
: Entity_Id
) is
7473 Set_Has_Delayed_Freeze
(T
, False);
7474 Set_Freeze_Node
(T
, Empty
);
7476 -- Since we don't want T to have a Freeze_Node, we don't want its
7477 -- Full_View or Corresponding_Record_Type to have one either.
7479 -- ??? Fundamentally, this whole handling is unpleasant. What we really
7480 -- want is to be sure that for an Itype that's part of record R and is a
7481 -- subtype of type T, that it's frozen after the later of the freeze
7482 -- points of R and T. We have no way of doing that directly, so what we
7483 -- do is force most such Itypes to be frozen as part of freezing R via
7484 -- this procedure and only delay the ones that need to be delayed
7485 -- (mostly the designated types of access types that are defined as part
7488 if Is_Private_Type
(T
)
7489 and then Present
(Full_View
(T
))
7490 and then Is_Itype
(Full_View
(T
))
7491 and then Is_Record_Type
(Scope
(Full_View
(T
)))
7493 Undelay_Type
(Full_View
(T
));
7496 if Is_Concurrent_Type
(T
)
7497 and then Present
(Corresponding_Record_Type
(T
))
7498 and then Is_Itype
(Corresponding_Record_Type
(T
))
7499 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
7501 Undelay_Type
(Corresponding_Record_Type
(T
));
7509 procedure Warn_Overlay
7514 Ent
: constant Entity_Id
:= Entity
(Nam
);
7515 -- The object to which the address clause applies
7518 Old
: Entity_Id
:= Empty
;
7522 -- No warning if address clause overlay warnings are off
7524 if not Address_Clause_Overlay_Warnings
then
7528 -- No warning if there is an explicit initialization
7530 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
7532 if Present
(Init
) and then Comes_From_Source
(Init
) then
7536 -- We only give the warning for non-imported entities of a type for
7537 -- which a non-null base init proc is defined, or for objects of access
7538 -- types with implicit null initialization, or when Normalize_Scalars
7539 -- applies and the type is scalar or a string type (the latter being
7540 -- tested for because predefined String types are initialized by inline
7541 -- code rather than by an init_proc). Note that we do not give the
7542 -- warning for Initialize_Scalars, since we suppressed initialization
7543 -- in this case. Also, do not warn if Suppress_Initialization is set.
7546 and then not Is_Imported
(Ent
)
7547 and then not Initialization_Suppressed
(Typ
)
7548 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
7549 or else Is_Access_Type
(Typ
)
7550 or else (Normalize_Scalars
7551 and then (Is_Scalar_Type
(Typ
)
7552 or else Is_String_Type
(Typ
))))
7554 if Nkind
(Expr
) = N_Attribute_Reference
7555 and then Is_Entity_Name
(Prefix
(Expr
))
7557 Old
:= Entity
(Prefix
(Expr
));
7559 elsif Is_Entity_Name
(Expr
)
7560 and then Ekind
(Entity
(Expr
)) = E_Constant
7562 Decl
:= Declaration_Node
(Entity
(Expr
));
7564 if Nkind
(Decl
) = N_Object_Declaration
7565 and then Present
(Expression
(Decl
))
7566 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
7567 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
7569 Old
:= Entity
(Prefix
(Expression
(Decl
)));
7571 elsif Nkind
(Expr
) = N_Function_Call
then
7575 -- A function call (most likely to To_Address) is probably not an
7576 -- overlay, so skip warning. Ditto if the function call was inlined
7577 -- and transformed into an entity.
7579 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
7583 Decl
:= Next
(Parent
(Expr
));
7585 -- If a pragma Import follows, we assume that it is for the current
7586 -- target of the address clause, and skip the warning.
7589 and then Nkind
(Decl
) = N_Pragma
7590 and then Pragma_Name
(Decl
) = Name_Import
7595 if Present
(Old
) then
7596 Error_Msg_Node_2
:= Old
;
7598 ("default initialization of & may modify &??",
7602 ("default initialization of & may modify overlaid storage??",
7606 -- Add friendly warning if initialization comes from a packed array
7609 if Is_Record_Type
(Typ
) then
7614 Comp
:= First_Component
(Typ
);
7615 while Present
(Comp
) loop
7616 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
7617 and then Present
(Expression
(Parent
(Comp
)))
7620 elsif Is_Array_Type
(Etype
(Comp
))
7621 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
7624 ("\packed array component& " &
7625 "will be initialized to zero??",
7629 Next_Component
(Comp
);
7636 ("\use pragma Import for & to " &
7637 "suppress initialization (RM B.1(24))??",