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
);
1825 Test_E
: Entity_Id
:= E
;
1826 -- This could use a comment ???
1828 Late_Freezing
: Boolean := False;
1829 -- Used to detect attempt to freeze function declared in another unit
1831 Result
: List_Id
:= No_List
;
1832 -- List of freezing actions, left at No_List if none
1834 Has_Default_Initialization
: Boolean := False;
1835 -- This flag gets set to true for a variable with default initialization
1837 procedure Add_To_Result
(N
: Node_Id
);
1838 -- N is a freezing action to be appended to the Result
1840 function After_Last_Declaration
return Boolean;
1841 -- If Loc is a freeze_entity that appears after the last declaration
1842 -- in the scope, inhibit error messages on late completion.
1844 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
);
1845 -- Check that an Access or Unchecked_Access attribute with a prefix
1846 -- which is the current instance type can only be applied when the type
1849 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
);
1850 -- Give warning for modulus of 8, 16, 32, or 64 given as an explicit
1851 -- integer literal without an explicit corresponding size clause. The
1852 -- caller has checked that Utype is a modular integer type.
1854 procedure Freeze_Array_Type
(Arr
: Entity_Id
);
1855 -- Freeze array type, including freezing index and component types
1857 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
;
1858 -- Create Freeze_Generic_Entity nodes for types declared in a generic
1859 -- package. Recurse on inner generic packages.
1861 procedure Freeze_Record_Type
(Rec
: Entity_Id
);
1862 -- Freeze record type, including freezing component types, and freezing
1863 -- primitive operations if this is a tagged type.
1865 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean;
1866 -- Determine whether an arbitrary entity is subject to Boolean aspect
1867 -- Import and its value is specified as True.
1869 procedure Late_Freeze_Subprogram
(E
: Entity_Id
);
1870 -- Following AI05-151, a function can return a limited view of a type
1871 -- declared elsewhere. In that case the function cannot be frozen at
1872 -- the end of its enclosing package. If its first use is in a different
1873 -- unit, it cannot be frozen there, but if the call is legal the full
1874 -- view of the return type is available and the subprogram can now be
1875 -- frozen. However the freeze node cannot be inserted at the point of
1876 -- call, but rather must go in the package holding the function, so that
1877 -- the backend can process it in the proper context.
1879 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
);
1880 -- If E is an entity for an imported subprogram with pre/post-conditions
1881 -- then this procedure will create a wrapper to ensure that proper run-
1882 -- time checking of the pre/postconditions. See body for details.
1888 procedure Add_To_Result
(N
: Node_Id
) is
1891 Result
:= New_List
(N
);
1897 ----------------------------
1898 -- After_Last_Declaration --
1899 ----------------------------
1901 function After_Last_Declaration
return Boolean is
1902 Spec
: constant Node_Id
:= Parent
(Current_Scope
);
1905 if Nkind
(Spec
) = N_Package_Specification
then
1906 if Present
(Private_Declarations
(Spec
)) then
1907 return Loc
>= Sloc
(Last
(Private_Declarations
(Spec
)));
1908 elsif Present
(Visible_Declarations
(Spec
)) then
1909 return Loc
>= Sloc
(Last
(Visible_Declarations
(Spec
)));
1917 end After_Last_Declaration
;
1919 ----------------------------
1920 -- Check_Current_Instance --
1921 ----------------------------
1923 procedure Check_Current_Instance
(Comp_Decl
: Node_Id
) is
1925 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean;
1926 -- Determine whether Typ is compatible with the rules for aliased
1927 -- views of types as defined in RM 3.10 in the various dialects.
1929 function Process
(N
: Node_Id
) return Traverse_Result
;
1930 -- Process routine to apply check to given node
1932 -----------------------------
1933 -- Is_Aliased_View_Of_Type --
1934 -----------------------------
1936 function Is_Aliased_View_Of_Type
(Typ
: Entity_Id
) return Boolean is
1937 Typ_Decl
: constant Node_Id
:= Parent
(Typ
);
1942 if Nkind
(Typ_Decl
) = N_Full_Type_Declaration
1943 and then Limited_Present
(Type_Definition
(Typ_Decl
))
1947 -- The following paragraphs describe what a legal aliased view of
1948 -- a type is in the various dialects of Ada.
1952 -- The current instance of a limited type, and a formal parameter
1953 -- or generic formal object of a tagged type.
1955 -- Ada 95 limited type
1956 -- * Type with reserved word "limited"
1957 -- * A protected or task type
1958 -- * A composite type with limited component
1960 elsif Ada_Version
<= Ada_95
then
1961 return Is_Limited_Type
(Typ
);
1965 -- The current instance of a limited tagged type, a protected
1966 -- type, a task type, or a type that has the reserved word
1967 -- "limited" in its full definition ... a formal parameter or
1968 -- generic formal object of a tagged type.
1970 -- Ada 2005 limited type
1971 -- * Type with reserved word "limited", "synchronized", "task"
1973 -- * A composite type with limited component
1974 -- * A derived type whose parent is a non-interface limited type
1976 elsif Ada_Version
= Ada_2005
then
1978 (Is_Limited_Type
(Typ
) and then Is_Tagged_Type
(Typ
))
1980 (Is_Derived_Type
(Typ
)
1981 and then not Is_Interface
(Etype
(Typ
))
1982 and then Is_Limited_Type
(Etype
(Typ
)));
1984 -- Ada 2012 and beyond
1986 -- The current instance of an immutably limited type ... a formal
1987 -- parameter or generic formal object of a tagged type.
1989 -- Ada 2012 limited type
1990 -- * Type with reserved word "limited", "synchronized", "task"
1992 -- * A composite type with limited component
1993 -- * A derived type whose parent is a non-interface limited type
1994 -- * An incomplete view
1996 -- Ada 2012 immutably limited type
1997 -- * Explicitly limited record type
1998 -- * Record extension with "limited" present
1999 -- * Non-formal limited private type that is either tagged
2000 -- or has at least one access discriminant with a default
2002 -- * Task type, protected type or synchronized interface
2003 -- * Type derived from immutably limited type
2007 Is_Immutably_Limited_Type
(Typ
)
2008 or else Is_Incomplete_Type
(Typ
);
2010 end Is_Aliased_View_Of_Type
;
2016 function Process
(N
: Node_Id
) return Traverse_Result
is
2019 when N_Attribute_Reference
=>
2020 if Nam_In
(Attribute_Name
(N
), Name_Access
,
2021 Name_Unchecked_Access
)
2022 and then Is_Entity_Name
(Prefix
(N
))
2023 and then Is_Type
(Entity
(Prefix
(N
)))
2024 and then Entity
(Prefix
(N
)) = E
2026 if Ada_Version
< Ada_2012
then
2028 ("current instance must be a limited type",
2032 ("current instance must be an immutably limited "
2033 & "type (RM-2012, 7.5 (8.1/3))", Prefix
(N
));
2042 when others => return OK
;
2046 procedure Traverse
is new Traverse_Proc
(Process
);
2050 Rec_Type
: constant Entity_Id
:=
2051 Scope
(Defining_Identifier
(Comp_Decl
));
2053 -- Start of processing for Check_Current_Instance
2056 if not Is_Aliased_View_Of_Type
(Rec_Type
) then
2057 Traverse
(Comp_Decl
);
2059 end Check_Current_Instance
;
2061 ------------------------------
2062 -- Check_Suspicious_Modulus --
2063 ------------------------------
2065 procedure Check_Suspicious_Modulus
(Utype
: Entity_Id
) is
2066 Decl
: constant Node_Id
:= Declaration_Node
(Underlying_Type
(Utype
));
2069 if not Warn_On_Suspicious_Modulus_Value
then
2073 if Nkind
(Decl
) = N_Full_Type_Declaration
then
2075 Tdef
: constant Node_Id
:= Type_Definition
(Decl
);
2078 if Nkind
(Tdef
) = N_Modular_Type_Definition
then
2080 Modulus
: constant Node_Id
:=
2081 Original_Node
(Expression
(Tdef
));
2084 if Nkind
(Modulus
) = N_Integer_Literal
then
2086 Modv
: constant Uint
:= Intval
(Modulus
);
2087 Sizv
: constant Uint
:= RM_Size
(Utype
);
2090 -- First case, modulus and size are the same. This
2091 -- happens if you have something like mod 32, with
2092 -- an explicit size of 32, this is for sure a case
2093 -- where the warning is given, since it is seems
2094 -- very unlikely that someone would want e.g. a
2095 -- five bit type stored in 32 bits. It is much
2096 -- more likely they wanted a 32-bit type.
2101 -- Second case, the modulus is 32 or 64 and no
2102 -- size clause is present. This is a less clear
2103 -- case for giving the warning, but in the case
2104 -- of 32/64 (5-bit or 6-bit types) these seem rare
2105 -- enough that it is a likely error (and in any
2106 -- case using 2**5 or 2**6 in these cases seems
2107 -- clearer. We don't include 8 or 16 here, simply
2108 -- because in practice 3-bit and 4-bit types are
2109 -- more common and too many false positives if
2110 -- we warn in these cases.
2112 elsif not Has_Size_Clause
(Utype
)
2113 and then (Modv
= Uint_32
or else Modv
= Uint_64
)
2117 -- No warning needed
2123 -- If we fall through, give warning
2125 Error_Msg_Uint_1
:= Modv
;
2127 ("?M?2 '*'*^' may have been intended here",
2135 end Check_Suspicious_Modulus
;
2137 -----------------------
2138 -- Freeze_Array_Type --
2139 -----------------------
2141 procedure Freeze_Array_Type
(Arr
: Entity_Id
) is
2142 FS
: constant Entity_Id
:= First_Subtype
(Arr
);
2143 Ctyp
: constant Entity_Id
:= Component_Type
(Arr
);
2146 Non_Standard_Enum
: Boolean := False;
2147 -- Set true if any of the index types is an enumeration type with a
2148 -- non-standard representation.
2151 Freeze_And_Append
(Ctyp
, N
, Result
);
2153 Indx
:= First_Index
(Arr
);
2154 while Present
(Indx
) loop
2155 Freeze_And_Append
(Etype
(Indx
), N
, Result
);
2157 if Is_Enumeration_Type
(Etype
(Indx
))
2158 and then Has_Non_Standard_Rep
(Etype
(Indx
))
2160 Non_Standard_Enum
:= True;
2166 -- Processing that is done only for base types
2168 if Ekind
(Arr
) = E_Array_Type
then
2170 -- Deal with default setting of reverse storage order
2172 Set_SSO_From_Default
(Arr
);
2174 -- Propagate flags for component type
2176 if Is_Controlled
(Component_Type
(Arr
))
2177 or else Has_Controlled_Component
(Ctyp
)
2179 Set_Has_Controlled_Component
(Arr
);
2182 if Has_Unchecked_Union
(Component_Type
(Arr
)) then
2183 Set_Has_Unchecked_Union
(Arr
);
2186 -- Warn for pragma Pack overriding foreign convention
2188 if Has_Foreign_Convention
(Ctyp
)
2189 and then Has_Pragma_Pack
(Arr
)
2192 CN
: constant Name_Id
:=
2193 Get_Convention_Name
(Convention
(Ctyp
));
2194 PP
: constant Node_Id
:=
2195 Get_Pragma
(First_Subtype
(Arr
), Pragma_Pack
);
2197 if Present
(PP
) then
2198 Error_Msg_Name_1
:= CN
;
2199 Error_Msg_Sloc
:= Sloc
(Arr
);
2201 ("pragma Pack affects convention % components #??", PP
);
2202 Error_Msg_Name_1
:= CN
;
2204 ("\array components may not have % compatible "
2205 & "representation??", PP
);
2210 -- If packing was requested or if the component size was
2211 -- set explicitly, then see if bit packing is required. This
2212 -- processing is only done for base types, since all of the
2213 -- representation aspects involved are type-related.
2215 -- This is not just an optimization, if we start processing the
2216 -- subtypes, they interfere with the settings on the base type
2217 -- (this is because Is_Packed has a slightly different meaning
2218 -- before and after freezing).
2225 if (Is_Packed
(Arr
) or else Has_Pragma_Pack
(Arr
))
2226 and then Known_Static_RM_Size
(Ctyp
)
2227 and then not Has_Component_Size_Clause
(Arr
)
2229 Csiz
:= UI_Max
(RM_Size
(Ctyp
), 1);
2231 elsif Known_Component_Size
(Arr
) then
2232 Csiz
:= Component_Size
(Arr
);
2234 elsif not Known_Static_Esize
(Ctyp
) then
2238 Esiz
:= Esize
(Ctyp
);
2240 -- We can set the component size if it is less than 16,
2241 -- rounding it up to the next storage unit size.
2245 elsif Esiz
<= 16 then
2251 -- Set component size up to match alignment if it would
2252 -- otherwise be less than the alignment. This deals with
2253 -- cases of types whose alignment exceeds their size (the
2254 -- padded type cases).
2258 A
: constant Uint
:= Alignment_In_Bits
(Ctyp
);
2267 -- Case of component size that may result in packing
2269 if 1 <= Csiz
and then Csiz
<= 64 then
2271 Ent
: constant Entity_Id
:=
2272 First_Subtype
(Arr
);
2273 Pack_Pragma
: constant Node_Id
:=
2274 Get_Rep_Pragma
(Ent
, Name_Pack
);
2275 Comp_Size_C
: constant Node_Id
:=
2276 Get_Attribute_Definition_Clause
2277 (Ent
, Attribute_Component_Size
);
2280 -- Warn if we have pack and component size so that the
2283 -- Note: here we must check for the presence of a
2284 -- component size before checking for a Pack pragma to
2285 -- deal with the case where the array type is a derived
2286 -- type whose parent is currently private.
2288 if Present
(Comp_Size_C
)
2289 and then Has_Pragma_Pack
(Ent
)
2290 and then Warn_On_Redundant_Constructs
2292 Error_Msg_Sloc
:= Sloc
(Comp_Size_C
);
2294 ("?r?pragma Pack for& ignored!", Pack_Pragma
, Ent
);
2296 ("\?r?explicit component size given#!", Pack_Pragma
);
2297 Set_Is_Packed
(Base_Type
(Ent
), False);
2298 Set_Is_Bit_Packed_Array
(Base_Type
(Ent
), False);
2301 -- Set component size if not already set by a component
2304 if not Present
(Comp_Size_C
) then
2305 Set_Component_Size
(Arr
, Csiz
);
2308 -- Check for base type of 8, 16, 32 bits, where an
2309 -- unsigned subtype has a length one less than the
2310 -- base type (e.g. Natural subtype of Integer).
2312 -- In such cases, if a component size was not set
2313 -- explicitly, then generate a warning.
2315 if Has_Pragma_Pack
(Arr
)
2316 and then not Present
(Comp_Size_C
)
2317 and then (Csiz
= 7 or else Csiz
= 15 or else Csiz
= 31)
2318 and then Esize
(Base_Type
(Ctyp
)) = Csiz
+ 1
2320 Error_Msg_Uint_1
:= Csiz
;
2322 if Present
(Pack_Pragma
) then
2324 ("??pragma Pack causes component size to be ^!",
2327 ("\??use Component_Size to set desired value!",
2332 -- Actual packing is not needed for 8, 16, 32, 64. Also
2333 -- not needed for 24 if alignment is 1.
2339 or else (Csiz
= 24 and then Alignment
(Ctyp
) = 1)
2341 -- Here the array was requested to be packed, but
2342 -- the packing request had no effect, so Is_Packed
2345 -- Note: semantically this means that we lose track
2346 -- of the fact that a derived type inherited a pragma
2347 -- Pack that was non- effective, but that seems fine.
2349 -- We regard a Pack pragma as a request to set a
2350 -- representation characteristic, and this request
2353 Set_Is_Packed
(Base_Type
(Arr
), False);
2354 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), False);
2356 if Known_Static_Esize
(Component_Type
(Arr
))
2357 and then Esize
(Component_Type
(Arr
)) = Csiz
2359 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), False);
2362 -- In all other cases, packing is indeed needed
2365 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
), True);
2366 Set_Is_Bit_Packed_Array
(Base_Type
(Arr
), True);
2367 Set_Is_Packed
(Base_Type
(Arr
), True);
2373 -- Check for Atomic_Components or Aliased with unsuitable packing
2374 -- or explicit component size clause given.
2376 if (Has_Atomic_Components
(Arr
)
2378 Has_Aliased_Components
(Arr
))
2380 (Has_Component_Size_Clause
(Arr
) or else Is_Packed
(Arr
))
2382 Alias_Atomic_Check
: declare
2384 procedure Complain_CS
(T
: String);
2385 -- Outputs error messages for incorrect CS clause or pragma
2386 -- Pack for aliased or atomic components (T is "aliased" or
2393 procedure Complain_CS
(T
: String) is
2395 if Has_Component_Size_Clause
(Arr
) then
2397 Get_Attribute_Definition_Clause
2398 (FS
, Attribute_Component_Size
);
2400 if Known_Static_Esize
(Ctyp
) then
2402 ("incorrect component size for "
2403 & T
& " components", Clause
);
2404 Error_Msg_Uint_1
:= Esize
(Ctyp
);
2406 ("\only allowed value is^", Clause
);
2410 ("component size cannot be given for "
2411 & T
& " components", Clause
);
2416 ("cannot pack " & T
& " components",
2417 Get_Rep_Pragma
(FS
, Name_Pack
));
2423 -- Start of processing for Alias_Atomic_Check
2426 -- If object size of component type isn't known, we cannot
2427 -- be sure so we defer to the back end.
2429 if not Known_Static_Esize
(Ctyp
) then
2432 -- Case where component size has no effect. First check for
2433 -- object size of component type multiple of the storage
2436 elsif Esize
(Ctyp
) mod System_Storage_Unit
= 0
2438 -- OK in both packing case and component size case if RM
2439 -- size is known and static and same as the object size.
2442 ((Known_Static_RM_Size
(Ctyp
)
2443 and then Esize
(Ctyp
) = RM_Size
(Ctyp
))
2445 -- Or if we have an explicit component size clause and
2446 -- the component size and object size are equal.
2449 (Has_Component_Size_Clause
(Arr
)
2450 and then Component_Size
(Arr
) = Esize
(Ctyp
)))
2454 elsif Has_Aliased_Components
(Arr
)
2455 or else Is_Aliased
(Ctyp
)
2457 Complain_CS
("aliased");
2459 elsif Has_Atomic_Components
(Arr
)
2460 or else Is_Atomic
(Ctyp
)
2462 Complain_CS
("atomic");
2464 end Alias_Atomic_Check
;
2467 -- Warn for case of atomic type
2469 Clause
:= Get_Rep_Pragma
(FS
, Name_Atomic
);
2472 and then not Addressable
(Component_Size
(FS
))
2475 ("non-atomic components of type& may not be "
2476 & "accessible by separate tasks??", Clause
, Arr
);
2478 if Has_Component_Size_Clause
(Arr
) then
2479 Error_Msg_Sloc
:= Sloc
(Get_Attribute_Definition_Clause
2480 (FS
, Attribute_Component_Size
));
2481 Error_Msg_N
("\because of component size clause#??", Clause
);
2483 elsif Has_Pragma_Pack
(Arr
) then
2484 Error_Msg_Sloc
:= Sloc
(Get_Rep_Pragma
(FS
, Name_Pack
));
2485 Error_Msg_N
("\because of pragma Pack#??", Clause
);
2489 -- Check for scalar storage order
2494 Check_Component_Storage_Order
2497 ADC
=> Get_Attribute_Definition_Clause
2498 (First_Subtype
(Arr
),
2499 Attribute_Scalar_Storage_Order
),
2500 Comp_ADC_Present
=> Dummy
);
2503 -- Processing that is done only for subtypes
2506 -- Acquire alignment from base type
2508 if Unknown_Alignment
(Arr
) then
2509 Set_Alignment
(Arr
, Alignment
(Base_Type
(Arr
)));
2510 Adjust_Esize_Alignment
(Arr
);
2514 -- Specific checks for bit-packed arrays
2516 if Is_Bit_Packed_Array
(Arr
) then
2518 -- Check number of elements for bit packed arrays that come from
2519 -- source and have compile time known ranges. The bit-packed
2520 -- arrays circuitry does not support arrays with more than
2521 -- Integer'Last + 1 elements, and when this restriction is
2522 -- violated, causes incorrect data access.
2524 -- For the case where this is not compile time known, a run-time
2525 -- check should be generated???
2527 if Comes_From_Source
(Arr
) and then Is_Constrained
(Arr
) then
2536 Index
:= First_Index
(Arr
);
2537 while Present
(Index
) loop
2538 Ityp
:= Etype
(Index
);
2540 -- Never generate an error if any index is of a generic
2541 -- type. We will check this in instances.
2543 if Is_Generic_Type
(Ityp
) then
2549 Make_Attribute_Reference
(Loc
,
2550 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2551 Attribute_Name
=> Name_Range_Length
);
2552 Analyze_And_Resolve
(Ilen
);
2554 -- No attempt is made to check number of elements
2555 -- if not compile time known.
2557 if Nkind
(Ilen
) /= N_Integer_Literal
then
2562 Elmts
:= Elmts
* Intval
(Ilen
);
2566 if Elmts
> Intval
(High_Bound
2567 (Scalar_Range
(Standard_Integer
))) + 1
2570 ("bit packed array type may not have "
2571 & "more than Integer''Last+1 elements", Arr
);
2578 if Known_RM_Size
(Arr
) then
2580 SizC
: constant Node_Id
:= Size_Clause
(Arr
);
2584 -- It is not clear if it is possible to have no size clause
2585 -- at this stage, but it is not worth worrying about. Post
2586 -- error on the entity name in the size clause if present,
2587 -- else on the type entity itself.
2589 if Present
(SizC
) then
2590 Check_Size
(Name
(SizC
), Arr
, RM_Size
(Arr
), Discard
);
2592 Check_Size
(Arr
, Arr
, RM_Size
(Arr
), Discard
);
2598 -- If any of the index types was an enumeration type with a
2599 -- non-standard rep clause, then we indicate that the array type
2600 -- is always packed (even if it is not bit packed).
2602 if Non_Standard_Enum
then
2603 Set_Has_Non_Standard_Rep
(Base_Type
(Arr
));
2604 Set_Is_Packed
(Base_Type
(Arr
));
2607 Set_Component_Alignment_If_Not_Set
(Arr
);
2609 -- If the array is packed, we must create the packed array type to be
2610 -- used to actually implement the type. This is only needed for real
2611 -- array types (not for string literal types, since they are present
2612 -- only for the front end).
2615 and then Ekind
(Arr
) /= E_String_Literal_Subtype
2617 Create_Packed_Array_Impl_Type
(Arr
);
2618 Freeze_And_Append
(Packed_Array_Impl_Type
(Arr
), N
, Result
);
2620 -- Size information of packed array type is copied to the array
2621 -- type, since this is really the representation. But do not
2622 -- override explicit existing size values. If the ancestor subtype
2623 -- is constrained the Packed_Array_Impl_Type will be inherited
2624 -- from it, but the size may have been provided already, and
2625 -- must not be overridden either.
2627 if not Has_Size_Clause
(Arr
)
2629 (No
(Ancestor_Subtype
(Arr
))
2630 or else not Has_Size_Clause
(Ancestor_Subtype
(Arr
)))
2632 Set_Esize
(Arr
, Esize
(Packed_Array_Impl_Type
(Arr
)));
2633 Set_RM_Size
(Arr
, RM_Size
(Packed_Array_Impl_Type
(Arr
)));
2636 if not Has_Alignment_Clause
(Arr
) then
2637 Set_Alignment
(Arr
, Alignment
(Packed_Array_Impl_Type
(Arr
)));
2641 -- For non-packed arrays set the alignment of the array to the
2642 -- alignment of the component type if it is unknown. Skip this
2643 -- in atomic case (atomic arrays may need larger alignments).
2645 if not Is_Packed
(Arr
)
2646 and then Unknown_Alignment
(Arr
)
2647 and then Known_Alignment
(Ctyp
)
2648 and then Known_Static_Component_Size
(Arr
)
2649 and then Known_Static_Esize
(Ctyp
)
2650 and then Esize
(Ctyp
) = Component_Size
(Arr
)
2651 and then not Is_Atomic
(Arr
)
2653 Set_Alignment
(Arr
, Alignment
(Component_Type
(Arr
)));
2655 end Freeze_Array_Type
;
2657 -----------------------------
2658 -- Freeze_Generic_Entities --
2659 -----------------------------
2661 function Freeze_Generic_Entities
(Pack
: Entity_Id
) return List_Id
is
2668 E
:= First_Entity
(Pack
);
2669 while Present
(E
) loop
2670 if Is_Type
(E
) and then not Is_Generic_Type
(E
) then
2671 F
:= Make_Freeze_Generic_Entity
(Sloc
(Pack
));
2673 Append_To
(Flist
, F
);
2675 elsif Ekind
(E
) = E_Generic_Package
then
2676 Append_List_To
(Flist
, Freeze_Generic_Entities
(E
));
2683 end Freeze_Generic_Entities
;
2685 ------------------------
2686 -- Freeze_Record_Type --
2687 ------------------------
2689 procedure Freeze_Record_Type
(Rec
: Entity_Id
) is
2696 pragma Warnings
(Off
, Junk
);
2698 Rec_Pushed
: Boolean := False;
2699 -- Set True if the record type scope Rec has been pushed on the scope
2700 -- stack. Needed for the analysis of delayed aspects specified to the
2701 -- components of Rec.
2704 -- Scalar_Storage_Order attribute definition clause for the record
2706 Unplaced_Component
: Boolean := False;
2707 -- Set True if we find at least one component with no component
2708 -- clause (used to warn about useless Pack pragmas).
2710 Placed_Component
: Boolean := False;
2711 -- Set True if we find at least one component with a component
2712 -- clause (used to warn about useless Bit_Order pragmas, and also
2713 -- to detect cases where Implicit_Packing may have an effect).
2715 Aliased_Component
: Boolean := False;
2716 -- Set True if we find at least one component which is aliased. This
2717 -- is used to prevent Implicit_Packing of the record, since packing
2718 -- cannot modify the size of alignment of an aliased component.
2720 SSO_ADC_Component
: Boolean := False;
2721 -- Set True if we find at least one component whose type has a
2722 -- Scalar_Storage_Order attribute definition clause.
2724 All_Scalar_Components
: Boolean := True;
2725 -- Set False if we encounter a component of a non-scalar type
2727 Scalar_Component_Total_RM_Size
: Uint
:= Uint_0
;
2728 Scalar_Component_Total_Esize
: Uint
:= Uint_0
;
2729 -- Accumulates total RM_Size values and total Esize values of all
2730 -- scalar components. Used for processing of Implicit_Packing.
2732 function Check_Allocator
(N
: Node_Id
) return Node_Id
;
2733 -- If N is an allocator, possibly wrapped in one or more level of
2734 -- qualified expression(s), return the inner allocator node, else
2737 procedure Check_Itype
(Typ
: Entity_Id
);
2738 -- If the component subtype is an access to a constrained subtype of
2739 -- an already frozen type, make the subtype frozen as well. It might
2740 -- otherwise be frozen in the wrong scope, and a freeze node on
2741 -- subtype has no effect. Similarly, if the component subtype is a
2742 -- regular (not protected) access to subprogram, set the anonymous
2743 -- subprogram type to frozen as well, to prevent an out-of-scope
2744 -- freeze node at some eventual point of call. Protected operations
2745 -- are handled elsewhere.
2747 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
);
2748 -- Make sure that all types mentioned in Discrete_Choices of the
2749 -- variants referenceed by the Variant_Part VP are frozen. This is
2750 -- a recursive routine to deal with nested variants.
2752 ---------------------
2753 -- Check_Allocator --
2754 ---------------------
2756 function Check_Allocator
(N
: Node_Id
) return Node_Id
is
2761 if Nkind
(Inner
) = N_Allocator
then
2763 elsif Nkind
(Inner
) = N_Qualified_Expression
then
2764 Inner
:= Expression
(Inner
);
2769 end Check_Allocator
;
2775 procedure Check_Itype
(Typ
: Entity_Id
) is
2776 Desig
: constant Entity_Id
:= Designated_Type
(Typ
);
2779 if not Is_Frozen
(Desig
)
2780 and then Is_Frozen
(Base_Type
(Desig
))
2782 Set_Is_Frozen
(Desig
);
2784 -- In addition, add an Itype_Reference to ensure that the
2785 -- access subtype is elaborated early enough. This cannot be
2786 -- done if the subtype may depend on discriminants.
2788 if Ekind
(Comp
) = E_Component
2789 and then Is_Itype
(Etype
(Comp
))
2790 and then not Has_Discriminants
(Rec
)
2792 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
2793 Set_Itype
(IR
, Desig
);
2797 elsif Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
2798 and then Convention
(Desig
) /= Convention_Protected
2800 Set_Is_Frozen
(Desig
);
2804 ------------------------------------
2805 -- Freeze_Choices_In_Variant_Part --
2806 ------------------------------------
2808 procedure Freeze_Choices_In_Variant_Part
(VP
: Node_Id
) is
2809 pragma Assert
(Nkind
(VP
) = N_Variant_Part
);
2816 -- Loop through variants
2818 Variant
:= First_Non_Pragma
(Variants
(VP
));
2819 while Present
(Variant
) loop
2821 -- Loop through choices, checking that all types are frozen
2823 Choice
:= First_Non_Pragma
(Discrete_Choices
(Variant
));
2824 while Present
(Choice
) loop
2825 if Nkind
(Choice
) in N_Has_Etype
2826 and then Present
(Etype
(Choice
))
2828 Freeze_And_Append
(Etype
(Choice
), N
, Result
);
2831 Next_Non_Pragma
(Choice
);
2834 -- Check for nested variant part to process
2836 CL
:= Component_List
(Variant
);
2838 if not Null_Present
(CL
) then
2839 if Present
(Variant_Part
(CL
)) then
2840 Freeze_Choices_In_Variant_Part
(Variant_Part
(CL
));
2844 Next_Non_Pragma
(Variant
);
2846 end Freeze_Choices_In_Variant_Part
;
2848 -- Start of processing for Freeze_Record_Type
2851 -- Deal with delayed aspect specifications for components. The
2852 -- analysis of the aspect is required to be delayed to the freeze
2853 -- point, thus we analyze the pragma or attribute definition
2854 -- clause in the tree at this point. We also analyze the aspect
2855 -- specification node at the freeze point when the aspect doesn't
2856 -- correspond to pragma/attribute definition clause.
2858 Comp
:= First_Entity
(Rec
);
2859 while Present
(Comp
) loop
2860 if Ekind
(Comp
) = E_Component
2861 and then Has_Delayed_Aspects
(Comp
)
2863 if not Rec_Pushed
then
2867 -- The visibility to the discriminants must be restored in
2868 -- order to properly analyze the aspects.
2870 if Has_Discriminants
(Rec
) then
2871 Install_Discriminants
(Rec
);
2875 Analyze_Aspects_At_Freeze_Point
(Comp
);
2881 -- Pop the scope if Rec scope has been pushed on the scope stack
2882 -- during the delayed aspect analysis process.
2885 if Has_Discriminants
(Rec
) then
2886 Uninstall_Discriminants
(Rec
);
2892 -- Freeze components and embedded subtypes
2894 Comp
:= First_Entity
(Rec
);
2896 while Present
(Comp
) loop
2897 if Is_Aliased
(Comp
) then
2898 Aliased_Component
:= True;
2901 -- Handle the component and discriminant case
2903 if Ekind_In
(Comp
, E_Component
, E_Discriminant
) then
2905 CC
: constant Node_Id
:= Component_Clause
(Comp
);
2908 -- Freezing a record type freezes the type of each of its
2909 -- components. However, if the type of the component is
2910 -- part of this record, we do not want or need a separate
2911 -- Freeze_Node. Note that Is_Itype is wrong because that's
2912 -- also set in private type cases. We also can't check for
2913 -- the Scope being exactly Rec because of private types and
2914 -- record extensions.
2916 if Is_Itype
(Etype
(Comp
))
2917 and then Is_Record_Type
(Underlying_Type
2918 (Scope
(Etype
(Comp
))))
2920 Undelay_Type
(Etype
(Comp
));
2923 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
2925 -- Warn for pragma Pack overriding foreign convention
2927 if Has_Foreign_Convention
(Etype
(Comp
))
2928 and then Has_Pragma_Pack
(Rec
)
2930 -- Don't warn for aliased components, since override
2931 -- cannot happen in that case.
2933 and then not Is_Aliased
(Comp
)
2936 CN
: constant Name_Id
:=
2937 Get_Convention_Name
(Convention
(Etype
(Comp
)));
2938 PP
: constant Node_Id
:=
2939 Get_Pragma
(Rec
, Pragma_Pack
);
2941 if Present
(PP
) then
2942 Error_Msg_Name_1
:= CN
;
2943 Error_Msg_Sloc
:= Sloc
(Comp
);
2945 ("pragma Pack affects convention % component#??",
2947 Error_Msg_Name_1
:= CN
;
2949 ("\component & may not have % compatible "
2950 & "representation??", PP
, Comp
);
2955 -- Check for error of component clause given for variable
2956 -- sized type. We have to delay this test till this point,
2957 -- since the component type has to be frozen for us to know
2958 -- if it is variable length.
2960 if Present
(CC
) then
2961 Placed_Component
:= True;
2963 -- We omit this test in a generic context, it will be
2964 -- applied at instantiation time.
2966 if Inside_A_Generic
then
2969 -- Also omit this test in CodePeer mode, since we do not
2970 -- have sufficient info on size and rep clauses.
2972 elsif CodePeer_Mode
then
2978 Size_Known_At_Compile_Time
2979 (Underlying_Type
(Etype
(Comp
)))
2982 ("component clause not allowed for variable " &
2983 "length component", CC
);
2987 Unplaced_Component
:= True;
2990 -- Case of component requires byte alignment
2992 if Must_Be_On_Byte_Boundary
(Etype
(Comp
)) then
2994 -- Set the enclosing record to also require byte align
2996 Set_Must_Be_On_Byte_Boundary
(Rec
);
2998 -- Check for component clause that is inconsistent with
2999 -- the required byte boundary alignment.
3002 and then Normalized_First_Bit
(Comp
) mod
3003 System_Storage_Unit
/= 0
3006 ("component & must be byte aligned",
3007 Component_Name
(Component_Clause
(Comp
)));
3013 -- Gather data for possible Implicit_Packing later. Note that at
3014 -- this stage we might be dealing with a real component, or with
3015 -- an implicit subtype declaration.
3017 if not Is_Scalar_Type
(Etype
(Comp
)) then
3018 All_Scalar_Components
:= False;
3020 Scalar_Component_Total_RM_Size
:=
3021 Scalar_Component_Total_RM_Size
+ RM_Size
(Etype
(Comp
));
3022 Scalar_Component_Total_Esize
:=
3023 Scalar_Component_Total_Esize
+ Esize
(Etype
(Comp
));
3026 -- If the component is an Itype with Delayed_Freeze and is either
3027 -- a record or array subtype and its base type has not yet been
3028 -- frozen, we must remove this from the entity list of this record
3029 -- and put it on the entity list of the scope of its base type.
3030 -- Note that we know that this is not the type of a component
3031 -- since we cleared Has_Delayed_Freeze for it in the previous
3032 -- loop. Thus this must be the Designated_Type of an access type,
3033 -- which is the type of a component.
3036 and then Is_Type
(Scope
(Comp
))
3037 and then Is_Composite_Type
(Comp
)
3038 and then Base_Type
(Comp
) /= Comp
3039 and then Has_Delayed_Freeze
(Comp
)
3040 and then not Is_Frozen
(Base_Type
(Comp
))
3043 Will_Be_Frozen
: Boolean := False;
3047 -- We have a difficult case to handle here. Suppose Rec is
3048 -- subtype being defined in a subprogram that's created as
3049 -- part of the freezing of Rec'Base. In that case, we know
3050 -- that Comp'Base must have already been frozen by the time
3051 -- we get to elaborate this because Gigi doesn't elaborate
3052 -- any bodies until it has elaborated all of the declarative
3053 -- part. But Is_Frozen will not be set at this point because
3054 -- we are processing code in lexical order.
3056 -- We detect this case by going up the Scope chain of Rec
3057 -- and seeing if we have a subprogram scope before reaching
3058 -- the top of the scope chain or that of Comp'Base. If we
3059 -- do, then mark that Comp'Base will actually be frozen. If
3060 -- so, we merely undelay it.
3063 while Present
(S
) loop
3064 if Is_Subprogram
(S
) then
3065 Will_Be_Frozen
:= True;
3067 elsif S
= Scope
(Base_Type
(Comp
)) then
3074 if Will_Be_Frozen
then
3075 Undelay_Type
(Comp
);
3078 if Present
(Prev
) then
3079 Set_Next_Entity
(Prev
, Next_Entity
(Comp
));
3081 Set_First_Entity
(Rec
, Next_Entity
(Comp
));
3084 -- Insert in entity list of scope of base type (which
3085 -- must be an enclosing scope, because still unfrozen).
3087 Append_Entity
(Comp
, Scope
(Base_Type
(Comp
)));
3091 -- If the component is an access type with an allocator as default
3092 -- value, the designated type will be frozen by the corresponding
3093 -- expression in init_proc. In order to place the freeze node for
3094 -- the designated type before that for the current record type,
3097 -- Same process if the component is an array of access types,
3098 -- initialized with an aggregate. If the designated type is
3099 -- private, it cannot contain allocators, and it is premature
3100 -- to freeze the type, so we check for this as well.
3102 elsif Is_Access_Type
(Etype
(Comp
))
3103 and then Present
(Parent
(Comp
))
3104 and then Present
(Expression
(Parent
(Comp
)))
3107 Alloc
: constant Node_Id
:=
3108 Check_Allocator
(Expression
(Parent
(Comp
)));
3111 if Present
(Alloc
) then
3113 -- If component is pointer to a class-wide type, freeze
3114 -- the specific type in the expression being allocated.
3115 -- The expression may be a subtype indication, in which
3116 -- case freeze the subtype mark.
3118 if Is_Class_Wide_Type
3119 (Designated_Type
(Etype
(Comp
)))
3121 if Is_Entity_Name
(Expression
(Alloc
)) then
3123 (Entity
(Expression
(Alloc
)), N
, Result
);
3125 elsif Nkind
(Expression
(Alloc
)) = N_Subtype_Indication
3128 (Entity
(Subtype_Mark
(Expression
(Alloc
))),
3132 elsif Is_Itype
(Designated_Type
(Etype
(Comp
))) then
3133 Check_Itype
(Etype
(Comp
));
3137 (Designated_Type
(Etype
(Comp
)), N
, Result
);
3142 elsif Is_Access_Type
(Etype
(Comp
))
3143 and then Is_Itype
(Designated_Type
(Etype
(Comp
)))
3145 Check_Itype
(Etype
(Comp
));
3147 -- Freeze the designated type when initializing a component with
3148 -- an aggregate in case the aggregate contains allocators.
3151 -- type T_Ptr is access all T;
3152 -- type T_Array is array ... of T_Ptr;
3154 -- type Rec is record
3155 -- Comp : T_Array := (others => ...);
3158 elsif Is_Array_Type
(Etype
(Comp
))
3159 and then Is_Access_Type
(Component_Type
(Etype
(Comp
)))
3162 Comp_Par
: constant Node_Id
:= Parent
(Comp
);
3163 Desig_Typ
: constant Entity_Id
:=
3165 (Component_Type
(Etype
(Comp
)));
3168 -- The only case when this sort of freezing is not done is
3169 -- when the designated type is class-wide and the root type
3170 -- is the record owning the component. This scenario results
3171 -- in a circularity because the class-wide type requires
3172 -- primitives that have not been created yet as the root
3173 -- type is in the process of being frozen.
3175 -- type Rec is tagged;
3176 -- type Rec_Ptr is access all Rec'Class;
3177 -- type Rec_Array is array ... of Rec_Ptr;
3179 -- type Rec is record
3180 -- Comp : Rec_Array := (others => ...);
3183 if Is_Class_Wide_Type
(Desig_Typ
)
3184 and then Root_Type
(Desig_Typ
) = Rec
3188 elsif Is_Fully_Defined
(Desig_Typ
)
3189 and then Present
(Comp_Par
)
3190 and then Nkind
(Comp_Par
) = N_Component_Declaration
3191 and then Present
(Expression
(Comp_Par
))
3192 and then Nkind
(Expression
(Comp_Par
)) = N_Aggregate
3194 Freeze_And_Append
(Desig_Typ
, N
, Result
);
3203 SSO_ADC
:= Get_Attribute_Definition_Clause
3204 (Rec
, Attribute_Scalar_Storage_Order
);
3206 -- Check consistent attribute setting on component types
3209 Comp_ADC_Present
: Boolean;
3211 Comp
:= First_Component
(Rec
);
3212 while Present
(Comp
) loop
3213 Check_Component_Storage_Order
3217 Comp_ADC_Present
=> Comp_ADC_Present
);
3218 SSO_ADC_Component
:= SSO_ADC_Component
or Comp_ADC_Present
;
3219 Next_Component
(Comp
);
3223 -- Deal with default setting of reverse storage order
3225 Set_SSO_From_Default
(Rec
);
3227 -- Now deal with reverse storage order/bit order issues
3229 if Present
(SSO_ADC
) then
3231 -- Check compatibility of Scalar_Storage_Order with Bit_Order, if
3232 -- the former is specified.
3234 if Reverse_Bit_Order
(Rec
) /= Reverse_Storage_Order
(Rec
) then
3236 -- Note: report error on Rec, not on SSO_ADC, as ADC may apply
3237 -- to some ancestor type.
3239 Error_Msg_Sloc
:= Sloc
(SSO_ADC
);
3241 ("scalar storage order for& specified# inconsistent with "
3242 & "bit order", Rec
);
3245 -- Warn if there is an Scalar_Storage_Order attribute definition
3246 -- clause but no component clause, no component that itself has
3247 -- such an attribute definition, and no pragma Pack.
3249 if not (Placed_Component
3256 ("??scalar storage order specified but no component clause",
3261 -- Deal with Bit_Order aspect
3263 ADC
:= Get_Attribute_Definition_Clause
(Rec
, Attribute_Bit_Order
);
3265 if Present
(ADC
) and then Base_Type
(Rec
) = Rec
then
3266 if not (Placed_Component
3267 or else Present
(SSO_ADC
)
3268 or else Is_Packed
(Rec
))
3270 -- Warn if clause has no effect when no component clause is
3271 -- present, but suppress warning if the Bit_Order is required
3272 -- due to the presence of a Scalar_Storage_Order attribute.
3275 ("??bit order specification has no effect", ADC
);
3277 ("\??since no component clauses were specified", ADC
);
3279 -- Here is where we do the processing to adjust component clauses
3280 -- for reversed bit order, when not using reverse SSO.
3282 elsif Reverse_Bit_Order
(Rec
)
3283 and then not Reverse_Storage_Order
(Rec
)
3285 Adjust_Record_For_Reverse_Bit_Order
(Rec
);
3287 -- Case where we have both an explicit Bit_Order and the same
3288 -- Scalar_Storage_Order: leave record untouched, the back-end
3289 -- will take care of required layout conversions.
3297 -- Complete error checking on record representation clause (e.g.
3298 -- overlap of components). This is called after adjusting the
3299 -- record for reverse bit order.
3302 RRC
: constant Node_Id
:= Get_Record_Representation_Clause
(Rec
);
3304 if Present
(RRC
) then
3305 Check_Record_Representation_Clause
(RRC
);
3309 -- Set OK_To_Reorder_Components depending on debug flags
3311 if Is_Base_Type
(Rec
) and then Convention
(Rec
) = Convention_Ada
then
3312 if (Has_Discriminants
(Rec
) and then Debug_Flag_Dot_V
)
3314 (not Has_Discriminants
(Rec
) and then Debug_Flag_Dot_R
)
3316 Set_OK_To_Reorder_Components
(Rec
);
3320 -- Check for useless pragma Pack when all components placed. We only
3321 -- do this check for record types, not subtypes, since a subtype may
3322 -- have all its components placed, and it still makes perfectly good
3323 -- sense to pack other subtypes or the parent type. We do not give
3324 -- this warning if Optimize_Alignment is set to Space, since the
3325 -- pragma Pack does have an effect in this case (it always resets
3326 -- the alignment to one).
3328 if Ekind
(Rec
) = E_Record_Type
3329 and then Is_Packed
(Rec
)
3330 and then not Unplaced_Component
3331 and then Optimize_Alignment
/= 'S'
3333 -- Reset packed status. Probably not necessary, but we do it so
3334 -- that there is no chance of the back end doing something strange
3335 -- with this redundant indication of packing.
3337 Set_Is_Packed
(Rec
, False);
3339 -- Give warning if redundant constructs warnings on
3341 if Warn_On_Redundant_Constructs
then
3342 Error_Msg_N
-- CODEFIX
3343 ("??pragma Pack has no effect, no unplaced components",
3344 Get_Rep_Pragma
(Rec
, Name_Pack
));
3348 -- If this is the record corresponding to a remote type, freeze the
3349 -- remote type here since that is what we are semantically freezing.
3350 -- This prevents the freeze node for that type in an inner scope.
3352 if Ekind
(Rec
) = E_Record_Type
then
3353 if Present
(Corresponding_Remote_Type
(Rec
)) then
3354 Freeze_And_Append
(Corresponding_Remote_Type
(Rec
), N
, Result
);
3357 -- Check for controlled components and unchecked unions.
3359 Comp
:= First_Component
(Rec
);
3360 while Present
(Comp
) loop
3362 -- Do not set Has_Controlled_Component on a class-wide
3363 -- equivalent type. See Make_CW_Equivalent_Type.
3365 if not Is_Class_Wide_Equivalent_Type
(Rec
)
3367 (Has_Controlled_Component
(Etype
(Comp
))
3369 (Chars
(Comp
) /= Name_uParent
3370 and then Is_Controlled
(Etype
(Comp
)))
3372 (Is_Protected_Type
(Etype
(Comp
))
3374 Present
(Corresponding_Record_Type
(Etype
(Comp
)))
3376 Has_Controlled_Component
3377 (Corresponding_Record_Type
(Etype
(Comp
)))))
3379 Set_Has_Controlled_Component
(Rec
);
3382 if Has_Unchecked_Union
(Etype
(Comp
)) then
3383 Set_Has_Unchecked_Union
(Rec
);
3386 -- Scan component declaration for likely misuses of current
3387 -- instance, either in a constraint or a default expression.
3389 if Has_Per_Object_Constraint
(Comp
) then
3390 Check_Current_Instance
(Parent
(Comp
));
3393 Next_Component
(Comp
);
3397 -- Enforce the restriction that access attributes with a current
3398 -- instance prefix can only apply to limited types. This comment
3399 -- is floating here, but does not seem to belong here???
3401 -- Set component alignment if not otherwise already set
3403 Set_Component_Alignment_If_Not_Set
(Rec
);
3405 -- For first subtypes, check if there are any fixed-point fields with
3406 -- component clauses, where we must check the size. This is not done
3407 -- till the freeze point since for fixed-point types, we do not know
3408 -- the size until the type is frozen. Similar processing applies to
3409 -- bit packed arrays.
3411 if Is_First_Subtype
(Rec
) then
3412 Comp
:= First_Component
(Rec
);
3413 while Present
(Comp
) loop
3414 if Present
(Component_Clause
(Comp
))
3415 and then (Is_Fixed_Point_Type
(Etype
(Comp
))
3416 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
3419 (Component_Name
(Component_Clause
(Comp
)),
3425 Next_Component
(Comp
);
3429 -- Generate warning for applying C or C++ convention to a record
3430 -- with discriminants. This is suppressed for the unchecked union
3431 -- case, since the whole point in this case is interface C. We also
3432 -- do not generate this within instantiations, since we will have
3433 -- generated a message on the template.
3435 if Has_Discriminants
(E
)
3436 and then not Is_Unchecked_Union
(E
)
3437 and then (Convention
(E
) = Convention_C
3439 Convention
(E
) = Convention_CPP
)
3440 and then Comes_From_Source
(E
)
3441 and then not In_Instance
3442 and then not Has_Warnings_Off
(E
)
3443 and then not Has_Warnings_Off
(Base_Type
(E
))
3446 Cprag
: constant Node_Id
:= Get_Rep_Pragma
(E
, Name_Convention
);
3450 if Present
(Cprag
) then
3451 A2
:= Next
(First
(Pragma_Argument_Associations
(Cprag
)));
3453 if Convention
(E
) = Convention_C
then
3455 ("?x?variant record has no direct equivalent in C",
3459 ("?x?variant record has no direct equivalent in C++",
3464 ("\?x?use of convention for type& is dubious", A2
, E
);
3469 -- See if Size is too small as is (and implicit packing might help)
3471 if not Is_Packed
(Rec
)
3473 -- No implicit packing if even one component is explicitly placed
3475 and then not Placed_Component
3477 -- Or even one component is aliased
3479 and then not Aliased_Component
3481 -- Must have size clause and all scalar components
3483 and then Has_Size_Clause
(Rec
)
3484 and then All_Scalar_Components
3486 -- Do not try implicit packing on records with discriminants, too
3487 -- complicated, especially in the variant record case.
3489 and then not Has_Discriminants
(Rec
)
3491 -- We can implicitly pack if the specified size of the record is
3492 -- less than the sum of the object sizes (no point in packing if
3493 -- this is not the case).
3495 and then RM_Size
(Rec
) < Scalar_Component_Total_Esize
3497 -- And the total RM size cannot be greater than the specified size
3498 -- since otherwise packing will not get us where we have to be.
3500 and then RM_Size
(Rec
) >= Scalar_Component_Total_RM_Size
3502 -- Never do implicit packing in CodePeer or SPARK modes since
3503 -- we don't do any packing in these modes, since this generates
3504 -- over-complex code that confuses static analysis, and in
3505 -- general, neither CodePeer not GNATprove care about the
3506 -- internal representation of objects.
3508 and then not (CodePeer_Mode
or GNATprove_Mode
)
3510 -- If implicit packing enabled, do it
3512 if Implicit_Packing
then
3513 Set_Is_Packed
(Rec
);
3515 -- Otherwise flag the size clause
3519 Sz
: constant Node_Id
:= Size_Clause
(Rec
);
3521 Error_Msg_NE
-- CODEFIX
3522 ("size given for& too small", Sz
, Rec
);
3523 Error_Msg_N
-- CODEFIX
3524 ("\use explicit pragma Pack "
3525 & "or use pragma Implicit_Packing", Sz
);
3530 -- The following checks are only relevant when SPARK_Mode is on as
3531 -- they are not standard Ada legality rules.
3533 if SPARK_Mode
= On
then
3534 if Is_Effectively_Volatile
(Rec
) then
3536 -- A discriminated type cannot be effectively volatile
3537 -- (SPARK RM C.6(4)).
3539 if Has_Discriminants
(Rec
) then
3540 Error_Msg_N
("discriminated type & cannot be volatile", Rec
);
3542 -- A tagged type cannot be effectively volatile
3543 -- (SPARK RM C.6(5)).
3545 elsif Is_Tagged_Type
(Rec
) then
3546 Error_Msg_N
("tagged type & cannot be volatile", Rec
);
3549 -- A non-effectively volatile record type cannot contain
3550 -- effectively volatile components (SPARK RM C.6(2)).
3553 Comp
:= First_Component
(Rec
);
3554 while Present
(Comp
) loop
3555 if Comes_From_Source
(Comp
)
3556 and then Is_Effectively_Volatile
(Etype
(Comp
))
3558 Error_Msg_Name_1
:= Chars
(Rec
);
3560 ("component & of non-volatile type % cannot be "
3561 & "volatile", Comp
);
3564 Next_Component
(Comp
);
3569 -- All done if not a full record definition
3571 if Ekind
(Rec
) /= E_Record_Type
then
3575 -- Finally we need to check the variant part to make sure that
3576 -- all types within choices are properly frozen as part of the
3577 -- freezing of the record type.
3579 Check_Variant_Part
: declare
3580 D
: constant Node_Id
:= Declaration_Node
(Rec
);
3585 -- Find component list
3589 if Nkind
(D
) = N_Full_Type_Declaration
then
3590 T
:= Type_Definition
(D
);
3592 if Nkind
(T
) = N_Record_Definition
then
3593 C
:= Component_List
(T
);
3595 elsif Nkind
(T
) = N_Derived_Type_Definition
3596 and then Present
(Record_Extension_Part
(T
))
3598 C
:= Component_List
(Record_Extension_Part
(T
));
3602 -- Case of variant part present
3604 if Present
(C
) and then Present
(Variant_Part
(C
)) then
3605 Freeze_Choices_In_Variant_Part
(Variant_Part
(C
));
3608 -- Note: we used to call Check_Choices here, but it is too early,
3609 -- since predicated subtypes are frozen here, but their freezing
3610 -- actions are in Analyze_Freeze_Entity, which has not been called
3611 -- yet for entities frozen within this procedure, so we moved that
3612 -- call to the Analyze_Freeze_Entity for the record type.
3614 end Check_Variant_Part
;
3615 end Freeze_Record_Type
;
3617 -------------------------------
3618 -- Has_Boolean_Aspect_Import --
3619 -------------------------------
3621 function Has_Boolean_Aspect_Import
(E
: Entity_Id
) return Boolean is
3622 Decl
: constant Node_Id
:= Declaration_Node
(E
);
3627 if Has_Aspects
(Decl
) then
3628 Asp
:= First
(Aspect_Specifications
(Decl
));
3629 while Present
(Asp
) loop
3630 Expr
:= Expression
(Asp
);
3632 -- The value of aspect Import is True when the expression is
3633 -- either missing or it is explicitly set to True.
3635 if Get_Aspect_Id
(Asp
) = Aspect_Import
3637 or else (Compile_Time_Known_Value
(Expr
)
3638 and then Is_True
(Expr_Value
(Expr
))))
3648 end Has_Boolean_Aspect_Import
;
3650 ----------------------------
3651 -- Late_Freeze_Subprogram --
3652 ----------------------------
3654 procedure Late_Freeze_Subprogram
(E
: Entity_Id
) is
3655 Spec
: constant Node_Id
:=
3656 Specification
(Unit_Declaration_Node
(Scope
(E
)));
3660 if Present
(Private_Declarations
(Spec
)) then
3661 Decls
:= Private_Declarations
(Spec
);
3663 Decls
:= Visible_Declarations
(Spec
);
3666 Append_List
(Result
, Decls
);
3667 end Late_Freeze_Subprogram
;
3669 ------------------------------
3670 -- Wrap_Imported_Subprogram --
3671 ------------------------------
3673 -- The issue here is that our normal approach of checking preconditions
3674 -- and postconditions does not work for imported procedures, since we
3675 -- are not generating code for the body. To get around this we create
3676 -- a wrapper, as shown by the following example:
3678 -- procedure K (A : Integer);
3679 -- pragma Import (C, K);
3681 -- The spec is rewritten by removing the effects of pragma Import, but
3682 -- leaving the convention unchanged, as though the source had said:
3684 -- procedure K (A : Integer);
3685 -- pragma Convention (C, K);
3687 -- and we create a body, added to the entity K freeze actions, which
3690 -- procedure K (A : Integer) is
3691 -- procedure K (A : Integer);
3692 -- pragma Import (C, K);
3697 -- Now the contract applies in the normal way to the outer procedure,
3698 -- and the inner procedure has no contracts, so there is no problem
3699 -- in just calling it to get the original effect.
3701 -- In the case of a function, we create an appropriate return statement
3702 -- for the subprogram body that calls the inner procedure.
3704 procedure Wrap_Imported_Subprogram
(E
: Entity_Id
) is
3705 Loc
: constant Source_Ptr
:= Sloc
(E
);
3706 CE
: constant Name_Id
:= Chars
(E
);
3715 -- Nothing to do if not imported
3717 if not Is_Imported
(E
) then
3720 -- Test enabling conditions for wrapping
3722 elsif Is_Subprogram
(E
)
3723 and then Present
(Contract
(E
))
3724 and then Present
(Pre_Post_Conditions
(Contract
(E
)))
3725 and then not GNATprove_Mode
3727 -- Here we do the wrap
3729 -- Note on calls to Copy_Separate_Tree. The trees we are copying
3730 -- here are fully analyzed, but we definitely want fully syntactic
3731 -- unanalyzed trees in the body we construct, so that the analysis
3732 -- generates the right visibility, and that is exactly what the
3733 -- calls to Copy_Separate_Tree give us.
3735 -- Acquire copy of Inline pragma
3737 Iprag
:= Copy_Separate_Tree
(Import_Pragma
(E
));
3739 -- Fix up spec to be not imported any more
3741 Set_Is_Imported
(E
, False);
3742 Set_Interface_Name
(E
, Empty
);
3743 Set_Has_Completion
(E
, False);
3744 Set_Import_Pragma
(E
, Empty
);
3746 -- Grab the subprogram declaration and specification
3748 Spec
:= Declaration_Node
(E
);
3750 -- Build parameter list that we need
3753 Forml
:= First_Formal
(E
);
3754 while Present
(Forml
) loop
3755 Append_To
(Parms
, Make_Identifier
(Loc
, Chars
(Forml
)));
3756 Next_Formal
(Forml
);
3761 if Ekind_In
(E
, E_Function
, E_Generic_Function
) then
3763 Make_Simple_Return_Statement
(Loc
,
3765 Make_Function_Call
(Loc
,
3766 Name
=> Make_Identifier
(Loc
, CE
),
3767 Parameter_Associations
=> Parms
));
3771 Make_Procedure_Call_Statement
(Loc
,
3772 Name
=> Make_Identifier
(Loc
, CE
),
3773 Parameter_Associations
=> Parms
);
3776 -- Now build the body
3779 Make_Subprogram_Body
(Loc
,
3781 Copy_Separate_Tree
(Spec
),
3782 Declarations
=> New_List
(
3783 Make_Subprogram_Declaration
(Loc
,
3785 Copy_Separate_Tree
(Spec
)),
3787 Handled_Statement_Sequence
=>
3788 Make_Handled_Sequence_Of_Statements
(Loc
,
3789 Statements
=> New_List
(Stmt
),
3790 End_Label
=> Make_Identifier
(Loc
, CE
)));
3792 -- Append the body to freeze result
3794 Add_To_Result
(Bod
);
3797 -- Case of imported subprogram that does not get wrapped
3800 -- Set Is_Public. All imported entities need an external symbol
3801 -- created for them since they are always referenced from another
3802 -- object file. Note this used to be set when we set Is_Imported
3803 -- back in Sem_Prag, but now we delay it to this point, since we
3804 -- don't want to set this flag if we wrap an imported subprogram.
3808 end Wrap_Imported_Subprogram
;
3810 -- Start of processing for Freeze_Entity
3813 -- We are going to test for various reasons why this entity need not be
3814 -- frozen here, but in the case of an Itype that's defined within a
3815 -- record, that test actually applies to the record.
3817 if Is_Itype
(E
) and then Is_Record_Type
(Scope
(E
)) then
3818 Test_E
:= Scope
(E
);
3819 elsif Is_Itype
(E
) and then Present
(Underlying_Type
(Scope
(E
)))
3820 and then Is_Record_Type
(Underlying_Type
(Scope
(E
)))
3822 Test_E
:= Underlying_Type
(Scope
(E
));
3825 -- Do not freeze if already frozen since we only need one freeze node
3827 if Is_Frozen
(E
) then
3830 -- It is improper to freeze an external entity within a generic because
3831 -- its freeze node will appear in a non-valid context. The entity will
3832 -- be frozen in the proper scope after the current generic is analyzed.
3833 -- However, aspects must be analyzed because they may be queried later
3834 -- within the generic itself, and the corresponding pragma or attribute
3835 -- definition has not been analyzed yet.
3837 elsif Inside_A_Generic
and then External_Ref_In_Generic
(Test_E
) then
3838 if Has_Delayed_Aspects
(E
) then
3839 Analyze_Aspects_At_Freeze_Point
(E
);
3844 -- AI05-0213: A formal incomplete type does not freeze the actual. In
3845 -- the instance, the same applies to the subtype renaming the actual.
3847 elsif Is_Private_Type
(E
)
3848 and then Is_Generic_Actual_Type
(E
)
3849 and then No
(Full_View
(Base_Type
(E
)))
3850 and then Ada_Version
>= Ada_2012
3854 -- Formal subprograms are never frozen
3856 elsif Is_Formal_Subprogram
(E
) then
3859 -- Generic types are never frozen as they lack delayed semantic checks
3861 elsif Is_Generic_Type
(E
) then
3864 -- Do not freeze a global entity within an inner scope created during
3865 -- expansion. A call to subprogram E within some internal procedure
3866 -- (a stream attribute for example) might require freezing E, but the
3867 -- freeze node must appear in the same declarative part as E itself.
3868 -- The two-pass elaboration mechanism in gigi guarantees that E will
3869 -- be frozen before the inner call is elaborated. We exclude constants
3870 -- from this test, because deferred constants may be frozen early, and
3871 -- must be diagnosed (e.g. in the case of a deferred constant being used
3872 -- in a default expression). If the enclosing subprogram comes from
3873 -- source, or is a generic instance, then the freeze point is the one
3874 -- mandated by the language, and we freeze the entity. A subprogram that
3875 -- is a child unit body that acts as a spec does not have a spec that
3876 -- comes from source, but can only come from source.
3878 elsif In_Open_Scopes
(Scope
(Test_E
))
3879 and then Scope
(Test_E
) /= Current_Scope
3880 and then Ekind
(Test_E
) /= E_Constant
3887 while Present
(S
) loop
3888 if Is_Overloadable
(S
) then
3889 if Comes_From_Source
(S
)
3890 or else Is_Generic_Instance
(S
)
3891 or else Is_Child_Unit
(S
)
3903 -- Similarly, an inlined instance body may make reference to global
3904 -- entities, but these references cannot be the proper freezing point
3905 -- for them, and in the absence of inlining freezing will take place in
3906 -- their own scope. Normally instance bodies are analyzed after the
3907 -- enclosing compilation, and everything has been frozen at the proper
3908 -- place, but with front-end inlining an instance body is compiled
3909 -- before the end of the enclosing scope, and as a result out-of-order
3910 -- freezing must be prevented.
3912 elsif Front_End_Inlining
3913 and then In_Instance_Body
3914 and then Present
(Scope
(Test_E
))
3920 S
:= Scope
(Test_E
);
3921 while Present
(S
) loop
3922 if Is_Generic_Instance
(S
) then
3934 elsif Ekind
(E
) = E_Generic_Package
then
3935 return Freeze_Generic_Entities
(E
);
3938 -- Add checks to detect proper initialization of scalars that may appear
3939 -- as subprogram parameters.
3941 if Is_Subprogram
(E
) and then Check_Validity_Of_Parameters
then
3942 Apply_Parameter_Validity_Checks
(E
);
3945 -- Deal with delayed aspect specifications. The analysis of the aspect
3946 -- is required to be delayed to the freeze point, thus we analyze the
3947 -- pragma or attribute definition clause in the tree at this point. We
3948 -- also analyze the aspect specification node at the freeze point when
3949 -- the aspect doesn't correspond to pragma/attribute definition clause.
3951 if Has_Delayed_Aspects
(E
) then
3952 Analyze_Aspects_At_Freeze_Point
(E
);
3955 -- Here to freeze the entity
3959 -- Case of entity being frozen is other than a type
3961 if not Is_Type
(E
) then
3963 -- If entity is exported or imported and does not have an external
3964 -- name, now is the time to provide the appropriate default name.
3965 -- Skip this if the entity is stubbed, since we don't need a name
3966 -- for any stubbed routine. For the case on intrinsics, if no
3967 -- external name is specified, then calls will be handled in
3968 -- Exp_Intr.Expand_Intrinsic_Call, and no name is needed. If an
3969 -- external name is provided, then Expand_Intrinsic_Call leaves
3970 -- calls in place for expansion by GIGI.
3972 if (Is_Imported
(E
) or else Is_Exported
(E
))
3973 and then No
(Interface_Name
(E
))
3974 and then Convention
(E
) /= Convention_Stubbed
3975 and then Convention
(E
) /= Convention_Intrinsic
3977 Set_Encoded_Interface_Name
3978 (E
, Get_Default_External_Name
(E
));
3980 -- If entity is an atomic object appearing in a declaration and
3981 -- the expression is an aggregate, assign it to a temporary to
3982 -- ensure that the actual assignment is done atomically rather
3983 -- than component-wise (the assignment to the temp may be done
3984 -- component-wise, but that is harmless).
3987 and then Nkind
(Parent
(E
)) = N_Object_Declaration
3988 and then Present
(Expression
(Parent
(E
)))
3989 and then Nkind
(Expression
(Parent
(E
))) = N_Aggregate
3990 and then Is_Atomic_Aggregate
(Expression
(Parent
(E
)), Etype
(E
))
3997 if Is_Subprogram
(E
) then
3999 -- Check for needing to wrap imported subprogram
4001 Wrap_Imported_Subprogram
(E
);
4003 -- Freeze all parameter types and the return type (RM 13.14(14)).
4004 -- However skip this for internal subprograms. This is also where
4005 -- any extra formal parameters are created since we now know
4006 -- whether the subprogram will use a foreign convention.
4008 if not Is_Internal
(E
) then
4012 Warn_Node
: Node_Id
;
4015 -- Loop through formals
4017 Formal
:= First_Formal
(E
);
4018 while Present
(Formal
) loop
4019 F_Type
:= Etype
(Formal
);
4021 -- AI05-0151: incomplete types can appear in a profile.
4022 -- By the time the entity is frozen, the full view must
4023 -- be available, unless it is a limited view.
4025 if Is_Incomplete_Type
(F_Type
)
4026 and then Present
(Full_View
(F_Type
))
4027 and then not From_Limited_With
(F_Type
)
4029 F_Type
:= Full_View
(F_Type
);
4030 Set_Etype
(Formal
, F_Type
);
4033 Freeze_And_Append
(F_Type
, N
, Result
);
4035 if Is_Private_Type
(F_Type
)
4036 and then Is_Private_Type
(Base_Type
(F_Type
))
4037 and then No
(Full_View
(Base_Type
(F_Type
)))
4038 and then not Is_Generic_Type
(F_Type
)
4039 and then not Is_Derived_Type
(F_Type
)
4041 -- If the type of a formal is incomplete, subprogram
4042 -- is being frozen prematurely. Within an instance
4043 -- (but not within a wrapper package) this is an
4044 -- artifact of our need to regard the end of an
4045 -- instantiation as a freeze point. Otherwise it is
4046 -- a definite error.
4049 Set_Is_Frozen
(E
, False);
4052 elsif not After_Last_Declaration
4053 and then not Freezing_Library_Level_Tagged_Type
4055 Error_Msg_Node_1
:= F_Type
;
4057 ("type& must be fully defined before this point",
4062 -- Check suspicious parameter for C function. These tests
4063 -- apply only to exported/imported subprograms.
4065 if Warn_On_Export_Import
4066 and then Comes_From_Source
(E
)
4067 and then (Convention
(E
) = Convention_C
4069 Convention
(E
) = Convention_CPP
)
4070 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4071 and then Convention
(E
) /= Convention
(Formal
)
4072 and then not Has_Warnings_Off
(E
)
4073 and then not Has_Warnings_Off
(F_Type
)
4074 and then not Has_Warnings_Off
(Formal
)
4076 -- Qualify mention of formals with subprogram name
4078 Error_Msg_Qual_Level
:= 1;
4080 -- Check suspicious use of fat C pointer
4082 if Is_Access_Type
(F_Type
)
4083 and then Esize
(F_Type
) > Ttypes
.System_Address_Size
4086 ("?x?type of & does not correspond to C pointer!",
4089 -- Check suspicious return of boolean
4091 elsif Root_Type
(F_Type
) = Standard_Boolean
4092 and then Convention
(F_Type
) = Convention_Ada
4093 and then not Has_Warnings_Off
(F_Type
)
4094 and then not Has_Size_Clause
(F_Type
)
4095 and then VM_Target
= No_VM
4098 ("& is an 8-bit Ada Boolean?x?", Formal
);
4100 ("\use appropriate corresponding type in C "
4101 & "(e.g. char)?x?", Formal
);
4103 -- Check suspicious tagged type
4105 elsif (Is_Tagged_Type
(F_Type
)
4106 or else (Is_Access_Type
(F_Type
)
4109 (Designated_Type
(F_Type
))))
4110 and then Convention
(E
) = Convention_C
4113 ("?x?& involves a tagged type which does not "
4114 & "correspond to any C type!", Formal
);
4116 -- Check wrong convention subprogram pointer
4118 elsif Ekind
(F_Type
) = E_Access_Subprogram_Type
4119 and then not Has_Foreign_Convention
(F_Type
)
4122 ("?x?subprogram pointer & should "
4123 & "have foreign convention!", Formal
);
4124 Error_Msg_Sloc
:= Sloc
(F_Type
);
4126 ("\?x?add Convention pragma to declaration of &#",
4130 -- Turn off name qualification after message output
4132 Error_Msg_Qual_Level
:= 0;
4135 -- Check for unconstrained array in exported foreign
4138 if Has_Foreign_Convention
(E
)
4139 and then not Is_Imported
(E
)
4140 and then Is_Array_Type
(F_Type
)
4141 and then not Is_Constrained
(F_Type
)
4142 and then Warn_On_Export_Import
4144 -- Exclude VM case, since both .NET and JVM can handle
4145 -- unconstrained arrays without a problem.
4147 and then VM_Target
= No_VM
4149 Error_Msg_Qual_Level
:= 1;
4151 -- If this is an inherited operation, place the
4152 -- warning on the derived type declaration, rather
4153 -- than on the original subprogram.
4155 if Nkind
(Original_Node
(Parent
(E
))) =
4156 N_Full_Type_Declaration
4158 Warn_Node
:= Parent
(E
);
4160 if Formal
= First_Formal
(E
) then
4162 ("??in inherited operation&", Warn_Node
, E
);
4165 Warn_Node
:= Formal
;
4169 ("?x?type of argument& is unconstrained array",
4172 ("?x?foreign caller must pass bounds explicitly",
4174 Error_Msg_Qual_Level
:= 0;
4177 if not From_Limited_With
(F_Type
) then
4178 if Is_Access_Type
(F_Type
) then
4179 F_Type
:= Designated_Type
(F_Type
);
4182 -- If the formal is an anonymous_access_to_subprogram
4183 -- freeze the subprogram type as well, to prevent
4184 -- scope anomalies in gigi, because there is no other
4185 -- clear point at which it could be frozen.
4187 if Is_Itype
(Etype
(Formal
))
4188 and then Ekind
(F_Type
) = E_Subprogram_Type
4190 Freeze_And_Append
(F_Type
, N
, Result
);
4194 Next_Formal
(Formal
);
4197 -- Case of function: similar checks on return type
4199 if Ekind
(E
) = E_Function
then
4201 -- Check whether function is declared elsewhere.
4204 Get_Source_Unit
(E
) /= Get_Source_Unit
(N
)
4205 and then Returns_Limited_View
(E
)
4206 and then not In_Open_Scopes
(Scope
(E
));
4208 -- Freeze return type
4210 R_Type
:= Etype
(E
);
4212 -- AI05-0151: the return type may have been incomplete
4213 -- at the point of declaration. Replace it with the full
4214 -- view, unless the current type is a limited view. In
4215 -- that case the full view is in a different unit, and
4216 -- gigi finds the non-limited view after the other unit
4219 if Ekind
(R_Type
) = E_Incomplete_Type
4220 and then Present
(Full_View
(R_Type
))
4221 and then not From_Limited_With
(R_Type
)
4223 R_Type
:= Full_View
(R_Type
);
4224 Set_Etype
(E
, R_Type
);
4226 -- If the return type is a limited view and the non-
4227 -- limited view is still incomplete, the function has
4228 -- to be frozen at a later time.
4230 elsif Ekind
(R_Type
) = E_Incomplete_Type
4231 and then From_Limited_With
(R_Type
)
4233 Ekind
(Non_Limited_View
(R_Type
)) = E_Incomplete_Type
4235 Set_Is_Frozen
(E
, False);
4236 Set_Returns_Limited_View
(E
);
4240 Freeze_And_Append
(R_Type
, N
, Result
);
4242 -- Check suspicious return type for C function
4244 if Warn_On_Export_Import
4245 and then (Convention
(E
) = Convention_C
4247 Convention
(E
) = Convention_CPP
)
4248 and then (Is_Imported
(E
) or else Is_Exported
(E
))
4250 -- Check suspicious return of fat C pointer
4252 if Is_Access_Type
(R_Type
)
4253 and then Esize
(R_Type
) > Ttypes
.System_Address_Size
4254 and then not Has_Warnings_Off
(E
)
4255 and then not Has_Warnings_Off
(R_Type
)
4258 ("?x?return type of& does not "
4259 & "correspond to C pointer!", E
);
4261 -- Check suspicious return of boolean
4263 elsif Root_Type
(R_Type
) = Standard_Boolean
4264 and then Convention
(R_Type
) = Convention_Ada
4265 and then VM_Target
= No_VM
4266 and then not Has_Warnings_Off
(E
)
4267 and then not Has_Warnings_Off
(R_Type
)
4268 and then not Has_Size_Clause
(R_Type
)
4271 N
: constant Node_Id
:=
4272 Result_Definition
(Declaration_Node
(E
));
4275 ("return type of & is an 8-bit Ada Boolean?x?",
4278 ("\use appropriate corresponding type in C "
4279 & "(e.g. char)?x?", N
, E
);
4282 -- Check suspicious return tagged type
4284 elsif (Is_Tagged_Type
(R_Type
)
4285 or else (Is_Access_Type
(R_Type
)
4288 (Designated_Type
(R_Type
))))
4289 and then Convention
(E
) = Convention_C
4290 and then not Has_Warnings_Off
(E
)
4291 and then not Has_Warnings_Off
(R_Type
)
4294 ("?x?return type of & does not "
4295 & "correspond to C type!", E
);
4297 -- Check return of wrong convention subprogram pointer
4299 elsif Ekind
(R_Type
) = E_Access_Subprogram_Type
4300 and then not Has_Foreign_Convention
(R_Type
)
4301 and then not Has_Warnings_Off
(E
)
4302 and then not Has_Warnings_Off
(R_Type
)
4305 ("?x?& should return a foreign "
4306 & "convention subprogram pointer", E
);
4307 Error_Msg_Sloc
:= Sloc
(R_Type
);
4309 ("\?x?add Convention pragma to declaration of& #",
4314 -- Give warning for suspicious return of a result of an
4315 -- unconstrained array type in a foreign convention
4318 if Has_Foreign_Convention
(E
)
4320 -- We are looking for a return of unconstrained array
4322 and then Is_Array_Type
(R_Type
)
4323 and then not Is_Constrained
(R_Type
)
4325 -- Exclude imported routines, the warning does not
4326 -- belong on the import, but rather on the routine
4329 and then not Is_Imported
(E
)
4331 -- Exclude VM case, since both .NET and JVM can handle
4332 -- return of unconstrained arrays without a problem.
4334 and then VM_Target
= No_VM
4336 -- Check that general warning is enabled, and that it
4337 -- is not suppressed for this particular case.
4339 and then Warn_On_Export_Import
4340 and then not Has_Warnings_Off
(E
)
4341 and then not Has_Warnings_Off
(R_Type
)
4344 ("?x?foreign convention function& should not " &
4345 "return unconstrained array!", E
);
4351 -- Must freeze its parent first if it is a derived subprogram
4353 if Present
(Alias
(E
)) then
4354 Freeze_And_Append
(Alias
(E
), N
, Result
);
4357 -- We don't freeze internal subprograms, because we don't normally
4358 -- want addition of extra formals or mechanism setting to happen
4359 -- for those. However we do pass through predefined dispatching
4360 -- cases, since extra formals may be needed in some cases, such as
4361 -- for the stream 'Input function (build-in-place formals).
4363 if not Is_Internal
(E
)
4364 or else Is_Predefined_Dispatching_Operation
(E
)
4366 Freeze_Subprogram
(E
);
4369 if Late_Freezing
then
4370 Late_Freeze_Subprogram
(E
);
4374 -- If warning on suspicious contracts then check for the case of
4375 -- a postcondition other than False for a No_Return subprogram.
4378 and then Warn_On_Suspicious_Contract
4379 and then Present
(Contract
(E
))
4382 Prag
: Node_Id
:= Pre_Post_Conditions
(Contract
(E
));
4386 while Present
(Prag
) loop
4387 if Nam_In
(Pragma_Name
(Prag
), Name_Post
,
4393 (First
(Pragma_Argument_Associations
(Prag
)));
4395 if Nkind
(Exp
) /= N_Identifier
4396 or else Chars
(Exp
) /= Name_False
4399 ("useless postcondition, & is marked "
4400 & "No_Return?T?", Exp
, E
);
4404 Prag
:= Next_Pragma
(Prag
);
4409 -- Here for other than a subprogram or type
4412 -- If entity has a type, and it is not a generic unit, then
4413 -- freeze it first (RM 13.14(10)).
4415 if Present
(Etype
(E
))
4416 and then Ekind
(E
) /= E_Generic_Function
4418 Freeze_And_Append
(Etype
(E
), N
, Result
);
4421 -- Special processing for objects created by object declaration
4423 if Nkind
(Declaration_Node
(E
)) = N_Object_Declaration
then
4425 -- Abstract type allowed only for C++ imported variables or
4428 -- Note: we inhibit this check for objects that do not come
4429 -- from source because there is at least one case (the
4430 -- expansion of x'Class'Input where x is abstract) where we
4431 -- legitimately generate an abstract object.
4433 if Is_Abstract_Type
(Etype
(E
))
4434 and then Comes_From_Source
(Parent
(E
))
4435 and then not (Is_Imported
(E
)
4436 and then Is_CPP_Class
(Etype
(E
)))
4438 Error_Msg_N
("type of object cannot be abstract",
4439 Object_Definition
(Parent
(E
)));
4441 if Is_CPP_Class
(Etype
(E
)) then
4443 ("\} may need a cpp_constructor",
4444 Object_Definition
(Parent
(E
)), Etype
(E
));
4448 -- For object created by object declaration, perform required
4449 -- categorization (preelaborate and pure) checks. Defer these
4450 -- checks to freeze time since pragma Import inhibits default
4451 -- initialization and thus pragma Import affects these checks.
4453 Validate_Object_Declaration
(Declaration_Node
(E
));
4455 -- If there is an address clause, check that it is valid
4457 Check_Address_Clause
(E
);
4459 -- Reset Is_True_Constant for aliased object. We consider that
4460 -- the fact that something is aliased may indicate that some
4461 -- funny business is going on, e.g. an aliased object is passed
4462 -- by reference to a procedure which captures the address of
4463 -- the object, which is later used to assign a new value. Such
4464 -- code is highly dubious, but we choose to make it "work" for
4467 -- However, we don't do that for internal entities. We figure
4468 -- that if we deliberately set Is_True_Constant for an internal
4469 -- entity, e.g. a dispatch table entry, then we mean it.
4471 if (Is_Aliased
(E
) or else Is_Aliased
(Etype
(E
)))
4472 and then not Is_Internal_Name
(Chars
(E
))
4474 Set_Is_True_Constant
(E
, False);
4477 -- If the object needs any kind of default initialization, an
4478 -- error must be issued if No_Default_Initialization applies.
4479 -- The check doesn't apply to imported objects, which are not
4480 -- ever default initialized, and is why the check is deferred
4481 -- until freezing, at which point we know if Import applies.
4482 -- Deferred constants are also exempted from this test because
4483 -- their completion is explicit, or through an import pragma.
4485 if Ekind
(E
) = E_Constant
4486 and then Present
(Full_View
(E
))
4490 elsif Comes_From_Source
(E
)
4491 and then not Is_Imported
(E
)
4492 and then not Has_Init_Expression
(Declaration_Node
(E
))
4494 ((Has_Non_Null_Base_Init_Proc
(Etype
(E
))
4495 and then not No_Initialization
(Declaration_Node
(E
))
4496 and then not Is_Value_Type
(Etype
(E
))
4497 and then not Initialization_Suppressed
(Etype
(E
)))
4499 (Needs_Simple_Initialization
(Etype
(E
))
4500 and then not Is_Internal
(E
)))
4502 Has_Default_Initialization
:= True;
4504 (No_Default_Initialization
, Declaration_Node
(E
));
4507 -- Check that a Thread_Local_Storage variable does not have
4508 -- default initialization, and any explicit initialization must
4509 -- either be the null constant or a static constant.
4511 if Has_Pragma_Thread_Local_Storage
(E
) then
4513 Decl
: constant Node_Id
:= Declaration_Node
(E
);
4515 if Has_Default_Initialization
4517 (Has_Init_Expression
(Decl
)
4519 (No
(Expression
(Decl
))
4521 (Is_OK_Static_Expression
(Expression
(Decl
))
4523 Nkind
(Expression
(Decl
)) = N_Null
)))
4526 ("Thread_Local_Storage variable& is "
4527 & "improperly initialized", Decl
, E
);
4529 ("\only allowed initialization is explicit "
4530 & "NULL or static expression", Decl
, E
);
4535 -- For imported objects, set Is_Public unless there is also an
4536 -- address clause, which means that there is no external symbol
4537 -- needed for the Import (Is_Public may still be set for other
4538 -- unrelated reasons). Note that we delayed this processing
4539 -- till freeze time so that we can be sure not to set the flag
4540 -- if there is an address clause. If there is such a clause,
4541 -- then the only purpose of the Import pragma is to suppress
4542 -- implicit initialization.
4544 if Is_Imported
(E
) and then No
(Address_Clause
(E
)) then
4548 -- For source objects that are not Imported and are library
4549 -- level, if no linker section pragma was given inherit the
4550 -- appropriate linker section from the corresponding type.
4552 if Comes_From_Source
(E
)
4553 and then not Is_Imported
(E
)
4554 and then Is_Library_Level_Entity
(E
)
4555 and then No
(Linker_Section_Pragma
(E
))
4557 Set_Linker_Section_Pragma
4558 (E
, Linker_Section_Pragma
(Etype
(E
)));
4561 -- For convention C objects of an enumeration type, warn if
4562 -- the size is not integer size and no explicit size given.
4563 -- Skip warning for Boolean, and Character, assume programmer
4564 -- expects 8-bit sizes for these cases.
4566 if (Convention
(E
) = Convention_C
4568 Convention
(E
) = Convention_CPP
)
4569 and then Is_Enumeration_Type
(Etype
(E
))
4570 and then not Is_Character_Type
(Etype
(E
))
4571 and then not Is_Boolean_Type
(Etype
(E
))
4572 and then Esize
(Etype
(E
)) < Standard_Integer_Size
4573 and then not Has_Size_Clause
(E
)
4575 Error_Msg_Uint_1
:= UI_From_Int
(Standard_Integer_Size
);
4577 ("??convention C enumeration object has size less than ^",
4579 Error_Msg_N
("\??use explicit size clause to set size", E
);
4583 -- Check that a constant which has a pragma Volatile[_Components]
4584 -- or Atomic[_Components] also has a pragma Import (RM C.6(13)).
4586 -- Note: Atomic[_Components] also sets Volatile[_Components]
4588 if Ekind
(E
) = E_Constant
4589 and then (Has_Volatile_Components
(E
) or else Is_Volatile
(E
))
4590 and then not Is_Imported
(E
)
4591 and then not Has_Boolean_Aspect_Import
(E
)
4593 -- Make sure we actually have a pragma, and have not merely
4594 -- inherited the indication from elsewhere (e.g. an address
4595 -- clause, which is not good enough in RM terms).
4597 if Has_Rep_Pragma
(E
, Name_Atomic
)
4599 Has_Rep_Pragma
(E
, Name_Atomic_Components
)
4602 ("stand alone atomic constant must be " &
4603 "imported (RM C.6(13))", E
);
4605 elsif Has_Rep_Pragma
(E
, Name_Volatile
)
4607 Has_Rep_Pragma
(E
, Name_Volatile_Components
)
4610 ("stand alone volatile constant must be " &
4611 "imported (RM C.6(13))", E
);
4615 -- Static objects require special handling
4617 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
4618 and then Is_Statically_Allocated
(E
)
4620 Freeze_Static_Object
(E
);
4623 -- Remaining step is to layout objects
4625 if Ekind_In
(E
, E_Variable
, E_Constant
, E_Loop_Parameter
)
4626 or else Is_Formal
(E
)
4631 -- For an object that does not have delayed freezing, and whose
4632 -- initialization actions have been captured in a compound
4633 -- statement, move them back now directly within the enclosing
4634 -- statement sequence.
4636 if Ekind_In
(E
, E_Constant
, E_Variable
)
4637 and then not Has_Delayed_Freeze
(E
)
4639 Explode_Initialization_Compound_Statement
(E
);
4643 -- Case of a type or subtype being frozen
4646 -- We used to check here that a full type must have preelaborable
4647 -- initialization if it completes a private type specified with
4648 -- pragma Preelaborable_Initialization, but that missed cases where
4649 -- the types occur within a generic package, since the freezing
4650 -- that occurs within a containing scope generally skips traversal
4651 -- of a generic unit's declarations (those will be frozen within
4652 -- instances). This check was moved to Analyze_Package_Specification.
4654 -- The type may be defined in a generic unit. This can occur when
4655 -- freezing a generic function that returns the type (which is
4656 -- defined in a parent unit). It is clearly meaningless to freeze
4657 -- this type. However, if it is a subtype, its size may be determi-
4658 -- nable and used in subsequent checks, so might as well try to
4661 -- In Ada 2012, Freeze_Entities is also used in the front end to
4662 -- trigger the analysis of aspect expressions, so in this case we
4663 -- want to continue the freezing process.
4665 if Present
(Scope
(E
))
4666 and then Is_Generic_Unit
(Scope
(E
))
4668 (not Has_Predicates
(E
)
4669 and then not Has_Delayed_Freeze
(E
))
4671 Check_Compile_Time_Size
(E
);
4675 -- Check for error of Type_Invariant'Class applied to an untagged
4676 -- type (check delayed to freeze time when full type is available).
4679 Prag
: constant Node_Id
:= Get_Pragma
(E
, Pragma_Invariant
);
4682 and then Class_Present
(Prag
)
4683 and then not Is_Tagged_Type
(E
)
4686 ("Type_Invariant''Class cannot be specified for &",
4689 ("\can only be specified for a tagged type", Prag
);
4693 -- Deal with special cases of freezing for subtype
4695 if E
/= Base_Type
(E
) then
4697 -- Before we do anything else, a specialized test for the case of
4698 -- a size given for an array where the array needs to be packed,
4699 -- but was not so the size cannot be honored. This is the case
4700 -- where implicit packing may apply. The reason we do this so
4701 -- early is that if we have implicit packing, the layout of the
4702 -- base type is affected, so we must do this before we freeze
4705 -- We could do this processing only if implicit packing is enabled
4706 -- since in all other cases, the error would be caught by the back
4707 -- end. However, we choose to do the check even if we do not have
4708 -- implicit packing enabled, since this allows us to give a more
4709 -- useful error message (advising use of pragmas Implicit_Packing
4712 if Is_Array_Type
(E
) then
4714 Ctyp
: constant Entity_Id
:= Component_Type
(E
);
4715 Rsiz
: constant Uint
:= RM_Size
(Ctyp
);
4716 SZ
: constant Node_Id
:= Size_Clause
(E
);
4717 Btyp
: constant Entity_Id
:= Base_Type
(E
);
4724 -- Number of elements in array
4727 -- Check enabling conditions. These are straightforward
4728 -- except for the test for a limited composite type. This
4729 -- eliminates the rare case of a array of limited components
4730 -- where there are issues of whether or not we can go ahead
4731 -- and pack the array (since we can't freely pack and unpack
4732 -- arrays if they are limited).
4734 -- Note that we check the root type explicitly because the
4735 -- whole point is we are doing this test before we have had
4736 -- a chance to freeze the base type (and it is that freeze
4737 -- action that causes stuff to be inherited).
4739 if Has_Size_Clause
(E
)
4740 and then Known_Static_RM_Size
(E
)
4741 and then not Is_Packed
(E
)
4742 and then not Has_Pragma_Pack
(E
)
4743 and then not Has_Component_Size_Clause
(E
)
4744 and then Known_Static_RM_Size
(Ctyp
)
4745 and then RM_Size
(Ctyp
) < 64
4746 and then not Is_Limited_Composite
(E
)
4747 and then not Is_Packed
(Root_Type
(E
))
4748 and then not Has_Component_Size_Clause
(Root_Type
(E
))
4749 and then not (CodePeer_Mode
or GNATprove_Mode
)
4751 -- Compute number of elements in array
4753 Num_Elmts
:= Uint_1
;
4754 Indx
:= First_Index
(E
);
4755 while Present
(Indx
) loop
4756 Get_Index_Bounds
(Indx
, Lo
, Hi
);
4758 if not (Compile_Time_Known_Value
(Lo
)
4760 Compile_Time_Known_Value
(Hi
))
4762 goto No_Implicit_Packing
;
4768 Expr_Value
(Hi
) - Expr_Value
(Lo
) + 1);
4772 -- What we are looking for here is the situation where
4773 -- the RM_Size given would be exactly right if there was
4774 -- a pragma Pack (resulting in the component size being
4775 -- the same as the RM_Size). Furthermore, the component
4776 -- type size must be an odd size (not a multiple of
4777 -- storage unit). If the component RM size is an exact
4778 -- number of storage units that is a power of two, the
4779 -- array is not packed and has a standard representation.
4781 if RM_Size
(E
) = Num_Elmts
* Rsiz
4782 and then Rsiz
mod System_Storage_Unit
/= 0
4784 -- For implicit packing mode, just set the component
4787 if Implicit_Packing
then
4788 Set_Component_Size
(Btyp
, Rsiz
);
4789 Set_Is_Bit_Packed_Array
(Btyp
);
4790 Set_Is_Packed
(Btyp
);
4791 Set_Has_Non_Standard_Rep
(Btyp
);
4793 -- Otherwise give an error message
4797 ("size given for& too small", SZ
, E
);
4798 Error_Msg_N
-- CODEFIX
4799 ("\use explicit pragma Pack "
4800 & "or use pragma Implicit_Packing", SZ
);
4803 elsif RM_Size
(E
) = Num_Elmts
* Rsiz
4804 and then Implicit_Packing
4806 (Rsiz
/ System_Storage_Unit
= 1
4808 Rsiz
/ System_Storage_Unit
= 2
4810 Rsiz
/ System_Storage_Unit
= 4)
4812 -- Not a packed array, but indicate the desired
4813 -- component size, for the back-end.
4815 Set_Component_Size
(Btyp
, Rsiz
);
4821 <<No_Implicit_Packing
>>
4823 -- If ancestor subtype present, freeze that first. Note that this
4824 -- will also get the base type frozen. Need RM reference ???
4826 Atype
:= Ancestor_Subtype
(E
);
4828 if Present
(Atype
) then
4829 Freeze_And_Append
(Atype
, N
, Result
);
4831 -- No ancestor subtype present
4834 -- See if we have a nearest ancestor that has a predicate.
4835 -- That catches the case of derived type with a predicate.
4836 -- Need RM reference here ???
4838 Atype
:= Nearest_Ancestor
(E
);
4840 if Present
(Atype
) and then Has_Predicates
(Atype
) then
4841 Freeze_And_Append
(Atype
, N
, Result
);
4844 -- Freeze base type before freezing the entity (RM 13.14(15))
4846 if E
/= Base_Type
(E
) then
4847 Freeze_And_Append
(Base_Type
(E
), N
, Result
);
4851 -- A subtype inherits all the type-related representation aspects
4852 -- from its parents (RM 13.1(8)).
4854 Inherit_Aspects_At_Freeze_Point
(E
);
4856 -- For a derived type, freeze its parent type first (RM 13.14(15))
4858 elsif Is_Derived_Type
(E
) then
4859 Freeze_And_Append
(Etype
(E
), N
, Result
);
4860 Freeze_And_Append
(First_Subtype
(Etype
(E
)), N
, Result
);
4862 -- A derived type inherits each type-related representation aspect
4863 -- of its parent type that was directly specified before the
4864 -- declaration of the derived type (RM 13.1(15)).
4866 Inherit_Aspects_At_Freeze_Point
(E
);
4869 -- Check for incompatible size and alignment for record type
4871 if Warn_On_Size_Alignment
4872 and then Is_Record_Type
(E
)
4873 and then Has_Size_Clause
(E
) and then Has_Alignment_Clause
(E
)
4875 -- If explicit Object_Size clause given assume that the programmer
4876 -- knows what he is doing, and expects the compiler behavior.
4878 and then not Has_Object_Size_Clause
(E
)
4880 -- Check for size not a multiple of alignment
4882 and then RM_Size
(E
) mod (Alignment
(E
) * System_Storage_Unit
) /= 0
4885 SC
: constant Node_Id
:= Size_Clause
(E
);
4886 AC
: constant Node_Id
:= Alignment_Clause
(E
);
4888 Abits
: constant Uint
:= Alignment
(E
) * System_Storage_Unit
;
4891 if Present
(SC
) and then Present
(AC
) then
4895 if Sloc
(SC
) > Sloc
(AC
) then
4898 ("??size is not a multiple of alignment for &", Loc
, E
);
4899 Error_Msg_Sloc
:= Sloc
(AC
);
4900 Error_Msg_Uint_1
:= Alignment
(E
);
4901 Error_Msg_N
("\??alignment of ^ specified #", Loc
);
4906 ("??size is not a multiple of alignment for &", Loc
, E
);
4907 Error_Msg_Sloc
:= Sloc
(SC
);
4908 Error_Msg_Uint_1
:= RM_Size
(E
);
4909 Error_Msg_N
("\??size of ^ specified #", Loc
);
4912 Error_Msg_Uint_1
:= ((RM_Size
(E
) / Abits
) + 1) * Abits
;
4913 Error_Msg_N
("\??Object_Size will be increased to ^", Loc
);
4920 if Is_Array_Type
(E
) then
4921 Freeze_Array_Type
(E
);
4923 -- For a class-wide type, the corresponding specific type is
4924 -- frozen as well (RM 13.14(15))
4926 elsif Is_Class_Wide_Type
(E
) then
4927 Freeze_And_Append
(Root_Type
(E
), N
, Result
);
4929 -- If the base type of the class-wide type is still incomplete,
4930 -- the class-wide remains unfrozen as well. This is legal when
4931 -- E is the formal of a primitive operation of some other type
4932 -- which is being frozen.
4934 if not Is_Frozen
(Root_Type
(E
)) then
4935 Set_Is_Frozen
(E
, False);
4939 -- The equivalent type associated with a class-wide subtype needs
4940 -- to be frozen to ensure that its layout is done.
4942 if Ekind
(E
) = E_Class_Wide_Subtype
4943 and then Present
(Equivalent_Type
(E
))
4945 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
4948 -- Generate an itype reference for a library-level class-wide type
4949 -- at the freeze point. Otherwise the first explicit reference to
4950 -- the type may appear in an inner scope which will be rejected by
4954 and then Is_Compilation_Unit
(Scope
(E
))
4957 Ref
: constant Node_Id
:= Make_Itype_Reference
(Loc
);
4962 -- From a gigi point of view, a class-wide subtype derives
4963 -- from its record equivalent type. As a result, the itype
4964 -- reference must appear after the freeze node of the
4965 -- equivalent type or gigi will reject the reference.
4967 if Ekind
(E
) = E_Class_Wide_Subtype
4968 and then Present
(Equivalent_Type
(E
))
4970 Insert_After
(Freeze_Node
(Equivalent_Type
(E
)), Ref
);
4972 Add_To_Result
(Ref
);
4977 -- For a record type or record subtype, freeze all component types
4978 -- (RM 13.14(15)). We test for E_Record_(sub)Type here, rather than
4979 -- using Is_Record_Type, because we don't want to attempt the freeze
4980 -- for the case of a private type with record extension (we will do
4981 -- that later when the full type is frozen).
4983 elsif Ekind_In
(E
, E_Record_Type
, E_Record_Subtype
)
4984 and then not Is_Generic_Unit
(Scope
(E
))
4986 Freeze_Record_Type
(E
);
4988 -- For a concurrent type, freeze corresponding record type. This does
4989 -- not correspond to any specific rule in the RM, but the record type
4990 -- is essentially part of the concurrent type. Also freeze all local
4991 -- entities. This includes record types created for entry parameter
4992 -- blocks and whatever local entities may appear in the private part.
4994 elsif Is_Concurrent_Type
(E
) then
4995 if Present
(Corresponding_Record_Type
(E
)) then
4996 Freeze_And_Append
(Corresponding_Record_Type
(E
), N
, Result
);
4999 Comp
:= First_Entity
(E
);
5000 while Present
(Comp
) loop
5001 if Is_Type
(Comp
) then
5002 Freeze_And_Append
(Comp
, N
, Result
);
5004 elsif (Ekind
(Comp
)) /= E_Function
then
5006 -- The guard on the presence of the Etype seems to be needed
5007 -- for some CodePeer (-gnatcC) cases, but not clear why???
5009 if Present
(Etype
(Comp
)) then
5010 if Is_Itype
(Etype
(Comp
))
5011 and then Underlying_Type
(Scope
(Etype
(Comp
))) = E
5013 Undelay_Type
(Etype
(Comp
));
5016 Freeze_And_Append
(Etype
(Comp
), N
, Result
);
5023 -- Private types are required to point to the same freeze node as
5024 -- their corresponding full views. The freeze node itself has to
5025 -- point to the partial view of the entity (because from the partial
5026 -- view, we can retrieve the full view, but not the reverse).
5027 -- However, in order to freeze correctly, we need to freeze the full
5028 -- view. If we are freezing at the end of a scope (or within the
5029 -- scope) of the private type, the partial and full views will have
5030 -- been swapped, the full view appears first in the entity chain and
5031 -- the swapping mechanism ensures that the pointers are properly set
5034 -- If we encounter the partial view before the full view (e.g. when
5035 -- freezing from another scope), we freeze the full view, and then
5036 -- set the pointers appropriately since we cannot rely on swapping to
5037 -- fix things up (subtypes in an outer scope might not get swapped).
5039 -- If the full view is itself private, the above requirements apply
5040 -- to the underlying full view instead of the full view. But there is
5041 -- no swapping mechanism for the underlying full view so we need to
5042 -- set the pointers appropriately in both cases.
5044 elsif Is_Incomplete_Or_Private_Type
(E
)
5045 and then not Is_Generic_Type
(E
)
5047 -- The construction of the dispatch table associated with library
5048 -- level tagged types forces freezing of all the primitives of the
5049 -- type, which may cause premature freezing of the partial view.
5053 -- type T is tagged private;
5054 -- type DT is new T with private;
5055 -- procedure Prim (X : in out T; Y : in out DT'Class);
5057 -- type T is tagged null record;
5059 -- type DT is new T with null record;
5062 -- In this case the type will be frozen later by the usual
5063 -- mechanism: an object declaration, an instantiation, or the
5064 -- end of a declarative part.
5066 if Is_Library_Level_Tagged_Type
(E
)
5067 and then not Present
(Full_View
(E
))
5069 Set_Is_Frozen
(E
, False);
5072 -- Case of full view present
5074 elsif Present
(Full_View
(E
)) then
5076 -- If full view has already been frozen, then no further
5077 -- processing is required
5079 if Is_Frozen
(Full_View
(E
)) then
5080 Set_Has_Delayed_Freeze
(E
, False);
5081 Set_Freeze_Node
(E
, Empty
);
5083 -- Otherwise freeze full view and patch the pointers so that
5084 -- the freeze node will elaborate both views in the back end.
5085 -- However, if full view is itself private, freeze underlying
5086 -- full view instead and patch the pointers so that the freeze
5087 -- node will elaborate the three views in the back end.
5091 Full
: Entity_Id
:= Full_View
(E
);
5094 if Is_Private_Type
(Full
)
5095 and then Present
(Underlying_Full_View
(Full
))
5097 Full
:= Underlying_Full_View
(Full
);
5100 Freeze_And_Append
(Full
, N
, Result
);
5102 if Full
/= Full_View
(E
)
5103 and then Has_Delayed_Freeze
(Full_View
(E
))
5105 F_Node
:= Freeze_Node
(Full
);
5107 if Present
(F_Node
) then
5108 Set_Freeze_Node
(Full_View
(E
), F_Node
);
5109 Set_Entity
(F_Node
, Full_View
(E
));
5112 Set_Has_Delayed_Freeze
(Full_View
(E
), False);
5113 Set_Freeze_Node
(Full_View
(E
), Empty
);
5117 if Has_Delayed_Freeze
(E
) then
5118 F_Node
:= Freeze_Node
(Full_View
(E
));
5120 if Present
(F_Node
) then
5121 Set_Freeze_Node
(E
, F_Node
);
5122 Set_Entity
(F_Node
, E
);
5125 -- {Incomplete,Private}_Subtypes with Full_Views
5126 -- constrained by discriminants.
5128 Set_Has_Delayed_Freeze
(E
, False);
5129 Set_Freeze_Node
(E
, Empty
);
5135 Check_Debug_Info_Needed
(E
);
5137 -- AI-117 requires that the convention of a partial view be the
5138 -- same as the convention of the full view. Note that this is a
5139 -- recognized breach of privacy, but it's essential for logical
5140 -- consistency of representation, and the lack of a rule in
5141 -- RM95 was an oversight.
5143 Set_Convention
(E
, Convention
(Full_View
(E
)));
5145 Set_Size_Known_At_Compile_Time
(E
,
5146 Size_Known_At_Compile_Time
(Full_View
(E
)));
5148 -- Size information is copied from the full view to the
5149 -- incomplete or private view for consistency.
5151 -- We skip this is the full view is not a type. This is very
5152 -- strange of course, and can only happen as a result of
5153 -- certain illegalities, such as a premature attempt to derive
5154 -- from an incomplete type.
5156 if Is_Type
(Full_View
(E
)) then
5157 Set_Size_Info
(E
, Full_View
(E
));
5158 Set_RM_Size
(E
, RM_Size
(Full_View
(E
)));
5163 -- Case of underlying full view present
5165 elsif Is_Private_Type
(E
)
5166 and then Present
(Underlying_Full_View
(E
))
5168 if not Is_Frozen
(Underlying_Full_View
(E
)) then
5169 Freeze_And_Append
(Underlying_Full_View
(E
), N
, Result
);
5172 -- Patch the pointers so that the freeze node will elaborate
5173 -- both views in the back end.
5175 if Has_Delayed_Freeze
(E
) then
5176 F_Node
:= Freeze_Node
(Underlying_Full_View
(E
));
5178 if Present
(F_Node
) then
5179 Set_Freeze_Node
(E
, F_Node
);
5180 Set_Entity
(F_Node
, E
);
5183 Set_Has_Delayed_Freeze
(E
, False);
5184 Set_Freeze_Node
(E
, Empty
);
5188 Check_Debug_Info_Needed
(E
);
5192 -- Case of no full view present. If entity is derived or subtype,
5193 -- it is safe to freeze, correctness depends on the frozen status
5194 -- of parent. Otherwise it is either premature usage, or a Taft
5195 -- amendment type, so diagnosis is at the point of use and the
5196 -- type might be frozen later.
5198 elsif E
/= Base_Type
(E
) or else Is_Derived_Type
(E
) then
5202 Set_Is_Frozen
(E
, False);
5206 -- For access subprogram, freeze types of all formals, the return
5207 -- type was already frozen, since it is the Etype of the function.
5208 -- Formal types can be tagged Taft amendment types, but otherwise
5209 -- they cannot be incomplete.
5211 elsif Ekind
(E
) = E_Subprogram_Type
then
5212 Formal
:= First_Formal
(E
);
5213 while Present
(Formal
) loop
5214 if Ekind
(Etype
(Formal
)) = E_Incomplete_Type
5215 and then No
(Full_View
(Etype
(Formal
)))
5216 and then not Is_Value_Type
(Etype
(Formal
))
5218 if Is_Tagged_Type
(Etype
(Formal
)) then
5221 -- AI05-151: Incomplete types are allowed in access to
5222 -- subprogram specifications.
5224 elsif Ada_Version
< Ada_2012
then
5226 ("invalid use of incomplete type&", E
, Etype
(Formal
));
5230 Freeze_And_Append
(Etype
(Formal
), N
, Result
);
5231 Next_Formal
(Formal
);
5234 Freeze_Subprogram
(E
);
5236 -- For access to a protected subprogram, freeze the equivalent type
5237 -- (however this is not set if we are not generating code or if this
5238 -- is an anonymous type used just for resolution).
5240 elsif Is_Access_Protected_Subprogram_Type
(E
) then
5241 if Present
(Equivalent_Type
(E
)) then
5242 Freeze_And_Append
(Equivalent_Type
(E
), N
, Result
);
5246 -- Generic types are never seen by the back-end, and are also not
5247 -- processed by the expander (since the expander is turned off for
5248 -- generic processing), so we never need freeze nodes for them.
5250 if Is_Generic_Type
(E
) then
5254 -- Some special processing for non-generic types to complete
5255 -- representation details not known till the freeze point.
5257 if Is_Fixed_Point_Type
(E
) then
5258 Freeze_Fixed_Point_Type
(E
);
5260 -- Some error checks required for ordinary fixed-point type. Defer
5261 -- these till the freeze-point since we need the small and range
5262 -- values. We only do these checks for base types
5264 if Is_Ordinary_Fixed_Point_Type
(E
) and then Is_Base_Type
(E
) then
5265 if Small_Value
(E
) < Ureal_2_M_80
then
5266 Error_Msg_Name_1
:= Name_Small
;
5268 ("`&''%` too small, minimum allowed is 2.0'*'*(-80)", E
);
5270 elsif Small_Value
(E
) > Ureal_2_80
then
5271 Error_Msg_Name_1
:= Name_Small
;
5273 ("`&''%` too large, maximum allowed is 2.0'*'*80", E
);
5276 if Expr_Value_R
(Type_Low_Bound
(E
)) < Ureal_M_10_36
then
5277 Error_Msg_Name_1
:= Name_First
;
5279 ("`&''%` too small, minimum allowed is -10.0'*'*36", E
);
5282 if Expr_Value_R
(Type_High_Bound
(E
)) > Ureal_10_36
then
5283 Error_Msg_Name_1
:= Name_Last
;
5285 ("`&''%` too large, maximum allowed is 10.0'*'*36", E
);
5289 elsif Is_Enumeration_Type
(E
) then
5290 Freeze_Enumeration_Type
(E
);
5292 elsif Is_Integer_Type
(E
) then
5293 Adjust_Esize_For_Alignment
(E
);
5295 if Is_Modular_Integer_Type
(E
)
5296 and then Warn_On_Suspicious_Modulus_Value
5298 Check_Suspicious_Modulus
(E
);
5301 elsif Is_Access_Type
(E
)
5302 and then not Is_Access_Subprogram_Type
(E
)
5304 -- If a pragma Default_Storage_Pool applies, and this type has no
5305 -- Storage_Pool or Storage_Size clause (which must have occurred
5306 -- before the freezing point), then use the default. This applies
5307 -- only to base types.
5309 -- None of this applies to access to subprograms, for which there
5310 -- are clearly no pools.
5312 if Present
(Default_Pool
)
5313 and then Is_Base_Type
(E
)
5314 and then not Has_Storage_Size_Clause
(E
)
5315 and then No
(Associated_Storage_Pool
(E
))
5317 -- Case of pragma Default_Storage_Pool (null)
5319 if Nkind
(Default_Pool
) = N_Null
then
5320 Set_No_Pool_Assigned
(E
);
5322 -- Case of pragma Default_Storage_Pool (storage_pool_NAME)
5325 Set_Associated_Storage_Pool
(E
, Entity
(Default_Pool
));
5329 -- Check restriction for standard storage pool
5331 if No
(Associated_Storage_Pool
(E
)) then
5332 Check_Restriction
(No_Standard_Storage_Pools
, E
);
5335 -- Deal with error message for pure access type. This is not an
5336 -- error in Ada 2005 if there is no pool (see AI-366).
5338 if Is_Pure_Unit_Access_Type
(E
)
5339 and then (Ada_Version
< Ada_2005
5340 or else not No_Pool_Assigned
(E
))
5341 and then not Is_Generic_Unit
(Scope
(E
))
5343 Error_Msg_N
("named access type not allowed in pure unit", E
);
5345 if Ada_Version
>= Ada_2005
then
5347 ("\would be legal if Storage_Size of 0 given??", E
);
5349 elsif No_Pool_Assigned
(E
) then
5351 ("\would be legal in Ada 2005??", E
);
5355 ("\would be legal in Ada 2005 if "
5356 & "Storage_Size of 0 given??", E
);
5361 -- Case of composite types
5363 if Is_Composite_Type
(E
) then
5365 -- AI-117 requires that all new primitives of a tagged type must
5366 -- inherit the convention of the full view of the type. Inherited
5367 -- and overriding operations are defined to inherit the convention
5368 -- of their parent or overridden subprogram (also specified in
5369 -- AI-117), which will have occurred earlier (in Derive_Subprogram
5370 -- and New_Overloaded_Entity). Here we set the convention of
5371 -- primitives that are still convention Ada, which will ensure
5372 -- that any new primitives inherit the type's convention. Class-
5373 -- wide types can have a foreign convention inherited from their
5374 -- specific type, but are excluded from this since they don't have
5375 -- any associated primitives.
5377 if Is_Tagged_Type
(E
)
5378 and then not Is_Class_Wide_Type
(E
)
5379 and then Convention
(E
) /= Convention_Ada
5382 Prim_List
: constant Elist_Id
:= Primitive_Operations
(E
);
5386 Prim
:= First_Elmt
(Prim_List
);
5387 while Present
(Prim
) loop
5388 if Convention
(Node
(Prim
)) = Convention_Ada
then
5389 Set_Convention
(Node
(Prim
), Convention
(E
));
5397 -- If the type is a simple storage pool type, then this is where
5398 -- we attempt to locate and validate its Allocate, Deallocate, and
5399 -- Storage_Size operations (the first is required, and the latter
5400 -- two are optional). We also verify that the full type for a
5401 -- private type is allowed to be a simple storage pool type.
5403 if Present
(Get_Rep_Pragma
(E
, Name_Simple_Storage_Pool_Type
))
5404 and then (Is_Base_Type
(E
) or else Has_Private_Declaration
(E
))
5406 -- If the type is marked Has_Private_Declaration, then this is
5407 -- a full type for a private type that was specified with the
5408 -- pragma Simple_Storage_Pool_Type, and here we ensure that the
5409 -- pragma is allowed for the full type (for example, it can't
5410 -- be an array type, or a nonlimited record type).
5412 if Has_Private_Declaration
(E
) then
5413 if (not Is_Record_Type
(E
) or else not Is_Limited_View
(E
))
5414 and then not Is_Private_Type
(E
)
5416 Error_Msg_Name_1
:= Name_Simple_Storage_Pool_Type
;
5418 ("pragma% can only apply to full type that is an " &
5419 "explicitly limited type", E
);
5423 Validate_Simple_Pool_Ops
: declare
5424 Pool_Type
: Entity_Id
renames E
;
5425 Address_Type
: constant Entity_Id
:= RTE
(RE_Address
);
5426 Stg_Cnt_Type
: constant Entity_Id
:= RTE
(RE_Storage_Count
);
5428 procedure Validate_Simple_Pool_Op_Formal
5429 (Pool_Op
: Entity_Id
;
5430 Pool_Op_Formal
: in out Entity_Id
;
5431 Expected_Mode
: Formal_Kind
;
5432 Expected_Type
: Entity_Id
;
5433 Formal_Name
: String;
5434 OK_Formal
: in out Boolean);
5435 -- Validate one formal Pool_Op_Formal of the candidate pool
5436 -- operation Pool_Op. The formal must be of Expected_Type
5437 -- and have mode Expected_Mode. OK_Formal will be set to
5438 -- False if the formal doesn't match. If OK_Formal is False
5439 -- on entry, then the formal will effectively be ignored
5440 -- (because validation of the pool op has already failed).
5441 -- Upon return, Pool_Op_Formal will be updated to the next
5444 procedure Validate_Simple_Pool_Operation
5445 (Op_Name
: Name_Id
);
5446 -- Search for and validate a simple pool operation with the
5447 -- name Op_Name. If the name is Allocate, then there must be
5448 -- exactly one such primitive operation for the simple pool
5449 -- type. If the name is Deallocate or Storage_Size, then
5450 -- there can be at most one such primitive operation. The
5451 -- profile of the located primitive must conform to what
5452 -- is expected for each operation.
5454 ------------------------------------
5455 -- Validate_Simple_Pool_Op_Formal --
5456 ------------------------------------
5458 procedure Validate_Simple_Pool_Op_Formal
5459 (Pool_Op
: Entity_Id
;
5460 Pool_Op_Formal
: in out Entity_Id
;
5461 Expected_Mode
: Formal_Kind
;
5462 Expected_Type
: Entity_Id
;
5463 Formal_Name
: String;
5464 OK_Formal
: in out Boolean)
5467 -- If OK_Formal is False on entry, then simply ignore
5468 -- the formal, because an earlier formal has already
5471 if not OK_Formal
then
5474 -- If no formal is passed in, then issue an error for a
5477 elsif not Present
(Pool_Op_Formal
) then
5479 ("simple storage pool op missing formal " &
5480 Formal_Name
& " of type&", Pool_Op
, Expected_Type
);
5486 if Etype
(Pool_Op_Formal
) /= Expected_Type
then
5488 -- If the pool type was expected for this formal, then
5489 -- this will not be considered a candidate operation
5490 -- for the simple pool, so we unset OK_Formal so that
5491 -- the op and any later formals will be ignored.
5493 if Expected_Type
= Pool_Type
then
5500 ("wrong type for formal " & Formal_Name
&
5501 " of simple storage pool op; expected type&",
5502 Pool_Op_Formal
, Expected_Type
);
5506 -- Issue error if formal's mode is not the expected one
5508 if Ekind
(Pool_Op_Formal
) /= Expected_Mode
then
5510 ("wrong mode for formal of simple storage pool op",
5514 -- Advance to the next formal
5516 Next_Formal
(Pool_Op_Formal
);
5517 end Validate_Simple_Pool_Op_Formal
;
5519 ------------------------------------
5520 -- Validate_Simple_Pool_Operation --
5521 ------------------------------------
5523 procedure Validate_Simple_Pool_Operation
5527 Found_Op
: Entity_Id
:= Empty
;
5533 (Nam_In
(Op_Name
, Name_Allocate
,
5535 Name_Storage_Size
));
5537 Error_Msg_Name_1
:= Op_Name
;
5539 -- For each homonym declared immediately in the scope
5540 -- of the simple storage pool type, determine whether
5541 -- the homonym is an operation of the pool type, and,
5542 -- if so, check that its profile is as expected for
5543 -- a simple pool operation of that name.
5545 Op
:= Get_Name_Entity_Id
(Op_Name
);
5546 while Present
(Op
) loop
5547 if Ekind_In
(Op
, E_Function
, E_Procedure
)
5548 and then Scope
(Op
) = Current_Scope
5550 Formal
:= First_Entity
(Op
);
5554 -- The first parameter must be of the pool type
5555 -- in order for the operation to qualify.
5557 if Op_Name
= Name_Storage_Size
then
5558 Validate_Simple_Pool_Op_Formal
5559 (Op
, Formal
, E_In_Parameter
, Pool_Type
,
5562 Validate_Simple_Pool_Op_Formal
5563 (Op
, Formal
, E_In_Out_Parameter
, Pool_Type
,
5567 -- If another operation with this name has already
5568 -- been located for the type, then flag an error,
5569 -- since we only allow the type to have a single
5572 if Present
(Found_Op
) and then Is_OK
then
5574 ("only one % operation allowed for " &
5575 "simple storage pool type&", Op
, Pool_Type
);
5578 -- In the case of Allocate and Deallocate, a formal
5579 -- of type System.Address is required.
5581 if Op_Name
= Name_Allocate
then
5582 Validate_Simple_Pool_Op_Formal
5583 (Op
, Formal
, E_Out_Parameter
,
5584 Address_Type
, "Storage_Address", Is_OK
);
5586 elsif Op_Name
= Name_Deallocate
then
5587 Validate_Simple_Pool_Op_Formal
5588 (Op
, Formal
, E_In_Parameter
,
5589 Address_Type
, "Storage_Address", Is_OK
);
5592 -- In the case of Allocate and Deallocate, formals
5593 -- of type Storage_Count are required as the third
5594 -- and fourth parameters.
5596 if Op_Name
/= Name_Storage_Size
then
5597 Validate_Simple_Pool_Op_Formal
5598 (Op
, Formal
, E_In_Parameter
,
5599 Stg_Cnt_Type
, "Size_In_Storage_Units", Is_OK
);
5600 Validate_Simple_Pool_Op_Formal
5601 (Op
, Formal
, E_In_Parameter
,
5602 Stg_Cnt_Type
, "Alignment", Is_OK
);
5605 -- If no mismatched formals have been found (Is_OK)
5606 -- and no excess formals are present, then this
5607 -- operation has been validated, so record it.
5609 if not Present
(Formal
) and then Is_OK
then
5617 -- There must be a valid Allocate operation for the type,
5618 -- so issue an error if none was found.
5620 if Op_Name
= Name_Allocate
5621 and then not Present
(Found_Op
)
5623 Error_Msg_N
("missing % operation for simple " &
5624 "storage pool type", Pool_Type
);
5626 elsif Present
(Found_Op
) then
5628 -- Simple pool operations can't be abstract
5630 if Is_Abstract_Subprogram
(Found_Op
) then
5632 ("simple storage pool operation must not be " &
5633 "abstract", Found_Op
);
5636 -- The Storage_Size operation must be a function with
5637 -- Storage_Count as its result type.
5639 if Op_Name
= Name_Storage_Size
then
5640 if Ekind
(Found_Op
) = E_Procedure
then
5642 ("% operation must be a function", Found_Op
);
5644 elsif Etype
(Found_Op
) /= Stg_Cnt_Type
then
5646 ("wrong result type for%, expected type&",
5647 Found_Op
, Stg_Cnt_Type
);
5650 -- Allocate and Deallocate must be procedures
5652 elsif Ekind
(Found_Op
) = E_Function
then
5654 ("% operation must be a procedure", Found_Op
);
5657 end Validate_Simple_Pool_Operation
;
5659 -- Start of processing for Validate_Simple_Pool_Ops
5662 Validate_Simple_Pool_Operation
(Name_Allocate
);
5663 Validate_Simple_Pool_Operation
(Name_Deallocate
);
5664 Validate_Simple_Pool_Operation
(Name_Storage_Size
);
5665 end Validate_Simple_Pool_Ops
;
5669 -- Now that all types from which E may depend are frozen, see if the
5670 -- size is known at compile time, if it must be unsigned, or if
5671 -- strict alignment is required
5673 Check_Compile_Time_Size
(E
);
5674 Check_Unsigned_Type
(E
);
5676 if Base_Type
(E
) = E
then
5677 Check_Strict_Alignment
(E
);
5680 -- Do not allow a size clause for a type which does not have a size
5681 -- that is known at compile time
5683 if Has_Size_Clause
(E
)
5684 and then not Size_Known_At_Compile_Time
(E
)
5686 -- Suppress this message if errors posted on E, even if we are
5687 -- in all errors mode, since this is often a junk message
5689 if not Error_Posted
(E
) then
5691 ("size clause not allowed for variable length type",
5696 -- Now we set/verify the representation information, in particular
5697 -- the size and alignment values. This processing is not required for
5698 -- generic types, since generic types do not play any part in code
5699 -- generation, and so the size and alignment values for such types
5700 -- are irrelevant. Ditto for types declared within a generic unit,
5701 -- which may have components that depend on generic parameters, and
5702 -- that will be recreated in an instance.
5704 if Inside_A_Generic
then
5707 -- Otherwise we call the layout procedure
5713 -- If this is an access to subprogram whose designated type is itself
5714 -- a subprogram type, the return type of this anonymous subprogram
5715 -- type must be decorated as well.
5717 if Ekind
(E
) = E_Anonymous_Access_Subprogram_Type
5718 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
5720 Layout_Type
(Etype
(Designated_Type
(E
)));
5723 -- If the type has a Defaut_Value/Default_Component_Value aspect,
5724 -- this is where we analye the expression (after the type is frozen,
5725 -- since in the case of Default_Value, we are analyzing with the
5726 -- type itself, and we treat Default_Component_Value similarly for
5727 -- the sake of uniformity).
5729 if Is_First_Subtype
(E
) and then Has_Default_Aspect
(E
) then
5736 if Is_Scalar_Type
(E
) then
5737 Nam
:= Name_Default_Value
;
5739 Exp
:= Default_Aspect_Value
(Typ
);
5741 Nam
:= Name_Default_Component_Value
;
5742 Typ
:= Component_Type
(E
);
5743 Exp
:= Default_Aspect_Component_Value
(E
);
5746 Analyze_And_Resolve
(Exp
, Typ
);
5748 if Etype
(Exp
) /= Any_Type
then
5749 if not Is_OK_Static_Expression
(Exp
) then
5750 Error_Msg_Name_1
:= Nam
;
5751 Flag_Non_Static_Expr
5752 ("aspect% requires static expression", Exp
);
5758 -- End of freeze processing for type entities
5761 -- Here is where we logically freeze the current entity. If it has a
5762 -- freeze node, then this is the point at which the freeze node is
5763 -- linked into the result list.
5765 if Has_Delayed_Freeze
(E
) then
5767 -- If a freeze node is already allocated, use it, otherwise allocate
5768 -- a new one. The preallocation happens in the case of anonymous base
5769 -- types, where we preallocate so that we can set First_Subtype_Link.
5770 -- Note that we reset the Sloc to the current freeze location.
5772 if Present
(Freeze_Node
(E
)) then
5773 F_Node
:= Freeze_Node
(E
);
5774 Set_Sloc
(F_Node
, Loc
);
5777 F_Node
:= New_Node
(N_Freeze_Entity
, Loc
);
5778 Set_Freeze_Node
(E
, F_Node
);
5779 Set_Access_Types_To_Process
(F_Node
, No_Elist
);
5780 Set_TSS_Elist
(F_Node
, No_Elist
);
5781 Set_Actions
(F_Node
, No_List
);
5784 Set_Entity
(F_Node
, E
);
5785 Add_To_Result
(F_Node
);
5787 -- A final pass over record types with discriminants. If the type
5788 -- has an incomplete declaration, there may be constrained access
5789 -- subtypes declared elsewhere, which do not depend on the discrimi-
5790 -- nants of the type, and which are used as component types (i.e.
5791 -- the full view is a recursive type). The designated types of these
5792 -- subtypes can only be elaborated after the type itself, and they
5793 -- need an itype reference.
5795 if Ekind
(E
) = E_Record_Type
5796 and then Has_Discriminants
(E
)
5804 Comp
:= First_Component
(E
);
5805 while Present
(Comp
) loop
5806 Typ
:= Etype
(Comp
);
5808 if Ekind
(Comp
) = E_Component
5809 and then Is_Access_Type
(Typ
)
5810 and then Scope
(Typ
) /= E
5811 and then Base_Type
(Designated_Type
(Typ
)) = E
5812 and then Is_Itype
(Designated_Type
(Typ
))
5814 IR
:= Make_Itype_Reference
(Sloc
(Comp
));
5815 Set_Itype
(IR
, Designated_Type
(Typ
));
5816 Append
(IR
, Result
);
5819 Next_Component
(Comp
);
5825 -- When a type is frozen, the first subtype of the type is frozen as
5826 -- well (RM 13.14(15)). This has to be done after freezing the type,
5827 -- since obviously the first subtype depends on its own base type.
5830 Freeze_And_Append
(First_Subtype
(E
), N
, Result
);
5832 -- If we just froze a tagged non-class wide record, then freeze the
5833 -- corresponding class-wide type. This must be done after the tagged
5834 -- type itself is frozen, because the class-wide type refers to the
5835 -- tagged type which generates the class.
5837 if Is_Tagged_Type
(E
)
5838 and then not Is_Class_Wide_Type
(E
)
5839 and then Present
(Class_Wide_Type
(E
))
5841 Freeze_And_Append
(Class_Wide_Type
(E
), N
, Result
);
5845 Check_Debug_Info_Needed
(E
);
5847 -- Special handling for subprograms
5849 if Is_Subprogram
(E
) then
5851 -- If subprogram has address clause then reset Is_Public flag, since
5852 -- we do not want the backend to generate external references.
5854 if Present
(Address_Clause
(E
))
5855 and then not Is_Library_Level_Entity
(E
)
5857 Set_Is_Public
(E
, False);
5864 -----------------------------
5865 -- Freeze_Enumeration_Type --
5866 -----------------------------
5868 procedure Freeze_Enumeration_Type
(Typ
: Entity_Id
) is
5870 -- By default, if no size clause is present, an enumeration type with
5871 -- Convention C is assumed to interface to a C enum, and has integer
5872 -- size. This applies to types. For subtypes, verify that its base
5873 -- type has no size clause either. Treat other foreign conventions
5874 -- in the same way, and also make sure alignment is set right.
5876 if Has_Foreign_Convention
(Typ
)
5877 and then not Has_Size_Clause
(Typ
)
5878 and then not Has_Size_Clause
(Base_Type
(Typ
))
5879 and then Esize
(Typ
) < Standard_Integer_Size
5881 -- Don't do this if Short_Enums on target
5883 and then not Target_Short_Enums
5885 Init_Esize
(Typ
, Standard_Integer_Size
);
5886 Set_Alignment
(Typ
, Alignment
(Standard_Integer
));
5888 -- Normal Ada case or size clause present or not Long_C_Enums on target
5891 -- If the enumeration type interfaces to C, and it has a size clause
5892 -- that specifies less than int size, it warrants a warning. The
5893 -- user may intend the C type to be an enum or a char, so this is
5894 -- not by itself an error that the Ada compiler can detect, but it
5895 -- it is a worth a heads-up. For Boolean and Character types we
5896 -- assume that the programmer has the proper C type in mind.
5898 if Convention
(Typ
) = Convention_C
5899 and then Has_Size_Clause
(Typ
)
5900 and then Esize
(Typ
) /= Esize
(Standard_Integer
)
5901 and then not Is_Boolean_Type
(Typ
)
5902 and then not Is_Character_Type
(Typ
)
5904 -- Don't do this if Short_Enums on target
5906 and then not Target_Short_Enums
5909 ("C enum types have the size of a C int??", Size_Clause
(Typ
));
5912 Adjust_Esize_For_Alignment
(Typ
);
5914 end Freeze_Enumeration_Type
;
5916 -----------------------
5917 -- Freeze_Expression --
5918 -----------------------
5920 procedure Freeze_Expression
(N
: Node_Id
) is
5921 In_Spec_Exp
: constant Boolean := In_Spec_Expression
;
5924 Desig_Typ
: Entity_Id
;
5928 Freeze_Outside
: Boolean := False;
5929 -- This flag is set true if the entity must be frozen outside the
5930 -- current subprogram. This happens in the case of expander generated
5931 -- subprograms (_Init_Proc, _Input, _Output, _Read, _Write) which do
5932 -- not freeze all entities like other bodies, but which nevertheless
5933 -- may reference entities that have to be frozen before the body and
5934 -- obviously cannot be frozen inside the body.
5936 function In_Exp_Body
(N
: Node_Id
) return Boolean;
5937 -- Given an N_Handled_Sequence_Of_Statements node N, determines whether
5938 -- it is the handled statement sequence of an expander-generated
5939 -- subprogram (init proc, stream subprogram, or renaming as body).
5940 -- If so, this is not a freezing context.
5946 function In_Exp_Body
(N
: Node_Id
) return Boolean is
5951 if Nkind
(N
) = N_Subprogram_Body
then
5957 if Nkind
(P
) /= N_Subprogram_Body
then
5961 Id
:= Defining_Unit_Name
(Specification
(P
));
5963 -- Following complex conditional could use comments ???
5965 if Nkind
(Id
) = N_Defining_Identifier
5966 and then (Is_Init_Proc
(Id
)
5967 or else Is_TSS
(Id
, TSS_Stream_Input
)
5968 or else Is_TSS
(Id
, TSS_Stream_Output
)
5969 or else Is_TSS
(Id
, TSS_Stream_Read
)
5970 or else Is_TSS
(Id
, TSS_Stream_Write
)
5971 or else Nkind_In
(Original_Node
(P
),
5972 N_Subprogram_Renaming_Declaration
,
5973 N_Expression_Function
))
5982 -- Start of processing for Freeze_Expression
5985 -- Immediate return if freezing is inhibited. This flag is set by the
5986 -- analyzer to stop freezing on generated expressions that would cause
5987 -- freezing if they were in the source program, but which are not
5988 -- supposed to freeze, since they are created.
5990 if Must_Not_Freeze
(N
) then
5994 -- If expression is non-static, then it does not freeze in a default
5995 -- expression, see section "Handling of Default Expressions" in the
5996 -- spec of package Sem for further details. Note that we have to make
5997 -- sure that we actually have a real expression (if we have a subtype
5998 -- indication, we can't test Is_OK_Static_Expression). However, we
5999 -- exclude the case of the prefix of an attribute of a static scalar
6000 -- subtype from this early return, because static subtype attributes
6001 -- should always cause freezing, even in default expressions, but
6002 -- the attribute may not have been marked as static yet (because in
6003 -- Resolve_Attribute, the call to Eval_Attribute follows the call of
6004 -- Freeze_Expression on the prefix).
6007 and then Nkind
(N
) in N_Subexpr
6008 and then not Is_OK_Static_Expression
(N
)
6009 and then (Nkind
(Parent
(N
)) /= N_Attribute_Reference
6010 or else not (Is_Entity_Name
(N
)
6011 and then Is_Type
(Entity
(N
))
6012 and then Is_OK_Static_Subtype
(Entity
(N
))))
6017 -- Freeze type of expression if not frozen already
6021 if Nkind
(N
) in N_Has_Etype
then
6022 if not Is_Frozen
(Etype
(N
)) then
6025 -- Base type may be an derived numeric type that is frozen at
6026 -- the point of declaration, but first_subtype is still unfrozen.
6028 elsif not Is_Frozen
(First_Subtype
(Etype
(N
))) then
6029 Typ
:= First_Subtype
(Etype
(N
));
6033 -- For entity name, freeze entity if not frozen already. A special
6034 -- exception occurs for an identifier that did not come from source.
6035 -- We don't let such identifiers freeze a non-internal entity, i.e.
6036 -- an entity that did come from source, since such an identifier was
6037 -- generated by the expander, and cannot have any semantic effect on
6038 -- the freezing semantics. For example, this stops the parameter of
6039 -- an initialization procedure from freezing the variable.
6041 if Is_Entity_Name
(N
)
6042 and then not Is_Frozen
(Entity
(N
))
6043 and then (Nkind
(N
) /= N_Identifier
6044 or else Comes_From_Source
(N
)
6045 or else not Comes_From_Source
(Entity
(N
)))
6049 if Present
(Nam
) and then Ekind
(Nam
) = E_Function
then
6050 Check_Expression_Function
(N
, Nam
);
6057 -- For an allocator freeze designated type if not frozen already
6059 -- For an aggregate whose component type is an access type, freeze the
6060 -- designated type now, so that its freeze does not appear within the
6061 -- loop that might be created in the expansion of the aggregate. If the
6062 -- designated type is a private type without full view, the expression
6063 -- cannot contain an allocator, so the type is not frozen.
6065 -- For a function, we freeze the entity when the subprogram declaration
6066 -- is frozen, but a function call may appear in an initialization proc.
6067 -- before the declaration is frozen. We need to generate the extra
6068 -- formals, if any, to ensure that the expansion of the call includes
6069 -- the proper actuals. This only applies to Ada subprograms, not to
6076 Desig_Typ
:= Designated_Type
(Etype
(N
));
6079 if Is_Array_Type
(Etype
(N
))
6080 and then Is_Access_Type
(Component_Type
(Etype
(N
)))
6082 Desig_Typ
:= Designated_Type
(Component_Type
(Etype
(N
)));
6085 when N_Selected_Component |
6086 N_Indexed_Component |
6089 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6090 Desig_Typ
:= Designated_Type
(Etype
(Prefix
(N
)));
6093 when N_Identifier
=>
6095 and then Ekind
(Nam
) = E_Function
6096 and then Nkind
(Parent
(N
)) = N_Function_Call
6097 and then Convention
(Nam
) = Convention_Ada
6099 Create_Extra_Formals
(Nam
);
6106 if Desig_Typ
/= Empty
6107 and then (Is_Frozen
(Desig_Typ
)
6108 or else (not Is_Fully_Defined
(Desig_Typ
)))
6113 -- All done if nothing needs freezing
6117 and then No
(Desig_Typ
)
6122 -- Examine the enclosing context by climbing the parent chain. The
6123 -- traversal serves two purposes - to detect scenarios where freezeing
6124 -- is not needed and to find the proper insertion point for the freeze
6125 -- nodes. Although somewhat similar to Insert_Actions, this traversal
6126 -- is freezing semantics-sensitive. Inserting freeze nodes blindly in
6127 -- the tree may result in types being frozen too early.
6131 Parent_P
:= Parent
(P
);
6133 -- If we don't have a parent, then we are not in a well-formed tree.
6134 -- This is an unusual case, but there are some legitimate situations
6135 -- in which this occurs, notably when the expressions in the range of
6136 -- a type declaration are resolved. We simply ignore the freeze
6137 -- request in this case. Is this right ???
6139 if No
(Parent_P
) then
6143 -- See if we have got to an appropriate point in the tree
6145 case Nkind
(Parent_P
) is
6147 -- A special test for the exception of (RM 13.14(8)) for the case
6148 -- of per-object expressions (RM 3.8(18)) occurring in component
6149 -- definition or a discrete subtype definition. Note that we test
6150 -- for a component declaration which includes both cases we are
6151 -- interested in, and furthermore the tree does not have explicit
6152 -- nodes for either of these two constructs.
6154 when N_Component_Declaration
=>
6156 -- The case we want to test for here is an identifier that is
6157 -- a per-object expression, this is either a discriminant that
6158 -- appears in a context other than the component declaration
6159 -- or it is a reference to the type of the enclosing construct.
6161 -- For either of these cases, we skip the freezing
6163 if not In_Spec_Expression
6164 and then Nkind
(N
) = N_Identifier
6165 and then (Present
(Entity
(N
)))
6167 -- We recognize the discriminant case by just looking for
6168 -- a reference to a discriminant. It can only be one for
6169 -- the enclosing construct. Skip freezing in this case.
6171 if Ekind
(Entity
(N
)) = E_Discriminant
then
6174 -- For the case of a reference to the enclosing record,
6175 -- (or task or protected type), we look for a type that
6176 -- matches the current scope.
6178 elsif Entity
(N
) = Current_Scope
then
6183 -- If we have an enumeration literal that appears as the choice in
6184 -- the aggregate of an enumeration representation clause, then
6185 -- freezing does not occur (RM 13.14(10)).
6187 when N_Enumeration_Representation_Clause
=>
6189 -- The case we are looking for is an enumeration literal
6191 if (Nkind
(N
) = N_Identifier
or Nkind
(N
) = N_Character_Literal
)
6192 and then Is_Enumeration_Type
(Etype
(N
))
6194 -- If enumeration literal appears directly as the choice,
6195 -- do not freeze (this is the normal non-overloaded case)
6197 if Nkind
(Parent
(N
)) = N_Component_Association
6198 and then First
(Choices
(Parent
(N
))) = N
6202 -- If enumeration literal appears as the name of function
6203 -- which is the choice, then also do not freeze. This
6204 -- happens in the overloaded literal case, where the
6205 -- enumeration literal is temporarily changed to a function
6206 -- call for overloading analysis purposes.
6208 elsif Nkind
(Parent
(N
)) = N_Function_Call
6210 Nkind
(Parent
(Parent
(N
))) = N_Component_Association
6212 First
(Choices
(Parent
(Parent
(N
)))) = Parent
(N
)
6218 -- Normally if the parent is a handled sequence of statements,
6219 -- then the current node must be a statement, and that is an
6220 -- appropriate place to insert a freeze node.
6222 when N_Handled_Sequence_Of_Statements
=>
6224 -- An exception occurs when the sequence of statements is for
6225 -- an expander generated body that did not do the usual freeze
6226 -- all operation. In this case we usually want to freeze
6227 -- outside this body, not inside it, and we skip past the
6228 -- subprogram body that we are inside.
6230 if In_Exp_Body
(Parent_P
) then
6232 Subp
: constant Node_Id
:= Parent
(Parent_P
);
6236 -- Freeze the entity only when it is declared inside the
6237 -- body of the expander generated procedure. This case
6238 -- is recognized by the scope of the entity or its type,
6239 -- which is either the spec for some enclosing body, or
6240 -- (in the case of init_procs, for which there are no
6241 -- separate specs) the current scope.
6243 if Nkind
(Subp
) = N_Subprogram_Body
then
6244 Spec
:= Corresponding_Spec
(Subp
);
6246 if (Present
(Typ
) and then Scope
(Typ
) = Spec
)
6248 (Present
(Nam
) and then Scope
(Nam
) = Spec
)
6253 and then Scope
(Typ
) = Current_Scope
6254 and then Defining_Entity
(Subp
) = Current_Scope
6260 -- An expression function may act as a completion of
6261 -- a function declaration. As such, it can reference
6262 -- entities declared between the two views:
6265 -- function F return ...;
6267 -- function Hidden return ...;
6268 -- function F return ... is (Hidden); -- 2
6270 -- Refering to the example above, freezing the expression
6271 -- of F (2) would place Hidden's freeze node (1) in the
6272 -- wrong place. Avoid explicit freezing and let the usual
6273 -- scenarios do the job - for example, reaching the end
6274 -- of the private declarations.
6276 if Nkind
(Original_Node
(Subp
)) =
6277 N_Expression_Function
6281 -- Freeze outside the body
6284 Parent_P
:= Parent
(Parent_P
);
6285 Freeze_Outside
:= True;
6289 -- Here if normal case where we are in handled statement
6290 -- sequence and want to do the insertion right there.
6296 -- If parent is a body or a spec or a block, then the current node
6297 -- is a statement or declaration and we can insert the freeze node
6300 when N_Block_Statement |
6303 N_Package_Specification |
6306 N_Task_Body
=> exit;
6308 -- The expander is allowed to define types in any statements list,
6309 -- so any of the following parent nodes also mark a freezing point
6310 -- if the actual node is in a list of statements or declarations.
6312 when N_Abortable_Part |
6313 N_Accept_Alternative |
6315 N_Case_Statement_Alternative |
6316 N_Compilation_Unit_Aux |
6317 N_Conditional_Entry_Call |
6318 N_Delay_Alternative |
6320 N_Entry_Call_Alternative |
6321 N_Exception_Handler |
6322 N_Extended_Return_Statement |
6326 N_Selective_Accept |
6327 N_Triggering_Alternative
=>
6329 exit when Is_List_Member
(P
);
6331 -- Freeze nodes produced by an expression coming from the Actions
6332 -- list of a N_Expression_With_Actions node must remain within the
6333 -- Actions list. Inserting the freeze nodes further up the tree
6334 -- may lead to use before declaration issues in the case of array
6337 when N_Expression_With_Actions
=>
6338 if Is_List_Member
(P
)
6339 and then List_Containing
(P
) = Actions
(Parent_P
)
6344 -- Note: N_Loop_Statement is a special case. A type that appears
6345 -- in the source can never be frozen in a loop (this occurs only
6346 -- because of a loop expanded by the expander), so we keep on
6347 -- going. Otherwise we terminate the search. Same is true of any
6348 -- entity which comes from source. (if they have predefined type,
6349 -- that type does not appear to come from source, but the entity
6350 -- should not be frozen here).
6352 when N_Loop_Statement
=>
6353 exit when not Comes_From_Source
(Etype
(N
))
6354 and then (No
(Nam
) or else not Comes_From_Source
(Nam
));
6356 -- For all other cases, keep looking at parents
6362 -- We fall through the case if we did not yet find the proper
6363 -- place in the free for inserting the freeze node, so climb.
6368 -- If the expression appears in a record or an initialization procedure,
6369 -- the freeze nodes are collected and attached to the current scope, to
6370 -- be inserted and analyzed on exit from the scope, to insure that
6371 -- generated entities appear in the correct scope. If the expression is
6372 -- a default for a discriminant specification, the scope is still void.
6373 -- The expression can also appear in the discriminant part of a private
6374 -- or concurrent type.
6376 -- If the expression appears in a constrained subcomponent of an
6377 -- enclosing record declaration, the freeze nodes must be attached to
6378 -- the outer record type so they can eventually be placed in the
6379 -- enclosing declaration list.
6381 -- The other case requiring this special handling is if we are in a
6382 -- default expression, since in that case we are about to freeze a
6383 -- static type, and the freeze scope needs to be the outer scope, not
6384 -- the scope of the subprogram with the default parameter.
6386 -- For default expressions and other spec expressions in generic units,
6387 -- the Move_Freeze_Nodes mechanism (see sem_ch12.adb) takes care of
6388 -- placing them at the proper place, after the generic unit.
6390 if (In_Spec_Exp
and not Inside_A_Generic
)
6391 or else Freeze_Outside
6392 or else (Is_Type
(Current_Scope
)
6393 and then (not Is_Concurrent_Type
(Current_Scope
)
6394 or else not Has_Completion
(Current_Scope
)))
6395 or else Ekind
(Current_Scope
) = E_Void
6398 N
: constant Node_Id
:= Current_Scope
;
6399 Freeze_Nodes
: List_Id
:= No_List
;
6400 Pos
: Int
:= Scope_Stack
.Last
;
6403 if Present
(Desig_Typ
) then
6404 Freeze_And_Append
(Desig_Typ
, N
, Freeze_Nodes
);
6407 if Present
(Typ
) then
6408 Freeze_And_Append
(Typ
, N
, Freeze_Nodes
);
6411 if Present
(Nam
) then
6412 Freeze_And_Append
(Nam
, N
, Freeze_Nodes
);
6415 -- The current scope may be that of a constrained component of
6416 -- an enclosing record declaration, or of a loop of an enclosing
6417 -- quantified expression, which is above the current scope in the
6418 -- scope stack. Indeed in the context of a quantified expression,
6419 -- a scope is created and pushed above the current scope in order
6420 -- to emulate the loop-like behavior of the quantified expression.
6421 -- If the expression is within a top-level pragma, as for a pre-
6422 -- condition on a library-level subprogram, nothing to do.
6424 if not Is_Compilation_Unit
(Current_Scope
)
6425 and then (Is_Record_Type
(Scope
(Current_Scope
))
6426 or else Nkind
(Parent
(Current_Scope
)) =
6427 N_Quantified_Expression
)
6432 if Is_Non_Empty_List
(Freeze_Nodes
) then
6433 if No
(Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
) then
6434 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
:=
6437 Append_List
(Freeze_Nodes
,
6438 Scope_Stack
.Table
(Pos
).Pending_Freeze_Actions
);
6446 -- Now we have the right place to do the freezing. First, a special
6447 -- adjustment, if we are in spec-expression analysis mode, these freeze
6448 -- actions must not be thrown away (normally all inserted actions are
6449 -- thrown away in this mode. However, the freeze actions are from static
6450 -- expressions and one of the important reasons we are doing this
6451 -- special analysis is to get these freeze actions. Therefore we turn
6452 -- off the In_Spec_Expression mode to propagate these freeze actions.
6453 -- This also means they get properly analyzed and expanded.
6455 In_Spec_Expression
:= False;
6457 -- Freeze the designated type of an allocator (RM 13.14(13))
6459 if Present
(Desig_Typ
) then
6460 Freeze_Before
(P
, Desig_Typ
);
6463 -- Freeze type of expression (RM 13.14(10)). Note that we took care of
6464 -- the enumeration representation clause exception in the loop above.
6466 if Present
(Typ
) then
6467 Freeze_Before
(P
, Typ
);
6470 -- Freeze name if one is present (RM 13.14(11))
6472 if Present
(Nam
) then
6473 Freeze_Before
(P
, Nam
);
6476 -- Restore In_Spec_Expression flag
6478 In_Spec_Expression
:= In_Spec_Exp
;
6479 end Freeze_Expression
;
6481 -----------------------------
6482 -- Freeze_Fixed_Point_Type --
6483 -----------------------------
6485 -- Certain fixed-point types and subtypes, including implicit base types
6486 -- and declared first subtypes, have not yet set up a range. This is
6487 -- because the range cannot be set until the Small and Size values are
6488 -- known, and these are not known till the type is frozen.
6490 -- To signal this case, Scalar_Range contains an unanalyzed syntactic range
6491 -- whose bounds are unanalyzed real literals. This routine will recognize
6492 -- this case, and transform this range node into a properly typed range
6493 -- with properly analyzed and resolved values.
6495 procedure Freeze_Fixed_Point_Type
(Typ
: Entity_Id
) is
6496 Rng
: constant Node_Id
:= Scalar_Range
(Typ
);
6497 Lo
: constant Node_Id
:= Low_Bound
(Rng
);
6498 Hi
: constant Node_Id
:= High_Bound
(Rng
);
6499 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6500 Brng
: constant Node_Id
:= Scalar_Range
(Btyp
);
6501 BLo
: constant Node_Id
:= Low_Bound
(Brng
);
6502 BHi
: constant Node_Id
:= High_Bound
(Brng
);
6503 Small
: constant Ureal
:= Small_Value
(Typ
);
6510 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
;
6511 -- Returns size of type with given bounds. Also leaves these
6512 -- bounds set as the current bounds of the Typ.
6518 function Fsize
(Lov
, Hiv
: Ureal
) return Nat
is
6520 Set_Realval
(Lo
, Lov
);
6521 Set_Realval
(Hi
, Hiv
);
6522 return Minimum_Size
(Typ
);
6525 -- Start of processing for Freeze_Fixed_Point_Type
6528 -- If Esize of a subtype has not previously been set, set it now
6530 if Unknown_Esize
(Typ
) then
6531 Atype
:= Ancestor_Subtype
(Typ
);
6533 if Present
(Atype
) then
6534 Set_Esize
(Typ
, Esize
(Atype
));
6536 Set_Esize
(Typ
, Esize
(Base_Type
(Typ
)));
6540 -- Immediate return if the range is already analyzed. This means that
6541 -- the range is already set, and does not need to be computed by this
6544 if Analyzed
(Rng
) then
6548 -- Immediate return if either of the bounds raises Constraint_Error
6550 if Raises_Constraint_Error
(Lo
)
6551 or else Raises_Constraint_Error
(Hi
)
6556 Loval
:= Realval
(Lo
);
6557 Hival
:= Realval
(Hi
);
6559 -- Ordinary fixed-point case
6561 if Is_Ordinary_Fixed_Point_Type
(Typ
) then
6563 -- For the ordinary fixed-point case, we are allowed to fudge the
6564 -- end-points up or down by small. Generally we prefer to fudge up,
6565 -- i.e. widen the bounds for non-model numbers so that the end points
6566 -- are included. However there are cases in which this cannot be
6567 -- done, and indeed cases in which we may need to narrow the bounds.
6568 -- The following circuit makes the decision.
6570 -- Note: our terminology here is that Incl_EP means that the bounds
6571 -- are widened by Small if necessary to include the end points, and
6572 -- Excl_EP means that the bounds are narrowed by Small to exclude the
6573 -- end-points if this reduces the size.
6575 -- Note that in the Incl case, all we care about is including the
6576 -- end-points. In the Excl case, we want to narrow the bounds as
6577 -- much as permitted by the RM, to give the smallest possible size.
6580 Loval_Incl_EP
: Ureal
;
6581 Hival_Incl_EP
: Ureal
;
6583 Loval_Excl_EP
: Ureal
;
6584 Hival_Excl_EP
: Ureal
;
6590 First_Subt
: Entity_Id
;
6595 -- First step. Base types are required to be symmetrical. Right
6596 -- now, the base type range is a copy of the first subtype range.
6597 -- This will be corrected before we are done, but right away we
6598 -- need to deal with the case where both bounds are non-negative.
6599 -- In this case, we set the low bound to the negative of the high
6600 -- bound, to make sure that the size is computed to include the
6601 -- required sign. Note that we do not need to worry about the
6602 -- case of both bounds negative, because the sign will be dealt
6603 -- with anyway. Furthermore we can't just go making such a bound
6604 -- symmetrical, since in a twos-complement system, there is an
6605 -- extra negative value which could not be accommodated on the
6609 and then not UR_Is_Negative
(Loval
)
6610 and then Hival
> Loval
6613 Set_Realval
(Lo
, Loval
);
6616 -- Compute the fudged bounds. If the number is a model number,
6617 -- then we do nothing to include it, but we are allowed to backoff
6618 -- to the next adjacent model number when we exclude it. If it is
6619 -- not a model number then we straddle the two values with the
6620 -- model numbers on either side.
6622 Model_Num
:= UR_Trunc
(Loval
/ Small
) * Small
;
6624 if Loval
= Model_Num
then
6625 Loval_Incl_EP
:= Model_Num
;
6627 Loval_Incl_EP
:= Model_Num
- Small
;
6630 -- The low value excluding the end point is Small greater, but
6631 -- we do not do this exclusion if the low value is positive,
6632 -- since it can't help the size and could actually hurt by
6633 -- crossing the high bound.
6635 if UR_Is_Negative
(Loval_Incl_EP
) then
6636 Loval_Excl_EP
:= Loval_Incl_EP
+ Small
;
6638 -- If the value went from negative to zero, then we have the
6639 -- case where Loval_Incl_EP is the model number just below
6640 -- zero, so we want to stick to the negative value for the
6641 -- base type to maintain the condition that the size will
6642 -- include signed values.
6645 and then UR_Is_Zero
(Loval_Excl_EP
)
6647 Loval_Excl_EP
:= Loval_Incl_EP
;
6651 Loval_Excl_EP
:= Loval_Incl_EP
;
6654 -- Similar processing for upper bound and high value
6656 Model_Num
:= UR_Trunc
(Hival
/ Small
) * Small
;
6658 if Hival
= Model_Num
then
6659 Hival_Incl_EP
:= Model_Num
;
6661 Hival_Incl_EP
:= Model_Num
+ Small
;
6664 if UR_Is_Positive
(Hival_Incl_EP
) then
6665 Hival_Excl_EP
:= Hival_Incl_EP
- Small
;
6667 Hival_Excl_EP
:= Hival_Incl_EP
;
6670 -- One further adjustment is needed. In the case of subtypes, we
6671 -- cannot go outside the range of the base type, or we get
6672 -- peculiarities, and the base type range is already set. This
6673 -- only applies to the Incl values, since clearly the Excl values
6674 -- are already as restricted as they are allowed to be.
6677 Loval_Incl_EP
:= UR_Max
(Loval_Incl_EP
, Realval
(BLo
));
6678 Hival_Incl_EP
:= UR_Min
(Hival_Incl_EP
, Realval
(BHi
));
6681 -- Get size including and excluding end points
6683 Size_Incl_EP
:= Fsize
(Loval_Incl_EP
, Hival_Incl_EP
);
6684 Size_Excl_EP
:= Fsize
(Loval_Excl_EP
, Hival_Excl_EP
);
6686 -- No need to exclude end-points if it does not reduce size
6688 if Fsize
(Loval_Incl_EP
, Hival_Excl_EP
) = Size_Excl_EP
then
6689 Loval_Excl_EP
:= Loval_Incl_EP
;
6692 if Fsize
(Loval_Excl_EP
, Hival_Incl_EP
) = Size_Excl_EP
then
6693 Hival_Excl_EP
:= Hival_Incl_EP
;
6696 -- Now we set the actual size to be used. We want to use the
6697 -- bounds fudged up to include the end-points but only if this
6698 -- can be done without violating a specifically given size
6699 -- size clause or causing an unacceptable increase in size.
6701 -- Case of size clause given
6703 if Has_Size_Clause
(Typ
) then
6705 -- Use the inclusive size only if it is consistent with
6706 -- the explicitly specified size.
6708 if Size_Incl_EP
<= RM_Size
(Typ
) then
6709 Actual_Lo
:= Loval_Incl_EP
;
6710 Actual_Hi
:= Hival_Incl_EP
;
6711 Actual_Size
:= Size_Incl_EP
;
6713 -- If the inclusive size is too large, we try excluding
6714 -- the end-points (will be caught later if does not work).
6717 Actual_Lo
:= Loval_Excl_EP
;
6718 Actual_Hi
:= Hival_Excl_EP
;
6719 Actual_Size
:= Size_Excl_EP
;
6722 -- Case of size clause not given
6725 -- If we have a base type whose corresponding first subtype
6726 -- has an explicit size that is large enough to include our
6727 -- end-points, then do so. There is no point in working hard
6728 -- to get a base type whose size is smaller than the specified
6729 -- size of the first subtype.
6731 First_Subt
:= First_Subtype
(Typ
);
6733 if Has_Size_Clause
(First_Subt
)
6734 and then Size_Incl_EP
<= Esize
(First_Subt
)
6736 Actual_Size
:= Size_Incl_EP
;
6737 Actual_Lo
:= Loval_Incl_EP
;
6738 Actual_Hi
:= Hival_Incl_EP
;
6740 -- If excluding the end-points makes the size smaller and
6741 -- results in a size of 8,16,32,64, then we take the smaller
6742 -- size. For the 64 case, this is compulsory. For the other
6743 -- cases, it seems reasonable. We like to include end points
6744 -- if we can, but not at the expense of moving to the next
6745 -- natural boundary of size.
6747 elsif Size_Incl_EP
/= Size_Excl_EP
6748 and then Addressable
(Size_Excl_EP
)
6750 Actual_Size
:= Size_Excl_EP
;
6751 Actual_Lo
:= Loval_Excl_EP
;
6752 Actual_Hi
:= Hival_Excl_EP
;
6754 -- Otherwise we can definitely include the end points
6757 Actual_Size
:= Size_Incl_EP
;
6758 Actual_Lo
:= Loval_Incl_EP
;
6759 Actual_Hi
:= Hival_Incl_EP
;
6762 -- One pathological case: normally we never fudge a low bound
6763 -- down, since it would seem to increase the size (if it has
6764 -- any effect), but for ranges containing single value, or no
6765 -- values, the high bound can be small too large. Consider:
6767 -- type t is delta 2.0**(-14)
6768 -- range 131072.0 .. 0;
6770 -- That lower bound is *just* outside the range of 32 bits, and
6771 -- does need fudging down in this case. Note that the bounds
6772 -- will always have crossed here, since the high bound will be
6773 -- fudged down if necessary, as in the case of:
6775 -- type t is delta 2.0**(-14)
6776 -- range 131072.0 .. 131072.0;
6778 -- So we detect the situation by looking for crossed bounds,
6779 -- and if the bounds are crossed, and the low bound is greater
6780 -- than zero, we will always back it off by small, since this
6781 -- is completely harmless.
6783 if Actual_Lo
> Actual_Hi
then
6784 if UR_Is_Positive
(Actual_Lo
) then
6785 Actual_Lo
:= Loval_Incl_EP
- Small
;
6786 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
6788 -- And of course, we need to do exactly the same parallel
6789 -- fudge for flat ranges in the negative region.
6791 elsif UR_Is_Negative
(Actual_Hi
) then
6792 Actual_Hi
:= Hival_Incl_EP
+ Small
;
6793 Actual_Size
:= Fsize
(Actual_Lo
, Actual_Hi
);
6798 Set_Realval
(Lo
, Actual_Lo
);
6799 Set_Realval
(Hi
, Actual_Hi
);
6802 -- For the decimal case, none of this fudging is required, since there
6803 -- are no end-point problems in the decimal case (the end-points are
6804 -- always included).
6807 Actual_Size
:= Fsize
(Loval
, Hival
);
6810 -- At this stage, the actual size has been calculated and the proper
6811 -- required bounds are stored in the low and high bounds.
6813 if Actual_Size
> 64 then
6814 Error_Msg_Uint_1
:= UI_From_Int
(Actual_Size
);
6816 ("size required (^) for type& too large, maximum allowed is 64",
6821 -- Check size against explicit given size
6823 if Has_Size_Clause
(Typ
) then
6824 if Actual_Size
> RM_Size
(Typ
) then
6825 Error_Msg_Uint_1
:= RM_Size
(Typ
);
6826 Error_Msg_Uint_2
:= UI_From_Int
(Actual_Size
);
6828 ("size given (^) for type& too small, minimum allowed is ^",
6829 Size_Clause
(Typ
), Typ
);
6832 Actual_Size
:= UI_To_Int
(Esize
(Typ
));
6835 -- Increase size to next natural boundary if no size clause given
6838 if Actual_Size
<= 8 then
6840 elsif Actual_Size
<= 16 then
6842 elsif Actual_Size
<= 32 then
6848 Init_Esize
(Typ
, Actual_Size
);
6849 Adjust_Esize_For_Alignment
(Typ
);
6852 -- If we have a base type, then expand the bounds so that they extend to
6853 -- the full width of the allocated size in bits, to avoid junk range
6854 -- checks on intermediate computations.
6856 if Base_Type
(Typ
) = Typ
then
6857 Set_Realval
(Lo
, -(Small
* (Uint_2
** (Actual_Size
- 1))));
6858 Set_Realval
(Hi
, (Small
* (Uint_2
** (Actual_Size
- 1) - 1)));
6861 -- Final step is to reanalyze the bounds using the proper type
6862 -- and set the Corresponding_Integer_Value fields of the literals.
6864 Set_Etype
(Lo
, Empty
);
6865 Set_Analyzed
(Lo
, False);
6868 -- Resolve with universal fixed if the base type, and the base type if
6869 -- it is a subtype. Note we can't resolve the base type with itself,
6870 -- that would be a reference before definition.
6873 Resolve
(Lo
, Universal_Fixed
);
6878 -- Set corresponding integer value for bound
6880 Set_Corresponding_Integer_Value
6881 (Lo
, UR_To_Uint
(Realval
(Lo
) / Small
));
6883 -- Similar processing for high bound
6885 Set_Etype
(Hi
, Empty
);
6886 Set_Analyzed
(Hi
, False);
6890 Resolve
(Hi
, Universal_Fixed
);
6895 Set_Corresponding_Integer_Value
6896 (Hi
, UR_To_Uint
(Realval
(Hi
) / Small
));
6898 -- Set type of range to correspond to bounds
6900 Set_Etype
(Rng
, Etype
(Lo
));
6902 -- Set Esize to calculated size if not set already
6904 if Unknown_Esize
(Typ
) then
6905 Init_Esize
(Typ
, Actual_Size
);
6908 -- Set RM_Size if not already set. If already set, check value
6911 Minsiz
: constant Uint
:= UI_From_Int
(Minimum_Size
(Typ
));
6914 if RM_Size
(Typ
) /= Uint_0
then
6915 if RM_Size
(Typ
) < Minsiz
then
6916 Error_Msg_Uint_1
:= RM_Size
(Typ
);
6917 Error_Msg_Uint_2
:= Minsiz
;
6919 ("size given (^) for type& too small, minimum allowed is ^",
6920 Size_Clause
(Typ
), Typ
);
6924 Set_RM_Size
(Typ
, Minsiz
);
6927 end Freeze_Fixed_Point_Type
;
6933 procedure Freeze_Itype
(T
: Entity_Id
; N
: Node_Id
) is
6937 Set_Has_Delayed_Freeze
(T
);
6938 L
:= Freeze_Entity
(T
, N
);
6940 if Is_Non_Empty_List
(L
) then
6941 Insert_Actions
(N
, L
);
6945 --------------------------
6946 -- Freeze_Static_Object --
6947 --------------------------
6949 procedure Freeze_Static_Object
(E
: Entity_Id
) is
6951 Cannot_Be_Static
: exception;
6952 -- Exception raised if the type of a static object cannot be made
6953 -- static. This happens if the type depends on non-global objects.
6955 procedure Ensure_Expression_Is_SA
(N
: Node_Id
);
6956 -- Called to ensure that an expression used as part of a type definition
6957 -- is statically allocatable, which means that the expression type is
6958 -- statically allocatable, and the expression is either static, or a
6959 -- reference to a library level constant.
6961 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
);
6962 -- Called to mark a type as static, checking that it is possible
6963 -- to set the type as static. If it is not possible, then the
6964 -- exception Cannot_Be_Static is raised.
6966 -----------------------------
6967 -- Ensure_Expression_Is_SA --
6968 -----------------------------
6970 procedure Ensure_Expression_Is_SA
(N
: Node_Id
) is
6974 Ensure_Type_Is_SA
(Etype
(N
));
6976 if Is_OK_Static_Expression
(N
) then
6979 elsif Nkind
(N
) = N_Identifier
then
6983 and then Ekind
(Ent
) = E_Constant
6984 and then Is_Library_Level_Entity
(Ent
)
6990 raise Cannot_Be_Static
;
6991 end Ensure_Expression_Is_SA
;
6993 -----------------------
6994 -- Ensure_Type_Is_SA --
6995 -----------------------
6997 procedure Ensure_Type_Is_SA
(Typ
: Entity_Id
) is
7002 -- If type is library level, we are all set
7004 if Is_Library_Level_Entity
(Typ
) then
7008 -- We are also OK if the type already marked as statically allocated,
7009 -- which means we processed it before.
7011 if Is_Statically_Allocated
(Typ
) then
7015 -- Mark type as statically allocated
7017 Set_Is_Statically_Allocated
(Typ
);
7019 -- Check that it is safe to statically allocate this type
7021 if Is_Scalar_Type
(Typ
) or else Is_Real_Type
(Typ
) then
7022 Ensure_Expression_Is_SA
(Type_Low_Bound
(Typ
));
7023 Ensure_Expression_Is_SA
(Type_High_Bound
(Typ
));
7025 elsif Is_Array_Type
(Typ
) then
7026 N
:= First_Index
(Typ
);
7027 while Present
(N
) loop
7028 Ensure_Type_Is_SA
(Etype
(N
));
7032 Ensure_Type_Is_SA
(Component_Type
(Typ
));
7034 elsif Is_Access_Type
(Typ
) then
7035 if Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
then
7039 T
: constant Entity_Id
:= Etype
(Designated_Type
(Typ
));
7042 if T
/= Standard_Void_Type
then
7043 Ensure_Type_Is_SA
(T
);
7046 F
:= First_Formal
(Designated_Type
(Typ
));
7047 while Present
(F
) loop
7048 Ensure_Type_Is_SA
(Etype
(F
));
7054 Ensure_Type_Is_SA
(Designated_Type
(Typ
));
7057 elsif Is_Record_Type
(Typ
) then
7058 C
:= First_Entity
(Typ
);
7059 while Present
(C
) loop
7060 if Ekind
(C
) = E_Discriminant
7061 or else Ekind
(C
) = E_Component
7063 Ensure_Type_Is_SA
(Etype
(C
));
7065 elsif Is_Type
(C
) then
7066 Ensure_Type_Is_SA
(C
);
7072 elsif Ekind
(Typ
) = E_Subprogram_Type
then
7073 Ensure_Type_Is_SA
(Etype
(Typ
));
7075 C
:= First_Formal
(Typ
);
7076 while Present
(C
) loop
7077 Ensure_Type_Is_SA
(Etype
(C
));
7082 raise Cannot_Be_Static
;
7084 end Ensure_Type_Is_SA
;
7086 -- Start of processing for Freeze_Static_Object
7089 Ensure_Type_Is_SA
(Etype
(E
));
7092 when Cannot_Be_Static
=>
7094 -- If the object that cannot be static is imported or exported, then
7095 -- issue an error message saying that this object cannot be imported
7096 -- or exported. If it has an address clause it is an overlay in the
7097 -- current partition and the static requirement is not relevant.
7098 -- Do not issue any error message when ignoring rep clauses.
7100 if Ignore_Rep_Clauses
then
7103 elsif Is_Imported
(E
) then
7104 if No
(Address_Clause
(E
)) then
7106 ("& cannot be imported (local type is not constant)", E
);
7109 -- Otherwise must be exported, something is wrong if compiler
7110 -- is marking something as statically allocated which cannot be).
7112 else pragma Assert
(Is_Exported
(E
));
7114 ("& cannot be exported (local type is not constant)", E
);
7116 end Freeze_Static_Object
;
7118 -----------------------
7119 -- Freeze_Subprogram --
7120 -----------------------
7122 procedure Freeze_Subprogram
(E
: Entity_Id
) is
7127 -- Subprogram may not have an address clause unless it is imported
7129 if Present
(Address_Clause
(E
)) then
7130 if not Is_Imported
(E
) then
7132 ("address clause can only be given " &
7133 "for imported subprogram",
7134 Name
(Address_Clause
(E
)));
7138 -- Reset the Pure indication on an imported subprogram unless an
7139 -- explicit Pure_Function pragma was present or the subprogram is an
7140 -- intrinsic. We do this because otherwise it is an insidious error
7141 -- to call a non-pure function from pure unit and have calls
7142 -- mysteriously optimized away. What happens here is that the Import
7143 -- can bypass the normal check to ensure that pure units call only pure
7146 -- The reason for the intrinsic exception is that in general, intrinsic
7147 -- functions (such as shifts) are pure anyway. The only exceptions are
7148 -- the intrinsics in GNAT.Source_Info, and that unit is not marked Pure
7149 -- in any case, so no problem arises.
7152 and then Is_Pure
(E
)
7153 and then not Has_Pragma_Pure_Function
(E
)
7154 and then not Is_Intrinsic_Subprogram
(E
)
7156 Set_Is_Pure
(E
, False);
7159 -- For non-foreign convention subprograms, this is where we create
7160 -- the extra formals (for accessibility level and constrained bit
7161 -- information). We delay this till the freeze point precisely so
7162 -- that we know the convention.
7164 if not Has_Foreign_Convention
(E
) then
7165 Create_Extra_Formals
(E
);
7168 -- If this is convention Ada and a Valued_Procedure, that's odd
7170 if Ekind
(E
) = E_Procedure
7171 and then Is_Valued_Procedure
(E
)
7172 and then Convention
(E
) = Convention_Ada
7173 and then Warn_On_Export_Import
7176 ("??Valued_Procedure has no effect for convention Ada", E
);
7177 Set_Is_Valued_Procedure
(E
, False);
7180 -- Case of foreign convention
7185 -- For foreign conventions, warn about return of unconstrained array
7187 if Ekind
(E
) = E_Function
then
7188 Retype
:= Underlying_Type
(Etype
(E
));
7190 -- If no return type, probably some other error, e.g. a
7191 -- missing full declaration, so ignore.
7196 -- If the return type is generic, we have emitted a warning
7197 -- earlier on, and there is nothing else to check here. Specific
7198 -- instantiations may lead to erroneous behavior.
7200 elsif Is_Generic_Type
(Etype
(E
)) then
7203 -- Display warning if returning unconstrained array
7205 elsif Is_Array_Type
(Retype
)
7206 and then not Is_Constrained
(Retype
)
7208 -- Check appropriate warning is enabled (should we check for
7209 -- Warnings (Off) on specific entities here, probably so???)
7211 and then Warn_On_Export_Import
7213 -- Exclude the VM case, since return of unconstrained arrays
7214 -- is properly handled in both the JVM and .NET cases.
7216 and then VM_Target
= No_VM
7219 ("?x?foreign convention function& should not return " &
7220 "unconstrained array", E
);
7225 -- If any of the formals for an exported foreign convention
7226 -- subprogram have defaults, then emit an appropriate warning since
7227 -- this is odd (default cannot be used from non-Ada code)
7229 if Is_Exported
(E
) then
7230 F
:= First_Formal
(E
);
7231 while Present
(F
) loop
7232 if Warn_On_Export_Import
7233 and then Present
(Default_Value
(F
))
7236 ("?x?parameter cannot be defaulted in non-Ada call",
7245 -- Pragma Inline_Always is disallowed for dispatching subprograms
7246 -- because the address of such subprograms is saved in the dispatch
7247 -- table to support dispatching calls, and dispatching calls cannot
7248 -- be inlined. This is consistent with the restriction against using
7249 -- 'Access or 'Address on an Inline_Always subprogram.
7251 if Is_Dispatching_Operation
(E
)
7252 and then Has_Pragma_Inline_Always
(E
)
7255 ("pragma Inline_Always not allowed for dispatching subprograms", E
);
7258 -- Because of the implicit representation of inherited predefined
7259 -- operators in the front-end, the overriding status of the operation
7260 -- may be affected when a full view of a type is analyzed, and this is
7261 -- not captured by the analysis of the corresponding type declaration.
7262 -- Therefore the correctness of a not-overriding indicator must be
7263 -- rechecked when the subprogram is frozen.
7265 if Nkind
(E
) = N_Defining_Operator_Symbol
7266 and then not Error_Posted
(Parent
(E
))
7268 Check_Overriding_Indicator
(E
, Empty
, Is_Primitive
(E
));
7270 end Freeze_Subprogram
;
7272 ----------------------
7273 -- Is_Fully_Defined --
7274 ----------------------
7276 function Is_Fully_Defined
(T
: Entity_Id
) return Boolean is
7278 if Ekind
(T
) = E_Class_Wide_Type
then
7279 return Is_Fully_Defined
(Etype
(T
));
7281 elsif Is_Array_Type
(T
) then
7282 return Is_Fully_Defined
(Component_Type
(T
));
7284 elsif Is_Record_Type
(T
)
7285 and not Is_Private_Type
(T
)
7287 -- Verify that the record type has no components with private types
7288 -- without completion.
7294 Comp
:= First_Component
(T
);
7295 while Present
(Comp
) loop
7296 if not Is_Fully_Defined
(Etype
(Comp
)) then
7300 Next_Component
(Comp
);
7305 -- For the designated type of an access to subprogram, all types in
7306 -- the profile must be fully defined.
7308 elsif Ekind
(T
) = E_Subprogram_Type
then
7313 F
:= First_Formal
(T
);
7314 while Present
(F
) loop
7315 if not Is_Fully_Defined
(Etype
(F
)) then
7322 return Is_Fully_Defined
(Etype
(T
));
7326 return not Is_Private_Type
(T
)
7327 or else Present
(Full_View
(Base_Type
(T
)));
7329 end Is_Fully_Defined
;
7331 ---------------------------------
7332 -- Process_Default_Expressions --
7333 ---------------------------------
7335 procedure Process_Default_Expressions
7337 After
: in out Node_Id
)
7339 Loc
: constant Source_Ptr
:= Sloc
(E
);
7346 Set_Default_Expressions_Processed
(E
);
7348 -- A subprogram instance and its associated anonymous subprogram share
7349 -- their signature. The default expression functions are defined in the
7350 -- wrapper packages for the anonymous subprogram, and should not be
7351 -- generated again for the instance.
7353 if Is_Generic_Instance
(E
)
7354 and then Present
(Alias
(E
))
7355 and then Default_Expressions_Processed
(Alias
(E
))
7360 Formal
:= First_Formal
(E
);
7361 while Present
(Formal
) loop
7362 if Present
(Default_Value
(Formal
)) then
7364 -- We work with a copy of the default expression because we
7365 -- do not want to disturb the original, since this would mess
7366 -- up the conformance checking.
7368 Dcopy
:= New_Copy_Tree
(Default_Value
(Formal
));
7370 -- The analysis of the expression may generate insert actions,
7371 -- which of course must not be executed. We wrap those actions
7372 -- in a procedure that is not called, and later on eliminated.
7373 -- The following cases have no side-effects, and are analyzed
7376 if Nkind
(Dcopy
) = N_Identifier
7377 or else Nkind_In
(Dcopy
, N_Expanded_Name
,
7379 N_Character_Literal
,
7382 or else (Nkind
(Dcopy
) = N_Attribute_Reference
7383 and then Attribute_Name
(Dcopy
) = Name_Null_Parameter
)
7384 or else Known_Null
(Dcopy
)
7386 -- If there is no default function, we must still do a full
7387 -- analyze call on the default value, to ensure that all error
7388 -- checks are performed, e.g. those associated with static
7389 -- evaluation. Note: this branch will always be taken if the
7390 -- analyzer is turned off (but we still need the error checks).
7392 -- Note: the setting of parent here is to meet the requirement
7393 -- that we can only analyze the expression while attached to
7394 -- the tree. Really the requirement is that the parent chain
7395 -- be set, we don't actually need to be in the tree.
7397 Set_Parent
(Dcopy
, Declaration_Node
(Formal
));
7400 -- Default expressions are resolved with their own type if the
7401 -- context is generic, to avoid anomalies with private types.
7403 if Ekind
(Scope
(E
)) = E_Generic_Package
then
7406 Resolve
(Dcopy
, Etype
(Formal
));
7409 -- If that resolved expression will raise constraint error,
7410 -- then flag the default value as raising constraint error.
7411 -- This allows a proper error message on the calls.
7413 if Raises_Constraint_Error
(Dcopy
) then
7414 Set_Raises_Constraint_Error
(Default_Value
(Formal
));
7417 -- If the default is a parameterless call, we use the name of
7418 -- the called function directly, and there is no body to build.
7420 elsif Nkind
(Dcopy
) = N_Function_Call
7421 and then No
(Parameter_Associations
(Dcopy
))
7425 -- Else construct and analyze the body of a wrapper procedure
7426 -- that contains an object declaration to hold the expression.
7427 -- Given that this is done only to complete the analysis, it
7428 -- simpler to build a procedure than a function which might
7429 -- involve secondary stack expansion.
7432 Dnam
:= Make_Temporary
(Loc
, 'D');
7435 Make_Subprogram_Body
(Loc
,
7437 Make_Procedure_Specification
(Loc
,
7438 Defining_Unit_Name
=> Dnam
),
7440 Declarations
=> New_List
(
7441 Make_Object_Declaration
(Loc
,
7442 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
7443 Object_Definition
=>
7444 New_Occurrence_Of
(Etype
(Formal
), Loc
),
7445 Expression
=> New_Copy_Tree
(Dcopy
))),
7447 Handled_Statement_Sequence
=>
7448 Make_Handled_Sequence_Of_Statements
(Loc
,
7449 Statements
=> Empty_List
));
7451 Set_Scope
(Dnam
, Scope
(E
));
7452 Set_Assignment_OK
(First
(Declarations
(Dbody
)));
7453 Set_Is_Eliminated
(Dnam
);
7454 Insert_After
(After
, Dbody
);
7460 Next_Formal
(Formal
);
7462 end Process_Default_Expressions
;
7464 ----------------------------------------
7465 -- Set_Component_Alignment_If_Not_Set --
7466 ----------------------------------------
7468 procedure Set_Component_Alignment_If_Not_Set
(Typ
: Entity_Id
) is
7470 -- Ignore if not base type, subtypes don't need anything
7472 if Typ
/= Base_Type
(Typ
) then
7476 -- Do not override existing representation
7478 if Is_Packed
(Typ
) then
7481 elsif Has_Specified_Layout
(Typ
) then
7484 elsif Component_Alignment
(Typ
) /= Calign_Default
then
7488 Set_Component_Alignment
7489 (Typ
, Scope_Stack
.Table
7490 (Scope_Stack
.Last
).Component_Alignment_Default
);
7492 end Set_Component_Alignment_If_Not_Set
;
7494 --------------------------
7495 -- Set_SSO_From_Default --
7496 --------------------------
7498 procedure Set_SSO_From_Default
(T
: Entity_Id
) is
7500 if (Is_Record_Type
(T
) or else Is_Array_Type
(T
))
7501 and then Is_Base_Type
(T
)
7503 if ((Bytes_Big_Endian
and then SSO_Set_Low_By_Default
(T
))
7505 ((not Bytes_Big_Endian
) and then SSO_Set_High_By_Default
(T
)))
7507 -- For a record type, if native bit order is specified explicitly,
7508 -- then never set reverse SSO from default.
7512 and then Has_Rep_Item
(T
, Name_Bit_Order
)
7513 and then not Reverse_Bit_Order
(T
))
7515 -- If flags cause reverse storage order, then set the result. Note
7516 -- that we would have ignored the pragma setting the non default
7517 -- storage order in any case, hence the assertion at this point.
7519 pragma Assert
(Support_Nondefault_SSO_On_Target
);
7520 Set_Reverse_Storage_Order
(T
);
7522 -- For a record type, also set reversed bit order. Note that if
7523 -- a bit order has been specified explicitly, then this is a
7524 -- no-op, as per the guard above.
7526 if Is_Record_Type
(T
) then
7527 Set_Reverse_Bit_Order
(T
);
7531 end Set_SSO_From_Default
;
7537 procedure Undelay_Type
(T
: Entity_Id
) is
7539 Set_Has_Delayed_Freeze
(T
, False);
7540 Set_Freeze_Node
(T
, Empty
);
7542 -- Since we don't want T to have a Freeze_Node, we don't want its
7543 -- Full_View or Corresponding_Record_Type to have one either.
7545 -- ??? Fundamentally, this whole handling is unpleasant. What we really
7546 -- want is to be sure that for an Itype that's part of record R and is a
7547 -- subtype of type T, that it's frozen after the later of the freeze
7548 -- points of R and T. We have no way of doing that directly, so what we
7549 -- do is force most such Itypes to be frozen as part of freezing R via
7550 -- this procedure and only delay the ones that need to be delayed
7551 -- (mostly the designated types of access types that are defined as part
7554 if Is_Private_Type
(T
)
7555 and then Present
(Full_View
(T
))
7556 and then Is_Itype
(Full_View
(T
))
7557 and then Is_Record_Type
(Scope
(Full_View
(T
)))
7559 Undelay_Type
(Full_View
(T
));
7562 if Is_Concurrent_Type
(T
)
7563 and then Present
(Corresponding_Record_Type
(T
))
7564 and then Is_Itype
(Corresponding_Record_Type
(T
))
7565 and then Is_Record_Type
(Scope
(Corresponding_Record_Type
(T
)))
7567 Undelay_Type
(Corresponding_Record_Type
(T
));
7575 procedure Warn_Overlay
7580 Ent
: constant Entity_Id
:= Entity
(Nam
);
7581 -- The object to which the address clause applies
7584 Old
: Entity_Id
:= Empty
;
7588 -- No warning if address clause overlay warnings are off
7590 if not Address_Clause_Overlay_Warnings
then
7594 -- No warning if there is an explicit initialization
7596 Init
:= Original_Node
(Expression
(Declaration_Node
(Ent
)));
7598 if Present
(Init
) and then Comes_From_Source
(Init
) then
7602 -- We only give the warning for non-imported entities of a type for
7603 -- which a non-null base init proc is defined, or for objects of access
7604 -- types with implicit null initialization, or when Normalize_Scalars
7605 -- applies and the type is scalar or a string type (the latter being
7606 -- tested for because predefined String types are initialized by inline
7607 -- code rather than by an init_proc). Note that we do not give the
7608 -- warning for Initialize_Scalars, since we suppressed initialization
7609 -- in this case. Also, do not warn if Suppress_Initialization is set.
7612 and then not Is_Imported
(Ent
)
7613 and then not Initialization_Suppressed
(Typ
)
7614 and then (Has_Non_Null_Base_Init_Proc
(Typ
)
7615 or else Is_Access_Type
(Typ
)
7616 or else (Normalize_Scalars
7617 and then (Is_Scalar_Type
(Typ
)
7618 or else Is_String_Type
(Typ
))))
7620 if Nkind
(Expr
) = N_Attribute_Reference
7621 and then Is_Entity_Name
(Prefix
(Expr
))
7623 Old
:= Entity
(Prefix
(Expr
));
7625 elsif Is_Entity_Name
(Expr
)
7626 and then Ekind
(Entity
(Expr
)) = E_Constant
7628 Decl
:= Declaration_Node
(Entity
(Expr
));
7630 if Nkind
(Decl
) = N_Object_Declaration
7631 and then Present
(Expression
(Decl
))
7632 and then Nkind
(Expression
(Decl
)) = N_Attribute_Reference
7633 and then Is_Entity_Name
(Prefix
(Expression
(Decl
)))
7635 Old
:= Entity
(Prefix
(Expression
(Decl
)));
7637 elsif Nkind
(Expr
) = N_Function_Call
then
7641 -- A function call (most likely to To_Address) is probably not an
7642 -- overlay, so skip warning. Ditto if the function call was inlined
7643 -- and transformed into an entity.
7645 elsif Nkind
(Original_Node
(Expr
)) = N_Function_Call
then
7649 Decl
:= Next
(Parent
(Expr
));
7651 -- If a pragma Import follows, we assume that it is for the current
7652 -- target of the address clause, and skip the warning.
7655 and then Nkind
(Decl
) = N_Pragma
7656 and then Pragma_Name
(Decl
) = Name_Import
7661 if Present
(Old
) then
7662 Error_Msg_Node_2
:= Old
;
7664 ("default initialization of & may modify &??",
7668 ("default initialization of & may modify overlaid storage??",
7672 -- Add friendly warning if initialization comes from a packed array
7675 if Is_Record_Type
(Typ
) then
7680 Comp
:= First_Component
(Typ
);
7681 while Present
(Comp
) loop
7682 if Nkind
(Parent
(Comp
)) = N_Component_Declaration
7683 and then Present
(Expression
(Parent
(Comp
)))
7686 elsif Is_Array_Type
(Etype
(Comp
))
7687 and then Present
(Packed_Array_Impl_Type
(Etype
(Comp
)))
7690 ("\packed array component& " &
7691 "will be initialized to zero??",
7695 Next_Component
(Comp
);
7702 ("\use pragma Import for & to " &
7703 "suppress initialization (RM B.1(24))??",